Add a way to grab a particular attribute out of a DIE.
authorEric Christopher <echristo@gmail.com>
Wed, 7 Aug 2013 01:18:33 +0000 (01:18 +0000)
committerEric Christopher <echristo@gmail.com>
Wed, 7 Aug 2013 01:18:33 +0000 (01:18 +0000)
Use it when we're looking for a string in particular. Update comments
as well.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@187844 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/AsmPrinter/DIE.cpp
lib/CodeGen/AsmPrinter/DIE.h
lib/CodeGen/AsmPrinter/DwarfDebug.cpp

index 0b154123315a5f21e61c592f90c4080180c54f90..ab03861f9ddfcd063d5df1352c1bee3fddd9d25e 100644 (file)
@@ -122,6 +122,18 @@ DIE *DIE::getCompileUnit() {
   llvm_unreachable("We should not have orphaned DIEs.");
 }
 
+DIEValue *DIE::findAttribute(unsigned Attribute) {
+  const SmallVectorImpl<DIEValue *> &Values = getValues();
+  const DIEAbbrev &Abbrevs = getAbbrev();
+
+  // Iterate through all the attributes until we find the one we're
+  // looking for, if we can't find it return NULL.
+  for (size_t i = 0; i < Values.size(); ++i)
+    if (Abbrevs.getData()[i].getAttribute() == Attribute)
+      return Values[i];
+  return NULL;
+}
+
 #ifndef NDEBUG
 void DIE::print(raw_ostream &O, unsigned IndentCount) const {
   const std::string Indent(IndentCount, ' ');
index e2f49d64bee6c2607cadfeafbf80e0b32f59545a..bfd7d1daeedc9eb34b8d518e4c6b370dc4946c40 100644 (file)
@@ -175,6 +175,10 @@ namespace llvm {
       Child->Parent = this;
     }
 
+    /// findAttribute - Find a value in the DIE with the attribute given, returns NULL
+    /// if no such attribute exists.
+    DIEValue *findAttribute(unsigned Attribute);
+
 #ifndef NDEBUG
     void print(raw_ostream &O, unsigned IndentCount = 0) const;
     void dump();
index 859805c8181bbb3c1df704e1e6bb04bd885aaff1..9a09bc1b6445d905962c664b7b9c4864579a27e7 100644 (file)
@@ -966,21 +966,13 @@ void DwarfDebug::collectDeadVariables() {
 typedef ArrayRef<uint8_t> HashValue;
 
 /// \brief Grabs the string in whichever attribute is passed in and returns
-/// a reference to it.
+/// a reference to it. Returns "" if the attribute doesn't exist.
 static StringRef getDIEStringAttr(DIE *Die, unsigned Attr) {
-  const SmallVectorImpl<DIEValue *> &Values = Die->getValues();
-  const DIEAbbrev &Abbrevs = Die->getAbbrev();
-
-  // Iterate through all the attributes until we find the one we're
-  // looking for, if we can't find it return an empty string.
-  for (size_t i = 0; i < Values.size(); ++i) {
-    if (Abbrevs.getData()[i].getAttribute() == Attr) {
-      DIEValue *V = Values[i];
-      assert(isa<DIEString>(V) && "String requested. Not a string.");
-      DIEString *S = cast<DIEString>(V);
-      return S->getString();
-    }
-  }
+  DIEValue *V = Die->findAttribute(Attr);
+
+  if (DIEString *S = dyn_cast_or_null<DIEString>(V))
+    return S->getString();
+
   return StringRef("");
 }