[llvm] [llvm][support] Add LLVM_DLOG macro. (PR #143704)
Mehdi Amini via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 8 08:18:25 PDT 2025
================
@@ -0,0 +1,69 @@
+//===- llvm/Support/DebugLog.h - Logging like debug output ------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+// This file contains macros for logging like debug output. It builds upon the
+// support in Debug.h but provides a utility function for common debug output
+// style.
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_SUPPORT_DEBUGLOG_H
+#define LLVM_SUPPORT_DEBUGLOG_H
+
+#include "llvm/Support/Debug.h"
+#include "llvm/Support/raw_ostream.h"
+
+namespace llvm {
+#ifndef NDEBUG
+
+// Output with given inputs and trailing newline. E.g.,
+// LLVM_DLOG() << "Bitset contains: " << Bitset;
+// is equivalent to
+// LLVM_DEBUG(dbgs() << DEBUG_TYPE << " " << __FILE__ << ":" << __LINE__
+// << "] " << "Bitset contains: " << Bitset << "\n");
----------------
joker-eph wrote:
Unfortunately I don't believe this is strictly equivalent.
The reason LLVM_DEBUG is designed this way is to protect against function call in the streaming sequence, some of which may be costly, have side-effects, and also bring in more symbols to link in the final binary (some of them that may not be available in release mode by the way).
https://github.com/llvm/llvm-project/pull/143704
More information about the llvm-commits
mailing list