Skip to content

Commit 8d78b7c

Browse files
authored
[RISCV] Introduce RISCV::RVVBytesPerBlock to simplify code [nfc] (#132436)
1 parent 9933117 commit 8d78b7c

File tree

6 files changed

+14
-15
lines changed

6 files changed

+14
-15
lines changed

llvm/include/llvm/TargetParser/RISCVTargetParser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ struct CPUInfo {
4949

5050
// We use 64 bits as the known part in the scalable vector types.
5151
static constexpr unsigned RVVBitsPerBlock = 64;
52+
static constexpr unsigned RVVBytesPerBlock = RVVBitsPerBlock / 8;
5253

5354
void getFeaturesForCPU(StringRef CPU,
5455
SmallVectorImpl<std::string> &EnabledFeatures,

llvm/lib/IR/Type.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ static TargetTypeInfo getTargetTypeInfo(const TargetExtType *Ty) {
10091009
unsigned TotalNumElts =
10101010
std::max(cast<ScalableVectorType>(Ty->getTypeParameter(0))
10111011
->getMinNumElements(),
1012-
RISCV::RVVBitsPerBlock / 8) *
1012+
RISCV::RVVBytesPerBlock) *
10131013
Ty->getIntParameter(0);
10141014
return TargetTypeInfo(
10151015
ScalableVectorType::get(Type::getInt8Ty(C), TotalNumElts),

llvm/lib/Target/RISCV/RISCVFrameLowering.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ void RISCVFrameLowering::allocateAndProbeStackForRVV(
526526
// Get VLEN in TargetReg
527527
const RISCVInstrInfo *TII = STI.getInstrInfo();
528528
Register TargetReg = RISCV::X6;
529-
uint32_t NumOfVReg = Amount / (RISCV::RVVBitsPerBlock / 8);
529+
uint32_t NumOfVReg = Amount / RISCV::RVVBytesPerBlock;
530530
BuildMI(MBB, MBBI, DL, TII->get(RISCV::PseudoReadVLENB), TargetReg)
531531
.setMIFlag(Flag);
532532
TII->mulImm(MF, MBB, MBBI, DL, TargetReg, NumOfVReg, Flag);
@@ -1544,11 +1544,11 @@ RISCVFrameLowering::assignRVVStackObjectOffsets(MachineFunction &MF) const {
15441544
// ObjectSize in bytes.
15451545
int64_t ObjectSize = MFI.getObjectSize(FI);
15461546
auto ObjectAlign =
1547-
std::max(Align(RISCV::RVVBitsPerBlock / 8), MFI.getObjectAlign(FI));
1547+
std::max(Align(RISCV::RVVBytesPerBlock), MFI.getObjectAlign(FI));
15481548
// If the data type is the fractional vector type, reserve one vector
15491549
// register for it.
1550-
if (ObjectSize < (RISCV::RVVBitsPerBlock / 8))
1551-
ObjectSize = (RISCV::RVVBitsPerBlock / 8);
1550+
if (ObjectSize < RISCV::RVVBytesPerBlock)
1551+
ObjectSize = RISCV::RVVBytesPerBlock;
15521552
Offset = alignTo(Offset + ObjectSize, ObjectAlign);
15531553
MFI.setObjectOffset(FI, -Offset);
15541554
// Update the maximum alignment of the RVV stack section

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,7 +1633,7 @@ bool RISCVTargetLowering::shouldExpandGetVectorLength(EVT TripCountVT,
16331633

16341634
// The maximum VF is for the smallest element width with LMUL=8.
16351635
// VF must be a power of 2.
1636-
unsigned MaxVF = (RISCV::RVVBitsPerBlock / 8) * 8;
1636+
unsigned MaxVF = RISCV::RVVBytesPerBlock * 8;
16371637
return VF > MaxVF || !isPowerOf2_32(VF);
16381638
}
16391639

@@ -22713,7 +22713,7 @@ EVT RISCVTargetLowering::getOptimalMemOpType(const MemOp &Op,
2271322713

2271422714
// If the minimum VLEN is less than RISCV::RVVBitsPerBlock we don't support
2271522715
// fixed vectors.
22716-
if (MinVLenInBytes <= RISCV::RVVBitsPerBlock / 8)
22716+
if (MinVLenInBytes <= RISCV::RVVBytesPerBlock)
2271722717
return MVT::Other;
2271822718

2271922719
// Prefer i8 for non-zero memset as it allows us to avoid materializing

llvm/lib/Target/RISCV/RISCVInstrInfo.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,8 @@ Register RISCVInstrInfo::isLoadFromStackSlot(const MachineInstr &MI,
163163
if (!MI.getOperand(1).isFI())
164164
return Register();
165165
FrameIndex = MI.getOperand(1).getIndex();
166-
unsigned BytesPerBlock = RISCV::RVVBitsPerBlock / 8;
167166
unsigned LMUL = *getLMULForRVVWholeLoadStore(MI.getOpcode());
168-
MemBytes = TypeSize::getScalable(BytesPerBlock * LMUL);
167+
MemBytes = TypeSize::getScalable(RISCV::RVVBytesPerBlock * LMUL);
169168
return MI.getOperand(0).getReg();
170169
}
171170

@@ -214,9 +213,8 @@ Register RISCVInstrInfo::isStoreToStackSlot(const MachineInstr &MI,
214213
if (!MI.getOperand(1).isFI())
215214
return Register();
216215
FrameIndex = MI.getOperand(1).getIndex();
217-
unsigned BytesPerBlock = RISCV::RVVBitsPerBlock / 8;
218216
unsigned LMUL = *getLMULForRVVWholeLoadStore(MI.getOpcode());
219-
MemBytes = TypeSize::getScalable(BytesPerBlock * LMUL);
217+
MemBytes = TypeSize::getScalable(RISCV::RVVBytesPerBlock * LMUL);
220218
return MI.getOperand(0).getReg();
221219
}
222220

llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ void RISCVRegisterInfo::adjustReg(MachineBasicBlock &MBB,
194194
if (auto VLEN = ST.getRealVLen()) {
195195
// 1. Multiply the number of v-slots by the (constant) length of register
196196
const int64_t VLENB = *VLEN / 8;
197-
assert(Offset.getScalable() % (RISCV::RVVBitsPerBlock / 8) == 0 &&
197+
assert(Offset.getScalable() % RISCV::RVVBytesPerBlock == 0 &&
198198
"Reserve the stack by the multiple of one vector size.");
199199
const int64_t NumOfVReg = Offset.getScalable() / 8;
200200
const int64_t FixedOffset = NumOfVReg * VLENB;
@@ -221,11 +221,11 @@ void RISCVRegisterInfo::adjustReg(MachineBasicBlock &MBB,
221221
ScratchReg = MRI.createVirtualRegister(&RISCV::GPRRegClass);
222222

223223
assert(ScalableValue > 0 && "There is no need to get VLEN scaled value.");
224-
assert(ScalableValue % (RISCV::RVVBitsPerBlock / 8) == 0 &&
224+
assert(ScalableValue % RISCV::RVVBytesPerBlock == 0 &&
225225
"Reserve the stack by the multiple of one vector size.");
226-
assert(isInt<32>(ScalableValue / (RISCV::RVVBitsPerBlock / 8)) &&
226+
assert(isInt<32>(ScalableValue / RISCV::RVVBytesPerBlock) &&
227227
"Expect the number of vector registers within 32-bits.");
228-
uint32_t NumOfVReg = ScalableValue / (RISCV::RVVBitsPerBlock / 8);
228+
uint32_t NumOfVReg = ScalableValue / RISCV::RVVBytesPerBlock;
229229
// Only use vsetvli rather than vlenb if adjusting in the prologue or
230230
// epilogue, otherwise it may disturb the VTYPE and VL status.
231231
bool IsPrologueOrEpilogue =

0 commit comments

Comments
 (0)