LLVM 22.0.0git
EmbedBitcodePass.cpp
Go to the documentation of this file.
1//===- EmbedBitcodePass.cpp - Pass that embeds the bitcode into a global---===//
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
12#include "llvm/IR/PassManager.h"
13#include "llvm/Pass.h"
20
21#include <string>
22
23using namespace llvm;
24
26 if (M.getGlobalVariable("llvm.embedded.module", /*AllowInternal=*/true))
27 reportFatalUsageError("Can only embed the module once");
28
29 Triple T(M.getTargetTriple());
30 if (T.getObjectFormat() != Triple::ELF)
32 "EmbedBitcode pass currently only supports ELF object format");
33
34 std::string Data;
36 if (IsThinLTO)
37 ThinLTOBitcodeWriterPass(OS, /*ThinLinkOS=*/nullptr).run(M, AM);
38 else
39 BitcodeWriterPass(OS, /*ShouldPreserveUseListOrder=*/false, EmitLTOSummary)
40 .run(M, AM);
41
42 embedBufferInModule(M, MemoryBufferRef(Data, "ModuleData"), ".llvm.lto");
43
45}
This file provides a bitcode writing pass.
This file provides a pass which clones the current module and runs the provided pass pipeline on the ...
This header defines various interfaces for pass management in LLVM.
raw_pwrite_stream & OS
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:255
Pass for writing a module of IR out to a bitcode file.
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &)
Run the bitcode writer pass, and output the module to the selected output stream.
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &)
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:112
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
Definition: Analysis.h:115
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:47
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:662
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
LLVM_ABI void embedBufferInModule(Module &M, MemoryBufferRef Buf, StringRef SectionName, Align Alignment=Align(1))
Embed the memory buffer Buf into the module M as a global using the specified section name.
LLVM_ABI void reportFatalUsageError(Error Err)
Report a fatal error that does not indicate a bug in LLVM.
Definition: Error.cpp:180