mirror of
https://github.com/RPCSX/llvm.git
synced 2024-11-28 06:00:28 +00:00
[C++11] Change DebugInfoFinder to use range-based loops
Also changes the iterators to return actual DI type over MDNode. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204130 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
fabbbc96ca
commit
086494730d
@ -18,6 +18,7 @@
|
||||
#define LLVM_IR_DEBUGINFO_H
|
||||
|
||||
#include "llvm/ADT/DenseMap.h"
|
||||
#include "llvm/ADT/iterator_range.h"
|
||||
#include "llvm/ADT/SmallPtrSet.h"
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
@ -876,17 +877,31 @@ private:
|
||||
bool addScope(DIScope Scope);
|
||||
|
||||
public:
|
||||
typedef SmallVectorImpl<MDNode *>::const_iterator iterator;
|
||||
iterator compile_unit_begin() const { return CUs.begin(); }
|
||||
iterator compile_unit_end() const { return CUs.end(); }
|
||||
iterator subprogram_begin() const { return SPs.begin(); }
|
||||
iterator subprogram_end() const { return SPs.end(); }
|
||||
iterator global_variable_begin() const { return GVs.begin(); }
|
||||
iterator global_variable_end() const { return GVs.end(); }
|
||||
iterator type_begin() const { return TYs.begin(); }
|
||||
iterator type_end() const { return TYs.end(); }
|
||||
iterator scope_begin() const { return Scopes.begin(); }
|
||||
iterator scope_end() const { return Scopes.end(); }
|
||||
typedef SmallVectorImpl<DICompileUnit>::const_iterator compile_unit_iterator;
|
||||
typedef SmallVectorImpl<DISubprogram>::const_iterator subprogram_iterator;
|
||||
typedef SmallVectorImpl<DIGlobalVariable>::const_iterator global_variable_iterator;
|
||||
typedef SmallVectorImpl<DIType>::const_iterator type_iterator;
|
||||
typedef SmallVectorImpl<DIScope>::const_iterator scope_iterator;
|
||||
|
||||
iterator_range<compile_unit_iterator> compile_units() const {
|
||||
return iterator_range<compile_unit_iterator>(CUs.begin(), CUs.end());
|
||||
}
|
||||
|
||||
iterator_range<subprogram_iterator> subprograms() const {
|
||||
return iterator_range<subprogram_iterator>(SPs.begin(), SPs.end());
|
||||
}
|
||||
|
||||
iterator_range<global_variable_iterator> global_variables() const {
|
||||
return iterator_range<global_variable_iterator>(GVs.begin(), GVs.end());
|
||||
}
|
||||
|
||||
iterator_range<type_iterator> types() const {
|
||||
return iterator_range<type_iterator>(TYs.begin(), TYs.end());
|
||||
}
|
||||
|
||||
iterator_range<scope_iterator> scopes() const {
|
||||
return iterator_range<scope_iterator>(Scopes.begin(), Scopes.end());
|
||||
}
|
||||
|
||||
unsigned compile_unit_count() const { return CUs.size(); }
|
||||
unsigned global_variable_count() const { return GVs.size(); }
|
||||
@ -895,11 +910,11 @@ public:
|
||||
unsigned scope_count() const { return Scopes.size(); }
|
||||
|
||||
private:
|
||||
SmallVector<MDNode *, 8> CUs; // Compile Units
|
||||
SmallVector<MDNode *, 8> SPs; // Subprograms
|
||||
SmallVector<MDNode *, 8> GVs; // Global Variables;
|
||||
SmallVector<MDNode *, 8> TYs; // Types
|
||||
SmallVector<MDNode *, 8> Scopes; // Scopes
|
||||
SmallVector<DICompileUnit, 8> CUs; // Compile Units
|
||||
SmallVector<DISubprogram, 8> SPs; // Subprograms
|
||||
SmallVector<DIGlobalVariable, 8> GVs; // Global Variables;
|
||||
SmallVector<DIType, 8> TYs; // Types
|
||||
SmallVector<DIScope, 8> Scopes; // Scopes
|
||||
SmallPtrSet<MDNode *, 64> NodesSeen;
|
||||
DITypeIdentifierMap TypeIdentifierMap;
|
||||
/// Specify if TypeIdentifierMap is initialized.
|
||||
|
@ -56,31 +56,27 @@ bool ModuleDebugInfoPrinter::runOnModule(Module &M) {
|
||||
}
|
||||
|
||||
void ModuleDebugInfoPrinter::print(raw_ostream &O, const Module *M) const {
|
||||
for (DebugInfoFinder::iterator I = Finder.compile_unit_begin(),
|
||||
E = Finder.compile_unit_end(); I != E; ++I) {
|
||||
for (DICompileUnit CU : Finder.compile_units()) {
|
||||
O << "Compile Unit: ";
|
||||
DICompileUnit(*I).print(O);
|
||||
CU.print(O);
|
||||
O << '\n';
|
||||
}
|
||||
|
||||
for (DebugInfoFinder::iterator I = Finder.subprogram_begin(),
|
||||
E = Finder.subprogram_end(); I != E; ++I) {
|
||||
for (DISubprogram S : Finder.subprograms()) {
|
||||
O << "Subprogram: ";
|
||||
DISubprogram(*I).print(O);
|
||||
S.print(O);
|
||||
O << '\n';
|
||||
}
|
||||
|
||||
for (DebugInfoFinder::iterator I = Finder.global_variable_begin(),
|
||||
E = Finder.global_variable_end(); I != E; ++I) {
|
||||
for (DIGlobalVariable GV : Finder.global_variables()) {
|
||||
O << "GlobalVariable: ";
|
||||
DIGlobalVariable(*I).print(O);
|
||||
GV.print(O);
|
||||
O << '\n';
|
||||
}
|
||||
|
||||
for (DebugInfoFinder::iterator I = Finder.type_begin(),
|
||||
E = Finder.type_end(); I != E; ++I) {
|
||||
for (DIType T : Finder.types()) {
|
||||
O << "Type: ";
|
||||
DIType(*I).print(O);
|
||||
T.print(O);
|
||||
O << '\n';
|
||||
}
|
||||
}
|
||||
|
@ -2355,22 +2355,21 @@ void Verifier::visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI) {
|
||||
void Verifier::verifyDebugInfo() {
|
||||
// Verify Debug Info.
|
||||
if (!DisableDebugInfoVerifier) {
|
||||
for (DebugInfoFinder::iterator I = Finder.compile_unit_begin(),
|
||||
E = Finder.compile_unit_end(); I != E; ++I)
|
||||
Assert1(DICompileUnit(*I).Verify(), "DICompileUnit does not Verify!", *I);
|
||||
for (DebugInfoFinder::iterator I = Finder.subprogram_begin(),
|
||||
E = Finder.subprogram_end(); I != E; ++I)
|
||||
Assert1(DISubprogram(*I).Verify(), "DISubprogram does not Verify!", *I);
|
||||
for (DebugInfoFinder::iterator I = Finder.global_variable_begin(),
|
||||
E = Finder.global_variable_end(); I != E; ++I)
|
||||
Assert1(DIGlobalVariable(*I).Verify(),
|
||||
"DIGlobalVariable does not Verify!", *I);
|
||||
for (DebugInfoFinder::iterator I = Finder.type_begin(),
|
||||
E = Finder.type_end(); I != E; ++I)
|
||||
Assert1(DIType(*I).Verify(), "DIType does not Verify!", *I);
|
||||
for (DebugInfoFinder::iterator I = Finder.scope_begin(),
|
||||
E = Finder.scope_end(); I != E; ++I)
|
||||
Assert1(DIScope(*I).Verify(), "DIScope does not Verify!", *I);
|
||||
for (DICompileUnit CU : Finder.compile_units()) {
|
||||
Assert1(CU.Verify(), "DICompileUnit does not Verify!", CU);
|
||||
}
|
||||
for (DISubprogram S : Finder.subprograms()) {
|
||||
Assert1(S.Verify(), "DISubprogram does not Verify!", S);
|
||||
}
|
||||
for (DIGlobalVariable GV : Finder.global_variables()) {
|
||||
Assert1(GV.Verify(), "DIGlobalVariable does not Verify!", GV);
|
||||
}
|
||||
for (DIType T : Finder.types()) {
|
||||
Assert1(T.Verify(), "DIType does not Verify!", T);
|
||||
}
|
||||
for (DIScope S : Finder.scopes()) {
|
||||
Assert1(S.Verify(), "DIScope does not Verify!", S);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -838,10 +838,7 @@ void NVPTXAsmPrinter::recordAndEmitFilenames(Module &M) {
|
||||
DbgFinder.processModule(M);
|
||||
|
||||
unsigned i = 1;
|
||||
for (DebugInfoFinder::iterator I = DbgFinder.compile_unit_begin(),
|
||||
E = DbgFinder.compile_unit_end();
|
||||
I != E; ++I) {
|
||||
DICompileUnit DIUnit(*I);
|
||||
for (DICompileUnit DIUnit : DbgFinder.compile_units()) {
|
||||
StringRef Filename(DIUnit.getFilename());
|
||||
StringRef Dirname(DIUnit.getDirectory());
|
||||
SmallString<128> FullPathName = Dirname;
|
||||
@ -856,10 +853,7 @@ void NVPTXAsmPrinter::recordAndEmitFilenames(Module &M) {
|
||||
++i;
|
||||
}
|
||||
|
||||
for (DebugInfoFinder::iterator I = DbgFinder.subprogram_begin(),
|
||||
E = DbgFinder.subprogram_end();
|
||||
I != E; ++I) {
|
||||
DISubprogram SP(*I);
|
||||
for (DISubprogram SP : DbgFinder.subprograms()) {
|
||||
StringRef Filename(SP.getFilename());
|
||||
StringRef Dirname(SP.getDirectory());
|
||||
SmallString<128> FullPathName = Dirname;
|
||||
|
@ -306,10 +306,7 @@ bool StripDeadDebugInfo::runOnModule(Module &M) {
|
||||
SmallVector<Value *, 64> LiveSubprograms;
|
||||
DenseSet<const MDNode *> VisitedSet;
|
||||
|
||||
for (DebugInfoFinder::iterator CI = F.compile_unit_begin(),
|
||||
CE = F.compile_unit_end(); CI != CE; ++CI) {
|
||||
// Create our compile unit.
|
||||
DICompileUnit DIC(*CI);
|
||||
for (DICompileUnit DIC : F.compile_units()) {
|
||||
assert(DIC.Verify() && "DIC must verify as a DICompileUnit.");
|
||||
|
||||
// Create our live subprogram list.
|
||||
|
@ -183,8 +183,8 @@ public:
|
||||
if (Finder.compile_unit_count() > 1)
|
||||
report_fatal_error("DebugIR pass supports only a signle compile unit per "
|
||||
"Module.");
|
||||
createCompileUnit(
|
||||
Finder.compile_unit_count() == 1 ? *Finder.compile_unit_begin() : 0);
|
||||
createCompileUnit(Finder.compile_unit_count() == 1 ?
|
||||
(MDNode*)*Finder.compile_units().begin() : 0);
|
||||
}
|
||||
|
||||
void visitFunction(Function &F) {
|
||||
@ -325,14 +325,11 @@ private:
|
||||
<< " subprogram nodes"
|
||||
<< "\n");
|
||||
|
||||
for (DebugInfoFinder::iterator i = Finder.subprogram_begin(),
|
||||
e = Finder.subprogram_end();
|
||||
i != e; ++i) {
|
||||
DISubprogram S(*i);
|
||||
for (DISubprogram S : Finder.subprograms()) {
|
||||
if (S.getFunction() == F) {
|
||||
DEBUG(dbgs() << "Found DISubprogram " << *i << " for function "
|
||||
DEBUG(dbgs() << "Found DISubprogram " << S << " for function "
|
||||
<< S.getFunction() << "\n");
|
||||
return *i;
|
||||
return S;
|
||||
}
|
||||
}
|
||||
DEBUG(dbgs() << "unable to find DISubprogram node for function "
|
||||
|
@ -154,10 +154,7 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
|
||||
|
||||
// Find the MDNode which corresponds to the DISubprogram data that described F.
|
||||
static MDNode* FindSubprogram(const Function *F, DebugInfoFinder &Finder) {
|
||||
for (DebugInfoFinder::iterator I = Finder.subprogram_begin(),
|
||||
E = Finder.subprogram_end();
|
||||
I != E; ++I) {
|
||||
DISubprogram Subprogram(*I);
|
||||
for (DISubprogram Subprogram : Finder.subprograms()) {
|
||||
if (Subprogram.describes(F)) return Subprogram;
|
||||
}
|
||||
return NULL;
|
||||
@ -190,10 +187,7 @@ static void CloneDebugInfoMetadata(Function *NewFunc, const Function *OldFunc,
|
||||
VMap[OldFunc] = NewFunc;
|
||||
DISubprogram NewSubprogram(MapValue(OldSubprogramMDNode, VMap));
|
||||
|
||||
for (DebugInfoFinder::iterator CUIter = Finder.compile_unit_begin(),
|
||||
CUEnd = Finder.compile_unit_end(); CUIter != CUEnd; ++CUIter) {
|
||||
DICompileUnit CU(*CUIter);
|
||||
|
||||
for (DICompileUnit CU : Finder.compile_units()) {
|
||||
DIArray Subprograms(CU.getSubprograms());
|
||||
|
||||
// If the compile unit's function list contains the old function, it should
|
||||
|
@ -276,7 +276,7 @@ TEST_F(CloneFunc, Subprogram) {
|
||||
unsigned SubprogramCount = Finder->subprogram_count();
|
||||
EXPECT_EQ(2U, SubprogramCount);
|
||||
|
||||
DebugInfoFinder::iterator Iter = Finder->subprogram_begin();
|
||||
auto Iter = Finder->subprograms().begin();
|
||||
DISubprogram Sub1(*Iter);
|
||||
EXPECT_TRUE(Sub1.Verify());
|
||||
Iter++;
|
||||
@ -292,7 +292,7 @@ TEST_F(CloneFunc, Subprogram) {
|
||||
TEST_F(CloneFunc, SubprogramInRightCU) {
|
||||
EXPECT_EQ(2U, Finder->compile_unit_count());
|
||||
|
||||
DebugInfoFinder::iterator Iter = Finder->compile_unit_begin();
|
||||
auto Iter = Finder->compile_units().begin();
|
||||
DICompileUnit CU1(*Iter);
|
||||
EXPECT_TRUE(CU1.Verify());
|
||||
Iter++;
|
||||
|
Loading…
Reference in New Issue
Block a user