LLVM 24.0.0git
TargetSubtargetInfo.h
Go to the documentation of this file.
1//===- llvm/CodeGen/TargetSubtargetInfo.h - Target Information --*- C++ -*-===//
2//
3// 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
6//
7//===----------------------------------------------------------------------===//
8//
9// This file describes the subtarget options of a Target machine.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CODEGEN_TARGETSUBTARGETINFO_H
14#define LLVM_CODEGEN_TARGETSUBTARGETINFO_H
15
16#include "llvm/ADT/ArrayRef.h"
17#include "llvm/ADT/DenseMap.h"
19#include "llvm/ADT/StringRef.h"
24#include "llvm/IR/GlobalValue.h"
28#include <memory>
29#include <vector>
30
31namespace llvm {
32
33class APInt;
34class BitVector;
35class MachineFunction;
37class CallLowering;
38class GlobalValue;
41struct InstrStage;
43class LegalizerInfo;
45class MachineInstr;
49struct MCSchedModel;
53class SDep;
55class SUnit;
57class TargetInstrInfo;
58class TargetLowering;
59class MCRegisterClass;
63class Triple;
64struct SchedRegion;
65
66//===----------------------------------------------------------------------===//
67///
68/// TargetSubtargetInfo - Generic base class for all target subtargets. All
69/// Target-specific options that control code generation and printing should
70/// be exposed through a TargetSubtargetInfo-derived class.
71///
73protected: // Can only create subclasses...
74 TargetSubtargetInfo(const Triple &TT, StringRef CPU, StringRef TuneCPU,
79 const MCSchedModel *PSM, const MCWriteProcResEntry *WPR,
80 const MCWriteLatencyEntry *WL,
81 const MCReadAdvanceEntry *RA, const InstrStage *IS,
82 const unsigned *OC, const unsigned *FP);
83
84public:
85 // AntiDepBreakMode - Type of anti-dependence breaking that should
86 // be performed before post-RA scheduling.
87 using AntiDepBreakMode = enum { ANTIDEP_NONE, ANTIDEP_CRITICAL, ANTIDEP_ALL };
89
94
95 virtual bool isXRaySupported() const { return false; }
96
97 /// \returns true if the target intrinsic \p IntrinsicID is supported by this
98 /// subtarget.
99 bool isIntrinsicSupported(unsigned IntrinsicID) const;
100
101 // Interfaces to the major aspects of target machine information:
102 //
103 // -- Instruction opcode and operand information
104 // -- Pipelines and scheduling information
105 // -- Stack frame information
106 // -- Selection DAG lowering information
107 // -- Call lowering information
108 //
109 // N.B. These objects may change during compilation. It's not safe to cache
110 // them between functions.
111 virtual const TargetInstrInfo *getInstrInfo() const { return nullptr; }
112 virtual const TargetFrameLowering *getFrameLowering() const {
113 return nullptr;
114 }
115 virtual const TargetLowering *getTargetLowering() const { return nullptr; }
117 return nullptr;
118 }
119 virtual const CallLowering *getCallLowering() const { return nullptr; }
120
122 return nullptr;
123 }
124
125 // FIXME: This lets targets specialize the selector by subtarget (which lets
126 // us do things like a dedicated avx512 selector). However, we might want
127 // to also specialize selectors by MachineFunction, which would let us be
128 // aware of optsize/optnone and such.
130 return nullptr;
131 }
132
133 /// Target can subclass this hook to select a different DAG scheduler.
136 return nullptr;
137 }
138
139 virtual const LegalizerInfo *getLegalizerInfo() const { return nullptr; }
140
141 /// Return the target's register information.
142 virtual const TargetRegisterInfo *getRegisterInfo() const = 0;
143
144 /// If the information for the register banks is available, return it.
145 /// Otherwise return nullptr.
146 virtual const RegisterBankInfo *getRegBankInfo() const { return nullptr; }
147
148 /// getInstrItineraryData - Returns instruction itinerary data for the target
149 /// or specific subtarget.
151 return nullptr;
152 }
153
154 /// Return the number of extra cycles the processor takes to recover from a
155 /// branch misprediction. Defaults to the value in the scheduling model.
156 virtual unsigned getMispredictionPenalty() const {
157 return getSchedModel().MispredictPenalty;
158 }
159
160 /// Return the expected latency of load instructions. Defaults to the value
161 /// in the scheduling model.
162 virtual unsigned getLoadLatency() const {
163 return getSchedModel().LoadLatency;
164 }
165
166 /// Configure the LibcallLoweringInfo for this subtarget. The libcalls will be
167 /// pre-configured with defaults based on RuntimeLibcallsInfo. This may be
168 /// used to override those decisions, such as disambiguating alternative
169 /// implementations.
170 virtual void initLibcallLoweringInfo(LibcallLoweringInfo &Info) const {}
171
172 /// Resolve a SchedClass at runtime, where SchedClass identifies an
173 /// MCSchedClassDesc with the isVariant property. This may return the ID of
174 /// another variant SchedClass, but repeated invocation must quickly terminate
175 /// in a nonvariant SchedClass.
176 virtual unsigned resolveSchedClass(unsigned SchedClass,
177 const MachineInstr *MI,
178 const TargetSchedModel *SchedModel) const {
179 return 0;
180 }
181
182 /// Returns true if MI is a dependency breaking zero-idiom instruction for the
183 /// subtarget.
184 ///
185 /// This function also sets bits in Mask related to input operands that
186 /// are not in a data dependency relationship. There is one bit for each
187 /// machine operand; implicit operands follow explicit operands in the bit
188 /// representation used for Mask. An empty (i.e. a mask with all bits
189 /// cleared) means: data dependencies are "broken" for all the explicit input
190 /// machine operands of MI.
191 virtual bool isZeroIdiom(const MachineInstr *MI, APInt &Mask) const {
192 return false;
193 }
194
195 /// Returns true if MI is a dependency breaking instruction for the subtarget.
196 ///
197 /// Similar in behavior to `isZeroIdiom`. However, it knows how to identify
198 /// all dependency breaking instructions (i.e. not just zero-idioms).
199 ///
200 /// As for `isZeroIdiom`, this method returns a mask of "broken" dependencies.
201 /// (See method `isZeroIdiom` for a detailed description of Mask).
202 virtual bool isDependencyBreaking(const MachineInstr *MI, APInt &Mask) const {
203 return isZeroIdiom(MI, Mask);
204 }
205
206 /// Returns true if MI is a candidate for move elimination.
207 ///
208 /// A candidate for move elimination may be optimized out at register renaming
209 /// stage. Subtargets can specify the set of optimizable moves by
210 /// instantiating tablegen class `IsOptimizableRegisterMove` (see
211 /// llvm/Target/TargetInstrPredicate.td).
212 ///
213 /// SubtargetEmitter is responsible for processing all the definitions of class
214 /// IsOptimizableRegisterMove, and auto-generate an override for this method.
215 virtual bool isOptimizableRegisterMove(const MachineInstr *MI) const {
216 return false;
217 }
218
219 /// True if the subtarget should run MachineScheduler after aggressive
220 /// coalescing.
221 ///
222 /// This currently replaces the SelectionDAG scheduler with the "source" order
223 /// scheduler (though see below for an option to turn this off and use the
224 /// TargetLowering preference). It does not yet disable the postRA scheduler.
225 virtual bool enableMachineScheduler() const;
226
227 /// True if the machine scheduler should disable the TLI preference
228 /// for preRA scheduling with the source level scheduler.
229 virtual bool enableMachineSchedDefaultSched() const { return true; }
230
231 /// True if the subtarget should run MachinePipeliner
232 virtual bool enableMachinePipeliner() const { return true; };
233
234 /// True if the subtarget should run WindowScheduler.
235 virtual bool enableWindowScheduler() const { return true; }
236
237 /// True if the subtarget should enable joining global copies.
238 ///
239 /// By default this is enabled if the machine scheduler is enabled, but
240 /// can be overridden.
241 virtual bool enableJoinGlobalCopies() const;
242
243 /// Hack to bring up option. This should be unconditionally true, all targets
244 /// should enable it and delete this.
245 virtual bool enableTerminalRule() const { return false; }
246
247 /// True if the subtarget should run a scheduler after register allocation.
248 ///
249 /// By default this queries the PostRAScheduling bit in the scheduling model
250 /// which is the preferred way to influence this.
251 virtual bool enablePostRAScheduler() const;
252
253 /// True if the subtarget should run a machine scheduler after register
254 /// allocation.
255 virtual bool enablePostRAMachineScheduler() const;
256
257 /// True if the subtarget should run the atomic expansion pass.
258 virtual bool enableAtomicExpand() const;
259
260 /// True if the subtarget should run the indirectbr expansion pass.
261 virtual bool enableIndirectBrExpand() const;
262
263 /// Override generic scheduling policy within a region.
264 ///
265 /// This is a convenient way for targets that don't provide any custom
266 /// scheduling heuristics (no custom MachineSchedStrategy) to make
267 /// changes to the generic scheduling policy.
269 const SchedRegion &Region) const {}
270
271 /// Override generic post-ra scheduling policy within a region.
272 ///
273 /// This is a convenient way for targets that don't provide any custom
274 /// scheduling heuristics (no custom MachineSchedStrategy) to make
275 /// changes to the generic post-ra scheduling policy.
276 /// Note that some options like tracking register pressure won't take effect
277 /// in post-ra scheduling.
279 const SchedRegion &Region) const {}
280
281 /// Override generic software pipelining policy.
282 virtual void overridePipelinerPolicy(MachinePipelinerPolicy &Policy) const {}
283
284 // Perform target-specific adjustments to the latency of a schedule
285 // dependency.
286 // If a pair of operands is associated with the schedule dependency, DefOpIdx
287 // and UseOpIdx are the indices of the operands in Def and Use, respectively.
288 // Otherwise, either may be -1.
289 virtual void adjustSchedDependency(SUnit *Def, int DefOpIdx, SUnit *Use,
290 int UseOpIdx, SDep &Dep,
291 const TargetSchedModel *SchedModel) const {
292 }
293
294 // For use with PostRAScheduling: get the anti-dependence breaking that should
295 // be performed before post-RA scheduling.
296 virtual AntiDepBreakMode getAntiDepBreakMode() const { return ANTIDEP_NONE; }
297
298 // For use with PostRAScheduling: in CriticalPathRCs, return any register
299 // classes that should only be considered for anti-dependence breaking if they
300 // are on the critical path.
301 virtual void getCriticalPathRCs(RegClassVector &CriticalPathRCs) const {
302 return CriticalPathRCs.clear();
303 }
304
305 // Provide an ordered list of schedule DAG mutations for the post-RA
306 // scheduler.
307 virtual void getPostRAMutations(
308 std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations) const {
309 }
310
311 // Provide an ordered list of schedule DAG mutations for the machine
312 // pipeliner.
313 virtual void getSMSMutations(
314 std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations) const {
315 }
316
317 /// Default to DFA for resource management, return false when target will use
318 /// ProcResource in InstrSchedModel instead.
319 virtual bool useDFAforSMS() const { return true; }
320
321 // For use with PostRAScheduling: get the minimum optimization level needed
322 // to enable post-RA scheduling.
326
327 /// True if the subtarget should run the local reassignment
328 /// heuristic of the register allocator.
329 /// This heuristic may be compile time intensive, \p OptLevel provides
330 /// a finer grain to tune the register allocator.
331 virtual bool enableRALocalReassignment(CodeGenOptLevel OptLevel) const;
332
333 /// Enable use of alias analysis during code generation (during MI
334 /// scheduling, DAGCombine, etc.).
335 virtual bool useAA() const;
336
337 /// \brief Sink addresses into blocks using GEP instructions rather than
338 /// pointer casts and arithmetic.
339 virtual bool addrSinkUsingGEPs() const {
340 return useAA();
341 }
342
343 /// Enable the use of the early if conversion pass.
344 virtual bool enableEarlyIfConversion() const { return false; }
345
346 /// Return PBQPConstraint(s) for the target.
347 ///
348 /// Override to provide custom PBQP constraints.
349 virtual std::unique_ptr<PBQPRAConstraint> getCustomPBQPConstraints() const {
350 return nullptr;
351 }
352
353 /// Enable tracking of subregister liveness in register allocator.
354 /// Please use MachineRegisterInfo::subRegLivenessEnabled() instead where
355 /// possible.
356 virtual bool enableSubRegLiveness() const { return false; }
357
358 /// This is called after a .mir file was loaded.
359 virtual void mirFileLoaded(MachineFunction &MF) const;
360
361 /// Constructs a Mask of physical registers whose allocation orders should be
362 /// used exactly as written in the TableGen descriptions, rather than
363 /// allocating them later if they are callee-saved. Mask is empty on entry
364 /// and must either remain empty or cover all physical registers.
366 BitVector &Mask) const {}
367
368 /// Classify a global function reference. This mainly used to fetch target
369 /// special flags for lowering a function address. For example mark a function
370 /// call should be plt or pc-related addressing.
371 virtual unsigned char
373 return 0;
374 }
375
376 /// Enable spillage copy elimination in MachineCopyPropagation pass. This
377 /// helps removing redundant copies generated by register allocator when
378 /// handling complex eviction chains.
379 virtual bool enableSpillageCopyElimination() const { return false; }
380
381 /// Get the list of MacroFusion predicates.
382 virtual std::vector<MacroFusionPredTy> getMacroFusions() const { return {}; };
383
384 /// Whether the target has instructions where an early-clobber result
385 /// operand cannot overlap with an undef input operand.
387 // Conservatively assume such instructions exist by default.
388 return true;
389 }
390
391 virtual bool isRegisterReservedByUser(Register R) const { return false; }
392
393 /// Target features to ignore for inline compatibility check.
394 virtual const FeatureBitset &getInlineIgnoreFeatures() const = 0;
395 /// Target features where the callee may have an additional feature,
396 /// instead of the caller.
397 virtual const FeatureBitset &getInlineInverseFeatures() const = 0;
398 /// Target features where all mismatches prevent inlining.
399 virtual const FeatureBitset &getInlineMustMatchFeatures() const = 0;
400
401private:
402 /// Lazy, incrementally-populated cache for isIntrinsicSupported().
403 mutable DenseMap<unsigned, bool> IntrinsicSupportCache;
404};
405} // end namespace llvm
406
407#endif // LLVM_CODEGEN_TARGETSUBTARGETINFO_H
#define LLVM_ABI
Definition Compiler.h:215
This file defines the DenseMap class.
IRTranslator LLVM IR MI
static bool enablePostRAScheduler(const TargetSubtargetInfo &ST, CodeGenOptLevel OptLevel)
SI optimize exec mask operations pre RA
This file defines the SmallVector class.
Class for arbitrary precision integers.
Definition APInt.h:78
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
Container class for subtarget features.
Itinerary data supplied by a subtarget to be used by a target.
Tracks which library functions to use for a particular subtarget or function.
MCRegisterClass - Base class of TargetRegisterClass.
MCSubtargetInfo(const MCSubtargetInfo &)=default
const MCSchedModel & getSchedModel() const
Get the machine model for this subtarget's CPU.
Representation of each machine instruction.
Holds all the information related to register banks.
ScheduleDAGSDNodes *(*)(SelectionDAGISel *, CodeGenOptLevel) FunctionPassCtor
Wrapper class representing virtual and physical registers.
Definition Register.h:20
Scheduling dependency.
Definition ScheduleDAG.h:52
Scheduling unit. This is a node in the scheduling DAG.
Mutate the DAG as a postpass after normal DAG building.
Targets can subclass this to parameterize the SelectionDAG lowering and instruction selection process...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
A table of densely packed, null-terminated strings indexed by offset.
Definition StringTable.h:34
Information about stack frame layout on the target.
TargetInstrInfo - Interface to description of machine instruction set.
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
Provide an instruction scheduling machine model to CodeGen passes.
virtual unsigned char classifyGlobalFunctionReference(const GlobalValue *GV) const
Classify a global function reference.
virtual bool requiresDisjointEarlyClobberAndUndef() const
Whether the target has instructions where an early-clobber result operand cannot overlap with an unde...
virtual void overridePipelinerPolicy(MachinePipelinerPolicy &Policy) const
Override generic software pipelining policy.
TargetSubtargetInfo(const Triple &TT, StringRef CPU, StringRef TuneCPU, StringRef FS, StringTable PN, ArrayRef< SubtargetFeatureKV > PF, ArrayRef< SubtargetSubTypeKV > PD, ArrayRef< SubtargetSubTypeAliasKV > PA, const MCSchedModel *PSM, const MCWriteProcResEntry *WPR, const MCWriteLatencyEntry *WL, const MCReadAdvanceEntry *RA, const InstrStage *IS, const unsigned *OC, const unsigned *FP)
enum { ANTIDEP_NONE, ANTIDEP_CRITICAL, ANTIDEP_ALL } AntiDepBreakMode
SmallVectorImpl< const TargetRegisterClass * > RegClassVector
virtual std::vector< MacroFusionPredTy > getMacroFusions() const
Get the list of MacroFusion predicates.
virtual const SelectionDAGTargetInfo * getSelectionDAGInfo() const
virtual void overridePostRASchedPolicy(MachineSchedPolicy &Policy, const SchedRegion &Region) const
Override generic post-ra scheduling policy within a region.
virtual void getCSRAllocationOrderMask(const MachineFunction &MF, BitVector &Mask) const
Constructs a Mask of physical registers whose allocation orders should be used exactly as written in ...
virtual const FeatureBitset & getInlineMustMatchFeatures() const =0
Target features where all mismatches prevent inlining.
virtual const InlineAsmLowering * getInlineAsmLowering() const
virtual unsigned getMispredictionPenalty() const
Return the number of extra cycles the processor takes to recover from a branch misprediction.
virtual void overrideSchedPolicy(MachineSchedPolicy &Policy, const SchedRegion &Region) const
Override generic scheduling policy within a region.
virtual void initLibcallLoweringInfo(LibcallLoweringInfo &Info) const
Configure the LibcallLoweringInfo for this subtarget.
virtual bool isRegisterReservedByUser(Register R) const
virtual std::unique_ptr< PBQPRAConstraint > getCustomPBQPConstraints() const
Return PBQPConstraint(s) for the target.
virtual unsigned getLoadLatency() const
Return the expected latency of load instructions.
virtual void getCriticalPathRCs(RegClassVector &CriticalPathRCs) const
virtual CodeGenOptLevel getOptLevelToEnablePostRAScheduler() const
virtual RegisterScheduler::FunctionPassCtor getDAGScheduler(CodeGenOptLevel) const
Target can subclass this hook to select a different DAG scheduler.
virtual bool enableSpillageCopyElimination() const
Enable spillage copy elimination in MachineCopyPropagation pass.
virtual bool isDependencyBreaking(const MachineInstr *MI, APInt &Mask) const
Returns true if MI is a dependency breaking instruction for the subtarget.
virtual const CallLowering * getCallLowering() const
virtual bool isXRaySupported() const
virtual const RegisterBankInfo * getRegBankInfo() const
If the information for the register banks is available, return it.
virtual bool useAA() const
Enable use of alias analysis during code generation (during MI scheduling, DAGCombine,...
TargetSubtargetInfo(const TargetSubtargetInfo &)=delete
virtual InstructionSelector * getInstructionSelector() const
virtual AntiDepBreakMode getAntiDepBreakMode() const
virtual bool enableWindowScheduler() const
True if the subtarget should run WindowScheduler.
virtual void getPostRAMutations(std::vector< std::unique_ptr< ScheduleDAGMutation > > &Mutations) const
virtual void getSMSMutations(std::vector< std::unique_ptr< ScheduleDAGMutation > > &Mutations) const
virtual bool enableMachinePipeliner() const
True if the subtarget should run MachinePipeliner.
virtual const LegalizerInfo * getLegalizerInfo() const
virtual bool useDFAforSMS() const
Default to DFA for resource management, return false when target will use ProcResource in InstrSchedM...
virtual void adjustSchedDependency(SUnit *Def, int DefOpIdx, SUnit *Use, int UseOpIdx, SDep &Dep, const TargetSchedModel *SchedModel) const
virtual const TargetFrameLowering * getFrameLowering() const
virtual bool isOptimizableRegisterMove(const MachineInstr *MI) const
Returns true if MI is a candidate for move elimination.
virtual const TargetInstrInfo * getInstrInfo() const
virtual bool isZeroIdiom(const MachineInstr *MI, APInt &Mask) const
Returns true if MI is a dependency breaking zero-idiom instruction for the subtarget.
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
virtual bool enableMachineSchedDefaultSched() const
True if the machine scheduler should disable the TLI preference for preRA scheduling with the source ...
virtual bool enableSubRegLiveness() const
Enable tracking of subregister liveness in register allocator.
virtual const FeatureBitset & getInlineInverseFeatures() const =0
Target features where the callee may have an additional feature, instead of the caller.
virtual const TargetLowering * getTargetLowering() const
virtual bool addrSinkUsingGEPs() const
Sink addresses into blocks using GEP instructions rather than pointer casts and arithmetic.
virtual const InstrItineraryData * getInstrItineraryData() const
getInstrItineraryData - Returns instruction itinerary data for the target or specific subtarget.
virtual const FeatureBitset & getInlineIgnoreFeatures() const =0
Target features to ignore for inline compatibility check.
virtual bool enableTerminalRule() const
Hack to bring up option.
virtual unsigned resolveSchedClass(unsigned SchedClass, const MachineInstr *MI, const TargetSchedModel *SchedModel) const
Resolve a SchedClass at runtime, where SchedClass identifies an MCSchedClassDesc with the isVariant p...
TargetSubtargetInfo & operator=(const TargetSubtargetInfo &)=delete
virtual bool enableEarlyIfConversion() const
Enable the use of the early if conversion pass.
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
A Use represents the edge between a Value definition and its users.
Definition Use.h:35
This is an optimization pass for GlobalISel generic memory operations.
CodeGenOptLevel
Code generation optimization level.
Definition CodeGen.h:149
@ Default
-O2, -Os, -Oz
Definition CodeGen.h:152
MCRegisterClass TargetRegisterClass
Definition FastISel.h:58
These values represent a non-pipelined step in the execution of an instruction.
Specify the number of cycles allowed after instruction issue before a particular use operand reads it...
Definition MCSchedule.h:114
Machine model for scheduling, bundling, and heuristics.
Definition MCSchedule.h:273
Specify the latency in cpu cycles for a particular scheduling class and def index.
Definition MCSchedule.h:97
Identify one of the processor resource kinds consumed by a particular scheduling class for the specif...
Definition MCSchedule.h:74
Software pipelining policy for a loop, which a target can customize by implementing TargetSubtargetIn...
Define a generic scheduling policy for targets that don't provide their own MachineSchedStrategy.
A region of an MBB for scheduling.