[PATCH] D21624: Linker: Copy metadata when linking declarations.
Peter Collingbourne via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 24 10:49:23 PDT 2016
This revision was automatically updated to reflect the committed changes.
Closed by commit rL273692: Linker: Copy metadata when linking declarations. (authored by pcc).
Changed prior to commit:
http://reviews.llvm.org/D21624?vs=61709&id=61808#toc
Repository:
rL LLVM
http://reviews.llvm.org/D21624
Files:
llvm/trunk/include/llvm/IR/GlobalObject.h
llvm/trunk/lib/IR/Metadata.cpp
llvm/trunk/lib/Linker/IRMover.cpp
llvm/trunk/test/Linker/metadata-attach.ll
Index: llvm/trunk/include/llvm/IR/GlobalObject.h
===================================================================
--- llvm/trunk/include/llvm/IR/GlobalObject.h
+++ llvm/trunk/include/llvm/IR/GlobalObject.h
@@ -114,6 +114,9 @@
/// Erase all metadata attachments with the given kind.
void eraseMetadata(unsigned KindID);
+ /// Copy metadata from Src.
+ void copyMetadata(const GlobalObject *Src);
+
void copyAttributesFrom(const GlobalValue *Src) override;
// Methods for support type inquiry through isa, cast, and dyn_cast:
Index: llvm/trunk/test/Linker/metadata-attach.ll
===================================================================
--- llvm/trunk/test/Linker/metadata-attach.ll
+++ llvm/trunk/test/Linker/metadata-attach.ll
@@ -0,0 +1,19 @@
+; RUN: llvm-link %s -S -o - | FileCheck %s
+
+; CHECK: @g1 = global i32 0, !attach !0
+ at g1 = global i32 0, !attach !0
+
+; CHECK: @g2 = external global i32, !attach !0
+ at g2 = external global i32, !attach !0
+
+; CHECK: define void @f1() !attach !0
+define void @f1() !attach !0 {
+ call void @f2()
+ store i32 0, i32* @g2
+ ret void
+}
+
+; CHECK: declare !attach !0 void @f2()
+declare !attach !0 void @f2()
+
+!0 = !{}
Index: llvm/trunk/lib/Linker/IRMover.cpp
===================================================================
--- llvm/trunk/lib/Linker/IRMover.cpp
+++ llvm/trunk/lib/Linker/IRMover.cpp
@@ -638,6 +638,12 @@
NewGV->copyAttributesFrom(SGV);
+ if (auto *NewGO = dyn_cast<GlobalObject>(NewGV)) {
+ // Metadata for global variables and function declarations is copied eagerly.
+ if (isa<GlobalVariable>(SGV) || SGV->isDeclaration())
+ NewGO->copyMetadata(cast<GlobalObject>(SGV));
+ }
+
// 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.
@@ -961,10 +967,7 @@
Dst.setPersonalityFn(Src.getPersonalityFn());
// Copy over the metadata attachments without remapping.
- SmallVector<std::pair<unsigned, MDNode *>, 8> MDs;
- Src.getAllMetadata(MDs);
- for (const auto &I : MDs)
- Dst.setMetadata(I.first, I.second);
+ Dst.copyMetadata(&Src);
// Steal arguments and splice the body of Src into Dst.
Dst.stealArgumentListFrom(Src);
Index: llvm/trunk/lib/IR/Metadata.cpp
===================================================================
--- llvm/trunk/lib/IR/Metadata.cpp
+++ llvm/trunk/lib/IR/Metadata.cpp
@@ -1393,6 +1393,13 @@
return getMetadata(getContext().getMDKindID(Kind));
}
+void GlobalObject::copyMetadata(const GlobalObject *Other) {
+ SmallVector<std::pair<unsigned, MDNode *>, 8> MDs;
+ Other->getAllMetadata(MDs);
+ for (auto &MD : MDs)
+ addMetadata(MD.first, *MD.second);
+}
+
void Function::setSubprogram(DISubprogram *SP) {
setMetadata(LLVMContext::MD_dbg, SP);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21624.61808.patch
Type: text/x-patch
Size: 2871 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160624/07630b6c/attachment.bin>
More information about the llvm-commits
mailing list