diff options
author | Matthias Braun <matze@braunis.de> | 2015-06-24 20:03:33 +0000 |
---|---|---|
committer | Matthias Braun <matze@braunis.de> | 2015-06-24 20:03:33 +0000 |
commit | 50b82ece5d628f2a41e9a0b1bb40e446a2002841 (patch) | |
tree | 88fe94b9b0566125e319984d6f5c515889c0844d /tools/opt | |
parent | 7d46df36264e7f81f59135c7847fb8dce5642242 (diff) |
opt: Add option to strip or add llvm value names
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240583 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/opt')
-rw-r--r-- | tools/opt/opt.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp index 55426e7b274..197dc4c7fa9 100644 --- a/tools/opt/opt.cpp +++ b/tools/opt/opt.cpp @@ -105,6 +105,12 @@ StripDebug("strip-debug", cl::desc("Strip debugger symbol info from translation unit")); static cl::opt<bool> +StripValueNames("strip-value-names", cl::desc("Remove llvm value names")); + +static cl::opt<bool> +NameValues("name-values", cl::desc("Give anonymous llvm values a name")); + +static cl::opt<bool> DisableInline("disable-inlining", cl::desc("Do not run the inliner pass")); static cl::opt<bool> @@ -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(). |