|
@@ -1182,35 +1182,26 @@ static void AddDIGlobalVariable(DIBuilder &Builder, DIGlobalVariable *LocDIGV,
|
|
LocDIGV->getScope(), Name, GV->getName(), LocDIGV->getFile(),
|
|
LocDIGV->getScope(), Name, GV->getName(), LocDIGV->getFile(),
|
|
LocDIGV->getLine(), DITy, false, GV);
|
|
LocDIGV->getLine(), DITy, false, GV);
|
|
|
|
|
|
- DICompileUnit *DICU = dyn_cast<DICompileUnit>(LocDIGV->getScope());
|
|
|
|
- if (!DICU) {
|
|
|
|
- DISubprogram *DIS = dyn_cast<DISubprogram>(LocDIGV->getScope());
|
|
|
|
- if (DIS) {
|
|
|
|
- // Find the DICU which has this Subprogram.
|
|
|
|
- NamedMDNode *CompileUnits = GV->getParent()->getNamedMetadata("llvm.dbg.cu");
|
|
|
|
- DXASSERT_NOMSG(CompileUnits);
|
|
|
|
- for (unsigned I = 0, E = CompileUnits->getNumOperands(); I != E; ++I) {
|
|
|
|
- auto *CU = cast<DICompileUnit>(CompileUnits->getOperand(I));
|
|
|
|
- DXASSERT(CU , "Expected valid compile unit");
|
|
|
|
-
|
|
|
|
- for (DISubprogram *SP : CU->getSubprograms()) {
|
|
|
|
- if (SP == DIS) {
|
|
|
|
- DICU = CU;
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ DICompileUnit *DICU = nullptr;
|
|
|
|
+ std::vector<Metadata *> AllGVs;
|
|
|
|
+ std::vector<Metadata *>::iterator locIt;
|
|
|
|
+ for (auto itDICU : DbgInfoFinder.compile_units()) {
|
|
|
|
+ MDTuple *GTuple = cast_or_null<MDTuple>(itDICU->getRawGlobalVariables());
|
|
|
|
+ if (!GTuple)
|
|
|
|
+ continue;
|
|
|
|
+ AllGVs.assign(GTuple->operands().begin(), GTuple->operands().end());
|
|
|
|
+ locIt = std::find(AllGVs.begin(), AllGVs.end(), LocDIGV);
|
|
|
|
+ if (locIt == AllGVs.end())
|
|
|
|
+ continue;
|
|
|
|
+ DICU = itDICU;
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
DXASSERT_NOMSG(DICU);
|
|
DXASSERT_NOMSG(DICU);
|
|
|
|
+ if (!DICU)
|
|
|
|
+ return;
|
|
|
|
+
|
|
// Add global to CU.
|
|
// Add global to CU.
|
|
- auto *GlobalVariables = DICU->getRawGlobalVariables();
|
|
|
|
- DXASSERT_NOMSG(GlobalVariables);
|
|
|
|
- MDTuple *GTuple = cast<MDTuple>(GlobalVariables);
|
|
|
|
- std::vector<Metadata *> AllGVs(GTuple->operands().begin(),
|
|
|
|
- GTuple->operands().end());
|
|
|
|
if (removeLocDIGV) {
|
|
if (removeLocDIGV) {
|
|
- auto locIt = std::find(AllGVs.begin(), AllGVs.end(), LocDIGV);
|
|
|
|
AllGVs.erase(locIt);
|
|
AllGVs.erase(locIt);
|
|
}
|
|
}
|
|
AllGVs.emplace_back(EltDIGV);
|
|
AllGVs.emplace_back(EltDIGV);
|