LLVM 19.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 // RemoveDIs: there's no bitcode representation of the DPValue debug-info,
23 // convert to dbg.values before writing out.
24 bool IsNewDbgInfoFormat = M.IsNewDbgInfoFormat;
25 if (IsNewDbgInfoFormat)
26 M.convertFromNewDbgValues();
27
29 EmitSummaryIndex ? &(AM.getResult<ModuleSummaryIndexAnalysis>(M))
30 : nullptr;
31 WriteBitcodeToFile(M, OS, ShouldPreserveUseListOrder, Index, EmitModuleHash);
32
33 if (IsNewDbgInfoFormat)
34 M.convertToNewDbgValues();
35
37}
38
39namespace {
40 class WriteBitcodePass : public ModulePass {
41 raw_ostream &OS; // raw_ostream to print on
42 bool ShouldPreserveUseListOrder;
43
44 public:
45 static char ID; // Pass identification, replacement for typeid
46 WriteBitcodePass() : ModulePass(ID), OS(dbgs()) {
48 }
49
50 explicit WriteBitcodePass(raw_ostream &o, bool ShouldPreserveUseListOrder)
51 : ModulePass(ID), OS(o),
52 ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) {
54 }
55
56 StringRef getPassName() const override { return "Bitcode Writer"; }
57
58 bool runOnModule(Module &M) override {
59 // RemoveDIs: there's no bitcode representation of the DPValue debug-info,
60 // convert to dbg.values before writing out.
61 bool IsNewDbgInfoFormat = M.IsNewDbgInfoFormat;
62 if (IsNewDbgInfoFormat)
63 M.convertFromNewDbgValues();
64
65 WriteBitcodeToFile(M, OS, ShouldPreserveUseListOrder, /*Index=*/nullptr,
66 /*EmitModuleHash=*/false);
67
68 if (IsNewDbgInfoFormat)
69 M.convertToNewDbgValues();
70 return false;
71 }
72 void getAnalysisUsage(AnalysisUsage &AU) const override {
73 AU.setPreservesAll();
74 }
75 };
76}
77
78char WriteBitcodePass::ID = 0;
79INITIALIZE_PASS_BEGIN(WriteBitcodePass, "write-bitcode", "Write Bitcode", false,
80 true)
82INITIALIZE_PASS_END(WriteBitcodePass, "write-bitcode", "Write Bitcode", false,
83 true)
84
86 bool ShouldPreserveUseListOrder) {
87 return new WriteBitcodePass(Str, ShouldPreserveUseListOrder);
88}
89
91 return P->getPassID() == (llvm::AnalysisID)&WriteBitcodePass::ID;
92}
basic Basic Alias true
write Write Bitcode
write bitcode
This file provides a bitcode writing pass.
This is the interface to build a ModuleSummaryIndex for a module.
#define P(N)
This header defines various interfaces for pass management in LLVM.
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:55
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:59
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:52
raw_pwrite_stream & OS
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:348
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:500
Represent the analysis usage information of a pass.
void setPreservesAll()
Set by analyses that do not transform their input at all.
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:251
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:65
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:94
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:109
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: Analysis.h:115
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
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.
Definition: AddressRanges.h:18
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.
void initializeWriteBitcodePassPass(PassRegistry &)
Error write(MCStreamer &Out, ArrayRef< std::string > Inputs, OnCuIndexOverflow OverflowOptValue)
Definition: DWP.cpp:601
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
ModulePass * createBitcodeWriterPass(raw_ostream &Str, bool ShouldPreserveUseListOrder=false)
Create and return a pass that writes the module to the specified ostream.
const void * AnalysisID
Definition: Pass.h:50
bool isBitcodeWriterPass(Pass *P)
Check whether a pass is a BitcodeWriterPass.