blob: 038eb76ae1d2bec29b9a817f8521aff44242dab6 [file] [log] [blame]
Jia Liub22310f2012-02-18 12:03:15 +00001//===-- ARMSubtarget.h - Define Subtarget for the ARM ----------*- C++ -*--===//
Evan Cheng10043e22007-01-19 07:51:42 +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.
Evan Cheng10043e22007-01-19 07:51:42 +00007//
8//===----------------------------------------------------------------------===//
9//
Evan Cheng0d639a22011-07-01 21:01:15 +000010// This file declares the ARM specific subclass of TargetSubtargetInfo.
Evan Cheng10043e22007-01-19 07:51:42 +000011//
12//===----------------------------------------------------------------------===//
13
14#ifndef ARMSUBTARGET_H
15#define ARMSUBTARGET_H
16
Evan Cheng2bd65362011-07-07 00:08:19 +000017#include "MCTargetDesc/ARMMCTargetDesc.h"
Evan Chenge45d6852011-01-11 21:46:47 +000018#include "llvm/ADT/Triple.h"
Chandler Carruth802d7552012-12-04 07:12:27 +000019#include "llvm/MC/MCInstrItineraries.h"
20#include "llvm/Target/TargetSubtargetInfo.h"
Evan Cheng10043e22007-01-19 07:51:42 +000021#include <string>
22
Evan Cheng54b68e32011-07-01 20:45:01 +000023#define GET_SUBTARGETINFO_HEADER
Evan Chengc9c090d2011-07-01 22:36:09 +000024#include "ARMGenSubtargetInfo.inc"
Evan Cheng54b68e32011-07-01 20:45:01 +000025
Evan Cheng10043e22007-01-19 07:51:42 +000026namespace llvm {
Evan Cheng43b9ca62009-08-28 23:18:09 +000027class GlobalValue;
Evan Cheng1a72add62011-07-07 07:07:08 +000028class StringRef;
Renato Golinb4dd6c52013-03-21 18:47:47 +000029class TargetOptions;
Evan Cheng10043e22007-01-19 07:51:42 +000030
Evan Cheng54b68e32011-07-01 20:45:01 +000031class ARMSubtarget : public ARMGenSubtargetInfo {
Evan Cheng10043e22007-01-19 07:51:42 +000032protected:
Evan Chengbf407072010-09-10 01:29:16 +000033 enum ARMProcFamilyEnum {
Quentin Colombetb1b66e72012-12-21 04:35:05 +000034 Others, CortexA5, CortexA8, CortexA9, CortexA15, CortexR5, Swift
Evan Chengbf407072010-09-10 01:29:16 +000035 };
36
Evan Chengbf407072010-09-10 01:29:16 +000037 /// ARMProcFamily - ARM processor family: Cortex-A8, Cortex-A9, and others.
38 ARMProcFamilyEnum ARMProcFamily;
39
Evan Cheng8b2bda02011-07-07 03:55:05 +000040 /// HasV4TOps, HasV5TOps, HasV5TEOps, HasV6Ops, HasV6T2Ops, HasV7Ops -
41 /// Specify whether target support specific ARM ISA variants.
42 bool HasV4TOps;
43 bool HasV5TOps;
44 bool HasV5TEOps;
45 bool HasV6Ops;
46 bool HasV6T2Ops;
47 bool HasV7Ops;
48
Evan Cheng48346c12012-04-11 05:33:07 +000049 /// HasVFPv2, HasVFPv3, HasVFPv4, HasNEON - Specify what
Anton Korobeynikov5482b9f2012-01-22 12:07:33 +000050 /// floating point ISAs are supported.
Evan Cheng8b2bda02011-07-07 03:55:05 +000051 bool HasVFPv2;
52 bool HasVFPv3;
Anton Korobeynikov5482b9f2012-01-22 12:07:33 +000053 bool HasVFPv4;
Evan Cheng8b2bda02011-07-07 03:55:05 +000054 bool HasNEON;
Evan Cheng10043e22007-01-19 07:51:42 +000055
David Goodwina307edb2009-08-05 16:01:19 +000056 /// UseNEONForSinglePrecisionFP - if the NEONFP attribute has been
57 /// specified. Use the method useNEONForSinglePrecisionFP() to
58 /// determine if NEON should actually be used.
David Goodwin3b9c52c2009-08-04 17:53:06 +000059 bool UseNEONForSinglePrecisionFP;
60
Bob Wilsone8a549c2012-09-29 21:43:49 +000061 /// UseMulOps - True if non-microcoded fused integer multiply-add and
62 /// multiply-subtract instructions should be used.
63 bool UseMulOps;
64
Evan Cheng62c7b5b2010-12-05 22:04:16 +000065 /// SlowFPVMLx - If the VFP2 / NEON instructions are available, indicates
66 /// whether the FP VML[AS] instructions are slow (if so, don't use them).
67 bool SlowFPVMLx;
Jim Grosbach34de7762010-03-24 22:31:46 +000068
Evan Cheng38bf5ad2011-03-31 19:38:48 +000069 /// HasVMLxForwarding - If true, NEON has special multiplier accumulator
70 /// forwarding to allow mul + mla being issued back to back.
71 bool HasVMLxForwarding;
72
Evan Cheng58066e32010-07-13 19:21:50 +000073 /// SlowFPBrcc - True if floating point compare + branch is slow.
74 bool SlowFPBrcc;
75
Evan Cheng6dbe7132011-07-07 19:09:06 +000076 /// InThumbMode - True if compiling for Thumb, false for ARM.
Evan Cheng1834f5d2011-07-07 19:05:12 +000077 bool InThumbMode;
Anton Korobeynikov12694bd2009-06-01 20:00:48 +000078
Evan Cheng2bd65362011-07-07 00:08:19 +000079 /// HasThumb2 - True if Thumb2 instructions are supported.
80 bool HasThumb2;
Evan Cheng10043e22007-01-19 07:51:42 +000081
Andrew Trick207c5692012-08-08 02:44:08 +000082 /// IsMClass - True if the subtarget belongs to the 'M' profile of CPUs -
James Molloy21efa7d2011-09-28 14:21:38 +000083 /// v6m, v7m for example.
84 bool IsMClass;
85
Evan Cheng5190f092010-08-11 07:17:46 +000086 /// NoARM - True if subtarget does not support ARM mode execution.
87 bool NoARM;
88
David Goodwin17199b52009-09-30 00:10:16 +000089 /// PostRAScheduler - True if using post-register-allocation scheduler.
90 bool PostRAScheduler;
91
Evan Cheng10043e22007-01-19 07:51:42 +000092 /// IsR9Reserved - True if R9 is a not available as general purpose register.
93 bool IsR9Reserved;
Lauro Ramos Venancio048e16ff2007-02-13 19:52:28 +000094
Anton Korobeynikov25229082009-11-24 00:44:37 +000095 /// UseMovt - True if MOVT / MOVW pairs are used for materialization of 32-bit
96 /// imms (including global addresses).
97 bool UseMovt;
98
Bob Wilson8decdc42011-10-07 17:17:49 +000099 /// SupportsTailCall - True if the OS supports tail call. The dynamic linker
100 /// must be able to synthesize call stubs for interworking between ARM and
101 /// Thumb.
102 bool SupportsTailCall;
103
Anton Korobeynikov0a65a372010-03-14 18:42:38 +0000104 /// HasFP16 - True if subtarget supports half-precision FP (We support VFP+HF
105 /// only so far)
106 bool HasFP16;
107
Bob Wilsondd6eb5b2010-10-12 16:22:47 +0000108 /// HasD16 - True if subtarget is limited to 16 double precision
109 /// FP registers for VFPv3.
110 bool HasD16;
111
Jim Grosbach151cd8f2010-05-05 23:44:43 +0000112 /// HasHardwareDivide - True if subtarget supports [su]div
113 bool HasHardwareDivide;
114
Bob Wilsone8a549c2012-09-29 21:43:49 +0000115 /// HasHardwareDivideInARM - True if subtarget supports [su]div in ARM mode
116 bool HasHardwareDivideInARM;
117
Jim Grosbach151cd8f2010-05-05 23:44:43 +0000118 /// HasT2ExtractPack - True if subtarget supports thumb2 extract/pack
119 /// instructions.
120 bool HasT2ExtractPack;
121
Evan Cheng6e809de2010-08-11 06:22:01 +0000122 /// HasDataBarrier - True if the subtarget supports DMB / DSB data barrier
123 /// instructions.
124 bool HasDataBarrier;
125
Evan Chengce8fb682010-08-09 18:35:19 +0000126 /// Pref32BitThumb - If true, codegen would prefer 32-bit Thumb instructions
127 /// over 16-bit ones.
128 bool Pref32BitThumb;
129
Bob Wilsona2881ee2011-04-19 18:11:49 +0000130 /// AvoidCPSRPartialUpdate - If true, codegen would avoid using instructions
131 /// that partially update CPSR and add false dependency on the previous
132 /// CPSR setting instruction.
133 bool AvoidCPSRPartialUpdate;
134
Evan Chengddc0cb62012-12-20 19:59:30 +0000135 /// AvoidMOVsShifterOperand - If true, codegen should avoid using flag setting
136 /// movs with shifter operand (i.e. asr, lsl, lsr).
137 bool AvoidMOVsShifterOperand;
138
Evan Cheng65f9d192012-02-28 18:51:51 +0000139 /// HasRAS - Some processors perform return stack prediction. CodeGen should
140 /// avoid issue "normal" call instructions to callees which do not return.
141 bool HasRAS;
142
Evan Cheng8740ee32010-11-03 06:34:55 +0000143 /// HasMPExtension - True if the subtarget supports Multiprocessing
144 /// extension (ARMv7 only).
145 bool HasMPExtension;
146
Jim Grosbach4d5dc3e2010-08-11 15:44:15 +0000147 /// FPOnlySP - If true, the floating point unit only supports single
148 /// precision.
149 bool FPOnlySP;
150
Tim Northoverc6047652013-04-10 12:08:35 +0000151 /// HasTrustZone - if true, processor supports TrustZone security extensions
152 bool HasTrustZone;
153
Bob Wilson3dc97322010-09-28 04:09:35 +0000154 /// AllowsUnalignedMem - If true, the subtarget allows unaligned memory
155 /// accesses for some types. For details, see
156 /// ARMTargetLowering::allowsUnalignedMemoryAccesses().
157 bool AllowsUnalignedMem;
158
Jim Grosbachcf1464d2011-07-01 21:12:19 +0000159 /// Thumb2DSP - If true, the subtarget supports the v7 DSP (saturating arith
160 /// and such) instructions in Thumb2 code.
161 bool Thumb2DSP;
162
Eli Bendersky2e2ce492013-01-30 16:30:19 +0000163 /// NaCl TRAP instruction is generated instead of the regular TRAP.
164 bool UseNaClTrap;
165
Renato Golinb4dd6c52013-03-21 18:47:47 +0000166 /// Target machine allowed unsafe FP math (such as use of NEON fp)
167 bool UnsafeFPMath;
168
Evan Cheng10043e22007-01-19 07:51:42 +0000169 /// stackAlignment - The minimum alignment known to hold of the stack frame on
170 /// entry to the function and which must be maintained by every function.
171 unsigned stackAlignment;
172
Anton Korobeynikov08bf4c02009-05-23 19:50:50 +0000173 /// CPUString - String name of used CPU.
174 std::string CPUString;
175
Evan Chenge45d6852011-01-11 21:46:47 +0000176 /// TargetTriple - What processor and OS we're targeting.
177 Triple TargetTriple;
178
Andrew Trick352abc12012-08-08 02:44:16 +0000179 /// SchedModel - Processor specific instruction costs.
180 const MCSchedModel *SchedModel;
181
Evan Cheng4e712de2009-06-19 01:51:50 +0000182 /// Selected instruction itineraries (one entry per itinerary class.)
183 InstrItineraryData InstrItins;
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000184
Renato Golinb4dd6c52013-03-21 18:47:47 +0000185 /// Options passed via command line that could influence the target
186 const TargetOptions &Options;
187
Evan Cheng10043e22007-01-19 07:51:42 +0000188 public:
Evan Cheng181fe362007-01-19 19:22:40 +0000189 enum {
190 isELF, isDarwin
191 } TargetType;
192
Lauro Ramos Venancio048e16ff2007-02-13 19:52:28 +0000193 enum {
194 ARM_ABI_APCS,
195 ARM_ABI_AAPCS // ARM EABI
196 } TargetABI;
197
Evan Cheng10043e22007-01-19 07:51:42 +0000198 /// This constructor initializes the data members to match that
Daniel Dunbar31b44e82009-08-02 22:11:08 +0000199 /// of the specified triple.
Evan Cheng10043e22007-01-19 07:51:42 +0000200 ///
Evan Chengfe6e4052011-06-30 01:53:36 +0000201 ARMSubtarget(const std::string &TT, const std::string &CPU,
Renato Golinb4dd6c52013-03-21 18:47:47 +0000202 const std::string &FS, const TargetOptions &Options);
Evan Cheng10043e22007-01-19 07:51:42 +0000203
Dan Gohman544ab2c2008-04-12 04:36:06 +0000204 /// getMaxInlineSizeThreshold - Returns the maximum memset / memcpy size
205 /// that still makes it profitable to inline the call.
Rafael Espindola419b6d72007-10-31 14:39:58 +0000206 unsigned getMaxInlineSizeThreshold() const {
Bob Wilsonc499fae2010-03-11 00:20:49 +0000207 // FIXME: For now, we don't lower memcpy's to loads / stores for Thumb1.
208 // Change this once Thumb1 ldmia / stmia support is added.
209 return isThumb1Only() ? 0 : 64;
Rafael Espindola419b6d72007-10-31 14:39:58 +0000210 }
Anton Korobeynikov0b91cc42009-05-23 19:51:43 +0000211 /// ParseSubtargetFeatures - Parses features string setting specified
Evan Cheng10043e22007-01-19 07:51:42 +0000212 /// subtarget options. Definition of function is auto generated by tblgen.
Evan Cheng1a72add62011-07-07 07:07:08 +0000213 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
Evan Cheng10043e22007-01-19 07:51:42 +0000214
Renato Golinb2603ed2013-02-16 19:14:59 +0000215 /// \brief Reset the features for the ARM target.
Bill Wendling5a92eec2013-02-15 22:41:25 +0000216 virtual void resetSubtargetFeatures(const MachineFunction *MF);
Bill Wendling61375d82013-02-16 01:36:26 +0000217private:
218 void initializeEnvironment();
Bill Wendling5a92eec2013-02-15 22:41:25 +0000219 void resetSubtargetFeatures(StringRef CPU, StringRef FS);
Bill Wendling61375d82013-02-16 01:36:26 +0000220public:
Andrew Trick10ffc2b2010-12-24 05:03:26 +0000221 void computeIssueWidth();
222
Evan Cheng8b2bda02011-07-07 03:55:05 +0000223 bool hasV4TOps() const { return HasV4TOps; }
224 bool hasV5TOps() const { return HasV5TOps; }
225 bool hasV5TEOps() const { return HasV5TEOps; }
226 bool hasV6Ops() const { return HasV6Ops; }
227 bool hasV6T2Ops() const { return HasV6T2Ops; }
228 bool hasV7Ops() const { return HasV7Ops; }
Evan Cheng10043e22007-01-19 07:51:42 +0000229
Quentin Colombet13cd5212012-11-29 19:48:01 +0000230 bool isCortexA5() const { return ARMProcFamily == CortexA5; }
Evan Chengbf407072010-09-10 01:29:16 +0000231 bool isCortexA8() const { return ARMProcFamily == CortexA8; }
232 bool isCortexA9() const { return ARMProcFamily == CortexA9; }
Silviu Barangab47bb942012-09-13 15:05:10 +0000233 bool isCortexA15() const { return ARMProcFamily == CortexA15; }
Bob Wilsone8a549c2012-09-29 21:43:49 +0000234 bool isSwift() const { return ARMProcFamily == Swift; }
Evan Cheng94307f62011-11-09 01:57:03 +0000235 bool isCortexM3() const { return CPUString == "cortex-m3"; }
Silviu Barangab47bb942012-09-13 15:05:10 +0000236 bool isLikeA9() const { return isCortexA9() || isCortexA15(); }
Quentin Colombetb1b66e72012-12-21 04:35:05 +0000237 bool isCortexR5() const { return ARMProcFamily == CortexR5; }
Evan Chengbf407072010-09-10 01:29:16 +0000238
Evan Cheng5190f092010-08-11 07:17:46 +0000239 bool hasARMOps() const { return !NoARM; }
240
Evan Cheng8b2bda02011-07-07 03:55:05 +0000241 bool hasVFP2() const { return HasVFPv2; }
242 bool hasVFP3() const { return HasVFPv3; }
Anton Korobeynikov5482b9f2012-01-22 12:07:33 +0000243 bool hasVFP4() const { return HasVFPv4; }
Evan Cheng8b2bda02011-07-07 03:55:05 +0000244 bool hasNEON() const { return HasNEON; }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000245 bool useNEONForSinglePrecisionFP() const {
David Goodwin3b9c52c2009-08-04 17:53:06 +0000246 return hasNEON() && UseNEONForSinglePrecisionFP; }
Evan Cheng8b2bda02011-07-07 03:55:05 +0000247
Shantonu Sen94231ee2010-05-06 14:57:47 +0000248 bool hasDivide() const { return HasHardwareDivide; }
Bob Wilsone8a549c2012-09-29 21:43:49 +0000249 bool hasDivideInARMMode() const { return HasHardwareDivideInARM; }
Shantonu Sen94231ee2010-05-06 14:57:47 +0000250 bool hasT2ExtractPack() const { return HasT2ExtractPack; }
Evan Cheng6e809de2010-08-11 06:22:01 +0000251 bool hasDataBarrier() const { return HasDataBarrier; }
Bob Wilsone8a549c2012-09-29 21:43:49 +0000252 bool useMulOps() const { return UseMulOps; }
Evan Cheng62c7b5b2010-12-05 22:04:16 +0000253 bool useFPVMLx() const { return !SlowFPVMLx; }
Evan Cheng38bf5ad2011-03-31 19:38:48 +0000254 bool hasVMLxForwarding() const { return HasVMLxForwarding; }
Evan Cheng58066e32010-07-13 19:21:50 +0000255 bool isFPBrccSlow() const { return SlowFPBrcc; }
Jim Grosbach4d5dc3e2010-08-11 15:44:15 +0000256 bool isFPOnlySP() const { return FPOnlySP; }
Tim Northoverc6047652013-04-10 12:08:35 +0000257 bool hasTrustZone() const { return HasTrustZone; }
Evan Chengce8fb682010-08-09 18:35:19 +0000258 bool prefers32BitThumb() const { return Pref32BitThumb; }
Bob Wilsona2881ee2011-04-19 18:11:49 +0000259 bool avoidCPSRPartialUpdate() const { return AvoidCPSRPartialUpdate; }
Evan Chengddc0cb62012-12-20 19:59:30 +0000260 bool avoidMOVsShifterOperand() const { return AvoidMOVsShifterOperand; }
Evan Cheng65f9d192012-02-28 18:51:51 +0000261 bool hasRAS() const { return HasRAS; }
Evan Cheng8740ee32010-11-03 06:34:55 +0000262 bool hasMPExtension() const { return HasMPExtension; }
Jim Grosbachcf1464d2011-07-01 21:12:19 +0000263 bool hasThumb2DSP() const { return Thumb2DSP; }
Eli Bendersky2e2ce492013-01-30 16:30:19 +0000264 bool useNaClTrap() const { return UseNaClTrap; }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000265
Anton Korobeynikov0a65a372010-03-14 18:42:38 +0000266 bool hasFP16() const { return HasFP16; }
Bob Wilsondd6eb5b2010-10-12 16:22:47 +0000267 bool hasD16() const { return HasD16; }
Anton Korobeynikov0a65a372010-03-14 18:42:38 +0000268
Evan Cheng5f1ba4c2011-04-20 22:20:12 +0000269 const Triple &getTargetTriple() const { return TargetTriple; }
270
Evan Cheng68132d82011-12-20 18:26:50 +0000271 bool isTargetIOS() const { return TargetTriple.getOS() == Triple::IOS; }
Daniel Dunbar2b9b0e32011-04-19 21:14:45 +0000272 bool isTargetDarwin() const { return TargetTriple.isOSDarwin(); }
Nick Lewycky73df7e32011-09-05 21:51:43 +0000273 bool isTargetNaCl() const {
Eli Benderskyabe54632012-12-04 18:37:26 +0000274 return TargetTriple.getOS() == Triple::NaCl;
Nick Lewycky73df7e32011-09-05 21:51:43 +0000275 }
Evan Chenge45d6852011-01-11 21:46:47 +0000276 bool isTargetELF() const { return !isTargetDarwin(); }
Evan Cheng181fe362007-01-19 19:22:40 +0000277
Lauro Ramos Venancio048e16ff2007-02-13 19:52:28 +0000278 bool isAPCS_ABI() const { return TargetABI == ARM_ABI_APCS; }
279 bool isAAPCS_ABI() const { return TargetABI == ARM_ABI_AAPCS; }
280
Evan Cheng1834f5d2011-07-07 19:05:12 +0000281 bool isThumb() const { return InThumbMode; }
282 bool isThumb1Only() const { return InThumbMode && !HasThumb2; }
283 bool isThumb2() const { return InThumbMode && HasThumb2; }
Evan Cheng2bd65362011-07-07 00:08:19 +0000284 bool hasThumb2() const { return HasThumb2; }
James Molloy21efa7d2011-09-28 14:21:38 +0000285 bool isMClass() const { return IsMClass; }
286 bool isARClass() const { return !IsMClass; }
Evan Cheng10043e22007-01-19 07:51:42 +0000287
Evan Cheng10043e22007-01-19 07:51:42 +0000288 bool isR9Reserved() const { return IsR9Reserved; }
289
Anton Korobeynikov25229082009-11-24 00:44:37 +0000290 bool useMovt() const { return UseMovt && hasV6T2Ops(); }
Bob Wilson8decdc42011-10-07 17:17:49 +0000291 bool supportsTailCall() const { return SupportsTailCall; }
Anton Korobeynikov25229082009-11-24 00:44:37 +0000292
Bob Wilson3dc97322010-09-28 04:09:35 +0000293 bool allowsUnalignedMem() const { return AllowsUnalignedMem; }
294
Anton Korobeynikov08bf4c02009-05-23 19:50:50 +0000295 const std::string & getCPUString() const { return CPUString; }
Anton Korobeynikov25229082009-11-24 00:44:37 +0000296
Owen Andersona3181e22010-09-28 21:57:50 +0000297 unsigned getMispredictionPenalty() const;
Andrew Trickc416ba62010-12-24 04:28:06 +0000298
David Goodwin0d412c22009-11-10 00:48:55 +0000299 /// enablePostRAScheduler - True at 'More' optimization.
David Goodwin02ad4cb2009-10-22 23:19:17 +0000300 bool enablePostRAScheduler(CodeGenOpt::Level OptLevel,
Evan Cheng0d639a22011-07-01 21:01:15 +0000301 TargetSubtargetInfo::AntiDepBreakMode& Mode,
David Goodwinb9fe5d52009-11-13 19:52:48 +0000302 RegClassVector& CriticalPathRCs) const;
Anton Korobeynikov08bf4c02009-05-23 19:50:50 +0000303
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000304 /// getInstrItins - Return the instruction itineraies based on subtarget
Evan Cheng4e712de2009-06-19 01:51:50 +0000305 /// selection.
306 const InstrItineraryData &getInstrItineraryData() const { return InstrItins; }
307
Evan Cheng10043e22007-01-19 07:51:42 +0000308 /// getStackAlignment - Returns the minimum alignment known to hold of the
309 /// stack frame on entry to the function and which must be maintained by every
310 /// function for this subtarget.
311 unsigned getStackAlignment() const { return stackAlignment; }
Evan Cheng43b9ca62009-08-28 23:18:09 +0000312
313 /// GVIsIndirectSymbol - true if the GV will be accessed via an indirect
314 /// symbol.
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000315 bool GVIsIndirectSymbol(const GlobalValue *GV, Reloc::Model RelocM) const;
Evan Cheng10043e22007-01-19 07:51:42 +0000316};
317} // End llvm namespace
318
319#endif // ARMSUBTARGET_H