blob: 54b1a2c31cef710480185b3306dbf843b594f086 [file] [log] [blame]
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +00001//===--------------------- SourceMgr.h --------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9/// \file
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.
13///
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_TOOLS_LLVM_MCA_SOURCEMGR_H
17#define LLVM_TOOLS_LLVM_MCA_SOURCEMGR_H
18
Andrea Di Biagio01b9fd62018-10-22 15:36:15 +000019#include "llvm/ADT/ArrayRef.h"
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000020
21namespace mca {
22
Andrea Di Biagiodf4d65d2018-10-29 13:29:22 +000023class Instruction;
24
25typedef std::pair<unsigned, const Instruction &> SourceRef;
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000026
27class SourceMgr {
Andrea Di Biagiodf4d65d2018-10-29 13:29:22 +000028 using UniqueInst = std::unique_ptr<Instruction>;
29 llvm::ArrayRef<UniqueInst> Sequence;
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000030 unsigned Current;
Andrea Di Biagio7be45b0f2018-10-24 15:06:27 +000031 const unsigned Iterations;
Andrea Di Biagio074cef32018-04-10 12:50:03 +000032 static const unsigned DefaultIterations = 100;
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000033
34public:
Andrea Di Biagiodf4d65d2018-10-29 13:29:22 +000035 SourceMgr(llvm::ArrayRef<UniqueInst> S, unsigned Iter)
36 : Sequence(S), Current(0), Iterations(Iter ? Iter : DefaultIterations) {}
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000037
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000038 unsigned getNumIterations() const { return Iterations; }
39 unsigned size() const { return Sequence.size(); }
Andrea Di Biagio7be45b0f2018-10-24 15:06:27 +000040 bool hasNext() const { return Current < (Iterations * Sequence.size()); }
41 void updateNext() { ++Current; }
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000042
Andrea Di Biagiodf4d65d2018-10-29 13:29:22 +000043 SourceRef peekNext() const {
Andrea Di Biagio492816d2018-08-16 15:43:09 +000044 assert(hasNext() && "Already at end of sequence!");
Andrea Di Biagiodf4d65d2018-10-29 13:29:22 +000045 return SourceRef(Current, *Sequence[Current % Sequence.size()]);
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000046 }
47
Andrea Di Biagiodf4d65d2018-10-29 13:29:22 +000048 using const_iterator = llvm::ArrayRef<UniqueInst>::const_iterator;
Andrea Di Biagio7be45b0f2018-10-24 15:06:27 +000049 const_iterator begin() const { return Sequence.begin(); }
50 const_iterator end() const { return Sequence.end(); }
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000051};
Andrea Di Biagio84d00512018-10-26 10:48:04 +000052
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000053} // namespace mca
54
55#endif