CodeRegionGenerator.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //===----------------------- CodeRegionGenerator.h --------------*- 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 declares classes responsible for generating llvm-mca
  11. /// CodeRegions from various types of input. llvm-mca only analyzes CodeRegions,
  12. /// so the classes here provide the input-to-CodeRegions translation.
  13. //
  14. //===----------------------------------------------------------------------===//
  15. #ifndef LLVM_TOOLS_LLVM_MCA_CODEREGION_GENERATOR_H
  16. #define LLVM_TOOLS_LLVM_MCA_CODEREGION_GENERATOR_H
  17. #include "CodeRegion.h"
  18. #include "llvm/MC/MCAsmInfo.h"
  19. #include "llvm/MC/MCContext.h"
  20. #include "llvm/MC/MCSubtargetInfo.h"
  21. #include "llvm/MC/TargetRegistry.h"
  22. #include "llvm/Support/Error.h"
  23. #include "llvm/Support/SourceMgr.h"
  24. #include <memory>
  25. namespace llvm {
  26. namespace mca {
  27. /// This class is responsible for parsing the input given to the llvm-mca
  28. /// driver, and converting that into a CodeRegions instance.
  29. class CodeRegionGenerator {
  30. protected:
  31. CodeRegions Regions;
  32. CodeRegionGenerator(const CodeRegionGenerator &) = delete;
  33. CodeRegionGenerator &operator=(const CodeRegionGenerator &) = delete;
  34. public:
  35. CodeRegionGenerator(llvm::SourceMgr &SM) : Regions(SM) {}
  36. virtual ~CodeRegionGenerator();
  37. virtual Expected<const CodeRegions &>
  38. parseCodeRegions(const std::unique_ptr<MCInstPrinter> &IP) = 0;
  39. };
  40. /// This class is responsible for parsing input ASM and generating
  41. /// a CodeRegions instance.
  42. class AsmCodeRegionGenerator final : public CodeRegionGenerator {
  43. const Target &TheTarget;
  44. MCContext &Ctx;
  45. const MCAsmInfo &MAI;
  46. const MCSubtargetInfo &STI;
  47. const MCInstrInfo &MCII;
  48. unsigned AssemblerDialect; // This is set during parsing.
  49. public:
  50. AsmCodeRegionGenerator(const Target &T, llvm::SourceMgr &SM, MCContext &C,
  51. const MCAsmInfo &A, const MCSubtargetInfo &S,
  52. const MCInstrInfo &I)
  53. : CodeRegionGenerator(SM), TheTarget(T), Ctx(C), MAI(A), STI(S), MCII(I),
  54. AssemblerDialect(0) {}
  55. unsigned getAssemblerDialect() const { return AssemblerDialect; }
  56. Expected<const CodeRegions &>
  57. parseCodeRegions(const std::unique_ptr<MCInstPrinter> &IP) override;
  58. };
  59. } // namespace mca
  60. } // namespace llvm
  61. #endif // LLVM_TOOLS_LLVM_MCA_CODEREGION_GENERATOR_H