LLVM 19.0.0git
CallLowering.h
Go to the documentation of this file.
1//===- llvm/CodeGen/GlobalISel/CallLowering.h - Call lowering ---*- C++ -*-===//
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 describes how to lower LLVM calls to machine code calls.
11///
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CODEGEN_GLOBALISEL_CALLLOWERING_H
15#define LLVM_CODEGEN_GLOBALISEL_CALLLOWERING_H
16
17#include "llvm/ADT/ArrayRef.h"
24#include "llvm/IR/CallingConv.h"
25#include "llvm/IR/Type.h"
26#include "llvm/IR/Value.h"
28#include <cstdint>
29#include <functional>
30
31namespace llvm {
32
33class AttributeList;
34class CallBase;
35class DataLayout;
36class Function;
37class FunctionLoweringInfo;
38class MachineIRBuilder;
39class MachineFunction;
40struct MachinePointerInfo;
41class MachineRegisterInfo;
42class TargetLowering;
43
45 const TargetLowering *TLI;
46
47 virtual void anchor();
48public:
49 struct BaseArgInfo {
52 bool IsFixed;
53
56 bool IsFixed = true)
57 : Ty(Ty), Flags(Flags.begin(), Flags.end()), IsFixed(IsFixed) {}
58
59 BaseArgInfo() : Ty(nullptr), IsFixed(false) {}
60 };
61
62 struct ArgInfo : public BaseArgInfo {
64 // If the argument had to be split into multiple parts according to the
65 // target calling convention, then this contains the original vregs
66 // if the argument was an incoming arg.
68
69 /// Optionally track the original IR value for the argument. This may not be
70 /// meaningful in all contexts. This should only be used on for forwarding
71 /// through to use for aliasing information in MachinePointerInfo for memory
72 /// arguments.
73 const Value *OrigValue = nullptr;
74
75 /// Index original Function's argument.
76 unsigned OrigArgIndex;
77
78 /// Sentinel value for implicit machine-level input arguments.
79 static const unsigned NoArgIndex = UINT_MAX;
80
81 ArgInfo(ArrayRef<Register> Regs, Type *Ty, unsigned OrigIndex,
83 bool IsFixed = true, const Value *OrigValue = nullptr)
84 : BaseArgInfo(Ty, Flags, IsFixed), Regs(Regs.begin(), Regs.end()),
85 OrigValue(OrigValue), OrigArgIndex(OrigIndex) {
86 if (!Regs.empty() && Flags.empty())
87 this->Flags.push_back(ISD::ArgFlagsTy());
88 // FIXME: We should have just one way of saying "no register".
89 assert(((Ty->isVoidTy() || Ty->isEmptyTy()) ==
90 (Regs.empty() || Regs[0] == 0)) &&
91 "only void types should have no register");
92 }
93
94 ArgInfo(ArrayRef<Register> Regs, const Value &OrigValue, unsigned OrigIndex,
96 bool IsFixed = true)
97 : ArgInfo(Regs, OrigValue.getType(), OrigIndex, Flags, IsFixed, &OrigValue) {}
98
99 ArgInfo() = default;
100 };
101
103 /// Calling convention to be used for the call.
105
106 /// Destination of the call. It should be either a register, globaladdress,
107 /// or externalsymbol.
109
110 /// Descriptor for the return type of the function.
112
113 /// List of descriptors of the arguments passed to the function.
115
116 /// Valid if the call has a swifterror inout parameter, and contains the
117 /// vreg that the swifterror should be copied into after the call.
119
120 /// Valid if the call is a controlled convergent operation.
122
123 /// Original IR callsite corresponding to this call, if available.
124 const CallBase *CB = nullptr;
125
127
128 /// True if the call must be tail call optimized.
129 bool IsMustTailCall = false;
130
131 /// True if the call passes all target-independent checks for tail call
132 /// optimization.
133 bool IsTailCall = false;
134
135 /// True if the call was lowered as a tail call. This is consumed by the
136 /// legalizer. This allows the legalizer to lower libcalls as tail calls.
137 bool LoweredTailCall = false;
138
139 /// True if the call is to a vararg function.
140 bool IsVarArg = false;
141
142 /// True if the function's return value can be lowered to registers.
143 bool CanLowerReturn = true;
144
145 /// VReg to hold the hidden sret parameter.
147
148 /// The stack index for sret demotion.
150
151 /// Expected type identifier for indirect calls with a CFI check.
152 const ConstantInt *CFIType = nullptr;
153
154 /// True if this call results in convergent operations.
155 bool IsConvergent = true;
156 };
157
158 /// Argument handling is mostly uniform between the four places that
159 /// make these decisions: function formal arguments, call
160 /// instruction args, call instruction returns and function
161 /// returns. However, once a decision has been made on where an
162 /// argument should go, exactly what happens can vary slightly. This
163 /// class abstracts the differences.
164 ///
165 /// ValueAssigner should not depend on any specific function state, and
166 /// only determine the types and locations for arguments.
168 ValueAssigner(bool IsIncoming, CCAssignFn *AssignFn_,
169 CCAssignFn *AssignFnVarArg_ = nullptr)
170 : AssignFn(AssignFn_), AssignFnVarArg(AssignFnVarArg_),
171 IsIncomingArgumentHandler(IsIncoming) {
172
173 // Some targets change the handler depending on whether the call is
174 // varargs or not. If
175 if (!AssignFnVarArg)
177 }
178
179 virtual ~ValueAssigner() = default;
180
181 /// Returns true if the handler is dealing with incoming arguments,
182 /// i.e. those that move values from some physical location to vregs.
184 return IsIncomingArgumentHandler;
185 }
186
187 /// Wrap call to (typically tablegenerated CCAssignFn). This may be
188 /// overridden to track additional state information as arguments are
189 /// assigned or apply target specific hacks around the legacy
190 /// infrastructure.
191 virtual bool assignArg(unsigned ValNo, EVT OrigVT, MVT ValVT, MVT LocVT,
192 CCValAssign::LocInfo LocInfo, const ArgInfo &Info,
193 ISD::ArgFlagsTy Flags, CCState &State) {
194 if (getAssignFn(State.isVarArg())(ValNo, ValVT, LocVT, LocInfo, Flags,
195 State))
196 return true;
197 StackSize = State.getStackSize();
198 return false;
199 }
200
201 /// Assignment function to use for a general call.
203
204 /// Assignment function to use for a variadic call. This is usually the same
205 /// as AssignFn on most targets.
207
208 /// The size of the currently allocated portion of the stack.
210
211 /// Select the appropriate assignment function depending on whether this is
212 /// a variadic call.
213 CCAssignFn *getAssignFn(bool IsVarArg) const {
214 return IsVarArg ? AssignFnVarArg : AssignFn;
215 }
216
217 private:
218 const bool IsIncomingArgumentHandler;
219 virtual void anchor();
220 };
221
224 CCAssignFn *AssignFnVarArg_ = nullptr)
225 : ValueAssigner(true, AssignFn_, AssignFnVarArg_) {}
226 };
227
230 CCAssignFn *AssignFnVarArg_ = nullptr)
231 : ValueAssigner(false, AssignFn_, AssignFnVarArg_) {}
232 };
233
238
242 IsIncomingArgumentHandler(IsIncoming) {}
243
244 virtual ~ValueHandler() = default;
245
246 /// Returns true if the handler is dealing with incoming arguments,
247 /// i.e. those that move values from some physical location to vregs.
250 }
251
252 /// Materialize a VReg containing the address of the specified
253 /// stack-based object. This is either based on a FrameIndex or
254 /// direct SP manipulation, depending on the context. \p MPO
255 /// should be initialized to an appropriate description of the
256 /// address created.
257 virtual Register getStackAddress(uint64_t MemSize, int64_t Offset,
259 ISD::ArgFlagsTy Flags) = 0;
260
261 /// Return the in-memory size to write for the argument at \p VA. This may
262 /// be smaller than the allocated stack slot size.
263 ///
264 /// This is overridable primarily for targets to maintain compatibility with
265 /// hacks around the existing DAG call lowering infrastructure.
267 const CCValAssign &VA,
268 ISD::ArgFlagsTy Flags) const;
269
270 /// The specified value has been assigned to a physical register,
271 /// handle the appropriate COPY (either to or from) and mark any
272 /// relevant uses/defines as needed.
273 virtual void assignValueToReg(Register ValVReg, Register PhysReg,
274 const CCValAssign &VA) = 0;
275
276 /// The specified value has been assigned to a stack
277 /// location. Load or store it there, with appropriate extension
278 /// if necessary.
280 LLT MemTy, const MachinePointerInfo &MPO,
281 const CCValAssign &VA) = 0;
282
283 /// An overload which takes an ArgInfo if additional information about the
284 /// arg is needed. \p ValRegIndex is the index in \p Arg.Regs for the value
285 /// to store.
286 virtual void assignValueToAddress(const ArgInfo &Arg, unsigned ValRegIndex,
287 Register Addr, LLT MemTy,
288 const MachinePointerInfo &MPO,
289 const CCValAssign &VA) {
290 assignValueToAddress(Arg.Regs[ValRegIndex], Addr, MemTy, MPO, VA);
291 }
292
293 /// Handle custom values, which may be passed into one or more of \p VAs.
294 /// \p If the handler wants the assignments to be delayed until after
295 /// mem loc assignments, then it sets \p Thunk to the thunk to do the
296 /// assignment.
297 /// \return The number of \p VAs that have been assigned including the
298 /// first one, and which should therefore be skipped from further
299 /// processing.
301 std::function<void()> *Thunk = nullptr) {
302 // This is not a pure virtual method because not all targets need to worry
303 // about custom values.
304 llvm_unreachable("Custom values not supported");
305 }
306
307 /// Do a memory copy of \p MemSize bytes from \p SrcPtr to \p DstPtr. This
308 /// is necessary for outgoing stack-passed byval arguments.
309 void
310 copyArgumentMemory(const ArgInfo &Arg, Register DstPtr, Register SrcPtr,
311 const MachinePointerInfo &DstPtrInfo, Align DstAlign,
312 const MachinePointerInfo &SrcPtrInfo, Align SrcAlign,
313 uint64_t MemSize, CCValAssign &VA) const;
314
315 /// Extend a register to the location type given in VA, capped at extending
316 /// to at most MaxSize bits. If MaxSizeBits is 0 then no maximum is set.
318 unsigned MaxSizeBits = 0);
319 };
320
321 /// Base class for ValueHandlers used for arguments coming into the current
322 /// function, or for return values received from a call.
325 : ValueHandler(/*IsIncoming*/ true, MIRBuilder, MRI) {}
326
327 /// Insert G_ASSERT_ZEXT/G_ASSERT_SEXT or other hint instruction based on \p
328 /// VA, returning the new register if a hint was inserted.
330 LLT NarrowTy);
331
332 /// Provides a default implementation for argument handling.
333 void assignValueToReg(Register ValVReg, Register PhysReg,
334 const CCValAssign &VA) override;
335 };
336
337 /// Base class for ValueHandlers used for arguments passed to a function call,
338 /// or for return values.
341 : ValueHandler(/*IsIncoming*/ false, MIRBuilder, MRI) {}
342 };
343
344protected:
345 /// Getter for generic TargetLowering class.
346 const TargetLowering *getTLI() const {
347 return TLI;
348 }
349
350 /// Getter for target specific TargetLowering class.
351 template <class XXXTargetLowering>
352 const XXXTargetLowering *getTLI() const {
353 return static_cast<const XXXTargetLowering *>(TLI);
354 }
355
356 /// \returns Flags corresponding to the attributes on the \p ArgIdx-th
357 /// parameter of \p Call.
359 unsigned ArgIdx) const;
360
361 /// \returns Flags corresponding to the attributes on the return from \p Call.
363
364 /// Adds flags to \p Flags based off of the attributes in \p Attrs.
365 /// \p OpIdx is the index in \p Attrs to add flags from.
367 const AttributeList &Attrs,
368 unsigned OpIdx) const;
369
370 template <typename FuncInfoTy>
371 void setArgFlags(ArgInfo &Arg, unsigned OpIdx, const DataLayout &DL,
372 const FuncInfoTy &FuncInfo) const;
373
374 /// Break \p OrigArgInfo into one or more pieces the calling convention can
375 /// process, returned in \p SplitArgs. For example, this should break structs
376 /// down into individual fields.
377 ///
378 /// If \p Offsets is non-null, it points to a vector to be filled in
379 /// with the in-memory offsets of each of the individual values.
380 void splitToValueTypes(const ArgInfo &OrigArgInfo,
381 SmallVectorImpl<ArgInfo> &SplitArgs,
382 const DataLayout &DL, CallingConv::ID CallConv,
383 SmallVectorImpl<uint64_t> *Offsets = nullptr) const;
384
385 /// Analyze the argument list in \p Args, using \p Assigner to populate \p
386 /// CCInfo. This will determine the types and locations to use for passed or
387 /// returned values. This may resize fields in \p Args if the value is split
388 /// across multiple registers or stack slots.
389 ///
390 /// This is independent of the function state and can be used
391 /// to determine how a call would pass arguments without needing to change the
392 /// function. This can be used to check if arguments are suitable for tail
393 /// call lowering.
394 ///
395 /// \return True if everything has succeeded, false otherwise.
396 bool determineAssignments(ValueAssigner &Assigner,
398 CCState &CCInfo) const;
399
400 /// Invoke ValueAssigner::assignArg on each of the given \p Args and then use
401 /// \p Handler to move them to the assigned locations.
402 ///
403 /// \return True if everything has succeeded, false otherwise.
405 ValueHandler &Handler, ValueAssigner &Assigner,
407 CallingConv::ID CallConv, bool IsVarArg,
408 ArrayRef<Register> ThisReturnRegs = std::nullopt) const;
409
410 /// Use \p Handler to insert code to handle the argument/return values
411 /// represented by \p Args. It's expected determineAssignments previously
412 /// processed these arguments to populate \p CCState and \p ArgLocs.
413 bool
414 handleAssignments(ValueHandler &Handler, SmallVectorImpl<ArgInfo> &Args,
416 MachineIRBuilder &MIRBuilder,
417 ArrayRef<Register> ThisReturnRegs = std::nullopt) const;
418
419 /// Check whether parameters to a call that are passed in callee saved
420 /// registers are the same as from the calling function. This needs to be
421 /// checked for tail call eligibility.
423 const uint32_t *CallerPreservedMask,
424 const SmallVectorImpl<CCValAssign> &ArgLocs,
425 const SmallVectorImpl<ArgInfo> &OutVals) const;
426
427 /// \returns True if the calling convention for a callee and its caller pass
428 /// results in the same way. Typically used for tail call eligibility checks.
429 ///
430 /// \p Info is the CallLoweringInfo for the call.
431 /// \p MF is the MachineFunction for the caller.
432 /// \p InArgs contains the results of the call.
433 /// \p CalleeAssigner specifies the target's handling of the argument types
434 /// for the callee.
435 /// \p CallerAssigner specifies the target's handling of the
436 /// argument types for the caller.
437 bool resultsCompatible(CallLoweringInfo &Info, MachineFunction &MF,
439 ValueAssigner &CalleeAssigner,
440 ValueAssigner &CallerAssigner) const;
441
442public:
443 CallLowering(const TargetLowering *TLI) : TLI(TLI) {}
444 virtual ~CallLowering() = default;
445
446 /// \return true if the target is capable of handling swifterror values that
447 /// have been promoted to a specified register. The extended versions of
448 /// lowerReturn and lowerCall should be implemented.
449 virtual bool supportSwiftError() const {
450 return false;
451 }
452
453 /// Load the returned value from the stack into virtual registers in \p VRegs.
454 /// It uses the frame index \p FI and the start offset from \p DemoteReg.
455 /// The loaded data size will be determined from \p RetTy.
456 void insertSRetLoads(MachineIRBuilder &MIRBuilder, Type *RetTy,
457 ArrayRef<Register> VRegs, Register DemoteReg,
458 int FI) const;
459
460 /// Store the return value given by \p VRegs into stack starting at the offset
461 /// specified in \p DemoteReg.
462 void insertSRetStores(MachineIRBuilder &MIRBuilder, Type *RetTy,
463 ArrayRef<Register> VRegs, Register DemoteReg) const;
464
465 /// Insert the hidden sret ArgInfo to the beginning of \p SplitArgs.
466 /// This function should be called from the target specific
467 /// lowerFormalArguments when \p F requires the sret demotion.
469 SmallVectorImpl<ArgInfo> &SplitArgs,
470 Register &DemoteReg, MachineRegisterInfo &MRI,
471 const DataLayout &DL) const;
472
473 /// For the call-base described by \p CB, insert the hidden sret ArgInfo to
474 /// the OrigArgs field of \p Info.
476 const CallBase &CB,
477 CallLoweringInfo &Info) const;
478
479 /// \return True if the return type described by \p Outs can be returned
480 /// without performing sret demotion.
482 CCAssignFn *Fn) const;
483
484 /// Get the type and the ArgFlags for the split components of \p RetTy as
485 /// returned by \c ComputeValueVTs.
488 const DataLayout &DL) const;
489
490 /// Toplevel function to check the return type based on the target calling
491 /// convention. \return True if the return value of \p MF can be returned
492 /// without performing sret demotion.
494
495 /// This hook must be implemented to check whether the return values
496 /// described by \p Outs can fit into the return registers. If false
497 /// is returned, an sret-demotion is performed.
500 bool IsVarArg) const {
501 return true;
502 }
503
504 /// This hook must be implemented to lower outgoing return values, described
505 /// by \p Val, into the specified virtual registers \p VRegs.
506 /// This hook is used by GlobalISel.
507 ///
508 /// \p FLI is required for sret demotion.
509 ///
510 /// \p SwiftErrorVReg is non-zero if the function has a swifterror parameter
511 /// that needs to be implicitly returned.
512 ///
513 /// \return True if the lowering succeeds, false otherwise.
514 virtual bool lowerReturn(MachineIRBuilder &MIRBuilder, const Value *Val,
516 Register SwiftErrorVReg) const {
517 if (!supportSwiftError()) {
518 assert(SwiftErrorVReg == 0 && "attempt to use unsupported swifterror");
519 return lowerReturn(MIRBuilder, Val, VRegs, FLI);
520 }
521 return false;
522 }
523
524 /// This hook behaves as the extended lowerReturn function, but for targets
525 /// that do not support swifterror value promotion.
526 virtual bool lowerReturn(MachineIRBuilder &MIRBuilder, const Value *Val,
527 ArrayRef<Register> VRegs,
528 FunctionLoweringInfo &FLI) const {
529 return false;
530 }
531
532 virtual bool fallBackToDAGISel(const MachineFunction &MF) const {
533 return false;
534 }
535
536 /// This hook must be implemented to lower the incoming (formal)
537 /// arguments, described by \p VRegs, for GlobalISel. Each argument
538 /// must end up in the related virtual registers described by \p VRegs.
539 /// In other words, the first argument should end up in \c VRegs[0],
540 /// the second in \c VRegs[1], and so on. For each argument, there will be one
541 /// register for each non-aggregate type, as returned by \c computeValueLLTs.
542 /// \p MIRBuilder is set to the proper insertion for the argument
543 /// lowering. \p FLI is required for sret demotion.
544 ///
545 /// \return True if the lowering succeeded, false otherwise.
546 virtual bool lowerFormalArguments(MachineIRBuilder &MIRBuilder,
547 const Function &F,
549 FunctionLoweringInfo &FLI) const {
550 return false;
551 }
552
553 /// This hook must be implemented to lower the given call instruction,
554 /// including argument and return value marshalling.
555 ///
556 ///
557 /// \return true if the lowering succeeded, false otherwise.
558 virtual bool lowerCall(MachineIRBuilder &MIRBuilder,
559 CallLoweringInfo &Info) const {
560 return false;
561 }
562
563 /// Lower the given call instruction, including argument and return value
564 /// marshalling.
565 ///
566 /// \p CI is the call/invoke instruction.
567 ///
568 /// \p ResRegs are the registers where the call's return value should be
569 /// stored (or 0 if there is no return value). There will be one register for
570 /// each non-aggregate type, as returned by \c computeValueLLTs.
571 ///
572 /// \p ArgRegs is a list of lists of virtual registers containing each
573 /// argument that needs to be passed (argument \c i should be placed in \c
574 /// ArgRegs[i]). For each argument, there will be one register for each
575 /// non-aggregate type, as returned by \c computeValueLLTs.
576 ///
577 /// \p SwiftErrorVReg is non-zero if the call has a swifterror inout
578 /// parameter, and contains the vreg that the swifterror should be copied into
579 /// after the call.
580 ///
581 /// \p GetCalleeReg is a callback to materialize a register for the callee if
582 /// the target determines it cannot jump to the destination based purely on \p
583 /// CI. This might be because \p CI is indirect, or because of the limited
584 /// range of an immediate jump.
585 ///
586 /// \return true if the lowering succeeded, false otherwise.
587 bool lowerCall(MachineIRBuilder &MIRBuilder, const CallBase &Call,
588 ArrayRef<Register> ResRegs,
589 ArrayRef<ArrayRef<Register>> ArgRegs, Register SwiftErrorVReg,
590 Register ConvergenceCtrlToken,
591 std::function<unsigned()> GetCalleeReg) const;
592
593 /// For targets which want to use big-endian can enable it with
594 /// enableBigEndian() hook
595 virtual bool enableBigEndian() const { return false; }
596
597 /// For targets which support the "returned" parameter attribute, returns
598 /// true if the given type is a valid one to use with "returned".
599 virtual bool isTypeIsValidForThisReturn(EVT Ty) const { return false; }
600};
601
602} // end namespace llvm
603
604#endif // LLVM_CODEGEN_GLOBALISEL_CALLLOWERING_H
unsigned const MachineRegisterInfo * MRI
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
basic Basic Alias true
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
return RetTy
uint64_t Addr
Implement a low-level type suitable for MachineInstr level instruction selection.
#define F(x, y, z)
Definition: MD5.cpp:55
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
static SymbolRef::Type getType(const Symbol *Sym)
Definition: TapiFile.cpp:40
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
CCState - This class holds information needed while lowering arguments and return values.
uint64_t getStackSize() const
Returns the size of the currently allocated portion of the stack.
bool isVarArg() const
CCValAssign - Represent assignment of one arg/retval to a location.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1494
virtual ~CallLowering()=default
bool handleAssignments(ValueHandler &Handler, SmallVectorImpl< ArgInfo > &Args, CCState &CCState, SmallVectorImpl< CCValAssign > &ArgLocs, MachineIRBuilder &MIRBuilder, ArrayRef< Register > ThisReturnRegs=std::nullopt) const
Use Handler to insert code to handle the argument/return values represented by Args.
void insertSRetOutgoingArgument(MachineIRBuilder &MIRBuilder, const CallBase &CB, CallLoweringInfo &Info) const
For the call-base described by CB, insert the hidden sret ArgInfo to the OrigArgs field of Info.
void insertSRetLoads(MachineIRBuilder &MIRBuilder, Type *RetTy, ArrayRef< Register > VRegs, Register DemoteReg, int FI) const
Load the returned value from the stack into virtual registers in VRegs.
bool checkReturnTypeForCallConv(MachineFunction &MF) const
Toplevel function to check the return type based on the target calling convention.
bool determineAndHandleAssignments(ValueHandler &Handler, ValueAssigner &Assigner, SmallVectorImpl< ArgInfo > &Args, MachineIRBuilder &MIRBuilder, CallingConv::ID CallConv, bool IsVarArg, ArrayRef< Register > ThisReturnRegs=std::nullopt) const
Invoke ValueAssigner::assignArg on each of the given Args and then use Handler to move them to the as...
bool resultsCompatible(CallLoweringInfo &Info, MachineFunction &MF, SmallVectorImpl< ArgInfo > &InArgs, ValueAssigner &CalleeAssigner, ValueAssigner &CallerAssigner) const
void splitToValueTypes(const ArgInfo &OrigArgInfo, SmallVectorImpl< ArgInfo > &SplitArgs, const DataLayout &DL, CallingConv::ID CallConv, SmallVectorImpl< uint64_t > *Offsets=nullptr) const
Break OrigArgInfo into one or more pieces the calling convention can process, returned in SplitArgs.
virtual bool lowerFormalArguments(MachineIRBuilder &MIRBuilder, const Function &F, ArrayRef< ArrayRef< Register > > VRegs, FunctionLoweringInfo &FLI) const
This hook must be implemented to lower the incoming (formal) arguments, described by VRegs,...
Definition: CallLowering.h:546
virtual bool canLowerReturn(MachineFunction &MF, CallingConv::ID CallConv, SmallVectorImpl< BaseArgInfo > &Outs, bool IsVarArg) const
This hook must be implemented to check whether the return values described by Outs can fit into the r...
Definition: CallLowering.h:498
virtual bool isTypeIsValidForThisReturn(EVT Ty) const
For targets which support the "returned" parameter attribute, returns true if the given type is a val...
Definition: CallLowering.h:599
void insertSRetIncomingArgument(const Function &F, SmallVectorImpl< ArgInfo > &SplitArgs, Register &DemoteReg, MachineRegisterInfo &MRI, const DataLayout &DL) const
Insert the hidden sret ArgInfo to the beginning of SplitArgs.
ISD::ArgFlagsTy getAttributesForArgIdx(const CallBase &Call, unsigned ArgIdx) const
void insertSRetStores(MachineIRBuilder &MIRBuilder, Type *RetTy, ArrayRef< Register > VRegs, Register DemoteReg) const
Store the return value given by VRegs into stack starting at the offset specified in DemoteReg.
void addArgFlagsFromAttributes(ISD::ArgFlagsTy &Flags, const AttributeList &Attrs, unsigned OpIdx) const
Adds flags to Flags based off of the attributes in Attrs.
virtual bool enableBigEndian() const
For targets which want to use big-endian can enable it with enableBigEndian() hook.
Definition: CallLowering.h:595
virtual bool supportSwiftError() const
Definition: CallLowering.h:449
bool parametersInCSRMatch(const MachineRegisterInfo &MRI, const uint32_t *CallerPreservedMask, const SmallVectorImpl< CCValAssign > &ArgLocs, const SmallVectorImpl< ArgInfo > &OutVals) const
Check whether parameters to a call that are passed in callee saved registers are the same as from the...
void getReturnInfo(CallingConv::ID CallConv, Type *RetTy, AttributeList Attrs, SmallVectorImpl< BaseArgInfo > &Outs, const DataLayout &DL) const
Get the type and the ArgFlags for the split components of RetTy as returned by ComputeValueVTs.
bool determineAssignments(ValueAssigner &Assigner, SmallVectorImpl< ArgInfo > &Args, CCState &CCInfo) const
Analyze the argument list in Args, using Assigner to populate CCInfo.
bool checkReturn(CCState &CCInfo, SmallVectorImpl< BaseArgInfo > &Outs, CCAssignFn *Fn) const
CallLowering(const TargetLowering *TLI)
Definition: CallLowering.h:443
virtual bool lowerReturn(MachineIRBuilder &MIRBuilder, const Value *Val, ArrayRef< Register > VRegs, FunctionLoweringInfo &FLI, Register SwiftErrorVReg) const
This hook must be implemented to lower outgoing return values, described by Val, into the specified v...
Definition: CallLowering.h:514
virtual bool lowerReturn(MachineIRBuilder &MIRBuilder, const Value *Val, ArrayRef< Register > VRegs, FunctionLoweringInfo &FLI) const
This hook behaves as the extended lowerReturn function, but for targets that do not support swifterro...
Definition: CallLowering.h:526
const TargetLowering * getTLI() const
Getter for generic TargetLowering class.
Definition: CallLowering.h:346
const XXXTargetLowering * getTLI() const
Getter for target specific TargetLowering class.
Definition: CallLowering.h:352
virtual bool lowerCall(MachineIRBuilder &MIRBuilder, CallLoweringInfo &Info) const
This hook must be implemented to lower the given call instruction, including argument and return valu...
Definition: CallLowering.h:558
void setArgFlags(ArgInfo &Arg, unsigned OpIdx, const DataLayout &DL, const FuncInfoTy &FuncInfo) const
virtual bool fallBackToDAGISel(const MachineFunction &MF) const
Definition: CallLowering.h:532
ISD::ArgFlagsTy getAttributesForReturn(const CallBase &Call) const
This is the shared class of boolean and integer constants.
Definition: Constants.h:80
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:110
FunctionLoweringInfo - This contains information that is global to a function that is used when lower...
Metadata node.
Definition: Metadata.h:1067
Machine Value Type.
Helper class to build MachineInstr.
MachineOperand class - Representation of each machine instruction operand.
static MachineOperand CreateImm(int64_t Val)
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:586
void push_back(const T &Elt)
Definition: SmallVector.h:426
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
bool isEmptyTy() const
Return true if this type is empty, that is, it has no elements or all of its elements are empty.
bool isVoidTy() const
Return true if this is 'void'.
Definition: Type.h:140
LLVM Value Representation.
Definition: Value.h:74
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:456
bool CCAssignFn(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, CCState &State)
CCAssignFn - This function assigns a location for Val, updating State to reflect the change.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
Helper struct shared between Function Specialization and SCCP Solver.
Definition: SCCPSolver.h:41
const Value * OrigValue
Optionally track the original IR value for the argument.
Definition: CallLowering.h:73
SmallVector< Register, 4 > Regs
Definition: CallLowering.h:63
SmallVector< Register, 2 > OrigRegs
Definition: CallLowering.h:67
unsigned OrigArgIndex
Index original Function's argument.
Definition: CallLowering.h:76
ArgInfo(ArrayRef< Register > Regs, Type *Ty, unsigned OrigIndex, ArrayRef< ISD::ArgFlagsTy > Flags=ArrayRef< ISD::ArgFlagsTy >(), bool IsFixed=true, const Value *OrigValue=nullptr)
Definition: CallLowering.h:81
ArgInfo(ArrayRef< Register > Regs, const Value &OrigValue, unsigned OrigIndex, ArrayRef< ISD::ArgFlagsTy > Flags=ArrayRef< ISD::ArgFlagsTy >(), bool IsFixed=true)
Definition: CallLowering.h:94
static const unsigned NoArgIndex
Sentinel value for implicit machine-level input arguments.
Definition: CallLowering.h:79
SmallVector< ISD::ArgFlagsTy, 4 > Flags
Definition: CallLowering.h:51
BaseArgInfo(Type *Ty, ArrayRef< ISD::ArgFlagsTy > Flags=ArrayRef< ISD::ArgFlagsTy >(), bool IsFixed=true)
Definition: CallLowering.h:54
bool IsVarArg
True if the call is to a vararg function.
Definition: CallLowering.h:140
bool IsMustTailCall
True if the call must be tail call optimized.
Definition: CallLowering.h:129
bool IsTailCall
True if the call passes all target-independent checks for tail call optimization.
Definition: CallLowering.h:133
MachineOperand Callee
Destination of the call.
Definition: CallLowering.h:108
bool CanLowerReturn
True if the function's return value can be lowered to registers.
Definition: CallLowering.h:143
ArgInfo OrigRet
Descriptor for the return type of the function.
Definition: CallLowering.h:111
const ConstantInt * CFIType
Expected type identifier for indirect calls with a CFI check.
Definition: CallLowering.h:152
CallingConv::ID CallConv
Calling convention to be used for the call.
Definition: CallLowering.h:104
Register ConvergenceCtrlToken
Valid if the call is a controlled convergent operation.
Definition: CallLowering.h:121
const CallBase * CB
Original IR callsite corresponding to this call, if available.
Definition: CallLowering.h:124
Register DemoteRegister
VReg to hold the hidden sret parameter.
Definition: CallLowering.h:146
bool IsConvergent
True if this call results in convergent operations.
Definition: CallLowering.h:155
int DemoteStackIndex
The stack index for sret demotion.
Definition: CallLowering.h:149
Register SwiftErrorVReg
Valid if the call has a swifterror inout parameter, and contains the vreg that the swifterror should ...
Definition: CallLowering.h:118
SmallVector< ArgInfo, 32 > OrigArgs
List of descriptors of the arguments passed to the function.
Definition: CallLowering.h:114
bool LoweredTailCall
True if the call was lowered as a tail call.
Definition: CallLowering.h:137
IncomingValueAssigner(CCAssignFn *AssignFn_, CCAssignFn *AssignFnVarArg_=nullptr)
Definition: CallLowering.h:223
Base class for ValueHandlers used for arguments coming into the current function, or for return value...
Definition: CallLowering.h:323
void assignValueToReg(Register ValVReg, Register PhysReg, const CCValAssign &VA) override
Provides a default implementation for argument handling.
Register buildExtensionHint(const CCValAssign &VA, Register SrcReg, LLT NarrowTy)
Insert G_ASSERT_ZEXT/G_ASSERT_SEXT or other hint instruction based on VA, returning the new register ...
IncomingValueHandler(MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI)
Definition: CallLowering.h:324
OutgoingValueAssigner(CCAssignFn *AssignFn_, CCAssignFn *AssignFnVarArg_=nullptr)
Definition: CallLowering.h:229
Base class for ValueHandlers used for arguments passed to a function call, or for return values.
Definition: CallLowering.h:339
OutgoingValueHandler(MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI)
Definition: CallLowering.h:340
Argument handling is mostly uniform between the four places that make these decisions: function forma...
Definition: CallLowering.h:167
CCAssignFn * getAssignFn(bool IsVarArg) const
Select the appropriate assignment function depending on whether this is a variadic call.
Definition: CallLowering.h:213
CCAssignFn * AssignFn
Assignment function to use for a general call.
Definition: CallLowering.h:202
bool isIncomingArgumentHandler() const
Returns true if the handler is dealing with incoming arguments, i.e.
Definition: CallLowering.h:183
ValueAssigner(bool IsIncoming, CCAssignFn *AssignFn_, CCAssignFn *AssignFnVarArg_=nullptr)
Definition: CallLowering.h:168
CCAssignFn * AssignFnVarArg
Assignment function to use for a variadic call.
Definition: CallLowering.h:206
virtual bool assignArg(unsigned ValNo, EVT OrigVT, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, const ArgInfo &Info, ISD::ArgFlagsTy Flags, CCState &State)
Wrap call to (typically tablegenerated CCAssignFn).
Definition: CallLowering.h:191
uint64_t StackSize
The size of the currently allocated portion of the stack.
Definition: CallLowering.h:209
void copyArgumentMemory(const ArgInfo &Arg, Register DstPtr, Register SrcPtr, const MachinePointerInfo &DstPtrInfo, Align DstAlign, const MachinePointerInfo &SrcPtrInfo, Align SrcAlign, uint64_t MemSize, CCValAssign &VA) const
Do a memory copy of MemSize bytes from SrcPtr to DstPtr.
MachineRegisterInfo & MRI
Definition: CallLowering.h:236
virtual Register getStackAddress(uint64_t MemSize, int64_t Offset, MachinePointerInfo &MPO, ISD::ArgFlagsTy Flags)=0
Materialize a VReg containing the address of the specified stack-based object.
virtual void assignValueToAddress(const ArgInfo &Arg, unsigned ValRegIndex, Register Addr, LLT MemTy, const MachinePointerInfo &MPO, const CCValAssign &VA)
An overload which takes an ArgInfo if additional information about the arg is needed.
Definition: CallLowering.h:286
virtual LLT getStackValueStoreType(const DataLayout &DL, const CCValAssign &VA, ISD::ArgFlagsTy Flags) const
Return the in-memory size to write for the argument at VA.
bool isIncomingArgumentHandler() const
Returns true if the handler is dealing with incoming arguments, i.e.
Definition: CallLowering.h:248
virtual void assignValueToAddress(Register ValVReg, Register Addr, LLT MemTy, const MachinePointerInfo &MPO, const CCValAssign &VA)=0
The specified value has been assigned to a stack location.
Register extendRegister(Register ValReg, const CCValAssign &VA, unsigned MaxSizeBits=0)
Extend a register to the location type given in VA, capped at extending to at most MaxSize bits.
virtual unsigned assignCustomValue(ArgInfo &Arg, ArrayRef< CCValAssign > VAs, std::function< void()> *Thunk=nullptr)
Handle custom values, which may be passed into one or more of VAs.
Definition: CallLowering.h:300
virtual void assignValueToReg(Register ValVReg, Register PhysReg, const CCValAssign &VA)=0
The specified value has been assigned to a physical register, handle the appropriate COPY (either to ...
ValueHandler(bool IsIncoming, MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI)
Definition: CallLowering.h:239
Extended Value Type.
Definition: ValueTypes.h:34
This class contains a discriminated union of information about pointers in memory operands,...