Revert r354244 "[DAGCombiner] Eliminate dead stores to stack."
[llvm-complete.git] / include / llvm / MCA / SourceMgr.h
blobdbe31db1b1ddbd97c41c6178729daa245ba5a359
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 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.
12 ///
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_MCA_SOURCEMGR_H
16 #define LLVM_MCA_SOURCEMGR_H
18 #include "llvm/ADT/ArrayRef.h"
20 namespace llvm {
21 namespace mca {
23 class Instruction;
25 typedef std::pair<unsigned, const Instruction &> SourceRef;
27 class SourceMgr {
28 using UniqueInst = std::unique_ptr<Instruction>;
29 ArrayRef<UniqueInst> Sequence;
30 unsigned Current;
31 const unsigned Iterations;
32 static const unsigned DefaultIterations = 100;
34 public:
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(); }
53 } // namespace mca
54 } // namespace llvm
56 #endif // LLVM_MCA_SOURCEMGR_H