LLVM  14.0.0git
DIEHash.h
Go to the documentation of this file.
1 //===-- llvm/CodeGen/DIEHash.h - Dwarf Hashing Framework -------*- C++ -*--===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains support for DWARF4 hashing of DIEs.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DIEHASH_H
14 #define LLVM_LIB_CODEGEN_ASMPRINTER_DIEHASH_H
15 
16 #include "llvm/ADT/DenseMap.h"
17 #include "llvm/CodeGen/DIE.h"
18 #include "llvm/Support/MD5.h"
19 
20 namespace llvm {
21 
22 class AsmPrinter;
23 
24 /// An object containing the capability of hashing and adding hash
25 /// attributes onto a DIE.
26 class DIEHash {
27  // Collection of all attributes used in hashing a particular DIE.
28  struct DIEAttrs {
29 #define HANDLE_DIE_HASH_ATTR(NAME) DIEValue NAME;
30 #include "DIEHashAttributes.def"
31  };
32 
33 public:
34  DIEHash(AsmPrinter *A = nullptr, DwarfCompileUnit *CU = nullptr)
35  : AP(A), CU(CU) {}
36 
37  /// Computes the CU signature.
38  uint64_t computeCUSignature(StringRef DWOName, const DIE &Die);
39 
40  /// Computes the type signature.
41  uint64_t computeTypeSignature(const DIE &Die);
42 
43  // Helper routines to process parts of a DIE.
44 private:
45  /// Adds the parent context of \param Parent to the hash.
46  void addParentContext(const DIE &Parent);
47 
48  /// Adds the attributes of \param Die to the hash.
49  void addAttributes(const DIE &Die);
50 
51  /// Computes the full DWARF4 7.27 hash of the DIE.
52  void computeHash(const DIE &Die);
53 
54  // Routines that add DIEValues to the hash.
55 public:
56  /// Adds \param Value to the hash.
57  void update(uint8_t Value) { Hash.update(Value); }
58 
59  /// Encodes and adds \param Value to the hash as a ULEB128.
61 
62  /// Encodes and adds \param Value to the hash as a SLEB128.
63  void addSLEB128(int64_t Value);
64 
65 private:
66  /// Adds \param Str to the hash and includes a NULL byte.
67  void addString(StringRef Str);
68 
69  /// Collects the attributes of DIE \param Die into the \param Attrs
70  /// structure.
71  void collectAttributes(const DIE &Die, DIEAttrs &Attrs);
72 
73  /// Hashes the attributes in \param Attrs in order.
74  void hashAttributes(const DIEAttrs &Attrs, dwarf::Tag Tag);
75 
76  /// Hashes the data in a block like DIEValue, e.g. DW_FORM_block or
77  /// DW_FORM_exprloc.
78  void hashBlockData(const DIE::const_value_range &Values);
79 
80  /// Hashes the contents pointed to in the .debug_loc section.
81  void hashLocList(const DIELocList &LocList);
82 
83  /// Hashes an individual attribute.
84  void hashAttribute(const DIEValue &Value, dwarf::Tag Tag);
85 
86  /// Hashes an attribute that refers to another DIE.
87  void hashDIEEntry(dwarf::Attribute Attribute, dwarf::Tag Tag,
88  const DIE &Entry);
89 
90  /// Hashes a reference to a named type in such a way that is
91  /// independent of whether that type is described by a declaration or a
92  /// definition.
93  void hashShallowTypeReference(dwarf::Attribute Attribute, const DIE &Entry,
94  StringRef Name);
95 
96  /// Hashes a reference to a previously referenced type DIE.
97  void hashRepeatedTypeReference(dwarf::Attribute Attribute,
98  unsigned DieNumber);
99 
100  void hashNestedType(const DIE &Die, StringRef Name);
101 
102 private:
103  MD5 Hash;
104  AsmPrinter *AP;
107 };
108 }
109 
110 #endif
Attrs
Function Attrs
Definition: README_ALTIVEC.txt:215
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::MD5::update
void update(ArrayRef< uint8_t > Data)
Updates the hash for the byte stream provided.
Definition: MD5.cpp:190
llvm::Attribute
Definition: Attributes.h:52
llvm::DwarfCompileUnit
Definition: DwarfCompileUnit.h:47
llvm::DIEValue
Definition: DIE.h:369
llvm::DIEHash::DIEHash
DIEHash(AsmPrinter *A=nullptr, DwarfCompileUnit *CU=nullptr)
Definition: DIEHash.h:34
DenseMap.h
llvm::DIE
A structured debug information entry.
Definition: DIE.h:739
llvm::dwarf::Tag
Tag
Definition: Dwarf.h:104
llvm::DIEHash::addULEB128
void addULEB128(uint64_t Value)
Encodes and adds.
Definition: DIEHash.cpp:53
llvm::DIEHash::addSLEB128
void addSLEB128(int64_t Value)
Encodes and adds.
Definition: DIEHash.cpp:64
llvm::dwarf::Attribute
Attribute
Attributes.
Definition: Dwarf.h:124
llvm::DIEHash::computeTypeSignature
uint64_t computeTypeSignature(const DIE &Die)
Computes the type signature.
Definition: DIEHash.cpp:415
llvm::DIEHash
An object containing the capability of hashing and adding hash attributes onto a DIE.
Definition: DIEHash.h:26
MD5.h
llvm::DIELocList
Represents a pointer to a location list in the debug_loc section.
Definition: DIE.h:332
DIE.h
llvm::DIEHash::computeCUSignature
uint64_t computeCUSignature(StringRef DWOName, const DIE &Die)
Computes the CU signature.
Definition: DIEHash.cpp:392
llvm::DIEHash::update
void update(uint8_t Value)
Adds.
Definition: DIEHash.h:57
uint64_t
llvm::MD5
Definition: MD5.h:41
llvm::DenseMap
Definition: DenseMap.h:714
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
llvm::AsmPrinter
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:82
llvm::iterator_range
A range adaptor for a pair of iterators.
Definition: iterator_range.h:30
CU
Definition: AArch64AsmBackend.cpp:501
llvm::Value
LLVM Value Representation.
Definition: Value.h:75