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 | #include "llvm/MC/MCInst.h" |
| 21 | #include <vector> |
| 22 | |
| 23 | namespace mca { |
| 24 | |
Andrea Di Biagio | 01b9fd6 | 2018-10-22 15:36:15 +0000 | [diff] [blame] | 25 | typedef std::pair<unsigned, const llvm::MCInst &> SourceRef; |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 26 | |
| 27 | class SourceMgr { |
Andrea Di Biagio | 01b9fd6 | 2018-10-22 15:36:15 +0000 | [diff] [blame] | 28 | llvm::ArrayRef<llvm::MCInst> Sequence; |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 29 | unsigned Current; |
Andrea Di Biagio | 7be45b0f | 2018-10-24 15:06:27 +0000 | [diff] [blame] | 30 | const unsigned Iterations; |
Andrea Di Biagio | 074cef3 | 2018-04-10 12:50:03 +0000 | [diff] [blame] | 31 | static const unsigned DefaultIterations = 100; |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 32 | |
| 33 | public: |
Andrea Di Biagio | 01b9fd6 | 2018-10-22 15:36:15 +0000 | [diff] [blame] | 34 | SourceMgr(llvm::ArrayRef<llvm::MCInst> MCInstSequence, unsigned NumIterations) |
Andrea Di Biagio | c659012 | 2018-04-09 16:39:52 +0000 | [diff] [blame] | 35 | : Sequence(MCInstSequence), Current(0), |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 36 | Iterations(NumIterations ? NumIterations : DefaultIterations) {} |
| 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 | |
Matt Davis | 21a8d32 | 2018-05-07 18:29:15 +0000 | [diff] [blame] | 43 | const 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 | 7be45b0f | 2018-10-24 15:06:27 +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 | 7be45b0f | 2018-10-24 15:06:27 +0000 | [diff] [blame] | 48 | using const_iterator = llvm::ArrayRef<llvm::MCInst>::const_iterator; |
| 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 |