LLVM 19.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
37typedef llvm::function_ref<std::optional<std::string>(StringRef, StringRef)>
39
40/// This class initializes machine functions by applying the state loaded from
41/// a MIR file.
42class MIRParser {
43 std::unique_ptr<MIRParserImpl> Impl;
44
45public:
46 MIRParser(std::unique_ptr<MIRParserImpl> Impl);
47 MIRParser(const MIRParser &) = delete;
49
50 /// Parses the optional LLVM IR module in the MIR file.
51 ///
52 /// A new, empty module is created if the LLVM IR isn't present.
53 /// \returns nullptr if a parsing error occurred.
54 std::unique_ptr<Module>
55 parseIRModule(DataLayoutCallbackTy DataLayoutCallback =
56 [](StringRef, StringRef) { return std::nullopt; });
57
58 /// Parses MachineFunctions in the MIR file and add them to the given
59 /// MachineModuleInfo \p MMI.
60 ///
61 /// \returns true if an error occurred.
63};
64
65/// This function is the main interface to the MIR serialization format parser.
66///
67/// It reads in a MIR file and returns a MIR parser that can parse the embedded
68/// LLVM IR module and initialize the machine functions by parsing the machine
69/// function's state.
70///
71/// \param Filename - The name of the file to parse.
72/// \param Error - Error result info.
73/// \param Context - Context which will be used for the parsed LLVM IR module.
74/// \param ProcessIRFunction - function to run on every IR function or stub
75/// loaded from the MIR file.
76std::unique_ptr<MIRParser> createMIRParserFromFile(
77 StringRef Filename, SMDiagnostic &Error, LLVMContext &Context,
78 std::function<void(Function &)> ProcessIRFunction = nullptr);
79
80/// This function is another interface to the MIR serialization format parser.
81///
82/// It returns a MIR parser that works with the given memory buffer and that can
83/// parse the embedded LLVM IR module and initialize the machine functions by
84/// parsing the machine function's state.
85///
86/// \param Contents - The MemoryBuffer containing the machine level IR.
87/// \param Context - Context which will be used for the parsed LLVM IR module.
88std::unique_ptr<MIRParser>
89createMIRParser(std::unique_ptr<MemoryBuffer> Contents, LLVMContext &Context,
90 std::function<void(Function &)> ProcessIRFunction = nullptr);
91
92} // end namespace llvm
93
94#endif // LLVM_CODEGEN_MIRPARSER_MIRPARSER_H
Machine Check Debug Module
This class initializes machine functions by applying the state loaded from a MIR file.
Definition: MIRParser.h:42
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:1096
bool parseMachineFunctions(Module &M, MachineModuleInfo &MMI)
Parses MachineFunctions in the MIR file and add them to the given MachineModuleInfo MMI.
Definition: MIRParser.cpp:1100
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:50
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:1104
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:1118
llvm::function_ref< std::optional< std::string >(StringRef, StringRef)> DataLayoutCallbackTy
Definition: Parser.h:33