blob: c3db2d06ca459e179e80ab84cd72635107451c93 [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
Eric Christopher5c38b652014-03-07 22:40:30 +000014#ifndef CODEGEN_ASMPRINTER_DIEHASH_H__
15#define CODEGEN_ASMPRINTER_DIEHASH_H__
16
David Blaikie9208b5e2013-11-13 18:07:27 +000017#include "DIE.h"
David Blaikie980d4992013-10-21 18:59:40 +000018#include "llvm/ADT/DenseMap.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 Christopher5c38b652014-03-07 22:40:30 +000029
Eric Christopherd29614f2013-08-13 01:21:55 +000030 // The entry for a particular attribute.
31 struct AttrEntry {
32 const DIEValue *Val;
33 const DIEAbbrevData *Desc;
34 };
35
36 // Collection of all attributes used in hashing a particular DIE.
37 struct DIEAttrs {
38 AttrEntry DW_AT_name;
Eric Christophere020fa72013-09-03 20:00:20 +000039 AttrEntry DW_AT_accessibility;
40 AttrEntry DW_AT_address_class;
41 AttrEntry DW_AT_allocated;
42 AttrEntry DW_AT_artificial;
43 AttrEntry DW_AT_associated;
44 AttrEntry DW_AT_binary_scale;
45 AttrEntry DW_AT_bit_offset;
46 AttrEntry DW_AT_bit_size;
47 AttrEntry DW_AT_bit_stride;
48 AttrEntry DW_AT_byte_size;
49 AttrEntry DW_AT_byte_stride;
50 AttrEntry DW_AT_const_expr;
51 AttrEntry DW_AT_const_value;
52 AttrEntry DW_AT_containing_type;
53 AttrEntry DW_AT_count;
54 AttrEntry DW_AT_data_bit_offset;
55 AttrEntry DW_AT_data_location;
56 AttrEntry DW_AT_data_member_location;
57 AttrEntry DW_AT_decimal_scale;
58 AttrEntry DW_AT_decimal_sign;
59 AttrEntry DW_AT_default_value;
60 AttrEntry DW_AT_digit_count;
61 AttrEntry DW_AT_discr;
62 AttrEntry DW_AT_discr_list;
63 AttrEntry DW_AT_discr_value;
64 AttrEntry DW_AT_encoding;
65 AttrEntry DW_AT_enum_class;
66 AttrEntry DW_AT_endianity;
67 AttrEntry DW_AT_explicit;
68 AttrEntry DW_AT_is_optional;
69 AttrEntry DW_AT_location;
70 AttrEntry DW_AT_lower_bound;
71 AttrEntry DW_AT_mutable;
72 AttrEntry DW_AT_ordering;
73 AttrEntry DW_AT_picture_string;
74 AttrEntry DW_AT_prototyped;
75 AttrEntry DW_AT_small;
76 AttrEntry DW_AT_segment;
77 AttrEntry DW_AT_string_length;
78 AttrEntry DW_AT_threads_scaled;
79 AttrEntry DW_AT_upper_bound;
80 AttrEntry DW_AT_use_location;
81 AttrEntry DW_AT_use_UTF8;
82 AttrEntry DW_AT_variable_parameter;
83 AttrEntry DW_AT_virtuality;
84 AttrEntry DW_AT_visibility;
85 AttrEntry DW_AT_vtable_elem_location;
David Blaikieca353be2013-10-17 22:07:09 +000086 AttrEntry DW_AT_type;
Eric Christophere020fa72013-09-03 20:00:20 +000087
88 // Insert any additional ones here...
Eric Christopherd29614f2013-08-13 01:21:55 +000089 };
90
Eric Christopher45731982013-08-08 23:45:55 +000091public:
Eric Christopher420569b2014-02-20 02:50:45 +000092 DIEHash(AsmPrinter *A = NULL) : AP(A) {}
93
Eric Christopherb86e2ad2013-09-03 21:57:50 +000094 /// \brief Computes the ODR signature.
David Blaikie2aee7be2013-10-24 18:29:03 +000095 uint64_t computeDIEODRSignature(const DIE &Die);
Eric Christopher45731982013-08-08 23:45:55 +000096
Eric Christopherb86e2ad2013-09-03 21:57:50 +000097 /// \brief Computes the CU signature.
David Blaikie2aee7be2013-10-24 18:29:03 +000098 uint64_t computeCUSignature(const DIE &Die);
Eric Christopherd29614f2013-08-13 01:21:55 +000099
Eric Christopher25b7adc2013-09-03 21:57:57 +0000100 /// \brief Computes the type signature.
David Blaikie2aee7be2013-10-24 18:29:03 +0000101 uint64_t computeTypeSignature(const DIE &Die);
Eric Christopher25b7adc2013-09-03 21:57:57 +0000102
Eric Christopher45731982013-08-08 23:45:55 +0000103 // Helper routines to process parts of a DIE.
Eric Christopherd29614f2013-08-13 01:21:55 +0000104private:
Eric Christopher45731982013-08-08 23:45:55 +0000105 /// \brief Adds the parent context of \param Die to the hash.
David Blaikie2aee7be2013-10-24 18:29:03 +0000106 void addParentContext(const DIE &Die);
Eric Christopherd29614f2013-08-13 01:21:55 +0000107
108 /// \brief Adds the attributes of \param Die to the hash.
David Blaikie2aee7be2013-10-24 18:29:03 +0000109 void addAttributes(const DIE &Die);
Eric Christopherd29614f2013-08-13 01:21:55 +0000110
111 /// \brief Computes the full DWARF4 7.27 hash of the DIE.
David Blaikie2aee7be2013-10-24 18:29:03 +0000112 void computeHash(const DIE &Die);
Eric Christopherd29614f2013-08-13 01:21:55 +0000113
Eric Christopher45731982013-08-08 23:45:55 +0000114 // Routines that add DIEValues to the hash.
Eric Christopher5c38b652014-03-07 22:40:30 +0000115public:
116 /// \brief Adds \param Value to the hash.
117 void update(uint8_t Value) { Hash.update(Value); }
118
Eric Christopher45731982013-08-08 23:45:55 +0000119 /// \brief Encodes and adds \param Value to the hash as a ULEB128.
120 void addULEB128(uint64_t Value);
121
David Blaikie6316ca42013-10-16 23:36:20 +0000122 /// \brief Encodes and adds \param Value to the hash as a SLEB128.
123 void addSLEB128(int64_t Value);
124
Eric Christopher5c38b652014-03-07 22:40:30 +0000125private:
Eric Christopher45731982013-08-08 23:45:55 +0000126 /// \brief Adds \param Str to the hash and includes a NULL byte.
127 void addString(StringRef Str);
Eric Christopherd29614f2013-08-13 01:21:55 +0000128
129 /// \brief Collects the attributes of DIE \param Die into the \param Attrs
130 /// structure.
David Blaikie2aee7be2013-10-24 18:29:03 +0000131 void collectAttributes(const DIE &Die, DIEAttrs &Attrs);
Eric Christopherd29614f2013-08-13 01:21:55 +0000132
133 /// \brief Hashes the attributes in \param Attrs in order.
David Blaikie6cf58c82013-10-21 22:36:50 +0000134 void hashAttributes(const DIEAttrs &Attrs, dwarf::Tag Tag);
Eric Christopherd29614f2013-08-13 01:21:55 +0000135
Eric Christopher420569b2014-02-20 02:50:45 +0000136 /// \brief Hashes the data in a block like DIEValue, e.g. DW_FORM_block or
137 /// DW_FORM_exprloc.
138 void hashBlockData(const SmallVectorImpl<DIEValue *> &Values);
139
Eric Christopherd29614f2013-08-13 01:21:55 +0000140 /// \brief Hashes an individual attribute.
David Blaikie6cf58c82013-10-21 22:36:50 +0000141 void hashAttribute(AttrEntry Attr, dwarf::Tag Tag);
Eric Christopherd29614f2013-08-13 01:21:55 +0000142
David Blaikieafcb9652013-10-24 17:51:43 +0000143 /// \brief Hashes an attribute that refers to another DIE.
144 void hashDIEEntry(dwarf::Attribute Attribute, dwarf::Tag Tag,
David Blaikie2aee7be2013-10-24 18:29:03 +0000145 const DIE &Entry);
David Blaikieafcb9652013-10-24 17:51:43 +0000146
147 /// \brief Hashes a reference to a named type in such a way that is
148 /// independent of whether that type is described by a declaration or a
149 /// definition.
David Blaikie2aee7be2013-10-24 18:29:03 +0000150 void hashShallowTypeReference(dwarf::Attribute Attribute, const DIE &Entry,
151 StringRef Name);
David Blaikieafcb9652013-10-24 17:51:43 +0000152
153 /// \brief Hashes a reference to a previously referenced type DIE.
Eric Christophera07e4f52013-11-19 09:28:34 +0000154 void hashRepeatedTypeReference(dwarf::Attribute Attribute,
155 unsigned DieNumber);
David Blaikieafcb9652013-10-24 17:51:43 +0000156
David Blaikie65cc9692013-10-25 18:38:43 +0000157 void hashNestedType(const DIE &Die, StringRef Name);
158
Eric Christopher45731982013-08-08 23:45:55 +0000159private:
160 MD5 Hash;
Eric Christopher420569b2014-02-20 02:50:45 +0000161 AsmPrinter *AP;
David Blaikie2aee7be2013-10-24 18:29:03 +0000162 DenseMap<const DIE *, unsigned> Numbering;
Eric Christopher45731982013-08-08 23:45:55 +0000163};
164}
Eric Christopher5c38b652014-03-07 22:40:30 +0000165
166#endif