llvm.org GIT mirror llvm / ee765a1
[TargetSchedule] Expose sub-units of a ProcResGroup in MCProcResourceDesc. Summary: Right now using a ProcResource automatically counts as usage of all super ProcResGroups. All this is done during codegen, so there is no way for schedulers to get this information at runtime. This adds the information of which individual ProcRes units are contained in a ProcResGroup in MCProcResourceDesc. Reviewers: gchatelet Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D43023 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@324582 91177308-0d34-0410-b5e6-96231b3b80d8 Clement Courbet 2 years ago
3 changed file(s) with 45 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
4242 // in the same cycle. This is for in-order cpus, or the in-order portion of
4343 // an out-of-order cpus.
4444 int BufferSize;
45
46 // If the resource has sub-units, a pointer to the first element of an array
47 // of `NumUnits` elements containing the ProcResourceIdx of the sub units.
48 // nullptr if the resource does not have sub-units.
49 const unsigned *SubUnitsIdxBegin;
4550
4651 bool operator==(const MCProcResourceDesc &Other) const {
4752 return NumUnits == Other.NumUnits && SuperIdx == Other.SuperIdx
174174 // BufferSize=1.
175175 //
176176 // SchedModel ties these units to a processor for any stand-alone defs
177 // of this class. Instances of subclass ProcResource will be automatically
178 // attached to a processor, so SchedModel is not needed.
177 // of this class.
179178 class ProcResourceUnits {
180179 ProcResourceKind Kind = kind;
181180 int NumUnits = num;
9191 &ProcItinLists);
9292 void EmitProcessorProp(raw_ostream &OS, const Record *R, StringRef Name,
9393 char Separator);
94 void EmitProcessorResourceSubUnits(const CodeGenProcModel &ProcModel,
95 raw_ostream &OS);
9496 void EmitProcessorResources(const CodeGenProcModel &ProcModel,
9597 raw_ostream &OS);
9698 Record *FindWriteResources(const CodeGenSchedRW &SchedWrite,
577579 OS << '\n';
578580 }
579581
582 void SubtargetEmitter::EmitProcessorResourceSubUnits(
583 const CodeGenProcModel &ProcModel, raw_ostream &OS) {
584 OS << "\nstatic const unsigned " << ProcModel.ModelName
585 << "ProcResourceSubUnits[] = {\n"
586 << " 0, // Invalid\n";
587
588 for (unsigned i = 0, e = ProcModel.ProcResourceDefs.size(); i < e; ++i) {
589 Record *PRDef = ProcModel.ProcResourceDefs[i];
590 if (!PRDef->isSubClassOf("ProcResGroup"))
591 continue;
592 RecVec ResUnits = PRDef->getValueAsListOfDefs("Resources");
593 for (Record *RUDef : ResUnits) {
594 Record *const RU =
595 SchedModels.findProcResUnits(RUDef, ProcModel, PRDef->getLoc());
596 for (unsigned J = 0; J < RU->getValueAsInt("NumUnits"); ++J) {
597 OS << " " << ProcModel.getProcResourceIdx(RU) << ", ";
598 }
599 }
600 OS << " // " << PRDef->getName() << "\n";
601 }
602 OS << "};\n";
603 }
604
580605 void SubtargetEmitter::EmitProcessorResources(const CodeGenProcModel &ProcModel,
581606 raw_ostream &OS) {
582 OS << "\n// {Name, NumUnits, SuperIdx, IsBuffered}\n";
607 EmitProcessorResourceSubUnits(ProcModel, OS);
608
609 OS << "\n// {Name, NumUnits, SuperIdx, IsBuffered, SubUnitsIdxBegin}\n";
583610 OS << "static const llvm::MCProcResourceDesc "
584611 << ProcModel.ModelName << "ProcResources" << "[] = {\n"
585612 << " {DBGFIELD(\"InvalidUnit\") 0, 0, 0},\n";
586613
614 unsigned SubUnitsOffset = 1;
587615 for (unsigned i = 0, e = ProcModel.ProcResourceDefs.size(); i < e; ++i) {
588616 Record *PRDef = ProcModel.ProcResourceDefs[i];
589617
590618 Record *SuperDef = nullptr;
591619 unsigned SuperIdx = 0;
592620 unsigned NumUnits = 0;
621 const unsigned SubUnitsBeginOffset = SubUnitsOffset;
593622 int BufferSize = PRDef->getValueAsInt("BufferSize");
594623 if (PRDef->isSubClassOf("ProcResGroup")) {
595624 RecVec ResUnits = PRDef->getValueAsListOfDefs("Resources");
596625 for (Record *RU : ResUnits) {
597626 NumUnits += RU->getValueAsInt("NumUnits");
627 SubUnitsOffset += NumUnits;
598628 }
599629 }
600630 else {
611641 OS << " {DBGFIELD(\"" << PRDef->getName() << "\") ";
612642 if (PRDef->getName().size() < 15)
613643 OS.indent(15 - PRDef->getName().size());
614 OS << NumUnits << ", " << SuperIdx << ", "
615 << BufferSize << "}, // #" << i+1;
644 OS << NumUnits << ", " << SuperIdx << ", " << BufferSize << ", ";
645 if (SubUnitsBeginOffset != SubUnitsOffset) {
646 OS << ProcModel.ModelName << "ProcResourceSubUnits + "
647 << SubUnitsBeginOffset;
648 } else {
649 OS << "nullptr";
650 }
651 OS << "}, // #" << i+1;
616652 if (SuperDef)
617653 OS << ", Super=" << SuperDef->getName();
618654 OS << "\n";