Path: blob/main/contrib/llvm-project/llvm/lib/CodeGen/AsmPrinter/DIEHash.h
35271 views
//===-- llvm/CodeGen/DIEHash.h - Dwarf Hashing Framework -------*- C++ -*--===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file contains support for DWARF4 hashing of DIEs.9//10//===----------------------------------------------------------------------===//1112#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DIEHASH_H13#define LLVM_LIB_CODEGEN_ASMPRINTER_DIEHASH_H1415#include "llvm/ADT/DenseMap.h"16#include "llvm/CodeGen/DIE.h"17#include "llvm/Support/MD5.h"1819namespace llvm {2021class AsmPrinter;2223/// An object containing the capability of hashing and adding hash24/// attributes onto a DIE.25class DIEHash {26// Collection of all attributes used in hashing a particular DIE.27struct DIEAttrs {28#define HANDLE_DIE_HASH_ATTR(NAME) DIEValue NAME;29#include "DIEHashAttributes.def"30};3132public:33DIEHash(AsmPrinter *A = nullptr, DwarfCompileUnit *CU = nullptr)34: AP(A), CU(CU) {}3536/// Computes the CU signature.37uint64_t computeCUSignature(StringRef DWOName, const DIE &Die);3839/// Computes the type signature.40uint64_t computeTypeSignature(const DIE &Die);4142// Helper routines to process parts of a DIE.43private:44/// Adds the parent context of \param Parent to the hash.45void addParentContext(const DIE &Parent);4647/// Adds the attributes of \param Die to the hash.48void addAttributes(const DIE &Die);4950/// Computes the full DWARF4 7.27 hash of the DIE.51void computeHash(const DIE &Die);5253// Routines that add DIEValues to the hash.54public:55/// Adds \param Value to the hash.56void update(uint8_t Value) { Hash.update(Value); }5758/// Encodes and adds \param Value to the hash as a ULEB128.59void addULEB128(uint64_t Value);6061/// Encodes and adds \param Value to the hash as a SLEB128.62void addSLEB128(int64_t Value);6364void hashRawTypeReference(const DIE &Entry);6566private:67/// Adds \param Str to the hash and includes a NULL byte.68void addString(StringRef Str);6970/// Collects the attributes of DIE \param Die into the \param Attrs71/// structure.72void collectAttributes(const DIE &Die, DIEAttrs &Attrs);7374/// Hashes the attributes in \param Attrs in order.75void hashAttributes(const DIEAttrs &Attrs, dwarf::Tag Tag);7677/// Hashes the data in a block like DIEValue, e.g. DW_FORM_block or78/// DW_FORM_exprloc.79void hashBlockData(const DIE::const_value_range &Values);8081/// Hashes the contents pointed to in the .debug_loc section.82void hashLocList(const DIELocList &LocList);8384/// Hashes an individual attribute.85void hashAttribute(const DIEValue &Value, dwarf::Tag Tag);8687/// Hashes an attribute that refers to another DIE.88void hashDIEEntry(dwarf::Attribute Attribute, dwarf::Tag Tag,89const DIE &Entry);9091/// Hashes a reference to a named type in such a way that is92/// independent of whether that type is described by a declaration or a93/// definition.94void hashShallowTypeReference(dwarf::Attribute Attribute, const DIE &Entry,95StringRef Name);9697/// Hashes a reference to a previously referenced type DIE.98void hashRepeatedTypeReference(dwarf::Attribute Attribute,99unsigned DieNumber);100101void hashNestedType(const DIE &Die, StringRef Name);102103private:104MD5 Hash;105AsmPrinter *AP;106DwarfCompileUnit *CU;107DenseMap<const DIE *, unsigned> Numbering;108};109}110111#endif112113114