summaryrefslogtreecommitdiff
path: root/tools/llvm-mca/Scheduler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/llvm-mca/Scheduler.cpp')
-rw-r--r--tools/llvm-mca/Scheduler.cpp29
1 files changed, 22 insertions, 7 deletions
diff --git a/tools/llvm-mca/Scheduler.cpp b/tools/llvm-mca/Scheduler.cpp
index deefb461638..a2561fc3582 100644
--- a/tools/llvm-mca/Scheduler.cpp
+++ b/tools/llvm-mca/Scheduler.cpp
@@ -312,17 +312,32 @@ void Scheduler::promoteToReadyQueue(SmallVectorImpl<InstRef> &Ready) {
}
InstRef Scheduler::select() {
- // Give priority to older instructions in the ReadyQueue. Since the ready
- // queue is ordered by key, this will always prioritize older instructions.
- const auto It = std::find_if(ReadyQueue.begin(), ReadyQueue.end(),
- [&](const QueueEntryTy &Entry) {
- const InstrDesc &D = Entry.second->getDesc();
- return Resources->canBeIssued(D);
- });
+ // Find the oldest ready-to-issue instruction in the ReadyQueue.
+ auto It = std::find_if(ReadyQueue.begin(), ReadyQueue.end(),
+ [&](const QueueEntryTy &Entry) {
+ const InstrDesc &D = Entry.second->getDesc();
+ return Resources->canBeIssued(D);
+ });
if (It == ReadyQueue.end())
return {0, nullptr};
+ // We want to prioritize older instructions over younger instructions to
+ // minimize the pressure on the reorder buffer. We also want to
+ // rank higher the instructions with more users to better expose ILP.
+
+ // Compute a rank value based on the age of an instruction (i.e. its source
+ // index) and its number of users. The lower the rank value, the better.
+ int Rank = It->first - It->second->getNumUsers();
+ for (auto I = It, E = ReadyQueue.end(); I != E; ++I) {
+ int CurrentRank = I->first - I->second->getNumUsers();
+ if (CurrentRank < Rank) {
+ const InstrDesc &D = I->second->getDesc();
+ if (Resources->canBeIssued(D))
+ It = I;
+ }
+ }
+
// We found an instruction to issue.
InstRef IR(It->first, It->second);
ReadyQueue.erase(It);