1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-21 03:53:04 +02:00
llvm-mirror/tools/llvm-mca/SourceMgr.h
Matt Davis 3e43e69679 [llvm-mca] Avoid exposing index values in the MCA interfaces.
Summary:
This patch eliminates many places where we originally needed to  pass index
values to represent an instruction.  The index is still used as a key, in various parts of 
MCA.  I'm  not comfortable eliminating the index just yet.    By burying the index in
the instruction, we can avoid exposing that value in many places.

Eventually, we should consider removing the Instructions list in the Backend 
all together,   it's only used to hold and reclaim the memory for the allocated 
Instruction instances.  Instead we could pass around a smart pointer.  But that's
a separate discussion/patch.

Reviewers: andreadb, courbet, RKSimon

Reviewed By: andreadb

Subscribers: javed.absar, tschuett, gbedwell, llvm-commits

Differential Revision: https://reviews.llvm.org/D46367

llvm-svn: 331660
2018-05-07 18:29:15 +00:00

64 lines
2.0 KiB
C++

//===--------------------- SourceMgr.h --------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
/// \file
/// This file implements class SourceMgr. Class SourceMgr abstracts the input
/// code sequence (a sequence of MCInst), and assings unique identifiers to
/// every instruction in the sequence.
///
//===----------------------------------------------------------------------===//
#ifndef LLVM_TOOLS_LLVM_MCA_SOURCEMGR_H
#define LLVM_TOOLS_LLVM_MCA_SOURCEMGR_H
#include "llvm/MC/MCInst.h"
#include <vector>
namespace mca {
typedef std::pair<unsigned, const llvm::MCInst *> SourceRef;
class SourceMgr {
using InstVec = std::vector<std::unique_ptr<const llvm::MCInst>>;
const InstVec &Sequence;
unsigned Current;
unsigned Iterations;
static const unsigned DefaultIterations = 100;
public:
SourceMgr(const InstVec &MCInstSequence, unsigned NumIterations)
: 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(); }
const InstVec &getSequence() const { return Sequence; }
bool hasNext() { return Current < (Iterations * size()); }
void updateNext() { Current++; }
const SourceRef peekNext() const {
unsigned Index = getCurrentInstructionIndex();
return SourceRef(Current, Sequence[Index].get());
}
unsigned getCurrentInstructionIndex() const {
return Current % Sequence.size();
}
const llvm::MCInst &getMCInstFromIndex(unsigned Index) const {
return *Sequence[Index % size()];
}
bool isEmpty() const { return size() == 0; }
};
} // namespace mca
#endif