-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[TableGen] Add mapping from processor ID to resource index for packetizer #158182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
311a4b8
9d25fe7
26ac7b6
64e6793
a04ae23
409b19f
65159da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// RUN: llvm-tblgen -gen-dfa-packetizer -I %p/../../include %s | FileCheck %s | ||
|
||
include "llvm/Target/Target.td" | ||
|
||
def TestTarget : Target; | ||
|
||
def TestSchedModel : SchedMachineModel { | ||
let CompleteModel = 0; | ||
} | ||
|
||
def TestProcessor1 : ProcessorModel<"testprocessor1", TestSchedModel, []>; | ||
|
||
def FU0 : FuncUnit; | ||
def FU1 : FuncUnit; | ||
|
||
def OP0 : InstrItinClass; | ||
def OP1 : InstrItinClass; | ||
|
||
def Itin { | ||
list<InstrItinData> ItinList = [ | ||
InstrItinData<OP0, [InstrStage<1, [FU0]>]>, | ||
InstrItinData<OP1, [InstrStage<1, [FU1]>]>, | ||
]; | ||
} | ||
|
||
// CHECK: int TestTargetGetResourceIndex(unsigned ProcID) { | ||
// CHECK-NEXT: static const unsigned TestTargetProcIdToProcResourceIdxTable[][2] = { | ||
// CHECK-NEXT: { 2, 1 }, // TestItinerariesModel | ||
// CHECK-NEXT: }; | ||
// CHECK-NEXT: auto It = llvm::lower_bound(TestTargetProcIdToProcResourceIdxTable, ProcID, | ||
// CHECK-NEXT: [](const unsigned LHS[], unsigned Val) { return LHS[0] < Val; }); | ||
// CHECK-NEXT: assert(*It[0] == ProcID); | ||
// CHECK-NEXT: return (*It)[1]; | ||
|
||
// CHECK-NEXT: } | ||
|
||
// CHECK: unsigned Index = TestTargetGetResourceIndex(IID->SchedModel.ProcID); | ||
|
||
def TestItineraries: ProcessorItineraries<[], [], Itin.ItinList>; | ||
def TestProcessor2 : Processor<"testprocessor2", TestItineraries, []>; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -266,6 +266,25 @@ void DFAPacketizerEmitter::emitForItineraries( | |
} | ||
OS << " " << ScheduleClasses.size() << "\n};\n\n"; | ||
|
||
// Output the mapping from proc ID to ResourceIndexStart | ||
Idx = 1; | ||
OS << "int " << TargetName << DFAName | ||
<< "GetResourceIndex(unsigned ProcID) { \n" | ||
<< " static const unsigned " << TargetName << DFAName | ||
<< "ProcIdToProcResourceIdxTable[][2] = {\n"; | ||
for (const CodeGenProcModel *Model : ProcModels) { | ||
OS << " { " << Model->Index << ", " << Idx++ << " }, // " | ||
<< Model->ModelName << "\n"; | ||
} | ||
OS << " };\n" | ||
<< " auto It = llvm::lower_bound(" << TargetName << DFAName | ||
<< "ProcIdToProcResourceIdxTable, ProcID,\n" | ||
<< " [](const unsigned LHS[], unsigned Val) { return LHS[0] < Val; " | ||
"});\n" | ||
<< " assert(*It[0] == ProcID);\n" | ||
<< " return (*It)[1];\n" | ||
<< "}\n\n"; | ||
|
||
// The type of a state in the nondeterministic automaton we're defining. | ||
using NfaStateTy = uint64_t; | ||
|
||
|
@@ -339,16 +358,17 @@ void DFAPacketizerEmitter::emitForItineraries( | |
|
||
std::string SubTargetClassName = TargetName + "GenSubtargetInfo"; | ||
OS << "namespace llvm {\n"; | ||
OS << "DFAPacketizer *" << SubTargetClassName << "::" | ||
<< "create" << DFAName | ||
OS << "DFAPacketizer *" << SubTargetClassName << "::" << "create" << DFAName | ||
<< "DFAPacketizer(const InstrItineraryData *IID) const {\n" | ||
<< " static Automaton<uint64_t> A(ArrayRef<" << TargetAndDFAName | ||
<< "Transition>(" << TargetAndDFAName << "Transitions), " | ||
<< TargetAndDFAName << "TransitionInfo);\n" | ||
<< " unsigned Index = " << TargetName << DFAName | ||
|
||
<< "GetResourceIndex(IID->SchedModel.ProcID);\n" | ||
<< " unsigned ProcResIdxStart = " << TargetAndDFAName | ||
<< "ProcResourceIndexStart[IID->SchedModel.ProcID];\n" | ||
<< "ProcResourceIndexStart[Index];\n" | ||
<< " unsigned ProcResIdxNum = " << TargetAndDFAName | ||
<< "ProcResourceIndexStart[IID->SchedModel.ProcID + 1] - " | ||
<< "ProcResourceIndexStart[Index + 1] - " | ||
"ProcResIdxStart;\n" | ||
<< " return new DFAPacketizer(IID, A, {&" << TargetAndDFAName | ||
<< "ResourceIndices[ProcResIdxStart], ProcResIdxNum});\n" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: I guess llvm::lower_bound supports unsigned[][].
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got compiling error with below code. I'd like keep this code in this patch and revise it when there is a better way to call lower_bound() for
unsigned arr[][]
.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean something like:
See
llvm-project/llvm/include/llvm/ADT/STLExtras.h
Lines 1982 to 1985 in cedceeb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revised.