CodeRegionGenerator.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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/Support/Error.h"
  22. #include "llvm/Support/SourceMgr.h"
  23. #include "llvm/Support/TargetRegistry.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(SourceMgr &SM) : Regions(SM) {}
  36. virtual ~CodeRegionGenerator();
  37. virtual Expected<const CodeRegions &> parseCodeRegions() = 0;
  38. };
  39. /// This class is responsible for parsing input ASM and generating
  40. /// a CodeRegions instance.
  41. class AsmCodeRegionGenerator final : public CodeRegionGenerator {
  42. const Target &TheTarget;
  43. MCContext &Ctx;
  44. const MCAsmInfo &MAI;
  45. const MCSubtargetInfo &STI;
  46. const MCInstrInfo &MCII;
  47. unsigned AssemblerDialect; // This is set during parsing.
  48. public:
  49. AsmCodeRegionGenerator(const Target &T, SourceMgr &SM, MCContext &C,
  50. const MCAsmInfo &A, const MCSubtargetInfo &S,
  51. const MCInstrInfo &I)
  52. : CodeRegionGenerator(SM), TheTarget(T), Ctx(C), MAI(A), STI(S), MCII(I),
  53. AssemblerDialect(0) {}
  54. unsigned getAssemblerDialect() const { return AssemblerDialect; }
  55. Expected<const CodeRegions &> parseCodeRegions() override;
  56. };
  57. } // namespace mca
  58. } // namespace llvm
  59. #endif // LLVM_TOOLS_LLVM_MCA_CODEREGION_GENERATOR_H