diff --git a/llvm/include/llvm/ADT/BitVector.h b/llvm/include/llvm/ADT/BitVector.h --- a/llvm/include/llvm/ADT/BitVector.h +++ b/llvm/include/llvm/ADT/BitVector.h @@ -23,6 +23,7 @@ #include #include #include +#include #include namespace llvm { @@ -144,6 +145,13 @@ clear_unused_bits(); } + /// Creates a bitvector with the specified values. + BitVector(std::initializer_list Values) : BitVector(Values.size()) { + unsigned Idx = 0; + for (bool Value : Values) + (*this)[Idx++] = Value; + } + /// empty - Tests whether there are no bits in this bitvector. bool empty() const { return Size == 0; } diff --git a/llvm/include/llvm/ADT/SmallBitVector.h b/llvm/include/llvm/ADT/SmallBitVector.h --- a/llvm/include/llvm/ADT/SmallBitVector.h +++ b/llvm/include/llvm/ADT/SmallBitVector.h @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -151,6 +152,14 @@ switchToLarge(new BitVector(s, t)); } + /// Creates a bitvector with the specified values. + SmallBitVector(std::initializer_list Values) + : SmallBitVector(Values.size()) { + unsigned Idx = 0; + for (bool Value : Values) + (*this)[Idx++] = Value; + } + /// SmallBitVector copy ctor. SmallBitVector(const SmallBitVector &RHS) { if (RHS.isSmall()) diff --git a/llvm/include/llvm/CodeGen/GlobalISel/LegalizerInfo.h b/llvm/include/llvm/CodeGen/GlobalISel/LegalizerInfo.h --- a/llvm/include/llvm/CodeGen/GlobalISel/LegalizerInfo.h +++ b/llvm/include/llvm/CodeGen/GlobalISel/LegalizerInfo.h @@ -416,10 +416,10 @@ /// indices. The bitset is intentionally 1 bit wider than it absolutely needs /// to be to distinguish such cases from the cases where all type indices are /// individually handled. - SmallBitVector TypeIdxsCovered{MCOI::OPERAND_LAST_GENERIC - - MCOI::OPERAND_FIRST_GENERIC + 2}; - SmallBitVector ImmIdxsCovered{MCOI::OPERAND_LAST_GENERIC_IMM - - MCOI::OPERAND_FIRST_GENERIC_IMM + 2}; + SmallBitVector TypeIdxsCovered = SmallBitVector( + MCOI::OPERAND_LAST_GENERIC - MCOI::OPERAND_FIRST_GENERIC + 2); + SmallBitVector ImmIdxsCovered = SmallBitVector( + MCOI::OPERAND_LAST_GENERIC_IMM - MCOI::OPERAND_FIRST_GENERIC_IMM + 2); #endif unsigned typeIdx(unsigned TypeIdx) { diff --git a/llvm/lib/CodeGen/MachineCheckDebugify.cpp b/llvm/lib/CodeGen/MachineCheckDebugify.cpp --- a/llvm/lib/CodeGen/MachineCheckDebugify.cpp +++ b/llvm/lib/CodeGen/MachineCheckDebugify.cpp @@ -45,8 +45,8 @@ "llvm.mir.debugify should have exactly 2 operands!"); unsigned NumLines = getDebugifyOperand(0); unsigned NumVars = getDebugifyOperand(1); - BitVector MissingLines{NumLines, true}; - BitVector MissingVars{NumVars, true}; + BitVector MissingLines(NumLines, true); + BitVector MissingVars(NumVars, true); for (Function &F : M.functions()) { MachineFunction *MF = MMI.getMachineFunction(F); diff --git a/llvm/lib/Target/X86/ImmutableGraph.h b/llvm/lib/Target/X86/ImmutableGraph.h --- a/llvm/lib/Target/X86/ImmutableGraph.h +++ b/llvm/lib/Target/X86/ImmutableGraph.h @@ -114,7 +114,7 @@ public: NodeSet(const ImmutableGraph &G, bool ContainsAll = false) - : G{G}, V{static_cast(G.nodes_size()), ContainsAll} {} + : G{G}, V(static_cast(G.nodes_size()), ContainsAll) {} bool insert(const Node &N) { size_type Idx = G.getNodeIndex(N); bool AlreadyExists = V.test(Idx); @@ -202,7 +202,7 @@ public: EdgeSet(const ImmutableGraph &G, bool ContainsAll = false) - : G{G}, V{static_cast(G.edges_size()), ContainsAll} {} + : G{G}, V(static_cast(G.edges_size()), ContainsAll) {} bool insert(const Edge &E) { size_type Idx = G.getEdgeIndex(E); bool AlreadyExists = V.test(Idx); diff --git a/llvm/lib/Transforms/Utils/Debugify.cpp b/llvm/lib/Transforms/Utils/Debugify.cpp --- a/llvm/lib/Transforms/Utils/Debugify.cpp +++ b/llvm/lib/Transforms/Utils/Debugify.cpp @@ -698,8 +698,8 @@ if (StatsMap && !NameOfWrappedPass.empty()) Stats = &StatsMap->operator[](NameOfWrappedPass); - BitVector MissingLines{OriginalNumLines, true}; - BitVector MissingVars{OriginalNumVars, true}; + BitVector MissingLines(OriginalNumLines, true); + BitVector MissingVars(OriginalNumVars, true); for (Function &F : Functions) { if (isFunctionSkipped(F)) continue; diff --git a/llvm/unittests/ADT/BitVectorTest.cpp b/llvm/unittests/ADT/BitVectorTest.cpp --- a/llvm/unittests/ADT/BitVectorTest.cpp +++ b/llvm/unittests/ADT/BitVectorTest.cpp @@ -23,6 +23,15 @@ typedef ::testing::Types BitVectorTestTypes; TYPED_TEST_SUITE(BitVectorTest, BitVectorTestTypes, ); +TYPED_TEST(BitVectorTest, InitializerListCtor) { + TypeParam Vec{true, false, true, true}; + EXPECT_EQ(4U, Vec.size()); + EXPECT_EQ(true, Vec[0]); + EXPECT_EQ(false, Vec[1]); + EXPECT_EQ(true, Vec[2]); + EXPECT_EQ(true, Vec[3]); +} + TYPED_TEST(BitVectorTest, TrivialOperation) { TypeParam Vec; EXPECT_EQ(0U, Vec.count());