Skip to content

Commit b8ce6a6

Browse files
committed
[SVE][CodeGen] Add new EVT/MVT getFixedSizeInBits() functions
When we know that a particular type is always going to be fixed width we have so far been writing code like this: getSizeInBits().getFixedSize() Since we are doing this in quite a few places now it seems to make sense to add a new helper function that allows us to replace these calls with a single getFixedSizeInBits() call. Differential Revision: https://reviews.llvm.org/D88649
1 parent afb4e0f commit b8ce6a6

File tree

8 files changed

+25
-13
lines changed

8 files changed

+25
-13
lines changed

llvm/include/llvm/CodeGen/SelectionDAGNodes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ class SDValue {
181181
}
182182

183183
uint64_t getScalarValueSizeInBits() const {
184-
return getValueType().getScalarType().getSizeInBits().getFixedSize();
184+
return getValueType().getScalarType().getFixedSizeInBits();
185185
}
186186

187187
// Forwarding methods - These forward to the corresponding methods in SDNode.

llvm/include/llvm/CodeGen/ValueTypes.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,12 @@ namespace llvm {
348348
return getExtendedSizeInBits();
349349
}
350350

351+
/// Return the size of the specified fixed width value type in bits. The
352+
/// function will assert if the type is scalable.
353+
uint64_t getFixedSizeInBits() const {
354+
return getSizeInBits().getFixedSize();
355+
}
356+
351357
uint64_t getScalarSizeInBits() const {
352358
return getScalarType().getSizeInBits().getFixedSize();
353359
}

llvm/include/llvm/Support/MachineValueType.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,12 @@ namespace llvm {
923923
}
924924
}
925925

926+
/// Return the size of the specified fixed width value type in bits. The
927+
/// function will assert if the type is scalable.
928+
uint64_t getFixedSizeInBits() const {
929+
return getSizeInBits().getFixedSize();
930+
}
931+
926932
uint64_t getScalarSizeInBits() const {
927933
return getScalarType().getSizeInBits().getFixedSize();
928934
}

llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,7 +1517,7 @@ void DAGTypeLegalizer::SplitVecRes_INSERT_VECTOR_ELT(SDNode *N, SDValue &Lo,
15171517
Store = DAG.getTruncStore(
15181518
Store, dl, Elt, EltPtr, MachinePointerInfo::getUnknownStack(MF), EltVT,
15191519
commonAlignment(SmallestAlign,
1520-
EltVT.getSizeInBits().getFixedSize() / 8));
1520+
EltVT.getFixedSizeInBits() / 8));
15211521

15221522
EVT LoVT, HiVT;
15231523
std::tie(LoVT, HiVT) = DAG.GetSplitDestVTs(VecVT);
@@ -2310,7 +2310,7 @@ SDValue DAGTypeLegalizer::SplitVecOp_EXTRACT_VECTOR_ELT(SDNode *N) {
23102310
return DAG.getExtLoad(
23112311
ISD::EXTLOAD, dl, N->getValueType(0), Store, StackPtr,
23122312
MachinePointerInfo::getUnknownStack(DAG.getMachineFunction()), EltVT,
2313-
commonAlignment(SmallestAlign, EltVT.getSizeInBits().getFixedSize() / 8));
2313+
commonAlignment(SmallestAlign, EltVT.getFixedSizeInBits() / 8));
23142314
}
23152315

