blob: a59df35a0d860ff2deb406b09fe3573f289009dd [file] [log] [blame]
Eric Christopher0d27ca12013-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
David Blaikie3baa3c32013-10-21 18:59:40 +000014#include "llvm/ADT/DenseMap.h"
Eric Christopher0d27ca12013-08-08 23:45:55 +000015#include "llvm/Support/MD5.h"
16
17namespace llvm {
18
19class CompileUnit;
20
21/// \brief An object containing the capability of hashing and adding hash
22/// attributes onto a DIE.
Benjamin Kramer55c06ae2013-09-11 18:05:11 +000023class DIEHash {
Eric Christopher0710bfa2013-08-13 01:21:55 +000024 // The entry for a particular attribute.
25 struct AttrEntry {
26 const DIEValue *Val;
27 const DIEAbbrevData *Desc;
28 };
29
30 // Collection of all attributes used in hashing a particular DIE.
31 struct DIEAttrs {
32 AttrEntry DW_AT_name;
Eric Christopherbd18c8d2013-09-03 20:00:20 +000033 AttrEntry DW_AT_accessibility;
34 AttrEntry DW_AT_address_class;
35 AttrEntry DW_AT_allocated;
36 AttrEntry DW_AT_artificial;
37 AttrEntry DW_AT_associated;
38 AttrEntry DW_AT_binary_scale;
39 AttrEntry DW_AT_bit_offset;
40 AttrEntry DW_AT_bit_size;
41 AttrEntry DW_AT_bit_stride;
42 AttrEntry DW_AT_byte_size;
43 AttrEntry DW_AT_byte_stride;
44 AttrEntry DW_AT_const_expr;
45 AttrEntry DW_AT_const_value;
46 AttrEntry DW_AT_containing_type;
47 AttrEntry DW_AT_count;
48 AttrEntry DW_AT_data_bit_offset;
49 AttrEntry DW_AT_data_location;
50 AttrEntry DW_AT_data_member_location;
51 AttrEntry DW_AT_decimal_scale;
52 AttrEntry DW_AT_decimal_sign;
53 AttrEntry DW_AT_default_value;
54 AttrEntry DW_AT_digit_count;
55 AttrEntry DW_AT_discr;
56 AttrEntry DW_AT_discr_list;
57 AttrEntry DW_AT_discr_value;
58 AttrEntry DW_AT_encoding;
59 AttrEntry DW_AT_enum_class;
60 AttrEntry DW_AT_endianity;
61 AttrEntry DW_AT_explicit;
62 AttrEntry DW_AT_is_optional;
63 AttrEntry DW_AT_location;
64 AttrEntry DW_AT_lower_bound;
65 AttrEntry DW_AT_mutable;
66 AttrEntry DW_AT_ordering;
67 AttrEntry DW_AT_picture_string;
68 AttrEntry DW_AT_prototyped;
69 AttrEntry DW_AT_small;
70 AttrEntry DW_AT_segment;
71 AttrEntry DW_AT_string_length;
72 AttrEntry DW_AT_threads_scaled;
73 AttrEntry DW_AT_upper_bound;
74 AttrEntry DW_AT_use_location;
75 AttrEntry DW_AT_use_UTF8;
76 AttrEntry DW_AT_variable_parameter;
77 AttrEntry DW_AT_virtuality;
78 AttrEntry DW_AT_visibility;
79 AttrEntry DW_AT_vtable_elem_location;
David Blaikie47f66d52013-10-17 22:07:09 +000080 AttrEntry DW_AT_type;
Eric Christopherbd18c8d2013-09-03 20:00:20 +000081
82 // Insert any additional ones here...
Eric Christopher0710bfa2013-08-13 01:21:55 +000083 };
84
Eric Christopher0d27ca12013-08-08 23:45:55 +000085public:
Eric Christopher41627cf2013-09-03 21:57:50 +000086 /// \brief Computes the ODR signature.
Eric Christopher0d27ca12013-08-08 23:45:55 +000087 uint64_t computeDIEODRSignature(DIE *Die);
88
Eric Christopher41627cf2013-09-03 21:57:50 +000089 /// \brief Computes the CU signature.
Eric Christopher0710bfa2013-08-13 01:21:55 +000090 uint64_t computeCUSignature(DIE *Die);
91
Eric Christopher800a8762013-09-03 21:57:57 +000092 /// \brief Computes the type signature.
93 uint64_t computeTypeSignature(DIE *Die);
94
Eric Christopher0d27ca12013-08-08 23:45:55 +000095 // Helper routines to process parts of a DIE.
Eric Christopher0710bfa2013-08-13 01:21:55 +000096private:
Eric Christopher0d27ca12013-08-08 23:45:55 +000097 /// \brief Adds the parent context of \param Die to the hash.
98 void addParentContext(DIE *Die);
Eric Christopher0710bfa2013-08-13 01:21:55 +000099
100 /// \brief Adds the attributes of \param Die to the hash.
101 void addAttributes(DIE *Die);
102
103 /// \brief Computes the full DWARF4 7.27 hash of the DIE.
104 void computeHash(DIE *Die);
105
Eric Christopher0d27ca12013-08-08 23:45:55 +0000106 // Routines that add DIEValues to the hash.
107private:
108 /// \brief Encodes and adds \param Value to the hash as a ULEB128.
109 void addULEB128(uint64_t Value);
110
David Blaikiec0987082013-10-16 23:36:20 +0000111 /// \brief Encodes and adds \param Value to the hash as a SLEB128.
112 void addSLEB128(int64_t Value);
113
Eric Christopher0d27ca12013-08-08 23:45:55 +0000114 /// \brief Adds \param Str to the hash and includes a NULL byte.
115 void addString(StringRef Str);
Eric Christopher0710bfa2013-08-13 01:21:55 +0000116
117 /// \brief Collects the attributes of DIE \param Die into the \param Attrs
118 /// structure.
David Blaikiecbb5c732013-08-14 22:23:05 +0000119 void collectAttributes(DIE *Die, DIEAttrs &Attrs);
Eric Christopher0710bfa2013-08-13 01:21:55 +0000120
121 /// \brief Hashes the attributes in \param Attrs in order.
David Blaikief1545a22013-10-21 22:36:50 +0000122 void hashAttributes(const DIEAttrs &Attrs, dwarf::Tag Tag);
Eric Christopher0710bfa2013-08-13 01:21:55 +0000123
124 /// \brief Hashes an individual attribute.
David Blaikief1545a22013-10-21 22:36:50 +0000125 void hashAttribute(AttrEntry Attr, dwarf::Tag Tag);
Eric Christopher0710bfa2013-08-13 01:21:55 +0000126
Eric Christopher0d27ca12013-08-08 23:45:55 +0000127private:
128 MD5 Hash;
David Blaikie3baa3c32013-10-21 18:59:40 +0000129 DenseMap<DIE*, unsigned> Numbering;
Eric Christopher0d27ca12013-08-08 23:45:55 +0000130};
131}