DebugInfo: Shrink pubnames/pubtypes in the presence of type units by only emitting...
[oota-llvm.git] / lib / CodeGen / AsmPrinter / DIEHash.h
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 #include "DIE.h"
15 #include "llvm/ADT/DenseMap.h"
16 #include "llvm/Support/MD5.h"
17
18 namespace llvm {
19
20 class AsmPrinter;
21 class CompileUnit;
22
23 /// \brief An object containing the capability of hashing and adding hash
24 /// attributes onto a DIE.
25 class DIEHash {
26   // The entry for a particular attribute.
27   struct AttrEntry {
28     const DIEValue *Val;
29     const DIEAbbrevData *Desc;
30   };
31
32   // Collection of all attributes used in hashing a particular DIE.
33   struct DIEAttrs {
34     AttrEntry DW_AT_name;
35     AttrEntry DW_AT_accessibility;
36     AttrEntry DW_AT_address_class;
37     AttrEntry DW_AT_allocated;
38     AttrEntry DW_AT_artificial;
39     AttrEntry DW_AT_associated;
40     AttrEntry DW_AT_binary_scale;
41     AttrEntry DW_AT_bit_offset;
42     AttrEntry DW_AT_bit_size;
43     AttrEntry DW_AT_bit_stride;
44     AttrEntry DW_AT_byte_size;
45     AttrEntry DW_AT_byte_stride;
46     AttrEntry DW_AT_const_expr;
47     AttrEntry DW_AT_const_value;
48     AttrEntry DW_AT_containing_type;
49     AttrEntry DW_AT_count;
50     AttrEntry DW_AT_data_bit_offset;
51     AttrEntry DW_AT_data_location;
52     AttrEntry DW_AT_data_member_location;
53     AttrEntry DW_AT_decimal_scale;
54     AttrEntry DW_AT_decimal_sign;
55     AttrEntry DW_AT_default_value;
56     AttrEntry DW_AT_digit_count;
57     AttrEntry DW_AT_discr;
58     AttrEntry DW_AT_discr_list;
59     AttrEntry DW_AT_discr_value;
60     AttrEntry DW_AT_encoding;
61     AttrEntry DW_AT_enum_class;
62     AttrEntry DW_AT_endianity;
63     AttrEntry DW_AT_explicit;
64     AttrEntry DW_AT_is_optional;
65     AttrEntry DW_AT_location;
66     AttrEntry DW_AT_lower_bound;
67     AttrEntry DW_AT_mutable;
68     AttrEntry DW_AT_ordering;
69     AttrEntry DW_AT_picture_string;
70     AttrEntry DW_AT_prototyped;
71     AttrEntry DW_AT_small;
72     AttrEntry DW_AT_segment;
73     AttrEntry DW_AT_string_length;
74     AttrEntry DW_AT_threads_scaled;
75     AttrEntry DW_AT_upper_bound;
76     AttrEntry DW_AT_use_location;
77     AttrEntry DW_AT_use_UTF8;
78     AttrEntry DW_AT_variable_parameter;
79     AttrEntry DW_AT_virtuality;
80     AttrEntry DW_AT_visibility;
81     AttrEntry DW_AT_vtable_elem_location;
82     AttrEntry DW_AT_type;
83
84     // Insert any additional ones here...
85   };
86
87 public:
88   DIEHash(AsmPrinter *A = NULL) : AP(A) {}
89
90   /// \brief Computes the ODR signature.
91   uint64_t computeDIEODRSignature(const DIE &Die);
92
93   /// \brief Computes the CU signature.
94   uint64_t computeCUSignature(const DIE &Die);
95
96   /// \brief Computes the type signature.
97   uint64_t computeTypeSignature(const DIE &Die);
98
99   // Helper routines to process parts of a DIE.
100 private:
101   /// \brief Adds the parent context of \param Die to the hash.
102   void addParentContext(const DIE &Die);
103
104   /// \brief Adds the attributes of \param Die to the hash.
105   void addAttributes(const DIE &Die);
106
107   /// \brief Computes the full DWARF4 7.27 hash of the DIE.
108   void computeHash(const DIE &Die);
109
110   // Routines that add DIEValues to the hash.
111 private:
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   /// \brief Adds \param Str to the hash and includes a NULL byte.
119   void addString(StringRef Str);
120
121   /// \brief Collects the attributes of DIE \param Die into the \param Attrs
122   /// structure.
123   void collectAttributes(const DIE &Die, DIEAttrs &Attrs);
124
125   /// \brief Hashes the attributes in \param Attrs in order.
126   void hashAttributes(const DIEAttrs &Attrs, dwarf::Tag Tag);
127
128   /// \brief Hashes the data in a block like DIEValue, e.g. DW_FORM_block or
129   /// DW_FORM_exprloc.
130   void hashBlockData(const SmallVectorImpl<DIEValue *> &Values);
131
132   /// \brief Hashes an individual attribute.
133   void hashAttribute(AttrEntry Attr, dwarf::Tag Tag);
134
135   /// \brief Hashes an attribute that refers to another DIE.
136   void hashDIEEntry(dwarf::Attribute Attribute, dwarf::Tag Tag,
137                     const DIE &Entry);
138
139   /// \brief Hashes a reference to a named type in such a way that is
140   /// independent of whether that type is described by a declaration or a
141   /// definition.
142   void hashShallowTypeReference(dwarf::Attribute Attribute, const DIE &Entry,
143                                 StringRef Name);
144
145   /// \brief Hashes a reference to a previously referenced type DIE.
146   void hashRepeatedTypeReference(dwarf::Attribute Attribute,
147                                  unsigned DieNumber);
148
149   void hashNestedType(const DIE &Die, StringRef Name);
150
151 private:
152   MD5 Hash;
153   AsmPrinter *AP;
154   DenseMap<const DIE *, unsigned> Numbering;
155 };
156 }