2012-02-17 16:55:11 +08:00
|
|
|
//===-- MipsSubtarget.cpp - Mips Subtarget Information --------------------===//
|
2007-06-06 15:42:06 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:36:04 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-06-06 15:42:06 +08:00
|
|
|
//
|
2011-04-16 05:51:11 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2007-06-06 15:42:06 +08:00
|
|
|
//
|
2011-07-02 05:01:15 +08:00
|
|
|
// This file implements the Mips specific subclass of TargetSubtargetInfo.
|
2007-06-06 15:42:06 +08:00
|
|
|
//
|
2011-04-16 05:51:11 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2007-06-06 15:42:06 +08:00
|
|
|
|
2013-04-10 03:46:01 +08:00
|
|
|
#define DEBUG_TYPE "mips-subtarget"
|
|
|
|
|
|
|
|
#include "MipsMachineFunction.h"
|
2007-06-06 15:42:06 +08:00
|
|
|
#include "Mips.h"
|
2012-03-28 08:24:17 +08:00
|
|
|
#include "MipsRegisterInfo.h"
|
2014-01-07 19:48:04 +08:00
|
|
|
#include "MipsSubtarget.h"
|
|
|
|
#include "MipsTargetMachine.h"
|
2013-04-10 03:46:01 +08:00
|
|
|
#include "llvm/IR/Attributes.h"
|
|
|
|
#include "llvm/IR/Function.h"
|
|
|
|
#include "llvm/Support/CommandLine.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
2011-08-25 02:08:43 +08:00
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
2013-04-10 03:46:01 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2011-07-02 04:45:01 +08:00
|
|
|
|
|
|
|
#define GET_SUBTARGETINFO_TARGET_DESC
|
2011-07-08 09:53:10 +08:00
|
|
|
#define GET_SUBTARGETINFO_CTOR
|
2011-07-02 06:36:09 +08:00
|
|
|
#include "MipsGenSubtargetInfo.inc"
|
2011-07-02 04:45:01 +08:00
|
|
|
|
2013-04-10 03:46:01 +08:00
|
|
|
|
2007-06-06 15:42:06 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2013-04-10 03:46:01 +08: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-11 00:58:04 +08: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).
llvm-svn: 181641
2013-05-11 06:25:39 +08:00
|
|
|
static cl::opt<bool>
|
|
|
|
Mips16HardFloat("mips16-hard-float", cl::NotHidden,
|
|
|
|
cl::desc("MIPS: mips16 hard float enable."),
|
|
|
|
cl::init(false));
|
|
|
|
|
2013-10-28 05:57:36 +08:00
|
|
|
static cl::opt<bool>
|
|
|
|
Mips16ConstantIslands(
|
2013-11-28 08:56:37 +08:00
|
|
|
"mips16-constant-islands", cl::NotHidden,
|
|
|
|
cl::desc("MIPS: mips16 constant islands enable."),
|
|
|
|
cl::init(true));
|
2013-10-28 05:57:36 +08:00
|
|
|
|
2014-02-20 21:13:33 +08:00
|
|
|
/// Select the Mips CPU for the given triple and cpu name.
|
|
|
|
/// FIXME: Merge with the copy in MipsMCTargetDesc.cpp
|
|
|
|
static inline StringRef selectMipsCPU(StringRef TT, StringRef CPU) {
|
2014-02-26 18:20:15 +08:00
|
|
|
if (CPU.empty() || CPU == "generic") {
|
2014-02-20 21:13:33 +08:00
|
|
|
Triple TheTriple(TT);
|
|
|
|
if (TheTriple.getArch() == Triple::mips ||
|
|
|
|
TheTriple.getArch() == Triple::mipsel)
|
|
|
|
CPU = "mips32";
|
|
|
|
else
|
|
|
|
CPU = "mips64";
|
|
|
|
}
|
|
|
|
return CPU;
|
|
|
|
}
|
|
|
|
|
2011-12-20 10:50:00 +08:00
|
|
|
void MipsSubtarget::anchor() { }
|
|
|
|
|
2011-06-30 09:53:36 +08:00
|
|
|
MipsSubtarget::MipsSubtarget(const std::string &TT, const std::string &CPU,
|
2012-08-22 11:18:13 +08:00
|
|
|
const std::string &FS, bool little,
|
2013-04-10 03:46:01 +08:00
|
|
|
Reloc::Model _RM, MipsTargetMachine *_TM) :
|
2011-07-07 15:07:08 +08:00
|
|
|
MipsGenSubtargetInfo(TT, CPU, FS),
|
2012-02-28 15:46:26 +08:00
|
|
|
MipsArchVersion(Mips32), MipsABI(UnknownABI), IsLittle(little),
|
2011-09-22 01:31:45 +08:00
|
|
|
IsSingleFloat(false), IsFP64bit(false), IsGP64bit(false), HasVFPU(false),
|
2014-03-20 19:51:58 +08:00
|
|
|
HasCnMips(false), IsLinux(true), HasSEInReg(false), HasCondMov(false),
|
|
|
|
HasSwap(false), HasBitCount(false), HasFPIdx(false),
|
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).
llvm-svn: 181641
2013-05-11 06:25:39 +08:00
|
|
|
InMips16Mode(false), InMips16HardFloat(Mips16HardFloat),
|
|
|
|
InMicroMipsMode(false), HasDSP(false), HasDSPR2(false),
|
2013-08-14 04:54:07 +08:00
|
|
|
AllowMixed16_32(Mixed16_32 | Mips_Os16), Os16(Mips_Os16), HasMSA(false),
|
2014-02-06 01:19:30 +08:00
|
|
|
RM(_RM), OverrideMode(NoOverride), TM(_TM), TargetTriple(TT)
|
2007-06-06 15:42:06 +08:00
|
|
|
{
|
2011-06-30 09:53:36 +08:00
|
|
|
std::string CPUName = CPU;
|
2014-02-20 21:13:33 +08:00
|
|
|
CPUName = selectMipsCPU(TT, CPUName);
|
2007-06-06 15:42:06 +08:00
|
|
|
|
|
|
|
// Parse features string.
|
2011-07-07 15:07:08 +08:00
|
|
|
ParseSubtargetFeatures(CPUName, FS);
|
2008-07-14 22:42:54 +08:00
|
|
|
|
2013-11-19 20:20:17 +08:00
|
|
|
if (InMips16Mode && !TM->Options.UseSoftFloat) {
|
|
|
|
// Hard float for mips16 means essentially to compile as soft float
|
|
|
|
// but to use a runtime library for soft float that is written with
|
|
|
|
// native mips32 floating point instructions (those runtime routines
|
|
|
|
// run in mips32 hard float mode).
|
|
|
|
TM->Options.UseSoftFloat = true;
|
|
|
|
TM->Options.FloatABIType = FloatABI::Soft;
|
|
|
|
InMips16HardFloat = true;
|
|
|
|
}
|
|
|
|
|
2013-04-10 03:46:01 +08:00
|
|
|
PreviousInMips16Mode = InMips16Mode;
|
|
|
|
|
2011-07-02 04:45:01 +08:00
|
|
|
// Initialize scheduling itinerary for the specified CPU.
|
|
|
|
InstrItins = getInstrItineraryForCPU(CPUName);
|
|
|
|
|
2014-02-20 22:58:19 +08: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 10:45:29 +08:00
|
|
|
|
|
|
|
// Check if Architecture and ABI are compatible.
|
2014-03-28 00:42:17 +08:00
|
|
|
assert(((!isGP64bit() && (isABI_O32() || isABI_EABI())) ||
|
|
|
|
(isGP64bit() && (isABI_N32() || isABI_N64()))) &&
|
2011-09-21 10:45:29 +08:00
|
|
|
"Invalid Arch & ABI pair.");
|
|
|
|
|
2013-09-27 18:08:31 +08:00
|
|
|
if (hasMSA() && !isFP64bit())
|
|
|
|
report_fatal_error("MSA requires a 64-bit FPU register file (FR=1 mode). "
|
|
|
|
"See -mattr=+fp64.",
|
|
|
|
false);
|
|
|
|
|
2008-07-14 22:42:54 +08:00
|
|
|
// Is the target system Linux ?
|
|
|
|
if (TT.find("linux") == std::string::npos)
|
|
|
|
IsLinux = false;
|
2012-08-22 11:18:13 +08:00
|
|
|
|
|
|
|
// Set UseSmallSection.
|
2014-04-16 20:29:08 +08:00
|
|
|
// TODO: Investigate the IsLinux check. I suspect it's really checking for
|
|
|
|
// bare-metal.
|
2012-08-22 11:18:13 +08:00
|
|
|
UseSmallSection = !IsLinux && (RM == Reloc::Static);
|
2013-08-17 07:05:18 +08:00
|
|
|
// set some subtarget specific features
|
|
|
|
if (inMips16Mode())
|
|
|
|
HasBitCount=false;
|
2007-06-06 15:42:06 +08:00
|
|
|
}
|
2012-03-28 08:24:17 +08:00
|
|
|
|
|
|
|
bool
|
|
|
|
MipsSubtarget::enablePostRAScheduler(CodeGenOpt::Level OptLevel,
|
2012-06-15 05:10:56 +08:00
|
|
|
TargetSubtargetInfo::AntiDepBreakMode &Mode,
|
|
|
|
RegClassVector &CriticalPathRCs) const {
|
2012-05-15 11:14:52 +08:00
|
|
|
Mode = TargetSubtargetInfo::ANTIDEP_NONE;
|
2012-03-28 08:24:17 +08:00
|
|
|
CriticalPathRCs.clear();
|
2014-03-28 00:42:17 +08:00
|
|
|
CriticalPathRCs.push_back(isGP64bit() ? &Mips::GPR64RegClass
|
|
|
|
: &Mips::GPR32RegClass);
|
2012-03-28 08:52:23 +08:00
|
|
|
return OptLevel >= CodeGenOpt::Aggressive;
|
2012-03-28 08:24:17 +08:00
|
|
|
}
|
2013-04-10 03:46:01 +08:00
|
|
|
|
|
|
|
//FIXME: This logic for reseting the subtarget along with
|
|
|
|
// the helper classes can probably be simplified but there are a lot of
|
|
|
|
// cases so we will defer rewriting this to later.
|
|
|
|
//
|
|
|
|
void MipsSubtarget::resetSubtarget(MachineFunction *MF) {
|
|
|
|
bool ChangeToMips16 = false, ChangeToNoMips16 = false;
|
|
|
|
DEBUG(dbgs() << "resetSubtargetFeatures" << "\n");
|
|
|
|
AttributeSet FnAttrs = MF->getFunction()->getAttributes();
|
|
|
|
ChangeToMips16 = FnAttrs.hasAttribute(AttributeSet::FunctionIndex,
|
|
|
|
"mips16");
|
|
|
|
ChangeToNoMips16 = FnAttrs.hasAttribute(AttributeSet::FunctionIndex,
|
|
|
|
"nomips16");
|
|
|
|
assert (!(ChangeToMips16 & ChangeToNoMips16) &&
|
|
|
|
"mips16 and nomips16 specified on the same function");
|
|
|
|
if (ChangeToMips16) {
|
|
|
|
if (PreviousInMips16Mode)
|
|
|
|
return;
|
|
|
|
OverrideMode = Mips16Override;
|
|
|
|
PreviousInMips16Mode = true;
|
|
|
|
TM->setHelperClassesMips16();
|
|
|
|
return;
|
|
|
|
} else if (ChangeToNoMips16) {
|
|
|
|
if (!PreviousInMips16Mode)
|
|
|
|
return;
|
|
|
|
OverrideMode = NoMips16Override;
|
|
|
|
PreviousInMips16Mode = false;
|
|
|
|
TM->setHelperClassesMipsSE();
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
if (OverrideMode == NoOverride)
|
|
|
|
return;
|
|
|
|
OverrideMode = NoOverride;
|
|
|
|
DEBUG(dbgs() << "back to default" << "\n");
|
|
|
|
if (inMips16Mode() && !PreviousInMips16Mode) {
|
|
|
|
TM->setHelperClassesMips16();
|
|
|
|
PreviousInMips16Mode = true;
|
|
|
|
} else if (!inMips16Mode() && PreviousInMips16Mode) {
|
|
|
|
TM->setHelperClassesMipsSE();
|
|
|
|
PreviousInMips16Mode = false;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-31 03:40:56 +08:00
|
|
|
bool MipsSubtarget::mipsSEUsesSoftFloat() const {
|
|
|
|
return TM->Options.UseSoftFloat && !InMips16HardFloat;
|
|
|
|
}
|
2013-10-28 05:57:36 +08:00
|
|
|
|
|
|
|
bool MipsSubtarget::useConstantIslands() {
|
|
|
|
DEBUG(dbgs() << "use constant islands " << Mips16ConstantIslands << "\n");
|
|
|
|
return Mips16ConstantIslands;
|
|
|
|
}
|