Extend the ValuesAtScope cache to cover all expressions, not just
[oota-llvm.git] / lib / Analysis / DebugInfo.cpp
index a7e0a79decb161293e1fa996dcf5b787eea1c674..e815931e611743840afb440c6f10a5ff45a6efbe 100644 (file)
@@ -124,22 +124,23 @@ GlobalVariable *DIDescriptor::getGlobalVariableField(unsigned Elt) const {
 }
 
 //===----------------------------------------------------------------------===//
-// Simple Descriptor Constructors and other Methods
+// Predicates
 //===----------------------------------------------------------------------===//
 
-// Needed by DIVariable::getType().
-DIType::DIType(MDNode *N) : DIDescriptor(N) {
-  if (!N) return;
-  unsigned tag = getTag();
-  if (tag != dwarf::DW_TAG_base_type && !DIDerivedType::isDerivedType(tag) &&
-      !DICompositeType::isCompositeType(tag)) {
-    DbgNode = 0;
-  }
+/// isBasicType - Return true if the specified tag is legal for
+/// DIBasicType.
+bool DIDescriptor::isBasicType() const {
+  assert (!isNull() && "Invalid descriptor!");
+  unsigned Tag = getTag();
+  
+  return Tag == dwarf::DW_TAG_base_type;
 }
 
-/// isDerivedType - Return true if the specified tag is legal for
-/// DIDerivedType.
-bool DIType::isDerivedType(unsigned Tag) {
+/// isDerivedType - Return true if the specified tag is legal for DIDerivedType.
+bool DIDescriptor::isDerivedType() const {
+  assert (!isNull() && "Invalid descriptor!");
+  unsigned Tag = getTag();
+
   switch (Tag) {
   case dwarf::DW_TAG_typedef:
   case dwarf::DW_TAG_pointer_type:
@@ -152,14 +153,17 @@ bool DIType::isDerivedType(unsigned Tag) {
     return true;
   default:
     // CompositeTypes are currently modelled as DerivedTypes.
-    return isCompositeType(Tag);
+    return isCompositeType();
   }
 }
 
 /// isCompositeType - Return true if the specified tag is legal for
 /// DICompositeType.
-bool DIType::isCompositeType(unsigned TAG) {
-  switch (TAG) {
+bool DIDescriptor::isCompositeType() const {
+  assert (!isNull() && "Invalid descriptor!");
+  unsigned Tag = getTag();
+
+  switch (Tag) {
   case dwarf::DW_TAG_array_type:
   case dwarf::DW_TAG_structure_type:
   case dwarf::DW_TAG_union_type:
@@ -174,7 +178,10 @@ bool DIType::isCompositeType(unsigned TAG) {
 }
 
 /// isVariable - Return true if the specified tag is legal for DIVariable.
-bool DIVariable::isVariable(unsigned Tag) {
+bool DIDescriptor::isVariable() const {
+  assert (!isNull() && "Invalid descriptor!");
+  unsigned Tag = getTag();
+
   switch (Tag) {
   case dwarf::DW_TAG_auto_variable:
   case dwarf::DW_TAG_arg_variable:
@@ -185,6 +192,52 @@ bool DIVariable::isVariable(unsigned Tag) {
   }
 }
 
+/// isSubprogram - Return true if the specified tag is legal for
+/// DISubprogram.
+bool DIDescriptor::isSubprogram() const {
+  assert (!isNull() && "Invalid descriptor!");
+  unsigned Tag = getTag();
+  
+  return Tag == dwarf::DW_TAG_subprogram;
+}
+
+/// isGlobalVariable - Return true if the specified tag is legal for
+/// DIGlobalVariable.
+bool DIDescriptor::isGlobalVariable() const {
+  assert (!isNull() && "Invalid descriptor!");
+  unsigned Tag = getTag();
+
+  return Tag == dwarf::DW_TAG_variable;
+}
+
+/// isScope - Return true if the specified tag is one of the scope 
+/// related tag.
+bool DIDescriptor::isScope() const {
+  assert (!isNull() && "Invalid descriptor!");
+  unsigned Tag = getTag();
+
+  switch (Tag) {
+    case dwarf::DW_TAG_compile_unit:
+    case dwarf::DW_TAG_lexical_block:
+    case dwarf::DW_TAG_subprogram:
+      return true;
+    default:
+      break;
+  }
+  return false;
+}
+
+//===----------------------------------------------------------------------===//
+// Simple Descriptor Constructors and other Methods
+//===----------------------------------------------------------------------===//
+
+DIType::DIType(MDNode *N) : DIDescriptor(N) {
+  if (!N) return;
+  if (!isBasicType() && !isDerivedType() && !isCompositeType()) {
+    DbgNode = 0;
+  }
+}
+
 unsigned DIArray::getNumElements() const {
   assert (DbgNode && "Invalid DIArray");
   return DbgNode->getNumElements();
@@ -366,11 +419,11 @@ void DIType::dump() const {
   if (isForwardDecl())
     errs() << " [fwd] ";
 
-  if (isBasicType(Tag))
+  if (isBasicType())
     DIBasicType(DbgNode).dump();
-  else if (isDerivedType(Tag))
+  else if (isDerivedType())
     DIDerivedType(DbgNode).dump();
-  else if (isCompositeType(Tag))
+  else if (isCompositeType())
     DICompositeType(DbgNode).dump();
   else {
     errs() << "Invalid DIType\n";
@@ -417,7 +470,7 @@ void DIGlobal::dump() const {
   if (isDefinition())
     errs() << " [def] ";
 
-  if (isGlobalVariable(Tag))
+  if (isGlobalVariable())
     DIGlobalVariable(DbgNode).dump();
 
   errs() << "\n";
@@ -478,7 +531,7 @@ DIArray DIFactory::GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys) {
   else
     for (unsigned i = 0; i != NumTys; ++i)
       Elts.push_back(Tys[i].getNode());
-  
+
   return DIArray(MDNode::get(VMContext,Elts.data(), Elts.size()));
 }
 
@@ -529,7 +582,6 @@ DIEnumerator DIFactory::CreateEnumerator(const std::string &Name, uint64_t Val){
     MDString::get(VMContext, Name),
     ConstantInt::get(Type::getInt64Ty(VMContext), Val)
   };
-
   return DIEnumerator(MDNode::get(VMContext, &Elts[0], 3));
 }
 
@@ -555,7 +607,6 @@ DIBasicType DIFactory::CreateBasicType(DIDescriptor Context,
     ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
     ConstantInt::get(Type::getInt32Ty(VMContext), Encoding)
   };
-  
   return DIBasicType(MDNode::get(VMContext, &Elts[0], 10));
 }
 
@@ -583,7 +634,6 @@ DIDerivedType DIFactory::CreateDerivedType(unsigned Tag,
     ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
     DerivedFrom.getNode(),
   };
-
   return DIDerivedType(MDNode::get(VMContext, &Elts[0], 10));
 }
 
@@ -615,7 +665,6 @@ DICompositeType DIFactory::CreateCompositeType(unsigned Tag,
     Elements.getNode(),
     ConstantInt::get(Type::getInt32Ty(VMContext), RuntimeLang)
   };
-
   return DICompositeType(MDNode::get(VMContext, &Elts[0], 12));
 }
 
@@ -645,7 +694,6 @@ DISubprogram DIFactory::CreateSubprogram(DIDescriptor Context,
     ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
     ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition)
   };
-  
   return DISubprogram(MDNode::get(VMContext, &Elts[0], 11));
 }
 
@@ -696,7 +744,6 @@ DIVariable DIFactory::CreateVariable(unsigned Tag, DIDescriptor Context,
     ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
     Type.getNode(),
   };
-  
   return DIVariable(MDNode::get(VMContext, &Elts[0], 6));
 }
 
@@ -708,7 +755,6 @@ DIBlock DIFactory::CreateBlock(DIDescriptor Context) {
     GetTagConstant(dwarf::DW_TAG_lexical_block),
     Context.getNode()
   };
-
   return DIBlock(MDNode::get(VMContext, &Elts[0], 2));
 }
 
@@ -825,7 +871,7 @@ void DebugInfoFinder::processType(DIType DT) {
     return;
 
   addCompileUnit(DT.getCompileUnit());
-  if (DT.isCompositeType(DT.getTag())) {
+  if (DT.isCompositeType()) {
     DICompositeType DCT(DT.getNode());
     processType(DCT.getTypeDerivedFrom());
     DIArray DA = DCT.getTypeArray();
@@ -838,7 +884,7 @@ void DebugInfoFinder::processType(DIType DT) {
         else 
           processSubprogram(DISubprogram(D.getNode()));
       }
-  } else if (DT.isDerivedType(DT.getTag())) {
+  } else if (DT.isDerivedType()) {
     DIDerivedType DDT(DT.getNode());
     if (!DDT.isNull()) 
       processType(DDT.getTypeDerivedFrom());