Fix for PR34888.
[llvm-core.git] / lib / CodeGen / AsmPrinter / DIEHash.h
blob29337ae38a996b699fd50c3b2236690b87fbbc8a
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.
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"
21 namespace llvm {
23 class AsmPrinter;
24 class CompileUnit;
26 /// \brief An object containing the capability of hashing and adding hash
27 /// attributes onto a DIE.
28 class DIEHash {
29 // Collection of all attributes used in hashing a particular DIE.
30 struct DIEAttrs {
31 #define HANDLE_DIE_HASH_ATTR(NAME) DIEValue NAME;
32 #include "DIEHashAttributes.def"
35 public:
36 DIEHash(AsmPrinter *A = nullptr) : AP(A) {}
38 /// \brief Computes the CU signature.
39 uint64_t computeCUSignature(StringRef DWOName, const DIE &Die);
41 /// \brief Computes the type signature.
42 uint64_t computeTypeSignature(const DIE &Die);
44 // Helper routines to process parts of a DIE.
45 private:
46 /// \brief Adds the parent context of \param Die to the hash.
47 void addParentContext(const DIE &Die);
49 /// \brief Adds the attributes of \param Die to the hash.
50 void addAttributes(const DIE &Die);
52 /// \brief Computes the full DWARF4 7.27 hash of the DIE.
53 void computeHash(const DIE &Die);
55 // Routines that add DIEValues to the hash.
56 public:
57 /// \brief Adds \param Value to the hash.
58 void update(uint8_t Value) { Hash.update(Value); }
60 /// \brief Encodes and adds \param Value to the hash as a ULEB128.
61 void addULEB128(uint64_t Value);
63 /// \brief Encodes and adds \param Value to the hash as a SLEB128.
64 void addSLEB128(int64_t Value);
66 private:
67 /// \brief Adds \param Str to the hash and includes a NULL byte.
68 void addString(StringRef Str);
70 /// \brief Collects the attributes of DIE \param Die into the \param Attrs
71 /// structure.
72 void collectAttributes(const DIE &Die, DIEAttrs &Attrs);
74 /// \brief Hashes the attributes in \param Attrs in order.
75 void hashAttributes(const DIEAttrs &Attrs, dwarf::Tag Tag);
77 /// \brief Hashes the data in a block like DIEValue, e.g. DW_FORM_block or
78 /// DW_FORM_exprloc.
79 void hashBlockData(const DIE::const_value_range &Values);
81 /// \brief Hashes the contents pointed to in the .debug_loc section.
82 void hashLocList(const DIELocList &LocList);
84 /// \brief Hashes an individual attribute.
85 void hashAttribute(const DIEValue &Value, dwarf::Tag Tag);
87 /// \brief Hashes an attribute that refers to another DIE.
88 void hashDIEEntry(dwarf::Attribute Attribute, dwarf::Tag Tag,
89 const DIE &Entry);
91 /// \brief 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
93 /// definition.
94 void hashShallowTypeReference(dwarf::Attribute Attribute, const DIE &Entry,
95 StringRef Name);
97 /// \brief Hashes a reference to a previously referenced type DIE.
98 void hashRepeatedTypeReference(dwarf::Attribute Attribute,
99 unsigned DieNumber);
101 void hashNestedType(const DIE &Die, StringRef Name);
103 private:
104 MD5 Hash;
105 AsmPrinter *AP;
106 DenseMap<const DIE *, unsigned> Numbering;
110 #endif