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
55
57 Type *T) {
58 if (T->isArrayTy())
59 return isSupportedType(DL, TLI, T->getArrayElementType());
60
61 if (T->isStructTy()) {
62 // For now we only allow homogeneous structs that we can manipulate with
63 // G_MERGE_VALUES and G_UNMERGE_VALUES
64 auto StructT = cast<StructType>(T);
65 for (unsigned i = 1, e = StructT->getNumElements(); i != e; ++i)
66 if (StructT->getElementType(i) != StructT->getElementType(0))
67 return false;
68 return isSupportedType(DL, TLI, StructT->getElementType(0));
69 }
70
71 EVT VT = TLI.getValueType(DL, T, true);
72 if (!VT.isSimple() || VT.isVector() ||
73 !(VT.isInteger() || VT.isFloatingPoint()))
74 return false;
75
76 unsigned VTSize = VT.getSimpleVT().getSizeInBits();
77
78 if (VTSize == 64)
79 // FIXME: Support i64 too
80 return VT.isFloatingPoint();
81
82 return VTSize == 1 || VTSize == 8 || VTSize == 16 || VTSize == 32;
83}
84
85namespace {
86
87/// Helper class for values going out through an ABI boundary (used for handling
88/// function return values and call parameters).
89struct ARMOutgoingValueHandler : public CallLowering::OutgoingValueHandler {
90 ARMOutgoingValueHandler(MachineIRBuilder &MIRBuilder,
91 MachineRegisterInfo &MRI, MachineInstrBuilder &MIB)
92 : OutgoingValueHandler(MIRBuilder, MRI), MIB(MIB) {}
93
94 Register getStackAddress(uint64_t Size, int64_t Offset,
95 MachinePointerInfo &MPO,
96 ISD::ArgFlagsTy Flags) override {
97 assert((Size == 1 || Size == 2 || Size == 4 || Size == 8) &&
98 "Unsupported size");
99
100 LLT p0 = LLT::pointer(0, 32);
101 auto SPReg = MIRBuilder.buildCopy(p0, Register(ARM::SP));
102
103 auto OffsetReg = MIRBuilder.buildConstant(LLT::integer(32), Offset);
104
105 auto AddrReg = MIRBuilder.buildPtrAdd(p0, SPReg, OffsetReg);
106
107 MPO = MachinePointerInfo::getStack(MIRBuilder.getMF(), Offset);
108 return AddrReg.getReg(0);
109 }
110
111 void assignValueToReg(Register ValVReg, Register PhysReg,
112 const CCValAssign &VA,
113 ISD::ArgFlagsTy Flags = {}) override {
114 assert(VA.isRegLoc() && "Value shouldn't be assigned to reg");
115 assert(VA.getLocReg() == PhysReg && "Assigning to the wrong reg?");
116
117 assert(VA.getValVT().getSizeInBits() <= 64 && "Unsupported value size");
118 assert(VA.getLocVT().getSizeInBits() <= 64 && "Unsupported location size");
119
120 Register ExtReg = extendRegister(ValVReg, VA);
121 MIRBuilder.buildCopy(PhysReg, ExtReg);
122 MIB.addUse(PhysReg, RegState::Implicit);
123 }
124
125 void assignValueToAddress(Register ValVReg, Register Addr, LLT MemTy,
126 const MachinePointerInfo &MPO,
127 const CCValAssign &VA) override {
128 Register ExtReg = extendRegister(ValVReg, VA);
129 auto MMO = MIRBuilder.getMF().getMachineMemOperand(
130 MPO, MachineMemOperand::MOStore, MemTy, Align(1));
131 MIRBuilder.buildStore(ExtReg, Addr, *MMO);
132 }
133
134 unsigned assignCustomValue(CallLowering::ArgInfo &Arg,
136 std::function<void()> *Thunk) override {
137 assert(Arg.Regs.size() == 1 && "Can't handle multiple regs yet");
138
139 const CCValAssign &VA = VAs[0];
140 assert(VA.needsCustom() && "Value doesn't need custom handling");
141
142 // Custom lowering for other types, such as f16, is currently not supported
143 if (VA.getValVT() != MVT::f64)
144 return 0;
145
146 const CCValAssign &NextVA = VAs[1];
147 assert(NextVA.needsCustom() && "Value doesn't need custom handling");
148 assert(NextVA.getValVT() == MVT::f64 && "Unsupported type");
149
150 assert(VA.getValNo() == NextVA.getValNo() &&
151 "Values belong to different arguments");
152
153 assert(VA.isRegLoc() && "Value should be in reg");
154 assert(NextVA.isRegLoc() && "Value should be in reg");
155
158 MIRBuilder.buildUnmerge(NewRegs, Arg.Regs[0]);
159
160 bool IsLittle = MIRBuilder.getMF().getSubtarget<ARMSubtarget>().isLittle();
161 if (!IsLittle)
162 std::swap(NewRegs[0], NewRegs[1]);
163
164 if (Thunk) {
165 *Thunk = [=]() {
166 assignValueToReg(NewRegs[0], VA.getLocReg(), VA);
167 assignValueToReg(NewRegs[1], NextVA.getLocReg(), NextVA);
168 };
169 return 2;
170 }
171 assignValueToReg(NewRegs[0], VA.getLocReg(), VA);
172 assignValueToReg(NewRegs[1], NextVA.getLocReg(), NextVA);
173 return 2;
174 }
175
176 MachineInstrBuilder MIB;
177};
178
179} // end anonymous namespace
180
181/// Lower the return value for the already existing \p Ret. This assumes that
182/// \p MIRBuilder's insertion point is correct.
183bool ARMCallLowering::lowerReturnVal(MachineIRBuilder &MIRBuilder,
184 const Value *Val, ArrayRef<Register> VRegs,
185 MachineInstrBuilder &Ret) const {
186 if (!Val)
187 // Nothing to do here.
188 return true;
189
190 auto &MF = MIRBuilder.getMF();
191 const auto &F = MF.getFunction();
192
193 const auto &DL = MF.getDataLayout();
194 auto &TLI = *getTLI<ARMTargetLowering>();
195 if (!isSupportedType(DL, TLI, Val->getType()))
196 return false;
197
198 ArgInfo OrigRetInfo(VRegs, Val->getType(), 0);
199 setArgFlags(OrigRetInfo, AttributeList::ReturnIndex, DL, F);
200
201 SmallVector<ArgInfo, 4> SplitRetInfos;
202 splitToValueTypes(OrigRetInfo, SplitRetInfos, DL, F.getCallingConv());
203
204 CCAssignFn *AssignFn =
205 TLI.CCAssignFnForReturn(F.getCallingConv(), F.isVarArg());
206
207 OutgoingValueAssigner RetAssigner(AssignFn);
208 ARMOutgoingValueHandler RetHandler(MIRBuilder, MF.getRegInfo(), Ret);
209 return determineAndHandleAssignments(RetHandler, RetAssigner, SplitRetInfos,
210 MIRBuilder, F.getCallingConv(),
211 F.isVarArg());
212}
213
215 const Value *Val, ArrayRef<Register> VRegs,
216 FunctionLoweringInfo &FLI) const {
217 assert(!Val == VRegs.empty() && "Return value without a vreg");
218
219 auto const &ST = MIRBuilder.getMF().getSubtarget<ARMSubtarget>();
220 unsigned Opcode = ST.getReturnOpcode();
221 auto Ret = MIRBuilder.buildInstrNoInsert(Opcode).add(predOps(ARMCC::AL));
222
223 if (!lowerReturnVal(MIRBuilder, Val, VRegs, Ret))
224 return false;
225
226 MIRBuilder.insertInstr(Ret);
227 return true;
228}
229
230namespace {
231
232/// Helper class for values coming in through an ABI boundary (used for handling
233/// formal arguments and call return values).
234struct ARMIncomingValueHandler : public CallLowering::IncomingValueHandler {
235 ARMIncomingValueHandler(MachineIRBuilder &MIRBuilder,
237 : IncomingValueHandler(MIRBuilder, MRI) {}
238
239 Register getStackAddress(uint64_t Size, int64_t Offset,
241 ISD::ArgFlagsTy Flags) override {
242 assert((Size == 1 || Size == 2 || Size == 4 || Size == 8) &&
243 "Unsupported size");
244
245 auto &MFI = MIRBuilder.getMF().getFrameInfo();
246
247 // Byval is assumed to be writable memory, but other stack passed arguments
248 // are not.
249 const bool IsImmutable = !Flags.isByVal();
250
251 int FI = MFI.CreateFixedObject(Size, Offset, IsImmutable);
252 MPO = MachinePointerInfo::getFixedStack(MIRBuilder.getMF(), FI);
253
254 return MIRBuilder.buildFrameIndex(LLT::pointer(MPO.getAddrSpace(), 32), FI)
255 .getReg(0);
256 }
257
258 void assignValueToAddress(Register ValVReg, Register Addr, LLT MemTy,
259 const MachinePointerInfo &MPO,
260 const CCValAssign &VA) override {
261 if (VA.getLocInfo() == CCValAssign::SExt ||
263 // If the value is zero- or sign-extended, its size becomes 4 bytes, so
264 // that's what we should load.
265 MemTy = LLT::scalar(32);
266 assert(MRI.getType(ValVReg).isScalar() && "Only scalars supported atm");
267
268 auto LoadVReg = buildLoad(LLT::integer(32), Addr, MemTy, MPO);
269 MIRBuilder.buildTrunc(ValVReg, LoadVReg);
270 } else {
271 // If the value is not extended, a simple load will suffice.
272 buildLoad(ValVReg, Addr, MemTy, MPO);
273 }
274 }
275
276 MachineInstrBuilder buildLoad(const DstOp &Res, Register Addr, LLT MemTy,
277 const MachinePointerInfo &MPO) {
278 MachineFunction &MF = MIRBuilder.getMF();
279
280 auto MMO = MF.getMachineMemOperand(MPO, MachineMemOperand::MOLoad, MemTy,
281 inferAlignFromPtrInfo(MF, MPO));
282 return MIRBuilder.buildLoad(Res, Addr, *MMO);
283 }
284
285 void assignValueToReg(Register ValVReg, Register PhysReg,
286 const CCValAssign &VA,
287 ISD::ArgFlagsTy Flags = {}) override {
288 assert(VA.isRegLoc() && "Value shouldn't be assigned to reg");
289 assert(VA.getLocReg() == PhysReg && "Assigning to the wrong reg?");
290
291 uint64_t ValSize = VA.getValVT().getFixedSizeInBits();
292 uint64_t LocSize = VA.getLocVT().getFixedSizeInBits();
293
294 assert(ValSize <= 64 && "Unsupported value size");
295 assert(LocSize <= 64 && "Unsupported location size");
296
297 markPhysRegUsed(PhysReg);
298 if (ValSize == LocSize) {
299 MIRBuilder.buildCopy(ValVReg, PhysReg);
300 } else {
301 assert(ValSize < LocSize && "Extensions not supported");
302
303 // We cannot create a truncating copy, nor a trunc of a physical register.
304 // Therefore, we need to copy the content of the physical register into a
305 // virtual one and then truncate that.
306 auto PhysRegToVReg = MIRBuilder.buildCopy(LLT::integer(LocSize), PhysReg);
307 LLT ValTy = MRI.getType(ValVReg);
308 LLT ValITy = ValTy.changeToInteger();
309 if (ValTy == ValITy) {
310 MIRBuilder.buildTrunc(ValVReg, PhysRegToVReg);
311 } else {
312 auto T = MIRBuilder.buildTrunc(ValITy, PhysRegToVReg);
313 MIRBuilder.buildBitcast(ValVReg, T);
314 }
315 }
316 }
317
318 unsigned assignCustomValue(ARMCallLowering::ArgInfo &Arg,
320 std::function<void()> *Thunk) override {
321 assert(Arg.Regs.size() == 1 && "Can't handle multiple regs yet");
322
323 const CCValAssign &VA = VAs[0];
324 assert(VA.needsCustom() && "Value doesn't need custom handling");
325
326 // Custom lowering for other types, such as f16, is currently not supported
327 if (VA.getValVT() != MVT::f64)
328 return 0;
329
330 const CCValAssign &NextVA = VAs[1];
331 assert(NextVA.needsCustom() && "Value doesn't need custom handling");
332 assert(NextVA.getValVT() == MVT::f64 && "Unsupported type");
333
334 assert(VA.getValNo() == NextVA.getValNo() &&
335 "Values belong to different arguments");
336
337 assert(VA.isRegLoc() && "Value should be in reg");
338 assert(NextVA.isRegLoc() && "Value should be in reg");
339
342
343 assignValueToReg(NewRegs[0], VA.getLocReg(), VA);
344 assignValueToReg(NewRegs[1], NextVA.getLocReg(), NextVA);
345
346 bool IsLittle = MIRBuilder.getMF().getSubtarget<ARMSubtarget>().isLittle();
347 if (!IsLittle)
348 std::swap(NewRegs[0], NewRegs[1]);
349
350 MIRBuilder.buildMergeLikeInstr(Arg.Regs[0], NewRegs);
351
352 return 2;
353 }
354
355 /// Marking a physical register as used is different between formal
356 /// parameters, where it's a basic block live-in, and call returns, where it's
357 /// an implicit-def of the call instruction.
358 virtual void markPhysRegUsed(unsigned PhysReg) = 0;
359};
360
361struct FormalArgHandler : public ARMIncomingValueHandler {
362 FormalArgHandler(MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI)
363 : ARMIncomingValueHandler(MIRBuilder, MRI) {}
364
365 void markPhysRegUsed(unsigned PhysReg) override {
366 MIRBuilder.getMRI()->addLiveIn(PhysReg);
367 MIRBuilder.getMBB().addLiveIn(PhysReg);
368 }
369};
370
371} // end anonymous namespace
372
374 const Function &F,
376 FunctionLoweringInfo &FLI) const {
377 auto &TLI = *getTLI<ARMTargetLowering>();
378 auto Subtarget = TLI.getSubtarget();
379
380 if (Subtarget->isThumb1Only())
381 return false;
382
383 // Quick exit if there aren't any args
384 if (F.arg_empty())
385 return true;
386
387 if (F.isVarArg())
388 return false;
389
390 auto &MF = MIRBuilder.getMF();
391 auto &MBB = MIRBuilder.getMBB();
392 const auto &DL = MF.getDataLayout();
393
394 for (auto &Arg : F.args()) {
395 if (!isSupportedType(DL, TLI, Arg.getType()))
396 return false;
397 if (Arg.hasPassPointeeByValueCopyAttr())
398 return false;
399 }
400
401 CCAssignFn *AssignFn =
402 TLI.CCAssignFnForCall(F.getCallingConv(), F.isVarArg());
403
404 OutgoingValueAssigner ArgAssigner(AssignFn);
405 FormalArgHandler ArgHandler(MIRBuilder, MIRBuilder.getMF().getRegInfo());
406
407 SmallVector<ArgInfo, 8> SplitArgInfos;
408 unsigned Idx = 0;
409 for (auto &Arg : F.args()) {
410 ArgInfo OrigArgInfo(VRegs[Idx], Arg.getType(), Idx);
411
412 setArgFlags(OrigArgInfo, Idx + AttributeList::FirstArgIndex, DL, F);
413 splitToValueTypes(OrigArgInfo, SplitArgInfos, DL, F.getCallingConv());
414
415 Idx++;
416 }
417
418 if (!MBB.empty())
419 MIRBuilder.setInstr(*MBB.begin());
420
421 if (!determineAndHandleAssignments(ArgHandler, ArgAssigner, SplitArgInfos,
422 MIRBuilder, F.getCallingConv(),
423 F.isVarArg()))
424 return false;
425
426 // Move back to the end of the basic block.
427 MIRBuilder.setMBB(MBB);
428 return true;
429}
430
431namespace {
432
433struct CallReturnHandler : public ARMIncomingValueHandler {
434 CallReturnHandler(MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI,
436 : ARMIncomingValueHandler(MIRBuilder, MRI), MIB(MIB) {}
437
438 void markPhysRegUsed(unsigned PhysReg) override {
439 MIB.addDef(PhysReg, RegState::Implicit);
440 }
441
442 MachineInstrBuilder MIB;
443};
444
445// FIXME: This should move to the ARMSubtarget when it supports all the opcodes.
446unsigned getCallOpcode(const MachineFunction &MF, const ARMSubtarget &STI,
447 bool isDirect) {
448 if (isDirect)
449 return STI.isThumb() ? ARM::tBL : ARM::BL;
450
451 if (STI.isThumb())
452 return gettBLXrOpcode(MF);
453
454 if (STI.hasV5TOps())
455 return getBLXOpcode(MF);
456
457 if (STI.hasV4TOps())
458 return ARM::BX_CALL;
459
460 return ARM::BMOVPCRX_CALL;
461}
462} // end anonymous namespace
463
465 MachineFunction &MF = MIRBuilder.getMF();
466 const auto &TLI = *getTLI<ARMTargetLowering>();
467 const auto &DL = MF.getDataLayout();
468 const auto &STI = MF.getSubtarget<ARMSubtarget>();
471
472 if (STI.genLongCalls())
473 return false;
474
475 if (STI.isThumb1Only())
476 return false;
477
478 auto CallSeqStart = MIRBuilder.buildInstr(ARM::ADJCALLSTACKDOWN);
479
480 // Create the call instruction so we can add the implicit uses of arg
481 // registers, but don't insert it yet.
482 bool IsDirect = !Info.Callee.isReg();
483 auto CallOpcode = getCallOpcode(MF, STI, IsDirect);
484 auto MIB = MIRBuilder.buildInstrNoInsert(CallOpcode);
485 if (Info.NoMerge)
487
488 bool IsThumb = STI.isThumb();
489 if (IsThumb)
490 MIB.add(predOps(ARMCC::AL));
491
492 MIB.add(Info.Callee);
493 if (!IsDirect) {
494 auto CalleeReg = Info.Callee.getReg();
495 if (CalleeReg && !CalleeReg.isPhysical()) {
496 unsigned CalleeIdx = IsThumb ? 2 : 0;
497 MIB->getOperand(CalleeIdx).setReg(constrainOperandRegClass(
498 MF, *TRI, MRI, *STI.getInstrInfo(), *STI.getRegBankInfo(),
499 *MIB.getInstr(), MIB->getDesc(), Info.Callee, CalleeIdx));
500 }
501 }
502
503 MIB.addRegMask(TRI->getCallPreservedMask(MF, Info.CallConv));
504
506 for (auto Arg : Info.OrigArgs) {
507 if (!isSupportedType(DL, TLI, Arg.Ty))
508 return false;
509
510 if (Arg.Flags[0].isByVal())
511 return false;
512
513 splitToValueTypes(Arg, ArgInfos, DL, Info.CallConv);
514 }
515
516 auto ArgAssignFn = TLI.CCAssignFnForCall(Info.CallConv, Info.IsVarArg);
517 OutgoingValueAssigner ArgAssigner(ArgAssignFn);
518 ARMOutgoingValueHandler ArgHandler(MIRBuilder, MRI, MIB);
519 if (!determineAndHandleAssignments(ArgHandler, ArgAssigner, ArgInfos,
520 MIRBuilder, Info.CallConv, Info.IsVarArg))
521 return false;
522
523 // Now we can add the actual call instruction to the correct basic block.
524 MIRBuilder.insertInstr(MIB);
525
526 if (!Info.OrigRet.Ty->isVoidTy()) {
527 if (!isSupportedType(DL, TLI, Info.OrigRet.Ty))
528 return false;
529
530 ArgInfos.clear();
531 splitToValueTypes(Info.OrigRet, ArgInfos, DL, Info.CallConv);
532 auto RetAssignFn = TLI.CCAssignFnForReturn(Info.CallConv, Info.IsVarArg);
533 OutgoingValueAssigner Assigner(RetAssignFn);
534 CallReturnHandler RetHandler(MIRBuilder, MRI, MIB);
535 if (!determineAndHandleAssignments(RetHandler, Assigner, ArgInfos,
536 MIRBuilder, Info.CallConv,
537 Info.IsVarArg))
538 return false;
539 }
540
541 // We now know the size of the stack - update the ADJCALLSTACKDOWN
542 // accordingly.
543 CallSeqStart.addImm(ArgAssigner.StackSize).addImm(0).add(predOps(ARMCC::AL));
544
545 MIRBuilder.buildInstr(ARM::ADJCALLSTACKUP)
546 .addImm(ArgAssigner.StackSize)
547 .addImm(-1ULL)
549
550 return true;
551}
552
554 const ARMSubtarget &ST = *getTLI<ARMTargetLowering>()->getSubtarget();
555 return ST.getCLOpts().gisel_bigendian;
556}
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)
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:63
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.
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.