blob: c1b197dfe2e6744fc53e2c9b05283e7da9406083 [file] [log] [blame]
Matt Davis73b3f8b2018-07-06 18:03:14 +00001//===---------------------------- Context.cpp -------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9/// \file
10///
11/// This file defines a class for holding ownership of various simulated
12/// hardware units. A Context also provides a utility routine for constructing
13/// a default out-of-order pipeline with fetch, dispatch, execute, and retire
Matt Davis9dc624a2018-08-22 18:03:58 +000014/// stages.
Matt Davis73b3f8b2018-07-06 18:03:14 +000015///
16//===----------------------------------------------------------------------===//
17
Clement Courbet8178ac82018-12-17 08:08:31 +000018#include "llvm/MCA/Context.h"
19#include "llvm/MCA/HardwareUnits/RegisterFile.h"
20#include "llvm/MCA/HardwareUnits/RetireControlUnit.h"
21#include "llvm/MCA/HardwareUnits/Scheduler.h"
22#include "llvm/MCA/Stages/DispatchStage.h"
23#include "llvm/MCA/Stages/EntryStage.h"
24#include "llvm/MCA/Stages/ExecuteStage.h"
25#include "llvm/MCA/Stages/RetireStage.h"
Matt Davis73b3f8b2018-07-06 18:03:14 +000026
Fangrui Song467c3072018-10-30 15:56:08 +000027namespace llvm {
Matt Davis73b3f8b2018-07-06 18:03:14 +000028namespace mca {
29
Matt Davis73b3f8b2018-07-06 18:03:14 +000030std::unique_ptr<Pipeline>
31Context::createDefaultPipeline(const PipelineOptions &Opts, InstrBuilder &IB,
32 SourceMgr &SrcMgr) {
33 const MCSchedModel &SM = STI.getSchedModel();
34
35 // Create the hardware units defining the backend.
36 auto RCU = llvm::make_unique<RetireControlUnit>(SM);
37 auto PRF = llvm::make_unique<RegisterFile>(SM, MRI, Opts.RegisterFileSize);
Andrea Di Biagio51af6fd2018-11-29 12:15:56 +000038 auto LSU = llvm::make_unique<LSUnit>(SM, Opts.LoadQueueSize,
39 Opts.StoreQueueSize, Opts.AssumeNoAlias);
Andrea Di Biagio87b02fc2018-11-30 12:49:30 +000040 auto HWS = llvm::make_unique<Scheduler>(SM, *LSU);
Matt Davis73b3f8b2018-07-06 18:03:14 +000041
Matt Davis7fdf8ca2018-08-29 00:34:32 +000042 // Create the pipeline stages.
Andrea Di Biagiob6654872018-11-08 17:49:30 +000043 auto Fetch = llvm::make_unique<EntryStage>(SrcMgr);
Matt Davis3b3d4832018-08-29 00:41:04 +000044 auto Dispatch = llvm::make_unique<DispatchStage>(STI, MRI, Opts.DispatchWidth,
45 *RCU, *PRF);
Andrea Di Biagio8744f362018-08-16 19:00:48 +000046 auto Execute = llvm::make_unique<ExecuteStage>(*HWS);
47 auto Retire = llvm::make_unique<RetireStage>(*RCU, *PRF);
Matt Davis73b3f8b2018-07-06 18:03:14 +000048
Andrea Di Biagio681bdae2018-08-20 14:41:36 +000049 // Pass the ownership of all the hardware units to this Context.
Matt Davis73b3f8b2018-07-06 18:03:14 +000050 addHardwareUnit(std::move(RCU));
51 addHardwareUnit(std::move(PRF));
Andrea Di Biagio681bdae2018-08-20 14:41:36 +000052 addHardwareUnit(std::move(LSU));
Matt Davis73b3f8b2018-07-06 18:03:14 +000053 addHardwareUnit(std::move(HWS));
54
55 // Build the pipeline.
Matt Davis7fdf8ca2018-08-29 00:34:32 +000056 auto StagePipeline = llvm::make_unique<Pipeline>();
Andrea Di Biagio8744f362018-08-16 19:00:48 +000057 StagePipeline->appendStage(std::move(Fetch));
58 StagePipeline->appendStage(std::move(Dispatch));
59 StagePipeline->appendStage(std::move(Execute));
60 StagePipeline->appendStage(std::move(Retire));
61 return StagePipeline;
Matt Davis73b3f8b2018-07-06 18:03:14 +000062}
63
64} // namespace mca
Fangrui Song467c3072018-10-30 15:56:08 +000065} // namespace llvm