xref: /src/contrib/llvm-project/llvm/lib/Target/PowerPC/PPCMachineFunctionInfo.cpp (revision bdd1243df58e60e85101c09001d9812a789b6bc4)
163faed5bSDimitry Andric //===-- PPCMachineFunctionInfo.cpp - Private data used for PowerPC --------===//
263faed5bSDimitry Andric //
3e6d15924SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4e6d15924SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5e6d15924SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
663faed5bSDimitry Andric //
763faed5bSDimitry Andric //===----------------------------------------------------------------------===//
863faed5bSDimitry Andric 
963faed5bSDimitry Andric #include "PPCMachineFunctionInfo.h"
1071d5a254SDimitry Andric #include "llvm/ADT/Twine.h"
11b60736ecSDimitry Andric #include "llvm/BinaryFormat/XCOFF.h"
125ca98fd9SDimitry Andric #include "llvm/IR/DataLayout.h"
135ca98fd9SDimitry Andric #include "llvm/MC/MCContext.h"
14cfca06d7SDimitry Andric #include "llvm/Support/CommandLine.h"
1563faed5bSDimitry Andric 
1663faed5bSDimitry Andric using namespace llvm;
17cfca06d7SDimitry Andric static cl::opt<bool> PPCDisableNonVolatileCR(
18cfca06d7SDimitry Andric     "ppc-disable-non-volatile-cr",
19cfca06d7SDimitry Andric     cl::desc("Disable the use of non-volatile CR register fields"),
20cfca06d7SDimitry Andric     cl::init(false), cl::Hidden);
2163faed5bSDimitry Andric 
anchor()2263faed5bSDimitry Andric void PPCFunctionInfo::anchor() {}
PPCFunctionInfo(const Function & F,const TargetSubtargetInfo * STI)23e3b55780SDimitry Andric PPCFunctionInfo::PPCFunctionInfo(const Function &F,
24e3b55780SDimitry Andric                                  const TargetSubtargetInfo *STI)
25cfca06d7SDimitry Andric     : DisableNonVolatileCR(PPCDisableNonVolatileCR) {}
2663faed5bSDimitry Andric 
27145449b1SDimitry Andric MachineFunctionInfo *
clone(BumpPtrAllocator & Allocator,MachineFunction & DestMF,const DenseMap<MachineBasicBlock *,MachineBasicBlock * > & Src2DstMBB) const28145449b1SDimitry Andric PPCFunctionInfo::clone(BumpPtrAllocator &Allocator, MachineFunction &DestMF,
29145449b1SDimitry Andric                        const DenseMap<MachineBasicBlock *, MachineBasicBlock *>
30145449b1SDimitry Andric                            &Src2DstMBB) const {
31145449b1SDimitry Andric   return DestMF.cloneInfo<PPCFunctionInfo>(*this);
32145449b1SDimitry Andric }
33145449b1SDimitry Andric 
getPICOffsetSymbol(MachineFunction & MF) const34cfca06d7SDimitry Andric MCSymbol *PPCFunctionInfo::getPICOffsetSymbol(MachineFunction &MF) const {
35dd58ef01SDimitry Andric   const DataLayout &DL = MF.getDataLayout();
36dd58ef01SDimitry Andric   return MF.getContext().getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) +
375a5ac124SDimitry Andric                                            Twine(MF.getFunctionNumber()) +
385a5ac124SDimitry Andric                                            "$poff");
395ca98fd9SDimitry Andric }
40050e163aSDimitry Andric 
getGlobalEPSymbol(MachineFunction & MF) const41cfca06d7SDimitry Andric MCSymbol *PPCFunctionInfo::getGlobalEPSymbol(MachineFunction &MF) const {
42050e163aSDimitry Andric   const DataLayout &DL = MF.getDataLayout();
43050e163aSDimitry Andric   return MF.getContext().getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) +
44050e163aSDimitry Andric                                            "func_gep" +
45050e163aSDimitry Andric                                            Twine(MF.getFunctionNumber()));
46050e163aSDimitry Andric }
47050e163aSDimitry Andric 
getLocalEPSymbol(MachineFunction & MF) const48cfca06d7SDimitry Andric MCSymbol *PPCFunctionInfo::getLocalEPSymbol(MachineFunction &MF) const {
49050e163aSDimitry Andric   const DataLayout &DL = MF.getDataLayout();
50050e163aSDimitry Andric   return MF.getContext().getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) +
51050e163aSDimitry Andric                                            "func_lep" +
52050e163aSDimitry Andric                                            Twine(MF.getFunctionNumber()));
53050e163aSDimitry Andric }
54050e163aSDimitry Andric 
getTOCOffsetSymbol(MachineFunction & MF) const55cfca06d7SDimitry Andric MCSymbol *PPCFunctionInfo::getTOCOffsetSymbol(MachineFunction &MF) const {
56050e163aSDimitry Andric   const DataLayout &DL = MF.getDataLayout();
57050e163aSDimitry Andric   return MF.getContext().getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) +
58050e163aSDimitry Andric                                            "func_toc" +
59050e163aSDimitry Andric                                            Twine(MF.getFunctionNumber()));
60050e163aSDimitry Andric }
61044eb2f6SDimitry Andric 
isLiveInSExt(Register VReg) const62cfca06d7SDimitry Andric bool PPCFunctionInfo::isLiveInSExt(Register VReg) const {
63cfca06d7SDimitry Andric   for (const std::pair<Register, ISD::ArgFlagsTy> &LiveIn : LiveInAttrs)
64044eb2f6SDimitry Andric     if (LiveIn.first == VReg)
65044eb2f6SDimitry Andric       return LiveIn.second.isSExt();
66044eb2f6SDimitry Andric   return false;
67044eb2f6SDimitry Andric }
68044eb2f6SDimitry Andric 
isLiveInZExt(Register VReg) const69cfca06d7SDimitry Andric bool PPCFunctionInfo::isLiveInZExt(Register VReg) const {
70cfca06d7SDimitry Andric   for (const std::pair<Register, ISD::ArgFlagsTy> &LiveIn : LiveInAttrs)
71044eb2f6SDimitry Andric     if (LiveIn.first == VReg)
72044eb2f6SDimitry Andric       return LiveIn.second.isZExt();
73044eb2f6SDimitry Andric   return false;
74044eb2f6SDimitry Andric }
75b60736ecSDimitry Andric 
appendParameterType(ParamType Type)76b60736ecSDimitry Andric void PPCFunctionInfo::appendParameterType(ParamType Type) {
77b60736ecSDimitry Andric 
78344a3780SDimitry Andric   ParamtersType.push_back(Type);
79344a3780SDimitry Andric   switch (Type) {
80344a3780SDimitry Andric   case FixedType:
81344a3780SDimitry Andric     ++FixedParmsNum;
82344a3780SDimitry Andric     return;
83344a3780SDimitry Andric   case ShortFloatingPoint:
84344a3780SDimitry Andric   case LongFloatingPoint:
85344a3780SDimitry Andric     ++FloatingParmsNum;
86344a3780SDimitry Andric     return;
87344a3780SDimitry Andric   case VectorChar:
88344a3780SDimitry Andric   case VectorShort:
89344a3780SDimitry Andric   case VectorInt:
90344a3780SDimitry Andric   case VectorFloat:
91344a3780SDimitry Andric     ++VectorParmsNum;
92b60736ecSDimitry Andric     return;
93b60736ecSDimitry Andric   }
94344a3780SDimitry Andric   llvm_unreachable("Error ParamType type.");
95344a3780SDimitry Andric }
96b60736ecSDimitry Andric 
getVecExtParmsType() const97344a3780SDimitry Andric uint32_t PPCFunctionInfo::getVecExtParmsType() const {
98b60736ecSDimitry Andric 
99344a3780SDimitry Andric   uint32_t VectExtParamInfo = 0;
100344a3780SDimitry Andric   unsigned ShiftBits = 32 - XCOFF::TracebackTable::WidthOfParamType;
101344a3780SDimitry Andric   int Bits = 0;
102344a3780SDimitry Andric 
103344a3780SDimitry Andric   if (!hasVectorParms())
104344a3780SDimitry Andric     return 0;
105344a3780SDimitry Andric 
106344a3780SDimitry Andric   for (const auto &Elt : ParamtersType) {
107344a3780SDimitry Andric     switch (Elt) {
108344a3780SDimitry Andric     case VectorChar:
109344a3780SDimitry Andric       VectExtParamInfo <<= XCOFF::TracebackTable::WidthOfParamType;
110344a3780SDimitry Andric       VectExtParamInfo |=
111344a3780SDimitry Andric           XCOFF::TracebackTable::ParmTypeIsVectorCharBit >> ShiftBits;
112344a3780SDimitry Andric       Bits += XCOFF::TracebackTable::WidthOfParamType;
113344a3780SDimitry Andric       break;
114344a3780SDimitry Andric     case VectorShort:
115344a3780SDimitry Andric       VectExtParamInfo <<= XCOFF::TracebackTable::WidthOfParamType;
116344a3780SDimitry Andric       VectExtParamInfo |=
117344a3780SDimitry Andric           XCOFF::TracebackTable::ParmTypeIsVectorShortBit >> ShiftBits;
118344a3780SDimitry Andric       Bits += XCOFF::TracebackTable::WidthOfParamType;
119344a3780SDimitry Andric       break;
120344a3780SDimitry Andric     case VectorInt:
121344a3780SDimitry Andric       VectExtParamInfo <<= XCOFF::TracebackTable::WidthOfParamType;
122344a3780SDimitry Andric       VectExtParamInfo |=
123344a3780SDimitry Andric           XCOFF::TracebackTable::ParmTypeIsVectorIntBit >> ShiftBits;
124344a3780SDimitry Andric       Bits += XCOFF::TracebackTable::WidthOfParamType;
125344a3780SDimitry Andric       break;
126344a3780SDimitry Andric     case VectorFloat:
127344a3780SDimitry Andric       VectExtParamInfo <<= XCOFF::TracebackTable::WidthOfParamType;
128344a3780SDimitry Andric       VectExtParamInfo |=
129344a3780SDimitry Andric           XCOFF::TracebackTable::ParmTypeIsVectorFloatBit >> ShiftBits;
130344a3780SDimitry Andric       Bits += XCOFF::TracebackTable::WidthOfParamType;
131344a3780SDimitry Andric       break;
132344a3780SDimitry Andric     default:
133344a3780SDimitry Andric       break;
134344a3780SDimitry Andric     }
135344a3780SDimitry Andric 
136344a3780SDimitry Andric     // There are only 32bits in the VectExtParamInfo.
137344a3780SDimitry Andric     if (Bits >= 32)
138344a3780SDimitry Andric       break;
139344a3780SDimitry Andric   }
140344a3780SDimitry Andric   return Bits < 32 ? VectExtParamInfo << (32 - Bits) : VectExtParamInfo;
141344a3780SDimitry Andric }
142344a3780SDimitry Andric 
getParmsType() const143344a3780SDimitry Andric uint32_t PPCFunctionInfo::getParmsType() const {
144344a3780SDimitry Andric   uint32_t ParamsTypeInfo = 0;
145344a3780SDimitry Andric   unsigned ShiftBits = 32 - XCOFF::TracebackTable::WidthOfParamType;
146344a3780SDimitry Andric 
147344a3780SDimitry Andric   int Bits = 0;
148344a3780SDimitry Andric   for (const auto &Elt : ParamtersType) {
149344a3780SDimitry Andric 
150344a3780SDimitry Andric     if (Bits > 31 || (Bits > 30 && (Elt != FixedType || hasVectorParms())))
151344a3780SDimitry Andric       break;
152344a3780SDimitry Andric 
153344a3780SDimitry Andric     switch (Elt) {
154344a3780SDimitry Andric     case FixedType:
155344a3780SDimitry Andric       if (hasVectorParms()) {
156344a3780SDimitry Andric         //'00'  ==> fixed parameter if HasVectorParms is true.
157344a3780SDimitry Andric         ParamsTypeInfo <<= XCOFF::TracebackTable::WidthOfParamType;
158344a3780SDimitry Andric         ParamsTypeInfo |=
159344a3780SDimitry Andric             XCOFF::TracebackTable::ParmTypeIsFixedBits >> ShiftBits;
160344a3780SDimitry Andric         Bits += XCOFF::TracebackTable::WidthOfParamType;
161b60736ecSDimitry Andric       } else {
162344a3780SDimitry Andric         //'0'  ==> fixed parameter if HasVectorParms is false.
163344a3780SDimitry Andric         ParamsTypeInfo <<= 1;
164b60736ecSDimitry Andric         ++Bits;
165b60736ecSDimitry Andric       }
166344a3780SDimitry Andric       break;
167344a3780SDimitry Andric     case ShortFloatingPoint:
168344a3780SDimitry Andric       // '10'b => floating point short parameter.
169344a3780SDimitry Andric       ParamsTypeInfo <<= XCOFF::TracebackTable::WidthOfParamType;
170344a3780SDimitry Andric       ParamsTypeInfo |=
171344a3780SDimitry Andric           XCOFF::TracebackTable::ParmTypeIsFloatingBits >> ShiftBits;
172344a3780SDimitry Andric       Bits += XCOFF::TracebackTable::WidthOfParamType;
173344a3780SDimitry Andric       break;
174344a3780SDimitry Andric     case LongFloatingPoint:
175344a3780SDimitry Andric       // '11'b => floating point long parameter.
176344a3780SDimitry Andric       ParamsTypeInfo <<= XCOFF::TracebackTable::WidthOfParamType;
177344a3780SDimitry Andric       ParamsTypeInfo |=
178344a3780SDimitry Andric           XCOFF::TracebackTable::ParmTypeIsDoubleBits >> ShiftBits;
179344a3780SDimitry Andric       Bits += XCOFF::TracebackTable::WidthOfParamType;
180344a3780SDimitry Andric       break;
181344a3780SDimitry Andric     case VectorChar:
182344a3780SDimitry Andric     case VectorShort:
183344a3780SDimitry Andric     case VectorInt:
184344a3780SDimitry Andric     case VectorFloat:
185344a3780SDimitry Andric       //	'01' ==> vector parameter
186344a3780SDimitry Andric       ParamsTypeInfo <<= XCOFF::TracebackTable::WidthOfParamType;
187344a3780SDimitry Andric       ParamsTypeInfo |=
188344a3780SDimitry Andric           XCOFF::TracebackTable::ParmTypeIsVectorBits >> ShiftBits;
189344a3780SDimitry Andric       Bits += XCOFF::TracebackTable::WidthOfParamType;
190344a3780SDimitry Andric       break;
191344a3780SDimitry Andric     }
192b60736ecSDimitry Andric   }
193b60736ecSDimitry Andric 
194344a3780SDimitry Andric   return Bits < 32 ? ParamsTypeInfo << (32 - Bits) : ParamsTypeInfo;
195b60736ecSDimitry Andric }
196