[UpdateCCTestChecks] Detect function mangled name on separate line
[llvm-core.git] / tools / llvm-exegesis / lib / LlvmState.h
blobf52a521c4dd5f68db1092588cf4ccaebc532b90c
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 //===----------------------------------------------------------------------===//
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"
25 #include <memory>
26 #include <string>
28 namespace llvm {
29 namespace exegesis {
31 class ExegesisTarget;
32 struct PfmCountersInfo;
34 // An object to initialize LLVM and prepare objects needed to run the
35 // measurements.
36 class LLVMState {
37 public:
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;
52 // For convenience:
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; }
68 private:
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
77 } // namespace llvm
79 #endif // LLVM_TOOLS_LLVM_EXEGESIS_LLVMSTATE_H