[llvm] r201751 - Make DIELoc/DIEBlock's ComputeSize method const. Add a setSize

Eric Christopher echristo at gmail.com
Wed Feb 19 18:40:45 PST 2014


Author: echristo
Date: Wed Feb 19 20:40:45 2014
New Revision: 201751

URL: http://llvm.org/viewvc/llvm-project?rev=201751&view=rev
Log:
Make DIELoc/DIEBlock's ComputeSize method const. Add a setSize
method to actually set it in the class to avoid computing it
multiple times.

Modified:
    llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp
    llvm/trunk/lib/CodeGen/AsmPrinter/DIE.h
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp?rev=201751&r1=201750&r2=201751&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp Wed Feb 19 20:40:45 2014
@@ -424,14 +424,16 @@ void DIETypeSignature::dump() const { pr
 
 /// 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.

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DIE.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DIE.h?rev=201751&r1=201750&r2=201751&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DIE.h (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DIE.h Wed Feb 19 20:40:45 2014
@@ -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.
     ///

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp?rev=201751&r1=201750&r2=201751&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp Wed Feb 19 20:40:45 2014
@@ -348,14 +348,14 @@ DIE *DwarfUnit::createAndAddDIE(unsigned
 /// 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);
 }





More information about the llvm-commits mailing list