diff options
author | Peter Collingbourne <peter@pcc.me.uk> | 2016-06-24 21:21:32 +0000 |
---|---|---|
committer | Peter Collingbourne <peter@pcc.me.uk> | 2016-06-24 21:21:32 +0000 |
commit | dba9146333f6b548bbc08ea61733b9e1a8a9595e (patch) | |
tree | 1e9166b06799cc433b5c97c6e9d5e50b8b9eb452 /unittests | |
parent | 87d5e72f1d1ec87799ea1966eb189931b17c2006 (diff) |
IR: New representation for CFI and virtual call optimization pass metadata.
The bitset metadata currently used in LLVM has a few problems:
1. It has the wrong name. The name "bitset" refers to an implementation
detail of one use of the metadata (i.e. its original use case, CFI).
This makes it harder to understand, as the name makes no sense in the
context of virtual call optimization.
2. It is represented using a global named metadata node, rather than
being directly associated with a global. This makes it harder to
manipulate the metadata when rebuilding global variables, summarise it
as part of ThinLTO and drop unused metadata when associated globals are
dropped. For this reason, CFI does not currently work correctly when
both CFI and vcall opt are enabled, as vcall opt needs to rebuild vtable
globals, and fails to associate metadata with the rebuilt globals. As I
understand it, the same problem could also affect ASan, which rebuilds
globals with a red zone.
This patch solves both of those problems in the following way:
1. Rename the metadata to "type metadata". This new name reflects how
the metadata is currently being used (i.e. to represent type information
for CFI and vtable opt). The new name is reflected in the name for the
associated intrinsic (llvm.type.test) and pass (LowerTypeTests).
2. Attach metadata directly to the globals that it pertains to, rather
than using the "llvm.bitsets" global metadata node as we are doing now.
This is done using the newly introduced capability to attach
metadata to global variables (r271348 and r271358).
See also: http://lists.llvm.org/pipermail/llvm-dev/2016-June/100462.html
Differential Revision: http://reviews.llvm.org/D21053
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273729 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/Transforms/IPO/CMakeLists.txt | 2 | ||||
-rw-r--r-- | unittests/Transforms/IPO/LowerTypeTests.cpp (renamed from unittests/Transforms/IPO/LowerBitSets.cpp) | 12 | ||||
-rw-r--r-- | unittests/Transforms/IPO/WholeProgramDevirt.cpp | 26 |
3 files changed, 20 insertions, 20 deletions
diff --git a/unittests/Transforms/IPO/CMakeLists.txt b/unittests/Transforms/IPO/CMakeLists.txt index 445f70354e7..ee33a5fcd1b 100644 --- a/unittests/Transforms/IPO/CMakeLists.txt +++ b/unittests/Transforms/IPO/CMakeLists.txt @@ -5,6 +5,6 @@ set(LLVM_LINK_COMPONENTS ) add_llvm_unittest(IPOTests - LowerBitSets.cpp + LowerTypeTests.cpp WholeProgramDevirt.cpp ) diff --git a/unittests/Transforms/IPO/LowerBitSets.cpp b/unittests/Transforms/IPO/LowerTypeTests.cpp index d3ee27d7e94..66c9de6bd66 100644 --- a/unittests/Transforms/IPO/LowerBitSets.cpp +++ b/unittests/Transforms/IPO/LowerTypeTests.cpp @@ -1,4 +1,4 @@ -//===- LowerBitSets.cpp - Unit tests for bitset lowering ------------------===// +//===- LowerTypeTests.cpp - Unit tests for type test lowering -------------===// // // The LLVM Compiler Infrastructure // @@ -7,13 +7,13 @@ // //===----------------------------------------------------------------------===// -#include "llvm/Transforms/IPO/LowerBitSets.h" +#include "llvm/Transforms/IPO/LowerTypeTests.h" #include "gtest/gtest.h" using namespace llvm; -using namespace lowerbitsets; +using namespace lowertypetests; -TEST(LowerBitSets, BitSetBuilder) { +TEST(LowerTypeTests, BitSetBuilder) { struct { std::vector<uint64_t> Offsets; std::set<uint64_t> Bits; @@ -80,7 +80,7 @@ TEST(LowerBitSets, BitSetBuilder) { } } -TEST(LowerBitSets, GlobalLayoutBuilder) { +TEST(LowerTypeTests, GlobalLayoutBuilder) { struct { uint64_t NumObjects; std::vector<std::set<uint64_t>> Fragments; @@ -107,7 +107,7 @@ TEST(LowerBitSets, GlobalLayoutBuilder) { } } -TEST(LowerBitSets, ByteArrayBuilder) { +TEST(LowerTypeTests, ByteArrayBuilder) { struct BABAlloc { std::set<uint64_t> Bits; uint64_t BitSize; diff --git a/unittests/Transforms/IPO/WholeProgramDevirt.cpp b/unittests/Transforms/IPO/WholeProgramDevirt.cpp index 794863b0a91..7e7a6bf4596 100644 --- a/unittests/Transforms/IPO/WholeProgramDevirt.cpp +++ b/unittests/Transforms/IPO/WholeProgramDevirt.cpp @@ -25,11 +25,11 @@ TEST(WholeProgramDevirt, findLowestOffset) { VT2.Before.BytesUsed = {1 << 1}; VT2.After.BytesUsed = {1 << 0}; - BitSetInfo BS1{&VT1, 0}; - BitSetInfo BS2{&VT2, 0}; + TypeMemberInfo TM1{&VT1, 0}; + TypeMemberInfo TM2{&VT2, 0}; VirtualCallTarget Targets[] = { - {&BS1, /*IsBigEndian=*/false}, - {&BS2, /*IsBigEndian=*/false}, + {&TM1, /*IsBigEndian=*/false}, + {&TM2, /*IsBigEndian=*/false}, }; EXPECT_EQ(2ull, findLowestOffset(Targets, /*IsAfter=*/false, 1)); @@ -38,15 +38,15 @@ TEST(WholeProgramDevirt, findLowestOffset) { EXPECT_EQ(8ull, findLowestOffset(Targets, /*IsAfter=*/false, 8)); EXPECT_EQ(72ull, findLowestOffset(Targets, /*IsAfter=*/true, 8)); - BS1.Offset = 4; + TM1.Offset = 4; EXPECT_EQ(33ull, findLowestOffset(Targets, /*IsAfter=*/false, 1)); EXPECT_EQ(65ull, findLowestOffset(Targets, /*IsAfter=*/true, 1)); EXPECT_EQ(40ull, findLowestOffset(Targets, /*IsAfter=*/false, 8)); EXPECT_EQ(72ull, findLowestOffset(Targets, /*IsAfter=*/true, 8)); - BS1.Offset = 8; - BS2.Offset = 8; + TM1.Offset = 8; + TM2.Offset = 8; EXPECT_EQ(66ull, findLowestOffset(Targets, /*IsAfter=*/false, 1)); EXPECT_EQ(2ull, findLowestOffset(Targets, /*IsAfter=*/true, 1)); @@ -66,15 +66,15 @@ TEST(WholeProgramDevirt, setReturnValues) { VTableBits VT2; VT2.ObjectSize = 8; - BitSetInfo BS1{&VT1, 0}; - BitSetInfo BS2{&VT2, 0}; + TypeMemberInfo TM1{&VT1, 0}; + TypeMemberInfo TM2{&VT2, 0}; VirtualCallTarget Targets[] = { - {&BS1, /*IsBigEndian=*/false}, - {&BS2, /*IsBigEndian=*/false}, + {&TM1, /*IsBigEndian=*/false}, + {&TM2, /*IsBigEndian=*/false}, }; - BS1.Offset = 4; - BS2.Offset = 4; + TM1.Offset = 4; + TM2.Offset = 4; int64_t OffsetByte; uint64_t OffsetBit; |