LLVM  14.0.0git
SourceMgr.h
Go to the documentation of this file.
1 //===--------------------- SourceMgr.h --------------------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 /// \file
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.
12 ///
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_MCA_SOURCEMGR_H
16 #define LLVM_MCA_SOURCEMGR_H
17 
18 #include "llvm/ADT/ArrayRef.h"
19 #include "llvm/MCA/Instruction.h"
20 
21 namespace llvm {
22 namespace mca {
23 
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;
27 
28 class SourceMgr {
29  using UniqueInst = std::unique_ptr<Instruction>;
30  ArrayRef<UniqueInst> Sequence;
31  unsigned Current;
32  const unsigned Iterations;
33  static const unsigned DefaultIterations = 100;
34 
35 public:
37  : Sequence(S), Current(0), Iterations(Iter ? Iter : DefaultIterations) {}
38 
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; }
43 
44  SourceRef peekNext() const {
45  assert(hasNext() && "Already at end of sequence!");
46  return SourceRef(Current, *Sequence[Current % Sequence.size()]);
47  }
48 
50  const_iterator begin() const { return Sequence.begin(); }
51  const_iterator end() const { return Sequence.end(); }
52 };
53 
54 } // namespace mca
55 } // namespace llvm
56 
57 #endif // LLVM_MCA_SOURCEMGR_H
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::mca::SourceMgr::getNumIterations
unsigned getNumIterations() const
Definition: SourceMgr.h:39
llvm::mca::SourceMgr::size
unsigned size() const
Definition: SourceMgr.h:40
llvm::mca::SourceMgr::end
const_iterator end() const
Definition: SourceMgr.h:51
Instruction.h
llvm::mca::SourceMgr::const_iterator
ArrayRef< UniqueInst >::const_iterator const_iterator
Definition: SourceMgr.h:49
llvm::mca::SourceMgr::peekNext
SourceRef peekNext() const
Definition: SourceMgr.h:44
llvm::mca::SourceMgr::hasNext
bool hasNext() const
Definition: SourceMgr.h:41
ArrayRef.h
llvm::mca::SourceMgr::begin
const_iterator begin() const
Definition: SourceMgr.h:50
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::ArrayRef< UniqueInst >
llvm::mca::SourceMgr::SourceMgr
SourceMgr(ArrayRef< UniqueInst > S, unsigned Iter)
Definition: SourceMgr.h:36
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::mca::SourceMgr
Definition: SourceMgr.h:28
llvm::mca::SourceRef
std::pair< unsigned, const Instruction & > SourceRef
Definition: SourceMgr.h:26
llvm::mca::SourceMgr::updateNext
void updateNext()
Definition: SourceMgr.h:42