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