New approach to fix
This commit is contained in:
@@ -130,6 +130,9 @@ namespace {
|
|||||||
// To avoid walking constant expressions multiple times and other IR
|
// To avoid walking constant expressions multiple times and other IR
|
||||||
// objects, we keep several helper maps.
|
// objects, we keep several helper maps.
|
||||||
llvm::DenseSet<const llvm::Value*> VisitedConstants;
|
llvm::DenseSet<const llvm::Value*> VisitedConstants;
|
||||||
|
#if !defined (LLVM_3_2) && !defined (LLVM_3_3) && !defined (LLVM_3_4) && !defined (LLVM_3_5)// LLVN 3.6++
|
||||||
|
llvm::DenseSet<const llvm::MDNode*> VisitedConstantsInNodes;
|
||||||
|
#endif
|
||||||
llvm::DenseSet<llvm::Type*> VisitedTypes;
|
llvm::DenseSet<llvm::Type*> VisitedTypes;
|
||||||
|
|
||||||
std::vector<llvm::ArrayType*> &ArrayTypes;
|
std::vector<llvm::ArrayType*> &ArrayTypes;
|
||||||
@@ -266,7 +269,7 @@ namespace {
|
|||||||
#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)
|
||||||
if (!VisitedConstants.insert(V).second)
|
if (!VisitedConstants.insert(V).second)
|
||||||
#else // LLVN 3.6++
|
#else // LLVN 3.6++
|
||||||
if (!VisitedConstants.insert(llvm::cast<llvm::ValueAsMetadata>(V)->getValue()).second)
|
if (!VisitedConstantsInNodes.insert(V).second)
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
27
module.cpp
27
module.cpp
@@ -166,9 +166,11 @@ static void
|
|||||||
lStripUnusedDebugInfo(llvm::Module *module) {
|
lStripUnusedDebugInfo(llvm::Module *module) {
|
||||||
if (g->generateDebuggingSymbols == false)
|
if (g->generateDebuggingSymbols == false)
|
||||||
return;
|
return;
|
||||||
|
#if defined (LLVM_3_2) || defined (LLVM_3_3)|| defined (LLVM_3_4)|| defined (LLVM_3_5)
|
||||||
std::set<llvm::Value *> SPall;
|
std::set<llvm::Value *> SPall;
|
||||||
|
#else // LLVN 3.6++
|
||||||
|
std::set<llvm::Metadata *> SPall;
|
||||||
|
#endif
|
||||||
// OK, now we are to determine which functions actually survived the
|
// OK, now we are to determine which functions actually survived the
|
||||||
// optimization. We will now read all IR instructions in the module.
|
// optimization. We will now read all IR instructions in the module.
|
||||||
//
|
//
|
||||||
@@ -200,11 +202,7 @@ lStripUnusedDebugInfo(llvm::Module *module) {
|
|||||||
}
|
}
|
||||||
if (scope.isSubprogram()) {
|
if (scope.isSubprogram()) {
|
||||||
// good, the chain ended with a function; adding
|
// 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);
|
SPall.insert(scope);
|
||||||
#else // LLVN 3.6++
|
|
||||||
SPall.insert(llvm::cast<llvm::ValueAsMetadata>(scope.get())->getValue());
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -212,26 +210,27 @@ lStripUnusedDebugInfo(llvm::Module *module) {
|
|||||||
// loop over the compile units that contributed to the final module
|
// loop over the compile units that contributed to the final module
|
||||||
if (llvm::NamedMDNode *cuNodes = module->getNamedMetadata("llvm.dbg.cu")) {
|
if (llvm::NamedMDNode *cuNodes = module->getNamedMetadata("llvm.dbg.cu")) {
|
||||||
for (unsigned i = 0, ie = cuNodes->getNumOperands(); i != ie; ++i) {
|
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);
|
llvm::MDNode *cuNode = cuNodes->getOperand(i);
|
||||||
#else // LLVM 3.6+
|
|
||||||
llvm::MDNode *cuNode = llvm::cast<llvm::MDNode>(cuNodes->getOperand(i));
|
|
||||||
#endif
|
|
||||||
llvm::DICompileUnit cu(cuNode);
|
llvm::DICompileUnit cu(cuNode);
|
||||||
llvm::DIArray subprograms = cu.getSubprograms();
|
llvm::DIArray subprograms = cu.getSubprograms();
|
||||||
|
|
||||||
if (subprograms.getNumElements() == 0)
|
if (subprograms.getNumElements() == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
#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;
|
||||||
|
#else // LLVM 3.6+
|
||||||
|
std::set<llvm::Metadata *> SPset;
|
||||||
|
std::vector<llvm::Metadata *> usedSubprograms;
|
||||||
|
#endif
|
||||||
|
|
||||||
// determine what functions of those extracted belong to the unit
|
// determine what functions of those extracted belong to the unit
|
||||||
for (unsigned j = 0, je = subprograms.getNumElements(); j != je; ++j)
|
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)
|
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5)
|
||||||
SPset.insert(subprograms->getOperand(j));
|
SPset.insert(subprograms->getOperand(j));
|
||||||
#else // LLVM 3.6+
|
#else // LLVM 3.6+
|
||||||
SPset.insert(llvm::cast<llvm::ValueAsMetadata>((subprograms->getOperand(j)).get())->getValue());
|
SPset.insert(subprograms.getElement(j));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::set_intersection(SPall.begin(), SPall.end(),
|
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
|
// And now we can go and stuff it into the unit with some
|
||||||
// confidence...
|
// confidence...
|
||||||
std::vector<llvm::Metadata *> usedSubprograms_tmp;
|
llvm::MDNode *replNode = llvm::MDNode::get(module->getContext(),
|
||||||
for (int i = 0; i < usedSubprograms.size(); ++i)
|
llvm::ArrayRef<llvm::Metadata *>(usedSubprograms));
|
||||||
usedSubprograms_tmp.at(i) = llvm::ValueAsMetadata::get(usedSubprograms.at(i));
|
|
||||||
llvm::MDNode *replNode = llvm::MDNode::get(module->getContext(), usedSubprograms_tmp);
|
|
||||||
cu.replaceSubprograms(llvm::DIArray(replNode));
|
cu.replaceSubprograms(llvm::DIArray(replNode));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user