Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 1 | //===--------------------- 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 Biagio | 01b9fd6 | 2018-10-22 15:36:15 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/ArrayRef.h" |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 20 | |
| 21 | namespace mca { |
| 22 | |
Andrea Di Biagio | df4d65d | 2018-10-29 13:29:22 +0000 | [diff] [blame^] | 23 | class Instruction; |
| 24 | |
| 25 | typedef std::pair<unsigned, const Instruction &> SourceRef; |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 26 | |
| 27 | class SourceMgr { |
Andrea Di Biagio | df4d65d | 2018-10-29 13:29:22 +0000 | [diff] [blame^] | 28 | using UniqueInst = std::unique_ptr<Instruction>; |
| 29 | llvm::ArrayRef<UniqueInst> Sequence; |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 30 | unsigned Current; |
Andrea Di Biagio | 7be45b0f | 2018-10-24 15:06:27 +0000 | [diff] [blame] | 31 | const unsigned Iterations; |
Andrea Di Biagio | 074cef3 | 2018-04-10 12:50:03 +0000 | [diff] [blame] | 32 | static const unsigned DefaultIterations = 100; |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 33 | |
| 34 | public: |
Andrea Di Biagio | df4d65d | 2018-10-29 13:29:22 +0000 | [diff] [blame^] | 35 | SourceMgr(llvm::ArrayRef<UniqueInst> S, unsigned Iter) |
| 36 | : Sequence(S), Current(0), Iterations(Iter ? Iter : DefaultIterations) {} |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 37 | |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 38 | unsigned getNumIterations() const { return Iterations; } |
| 39 | unsigned size() const { return Sequence.size(); } |
Andrea Di Biagio | 7be45b0f | 2018-10-24 15:06:27 +0000 | [diff] [blame] | 40 | bool hasNext() const { return Current < (Iterations * Sequence.size()); } |
| 41 | void updateNext() { ++Current; } |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 42 | |
Andrea Di Biagio | df4d65d | 2018-10-29 13:29:22 +0000 | [diff] [blame^] | 43 | SourceRef peekNext() const { |
Andrea Di Biagio | 492816d | 2018-08-16 15:43:09 +0000 | [diff] [blame] | 44 | assert(hasNext() && "Already at end of sequence!"); |
Andrea Di Biagio | df4d65d | 2018-10-29 13:29:22 +0000 | [diff] [blame^] | 45 | return SourceRef(Current, *Sequence[Current % Sequence.size()]); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 46 | } |
| 47 | |
Andrea Di Biagio | df4d65d | 2018-10-29 13:29:22 +0000 | [diff] [blame^] | 48 | using const_iterator = llvm::ArrayRef<UniqueInst>::const_iterator; |
Andrea Di Biagio | 7be45b0f | 2018-10-24 15:06:27 +0000 | [diff] [blame] | 49 | const_iterator begin() const { return Sequence.begin(); } |
| 50 | const_iterator end() const { return Sequence.end(); } |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 51 | }; |
Andrea Di Biagio | 84d0051 | 2018-10-26 10:48:04 +0000 | [diff] [blame] | 52 | |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 53 | } // namespace mca |
| 54 | |
| 55 | #endif |