Skip to content

Commit 311a4b8

Browse files
author
Yuanke Luo
committed
[TableGen] Add mapping from processor ID to resource index for packetizer
Tablegen would generate code to access TargetResourceIndices with processor ID. The TargetProcResourceIndexStart[] array is generated for each processor which has itineraries. The processor which doesn't has itineraries is excluded from the array. When a target has mixed processors, the processor ID may exceed the array size and cause the error. This patch is to generate a table mapping processor with itineraries to resource index, so that scheduler can get the correct resource index with processor ID.
1 parent 1afadbf commit 311a4b8

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// RUN: llvm-tblgen -gen-dfa-packetizer -I %p/../../include %s | FileCheck %s
2+
3+
include "llvm/Target/Target.td"
4+
5+
def TestTarget : Target;
6+
7+
def TestSchedModel : SchedMachineModel {
8+
let CompleteModel = 0;
9+
}
10+
11+
def TestProcessor1 : ProcessorModel<"testprocessor1", TestSchedModel, []>;
12+
13+
def FU0 : FuncUnit;
14+
def FU1 : FuncUnit;
15+
16+
def OP0 : InstrItinClass;
17+
def OP1 : InstrItinClass;
18+
19+
def Itin {
20+
list<InstrItinData> ItinList = [
21+
InstrItinData<OP0, [InstrStage<1, [FU0]>]>,
22+
InstrItinData<OP1, [InstrStage<1, [FU1]>]>,
23+
];
24+
}
25+
26+
// CHECK: std::map<unsigned, unsigned> TestTargetProcIdToResourceIndexStartMapping = {
27+
// CHECK-NEXT: { 2, 1 }, // TestItinerariesModel
28+
// CHECK-NEXT: };
29+
30+
def TestItineraries: ProcessorItineraries<[], [], Itin.ItinList>;
31+
def TestProcessor2 : Processor<"testprocessor2", TestItineraries, []>;

llvm/utils/TableGen/DFAPacketizerEmitter.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,16 @@ 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+
259269
// And the mapping from Itinerary index into the previous table.
260270
OS << "constexpr unsigned " << TargetName << DFAName
261271
<< "ProcResourceIndexStart[] = {\n";
@@ -339,16 +349,17 @@ void DFAPacketizerEmitter::emitForItineraries(
339349

340350
std::string SubTargetClassName = TargetName + "GenSubtargetInfo";
341351
OS << "namespace llvm {\n";
342-
OS << "DFAPacketizer *" << SubTargetClassName << "::"
343-
<< "create" << DFAName
352+
OS << "DFAPacketizer *" << SubTargetClassName << "::" << "create" << DFAName
344353
<< "DFAPacketizer(const InstrItineraryData *IID) const {\n"
345354
<< " static Automaton<uint64_t> A(ArrayRef<" << TargetAndDFAName
346355
<< "Transition>(" << TargetAndDFAName << "Transitions), "
347356
<< TargetAndDFAName << "TransitionInfo);\n"
357+
<< " unsigned Index = " << TargetName << DFAName
358+
<< "ProcIdToResourceIndexStartMapping[IID->SchedModel.ProcID];\n"
348359
<< " unsigned ProcResIdxStart = " << TargetAndDFAName
349-
<< "ProcResourceIndexStart[IID->SchedModel.ProcID];\n"
360+
<< "ProcResourceIndexStart[Index];\n"
350361
<< " unsigned ProcResIdxNum = " << TargetAndDFAName
351-
<< "ProcResourceIndexStart[IID->SchedModel.ProcID + 1] - "
362+
<< "ProcResourceIndexStart[Index + 1] - "
352363
"ProcResIdxStart;\n"
353364
<< " return new DFAPacketizer(IID, A, {&" << TargetAndDFAName
354365
<< "ResourceIndices[ProcResIdxStart], ProcResIdxNum});\n"

0 commit comments

Comments
 (0)