/src/llvm-project/llvm/lib/CodeGen/MultiHazardRecognizer.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | |
14 | | #include "llvm/CodeGen/MultiHazardRecognizer.h" |
15 | | #include "llvm/ADT/STLExtras.h" |
16 | | #include <algorithm> |
17 | | #include <functional> |
18 | | #include <numeric> |
19 | | |
20 | | using namespace llvm; |
21 | | |
22 | | void MultiHazardRecognizer::AddHazardRecognizer( |
23 | 2.46k | std::unique_ptr<ScheduleHazardRecognizer> &&R) { |
24 | 2.46k | MaxLookAhead = std::max(MaxLookAhead, R->getMaxLookAhead()); |
25 | 2.46k | Recognizers.push_back(std::move(R)); |
26 | 2.46k | } |
27 | | |
28 | 208k | bool MultiHazardRecognizer::atIssueLimit() const { |
29 | 208k | return llvm::any_of(Recognizers, |
30 | 208k | std::mem_fn(&ScheduleHazardRecognizer::atIssueLimit)); |
31 | 208k | } |
32 | | |
33 | | ScheduleHazardRecognizer::HazardType |
34 | 317k | MultiHazardRecognizer::getHazardType(SUnit *SU, int Stalls) { |
35 | 317k | for (auto &R : Recognizers) { |
36 | 317k | auto res = R->getHazardType(SU, Stalls); |
37 | 317k | if (res != NoHazard) |
38 | 109k | return res; |
39 | 317k | } |
40 | 208k | return NoHazard; |
41 | 317k | } |
42 | | |
43 | 50.4k | void MultiHazardRecognizer::Reset() { |
44 | 50.4k | for (auto &R : Recognizers) |
45 | 50.4k | R->Reset(); |
46 | 50.4k | } |
47 | | |
48 | 208k | void MultiHazardRecognizer::EmitInstruction(SUnit *SU) { |
49 | 208k | for (auto &R : Recognizers) |
50 | 208k | R->EmitInstruction(SU); |
51 | 208k | } |
52 | | |
53 | 0 | void MultiHazardRecognizer::EmitInstruction(MachineInstr *MI) { |
54 | 0 | for (auto &R : Recognizers) |
55 | 0 | R->EmitInstruction(MI); |
56 | 0 | } |
57 | | |
58 | 208k | unsigned MultiHazardRecognizer::PreEmitNoops(SUnit *SU) { |
59 | 208k | auto MN = [=](unsigned a, std::unique_ptr<ScheduleHazardRecognizer> &R) { |
60 | 208k | return std::max(a, R->PreEmitNoops(SU)); |
61 | 208k | }; |
62 | 208k | return std::accumulate(Recognizers.begin(), Recognizers.end(), 0u, MN); |
63 | 208k | } |
64 | | |
65 | 0 | unsigned MultiHazardRecognizer::PreEmitNoops(MachineInstr *MI) { |
66 | 0 | auto MN = [=](unsigned a, std::unique_ptr<ScheduleHazardRecognizer> &R) { |
67 | 0 | return std::max(a, R->PreEmitNoops(MI)); |
68 | 0 | }; |
69 | 0 | return std::accumulate(Recognizers.begin(), Recognizers.end(), 0u, MN); |
70 | 0 | } |
71 | | |
72 | 208k | bool MultiHazardRecognizer::ShouldPreferAnother(SUnit *SU) { |
73 | 208k | auto SPA = [=](std::unique_ptr<ScheduleHazardRecognizer> &R) { |
74 | 208k | return R->ShouldPreferAnother(SU); |
75 | 208k | }; |
76 | 208k | return llvm::any_of(Recognizers, SPA); |
77 | 208k | } |
78 | | |
79 | 163k | void MultiHazardRecognizer::AdvanceCycle() { |
80 | 163k | for (auto &R : Recognizers) |
81 | 163k | R->AdvanceCycle(); |
82 | 163k | } |
83 | | |
84 | 0 | void MultiHazardRecognizer::RecedeCycle() { |
85 | 0 | for (auto &R : Recognizers) |
86 | 0 | R->RecedeCycle(); |
87 | 0 | } |
88 | | |
89 | 0 | void MultiHazardRecognizer::EmitNoop() { |
90 | 0 | for (auto &R : Recognizers) |
91 | 0 | R->EmitNoop(); |
92 | 0 | } |