forked from OSchip/llvm-project
[RISCV] Move some methods out of RISCVInstrInfo and into RISCV namespace.
These methods don't access any state from RISCVInstrInfo. Make them free functions in the RISCV namespace. Reviewed By: frasercrmck Differential Revision: https://reviews.llvm.org/D127583
This commit is contained in:
parent
974dbb20bd
commit
d63b66840f
|
@ -290,7 +290,7 @@ bool RISCVExpandPseudo::expandVSPILL(MachineBasicBlock &MBB,
|
||||||
Register SrcReg = MBBI->getOperand(0).getReg();
|
Register SrcReg = MBBI->getOperand(0).getReg();
|
||||||
Register Base = MBBI->getOperand(1).getReg();
|
Register Base = MBBI->getOperand(1).getReg();
|
||||||
Register VL = MBBI->getOperand(2).getReg();
|
Register VL = MBBI->getOperand(2).getReg();
|
||||||
auto ZvlssegInfo = TII->isRVVSpillForZvlsseg(MBBI->getOpcode());
|
auto ZvlssegInfo = RISCV::isRVVSpillForZvlsseg(MBBI->getOpcode());
|
||||||
if (!ZvlssegInfo)
|
if (!ZvlssegInfo)
|
||||||
return false;
|
return false;
|
||||||
unsigned NF = ZvlssegInfo->first;
|
unsigned NF = ZvlssegInfo->first;
|
||||||
|
@ -335,7 +335,7 @@ bool RISCVExpandPseudo::expandVRELOAD(MachineBasicBlock &MBB,
|
||||||
Register DestReg = MBBI->getOperand(0).getReg();
|
Register DestReg = MBBI->getOperand(0).getReg();
|
||||||
Register Base = MBBI->getOperand(1).getReg();
|
Register Base = MBBI->getOperand(1).getReg();
|
||||||
Register VL = MBBI->getOperand(2).getReg();
|
Register VL = MBBI->getOperand(2).getReg();
|
||||||
auto ZvlssegInfo = TII->isRVVSpillForZvlsseg(MBBI->getOpcode());
|
auto ZvlssegInfo = RISCV::isRVVSpillForZvlsseg(MBBI->getOpcode());
|
||||||
if (!ZvlssegInfo)
|
if (!ZvlssegInfo)
|
||||||
return false;
|
return false;
|
||||||
unsigned NF = ZvlssegInfo->first;
|
unsigned NF = ZvlssegInfo->first;
|
||||||
|
|
|
@ -941,14 +941,14 @@ RISCVFrameLowering::assignRVVStackObjectOffsets(MachineFrameInfo &MFI) const {
|
||||||
return std::make_pair(StackSize, RVVStackAlign);
|
return std::make_pair(StackSize, RVVStackAlign);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool hasRVVSpillWithFIs(MachineFunction &MF, const RISCVInstrInfo &TII) {
|
static bool hasRVVSpillWithFIs(MachineFunction &MF) {
|
||||||
if (!MF.getSubtarget<RISCVSubtarget>().hasVInstructions())
|
if (!MF.getSubtarget<RISCVSubtarget>().hasVInstructions())
|
||||||
return false;
|
return false;
|
||||||
return any_of(MF, [&TII](const MachineBasicBlock &MBB) {
|
for (const MachineBasicBlock &MBB : MF)
|
||||||
return any_of(MBB, [&TII](const MachineInstr &MI) {
|
for (const MachineInstr &MI : MBB)
|
||||||
return TII.isRVVSpill(MI, /*CheckFIs*/ true);
|
if (RISCV::isRVVSpill(MI, /*CheckFIs*/ true))
|
||||||
});
|
return true;
|
||||||
});
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RISCVFrameLowering::processFunctionBeforeFrameFinalized(
|
void RISCVFrameLowering::processFunctionBeforeFrameFinalized(
|
||||||
|
@ -971,8 +971,6 @@ void RISCVFrameLowering::processFunctionBeforeFrameFinalized(
|
||||||
// target-independent code.
|
// target-independent code.
|
||||||
MFI.ensureMaxAlignment(RVVStackAlign);
|
MFI.ensureMaxAlignment(RVVStackAlign);
|
||||||
|
|
||||||
const RISCVInstrInfo &TII = *MF.getSubtarget<RISCVSubtarget>().getInstrInfo();
|
|
||||||
|
|
||||||
// estimateStackSize has been observed to under-estimate the final stack
|
// estimateStackSize has been observed to under-estimate the final stack
|
||||||
// size, so give ourselves wiggle-room by checking for stack size
|
// size, so give ourselves wiggle-room by checking for stack size
|
||||||
// representable an 11-bit signed field rather than 12-bits.
|
// representable an 11-bit signed field rather than 12-bits.
|
||||||
|
@ -982,7 +980,7 @@ void RISCVFrameLowering::processFunctionBeforeFrameFinalized(
|
||||||
// RVV loads & stores have no capacity to hold the immediate address offsets
|
// RVV loads & stores have no capacity to hold the immediate address offsets
|
||||||
// so we must always reserve an emergency spill slot if the MachineFunction
|
// so we must always reserve an emergency spill slot if the MachineFunction
|
||||||
// contains any RVV spills.
|
// contains any RVV spills.
|
||||||
if (!isInt<11>(MFI.estimateStackSize(MF)) || hasRVVSpillWithFIs(MF, TII)) {
|
if (!isInt<11>(MFI.estimateStackSize(MF)) || hasRVVSpillWithFIs(MF)) {
|
||||||
int RegScavFI = MFI.CreateStackObject(RegInfo->getSpillSize(*RC),
|
int RegScavFI = MFI.CreateStackObject(RegInfo->getSpillSize(*RC),
|
||||||
RegInfo->getSpillAlign(*RC), false);
|
RegInfo->getSpillAlign(*RC), false);
|
||||||
RS->addScavengingFrameIndex(RegScavFI);
|
RS->addScavengingFrameIndex(RegScavFI);
|
||||||
|
|
|
@ -1413,11 +1413,10 @@ void RISCVInsertVSETVLI::doLocalPostpass(MachineBasicBlock &MBB) {
|
||||||
|
|
||||||
void RISCVInsertVSETVLI::insertReadVL(MachineBasicBlock &MBB) {
|
void RISCVInsertVSETVLI::insertReadVL(MachineBasicBlock &MBB) {
|
||||||
const MachineFunction *MF = MBB.getParent();
|
const MachineFunction *MF = MBB.getParent();
|
||||||
const RISCVInstrInfo *TII = MF->getSubtarget<RISCVSubtarget>().getInstrInfo();
|
|
||||||
|
|
||||||
for (auto I = MBB.begin(), E = MBB.end(); I != E;) {
|
for (auto I = MBB.begin(), E = MBB.end(); I != E;) {
|
||||||
MachineInstr &MI = *I++;
|
MachineInstr &MI = *I++;
|
||||||
if (TII->isFaultFirstLoad(MI)) {
|
if (RISCV::isFaultFirstLoad(MI)) {
|
||||||
Register VLOutput = MI.getOperand(1).getReg();
|
Register VLOutput = MI.getOperand(1).getReg();
|
||||||
if (!MRI->use_nodbg_empty(VLOutput))
|
if (!MRI->use_nodbg_empty(VLOutput))
|
||||||
BuildMI(MBB, I, MI.getDebugLoc(), TII->get(RISCV::PseudoReadVL),
|
BuildMI(MBB, I, MI.getDebugLoc(), TII->get(RISCV::PseudoReadVL),
|
||||||
|
|
|
@ -1878,7 +1878,7 @@ static bool isRVVWholeLoadStore(unsigned Opcode) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RISCVInstrInfo::isRVVSpill(const MachineInstr &MI, bool CheckFIs) const {
|
bool RISCV::isRVVSpill(const MachineInstr &MI, bool CheckFIs) {
|
||||||
// RVV lacks any support for immediate addressing for stack addresses, so be
|
// RVV lacks any support for immediate addressing for stack addresses, so be
|
||||||
// conservative.
|
// conservative.
|
||||||
unsigned Opcode = MI.getOpcode();
|
unsigned Opcode = MI.getOpcode();
|
||||||
|
@ -1891,7 +1891,7 @@ bool RISCVInstrInfo::isRVVSpill(const MachineInstr &MI, bool CheckFIs) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<std::pair<unsigned, unsigned>>
|
Optional<std::pair<unsigned, unsigned>>
|
||||||
RISCVInstrInfo::isRVVSpillForZvlsseg(unsigned Opcode) const {
|
RISCV::isRVVSpillForZvlsseg(unsigned Opcode) {
|
||||||
switch (Opcode) {
|
switch (Opcode) {
|
||||||
default:
|
default:
|
||||||
return None;
|
return None;
|
||||||
|
@ -1931,7 +1931,7 @@ RISCVInstrInfo::isRVVSpillForZvlsseg(unsigned Opcode) const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RISCVInstrInfo::isFaultFirstLoad(const MachineInstr &MI) const {
|
bool RISCV::isFaultFirstLoad(const MachineInstr &MI) {
|
||||||
return MI.getNumExplicitDefs() == 2 && MI.modifiesRegister(RISCV::VL) &&
|
return MI.getNumExplicitDefs() == 2 && MI.modifiesRegister(RISCV::VL) &&
|
||||||
!MI.isInlineAsm();
|
!MI.isInlineAsm();
|
||||||
}
|
}
|
||||||
|
|
|
@ -177,22 +177,21 @@ public:
|
||||||
MachineBasicBlock::iterator II, const DebugLoc &DL, int64_t Amount,
|
MachineBasicBlock::iterator II, const DebugLoc &DL, int64_t Amount,
|
||||||
MachineInstr::MIFlag Flag = MachineInstr::NoFlags) const;
|
MachineInstr::MIFlag Flag = MachineInstr::NoFlags) const;
|
||||||
|
|
||||||
// Returns true if the given MI is an RVV instruction opcode for which we may
|
|
||||||
// expect to see a FrameIndex operand. When CheckFIs is true, the instruction
|
|
||||||
// must contain at least one FrameIndex operand.
|
|
||||||
bool isRVVSpill(const MachineInstr &MI, bool CheckFIs) const;
|
|
||||||
|
|
||||||
Optional<std::pair<unsigned, unsigned>>
|
|
||||||
isRVVSpillForZvlsseg(unsigned Opcode) const;
|
|
||||||
|
|
||||||
bool isFaultFirstLoad(const MachineInstr &MI) const;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const RISCVSubtarget &STI;
|
const RISCVSubtarget &STI;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace RISCV {
|
namespace RISCV {
|
||||||
|
|
||||||
|
// Returns true if the given MI is an RVV instruction opcode for which we may
|
||||||
|
// expect to see a FrameIndex operand. When CheckFIs is true, the instruction
|
||||||
|
// must contain at least one FrameIndex operand.
|
||||||
|
bool isRVVSpill(const MachineInstr &MI, bool CheckFIs);
|
||||||
|
|
||||||
|
Optional<std::pair<unsigned, unsigned>> isRVVSpillForZvlsseg(unsigned Opcode);
|
||||||
|
|
||||||
|
bool isFaultFirstLoad(const MachineInstr &MI);
|
||||||
|
|
||||||
// Implemented in RISCVGenInstrInfo.inc
|
// Implemented in RISCVGenInstrInfo.inc
|
||||||
int16_t getNamedOperandIdx(uint16_t Opcode, uint16_t NamedIndex);
|
int16_t getNamedOperandIdx(uint16_t Opcode, uint16_t NamedIndex);
|
||||||
|
|
||||||
|
|
|
@ -145,7 +145,6 @@ static bool lowerRISCVVMachineInstrToMCInst(const MachineInstr *MI,
|
||||||
|
|
||||||
const TargetRegisterInfo *TRI =
|
const TargetRegisterInfo *TRI =
|
||||||
MF->getSubtarget<RISCVSubtarget>().getRegisterInfo();
|
MF->getSubtarget<RISCVSubtarget>().getRegisterInfo();
|
||||||
const RISCVInstrInfo *TII = MF->getSubtarget<RISCVSubtarget>().getInstrInfo();
|
|
||||||
|
|
||||||
assert(TRI && "TargetRegisterInfo expected");
|
assert(TRI && "TargetRegisterInfo expected");
|
||||||
|
|
||||||
|
@ -160,7 +159,7 @@ static bool lowerRISCVVMachineInstrToMCInst(const MachineInstr *MI,
|
||||||
if (RISCVII::hasSEWOp(TSFlags))
|
if (RISCVII::hasSEWOp(TSFlags))
|
||||||
--NumOps;
|
--NumOps;
|
||||||
|
|
||||||
bool hasVLOutput = TII->isFaultFirstLoad(*MI);
|
bool hasVLOutput = RISCV::isFaultFirstLoad(*MI);
|
||||||
for (unsigned OpNo = 0; OpNo != NumOps; ++OpNo) {
|
for (unsigned OpNo = 0; OpNo != NumOps; ++OpNo) {
|
||||||
const MachineOperand &MO = MI->getOperand(OpNo);
|
const MachineOperand &MO = MI->getOperand(OpNo);
|
||||||
// Skip vl ouput. It should be the second output.
|
// Skip vl ouput. It should be the second output.
|
||||||
|
|
|
@ -174,7 +174,7 @@ void RISCVRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II,
|
||||||
Register FrameReg;
|
Register FrameReg;
|
||||||
StackOffset Offset =
|
StackOffset Offset =
|
||||||
getFrameLowering(MF)->getFrameIndexReference(MF, FrameIndex, FrameReg);
|
getFrameLowering(MF)->getFrameIndexReference(MF, FrameIndex, FrameReg);
|
||||||
bool IsRVVSpill = TII->isRVVSpill(MI, /*CheckFIs*/ false);
|
bool IsRVVSpill = RISCV::isRVVSpill(MI, /*CheckFIs*/ false);
|
||||||
if (!IsRVVSpill)
|
if (!IsRVVSpill)
|
||||||
Offset += StackOffset::getFixed(MI.getOperand(FIOperandNum + 1).getImm());
|
Offset += StackOffset::getFixed(MI.getOperand(FIOperandNum + 1).getImm());
|
||||||
|
|
||||||
|
@ -273,7 +273,7 @@ void RISCVRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II,
|
||||||
MI.getOperand(FIOperandNum + 1).ChangeToImmediate(Offset.getFixed());
|
MI.getOperand(FIOperandNum + 1).ChangeToImmediate(Offset.getFixed());
|
||||||
}
|
}
|
||||||
|
|
||||||
auto ZvlssegInfo = TII->isRVVSpillForZvlsseg(MI.getOpcode());
|
auto ZvlssegInfo = RISCV::isRVVSpillForZvlsseg(MI.getOpcode());
|
||||||
if (ZvlssegInfo) {
|
if (ZvlssegInfo) {
|
||||||
Register VL = MRI.createVirtualRegister(&RISCV::GPRRegClass);
|
Register VL = MRI.createVirtualRegister(&RISCV::GPRRegClass);
|
||||||
BuildMI(MBB, II, DL, TII->get(RISCV::PseudoReadVLENB), VL);
|
BuildMI(MBB, II, DL, TII->get(RISCV::PseudoReadVLENB), VL);
|
||||||
|
|
Loading…
Reference in New Issue