Skip to content

Commit

Permalink
[TableGen] Emit a fatal error on inconsistencies in resource units vs…
Browse files Browse the repository at this point in the history
… cycles.

Summary:
For targets I'm not familiar with, I've automatically made the "default to 1 for each resource" behaviour explicit in the td files.
For more obvious cases, I've ventured a fix.

Some notes:
 - Exynos is especially fishy.
 - AArch64SchedThunderX2T99.td had some truncated entries. If I understand correctly, the person who wrote that interpreted the ResourceCycle as a range. I made the decision to use the upper/lower bound for consistency with the 'Latency' value. I'm sure there is a better choice.
 - The change to X86ScheduleBtVer2.td is an NFC, it just makes values more explicit.

Also see PR37310.

Reviewers: RKSimon, craig.topper, javed.absar

Subscribers: kristof.beyls, llvm-commits

Differential Revision: https://reviews.llvm.org/D46356

llvm-svn: 334586
  • Loading branch information
legrosbuffle committed Jun 13, 2018
1 parent b10ef47 commit 5eeed77
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
7 changes: 3 additions & 4 deletions llvm/include/llvm/Target/TargetSchedule.td
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,9 @@ class ProcWriteResources<list<ProcResourceKind> resources> {
// ProcResources indicates the set of resources consumed by the write.
// Optionally, ResourceCycles indicates the number of cycles the
// resource is consumed. Each ResourceCycles item is paired with the
// ProcResource item at the same position in its list. Since
// ResourceCycles are rarely specialized, the list may be
// incomplete. By default, resources are consumed for a single cycle,
// regardless of latency, which models a fully pipelined processing
// ProcResource item at the same position in its list. ResourceCycles
// can be `[]`: in that case, all resources are consumed for a single
// cycle, regardless of latency, which models a fully pipelined processing
// unit. A value of 0 for ResourceCycles means that the resource must
// be available but is not consumed, which is only relevant for
// unbuffered resources.
Expand Down
12 changes: 6 additions & 6 deletions llvm/lib/Target/AArch64/AArch64SchedThunderX2T99.td
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ def : InstRW<[THX2T99Write_1Cyc_I2],
// Address generation
def : WriteRes<WriteI, [THX2T99I012]> {
let Latency = 1;
let ResourceCycles = [1, 3];
let ResourceCycles = [1];
let NumMicroOps = 2;
}

Expand All @@ -438,7 +438,7 @@ def : InstRW<[WriteI], (instrs COPY)>;
// ALU, extend and/or shift
def : WriteRes<WriteISReg, [THX2T99I012]> {
let Latency = 2;
let ResourceCycles = [2, 3];
let ResourceCycles = [2];
let NumMicroOps = 2;
}

Expand All @@ -457,7 +457,7 @@ def : InstRW<[WriteISReg],

def : WriteRes<WriteIEReg, [THX2T99I012]> {
let Latency = 1;
let ResourceCycles = [1, 3];
let ResourceCycles = [1];
let NumMicroOps = 2;
}

Expand Down Expand Up @@ -500,14 +500,14 @@ def : WriteRes<WriteIS, [THX2T99I012]> {
// Latency range of 13-23/13-39.
def : WriteRes<WriteID32, [THX2T99I1]> {
let Latency = 39;
let ResourceCycles = [13, 39];
let ResourceCycles = [39];
let NumMicroOps = 4;
}

// Divide, X-form
def : WriteRes<WriteID64, [THX2T99I1]> {
let Latency = 23;
let ResourceCycles = [13, 23];
let ResourceCycles = [23];
let NumMicroOps = 4;
}

Expand Down Expand Up @@ -1252,7 +1252,7 @@ def : InstRW<[THX2T99Write_5Cyc_F01], (instrs FMOVXDHighr, FMOVDXHighr)>;
def : WriteRes<WriteV, [THX2T99F01]> {
let Latency = 7;
let NumMicroOps = 4;
let ResourceCycles = [4, 23];
let ResourceCycles = [4];
}

// ASIMD arith, reduce, 4H/4S
Expand Down
18 changes: 16 additions & 2 deletions llvm/utils/TableGen/SubtargetEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -941,8 +941,7 @@ Record *SubtargetEmitter::FindReadAdvance(const CodeGenSchedRW &SchedRead,
void SubtargetEmitter::ExpandProcResources(RecVec &PRVec,
std::vector<int64_t> &Cycles,
const CodeGenProcModel &PM) {
// Default to 1 resource cycle.
Cycles.resize(PRVec.size(), 1);
assert(PRVec.size() == Cycles.size() && "failed precondition");
for (unsigned i = 0, e = PRVec.size(); i != e; ++i) {
Record *PRDef = PRVec[i];
RecVec SubResources;
Expand Down Expand Up @@ -1111,6 +1110,21 @@ void SubtargetEmitter::GenSchedClassTables(const CodeGenProcModel &ProcModel,
std::vector<int64_t> Cycles =
WriteRes->getValueAsListOfInts("ResourceCycles");

if (Cycles.empty()) {
// If ResourceCycles is not provided, default to one cycle per
// resource.
Cycles.resize(PRVec.size(), 1);
} else if (Cycles.size() != PRVec.size()) {
// If ResourceCycles is provided, check consistency.
PrintFatalError(
WriteRes->getLoc(),
Twine("Inconsistent resource cycles: !size(ResourceCycles) != "
"!size(ProcResources): ")
.concat(Twine(PRVec.size()))
.concat(" vs ")
.concat(Twine(Cycles.size())));
}

ExpandProcResources(PRVec, Cycles, ProcModel);

for (unsigned PRIdx = 0, PREnd = PRVec.size();
Expand Down

0 comments on commit 5eeed77

Please sign in to comment.