diff options
author | Roman Tereshin <rtereshin@apple.com> | 2018-04-13 21:23:11 +0000 |
---|---|---|
committer | Roman Tereshin <rtereshin@apple.com> | 2018-04-13 21:23:11 +0000 |
commit | dab10b546873408533adac9b4a7f34bd9d1d2671 (patch) | |
tree | 8711f2e9c442cc6d161c109923f3d156606eff74 /llvm/lib | |
parent | d769eb36ab2b8813f71958cd96183adc611c43eb (diff) | |
download | bcm5719-llvm-dab10b546873408533adac9b4a7f34bd9d1d2671.tar.gz bcm5719-llvm-dab10b546873408533adac9b4a7f34bd9d1d2671.zip |
[DebugInfo][OPT] NFC follow-up on "Fixing a couple of DI duplication bugs of CloneModule"
llvm-svn: 330070
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/IR/DebugInfo.cpp | 57 | ||||
-rw-r--r-- | llvm/lib/Transforms/Utils/CloneFunction.cpp | 43 |
2 files changed, 32 insertions, 68 deletions
diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp index 2a4d0d3a447..830082ffa5f 100644 --- a/llvm/lib/IR/DebugInfo.cpp +++ b/llvm/lib/IR/DebugInfo.cpp @@ -61,52 +61,16 @@ void DebugInfoFinder::reset() { } void DebugInfoFinder::processModule(const Module &M) { - for (auto *CU : M.debug_compile_units()) { - addCompileUnit(CU); - for (auto DIG : CU->getGlobalVariables()) { - if (!addGlobalVariable(DIG)) - continue; - auto *GV = DIG->getVariable(); - processScope(GV->getScope()); - processType(GV->getType().resolve()); - } - for (auto *ET : CU->getEnumTypes()) - processType(ET); - for (auto *RT : CU->getRetainedTypes()) - if (auto *T = dyn_cast<DIType>(RT)) - processType(T); - else - processSubprogram(cast<DISubprogram>(RT)); - for (auto *Import : CU->getImportedEntities()) { - auto *Entity = Import->getEntity().resolve(); - if (auto *T = dyn_cast<DIType>(Entity)) - processType(T); - else if (auto *SP = dyn_cast<DISubprogram>(Entity)) - processSubprogram(SP); - else if (auto *NS = dyn_cast<DINamespace>(Entity)) - processScope(NS->getScope()); - else if (auto *M = dyn_cast<DIModule>(Entity)) - processScope(M->getScope()); - else - llvm_unreachable("unexpected imported entity type"); - } - } + for (auto *CU : M.debug_compile_units()) + processCompileUnit(CU); for (auto &F : M.functions()) { if (auto *SP = cast_or_null<DISubprogram>(F.getSubprogram())) processSubprogram(SP); // There could be subprograms from inlined functions referenced from // instructions only. Walk the function to find them. - for (const BasicBlock &BB : F) { - for (const Instruction &I : BB) { - if (auto *DDI = dyn_cast<DbgDeclareInst>(&I)) - processDeclare(M, DDI); - else if (auto *DVI = dyn_cast<DbgValueInst>(&I)) - processValue(M, DVI); - - if (auto DbgLoc = I.getDebugLoc()) - processLocation(M, DbgLoc.get()); - } - } + for (const BasicBlock &BB : F) + for (const Instruction &I : BB) + processInstruction(M, I); } } @@ -142,6 +106,17 @@ void DebugInfoFinder::processCompileUnit(DICompileUnit *CU) { } } +void DebugInfoFinder::processInstruction(const Module &M, + const Instruction &I) { + if (auto *DDI = dyn_cast<DbgDeclareInst>(&I)) + processDeclare(M, DDI); + else if (auto *DVI = dyn_cast<DbgValueInst>(&I)) + processValue(M, DVI); + + if (auto DbgLoc = I.getDebugLoc()) + processLocation(M, DbgLoc.get()); +} + void DebugInfoFinder::processLocation(const Module &M, const DILocation *Loc) { if (!Loc) return; diff --git a/llvm/lib/Transforms/Utils/CloneFunction.cpp b/llvm/lib/Transforms/Utils/CloneFunction.cpp index 0bb9ebfed95..efef34008ca 100644 --- a/llvm/lib/Transforms/Utils/CloneFunction.cpp +++ b/llvm/lib/Transforms/Utils/CloneFunction.cpp @@ -43,44 +43,36 @@ BasicBlock *llvm::CloneBasicBlock(const BasicBlock *BB, ValueToValueMapTy &VMap, DebugInfoFinder *DIFinder) { DenseMap<const MDNode *, MDNode *> Cache; BasicBlock *NewBB = BasicBlock::Create(BB->getContext(), "", F); - if (BB->hasName()) NewBB->setName(BB->getName()+NameSuffix); + if (BB->hasName()) + NewBB->setName(BB->getName() + NameSuffix); bool hasCalls = false, hasDynamicAllocas = false, hasStaticAllocas = false; Module *TheModule = F ? F->getParent() : nullptr; // Loop over all instructions, and copy them over. - for (BasicBlock::const_iterator II = BB->begin(), IE = BB->end(); - II != IE; ++II) { - - if (DIFinder && TheModule) { - if (auto *DDI = dyn_cast<DbgDeclareInst>(II)) - DIFinder->processDeclare(*TheModule, DDI); - else if (auto *DVI = dyn_cast<DbgValueInst>(II)) - DIFinder->processValue(*TheModule, DVI); - - if (auto DbgLoc = II->getDebugLoc()) - DIFinder->processLocation(*TheModule, DbgLoc.get()); - } + for (const Instruction &I : *BB) { + if (DIFinder && TheModule) + DIFinder->processInstruction(*TheModule, I); - Instruction *NewInst = II->clone(); - if (II->hasName()) - NewInst->setName(II->getName()+NameSuffix); + Instruction *NewInst = I.clone(); + if (I.hasName()) + NewInst->setName(I.getName() + NameSuffix); NewBB->getInstList().push_back(NewInst); - VMap[&*II] = NewInst; // Add instruction map to value. + VMap[&I] = NewInst; // Add instruction map to value. - hasCalls |= (isa<CallInst>(II) && !isa<DbgInfoIntrinsic>(II)); - if (const AllocaInst *AI = dyn_cast<AllocaInst>(II)) { + hasCalls |= (isa<CallInst>(I) && !isa<DbgInfoIntrinsic>(I)); + if (const AllocaInst *AI = dyn_cast<AllocaInst>(&I)) { if (isa<ConstantInt>(AI->getArraySize())) hasStaticAllocas = true; else hasDynamicAllocas = true; } } - + if (CodeInfo) { CodeInfo->ContainsCalls |= hasCalls; CodeInfo->ContainsDynamicAllocas |= hasDynamicAllocas; - CodeInfo->ContainsDynamicAllocas |= hasStaticAllocas && + CodeInfo->ContainsDynamicAllocas |= hasStaticAllocas && BB != &BB->getParent()->getEntryBlock(); } return NewBB; @@ -197,18 +189,15 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc, Returns.push_back(RI); } - for (DISubprogram *ISP : DIFinder.subprograms()) { - if (ISP != SP) { + for (DISubprogram *ISP : DIFinder.subprograms()) + if (ISP != SP) VMap.MD()[ISP].reset(ISP); - } - } for (DICompileUnit *CU : DIFinder.compile_units()) VMap.MD()[CU].reset(CU); - for (auto *Type : DIFinder.types()) { + for (DIType *Type : DIFinder.types()) VMap.MD()[Type].reset(Type); - } // Loop over all of the instructions in the function, fixing up operand // references as we go. This uses VMap to do all the hard work. |