Skip to content

Commit 8af2e4e

Browse files
committed
remove LLT initializers taking a scalar size in favor of initializers taking a LLT
1 parent 4cce107 commit 8af2e4e

36 files changed

+555
-524
lines changed

llvm/include/llvm/CodeGen/MachineFunction.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,12 +1063,12 @@ class LLVM_ABI MachineFunction {
10631063
int64_t Offset, LLT Ty);
10641064
MachineMemOperand *getMachineMemOperand(const MachineMemOperand *MMO,
10651065
int64_t Offset, LocationSize Size) {
1066-
return getMachineMemOperand(
1067-
MMO, Offset,
1068-
!Size.hasValue() ? LLT()
1069-
: Size.isScalable()
1070-
? LLT::scalable_vector(1, 8 * Size.getValue().getKnownMinValue())
1071-
: LLT::scalar(8 * Size.getValue().getKnownMinValue()));
1066+
if (!Size.hasValue())
1067+
return getMachineMemOperand(MMO, Offset, LLT());
1068+
1069+
ElementCount EC = ElementCount::get(1, Size.isScalable());
1070+
LLT Ty = LLT::scalar(8 * Size.getValue().getKnownMinValue());
1071+
return getMachineMemOperand(MMO, Offset, LLT::scalarOrVector(EC, Ty));
10721072
}
10731073
MachineMemOperand *getMachineMemOperand(const MachineMemOperand *MMO,
10741074
int64_t Offset, uint64_t Size) {

llvm/include/llvm/CodeGenTypes/LowLevelType.h

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,6 @@ class LLT {
6060
ElementCount::getFixed(0), SizeInBits, AddressSpace};
6161
}
6262

