LLVM  15.0.0git
IRReader.h
Go to the documentation of this file.
1 //===---- llvm/IRReader/IRReader.h - Reader for LLVM IR files ---*- 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 file defines functions for reading LLVM IR. They support both
10 // Bitcode and Assembly, automatically detecting the input format.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_IRREADER_IRREADER_H
15 #define LLVM_IRREADER_IRREADER_H
16 
17 #include "llvm/ADT/Optional.h"
20 #include "llvm/ADT/StringRef.h"
21 #include <memory>
22 
23 namespace llvm {
24 
25 class MemoryBuffer;
26 class MemoryBufferRef;
27 class Module;
28 class SMDiagnostic;
29 class LLVMContext;
30 
33 
34 /// If the given MemoryBuffer holds a bitcode image, return a Module
35 /// for it which does lazy deserialization of function bodies. Otherwise,
36 /// attempt to parse it as LLVM Assembly and return a fully populated
37 /// Module. The ShouldLazyLoadMetadata flag is passed down to the bitcode
38 /// reader to optionally enable lazy metadata loading. This takes ownership
39 /// of \p Buffer.
40 std::unique_ptr<Module> getLazyIRModule(std::unique_ptr<MemoryBuffer> Buffer,
41  SMDiagnostic &Err, LLVMContext &Context,
42  bool ShouldLazyLoadMetadata = false);
43 
44 /// If the given file holds a bitcode image, return a Module
45 /// for it which does lazy deserialization of function bodies. Otherwise,
46 /// attempt to parse it as LLVM Assembly and return a fully populated
47 /// Module. The ShouldLazyLoadMetadata flag is passed down to the bitcode
48 /// reader to optionally enable lazy metadata loading.
49 std::unique_ptr<Module>
50 getLazyIRFileModule(StringRef Filename, SMDiagnostic &Err, LLVMContext &Context,
51  bool ShouldLazyLoadMetadata = false);
52 
53 /// If the given MemoryBuffer holds a bitcode image, return a Module
54 /// for it. Otherwise, attempt to parse it as LLVM Assembly and return
55 /// a Module for it.
56 /// \param DataLayoutCallback Override datalayout in the llvm assembly.
57 std::unique_ptr<Module> parseIR(
58  MemoryBufferRef Buffer, SMDiagnostic &Err, LLVMContext &Context,
59  DataLayoutCallbackTy DataLayoutCallback = [](StringRef) { return None; });
60 
61 /// If the given file holds a bitcode image, return a Module for it.
62 /// Otherwise, attempt to parse it as LLVM Assembly and return a Module
63 /// for it.
64 /// \param DataLayoutCallback Override datalayout in the llvm assembly.
65 std::unique_ptr<Module> parseIRFile(
66  StringRef Filename, SMDiagnostic &Err, LLVMContext &Context,
67  DataLayoutCallbackTy DataLayoutCallback = [](StringRef) { return None; });
68 }
69 
70 #endif
llvm::parseIR
std::unique_ptr< Module > parseIR(MemoryBufferRef Buffer, SMDiagnostic &Err, LLVMContext &Context, DataLayoutCallbackTy DataLayoutCallback=[](StringRef) { return None;})
If the given MemoryBuffer holds a bitcode image, return a Module for it.
Definition: IRReader.cpp:68
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
Optional.h
StringRef.h
Context
LLVMContext & Context
Definition: NVVMIntrRange.cpp:66
llvm::getLazyIRFileModule
std::unique_ptr< Module > getLazyIRFileModule(StringRef Filename, SMDiagnostic &Err, LLVMContext &Context, bool ShouldLazyLoadMetadata=false)
If the given file holds a bitcode image, return a Module for it which does lazy deserialization of fu...
Definition: IRReader.cpp:52
STLForwardCompat.h
STLFunctionalExtras.h
llvm::None
const NoneType None
Definition: None.h:24
llvm::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLFunctionalExtras.h:36
Module
Machine Check Debug Module
Definition: MachineCheckDebugify.cpp:122
llvm::parseIRFile
std::unique_ptr< Module > parseIRFile(StringRef Filename, SMDiagnostic &Err, LLVMContext &Context, DataLayoutCallbackTy DataLayoutCallback=[](StringRef) { return None;})
If the given file holds a bitcode image, return a Module for it.
Definition: IRReader.cpp:92
llvm::getLazyIRModule
std::unique_ptr< Module > getLazyIRModule(std::unique_ptr< MemoryBuffer > Buffer, SMDiagnostic &Err, LLVMContext &Context, bool ShouldLazyLoadMetadata=false)
If the given MemoryBuffer holds a bitcode image, return a Module for it which does lazy deserializati...
Definition: IRReader.cpp:33
llvm::DataLayoutCallbackTy
llvm::function_ref< Optional< std::string >StringRef)> DataLayoutCallbackTy
Definition: Parser.h:31