LLVM  3.7.0
DIEHash.h
Go to the documentation of this file.
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 #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DIEHASH_H
15 #define LLVM_LIB_CODEGEN_ASMPRINTER_DIEHASH_H
16 
17 #include "llvm/ADT/DenseMap.h"
18 #include "llvm/CodeGen/DIE.h"
19 #include "llvm/Support/MD5.h"
20 
21 namespace llvm {
22 
23 class AsmPrinter;
24 class CompileUnit;
25 
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 {
80 
81  // Insert any additional ones here...
82  };
83 
84 public:
85  DIEHash(AsmPrinter *A = nullptr) : AP(A) {}
86 
87  /// \brief Computes the ODR signature.
88  uint64_t computeDIEODRSignature(const DIE &Die);
89 
90  /// \brief Computes the CU signature.
91  uint64_t computeCUSignature(const DIE &Die);
92 
93  /// \brief Computes the type signature.
94  uint64_t computeTypeSignature(const DIE &Die);
95 
96  // Helper routines to process parts of a DIE.
97 private:
98  /// \brief Adds the parent context of \param Die to the hash.
99  void addParentContext(const DIE &Die);
100 
101  /// \brief Adds the attributes of \param Die to the hash.
102  void addAttributes(const DIE &Die);
103 
104  /// \brief Computes the full DWARF4 7.27 hash of the DIE.
105  void computeHash(const DIE &Die);
106 
107  // Routines that add DIEValues to the hash.
108 public:
109  /// \brief Adds \param Value to the hash.
110  void update(uint8_t Value) { Hash.update(Value); }
111 
112  /// \brief Encodes and adds \param Value to the hash as a ULEB128.
113  void addULEB128(uint64_t Value);
114 
115  /// \brief Encodes and adds \param Value to the hash as a SLEB128.
116  void addSLEB128(int64_t Value);
117 
118 private:
119  /// \brief Adds \param Str to the hash and includes a NULL byte.
120  void addString(StringRef Str);
121 
122  /// \brief Collects the attributes of DIE \param Die into the \param Attrs
123  /// structure.
124  void collectAttributes(const DIE &Die, DIEAttrs &Attrs);
125 
126  /// \brief Hashes the attributes in \param Attrs in order.
127  void hashAttributes(const DIEAttrs &Attrs, dwarf::Tag Tag);
128 
129  /// \brief Hashes the data in a block like DIEValue, e.g. DW_FORM_block or
130  /// DW_FORM_exprloc.
131  void hashBlockData(const DIE::const_value_range &Values);
132 
133  /// \brief Hashes the contents pointed to in the .debug_loc section.
134  void hashLocList(const DIELocList &LocList);
135 
136  /// \brief Hashes an individual attribute.
137  void hashAttribute(DIEValue Value, dwarf::Tag Tag);
138 
139  /// \brief Hashes an attribute that refers to another DIE.
140  void hashDIEEntry(dwarf::Attribute Attribute, dwarf::Tag Tag,
141  const DIE &Entry);
142 
143  /// \brief Hashes a reference to a named type in such a way that is
144  /// independent of whether that type is described by a declaration or a
145  /// definition.
146  void hashShallowTypeReference(dwarf::Attribute Attribute, const DIE &Entry,
147  StringRef Name);
148 
149  /// \brief Hashes a reference to a previously referenced type DIE.
150  void hashRepeatedTypeReference(dwarf::Attribute Attribute,
151  unsigned DieNumber);
152 
153  void hashNestedType(const DIE &Die, StringRef Name);
154 
155 private:
156  MD5 Hash;
157  AsmPrinter *AP;
159 };
160 }
161 
162 #endif
An object containing the capability of hashing and adding hash attributes onto a DIE.
Definition: DIEHash.h:28
uint64_t computeCUSignature(const DIE &Die)
Computes the CU signature.
Definition: DIEHash.cpp:508
DIEHash(AsmPrinter *A=nullptr)
Definition: DIEHash.h:85
void addULEB128(uint64_t Value)
Encodes and adds.
Definition: DIEHash.cpp:55
DIELocList - Represents a pointer to a location list in the debug_loc section.
Definition: DIE.h:285
uint64_t computeTypeSignature(const DIE &Die)
Computes the type signature.
Definition: DIEHash.cpp:529
void update(ArrayRef< uint8_t > Data)
Updates the hash for the byte stream provided.
Definition: MD5.cpp:187
DIE - A structured debug information entry.
Definition: DIE.h:623
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:66
uint64_t computeDIEODRSignature(const DIE &Die)
Computes the ODR signature.
Definition: DIEHash.cpp:476
A range adaptor for a pair of iterators.
void update(uint8_t Value)
Adds.
Definition: DIEHash.h:110
void addSLEB128(int64_t Value)
Encodes and adds.
Definition: DIEHash.cpp:66
Definition: MD5.h:37
LLVM Value Representation.
Definition: Value.h:69
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:40