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 <memory>
22#include <string>
23
24using namespace llvm;
25
27 if (M.getGlobalVariable("llvm.embedded.module", /*AllowInternal=*/true))
28 report_fatal_error("Can only embed the module once",
29 /*gen_crash_diag=*/false);
30
31 Triple T(M.getTargetTriple());
32 if (T.getObjectFormat() != Triple::ELF)
34 "EmbedBitcode pass currently only supports ELF object format",
35 /*gen_crash_diag=*/false);
36
37 std::string Data;
39 if (IsThinLTO)
40 ThinLTOBitcodeWriterPass(OS, /*ThinLinkOS=*/nullptr).run(M, AM);
41 else
42 BitcodeWriterPass(OS, /*ShouldPreserveUseListOrder=*/false, EmitLTOSummary)
43 .run(M, AM);
44
45 embedBufferInModule(M, MemoryBufferRef(Data, "ModuleData"), ".llvm.lto");
46
48}
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.