Context.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===---------------------------- Context.h ---------------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. /// \file
  14. ///
  15. /// This file defines a class for holding ownership of various simulated
  16. /// hardware units. A Context also provides a utility routine for constructing
  17. /// a default out-of-order pipeline with fetch, dispatch, execute, and retire
  18. /// stages.
  19. ///
  20. //===----------------------------------------------------------------------===//
  21. #ifndef LLVM_MCA_CONTEXT_H
  22. #define LLVM_MCA_CONTEXT_H
  23. #include "llvm/MC/MCRegisterInfo.h"
  24. #include "llvm/MC/MCSubtargetInfo.h"
  25. #include "llvm/MCA/CustomBehaviour.h"
  26. #include "llvm/MCA/HardwareUnits/HardwareUnit.h"
  27. #include "llvm/MCA/Pipeline.h"
  28. #include "llvm/MCA/SourceMgr.h"
  29. #include <memory>
  30. namespace llvm {
  31. namespace mca {
  32. /// This is a convenience struct to hold the parameters necessary for creating
  33. /// the pre-built "default" out-of-order pipeline.
  34. struct PipelineOptions {
  35. PipelineOptions(unsigned UOPQSize, unsigned DecThr, unsigned DW, unsigned RFS,
  36. unsigned LQS, unsigned SQS, bool NoAlias,
  37. bool ShouldEnableBottleneckAnalysis = false)
  38. : MicroOpQueueSize(UOPQSize), DecodersThroughput(DecThr),
  39. DispatchWidth(DW), RegisterFileSize(RFS), LoadQueueSize(LQS),
  40. StoreQueueSize(SQS), AssumeNoAlias(NoAlias),
  41. EnableBottleneckAnalysis(ShouldEnableBottleneckAnalysis) {}
  42. unsigned MicroOpQueueSize;
  43. unsigned DecodersThroughput; // Instructions per cycle.
  44. unsigned DispatchWidth;
  45. unsigned RegisterFileSize;
  46. unsigned LoadQueueSize;
  47. unsigned StoreQueueSize;
  48. bool AssumeNoAlias;
  49. bool EnableBottleneckAnalysis;
  50. };
  51. class Context {
  52. SmallVector<std::unique_ptr<HardwareUnit>, 4> Hardware;
  53. const MCRegisterInfo &MRI;
  54. const MCSubtargetInfo &STI;
  55. public:
  56. Context(const MCRegisterInfo &R, const MCSubtargetInfo &S) : MRI(R), STI(S) {}
  57. Context(const Context &C) = delete;
  58. Context &operator=(const Context &C) = delete;
  59. const MCRegisterInfo &getMCRegisterInfo() const { return MRI; }
  60. const MCSubtargetInfo &getMCSubtargetInfo() const { return STI; }
  61. void addHardwareUnit(std::unique_ptr<HardwareUnit> H) {
  62. Hardware.push_back(std::move(H));
  63. }
  64. /// Construct a basic pipeline for simulating an out-of-order pipeline.
  65. /// This pipeline consists of Fetch, Dispatch, Execute, and Retire stages.
  66. std::unique_ptr<Pipeline> createDefaultPipeline(const PipelineOptions &Opts,
  67. SourceMgr &SrcMgr,
  68. CustomBehaviour &CB);
  69. /// Construct a basic pipeline for simulating an in-order pipeline.
  70. /// This pipeline consists of Fetch, InOrderIssue, and Retire stages.
  71. std::unique_ptr<Pipeline> createInOrderPipeline(const PipelineOptions &Opts,
  72. SourceMgr &SrcMgr,
  73. CustomBehaviour &CB);
  74. };
  75. } // namespace mca
  76. } // namespace llvm
  77. #endif // LLVM_MCA_CONTEXT_H
  78. #ifdef __GNUC__
  79. #pragma GCC diagnostic pop
  80. #endif