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 Function
&F
,
24 const TargetSubtargetInfo
*STI
)
25 : DisableNonVolatileCR(PPCDisableNonVolatileCR
) {}
28 PPCFunctionInfo::clone(BumpPtrAllocator
&Allocator
, MachineFunction
&DestMF
,
29 const DenseMap
<MachineBasicBlock
*, MachineBasicBlock
*>
31 return DestMF
.cloneInfo
<PPCFunctionInfo
>(*this);
34 MCSymbol
*PPCFunctionInfo::getPICOffsetSymbol(MachineFunction
&MF
) const {
35 const DataLayout
&DL
= MF
.getDataLayout();
36 return MF
.getContext().getOrCreateSymbol(Twine(DL
.getPrivateGlobalPrefix()) +
37 Twine(MF
.getFunctionNumber()) +
41 MCSymbol
*PPCFunctionInfo::getGlobalEPSymbol(MachineFunction
&MF
) const {
42 const DataLayout
&DL
= MF
.getDataLayout();
43 return MF
.getContext().getOrCreateSymbol(Twine(DL
.getPrivateGlobalPrefix()) +
45 Twine(MF
.getFunctionNumber()));
48 MCSymbol
*PPCFunctionInfo::getLocalEPSymbol(MachineFunction
&MF
) const {
49 const DataLayout
&DL
= MF
.getDataLayout();
50 return MF
.getContext().getOrCreateSymbol(Twine(DL
.getPrivateGlobalPrefix()) +
52 Twine(MF
.getFunctionNumber()));
55 MCSymbol
*PPCFunctionInfo::getTOCOffsetSymbol(MachineFunction
&MF
) const {
56 const DataLayout
&DL
= MF
.getDataLayout();
57 return MF
.getContext().getOrCreateSymbol(Twine(DL
.getPrivateGlobalPrefix()) +
59 Twine(MF
.getFunctionNumber()));
62 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();
69 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();
76 void PPCFunctionInfo::appendParameterType(ParamType Type
) {
78 ParamtersType
.push_back(Type
);
83 case ShortFloatingPoint
:
84 case LongFloatingPoint
:
94 llvm_unreachable("Error ParamType type.");
97 uint32_t PPCFunctionInfo::getVecExtParmsType() const {
99 uint32_t VectExtParamInfo
= 0;
100 unsigned ShiftBits
= 32 - XCOFF::TracebackTable::WidthOfParamType
;
103 if (!hasVectorParms())
106 for (const auto &Elt
: ParamtersType
) {
109 VectExtParamInfo
<<= XCOFF::TracebackTable::WidthOfParamType
;
111 XCOFF::TracebackTable::ParmTypeIsVectorCharBit
>> ShiftBits
;
112 Bits
+= XCOFF::TracebackTable::WidthOfParamType
;
115 VectExtParamInfo
<<= XCOFF::TracebackTable::WidthOfParamType
;
117 XCOFF::TracebackTable::ParmTypeIsVectorShortBit
>> ShiftBits
;
118 Bits
+= XCOFF::TracebackTable::WidthOfParamType
;
121 VectExtParamInfo
<<= XCOFF::TracebackTable::WidthOfParamType
;
123 XCOFF::TracebackTable::ParmTypeIsVectorIntBit
>> ShiftBits
;
124 Bits
+= XCOFF::TracebackTable::WidthOfParamType
;
127 VectExtParamInfo
<<= XCOFF::TracebackTable::WidthOfParamType
;
129 XCOFF::TracebackTable::ParmTypeIsVectorFloatBit
>> ShiftBits
;
130 Bits
+= XCOFF::TracebackTable::WidthOfParamType
;
136 // There are only 32bits in the VectExtParamInfo.
140 return Bits
< 32 ? VectExtParamInfo
<< (32 - Bits
) : VectExtParamInfo
;
143 uint32_t PPCFunctionInfo::getParmsType() const {
144 uint32_t ParamsTypeInfo
= 0;
145 unsigned ShiftBits
= 32 - XCOFF::TracebackTable::WidthOfParamType
;
148 for (const auto &Elt
: ParamtersType
) {
150 if (Bits
> 31 || (Bits
> 30 && (Elt
!= FixedType
|| hasVectorParms())))
155 if (hasVectorParms()) {
156 //'00' ==> fixed parameter if HasVectorParms is true.
157 ParamsTypeInfo
<<= XCOFF::TracebackTable::WidthOfParamType
;
159 XCOFF::TracebackTable::ParmTypeIsFixedBits
>> ShiftBits
;
160 Bits
+= XCOFF::TracebackTable::WidthOfParamType
;
162 //'0' ==> fixed parameter if HasVectorParms is false.
163 ParamsTypeInfo
<<= 1;
167 case ShortFloatingPoint
:
168 // '10'b => floating point short parameter.
169 ParamsTypeInfo
<<= XCOFF::TracebackTable::WidthOfParamType
;
171 XCOFF::TracebackTable::ParmTypeIsFloatingBits
>> ShiftBits
;
172 Bits
+= XCOFF::TracebackTable::WidthOfParamType
;
174 case LongFloatingPoint
:
175 // '11'b => floating point long parameter.
176 ParamsTypeInfo
<<= XCOFF::TracebackTable::WidthOfParamType
;
178 XCOFF::TracebackTable::ParmTypeIsDoubleBits
>> ShiftBits
;
179 Bits
+= XCOFF::TracebackTable::WidthOfParamType
;
185 // '01' ==> vector parameter
186 ParamsTypeInfo
<<= XCOFF::TracebackTable::WidthOfParamType
;
188 XCOFF::TracebackTable::ParmTypeIsVectorBits
>> ShiftBits
;
189 Bits
+= XCOFF::TracebackTable::WidthOfParamType
;
194 return Bits
< 32 ? ParamsTypeInfo
<< (32 - Bits
) : ParamsTypeInfo
;