[llvm-mca] Refactor class SourceMgr. NFCI
Added begin()/end() methods to allow the usage of SourceMgr in foreach loops.
With this change, method getMCInstFromIndex() (as well as a couple of other
methods) are now redundant, and can be removed from the public interface.
llvm-svn: 345147
diff --git a/llvm/tools/llvm-mca/include/SourceMgr.h b/llvm/tools/llvm-mca/include/SourceMgr.h
index 8941283..e7cd358 100644
--- a/llvm/tools/llvm-mca/include/SourceMgr.h
+++ b/llvm/tools/llvm-mca/include/SourceMgr.h
@@ -27,7 +27,7 @@
class SourceMgr {
llvm::ArrayRef<llvm::MCInst> Sequence;
unsigned Current;
- unsigned Iterations;
+ const unsigned Iterations;
static const unsigned DefaultIterations = 100;
public:
@@ -35,27 +35,19 @@
: Sequence(MCInstSequence), Current(0),
Iterations(NumIterations ? NumIterations : DefaultIterations) {}
- unsigned getCurrentIteration() const { return Current / Sequence.size(); }
unsigned getNumIterations() const { return Iterations; }
unsigned size() const { return Sequence.size(); }
- llvm::ArrayRef<llvm::MCInst> getSequence() const { return Sequence; }
-
- bool hasNext() const { return Current < (Iterations * size()); }
- void updateNext() { Current++; }
+ bool hasNext() const { return Current < (Iterations * Sequence.size()); }
+ void updateNext() { ++Current; }
const SourceRef peekNext() const {
assert(hasNext() && "Already at end of sequence!");
- unsigned Index = getCurrentInstructionIndex();
- return SourceRef(Current, Sequence[Index]);
+ return SourceRef(Current, Sequence[Current % Sequence.size()]);
}
- unsigned getCurrentInstructionIndex() const {
- return Current % Sequence.size();
- }
-
- const llvm::MCInst &getMCInstFromIndex(unsigned Index) const {
- return Sequence[Index % size()];
- }
+ using const_iterator = llvm::ArrayRef<llvm::MCInst>::const_iterator;
+ const_iterator begin() const { return Sequence.begin(); }
+ const_iterator end() const { return Sequence.end(); }
bool isEmpty() const { return size() == 0; }
};