TargetSubtargetInfo.h 13 KB

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