Matt Davis | 73b3f8b | 2018-07-06 18:03:14 +0000 | [diff] [blame] | 1 | //===---------------------------- 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 Davis | 9dc624a | 2018-08-22 18:03:58 +0000 | [diff] [blame] | 14 | /// stages. |
Matt Davis | 73b3f8b | 2018-07-06 18:03:14 +0000 | [diff] [blame] | 15 | /// |
| 16 | //===----------------------------------------------------------------------===// |
| 17 | |
Clement Courbet | 8178ac8 | 2018-12-17 08:08:31 +0000 | [diff] [blame] | 18 | #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 Davis | 73b3f8b | 2018-07-06 18:03:14 +0000 | [diff] [blame] | 26 | |
Fangrui Song | 467c307 | 2018-10-30 15:56:08 +0000 | [diff] [blame] | 27 | namespace llvm { |
Matt Davis | 73b3f8b | 2018-07-06 18:03:14 +0000 | [diff] [blame] | 28 | namespace mca { |
| 29 | |
Matt Davis | 73b3f8b | 2018-07-06 18:03:14 +0000 | [diff] [blame] | 30 | std::unique_ptr<Pipeline> |
| 31 | Context::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 Biagio | 51af6fd | 2018-11-29 12:15:56 +0000 | [diff] [blame] | 38 | auto LSU = llvm::make_unique<LSUnit>(SM, Opts.LoadQueueSize, |
| 39 | Opts.StoreQueueSize, Opts.AssumeNoAlias); |
Andrea Di Biagio | 87b02fc | 2018-11-30 12:49:30 +0000 | [diff] [blame] | 40 | auto HWS = llvm::make_unique<Scheduler>(SM, *LSU); |
Matt Davis | 73b3f8b | 2018-07-06 18:03:14 +0000 | [diff] [blame] | 41 | |
Matt Davis | 7fdf8ca | 2018-08-29 00:34:32 +0000 | [diff] [blame] | 42 | // Create the pipeline stages. |
Andrea Di Biagio | b665487 | 2018-11-08 17:49:30 +0000 | [diff] [blame] | 43 | auto Fetch = llvm::make_unique<EntryStage>(SrcMgr); |
Matt Davis | 3b3d483 | 2018-08-29 00:41:04 +0000 | [diff] [blame] | 44 | auto Dispatch = llvm::make_unique<DispatchStage>(STI, MRI, Opts.DispatchWidth, |
| 45 | *RCU, *PRF); |
Andrea Di Biagio | 8744f36 | 2018-08-16 19:00:48 +0000 | [diff] [blame] | 46 | auto Execute = llvm::make_unique<ExecuteStage>(*HWS); |
| 47 | auto Retire = llvm::make_unique<RetireStage>(*RCU, *PRF); |
Matt Davis | 73b3f8b | 2018-07-06 18:03:14 +0000 | [diff] [blame] | 48 | |
Andrea Di Biagio | 681bdae | 2018-08-20 14:41:36 +0000 | [diff] [blame] | 49 | // Pass the ownership of all the hardware units to this Context. |
Matt Davis | 73b3f8b | 2018-07-06 18:03:14 +0000 | [diff] [blame] | 50 | addHardwareUnit(std::move(RCU)); |
| 51 | addHardwareUnit(std::move(PRF)); |
Andrea Di Biagio | 681bdae | 2018-08-20 14:41:36 +0000 | [diff] [blame] | 52 | addHardwareUnit(std::move(LSU)); |
Matt Davis | 73b3f8b | 2018-07-06 18:03:14 +0000 | [diff] [blame] | 53 | addHardwareUnit(std::move(HWS)); |
| 54 | |
| 55 | // Build the pipeline. |
Matt Davis | 7fdf8ca | 2018-08-29 00:34:32 +0000 | [diff] [blame] | 56 | auto StagePipeline = llvm::make_unique<Pipeline>(); |
Andrea Di Biagio | 8744f36 | 2018-08-16 19:00:48 +0000 | [diff] [blame] | 57 | 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 Davis | 73b3f8b | 2018-07-06 18:03:14 +0000 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | } // namespace mca |
Fangrui Song | 467c307 | 2018-10-30 15:56:08 +0000 | [diff] [blame] | 65 | } // namespace llvm |