2017-09-21 05:35:51 +08:00
|
|
|
//===- llvm/lib/Target/ARM/ARMCallLowering.cpp - Call lowering ------------===//
|
2016-11-11 16:27:37 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2016-11-11 16:27:37 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2017-09-21 05:35:51 +08:00
|
|
|
//
|
2016-11-11 16:27:37 +08:00
|
|
|
/// \file
|
|
|
|
/// This file implements the lowering of LLVM calls to machine code calls for
|
|
|
|
/// GlobalISel.
|
2017-09-21 05:35:51 +08:00
|
|
|
//
|
2016-11-11 16:27:37 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "ARMCallLowering.h"
|
|
|
|
#include "ARMBaseInstrInfo.h"
|
|
|
|
#include "ARMISelLowering.h"
|
2017-01-25 15:08:53 +08:00
|
|
|
#include "ARMSubtarget.h"
|
2017-09-21 05:35:51 +08:00
|
|
|
#include "Utils/ARMBaseInfo.h"
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2017-02-02 22:01:00 +08:00
|
|
|
#include "llvm/CodeGen/Analysis.h"
|
2017-09-21 05:35:51 +08:00
|
|
|
#include "llvm/CodeGen/CallingConvLower.h"
|
2016-11-11 16:27:37 +08:00
|
|
|
#include "llvm/CodeGen/GlobalISel/MachineIRBuilder.h"
|
2017-06-05 20:54:53 +08:00
|
|
|
#include "llvm/CodeGen/GlobalISel/Utils.h"
|
2017-09-21 05:35:51 +08:00
|
|
|
#include "llvm/CodeGen/LowLevelType.h"
|
|
|
|
#include "llvm/CodeGen/MachineBasicBlock.h"
|
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
|
|
|
#include "llvm/CodeGen/MachineMemOperand.h"
|
|
|
|
#include "llvm/CodeGen/MachineOperand.h"
|
2016-12-19 19:55:41 +08:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2017-11-17 09:07:10 +08:00
|
|
|
#include "llvm/CodeGen/TargetRegisterInfo.h"
|
|
|
|
#include "llvm/CodeGen/TargetSubtargetInfo.h"
|
2018-03-30 01:21:10 +08:00
|
|
|
#include "llvm/CodeGen/ValueTypes.h"
|
2017-09-21 05:35:51 +08:00
|
|
|
#include "llvm/IR/Attributes.h"
|
|
|
|
#include "llvm/IR/DataLayout.h"
|
|
|
|
#include "llvm/IR/DerivedTypes.h"
|
|
|
|
#include "llvm/IR/Function.h"
|
|
|
|
#include "llvm/IR/Type.h"
|
|
|
|
#include "llvm/IR/Value.h"
|
|
|
|
#include "llvm/Support/Casting.h"
|
|
|
|
#include "llvm/Support/LowLevelTypeImpl.h"
|
2018-03-24 07:58:25 +08:00
|
|
|
#include "llvm/Support/MachineValueType.h"
|
2017-09-21 05:35:51 +08:00
|
|
|
#include <algorithm>
|
|
|
|
#include <cassert>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <utility>
|
2016-11-11 16:27:37 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
ARMCallLowering::ARMCallLowering(const ARMTargetLowering &TLI)
|
|
|
|
: CallLowering(&TLI) {}
|
|
|
|
|
2017-01-13 22:39:03 +08:00
|
|
|
static bool isSupportedType(const DataLayout &DL, const ARMTargetLowering &TLI,
|
2016-12-16 20:54:46 +08:00
|
|
|
Type *T) {
|
2017-06-15 17:42:02 +08:00
|
|
|
if (T->isArrayTy())
|
2019-04-30 17:05:25 +08:00
|
|
|
return isSupportedType(DL, TLI, T->getArrayElementType());
|
2017-05-29 15:01:52 +08:00
|
|
|
|
2017-06-15 17:42:02 +08:00
|
|
|
if (T->isStructTy()) {
|
|
|
|
// For now we only allow homogeneous structs that we can manipulate with
|
|
|
|
// G_MERGE_VALUES and G_UNMERGE_VALUES
|
|
|
|
auto StructT = cast<StructType>(T);
|
|
|
|
for (unsigned i = 1, e = StructT->getNumElements(); i != e; ++i)
|
|
|
|
if (StructT->getElementType(i) != StructT->getElementType(0))
|
|
|
|
return false;
|
2019-04-30 17:05:25 +08:00
|
|
|
return isSupportedType(DL, TLI, StructT->getElementType(0));
|
2017-06-15 17:42:02 +08:00
|
|
|
}
|
|
|
|
|
2017-02-02 22:00:54 +08:00
|
|
|
EVT VT = TLI.getValueType(DL, T, true);
|
2017-04-21 19:53:01 +08:00
|
|
|
if (!VT.isSimple() || VT.isVector() ||
|
|
|
|
!(VT.isInteger() || VT.isFloatingPoint()))
|
2016-12-19 22:08:02 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
unsigned VTSize = VT.getSimpleVT().getSizeInBits();
|
2017-02-16 15:53:07 +08:00
|
|
|
|
|
|
|
if (VTSize == 64)
|
|
|
|
// FIXME: Support i64 too
|
|
|
|
return VT.isFloatingPoint();
|
|
|
|
|
2017-01-25 16:47:40 +08:00
|
|
|
return VTSize == 1 || VTSize == 8 || VTSize == 16 || VTSize == 32;
|
2016-12-16 20:54:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
2017-09-21 05:35:51 +08:00
|
|
|
|
2017-02-23 21:25:43 +08:00
|
|
|
/// Helper class for values going out through an ABI boundary (used for handling
|
|
|
|
/// function return values and call parameters).
|
|
|
|
struct OutgoingValueHandler : public CallLowering::ValueHandler {
|
|
|
|
OutgoingValueHandler(MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI,
|
|
|
|
MachineInstrBuilder &MIB, CCAssignFn *AssignFn)
|
2017-09-21 05:35:51 +08:00
|
|
|
: ValueHandler(MIRBuilder, MRI, AssignFn), MIB(MIB) {}
|
2016-12-16 20:54:46 +08:00
|
|
|
|
2019-06-25 00:16:12 +08:00
|
|
|
Register getStackAddress(uint64_t Size, int64_t Offset,
|
2016-12-16 20:54:46 +08:00
|
|
|
MachinePointerInfo &MPO) override {
|
2017-03-01 23:54:21 +08:00
|
|
|
assert((Size == 1 || Size == 2 || Size == 4 || Size == 8) &&
|
|
|
|
"Unsupported size");
|
2017-02-28 22:17:53 +08:00
|
|
|
|
|
|
|
LLT p0 = LLT::pointer(0, 32);
|
|
|
|
LLT s32 = LLT::scalar(32);
|
2019-06-25 00:16:12 +08:00
|
|
|
Register SPReg = MRI.createGenericVirtualRegister(p0);
|
|
|
|
MIRBuilder.buildCopy(SPReg, Register(ARM::SP));
|
2017-02-28 22:17:53 +08:00
|
|
|
|
2019-06-25 00:16:12 +08:00
|
|
|
Register OffsetReg = MRI.createGenericVirtualRegister(s32);
|
2017-02-28 22:17:53 +08:00
|
|
|
MIRBuilder.buildConstant(OffsetReg, Offset);
|
|
|
|
|
2019-06-25 00:16:12 +08:00
|
|
|
Register AddrReg = MRI.createGenericVirtualRegister(p0);
|
2017-02-28 22:17:53 +08:00
|
|
|
MIRBuilder.buildGEP(AddrReg, SPReg, OffsetReg);
|
|
|
|
|
|
|
|
MPO = MachinePointerInfo::getStack(MIRBuilder.getMF(), Offset);
|
|
|
|
return AddrReg;
|
2016-12-16 20:54:46 +08:00
|
|
|
}
|
|
|
|
|
2019-06-25 00:16:12 +08:00
|
|
|
void assignValueToReg(Register ValVReg, Register PhysReg,
|
2016-12-16 20:54:46 +08:00
|
|
|
CCValAssign &VA) override {
|
|
|
|
assert(VA.isRegLoc() && "Value shouldn't be assigned to reg");
|
|
|
|
assert(VA.getLocReg() == PhysReg && "Assigning to the wrong reg?");
|
|
|
|
|
2017-02-16 15:53:07 +08:00
|
|
|
assert(VA.getValVT().getSizeInBits() <= 64 && "Unsupported value size");
|
|
|
|
assert(VA.getLocVT().getSizeInBits() <= 64 && "Unsupported location size");
|
2016-12-16 20:54:46 +08:00
|
|
|
|
2019-06-25 00:16:12 +08:00
|
|
|
Register ExtReg = extendRegister(ValVReg, VA);
|
2017-01-25 16:10:40 +08:00
|
|
|
MIRBuilder.buildCopy(PhysReg, ExtReg);
|
2016-12-16 20:54:46 +08:00
|
|
|
MIB.addUse(PhysReg, RegState::Implicit);
|
|
|
|
}
|
|
|
|
|
2019-06-25 00:16:12 +08:00
|
|
|
void assignValueToAddress(Register ValVReg, Register Addr, uint64_t Size,
|
2016-12-16 20:54:46 +08:00
|
|
|
MachinePointerInfo &MPO, CCValAssign &VA) override {
|
[ARM] GlobalISel: Lower call params that need extensions
Lower i1, i8 and i16 call parameters by extending them before storing them on
the stack. Also make sure we encode the correct, extended size in the
corresponding memory operand, and that we compute the correct stack size in the
end.
The latter is a bit more complicated because we used to compute the stack size
in the getStackAddress method, based on the Size and Offset of the parameters.
However, if the last parameter is sign extended, we'd be using the wrong,
non-extended size, and we'd end up with a smaller stack than we need to hold the
extended value. Instead of hacking this up based on the value of Size in
getStackAddress, we move our stack size handling logic to assignArg, where we
have access to the CCState which knows everything we could possibly want to know
about the stack. This way we don't need to duplicate any knowledge or resort to
any ugly hacks.
On this same occasion, update the IRTranslator test to check the sizes of the
stores everywhere, not just for sign extended paramteres.
llvm-svn: 296631
2017-03-01 23:35:14 +08:00
|
|
|
assert((Size == 1 || Size == 2 || Size == 4 || Size == 8) &&
|
|
|
|
"Unsupported size");
|
2017-02-28 22:17:53 +08:00
|
|
|
|
2019-06-25 00:16:12 +08:00
|
|
|
Register ExtReg = extendRegister(ValVReg, VA);
|
2017-02-28 22:17:53 +08:00
|
|
|
auto MMO = MIRBuilder.getMF().getMachineMemOperand(
|
[ARM] GlobalISel: Lower call params that need extensions
Lower i1, i8 and i16 call parameters by extending them before storing them on
the stack. Also make sure we encode the correct, extended size in the
corresponding memory operand, and that we compute the correct stack size in the
end.
The latter is a bit more complicated because we used to compute the stack size
in the getStackAddress method, based on the Size and Offset of the parameters.
However, if the last parameter is sign extended, we'd be using the wrong,
non-extended size, and we'd end up with a smaller stack than we need to hold the
extended value. Instead of hacking this up based on the value of Size in
getStackAddress, we move our stack size handling logic to assignArg, where we
have access to the CCState which knows everything we could possibly want to know
about the stack. This way we don't need to duplicate any knowledge or resort to
any ugly hacks.
On this same occasion, update the IRTranslator test to check the sizes of the
stores everywhere, not just for sign extended paramteres.
llvm-svn: 296631
2017-03-01 23:35:14 +08:00
|
|
|
MPO, MachineMemOperand::MOStore, VA.getLocVT().getStoreSize(),
|
2019-01-31 09:38:47 +08:00
|
|
|
/* Alignment */ 1);
|
[ARM] GlobalISel: Lower call params that need extensions
Lower i1, i8 and i16 call parameters by extending them before storing them on
the stack. Also make sure we encode the correct, extended size in the
corresponding memory operand, and that we compute the correct stack size in the
end.
The latter is a bit more complicated because we used to compute the stack size
in the getStackAddress method, based on the Size and Offset of the parameters.
However, if the last parameter is sign extended, we'd be using the wrong,
non-extended size, and we'd end up with a smaller stack than we need to hold the
extended value. Instead of hacking this up based on the value of Size in
getStackAddress, we move our stack size handling logic to assignArg, where we
have access to the CCState which knows everything we could possibly want to know
about the stack. This way we don't need to duplicate any knowledge or resort to
any ugly hacks.
On this same occasion, update the IRTranslator test to check the sizes of the
stores everywhere, not just for sign extended paramteres.
llvm-svn: 296631
2017-03-01 23:35:14 +08:00
|
|
|
MIRBuilder.buildStore(ExtReg, Addr, *MMO);
|
2016-12-16 20:54:46 +08:00
|
|
|
}
|
|
|
|
|
2017-02-16 15:53:07 +08:00
|
|
|
unsigned assignCustomValue(const CallLowering::ArgInfo &Arg,
|
|
|
|
ArrayRef<CCValAssign> VAs) override {
|
2019-06-27 16:50:53 +08:00
|
|
|
assert(Arg.Regs.size() == 1 && "Can't handle multple regs yet");
|
|
|
|
|
2017-02-16 15:53:07 +08:00
|
|
|
CCValAssign VA = VAs[0];
|
|
|
|
assert(VA.needsCustom() && "Value doesn't need custom handling");
|
|
|
|
assert(VA.getValVT() == MVT::f64 && "Unsupported type");
|
|
|
|
|
|
|
|
CCValAssign NextVA = VAs[1];
|
|
|
|
assert(NextVA.needsCustom() && "Value doesn't need custom handling");
|
|
|
|
assert(NextVA.getValVT() == MVT::f64 && "Unsupported type");
|
|
|
|
|
|
|
|
assert(VA.getValNo() == NextVA.getValNo() &&
|
|
|
|
"Values belong to different arguments");
|
|
|
|
|
|
|
|
assert(VA.isRegLoc() && "Value should be in reg");
|
|
|
|
assert(NextVA.isRegLoc() && "Value should be in reg");
|
|
|
|
|
2019-06-24 23:50:29 +08:00
|
|
|
Register NewRegs[] = {MRI.createGenericVirtualRegister(LLT::scalar(32)),
|
2017-02-16 15:53:07 +08:00
|
|
|
MRI.createGenericVirtualRegister(LLT::scalar(32))};
|
2019-06-27 16:50:53 +08:00
|
|
|
MIRBuilder.buildUnmerge(NewRegs, Arg.Regs[0]);
|
2017-02-16 15:53:07 +08:00
|
|
|
|
|
|
|
bool IsLittle = MIRBuilder.getMF().getSubtarget<ARMSubtarget>().isLittle();
|
|
|
|
if (!IsLittle)
|
|
|
|
std::swap(NewRegs[0], NewRegs[1]);
|
|
|
|
|
|
|
|
assignValueToReg(NewRegs[0], VA.getLocReg(), VA);
|
|
|
|
assignValueToReg(NewRegs[1], NextVA.getLocReg(), NextVA);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
[ARM] GlobalISel: Lower call params that need extensions
Lower i1, i8 and i16 call parameters by extending them before storing them on
the stack. Also make sure we encode the correct, extended size in the
corresponding memory operand, and that we compute the correct stack size in the
end.
The latter is a bit more complicated because we used to compute the stack size
in the getStackAddress method, based on the Size and Offset of the parameters.
However, if the last parameter is sign extended, we'd be using the wrong,
non-extended size, and we'd end up with a smaller stack than we need to hold the
extended value. Instead of hacking this up based on the value of Size in
getStackAddress, we move our stack size handling logic to assignArg, where we
have access to the CCState which knows everything we could possibly want to know
about the stack. This way we don't need to duplicate any knowledge or resort to
any ugly hacks.
On this same occasion, update the IRTranslator test to check the sizes of the
stores everywhere, not just for sign extended paramteres.
llvm-svn: 296631
2017-03-01 23:35:14 +08:00
|
|
|
bool assignArg(unsigned ValNo, MVT ValVT, MVT LocVT,
|
2017-03-01 23:54:21 +08:00
|
|
|
CCValAssign::LocInfo LocInfo,
|
|
|
|
const CallLowering::ArgInfo &Info, CCState &State) override {
|
[ARM] GlobalISel: Lower call params that need extensions
Lower i1, i8 and i16 call parameters by extending them before storing them on
the stack. Also make sure we encode the correct, extended size in the
corresponding memory operand, and that we compute the correct stack size in the
end.
The latter is a bit more complicated because we used to compute the stack size
in the getStackAddress method, based on the Size and Offset of the parameters.
However, if the last parameter is sign extended, we'd be using the wrong,
non-extended size, and we'd end up with a smaller stack than we need to hold the
extended value. Instead of hacking this up based on the value of Size in
getStackAddress, we move our stack size handling logic to assignArg, where we
have access to the CCState which knows everything we could possibly want to know
about the stack. This way we don't need to duplicate any knowledge or resort to
any ugly hacks.
On this same occasion, update the IRTranslator test to check the sizes of the
stores everywhere, not just for sign extended paramteres.
llvm-svn: 296631
2017-03-01 23:35:14 +08:00
|
|
|
if (AssignFn(ValNo, ValVT, LocVT, LocInfo, Info.Flags, State))
|
|
|
|
return true;
|
|
|
|
|
2017-03-01 23:54:21 +08:00
|
|
|
StackSize =
|
|
|
|
std::max(StackSize, static_cast<uint64_t>(State.getNextStackOffset()));
|
[ARM] GlobalISel: Lower call params that need extensions
Lower i1, i8 and i16 call parameters by extending them before storing them on
the stack. Also make sure we encode the correct, extended size in the
corresponding memory operand, and that we compute the correct stack size in the
end.
The latter is a bit more complicated because we used to compute the stack size
in the getStackAddress method, based on the Size and Offset of the parameters.
However, if the last parameter is sign extended, we'd be using the wrong,
non-extended size, and we'd end up with a smaller stack than we need to hold the
extended value. Instead of hacking this up based on the value of Size in
getStackAddress, we move our stack size handling logic to assignArg, where we
have access to the CCState which knows everything we could possibly want to know
about the stack. This way we don't need to duplicate any knowledge or resort to
any ugly hacks.
On this same occasion, update the IRTranslator test to check the sizes of the
stores everywhere, not just for sign extended paramteres.
llvm-svn: 296631
2017-03-01 23:35:14 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-12-16 20:54:46 +08:00
|
|
|
MachineInstrBuilder &MIB;
|
2017-09-21 05:35:51 +08:00
|
|
|
uint64_t StackSize = 0;
|
2016-12-16 20:54:46 +08:00
|
|
|
};
|
2017-09-21 05:35:51 +08:00
|
|
|
|
|
|
|
} // end anonymous namespace
|
2016-12-16 20:54:46 +08:00
|
|
|
|
2017-05-29 15:01:52 +08:00
|
|
|
void ARMCallLowering::splitToValueTypes(
|
|
|
|
const ArgInfo &OrigArg, SmallVectorImpl<ArgInfo> &SplitArgs,
|
|
|
|
MachineFunction &MF, const SplitArgTy &PerformArgSplit) const {
|
2017-02-02 22:01:00 +08:00
|
|
|
const ARMTargetLowering &TLI = *getTLI<ARMTargetLowering>();
|
|
|
|
LLVMContext &Ctx = OrigArg.Ty->getContext();
|
2017-05-29 15:01:52 +08:00
|
|
|
const DataLayout &DL = MF.getDataLayout();
|
|
|
|
MachineRegisterInfo &MRI = MF.getRegInfo();
|
2017-12-16 06:22:58 +08:00
|
|
|
const Function &F = MF.getFunction();
|
2017-02-02 22:01:00 +08:00
|
|
|
|
|
|
|
SmallVector<EVT, 4> SplitVTs;
|
2019-05-27 18:30:33 +08:00
|
|
|
ComputeValueVTs(TLI, DL, OrigArg.Ty, SplitVTs, nullptr, nullptr, 0);
|
2017-02-02 22:01:00 +08:00
|
|
|
|
2017-05-29 15:01:52 +08:00
|
|
|
if (SplitVTs.size() == 1) {
|
|
|
|
// Even if there is no splitting to do, we still want to replace the
|
|
|
|
// original type (e.g. pointer type -> integer).
|
2019-06-27 16:54:17 +08:00
|
|
|
assert(OrigArg.Regs.size() == 1 && "Regs / types mismatch");
|
2017-06-02 18:16:48 +08:00
|
|
|
auto Flags = OrigArg.Flags;
|
|
|
|
unsigned OriginalAlignment = DL.getABITypeAlignment(OrigArg.Ty);
|
|
|
|
Flags.setOrigAlign(OriginalAlignment);
|
2019-06-27 16:50:53 +08:00
|
|
|
SplitArgs.emplace_back(OrigArg.Regs[0], SplitVTs[0].getTypeForEVT(Ctx),
|
|
|
|
Flags, OrigArg.IsFixed);
|
2017-05-29 15:01:52 +08:00
|
|
|
return;
|
|
|
|
}
|
2017-02-02 22:01:00 +08:00
|
|
|
|
2019-06-27 16:54:17 +08:00
|
|
|
if (OrigArg.Regs.size() > 1) {
|
|
|
|
// Create one ArgInfo for each virtual register.
|
|
|
|
assert(OrigArg.Regs.size() == SplitVTs.size() && "Regs / types mismatch");
|
|
|
|
for (unsigned i = 0, e = SplitVTs.size(); i != e; ++i) {
|
|
|
|
EVT SplitVT = SplitVTs[i];
|
|
|
|
Type *SplitTy = SplitVT.getTypeForEVT(Ctx);
|
|
|
|
auto Flags = OrigArg.Flags;
|
|
|
|
|
|
|
|
unsigned OriginalAlignment = DL.getABITypeAlignment(SplitTy);
|
|
|
|
Flags.setOrigAlign(OriginalAlignment);
|
|
|
|
|
|
|
|
bool NeedsConsecutiveRegisters =
|
|
|
|
TLI.functionArgumentNeedsConsecutiveRegisters(
|
|
|
|
SplitTy, F.getCallingConv(), F.isVarArg());
|
|
|
|
if (NeedsConsecutiveRegisters) {
|
|
|
|
Flags.setInConsecutiveRegs();
|
|
|
|
if (i == e - 1)
|
|
|
|
Flags.setInConsecutiveRegsLast();
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: We also want to split SplitTy further.
|
|
|
|
Register PartReg = OrigArg.Regs[i];
|
|
|
|
SplitArgs.emplace_back(PartReg, SplitTy, Flags, OrigArg.IsFixed);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-29 15:01:52 +08:00
|
|
|
for (unsigned i = 0, e = SplitVTs.size(); i != e; ++i) {
|
|
|
|
EVT SplitVT = SplitVTs[i];
|
|
|
|
Type *SplitTy = SplitVT.getTypeForEVT(Ctx);
|
|
|
|
auto Flags = OrigArg.Flags;
|
2017-06-02 18:16:48 +08:00
|
|
|
|
|
|
|
unsigned OriginalAlignment = DL.getABITypeAlignment(SplitTy);
|
|
|
|
Flags.setOrigAlign(OriginalAlignment);
|
|
|
|
|
2017-05-29 15:01:52 +08:00
|
|
|
bool NeedsConsecutiveRegisters =
|
|
|
|
TLI.functionArgumentNeedsConsecutiveRegisters(
|
2017-12-16 06:22:58 +08:00
|
|
|
SplitTy, F.getCallingConv(), F.isVarArg());
|
2017-05-29 15:01:52 +08:00
|
|
|
if (NeedsConsecutiveRegisters) {
|
|
|
|
Flags.setInConsecutiveRegs();
|
|
|
|
if (i == e - 1)
|
|
|
|
Flags.setInConsecutiveRegsLast();
|
|
|
|
}
|
2017-06-02 18:16:48 +08:00
|
|
|
|
2019-06-27 16:50:53 +08:00
|
|
|
Register PartReg =
|
2019-05-27 18:30:33 +08:00
|
|
|
MRI.createGenericVirtualRegister(getLLTForType(*SplitTy, DL));
|
|
|
|
SplitArgs.push_back(ArgInfo{PartReg, SplitTy, Flags, OrigArg.IsFixed});
|
|
|
|
PerformArgSplit(PartReg);
|
2017-05-29 15:01:52 +08:00
|
|
|
}
|
2017-02-02 22:01:00 +08:00
|
|
|
}
|
|
|
|
|
2016-12-16 20:54:46 +08:00
|
|
|
/// Lower the return value for the already existing \p Ret. This assumes that
|
|
|
|
/// \p MIRBuilder's insertion point is correct.
|
|
|
|
bool ARMCallLowering::lowerReturnVal(MachineIRBuilder &MIRBuilder,
|
2019-06-24 23:50:29 +08:00
|
|
|
const Value *Val, ArrayRef<Register> VRegs,
|
2016-12-16 20:54:46 +08:00
|
|
|
MachineInstrBuilder &Ret) const {
|
|
|
|
if (!Val)
|
|
|
|
// Nothing to do here.
|
|
|
|
return true;
|
|
|
|
|
|
|
|
auto &MF = MIRBuilder.getMF();
|
2017-12-16 06:22:58 +08:00
|
|
|
const auto &F = MF.getFunction();
|
2016-12-16 20:54:46 +08:00
|
|
|
|
|
|
|
auto DL = MF.getDataLayout();
|
|
|
|
auto &TLI = *getTLI<ARMTargetLowering>();
|
|
|
|
if (!isSupportedType(DL, TLI, Val->getType()))
|
|
|
|
return false;
|
|
|
|
|
2018-08-02 16:33:31 +08:00
|
|
|
SmallVector<EVT, 4> SplitEVTs;
|
|
|
|
ComputeValueVTs(TLI, DL, Val->getType(), SplitEVTs);
|
|
|
|
assert(VRegs.size() == SplitEVTs.size() &&
|
|
|
|
"For each split Type there should be exactly one VReg.");
|
2017-02-02 22:01:00 +08:00
|
|
|
|
2018-08-02 16:33:31 +08:00
|
|
|
SmallVector<ArgInfo, 4> SplitVTs;
|
|
|
|
LLVMContext &Ctx = Val->getType()->getContext();
|
|
|
|
for (unsigned i = 0; i < SplitEVTs.size(); ++i) {
|
|
|
|
ArgInfo CurArgInfo(VRegs[i], SplitEVTs[i].getTypeForEVT(Ctx));
|
|
|
|
setArgFlags(CurArgInfo, AttributeList::ReturnIndex, DL, F);
|
|
|
|
|
2019-06-24 23:50:29 +08:00
|
|
|
SmallVector<Register, 4> Regs;
|
2019-05-27 18:30:33 +08:00
|
|
|
splitToValueTypes(CurArgInfo, SplitVTs, MF,
|
2019-06-24 23:50:29 +08:00
|
|
|
[&](Register Reg) { Regs.push_back(Reg); });
|
2018-08-02 16:33:31 +08:00
|
|
|
if (Regs.size() > 1)
|
|
|
|
MIRBuilder.buildUnmerge(Regs, VRegs[i]);
|
|
|
|
}
|
2017-06-15 17:42:02 +08:00
|
|
|
|
2017-02-02 22:01:00 +08:00
|
|
|
CCAssignFn *AssignFn =
|
|
|
|
TLI.CCAssignFnForReturn(F.getCallingConv(), F.isVarArg());
|
2016-12-16 20:54:46 +08:00
|
|
|
|
2017-02-23 21:25:43 +08:00
|
|
|
OutgoingValueHandler RetHandler(MIRBuilder, MF.getRegInfo(), Ret, AssignFn);
|
2017-02-02 22:01:00 +08:00
|
|
|
return handleAssignments(MIRBuilder, SplitVTs, RetHandler);
|
2016-12-16 20:54:46 +08:00
|
|
|
}
|
|
|
|
|
2016-11-11 16:27:37 +08:00
|
|
|
bool ARMCallLowering::lowerReturn(MachineIRBuilder &MIRBuilder,
|
2018-08-02 16:33:31 +08:00
|
|
|
const Value *Val,
|
2019-06-24 23:50:29 +08:00
|
|
|
ArrayRef<Register> VRegs) const {
|
2018-08-02 16:33:31 +08:00
|
|
|
assert(!Val == VRegs.empty() && "Return value without a vreg");
|
2016-11-11 16:27:37 +08:00
|
|
|
|
2017-08-29 04:20:47 +08:00
|
|
|
auto const &ST = MIRBuilder.getMF().getSubtarget<ARMSubtarget>();
|
|
|
|
unsigned Opcode = ST.getReturnOpcode();
|
|
|
|
auto Ret = MIRBuilder.buildInstrNoInsert(Opcode).add(predOps(ARMCC::AL));
|
2016-11-11 16:27:37 +08:00
|
|
|
|
2018-08-02 16:33:31 +08:00
|
|
|
if (!lowerReturnVal(MIRBuilder, Val, VRegs, Ret))
|
2016-12-16 20:54:46 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
MIRBuilder.insertInstr(Ret);
|
2016-11-11 16:27:37 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-12-16 20:54:46 +08:00
|
|
|
namespace {
|
2017-09-21 05:35:51 +08:00
|
|
|
|
2017-02-23 22:18:41 +08:00
|
|
|
/// Helper class for values coming in through an ABI boundary (used for handling
|
|
|
|
/// formal arguments and call return values).
|
|
|
|
struct IncomingValueHandler : public CallLowering::ValueHandler {
|
|
|
|
IncomingValueHandler(MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI,
|
|
|
|
CCAssignFn AssignFn)
|
2017-01-18 06:30:10 +08:00
|
|
|
: ValueHandler(MIRBuilder, MRI, AssignFn) {}
|
2016-12-16 20:54:46 +08:00
|
|
|
|
2019-04-10 05:22:33 +08:00
|
|
|
bool isArgumentHandler() const override { return true; }
|
|
|
|
|
2019-06-25 00:16:12 +08:00
|
|
|
Register getStackAddress(uint64_t Size, int64_t Offset,
|
2016-12-16 20:54:46 +08:00
|
|
|
MachinePointerInfo &MPO) override {
|
2017-02-16 15:53:07 +08:00
|
|
|
assert((Size == 1 || Size == 2 || Size == 4 || Size == 8) &&
|
|
|
|
"Unsupported size");
|
2016-12-19 19:55:41 +08:00
|
|
|
|
|
|
|
auto &MFI = MIRBuilder.getMF().getFrameInfo();
|
|
|
|
|
|
|
|
int FI = MFI.CreateFixedObject(Size, Offset, true);
|
|
|
|
MPO = MachinePointerInfo::getFixedStack(MIRBuilder.getMF(), FI);
|
|
|
|
|
|
|
|
unsigned AddrReg =
|
|
|
|
MRI.createGenericVirtualRegister(LLT::pointer(MPO.getAddrSpace(), 32));
|
|
|
|
MIRBuilder.buildFrameIndex(AddrReg, FI);
|
|
|
|
|
|
|
|
return AddrReg;
|
|
|
|
}
|
|
|
|
|
2019-06-25 00:16:12 +08:00
|
|
|
void assignValueToAddress(Register ValVReg, Register Addr, uint64_t Size,
|
2016-12-19 19:55:41 +08:00
|
|
|
MachinePointerInfo &MPO, CCValAssign &VA) override {
|
2017-02-16 15:53:07 +08:00
|
|
|
assert((Size == 1 || Size == 2 || Size == 4 || Size == 8) &&
|
|
|
|
"Unsupported size");
|
2017-01-26 17:20:47 +08:00
|
|
|
|
|
|
|
if (VA.getLocInfo() == CCValAssign::SExt ||
|
|
|
|
VA.getLocInfo() == CCValAssign::ZExt) {
|
2017-02-23 22:18:41 +08:00
|
|
|
// If the value is zero- or sign-extended, its size becomes 4 bytes, so
|
|
|
|
// that's what we should load.
|
2017-01-26 17:20:47 +08:00
|
|
|
Size = 4;
|
|
|
|
assert(MRI.getType(ValVReg).isScalar() && "Only scalars supported atm");
|
2017-04-27 18:23:30 +08:00
|
|
|
|
|
|
|
auto LoadVReg = MRI.createGenericVirtualRegister(LLT::scalar(32));
|
2019-01-31 09:38:47 +08:00
|
|
|
buildLoad(LoadVReg, Addr, Size, /* Alignment */ 1, MPO);
|
2017-04-27 18:23:30 +08:00
|
|
|
MIRBuilder.buildTrunc(ValVReg, LoadVReg);
|
|
|
|
} else {
|
|
|
|
// If the value is not extended, a simple load will suffice.
|
2019-01-31 09:38:47 +08:00
|
|
|
buildLoad(ValVReg, Addr, Size, /* Alignment */ 1, MPO);
|
2017-01-26 17:20:47 +08:00
|
|
|
}
|
2017-04-27 18:23:30 +08:00
|
|
|
}
|
2016-12-19 19:55:41 +08:00
|
|
|
|
2019-06-25 00:16:12 +08:00
|
|
|
void buildLoad(Register Val, Register Addr, uint64_t Size, unsigned Alignment,
|
2017-04-27 18:23:30 +08:00
|
|
|
MachinePointerInfo &MPO) {
|
2016-12-19 19:55:41 +08:00
|
|
|
auto MMO = MIRBuilder.getMF().getMachineMemOperand(
|
2017-04-27 18:23:30 +08:00
|
|
|
MPO, MachineMemOperand::MOLoad, Size, Alignment);
|
|
|
|
MIRBuilder.buildLoad(Val, Addr, *MMO);
|
2016-12-16 20:54:46 +08:00
|
|
|
}
|
|
|
|
|
2019-06-25 00:16:12 +08:00
|
|
|
void assignValueToReg(Register ValVReg, Register PhysReg,
|
2016-12-16 20:54:46 +08:00
|
|
|
CCValAssign &VA) override {
|
|
|
|
assert(VA.isRegLoc() && "Value shouldn't be assigned to reg");
|
|
|
|
assert(VA.getLocReg() == PhysReg && "Assigning to the wrong reg?");
|
|
|
|
|
2017-10-10 04:07:43 +08:00
|
|
|
auto ValSize = VA.getValVT().getSizeInBits();
|
|
|
|
auto LocSize = VA.getLocVT().getSizeInBits();
|
|
|
|
|
|
|
|
assert(ValSize <= 64 && "Unsupported value size");
|
|
|
|
assert(LocSize <= 64 && "Unsupported location size");
|
2016-12-16 20:54:46 +08:00
|
|
|
|
2017-02-23 22:18:41 +08:00
|
|
|
markPhysRegUsed(PhysReg);
|
2017-10-10 04:07:43 +08:00
|
|
|
if (ValSize == LocSize) {
|
|
|
|
MIRBuilder.buildCopy(ValVReg, PhysReg);
|
|
|
|
} else {
|
|
|
|
assert(ValSize < LocSize && "Extensions not supported");
|
|
|
|
|
|
|
|
// We cannot create a truncating copy, nor a trunc of a physical register.
|
|
|
|
// Therefore, we need to copy the content of the physical register into a
|
|
|
|
// virtual one and then truncate that.
|
|
|
|
auto PhysRegToVReg =
|
|
|
|
MRI.createGenericVirtualRegister(LLT::scalar(LocSize));
|
|
|
|
MIRBuilder.buildCopy(PhysRegToVReg, PhysReg);
|
|
|
|
MIRBuilder.buildTrunc(ValVReg, PhysRegToVReg);
|
|
|
|
}
|
2016-12-16 20:54:46 +08:00
|
|
|
}
|
2017-02-16 15:53:07 +08:00
|
|
|
|
2017-02-23 21:25:43 +08:00
|
|
|
unsigned assignCustomValue(const ARMCallLowering::ArgInfo &Arg,
|
2017-02-16 15:53:07 +08:00
|
|
|
ArrayRef<CCValAssign> VAs) override {
|
2019-06-27 16:50:53 +08:00
|
|
|
assert(Arg.Regs.size() == 1 && "Can't handle multple regs yet");
|
|
|
|
|
2017-02-16 15:53:07 +08:00
|
|
|
CCValAssign VA = VAs[0];
|
|
|
|
assert(VA.needsCustom() && "Value doesn't need custom handling");
|
|
|
|
assert(VA.getValVT() == MVT::f64 && "Unsupported type");
|
|
|
|
|
|
|
|
CCValAssign NextVA = VAs[1];
|
|
|
|
assert(NextVA.needsCustom() && "Value doesn't need custom handling");
|
|
|
|
assert(NextVA.getValVT() == MVT::f64 && "Unsupported type");
|
|
|
|
|
|
|
|
assert(VA.getValNo() == NextVA.getValNo() &&
|
|
|
|
"Values belong to different arguments");
|
|
|
|
|
|
|
|
assert(VA.isRegLoc() && "Value should be in reg");
|
|
|
|
assert(NextVA.isRegLoc() && "Value should be in reg");
|
|
|
|
|
2019-06-24 23:50:29 +08:00
|
|
|
Register NewRegs[] = {MRI.createGenericVirtualRegister(LLT::scalar(32)),
|
2017-02-16 15:53:07 +08:00
|
|
|
MRI.createGenericVirtualRegister(LLT::scalar(32))};
|
|
|
|
|
|
|
|
assignValueToReg(NewRegs[0], VA.getLocReg(), VA);
|
|
|
|
assignValueToReg(NewRegs[1], NextVA.getLocReg(), NextVA);
|
|
|
|
|
|
|
|
bool IsLittle = MIRBuilder.getMF().getSubtarget<ARMSubtarget>().isLittle();
|
|
|
|
if (!IsLittle)
|
|
|
|
std::swap(NewRegs[0], NewRegs[1]);
|
|
|
|
|
2019-06-27 16:50:53 +08:00
|
|
|
MIRBuilder.buildMerge(Arg.Regs[0], NewRegs);
|
2017-02-16 15:53:07 +08:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
2017-02-23 22:18:41 +08:00
|
|
|
|
|
|
|
/// Marking a physical register as used is different between formal
|
|
|
|
/// parameters, where it's a basic block live-in, and call returns, where it's
|
|
|
|
/// an implicit-def of the call instruction.
|
|
|
|
virtual void markPhysRegUsed(unsigned PhysReg) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct FormalArgHandler : public IncomingValueHandler {
|
|
|
|
FormalArgHandler(MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI,
|
|
|
|
CCAssignFn AssignFn)
|
|
|
|
: IncomingValueHandler(MIRBuilder, MRI, AssignFn) {}
|
|
|
|
|
|
|
|
void markPhysRegUsed(unsigned PhysReg) override {
|
|
|
|
MIRBuilder.getMBB().addLiveIn(PhysReg);
|
|
|
|
}
|
2016-12-16 20:54:46 +08:00
|
|
|
};
|
2017-09-21 05:35:51 +08:00
|
|
|
|
|
|
|
} // end anonymous namespace
|
2016-12-16 20:54:46 +08:00
|
|
|
|
2019-06-27 16:54:17 +08:00
|
|
|
bool ARMCallLowering::lowerFormalArguments(
|
|
|
|
MachineIRBuilder &MIRBuilder, const Function &F,
|
|
|
|
ArrayRef<ArrayRef<Register>> VRegs) const {
|
2017-11-03 18:30:12 +08:00
|
|
|
auto &TLI = *getTLI<ARMTargetLowering>();
|
|
|
|
auto Subtarget = TLI.getSubtarget();
|
|
|
|
|
2018-12-05 18:35:28 +08:00
|
|
|
if (Subtarget->isThumb1Only())
|
2017-11-03 18:30:12 +08:00
|
|
|
return false;
|
|
|
|
|
2016-12-16 20:54:46 +08:00
|
|
|
// Quick exit if there aren't any args
|
|
|
|
if (F.arg_empty())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (F.isVarArg())
|
|
|
|
return false;
|
|
|
|
|
2017-02-02 22:01:00 +08:00
|
|
|
auto &MF = MIRBuilder.getMF();
|
2017-05-29 15:01:52 +08:00
|
|
|
auto &MBB = MIRBuilder.getMBB();
|
2017-02-02 22:01:00 +08:00
|
|
|
auto DL = MF.getDataLayout();
|
2017-02-09 21:09:59 +08:00
|
|
|
|
2017-11-30 20:23:44 +08:00
|
|
|
for (auto &Arg : F.args()) {
|
2016-12-16 20:54:46 +08:00
|
|
|
if (!isSupportedType(DL, TLI, Arg.getType()))
|
|
|
|
return false;
|
2017-11-30 20:23:44 +08:00
|
|
|
if (Arg.hasByValOrInAllocaAttr())
|
|
|
|
return false;
|
|
|
|
}
|
2016-12-16 20:54:46 +08:00
|
|
|
|
|
|
|
CCAssignFn *AssignFn =
|
|
|
|
TLI.CCAssignFnForCall(F.getCallingConv(), F.isVarArg());
|
|
|
|
|
2017-05-29 17:09:54 +08:00
|
|
|
FormalArgHandler ArgHandler(MIRBuilder, MIRBuilder.getMF().getRegInfo(),
|
|
|
|
AssignFn);
|
|
|
|
|
2019-06-27 16:54:17 +08:00
|
|
|
SmallVector<ArgInfo, 8> SplitArgInfos;
|
2016-12-16 20:54:46 +08:00
|
|
|
unsigned Idx = 0;
|
Remove getArgumentList() in favor of arg_begin(), args(), etc
Users often call getArgumentList().size(), which is a linear way to get
the number of function arguments. arg_size(), on the other hand, is
constant time.
In general, the fact that arguments are stored in an iplist is an
implementation detail, so I've removed it from the Function interface
and moved all other users to the argument container APIs (arg_begin(),
arg_end(), args(), arg_size()).
Reviewed By: chandlerc
Differential Revision: https://reviews.llvm.org/D31052
llvm-svn: 298010
2017-03-17 06:59:15 +08:00
|
|
|
for (auto &Arg : F.args()) {
|
2019-06-27 16:54:17 +08:00
|
|
|
ArgInfo OrigArgInfo(VRegs[Idx], Arg.getType());
|
|
|
|
setArgFlags(OrigArgInfo, Idx + AttributeList::FirstArgIndex, DL, F);
|
2017-05-29 17:09:54 +08:00
|
|
|
|
2019-06-27 16:54:17 +08:00
|
|
|
splitToValueTypes(OrigArgInfo, SplitArgInfos, MF, [&](Register Reg) {
|
|
|
|
llvm_unreachable("Args should already be split");
|
|
|
|
});
|
2017-05-29 15:01:52 +08:00
|
|
|
|
2016-12-16 20:54:46 +08:00
|
|
|
Idx++;
|
|
|
|
}
|
|
|
|
|
2017-05-29 15:01:52 +08:00
|
|
|
if (!MBB.empty())
|
|
|
|
MIRBuilder.setInstr(*MBB.begin());
|
|
|
|
|
2019-06-27 16:54:17 +08:00
|
|
|
if (!handleAssignments(MIRBuilder, SplitArgInfos, ArgHandler))
|
2018-05-16 18:32:02 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// Move back to the end of the basic block.
|
|
|
|
MIRBuilder.setMBB(MBB);
|
|
|
|
return true;
|
2016-11-11 16:27:37 +08:00
|
|
|
}
|
2017-02-21 19:33:59 +08:00
|
|
|
|
2017-02-23 22:18:41 +08:00
|
|
|
namespace {
|
2017-09-21 05:35:51 +08:00
|
|
|
|
2017-02-23 22:18:41 +08:00
|
|
|
struct CallReturnHandler : public IncomingValueHandler {
|
|
|
|
CallReturnHandler(MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI,
|
|
|
|
MachineInstrBuilder MIB, CCAssignFn *AssignFn)
|
|
|
|
: IncomingValueHandler(MIRBuilder, MRI, AssignFn), MIB(MIB) {}
|
|
|
|
|
|
|
|
void markPhysRegUsed(unsigned PhysReg) override {
|
|
|
|
MIB.addDef(PhysReg, RegState::Implicit);
|
|
|
|
}
|
|
|
|
|
|
|
|
MachineInstrBuilder MIB;
|
|
|
|
};
|
2017-09-21 05:35:51 +08:00
|
|
|
|
2018-12-05 18:35:28 +08:00
|
|
|
// FIXME: This should move to the ARMSubtarget when it supports all the opcodes.
|
|
|
|
unsigned getCallOpcode(const ARMSubtarget &STI, bool isDirect) {
|
|
|
|
if (isDirect)
|
|
|
|
return STI.isThumb() ? ARM::tBL : ARM::BL;
|
|
|
|
|
|
|
|
if (STI.isThumb())
|
|
|
|
return ARM::tBLXr;
|
|
|
|
|
|
|
|
if (STI.hasV5TOps())
|
|
|
|
return ARM::BLX;
|
|
|
|
|
|
|
|
if (STI.hasV4TOps())
|
|
|
|
return ARM::BX_CALL;
|
|
|
|
|
|
|
|
return ARM::BMOVPCRX_CALL;
|
|
|
|
}
|
2017-09-21 05:35:51 +08:00
|
|
|
} // end anonymous namespace
|
2017-02-23 22:18:41 +08:00
|
|
|
|
2017-02-21 19:33:59 +08:00
|
|
|
bool ARMCallLowering::lowerCall(MachineIRBuilder &MIRBuilder,
|
2017-03-20 22:40:18 +08:00
|
|
|
CallingConv::ID CallConv,
|
2017-02-21 19:33:59 +08:00
|
|
|
const MachineOperand &Callee,
|
|
|
|
const ArgInfo &OrigRet,
|
|
|
|
ArrayRef<ArgInfo> OrigArgs) const {
|
2017-02-23 21:25:43 +08:00
|
|
|
MachineFunction &MF = MIRBuilder.getMF();
|
|
|
|
const auto &TLI = *getTLI<ARMTargetLowering>();
|
|
|
|
const auto &DL = MF.getDataLayout();
|
2017-10-25 19:42:40 +08:00
|
|
|
const auto &STI = MF.getSubtarget<ARMSubtarget>();
|
2017-06-05 20:54:53 +08:00
|
|
|
const TargetRegisterInfo *TRI = STI.getRegisterInfo();
|
2017-02-23 21:25:43 +08:00
|
|
|
MachineRegisterInfo &MRI = MF.getRegInfo();
|
2017-02-21 19:33:59 +08:00
|
|
|
|
2017-10-25 19:42:40 +08:00
|
|
|
if (STI.genLongCalls())
|
2017-02-21 19:33:59 +08:00
|
|
|
return false;
|
|
|
|
|
2018-12-05 18:35:28 +08:00
|
|
|
if (STI.isThumb1Only())
|
|
|
|
return false;
|
|
|
|
|
2017-02-28 22:17:53 +08:00
|
|
|
auto CallSeqStart = MIRBuilder.buildInstr(ARM::ADJCALLSTACKDOWN);
|
2017-02-21 19:33:59 +08:00
|
|
|
|
2017-02-23 21:25:43 +08:00
|
|
|
// Create the call instruction so we can add the implicit uses of arg
|
|
|
|
// registers, but don't insert it yet.
|
2019-01-17 18:11:59 +08:00
|
|
|
bool IsDirect = !Callee.isReg();
|
|
|
|
auto CallOpcode = getCallOpcode(STI, IsDirect);
|
2018-12-05 18:35:28 +08:00
|
|
|
auto MIB = MIRBuilder.buildInstrNoInsert(CallOpcode);
|
|
|
|
|
2019-01-17 18:11:59 +08:00
|
|
|
bool IsThumb = STI.isThumb();
|
|
|
|
if (IsThumb)
|
2018-12-05 18:35:28 +08:00
|
|
|
MIB.add(predOps(ARMCC::AL));
|
|
|
|
|
|
|
|
MIB.add(Callee);
|
2019-01-17 18:11:59 +08:00
|
|
|
if (!IsDirect) {
|
2017-06-05 20:54:53 +08:00
|
|
|
auto CalleeReg = Callee.getReg();
|
2018-12-05 18:35:28 +08:00
|
|
|
if (CalleeReg && !TRI->isPhysicalRegister(CalleeReg)) {
|
2019-01-17 18:11:59 +08:00
|
|
|
unsigned CalleeIdx = IsThumb ? 2 : 0;
|
2018-12-05 18:35:28 +08:00
|
|
|
MIB->getOperand(CalleeIdx).setReg(constrainOperandRegClass(
|
2017-06-05 20:54:53 +08:00
|
|
|
MF, *TRI, MRI, *STI.getInstrInfo(), *STI.getRegBankInfo(),
|
2018-12-05 18:35:28 +08:00
|
|
|
*MIB.getInstr(), MIB->getDesc(), Callee, CalleeIdx));
|
|
|
|
}
|
2017-06-05 20:54:53 +08:00
|
|
|
}
|
2017-02-23 21:25:43 +08:00
|
|
|
|
2018-12-05 18:35:28 +08:00
|
|
|
MIB.addRegMask(TRI->getCallPreservedMask(MF, CallConv));
|
|
|
|
|
2019-01-17 18:11:55 +08:00
|
|
|
bool IsVarArg = false;
|
2017-02-23 21:25:43 +08:00
|
|
|
SmallVector<ArgInfo, 8> ArgInfos;
|
|
|
|
for (auto Arg : OrigArgs) {
|
|
|
|
if (!isSupportedType(DL, TLI, Arg.Ty))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!Arg.IsFixed)
|
2019-01-17 18:11:55 +08:00
|
|
|
IsVarArg = true;
|
2017-02-23 21:25:43 +08:00
|
|
|
|
2017-11-30 20:23:44 +08:00
|
|
|
if (Arg.Flags.isByVal())
|
|
|
|
return false;
|
|
|
|
|
2019-06-27 16:50:53 +08:00
|
|
|
assert(Arg.Regs.size() == 1 && "Can't handle multple regs yet");
|
|
|
|
|
2019-06-24 23:50:29 +08:00
|
|
|
SmallVector<Register, 8> Regs;
|
2019-05-27 18:30:33 +08:00
|
|
|
splitToValueTypes(Arg, ArgInfos, MF,
|
|
|
|
[&](unsigned Reg) { Regs.push_back(Reg); });
|
2017-06-15 17:42:02 +08:00
|
|
|
|
|
|
|
if (Regs.size() > 1)
|
2019-06-27 16:50:53 +08:00
|
|
|
MIRBuilder.buildUnmerge(Regs, Arg.Regs[0]);
|
2017-02-23 21:25:43 +08:00
|
|
|
}
|
|
|
|
|
2019-01-17 18:11:55 +08:00
|
|
|
auto ArgAssignFn = TLI.CCAssignFnForCall(CallConv, IsVarArg);
|
2017-02-23 21:25:43 +08:00
|
|
|
OutgoingValueHandler ArgHandler(MIRBuilder, MRI, MIB, ArgAssignFn);
|
|
|
|
if (!handleAssignments(MIRBuilder, ArgInfos, ArgHandler))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Now we can add the actual call instruction to the correct basic block.
|
|
|
|
MIRBuilder.insertInstr(MIB);
|
2017-02-21 19:33:59 +08:00
|
|
|
|
2017-02-23 22:18:41 +08:00
|
|
|
if (!OrigRet.Ty->isVoidTy()) {
|
|
|
|
if (!isSupportedType(DL, TLI, OrigRet.Ty))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
ArgInfos.clear();
|
2019-06-24 23:50:29 +08:00
|
|
|
SmallVector<Register, 8> SplitRegs;
|
2017-05-29 15:01:52 +08:00
|
|
|
splitToValueTypes(OrigRet, ArgInfos, MF,
|
2019-06-24 23:50:29 +08:00
|
|
|
[&](Register Reg) { SplitRegs.push_back(Reg); });
|
2017-02-23 22:18:41 +08:00
|
|
|
|
2019-01-17 18:11:55 +08:00
|
|
|
auto RetAssignFn = TLI.CCAssignFnForReturn(CallConv, IsVarArg);
|
2017-02-23 22:18:41 +08:00
|
|
|
CallReturnHandler RetHandler(MIRBuilder, MRI, MIB, RetAssignFn);
|
|
|
|
if (!handleAssignments(MIRBuilder, ArgInfos, RetHandler))
|
|
|
|
return false;
|
2017-05-29 16:19:19 +08:00
|
|
|
|
2017-06-15 17:42:02 +08:00
|
|
|
if (!SplitRegs.empty()) {
|
2017-05-29 16:19:19 +08:00
|
|
|
// We have split the value and allocated each individual piece, now build
|
|
|
|
// it up again.
|
2019-06-27 16:50:53 +08:00
|
|
|
assert(OrigRet.Regs.size() == 1 && "Can't handle multple regs yet");
|
|
|
|
MIRBuilder.buildMerge(OrigRet.Regs[0], SplitRegs);
|
2017-05-29 16:19:19 +08:00
|
|
|
}
|
2017-02-23 22:18:41 +08:00
|
|
|
}
|
|
|
|
|
2017-02-28 22:17:53 +08:00
|
|
|
// We now know the size of the stack - update the ADJCALLSTACKDOWN
|
|
|
|
// accordingly.
|
2017-05-09 21:35:13 +08:00
|
|
|
CallSeqStart.addImm(ArgHandler.StackSize).addImm(0).add(predOps(ARMCC::AL));
|
2017-02-28 22:17:53 +08:00
|
|
|
|
2017-02-21 19:33:59 +08:00
|
|
|
MIRBuilder.buildInstr(ARM::ADJCALLSTACKUP)
|
2017-02-28 22:17:53 +08:00
|
|
|
.addImm(ArgHandler.StackSize)
|
2017-02-21 19:33:59 +08:00
|
|
|
.addImm(0)
|
|
|
|
.add(predOps(ARMCC::AL));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|