Skip to content

Commit 9d25fe7

Browse files
author
Yuanke Luo
committed
[TableGen] Address Matt and Haohai's comments
1 parent 311a4b8 commit 9d25fe7

File tree

2 files changed

+56
-14
lines changed

2 files changed

+56
-14
lines changed

llvm/test/TableGen/DFAPacketizer.td

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,29 @@ def Itin {
2323
];
2424
}
2525

26-
// CHECK: std::map<unsigned, unsigned> TestTargetProcIdToResourceIndexStartMapping = {
27-
// CHECK-NEXT: { 2, 1 }, // TestItinerariesModel
28-
// CHECK-NEXT: };
26+
// CHECK: int TestTargetGetResourceIndex(unsigned ProcID) {
27+
// CHECK-NEXT: static const unsigned TestTargetProcIdToProcResourceIdxTable[][2] = {
28+
// CHECK-NEXT: { 2, 1 }, // TestItinerariesModel
29+
// CHECK-NEXT: };
30+
// CHECK-NEXT: unsigned Mid;
31+
// CHECK-NEXT: unsigned Start = 0;
32+
// CHECK-NEXT: unsigned End = 1;
33+
// CHECK-NEXT: while (Start < End) {
34+
// CHECK-NEXT: Mid = Start + (End - Start) / 2;
35+
// CHECK-NEXT: if (ProcID == TestTargetProcIdToProcResourceIdxTable[Mid][0]) {
36+
// CHECK-NEXT: break;
37+
// CHECK-NEXT: }
38+
// CHECK-NEXT: if (ProcID < TestTargetProcIdToProcResourceIdxTable[Mid][0])
39+
// CHECK-NEXT: End = Mid;
40+
// CHECK-NEXT: else
41+
// CHECK-NEXT: Start = Mid + 1;
42+
// CHECK-NEXT: }
43+
// CHECK-NEXT: if (Start == End)
44+
// CHECK-NEXT: return -1; // Didn't find
45+
// CHECK-NEXT: return TestTargetProcIdToProcResourceIdxTable[Mid][1];
46+
// CHECK-NEXT: }
47+
48+
// CHECK: unsigned Index = TestTargetGetResourceIndex(IID->SchedModel.ProcID);
2949

3050
def TestItineraries: ProcessorItineraries<[], [], Itin.ItinList>;
3151
def TestProcessor2 : Processor<"testprocessor2", TestItineraries, []>;

llvm/utils/TableGen/DFAPacketizerEmitter.cpp

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -256,16 +256,6 @@ void DFAPacketizerEmitter::emitForItineraries(
256256
}
257257
OS << "\n};\n\n";
258258

259-
// Output the mapping from proc ID to ResourceIndexStart
260-
Idx = 1;
261-
OS << "std::map<unsigned, unsigned> " << TargetName << DFAName
262-
<< "ProcIdToResourceIndexStartMapping = {\n";
263-
for (const CodeGenProcModel *Model : ProcModels) {
264-
OS << " { " << Model->Index << ", " << Idx++ << " }, // "
265-
<< Model->ModelName << "\n";
266-
}
267-
OS << "};\n\n";
268-
269259
// And the mapping from Itinerary index into the previous table.
270260
OS << "constexpr unsigned " << TargetName << DFAName
271261
<< "ProcResourceIndexStart[] = {\n";
@@ -276,6 +266,38 @@ void DFAPacketizerEmitter::emitForItineraries(
276266
}
277267
OS << " " << ScheduleClasses.size() << "\n};\n\n";
278268

269+
// Output the mapping from proc ID to ResourceIndexStart
270+
Idx = 1;
271+
OS << "int " << TargetName << DFAName
272+
<< "GetResourceIndex(unsigned ProcID) { \n"
273+
<< " static const unsigned " << TargetName << DFAName
274+
<< "ProcIdToProcResourceIdxTable[][2] = {\n";
275+
for (const CodeGenProcModel *Model : ProcModels) {
276+
OS << " { " << Model->Index << ", " << Idx++ << " }, // "
277+
<< Model->ModelName << "\n";
278+
}
279+
OS << " };\n"
280+
<< " unsigned Mid;\n"
281+
<< " unsigned Start = 0;\n"
282+
<< " unsigned End = " << ProcModels.size() << ";\n"
283+
<< " while (Start < End) {\n"
284+
<< " Mid = Start + (End - Start) / 2;\n"
285+
<< " if (ProcID == " << TargetName << DFAName
286+
<< "ProcIdToProcResourceIdxTable[Mid][0]) {\n"
287+
<< " break;\n"
288+
<< " }\n"
289+
<< " if (ProcID < " << TargetName << DFAName
290+
<< "ProcIdToProcResourceIdxTable[Mid][0])\n"
291+
<< " End = Mid;\n"
292+
<< " else\n"
293+
<< " Start = Mid + 1;\n"
294+
<< " }\n"
295+
<< " if (Start == End)\n"
296+
<< " return -1; // Didn't find\n"
297+
<< " return " << TargetName << DFAName
298+
<< "ProcIdToProcResourceIdxTable[Mid][1];\n"
299+
<< "}\n\n";
300+
279301
// The type of a state in the nondeterministic automaton we're defining.
280302
using NfaStateTy = uint64_t;
281303

@@ -355,7 +377,7 @@ void DFAPacketizerEmitter::emitForItineraries(
355377
<< "Transition>(" << TargetAndDFAName << "Transitions), "
356378
<< TargetAndDFAName << "TransitionInfo);\n"
357379
<< " unsigned Index = " << TargetName << DFAName
358-
<< "ProcIdToResourceIndexStartMapping[IID->SchedModel.ProcID];\n"
380+
<< "GetResourceIndex(IID->SchedModel.ProcID);\n"
359381
<< " unsigned ProcResIdxStart = " << TargetAndDFAName
360382
<< "ProcResourceIndexStart[Index];\n"
361383
<< " unsigned ProcResIdxNum = " << TargetAndDFAName

0 commit comments

Comments
 (0)