[llvm] Stop including unordered_map (NFC)
[llvm-project.git] / llvm / tools / llvm-exegesis / lib / LlvmState.h
blob16f0def518256f0d144f0b9b1b3e026d928aee85
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 static constexpr llvm::StringLiteral kNoRegister("%noreg");
30 namespace llvm {
31 namespace exegesis {
33 class ExegesisTarget;
34 struct PfmCountersInfo;
36 // An object to initialize LLVM and prepare objects needed to run the
37 // measurements.
38 class LLVMState {
39 public:
40 // Factory function.
41 // If `Triple` is empty, uses the host triple.
42 // If `CpuName` is empty, uses the host CPU.
43 // If `UseDummyPerfCounters` is set, does not query the kernel
44 // for event counts.
45 // `UseDummyPerfCounters` and `Features` are intended for tests.
46 static Expected<LLVMState> Create(std::string TripleName, std::string CpuName,
47 StringRef Features = "",
48 bool UseDummyPerfCounters = false);
50 const TargetMachine &getTargetMachine() const { return *TheTargetMachine; }
51 std::unique_ptr<LLVMTargetMachine> createTargetMachine() const;
53 const ExegesisTarget &getExegesisTarget() const { return *TheExegesisTarget; }
55 bool canAssemble(const MCInst &mc_inst) const;
57 // For convenience:
58 const MCInstrInfo &getInstrInfo() const {
59 return *TheTargetMachine->getMCInstrInfo();
61 const MCRegisterInfo &getRegInfo() const {
62 return *TheTargetMachine->getMCRegisterInfo();
64 const MCSubtargetInfo &getSubtargetInfo() const {
65 return *TheTargetMachine->getMCSubtargetInfo();
68 const RegisterAliasingTrackerCache &getRATC() const { return *RATC; }
69 const InstructionsCache &getIC() const { return *IC; }
71 const PfmCountersInfo &getPfmCounters() const { return *PfmCounters; }
73 const DenseMap<StringRef, unsigned> &getOpcodeNameToOpcodeIdxMapping() const {
74 assert(OpcodeNameToOpcodeIdxMapping);
75 return *OpcodeNameToOpcodeIdxMapping;
78 const DenseMap<StringRef, unsigned> &getRegNameToRegNoMapping() const {
79 assert(RegNameToRegNoMapping);
80 return *RegNameToRegNoMapping;
83 private:
84 std::unique_ptr<const DenseMap<StringRef, unsigned>>
85 createOpcodeNameToOpcodeIdxMapping() const;
87 std::unique_ptr<const DenseMap<StringRef, unsigned>>
88 createRegNameToRegNoMapping() const;
90 LLVMState(std::unique_ptr<const TargetMachine> TM, const ExegesisTarget *ET,
91 const PfmCountersInfo *PCI);
93 const ExegesisTarget *TheExegesisTarget;
94 std::unique_ptr<const TargetMachine> TheTargetMachine;
95 std::unique_ptr<const RegisterAliasingTrackerCache> RATC;
96 std::unique_ptr<const InstructionsCache> IC;
97 const PfmCountersInfo *PfmCounters;
98 std::unique_ptr<const DenseMap<StringRef, unsigned>>
99 OpcodeNameToOpcodeIdxMapping;
100 std::unique_ptr<const DenseMap<StringRef, unsigned>> RegNameToRegNoMapping;
103 } // namespace exegesis
104 } // namespace llvm
106 #endif // LLVM_TOOLS_LLVM_EXEGESIS_LLVMSTATE_H