MipsSubtarget.cpp revision f1ef27e6e308435035ffec112a6474ed5e009484
1//===-- MipsSubtarget.cpp - Mips Subtarget Information --------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the Mips specific subclass of TargetSubtargetInfo.
11//
12//===----------------------------------------------------------------------===//
13
14#define DEBUG_TYPE "mips-subtarget"
15
16#include "MipsMachineFunction.h"
17#include "MipsSubtarget.h"
18#include "MipsTargetMachine.h"
19#include "Mips.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"
27
28#define GET_SUBTARGETINFO_TARGET_DESC
29#define GET_SUBTARGETINFO_CTOR
30#include "MipsGenSubtargetInfo.inc"
31
32
33using namespace llvm;
34
35// FIXME: Maybe this should be on by default when Mips16 is specified
36//
37static cl::opt<bool> Mixed16_32(
38  "mips-mixed-16-32",
39  cl::init(false),
40  cl::desc("Allow for a mixture of Mips16 "
41           "and Mips32 code in a single source file"),
42  cl::Hidden);
43
44static cl::opt<bool> Mips_Os16(
45  "mips-os16",
46  cl::init(false),
47  cl::desc("Compile all functions that don' use "
48           "floating point as Mips 16"),
49  cl::Hidden);
50
51static cl::opt<bool>
52Mips16HardFloat("mips16-hard-float", cl::NotHidden,
53                cl::desc("MIPS: mips16 hard float enable."),
54                cl::init(false));
55
56void MipsSubtarget::anchor() { }
57
58MipsSubtarget::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)
70{
71  std::string CPUName = CPU;
72  if (CPUName.empty())
73    CPUName = "mips32";
74
75  // Parse features string.
76  ParseSubtargetFeatures(CPUName, FS);
77
78  PreviousInMips16Mode = InMips16Mode;
79
80  // Initialize scheduling itinerary for the specified CPU.
81  InstrItins = getInstrItineraryForCPU(CPUName);
82
83  // Set MipsABI if it hasn't been set yet.
84  if (MipsABI == UnknownABI)
85    MipsABI = hasMips64() ? N64 : O32;
86
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.");
91
92  if (hasMSA() && !isFP64bit())
93    report_fatal_error("MSA requires a 64-bit FPU register file (FR=1 mode). "
94                       "See -mattr=+fp64.",
95                       false);
96
97  // Is the target system Linux ?
98  if (TT.find("linux") == std::string::npos)
99    IsLinux = false;
100
101  // Set UseSmallSection.
102  UseSmallSection = !IsLinux && (RM == Reloc::Static);
103  // set some subtarget specific features
104  if (inMips16Mode())
105    HasBitCount=false;
106}
107
108bool
109MipsSubtarget::enablePostRAScheduler(CodeGenOpt::Level OptLevel,
110                                    TargetSubtargetInfo::AntiDepBreakMode &Mode,
111                                     RegClassVector &CriticalPathRCs) const {
112  Mode = TargetSubtargetInfo::ANTIDEP_NONE;
113  CriticalPathRCs.clear();
114  CriticalPathRCs.push_back(hasMips64() ?
115                            &Mips::GPR64RegClass : &Mips::GPR32RegClass);
116  return OptLevel >= CodeGenOpt::Aggressive;
117}
118
119//FIXME: This logic for reseting the subtarget along with
120// the helper classes can probably be simplified but there are a lot of
121// cases so we will defer rewriting this to later.
122//
123void MipsSubtarget::resetSubtarget(MachineFunction *MF) {
124  bool ChangeToMips16 = false, ChangeToNoMips16 = false;
125  DEBUG(dbgs() << "resetSubtargetFeatures" << "\n");
126  AttributeSet FnAttrs = MF->getFunction()->getAttributes();
127  ChangeToMips16 = FnAttrs.hasAttribute(AttributeSet::FunctionIndex,
128                                        "mips16");
129  ChangeToNoMips16 = FnAttrs.hasAttribute(AttributeSet::FunctionIndex,
130                                        "nomips16");
131  assert (!(ChangeToMips16 & ChangeToNoMips16) &&
132          "mips16 and nomips16 specified on the same function");
133  if (ChangeToMips16) {
134    if (PreviousInMips16Mode)
135      return;
136    OverrideMode = Mips16Override;
137    PreviousInMips16Mode = true;
138    TM->setHelperClassesMips16();
139    return;
140  } else if (ChangeToNoMips16) {
141    if (!PreviousInMips16Mode)
142      return;
143    OverrideMode = NoMips16Override;
144    PreviousInMips16Mode = false;
145    TM->setHelperClassesMipsSE();
146    return;
147  } else {
148    if (OverrideMode == NoOverride)
149      return;
150    OverrideMode = NoOverride;
151    DEBUG(dbgs() << "back to default" << "\n");
152    if (inMips16Mode() && !PreviousInMips16Mode) {
153      TM->setHelperClassesMips16();
154      PreviousInMips16Mode = true;
155    } else if (!inMips16Mode() && PreviousInMips16Mode) {
156      TM->setHelperClassesMipsSE();
157      PreviousInMips16Mode = false;
158    }
159    return;
160  }
161}
162
163bool MipsSubtarget::mipsSEUsesSoftFloat() const {
164  return TM->Options.UseSoftFloat && !InMips16HardFloat;
165}
166