Eric Christopher | 4573198 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 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 | |
Benjamin Kramer | a7c40ef | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 14 | #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DIEHASH_H |
| 15 | #define LLVM_LIB_CODEGEN_ASMPRINTER_DIEHASH_H |
Eric Christopher | 5c38b65 | 2014-03-07 22:40:30 +0000 | [diff] [blame] | 16 | |
David Blaikie | 980d499 | 2013-10-21 18:59:40 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/DenseMap.h" |
Chandler Carruth | d990388 | 2015-01-14 11:23:27 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/DIE.h" |
Eric Christopher | 4573198 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 19 | #include "llvm/Support/MD5.h" |
| 20 | |
| 21 | namespace llvm { |
| 22 | |
Eric Christopher | 420569b | 2014-02-20 02:50:45 +0000 | [diff] [blame] | 23 | class AsmPrinter; |
Eric Christopher | 4573198 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 24 | class CompileUnit; |
| 25 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 26 | /// An object containing the capability of hashing and adding hash |
Eric Christopher | 4573198 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 27 | /// attributes onto a DIE. |
Benjamin Kramer | 079b96e | 2013-09-11 18:05:11 +0000 | [diff] [blame] | 28 | class DIEHash { |
Eric Christopher | d29614f | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 29 | // Collection of all attributes used in hashing a particular DIE. |
| 30 | struct DIEAttrs { |
David Blaikie | 74fa803 | 2017-05-23 18:27:09 +0000 | [diff] [blame] | 31 | #define HANDLE_DIE_HASH_ATTR(NAME) DIEValue NAME; |
| 32 | #include "DIEHashAttributes.def" |
Eric Christopher | d29614f | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 33 | }; |
| 34 | |
Eric Christopher | 4573198 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 35 | public: |
Craig Topper | 353eda4 | 2014-04-24 06:44:33 +0000 | [diff] [blame] | 36 | DIEHash(AsmPrinter *A = nullptr) : AP(A) {} |
Eric Christopher | 420569b | 2014-02-20 02:50:45 +0000 | [diff] [blame] | 37 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 38 | /// Computes the CU signature. |
Mehdi Amini | 96ab48f | 2017-05-29 06:32:34 +0000 | [diff] [blame] | 39 | uint64_t computeCUSignature(StringRef DWOName, const DIE &Die); |
Eric Christopher | d29614f | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 40 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 41 | /// Computes the type signature. |
David Blaikie | 2aee7be | 2013-10-24 18:29:03 +0000 | [diff] [blame] | 42 | uint64_t computeTypeSignature(const DIE &Die); |
Eric Christopher | 25b7adc | 2013-09-03 21:57:57 +0000 | [diff] [blame] | 43 | |
Eric Christopher | 4573198 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 44 | // Helper routines to process parts of a DIE. |
Eric Christopher | d29614f | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 45 | private: |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 46 | /// Adds the parent context of \param Die to the hash. |
David Blaikie | 2aee7be | 2013-10-24 18:29:03 +0000 | [diff] [blame] | 47 | void addParentContext(const DIE &Die); |
Eric Christopher | d29614f | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 48 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 49 | /// Adds the attributes of \param Die to the hash. |
David Blaikie | 2aee7be | 2013-10-24 18:29:03 +0000 | [diff] [blame] | 50 | void addAttributes(const DIE &Die); |
Eric Christopher | d29614f | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 51 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 52 | /// Computes the full DWARF4 7.27 hash of the DIE. |
David Blaikie | 2aee7be | 2013-10-24 18:29:03 +0000 | [diff] [blame] | 53 | void computeHash(const DIE &Die); |
Eric Christopher | d29614f | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 54 | |
Eric Christopher | 4573198 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 55 | // Routines that add DIEValues to the hash. |
Eric Christopher | 5c38b65 | 2014-03-07 22:40:30 +0000 | [diff] [blame] | 56 | public: |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 57 | /// Adds \param Value to the hash. |
Eric Christopher | 5c38b65 | 2014-03-07 22:40:30 +0000 | [diff] [blame] | 58 | void update(uint8_t Value) { Hash.update(Value); } |
| 59 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 60 | /// Encodes and adds \param Value to the hash as a ULEB128. |
Eric Christopher | 4573198 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 61 | void addULEB128(uint64_t Value); |
| 62 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 63 | /// Encodes and adds \param Value to the hash as a SLEB128. |
David Blaikie | 6316ca4 | 2013-10-16 23:36:20 +0000 | [diff] [blame] | 64 | void addSLEB128(int64_t Value); |
| 65 | |
Eric Christopher | 5c38b65 | 2014-03-07 22:40:30 +0000 | [diff] [blame] | 66 | private: |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 67 | /// Adds \param Str to the hash and includes a NULL byte. |
Eric Christopher | 4573198 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 68 | void addString(StringRef Str); |
Eric Christopher | d29614f | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 69 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 70 | /// Collects the attributes of DIE \param Die into the \param Attrs |
Eric Christopher | d29614f | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 71 | /// structure. |
David Blaikie | 2aee7be | 2013-10-24 18:29:03 +0000 | [diff] [blame] | 72 | void collectAttributes(const DIE &Die, DIEAttrs &Attrs); |
Eric Christopher | d29614f | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 73 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 74 | /// Hashes the attributes in \param Attrs in order. |
David Blaikie | 6cf58c8 | 2013-10-21 22:36:50 +0000 | [diff] [blame] | 75 | void hashAttributes(const DIEAttrs &Attrs, dwarf::Tag Tag); |
Eric Christopher | d29614f | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 76 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 77 | /// Hashes the data in a block like DIEValue, e.g. DW_FORM_block or |
Eric Christopher | 420569b | 2014-02-20 02:50:45 +0000 | [diff] [blame] | 78 | /// DW_FORM_exprloc. |
Duncan P. N. Exon Smith | 4fb1f9c | 2015-06-25 23:46:41 +0000 | [diff] [blame] | 79 | void hashBlockData(const DIE::const_value_range &Values); |
Eric Christopher | 420569b | 2014-02-20 02:50:45 +0000 | [diff] [blame] | 80 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 81 | /// Hashes the contents pointed to in the .debug_loc section. |
Eric Christopher | 4f17ee0 | 2014-03-08 00:29:41 +0000 | [diff] [blame] | 82 | void hashLocList(const DIELocList &LocList); |
| 83 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 84 | /// Hashes an individual attribute. |
Benjamin Kramer | 1afc1de | 2016-06-17 20:41:14 +0000 | [diff] [blame] | 85 | void hashAttribute(const DIEValue &Value, dwarf::Tag Tag); |
Eric Christopher | d29614f | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 86 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 87 | /// Hashes an attribute that refers to another DIE. |
David Blaikie | afcb965 | 2013-10-24 17:51:43 +0000 | [diff] [blame] | 88 | void hashDIEEntry(dwarf::Attribute Attribute, dwarf::Tag Tag, |
David Blaikie | 2aee7be | 2013-10-24 18:29:03 +0000 | [diff] [blame] | 89 | const DIE &Entry); |
David Blaikie | afcb965 | 2013-10-24 17:51:43 +0000 | [diff] [blame] | 90 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 91 | /// Hashes a reference to a named type in such a way that is |
David Blaikie | afcb965 | 2013-10-24 17:51:43 +0000 | [diff] [blame] | 92 | /// independent of whether that type is described by a declaration or a |
| 93 | /// definition. |
David Blaikie | 2aee7be | 2013-10-24 18:29:03 +0000 | [diff] [blame] | 94 | void hashShallowTypeReference(dwarf::Attribute Attribute, const DIE &Entry, |
| 95 | StringRef Name); |
David Blaikie | afcb965 | 2013-10-24 17:51:43 +0000 | [diff] [blame] | 96 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 97 | /// Hashes a reference to a previously referenced type DIE. |
Eric Christopher | a07e4f5 | 2013-11-19 09:28:34 +0000 | [diff] [blame] | 98 | void hashRepeatedTypeReference(dwarf::Attribute Attribute, |
| 99 | unsigned DieNumber); |
David Blaikie | afcb965 | 2013-10-24 17:51:43 +0000 | [diff] [blame] | 100 | |
David Blaikie | 65cc969 | 2013-10-25 18:38:43 +0000 | [diff] [blame] | 101 | void hashNestedType(const DIE &Die, StringRef Name); |
| 102 | |
Eric Christopher | 4573198 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 103 | private: |
| 104 | MD5 Hash; |
Eric Christopher | 420569b | 2014-02-20 02:50:45 +0000 | [diff] [blame] | 105 | AsmPrinter *AP; |
David Blaikie | 2aee7be | 2013-10-24 18:29:03 +0000 | [diff] [blame] | 106 | DenseMap<const DIE *, unsigned> Numbering; |
Eric Christopher | 4573198 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 107 | }; |
Alexander Kornienko | f00654e | 2015-06-23 09:49:53 +0000 | [diff] [blame] | 108 | } |
Eric Christopher | 5c38b65 | 2014-03-07 22:40:30 +0000 | [diff] [blame] | 109 | |
| 110 | #endif |