2012-02-17 16:55:11 +08:00
|
|
|
//===-- MipsMachineFunctionInfo.cpp - Private data used for Mips ----------===//
|
2011-12-20 10:50:00 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "MCTargetDesc/MipsBaseInfo.h"
|
2012-02-25 06:34:47 +08:00
|
|
|
#include "MipsInstrInfo.h"
|
2015-02-13 17:09:03 +08:00
|
|
|
#include "MipsMachineFunction.h"
|
2012-02-25 06:34:47 +08:00
|
|
|
#include "MipsSubtarget.h"
|
2015-01-30 07:27:36 +08:00
|
|
|
#include "MipsTargetMachine.h"
|
2012-02-25 06:34:47 +08:00
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/Function.h"
|
2012-02-25 06:34:47 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2013-09-28 09:35:07 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2011-12-20 10:50:00 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2012-02-25 06:34:47 +08:00
|
|
|
static cl::opt<bool>
|
|
|
|
FixGlobalBaseReg("mips-fix-global-base-reg", cl::Hidden, cl::init(true),
|
|
|
|
cl::desc("Always use $gp as the global base register."));
|
|
|
|
|
2015-04-16 20:43:33 +08:00
|
|
|
MipsFunctionInfo::~MipsFunctionInfo() {}
|
2013-09-28 06:30:36 +08:00
|
|
|
|
2012-02-25 06:34:47 +08:00
|
|
|
bool MipsFunctionInfo::globalBaseRegSet() const {
|
|
|
|
return GlobalBaseReg;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned MipsFunctionInfo::getGlobalBaseReg() {
|
|
|
|
// Return if it has already been initialized.
|
|
|
|
if (GlobalBaseReg)
|
|
|
|
return GlobalBaseReg;
|
|
|
|
|
2015-02-27 23:03:50 +08:00
|
|
|
MipsSubtarget const &STI =
|
|
|
|
static_cast<const MipsSubtarget &>(MF.getSubtarget());
|
|
|
|
|
2014-11-21 13:58:21 +08:00
|
|
|
const TargetRegisterClass *RC =
|
2015-02-27 23:03:50 +08:00
|
|
|
STI.inMips16Mode()
|
2015-01-30 07:27:36 +08:00
|
|
|
? &Mips::CPU16RegsRegClass
|
2015-02-27 23:03:50 +08:00
|
|
|
: STI.inMicroMipsMode()
|
2016-04-13 14:17:21 +08:00
|
|
|
? STI.hasMips64()
|
|
|
|
? &Mips::GPRMM16_64RegClass
|
|
|
|
: &Mips::GPRMM16RegClass
|
2015-02-27 23:03:50 +08:00
|
|
|
: static_cast<const MipsTargetMachine &>(MF.getTarget())
|
|
|
|
.getABI()
|
|
|
|
.IsN64()
|
|
|
|
? &Mips::GPR64RegClass
|
|
|
|
: &Mips::GPR32RegClass;
|
2012-02-25 06:34:47 +08:00
|
|
|
return GlobalBaseReg = MF.getRegInfo().createVirtualRegister(RC);
|
|
|
|
}
|
|
|
|
|
2012-10-28 14:02:37 +08:00
|
|
|
bool MipsFunctionInfo::mips16SPAliasRegSet() const {
|
|
|
|
return Mips16SPAliasReg;
|
|
|
|
}
|
|
|
|
unsigned MipsFunctionInfo::getMips16SPAliasReg() {
|
|
|
|
// Return if it has already been initialized.
|
|
|
|
if (Mips16SPAliasReg)
|
|
|
|
return Mips16SPAliasReg;
|
|
|
|
|
2014-11-21 13:58:21 +08:00
|
|
|
const TargetRegisterClass *RC = &Mips::CPU16RegsRegClass;
|
2012-10-28 14:02:37 +08:00
|
|
|
return Mips16SPAliasReg = MF.getRegInfo().createVirtualRegister(RC);
|
|
|
|
}
|
|
|
|
|
2013-01-30 08:26:49 +08:00
|
|
|
void MipsFunctionInfo::createEhDataRegsFI() {
|
|
|
|
for (int I = 0; I < 4; ++I) {
|
2015-01-30 07:27:36 +08:00
|
|
|
const TargetRegisterClass *RC =
|
|
|
|
static_cast<const MipsTargetMachine &>(MF.getTarget()).getABI().IsN64()
|
|
|
|
? &Mips::GPR64RegClass
|
|
|
|
: &Mips::GPR32RegClass;
|
2013-01-30 08:26:49 +08:00
|
|
|
|
|
|
|
EhDataRegFI[I] = MF.getFrameInfo()->CreateStackObject(RC->getSize(),
|
|
|
|
RC->getAlignment(), false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-26 20:38:43 +08:00
|
|
|
void MipsFunctionInfo::createISRRegFI() {
|
|
|
|
// ISRs require spill slots for Status & ErrorPC Coprocessor 0 registers.
|
|
|
|
// The current implementation only supports Mips32r2+ not Mips64rX. Status
|
|
|
|
// is always 32 bits, ErrorPC is 32 or 64 bits dependant on architecture,
|
|
|
|
// however Mips32r2+ is the supported architecture.
|
|
|
|
const TargetRegisterClass *RC = &Mips::GPR32RegClass;
|
|
|
|
|
|
|
|
for (int I = 0; I < 2; ++I)
|
|
|
|
ISRDataRegFI[I] = MF.getFrameInfo()->CreateStackObject(
|
|
|
|
RC->getSize(), RC->getAlignment(), false);
|
|
|
|
}
|
|
|
|
|
2013-01-30 08:26:49 +08:00
|
|
|
bool MipsFunctionInfo::isEhDataRegFI(int FI) const {
|
|
|
|
return CallsEhReturn && (FI == EhDataRegFI[0] || FI == EhDataRegFI[1]
|
|
|
|
|| FI == EhDataRegFI[2] || FI == EhDataRegFI[3]);
|
|
|
|
}
|
|
|
|
|
2015-10-26 20:38:43 +08:00
|
|
|
bool MipsFunctionInfo::isISRRegFI(int FI) const {
|
|
|
|
return IsISR && (FI == ISRDataRegFI[0] || FI == ISRDataRegFI[1]);
|
|
|
|
}
|
2015-08-12 07:23:17 +08:00
|
|
|
MachinePointerInfo MipsFunctionInfo::callPtrInfo(const char *ES) {
|
|
|
|
return MachinePointerInfo(MF.getPSVManager().getExternalSymbolCallEntry(ES));
|
2013-09-28 06:30:36 +08:00
|
|
|
}
|
|
|
|
|
2015-08-12 07:23:17 +08:00
|
|
|
MachinePointerInfo MipsFunctionInfo::callPtrInfo(const GlobalValue *GV) {
|
|
|
|
return MachinePointerInfo(MF.getPSVManager().getGlobalValueCallEntry(GV));
|
2013-09-28 06:30:36 +08:00
|
|
|
}
|
|
|
|
|
2014-07-14 21:08:14 +08:00
|
|
|
int MipsFunctionInfo::getMoveF64ViaSpillFI(const TargetRegisterClass *RC) {
|
|
|
|
if (MoveF64ViaSpillFI == -1) {
|
|
|
|
MoveF64ViaSpillFI = MF.getFrameInfo()->CreateStackObject(
|
|
|
|
RC->getSize(), RC->getAlignment(), false);
|
2014-07-14 17:40:29 +08:00
|
|
|
}
|
2014-07-14 21:08:14 +08:00
|
|
|
return MoveF64ViaSpillFI;
|
2014-07-14 17:40:29 +08:00
|
|
|
}
|
|
|
|
|
2011-12-20 10:50:00 +08:00
|
|
|
void MipsFunctionInfo::anchor() { }
|