[MISched][rework] Introduce and use ResourceSegments.
authorFrancesco Petrogalli <francesco.petrogalli@apple.com>
Fri, 9 Jun 2023 11:24:21 +0000 (13:24 +0200)
committerFrancesco Petrogalli <francesco.petrogalli@apple.com>
Fri, 9 Jun 2023 13:02:00 +0000 (15:02 +0200)
commitaee34000f9fbd50849af4e8950bf16d2034bae6a
tree386cc6c71a6fd5948a99cbc0c74000cd764d53f6
parent63901cb082add8d471a834df420a11a510664d4c
[MISched][rework] Introduce and use ResourceSegments.

Re-landing the code that was reverted because of the buildbot failure
in https://lab.llvm.org/buildbot#builders/9/builds/27319.

Original commit message
======================

The class `ResourceSegments` is used to keep track of the intervals
that represent resource usage of a list of instructions that are
being scheduled by the machine scheduler.

The collection is made of intervals that are closed on the left and
open on the right (represented by the standard notation `[a, b)`).

These collections of intervals can be extended by `add`ing new
intervals accordingly while scheduling a basic block.

Unit tests are added to verify the possible configurations of
intervals, and the relative possibility of scheduling a new
instruction in these configurations. Specifically, the methods
`getFirstAvailableAtFromBottom` and `getFirstAvailableAtFromTop` are
tested to make sure that both bottom-up and top-down scheduling work
when tracking resource usage across the basic block with
`ResourceSegments`.

Note that the scheduler tracks resource usage with two methods:

1. counters (via `std::vector<unsigned> ReservedCycles;`);

2. intervals (via `std::map<unsigned, ResourceSegments> ReservedResourceSegments;`).

This patch can be considered a NFC test for existing scheduling models
because the tracking system that uses intervals is turned off by
default (field `bit EnableIntervals = false;` in the tablegen class
`SchedMachineModel`).

Reviewed By: andreadb

Differential Revision: https://reviews.llvm.org/D150312
llvm/include/llvm/CodeGen/MachineScheduler.h
llvm/include/llvm/CodeGen/TargetSchedule.h
llvm/include/llvm/MC/MCSchedule.h
llvm/include/llvm/Target/TargetSchedule.td
llvm/lib/CodeGen/MachineScheduler.cpp
llvm/lib/MC/MCSchedule.cpp
llvm/unittests/CodeGen/CMakeLists.txt
llvm/unittests/CodeGen/SchedBoundary.cpp [new file with mode: 0644]
llvm/utils/TableGen/SubtargetEmitter.cpp