DPC++ Runtime
Runtime libraries for oneAPI DPC++
common.cpp
Go to the documentation of this file.
1 //==----------- common.cpp -----------------------------------------------==//
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 #include <sycl/detail/common.hpp>
10 
11 namespace sycl {
12 inline namespace _V1 {
13 namespace detail {
19 static thread_local detail::code_location GCodeLocTLS = {};
20 
25  // Check TLS to see if a previously stashed code_location object is
26  // available; if so, we are in a local scope.
27  MLocalScope = GCodeLocTLS.fileName() && GCodeLocTLS.functionName();
28 }
29 
36  // Check TLS to see if a previously stashed code_location object is
37  // available; if so, then don't overwrite the previous information as we
38  // are still in scope of the instrumented function
39  MLocalScope = GCodeLocTLS.fileName() && GCodeLocTLS.functionName();
40 
41  if (!MLocalScope)
42  // Update the TLS information with the code_location information
43  GCodeLocTLS = CodeLoc;
44 }
45 
48  // Only reset the TLS data if the top level function is going out of scope
49  if (!MLocalScope) {
50  GCodeLocTLS = {};
51  }
52 }
53 
55 
56 const char *stringifyErrorCode(pi_int32 error) {
57  switch (error) {
58 #define _PI_ERRC(NAME, VAL) \
59  case NAME: \
60  return #NAME;
61 #define _PI_ERRC_WITH_MSG(NAME, VAL, MSG) \
62  case NAME: \
63  return MSG;
64 #include <sycl/detail/pi_error.def>
65 #undef _PI_ERRC
66 #undef _PI_ERRC_WITH_MSG
67 
68  default:
69  return "Unknown error code";
70  }
71 }
72 } // namespace detail
73 } // namespace _V1
74 } // namespace sycl
tls_code_loc_t()
Consructor that checks to see if a TLS entry already exists.
Definition: common.cpp:24
const detail::code_location & query()
Query the information in the TLS slot.
Definition: common.cpp:54
~tls_code_loc_t()
If the code location is set up by this instance, reset it.
Definition: common.cpp:47
const char * stringifyErrorCode(pi_int32 error)
Definition: common.cpp:56
static thread_local detail::code_location GCodeLocTLS
CodeLocation information slot in thread local storage.
Definition: common.cpp:19
Definition: access.hpp:18
int32_t pi_int32
Definition: pi.h:212
constexpr const char * fileName() const noexcept
Definition: common.hpp:89
constexpr const char * functionName() const noexcept
Definition: common.hpp:90