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" 30 31 namespace llvm { 32 33 class MCInstrDesc; 34 class MachineInstr; 35 class InstrItineraryData; 36 37 class DFAPacketizer { 38 private: 39 typedef std::pair<unsigned, unsigned> UnsignPair; 40 const InstrItineraryData *InstrItins; 41 int CurrentState; 42 const int (*DFAStateInputTable)[2]; 43 const unsigned *DFAStateEntryTable; 44 45 // CachedTable is a map from <FromState, Input> to ToState. 46 DenseMap<UnsignPair, unsigned> CachedTable; 47 48 // ReadTable - Read the DFA transition table and update CachedTable. 49 void ReadTable(unsigned int state); 50 51 public: 52 DFAPacketizer(const InstrItineraryData *I, const int (*SIT)[2], 53 const unsigned *SET); 54 55 // Reset the current state to make all resources available. 56 void clearResources() { 57 CurrentState = 0; 58 } 59 60 // canReserveResources - Check if the resources occupied by a MCInstrDesc 61 // are available in the current state. 62 bool canReserveResources(const llvm::MCInstrDesc *MID); 63 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); 67 68 // canReserveResources - Check if the resources occupied by a machine 69 // instruction are available in the current state. 70 bool canReserveResources(llvm::MachineInstr *MI); 71 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); 75 }; 76 } 77 78 #endif 79