Context.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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/InOrderIssueStage.h"
  24. #include "llvm/MCA/Stages/MicroOpQueueStage.h"
  25. #include "llvm/MCA/Stages/RetireStage.h"
  26. namespace llvm {
  27. namespace mca {
  28. std::unique_ptr<Pipeline>
  29. Context::createDefaultPipeline(const PipelineOptions &Opts, SourceMgr &SrcMgr,
  30. CustomBehaviour &CB) {
  31. const MCSchedModel &SM = STI.getSchedModel();
  32. if (!SM.isOutOfOrder())
  33. return createInOrderPipeline(Opts, SrcMgr, CB);
  34. // Create the hardware units defining the backend.
  35. auto RCU = std::make_unique<RetireControlUnit>(SM);
  36. auto PRF = std::make_unique<RegisterFile>(SM, MRI, Opts.RegisterFileSize);
  37. auto LSU = std::make_unique<LSUnit>(SM, Opts.LoadQueueSize,
  38. Opts.StoreQueueSize, Opts.AssumeNoAlias);
  39. auto HWS = std::make_unique<Scheduler>(SM, *LSU);
  40. // Create the pipeline stages.
  41. auto Fetch = std::make_unique<EntryStage>(SrcMgr);
  42. auto Dispatch =
  43. std::make_unique<DispatchStage>(STI, MRI, Opts.DispatchWidth, *RCU, *PRF);
  44. auto Execute =
  45. std::make_unique<ExecuteStage>(*HWS, Opts.EnableBottleneckAnalysis);
  46. auto Retire = std::make_unique<RetireStage>(*RCU, *PRF, *LSU);
  47. // Pass the ownership of all the hardware units to this Context.
  48. addHardwareUnit(std::move(RCU));
  49. addHardwareUnit(std::move(PRF));
  50. addHardwareUnit(std::move(LSU));
  51. addHardwareUnit(std::move(HWS));
  52. // Build the pipeline.
  53. auto StagePipeline = std::make_unique<Pipeline>();
  54. StagePipeline->appendStage(std::move(Fetch));
  55. if (Opts.MicroOpQueueSize)
  56. StagePipeline->appendStage(std::make_unique<MicroOpQueueStage>(
  57. Opts.MicroOpQueueSize, Opts.DecodersThroughput));
  58. StagePipeline->appendStage(std::move(Dispatch));
  59. StagePipeline->appendStage(std::move(Execute));
  60. StagePipeline->appendStage(std::move(Retire));
  61. return StagePipeline;
  62. }
  63. std::unique_ptr<Pipeline>
  64. Context::createInOrderPipeline(const PipelineOptions &Opts, SourceMgr &SrcMgr,
  65. CustomBehaviour &CB) {
  66. const MCSchedModel &SM = STI.getSchedModel();
  67. auto PRF = std::make_unique<RegisterFile>(SM, MRI, Opts.RegisterFileSize);
  68. auto LSU = std::make_unique<LSUnit>(SM, Opts.LoadQueueSize,
  69. Opts.StoreQueueSize, Opts.AssumeNoAlias);
  70. // Create the pipeline stages.
  71. auto Entry = std::make_unique<EntryStage>(SrcMgr);
  72. auto InOrderIssue = std::make_unique<InOrderIssueStage>(STI, *PRF, CB, *LSU);
  73. auto StagePipeline = std::make_unique<Pipeline>();
  74. // Pass the ownership of all the hardware units to this Context.
  75. addHardwareUnit(std::move(PRF));
  76. addHardwareUnit(std::move(LSU));
  77. // Build the pipeline.
  78. StagePipeline->appendStage(std::move(Entry));
  79. StagePipeline->appendStage(std::move(InOrderIssue));
  80. return StagePipeline;
  81. }
  82. } // namespace mca
  83. } // namespace llvm