xref: /freebsd/contrib/llvm-project/llvm/lib/MCA/Context.cpp (revision 8bcb0991864975618c09697b1aca10683346d9f0)
10b57cec5SDimitry Andric //===---------------------------- Context.cpp -------------------*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric /// \file
90b57cec5SDimitry Andric ///
100b57cec5SDimitry Andric /// This file defines a class for holding ownership of various simulated
110b57cec5SDimitry Andric /// hardware units.  A Context also provides a utility routine for constructing
120b57cec5SDimitry Andric /// a default out-of-order pipeline with fetch, dispatch, execute, and retire
130b57cec5SDimitry Andric /// stages.
140b57cec5SDimitry Andric ///
150b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
160b57cec5SDimitry Andric 
170b57cec5SDimitry Andric #include "llvm/MCA/Context.h"
180b57cec5SDimitry Andric #include "llvm/MCA/HardwareUnits/RegisterFile.h"
190b57cec5SDimitry Andric #include "llvm/MCA/HardwareUnits/RetireControlUnit.h"
200b57cec5SDimitry Andric #include "llvm/MCA/HardwareUnits/Scheduler.h"
210b57cec5SDimitry Andric #include "llvm/MCA/Stages/DispatchStage.h"
220b57cec5SDimitry Andric #include "llvm/MCA/Stages/EntryStage.h"
230b57cec5SDimitry Andric #include "llvm/MCA/Stages/ExecuteStage.h"
240b57cec5SDimitry Andric #include "llvm/MCA/Stages/MicroOpQueueStage.h"
250b57cec5SDimitry Andric #include "llvm/MCA/Stages/RetireStage.h"
260b57cec5SDimitry Andric 
270b57cec5SDimitry Andric namespace llvm {
280b57cec5SDimitry Andric namespace mca {
290b57cec5SDimitry Andric 
300b57cec5SDimitry Andric std::unique_ptr<Pipeline>
31*8bcb0991SDimitry Andric Context::createDefaultPipeline(const PipelineOptions &Opts, SourceMgr &SrcMgr) {
320b57cec5SDimitry Andric   const MCSchedModel &SM = STI.getSchedModel();
330b57cec5SDimitry Andric 
340b57cec5SDimitry Andric   // Create the hardware units defining the backend.
35*8bcb0991SDimitry Andric   auto RCU = std::make_unique<RetireControlUnit>(SM);
36*8bcb0991SDimitry Andric   auto PRF = std::make_unique<RegisterFile>(SM, MRI, Opts.RegisterFileSize);
37*8bcb0991SDimitry Andric   auto LSU = std::make_unique<LSUnit>(SM, Opts.LoadQueueSize,
380b57cec5SDimitry Andric                                        Opts.StoreQueueSize, Opts.AssumeNoAlias);
39*8bcb0991SDimitry Andric   auto HWS = std::make_unique<Scheduler>(SM, *LSU);
400b57cec5SDimitry Andric 
410b57cec5SDimitry Andric   // Create the pipeline stages.
42*8bcb0991SDimitry Andric   auto Fetch = std::make_unique<EntryStage>(SrcMgr);
43*8bcb0991SDimitry Andric   auto Dispatch = std::make_unique<DispatchStage>(STI, MRI, Opts.DispatchWidth,
440b57cec5SDimitry Andric                                                    *RCU, *PRF);
450b57cec5SDimitry Andric   auto Execute =
46*8bcb0991SDimitry Andric       std::make_unique<ExecuteStage>(*HWS, Opts.EnableBottleneckAnalysis);
47*8bcb0991SDimitry Andric   auto Retire = std::make_unique<RetireStage>(*RCU, *PRF, *LSU);
480b57cec5SDimitry Andric 
490b57cec5SDimitry Andric   // Pass the ownership of all the hardware units to this Context.
500b57cec5SDimitry Andric   addHardwareUnit(std::move(RCU));
510b57cec5SDimitry Andric   addHardwareUnit(std::move(PRF));
520b57cec5SDimitry Andric   addHardwareUnit(std::move(LSU));
530b57cec5SDimitry Andric   addHardwareUnit(std::move(HWS));
540b57cec5SDimitry Andric 
550b57cec5SDimitry Andric   // Build the pipeline.
56*8bcb0991SDimitry Andric   auto StagePipeline = std::make_unique<Pipeline>();
570b57cec5SDimitry Andric   StagePipeline->appendStage(std::move(Fetch));
580b57cec5SDimitry Andric   if (Opts.MicroOpQueueSize)
59*8bcb0991SDimitry Andric     StagePipeline->appendStage(std::make_unique<MicroOpQueueStage>(
600b57cec5SDimitry Andric         Opts.MicroOpQueueSize, Opts.DecodersThroughput));
610b57cec5SDimitry Andric   StagePipeline->appendStage(std::move(Dispatch));
620b57cec5SDimitry Andric   StagePipeline->appendStage(std::move(Execute));
630b57cec5SDimitry Andric   StagePipeline->appendStage(std::move(Retire));
640b57cec5SDimitry Andric   return StagePipeline;
650b57cec5SDimitry Andric }
660b57cec5SDimitry Andric 
670b57cec5SDimitry Andric } // namespace mca
680b57cec5SDimitry Andric } // namespace llvm
69