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