Skip to content

Commit 093b8bf

Browse files
authored
[RISCV] Separate the calling convention handlers into their own file. NFC (#107484)
These are used by both SelectionDAG and GlobalISel and are separate from RISCVTargetLowering. Having a separate file is how other targets are structured. Though other targets generate most of their calling convention code through tablegen. I moved the `CC_RISV` functions from the `llvm::RISCV` namespace to `llvm::`. That's what the tablegen code on other targets does and the functions already have RISCV in their name. `RISCVCCAssignFn` is moved from `RISCVTargetLowering` to the `llvm` namespace.
1 parent 77f1b48 commit 093b8bf

File tree

6 files changed

+762
-725
lines changed

6 files changed

+762
-725
lines changed

llvm/lib/Target/RISCV/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ add_public_tablegen_target(RISCVCommonTableGen)
2929

3030
add_llvm_target(RISCVCodeGen
3131
RISCVAsmPrinter.cpp
32+
RISCVCallingConv.cpp
3233
RISCVCodeGenPrepare.cpp
3334
RISCVDeadRegisterDefinitions.cpp
3435
RISCVMakeCompressible.cpp

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

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
//===----------------------------------------------------------------------===//
1414

1515
#include "RISCVCallLowering.h"
16+
#include "RISCVCallingConv.h"
1617
#include "RISCVISelLowering.h"
1718
#include "RISCVMachineFunctionInfo.h"
1819
#include "RISCVSubtarget.h"
@@ -30,14 +31,13 @@ struct RISCVOutgoingValueAssigner : public CallLowering::OutgoingValueAssigner {
3031
// The function used internally to assign args - we ignore the AssignFn stored
3132
// by OutgoingValueAssigner since RISC-V implements its CC using a custom
3233
// function with a different signature.
33-
RISCVTargetLowering::RISCVCCAssignFn *RISCVAssignFn;
34+
RISCVCCAssignFn *RISCVAssignFn;
3435

3536
// Whether this is assigning args for a return.
3637
bool IsRet;
3738

3839
public:
39-
RISCVOutgoingValueAssigner(
40-
RISCVTargetLowering::RISCVCCAssignFn *RISCVAssignFn_, bool IsRet)
40+
RISCVOutgoingValueAssigner(RISCVCCAssignFn *RISCVAssignFn_, bool IsRet)
4141
: CallLowering::OutgoingValueAssigner(nullptr),
4242
RISCVAssignFn(RISCVAssignFn_), IsRet(IsRet) {}
4343

@@ -182,14 +182,13 @@ struct RISCVIncomingValueAssigner : public CallLowering::IncomingValueAssigner {
182182
// The function used internally to assign args - we ignore the AssignFn stored
183183
// by IncomingValueAssigner since RISC-V implements its CC using a custom
184184
// function with a different signature.
185-
RISCVTargetLowering::RISCVCCAssignFn *RISCVAssignFn;
185+
RISCVCCAssignFn *RISCVAssignFn;
186186

187187
// Whether this is assigning args from a return.
188188
bool IsRet;
189189

190190
public:
191-
RISCVIncomingValueAssigner(
192-
RISCVTargetLowering::RISCVCCAssignFn *RISCVAssignFn_, bool IsRet)
191+
RISCVIncomingValueAssigner(RISCVCCAssignFn *RISCVAssignFn_, bool IsRet)
193192
: CallLowering::IncomingValueAssigner(nullptr),
194193
RISCVAssignFn(RISCVAssignFn_), IsRet(IsRet) {}
195194

@@ -425,7 +424,7 @@ bool RISCVCallLowering::lowerReturn(MachineIRBuilder &MIRBuilder,
425424
splitToValueTypes(OrigRetInfo, SplitRetInfos, DL, CC);
426425

427426
RISCVOutgoingValueAssigner Assigner(
428-
CC == CallingConv::Fast ? RISCV::CC_RISCV_FastCC : RISCV::CC_RISCV,
427+
CC == CallingConv::Fast ? CC_RISCV_FastCC : CC_RISCV,
429428
/*IsRet=*/true);
430429
RISCVOutgoingValueHandler Handler(MIRBuilder, MF.getRegInfo(), Ret);
431430
if (!determineAndHandleAssignments(Handler, Assigner, SplitRetInfos,
@@ -461,9 +460,9 @@ bool RISCVCallLowering::canLowerReturn(MachineFunction &MF,
461460

462461
for (unsigned I = 0, E = Outs.size(); I < E; ++I) {
463462
MVT VT = MVT::getVT(Outs[I].Ty);
464-
if (RISCV::CC_RISCV(MF.getDataLayout(), ABI, I, VT, VT, CCValAssign::Full,
465-
Outs[I].Flags[0], CCInfo, /*IsFixed=*/true,
466-
/*isRet=*/true, nullptr, TLI))
463+
if (CC_RISCV(MF.getDataLayout(), ABI, I, VT, VT, CCValAssign::Full,
464+
Outs[I].Flags[0], CCInfo, /*IsFixed=*/true,
465+
/*isRet=*/true, nullptr, TLI))
467466
return false;
468467
}
469468
return true;
@@ -576,9 +575,9 @@ bool RISCVCallLowering::lowerFormalArguments(MachineIRBuilder &MIRBuilder,
576575
++Index;
577576
}
578577

579-
RISCVIncomingValueAssigner Assigner(
580-
CC == CallingConv::Fast ? RISCV::CC_RISCV_FastCC : RISCV::CC_RISCV,
581-
/*IsRet=*/false);
578+
RISCVIncomingValueAssigner Assigner(CC == CallingConv::Fast ? CC_RISCV_FastCC
579+
: CC_RISCV,
580+
/*IsRet=*/false);
582581
RISCVFormalArgHandler Handler(MIRBuilder, MF.getRegInfo());
583582

584583
SmallVector<CCValAssign, 16> ArgLocs;
@@ -639,7 +638,7 @@ bool RISCVCallLowering::lowerCall(MachineIRBuilder &MIRBuilder,
639638
Call.addRegMask(TRI->getCallPreservedMask(MF, Info.CallConv));
640639

641640
RISCVOutgoingValueAssigner ArgAssigner(
642-
CC == CallingConv::Fast ? RISCV::CC_RISCV_FastCC : RISCV::CC_RISCV,
641+
CC == CallingConv::Fast ? CC_RISCV_FastCC : CC_RISCV,
643642
/*IsRet=*/false);
644643
RISCVOutgoingValueHandler ArgHandler(MIRBuilder, MF.getRegInfo(), Call);
645644
if (!determineAndHandleAssignments(ArgHandler, ArgAssigner, SplitArgInfos,
@@ -667,7 +666,7 @@ bool RISCVCallLowering::lowerCall(MachineIRBuilder &MIRBuilder,
667666
splitToValueTypes(Info.OrigRet, SplitRetInfos, DL, CC);
668667

669668
RISCVIncomingValueAssigner RetAssigner(
670-
CC == CallingConv::Fast ? RISCV::CC_RISCV_FastCC : RISCV::CC_RISCV,
669+
CC == CallingConv::Fast ? CC_RISCV_FastCC : CC_RISCV,
671670
/*IsRet=*/true);
672671
RISCVCallReturnHandler RetHandler(MIRBuilder, MF.getRegInfo(), Call);
673672
if (!determineAndHandleAssignments(RetHandler, RetAssigner, SplitRetInfos,

0 commit comments

Comments
 (0)