From f9e4576e080501459e22e75775e6b931a8e7fd85 Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Sun, 10 Apr 2016 21:07:19 +0000 Subject: [PATCH] Plumb the option to emit the `ModuleHash` in the bitcode through the bitcode writer APIs From: Mehdi Amini llvm-svn: 265907 --- llvm/include/llvm/Bitcode/BitcodeWriterPass.h | 16 +++++++++++----- llvm/lib/Bitcode/Writer/BitcodeWriterPass.cpp | 13 +++++++------ 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/llvm/include/llvm/Bitcode/BitcodeWriterPass.h b/llvm/include/llvm/Bitcode/BitcodeWriterPass.h index a4521bf..dd0d577 100644 --- a/llvm/include/llvm/Bitcode/BitcodeWriterPass.h +++ b/llvm/include/llvm/Bitcode/BitcodeWriterPass.h @@ -30,11 +30,15 @@ class PreservedAnalyses; /// If \c ShouldPreserveUseListOrder, encode use-list order so it can be /// reproduced when deserialized. /// -/// If \c EmitSummaryIndex, emit the summary index (currently -/// for use in ThinLTO optimization). +/// If \c EmitSummaryIndex, emit the summary index (currently for use in ThinLTO +/// optimization). +/// +/// If \c EmitModuleHash, compute and emit the module hash in the bitcode +/// (currently for use in ThinLTO incremental build). ModulePass *createBitcodeWriterPass(raw_ostream &Str, bool ShouldPreserveUseListOrder = false, - bool EmitSummaryIndex = false); + bool EmitSummaryIndex = false, + bool EmitModuleHash = false); /// \brief Pass for writing a module of IR out to a bitcode file. /// @@ -44,6 +48,7 @@ class BitcodeWriterPass { raw_ostream &OS; bool ShouldPreserveUseListOrder; bool EmitSummaryIndex; + bool EmitModuleHash; public: /// \brief Construct a bitcode writer pass around a particular output stream. @@ -55,9 +60,10 @@ public: /// for use in ThinLTO optimization). explicit BitcodeWriterPass(raw_ostream &OS, bool ShouldPreserveUseListOrder = false, - bool EmitSummaryIndex = false) + bool EmitSummaryIndex = false, + bool EmitModuleHash = false) : OS(OS), ShouldPreserveUseListOrder(ShouldPreserveUseListOrder), - EmitSummaryIndex(EmitSummaryIndex) {} + EmitSummaryIndex(EmitSummaryIndex), EmitModuleHash(EmitModuleHash) {} /// \brief Run the bitcode writer pass, and output the module to the selected /// output stream. diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriterPass.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriterPass.cpp index 85b9bd8..7dbede4 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriterPass.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriterPass.cpp @@ -19,7 +19,7 @@ using namespace llvm; PreservedAnalyses BitcodeWriterPass::run(Module &M) { - WriteBitcodeToFile(&M, OS, ShouldPreserveUseListOrder, EmitSummaryIndex); + WriteBitcodeToFile(&M, OS, ShouldPreserveUseListOrder, EmitSummaryIndex, EmitModuleHash); return PreservedAnalyses::all(); } @@ -28,19 +28,20 @@ namespace { raw_ostream &OS; // raw_ostream to print on bool ShouldPreserveUseListOrder; bool EmitSummaryIndex; + bool EmitModuleHash; public: static char ID; // Pass identification, replacement for typeid explicit WriteBitcodePass(raw_ostream &o, bool ShouldPreserveUseListOrder, - bool EmitSummaryIndex) + bool EmitSummaryIndex, bool EmitModuleHash) : ModulePass(ID), OS(o), ShouldPreserveUseListOrder(ShouldPreserveUseListOrder), - EmitSummaryIndex(EmitSummaryIndex) {} + EmitSummaryIndex(EmitSummaryIndex), EmitModuleHash(EmitModuleHash) {} const char *getPassName() const override { return "Bitcode Writer"; } bool runOnModule(Module &M) override { - WriteBitcodeToFile(&M, OS, ShouldPreserveUseListOrder, EmitSummaryIndex); + WriteBitcodeToFile(&M, OS, ShouldPreserveUseListOrder, EmitSummaryIndex, EmitModuleHash); return false; } }; @@ -50,7 +51,7 @@ char WriteBitcodePass::ID = 0; ModulePass *llvm::createBitcodeWriterPass(raw_ostream &Str, bool ShouldPreserveUseListOrder, - bool EmitSummaryIndex) { + bool EmitSummaryIndex, bool EmitModuleHash) { return new WriteBitcodePass(Str, ShouldPreserveUseListOrder, - EmitSummaryIndex); + EmitSummaryIndex, EmitModuleHash); } -- 2.7.4