Debian Codegraph @

llvm-project/llvm/projects/llvm-spirv/lib/SPIRV/libSPIRV/SPIRVDebug.h

raw
1 //===- SPIRVDebug.h - SPIR-V Debug Utility ----------------------*- C++ -*-===//
2 //
3 // The LLVM/SPIRV Translator
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 // Copyright (c) 2014 Advanced Micro Devices, Inc. All rights reserved.
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining a
11 // copy of this software and associated documentation files (the "Software"),
12 // to deal with the Software without restriction, including without limitation
13 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 // and/or sell copies of the Software, and to permit persons to whom the
15 // Software is furnished to do so, subject to the following conditions:
16 //
17 // Redistributions of source code must retain the above copyright notice,
18 // this list of conditions and the following disclaimers.
19 // Redistributions in binary form must reproduce the above copyright notice,
20 // this list of conditions and the following disclaimers in the documentation
21 // and/or other materials provided with the distribution.
22 // Neither the names of Advanced Micro Devices, Inc., nor the names of its
23 // contributors may be used to endorse or promote products derived from this
24 // Software without specific prior written permission.
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28 // CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH
31 // THE SOFTWARE.
32 //
33 //===----------------------------------------------------------------------===//
34 /// \file
35 ///
36 /// This file defines Macros and variables for debugging SPIRV.
37 ///
38 //===----------------------------------------------------------------------===//
39
40 #ifndef SPIRV_LIBSPIRV_SPIRVDEBUG_H
41 #define SPIRV_LIBSPIRV_SPIRVDEBUG_H
42
43 #include "SPIRVUtil.h"
44
45 #include <iostream>
46 #include <string>
47
48 namespace llvm {
49 class Module;
50 }
51
52 namespace SPIRV {
53
54 // Include source file and line number in error message.
55 extern bool SPIRVDbgErrorMsgIncludesSourceInfo;
56
57 // Enable assert or exit on error
58 enum class SPIRVDbgErrorHandlingKinds { Abort, Exit, Ignore };
59 extern SPIRVDbgErrorHandlingKinds SPIRVDbgError;
60
61 // Enable debug output.
62 extern bool SPIRVDbgEnable;
63
64 void verifyRegularizationPass(llvm::Module &, const std::string &);
65
66 #ifndef _SPIRVDBG
67 #if !defined(NDEBUG) || defined(_DEBUG)
68 #define _SPIRVDBG true
69 #else
70 #define _SPIRVDBG false
71 #endif
72 #endif
73
74 #if _SPIRVDBG
75
76 #define SPIRVDBG(x) \
77 if (SPIRVDbgEnable) { \
78 x; \
79 }
80
81 // Output stream for SPIRV debug information.
82 inline spv_ostream &spvdbgs() {
83 return std::cerr;
84 }
85
86 #else
87
88 #define SPIRVDBG(x)
89
90 // Minimal std::basic_ostream mock that ignores everything being printed via
91 // operator<<
92 class dev_null_stream {
93 public:
94 void flush() {}
95 };
96
97 template <typename T>
98 const dev_null_stream &operator<<(const dev_null_stream &Out, const T &) {
99 return Out;
100 }
101
102 template <typename T>
103 const dev_null_stream &&operator<<(const dev_null_stream &&Out, const T &) {
104 return std::move(Out);
105 }
106
107 // Output stream for SPIRV debug information.
108 inline dev_null_stream &spvdbgs() {
109 static dev_null_stream Out;
110 return Out;
111 }
112
113 #endif
114
115 } // namespace SPIRV
116 #endif // SPIRV_LIBSPIRV_SPIRVDEBUG_H