mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-24 22:24:54 +00:00
AsmPrinter: Store abbreviation data directly in DIE and DIEValue
Stop storing a `DIEAbbrev` in `DIE`, since the data fits neatly inside the `DIEValue` list. Besides being a cleaner data structure (avoiding the parallel arrays), this gives us more freedom to rearrange the `DIEValue` list. This fixes the temporary memory regression from 845 MB up to 879 MB, and drops it further to 829 MB for a net memory decrease of around 1.9% (incremental decrease around 5.7%). (I'm looking at `llc` memory usage on `verify-uselistorder.lto.opt.bc`; see r236629 for details.) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238364 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -254,24 +254,20 @@ void AsmPrinter::emitCFIInstruction(const MCCFIInstruction &Inst) const {
|
||||
}
|
||||
|
||||
void AsmPrinter::emitDwarfDIE(const DIE &Die) const {
|
||||
// Get the abbreviation for this DIE.
|
||||
const DIEAbbrev &Abbrev = Die.getAbbrev();
|
||||
|
||||
// Emit the code (index) for the abbreviation.
|
||||
if (isVerbose())
|
||||
OutStreamer->AddComment("Abbrev [" + Twine(Abbrev.getNumber()) +
|
||||
"] 0x" + Twine::utohexstr(Die.getOffset()) +
|
||||
":0x" + Twine::utohexstr(Die.getSize()) + " " +
|
||||
dwarf::TagString(Abbrev.getTag()));
|
||||
EmitULEB128(Abbrev.getNumber());
|
||||
OutStreamer->AddComment("Abbrev [" + Twine(Die.getAbbrevNumber()) + "] 0x" +
|
||||
Twine::utohexstr(Die.getOffset()) + ":0x" +
|
||||
Twine::utohexstr(Die.getSize()) + " " +
|
||||
dwarf::TagString(Die.getTag()));
|
||||
EmitULEB128(Die.getAbbrevNumber());
|
||||
|
||||
const SmallVectorImpl<DIEValue> &Values = Die.getValues();
|
||||
const SmallVectorImpl<DIEAbbrevData> &AbbrevData = Abbrev.getData();
|
||||
|
||||
// Emit the DIE attribute values.
|
||||
for (unsigned i = 0, N = Values.size(); i < N; ++i) {
|
||||
dwarf::Attribute Attr = AbbrevData[i].getAttribute();
|
||||
dwarf::Form Form = AbbrevData[i].getForm();
|
||||
dwarf::Attribute Attr = Values[i].getAttribute();
|
||||
dwarf::Form Form = Values[i].getForm();
|
||||
assert(Form && "Too many attributes for DIE (check abbreviation)");
|
||||
|
||||
if (isVerbose()) {
|
||||
@@ -286,7 +282,7 @@ void AsmPrinter::emitDwarfDIE(const DIE &Die) const {
|
||||
}
|
||||
|
||||
// Emit the DIE children if any.
|
||||
if (Abbrev.hasChildren()) {
|
||||
if (Die.hasChildren()) {
|
||||
for (auto &Child : Die.getChildren())
|
||||
emitDwarfDIE(*Child);
|
||||
|
||||
|
@@ -107,6 +107,13 @@ void DIEAbbrev::print(raw_ostream &O) {
|
||||
void DIEAbbrev::dump() { print(dbgs()); }
|
||||
#endif
|
||||
|
||||
DIEAbbrev DIE::generateAbbrev() const {
|
||||
DIEAbbrev Abbrev(Tag, hasChildren());
|
||||
for (const DIEValue &V : Values)
|
||||
Abbrev.AddAttribute(V.getAttribute(), V.getForm());
|
||||
return Abbrev;
|
||||
}
|
||||
|
||||
/// Climb up the parent chain to get the unit DIE to which this DIE
|
||||
/// belongs.
|
||||
const DIE *DIE::getUnit() const {
|
||||
@@ -130,12 +137,11 @@ const DIE *DIE::getUnitOrNull() const {
|
||||
|
||||
DIEValue DIE::findAttribute(dwarf::Attribute Attribute) const {
|
||||
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)
|
||||
if (Values[i].getAttribute() == Attribute)
|
||||
return Values[i];
|
||||
return DIEValue();
|
||||
}
|
||||
@@ -143,7 +149,7 @@ DIEValue DIE::findAttribute(dwarf::Attribute Attribute) const {
|
||||
#ifndef NDEBUG
|
||||
void DIE::print(raw_ostream &O, unsigned IndentCount) const {
|
||||
const std::string Indent(IndentCount, ' ');
|
||||
bool isBlock = Abbrev.getTag() == 0;
|
||||
bool isBlock = getTag() == 0;
|
||||
|
||||
if (!isBlock) {
|
||||
O << Indent
|
||||
@@ -153,26 +159,24 @@ void DIE::print(raw_ostream &O, unsigned IndentCount) const {
|
||||
<< ", Size: " << Size << "\n";
|
||||
|
||||
O << Indent
|
||||
<< dwarf::TagString(Abbrev.getTag())
|
||||
<< dwarf::TagString(getTag())
|
||||
<< " "
|
||||
<< dwarf::ChildrenString(Abbrev.hasChildren()) << "\n";
|
||||
<< dwarf::ChildrenString(hasChildren()) << "\n";
|
||||
} else {
|
||||
O << "Size: " << Size << "\n";
|
||||
}
|
||||
|
||||
const SmallVectorImpl<DIEAbbrevData> &Data = Abbrev.getData();
|
||||
|
||||
IndentCount += 2;
|
||||
for (unsigned i = 0, N = Data.size(); i < N; ++i) {
|
||||
for (unsigned i = 0, N = Values.size(); i < N; ++i) {
|
||||
O << Indent;
|
||||
|
||||
if (!isBlock)
|
||||
O << dwarf::AttributeString(Data[i].getAttribute());
|
||||
O << dwarf::AttributeString(Values[i].getAttribute());
|
||||
else
|
||||
O << "Blk[" << i << "]";
|
||||
|
||||
O << " "
|
||||
<< dwarf::FormEncodingString(Data[i].getForm())
|
||||
<< dwarf::FormEncodingString(Values[i].getForm())
|
||||
<< " ";
|
||||
Values[i].print(O);
|
||||
O << "\n";
|
||||
@@ -505,9 +509,8 @@ void DIETypeSignature::print(raw_ostream &O) const {
|
||||
///
|
||||
unsigned DIELoc::ComputeSize(const AsmPrinter *AP) const {
|
||||
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());
|
||||
Size += Values[i].SizeOf(AP, Values[i].getForm());
|
||||
}
|
||||
|
||||
return Size;
|
||||
@@ -526,9 +529,8 @@ void DIELoc::EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const {
|
||||
Asm->EmitULEB128(Size); break;
|
||||
}
|
||||
|
||||
const SmallVectorImpl<DIEAbbrevData> &AbbrevData = Abbrev.getData();
|
||||
for (unsigned i = 0, N = Values.size(); i < N; ++i)
|
||||
Values[i].EmitValue(Asm, AbbrevData[i].getForm());
|
||||
Values[i].EmitValue(Asm, Values[i].getForm());
|
||||
}
|
||||
|
||||
/// SizeOf - Determine size of location data in bytes.
|
||||
@@ -560,9 +562,8 @@ void DIELoc::print(raw_ostream &O) const {
|
||||
///
|
||||
unsigned DIEBlock::ComputeSize(const AsmPrinter *AP) const {
|
||||
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());
|
||||
Size += Values[i].SizeOf(AP, Values[i].getForm());
|
||||
}
|
||||
|
||||
return Size;
|
||||
@@ -579,9 +580,8 @@ void DIEBlock::EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const {
|
||||
case dwarf::DW_FORM_block: Asm->EmitULEB128(Size); break;
|
||||
}
|
||||
|
||||
const SmallVectorImpl<DIEAbbrevData> &AbbrevData = Abbrev.getData();
|
||||
for (unsigned i = 0, N = Values.size(); i < N; ++i)
|
||||
Values[i].EmitValue(Asm, AbbrevData[i].getForm());
|
||||
Values[i].EmitValue(Asm, Values[i].getForm());
|
||||
}
|
||||
|
||||
/// SizeOf - Determine size of block data in bytes.
|
||||
|
@@ -32,12 +32,11 @@ using namespace llvm;
|
||||
/// a reference to it.
|
||||
static StringRef getDIEStringAttr(const DIE &Die, uint16_t Attr) {
|
||||
const auto &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)
|
||||
if (Values[i].getAttribute() == Attr)
|
||||
return Values[i].getDIEString().getString();
|
||||
}
|
||||
return StringRef("");
|
||||
@@ -120,19 +119,17 @@ void DIEHash::addParentContext(const DIE &Parent) {
|
||||
// Collect all of the attributes for a particular DIE in single structure.
|
||||
void DIEHash::collectAttributes(const DIE &Die, DIEAttrs &Attrs) {
|
||||
const SmallVectorImpl<DIEValue> &Values = Die.getValues();
|
||||
const DIEAbbrev &Abbrevs = Die.getAbbrev();
|
||||
|
||||
#define COLLECT_ATTR(NAME) \
|
||||
case dwarf::NAME: \
|
||||
Attrs.NAME.Val = Values[i]; \
|
||||
Attrs.NAME.Desc = &Abbrevs.getData()[i]; \
|
||||
break
|
||||
|
||||
for (size_t i = 0, e = Values.size(); i != e; ++i) {
|
||||
DEBUG(dbgs() << "Attribute: "
|
||||
<< dwarf::AttributeString(Abbrevs.getData()[i].getAttribute())
|
||||
<< dwarf::AttributeString(Values[i].getAttribute())
|
||||
<< " added.\n");
|
||||
switch (Abbrevs.getData()[i].getAttribute()) {
|
||||
switch (Values[i].getAttribute()) {
|
||||
COLLECT_ATTR(DW_AT_name);
|
||||
COLLECT_ATTR(DW_AT_accessibility);
|
||||
COLLECT_ATTR(DW_AT_address_class);
|
||||
@@ -288,8 +285,7 @@ void DIEHash::hashLocList(const DIELocList &LocList) {
|
||||
// the form.
|
||||
void DIEHash::hashAttribute(AttrEntry Attr, dwarf::Tag Tag) {
|
||||
const DIEValue &Value = Attr.Val;
|
||||
const DIEAbbrevData *Desc = Attr.Desc;
|
||||
dwarf::Attribute Attribute = Desc->getAttribute();
|
||||
dwarf::Attribute Attribute = Value.getAttribute();
|
||||
|
||||
// Other attribute values use the letter 'A' as the marker, and the value
|
||||
// consists of the form code (encoded as an unsigned LEB128 value) followed by
|
||||
@@ -311,7 +307,7 @@ void DIEHash::hashAttribute(AttrEntry Attr, dwarf::Tag Tag) {
|
||||
case DIEValue::isInteger: {
|
||||
addULEB128('A');
|
||||
addULEB128(Attribute);
|
||||
switch (Desc->getForm()) {
|
||||
switch (Value.getForm()) {
|
||||
case dwarf::DW_FORM_data1:
|
||||
case dwarf::DW_FORM_data2:
|
||||
case dwarf::DW_FORM_data4:
|
||||
|
@@ -28,9 +28,10 @@ class CompileUnit;
|
||||
class DIEHash {
|
||||
|
||||
// The entry for a particular attribute.
|
||||
//
|
||||
// FIXME: Remove this struct, it's pretty boring now.
|
||||
struct AttrEntry {
|
||||
DIEValue Val;
|
||||
const DIEAbbrevData *Desc;
|
||||
};
|
||||
|
||||
// Collection of all attributes used in hashing a particular DIE.
|
||||
|
@@ -51,8 +51,10 @@ void DwarfCompileUnit::addLocalLabelAddress(DIE &Die,
|
||||
if (Label)
|
||||
DD->addArangeLabel(SymbolCU(this, Label));
|
||||
|
||||
Die.addValue(Attribute, dwarf::DW_FORM_addr,
|
||||
Label ? DIEValue(DIELabel(Label)) : DIEValue(DIEInteger(0)));
|
||||
if (Label)
|
||||
Die.addValue(Attribute, dwarf::DW_FORM_addr, DIELabel(Label));
|
||||
else
|
||||
Die.addValue(Attribute, dwarf::DW_FORM_addr, DIEInteger(0));
|
||||
}
|
||||
|
||||
unsigned DwarfCompileUnit::getOrCreateSourceID(StringRef FileName,
|
||||
@@ -253,9 +255,7 @@ void DwarfCompileUnit::initStmtList() {
|
||||
}
|
||||
|
||||
void DwarfCompileUnit::applyStmtList(DIE &D) {
|
||||
D.addValue(dwarf::DW_AT_stmt_list,
|
||||
UnitDie.getAbbrev().getData()[stmtListIndex].getForm(),
|
||||
UnitDie.getValues()[stmtListIndex]);
|
||||
D.addValue(UnitDie.getValues()[stmtListIndex]);
|
||||
}
|
||||
|
||||
void DwarfCompileUnit::attachLowHighPC(DIE &D, const MCSymbol *Begin,
|
||||
|
@@ -24,21 +24,27 @@ DwarfFile::~DwarfFile() {}
|
||||
|
||||
// Define a unique number for the abbreviation.
|
||||
//
|
||||
void DwarfFile::assignAbbrevNumber(DIEAbbrev &Abbrev) {
|
||||
// Check the set for priors.
|
||||
DIEAbbrev *InSet = AbbreviationsSet.GetOrInsertNode(&Abbrev);
|
||||
DIEAbbrev &DwarfFile::assignAbbrevNumber(DIE &Die) {
|
||||
FoldingSetNodeID ID;
|
||||
DIEAbbrev Abbrev = Die.generateAbbrev();
|
||||
Abbrev.Profile(ID);
|
||||
|
||||
// If it's newly added.
|
||||
if (InSet == &Abbrev) {
|
||||
// Add to abbreviation list.
|
||||
Abbreviations.push_back(&Abbrev);
|
||||
|
||||
// Assign the vector position + 1 as its number.
|
||||
Abbrev.setNumber(Abbreviations.size());
|
||||
} else {
|
||||
// Assign existing abbreviation number.
|
||||
Abbrev.setNumber(InSet->getNumber());
|
||||
void *InsertPos;
|
||||
if (DIEAbbrev *Existing =
|
||||
AbbreviationsSet.FindNodeOrInsertPos(ID, InsertPos)) {
|
||||
Die.setAbbrevNumber(Existing->getNumber());
|
||||
return *Existing;
|
||||
}
|
||||
|
||||
// Move the abbreviation to the heap and assign a number.
|
||||
DIEAbbrev *New = new (AbbrevAllocator) DIEAbbrev(std::move(Abbrev));
|
||||
Abbreviations.push_back(New);
|
||||
New->setNumber(Abbreviations.size());
|
||||
Die.setAbbrevNumber(Abbreviations.size());
|
||||
|
||||
// Store it for lookup.
|
||||
AbbreviationsSet.InsertNode(New, InsertPos);
|
||||
return *New;
|
||||
}
|
||||
|
||||
void DwarfFile::addUnit(std::unique_ptr<DwarfUnit> U) {
|
||||
@@ -83,10 +89,7 @@ void DwarfFile::computeSizeAndOffsets() {
|
||||
// CU. It returns the offset after laying out the DIE.
|
||||
unsigned DwarfFile::computeSizeAndOffset(DIE &Die, unsigned Offset) {
|
||||
// Record the abbreviation.
|
||||
assignAbbrevNumber(Die.getAbbrev());
|
||||
|
||||
// Get the abbreviation for this DIE.
|
||||
const DIEAbbrev &Abbrev = Die.getAbbrev();
|
||||
const DIEAbbrev &Abbrev = assignAbbrevNumber(Die);
|
||||
|
||||
// Set DIE offset
|
||||
Die.setOffset(Offset);
|
||||
|
@@ -37,6 +37,8 @@ class DwarfFile {
|
||||
// Target of Dwarf emission, used for sizing of abbreviations.
|
||||
AsmPrinter *Asm;
|
||||
|
||||
BumpPtrAllocator AbbrevAllocator;
|
||||
|
||||
// Used to uniquely define abbreviations.
|
||||
FoldingSet<DIEAbbrev> AbbreviationsSet;
|
||||
|
||||
@@ -72,8 +74,11 @@ public:
|
||||
/// \brief Compute the size and offset of all the DIEs.
|
||||
void computeSizeAndOffsets();
|
||||
|
||||
/// \brief Define a unique number for the abbreviation.
|
||||
void assignAbbrevNumber(DIEAbbrev &Abbrev);
|
||||
/// Define a unique number for the abbreviation.
|
||||
///
|
||||
/// Compute the abbreviation for \c Die, look up its unique number, and
|
||||
/// return a reference to it in the uniquing table.
|
||||
DIEAbbrev &assignAbbrevNumber(DIE &Die);
|
||||
|
||||
/// \brief Add a unit to the list of CUs.
|
||||
void addUnit(std::unique_ptr<DwarfUnit> U);
|
||||
|
Reference in New Issue
Block a user