ARMCallLowering.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  1. //===- llvm/lib/Target/ARM/ARMCallLowering.cpp - Call lowering ------------===//
  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 implements the lowering of LLVM calls to machine code calls for
  11. /// GlobalISel.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #include "ARMCallLowering.h"
  15. #include "ARMBaseInstrInfo.h"
  16. #include "ARMISelLowering.h"
  17. #include "ARMSubtarget.h"
  18. #include "Utils/ARMBaseInfo.h"
  19. #include "llvm/ADT/SmallVector.h"
  20. #include "llvm/CodeGen/Analysis.h"
  21. #include "llvm/CodeGen/CallingConvLower.h"
  22. #include "llvm/CodeGen/GlobalISel/MachineIRBuilder.h"
  23. #include "llvm/CodeGen/GlobalISel/Utils.h"
  24. #include "llvm/CodeGen/LowLevelType.h"
  25. #include "llvm/CodeGen/MachineBasicBlock.h"
  26. #include "llvm/CodeGen/MachineFrameInfo.h"
  27. #include "llvm/CodeGen/MachineFunction.h"
  28. #include "llvm/CodeGen/MachineInstrBuilder.h"
  29. #include "llvm/CodeGen/MachineMemOperand.h"
  30. #include "llvm/CodeGen/MachineOperand.h"
  31. #include "llvm/CodeGen/MachineRegisterInfo.h"
  32. #include "llvm/CodeGen/TargetRegisterInfo.h"
  33. #include "llvm/CodeGen/TargetSubtargetInfo.h"
  34. #include "llvm/CodeGen/ValueTypes.h"
  35. #include "llvm/IR/Attributes.h"
  36. #include "llvm/IR/DataLayout.h"
  37. #include "llvm/IR/DerivedTypes.h"
  38. #include "llvm/IR/Function.h"
  39. #include "llvm/IR/Type.h"
  40. #include "llvm/IR/Value.h"
  41. #include "llvm/Support/Casting.h"
  42. #include "llvm/Support/LowLevelTypeImpl.h"
  43. #include "llvm/Support/MachineValueType.h"
  44. #include <algorithm>
  45. #include <cassert>
  46. #include <cstdint>
  47. #include <functional>
  48. #include <utility>
  49. using namespace llvm;
  50. ARMCallLowering::ARMCallLowering(const ARMTargetLowering &TLI)
  51. : CallLowering(&TLI) {}
  52. static bool isSupportedType(const DataLayout &DL, const ARMTargetLowering &TLI,
  53. Type *T) {
  54. if (T->isArrayTy())
  55. return isSupportedType(DL, TLI, T->getArrayElementType());
  56. if (T->isStructTy()) {
  57. // For now we only allow homogeneous structs that we can manipulate with
  58. // G_MERGE_VALUES and G_UNMERGE_VALUES
  59. auto StructT = cast<StructType>(T);
  60. for (unsigned i = 1, e = StructT->getNumElements(); i != e; ++i)
  61. if (StructT->getElementType(i) != StructT->getElementType(0))
  62. return false;
  63. return isSupportedType(DL, TLI, StructT->getElementType(0));
  64. }
  65. EVT VT = TLI.getValueType(DL, T, true);
  66. if (!VT.isSimple() || VT.isVector() ||
  67. !(VT.isInteger() || VT.isFloatingPoint()))
  68. return false;
  69. unsigned VTSize = VT.getSimpleVT().getSizeInBits();
  70. if (VTSize == 64)
  71. // FIXME: Support i64 too
  72. return VT.isFloatingPoint();
  73. return VTSize == 1 || VTSize == 8 || VTSize == 16 || VTSize == 32;
  74. }
  75. namespace {
  76. /// Helper class for values going out through an ABI boundary (used for handling
  77. /// function return values and call parameters).
  78. struct ARMOutgoingValueHandler : public CallLowering::OutgoingValueHandler {
  79. ARMOutgoingValueHandler(MachineIRBuilder &MIRBuilder,
  80. MachineRegisterInfo &MRI, MachineInstrBuilder &MIB)
  81. : OutgoingValueHandler(MIRBuilder, MRI), MIB(MIB) {}
  82. Register getStackAddress(uint64_t Size, int64_t Offset,
  83. MachinePointerInfo &MPO,
  84. ISD::ArgFlagsTy Flags) override {
  85. assert((Size == 1 || Size == 2 || Size == 4 || Size == 8) &&
  86. "Unsupported size");
  87. LLT p0 = LLT::pointer(0, 32);
  88. LLT s32 = LLT::scalar(32);
  89. auto SPReg = MIRBuilder.buildCopy(p0, Register(ARM::SP));
  90. auto OffsetReg = MIRBuilder.buildConstant(s32, Offset);
  91. auto AddrReg = MIRBuilder.buildPtrAdd(p0, SPReg, OffsetReg);
  92. MPO = MachinePointerInfo::getStack(MIRBuilder.getMF(), Offset);
  93. return AddrReg.getReg(0);
  94. }
  95. void assignValueToReg(Register ValVReg, Register PhysReg,
  96. CCValAssign VA) override {
  97. assert(VA.isRegLoc() && "Value shouldn't be assigned to reg");
  98. assert(VA.getLocReg() == PhysReg && "Assigning to the wrong reg?");
  99. assert(VA.getValVT().getSizeInBits() <= 64 && "Unsupported value size");
  100. assert(VA.getLocVT().getSizeInBits() <= 64 && "Unsupported location size");
  101. Register ExtReg = extendRegister(ValVReg, VA);
  102. MIRBuilder.buildCopy(PhysReg, ExtReg);
  103. MIB.addUse(PhysReg, RegState::Implicit);
  104. }
  105. void assignValueToAddress(Register ValVReg, Register Addr, LLT MemTy,
  106. MachinePointerInfo &MPO, CCValAssign &VA) override {
  107. Register ExtReg = extendRegister(ValVReg, VA);
  108. auto MMO = MIRBuilder.getMF().getMachineMemOperand(
  109. MPO, MachineMemOperand::MOStore, MemTy, Align(1));
  110. MIRBuilder.buildStore(ExtReg, Addr, *MMO);
  111. }
  112. unsigned assignCustomValue(CallLowering::ArgInfo &Arg,
  113. ArrayRef<CCValAssign> VAs,
  114. std::function<void()> *Thunk) override {
  115. assert(Arg.Regs.size() == 1 && "Can't handle multple regs yet");
  116. CCValAssign VA = VAs[0];
  117. assert(VA.needsCustom() && "Value doesn't need custom handling");
  118. // Custom lowering for other types, such as f16, is currently not supported
  119. if (VA.getValVT() != MVT::f64)
  120. return 0;
  121. CCValAssign NextVA = VAs[1];
  122. assert(NextVA.needsCustom() && "Value doesn't need custom handling");
  123. assert(NextVA.getValVT() == MVT::f64 && "Unsupported type");
  124. assert(VA.getValNo() == NextVA.getValNo() &&
  125. "Values belong to different arguments");
  126. assert(VA.isRegLoc() && "Value should be in reg");
  127. assert(NextVA.isRegLoc() && "Value should be in reg");
  128. Register NewRegs[] = {MRI.createGenericVirtualRegister(LLT::scalar(32)),
  129. MRI.createGenericVirtualRegister(LLT::scalar(32))};
  130. MIRBuilder.buildUnmerge(NewRegs, Arg.Regs[0]);
  131. bool IsLittle = MIRBuilder.getMF().getSubtarget<ARMSubtarget>().isLittle();
  132. if (!IsLittle)
  133. std::swap(NewRegs[0], NewRegs[1]);
  134. if (Thunk) {
  135. *Thunk = [=]() {
  136. assignValueToReg(NewRegs[0], VA.getLocReg(), VA);
  137. assignValueToReg(NewRegs[1], NextVA.getLocReg(), NextVA);
  138. };
  139. return 1;
  140. }
  141. assignValueToReg(NewRegs[0], VA.getLocReg(), VA);
  142. assignValueToReg(NewRegs[1], NextVA.getLocReg(), NextVA);
  143. return 1;
  144. }
  145. MachineInstrBuilder MIB;
  146. };
  147. } // end anonymous namespace
  148. /// Lower the return value for the already existing \p Ret. This assumes that
  149. /// \p MIRBuilder's insertion point is correct.
  150. bool ARMCallLowering::lowerReturnVal(MachineIRBuilder &MIRBuilder,
  151. const Value *Val, ArrayRef<Register> VRegs,
  152. MachineInstrBuilder &Ret) const {
  153. if (!Val)
  154. // Nothing to do here.
  155. return true;
  156. auto &MF = MIRBuilder.getMF();
  157. const auto &F = MF.getFunction();
  158. const auto &DL = MF.getDataLayout();
  159. auto &TLI = *getTLI<ARMTargetLowering>();
  160. if (!isSupportedType(DL, TLI, Val->getType()))
  161. return false;
  162. ArgInfo OrigRetInfo(VRegs, Val->getType(), 0);
  163. setArgFlags(OrigRetInfo, AttributeList::ReturnIndex, DL, F);
  164. SmallVector<ArgInfo, 4> SplitRetInfos;
  165. splitToValueTypes(OrigRetInfo, SplitRetInfos, DL, F.getCallingConv());
  166. CCAssignFn *AssignFn =
  167. TLI.CCAssignFnForReturn(F.getCallingConv(), F.isVarArg());
  168. OutgoingValueAssigner RetAssigner(AssignFn);
  169. ARMOutgoingValueHandler RetHandler(MIRBuilder, MF.getRegInfo(), Ret);
  170. return determineAndHandleAssignments(RetHandler, RetAssigner, SplitRetInfos,
  171. MIRBuilder, F.getCallingConv(),
  172. F.isVarArg());
  173. }
  174. bool ARMCallLowering::lowerReturn(MachineIRBuilder &MIRBuilder,
  175. const Value *Val, ArrayRef<Register> VRegs,
  176. FunctionLoweringInfo &FLI) const {
  177. assert(!Val == VRegs.empty() && "Return value without a vreg");
  178. auto const &ST = MIRBuilder.getMF().getSubtarget<ARMSubtarget>();
  179. unsigned Opcode = ST.getReturnOpcode();
  180. auto Ret = MIRBuilder.buildInstrNoInsert(Opcode).add(predOps(ARMCC::AL));
  181. if (!lowerReturnVal(MIRBuilder, Val, VRegs, Ret))
  182. return false;
  183. MIRBuilder.insertInstr(Ret);
  184. return true;
  185. }
  186. namespace {
  187. /// Helper class for values coming in through an ABI boundary (used for handling
  188. /// formal arguments and call return values).
  189. struct ARMIncomingValueHandler : public CallLowering::IncomingValueHandler {
  190. ARMIncomingValueHandler(MachineIRBuilder &MIRBuilder,
  191. MachineRegisterInfo &MRI)
  192. : IncomingValueHandler(MIRBuilder, MRI) {}
  193. Register getStackAddress(uint64_t Size, int64_t Offset,
  194. MachinePointerInfo &MPO,
  195. ISD::ArgFlagsTy Flags) override {
  196. assert((Size == 1 || Size == 2 || Size == 4 || Size == 8) &&
  197. "Unsupported size");
  198. auto &MFI = MIRBuilder.getMF().getFrameInfo();
  199. // Byval is assumed to be writable memory, but other stack passed arguments
  200. // are not.
  201. const bool IsImmutable = !Flags.isByVal();
  202. int FI = MFI.CreateFixedObject(Size, Offset, IsImmutable);
  203. MPO = MachinePointerInfo::getFixedStack(MIRBuilder.getMF(), FI);
  204. return MIRBuilder.buildFrameIndex(LLT::pointer(MPO.getAddrSpace(), 32), FI)
  205. .getReg(0);
  206. }
  207. void assignValueToAddress(Register ValVReg, Register Addr, LLT MemTy,
  208. MachinePointerInfo &MPO, CCValAssign &VA) override {
  209. if (VA.getLocInfo() == CCValAssign::SExt ||
  210. VA.getLocInfo() == CCValAssign::ZExt) {
  211. // If the value is zero- or sign-extended, its size becomes 4 bytes, so
  212. // that's what we should load.
  213. MemTy = LLT::scalar(32);
  214. assert(MRI.getType(ValVReg).isScalar() && "Only scalars supported atm");
  215. auto LoadVReg = buildLoad(LLT::scalar(32), Addr, MemTy, MPO);
  216. MIRBuilder.buildTrunc(ValVReg, LoadVReg);
  217. } else {
  218. // If the value is not extended, a simple load will suffice.
  219. buildLoad(ValVReg, Addr, MemTy, MPO);
  220. }
  221. }
  222. MachineInstrBuilder buildLoad(const DstOp &Res, Register Addr, LLT MemTy,
  223. MachinePointerInfo &MPO) {
  224. MachineFunction &MF = MIRBuilder.getMF();
  225. auto MMO = MF.getMachineMemOperand(MPO, MachineMemOperand::MOLoad, MemTy,
  226. inferAlignFromPtrInfo(MF, MPO));
  227. return MIRBuilder.buildLoad(Res, Addr, *MMO);
  228. }
  229. void assignValueToReg(Register ValVReg, Register PhysReg,
  230. CCValAssign VA) override {
  231. assert(VA.isRegLoc() && "Value shouldn't be assigned to reg");
  232. assert(VA.getLocReg() == PhysReg && "Assigning to the wrong reg?");
  233. uint64_t ValSize = VA.getValVT().getFixedSizeInBits();
  234. uint64_t LocSize = VA.getLocVT().getFixedSizeInBits();
  235. assert(ValSize <= 64 && "Unsupported value size");
  236. assert(LocSize <= 64 && "Unsupported location size");
  237. markPhysRegUsed(PhysReg);
  238. if (ValSize == LocSize) {
  239. MIRBuilder.buildCopy(ValVReg, PhysReg);
  240. } else {
  241. assert(ValSize < LocSize && "Extensions not supported");
  242. // We cannot create a truncating copy, nor a trunc of a physical register.
  243. // Therefore, we need to copy the content of the physical register into a
  244. // virtual one and then truncate that.
  245. auto PhysRegToVReg = MIRBuilder.buildCopy(LLT::scalar(LocSize), PhysReg);
  246. MIRBuilder.buildTrunc(ValVReg, PhysRegToVReg);
  247. }
  248. }
  249. unsigned assignCustomValue(ARMCallLowering::ArgInfo &Arg,
  250. ArrayRef<CCValAssign> VAs,
  251. std::function<void()> *Thunk) override {
  252. assert(Arg.Regs.size() == 1 && "Can't handle multple regs yet");
  253. CCValAssign VA = VAs[0];
  254. assert(VA.needsCustom() && "Value doesn't need custom handling");
  255. // Custom lowering for other types, such as f16, is currently not supported
  256. if (VA.getValVT() != MVT::f64)
  257. return 0;
  258. CCValAssign NextVA = VAs[1];
  259. assert(NextVA.needsCustom() && "Value doesn't need custom handling");
  260. assert(NextVA.getValVT() == MVT::f64 && "Unsupported type");
  261. assert(VA.getValNo() == NextVA.getValNo() &&
  262. "Values belong to different arguments");
  263. assert(VA.isRegLoc() && "Value should be in reg");
  264. assert(NextVA.isRegLoc() && "Value should be in reg");
  265. Register NewRegs[] = {MRI.createGenericVirtualRegister(LLT::scalar(32)),
  266. MRI.createGenericVirtualRegister(LLT::scalar(32))};
  267. assignValueToReg(NewRegs[0], VA.getLocReg(), VA);
  268. assignValueToReg(NewRegs[1], NextVA.getLocReg(), NextVA);
  269. bool IsLittle = MIRBuilder.getMF().getSubtarget<ARMSubtarget>().isLittle();
  270. if (!IsLittle)
  271. std::swap(NewRegs[0], NewRegs[1]);
  272. MIRBuilder.buildMerge(Arg.Regs[0], NewRegs);
  273. return 1;
  274. }
  275. /// Marking a physical register as used is different between formal
  276. /// parameters, where it's a basic block live-in, and call returns, where it's
  277. /// an implicit-def of the call instruction.
  278. virtual void markPhysRegUsed(unsigned PhysReg) = 0;
  279. };
  280. struct FormalArgHandler : public ARMIncomingValueHandler {
  281. FormalArgHandler(MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI)
  282. : ARMIncomingValueHandler(MIRBuilder, MRI) {}
  283. void markPhysRegUsed(unsigned PhysReg) override {
  284. MIRBuilder.getMRI()->addLiveIn(PhysReg);
  285. MIRBuilder.getMBB().addLiveIn(PhysReg);
  286. }
  287. };
  288. } // end anonymous namespace
  289. bool ARMCallLowering::lowerFormalArguments(MachineIRBuilder &MIRBuilder,
  290. const Function &F,
  291. ArrayRef<ArrayRef<Register>> VRegs,
  292. FunctionLoweringInfo &FLI) const {
  293. auto &TLI = *getTLI<ARMTargetLowering>();
  294. auto Subtarget = TLI.getSubtarget();
  295. if (Subtarget->isThumb1Only())
  296. return false;
  297. // Quick exit if there aren't any args
  298. if (F.arg_empty())
  299. return true;
  300. if (F.isVarArg())
  301. return false;
  302. auto &MF = MIRBuilder.getMF();
  303. auto &MBB = MIRBuilder.getMBB();
  304. const auto &DL = MF.getDataLayout();
  305. for (auto &Arg : F.args()) {
  306. if (!isSupportedType(DL, TLI, Arg.getType()))
  307. return false;
  308. if (Arg.hasPassPointeeByValueCopyAttr())
  309. return false;
  310. }
  311. CCAssignFn *AssignFn =
  312. TLI.CCAssignFnForCall(F.getCallingConv(), F.isVarArg());
  313. OutgoingValueAssigner ArgAssigner(AssignFn);
  314. FormalArgHandler ArgHandler(MIRBuilder, MIRBuilder.getMF().getRegInfo());
  315. SmallVector<ArgInfo, 8> SplitArgInfos;
  316. unsigned Idx = 0;
  317. for (auto &Arg : F.args()) {
  318. ArgInfo OrigArgInfo(VRegs[Idx], Arg.getType(), Idx);
  319. setArgFlags(OrigArgInfo, Idx + AttributeList::FirstArgIndex, DL, F);
  320. splitToValueTypes(OrigArgInfo, SplitArgInfos, DL, F.getCallingConv());
  321. Idx++;
  322. }
  323. if (!MBB.empty())
  324. MIRBuilder.setInstr(*MBB.begin());
  325. if (!determineAndHandleAssignments(ArgHandler, ArgAssigner, SplitArgInfos,
  326. MIRBuilder, F.getCallingConv(),
  327. F.isVarArg()))
  328. return false;
  329. // Move back to the end of the basic block.
  330. MIRBuilder.setMBB(MBB);
  331. return true;
  332. }
  333. namespace {
  334. struct CallReturnHandler : public ARMIncomingValueHandler {
  335. CallReturnHandler(MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI,
  336. MachineInstrBuilder MIB)
  337. : ARMIncomingValueHandler(MIRBuilder, MRI), MIB(MIB) {}
  338. void markPhysRegUsed(unsigned PhysReg) override {
  339. MIB.addDef(PhysReg, RegState::Implicit);
  340. }
  341. MachineInstrBuilder MIB;
  342. };
  343. // FIXME: This should move to the ARMSubtarget when it supports all the opcodes.
  344. unsigned getCallOpcode(const MachineFunction &MF, const ARMSubtarget &STI,
  345. bool isDirect) {
  346. if (isDirect)
  347. return STI.isThumb() ? ARM::tBL : ARM::BL;
  348. if (STI.isThumb())
  349. return gettBLXrOpcode(MF);
  350. if (STI.hasV5TOps())
  351. return getBLXOpcode(MF);
  352. if (STI.hasV4TOps())
  353. return ARM::BX_CALL;
  354. return ARM::BMOVPCRX_CALL;
  355. }
  356. } // end anonymous namespace
  357. bool ARMCallLowering::lowerCall(MachineIRBuilder &MIRBuilder, CallLoweringInfo &Info) const {
  358. MachineFunction &MF = MIRBuilder.getMF();
  359. const auto &TLI = *getTLI<ARMTargetLowering>();
  360. const auto &DL = MF.getDataLayout();
  361. const auto &STI = MF.getSubtarget<ARMSubtarget>();
  362. const TargetRegisterInfo *TRI = STI.getRegisterInfo();
  363. MachineRegisterInfo &MRI = MF.getRegInfo();
  364. if (STI.genLongCalls())
  365. return false;
  366. if (STI.isThumb1Only())
  367. return false;
  368. auto CallSeqStart = MIRBuilder.buildInstr(ARM::ADJCALLSTACKDOWN);
  369. // Create the call instruction so we can add the implicit uses of arg
  370. // registers, but don't insert it yet.
  371. bool IsDirect = !Info.Callee.isReg();
  372. auto CallOpcode = getCallOpcode(MF, STI, IsDirect);
  373. auto MIB = MIRBuilder.buildInstrNoInsert(CallOpcode);
  374. bool IsThumb = STI.isThumb();
  375. if (IsThumb)
  376. MIB.add(predOps(ARMCC::AL));
  377. MIB.add(Info.Callee);
  378. if (!IsDirect) {
  379. auto CalleeReg = Info.Callee.getReg();
  380. if (CalleeReg && !Register::isPhysicalRegister(CalleeReg)) {
  381. unsigned CalleeIdx = IsThumb ? 2 : 0;
  382. MIB->getOperand(CalleeIdx).setReg(constrainOperandRegClass(
  383. MF, *TRI, MRI, *STI.getInstrInfo(), *STI.getRegBankInfo(),
  384. *MIB.getInstr(), MIB->getDesc(), Info.Callee, CalleeIdx));
  385. }
  386. }
  387. MIB.addRegMask(TRI->getCallPreservedMask(MF, Info.CallConv));
  388. SmallVector<ArgInfo, 8> ArgInfos;
  389. for (auto Arg : Info.OrigArgs) {
  390. if (!isSupportedType(DL, TLI, Arg.Ty))
  391. return false;
  392. if (Arg.Flags[0].isByVal())
  393. return false;
  394. splitToValueTypes(Arg, ArgInfos, DL, Info.CallConv);
  395. }
  396. auto ArgAssignFn = TLI.CCAssignFnForCall(Info.CallConv, Info.IsVarArg);
  397. OutgoingValueAssigner ArgAssigner(ArgAssignFn);
  398. ARMOutgoingValueHandler ArgHandler(MIRBuilder, MRI, MIB);
  399. if (!determineAndHandleAssignments(ArgHandler, ArgAssigner, ArgInfos,
  400. MIRBuilder, Info.CallConv, Info.IsVarArg))
  401. return false;
  402. // Now we can add the actual call instruction to the correct basic block.
  403. MIRBuilder.insertInstr(MIB);
  404. if (!Info.OrigRet.Ty->isVoidTy()) {
  405. if (!isSupportedType(DL, TLI, Info.OrigRet.Ty))
  406. return false;
  407. ArgInfos.clear();
  408. splitToValueTypes(Info.OrigRet, ArgInfos, DL, Info.CallConv);
  409. auto RetAssignFn = TLI.CCAssignFnForReturn(Info.CallConv, Info.IsVarArg);
  410. OutgoingValueAssigner Assigner(RetAssignFn);
  411. CallReturnHandler RetHandler(MIRBuilder, MRI, MIB);
  412. if (!determineAndHandleAssignments(RetHandler, Assigner, ArgInfos,
  413. MIRBuilder, Info.CallConv,
  414. Info.IsVarArg))
  415. return false;
  416. }
  417. // We now know the size of the stack - update the ADJCALLSTACKDOWN
  418. // accordingly.
  419. CallSeqStart.addImm(ArgAssigner.StackOffset)
  420. .addImm(0)
  421. .add(predOps(ARMCC::AL));
  422. MIRBuilder.buildInstr(ARM::ADJCALLSTACKUP)
  423. .addImm(ArgAssigner.StackOffset)
  424. .addImm(-1ULL)
  425. .add(predOps(ARMCC::AL));
  426. return true;
  427. }