[PATCH] D25339: [PGO] Create weak alias for the renamed Comdat function
Rong Xu via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 6 11:45:39 PDT 2016
xur created this revision.
xur added a reviewer: davidxl.
xur added a subscriber: llvm-commits.
Add a weak alias to the renamed Comdat function in IR level instrumentation, using it's original name. This ensures the same behavior w/ and w/o IR instrumentation, even for non standard conforming code.
https://reviews.llvm.org/D25339
Files:
lib/Transforms/Instrumentation/PGOInstrumentation.cpp
test/Transforms/PGOProfile/comdat_rename.ll
Index: test/Transforms/PGOProfile/comdat_rename.ll
===================================================================
--- test/Transforms/PGOProfile/comdat_rename.ll
+++ test/Transforms/PGOProfile/comdat_rename.ll
@@ -50,6 +50,12 @@
; Rename AvailableExternallyLinkage functions
; ELFONLY-DAG: $aef.[[SINGLEBB_HASH]] = comdat any
+
+; ELFONLY: @f = weak alias void (), void ()* @f.[[SINGLEBB_HASH]]
+; ELFONLY: @f_with_alias = weak alias void (), void ()* @f_with_alias.[[SINGLEBB_HASH]]
+; ELFONLY: @af = weak alias void (...), void (...)* @af.[[SINGLEBB_HASH]]
+; ELFONLY: @aef = weak alias void (), void ()* @aef.[[SINGLEBB_HASH]]
+
define available_externally void @aef() {
; ELFONLY: define linkonce_odr void @aef.[[SINGLEBB_HASH]]() comdat {
; COFFONLY: define available_externally void @aef() {
Index: lib/Transforms/Instrumentation/PGOInstrumentation.cpp
===================================================================
--- lib/Transforms/Instrumentation/PGOInstrumentation.cpp
+++ lib/Transforms/Instrumentation/PGOInstrumentation.cpp
@@ -439,9 +439,11 @@
void FuncPGOInstrumentation<Edge, BBInfo>::renameComdatFunction() {
if (!canRenameComdat(F, ComdatMembers))
return;
+ std::string OrigName = F.getName().str();
std::string NewFuncName =
Twine(F.getName() + "." + Twine(FunctionHash)).str();
F.setName(Twine(NewFuncName));
+ GlobalAlias::create(GlobalValue::WeakAnyLinkage, OrigName, &F);
FuncName = Twine(FuncName + "." + Twine(FunctionHash)).str();
Comdat *NewComdat;
Module *M = F.getParent();
@@ -467,7 +469,9 @@
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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25339.73827.patch
Type: text/x-patch
Size: 2014 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161006/1c113e13/attachment.bin>
More information about the llvm-commits
mailing list