blob: dca9966d8a9dd03faae8b97462cc800f180cd353 [file] [log] [blame]
Jia Liuf54f60f2012-02-28 07:46:26 +00001//===-- MipsSubtarget.h - Define Subtarget for the Mips ---------*- C++ -*-===//
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +00007//
Akira Hatanakae2489122011-04-15 21:51:11 +00008//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +00009//
Evan Cheng0d639a22011-07-01 21:01:15 +000010// This file declares the Mips specific subclass of TargetSubtargetInfo.
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000011//
Akira Hatanakae2489122011-04-15 21:51:11 +000012//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000013
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000014#ifndef LLVM_LIB_TARGET_MIPS_MIPSSUBTARGET_H
15#define LLVM_LIB_TARGET_MIPS_MIPSSUBTARGET_H
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000016
Eric Christopherdaa9dbb2014-07-03 00:10:24 +000017#include "MipsFrameLowering.h"
18#include "MipsISelLowering.h"
19#include "MipsInstrInfo.h"
Eric Christopher5f9fd212014-07-02 21:29:23 +000020#include "MipsSelectionDAGInfo.h"
21#include "llvm/IR/DataLayout.h"
Evan Cheng8264e272011-06-29 01:14:12 +000022#include "llvm/MC/MCInstrItineraries.h"
Reed Kotler1595f362013-04-09 19:46:01 +000023#include "llvm/Support/ErrorHandling.h"
Chandler Carruth802d7552012-12-04 07:12:27 +000024#include "llvm/Target/TargetSubtargetInfo.h"
Vladimir Medic636fefe2014-12-17 11:49:56 +000025#include "MCTargetDesc/MipsABIInfo.h"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000026#include <string>
27
Evan Cheng54b68e32011-07-01 20:45:01 +000028#define GET_SUBTARGETINFO_HEADER
Evan Chengc9c090d2011-07-01 22:36:09 +000029#include "MipsGenSubtargetInfo.inc"
Evan Cheng54b68e32011-07-01 20:45:01 +000030
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000031namespace llvm {
Evan Cheng1a72add62011-07-07 07:07:08 +000032class StringRef;
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000033
Reed Kotler1595f362013-04-09 19:46:01 +000034class MipsTargetMachine;
35
Evan Cheng54b68e32011-07-01 20:45:01 +000036class MipsSubtarget : public MipsGenSubtargetInfo {
David Blaikiea379b1812011-12-20 02:50:00 +000037 virtual void anchor();
Bruno Cardoso Lopes87beec92007-08-18 01:52:27 +000038
Daniel Sandersb7f1c6f2014-05-09 09:46:21 +000039 enum MipsArchEnum {
Vasileios Kalintirisb2dd15f2014-11-11 11:43:55 +000040 MipsDefault,
Daniel Sandersb7f1c6f2014-05-09 09:46:21 +000041 Mips1, Mips2, Mips32, Mips32r2, Mips32r6, Mips3, Mips4, Mips5, Mips64,
42 Mips64r2, Mips64r6
43 };
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +000044
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +000045 // Mips architecture version
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +000046 MipsArchEnum MipsArchVersion;
47
Daniel Sanderse2e25da2014-10-24 16:15:27 +000048 // Selected ABI
49 MipsABIInfo ABI;
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +000050
51 // IsLittle - The target is Little Endian
Bruno Cardoso Lopes326a0372008-06-04 01:45:25 +000052 bool IsLittle;
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +000053
54 // IsSingleFloat - The target only supports single precision float
55 // point operations. This enable the target to use all 32 32-bit
Bruno Cardoso Lopes7ceec572008-07-09 04:45:36 +000056 // floating point registers instead of only using even ones.
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +000057 bool IsSingleFloat;
58
Zoran Jovanovic255d00d2014-07-10 15:36:12 +000059 // IsFPXX - MIPS O32 modeless ABI.
60 bool IsFPXX;
61
Daniel Sandersfeb61302014-08-08 15:47:17 +000062 // NoABICalls - Disable SVR4-style position-independent code.
63 bool NoABICalls;
Daniel Sanders35837ac2014-08-08 10:01:29 +000064
Bruno Cardoso Lopes7ceec572008-07-09 04:45:36 +000065 // IsFP64bit - The target processor has 64-bit floating point registers.
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +000066 bool IsFP64bit;
67
Daniel Sanders7e527422014-07-10 13:38:23 +000068 /// Are odd single-precision registers permitted?
69 /// This corresponds to -modd-spreg and -mno-odd-spreg
70 bool UseOddSPReg;
71
Matheus Almeida0051f2d2014-04-16 15:48:55 +000072 // IsNan2008 - IEEE 754-2008 NaN encoding.
73 bool IsNaN2008bit;
74
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +000075 // IsFP64bit - General-purpose registers are 64 bits wide
76 bool IsGP64bit;
77
Bruno Cardoso Lopesbcc21392008-07-09 05:32:22 +000078 // HasVFPU - Processor has a vector floating point unit.
79 bool HasVFPU;
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +000080
Kai Nacke93fe5e82014-03-20 11:51:58 +000081 // CPU supports cnMIPS (Cavium Networks Octeon CPU).
82 bool HasCnMips;
83
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +000084 // isLinux - Target system is Linux. Is false we consider ELFOS for now.
85 bool IsLinux;
86
Akira Hatanakaad495022012-08-22 03:18:13 +000087 // UseSmallSection - Small section is used.
88 bool UseSmallSection;
89
Bruno Cardoso Lopesf714e252008-07-30 17:01:06 +000090 /// Features related to the presence of specific instructions.
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +000091
Daniel Sandersf2056be2014-05-09 13:02:27 +000092 // HasMips3_32 - The subset of MIPS-III instructions added to MIPS32
93 bool HasMips3_32;
94
Daniel Sanders387fc152014-05-13 11:45:36 +000095 // HasMips3_32r2 - The subset of MIPS-III instructions added to MIPS32r2
96 bool HasMips3_32r2;
97
Daniel Sanders94eda2e2014-05-12 11:56:16 +000098 // HasMips4_32 - Has the subset of MIPS-IV present in MIPS32
Daniel Sanderse57d8662014-05-09 14:06:17 +000099 bool HasMips4_32;
100
Daniel Sanders94eda2e2014-05-12 11:56:16 +0000101 // HasMips4_32r2 - Has the subset of MIPS-IV present in MIPS32r2
102 bool HasMips4_32r2;
103
Daniel Sanders07cdea22014-05-12 12:52:44 +0000104 // HasMips5_32r2 - Has the subset of MIPS-V present in MIPS32r2
105 bool HasMips5_32r2;
106
Akira Hatanaka0faaebf2012-05-16 22:19:56 +0000107 // InMips16 -- can process Mips16 instructions
108 bool InMips16Mode;
109
Reed Kotler783c7942013-05-10 22:25:39 +0000110 // Mips16 hard float
111 bool InMips16HardFloat;
112
Reed Kotler1595f362013-04-09 19:46:01 +0000113 // PreviousInMips16 -- the function we just processed was in Mips 16 Mode
114 bool PreviousInMips16Mode;
115
Jack Carter428a06c2013-02-05 09:30:03 +0000116 // InMicroMips -- can process MicroMips instructions
117 bool InMicroMipsMode;
118
Akira Hatanaka65ce9312012-09-21 23:41:49 +0000119 // HasDSP, HasDSPR2 -- supports DSP ASE.
120 bool HasDSP, HasDSPR2;
121
Reed Kotler1595f362013-04-09 19:46:01 +0000122 // Allow mixed Mips16 and Mips32 in one source file
123 bool AllowMixed16_32;
124
Reed Kotlerfe94cc32013-04-10 16:58:04 +0000125 // Optimize for space by compiling all functions as Mips 16 unless
126 // it needs floating point. Functions needing floating point are
127 // compiled as Mips32
128 bool Os16;
129
Jack Carter3a2c2d42013-08-13 20:54:07 +0000130 // HasMSA -- supports MSA ASE.
131 bool HasMSA;
132
Bruno Cardoso Lopes87beec92007-08-18 01:52:27 +0000133 InstrItineraryData InstrItins;
134
Reed Kotler1595f362013-04-09 19:46:01 +0000135 // We can override the determination of whether we are in mips16 mode
136 // as from the command line
137 enum {NoOverride, Mips16Override, NoMips16Override} OverrideMode;
138
Eric Christopherb1526602014-09-19 23:30:42 +0000139 const MipsTargetMachine *TM;
Reed Kotler1595f362013-04-09 19:46:01 +0000140
Petar Jovanovic97250162014-02-05 17:19:30 +0000141 Triple TargetTriple;
Eric Christopher1f51ddd2014-07-02 00:54:12 +0000142
Eric Christopher5f9fd212014-07-02 21:29:23 +0000143 const DataLayout DL; // Calculates type size & alignment
144 const MipsSelectionDAGInfo TSInfo;
Eric Christopherdaa9dbb2014-07-03 00:10:24 +0000145 std::unique_ptr<const MipsInstrInfo> InstrInfo;
146 std::unique_ptr<const MipsFrameLowering> FrameLowering;
147 std::unique_ptr<const MipsTargetLowering> TLInfo;
Eric Christopher5f9fd212014-07-02 21:29:23 +0000148
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000149public:
Sanjay Patela2f658d2014-07-15 22:39:58 +0000150 /// This overrides the PostRAScheduler bit in the SchedModel for each CPU.
151 bool enablePostMachineScheduler() const override;
152 void getCriticalPathRCs(RegClassVector &CriticalPathRCs) const override;
153 CodeGenOpt::Level getOptLevelToEnablePostRAScheduler() const override;
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +0000154
155 /// Only O32 and EABI supported right now.
Daniel Sanderse2e25da2014-10-24 16:15:27 +0000156 bool isABI_EABI() const { return ABI.IsEABI(); }
157 bool isABI_N64() const { return ABI.IsN64(); }
158 bool isABI_N32() const { return ABI.IsN32(); }
159 bool isABI_O32() const { return ABI.IsO32(); }
Sasa Stankovicb976fee2014-07-14 09:40:29 +0000160 bool isABI_FPXX() const { return isABI_O32() && IsFPXX; }
Daniel Sanderse2e25da2014-10-24 16:15:27 +0000161 const MipsABIInfo &getABI() const { return ABI; }
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +0000162
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000163 /// This constructor initializes the data members to match that
Daniel Dunbar31b44e82009-08-02 22:11:08 +0000164 /// of the specified triple.
Evan Chengfe6e4052011-06-30 01:53:36 +0000165 MipsSubtarget(const std::string &TT, const std::string &CPU,
Eric Christopherb1526602014-09-19 23:30:42 +0000166 const std::string &FS, bool little,
167 const MipsTargetMachine *TM);
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000168
169 /// ParseSubtargetFeatures - Parses features string setting specified
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000170 /// subtarget options. Definition of function is auto generated by tblgen.
Evan Cheng1a72add62011-07-07 07:07:08 +0000171 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000172
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000173 bool hasMips1() const { return MipsArchVersion >= Mips1; }
Daniel Sandersd39320c2014-05-08 12:40:48 +0000174 bool hasMips2() const { return MipsArchVersion >= Mips2; }
Daniel Sandersf2056be2014-05-09 13:02:27 +0000175 bool hasMips3() const { return MipsArchVersion >= Mips3; }
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000176 bool hasMips4() const { return MipsArchVersion >= Mips4; }
177 bool hasMips5() const { return MipsArchVersion >= Mips5; }
Daniel Sanderse57d8662014-05-09 14:06:17 +0000178 bool hasMips4_32() const { return HasMips4_32; }
Daniel Sanders94eda2e2014-05-12 11:56:16 +0000179 bool hasMips4_32r2() const { return HasMips4_32r2; }
Daniel Sanders00463112014-06-16 13:18:59 +0000180 bool hasMips32() const {
181 return MipsArchVersion >= Mips32 && MipsArchVersion != Mips3 &&
182 MipsArchVersion != Mips4 && MipsArchVersion != Mips5;
183 }
Daniel Sanders1f6f0f42014-06-12 11:55:58 +0000184 bool hasMips32r2() const {
185 return MipsArchVersion == Mips32r2 || MipsArchVersion == Mips32r6 ||
Daniel Sanders6a803f62014-06-16 13:13:03 +0000186 MipsArchVersion == Mips64r2 || MipsArchVersion == Mips64r6;
Daniel Sanders1f6f0f42014-06-12 11:55:58 +0000187 }
188 bool hasMips32r6() const {
189 return MipsArchVersion == Mips32r6 || MipsArchVersion == Mips64r6;
190 }
Akira Hatanaka6e506eb2011-09-21 02:24:25 +0000191 bool hasMips64() const { return MipsArchVersion >= Mips64; }
Daniel Sanders1f6f0f42014-06-12 11:55:58 +0000192 bool hasMips64r2() const {
193 return MipsArchVersion == Mips64r2 || MipsArchVersion == Mips64r6;
194 }
Daniel Sandersb7f1c6f2014-05-09 09:46:21 +0000195 bool hasMips64r6() const { return MipsArchVersion == Mips64r6; }
Bruno Cardoso Lopes326a0372008-06-04 01:45:25 +0000196
Kai Nacke93fe5e82014-03-20 11:51:58 +0000197 bool hasCnMips() const { return HasCnMips; }
198
Bruno Cardoso Lopes326a0372008-06-04 01:45:25 +0000199 bool isLittle() const { return IsLittle; }
Daniel Sandersfeb61302014-08-08 15:47:17 +0000200 bool isABICalls() const { return !NoABICalls; }
Zoran Jovanovic255d00d2014-07-10 15:36:12 +0000201 bool isFPXX() const { return IsFPXX; }
Douglas Gregor740ab382009-12-19 07:05:23 +0000202 bool isFP64bit() const { return IsFP64bit; }
Daniel Sanders7e527422014-07-10 13:38:23 +0000203 bool useOddSPReg() const { return UseOddSPReg; }
Sasa Stankovicf4a9e3b2014-07-29 14:39:24 +0000204 bool noOddSPReg() const { return !UseOddSPReg; }
Matheus Almeida0051f2d2014-04-16 15:48:55 +0000205 bool isNaN2008() const { return IsNaN2008bit; }
Douglas Gregor740ab382009-12-19 07:05:23 +0000206 bool isGP64bit() const { return IsGP64bit; }
207 bool isGP32bit() const { return !IsGP64bit; }
Daniel Sanders2b746bc2014-09-09 12:11:16 +0000208 unsigned getGPRSizeInBytes() const { return isGP64bit() ? 8 : 4; }
Douglas Gregor740ab382009-12-19 07:05:23 +0000209 bool isSingleFloat() const { return IsSingleFloat; }
Douglas Gregor740ab382009-12-19 07:05:23 +0000210 bool hasVFPU() const { return HasVFPU; }
Eric Christopher4e7d1e72014-07-18 23:41:32 +0000211 bool inMips16Mode() const { return InMips16Mode; }
Reed Kotler783c7942013-05-10 22:25:39 +0000212 bool inMips16ModeDefault() const {
Reed Kotler1595f362013-04-09 19:46:01 +0000213 return InMips16Mode;
214 }
Eric Christopher7394e232014-07-18 00:08:50 +0000215 // Hard float for mips16 means essentially to compile as soft float
216 // but to use a runtime library for soft float that is written with
217 // native mips32 floating point instructions (those runtime routines
218 // run in mips32 hard float mode).
Reed Kotler783c7942013-05-10 22:25:39 +0000219 bool inMips16HardFloat() const {
220 return inMips16Mode() && InMips16HardFloat;
221 }
Jack Carter428a06c2013-02-05 09:30:03 +0000222 bool inMicroMipsMode() const { return InMicroMipsMode; }
Akira Hatanaka65ce9312012-09-21 23:41:49 +0000223 bool hasDSP() const { return HasDSP; }
224 bool hasDSPR2() const { return HasDSPR2; }
Jack Carter3a2c2d42013-08-13 20:54:07 +0000225 bool hasMSA() const { return HasMSA; }
Akira Hatanakaad495022012-08-22 03:18:13 +0000226 bool useSmallSection() const { return UseSmallSection; }
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +0000227
Akira Hatanakacdf4fd82012-05-22 03:10:09 +0000228 bool hasStandardEncoding() const { return !inMips16Mode(); }
229
Eric Christopher7394e232014-07-18 00:08:50 +0000230 bool abiUsesSoftFloat() const;
Reed Kotlerc03807a2013-08-30 19:40:56 +0000231
Akira Hatanakaa8a05be2013-10-07 19:06:57 +0000232 bool enableLongBranchPass() const {
233 return hasStandardEncoding() || allowMixed16_32();
234 }
235
Bruno Cardoso Lopesf714e252008-07-30 17:01:06 +0000236 /// Features related to the presence of specific instructions.
Akira Hatanaka4a3836b2013-10-09 23:36:17 +0000237 bool hasExtractInsert() const { return !inMips16Mode() && hasMips32r2(); }
Sasa Stankovicb976fee2014-07-14 09:40:29 +0000238 bool hasMTHC1() const { return hasMips32r2(); }
Jack Carterc1b17ed2013-01-18 21:20:38 +0000239
Reed Kotler783c7942013-05-10 22:25:39 +0000240 bool allowMixed16_32() const { return inMips16ModeDefault() |
241 AllowMixed16_32;}
Reed Kotler1595f362013-04-09 19:46:01 +0000242
Reed Kotlerfe94cc32013-04-10 16:58:04 +0000243 bool os16() const { return Os16;};
244
Petar Jovanovic97250162014-02-05 17:19:30 +0000245 bool isTargetNaCl() const { return TargetTriple.isOSNaCl(); }
246
Daniel Sanders82cd99a2014-04-16 14:38:27 +0000247 // for now constant islands are on for the whole compilation unit but we only
248 // really use them if in addition we are in mips16 mode
249 static bool useConstantIslands();
Akira Hatanaka6b2d8412013-10-29 19:29:03 +0000250
Akira Hatanaka8f1caeb2013-11-11 21:49:03 +0000251 unsigned stackAlignment() const { return hasMips64() ? 16 : 8; }
Akira Hatanaka6b2d8412013-10-29 19:29:03 +0000252
Jack Carter7f378102013-01-30 02:16:36 +0000253 // Grab relocation model
Eric Christopherf74faf42014-07-18 22:34:20 +0000254 Reloc::Model getRelocationModel() const;
Reed Kotler1595f362013-04-09 19:46:01 +0000255
Eric Christopherdaa9dbb2014-07-03 00:10:24 +0000256 MipsSubtarget &initializeSubtargetDependencies(StringRef CPU, StringRef FS,
257 const TargetMachine *TM);
Eric Christopher5b336a22014-07-02 01:14:43 +0000258
Daniel Sandersac272632014-05-23 13:18:02 +0000259 /// Does the system support unaligned memory access.
260 ///
261 /// MIPS32r6/MIPS64r6 require full unaligned access support but does not
262 /// specify which component of the system provides it. Hardware, software, and
263 /// hybrid implementations are all valid.
264 bool systemSupportsUnalignedAccess() const { return hasMips32r6(); }
Eric Christopher1f51ddd2014-07-02 00:54:12 +0000265
Eric Christopherdaa9dbb2014-07-03 00:10:24 +0000266 // Set helper classes
267 void setHelperClassesMips16();
268 void setHelperClassesMipsSE();
269
Eric Christopherd9134482014-08-04 21:25:23 +0000270 const MipsSelectionDAGInfo *getSelectionDAGInfo() const override {
271 return &TSInfo;
272 }
273 const DataLayout *getDataLayout() const override { return &DL; }
274 const MipsInstrInfo *getInstrInfo() const override { return InstrInfo.get(); }
275 const TargetFrameLowering *getFrameLowering() const override {
Eric Christopherdaa9dbb2014-07-03 00:10:24 +0000276 return FrameLowering.get();
277 }
Eric Christopherd9134482014-08-04 21:25:23 +0000278 const MipsRegisterInfo *getRegisterInfo() const override {
Eric Christopherdaa9dbb2014-07-03 00:10:24 +0000279 return &InstrInfo->getRegisterInfo();
280 }
Eric Christopherd9134482014-08-04 21:25:23 +0000281 const MipsTargetLowering *getTargetLowering() const override {
282 return TLInfo.get();
283 }
284 const InstrItineraryData *getInstrItineraryData() const override {
285 return &InstrItins;
286 }
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000287};
288} // End llvm namespace
289
290#endif