LLVM  12.0.0git
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 //===----------------------------------------------------------------------===//
16 #include "llvm/IR/Module.h"
17 #include "llvm/IR/PassManager.h"
18 #include "llvm/InitializePasses.h"
19 #include "llvm/Pass.h"
20 using namespace llvm;
23  const ModuleSummaryIndex *Index =
24  EmitSummaryIndex ? &(AM.getResult<ModuleSummaryIndexAnalysis>(M))
25  : nullptr;
26  WriteBitcodeToFile(M, OS, ShouldPreserveUseListOrder, Index, EmitModuleHash);
27  return PreservedAnalyses::all();
28 }
30 namespace {
31  class WriteBitcodePass : public ModulePass {
32  raw_ostream &OS; // raw_ostream to print on
33  bool ShouldPreserveUseListOrder;
34  bool EmitSummaryIndex;
35  bool EmitModuleHash;
37  public:
38  static char ID; // Pass identification, replacement for typeid
39  WriteBitcodePass() : ModulePass(ID), OS(dbgs()) {
41  }
43  explicit WriteBitcodePass(raw_ostream &o, bool ShouldPreserveUseListOrder,
44  bool EmitSummaryIndex, bool EmitModuleHash)
45  : ModulePass(ID), OS(o),
46  ShouldPreserveUseListOrder(ShouldPreserveUseListOrder),
47  EmitSummaryIndex(EmitSummaryIndex), EmitModuleHash(EmitModuleHash) {
49  }
51  StringRef getPassName() const override { return "Bitcode Writer"; }
53  bool runOnModule(Module &M) override {
54  const ModuleSummaryIndex *Index =
55  EmitSummaryIndex
56  ? &(getAnalysis<ModuleSummaryIndexWrapperPass>().getIndex())
57  : nullptr;
58  WriteBitcodeToFile(M, OS, ShouldPreserveUseListOrder, Index,
59  EmitModuleHash);
60  return false;
61  }
62  void getAnalysisUsage(AnalysisUsage &AU) const override {
63  AU.setPreservesAll();
64  if (EmitSummaryIndex)
66  }
67  };
68 }
70 char WriteBitcodePass::ID = 0;
71 INITIALIZE_PASS_BEGIN(WriteBitcodePass, "write-bitcode", "Write Bitcode", false,
72  true)
74 INITIALIZE_PASS_END(WriteBitcodePass, "write-bitcode", "Write Bitcode", false,
75  true)
78  bool ShouldPreserveUseListOrder,
79  bool EmitSummaryIndex, bool EmitModuleHash) {
80  return new WriteBitcodePass(Str, ShouldPreserveUseListOrder,
81  EmitSummaryIndex, EmitModuleHash);
82 }
85  return P->getPassID() == (llvm::AnalysisID)&WriteBitcodePass::ID;
86 }
Pass interface - Implemented by all &#39;passes&#39;.
Definition: Pass.h:77
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:769
This class represents lattice values for constants.
Definition: AllocatorList.h:23
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:67
This is the interface to build a ModuleSummaryIndex for a module.
This file provides a bitcode writing pass.
Analysis pass to provide the ModuleSummaryIndex object.
INITIALIZE_PASS_BEGIN(WriteBitcodePass, "write-bitcode", "Write Bitcode", false, true) INITIALIZE_PASS_END(WriteBitcodePass
AnalysisUsage & addRequired()
write bitcode
bool isBitcodeWriterPass(Pass *P)
Check whether a pass is a BitcodeWriterPass.
Class to hold module path string table and global value map, and encapsulate methods for operating on...
#define P(N)
void initializeWriteBitcodePassPass(PassRegistry &)
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:154
AnalysisID getPassID() const
getPassID - Return the PassID number that corresponds to this pass.
Definition: Pass.h:96
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.
Represent the analysis usage information of a pass.
static void write(bool isBE, void *P, T V)
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:160
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
write Write Bitcode
Module.h This file contains the declarations for the Module class.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
const void * AnalysisID
Definition: Pass.h:47
void setPreservesAll()
Set by analyses that do not transform their input at all.
basic Basic Alias true
ModulePass * createBitcodeWriterPass(raw_ostream &Str, bool ShouldPreserveUseListOrder=false, bool EmitSummaryIndex=false, bool EmitModuleHash=false)
Create and return a pass that writes the module to the specified ostream.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition: Pass.h:224
PreservedAnalyses run(Module &M, ModuleAnalysisManager &)
Run the bitcode writer pass, and output the module to the selected output stream. ...
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
A container for analyses that lazily runs them and caches their results.
This header defines various interfaces for pass management in LLVM.
Legacy wrapper pass to provide the ModuleSummaryIndex object.