MultiHazardRecognizer.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. //===- MultiHazardRecognizer.cpp - Scheduler Support ----------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file implements the MultiHazardRecognizer class, which is a wrapper
  10. // for a set of ScheduleHazardRecognizer instances
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "llvm/CodeGen/MultiHazardRecognizer.h"
  14. #include "llvm/ADT/STLExtras.h"
  15. #include <algorithm>
  16. #include <functional>
  17. #include <numeric>
  18. using namespace llvm;
  19. void MultiHazardRecognizer::AddHazardRecognizer(
  20. std::unique_ptr<ScheduleHazardRecognizer> &&R) {
  21. MaxLookAhead = std::max(MaxLookAhead, R->getMaxLookAhead());
  22. Recognizers.push_back(std::move(R));
  23. }
  24. bool MultiHazardRecognizer::atIssueLimit() const {
  25. return llvm::any_of(Recognizers,
  26. std::mem_fn(&ScheduleHazardRecognizer::atIssueLimit));
  27. }
  28. ScheduleHazardRecognizer::HazardType
  29. MultiHazardRecognizer::getHazardType(SUnit *SU, int Stalls) {
  30. for (auto &R : Recognizers) {
  31. auto res = R->getHazardType(SU, Stalls);
  32. if (res != NoHazard)
  33. return res;
  34. }
  35. return NoHazard;
  36. }
  37. void MultiHazardRecognizer::Reset() {
  38. for (auto &R : Recognizers)
  39. R->Reset();
  40. }
  41. void MultiHazardRecognizer::EmitInstruction(SUnit *SU) {
  42. for (auto &R : Recognizers)
  43. R->EmitInstruction(SU);
  44. }
  45. void MultiHazardRecognizer::EmitInstruction(MachineInstr *MI) {
  46. for (auto &R : Recognizers)
  47. R->EmitInstruction(MI);
  48. }
  49. unsigned MultiHazardRecognizer::PreEmitNoops(SUnit *SU) {
  50. auto MN = [=](unsigned a, std::unique_ptr<ScheduleHazardRecognizer> &R) {
  51. return std::max(a, R->PreEmitNoops(SU));
  52. };
  53. return std::accumulate(Recognizers.begin(), Recognizers.end(), 0u, MN);
  54. }
  55. unsigned MultiHazardRecognizer::PreEmitNoops(MachineInstr *MI) {
  56. auto MN = [=](unsigned a, std::unique_ptr<ScheduleHazardRecognizer> &R) {
  57. return std::max(a, R->PreEmitNoops(MI));
  58. };
  59. return std::accumulate(Recognizers.begin(), Recognizers.end(), 0u, MN);
  60. }
  61. bool MultiHazardRecognizer::ShouldPreferAnother(SUnit *SU) {
  62. auto SPA = [=](std::unique_ptr<ScheduleHazardRecognizer> &R) {
  63. return R->ShouldPreferAnother(SU);
  64. };
  65. return llvm::any_of(Recognizers, SPA);
  66. }
  67. void MultiHazardRecognizer::AdvanceCycle() {
  68. for (auto &R : Recognizers)
  69. R->AdvanceCycle();
  70. }
  71. void MultiHazardRecognizer::RecedeCycle() {
  72. for (auto &R : Recognizers)
  73. R->RecedeCycle();
  74. }
  75. void MultiHazardRecognizer::EmitNoop() {
  76. for (auto &R : Recognizers)
  77. R->EmitNoop();
  78. }