1 //===--------------------- SourceMgr.h --------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 /// This file implements class SourceMgr. Class SourceMgr abstracts the input
10 /// code sequence (a sequence of MCInst), and assings unique identifiers to
11 /// every instruction in the sequence.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_MCA_SOURCEMGR_H
16 #define LLVM_MCA_SOURCEMGR_H
18 #include "llvm/ADT/ArrayRef.h"
25 typedef std::pair<unsigned, const Instruction &> SourceRef;
28 using UniqueInst = std::unique_ptr<Instruction>;
29 ArrayRef<UniqueInst> Sequence;
31 const unsigned Iterations;
32 static const unsigned DefaultIterations = 100;
35 SourceMgr(ArrayRef<UniqueInst> S, unsigned Iter)
36 : Sequence(S), Current(0), Iterations(Iter ? Iter : DefaultIterations) {}
38 unsigned getNumIterations() const { return Iterations; }
39 unsigned size() const { return Sequence.size(); }
40 bool hasNext() const { return Current < (Iterations * Sequence.size()); }
41 void updateNext() { ++Current; }
43 SourceRef peekNext() const {
44 assert(hasNext() && "Already at end of sequence!");
45 return SourceRef(Current, *Sequence[Current % Sequence.size()]);
48 using const_iterator = ArrayRef<UniqueInst>::const_iterator;
49 const_iterator begin() const { return Sequence.begin(); }
50 const_iterator end() const { return Sequence.end(); }
56 #endif // LLVM_MCA_SOURCEMGR_H