Debian Codegraph @

llvm-project/llvm/projects/llvm-spirv/lib/SPIRV/SPIRVWriterPass.h

raw
1 //===------ SPIRVWriterPass.h - SPIRV writing pass --------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 /// \file
10 ///
11 /// This file provides a SPIRV writing pass.
12 ///
13 //===----------------------------------------------------------------------===//
14
15 #ifndef SPIRV_SPIRVWRITERPASS_H
16 #define SPIRV_SPIRVWRITERPASS_H
17
18 #include "LLVMSPIRVOpts.h"
19 #include "llvm/ADT/StringRef.h"
20
21 namespace llvm {
22 class Module;
23 class ModulePass;
24 class PreservedAnalyses;
25
26 /// \brief Create and return a pass that writes the module to the specified
27 /// ostream. Note that this pass is designed for use with the legacy pass
28 /// manager.
29 ModulePass *createSPIRVWriterPass(std::ostream &Str);
30
31 /// \brief Create and return a pass that writes the module to the specified
32 /// ostream. Note that this pass is designed for use with the legacy pass
33 /// manager.
34 ModulePass *createSPIRVWriterPass(std::ostream &Str,
35 const SPIRV::TranslatorOpts &Opts);
36
37 /// \brief Pass for writing a module of IR out to a SPIRV file.
38 ///
39 /// Note that this is intended for use with the new pass manager. To construct
40 /// a pass for the legacy pass manager, use the function above.
41 class SPIRVWriterPass {
42 std::ostream &OS;
43 SPIRV::TranslatorOpts Opts;
44
45 public:
46 /// \brief Construct a SPIRV writer pass around a particular output stream.
47 explicit SPIRVWriterPass(std::ostream &OS) : OS(OS) {
48 Opts.enableAllExtensions();
49 }
50 SPIRVWriterPass(std::ostream &OS, const SPIRV::TranslatorOpts &Opts)
51 : OS(OS), Opts(Opts) {}
52
53 /// \brief Run the SPIRV writer pass, and output the module to the selected
54 /// output stream.
55 PreservedAnalyses run(Module &M);
56
57 static StringRef name() { return "SPIRVWriterPass"; }
58 };
59
60 } // namespace llvm
61
62 #endif // SPIRV_SPIRVWRITERPASS_H