From 8672aff298e4829db215e6910bed1e40d9245151 Mon Sep 17 00:00:00 2001 From: Vsevolod Livinskiy Date: Thu, 25 Dec 2014 14:31:46 +0300 Subject: [PATCH] New approach to fix --- cbackend.cpp | 5 ++++- module.cpp | 27 ++++++++++++--------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/cbackend.cpp b/cbackend.cpp index e6a22693..0f8ddbd6 100644 --- a/cbackend.cpp +++ b/cbackend.cpp @@ -130,6 +130,9 @@ namespace { // To avoid walking constant expressions multiple times and other IR // objects, we keep several helper maps. llvm::DenseSet VisitedConstants; +#if !defined (LLVM_3_2) && !defined (LLVM_3_3) && !defined (LLVM_3_4) && !defined (LLVM_3_5)// LLVN 3.6++ + llvm::DenseSet VisitedConstantsInNodes; +#endif llvm::DenseSet VisitedTypes; std::vector &ArrayTypes; @@ -266,7 +269,7 @@ namespace { #if defined (LLVM_3_2) || defined (LLVM_3_3)|| defined (LLVM_3_4)|| defined (LLVM_3_5) if (!VisitedConstants.insert(V).second) #else // LLVN 3.6++ - if (!VisitedConstants.insert(llvm::cast(V)->getValue()).second) + if (!VisitedConstantsInNodes.insert(V).second) #endif return; diff --git a/module.cpp b/module.cpp index 059375f5..ef541915 100644 --- a/module.cpp +++ b/module.cpp @@ -166,9 +166,11 @@ static void lStripUnusedDebugInfo(llvm::Module *module) { if (g->generateDebuggingSymbols == false) return; - +#if defined (LLVM_3_2) || defined (LLVM_3_3)|| defined (LLVM_3_4)|| defined (LLVM_3_5) std::set SPall; - +#else // LLVN 3.6++ + std::set SPall; +#endif // OK, now we are to determine which functions actually survived the // optimization. We will now read all IR instructions in the module. // @@ -200,11 +202,7 @@ lStripUnusedDebugInfo(llvm::Module *module) { } if (scope.isSubprogram()) { // good, the chain ended with a function; adding -#if defined (LLVM_3_2) || defined (LLVM_3_3)|| defined (LLVM_3_4)|| defined (LLVM_3_5) SPall.insert(scope); -#else // LLVN 3.6++ - SPall.insert(llvm::cast(scope.get())->getValue()); -#endif } } } @@ -212,26 +210,27 @@ lStripUnusedDebugInfo(llvm::Module *module) { // loop over the compile units that contributed to the final module if (llvm::NamedMDNode *cuNodes = module->getNamedMetadata("llvm.dbg.cu")) { for (unsigned i = 0, ie = cuNodes->getNumOperands(); i != ie; ++i) { -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) llvm::MDNode *cuNode = cuNodes->getOperand(i); -#else // LLVM 3.6+ - llvm::MDNode *cuNode = llvm::cast(cuNodes->getOperand(i)); -#endif llvm::DICompileUnit cu(cuNode); llvm::DIArray subprograms = cu.getSubprograms(); if (subprograms.getNumElements() == 0) continue; +#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) std::set SPset; std::vector usedSubprograms; +#else // LLVM 3.6+ + std::set SPset; + std::vector usedSubprograms; +#endif // determine what functions of those extracted belong to the unit for (unsigned j = 0, je = subprograms.getNumElements(); j != je; ++j) #if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) SPset.insert(subprograms->getOperand(j)); #else // LLVM 3.6+ - SPset.insert(llvm::cast((subprograms->getOperand(j)).get())->getValue()); + SPset.insert(subprograms.getElement(j)); #endif std::set_intersection(SPall.begin(), SPall.end(), @@ -301,10 +300,8 @@ lStripUnusedDebugInfo(llvm::Module *module) { // And now we can go and stuff it into the unit with some // confidence... - std::vector usedSubprograms_tmp; - for (int i = 0; i < usedSubprograms.size(); ++i) - usedSubprograms_tmp.at(i) = llvm::ValueAsMetadata::get(usedSubprograms.at(i)); - llvm::MDNode *replNode = llvm::MDNode::get(module->getContext(), usedSubprograms_tmp); + llvm::MDNode *replNode = llvm::MDNode::get(module->getContext(), + llvm::ArrayRef(usedSubprograms)); cu.replaceSubprograms(llvm::DIArray(replNode)); #endif }