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