Eric Christopher | 0d27ca1 | 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 | |
| 14 | #include "llvm/Support/MD5.h" |
| 15 | |
| 16 | namespace llvm { |
| 17 | |
| 18 | class CompileUnit; |
| 19 | |
| 20 | /// \brief An object containing the capability of hashing and adding hash |
| 21 | /// attributes onto a DIE. |
| 22 | class DIEHash { |
Eric Christopher | 0710bfa | 2013-08-13 01:21:55 +0000 | [diff] [blame^] | 23 | // 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; |
| 32 | }; |
| 33 | |
Eric Christopher | 0d27ca1 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 34 | public: |
Eric Christopher | 0d27ca1 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 35 | /// \brief Computes the ODR signature |
| 36 | uint64_t computeDIEODRSignature(DIE *Die); |
| 37 | |
Eric Christopher | 0710bfa | 2013-08-13 01:21:55 +0000 | [diff] [blame^] | 38 | /// \brief Computes the CU signature |
| 39 | uint64_t computeCUSignature(DIE *Die); |
| 40 | |
Eric Christopher | 0d27ca1 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 41 | // Helper routines to process parts of a DIE. |
Eric Christopher | 0710bfa | 2013-08-13 01:21:55 +0000 | [diff] [blame^] | 42 | private: |
Eric Christopher | 0d27ca1 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 43 | /// \brief Adds the parent context of \param Die to the hash. |
| 44 | void addParentContext(DIE *Die); |
Eric Christopher | 0710bfa | 2013-08-13 01:21:55 +0000 | [diff] [blame^] | 45 | |
| 46 | /// \brief Adds the attributes of \param Die to the hash. |
| 47 | void addAttributes(DIE *Die); |
| 48 | |
| 49 | /// \brief Computes the full DWARF4 7.27 hash of the DIE. |
| 50 | void computeHash(DIE *Die); |
| 51 | |
Eric Christopher | 0d27ca1 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 52 | // Routines that add DIEValues to the hash. |
| 53 | private: |
| 54 | /// \brief Encodes and adds \param Value to the hash as a ULEB128. |
| 55 | void addULEB128(uint64_t Value); |
| 56 | |
| 57 | /// \brief Adds \param Str to the hash and includes a NULL byte. |
| 58 | void addString(StringRef Str); |
Eric Christopher | 0710bfa | 2013-08-13 01:21:55 +0000 | [diff] [blame^] | 59 | |
| 60 | /// \brief Collects the attributes of DIE \param Die into the \param Attrs |
| 61 | /// structure. |
| 62 | void collectAttributes(DIE *Die, DIEAttrs Attrs); |
| 63 | |
| 64 | /// \brief Hashes the attributes in \param Attrs in order. |
| 65 | void hashAttributes(DIEAttrs Attrs); |
| 66 | |
| 67 | /// \brief Hashes an individual attribute. |
| 68 | void hashAttribute(AttrEntry Attr); |
| 69 | |
Eric Christopher | 0d27ca1 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 70 | private: |
| 71 | MD5 Hash; |
| 72 | }; |
| 73 | } |