Skip to content

Commit eac0960

Browse files
committedNov 1, 2014
[mips] Move F128 argument handling into MipsCCState as we did for returns. NFC.
Summary: There are a couple more changes to make before analyzeFormalArguments can be merged into the standard AnalyzeFormalArguments. I've had to temporarily poke a couple holes in MipsCCState's encapsulation to save having to make all the required changes for this merge all at once*. These will be removed shortly. * We must merge our ByVal argument handling with the implementation in CCState. This will be done over the next three patches, then the fourth will merge analyzeFormalArguments with AnalyzeFormalArguments. Depends on D5967 Reviewers: vmedic Reviewed By: vmedic Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D5969 llvm-svn: 221056
1 parent 7cbf58a commit eac0960

File tree

3 files changed

+90
-27
lines changed

3 files changed

+90
-27
lines changed
 

‎llvm/lib/Target/Mips/MipsCallingConv.td

+15
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,21 @@ def RetCC_Mips : CallingConv<[
298298
]>;
299299

300300
def CC_Mips_FixedArg : CallingConv<[
301+
// f128 needs to be handled similarly to f32 and f64 on hard-float. However,
302+
// f128 is not legal and is lowered to i128 which is further lowered to a pair
303+
// of i64's.
304+
// This presents us with a problem for the calling convention since hard-float
305+
// still needs to pass them in FPU registers. We therefore resort to a
306+
// pre-analyze (see PreAnalyzeFormalArgsForF128()) step to pass information on
307+
// whether the argument was originally an f128 into the tablegen-erated code.
308+
//
309+
// f128 should only occur for the N64 ABI where long double is 128-bit. On
310+
// N32, long double is equivalent to double.
311+
CCIfType<[i64],
312+
CCIfSubtargetNot<"abiUsesSoftFloat()",
313+
CCIf<"static_cast<MipsCCState *>(&State)->WasOriginalArgF128(ValNo)",
314+
CCBitConvertToType<f64>>>>,
315+
301316
CCIfCC<"CallingConv::Fast", CCDelegateTo<CC_Mips_FastCC>>,
302317

303318
// FIXME: There wasn't an EABI case in the original code and it seems unlikely

‎llvm/lib/Target/Mips/MipsISelLowering.cpp

+75-26
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,52 @@ class MipsCCState : public CCState {
9595
originalTypeIsF128(MF.getFunction()->getReturnType(), nullptr));
9696
}
9797

98+
/// Identify lowered values that originated from f128 arguments and record
99+
/// this.
100+
void PreAnalyzeCallOperandsForF128(
101+
const SmallVectorImpl<ISD::OutputArg> &Outs,
102+
std::vector<TargetLowering::ArgListEntry> &FuncArgs, SDNode *CallNode) {
103+
const MachineFunction &MF = getMachineFunction();
104+
for (unsigned i = 0; i < Outs.size(); ++i)
105+
OriginalArgWasF128.push_back(
106+
originalTypeIsF128(FuncArgs[Outs[i].OrigArgIndex].Ty, CallNode));
107+
}
108+
109+
/// Identify lowered values that originated from f128 arguments and record
110+
/// this.
111+
void
112+
PreAnalyzeFormalArgumentsForF128(const SmallVectorImpl<ISD::InputArg> &Ins) {
113+
const MachineFunction &MF = getMachineFunction();
114+
for (unsigned i = 0; i < Ins.size(); ++i) {
115+
Function::const_arg_iterator FuncArg = MF.getFunction()->arg_begin();
116+
std::advance(FuncArg, Ins[i].OrigArgIndex);
117+
118+
OriginalArgWasF128.push_back(
119+
originalTypeIsF128(FuncArg->getType(), nullptr));
120+
}
121+
}
122+
98123
/// Records whether the value has been lowered from an f128.
99124
SmallVector<bool, 4> OriginalArgWasF128;
100125

