Skip to content

Commit 4fc56d7

Browse files
committed
Revert "[NFC][llvm] Make the contructors of ElementCount private."
This reverts commit 264afb9. (and dependent 6b742cc and fc53bd6) MLIR/Flang are broken.
1 parent d25b12b commit 4fc56d7

26 files changed

+83
-109
lines changed

clang/lib/AST/ASTContext.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3714,11 +3714,11 @@ QualType ASTContext::getIncompleteArrayType(QualType elementType,
37143714
ASTContext::BuiltinVectorTypeInfo
37153715
ASTContext::getBuiltinVectorTypeInfo(const BuiltinType *Ty) const {
37163716
#define SVE_INT_ELTTY(BITS, ELTS, SIGNED, NUMVECTORS) \
3717-
{getIntTypeForBitwidth(BITS, SIGNED), llvm::ElementCount::getScalable(ELTS), \
3717+
{getIntTypeForBitwidth(BITS, SIGNED), llvm::ElementCount(ELTS, true), \
37183718
NUMVECTORS};
37193719

37203720
#define SVE_ELTTY(ELTTY, ELTS, NUMVECTORS) \
3721-
{ELTTY, llvm::ElementCount::getScalable(ELTS), NUMVECTORS};
3721+
{ELTTY, llvm::ElementCount(ELTS, true), NUMVECTORS};
37223722

37233723
switch (Ty->getKind()) {
37243724
default:

llvm/include/llvm/Analysis/VectorUtils.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ struct VFShape {
9999
// Retrieve the VFShape that can be used to map a (scalar) function to itself,
100100
// with VF = 1.
101101
static VFShape getScalarShape(const CallInst &CI) {
102-
return VFShape::get(CI, ElementCount::getFixed(1),
103-
/*HasGlobalPredicate*/ false);
102+
return VFShape::get(CI, /*EC*/ {1, false}, /*HasGlobalPredicate*/ false);
104103
}
105104

106105
// Retrieve the basic vectorization shape of the function, where all
@@ -306,7 +305,7 @@ typedef unsigned ID;
306305
inline Type *ToVectorTy(Type *Scalar, unsigned VF, bool isScalable = false) {
307306
if (Scalar->isVoidTy() || VF == 1)
308307
return Scalar;
309-
return VectorType::get(Scalar, ElementCount::get(VF, isScalable));
308+
return VectorType::get(Scalar, {VF, isScalable});
310309
}
311310

312311
/// Identify if the intrinsic is trivially vectorizable.

llvm/include/llvm/IR/DerivedTypes.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,7 @@ class VectorType : public Type {
446446

447447
static VectorType *get(Type *ElementType, unsigned NumElements,
448448
bool Scalable) {
449-
return VectorType::get(ElementType,
450-
ElementCount::get(NumElements, Scalable));
449+
return VectorType::get(ElementType, {NumElements, Scalable});
451450
}
452451

453452
static VectorType *get(Type *ElementType, const VectorType *Other) {
@@ -641,7 +640,7 @@ class ScalableVectorType : public VectorType {
641640
};
642641

643642
inline ElementCount VectorType::getElementCount() const {
644-
return ElementCount::get(ElementQuantity, isa<ScalableVectorType>(this));
643+
return ElementCount(ElementQuantity, isa<ScalableVectorType>(this));
645644
}
646645

647646
/// Class to represent pointers.

llvm/include/llvm/IR/Intrinsics.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,7 @@ namespace Intrinsic {
134134
unsigned Pointer_AddressSpace;
135135
unsigned Struct_NumElements;
136136
unsigned Argument_Info;
137-
// There is no default constructor in `ElementCount`, so we need
138-
// to explicitly initialize this field with a value.
139-
ElementCount Vector_Width = ElementCount::getFixed(0);
137+
ElementCount Vector_Width;
140138
};
141139

142140
enum ArgKind {
@@ -192,7 +190,8 @@ namespace Intrinsic {
192190
static IITDescriptor getVector(unsigned Width, bool IsScalable) {
193191
IITDescriptor Result;
194192
Result.Kind = Vector;
195-
Result.Vector_Width = ElementCount::get(Width, IsScalable);
193+
Result.Vector_Width.Min = Width;
194+
Result.Vector_Width.Scalable = IsScalable;
196195
return Result;
197196
}
198197
};

llvm/include/llvm/Support/MachineValueType.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ namespace llvm {
737737
}
738738

739739
ElementCount getVectorElementCount() const {
740-
return ElementCount::get(getVectorNumElements(), isScalableVector());
740+
return { getVectorNumElements(), isScalableVector() };
741741
}
742742

743743
/// Given a vector type, return the minimum number of elements it contains.

llvm/include/llvm/Support/TypeSize.h

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,16 @@ namespace llvm {
2626
template <typename T> struct DenseMapInfo;
2727

2828
class ElementCount {
29-
private:
30-
/// Prevent code from using initializer-list contructors like
31-
/// ElementCount EC = {<unsigned>, <bool>}. The static `get*`
32-
/// methods below are preferred, as users should always make a
33-
/// conscious choice on the type of `ElementCount` they are
34-
/// requesting.
35-
ElementCount(unsigned Min, bool Scalable) : Min(Min), Scalable(Scalable) {}
36-
3729
public:
38-
/// No default constructor. Users should use one of the `get*`
39-
/// static methods below, as they should always make a conscious
40-
/// choice on the type of `ElementCount` they are requesting.
41-
ElementCount() = delete;
4230
unsigned Min; // Minimum number of vector elements.
4331
bool Scalable; // If true, NumElements is a multiple of 'Min' determined
4432
// at runtime rather than compile time.
4533

34+
ElementCount() = default;
35+
36+
ElementCount(unsigned Min, bool Scalable)
37+
: Min(Min), Scalable(Scalable) {}
38+
4639
ElementCount operator*(unsigned RHS) {
4740
return { Min * RHS, Scalable };
4841
}
@@ -61,13 +54,7 @@ class ElementCount {
6154
bool operator!=(unsigned RHS) const { return !(*this == RHS); }
6255

6356
ElementCount NextPowerOf2() const {
64-
return {(unsigned)llvm::NextPowerOf2(Min), Scalable};
65-
}
66-
67-
static ElementCount getFixed(unsigned Min) { return {Min, false}; }
68-
static ElementCount getScalable(unsigned Min) { return {Min, true}; }
69-
static ElementCount get(unsigned Min, bool Scalable) {
70-
return {Min, Scalable};
57+
return ElementCount(llvm::NextPowerOf2(Min), Scalable);
7158
}
7259
};
7360

@@ -292,12 +279,8 @@ inline TypeSize alignTo(TypeSize Size, uint64_t Align) {
292279
}
293280

294281
template <> struct DenseMapInfo<ElementCount> {
295-
static inline ElementCount getEmptyKey() {
296-
return ElementCount::getScalable(~0U);
297-
}
298-
static inline ElementCount getTombstoneKey() {
299-
return ElementCount::getFixed(~0U - 1);
300-
}
282+
static inline ElementCount getEmptyKey() { return {~0U, true}; }
283+
static inline ElementCount getTombstoneKey() { return {~0U - 1, false}; }
301284
static unsigned getHashValue(const ElementCount& EltCnt) {
302285
if (EltCnt.Scalable)
303286
return (EltCnt.Min * 37U) - 1U;

llvm/lib/Analysis/VFABIDemangling.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ ElementCount getECFromSignature(FunctionType *Signature) {
310310
if (auto *VTy = dyn_cast<VectorType>(Ty))
311311
return VTy->getElementCount();
312312

313-
return ElementCount::getFixed(/*Min=*/1);
313+
return ElementCount(/*Min=*/1, /*Scalable=*/false);
314314
}
315315
} // namespace
316316

llvm/lib/AsmParser/LLParser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7395,7 +7395,7 @@ int LLParser::ParseGetElementPtr(Instruction *&Inst, PerFunctionState &PFS) {
73957395
// All vector parameters should have the same vector width.
73967396
ElementCount GEPWidth = BaseType->isVectorTy()
73977397
? cast<VectorType>(BaseType)->getElementCount()
7398-
: ElementCount::getFixed(0);
7398+
: ElementCount(0, false);
73997399

74007400
while (EatIfPresent(lltok::comma)) {
74017401
if (Lex.getKind() == lltok::MetadataVar) {
@@ -7408,7 +7408,7 @@ int LLParser::ParseGetElementPtr(Instruction *&Inst, PerFunctionState &PFS) {
74087408

74097409
if (auto *ValVTy = dyn_cast<VectorType>(Val->getType())) {
74107410
ElementCount ValNumEl = ValVTy->getElementCount();
7411-
if (GEPWidth != ElementCount::getFixed(0) && GEPWidth != ValNumEl)
7411+
if (GEPWidth != ElementCount(0, false) && GEPWidth != ValNumEl)
74127412
return Error(EltLoc,
74137413
"getelementptr vector index has a wrong number of elements");
74147414
GEPWidth = ValNumEl;

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -729,15 +729,15 @@ static void getCopyToPartsVector(SelectionDAG &DAG, const SDLoc &DL,
729729
assert(IntermediateVT.isScalableVector() == ValueVT.isScalableVector() &&
730730
"Mixing scalable and fixed vectors when copying in parts");
731731

732-
Optional<ElementCount> DestEltCnt;
732+
ElementCount DestEltCnt;
733733

734734
if (IntermediateVT.isVector())
735735
DestEltCnt = IntermediateVT.getVectorElementCount() * NumIntermediates;
736736
else
737-
DestEltCnt = ElementCount::getFixed(NumIntermediates);
737+
DestEltCnt = ElementCount(NumIntermediates, false);
738738

739739
EVT BuiltVectorTy = EVT::getVectorVT(
740-
*DAG.getContext(), IntermediateVT.getScalarType(), DestEltCnt.getValue());
740+
*DAG.getContext(), IntermediateVT.getScalarType(), DestEltCnt);
741741
if (ValueVT != BuiltVectorTy) {
742742
if (SDValue Widened = widenVectorToPartType(DAG, Val, DL, BuiltVectorTy))
743743
Val = Widened;
@@ -3746,7 +3746,7 @@ void SelectionDAGBuilder::visitGetElementPtr(const User &I) {
37463746
bool IsVectorGEP = I.getType()->isVectorTy();
37473747
ElementCount VectorElementCount =
37483748
IsVectorGEP ? cast<VectorType>(I.getType())->getElementCount()
3749-
: ElementCount::getFixed(0);
3749+
: ElementCount(0, false);
37503750

37513751
if (IsVectorGEP && !N.getValueType().isVector()) {
37523752
LLVMContext &Context = *DAG.getContext();

llvm/lib/CodeGen/TargetLoweringBase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ TargetLoweringBase::getTypeConversion(LLVMContext &Context, EVT VT) const {
866866
if (NumElts == 1)
867867
return LegalizeKind(TypeScalarizeVector, EltVT);
868868

869-
if (VT.getVectorElementCount() == ElementCount::getScalable(1))
869+
if (VT.getVectorElementCount() == ElementCount(1, true))
870870
report_fatal_error("Cannot legalize this vector");
871871

872872
// Try to widen vector elements until the element type is a power of two and

0 commit comments

Comments
 (0)