Skip to content

Commit 47fe9fc

Browse files
authored
[RISCV] Share ArgGPRs array between SelectionDAG and GISel. (#74152)
This will allow us to isolate the EABI from D70401 to this new function.
1 parent c4cebe5 commit 47fe9fc

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

llvm/lib/Target/RISCV/GISel/RISCVCallLowering.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -423,10 +423,6 @@ bool RISCVCallLowering::lowerReturn(MachineIRBuilder &MIRBuilder,
423423
return true;
424424
}
425425

426-
static const MCPhysReg ArgGPRs[] = {RISCV::X10, RISCV::X11, RISCV::X12,
427-
RISCV::X13, RISCV::X14, RISCV::X15,
428-
RISCV::X16, RISCV::X17};
429-
430426
/// If there are varargs that were passed in a0-a7, the data in those registers
431427
/// must be copied to the varargs save area on the stack.
432428
void RISCVCallLowering::saveVarArgRegisters(
@@ -435,7 +431,7 @@ void RISCVCallLowering::saveVarArgRegisters(
435431
MachineFunction &MF = MIRBuilder.getMF();
436432
const RISCVSubtarget &Subtarget = MF.getSubtarget<RISCVSubtarget>();
437433
unsigned XLenInBytes = Subtarget.getXLen() / 8;
438-
ArrayRef<MCPhysReg> ArgRegs(ArgGPRs);
434+
ArrayRef<MCPhysReg> ArgRegs = RISCV::getArgGPRs();
439435
unsigned Idx = CCInfo.getFirstUnallocated(ArgRegs);
440436

441437
// Offset of the first variable argument from stack pointer, and size of

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16844,10 +16844,6 @@ void RISCVTargetLowering::AdjustInstrPostInstrSelection(MachineInstr &MI,
1684416844
// register-size fields in the same situations they would be for fixed
1684516845
// arguments.
1684616846

16847-
static const MCPhysReg ArgGPRs[] = {
16848-
RISCV::X10, RISCV::X11, RISCV::X12, RISCV::X13,
16849-
RISCV::X14, RISCV::X15, RISCV::X16, RISCV::X17
16850-
};
1685116847
static const MCPhysReg ArgFPR16s[] = {
1685216848
RISCV::F10_H, RISCV::F11_H, RISCV::F12_H, RISCV::F13_H,
1685316849
RISCV::F14_H, RISCV::F15_H, RISCV::F16_H, RISCV::F17_H
@@ -16872,13 +16868,22 @@ static const MCPhysReg ArgVRM4s[] = {RISCV::V8M4, RISCV::V12M4, RISCV::V16M4,
1687216868
RISCV::V20M4};
1687316869
static const MCPhysReg ArgVRM8s[] = {RISCV::V8M8, RISCV::V16M8};
1687416870

16871+
ArrayRef<MCPhysReg> RISCV::getArgGPRs() {
16872+
static const MCPhysReg ArgGPRs[] = {RISCV::X10, RISCV::X11, RISCV::X12,
16873+
RISCV::X13, RISCV::X14, RISCV::X15,
16874+
RISCV::X16, RISCV::X17};
16875+
16876+
return ArrayRef(ArgGPRs);
16877+
}
16878+
1687516879
// Pass a 2*XLEN argument that has been split into two XLEN values through
1687616880
// registers or the stack as necessary.
1687716881
static bool CC_RISCVAssign2XLen(unsigned XLen, CCState &State, CCValAssign VA1,
1687816882
ISD::ArgFlagsTy ArgFlags1, unsigned ValNo2,
1687916883
MVT ValVT2, MVT LocVT2,
1688016884
ISD::ArgFlagsTy ArgFlags2) {
1688116885
unsigned XLenInBytes = XLen / 8;
16886+
ArrayRef<MCPhysReg> ArgGPRs = RISCV::getArgGPRs();
1688216887
if (Register Reg = State.AllocateReg(ArgGPRs)) {
1688316888
// At least one half can be passed via register.
1688416889
State.addLoc(CCValAssign::getReg(VA1.getValNo(), VA1.getValVT(), Reg,
@@ -16999,6 +17004,8 @@ bool RISCV::CC_RISCV(const DataLayout &DL, RISCVABI::ABI ABI, unsigned ValNo,
1699917004
LocInfo = CCValAssign::BCvt;
1700017005
}
1700117006

17007+
ArrayRef<MCPhysReg> ArgGPRs = RISCV::getArgGPRs();
17008+
1700217009
// If this is a variadic argument, the RISC-V calling convention requires
1700317010
// that it is assigned an 'even' or 'aligned' register if it has 8-byte
1700417011
// alignment (RV32) or 16-byte alignment (RV64). An aligned register should
@@ -17684,7 +17691,7 @@ SDValue RISCVTargetLowering::LowerFormalArguments(
1768417691
MF.getInfo<RISCVMachineFunctionInfo>()->setIsVectorCall();
1768517692

1768617693
if (IsVarArg) {
17687-
ArrayRef<MCPhysReg> ArgRegs = ArrayRef(ArgGPRs);
17694+
ArrayRef<MCPhysReg> ArgRegs = RISCV::getArgGPRs();
1768817695
unsigned Idx = CCInfo.getFirstUnallocated(ArgRegs);
1768917696
const TargetRegisterClass *RC = &RISCV::GPRRegClass;
1769017697
MachineFrameInfo &MFI = MF.getFrameInfo();

llvm/lib/Target/RISCV/RISCVISelLowering.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,9 @@ bool CC_RISCV_FastCC(const DataLayout &DL, RISCVABI::ABI ABI, unsigned ValNo,
986986
bool CC_RISCV_GHC(unsigned ValNo, MVT ValVT, MVT LocVT,
987987
CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags,
988988
CCState &State);
989+
990+
ArrayRef<MCPhysReg> getArgGPRs();
991+
989992
} // end namespace RISCV
990993

991994
namespace RISCVVIntrinsicsTable {

0 commit comments

Comments
 (0)