diff options
author | Michael Maitland <michaeltmaitland@gmail.com> | 2024-01-24 11:40:23 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-24 13:40:23 -0500 |
commit | 7e09239e24b339f45f63a670e2e831150826bf70 (patch) | |
tree | c235b7627a2fa68bf17da67c4111afe576091276 /llvm/lib/CodeGen/MachineScheduler.cpp | |
parent | 32f7922646d5903f63d16c9fbfe3d508b0f8cda7 (diff) | |
download | llvm-7e09239e24b339f45f63a670e2e831150826bf70.zip llvm-7e09239e24b339f45f63a670e2e831150826bf70.tar.gz llvm-7e09239e24b339f45f63a670e2e831150826bf70.tar.bz2 |
[CodeGen][MISched] Handle empty sized resource usage. (#75951)
TargetSchedule.td explicitly allows the usage of a ProcResource for zero
cycles, in order to represent that the ProcResource must be available
but is not consumed by the instruction. On the other hand,
ResourceSegments explicitly does not allow for a zero sized interval. In
order to remedy this, this patch handles the special case of when there
is an empty interval usage of a resource by not adding an empty
interval.
We ran into this issue downstream, but it makes sense to have
this upstream since it is explicitly allowed by TargetSchedule.td.
Diffstat (limited to 'llvm/lib/CodeGen/MachineScheduler.cpp')
-rw-r--r-- | llvm/lib/CodeGen/MachineScheduler.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/MachineScheduler.cpp b/llvm/lib/CodeGen/MachineScheduler.cpp index f40e918..f6d03f5 100644 --- a/llvm/lib/CodeGen/MachineScheduler.cpp +++ b/llvm/lib/CodeGen/MachineScheduler.cpp @@ -4275,6 +4275,12 @@ unsigned ResourceSegments::getFirstAvailableAt( assert(std::is_sorted(std::begin(_Intervals), std::end(_Intervals), sortIntervals) && "Cannot execute on an un-sorted set of intervals."); + + // Zero resource usage is allowed by TargetSchedule.td but we do not construct + // a ResourceSegment interval for that situation. + if (AcquireAtCycle == Cycle) + return CurrCycle; + unsigned RetCycle = CurrCycle; ResourceSegments::IntervalTy NewInterval = IntervalBuilder(RetCycle, AcquireAtCycle, ReleaseAtCycle); @@ -4294,8 +4300,16 @@ unsigned ResourceSegments::getFirstAvailableAt( void ResourceSegments::add(ResourceSegments::IntervalTy A, const unsigned CutOff) { - assert(A.first < A.second && "Cannot add empty resource usage"); + assert(A.first <= A.second && "Cannot add negative resource usage"); assert(CutOff > 0 && "0-size interval history has no use."); + // Zero resource usage is allowed by TargetSchedule.td, in the case that the + // instruction needed the resource to be available but does not use it. + // However, ResourceSegment represents an interval that is closed on the left + // and open on the right. It is impossible to represent an empty interval when + // the left is closed. Do not add it to Intervals. + if (A.first == A.second) + return; + assert(all_of(_Intervals, [&A](const ResourceSegments::IntervalTy &Interval) -> bool { return !intersects(A, Interval); |