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