blob: 29337ae38a996b699fd50c3b2236690b87fbbc8a [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 {
David Blaikie74fa8032017-05-23 18:27:09 +000031#define HANDLE_DIE_HASH_ATTR(NAME) DIEValue NAME;
32#include "DIEHashAttributes.def"
Eric Christopherd29614f2013-08-13 01:21:55 +000033 };
34
Eric Christopher45731982013-08-08 23:45:55 +000035public:
Craig Topper353eda42014-04-24 06:44:33 +000036 DIEHash(AsmPrinter *A = nullptr) : AP(A) {}
Eric Christopher420569b2014-02-20 02:50:45 +000037
Eric Christopherb86e2ad2013-09-03 21:57:50 +000038 /// \brief Computes the CU signature.
Mehdi Amini96ab48f2017-05-29 06:32:34 +000039 uint64_t computeCUSignature(StringRef DWOName, const DIE &Die);
Eric Christopherd29614f2013-08-13 01:21:55 +000040
Eric Christopher25b7adc2013-09-03 21:57:57 +000041 /// \brief Computes the type signature.
David Blaikie2aee7be2013-10-24 18:29:03 +000042 uint64_t computeTypeSignature(const DIE &Die);
Eric Christopher25b7adc2013-09-03 21:57:57 +000043
Eric Christopher45731982013-08-08 23:45:55 +000044 // Helper routines to process parts of a DIE.
Eric Christopherd29614f2013-08-13 01:21:55 +000045private:
Eric Christopher45731982013-08-08 23:45:55 +000046 /// \brief Adds the parent context of \param Die to the hash.
David Blaikie2aee7be2013-10-24 18:29:03 +000047 void addParentContext(const DIE &Die);
Eric Christopherd29614f2013-08-13 01:21:55 +000048
49 /// \brief Adds the attributes of \param Die to the hash.
David Blaikie2aee7be2013-10-24 18:29:03 +000050 void addAttributes(const DIE &Die);
Eric Christopherd29614f2013-08-13 01:21:55 +000051
52 /// \brief Computes the full DWARF4 7.27 hash of the DIE.
David Blaikie2aee7be2013-10-24 18:29:03 +000053 void computeHash(const DIE &Die);
Eric Christopherd29614f2013-08-13 01:21:55 +000054
Eric Christopher45731982013-08-08 23:45:55 +000055 // Routines that add DIEValues to the hash.
Eric Christopher5c38b652014-03-07 22:40:30 +000056public:
57 /// \brief Adds \param Value to the hash.
58 void update(uint8_t Value) { Hash.update(Value); }
59
Eric Christopher45731982013-08-08 23:45:55 +000060 /// \brief Encodes and adds \param Value to the hash as a ULEB128.
61 void addULEB128(uint64_t Value);
62
David Blaikie6316ca42013-10-16 23:36:20 +000063 /// \brief Encodes and adds \param Value to the hash as a SLEB128.
64 void addSLEB128(int64_t Value);
65
Eric Christopher5c38b652014-03-07 22:40:30 +000066private:
Eric Christopher45731982013-08-08 23:45:55 +000067 /// \brief Adds \param Str to the hash and includes a NULL byte.
68 void addString(StringRef Str);
Eric Christopherd29614f2013-08-13 01:21:55 +000069
70 /// \brief Collects the attributes of DIE \param Die into the \param Attrs
71 /// structure.
David Blaikie2aee7be2013-10-24 18:29:03 +000072 void collectAttributes(const DIE &Die, DIEAttrs &Attrs);
Eric Christopherd29614f2013-08-13 01:21:55 +000073
74 /// \brief Hashes the attributes in \param Attrs in order.
David Blaikie6cf58c82013-10-21 22:36:50 +000075 void hashAttributes(const DIEAttrs &Attrs, dwarf::Tag Tag);
Eric Christopherd29614f2013-08-13 01:21:55 +000076
Eric Christopher420569b2014-02-20 02:50:45 +000077 /// \brief Hashes the data in a block like DIEValue, e.g. DW_FORM_block or
78 /// DW_FORM_exprloc.
Duncan P. N. Exon Smith4fb1f9c2015-06-25 23:46:41 +000079 void hashBlockData(const DIE::const_value_range &Values);
Eric Christopher420569b2014-02-20 02:50:45 +000080
Eric Christopher4f17ee02014-03-08 00:29:41 +000081 /// \brief Hashes the contents pointed to in the .debug_loc section.
82 void hashLocList(const DIELocList &LocList);
83
Eric Christopherd29614f2013-08-13 01:21:55 +000084 /// \brief Hashes an individual attribute.
Benjamin Kramer1afc1de2016-06-17 20:41:14 +000085 void hashAttribute(const DIEValue &Value, dwarf::Tag Tag);
Eric Christopherd29614f2013-08-13 01:21:55 +000086
David Blaikieafcb9652013-10-24 17:51:43 +000087 /// \brief Hashes an attribute that refers to another DIE.
88 void hashDIEEntry(dwarf::Attribute Attribute, dwarf::Tag Tag,
David Blaikie2aee7be2013-10-24 18:29:03 +000089 const DIE &Entry);
David Blaikieafcb9652013-10-24 17:51:43 +000090
91 /// \brief Hashes a reference to a named type in such a way that is
92 /// independent of whether that type is described by a declaration or a
93 /// definition.
David Blaikie2aee7be2013-10-24 18:29:03 +000094 void hashShallowTypeReference(dwarf::Attribute Attribute, const DIE &Entry,
95 StringRef Name);
David Blaikieafcb9652013-10-24 17:51:43 +000096
97 /// \brief Hashes a reference to a previously referenced type DIE.
Eric Christophera07e4f52013-11-19 09:28:34 +000098 void hashRepeatedTypeReference(dwarf::Attribute Attribute,
99 unsigned DieNumber);
David Blaikieafcb9652013-10-24 17:51:43 +0000100
David Blaikie65cc9692013-10-25 18:38:43 +0000101 void hashNestedType(const DIE &Die, StringRef Name);
102
Eric Christopher45731982013-08-08 23:45:55 +0000103private:
104 MD5 Hash;
Eric Christopher420569b2014-02-20 02:50:45 +0000105 AsmPrinter *AP;
David Blaikie2aee7be2013-10-24 18:29:03 +0000106 DenseMap<const DIE *, unsigned> Numbering;
Eric Christopher45731982013-08-08 23:45:55 +0000107};
Alexander Kornienkof00654e2015-06-23 09:49:53 +0000108}
Eric Christopher5c38b652014-03-07 22:40:30 +0000109
110#endif