Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

170 lines
6.3 KiB

  1. //===-- llvm/CodeGen/TargetSchedule.h - Sched Machine Model -----*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file defines a wrapper around MCSchedModel that allows the interface to
  11. // benefit from information currently only available in TargetInstrInfo.
  12. // Ideally, the scheduling interface would be fully defined in the MC layer.
  13. //
  14. //===----------------------------------------------------------------------===//
  15. #ifndef LLVM_CODEGEN_TARGETSCHEDULE_H
  16. #define LLVM_CODEGEN_TARGETSCHEDULE_H
  17. #include "llvm/ADT/SmallVector.h"
  18. #include "llvm/MC/MCInstrItineraries.h"
  19. #include "llvm/MC/MCSchedule.h"
  20. #include "llvm/Target/TargetSubtargetInfo.h"
  21. namespace llvm {
  22. class TargetRegisterInfo;
  23. class TargetSubtargetInfo;
  24. class TargetInstrInfo;
  25. class MachineInstr;
  26. /// Provide an instruction scheduling machine model to CodeGen passes.
  27. class TargetSchedModel {
  28. // For efficiency, hold a copy of the statically defined MCSchedModel for this
  29. // processor.
  30. MCSchedModel SchedModel;
  31. InstrItineraryData InstrItins;
  32. const TargetSubtargetInfo *STI;
  33. const TargetInstrInfo *TII;
  34. SmallVector<unsigned, 16> ResourceFactors;
  35. unsigned MicroOpFactor; // Multiply to normalize microops to resource units.
  36. unsigned ResourceLCM; // Resource units per cycle. Latency normalization factor.
  37. public:
  38. TargetSchedModel(): STI(0), TII(0) {}
  39. /// \brief Initialize the machine model for instruction scheduling.
  40. ///
  41. /// The machine model API keeps a copy of the top-level MCSchedModel table
  42. /// indices and may query TargetSubtargetInfo and TargetInstrInfo to resolve
  43. /// dynamic properties.
  44. void init(const MCSchedModel &sm, const TargetSubtargetInfo *sti,
  45. const TargetInstrInfo *tii);
  46. /// Return the MCSchedClassDesc for this instruction.
  47. const MCSchedClassDesc *resolveSchedClass(const MachineInstr *MI) const;
  48. /// \brief TargetInstrInfo getter.
  49. const TargetInstrInfo *getInstrInfo() const { return TII; }
  50. /// \brief Return true if this machine model includes an instruction-level
  51. /// scheduling model.
  52. ///
  53. /// This is more detailed than the course grain IssueWidth and default
  54. /// latency properties, but separate from the per-cycle itinerary data.
  55. bool hasInstrSchedModel() const;
  56. const MCSchedModel *getMCSchedModel() const { return &SchedModel; }
  57. /// \brief Return true if this machine model includes cycle-to-cycle itinerary
  58. /// data.
  59. ///
  60. /// This models scheduling at each stage in the processor pipeline.
  61. bool hasInstrItineraries() const;
  62. const InstrItineraryData *getInstrItineraries() const {
  63. if (hasInstrItineraries())
  64. return &InstrItins;
  65. return 0;
  66. }
  67. /// \brief Identify the processor corresponding to the current subtarget.
  68. unsigned getProcessorID() const { return SchedModel.getProcessorID(); }
  69. /// \brief Maximum number of micro-ops that may be scheduled per cycle.
  70. unsigned getIssueWidth() const { return SchedModel.IssueWidth; }
  71. /// \brief Number of cycles the OOO processor is expected to hide.
  72. unsigned getILPWindow() const { return SchedModel.ILPWindow; }
  73. /// \brief Return the number of issue slots required for this MI.
  74. unsigned getNumMicroOps(const MachineInstr *MI,
  75. const MCSchedClassDesc *SC = 0) const;
  76. /// \brief Get the number of kinds of resources for this target.
  77. unsigned getNumProcResourceKinds() const {
  78. return SchedModel.getNumProcResourceKinds();
  79. }
  80. /// \brief Get a processor resource by ID for convenience.
  81. const MCProcResourceDesc *getProcResource(unsigned PIdx) const {
  82. return SchedModel.getProcResource(PIdx);
  83. }
  84. typedef const MCWriteProcResEntry *ProcResIter;
  85. // \brief Get an iterator into the processor resources consumed by this
  86. // scheduling class.
  87. ProcResIter getWriteProcResBegin(const MCSchedClassDesc *SC) const {
  88. // The subtarget holds a single resource table for all processors.
  89. return STI->getWriteProcResBegin(SC);
  90. }
  91. ProcResIter getWriteProcResEnd(const MCSchedClassDesc *SC) const {
  92. return STI->getWriteProcResEnd(SC);
  93. }
  94. /// \brief Multiply the number of units consumed for a resource by this factor
  95. /// to normalize it relative to other resources.
  96. unsigned getResourceFactor(unsigned ResIdx) const {
  97. return ResourceFactors[ResIdx];
  98. }
  99. /// \brief Multiply number of micro-ops by this factor to normalize it
  100. /// relative to other resources.
  101. unsigned getMicroOpFactor() const {
  102. return MicroOpFactor;
  103. }
  104. /// \brief Multiply cycle count by this factor to normalize it relative to
  105. /// other resources. This is the number of resource units per cycle.
  106. unsigned getLatencyFactor() const {
  107. return ResourceLCM;
  108. }
  109. /// \brief Compute operand latency based on the available machine model.
  110. ///
  111. /// Computes and return the latency of the given data dependent def and use
  112. /// when the operand indices are already known. UseMI may be NULL for an
  113. /// unknown user.
  114. ///
  115. /// FindMin may be set to get the minimum vs. expected latency. Minimum
  116. /// latency is used for scheduling groups, while expected latency is for
  117. /// instruction cost and critical path.
  118. unsigned computeOperandLatency(const MachineInstr *DefMI, unsigned DefOperIdx,
  119. const MachineInstr *UseMI, unsigned UseOperIdx,
  120. bool FindMin) const;
  121. /// \brief Compute the instruction latency based on the available machine
  122. /// model.
  123. ///
  124. /// Compute and return the expected latency of this instruction independent of
  125. /// a particular use. computeOperandLatency is the prefered API, but this is
  126. /// occasionally useful to help estimate instruction cost.
  127. unsigned computeInstrLatency(const MachineInstr *MI) const;
  128. /// \brief Output dependency latency of a pair of defs of the same register.
  129. ///
  130. /// This is typically one cycle.
  131. unsigned computeOutputLatency(const MachineInstr *DefMI, unsigned DefIdx,
  132. const MachineInstr *DepMI) const;
  133. private:
  134. /// getDefLatency is a helper for computeOperandLatency. Return the
  135. /// instruction's latency if operand lookup is not required.
  136. /// Otherwise return -1.
  137. int getDefLatency(const MachineInstr *DefMI, bool FindMin) const;
  138. };
  139. } // namespace llvm
  140. #endif