LLVM 20.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"
22#include <functional>
23#include <memory>
24#include <optional>
25
26namespace llvm {
27
28class Function;
29class LLVMContext;
30class MemoryBuffer;
31class Module;
32class MIRParserImpl;
33class MachineModuleInfo;
34class SMDiagnostic;
35class StringRef;
36
37template <typename IRUnitT, typename... ExtraArgTs> class AnalysisManager;
39
42
43/// This class initializes machine functions by applying the state loaded from
44/// a MIR file.
45class MIRParser {
46 std::unique_ptr<MIRParserImpl> Impl;
47
48public:
49 MIRParser(std::unique_ptr<MIRParserImpl> Impl);
50 MIRParser(const MIRParser &) = delete;
52
53 /// Parses the optional LLVM IR module in the MIR file.
54 ///
55 /// A new, empty module is created if the LLVM IR isn't present.
56 /// \returns nullptr if a parsing error occurred.
57 std::unique_ptr<Module>
58 parseIRModule(DataLayoutCallbackTy DataLayoutCallback =
59 [](StringRef, StringRef) { return std::nullopt; });
60
61 /// Parses MachineFunctions in the MIR file and add them to the given
62 /// MachineModuleInfo \p MMI.
63 ///
64 /// \returns true if an error occurred.
66
67 /// Parses MachineFunctions in the MIR file and add them as the result
68 /// of MachineFunctionAnalysis in ModulePassManager \p MAM.
69 /// User should register at least MachineFunctionAnalysis,
70 /// MachineModuleAnalysis, FunctionAnalysisManagerModuleProxy and
71 /// PassInstrumentationAnalysis in \p MAM before parsing MIR.
72 ///
73 /// \returns true if an error occurred.
75};
76
77/// This function is the main interface to the MIR serialization format parser.
78///
79/// It reads in a MIR file and returns a MIR parser that can parse the embedded
80/// LLVM IR module and initialize the machine functions by parsing the machine
81/// function's state.
82///
83/// \param Filename - The name of the file to parse.
84/// \param Error - Error result info.
85/// \param Context - Context which will be used for the parsed LLVM IR module.
86/// \param ProcessIRFunction - function to run on every IR function or stub
87/// loaded from the MIR file.
88std::unique_ptr<MIRParser> createMIRParserFromFile(
89 StringRef Filename, SMDiagnostic &Error, LLVMContext &Context,
90 std::function<void(Function &)> ProcessIRFunction = nullptr);
91
92/// This function is another interface to the MIR serialization format parser.
93///
94/// It returns a MIR parser that works with the given memory buffer and that can
95/// parse the embedded LLVM IR module and initialize the machine functions by
96/// parsing the machine function's state.
97///
98/// \param Contents - The MemoryBuffer containing the machine level IR.
99/// \param Context - Context which will be used for the parsed LLVM IR module.
100std::unique_ptr<MIRParser>
101createMIRParser(std::unique_ptr<MemoryBuffer> Contents, LLVMContext &Context,
102 std::function<void(Function &)> ProcessIRFunction = nullptr);
103
104} // end namespace llvm
105
106#endif // LLVM_CODEGEN_MIRPARSER_MIRPARSER_H
Machine Check Debug Module
ModuleAnalysisManager MAM
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:253
This class initializes machine functions by applying the state loaded from a MIR file.
Definition: MIRParser.h:45
MIRParser(const MIRParser &)=delete
std::unique_ptr< Module > parseIRModule(DataLayoutCallbackTy DataLayoutCallback=[](StringRef, StringRef) { return std::nullopt;})
Parses the optional LLVM IR module in the MIR file.
Definition: MIRParser.cpp:1167
bool parseMachineFunctions(Module &M, MachineModuleInfo &MMI)
Parses MachineFunctions in the MIR file and add them to the given MachineModuleInfo MMI.
Definition: MIRParser.cpp:1171
This class contains meta information specific to a module.
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
An efficient, type-erasing, non-owning reference to a callable.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
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.
Definition: MIRParser.cpp:1180
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.
Definition: MIRParser.cpp:1194
llvm::function_ref< std::optional< std::string >(StringRef, StringRef)> DataLayoutCallbackTy
Definition: Parser.h:34