Recurring LLVM debug info fix

This commit is contained in:
Andrey Guskov
2015-04-16 19:31:16 +03:00
parent f62ad11fb0
commit 189e892b96
3 changed files with 62 additions and 18 deletions

21
ctx.cpp
View File

@@ -347,8 +347,10 @@ FunctionEmitContext::FunctionEmitContext(Function *func, Symbol *funSym,
#if defined(LLVM_3_2) || defined(LLVM_3_3)
llvm::DIScope scope = llvm::DIScope(m->diBuilder->getCU());
#else // LLVM_3_4+
#elif defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
llvm::DIScope scope = llvm::DIScope(m->diCompileUnit);
#else // LLVM 3.7+
llvm::DIScope scope = m->diCompileUnit;
#endif
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
AssertPos(currentPos, scope.Verify());
@@ -375,10 +377,12 @@ FunctionEmitContext::FunctionEmitContext(Function *func, Symbol *funSym,
Assert(diSubprogramType.isCompositeType());
llvm::DICompositeType diSubprogramType_n =
static_cast<llvm::DICompositeType>(diSubprogramType);
int flags = llvm::DIDescriptor::FlagPrototyped;
#else // LLVM 3.7+
Assert(llvm::isa<llvm::MDCompositeTypeBase>(diSubprogramType));
llvm::DICompositeType diSubprogramType_n =
llvm::cast<llvm::MDCompositeTypeBase>(diSubprogramType);
int flags = llvm::DebugNode::FlagPrototyped;
#endif
std::string mangledName = llvmFunction->getName();
@@ -388,7 +392,6 @@ FunctionEmitContext::FunctionEmitContext(Function *func, Symbol *funSym,
bool isStatic = (funSym->storageClass == SC_STATIC);
bool isOptimized = (g->opt.level > 0);
int firstLine = funcStartPos.first_line;
int flags = (llvm::DIDescriptor::FlagPrototyped);
diSubprogram =
m->diBuilder->createFunction(diFile /* scope */, funSym->name,
@@ -1737,7 +1740,12 @@ FunctionEmitContext::EmitVariableDebugInfo(Symbol *sym) {
#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) && !defined(LLVM_3_5)// LLVM 3.6+
llvm::DIExpression E = m->diBuilder->createExpression();
llvm::Instruction *declareInst =
m->diBuilder->insertDeclare(sym->storagePtr, var, E, bblock);
m->diBuilder->insertDeclare(sym->storagePtr, var, E,
#if !defined(LLVM_3_6) // LLVM 3.7++
llvm::DebugLoc::get(sym->pos.first_line,
sym->pos.first_column, scope),
#endif
bblock);
#else
llvm::Instruction *declareInst =
m->diBuilder->insertDeclare(sym->storagePtr, var, bblock);
@@ -1778,7 +1786,12 @@ FunctionEmitContext::EmitFunctionParameterDebugInfo(Symbol *sym, int argNum) {
#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) && !defined(LLVM_3_5)// LLVM 3.6+
llvm::DIExpression E = m->diBuilder->createExpression();
llvm::Instruction *declareInst =
m->diBuilder->insertDeclare(sym->storagePtr, var, E, bblock);
m->diBuilder->insertDeclare(sym->storagePtr, var, E,
#if !defined(LLVM_3_6) // LLVM 3.7++
llvm::DebugLoc::get(sym->pos.first_line,
sym->pos.first_column, scope),
#endif
bblock);
#else
llvm::Instruction *declareInst =
m->diBuilder->insertDeclare(sym->storagePtr, var, bblock);

View File

@@ -172,7 +172,7 @@ lStripUnusedDebugInfo(llvm::Module *module) {
return;
#if defined (LLVM_3_2) || defined (LLVM_3_3)|| defined (LLVM_3_4)|| defined (LLVM_3_5)
std::set<llvm::Value *> SPall;
#else // LLVN 3.6++
#else // LLVM 3.6++
std::set<llvm::Metadata *> SPall;
#endif
// OK, now we are to determine which functions actually survived the
@@ -232,14 +232,15 @@ lStripUnusedDebugInfo(llvm::Module *module) {
if (llvm::NamedMDNode *cuNodes = module->getNamedMetadata("llvm.dbg.cu")) {
for (unsigned i = 0, ie = cuNodes->getNumOperands(); i != ie; ++i) {
llvm::MDNode *cuNode = cuNodes->getOperand(i);
#if defined (LLVM_3_2) || defined (LLVM_3_3)|| defined (LLVM_3_4)|| defined (LLVM_3_5) || (LLVM_3_6)
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
llvm::DICompileUnit cu(cuNode);
llvm::DIArray subprograms = cu.getSubprograms();
#else // LLVM 3.7+
llvm::DICompileUnit cu(llvm::cast<llvm::MDCompileUnit>(cuNode));
llvm::DIArray subprograms = cu->getSubprograms();
#endif
llvm::DIArray subprograms = cu.getSubprograms();
#if defined (LLVM_3_2) || defined (LLVM_3_3)|| defined (LLVM_3_4)|| defined (LLVM_3_5) || (LLVM_3_6)
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
if (subprograms.getNumElements() == 0)
#else // LLVM 3.7+
if (subprograms.size() == 0)
@@ -255,7 +256,7 @@ lStripUnusedDebugInfo(llvm::Module *module) {
#endif
// determine what functions of those extracted belong to the unit
#if defined (LLVM_3_2) || defined (LLVM_3_3)|| defined (LLVM_3_4)|| defined (LLVM_3_5) || (LLVM_3_6)
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
for (unsigned j = 0, je = subprograms.getNumElements(); j != je; ++j)
#else // LLVM 3.7+
for (unsigned j = 0, je = subprograms.size(); j != je; ++j)
@@ -274,7 +275,7 @@ lStripUnusedDebugInfo(llvm::Module *module) {
Debug(SourcePos(), "%d / %d functions left in module with debug "
"info.", (int)usedSubprograms.size(),
#if defined (LLVM_3_2) || defined (LLVM_3_3)|| defined (LLVM_3_4)|| defined (LLVM_3_5) || (LLVM_3_6)
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
(int)subprograms.getNumElements());
#else // LLVM 3.7+
(int)subprograms.size());
@@ -332,22 +333,27 @@ lStripUnusedDebugInfo(llvm::Module *module) {
m->diBuilder->getOrCreateArray(llvm::ArrayRef<llvm::Value *>(usedSubprograms));
cuNode->replaceOperandWith(9, replNode);
#else // LLVM 3.6+
llvm::DIArray nodeSPs = cu.getSubprograms();
// And now we can go and stuff it into the unit with some
// confidence...
#if defined(LLVM_3_6)
llvm::DIArray nodeSPs = cu.getSubprograms();
Assert(nodeSPs.getNumElements() == subprograms.getNumElements());
for (int i = 0; i < (int)nodeSPs.getNumElements(); ++i)
Assert(nodeSPs.getElement(i) == subprograms.getElement(i));
// And now we can go and stuff it into the unit with some
// confidence...
llvm::MDNode *replNode = llvm::MDNode::get(module->getContext(),
llvm::ArrayRef<llvm::Metadata *>(usedSubprograms));
cu.replaceSubprograms(llvm::DIArray(replNode));
#else // LLVM 3.7+
llvm::DIArray nodeSPs = cu->getSubprograms();
Assert(nodeSPs.size() == subprograms.size());
for (int i = 0; i < (int)nodeSPs.size(); ++i)
Assert(nodeSPs [i] == subprograms [i]);
cu.replaceSubprograms(llvm::MDTuple::get(cu->getContext(),
llvm::ArrayRef<llvm::Metadata *>(usedSubprograms)));
// And now we can go and stuff it into the unit with some
// confidence...
cu->replaceSubprograms(llvm::MDTuple::get(cu->getContext(),
llvm::ArrayRef<llvm::Metadata *>(usedSubprograms)));
#endif
#endif
}

View File

@@ -103,9 +103,14 @@ lCreateDIArray(llvm::DIType eltType, int count) {
#endif
subs.push_back(sub);
llvm::DIArray subArray = m->diBuilder->getOrCreateArray(subs);
#if defined (LLVM_3_2) || defined (LLVM_3_3) || defined (LLVM_3_4) || defined (LLVM_3_5) || defined (LLVM_3_6)
uint64_t size = eltType.getSizeInBits() * count;
uint64_t align = eltType.getAlignInBits();
#else // LLVM 3.7++
uint64_t size = eltType->getSizeInBits() * count;
uint64_t align = eltType->getAlignInBits();
#endif
return m->diBuilder->createArrayType(size, align, eltType, subArray);
}
@@ -583,8 +588,13 @@ AtomicType::GetDIType(llvm::DIDescriptor scope) const {
llvm::Metadata *sub = m->diBuilder->getOrCreateSubrange(0, g->target->getVectorWidth());
#endif
llvm::DIArray subArray = m->diBuilder->getOrCreateArray(sub);
#if defined (LLVM_3_3)|| defined (LLVM_3_4) || defined (LLVM_3_5) || defined (LLVM_3_6)
uint64_t size = unifType.getSizeInBits() * g->target->getVectorWidth();
uint64_t align = unifType.getAlignInBits() * g->target->getVectorWidth();
#else // LLVM 3.7++
uint64_t size = unifType->getSizeInBits() * g->target->getVectorWidth();
uint64_t align = unifType->getAlignInBits()* g->target->getVectorWidth();
#endif
return m->diBuilder->createVectorType(size, align, unifType, subArray);
}
else {
@@ -862,8 +872,13 @@ EnumType::GetDIType(llvm::DIDescriptor scope) const {
llvm::Metadata *sub = m->diBuilder->getOrCreateSubrange(0, g->target->getVectorWidth());
#endif
llvm::DIArray subArray = m->diBuilder->getOrCreateArray(sub);
#if defined (LLVM_3_3)|| defined (LLVM_3_4) || defined (LLVM_3_5) || defined (LLVM_3_6)
uint64_t size = diType.getSizeInBits() * g->target->getVectorWidth();
uint64_t align = diType.getAlignInBits() * g->target->getVectorWidth();
#else // LLVM 3.7++
uint64_t size = diType->getSizeInBits() * g->target->getVectorWidth();
uint64_t align = diType->getAlignInBits()* g->target->getVectorWidth();
#endif
return m->diBuilder->createVectorType(size, align, diType, subArray);
}
case Variability::SOA: {
@@ -1759,12 +1774,17 @@ VectorType::GetDIType(llvm::DIDescriptor scope) const {
#endif
llvm::DIArray subArray = m->diBuilder->getOrCreateArray(sub);
uint64_t sizeBits = eltType.getSizeInBits() * numElements;
// vectors of varying types are already naturally aligned to the
// machine's vector width, but arrays of uniform types need to be
// explicitly aligned to the machines natural vector alignment.
#if defined (LLVM_3_3)|| defined (LLVM_3_4) || defined (LLVM_3_5) || defined (LLVM_3_6)
uint64_t sizeBits = eltType.getSizeInBits() * numElements;
uint64_t align = eltType.getAlignInBits();
#else // LLVM 3.7++
uint64_t sizeBits = eltType->getSizeInBits() * numElements;
uint64_t align = eltType->getAlignInBits();
#endif
if (IsUniformType())
align = 4 * g->target->getNativeVectorWidth();
@@ -2189,8 +2209,13 @@ StructType::GetDIType(llvm::DIDescriptor scope) const {
// start of the structure.
for (unsigned int i = 0; i < elementTypes.size(); ++i) {
llvm::DIType eltType = GetElementType(i)->GetDIType(scope);
#if defined (LLVM_3_2) || defined (LLVM_3_3) || defined (LLVM_3_4) || defined (LLVM_3_5) || defined (LLVM_3_6)
uint64_t eltAlign = eltType.getAlignInBits();
uint64_t eltSize = eltType.getSizeInBits();
#else // LLVM 3.7++
uint64_t eltAlign = eltType->getAlignInBits();
uint64_t eltSize = eltType->getSizeInBits();
#endif
Assert(eltAlign != 0);
// The alignment for the entire structure is the maximum of the