1 //===-- MipsSubtarget.cpp - Mips Subtarget Information --------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the Mips specific subclass of TargetSubtargetInfo.
12 //===----------------------------------------------------------------------===//
14 #define DEBUG_TYPE "mips-subtarget"
16 #include "MipsMachineFunction.h"
17 #include "MipsSubtarget.h"
18 #include "MipsTargetMachine.h"
20 #include "MipsRegisterInfo.h"
21 #include "llvm/IR/Attributes.h"
22 #include "llvm/IR/Function.h"
23 #include "llvm/Support/CommandLine.h"
24 #include "llvm/Support/Debug.h"
25 #include "llvm/Support/TargetRegistry.h"
26 #include "llvm/Support/raw_ostream.h"
28 #define GET_SUBTARGETINFO_TARGET_DESC
29 #define GET_SUBTARGETINFO_CTOR
30 #include "MipsGenSubtargetInfo.inc"
35 // FIXME: Maybe this should be on by default when Mips16 is specified
37 static cl::opt<bool> Mixed16_32(
40 cl::desc("Allow for a mixture of Mips16 "
41 "and Mips32 code in a single source file"),
44 static cl::opt<bool> Mips_Os16(
47 cl::desc("Compile all functions that don' use "
48 "floating point as Mips 16"),
52 Mips16HardFloat("mips16-hard-float", cl::NotHidden,
53 cl::desc("MIPS: mips16 hard float enable."),
56 void MipsSubtarget::anchor() { }
58 MipsSubtarget::MipsSubtarget(const std::string &TT, const std::string &CPU,
59 const std::string &FS, bool little,
60 Reloc::Model _RM, MipsTargetMachine *_TM) :
61 MipsGenSubtargetInfo(TT, CPU, FS),
62 MipsArchVersion(Mips32), MipsABI(UnknownABI), IsLittle(little),
63 IsSingleFloat(false), IsFP64bit(false), IsGP64bit(false), HasVFPU(false),
64 IsLinux(true), HasSEInReg(false), HasCondMov(false), HasSwap(false),
65 HasBitCount(false), HasFPIdx(false),
66 InMips16Mode(false), InMips16HardFloat(Mips16HardFloat),
67 InMicroMipsMode(false), HasDSP(false), HasDSPR2(false),
68 AllowMixed16_32(Mixed16_32 | Mips_Os16), Os16(Mips_Os16), HasMSA(false),
69 RM(_RM), OverrideMode(NoOverride), TM(_TM)
71 std::string CPUName = CPU;
75 // Parse features string.
76 ParseSubtargetFeatures(CPUName, FS);
78 PreviousInMips16Mode = InMips16Mode;
80 // Initialize scheduling itinerary for the specified CPU.
81 InstrItins = getInstrItineraryForCPU(CPUName);
83 // Set MipsABI if it hasn't been set yet.
84 if (MipsABI == UnknownABI)
85 MipsABI = hasMips64() ? N64 : O32;
87 // Check if Architecture and ABI are compatible.
88 assert(((!hasMips64() && (isABI_O32() || isABI_EABI())) ||
89 (hasMips64() && (isABI_N32() || isABI_N64()))) &&
90 "Invalid Arch & ABI pair.");
92 // Is the target system Linux ?
93 if (TT.find("linux") == std::string::npos)
96 // Set UseSmallSection.
97 UseSmallSection = !IsLinux && (RM == Reloc::Static);
98 // set some subtarget specific features
104 MipsSubtarget::enablePostRAScheduler(CodeGenOpt::Level OptLevel,
105 TargetSubtargetInfo::AntiDepBreakMode &Mode,
106 RegClassVector &CriticalPathRCs) const {
107 Mode = TargetSubtargetInfo::ANTIDEP_NONE;
108 CriticalPathRCs.clear();
109 CriticalPathRCs.push_back(hasMips64() ?
110 &Mips::GPR64RegClass : &Mips::GPR32RegClass);
111 return OptLevel >= CodeGenOpt::Aggressive;
114 //FIXME: This logic for reseting the subtarget along with
115 // the helper classes can probably be simplified but there are a lot of
116 // cases so we will defer rewriting this to later.
118 void MipsSubtarget::resetSubtarget(MachineFunction *MF) {
119 bool ChangeToMips16 = false, ChangeToNoMips16 = false;
120 DEBUG(dbgs() << "resetSubtargetFeatures" << "\n");
121 AttributeSet FnAttrs = MF->getFunction()->getAttributes();
122 ChangeToMips16 = FnAttrs.hasAttribute(AttributeSet::FunctionIndex,
124 ChangeToNoMips16 = FnAttrs.hasAttribute(AttributeSet::FunctionIndex,
126 assert (!(ChangeToMips16 & ChangeToNoMips16) &&
127 "mips16 and nomips16 specified on the same function");
128 if (ChangeToMips16) {
129 if (PreviousInMips16Mode)
131 OverrideMode = Mips16Override;
132 PreviousInMips16Mode = true;
133 TM->setHelperClassesMips16();
135 } else if (ChangeToNoMips16) {
136 if (!PreviousInMips16Mode)
138 OverrideMode = NoMips16Override;
139 PreviousInMips16Mode = false;
140 TM->setHelperClassesMipsSE();
143 if (OverrideMode == NoOverride)
145 OverrideMode = NoOverride;
146 DEBUG(dbgs() << "back to default" << "\n");
147 if (inMips16Mode() && !PreviousInMips16Mode) {
148 TM->setHelperClassesMips16();
149 PreviousInMips16Mode = true;
150 } else if (!inMips16Mode() && PreviousInMips16Mode) {
151 TM->setHelperClassesMipsSE();
152 PreviousInMips16Mode = false;
158 bool MipsSubtarget::mipsSEUsesSoftFloat() const {
159 return TM->Options.UseSoftFloat && !InMips16HardFloat;