2012-02-17 08:55:11 +00:00
|
|
|
//===-- MipsSubtarget.cpp - Mips Subtarget Information --------------------===//
|
2007-06-06 07:42:06 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-06-06 07:42:06 +00:00
|
|
|
//
|
2011-04-15 21:51:11 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2007-06-06 07:42:06 +00:00
|
|
|
//
|
2011-07-01 21:01:15 +00:00
|
|
|
// This file implements the Mips specific subclass of TargetSubtargetInfo.
|
2007-06-06 07:42:06 +00:00
|
|
|
//
|
2011-04-15 21:51:11 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2007-06-06 07:42:06 +00:00
|
|
|
|
2013-04-09 19:46:01 +00:00
|
|
|
#include "MipsMachineFunction.h"
|
2007-06-06 07:42:06 +00:00
|
|
|
#include "Mips.h"
|
2012-03-28 00:24:17 +00:00
|
|
|
#include "MipsRegisterInfo.h"
|
2014-01-07 11:48:04 +00:00
|
|
|
#include "MipsSubtarget.h"
|
|
|
|
#include "MipsTargetMachine.h"
|
2013-04-09 19:46:01 +00:00
|
|
|
#include "llvm/IR/Attributes.h"
|
|
|
|
#include "llvm/IR/Function.h"
|
|
|
|
#include "llvm/Support/CommandLine.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
2011-08-24 18:08:43 +00:00
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
2013-04-09 19:46:01 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2011-07-01 20:45:01 +00:00
|
|
|
|
2014-04-22 02:03:14 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2014-04-22 02:41:26 +00:00
|
|
|
#define DEBUG_TYPE "mips-subtarget"
|
|
|
|
|
2011-07-01 20:45:01 +00:00
|
|
|
#define GET_SUBTARGETINFO_TARGET_DESC
|
2011-07-08 01:53:10 +00:00
|
|
|
#define GET_SUBTARGETINFO_CTOR
|
2011-07-01 22:36:09 +00:00
|
|
|
#include "MipsGenSubtargetInfo.inc"
|
2011-07-01 20:45:01 +00:00
|
|
|
|
2013-04-09 19:46:01 +00:00
|
|
|
// FIXME: Maybe this should be on by default when Mips16 is specified
|
|
|
|
//
|
|
|
|
static cl::opt<bool> Mixed16_32(
|
|
|
|
"mips-mixed-16-32",
|
|
|
|
cl::init(false),
|
|
|
|
cl::desc("Allow for a mixture of Mips16 "
|
|
|
|
"and Mips32 code in a single source file"),
|
|
|
|
cl::Hidden);
|
|
|
|
|
2013-04-10 16:58:04 +00:00
|
|
|
static cl::opt<bool> Mips_Os16(
|
|
|
|
"mips-os16",
|
|
|
|
cl::init(false),
|
|
|
|
cl::desc("Compile all functions that don' use "
|
|
|
|
"floating point as Mips 16"),
|
|
|
|
cl::Hidden);
|
|
|
|
|
Checkin in of first of several patches to finish implementation of
mips16/mips32 floating point interoperability.
This patch fixes returns from mips16 functions so that if the function
was in fact called by a mips32 hard float routine, then values
that would have been returned in floating point registers are so returned.
Mips16 mode has no floating point instructions so there is no way to
load values into floating point registers.
This is needed when returning float, double, single complex, double complex
in the Mips ABI.
Helper functions in libc for mips16 are available to do this.
For efficiency purposes, these helper functions have a different calling
convention from normal Mips calls.
Registers v0,v1,a0,a1 are used to pass parameters instead of
a0,a1,a2,a3.
This is because v0,v1,a0,a1 are the natural registers used to return
floating point values in soft float. These values can then be moved
to the appropriate floating point registers with no extra cost.
The only register that is modified is ra in this call.
The helper functions make sure that the return values are in the floating
point registers that they would be in if soft float was not in effect
(which it is for mips16, though the soft float is implemented using a mips32
library that uses hard float).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@181641 91177308-0d34-0410-b5e6-96231b3b80d8
2013-05-10 22:25:39 +00:00
|
|
|
static cl::opt<bool>
|
|
|
|
Mips16HardFloat("mips16-hard-float", cl::NotHidden,
|
|
|
|
cl::desc("MIPS: mips16 hard float enable."),
|
|
|
|
cl::init(false));
|
|
|
|
|
2013-10-27 21:57:36 +00:00
|
|
|
static cl::opt<bool>
|
|
|
|
Mips16ConstantIslands(
|
2013-11-28 00:56:37 +00:00
|
|
|
"mips16-constant-islands", cl::NotHidden,
|
|
|
|
cl::desc("MIPS: mips16 constant islands enable."),
|
|
|
|
cl::init(true));
|
2013-10-27 21:57:36 +00:00
|
|
|
|
2014-02-20 13:13:33 +00:00
|
|
|
/// Select the Mips CPU for the given triple and cpu name.
|
|
|
|
/// FIXME: Merge with the copy in MipsMCTargetDesc.cpp
|
2014-07-02 01:14:43 +00:00
|
|
|
static StringRef selectMipsCPU(Triple TT, StringRef CPU) {
|
2014-02-26 10:20:15 +00:00
|
|
|
if (CPU.empty() || CPU == "generic") {
|
2014-07-02 01:14:43 +00:00
|
|
|
if (TT.getArch() == Triple::mips || TT.getArch() == Triple::mipsel)
|
2014-02-20 13:13:33 +00:00
|
|
|
CPU = "mips32";
|
|
|
|
else
|
|
|
|
CPU = "mips64";
|
|
|
|
}
|
|
|
|
return CPU;
|
|
|
|
}
|
|
|
|
|
2011-12-20 02:50:00 +00:00
|
|
|
void MipsSubtarget::anchor() { }
|
|
|
|
|
2014-07-02 21:29:23 +00:00
|
|
|
static std::string computeDataLayout(const MipsSubtarget &ST) {
|
|
|
|
std::string Ret = "";
|
|
|
|
|
|
|
|
// There are both little and big endian mips.
|
|
|
|
if (ST.isLittle())
|
|
|
|
Ret += "e";
|
|
|
|
else
|
|
|
|
Ret += "E";
|
|
|
|
|
|
|
|
Ret += "-m:m";
|
|
|
|
|
|
|
|
// Pointers are 32 bit on some ABIs.
|
|
|
|
if (!ST.isABI_N64())
|
|
|
|
Ret += "-p:32:32";
|
|
|
|
|
|
|
|
// 8 and 16 bit integers only need no have natural alignment, but try to
|
|
|
|
// align them to 32 bits. 64 bit integers have natural alignment.
|
|
|
|
Ret += "-i8:8:32-i16:16:32-i64:64";
|
|
|
|
|
|
|
|
// 32 bit registers are always available and the stack is at least 64 bit
|
|
|
|
// aligned. On N64 64 bit registers are also available and the stack is
|
|
|
|
// 128 bit aligned.
|
|
|
|
if (ST.isABI_N64() || ST.isABI_N32())
|
|
|
|
Ret += "-n32:64-S128";
|
|
|
|
else
|
|
|
|
Ret += "-n32-S64";
|
|
|
|
|
|
|
|
return Ret;
|
|
|
|
}
|
|
|
|
|
2011-06-30 01:53:36 +00:00
|
|
|
MipsSubtarget::MipsSubtarget(const std::string &TT, const std::string &CPU,
|
2012-08-22 03:18:13 +00:00
|
|
|
const std::string &FS, bool little,
|
2014-09-19 23:30:42 +00:00
|
|
|
const MipsTargetMachine *_TM)
|
2014-04-16 15:48:55 +00:00
|
|
|
: MipsGenSubtargetInfo(TT, CPU, FS), MipsArchVersion(Mips32),
|
|
|
|
MipsABI(UnknownABI), IsLittle(little), IsSingleFloat(false),
|
2014-08-08 15:47:17 +00:00
|
|
|
IsFPXX(false), NoABICalls(false), IsFP64bit(false), UseOddSPReg(true),
|
2014-08-08 10:01:29 +00:00
|
|
|
IsNaN2008bit(false), IsGP64bit(false), HasVFPU(false), HasCnMips(false),
|
|
|
|
IsLinux(true), HasMips3_32(false), HasMips3_32r2(false),
|
|
|
|
HasMips4_32(false), HasMips4_32r2(false), HasMips5_32r2(false),
|
|
|
|
InMips16Mode(false), InMips16HardFloat(Mips16HardFloat),
|
|
|
|
InMicroMipsMode(false), HasDSP(false), HasDSPR2(false),
|
|
|
|
AllowMixed16_32(Mixed16_32 | Mips_Os16), Os16(Mips_Os16),
|
2014-07-18 23:41:32 +00:00
|
|
|
HasMSA(false), TM(_TM), TargetTriple(TT),
|
2014-07-03 00:10:24 +00:00
|
|
|
DL(computeDataLayout(initializeSubtargetDependencies(CPU, FS, TM))),
|
2014-09-02 22:28:02 +00:00
|
|
|
TSInfo(DL), InstrInfo(MipsInstrInfo::create(*this)),
|
2014-07-18 23:33:47 +00:00
|
|
|
FrameLowering(MipsFrameLowering::create(*this)),
|
2014-07-18 23:25:04 +00:00
|
|
|
TLInfo(MipsTargetLowering::create(*TM, *this)) {
|
2013-11-19 12:20:17 +00:00
|
|
|
|
2013-04-09 19:46:01 +00:00
|
|
|
PreviousInMips16Mode = InMips16Mode;
|
|
|
|
|
2014-05-07 16:25:22 +00:00
|
|
|
// Don't even attempt to generate code for MIPS-I, MIPS-II, MIPS-III, and
|
|
|
|
// MIPS-V. They have not been tested and currently exist for the integrated
|
|
|
|
// assembler only.
|
|
|
|
if (MipsArchVersion == Mips1)
|
|
|
|
report_fatal_error("Code generation for MIPS-I is not implemented", false);
|
|
|
|
if (MipsArchVersion == Mips2)
|
|
|
|
report_fatal_error("Code generation for MIPS-II is not implemented", false);
|
|
|
|
if (MipsArchVersion == Mips3)
|
|
|
|
report_fatal_error("Code generation for MIPS-III is not implemented",
|
|
|
|
false);
|
|
|
|
if (MipsArchVersion == Mips5)
|
|
|
|
report_fatal_error("Code generation for MIPS-V is not implemented", false);
|
|
|
|
|
2014-02-20 14:58:19 +00:00
|
|
|
// Assert exactly one ABI was chosen.
|
|
|
|
assert(MipsABI != UnknownABI);
|
|
|
|
assert((((getFeatureBits() & Mips::FeatureO32) != 0) +
|
|
|
|
((getFeatureBits() & Mips::FeatureEABI) != 0) +
|
|
|
|
((getFeatureBits() & Mips::FeatureN32) != 0) +
|
|
|
|
((getFeatureBits() & Mips::FeatureN64) != 0)) == 1);
|
2011-09-21 02:45:29 +00:00
|
|
|
|
|
|
|
// Check if Architecture and ABI are compatible.
|
2014-03-27 16:42:17 +00:00
|
|
|
assert(((!isGP64bit() && (isABI_O32() || isABI_EABI())) ||
|
|
|
|
(isGP64bit() && (isABI_N32() || isABI_N64()))) &&
|
2011-09-21 02:45:29 +00:00
|
|
|
"Invalid Arch & ABI pair.");
|
|
|
|
|
2013-09-27 10:08:31 +00:00
|
|
|
if (hasMSA() && !isFP64bit())
|
|
|
|
report_fatal_error("MSA requires a 64-bit FPU register file (FR=1 mode). "
|
|
|
|
"See -mattr=+fp64.",
|
|
|
|
false);
|
|
|
|
|
2014-07-10 13:38:23 +00:00
|
|
|
if (!isABI_O32() && !useOddSPReg())
|
2014-07-14 13:08:14 +00:00
|
|
|
report_fatal_error("-mattr=+nooddspreg requires the O32 ABI.", false);
|
2014-07-10 13:38:23 +00:00
|
|
|
|
2014-07-14 09:40:29 +00:00
|
|
|
if (IsFPXX && (isABI_N32() || isABI_N64()))
|
|
|
|
report_fatal_error("FPXX is not permitted for the N32/N64 ABI's.", false);
|
|
|
|
|
2014-05-09 09:46:21 +00:00
|
|
|
if (hasMips32r6()) {
|
|
|
|
StringRef ISA = hasMips64r6() ? "MIPS64r6" : "MIPS32r6";
|
|
|
|
|
|
|
|
assert(isFP64bit());
|
|
|
|
assert(isNaN2008());
|
|
|
|
if (hasDSP())
|
|
|
|
report_fatal_error(ISA + " is not compatible with the DSP ASE", false);
|
|
|
|
}
|
|
|
|
|
2008-07-14 14:42:54 +00:00
|
|
|
// Is the target system Linux ?
|
|
|
|
if (TT.find("linux") == std::string::npos)
|
|
|
|
IsLinux = false;
|
2012-08-22 03:18:13 +00:00
|
|
|
|
|
|
|
// Set UseSmallSection.
|
2014-04-16 12:29:08 +00:00
|
|
|
// TODO: Investigate the IsLinux check. I suspect it's really checking for
|
|
|
|
// bare-metal.
|
2014-07-18 22:34:20 +00:00
|
|
|
UseSmallSection = !IsLinux && (TM->getRelocationModel() == Reloc::Static);
|
2007-06-06 07:42:06 +00:00
|
|
|
}
|
2012-03-28 00:24:17 +00:00
|
|
|
|
2014-07-15 22:39:58 +00:00
|
|
|
/// This overrides the PostRAScheduler bit in the SchedModel for any CPU.
|
|
|
|
bool MipsSubtarget::enablePostMachineScheduler() const { return true; }
|
|
|
|
|
|
|
|
void MipsSubtarget::getCriticalPathRCs(RegClassVector &CriticalPathRCs) const {
|
2012-03-28 00:24:17 +00:00
|
|
|
CriticalPathRCs.clear();
|
2014-07-15 22:39:58 +00:00
|
|
|
CriticalPathRCs.push_back(isGP64bit() ?
|
|
|
|
&Mips::GPR64RegClass : &Mips::GPR32RegClass);
|
|
|
|
}
|
|
|
|
|
|
|
|
CodeGenOpt::Level MipsSubtarget::getOptLevelToEnablePostRAScheduler() const {
|
|
|
|
return CodeGenOpt::Aggressive;
|
2012-03-28 00:24:17 +00:00
|
|
|
}
|
2013-04-09 19:46:01 +00:00
|
|
|
|
2014-07-03 00:10:24 +00:00
|
|
|
MipsSubtarget &
|
|
|
|
MipsSubtarget::initializeSubtargetDependencies(StringRef CPU, StringRef FS,
|
|
|
|
const TargetMachine *TM) {
|
2014-07-02 01:14:43 +00:00
|
|
|
std::string CPUName = selectMipsCPU(TargetTriple, CPU);
|
|
|
|
|
|
|
|
// Parse features string.
|
|
|
|
ParseSubtargetFeatures(CPUName, FS);
|
|
|
|
// Initialize scheduling itinerary for the specified CPU.
|
|
|
|
InstrItins = getInstrItineraryForCPU(CPUName);
|
2014-07-03 00:10:24 +00:00
|
|
|
|
2014-07-18 00:08:50 +00:00
|
|
|
if (InMips16Mode && !TM->Options.UseSoftFloat)
|
2014-07-03 00:10:24 +00:00
|
|
|
InMips16HardFloat = true;
|
|
|
|
|
2014-07-02 01:14:43 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2014-07-18 00:08:50 +00:00
|
|
|
bool MipsSubtarget::abiUsesSoftFloat() const {
|
2013-08-30 19:40:56 +00:00
|
|
|
return TM->Options.UseSoftFloat && !InMips16HardFloat;
|
|
|
|
}
|
2013-10-27 21:57:36 +00:00
|
|
|
|
|
|
|
bool MipsSubtarget::useConstantIslands() {
|
|
|
|
DEBUG(dbgs() << "use constant islands " << Mips16ConstantIslands << "\n");
|
|
|
|
return Mips16ConstantIslands;
|
|
|
|
}
|
2014-07-18 22:34:20 +00:00
|
|
|
|
|
|
|
Reloc::Model MipsSubtarget::getRelocationModel() const {
|
|
|
|
return TM->getRelocationModel();
|
|
|
|
}
|