llvm.org GIT mirror llvm / 2187597
Plumb the option to emit the `ModuleHash` in the bitcode through the bitcode writer APIs From: Mehdi Amini <mehdi.amini@apple.com> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@265907 91177308-0d34-0410-b5e6-96231b3b80d8 Mehdi Amini 4 years ago
2 changed file(s) with 18 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
2929 /// If \c ShouldPreserveUseListOrder, encode use-list order so it can be
3030 /// reproduced when deserialized.
3131 ///
32 /// If \c EmitSummaryIndex, emit the summary index (currently
33 /// for use in ThinLTO optimization).
32 /// If \c EmitSummaryIndex, emit the summary index (currently for use in ThinLTO
33 /// optimization).
34 ///
35 /// If \c EmitModuleHash, compute and emit the module hash in the bitcode
36 /// (currently for use in ThinLTO incremental build).
3437 ModulePass *createBitcodeWriterPass(raw_ostream &Str,
3538 bool ShouldPreserveUseListOrder = false,
36 bool EmitSummaryIndex = false);
39 bool EmitSummaryIndex = false,
40 bool EmitModuleHash = false);
3741
3842 /// \brief Pass for writing a module of IR out to a bitcode file.
3943 ///
4347 raw_ostream &OS;
4448 bool ShouldPreserveUseListOrder;
4549 bool EmitSummaryIndex;
50 bool EmitModuleHash;
4651
4752 public:
4853 /// \brief Construct a bitcode writer pass around a particular output stream.
5459 /// for use in ThinLTO optimization).
5560 explicit BitcodeWriterPass(raw_ostream &OS,
5661 bool ShouldPreserveUseListOrder = false,
57 bool EmitSummaryIndex = false)
62 bool EmitSummaryIndex = false,
63 bool EmitModuleHash = false)
5864 : OS(OS), ShouldPreserveUseListOrder(ShouldPreserveUseListOrder),
59 EmitSummaryIndex(EmitSummaryIndex) {}
65 EmitSummaryIndex(EmitSummaryIndex), EmitModuleHash(EmitModuleHash) {}
6066
6167 /// \brief Run the bitcode writer pass, and output the module to the selected
6268 /// output stream.
1818 using namespace llvm;
1919
2020 PreservedAnalyses BitcodeWriterPass::run(Module &M) {
21 WriteBitcodeToFile(&M, OS, ShouldPreserveUseListOrder, EmitSummaryIndex);
21 WriteBitcodeToFile(&M, OS, ShouldPreserveUseListOrder, EmitSummaryIndex, EmitModuleHash);
2222 return PreservedAnalyses::all();
2323 }
2424
2727 raw_ostream &OS; // raw_ostream to print on
2828 bool ShouldPreserveUseListOrder;
2929 bool EmitSummaryIndex;
30 bool EmitModuleHash;
3031
3132 public:
3233 static char ID; // Pass identification, replacement for typeid
3334 explicit WriteBitcodePass(raw_ostream &o, bool ShouldPreserveUseListOrder,
34 bool EmitSummaryIndex)
35 bool EmitSummaryIndex, bool EmitModuleHash)
3536 : ModulePass(ID), OS(o),
3637 ShouldPreserveUseListOrder(ShouldPreserveUseListOrder),
37 EmitSummaryIndex(EmitSummaryIndex) {}
38 EmitSummaryIndex(EmitSummaryIndex), EmitModuleHash(EmitModuleHash) {}
3839
3940 const char *getPassName() const override { return "Bitcode Writer"; }
4041
4142 bool runOnModule(Module &M) override {
42 WriteBitcodeToFile(&M, OS, ShouldPreserveUseListOrder, EmitSummaryIndex);
43 WriteBitcodeToFile(&M, OS, ShouldPreserveUseListOrder, EmitSummaryIndex, EmitModuleHash);
4344 return false;
4445 }
4546 };
4950
5051 ModulePass *llvm::createBitcodeWriterPass(raw_ostream &Str,
5152 bool ShouldPreserveUseListOrder,
52 bool EmitSummaryIndex) {
53 bool EmitSummaryIndex, bool EmitModuleHash) {
5354 return new WriteBitcodePass(Str, ShouldPreserveUseListOrder,
54 EmitSummaryIndex);
55 EmitSummaryIndex, EmitModuleHash);
5556 }