Home | History | Annotate | Line # | Download | only in PowerPC
      1 //===-- PPCMachineFunctionInfo.cpp - Private data used for PowerPC --------===//
      2 //
      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
      6 //
      7 //===----------------------------------------------------------------------===//
      8 
      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"
     15 
     16 using namespace llvm;
     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);
     21 
     22 void PPCFunctionInfo::anchor() {}
     23 PPCFunctionInfo::PPCFunctionInfo(const MachineFunction &MF)
     24     : DisableNonVolatileCR(PPCDisableNonVolatileCR) {}
     25 
     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()) +
     30                                            "$poff");
     31 }
     32 
     33 MCSymbol *PPCFunctionInfo::getGlobalEPSymbol(MachineFunction &MF) const {
     34   const DataLayout &DL = MF.getDataLayout();
     35   return MF.getContext().getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) +
     36                                            "func_gep" +
     37                                            Twine(MF.getFunctionNumber()));
     38 }
     39 
     40 MCSymbol *PPCFunctionInfo::getLocalEPSymbol(MachineFunction &MF) const {
     41   const DataLayout &DL = MF.getDataLayout();
     42   return MF.getContext().getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) +
     43                                            "func_lep" +
     44                                            Twine(MF.getFunctionNumber()));
     45 }
     46 
     47 MCSymbol *PPCFunctionInfo::getTOCOffsetSymbol(MachineFunction &MF) const {
     48   const DataLayout &DL = MF.getDataLayout();
     49   return MF.getContext().getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) +
     50                                            "func_toc" +
     51                                            Twine(MF.getFunctionNumber()));
     52 }
     53 
     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();
     58   return false;
     59 }
     60 
     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();
     65   return false;
     66 }
     67 
     68 void PPCFunctionInfo::appendParameterType(ParamType Type) {
     69   uint32_t CopyParamType = ParameterType;
     70   int Bits = 0;
     71 
     72   // If it is fixed type, we only need to increase the FixedParamNum, for
     73   // the bit encode of fixed type is bit of zero, we do not need to change the
     74   // ParamType.
     75   if (Type == FixedType) {
     76     ++FixedParamNum;
     77     return;
     78   }
     79 
     80   ++FloatingPointParamNum;
     81 
     82   for (int I = 0;
     83        I < static_cast<int>(FloatingPointParamNum + FixedParamNum - 1); ++I) {
     84     if (CopyParamType & XCOFF::TracebackTable::ParmTypeIsFloatingBit) {
     85       // '10'b => floating point short parameter.
     86       // '11'b => floating point long parameter.
     87       CopyParamType <<= 2;
     88       Bits += 2;
     89     } else {
     90       // '0'b => fixed parameter.
     91       CopyParamType <<= 1;
     92       ++Bits;
     93     }
     94   }
     95 
     96   assert(Type != FixedType && "FixedType should already be handled.");
     97   if (Bits < 31)
     98     ParameterType |= Type << (30 - Bits);
     99 }
    100