1 //===--------------------- SourceMgr.h --------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
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.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_MCA_SOURCEMGR_H
16 #define LLVM_MCA_SOURCEMGR_H
18 #include "llvm/ADT/ArrayRef.h"
19 #include "llvm/MCA/Instruction.h"
24 // MSVC >= 19.15, < 19.20 need to see the definition of class Instruction to
25 // prevent compiler error C2139 about intrinsic type trait '__is_assignable'.
26 typedef std::pair
<unsigned, const Instruction
&> SourceRef
;
29 using UniqueInst
= std::unique_ptr
<Instruction
>;
30 ArrayRef
<UniqueInst
> Sequence
;
32 const unsigned Iterations
;
33 static const unsigned DefaultIterations
= 100;
36 SourceMgr(ArrayRef
<UniqueInst
> S
, unsigned Iter
)
37 : Sequence(S
), Current(0), Iterations(Iter
? Iter
: DefaultIterations
) {}
39 unsigned getNumIterations() const { return Iterations
; }
40 unsigned size() const { return Sequence
.size(); }
41 bool hasNext() const { return Current
< (Iterations
* Sequence
.size()); }
42 void updateNext() { ++Current
; }
44 SourceRef
peekNext() const {
45 assert(hasNext() && "Already at end of sequence!");
46 return SourceRef(Current
, *Sequence
[Current
% Sequence
.size()]);
49 using const_iterator
= ArrayRef
<UniqueInst
>::const_iterator
;
50 const_iterator
begin() const { return Sequence
.begin(); }
51 const_iterator
end() const { return Sequence
.end(); }
57 #endif // LLVM_MCA_SOURCEMGR_H