LLVM  14.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/Module.h"
17 #include "llvm/IR/PassManager.h"
18 #include "llvm/InitializePasses.h"
19 #include "llvm/Pass.h"
20 using namespace llvm;
21 
23  const ModuleSummaryIndex *Index =
24  EmitSummaryIndex ? &(AM.getResult<ModuleSummaryIndexAnalysis>(M))
25  : nullptr;
26  WriteBitcodeToFile(M, OS, ShouldPreserveUseListOrder, Index, EmitModuleHash);
27  return PreservedAnalyses::all();
28 }
29 
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;
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  bool EmitSummaryIndex, bool EmitModuleHash)
45  : ModulePass(ID), OS(o),
46  ShouldPreserveUseListOrder(ShouldPreserveUseListOrder),
47  EmitSummaryIndex(EmitSummaryIndex), EmitModuleHash(EmitModuleHash) {
49  }
50 
51  StringRef getPassName() const override { return "Bitcode Writer"; }
52 
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 }
69 
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)
76 
78  bool ShouldPreserveUseListOrder,
79  bool EmitSummaryIndex, bool EmitModuleHash) {
80  return new WriteBitcodePass(Str, ShouldPreserveUseListOrder,
81  EmitSummaryIndex, EmitModuleHash);
82 }
83 
85  return P->getPassID() == (llvm::AnalysisID)&WriteBitcodePass::ID;
86 }
llvm::PreservedAnalyses
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:155
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::ModulePass
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition: Pass.h:238
llvm::AnalysisManager::getResult
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:769
P
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
Definition: README-SSE.txt:411
Pass.h
llvm::write
Error write(MCStreamer &Out, ArrayRef< std::string > Inputs)
Definition: DWP.cpp:535
llvm::ModuleSummaryIndexAnalysis
Analysis pass to provide the ModuleSummaryIndex object.
Definition: ModuleSummaryAnalysis.h:44
bitcode
write bitcode
Definition: BitcodeWriterPass.cpp:74
llvm::AnalysisID
const void * AnalysisID
Definition: Pass.h:47
Module.h
llvm::createBitcodeWriterPass
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.
Definition: BitcodeWriterPass.cpp:77
ModuleSummaryAnalysis.h
BitcodeWriterPass.h
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
llvm::PassRegistry::getPassRegistry
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Definition: PassRegistry.cpp:31
llvm::initializeWriteBitcodePassPass
void initializeWriteBitcodePassPass(PassRegistry &)
BitcodeWriter.h
llvm::AnalysisUsage
Represent the analysis usage information of a pass.
Definition: PassAnalysisSupport.h:47
false
Definition: StackSlotColoring.cpp:142
INITIALIZE_PASS_BEGIN
INITIALIZE_PASS_BEGIN(WriteBitcodePass, "write-bitcode", "Write Bitcode", false, true) INITIALIZE_PASS_END(WriteBitcodePass
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
Bitcode
write Write Bitcode
Definition: BitcodeWriterPass.cpp:74
INITIALIZE_PASS_END
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:58
Index
uint32_t Index
Definition: ELFObjHandler.cpp:84
INITIALIZE_PASS_DEPENDENCY
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::WriteBitcodeToFile
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.
Definition: BitcodeWriter.cpp:4632
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::AnalysisUsage::setPreservesAll
void setPreservesAll()
Set by analyses that do not transform their input at all.
Definition: PassAnalysisSupport.h:130
llvm::PreservedAnalyses::all
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:161
PassManager.h
llvm::BitcodeWriterPass::run
PreservedAnalyses run(Module &M, ModuleAnalysisManager &)
Run the bitcode writer pass, and output the module to the selected output stream.
Definition: BitcodeWriterPass.cpp:22
llvm::Pass
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:91
llvm::ModuleSummaryIndex
Class to hold module path string table and global value map, and encapsulate methods for operating on...
Definition: ModuleSummaryIndex.h:1028
llvm::AnalysisManager
A container for analyses that lazily runs them and caches their results.
Definition: InstructionSimplify.h:44
llvm::AnalysisUsage::addRequired
AnalysisUsage & addRequired()
Definition: PassAnalysisSupport.h:75
llvm::ModuleSummaryIndexWrapperPass
Legacy wrapper pass to provide the ModuleSummaryIndex object.
Definition: ModuleSummaryAnalysis.h:57
true
basic Basic Alias true
Definition: BasicAliasAnalysis.cpp:1815
InitializePasses.h
llvm::isBitcodeWriterPass
bool isBitcodeWriterPass(Pass *P)
Check whether a pass is a BitcodeWriterPass.
Definition: BitcodeWriterPass.cpp:84
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:38