From 0e79f7d11d6a76c8509554bde344d0270fea814d Mon Sep 17 00:00:00 2001 From: Rong Xu Date: Thu, 6 Oct 2016 20:38:13 +0000 Subject: [PGO] Create weak alias for the renamed Comdat function 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 llvm-svn: 283490 --- llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'llvm/lib') diff --git a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp index 4d6a5048797..c2e42177661 100644 --- a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp +++ b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp @@ -439,9 +439,11 @@ template void FuncPGOInstrumentation::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 @@ void FuncPGOInstrumentation::renameComdatFunction() { if (GlobalAlias *GA = dyn_cast(CM.second)) { // For aliases, change the name directly. assert(dyn_cast(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. -- cgit v1.2.3