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
|
|
|
#define DEBUG_TYPE "mips-subtarget"
|
|
|
|
|
|
|
|
#include "MipsMachineFunction.h"
|
2007-06-06 07:42:06 +00:00
|
|
|
#include "MipsSubtarget.h"
|
2013-04-09 19:46:01 +00:00
|
|
|
#include "MipsTargetMachine.h"
|
2007-06-06 07:42:06 +00:00
|
|
|
#include "Mips.h"
|
2012-03-28 00:24:17 +00:00
|
|
|
#include "MipsRegisterInfo.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
|
|
|
|
|
|
|
#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
|
|
|
|
2007-06-06 07:42:06 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
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);
|
|
|
|
|
2011-12-20 02:50:00 +00:00
|
|
|
void MipsSubtarget::anchor() { }
|
|
|
|
|
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,
|
2013-04-09 19:46:01 +00:00
|
|
|
Reloc::Model _RM, MipsTargetMachine *_TM) :
|
2011-07-07 07:07:08 +00:00
|
|
|
MipsGenSubtargetInfo(TT, CPU, FS),
|
2012-02-28 07:46:26 +00:00
|
|
|
MipsArchVersion(Mips32), MipsABI(UnknownABI), IsLittle(little),
|
2011-09-21 17:31:45 +00:00
|
|
|
IsSingleFloat(false), IsFP64bit(false), IsGP64bit(false), HasVFPU(false),
|
2012-12-07 03:04:05 +00:00
|
|
|
IsLinux(true), HasSEInReg(false), HasCondMov(false), HasSwap(false),
|
|
|
|
HasBitCount(false), HasFPIdx(false),
|
2013-02-05 09:30:03 +00:00
|
|
|
InMips16Mode(false), InMicroMipsMode(false), HasDSP(false), HasDSPR2(false),
|
2013-04-10 16:58:04 +00:00
|
|
|
AllowMixed16_32(Mixed16_32 | Mips_Os16), Os16(Mips_Os16),
|
2013-04-09 19:46:01 +00:00
|
|
|
RM(_RM), OverrideMode(NoOverride), TM(_TM)
|
2007-06-06 07:42:06 +00:00
|
|
|
{
|
2011-06-30 01:53:36 +00:00
|
|
|
std::string CPUName = CPU;
|
|
|
|
if (CPUName.empty())
|
2011-11-29 23:08:41 +00:00
|
|
|
CPUName = "mips32";
|
2007-06-06 07:42:06 +00:00
|
|
|
|
|
|
|
// Parse features string.
|
2011-07-07 07:07:08 +00:00
|
|
|
ParseSubtargetFeatures(CPUName, FS);
|
2008-07-14 14:42:54 +00:00
|
|
|
|
2013-04-09 19:46:01 +00:00
|
|
|
PreviousInMips16Mode = InMips16Mode;
|
|
|
|
|
2011-07-01 20:45:01 +00:00
|
|
|
// Initialize scheduling itinerary for the specified CPU.
|
|
|
|
InstrItins = getInstrItineraryForCPU(CPUName);
|
|
|
|
|
2011-09-21 02:45:29 +00:00
|
|
|
// Set MipsABI if it hasn't been set yet.
|
|
|
|
if (MipsABI == UnknownABI)
|
2012-02-28 07:46:26 +00:00
|
|
|
MipsABI = hasMips64() ? N64 : O32;
|
2011-09-21 02:45:29 +00:00
|
|
|
|
|
|
|
// Check if Architecture and ABI are compatible.
|
|
|
|
assert(((!hasMips64() && (isABI_O32() || isABI_EABI())) ||
|
|
|
|
(hasMips64() && (isABI_N32() || isABI_N64()))) &&
|
|
|
|
"Invalid Arch & ABI pair.");
|
|
|
|
|
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.
|
|
|
|
UseSmallSection = !IsLinux && (RM == Reloc::Static);
|
2007-06-06 07:42:06 +00:00
|
|
|
}
|
2012-03-28 00:24:17 +00:00
|
|
|
|
|
|
|
bool
|
|
|
|
MipsSubtarget::enablePostRAScheduler(CodeGenOpt::Level OptLevel,
|
2012-06-14 21:10:56 +00:00
|
|
|
TargetSubtargetInfo::AntiDepBreakMode &Mode,
|
|
|
|
RegClassVector &CriticalPathRCs) const {
|
2012-05-15 03:14:52 +00:00
|
|
|
Mode = TargetSubtargetInfo::ANTIDEP_NONE;
|
2012-03-28 00:24:17 +00:00
|
|
|
CriticalPathRCs.clear();
|
|
|
|
CriticalPathRCs.push_back(hasMips64() ?
|
|
|
|
&Mips::CPU64RegsRegClass : &Mips::CPURegsRegClass);
|
2012-03-28 00:52:23 +00:00
|
|
|
return OptLevel >= CodeGenOpt::Aggressive;
|
2012-03-28 00:24:17 +00:00
|
|
|
}
|
2013-04-09 19:46:01 +00: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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|