LLVM  3.7.0
DFAPacketizer.h
Go to the documentation of this file.
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 
26 #ifndef LLVM_CODEGEN_DFAPACKETIZER_H
27 #define LLVM_CODEGEN_DFAPACKETIZER_H
28 
29 #include "llvm/ADT/DenseMap.h"
31 #include <map>
32 
33 namespace llvm {
34 
35 class MCInstrDesc;
36 class MachineInstr;
37 class MachineLoopInfo;
38 class MachineDominatorTree;
39 class InstrItineraryData;
40 class DefaultVLIWScheduler;
41 class SUnit;
42 
44 private:
45  typedef std::pair<unsigned, unsigned> UnsignPair;
46  const InstrItineraryData *InstrItins;
47  int CurrentState;
48  const int (*DFAStateInputTable)[2];
49  const unsigned *DFAStateEntryTable;
50 
51  // CachedTable is a map from <FromState, Input> to ToState.
53 
54  // ReadTable - Read the DFA transition table and update CachedTable.
55  void ReadTable(unsigned int state);
56 
57 public:
58  DFAPacketizer(const InstrItineraryData *I, const int (*SIT)[2],
59  const unsigned *SET);
60 
61  // Reset the current state to make all resources available.
62  void clearResources() {
63  CurrentState = 0;
64  }
65 
66  // canReserveResources - Check if the resources occupied by a MCInstrDesc
67  // are available in the current state.
68  bool canReserveResources(const llvm::MCInstrDesc *MID);
69 
70  // reserveResources - Reserve the resources occupied by a MCInstrDesc and
71  // change the current state to reflect that change.
72  void reserveResources(const llvm::MCInstrDesc *MID);
73 
74  // canReserveResources - Check if the resources occupied by a machine
75  // instruction are available in the current state.
77 
78  // reserveResources - Reserve the resources occupied by a machine
79  // instruction and change the current state to reflect that change.
81 
82  const InstrItineraryData *getInstrItins() const { return InstrItins; }
83 };
84 
85 // VLIWPacketizerList - Implements a simple VLIW packetizer using DFA. The
86 // packetizer works on machine basic blocks. For each instruction I in BB, the
87 // packetizer consults the DFA to see if machine resources are available to
88 // execute I. If so, the packetizer checks if I depends on any instruction J in
89 // the current packet. If no dependency is found, I is added to current packet
90 // and machine resource is marked as taken. If any dependency is found, a target
91 // API call is made to prune the dependence.
93 protected:
96 
97  // The VLIW Scheduler.
99 
100  // Vector of instructions assigned to the current packet.
101  std::vector<MachineInstr*> CurrentPacketMIs;
102  // DFA resource tracker.
104 
105  // Generate MI -> SU map.
106  std::map<MachineInstr*, SUnit*> MIToSUnit;
107 
108 public:
109  VLIWPacketizerList(MachineFunction &MF, MachineLoopInfo &MLI, bool IsPostRA);
110 
111  virtual ~VLIWPacketizerList();
112 
113  // PacketizeMIs - Implement this API in the backend to bundle instructions.
117 
118  // getResourceTracker - return ResourceTracker
120 
121  // addToPacket - Add MI to the current packet.
124  CurrentPacketMIs.push_back(MI);
126  return MII;
127  }
128 
129  // endPacket - End the current packet.
131 
132  // initPacketizerState - perform initialization before packetizing
133  // an instruction. This function is supposed to be overrided by
134  // the target dependent packetizer.
135  virtual void initPacketizerState() { return; }
136 
137  // ignorePseudoInstruction - Ignore bundling of pseudo instructions.
139  MachineBasicBlock *MBB) {
140  return false;
141  }
142 
143  // isSoloInstruction - return true if instruction MI can not be packetized
144  // with any other instruction, which means that MI itself is a packet.
146  return true;
147  }
148 
149  // isLegalToPacketizeTogether - Is it legal to packetize SUI and SUJ
150  // together.
151  virtual bool isLegalToPacketizeTogether(SUnit *SUI, SUnit *SUJ) {
152  return false;
153  }
154 
155  // isLegalToPruneDependencies - Is it legal to prune dependece between SUI
156  // and SUJ.
157  virtual bool isLegalToPruneDependencies(SUnit *SUI, SUnit *SUJ) {
158  return false;
159  }
160 
161 };
162 }
163 
164 #endif
bool canReserveResources(const llvm::MCInstrDesc *MID)
std::vector< MachineInstr * > CurrentPacketMIs
virtual void initPacketizerState()
Describe properties that are true of each instruction in the target description file.
Definition: MCInstrDesc.h:138
virtual bool isLegalToPruneDependencies(SUnit *SUI, SUnit *SUJ)
virtual bool ignorePseudoInstruction(MachineInstr *I, MachineBasicBlock *MBB)
std::map< MachineInstr *, SUnit * > MIToSUnit
const InstrItineraryData * getInstrItins() const
Definition: DFAPacketizer.h:82
MachineFunction & MF
Definition: DFAPacketizer.h:94
DFAPacketizer * ResourceTracker
Itinerary data supplied by a subtarget to be used by a target.
void reserveResources(const llvm::MCInstrDesc *MID)
TargetInstrInfo - Interface to description of machine instruction set.
bundle_iterator< MachineInstr, instr_iterator > iterator
#define SET(n)
Definition: MD5.cpp:64
const TargetInstrInfo * TII
Definition: DFAPacketizer.h:95
virtual bool isLegalToPacketizeTogether(SUnit *SUI, SUnit *SUJ)
VLIWPacketizerList(MachineFunction &MF, MachineLoopInfo &MLI, bool IsPostRA)
DFAPacketizer(const InstrItineraryData *I, const int(*SIT)[2], const unsigned *SET)
Representation of each machine instruction.
Definition: MachineInstr.h:51
#define I(x, y, z)
Definition: MD5.cpp:54
void endPacket(MachineBasicBlock *MBB, MachineInstr *MI)
virtual bool isSoloInstruction(MachineInstr *MI)
DFAPacketizer * getResourceTracker()
void PacketizeMIs(MachineBasicBlock *MBB, MachineBasicBlock::iterator BeginItr, MachineBasicBlock::iterator EndItr)
DefaultVLIWScheduler * VLIWScheduler
Definition: DFAPacketizer.h:98
SUnit - Scheduling unit. This is a node in the scheduling DAG.
Definition: ScheduleDAG.h:261
virtual MachineBasicBlock::iterator addToPacket(MachineInstr *MI)