|
29 | 29 | #include <map>
|
30 | 30 | #include <set>
|
31 | 31 | #include <string>
|
| 32 | +#include <unordered_map> |
32 | 33 | #include <vector>
|
33 | 34 |
|
34 | 35 | using namespace llvm;
|
@@ -154,6 +155,11 @@ class DFAPacketizerEmitter {
|
154 | 155 | int &maxStages,
|
155 | 156 | raw_ostream &OS);
|
156 | 157 |
|
| 158 | + // Emit code for a subset of itineraries. |
| 159 | + void emitForItineraries(raw_ostream &OS, |
| 160 | + std::vector<Record *> &ProcItinList, |
| 161 | + std::string DFAName); |
| 162 | + |
157 | 163 | void run(raw_ostream &OS);
|
158 | 164 | };
|
159 | 165 |
|
@@ -545,14 +551,6 @@ void DFA::writeTableAndAPI(raw_ostream &OS, const std::string &TargetName,
|
545 | 551 | LLVM_DEBUG(dbgs() << "writeTableAndAPI\n");
|
546 | 552 | LLVM_DEBUG(dbgs() << "Total states: " << numStates << "\n");
|
547 | 553 |
|
548 |
| - OS << "namespace llvm {\n"; |
549 |
| - |
550 |
| - OS << "\n// Input format:\n"; |
551 |
| - OS << "#define DFA_MAX_RESTERMS " << DFA_MAX_RESTERMS |
552 |
| - << "\t// maximum AND'ed resource terms\n"; |
553 |
| - OS << "#define DFA_MAX_RESOURCES " << DFA_MAX_RESOURCES |
554 |
| - << "\t// maximum resource bits in one term\n"; |
555 |
| - |
556 | 554 | OS << "\n// " << TargetName << "DFAStateInputTable[][2] = "
|
557 | 555 | << "pairs of <Input, NextState> for all valid\n";
|
558 | 556 | OS << "// transitions.\n";
|
@@ -626,21 +624,7 @@ void DFA::writeTableAndAPI(raw_ostream &OS, const std::string &TargetName,
|
626 | 624 | // Print out the index to the sentinel entry in StateInputTable
|
627 | 625 | OS << ValidTransitions << ", ";
|
628 | 626 | OS << " // states " << (lastState+1) << ":" << numStates << "\n";
|
629 |
| - |
630 | 627 | OS << "};\n";
|
631 |
| - OS << "} // end namespace llvm\n"; |
632 |
| - |
633 |
| - // |
634 |
| - // Emit DFA Packetizer tables if the target is a VLIW machine. |
635 |
| - // |
636 |
| - std::string SubTargetClassName = TargetName + "GenSubtargetInfo"; |
637 |
| - OS << "\n" << "#include \"llvm/CodeGen/DFAPacketizer.h\"\n"; |
638 |
| - OS << "namespace llvm {\n"; |
639 |
| - OS << "DFAPacketizer *" << SubTargetClassName << "::" |
640 |
| - << "createDFAPacketizer(const InstrItineraryData *IID) const {\n" |
641 |
| - << " return new DFAPacketizer(IID, " << TargetName |
642 |
| - << "DFAStateInputTable, " << TargetName << "DFAStateEntryTable);\n}\n\n"; |
643 |
| - OS << "} // end namespace llvm\n"; |
644 | 628 | }
|
645 | 629 |
|
646 | 630 | //
|
@@ -837,10 +821,32 @@ int DFAPacketizerEmitter::collectAllInsnClasses(const std::string &ProcName,
|
837 | 821 | // Run the worklist algorithm to generate the DFA.
|
838 | 822 | //
|
839 | 823 | void DFAPacketizerEmitter::run(raw_ostream &OS) {
|
| 824 | + OS << "\n" |
| 825 | + << "#include \"llvm/CodeGen/DFAPacketizer.h\"\n"; |
| 826 | + OS << "namespace llvm {\n"; |
| 827 | + |
| 828 | + OS << "\n// Input format:\n"; |
| 829 | + OS << "#define DFA_MAX_RESTERMS " << DFA_MAX_RESTERMS |
| 830 | + << "\t// maximum AND'ed resource terms\n"; |
| 831 | + OS << "#define DFA_MAX_RESOURCES " << DFA_MAX_RESOURCES |
| 832 | + << "\t// maximum resource bits in one term\n"; |
| 833 | + |
840 | 834 | // Collect processor iteraries.
|
841 | 835 | std::vector<Record*> ProcItinList =
|
842 | 836 | Records.getAllDerivedDefinitions("ProcessorItineraries");
|
843 | 837 |
|
| 838 | + std::unordered_map<std::string, std::vector<Record*>> ItinsByNamespace; |
| 839 | + for (Record *R : ProcItinList) |
| 840 | + ItinsByNamespace[R->getValueAsString("PacketizerNamespace")].push_back(R); |
| 841 | + |
| 842 | + for (auto &KV : ItinsByNamespace) |
| 843 | + emitForItineraries(OS, KV.second, KV.first); |
| 844 | + OS << "} // end namespace llvm\n"; |
| 845 | +} |
| 846 | + |
| 847 | +void DFAPacketizerEmitter::emitForItineraries( |
| 848 | + raw_ostream &OS, std::vector<Record *> &ProcItinList, |
| 849 | + std::string DFAName) { |
844 | 850 | //
|
845 | 851 | // Collect the Functional units.
|
846 | 852 | //
|
@@ -982,8 +988,19 @@ void DFAPacketizerEmitter::run(raw_ostream &OS) {
|
982 | 988 | }
|
983 | 989 |
|
984 | 990 | // Print out the table.
|
985 |
| - D.writeTableAndAPI(OS, TargetName, |
986 |
| - numInsnClasses, maxResources, numCombos, maxStages); |
| 991 | + D.writeTableAndAPI(OS, TargetName + DFAName, numInsnClasses, maxResources, |
| 992 | + numCombos, maxStages); |
| 993 | + |
| 994 | + OS << "} // end namespace llvm\n"; |
| 995 | + |
| 996 | + std::string SubTargetClassName = TargetName + "GenSubtargetInfo"; |
| 997 | + OS << "namespace llvm {\n"; |
| 998 | + OS << "DFAPacketizer *" << SubTargetClassName << "::" |
| 999 | + << "create" << DFAName |
| 1000 | + << "DFAPacketizer(const InstrItineraryData *IID) const {\n" |
| 1001 | + << " return new DFAPacketizer(IID, " << TargetName << DFAName |
| 1002 | + << "DFAStateInputTable, " << TargetName << DFAName |
| 1003 | + << "DFAStateEntryTable);\n}\n\n"; |
987 | 1004 | }
|
988 | 1005 |
|
989 | 1006 | namespace llvm {
|
|
0 commit comments