LLVM 24.0.0git
RISCVCallingConv.cpp
Go to the documentation of this file.
1//===-- RISCVCallingConv.cpp - RISC-V Custom CC Routines ------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains the custom routines for the RISC-V Calling Convention.
10//
11//===----------------------------------------------------------------------===//
12
13#include "RISCVCallingConv.h"
15#include "RISCVSubtarget.h"
16#include "llvm/IR/DataLayout.h"
17#include "llvm/MC/MCRegister.h"
18
19using namespace llvm;
20
21// This does not have the regular `CCAssignFn` signature, it has an extra
22// `bool IsRet` parameter.
23static bool CC_RISCV_Impl(unsigned ValNo, MVT ValVT, MVT LocVT,
25 ISD::ArgFlagsTy ArgFlags, Type *OrigTy,
26 CCState &State, bool IsRet);
27
28/// Used for assigning arguments with CallingConvention::GHC
30
31/// Used for assigning arguments with CallingConvention::Fast
33
34bool llvm::CC_RISCV(unsigned ValNo, MVT ValVT, MVT LocVT,
35 CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags,
36 Type *OrigTy, CCState &State) {
37 if (State.getCallingConv() == CallingConv::GHC)
38 return CC_RISCV_GHC(ValNo, ValVT, LocVT, LocInfo, ArgFlags, OrigTy, State);
39
40 if (State.getCallingConv() == CallingConv::Fast)
41 return CC_RISCV_FastCC(ValNo, ValVT, LocVT, LocInfo, ArgFlags, OrigTy,
42 State);
43
44 // For all other cases, use the standard calling convention
45 return CC_RISCV_Impl(ValNo, ValVT, LocVT, LocInfo, ArgFlags, OrigTy, State,
46 /*IsRet=*/false);
47}
48
49bool llvm::RetCC_RISCV(unsigned ValNo, MVT ValVT, MVT LocVT,
50 CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags,
51 Type *OrigTy, CCState &State) {
52 // Always use the standard calling convention.
53 return CC_RISCV_Impl(ValNo, ValVT, LocVT, LocInfo, ArgFlags, OrigTy, State,
54 /*IsRet=*/true);
55}
56
57// Calling Convention Implementation.
58// The expectations for frontend ABI lowering vary from target to target.
59// Ideally, an LLVM frontend would be able to avoid worrying about many ABI
60// details, but this is a longer term goal. For now, we simply try to keep the
61// role of the frontend as simple and well-defined as possible. The rules can
62// be summarised as:
63// * Never split up large scalar arguments. We handle them here.
64// * If a hardfloat calling convention is being used, and the struct may be
65// passed in a pair of registers (fp+fp, int+fp), and both registers are
66// available, then pass as two separate arguments. If either the GPRs or FPRs
67// are exhausted, then pass according to the rule below.
68// * If a struct could never be passed in registers or directly in a stack
69// slot (as it is larger than 2*XLEN and the floating point rules don't
70// apply), then pass it using a pointer with the byval attribute.
71// * If a struct is less than 2*XLEN, then coerce to either a two-element
72// word-sized array or a 2*XLEN scalar (depending on alignment).
73// * The frontend can determine whether a struct is returned by reference or
74// not based on its size and fields. If it will be returned by reference, the
75// frontend must modify the prototype so a pointer with the sret annotation is
76// passed as the first argument. This is not necessary for large scalar
77// returns.
78// * Struct return values and varargs should be coerced to structs containing
79// register-size fields in the same situations they would be for fixed
80// arguments.
81
82static const MCPhysReg ArgFPR16s[] = {RISCV::F10_H, RISCV::F11_H, RISCV::F12_H,
83 RISCV::F13_H, RISCV::F14_H, RISCV::F15_H,
84 RISCV::F16_H, RISCV::F17_H};
85static const MCPhysReg ArgFPR32s[] = {RISCV::F10_F, RISCV::F11_F, RISCV::F12_F,
86 RISCV::F13_F, RISCV::F14_F, RISCV::F15_F,
87 RISCV::F16_F, RISCV::F17_F};
88static const MCPhysReg ArgFPR64s[] = {RISCV::F10_D, RISCV::F11_D, RISCV::F12_D,
89 RISCV::F13_D, RISCV::F14_D, RISCV::F15_D,
90 RISCV::F16_D, RISCV::F17_D};
91static const MCPhysReg ArgFPR128s[] = {RISCV::F10_Q, RISCV::F11_Q, RISCV::F12_Q,
92 RISCV::F13_Q, RISCV::F14_Q, RISCV::F15_Q,
93 RISCV::F16_Q, RISCV::F17_Q};
94
95// This is an interim calling convention and it may be changed in the future.
96static const MCPhysReg ArgVRs[] = {
97 RISCV::V8, RISCV::V9, RISCV::V10, RISCV::V11, RISCV::V12, RISCV::V13,
98 RISCV::V14, RISCV::V15, RISCV::V16, RISCV::V17, RISCV::V18, RISCV::V19,
99 RISCV::V20, RISCV::V21, RISCV::V22, RISCV::V23};
100static const MCPhysReg ArgVRM2s[] = {RISCV::V8M2, RISCV::V10M2, RISCV::V12M2,
101 RISCV::V14M2, RISCV::V16M2, RISCV::V18M2,
102 RISCV::V20M2, RISCV::V22M2};
103static const MCPhysReg ArgVRM4s[] = {RISCV::V8M4, RISCV::V12M4, RISCV::V16M4,
104 RISCV::V20M4};
105static const MCPhysReg ArgVRM8s[] = {RISCV::V8M8, RISCV::V16M8};
106static const MCPhysReg ArgVRN2M1s[] = {
107 RISCV::V8_V9, RISCV::V9_V10, RISCV::V10_V11, RISCV::V11_V12,
108 RISCV::V12_V13, RISCV::V13_V14, RISCV::V14_V15, RISCV::V15_V16,
109 RISCV::V16_V17, RISCV::V17_V18, RISCV::V18_V19, RISCV::V19_V20,
110 RISCV::V20_V21, RISCV::V21_V22, RISCV::V22_V23};
111static const MCPhysReg ArgVRN3M1s[] = {
112 RISCV::V8_V9_V10, RISCV::V9_V10_V11, RISCV::V10_V11_V12,
113 RISCV::V11_V12_V13, RISCV::V12_V13_V14, RISCV::V13_V14_V15,
114 RISCV::V14_V15_V16, RISCV::V15_V16_V17, RISCV::V16_V17_V18,
115 RISCV::V17_V18_V19, RISCV::V18_V19_V20, RISCV::V19_V20_V21,
116 RISCV::V20_V21_V22, RISCV::V21_V22_V23};
117static const MCPhysReg ArgVRN4M1s[] = {
118 RISCV::V8_V9_V10_V11, RISCV::V9_V10_V11_V12, RISCV::V10_V11_V12_V13,
119 RISCV::V11_V12_V13_V14, RISCV::V12_V13_V14_V15, RISCV::V13_V14_V15_V16,
120 RISCV::V14_V15_V16_V17, RISCV::V15_V16_V17_V18, RISCV::V16_V17_V18_V19,
121 RISCV::V17_V18_V19_V20, RISCV::V18_V19_V20_V21, RISCV::V19_V20_V21_V22,
122 RISCV::V20_V21_V22_V23};
123static const MCPhysReg ArgVRN5M1s[] = {
124 RISCV::V8_V9_V10_V11_V12, RISCV::V9_V10_V11_V12_V13,
125 RISCV::V10_V11_V12_V13_V14, RISCV::V11_V12_V13_V14_V15,
126 RISCV::V12_V13_V14_V15_V16, RISCV::V13_V14_V15_V16_V17,
127 RISCV::V14_V15_V16_V17_V18, RISCV::V15_V16_V17_V18_V19,
128 RISCV::V16_V17_V18_V19_V20, RISCV::V17_V18_V19_V20_V21,
129 RISCV::V18_V19_V20_V21_V22, RISCV::V19_V20_V21_V22_V23};
130static const MCPhysReg ArgVRN6M1s[] = {
131 RISCV::V8_V9_V10_V11_V12_V13, RISCV::V9_V10_V11_V12_V13_V14,
132 RISCV::V10_V11_V12_V13_V14_V15, RISCV::V11_V12_V13_V14_V15_V16,
133 RISCV::V12_V13_V14_V15_V16_V17, RISCV::V13_V14_V15_V16_V17_V18,
134 RISCV::V14_V15_V16_V17_V18_V19, RISCV::V15_V16_V17_V18_V19_V20,
135 RISCV::V16_V17_V18_V19_V20_V21, RISCV::V17_V18_V19_V20_V21_V22,
136 RISCV::V18_V19_V20_V21_V22_V23};
137static const MCPhysReg ArgVRN7M1s[] = {
138 RISCV::V8_V9_V10_V11_V12_V13_V14, RISCV::V9_V10_V11_V12_V13_V14_V15,
139 RISCV::V10_V11_V12_V13_V14_V15_V16, RISCV::V11_V12_V13_V14_V15_V16_V17,
140 RISCV::V12_V13_V14_V15_V16_V17_V18, RISCV::V13_V14_V15_V16_V17_V18_V19,
141 RISCV::V14_V15_V16_V17_V18_V19_V20, RISCV::V15_V16_V17_V18_V19_V20_V21,
142 RISCV::V16_V17_V18_V19_V20_V21_V22, RISCV::V17_V18_V19_V20_V21_V22_V23};
143static const MCPhysReg ArgVRN8M1s[] = {RISCV::V8_V9_V10_V11_V12_V13_V14_V15,
144 RISCV::V9_V10_V11_V12_V13_V14_V15_V16,
145 RISCV::V10_V11_V12_V13_V14_V15_V16_V17,
146 RISCV::V11_V12_V13_V14_V15_V16_V17_V18,
147 RISCV::V12_V13_V14_V15_V16_V17_V18_V19,
148 RISCV::V13_V14_V15_V16_V17_V18_V19_V20,
149 RISCV::V14_V15_V16_V17_V18_V19_V20_V21,
150 RISCV::V15_V16_V17_V18_V19_V20_V21_V22,
151 RISCV::V16_V17_V18_V19_V20_V21_V22_V23};
152static const MCPhysReg ArgVRN2M2s[] = {RISCV::V8M2_V10M2, RISCV::V10M2_V12M2,
153 RISCV::V12M2_V14M2, RISCV::V14M2_V16M2,
154 RISCV::V16M2_V18M2, RISCV::V18M2_V20M2,
155 RISCV::V20M2_V22M2};
156static const MCPhysReg ArgVRN3M2s[] = {
157 RISCV::V8M2_V10M2_V12M2, RISCV::V10M2_V12M2_V14M2,
158 RISCV::V12M2_V14M2_V16M2, RISCV::V14M2_V16M2_V18M2,
159 RISCV::V16M2_V18M2_V20M2, RISCV::V18M2_V20M2_V22M2};
160static const MCPhysReg ArgVRN4M2s[] = {
161 RISCV::V8M2_V10M2_V12M2_V14M2, RISCV::V10M2_V12M2_V14M2_V16M2,
162 RISCV::V12M2_V14M2_V16M2_V18M2, RISCV::V14M2_V16M2_V18M2_V20M2,
163 RISCV::V16M2_V18M2_V20M2_V22M2};
164static const MCPhysReg ArgVRN2M4s[] = {RISCV::V8M4_V12M4, RISCV::V12M4_V16M4,
165 RISCV::V16M4_V20M4};
166
168 RISCVABI::ABI ABI = STI.getTargetABI();
169
170 // The GPRs used for passing arguments in the ILP32* and LP64* ABIs. The
171 // ILP32E/LP64E ABIs only use the first 6 (X10-X15).
172 static const MCPhysReg ArgGPRs[] = {RISCV::X10, RISCV::X11, RISCV::X12,
173 RISCV::X13, RISCV::X14, RISCV::X15,
174 RISCV::X16, RISCV::X17};
175
176 return ArrayRef(ArgGPRs).take_front(RISCVABI::isRVE(ABI) ? 6 : 8);
177}
178
180 if (STI.isSoftFPABI() || !STI.hasStdExtF())
181 return {};
182
183 if (STI.hasStdExtQ())
184 return ArrayRef(ArgFPR128s);
185
186 if (STI.hasStdExtD())
187 return ArrayRef(ArgFPR64s);
188
189 return ArrayRef(ArgFPR32s);
190}
191
193 if (STI.hasVInstructions())
194 return ArrayRef(ArgVRs);
195
196 return {};
197}
198
200 // The GPRs used for passing arguments in the ILP32* and LP64* ABIs. The
201 // ILP32E/LP64E ABIs only use the first 6 (X10-X15).
202 static const MCPhysReg ArgGPRs[] = {RISCV::X10_H, RISCV::X11_H, RISCV::X12_H,
203 RISCV::X13_H, RISCV::X14_H, RISCV::X15_H,
204 RISCV::X16_H, RISCV::X17_H};
205
206 return ArrayRef(ArgGPRs).take_front(RISCVABI::isRVE(ABI) ? 6 : 8);
207}
208
210 // The GPRs used for passing arguments in the ILP32* and LP64* ABIs. The
211 // ILP32E/LP64E ABIs only use the first 6 (X10-X15).
212 static const MCPhysReg ArgGPRs[] = {RISCV::X10_W, RISCV::X11_W, RISCV::X12_W,
213 RISCV::X13_W, RISCV::X14_W, RISCV::X15_W,
214 RISCV::X16_W, RISCV::X17_W};
215
216 return ArrayRef(ArgGPRs).take_front(RISCVABI::isRVE(ABI) ? 6 : 8);
217}
218
220 // The GPRs used for passing arguments in the FastCC, X5 and X6 might be used
221 // for save-restore libcall, so we don't use them.
222 // Don't use X7 for fastcc, since Zicfilp uses X7 as the label register.
223 // The ILP32E/LP64E ABIs only use the first 6 (X10-X15).
224 static const MCPhysReg FastCCGPRs[] = {
225 RISCV::X10, RISCV::X11, RISCV::X12, RISCV::X13, RISCV::X14, RISCV::X15,
226 RISCV::X16, RISCV::X17, RISCV::X28, RISCV::X29, RISCV::X30, RISCV::X31};
227
228 return ArrayRef(FastCCGPRs).take_front(RISCVABI::isRVE(ABI) ? 6 : 12);
229}
230
232 // The GPRs used for passing arguments in the FastCC, X5 and X6 might be used
233 // for save-restore libcall, so we don't use them.
234 // Don't use X7 for fastcc, since Zicfilp uses X7 as the label register.
235 // The ILP32E/LP64E ABIs only use the first 6 (X10-X15).
236 static const MCPhysReg FastCCGPRs[] = {
237 RISCV::X10_H, RISCV::X11_H, RISCV::X12_H, RISCV::X13_H,
238 RISCV::X14_H, RISCV::X15_H, RISCV::X16_H, RISCV::X17_H,
239 RISCV::X28_H, RISCV::X29_H, RISCV::X30_H, RISCV::X31_H};
240
241 return ArrayRef(FastCCGPRs).take_front(RISCVABI::isRVE(ABI) ? 6 : 12);
242}
243
245 // The GPRs used for passing arguments in the FastCC, X5 and X6 might be used
246 // for save-restore libcall, so we don't use them.
247 // Don't use X7 for fastcc, since Zicfilp uses X7 as the label register.
248 // The ILP32E/LP64E ABIs only use the first 6 (X10-X15).
249 static const MCPhysReg FastCCGPRs[] = {
250 RISCV::X10_W, RISCV::X11_W, RISCV::X12_W, RISCV::X13_W,
251 RISCV::X14_W, RISCV::X15_W, RISCV::X16_W, RISCV::X17_W,
252 RISCV::X28_W, RISCV::X29_W, RISCV::X30_W, RISCV::X31_W};
253
254 return ArrayRef(FastCCGPRs).take_front(RISCVABI::isRVE(ABI) ? 6 : 12);
255}
256
257// Pass a 2*XLEN argument that has been split into two XLEN values through
258// registers or the stack as necessary.
260 ISD::ArgFlagsTy ArgFlags1, unsigned ValNo2,
261 MVT ValVT2, MVT LocVT2,
262 ISD::ArgFlagsTy ArgFlags2,
263 const RISCVSubtarget &Subtarget) {
264 unsigned XLen = Subtarget.getXLen();
265 unsigned XLenInBytes = XLen / 8;
266
268
269 if (MCRegister Reg = State.AllocateReg(ArgGPRs)) {
270 // At least one half can be passed via register.
271 State.addLoc(CCValAssign::getReg(VA1.getValNo(), VA1.getValVT(), Reg,
273 } else {
274 // Both halves must be passed on the stack, with proper alignment.
275 // TODO: To be compatible with GCC's behaviors, we clamp the alignment by
276 // the ABI stack alignment. This behavior may be changed when RV32E/ILP32E
277 // is ratified.
278 Align StackAlign =
279 std::min(RISCVABI::getStackAlignment(Subtarget.getTargetABI()),
280 std::max(Align(XLenInBytes), ArgFlags1.getNonZeroOrigAlign()));
281 State.addLoc(
283 State.AllocateStack(XLenInBytes, StackAlign),
285 State.addLoc(CCValAssign::getMem(
286 ValNo2, ValVT2, State.AllocateStack(XLenInBytes, Align(XLenInBytes)),
287 LocVT2, CCValAssign::Full));
288 return false;
289 }
290
291 if (MCRegister Reg = State.AllocateReg(ArgGPRs)) {
292 // The second half can also be passed via register.
293 State.addLoc(
294 CCValAssign::getReg(ValNo2, ValVT2, Reg, LocVT2, CCValAssign::Full));
295 } else {
296 // The second half is passed via the stack, without additional alignment.
297 State.addLoc(CCValAssign::getMem(
298 ValNo2, ValVT2, State.AllocateStack(XLenInBytes, Align(XLenInBytes)),
299 LocVT2, CCValAssign::Full));
300 }
301
302 return false;
303}
304
305static MCRegister allocateRVVReg(MVT LocVT, unsigned ValNo, CCState &State,
306 const RISCVTargetLowering &TLI) {
307 const TargetRegisterClass *RC = TLI.getRegClassFor(LocVT);
308 if (RC == &RISCV::VRRegClass) {
309 // Assign the first mask argument to V0.
310 // This is an interim calling convention and it may be changed in the
311 // future.
312 if (LocVT.getVectorElementType() == MVT::i1)
313 if (MCRegister Reg = State.AllocateReg(RISCV::V0))
314 return Reg;
315 return State.AllocateReg(ArgVRs);
316 }
317 if (RC == &RISCV::VRM2RegClass)
318 return State.AllocateReg(ArgVRM2s);
319 if (RC == &RISCV::VRM4RegClass)
320 return State.AllocateReg(ArgVRM4s);
321 if (RC == &RISCV::VRM8RegClass)
322 return State.AllocateReg(ArgVRM8s);
323 if (RC == &RISCV::VRN2M1RegClass)
324 return State.AllocateReg(ArgVRN2M1s);
325 if (RC == &RISCV::VRN3M1RegClass)
326 return State.AllocateReg(ArgVRN3M1s);
327 if (RC == &RISCV::VRN4M1RegClass)
328 return State.AllocateReg(ArgVRN4M1s);
329 if (RC == &RISCV::VRN5M1RegClass)
330 return State.AllocateReg(ArgVRN5M1s);
331 if (RC == &RISCV::VRN6M1RegClass)
332 return State.AllocateReg(ArgVRN6M1s);
333 if (RC == &RISCV::VRN7M1RegClass)
334 return State.AllocateReg(ArgVRN7M1s);
335 if (RC == &RISCV::VRN8M1RegClass)
336 return State.AllocateReg(ArgVRN8M1s);
337 if (RC == &RISCV::VRN2M2RegClass)
338 return State.AllocateReg(ArgVRN2M2s);
339 if (RC == &RISCV::VRN3M2RegClass)
340 return State.AllocateReg(ArgVRN3M2s);
341 if (RC == &RISCV::VRN4M2RegClass)
342 return State.AllocateReg(ArgVRN4M2s);
343 if (RC == &RISCV::VRN2M4RegClass)
344 return State.AllocateReg(ArgVRN2M4s);
345 llvm_unreachable("Unhandled register class for ValueType");
346}
347
348// Implements the RISC-V calling convention. Returns true upon failure.
349//
350// This has a slightly different signature to CCAssignFn - it adds `bool IsRet`.
351static bool CC_RISCV_Impl(unsigned ValNo, MVT ValVT, MVT LocVT,
352 CCValAssign::LocInfo LocInfo,
353 ISD::ArgFlagsTy ArgFlags, Type *OrigTy,
354 CCState &State, bool IsRet) {
355 assert(ValVT == LocVT && "Expected ValVT and LocVT to match");
356 const MachineFunction &MF = State.getMachineFunction();
357 const DataLayout &DL = MF.getDataLayout();
359 const RISCVTargetLowering &TLI = *Subtarget.getTargetLowering();
360
361 unsigned XLen = Subtarget.getXLen();
362 MVT XLenVT = Subtarget.getXLenVT();
363
364 if (ArgFlags.isNest()) {
365 // Static chain parameter must not be passed in normal argument registers,
366 // so we assign t2/t3 for it as done in GCC's
367 // __builtin_call_with_static_chain
368 bool HasCFBranch =
369 MF.getInfo<RISCVMachineFunctionInfo>()->hasCFProtectionBranch();
370
371 // Normal: t2, Branch control flow protection: t3
372 const auto StaticChainReg = HasCFBranch ? RISCV::X28 : RISCV::X7;
373
374 RISCVABI::ABI ABI = Subtarget.getTargetABI();
375 if (HasCFBranch && RISCVABI::isRVE(ABI))
377 "Nested functions with control flow protection are not "
378 "usable with ILP32E or LP64E ABI.");
379 if (MCRegister Reg = State.AllocateReg(StaticChainReg)) {
380 State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
381 return false;
382 }
383 }
384
385 // Any return value split in to more than two values can't be returned
386 // directly. Vectors are returned via the available vector registers.
387 if ((!LocVT.isVector() || Subtarget.isPExtPackedType(LocVT)) && IsRet &&
388 ValNo > 1)
389 return true;
390
391 // Double wide packed types require 2 GPRs so we can only return 1 of them.
392 if (Subtarget.isPExtPackedDoubleType(LocVT) && IsRet && ValNo > 0)
393 return true;
394
395 // AllowFPRForF16_F32 if targeting an FLEN>=32 ABI and the argument isn't
396 // variadic.
397 bool AllowFPRForF16_F32 = false;
398 // UseFPRForF64 if targeting an FLEN>=64 ABI and the argument isn't variadic.
399 bool AllowFPRForF64 = false;
400
401 RISCVABI::ABI ABI = Subtarget.getTargetABI();
403 "Unexpected ABI");
404 bool IsDoubleFPABI = RISCVABI::isDoubleFP(ABI);
405 if (IsDoubleFPABI || RISCVABI::isSingleFP(ABI))
406 AllowFPRForF16_F32 = !ArgFlags.isVarArg();
407 if (IsDoubleFPABI)
408 AllowFPRForF64 = !ArgFlags.isVarArg();
409
410 if ((LocVT == MVT::f16 || LocVT == MVT::bf16) && AllowFPRForF16_F32) {
411 if (MCRegister Reg = State.AllocateReg(ArgFPR16s)) {
412 State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
413 return false;
414 }
415 }
416
417 if (LocVT == MVT::f32 && AllowFPRForF16_F32) {
418 if (MCRegister Reg = State.AllocateReg(ArgFPR32s)) {
419 State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
420 return false;
421 }
422 }
423
424 if (LocVT == MVT::f64 && AllowFPRForF64) {
425 if (MCRegister Reg = State.AllocateReg(ArgFPR64s)) {
426 State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
427 return false;
428 }
429 }
430
431 if (LocVT == MVT::f16 && Subtarget.hasStdExtZhinxmin()) {
432 if (MCRegister Reg = State.AllocateReg(getArgGPR16s(ABI))) {
433 State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
434 return false;
435 }
436 }
437
438 if (LocVT == MVT::f32 && Subtarget.hasStdExtZfinx()) {
439 if (MCRegister Reg = State.AllocateReg(getArgGPR32s(ABI))) {
440 State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
441 return false;
442 }
443 }
444
446
447 // Zdinx use GPR without a bitcast when possible.
448 if (LocVT == MVT::f64 && XLen == 64 && Subtarget.hasStdExtZdinx()) {
449 if (MCRegister Reg = State.AllocateReg(ArgGPRs)) {
450 State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
451 return false;
452 }
453 }
454
455 // FP smaller than XLen, uses custom GPR.
456 if (LocVT == MVT::f16 || LocVT == MVT::bf16 ||
457 (LocVT == MVT::f32 && XLen == 64)) {
458 if (MCRegister Reg = State.AllocateReg(ArgGPRs)) {
459 LocVT = XLenVT;
460 State.addLoc(
461 CCValAssign::getCustomReg(ValNo, ValVT, Reg, LocVT, LocInfo));
462 return false;
463 }
464 }
465
466 // Bitcast FP to GPR if we can use a GPR register.
467 if ((XLen == 32 && LocVT == MVT::f32) || (XLen == 64 && LocVT == MVT::f64)) {
468 if (MCRegister Reg = State.AllocateReg(ArgGPRs)) {
469 LocVT = XLenVT;
470 LocInfo = CCValAssign::BCvt;
471 State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
472 return false;
473 }
474 }
475
476 // If this is a variadic argument, the RISC-V calling convention requires
477 // that it is assigned an 'even' or 'aligned' register if it has 8-byte
478 // alignment (RV32) or 16-byte alignment (RV64). An aligned register should
479 // be used regardless of whether the original argument was split during
480 // legalisation or not. The argument will not be passed by registers if the
481 // original type is larger than 2*XLEN, so the register alignment rule does
482 // not apply.
483 // TODO: To be compatible with GCC's behaviors, we clamp the alignment by the
484 // ABI stack alignment, so registers are never aligned for ILP32E/LP64E. This
485 // behavior may be changed when RV32E/ILP32E is ratified.
486 unsigned TwoXLenInBytes = (2 * XLen) / 8;
487 Align ArgAlign = std::min(ArgFlags.getNonZeroOrigAlign(),
489 if (ArgFlags.isVarArg() && ArgAlign == TwoXLenInBytes &&
490 DL.getTypeAllocSize(OrigTy) == TwoXLenInBytes) {
491 unsigned RegIdx = State.getFirstUnallocated(ArgGPRs);
492 // Skip 'odd' register if necessary.
493 if (RegIdx != std::size(ArgGPRs) && RegIdx % 2 == 1)
494 State.AllocateReg(ArgGPRs);
495 }
496
497 SmallVectorImpl<CCValAssign> &PendingLocs = State.getPendingLocs();
498 SmallVectorImpl<ISD::ArgFlagsTy> &PendingArgFlags =
499 State.getPendingArgFlags();
500
501 assert(PendingLocs.size() == PendingArgFlags.size() &&
502 "PendingLocs and PendingArgFlags out of sync");
503
504 // Handle passing f64 on RV32D with a soft float ABI or when floating point
505 // registers are exhausted. Or 64-bit P extension vectors on RV32.
506 if (XLen == 32 &&
507 (LocVT == MVT::f64 || (Subtarget.isPExtPackedDoubleType(LocVT) &&
508 !ArgFlags.isSplit() && PendingLocs.empty()))) {
509 assert(PendingLocs.empty() &&
510 "Can't lower f64 or P extension vector if it is split");
511 // Depending on available argument GPRS, f64 may be passed in a pair of
512 // GPRs, split between a GPR and the stack, or passed completely on the
513 // stack. LowerCall/LowerFormalArguments/LowerReturn must recognise these
514 // cases.
515 MCRegister Reg = State.AllocateReg(ArgGPRs);
516 if (!Reg) {
517 int64_t StackOffset = State.AllocateStack(8, Align(8));
518 State.addLoc(
519 CCValAssign::getMem(ValNo, ValVT, StackOffset, LocVT, LocInfo));
520 return false;
521 }
522 LocVT = MVT::i32;
523 State.addLoc(CCValAssign::getCustomReg(ValNo, ValVT, Reg, LocVT, LocInfo));
524 MCRegister HiReg = State.AllocateReg(ArgGPRs);
525 if (HiReg) {
526 State.addLoc(
527 CCValAssign::getCustomReg(ValNo, ValVT, HiReg, LocVT, LocInfo));
528 } else {
529 int64_t StackOffset = State.AllocateStack(4, Align(4));
530 State.addLoc(
531 CCValAssign::getCustomMem(ValNo, ValVT, StackOffset, LocVT, LocInfo));
532 }
533 return false;
534 }
535
536 // If the split argument only had two elements, it should be passed directly
537 // in registers or on the stack.
538 if ((LocVT.isScalarInteger() ||
539 (Subtarget.isPExtPackedType(LocVT) && LocVT.getSizeInBits() == XLen)) &&
540 ArgFlags.isSplitEnd() && PendingLocs.size() <= 1) {
541 assert(PendingLocs.size() == 1 && "Unexpected PendingLocs.size()");
542 // Apply the normal calling convention rules to the first half of the
543 // split argument.
544 CCValAssign VA = PendingLocs[0];
545 ISD::ArgFlagsTy AF = PendingArgFlags[0];
546 PendingLocs.clear();
547 PendingArgFlags.clear();
548 return CC_RISCVAssign2XLen(State, VA, AF, ValNo, ValVT, LocVT, ArgFlags,
549 Subtarget);
550 }
551
552 // Split arguments might be passed indirectly, so keep track of the pending
553 // values. Split vectors excluding P extension packed vectors(see
554 // isPExtPackedType) are passed via a mix of registers and indirectly, so
555 // treat them as we would any other argument.
556 if ((LocVT.isScalarInteger() || Subtarget.isPExtPackedType(LocVT)) &&
557 (ArgFlags.isSplit() || !PendingLocs.empty())) {
558 PendingLocs.push_back(
559 CCValAssign::getPending(ValNo, ValVT, LocVT, LocInfo));
560 PendingArgFlags.push_back(ArgFlags);
561 if (!ArgFlags.isSplitEnd()) {
562 return false;
563 }
564 }
565
566 // Allocate to a register if possible, or else a stack slot.
568 unsigned StoreSizeBytes = XLen / 8;
569 Align StackAlign = Align(XLen / 8);
570
571 // FIXME: If P extension and V extension are enabled at the same time,
572 // who should go first?
573 if (!Subtarget.isPExtPackedType(LocVT) &&
574 (LocVT.isVector() || LocVT.isRISCVVectorTuple())) {
575 Reg = allocateRVVReg(LocVT, ValNo, State, TLI);
576 if (Reg) {
577 // Fixed-length vectors are located in the corresponding scalable-vector
578 // container types.
579 if (LocVT.isFixedLengthVector()) {
580 LocVT = TLI.getContainerForFixedLengthVector(LocVT);
581 State.addLoc(
582 CCValAssign::getCustomReg(ValNo, ValVT, Reg, LocVT, LocInfo));
583 return false;
584 }
585 } else {
586 // For return values, the vector must be passed fully via registers or
587 // via the stack.
588 if (IsRet)
589 return true;
590 // Try using a GPR to pass the address
591 if ((Reg = State.AllocateReg(ArgGPRs))) {
592 LocVT = XLenVT;
593 LocInfo = CCValAssign::Indirect;
594 } else if (LocVT.isScalableVector()) {
595 LocVT = XLenVT;
596 LocInfo = CCValAssign::Indirect;
597 } else {
598 StoreSizeBytes = LocVT.getStoreSize();
599 // Align vectors to their element sizes, being careful for vXi1
600 // vectors.
601 StackAlign = MaybeAlign(LocVT.getScalarSizeInBits() / 8).valueOrOne();
602 }
603 }
604 } else {
605 Reg = State.AllocateReg(ArgGPRs);
606 }
607
608 int64_t StackOffset =
609 Reg ? 0 : State.AllocateStack(StoreSizeBytes, StackAlign);
610
611 // If we reach this point and PendingLocs is non-empty, we must be at the
612 // end of a split argument that must be passed indirectly.
613 if (!PendingLocs.empty()) {
614 assert(ArgFlags.isSplitEnd() && "Expected ArgFlags.isSplitEnd()");
615 assert(PendingLocs.size() > 1 && "Unexpected PendingLocs.size()");
616
617 for (auto &It : PendingLocs) {
618 if (Reg)
619 State.addLoc(CCValAssign::getReg(It.getValNo(), It.getValVT(), Reg,
620 XLenVT, CCValAssign::Indirect));
621 else
622 State.addLoc(CCValAssign::getMem(It.getValNo(), It.getValVT(),
623 StackOffset, XLenVT,
625 }
626 PendingLocs.clear();
627 PendingArgFlags.clear();
628 return false;
629 }
630
631 assert(((LocVT.isFloatingPoint() && !LocVT.isVector()) || LocVT == XLenVT ||
632 Subtarget.isPExtPackedType(LocVT) ||
633 (TLI.getSubtarget().hasVInstructions() &&
634 (LocVT.isVector() || LocVT.isRISCVVectorTuple()))) &&
635 "Expected an XLenVT or vector types at this stage");
636
637 if (Reg) {
638 State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
639 return false;
640 }
641
642 State.addLoc(CCValAssign::getMem(ValNo, ValVT, StackOffset, LocVT, LocInfo));
643 return false;
644}
645
646// FastCC has less than 1% performance improvement for some particular
647// benchmark. But theoretically, it may have benefit for some cases.
648static bool CC_RISCV_FastCC(unsigned ValNo, MVT ValVT, MVT LocVT,
649 CCValAssign::LocInfo LocInfo,
650 ISD::ArgFlagsTy ArgFlags, Type *OrigTy,
651 CCState &State) {
652 const MachineFunction &MF = State.getMachineFunction();
654 const RISCVTargetLowering &TLI = *Subtarget.getTargetLowering();
655 RISCVABI::ABI ABI = Subtarget.getTargetABI();
656
657 if ((LocVT == MVT::f16 && Subtarget.hasStdExtZfhmin()) ||
658 (LocVT == MVT::bf16 && Subtarget.hasStdExtZfbfmin())) {
659 static const MCPhysReg FPR16List[] = {
660 RISCV::F10_H, RISCV::F11_H, RISCV::F12_H, RISCV::F13_H, RISCV::F14_H,
661 RISCV::F15_H, RISCV::F16_H, RISCV::F17_H, RISCV::F0_H, RISCV::F1_H,
662 RISCV::F2_H, RISCV::F3_H, RISCV::F4_H, RISCV::F5_H, RISCV::F6_H,
663 RISCV::F7_H, RISCV::F28_H, RISCV::F29_H, RISCV::F30_H, RISCV::F31_H};
664 if (MCRegister Reg = State.AllocateReg(FPR16List)) {
665 State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
666 return false;
667 }
668 }
669
670 if (LocVT == MVT::f32 && Subtarget.hasStdExtF()) {
671 static const MCPhysReg FPR32List[] = {
672 RISCV::F10_F, RISCV::F11_F, RISCV::F12_F, RISCV::F13_F, RISCV::F14_F,
673 RISCV::F15_F, RISCV::F16_F, RISCV::F17_F, RISCV::F0_F, RISCV::F1_F,
674 RISCV::F2_F, RISCV::F3_F, RISCV::F4_F, RISCV::F5_F, RISCV::F6_F,
675 RISCV::F7_F, RISCV::F28_F, RISCV::F29_F, RISCV::F30_F, RISCV::F31_F};
676 if (MCRegister Reg = State.AllocateReg(FPR32List)) {
677 State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
678 return false;
679 }
680 }
681
682 if (LocVT == MVT::f64 && Subtarget.hasStdExtD()) {
683 static const MCPhysReg FPR64List[] = {
684 RISCV::F10_D, RISCV::F11_D, RISCV::F12_D, RISCV::F13_D, RISCV::F14_D,
685 RISCV::F15_D, RISCV::F16_D, RISCV::F17_D, RISCV::F0_D, RISCV::F1_D,
686 RISCV::F2_D, RISCV::F3_D, RISCV::F4_D, RISCV::F5_D, RISCV::F6_D,
687 RISCV::F7_D, RISCV::F28_D, RISCV::F29_D, RISCV::F30_D, RISCV::F31_D};
688 if (MCRegister Reg = State.AllocateReg(FPR64List)) {
689 State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
690 return false;
691 }
692 }
693
694 MVT XLenVT = Subtarget.getXLenVT();
695
696 // Check if there is an available GPRF16 before hitting the stack.
697 if ((LocVT == MVT::f16 && Subtarget.hasStdExtZhinxmin())) {
698 if (MCRegister Reg = State.AllocateReg(getFastCCArgGPRF16s(ABI))) {
699 State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
700 return false;
701 }
702 }
703
704 // Check if there is an available GPRF32 before hitting the stack.
705 if (LocVT == MVT::f32 && Subtarget.hasStdExtZfinx()) {
706 if (MCRegister Reg = State.AllocateReg(getFastCCArgGPRF32s(ABI))) {
707 State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
708 return false;
709 }
710 }
711
713
714 // Check if there is an available GPR before hitting the stack.
715 if (LocVT == MVT::f64 && Subtarget.is64Bit() && Subtarget.hasStdExtZdinx()) {
716 if (MCRegister Reg = State.AllocateReg(ArgGPRs)) {
717 if (LocVT.getSizeInBits() != Subtarget.getXLen()) {
718 LocVT = XLenVT;
719 State.addLoc(
720 CCValAssign::getCustomReg(ValNo, ValVT, Reg, LocVT, LocInfo));
721 return false;
722 }
723 State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
724 return false;
725 }
726 }
727
728 // FIXME: If P extension and V extension are enabled at the same time,
729 // who should go first?
730 if (!Subtarget.isPExtPackedType(LocVT) && LocVT.isVector()) {
731 if (MCRegister Reg = allocateRVVReg(ValVT, ValNo, State, TLI)) {
732 // Fixed-length vectors are located in the corresponding scalable-vector
733 // container types.
734 if (LocVT.isFixedLengthVector()) {
735 LocVT = TLI.getContainerForFixedLengthVector(LocVT);
736 State.addLoc(
737 CCValAssign::getCustomReg(ValNo, ValVT, Reg, LocVT, LocInfo));
738 return false;
739 }
740 State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
741 return false;
742 }
743
744 // Pass scalable vectors indirectly. Pass fixed vectors indirectly if we
745 // have a free GPR.
746 if (LocVT.isScalableVector() ||
747 State.getFirstUnallocated(ArgGPRs) != ArgGPRs.size()) {
748 LocInfo = CCValAssign::Indirect;
749 LocVT = XLenVT;
750 }
751 }
752
753 // Pass 2*XLen P extension vectors on RV32 in a pair of GPRs, split between a
754 // GPR and the stack, or entirely on the stack.
755 if (Subtarget.isPExtPackedDoubleType(LocVT)) {
756 MCRegister Reg = State.AllocateReg(ArgGPRs);
757 if (Reg) {
758 LocVT = MVT::i32;
759 State.addLoc(
760 CCValAssign::getCustomReg(ValNo, ValVT, Reg, LocVT, LocInfo));
761 if (MCRegister HiReg = State.AllocateReg(ArgGPRs)) {
762 State.addLoc(
763 CCValAssign::getCustomReg(ValNo, ValVT, HiReg, LocVT, LocInfo));
764 } else {
765 int64_t StackOffset = State.AllocateStack(4, Align(4));
766 State.addLoc(CCValAssign::getCustomMem(ValNo, ValVT, StackOffset, LocVT,
767 LocInfo));
768 }
769 return false;
770 }
771 }
772
773 if (LocVT == XLenVT || Subtarget.isPExtPackedType(LocVT)) {
774 if (MCRegister Reg = State.AllocateReg(ArgGPRs)) {
775 State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
776 return false;
777 }
778 }
779
780 if (LocVT == XLenVT || LocVT == MVT::f16 || LocVT == MVT::bf16 ||
781 LocVT == MVT::f32 || LocVT == MVT::f64 || LocVT.isFixedLengthVector()) {
782 Align StackAlign = MaybeAlign(ValVT.getScalarSizeInBits() / 8).valueOrOne();
783 // P extension packed vectors are GPR sized and need XLen alignment.
784 if (Subtarget.isPExtPackedType(LocVT))
785 StackAlign = Align(Subtarget.getXLen() / 8);
786 int64_t Offset = State.AllocateStack(LocVT.getStoreSize(), StackAlign);
787 State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo));
788 return false;
789 }
790
791 return true; // CC didn't match.
792}
793
794static bool CC_RISCV_GHC(unsigned ValNo, MVT ValVT, MVT LocVT,
795 CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags,
796 Type *OrigTy, CCState &State) {
797 if (ArgFlags.isNest()) {
799 "Attribute 'nest' is not supported in GHC calling convention");
800 }
801
802 static const MCPhysReg GPRList[] = {
803 RISCV::X9, RISCV::X18, RISCV::X19, RISCV::X20, RISCV::X21, RISCV::X22,
804 RISCV::X23, RISCV::X24, RISCV::X25, RISCV::X26, RISCV::X27};
805
806 if (LocVT == MVT::i32 || LocVT == MVT::i64) {
807 // Pass in STG registers: Base, Sp, Hp, R1, R2, R3, R4, R5, R6, R7, SpLim
808 // s1 s2 s3 s4 s5 s6 s7 s8 s9 s10 s11
809 if (MCRegister Reg = State.AllocateReg(GPRList)) {
810 State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
811 return false;
812 }
813 }
814
816 State.getMachineFunction().getSubtarget<RISCVSubtarget>();
817
818 if (LocVT == MVT::f32 && Subtarget.hasStdExtF()) {
819 // Pass in STG registers: F1, ..., F6
820 // fs0 ... fs5
821 static const MCPhysReg FPR32List[] = {RISCV::F8_F, RISCV::F9_F,
822 RISCV::F18_F, RISCV::F19_F,
823 RISCV::F20_F, RISCV::F21_F};
824 if (MCRegister Reg = State.AllocateReg(FPR32List)) {
825 State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
826 return false;
827 }
828 }
829
830 if (LocVT == MVT::f64 && Subtarget.hasStdExtD()) {
831 // Pass in STG registers: D1, ..., D6
832 // fs6 ... fs11
833 static const MCPhysReg FPR64List[] = {RISCV::F22_D, RISCV::F23_D,
834 RISCV::F24_D, RISCV::F25_D,
835 RISCV::F26_D, RISCV::F27_D};
836 if (MCRegister Reg = State.AllocateReg(FPR64List)) {
837 State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
838 return false;
839 }
840 }
841
842 if (LocVT == MVT::f32 && Subtarget.hasStdExtZfinx()) {
843 static const MCPhysReg GPR32List[] = {
844 RISCV::X9_W, RISCV::X18_W, RISCV::X19_W, RISCV::X20_W,
845 RISCV::X21_W, RISCV::X22_W, RISCV::X23_W, RISCV::X24_W,
846 RISCV::X25_W, RISCV::X26_W, RISCV::X27_W};
847 if (MCRegister Reg = State.AllocateReg(GPR32List)) {
848 State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
849 return false;
850 }
851 }
852
853 if (LocVT == MVT::f64 && Subtarget.hasStdExtZdinx() && Subtarget.is64Bit()) {
854 if (MCRegister Reg = State.AllocateReg(GPRList)) {
855 State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
856 return false;
857 }
858 }
859
860 report_fatal_error("No registers left in GHC calling convention");
861 return true;
862}
const AArch64Subtarget & Subtarget
const TargetLowering & TLI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
const MCPhysReg ArgFPR32s[]
const MCPhysReg ArgVRs[]
const MCPhysReg ArgFPR64s[]
const MCPhysReg ArgGPRs[]
Register Reg
static const MCPhysReg ArgVRN2M2s[]
static CCAssignFn CC_RISCV_FastCC
Used for assigning arguments with CallingConvention::Fast.
static const MCPhysReg ArgVRM2s[]
static CCAssignFn CC_RISCV_GHC
Used for assigning arguments with CallingConvention::GHC.
static const MCPhysReg ArgVRN3M2s[]
static const MCPhysReg ArgVRN4M1s[]
static const MCPhysReg ArgVRN6M1s[]
static bool CC_RISCV_Impl(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, Type *OrigTy, CCState &State, bool IsRet)
static ArrayRef< MCPhysReg > getFastCCArgGPRF32s(const RISCVABI::ABI ABI)
static const MCPhysReg ArgVRN4M2s[]
static const MCPhysReg ArgFPR128s[]
static const MCPhysReg ArgVRN3M1s[]
static const MCPhysReg ArgVRN7M1s[]
static bool CC_RISCVAssign2XLen(CCState &State, CCValAssign VA1, ISD::ArgFlagsTy ArgFlags1, unsigned ValNo2, MVT ValVT2, MVT LocVT2, ISD::ArgFlagsTy ArgFlags2, const RISCVSubtarget &Subtarget)
static MCRegister allocateRVVReg(MVT LocVT, unsigned ValNo, CCState &State, const RISCVTargetLowering &TLI)
static const MCPhysReg ArgVRN5M1s[]
static const MCPhysReg ArgVRN2M4s[]
static ArrayRef< MCPhysReg > getFastCCArgGPRF16s(const RISCVABI::ABI ABI)
static ArrayRef< MCPhysReg > getArgGPR32s(const RISCVABI::ABI ABI)
static const MCPhysReg ArgVRN2M1s[]
static const MCPhysReg ArgVRN8M1s[]
static ArrayRef< MCPhysReg > getArgGPR16s(const RISCVABI::ABI ABI)
static ArrayRef< MCPhysReg > getFastCCArgGPRs(const RISCVABI::ABI ABI)
static const MCPhysReg ArgVRM8s[]
static const MCPhysReg ArgVRM4s[]
static const MCPhysReg ArgFPR16s[]
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
CCState - This class holds information needed while lowering arguments and return values.
CCValAssign - Represent assignment of one arg/retval to a location.
static CCValAssign getPending(unsigned ValNo, MVT ValVT, MVT LocVT, LocInfo HTP, unsigned ExtraInfo=0)
static CCValAssign getReg(unsigned ValNo, MVT ValVT, MCRegister Reg, MVT LocVT, LocInfo HTP, bool IsCustom=false)
static CCValAssign getCustomReg(unsigned ValNo, MVT ValVT, MCRegister Reg, MVT LocVT, LocInfo HTP)
static CCValAssign getMem(unsigned ValNo, MVT ValVT, int64_t Offset, MVT LocVT, LocInfo HTP, bool IsCustom=false)
unsigned getValNo() const
static CCValAssign getCustomMem(unsigned ValNo, MVT ValVT, int64_t Offset, MVT LocVT, LocInfo HTP)
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:41
Machine Value Type.
bool isRISCVVectorTuple() const
Return true if this is a RISCV vector tuple type where the runtime length is machine dependent.
uint64_t getScalarSizeInBits() const
bool isVector() const
Return true if this is a vector value type.
bool isScalableVector() const
Return true if this is a vector value type where the runtime length is machine dependent.
TypeSize getSizeInBits() const
Returns the size of the specified MVT in bits.
bool isFixedLengthVector() const
TypeSize getStoreSize() const
Return the number of bytes overwritten by a store of the specified value type.
bool isScalarInteger() const
Return true if this is an integer, not including vectors.
MVT getVectorElementType() const
bool isFloatingPoint() const
Return true if this is a FP or a vector FP type.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
RISCVMachineFunctionInfo - This class is derived from MachineFunctionInfo and contains private RISCV-...
RISCVABI::ABI getTargetABI() const
bool hasVInstructions() const
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
StackOffset holds a fixed and a scalable offset in bytes.
Definition TypeSize.h:31
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ GHC
Used by the Glasgow Haskell Compiler (GHC).
Definition CallingConv.h:50
@ Fast
Attempts to make calls as fast as possible (e.g.
Definition CallingConv.h:41
bool isRVE(ABI TargetABI)
bool isSingleFP(ABI TargetABI)
bool isDoubleFP(ABI TargetABI)
bool isPurecap(ABI TargetABI)
Align getStackAlignment(ABI TargetABI)
ArrayRef< MCPhysReg > getArgFPRs(const RISCVSubtarget &STI)
ArrayRef< MCPhysReg > getArgGPRs(const RISCVSubtarget &STI)
ArrayRef< MCPhysReg > getArgVRs(const RISCVSubtarget &STI)
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
bool CCAssignFn(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, Type *OrigTy, CCState &State)
CCAssignFn - This function assigns a location for Val, updating State to reflect the change.
CCAssignFn RetCC_RISCV
This is used for assigning return values to locations when making calls.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:163
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
Definition MCRegister.h:21
ArrayRef(const T &OneElt) -> ArrayRef< T >
CCAssignFn CC_RISCV
This is used for assigining arguments to locations when making calls.
MCRegisterClass TargetRegisterClass
Definition FastISel.h:58
LLVM_ABI void reportFatalUsageError(Error Err)
Report a fatal error that does not indicate a bug in LLVM.
Definition Error.cpp:177
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
Align getNonZeroOrigAlign() const
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition Alignment.h:111
Align valueOrOne() const
For convenience, returns a valid alignment or 1 if undefined.
Definition Alignment.h:135