LLVM 24.0.0git
ARMCallLowering.cpp
Go to the documentation of this file.
1//===- llvm/lib/Target/ARM/ARMCallLowering.cpp - Call lowering ------------===//
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/// \file
10/// This file implements the lowering of LLVM calls to machine code calls for
11/// GlobalISel.
12//
13//===----------------------------------------------------------------------===//
14
15#include "ARMCallLowering.h"
16#include "ARMBaseInstrInfo.h"
17#include "ARMISelLowering.h"
18#include "ARMSubtarget.h"
19#include "Utils/ARMBaseInfo.h"
38#include "llvm/IR/Attributes.h"
39#include "llvm/IR/DataLayout.h"
41#include "llvm/IR/Function.h"
42#include "llvm/IR/Type.h"
43#include "llvm/IR/Value.h"
45#include <algorithm>
46#include <cassert>
47#include <cstdint>
48#include <functional>
49#include <utility>
50
51using namespace llvm;
52
53// Whether Big-endian GISel is enabled, defaults to off, can be enabled for
54// testing.
55static cl::opt<bool>
56 EnableGISelBigEndian("enable-arm-gisel-bigendian", cl::Hidden,
57 cl::init(false),
58 cl::desc("Enable Global-ISel Big Endian Lowering"));
59
62
64 Type *T) {
65 if (T->isArrayTy())
66 return isSupportedType(DL, TLI, T->getArrayElementType());
67
68 if (T->isStructTy()) {
69 // For now we only allow homogeneous structs that we can manipulate with
70 // G_MERGE_VALUES and G_UNMERGE_VALUES
71 auto StructT = cast<StructType>(T);
72 for (unsigned i = 1, e = StructT->getNumElements(); i != e; ++i)
73 if (StructT->getElementType(i) != StructT->getElementType(0))
74 return false;
75 return isSupportedType(DL, TLI, StructT->getElementType(0));
76 }
77
78 EVT VT = TLI.getValueType(DL, T, true);
79 if (!VT.isSimple() || VT.isVector() ||
80 !(VT.isInteger() || VT.isFloatingPoint()))
81 return false;
82
83 unsigned VTSize = VT.getSimpleVT().getSizeInBits();
84
85 if (VTSize == 64)
86 // FIXME: Support i64 too
87 return VT.isFloatingPoint();
88
89 return VTSize == 1 || VTSize == 8 || VTSize == 16 || VTSize == 32;
90}
91
92namespace {
93
94/// Helper class for values going out through an ABI boundary (used for handling
95/// function return values and call parameters).
96struct ARMOutgoingValueHandler : public CallLowering::OutgoingValueHandler {
97 ARMOutgoingValueHandler(MachineIRBuilder &MIRBuilder,
98 MachineRegisterInfo &MRI, MachineInstrBuilder &MIB)
99 : OutgoingValueHandler(MIRBuilder, MRI), MIB(MIB) {}
100
101 Register getStackAddress(uint64_t Size, int64_t Offset,
102 MachinePointerInfo &MPO,
103 ISD::ArgFlagsTy Flags) override {
104 assert((Size == 1 || Size == 2 || Size == 4 || Size == 8) &&
105 "Unsupported size");
106
107 LLT p0 = LLT::pointer(0, 32);
108 auto SPReg = MIRBuilder.buildCopy(p0, Register(ARM::SP));
109
110 auto OffsetReg = MIRBuilder.buildConstant(LLT::integer(32), Offset);
111
112 auto AddrReg = MIRBuilder.buildPtrAdd(p0, SPReg, OffsetReg);
113
114 MPO = MachinePointerInfo::getStack(MIRBuilder.getMF(), Offset);
115 return AddrReg.getReg(0);
116 }
117
118 void assignValueToReg(Register ValVReg, Register PhysReg,
119 const CCValAssign &VA,
120 ISD::ArgFlagsTy Flags = {}) override {
121 assert(VA.isRegLoc() && "Value shouldn't be assigned to reg");
122 assert(VA.getLocReg() == PhysReg && "Assigning to the wrong reg?");
123
124 assert(VA.getValVT().getSizeInBits() <= 64 && "Unsupported value size");
125 assert(VA.getLocVT().getSizeInBits() <= 64 && "Unsupported location size");
126
127 Register ExtReg = extendRegister(ValVReg, VA);
128 MIRBuilder.buildCopy(PhysReg, ExtReg);
129 MIB.addUse(PhysReg, RegState::Implicit);
130 }
131
132 void assignValueToAddress(Register ValVReg, Register Addr, LLT MemTy,
133 const MachinePointerInfo &MPO,
134 const CCValAssign &VA) override {
135 Register ExtReg = extendRegister(ValVReg, VA);
136 auto MMO = MIRBuilder.getMF().getMachineMemOperand(
137 MPO, MachineMemOperand::MOStore, MemTy, Align(1));
138 MIRBuilder.buildStore(ExtReg, Addr, *MMO);
139 }
140
141 unsigned assignCustomValue(CallLowering::ArgInfo &Arg,
143 std::function<void()> *Thunk) override {
144 assert(Arg.Regs.size() == 1 && "Can't handle multiple regs yet");
145
146 const CCValAssign &VA = VAs[0];
147 assert(VA.needsCustom() && "Value doesn't need custom handling");
148
149 // Custom lowering for other types, such as f16, is currently not supported
150 if (VA.getValVT() != MVT::f64)
151 return 0;
152
153 const CCValAssign &NextVA = VAs[1];
154 assert(NextVA.needsCustom() && "Value doesn't need custom handling");
155 assert(NextVA.getValVT() == MVT::f64 && "Unsupported type");
156
157 assert(VA.getValNo() == NextVA.getValNo() &&
158 "Values belong to different arguments");
159
160 assert(VA.isRegLoc() && "Value should be in reg");
161 assert(NextVA.isRegLoc() && "Value should be in reg");
162
165 MIRBuilder.buildUnmerge(NewRegs, Arg.Regs[0]);
166
167 bool IsLittle = MIRBuilder.getMF().getSubtarget<ARMSubtarget>().isLittle();
168 if (!IsLittle)
169 std::swap(NewRegs[0], NewRegs[1]);
170
171 if (Thunk) {
172 *Thunk = [=]() {
173 assignValueToReg(NewRegs[0], VA.getLocReg(), VA);
174 assignValueToReg(NewRegs[1], NextVA.getLocReg(), NextVA);
175 };
176 return 2;
177 }
178 assignValueToReg(NewRegs[0], VA.getLocReg(), VA);
179 assignValueToReg(NewRegs[1], NextVA.getLocReg(), NextVA);
180 return 2;
181 }
182
183 MachineInstrBuilder MIB;
184};
185
186} // end anonymous namespace
187
188/// Lower the return value for the already existing \p Ret. This assumes that
189/// \p MIRBuilder's insertion point is correct.
190bool ARMCallLowering::lowerReturnVal(MachineIRBuilder &MIRBuilder,
191 const Value *Val, ArrayRef<Register> VRegs,
192 MachineInstrBuilder &Ret) const {
193 if (!Val)
194 // Nothing to do here.
195 return true;
196
197 auto &MF = MIRBuilder.getMF();
198 const auto &F = MF.getFunction();
199
200 const auto &DL = MF.getDataLayout();
201 auto &TLI = *getTLI<ARMTargetLowering>();
202 if (!isSupportedType(DL, TLI, Val->getType()))
203 return false;
204
205 ArgInfo OrigRetInfo(VRegs, Val->getType(), 0);
206 setArgFlags(OrigRetInfo, AttributeList::ReturnIndex, DL, F);
207
208 SmallVector<ArgInfo, 4> SplitRetInfos;
209 splitToValueTypes(OrigRetInfo, SplitRetInfos, DL, F.getCallingConv());
210
211 CCAssignFn *AssignFn =
212 TLI.CCAssignFnForReturn(F.getCallingConv(), F.isVarArg());
213
214 OutgoingValueAssigner RetAssigner(AssignFn);
215 ARMOutgoingValueHandler RetHandler(MIRBuilder, MF.getRegInfo(), Ret);
216 return determineAndHandleAssignments(RetHandler, RetAssigner, SplitRetInfos,
217 MIRBuilder, F.getCallingConv(),
218 F.isVarArg());
219}
220
222 const Value *Val, ArrayRef<Register> VRegs,
223 FunctionLoweringInfo &FLI) const {
224 assert(!Val == VRegs.empty() && "Return value without a vreg");
225
226 auto const &ST = MIRBuilder.getMF().getSubtarget<ARMSubtarget>();
227 unsigned Opcode = ST.getReturnOpcode();
228 auto Ret = MIRBuilder.buildInstrNoInsert(Opcode).add(predOps(ARMCC::AL));
229
230 if (!lowerReturnVal(MIRBuilder, Val, VRegs, Ret))
231 return false;
232
233 MIRBuilder.insertInstr(Ret);
234 return true;
235}
236
237namespace {
238
239/// Helper class for values coming in through an ABI boundary (used for handling
240/// formal arguments and call return values).
241struct ARMIncomingValueHandler : public CallLowering::IncomingValueHandler {
242 ARMIncomingValueHandler(MachineIRBuilder &MIRBuilder,
244 : IncomingValueHandler(MIRBuilder, MRI) {}
245
246 Register getStackAddress(uint64_t Size, int64_t Offset,
248 ISD::ArgFlagsTy Flags) override {
249 assert((Size == 1 || Size == 2 || Size == 4 || Size == 8) &&
250 "Unsupported size");
251
252 auto &MFI = MIRBuilder.getMF().getFrameInfo();
253
254 // Byval is assumed to be writable memory, but other stack passed arguments
255 // are not.
256 const bool IsImmutable = !Flags.isByVal();
257
258 int FI = MFI.CreateFixedObject(Size, Offset, IsImmutable);
259 MPO = MachinePointerInfo::getFixedStack(MIRBuilder.getMF(), FI);
260
261 return MIRBuilder.buildFrameIndex(LLT::pointer(MPO.getAddrSpace(), 32), FI)
262 .getReg(0);
263 }
264
265 void assignValueToAddress(Register ValVReg, Register Addr, LLT MemTy,
266 const MachinePointerInfo &MPO,
267 const CCValAssign &VA) override {
268 if (VA.getLocInfo() == CCValAssign::SExt ||
270 // If the value is zero- or sign-extended, its size becomes 4 bytes, so
271 // that's what we should load.
272 MemTy = LLT::scalar(32);
273 assert(MRI.getType(ValVReg).isScalar() && "Only scalars supported atm");
274
275 auto LoadVReg = buildLoad(LLT::integer(32), Addr, MemTy, MPO);
276 MIRBuilder.buildTrunc(ValVReg, LoadVReg);
277 } else {
278 // If the value is not extended, a simple load will suffice.
279 buildLoad(ValVReg, Addr, MemTy, MPO);
280 }
281 }
282
283 MachineInstrBuilder buildLoad(const DstOp &Res, Register Addr, LLT MemTy,
284 const MachinePointerInfo &MPO) {
285 MachineFunction &MF = MIRBuilder.getMF();
286
287 auto MMO = MF.getMachineMemOperand(MPO, MachineMemOperand::MOLoad, MemTy,
288 inferAlignFromPtrInfo(MF, MPO));
289 return MIRBuilder.buildLoad(Res, Addr, *MMO);
290 }
291
292 void assignValueToReg(Register ValVReg, Register PhysReg,
293 const CCValAssign &VA,
294 ISD::ArgFlagsTy Flags = {}) override {
295 assert(VA.isRegLoc() && "Value shouldn't be assigned to reg");
296 assert(VA.getLocReg() == PhysReg && "Assigning to the wrong reg?");
297
298 uint64_t ValSize = VA.getValVT().getFixedSizeInBits();
299 uint64_t LocSize = VA.getLocVT().getFixedSizeInBits();
300
301 assert(ValSize <= 64 && "Unsupported value size");
302 assert(LocSize <= 64 && "Unsupported location size");
303
304 markPhysRegUsed(PhysReg);
305 if (ValSize == LocSize) {
306 MIRBuilder.buildCopy(ValVReg, PhysReg);
307 } else {
308 assert(ValSize < LocSize && "Extensions not supported");
309
310 // We cannot create a truncating copy, nor a trunc of a physical register.
311 // Therefore, we need to copy the content of the physical register into a
312 // virtual one and then truncate that.
313 auto PhysRegToVReg = MIRBuilder.buildCopy(LLT::integer(LocSize), PhysReg);
314 LLT ValTy = MRI.getType(ValVReg);
315 LLT ValITy = ValTy.changeToInteger();
316 if (ValTy == ValITy) {
317 MIRBuilder.buildTrunc(ValVReg, PhysRegToVReg);
318 } else {
319 auto T = MIRBuilder.buildTrunc(ValITy, PhysRegToVReg);
320 MIRBuilder.buildBitcast(ValVReg, T);
321 }
322 }
323 }
324
325 unsigned assignCustomValue(ARMCallLowering::ArgInfo &Arg,
327 std::function<void()> *Thunk) override {
328 assert(Arg.Regs.size() == 1 && "Can't handle multiple regs yet");
329
330 const CCValAssign &VA = VAs[0];
331 assert(VA.needsCustom() && "Value doesn't need custom handling");
332
333 // Custom lowering for other types, such as f16, is currently not supported
334 if (VA.getValVT() != MVT::f64)
335 return 0;
336
337 const CCValAssign &NextVA = VAs[1];
338 assert(NextVA.needsCustom() && "Value doesn't need custom handling");
339 assert(NextVA.getValVT() == MVT::f64 && "Unsupported type");
340
341 assert(VA.getValNo() == NextVA.getValNo() &&
342 "Values belong to different arguments");
343
344 assert(VA.isRegLoc() && "Value should be in reg");
345 assert(NextVA.isRegLoc() && "Value should be in reg");
346
349
350 assignValueToReg(NewRegs[0], VA.getLocReg(), VA);
351 assignValueToReg(NewRegs[1], NextVA.getLocReg(), NextVA);
352
353 bool IsLittle = MIRBuilder.getMF().getSubtarget<ARMSubtarget>().isLittle();
354 if (!IsLittle)
355 std::swap(NewRegs[0], NewRegs[1]);
356
357 MIRBuilder.buildMergeLikeInstr(Arg.Regs[0], NewRegs);
358
359 return 2;
360 }
361
362 /// Marking a physical register as used is different between formal
363 /// parameters, where it's a basic block live-in, and call returns, where it's
364 /// an implicit-def of the call instruction.
365 virtual void markPhysRegUsed(unsigned PhysReg) = 0;
366};
367
368struct FormalArgHandler : public ARMIncomingValueHandler {
369 FormalArgHandler(MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI)
370 : ARMIncomingValueHandler(MIRBuilder, MRI) {}
371
372 void markPhysRegUsed(unsigned PhysReg) override {
373 MIRBuilder.getMRI()->addLiveIn(PhysReg);
374 MIRBuilder.getMBB().addLiveIn(PhysReg);
375 }
376};
377
378} // end anonymous namespace
379
381 const Function &F,
383 FunctionLoweringInfo &FLI) const {
384 auto &TLI = *getTLI<ARMTargetLowering>();
385 auto Subtarget = TLI.getSubtarget();
386
387 if (Subtarget->isThumb1Only())
388 return false;
389
390 // Quick exit if there aren't any args
391 if (F.arg_empty())
392 return true;
393
394 if (F.isVarArg())
395 return false;
396
397 auto &MF = MIRBuilder.getMF();
398 auto &MBB = MIRBuilder.getMBB();
399 const auto &DL = MF.getDataLayout();
400
401 for (auto &Arg : F.args()) {
402 if (!isSupportedType(DL, TLI, Arg.getType()))
403 return false;
404 if (Arg.hasPassPointeeByValueCopyAttr())
405 return false;
406 }
407
408 CCAssignFn *AssignFn =
409 TLI.CCAssignFnForCall(F.getCallingConv(), F.isVarArg());
410
411 OutgoingValueAssigner ArgAssigner(AssignFn);
412 FormalArgHandler ArgHandler(MIRBuilder, MIRBuilder.getMF().getRegInfo());
413
414 SmallVector<ArgInfo, 8> SplitArgInfos;
415 unsigned Idx = 0;
416 for (auto &Arg : F.args()) {
417 ArgInfo OrigArgInfo(VRegs[Idx], Arg.getType(), Idx);
418
419 setArgFlags(OrigArgInfo, Idx + AttributeList::FirstArgIndex, DL, F);
420 splitToValueTypes(OrigArgInfo, SplitArgInfos, DL, F.getCallingConv());
421
422 Idx++;
423 }
424
425 if (!MBB.empty())
426 MIRBuilder.setInstr(*MBB.begin());
427
428 if (!determineAndHandleAssignments(ArgHandler, ArgAssigner, SplitArgInfos,
429 MIRBuilder, F.getCallingConv(),
430 F.isVarArg()))
431 return false;
432
433 // Move back to the end of the basic block.
434 MIRBuilder.setMBB(MBB);
435 return true;
436}
437
438namespace {
439
440struct CallReturnHandler : public ARMIncomingValueHandler {
441 CallReturnHandler(MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI,
443 : ARMIncomingValueHandler(MIRBuilder, MRI), MIB(MIB) {}
444
445 void markPhysRegUsed(unsigned PhysReg) override {
446 MIB.addDef(PhysReg, RegState::Implicit);
447 }
448
449 MachineInstrBuilder MIB;
450};
451
452// FIXME: This should move to the ARMSubtarget when it supports all the opcodes.
453unsigned getCallOpcode(const MachineFunction &MF, const ARMSubtarget &STI,
454 bool isDirect) {
455 if (isDirect)
456 return STI.isThumb() ? ARM::tBL : ARM::BL;
457
458 if (STI.isThumb())
459 return gettBLXrOpcode(MF);
460
461 if (STI.hasV5TOps())
462 return getBLXOpcode(MF);
463
464 if (STI.hasV4TOps())
465 return ARM::BX_CALL;
466
467 return ARM::BMOVPCRX_CALL;
468}
469} // end anonymous namespace
470
472 MachineFunction &MF = MIRBuilder.getMF();
473 const auto &TLI = *getTLI<ARMTargetLowering>();
474 const auto &DL = MF.getDataLayout();
475 const auto &STI = MF.getSubtarget<ARMSubtarget>();
478
479 if (STI.genLongCalls())
480 return false;
481
482 if (STI.isThumb1Only())
483 return false;
484
485 auto CallSeqStart = MIRBuilder.buildInstr(ARM::ADJCALLSTACKDOWN);
486
487 // Create the call instruction so we can add the implicit uses of arg
488 // registers, but don't insert it yet.
489 bool IsDirect = !Info.Callee.isReg();
490 auto CallOpcode = getCallOpcode(MF, STI, IsDirect);
491 auto MIB = MIRBuilder.buildInstrNoInsert(CallOpcode);
492 if (Info.NoMerge)
494
495 bool IsThumb = STI.isThumb();
496 if (IsThumb)
497 MIB.add(predOps(ARMCC::AL));
498
499 MIB.add(Info.Callee);
500 if (!IsDirect) {
501 auto CalleeReg = Info.Callee.getReg();
502 if (CalleeReg && !CalleeReg.isPhysical()) {
503 unsigned CalleeIdx = IsThumb ? 2 : 0;
504 MIB->getOperand(CalleeIdx).setReg(constrainOperandRegClass(
505 MF, *TRI, MRI, *STI.getInstrInfo(), *STI.getRegBankInfo(),
506 *MIB.getInstr(), MIB->getDesc(), Info.Callee, CalleeIdx));
507 }
508 }
509
510 MIB.addRegMask(TRI->getCallPreservedMask(MF, Info.CallConv));
511
513 for (auto Arg : Info.OrigArgs) {
514 if (!isSupportedType(DL, TLI, Arg.Ty))
515 return false;
516
517 if (Arg.Flags[0].isByVal())
518 return false;
519
520 splitToValueTypes(Arg, ArgInfos, DL, Info.CallConv);
521 }
522
523 auto ArgAssignFn = TLI.CCAssignFnForCall(Info.CallConv, Info.IsVarArg);
524 OutgoingValueAssigner ArgAssigner(ArgAssignFn);
525 ARMOutgoingValueHandler ArgHandler(MIRBuilder, MRI, MIB);
526 if (!determineAndHandleAssignments(ArgHandler, ArgAssigner, ArgInfos,
527 MIRBuilder, Info.CallConv, Info.IsVarArg))
528 return false;
529
530 // Now we can add the actual call instruction to the correct basic block.
531 MIRBuilder.insertInstr(MIB);
532
533 if (!Info.OrigRet.Ty->isVoidTy()) {
534 if (!isSupportedType(DL, TLI, Info.OrigRet.Ty))
535 return false;
536
537 ArgInfos.clear();
538 splitToValueTypes(Info.OrigRet, ArgInfos, DL, Info.CallConv);
539 auto RetAssignFn = TLI.CCAssignFnForReturn(Info.CallConv, Info.IsVarArg);
540 OutgoingValueAssigner Assigner(RetAssignFn);
541 CallReturnHandler RetHandler(MIRBuilder, MRI, MIB);
542 if (!determineAndHandleAssignments(RetHandler, Assigner, ArgInfos,
543 MIRBuilder, Info.CallConv,
544 Info.IsVarArg))
545 return false;
546 }
547
548 // We now know the size of the stack - update the ADJCALLSTACKDOWN
549 // accordingly.
550 CallSeqStart.addImm(ArgAssigner.StackSize).addImm(0).add(predOps(ARMCC::AL));
551
552 MIRBuilder.buildInstr(ARM::ADJCALLSTACKUP)
553 .addImm(ArgAssigner.StackSize)
554 .addImm(-1ULL)
556
557 return true;
558}
559
static unsigned getCallOpcode(const MachineFunction &CallerF, bool IsIndirect, bool IsTailCall, std::optional< CallLowering::PtrAuthInfo > &PAI, MachineRegisterInfo &MRI)
const AArch64Subtarget & Subtarget
const TargetLowering & TLI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
uint64_t uint64_t
static bool isSupportedType(const DataLayout &DL, const ARMTargetLowering &TLI, Type *T)
static cl::opt< bool > EnableGISelBigEndian("enable-arm-gisel-bigendian", cl::Hidden, cl::init(false), cl::desc("Enable Global-ISel Big Endian Lowering"))
This file describes how to lower LLVM calls to machine code calls.
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file contains the simple types necessary to represent the attributes associated with functions a...
Implement a low-level type suitable for MachineInstr level instruction selection.
Implement a low-level type suitable for MachineInstr level instruction selection.
#define F(x, y, z)
Definition MD5.cpp:54
This file declares the MachineIRBuilder class.
Register const TargetRegisterInfo * TRI
Promote Memory to Register
Definition Mem2Reg.cpp:110
#define T
static constexpr MCPhysReg SPReg
MachineRegisterInfo & MRI
This file defines the SmallVector class.
ARMCallLowering(const ARMTargetLowering &TLI)
bool lowerReturn(MachineIRBuilder &MIRBuilder, const Value *Val, ArrayRef< Register > VRegs, FunctionLoweringInfo &FLI) const override
This hook behaves as the extended lowerReturn function, but for targets that do not support swifterro...
bool enableBigEndian() const override
For targets which want to use big-endian can enable it with enableBigEndian() hook.
bool lowerFormalArguments(MachineIRBuilder &MIRBuilder, const Function &F, ArrayRef< ArrayRef< Register > > VRegs, FunctionLoweringInfo &FLI) const override
This hook must be implemented to lower the incoming (formal) arguments, described by VRegs,...
bool lowerCall(MachineIRBuilder &MIRBuilder, CallLoweringInfo &Info) const override
This hook must be implemented to lower the given call instruction, including argument and return valu...
const RegisterBankInfo * getRegBankInfo() const override
const ARMBaseInstrInfo * getInstrInfo() const override
bool isThumb1Only() const
const ARMBaseRegisterInfo * getRegisterInfo() const override
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
bool empty() const
Check if the array is empty.
Definition ArrayRef.h:136
Register getLocReg() const
LocInfo getLocInfo() const
bool needsCustom() const
unsigned getValNo() const
void splitToValueTypes(const ArgInfo &OrigArgInfo, SmallVectorImpl< ArgInfo > &SplitArgs, const DataLayout &DL, CallingConv::ID CallConv, SmallVectorImpl< TypeSize > *Offsets=nullptr) const
Break OrigArgInfo into one or more pieces the calling convention can process, returned in SplitArgs.
bool determineAndHandleAssignments(ValueHandler &Handler, ValueAssigner &Assigner, SmallVectorImpl< ArgInfo > &Args, MachineIRBuilder &MIRBuilder, CallingConv::ID CallConv, bool IsVarArg, ArrayRef< Register > ThisReturnRegs={}) const
Invoke ValueAssigner::assignArg on each of the given Args and then use Handler to move them to the as...
CallLowering(const TargetLowering *TLI)
const TargetLowering * getTLI() const
Getter for generic TargetLowering class.
void setArgFlags(ArgInfo &Arg, unsigned OpIdx, const DataLayout &DL, const FuncInfoTy &FuncInfo) const
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
FormalArgHandler(MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI)
FunctionLoweringInfo - This contains information that is global to a function that is used when lower...
constexpr bool isScalar() const
static constexpr LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
static constexpr LLT pointer(unsigned AddressSpace, unsigned SizeInBits)
Get a low-level pointer in the given address space.
LLT changeToInteger() const
static LLT integer(unsigned SizeInBits)
static constexpr LLT float32()
Get a 32-bit IEEE float value.
TypeSize getSizeInBits() const
Returns the size of the specified MVT in bits.
uint64_t getFixedSizeInBits() const
Return the size of the specified fixed width value type in bits.
LLVM_ABI int CreateFixedObject(uint64_t Size, int64_t SPOffset, bool IsImmutable, bool isAliased=false)
Create a new object at a fixed location on the stack.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
Function & getFunction()
Return the LLVM function that this machine code represents.
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags F, LLT MemTy, Align BaseAlignment, const MMOMetadata &Metadata=MMOMetadata(), SyncScope::ID SSID=SyncScope::System, AtomicOrdering Ordering=AtomicOrdering::NotAtomic, AtomicOrdering FailureOrdering=AtomicOrdering::NotAtomic)
getMachineMemOperand - Allocate a new MachineMemOperand.
Helper class to build MachineInstr.
MachineInstrBuilder insertInstr(MachineInstrBuilder MIB)
Insert an existing instruction at the insertion point.
void setInstr(MachineInstr &MI)
Set the insertion point to before MI.
MachineInstrBuilder buildMergeLikeInstr(const DstOp &Res, ArrayRef< Register > Ops)
Build and insert Res = G_MERGE_VALUES Op0, ... or Res = G_BUILD_VECTOR Op0, ... or Res = G_CONCAT_VEC...
MachineInstrBuilder buildLoad(const DstOp &Res, const SrcOp &Addr, MachineMemOperand &MMO)
Build and insert Res = G_LOAD Addr, MMO.
MachineInstrBuilder buildInstr(unsigned Opcode)
Build and insert <empty> = Opcode <empty>.
MachineInstrBuilder buildFrameIndex(const DstOp &Res, int Idx)
Build and insert Res = G_FRAME_INDEX Idx.
MachineFunction & getMF()
Getter for the function we currently build.
MachineInstrBuilder buildTrunc(const DstOp &Res, const SrcOp &Op, std::optional< unsigned > Flags=std::nullopt)
Build and insert Res = G_TRUNC Op.
const MachineBasicBlock & getMBB() const
Getter for the basic block we currently build.
void setMBB(MachineBasicBlock &MBB)
Set the insertion point to the end of MBB.
MachineInstrBuilder buildBitcast(const DstOp &Dst, const SrcOp &Src)
Build and insert Dst = G_BITCAST Src.
MachineInstrBuilder buildInstrNoInsert(unsigned Opcode)
Build but don't insert <empty> = Opcode <empty>.
MachineInstrBuilder buildCopy(const DstOp &Res, const SrcOp &Op)
Build and insert Res = COPY Op.
Register getReg(unsigned Idx) const
Get the register for the operand index.
const MachineInstrBuilder & setMIFlag(MachineInstr::MIFlag Flag) const
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & add(const MachineOperand &MO) const
const MachineInstrBuilder & addDef(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a virtual register definition operand.
@ MOLoad
The memory access reads data.
@ MOStore
The memory access writes data.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
LLT getType(Register Reg) const
Get the low-level type of Reg or LLT{} if Reg is not a generic (target independent) virtual register.
LLVM_ABI Register createGenericVirtualRegister(LLT Ty, StringRef Name="")
Create and return a new generic virtual register with low-level type Ty.
Wrapper class representing virtual and physical registers.
Definition Register.h:20
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:257
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
LLVM_ABI Register constrainOperandRegClass(const MachineFunction &MF, const TargetRegisterInfo &TRI, MachineRegisterInfo &MRI, const TargetInstrInfo &TII, const RegisterBankInfo &RBI, MachineInstr &InsertPt, const TargetRegisterClass &RegClass, MachineOperand &RegMO)
Constrain the Register operand OpIdx, so that it is now constrained to the TargetRegisterClass passed...
Definition Utils.cpp:64
@ Implicit
Not emitted register (e.g. carry, or temporary result).
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.
static std::array< MachineOperand, 2 > predOps(ARMCC::CondCodes Pred, unsigned PredReg=0)
Get the operands corresponding to the given Pred value.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
ArrayRef(const T &OneElt) -> ArrayRef< T >
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
unsigned gettBLXrOpcode(const MachineFunction &MF)
unsigned getBLXOpcode(const MachineFunction &MF)
LLVM_ABI Align inferAlignFromPtrInfo(MachineFunction &MF, const MachinePointerInfo &MPO)
Definition Utils.cpp:879
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition BitVector.h:881
SmallVector< Register, 4 > Regs
SmallVector< ISD::ArgFlagsTy, 4 > Flags
Base class for ValueHandlers used for arguments coming into the current function, or for return value...
Base class for ValueHandlers used for arguments passed to a function call, or for return values.
uint64_t StackSize
The size of the currently allocated portion of the stack.
Extended Value Type.
Definition ValueTypes.h:35
bool isSimple() const
Test if the given EVT is simple (as opposed to being extended).
Definition ValueTypes.h:160
bool isFloatingPoint() const
Return true if this is a FP or a vector FP type.
Definition ValueTypes.h:170
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
Definition ValueTypes.h:354
bool isVector() const
Return true if this is a vector value type.
Definition ValueTypes.h:191
bool isInteger() const
Return true if this is an integer or a vector integer type.
Definition ValueTypes.h:175
This class contains a discriminated union of information about pointers in memory operands,...
LLVM_ABI unsigned getAddrSpace() const
Return the LLVM IR address space number that this pointer points into.
static LLVM_ABI MachinePointerInfo getStack(MachineFunction &MF, int64_t Offset, uint8_t ID=0)
Stack pointer relative access.
static LLVM_ABI MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.