Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:26

0001 //===- MIRParser.h - MIR serialization format parser ------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This MIR serialization library is currently a work in progress. It can't
0010 // serialize machine functions at this time.
0011 //
0012 // This file declares the functions that parse the MIR serialization format
0013 // files.
0014 //
0015 //===----------------------------------------------------------------------===//
0016 
0017 #ifndef LLVM_CODEGEN_MIRPARSER_MIRPARSER_H
0018 #define LLVM_CODEGEN_MIRPARSER_MIRPARSER_H
0019 
0020 #include "llvm/ADT/STLFunctionalExtras.h"
0021 #include "llvm/ADT/StringRef.h"
0022 #include <functional>
0023 #include <memory>
0024 #include <optional>
0025 
0026 namespace llvm {
0027 
0028 class Function;
0029 class LLVMContext;
0030 class MemoryBuffer;
0031 class Module;
0032 class MIRParserImpl;
0033 class MachineModuleInfo;
0034 class SMDiagnostic;
0035 class StringRef;
0036 
0037 template <typename IRUnitT, typename... ExtraArgTs> class AnalysisManager;
0038 using ModuleAnalysisManager = AnalysisManager<Module>;
0039 
0040 typedef llvm::function_ref<std::optional<std::string>(StringRef, StringRef)>
0041     DataLayoutCallbackTy;
0042 
0043 /// This class initializes machine functions by applying the state loaded from
0044 /// a MIR file.
0045 class MIRParser {
0046   std::unique_ptr<MIRParserImpl> Impl;
0047 
0048 public:
0049   MIRParser(std::unique_ptr<MIRParserImpl> Impl);
0050   MIRParser(const MIRParser &) = delete;
0051   ~MIRParser();
0052 
0053   /// Parses the optional LLVM IR module in the MIR file.
0054   ///
0055   /// A new, empty module is created if the LLVM IR isn't present.
0056   /// \returns nullptr if a parsing error occurred.
0057   std::unique_ptr<Module>
0058   parseIRModule(DataLayoutCallbackTy DataLayoutCallback =
0059                     [](StringRef, StringRef) { return std::nullopt; });
0060 
0061   /// Parses MachineFunctions in the MIR file and add them to the given
0062   /// MachineModuleInfo \p MMI.
0063   ///
0064   /// \returns true if an error occurred.
0065   bool parseMachineFunctions(Module &M, MachineModuleInfo &MMI);
0066 
0067   /// Parses MachineFunctions in the MIR file and add them as the result
0068   /// of MachineFunctionAnalysis in ModulePassManager \p MAM.
0069   /// User should register at least MachineFunctionAnalysis,
0070   /// MachineModuleAnalysis, FunctionAnalysisManagerModuleProxy and
0071   /// PassInstrumentationAnalysis in \p MAM before parsing MIR.
0072   ///
0073   /// \returns true if an error occurred.
0074   bool parseMachineFunctions(Module &M, ModuleAnalysisManager &MAM);
0075 };
0076 
0077 /// This function is the main interface to the MIR serialization format parser.
0078 ///
0079 /// It reads in a MIR file and returns a MIR parser that can parse the embedded
0080 /// LLVM IR module and initialize the machine functions by parsing the machine
0081 /// function's state.
0082 ///
0083 /// \param Filename - The name of the file to parse.
0084 /// \param Error - Error result info.
0085 /// \param Context - Context which will be used for the parsed LLVM IR module.
0086 /// \param ProcessIRFunction - function to run on every IR function or stub
0087 /// loaded from the MIR file.
0088 std::unique_ptr<MIRParser> createMIRParserFromFile(
0089     StringRef Filename, SMDiagnostic &Error, LLVMContext &Context,
0090     std::function<void(Function &)> ProcessIRFunction = nullptr);
0091 
0092 /// This function is another interface to the MIR serialization format parser.
0093 ///
0094 /// It returns a MIR parser that works with the given memory buffer and that can
0095 /// parse the embedded LLVM IR module and initialize the machine functions by
0096 /// parsing the machine function's state.
0097 ///
0098 /// \param Contents - The MemoryBuffer containing the machine level IR.
0099 /// \param Context - Context which will be used for the parsed LLVM IR module.
0100 std::unique_ptr<MIRParser>
0101 createMIRParser(std::unique_ptr<MemoryBuffer> Contents, LLVMContext &Context,
0102                 std::function<void(Function &)> ProcessIRFunction = nullptr);
0103 
0104 } // end namespace llvm
0105 
0106 #endif // LLVM_CODEGEN_MIRPARSER_MIRPARSER_H