LLVM  14.0.0git
MipsCCState.cpp
Go to the documentation of this file.
1 //===---- MipsCCState.cpp - CCState with Mips specific extensions ---------===//
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 #include "MipsCCState.h"
10 #include "MipsSubtarget.h"
11 #include "llvm/IR/Module.h"
12 
13 using namespace llvm;
14 
15 bool MipsCCState::isF128SoftLibCall(const char *CallSym) {
16  const char *const LibCalls[] = {
17  "__addtf3", "__divtf3", "__eqtf2", "__extenddftf2",
18  "__extendsftf2", "__fixtfdi", "__fixtfsi", "__fixtfti",
19  "__fixunstfdi", "__fixunstfsi", "__fixunstfti", "__floatditf",
20  "__floatsitf", "__floattitf", "__floatunditf", "__floatunsitf",
21  "__floatuntitf", "__getf2", "__gttf2", "__letf2",
22  "__lttf2", "__multf3", "__netf2", "__powitf2",
23  "__subtf3", "__trunctfdf2", "__trunctfsf2", "__unordtf2",
24  "ceill", "copysignl", "cosl", "exp2l",
25  "expl", "floorl", "fmal", "fmaxl",
26  "fmodl", "log10l", "log2l", "logl",
27  "nearbyintl", "powl", "rintl", "roundl",
28  "sinl", "sqrtl", "truncl"};
29 
30  // Check that LibCalls is sorted alphabetically.
31  auto Comp = [](const char *S1, const char *S2) { return strcmp(S1, S2) < 0; };
32  assert(llvm::is_sorted(LibCalls, Comp));
33  return std::binary_search(std::begin(LibCalls), std::end(LibCalls), CallSym,
34  Comp);
35 }
36 
37 /// This function returns true if Ty is fp128, {f128} or i128 which was
38 /// originally a fp128.
39 bool MipsCCState::originalTypeIsF128(const Type *Ty, const char *Func) {
40  if (Ty->isFP128Ty())
41  return true;
42 
43  if (Ty->isStructTy() && Ty->getStructNumElements() == 1 &&
45  return true;
46 
47  // If the Ty is i128 and the function being called is a long double emulation
48  // routine, then the original type is f128.
49  // FIXME: This is unsound because these functions could be indirectly called
50  return (Func && Ty->isIntegerTy(128) && isF128SoftLibCall(Func));
51 }
52 
53 /// Return true if the original type was vXfXX.
56  return true;
57 
58  return false;
59 }
60 
61 /// Return true if the original type was vXfXX / vXfXX.
63  if (Ty->isVectorTy() && Ty->isFPOrFPVectorTy())
64  return true;
65 
66  return false;
67 }
68 
71  const MipsSubtarget &Subtarget) {
73  if (Subtarget.inMips16HardFloat()) {
74  if (const GlobalAddressSDNode *G =
75  dyn_cast<const GlobalAddressSDNode>(Callee)) {
76  llvm::StringRef Sym = G->getGlobal()->getName();
77  Function *F = G->getGlobal()->getParent()->getFunction(Sym);
78  if (F && F->hasFnAttribute("__Mips16RetHelper")) {
79  SpecialCallingConv = Mips16RetHelperConv;
80  }
81  }
82  }
83  return SpecialCallingConv;
84 }
85 
86 void MipsCCState::PreAnalyzeCallResultForF128(
88  const Type *RetTy, const char *Call) {
89  for (unsigned i = 0; i < Ins.size(); ++i) {
90  OriginalArgWasF128.push_back(
91  originalTypeIsF128(RetTy, Call));
92  OriginalArgWasFloat.push_back(RetTy->isFloatingPointTy());
93  }
94 }
95 
96 /// Identify lowered values that originated from f128 or float arguments and
97 /// record this for use by RetCC_MipsN.
98 void MipsCCState::PreAnalyzeReturnForF128(
99  const SmallVectorImpl<ISD::OutputArg> &Outs) {
100  const MachineFunction &MF = getMachineFunction();
101  for (unsigned i = 0; i < Outs.size(); ++i) {
102  OriginalArgWasF128.push_back(
103  originalTypeIsF128(MF.getFunction().getReturnType(), nullptr));
104  OriginalArgWasFloat.push_back(
106  }
107 }
108 
109 /// Identify lower values that originated from vXfXX and record
110 /// this.
111 void MipsCCState::PreAnalyzeCallResultForVectorFloat(
112  const SmallVectorImpl<ISD::InputArg> &Ins, const Type *RetTy) {
113  for (unsigned i = 0; i < Ins.size(); ++i) {
114  OriginalRetWasFloatVector.push_back(originalTypeIsVectorFloat(RetTy));
115  }
116 }
117 
118 /// Identify lowered values that originated from vXfXX arguments and record
119 /// this.
120 void MipsCCState::PreAnalyzeReturnForVectorFloat(
121  const SmallVectorImpl<ISD::OutputArg> &Outs) {
122  for (unsigned i = 0; i < Outs.size(); ++i) {
123  ISD::OutputArg Out = Outs[i];
124  OriginalRetWasFloatVector.push_back(
126  }
127 }
128 
130  OriginalRetWasFloatVector.push_back(originalEVTTypeIsVectorFloat(ArgVT));
131 }
132 
133 void MipsCCState::PreAnalyzeCallOperand(const Type *ArgTy, bool IsFixed,
134  const char *Func) {
135  OriginalArgWasF128.push_back(originalTypeIsF128(ArgTy, Func));
136  OriginalArgWasFloat.push_back(ArgTy->isFloatingPointTy());
137  OriginalArgWasFloatVector.push_back(ArgTy->isVectorTy());
138  CallOperandIsFixed.push_back(IsFixed);
139 }
140 
141 /// Identify lowered values that originated from f128, float and sret to vXfXX
142 /// arguments and record this.
143 void MipsCCState::PreAnalyzeCallOperands(
145  std::vector<TargetLowering::ArgListEntry> &FuncArgs,
146  const char *Func) {
147  for (unsigned i = 0; i < Outs.size(); ++i) {
148  TargetLowering::ArgListEntry FuncArg = FuncArgs[Outs[i].OrigArgIndex];
149 
150  OriginalArgWasF128.push_back(originalTypeIsF128(FuncArg.Ty, Func));
151  OriginalArgWasFloat.push_back(FuncArg.Ty->isFloatingPointTy());
152  OriginalArgWasFloatVector.push_back(FuncArg.Ty->isVectorTy());
153  CallOperandIsFixed.push_back(Outs[i].IsFixed);
154  }
155 }
156 
158  ISD::ArgFlagsTy Flags) {
159  // SRet arguments cannot originate from f128 or {f128} returns so we just
160  // push false. We have to handle this specially since SRet arguments
161  // aren't mapped to an original argument.
162  if (Flags.isSRet()) {
163  OriginalArgWasF128.push_back(false);
164  OriginalArgWasFloat.push_back(false);
165  OriginalArgWasFloatVector.push_back(false);
166  return;
167  }
168 
169  OriginalArgWasF128.push_back(originalTypeIsF128(ArgTy, nullptr));
170  OriginalArgWasFloat.push_back(ArgTy->isFloatingPointTy());
171 
172  // The MIPS vector ABI exhibits a corner case of sorts or quirk; if the
173  // first argument is actually an SRet pointer to a vector, then the next
174  // argument slot is $a2.
175  OriginalArgWasFloatVector.push_back(ArgTy->isVectorTy());
176 }
177 
178 /// Identify lowered values that originated from f128, float and vXfXX arguments
179 /// and record this.
180 void MipsCCState::PreAnalyzeFormalArgumentsForF128(
182  const MachineFunction &MF = getMachineFunction();
183  for (unsigned i = 0; i < Ins.size(); ++i) {
185 
186  // SRet arguments cannot originate from f128 or {f128} returns so we just
187  // push false. We have to handle this specially since SRet arguments
188  // aren't mapped to an original argument.
189  if (Ins[i].Flags.isSRet()) {
190  OriginalArgWasF128.push_back(false);
191  OriginalArgWasFloat.push_back(false);
192  OriginalArgWasFloatVector.push_back(false);
193  continue;
194  }
195 
196  assert(Ins[i].getOrigArgIndex() < MF.getFunction().arg_size());
197  std::advance(FuncArg, Ins[i].getOrigArgIndex());
198 
199  OriginalArgWasF128.push_back(
200  originalTypeIsF128(FuncArg->getType(), nullptr));
201  OriginalArgWasFloat.push_back(FuncArg->getType()->isFloatingPointTy());
202 
203  // The MIPS vector ABI exhibits a corner case of sorts or quirk; if the
204  // first argument is actually an SRet pointer to a vector, then the next
205  // argument slot is $a2.
206  OriginalArgWasFloatVector.push_back(FuncArg->getType()->isVectorTy());
207  }
208 }
i
i
Definition: README.txt:29
llvm::Argument
This class represents an incoming formal argument to a Function.
Definition: Argument.h:29
llvm::MipsCCState::originalEVTTypeIsVectorFloat
static bool originalEVTTypeIsVectorFloat(EVT Ty)
Return true if the original type was vXfXX.
Definition: MipsCCState.cpp:54
llvm::MipsCCState::NoSpecialCallingConv
@ NoSpecialCallingConv
Definition: MipsCCState.h:22
llvm::MipsCCState::PreAnalyzeReturnValue
void PreAnalyzeReturnValue(EVT ArgVT)
Definition: MipsCCState.cpp:129
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::ISD::ArgFlagsTy::isSRet
bool isSRet() const
Definition: TargetCallingConv.h:82
llvm::MipsCCState::PreAnalyzeFormalArgument
void PreAnalyzeFormalArgument(const Type *ArgTy, ISD::ArgFlagsTy Flags)
Definition: MipsCCState.cpp:157
llvm::Function
Definition: Function.h:62
llvm::SDNode
Represents one node in the SelectionDAG.
Definition: SelectionDAGNodes.h:455
llvm::Type::isFPOrFPVectorTy
bool isFPOrFPVectorTy() const
Return true if this is a FP type or a vector of FP.
Definition: Type.h:178
llvm::Function::arg_size
size_t arg_size() const
Definition: Function.h:782
llvm::MipsCCState::SpecialCallingConvType
SpecialCallingConvType
Definition: MipsCCState.h:22
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
Module.h
llvm::sys::path::end
const_iterator end(StringRef path)
Get end iterator over path.
Definition: Path.cpp:233
llvm::sys::path::begin
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Definition: Path.cpp:224
llvm::CCState::getMachineFunction
MachineFunction & getMachineFunction() const
Definition: CallingConvLower.h:258
llvm::ISD::OutputArg::ArgVT
EVT ArgVT
Definition: TargetCallingConv.h:236
llvm::Type::isFloatingPointTy
bool isFloatingPointTy() const
Return true if this is one of the six floating-point types.
Definition: Type.h:162
llvm::MipsCCState::originalTypeIsVectorFloat
static bool originalTypeIsVectorFloat(const Type *Ty)
Return true if the original type was vXfXX / vXfXX.
Definition: MipsCCState.cpp:62
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::MipsCCState::getSpecialCallingConvForCallee
static SpecialCallingConvType getSpecialCallingConvForCallee(const SDNode *Callee, const MipsSubtarget &Subtarget)
Determine the SpecialCallingConvType for the given callee.
Definition: MipsCCState.cpp:70
llvm::EVT
Extended Value Type.
Definition: ValueTypes.h:35
llvm::MipsCCState::originalTypeIsF128
static bool originalTypeIsF128(const Type *Ty, const char *Func)
This function returns true if Ty is fp128, {f128} or i128 which was originally a fp128.
Definition: MipsCCState.cpp:39
llvm::Type::isVectorTy
bool isVectorTy() const
True if this is an instance of VectorType.
Definition: Type.h:226
llvm::Type::getStructNumElements
unsigned getStructNumElements() const
Definition: DerivedTypes.h:348
llvm::Type::isIntegerTy
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition: Type.h:190
G
const DataFlowGraph & G
Definition: RDFGraph.cpp:202
llvm::Function::getReturnType
Type * getReturnType() const
Returns the type of the ret val.
Definition: Function.h:182
llvm::ISD::OutputArg
OutputArg - This struct carries flags and a value for a single outgoing (actual) argument or outgoing...
Definition: TargetCallingConv.h:233
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::TargetLoweringBase::ArgListEntry
Definition: TargetLowering.h:274
llvm::MipsCCState::Mips16RetHelperConv
@ Mips16RetHelperConv
Definition: MipsCCState.h:22
llvm::MachineFunction
Definition: MachineFunction.h:234
llvm::EVT::isVector
bool isVector() const
Return true if this is a vector value type.
Definition: ValueTypes.h:155
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::Type::getStructElementType
Type * getStructElementType(unsigned N) const
Definition: DerivedTypes.h:352
llvm::Value::getType
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
llvm::ISD::ArgFlagsTy
Definition: TargetCallingConv.h:27
llvm::MipsSubtarget
Definition: MipsSubtarget.h:39
Callee
amdgpu Simplify well known AMD library false FunctionCallee Callee
Definition: AMDGPULibCalls.cpp:206
llvm::GlobalAddressSDNode
Definition: SelectionDAGNodes.h:1718
llvm::MachineFunction::getFunction
Function & getFunction()
Return the LLVM function that this machine code represents.
Definition: MachineFunction.h:596
llvm::TargetLoweringBase::ArgListEntry::Ty
Type * Ty
Definition: TargetLowering.h:278
MipsCCState.h
llvm::is_sorted
bool is_sorted(R &&Range, Compare C)
Wrapper function around std::is_sorted to check if elements in a range R are sorted with respect to a...
Definition: STLExtras.h:1622
llvm::Function::arg_begin
arg_iterator arg_begin()
Definition: Function.h:749
llvm::EVT::getVectorElementType
EVT getVectorElementType() const
Given a vector type, return the type of each element.
Definition: ValueTypes.h:301
llvm::Type::isStructTy
bool isStructTy() const
True if this is an instance of StructType.
Definition: Type.h:211
MipsSubtarget.h
llvm::MipsISD::Ins
@ Ins
Definition: MipsISelLowering.h:157
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:43
llvm::MipsCCState::isF128SoftLibCall
static bool isF128SoftLibCall(const char *CallSym)
This function returns true if CallSym is a long double emulation routine.
Definition: MipsCCState.cpp:15
llvm::MipsCCState::PreAnalyzeCallOperand
void PreAnalyzeCallOperand(const Type *ArgTy, bool IsFixed, const char *Func)
Definition: MipsCCState.cpp:133
llvm::Type::isFP128Ty
bool isFP128Ty() const
Return true if this is 'fp128'.
Definition: Type.h:156
llvm::EVT::isFloatingPoint
bool isFloatingPoint() const
Return true if this is a FP or a vector FP type.
Definition: ValueTypes.h:140
llvm::MipsSubtarget::inMips16HardFloat
bool inMips16HardFloat() const
Definition: MipsSubtarget.h:308