• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  
14  #ifndef LLVM_TOOLS_LLVM_EXEGESIS_LLVMSTATE_H
15  #define LLVM_TOOLS_LLVM_EXEGESIS_LLVMSTATE_H
16  
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>
27  
28  namespace llvm {
29  namespace exegesis {
30  
31  class ExegesisTarget;
32  struct PfmCountersInfo;
33  
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);
40  
41    LLVMState(const std::string &Triple,
42              const std::string &CpuName,
43              const std::string &Features = ""); // For tests.
44  
getTargetMachine()45    const TargetMachine &getTargetMachine() const { return *TheTargetMachine; }
46    std::unique_ptr<LLVMTargetMachine> createTargetMachine() const;
47  
getExegesisTarget()48    const ExegesisTarget &getExegesisTarget() const { return *TheExegesisTarget; }
49  
50    bool canAssemble(const MCInst &mc_inst) const;
51  
52    // For convenience:
getInstrInfo()53    const MCInstrInfo &getInstrInfo() const {
54      return *TheTargetMachine->getMCInstrInfo();
55    }
getRegInfo()56    const MCRegisterInfo &getRegInfo() const {
57      return *TheTargetMachine->getMCRegisterInfo();
58    }
getSubtargetInfo()59    const MCSubtargetInfo &getSubtargetInfo() const {
60      return *TheTargetMachine->getMCSubtargetInfo();
61    }
62  
getRATC()63    const RegisterAliasingTrackerCache &getRATC() const { return *RATC; }
getIC()64    const InstructionsCache &getIC() const { return *IC; }
65  
getPfmCounters()66    const PfmCountersInfo &getPfmCounters() const { return *PfmCounters; }
67  
68  private:
69    const ExegesisTarget *TheExegesisTarget;
70    std::unique_ptr<const TargetMachine> TheTargetMachine;
71    std::unique_ptr<const RegisterAliasingTrackerCache> RATC;
72    std::unique_ptr<const InstructionsCache> IC;
73    const PfmCountersInfo *PfmCounters;
74  };
75  
76  } // namespace exegesis
77  } // namespace llvm
78  
79  #endif // LLVM_TOOLS_LLVM_EXEGESIS_LLVMSTATE_H
80