1 //===-- LlvmState.h ---------------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
10 /// A class to set up and access common LLVM objects.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_TOOLS_LLVM_EXEGESIS_LLVMSTATE_H
15 #define LLVM_TOOLS_LLVM_EXEGESIS_LLVMSTATE_H
17 #include "MCInstrDescView.h"
18 #include "RegisterAliasing.h"
19 #include "llvm/MC/MCAsmInfo.h"
20 #include "llvm/MC/MCInst.h"
21 #include "llvm/MC/MCInstrInfo.h"
22 #include "llvm/MC/MCRegisterInfo.h"
23 #include "llvm/MC/MCSubtargetInfo.h"
24 #include "llvm/Target/TargetMachine.h"
32 struct PfmCountersInfo
;
34 // An object to initialize LLVM and prepare objects needed to run the
38 // Uses the host triple. If CpuName is empty, uses the host CPU.
39 LLVMState(const std::string
&CpuName
);
41 LLVMState(const std::string
&Triple
,
42 const std::string
&CpuName
,
43 const std::string
&Features
= ""); // For tests.
45 const llvm::TargetMachine
&getTargetMachine() const { return *TargetMachine
; }
46 std::unique_ptr
<llvm::LLVMTargetMachine
> createTargetMachine() const;
48 const ExegesisTarget
&getExegesisTarget() const { return *TheExegesisTarget
; }
50 bool canAssemble(const llvm::MCInst
&mc_inst
) const;
53 const llvm::MCInstrInfo
&getInstrInfo() const {
54 return *TargetMachine
->getMCInstrInfo();
56 const llvm::MCRegisterInfo
&getRegInfo() const {
57 return *TargetMachine
->getMCRegisterInfo();
59 const llvm::MCSubtargetInfo
&getSubtargetInfo() const {
60 return *TargetMachine
->getMCSubtargetInfo();
63 const RegisterAliasingTrackerCache
&getRATC() const { return *RATC
; }
64 const InstructionsCache
&getIC() const { return *IC
; }
66 const PfmCountersInfo
&getPfmCounters() const { return *PfmCounters
; }
69 const ExegesisTarget
*TheExegesisTarget
;
70 std::unique_ptr
<const llvm::TargetMachine
> TargetMachine
;
71 std::unique_ptr
<const RegisterAliasingTrackerCache
> RATC
;
72 std::unique_ptr
<const InstructionsCache
> IC
;
73 const PfmCountersInfo
*PfmCounters
;
76 } // namespace exegesis
79 #endif // LLVM_TOOLS_LLVM_EXEGESIS_LLVMSTATE_H