LLVM  14.0.0git
MultiHazardRecognizer.cpp
Go to the documentation of this file.
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 
15 #include "llvm/ADT/STLExtras.h"
16 #include <algorithm>
17 #include <functional>
18 #include <numeric>
19 
20 using namespace llvm;
21 
23  std::unique_ptr<ScheduleHazardRecognizer> &&R) {
24  MaxLookAhead = std::max(MaxLookAhead, R->getMaxLookAhead());
25  Recognizers.push_back(std::move(R));
26 }
27 
29  return llvm::any_of(Recognizers,
31 }
32 
35  for (auto &R : Recognizers) {
36  auto res = R->getHazardType(SU, Stalls);
37  if (res != NoHazard)
38  return res;
39  }
40  return NoHazard;
41 }
42 
44  for (auto &R : Recognizers)
45  R->Reset();
46 }
47 
49  for (auto &R : Recognizers)
50  R->EmitInstruction(SU);
51 }
52 
54  for (auto &R : Recognizers)
55  R->EmitInstruction(MI);
56 }
57 
59  auto MN = [=](unsigned a, std::unique_ptr<ScheduleHazardRecognizer> &R) {
60  return std::max(a, R->PreEmitNoops(SU));
61  };
62  return std::accumulate(Recognizers.begin(), Recognizers.end(), 0u, MN);
63 }
64 
66  auto MN = [=](unsigned a, std::unique_ptr<ScheduleHazardRecognizer> &R) {
67  return std::max(a, R->PreEmitNoops(MI));
68  };
69  return std::accumulate(Recognizers.begin(), Recognizers.end(), 0u, MN);
70 }
71 
73  auto SPA = [=](std::unique_ptr<ScheduleHazardRecognizer> &R) {
74  return R->ShouldPreferAnother(SU);
75  };
76  return llvm::any_of(Recognizers, SPA);
77 }
78 
80  for (auto &R : Recognizers)
81  R->AdvanceCycle();
82 }
83 
85  for (auto &R : Recognizers)
86  R->RecedeCycle();
87 }
88 
90  for (auto &R : Recognizers)
91  R->EmitNoop();
92 }
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:105
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::MultiHazardRecognizer::getHazardType
HazardType getHazardType(SUnit *, int Stalls=0) override
getHazardType - Return the hazard type of emitting this node.
Definition: MultiHazardRecognizer.cpp:34
llvm::ScheduleHazardRecognizer::MaxLookAhead
unsigned MaxLookAhead
MaxLookAhead - Indicate the number of cycles in the scoreboard state.
Definition: ScheduleHazardRecognizer.h:31
STLExtras.h
a
=0.0 ? 0.0 :(a > 0.0 ? 1.0 :-1.0) a
Definition: README.txt:489
llvm::MultiHazardRecognizer::EmitInstruction
void EmitInstruction(SUnit *) override
EmitInstruction - This callback is invoked when an instruction is emitted, to advance the hazard stat...
Definition: MultiHazardRecognizer.cpp:48
llvm::MultiHazardRecognizer::atIssueLimit
bool atIssueLimit() const override
atIssueLimit - Return true if no more instructions may be issued in this cycle.
Definition: MultiHazardRecognizer.cpp:28
llvm::ScheduleHazardRecognizer::atIssueLimit
virtual bool atIssueLimit() const
atIssueLimit - Return true if no more instructions may be issued in this cycle.
Definition: ScheduleHazardRecognizer.h:51
llvm::ScheduleHazardRecognizer::HazardType
HazardType
Definition: ScheduleHazardRecognizer.h:37
llvm::MultiHazardRecognizer::Reset
void Reset() override
Reset - This callback is invoked when a new block of instructions is about to be schedule.
Definition: MultiHazardRecognizer.cpp:43
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:64
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::MultiHazardRecognizer::RecedeCycle
void RecedeCycle() override
RecedeCycle - This callback is invoked whenever the next bottom-up instruction to be scheduled cannot...
Definition: MultiHazardRecognizer.cpp:84
llvm::any_of
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1558
llvm::ScheduleHazardRecognizer::NoHazard
@ NoHazard
Definition: ScheduleHazardRecognizer.h:38
llvm::MultiHazardRecognizer::EmitNoop
void EmitNoop() override
EmitNoop - This callback is invoked when a noop was added to the instruction stream.
Definition: MultiHazardRecognizer.cpp:89
llvm::max
Align max(MaybeAlign Lhs, Align Rhs)
Definition: Alignment.h:340
llvm::MultiHazardRecognizer::PreEmitNoops
unsigned PreEmitNoops(SUnit *) override
PreEmitNoops - This callback is invoked prior to emitting an instruction.
Definition: MultiHazardRecognizer.cpp:58
llvm::SUnit
Scheduling unit. This is a node in the scheduling DAG.
Definition: ScheduleDAG.h:242
MultiHazardRecognizer.h
llvm::MultiHazardRecognizer::AdvanceCycle
void AdvanceCycle() override
AdvanceCycle - This callback is invoked whenever the next top-down instruction to be scheduled cannot...
Definition: MultiHazardRecognizer.cpp:79
llvm::MultiHazardRecognizer::AddHazardRecognizer
void AddHazardRecognizer(std::unique_ptr< ScheduleHazardRecognizer > &&)
Definition: MultiHazardRecognizer.cpp:22
llvm::MultiHazardRecognizer::ShouldPreferAnother
bool ShouldPreferAnother(SUnit *) override
ShouldPreferAnother - This callback may be invoked if getHazardType returns NoHazard.
Definition: MultiHazardRecognizer.cpp:72