LLVM API Documentation

MipsMachineFunction.cpp
Go to the documentation of this file.
00001 //===-- MipsMachineFunctionInfo.cpp - Private data used for Mips ----------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 
00010 #include "MipsMachineFunction.h"
00011 #include "MCTargetDesc/MipsBaseInfo.h"
00012 #include "MipsInstrInfo.h"
00013 #include "MipsSubtarget.h"
00014 #include "llvm/CodeGen/MachineInstrBuilder.h"
00015 #include "llvm/CodeGen/MachineRegisterInfo.h"
00016 #include "llvm/IR/Function.h"
00017 #include "llvm/Support/CommandLine.h"
00018 
00019 using namespace llvm;
00020 
00021 static cl::opt<bool>
00022 FixGlobalBaseReg("mips-fix-global-base-reg", cl::Hidden, cl::init(true),
00023                  cl::desc("Always use $gp as the global base register."));
00024 
00025 bool MipsFunctionInfo::globalBaseRegSet() const {
00026   return GlobalBaseReg;
00027 }
00028 
00029 unsigned MipsFunctionInfo::getGlobalBaseReg() {
00030   // Return if it has already been initialized.
00031   if (GlobalBaseReg)
00032     return GlobalBaseReg;
00033 
00034   const MipsSubtarget &ST = MF.getTarget().getSubtarget<MipsSubtarget>();
00035 
00036   const TargetRegisterClass *RC;
00037   if (ST.inMips16Mode())
00038     RC=(const TargetRegisterClass*)&Mips::CPU16RegsRegClass;
00039   else
00040     RC = ST.isABI_N64() ?
00041       (const TargetRegisterClass*)&Mips::CPU64RegsRegClass :
00042       (const TargetRegisterClass*)&Mips::CPURegsRegClass;
00043   return GlobalBaseReg = MF.getRegInfo().createVirtualRegister(RC);
00044 }
00045 
00046 bool MipsFunctionInfo::mips16SPAliasRegSet() const {
00047   return Mips16SPAliasReg;
00048 }
00049 unsigned MipsFunctionInfo::getMips16SPAliasReg() {
00050   // Return if it has already been initialized.
00051   if (Mips16SPAliasReg)
00052     return Mips16SPAliasReg;
00053 
00054   const TargetRegisterClass *RC;
00055   RC=(const TargetRegisterClass*)&Mips::CPU16RegsRegClass;
00056   return Mips16SPAliasReg = MF.getRegInfo().createVirtualRegister(RC);
00057 }
00058 
00059 void MipsFunctionInfo::createEhDataRegsFI() {
00060   for (int I = 0; I < 4; ++I) {
00061     const MipsSubtarget &ST = MF.getTarget().getSubtarget<MipsSubtarget>();
00062     const TargetRegisterClass *RC = ST.isABI_N64() ?
00063         &Mips::CPU64RegsRegClass : &Mips::CPURegsRegClass;
00064 
00065     EhDataRegFI[I] = MF.getFrameInfo()->CreateStackObject(RC->getSize(),
00066         RC->getAlignment(), false);
00067   }
00068 }
00069 
00070 bool MipsFunctionInfo::isEhDataRegFI(int FI) const {
00071   return CallsEhReturn && (FI == EhDataRegFI[0] || FI == EhDataRegFI[1]
00072                         || FI == EhDataRegFI[2] || FI == EhDataRegFI[3]);
00073 }
00074 
00075 void MipsFunctionInfo::anchor() { }