23162316
SDValue DAGTypeLegalizer::SplitVecOp_ExtVecInRegOp(SDNode *N) {
@@ -4904,7 +4904,7 @@ static EVT FindMemType(SelectionDAG& DAG, const TargetLowering &TLI,
49044904
isPowerOf2_32(WidenWidth / MemVTWidth) &&
49054905
(MemVTWidth <= Width ||
49064906
(Align!=0 && MemVTWidth<=AlignInBits && MemVTWidth<=Width+WidenEx))) {
4907-
if (RetVT.getSizeInBits().getFixedSize() < MemVTWidth || MemVT == WidenVT)
4907+
if (RetVT.getFixedSizeInBits() < MemVTWidth || MemVT == WidenVT)
49084908
return MemVT;
49094909
}
49104910
}
@@ -5169,7 +5169,7 @@ void DAGTypeLegalizer::GenWidenVectorStores(SmallVectorImpl<SDValue> &StChain,
51695169
EVT ValVT = ValOp.getValueType();
51705170
TypeSize ValWidth = ValVT.getSizeInBits();
51715171
EVT ValEltVT = ValVT.getVectorElementType();
5172-
unsigned ValEltWidth = ValEltVT.getSizeInBits().getFixedSize();
5172+
unsigned ValEltWidth = ValEltVT.getFixedSizeInBits();
51735173
assert(StVT.getVectorElementType() == ValEltVT);
51745174
assert(StVT.isScalableVector() == ValVT.isScalableVector() &&
51755175
"Mismatch between store and value types");

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7204,7 +7204,7 @@ SDValue TargetLowering::expandUnalignedStore(StoreSDNode *ST,
72047204
"Unaligned store of unknown type.");
72057205
// Get the half-size VT
72067206
EVT NewStoredVT = StoreMemVT.getHalfSizedIntegerVT(*DAG.getContext());
7207-
unsigned NumBits = NewStoredVT.getSizeInBits().getFixedSize();
7207+
unsigned NumBits = NewStoredVT.getFixedSizeInBits();
72087208
unsigned IncrementSize = NumBits / 8;
72097209

72107210
// Divide the stored value in two parts.
@@ -7262,7 +7262,7 @@ TargetLowering::IncrementMemoryAddress(SDValue Addr, SDValue Mask,
72627262
Increment = DAG.getNode(ISD::MUL, DL, AddrVT, Increment, Scale);
72637263
} else if (DataVT.isScalableVector()) {
72647264
Increment = DAG.getVScale(DL, AddrVT,
7265-
APInt(AddrVT.getSizeInBits().getFixedSize(),
7265+
APInt(AddrVT.getFixedSizeInBits(),
72667266
DataVT.getStoreSize().getKnownMinSize()));
72677267
} else
72687268
Increment = DAG.getConstant(DataVT.getStoreSize(), DL, AddrVT);
@@ -7281,7 +7281,7 @@ static SDValue clampDynamicVectorIndex(SelectionDAG &DAG,
72817281
unsigned NElts = VecVT.getVectorMinNumElements();
72827282
if (VecVT.isScalableVector()) {
72837283
SDValue VS = DAG.getVScale(dl, IdxVT,
7284-
APInt(IdxVT.getSizeInBits().getFixedSize(),
7284+
APInt(IdxVT.getFixedSizeInBits(),
72857285
NElts));
72867286
SDValue Sub = DAG.getNode(ISD::SUB, dl, IdxVT, VS,
72877287
DAG.getConstant(1, dl, IdxVT));
@@ -7310,8 +7310,8 @@ SDValue TargetLowering::getVectorElementPointer(SelectionDAG &DAG,
73107310
EVT EltVT = VecVT.getVectorElementType();
73117311

73127312
// Calculate the element offset and add it to the pointer.
7313-
unsigned EltSize = EltVT.getSizeInBits().getFixedSize() / 8; // FIXME: should be ABI size.
7314-
assert(EltSize * 8 == EltVT.getSizeInBits().getFixedSize() &&
7313+
unsigned EltSize = EltVT.getFixedSizeInBits() / 8; // FIXME: should be ABI size.
7314+
assert(EltSize * 8 == EltVT.getFixedSizeInBits() &&
73157315
"Converting bits to bytes lost precision");
73167316

73177317
Index = clampDynamicVectorIndex(DAG, Index, VecVT, dl);

llvm/lib/CodeGen/TargetLoweringBase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ void TargetLoweringBase::initActions() {
615615
std::end(TargetDAGCombineArray), 0);
616616

617617
for (MVT VT : MVT::fp_valuetypes()) {
618-
MVT IntVT = MVT::getIntegerVT(VT.getSizeInBits().getFixedSize());
618+
MVT IntVT = MVT::getIntegerVT(VT.getFixedSizeInBits());
619619
if (IntVT.isValid()) {
620620
setOperationAction(ISD::ATOMIC_SWAP, VT, Promote);
621621
AddPromotedToType(ISD::ATOMIC_SWAP, VT, IntVT);

llvm/lib/Target/Hexagon/HexagonISelLoweringHVX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ HexagonTargetLowering::initializeHVXLowering() {
228228
for (MVT ElemTy : Subtarget.getHVXElementTypes()) {
229229
if (ElemTy == MVT::i1)
230230
continue;
231-
int ElemWidth = ElemTy.getSizeInBits().getFixedSize();
231+
int ElemWidth = ElemTy.getFixedSizeInBits();
232232
int MaxElems = (8*HwLen) / ElemWidth;
233233
for (int N = 2; N < MaxElems; N *= 2) {
234234
MVT VecTy = MVT::getVectorVT(ElemTy, N);

llvm/unittests/CodeGen/ScalableVectorMVTsTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ TEST(ScalableVectorMVTsTest, SizeQueries) {
160160

161161
// Check that we can obtain a known-exact size from a non-scalable type.
162162
EXPECT_EQ(v4i32.getSizeInBits(), 128U);
163-
EXPECT_EQ(v2i64.getSizeInBits().getFixedSize(), 128U);
163+
EXPECT_EQ(v2i64.getFixedSizeInBits(), 128U);
164164

165165
// Check that we can query the known minimum size for both scalable and
166166
// fixed length types.

0 commit comments

Comments
 (0)