LLVM API Documentation

DIEHash.h
Go to the documentation of this file.
00001 //===-- llvm/CodeGen/DIEHash.h - Dwarf Hashing Framework -------*- C++ -*--===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file contains support for DWARF4 hashing of DIEs.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DIEHASH_H
00015 #define LLVM_LIB_CODEGEN_ASMPRINTER_DIEHASH_H
00016 
00017 #include "DIE.h"
00018 #include "llvm/ADT/DenseMap.h"
00019 #include "llvm/Support/MD5.h"
00020 
00021 namespace llvm {
00022 
00023 class AsmPrinter;
00024 class CompileUnit;
00025 
00026 /// \brief An object containing the capability of hashing and adding hash
00027 /// attributes onto a DIE.
00028 class DIEHash {
00029 
00030   // The entry for a particular attribute.
00031   struct AttrEntry {
00032     const DIEValue *Val;
00033     const DIEAbbrevData *Desc;
00034   };
00035 
00036   // Collection of all attributes used in hashing a particular DIE.
00037   struct DIEAttrs {
00038     AttrEntry DW_AT_name;
00039     AttrEntry DW_AT_accessibility;
00040     AttrEntry DW_AT_address_class;
00041     AttrEntry DW_AT_allocated;
00042     AttrEntry DW_AT_artificial;
00043     AttrEntry DW_AT_associated;
00044     AttrEntry DW_AT_binary_scale;
00045     AttrEntry DW_AT_bit_offset;
00046     AttrEntry DW_AT_bit_size;
00047     AttrEntry DW_AT_bit_stride;
00048     AttrEntry DW_AT_byte_size;
00049     AttrEntry DW_AT_byte_stride;
00050     AttrEntry DW_AT_const_expr;
00051     AttrEntry DW_AT_const_value;
00052     AttrEntry DW_AT_containing_type;
00053     AttrEntry DW_AT_count;
00054     AttrEntry DW_AT_data_bit_offset;
00055     AttrEntry DW_AT_data_location;
00056     AttrEntry DW_AT_data_member_location;
00057     AttrEntry DW_AT_decimal_scale;
00058     AttrEntry DW_AT_decimal_sign;
00059     AttrEntry DW_AT_default_value;
00060     AttrEntry DW_AT_digit_count;
00061     AttrEntry DW_AT_discr;
00062     AttrEntry DW_AT_discr_list;
00063     AttrEntry DW_AT_discr_value;
00064     AttrEntry DW_AT_encoding;
00065     AttrEntry DW_AT_enum_class;
00066     AttrEntry DW_AT_endianity;
00067     AttrEntry DW_AT_explicit;
00068     AttrEntry DW_AT_is_optional;
00069     AttrEntry DW_AT_location;
00070     AttrEntry DW_AT_lower_bound;
00071     AttrEntry DW_AT_mutable;
00072     AttrEntry DW_AT_ordering;
00073     AttrEntry DW_AT_picture_string;
00074     AttrEntry DW_AT_prototyped;
00075     AttrEntry DW_AT_small;
00076     AttrEntry DW_AT_segment;
00077     AttrEntry DW_AT_string_length;
00078     AttrEntry DW_AT_threads_scaled;
00079     AttrEntry DW_AT_upper_bound;
00080     AttrEntry DW_AT_use_location;
00081     AttrEntry DW_AT_use_UTF8;
00082     AttrEntry DW_AT_variable_parameter;
00083     AttrEntry DW_AT_virtuality;
00084     AttrEntry DW_AT_visibility;
00085     AttrEntry DW_AT_vtable_elem_location;
00086     AttrEntry DW_AT_type;
00087 
00088     // Insert any additional ones here...
00089   };
00090 
00091 public:
00092   DIEHash(AsmPrinter *A = nullptr) : AP(A) {}
00093 
00094   /// \brief Computes the ODR signature.
00095   uint64_t computeDIEODRSignature(const DIE &Die);
00096 
00097   /// \brief Computes the CU signature.
00098   uint64_t computeCUSignature(const DIE &Die);
00099 
00100   /// \brief Computes the type signature.
00101   uint64_t computeTypeSignature(const DIE &Die);
00102 
00103   // Helper routines to process parts of a DIE.
00104 private:
00105   /// \brief Adds the parent context of \param Die to the hash.
00106   void addParentContext(const DIE &Die);
00107 
00108   /// \brief Adds the attributes of \param Die to the hash.
00109   void addAttributes(const DIE &Die);
00110 
00111   /// \brief Computes the full DWARF4 7.27 hash of the DIE.
00112   void computeHash(const DIE &Die);
00113 
00114   // Routines that add DIEValues to the hash.
00115 public:
00116   /// \brief Adds \param Value to the hash.
00117   void update(uint8_t Value) { Hash.update(Value); }
00118 
00119   /// \brief Encodes and adds \param Value to the hash as a ULEB128.
00120   void addULEB128(uint64_t Value);
00121 
00122   /// \brief Encodes and adds \param Value to the hash as a SLEB128.
00123   void addSLEB128(int64_t Value);
00124 
00125 private:
00126   /// \brief Adds \param Str to the hash and includes a NULL byte.
00127   void addString(StringRef Str);
00128 
00129   /// \brief Collects the attributes of DIE \param Die into the \param Attrs
00130   /// structure.
00131   void collectAttributes(const DIE &Die, DIEAttrs &Attrs);
00132 
00133   /// \brief Hashes the attributes in \param Attrs in order.
00134   void hashAttributes(const DIEAttrs &Attrs, dwarf::Tag Tag);
00135 
00136   /// \brief Hashes the data in a block like DIEValue, e.g. DW_FORM_block or
00137   /// DW_FORM_exprloc.
00138   void hashBlockData(const SmallVectorImpl<DIEValue *> &Values);
00139 
00140   /// \brief Hashes the contents pointed to in the .debug_loc section.
00141   void hashLocList(const DIELocList &LocList);
00142 
00143   /// \brief Hashes an individual attribute.
00144   void hashAttribute(AttrEntry Attr, dwarf::Tag Tag);
00145 
00146   /// \brief Hashes an attribute that refers to another DIE.
00147   void hashDIEEntry(dwarf::Attribute Attribute, dwarf::Tag Tag,
00148                     const DIE &Entry);
00149 
00150   /// \brief Hashes a reference to a named type in such a way that is
00151   /// independent of whether that type is described by a declaration or a
00152   /// definition.
00153   void hashShallowTypeReference(dwarf::Attribute Attribute, const DIE &Entry,
00154                                 StringRef Name);
00155 
00156   /// \brief Hashes a reference to a previously referenced type DIE.
00157   void hashRepeatedTypeReference(dwarf::Attribute Attribute,
00158                                  unsigned DieNumber);
00159 
00160   void hashNestedType(const DIE &Die, StringRef Name);
00161 
00162 private:
00163   MD5 Hash;
00164   AsmPrinter *AP;
00165   DenseMap<const DIE *, unsigned> Numbering;
00166 };
00167 }
00168 
00169 #endif