|
|
|||
File indexing completed on 2026-05-10 08:43:38
0001 //===- llvm/CodeGen/TargetSubtargetInfo.h - Target Information --*- C++ -*-===// 0002 // 0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 0004 // See https://llvm.org/LICENSE.txt for license information. 0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 0006 // 0007 //===----------------------------------------------------------------------===// 0008 // 0009 // This file describes the subtarget options of a Target machine. 0010 // 0011 //===----------------------------------------------------------------------===// 0012 0013 #ifndef LLVM_CODEGEN_TARGETSUBTARGETINFO_H 0014 #define LLVM_CODEGEN_TARGETSUBTARGETINFO_H 0015 0016 #include "llvm/ADT/ArrayRef.h" 0017 #include "llvm/ADT/SmallVector.h" 0018 #include "llvm/ADT/StringRef.h" 0019 #include "llvm/CodeGen/MacroFusion.h" 0020 #include "llvm/CodeGen/PBQPRAConstraint.h" 0021 #include "llvm/CodeGen/SchedulerRegistry.h" 0022 #include "llvm/IR/GlobalValue.h" 0023 #include "llvm/MC/MCSubtargetInfo.h" 0024 #include "llvm/Support/CodeGen.h" 0025 #include <memory> 0026 #include <vector> 0027 0028 namespace llvm { 0029 0030 class APInt; 0031 class MachineFunction; 0032 class ScheduleDAGMutation; 0033 class CallLowering; 0034 class GlobalValue; 0035 class InlineAsmLowering; 0036 class InstrItineraryData; 0037 struct InstrStage; 0038 class InstructionSelector; 0039 class LegalizerInfo; 0040 class MachineInstr; 0041 struct MachineSchedPolicy; 0042 struct MCReadAdvanceEntry; 0043 struct MCWriteLatencyEntry; 0044 struct MCWriteProcResEntry; 0045 class RegisterBankInfo; 0046 class SDep; 0047 class SelectionDAGTargetInfo; 0048 class SUnit; 0049 class TargetFrameLowering; 0050 class TargetInstrInfo; 0051 class TargetLowering; 0052 class TargetRegisterClass; 0053 class TargetRegisterInfo; 0054 class TargetSchedModel; 0055 class Triple; 0056 0057 //===----------------------------------------------------------------------===// 0058 /// 0059 /// TargetSubtargetInfo - Generic base class for all target subtargets. All 0060 /// Target-specific options that control code generation and printing should 0061 /// be exposed through a TargetSubtargetInfo-derived class. 0062 /// 0063 class TargetSubtargetInfo : public MCSubtargetInfo { 0064 protected: // Can only create subclasses... 0065 TargetSubtargetInfo(const Triple &TT, StringRef CPU, StringRef TuneCPU, 0066 StringRef FS, ArrayRef<StringRef> PN, 0067 ArrayRef<SubtargetFeatureKV> PF, 0068 ArrayRef<SubtargetSubTypeKV> PD, 0069 const MCWriteProcResEntry *WPR, 0070 const MCWriteLatencyEntry *WL, 0071 const MCReadAdvanceEntry *RA, const InstrStage *IS, 0072 const unsigned *OC, const unsigned *FP); 0073 0074 public: 0075 // AntiDepBreakMode - Type of anti-dependence breaking that should 0076 // be performed before post-RA scheduling. 0077 using AntiDepBreakMode = enum { ANTIDEP_NONE, ANTIDEP_CRITICAL, ANTIDEP_ALL }; 0078 using RegClassVector = SmallVectorImpl<const TargetRegisterClass *>; 0079 0080 TargetSubtargetInfo() = delete; 0081 TargetSubtargetInfo(const TargetSubtargetInfo &) = delete; 0082 TargetSubtargetInfo &operator=(const TargetSubtargetInfo &) = delete; 0083 ~TargetSubtargetInfo() override; 0084 0085 virtual bool isXRaySupported() const { return false; } 0086 0087 // Interfaces to the major aspects of target machine information: 0088 // 0089 // -- Instruction opcode and operand information 0090 // -- Pipelines and scheduling information 0091 // -- Stack frame information 0092 // -- Selection DAG lowering information 0093 // -- Call lowering information 0094 // 0095 // N.B. These objects may change during compilation. It's not safe to cache 0096 // them between functions. 0097 virtual const TargetInstrInfo *getInstrInfo() const { return nullptr; } 0098 virtual const TargetFrameLowering *getFrameLowering() const { 0099 return nullptr; 0100 } 0101 virtual const TargetLowering *getTargetLowering() const { return nullptr; } 0102 virtual const SelectionDAGTargetInfo *getSelectionDAGInfo() const { 0103 return nullptr; 0104 } 0105 virtual const CallLowering *getCallLowering() const { return nullptr; } 0106 0107 virtual const InlineAsmLowering *getInlineAsmLowering() const { 0108 return nullptr; 0109 } 0110 0111 // FIXME: This lets targets specialize the selector by subtarget (which lets 0112 // us do things like a dedicated avx512 selector). However, we might want 0113 // to also specialize selectors by MachineFunction, which would let us be 0114 // aware of optsize/optnone and such. 0115 virtual InstructionSelector *getInstructionSelector() const { 0116 return nullptr; 0117 } 0118 0119 /// Target can subclass this hook to select a different DAG scheduler. 0120 virtual RegisterScheduler::FunctionPassCtor 0121 getDAGScheduler(CodeGenOptLevel) const { 0122 return nullptr; 0123 } 0124 0125 virtual const LegalizerInfo *getLegalizerInfo() const { return nullptr; } 0126 0127 /// getRegisterInfo - If register information is available, return it. If 0128 /// not, return null. 0129 virtual const TargetRegisterInfo *getRegisterInfo() const { return nullptr; } 0130 0131 /// If the information for the register banks is available, return it. 0132 /// Otherwise return nullptr. 0133 virtual const RegisterBankInfo *getRegBankInfo() const { return nullptr; } 0134 0135 /// getInstrItineraryData - Returns instruction itinerary data for the target 0136 /// or specific subtarget. 0137 virtual const InstrItineraryData *getInstrItineraryData() const { 0138 return nullptr; 0139 } 0140 0141 /// Resolve a SchedClass at runtime, where SchedClass identifies an 0142 /// MCSchedClassDesc with the isVariant property. This may return the ID of 0143 /// another variant SchedClass, but repeated invocation must quickly terminate 0144 /// in a nonvariant SchedClass. 0145 virtual unsigned resolveSchedClass(unsigned SchedClass, 0146 const MachineInstr *MI, 0147 const TargetSchedModel *SchedModel) const { 0148 return 0; 0149 } 0150 0151 /// Returns true if MI is a dependency breaking zero-idiom instruction for the 0152 /// subtarget. 0153 /// 0154 /// This function also sets bits in Mask related to input operands that 0155 /// are not in a data dependency relationship. There is one bit for each 0156 /// machine operand; implicit operands follow explicit operands in the bit 0157 /// representation used for Mask. An empty (i.e. a mask with all bits 0158 /// cleared) means: data dependencies are "broken" for all the explicit input 0159 /// machine operands of MI. 0160 virtual bool isZeroIdiom(const MachineInstr *MI, APInt &Mask) const { 0161 return false; 0162 } 0163 0164 /// Returns true if MI is a dependency breaking instruction for the subtarget. 0165 /// 0166 /// Similar in behavior to `isZeroIdiom`. However, it knows how to identify 0167 /// all dependency breaking instructions (i.e. not just zero-idioms). 0168 /// 0169 /// As for `isZeroIdiom`, this method returns a mask of "broken" dependencies. 0170 /// (See method `isZeroIdiom` for a detailed description of Mask). 0171 virtual bool isDependencyBreaking(const MachineInstr *MI, APInt &Mask) const { 0172 return isZeroIdiom(MI, Mask); 0173 } 0174 0175 /// Returns true if MI is a candidate for move elimination. 0176 /// 0177 /// A candidate for move elimination may be optimized out at register renaming 0178 /// stage. Subtargets can specify the set of optimizable moves by 0179 /// instantiating tablegen class `IsOptimizableRegisterMove` (see 0180 /// llvm/Target/TargetInstrPredicate.td). 0181 /// 0182 /// SubtargetEmitter is responsible for processing all the definitions of class 0183 /// IsOptimizableRegisterMove, and auto-generate an override for this method. 0184 virtual bool isOptimizableRegisterMove(const MachineInstr *MI) const { 0185 return false; 0186 } 0187 0188 /// True if the subtarget should run MachineScheduler after aggressive 0189 /// coalescing. 0190 /// 0191 /// This currently replaces the SelectionDAG scheduler with the "source" order 0192 /// scheduler (though see below for an option to turn this off and use the 0193 /// TargetLowering preference). It does not yet disable the postRA scheduler. 0194 virtual bool enableMachineScheduler() const; 0195 0196 /// True if the machine scheduler should disable the TLI preference 0197 /// for preRA scheduling with the source level scheduler. 0198 virtual bool enableMachineSchedDefaultSched() const { return true; } 0199 0200 /// True if the subtarget should run MachinePipeliner 0201 virtual bool enableMachinePipeliner() const { return true; }; 0202 0203 /// True if the subtarget should run WindowScheduler. 0204 virtual bool enableWindowScheduler() const { return true; } 0205 0206 /// True if the subtarget should enable joining global copies. 0207 /// 0208 /// By default this is enabled if the machine scheduler is enabled, but 0209 /// can be overridden. 0210 virtual bool enableJoinGlobalCopies() const; 0211 0212 /// True if the subtarget should run a scheduler after register allocation. 0213 /// 0214 /// By default this queries the PostRAScheduling bit in the scheduling model 0215 /// which is the preferred way to influence this. 0216 virtual bool enablePostRAScheduler() const; 0217 0218 /// True if the subtarget should run a machine scheduler after register 0219 /// allocation. 0220 virtual bool enablePostRAMachineScheduler() const; 0221 0222 /// True if the subtarget should run the atomic expansion pass. 0223 virtual bool enableAtomicExpand() const; 0224 0225 /// True if the subtarget should run the indirectbr expansion pass. 0226 virtual bool enableIndirectBrExpand() const; 0227 0228 /// Override generic scheduling policy within a region. 0229 /// 0230 /// This is a convenient way for targets that don't provide any custom 0231 /// scheduling heuristics (no custom MachineSchedStrategy) to make 0232 /// changes to the generic scheduling policy. 0233 virtual void overrideSchedPolicy(MachineSchedPolicy &Policy, 0234 unsigned NumRegionInstrs) const {} 0235 0236 /// Override generic post-ra scheduling policy within a region. 0237 /// 0238 /// This is a convenient way for targets that don't provide any custom 0239 /// scheduling heuristics (no custom MachineSchedStrategy) to make 0240 /// changes to the generic post-ra scheduling policy. 0241 /// Note that some options like tracking register pressure won't take effect 0242 /// in post-ra scheduling. 0243 virtual void overridePostRASchedPolicy(MachineSchedPolicy &Policy, 0244 unsigned NumRegionInstrs) const {} 0245 0246 // Perform target-specific adjustments to the latency of a schedule 0247 // dependency. 0248 // If a pair of operands is associated with the schedule dependency, DefOpIdx 0249 // and UseOpIdx are the indices of the operands in Def and Use, respectively. 0250 // Otherwise, either may be -1. 0251 virtual void adjustSchedDependency(SUnit *Def, int DefOpIdx, SUnit *Use, 0252 int UseOpIdx, SDep &Dep, 0253 const TargetSchedModel *SchedModel) const { 0254 } 0255 0256 // For use with PostRAScheduling: get the anti-dependence breaking that should 0257 // be performed before post-RA scheduling. 0258 virtual AntiDepBreakMode getAntiDepBreakMode() const { return ANTIDEP_NONE; } 0259 0260 // For use with PostRAScheduling: in CriticalPathRCs, return any register 0261 // classes that should only be considered for anti-dependence breaking if they 0262 // are on the critical path. 0263 virtual void getCriticalPathRCs(RegClassVector &CriticalPathRCs) const { 0264 return CriticalPathRCs.clear(); 0265 } 0266 0267 // Provide an ordered list of schedule DAG mutations for the post-RA 0268 // scheduler. 0269 virtual void getPostRAMutations( 0270 std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations) const { 0271 } 0272 0273 // Provide an ordered list of schedule DAG mutations for the machine 0274 // pipeliner. 0275 virtual void getSMSMutations( 0276 std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations) const { 0277 } 0278 0279 /// Default to DFA for resource management, return false when target will use 0280 /// ProcResource in InstrSchedModel instead. 0281 virtual bool useDFAforSMS() const { return true; } 0282 0283 // For use with PostRAScheduling: get the minimum optimization level needed 0284 // to enable post-RA scheduling. 0285 virtual CodeGenOptLevel getOptLevelToEnablePostRAScheduler() const { 0286 return CodeGenOptLevel::Default; 0287 } 0288 0289 /// True if the subtarget should run the local reassignment 0290 /// heuristic of the register allocator. 0291 /// This heuristic may be compile time intensive, \p OptLevel provides 0292 /// a finer grain to tune the register allocator. 0293 virtual bool enableRALocalReassignment(CodeGenOptLevel OptLevel) const; 0294 0295 /// Enable use of alias analysis during code generation (during MI 0296 /// scheduling, DAGCombine, etc.). 0297 virtual bool useAA() const; 0298 0299 /// \brief Sink addresses into blocks using GEP instructions rather than 0300 /// pointer casts and arithmetic. 0301 virtual bool addrSinkUsingGEPs() const { 0302 return useAA(); 0303 } 0304 0305 /// Enable the use of the early if conversion pass. 0306 virtual bool enableEarlyIfConversion() const { return false; } 0307 0308 /// Return PBQPConstraint(s) for the target. 0309 /// 0310 /// Override to provide custom PBQP constraints. 0311 virtual std::unique_ptr<PBQPRAConstraint> getCustomPBQPConstraints() const { 0312 return nullptr; 0313 } 0314 0315 /// Enable tracking of subregister liveness in register allocator. 0316 /// Please use MachineRegisterInfo::subRegLivenessEnabled() instead where 0317 /// possible. 0318 virtual bool enableSubRegLiveness() const { return false; } 0319 0320 /// This is called after a .mir file was loaded. 0321 virtual void mirFileLoaded(MachineFunction &MF) const; 0322 0323 /// True if the register allocator should use the allocation orders exactly as 0324 /// written in the tablegen descriptions, false if it should allocate 0325 /// the specified physical register later if is it callee-saved. 0326 virtual bool ignoreCSRForAllocationOrder(const MachineFunction &MF, 0327 MCRegister PhysReg) const { 0328 return false; 0329 } 0330 0331 /// Classify a global function reference. This mainly used to fetch target 0332 /// special flags for lowering a function address. For example mark a function 0333 /// call should be plt or pc-related addressing. 0334 virtual unsigned char 0335 classifyGlobalFunctionReference(const GlobalValue *GV) const { 0336 return 0; 0337 } 0338 0339 /// Enable spillage copy elimination in MachineCopyPropagation pass. This 0340 /// helps removing redundant copies generated by register allocator when 0341 /// handling complex eviction chains. 0342 virtual bool enableSpillageCopyElimination() const { return false; } 0343 0344 /// Get the list of MacroFusion predicates. 0345 virtual std::vector<MacroFusionPredTy> getMacroFusions() const { return {}; }; 0346 0347 /// Whether the target has instructions where an early-clobber result 0348 /// operand cannot overlap with an undef input operand. 0349 virtual bool requiresDisjointEarlyClobberAndUndef() const { 0350 // Conservatively assume such instructions exist by default. 0351 return true; 0352 } 0353 0354 virtual bool isRegisterReservedByUser(Register R) const { return false; } 0355 }; 0356 } // end namespace llvm 0357 0358 #endif // LLVM_CODEGEN_TARGETSUBTARGETINFO_H
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|