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