1*9880d681SAndroid Build Coastguard Worker //===-- llvm/CodeGen/DIEHash.h - Dwarf Hashing Framework -------*- C++ -*--===// 2*9880d681SAndroid Build Coastguard Worker // 3*9880d681SAndroid Build Coastguard Worker // The LLVM Compiler Infrastructure 4*9880d681SAndroid Build Coastguard Worker // 5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source 6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details. 7*9880d681SAndroid Build Coastguard Worker // 8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 9*9880d681SAndroid Build Coastguard Worker // 10*9880d681SAndroid Build Coastguard Worker // This file contains support for DWARF4 hashing of DIEs. 11*9880d681SAndroid Build Coastguard Worker // 12*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 13*9880d681SAndroid Build Coastguard Worker 14*9880d681SAndroid Build Coastguard Worker #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DIEHASH_H 15*9880d681SAndroid Build Coastguard Worker #define LLVM_LIB_CODEGEN_ASMPRINTER_DIEHASH_H 16*9880d681SAndroid Build Coastguard Worker 17*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/DenseMap.h" 18*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/DIE.h" 19*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/MD5.h" 20*9880d681SAndroid Build Coastguard Worker 21*9880d681SAndroid Build Coastguard Worker namespace llvm { 22*9880d681SAndroid Build Coastguard Worker 23*9880d681SAndroid Build Coastguard Worker class AsmPrinter; 24*9880d681SAndroid Build Coastguard Worker class CompileUnit; 25*9880d681SAndroid Build Coastguard Worker 26*9880d681SAndroid Build Coastguard Worker /// \brief An object containing the capability of hashing and adding hash 27*9880d681SAndroid Build Coastguard Worker /// attributes onto a DIE. 28*9880d681SAndroid Build Coastguard Worker class DIEHash { 29*9880d681SAndroid Build Coastguard Worker // Collection of all attributes used in hashing a particular DIE. 30*9880d681SAndroid Build Coastguard Worker struct DIEAttrs { 31*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_name; 32*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_accessibility; 33*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_address_class; 34*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_allocated; 35*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_artificial; 36*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_associated; 37*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_binary_scale; 38*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_bit_offset; 39*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_bit_size; 40*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_bit_stride; 41*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_byte_size; 42*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_byte_stride; 43*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_const_expr; 44*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_const_value; 45*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_containing_type; 46*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_count; 47*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_data_bit_offset; 48*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_data_location; 49*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_data_member_location; 50*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_decimal_scale; 51*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_decimal_sign; 52*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_default_value; 53*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_digit_count; 54*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_discr; 55*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_discr_list; 56*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_discr_value; 57*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_encoding; 58*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_enum_class; 59*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_endianity; 60*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_explicit; 61*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_is_optional; 62*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_location; 63*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_lower_bound; 64*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_mutable; 65*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_ordering; 66*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_picture_string; 67*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_prototyped; 68*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_small; 69*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_segment; 70*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_string_length; 71*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_threads_scaled; 72*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_upper_bound; 73*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_use_location; 74*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_use_UTF8; 75*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_variable_parameter; 76*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_virtuality; 77*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_visibility; 78*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_vtable_elem_location; 79*9880d681SAndroid Build Coastguard Worker DIEValue DW_AT_type; 80*9880d681SAndroid Build Coastguard Worker 81*9880d681SAndroid Build Coastguard Worker // Insert any additional ones here... 82*9880d681SAndroid Build Coastguard Worker }; 83*9880d681SAndroid Build Coastguard Worker 84*9880d681SAndroid Build Coastguard Worker public: AP(A)85*9880d681SAndroid Build Coastguard Worker DIEHash(AsmPrinter *A = nullptr) : AP(A) {} 86*9880d681SAndroid Build Coastguard Worker 87*9880d681SAndroid Build Coastguard Worker /// \brief Computes the CU signature. 88*9880d681SAndroid Build Coastguard Worker uint64_t computeCUSignature(const DIE &Die); 89*9880d681SAndroid Build Coastguard Worker 90*9880d681SAndroid Build Coastguard Worker /// \brief Computes the type signature. 91*9880d681SAndroid Build Coastguard Worker uint64_t computeTypeSignature(const DIE &Die); 92*9880d681SAndroid Build Coastguard Worker 93*9880d681SAndroid Build Coastguard Worker // Helper routines to process parts of a DIE. 94*9880d681SAndroid Build Coastguard Worker private: 95*9880d681SAndroid Build Coastguard Worker /// \brief Adds the parent context of \param Die to the hash. 96*9880d681SAndroid Build Coastguard Worker void addParentContext(const DIE &Die); 97*9880d681SAndroid Build Coastguard Worker 98*9880d681SAndroid Build Coastguard Worker /// \brief Adds the attributes of \param Die to the hash. 99*9880d681SAndroid Build Coastguard Worker void addAttributes(const DIE &Die); 100*9880d681SAndroid Build Coastguard Worker 101*9880d681SAndroid Build Coastguard Worker /// \brief Computes the full DWARF4 7.27 hash of the DIE. 102*9880d681SAndroid Build Coastguard Worker void computeHash(const DIE &Die); 103*9880d681SAndroid Build Coastguard Worker 104*9880d681SAndroid Build Coastguard Worker // Routines that add DIEValues to the hash. 105*9880d681SAndroid Build Coastguard Worker public: 106*9880d681SAndroid Build Coastguard Worker /// \brief Adds \param Value to the hash. update(uint8_t Value)107*9880d681SAndroid Build Coastguard Worker void update(uint8_t Value) { Hash.update(Value); } 108*9880d681SAndroid Build Coastguard Worker 109*9880d681SAndroid Build Coastguard Worker /// \brief Encodes and adds \param Value to the hash as a ULEB128. 110*9880d681SAndroid Build Coastguard Worker void addULEB128(uint64_t Value); 111*9880d681SAndroid Build Coastguard Worker 112*9880d681SAndroid Build Coastguard Worker /// \brief Encodes and adds \param Value to the hash as a SLEB128. 113*9880d681SAndroid Build Coastguard Worker void addSLEB128(int64_t Value); 114*9880d681SAndroid Build Coastguard Worker 115*9880d681SAndroid Build Coastguard Worker private: 116*9880d681SAndroid Build Coastguard Worker /// \brief Adds \param Str to the hash and includes a NULL byte. 117*9880d681SAndroid Build Coastguard Worker void addString(StringRef Str); 118*9880d681SAndroid Build Coastguard Worker 119*9880d681SAndroid Build Coastguard Worker /// \brief Collects the attributes of DIE \param Die into the \param Attrs 120*9880d681SAndroid Build Coastguard Worker /// structure. 121*9880d681SAndroid Build Coastguard Worker void collectAttributes(const DIE &Die, DIEAttrs &Attrs); 122*9880d681SAndroid Build Coastguard Worker 123*9880d681SAndroid Build Coastguard Worker /// \brief Hashes the attributes in \param Attrs in order. 124*9880d681SAndroid Build Coastguard Worker void hashAttributes(const DIEAttrs &Attrs, dwarf::Tag Tag); 125*9880d681SAndroid Build Coastguard Worker 126*9880d681SAndroid Build Coastguard Worker /// \brief Hashes the data in a block like DIEValue, e.g. DW_FORM_block or 127*9880d681SAndroid Build Coastguard Worker /// DW_FORM_exprloc. 128*9880d681SAndroid Build Coastguard Worker void hashBlockData(const DIE::const_value_range &Values); 129*9880d681SAndroid Build Coastguard Worker 130*9880d681SAndroid Build Coastguard Worker /// \brief Hashes the contents pointed to in the .debug_loc section. 131*9880d681SAndroid Build Coastguard Worker void hashLocList(const DIELocList &LocList); 132*9880d681SAndroid Build Coastguard Worker 133*9880d681SAndroid Build Coastguard Worker /// \brief Hashes an individual attribute. 134*9880d681SAndroid Build Coastguard Worker void hashAttribute(const DIEValue &Value, dwarf::Tag Tag); 135*9880d681SAndroid Build Coastguard Worker 136*9880d681SAndroid Build Coastguard Worker /// \brief Hashes an attribute that refers to another DIE. 137*9880d681SAndroid Build Coastguard Worker void hashDIEEntry(dwarf::Attribute Attribute, dwarf::Tag Tag, 138*9880d681SAndroid Build Coastguard Worker const DIE &Entry); 139*9880d681SAndroid Build Coastguard Worker 140*9880d681SAndroid Build Coastguard Worker /// \brief Hashes a reference to a named type in such a way that is 141*9880d681SAndroid Build Coastguard Worker /// independent of whether that type is described by a declaration or a 142*9880d681SAndroid Build Coastguard Worker /// definition. 143*9880d681SAndroid Build Coastguard Worker void hashShallowTypeReference(dwarf::Attribute Attribute, const DIE &Entry, 144*9880d681SAndroid Build Coastguard Worker StringRef Name); 145*9880d681SAndroid Build Coastguard Worker 146*9880d681SAndroid Build Coastguard Worker /// \brief Hashes a reference to a previously referenced type DIE. 147*9880d681SAndroid Build Coastguard Worker void hashRepeatedTypeReference(dwarf::Attribute Attribute, 148*9880d681SAndroid Build Coastguard Worker unsigned DieNumber); 149*9880d681SAndroid Build Coastguard Worker 150*9880d681SAndroid Build Coastguard Worker void hashNestedType(const DIE &Die, StringRef Name); 151*9880d681SAndroid Build Coastguard Worker 152*9880d681SAndroid Build Coastguard Worker private: 153*9880d681SAndroid Build Coastguard Worker MD5 Hash; 154*9880d681SAndroid Build Coastguard Worker AsmPrinter *AP; 155*9880d681SAndroid Build Coastguard Worker DenseMap<const DIE *, unsigned> Numbering; 156*9880d681SAndroid Build Coastguard Worker }; 157*9880d681SAndroid Build Coastguard Worker } 158*9880d681SAndroid Build Coastguard Worker 159*9880d681SAndroid Build Coastguard Worker #endif 160