1 //===-- PPCMachineFunctionInfo.cpp - Private data used for PowerPC --------===//
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 //===----------------------------------------------------------------------===//
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"
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
);
22 void PPCFunctionInfo::anchor() {}
23 PPCFunctionInfo::PPCFunctionInfo(const MachineFunction
&MF
)
24 : DisableNonVolatileCR(PPCDisableNonVolatileCR
) {}
26 MCSymbol
*PPCFunctionInfo::getPICOffsetSymbol(MachineFunction
&MF
) const {
27 const DataLayout
&DL
= MF
.getDataLayout();
28 return MF
.getContext().getOrCreateSymbol(Twine(DL
.getPrivateGlobalPrefix()) +
29 Twine(MF
.getFunctionNumber()) +
33 MCSymbol
*PPCFunctionInfo::getGlobalEPSymbol(MachineFunction
&MF
) const {
34 const DataLayout
&DL
= MF
.getDataLayout();
35 return MF
.getContext().getOrCreateSymbol(Twine(DL
.getPrivateGlobalPrefix()) +
37 Twine(MF
.getFunctionNumber()));
40 MCSymbol
*PPCFunctionInfo::getLocalEPSymbol(MachineFunction
&MF
) const {
41 const DataLayout
&DL
= MF
.getDataLayout();
42 return MF
.getContext().getOrCreateSymbol(Twine(DL
.getPrivateGlobalPrefix()) +
44 Twine(MF
.getFunctionNumber()));
47 MCSymbol
*PPCFunctionInfo::getTOCOffsetSymbol(MachineFunction
&MF
) const {
48 const DataLayout
&DL
= MF
.getDataLayout();
49 return MF
.getContext().getOrCreateSymbol(Twine(DL
.getPrivateGlobalPrefix()) +
51 Twine(MF
.getFunctionNumber()));
54 bool PPCFunctionInfo::isLiveInSExt(Register VReg
) const {
55 for (const std::pair
<Register
, ISD::ArgFlagsTy
> &LiveIn
: LiveInAttrs
)
56 if (LiveIn
.first
== VReg
)
57 return LiveIn
.second
.isSExt();
61 bool PPCFunctionInfo::isLiveInZExt(Register VReg
) const {
62 for (const std::pair
<Register
, ISD::ArgFlagsTy
> &LiveIn
: LiveInAttrs
)
63 if (LiveIn
.first
== VReg
)
64 return LiveIn
.second
.isZExt();
68 void PPCFunctionInfo::appendParameterType(ParamType Type
) {
70 ParamtersType
.push_back(Type
);
75 case ShortFloatingPoint
:
76 case LongFloatingPoint
:
86 llvm_unreachable("Error ParamType type.");
89 uint32_t PPCFunctionInfo::getVecExtParmsType() const {
91 uint32_t VectExtParamInfo
= 0;
92 unsigned ShiftBits
= 32 - XCOFF::TracebackTable::WidthOfParamType
;
95 if (!hasVectorParms())
98 for (const auto &Elt
: ParamtersType
) {
101 VectExtParamInfo
<<= XCOFF::TracebackTable::WidthOfParamType
;
103 XCOFF::TracebackTable::ParmTypeIsVectorCharBit
>> ShiftBits
;
104 Bits
+= XCOFF::TracebackTable::WidthOfParamType
;
107 VectExtParamInfo
<<= XCOFF::TracebackTable::WidthOfParamType
;
109 XCOFF::TracebackTable::ParmTypeIsVectorShortBit
>> ShiftBits
;
110 Bits
+= XCOFF::TracebackTable::WidthOfParamType
;
113 VectExtParamInfo
<<= XCOFF::TracebackTable::WidthOfParamType
;
115 XCOFF::TracebackTable::ParmTypeIsVectorIntBit
>> ShiftBits
;
116 Bits
+= XCOFF::TracebackTable::WidthOfParamType
;
119 VectExtParamInfo
<<= XCOFF::TracebackTable::WidthOfParamType
;
121 XCOFF::TracebackTable::ParmTypeIsVectorFloatBit
>> ShiftBits
;
122 Bits
+= XCOFF::TracebackTable::WidthOfParamType
;
128 // There are only 32bits in the VectExtParamInfo.
132 return Bits
< 32 ? VectExtParamInfo
<< (32 - Bits
) : VectExtParamInfo
;
135 uint32_t PPCFunctionInfo::getParmsType() const {
136 uint32_t ParamsTypeInfo
= 0;
137 unsigned ShiftBits
= 32 - XCOFF::TracebackTable::WidthOfParamType
;
140 for (const auto &Elt
: ParamtersType
) {
142 if (Bits
> 31 || (Bits
> 30 && (Elt
!= FixedType
|| hasVectorParms())))
147 if (hasVectorParms()) {
148 //'00' ==> fixed parameter if HasVectorParms is true.
149 ParamsTypeInfo
<<= XCOFF::TracebackTable::WidthOfParamType
;
151 XCOFF::TracebackTable::ParmTypeIsFixedBits
>> ShiftBits
;
152 Bits
+= XCOFF::TracebackTable::WidthOfParamType
;
154 //'0' ==> fixed parameter if HasVectorParms is false.
155 ParamsTypeInfo
<<= 1;
159 case ShortFloatingPoint
:
160 // '10'b => floating point short parameter.
161 ParamsTypeInfo
<<= XCOFF::TracebackTable::WidthOfParamType
;
163 XCOFF::TracebackTable::ParmTypeIsFloatingBits
>> ShiftBits
;
164 Bits
+= XCOFF::TracebackTable::WidthOfParamType
;
166 case LongFloatingPoint
:
167 // '11'b => floating point long parameter.
168 ParamsTypeInfo
<<= XCOFF::TracebackTable::WidthOfParamType
;
170 XCOFF::TracebackTable::ParmTypeIsDoubleBits
>> ShiftBits
;
171 Bits
+= XCOFF::TracebackTable::WidthOfParamType
;
177 // '01' ==> vector parameter
178 ParamsTypeInfo
<<= XCOFF::TracebackTable::WidthOfParamType
;
180 XCOFF::TracebackTable::ParmTypeIsVectorBits
>> ShiftBits
;
181 Bits
+= XCOFF::TracebackTable::WidthOfParamType
;
186 return Bits
< 32 ? ParamsTypeInfo
<< (32 - Bits
) : ParamsTypeInfo
;