diff --git a/ctx.cpp b/ctx.cpp index f73f6cf1..0d692de1 100644 --- a/ctx.cpp +++ b/ctx.cpp @@ -1685,10 +1685,10 @@ FunctionEmitContext::StartScope() { #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) AssertPos(currentPos, lexicalBlock.Verify()); -#else // LLVM 3.7+ - //comming soon -#endif debugScopes.push_back(lexicalBlock); +#else // LLVM 3.7+ + debugScopes.push_back(llvm::cast(lexicalBlock)); +#endif } } diff --git a/ctx.h b/ctx.h index cd4db7e8..c7b84d2c 100644 --- a/ctx.h +++ b/ctx.h @@ -685,7 +685,11 @@ private: /** These correspond to the current set of nested scopes in the function. */ +#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) std::vector debugScopes; +#else // LLVM 3.7++ + std::vector debugScopes; +#endif /** True if a 'launch' statement has been encountered in the function. */ bool launchedTasks; diff --git a/module.cpp b/module.cpp index 41e2480a..9ad007a3 100644 --- a/module.cpp +++ b/module.cpp @@ -189,37 +189,37 @@ lStripUnusedDebugInfo(llvm::Module *module) { // get the instruction`s debugging metadata llvm::MDNode *node = inst->getMetadata(llvm::LLVMContext::MD_dbg); 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) llvm::DILocation dloc(node); -#else // LLVM 3.7+ - llvm::DILocation dloc(llvm::cast(node)); -#endif - // get the scope of the current instruction`s location llvm::DIScope scope = dloc.getScope(); - // node becomes NULL if this was the original location node = dloc.getOrigLocation(); // now following a chain of nested scopes 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()) scope = llvm::DILexicalBlockFile(scope).getScope(); else if (scope.isLexicalBlock()) scope = llvm::DILexicalBlock(scope).getContext(); else if (scope.isNameSpace()) scope = llvm::DINameSpace(scope).getContext(); -#else // LLVM 3.7+ - if (llvm::isa(scope)) - scope = llvm::DILexicalBlockFile(llvm::cast(scope)).getContext(); - else if (llvm::isa(scope)) - scope = llvm::DILexicalBlock(llvm::cast(scope)).getContext(); - else if (llvm::isa(scope)) - scope = llvm::DINameSpace(llvm::cast(scope)).getContext(); -#endif 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()) { #else // LLVM 3.7+ + llvm::DILocation dloc(llvm::cast(node)); + llvm::DIScope scope = dloc->getScope(); + node = dloc->getInlinedAt(); + // now following a chain of nested scopes + while (!0) { + if (llvm::isa(scope)) + scope = llvm::DILexicalBlockFile(llvm::cast(scope))->getScope(); + else if (llvm::isa(scope)) + scope = llvm::DILexicalBlock(llvm::cast(scope))->getScope(); + else if (llvm::isa(scope)) + scope = llvm::DINameSpace(llvm::cast(scope))->getScope(); + else break; + } if (llvm::isa(scope)) { #endif // good, the chain ended with a function; adding @@ -333,25 +333,22 @@ lStripUnusedDebugInfo(llvm::Module *module) { cuNode->replaceOperandWith(9, replNode); #else // LLVM 3.6+ 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()); for (int i = 0; i < (int)nodeSPs.getNumElements(); ++i) Assert(nodeSPs.getElement(i) == subprograms.getElement(i)); -#else // LLVM 3.7+ + llvm::MDNode *replNode = llvm::MDNode::get(module->getContext(), + llvm::ArrayRef(usedSubprograms)); + cu.replaceSubprograms(llvm::DIArray(replNode)); + #else // LLVM 3.7+ Assert(nodeSPs.size() == subprograms.size()); for (int i = 0; i < (int)nodeSPs.size(); ++i) Assert(nodeSPs [i] == subprograms [i]); -#endif - // And now we can go and stuff it into the unit with some - // confidence... - llvm::MDNode *replNode = llvm::MDNode::get(module->getContext(), - llvm::ArrayRef(usedSubprograms)); -#if defined(LLVM_3_6) - cu.replaceSubprograms(llvm::DIArray(replNode)); -#else // LLVM 3.7+ - cu.replaceSubprograms(llvm::DIArray(llvm::cast(replNode))); - -#endif + cu.replaceSubprograms(llvm::MDTuple::get(cu->getContext(), + llvm::ArrayRef(usedSubprograms))); + #endif #endif } } @@ -1479,8 +1476,11 @@ Module::writeObjectFileOrAssembly(llvm::TargetMachine *targetMachine, pm.add(dlp); #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()); - +#else // LLVM 3.7+ + llvm::raw_fd_ostream &fos(of->os()); +#endif if (targetMachine->addPassesToEmitFile(pm, fos, fileType)) { fprintf(stderr, "Fatal error adding passes to emit object file!"); exit(1);