1 //=- llvm/CodeGen/DFAPacketizer.h - DFA Packetizer for VLIW ---*- C++ -*-=====//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
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.
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.
24 //===----------------------------------------------------------------------===//
26 #ifndef LLVM_CODEGEN_DFAPACKETIZER_H
27 #define LLVM_CODEGEN_DFAPACKETIZER_H
29 #include "llvm/ADT/DenseMap.h"
35 class InstrItineraryData;
39 typedef std::pair<unsigned, unsigned> UnsignPair;
40 const InstrItineraryData *InstrItins;
42 const int (*DFAStateInputTable)[2];
43 const unsigned *DFAStateEntryTable;
45 // CachedTable is a map from <FromState, Input> to ToState.
46 DenseMap<UnsignPair, unsigned> CachedTable;
48 // ReadTable - Read the DFA transition table and update CachedTable.
49 void ReadTable(unsigned int state);
52 DFAPacketizer(const InstrItineraryData *I, const int (*SIT)[2],
55 // Reset the current state to make all resources available.
56 void clearResources() {
60 // canReserveResources - Check if the resources occupied by a MCInstrDesc
61 // are available in the current state.
62 bool canReserveResources(const llvm::MCInstrDesc *MID);
64 // reserveResources - Reserve the resources occupied by a MCInstrDesc and
65 // change the current state to reflect that change.
66 void reserveResources(const llvm::MCInstrDesc *MID);
68 // canReserveResources - Check if the resources occupied by a machine
69 // instruction are available in the current state.
70 bool canReserveResources(llvm::MachineInstr *MI);
72 // reserveResources - Reserve the resources occupied by a machine
73 // instruction and change the current state to reflect that change.
74 void reserveResources(llvm::MachineInstr *MI);