LLVM 20.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 report_fatal_error("Can only embed the module once",
28 /*gen_crash_diag=*/false);
29
30 Triple T(M.getTargetTriple());
31 if (T.getObjectFormat() != Triple::ELF)
33 "EmbedBitcode pass currently only supports ELF object format",
34 /*gen_crash_diag=*/false);
35
36 std::string Data;
38 if (IsThinLTO)
39 ThinLTOBitcodeWriterPass(OS, /*ThinLinkOS=*/nullptr).run(M, AM);
40 else
41 BitcodeWriterPass(OS, /*ShouldPreserveUseListOrder=*/false, EmitLTOSummary)
42 .run(M, AM);
43
44 embedBufferInModule(M, MemoryBufferRef(Data, "ModuleData"), ".llvm.lto");
45
47}
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:253
Pass for writing a module of IR out to a bitcode file.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &)
Run the bitcode writer pass, and output the module to the selected output stream.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &)
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:111
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: Analysis.h:117
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:661
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:167
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.