From a7f3f03329b99b39bb4052ff26914a811a03208f Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Wed, 24 Jun 2015 20:03:33 +0000 Subject: [PATCH] opt: Add option to strip or add llvm value names llvm-svn: 240583 --- llvm/tools/opt/opt.cpp | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/llvm/tools/opt/opt.cpp b/llvm/tools/opt/opt.cpp index 55426e7b2743..197dc4c7fa91 100644 --- a/llvm/tools/opt/opt.cpp +++ b/llvm/tools/opt/opt.cpp @@ -104,6 +104,12 @@ static cl::opt StripDebug("strip-debug", cl::desc("Strip debugger symbol info from translation unit")); +static cl::opt +StripValueNames("strip-value-names", cl::desc("Remove llvm value names")); + +static cl::opt +NameValues("name-values", cl::desc("Give anonymous llvm values a name")); + static cl::opt DisableInline("disable-inlining", cl::desc("Do not run the inliner pass")); @@ -281,6 +287,37 @@ static TargetMachine* GetTargetMachine(Triple TheTriple, StringRef CPUStr, GetCodeGenOptLevel()); } +static void removeValueNames(Module &Mod) { + for (Function &F : Mod) { + for (BasicBlock &BB : F) { + BB.setName(""); + for (Instruction &I : BB) + I.setName(""); + } + } +} + +static void nameValuesInFunction(Function &F) { + bool FirstBB = true; + for (BasicBlock &BB : F) { + if (!BB.hasName()) + BB.setName(FirstBB ? "entry" : "BB"); + FirstBB = false; + + for (Instruction &I : BB) { + if (I.getType()->isVoidTy()) + continue; + if (!I.hasName()) + I.setName("v"); + } + } +} + +static void nameValues(Module &Mod) { + for (Function &F : Mod) + nameValuesInFunction(F); +} + #ifdef LINK_POLLY_INTO_TOOLS namespace polly { void initializePollyPasses(llvm::PassRegistry &Registry); @@ -351,6 +388,12 @@ int main(int argc, char **argv) { if (StripDebug) StripDebugInfo(*M); + if (StripValueNames) + removeValueNames(*M); + + if (NameValues) + nameValues(*M); + // Immediately run the verifier to catch any problems before starting up the // pass pipelines. Otherwise we can crash on broken code during // doInitialization().