1 //===---- MipsCCState.h - CCState with Mips specific extensions -----------===//
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
7 //===----------------------------------------------------------------------===//
12 #include "MipsISelLowering.h"
13 #include "llvm/ADT/SmallVector.h"
14 #include "llvm/CodeGen/CallingConvLower.h"
20 class MipsCCState
: public CCState
{
22 enum SpecialCallingConvType
{ Mips16RetHelperConv
, NoSpecialCallingConv
};
24 /// Determine the SpecialCallingConvType for the given callee
25 static SpecialCallingConvType
26 getSpecialCallingConvForCallee(const SDNode
*Callee
,
27 const MipsSubtarget
&Subtarget
);
30 /// Identify lowered values that originated from f128 arguments and record
31 /// this for use by RetCC_MipsN.
32 void PreAnalyzeCallResultForF128(const SmallVectorImpl
<ISD::InputArg
> &Ins
,
33 const Type
*RetTy
, const char * Func
);
35 /// Identify lowered values that originated from f128 arguments and record
36 /// this for use by RetCC_MipsN.
37 void PreAnalyzeReturnForF128(const SmallVectorImpl
<ISD::OutputArg
> &Outs
);
39 /// Identify lowered values that originated from f128 arguments and record
42 PreAnalyzeCallOperands(const SmallVectorImpl
<ISD::OutputArg
> &Outs
,
43 std::vector
<TargetLowering::ArgListEntry
> &FuncArgs
,
46 /// Identify lowered values that originated from f128 arguments and record
47 /// this for use by RetCC_MipsN.
49 PreAnalyzeFormalArgumentsForF128(const SmallVectorImpl
<ISD::InputArg
> &Ins
);
52 PreAnalyzeCallResultForVectorFloat(const SmallVectorImpl
<ISD::InputArg
> &Ins
,
55 void PreAnalyzeFormalArgumentsForVectorFloat(
56 const SmallVectorImpl
<ISD::InputArg
> &Ins
);
59 PreAnalyzeReturnForVectorFloat(const SmallVectorImpl
<ISD::OutputArg
> &Outs
);
61 /// Records whether the value has been lowered from an f128.
62 SmallVector
<bool, 4> OriginalArgWasF128
;
64 /// Records whether the value has been lowered from float.
65 SmallVector
<bool, 4> OriginalArgWasFloat
;
67 /// Records whether the value has been lowered from a floating point vector.
68 SmallVector
<bool, 4> OriginalArgWasFloatVector
;
70 /// Records whether the return value has been lowered from a floating point
72 SmallVector
<bool, 4> OriginalRetWasFloatVector
;
74 /// Records whether the value was a fixed argument.
75 /// See ISD::OutputArg::IsFixed,
76 SmallVector
<bool, 4> CallOperandIsFixed
;
78 // Used to handle MIPS16-specific calling convention tweaks.
79 // FIXME: This should probably be a fully fledged calling convention.
80 SpecialCallingConvType SpecialCallingConv
;
83 MipsCCState(CallingConv::ID CC
, bool isVarArg
, MachineFunction
&MF
,
84 SmallVectorImpl
<CCValAssign
> &locs
, LLVMContext
&C
,
85 SpecialCallingConvType SpecialCC
= NoSpecialCallingConv
)
86 : CCState(CC
, isVarArg
, MF
, locs
, C
), SpecialCallingConv(SpecialCC
) {}
89 AnalyzeCallOperands(const SmallVectorImpl
<ISD::OutputArg
> &Outs
,
91 std::vector
<TargetLowering::ArgListEntry
> &FuncArgs
,
93 PreAnalyzeCallOperands(Outs
, FuncArgs
, Func
);
94 CCState::AnalyzeCallOperands(Outs
, Fn
);
95 OriginalArgWasF128
.clear();
96 OriginalArgWasFloat
.clear();
97 OriginalArgWasFloatVector
.clear();
98 CallOperandIsFixed
.clear();
101 // The AnalyzeCallOperands in the base class is not usable since we must
102 // provide a means of accessing ArgListEntry::IsFixed. Delete them from this
103 // class. This doesn't stop them being used via the base class though.
104 void AnalyzeCallOperands(const SmallVectorImpl
<ISD::OutputArg
> &Outs
,
105 CCAssignFn Fn
) = delete;
106 void AnalyzeCallOperands(const SmallVectorImpl
<MVT
> &Outs
,
107 SmallVectorImpl
<ISD::ArgFlagsTy
> &Flags
,
108 CCAssignFn Fn
) = delete;
110 void AnalyzeFormalArguments(const SmallVectorImpl
<ISD::InputArg
> &Ins
,
112 PreAnalyzeFormalArgumentsForF128(Ins
);
113 CCState::AnalyzeFormalArguments(Ins
, Fn
);
114 OriginalArgWasFloat
.clear();
115 OriginalArgWasF128
.clear();
116 OriginalArgWasFloatVector
.clear();
119 void AnalyzeCallResult(const SmallVectorImpl
<ISD::InputArg
> &Ins
,
120 CCAssignFn Fn
, const Type
*RetTy
,
122 PreAnalyzeCallResultForF128(Ins
, RetTy
, Func
);
123 PreAnalyzeCallResultForVectorFloat(Ins
, RetTy
);
124 CCState::AnalyzeCallResult(Ins
, Fn
);
125 OriginalArgWasFloat
.clear();
126 OriginalArgWasF128
.clear();
127 OriginalArgWasFloatVector
.clear();
130 void AnalyzeReturn(const SmallVectorImpl
<ISD::OutputArg
> &Outs
,
132 PreAnalyzeReturnForF128(Outs
);
133 PreAnalyzeReturnForVectorFloat(Outs
);
134 CCState::AnalyzeReturn(Outs
, Fn
);
135 OriginalArgWasFloat
.clear();
136 OriginalArgWasF128
.clear();
137 OriginalArgWasFloatVector
.clear();
140 bool CheckReturn(const SmallVectorImpl
<ISD::OutputArg
> &ArgsFlags
,
142 PreAnalyzeReturnForF128(ArgsFlags
);
143 PreAnalyzeReturnForVectorFloat(ArgsFlags
);
144 bool Return
= CCState::CheckReturn(ArgsFlags
, Fn
);
145 OriginalArgWasFloat
.clear();
146 OriginalArgWasF128
.clear();
147 OriginalArgWasFloatVector
.clear();
151 bool WasOriginalArgF128(unsigned ValNo
) { return OriginalArgWasF128
[ValNo
]; }
152 bool WasOriginalArgFloat(unsigned ValNo
) {
153 return OriginalArgWasFloat
[ValNo
];
155 bool WasOriginalArgVectorFloat(unsigned ValNo
) const {
156 return OriginalArgWasFloatVector
[ValNo
];
158 bool WasOriginalRetVectorFloat(unsigned ValNo
) const {
159 return OriginalRetWasFloatVector
[ValNo
];
161 bool IsCallOperandFixed(unsigned ValNo
) { return CallOperandIsFixed
[ValNo
]; }
162 SpecialCallingConvType
getSpecialCallingConv() { return SpecialCallingConv
; }