Skip to content

Commit 2695936

Browse files
committed
Use a CMake macro for speedup
1 parent 7c971c5 commit 2695936

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

llvm/cmake/modules/LLVMProcessSources.cmake

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ function(llvm_process_sources OUT_VAR)
5858
set(sources ${ARG_UNPARSED_ARGUMENTS})
5959
llvm_check_source_file_list(${sources})
6060

61+
foreach(fn ${sources})
62+
get_filename_component(suf ${fn} EXT)
63+
if("${suf}" STREQUAL ".cpp" OR "${suf}" STREQUAL ".c")
64+
get_filename_component(short_name ${fn} NAME)
65+
set_source_files_properties(${fn} PROPERTIES COMPILE_DEFINITIONS "__SHORT_FILE__=\"${short_name}\"")
66+
endif()
67+
endforeach()
68+
69+
6170
# This adds .td and .h files to the Visual Studio solution:
6271
add_td_sources(sources)
6372
find_all_header_files(hdrs "${ARG_ADDITIONAL_HEADER_DIRS}")

llvm/include/llvm/Support/DebugLog.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,27 @@ namespace llvm {
2626
// << "] " << "Bitset contains: " << Bitset << "\n");
2727
#define LDBG() DEBUGLOG_WITH_STREAM_AND_TYPE(llvm::dbgs(), DEBUG_TYPE)
2828

29+
#if defined(__SHORT_FILE__)
2930
#define DEBUGLOG_WITH_STREAM_AND_TYPE(STREAM, TYPE) \
3031
for (bool _c = (::llvm::DebugFlag && ::llvm::isCurrentDebugType(TYPE)); _c; \
3132
_c = false) \
32-
::llvm::impl::LogWithNewline( \
33-
TYPE, \
34-
[] { \
35-
/* Force constexpr eval */ \
36-
constexpr const char *filename = \
37-
::llvm::impl::LogWithNewline::getFileName(__FILE__); \
38-
return filename; \
39-
}(), \
40-
__LINE__, (STREAM))
33+
::llvm::impl::LogWithNewline(TYPE, __SHORT_FILE__, __LINE__, (STREAM))
34+
#else
35+
#define DEBUGLOG_WITH_STREAM_AND_TYPE(STREAM, TYPE) \
36+
for (bool _c = (::llvm::DebugFlag && ::llvm::isCurrentDebugType(TYPE)); _c; \
37+
_c = false) \
38+
::llvm::impl::LogWithNewline(TYPE, __FILE__, __LINE__, (STREAM))
39+
#endif
4140

4241
namespace impl {
4342
class LogWithNewline {
4443
public:
4544
LogWithNewline(const char *debug_type, const char *file, int line,
4645
raw_ostream &os)
4746
: os(os) {
47+
#if !defined(__SHORT_FILE__)
48+
file = ::llvm::impl::LogWithNewline::getShortFileName(file);
49+
#endif
4850
if (debug_type)
4951
os << "[" << debug_type << "] ";
5052
os << file << ":" << line << " ";
@@ -59,7 +61,7 @@ class LogWithNewline {
5961
LogWithNewline(const LogWithNewline &) = delete;
6062
LogWithNewline &operator=(const LogWithNewline &) = delete;
6163
LogWithNewline &operator=(LogWithNewline &&) = delete;
62-
static constexpr const char *getFileName(const char *path) {
64+
static constexpr const char *getShortFileName(const char *path) {
6365
// Remove the path prefix from the file name.
6466
const char *filename = path;
6567
for (const char *p = path; *p != '\0'; ++p) {

0 commit comments

Comments
 (0)