[PATCH] D93451: [Cloning] Copy metadata of global declarations
Ruiling, Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 7 16:26:25 PST 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8dddcc762dd9: [Cloning] Copy metadata of global declarations (authored by ruiling).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D93451/new/
https://reviews.llvm.org/D93451
Files:
llvm/lib/Transforms/Utils/CloneModule.cpp
llvm/test/Other/copy-metadata-of-declaration.ll
Index: llvm/test/Other/copy-metadata-of-declaration.ll
===================================================================
--- /dev/null
+++ llvm/test/Other/copy-metadata-of-declaration.ll
@@ -0,0 +1,10 @@
+; RUN: opt -run-twice -verify -S -o - %s | FileCheck %s
+
+; This test is used to check metadata attached to global variable declarations
+; are copied when CloneModule(). This is required by out-of-tree passes.
+
+; CHECK: @g = external addrspace(64) global i32, !spirv.InOut !0
+
+ at g = external addrspace(64) global i32, !spirv.InOut !0
+
+!0 = !{i32 1}
Index: llvm/lib/Transforms/Utils/CloneModule.cpp
===================================================================
--- llvm/lib/Transforms/Utils/CloneModule.cpp
+++ llvm/lib/Transforms/Utils/CloneModule.cpp
@@ -117,10 +117,17 @@
//
for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
I != E; ++I) {
+ GlobalVariable *GV = cast<GlobalVariable>(VMap[&*I]);
+
+ SmallVector<std::pair<unsigned, MDNode *>, 1> MDs;
+ I->getAllMetadata(MDs);
+ for (auto MD : MDs)
+ GV->addMetadata(MD.first,
+ *MapMetadata(MD.second, VMap, RF_MoveDistinctMDs));
+
if (I->isDeclaration())
continue;
- GlobalVariable *GV = cast<GlobalVariable>(VMap[&*I]);
if (!ShouldCloneDefinition(&*I)) {
// Skip after setting the correct linkage for an external reference.
GV->setLinkage(GlobalValue::ExternalLinkage);
@@ -129,12 +136,6 @@
if (I->hasInitializer())
GV->setInitializer(MapValue(I->getInitializer(), VMap));
- SmallVector<std::pair<unsigned, MDNode *>, 1> MDs;
- I->getAllMetadata(MDs);
- for (auto MD : MDs)
- GV->addMetadata(MD.first,
- *MapMetadata(MD.second, VMap, RF_MoveDistinctMDs));
-
copyComdat(GV, &*I);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93451.315270.patch
Type: text/x-patch
Size: 1830 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210108/e586e185/attachment.bin>
More information about the llvm-commits
mailing list