llvm.org GIT mirror llvm / 0864947
[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 Alon Mishne 6 years ago
8 changed file(s) with 66 addition(s) and 74 deletion(s). Raw diff Collapse all Expand all
1717 #define LLVM_IR_DEBUGINFO_H
1818
1919 #include "llvm/ADT/DenseMap.h"
20 #include "llvm/ADT/iterator_range.h"
2021 #include "llvm/ADT/SmallPtrSet.h"
2122 #include "llvm/ADT/SmallVector.h"
2223 #include "llvm/ADT/StringRef.h"
875876 bool addScope(DIScope Scope);
876877
877878 public:
878 typedef SmallVectorImpl::const_iterator iterator;
879 iterator compile_unit_begin() const { return CUs.begin(); }
880 iterator compile_unit_end() const { return CUs.end(); }
881 iterator subprogram_begin() const { return SPs.begin(); }
882 iterator subprogram_end() const { return SPs.end(); }
883 iterator global_variable_begin() const { return GVs.begin(); }
884 iterator global_variable_end() const { return GVs.end(); }
885 iterator type_begin() const { return TYs.begin(); }
886 iterator type_end() const { return TYs.end(); }
887 iterator scope_begin() const { return Scopes.begin(); }
888 iterator scope_end() const { return Scopes.end(); }
879 typedef SmallVectorImpl::const_iterator compile_unit_iterator;
880 typedef SmallVectorImpl::const_iterator subprogram_iterator;
881 typedef SmallVectorImpl::const_iterator global_variable_iterator;
882 typedef SmallVectorImpl::const_iterator type_iterator;
883 typedef SmallVectorImpl::const_iterator scope_iterator;
884
885 iterator_range compile_units() const {
886 return iterator_range(CUs.begin(), CUs.end());
887 }
888
889 iterator_range subprograms() const {
890 return iterator_range(SPs.begin(), SPs.end());
891 }
892
893 iterator_range global_variables() const {
894 return iterator_range(GVs.begin(), GVs.end());
895 }
896
897 iterator_range types() const {
898 return iterator_range(TYs.begin(), TYs.end());
899 }
900
901 iterator_range scopes() const {
902 return iterator_range(Scopes.begin(), Scopes.end());
903 }
889904
890905 unsigned compile_unit_count() const { return CUs.size(); }
891906 unsigned global_variable_count() const { return GVs.size(); }
894909 unsigned scope_count() const { return Scopes.size(); }
895910
896911 private:
897 SmallVector CUs; // Compile Units
898 SmallVector SPs; // Subprograms
899 SmallVector GVs; // Global Variables;
900 SmallVector TYs; // Types
901 SmallVector<MDNode *, 8> Scopes; // Scopes
912 SmallVector<DICompileUnit, 8> CUs; // Compile Units
913 SmallVector SPs; // Subprograms
914 SmallVector GVs; // Global Variables;
915 SmallVector TYs; // Types
916 SmallVector Scopes; // Scopes
902917 SmallPtrSet NodesSeen;
903918 DITypeIdentifierMap TypeIdentifierMap;
904919 /// Specify if TypeIdentifierMap is initialized.
5555 }
5656
5757 void ModuleDebugInfoPrinter::print(raw_ostream &O, const Module *M) const {
58 for (DebugInfoFinder::iterator I = Finder.compile_unit_begin(),
59 E = Finder.compile_unit_end(); I != E; ++I) {
58 for (DICompileUnit CU : Finder.compile_units()) {
6059 O << "Compile Unit: ";
61 DICompileUnit(*I).print(O);
60 CU.print(O);
6261 O << '\n';
6362 }
6463
65 for (DebugInfoFinder::iterator I = Finder.subprogram_begin(),
66 E = Finder.subprogram_end(); I != E; ++I) {
64 for (DISubprogram S : Finder.subprograms()) {
6765 O << "Subprogram: ";
68 DISubprogram(*I).print(O);
66 S.print(O);
6967 O << '\n';
7068 }
7169
72 for (DebugInfoFinder::iterator I = Finder.global_variable_begin(),
73 E = Finder.global_variable_end(); I != E; ++I) {
70 for (DIGlobalVariable GV : Finder.global_variables()) {
7471 O << "GlobalVariable: ";
75 DIGlobalVariable(*I).print(O);
72 GV.print(O);
7673 O << '\n';
7774 }
7875
79 for (DebugInfoFinder::iterator I = Finder.type_begin(),
80 E = Finder.type_end(); I != E; ++I) {
76 for (DIType T : Finder.types()) {
8177 O << "Type: ";
82 DIType(*I).print(O);
78 T.print(O);
8379 O << '\n';
8480 }
8581 }
23542354 void Verifier::verifyDebugInfo() {
23552355 // Verify Debug Info.
23562356 if (!DisableDebugInfoVerifier) {
2357 for (DebugInfoFinder::iterator I = Finder.compile_unit_begin(),
2358 E = Finder.compile_unit_end(); I != E; ++I)
2359 Assert1(DICompileUnit(*I).Verify(), "DICompileUnit does not Verify!", *I);
2360 for (DebugInfoFinder::iterator I = Finder.subprogram_begin(),
2361 E = Finder.subprogram_end(); I != E; ++I)
2362 Assert1(DISubprogram(*I).Verify(), "DISubprogram does not Verify!", *I);
2363 for (DebugInfoFinder::iterator I = Finder.global_variable_begin(),
2364 E = Finder.global_variable_end(); I != E; ++I)
2365 Assert1(DIGlobalVariable(*I).Verify(),
2366 "DIGlobalVariable does not Verify!", *I);
2367 for (DebugInfoFinder::iterator I = Finder.type_begin(),
2368 E = Finder.type_end(); I != E; ++I)
2369 Assert1(DIType(*I).Verify(), "DIType does not Verify!", *I);
2370 for (DebugInfoFinder::iterator I = Finder.scope_begin(),
2371 E = Finder.scope_end(); I != E; ++I)
2372 Assert1(DIScope(*I).Verify(), "DIScope does not Verify!", *I);
2357 for (DICompileUnit CU : Finder.compile_units()) {
2358 Assert1(CU.Verify(), "DICompileUnit does not Verify!", CU);
2359 }
2360 for (DISubprogram S : Finder.subprograms()) {
2361 Assert1(S.Verify(), "DISubprogram does not Verify!", S);
2362 }
2363 for (DIGlobalVariable GV : Finder.global_variables()) {
2364 Assert1(GV.Verify(), "DIGlobalVariable does not Verify!", GV);
2365 }
2366 for (DIType T : Finder.types()) {
2367 Assert1(T.Verify(), "DIType does not Verify!", T);
2368 }
2369 for (DIScope S : Finder.scopes()) {
2370 Assert1(S.Verify(), "DIScope does not Verify!", S);
2371 }
23732372 }
23742373 }
23752374
837837 DbgFinder.processModule(M);
838838
839839 unsigned i = 1;
840 for (DebugInfoFinder::iterator I = DbgFinder.compile_unit_begin(),
841 E = DbgFinder.compile_unit_end();
842 I != E; ++I) {
843 DICompileUnit DIUnit(*I);
840 for (DICompileUnit DIUnit : DbgFinder.compile_units()) {
844841 StringRef Filename(DIUnit.getFilename());
845842 StringRef Dirname(DIUnit.getDirectory());
846843 SmallString<128> FullPathName = Dirname;
855852 ++i;
856853 }
857854
858 for (DebugInfoFinder::iterator I = DbgFinder.subprogram_begin(),
859 E = DbgFinder.subprogram_end();
860 I != E; ++I) {
861 DISubprogram SP(*I);
855 for (DISubprogram SP : DbgFinder.subprograms()) {
862856 StringRef Filename(SP.getFilename());
863857 StringRef Dirname(SP.getDirectory());
864858 SmallString<128> FullPathName = Dirname;
305305 SmallVector LiveSubprograms;
306306 DenseSet VisitedSet;
307307
308 for (DebugInfoFinder::iterator CI = F.compile_unit_begin(),
309 CE = F.compile_unit_end(); CI != CE; ++CI) {
310 // Create our compile unit.
311 DICompileUnit DIC(*CI);
308 for (DICompileUnit DIC : F.compile_units()) {
312309 assert(DIC.Verify() && "DIC must verify as a DICompileUnit.");
313310
314311 // Create our live subprogram list.
182182 if (Finder.compile_unit_count() > 1)
183183 report_fatal_error("DebugIR pass supports only a signle compile unit per "
184184 "Module.");
185 createCompileUnit(
186 Finder.compile_unit_count() == 1 ? *Finder.compile_unit_begin() : 0);
185 createCompileUnit(Finder.compile_unit_count() == 1 ?
186 (MDNode*)*Finder.compile_units().begin() : 0);
187187 }
188188
189189 void visitFunction(Function &F) {
324324 << " subprogram nodes"
325325 << "\n");
326326
327 for (DebugInfoFinder::iterator i = Finder.subprogram_begin(),
328 e = Finder.subprogram_end();
329 i != e; ++i) {
330 DISubprogram S(*i);
327 for (DISubprogram S : Finder.subprograms()) {
331328 if (S.getFunction() == F) {
332 DEBUG(dbgs() << "Found DISubprogram " << *i << " for function "
329 DEBUG(dbgs() << "Found DISubprogram " << S << " for function "
333330 << S.getFunction() << "\n");
334 return *i;
331 return S;
335332 }
336333 }
337334 DEBUG(dbgs() << "unable to find DISubprogram node for function "
153153
154154 // Find the MDNode which corresponds to the DISubprogram data that described F.
155155 static MDNode* FindSubprogram(const Function *F, DebugInfoFinder &Finder) {
156 for (DebugInfoFinder::iterator I = Finder.subprogram_begin(),
157 E = Finder.subprogram_end();
158 I != E; ++I) {
159 DISubprogram Subprogram(*I);
156 for (DISubprogram Subprogram : Finder.subprograms()) {
160157 if (Subprogram.describes(F)) return Subprogram;
161158 }
162159 return NULL;
189186 VMap[OldFunc] = NewFunc;
190187 DISubprogram NewSubprogram(MapValue(OldSubprogramMDNode, VMap));
191188
192 for (DebugInfoFinder::iterator CUIter = Finder.compile_unit_begin(),
193 CUEnd = Finder.compile_unit_end(); CUIter != CUEnd; ++CUIter) {
194 DICompileUnit CU(*CUIter);
195
189 for (DICompileUnit CU : Finder.compile_units()) {
196190 DIArray Subprograms(CU.getSubprograms());
197191
198192 // If the compile unit's function list contains the old function, it should
275275 unsigned SubprogramCount = Finder->subprogram_count();
276276 EXPECT_EQ(2U, SubprogramCount);
277277
278 DebugInfoFinder::iterator Iter = Finder->subprogram_begin();
278 auto Iter = Finder->subprograms().begin();
279279 DISubprogram Sub1(*Iter);
280280 EXPECT_TRUE(Sub1.Verify());
281281 Iter++;
291291 TEST_F(CloneFunc, SubprogramInRightCU) {
292292 EXPECT_EQ(2U, Finder->compile_unit_count());
293293
294 DebugInfoFinder::iterator Iter = Finder->compile_unit_begin();
294 auto Iter = Finder->compile_units().begin();
295295 DICompileUnit CU1(*Iter);
296296 EXPECT_TRUE(CU1.Verify());
297297 Iter++;