Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Schedule] Add a MultiHazardRecognizer
This adds a MultiHazardRecognizer and starts to make use of it in the ARM backend. The idea of the class is to allow multiple independent hazard recognizers to be added to a single base MultiHazardRecognizer, allowing them to all work in parallel without requiring them to be chained into subclasses. They can then be added or not based on cpu or subtarget features, which will become useful in the ARM backend once more hazard recognizers are being used for various things. This also renames ARMHazardRecognizer to ARMHazardRecognizerFPMLx in the process, to more clearly explain what that recognizer is designed for. Differential Revision: https://reviews.llvm.org/D72939
- Loading branch information
1 parent
52f03fe
commit 61bc18d
Showing
6 changed files
with
159 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
//=- llvm/CodeGen/MultiHazardRecognizer.h - Scheduling Support ----*- C++ -*-=// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file implements the MultiHazardRecognizer class, which is a wrapper | ||
// for a set of ScheduleHazardRecognizer instances | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_CODEGEN_MULTIHAZARDRECOGNIZER_H | ||
#define LLVM_CODEGEN_MULTIHAZARDRECOGNIZER_H | ||
|
||
#include "llvm/ADT/SmallVector.h" | ||
#include "llvm/CodeGen/ScheduleHazardRecognizer.h" | ||
|
||
namespace llvm { | ||
|
||
class MachineInstr; | ||
class SUnit; | ||
|
||
class MultiHazardRecognizer : public ScheduleHazardRecognizer { | ||
SmallVector<std::unique_ptr<ScheduleHazardRecognizer>, 4> Recognizers; | ||
|
||
public: | ||
MultiHazardRecognizer() = default; | ||
void AddHazardRecognizer(std::unique_ptr<ScheduleHazardRecognizer> &&); | ||
|
||
bool atIssueLimit() const override; | ||
HazardType getHazardType(SUnit *m, int Stalls = 0) override; | ||
void Reset() override; | ||
void EmitInstruction(SUnit *) override; | ||
void EmitInstruction(MachineInstr *) override; | ||
unsigned PreEmitNoops(SUnit *) override; | ||
unsigned PreEmitNoops(MachineInstr *) override; | ||
bool ShouldPreferAnother(SUnit *) override; | ||
void AdvanceCycle() override; | ||
void RecedeCycle() override; | ||
void EmitNoop() override; | ||
}; | ||
|
||
} // end namespace llvm | ||
|
||
#endif // LLVM_CODEGEN_MULTIHAZARDRECOGNIZER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
//===- MultiHazardRecognizer.cpp - Scheduler Support ----------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file implements the MultiHazardRecognizer class, which is a wrapper | ||
// for a set of ScheduleHazardRecognizer instances | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "llvm/CodeGen/MultiHazardRecognizer.h" | ||
#include <algorithm> | ||
#include <functional> | ||
#include <numeric> | ||
|
||
using namespace llvm; | ||
|
||
void MultiHazardRecognizer::AddHazardRecognizer( | ||
std::unique_ptr<ScheduleHazardRecognizer> &&R) { | ||
MaxLookAhead = std::max(MaxLookAhead, R->getMaxLookAhead()); | ||
Recognizers.push_back(std::move(R)); | ||
} | ||
|
||
bool MultiHazardRecognizer::atIssueLimit() const { | ||
return std::any_of(Recognizers.begin(), Recognizers.end(), | ||
std::mem_fn(&ScheduleHazardRecognizer::atIssueLimit)); | ||
} | ||
|
||
ScheduleHazardRecognizer::HazardType | ||
MultiHazardRecognizer::getHazardType(SUnit *SU, int Stalls) { | ||
for (auto &R : Recognizers) { | ||
auto res = R->getHazardType(SU, Stalls); | ||
if (res != NoHazard) | ||
return res; | ||
} | ||
return NoHazard; | ||
} | ||
|
||
void MultiHazardRecognizer::Reset() { | ||
for (auto &R : Recognizers) | ||
R->Reset(); | ||
} | ||
|
||
void MultiHazardRecognizer::EmitInstruction(SUnit *SU) { | ||
for (auto &R : Recognizers) | ||
R->EmitInstruction(SU); | ||
} | ||
|
||
void MultiHazardRecognizer::EmitInstruction(MachineInstr *MI) { | ||
for (auto &R : Recognizers) | ||
R->EmitInstruction(MI); | ||
} | ||
|
||
unsigned MultiHazardRecognizer::PreEmitNoops(SUnit *SU) { | ||
auto MN = [=](unsigned a, std::unique_ptr<ScheduleHazardRecognizer> &R) { | ||
return std::max(a, R->PreEmitNoops(SU)); | ||
}; | ||
return std::accumulate(Recognizers.begin(), Recognizers.end(), 0u, MN); | ||
} | ||
|
||
unsigned MultiHazardRecognizer::PreEmitNoops(MachineInstr *MI) { | ||
auto MN = [=](unsigned a, std::unique_ptr<ScheduleHazardRecognizer> &R) { | ||
return std::max(a, R->PreEmitNoops(MI)); | ||
}; | ||
return std::accumulate(Recognizers.begin(), Recognizers.end(), 0u, MN); | ||
} | ||
|
||
bool MultiHazardRecognizer::ShouldPreferAnother(SUnit *SU) { | ||
auto SPA = [=](std::unique_ptr<ScheduleHazardRecognizer> &R) { | ||
return R->ShouldPreferAnother(SU); | ||
}; | ||
return std::any_of(Recognizers.begin(), Recognizers.end(), SPA); | ||
} | ||
|
||
void MultiHazardRecognizer::AdvanceCycle() { | ||
for (auto &R : Recognizers) | ||
R->AdvanceCycle(); | ||
} | ||
|
||
void MultiHazardRecognizer::RecedeCycle() { | ||
for (auto &R : Recognizers) | ||
R->RecedeCycle(); | ||
} | ||
|
||
void MultiHazardRecognizer::EmitNoop() { | ||
for (auto &R : Recognizers) | ||
R->EmitNoop(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters