1 //==-- llvm/Target/TargetSubtargetInfo.h - Target Information ----*- C++ -*-==//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file describes the subtarget options of a Target machine.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_TARGET_TARGETSUBTARGETINFO_H
15 #define LLVM_TARGET_TARGETSUBTARGETINFO_H
17 #include "llvm/ADT/ArrayRef.h"
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/ADT/StringRef.h"
20 #include "llvm/CodeGen/PBQPRAConstraint.h"
21 #include "llvm/CodeGen/SchedulerRegistry.h"
22 #include "llvm/CodeGen/ScheduleDAGMutation.h"
23 #include "llvm/MC/MCSubtargetInfo.h"
24 #include "llvm/Support/CodeGen.h"
31 class InstructionSelector;
34 class RegisterBankInfo;
36 class SelectionDAGTargetInfo;
38 class TargetFrameLowering;
39 class TargetInstrInfo;
41 class TargetRegisterClass;
42 class TargetRegisterInfo;
43 class TargetSchedModel;
44 struct MachineSchedPolicy;
46 //===----------------------------------------------------------------------===//
48 /// TargetSubtargetInfo - Generic base class for all target subtargets. All
49 /// Target-specific options that control code generation and printing should
50 /// be exposed through a TargetSubtargetInfo-derived class.
52 class TargetSubtargetInfo : public MCSubtargetInfo {
53 protected: // Can only create subclasses...
54 TargetSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS,
55 ArrayRef<SubtargetFeatureKV> PF,
56 ArrayRef<SubtargetFeatureKV> PD,
57 const SubtargetInfoKV *ProcSched,
58 const MCWriteProcResEntry *WPR,
59 const MCWriteLatencyEntry *WL,
60 const MCReadAdvanceEntry *RA, const InstrStage *IS,
61 const unsigned *OC, const unsigned *FP);
64 // AntiDepBreakMode - Type of anti-dependence breaking that should
65 // be performed before post-RA scheduling.
66 typedef enum { ANTIDEP_NONE, ANTIDEP_CRITICAL, ANTIDEP_ALL } AntiDepBreakMode;
67 typedef SmallVectorImpl<const TargetRegisterClass *> RegClassVector;
69 TargetSubtargetInfo() = delete;
70 TargetSubtargetInfo(const TargetSubtargetInfo &) = delete;
71 void operator=(const TargetSubtargetInfo &) = delete;
72 virtual ~TargetSubtargetInfo();
74 virtual bool isXRaySupported() const { return false; }
76 // Interfaces to the major aspects of target machine information:
78 // -- Instruction opcode and operand information
79 // -- Pipelines and scheduling information
80 // -- Stack frame information
81 // -- Selection DAG lowering information
82 // -- Call lowering information
84 // N.B. These objects may change during compilation. It's not safe to cache
85 // them between functions.
86 virtual const TargetInstrInfo *getInstrInfo() const { return nullptr; }
87 virtual const TargetFrameLowering *getFrameLowering() const {
90 virtual const TargetLowering *getTargetLowering() const { return nullptr; }
91 virtual const SelectionDAGTargetInfo *getSelectionDAGInfo() const {
94 virtual const CallLowering *getCallLowering() const { return nullptr; }
96 // FIXME: This lets targets specialize the selector by subtarget (which lets
97 // us do things like a dedicated avx512 selector). However, we might want
98 // to also specialize selectors by MachineFunction, which would let us be
99 // aware of optsize/optnone and such.
100 virtual const InstructionSelector *getInstructionSelector() const {
104 /// Target can subclass this hook to select a different DAG scheduler.
105 virtual RegisterScheduler::FunctionPassCtor
106 getDAGScheduler(CodeGenOpt::Level) const {
110 virtual const LegalizerInfo *getLegalizerInfo() const { return nullptr; }
112 /// getRegisterInfo - If register information is available, return it. If
113 /// not, return null.
115 virtual const TargetRegisterInfo *getRegisterInfo() const { return nullptr; }
117 /// If the information for the register banks is available, return it.
118 /// Otherwise return nullptr.
119 virtual const RegisterBankInfo *getRegBankInfo() const { return nullptr; }
121 /// getInstrItineraryData - Returns instruction itinerary data for the target
122 /// or specific subtarget.
124 virtual const InstrItineraryData *getInstrItineraryData() const {
128 /// Resolve a SchedClass at runtime, where SchedClass identifies an
129 /// MCSchedClassDesc with the isVariant property. This may return the ID of
130 /// another variant SchedClass, but repeated invocation must quickly terminate
131 /// in a nonvariant SchedClass.
132 virtual unsigned resolveSchedClass(unsigned SchedClass,
133 const MachineInstr *MI,
134 const TargetSchedModel *SchedModel) const {
138 /// \brief True if the subtarget should run MachineScheduler after aggressive
141 /// This currently replaces the SelectionDAG scheduler with the "source" order
142 /// scheduler (though see below for an option to turn this off and use the
143 /// TargetLowering preference). It does not yet disable the postRA scheduler.
144 virtual bool enableMachineScheduler() const;
146 /// \brief True if the machine scheduler should disable the TLI preference
147 /// for preRA scheduling with the source level scheduler.
148 virtual bool enableMachineSchedDefaultSched() const { return true; }
150 /// \brief True if the subtarget should enable joining global copies.
152 /// By default this is enabled if the machine scheduler is enabled, but
153 /// can be overridden.
154 virtual bool enableJoinGlobalCopies() const;
156 /// True if the subtarget should run a scheduler after register allocation.
158 /// By default this queries the PostRAScheduling bit in the scheduling model
159 /// which is the preferred way to influence this.
160 virtual bool enablePostRAScheduler() const;
162 /// \brief True if the subtarget should run the atomic expansion pass.
163 virtual bool enableAtomicExpand() const;
165 /// \brief Override generic scheduling policy within a region.
167 /// This is a convenient way for targets that don't provide any custom
168 /// scheduling heuristics (no custom MachineSchedStrategy) to make
169 /// changes to the generic scheduling policy.
170 virtual void overrideSchedPolicy(MachineSchedPolicy &Policy,
171 unsigned NumRegionInstrs) const {}
173 // \brief Perform target specific adjustments to the latency of a schedule
175 virtual void adjustSchedDependency(SUnit *def, SUnit *use, SDep &dep) const {}
177 // For use with PostRAScheduling: get the anti-dependence breaking that should
178 // be performed before post-RA scheduling.
179 virtual AntiDepBreakMode getAntiDepBreakMode() const { return ANTIDEP_NONE; }
181 // For use with PostRAScheduling: in CriticalPathRCs, return any register
182 // classes that should only be considered for anti-dependence breaking if they
183 // are on the critical path.
184 virtual void getCriticalPathRCs(RegClassVector &CriticalPathRCs) const {
185 return CriticalPathRCs.clear();
188 // \brief Provide an ordered list of schedule DAG mutations for the post-RA
190 virtual void getPostRAMutations(
191 std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations) const {
194 // \brief Provide an ordered list of schedule DAG mutations for the machine
196 virtual void getSMSMutations(
197 std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations) const {
200 // For use with PostRAScheduling: get the minimum optimization level needed
201 // to enable post-RA scheduling.
202 virtual CodeGenOpt::Level getOptLevelToEnablePostRAScheduler() const {
203 return CodeGenOpt::Default;
206 /// \brief True if the subtarget should run the local reassignment
207 /// heuristic of the register allocator.
208 /// This heuristic may be compile time intensive, \p OptLevel provides
209 /// a finer grain to tune the register allocator.
210 virtual bool enableRALocalReassignment(CodeGenOpt::Level OptLevel) const;
212 /// \brief Enable use of alias analysis during code generation (during MI
213 /// scheduling, DAGCombine, etc.).
214 virtual bool useAA() const;
216 /// \brief Enable the use of the early if conversion pass.
217 virtual bool enableEarlyIfConversion() const { return false; }
219 /// \brief Return PBQPConstraint(s) for the target.
221 /// Override to provide custom PBQP constraints.
222 virtual std::unique_ptr<PBQPRAConstraint> getCustomPBQPConstraints() const {
226 /// Enable tracking of subregister liveness in register allocator.
227 /// Please use MachineRegisterInfo::subRegLivenessEnabled() instead where
229 virtual bool enableSubRegLiveness() const { return false; }
232 } // end namespace llvm
234 #endif // LLVM_TARGET_TARGETSUBTARGETINFO_H