LLVM debug info fix, again

This commit is contained in:
Andrey Guskov
2015-04-23 19:00:54 +03:00
parent a0cbd7e33a
commit 5defbf25f1
9 changed files with 334 additions and 128 deletions

View File

@@ -917,12 +917,16 @@ lDefineConstantInt(const char *name, int val, llvm::Module *module,
symbolTable->AddVariable(sym); symbolTable->AddVariable(sym);
if (m->diBuilder != NULL) { if (m->diBuilder != NULL) {
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
llvm::DIFile file; llvm::DIFile file;
llvm::DIType diType = sym->type->GetDIType(file); llvm::DIType diType = sym->type->GetDIType(file);
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
Assert(diType.Verify()); Assert(diType.Verify());
#else // LLVM 3.7+ #else // LLVM 3.7+
//comming soon llvm::MDFile *file =
m->diBuilder->createFile(m->diCompileUnit->getFilename(),
m->diCompileUnit->getDirectory());
llvm::MDType *diType = sym->type->GetDIType(file);
// Assert(diType.Verify());
#endif #endif
// FIXME? DWARF says that this (and programIndex below) should // FIXME? DWARF says that this (and programIndex below) should
// have the DW_AT_artifical attribute. It's not clear if this // have the DW_AT_artifical attribute. It's not clear if this
@@ -1015,12 +1019,16 @@ lDefineProgramIndex(llvm::Module *module, SymbolTable *symbolTable) {
symbolTable->AddVariable(sym); symbolTable->AddVariable(sym);
if (m->diBuilder != NULL) { if (m->diBuilder != NULL) {
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
llvm::DIFile file; llvm::DIFile file;
llvm::DIType diType = sym->type->GetDIType(file); llvm::DIType diType = sym->type->GetDIType(file);
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
Assert(diType.Verify()); Assert(diType.Verify());
#else // LLVM 3.7+ #else // LLVM 3.7+
//comming soon llvm::MDFile *file =
m->diBuilder->createFile(m->diCompileUnit->getFilename(),
m->diCompileUnit->getDirectory());
llvm::MDType *diType = sym->type->GetDIType(file);
// Assert(diType.Verify());
#endif #endif
#if defined(LLVM_3_6)// LLVM 3.6+ #if defined(LLVM_3_6)// LLVM 3.6+
llvm::Constant *sym_const_storagePtr = llvm::dyn_cast<llvm::Constant>(sym->storagePtr); llvm::Constant *sym_const_storagePtr = llvm::dyn_cast<llvm::Constant>(sym->storagePtr);

117
ctx.cpp
View File

@@ -337,12 +337,11 @@ FunctionEmitContext::FunctionEmitContext(Function *func, Symbol *funSym,
/* If debugging is enabled, tell the debug information emission /* If debugging is enabled, tell the debug information emission
code about this new function */ code about this new function */
diFile = funcStartPos.GetDIFile();
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) #if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
diFile = funcStartPos.GetDIFile();
AssertPos(currentPos, diFile.Verify()); AssertPos(currentPos, diFile.Verify());
#else // LLVM 3.7+ #else // LLVM 3.7+
//comming soon diFile = funcStartPos.GetDIFile();
#endif #endif
#if defined(LLVM_3_2) || defined(LLVM_3_3) #if defined(LLVM_3_2) || defined(LLVM_3_3)
@@ -350,16 +349,16 @@ FunctionEmitContext::FunctionEmitContext(Function *func, Symbol *funSym,
#elif defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) #elif defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
llvm::DIScope scope = llvm::DIScope(m->diCompileUnit); llvm::DIScope scope = llvm::DIScope(m->diCompileUnit);
#else // LLVM 3.7+ #else // LLVM 3.7+
llvm::DIScope scope = m->diCompileUnit; llvm::MDScope *scope = m->diCompileUnit;
#endif #endif
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(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::DIType diSubprogramType;
AssertPos(currentPos, scope.Verify()); AssertPos(currentPos, scope.Verify());
#else // LLVM 3.7+ #else // LLVM 3.7+
//comming soon llvm::MDType *diSubprogramType = NULL;
#endif #endif
const FunctionType *functionType = function->GetType(); const FunctionType *functionType = function->GetType();
llvm::DIType diSubprogramType;
if (functionType == NULL) if (functionType == NULL)
AssertPos(currentPos, m->errorCount > 0); AssertPos(currentPos, m->errorCount > 0);
else { else {
@@ -380,8 +379,8 @@ FunctionEmitContext::FunctionEmitContext(Function *func, Symbol *funSym,
int flags = llvm::DIDescriptor::FlagPrototyped; int flags = llvm::DIDescriptor::FlagPrototyped;
#else // LLVM 3.7+ #else // LLVM 3.7+
Assert(llvm::isa<llvm::MDCompositeTypeBase>(diSubprogramType)); Assert(llvm::isa<llvm::MDCompositeTypeBase>(diSubprogramType));
llvm::DICompositeType diSubprogramType_n = llvm::MDSubroutineType *diSubprogramType_n =
llvm::cast<llvm::MDCompositeTypeBase>(diSubprogramType); llvm::cast<llvm::MDSubroutineType>(getDICompositeType(diSubprogramType));
int flags = llvm::DebugNode::FlagPrototyped; int flags = llvm::DebugNode::FlagPrototyped;
#endif #endif
@@ -393,18 +392,23 @@ FunctionEmitContext::FunctionEmitContext(Function *func, Symbol *funSym,
bool isOptimized = (g->opt.level > 0); bool isOptimized = (g->opt.level > 0);
int firstLine = funcStartPos.first_line; int firstLine = funcStartPos.first_line;
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
diSubprogram = diSubprogram =
m->diBuilder->createFunction(diFile /* scope */, funSym->name, m->diBuilder->createFunction(diFile /* scope */, funSym->name,
mangledName, diFile, mangledName, diFile,
firstLine, diSubprogramType_n, firstLine, diSubprogramType_n,
isStatic, true, /* is defn */ isStatic, true, /* is defn */
firstLine, firstLine, flags,
flags,
isOptimized, llvmFunction); isOptimized, llvmFunction);
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
AssertPos(currentPos, diSubprogram.Verify()); AssertPos(currentPos, diSubprogram.Verify());
#else // LLVM 3.7+ #else // LLVM 3.7+
//comming soon diSubprogram =
m->diBuilder->createFunction(diFile /* scope */, funSym->name,
mangledName, diFile,
firstLine, diSubprogramType_n,
isStatic, true, /* is defn */
firstLine, flags,
isOptimized, llvmFunction);
#endif #endif
/* And start a scope representing the initial function scope */ /* And start a scope representing the initial function scope */
@@ -1650,7 +1654,11 @@ FunctionEmitContext::GetDebugPos() const {
void void
FunctionEmitContext::AddDebugPos(llvm::Value *value, const SourcePos *pos, FunctionEmitContext::AddDebugPos(llvm::Value *value, const SourcePos *pos,
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
llvm::DIScope *scope) { llvm::DIScope *scope) {
#else // LLVM 3.7++
llvm::MDScope *scope) {
#endif
llvm::Instruction *inst = llvm::dyn_cast<llvm::Instruction>(value); llvm::Instruction *inst = llvm::dyn_cast<llvm::Instruction>(value);
if (inst != NULL && m->diBuilder) { if (inst != NULL && m->diBuilder) {
SourcePos p = pos ? *pos : currentPos; SourcePos p = pos ? *pos : currentPos;
@@ -1659,7 +1667,7 @@ FunctionEmitContext::AddDebugPos(llvm::Value *value, const SourcePos *pos,
// the standard library or the like; don't add debug positions // the standard library or the like; don't add debug positions
// for those functions // for those functions
inst->setDebugLoc(llvm::DebugLoc::get(p.first_line, p.first_column, inst->setDebugLoc(llvm::DebugLoc::get(p.first_line, p.first_column,
scope ? *scope : GetDIScope())); scope ? scope : GetDIScope()));
} }
} }
@@ -1667,13 +1675,19 @@ FunctionEmitContext::AddDebugPos(llvm::Value *value, const SourcePos *pos,
void void
FunctionEmitContext::StartScope() { FunctionEmitContext::StartScope() {
if (m->diBuilder != NULL) { if (m->diBuilder != NULL) {
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
llvm::DIScope parentScope; llvm::DIScope parentScope;
llvm::DILexicalBlock lexicalBlock;
#else // LLVM 3.7++
llvm::MDScope *parentScope;
llvm::MDLexicalBlock *lexicalBlock;
#endif
if (debugScopes.size() > 0) if (debugScopes.size() > 0)
parentScope = debugScopes.back(); parentScope = debugScopes.back();
else else
parentScope = diSubprogram; parentScope = diSubprogram;
llvm::DILexicalBlock lexicalBlock = lexicalBlock =
m->diBuilder->createLexicalBlock(parentScope, diFile, m->diBuilder->createLexicalBlock(parentScope, diFile,
currentPos.first_line, currentPos.first_line,
#if defined(LLVM_3_5) #if defined(LLVM_3_5)
@@ -1705,7 +1719,11 @@ FunctionEmitContext::EndScope() {
} }
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
llvm::DIScope llvm::DIScope
#else // LLVM 3.7+
llvm::MDScope*
#endif
FunctionEmitContext::GetDIScope() const { FunctionEmitContext::GetDIScope() const {
AssertPos(currentPos, debugScopes.size() > 0); AssertPos(currentPos, debugScopes.size() > 0);
return debugScopes.back(); return debugScopes.back();
@@ -1717,14 +1735,16 @@ FunctionEmitContext::EmitVariableDebugInfo(Symbol *sym) {
if (m->diBuilder == NULL) if (m->diBuilder == NULL)
return; return;
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
llvm::DIScope scope = GetDIScope(); llvm::DIScope scope = GetDIScope();
llvm::DIType diType = sym->type->GetDIType(scope); llvm::DIType diType = sym->type->GetDIType(scope);
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
AssertPos(currentPos, diType.Verify()); AssertPos(currentPos, diType.Verify());
#else // LLVM 3.7+
//comming soon
#endif
llvm::DIVariable var = llvm::DIVariable var =
#else // LLVM 3.7+
llvm::MDScope *scope = GetDIScope();
llvm::MDType *diType = sym->type->GetDIType(scope);
llvm::MDLocalVariable *var =
#endif
m->diBuilder->createLocalVariable(llvm::dwarf::DW_TAG_auto_variable, m->diBuilder->createLocalVariable(llvm::dwarf::DW_TAG_auto_variable,
scope, scope,
sym->name, sym->name,
@@ -1734,23 +1754,22 @@ FunctionEmitContext::EmitVariableDebugInfo(Symbol *sym) {
true /* preserve through opts */); true /* preserve through opts */);
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) #if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
AssertPos(currentPos, var.Verify()); AssertPos(currentPos, var.Verify());
#else // LLVM 3.7+
//comming soon
#endif
#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 = llvm::Instruction *declareInst =
m->diBuilder->insertDeclare(sym->storagePtr, var, E, m->diBuilder->insertDeclare(sym->storagePtr, var,
#if !defined(LLVM_3_6) // LLVM 3.7++ #if defined(LLVM_3_6)
m->diBuilder->createExpression(),
#endif
bblock);
AddDebugPos(declareInst, &sym->pos, &scope);
#else // LLVM 3.7++
llvm::Instruction *declareInst =
m->diBuilder->insertDeclare(sym->storagePtr, var,
m->diBuilder->createExpression(),
llvm::DebugLoc::get(sym->pos.first_line, llvm::DebugLoc::get(sym->pos.first_line,
sym->pos.first_column, scope), sym->pos.first_column, scope),
#endif
bblock); bblock);
#else AddDebugPos(declareInst, &sym->pos, scope);
llvm::Instruction *declareInst =
m->diBuilder->insertDeclare(sym->storagePtr, var, bblock);
#endif #endif
AddDebugPos(declareInst, &sym->pos, &scope);
} }
@@ -1759,16 +1778,17 @@ FunctionEmitContext::EmitFunctionParameterDebugInfo(Symbol *sym, int argNum) {
if (m->diBuilder == NULL) if (m->diBuilder == NULL)
return; return;
int flags = 0;
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
llvm::DIScope scope = diSubprogram; llvm::DIScope scope = diSubprogram;
llvm::DIType diType = sym->type->GetDIType(scope); llvm::DIType diType = sym->type->GetDIType(scope);
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
AssertPos(currentPos, diType.Verify()); AssertPos(currentPos, diType.Verify());
#else // LLVM 3.7+
//comming soon
#endif
int flags = 0;
llvm::DIVariable var = llvm::DIVariable var =
#else // LLVM 3.7+
llvm::MDScope *scope = diSubprogram;
llvm::MDType *diType = sym->type->GetDIType(scope);
llvm::MDLocalVariable *var =
#endif
m->diBuilder->createLocalVariable(llvm::dwarf::DW_TAG_arg_variable, m->diBuilder->createLocalVariable(llvm::dwarf::DW_TAG_arg_variable,
scope, scope,
sym->name, sym->name,
@@ -1777,26 +1797,25 @@ FunctionEmitContext::EmitFunctionParameterDebugInfo(Symbol *sym, int argNum) {
diType, diType,
true /* preserve through opts */, true /* preserve through opts */,
flags, flags,
argNum+1); argNum + 1);
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) #if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
AssertPos(currentPos, var.Verify()); AssertPos(currentPos, var.Verify());
#else // LLVM 3.7+
//comming soon
#endif
#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 = llvm::Instruction *declareInst =
m->diBuilder->insertDeclare(sym->storagePtr, var, E, m->diBuilder->insertDeclare(sym->storagePtr, var,
#if !defined(LLVM_3_6) // LLVM 3.7++ #if defined(LLVM_3_6)
m->diBuilder->createExpression(),
#endif
bblock);
AddDebugPos(declareInst, &sym->pos, &scope);
#else // LLVM 3.7++
llvm::Instruction *declareInst =
m->diBuilder->insertDeclare(sym->storagePtr, var,
m->diBuilder->createExpression(),
llvm::DebugLoc::get(sym->pos.first_line, llvm::DebugLoc::get(sym->pos.first_line,
sym->pos.first_column, scope), sym->pos.first_column, scope),
#endif
bblock); bblock);
#else AddDebugPos(declareInst, &sym->pos, scope);
llvm::Instruction *declareInst =
m->diBuilder->insertDeclare(sym->storagePtr, var, bblock);
#endif #endif
AddDebugPos(declareInst, &sym->pos, &scope);
} }

22
ctx.h
View File

@@ -352,7 +352,11 @@ public:
Instructions stored using Value pointers; the code here returns Instructions stored using Value pointers; the code here returns
silently if it's not actually given an instruction. */ silently if it's not actually given an instruction. */
void AddDebugPos(llvm::Value *instruction, const SourcePos *pos = NULL, void AddDebugPos(llvm::Value *instruction, const SourcePos *pos = NULL,
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
llvm::DIScope *scope = NULL); llvm::DIScope *scope = NULL);
#else // LLVM 3.7++
llvm::MDScope *scope = NULL);
#endif
/** Inform the debugging information generation code that a new scope /** Inform the debugging information generation code that a new scope
is starting in the source program. */ is starting in the source program. */
@@ -364,7 +368,11 @@ public:
/** Returns the llvm::DIScope corresponding to the current program /** Returns the llvm::DIScope corresponding to the current program
scope. */ scope. */
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
llvm::DIScope GetDIScope() const; llvm::DIScope GetDIScope() const;
#else // LLVM 3.7++
llvm::MDScope *GetDIScope() const;
#endif
/** Emits debugging information for the variable represented by /** Emits debugging information for the variable represented by
sym. */ sym. */
@@ -675,6 +683,7 @@ private:
emitted. */ emitted. */
std::vector<CFInfo *> controlFlowInfo; std::vector<CFInfo *> controlFlowInfo;
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
/** DIFile object corresponding to the source file where the current /** DIFile object corresponding to the source file where the current
function was defined (used for debugging info). */ function was defined (used for debugging info). */
llvm::DIFile diFile; llvm::DIFile diFile;
@@ -685,10 +694,19 @@ private:
/** These correspond to the current set of nested scopes in the /** These correspond to the current set of nested scopes in the
function. */ function. */
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
std::vector<llvm::DILexicalBlock> debugScopes; std::vector<llvm::DILexicalBlock> debugScopes;
#else // LLVM 3.7++ #else // LLVM 3.7++
std::vector<llvm::DIScope> debugScopes; /** MDFile object corresponding to the source file where the current
function was defined (used for debugging info). */
llvm::MDFile *diFile;
/** MDSubprogram corresponding to this function (used for debugging
info). */
llvm::MDSubprogram *diSubprogram;
/** These correspond to the current set of nested scopes in the
function. */
std::vector<llvm::MDScope *> debugScopes;
#endif #endif
/** True if a 'launch' statement has been encountered in the function. */ /** True if a 'launch' statement has been encountered in the function. */

View File

@@ -1407,15 +1407,19 @@ SourcePos::SourcePos(const char *n, int fl, int fc, int ll, int lc) {
} }
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
llvm::DIFile llvm::DIFile
#else // LLVM 3.7+
llvm::MDFile*
#endif
SourcePos::GetDIFile() const { SourcePos::GetDIFile() const {
std::string directory, filename; std::string directory, filename;
GetDirectoryAndFileName(g->currentDirectory, name, &directory, &filename); GetDirectoryAndFileName(g->currentDirectory, name, &directory, &filename);
llvm::DIFile ret = m->diBuilder->createFile(filename, directory);
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(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::DIFile ret = m->diBuilder->createFile(filename, directory);
Assert(ret.Verify()); Assert(ret.Verify());
#else // LLVM 3.7+ #else // LLVM 3.7+
//comming soon llvm::MDFile *ret = m->diBuilder->createFile(filename, directory);
#endif #endif
return ret; return ret;
} }

17
ispc.h
View File

@@ -78,9 +78,6 @@ namespace llvm {
class ConstantValue; class ConstantValue;
class DataLayout; class DataLayout;
class DIBuilder; class DIBuilder;
class DIDescriptor;
class DIFile;
class DIType;
class Function; class Function;
class FunctionType; class FunctionType;
class LLVMContext; class LLVMContext;
@@ -89,6 +86,15 @@ namespace llvm {
class TargetMachine; class TargetMachine;
class Type; class Type;
class Value; class Value;
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
class DIFile;
class DIType;
class DIDescriptor;
#else // LLVM 3.7++
class MDFile;
class MDType;
class MDScope;
#endif
} }
@@ -138,8 +144,13 @@ struct SourcePos {
/** Prints the filename and line/column range to standard output. */ /** Prints the filename and line/column range to standard output. */
void Print() const; void Print() const;
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
/** Returns a LLVM DIFile object that represents the SourcePos's file */ /** Returns a LLVM DIFile object that represents the SourcePos's file */
llvm::DIFile GetDIFile() const; llvm::DIFile GetDIFile() const;
#else
/** Returns a LLVM MDFile object that represents the SourcePos's file */
llvm::MDFile *GetDIFile() const;
#endif
bool operator==(const SourcePos &p2) const; bool operator==(const SourcePos &p2) const;
}; };

View File

@@ -207,17 +207,17 @@ lStripUnusedDebugInfo(llvm::Module *module) {
} }
if (scope.isSubprogram()) { if (scope.isSubprogram()) {
#else // LLVM 3.7+ #else // LLVM 3.7+
llvm::DILocation dloc(llvm::cast<llvm::MDLocation>(node)); llvm::MDLocation *dloc = llvm::cast<llvm::MDLocation>(node);
llvm::DIScope scope = dloc->getScope(); llvm::MDScope *scope = dloc->getScope();
node = dloc->getInlinedAt(); node = dloc->getInlinedAt();
// now following a chain of nested scopes // now following a chain of nested scopes
while (!0) { while (!0) {
if (llvm::isa<llvm::MDLexicalBlockFile>(scope)) if (llvm::isa<llvm::MDLexicalBlockFile>(scope))
scope = llvm::DILexicalBlockFile(llvm::cast<llvm::MDLexicalBlockFile>(scope))->getScope(); scope = llvm::cast<llvm::MDLexicalBlockFile>(scope)->getScope();
else if (llvm::isa<llvm::MDLexicalBlockBase>(scope)) else if (llvm::isa<llvm::MDLexicalBlockBase>(scope))
scope = llvm::DILexicalBlock(llvm::cast<llvm::MDLexicalBlockBase>(scope))->getScope(); scope = llvm::cast<llvm::MDLexicalBlockBase>(scope)->getScope();
else if (llvm::isa<llvm::MDNamespace>(scope)) else if (llvm::isa<llvm::MDNamespace>(scope))
scope = llvm::DINameSpace(llvm::cast<llvm::MDNamespace>(scope))->getScope(); scope = llvm::cast<llvm::MDNamespace>(scope)->getScope();
else break; else break;
} }
if (llvm::isa<llvm::MDSubprogram>(scope)) { if (llvm::isa<llvm::MDSubprogram>(scope)) {
@@ -235,18 +235,14 @@ lStripUnusedDebugInfo(llvm::Module *module) {
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(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::DICompileUnit cu(cuNode);
llvm::DIArray subprograms = cu.getSubprograms(); llvm::DIArray subprograms = cu.getSubprograms();
if (subprograms.getNumElements() == 0) {
#else // LLVM 3.7+ #else // LLVM 3.7+
llvm::DICompileUnit cu(llvm::cast<llvm::MDCompileUnit>(cuNode)); llvm::MDCompileUnit *cu = llvm::cast<llvm::MDCompileUnit>(cuNode);
llvm::DIArray subprograms = cu->getSubprograms(); llvm::MDSubprogramArray subprograms = cu->getSubprograms();
#endif if (subprograms.size() == 0) {
#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)
#endif #endif
continue; continue;
}
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) #if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5)
std::set<llvm::Value *> SPset; std::set<llvm::Value *> SPset;
std::vector<llvm::Value *> usedSubprograms; std::vector<llvm::Value *> usedSubprograms;
@@ -345,7 +341,7 @@ lStripUnusedDebugInfo(llvm::Module *module) {
llvm::ArrayRef<llvm::Metadata *>(usedSubprograms)); llvm::ArrayRef<llvm::Metadata *>(usedSubprograms));
cu.replaceSubprograms(llvm::DIArray(replNode)); cu.replaceSubprograms(llvm::DIArray(replNode));
#else // LLVM 3.7+ #else // LLVM 3.7+
llvm::DIArray nodeSPs = cu->getSubprograms(); llvm::MDSubprogramArray nodeSPs = cu->getSubprograms();
Assert(nodeSPs.size() == subprograms.size()); Assert(nodeSPs.size() == subprograms.size());
for (int i = 0; i < (int)nodeSPs.size(); ++i) for (int i = 0; i < (int)nodeSPs.size(); ++i)
Assert(nodeSPs [i] == subprograms [i]); Assert(nodeSPs [i] == subprograms [i]);
@@ -702,8 +698,8 @@ Module::AddGlobalVariable(const std::string &name, const Type *type, Expr *initE
} }
if (diBuilder) { if (diBuilder) {
llvm::DIFile file = pos.GetDIFile();
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) #if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5)
llvm::DIFile file = pos.GetDIFile();
llvm::DIGlobalVariable var = diBuilder->createGlobalVariable( llvm::DIGlobalVariable var = diBuilder->createGlobalVariable(
name, name,
file, file,
@@ -712,6 +708,7 @@ Module::AddGlobalVariable(const std::string &name, const Type *type, Expr *initE
(sym->storageClass == SC_STATIC), (sym->storageClass == SC_STATIC),
sym->storagePtr); sym->storagePtr);
#elif defined(LLVM_3_6) #elif defined(LLVM_3_6)
llvm::DIFile file = pos.GetDIFile();
llvm::Constant *sym_const_storagePtr = llvm::dyn_cast<llvm::Constant>(sym->storagePtr); llvm::Constant *sym_const_storagePtr = llvm::dyn_cast<llvm::Constant>(sym->storagePtr);
Assert(sym_const_storagePtr); Assert(sym_const_storagePtr);
llvm::DIGlobalVariable var = diBuilder->createGlobalVariable( llvm::DIGlobalVariable var = diBuilder->createGlobalVariable(
@@ -724,6 +721,7 @@ Module::AddGlobalVariable(const std::string &name, const Type *type, Expr *initE
(sym->storageClass == SC_STATIC), (sym->storageClass == SC_STATIC),
sym_const_storagePtr); sym_const_storagePtr);
#else // LLVM 3.7+ #else // LLVM 3.7+
llvm::MDFile *file = pos.GetDIFile();
llvm::Constant *sym_const_storagePtr = llvm::dyn_cast<llvm::Constant>(sym->storagePtr); llvm::Constant *sym_const_storagePtr = llvm::dyn_cast<llvm::Constant>(sym->storagePtr);
Assert(sym_const_storagePtr); Assert(sym_const_storagePtr);
diBuilder->createGlobalVariable( diBuilder->createGlobalVariable(

View File

@@ -161,8 +161,10 @@ public:
/** The diBuilder manages generating debugging information */ /** The diBuilder manages generating debugging information */
llvm::DIBuilder *diBuilder; llvm::DIBuilder *diBuilder;
#if !defined(LLVM_3_2) && !defined(LLVM_3_3) #if defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
llvm::DICompileUnit diCompileUnit; llvm::DICompileUnit diCompileUnit;
#elif !defined(LLVM_3_2) && !defined(LLVM_3_3) // LLVM 3.7++
llvm::MDCompileUnit *diCompileUnit;
#endif // LLVM_3_4+ #endif // LLVM_3_4+
private: private:

206
type.cpp
View File

@@ -77,10 +77,13 @@ lShouldPrintName(const std::string &name) {
} }
/** Utility routine to create a llvm DIArray type of the given number of /** Utility routine to create a llvm array type of the given number of
the given element type. */ the given element type. */
static llvm::DIType #if defined (LLVM_3_2) || defined (LLVM_3_3) || defined (LLVM_3_4) || defined (LLVM_3_5) || defined (LLVM_3_6)
lCreateDIArray(llvm::DIType eltType, int count) { static llvm::DIType lCreateDIArray(llvm::DIType eltType, int count) {
#else // LLVM 3.7++
static llvm::MDType *lCreateDIArray(llvm::MDType *eltType, int count) {
#endif
#ifdef LLVM_3_2 #ifdef LLVM_3_2
int lowerBound = 0, upperBound = count-1; int lowerBound = 0, upperBound = count-1;
@@ -102,12 +105,13 @@ lCreateDIArray(llvm::DIType eltType, int count) {
std::vector<llvm::Metadata *> subs; std::vector<llvm::Metadata *> subs;
#endif #endif
subs.push_back(sub); 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) #if defined (LLVM_3_2) || defined (LLVM_3_3) || defined (LLVM_3_4) || defined (LLVM_3_5) || defined (LLVM_3_6)
llvm::DIArray subArray = m->diBuilder->getOrCreateArray(subs);
uint64_t size = eltType.getSizeInBits() * count; uint64_t size = eltType.getSizeInBits() * count;
uint64_t align = eltType.getAlignInBits(); uint64_t align = eltType.getAlignInBits();
#else // LLVM 3.7++ #else // LLVM 3.7++
llvm::DebugNodeArray subArray = m->diBuilder->getOrCreateArray(subs);
uint64_t size = eltType->getSizeInBits() * count; uint64_t size = eltType->getSizeInBits() * count;
uint64_t align = eltType->getAlignInBits(); uint64_t align = eltType->getAlignInBits();
#endif #endif
@@ -521,14 +525,21 @@ AtomicType::LLVMType(llvm::LLVMContext *ctx) const {
} }
llvm::DIType #if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
AtomicType::GetDIType(llvm::DIDescriptor scope) const { llvm::DIType AtomicType::GetDIType(llvm::DIDescriptor scope) const {
#else //LLVM 3.7++
llvm::MDType *AtomicType::GetDIType(llvm::MDScope *scope) const {
#endif
Assert(variability.type != Variability::Unbound); Assert(variability.type != Variability::Unbound);
if (variability.type == Variability::Uniform) { if (variability.type == Variability::Uniform) {
switch (basicType) { switch (basicType) {
case TYPE_VOID: case TYPE_VOID:
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
return llvm::DIType(); return llvm::DIType();
#else //LLVM 3.7++
return NULL;
#endif
case TYPE_BOOL: case TYPE_BOOL:
return m->diBuilder->createBasicType("bool", 32 /* size */, 32 /* align */, return m->diBuilder->createBasicType("bool", 32 /* size */, 32 /* align */,
llvm::dwarf::DW_ATE_unsigned); llvm::dwarf::DW_ATE_unsigned);
@@ -575,11 +586,14 @@ AtomicType::GetDIType(llvm::DIDescriptor scope) const {
break; break;
default: default:
FATAL("unhandled basic type in AtomicType::GetDIType()"); FATAL("unhandled basic type in AtomicType::GetDIType()");
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
return llvm::DIType(); return llvm::DIType();
#else //LLVM 3.7++
return NULL;
#endif
} }
} }
else if (variability == Variability::Varying) { else if (variability == Variability::Varying) {
llvm::DIType unifType = GetAsUniformType()->GetDIType(scope);
#ifdef LLVM_3_2 #ifdef LLVM_3_2
llvm::Value *sub = m->diBuilder->getOrCreateSubrange(0, g->target->getVectorWidth()-1); llvm::Value *sub = m->diBuilder->getOrCreateSubrange(0, g->target->getVectorWidth()-1);
#elif defined (LLVM_3_3)|| defined (LLVM_3_4) || defined (LLVM_3_5) #elif defined (LLVM_3_3)|| defined (LLVM_3_4) || defined (LLVM_3_5)
@@ -587,11 +601,14 @@ AtomicType::GetDIType(llvm::DIDescriptor scope) const {
#else // LLVM 3.6++ #else // LLVM 3.6++
llvm::Metadata *sub = m->diBuilder->getOrCreateSubrange(0, g->target->getVectorWidth()); llvm::Metadata *sub = m->diBuilder->getOrCreateSubrange(0, g->target->getVectorWidth());
#endif #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) #if defined (LLVM_3_3)|| defined (LLVM_3_4) || defined (LLVM_3_5) || defined (LLVM_3_6)
llvm::DIArray subArray = m->diBuilder->getOrCreateArray(sub);
llvm::DIType unifType = GetAsUniformType()->GetDIType(scope);
uint64_t size = unifType.getSizeInBits() * g->target->getVectorWidth(); uint64_t size = unifType.getSizeInBits() * g->target->getVectorWidth();
uint64_t align = unifType.getAlignInBits() * g->target->getVectorWidth(); uint64_t align = unifType.getAlignInBits() * g->target->getVectorWidth();
#else // LLVM 3.7++ #else // LLVM 3.7++
llvm::DebugNodeArray subArray = m->diBuilder->getOrCreateArray(sub);
llvm::MDType *unifType = GetAsUniformType()->GetDIType(scope);
uint64_t size = unifType->getSizeInBits() * g->target->getVectorWidth(); uint64_t size = unifType->getSizeInBits() * g->target->getVectorWidth();
uint64_t align = unifType->getAlignInBits()* g->target->getVectorWidth(); uint64_t align = unifType->getAlignInBits()* g->target->getVectorWidth();
#endif #endif
@@ -827,8 +844,12 @@ EnumType::LLVMType(llvm::LLVMContext *ctx) const {
} }
llvm::DIType #if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
EnumType::GetDIType(llvm::DIDescriptor scope) const { llvm::DIType EnumType::GetDIType(llvm::DIDescriptor scope) const {
#else // LLVM 3.7++
llvm::MDType *EnumType::GetDIType(llvm::MDScope *scope) const {
#endif
#if defined (LLVM_3_2) || defined (LLVM_3_3) || defined (LLVM_3_4) || defined (LLVM_3_5) #if defined (LLVM_3_2) || defined (LLVM_3_3) || defined (LLVM_3_4) || defined (LLVM_3_5)
std::vector<llvm::Value *> enumeratorDescriptors; std::vector<llvm::Value *> enumeratorDescriptors;
#else // LLVM 3.6++ #else // LLVM 3.6++
@@ -847,19 +868,25 @@ EnumType::GetDIType(llvm::DIDescriptor scope) const {
m->diBuilder->createEnumerator(enumerators[i]->name, enumeratorValue); m->diBuilder->createEnumerator(enumerators[i]->name, enumeratorValue);
enumeratorDescriptors.push_back(descriptor); enumeratorDescriptors.push_back(descriptor);
} }
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
llvm::DIArray elementArray = llvm::DIArray elementArray =
m->diBuilder->getOrCreateArray(enumeratorDescriptors); m->diBuilder->getOrCreateArray(enumeratorDescriptors);
llvm::DIFile diFile = pos.GetDIFile(); llvm::DIFile diFile = pos.GetDIFile();
llvm::DIType diType = llvm::DIType diType =
m->diBuilder->createEnumerationType(diFile, name, diFile, pos.first_line, m->diBuilder->createEnumerationType(diFile, name, diFile, pos.first_line,
32 /* size in bits */, 32 /* size in bits */,
32 /* align in bits */, 32 /* align in bits */,
elementArray elementArray, llvm::DIType());
, llvm::DIType() #else // LLVM 3.7++
); llvm::DebugNodeArray elementArray =
m->diBuilder->getOrCreateArray(enumeratorDescriptors);
llvm::MDFile *diFile = pos.GetDIFile();
llvm::MDType *diType =
m->diBuilder->createEnumerationType(diFile, name, diFile, pos.first_line,
32 /* size in bits */,
32 /* align in bits */,
elementArray, NULL);
#endif
switch (variability.type) { switch (variability.type) {
case Variability::Uniform: case Variability::Uniform:
return diType; return diType;
@@ -871,11 +898,12 @@ EnumType::GetDIType(llvm::DIDescriptor scope) const {
#else // LLVM 3.6++ #else // LLVM 3.6++
llvm::Metadata *sub = m->diBuilder->getOrCreateSubrange(0, g->target->getVectorWidth()); llvm::Metadata *sub = m->diBuilder->getOrCreateSubrange(0, g->target->getVectorWidth());
#endif #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) #if defined (LLVM_3_3)|| defined (LLVM_3_4) || defined (LLVM_3_5) || defined (LLVM_3_6)
llvm::DIArray subArray = m->diBuilder->getOrCreateArray(sub);
uint64_t size = diType.getSizeInBits() * g->target->getVectorWidth(); uint64_t size = diType.getSizeInBits() * g->target->getVectorWidth();
uint64_t align = diType.getAlignInBits() * g->target->getVectorWidth(); uint64_t align = diType.getAlignInBits() * g->target->getVectorWidth();
#else // LLVM 3.7++ #else // LLVM 3.7++
llvm::DebugNodeArray subArray = m->diBuilder->getOrCreateArray(sub);
uint64_t size = diType->getSizeInBits() * g->target->getVectorWidth(); uint64_t size = diType->getSizeInBits() * g->target->getVectorWidth();
uint64_t align = diType->getAlignInBits()* g->target->getVectorWidth(); uint64_t align = diType->getAlignInBits()* g->target->getVectorWidth();
#endif #endif
@@ -886,7 +914,11 @@ EnumType::GetDIType(llvm::DIDescriptor scope) const {
} }
default: default:
FATAL("Unexpected variability in EnumType::GetDIType()"); FATAL("Unexpected variability in EnumType::GetDIType()");
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
return llvm::DIType(); return llvm::DIType();
#else //LLVM 3.7++
return NULL;
#endif
} }
} }
@@ -1220,14 +1252,21 @@ PointerType::LLVMType(llvm::LLVMContext *ctx) const {
} }
llvm::DIType #if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
PointerType::GetDIType(llvm::DIDescriptor scope) const { llvm::DIType PointerType::GetDIType(llvm::DIDescriptor scope) const {
if (baseType == NULL) { if (baseType == NULL) {
Assert(m->errorCount > 0); Assert(m->errorCount > 0);
return llvm::DIType(); return llvm::DIType();
} }
llvm::DIType diTargetType = baseType->GetDIType(scope); llvm::DIType diTargetType = baseType->GetDIType(scope);
#else //LLVM 3.7++
llvm::MDType *PointerType::GetDIType(llvm::MDScope *scope) const {
if (baseType == NULL) {
Assert(m->errorCount > 0);
return NULL;
}
llvm::MDType *diTargetType = baseType->GetDIType(scope);
#endif
int bitsSize = g->target->is32Bit() ? 32 : 64; int bitsSize = g->target->is32Bit() ? 32 : 64;
int ptrAlignBits = bitsSize; int ptrAlignBits = bitsSize;
switch (variability.type) { switch (variability.type) {
@@ -1236,8 +1275,11 @@ PointerType::GetDIType(llvm::DIDescriptor scope) const {
ptrAlignBits); ptrAlignBits);
case Variability::Varying: { case Variability::Varying: {
// emit them as an array of pointers // emit them as an array of pointers
llvm::DIType eltType = m->diBuilder->createPointerType(diTargetType, #if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
bitsSize, ptrAlignBits); #else //LLVM 3.7++
llvm::MDDerivedType *eltType =
m->diBuilder->createPointerType(diTargetType, bitsSize, ptrAlignBits);
#endif
return lCreateDIArray(eltType, g->target->getVectorWidth()); return lCreateDIArray(eltType, g->target->getVectorWidth());
} }
case Variability::SOA: { case Variability::SOA: {
@@ -1246,7 +1288,11 @@ PointerType::GetDIType(llvm::DIDescriptor scope) const {
} }
default: default:
FATAL("Unexpected variability in PointerType::GetDIType()"); FATAL("Unexpected variability in PointerType::GetDIType()");
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
return llvm::DIType(); return llvm::DIType();
#else //LLVM 3.7++
return NULL;
#endif
} }
} }
@@ -1520,14 +1566,21 @@ ArrayType::TotalElementCount() const {
} }
llvm::DIType #if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
ArrayType::GetDIType(llvm::DIDescriptor scope) const { llvm::DIType ArrayType::GetDIType(llvm::DIDescriptor scope) const {
if (child == NULL) { if (child == NULL) {
Assert(m->errorCount > 0); Assert(m->errorCount > 0);
return llvm::DIType(); return llvm::DIType();
} }
llvm::DIType eltType = child->GetDIType(scope); llvm::DIType eltType = child->GetDIType(scope);
#else //LLVM 3.7++
llvm::MDType *ArrayType::GetDIType(llvm::MDScope *scope) const {
if (child == NULL) {
Assert(m->errorCount > 0);
return NULL;
}
llvm::MDType *eltType = child->GetDIType(scope);
#endif
return lCreateDIArray(eltType, numElements); return lCreateDIArray(eltType, numElements);
} }
@@ -1762,9 +1815,13 @@ VectorType::LLVMType(llvm::LLVMContext *ctx) const {
} }
llvm::DIType #if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
VectorType::GetDIType(llvm::DIDescriptor scope) const { llvm::DIType VectorType::GetDIType(llvm::DIDescriptor scope) const {
llvm::DIType eltType = base->GetDIType(scope); llvm::DIType eltType = base->GetDIType(scope);
#else //LLVM 3.7++
llvm::MDType *VectorType::GetDIType(llvm::MDScope *scope) const {
llvm::MDType *eltType = base->GetDIType(scope);
#endif
#ifdef LLVM_3_2 #ifdef LLVM_3_2
llvm::Value *sub = m->diBuilder->getOrCreateSubrange(0, numElements-1); llvm::Value *sub = m->diBuilder->getOrCreateSubrange(0, numElements-1);
#elif defined (LLVM_3_3)|| defined (LLVM_3_4) || defined (LLVM_3_5) #elif defined (LLVM_3_3)|| defined (LLVM_3_4) || defined (LLVM_3_5)
@@ -1772,15 +1829,16 @@ VectorType::GetDIType(llvm::DIDescriptor scope) const {
#else // LLVM 3.6++ #else // LLVM 3.6++
llvm::Metadata *sub = m->diBuilder->getOrCreateSubrange(0, numElements); llvm::Metadata *sub = m->diBuilder->getOrCreateSubrange(0, numElements);
#endif #endif
llvm::DIArray subArray = m->diBuilder->getOrCreateArray(sub);
// vectors of varying types are already naturally aligned to the // vectors of varying types are already naturally aligned to the
// machine's vector width, but arrays of uniform types need to be // machine's vector width, but arrays of uniform types need to be
// explicitly aligned to the machines natural vector alignment. // 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) #if defined (LLVM_3_3)|| defined (LLVM_3_4) || defined (LLVM_3_5) || defined (LLVM_3_6)
llvm::DIArray subArray = m->diBuilder->getOrCreateArray(sub);
uint64_t sizeBits = eltType.getSizeInBits() * numElements; uint64_t sizeBits = eltType.getSizeInBits() * numElements;
uint64_t align = eltType.getAlignInBits(); uint64_t align = eltType.getAlignInBits();
#else // LLVM 3.7++ #else // LLVM 3.7++
llvm::DebugNodeArray subArray = m->diBuilder->getOrCreateArray(sub);
uint64_t sizeBits = eltType->getSizeInBits() * numElements; uint64_t sizeBits = eltType->getSizeInBits() * numElements;
uint64_t align = eltType->getAlignInBits(); uint64_t align = eltType->getAlignInBits();
#endif #endif
@@ -1796,7 +1854,11 @@ VectorType::GetDIType(llvm::DIDescriptor scope) const {
} }
else { else {
FATAL("Unexpected variability in VectorType::GetDIType()"); FATAL("Unexpected variability in VectorType::GetDIType()");
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
return llvm::DIType(); return llvm::DIType();
#else // LLVM 3.7++
return NULL;
#endif
} }
} }
@@ -2196,8 +2258,11 @@ StructType::LLVMType(llvm::LLVMContext *ctx) const {
} }
llvm::DIType #if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
StructType::GetDIType(llvm::DIDescriptor scope) const { llvm::DIType StructType::GetDIType(llvm::DIDescriptor scope) const {
#else //LLVM 3.7++
llvm::MDType *StructType::GetDIType(llvm::MDScope *scope) const {
#endif
uint64_t currentSize = 0, align = 0; uint64_t currentSize = 0, align = 0;
#if defined (LLVM_3_2) || defined (LLVM_3_3) || defined (LLVM_3_4) || defined (LLVM_3_5) #if defined (LLVM_3_2) || defined (LLVM_3_3) || defined (LLVM_3_4) || defined (LLVM_3_5)
std::vector<llvm::Value *> elementLLVMTypes; std::vector<llvm::Value *> elementLLVMTypes;
@@ -2208,11 +2273,12 @@ StructType::GetDIType(llvm::DIDescriptor scope) const {
// alignment and size, using that to figure out its offset w.r.t. the // alignment and size, using that to figure out its offset w.r.t. the
// start of the structure. // start of the structure.
for (unsigned int i = 0; i < elementTypes.size(); ++i) { 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) #if defined (LLVM_3_2) || defined (LLVM_3_3) || defined (LLVM_3_4) || defined (LLVM_3_5) || defined (LLVM_3_6)
llvm::DIType eltType = GetElementType(i)->GetDIType(scope);
uint64_t eltAlign = eltType.getAlignInBits(); uint64_t eltAlign = eltType.getAlignInBits();
uint64_t eltSize = eltType.getSizeInBits(); uint64_t eltSize = eltType.getSizeInBits();
#else // LLVM 3.7++ #else // LLVM 3.7++
llvm::MDType *eltType = GetElementType(i)->GetDIType(scope);
uint64_t eltAlign = eltType->getAlignInBits(); uint64_t eltAlign = eltType->getAlignInBits();
uint64_t eltSize = eltType->getSizeInBits(); uint64_t eltSize = eltType->getSizeInBits();
#endif #endif
@@ -2228,9 +2294,14 @@ StructType::GetDIType(llvm::DIDescriptor scope) const {
currentSize += eltAlign - (currentSize % eltAlign); currentSize += eltAlign - (currentSize % eltAlign);
Assert((currentSize == 0) || (currentSize % eltAlign) == 0); Assert((currentSize == 0) || (currentSize % eltAlign) == 0);
llvm::DIFile diFile = elementPositions[i].GetDIFile();
int line = elementPositions[i].first_line; int line = elementPositions[i].first_line;
#if defined (LLVM_3_2) || defined (LLVM_3_3) || defined (LLVM_3_4) || defined (LLVM_3_5) || defined (LLVM_3_6)
llvm::DIFile diFile = elementPositions[i].GetDIFile();
llvm::DIType fieldType = llvm::DIType fieldType =
#else // LLVM 3.7++
llvm::MDFile *diFile = elementPositions[i].GetDIFile();
llvm::MDDerivedType *fieldType =
#endif
m->diBuilder->createMemberType(scope, elementNames[i], diFile, m->diBuilder->createMemberType(scope, elementNames[i], diFile,
line, eltSize, eltAlign, line, eltSize, eltAlign,
currentSize, 0, eltType); currentSize, 0, eltType);
@@ -2244,8 +2315,13 @@ StructType::GetDIType(llvm::DIDescriptor scope) const {
if (currentSize > 0 && (currentSize % align)) if (currentSize > 0 && (currentSize % align))
currentSize += align - (currentSize % align); currentSize += align - (currentSize % align);
#if defined (LLVM_3_2) || defined (LLVM_3_3) || defined (LLVM_3_4) || defined (LLVM_3_5) || defined (LLVM_3_6)
llvm::DIArray elements = m->diBuilder->getOrCreateArray(elementLLVMTypes); llvm::DIArray elements = m->diBuilder->getOrCreateArray(elementLLVMTypes);
llvm::DIFile diFile = pos.GetDIFile(); llvm::DIFile diFile = pos.GetDIFile();
#else // LLVM 3.7++
llvm::DebugNodeArray elements = m->diBuilder->getOrCreateArray(elementLLVMTypes);
llvm::MDFile *diFile = pos.GetDIFile();
#endif
return m->diBuilder->createStructType( return m->diBuilder->createStructType(
diFile, diFile,
name, name,
@@ -2254,8 +2330,10 @@ StructType::GetDIType(llvm::DIDescriptor scope) const {
currentSize, // Size in bits currentSize, // Size in bits
align, // Alignment in bits align, // Alignment in bits
0, // Flags 0, // Flags
#if !defined(LLVM_3_2) #if defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
llvm::DIType(), // DerivedFrom llvm::DIType(), // DerivedFrom
#elif !defined(LLVM_3_2) // LLVM 3.7++
NULL,
#endif #endif
elements); elements);
} }
@@ -2485,10 +2563,15 @@ UndefinedStructType::LLVMType(llvm::LLVMContext *ctx) const {
} }
llvm::DIType #if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
UndefinedStructType::GetDIType(llvm::DIDescriptor scope) const { llvm::DIType UndefinedStructType::GetDIType(llvm::DIDescriptor scope) const {
llvm::DIFile diFile = pos.GetDIFile(); llvm::DIFile diFile = pos.GetDIFile();
llvm::DIArray elements; llvm::DIArray elements;
#else //LLVM 3.7++
llvm::MDType *UndefinedStructType::GetDIType(llvm::MDScope *scope) const {
llvm::MDFile *diFile = pos.GetDIFile();
llvm::DebugNodeArray elements;
#endif
return m->diBuilder->createStructType( return m->diBuilder->createStructType(
diFile, diFile,
name, name,
@@ -2497,8 +2580,10 @@ UndefinedStructType::GetDIType(llvm::DIDescriptor scope) const {
0, // Size 0, // Size
0, // Align 0, // Align
0, // Flags 0, // Flags
#if !defined(LLVM_3_2) #if defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
llvm::DIType(), // DerivedFrom llvm::DIType(), // DerivedFrom
#elif !defined(LLVM_3_2) // LLVM 3.7++
NULL,
#endif #endif
elements); elements);
} }
@@ -2752,14 +2837,21 @@ ReferenceType::LLVMType(llvm::LLVMContext *ctx) const {
} }
llvm::DIType #if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
ReferenceType::GetDIType(llvm::DIDescriptor scope) const { llvm::DIType ReferenceType::GetDIType(llvm::DIDescriptor scope) const {
if (targetType == NULL) { if (targetType == NULL) {
Assert(m->errorCount > 0); Assert(m->errorCount > 0);
return llvm::DIType(); return llvm::DIType();
} }
llvm::DIType diTargetType = targetType->GetDIType(scope); llvm::DIType diTargetType = targetType->GetDIType(scope);
#else //LLVM 3.7++
llvm::MDType *ReferenceType::GetDIType(llvm::MDScope *scope) const {
if (targetType == NULL) {
Assert(m->errorCount > 0);
return NULL;
}
llvm::MDType *diTargetType = targetType->GetDIType(scope);
#endif
return m->diBuilder->createReferenceType(llvm::dwarf::DW_TAG_reference_type, return m->diBuilder->createReferenceType(llvm::dwarf::DW_TAG_reference_type,
diTargetType); diTargetType);
} }
@@ -3024,8 +3116,12 @@ FunctionType::LLVMType(llvm::LLVMContext *ctx) const {
} }
llvm::DIType #if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
FunctionType::GetDIType(llvm::DIDescriptor scope) const { llvm::DIType FunctionType::GetDIType(llvm::DIDescriptor scope) const {
#else //LLVM 3.7++
llvm::MDType *FunctionType::GetDIType(llvm::MDScope *scope) const {
#endif
#if defined (LLVM_3_2) || defined (LLVM_3_3) || defined (LLVM_3_4) || defined (LLVM_3_5) #if defined (LLVM_3_2) || defined (LLVM_3_3) || defined (LLVM_3_4) || defined (LLVM_3_5)
std::vector<llvm::Value *> retArgTypes; std::vector<llvm::Value *> retArgTypes;
#else // LLVM 3.6++ #else // LLVM 3.6++
@@ -3036,25 +3132,33 @@ FunctionType::GetDIType(llvm::DIDescriptor scope) const {
const Type *t = GetParameterType(i); const Type *t = GetParameterType(i);
if (t == NULL) if (t == NULL)
#if !defined(LLVM_3_2) && !defined(LLVM_3_3)// LLVM 3.4+ #if defined(LLVM_3_2) || defined(LLVM_3_3)
return llvm::DICompositeType();
#else
return llvm::DIType(); return llvm::DIType();
#elif defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
return llvm::DICompositeType();
#else // LLVM 3.7++
return NULL;
#endif #endif
retArgTypes.push_back(t->GetDIType(scope)); retArgTypes.push_back(t->GetDIType(scope));
} }
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5)
#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) && !defined(LLVM_3_5) // LLVM 3.6+
llvm::DITypeArray retArgTypesArray =
m->diBuilder->getOrCreateTypeArray(retArgTypes);
#else
llvm::DIArray retArgTypesArray = llvm::DIArray retArgTypesArray =
m->diBuilder->getOrCreateArray(llvm::ArrayRef<llvm::Value *>(retArgTypes)); m->diBuilder->getOrCreateArray(llvm::ArrayRef<llvm::Value *>(retArgTypes));
#endif
llvm::DIType diType = llvm::DIType diType =
// FIXME: DIFile // FIXME: DIFile
m->diBuilder->createSubroutineType(llvm::DIFile(), retArgTypesArray); m->diBuilder->createSubroutineType(llvm::DIFile(), retArgTypesArray);
#elif defined(LLVM_3_6)
llvm::DITypeArray retArgTypesArray =
m->diBuilder->getOrCreateTypeArray(retArgTypes);
llvm::DIType diType =
// FIXME: DIFile
m->diBuilder->createSubroutineType(llvm::DIFile(), retArgTypesArray);
#else // LLVM 3.7++
llvm::MDTypeRefArray retArgTypesArray =
m->diBuilder->getOrCreateTypeArray(retArgTypes);
llvm::MDType *diType =
m->diBuilder->createSubroutineType(NULL, retArgTypesArray);
#endif
return diType; return diType;
} }

42
type.h
View File

@@ -222,9 +222,15 @@ public:
/** Returns the LLVM type corresponding to this ispc type */ /** Returns the LLVM type corresponding to this ispc type */
virtual llvm::Type *LLVMType(llvm::LLVMContext *ctx) const = 0; virtual llvm::Type *LLVMType(llvm::LLVMContext *ctx) const = 0;
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
/** Returns the DIType (LLVM's debugging information structure), /** Returns the DIType (LLVM's debugging information structure),
corresponding to this type. */ corresponding to this type. */
virtual llvm::DIType GetDIType(llvm::DIDescriptor scope) const = 0; virtual llvm::DIType GetDIType(llvm::DIDescriptor scope) const = 0;
#else
/** Returns the MDType (LLVM's debugging information structure),
corresponding to this type. */
virtual llvm::MDType *GetDIType(llvm::MDScope *scope) const = 0;
#endif
/** Checks two types for equality. Returns true if they are exactly /** Checks two types for equality. Returns true if they are exactly
the same, false otherwise. */ the same, false otherwise. */
@@ -311,7 +317,11 @@ public:
std::string GetCDeclaration(const std::string &name) const; std::string GetCDeclaration(const std::string &name) const;
llvm::Type *LLVMType(llvm::LLVMContext *ctx) const; llvm::Type *LLVMType(llvm::LLVMContext *ctx) const;
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
llvm::DIType GetDIType(llvm::DIDescriptor scope) const; llvm::DIType GetDIType(llvm::DIDescriptor scope) const;
#else // LLVM 3.7++
llvm::MDType *GetDIType(llvm::MDScope *scope) const;
#endif
/** This enumerator records the basic types that AtomicTypes can be /** This enumerator records the basic types that AtomicTypes can be
built from. */ built from. */
@@ -390,7 +400,11 @@ public:
const std::string &GetEnumName() const { return name; } const std::string &GetEnumName() const { return name; }
llvm::Type *LLVMType(llvm::LLVMContext *ctx) const; llvm::Type *LLVMType(llvm::LLVMContext *ctx) const;
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
llvm::DIType GetDIType(llvm::DIDescriptor scope) const; llvm::DIType GetDIType(llvm::DIDescriptor scope) const;
#else // LLVM 3.7++
llvm::MDType *GetDIType(llvm::MDScope *scope) const;
#endif
/** Provides the enumerators defined in the enum definition. */ /** Provides the enumerators defined in the enum definition. */
void SetEnumerators(const std::vector<Symbol *> &enumerators); void SetEnumerators(const std::vector<Symbol *> &enumerators);
@@ -471,7 +485,11 @@ public:
std::string GetCDeclaration(const std::string &name) const; std::string GetCDeclaration(const std::string &name) const;
llvm::Type *LLVMType(llvm::LLVMContext *ctx) const; llvm::Type *LLVMType(llvm::LLVMContext *ctx) const;
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
llvm::DIType GetDIType(llvm::DIDescriptor scope) const; llvm::DIType GetDIType(llvm::DIDescriptor scope) const;
#else // LLVM 3.7++
llvm::MDType *GetDIType(llvm::MDScope *scope) const;
#endif
static PointerType *Void; static PointerType *Void;
@@ -573,7 +591,11 @@ public:
std::string Mangle() const; std::string Mangle() const;
std::string GetCDeclaration(const std::string &name) const; std::string GetCDeclaration(const std::string &name) const;
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
llvm::DIType GetDIType(llvm::DIDescriptor scope) const; llvm::DIType GetDIType(llvm::DIDescriptor scope) const;
#else // LLVM 3.7++
llvm::MDType *GetDIType(llvm::MDScope *scope) const;
#endif
llvm::ArrayType *LLVMType(llvm::LLVMContext *ctx) const; llvm::ArrayType *LLVMType(llvm::LLVMContext *ctx) const;
/** This method returns the total number of elements in the array, /** This method returns the total number of elements in the array,
@@ -641,7 +663,11 @@ public:
std::string GetCDeclaration(const std::string &name) const; std::string GetCDeclaration(const std::string &name) const;
llvm::Type *LLVMType(llvm::LLVMContext *ctx) const; llvm::Type *LLVMType(llvm::LLVMContext *ctx) const;
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
llvm::DIType GetDIType(llvm::DIDescriptor scope) const; llvm::DIType GetDIType(llvm::DIDescriptor scope) const;
#else // LLVM 3.7++
llvm::MDType *GetDIType(llvm::MDScope *scope) const;
#endif
int GetElementCount() const; int GetElementCount() const;
const AtomicType *GetElementType() const; const AtomicType *GetElementType() const;
@@ -692,7 +718,11 @@ public:
std::string GetCDeclaration(const std::string &name) const; std::string GetCDeclaration(const std::string &name) const;
llvm::Type *LLVMType(llvm::LLVMContext *ctx) const; llvm::Type *LLVMType(llvm::LLVMContext *ctx) const;
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
llvm::DIType GetDIType(llvm::DIDescriptor scope) const; llvm::DIType GetDIType(llvm::DIDescriptor scope) const;
#else // LLVM 3.7++
llvm::MDType *GetDIType(llvm::MDScope *scope) const;
#endif
/** Returns the type of the structure element with the given name (if any). /** Returns the type of the structure element with the given name (if any).
Returns NULL if there is no such named element. */ Returns NULL if there is no such named element. */
@@ -780,7 +810,11 @@ public:
std::string GetCDeclaration(const std::string &name) const; std::string GetCDeclaration(const std::string &name) const;
llvm::Type *LLVMType(llvm::LLVMContext *ctx) const; llvm::Type *LLVMType(llvm::LLVMContext *ctx) const;
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
llvm::DIType GetDIType(llvm::DIDescriptor scope) const; llvm::DIType GetDIType(llvm::DIDescriptor scope) const;
#else // LLVM 3.7++
llvm::MDType *GetDIType(llvm::MDScope *scope) const;
#endif
/** Returns the name of the structure type. (e.g. struct Foo -> "Foo".) */ /** Returns the name of the structure type. (e.g. struct Foo -> "Foo".) */
const std::string &GetStructName() const { return name; } const std::string &GetStructName() const { return name; }
@@ -823,7 +857,11 @@ public:
std::string GetCDeclaration(const std::string &name) const; std::string GetCDeclaration(const std::string &name) const;
llvm::Type *LLVMType(llvm::LLVMContext *ctx) const; llvm::Type *LLVMType(llvm::LLVMContext *ctx) const;
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
llvm::DIType GetDIType(llvm::DIDescriptor scope) const; llvm::DIType GetDIType(llvm::DIDescriptor scope) const;
#else // LLVM 3.7++
llvm::MDType *GetDIType(llvm::MDScope *scope) const;
#endif
private: private:
const Type * const targetType; const Type * const targetType;
@@ -877,7 +915,11 @@ public:
std::string GetCDeclarationForDispatch(const std::string &fname) const; std::string GetCDeclarationForDispatch(const std::string &fname) const;
llvm::Type *LLVMType(llvm::LLVMContext *ctx) const; llvm::Type *LLVMType(llvm::LLVMContext *ctx) const;
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
llvm::DIType GetDIType(llvm::DIDescriptor scope) const; llvm::DIType GetDIType(llvm::DIDescriptor scope) const;
#else // LLVM 3.7++
llvm::MDType *GetDIType(llvm::MDScope *scope) const;
#endif
const Type *GetReturnType() const { return returnType; } const Type *GetReturnType() const { return returnType; }