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