[PATCH] D24641: Fix NameAnonFunctions pass: for ThinLTO we need to rename global variables as well

Mehdi AMINI via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 16 10:05:14 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL281744: Fix NameAnonFunctions pass: for ThinLTO we need to rename global variables as… (authored by mehdi_amini).

Changed prior to commit:
  https://reviews.llvm.org/D24641?vs=71582&id=71669#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D24641

Files:
  llvm/trunk/lib/Transforms/Utils/NameAnonFunctions.cpp
  llvm/trunk/test/Transforms/NameAnonFunctions/rename.ll

Index: llvm/trunk/test/Transforms/NameAnonFunctions/rename.ll
===================================================================
--- llvm/trunk/test/Transforms/NameAnonFunctions/rename.ll
+++ llvm/trunk/test/Transforms/NameAnonFunctions/rename.ll
@@ -11,6 +11,8 @@
     ret void
 }
 
+; CHECK: @anon.acbd18db4cc2f85cedef654fccc4a4d8.3 = global i8 0
+; CHECK: @anon.acbd18db4cc2f85cedef654fccc4a4d8.4 = alias i8, i8* @anon.acbd18db4cc2f85cedef654fccc4a4d8.3
 ; CHECK: define void @anon.acbd18db4cc2f85cedef654fccc4a4d8.0()
 ; CHECK: define void @anon.acbd18db4cc2f85cedef654fccc4a4d8.1()
 ; CHECK: define void @anon.acbd18db4cc2f85cedef654fccc4a4d8.2()
@@ -25,3 +27,7 @@
     ret void
 }
 
+
+ at 3 = global i8 0
+
+ at 4 = alias i8, i8 *@3
Index: llvm/trunk/lib/Transforms/Utils/NameAnonFunctions.cpp
===================================================================
--- llvm/trunk/lib/Transforms/Utils/NameAnonFunctions.cpp
+++ llvm/trunk/lib/Transforms/Utils/NameAnonFunctions.cpp
@@ -67,12 +67,17 @@
   bool Changed = false;
   ModuleHasher ModuleHash(M);
   int count = 0;
-  for (auto &F : M) {
-    if (F.hasName())
-      continue;
-    F.setName(Twine("anon.") + ModuleHash.get() + "." + Twine(count++));
+  auto RenameIfNeed = [&] (GlobalValue &GV) {
+    if (GV.hasName())
+      return;
+    GV.setName(Twine("anon.") + ModuleHash.get() + "." + Twine(count++));
     Changed = true;
-  }
+  };
+  for (auto &GO : M.global_objects())
+    RenameIfNeed(GO);
+  for (auto &GA : M.aliases())
+    RenameIfNeed(GA);
+
   return Changed;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24641.71669.patch
Type: text/x-patch
Size: 1545 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160916/ffd84177/attachment.bin>


More information about the llvm-commits mailing list