From 800a8761285a239bb82f7d1883a8398815cd2d8f Mon Sep 17 00:00:00 2001 From: Eric Christopher Date: Tue, 3 Sep 2013 21:57:57 +0000 Subject: Add a hashing routine that handles hashing types. Add a test for hashing the contents of DW_FORM_data1 on top of a type with attributes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@189862 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/AsmPrinter/DIEHash.cpp | 20 ++++++++++++++++++++ lib/CodeGen/AsmPrinter/DIEHash.h | 3 +++ unittests/CMakeLists.txt | 1 + unittests/CodeGen/CMakeLists.txt | 13 +++++++++++++ unittests/CodeGen/DIEHashTest.cpp | 29 +++++++++++++++++++++++++++++ unittests/CodeGen/Makefile | 16 ++++++++++++++++ unittests/Makefile | 4 ++-- 7 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 unittests/CodeGen/CMakeLists.txt create mode 100644 unittests/CodeGen/DIEHashTest.cpp create mode 100644 unittests/CodeGen/Makefile diff --git a/lib/CodeGen/AsmPrinter/DIEHash.cpp b/lib/CodeGen/AsmPrinter/DIEHash.cpp index 1581c9682d..519c8a0068 100644 --- a/lib/CodeGen/AsmPrinter/DIEHash.cpp +++ b/lib/CodeGen/AsmPrinter/DIEHash.cpp @@ -422,6 +422,7 @@ uint64_t DIEHash::computeDIEODRSignature(DIE *Die) { /// This is based on the type signature computation given in section 7.27 of the /// DWARF4 standard. It is an md5 hash of the flattened description of the DIE /// with the inclusion of the full CU and all top level CU entities. +// TODO: Initialize the type chain at 0 instead of 1 for CU signatures. uint64_t DIEHash::computeCUSignature(DIE *Die) { // Hash the DIE. @@ -436,3 +437,22 @@ uint64_t DIEHash::computeCUSignature(DIE *Die) { // appropriately. return *reinterpret_cast(Result + 8); } + +/// This is based on the type signature computation given in section 7.27 of the +/// DWARF4 standard. It is an md5 hash of the flattened description of the DIE +/// with the inclusion of additional forms not specifically called out in the +/// standard. +uint64_t DIEHash::computeTypeSignature(DIE *Die) { + + // Hash the DIE. + computeHash(Die); + + // Now return the result. + MD5::MD5Result Result; + Hash.final(Result); + + // ... take the least significant 8 bytes and return those. Our MD5 + // implementation always returns its results in little endian, swap bytes + // appropriately. + return *reinterpret_cast(Result + 8); +} diff --git a/lib/CodeGen/AsmPrinter/DIEHash.h b/lib/CodeGen/AsmPrinter/DIEHash.h index f98b56dd73..b792aeab6c 100644 --- a/lib/CodeGen/AsmPrinter/DIEHash.h +++ b/lib/CodeGen/AsmPrinter/DIEHash.h @@ -87,6 +87,9 @@ public: /// \brief Computes the CU signature. uint64_t computeCUSignature(DIE *Die); + /// \brief Computes the type signature. + uint64_t computeTypeSignature(DIE *Die); + // Helper routines to process parts of a DIE. private: /// \brief Adds the parent context of \param Die to the hash. diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt index bbf571af5d..3bfe9c0aff 100644 --- a/unittests/CMakeLists.txt +++ b/unittests/CMakeLists.txt @@ -8,6 +8,7 @@ endfunction() add_subdirectory(ADT) add_subdirectory(Analysis) add_subdirectory(Bitcode) +add_subdirectory(CodeGen) add_subdirectory(DebugInfo) add_subdirectory(ExecutionEngine) add_subdirectory(IR) diff --git a/unittests/CodeGen/CMakeLists.txt b/unittests/CodeGen/CMakeLists.txt new file mode 100644 index 0000000000..5f5c90a00d --- /dev/null +++ b/unittests/CodeGen/CMakeLists.txt @@ -0,0 +1,13 @@ +set(LLVM_LINK_COMPONENTS + asmprinter + codegen + support + ) + +set(DebugInfoSources + DIEHashTest.cpp + ) + +add_llvm_unittest(DebugInfoTests + ${DebugInfoSources} + ) diff --git a/unittests/CodeGen/DIEHashTest.cpp b/unittests/CodeGen/DIEHashTest.cpp new file mode 100644 index 0000000000..54dc4ee5d7 --- /dev/null +++ b/unittests/CodeGen/DIEHashTest.cpp @@ -0,0 +1,29 @@ +//===- llvm/unittest/DebugInfo/DWARFFormValueTest.cpp ---------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "../lib/CodeGen/AsmPrinter/DIE.h" +#include "../lib/CodeGen/AsmPrinter/DIEHash.h" +#include "llvm/Support/Dwarf.h" +#include "llvm/Support/Debug.h" +#include "llvm/Support/Format.h" +#include "gtest/gtest.h" + +namespace { + +using namespace llvm; +TEST(DIEHashData1Test, DIEHash) { + DIEHash Hash; + DIE *Die = new DIE(dwarf::DW_TAG_base_type); + DIEValue *Size = new DIEInteger(4); + Die->addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Size); + uint64_t MD5Res = Hash.computeTypeSignature(Die); + ASSERT_TRUE(MD5Res == 0x540e9ff30ade3e4a); + delete Die; +} +} diff --git a/unittests/CodeGen/Makefile b/unittests/CodeGen/Makefile new file mode 100644 index 0000000000..4f07017c29 --- /dev/null +++ b/unittests/CodeGen/Makefile @@ -0,0 +1,16 @@ +##===- unittests/DebugInfo/Makefile ------------------------*- Makefile -*-===## +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## + +LEVEL = ../.. +TESTNAME = CodeGen +LINK_COMPONENTS := asmprinter codegen support + +include $(LEVEL)/Makefile.config + +include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest diff --git a/unittests/Makefile b/unittests/Makefile index 36b82da9e6..4ba1179365 100644 --- a/unittests/Makefile +++ b/unittests/Makefile @@ -9,8 +9,8 @@ LEVEL = .. -PARALLEL_DIRS = ADT Analysis Bitcode DebugInfo ExecutionEngine IR Object \ - Option Support Transforms +PARALLEL_DIRS = ADT Analysis Bitcode CodeGen DebugInfo ExecutionEngine IR \ + Object Option Support Transforms include $(LEVEL)/Makefile.common -- cgit v1.2.3