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