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.

167 lines
5.9 KiB

  1. //=- llvm/CodeGen/DFAPacketizer.h - DFA Packetizer for VLIW ---*- 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. // This class implements a deterministic finite automaton (DFA) based
  10. // packetizing mechanism for VLIW architectures. It provides APIs to
  11. // determine whether there exists a legal mapping of instructions to
  12. // functional unit assignments in a packet. The DFA is auto-generated from
  13. // the target's Schedule.td file.
  14. //
  15. // A DFA consists of 3 major elements: states, inputs, and transitions. For
  16. // the packetizing mechanism, the input is the set of instruction classes for
  17. // a target. The state models all possible combinations of functional unit
  18. // consumption for a given set of instructions in a packet. A transition
  19. // models the addition of an instruction to a packet. In the DFA constructed
  20. // by this class, if an instruction can be added to a packet, then a valid
  21. // transition exists from the corresponding state. Invalid transitions
  22. // indicate that the instruction cannot be added to the current packet.
  23. //
  24. //===----------------------------------------------------------------------===//
  25. #ifndef LLVM_CODEGEN_DFAPACKETIZER_H
  26. #define LLVM_CODEGEN_DFAPACKETIZER_H
  27. #include "llvm/ADT/DenseMap.h"
  28. #include "llvm/CodeGen/MachineBasicBlock.h"
  29. #include <map>
  30. namespace llvm {
  31. class MCInstrDesc;
  32. class MachineInstr;
  33. class MachineLoopInfo;
  34. class MachineDominatorTree;
  35. class InstrItineraryData;
  36. class DefaultVLIWScheduler;
  37. class SUnit;
  38. class DFAPacketizer {
  39. private:
  40. typedef std::pair<unsigned, unsigned> UnsignPair;
  41. const InstrItineraryData *InstrItins;
  42. int CurrentState;
  43. const int (*DFAStateInputTable)[2];
  44. const unsigned *DFAStateEntryTable;
  45. // CachedTable is a map from <FromState, Input> to ToState.
  46. DenseMap<UnsignPair, unsigned> CachedTable;
  47. // ReadTable - Read the DFA transition table and update CachedTable.
  48. void ReadTable(unsigned int state);
  49. public:
  50. DFAPacketizer(const InstrItineraryData *I, const int (*SIT)[2],
  51. const unsigned *SET);
  52. // Reset the current state to make all resources available.
  53. void clearResources() {
  54. CurrentState = 0;
  55. }
  56. // canReserveResources - Check if the resources occupied by a MCInstrDesc
  57. // are available in the current state.
  58. bool canReserveResources(const llvm::MCInstrDesc *MID);
  59. // reserveResources - Reserve the resources occupied by a MCInstrDesc and
  60. // change the current state to reflect that change.
  61. void reserveResources(const llvm::MCInstrDesc *MID);
  62. // canReserveResources - Check if the resources occupied by a machine
  63. // instruction are available in the current state.
  64. bool canReserveResources(llvm::MachineInstr *MI);
  65. // reserveResources - Reserve the resources occupied by a machine
  66. // instruction and change the current state to reflect that change.
  67. void reserveResources(llvm::MachineInstr *MI);
  68. const InstrItineraryData *getInstrItins() const { return InstrItins; }
  69. };
  70. // VLIWPacketizerList - Implements a simple VLIW packetizer using DFA. The
  71. // packetizer works on machine basic blocks. For each instruction I in BB, the
  72. // packetizer consults the DFA to see if machine resources are available to
  73. // execute I. If so, the packetizer checks if I depends on any instruction J in
  74. // the current packet. If no dependency is found, I is added to current packet
  75. // and machine resource is marked as taken. If any dependency is found, a target
  76. // API call is made to prune the dependence.
  77. class VLIWPacketizerList {
  78. protected:
  79. const TargetMachine &TM;
  80. const MachineFunction &MF;
  81. const TargetInstrInfo *TII;
  82. // The VLIW Scheduler.
  83. DefaultVLIWScheduler *VLIWScheduler;
  84. // Vector of instructions assigned to the current packet.
  85. std::vector<MachineInstr*> CurrentPacketMIs;
  86. // DFA resource tracker.
  87. DFAPacketizer *ResourceTracker;
  88. // Generate MI -> SU map.
  89. std::map<MachineInstr*, SUnit*> MIToSUnit;
  90. public:
  91. VLIWPacketizerList(
  92. MachineFunction &MF, MachineLoopInfo &MLI, MachineDominatorTree &MDT,
  93. bool IsPostRA);
  94. virtual ~VLIWPacketizerList();
  95. // PacketizeMIs - Implement this API in the backend to bundle instructions.
  96. void PacketizeMIs(MachineBasicBlock *MBB,
  97. MachineBasicBlock::iterator BeginItr,
  98. MachineBasicBlock::iterator EndItr);
  99. // getResourceTracker - return ResourceTracker
  100. DFAPacketizer *getResourceTracker() {return ResourceTracker;}
  101. // addToPacket - Add MI to the current packet.
  102. virtual MachineBasicBlock::iterator addToPacket(MachineInstr *MI) {
  103. MachineBasicBlock::iterator MII = MI;
  104. CurrentPacketMIs.push_back(MI);
  105. ResourceTracker->reserveResources(MI);
  106. return MII;
  107. }
  108. // endPacket - End the current packet.
  109. void endPacket(MachineBasicBlock *MBB, MachineInstr *MI);
  110. // initPacketizerState - perform initialization before packetizing
  111. // an instruction. This function is supposed to be overrided by
  112. // the target dependent packetizer.
  113. virtual void initPacketizerState() { return; }
  114. // ignorePseudoInstruction - Ignore bundling of pseudo instructions.
  115. virtual bool ignorePseudoInstruction(MachineInstr *I,
  116. MachineBasicBlock *MBB) {
  117. return false;
  118. }
  119. // isSoloInstruction - return true if instruction MI can not be packetized
  120. // with any other instruction, which means that MI itself is a packet.
  121. virtual bool isSoloInstruction(MachineInstr *MI) {
  122. return true;
  123. }
  124. // isLegalToPacketizeTogether - Is it legal to packetize SUI and SUJ
  125. // together.
  126. virtual bool isLegalToPacketizeTogether(SUnit *SUI, SUnit *SUJ) {
  127. return false;
  128. }
  129. // isLegalToPruneDependencies - Is it legal to prune dependece between SUI
  130. // and SUJ.
  131. virtual bool isLegalToPruneDependencies(SUnit *SUI, SUnit *SUJ) {
  132. return false;
  133. }
  134. };
  135. }
  136. #endif