Skip to content

Commit

Permalink
[PGO] Create weak alias for the renamed Comdat function
Browse files Browse the repository at this point in the history
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.

Differential Revision: http://reviews.llvm.org/D25339


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@283490 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
xur-llvm committed Oct 6, 2016
1 parent f978224 commit bb6f9b5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/Transforms/Instrumentation/PGOInstrumentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,11 @@ template <class Edge, class BBInfo>
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();
Expand All @@ -467,7 +469,9 @@ void FuncPGOInstrumentation<Edge, BBInfo>::renameComdatFunction() {
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.
Expand Down
6 changes: 6 additions & 0 deletions test/Transforms/PGOProfile/comdat_rename.ll
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ define linkonce_odr void @f_with_alias() comdat($f_with_alias) {

; 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() {
Expand Down

0 comments on commit bb6f9b5

Please sign in to comment.