DIEHash.h revision 303975
1139825Simp//===-- llvm/CodeGen/DIEHash.h - Dwarf Hashing Framework -------*- C++ -*--===//
2148078Srwatson//
3148078Srwatson//                     The LLVM Compiler Infrastructure
4148078Srwatson//
592654Sjeff// This file is distributed under the University of Illinois Open Source
692654Sjeff// License. See LICENSE.TXT for details.
792654Sjeff//
892654Sjeff//===----------------------------------------------------------------------===//
992654Sjeff//
1092654Sjeff// This file contains support for DWARF4 hashing of DIEs.
1192654Sjeff//
1292654Sjeff//===----------------------------------------------------------------------===//
1392654Sjeff
1492654Sjeff#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DIEHASH_H
1592654Sjeff#define LLVM_LIB_CODEGEN_ASMPRINTER_DIEHASH_H
1692654Sjeff
1792654Sjeff#include "llvm/ADT/DenseMap.h"
1892654Sjeff#include "llvm/CodeGen/DIE.h"
1992654Sjeff#include "llvm/Support/MD5.h"
2092654Sjeff
2192654Sjeffnamespace llvm {
2292654Sjeff
2392654Sjeffclass AsmPrinter;
2492654Sjeffclass CompileUnit;
2592654Sjeff
2692654Sjeff/// \brief An object containing the capability of hashing and adding hash
2792654Sjeff/// attributes onto a DIE.
2892654Sjeffclass DIEHash {
2992654Sjeff  // Collection of all attributes used in hashing a particular DIE.
3092654Sjeff  struct DIEAttrs {
3192654Sjeff    DIEValue DW_AT_name;
3292654Sjeff    DIEValue DW_AT_accessibility;
3392654Sjeff    DIEValue DW_AT_address_class;
3492654Sjeff    DIEValue DW_AT_allocated;
3592654Sjeff    DIEValue DW_AT_artificial;
3692654Sjeff    DIEValue DW_AT_associated;
3792654Sjeff    DIEValue DW_AT_binary_scale;
3892654Sjeff    DIEValue DW_AT_bit_offset;
3992654Sjeff    DIEValue DW_AT_bit_size;
4092654Sjeff    DIEValue DW_AT_bit_stride;
4192654Sjeff    DIEValue DW_AT_byte_size;
42184546Skeramida    DIEValue DW_AT_byte_stride;
4392654Sjeff    DIEValue DW_AT_const_expr;
4492654Sjeff    DIEValue DW_AT_const_value;
4592654Sjeff    DIEValue DW_AT_containing_type;
4692654Sjeff    DIEValue DW_AT_count;
47129906Sbmilekic    DIEValue DW_AT_data_bit_offset;
4892654Sjeff    DIEValue DW_AT_data_location;
4992654Sjeff    DIEValue DW_AT_data_member_location;
5092654Sjeff    DIEValue DW_AT_decimal_scale;
51166213Smohans    DIEValue DW_AT_decimal_sign;
52166213Smohans    DIEValue DW_AT_default_value;
5392654Sjeff    DIEValue DW_AT_digit_count;
5492654Sjeff    DIEValue DW_AT_discr;
5592654Sjeff    DIEValue DW_AT_discr_list;
5692654Sjeff    DIEValue DW_AT_discr_value;
5792654Sjeff    DIEValue DW_AT_encoding;
5892654Sjeff    DIEValue DW_AT_enum_class;
5992654Sjeff    DIEValue DW_AT_endianity;
60132987Sgreen    DIEValue DW_AT_explicit;
6192654Sjeff    DIEValue DW_AT_is_optional;
6292654Sjeff    DIEValue DW_AT_location;
63132987Sgreen    DIEValue DW_AT_lower_bound;
64132987Sgreen    DIEValue DW_AT_mutable;
6592654Sjeff    DIEValue DW_AT_ordering;
6692654Sjeff    DIEValue DW_AT_picture_string;
6792654Sjeff    DIEValue DW_AT_prototyped;
68105689Ssheldonh    DIEValue DW_AT_small;
6992654Sjeff    DIEValue DW_AT_segment;
70132987Sgreen    DIEValue DW_AT_string_length;
7192654Sjeff    DIEValue DW_AT_threads_scaled;
7292654Sjeff    DIEValue DW_AT_upper_bound;
7392654Sjeff    DIEValue DW_AT_use_location;
7492654Sjeff    DIEValue DW_AT_use_UTF8;
7592654Sjeff    DIEValue DW_AT_variable_parameter;
7692654Sjeff    DIEValue DW_AT_virtuality;
7792654Sjeff    DIEValue DW_AT_visibility;
7892654Sjeff    DIEValue DW_AT_vtable_elem_location;
7992654Sjeff    DIEValue DW_AT_type;
8092654Sjeff
8192654Sjeff    // Insert any additional ones here...
8292654Sjeff  };
8392654Sjeff
8492654Sjeffpublic:
8592654Sjeff  DIEHash(AsmPrinter *A = nullptr) : AP(A) {}
8692654Sjeff
8792654Sjeff  /// \brief Computes the CU signature.
8892654Sjeff  uint64_t computeCUSignature(const DIE &Die);
8992654Sjeff
9092654Sjeff  /// \brief Computes the type signature.
9192654Sjeff  uint64_t computeTypeSignature(const DIE &Die);
9292654Sjeff
9392654Sjeff  // Helper routines to process parts of a DIE.
9492654Sjeffprivate:
9592654Sjeff  /// \brief Adds the parent context of \param Die to the hash.
96132987Sgreen  void addParentContext(const DIE &Die);
9792654Sjeff
9892654Sjeff  /// \brief Adds the attributes of \param Die to the hash.
99132987Sgreen  void addAttributes(const DIE &Die);
100132987Sgreen
10192654Sjeff  /// \brief Computes the full DWARF4 7.27 hash of the DIE.
10292654Sjeff  void computeHash(const DIE &Die);
10392654Sjeff
104184546Skeramida  // Routines that add DIEValues to the hash.
105184546Skeramidapublic:
10692654Sjeff  /// \brief Adds \param Value to the hash.
107132987Sgreen  void update(uint8_t Value) { Hash.update(Value); }
10892654Sjeff
10992654Sjeff  /// \brief Encodes and adds \param Value to the hash as a ULEB128.
11092654Sjeff  void addULEB128(uint64_t Value);
11192654Sjeff
11292654Sjeff  /// \brief Encodes and adds \param Value to the hash as a SLEB128.
11392654Sjeff  void addSLEB128(int64_t Value);
11492654Sjeff
11592654Sjeffprivate:
11692654Sjeff  /// \brief Adds \param Str to the hash and includes a NULL byte.
11792654Sjeff  void addString(StringRef Str);
11892654Sjeff
11992654Sjeff  /// \brief Collects the attributes of DIE \param Die into the \param Attrs
12092654Sjeff  /// structure.
12192654Sjeff  void collectAttributes(const DIE &Die, DIEAttrs &Attrs);
122184546Skeramida
12392654Sjeff  /// \brief Hashes the attributes in \param Attrs in order.
12492654Sjeff  void hashAttributes(const DIEAttrs &Attrs, dwarf::Tag Tag);
12592654Sjeff
12692654Sjeff  /// \brief Hashes the data in a block like DIEValue, e.g. DW_FORM_block or
12792654Sjeff  /// DW_FORM_exprloc.
12892654Sjeff  void hashBlockData(const DIE::const_value_range &Values);
12992654Sjeff
13092654Sjeff  /// \brief Hashes the contents pointed to in the .debug_loc section.
13192654Sjeff  void hashLocList(const DIELocList &LocList);
13292654Sjeff
13392654Sjeff  /// \brief Hashes an individual attribute.
13492654Sjeff  void hashAttribute(DIEValue Value, dwarf::Tag Tag);
135184546Skeramida
13692654Sjeff  /// \brief Hashes an attribute that refers to another DIE.
137105689Ssheldonh  void hashDIEEntry(dwarf::Attribute Attribute, dwarf::Tag Tag,
13892654Sjeff                    const DIE &Entry);
13992654Sjeff
14092654Sjeff  /// \brief Hashes a reference to a named type in such a way that is
14192654Sjeff  /// independent of whether that type is described by a declaration or a
14292654Sjeff  /// definition.
14392654Sjeff  void hashShallowTypeReference(dwarf::Attribute Attribute, const DIE &Entry,
14492654Sjeff                                StringRef Name);
14592654Sjeff
14692654Sjeff  /// \brief Hashes a reference to a previously referenced type DIE.
14792654Sjeff  void hashRepeatedTypeReference(dwarf::Attribute Attribute,
14892654Sjeff                                 unsigned DieNumber);
14992654Sjeff
15092654Sjeff  void hashNestedType(const DIE &Die, StringRef Name);
15192654Sjeff
152184546Skeramidaprivate:
15392654Sjeff  MD5 Hash;
15492654Sjeff  AsmPrinter *AP;
155184546Skeramida  DenseMap<const DIE *, unsigned> Numbering;
15692654Sjeff};
15792654Sjeff}
15892654Sjeff
15992654Sjeff#endif
160184546Skeramida