1 //===-- PPCMachineFunctionInfo.cpp - Private data used for PowerPC --------===//
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 "PPCMachineFunctionInfo.h"
10 #include "llvm/ADT/Twine.h"
11 #include "llvm/BinaryFormat/XCOFF.h"
12 #include "llvm/IR/DataLayout.h"
13 #include "llvm/MC/MCContext.h"
14 #include "llvm/Support/CommandLine.h"
15
16 using namespace llvm;
17 static cl::opt<bool> PPCDisableNonVolatileCR(
18 "ppc-disable-non-volatile-cr",
19 cl::desc("Disable the use of non-volatile CR register fields"),
20 cl::init(false), cl::Hidden);
21
anchor()22 void PPCFunctionInfo::anchor() {}
PPCFunctionInfo(const Function & F,const TargetSubtargetInfo * STI)23 PPCFunctionInfo::PPCFunctionInfo(const Function &F,
24 const TargetSubtargetInfo *STI)
25 : DisableNonVolatileCR(PPCDisableNonVolatileCR) {}
26
27 MachineFunctionInfo *
clone(BumpPtrAllocator & Allocator,MachineFunction & DestMF,const DenseMap<MachineBasicBlock *,MachineBasicBlock * > & Src2DstMBB) const28 PPCFunctionInfo::clone(BumpPtrAllocator &Allocator, MachineFunction &DestMF,
29 const DenseMap<MachineBasicBlock *, MachineBasicBlock *>
30 &Src2DstMBB) const {
31 return DestMF.cloneInfo<PPCFunctionInfo>(*this);
32 }
33
getPICOffsetSymbol(MachineFunction & MF) const34 MCSymbol *PPCFunctionInfo::getPICOffsetSymbol(MachineFunction &MF) const {
35 const DataLayout &DL = MF.getDataLayout();
36 return MF.getContext().getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) +
37 Twine(MF.getFunctionNumber()) +
38 "$poff");
39 }
40
getGlobalEPSymbol(MachineFunction & MF) const41 MCSymbol *PPCFunctionInfo::getGlobalEPSymbol(MachineFunction &MF) const {
42 const DataLayout &DL = MF.getDataLayout();
43 return MF.getContext().getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) +
44 "func_gep" +
45 Twine(MF.getFunctionNumber()));
46 }
47
getLocalEPSymbol(MachineFunction & MF) const48 MCSymbol *PPCFunctionInfo::getLocalEPSymbol(MachineFunction &MF) const {
49 const DataLayout &DL = MF.getDataLayout();
50 return MF.getContext().getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) +
51 "func_lep" +
52 Twine(MF.getFunctionNumber()));
53 }
54
getTOCOffsetSymbol(MachineFunction & MF) const55 MCSymbol *PPCFunctionInfo::getTOCOffsetSymbol(MachineFunction &MF) const {
56 const DataLayout &DL = MF.getDataLayout();
57 return MF.getContext().getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) +
58 "func_toc" +
59 Twine(MF.getFunctionNumber()));
60 }
61
isLiveInSExt(Register VReg) const62 bool PPCFunctionInfo::isLiveInSExt(Register VReg) const {
63 for (const std::pair<Register, ISD::ArgFlagsTy> &LiveIn : LiveInAttrs)
64 if (LiveIn.first == VReg)
65 return LiveIn.second.isSExt();
66 return false;
67 }
68
isLiveInZExt(Register VReg) const69 bool PPCFunctionInfo::isLiveInZExt(Register VReg) const {
70 for (const std::pair<Register, ISD::ArgFlagsTy> &LiveIn : LiveInAttrs)
71 if (LiveIn.first == VReg)
72 return LiveIn.second.isZExt();
73 return false;
74 }
75
appendParameterType(ParamType Type)76 void PPCFunctionInfo::appendParameterType(ParamType Type) {
77
78 ParamtersType.push_back(Type);
79 switch (Type) {
80 case FixedType:
81 ++FixedParmsNum;
82 return;
83 case ShortFloatingPoint:
84 case LongFloatingPoint:
85 ++FloatingParmsNum;
86 return;
87 case VectorChar:
88 case VectorShort:
89 case VectorInt:
90 case VectorFloat:
91 ++VectorParmsNum;
92 return;
93 }
94 llvm_unreachable("Error ParamType type.");
95 }
96
getVecExtParmsType() const97 uint32_t PPCFunctionInfo::getVecExtParmsType() const {
98
99 uint32_t VectExtParamInfo = 0;
100 unsigned ShiftBits = 32 - XCOFF::TracebackTable::WidthOfParamType;
101 int Bits = 0;
102
103 if (!hasVectorParms())
104 return 0;
105
106 for (const auto &Elt : ParamtersType) {
107 switch (Elt) {
108 case VectorChar:
109 VectExtParamInfo <<= XCOFF::TracebackTable::WidthOfParamType;
110 VectExtParamInfo |=
111 XCOFF::TracebackTable::ParmTypeIsVectorCharBit >> ShiftBits;
112 Bits += XCOFF::TracebackTable::WidthOfParamType;
113 break;
114 case VectorShort:
115 VectExtParamInfo <<= XCOFF::TracebackTable::WidthOfParamType;
116 VectExtParamInfo |=
117 XCOFF::TracebackTable::ParmTypeIsVectorShortBit >> ShiftBits;
118 Bits += XCOFF::TracebackTable::WidthOfParamType;
119 break;
120 case VectorInt:
121 VectExtParamInfo <<= XCOFF::TracebackTable::WidthOfParamType;
122 VectExtParamInfo |=
123 XCOFF::TracebackTable::ParmTypeIsVectorIntBit >> ShiftBits;
124 Bits += XCOFF::TracebackTable::WidthOfParamType;
125 break;
126 case VectorFloat:
127 VectExtParamInfo <<= XCOFF::TracebackTable::WidthOfParamType;
128 VectExtParamInfo |=
129 XCOFF::TracebackTable::ParmTypeIsVectorFloatBit >> ShiftBits;
130 Bits += XCOFF::TracebackTable::WidthOfParamType;
131 break;
132 default:
133 break;
134 }
135
136 // There are only 32bits in the VectExtParamInfo.
137 if (Bits >= 32)
138 break;
139 }
140 return Bits < 32 ? VectExtParamInfo << (32 - Bits) : VectExtParamInfo;
141 }
142
getParmsType() const143 uint32_t PPCFunctionInfo::getParmsType() const {
144 uint32_t ParamsTypeInfo = 0;
145 unsigned ShiftBits = 32 - XCOFF::TracebackTable::WidthOfParamType;
146
147 int Bits = 0;
148 for (const auto &Elt : ParamtersType) {
149
150 if (Bits > 31 || (Bits > 30 && (Elt != FixedType || hasVectorParms())))
151 break;
152
153 switch (Elt) {
154 case FixedType:
155 if (hasVectorParms()) {
156 //'00' ==> fixed parameter if HasVectorParms is true.
157 ParamsTypeInfo <<= XCOFF::TracebackTable::WidthOfParamType;
158 ParamsTypeInfo |=
159 XCOFF::TracebackTable::ParmTypeIsFixedBits >> ShiftBits;
160 Bits += XCOFF::TracebackTable::WidthOfParamType;
161 } else {
162 //'0' ==> fixed parameter if HasVectorParms is false.
163 ParamsTypeInfo <<= 1;
164 ++Bits;
165 }
166 break;
167 case ShortFloatingPoint:
168 // '10'b => floating point short parameter.
169 ParamsTypeInfo <<= XCOFF::TracebackTable::WidthOfParamType;
170 ParamsTypeInfo |=
171 XCOFF::TracebackTable::ParmTypeIsFloatingBits >> ShiftBits;
172 Bits += XCOFF::TracebackTable::WidthOfParamType;
173 break;
174 case LongFloatingPoint:
175 // '11'b => floating point long parameter.
176 ParamsTypeInfo <<= XCOFF::TracebackTable::WidthOfParamType;
177 ParamsTypeInfo |=
178 XCOFF::TracebackTable::ParmTypeIsDoubleBits >> ShiftBits;
179 Bits += XCOFF::TracebackTable::WidthOfParamType;
180 break;
181 case VectorChar:
182 case VectorShort:
183 case VectorInt:
184 case VectorFloat:
185 // '01' ==> vector parameter
186 ParamsTypeInfo <<= XCOFF::TracebackTable::WidthOfParamType;
187 ParamsTypeInfo |=
188 XCOFF::TracebackTable::ParmTypeIsVectorBits >> ShiftBits;
189 Bits += XCOFF::TracebackTable::WidthOfParamType;
190 break;
191 }
192 }
193
194 return Bits < 32 ? ParamsTypeInfo << (32 - Bits) : ParamsTypeInfo;
195 }
196