mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 19:23:23 +01:00
[DWARF] Shrink AttributeSpec from 24 to 16 bytes.
This is a bit ugly because we can't put Optional into a union. Hide all of that behind a set of accessors and make accesses safer using asserts. llvm-svn: 313884
This commit is contained in:
parent
2f2ce511ad
commit
58b0a1afcd
@ -28,31 +28,54 @@ class raw_ostream;
|
||||
class DWARFAbbreviationDeclaration {
|
||||
public:
|
||||
struct AttributeSpec {
|
||||
AttributeSpec(dwarf::Attribute A, dwarf::Form F, Optional<int64_t> V)
|
||||
: Attr(A), Form(F), ByteSizeOrValue(V) {}
|
||||
AttributeSpec(dwarf::Attribute A, dwarf::Form F, int64_t Value)
|
||||
: Attr(A), Form(F), Value(Value) {
|
||||
assert(isImplicitConst());
|
||||
}
|
||||
AttributeSpec(dwarf::Attribute A, dwarf::Form F, Optional<uint8_t> ByteSize)
|
||||
: Attr(A), Form(F) {
|
||||
assert(!isImplicitConst());
|
||||
this->ByteSize.HasByteSize = ByteSize.hasValue();
|
||||
if (this->ByteSize.HasByteSize)
|
||||
this->ByteSize.ByteSize = *ByteSize;
|
||||
}
|
||||
|
||||
dwarf::Attribute Attr;
|
||||
dwarf::Form Form;
|
||||
|
||||
private:
|
||||
/// The following field is used for ByteSize for non-implicit_const
|
||||
/// attributes and as value for implicit_const ones, indicated by
|
||||
/// Form == DW_FORM_implicit_const.
|
||||
/// The following cases are distinguished:
|
||||
/// * Form != DW_FORM_implicit_const and ByteSizeOrValue has a value:
|
||||
/// ByteSizeOrValue contains the fixed size in bytes
|
||||
/// for the Form in this object.
|
||||
/// * Form != DW_FORM_implicit_const and ByteSizeOrValue is None:
|
||||
/// * Form != DW_FORM_implicit_const and HasByteSize is true:
|
||||
/// ByteSize contains the fixed size in bytes for the Form in this
|
||||
/// object.
|
||||
/// * Form != DW_FORM_implicit_const and HasByteSize is false:
|
||||
/// byte size of Form either varies according to the DWARFUnit
|
||||
/// that it is contained in or the value size varies and must be
|
||||
/// decoded from the debug information in order to determine its size.
|
||||
/// * Form == DW_FORM_implicit_const:
|
||||
/// ByteSizeOrValue contains value for the implicit_const attribute.
|
||||
Optional<int64_t> ByteSizeOrValue;
|
||||
/// Value contains value for the implicit_const attribute.
|
||||
struct ByteSizeStorage {
|
||||
bool HasByteSize;
|
||||
uint8_t ByteSize;
|
||||
};
|
||||
union {
|
||||
ByteSizeStorage ByteSize;
|
||||
int64_t Value;
|
||||
};
|
||||
|
||||
public:
|
||||
bool isImplicitConst() const {
|
||||
return Form == dwarf::DW_FORM_implicit_const;
|
||||
}
|
||||
|
||||
int64_t getImplicitConstValue() const {
|
||||
assert(isImplicitConst());
|
||||
return Value;
|
||||
}
|
||||
|
||||
/// Get the fixed byte size of this Form if possible. This function might
|
||||
/// use the DWARFUnit to calculate the size of the Form, like for
|
||||
/// DW_AT_address and DW_AT_ref_addr, so this isn't just an accessor for
|
||||
|
@ -63,13 +63,13 @@ DWARFAbbreviationDeclaration::extract(DataExtractor Data,
|
||||
auto A = static_cast<Attribute>(Data.getULEB128(OffsetPtr));
|
||||
auto F = static_cast<Form>(Data.getULEB128(OffsetPtr));
|
||||
if (A && F) {
|
||||
Optional<int64_t> V;
|
||||
bool IsImplicitConst = (F == DW_FORM_implicit_const);
|
||||
if (IsImplicitConst) {
|
||||
V = Data.getSLEB128(OffsetPtr);
|
||||
int64_t V = Data.getSLEB128(OffsetPtr);
|
||||
AttributeSpecs.push_back(AttributeSpec(A, F, V));
|
||||
continue;
|
||||
}
|
||||
Optional<uint8_t> ByteSize;
|
||||
// If this abbrevation still has a fixed byte size, then update the
|
||||
// FixedAttributeSize as needed.
|
||||
switch (F) {
|
||||
@ -96,11 +96,10 @@ DWARFAbbreviationDeclaration::extract(DataExtractor Data,
|
||||
default:
|
||||
// The form has a byte size that doesn't depend on Params.
|
||||
// If it's a fixed size, keep track of it.
|
||||
if (auto Size =
|
||||
DWARFFormValue::getFixedByteSize(F, DWARFFormParams())) {
|
||||
V = *Size;
|
||||
if ((ByteSize =
|
||||
DWARFFormValue::getFixedByteSize(F, DWARFFormParams()))) {
|
||||
if (FixedAttributeSize)
|
||||
FixedAttributeSize->NumBytes += *V;
|
||||
FixedAttributeSize->NumBytes += *ByteSize;
|
||||
break;
|
||||
}
|
||||
// Indicate we no longer have a fixed byte size for this
|
||||
@ -110,7 +109,7 @@ DWARFAbbreviationDeclaration::extract(DataExtractor Data,
|
||||
break;
|
||||
}
|
||||
// Record this attribute and its fixed size if it has one.
|
||||
AttributeSpecs.push_back(AttributeSpec(A, F, V));
|
||||
AttributeSpecs.push_back(AttributeSpec(A, F, ByteSize));
|
||||
} else if (A == 0 && F == 0) {
|
||||
// We successfully reached the end of this abbreviation declaration
|
||||
// since both attribute and form are zero.
|
||||
@ -149,7 +148,7 @@ void DWARFAbbreviationDeclaration::dump(raw_ostream &OS) const {
|
||||
else
|
||||
OS << format("DW_FORM_Unknown_%x", Spec.Form);
|
||||
if (Spec.isImplicitConst())
|
||||
OS << '\t' << *Spec.ByteSizeOrValue;
|
||||
OS << '\t' << Spec.getImplicitConstValue();
|
||||
OS << '\n';
|
||||
}
|
||||
OS << '\n';
|
||||
@ -182,7 +181,7 @@ Optional<DWARFFormValue> DWARFAbbreviationDeclaration::getAttributeValue(
|
||||
// We have arrived at the attribute to extract, extract if from Offset.
|
||||
DWARFFormValue FormValue(Spec.Form);
|
||||
if (Spec.isImplicitConst()) {
|
||||
FormValue.setSValue(*Spec.ByteSizeOrValue);
|
||||
FormValue.setSValue(Spec.getImplicitConstValue());
|
||||
return FormValue;
|
||||
}
|
||||
if (FormValue.extractValue(DebugInfoData, &Offset, &U))
|
||||
@ -215,8 +214,8 @@ Optional<int64_t> DWARFAbbreviationDeclaration::AttributeSpec::getByteSize(
|
||||
const DWARFUnit &U) const {
|
||||
if (isImplicitConst())
|
||||
return 0;
|
||||
if (ByteSizeOrValue)
|
||||
return ByteSizeOrValue;
|
||||
if (ByteSize.HasByteSize)
|
||||
return ByteSize.ByteSize;
|
||||
Optional<int64_t> S;
|
||||
auto FixedByteSize =
|
||||
DWARFFormValue::getFixedByteSize(Form, U.getFormParams());
|
||||
|
Loading…
Reference in New Issue
Block a user