AsmPrinter: Return added DIE from DIE::addChild()
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Wed, 27 May 2015 22:59:03 +0000 (22:59 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Wed, 27 May 2015 22:59:03 +0000 (22:59 +0000)
Change `DIE::addChild()` to return a reference to the just-added node,
and update consumers to use it directly.  An upcoming commit will
abstract away (and eventually change) the underlying storage of
`DIE::Children`.

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

include/llvm/CodeGen/DIE.h
lib/CodeGen/AsmPrinter/DwarfUnit.cpp

index 5a8f4915f5ea610cd919e32273f803cfaac7de3b..c843f3fd1a6249ca19c63d8afdf75d9ff56ff914 100644 (file)
@@ -543,10 +543,11 @@ public:
 
   /// addChild - Add a child to the DIE.
   ///
-  void addChild(std::unique_ptr<DIE> Child) {
+  DIE &addChild(std::unique_ptr<DIE> Child) {
     assert(!Child->getParent());
     Child->Parent = this;
     Children.push_back(std::move(Child));
+    return *Children.back();
   }
 
   /// Find a value in the DIE with the attribute given.
index fc57f2611884bd5428cac745be45e35df866d1f9..907f6706bc6a92e1ab384a2f1d0c45824f199ae4 100644 (file)
@@ -290,8 +290,7 @@ void DwarfUnit::addDIEEntry(DIE &Die, dwarf::Attribute Attribute,
 DIE &DwarfUnit::createAndAddDIE(unsigned Tag, DIE &Parent, const DINode *N) {
   assert(Tag != dwarf::DW_TAG_auto_variable &&
          Tag != dwarf::DW_TAG_arg_variable);
-  Parent.addChild(make_unique<DIE>((dwarf::Tag)Tag));
-  DIE &Die = *Parent.getChildren().back();
+  DIE &Die = Parent.addChild(make_unique<DIE>((dwarf::Tag)Tag));
   if (N)
     insertDIE(N, &Die);
   return Die;