[llvm] r189862 - Add a hashing routine that handles hashing types. Add a test for
Eric Christopher
echristo at gmail.com
Tue Sep 3 14:57:57 PDT 2013
Author: echristo
Date: Tue Sep 3 16:57:57 2013
New Revision: 189862
URL: http://llvm.org/viewvc/llvm-project?rev=189862&view=rev
Log:
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.
Added:
llvm/trunk/unittests/CodeGen/
llvm/trunk/unittests/CodeGen/CMakeLists.txt
llvm/trunk/unittests/CodeGen/DIEHashTest.cpp
llvm/trunk/unittests/CodeGen/Makefile
- copied, changed from r189861, llvm/trunk/unittests/Makefile
Modified:
llvm/trunk/lib/CodeGen/AsmPrinter/DIEHash.cpp
llvm/trunk/lib/CodeGen/AsmPrinter/DIEHash.h
llvm/trunk/unittests/CMakeLists.txt
llvm/trunk/unittests/Makefile
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DIEHash.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DIEHash.cpp?rev=189862&r1=189861&r2=189862&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DIEHash.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DIEHash.cpp Tue Sep 3 16:57:57 2013
@@ -422,10 +422,30 @@ uint64_t DIEHash::computeDIEODRSignature
/// 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.
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<support::ulittle64_t *>(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;
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DIEHash.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DIEHash.h?rev=189862&r1=189861&r2=189862&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DIEHash.h (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DIEHash.h Tue Sep 3 16:57:57 2013
@@ -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.
Modified: llvm/trunk/unittests/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/CMakeLists.txt?rev=189862&r1=189861&r2=189862&view=diff
==============================================================================
--- llvm/trunk/unittests/CMakeLists.txt (original)
+++ llvm/trunk/unittests/CMakeLists.txt Tue Sep 3 16:57:57 2013
@@ -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)
Added: llvm/trunk/unittests/CodeGen/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/CodeGen/CMakeLists.txt?rev=189862&view=auto
==============================================================================
--- llvm/trunk/unittests/CodeGen/CMakeLists.txt (added)
+++ llvm/trunk/unittests/CodeGen/CMakeLists.txt Tue Sep 3 16:57:57 2013
@@ -0,0 +1,13 @@
+set(LLVM_LINK_COMPONENTS
+ asmprinter
+ codegen
+ support
+ )
+
+set(DebugInfoSources
+ DIEHashTest.cpp
+ )
+
+add_llvm_unittest(DebugInfoTests
+ ${DebugInfoSources}
+ )
Added: llvm/trunk/unittests/CodeGen/DIEHashTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/CodeGen/DIEHashTest.cpp?rev=189862&view=auto
==============================================================================
--- llvm/trunk/unittests/CodeGen/DIEHashTest.cpp (added)
+++ llvm/trunk/unittests/CodeGen/DIEHashTest.cpp Tue Sep 3 16:57:57 2013
@@ -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;
+}
+}
Copied: llvm/trunk/unittests/CodeGen/Makefile (from r189861, llvm/trunk/unittests/Makefile)
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/CodeGen/Makefile?p2=llvm/trunk/unittests/CodeGen/Makefile&p1=llvm/trunk/unittests/Makefile&r1=189861&r2=189862&rev=189862&view=diff
==============================================================================
--- llvm/trunk/unittests/Makefile (original)
+++ llvm/trunk/unittests/CodeGen/Makefile Tue Sep 3 16:57:57 2013
@@ -1,4 +1,4 @@
-##===- unittests/Makefile ----------------------------------*- Makefile -*-===##
+##===- unittests/DebugInfo/Makefile ------------------------*- Makefile -*-===##
#
# The LLVM Compiler Infrastructure
#
@@ -7,12 +7,10 @@
#
##===----------------------------------------------------------------------===##
-LEVEL = ..
+LEVEL = ../..
+TESTNAME = CodeGen
+LINK_COMPONENTS := asmprinter codegen support
-PARALLEL_DIRS = ADT Analysis Bitcode DebugInfo ExecutionEngine IR Object \
- Option Support Transforms
+include $(LEVEL)/Makefile.config
-include $(LEVEL)/Makefile.common
-
-clean::
- $(Verb) $(RM) -f *Tests
+include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest
Modified: llvm/trunk/unittests/Makefile
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Makefile?rev=189862&r1=189861&r2=189862&view=diff
==============================================================================
--- llvm/trunk/unittests/Makefile (original)
+++ llvm/trunk/unittests/Makefile Tue Sep 3 16:57:57 2013
@@ -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
More information about the llvm-commits
mailing list