blob: 037fc3ed3243e08b4f31f0fe4ad3ea77b03ebeef [file] [log] [blame]
David Blaikieb3bde2e2017-11-17 01:07:10 +00001//===- llvm/CodeGen/TargetSubtargetInfo.h - Target Information --*- C++ -*-===//
Nate Begemanf26625e2005-07-12 01:41:54 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Nate Begemanf26625e2005-07-12 01:41:54 +00006//
7//===----------------------------------------------------------------------===//
8//
9// This file describes the subtarget options of a Target machine.
10//
11//===----------------------------------------------------------------------===//
12
David Blaikieb3bde2e2017-11-17 01:07:10 +000013#ifndef LLVM_CODEGEN_TARGETSUBTARGETINFO_H
14#define LLVM_CODEGEN_TARGETSUBTARGETINFO_H
Nate Begemanf26625e2005-07-12 01:41:54 +000015
Andrea Di Biagio8b6c3142018-09-19 15:57:45 +000016#include "llvm/ADT/APInt.h"
Eugene Zelenkoc4ad1ce2017-01-11 01:45:03 +000017#include "llvm/ADT/ArrayRef.h"
18#include "llvm/ADT/SmallVector.h"
19#include "llvm/ADT/StringRef.h"
Lang Hames8f31f442014-10-09 18:20:51 +000020#include "llvm/CodeGen/PBQPRAConstraint.h"
Krzysztof Parzyszek5c61d112016-03-05 15:45:23 +000021#include "llvm/CodeGen/ScheduleDAGMutation.h"
Chandler Carruth6bda14b2017-06-06 11:49:48 +000022#include "llvm/CodeGen/SchedulerRegistry.h"
Evan Cheng54b68e32011-07-01 20:45:01 +000023#include "llvm/MC/MCSubtargetInfo.h"
Craig Topper7a901d92012-03-25 18:09:44 +000024#include "llvm/Support/CodeGen.h"
Eugene Zelenkoc4ad1ce2017-01-11 01:45:03 +000025#include <memory>
Krzysztof Parzyszek5c61d112016-03-05 15:45:23 +000026#include <vector>
Evan Cheng007ceb42009-10-16 21:06:15 +000027
Eugene Zelenko8361b0a2017-06-19 22:43:19 +000028
Nate Begemanf26625e2005-07-12 01:41:54 +000029namespace llvm {
30
Quentin Colombetba2a0162016-02-16 19:26:02 +000031class CallLowering;
Eugene Zelenko8361b0a2017-06-19 22:43:19 +000032class InstrItineraryData;
33struct InstrStage;
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +000034class InstructionSelector;
Tim Northover69fa84a2016-10-14 22:18:18 +000035class LegalizerInfo;
Andrew Trick1188e432012-09-18 03:32:57 +000036class MachineInstr;
Eugene Zelenko8361b0a2017-06-19 22:43:19 +000037struct MachineSchedPolicy;
38struct MCReadAdvanceEntry;
39struct MCWriteLatencyEntry;
40struct MCWriteProcResEntry;
Quentin Colombet62c1b912016-04-05 22:50:40 +000041class RegisterBankInfo;
David Goodwin90e6b8b2009-08-13 16:05:04 +000042class SDep;
Eugene Zelenkoc4ad1ce2017-01-11 01:45:03 +000043class SelectionDAGTargetInfo;
Eugene Zelenko8361b0a2017-06-19 22:43:19 +000044struct SubtargetFeatureKV;
Craig Topperca268082019-03-05 18:54:34 +000045struct SubtargetSubTypeKV;
Eugene Zelenko8361b0a2017-06-19 22:43:19 +000046struct SubtargetInfoKV;
David Goodwin9b48cd42009-08-19 16:08:58 +000047class SUnit;
Eric Christopherd9134482014-08-04 21:25:23 +000048class TargetFrameLowering;
49class TargetInstrInfo;
Eric Christopherd9134482014-08-04 21:25:23 +000050class TargetLowering;
David Goodwin0d412c22009-11-10 00:48:55 +000051class TargetRegisterClass;
Eric Christopherd9134482014-08-04 21:25:23 +000052class TargetRegisterInfo;
Andrew Trick1188e432012-09-18 03:32:57 +000053class TargetSchedModel;
Eugene Zelenko8361b0a2017-06-19 22:43:19 +000054class Triple;
David Goodwin90e6b8b2009-08-13 16:05:04 +000055
Nate Begemanf26625e2005-07-12 01:41:54 +000056//===----------------------------------------------------------------------===//
57///
Evan Cheng0d639a22011-07-01 21:01:15 +000058/// TargetSubtargetInfo - Generic base class for all target subtargets. All
Nate Begemanf26625e2005-07-12 01:41:54 +000059/// Target-specific options that control code generation and printing should
Evan Cheng0d639a22011-07-01 21:01:15 +000060/// be exposed through a TargetSubtargetInfo-derived class.
Nate Begemanf26625e2005-07-12 01:41:54 +000061///
Evan Cheng0d639a22011-07-01 21:01:15 +000062class TargetSubtargetInfo : public MCSubtargetInfo {
Nate Begemanf26625e2005-07-12 01:41:54 +000063protected: // Can only create subclasses...
Daniel Sanders50f17232015-09-15 16:17:27 +000064 TargetSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS,
Duncan P. N. Exon Smith754e21f2015-07-10 22:43:42 +000065 ArrayRef<SubtargetFeatureKV> PF,
Craig Topperca268082019-03-05 18:54:34 +000066 ArrayRef<SubtargetSubTypeKV> PD,
Duncan P. N. Exon Smith754e21f2015-07-10 22:43:42 +000067 const MCWriteProcResEntry *WPR,
68 const MCWriteLatencyEntry *WL,
69 const MCReadAdvanceEntry *RA, const InstrStage *IS,
70 const unsigned *OC, const unsigned *FP);
Eric Christopher09e92322015-04-04 03:53:25 +000071
Nate Begemanf26625e2005-07-12 01:41:54 +000072public:
David Goodwin02ad4cb2009-10-22 23:19:17 +000073 // AntiDepBreakMode - Type of anti-dependence breaking that should
74 // be performed before post-RA scheduling.
Eugene Zelenko8361b0a2017-06-19 22:43:19 +000075 using AntiDepBreakMode = enum { ANTIDEP_NONE, ANTIDEP_CRITICAL, ANTIDEP_ALL };
76 using RegClassVector = SmallVectorImpl<const TargetRegisterClass *>;
David Goodwin02ad4cb2009-10-22 23:19:17 +000077
Eugene Zelenkoc4ad1ce2017-01-11 01:45:03 +000078 TargetSubtargetInfo() = delete;
79 TargetSubtargetInfo(const TargetSubtargetInfo &) = delete;
Eugene Zelenko8361b0a2017-06-19 22:43:19 +000080 TargetSubtargetInfo &operator=(const TargetSubtargetInfo &) = delete;
81 ~TargetSubtargetInfo() override;
Dan Gohmanb9a01212008-12-16 03:35:01 +000082
Dean Michael Berris464015442016-09-19 00:54:35 +000083 virtual bool isXRaySupported() const { return false; }
84
Eric Christopherd9134482014-08-04 21:25:23 +000085 // Interfaces to the major aspects of target machine information:
86 //
87 // -- Instruction opcode and operand information
88 // -- Pipelines and scheduling information
89 // -- Stack frame information
90 // -- Selection DAG lowering information
Quentin Colombetba2a0162016-02-16 19:26:02 +000091 // -- Call lowering information
Eric Christopherd9134482014-08-04 21:25:23 +000092 //
93 // N.B. These objects may change during compilation. It's not safe to cache
94 // them between functions.
95 virtual const TargetInstrInfo *getInstrInfo() const { return nullptr; }
96 virtual const TargetFrameLowering *getFrameLowering() const {
97 return nullptr;
98 }
99 virtual const TargetLowering *getTargetLowering() const { return nullptr; }
Benjamin Kramerf9172fd42016-01-27 16:32:26 +0000100 virtual const SelectionDAGTargetInfo *getSelectionDAGInfo() const {
Eric Christopherd9134482014-08-04 21:25:23 +0000101 return nullptr;
102 }
Quentin Colombetba2a0162016-02-16 19:26:02 +0000103 virtual const CallLowering *getCallLowering() const { return nullptr; }
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +0000104
105 // FIXME: This lets targets specialize the selector by subtarget (which lets
106 // us do things like a dedicated avx512 selector). However, we might want
107 // to also specialize selectors by MachineFunction, which would let us be
108 // aware of optsize/optnone and such.
109 virtual const InstructionSelector *getInstructionSelector() const {
110 return nullptr;
111 }
112
Krzysztof Parzyszek788e7682017-09-14 20:44:20 +0000113 virtual unsigned getHwMode() const { return 0; }
114
Mehdi Aminib58f8132015-07-28 06:18:04 +0000115 /// Target can subclass this hook to select a different DAG scheduler.
116 virtual RegisterScheduler::FunctionPassCtor
117 getDAGScheduler(CodeGenOpt::Level) const {
118 return nullptr;
119 }
Eric Christopherd9134482014-08-04 21:25:23 +0000120
Tim Northover69fa84a2016-10-14 22:18:18 +0000121 virtual const LegalizerInfo *getLegalizerInfo() const { return nullptr; }
Tim Northover33b07d62016-07-22 20:03:43 +0000122
Eric Christopherd9134482014-08-04 21:25:23 +0000123 /// getRegisterInfo - If register information is available, return it. If
Quentin Colombet6ae3b782016-04-05 23:04:54 +0000124 /// not, return null.
Eric Christopherd9134482014-08-04 21:25:23 +0000125 virtual const TargetRegisterInfo *getRegisterInfo() const { return nullptr; }
126
Quentin Colombet62c1b912016-04-05 22:50:40 +0000127 /// If the information for the register banks is available, return it.
128 /// Otherwise return nullptr.
129 virtual const RegisterBankInfo *getRegBankInfo() const { return nullptr; }
130
Eric Christopherd9134482014-08-04 21:25:23 +0000131 /// getInstrItineraryData - Returns instruction itinerary data for the target
132 /// or specific subtarget.
Eric Christopherd9134482014-08-04 21:25:23 +0000133 virtual const InstrItineraryData *getInstrItineraryData() const {
134 return nullptr;
135 }
136
Andrew Trick1188e432012-09-18 03:32:57 +0000137 /// Resolve a SchedClass at runtime, where SchedClass identifies an
138 /// MCSchedClassDesc with the isVariant property. This may return the ID of
139 /// another variant SchedClass, but repeated invocation must quickly terminate
140 /// in a nonvariant SchedClass.
Eric Christopher09e92322015-04-04 03:53:25 +0000141 virtual unsigned resolveSchedClass(unsigned SchedClass,
142 const MachineInstr *MI,
143 const TargetSchedModel *SchedModel) const {
Andrew Trick1188e432012-09-18 03:32:57 +0000144 return 0;
Andrew Trickab722bd2012-09-18 03:18:56 +0000145 }
146
Andrea Di Biagio045aa202018-09-20 11:07:57 +0000147 /// Returns true if MI is a dependency breaking zero-idiom instruction for the
148 /// subtarget.
Andrea Di Biagio8b6c3142018-09-19 15:57:45 +0000149 ///
Andrea Di Biagio045aa202018-09-20 11:07:57 +0000150 /// This function also sets bits in Mask related to input operands that
Andrea Di Biagio8b6c3142018-09-19 15:57:45 +0000151 /// are not in a data dependency relationship. There is one bit for each
152 /// machine operand; implicit operands follow explicit operands in the bit
Andrea Di Biagio045aa202018-09-20 11:07:57 +0000153 /// representation used for Mask. An empty (i.e. a mask with all bits
154 /// cleared) means: data dependencies are "broken" for all the explicit input
155 /// machine operands of MI.
Andrea Di Biagio8b6c3142018-09-19 15:57:45 +0000156 virtual bool isZeroIdiom(const MachineInstr *MI, APInt &Mask) const {
157 return false;
158 }
159
Andrea Di Biagio045aa202018-09-20 11:07:57 +0000160 /// Returns true if MI is a dependency breaking instruction for the subtarget.
Andrea Di Biagio8b6c3142018-09-19 15:57:45 +0000161 ///
162 /// Similar in behavior to `isZeroIdiom`. However, it knows how to identify
163 /// all dependency breaking instructions (i.e. not just zero-idioms).
164 ///
165 /// As for `isZeroIdiom`, this method returns a mask of "broken" dependencies.
Andrea Di Biagio045aa202018-09-20 11:07:57 +0000166 /// (See method `isZeroIdiom` for a detailed description of Mask).
Andrea Di Biagio8b6c3142018-09-19 15:57:45 +0000167 virtual bool isDependencyBreaking(const MachineInstr *MI, APInt &Mask) const {
168 return isZeroIdiom(MI, Mask);
169 }
170
Andrea Di Biagio6eebbe02018-10-12 11:23:04 +0000171 /// Returns true if MI is a candidate for move elimination.
172 ///
173 /// A candidate for move elimination may be optimized out at register renaming
174 /// stage. Subtargets can specify the set of optimizable moves by
175 /// instantiating tablegen class `IsOptimizableRegisterMove` (see
176 /// llvm/Target/TargetInstrPredicate.td).
177 ///
178 /// SubtargetEmitter is responsible for processing all the definitions of class
179 /// IsOptimizableRegisterMove, and auto-generate an override for this method.
180 virtual bool isOptimizableRegisterMove(const MachineInstr *MI) const {
181 return false;
182 }
183
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000184 /// True if the subtarget should run MachineScheduler after aggressive
Andrew Trick108c88c2012-11-13 08:47:29 +0000185 /// coalescing.
186 ///
187 /// This currently replaces the SelectionDAG scheduler with the "source" order
Eric Christopher5f141b02015-03-11 22:56:10 +0000188 /// scheduler (though see below for an option to turn this off and use the
189 /// TargetLowering preference). It does not yet disable the postRA scheduler.
Andrew Trick108c88c2012-11-13 08:47:29 +0000190 virtual bool enableMachineScheduler() const;
191
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000192 /// True if the machine scheduler should disable the TLI preference
Eric Christopher5f141b02015-03-11 22:56:10 +0000193 /// for preRA scheduling with the source level scheduler.
194 virtual bool enableMachineSchedDefaultSched() const { return true; }
195
Jinsong Jief2d6d92019-06-11 17:40:39 +0000196 /// True if the subtarget should run MachinePipeliner
197 virtual bool enableMachinePipeliner() const { return true; };
198
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000199 /// True if the subtarget should enable joining global copies.
Eric Christopher5f141b02015-03-11 22:56:10 +0000200 ///
201 /// By default this is enabled if the machine scheduler is enabled, but
202 /// can be overridden.
203 virtual bool enableJoinGlobalCopies() const;
204
Matthias Braun39a2afc2015-06-13 03:42:16 +0000205 /// True if the subtarget should run a scheduler after register allocation.
Andrew Trick8d2ee372014-06-04 07:06:27 +0000206 ///
Matthias Braun39a2afc2015-06-13 03:42:16 +0000207 /// By default this queries the PostRAScheduling bit in the scheduling model
208 /// which is the preferred way to influence this.
209 virtual bool enablePostRAScheduler() const;
Andrew Trick8d2ee372014-06-04 07:06:27 +0000210
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000211 /// True if the subtarget should run the atomic expansion pass.
Robin Morisset59c23cd2014-08-21 21:50:01 +0000212 virtual bool enableAtomicExpand() const;
Eric Christopherc40e5ed2014-06-19 21:03:04 +0000213
Chandler Carruthc58f2162018-01-22 22:05:25 +0000214 /// True if the subtarget should run the indirectbr expansion pass.
215 virtual bool enableIndirectBrExpand() const;
216
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000217 /// Override generic scheduling policy within a region.
Andrew Trick75e411c2013-09-06 17:32:34 +0000218 ///
219 /// This is a convenient way for targets that don't provide any custom
220 /// scheduling heuristics (no custom MachineSchedStrategy) to make
221 /// changes to the generic scheduling policy.
222 virtual void overrideSchedPolicy(MachineSchedPolicy &Policy,
Andrew Trick75e411c2013-09-06 17:32:34 +0000223 unsigned NumRegionInstrs) const {}
224
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000225 // Perform target specific adjustments to the latency of a schedule
Eric Christophered19bad2014-05-21 23:40:18 +0000226 // dependency.
Eric Christopher09e92322015-04-04 03:53:25 +0000227 virtual void adjustSchedDependency(SUnit *def, SUnit *use, SDep &dep) const {}
NAKAMURA Takumi16d99f932014-07-23 00:42:52 +0000228
Sanjay Patela2f658d2014-07-15 22:39:58 +0000229 // For use with PostRAScheduling: get the anti-dependence breaking that should
230 // be performed before post-RA scheduling.
Eric Christopher09e92322015-04-04 03:53:25 +0000231 virtual AntiDepBreakMode getAntiDepBreakMode() const { return ANTIDEP_NONE; }
NAKAMURA Takumi16d99f932014-07-23 00:42:52 +0000232
Sanjay Patela2f658d2014-07-15 22:39:58 +0000233 // For use with PostRAScheduling: in CriticalPathRCs, return any register
234 // classes that should only be considered for anti-dependence breaking if they
235 // are on the critical path.
236 virtual void getCriticalPathRCs(RegClassVector &CriticalPathRCs) const {
237 return CriticalPathRCs.clear();
238 }
NAKAMURA Takumi16d99f932014-07-23 00:42:52 +0000239
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000240 // Provide an ordered list of schedule DAG mutations for the post-RA
Krzysztof Parzyszek5c61d112016-03-05 15:45:23 +0000241 // scheduler.
242 virtual void getPostRAMutations(
243 std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations) const {
244 }
245
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000246 // Provide an ordered list of schedule DAG mutations for the machine
Krzysztof Parzyszek88391242016-12-22 19:21:20 +0000247 // pipeliner.
248 virtual void getSMSMutations(
249 std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations) const {
250 }
251
Jinsong Jif6cb3bc2019-05-29 03:02:59 +0000252 /// Default to DFA for resource management, return false when target will use
253 /// ProcResource in InstrSchedModel instead.
254 virtual bool useDFAforSMS() const { return true; }
255
Sanjay Patela2f658d2014-07-15 22:39:58 +0000256 // For use with PostRAScheduling: get the minimum optimization level needed
257 // to enable post-RA scheduling.
258 virtual CodeGenOpt::Level getOptLevelToEnablePostRAScheduler() const {
259 return CodeGenOpt::Default;
260 }
NAKAMURA Takumi16d99f932014-07-23 00:42:52 +0000261
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000262 /// True if the subtarget should run the local reassignment
Quentin Colombet5caa6a22014-07-02 18:32:04 +0000263 /// heuristic of the register allocator.
264 /// This heuristic may be compile time intensive, \p OptLevel provides
265 /// a finer grain to tune the register allocator.
266 virtual bool enableRALocalReassignment(CodeGenOpt::Level OptLevel) const;
267
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000268 /// True if the subtarget should consider the cost of local intervals
Marina Yatsinaf9371d82017-10-22 17:59:38 +0000269 /// created by a split candidate when choosing the best split candidate. This
270 /// heuristic may be compile time intensive.
271 virtual bool enableAdvancedRASplitCost() const;
272
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000273 /// Enable use of alias analysis during code generation (during MI
Hal Finkelb350ffd2013-08-29 03:25:05 +0000274 /// scheduling, DAGCombine, etc.).
275 virtual bool useAA() const;
276
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000277 /// Enable the use of the early if conversion pass.
Eric Christopher6b0fcfe2014-05-21 23:40:26 +0000278 virtual bool enableEarlyIfConversion() const { return false; }
Lang Hames8f31f442014-10-09 18:20:51 +0000279
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000280 /// Return PBQPConstraint(s) for the target.
Lang Hames8f31f442014-10-09 18:20:51 +0000281 ///
282 /// Override to provide custom PBQP constraints.
283 virtual std::unique_ptr<PBQPRAConstraint> getCustomPBQPConstraints() const {
284 return nullptr;
285 }
Matthias Braune3d3b882014-12-10 01:12:30 +0000286
287 /// Enable tracking of subregister liveness in register allocator.
Matthias Braunf1b20c52016-08-24 22:17:45 +0000288 /// Please use MachineRegisterInfo::subRegLivenessEnabled() instead where
289 /// possible.
Eric Christopher09e92322015-04-04 03:53:25 +0000290 virtual bool enableSubRegLiveness() const { return false; }
Andrew V. Tischenko75745d02017-04-14 07:44:23 +0000291
Matthias Braun5c290dc2018-01-19 03:16:36 +0000292 /// This is called after a .mir file was loaded.
293 virtual void mirFileLoaded(MachineFunction &MF) const;
Oliver Stannard830b2032019-07-03 09:58:52 +0000294
295 /// True if the register allocator should use the allocation orders exactly as
296 /// written in the tablegen descriptions, false if it should allocate
297 /// the specified physical register later if is it callee-saved.
298 virtual bool ignoreCSRForAllocationOrder(const MachineFunction &MF,
299 unsigned PhysReg) const {
300 return false;
301 }
Nate Begemanf26625e2005-07-12 01:41:54 +0000302};
303
Eugene Zelenkoc4ad1ce2017-01-11 01:45:03 +0000304} // end namespace llvm
Nate Begemanf26625e2005-07-12 01:41:54 +0000305
David Blaikieb3bde2e2017-11-17 01:07:10 +0000306#endif // LLVM_CODEGEN_TARGETSUBTARGETINFO_H