LLVM 22.0.0git
MIRParser.h
Go to the documentation of this file.
1//===- MIRParser.h - MIR serialization format parser ------------*- 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// This MIR serialization library is currently a work in progress. It can't
10// serialize machine functions at this time.
11//
12// This file declares the functions that parse the MIR serialization format
13// files.
14//
15//===----------------------------------------------------------------------===//
16
17#ifndef LLVM_CODEGEN_MIRPARSER_MIRPARSER_H
18#define LLVM_CODEGEN_MIRPARSER_MIRPARSER_H
19
21#include "llvm/ADT/StringRef.h"
23#include <functional>
24#include <memory>
25#include <optional>
26
27namespace llvm {
28
29class Function;
30class LLVMContext;
31class MemoryBuffer;
32class Module;
33class MIRParserImpl;
35class SMDiagnostic;
36class StringRef;
37
38template <typename IRUnitT, typename... ExtraArgTs> class AnalysisManager;
40
43
44/// This class initializes machine functions by applying the state loaded from
45/// a MIR file.
46class MIRParser {
47 std::unique_ptr<MIRParserImpl> Impl;
48
49public:
50 LLVM_ABI MIRParser(std::unique_ptr<MIRParserImpl> Impl);
51 MIRParser(const MIRParser &) = delete;
53
54 /// Parses the optional LLVM IR module in the MIR file.
55 ///
56 /// A new, empty module is created if the LLVM IR isn't present.
57 /// \returns nullptr if a parsing error occurred.
58 LLVM_ABI std::unique_ptr<Module>
59 parseIRModule(DataLayoutCallbackTy DataLayoutCallback =
60 [](StringRef, StringRef) { return std::nullopt; });
61
62 /// Parses MachineFunctions in the MIR file and add them to the given
63 /// MachineModuleInfo \p MMI.
64 ///
65 /// \returns true if an error occurred.
67
68 /// Parses MachineFunctions in the MIR file and add them as the result
69 /// of MachineFunctionAnalysis in ModulePassManager \p MAM.
70 /// User should register at least MachineFunctionAnalysis,
71 /// MachineModuleAnalysis, FunctionAnalysisManagerModuleProxy and
72 /// PassInstrumentationAnalysis in \p MAM before parsing MIR.
73 ///
74 /// \returns true if an error occurred.
76};
77
78/// This function is the main interface to the MIR serialization format parser.
79///
80/// It reads in a MIR file and returns a MIR parser that can parse the embedded
81/// LLVM IR module and initialize the machine functions by parsing the machine
82/// function's state.
83///
84/// \param Filename - The name of the file to parse.
85/// \param Error - Error result info.
86/// \param Context - Context which will be used for the parsed LLVM IR module.
87/// \param ProcessIRFunction - function to run on every IR function or stub
88/// loaded from the MIR file.
89LLVM_ABI std::unique_ptr<MIRParser> createMIRParserFromFile(
90 StringRef Filename, SMDiagnostic &Error, LLVMContext &Context,
91 std::function<void(Function &)> ProcessIRFunction = nullptr);
92
93/// This function is another interface to the MIR serialization format parser.
94///
95/// It returns a MIR parser that works with the given memory buffer and that can
96/// parse the embedded LLVM IR module and initialize the machine functions by
97/// parsing the machine function's state.
98///
99/// \param Contents - The MemoryBuffer containing the machine level IR.
100/// \param Context - Context which will be used for the parsed LLVM IR module.
101LLVM_ABI std::unique_ptr<MIRParser>
102createMIRParser(std::unique_ptr<MemoryBuffer> Contents, LLVMContext &Context,
103 std::function<void(Function &)> ProcessIRFunction = nullptr);
104
105} // end namespace llvm
106
107#endif // LLVM_CODEGEN_MIRPARSER_MIRPARSER_H
#define LLVM_ABI
Definition Compiler.h:213
ModuleAnalysisManager MAM
A container for analyses that lazily runs them and caches their results.
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
This class implements the parsing of LLVM IR that's embedded inside a MIR file.
Definition MIRParser.cpp:51
LLVM_ABI MIRParser(std::unique_ptr< MIRParserImpl > Impl)
MIRParser(const MIRParser &)=delete
LLVM_ABI std::unique_ptr< Module > parseIRModule(DataLayoutCallbackTy DataLayoutCallback=[](StringRef, StringRef) { return std::nullopt;})
Parses the optional LLVM IR module in the MIR file.
LLVM_ABI bool parseMachineFunctions(Module &M, MachineModuleInfo &MMI)
Parses MachineFunctions in the MIR file and add them to the given MachineModuleInfo MMI.
LLVM_ABI ~MIRParser()
This class contains meta information specific to a module.
This interface provides simple read-only access to a block of memory, and provides simple methods for...
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
Definition SourceMgr.h:282
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
An efficient, type-erasing, non-owning reference to a callable.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI std::unique_ptr< MIRParser > createMIRParserFromFile(StringRef Filename, SMDiagnostic &Error, LLVMContext &Context, std::function< void(Function &)> ProcessIRFunction=nullptr)
This function is the main interface to the MIR serialization format parser.
LLVM_ABI std::unique_ptr< MIRParser > createMIRParser(std::unique_ptr< MemoryBuffer > Contents, LLVMContext &Context, std::function< void(Function &)> ProcessIRFunction=nullptr)
This function is another interface to the MIR serialization format parser.
llvm::function_ref< std::optional< std::string >(StringRef, StringRef)> DataLayoutCallbackTy
Definition Parser.h:35
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition MIRParser.h:39