1 //===-- LlvmState.h ---------------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 /// 10 /// \file 11 /// A class to set up and access common LLVM objects. 12 /// 13 //===----------------------------------------------------------------------===// 14 15 #ifndef LLVM_TOOLS_LLVM_EXEGESIS_LLVMSTATE_H 16 #define LLVM_TOOLS_LLVM_EXEGESIS_LLVMSTATE_H 17 18 #include "llvm/MC/MCAsmInfo.h" 19 #include "llvm/MC/MCInst.h" 20 #include "llvm/MC/MCInstrInfo.h" 21 #include "llvm/MC/MCRegisterInfo.h" 22 #include "llvm/MC/MCSubtargetInfo.h" 23 #include "llvm/Target/TargetMachine.h" 24 #include <memory> 25 #include <string> 26 27 namespace exegesis { 28 29 class ExegesisTarget; 30 31 // An object to initialize LLVM and prepare objects needed to run the 32 // measurements. 33 class LLVMState { 34 public: 35 LLVMState(); 36 37 LLVMState(const std::string &Triple, 38 const std::string &CpuName); // For tests. 39 getTargetMachine()40 const llvm::TargetMachine &getTargetMachine() const { return *TargetMachine; } 41 std::unique_ptr<llvm::LLVMTargetMachine> createTargetMachine() const; 42 getExegesisTarget()43 const ExegesisTarget &getExegesisTarget() const { return *TheExegesisTarget; } 44 45 bool canAssemble(const llvm::MCInst &mc_inst) const; 46 47 // For convenience: getInstrInfo()48 const llvm::MCInstrInfo &getInstrInfo() const { 49 return *TargetMachine->getMCInstrInfo(); 50 } getRegInfo()51 const llvm::MCRegisterInfo &getRegInfo() const { 52 return *TargetMachine->getMCRegisterInfo(); 53 } getSubtargetInfo()54 const llvm::MCSubtargetInfo &getSubtargetInfo() const { 55 return *TargetMachine->getMCSubtargetInfo(); 56 } 57 58 private: 59 const ExegesisTarget *TheExegesisTarget; 60 std::unique_ptr<const llvm::TargetMachine> TargetMachine; 61 }; 62 63 } // namespace exegesis 64 65 #endif // LLVM_TOOLS_LLVM_EXEGESIS_LLVMSTATE_H 66