Make DIELoc/DIEBlock's ComputeSize method const. Add a setSize
authorEric Christopher <echristo@gmail.com>
Thu, 20 Feb 2014 02:40:45 +0000 (02:40 +0000)
committerEric Christopher <echristo@gmail.com>
Thu, 20 Feb 2014 02:40:45 +0000 (02:40 +0000)
method to actually set it in the class to avoid computing it
multiple times.

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

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

index 79c4b438f8e0b54703d58d3b8a2614c2cbce1a5c..845bb4610a242fe5ca0949721d41c52d2f92be55 100644 (file)
@@ -424,14 +424,16 @@ void DIETypeSignature::dump() const { print(dbgs()); }
 
 /// ComputeSize - calculate the size of the location expression.
 ///
-unsigned DIELoc::ComputeSize(AsmPrinter *AP) {
-  if (!Size) {
-    const SmallVectorImpl<DIEAbbrevData> &AbbrevData = Abbrev.getData();
-    for (unsigned i = 0, N = Values.size(); i < N; ++i)
-      Size += Values[i]->SizeOf(AP, AbbrevData[i].getForm());
-  }
+unsigned DIELoc::ComputeSize(AsmPrinter *AP) const {
+  if (Size)
+    return Size;
+
+  unsigned Sz = 0;
+  const SmallVectorImpl<DIEAbbrevData> &AbbrevData = Abbrev.getData();
+  for (unsigned i = 0, N = Values.size(); i < N; ++i)
+    Sz += Values[i]->SizeOf(AP, AbbrevData[i].getForm());
 
-  return Size;
+  return Sz;
 }
 
 /// EmitValue - Emit location data.
@@ -479,14 +481,16 @@ void DIELoc::print(raw_ostream &O) const {
 
 /// ComputeSize - calculate the size of the block.
 ///
-unsigned DIEBlock::ComputeSize(AsmPrinter *AP) {
-  if (!Size) {
-    const SmallVectorImpl<DIEAbbrevData> &AbbrevData = Abbrev.getData();
-    for (unsigned i = 0, N = Values.size(); i < N; ++i)
-      Size += Values[i]->SizeOf(AP, AbbrevData[i].getForm());
-  }
+unsigned DIEBlock::ComputeSize(AsmPrinter *AP) const {
+  if (Size)
+    return Size;
+
+  unsigned Sz = 0;
+  const SmallVectorImpl<DIEAbbrevData> &AbbrevData = Abbrev.getData();
+  for (unsigned i = 0, N = Values.size(); i < N; ++i)
+    Sz += Values[i]->SizeOf(AP, AbbrevData[i].getForm());
 
-  return Size;
+  return Sz;
 }
 
 /// EmitValue - Emit block data.
index a35229da910376b06bd951ebd7062222b442fda7..d4f3154d15c7725ba277f3de7b5214ffedb0b0ed 100644 (file)
@@ -451,7 +451,11 @@ namespace llvm {
 
     /// ComputeSize - Calculate the size of the location expression.
     ///
-    unsigned ComputeSize(AsmPrinter *AP);
+    unsigned ComputeSize(AsmPrinter *AP) const;
+
+    /// setSize - Set the size of the location entry.
+    ///
+    void setSize(unsigned Sz) { Size = Sz; }
 
     /// BestForm - Choose the best form for data.
     ///
@@ -490,7 +494,11 @@ namespace llvm {
 
     /// ComputeSize - Calculate the size of the location expression.
     ///
-    unsigned ComputeSize(AsmPrinter *AP);
+    unsigned ComputeSize(AsmPrinter *AP) const;
+
+    /// setSize - Set the size of the block.
+    ///
+    void setSize(unsigned Sz) { Size = Sz; }
 
     /// BestForm - Choose the best form for data.
     ///
index dfffcadf61e91e0826b92b0e301f57d08aa48dcc..81dbfc505ac9257b15e497e47babf783de6048d0 100644 (file)
@@ -348,14 +348,14 @@ DIE *DwarfUnit::createAndAddDIE(unsigned Tag, DIE &Parent, DIDescriptor N) {
 /// addBlock - Add block data.
 ///
 void DwarfUnit::addBlock(DIE *Die, dwarf::Attribute Attribute, DIELoc *Loc) {
-  Loc->ComputeSize(Asm);
+  Loc->setSize(Loc->ComputeSize(Asm));
   DIELocs.push_back(Loc); // Memoize so we can call the destructor later on.
   Die->addValue(Attribute, Loc->BestForm(DD->getDwarfVersion()), Loc);
 }
 
 void DwarfUnit::addBlock(DIE *Die, dwarf::Attribute Attribute,
                          DIEBlock *Block) {
-  Block->ComputeSize(Asm);
+  Block->setSize(Block->ComputeSize(Asm));
   DIEBlocks.push_back(Block); // Memoize so we can call the destructor later on.
   Die->addValue(Attribute, Block->BestForm(), Block);
 }