Eric Christopher | 0d27ca1 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 1 | //===-- llvm/CodeGen/DIEHash.h - Dwarf Hashing Framework -------*- C++ -*--===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file contains support for DWARF4 hashing of DIEs. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
David Blaikie | a9a8f0f | 2013-11-13 18:07:27 +0000 | [diff] [blame] | 14 | #include "DIE.h" |
David Blaikie | 3baa3c3 | 2013-10-21 18:59:40 +0000 | [diff] [blame] | 15 | #include "llvm/ADT/DenseMap.h" |
Eric Christopher | 0d27ca1 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 16 | #include "llvm/Support/MD5.h" |
| 17 | |
| 18 | namespace llvm { |
| 19 | |
| 20 | class CompileUnit; |
| 21 | |
| 22 | /// \brief An object containing the capability of hashing and adding hash |
| 23 | /// attributes onto a DIE. |
Benjamin Kramer | 55c06ae | 2013-09-11 18:05:11 +0000 | [diff] [blame] | 24 | class DIEHash { |
Eric Christopher | 0710bfa | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 25 | // The entry for a particular attribute. |
| 26 | struct AttrEntry { |
| 27 | const DIEValue *Val; |
| 28 | const DIEAbbrevData *Desc; |
| 29 | }; |
| 30 | |
| 31 | // Collection of all attributes used in hashing a particular DIE. |
| 32 | struct DIEAttrs { |
| 33 | AttrEntry DW_AT_name; |
Eric Christopher | bd18c8d | 2013-09-03 20:00:20 +0000 | [diff] [blame] | 34 | AttrEntry DW_AT_accessibility; |
| 35 | AttrEntry DW_AT_address_class; |
| 36 | AttrEntry DW_AT_allocated; |
| 37 | AttrEntry DW_AT_artificial; |
| 38 | AttrEntry DW_AT_associated; |
| 39 | AttrEntry DW_AT_binary_scale; |
| 40 | AttrEntry DW_AT_bit_offset; |
| 41 | AttrEntry DW_AT_bit_size; |
| 42 | AttrEntry DW_AT_bit_stride; |
| 43 | AttrEntry DW_AT_byte_size; |
| 44 | AttrEntry DW_AT_byte_stride; |
| 45 | AttrEntry DW_AT_const_expr; |
| 46 | AttrEntry DW_AT_const_value; |
| 47 | AttrEntry DW_AT_containing_type; |
| 48 | AttrEntry DW_AT_count; |
| 49 | AttrEntry DW_AT_data_bit_offset; |
| 50 | AttrEntry DW_AT_data_location; |
| 51 | AttrEntry DW_AT_data_member_location; |
| 52 | AttrEntry DW_AT_decimal_scale; |
| 53 | AttrEntry DW_AT_decimal_sign; |
| 54 | AttrEntry DW_AT_default_value; |
| 55 | AttrEntry DW_AT_digit_count; |
| 56 | AttrEntry DW_AT_discr; |
| 57 | AttrEntry DW_AT_discr_list; |
| 58 | AttrEntry DW_AT_discr_value; |
| 59 | AttrEntry DW_AT_encoding; |
| 60 | AttrEntry DW_AT_enum_class; |
| 61 | AttrEntry DW_AT_endianity; |
| 62 | AttrEntry DW_AT_explicit; |
| 63 | AttrEntry DW_AT_is_optional; |
| 64 | AttrEntry DW_AT_location; |
| 65 | AttrEntry DW_AT_lower_bound; |
| 66 | AttrEntry DW_AT_mutable; |
| 67 | AttrEntry DW_AT_ordering; |
| 68 | AttrEntry DW_AT_picture_string; |
| 69 | AttrEntry DW_AT_prototyped; |
| 70 | AttrEntry DW_AT_small; |
| 71 | AttrEntry DW_AT_segment; |
| 72 | AttrEntry DW_AT_string_length; |
| 73 | AttrEntry DW_AT_threads_scaled; |
| 74 | AttrEntry DW_AT_upper_bound; |
| 75 | AttrEntry DW_AT_use_location; |
| 76 | AttrEntry DW_AT_use_UTF8; |
| 77 | AttrEntry DW_AT_variable_parameter; |
| 78 | AttrEntry DW_AT_virtuality; |
| 79 | AttrEntry DW_AT_visibility; |
| 80 | AttrEntry DW_AT_vtable_elem_location; |
David Blaikie | 47f66d5 | 2013-10-17 22:07:09 +0000 | [diff] [blame] | 81 | AttrEntry DW_AT_type; |
Eric Christopher | bd18c8d | 2013-09-03 20:00:20 +0000 | [diff] [blame] | 82 | |
| 83 | // Insert any additional ones here... |
Eric Christopher | 0710bfa | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 84 | }; |
| 85 | |
Eric Christopher | 0d27ca1 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 86 | public: |
Eric Christopher | 41627cf | 2013-09-03 21:57:50 +0000 | [diff] [blame] | 87 | /// \brief Computes the ODR signature. |
David Blaikie | 377e832 | 2013-10-24 18:29:03 +0000 | [diff] [blame] | 88 | uint64_t computeDIEODRSignature(const DIE &Die); |
Eric Christopher | 0d27ca1 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 89 | |
Eric Christopher | 41627cf | 2013-09-03 21:57:50 +0000 | [diff] [blame] | 90 | /// \brief Computes the CU signature. |
David Blaikie | 377e832 | 2013-10-24 18:29:03 +0000 | [diff] [blame] | 91 | uint64_t computeCUSignature(const DIE &Die); |
Eric Christopher | 0710bfa | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 92 | |
Eric Christopher | 800a876 | 2013-09-03 21:57:57 +0000 | [diff] [blame] | 93 | /// \brief Computes the type signature. |
David Blaikie | 377e832 | 2013-10-24 18:29:03 +0000 | [diff] [blame] | 94 | uint64_t computeTypeSignature(const DIE &Die); |
Eric Christopher | 800a876 | 2013-09-03 21:57:57 +0000 | [diff] [blame] | 95 | |
Eric Christopher | 0d27ca1 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 96 | // Helper routines to process parts of a DIE. |
Eric Christopher | 0710bfa | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 97 | private: |
Eric Christopher | 0d27ca1 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 98 | /// \brief Adds the parent context of \param Die to the hash. |
David Blaikie | 377e832 | 2013-10-24 18:29:03 +0000 | [diff] [blame] | 99 | void addParentContext(const DIE &Die); |
Eric Christopher | 0710bfa | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 100 | |
| 101 | /// \brief Adds the attributes of \param Die to the hash. |
David Blaikie | 377e832 | 2013-10-24 18:29:03 +0000 | [diff] [blame] | 102 | void addAttributes(const DIE &Die); |
Eric Christopher | 0710bfa | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 103 | |
| 104 | /// \brief Computes the full DWARF4 7.27 hash of the DIE. |
David Blaikie | 377e832 | 2013-10-24 18:29:03 +0000 | [diff] [blame] | 105 | void computeHash(const DIE &Die); |
Eric Christopher | 0710bfa | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 106 | |
Eric Christopher | 0d27ca1 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 107 | // Routines that add DIEValues to the hash. |
| 108 | private: |
| 109 | /// \brief Encodes and adds \param Value to the hash as a ULEB128. |
| 110 | void addULEB128(uint64_t Value); |
| 111 | |
David Blaikie | c098708 | 2013-10-16 23:36:20 +0000 | [diff] [blame] | 112 | /// \brief Encodes and adds \param Value to the hash as a SLEB128. |
| 113 | void addSLEB128(int64_t Value); |
| 114 | |
Eric Christopher | 0d27ca1 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 115 | /// \brief Adds \param Str to the hash and includes a NULL byte. |
| 116 | void addString(StringRef Str); |
Eric Christopher | 0710bfa | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 117 | |
| 118 | /// \brief Collects the attributes of DIE \param Die into the \param Attrs |
| 119 | /// structure. |
David Blaikie | 377e832 | 2013-10-24 18:29:03 +0000 | [diff] [blame] | 120 | void collectAttributes(const DIE &Die, DIEAttrs &Attrs); |
Eric Christopher | 0710bfa | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 121 | |
| 122 | /// \brief Hashes the attributes in \param Attrs in order. |
David Blaikie | f1545a2 | 2013-10-21 22:36:50 +0000 | [diff] [blame] | 123 | void hashAttributes(const DIEAttrs &Attrs, dwarf::Tag Tag); |
Eric Christopher | 0710bfa | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 124 | |
| 125 | /// \brief Hashes an individual attribute. |
David Blaikie | f1545a2 | 2013-10-21 22:36:50 +0000 | [diff] [blame] | 126 | void hashAttribute(AttrEntry Attr, dwarf::Tag Tag); |
Eric Christopher | 0710bfa | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 127 | |
David Blaikie | 851aa94 | 2013-10-24 17:51:43 +0000 | [diff] [blame] | 128 | /// \brief Hashes an attribute that refers to another DIE. |
| 129 | void hashDIEEntry(dwarf::Attribute Attribute, dwarf::Tag Tag, |
David Blaikie | 377e832 | 2013-10-24 18:29:03 +0000 | [diff] [blame] | 130 | const DIE &Entry); |
David Blaikie | 851aa94 | 2013-10-24 17:51:43 +0000 | [diff] [blame] | 131 | |
| 132 | /// \brief Hashes a reference to a named type in such a way that is |
| 133 | /// independent of whether that type is described by a declaration or a |
| 134 | /// definition. |
David Blaikie | 377e832 | 2013-10-24 18:29:03 +0000 | [diff] [blame] | 135 | void hashShallowTypeReference(dwarf::Attribute Attribute, const DIE &Entry, |
| 136 | StringRef Name); |
David Blaikie | 851aa94 | 2013-10-24 17:51:43 +0000 | [diff] [blame] | 137 | |
| 138 | /// \brief Hashes a reference to a previously referenced type DIE. |
| 139 | void hashRepeatedTypeReference(dwarf::Attribute Attribute, unsigned DieNumber); |
| 140 | |
David Blaikie | a954618 | 2013-10-25 18:38:43 +0000 | [diff] [blame] | 141 | void hashNestedType(const DIE &Die, StringRef Name); |
| 142 | |
Eric Christopher | 0d27ca1 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 143 | private: |
| 144 | MD5 Hash; |
David Blaikie | 377e832 | 2013-10-24 18:29:03 +0000 | [diff] [blame] | 145 | DenseMap<const DIE *, unsigned> Numbering; |
Eric Christopher | 0d27ca1 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 146 | }; |
| 147 | } |