Recommit r373598 "[yaml2obj/obj2yaml] - Add support for SHT_LLVM_ADDRSIG sections."
[llvm-complete.git] / lib / CodeGen / AsmPrinter / DIEHash.h
blob2e49514c98be383d6d9765567a2c98fa3a41d509
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.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DIEHASH_H
14 #define LLVM_LIB_CODEGEN_ASMPRINTER_DIEHASH_H
16 #include "llvm/ADT/DenseMap.h"
17 #include "llvm/CodeGen/DIE.h"
18 #include "llvm/Support/MD5.h"
20 namespace llvm {
22 class AsmPrinter;
23 class CompileUnit;
25 /// An object containing the capability of hashing and adding hash
26 /// attributes onto a DIE.
27 class DIEHash {
28 // Collection of all attributes used in hashing a particular DIE.
29 struct DIEAttrs {
30 #define HANDLE_DIE_HASH_ATTR(NAME) DIEValue NAME;
31 #include "DIEHashAttributes.def"
34 public:
35 DIEHash(AsmPrinter *A = nullptr) : AP(A) {}
37 /// Computes the CU signature.
38 uint64_t computeCUSignature(StringRef DWOName, const DIE &Die);
40 /// Computes the type signature.
41 uint64_t computeTypeSignature(const DIE &Die);
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);
48 /// Adds the attributes of \param Die to the hash.
49 void addAttributes(const DIE &Die);
51 /// Computes the full DWARF4 7.27 hash of the DIE.
52 void computeHash(const DIE &Die);
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); }
59 /// Encodes and adds \param Value to the hash as a ULEB128.
60 void addULEB128(uint64_t Value);
62 /// Encodes and adds \param Value to the hash as a SLEB128.
63 void addSLEB128(int64_t Value);
65 private:
66 /// Adds \param Str to the hash and includes a NULL byte.
67 void addString(StringRef Str);
69 /// Collects the attributes of DIE \param Die into the \param Attrs
70 /// structure.
71 void collectAttributes(const DIE &Die, DIEAttrs &Attrs);
73 /// Hashes the attributes in \param Attrs in order.
74 void hashAttributes(const DIEAttrs &Attrs, dwarf::Tag Tag);
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);
80 /// Hashes the contents pointed to in the .debug_loc section.
81 void hashLocList(const DIELocList &LocList);
83 /// Hashes an individual attribute.
84 void hashAttribute(const DIEValue &Value, dwarf::Tag Tag);
86 /// Hashes an attribute that refers to another DIE.
87 void hashDIEEntry(dwarf::Attribute Attribute, dwarf::Tag Tag,
88 const DIE &Entry);
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);
96 /// Hashes a reference to a previously referenced type DIE.
97 void hashRepeatedTypeReference(dwarf::Attribute Attribute,
98 unsigned DieNumber);
100 void hashNestedType(const DIE &Die, StringRef Name);
102 private:
103 MD5 Hash;
104 AsmPrinter *AP;
105 DenseMap<const DIE *, unsigned> Numbering;
109 #endif