blob: 85f2fea937facb5179eb1fdf72d6ec4db367bd97 [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
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000026/// An object containing the capability of hashing and adding hash
Eric Christopher45731982013-08-08 23:45:55 +000027/// 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
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000038 /// 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
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000041 /// 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:
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000046 /// 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
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000049 /// 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
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000052 /// 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:
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000057 /// Adds \param Value to the hash.
Eric Christopher5c38b652014-03-07 22:40:30 +000058 void update(uint8_t Value) { Hash.update(Value); }
59
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000060 /// Encodes and adds \param Value to the hash as a ULEB128.
Eric Christopher45731982013-08-08 23:45:55 +000061 void addULEB128(uint64_t Value);
62
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000063 /// Encodes and adds \param Value to the hash as a SLEB128.
David Blaikie6316ca42013-10-16 23:36:20 +000064 void addSLEB128(int64_t Value);
65
Eric Christopher5c38b652014-03-07 22:40:30 +000066private:
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000067 /// Adds \param Str to the hash and includes a NULL byte.
Eric Christopher45731982013-08-08 23:45:55 +000068 void addString(StringRef Str);
Eric Christopherd29614f2013-08-13 01:21:55 +000069
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000070 /// Collects the attributes of DIE \param Die into the \param Attrs
Eric Christopherd29614f2013-08-13 01:21:55 +000071 /// structure.
David Blaikie2aee7be2013-10-24 18:29:03 +000072 void collectAttributes(const DIE &Die, DIEAttrs &Attrs);
Eric Christopherd29614f2013-08-13 01:21:55 +000073
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000074 /// 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
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000077 /// Hashes the data in a block like DIEValue, e.g. DW_FORM_block or
Eric Christopher420569b2014-02-20 02:50:45 +000078 /// 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
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000081 /// Hashes the contents pointed to in the .debug_loc section.
Eric Christopher4f17ee02014-03-08 00:29:41 +000082 void hashLocList(const DIELocList &LocList);
83
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000084 /// 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
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000087 /// Hashes an attribute that refers to another DIE.
David Blaikieafcb9652013-10-24 17:51:43 +000088 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
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000091 /// Hashes a reference to a named type in such a way that is
David Blaikieafcb9652013-10-24 17:51:43 +000092 /// 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
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000097 /// 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