llvm-project
96 строк · 3.8 Кб
1//===---------------------------- Context.cpp -------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8/// \file
9///
10/// This file defines a class for holding ownership of various simulated
11/// hardware units. A Context also provides a utility routine for constructing
12/// a default out-of-order pipeline with fetch, dispatch, execute, and retire
13/// stages.
14///
15//===----------------------------------------------------------------------===//
16
17#include "llvm/MCA/Context.h"18#include "llvm/MCA/HardwareUnits/RegisterFile.h"19#include "llvm/MCA/HardwareUnits/RetireControlUnit.h"20#include "llvm/MCA/HardwareUnits/Scheduler.h"21#include "llvm/MCA/Stages/DispatchStage.h"22#include "llvm/MCA/Stages/EntryStage.h"23#include "llvm/MCA/Stages/ExecuteStage.h"24#include "llvm/MCA/Stages/InOrderIssueStage.h"25#include "llvm/MCA/Stages/MicroOpQueueStage.h"26#include "llvm/MCA/Stages/RetireStage.h"27
28namespace llvm {29namespace mca {30
31std::unique_ptr<Pipeline>32Context::createDefaultPipeline(const PipelineOptions &Opts, SourceMgr &SrcMgr,33CustomBehaviour &CB) {34const MCSchedModel &SM = STI.getSchedModel();35
36if (!SM.isOutOfOrder())37return createInOrderPipeline(Opts, SrcMgr, CB);38
39// Create the hardware units defining the backend.40auto RCU = std::make_unique<RetireControlUnit>(SM);41auto PRF = std::make_unique<RegisterFile>(SM, MRI, Opts.RegisterFileSize);42auto LSU = std::make_unique<LSUnit>(SM, Opts.LoadQueueSize,43Opts.StoreQueueSize, Opts.AssumeNoAlias);44auto HWS = std::make_unique<Scheduler>(SM, *LSU);45
46// Create the pipeline stages.47auto Fetch = std::make_unique<EntryStage>(SrcMgr);48auto Dispatch =49std::make_unique<DispatchStage>(STI, MRI, Opts.DispatchWidth, *RCU, *PRF);50auto Execute =51std::make_unique<ExecuteStage>(*HWS, Opts.EnableBottleneckAnalysis);52auto Retire = std::make_unique<RetireStage>(*RCU, *PRF, *LSU);53
54// Pass the ownership of all the hardware units to this Context.55addHardwareUnit(std::move(RCU));56addHardwareUnit(std::move(PRF));57addHardwareUnit(std::move(LSU));58addHardwareUnit(std::move(HWS));59
60// Build the pipeline.61auto StagePipeline = std::make_unique<Pipeline>();62StagePipeline->appendStage(std::move(Fetch));63if (Opts.MicroOpQueueSize)64StagePipeline->appendStage(std::make_unique<MicroOpQueueStage>(65Opts.MicroOpQueueSize, Opts.DecodersThroughput));66StagePipeline->appendStage(std::move(Dispatch));67StagePipeline->appendStage(std::move(Execute));68StagePipeline->appendStage(std::move(Retire));69return StagePipeline;70}
71
72std::unique_ptr<Pipeline>73Context::createInOrderPipeline(const PipelineOptions &Opts, SourceMgr &SrcMgr,74CustomBehaviour &CB) {75const MCSchedModel &SM = STI.getSchedModel();76auto PRF = std::make_unique<RegisterFile>(SM, MRI, Opts.RegisterFileSize);77auto LSU = std::make_unique<LSUnit>(SM, Opts.LoadQueueSize,78Opts.StoreQueueSize, Opts.AssumeNoAlias);79
80// Create the pipeline stages.81auto Entry = std::make_unique<EntryStage>(SrcMgr);82auto InOrderIssue = std::make_unique<InOrderIssueStage>(STI, *PRF, CB, *LSU);83auto StagePipeline = std::make_unique<Pipeline>();84
85// Pass the ownership of all the hardware units to this Context.86addHardwareUnit(std::move(PRF));87addHardwareUnit(std::move(LSU));88
89// Build the pipeline.90StagePipeline->appendStage(std::move(Entry));91StagePipeline->appendStage(std::move(InOrderIssue));92return StagePipeline;93}
94
95} // namespace mca96} // namespace llvm97