DebugInfo: Provide a utility for building a mapping from llvm::Function*s to llvm::DISubprograms

Update DeadArgumentElimintation to use this, with the intent of reusing
the functionality for ArgumentPromotion as well.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@212122 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
David Blaikie 2014-07-01 20:05:26 +00:00
parent 4f5fa35b59
commit f652ec594e
3 changed files with 23 additions and 31 deletions

View File

@ -934,6 +934,9 @@ private:
/// Specify if TypeIdentifierMap is initialized.
bool TypeMapInitialized;
};
DenseMap<Function *, DISubprogram> makeSubprogramMap(Module &M);
} // end namespace llvm
#endif

View File

@ -1526,3 +1526,22 @@ unsigned llvm::getDebugMetadataVersionFromModule(const Module &M) {
return 0;
return cast<ConstantInt>(Val)->getZExtValue();
}
llvm::DenseMap<llvm::Function *, llvm::DISubprogram> llvm::makeSubprogramMap(Module &M) {
DenseMap<Function *, DISubprogram> R;
NamedMDNode *CU_Nodes = M.getNamedMetadata("llvm.dbg.cu");
if (!CU_Nodes)
return R;
for (MDNode *N : CU_Nodes->operands()) {
DICompileUnit CUNode(N);
DIArray SPs = CUNode.getSubprograms();
for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i) {
DISubprogram SP(SPs.getElement(i));
if (Function *F = SP.getFunction())
R.insert(std::make_pair(F, SP));
}
}
return R;
}

View File

@ -150,7 +150,6 @@ namespace {
unsigned RetValNum = 0);
Liveness SurveyUses(const Value *V, UseVector &MaybeLiveUses);
void CollectFunctionDIs(Module &M);
void SurveyFunction(const Function &F);
void MarkValue(const RetOrArg &RA, Liveness L,
const UseVector &MaybeLiveUses);
@ -190,35 +189,6 @@ INITIALIZE_PASS(DAH, "deadarghaX0r",
ModulePass *llvm::createDeadArgEliminationPass() { return new DAE(); }
ModulePass *llvm::createDeadArgHackingPass() { return new DAH(); }
/// CollectFunctionDIs - Map each function in the module to its debug info
/// descriptor.
void DAE::CollectFunctionDIs(Module &M) {
FunctionDIs.clear();
for (Module::named_metadata_iterator I = M.named_metadata_begin(),
E = M.named_metadata_end(); I != E; ++I) {
NamedMDNode &NMD = *I;
for (unsigned MDIndex = 0, MDNum = NMD.getNumOperands();
MDIndex < MDNum; ++MDIndex) {
MDNode *Node = NMD.getOperand(MDIndex);
if (!DIDescriptor(Node).isCompileUnit())
continue;
DICompileUnit CU(Node);
const DIArray &SPs = CU.getSubprograms();
for (unsigned SPIndex = 0, SPNum = SPs.getNumElements();
SPIndex < SPNum; ++SPIndex) {
DISubprogram SP(SPs.getElement(SPIndex));
assert((!SP || SP.isSubprogram()) &&
"A MDNode in subprograms of a CU should be null or a DISubprogram.");
if (!SP)
continue;
if (Function *F = SP.getFunction())
FunctionDIs[F] = SP;
}
}
}
}
/// DeleteDeadVarargs - If this is an function that takes a ... list, and if
/// llvm.vastart is never called, the varargs list is dead for the function.
bool DAE::DeleteDeadVarargs(Function &Fn) {
@ -1101,7 +1071,7 @@ bool DAE::runOnModule(Module &M) {
bool Changed = false;
// Collect debug info descriptors for functions.
CollectFunctionDIs(M);
FunctionDIs = makeSubprogramMap(M);
// First pass: Do a simple check to see if any functions can have their "..."
// removed. We can do this if they never call va_start. This loop cannot be