mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-08 06:32:24 +00:00
5a81e14385
This patch introduces a new mechanism that allows IR modules to co-operatively build pointer sets corresponding to addresses within a given set of globals. One particular use case for this is to allow a C++ program to efficiently verify (at each call site) that a vtable pointer is in the set of valid vtable pointers for the class or its derived classes. One way of doing this is for a toolchain component to build, for each class, a bit set that maps to the memory region allocated for the vtables, such that each 1 bit in the bit set maps to a valid vtable for that class, and lay out the vtables next to each other, to minimize the total size of the bit sets. The patch introduces a metadata format for representing pointer sets, an '@llvm.bitset.test' intrinsic and an LTO lowering pass that lays out the globals and builds the bitsets, and documents the new feature. Differential Revision: http://reviews.llvm.org/D7288 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@230054 91177308-0d34-0410-b5e6-96231b3b80d8
65 lines
1.8 KiB
C++
65 lines
1.8 KiB
C++
//===- LowerBitSets.cpp - Unit tests for bitset lowering ------------------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/Transforms/IPO/LowerBitSets.h"
|
|
#include "gtest/gtest.h"
|
|
|
|
using namespace llvm;
|
|
|
|
TEST(LowerBitSets, BitSetBuilder) {
|
|
struct {
|
|
std::vector<uint64_t> Offsets;
|
|
std::vector<uint8_t> Bits;
|
|
uint64_t ByteOffset;
|
|
uint64_t BitSize;
|
|
unsigned AlignLog2;
|
|
bool IsSingleOffset;
|
|
} BSBTests[] = {
|
|
{{}, {0}, 0, 1, 0, false},
|
|
{{0}, {1}, 0, 1, 0, true},
|
|
{{4}, {1}, 4, 1, 0, true},
|
|
{{37}, {1}, 37, 1, 0, true},
|
|
{{0, 1}, {3}, 0, 2, 0, false},
|
|
{{0, 4}, {3}, 0, 2, 2, false},
|
|
{{0, uint64_t(1) << 33}, {3}, 0, 2, 33, false},
|
|
{{3, 7}, {3}, 3, 2, 2, false},
|
|
{{0, 1, 7}, {131}, 0, 8, 0, false},
|
|
{{0, 2, 14}, {131}, 0, 8, 1, false},
|
|
{{0, 1, 8}, {3, 1}, 0, 9, 0, false},
|
|
{{0, 2, 16}, {3, 1}, 0, 9, 1, false},
|
|
};
|
|
|
|
for (auto &&T : BSBTests) {
|
|
BitSetBuilder BSB;
|
|
for (auto Offset : T.Offsets)
|
|
BSB.addOffset(Offset);
|
|
|
|
BitSetInfo BSI = BSB.build();
|
|
|
|
EXPECT_EQ(T.Bits, BSI.Bits);
|
|
EXPECT_EQ(T.ByteOffset, BSI.ByteOffset);
|
|
EXPECT_EQ(T.BitSize, BSI.BitSize);
|
|
EXPECT_EQ(T.AlignLog2, BSI.AlignLog2);
|
|
EXPECT_EQ(T.IsSingleOffset, BSI.isSingleOffset());
|
|
|
|
for (auto Offset : T.Offsets)
|
|
EXPECT_TRUE(BSI.containsGlobalOffset(Offset));
|
|
|
|
auto I = T.Offsets.begin();
|
|
for (uint64_t NonOffset = 0; NonOffset != 256; ++NonOffset) {
|
|
if (I != T.Offsets.end() && *I == NonOffset) {
|
|
++I;
|
|
continue;
|
|
}
|
|
|
|
EXPECT_FALSE(BSI.containsGlobalOffset(NonOffset));
|
|
}
|
|
}
|
|
}
|