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