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