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