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 void MipsSubtarget::anchor() { }
46 MipsSubtarget::MipsSubtarget(const std::string &TT, const std::string &CPU,
47 const std::string &FS, bool little,
48 Reloc::Model _RM, MipsTargetMachine *_TM) :
49 MipsGenSubtargetInfo(TT, CPU, FS),
50 MipsArchVersion(Mips32), MipsABI(UnknownABI), IsLittle(little),
51 IsSingleFloat(false), IsFP64bit(false), IsGP64bit(false), HasVFPU(false),
52 IsLinux(true), HasSEInReg(false), HasCondMov(false), HasSwap(false),
53 HasBitCount(false), HasFPIdx(false),
54 InMips16Mode(false), InMicroMipsMode(false), HasDSP(false), HasDSPR2(false),
55 AllowMixed16_32(Mixed16_32),
56 RM(_RM), OverrideMode(NoOverride), TM(_TM)
58 std::string CPUName = CPU;
62 // Parse features string.
63 ParseSubtargetFeatures(CPUName, FS);
65 PreviousInMips16Mode = InMips16Mode;
67 // Initialize scheduling itinerary for the specified CPU.
68 InstrItins = getInstrItineraryForCPU(CPUName);
70 // Set MipsABI if it hasn't been set yet.
71 if (MipsABI == UnknownABI)
72 MipsABI = hasMips64() ? N64 : O32;
74 // Check if Architecture and ABI are compatible.
75 assert(((!hasMips64() && (isABI_O32() || isABI_EABI())) ||
76 (hasMips64() && (isABI_N32() || isABI_N64()))) &&
77 "Invalid Arch & ABI pair.");
79 // Is the target system Linux ?
80 if (TT.find("linux") == std::string::npos)
83 // Set UseSmallSection.
84 UseSmallSection = !IsLinux && (RM == Reloc::Static);
88 MipsSubtarget::enablePostRAScheduler(CodeGenOpt::Level OptLevel,
89 TargetSubtargetInfo::AntiDepBreakMode &Mode,
90 RegClassVector &CriticalPathRCs) const {
91 Mode = TargetSubtargetInfo::ANTIDEP_NONE;
92 CriticalPathRCs.clear();
93 CriticalPathRCs.push_back(hasMips64() ?
94 &Mips::CPU64RegsRegClass : &Mips::CPURegsRegClass);
95 return OptLevel >= CodeGenOpt::Aggressive;
98 //FIXME: This logic for reseting the subtarget along with
99 // the helper classes can probably be simplified but there are a lot of
100 // cases so we will defer rewriting this to later.
102 void MipsSubtarget::resetSubtarget(MachineFunction *MF) {
103 bool ChangeToMips16 = false, ChangeToNoMips16 = false;
104 DEBUG(dbgs() << "resetSubtargetFeatures" << "\n");
105 AttributeSet FnAttrs = MF->getFunction()->getAttributes();
106 ChangeToMips16 = FnAttrs.hasAttribute(AttributeSet::FunctionIndex,
108 ChangeToNoMips16 = FnAttrs.hasAttribute(AttributeSet::FunctionIndex,
110 assert (!(ChangeToMips16 & ChangeToNoMips16) &&
111 "mips16 and nomips16 specified on the same function");
112 if (ChangeToMips16) {
113 if (PreviousInMips16Mode)
115 OverrideMode = Mips16Override;
116 PreviousInMips16Mode = true;
117 TM->setHelperClassesMips16();
119 } else if (ChangeToNoMips16) {
120 if (!PreviousInMips16Mode)
122 OverrideMode = NoMips16Override;
123 PreviousInMips16Mode = false;
124 TM->setHelperClassesMipsSE();
127 if (OverrideMode == NoOverride)
129 OverrideMode = NoOverride;
130 DEBUG(dbgs() << "back to default" << "\n");
131 if (inMips16Mode() && !PreviousInMips16Mode) {
132 TM->setHelperClassesMips16();
133 PreviousInMips16Mode = true;
134 } else if (!inMips16Mode() && PreviousInMips16Mode) {
135 TM->setHelperClassesMipsSE();
136 PreviousInMips16Mode = false;