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