[PATCH] D18883: Add a pass to name anonymous/nameless function

Teresa Johnson via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 8 06:55:51 PDT 2016


tejohnson added a comment.

Perhaps this should be named something more general than NameAnonFunctionPass. This is the naming scheme pcc was proposing for promoted values as well, and eventually it would be good to do any early renaming/promotion of locals here. The moduleHash() facility could also be used during importing to rename/promote imported locals (i.e. invoked from FunctionImportGlobalProcessing), for anything not promoted/renamed during the compile step, so it would also be good to put that into a more general location.


================
Comment at: lib/Transforms/Utils/NameAnonFunctions.cpp:59
@@ +58,3 @@
+  auto ModuleHash = moduleHash(M);
+  Twine Prefix = Twine("anon.") + ModuleHash + ".";
+  int count = 0;
----------------
george.burgess.iv wrote:
> ISTM this code is making many `Twine`s here, and the lifetimes of all but the top-level `Twine` will end when we're done constructing `Prefix`, which is bad. Am I missing something?
Right, I think this should just be std::string (although the Twine(count++) below seems fine since it is constructing a function parameter).

================
Comment at: lib/Transforms/Utils/NameAnonFunctions.cpp:64
@@ +63,3 @@
+      continue;
+    F.setName(Prefix + Twine(count++));
+    Changed = true;
----------------
Another possibility would be to move the Twines here: 
 Twine("anon.") + ModuleHash + "." + Twine(count++)


http://reviews.llvm.org/D18883





More information about the llvm-commits mailing list