Path: blob/main/contrib/llvm-project/llvm/lib/MCA/Context.cpp
35260 views
//===---------------------------- Context.cpp -------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7/// \file8///9/// This file defines a class for holding ownership of various simulated10/// hardware units. A Context also provides a utility routine for constructing11/// a default out-of-order pipeline with fetch, dispatch, execute, and retire12/// stages.13///14//===----------------------------------------------------------------------===//1516#include "llvm/MCA/Context.h"17#include "llvm/MCA/HardwareUnits/RegisterFile.h"18#include "llvm/MCA/HardwareUnits/RetireControlUnit.h"19#include "llvm/MCA/HardwareUnits/Scheduler.h"20#include "llvm/MCA/Stages/DispatchStage.h"21#include "llvm/MCA/Stages/EntryStage.h"22#include "llvm/MCA/Stages/ExecuteStage.h"23#include "llvm/MCA/Stages/InOrderIssueStage.h"24#include "llvm/MCA/Stages/MicroOpQueueStage.h"25#include "llvm/MCA/Stages/RetireStage.h"2627namespace llvm {28namespace mca {2930std::unique_ptr<Pipeline>31Context::createDefaultPipeline(const PipelineOptions &Opts, SourceMgr &SrcMgr,32CustomBehaviour &CB) {33const MCSchedModel &SM = STI.getSchedModel();3435if (!SM.isOutOfOrder())36return createInOrderPipeline(Opts, SrcMgr, CB);3738// Create the hardware units defining the backend.39auto RCU = std::make_unique<RetireControlUnit>(SM);40auto PRF = std::make_unique<RegisterFile>(SM, MRI, Opts.RegisterFileSize);41auto LSU = std::make_unique<LSUnit>(SM, Opts.LoadQueueSize,42Opts.StoreQueueSize, Opts.AssumeNoAlias);43auto HWS = std::make_unique<Scheduler>(SM, *LSU);4445// Create the pipeline stages.46auto Fetch = std::make_unique<EntryStage>(SrcMgr);47auto Dispatch =48std::make_unique<DispatchStage>(STI, MRI, Opts.DispatchWidth, *RCU, *PRF);49auto Execute =50std::make_unique<ExecuteStage>(*HWS, Opts.EnableBottleneckAnalysis);51auto Retire = std::make_unique<RetireStage>(*RCU, *PRF, *LSU);5253// Pass the ownership of all the hardware units to this Context.54addHardwareUnit(std::move(RCU));55addHardwareUnit(std::move(PRF));56addHardwareUnit(std::move(LSU));57addHardwareUnit(std::move(HWS));5859// Build the pipeline.60auto StagePipeline = std::make_unique<Pipeline>();61StagePipeline->appendStage(std::move(Fetch));62if (Opts.MicroOpQueueSize)63StagePipeline->appendStage(std::make_unique<MicroOpQueueStage>(64Opts.MicroOpQueueSize, Opts.DecodersThroughput));65StagePipeline->appendStage(std::move(Dispatch));66StagePipeline->appendStage(std::move(Execute));67StagePipeline->appendStage(std::move(Retire));68return StagePipeline;69}7071std::unique_ptr<Pipeline>72Context::createInOrderPipeline(const PipelineOptions &Opts, SourceMgr &SrcMgr,73CustomBehaviour &CB) {74const MCSchedModel &SM = STI.getSchedModel();75auto PRF = std::make_unique<RegisterFile>(SM, MRI, Opts.RegisterFileSize);76auto LSU = std::make_unique<LSUnit>(SM, Opts.LoadQueueSize,77Opts.StoreQueueSize, Opts.AssumeNoAlias);7879// Create the pipeline stages.80auto Entry = std::make_unique<EntryStage>(SrcMgr);81auto InOrderIssue = std::make_unique<InOrderIssueStage>(STI, *PRF, CB, *LSU);82auto StagePipeline = std::make_unique<Pipeline>();8384// Pass the ownership of all the hardware units to this Context.85addHardwareUnit(std::move(PRF));86addHardwareUnit(std::move(LSU));8788// Build the pipeline.89StagePipeline->appendStage(std::move(Entry));90StagePipeline->appendStage(std::move(InOrderIssue));91return StagePipeline;92}9394} // namespace mca95} // namespace llvm969798