Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bolt/lib/Passes/PAuthGadgetScanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ class SrcSafetyAnalysis {

// Being trusted is a strictly stronger property than being
// safe-to-dereference.
assert(!Next.TrustedRegs.test(Next.SafeToDerefRegs) &&
assert(Next.TrustedRegs.subsetOf(Next.SafeToDerefRegs) &&
"SafeToDerefRegs should contain all TrustedRegs");

return Next;
Expand Down
5 changes: 4 additions & 1 deletion llvm/include/llvm/ADT/BitVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ class BitVector {
return *this;
}

/// test - Check if (This - RHS) is zero.
/// test - Check if (This - RHS) is non-zero.
/// This is the same as reset(RHS) and any().
bool test(const BitVector &RHS) const {
unsigned ThisWords = Bits.size();
Expand All @@ -567,6 +567,9 @@ class BitVector {
return false;
}

/// subsetOf - Check if This is a subset of RHS.
bool subsetOf(const BitVector &RHS) const { return !test(RHS); }

template <class F, class... ArgTys>
static BitVector &apply(F &&f, BitVector &Out, BitVector const &Arg,
ArgTys const &...Args) {
Expand Down
6 changes: 5 additions & 1 deletion llvm/include/llvm/ADT/SmallBitVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,8 @@ class SmallBitVector {
return *this;
}

/// Check if (This - RHS) is zero. This is the same as reset(RHS) and any().
/// Check if (This - RHS) is non-zero.
/// This is the same as reset(RHS) and any().
bool test(const SmallBitVector &RHS) const {
if (isSmall() && RHS.isSmall())
return (getSmallBits() & ~RHS.getSmallBits()) != 0;
Expand All @@ -571,6 +572,9 @@ class SmallBitVector {
return false;
}

/// Check if This is a subset of RHS.
bool subsetOf(const SmallBitVector &RHS) const { return !test(RHS); }

SmallBitVector &operator|=(const SmallBitVector &RHS) {
resize(std::max(size(), RHS.size()));
if (isSmall() && RHS.isSmall())
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Analysis/StackLifetime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ void StackLifetime::calculateLocalLiveness() {
BitsIn.resize(NumAllocas, true);

// Update block LiveIn set, noting whether it has changed.
if (BitsIn.test(BlockInfo.LiveIn)) {
if (!BitsIn.subsetOf(BlockInfo.LiveIn)) {
BlockInfo.LiveIn |= BitsIn;
}

Expand All @@ -198,7 +198,7 @@ void StackLifetime::calculateLocalLiveness() {
}

// Update block LiveOut set, noting whether it has changed.
if (BitsIn.test(BlockInfo.LiveOut)) {
if (!BitsIn.subsetOf(BlockInfo.LiveOut)) {
Changed = true;
BlockInfo.LiveOut |= BitsIn;
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ bool DwarfExpression::addMachineReg(const TargetRegisterInfo &TRI,

// If this sub-register has a DWARF number and we haven't covered
// its range, and its range covers the value, emit a DWARF piece for it.
if (Offset < MaxSize && CurSubReg.test(Coverage)) {
if (Offset < MaxSize && !CurSubReg.subsetOf(Coverage)) {
// Emit a piece for any gap in the coverage.
if (Offset > CurPos)
DwarfRegs.push_back(Register::createSubRegister(
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/CodeGen/StackColoring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -815,13 +815,13 @@ void StackColoring::calculateLocalLiveness() {
LocalLiveOut |= BlockInfo.Begin;

// Update block LiveIn set, noting whether it has changed.
if (LocalLiveIn.test(BlockInfo.LiveIn)) {
if (!LocalLiveIn.subsetOf(BlockInfo.LiveIn)) {
changed = true;
BlockInfo.LiveIn |= LocalLiveIn;
}

// Update block LiveOut set, noting whether it has changed.
if (LocalLiveOut.test(BlockInfo.LiveOut)) {
if (!LocalLiveOut.subsetOf(BlockInfo.LiveOut)) {
changed = true;
BlockInfo.LiveOut |= LocalLiveOut;
}
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Target/Hexagon/HexagonBitSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ namespace {
return !Bits.any();
}
bool includes(const RegisterSet &Rs) const {
// A.test(B) <=> A-B != {}
return !Rs.Bits.test(Bits);
return Rs.Bits.subsetOf(Bits);
}
bool intersects(const RegisterSet &Rs) const {
return Bits.anyCommon(Rs.Bits);
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Target/Hexagon/HexagonGenInsert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,7 @@ namespace {
return !BitVector::any();
}
bool includes(const RegisterSet &Rs) const {
// A.BitVector::test(B) <=> A-B != {}
return !Rs.BitVector::test(*this);
return Rs.BitVector::subsetOf(*this);
}
bool intersects(const RegisterSet &Rs) const {
return BitVector::anyCommon(Rs);
Expand Down
93 changes: 93 additions & 0 deletions llvm/unittests/ADT/BitVectorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallBitVector.h"
#include "gtest/gtest.h"
#include <initializer_list>

using namespace llvm;

Expand Down Expand Up @@ -835,26 +836,118 @@ TYPED_TEST(BitVectorTest, BinOps) {
A.resize(65);
EXPECT_FALSE(A.anyCommon(B));
EXPECT_FALSE(B.anyCommon(B));
EXPECT_TRUE(A.subsetOf(B));
EXPECT_TRUE(B.subsetOf(A));

B.resize(64);
A.set(64);
EXPECT_FALSE(A.anyCommon(B));
EXPECT_FALSE(B.anyCommon(A));
EXPECT_FALSE(A.subsetOf(B));
EXPECT_TRUE(B.subsetOf(A));

B.set(63);
EXPECT_FALSE(A.anyCommon(B));
EXPECT_FALSE(B.anyCommon(A));
EXPECT_FALSE(A.subsetOf(B));
EXPECT_FALSE(B.subsetOf(A));

A.set(63);
EXPECT_TRUE(A.anyCommon(B));
EXPECT_TRUE(B.anyCommon(A));
EXPECT_FALSE(A.subsetOf(B));
EXPECT_TRUE(B.subsetOf(A));

B.resize(70);
B.set(64);
B.reset(63);
A.resize(64);
EXPECT_FALSE(A.anyCommon(B));
EXPECT_FALSE(B.anyCommon(A));
EXPECT_FALSE(A.subsetOf(B));
EXPECT_FALSE(B.subsetOf(A));

B.set(63);
B.reset(64);
EXPECT_TRUE(A.anyCommon(B));
EXPECT_TRUE(B.anyCommon(A));
EXPECT_TRUE(A.subsetOf(B));
EXPECT_TRUE(B.subsetOf(A));
}

template <typename VecType>
static inline VecType
createBitVectorFromBits(uint32_t Size, std::initializer_list<int> SetBits) {
VecType V;
V.resize(Size);
for (int BitIndex : SetBits)
V.set(BitIndex);
return V;
}

TYPED_TEST(BitVectorTest, BinOpsLiteral) {
// More tests of binary operations with more focus on the semantics and
// less focus on mutability.

auto AnyCommon = [](uint32_t SizeLHS, std::initializer_list<int> SetBitsLHS,
uint32_t SizeRHS, std::initializer_list<int> SetBitsRHS) {
auto LHS = createBitVectorFromBits<TypeParam>(SizeLHS, SetBitsLHS);
auto RHS = createBitVectorFromBits<TypeParam>(SizeRHS, SetBitsRHS);
return LHS.anyCommon(RHS);
};
auto SubsetOf = [](uint32_t SizeLHS, std::initializer_list<int> SetBitsLHS,
uint32_t SizeRHS, std::initializer_list<int> SetBitsRHS) {
auto LHS = createBitVectorFromBits<TypeParam>(SizeLHS, SetBitsLHS);
auto RHS = createBitVectorFromBits<TypeParam>(SizeRHS, SetBitsRHS);
return LHS.subsetOf(RHS);
};

// clang-format off

// Test small-sized vectors.

EXPECT_TRUE (AnyCommon(10, {1, 2, 3}, 10, {3, 4, 5}));
EXPECT_FALSE(AnyCommon(10, {1, 2, 3}, 10, {4, 5}));

EXPECT_FALSE(SubsetOf(10, {1, 2, 3}, 10, {2, 3, 4}));
EXPECT_TRUE (SubsetOf(10, {2, 3}, 10, {2, 3, 4}));
EXPECT_FALSE(SubsetOf(10, {1, 2, 3}, 10, {2, 3}));
EXPECT_TRUE (SubsetOf(10, {1, 2, 3}, 10, {1, 2, 3}));

// Test representations of empty sets of various sizes.

EXPECT_FALSE(AnyCommon(10, {}, 10, {}));
EXPECT_FALSE(AnyCommon(10, {}, 123, {}));
EXPECT_FALSE(AnyCommon(123, {}, 10, {}));
EXPECT_FALSE(AnyCommon(123, {}, 123, {}));
EXPECT_TRUE(SubsetOf(10, {}, 10, {}));
EXPECT_TRUE(SubsetOf(10, {}, 123, {}));
EXPECT_TRUE(SubsetOf(123, {}, 10, {}));
EXPECT_TRUE(SubsetOf(123, {}, 123, {}));

// Test handling of the remainder words.

EXPECT_FALSE(AnyCommon(10, {1, 2}, 123, {5, 70}));
EXPECT_TRUE (AnyCommon(10, {1, 2}, 123, {1, 70}));
EXPECT_FALSE(AnyCommon(123, {5, 70}, 10, {1, 2}));
EXPECT_TRUE (AnyCommon(123, {1, 70}, 10, {1, 2}));

EXPECT_FALSE(AnyCommon(10, {1, 2}, 123, {5}));
EXPECT_TRUE (AnyCommon(10, {1, 2}, 123, {1}));
EXPECT_FALSE(AnyCommon(123, {5}, 10, {1, 2}));
EXPECT_TRUE (AnyCommon(123, {1}, 10, {1, 2}));

EXPECT_FALSE(SubsetOf(10, {1, 2}, 123, {2, 70}));
EXPECT_TRUE (SubsetOf(10, {1, 2}, 123, {1, 2, 70}));
EXPECT_FALSE(SubsetOf(123, {2, 70}, 10, {1, 2}));
EXPECT_FALSE(SubsetOf(123, {1, 2, 70}, 10, {1, 2}));

EXPECT_FALSE(SubsetOf(10, {1, 2}, 123, {2}));
EXPECT_TRUE (SubsetOf(10, {1, 2}, 123, {1, 2}));
EXPECT_TRUE (SubsetOf(123, {2}, 10, {1, 2}));
EXPECT_TRUE (SubsetOf(123, {1, 2}, 10, {1, 2}));

// clang-format on
}

using RangeList = std::vector<std::pair<int, int>>;
Expand Down
Loading