1 //===-------- Debug.h ---- Debug utilities ------------------------ C++ -*-===//
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 //
10 //===----------------------------------------------------------------------===//
11 
12 #ifndef OMPTARGET_DEVICERTL_DEBUG_H
13 #define OMPTARGET_DEVICERTL_DEBUG_H
14 
15 #include "Configuration.h"
16 
17 /// Assertion
18 ///
19 /// {
20 extern "C" {
21 void __assert_assume(bool condition);
22 void __assert_fail(const char *assertion, const char *file, unsigned line,
23                    const char *function);
24 }
25 
26 #define ASSERT(expr)                                                           \
27   {                                                                            \
28     if (config::isDebugMode(config::DebugKind::Assertion) && !(expr))          \
29       __assert_fail(#expr, __FILE__, __LINE__, __PRETTY_FUNCTION__);           \
30     else                                                                       \
31       __assert_assume(expr);                                                   \
32   }
33 
34 ///}
35 
36 /// Print
37 /// printf() calls are rewritten by CGGPUBuiltin to __llvm_omp_vprintf
38 /// {
39 
40 extern "C" {
41 int printf(const char *format, ...);
42 }
43 
44 #define PRINTF(fmt, ...) (void)printf(fmt, ##__VA_ARGS__);
45 #define PRINT(str) PRINTF("%s", str)
46 
47 ///}
48 
49 /// Enter a debugging scope for performing function traces. Enabled with
50 /// FunctionTracting set in the debug kind.
51 #define FunctionTracingRAII()                                                  \
52   DebugEntryRAII Entry(__FILE__, __LINE__, __PRETTY_FUNCTION__);
53 
54 /// An RAII class for handling entries to debug locations. The current location
55 /// and function will be printed on entry. Nested levels increase the
56 /// indentation shown in the debugging output.
57 struct DebugEntryRAII {
58   DebugEntryRAII(const char *File, const unsigned Line, const char *Function);
59   ~DebugEntryRAII();
60 
61   static void init();
62 };
63 
64 #endif
65