Skip to content

Commit

Permalink
Refactor DWARF hashing to use a .def file to avoid repetition
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@303666 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
dwblaikie committed May 23, 2017
1 parent 9d05387 commit e495804
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 158 deletions.
116 changes: 9 additions & 107 deletions lib/CodeGen/AsmPrinter/DIEHash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,65 +116,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) {
#define COLLECT_ATTR(NAME) \
case dwarf::NAME: \
Attrs.NAME = V; \
break

for (const auto &V : Die.values()) {
DEBUG(dbgs() << "Attribute: "
<< dwarf::AttributeString(V.getAttribute())
<< " added.\n");
switch (V.getAttribute()) {
COLLECT_ATTR(DW_AT_name);
COLLECT_ATTR(DW_AT_accessibility);
COLLECT_ATTR(DW_AT_address_class);
COLLECT_ATTR(DW_AT_allocated);
COLLECT_ATTR(DW_AT_artificial);
COLLECT_ATTR(DW_AT_associated);
COLLECT_ATTR(DW_AT_binary_scale);
COLLECT_ATTR(DW_AT_bit_offset);
COLLECT_ATTR(DW_AT_bit_size);
COLLECT_ATTR(DW_AT_bit_stride);
COLLECT_ATTR(DW_AT_byte_size);
COLLECT_ATTR(DW_AT_byte_stride);
COLLECT_ATTR(DW_AT_const_expr);
COLLECT_ATTR(DW_AT_const_value);
COLLECT_ATTR(DW_AT_containing_type);
COLLECT_ATTR(DW_AT_count);
COLLECT_ATTR(DW_AT_data_bit_offset);
COLLECT_ATTR(DW_AT_data_location);
COLLECT_ATTR(DW_AT_data_member_location);
COLLECT_ATTR(DW_AT_decimal_scale);
COLLECT_ATTR(DW_AT_decimal_sign);
COLLECT_ATTR(DW_AT_default_value);
COLLECT_ATTR(DW_AT_digit_count);
COLLECT_ATTR(DW_AT_discr);
COLLECT_ATTR(DW_AT_discr_list);
COLLECT_ATTR(DW_AT_discr_value);
COLLECT_ATTR(DW_AT_encoding);
COLLECT_ATTR(DW_AT_enum_class);
COLLECT_ATTR(DW_AT_endianity);
COLLECT_ATTR(DW_AT_explicit);
COLLECT_ATTR(DW_AT_is_optional);
COLLECT_ATTR(DW_AT_location);
COLLECT_ATTR(DW_AT_lower_bound);
COLLECT_ATTR(DW_AT_mutable);
COLLECT_ATTR(DW_AT_ordering);
COLLECT_ATTR(DW_AT_picture_string);
COLLECT_ATTR(DW_AT_prototyped);
COLLECT_ATTR(DW_AT_small);
COLLECT_ATTR(DW_AT_segment);
COLLECT_ATTR(DW_AT_string_length);
COLLECT_ATTR(DW_AT_threads_scaled);
COLLECT_ATTR(DW_AT_upper_bound);
COLLECT_ATTR(DW_AT_use_location);
COLLECT_ATTR(DW_AT_use_UTF8);
COLLECT_ATTR(DW_AT_variable_parameter);
COLLECT_ATTR(DW_AT_virtuality);
COLLECT_ATTR(DW_AT_visibility);
COLLECT_ATTR(DW_AT_vtable_elem_location);
COLLECT_ATTR(DW_AT_type);
#define HANDLE_DIE_HASH_ATTR(NAME) \
case dwarf::NAME: \
Attrs.NAME = V; \
break;
#include "DIEHashAttributes.def"
default:
break;
}
Expand Down Expand Up @@ -366,62 +318,12 @@ void DIEHash::hashAttribute(const DIEValue &Value, dwarf::Tag Tag) {
// Go through the attributes from \param Attrs in the order specified in 7.27.4
// and hash them.
void DIEHash::hashAttributes(const DIEAttrs &Attrs, dwarf::Tag Tag) {
#define ADD_ATTR(ATTR) \
#define HANDLE_DIE_HASH_ATTR(NAME) \
{ \
if (ATTR) \
hashAttribute(ATTR, Tag); \
if (Attrs.NAME) \
hashAttribute(Attrs.NAME, Tag); \
}

ADD_ATTR(Attrs.DW_AT_name);
ADD_ATTR(Attrs.DW_AT_accessibility);
ADD_ATTR(Attrs.DW_AT_address_class);
ADD_ATTR(Attrs.DW_AT_allocated);
ADD_ATTR(Attrs.DW_AT_artificial);
ADD_ATTR(Attrs.DW_AT_associated);
ADD_ATTR(Attrs.DW_AT_binary_scale);
ADD_ATTR(Attrs.DW_AT_bit_offset);
ADD_ATTR(Attrs.DW_AT_bit_size);
ADD_ATTR(Attrs.DW_AT_bit_stride);
ADD_ATTR(Attrs.DW_AT_byte_size);
ADD_ATTR(Attrs.DW_AT_byte_stride);
ADD_ATTR(Attrs.DW_AT_const_expr);
ADD_ATTR(Attrs.DW_AT_const_value);
ADD_ATTR(Attrs.DW_AT_containing_type);
ADD_ATTR(Attrs.DW_AT_count);
ADD_ATTR(Attrs.DW_AT_data_bit_offset);
ADD_ATTR(Attrs.DW_AT_data_location);
ADD_ATTR(Attrs.DW_AT_data_member_location);
ADD_ATTR(Attrs.DW_AT_decimal_scale);
ADD_ATTR(Attrs.DW_AT_decimal_sign);
ADD_ATTR(Attrs.DW_AT_default_value);
ADD_ATTR(Attrs.DW_AT_digit_count);
ADD_ATTR(Attrs.DW_AT_discr);
ADD_ATTR(Attrs.DW_AT_discr_list);
ADD_ATTR(Attrs.DW_AT_discr_value);
ADD_ATTR(Attrs.DW_AT_encoding);
ADD_ATTR(Attrs.DW_AT_enum_class);
ADD_ATTR(Attrs.DW_AT_endianity);
ADD_ATTR(Attrs.DW_AT_explicit);
ADD_ATTR(Attrs.DW_AT_is_optional);
ADD_ATTR(Attrs.DW_AT_location);
ADD_ATTR(Attrs.DW_AT_lower_bound);
ADD_ATTR(Attrs.DW_AT_mutable);
ADD_ATTR(Attrs.DW_AT_ordering);
ADD_ATTR(Attrs.DW_AT_picture_string);
ADD_ATTR(Attrs.DW_AT_prototyped);
ADD_ATTR(Attrs.DW_AT_small);
ADD_ATTR(Attrs.DW_AT_segment);
ADD_ATTR(Attrs.DW_AT_string_length);
ADD_ATTR(Attrs.DW_AT_threads_scaled);
ADD_ATTR(Attrs.DW_AT_upper_bound);
ADD_ATTR(Attrs.DW_AT_use_location);
ADD_ATTR(Attrs.DW_AT_use_UTF8);
ADD_ATTR(Attrs.DW_AT_variable_parameter);
ADD_ATTR(Attrs.DW_AT_virtuality);
ADD_ATTR(Attrs.DW_AT_visibility);
ADD_ATTR(Attrs.DW_AT_vtable_elem_location);
ADD_ATTR(Attrs.DW_AT_type);

#include "DIEHashAttributes.def"
// FIXME: Add the extended attributes.
}

Expand Down
53 changes: 2 additions & 51 deletions lib/CodeGen/AsmPrinter/DIEHash.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,57 +28,8 @@ class CompileUnit;
class DIEHash {
// Collection of all attributes used in hashing a particular DIE.
struct DIEAttrs {
DIEValue DW_AT_name;
DIEValue DW_AT_accessibility;
DIEValue DW_AT_address_class;
DIEValue DW_AT_allocated;
DIEValue DW_AT_artificial;
DIEValue DW_AT_associated;
DIEValue DW_AT_binary_scale;
DIEValue DW_AT_bit_offset;
DIEValue DW_AT_bit_size;
DIEValue DW_AT_bit_stride;
DIEValue DW_AT_byte_size;
DIEValue DW_AT_byte_stride;
DIEValue DW_AT_const_expr;
DIEValue DW_AT_const_value;
DIEValue DW_AT_containing_type;
DIEValue DW_AT_count;
DIEValue DW_AT_data_bit_offset;
DIEValue DW_AT_data_location;
DIEValue DW_AT_data_member_location;
DIEValue DW_AT_decimal_scale;
DIEValue DW_AT_decimal_sign;
DIEValue DW_AT_default_value;
DIEValue DW_AT_digit_count;
DIEValue DW_AT_discr;
DIEValue DW_AT_discr_list;
DIEValue DW_AT_discr_value;
DIEValue DW_AT_encoding;
DIEValue DW_AT_enum_class;
DIEValue DW_AT_endianity;
DIEValue DW_AT_explicit;
DIEValue DW_AT_is_optional;
DIEValue DW_AT_location;
DIEValue DW_AT_lower_bound;
DIEValue DW_AT_mutable;
DIEValue DW_AT_ordering;
DIEValue DW_AT_picture_string;
DIEValue DW_AT_prototyped;
DIEValue DW_AT_small;
DIEValue DW_AT_segment;
DIEValue DW_AT_string_length;
DIEValue DW_AT_threads_scaled;
DIEValue DW_AT_upper_bound;
DIEValue DW_AT_use_location;
DIEValue DW_AT_use_UTF8;
DIEValue DW_AT_variable_parameter;
DIEValue DW_AT_virtuality;
DIEValue DW_AT_visibility;
DIEValue DW_AT_vtable_elem_location;
DIEValue DW_AT_type;

// Insert any additional ones here...
#define HANDLE_DIE_HASH_ATTR(NAME) DIEValue NAME;
#include "DIEHashAttributes.def"
};

public:
Expand Down
54 changes: 54 additions & 0 deletions lib/CodeGen/AsmPrinter/DIEHashAttributes.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#ifndef HANDLE_DIE_HASH_ATTR
#error "Missing macro definition of HANDLE_DIE_HASH_ATTR"
#endif

HANDLE_DIE_HASH_ATTR(DW_AT_accessibility)
HANDLE_DIE_HASH_ATTR(DW_AT_address_class)
HANDLE_DIE_HASH_ATTR(DW_AT_allocated)
HANDLE_DIE_HASH_ATTR(DW_AT_artificial)
HANDLE_DIE_HASH_ATTR(DW_AT_associated)
HANDLE_DIE_HASH_ATTR(DW_AT_binary_scale)
HANDLE_DIE_HASH_ATTR(DW_AT_bit_offset)
HANDLE_DIE_HASH_ATTR(DW_AT_bit_size)
HANDLE_DIE_HASH_ATTR(DW_AT_bit_stride)
HANDLE_DIE_HASH_ATTR(DW_AT_byte_size)
HANDLE_DIE_HASH_ATTR(DW_AT_byte_stride)
HANDLE_DIE_HASH_ATTR(DW_AT_const_expr)
HANDLE_DIE_HASH_ATTR(DW_AT_const_value)
HANDLE_DIE_HASH_ATTR(DW_AT_containing_type)
HANDLE_DIE_HASH_ATTR(DW_AT_count)
HANDLE_DIE_HASH_ATTR(DW_AT_data_bit_offset)
HANDLE_DIE_HASH_ATTR(DW_AT_data_location)
HANDLE_DIE_HASH_ATTR(DW_AT_data_member_location)
HANDLE_DIE_HASH_ATTR(DW_AT_decimal_scale)
HANDLE_DIE_HASH_ATTR(DW_AT_decimal_sign)
HANDLE_DIE_HASH_ATTR(DW_AT_default_value)
HANDLE_DIE_HASH_ATTR(DW_AT_digit_count)
HANDLE_DIE_HASH_ATTR(DW_AT_discr)
HANDLE_DIE_HASH_ATTR(DW_AT_discr_list)
HANDLE_DIE_HASH_ATTR(DW_AT_discr_value)
HANDLE_DIE_HASH_ATTR(DW_AT_encoding)
HANDLE_DIE_HASH_ATTR(DW_AT_enum_class)
HANDLE_DIE_HASH_ATTR(DW_AT_endianity)
HANDLE_DIE_HASH_ATTR(DW_AT_explicit)
HANDLE_DIE_HASH_ATTR(DW_AT_is_optional)
HANDLE_DIE_HASH_ATTR(DW_AT_location)
HANDLE_DIE_HASH_ATTR(DW_AT_lower_bound)
HANDLE_DIE_HASH_ATTR(DW_AT_mutable)
HANDLE_DIE_HASH_ATTR(DW_AT_ordering)
HANDLE_DIE_HASH_ATTR(DW_AT_picture_string)
HANDLE_DIE_HASH_ATTR(DW_AT_prototyped)
HANDLE_DIE_HASH_ATTR(DW_AT_small)
HANDLE_DIE_HASH_ATTR(DW_AT_segment)
HANDLE_DIE_HASH_ATTR(DW_AT_string_length)
HANDLE_DIE_HASH_ATTR(DW_AT_threads_scaled)
HANDLE_DIE_HASH_ATTR(DW_AT_upper_bound)
HANDLE_DIE_HASH_ATTR(DW_AT_use_location)
HANDLE_DIE_HASH_ATTR(DW_AT_use_UTF8)
HANDLE_DIE_HASH_ATTR(DW_AT_variable_parameter)
HANDLE_DIE_HASH_ATTR(DW_AT_virtuality)
HANDLE_DIE_HASH_ATTR(DW_AT_visibility)
HANDLE_DIE_HASH_ATTR(DW_AT_vtable_elem_location)
HANDLE_DIE_HASH_ATTR(DW_AT_type)

#undef HANDLE_DIE_HASH_ATTR

0 comments on commit e495804

Please sign in to comment.