|
29 | 29 | #include "logger/ur_logger.hpp" |
30 | 30 | #include "ur_util.hpp" |
31 | 31 |
|
| 32 | +#include "llvm/Support/Compiler.h" |
| 33 | + |
32 | 34 | // Helper for one-liner validation. Not really an assertion. To be renamed. |
33 | 35 | // For assertion that abort program use UR_DASSERT or UR_FASSERT from |
34 | 36 | // ur_logger.hpp |
35 | 37 | #define UR_ASSERT(condition, error) \ |
36 | | - if (!(condition)) \ |
| 38 | + if (LLVM_UNLIKELY(!(condition))) \ |
37 | 39 | return error; |
38 | 40 |
|
39 | 41 | // Trace an internal UR call; returns in case of an error. |
40 | 42 | #define UR_CALL(Call) \ |
41 | 43 | { \ |
42 | | - if (PrintTrace) \ |
| 44 | + ur_result_t Result; \ |
| 45 | + if (LLVM_UNLIKELY(PrintTrace)) { \ |
43 | 46 | UR_LOG(QUIET, "UR ---> {}", #Call); \ |
44 | | - ur_result_t Result = (Call); \ |
45 | | - if (PrintTrace) \ |
| 47 | + Result = (Call); \ |
46 | 48 | UR_LOG(QUIET, "UR <--- {}({})", #Call, Result); \ |
| 49 | + } else { \ |
| 50 | + Result = (Call); \ |
| 51 | + } \ |
47 | 52 | if (Result != UR_RESULT_SUCCESS) \ |
48 | 53 | return Result; \ |
49 | 54 | } |
50 | 55 |
|
51 | 56 | // Trace an internal UR call; throw in case of an error. |
52 | 57 | #define UR_CALL_THROWS(Call) \ |
53 | 58 | { \ |
54 | | - if (PrintTrace) \ |
| 59 | + ur_result_t Result; \ |
| 60 | + if (LLVM_UNLIKELY(PrintTrace)) { \ |
55 | 61 | UR_LOG(QUIET, "UR ---> {}", #Call); \ |
56 | | - ur_result_t Result = (Call); \ |
57 | | - if (PrintTrace) \ |
| 62 | + Result = (Call); \ |
58 | 63 | UR_LOG(QUIET, "UR <--- {}({})", #Call, Result); \ |
| 64 | + } else { \ |
| 65 | + Result = (Call); \ |
| 66 | + } \ |
59 | 67 | if (Result != UR_RESULT_SUCCESS) \ |
60 | 68 | throw Result; \ |
61 | 69 | } |
62 | 70 |
|
63 | 71 | // Trace an internal UR call; ignore errors (useful in destructors). |
64 | 72 | #define UR_CALL_NOCHECK(Call) \ |
65 | 73 | { \ |
66 | | - if (PrintTrace) \ |
| 74 | + if (LLVM_UNLIKELY(PrintTrace)) { \ |
67 | 75 | UR_LOG(QUIET, "UR ---> {}", #Call); \ |
68 | | - (void)(Call); \ |
69 | | - if (PrintTrace) \ |
| 76 | + (void)(Call); \ |
70 | 77 | UR_LOG(QUIET, "UR <--- {}", #Call); \ |
| 78 | + } else { \ |
| 79 | + (void)(Call); \ |
| 80 | + } \ |
71 | 81 | } |
72 | 82 |
|
73 | 83 | template <class To, class From> To ur_cast(From Value) { |
74 | 84 | // TODO: see if more sanity checks are possible. |
75 | | - assert(sizeof(From) == sizeof(To)); |
| 85 | + static_assert(sizeof(From) == sizeof(To), |
| 86 | + "Size of From and To must be equal"); |
| 87 | + // TODO: a very bad cast, change a to static_cast and fix all compiler |
| 88 | + // warnings |
76 | 89 | return (To)(Value); |
77 | 90 | } |
78 | 91 |
|
@@ -214,7 +227,7 @@ struct ur_dditable_t; |
214 | 227 | struct ur_platform {}; |
215 | 228 |
|
216 | 229 | // Controls tracing UR calls from within the UR itself. |
217 | | -extern bool PrintTrace; |
| 230 | +extern const bool PrintTrace; |
218 | 231 |
|
219 | 232 | // The getInfo*/ReturnHelper facilities provide shortcut way of |
220 | 233 | // writing return bytes for the various getInfo APIs. |
|
0 commit comments