1 //===-- lib/CodeGen/GlobalISel/CallLowering.cpp - Call lowering -----------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 /// 10 /// \file 11 /// This file implements some simple delegations needed for call lowering. 12 /// 13 //===----------------------------------------------------------------------===// 14 15 16 #include "llvm/CodeGen/GlobalISel/CallLowering.h" 17 #include "llvm/CodeGen/MachineOperand.h" 18 #include "llvm/IR/Instructions.h" 19 20 using namespace llvm; 21 22 bool CallLowering::lowerCall( 23 MachineIRBuilder &MIRBuilder, const CallInst &CI, unsigned ResReg, 24 ArrayRef<unsigned> ArgRegs, std::function<unsigned()> GetCalleeReg) const { 25 // First step is to marshall all the function's parameters into the correct 26 // physregs and memory locations. Gather the sequence of argument types that 27 // we'll pass to the assigner function. 28 SmallVector<Type *, 8> ArgTys; 29 for (auto &Arg : CI.arg_operands()) 30 ArgTys.push_back(Arg->getType()); 31 32 MachineOperand Callee = MachineOperand::CreateImm(0); 33 if (Function *F = CI.getCalledFunction()) 34 Callee = MachineOperand::CreateGA(F, 0); 35 else 36 Callee = MachineOperand::CreateReg(GetCalleeReg(), false); 37 38 return lowerCall(MIRBuilder, Callee, CI.getType(), ResReg, ArgTys, ArgRegs); 39 } 40