1 //===- DXILWriterPass.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 // DXILWriterPass implementation.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "DXILWriterPass.h"
14 #include "DXILBitcodeWriter.h"
15 #include "llvm/ADT/DenseMap.h"
16 #include "llvm/ADT/StringRef.h"
17 #include "llvm/Analysis/ModuleSummaryAnalysis.h"
18 #include "llvm/IR/Module.h"
19 #include "llvm/IR/PassManager.h"
20 #include "llvm/InitializePasses.h"
21 #include "llvm/Pass.h"
22 
23 using namespace llvm;
24 using namespace llvm::dxil;
25 
26 namespace {
27 class WriteDXILPass : public llvm::ModulePass {
28   raw_ostream &OS; // raw_ostream to print on
29 
30 public:
31   static char ID; // Pass identification, replacement for typeid
32   WriteDXILPass() : ModulePass(ID), OS(dbgs()) {
33     initializeWriteDXILPassPass(*PassRegistry::getPassRegistry());
34   }
35 
36   explicit WriteDXILPass(raw_ostream &o) : ModulePass(ID), OS(o) {
37     initializeWriteDXILPassPass(*PassRegistry::getPassRegistry());
38   }
39 
40   StringRef getPassName() const override { return "Bitcode Writer"; }
41 
42   bool runOnModule(Module &M) override {
43     WriteDXILToFile(M, OS);
44     return false;
45   }
46   void getAnalysisUsage(AnalysisUsage &AU) const override {
47     AU.setPreservesAll();
48   }
49 };
50 } // namespace
51 
52 char WriteDXILPass::ID = 0;
53 INITIALIZE_PASS_BEGIN(WriteDXILPass, "write-bitcode", "Write Bitcode", false,
54                       true)
55 INITIALIZE_PASS_DEPENDENCY(ModuleSummaryIndexWrapperPass)
56 INITIALIZE_PASS_END(WriteDXILPass, "write-bitcode", "Write Bitcode", false,
57                     true)
58 
59 ModulePass *llvm::createDXILWriterPass(raw_ostream &Str) {
60   return new WriteDXILPass(Str);
61 }
62