TargetSubtargetInfo.h 13 KB

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