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"
22 FixGlobalBaseReg("mips-fix-global-base-reg", cl::Hidden, cl::init(true),
23 cl::desc("Always use $gp as the global base register."));
25 // class MipsCallEntry.
26 MipsCallEntry::MipsCallEntry(const StringRef &N) {
33 MipsCallEntry::MipsCallEntry(const GlobalValue *V) {
39 bool MipsCallEntry::isConstant(const MachineFrameInfo *) const {
43 bool MipsCallEntry::isAliased(const MachineFrameInfo *) const {
47 bool MipsCallEntry::mayAlias(const MachineFrameInfo *) const {
51 void MipsCallEntry::printCustom(raw_ostream &O) const {
52 O << "MipsCallEntry: ";
61 MipsFunctionInfo::~MipsFunctionInfo() {
62 for (StringMap<const MipsCallEntry *>::iterator
63 I = ExternalCallEntries.begin(), E = ExternalCallEntries.end(); I != E;
67 for (ValueMap<const GlobalValue *, const MipsCallEntry *>::iterator
68 I = GlobalCallEntries.begin(), E = GlobalCallEntries.end(); I != E; ++I)
72 bool MipsFunctionInfo::globalBaseRegSet() const {
76 unsigned MipsFunctionInfo::getGlobalBaseReg() {
77 // Return if it has already been initialized.
81 const MipsSubtarget &ST = MF.getTarget().getSubtarget<MipsSubtarget>();
83 const TargetRegisterClass *RC;
84 if (ST.inMips16Mode())
85 RC=(const TargetRegisterClass*)&Mips::CPU16RegsRegClass;
88 (const TargetRegisterClass*)&Mips::GPR64RegClass :
89 (const TargetRegisterClass*)&Mips::GPR32RegClass;
90 return GlobalBaseReg = MF.getRegInfo().createVirtualRegister(RC);
93 bool MipsFunctionInfo::mips16SPAliasRegSet() const {
94 return Mips16SPAliasReg;
96 unsigned MipsFunctionInfo::getMips16SPAliasReg() {
97 // Return if it has already been initialized.
99 return Mips16SPAliasReg;
101 const TargetRegisterClass *RC;
102 RC=(const TargetRegisterClass*)&Mips::CPU16RegsRegClass;
103 return Mips16SPAliasReg = MF.getRegInfo().createVirtualRegister(RC);
106 void MipsFunctionInfo::createEhDataRegsFI() {
107 for (int I = 0; I < 4; ++I) {
108 const MipsSubtarget &ST = MF.getTarget().getSubtarget<MipsSubtarget>();
109 const TargetRegisterClass *RC = ST.isABI_N64() ?
110 &Mips::GPR64RegClass : &Mips::GPR32RegClass;
112 EhDataRegFI[I] = MF.getFrameInfo()->CreateStackObject(RC->getSize(),
113 RC->getAlignment(), false);
117 bool MipsFunctionInfo::isEhDataRegFI(int FI) const {
118 return CallsEhReturn && (FI == EhDataRegFI[0] || FI == EhDataRegFI[1]
119 || FI == EhDataRegFI[2] || FI == EhDataRegFI[3]);
122 MachinePointerInfo MipsFunctionInfo::callPtrInfo(const StringRef &Name) {
123 StringMap<const MipsCallEntry *>::const_iterator I;
124 I = ExternalCallEntries.find(Name);
126 if (I != ExternalCallEntries.end())
127 return MachinePointerInfo(I->getValue());
129 const MipsCallEntry *E = ExternalCallEntries[Name] = new MipsCallEntry(Name);
130 return MachinePointerInfo(E);
133 MachinePointerInfo MipsFunctionInfo::callPtrInfo(const GlobalValue *Val) {
134 ValueMap<const GlobalValue *, const MipsCallEntry *>::const_iterator I;
135 I = GlobalCallEntries.find(Val);
137 if (I != GlobalCallEntries.end())
138 return MachinePointerInfo(I->second);
140 const MipsCallEntry *E = GlobalCallEntries[Val] = new MipsCallEntry(Val);
141 return MachinePointerInfo(E);
144 void MipsFunctionInfo::anchor() { }