diff options
author | Ruiling Song <ruiling.song@amd.com> | 2020-12-17 08:03:20 +0800 |
---|---|---|
committer | Ruiling Song <ruiling.song@amd.com> | 2021-01-08 08:21:18 +0800 |
commit | 8dddcc762dd98d53b9406b36e92f62502834187c (patch) | |
tree | 210052f34c1779e2e56b6006a96e253ac81d26f7 /llvm/lib/Transforms/Utils/CloneModule.cpp | |
parent | 6acfc3a78210639367ab8345a9af04e97692a661 (diff) | |
download | llvm-8dddcc762dd98d53b9406b36e92f62502834187c.zip llvm-8dddcc762dd98d53b9406b36e92f62502834187c.tar.gz llvm-8dddcc762dd98d53b9406b36e92f62502834187c.tar.bz2 |
[Cloning] Copy metadata of global declarations
We have modules with metadata on declarations, and out-of-tree passes
use that metadata, and we need to clone those modules. We really expect
such metadata is kept during the clone operation.
Reviewed by: arsenm, aprantl
Differential Revision: https://reviews.llvm.org/D93451
Diffstat (limited to 'llvm/lib/Transforms/Utils/CloneModule.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/CloneModule.cpp | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/llvm/lib/Transforms/Utils/CloneModule.cpp b/llvm/lib/Transforms/Utils/CloneModule.cpp index 2c8c3ab..a6327bb 100644 --- a/llvm/lib/Transforms/Utils/CloneModule.cpp +++ b/llvm/lib/Transforms/Utils/CloneModule.cpp @@ -117,10 +117,17 @@ std::unique_ptr<Module> llvm::CloneModule( // 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 @@ std::unique_ptr<Module> llvm::CloneModule( 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); } |