1*0b57cec5SDimitry Andric //===-- PPCMachineFunctionInfo.cpp - Private data used for PowerPC --------===//
2*0b57cec5SDimitry Andric //
3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*0b57cec5SDimitry Andric //
7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
8*0b57cec5SDimitry Andric
9*0b57cec5SDimitry Andric #include "PPCMachineFunctionInfo.h"
10*0b57cec5SDimitry Andric #include "llvm/ADT/Twine.h"
11*0b57cec5SDimitry Andric #include "llvm/BinaryFormat/XCOFF.h"
12*0b57cec5SDimitry Andric #include "llvm/IR/DataLayout.h"
13*0b57cec5SDimitry Andric #include "llvm/MC/MCContext.h"
14*0b57cec5SDimitry Andric #include "llvm/Support/CommandLine.h"
15*0b57cec5SDimitry Andric
16*0b57cec5SDimitry Andric using namespace llvm;
17*0b57cec5SDimitry Andric static cl::opt<bool> PPCDisableNonVolatileCR(
18*0b57cec5SDimitry Andric "ppc-disable-non-volatile-cr",
19*0b57cec5SDimitry Andric cl::desc("Disable the use of non-volatile CR register fields"),
20*0b57cec5SDimitry Andric cl::init(false), cl::Hidden);
21*0b57cec5SDimitry Andric
anchor()22*0b57cec5SDimitry Andric void PPCFunctionInfo::anchor() {}
PPCFunctionInfo(const Function & F,const TargetSubtargetInfo * STI)23*0b57cec5SDimitry Andric PPCFunctionInfo::PPCFunctionInfo(const Function &F,
24*0b57cec5SDimitry Andric const TargetSubtargetInfo *STI)
25*0b57cec5SDimitry Andric : DisableNonVolatileCR(PPCDisableNonVolatileCR) {}
26*0b57cec5SDimitry Andric
27*0b57cec5SDimitry Andric MachineFunctionInfo *
clone(BumpPtrAllocator & Allocator,MachineFunction & DestMF,const DenseMap<MachineBasicBlock *,MachineBasicBlock * > & Src2DstMBB) const28*0b57cec5SDimitry Andric PPCFunctionInfo::clone(BumpPtrAllocator &Allocator, MachineFunction &DestMF,
29*0b57cec5SDimitry Andric const DenseMap<MachineBasicBlock *, MachineBasicBlock *>
30*0b57cec5SDimitry Andric &Src2DstMBB) const {
31*0b57cec5SDimitry Andric return DestMF.cloneInfo<PPCFunctionInfo>(*this);
32*0b57cec5SDimitry Andric }
33*0b57cec5SDimitry Andric
getPICOffsetSymbol(MachineFunction & MF) const34*0b57cec5SDimitry Andric MCSymbol *PPCFunctionInfo::getPICOffsetSymbol(MachineFunction &MF) const {
35*0b57cec5SDimitry Andric const DataLayout &DL = MF.getDataLayout();
36*0b57cec5SDimitry Andric return MF.getContext().getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) +
37*0b57cec5SDimitry Andric Twine(MF.getFunctionNumber()) +
38*0b57cec5SDimitry Andric "$poff");
39*0b57cec5SDimitry Andric }
40*0b57cec5SDimitry Andric
getGlobalEPSymbol(MachineFunction & MF) const41*0b57cec5SDimitry Andric MCSymbol *PPCFunctionInfo::getGlobalEPSymbol(MachineFunction &MF) const {
42*0b57cec5SDimitry Andric const DataLayout &DL = MF.getDataLayout();
43*0b57cec5SDimitry Andric return MF.getContext().getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) +
44*0b57cec5SDimitry Andric "func_gep" +
45*0b57cec5SDimitry Andric Twine(MF.getFunctionNumber()));
46*0b57cec5SDimitry Andric }
47*0b57cec5SDimitry Andric
getLocalEPSymbol(MachineFunction & MF) const48*0b57cec5SDimitry Andric MCSymbol *PPCFunctionInfo::getLocalEPSymbol(MachineFunction &MF) const {
49*0b57cec5SDimitry Andric const DataLayout &DL = MF.getDataLayout();
50*0b57cec5SDimitry Andric return MF.getContext().getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) +
51*0b57cec5SDimitry Andric "func_lep" +
52*0b57cec5SDimitry Andric Twine(MF.getFunctionNumber()));
53*0b57cec5SDimitry Andric }
54*0b57cec5SDimitry Andric
getTOCOffsetSymbol(MachineFunction & MF) const55*0b57cec5SDimitry Andric MCSymbol *PPCFunctionInfo::getTOCOffsetSymbol(MachineFunction &MF) const {
56*0b57cec5SDimitry Andric const DataLayout &DL = MF.getDataLayout();
57*0b57cec5SDimitry Andric return MF.getContext().getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) +
58*0b57cec5SDimitry Andric "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