Summary:
This patch introduces llvm-mca as a library. The driver (llvm-mca.cpp), views, and stats, are not part of the library.
Those are separate components that are not required for the functioning of llvm-mca.
The directory has been organized as follows:
All library source files now reside in:
- `lib/HardwareUnits/` - All subclasses of HardwareUnit (these represent the simulated hardware components of a backend).
(LSUnit does not inherit from HardwareUnit, but Scheduler does which uses LSUnit).
- `lib/Stages/` - All subclasses of the pipeline stages.
- `lib/` - This is the root of the library and contains library code that does not fit into the Stages or HardwareUnit subdirs.
All library header files now reside in the `include` directory and mimic the same layout as the `lib` directory mentioned above.
In the (near) future we would like to move the library (include and lib) contents from tools and into the core of llvm somewhere.
That change would allow various analysis and optimization passes to make use of MCA functionality for things like cost modeling.
I left all of the non-library code just where it has always been, in the root of the llvm-mca directory.
The include directives for the non-library source file have been updated to refer to the llvm-mca library headers.
I updated the llvm-mca/CMakeLists.txt file to include the library headers, but I made the non-library code
explicitly reference the library's 'include' directory. Once we eventually (hopefully) migrate the MCA library
components into llvm the include directives used by the non-library source files will be updated to point to the
proper location in llvm.
Reviewers: andreadb, courbet, RKSimon
Reviewed By: andreadb
Subscribers: mgorny, javed.absar, tschuett, gbedwell, llvm-commits
Differential Revision: https://reviews.llvm.org/D50929
llvm-svn: 340755
65 lines
2.0 KiB
C++
65 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() const { return Current < (Iterations * size()); }
|
|
void updateNext() { Current++; }
|
|
|
|
const SourceRef peekNext() const {
|
|
assert(hasNext() && "Already at end of sequence!");
|
|
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
|