1 //===-- llvm/CodeGen/DIEHash.h - Dwarf Hashing Framework -------*- C++ -*--===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains support for DWARF4 hashing of DIEs.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DIEHASH_H
15 #define LLVM_LIB_CODEGEN_ASMPRINTER_DIEHASH_H
17 #include "llvm/ADT/DenseMap.h"
18 #include "llvm/CodeGen/DIE.h"
19 #include "llvm/Support/MD5.h"
26 /// An object containing the capability of hashing and adding hash
27 /// attributes onto a DIE.
29 // Collection of all attributes used in hashing a particular DIE.
31 #define HANDLE_DIE_HASH_ATTR(NAME) DIEValue NAME;
32 #include "DIEHashAttributes.def"
36 DIEHash(AsmPrinter *A = nullptr) : AP(A) {}
38 /// Computes the CU signature.
39 uint64_t computeCUSignature(StringRef DWOName, const DIE &Die);
41 /// Computes the type signature.
42 uint64_t computeTypeSignature(const DIE &Die);
44 // Helper routines to process parts of a DIE.
46 /// Adds the parent context of \param Parent to the hash.
47 void addParentContext(const DIE &Parent);
49 /// Adds the attributes of \param Die to the hash.
50 void addAttributes(const DIE &Die);
52 /// Computes the full DWARF4 7.27 hash of the DIE.
53 void computeHash(const DIE &Die);
55 // Routines that add DIEValues to the hash.
57 /// Adds \param Value to the hash.
58 void update(uint8_t Value) { Hash.update(Value); }
60 /// Encodes and adds \param Value to the hash as a ULEB128.
61 void addULEB128(uint64_t Value);
63 /// Encodes and adds \param Value to the hash as a SLEB128.
64 void addSLEB128(int64_t Value);
67 /// Adds \param Str to the hash and includes a NULL byte.
68 void addString(StringRef Str);
70 /// Collects the attributes of DIE \param Die into the \param Attrs
72 void collectAttributes(const DIE &Die, DIEAttrs &Attrs);
74 /// Hashes the attributes in \param Attrs in order.
75 void hashAttributes(const DIEAttrs &Attrs, dwarf::Tag Tag);
77 /// Hashes the data in a block like DIEValue, e.g. DW_FORM_block or
79 void hashBlockData(const DIE::const_value_range &Values);
81 /// Hashes the contents pointed to in the .debug_loc section.
82 void hashLocList(const DIELocList &LocList);
84 /// Hashes an individual attribute.
85 void hashAttribute(const DIEValue &Value, dwarf::Tag Tag);
87 /// Hashes an attribute that refers to another DIE.
88 void hashDIEEntry(dwarf::Attribute Attribute, dwarf::Tag Tag,
91 /// Hashes a reference to a named type in such a way that is
92 /// independent of whether that type is described by a declaration or a
94 void hashShallowTypeReference(dwarf::Attribute Attribute, const DIE &Entry,
97 /// Hashes a reference to a previously referenced type DIE.
98 void hashRepeatedTypeReference(dwarf::Attribute Attribute,
101 void hashNestedType(const DIE &Die, StringRef Name);
106 DenseMap<const DIE *, unsigned> Numbering;