[llvm] r186737 - Debug Info Verifier: simplify DIxxx::Verify

Manman Ren manman.ren at gmail.com
Fri Jul 19 17:38:47 PDT 2013


Author: mren
Date: Fri Jul 19 19:38:46 2013
New Revision: 186737

URL: http://llvm.org/viewvc/llvm-project?rev=186737&view=rev
Log:
Debug Info Verifier: simplify DIxxx::Verify

Simplify DIxxx:Verify to not call Verify on an operand. Instead, we use
DebugInfoFinder to list all MDNodes that should be a DIScope and all MDNodes
that should be a DIType and we will call Verify on those lists.

Modified:
    llvm/trunk/include/llvm/DebugInfo.h
    llvm/trunk/lib/IR/DebugInfo.cpp
    llvm/trunk/lib/IR/Verifier.cpp

Modified: llvm/trunk/include/llvm/DebugInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo.h?rev=186737&r1=186736&r2=186737&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo.h (original)
+++ llvm/trunk/include/llvm/DebugInfo.h Fri Jul 19 19:38:46 2013
@@ -768,6 +768,8 @@ namespace llvm {
     /// addType - Add type into Tys.
     bool addType(DIType DT);
 
+    bool addScope(DIScope Scope);
+
   public:
     typedef SmallVectorImpl<MDNode *>::const_iterator iterator;
     iterator compile_unit_begin()    const { return CUs.begin(); }
@@ -778,17 +780,21 @@ namespace llvm {
     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(); }
 
     unsigned compile_unit_count()    const { return CUs.size(); }
     unsigned global_variable_count() const { return GVs.size(); }
     unsigned subprogram_count()      const { return SPs.size(); }
     unsigned type_count()            const { return TYs.size(); }
+    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
     SmallPtrSet<MDNode *, 64> NodesSeen;
   };
 } // end namespace llvm

Modified: llvm/trunk/lib/IR/DebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DebugInfo.cpp?rev=186737&r1=186736&r2=186737&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DebugInfo.cpp (original)
+++ llvm/trunk/lib/IR/DebugInfo.cpp Fri Jul 19 19:38:46 2013
@@ -436,9 +436,6 @@ bool DIObjCProperty::Verify() const {
   if (!isObjCProperty())
     return false;
 
-  DIType Ty = getType();
-  if (!Ty.Verify()) return false;
-
   // Don't worry about the rest of the strings for now.
   return DbgNode->getNumOperands() == 8;
 }
@@ -447,8 +444,6 @@ bool DIObjCProperty::Verify() const {
 bool DIType::Verify() const {
   if (!isType())
     return false;
-  if (getContext() && !getContext().Verify())
-    return false;
   unsigned Tag = getTag();
   if (!isBasicType() && Tag != dwarf::DW_TAG_const_type &&
       Tag != dwarf::DW_TAG_volatile_type && Tag != dwarf::DW_TAG_pointer_type &&
@@ -481,8 +476,6 @@ bool DIDerivedType::Verify() const {
 bool DICompositeType::Verify() const {
   if (!isCompositeType())
     return false;
-  if (getContext() && !getContext().Verify())
-    return false;
 
   return DbgNode->getNumOperands() >= 10 && DbgNode->getNumOperands() <= 14;
 }
@@ -492,12 +485,6 @@ bool DISubprogram::Verify() const {
   if (!isSubprogram())
     return false;
 
-  if (getContext() && !getContext().Verify())
-    return false;
-
-  DICompositeType Ty = getType();
-  if (!Ty.Verify())
-    return false;
   return DbgNode->getNumOperands() == 20;
 }
 
@@ -509,13 +496,6 @@ bool DIGlobalVariable::Verify() const {
   if (getDisplayName().empty())
     return false;
 
-  if (getContext() && !getContext().Verify())
-    return false;
-
-  DIType Ty = getType();
-  if (!Ty.Verify())
-    return false;
-
   return DbgNode->getNumOperands() == 13;
 }
 
@@ -524,13 +504,6 @@ bool DIVariable::Verify() const {
   if (!isVariable())
     return false;
 
-  if (getContext() && !getContext().Verify())
-    return false;
-
-  DIType Ty = getType();
-  if (!Ty.Verify())
-    return false;
-
   return DbgNode->getNumOperands() >= 8;
 }
 
@@ -883,8 +856,10 @@ void DebugInfoFinder::processModule(cons
       DIArray GVs = CU.getGlobalVariables();
       for (unsigned i = 0, e = GVs.getNumElements(); i != e; ++i) {
         DIGlobalVariable DIG(GVs.getElement(i));
-        if (addGlobalVariable(DIG))
+        if (addGlobalVariable(DIG)) {
+          addScope(DIG.getContext());
           processType(DIG.getType());
+        }
       }
       DIArray SPs = CU.getSubprograms();
       for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i)
@@ -922,6 +897,7 @@ void DebugInfoFinder::processLocation(DI
 void DebugInfoFinder::processType(DIType DT) {
   if (!addType(DT))
     return;
+  addScope(DT.getContext());
   if (DT.isCompositeType()) {
     DICompositeType DCT(DT);
     processType(DCT.getTypeDerivedFrom());
@@ -956,6 +932,7 @@ void DebugInfoFinder::processLexicalBloc
 void DebugInfoFinder::processSubprogram(DISubprogram SP) {
   if (!addSubprogram(SP))
     return;
+  addScope(SP.getContext());
   processType(SP.getType());
 }
 
@@ -1021,6 +998,15 @@ bool DebugInfoFinder::addSubprogram(DISu
   return true;
 }
 
+bool DebugInfoFinder::addScope(DIScope Scope) {
+  if (!Scope)
+    return false;
+  if (!NodesSeen.insert(Scope))
+    return false;
+  Scopes.push_back(Scope);
+  return true;
+}
+
 //===----------------------------------------------------------------------===//
 // DIDescriptor: dump routines for all descriptors.
 //===----------------------------------------------------------------------===//

Modified: llvm/trunk/lib/IR/Verifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Verifier.cpp?rev=186737&r1=186736&r2=186737&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Verifier.cpp (original)
+++ llvm/trunk/lib/IR/Verifier.cpp Fri Jul 19 19:38:46 2013
@@ -2214,6 +2214,9 @@ void Verifier::verifyDebugInfo(Module &M
     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);
   }
 }
 





More information about the llvm-commits mailing list