Home | History | Annotate | Download | only in Mips
      1 //===-- MipsMachineFunctionInfo.cpp - Private data used for Mips ----------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 #include "MipsMachineFunction.h"
     11 #include "MCTargetDesc/MipsBaseInfo.h"
     12 #include "MipsInstrInfo.h"
     13 #include "MipsSubtarget.h"
     14 #include "llvm/CodeGen/MachineInstrBuilder.h"
     15 #include "llvm/CodeGen/MachineRegisterInfo.h"
     16 #include "llvm/IR/Function.h"
     17 #include "llvm/Support/CommandLine.h"
     18 
     19 using namespace llvm;
     20 
     21 static cl::opt<bool>
     22 FixGlobalBaseReg("mips-fix-global-base-reg", cl::Hidden, cl::init(true),
     23                  cl::desc("Always use $gp as the global base register."));
     24 
     25 bool MipsFunctionInfo::globalBaseRegSet() const {
     26   return GlobalBaseReg;
     27 }
     28 
     29 unsigned MipsFunctionInfo::getGlobalBaseReg() {
     30   // Return if it has already been initialized.
     31   if (GlobalBaseReg)
     32     return GlobalBaseReg;
     33 
     34   const MipsSubtarget &ST = MF.getTarget().getSubtarget<MipsSubtarget>();
     35 
     36   const TargetRegisterClass *RC;
     37   if (ST.inMips16Mode())
     38     RC=(const TargetRegisterClass*)&Mips::CPU16RegsRegClass;
     39   else
     40     RC = ST.isABI_N64() ?
     41       (const TargetRegisterClass*)&Mips::GPR64RegClass :
     42       (const TargetRegisterClass*)&Mips::GPR32RegClass;
     43   return GlobalBaseReg = MF.getRegInfo().createVirtualRegister(RC);
     44 }
     45 
     46 bool MipsFunctionInfo::mips16SPAliasRegSet() const {
     47   return Mips16SPAliasReg;
     48 }
     49 unsigned MipsFunctionInfo::getMips16SPAliasReg() {
     50   // Return if it has already been initialized.
     51   if (Mips16SPAliasReg)
     52     return Mips16SPAliasReg;
     53 
     54   const TargetRegisterClass *RC;
     55   RC=(const TargetRegisterClass*)&Mips::CPU16RegsRegClass;
     56   return Mips16SPAliasReg = MF.getRegInfo().createVirtualRegister(RC);
     57 }
     58 
     59 void MipsFunctionInfo::createEhDataRegsFI() {
     60   for (int I = 0; I < 4; ++I) {
     61     const MipsSubtarget &ST = MF.getTarget().getSubtarget<MipsSubtarget>();
     62     const TargetRegisterClass *RC = ST.isABI_N64() ?
     63         &Mips::GPR64RegClass : &Mips::GPR32RegClass;
     64 
     65     EhDataRegFI[I] = MF.getFrameInfo()->CreateStackObject(RC->getSize(),
     66         RC->getAlignment(), false);
     67   }
     68 }
     69 
     70 bool MipsFunctionInfo::isEhDataRegFI(int FI) const {
     71   return CallsEhReturn && (FI == EhDataRegFI[0] || FI == EhDataRegFI[1]
     72                         || FI == EhDataRegFI[2] || FI == EhDataRegFI[3]);
     73 }
     74 
     75 void MipsFunctionInfo::anchor() { }
     76