Fix for LLVM trunk

This commit is contained in:
Andrey Guskov
2015-04-15 16:31:23 +03:00
parent f73091f391
commit 824e47ece7
3 changed files with 36 additions and 32 deletions

View File

@@ -1685,10 +1685,10 @@ FunctionEmitContext::StartScope() {
#endif // LLVM 3.2, 3.3, 3.4 and 3.6+ #endif // LLVM 3.2, 3.3, 3.4 and 3.6+
#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, lexicalBlock.Verify()); AssertPos(currentPos, lexicalBlock.Verify());
#else // LLVM 3.7+
//comming soon
#endif
debugScopes.push_back(lexicalBlock); debugScopes.push_back(lexicalBlock);
#else // LLVM 3.7+
debugScopes.push_back(llvm::cast<llvm::MDLexicalBlockBase>(lexicalBlock));
#endif
} }
} }

4
ctx.h
View File

@@ -685,7 +685,11 @@ 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++
std::vector<llvm::DIScope> debugScopes;
#endif
/** True if a 'launch' statement has been encountered in the function. */ /** True if a 'launch' statement has been encountered in the function. */
bool launchedTasks; bool launchedTasks;

View File

@@ -189,37 +189,37 @@ lStripUnusedDebugInfo(llvm::Module *module) {
// get the instruction`s debugging metadata // get the instruction`s debugging metadata
llvm::MDNode *node = inst->getMetadata(llvm::LLVMContext::MD_dbg); llvm::MDNode *node = inst->getMetadata(llvm::LLVMContext::MD_dbg);
while (node) { while (node) {
// get the scope of the current instruction`s location
// node becomes NULL if this was the original location
#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) || (LLVM_3_6)
llvm::DILocation dloc(node); llvm::DILocation dloc(node);
#else // LLVM 3.7+
llvm::DILocation dloc(llvm::cast<llvm::MDLocation>(node));
#endif
// get the scope of the current instruction`s location
llvm::DIScope scope = dloc.getScope(); llvm::DIScope scope = dloc.getScope();
// node becomes NULL if this was the original location
node = dloc.getOrigLocation(); node = dloc.getOrigLocation();
// now following a chain of nested scopes // now following a chain of nested scopes
while (!0) { while (!0) {
#if defined (LLVM_3_2) || defined (LLVM_3_3)|| defined (LLVM_3_4)|| defined (LLVM_3_5) || (LLVM_3_6)
if (scope.isLexicalBlockFile()) if (scope.isLexicalBlockFile())
scope = llvm::DILexicalBlockFile(scope).getScope(); scope = llvm::DILexicalBlockFile(scope).getScope();
else if (scope.isLexicalBlock()) else if (scope.isLexicalBlock())
scope = llvm::DILexicalBlock(scope).getContext(); scope = llvm::DILexicalBlock(scope).getContext();
else if (scope.isNameSpace()) else if (scope.isNameSpace())
scope = llvm::DINameSpace(scope).getContext(); scope = llvm::DINameSpace(scope).getContext();
#else // LLVM 3.7+
if (llvm::isa<llvm::MDLexicalBlockFile>(scope))
scope = llvm::DILexicalBlockFile(llvm::cast<llvm::MDLexicalBlockFile>(scope)).getContext();
else if (llvm::isa<llvm::MDLexicalBlockBase>(scope))
scope = llvm::DILexicalBlock(llvm::cast<llvm::MDLexicalBlockBase>(scope)).getContext();
else if (llvm::isa<llvm::MDNamespace>(scope))
scope = llvm::DINameSpace(llvm::cast<llvm::MDNamespace>(scope)).getContext();
#endif
else break; else break;
} }
#if defined (LLVM_3_2) || defined (LLVM_3_3)|| defined (LLVM_3_4)|| defined (LLVM_3_5) || (LLVM_3_6)
if (scope.isSubprogram()) { if (scope.isSubprogram()) {
#else // LLVM 3.7+ #else // LLVM 3.7+
llvm::DILocation dloc(llvm::cast<llvm::MDLocation>(node));
llvm::DIScope scope = dloc->getScope();
node = dloc->getInlinedAt();
// now following a chain of nested scopes
while (!0) {
if (llvm::isa<llvm::MDLexicalBlockFile>(scope))
scope = llvm::DILexicalBlockFile(llvm::cast<llvm::MDLexicalBlockFile>(scope))->getScope();
else if (llvm::isa<llvm::MDLexicalBlockBase>(scope))
scope = llvm::DILexicalBlock(llvm::cast<llvm::MDLexicalBlockBase>(scope))->getScope();
else if (llvm::isa<llvm::MDNamespace>(scope))
scope = llvm::DINameSpace(llvm::cast<llvm::MDNamespace>(scope))->getScope();
else break;
}
if (llvm::isa<llvm::MDSubprogram>(scope)) { if (llvm::isa<llvm::MDSubprogram>(scope)) {
#endif #endif
// good, the chain ended with a function; adding // good, the chain ended with a function; adding
@@ -333,25 +333,22 @@ lStripUnusedDebugInfo(llvm::Module *module) {
cuNode->replaceOperandWith(9, replNode); cuNode->replaceOperandWith(9, replNode);
#else // LLVM 3.6+ #else // LLVM 3.6+
llvm::DIArray nodeSPs = cu.getSubprograms(); llvm::DIArray nodeSPs = cu.getSubprograms();
#if defined(LLVM_3_6) // And now we can go and stuff it into the unit with some
// confidence...
#if defined(LLVM_3_6)
Assert(nodeSPs.getNumElements() == subprograms.getNumElements()); Assert(nodeSPs.getNumElements() == subprograms.getNumElements());
for (int i = 0; i < (int)nodeSPs.getNumElements(); ++i) for (int i = 0; i < (int)nodeSPs.getNumElements(); ++i)
Assert(nodeSPs.getElement(i) == subprograms.getElement(i)); Assert(nodeSPs.getElement(i) == subprograms.getElement(i));
#else // LLVM 3.7+ llvm::MDNode *replNode = llvm::MDNode::get(module->getContext(),
llvm::ArrayRef<llvm::Metadata *>(usedSubprograms));
cu.replaceSubprograms(llvm::DIArray(replNode));
#else // LLVM 3.7+
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]);
#endif cu.replaceSubprograms(llvm::MDTuple::get(cu->getContext(),
// And now we can go and stuff it into the unit with some llvm::ArrayRef<llvm::Metadata *>(usedSubprograms)));
// confidence... #endif
llvm::MDNode *replNode = llvm::MDNode::get(module->getContext(),
llvm::ArrayRef<llvm::Metadata *>(usedSubprograms));
#if defined(LLVM_3_6)
cu.replaceSubprograms(llvm::DIArray(replNode));
#else // LLVM 3.7+
cu.replaceSubprograms(llvm::DIArray(llvm::cast<llvm::MDTuple>(replNode)));
#endif
#endif #endif
} }
} }
@@ -1479,8 +1476,11 @@ Module::writeObjectFileOrAssembly(llvm::TargetMachine *targetMachine,
pm.add(dlp); pm.add(dlp);
#endif // LLVM 3.7+ doesn't have DataLayoutPass anymore. #endif // LLVM 3.7+ doesn't have DataLayoutPass anymore.
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6)
llvm::formatted_raw_ostream fos(of->os()); llvm::formatted_raw_ostream fos(of->os());
#else // LLVM 3.7+
llvm::raw_fd_ostream &fos(of->os());
#endif
if (targetMachine->addPassesToEmitFile(pm, fos, fileType)) { if (targetMachine->addPassesToEmitFile(pm, fos, fileType)) {
fprintf(stderr, "Fatal error adding passes to emit object file!"); fprintf(stderr, "Fatal error adding passes to emit object file!");
exit(1); exit(1);