1 //===--- Debug.cpp -------- 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 // This file contains debug utilities
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "Debug.h"
14 #include "Configuration.h"
15 #include "Interface.h"
16 #include "Mapping.h"
17 #include "Types.h"
18 
19 using namespace _OMP;
20 
21 #pragma omp declare target
22 
23 extern "C" {
24 void __assert_assume(bool condition) { __builtin_assume(condition); }
25 
26 void __assert_fail(const char *assertion, const char *file, unsigned line,
27                    const char *function) {
28   PRINTF("%s:%u: %s: Assertion `%s' failed.\n", file, line, function,
29          assertion);
30   __builtin_trap();
31 }
32 }
33 
34 /// Current indentation level for the function trace. Only accessed by thread 0.
35 static uint32_t Level = 0;
36 #pragma omp allocate(Level) allocator(omp_pteam_mem_alloc)
37 
38 DebugEntryRAII::DebugEntryRAII(const char *File, const unsigned Line,
39                                const char *Function) {
40   if (config::isDebugMode(config::DebugKind::FunctionTracing) &&
41       mapping::getThreadIdInBlock() == 0 && mapping::getBlockId() == 0) {
42 
43     for (int I = 0; I < Level; ++I)
44       PRINTF("%s", "  ");
45 
46     PRINTF("%s:%u: Thread %u Entering %s\n", File, Line,
47            mapping::getThreadIdInBlock(), Function);
48     Level++;
49   }
50 }
51 
52 DebugEntryRAII::~DebugEntryRAII() {
53   if (config::isDebugMode(config::DebugKind::FunctionTracing) &&
54       mapping::getThreadIdInBlock() == 0 && mapping::getBlockId() == 0)
55     Level--;
56 }
57 
58 #pragma omp end declare target
59