1 //===-- MipsMachineFunctionInfo.cpp - Private data used for Mips ----------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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 #include "llvm/Support/raw_ostream.h"
23 FixGlobalBaseReg("mips-fix-global-base-reg", cl::Hidden, cl::init(true),
24 cl::desc("Always use $gp as the global base register."));
26 // class MipsCallEntry.
27 MipsCallEntry::MipsCallEntry(const StringRef &N) {
34 MipsCallEntry::MipsCallEntry(const GlobalValue *V) {
40 bool MipsCallEntry::isConstant(const MachineFrameInfo *) const {
44 bool MipsCallEntry::isAliased(const MachineFrameInfo *) const {
48 bool MipsCallEntry::mayAlias(const MachineFrameInfo *) const {
52 void MipsCallEntry::printCustom(raw_ostream &O) const {
53 O << "MipsCallEntry: ";
62 MipsFunctionInfo::~MipsFunctionInfo() {
63 for (StringMap<const MipsCallEntry *>::iterator
64 I = ExternalCallEntries.begin(), E = ExternalCallEntries.end(); I != E;
68 for (ValueMap<const GlobalValue *, const MipsCallEntry *>::iterator
69 I = GlobalCallEntries.begin(), E = GlobalCallEntries.end(); I != E; ++I)
73 bool MipsFunctionInfo::globalBaseRegSet() const {
77 unsigned MipsFunctionInfo::getGlobalBaseReg() {
78 // Return if it has already been initialized.
82 const MipsSubtarget &ST = MF.getTarget().getSubtarget<MipsSubtarget>();
84 const TargetRegisterClass *RC;
85 if (ST.inMips16Mode())
86 RC=(const TargetRegisterClass*)&Mips::CPU16RegsRegClass;
89 (const TargetRegisterClass*)&Mips::GPR64RegClass :
90 (const TargetRegisterClass*)&Mips::GPR32RegClass;
91 return GlobalBaseReg = MF.getRegInfo().createVirtualRegister(RC);
94 bool MipsFunctionInfo::mips16SPAliasRegSet() const {
95 return Mips16SPAliasReg;
97 unsigned MipsFunctionInfo::getMips16SPAliasReg() {
98 // Return if it has already been initialized.
100 return Mips16SPAliasReg;
102 const TargetRegisterClass *RC;
103 RC=(const TargetRegisterClass*)&Mips::CPU16RegsRegClass;
104 return Mips16SPAliasReg = MF.getRegInfo().createVirtualRegister(RC);
107 void MipsFunctionInfo::createEhDataRegsFI() {
108 for (int I = 0; I < 4; ++I) {
109 const MipsSubtarget &ST = MF.getTarget().getSubtarget<MipsSubtarget>();
110 const TargetRegisterClass *RC = ST.isABI_N64() ?
111 &Mips::GPR64RegClass : &Mips::GPR32RegClass;
113 EhDataRegFI[I] = MF.getFrameInfo()->CreateStackObject(RC->getSize(),
114 RC->getAlignment(), false);
118 bool MipsFunctionInfo::isEhDataRegFI(int FI) const {
119 return CallsEhReturn && (FI == EhDataRegFI[0] || FI == EhDataRegFI[1]
120 || FI == EhDataRegFI[2] || FI == EhDataRegFI[3]);
123 MachinePointerInfo MipsFunctionInfo::callPtrInfo(const StringRef &Name) {
124 const MipsCallEntry *&E = ExternalCallEntries[Name];
127 E = new MipsCallEntry(Name);
129 return MachinePointerInfo(E);
132 MachinePointerInfo MipsFunctionInfo::callPtrInfo(const GlobalValue *Val) {
133 const MipsCallEntry *&E = GlobalCallEntries[Val];
136 E = new MipsCallEntry(Val);
138 return MachinePointerInfo(E);
141 void MipsFunctionInfo::anchor() { }