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;
48struct MCSchedModel;
52class SDep;
54class SUnit;
56class TargetInstrInfo;
57class TargetLowering;
58class MCRegisterClass;
62class Triple;
63struct SchedRegion;
64
65//===----------------------------------------------------------------------===//
66///
67/// TargetSubtargetInfo - Generic base class for all target subtargets. All
68/// Target-specific options that control code generation and printing should
69/// be exposed through a TargetSubtargetInfo-derived class.
70///
72protected: // Can only create subclasses...
73 TargetSubtargetInfo(const Triple &TT, StringRef CPU, StringRef TuneCPU,
78 const MCSchedModel *PSM, const MCWriteProcResEntry *WPR,
79 const MCWriteLatencyEntry *WL,
80 const MCReadAdvanceEntry *RA, const InstrStage *IS,
81 const unsigned *OC, const unsigned *FP);
82
83public:
84 // AntiDepBreakMode - Type of anti-dependence breaking that should
85 // be performed before post-RA scheduling.
86 using AntiDepBreakMode = enum { ANTIDEP_NONE, ANTIDEP_CRITICAL, ANTIDEP_ALL };
88
93
94 virtual bool isXRaySupported() const { return false; }
95
96 /// \returns true if the target intrinsic \p IntrinsicID is supported by this
97 /// subtarget.
98 bool isIntrinsicSupported(unsigned IntrinsicID) const;
99
100 // Interfaces to the major aspects of target machine information:
101 //
102 // -- Instruction opcode and operand information
103 // -- Pipelines and scheduling information
104 // -- Stack frame information
105 // -- Selection DAG lowering information
106 // -- Call lowering information
107 //
108 // N.B. These objects may change during compilation. It's not safe to cache
109 // them between functions.
110 virtual const TargetInstrInfo *getInstrInfo() const { return nullptr; }
111 virtual const TargetFrameLowering *getFrameLowering() const {
112 return nullptr;
113 }
114 virtual const TargetLowering *getTargetLowering() const { return nullptr; }
116 return nullptr;
117 }
118 virtual const CallLowering *getCallLowering() const { return nullptr; }
119
121 return nullptr;
122 }
123
124 // FIXME: This lets targets specialize the selector by subtarget (which lets
125 // us do things like a dedicated avx512 selector). However, we might want
126 // to also specialize selectors by MachineFunction, which would let us be
127 // aware of optsize/optnone and such.
129 return nullptr;
130 }
131
132 /// Target can subclass this hook to select a different DAG scheduler.
135 return nullptr;
136 }
137
138 virtual const LegalizerInfo *getLegalizerInfo() const { return nullptr; }
139
140 /// Return the target's register information.
141 virtual const TargetRegisterInfo *getRegisterInfo() const = 0;
142
143 /// If the information for the register banks is available, return it.
144 /// Otherwise return nullptr.
145 virtual const RegisterBankInfo *getRegBankInfo() const { return nullptr; }
146
147 /// getInstrItineraryData - Returns instruction itinerary data for the target
148 /// or specific subtarget.
150 return nullptr;
151 }
152
153 /// Return the number of extra cycles the processor takes to recover from a
154 /// branch misprediction. Defaults to the value in the scheduling model.
155 virtual unsigned getMispredictionPenalty() const {
156 return getSchedModel().MispredictPenalty;
157 }
158
159 /// Return the expected latency of load instructions. Defaults to the value
160 /// in the scheduling model.
161 virtual unsigned getLoadLatency() const {
162 return getSchedModel().LoadLatency;
163 }
164
165 /// Configure the LibcallLoweringInfo for this subtarget. The libcalls will be
166 /// pre-configured with defaults based on RuntimeLibcallsInfo. This may be
167 /// used to override those decisions, such as disambiguating alternative
168 /// implementations.
169 virtual void initLibcallLoweringInfo(LibcallLoweringInfo &Info) const {}
170
171 /// Resolve a SchedClass at runtime, where SchedClass identifies an
172 /// MCSchedClassDesc with the isVariant property. This may return the ID of
173 /// another variant SchedClass, but repeated invocation must quickly terminate
174 /// in a nonvariant SchedClass.
175 virtual unsigned resolveSchedClass(unsigned SchedClass,
176 const MachineInstr *MI,
177 const TargetSchedModel *SchedModel) const {
178 return 0;
179 }
180
181 /// Returns true if MI is a dependency breaking zero-idiom instruction for the
182 /// subtarget.
183 ///
184 /// This function also sets bits in Mask related to input operands that
185 /// are not in a data dependency relationship. There is one bit for each
186 /// machine operand; implicit operands follow explicit operands in the bit
187 /// representation used for Mask. An empty (i.e. a mask with all bits
188 /// cleared) means: data dependencies are "broken" for all the explicit input
189 /// machine operands of MI.
190 virtual bool isZeroIdiom(const MachineInstr *MI, APInt &Mask) const {
191 return false;
192 }
193
194 /// Returns true if MI is a dependency breaking instruction for the subtarget.
195 ///
196 /// Similar in behavior to `isZeroIdiom`. However, it knows how to identify
197 /// all dependency breaking instructions (i.e. not just zero-idioms).
198 ///
199 /// As for `isZeroIdiom`, this method returns a mask of "broken" dependencies.
200 /// (See method `isZeroIdiom` for a detailed description of Mask).
201 virtual bool isDependencyBreaking(const MachineInstr *MI, APInt &Mask) const {
202 return isZeroIdiom(MI, Mask);
203 }
204
205 /// Returns true if MI is a candidate for move elimination.
206 ///
207 /// A candidate for move elimination may be optimized out at register renaming
208 /// stage. Subtargets can specify the set of optimizable moves by
209 /// instantiating tablegen class `IsOptimizableRegisterMove` (see
210 /// llvm/Target/TargetInstrPredicate.td).
211 ///
212 /// SubtargetEmitter is responsible for processing all the definitions of class
213 /// IsOptimizableRegisterMove, and auto-generate an override for this method.
214 virtual bool isOptimizableRegisterMove(const MachineInstr *MI) const {
215 return false;
216 }
217
218 /// True if the subtarget should run MachineScheduler after aggressive
219 /// coalescing.
220 ///
221 /// This currently replaces the SelectionDAG scheduler with the "source" order
222 /// scheduler (though see below for an option to turn this off and use the
223 /// TargetLowering preference). It does not yet disable the postRA scheduler.
224 virtual bool enableMachineScheduler() const;
225
226 /// True if the machine scheduler should disable the TLI preference
227 /// for preRA scheduling with the source level scheduler.
228 virtual bool enableMachineSchedDefaultSched() const { return true; }
229
230 /// True if the subtarget should run MachinePipeliner
231 virtual bool enableMachinePipeliner() const { return true; };
232
233 /// True if the subtarget should run WindowScheduler.
234 virtual bool enableWindowScheduler() const { return true; }
235
236 /// True if the subtarget should enable joining global copies.
237 ///
238 /// By default this is enabled if the machine scheduler is enabled, but
239 /// can be overridden.
240 virtual bool enableJoinGlobalCopies() const;
241
242 /// Hack to bring up option. This should be unconditionally true, all targets
243 /// should enable it and delete this.
244 virtual bool enableTerminalRule() const { return false; }
245
246 /// True if the subtarget should run a scheduler after register allocation.
247 ///
248 /// By default this queries the PostRAScheduling bit in the scheduling model
249 /// which is the preferred way to influence this.
250 virtual bool enablePostRAScheduler() const;
251
252 /// True if the subtarget should run a machine scheduler after register
253 /// allocation.
254 virtual bool enablePostRAMachineScheduler() const;
255
256 /// True if the subtarget should run the atomic expansion pass.
257 virtual bool enableAtomicExpand() const;
258
259 /// True if the subtarget should run the indirectbr expansion pass.
260 virtual bool enableIndirectBrExpand() const;
261
262 /// Override generic scheduling policy within a region.
263 ///
264 /// This is a convenient way for targets that don't provide any custom
265 /// scheduling heuristics (no custom MachineSchedStrategy) to make
266 /// changes to the generic scheduling policy.
268 const SchedRegion &Region) const {}
269
270 /// Override generic post-ra scheduling policy within a region.
271 ///
272 /// This is a convenient way for targets that don't provide any custom
273 /// scheduling heuristics (no custom MachineSchedStrategy) to make
274 /// changes to the generic post-ra scheduling policy.
275 /// Note that some options like tracking register pressure won't take effect
276 /// in post-ra scheduling.
278 const SchedRegion &Region) const {}
279
280 // Perform target-specific adjustments to the latency of a schedule
281 // dependency.
282 // If a pair of operands is associated with the schedule dependency, DefOpIdx
283 // and UseOpIdx are the indices of the operands in Def and Use, respectively.
284 // Otherwise, either may be -1.
285 virtual void adjustSchedDependency(SUnit *Def, int DefOpIdx, SUnit *Use,
286 int UseOpIdx, SDep &Dep,
287 const TargetSchedModel *SchedModel) const {
288 }
289
290 // For use with PostRAScheduling: get the anti-dependence breaking that should
291 // be performed before post-RA scheduling.
292 virtual AntiDepBreakMode getAntiDepBreakMode() const { return ANTIDEP_NONE; }
293
294 // For use with PostRAScheduling: in CriticalPathRCs, return any register
295 // classes that should only be considered for anti-dependence breaking if they
296 // are on the critical path.
297 virtual void getCriticalPathRCs(RegClassVector &CriticalPathRCs) const {
298 return CriticalPathRCs.clear();
299 }
300
301 // Provide an ordered list of schedule DAG mutations for the post-RA
302 // scheduler.
303 virtual void getPostRAMutations(
304 std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations) const {
305 }
306
307 // Provide an ordered list of schedule DAG mutations for the machine
308 // pipeliner.
309 virtual void getSMSMutations(
310 std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations) const {
311 }
312
313 /// Default to DFA for resource management, return false when target will use
314 /// ProcResource in InstrSchedModel instead.
315 virtual bool useDFAforSMS() const { return true; }
316
317 // For use with PostRAScheduling: get the minimum optimization level needed
318 // to enable post-RA scheduling.
322
323 /// True if the subtarget should run the local reassignment
324 /// heuristic of the register allocator.
325 /// This heuristic may be compile time intensive, \p OptLevel provides
326 /// a finer grain to tune the register allocator.
327 virtual bool enableRALocalReassignment(CodeGenOptLevel OptLevel) const;
328
329 /// Enable use of alias analysis during code generation (during MI
330 /// scheduling, DAGCombine, etc.).
331 virtual bool useAA() const;
332
333 /// \brief Sink addresses into blocks using GEP instructions rather than
334 /// pointer casts and arithmetic.
335 virtual bool addrSinkUsingGEPs() const {
336 return useAA();
337 }
338
339 /// Enable the use of the early if conversion pass.
340 virtual bool enableEarlyIfConversion() const { return false; }
341
342 /// Return PBQPConstraint(s) for the target.
343 ///
344 /// Override to provide custom PBQP constraints.
345 virtual std::unique_ptr<PBQPRAConstraint> getCustomPBQPConstraints() const {
346 return nullptr;
347 }
348
349 /// Enable tracking of subregister liveness in register allocator.
350 /// Please use MachineRegisterInfo::subRegLivenessEnabled() instead where
351 /// possible.
352 virtual bool enableSubRegLiveness() const { return false; }
353
354 /// This is called after a .mir file was loaded.
355 virtual void mirFileLoaded(MachineFunction &MF) const;
356
357 /// Constructs a Mask of physical registers whose allocation orders should be
358 /// used exactly as written in the TableGen descriptions, rather than
359 /// allocating them later if they are callee-saved. Mask is empty on entry
360 /// and must either remain empty or cover all physical registers.
362 BitVector &Mask) const {}
363
364 /// Classify a global function reference. This mainly used to fetch target
365 /// special flags for lowering a function address. For example mark a function
366 /// call should be plt or pc-related addressing.
367 virtual unsigned char
369 return 0;
370 }
371
372 /// Enable spillage copy elimination in MachineCopyPropagation pass. This
373 /// helps removing redundant copies generated by register allocator when
374 /// handling complex eviction chains.
375 virtual bool enableSpillageCopyElimination() const { return false; }
376
377 /// Get the list of MacroFusion predicates.
378 virtual std::vector<MacroFusionPredTy> getMacroFusions() const { return {}; };
379
380 /// Whether the target has instructions where an early-clobber result
381 /// operand cannot overlap with an undef input operand.
383 // Conservatively assume such instructions exist by default.
384 return true;
385 }
386
387 virtual bool isRegisterReservedByUser(Register R) const { return false; }
388
389 /// Target features to ignore for inline compatibility check.
390 virtual const FeatureBitset &getInlineIgnoreFeatures() const = 0;
391 /// Target features where the callee may have an additional feature,
392 /// instead of the caller.
393 virtual const FeatureBitset &getInlineInverseFeatures() const = 0;
394 /// Target features where all mismatches prevent inlining.
395 virtual const FeatureBitset &getInlineMustMatchFeatures() const = 0;
396
397private:
398 /// Lazy, incrementally-populated cache for isIntrinsicSupported().
399 mutable DenseMap<unsigned, bool> IntrinsicSupportCache;
400};
401} // end namespace llvm
402
403#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.
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...
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
Define a generic scheduling policy for targets that don't provide their own MachineSchedStrategy.
A region of an MBB for scheduling.