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 | |
| 14 | #include "llvm/Support/MD5.h" |
| 15 | |
| 16 | namespace llvm { |
| 17 | |
| 18 | class CompileUnit; |
| 19 | |
| 20 | /// \brief An object containing the capability of hashing and adding hash |
| 21 | /// attributes onto a DIE. |
Benjamin Kramer | 55c06ae | 2013-09-11 18:05:11 +0000 | [diff] [blame] | 22 | class DIEHash { |
Eric Christopher | 0710bfa | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 23 | // The entry for a particular attribute. |
| 24 | struct AttrEntry { |
| 25 | const DIEValue *Val; |
| 26 | const DIEAbbrevData *Desc; |
| 27 | }; |
| 28 | |
| 29 | // Collection of all attributes used in hashing a particular DIE. |
| 30 | struct DIEAttrs { |
| 31 | AttrEntry DW_AT_name; |
Eric Christopher | bd18c8d | 2013-09-03 20:00:20 +0000 | [diff] [blame] | 32 | AttrEntry DW_AT_accessibility; |
| 33 | AttrEntry DW_AT_address_class; |
| 34 | AttrEntry DW_AT_allocated; |
| 35 | AttrEntry DW_AT_artificial; |
| 36 | AttrEntry DW_AT_associated; |
| 37 | AttrEntry DW_AT_binary_scale; |
| 38 | AttrEntry DW_AT_bit_offset; |
| 39 | AttrEntry DW_AT_bit_size; |
| 40 | AttrEntry DW_AT_bit_stride; |
| 41 | AttrEntry DW_AT_byte_size; |
| 42 | AttrEntry DW_AT_byte_stride; |
| 43 | AttrEntry DW_AT_const_expr; |
| 44 | AttrEntry DW_AT_const_value; |
| 45 | AttrEntry DW_AT_containing_type; |
| 46 | AttrEntry DW_AT_count; |
| 47 | AttrEntry DW_AT_data_bit_offset; |
| 48 | AttrEntry DW_AT_data_location; |
| 49 | AttrEntry DW_AT_data_member_location; |
| 50 | AttrEntry DW_AT_decimal_scale; |
| 51 | AttrEntry DW_AT_decimal_sign; |
| 52 | AttrEntry DW_AT_default_value; |
| 53 | AttrEntry DW_AT_digit_count; |
| 54 | AttrEntry DW_AT_discr; |
| 55 | AttrEntry DW_AT_discr_list; |
| 56 | AttrEntry DW_AT_discr_value; |
| 57 | AttrEntry DW_AT_encoding; |
| 58 | AttrEntry DW_AT_enum_class; |
| 59 | AttrEntry DW_AT_endianity; |
| 60 | AttrEntry DW_AT_explicit; |
| 61 | AttrEntry DW_AT_is_optional; |
| 62 | AttrEntry DW_AT_location; |
| 63 | AttrEntry DW_AT_lower_bound; |
| 64 | AttrEntry DW_AT_mutable; |
| 65 | AttrEntry DW_AT_ordering; |
| 66 | AttrEntry DW_AT_picture_string; |
| 67 | AttrEntry DW_AT_prototyped; |
| 68 | AttrEntry DW_AT_small; |
| 69 | AttrEntry DW_AT_segment; |
| 70 | AttrEntry DW_AT_string_length; |
| 71 | AttrEntry DW_AT_threads_scaled; |
| 72 | AttrEntry DW_AT_upper_bound; |
| 73 | AttrEntry DW_AT_use_location; |
| 74 | AttrEntry DW_AT_use_UTF8; |
| 75 | AttrEntry DW_AT_variable_parameter; |
| 76 | AttrEntry DW_AT_virtuality; |
| 77 | AttrEntry DW_AT_visibility; |
| 78 | AttrEntry DW_AT_vtable_elem_location; |
| 79 | |
| 80 | // Insert any additional ones here... |
Eric Christopher | 0710bfa | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 81 | }; |
| 82 | |
Eric Christopher | 0d27ca1 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 83 | public: |
Eric Christopher | 41627cf | 2013-09-03 21:57:50 +0000 | [diff] [blame] | 84 | /// \brief Computes the ODR signature. |
Eric Christopher | 0d27ca1 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 85 | uint64_t computeDIEODRSignature(DIE *Die); |
| 86 | |
Eric Christopher | 41627cf | 2013-09-03 21:57:50 +0000 | [diff] [blame] | 87 | /// \brief Computes the CU signature. |
Eric Christopher | 0710bfa | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 88 | uint64_t computeCUSignature(DIE *Die); |
| 89 | |
Eric Christopher | 800a876 | 2013-09-03 21:57:57 +0000 | [diff] [blame] | 90 | /// \brief Computes the type signature. |
| 91 | uint64_t computeTypeSignature(DIE *Die); |
| 92 | |
Eric Christopher | 0d27ca1 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 93 | // Helper routines to process parts of a DIE. |
Eric Christopher | 0710bfa | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 94 | private: |
Eric Christopher | 0d27ca1 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 95 | /// \brief Adds the parent context of \param Die to the hash. |
| 96 | void addParentContext(DIE *Die); |
Eric Christopher | 0710bfa | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 97 | |
| 98 | /// \brief Adds the attributes of \param Die to the hash. |
| 99 | void addAttributes(DIE *Die); |
| 100 | |
| 101 | /// \brief Computes the full DWARF4 7.27 hash of the DIE. |
| 102 | void computeHash(DIE *Die); |
| 103 | |
Eric Christopher | 0d27ca1 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 104 | // Routines that add DIEValues to the hash. |
| 105 | private: |
| 106 | /// \brief Encodes and adds \param Value to the hash as a ULEB128. |
| 107 | void addULEB128(uint64_t Value); |
| 108 | |
David Blaikie | c098708 | 2013-10-16 23:36:20 +0000 | [diff] [blame] | 109 | /// \brief Encodes and adds \param Value to the hash as a SLEB128. |
| 110 | void addSLEB128(int64_t Value); |
| 111 | |
Eric Christopher | 0d27ca1 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 112 | /// \brief Adds \param Str to the hash and includes a NULL byte. |
| 113 | void addString(StringRef Str); |
Eric Christopher | 0710bfa | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 114 | |
| 115 | /// \brief Collects the attributes of DIE \param Die into the \param Attrs |
| 116 | /// structure. |
David Blaikie | cbb5c73 | 2013-08-14 22:23:05 +0000 | [diff] [blame] | 117 | void collectAttributes(DIE *Die, DIEAttrs &Attrs); |
Eric Christopher | 0710bfa | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 118 | |
| 119 | /// \brief Hashes the attributes in \param Attrs in order. |
David Blaikie | cbb5c73 | 2013-08-14 22:23:05 +0000 | [diff] [blame] | 120 | void hashAttributes(const DIEAttrs &Attrs); |
Eric Christopher | 0710bfa | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 121 | |
| 122 | /// \brief Hashes an individual attribute. |
| 123 | void hashAttribute(AttrEntry Attr); |
| 124 | |
Eric Christopher | 0d27ca1 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 125 | private: |
| 126 | MD5 Hash; |
| 127 | }; |
| 128 | } |