[llvm] r283490 - [PGO] Create weak alias for the renamed Comdat function

Sean Silva via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 8 10:48:34 PDT 2016


Can you please add a comment in the source explaining exactly what kind of
non-standard conforming code we are trying to handle with this? We usually
don't make concessions for non-standard conforming code without a precise
explanation of where/how the non-conforming code arises.

-- Sean Silva

On Thu, Oct 6, 2016 at 1:38 PM, Rong Xu via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> Author: xur
> Date: Thu Oct  6 15:38:13 2016
> New Revision: 283490
>
> URL: http://llvm.org/viewvc/llvm-project?rev=283490&view=rev
> Log:
> [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
>
> Modified:
>     llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
>     llvm/trunk/test/Transforms/PGOProfile/comdat_rename.ll
>
> Modified: llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/
> Transforms/Instrumentation/PGOInstrumentation.cpp?rev=
> 283490&r1=283489&r2=283490&view=diff
> ============================================================
> ==================
> --- llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
> (original)
> +++ llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp Thu
> Oct  6 15:38:13 2016
> @@ -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();
> @@ -467,7 +469,9 @@ void FuncPGOInstrumentation<Edge, BBInfo
>      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.
>
> Modified: llvm/trunk/test/Transforms/PGOProfile/comdat_rename.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/
> Transforms/PGOProfile/comdat_rename.ll?rev=283490&r1=
> 283489&r2=283490&view=diff
> ============================================================
> ==================
> --- llvm/trunk/test/Transforms/PGOProfile/comdat_rename.ll (original)
> +++ llvm/trunk/test/Transforms/PGOProfile/comdat_rename.ll Thu Oct  6
> 15:38:13 2016
> @@ -50,6 +50,12 @@ define linkonce_odr void @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() {
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161008/681fc340/attachment.html>


More information about the llvm-commits mailing list