[llvm] 3b21a07 - [PGO] Delete dead comdat renaming code related to GlobalAlias. NFC

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 10 09:02:12 PDT 2020


Author: Fangrui Song
Date: 2020-08-10T09:02:04-07:00
New Revision: 3b21a07fd7fd09618032db49f919cf917ef8afd7

URL: https://github.com/llvm/llvm-project/commit/3b21a07fd7fd09618032db49f919cf917ef8afd7
DIFF: https://github.com/llvm/llvm-project/commit/3b21a07fd7fd09618032db49f919cf917ef8afd7.diff

LOG: [PGO] Delete dead comdat renaming code related to GlobalAlias. NFC

A GlobalAlias is an address-taken user of its aliased function.
canRenameComdatFunc has excluded such cases.

Reviewed By: davidxl

Differential Revision: https://reviews.llvm.org/D85597

Added: 
    

Modified: 
    llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
    llvm/test/Transforms/PGOProfile/comdat_rename.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
index 5a0185600e06..be2e091e8c08 100644
--- a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
+++ b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
@@ -693,7 +693,7 @@ static bool canRenameComdat(
     return false;
 
   // FIXME: Current only handle those Comdat groups that only containing one
-  // function and function aliases.
+  // function.
   // (1) For a Comdat group containing multiple functions, we need to have a
   // unique postfix based on the hashes for each function. There is a
   // non-trivial code refactoring to do this efficiently.
@@ -701,8 +701,7 @@ static bool canRenameComdat(
   // group including global vars.
   Comdat *C = F.getComdat();
   for (auto &&CM : make_range(ComdatMembers.equal_range(C))) {
-    if (dyn_cast<GlobalAlias>(CM.second))
-      continue;
+    assert(!isa<GlobalAlias>(CM.second));
     Function *FM = dyn_cast<Function>(CM.second);
     if (FM != &F)
       return false;
@@ -742,18 +741,8 @@ void FuncPGOInstrumentation<Edge, BBInfo>::renameComdatFunction() {
   NewComdat->setSelectionKind(OrigComdat->getSelectionKind());
 
   for (auto &&CM : make_range(ComdatMembers.equal_range(OrigComdat))) {
-    if (GlobalAlias *GA = dyn_cast<GlobalAlias>(CM.second)) {
-      // For aliases, change the name directly.
-      assert(dyn_cast<Function>(GA->getAliasee()->stripPointerCasts()) == &F);
-      std::string OrigGAName = GA->getName().str();
-      GA->setName(Twine(GA->getName() + "." + Twine(FunctionHash)));
-      GlobalAlias::create(GlobalValue::WeakAnyLinkage, OrigGAName, GA);
-      continue;
-    }
     // Must be a function.
-    Function *CF = dyn_cast<Function>(CM.second);
-    assert(CF);
-    CF->setComdat(NewComdat);
+    cast<Function>(CM.second)->setComdat(NewComdat);
   }
 }
 

diff  --git a/llvm/test/Transforms/PGOProfile/comdat_rename.ll b/llvm/test/Transforms/PGOProfile/comdat_rename.ll
index 53fc7e430cf1..828bac7eda0b 100644
--- a/llvm/test/Transforms/PGOProfile/comdat_rename.ll
+++ b/llvm/test/Transforms/PGOProfile/comdat_rename.ll
@@ -10,6 +10,14 @@ define linkonce_odr void @f() comdat($f) {
   ret void
 }
 
+; Not rename Comdat with an alias (an alias is an address-taken user).
+$f_with_alias = comdat any
+; CHECK: $f_with_alias = comdat any
+define linkonce_odr void @f_with_alias() comdat {
+  ret void
+}
+ at f_alias = alias void (), void ()* @f_with_alias
+
 ; Not rename Comdat with right linkage.
 $nf = comdat any
 ; CHECK: $nf = comdat any


        


More information about the llvm-commits mailing list