LLVM  15.0.0git
IncrementalSourceMgr.h
Go to the documentation of this file.
1 //===---------------- IncrementalSourceMgr.h --------------------*- C++ -*-===//
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 /// \file
9 /// This file contains IncrementalSourceMgr, an implementation of SourceMgr
10 /// that allows users to add new instructions incrementally / dynamically.
11 ///
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_MCA_INCREMENTALSOURCEMGR_H
15 #define LLVM_MCA_INCREMENTALSOURCEMGR_H
16 
17 #include "llvm/MCA/SourceMgr.h"
18 #include <deque>
19 
20 namespace llvm {
21 namespace mca {
22 
23 /// An implementation of \a SourceMgr that allows users to add new instructions
24 /// incrementally / dynamically.
25 /// Note that this SourceMgr takes ownership of all \a mca::Instruction.
27  /// Owner of all mca::Instruction instances. Note that we use std::deque here
28  /// to have a better throughput, in comparison to std::vector or
29  /// llvm::SmallVector, as they usually pay a higher re-allocation cost when
30  /// there is a large number of instructions.
31  std::deque<UniqueInst> InstStorage;
32 
33  /// Instructions that are ready to be used. Each of them is a pointer of an
34  /// \a UniqueInst inside InstStorage.
35  std::deque<Instruction *> Staging;
36 
37  /// Current instruction index.
38  unsigned TotalCounter;
39 
40  /// End-of-stream flag.
41  bool EOS;
42 
43  /// Called when an instruction is no longer needed.
45  InstFreedCallback InstFreedCB;
46 
47 public:
48  IncrementalSourceMgr() : TotalCounter(0U), EOS(false) {}
49 
50  void clear();
51 
52  /// Set a callback that is invoked when a mca::Instruction is
53  /// no longer needed. This is usually used for recycling the
54  /// instruction.
55  void setOnInstFreedCallback(InstFreedCallback CB) { InstFreedCB = CB; }
56 
58  llvm_unreachable("Not applicable");
59  }
60 
61  bool hasNext() const override { return !Staging.empty(); }
62  bool isEnd() const override { return EOS; }
63 
64  SourceRef peekNext() const override {
65  assert(hasNext());
66  return SourceRef(TotalCounter, *Staging.front());
67  }
68 
69  /// Add a new instruction.
70  void addInst(UniqueInst &&Inst) {
71  InstStorage.emplace_back(std::move(Inst));
72  Staging.push_back(InstStorage.back().get());
73  }
74 
75  /// Add a recycled instruction.
76  void addRecycledInst(Instruction *Inst) { Staging.push_back(Inst); }
77 
78  void updateNext() override;
79 
80  /// Mark the end of instruction stream.
81  void endOfStream() { EOS = true; }
82 
83 #ifndef NDEBUG
84  /// Print statistic about instruction recycling stats.
85  void printStatistic(raw_ostream &OS);
86 #endif
87 };
88 
89 } // end namespace mca
90 } // end namespace llvm
91 
92 #endif // LLVM_MCA_INCREMENTALSOURCEMGR_H
llvm::mca::IncrementalSourceMgr::setOnInstFreedCallback
void setOnInstFreedCallback(InstFreedCallback CB)
Set a callback that is invoked when a mca::Instruction is no longer needed.
Definition: IncrementalSourceMgr.h:55
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::mca::IncrementalSourceMgr::addInst
void addInst(UniqueInst &&Inst)
Add a new instruction.
Definition: IncrementalSourceMgr.h:70
llvm::mca::IncrementalSourceMgr::addRecycledInst
void addRecycledInst(Instruction *Inst)
Add a recycled instruction.
Definition: IncrementalSourceMgr.h:76
llvm::mca::IncrementalSourceMgr::updateNext
void updateNext() override
Advance to the next SourceRef.
Definition: IncrementalSourceMgr.cpp:29
llvm::mca::SourceMgr
Abstracting the input code sequence (a sequence of MCInst) and assigning unique identifiers to every ...
Definition: SourceMgr.h:29
llvm::mca::IncrementalSourceMgr::isEnd
bool isEnd() const override
Whether the instruction stream has eneded.
Definition: IncrementalSourceMgr.h:62
llvm::mca::IncrementalSourceMgr::peekNext
SourceRef peekNext() const override
The next SourceRef.
Definition: IncrementalSourceMgr.h:64
llvm::mca::Instruction
An instruction propagated through the simulated instruction pipeline.
Definition: Instruction.h:600
SourceMgr.h
llvm::mca::IncrementalSourceMgr::clear
void clear()
Definition: IncrementalSourceMgr.cpp:22
false
Definition: StackSlotColoring.cpp:141
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:54
llvm::mca::IncrementalSourceMgr::endOfStream
void endOfStream()
Mark the end of instruction stream.
Definition: IncrementalSourceMgr.h:81
llvm::mca::IncrementalSourceMgr::hasNext
bool hasNext() const override
Whether there is any SourceRef to inspect / peek next.
Definition: IncrementalSourceMgr.h:61
llvm::function_ref< void(Instruction *)>
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
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::mca::IncrementalSourceMgr
An implementation of SourceMgr that allows users to add new instructions incrementally / dynamically.
Definition: IncrementalSourceMgr.h:26
llvm::ArrayRef< UniqueInst >
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:143
llvm::mca::IncrementalSourceMgr::printStatistic
void printStatistic(raw_ostream &OS)
Print statistic about instruction recycling stats.
Definition: IncrementalSourceMgr.cpp:40
llvm::mca::SourceMgr::UniqueInst
std::unique_ptr< Instruction > UniqueInst
Definition: SourceMgr.h:30
llvm::mca::SourceRef
std::pair< unsigned, const Instruction & > SourceRef
Definition: SourceMgr.h:25
llvm::mca::IncrementalSourceMgr::IncrementalSourceMgr
IncrementalSourceMgr()
Definition: IncrementalSourceMgr.h:48
llvm::mca::IncrementalSourceMgr::getInstructions
ArrayRef< UniqueInst > getInstructions() const override
Provides a fixed range of UniqueInst to iterate.
Definition: IncrementalSourceMgr.h:57