xref: /freebsd/contrib/llvm-project/llvm/lib/Target/PowerPC/PPCMachineFunctionInfo.cpp (revision e8d8bef961a50d4dc22501cde4fb9fb0be1b2532)
10b57cec5SDimitry Andric //===-- PPCMachineFunctionInfo.cpp - Private data used for PowerPC --------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric 
90b57cec5SDimitry Andric #include "PPCMachineFunctionInfo.h"
100b57cec5SDimitry Andric #include "llvm/ADT/Twine.h"
11*e8d8bef9SDimitry Andric #include "llvm/BinaryFormat/XCOFF.h"
120b57cec5SDimitry Andric #include "llvm/IR/DataLayout.h"
130b57cec5SDimitry Andric #include "llvm/MC/MCContext.h"
145ffd83dbSDimitry Andric #include "llvm/Support/CommandLine.h"
150b57cec5SDimitry Andric 
160b57cec5SDimitry Andric using namespace llvm;
175ffd83dbSDimitry Andric static cl::opt<bool> PPCDisableNonVolatileCR(
185ffd83dbSDimitry Andric     "ppc-disable-non-volatile-cr",
195ffd83dbSDimitry Andric     cl::desc("Disable the use of non-volatile CR register fields"),
205ffd83dbSDimitry Andric     cl::init(false), cl::Hidden);
210b57cec5SDimitry Andric 
220b57cec5SDimitry Andric void PPCFunctionInfo::anchor() {}
235ffd83dbSDimitry Andric PPCFunctionInfo::PPCFunctionInfo(const MachineFunction &MF)
245ffd83dbSDimitry Andric     : DisableNonVolatileCR(PPCDisableNonVolatileCR) {}
250b57cec5SDimitry Andric 
265ffd83dbSDimitry Andric MCSymbol *PPCFunctionInfo::getPICOffsetSymbol(MachineFunction &MF) const {
270b57cec5SDimitry Andric   const DataLayout &DL = MF.getDataLayout();
280b57cec5SDimitry Andric   return MF.getContext().getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) +
290b57cec5SDimitry Andric                                            Twine(MF.getFunctionNumber()) +
300b57cec5SDimitry Andric                                            "$poff");
310b57cec5SDimitry Andric }
320b57cec5SDimitry Andric 
335ffd83dbSDimitry Andric MCSymbol *PPCFunctionInfo::getGlobalEPSymbol(MachineFunction &MF) const {
340b57cec5SDimitry Andric   const DataLayout &DL = MF.getDataLayout();
350b57cec5SDimitry Andric   return MF.getContext().getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) +
360b57cec5SDimitry Andric                                            "func_gep" +
370b57cec5SDimitry Andric                                            Twine(MF.getFunctionNumber()));
380b57cec5SDimitry Andric }
390b57cec5SDimitry Andric 
405ffd83dbSDimitry Andric MCSymbol *PPCFunctionInfo::getLocalEPSymbol(MachineFunction &MF) const {
410b57cec5SDimitry Andric   const DataLayout &DL = MF.getDataLayout();
420b57cec5SDimitry Andric   return MF.getContext().getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) +
430b57cec5SDimitry Andric                                            "func_lep" +
440b57cec5SDimitry Andric                                            Twine(MF.getFunctionNumber()));
450b57cec5SDimitry Andric }
460b57cec5SDimitry Andric 
475ffd83dbSDimitry Andric MCSymbol *PPCFunctionInfo::getTOCOffsetSymbol(MachineFunction &MF) const {
480b57cec5SDimitry Andric   const DataLayout &DL = MF.getDataLayout();
490b57cec5SDimitry Andric   return MF.getContext().getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) +
500b57cec5SDimitry Andric                                            "func_toc" +
510b57cec5SDimitry Andric                                            Twine(MF.getFunctionNumber()));
520b57cec5SDimitry Andric }
530b57cec5SDimitry Andric 
545ffd83dbSDimitry Andric bool PPCFunctionInfo::isLiveInSExt(Register VReg) const {
555ffd83dbSDimitry Andric   for (const std::pair<Register, ISD::ArgFlagsTy> &LiveIn : LiveInAttrs)
560b57cec5SDimitry Andric     if (LiveIn.first == VReg)
570b57cec5SDimitry Andric       return LiveIn.second.isSExt();
580b57cec5SDimitry Andric   return false;
590b57cec5SDimitry Andric }
600b57cec5SDimitry Andric 
615ffd83dbSDimitry Andric bool PPCFunctionInfo::isLiveInZExt(Register VReg) const {
625ffd83dbSDimitry Andric   for (const std::pair<Register, ISD::ArgFlagsTy> &LiveIn : LiveInAttrs)
630b57cec5SDimitry Andric     if (LiveIn.first == VReg)
640b57cec5SDimitry Andric       return LiveIn.second.isZExt();
650b57cec5SDimitry Andric   return false;
660b57cec5SDimitry Andric }
67*e8d8bef9SDimitry Andric 
68*e8d8bef9SDimitry Andric void PPCFunctionInfo::appendParameterType(ParamType Type) {
69*e8d8bef9SDimitry Andric   uint32_t CopyParamType = ParameterType;
70*e8d8bef9SDimitry Andric   int Bits = 0;
71*e8d8bef9SDimitry Andric 
72*e8d8bef9SDimitry Andric   // If it is fixed type, we only need to increase the FixedParamNum, for
73*e8d8bef9SDimitry Andric   // the bit encode of fixed type is bit of zero, we do not need to change the
74*e8d8bef9SDimitry Andric   // ParamType.
75*e8d8bef9SDimitry Andric   if (Type == FixedType) {
76*e8d8bef9SDimitry Andric     ++FixedParamNum;
77*e8d8bef9SDimitry Andric     return;
78*e8d8bef9SDimitry Andric   }
79*e8d8bef9SDimitry Andric 
80*e8d8bef9SDimitry Andric   ++FloatingPointParamNum;
81*e8d8bef9SDimitry Andric 
82*e8d8bef9SDimitry Andric   for (int I = 0;
83*e8d8bef9SDimitry Andric        I < static_cast<int>(FloatingPointParamNum + FixedParamNum - 1); ++I) {
84*e8d8bef9SDimitry Andric     if (CopyParamType & XCOFF::TracebackTable::ParmTypeIsFloatingBit) {
85*e8d8bef9SDimitry Andric       // '10'b => floating point short parameter.
86*e8d8bef9SDimitry Andric       // '11'b => floating point long parameter.
87*e8d8bef9SDimitry Andric       CopyParamType <<= 2;
88*e8d8bef9SDimitry Andric       Bits += 2;
89*e8d8bef9SDimitry Andric     } else {
90*e8d8bef9SDimitry Andric       // '0'b => fixed parameter.
91*e8d8bef9SDimitry Andric       CopyParamType <<= 1;
92*e8d8bef9SDimitry Andric       ++Bits;
93*e8d8bef9SDimitry Andric     }
94*e8d8bef9SDimitry Andric   }
95*e8d8bef9SDimitry Andric 
96*e8d8bef9SDimitry Andric   assert(Type != FixedType && "FixedType should already be handled.");
97*e8d8bef9SDimitry Andric   if (Bits < 31)
98*e8d8bef9SDimitry Andric     ParameterType |= Type << (30 - Bits);
99*e8d8bef9SDimitry Andric }
100