blob: d83f78f68b48f1959697ec5a7a7f72fd3f54a65d [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
14#include "llvm/Support/MD5.h"
15
16namespace llvm {
17
18class CompileUnit;
19
20/// \brief An object containing the capability of hashing and adding hash
21/// attributes onto a DIE.
22class DIEHash {
Eric Christopher0710bfa2013-08-13 01:21:55 +000023 // The entry for a particular attribute.
24 struct AttrEntry {
25 const DIEValue *Val;
26 const DIEAbbrevData *Desc;
27 };
28
29 // Collection of all attributes used in hashing a particular DIE.
30 struct DIEAttrs {
31 AttrEntry DW_AT_name;
Eric Christopher7ced4fa2013-08-28 00:10:38 +000032 AttrEntry DW_AT_language;
Eric Christopher0710bfa2013-08-13 01:21:55 +000033 };
34
Eric Christopher0d27ca12013-08-08 23:45:55 +000035public:
Eric Christopher0d27ca12013-08-08 23:45:55 +000036 /// \brief Computes the ODR signature
37 uint64_t computeDIEODRSignature(DIE *Die);
38
Eric Christopher0710bfa2013-08-13 01:21:55 +000039 /// \brief Computes the CU signature
40 uint64_t computeCUSignature(DIE *Die);
41
Eric Christopher0d27ca12013-08-08 23:45:55 +000042 // Helper routines to process parts of a DIE.
Eric Christopher0710bfa2013-08-13 01:21:55 +000043private:
Eric Christopher0d27ca12013-08-08 23:45:55 +000044 /// \brief Adds the parent context of \param Die to the hash.
45 void addParentContext(DIE *Die);
Eric Christopher0710bfa2013-08-13 01:21:55 +000046
47 /// \brief Adds the attributes of \param Die to the hash.
48 void addAttributes(DIE *Die);
49
50 /// \brief Computes the full DWARF4 7.27 hash of the DIE.
51 void computeHash(DIE *Die);
52
Eric Christopher0d27ca12013-08-08 23:45:55 +000053 // Routines that add DIEValues to the hash.
54private:
55 /// \brief Encodes and adds \param Value to the hash as a ULEB128.
56 void addULEB128(uint64_t Value);
57
58 /// \brief Adds \param Str to the hash and includes a NULL byte.
59 void addString(StringRef Str);
Eric Christopher0710bfa2013-08-13 01:21:55 +000060
61 /// \brief Collects the attributes of DIE \param Die into the \param Attrs
62 /// structure.
David Blaikiecbb5c732013-08-14 22:23:05 +000063 void collectAttributes(DIE *Die, DIEAttrs &Attrs);
Eric Christopher0710bfa2013-08-13 01:21:55 +000064
65 /// \brief Hashes the attributes in \param Attrs in order.
David Blaikiecbb5c732013-08-14 22:23:05 +000066 void hashAttributes(const DIEAttrs &Attrs);
Eric Christopher0710bfa2013-08-13 01:21:55 +000067
68 /// \brief Hashes an individual attribute.
69 void hashAttribute(AttrEntry Attr);
70
Eric Christopher0d27ca12013-08-08 23:45:55 +000071private:
72 MD5 Hash;
73};
74}