File indexing completed on 2026-05-10 08:44:16
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef LLVM_MCA_SOURCEMGR_H
0015 #define LLVM_MCA_SOURCEMGR_H
0016
0017 #include "llvm/ADT/ArrayRef.h"
0018 #include "llvm/MCA/Instruction.h"
0019
0020 namespace llvm {
0021 namespace mca {
0022
0023
0024
0025 typedef std::pair<unsigned, const Instruction &> SourceRef;
0026
0027
0028
0029 struct SourceMgr {
0030 using UniqueInst = std::unique_ptr<Instruction>;
0031
0032
0033 virtual ArrayRef<UniqueInst> getInstructions() const = 0;
0034
0035
0036
0037 virtual size_t size() const { return getInstructions().size(); }
0038
0039
0040
0041
0042 virtual bool hasNext() const = 0;
0043
0044
0045 virtual bool isEnd() const = 0;
0046
0047
0048 virtual SourceRef peekNext() const = 0;
0049
0050
0051 virtual void updateNext() = 0;
0052
0053 virtual ~SourceMgr() {}
0054 };
0055
0056
0057
0058
0059 class CircularSourceMgr : public SourceMgr {
0060 ArrayRef<UniqueInst> Sequence;
0061 unsigned Current;
0062 const unsigned Iterations;
0063 static const unsigned DefaultIterations = 100;
0064
0065 public:
0066 CircularSourceMgr(ArrayRef<UniqueInst> S, unsigned Iter)
0067 : Sequence(S), Current(0U), Iterations(Iter ? Iter : DefaultIterations) {}
0068
0069 ArrayRef<UniqueInst> getInstructions() const override { return Sequence; }
0070
0071 unsigned getNumIterations() const { return Iterations; }
0072 bool hasNext() const override {
0073 return Current < (Iterations * Sequence.size());
0074 }
0075 bool isEnd() const override { return !hasNext(); }
0076
0077 SourceRef peekNext() const override {
0078 assert(hasNext() && "Already at end of sequence!");
0079 return SourceRef(Current, *Sequence[Current % Sequence.size()]);
0080 }
0081
0082 void updateNext() override { ++Current; }
0083 };
0084
0085 }
0086 }
0087
0088 #endif