2014-11-03 00:09:29 +08:00
|
|
|
//===---- MipsABIInfo.cpp - Information about MIPS ABI's ------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "MipsABIInfo.h"
|
|
|
|
#include "MipsRegisterInfo.h"
|
2015-01-27 01:33:46 +08:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
#include "llvm/ADT/StringSwitch.h"
|
|
|
|
#include "llvm/MC/MCTargetOptions.h"
|
2014-11-03 00:09:29 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
static const MCPhysReg O32IntRegs[4] = {Mips::A0, Mips::A1, Mips::A2, Mips::A3};
|
|
|
|
|
|
|
|
static const MCPhysReg Mips64IntRegs[8] = {
|
|
|
|
Mips::A0_64, Mips::A1_64, Mips::A2_64, Mips::A3_64,
|
|
|
|
Mips::T0_64, Mips::T1_64, Mips::T2_64, Mips::T3_64};
|
|
|
|
}
|
|
|
|
|
2015-09-28 08:15:34 +08:00
|
|
|
ArrayRef<MCPhysReg> MipsABIInfo::GetByValArgRegs() const {
|
2014-11-03 00:09:29 +08:00
|
|
|
if (IsO32())
|
|
|
|
return makeArrayRef(O32IntRegs);
|
|
|
|
if (IsN32() || IsN64())
|
|
|
|
return makeArrayRef(Mips64IntRegs);
|
|
|
|
llvm_unreachable("Unhandled ABI");
|
|
|
|
}
|
2014-11-07 20:21:37 +08:00
|
|
|
|
2015-09-28 08:15:34 +08:00
|
|
|
ArrayRef<MCPhysReg> MipsABIInfo::GetVarArgRegs() const {
|
2014-11-07 20:21:37 +08:00
|
|
|
if (IsO32())
|
|
|
|
return makeArrayRef(O32IntRegs);
|
|
|
|
if (IsN32() || IsN64())
|
|
|
|
return makeArrayRef(Mips64IntRegs);
|
|
|
|
llvm_unreachable("Unhandled ABI");
|
|
|
|
}
|
2014-11-07 23:03:53 +08:00
|
|
|
|
|
|
|
unsigned MipsABIInfo::GetCalleeAllocdArgSizeInBytes(CallingConv::ID CC) const {
|
|
|
|
if (IsO32())
|
|
|
|
return CC != CallingConv::Fast ? 16 : 0;
|
2016-06-03 18:38:09 +08:00
|
|
|
if (IsN32() || IsN64())
|
2014-11-07 23:03:53 +08:00
|
|
|
return 0;
|
|
|
|
llvm_unreachable("Unhandled ABI");
|
|
|
|
}
|
2015-01-27 01:33:46 +08:00
|
|
|
|
2015-09-16 00:17:27 +08:00
|
|
|
MipsABIInfo MipsABIInfo::computeTargetABI(const Triple &TT, StringRef CPU,
|
2015-01-27 01:33:46 +08:00
|
|
|
const MCTargetOptions &Options) {
|
|
|
|
if (Options.getABIName().startswith("o32"))
|
|
|
|
return MipsABIInfo::O32();
|
2016-12-11 01:30:09 +08:00
|
|
|
if (Options.getABIName().startswith("n32"))
|
2015-01-27 01:33:46 +08:00
|
|
|
return MipsABIInfo::N32();
|
2016-12-11 01:30:09 +08:00
|
|
|
if (Options.getABIName().startswith("n64"))
|
2015-01-27 01:33:46 +08:00
|
|
|
return MipsABIInfo::N64();
|
2016-12-11 01:30:09 +08:00
|
|
|
assert(Options.getABIName().empty() && "Unknown ABI option for MIPS");
|
2015-01-27 01:33:46 +08:00
|
|
|
|
2016-06-23 20:42:53 +08:00
|
|
|
if (TT.getArch() == Triple::mips64 || TT.getArch() == Triple::mips64el)
|
|
|
|
return MipsABIInfo::N64();
|
|
|
|
return MipsABIInfo::O32();
|
2015-01-27 01:33:46 +08:00
|
|
|
}
|
2015-04-17 17:50:21 +08:00
|
|
|
|
|
|
|
unsigned MipsABIInfo::GetStackPtr() const {
|
|
|
|
return ArePtrs64bit() ? Mips::SP_64 : Mips::SP;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned MipsABIInfo::GetFramePtr() const {
|
|
|
|
return ArePtrs64bit() ? Mips::FP_64 : Mips::FP;
|
|
|
|
}
|
|
|
|
|
2015-06-02 21:14:46 +08:00
|
|
|
unsigned MipsABIInfo::GetBasePtr() const {
|
|
|
|
return ArePtrs64bit() ? Mips::S7_64 : Mips::S7;
|
|
|
|
}
|
|
|
|
|
2016-06-03 17:53:06 +08:00
|
|
|
unsigned MipsABIInfo::GetGlobalPtr() const {
|
|
|
|
return ArePtrs64bit() ? Mips::GP_64 : Mips::GP;
|
|
|
|
}
|
|
|
|
|
2015-04-17 17:50:21 +08:00
|
|
|
unsigned MipsABIInfo::GetNullPtr() const {
|
|
|
|
return ArePtrs64bit() ? Mips::ZERO_64 : Mips::ZERO;
|
|
|
|
}
|
|
|
|
|
2015-08-17 18:11:55 +08:00
|
|
|
unsigned MipsABIInfo::GetZeroReg() const {
|
|
|
|
return AreGprs64bit() ? Mips::ZERO_64 : Mips::ZERO;
|
|
|
|
}
|
|
|
|
|
2015-04-17 17:50:21 +08:00
|
|
|
unsigned MipsABIInfo::GetPtrAdduOp() const {
|
|
|
|
return ArePtrs64bit() ? Mips::DADDu : Mips::ADDu;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned MipsABIInfo::GetPtrAddiuOp() const {
|
|
|
|
return ArePtrs64bit() ? Mips::DADDiu : Mips::ADDiu;
|
|
|
|
}
|
|
|
|
|
2016-06-14 21:39:43 +08:00
|
|
|
unsigned MipsABIInfo::GetPtrSubuOp() const {
|
|
|
|
return ArePtrs64bit() ? Mips::DSUBu : Mips::SUBu;
|
|
|
|
}
|
|
|
|
|
2016-04-29 00:26:43 +08:00
|
|
|
unsigned MipsABIInfo::GetPtrAndOp() const {
|
|
|
|
return ArePtrs64bit() ? Mips::AND64 : Mips::AND;
|
|
|
|
}
|
|
|
|
|
2015-08-11 16:56:25 +08:00
|
|
|
unsigned MipsABIInfo::GetGPRMoveOp() const {
|
|
|
|
return ArePtrs64bit() ? Mips::OR64 : Mips::OR;
|
|
|
|
}
|
|
|
|
|
2015-04-17 17:50:21 +08:00
|
|
|
unsigned MipsABIInfo::GetEhDataReg(unsigned I) const {
|
|
|
|
static const unsigned EhDataReg[] = {
|
|
|
|
Mips::A0, Mips::A1, Mips::A2, Mips::A3
|
|
|
|
};
|
|
|
|
static const unsigned EhDataReg64[] = {
|
|
|
|
Mips::A0_64, Mips::A1_64, Mips::A2_64, Mips::A3_64
|
|
|
|
};
|
|
|
|
|
|
|
|
return IsN64() ? EhDataReg64[I] : EhDataReg[I];
|
|
|
|
}
|
|
|
|
|