]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/llvm-mca/CodeRegionGenerator.h
MFV: r349861
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / llvm-mca / CodeRegionGenerator.h
1 //===----------------------- CodeRegionGenerator.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 /// \file
10 ///
11 /// This file declares classes responsible for generating llvm-mca
12 /// CodeRegions from various types of input. llvm-mca only analyzes CodeRegions,
13 /// so the classes here provide the input-to-CodeRegions translation.
14 //
15 //===----------------------------------------------------------------------===//
16
17 #ifndef LLVM_TOOLS_LLVM_MCA_CODEREGION_GENERATOR_H
18 #define LLVM_TOOLS_LLVM_MCA_CODEREGION_GENERATOR_H
19
20 #include "CodeRegion.h"
21 #include "llvm/MC/MCAsmInfo.h"
22 #include "llvm/MC/MCContext.h"
23 #include "llvm/MC/MCSubtargetInfo.h"
24 #include "llvm/Support/Error.h"
25 #include "llvm/Support/SourceMgr.h"
26 #include "llvm/Support/TargetRegistry.h"
27 #include <memory>
28
29 namespace llvm {
30 namespace mca {
31
32 /// This class is responsible for parsing the input given to the llvm-mca
33 /// driver, and converting that into a CodeRegions instance.
34 class CodeRegionGenerator {
35 protected:
36   CodeRegions Regions;
37   CodeRegionGenerator(const CodeRegionGenerator &) = delete;
38   CodeRegionGenerator &operator=(const CodeRegionGenerator &) = delete;
39
40 public:
41   CodeRegionGenerator(SourceMgr &SM) : Regions(SM) {}
42   virtual ~CodeRegionGenerator();
43   virtual Expected<const CodeRegions &> parseCodeRegions() = 0;
44 };
45
46 /// This class is responsible for parsing input ASM and generating
47 /// a CodeRegions instance.
48 class AsmCodeRegionGenerator final : public CodeRegionGenerator {
49   const Target &TheTarget;
50   MCContext &Ctx;
51   const MCAsmInfo &MAI;
52   const MCSubtargetInfo &STI;
53   const MCInstrInfo &MCII;
54   unsigned AssemblerDialect; // This is set during parsing.
55
56 public:
57   AsmCodeRegionGenerator(const Target &T, SourceMgr &SM, MCContext &C,
58                          const MCAsmInfo &A, const MCSubtargetInfo &S,
59                          const MCInstrInfo &I)
60       : CodeRegionGenerator(SM), TheTarget(T), Ctx(C), MAI(A), STI(S), MCII(I),
61         AssemblerDialect(0) {}
62
63   unsigned getAssemblerDialect() const { return AssemblerDialect; }
64   Expected<const CodeRegions &> parseCodeRegions() override;
65 };
66
67 } // namespace mca
68 } // namespace llvm
69
70 #endif // LLVM_TOOLS_LLVM_MCA_CODEREGION_GENERATOR_H