LLVM 24.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
13#include "llvm/IR/PassManager.h"
14#include "llvm/Pass.h"
21
22#include <string>
23
24using namespace llvm;
25
27 raw_ostream &OS, function_ref<StringRef(StringRef)> MapClassName2PassName) {
28 static_cast<PassInfoMixin<EmbedBitcodePass> *>(this)->printPipeline(
29 OS, MapClassName2PassName);
30 if (!IsThinLTO && !EmitLTOSummary)
31 return;
32 ListSeparator LS(";");
33 OS << '<';
34 if (IsThinLTO)
35 OS << LS << "thinlto";
36 if (EmitLTOSummary)
37 OS << LS << "emit-summary";
38 OS << '>';
39}
40
42 if (M.getGlobalVariable("llvm.embedded.module", /*AllowInternal=*/true))
43 reportFatalUsageError("Can only embed the module once");
44
45 Triple T(M.getTargetTriple());
46 if (T.getObjectFormat() != Triple::ELF && T.getObjectFormat() != Triple::COFF)
47 reportFatalUsageError("EmbedBitcode pass currently only supports COFF and "
48 "ELF object formats");
49
50 std::string Data;
52 if (IsThinLTO)
53 ThinLTOBitcodeWriterPass(OS, /*ThinLinkOS=*/nullptr).run(M, AM);
54 else
55 BitcodeWriterPass(OS, /*ShouldPreserveUseListOrder=*/false, EmitLTOSummary)
56 .run(M, AM);
57
58 embedBufferInModule(M, MemoryBufferRef(Data, "ModuleData"), ".llvm.lto");
59
61}
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.
#define T
This file contains some functions that are useful when dealing with strings.
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 void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &)
A helper class to return the specified delimiter string after the first invocation of operator String...
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
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
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
An efficient, type-erasing, non-owning reference to a callable.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
A raw_ostream that writes to an std::string.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI GlobalVariable * embedBufferInModule(Module &M, MemoryBufferRef Buf, StringRef SectionName, Align Alignment=Align(1), bool SectionExclude=true)
Embed the memory buffer Buf into the module M as a global using the specified section name.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition MIRParser.h:39
LLVM_ABI void reportFatalUsageError(Error Err)
Report a fatal error that does not indicate a bug in LLVM.
Definition Error.cpp:177