• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "MCTargetDesc/MipsBaseInfo.h"
11 #include "MipsInstrInfo.h"
12 #include "MipsMachineFunction.h"
13 #include "MipsSubtarget.h"
14 #include "MipsTargetMachine.h"
15 #include "llvm/CodeGen/MachineInstrBuilder.h"
16 #include "llvm/CodeGen/MachineRegisterInfo.h"
17 #include "llvm/IR/Function.h"
18 #include "llvm/Support/CommandLine.h"
19 #include "llvm/Support/raw_ostream.h"
20 
21 using namespace llvm;
22 
23 static cl::opt<bool>
24 FixGlobalBaseReg("mips-fix-global-base-reg", cl::Hidden, cl::init(true),
25                  cl::desc("Always use $gp as the global base register."));
26 
~MipsFunctionInfo()27 MipsFunctionInfo::~MipsFunctionInfo() {}
28 
globalBaseRegSet() const29 bool MipsFunctionInfo::globalBaseRegSet() const {
30   return GlobalBaseReg;
31 }
32 
getGlobalBaseReg()33 unsigned MipsFunctionInfo::getGlobalBaseReg() {
34   // Return if it has already been initialized.
35   if (GlobalBaseReg)
36     return GlobalBaseReg;
37 
38   MipsSubtarget const &STI =
39       static_cast<const MipsSubtarget &>(MF.getSubtarget());
40 
41   const TargetRegisterClass *RC =
42       STI.inMips16Mode()
43           ? &Mips::CPU16RegsRegClass
44           : STI.inMicroMipsMode()
45                 ? &Mips::GPRMM16RegClass
46                 : static_cast<const MipsTargetMachine &>(MF.getTarget())
47                           .getABI()
48                           .IsN64()
49                       ? &Mips::GPR64RegClass
50                       : &Mips::GPR32RegClass;
51   return GlobalBaseReg = MF.getRegInfo().createVirtualRegister(RC);
52 }
53 
mips16SPAliasRegSet() const54 bool MipsFunctionInfo::mips16SPAliasRegSet() const {
55   return Mips16SPAliasReg;
56 }
getMips16SPAliasReg()57 unsigned MipsFunctionInfo::getMips16SPAliasReg() {
58   // Return if it has already been initialized.
59   if (Mips16SPAliasReg)
60     return Mips16SPAliasReg;
61 
62   const TargetRegisterClass *RC = &Mips::CPU16RegsRegClass;
63   return Mips16SPAliasReg = MF.getRegInfo().createVirtualRegister(RC);
64 }
65 
createEhDataRegsFI()66 void MipsFunctionInfo::createEhDataRegsFI() {
67   for (int I = 0; I < 4; ++I) {
68     const TargetRegisterClass *RC =
69         static_cast<const MipsTargetMachine &>(MF.getTarget()).getABI().IsN64()
70             ? &Mips::GPR64RegClass
71             : &Mips::GPR32RegClass;
72 
73     EhDataRegFI[I] = MF.getFrameInfo()->CreateStackObject(RC->getSize(),
74         RC->getAlignment(), false);
75   }
76 }
77 
createISRRegFI()78 void MipsFunctionInfo::createISRRegFI() {
79   // ISRs require spill slots for Status & ErrorPC Coprocessor 0 registers.
80   // The current implementation only supports Mips32r2+ not Mips64rX. Status
81   // is always 32 bits, ErrorPC is 32 or 64 bits dependant on architecture,
82   // however Mips32r2+ is the supported architecture.
83   const TargetRegisterClass *RC = &Mips::GPR32RegClass;
84 
85   for (int I = 0; I < 2; ++I)
86     ISRDataRegFI[I] = MF.getFrameInfo()->CreateStackObject(
87         RC->getSize(), RC->getAlignment(), false);
88 }
89 
isEhDataRegFI(int FI) const90 bool MipsFunctionInfo::isEhDataRegFI(int FI) const {
91   return CallsEhReturn && (FI == EhDataRegFI[0] || FI == EhDataRegFI[1]
92                         || FI == EhDataRegFI[2] || FI == EhDataRegFI[3]);
93 }
94 
isISRRegFI(int FI) const95 bool MipsFunctionInfo::isISRRegFI(int FI) const {
96   return IsISR && (FI == ISRDataRegFI[0] || FI == ISRDataRegFI[1]);
97 }
callPtrInfo(const char * ES)98 MachinePointerInfo MipsFunctionInfo::callPtrInfo(const char *ES) {
99   return MachinePointerInfo(MF.getPSVManager().getExternalSymbolCallEntry(ES));
100 }
101 
callPtrInfo(const GlobalValue * GV)102 MachinePointerInfo MipsFunctionInfo::callPtrInfo(const GlobalValue *GV) {
103   return MachinePointerInfo(MF.getPSVManager().getGlobalValueCallEntry(GV));
104 }
105 
getMoveF64ViaSpillFI(const TargetRegisterClass * RC)106 int MipsFunctionInfo::getMoveF64ViaSpillFI(const TargetRegisterClass *RC) {
107   if (MoveF64ViaSpillFI == -1) {
108     MoveF64ViaSpillFI = MF.getFrameInfo()->CreateStackObject(
109         RC->getSize(), RC->getAlignment(), false);
110   }
111   return MoveF64ViaSpillFI;
112 }
113 
anchor()114 void MipsFunctionInfo::anchor() { }
115