2016-11-11 16:27:37 +08:00
|
|
|
//===-- llvm/lib/Target/ARM/ARMCallLowering.cpp - Call lowering -----------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// \file
|
|
|
|
/// This file implements the lowering of LLVM calls to machine code calls for
|
|
|
|
/// GlobalISel.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "ARMCallLowering.h"
|
|
|
|
|
|
|
|
#include "ARMBaseInstrInfo.h"
|
|
|
|
#include "ARMISelLowering.h"
|
2017-01-25 15:08:53 +08:00
|
|
|
#include "ARMSubtarget.h"
|
2016-11-11 16:27:37 +08:00
|
|
|
|
2017-02-02 22:01:00 +08:00
|
|
|
#include "llvm/CodeGen/Analysis.h"
|
2016-11-11 16:27:37 +08:00
|
|
|
#include "llvm/CodeGen/GlobalISel/MachineIRBuilder.h"
|
2016-12-19 19:55:41 +08:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2016-11-11 16:27:37 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
#ifndef LLVM_BUILD_GLOBAL_ISEL
|
|
|
|
#error "This shouldn't be built without GISel"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
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-02-02 22:00:54 +08:00
|
|
|
EVT VT = TLI.getValueType(DL, T, true);
|
2017-02-09 21:09:59 +08:00
|
|
|
if (!VT.isSimple() || VT.isVector())
|
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-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-02-28 22:17:53 +08:00
|
|
|
: ValueHandler(MIRBuilder, MRI, AssignFn), MIB(MIB), StackSize(0) {}
|
2016-12-16 20:54:46 +08:00
|
|
|
|
|
|
|
unsigned getStackAddress(uint64_t Size, int64_t Offset,
|
|
|
|
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);
|
|
|
|
unsigned SPReg = MRI.createGenericVirtualRegister(p0);
|
|
|
|
MIRBuilder.buildCopy(SPReg, ARM::SP);
|
|
|
|
|
|
|
|
unsigned OffsetReg = MRI.createGenericVirtualRegister(s32);
|
|
|
|
MIRBuilder.buildConstant(OffsetReg, Offset);
|
|
|
|
|
|
|
|
unsigned AddrReg = MRI.createGenericVirtualRegister(p0);
|
|
|
|
MIRBuilder.buildGEP(AddrReg, SPReg, OffsetReg);
|
|
|
|
|
|
|
|
MPO = MachinePointerInfo::getStack(MIRBuilder.getMF(), Offset);
|
|
|
|
return AddrReg;
|
2016-12-16 20:54:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void assignValueToReg(unsigned ValVReg, unsigned PhysReg,
|
|
|
|
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
|
|
|
|
2017-01-25 16:10:40 +08:00
|
|
|
unsigned ExtReg = extendRegister(ValVReg, VA);
|
|
|
|
MIRBuilder.buildCopy(PhysReg, ExtReg);
|
2016-12-16 20:54:46 +08:00
|
|
|
MIB.addUse(PhysReg, RegState::Implicit);
|
|
|
|
}
|
|
|
|
|
|
|
|
void assignValueToAddress(unsigned ValVReg, unsigned Addr, uint64_t Size,
|
|
|
|
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
|
|
|
|
[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
|
|
|
unsigned 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(),
|
|
|
|
/* Alignment */ 0);
|
|
|
|
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 {
|
|
|
|
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");
|
|
|
|
|
|
|
|
unsigned NewRegs[] = {MRI.createGenericVirtualRegister(LLT::scalar(32)),
|
|
|
|
MRI.createGenericVirtualRegister(LLT::scalar(32))};
|
2017-03-07 07:50:28 +08:00
|
|
|
MIRBuilder.buildExtract(NewRegs[0], Arg.Reg, 0);
|
|
|
|
MIRBuilder.buildExtract(NewRegs[1], Arg.Reg, 32);
|
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-02-28 22:17:53 +08:00
|
|
|
uint64_t StackSize;
|
2016-12-16 20:54:46 +08:00
|
|
|
};
|
|
|
|
} // End anonymous namespace.
|
|
|
|
|
2017-02-02 22:01:00 +08:00
|
|
|
void ARMCallLowering::splitToValueTypes(const ArgInfo &OrigArg,
|
|
|
|
SmallVectorImpl<ArgInfo> &SplitArgs,
|
|
|
|
const DataLayout &DL,
|
|
|
|
MachineRegisterInfo &MRI) const {
|
|
|
|
const ARMTargetLowering &TLI = *getTLI<ARMTargetLowering>();
|
|
|
|
LLVMContext &Ctx = OrigArg.Ty->getContext();
|
|
|
|
|
|
|
|
SmallVector<EVT, 4> SplitVTs;
|
|
|
|
SmallVector<uint64_t, 4> Offsets;
|
|
|
|
ComputeValueVTs(TLI, DL, OrigArg.Ty, SplitVTs, &Offsets, 0);
|
|
|
|
|
|
|
|
assert(SplitVTs.size() == 1 && "Unsupported type");
|
|
|
|
|
|
|
|
// Even if there is no splitting to do, we still want to replace the original
|
|
|
|
// type (e.g. pointer type -> integer).
|
|
|
|
SplitArgs.emplace_back(OrigArg.Reg, SplitVTs[0].getTypeForEVT(Ctx),
|
|
|
|
OrigArg.Flags, OrigArg.IsFixed);
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
const Value *Val, unsigned VReg,
|
|
|
|
MachineInstrBuilder &Ret) const {
|
|
|
|
if (!Val)
|
|
|
|
// Nothing to do here.
|
|
|
|
return true;
|
|
|
|
|
|
|
|
auto &MF = MIRBuilder.getMF();
|
|
|
|
const auto &F = *MF.getFunction();
|
|
|
|
|
|
|
|
auto DL = MF.getDataLayout();
|
|
|
|
auto &TLI = *getTLI<ARMTargetLowering>();
|
|
|
|
if (!isSupportedType(DL, TLI, Val->getType()))
|
|
|
|
return false;
|
|
|
|
|
2017-02-02 22:01:00 +08:00
|
|
|
SmallVector<ArgInfo, 4> SplitVTs;
|
2016-12-16 20:54:46 +08:00
|
|
|
ArgInfo RetInfo(VReg, Val->getType());
|
|
|
|
setArgFlags(RetInfo, AttributeSet::ReturnIndex, DL, F);
|
2017-02-02 22:01:00 +08:00
|
|
|
splitToValueTypes(RetInfo, SplitVTs, DL, MF.getRegInfo());
|
|
|
|
|
|
|
|
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,
|
|
|
|
const Value *Val, unsigned VReg) const {
|
2016-12-16 20:54:46 +08:00
|
|
|
assert(!Val == !VReg && "Return value without a vreg");
|
2016-11-11 16:27:37 +08:00
|
|
|
|
2017-01-13 17:37:56 +08:00
|
|
|
auto Ret = MIRBuilder.buildInstrNoInsert(ARM::BX_RET).add(predOps(ARMCC::AL));
|
2016-11-11 16:27:37 +08:00
|
|
|
|
2016-12-16 20:54:46 +08:00
|
|
|
if (!lowerReturnVal(MIRBuilder, Val, VReg, Ret))
|
|
|
|
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-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
|
|
|
|
|
|
|
unsigned getStackAddress(uint64_t Size, int64_t Offset,
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void assignValueToAddress(unsigned ValVReg, unsigned Addr, uint64_t Size,
|
|
|
|
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");
|
|
|
|
MRI.setType(ValVReg, LLT::scalar(32));
|
|
|
|
}
|
2016-12-19 19:55:41 +08:00
|
|
|
|
|
|
|
auto MMO = MIRBuilder.getMF().getMachineMemOperand(
|
|
|
|
MPO, MachineMemOperand::MOLoad, Size, /* Alignment */ 0);
|
|
|
|
MIRBuilder.buildLoad(ValVReg, Addr, *MMO);
|
2016-12-16 20:54:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void assignValueToReg(unsigned ValVReg, unsigned PhysReg,
|
|
|
|
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
|
|
|
|
2017-02-23 22:18:41 +08:00
|
|
|
// The necesary extensions are handled on the other side of the ABI
|
|
|
|
// boundary.
|
|
|
|
markPhysRegUsed(PhysReg);
|
2016-12-16 20:54:46 +08:00
|
|
|
MIRBuilder.buildCopy(ValVReg, PhysReg);
|
|
|
|
}
|
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 {
|
|
|
|
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");
|
|
|
|
|
|
|
|
unsigned NewRegs[] = {MRI.createGenericVirtualRegister(LLT::scalar(32)),
|
|
|
|
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]);
|
|
|
|
|
|
|
|
MIRBuilder.buildSequence(Arg.Reg, NewRegs, {0, 32});
|
|
|
|
|
|
|
|
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
|
|
|
};
|
|
|
|
} // End anonymous namespace
|
|
|
|
|
2016-11-11 16:27:37 +08:00
|
|
|
bool ARMCallLowering::lowerFormalArguments(MachineIRBuilder &MIRBuilder,
|
|
|
|
const Function &F,
|
|
|
|
ArrayRef<unsigned> VRegs) const {
|
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();
|
|
|
|
auto DL = MF.getDataLayout();
|
2016-12-16 20:54:46 +08:00
|
|
|
auto &TLI = *getTLI<ARMTargetLowering>();
|
|
|
|
|
2017-02-09 21:09:59 +08:00
|
|
|
auto Subtarget = TLI.getSubtarget();
|
|
|
|
|
|
|
|
if (Subtarget->isThumb())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// FIXME: Support soft float (when we're ready to generate libcalls)
|
|
|
|
if (Subtarget->useSoftFloat() || !Subtarget->hasVFP2())
|
2017-01-25 15:08:53 +08:00
|
|
|
return false;
|
|
|
|
|
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())
|
2016-12-16 20:54:46 +08:00
|
|
|
if (!isSupportedType(DL, TLI, Arg.getType()))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
CCAssignFn *AssignFn =
|
|
|
|
TLI.CCAssignFnForCall(F.getCallingConv(), F.isVarArg());
|
|
|
|
|
|
|
|
SmallVector<ArgInfo, 8> ArgInfos;
|
|
|
|
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()) {
|
2016-12-16 20:54:46 +08:00
|
|
|
ArgInfo AInfo(VRegs[Idx], Arg.getType());
|
|
|
|
setArgFlags(AInfo, Idx + 1, DL, F);
|
2017-02-02 22:01:00 +08:00
|
|
|
splitToValueTypes(AInfo, ArgInfos, DL, MF.getRegInfo());
|
2016-12-16 20:54:46 +08:00
|
|
|
Idx++;
|
|
|
|
}
|
|
|
|
|
2017-01-18 06:30:10 +08:00
|
|
|
FormalArgHandler ArgHandler(MIRBuilder, MIRBuilder.getMF().getRegInfo(),
|
|
|
|
AssignFn);
|
|
|
|
return handleAssignments(MIRBuilder, ArgInfos, ArgHandler);
|
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 {
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
} // End anonymous namespace.
|
|
|
|
|
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-02-21 19:33:59 +08:00
|
|
|
const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
|
2017-02-23 21:25:43 +08:00
|
|
|
MachineRegisterInfo &MRI = MF.getRegInfo();
|
2017-02-21 19:33:59 +08:00
|
|
|
|
|
|
|
if (MF.getSubtarget<ARMSubtarget>().genLongCalls())
|
|
|
|
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.
|
|
|
|
auto MIB = MIRBuilder.buildInstrNoInsert(ARM::BLX).add(Callee).addRegMask(
|
|
|
|
TRI->getCallPreservedMask(MF, CallConv));
|
|
|
|
|
|
|
|
SmallVector<ArgInfo, 8> ArgInfos;
|
|
|
|
for (auto Arg : OrigArgs) {
|
|
|
|
if (!isSupportedType(DL, TLI, Arg.Ty))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!Arg.IsFixed)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
splitToValueTypes(Arg, ArgInfos, DL, MRI);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto ArgAssignFn = TLI.CCAssignFnForCall(CallConv, /*IsVarArg=*/false);
|
|
|
|
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();
|
|
|
|
splitToValueTypes(OrigRet, ArgInfos, DL, MRI);
|
|
|
|
|
|
|
|
auto RetAssignFn = TLI.CCAssignFnForReturn(CallConv, /*IsVarArg=*/false);
|
|
|
|
CallReturnHandler RetHandler(MIRBuilder, MRI, MIB, RetAssignFn);
|
|
|
|
if (!handleAssignments(MIRBuilder, ArgInfos, RetHandler))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-02-28 22:17:53 +08:00
|
|
|
// We now know the size of the stack - update the ADJCALLSTACKDOWN
|
|
|
|
// accordingly.
|
|
|
|
CallSeqStart.addImm(ArgHandler.StackSize).add(predOps(ARMCC::AL));
|
|
|
|
|
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;
|
|
|
|
}
|