blob: 7c175537a725b7d5052697a8c7e844ec2a4aa677 [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
14#ifndef MIPSSUBTARGET_H
15#define MIPSSUBTARGET_H
16
Jack Carterc1b17ed2013-01-18 21:20:38 +000017#include "MCTargetDesc/MipsReginfo.h"
Evan Cheng8264e272011-06-29 01:14:12 +000018#include "llvm/MC/MCInstrItineraries.h"
Reed Kotler1595f362013-04-09 19:46:01 +000019#include "llvm/Support/ErrorHandling.h"
Chandler Carruth802d7552012-12-04 07:12:27 +000020#include "llvm/Target/TargetSubtargetInfo.h"
Reed Kotler1595f362013-04-09 19:46:01 +000021
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000022#include <string>
23
Evan Cheng54b68e32011-07-01 20:45:01 +000024#define GET_SUBTARGETINFO_HEADER
Evan Chengc9c090d2011-07-01 22:36:09 +000025#include "MipsGenSubtargetInfo.inc"
Evan Cheng54b68e32011-07-01 20:45:01 +000026
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000027namespace llvm {
Evan Cheng1a72add62011-07-07 07:07:08 +000028class StringRef;
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000029
Reed Kotler1595f362013-04-09 19:46:01 +000030class MipsTargetMachine;
31
Evan Cheng54b68e32011-07-01 20:45:01 +000032class MipsSubtarget : public MipsGenSubtargetInfo {
David Blaikiea379b1812011-12-20 02:50:00 +000033 virtual void anchor();
Bruno Cardoso Lopes87beec92007-08-18 01:52:27 +000034
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +000035public:
Akira Hatanaka3efff6c2011-09-14 17:22:51 +000036 // NOTE: O64 will not be supported.
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +000037 enum MipsABIEnum {
Akira Hatanaka6de4d122011-09-21 02:45:29 +000038 UnknownABI, O32, N32, N64, EABI
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +000039 };
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +000040
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000041protected:
Bruno Cardoso Lopes87beec92007-08-18 01:52:27 +000042
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +000043 enum MipsArchEnum {
Akira Hatanaka2b372612011-09-20 20:28:08 +000044 Mips32, Mips32r2, Mips64, Mips64r2
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +000045 };
46
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +000047 // Mips architecture version
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +000048 MipsArchEnum MipsArchVersion;
49
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +000050 // Mips supported ABIs
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +000051 MipsABIEnum MipsABI;
52
53 // IsLittle - The target is Little Endian
Bruno Cardoso Lopes326a0372008-06-04 01:45:25 +000054 bool IsLittle;
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +000055
56 // IsSingleFloat - The target only supports single precision float
57 // point operations. This enable the target to use all 32 32-bit
Bruno Cardoso Lopes7ceec572008-07-09 04:45:36 +000058 // floating point registers instead of only using even ones.
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +000059 bool IsSingleFloat;
60
Bruno Cardoso Lopes7ceec572008-07-09 04:45:36 +000061 // IsFP64bit - The target processor has 64-bit floating point registers.
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +000062 bool IsFP64bit;
63
64 // IsFP64bit - General-purpose registers are 64 bits wide
65 bool IsGP64bit;
66
Bruno Cardoso Lopesbcc21392008-07-09 05:32:22 +000067 // HasVFPU - Processor has a vector floating point unit.
68 bool HasVFPU;
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +000069
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +000070 // isLinux - Target system is Linux. Is false we consider ELFOS for now.
71 bool IsLinux;
72
Akira Hatanakaad495022012-08-22 03:18:13 +000073 // UseSmallSection - Small section is used.
74 bool UseSmallSection;
75
Bruno Cardoso Lopesf714e252008-07-30 17:01:06 +000076 /// Features related to the presence of specific instructions.
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +000077
Bruno Cardoso Lopesf714e252008-07-30 17:01:06 +000078 // HasSEInReg - SEB and SEH (signext in register) instructions.
79 bool HasSEInReg;
80
81 // HasCondMov - Conditional mov (MOVZ, MOVN) instructions.
82 bool HasCondMov;
83
Bruno Cardoso Lopesf714e252008-07-30 17:01:06 +000084 // HasSwap - Byte and half swap instructions.
85 bool HasSwap;
86
87 // HasBitCount - Count leading '1' and '0' bits.
88 bool HasBitCount;
89
Akira Hatanaka3bc1beb2012-11-15 21:17:13 +000090 // HasFPIdx -- Floating point indexed load/store instructions.
91 bool HasFPIdx;
92
Akira Hatanaka0faaebf2012-05-16 22:19:56 +000093 // InMips16 -- can process Mips16 instructions
94 bool InMips16Mode;
95
Reed Kotler783c7942013-05-10 22:25:39 +000096 // Mips16 hard float
97 bool InMips16HardFloat;
98
Reed Kotler1595f362013-04-09 19:46:01 +000099 // PreviousInMips16 -- the function we just processed was in Mips 16 Mode
100 bool PreviousInMips16Mode;
101
Jack Carter428a06c2013-02-05 09:30:03 +0000102 // InMicroMips -- can process MicroMips instructions
103 bool InMicroMipsMode;
104
Akira Hatanaka65ce9312012-09-21 23:41:49 +0000105 // HasDSP, HasDSPR2 -- supports DSP ASE.
106 bool HasDSP, HasDSPR2;
107
Reed Kotler1595f362013-04-09 19:46:01 +0000108 // Allow mixed Mips16 and Mips32 in one source file
109 bool AllowMixed16_32;
110
Reed Kotlerfe94cc32013-04-10 16:58:04 +0000111 // Optimize for space by compiling all functions as Mips 16 unless
112 // it needs floating point. Functions needing floating point are
113 // compiled as Mips32
114 bool Os16;
115
Jack Carter3a2c2d42013-08-13 20:54:07 +0000116 // HasMSA -- supports MSA ASE.
117 bool HasMSA;
118
Bruno Cardoso Lopes87beec92007-08-18 01:52:27 +0000119 InstrItineraryData InstrItins;
120
Jack Carterc1b17ed2013-01-18 21:20:38 +0000121 // The instance to the register info section object
122 MipsReginfo MRI;
123
Jack Carter7f378102013-01-30 02:16:36 +0000124 // Relocation Model
125 Reloc::Model RM;
126
Reed Kotler1595f362013-04-09 19:46:01 +0000127 // We can override the determination of whether we are in mips16 mode
128 // as from the command line
129 enum {NoOverride, Mips16Override, NoMips16Override} OverrideMode;
130
131 MipsTargetMachine *TM;
132
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000133public:
Akira Hatanaka047473e2012-03-28 00:24:17 +0000134 virtual bool enablePostRAScheduler(CodeGenOpt::Level OptLevel,
135 AntiDepBreakMode& Mode,
136 RegClassVector& CriticalPathRCs) const;
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +0000137
138 /// Only O32 and EABI supported right now.
139 bool isABI_EABI() const { return MipsABI == EABI; }
Akira Hatanaka2b372612011-09-20 20:28:08 +0000140 bool isABI_N64() const { return MipsABI == N64; }
141 bool isABI_N32() const { return MipsABI == N32; }
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +0000142 bool isABI_O32() const { return MipsABI == O32; }
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +0000143 unsigned getTargetABI() const { return MipsABI; }
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +0000144
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000145 /// This constructor initializes the data members to match that
Daniel Dunbar31b44e82009-08-02 22:11:08 +0000146 /// of the specified triple.
Evan Chengfe6e4052011-06-30 01:53:36 +0000147 MipsSubtarget(const std::string &TT, const std::string &CPU,
Reed Kotler1595f362013-04-09 19:46:01 +0000148 const std::string &FS, bool little, Reloc::Model RM,
149 MipsTargetMachine *TM);
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000150
151 /// ParseSubtargetFeatures - Parses features string setting specified
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000152 /// subtarget options. Definition of function is auto generated by tblgen.
Evan Cheng1a72add62011-07-07 07:07:08 +0000153 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000154
Akira Hatanakabb49e722011-09-20 23:53:09 +0000155 bool hasMips32() const { return MipsArchVersion >= Mips32; }
156 bool hasMips32r2() const { return MipsArchVersion == Mips32r2 ||
Akira Hatanaka2b372612011-09-20 20:28:08 +0000157 MipsArchVersion == Mips64r2; }
Akira Hatanaka6e506eb2011-09-21 02:24:25 +0000158 bool hasMips64() const { return MipsArchVersion >= Mips64; }
159 bool hasMips64r2() const { return MipsArchVersion == Mips64r2; }
Bruno Cardoso Lopes326a0372008-06-04 01:45:25 +0000160
Bruno Cardoso Lopes326a0372008-06-04 01:45:25 +0000161 bool isLittle() const { return IsLittle; }
Douglas Gregor740ab382009-12-19 07:05:23 +0000162 bool isFP64bit() const { return IsFP64bit; }
Akira Hatanakabfb66242013-08-20 23:38:40 +0000163 bool isNotFP64bit() const { return !IsFP64bit; }
Douglas Gregor740ab382009-12-19 07:05:23 +0000164 bool isGP64bit() const { return IsGP64bit; }
165 bool isGP32bit() const { return !IsGP64bit; }
166 bool isSingleFloat() const { return IsSingleFloat; }
167 bool isNotSingleFloat() const { return !IsSingleFloat; }
168 bool hasVFPU() const { return HasVFPU; }
Reed Kotler1595f362013-04-09 19:46:01 +0000169 bool inMips16Mode() const {
170 switch (OverrideMode) {
171 case NoOverride:
172 return InMips16Mode;
173 case Mips16Override:
174 return true;
175 case NoMips16Override:
176 return false;
177 }
178 llvm_unreachable("Unexpected mode");
179 }
Reed Kotler783c7942013-05-10 22:25:39 +0000180 bool inMips16ModeDefault() const {
Reed Kotler1595f362013-04-09 19:46:01 +0000181 return InMips16Mode;
182 }
Reed Kotler783c7942013-05-10 22:25:39 +0000183 bool inMips16HardFloat() const {
184 return inMips16Mode() && InMips16HardFloat;
185 }
Jack Carter428a06c2013-02-05 09:30:03 +0000186 bool inMicroMipsMode() const { return InMicroMipsMode; }
Akira Hatanaka65ce9312012-09-21 23:41:49 +0000187 bool hasDSP() const { return HasDSP; }
188 bool hasDSPR2() const { return HasDSPR2; }
Jack Carter3a2c2d42013-08-13 20:54:07 +0000189 bool hasMSA() const { return HasMSA; }
Douglas Gregor740ab382009-12-19 07:05:23 +0000190 bool isLinux() const { return IsLinux; }
Akira Hatanakaad495022012-08-22 03:18:13 +0000191 bool useSmallSection() const { return UseSmallSection; }
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +0000192
Akira Hatanakacdf4fd82012-05-22 03:10:09 +0000193 bool hasStandardEncoding() const { return !inMips16Mode(); }
194
Reed Kotlerc03807a2013-08-30 19:40:56 +0000195 bool mipsSEUsesSoftFloat() const;
196
Akira Hatanakaa8a05be2013-10-07 19:06:57 +0000197 bool enableLongBranchPass() const {
198 return hasStandardEncoding() || allowMixed16_32();
199 }
200
Bruno Cardoso Lopesf714e252008-07-30 17:01:06 +0000201 /// Features related to the presence of specific instructions.
Douglas Gregor740ab382009-12-19 07:05:23 +0000202 bool hasSEInReg() const { return HasSEInReg; }
203 bool hasCondMov() const { return HasCondMov; }
Douglas Gregor740ab382009-12-19 07:05:23 +0000204 bool hasSwap() const { return HasSwap; }
205 bool hasBitCount() const { return HasBitCount; }
Akira Hatanaka3bc1beb2012-11-15 21:17:13 +0000206 bool hasFPIdx() const { return HasFPIdx; }
Akira Hatanaka4a3836b2013-10-09 23:36:17 +0000207 bool hasExtractInsert() const { return !inMips16Mode() && hasMips32r2(); }
Jack Carterc1b17ed2013-01-18 21:20:38 +0000208
Akira Hatanaka66bc4192013-07-12 23:33:22 +0000209 const InstrItineraryData &getInstrItineraryData() const { return InstrItins; }
Reed Kotler783c7942013-05-10 22:25:39 +0000210 bool allowMixed16_32() const { return inMips16ModeDefault() |
211 AllowMixed16_32;}
Reed Kotler1595f362013-04-09 19:46:01 +0000212
Reed Kotlerfe94cc32013-04-10 16:58:04 +0000213 bool os16() const { return Os16;};
214
Reed Kotler91ae9822013-10-27 21:57:36 +0000215// for now constant islands are on for the whole compilation unit but we only
216// really use them if in addition we are in mips16 mode
217//
218static bool useConstantIslands();
Akira Hatanaka6b2d8412013-10-29 19:29:03 +0000219
Akira Hatanaka3048b022013-10-30 02:29:43 +0000220 unsigned stackAlignment() const { return isFP64bit() ? 16 : 8; }
Akira Hatanaka6b2d8412013-10-29 19:29:03 +0000221
Jack Carterc1b17ed2013-01-18 21:20:38 +0000222 // Grab MipsRegInfo object
223 const MipsReginfo &getMReginfo() const { return MRI; }
Jack Carter7f378102013-01-30 02:16:36 +0000224
225 // Grab relocation model
226 Reloc::Model getRelocationModel() const {return RM;}
Reed Kotler1595f362013-04-09 19:46:01 +0000227
228 /// \brief Reset the subtarget for the Mips target.
229 void resetSubtarget(MachineFunction *MF);
230
231
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000232};
233} // End llvm namespace
234
235#endif