LLVM 22.0.0git
BitcodeWriterPass.cpp
Go to the documentation of this file.
1//===- BitcodeWriterPass.cpp - Bitcode writing pass -----------------------===//
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// BitcodeWriterPass implementation.
10//
11//===----------------------------------------------------------------------===//
12
16#include "llvm/IR/PassManager.h"
18#include "llvm/Pass.h"
19using namespace llvm;
20
22 M.removeDebugIntrinsicDeclarations();
23
24 const ModuleSummaryIndex *Index =
25 EmitSummaryIndex ? &(AM.getResult<ModuleSummaryIndexAnalysis>(M))
26 : nullptr;
27 WriteBitcodeToFile(M, OS, ShouldPreserveUseListOrder, Index, EmitModuleHash);
28
30}
31
32namespace {
33 class WriteBitcodePass : public ModulePass {
34 raw_ostream &OS; // raw_ostream to print on
35 bool ShouldPreserveUseListOrder;
36
37 public:
38 static char ID; // Pass identification, replacement for typeid
39 WriteBitcodePass() : ModulePass(ID), OS(dbgs()) {
41 }
42
43 explicit WriteBitcodePass(raw_ostream &o, bool ShouldPreserveUseListOrder)
44 : ModulePass(ID), OS(o),
45 ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) {
47 }
48
49 StringRef getPassName() const override { return "Bitcode Writer"; }
50
51 bool runOnModule(Module &M) override {
52 M.removeDebugIntrinsicDeclarations();
53
54 WriteBitcodeToFile(M, OS, ShouldPreserveUseListOrder, /*Index=*/nullptr,
55 /*EmitModuleHash=*/false);
56
57 return false;
58 }
59 void getAnalysisUsage(AnalysisUsage &AU) const override {
60 AU.setPreservesAll();
61 }
62 };
63}
64
65char WriteBitcodePass::ID = 0;
66INITIALIZE_PASS_BEGIN(WriteBitcodePass, "write-bitcode", "Write Bitcode", false,
67 true)
69INITIALIZE_PASS_END(WriteBitcodePass, "write-bitcode", "Write Bitcode", false,
70 true)
71
73 bool ShouldPreserveUseListOrder) {
74 return new WriteBitcodePass(Str, ShouldPreserveUseListOrder);
75}
76
78 return P->getPassID() == (llvm::AnalysisID)&WriteBitcodePass::ID;
79}
This file provides a bitcode writing pass.
This header defines various interfaces for pass management in LLVM.
Machine Check Debug Module
This is the interface to build a ModuleSummaryIndex for a module.
#define P(N)
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition PassSupport.h:42
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition PassSupport.h:44
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
Definition PassSupport.h:39
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
void setPreservesAll()
Set by analyses that do not transform their input at all.
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &)
Run the bitcode writer pass, and output the module to the selected output stream.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition Pass.h:255
Analysis pass to provide the ModuleSummaryIndex object.
Legacy wrapper pass to provide the ModuleSummaryIndex object.
Class to hold module path string table and global value map, and encapsulate methods for operating on...
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Pass interface - Implemented by all 'passes'.
Definition Pass.h:99
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI void WriteBitcodeToFile(const Module &M, raw_ostream &Out, bool ShouldPreserveUseListOrder=false, const ModuleSummaryIndex *Index=nullptr, bool GenerateHash=false, ModuleHash *ModHash=nullptr)
Write the specified module to the specified raw output stream.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:207
LLVM_ABI ModulePass * createBitcodeWriterPass(raw_ostream &Str, bool ShouldPreserveUseListOrder=false)
Create and return a pass that writes the module to the specified ostream.
LLVM_ABI bool isBitcodeWriterPass(Pass *P)
Check whether a pass is a BitcodeWriterPass.
LLVM_ABI void initializeWriteBitcodePassPass(PassRegistry &)
const void * AnalysisID
Definition Pass.h:51
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition MIRParser.h:39