DIEHash.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DIEHASH_H
  14. #define LLVM_LIB_CODEGEN_ASMPRINTER_DIEHASH_H
  15. #include "llvm/ADT/DenseMap.h"
  16. #include "llvm/CodeGen/DIE.h"
  17. #include "llvm/Support/MD5.h"
  18. namespace llvm {
  19. class AsmPrinter;
  20. class CompileUnit;
  21. /// \brief An object containing the capability of hashing and adding hash
  22. /// attributes onto a DIE.
  23. class DIEHash {
  24. // Collection of all attributes used in hashing a particular DIE.
  25. struct DIEAttrs {
  26. DIEValue DW_AT_name;
  27. DIEValue DW_AT_accessibility;
  28. DIEValue DW_AT_address_class;
  29. DIEValue DW_AT_allocated;
  30. DIEValue DW_AT_artificial;
  31. DIEValue DW_AT_associated;
  32. DIEValue DW_AT_binary_scale;
  33. DIEValue DW_AT_bit_offset;
  34. DIEValue DW_AT_bit_size;
  35. DIEValue DW_AT_bit_stride;
  36. DIEValue DW_AT_byte_size;
  37. DIEValue DW_AT_byte_stride;
  38. DIEValue DW_AT_const_expr;
  39. DIEValue DW_AT_const_value;
  40. DIEValue DW_AT_containing_type;
  41. DIEValue DW_AT_count;
  42. DIEValue DW_AT_data_bit_offset;
  43. DIEValue DW_AT_data_location;
  44. DIEValue DW_AT_data_member_location;
  45. DIEValue DW_AT_decimal_scale;
  46. DIEValue DW_AT_decimal_sign;
  47. DIEValue DW_AT_default_value;
  48. DIEValue DW_AT_digit_count;
  49. DIEValue DW_AT_discr;
  50. DIEValue DW_AT_discr_list;
  51. DIEValue DW_AT_discr_value;
  52. DIEValue DW_AT_encoding;
  53. DIEValue DW_AT_enum_class;
  54. DIEValue DW_AT_endianity;
  55. DIEValue DW_AT_explicit;
  56. DIEValue DW_AT_is_optional;
  57. DIEValue DW_AT_location;
  58. DIEValue DW_AT_lower_bound;
  59. DIEValue DW_AT_mutable;
  60. DIEValue DW_AT_ordering;
  61. DIEValue DW_AT_picture_string;
  62. DIEValue DW_AT_prototyped;
  63. DIEValue DW_AT_small;
  64. DIEValue DW_AT_segment;
  65. DIEValue DW_AT_string_length;
  66. DIEValue DW_AT_threads_scaled;
  67. DIEValue DW_AT_upper_bound;
  68. DIEValue DW_AT_use_location;
  69. DIEValue DW_AT_use_UTF8;
  70. DIEValue DW_AT_variable_parameter;
  71. DIEValue DW_AT_virtuality;
  72. DIEValue DW_AT_visibility;
  73. DIEValue DW_AT_vtable_elem_location;
  74. DIEValue DW_AT_type;
  75. // Insert any additional ones here...
  76. };
  77. public:
  78. DIEHash(AsmPrinter *A = nullptr) : AP(A) {}
  79. /// \brief Computes the ODR signature.
  80. uint64_t computeDIEODRSignature(const DIE &Die);
  81. /// \brief Computes the CU signature.
  82. uint64_t computeCUSignature(const DIE &Die);
  83. /// \brief Computes the type signature.
  84. uint64_t computeTypeSignature(const DIE &Die);
  85. // Helper routines to process parts of a DIE.
  86. private:
  87. /// \brief Adds the parent context of \param Die to the hash.
  88. void addParentContext(const DIE &Die);
  89. /// \brief Adds the attributes of \param Die to the hash.
  90. void addAttributes(const DIE &Die);
  91. /// \brief Computes the full DWARF4 7.27 hash of the DIE.
  92. void computeHash(const DIE &Die);
  93. // Routines that add DIEValues to the hash.
  94. public:
  95. /// \brief Adds \param Value to the hash.
  96. void update(uint8_t Value) { Hash.update(Value); }
  97. /// \brief Encodes and adds \param Value to the hash as a ULEB128.
  98. void addULEB128(uint64_t Value);
  99. /// \brief Encodes and adds \param Value to the hash as a SLEB128.
  100. void addSLEB128(int64_t Value);
  101. private:
  102. /// \brief Adds \param Str to the hash and includes a NULL byte.
  103. void addString(StringRef Str);
  104. /// \brief Collects the attributes of DIE \param Die into the \param Attrs
  105. /// structure.
  106. void collectAttributes(const DIE &Die, DIEAttrs &Attrs);
  107. /// \brief Hashes the attributes in \param Attrs in order.
  108. void hashAttributes(const DIEAttrs &Attrs, dwarf::Tag Tag);
  109. /// \brief Hashes the data in a block like DIEValue, e.g. DW_FORM_block or
  110. /// DW_FORM_exprloc.
  111. void hashBlockData(const DIE::const_value_range &Values);
  112. /// \brief Hashes the contents pointed to in the .debug_loc section.
  113. void hashLocList(const DIELocList &LocList);
  114. /// \brief Hashes an individual attribute.
  115. void hashAttribute(DIEValue Value, dwarf::Tag Tag);
  116. /// \brief Hashes an attribute that refers to another DIE.
  117. void hashDIEEntry(dwarf::Attribute Attribute, dwarf::Tag Tag,
  118. const DIE &Entry);
  119. /// \brief Hashes a reference to a named type in such a way that is
  120. /// independent of whether that type is described by a declaration or a
  121. /// definition.
  122. void hashShallowTypeReference(dwarf::Attribute Attribute, const DIE &Entry,
  123. StringRef Name);
  124. /// \brief Hashes a reference to a previously referenced type DIE.
  125. void hashRepeatedTypeReference(dwarf::Attribute Attribute,
  126. unsigned DieNumber);
  127. void hashNestedType(const DIE &Die, StringRef Name);
  128. private:
  129. MD5 Hash;
  130. AsmPrinter *AP;
  131. DenseMap<const DIE *, unsigned> Numbering;
  132. };
  133. }
  134. #endif