LLVM 20.0.0git
SourceMgr.h
Go to the documentation of this file.
1//===--------------------- SourceMgr.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 abstract class SourceMgr and the default implementation,
10/// CircularSourceMgr.
11///
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_MCA_SOURCEMGR_H
15#define LLVM_MCA_SOURCEMGR_H
16
17#include "llvm/ADT/ArrayRef.h"
19
20namespace llvm {
21namespace mca {
22
23// MSVC >= 19.15, < 19.20 need to see the definition of class Instruction to
24// prevent compiler error C2139 about intrinsic type trait '__is_assignable'.
25typedef std::pair<unsigned, const Instruction &> SourceRef;
26
27/// Abstracting the input code sequence (a sequence of MCInst) and assigning
28/// unique identifiers to every instruction in the sequence.
29struct SourceMgr {
30 using UniqueInst = std::unique_ptr<Instruction>;
31
32 /// Provides a fixed range of \a UniqueInst to iterate.
34
35 /// (Fixed) Number of \a UniqueInst. Returns the size of
36 /// \a getInstructions by default.
37 virtual size_t size() const { return getInstructions().size(); }
38
39 /// Whether there is any \a SourceRef to inspect / peek next.
40 /// Note that returning false from this doesn't mean the instruction
41 /// stream has ended.
42 virtual bool hasNext() const = 0;
43
44 /// Whether the instruction stream has eneded.
45 virtual bool isEnd() const = 0;
46
47 /// The next \a SourceRef.
48 virtual SourceRef peekNext() const = 0;
49
50 /// Advance to the next \a SourceRef.
51 virtual void updateNext() = 0;
52
53 virtual ~SourceMgr() {}
54};
55
56/// The default implementation of \a SourceMgr. It always takes a fixed number
57/// of instructions and provides an option to loop the given sequence for a
58/// certain iterations.
60 ArrayRef<UniqueInst> Sequence;
61 unsigned Current;
62 const unsigned Iterations;
63 static const unsigned DefaultIterations = 100;
64
65public:
67 : Sequence(S), Current(0U), Iterations(Iter ? Iter : DefaultIterations) {}
68
69 ArrayRef<UniqueInst> getInstructions() const override { return Sequence; }
70
71 unsigned getNumIterations() const { return Iterations; }
72 bool hasNext() const override {
73 return Current < (Iterations * Sequence.size());
74 }
75 bool isEnd() const override { return !hasNext(); }
76
77 SourceRef peekNext() const override {
78 assert(hasNext() && "Already at end of sequence!");
79 return SourceRef(Current, *Sequence[Current % Sequence.size()]);
80 }
81
82 void updateNext() override { ++Current; }
83};
84
85} // namespace mca
86} // namespace llvm
87
88#endif // LLVM_MCA_SOURCEMGR_H
This file defines abstractions used by the Pipeline to model register reads, register writes and inst...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:165
The default implementation of SourceMgr.
Definition: SourceMgr.h:59
void updateNext() override
Advance to the next SourceRef.
Definition: SourceMgr.h:82
SourceRef peekNext() const override
The next SourceRef.
Definition: SourceMgr.h:77
CircularSourceMgr(ArrayRef< UniqueInst > S, unsigned Iter)
Definition: SourceMgr.h:66
bool hasNext() const override
Whether there is any SourceRef to inspect / peek next.
Definition: SourceMgr.h:72
ArrayRef< UniqueInst > getInstructions() const override
Provides a fixed range of UniqueInst to iterate.
Definition: SourceMgr.h:69
bool isEnd() const override
Whether the instruction stream has eneded.
Definition: SourceMgr.h:75
unsigned getNumIterations() const
Definition: SourceMgr.h:71
std::pair< unsigned, const Instruction & > SourceRef
Definition: SourceMgr.h:25
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Abstracting the input code sequence (a sequence of MCInst) and assigning unique identifiers to every ...
Definition: SourceMgr.h:29
virtual void updateNext()=0
Advance to the next SourceRef.
virtual size_t size() const
(Fixed) Number of UniqueInst.
Definition: SourceMgr.h:37
virtual ArrayRef< UniqueInst > getInstructions() const =0
Provides a fixed range of UniqueInst to iterate.
virtual ~SourceMgr()
Definition: SourceMgr.h:53
virtual bool isEnd() const =0
Whether the instruction stream has eneded.
std::unique_ptr< Instruction > UniqueInst
Definition: SourceMgr.h:30
virtual SourceRef peekNext() const =0
The next SourceRef.
virtual bool hasNext() const =0
Whether there is any SourceRef to inspect / peek next.