[llvm] r270743 - [IR] Copy comdats in GlobalObject::copyAttributesFrom

Rafael EspĂ­ndola via llvm-commits llvm-commits at lists.llvm.org
Wed May 25 12:56:24 PDT 2016


Thanks!

On 25 May 2016 at 14:36, Reid Kleckner via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> Author: rnk
> Date: Wed May 25 13:36:22 2016
> New Revision: 270743
>
> URL: http://llvm.org/viewvc/llvm-project?rev=270743&view=rev
> Log:
> [IR] Copy comdats in GlobalObject::copyAttributesFrom
>
> This is probably correct for all uses except cross-module IR linking,
> where we need to move the comdat from the source module to the
> destination module.
>
> Fixes PR27870.
>
> Reviewers: majnemer
>
> Differential Revision: http://reviews.llvm.org/D20631
>
> Added:
>     llvm/trunk/test/Transforms/DeadArgElim/comdat.ll
> Modified:
>     llvm/trunk/lib/IR/Globals.cpp
>     llvm/trunk/lib/Linker/IRMover.cpp
>
> Modified: llvm/trunk/lib/IR/Globals.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Globals.cpp?rev=270743&r1=270742&r2=270743&view=diff
> ==============================================================================
> --- llvm/trunk/lib/IR/Globals.cpp (original)
> +++ llvm/trunk/lib/IR/Globals.cpp Wed May 25 13:36:22 2016
> @@ -96,6 +96,7 @@ void GlobalObject::copyAttributesFrom(co
>    if (const auto *GV = dyn_cast<GlobalObject>(Src)) {
>      setAlignment(GV->getAlignment());
>      setSection(GV->getSection());
> +    setComdat(const_cast<GlobalObject *>(GV)->getComdat());
>    }
>  }
>
>
> Modified: llvm/trunk/lib/Linker/IRMover.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/IRMover.cpp?rev=270743&r1=270742&r2=270743&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Linker/IRMover.cpp (original)
> +++ llvm/trunk/lib/Linker/IRMover.cpp Wed May 25 13:36:22 2016
> @@ -622,6 +622,11 @@ GlobalValue *IRLinker::copyGlobalValuePr
>
>    NewGV->copyAttributesFrom(SGV);
>
> +  // Don't copy the comdat, it's from the original module. We'll handle it
> +  // later.
> +  if (auto *NewGO = dyn_cast<GlobalObject>(NewGV))
> +    NewGO->setComdat(nullptr);
> +
>    // Remove these copied constants in case this stays a declaration, since
>    // they point to the source module. If the def is linked the values will
>    // be mapped in during linkFunctionBody.
>
> Added: llvm/trunk/test/Transforms/DeadArgElim/comdat.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/DeadArgElim/comdat.ll?rev=270743&view=auto
> ==============================================================================
> --- llvm/trunk/test/Transforms/DeadArgElim/comdat.ll (added)
> +++ llvm/trunk/test/Transforms/DeadArgElim/comdat.ll Wed May 25 13:36:22 2016
> @@ -0,0 +1,14 @@
> +; RUN: opt -S < %s -deadargelim | FileCheck %s
> +
> +$f = comdat any
> +
> +define void @f() comdat {
> +  call void @g(i32 0)
> +  ret void
> +}
> +
> +define internal void @g(i32 %dead) comdat($f) {
> +  ret void
> +}
> +
> +; CHECK: define internal void @g() comdat($f) {
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list