DIEHash.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //===-- llvm/CodeGen/DIEHash.h - Dwarf Hashing Framework -------*- C++ -*--===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file contains support for DWARF4 hashing of DIEs.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DIEHASH_H
  13. #define LLVM_LIB_CODEGEN_ASMPRINTER_DIEHASH_H
  14. #include "llvm/ADT/DenseMap.h"
  15. #include "llvm/CodeGen/DIE.h"
  16. #include "llvm/Support/MD5.h"
  17. namespace llvm {
  18. class AsmPrinter;
  19. /// An object containing the capability of hashing and adding hash
  20. /// attributes onto a DIE.
  21. class DIEHash {
  22. // Collection of all attributes used in hashing a particular DIE.
  23. struct DIEAttrs {
  24. #define HANDLE_DIE_HASH_ATTR(NAME) DIEValue NAME;
  25. #include "DIEHashAttributes.def"
  26. };
  27. public:
  28. DIEHash(AsmPrinter *A = nullptr, DwarfCompileUnit *CU = nullptr)
  29. : AP(A), CU(CU) {}
  30. /// Computes the CU signature.
  31. uint64_t computeCUSignature(StringRef DWOName, const DIE &Die);
  32. /// Computes the type signature.
  33. uint64_t computeTypeSignature(const DIE &Die);
  34. // Helper routines to process parts of a DIE.
  35. private:
  36. /// Adds the parent context of \param Parent to the hash.
  37. void addParentContext(const DIE &Parent);
  38. /// Adds the attributes of \param Die to the hash.
  39. void addAttributes(const DIE &Die);
  40. /// Computes the full DWARF4 7.27 hash of the DIE.
  41. void computeHash(const DIE &Die);
  42. // Routines that add DIEValues to the hash.
  43. public:
  44. /// Adds \param Value to the hash.
  45. void update(uint8_t Value) { Hash.update(Value); }
  46. /// Encodes and adds \param Value to the hash as a ULEB128.
  47. void addULEB128(uint64_t Value);
  48. /// Encodes and adds \param Value to the hash as a SLEB128.
  49. void addSLEB128(int64_t Value);
  50. void hashRawTypeReference(const DIE &Entry);
  51. private:
  52. /// Adds \param Str to the hash and includes a NULL byte.
  53. void addString(StringRef Str);
  54. /// Collects the attributes of DIE \param Die into the \param Attrs
  55. /// structure.
  56. void collectAttributes(const DIE &Die, DIEAttrs &Attrs);
  57. /// Hashes the attributes in \param Attrs in order.
  58. void hashAttributes(const DIEAttrs &Attrs, dwarf::Tag Tag);
  59. /// Hashes the data in a block like DIEValue, e.g. DW_FORM_block or
  60. /// DW_FORM_exprloc.
  61. void hashBlockData(const DIE::const_value_range &Values);
  62. /// Hashes the contents pointed to in the .debug_loc section.
  63. void hashLocList(const DIELocList &LocList);
  64. /// Hashes an individual attribute.
  65. void hashAttribute(const DIEValue &Value, dwarf::Tag Tag);
  66. /// Hashes an attribute that refers to another DIE.
  67. void hashDIEEntry(dwarf::Attribute Attribute, dwarf::Tag Tag,
  68. const DIE &Entry);
  69. /// Hashes a reference to a named type in such a way that is
  70. /// independent of whether that type is described by a declaration or a
  71. /// definition.
  72. void hashShallowTypeReference(dwarf::Attribute Attribute, const DIE &Entry,
  73. StringRef Name);
  74. /// Hashes a reference to a previously referenced type DIE.
  75. void hashRepeatedTypeReference(dwarf::Attribute Attribute,
  76. unsigned DieNumber);
  77. void hashNestedType(const DIE &Die, StringRef Name);
  78. private:
  79. MD5 Hash;
  80. AsmPrinter *AP;
  81. DwarfCompileUnit *CU;
  82. DenseMap<const DIE *, unsigned> Numbering;
  83. };
  84. }
  85. #endif