63-
/// Get a low-level vector of some number of elements and element width.
64-
static constexpr LLT vector(ElementCount EC, unsigned ScalarSizeInBits) {
65-
assert(!EC.isScalar() && "invalid number of vector elements");
66-
return LLT{/*isPointer=*/false, /*isVector=*/true, /*isScalar=*/false,
67-
EC, ScalarSizeInBits, /*AddressSpace=*/0};
68-
}
69-
7063
/// Get a low-level vector of some number of elements and element type.
7164
static constexpr LLT vector(ElementCount EC, LLT ScalarTy) {
7265
assert(!EC.isScalar() && "invalid number of vector elements");
@@ -95,26 +88,12 @@ class LLT {
9588
return scalar(64);
9689
}
9790

98-
/// Get a low-level fixed-width vector of some number of elements and element
99-
/// width.
100-
static constexpr LLT fixed_vector(unsigned NumElements,
101-
unsigned ScalarSizeInBits) {
102-
return vector(ElementCount::getFixed(NumElements), ScalarSizeInBits);
103-
}
104-
10591
/// Get a low-level fixed-width vector of some number of elements and element
10692
/// type.
10793
static constexpr LLT fixed_vector(unsigned NumElements, LLT ScalarTy) {
10894
return vector(ElementCount::getFixed(NumElements), ScalarTy);
10995
}
11096

111-
/// Get a low-level scalable vector of some number of elements and element
112-
/// width.
113-
static constexpr LLT scalable_vector(unsigned MinNumElements,
114-
unsigned ScalarSizeInBits) {
115-
return vector(ElementCount::getScalable(MinNumElements), ScalarSizeInBits);
116-
}
117-
11897
/// Get a low-level scalable vector of some number of elements and element
11998
/// type.
12099
static constexpr LLT scalable_vector(unsigned MinNumElements, LLT ScalarTy) {
@@ -125,12 +104,6 @@ class LLT {
125104
return EC.isScalar() ? ScalarTy : LLT::vector(EC, ScalarTy);
126105
}
127106

128-
static constexpr LLT scalarOrVector(ElementCount EC, uint64_t ScalarSize) {
129-
assert(ScalarSize <= std::numeric_limits<unsigned>::max() &&
130-
"Not enough bits in LLT to represent size");
131-
return scalarOrVector(EC, LLT::scalar(static_cast<unsigned>(ScalarSize)));
132-
}
133-
134107
explicit constexpr LLT(bool isPointer, bool isVector, bool isScalar,
135108
ElementCount EC, uint64_t SizeInBits,
136109
unsigned AddressSpace)
@@ -215,16 +188,6 @@ class LLT {
215188
return isVector() ? LLT::vector(getElementCount(), NewEltTy) : NewEltTy;
216189
}
217190

218-
/// If this type is a vector, return a vector with the same number of elements
219-
/// but the new element size. Otherwise, return the new element type. Invalid
220-
/// for pointer types. For pointer types, use changeElementType.
221-
constexpr LLT changeElementSize(unsigned NewEltSize) const {
222-
assert(!isPointerOrPointerVector() &&
223-
"invalid to directly change element size for pointers");
224-
return isVector() ? LLT::vector(getElementCount(), NewEltSize)
225-
: LLT::scalar(NewEltSize);
226-
}
227-
228191
/// Return a vector or scalar with the same element type and the new element
229192
/// count.
230193
constexpr LLT changeElementCount(ElementCount EC) const {

llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2580,7 +2580,7 @@ static LLT getMidVTForTruncRightShiftCombine(LLT ShiftTy, LLT TruncTy) {
25802580

25812581
// ShiftTy > 32 > TruncTy -> 32
25822582
if (ShiftSize > 32 && TruncSize < 32)
2583-
return ShiftTy.changeElementSize(32);
2583+
return ShiftTy.changeElementType(LLT::scalar(32));
25842584

25852585
// TODO: We could also reduce to 16 bits, but that's more target-dependent.
25862586
// Some targets like it, some don't, some only like it under certain
@@ -5362,9 +5362,8 @@ MachineInstr *CombinerHelper::buildUDivUsingMul(MachineInstr &MI) {
53625362

53635363
Q = MIB.buildLShr(Ty, Q, PostShift).getReg(0);
53645364
auto One = MIB.buildConstant(Ty, 1);
5365-
auto IsOne = MIB.buildICmp(
5366-
CmpInst::Predicate::ICMP_EQ,
5367-
Ty.isScalar() ? LLT::scalar(1) : Ty.changeElementSize(1), RHS, One);
5365+
auto IsOne = MIB.buildICmp(CmpInst::Predicate::ICMP_EQ,
5366+
Ty.changeElementType(LLT::scalar(1)), RHS, One);
53685367
return MIB.buildSelect(Ty, IsOne, LHS, Q);
53695368
}
53705369

@@ -5404,8 +5403,7 @@ bool CombinerHelper::matchUDivByConst(MachineInstr &MI) {
54045403
return false;
54055404
if (!isLegalOrBeforeLegalizer(
54065405
{TargetOpcode::G_ICMP,
5407-
{DstTy.isVector() ? DstTy.changeElementSize(1) : LLT::scalar(1),
5408-
DstTy}}))
5406+
{DstTy.changeElementType(LLT::scalar(1)), DstTy}}))
54095407
return false;
54105408
}
54115409

@@ -5538,8 +5536,7 @@ void CombinerHelper::applySDivByPow2(MachineInstr &MI) {
55385536
Register RHS = SDiv.getReg(2);
55395537
LLT Ty = MRI.getType(Dst);
55405538
LLT ShiftAmtTy = getTargetLowering().getPreferredShiftAmountTy(Ty);
5541-
LLT CCVT =
5542-
Ty.isVector() ? LLT::vector(Ty.getElementCount(), 1) : LLT::scalar(1);
5539+
LLT CCVT = Ty.changeElementType(LLT::scalar(1));
55435540

55445541
// Effectively we want to lower G_SDIV %lhs, %rhs, where %rhs is a power of 2,
55455542
// to the following version:

llvm/lib/CodeGen/GlobalISel/LegacyLegalizerInfo.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -343,24 +343,22 @@ LegacyLegalizerInfo::findVectorLegalAction(const InstrAspect &Aspect) const {
343343
ScalarInVectorActions[OpcodeIdx][TypeIdx];
344344

345345
LLT IntermediateType;
346-
auto ElementSizeAndAction =
346+
auto &&[ElementSize, Action1] =
347347
findAction(ElemSizeVec, Aspect.Type.getScalarSizeInBits());
348-
IntermediateType = LLT::fixed_vector(Aspect.Type.getNumElements(),
349-
ElementSizeAndAction.first);
350-
if (ElementSizeAndAction.second != Legal)
351-
return {ElementSizeAndAction.second, IntermediateType};
348+
IntermediateType = Aspect.Type.changeElementType(LLT::scalar(ElementSize));
349+
if (Action1 != Legal)
350+
return {Action1, IntermediateType};
352351

353352
auto i = NumElements2Actions[OpcodeIdx].find(
354353
IntermediateType.getScalarSizeInBits());
355354
if (i == NumElements2Actions[OpcodeIdx].end()) {
356355
return {NotFound, IntermediateType};
357356
}
358357
const SizeAndActionsVec &NumElementsVec = (*i).second[TypeIdx];
359-
auto NumElementsAndAction =
358+
auto &&[NumElements, Action2] =
360359
findAction(NumElementsVec, IntermediateType.getNumElements());
361-
return {NumElementsAndAction.second,
362-
LLT::fixed_vector(NumElementsAndAction.first,
363-
IntermediateType.getScalarSizeInBits())};
360+
return {Action2,
361+
LLT::fixed_vector(NumElements, IntermediateType.getScalarType())};
364362
}
365363

366364
unsigned LegacyLegalizerInfo::getOpcodeIdxForOpcode(unsigned Opcode) const {

llvm/lib/CodeGen/GlobalISel/LegalizeMutations.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ LegalizeMutation LegalizeMutations::widenScalarOrEltToNextPow2(unsigned TypeIdx,
8080
const LLT Ty = Query.Types[TypeIdx];
8181
unsigned NewEltSizeInBits =
8282
std::max(1u << Log2_32_Ceil(Ty.getScalarSizeInBits()), Min);
83-
return std::make_pair(TypeIdx, Ty.changeElementSize(NewEltSizeInBits));
83+
return std::make_pair(TypeIdx,
84+
Ty.changeElementType(LLT::scalar(NewEltSizeInBits)));
8485
};
8586
}
8687

@@ -90,7 +91,8 @@ LegalizeMutations::widenScalarOrEltToNextMultipleOf(unsigned TypeIdx,
9091
return [=](const LegalityQuery &Query) {
9192
const LLT Ty = Query.Types[TypeIdx];
9293
unsigned NewEltSizeInBits = alignTo(Ty.getScalarSizeInBits(), Size);
93-
return std::make_pair(TypeIdx, Ty.changeElementSize(NewEltSizeInBits));
94+
return std::make_pair(TypeIdx,
95+
Ty.changeElementType(LLT::scalar(NewEltSizeInBits)));
9496
};
9597
}
9698

0 commit comments

Comments
 (0)