TargetSubtargetInfo.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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. #ifndef LLVM_CODEGEN_TARGETSUBTARGETINFO_H
  13. #define LLVM_CODEGEN_TARGETSUBTARGETINFO_H
  14. #include "llvm/ADT/APInt.h"
  15. #include "llvm/ADT/ArrayRef.h"
  16. #include "llvm/ADT/SmallVector.h"
  17. #include "llvm/ADT/StringRef.h"
  18. #include "llvm/CodeGen/PBQPRAConstraint.h"
  19. #include "llvm/CodeGen/ScheduleDAGMutation.h"
  20. #include "llvm/CodeGen/SchedulerRegistry.h"
  21. #include "llvm/MC/MCSubtargetInfo.h"
  22. #include "llvm/Support/CodeGen.h"
  23. #include <memory>
  24. #include <vector>
  25. namespace llvm {
  26. class CallLowering;
  27. class InlineAsmLowering;
  28. class InstrItineraryData;
  29. struct InstrStage;
  30. class InstructionSelector;
  31. class LegalizerInfo;
  32. class MachineInstr;
  33. struct MachineSchedPolicy;
  34. struct MCReadAdvanceEntry;
  35. struct MCWriteLatencyEntry;
  36. struct MCWriteProcResEntry;
  37. class RegisterBankInfo;
  38. class SDep;
  39. class SelectionDAGTargetInfo;
  40. class SUnit;
  41. class TargetFrameLowering;
  42. class TargetInstrInfo;
  43. class TargetLowering;
  44. class TargetRegisterClass;
  45. class TargetRegisterInfo;
  46. class TargetSchedModel;
  47. class Triple;
  48. //===----------------------------------------------------------------------===//
  49. ///
  50. /// TargetSubtargetInfo - Generic base class for all target subtargets. All
  51. /// Target-specific options that control code generation and printing should
  52. /// be exposed through a TargetSubtargetInfo-derived class.
  53. ///
  54. class TargetSubtargetInfo : public MCSubtargetInfo {
  55. protected: // Can only create subclasses...
  56. TargetSubtargetInfo(const Triple &TT, StringRef CPU, StringRef TuneCPU,
  57. StringRef FS, ArrayRef<SubtargetFeatureKV> PF,
  58. ArrayRef<SubtargetSubTypeKV> PD,
  59. const MCWriteProcResEntry *WPR,
  60. const MCWriteLatencyEntry *WL,
  61. const MCReadAdvanceEntry *RA, const InstrStage *IS,
  62. const unsigned *OC, const unsigned *FP);
  63. public:
  64. // AntiDepBreakMode - Type of anti-dependence breaking that should
  65. // be performed before post-RA scheduling.
  66. using AntiDepBreakMode = enum { ANTIDEP_NONE, ANTIDEP_CRITICAL, ANTIDEP_ALL };
  67. using RegClassVector = SmallVectorImpl<const TargetRegisterClass *>;
  68. TargetSubtargetInfo() = delete;
  69. TargetSubtargetInfo(const TargetSubtargetInfo &) = delete;
  70. TargetSubtargetInfo &operator=(const TargetSubtargetInfo &) = delete;
  71. ~TargetSubtargetInfo() override;
  72. virtual bool isXRaySupported() const { return false; }
  73. // Interfaces to the major aspects of target machine information:
  74. //
  75. // -- Instruction opcode and operand information
  76. // -- Pipelines and scheduling information
  77. // -- Stack frame information
  78. // -- Selection DAG lowering information
  79. // -- Call lowering information
  80. //
  81. // N.B. These objects may change during compilation. It's not safe to cache
  82. // them between functions.
  83. virtual const TargetInstrInfo *getInstrInfo() const { return nullptr; }
  84. virtual const TargetFrameLowering *getFrameLowering() const {
  85. return nullptr;
  86. }
  87. virtual const TargetLowering *getTargetLowering() const { return nullptr; }
  88. virtual const SelectionDAGTargetInfo *getSelectionDAGInfo() const {
  89. return nullptr;
  90. }
  91. virtual const CallLowering *getCallLowering() const { return nullptr; }
  92. virtual const InlineAsmLowering *getInlineAsmLowering() const {
  93. return nullptr;
  94. }
  95. // FIXME: This lets targets specialize the selector by subtarget (which lets
  96. // us do things like a dedicated avx512 selector). However, we might want
  97. // to also specialize selectors by MachineFunction, which would let us be
  98. // aware of optsize/optnone and such.
  99. virtual InstructionSelector *getInstructionSelector() const {
  100. return nullptr;
  101. }
  102. /// Target can subclass this hook to select a different DAG scheduler.
  103. virtual RegisterScheduler::FunctionPassCtor
  104. getDAGScheduler(CodeGenOpt::Level) const {
  105. return nullptr;
  106. }
  107. virtual const LegalizerInfo *getLegalizerInfo() const { return nullptr; }
  108. /// getRegisterInfo - If register information is available, return it. If
  109. /// not, return null.
  110. virtual const TargetRegisterInfo *getRegisterInfo() const { return nullptr; }
  111. /// If the information for the register banks is available, return it.
  112. /// Otherwise return nullptr.
  113. virtual const RegisterBankInfo *getRegBankInfo() const { return nullptr; }
  114. /// getInstrItineraryData - Returns instruction itinerary data for the target
  115. /// or specific subtarget.
  116. virtual const InstrItineraryData *getInstrItineraryData() const {
  117. return nullptr;
  118. }
  119. /// Resolve a SchedClass at runtime, where SchedClass identifies an
  120. /// MCSchedClassDesc with the isVariant property. This may return the ID of
  121. /// another variant SchedClass, but repeated invocation must quickly terminate
  122. /// in a nonvariant SchedClass.
  123. virtual unsigned resolveSchedClass(unsigned SchedClass,
  124. const MachineInstr *MI,
  125. const TargetSchedModel *SchedModel) const {
  126. return 0;
  127. }
  128. /// Returns true if MI is a dependency breaking zero-idiom instruction for the
  129. /// subtarget.
  130. ///
  131. /// This function also sets bits in Mask related to input operands that
  132. /// are not in a data dependency relationship. There is one bit for each
  133. /// machine operand; implicit operands follow explicit operands in the bit
  134. /// representation used for Mask. An empty (i.e. a mask with all bits
  135. /// cleared) means: data dependencies are "broken" for all the explicit input
  136. /// machine operands of MI.
  137. virtual bool isZeroIdiom(const MachineInstr *MI, APInt &Mask) const {
  138. return false;
  139. }
  140. /// Returns true if MI is a dependency breaking instruction for the subtarget.
  141. ///
  142. /// Similar in behavior to `isZeroIdiom`. However, it knows how to identify
  143. /// all dependency breaking instructions (i.e. not just zero-idioms).
  144. ///
  145. /// As for `isZeroIdiom`, this method returns a mask of "broken" dependencies.
  146. /// (See method `isZeroIdiom` for a detailed description of Mask).
  147. virtual bool isDependencyBreaking(const MachineInstr *MI, APInt &Mask) const {
  148. return isZeroIdiom(MI, Mask);
  149. }
  150. /// Returns true if MI is a candidate for move elimination.
  151. ///
  152. /// A candidate for move elimination may be optimized out at register renaming
  153. /// stage. Subtargets can specify the set of optimizable moves by
  154. /// instantiating tablegen class `IsOptimizableRegisterMove` (see
  155. /// llvm/Target/TargetInstrPredicate.td).
  156. ///
  157. /// SubtargetEmitter is responsible for processing all the definitions of class
  158. /// IsOptimizableRegisterMove, and auto-generate an override for this method.
  159. virtual bool isOptimizableRegisterMove(const MachineInstr *MI) const {
  160. return false;
  161. }
  162. /// True if the subtarget should run MachineScheduler after aggressive
  163. /// coalescing.
  164. ///
  165. /// This currently replaces the SelectionDAG scheduler with the "source" order
  166. /// scheduler (though see below for an option to turn this off and use the
  167. /// TargetLowering preference). It does not yet disable the postRA scheduler.
  168. virtual bool enableMachineScheduler() const;
  169. /// True if the machine scheduler should disable the TLI preference
  170. /// for preRA scheduling with the source level scheduler.
  171. virtual bool enableMachineSchedDefaultSched() const { return true; }
  172. /// True if the subtarget should run MachinePipeliner
  173. virtual bool enableMachinePipeliner() const { return true; };
  174. /// True if the subtarget should enable joining global copies.
  175. ///
  176. /// By default this is enabled if the machine scheduler is enabled, but
  177. /// can be overridden.
  178. virtual bool enableJoinGlobalCopies() const;
  179. /// True if the subtarget should run a scheduler after register allocation.
  180. ///
  181. /// By default this queries the PostRAScheduling bit in the scheduling model
  182. /// which is the preferred way to influence this.
  183. virtual bool enablePostRAScheduler() const;
  184. /// True if the subtarget should run a machine scheduler after register
  185. /// allocation.
  186. virtual bool enablePostRAMachineScheduler() const;
  187. /// True if the subtarget should run the atomic expansion pass.
  188. virtual bool enableAtomicExpand() const;
  189. /// True if the subtarget should run the indirectbr expansion pass.
  190. virtual bool enableIndirectBrExpand() const;
  191. /// Override generic scheduling policy within a region.
  192. ///
  193. /// This is a convenient way for targets that don't provide any custom
  194. /// scheduling heuristics (no custom MachineSchedStrategy) to make
  195. /// changes to the generic scheduling policy.
  196. virtual void overrideSchedPolicy(MachineSchedPolicy &Policy,
  197. unsigned NumRegionInstrs) const {}
  198. // Perform target-specific adjustments to the latency of a schedule
  199. // dependency.
  200. // If a pair of operands is associated with the schedule dependency, DefOpIdx
  201. // and UseOpIdx are the indices of the operands in Def and Use, respectively.
  202. // Otherwise, either may be -1.
  203. virtual void adjustSchedDependency(SUnit *Def, int DefOpIdx, SUnit *Use,
  204. int UseOpIdx, SDep &Dep) const {}
  205. // For use with PostRAScheduling: get the anti-dependence breaking that should
  206. // be performed before post-RA scheduling.
  207. virtual AntiDepBreakMode getAntiDepBreakMode() const { return ANTIDEP_NONE; }
  208. // For use with PostRAScheduling: in CriticalPathRCs, return any register
  209. // classes that should only be considered for anti-dependence breaking if they
  210. // are on the critical path.
  211. virtual void getCriticalPathRCs(RegClassVector &CriticalPathRCs) const {
  212. return CriticalPathRCs.clear();
  213. }
  214. // Provide an ordered list of schedule DAG mutations for the post-RA
  215. // scheduler.
  216. virtual void getPostRAMutations(
  217. std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations) const {
  218. }
  219. // Provide an ordered list of schedule DAG mutations for the machine
  220. // pipeliner.
  221. virtual void getSMSMutations(
  222. std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations) const {
  223. }
  224. /// Default to DFA for resource management, return false when target will use
  225. /// ProcResource in InstrSchedModel instead.
  226. virtual bool useDFAforSMS() const { return true; }
  227. // For use with PostRAScheduling: get the minimum optimization level needed
  228. // to enable post-RA scheduling.
  229. virtual CodeGenOpt::Level getOptLevelToEnablePostRAScheduler() const {
  230. return CodeGenOpt::Default;
  231. }
  232. /// True if the subtarget should run the local reassignment
  233. /// heuristic of the register allocator.
  234. /// This heuristic may be compile time intensive, \p OptLevel provides
  235. /// a finer grain to tune the register allocator.
  236. virtual bool enableRALocalReassignment(CodeGenOpt::Level OptLevel) const;
  237. /// True if the subtarget should consider the cost of local intervals
  238. /// created by a split candidate when choosing the best split candidate. This
  239. /// heuristic may be compile time intensive.
  240. virtual bool enableAdvancedRASplitCost() const;
  241. /// Enable use of alias analysis during code generation (during MI
  242. /// scheduling, DAGCombine, etc.).
  243. virtual bool useAA() const;
  244. /// \brief Sink addresses into blocks using GEP instructions rather than
  245. /// pointer casts and arithmetic.
  246. virtual bool addrSinkUsingGEPs() const {
  247. return useAA();
  248. }
  249. /// Enable the use of the early if conversion pass.
  250. virtual bool enableEarlyIfConversion() const { return false; }
  251. /// Return PBQPConstraint(s) for the target.
  252. ///
  253. /// Override to provide custom PBQP constraints.
  254. virtual std::unique_ptr<PBQPRAConstraint> getCustomPBQPConstraints() const {
  255. return nullptr;
  256. }
  257. /// Enable tracking of subregister liveness in register allocator.
  258. /// Please use MachineRegisterInfo::subRegLivenessEnabled() instead where
  259. /// possible.
  260. virtual bool enableSubRegLiveness() const { return false; }
  261. /// This is called after a .mir file was loaded.
  262. virtual void mirFileLoaded(MachineFunction &MF) const;
  263. /// True if the register allocator should use the allocation orders exactly as
  264. /// written in the tablegen descriptions, false if it should allocate
  265. /// the specified physical register later if is it callee-saved.
  266. virtual bool ignoreCSRForAllocationOrder(const MachineFunction &MF,
  267. unsigned PhysReg) const {
  268. return false;
  269. }
  270. };
  271. } // end namespace llvm
  272. #endif // LLVM_CODEGEN_TARGETSUBTARGETINFO_H