blob: 833ca0276fdb5088ee50e7c394862d2cf11b2425 [file] [log] [blame]
Eric Christopher45731982013-08-08 23:45:55 +00001//===-- 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
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000014#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DIEHASH_H
15#define LLVM_LIB_CODEGEN_ASMPRINTER_DIEHASH_H
Eric Christopher5c38b652014-03-07 22:40:30 +000016
David Blaikie980d4992013-10-21 18:59:40 +000017#include "llvm/ADT/DenseMap.h"
Chandler Carruthd9903882015-01-14 11:23:27 +000018#include "llvm/CodeGen/DIE.h"
Eric Christopher45731982013-08-08 23:45:55 +000019#include "llvm/Support/MD5.h"
20
21namespace llvm {
22
Eric Christopher420569b2014-02-20 02:50:45 +000023class AsmPrinter;
Eric Christopher45731982013-08-08 23:45:55 +000024class CompileUnit;
25
26/// \brief An object containing the capability of hashing and adding hash
27/// attributes onto a DIE.
Benjamin Kramer079b96e2013-09-11 18:05:11 +000028class DIEHash {
Eric Christopherd29614f2013-08-13 01:21:55 +000029 // Collection of all attributes used in hashing a particular DIE.
30 struct DIEAttrs {
Duncan P. N. Exon Smithf3a6a672015-05-27 22:36:37 +000031 DIEValue DW_AT_name;
32 DIEValue DW_AT_accessibility;
33 DIEValue DW_AT_address_class;
34 DIEValue DW_AT_allocated;
35 DIEValue DW_AT_artificial;
36 DIEValue DW_AT_associated;
37 DIEValue DW_AT_binary_scale;
38 DIEValue DW_AT_bit_offset;
39 DIEValue DW_AT_bit_size;
40 DIEValue DW_AT_bit_stride;
41 DIEValue DW_AT_byte_size;
42 DIEValue DW_AT_byte_stride;
43 DIEValue DW_AT_const_expr;
44 DIEValue DW_AT_const_value;
45 DIEValue DW_AT_containing_type;
46 DIEValue DW_AT_count;
47 DIEValue DW_AT_data_bit_offset;
48 DIEValue DW_AT_data_location;
49 DIEValue DW_AT_data_member_location;
50 DIEValue DW_AT_decimal_scale;
51 DIEValue DW_AT_decimal_sign;
52 DIEValue DW_AT_default_value;
53 DIEValue DW_AT_digit_count;
54 DIEValue DW_AT_discr;
55 DIEValue DW_AT_discr_list;
56 DIEValue DW_AT_discr_value;
57 DIEValue DW_AT_encoding;
58 DIEValue DW_AT_enum_class;
59 DIEValue DW_AT_endianity;
60 DIEValue DW_AT_explicit;
61 DIEValue DW_AT_is_optional;
62 DIEValue DW_AT_location;
63 DIEValue DW_AT_lower_bound;
64 DIEValue DW_AT_mutable;
65 DIEValue DW_AT_ordering;
66 DIEValue DW_AT_picture_string;
67 DIEValue DW_AT_prototyped;
68 DIEValue DW_AT_small;
69 DIEValue DW_AT_segment;
70 DIEValue DW_AT_string_length;
71 DIEValue DW_AT_threads_scaled;
72 DIEValue DW_AT_upper_bound;
73 DIEValue DW_AT_use_location;
74 DIEValue DW_AT_use_UTF8;
75 DIEValue DW_AT_variable_parameter;
76 DIEValue DW_AT_virtuality;
77 DIEValue DW_AT_visibility;
78 DIEValue DW_AT_vtable_elem_location;
79 DIEValue DW_AT_type;
Eric Christophere020fa72013-09-03 20:00:20 +000080
81 // Insert any additional ones here...
Eric Christopherd29614f2013-08-13 01:21:55 +000082 };
83
Eric Christopher45731982013-08-08 23:45:55 +000084public:
Craig Topper353eda42014-04-24 06:44:33 +000085 DIEHash(AsmPrinter *A = nullptr) : AP(A) {}
Eric Christopher420569b2014-02-20 02:50:45 +000086
Eric Christopherb86e2ad2013-09-03 21:57:50 +000087 /// \brief Computes the ODR signature.
David Blaikie2aee7be2013-10-24 18:29:03 +000088 uint64_t computeDIEODRSignature(const DIE &Die);
Eric Christopher45731982013-08-08 23:45:55 +000089
Eric Christopherb86e2ad2013-09-03 21:57:50 +000090 /// \brief Computes the CU signature.
David Blaikie2aee7be2013-10-24 18:29:03 +000091 uint64_t computeCUSignature(const DIE &Die);
Eric Christopherd29614f2013-08-13 01:21:55 +000092
Eric Christopher25b7adc2013-09-03 21:57:57 +000093 /// \brief Computes the type signature.
David Blaikie2aee7be2013-10-24 18:29:03 +000094 uint64_t computeTypeSignature(const DIE &Die);
Eric Christopher25b7adc2013-09-03 21:57:57 +000095
Eric Christopher45731982013-08-08 23:45:55 +000096 // Helper routines to process parts of a DIE.
Eric Christopherd29614f2013-08-13 01:21:55 +000097private:
Eric Christopher45731982013-08-08 23:45:55 +000098 /// \brief Adds the parent context of \param Die to the hash.
David Blaikie2aee7be2013-10-24 18:29:03 +000099 void addParentContext(const DIE &Die);
Eric Christopherd29614f2013-08-13 01:21:55 +0000100
101 /// \brief Adds the attributes of \param Die to the hash.
David Blaikie2aee7be2013-10-24 18:29:03 +0000102 void addAttributes(const DIE &Die);
Eric Christopherd29614f2013-08-13 01:21:55 +0000103
104 /// \brief Computes the full DWARF4 7.27 hash of the DIE.
David Blaikie2aee7be2013-10-24 18:29:03 +0000105 void computeHash(const DIE &Die);
Eric Christopherd29614f2013-08-13 01:21:55 +0000106
Eric Christopher45731982013-08-08 23:45:55 +0000107 // Routines that add DIEValues to the hash.
Eric Christopher5c38b652014-03-07 22:40:30 +0000108public:
109 /// \brief Adds \param Value to the hash.
110 void update(uint8_t Value) { Hash.update(Value); }
111
Eric Christopher45731982013-08-08 23:45:55 +0000112 /// \brief Encodes and adds \param Value to the hash as a ULEB128.
113 void addULEB128(uint64_t Value);
114
David Blaikie6316ca42013-10-16 23:36:20 +0000115 /// \brief Encodes and adds \param Value to the hash as a SLEB128.
116 void addSLEB128(int64_t Value);
117
Eric Christopher5c38b652014-03-07 22:40:30 +0000118private:
Eric Christopher45731982013-08-08 23:45:55 +0000119 /// \brief Adds \param Str to the hash and includes a NULL byte.
120 void addString(StringRef Str);
Eric Christopherd29614f2013-08-13 01:21:55 +0000121
122 /// \brief Collects the attributes of DIE \param Die into the \param Attrs
123 /// structure.
David Blaikie2aee7be2013-10-24 18:29:03 +0000124 void collectAttributes(const DIE &Die, DIEAttrs &Attrs);
Eric Christopherd29614f2013-08-13 01:21:55 +0000125
126 /// \brief Hashes the attributes in \param Attrs in order.
David Blaikie6cf58c82013-10-21 22:36:50 +0000127 void hashAttributes(const DIEAttrs &Attrs, dwarf::Tag Tag);
Eric Christopherd29614f2013-08-13 01:21:55 +0000128
Eric Christopher420569b2014-02-20 02:50:45 +0000129 /// \brief Hashes the data in a block like DIEValue, e.g. DW_FORM_block or
130 /// DW_FORM_exprloc.
Duncan P. N. Exon Smith4fb1f9c2015-06-25 23:46:41 +0000131 void hashBlockData(const DIE::const_value_range &Values);
Eric Christopher420569b2014-02-20 02:50:45 +0000132
Eric Christopher4f17ee02014-03-08 00:29:41 +0000133 /// \brief Hashes the contents pointed to in the .debug_loc section.
134 void hashLocList(const DIELocList &LocList);
135
Eric Christopherd29614f2013-08-13 01:21:55 +0000136 /// \brief Hashes an individual attribute.
Duncan P. N. Exon Smithf3a6a672015-05-27 22:36:37 +0000137 void hashAttribute(DIEValue Value, dwarf::Tag Tag);
Eric Christopherd29614f2013-08-13 01:21:55 +0000138
David Blaikieafcb9652013-10-24 17:51:43 +0000139 /// \brief Hashes an attribute that refers to another DIE.
140 void hashDIEEntry(dwarf::Attribute Attribute, dwarf::Tag Tag,
David Blaikie2aee7be2013-10-24 18:29:03 +0000141 const DIE &Entry);
David Blaikieafcb9652013-10-24 17:51:43 +0000142
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.
David Blaikie2aee7be2013-10-24 18:29:03 +0000146 void hashShallowTypeReference(dwarf::Attribute Attribute, const DIE &Entry,
147 StringRef Name);
David Blaikieafcb9652013-10-24 17:51:43 +0000148
149 /// \brief Hashes a reference to a previously referenced type DIE.
Eric Christophera07e4f52013-11-19 09:28:34 +0000150 void hashRepeatedTypeReference(dwarf::Attribute Attribute,
151 unsigned DieNumber);
David Blaikieafcb9652013-10-24 17:51:43 +0000152
David Blaikie65cc9692013-10-25 18:38:43 +0000153 void hashNestedType(const DIE &Die, StringRef Name);
154
Eric Christopher45731982013-08-08 23:45:55 +0000155private:
156 MD5 Hash;
Eric Christopher420569b2014-02-20 02:50:45 +0000157 AsmPrinter *AP;
David Blaikie2aee7be2013-10-24 18:29:03 +0000158 DenseMap<const DIE *, unsigned> Numbering;
Eric Christopher45731982013-08-08 23:45:55 +0000159};
Alexander Kornienkof00654e2015-06-23 09:49:53 +0000160}
Eric Christopher5c38b652014-03-07 22:40:30 +0000161
162#endif