[PATCH] opt: Add option to strip or add llvm value names
Matthias Braun
matze at braunis.de
Wed Jun 24 11:44:40 PDT 2015
This adds two commandline options to the opt tool:
* -name-values: Give anonymous llvm values a name.
* -strip-value-names: Removes names from llvm values.
This is useful for developers that want to manually edit .ll files. This is because with anonymous values you can't insert/remove instructions without renumbering all following values. The stripping part may be useful if you want to hide names from the original source or in combination with name-values you can force all values into a simple naming scheme.
REPOSITORY
rL LLVM
http://reviews.llvm.org/D10703
Files:
tools/opt/opt.cpp
Index: tools/opt/opt.cpp
===================================================================
--- tools/opt/opt.cpp
+++ tools/opt/opt.cpp
@@ -105,6 +105,12 @@
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 @@
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 @@
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().
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D10703.28378.patch
Type: text/x-patch
Size: 1746 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150624/1db719f6/attachment.bin>
More information about the llvm-commits
mailing list