1 //===--------------------- SourceMgr.h --------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 /// This file implements class SourceMgr. Class SourceMgr abstracts the input
11 /// code sequence (a sequence of MCInst), and assings unique identifiers to
12 /// every instruction in the sequence.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_TOOLS_LLVM_MCA_SOURCEMGR_H
17 #define LLVM_TOOLS_LLVM_MCA_SOURCEMGR_H
19 #include "llvm/MC/MCInst.h"
24 typedef std::pair<unsigned, const llvm::MCInst *> InstRef;
27 using InstVec = std::vector<std::unique_ptr<const llvm::MCInst>>;
28 const InstVec &Sequence;
31 static const unsigned DefaultIterations = 100;
34 SourceMgr(const InstVec &MCInstSequence, unsigned NumIterations)
35 : Sequence(MCInstSequence), Current(0),
36 Iterations(NumIterations ? NumIterations : DefaultIterations) {}
38 unsigned getCurrentIteration() const { return Current / Sequence.size(); }
39 unsigned getNumIterations() const { return Iterations; }
40 unsigned size() const { return Sequence.size(); }
41 const InstVec &getSequence() const { return Sequence; }
43 bool hasNext() { return Current < (Iterations * size()); }
44 void updateNext() { Current++; }
46 const InstRef peekNext() const {
47 unsigned Index = getCurrentInstructionIndex();
48 return InstRef(Current, Sequence[Index].get());
51 unsigned getCurrentInstructionIndex() const {
52 return Current % Sequence.size();
55 const llvm::MCInst &getMCInstFromIndex(unsigned Index) const {
56 return *Sequence[Index % size()];
59 bool isEmpty() const { return size() == 0; }