DwarfDebug: Allocate DIEValues with a BumpPtrAllocator. Most of them are

POD-like anyway, so we don't even care about calling their d'tors (DIEBlock
being the exception).

~6% less mallocs and ~1% compile time improvement on clang -O0 -g oggenc.c



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@100035 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Benjamin Kramer
2010-03-31 19:34:01 +00:00
parent e09ccab0ce
commit 345ef343cc
4 changed files with 30 additions and 32 deletions

View File

@@ -19,6 +19,7 @@
#include "llvm/MC/MCStreamer.h" #include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCSymbol.h" #include "llvm/MC/MCSymbol.h"
#include "llvm/Target/TargetData.h" #include "llvm/Target/TargetData.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/Debug.h" #include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Format.h" #include "llvm/Support/Format.h"
@@ -114,8 +115,8 @@ DIE::~DIE() {
/// addSiblingOffset - Add a sibling offset field to the front of the DIE. /// addSiblingOffset - Add a sibling offset field to the front of the DIE.
/// ///
DIEValue *DIE::addSiblingOffset() { DIEValue *DIE::addSiblingOffset(BumpPtrAllocator &A) {
DIEInteger *DI = new DIEInteger(0); DIEInteger *DI = new (A) DIEInteger(0);
Values.insert(Values.begin(), DI); Values.insert(Values.begin(), DI);
Abbrev.AddFirstAttribute(dwarf::DW_AT_sibling, dwarf::DW_FORM_ref4); Abbrev.AddFirstAttribute(dwarf::DW_AT_sibling, dwarf::DW_FORM_ref4);
return DI; return DI;

View File

@@ -174,7 +174,7 @@ namespace llvm {
/// The caller is responsible for deleting the return value at or after the /// The caller is responsible for deleting the return value at or after the
/// same time it destroys this DIE. /// same time it destroys this DIE.
/// ///
DIEValue *addSiblingOffset(); DIEValue *addSiblingOffset(BumpPtrAllocator &A);
/// addChild - Add a child to the DIE. /// addChild - Add a child to the DIE.
/// ///

View File

@@ -301,15 +301,15 @@ DbgScope::~DbgScope() {
DwarfDebug::DwarfDebug(raw_ostream &OS, AsmPrinter *A, const MCAsmInfo *T) DwarfDebug::DwarfDebug(raw_ostream &OS, AsmPrinter *A, const MCAsmInfo *T)
: DwarfPrinter(OS, A, T), ModuleCU(0), : DwarfPrinter(OS, A, T), ModuleCU(0),
AbbreviationsSet(InitAbbreviationsSetSize), Abbreviations(), AbbreviationsSet(InitAbbreviationsSetSize), Abbreviations(),
DIEValues(), SectionSourceLines(), didInitial(false), shouldEmit(false), DIEBlocks(), SectionSourceLines(), didInitial(false), shouldEmit(false),
CurrentFnDbgScope(0), PrevDILoc(0), DebugTimer(0) { CurrentFnDbgScope(0), PrevDILoc(0), DebugTimer(0) {
NextStringPoolNumber = 0; NextStringPoolNumber = 0;
if (TimePassesIsEnabled) if (TimePassesIsEnabled)
DebugTimer = new Timer("Dwarf Debug Writer"); DebugTimer = new Timer("Dwarf Debug Writer");
} }
DwarfDebug::~DwarfDebug() { DwarfDebug::~DwarfDebug() {
for (unsigned j = 0, M = DIEValues.size(); j < M; ++j) for (unsigned j = 0, M = DIEBlocks.size(); j < M; ++j)
delete DIEValues[j]; DIEBlocks[j]->~DIEBlock();
delete DebugTimer; delete DebugTimer;
} }
@@ -349,8 +349,7 @@ void DwarfDebug::assignAbbrevNumber(DIEAbbrev &Abbrev) {
/// createDIEEntry - Creates a new DIEEntry to be a proxy for a debug /// createDIEEntry - Creates a new DIEEntry to be a proxy for a debug
/// information entry. /// information entry.
DIEEntry *DwarfDebug::createDIEEntry(DIE *Entry) { DIEEntry *DwarfDebug::createDIEEntry(DIE *Entry) {
DIEEntry *Value = new DIEEntry(Entry); DIEEntry *Value = new (DIEValueAllocator) DIEEntry(Entry);
DIEValues.push_back(Value);
return Value; return Value;
} }
@@ -359,8 +358,7 @@ DIEEntry *DwarfDebug::createDIEEntry(DIE *Entry) {
void DwarfDebug::addUInt(DIE *Die, unsigned Attribute, void DwarfDebug::addUInt(DIE *Die, unsigned Attribute,
unsigned Form, uint64_t Integer) { unsigned Form, uint64_t Integer) {
if (!Form) Form = DIEInteger::BestForm(false, Integer); if (!Form) Form = DIEInteger::BestForm(false, Integer);
DIEValue *Value = new DIEInteger(Integer); DIEValue *Value = new (DIEValueAllocator) DIEInteger(Integer);
DIEValues.push_back(Value);
Die->addValue(Attribute, Form, Value); Die->addValue(Attribute, Form, Value);
} }
@@ -369,8 +367,7 @@ void DwarfDebug::addUInt(DIE *Die, unsigned Attribute,
void DwarfDebug::addSInt(DIE *Die, unsigned Attribute, void DwarfDebug::addSInt(DIE *Die, unsigned Attribute,
unsigned Form, int64_t Integer) { unsigned Form, int64_t Integer) {
if (!Form) Form = DIEInteger::BestForm(true, Integer); if (!Form) Form = DIEInteger::BestForm(true, Integer);
DIEValue *Value = new DIEInteger(Integer); DIEValue *Value = new (DIEValueAllocator) DIEInteger(Integer);
DIEValues.push_back(Value);
Die->addValue(Attribute, Form, Value); Die->addValue(Attribute, Form, Value);
} }
@@ -378,8 +375,7 @@ void DwarfDebug::addSInt(DIE *Die, unsigned Attribute,
/// keeps string reference. /// keeps string reference.
void DwarfDebug::addString(DIE *Die, unsigned Attribute, unsigned Form, void DwarfDebug::addString(DIE *Die, unsigned Attribute, unsigned Form,
StringRef String) { StringRef String) {
DIEValue *Value = new DIEString(String); DIEValue *Value = new (DIEValueAllocator) DIEString(String);
DIEValues.push_back(Value);
Die->addValue(Attribute, Form, Value); Die->addValue(Attribute, Form, Value);
} }
@@ -387,8 +383,7 @@ void DwarfDebug::addString(DIE *Die, unsigned Attribute, unsigned Form,
/// ///
void DwarfDebug::addLabel(DIE *Die, unsigned Attribute, unsigned Form, void DwarfDebug::addLabel(DIE *Die, unsigned Attribute, unsigned Form,
const MCSymbol *Label) { const MCSymbol *Label) {
DIEValue *Value = new DIELabel(Label); DIEValue *Value = new (DIEValueAllocator) DIELabel(Label);
DIEValues.push_back(Value);
Die->addValue(Attribute, Form, Value); Die->addValue(Attribute, Form, Value);
} }
@@ -396,8 +391,7 @@ void DwarfDebug::addLabel(DIE *Die, unsigned Attribute, unsigned Form,
/// ///
void DwarfDebug::addDelta(DIE *Die, unsigned Attribute, unsigned Form, void DwarfDebug::addDelta(DIE *Die, unsigned Attribute, unsigned Form,
const MCSymbol *Hi, const MCSymbol *Lo) { const MCSymbol *Hi, const MCSymbol *Lo) {
DIEValue *Value = new DIEDelta(Hi, Lo); DIEValue *Value = new (DIEValueAllocator) DIEDelta(Hi, Lo);
DIEValues.push_back(Value);
Die->addValue(Attribute, Form, Value); Die->addValue(Attribute, Form, Value);
} }
@@ -406,7 +400,7 @@ void DwarfDebug::addDelta(DIE *Die, unsigned Attribute, unsigned Form,
void DwarfDebug::addBlock(DIE *Die, unsigned Attribute, unsigned Form, void DwarfDebug::addBlock(DIE *Die, unsigned Attribute, unsigned Form,
DIEBlock *Block) { DIEBlock *Block) {
Block->ComputeSize(TD); Block->ComputeSize(TD);
DIEValues.push_back(Block); DIEBlocks.push_back(Block); // Memoize so we can call the destructor later on.
Die->addValue(Attribute, Block->BestForm(), Block); Die->addValue(Attribute, Block->BestForm(), Block);
} }
@@ -560,7 +554,7 @@ void DwarfDebug::addComplexAddress(DbgVariable *&DV, DIE *Die,
// Decode the original location, and use that as the start of the byref // Decode the original location, and use that as the start of the byref
// variable's location. // variable's location.
unsigned Reg = RI->getDwarfRegNum(Location.getReg(), false); unsigned Reg = RI->getDwarfRegNum(Location.getReg(), false);
DIEBlock *Block = new DIEBlock(); DIEBlock *Block = new (DIEValueAllocator) DIEBlock();
if (Location.isReg()) { if (Location.isReg()) {
if (Reg < 32) { if (Reg < 32) {
@@ -700,7 +694,7 @@ void DwarfDebug::addBlockByrefAddress(DbgVariable *&DV, DIE *Die,
// Decode the original location, and use that as the start of the byref // Decode the original location, and use that as the start of the byref
// variable's location. // variable's location.
unsigned Reg = RI->getDwarfRegNum(Location.getReg(), false); unsigned Reg = RI->getDwarfRegNum(Location.getReg(), false);
DIEBlock *Block = new DIEBlock(); DIEBlock *Block = new (DIEValueAllocator) DIEBlock();
if (Location.isReg()) { if (Location.isReg()) {
if (Reg < 32) if (Reg < 32)
@@ -755,7 +749,7 @@ void DwarfDebug::addBlockByrefAddress(DbgVariable *&DV, DIE *Die,
void DwarfDebug::addAddress(DIE *Die, unsigned Attribute, void DwarfDebug::addAddress(DIE *Die, unsigned Attribute,
const MachineLocation &Location) { const MachineLocation &Location) {
unsigned Reg = RI->getDwarfRegNum(Location.getReg(), false); unsigned Reg = RI->getDwarfRegNum(Location.getReg(), false);
DIEBlock *Block = new DIEBlock(); DIEBlock *Block = new (DIEValueAllocator) DIEBlock();
if (Location.isReg()) { if (Location.isReg()) {
if (Reg < 32) { if (Reg < 32) {
@@ -1102,7 +1096,7 @@ DIE *DwarfDebug::createMemberDIE(const DIDerivedType &DT) {
addSourceLine(MemberDie, &DT); addSourceLine(MemberDie, &DT);
DIEBlock *MemLocationDie = new DIEBlock(); DIEBlock *MemLocationDie = new (DIEValueAllocator) DIEBlock();
addUInt(MemLocationDie, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst); addUInt(MemLocationDie, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst);
uint64_t Size = DT.getSizeInBits(); uint64_t Size = DT.getSizeInBits();
@@ -1138,7 +1132,7 @@ DIE *DwarfDebug::createMemberDIE(const DIDerivedType &DT) {
// expression to extract appropriate offset from vtable. // expression to extract appropriate offset from vtable.
// BaseAddr = ObAddr + *((*ObAddr) - Offset) // BaseAddr = ObAddr + *((*ObAddr) - Offset)
DIEBlock *VBaseLocationDie = new DIEBlock(); DIEBlock *VBaseLocationDie = new (DIEValueAllocator) DIEBlock();
addUInt(VBaseLocationDie, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_dup); addUInt(VBaseLocationDie, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_dup);
addUInt(VBaseLocationDie, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_deref); addUInt(VBaseLocationDie, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_deref);
addUInt(VBaseLocationDie, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_constu); addUInt(VBaseLocationDie, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_constu);
@@ -1204,7 +1198,7 @@ DIE *DwarfDebug::createSubprogramDIE(const DISubprogram &SP, bool MakeDecl) {
unsigned VK = SP.getVirtuality(); unsigned VK = SP.getVirtuality();
if (VK) { if (VK) {
addUInt(SPDie, dwarf::DW_AT_virtuality, dwarf::DW_FORM_flag, VK); addUInt(SPDie, dwarf::DW_AT_virtuality, dwarf::DW_FORM_flag, VK);
DIEBlock *Block = new DIEBlock(); DIEBlock *Block = new (DIEValueAllocator) DIEBlock();
addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_constu); addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_constu);
addUInt(Block, 0, dwarf::DW_FORM_data1, SP.getVirtualIndex()); addUInt(Block, 0, dwarf::DW_FORM_data1, SP.getVirtualIndex());
addBlock(SPDie, dwarf::DW_AT_vtable_elem_location, 0, Block); addBlock(SPDie, dwarf::DW_AT_vtable_elem_location, 0, Block);
@@ -1509,7 +1503,7 @@ DIE *DwarfDebug::constructVariableDIE(DbgVariable *DV, DbgScope *Scope) {
VS); VS);
} else if (DbgValueInsn->getOperand(0).getType() == } else if (DbgValueInsn->getOperand(0).getType() ==
MachineOperand::MO_Immediate) { MachineOperand::MO_Immediate) {
DIEBlock *Block = new DIEBlock(); DIEBlock *Block = new (DIEValueAllocator) DIEBlock();
unsigned Imm = DbgValueInsn->getOperand(0).getImm(); unsigned Imm = DbgValueInsn->getOperand(0).getImm();
addUInt(Block, 0, dwarf::DW_FORM_udata, Imm); addUInt(Block, 0, dwarf::DW_FORM_udata, Imm);
addBlock(VariableDie, dwarf::DW_AT_const_value, 0, Block); addBlock(VariableDie, dwarf::DW_AT_const_value, 0, Block);
@@ -1729,7 +1723,7 @@ void DwarfDebug::constructGlobalVariableDIE(MDNode *N) {
DIE *VariableSpecDIE = new DIE(dwarf::DW_TAG_variable); DIE *VariableSpecDIE = new DIE(dwarf::DW_TAG_variable);
addDIEEntry(VariableSpecDIE, dwarf::DW_AT_specification, addDIEEntry(VariableSpecDIE, dwarf::DW_AT_specification,
dwarf::DW_FORM_ref4, VariableDie); dwarf::DW_FORM_ref4, VariableDie);
DIEBlock *Block = new DIEBlock(); DIEBlock *Block = new (DIEValueAllocator) DIEBlock();
addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_addr); addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_addr);
addLabel(Block, 0, dwarf::DW_FORM_udata, addLabel(Block, 0, dwarf::DW_FORM_udata,
Asm->Mang->getSymbol(DI_GV.getGlobal())); Asm->Mang->getSymbol(DI_GV.getGlobal()));
@@ -1737,7 +1731,7 @@ void DwarfDebug::constructGlobalVariableDIE(MDNode *N) {
addUInt(VariableDie, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag, 1); addUInt(VariableDie, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag, 1);
ModuleCU->addDie(VariableSpecDIE); ModuleCU->addDie(VariableSpecDIE);
} else { } else {
DIEBlock *Block = new DIEBlock(); DIEBlock *Block = new (DIEValueAllocator) DIEBlock();
addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_addr); addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_addr);
addLabel(Block, 0, dwarf::DW_FORM_udata, addLabel(Block, 0, dwarf::DW_FORM_udata,
Asm->Mang->getSymbol(DI_GV.getGlobal())); Asm->Mang->getSymbol(DI_GV.getGlobal()));
@@ -2383,7 +2377,7 @@ DwarfDebug::computeSizeAndOffset(DIE *Die, unsigned Offset, bool Last) {
// If not last sibling and has children then add sibling offset attribute. // If not last sibling and has children then add sibling offset attribute.
if (!Last && !Children.empty()) if (!Last && !Children.empty())
DIEValues.push_back(Die->addSiblingOffset()); Die->addSiblingOffset(DIEValueAllocator);
// Record the abbreviation. // Record the abbreviation.
assignAbbrevNumber(Die->getAbbrev()); assignAbbrevNumber(Die->getAbbrev());

View File

@@ -19,6 +19,7 @@
#include "llvm/CodeGen/AsmPrinter.h" #include "llvm/CodeGen/AsmPrinter.h"
#include "llvm/CodeGen/MachineLocation.h" #include "llvm/CodeGen/MachineLocation.h"
#include "llvm/Analysis/DebugInfo.h" #include "llvm/Analysis/DebugInfo.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/FoldingSet.h" #include "llvm/ADT/FoldingSet.h"
@@ -98,9 +99,11 @@ class DwarfDebug : public DwarfPrinter {
/// Lines - List of source line correspondence. /// Lines - List of source line correspondence.
std::vector<SrcLineInfo> Lines; std::vector<SrcLineInfo> Lines;
/// DIEValues - A list of all the unique values in use. /// DIEBlocks - A list of all the DIEBlocks in use.
/// std::vector<DIEBlock *> DIEBlocks;
std::vector<DIEValue *> DIEValues;
// DIEValueAllocator - All DIEValues are allocated through this allocator.
BumpPtrAllocator DIEValueAllocator;
/// StringPool - A String->Symbol mapping of strings used by indirect /// StringPool - A String->Symbol mapping of strings used by indirect
/// references. /// references.