diff options
-rw-r--r-- | llvm/include/llvm/Transforms/Utils/Cloning.h | 5 | ||||
-rw-r--r-- | llvm/lib/Transforms/Utils/CloneFunction.cpp | 13 | ||||
-rw-r--r-- | llvm/lib/Transforms/Utils/CloneModule.cpp | 1 | ||||
-rw-r--r-- | llvm/unittests/Transforms/Utils/Cloning.cpp | 6 |
4 files changed, 17 insertions, 8 deletions
diff --git a/llvm/include/llvm/Transforms/Utils/Cloning.h b/llvm/include/llvm/Transforms/Utils/Cloning.h index 0bae2bd533c..4f006f2adee 100644 --- a/llvm/include/llvm/Transforms/Utils/Cloning.h +++ b/llvm/include/llvm/Transforms/Utils/Cloning.h @@ -130,11 +130,6 @@ Function *CloneFunction(const Function *F, ValueToValueMapTy &VMap, bool ModuleLevelChanges, ClonedCodeInfo *CodeInfo = nullptr); -/// Clone the module-level debug info associated with OldFunc. The cloned data -/// will point to NewFunc instead. -void CloneDebugInfoMetadata(Function *NewFunc, const Function *OldFunc, - ValueToValueMapTy &VMap); - /// Clone OldFunc into NewFunc, transforming the old arguments into references /// to VMap values. Note that if NewFunc already has basic blocks, the ones /// cloned into it will be added to the end of the function. This function diff --git a/llvm/lib/Transforms/Utils/CloneFunction.cpp b/llvm/lib/Transforms/Utils/CloneFunction.cpp index 05b0a17d9b8..8e1715ac428 100644 --- a/llvm/lib/Transforms/Utils/CloneFunction.cpp +++ b/llvm/lib/Transforms/Utils/CloneFunction.cpp @@ -119,6 +119,15 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc, .addAttributes(NewFunc->getContext(), AttributeSet::FunctionIndex, OldAttrs.getFnAttributes())); + SmallVector<std::pair<unsigned, MDNode *>, 1> MDs; + OldFunc->getAllMetadata(MDs); + for (auto MD : MDs) + NewFunc->setMetadata( + MD.first, + MapMetadata(MD.second, VMap, + ModuleLevelChanges ? RF_None : RF_NoModuleLevelChanges, + TypeMapper, Materializer)); + // Loop over all of the basic blocks in the function, cloning them as // appropriate. Note that we save BE this way in order to handle cloning of // recursive functions into themselves. @@ -187,8 +196,8 @@ static void AddOperand(DICompileUnit *CU, DISubprogramArray SPs, // Clone the module-level debug info associated with OldFunc. The cloned data // will point to NewFunc instead. -void llvm::CloneDebugInfoMetadata(Function *NewFunc, const Function *OldFunc, - ValueToValueMapTy &VMap) { +static void CloneDebugInfoMetadata(Function *NewFunc, const Function *OldFunc, + ValueToValueMapTy &VMap) { DebugInfoFinder Finder; Finder.processModule(*OldFunc->getParent()); diff --git a/llvm/lib/Transforms/Utils/CloneModule.cpp b/llvm/lib/Transforms/Utils/CloneModule.cpp index 494e275991a..929f51bb987 100644 --- a/llvm/lib/Transforms/Utils/CloneModule.cpp +++ b/llvm/lib/Transforms/Utils/CloneModule.cpp @@ -138,7 +138,6 @@ std::unique_ptr<Module> llvm::CloneModule( VMap[&*J] = &*DestI++; } - CloneDebugInfoMetadata(F, &*I, VMap); SmallVector<ReturnInst*, 8> Returns; // Ignore returns cloned. CloneFunctionInto(F, &*I, VMap, /*ModuleLevelChanges=*/true, Returns); } diff --git a/llvm/unittests/Transforms/Utils/Cloning.cpp b/llvm/unittests/Transforms/Utils/Cloning.cpp index b761e4e220e..f06a20f1f9e 100644 --- a/llvm/unittests/Transforms/Utils/Cloning.cpp +++ b/llvm/unittests/Transforms/Utils/Cloning.cpp @@ -464,6 +464,12 @@ TEST_F(CloneModule, Verify) { EXPECT_FALSE(verifyModule(*NewM)); } +TEST_F(CloneModule, OldModuleUnchanged) { + DebugInfoFinder Finder; + Finder.processModule(*OldM); + EXPECT_EQ(1U, Finder.subprogram_count()); +} + TEST_F(CloneModule, Subprogram) { Function *NewF = NewM->getFunction("f"); DISubprogram *SP = NewF->getSubprogram(); |