[llvm] [NFC] Add explicit #include config.h where its macros are used. (PR #108077)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 11 08:30:29 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-support
@llvm/pr-subscribers-platform-windows
Author: Daniil Fukalov (dfukalov)
<details>
<summary>Changes</summary>
Without these explicit includes, removing other headers, who implicitly include `config.h`, may have non-trivial side effects. For example, `clangd` may report even `config.h` as "no used" in case it defines a macro, that is explicitly used with `#ifdef`. It is actually amplified with different build configs which use different set of macros.
---
Full diff: https://github.com/llvm/llvm-project/pull/108077.diff
13 Files Affected:
- (modified) llvm/include/llvm/Support/FileSystem.h (+1)
- (modified) llvm/lib/Support/Unix/DynamicLibrary.inc (+2)
- (modified) llvm/lib/Support/Unix/Path.inc (+1)
- (modified) llvm/lib/Support/Unix/Threading.inc (+1)
- (modified) llvm/lib/Support/Windows/explicit_symbols.inc (+1)
- (modified) llvm/lib/TargetParser/Host.cpp (+1)
- (modified) llvm/tools/llvm-exegesis/lib/Assembler.cpp (+1-1)
- (modified) llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp (+1)
- (modified) llvm/tools/llvm-exegesis/lib/X86/Target.cpp (+2-2)
- (modified) llvm/tools/llvm-exegesis/lib/X86/X86Counter.cpp (+1)
- (modified) llvm/tools/llvm-exegesis/lib/X86/X86Counter.h (+1)
- (modified) llvm/tools/llvm-exegesis/llvm-exegesis.cpp (+1)
- (modified) llvm/unittests/Support/ProcessTest.cpp (+1)
``````````diff
diff --git a/llvm/include/llvm/Support/FileSystem.h b/llvm/include/llvm/Support/FileSystem.h
index 9cf53360b4e966..f8ee00e842defa 100644
--- a/llvm/include/llvm/Support/FileSystem.h
+++ b/llvm/include/llvm/Support/FileSystem.h
@@ -29,6 +29,7 @@
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
+#include "llvm/Config/config.h" // for HAVE_SYS_STAT_H
#include "llvm/Config/llvm-config.h"
#include "llvm/Support/Chrono.h"
#include "llvm/Support/Error.h"
diff --git a/llvm/lib/Support/Unix/DynamicLibrary.inc b/llvm/lib/Support/Unix/DynamicLibrary.inc
index 7b77da5e0c6b28..d317dc53ecec3e 100644
--- a/llvm/lib/Support/Unix/DynamicLibrary.inc
+++ b/llvm/lib/Support/Unix/DynamicLibrary.inc
@@ -10,6 +10,8 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/Config/config.h" // for HAVE_DLFCN_H, HAVE_DLOPEN
+
#if defined(HAVE_DLFCN_H) && defined(HAVE_DLOPEN)
#include <dlfcn.h>
diff --git a/llvm/lib/Support/Unix/Path.inc b/llvm/lib/Support/Unix/Path.inc
index 44097bad7b46ed..b08ada816b1002 100644
--- a/llvm/lib/Support/Unix/Path.inc
+++ b/llvm/lib/Support/Unix/Path.inc
@@ -16,6 +16,7 @@
//===----------------------------------------------------------------------===//
#include "Unix.h"
+#include "llvm/Config/config.h" // for HAVE_DLFCN_H, HAVE_DLADDR, HAVE_FCNTL_H, HAVE_FUTIMENS, HAVE_FUTIMES, HAVE_PREAD, HAVE_SYS_STAT_H, HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC, HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC, HAVE_UNISTD_H
#include <limits.h>
#include <stdio.h>
#if HAVE_SYS_STAT_H
diff --git a/llvm/lib/Support/Unix/Threading.inc b/llvm/lib/Support/Unix/Threading.inc
index 43e18c3a963abf..65f1e9e2c399b5 100644
--- a/llvm/lib/Support/Unix/Threading.inc
+++ b/llvm/lib/Support/Unix/Threading.inc
@@ -16,6 +16,7 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
+#include "llvm/Config/config.h" // for HAVE_PTHREAD_GETNAME_NP, HAVE_PTHREAD_SETNAME_NP
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/raw_ostream.h"
diff --git a/llvm/lib/Support/Windows/explicit_symbols.inc b/llvm/lib/Support/Windows/explicit_symbols.inc
index 39c34f3f0b2d2e..5c6b8a4ba61d87 100644
--- a/llvm/lib/Support/Windows/explicit_symbols.inc
+++ b/llvm/lib/Support/Windows/explicit_symbols.inc
@@ -1,4 +1,5 @@
/* in libgcc.a */
+#include "llvm/Config/config.h" // for HAVE__* macros
#ifdef HAVE__ALLOCA
EXPLICIT_SYMBOL(_alloca)
diff --git a/llvm/lib/TargetParser/Host.cpp b/llvm/lib/TargetParser/Host.cpp
index 986b9a211ce6c1..400cb1f4f2444e 100644
--- a/llvm/lib/TargetParser/Host.cpp
+++ b/llvm/lib/TargetParser/Host.cpp
@@ -15,6 +15,7 @@
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSwitch.h"
+#include "llvm/Config/config.h" // for LLVM_VERSION_PRINTER_SHOW_HOST_TARGET_INFO
#include "llvm/Config/llvm-config.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/raw_ostream.h"
diff --git a/llvm/tools/llvm-exegesis/lib/Assembler.cpp b/llvm/tools/llvm-exegesis/lib/Assembler.cpp
index 92ab3a96d91e6b..f6f268736705f5 100644
--- a/llvm/tools/llvm-exegesis/lib/Assembler.cpp
+++ b/llvm/tools/llvm-exegesis/lib/Assembler.cpp
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
#include "Assembler.h"
-
#include "SnippetRepetitor.h"
#include "SubprocessMemory.h"
#include "Target.h"
@@ -22,6 +21,7 @@
#include "llvm/CodeGen/TargetLowering.h"
#include "llvm/CodeGen/TargetPassConfig.h"
#include "llvm/CodeGen/TargetSubtargetInfo.h"
+#include "llvm/Config/config.h" // for HAVE_LIBPFM
#include "llvm/ExecutionEngine/Orc/LLJIT.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Instructions.h"
diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
index 4e60d33fa2c637..e9bff521a78969 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
@@ -18,6 +18,7 @@
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
+#include "llvm/Config/config.h" // for HAVE_LIBPFM, HAVE_BUILTIN_THREAD_POINTER
#include "llvm/Config/llvm-config.h" // for LLVM_ON_UNIX
#include "llvm/Support/CrashRecoveryContext.h"
#include "llvm/Support/Error.h"
diff --git a/llvm/tools/llvm-exegesis/lib/X86/Target.cpp b/llvm/tools/llvm-exegesis/lib/X86/Target.cpp
index 4709dede5b2e20..1bfcb433eacf72 100644
--- a/llvm/tools/llvm-exegesis/lib/X86/Target.cpp
+++ b/llvm/tools/llvm-exegesis/lib/X86/Target.cpp
@@ -6,7 +6,6 @@
//
//===----------------------------------------------------------------------===//
#include "../Target.h"
-
#include "../Error.h"
#include "../MmapUtils.h"
#include "../ParallelSnippetGenerator.h"
@@ -20,16 +19,17 @@
#include "X86RegisterInfo.h"
#include "llvm/ADT/Sequence.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
+#include "llvm/Config/config.h" // for HAVE_LIBPFM, LIBPFM_HAS_FIELD_CYCLES
#include "llvm/MC/MCInstBuilder.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/TargetParser/Host.h"
-
#include <memory>
#include <string>
#include <vector>
+
#if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64))
#include <immintrin.h>
#include <intrin.h>
diff --git a/llvm/tools/llvm-exegesis/lib/X86/X86Counter.cpp b/llvm/tools/llvm-exegesis/lib/X86/X86Counter.cpp
index 05b6562a57dc67..eeac6d0c4b7bd0 100644
--- a/llvm/tools/llvm-exegesis/lib/X86/X86Counter.cpp
+++ b/llvm/tools/llvm-exegesis/lib/X86/X86Counter.cpp
@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
#include "X86Counter.h"
+#include "llvm/Config/config.h" // for HAVE_LIBPFM, LIBPFM_HAS_FIELD_CYCLES
#if defined(__linux__) && defined(HAVE_LIBPFM) && \
defined(LIBPFM_HAS_FIELD_CYCLES)
diff --git a/llvm/tools/llvm-exegesis/lib/X86/X86Counter.h b/llvm/tools/llvm-exegesis/lib/X86/X86Counter.h
index 75f687d395dec1..3ea9949e10d930 100644
--- a/llvm/tools/llvm-exegesis/lib/X86/X86Counter.h
+++ b/llvm/tools/llvm-exegesis/lib/X86/X86Counter.h
@@ -16,6 +16,7 @@
#define LLVM_TOOLS_LLVM_EXEGESIS_LIB_X86_X86COUNTER_H
#include "../PerfHelper.h"
+#include "llvm/Config/config.h" // for HAVE_LIBPFM, LIBPFM_HAS_FIELD_CYCLES
#include "llvm/Support/Error.h"
// FIXME: Use appropriate wrappers for poll.h and mman.h
diff --git a/llvm/tools/llvm-exegesis/llvm-exegesis.cpp b/llvm/tools/llvm-exegesis/llvm-exegesis.cpp
index e6a43cfc6db51c..da21640478d4e3 100644
--- a/llvm/tools/llvm-exegesis/llvm-exegesis.cpp
+++ b/llvm/tools/llvm-exegesis/llvm-exegesis.cpp
@@ -28,6 +28,7 @@
#include "lib/ValidationEvent.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/Twine.h"
+#include "llvm/Config/config.h" // for HAVE_LIBPFM
#include "llvm/MC/MCInstBuilder.h"
#include "llvm/MC/MCObjectFileInfo.h"
#include "llvm/MC/MCParser/MCAsmParser.h"
diff --git a/llvm/unittests/Support/ProcessTest.cpp b/llvm/unittests/Support/ProcessTest.cpp
index d508a67c57cddc..6bea869037920e 100644
--- a/llvm/unittests/Support/ProcessTest.cpp
+++ b/llvm/unittests/Support/ProcessTest.cpp
@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/Support/Process.h"
+#include "llvm/Config/config.h" // for HAVE_SETENV
#include "llvm/Support/Error.h"
#include "llvm/TargetParser/Host.h"
#include "llvm/TargetParser/Triple.h"
``````````
</details>
https://github.com/llvm/llvm-project/pull/108077
More information about the llvm-commits
mailing list