Context.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. #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/MicroOpQueueStage.h"
  24. #include "llvm/MCA/Stages/RetireStage.h"
  25. namespace llvm {
  26. namespace mca {
  27. std::unique_ptr<Pipeline>
  28. Context::createDefaultPipeline(const PipelineOptions &Opts, SourceMgr &SrcMgr) {
  29. const MCSchedModel &SM = STI.getSchedModel();
  30. // Create the hardware units defining the backend.
  31. auto RCU = std::make_unique<RetireControlUnit>(SM);
  32. auto PRF = std::make_unique<RegisterFile>(SM, MRI, Opts.RegisterFileSize);
  33. auto LSU = std::make_unique<LSUnit>(SM, Opts.LoadQueueSize,
  34. Opts.StoreQueueSize, Opts.AssumeNoAlias);
  35. auto HWS = std::make_unique<Scheduler>(SM, *LSU);
  36. // Create the pipeline stages.
  37. auto Fetch = std::make_unique<EntryStage>(SrcMgr);
  38. auto Dispatch = std::make_unique<DispatchStage>(STI, MRI, Opts.DispatchWidth,
  39. *RCU, *PRF);
  40. auto Execute =
  41. std::make_unique<ExecuteStage>(*HWS, Opts.EnableBottleneckAnalysis);
  42. auto Retire = std::make_unique<RetireStage>(*RCU, *PRF, *LSU);
  43. // Pass the ownership of all the hardware units to this Context.
  44. addHardwareUnit(std::move(RCU));
  45. addHardwareUnit(std::move(PRF));
  46. addHardwareUnit(std::move(LSU));
  47. addHardwareUnit(std::move(HWS));
  48. // Build the pipeline.
  49. auto StagePipeline = std::make_unique<Pipeline>();
  50. StagePipeline->appendStage(std::move(Fetch));
  51. if (Opts.MicroOpQueueSize)
  52. StagePipeline->appendStage(std::make_unique<MicroOpQueueStage>(
  53. Opts.MicroOpQueueSize, Opts.DecodersThroughput));
  54. StagePipeline->appendStage(std::move(Dispatch));
  55. StagePipeline->appendStage(std::move(Execute));
  56. StagePipeline->appendStage(std::move(Retire));
  57. return StagePipeline;
  58. }
  59. } // namespace mca
  60. } // namespace llvm