Eric Christopher | 4573198 | 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 | |
Benjamin Kramer | a7c40ef | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 14 | #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DIEHASH_H |
| 15 | #define LLVM_LIB_CODEGEN_ASMPRINTER_DIEHASH_H |
Eric Christopher | 5c38b65 | 2014-03-07 22:40:30 +0000 | [diff] [blame] | 16 | |
David Blaikie | 980d499 | 2013-10-21 18:59:40 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/DenseMap.h" |
Chandler Carruth | d990388 | 2015-01-14 11:23:27 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/DIE.h" |
Eric Christopher | 4573198 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 19 | #include "llvm/Support/MD5.h" |
| 20 | |
| 21 | namespace llvm { |
| 22 | |
Eric Christopher | 420569b | 2014-02-20 02:50:45 +0000 | [diff] [blame] | 23 | class AsmPrinter; |
Eric Christopher | 4573198 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 24 | class CompileUnit; |
| 25 | |
| 26 | /// \brief An object containing the capability of hashing and adding hash |
| 27 | /// attributes onto a DIE. |
Benjamin Kramer | 079b96e | 2013-09-11 18:05:11 +0000 | [diff] [blame] | 28 | class DIEHash { |
Eric Christopher | d29614f | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 29 | // Collection of all attributes used in hashing a particular DIE. |
| 30 | struct DIEAttrs { |
Duncan P. N. Exon Smith | f3a6a67 | 2015-05-27 22:36:37 +0000 | [diff] [blame] | 31 | DIEValue DW_AT_name; |
| 32 | DIEValue DW_AT_accessibility; |
| 33 | DIEValue DW_AT_address_class; |
| 34 | DIEValue DW_AT_allocated; |
| 35 | DIEValue DW_AT_artificial; |
| 36 | DIEValue DW_AT_associated; |
| 37 | DIEValue DW_AT_binary_scale; |
| 38 | DIEValue DW_AT_bit_offset; |
| 39 | DIEValue DW_AT_bit_size; |
| 40 | DIEValue DW_AT_bit_stride; |
| 41 | DIEValue DW_AT_byte_size; |
| 42 | DIEValue DW_AT_byte_stride; |
| 43 | DIEValue DW_AT_const_expr; |
| 44 | DIEValue DW_AT_const_value; |
| 45 | DIEValue DW_AT_containing_type; |
| 46 | DIEValue DW_AT_count; |
| 47 | DIEValue DW_AT_data_bit_offset; |
| 48 | DIEValue DW_AT_data_location; |
| 49 | DIEValue DW_AT_data_member_location; |
| 50 | DIEValue DW_AT_decimal_scale; |
| 51 | DIEValue DW_AT_decimal_sign; |
| 52 | DIEValue DW_AT_default_value; |
| 53 | DIEValue DW_AT_digit_count; |
| 54 | DIEValue DW_AT_discr; |
| 55 | DIEValue DW_AT_discr_list; |
| 56 | DIEValue DW_AT_discr_value; |
| 57 | DIEValue DW_AT_encoding; |
| 58 | DIEValue DW_AT_enum_class; |
| 59 | DIEValue DW_AT_endianity; |
| 60 | DIEValue DW_AT_explicit; |
| 61 | DIEValue DW_AT_is_optional; |
| 62 | DIEValue DW_AT_location; |
| 63 | DIEValue DW_AT_lower_bound; |
| 64 | DIEValue DW_AT_mutable; |
| 65 | DIEValue DW_AT_ordering; |
| 66 | DIEValue DW_AT_picture_string; |
| 67 | DIEValue DW_AT_prototyped; |
| 68 | DIEValue DW_AT_small; |
| 69 | DIEValue DW_AT_segment; |
| 70 | DIEValue DW_AT_string_length; |
| 71 | DIEValue DW_AT_threads_scaled; |
| 72 | DIEValue DW_AT_upper_bound; |
| 73 | DIEValue DW_AT_use_location; |
| 74 | DIEValue DW_AT_use_UTF8; |
| 75 | DIEValue DW_AT_variable_parameter; |
| 76 | DIEValue DW_AT_virtuality; |
| 77 | DIEValue DW_AT_visibility; |
| 78 | DIEValue DW_AT_vtable_elem_location; |
| 79 | DIEValue DW_AT_type; |
Eric Christopher | e020fa7 | 2013-09-03 20:00:20 +0000 | [diff] [blame] | 80 | |
| 81 | // Insert any additional ones here... |
Eric Christopher | d29614f | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 82 | }; |
| 83 | |
Eric Christopher | 4573198 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 84 | public: |
Craig Topper | 353eda4 | 2014-04-24 06:44:33 +0000 | [diff] [blame] | 85 | DIEHash(AsmPrinter *A = nullptr) : AP(A) {} |
Eric Christopher | 420569b | 2014-02-20 02:50:45 +0000 | [diff] [blame] | 86 | |
Eric Christopher | b86e2ad | 2013-09-03 21:57:50 +0000 | [diff] [blame] | 87 | /// \brief Computes the ODR signature. |
David Blaikie | 2aee7be | 2013-10-24 18:29:03 +0000 | [diff] [blame] | 88 | uint64_t computeDIEODRSignature(const DIE &Die); |
Eric Christopher | 4573198 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 89 | |
Eric Christopher | b86e2ad | 2013-09-03 21:57:50 +0000 | [diff] [blame] | 90 | /// \brief Computes the CU signature. |
David Blaikie | 2aee7be | 2013-10-24 18:29:03 +0000 | [diff] [blame] | 91 | uint64_t computeCUSignature(const DIE &Die); |
Eric Christopher | d29614f | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 92 | |
Eric Christopher | 25b7adc | 2013-09-03 21:57:57 +0000 | [diff] [blame] | 93 | /// \brief Computes the type signature. |
David Blaikie | 2aee7be | 2013-10-24 18:29:03 +0000 | [diff] [blame] | 94 | uint64_t computeTypeSignature(const DIE &Die); |
Eric Christopher | 25b7adc | 2013-09-03 21:57:57 +0000 | [diff] [blame] | 95 | |
Eric Christopher | 4573198 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 96 | // Helper routines to process parts of a DIE. |
Eric Christopher | d29614f | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 97 | private: |
Eric Christopher | 4573198 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 98 | /// \brief Adds the parent context of \param Die to the hash. |
David Blaikie | 2aee7be | 2013-10-24 18:29:03 +0000 | [diff] [blame] | 99 | void addParentContext(const DIE &Die); |
Eric Christopher | d29614f | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 100 | |
| 101 | /// \brief Adds the attributes of \param Die to the hash. |
David Blaikie | 2aee7be | 2013-10-24 18:29:03 +0000 | [diff] [blame] | 102 | void addAttributes(const DIE &Die); |
Eric Christopher | d29614f | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 103 | |
| 104 | /// \brief Computes the full DWARF4 7.27 hash of the DIE. |
David Blaikie | 2aee7be | 2013-10-24 18:29:03 +0000 | [diff] [blame] | 105 | void computeHash(const DIE &Die); |
Eric Christopher | d29614f | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 106 | |
Eric Christopher | 4573198 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 107 | // Routines that add DIEValues to the hash. |
Eric Christopher | 5c38b65 | 2014-03-07 22:40:30 +0000 | [diff] [blame] | 108 | public: |
| 109 | /// \brief Adds \param Value to the hash. |
| 110 | void update(uint8_t Value) { Hash.update(Value); } |
| 111 | |
Eric Christopher | 4573198 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 112 | /// \brief Encodes and adds \param Value to the hash as a ULEB128. |
| 113 | void addULEB128(uint64_t Value); |
| 114 | |
David Blaikie | 6316ca4 | 2013-10-16 23:36:20 +0000 | [diff] [blame] | 115 | /// \brief Encodes and adds \param Value to the hash as a SLEB128. |
| 116 | void addSLEB128(int64_t Value); |
| 117 | |
Eric Christopher | 5c38b65 | 2014-03-07 22:40:30 +0000 | [diff] [blame] | 118 | private: |
Eric Christopher | 4573198 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 119 | /// \brief Adds \param Str to the hash and includes a NULL byte. |
| 120 | void addString(StringRef Str); |
Eric Christopher | d29614f | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 121 | |
| 122 | /// \brief Collects the attributes of DIE \param Die into the \param Attrs |
| 123 | /// structure. |
David Blaikie | 2aee7be | 2013-10-24 18:29:03 +0000 | [diff] [blame] | 124 | void collectAttributes(const DIE &Die, DIEAttrs &Attrs); |
Eric Christopher | d29614f | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 125 | |
| 126 | /// \brief Hashes the attributes in \param Attrs in order. |
David Blaikie | 6cf58c8 | 2013-10-21 22:36:50 +0000 | [diff] [blame] | 127 | void hashAttributes(const DIEAttrs &Attrs, dwarf::Tag Tag); |
Eric Christopher | d29614f | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 128 | |
Eric Christopher | 420569b | 2014-02-20 02:50:45 +0000 | [diff] [blame] | 129 | /// \brief Hashes the data in a block like DIEValue, e.g. DW_FORM_block or |
| 130 | /// DW_FORM_exprloc. |
Duncan P. N. Exon Smith | 4fb1f9c | 2015-06-25 23:46:41 +0000 | [diff] [blame] | 131 | void hashBlockData(const DIE::const_value_range &Values); |
Eric Christopher | 420569b | 2014-02-20 02:50:45 +0000 | [diff] [blame] | 132 | |
Eric Christopher | 4f17ee0 | 2014-03-08 00:29:41 +0000 | [diff] [blame] | 133 | /// \brief Hashes the contents pointed to in the .debug_loc section. |
| 134 | void hashLocList(const DIELocList &LocList); |
| 135 | |
Eric Christopher | d29614f | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 136 | /// \brief Hashes an individual attribute. |
Duncan P. N. Exon Smith | f3a6a67 | 2015-05-27 22:36:37 +0000 | [diff] [blame] | 137 | void hashAttribute(DIEValue Value, dwarf::Tag Tag); |
Eric Christopher | d29614f | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 138 | |
David Blaikie | afcb965 | 2013-10-24 17:51:43 +0000 | [diff] [blame] | 139 | /// \brief Hashes an attribute that refers to another DIE. |
| 140 | void hashDIEEntry(dwarf::Attribute Attribute, dwarf::Tag Tag, |
David Blaikie | 2aee7be | 2013-10-24 18:29:03 +0000 | [diff] [blame] | 141 | const DIE &Entry); |
David Blaikie | afcb965 | 2013-10-24 17:51:43 +0000 | [diff] [blame] | 142 | |
| 143 | /// \brief Hashes a reference to a named type in such a way that is |
| 144 | /// independent of whether that type is described by a declaration or a |
| 145 | /// definition. |
David Blaikie | 2aee7be | 2013-10-24 18:29:03 +0000 | [diff] [blame] | 146 | void hashShallowTypeReference(dwarf::Attribute Attribute, const DIE &Entry, |
| 147 | StringRef Name); |
David Blaikie | afcb965 | 2013-10-24 17:51:43 +0000 | [diff] [blame] | 148 | |
| 149 | /// \brief Hashes a reference to a previously referenced type DIE. |
Eric Christopher | a07e4f5 | 2013-11-19 09:28:34 +0000 | [diff] [blame] | 150 | void hashRepeatedTypeReference(dwarf::Attribute Attribute, |
| 151 | unsigned DieNumber); |
David Blaikie | afcb965 | 2013-10-24 17:51:43 +0000 | [diff] [blame] | 152 | |
David Blaikie | 65cc969 | 2013-10-25 18:38:43 +0000 | [diff] [blame] | 153 | void hashNestedType(const DIE &Die, StringRef Name); |
| 154 | |
Eric Christopher | 4573198 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 155 | private: |
| 156 | MD5 Hash; |
Eric Christopher | 420569b | 2014-02-20 02:50:45 +0000 | [diff] [blame] | 157 | AsmPrinter *AP; |
David Blaikie | 2aee7be | 2013-10-24 18:29:03 +0000 | [diff] [blame] | 158 | DenseMap<const DIE *, unsigned> Numbering; |
Eric Christopher | 4573198 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 159 | }; |
Alexander Kornienko | f00654e | 2015-06-23 09:49:53 +0000 | [diff] [blame] | 160 | } |
Eric Christopher | 5c38b65 | 2014-03-07 22:40:30 +0000 | [diff] [blame] | 161 | |
| 162 | #endif |