104eeddc0SDimitry Andric //===- debug.h - Debugging output utilities ---------------------*- C++ -*-===// 204eeddc0SDimitry Andric // 304eeddc0SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 404eeddc0SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 504eeddc0SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 604eeddc0SDimitry Andric // 704eeddc0SDimitry Andric //===----------------------------------------------------------------------===// 804eeddc0SDimitry Andric // 904eeddc0SDimitry Andric // This file is a part of the ORC runtime support library. 1004eeddc0SDimitry Andric // 1104eeddc0SDimitry Andric //===----------------------------------------------------------------------===// 1204eeddc0SDimitry Andric 1304eeddc0SDimitry Andric #ifndef ORC_RT_DEBUG_H 1404eeddc0SDimitry Andric #define ORC_RT_DEBUG_H 1504eeddc0SDimitry Andric 1604eeddc0SDimitry Andric #include <atomic> 1704eeddc0SDimitry Andric 1804eeddc0SDimitry Andric #ifndef NDEBUG 1904eeddc0SDimitry Andric 2004eeddc0SDimitry Andric namespace __orc_rt { 2104eeddc0SDimitry Andric 2204eeddc0SDimitry Andric extern std::atomic<const char *> DebugTypes; 2304eeddc0SDimitry Andric extern char DebugTypesAll; 2404eeddc0SDimitry Andric extern char DebugTypesNone; 2504eeddc0SDimitry Andric 2604eeddc0SDimitry Andric const char *initializeDebug(); 2704eeddc0SDimitry Andric bool debugTypeEnabled(const char *Type, const char *Types); 2804eeddc0SDimitry Andric void printdbg(const char *format, ...); 2904eeddc0SDimitry Andric 3004eeddc0SDimitry Andric } // namespace __orc_rt 3104eeddc0SDimitry Andric 3204eeddc0SDimitry Andric #define ORC_RT_DEBUG_WITH_TYPE(TYPE, X) \ 3304eeddc0SDimitry Andric do { \ 3404eeddc0SDimitry Andric const char *Types = \ 3504eeddc0SDimitry Andric ::__orc_rt::DebugTypes.load(std::memory_order_relaxed); \ 3604eeddc0SDimitry Andric if (!Types) \ 3704eeddc0SDimitry Andric Types = initializeDebug(); \ 3804eeddc0SDimitry Andric if (Types == &DebugTypesNone) \ 3904eeddc0SDimitry Andric break; \ 4004eeddc0SDimitry Andric if (Types == &DebugTypesAll || \ 4104eeddc0SDimitry Andric ::__orc_rt::debugTypeEnabled(TYPE, Types)) { \ 4204eeddc0SDimitry Andric X; \ 4304eeddc0SDimitry Andric } \ 4404eeddc0SDimitry Andric } while (false) 4504eeddc0SDimitry Andric 4604eeddc0SDimitry Andric #else 4704eeddc0SDimitry Andric 4804eeddc0SDimitry Andric #define ORC_RT_DEBUG_WITH_TYPE(TYPE, X) \ 4904eeddc0SDimitry Andric do { \ 5004eeddc0SDimitry Andric } while (false) 5104eeddc0SDimitry Andric 5204eeddc0SDimitry Andric #endif // !NDEBUG 5304eeddc0SDimitry Andric 5404eeddc0SDimitry Andric #define ORC_RT_DEBUG(X) ORC_RT_DEBUG_WITH_TYPE(DEBUG_TYPE, X) 5504eeddc0SDimitry Andric 56*06c3fb27SDimitry Andric #endif // ORC_RT_DEBUG_H 57