DIEHash.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. class CompileUnit;
  20. /// An object containing the capability of hashing and adding hash
  21. /// attributes onto a DIE.
  22. class DIEHash {
  23. // Collection of all attributes used in hashing a particular DIE.
  24. struct DIEAttrs {
  25. #define HANDLE_DIE_HASH_ATTR(NAME) DIEValue NAME;
  26. #include "DIEHashAttributes.def"
  27. };
  28. public:
  29. DIEHash(AsmPrinter *A = nullptr) : AP(A) {}
  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. private:
  51. /// Adds \param Str to the hash and includes a NULL byte.
  52. void addString(StringRef Str);
  53. /// Collects the attributes of DIE \param Die into the \param Attrs
  54. /// structure.
  55. void collectAttributes(const DIE &Die, DIEAttrs &Attrs);
  56. /// Hashes the attributes in \param Attrs in order.
  57. void hashAttributes(const DIEAttrs &Attrs, dwarf::Tag Tag);
  58. /// Hashes the data in a block like DIEValue, e.g. DW_FORM_block or
  59. /// DW_FORM_exprloc.
  60. void hashBlockData(const DIE::const_value_range &Values);
  61. /// Hashes the contents pointed to in the .debug_loc section.
  62. void hashLocList(const DIELocList &LocList);
  63. /// Hashes an individual attribute.
  64. void hashAttribute(const DIEValue &Value, dwarf::Tag Tag);
  65. /// Hashes an attribute that refers to another DIE.
  66. void hashDIEEntry(dwarf::Attribute Attribute, dwarf::Tag Tag,
  67. const DIE &Entry);
  68. /// Hashes a reference to a named type in such a way that is
  69. /// independent of whether that type is described by a declaration or a
  70. /// definition.
  71. void hashShallowTypeReference(dwarf::Attribute Attribute, const DIE &Entry,
  72. StringRef Name);
  73. /// Hashes a reference to a previously referenced type DIE.
  74. void hashRepeatedTypeReference(dwarf::Attribute Attribute,
  75. unsigned DieNumber);
  76. void hashNestedType(const DIE &Die, StringRef Name);
  77. private:
  78. MD5 Hash;
  79. AsmPrinter *AP;
  80. DenseMap<const DIE *, unsigned> Numbering;
  81. };
  82. }
  83. #endif