From 271ce76352fdef802e6ecea7d1a9bb595963b609 Mon Sep 17 00:00:00 2001 From: Matt Davis Date: Mon, 27 Aug 2018 17:16:32 +0000 Subject: [llvm-mca] Introduce the llvm-mca library and organize the directory accordingly. NFC. 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 --- llvm/tools/llvm-mca/lib/Context.cpp | 65 +++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 llvm/tools/llvm-mca/lib/Context.cpp (limited to 'llvm/tools/llvm-mca/lib/Context.cpp') diff --git a/llvm/tools/llvm-mca/lib/Context.cpp b/llvm/tools/llvm-mca/lib/Context.cpp new file mode 100644 index 00000000000..31c09dce912 --- /dev/null +++ b/llvm/tools/llvm-mca/lib/Context.cpp @@ -0,0 +1,65 @@ +//===---------------------------- Context.cpp -------------------*- 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 defines a class for holding ownership of various simulated +/// hardware units. A Context also provides a utility routine for constructing +/// a default out-of-order pipeline with fetch, dispatch, execute, and retire +/// stages. +/// +//===----------------------------------------------------------------------===// + +#include "Context.h" +#include "HardwareUnits/RegisterFile.h" +#include "HardwareUnits/RetireControlUnit.h" +#include "HardwareUnits/Scheduler.h" +#include "Stages/DispatchStage.h" +#include "Stages/ExecuteStage.h" +#include "Stages/FetchStage.h" +#include "Stages/RetireStage.h" + +namespace mca { + +using namespace llvm; + +std::unique_ptr +Context::createDefaultPipeline(const PipelineOptions &Opts, InstrBuilder &IB, + SourceMgr &SrcMgr) { + const MCSchedModel &SM = STI.getSchedModel(); + + // Create the hardware units defining the backend. + auto RCU = llvm::make_unique(SM); + auto PRF = llvm::make_unique(SM, MRI, Opts.RegisterFileSize); + auto LSU = llvm::make_unique(Opts.LoadQueueSize, Opts.StoreQueueSize, + Opts.AssumeNoAlias); + auto HWS = llvm::make_unique(SM, LSU.get()); + + // Create the pipeline and its stages. + auto StagePipeline = llvm::make_unique(); + auto Fetch = llvm::make_unique(IB, SrcMgr); + auto Dispatch = llvm::make_unique( + STI, MRI, Opts.RegisterFileSize, Opts.DispatchWidth, *RCU, *PRF); + auto Execute = llvm::make_unique(*HWS); + auto Retire = llvm::make_unique(*RCU, *PRF); + + // Pass the ownership of all the hardware units to this Context. + addHardwareUnit(std::move(RCU)); + addHardwareUnit(std::move(PRF)); + addHardwareUnit(std::move(LSU)); + addHardwareUnit(std::move(HWS)); + + // Build the pipeline. + StagePipeline->appendStage(std::move(Fetch)); + StagePipeline->appendStage(std::move(Dispatch)); + StagePipeline->appendStage(std::move(Execute)); + StagePipeline->appendStage(std::move(Retire)); + return StagePipeline; +} + +} // namespace mca -- cgit v1.2.3