llvm.org GIT mirror llvm / e2dc71d
[PM] Wire up support for writing bitcode with new PM. This moves the old pass creation functionality to its own header and updates the callers of that routine. Then it adds a new PM supporting bitcode writer to the header file, and wires that up in the opt tool. A test is added that round-trips code into bitcode and back out using the new pass manager. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199078 91177308-0d34-0410-b5e6-96231b3b80d8 Chandler Carruth 6 years ago
7 changed file(s) with 70 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
0 //===-- BitcodeWriterPass.h - Bitcode writing pass --------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 /// \file
9 ///
10 /// This file provides a bitcode writing pass.
11 ///
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_BITCODE_BITCODE_WRITER_PASS_H
15 #define LLVM_BITCODE_BITCODE_WRITER_PASS_H
16
17 #include "llvm/ADT/StringRef.h"
18
19 namespace llvm {
20 class Module;
21 class ModulePass;
22 class raw_ostream;
23 class PreservedAnalyses;
24
25 /// \brief Create and return a pass that writes the module to the specified
26 /// ostream. Note that this pass is designed for use with the legacy pass
27 /// manager.
28 ModulePass *createBitcodeWriterPass(raw_ostream &Str);
29
30 /// \brief Pass for writing a module of IR out to a bitcode file.
31 ///
32 /// Note that this is intended for use with the new pass manager. To construct
33 /// a pass for the legacy pass manager, use the function above.
34 class BitcodeWriterPass {
35 raw_ostream &OS;
36
37 public:
38 /// \brief Construct a bitcode writer pass around a particular output stream.
39 explicit BitcodeWriterPass(raw_ostream &OS) : OS(OS) {}
40
41 /// \brief Run the bitcode writer pass, and output the module to the selected
42 /// \brief output stream.
43 PreservedAnalyses run(Module *M);
44
45 static StringRef name() { return "BitcodeWriterPass"; }
46 };
47
48 }
49
50 #endif
6161 /// raw output stream. For streams where it matters, the given stream
6262 /// should be in "binary" mode.
6363 void WriteBitcodeToFile(const Module *M, raw_ostream &Out);
64
65 /// createBitcodeWriterPass - Create and return a pass that writes the module
66 /// to the specified ostream.
67 ModulePass *createBitcodeWriterPass(raw_ostream &Str);
6864
6965
7066 /// isBitcodeWrapper - Return true if the given bytes are the magic bytes
None //===--- Bitcode/Writer/BitcodeWriterPass.cpp - Bitcode Writer ------------===//
0 //===- BitcodeWriterPass.cpp - Bitcode writing pass -----------------------===//
11 //
22 // The LLVM Compiler Infrastructure
33 //
1010 //
1111 //===----------------------------------------------------------------------===//
1212
13 #include "llvm/Bitcode/BitcodeWriterPass.h"
1314 #include "llvm/Bitcode/ReaderWriter.h"
15 #include "llvm/IR/Module.h"
16 #include "llvm/IR/PassManager.h"
1417 #include "llvm/Pass.h"
1518 using namespace llvm;
19
20 PreservedAnalyses BitcodeWriterPass::run(Module *M) {
21 WriteBitcodeToFile(M, OS);
22 return PreservedAnalyses::all();
23 }
1624
1725 namespace {
1826 class WriteBitcodePass : public ModulePass {
3341
3442 char WriteBitcodePass::ID = 0;
3543
36 /// createBitcodeWriterPass - Create and return a pass that writes the module
37 /// to the specified ostream.
3844 ModulePass *llvm::createBitcodeWriterPass(raw_ostream &Str) {
3945 return new WriteBitcodePass(Str);
4046 }
2828 ; CHECK-NOOP: ret void
2929 ; CHECK-NOOP: }
3030
31 ; Round trip through bitcode.
32 ; RUN: opt -f -o - -passes='no-op-module,no-op-module' %s \
33 ; RUN: | llvm-dis \
34 ; RUN: | FileCheck %s --check-prefix=CHECK-NOOP
35
3136 define void @foo() {
3237 ret void
3338 }
1313
1414 #include "llvm/ADT/SetVector.h"
1515 #include "llvm/ADT/SmallPtrSet.h"
16 #include "llvm/Bitcode/ReaderWriter.h"
16 #include "llvm/Bitcode/BitcodeWriterPass.h"
1717 #include "llvm/IR/DataLayout.h"
1818 #include "llvm/IR/IRPrintingPasses.h"
1919 #include "llvm/IR/LLVMContext.h"
1515 #include "NewPMDriver.h"
1616 #include "Passes.h"
1717 #include "llvm/ADT/StringRef.h"
18 #include "llvm/Bitcode/BitcodeWriterPass.h"
1819 #include "llvm/IR/IRPrintingPasses.h"
1920 #include "llvm/IR/LLVMContext.h"
2021 #include "llvm/IR/Module.h"
4344 MPM.addPass(PrintModulePass(Out->os()));
4445 break;
4546 case OK_OutputBitcode:
46 llvm::report_fatal_error("Bitcode output is not yet implemented!");
47 MPM.addPass(BitcodeWriterPass(Out->os()));
48 break;
4749 }
4850
4951 // Before executing passes, print the final values of the LLVM options.
1919 #include "llvm/Analysis/LoopPass.h"
2020 #include "llvm/Analysis/RegionPass.h"
2121 #include "llvm/Analysis/Verifier.h"
22 #include "llvm/Bitcode/ReaderWriter.h"
22 #include "llvm/Bitcode/BitcodeWriterPass.h"
2323 #include "llvm/CodeGen/CommandFlags.h"
2424 #include "llvm/DebugInfo.h"
2525 #include "llvm/IR/DataLayout.h"