101126
public:
127+
// FIXME: Remove this from a public inteface ASAP. It's a temporary trap door
128+
// to allow analyzeCallOperands to be removed incrementally.
129+
void PreAnalyzeCallOperandsForF128_(
130+
const SmallVectorImpl<ISD::OutputArg> &Outs,
131+
std::vector<TargetLowering::ArgListEntry> &FuncArgs, SDNode *CallNode) {
132+
PreAnalyzeCallOperandsForF128(Outs, FuncArgs, CallNode);
133+
}
134+
// FIXME: Remove this from a public inteface ASAP. It's a temporary trap door
135+
// to allow analyzeFormalArguments to be removed incrementally.
136+
void
137+
PreAnalyzeFormalArgumentsForF128_(const SmallVectorImpl<ISD::InputArg> &Ins) {
138+
PreAnalyzeFormalArgumentsForF128(Ins);
139+
}
140+
// FIXME: Remove this from a public inteface ASAP. It's a temporary trap door
141+
// to clean up after the above functions.
142+
void ClearOriginalArgWasF128() { OriginalArgWasF128.clear(); }
143+
102144
MipsCCState(CallingConv::ID CC, bool isVarArg, MachineFunction &MF,
103145
SmallVectorImpl<CCValAssign> &locs, LLVMContext &C)
104146
: CCState(CC, isVarArg, MF, locs, C) {}
@@ -2546,12 +2588,14 @@ MipsTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
25462588

25472589
// Analyze operands of the call, assigning locations to each operand.
25482590
SmallVector<CCValAssign, 16> ArgLocs;
2549-
CCState CCInfo(CallConv, IsVarArg, DAG.getMachineFunction(), ArgLocs,
2550-
*DAG.getContext());
2591+
MipsCCState CCInfo(CallConv, IsVarArg, DAG.getMachineFunction(), ArgLocs,
2592+
*DAG.getContext());
25512593
MipsCC MipsCCInfo(CallConv, Subtarget, CCInfo);
25522594

2595+
CCInfo.PreAnalyzeCallOperandsForF128_(Outs, CLI.getArgs(), Callee.getNode());
25532596
MipsCCInfo.analyzeCallOperands(Outs, IsVarArg, Subtarget.abiUsesSoftFloat(),
25542597
Callee.getNode(), CLI.getArgs(), CCInfo);
2598+
CCInfo.ClearOriginalArgWasF128();
25552599

