LlvmState.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //===-- LlvmState.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. ///
  9. /// \file
  10. /// A class to set up and access common LLVM objects.
  11. ///
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_TOOLS_LLVM_EXEGESIS_LLVMSTATE_H
  14. #define LLVM_TOOLS_LLVM_EXEGESIS_LLVMSTATE_H
  15. #include "MCInstrDescView.h"
  16. #include "RegisterAliasing.h"
  17. #include "llvm/MC/MCAsmInfo.h"
  18. #include "llvm/MC/MCInst.h"
  19. #include "llvm/MC/MCInstrInfo.h"
  20. #include "llvm/MC/MCRegisterInfo.h"
  21. #include "llvm/MC/MCSubtargetInfo.h"
  22. #include "llvm/Target/TargetMachine.h"
  23. #include <memory>
  24. #include <string>
  25. namespace llvm {
  26. namespace exegesis {
  27. class ExegesisTarget;
  28. struct PfmCountersInfo;
  29. // An object to initialize LLVM and prepare objects needed to run the
  30. // measurements.
  31. class LLVMState {
  32. public:
  33. // Uses the host triple. If CpuName is empty, uses the host CPU.
  34. LLVMState(const std::string &CpuName);
  35. LLVMState(const std::string &Triple,
  36. const std::string &CpuName,
  37. const std::string &Features = ""); // For tests.
  38. const TargetMachine &getTargetMachine() const { return *TheTargetMachine; }
  39. std::unique_ptr<LLVMTargetMachine> createTargetMachine() const;
  40. const ExegesisTarget &getExegesisTarget() const { return *TheExegesisTarget; }
  41. bool canAssemble(const MCInst &mc_inst) const;
  42. // For convenience:
  43. const MCInstrInfo &getInstrInfo() const {
  44. return *TheTargetMachine->getMCInstrInfo();
  45. }
  46. const MCRegisterInfo &getRegInfo() const {
  47. return *TheTargetMachine->getMCRegisterInfo();
  48. }
  49. const MCSubtargetInfo &getSubtargetInfo() const {
  50. return *TheTargetMachine->getMCSubtargetInfo();
  51. }
  52. const RegisterAliasingTrackerCache &getRATC() const { return *RATC; }
  53. const InstructionsCache &getIC() const { return *IC; }
  54. const PfmCountersInfo &getPfmCounters() const { return *PfmCounters; }
  55. private:
  56. const ExegesisTarget *TheExegesisTarget;
  57. std::unique_ptr<const TargetMachine> TheTargetMachine;
  58. std::unique_ptr<const RegisterAliasingTrackerCache> RATC;
  59. std::unique_ptr<const InstructionsCache> IC;
  60. const PfmCountersInfo *PfmCounters;
  61. };
  62. } // namespace exegesis
  63. } // namespace llvm
  64. #endif // LLVM_TOOLS_LLVM_EXEGESIS_LLVMSTATE_H