25562600
// Get a count of how many bytes are to be pushed on the stack.
25572601
unsigned NextStackOffset = CCInfo.getNextStackOffset();
@@ -2632,6 +2676,9 @@ MipsTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
26322676
}
26332677
}
26342678
break;
2679+
case CCValAssign::BCvt:
2680+
Arg = DAG.getNode(ISD::BITCAST, DL, LocVT, Arg);
2681+
break;
26352682
case CCValAssign::SExt:
26362683
Arg = DAG.getNode(ISD::SIGN_EXTEND, DL, LocVT, Arg);
26372684
break;
@@ -2829,14 +2876,16 @@ MipsTargetLowering::LowerFormalArguments(SDValue Chain,
28292876

28302877
// Assign locations to all of the incoming arguments.
28312878
SmallVector<CCValAssign, 16> ArgLocs;
2832-
CCState CCInfo(CallConv, IsVarArg, DAG.getMachineFunction(), ArgLocs,
2833-
*DAG.getContext());
2879+
MipsCCState CCInfo(CallConv, IsVarArg, DAG.getMachineFunction(), ArgLocs,
2880+
*DAG.getContext());
28342881
MipsCC MipsCCInfo(CallConv, Subtarget, CCInfo);
28352882
Function::const_arg_iterator FuncArg =
28362883
DAG.getMachineFunction().getFunction()->arg_begin();
28372884
bool UseSoftFloat = Subtarget.abiUsesSoftFloat();
28382885

2839-
MipsCCInfo.analyzeFormalArguments(Ins, UseSoftFloat, FuncArg, CCInfo);
2886+
CCInfo.PreAnalyzeFormalArgumentsForF128_(Ins);
2887+
MipsCCInfo.analyzeFormalArguments(Ins, UseSoftFloat, CCInfo);
2888+
CCInfo.ClearOriginalArgWasF128();
28402889
MipsFI->setFormalArgInfo(CCInfo.getNextStackOffset(),
28412890
MipsCCInfo.hasByValArg());
28422891

@@ -2875,16 +2924,24 @@ MipsTargetLowering::LowerFormalArguments(SDValue Chain,
28752924
// If this is an 8 or 16-bit value, it has been passed promoted
28762925
// to 32 bits. Insert an assert[sz]ext to capture this, then
28772926
// truncate to the right size.
2878-
if (VA.getLocInfo() != CCValAssign::Full) {
2879-
unsigned Opcode = 0;
2880-
if (VA.getLocInfo() == CCValAssign::SExt)
2881-
Opcode = ISD::AssertSext;
2882-
else if (VA.getLocInfo() == CCValAssign::ZExt)
2883-
Opcode = ISD::AssertZext;
2884-
if (Opcode)
2885-
ArgValue = DAG.getNode(Opcode, DL, RegVT, ArgValue,
2886-
DAG.getValueType(ValVT));
2927+
switch (VA.getLocInfo()) {
2928+
default:
2929+
llvm_unreachable("Unknown loc info!");
2930+
case CCValAssign::Full:
2931+
break;
2932+
case CCValAssign::SExt:
2933+
ArgValue = DAG.getNode(ISD::AssertSext, DL, RegVT, ArgValue,
2934+
DAG.getValueType(ValVT));
2935+
ArgValue = DAG.getNode(ISD::TRUNCATE, DL, ValVT, ArgValue);
2936+
break;
2937+
case CCValAssign::ZExt:
2938+
ArgValue = DAG.getNode(ISD::AssertZext, DL, RegVT, ArgValue,
2939+
DAG.getValueType(ValVT));
28872940
ArgValue = DAG.getNode(ISD::TRUNCATE, DL, ValVT, ArgValue);
2941+
break;
2942+
case CCValAssign::BCvt:
2943+
ArgValue = DAG.getNode(ISD::BITCAST, DL, ValVT, ArgValue);
2944+
break;
28882945
}
28892946

28902947
// Handle floating point arguments passed in integer registers and
@@ -3563,11 +3620,8 @@ void MipsTargetLowering::MipsCC::analyzeCallOperands(
35633620

35643621
if (IsVarArg && !Args[I].IsFixed)
35653622
R = CC_Mips_VarArg(I, ArgVT, ArgVT, CCValAssign::Full, ArgFlags, State);
3566-
else {
3567-
MVT RegVT = getRegVT(ArgVT, FuncArgs[Args[I].OrigArgIndex].Ty, CallNode,
3568-
IsSoftFloat);
3569-
R = FixedFn(I, ArgVT, RegVT, CCValAssign::Full, ArgFlags, State);
3570-
}
3623+
else
3624+
R = FixedFn(I, ArgVT, ArgVT, CCValAssign::Full, ArgFlags, State);
35713625

35723626
if (R) {
35733627
#ifndef NDEBUG
@@ -3581,24 +3635,19 @@ void MipsTargetLowering::MipsCC::analyzeCallOperands(
35813635

35823636
void MipsTargetLowering::MipsCC::analyzeFormalArguments(
35833637
const SmallVectorImpl<ISD::InputArg> &Args, bool IsSoftFloat,
3584-
Function::const_arg_iterator FuncArg, CCState &State) {
3638+
CCState &State) {
35853639
unsigned NumArgs = Args.size();
3586-
unsigned CurArgIdx = 0;
35873640

35883641
for (unsigned I = 0; I != NumArgs; ++I) {
35893642
MVT ArgVT = Args[I].VT;
35903643
ISD::ArgFlagsTy ArgFlags = Args[I].Flags;
3591-
std::advance(FuncArg, Args[I].OrigArgIndex - CurArgIdx);
3592-
CurArgIdx = Args[I].OrigArgIndex;
35933644

35943645
if (ArgFlags.isByVal()) {
35953646
handleByValArg(I, ArgVT, ArgVT, CCValAssign::Full, ArgFlags, State);
35963647
continue;
35973648
}
35983649

3599-
MVT RegVT = getRegVT(ArgVT, FuncArg->getType(), nullptr, IsSoftFloat);
3600-
3601-
if (!CC_Mips_FixedArg(I, ArgVT, RegVT, CCValAssign::Full, ArgFlags, State))
3650+
if (!CC_Mips_FixedArg(I, ArgVT, ArgVT, CCValAssign::Full, ArgFlags, State))
36023651
continue;
36033652

36043653
#ifndef NDEBUG

‎llvm/lib/Target/Mips/MipsISelLowering.h

-1
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,6 @@ namespace llvm {
366366
CCState &State);
367367
void analyzeFormalArguments(const SmallVectorImpl<ISD::InputArg> &Ins,
368368
bool IsSoftFloat,
369-
Function::const_arg_iterator FuncArg,
370369
CCState &State);
371370

372371
/// hasByValArg - Returns true if function has byval arguments.

0 commit comments

Comments
 (0)
Please sign in to comment.