[clang] [Driver][LTO] Copy fix empty stats filename to AIX (PR #71738)
@@ -32,6 +32,14 @@ // CHECK-LTO: "-o" "obj/dir{{/|}}save-stats.exe" // CHECK-LTO: "-plugin-opt=stats-file=save-stats.stats" + +// RUN: %clang --target=powerpc-unknown-aix -save-stats -flto -o obj/dir/save-stats %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-AIX-LTO +// RUN: %clang --target=powerpc-unknown-aix -save-stats -flto -o obj/dir/save-stats -Wl,-plugin-opt=-dummy %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-AIX-LTO qiongsiwu wrote: Did we intend to use the AIX linker option convention? ```suggestion // RUN: %clang --target=powerpc-unknown-aix -save-stats -flto -o obj/dir/save-stats -Wl,-bplugin_opt:-dummy %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-AIX-LTO ``` https://github.com/llvm/llvm-project/pull/71738 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver][LTO] Copy fix empty stats filename to AIX (PR #71738)
https://github.com/qiongsiwu approved this pull request. LGTM! Thanks so much! https://github.com/llvm/llvm-project/pull/71738 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [AIX] Disable flaky ClangScanDeps tests (PR #72304)
https://github.com/qiongsiwu approved this pull request. LGTM! Thanks Jake! https://github.com/llvm/llvm-project/pull/72304 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [clang-tools-extra] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)
https://github.com/qiongsiwu created https://github.com/llvm/llvm-project/pull/76471 This PR exposes three PGO functions `__llvm_profile_reset_counters`, `__llvm_profile_dump` and `__llvm_orderfile_dump` to user programs through the new header `instr_prof_interface.h` under `compiler-rt/include/profile`. This way, the user can include the header `profile/instr_prof_interface.h` to introduce these three names to their programs. Additionally, this PR defines macro `__LLVM_INSTR_PROFILE_GENERATE` when the program is compiled with profile generation, and defines macro `__LLVM_INSTR_PROFILE_USE` when the program is compiled with profile use. `__LLVM_INSTR_PROFILE_GENERATE` together with `instr_prof_interface.h` define the three PGO functions only when the program is compiled with profile generation. When profile generation is off, these PGO functions are defined away and leave no trace in the user's program. >From 6c9381ec324595947237bd25642b03ab40b6a4df Mon Sep 17 00:00:00 2001 From: Qiongsi Wu Date: Wed, 27 Dec 2023 13:05:01 -0500 Subject: [PATCH 1/4] Initial commit --- .../ExpandModularHeadersPPCallbacks.cpp | 2 +- clang/include/clang/Frontend/Utils.h | 4 +- clang/lib/Frontend/CompilerInstance.cpp | 2 +- clang/lib/Frontend/InitPreprocessor.cpp | 12 ++-- compiler-rt/include/CMakeLists.txt| 1 + .../include/profile/instr_prof_interface.h| 66 +++ compiler-rt/lib/profile/InstrProfiling.h | 32 + 7 files changed, 83 insertions(+), 36 deletions(-) create mode 100644 compiler-rt/include/profile/instr_prof_interface.h diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp index e414ac8c770508..5ecd4fb19131e4 100644 --- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp +++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp @@ -100,7 +100,7 @@ ExpandModularHeadersPPCallbacks::ExpandModularHeadersPPCallbacks( /*OwnsHeaderSearch=*/false); PP->Initialize(Compiler.getTarget(), Compiler.getAuxTarget()); InitializePreprocessor(*PP, *PO, Compiler.getPCHContainerReader(), - Compiler.getFrontendOpts()); + Compiler.getFrontendOpts(), Compiler.getCodeGenOpts()); ApplyHeaderSearchOptions(*HeaderInfo, *HSO, LangOpts, Compiler.getTarget().getTriple()); } diff --git a/clang/include/clang/Frontend/Utils.h b/clang/include/clang/Frontend/Utils.h index 143cf4359f00b5..604e42067a3f1e 100644 --- a/clang/include/clang/Frontend/Utils.h +++ b/clang/include/clang/Frontend/Utils.h @@ -43,12 +43,14 @@ class PCHContainerReader; class Preprocessor; class PreprocessorOptions; class PreprocessorOutputOptions; +class CodeGenOptions; /// InitializePreprocessor - Initialize the preprocessor getting it and the /// environment ready to process a single file. void InitializePreprocessor(Preprocessor &PP, const PreprocessorOptions &PPOpts, const PCHContainerReader &PCHContainerRdr, -const FrontendOptions &FEOpts); +const FrontendOptions &FEOpts, +const CodeGenOptions &CodeGenOpts); /// DoPrintPreprocessedInput - Implement -E mode. void DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream *OS, diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 56bbef9697b650..ea44a26b6db7da 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -470,7 +470,7 @@ void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) { // Predefine macros and configure the preprocessor. InitializePreprocessor(*PP, PPOpts, getPCHContainerReader(), - getFrontendOpts()); + getFrontendOpts(), getCodeGenOpts()); // Initialize the header search object. In CUDA compilations, we use the aux // triple (the host triple) to initialize our header search, since we need to diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index d83128adb511ef..009a67eea1eb52 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -1366,10 +1366,11 @@ static void InitializePredefinedMacros(const TargetInfo &TI, /// InitializePreprocessor - Initialize the preprocessor getting it and the /// environment ready to process a single file. -void clang::InitializePreprocessor( -Preprocessor &PP, const PreprocessorOptions &InitOpts, -const PCHContainerReader &PCHContainerRdr, -const FrontendOptions &FEOpts) { +void clang::InitializePreprocessor(Preprocessor &PP, + const PreprocessorOptions &InitOpts, +
[clang] [compiler-rt] [clang-tools-extra] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)
qiongsiwu wrote: Note to reviewers: I am only adding these three PGO functions because I am not sure if more should be added. Please let me know, and I will revise the PR. https://github.com/llvm/llvm-project/pull/76471 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[compiler-rt] [clang] [clang-tools-extra] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)
https://github.com/qiongsiwu edited https://github.com/llvm/llvm-project/pull/76471 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang] [compiler-rt] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)
https://github.com/qiongsiwu updated https://github.com/llvm/llvm-project/pull/76471 >From 6c9381ec324595947237bd25642b03ab40b6a4df Mon Sep 17 00:00:00 2001 From: Qiongsi Wu Date: Wed, 27 Dec 2023 13:05:01 -0500 Subject: [PATCH 1/5] Initial commit --- .../ExpandModularHeadersPPCallbacks.cpp | 2 +- clang/include/clang/Frontend/Utils.h | 4 +- clang/lib/Frontend/CompilerInstance.cpp | 2 +- clang/lib/Frontend/InitPreprocessor.cpp | 12 ++-- compiler-rt/include/CMakeLists.txt| 1 + .../include/profile/instr_prof_interface.h| 66 +++ compiler-rt/lib/profile/InstrProfiling.h | 32 + 7 files changed, 83 insertions(+), 36 deletions(-) create mode 100644 compiler-rt/include/profile/instr_prof_interface.h diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp index e414ac8c770508..5ecd4fb19131e4 100644 --- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp +++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp @@ -100,7 +100,7 @@ ExpandModularHeadersPPCallbacks::ExpandModularHeadersPPCallbacks( /*OwnsHeaderSearch=*/false); PP->Initialize(Compiler.getTarget(), Compiler.getAuxTarget()); InitializePreprocessor(*PP, *PO, Compiler.getPCHContainerReader(), - Compiler.getFrontendOpts()); + Compiler.getFrontendOpts(), Compiler.getCodeGenOpts()); ApplyHeaderSearchOptions(*HeaderInfo, *HSO, LangOpts, Compiler.getTarget().getTriple()); } diff --git a/clang/include/clang/Frontend/Utils.h b/clang/include/clang/Frontend/Utils.h index 143cf4359f00b5..604e42067a3f1e 100644 --- a/clang/include/clang/Frontend/Utils.h +++ b/clang/include/clang/Frontend/Utils.h @@ -43,12 +43,14 @@ class PCHContainerReader; class Preprocessor; class PreprocessorOptions; class PreprocessorOutputOptions; +class CodeGenOptions; /// InitializePreprocessor - Initialize the preprocessor getting it and the /// environment ready to process a single file. void InitializePreprocessor(Preprocessor &PP, const PreprocessorOptions &PPOpts, const PCHContainerReader &PCHContainerRdr, -const FrontendOptions &FEOpts); +const FrontendOptions &FEOpts, +const CodeGenOptions &CodeGenOpts); /// DoPrintPreprocessedInput - Implement -E mode. void DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream *OS, diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 56bbef9697b650..ea44a26b6db7da 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -470,7 +470,7 @@ void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) { // Predefine macros and configure the preprocessor. InitializePreprocessor(*PP, PPOpts, getPCHContainerReader(), - getFrontendOpts()); + getFrontendOpts(), getCodeGenOpts()); // Initialize the header search object. In CUDA compilations, we use the aux // triple (the host triple) to initialize our header search, since we need to diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index d83128adb511ef..009a67eea1eb52 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -1366,10 +1366,11 @@ static void InitializePredefinedMacros(const TargetInfo &TI, /// InitializePreprocessor - Initialize the preprocessor getting it and the /// environment ready to process a single file. -void clang::InitializePreprocessor( -Preprocessor &PP, const PreprocessorOptions &InitOpts, -const PCHContainerReader &PCHContainerRdr, -const FrontendOptions &FEOpts) { +void clang::InitializePreprocessor(Preprocessor &PP, + const PreprocessorOptions &InitOpts, + const PCHContainerReader &PCHContainerRdr, + const FrontendOptions &FEOpts, + const CodeGenOptions &CodeGenOpts) { const LangOptions &LangOpts = PP.getLangOpts(); std::string PredefineBuffer; PredefineBuffer.reserve(4080); @@ -1416,6 +1417,9 @@ void clang::InitializePreprocessor( InitializeStandardPredefinedMacros(PP.getTargetInfo(), PP.getLangOpts(), FEOpts, Builder); + if (CodeGenOpts.hasProfileIRInstr()) +Builder.defineMacro("__LLVM_INSTR_PROFILE_GENERATE"); + // Add on the predefines from the driver. Wrap in a #line directive to report // that they come from the command line. Builder.append("# 1 \"\" 1"); diff --git a/compiler-rt/include/CMakeLists.txt b/compiler-rt/include/CMakeLists.txt index
[compiler-rt] [clang] [clang-tools-extra] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)
https://github.com/qiongsiwu edited https://github.com/llvm/llvm-project/pull/76471 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang] [compiler-rt] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)
@@ -44,6 +44,7 @@ endif(COMPILER_RT_BUILD_ORC) if (COMPILER_RT_BUILD_PROFILE) set(PROFILE_HEADERS profile/InstrProfData.inc +profile/instr_prof_interface.h qiongsiwu wrote: Yes absolutely! That said, I am following the existing convention for interface headers in other runtime components. See https://github.com/llvm/llvm-project/pull/76471/files/b741a557715eb17b69fa5b4013f2efeadcb80fda#diff-acb14b664a9f7bf0598dfd6e22dad2071ac4106753612c9f0cf3ab96bfeac0afR25, https://github.com/llvm/llvm-project/pull/76471/files/b741a557715eb17b69fa5b4013f2efeadcb80fda#diff-acb14b664a9f7bf0598dfd6e22dad2071ac4106753612c9f0cf3ab96bfeac0afL32 and numerous ones here https://github.com/llvm/llvm-project/pull/76471/files/b741a557715eb17b69fa5b4013f2efeadcb80fda#diff-acb14b664a9f7bf0598dfd6e22dad2071ac4106753612c9f0cf3ab96bfeac0afR3. Could you confirm which convention I should follow? https://github.com/llvm/llvm-project/pull/76471 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang] [compiler-rt] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)
@@ -100,12 +103,6 @@ ValueProfNode *__llvm_profile_begin_vnodes(); ValueProfNode *__llvm_profile_end_vnodes(); uint32_t *__llvm_profile_begin_orderfile(); -/*! - * \brief Clear profile counters to zero. - * - */ -void __llvm_profile_reset_counters(void); qiongsiwu wrote: These functions are not actually removed from this file because the new header `instr_prof_interface.h` is included in this file (see https://github.com/llvm/llvm-project/pull/76471/files#diff-4de780ce726d76b7abc9d3353aef95013e7b21e7bda01be8940cc6574fb0b5ffR16). Are there downstream use cases that pull out `compiler-rt/lib/profile/InstrProfiling.h` and use it by itself? https://github.com/llvm/llvm-project/pull/76471 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [clang-tools-extra] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)
https://github.com/qiongsiwu commented: Thanks so much @snehasish for the fast review! I have two questions regarding your comments. I will address the remaining comments soon as well! https://github.com/llvm/llvm-project/pull/76471 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[compiler-rt] [clang] [clang-tools-extra] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)
@@ -100,12 +103,6 @@ ValueProfNode *__llvm_profile_begin_vnodes(); ValueProfNode *__llvm_profile_end_vnodes(); uint32_t *__llvm_profile_begin_orderfile(); -/*! - * \brief Clear profile counters to zero. - * - */ -void __llvm_profile_reset_counters(void); qiongsiwu wrote: > They are effectively removed if the frontend does not define > __LLVM_INSTR_PROFILE_GENERATE (see my other comment). `__LLVM_INSTR_PROFILE_GENERATE` is defined explicitly in this header `compiler-rt/lib/profile/InstrProfiling.h` before the new header is included (see https://github.com/llvm/llvm-project/pull/76471/files#diff-4de780ce726d76b7abc9d3353aef95013e7b21e7bda01be8940cc6574fb0b5ffR15) so that we do not depend on the frontend for the macro in the compiler-rt context, and we make sure that these three names are always available (regardless of frontend options). I am trying to avoid wrappers or duplicating definitions. [This comment](https://discourse.llvm.org/t/pgo-are-the-llvm-profile-functions-stable-c-apis-across-llvm-releases/75832/7?u=qwu_ibm) seem to imply that creating wrapper or duplicating definition is not desirable. However, if avoiding wrapper or duplication is making downstream code unnecessarily complicated, I will create the wrappers instead. https://github.com/llvm/llvm-project/pull/76471 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[compiler-rt] [clang] [clang-tools-extra] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)
https://github.com/qiongsiwu edited https://github.com/llvm/llvm-project/pull/76471 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[compiler-rt] [clang] [clang-tools-extra] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)
https://github.com/qiongsiwu edited https://github.com/llvm/llvm-project/pull/76471 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[compiler-rt] [clang] [clang-tools-extra] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)
@@ -100,12 +103,6 @@ ValueProfNode *__llvm_profile_begin_vnodes(); ValueProfNode *__llvm_profile_end_vnodes(); uint32_t *__llvm_profile_begin_orderfile(); -/*! - * \brief Clear profile counters to zero. - * - */ -void __llvm_profile_reset_counters(void); qiongsiwu wrote: > I would prefer the dependency to be in the other direction, include > InstrProfiling.h in the interface instr_prof_interface.h. Hmmm this is also something I am trying to avoid. The reason is that we are trying to not expose PGO internal definitions to the user. The intention is that a user can safely include `instr_prof_interface.h` in their program to use these public PGO APIs, without introducing all the PGO internal symbols to their programs. Could you help me understand the advantage for `instr_prof_interface.h` to include `InstrProfiling.h`? https://github.com/llvm/llvm-project/pull/76471 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[compiler-rt] [clang-tools-extra] [clang] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)
https://github.com/qiongsiwu updated https://github.com/llvm/llvm-project/pull/76471 >From 6c9381ec324595947237bd25642b03ab40b6a4df Mon Sep 17 00:00:00 2001 From: Qiongsi Wu Date: Wed, 27 Dec 2023 13:05:01 -0500 Subject: [PATCH 1/6] Initial commit --- .../ExpandModularHeadersPPCallbacks.cpp | 2 +- clang/include/clang/Frontend/Utils.h | 4 +- clang/lib/Frontend/CompilerInstance.cpp | 2 +- clang/lib/Frontend/InitPreprocessor.cpp | 12 ++-- compiler-rt/include/CMakeLists.txt| 1 + .../include/profile/instr_prof_interface.h| 66 +++ compiler-rt/lib/profile/InstrProfiling.h | 32 + 7 files changed, 83 insertions(+), 36 deletions(-) create mode 100644 compiler-rt/include/profile/instr_prof_interface.h diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp index e414ac8c770508..5ecd4fb19131e4 100644 --- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp +++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp @@ -100,7 +100,7 @@ ExpandModularHeadersPPCallbacks::ExpandModularHeadersPPCallbacks( /*OwnsHeaderSearch=*/false); PP->Initialize(Compiler.getTarget(), Compiler.getAuxTarget()); InitializePreprocessor(*PP, *PO, Compiler.getPCHContainerReader(), - Compiler.getFrontendOpts()); + Compiler.getFrontendOpts(), Compiler.getCodeGenOpts()); ApplyHeaderSearchOptions(*HeaderInfo, *HSO, LangOpts, Compiler.getTarget().getTriple()); } diff --git a/clang/include/clang/Frontend/Utils.h b/clang/include/clang/Frontend/Utils.h index 143cf4359f00b5..604e42067a3f1e 100644 --- a/clang/include/clang/Frontend/Utils.h +++ b/clang/include/clang/Frontend/Utils.h @@ -43,12 +43,14 @@ class PCHContainerReader; class Preprocessor; class PreprocessorOptions; class PreprocessorOutputOptions; +class CodeGenOptions; /// InitializePreprocessor - Initialize the preprocessor getting it and the /// environment ready to process a single file. void InitializePreprocessor(Preprocessor &PP, const PreprocessorOptions &PPOpts, const PCHContainerReader &PCHContainerRdr, -const FrontendOptions &FEOpts); +const FrontendOptions &FEOpts, +const CodeGenOptions &CodeGenOpts); /// DoPrintPreprocessedInput - Implement -E mode. void DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream *OS, diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 56bbef9697b650..ea44a26b6db7da 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -470,7 +470,7 @@ void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) { // Predefine macros and configure the preprocessor. InitializePreprocessor(*PP, PPOpts, getPCHContainerReader(), - getFrontendOpts()); + getFrontendOpts(), getCodeGenOpts()); // Initialize the header search object. In CUDA compilations, we use the aux // triple (the host triple) to initialize our header search, since we need to diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index d83128adb511ef..009a67eea1eb52 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -1366,10 +1366,11 @@ static void InitializePredefinedMacros(const TargetInfo &TI, /// InitializePreprocessor - Initialize the preprocessor getting it and the /// environment ready to process a single file. -void clang::InitializePreprocessor( -Preprocessor &PP, const PreprocessorOptions &InitOpts, -const PCHContainerReader &PCHContainerRdr, -const FrontendOptions &FEOpts) { +void clang::InitializePreprocessor(Preprocessor &PP, + const PreprocessorOptions &InitOpts, + const PCHContainerReader &PCHContainerRdr, + const FrontendOptions &FEOpts, + const CodeGenOptions &CodeGenOpts) { const LangOptions &LangOpts = PP.getLangOpts(); std::string PredefineBuffer; PredefineBuffer.reserve(4080); @@ -1416,6 +1417,9 @@ void clang::InitializePreprocessor( InitializeStandardPredefinedMacros(PP.getTargetInfo(), PP.getLangOpts(), FEOpts, Builder); + if (CodeGenOpts.hasProfileIRInstr()) +Builder.defineMacro("__LLVM_INSTR_PROFILE_GENERATE"); + // Add on the predefines from the driver. Wrap in a #line directive to report // that they come from the command line. Builder.append("# 1 \"\" 1"); diff --git a/compiler-rt/include/CMakeLists.txt b/compiler-rt/include/CMakeLists.txt index
[compiler-rt] [clang-tools-extra] [clang] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)
@@ -100,12 +103,6 @@ ValueProfNode *__llvm_profile_begin_vnodes(); ValueProfNode *__llvm_profile_end_vnodes(); uint32_t *__llvm_profile_begin_orderfile(); -/*! - * \brief Clear profile counters to zero. - * - */ -void __llvm_profile_reset_counters(void); qiongsiwu wrote: > Ok, if we don't want to expose the internals then the existing approach seems > like the simplest one. I think @davidxl's comment in the discourse thread is > about ensuring no control flow changes in profile gen and use in hot code > paths. This does not necessarily preclude additional wrappers. > > > Update: I think the explicit definition needs to be guarded by an #ifndef. > > Yes, I misread the original as `#ifdef` causing some confusion. This should > also be `#undef` afterwards. I was thinking about churn for existing users of > InstrProfiling.h but it should be a no-op. Ah got it! Thanks so much for the clarification! `InstrProfiling.h` is updated so we are guarding `__LLVM_INSTR_PROFILE_GENERATE`'s macro definition. https://github.com/llvm/llvm-project/pull/76471 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[compiler-rt] [clang-tools-extra] [clang] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)
qiongsiwu wrote: > > @teresajohnson I mentioned the same thing on > > [discourse](https://discourse.llvm.org/t/pgo-are-the-llvm-profile-functions-stable-c-apis-across-llvm-releases/75832/5) > > but it seems like linking on AIX does not support this model. > > I see. Perhaps instead of defining these away completely, they should be > defined to a dummy function with the same signature that always returns > success (0 I think)? Alternatively, not define them at all when > __LLVM_INSTR_PROFILE_GENERATE not defined and have the user guard calls by > `#ifdef __LLVM_INSTR_PROFILE_GENERATE`. Otherwise, the user either cannot > check the return values, or they have to guard their usage by a check of > __LLVM_INSTR_PROFILE_GENERATE anyway. Ah good catch! Thanks so much! The definitions of `__llvm_profile_dump` and `__llvm_orderfile_dump` are revised to `(0)` so they can be used in `if` conditions. See https://github.com/llvm/llvm-project/pull/76471/commits/cce25f062c00424c153254fc159309808441414c#diff-c21b547d913313490258f0fdb733251d783c5c5a242429ccc2fa5672914f22a2R58. https://github.com/llvm/llvm-project/pull/76471 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [clang-tools-extra] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)
https://github.com/qiongsiwu updated https://github.com/llvm/llvm-project/pull/76471 >From 6c9381ec324595947237bd25642b03ab40b6a4df Mon Sep 17 00:00:00 2001 From: Qiongsi Wu Date: Wed, 27 Dec 2023 13:05:01 -0500 Subject: [PATCH 1/7] Initial commit --- .../ExpandModularHeadersPPCallbacks.cpp | 2 +- clang/include/clang/Frontend/Utils.h | 4 +- clang/lib/Frontend/CompilerInstance.cpp | 2 +- clang/lib/Frontend/InitPreprocessor.cpp | 12 ++-- compiler-rt/include/CMakeLists.txt| 1 + .../include/profile/instr_prof_interface.h| 66 +++ compiler-rt/lib/profile/InstrProfiling.h | 32 + 7 files changed, 83 insertions(+), 36 deletions(-) create mode 100644 compiler-rt/include/profile/instr_prof_interface.h diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp index e414ac8c770508..5ecd4fb19131e4 100644 --- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp +++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp @@ -100,7 +100,7 @@ ExpandModularHeadersPPCallbacks::ExpandModularHeadersPPCallbacks( /*OwnsHeaderSearch=*/false); PP->Initialize(Compiler.getTarget(), Compiler.getAuxTarget()); InitializePreprocessor(*PP, *PO, Compiler.getPCHContainerReader(), - Compiler.getFrontendOpts()); + Compiler.getFrontendOpts(), Compiler.getCodeGenOpts()); ApplyHeaderSearchOptions(*HeaderInfo, *HSO, LangOpts, Compiler.getTarget().getTriple()); } diff --git a/clang/include/clang/Frontend/Utils.h b/clang/include/clang/Frontend/Utils.h index 143cf4359f00b5..604e42067a3f1e 100644 --- a/clang/include/clang/Frontend/Utils.h +++ b/clang/include/clang/Frontend/Utils.h @@ -43,12 +43,14 @@ class PCHContainerReader; class Preprocessor; class PreprocessorOptions; class PreprocessorOutputOptions; +class CodeGenOptions; /// InitializePreprocessor - Initialize the preprocessor getting it and the /// environment ready to process a single file. void InitializePreprocessor(Preprocessor &PP, const PreprocessorOptions &PPOpts, const PCHContainerReader &PCHContainerRdr, -const FrontendOptions &FEOpts); +const FrontendOptions &FEOpts, +const CodeGenOptions &CodeGenOpts); /// DoPrintPreprocessedInput - Implement -E mode. void DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream *OS, diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 56bbef9697b650..ea44a26b6db7da 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -470,7 +470,7 @@ void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) { // Predefine macros and configure the preprocessor. InitializePreprocessor(*PP, PPOpts, getPCHContainerReader(), - getFrontendOpts()); + getFrontendOpts(), getCodeGenOpts()); // Initialize the header search object. In CUDA compilations, we use the aux // triple (the host triple) to initialize our header search, since we need to diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index d83128adb511ef..009a67eea1eb52 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -1366,10 +1366,11 @@ static void InitializePredefinedMacros(const TargetInfo &TI, /// InitializePreprocessor - Initialize the preprocessor getting it and the /// environment ready to process a single file. -void clang::InitializePreprocessor( -Preprocessor &PP, const PreprocessorOptions &InitOpts, -const PCHContainerReader &PCHContainerRdr, -const FrontendOptions &FEOpts) { +void clang::InitializePreprocessor(Preprocessor &PP, + const PreprocessorOptions &InitOpts, + const PCHContainerReader &PCHContainerRdr, + const FrontendOptions &FEOpts, + const CodeGenOptions &CodeGenOpts) { const LangOptions &LangOpts = PP.getLangOpts(); std::string PredefineBuffer; PredefineBuffer.reserve(4080); @@ -1416,6 +1417,9 @@ void clang::InitializePreprocessor( InitializeStandardPredefinedMacros(PP.getTargetInfo(), PP.getLangOpts(), FEOpts, Builder); + if (CodeGenOpts.hasProfileIRInstr()) +Builder.defineMacro("__LLVM_INSTR_PROFILE_GENERATE"); + // Add on the predefines from the driver. Wrap in a #line directive to report // that they come from the command line. Builder.append("# 1 \"\" 1"); diff --git a/compiler-rt/include/CMakeLists.txt b/compiler-rt/include/CMakeLists.txt index
[clang] [compiler-rt] [clang-tools-extra] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)
https://github.com/qiongsiwu edited https://github.com/llvm/llvm-project/pull/76471 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [clang-tools-extra] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)
@@ -0,0 +1,26 @@ +// RUN: %clang_profgen %s -S -emit-llvm -o - | FileCheck %s --check-prefix=PROFGEN +// RUN: %clang_profgen -o %t %s +// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t +// RUN: llvm-profdata merge -o %t.profdata %t.profraw +// RUN: %clang_profuse=%t.profdata %s -S -emit-llvm -o - | FileCheck %s --check-prefix=PROFUSE +#include "profile/instr_profiling.h" + +__attribute__((noinline)) int bar() { return 4; } + +int foo() { + __llvm_profile_reset_counters(); qiongsiwu wrote: Yes absolutely! See https://github.com/llvm/llvm-project/pull/76471/files#diff-73a2e60ab2cfe7ec232978d767316cd70af176df9a4d98b12d6d5ed92a63324fR1. https://github.com/llvm/llvm-project/pull/76471 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [compiler-rt] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)
@@ -1364,12 +1364,22 @@ static void InitializePredefinedMacros(const TargetInfo &TI, TI.getTargetDefines(LangOpts, Builder); } +static void InitializePGOProfileMacros(const CodeGenOptions &CodeGenOpts, qiongsiwu wrote: This [comment](https://discourse.llvm.org/t/pgo-are-the-llvm-profile-functions-stable-c-apis-across-llvm-releases/75832/7?u=qwu_ibm) seems to indicate that such macros are useful, in addition to the reason that the compiler adding these macros can make the user program cleaner (user can now avoid wrapping these PGO calls or guarding them with macros). This PR does not change the current behaviour of `compiler-rt/lib/profile/InstrProfiling.h` so the user still has the freedom to use their own macros (or use the weak symbol mechanism). Does this sound reasonable so we keep the macros? If not, I can split this into two PRs. https://github.com/llvm/llvm-project/pull/76471 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [compiler-rt] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)
@@ -0,0 +1,26 @@ +// RUN: %clang_profgen %s -S -emit-llvm -o - | FileCheck %s --check-prefix=PROFGEN +// RUN: %clang_profgen -o %t %s +// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t +// RUN: llvm-profdata merge -o %t.profdata %t.profraw +// RUN: %clang_profuse=%t.profdata %s -S -emit-llvm -o - | FileCheck %s --check-prefix=PROFUSE +#include "profile/instr_profiling.h" + +__attribute__((noinline)) int bar() { return 4; } + +int foo() { + __llvm_profile_reset_counters(); qiongsiwu wrote: > (Maybe there exists one already but I'm not sure). I checked but I did not find any existing one. https://github.com/llvm/llvm-project/pull/76471 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [compiler-rt] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)
https://github.com/qiongsiwu edited https://github.com/llvm/llvm-project/pull/76471 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang] [compiler-rt] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)
https://github.com/qiongsiwu updated https://github.com/llvm/llvm-project/pull/76471 >From 6c9381ec324595947237bd25642b03ab40b6a4df Mon Sep 17 00:00:00 2001 From: Qiongsi Wu Date: Wed, 27 Dec 2023 13:05:01 -0500 Subject: [PATCH 1/8] Initial commit --- .../ExpandModularHeadersPPCallbacks.cpp | 2 +- clang/include/clang/Frontend/Utils.h | 4 +- clang/lib/Frontend/CompilerInstance.cpp | 2 +- clang/lib/Frontend/InitPreprocessor.cpp | 12 ++-- compiler-rt/include/CMakeLists.txt| 1 + .../include/profile/instr_prof_interface.h| 66 +++ compiler-rt/lib/profile/InstrProfiling.h | 32 + 7 files changed, 83 insertions(+), 36 deletions(-) create mode 100644 compiler-rt/include/profile/instr_prof_interface.h diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp index e414ac8c770508..5ecd4fb19131e4 100644 --- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp +++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp @@ -100,7 +100,7 @@ ExpandModularHeadersPPCallbacks::ExpandModularHeadersPPCallbacks( /*OwnsHeaderSearch=*/false); PP->Initialize(Compiler.getTarget(), Compiler.getAuxTarget()); InitializePreprocessor(*PP, *PO, Compiler.getPCHContainerReader(), - Compiler.getFrontendOpts()); + Compiler.getFrontendOpts(), Compiler.getCodeGenOpts()); ApplyHeaderSearchOptions(*HeaderInfo, *HSO, LangOpts, Compiler.getTarget().getTriple()); } diff --git a/clang/include/clang/Frontend/Utils.h b/clang/include/clang/Frontend/Utils.h index 143cf4359f00b5..604e42067a3f1e 100644 --- a/clang/include/clang/Frontend/Utils.h +++ b/clang/include/clang/Frontend/Utils.h @@ -43,12 +43,14 @@ class PCHContainerReader; class Preprocessor; class PreprocessorOptions; class PreprocessorOutputOptions; +class CodeGenOptions; /// InitializePreprocessor - Initialize the preprocessor getting it and the /// environment ready to process a single file. void InitializePreprocessor(Preprocessor &PP, const PreprocessorOptions &PPOpts, const PCHContainerReader &PCHContainerRdr, -const FrontendOptions &FEOpts); +const FrontendOptions &FEOpts, +const CodeGenOptions &CodeGenOpts); /// DoPrintPreprocessedInput - Implement -E mode. void DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream *OS, diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 56bbef9697b650..ea44a26b6db7da 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -470,7 +470,7 @@ void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) { // Predefine macros and configure the preprocessor. InitializePreprocessor(*PP, PPOpts, getPCHContainerReader(), - getFrontendOpts()); + getFrontendOpts(), getCodeGenOpts()); // Initialize the header search object. In CUDA compilations, we use the aux // triple (the host triple) to initialize our header search, since we need to diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index d83128adb511ef..009a67eea1eb52 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -1366,10 +1366,11 @@ static void InitializePredefinedMacros(const TargetInfo &TI, /// InitializePreprocessor - Initialize the preprocessor getting it and the /// environment ready to process a single file. -void clang::InitializePreprocessor( -Preprocessor &PP, const PreprocessorOptions &InitOpts, -const PCHContainerReader &PCHContainerRdr, -const FrontendOptions &FEOpts) { +void clang::InitializePreprocessor(Preprocessor &PP, + const PreprocessorOptions &InitOpts, + const PCHContainerReader &PCHContainerRdr, + const FrontendOptions &FEOpts, + const CodeGenOptions &CodeGenOpts) { const LangOptions &LangOpts = PP.getLangOpts(); std::string PredefineBuffer; PredefineBuffer.reserve(4080); @@ -1416,6 +1417,9 @@ void clang::InitializePreprocessor( InitializeStandardPredefinedMacros(PP.getTargetInfo(), PP.getLangOpts(), FEOpts, Builder); + if (CodeGenOpts.hasProfileIRInstr()) +Builder.defineMacro("__LLVM_INSTR_PROFILE_GENERATE"); + // Add on the predefines from the driver. Wrap in a #line directive to report // that they come from the command line. Builder.append("# 1 \"\" 1"); diff --git a/compiler-rt/include/CMakeLists.txt b/compiler-rt/include/CMakeLists.txt index
[clang-tools-extra] [clang] [compiler-rt] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)
https://github.com/qiongsiwu edited https://github.com/llvm/llvm-project/pull/76471 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang] [compiler-rt] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)
https://github.com/qiongsiwu commented: @snehasish I appreciate your timely feedback! The latest commit aims at addressing all the comments. https://github.com/llvm/llvm-project/pull/76471 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[compiler-rt] [clang-tools-extra] [clang] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)
@@ -1364,12 +1364,22 @@ static void InitializePredefinedMacros(const TargetInfo &TI, TI.getTargetDefines(LangOpts, Builder); } +static void InitializePGOProfileMacros(const CodeGenOptions &CodeGenOpts, qiongsiwu wrote: Got it! Thanks for the clarification! https://github.com/llvm/llvm-project/pull/76471 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[compiler-rt] [clang] [clang-tools-extra] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)
@@ -0,0 +1,17 @@ +// RUN: %clang_pgogen -o %t %s +// RUN: not %t +// RUN: %clang -o %t %s +// RUN: %t + +__attribute__((weak)) void __llvm_profile_reset_counters(void); + +__attribute__((noinline)) int bar() { return 4; } +int foo() { + if (__llvm_profile_reset_counters) { +__llvm_profile_reset_counters(); +return 0; + } + return bar(); qiongsiwu wrote: Ah good point! I think neither `foo` or `bar` is necessary. The code is simplified. https://github.com/llvm/llvm-project/pull/76471 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [clang-tools-extra] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)
@@ -1364,12 +1364,22 @@ static void InitializePredefinedMacros(const TargetInfo &TI, TI.getTargetDefines(LangOpts, Builder); } +static void InitializePGOProfileMacros(const CodeGenOptions &CodeGenOpts, + MacroBuilder &Builder) { + if (CodeGenOpts.hasProfileInstr()) +Builder.defineMacro("__LLVM_INSTR_PROFILE_GENERATE"); qiongsiwu wrote: Ahh this is a good idea! Documentation added at https://github.com/llvm/llvm-project/pull/76471/files#diff-7389be311daf0b9b476c876bef04245fa3c0ad9337ce865682174bd77d53b648R2812. https://github.com/llvm/llvm-project/pull/76471 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [compiler-rt] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)
@@ -12,6 +12,19 @@ #include "InstrProfilingPort.h" #include +// Make sure __LLVM_INSTR_PROFILE_GENERATE is always defined before +// including instr_prof_interface.h so the interface functions are +// declared correctly for the runtime. Additionally, make sure +// that __LLVM_INSTR_PROFILE_GENERATE is undefined only when it is +// not explicitly defined somewhere else. +#ifndef __LLVM_INSTR_PROFILE_GENERATE +#define __LLVM_INSTR_PROFILE_GENERATE +#include "profile/instr_prof_interface.h" +#undef __LLVM_INSTR_PROFILE_GENERATE +#else qiongsiwu wrote: Yes indeed! I was not aware of the fact that we do not support instrumenting the profiling runtime itself. The code is simplified. https://github.com/llvm/llvm-project/pull/76471 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [compiler-rt] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)
https://github.com/qiongsiwu updated https://github.com/llvm/llvm-project/pull/76471 >From 6c9381ec324595947237bd25642b03ab40b6a4df Mon Sep 17 00:00:00 2001 From: Qiongsi Wu Date: Wed, 27 Dec 2023 13:05:01 -0500 Subject: [PATCH 1/9] Initial commit --- .../ExpandModularHeadersPPCallbacks.cpp | 2 +- clang/include/clang/Frontend/Utils.h | 4 +- clang/lib/Frontend/CompilerInstance.cpp | 2 +- clang/lib/Frontend/InitPreprocessor.cpp | 12 ++-- compiler-rt/include/CMakeLists.txt| 1 + .../include/profile/instr_prof_interface.h| 66 +++ compiler-rt/lib/profile/InstrProfiling.h | 32 + 7 files changed, 83 insertions(+), 36 deletions(-) create mode 100644 compiler-rt/include/profile/instr_prof_interface.h diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp index e414ac8c770508..5ecd4fb19131e4 100644 --- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp +++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp @@ -100,7 +100,7 @@ ExpandModularHeadersPPCallbacks::ExpandModularHeadersPPCallbacks( /*OwnsHeaderSearch=*/false); PP->Initialize(Compiler.getTarget(), Compiler.getAuxTarget()); InitializePreprocessor(*PP, *PO, Compiler.getPCHContainerReader(), - Compiler.getFrontendOpts()); + Compiler.getFrontendOpts(), Compiler.getCodeGenOpts()); ApplyHeaderSearchOptions(*HeaderInfo, *HSO, LangOpts, Compiler.getTarget().getTriple()); } diff --git a/clang/include/clang/Frontend/Utils.h b/clang/include/clang/Frontend/Utils.h index 143cf4359f00b5..604e42067a3f1e 100644 --- a/clang/include/clang/Frontend/Utils.h +++ b/clang/include/clang/Frontend/Utils.h @@ -43,12 +43,14 @@ class PCHContainerReader; class Preprocessor; class PreprocessorOptions; class PreprocessorOutputOptions; +class CodeGenOptions; /// InitializePreprocessor - Initialize the preprocessor getting it and the /// environment ready to process a single file. void InitializePreprocessor(Preprocessor &PP, const PreprocessorOptions &PPOpts, const PCHContainerReader &PCHContainerRdr, -const FrontendOptions &FEOpts); +const FrontendOptions &FEOpts, +const CodeGenOptions &CodeGenOpts); /// DoPrintPreprocessedInput - Implement -E mode. void DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream *OS, diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 56bbef9697b650..ea44a26b6db7da 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -470,7 +470,7 @@ void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) { // Predefine macros and configure the preprocessor. InitializePreprocessor(*PP, PPOpts, getPCHContainerReader(), - getFrontendOpts()); + getFrontendOpts(), getCodeGenOpts()); // Initialize the header search object. In CUDA compilations, we use the aux // triple (the host triple) to initialize our header search, since we need to diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index d83128adb511ef..009a67eea1eb52 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -1366,10 +1366,11 @@ static void InitializePredefinedMacros(const TargetInfo &TI, /// InitializePreprocessor - Initialize the preprocessor getting it and the /// environment ready to process a single file. -void clang::InitializePreprocessor( -Preprocessor &PP, const PreprocessorOptions &InitOpts, -const PCHContainerReader &PCHContainerRdr, -const FrontendOptions &FEOpts) { +void clang::InitializePreprocessor(Preprocessor &PP, + const PreprocessorOptions &InitOpts, + const PCHContainerReader &PCHContainerRdr, + const FrontendOptions &FEOpts, + const CodeGenOptions &CodeGenOpts) { const LangOptions &LangOpts = PP.getLangOpts(); std::string PredefineBuffer; PredefineBuffer.reserve(4080); @@ -1416,6 +1417,9 @@ void clang::InitializePreprocessor( InitializeStandardPredefinedMacros(PP.getTargetInfo(), PP.getLangOpts(), FEOpts, Builder); + if (CodeGenOpts.hasProfileIRInstr()) +Builder.defineMacro("__LLVM_INSTR_PROFILE_GENERATE"); + // Add on the predefines from the driver. Wrap in a #line directive to report // that they come from the command line. Builder.append("# 1 \"\" 1"); diff --git a/compiler-rt/include/CMakeLists.txt b/compiler-rt/include/CMakeLists.txt index
[clang] [clang-tools-extra] [compiler-rt] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)
https://github.com/qiongsiwu updated https://github.com/llvm/llvm-project/pull/76471 >From 6c9381ec324595947237bd25642b03ab40b6a4df Mon Sep 17 00:00:00 2001 From: Qiongsi Wu Date: Wed, 27 Dec 2023 13:05:01 -0500 Subject: [PATCH 01/10] Initial commit --- .../ExpandModularHeadersPPCallbacks.cpp | 2 +- clang/include/clang/Frontend/Utils.h | 4 +- clang/lib/Frontend/CompilerInstance.cpp | 2 +- clang/lib/Frontend/InitPreprocessor.cpp | 12 ++-- compiler-rt/include/CMakeLists.txt| 1 + .../include/profile/instr_prof_interface.h| 66 +++ compiler-rt/lib/profile/InstrProfiling.h | 32 + 7 files changed, 83 insertions(+), 36 deletions(-) create mode 100644 compiler-rt/include/profile/instr_prof_interface.h diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp index e414ac8c770508..5ecd4fb19131e4 100644 --- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp +++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp @@ -100,7 +100,7 @@ ExpandModularHeadersPPCallbacks::ExpandModularHeadersPPCallbacks( /*OwnsHeaderSearch=*/false); PP->Initialize(Compiler.getTarget(), Compiler.getAuxTarget()); InitializePreprocessor(*PP, *PO, Compiler.getPCHContainerReader(), - Compiler.getFrontendOpts()); + Compiler.getFrontendOpts(), Compiler.getCodeGenOpts()); ApplyHeaderSearchOptions(*HeaderInfo, *HSO, LangOpts, Compiler.getTarget().getTriple()); } diff --git a/clang/include/clang/Frontend/Utils.h b/clang/include/clang/Frontend/Utils.h index 143cf4359f00b5..604e42067a3f1e 100644 --- a/clang/include/clang/Frontend/Utils.h +++ b/clang/include/clang/Frontend/Utils.h @@ -43,12 +43,14 @@ class PCHContainerReader; class Preprocessor; class PreprocessorOptions; class PreprocessorOutputOptions; +class CodeGenOptions; /// InitializePreprocessor - Initialize the preprocessor getting it and the /// environment ready to process a single file. void InitializePreprocessor(Preprocessor &PP, const PreprocessorOptions &PPOpts, const PCHContainerReader &PCHContainerRdr, -const FrontendOptions &FEOpts); +const FrontendOptions &FEOpts, +const CodeGenOptions &CodeGenOpts); /// DoPrintPreprocessedInput - Implement -E mode. void DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream *OS, diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 56bbef9697b650..ea44a26b6db7da 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -470,7 +470,7 @@ void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) { // Predefine macros and configure the preprocessor. InitializePreprocessor(*PP, PPOpts, getPCHContainerReader(), - getFrontendOpts()); + getFrontendOpts(), getCodeGenOpts()); // Initialize the header search object. In CUDA compilations, we use the aux // triple (the host triple) to initialize our header search, since we need to diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index d83128adb511ef..009a67eea1eb52 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -1366,10 +1366,11 @@ static void InitializePredefinedMacros(const TargetInfo &TI, /// InitializePreprocessor - Initialize the preprocessor getting it and the /// environment ready to process a single file. -void clang::InitializePreprocessor( -Preprocessor &PP, const PreprocessorOptions &InitOpts, -const PCHContainerReader &PCHContainerRdr, -const FrontendOptions &FEOpts) { +void clang::InitializePreprocessor(Preprocessor &PP, + const PreprocessorOptions &InitOpts, + const PCHContainerReader &PCHContainerRdr, + const FrontendOptions &FEOpts, + const CodeGenOptions &CodeGenOpts) { const LangOptions &LangOpts = PP.getLangOpts(); std::string PredefineBuffer; PredefineBuffer.reserve(4080); @@ -1416,6 +1417,9 @@ void clang::InitializePreprocessor( InitializeStandardPredefinedMacros(PP.getTargetInfo(), PP.getLangOpts(), FEOpts, Builder); + if (CodeGenOpts.hasProfileIRInstr()) +Builder.defineMacro("__LLVM_INSTR_PROFILE_GENERATE"); + // Add on the predefines from the driver. Wrap in a #line directive to report // that they come from the command line. Builder.append("# 1 \"\" 1"); diff --git a/compiler-rt/include/CMakeLists.txt b/compiler-rt/include/CMakeLists.txt ind
[clang-tools-extra] [compiler-rt] [clang] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)
https://github.com/qiongsiwu updated https://github.com/llvm/llvm-project/pull/76471 >From 6c9381ec324595947237bd25642b03ab40b6a4df Mon Sep 17 00:00:00 2001 From: Qiongsi Wu Date: Wed, 27 Dec 2023 13:05:01 -0500 Subject: [PATCH 01/11] Initial commit --- .../ExpandModularHeadersPPCallbacks.cpp | 2 +- clang/include/clang/Frontend/Utils.h | 4 +- clang/lib/Frontend/CompilerInstance.cpp | 2 +- clang/lib/Frontend/InitPreprocessor.cpp | 12 ++-- compiler-rt/include/CMakeLists.txt| 1 + .../include/profile/instr_prof_interface.h| 66 +++ compiler-rt/lib/profile/InstrProfiling.h | 32 + 7 files changed, 83 insertions(+), 36 deletions(-) create mode 100644 compiler-rt/include/profile/instr_prof_interface.h diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp index e414ac8c770508..5ecd4fb19131e4 100644 --- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp +++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp @@ -100,7 +100,7 @@ ExpandModularHeadersPPCallbacks::ExpandModularHeadersPPCallbacks( /*OwnsHeaderSearch=*/false); PP->Initialize(Compiler.getTarget(), Compiler.getAuxTarget()); InitializePreprocessor(*PP, *PO, Compiler.getPCHContainerReader(), - Compiler.getFrontendOpts()); + Compiler.getFrontendOpts(), Compiler.getCodeGenOpts()); ApplyHeaderSearchOptions(*HeaderInfo, *HSO, LangOpts, Compiler.getTarget().getTriple()); } diff --git a/clang/include/clang/Frontend/Utils.h b/clang/include/clang/Frontend/Utils.h index 143cf4359f00b5..604e42067a3f1e 100644 --- a/clang/include/clang/Frontend/Utils.h +++ b/clang/include/clang/Frontend/Utils.h @@ -43,12 +43,14 @@ class PCHContainerReader; class Preprocessor; class PreprocessorOptions; class PreprocessorOutputOptions; +class CodeGenOptions; /// InitializePreprocessor - Initialize the preprocessor getting it and the /// environment ready to process a single file. void InitializePreprocessor(Preprocessor &PP, const PreprocessorOptions &PPOpts, const PCHContainerReader &PCHContainerRdr, -const FrontendOptions &FEOpts); +const FrontendOptions &FEOpts, +const CodeGenOptions &CodeGenOpts); /// DoPrintPreprocessedInput - Implement -E mode. void DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream *OS, diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 56bbef9697b650..ea44a26b6db7da 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -470,7 +470,7 @@ void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) { // Predefine macros and configure the preprocessor. InitializePreprocessor(*PP, PPOpts, getPCHContainerReader(), - getFrontendOpts()); + getFrontendOpts(), getCodeGenOpts()); // Initialize the header search object. In CUDA compilations, we use the aux // triple (the host triple) to initialize our header search, since we need to diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index d83128adb511ef..009a67eea1eb52 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -1366,10 +1366,11 @@ static void InitializePredefinedMacros(const TargetInfo &TI, /// InitializePreprocessor - Initialize the preprocessor getting it and the /// environment ready to process a single file. -void clang::InitializePreprocessor( -Preprocessor &PP, const PreprocessorOptions &InitOpts, -const PCHContainerReader &PCHContainerRdr, -const FrontendOptions &FEOpts) { +void clang::InitializePreprocessor(Preprocessor &PP, + const PreprocessorOptions &InitOpts, + const PCHContainerReader &PCHContainerRdr, + const FrontendOptions &FEOpts, + const CodeGenOptions &CodeGenOpts) { const LangOptions &LangOpts = PP.getLangOpts(); std::string PredefineBuffer; PredefineBuffer.reserve(4080); @@ -1416,6 +1417,9 @@ void clang::InitializePreprocessor( InitializeStandardPredefinedMacros(PP.getTargetInfo(), PP.getLangOpts(), FEOpts, Builder); + if (CodeGenOpts.hasProfileIRInstr()) +Builder.defineMacro("__LLVM_INSTR_PROFILE_GENERATE"); + // Add on the predefines from the driver. Wrap in a #line directive to report // that they come from the command line. Builder.append("# 1 \"\" 1"); diff --git a/compiler-rt/include/CMakeLists.txt b/compiler-rt/include/CMakeLists.txt ind
[clang-tools-extra] [compiler-rt] [clang] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)
@@ -0,0 +1,92 @@ +/*=== instr_prof_interface.h - Instrumentation PGO User Program API === + * + * 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 header provides a public interface for fine-grained control of counter + * reset and profile dumping. These interface functions can be directly called + * in user programs. + * +\*===-===*/ + +#ifndef COMPILER_RT_INSTR_PROFILING +#define COMPILER_RT_INSTR_PROFILING + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __LLVM_INSTR_PROFILE_GENERATE +// Profile file reset and dump interfaces. +// When `-fprofile[-instr]-generate`/`-fcs-profile-generate` is in effect, +// clang defines __LLVM_INSTR_PROFILE_GENERATE to pick up the API calls. + +/*! + * \brief Set the filename for writing instrumentation data. + * + * Sets the filename to be used for subsequent calls to + * \a __llvm_profile_write_file(). + * + * \c Name is not copied, so it must remain valid. Passing NULL resets the + * filename logic to the default behaviour. + * + * Note: There may be multiple copies of the profile runtime (one for each + * instrumented image/DSO). This API only modifies the filename within the + * copy of the runtime available to the calling image. + * + * Warning: This is a no-op if continuous mode (\ref + * __llvm_profile_is_continuous_mode_enabled) is on. The reason for this is + * that in continuous mode, profile counters are mmap()'d to the profile at + * program initialization time. Support for transferring the mmap'd profile + * counts to a new file has not been implemented. + */ +void __llvm_profile_set_filename(const char *Name); + +/*! + * \brief Interface to set all PGO counters to zero for the current process. + * + */ +void __llvm_profile_reset_counters(void); + +/*! + * \brief this is a wrapper interface to \c __llvm_profile_write_file. + * After this interface is invoked, an already dumped flag will be set + * so that profile won't be dumped again during program exit. + * Invocation of interface __llvm_profile_reset_counters will clear + * the flag. This interface is designed to be used to collect profile + * data from user selected hot regions. The use model is + * __llvm_profile_reset_counters(); + * ... hot region 1 + * __llvm_profile_dump(); + * .. some other code + * __llvm_profile_reset_counters(); + * ... hot region 2 + * __llvm_profile_dump(); + * + * It is expected that on-line profile merging is on with \c %m specifier + * used in profile filename . If merging is not turned on, user is expected + * to invoke __llvm_profile_set_filename to specify different profile names qiongsiwu wrote: Ah thanks for pointing them out! Fixed. https://github.com/llvm/llvm-project/pull/76471 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[compiler-rt] [clang] [clang-tools-extra] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)
qiongsiwu wrote: Comments added. https://github.com/llvm/llvm-project/pull/76471 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [compiler-rt] [clang] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)
@@ -0,0 +1,38 @@ +// RUN: %clang_profgen %s --target=ppc64le-unknown-linux-gnu -S \ +// RUN:-emit-llvm -o - | FileCheck %s --check-prefix=PROFGEN +// RUN: %clang_profgen -o %t %s +// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t qiongsiwu wrote: > Nevertheless, I wonder test coverage for %clang_pgogen should be added here > as well. Ah good catch! Thanks! I had missed that. The `%clang_pgogen` tests are added. > Good point, can we drop the `--target=ppc64le-unknown-linux-gnu` flag? It > shouldn't make a difference to what we want to test here. Sounds good! The test is revised to avoid any target specific flags. https://github.com/llvm/llvm-project/pull/76471 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [compiler-rt] [clang] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)
@@ -0,0 +1,38 @@ +// RUN: %clang_profgen %s --target=ppc64le-unknown-linux-gnu -S \ +// RUN:-emit-llvm -o - | FileCheck %s --check-prefix=PROFGEN +// RUN: %clang_profgen -o %t %s +// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t qiongsiwu wrote: > Relatedly, I do get compilation errors on ppc big-endian systems for > clang_pgogen in another compiler-rt test > ([commit](https://github.com/llvm/llvm-project/commit/5136c167a2573fbd05179849cb41b198c4862b12) > and [buildbot > link](https://lab.llvm.org/buildbot/#/builders/18/builds/13228)) > From the error message, I think lack of ABI implementation should manifest > whether it's clang_pgogen or clang_profgen. Hmmm thanks for pointing this out! I don't have access to a BE machine at the moment to reproduce but I will go find one and take a look. https://github.com/llvm/llvm-project/pull/76471 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [compiler-rt] [clang] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)
qiongsiwu wrote: > thanks! Mostly lg with a pending discussion on whether we want to have test > coverage for `clang_pgogen` in `compiler-rt/test/profile/instrprof-api.c`, > and the open-ended discussion about the observed build failure in another > compiler-rt test. Thanks for the feedback! The latest commit aims at resolving most of the comments. I will look into the BE related failure. https://github.com/llvm/llvm-project/pull/76471 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [compiler-rt] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)
@@ -0,0 +1,16 @@ +// Test the linker feature that treats undefined weak symbols as null values. + +// RUN: %clang_pgogen -o %t %s qiongsiwu wrote: Ah no worries! I actually tried running this on AIX and the test is unsupported. I think compiler-rt [checks](https://github.com/llvm/llvm-project/blob/d933b88b71b00461815667d7cd0bb2fecd8606db/compiler-rt/test/profile/Linux/lit.local.cfg.py#L45) to see if the host is Linux before running the tests in the `Linux` folder. https://github.com/llvm/llvm-project/pull/76471 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [compiler-rt] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)
@@ -0,0 +1,38 @@ +// RUN: %clang_profgen %s --target=ppc64le-unknown-linux-gnu -S \ +// RUN:-emit-llvm -o - | FileCheck %s --check-prefix=PROFGEN +// RUN: %clang_profgen -o %t %s +// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t qiongsiwu wrote: Ah thanks for the proposal! We still want to keep this test working for both BE and LE because we want this test to run on AIX as well. In its current shape, the test passes on AIX. If it is fine, given [this comment](https://github.com/llvm/llvm-project/pull/76471#issuecomment-1874671580), I can be a bit speculative and let the buildbot alert me if this test is failing on Linux ppc BE. https://github.com/llvm/llvm-project/pull/76471 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [clang-tools-extra] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)
https://github.com/qiongsiwu updated https://github.com/llvm/llvm-project/pull/76471 >From 6c9381ec324595947237bd25642b03ab40b6a4df Mon Sep 17 00:00:00 2001 From: Qiongsi Wu Date: Wed, 27 Dec 2023 13:05:01 -0500 Subject: [PATCH 01/12] Initial commit --- .../ExpandModularHeadersPPCallbacks.cpp | 2 +- clang/include/clang/Frontend/Utils.h | 4 +- clang/lib/Frontend/CompilerInstance.cpp | 2 +- clang/lib/Frontend/InitPreprocessor.cpp | 12 ++-- compiler-rt/include/CMakeLists.txt| 1 + .../include/profile/instr_prof_interface.h| 66 +++ compiler-rt/lib/profile/InstrProfiling.h | 32 + 7 files changed, 83 insertions(+), 36 deletions(-) create mode 100644 compiler-rt/include/profile/instr_prof_interface.h diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp index e414ac8c770508..5ecd4fb19131e4 100644 --- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp +++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp @@ -100,7 +100,7 @@ ExpandModularHeadersPPCallbacks::ExpandModularHeadersPPCallbacks( /*OwnsHeaderSearch=*/false); PP->Initialize(Compiler.getTarget(), Compiler.getAuxTarget()); InitializePreprocessor(*PP, *PO, Compiler.getPCHContainerReader(), - Compiler.getFrontendOpts()); + Compiler.getFrontendOpts(), Compiler.getCodeGenOpts()); ApplyHeaderSearchOptions(*HeaderInfo, *HSO, LangOpts, Compiler.getTarget().getTriple()); } diff --git a/clang/include/clang/Frontend/Utils.h b/clang/include/clang/Frontend/Utils.h index 143cf4359f00b5..604e42067a3f1e 100644 --- a/clang/include/clang/Frontend/Utils.h +++ b/clang/include/clang/Frontend/Utils.h @@ -43,12 +43,14 @@ class PCHContainerReader; class Preprocessor; class PreprocessorOptions; class PreprocessorOutputOptions; +class CodeGenOptions; /// InitializePreprocessor - Initialize the preprocessor getting it and the /// environment ready to process a single file. void InitializePreprocessor(Preprocessor &PP, const PreprocessorOptions &PPOpts, const PCHContainerReader &PCHContainerRdr, -const FrontendOptions &FEOpts); +const FrontendOptions &FEOpts, +const CodeGenOptions &CodeGenOpts); /// DoPrintPreprocessedInput - Implement -E mode. void DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream *OS, diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 56bbef9697b650..ea44a26b6db7da 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -470,7 +470,7 @@ void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) { // Predefine macros and configure the preprocessor. InitializePreprocessor(*PP, PPOpts, getPCHContainerReader(), - getFrontendOpts()); + getFrontendOpts(), getCodeGenOpts()); // Initialize the header search object. In CUDA compilations, we use the aux // triple (the host triple) to initialize our header search, since we need to diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index d83128adb511ef..009a67eea1eb52 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -1366,10 +1366,11 @@ static void InitializePredefinedMacros(const TargetInfo &TI, /// InitializePreprocessor - Initialize the preprocessor getting it and the /// environment ready to process a single file. -void clang::InitializePreprocessor( -Preprocessor &PP, const PreprocessorOptions &InitOpts, -const PCHContainerReader &PCHContainerRdr, -const FrontendOptions &FEOpts) { +void clang::InitializePreprocessor(Preprocessor &PP, + const PreprocessorOptions &InitOpts, + const PCHContainerReader &PCHContainerRdr, + const FrontendOptions &FEOpts, + const CodeGenOptions &CodeGenOpts) { const LangOptions &LangOpts = PP.getLangOpts(); std::string PredefineBuffer; PredefineBuffer.reserve(4080); @@ -1416,6 +1417,9 @@ void clang::InitializePreprocessor( InitializeStandardPredefinedMacros(PP.getTargetInfo(), PP.getLangOpts(), FEOpts, Builder); + if (CodeGenOpts.hasProfileIRInstr()) +Builder.defineMacro("__LLVM_INSTR_PROFILE_GENERATE"); + // Add on the predefines from the driver. Wrap in a #line directive to report // that they come from the command line. Builder.append("# 1 \"\" 1"); diff --git a/compiler-rt/include/CMakeLists.txt b/compiler-rt/include/CMakeLists.txt ind
[clang] [compiler-rt] [clang-tools-extra] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)
https://github.com/qiongsiwu updated https://github.com/llvm/llvm-project/pull/76471 >From 6c9381ec324595947237bd25642b03ab40b6a4df Mon Sep 17 00:00:00 2001 From: Qiongsi Wu Date: Wed, 27 Dec 2023 13:05:01 -0500 Subject: [PATCH 01/13] Initial commit --- .../ExpandModularHeadersPPCallbacks.cpp | 2 +- clang/include/clang/Frontend/Utils.h | 4 +- clang/lib/Frontend/CompilerInstance.cpp | 2 +- clang/lib/Frontend/InitPreprocessor.cpp | 12 ++-- compiler-rt/include/CMakeLists.txt| 1 + .../include/profile/instr_prof_interface.h| 66 +++ compiler-rt/lib/profile/InstrProfiling.h | 32 + 7 files changed, 83 insertions(+), 36 deletions(-) create mode 100644 compiler-rt/include/profile/instr_prof_interface.h diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp index e414ac8c770508..5ecd4fb19131e4 100644 --- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp +++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp @@ -100,7 +100,7 @@ ExpandModularHeadersPPCallbacks::ExpandModularHeadersPPCallbacks( /*OwnsHeaderSearch=*/false); PP->Initialize(Compiler.getTarget(), Compiler.getAuxTarget()); InitializePreprocessor(*PP, *PO, Compiler.getPCHContainerReader(), - Compiler.getFrontendOpts()); + Compiler.getFrontendOpts(), Compiler.getCodeGenOpts()); ApplyHeaderSearchOptions(*HeaderInfo, *HSO, LangOpts, Compiler.getTarget().getTriple()); } diff --git a/clang/include/clang/Frontend/Utils.h b/clang/include/clang/Frontend/Utils.h index 143cf4359f00b5..604e42067a3f1e 100644 --- a/clang/include/clang/Frontend/Utils.h +++ b/clang/include/clang/Frontend/Utils.h @@ -43,12 +43,14 @@ class PCHContainerReader; class Preprocessor; class PreprocessorOptions; class PreprocessorOutputOptions; +class CodeGenOptions; /// InitializePreprocessor - Initialize the preprocessor getting it and the /// environment ready to process a single file. void InitializePreprocessor(Preprocessor &PP, const PreprocessorOptions &PPOpts, const PCHContainerReader &PCHContainerRdr, -const FrontendOptions &FEOpts); +const FrontendOptions &FEOpts, +const CodeGenOptions &CodeGenOpts); /// DoPrintPreprocessedInput - Implement -E mode. void DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream *OS, diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 56bbef9697b650..ea44a26b6db7da 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -470,7 +470,7 @@ void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) { // Predefine macros and configure the preprocessor. InitializePreprocessor(*PP, PPOpts, getPCHContainerReader(), - getFrontendOpts()); + getFrontendOpts(), getCodeGenOpts()); // Initialize the header search object. In CUDA compilations, we use the aux // triple (the host triple) to initialize our header search, since we need to diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index d83128adb511ef..009a67eea1eb52 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -1366,10 +1366,11 @@ static void InitializePredefinedMacros(const TargetInfo &TI, /// InitializePreprocessor - Initialize the preprocessor getting it and the /// environment ready to process a single file. -void clang::InitializePreprocessor( -Preprocessor &PP, const PreprocessorOptions &InitOpts, -const PCHContainerReader &PCHContainerRdr, -const FrontendOptions &FEOpts) { +void clang::InitializePreprocessor(Preprocessor &PP, + const PreprocessorOptions &InitOpts, + const PCHContainerReader &PCHContainerRdr, + const FrontendOptions &FEOpts, + const CodeGenOptions &CodeGenOpts) { const LangOptions &LangOpts = PP.getLangOpts(); std::string PredefineBuffer; PredefineBuffer.reserve(4080); @@ -1416,6 +1417,9 @@ void clang::InitializePreprocessor( InitializeStandardPredefinedMacros(PP.getTargetInfo(), PP.getLangOpts(), FEOpts, Builder); + if (CodeGenOpts.hasProfileIRInstr()) +Builder.defineMacro("__LLVM_INSTR_PROFILE_GENERATE"); + // Add on the predefines from the driver. Wrap in a #line directive to report // that they come from the command line. Builder.append("# 1 \"\" 1"); diff --git a/compiler-rt/include/CMakeLists.txt b/compiler-rt/include/CMakeLists.txt ind
[clang] [compiler-rt] [clang-tools-extra] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)
qiongsiwu wrote: I realized one problem during testing IRPGO (thanks again for the suggestion @minglotus-6 !). A functions control flow may change between `-fprofile-generate` and `-fprofile-use` when we make use of definitions in the new header. For example, one may have the following code: ```c void main() { ... if (__llvm_profile_dump()) return error; cleanup(); } ``` During `-fprofile-generate`, `__llvm_profile_dump` is a declared name and main's control flow includes a branch to `return error;`. During `-fprofile-use`, `__llvm_profile_dump()` is replaced by `(0)` and the frontend eliminates the `if` statement and the branch to `return error`. Such control flow change can lead to PGO warnings (hash mismatch). I think it may be OK to keep the PR this way because the new macros can potentially cause control flow changes directly as well. The documentation is updated (https://github.com/llvm/llvm-project/pull/76471/files#diff-7389be311daf0b9b476c876bef04245fa3c0ad9337ce865682174bd77d53b648R2908) to advise against using these APIs in a program's hot regions and warn about possible impact on control flow. Do you all think this is reasonable? https://github.com/llvm/llvm-project/pull/76471 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[compiler-rt] [clang] [clang-tools-extra] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)
qiongsiwu wrote: Landing this PR. It seems that the format error is not caused by any changes in this PR. https://github.com/llvm/llvm-project/pull/76471 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[compiler-rt] [clang] [clang-tools-extra] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)
https://github.com/qiongsiwu closed https://github.com/llvm/llvm-project/pull/76471 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [clang-tools-extra] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)
qiongsiwu wrote: > Breaks https://lab.llvm.org/buildbot/#/builders/127/builds/60635 Please fix > or revert. Thanks for reporting the problem @vitalybuka ! I don't have a Windows machine to reproduce the issue. It is not clear to me how the IR can contain names like `"??_C@_0BA@MIKMMAII@rawprof?4profraw?$AA@"`. Do we have some special name mangling treatment on Windows? I will modify the test to check for this string as well, but I will not know the result till the fix lands. https://github.com/llvm/llvm-project/pull/76471 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [compiler-rt] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)
qiongsiwu wrote: > Sometimes godbolt output (like https://godbolt.org/z/MxbjcnanW) could be > faster and more convenient (e.g., there is no need to get windows executable > to for debugging, only LLVM IR is needed). Thanks for the pointer! Yup godbolt can indeed reproduce IR quite well. https://godbolt.org/z/b7G1PnxME Working on a fix. https://github.com/llvm/llvm-project/pull/76471 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 3ca6328 - [clang][ppc] Creating Seperate Install Target for PPC htm Headers
Author: Qiongsi Wu Date: 2022-05-11T14:48:40-04:00 New Revision: 3ca6328637b3f42096c652e4df53282649956bdb URL: https://github.com/llvm/llvm-project/commit/3ca6328637b3f42096c652e4df53282649956bdb DIFF: https://github.com/llvm/llvm-project/commit/3ca6328637b3f42096c652e4df53282649956bdb.diff LOG: [clang][ppc] Creating Seperate Install Target for PPC htm Headers This patch splits out the htm intrinsic headers from the PPC headers list. Reviewed By: jsji Differential Revision: https://reviews.llvm.org/D125386 Added: Modified: clang/lib/Headers/CMakeLists.txt Removed: diff --git a/clang/lib/Headers/CMakeLists.txt b/clang/lib/Headers/CMakeLists.txt index bb24b4274380..08c5dccb3b77 100644 --- a/clang/lib/Headers/CMakeLists.txt +++ b/clang/lib/Headers/CMakeLists.txt @@ -73,6 +73,9 @@ set(opencl_files set(ppc_files altivec.h + ) + +set(ppc_htm_files htmintrin.h htmxlintrin.h ) @@ -212,6 +215,7 @@ set(files ${mips_msa_files} ${opencl_files} ${ppc_files} + ${ppc_htm_files} ${systemz_files} ${ve_files} ${x86_files} @@ -370,6 +374,7 @@ add_dependencies("clang-resource-headers" "hip-resource-headers" "mips-resource-headers" "ppc-resource-headers" + "ppc-htm-resource-headers" "riscv-resource-headers" "systemz-resource-headers" "ve-resource-headers" @@ -392,6 +397,7 @@ add_header_target("hexagon-resource-headers" "${hexagon_files}") add_header_target("hip-resource-headers" "${hip_files}") add_header_target("mips-resource-headers" "${mips_msa_files}") add_header_target("ppc-resource-headers" "${ppc_files};${ppc_wrapper_files}") +add_header_target("ppc-htm-resource-headers" "${ppc_htm_files}") add_header_target("riscv-resource-headers" "${riscv_generated_files}") add_header_target("systemz-resource-headers" "${systemz_files}") add_header_target("ve-resource-headers" "${ve_files}") @@ -491,11 +497,17 @@ install( COMPONENT ppc-resource-headers) install( - FILES ${ppc_files} ${utility_files} + FILES ${ppc_files} DESTINATION ${header_install_dir} EXCLUDE_FROM_ALL COMPONENT ppc-resource-headers) +install( + FILES ${ppc_htm_files} + DESTINATION ${header_install_dir} + EXCLUDE_FROM_ALL + COMPONENT ppc-htm-resource-headers) + install( FILES ${riscv_generated_files} DESTINATION ${header_install_dir} @@ -583,6 +595,9 @@ if (NOT LLVM_ENABLE_IDE) add_llvm_install_targets(install-ppc-resource-headers DEPENDS ppc-resource-headers COMPONENT ppc-resource-headers) + add_llvm_install_targets(install-ppc-htm-resource-headers + DEPENDS ppc-htm-resource-headers + COMPONENT ppc-htm-resource-headers) add_llvm_install_targets(install-riscv-resource-headers DEPENDS riscv-resource-headers COMPONENT riscv-resource-headers) ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 1f12718 - [clang] Fixing arm-common, windows only and openmp header install targets
Author: Qiongsi Wu Date: 2022-05-20T12:29:10-04:00 New Revision: 1f12718ccfd660f01ac0e444d4632cf8ce6b98e2 URL: https://github.com/llvm/llvm-project/commit/1f12718ccfd660f01ac0e444d4632cf8ce6b98e2 DIFF: https://github.com/llvm/llvm-project/commit/1f12718ccfd660f01ac0e444d4632cf8ce6b98e2.diff LOG: [clang] Fixing arm-common, windows only and openmp header install targets https://reviews.llvm.org/D123498 contains a few errors resulting in incorrect target contents or mismatched target/list names. This patch fixes all the known errors. Reviewed By: craig.topper Differential Revision: https://reviews.llvm.org/D126002 Added: Modified: clang/lib/Headers/CMakeLists.txt Removed: diff --git a/clang/lib/Headers/CMakeLists.txt b/clang/lib/Headers/CMakeLists.txt index 08c5dccb3b77a..8bf7dd570384f 100644 --- a/clang/lib/Headers/CMakeLists.txt +++ b/clang/lib/Headers/CMakeLists.txt @@ -366,7 +366,7 @@ set_target_properties("clang-resource-headers" PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${output_dir}") add_dependencies("clang-resource-headers" "core-resource-headers" - "arm-common-headers" + "arm-common-resource-headers" "arm-resource-headers" "aarch64-resource-headers" "cuda-resource-headers" @@ -387,7 +387,7 @@ add_dependencies("clang-resource-headers" # Core/common headers add_header_target("core-resource-headers" ${core_files}) -add_header_target("arm-common-headers" "${arm_common_files};${arm_common_generated_files}") +add_header_target("arm-common-resource-headers" "${arm_common_files};${arm_common_generated_files}") # Architecture/platform specific targets add_header_target("arm-resource-headers" "${arm_only_files};${arm_only_generated_files}") @@ -546,7 +546,7 @@ install( install( FILES ${openmp_wrapper_files} - DESTINATION ${header_install_dir} + DESTINATION ${header_install_dir}/openmp_wrappers EXCLUDE_FROM_ALL COMPONENT openmp-resource-headers) @@ -557,7 +557,7 @@ install( COMPONENT utility-resource-headers) install( - FILES ${windows_files} + FILES ${windows_only_files} DESTINATION ${header_install_dir} EXCLUDE_FROM_ALL COMPONENT windows-resource-headers) @@ -621,7 +621,7 @@ if (NOT LLVM_ENABLE_IDE) DEPENDS openmp-resource-headers COMPONENT openmp-resource-headers) add_llvm_install_targets(install-windows-resource-headers - DEPENDS window-resource-headers + DEPENDS windows-resource-headers COMPONENT windows-resource-headers) add_llvm_install_targets(install-utility-resource-headers DEPENDS utility-resource-headers ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [compiler-rt] [PGO] Reland PGO's Counter Reset and File Dumping APIs #76471 (PR #78285)
https://github.com/qiongsiwu created https://github.com/llvm/llvm-project/pull/78285 https://github.com/llvm/llvm-project/pull/76471 caused buildbot failure on Windows. For more details, see https://github.com/llvm/llvm-project/issues/77546. This PR revises the test and relands https://github.com/llvm/llvm-project/pull/76471. >From dbeeecfb7e378b0d6964bb24a58b0f695c259ca8 Mon Sep 17 00:00:00 2001 From: Qiongsi Wu Date: Fri, 12 Jan 2024 11:45:50 -0500 Subject: [PATCH 1/2] Reland https://github.com/llvm/llvm-project/pull/76471 --- .../ExpandModularHeadersPPCallbacks.cpp | 2 +- clang/docs/UsersManual.rst| 104 ++ clang/include/clang/Basic/CodeGenOptions.h| 3 + clang/include/clang/Frontend/Utils.h | 4 +- clang/lib/Frontend/CompilerInstance.cpp | 2 +- clang/lib/Frontend/InitPreprocessor.cpp | 23 +++- clang/test/Profile/c-general.c| 10 ++ compiler-rt/include/CMakeLists.txt| 1 + .../include/profile/instr_prof_interface.h| 92 compiler-rt/lib/profile/InstrProfiling.h | 61 ++ .../profile/Linux/instrprof-weak-symbol.c | 16 +++ compiler-rt/test/profile/instrprof-api.c | 46 12 files changed, 307 insertions(+), 57 deletions(-) create mode 100644 compiler-rt/include/profile/instr_prof_interface.h create mode 100644 compiler-rt/test/profile/Linux/instrprof-weak-symbol.c create mode 100644 compiler-rt/test/profile/instrprof-api.c diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp index e414ac8c770508..5ecd4fb19131e4 100644 --- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp +++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp @@ -100,7 +100,7 @@ ExpandModularHeadersPPCallbacks::ExpandModularHeadersPPCallbacks( /*OwnsHeaderSearch=*/false); PP->Initialize(Compiler.getTarget(), Compiler.getAuxTarget()); InitializePreprocessor(*PP, *PO, Compiler.getPCHContainerReader(), - Compiler.getFrontendOpts()); + Compiler.getFrontendOpts(), Compiler.getCodeGenOpts()); ApplyHeaderSearchOptions(*HeaderInfo, *HSO, LangOpts, Compiler.getTarget().getTriple()); } diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst index 7c30570437e8b0..27c629a1ffc657 100644 --- a/clang/docs/UsersManual.rst +++ b/clang/docs/UsersManual.rst @@ -2809,6 +2809,110 @@ indexed format, regardeless whether it is produced by frontend or the IR pass. overhead. ``prefer-atomic`` will be transformed to ``atomic`` when supported by the target, or ``single`` otherwise. +Fine Tuning Profile Collection +^^ + +The PGO infrastructure provides user program knobs to fine tune profile +collection. Specifically, the PGO runtime provides the following functions +that can be used to control the regions in the program where profiles should +be collected. + + * ``void __llvm_profile_set_filename(const char *Name)``: changes the name of + the profile file to ``Name``. + * ``void __llvm_profile_reset_counters(void)``: resets all counters to zero. + * ``int __llvm_profile_dump(void)``: write the profile data to disk. + * ``int __llvm_orderfile_dump(void)``: write the order file to disk. + +For example, the following pattern can be used to skip profiling program +initialization, profile two specific hot regions, and skip profiling program +cleanup: + +.. code-block:: c + +int main() { + initialize(); + + // Reset all profile counters to 0 to omit profile collected during + // initialize()'s execution. + __llvm_profile_reset_counters(); + ... hot region 1 + // Dump the profile for hot region 1. + __llvm_profile_set_filename("region1.profraw"); + __llvm_profile_dump(); + + // Reset counters before proceeding to hot region 2. + __llvm_profile_reset_counters(); + ... hot region 2 + // Dump the profile for hot region 2. + __llvm_profile_set_filename("region2.profraw"); + __llvm_profile_dump(); + + // Since the profile has been dumped, no further profile data + // will be collected beyond the above __llvm_profile_dump(). + cleanup(); + return 0; +} + +These APIs' names can be introduced to user programs in two ways. +They can be declared as weak symbols on platforms which support +treating weak symbols as ``null`` during linking. For example, the user can +have + +.. code-block:: c + +__attribute__((weak)) int __llvm_profile_dump(void); + +// Then later in the same source file +if (__llvm_profile_dump) + if (__llvm_profile_dump() != 0) { ... } +// The first if condition tests if the symbol is actually defined. +// Profile dumping only happens if the symbol is defined. Hen
[clang] [clang-tools-extra] [compiler-rt] [PGO] Reland PGO's Counter Reset and File Dumping APIs #76471 (PR #78285)
https://github.com/qiongsiwu edited https://github.com/llvm/llvm-project/pull/78285 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [compiler-rt] [PGO] Reland PGO's Counter Reset and File Dumping APIs #76471 (PR #78285)
https://github.com/qiongsiwu updated https://github.com/llvm/llvm-project/pull/78285 >From d64fabb3911ae6990a87729a2477df32c837fb1f Mon Sep 17 00:00:00 2001 From: Qiongsi Wu Date: Fri, 12 Jan 2024 11:45:50 -0500 Subject: [PATCH 1/2] Reland https://github.com/llvm/llvm-project/pull/76471 --- .../ExpandModularHeadersPPCallbacks.cpp | 2 +- clang/docs/UsersManual.rst| 104 ++ clang/include/clang/Basic/CodeGenOptions.h| 3 + clang/include/clang/Frontend/Utils.h | 4 +- clang/lib/Frontend/CompilerInstance.cpp | 2 +- clang/lib/Frontend/InitPreprocessor.cpp | 23 +++- clang/test/Profile/c-general.c| 10 ++ compiler-rt/include/CMakeLists.txt| 1 + .../include/profile/instr_prof_interface.h| 92 compiler-rt/lib/profile/InstrProfiling.h | 61 ++ .../profile/Linux/instrprof-weak-symbol.c | 16 +++ compiler-rt/test/profile/instrprof-api.c | 46 12 files changed, 307 insertions(+), 57 deletions(-) create mode 100644 compiler-rt/include/profile/instr_prof_interface.h create mode 100644 compiler-rt/test/profile/Linux/instrprof-weak-symbol.c create mode 100644 compiler-rt/test/profile/instrprof-api.c diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp index e414ac8c770508..5ecd4fb19131e4 100644 --- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp +++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp @@ -100,7 +100,7 @@ ExpandModularHeadersPPCallbacks::ExpandModularHeadersPPCallbacks( /*OwnsHeaderSearch=*/false); PP->Initialize(Compiler.getTarget(), Compiler.getAuxTarget()); InitializePreprocessor(*PP, *PO, Compiler.getPCHContainerReader(), - Compiler.getFrontendOpts()); + Compiler.getFrontendOpts(), Compiler.getCodeGenOpts()); ApplyHeaderSearchOptions(*HeaderInfo, *HSO, LangOpts, Compiler.getTarget().getTriple()); } diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst index c6a6b06fc04be7..1c3dde9d93f913 100644 --- a/clang/docs/UsersManual.rst +++ b/clang/docs/UsersManual.rst @@ -2809,6 +2809,110 @@ indexed format, regardeless whether it is produced by frontend or the IR pass. overhead. ``prefer-atomic`` will be transformed to ``atomic`` when supported by the target, or ``single`` otherwise. +Fine Tuning Profile Collection +^^ + +The PGO infrastructure provides user program knobs to fine tune profile +collection. Specifically, the PGO runtime provides the following functions +that can be used to control the regions in the program where profiles should +be collected. + + * ``void __llvm_profile_set_filename(const char *Name)``: changes the name of + the profile file to ``Name``. + * ``void __llvm_profile_reset_counters(void)``: resets all counters to zero. + * ``int __llvm_profile_dump(void)``: write the profile data to disk. + * ``int __llvm_orderfile_dump(void)``: write the order file to disk. + +For example, the following pattern can be used to skip profiling program +initialization, profile two specific hot regions, and skip profiling program +cleanup: + +.. code-block:: c + +int main() { + initialize(); + + // Reset all profile counters to 0 to omit profile collected during + // initialize()'s execution. + __llvm_profile_reset_counters(); + ... hot region 1 + // Dump the profile for hot region 1. + __llvm_profile_set_filename("region1.profraw"); + __llvm_profile_dump(); + + // Reset counters before proceeding to hot region 2. + __llvm_profile_reset_counters(); + ... hot region 2 + // Dump the profile for hot region 2. + __llvm_profile_set_filename("region2.profraw"); + __llvm_profile_dump(); + + // Since the profile has been dumped, no further profile data + // will be collected beyond the above __llvm_profile_dump(). + cleanup(); + return 0; +} + +These APIs' names can be introduced to user programs in two ways. +They can be declared as weak symbols on platforms which support +treating weak symbols as ``null`` during linking. For example, the user can +have + +.. code-block:: c + +__attribute__((weak)) int __llvm_profile_dump(void); + +// Then later in the same source file +if (__llvm_profile_dump) + if (__llvm_profile_dump() != 0) { ... } +// The first if condition tests if the symbol is actually defined. +// Profile dumping only happens if the symbol is defined. Hence, +// the user program works correctly during normal (not profile-generate) +// executions. + +Alternatively, the user program can include the header +``profile/instr_prof_interface.h``, which contains the API names. For example, + +.. code
[clang-tools-extra] [compiler-rt] [clang] [PGO] Reland PGO's Counter Reset and File Dumping APIs #76471 (PR #78285)
qiongsiwu wrote: > thanks for the fix! > > One test `Clang :: Preprocessor/init.c` failed > (https://lab.llvm.org/buildbot/#/builders/74/builds/24843) and the error is > due to mismatched macros (if I'm reading correctly wants `__LONG_LONG_MAX__` > right after `__LLONG_WIDTH__` but sees `__LLVM_INSTR_PROFILE_GENERATE` in the > middle). I'm wondering if the test (and other tests like > `Preprocessor/init-aarch64.c`) needs update (or if they should be fixed by > [#77546 > (comment)](https://github.com/llvm/llvm-project/issues/77546#issuecomment-1887953628)) Thanks for the fast response @minglotus-6 ! The preprocessor `init` tests were failing due to a mis-optimization introduced recently. Due to the misoptimization, `hasProfileInstr()` ([here](https://github.com/llvm/llvm-project/pull/78285/files#diff-3e17619db20856d476f7eee9bd87f730d9594b4aee2b796f6829a55de4c1fbf0R498)) always returned true and hence the `__LLVM_INSTR_PROFILE_GENERATE` macros were always inserted when it should not show up. As noted in the comment, https://github.com/llvm/llvm-project/pull/77831 fixed the mis-optimization. `hasProfileInstr()` is slightly rewritten in this PR as well to avoid triggering the pattern that was mis-optimized. That said this PR still has some issues. Four seemingly unrelated tests are failing the pre-commit CI on Linux and I am investigating. I will update this PR once these failures are sorted out! Thanks for your patience! ``` Failed Tests (4): cfi-devirt-lld-thinlto-x86_64 :: cross-dso/icall/dlopen.cpp cfi-devirt-lld-x86_64 :: cross-dso/icall/dlopen.cpp cfi-standalone-lld-thinlto-x86_64 :: cross-dso/icall/dlopen.cpp cfi-standalone-lld-x86_64 :: cross-dso/icall/dlopen.cpp ``` https://github.com/llvm/llvm-project/pull/78285 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[compiler-rt] [clang] [clang-tools-extra] [PGO] Reland PGO's Counter Reset and File Dumping APIs #76471 (PR #78285)
https://github.com/qiongsiwu updated https://github.com/llvm/llvm-project/pull/78285 >From ebae7155814ad83ebd1a0159b86550c14c72b2b6 Mon Sep 17 00:00:00 2001 From: Qiongsi Wu Date: Fri, 12 Jan 2024 11:45:50 -0500 Subject: [PATCH 1/2] Reland https://github.com/llvm/llvm-project/pull/76471 --- .../ExpandModularHeadersPPCallbacks.cpp | 2 +- clang/docs/UsersManual.rst| 104 ++ clang/include/clang/Basic/CodeGenOptions.h| 3 + clang/include/clang/Frontend/Utils.h | 4 +- clang/lib/Frontend/CompilerInstance.cpp | 2 +- clang/lib/Frontend/InitPreprocessor.cpp | 23 +++- clang/test/Profile/c-general.c| 10 ++ compiler-rt/include/CMakeLists.txt| 1 + .../include/profile/instr_prof_interface.h| 92 compiler-rt/lib/profile/InstrProfiling.h | 61 ++ .../profile/Linux/instrprof-weak-symbol.c | 16 +++ compiler-rt/test/profile/instrprof-api.c | 46 12 files changed, 307 insertions(+), 57 deletions(-) create mode 100644 compiler-rt/include/profile/instr_prof_interface.h create mode 100644 compiler-rt/test/profile/Linux/instrprof-weak-symbol.c create mode 100644 compiler-rt/test/profile/instrprof-api.c diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp index e414ac8c770508f..5ecd4fb19131e43 100644 --- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp +++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp @@ -100,7 +100,7 @@ ExpandModularHeadersPPCallbacks::ExpandModularHeadersPPCallbacks( /*OwnsHeaderSearch=*/false); PP->Initialize(Compiler.getTarget(), Compiler.getAuxTarget()); InitializePreprocessor(*PP, *PO, Compiler.getPCHContainerReader(), - Compiler.getFrontendOpts()); + Compiler.getFrontendOpts(), Compiler.getCodeGenOpts()); ApplyHeaderSearchOptions(*HeaderInfo, *HSO, LangOpts, Compiler.getTarget().getTriple()); } diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst index 881d903d91a7ea4..ff2d4a68b8e55a7 100644 --- a/clang/docs/UsersManual.rst +++ b/clang/docs/UsersManual.rst @@ -2809,6 +2809,110 @@ indexed format, regardeless whether it is produced by frontend or the IR pass. overhead. ``prefer-atomic`` will be transformed to ``atomic`` when supported by the target, or ``single`` otherwise. +Fine Tuning Profile Collection +^^ + +The PGO infrastructure provides user program knobs to fine tune profile +collection. Specifically, the PGO runtime provides the following functions +that can be used to control the regions in the program where profiles should +be collected. + + * ``void __llvm_profile_set_filename(const char *Name)``: changes the name of + the profile file to ``Name``. + * ``void __llvm_profile_reset_counters(void)``: resets all counters to zero. + * ``int __llvm_profile_dump(void)``: write the profile data to disk. + * ``int __llvm_orderfile_dump(void)``: write the order file to disk. + +For example, the following pattern can be used to skip profiling program +initialization, profile two specific hot regions, and skip profiling program +cleanup: + +.. code-block:: c + +int main() { + initialize(); + + // Reset all profile counters to 0 to omit profile collected during + // initialize()'s execution. + __llvm_profile_reset_counters(); + ... hot region 1 + // Dump the profile for hot region 1. + __llvm_profile_set_filename("region1.profraw"); + __llvm_profile_dump(); + + // Reset counters before proceeding to hot region 2. + __llvm_profile_reset_counters(); + ... hot region 2 + // Dump the profile for hot region 2. + __llvm_profile_set_filename("region2.profraw"); + __llvm_profile_dump(); + + // Since the profile has been dumped, no further profile data + // will be collected beyond the above __llvm_profile_dump(). + cleanup(); + return 0; +} + +These APIs' names can be introduced to user programs in two ways. +They can be declared as weak symbols on platforms which support +treating weak symbols as ``null`` during linking. For example, the user can +have + +.. code-block:: c + +__attribute__((weak)) int __llvm_profile_dump(void); + +// Then later in the same source file +if (__llvm_profile_dump) + if (__llvm_profile_dump() != 0) { ... } +// The first if condition tests if the symbol is actually defined. +// Profile dumping only happens if the symbol is defined. Hence, +// the user program works correctly during normal (not profile-generate) +// executions. + +Alternatively, the user program can include the header +``profile/instr_prof_interface.h``, which contains the API names. For example, + +..
[clang-tools-extra] [clang] [compiler-rt] [PGO] Reland PGO's Counter Reset and File Dumping APIs #76471 (PR #78285)
qiongsiwu wrote: It seems that either the precommit CI has some problems, or there are existing `compiler-rt` breakages. https://github.com/llvm/llvm-project/pull/78037 is also failing the same test cases. The changes in #78037 does not look harmful either. I took a brief look at the current buildbots and I don't see any similar failures. Additionally, I am not able to reproduce these failures locally. I will see what can be investigated next, but I suspect at this PR is not the root cause of the `dlopen.cpp` failures. https://github.com/llvm/llvm-project/pull/78285 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [compiler-rt] [PGO] Reland PGO's Counter Reset and File Dumping APIs #76471 (PR #78285)
qiongsiwu wrote: Ok I think I have a good theory on why these tests are failing. Most likely the test machine does not have the latest `lld` during the test. If we build `lld` together with the project, these tests pass. https://github.com/llvm/llvm-project/pull/78285 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [compiler-rt] [PGO] Reland PGO's Counter Reset and File Dumping APIs #76471 (PR #78285)
https://github.com/qiongsiwu updated https://github.com/llvm/llvm-project/pull/78285 >From ebae7155814ad83ebd1a0159b86550c14c72b2b6 Mon Sep 17 00:00:00 2001 From: Qiongsi Wu Date: Fri, 12 Jan 2024 11:45:50 -0500 Subject: [PATCH 1/3] Reland https://github.com/llvm/llvm-project/pull/76471 --- .../ExpandModularHeadersPPCallbacks.cpp | 2 +- clang/docs/UsersManual.rst| 104 ++ clang/include/clang/Basic/CodeGenOptions.h| 3 + clang/include/clang/Frontend/Utils.h | 4 +- clang/lib/Frontend/CompilerInstance.cpp | 2 +- clang/lib/Frontend/InitPreprocessor.cpp | 23 +++- clang/test/Profile/c-general.c| 10 ++ compiler-rt/include/CMakeLists.txt| 1 + .../include/profile/instr_prof_interface.h| 92 compiler-rt/lib/profile/InstrProfiling.h | 61 ++ .../profile/Linux/instrprof-weak-symbol.c | 16 +++ compiler-rt/test/profile/instrprof-api.c | 46 12 files changed, 307 insertions(+), 57 deletions(-) create mode 100644 compiler-rt/include/profile/instr_prof_interface.h create mode 100644 compiler-rt/test/profile/Linux/instrprof-weak-symbol.c create mode 100644 compiler-rt/test/profile/instrprof-api.c diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp index e414ac8c770508f..5ecd4fb19131e43 100644 --- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp +++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp @@ -100,7 +100,7 @@ ExpandModularHeadersPPCallbacks::ExpandModularHeadersPPCallbacks( /*OwnsHeaderSearch=*/false); PP->Initialize(Compiler.getTarget(), Compiler.getAuxTarget()); InitializePreprocessor(*PP, *PO, Compiler.getPCHContainerReader(), - Compiler.getFrontendOpts()); + Compiler.getFrontendOpts(), Compiler.getCodeGenOpts()); ApplyHeaderSearchOptions(*HeaderInfo, *HSO, LangOpts, Compiler.getTarget().getTriple()); } diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst index 881d903d91a7ea4..ff2d4a68b8e55a7 100644 --- a/clang/docs/UsersManual.rst +++ b/clang/docs/UsersManual.rst @@ -2809,6 +2809,110 @@ indexed format, regardeless whether it is produced by frontend or the IR pass. overhead. ``prefer-atomic`` will be transformed to ``atomic`` when supported by the target, or ``single`` otherwise. +Fine Tuning Profile Collection +^^ + +The PGO infrastructure provides user program knobs to fine tune profile +collection. Specifically, the PGO runtime provides the following functions +that can be used to control the regions in the program where profiles should +be collected. + + * ``void __llvm_profile_set_filename(const char *Name)``: changes the name of + the profile file to ``Name``. + * ``void __llvm_profile_reset_counters(void)``: resets all counters to zero. + * ``int __llvm_profile_dump(void)``: write the profile data to disk. + * ``int __llvm_orderfile_dump(void)``: write the order file to disk. + +For example, the following pattern can be used to skip profiling program +initialization, profile two specific hot regions, and skip profiling program +cleanup: + +.. code-block:: c + +int main() { + initialize(); + + // Reset all profile counters to 0 to omit profile collected during + // initialize()'s execution. + __llvm_profile_reset_counters(); + ... hot region 1 + // Dump the profile for hot region 1. + __llvm_profile_set_filename("region1.profraw"); + __llvm_profile_dump(); + + // Reset counters before proceeding to hot region 2. + __llvm_profile_reset_counters(); + ... hot region 2 + // Dump the profile for hot region 2. + __llvm_profile_set_filename("region2.profraw"); + __llvm_profile_dump(); + + // Since the profile has been dumped, no further profile data + // will be collected beyond the above __llvm_profile_dump(). + cleanup(); + return 0; +} + +These APIs' names can be introduced to user programs in two ways. +They can be declared as weak symbols on platforms which support +treating weak symbols as ``null`` during linking. For example, the user can +have + +.. code-block:: c + +__attribute__((weak)) int __llvm_profile_dump(void); + +// Then later in the same source file +if (__llvm_profile_dump) + if (__llvm_profile_dump() != 0) { ... } +// The first if condition tests if the symbol is actually defined. +// Profile dumping only happens if the symbol is defined. Hence, +// the user program works correctly during normal (not profile-generate) +// executions. + +Alternatively, the user program can include the header +``profile/instr_prof_interface.h``, which contains the API names. For example, + +..
[compiler-rt] [clang] [clang-tools-extra] [PGO] Reland PGO's Counter Reset and File Dumping APIs #76471 (PR #78285)
qiongsiwu wrote: Thanks for to comments/suggestions @w2yehia ! The test is modified so that 1. The profile files are generated. 2. The test does not support Windows to avoid known limitations on Windows. https://github.com/llvm/llvm-project/pull/78285 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[compiler-rt] [clang-tools-extra] [clang] [PGO] Reland PGO's Counter Reset and File Dumping APIs #76471 (PR #78285)
qiongsiwu wrote: Hi @vitalybuka ! I am landing this PR. The precommit CI failures do not seem to related to changes in this PR. Please let me know if you see failures and I will revert. Thanks so much! https://github.com/llvm/llvm-project/pull/78285 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[compiler-rt] [clang-tools-extra] [clang] [PGO] Reland PGO's Counter Reset and File Dumping APIs #76471 (PR #78285)
https://github.com/qiongsiwu closed https://github.com/llvm/llvm-project/pull/78285 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [clang-tools-extra] [PGO] Reland PGO's Counter Reset and File Dumping APIs #76471 (PR #78285)
qiongsiwu wrote: > This patch broke both the > [Solaris/sparcv9](https://lab.llvm.org/buildbot/#/builders/72/builds/2015) > and [Solaris/amd64](https://lab.llvm.org/staging/#/builders/94/builds/394) > buildbots. > > If it really requires recent `lld`, this is guaranteed to not work: `lld` > hasn't even been ported to Solaris. Similar issues most likely will exist on > other targets where the bot either doesn't build `lld` or it isn't supported > at all. Thanks for the note @rorth . I will investigate today. This PR in itself does not require `lld`. https://github.com/llvm/llvm-project/pull/78285 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang] [compiler-rt] [PGO] Reland PGO's Counter Reset and File Dumping APIs #76471 (PR #78285)
qiongsiwu wrote: @w2yehia I think a reasonable way to go forward is to remove the testing of `__llvm_orderfile_dump` from the main test, and add a separate test that runs only on Darwin. What do you think? https://github.com/llvm/llvm-project/pull/78285 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang] [compiler-rt] [PGO] Reland PGO's Counter Reset and File Dumping APIs #76471 (PR #78285)
qiongsiwu wrote: @w2yehia and I discussed, and we will remove `__llvm_orderfile_dump` from the main test for now. https://github.com/llvm/llvm-project/pull/78285 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang] [compiler-rt] [PGO] Reland PGO's Counter Reset and File Dumping APIs #76471 (PR #78285)
qiongsiwu wrote: https://github.com/llvm/llvm-project/pull/79150 is posted to avoid calling `_llvm_orderfile_dump()` in the test. https://github.com/llvm/llvm-project/pull/78285 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 04615b6 - [clang][LTO] Setting Desired Default AIX Debugging Options
Author: Qiongsi Wu Date: 2022-10-18T10:43:19-04:00 New Revision: 04615b695aadf5f3860e3be9631131518227f410 URL: https://github.com/llvm/llvm-project/commit/04615b695aadf5f3860e3be9631131518227f410 DIFF: https://github.com/llvm/llvm-project/commit/04615b695aadf5f3860e3be9631131518227f410.diff LOG: [clang][LTO] Setting Desired Default AIX Debugging Options On AIX, `strict-dwarf` defaults to `true`. This patch implement this default behaviour. Additionally, it adds debug tuning tests. Reviewed By: shchenz Differential Revision: https://reviews.llvm.org/D135908 Added: Modified: clang/lib/Driver/ToolChains/CommonArgs.cpp clang/test/Driver/lto-aix.c Removed: diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index ca8fc7b93972f..58e452418fa26 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -589,6 +589,18 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args, Args.MakeArgString(Twine(PluginOptPrefix) + "-debugger-tune=gdb")); } + if (IsOSAIX) { +// On AIX, clang assumes strict-dwarf is true if any debug option is +// specified, unless it is told explicitly not to assume so. +Arg *A = Args.getLastArg(options::OPT_g_Group); +bool EnableDebugInfo = A && !A->getOption().matches(options::OPT_g0) && + !A->getOption().matches(options::OPT_ggdb0); +if (EnableDebugInfo && Args.hasFlag(options::OPT_gstrict_dwarf, +options::OPT_gno_strict_dwarf, true)) + CmdArgs.push_back( + Args.MakeArgString(Twine(PluginOptPrefix) + "-strict-dwarf=true")); + } + bool UseSeparateSections = isUseSeparateSections(ToolChain.getEffectiveTriple()); diff --git a/clang/test/Driver/lto-aix.c b/clang/test/Driver/lto-aix.c index 89b5d5aeb8ef5..1689c2638410f 100644 --- a/clang/test/Driver/lto-aix.c +++ b/clang/test/Driver/lto-aix.c @@ -4,3 +4,30 @@ // // LTOPATH: "-bplugin:{{.*}}libLTO.{{so|dll|dylib}}" // MCPUOPTLEVEL: "-bplugin_opt:-mcpu={{.*}}" "-bplugin_opt:-O3" +// +// Test debugging options +// RUN: %clang --target=powerpc-ibm-aix-xcoff -### %s -flto -g 2>&1 \ +// RUN: | FileCheck -check-prefixes=STRICT,NODEBUGGER-TUNE %s +// RUN: %clang --target=powerpc64-ibm-aix-xcoff -### %s -flto -g 2>&1 \ +// RUN: | FileCheck -check-prefixes=STRICT,NODEBUGGER-TUNE %s +// RUN: %clang --target=powerpc-ibm-aix-xcoff -### %s -flto -g -gdbx 2>&1 \ +// RUN: | FileCheck -check-prefix=DBX -check-prefix=STRICT %s +// RUN: %clang --target=powerpc-ibm-aix-xcoff -### %s -flto -g -ggdb 2>&1 \ +// RUN: | FileCheck -check-prefix=GDB -check-prefix=STRICT %s +// RUN: %clang --target=powerpc-ibm-aix-xcoff -### %s -flto -g -ggdb0 2>&1 \ +// RUN: | FileCheck -check-prefix=GDB -check-prefix=NOSTRICT %s +// RUN: %clang --target=powerpc-ibm-aix-xcoff -### %s -flto -g -ggdb1 2>&1 \ +// RUN: | FileCheck -check-prefix=GDB -check-prefix=STRICT %s +// RUN: %clang --target=powerpc-ibm-aix-xcoff -### %s -flto -g -g0 2>&1 \ +// RUN: | FileCheck -check-prefix=NOSTRICT %s +// RUN: %clang --target=powerpc-ibm-aix-xcoff -### %s -flto -g -gno-strict-dwarf 2>&1 \ +// RUN: | FileCheck -check-prefix=NOSTRICT %s +// RUN: %clang --target=powerpc-ibm-aix-xcoff -### %s -flto -gstrict-dwarf 2>&1 \ +// RUN: | FileCheck -check-prefix=NOSTRICT %s +// +// DBX:"-bplugin_opt:-debugger-tune=dbx" +// GDB:"-bplugin_opt:-debugger-tune=gdb" +// NODEBUGGER-TUNE-NOT: "-bplugin_opt:-debugger-tune=" +// +// STRICT: "-bplugin_opt:-strict-dwarf=true" +// NOSTRICT-NOT: "-bplugin_opt:-strict-dwarf=true" ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] f911598 - [clang][AIX] Omitting Explicit Debugger Tuning Option
Author: Qiongsi Wu Date: 2022-10-20T15:16:31-04:00 New Revision: f911598bd440182b1383aa570de66a574d468a42 URL: https://github.com/llvm/llvm-project/commit/f911598bd440182b1383aa570de66a574d468a42 DIFF: https://github.com/llvm/llvm-project/commit/f911598bd440182b1383aa570de66a574d468a42.diff LOG: [clang][AIX] Omitting Explicit Debugger Tuning Option On AIX, the default debugger is `dbx` so it is not necessary to explicitly set `-debugger-tuning=dbx` in the presence of `-g`. Reviewed By: shchenz Differential Revision: https://reviews.llvm.org/D136187 Added: Modified: clang/lib/Driver/ToolChains/Clang.cpp clang/test/Driver/debug-options.c Removed: diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index da8b715a76984..9d21975751af5 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -4187,8 +4187,10 @@ static void renderDebugOptions(const ToolChain &TC, const Driver &D, } // If a debugger tuning argument appeared, remember it. + bool HasDebuggerTuning = false; if (const Arg *A = Args.getLastArg(options::OPT_gTune_Group, options::OPT_ggdbN_Group)) { +HasDebuggerTuning = true; if (checkDebugInfoOption(A, Args, D, TC)) { if (A->getOption().matches(options::OPT_glldb)) DebuggerTuning = llvm::DebuggerKind::LLDB; @@ -4364,8 +4366,12 @@ static void renderDebugOptions(const ToolChain &TC, const Driver &D, // Adjust the debug info kind for the given toolchain. TC.adjustDebugInfoKind(DebugInfoKind, Args); + // On AIX, the debugger tuning option can be omitted if it is not explicitly + // set. RenderDebugEnablingArgs(Args, CmdArgs, DebugInfoKind, EffectiveDWARFVersion, - DebuggerTuning); + T.isOSAIX() && !HasDebuggerTuning + ? llvm::DebuggerKind::Default + : DebuggerTuning); // -fdebug-macro turns on macro debug info generation. if (Args.hasFlag(options::OPT_fdebug_macro, options::OPT_fno_debug_macro, diff --git a/clang/test/Driver/debug-options.c b/clang/test/Driver/debug-options.c index 7e33d8d393eb2..37a975da5b48d 100644 --- a/clang/test/Driver/debug-options.c +++ b/clang/test/Driver/debug-options.c @@ -116,11 +116,19 @@ // RUN: %clang -### %s -g -target x86_64-scei-ps5 2>&1 \ // RUN: | FileCheck -check-prefix=LDGARANGE %s -// On the AIX, -g defaults to -gdbx and limited debug info. +// On the AIX, -g defaults to limited debug info. // RUN: %clang -### -c -g %s -target powerpc-ibm-aix-xcoff 2>&1 \ -// RUN: | FileCheck -check-prefix=G_LIMITED -check-prefix=G_DBX %s +// RUN: | FileCheck -check-prefix=G_LIMITED %s // RUN: %clang -### -c -g %s -target powerpc64-ibm-aix-xcoff 2>&1 \ -// RUN: | FileCheck -check-prefix=G_LIMITED -check-prefix=G_DBX %s +// RUN: | FileCheck -check-prefix=G_LIMITED %s +// RUN: %clang -### -c -g %s -target powerpc-ibm-aix-xcoff 2>&1 \ +// RUN: | FileCheck -check-prefix=G_NOTUNING %s +// RUN: %clang -### -c -g %s -target powerpc64-ibm-aix-xcoff 2>&1 \ +// RUN: | FileCheck -check-prefix=G_NOTUNING %s +// RUN: %clang -### -c -g -gdbx %s -target powerpc-ibm-aix-xcoff 2>&1 \ +// RUN: | FileCheck -check-prefixes=G_LIMITED,G_DBX %s +// RUN: %clang -### -c -g -gdbx %s -target powerpc64-ibm-aix-xcoff 2>&1 \ +// RUN: | FileCheck -check-prefixes=G_LIMITED,G_DBX %s // For DBX, -g defaults to -gstrict-dwarf. // RUN: %clang -### -c -g %s -target powerpc-ibm-aix-xcoff 2>&1 \ ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] bdd11bb - [clang][LTO][NFC] Adding More Tests for AIX Options
Author: Qiongsi Wu Date: 2022-10-22T11:09:03-04:00 New Revision: bdd11bbace5ee74036912a534ff5a7e07dd102de URL: https://github.com/llvm/llvm-project/commit/bdd11bbace5ee74036912a534ff5a7e07dd102de DIFF: https://github.com/llvm/llvm-project/commit/bdd11bbace5ee74036912a534ff5a7e07dd102de.diff LOG: [clang][LTO][NFC] Adding More Tests for AIX Options This patch adds more tests for AIX. It follows https://reviews.llvm.org/D134820 which added a minimal set of tests for the newly added AIX options. These new tests were originally created by https://reviews.llvm.org/D119109. Since we do not plan to land https://reviews.llvm.org/D119109 in its current shape to add the AIX specific options, we incorporate the relevant tests developed. Reviewed By: w2yehia Differential Revision: https://reviews.llvm.org/D135885 Added: Modified: clang/test/Driver/lto-aix.c Removed: diff --git a/clang/test/Driver/lto-aix.c b/clang/test/Driver/lto-aix.c index 1689c2638410f..88e7eaa4d5df0 100644 --- a/clang/test/Driver/lto-aix.c +++ b/clang/test/Driver/lto-aix.c @@ -5,7 +5,33 @@ // LTOPATH: "-bplugin:{{.*}}libLTO.{{so|dll|dylib}}" // MCPUOPTLEVEL: "-bplugin_opt:-mcpu={{.*}}" "-bplugin_opt:-O3" // +// More opt level option tests +// RUN: %clang --target=powerpc-ibm-aix --sysroot %S/Inputs/aix_ppc_tree %s \ +// RUN: -fuse-ld=ld -flto -O -### 2>&1 | FileCheck --check-prefix=O1 %s +// RUN: %clang --target=powerpc-ibm-aix --sysroot %S/Inputs/aix_ppc_tree %s \ +// RUN: -fuse-ld=ld -flto -O1 -### 2>&1 | FileCheck --check-prefix=O1 %s +// RUN: %clang --target=powerpc-ibm-aix --sysroot %S/Inputs/aix_ppc_tree %s \ +// RUN: -fuse-ld=ld -flto -Og -### 2>&1 | FileCheck --check-prefix=O1 %s +// RUN: %clang --target=powerpc-ibm-aix --sysroot %S/Inputs/aix_ppc_tree %s \ +// RUN: -fuse-ld=ld -flto -O2 -### 2>&1 | FileCheck --check-prefix=O2 %s +// RUN: %clang --target=powerpc-ibm-aix --sysroot %S/Inputs/aix_ppc_tree %s \ +// RUN: -fuse-ld=ld -flto -Os -### 2>&1 | FileCheck --check-prefix=O2 %s +// RUN: %clang --target=powerpc-ibm-aix --sysroot %S/Inputs/aix_ppc_tree %s \ +// RUN: -fuse-ld=ld -flto -Oz -### 2>&1 | FileCheck --check-prefix=O2 %s +// RUN: %clang --target=powerpc-ibm-aix --sysroot %S/Inputs/aix_ppc_tree %s \ +// RUN: -fuse-ld=ld -flto -O3 -### 2>&1 | FileCheck --check-prefix=O3 %s +// RUN: %clang --target=powerpc-ibm-aix --sysroot %S/Inputs/aix_ppc_tree %s \ +// RUN: -fuse-ld=ld -flto -Ofast -### 2>&1 | FileCheck --check-prefix=O3 %s +// +// O1: "-bplugin_opt:-O1" +// O2: "-bplugin_opt:-O2" +// O3: "-bplugin_opt:-O3" +// // Test debugging options +// RUN: %clang --target=powerpc-ibm-aix -### %s -flto -fuse-ld=ld -gdbx 2>&1 \ +// RUN: | FileCheck -check-prefix=DBX %s +// RUN: %clang --target=powerpc-ibm-aix -### %s -flto -fuse-ld=ld -g 2>&1 \ +// RUN: | FileCheck -check-prefix=NODEBUGGER-TUNE %s // RUN: %clang --target=powerpc-ibm-aix-xcoff -### %s -flto -g 2>&1 \ // RUN: | FileCheck -check-prefixes=STRICT,NODEBUGGER-TUNE %s // RUN: %clang --target=powerpc64-ibm-aix-xcoff -### %s -flto -g 2>&1 \ ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] fd448bb - [clang][LTO] Passing vec-extabi to the Backend on AIX
Author: Qiongsi Wu Date: 2022-10-28T09:13:17-04:00 New Revision: fd448bbedce91bcc6aad9072af58a4fcb7f7bf70 URL: https://github.com/llvm/llvm-project/commit/fd448bbedce91bcc6aad9072af58a4fcb7f7bf70 DIFF: https://github.com/llvm/llvm-project/commit/fd448bbedce91bcc6aad9072af58a4fcb7f7bf70.diff LOG: [clang][LTO] Passing vec-extabi to the Backend on AIX This patch passes on the `vec-extabi` mabi option on AIX. Reviewed By: w2yehia Differential Revision: https://reviews.llvm.org/D136874 Added: Modified: clang/lib/Driver/ToolChains/CommonArgs.cpp clang/test/Driver/lto-aix.c Removed: diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index 3feb1a2a63af3..1fcd160b76fab 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -599,6 +599,10 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args, options::OPT_gno_strict_dwarf, true)) CmdArgs.push_back( Args.MakeArgString(Twine(PluginOptPrefix) + "-strict-dwarf=true")); + +if (Args.getLastArg(options::OPT_mabi_EQ_vec_extabi)) + CmdArgs.push_back( + Args.MakeArgString(Twine(PluginOptPrefix) + "-vec-extabi")); } bool UseSeparateSections = diff --git a/clang/test/Driver/lto-aix.c b/clang/test/Driver/lto-aix.c index 88e7eaa4d5df0..e12fa1c3afaee 100644 --- a/clang/test/Driver/lto-aix.c +++ b/clang/test/Driver/lto-aix.c @@ -27,6 +27,16 @@ // O2: "-bplugin_opt:-O2" // O3: "-bplugin_opt:-O3" // +// vec-extabi option +// RUN: %clang --target=powerpc-ibm-aix --sysroot %S/Inputs/aix_ppc_tree %s \ +// RUN: -fuse-ld=ld -flto -mabi=vec-extabi -### 2>&1 \ +// RUN: | FileCheck --check-prefix=VECEXTABI %s +// RUN: %clang --target=powerpc-ibm-aix --sysroot %S/Inputs/aix_ppc_tree %s \ +// RUN: -fuse-ld=ld -flto -### 2>&1 | FileCheck --check-prefix=NOVECEXTABI %s +// +// VECEXTABI: "-bplugin_opt:-vec-extabi" +// NOVECEXTABI-NOT: "-bplugin_opt:-vec-extabi" +// // Test debugging options // RUN: %clang --target=powerpc-ibm-aix -### %s -flto -fuse-ld=ld -gdbx 2>&1 \ // RUN: | FileCheck -check-prefix=DBX %s ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 86cd353 - [LTO][clang] Using Single Dash Consistently when Passing LTO Options
Author: Qiongsi Wu Date: 2022-09-27T14:50:41-04:00 New Revision: 86cd3535206d6db611260aae6f2869202eae4bb4 URL: https://github.com/llvm/llvm-project/commit/86cd3535206d6db611260aae6f2869202eae4bb4 DIFF: https://github.com/llvm/llvm-project/commit/86cd3535206d6db611260aae6f2869202eae4bb4.diff LOG: [LTO][clang] Using Single Dash Consistently when Passing LTO Options The following three static functions in `clang/lib/Driver/ToolChains/CommonArgs.cpp` ``` static void renderRpassOptions(...) static void renderRemarksOptions(...) static void renderRemarksHotnessOptions(...) ``` use `--plugin-opt` for the plugin option prefix, while the function `tools::addLTOOptions` uses `-plugin-opt`. This patch makes sure that we only use `-plugin-opt` (single dash) everywhere. It is not clear to me that why we decided to use `--plugin-opt` in https://reviews.llvm.org/D85810. If using `--plugin-opt` is intended, I'd love to hear the reason and I will close this patch. We intend to followup this patch with a few other patches that teach `clang` to pass plugin options to the AIX linker, which uses a different prefix (`-bplugin_opt:`). Reviewed By: w2yehia Differential Revision: https://reviews.llvm.org/D134668 Added: Modified: clang/lib/Driver/ToolChains/CommonArgs.cpp clang/test/Driver/opt-record.c Removed: diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index 86ed6edfb86fa..d0abc4a0e26c2 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -67,16 +67,16 @@ using namespace llvm::opt; static void renderRpassOptions(const ArgList &Args, ArgStringList &CmdArgs) { if (const Arg *A = Args.getLastArg(options::OPT_Rpass_EQ)) -CmdArgs.push_back(Args.MakeArgString(Twine("--plugin-opt=-pass-remarks=") + +CmdArgs.push_back(Args.MakeArgString(Twine("-plugin-opt=-pass-remarks=") + A->getValue())); if (const Arg *A = Args.getLastArg(options::OPT_Rpass_missed_EQ)) CmdArgs.push_back(Args.MakeArgString( -Twine("--plugin-opt=-pass-remarks-missed=") + A->getValue())); +Twine("-plugin-opt=-pass-remarks-missed=") + A->getValue())); if (const Arg *A = Args.getLastArg(options::OPT_Rpass_analysis_EQ)) CmdArgs.push_back(Args.MakeArgString( -Twine("--plugin-opt=-pass-remarks-analysis=") + A->getValue())); +Twine("-plugin-opt=-pass-remarks-analysis=") + A->getValue())); } static void renderRemarksOptions(const ArgList &Args, ArgStringList &CmdArgs, @@ -97,28 +97,28 @@ static void renderRemarksOptions(const ArgList &Args, ArgStringList &CmdArgs, assert(!F.empty() && "Cannot determine remarks output name."); // Append "opt.ld." to the end of the file name. CmdArgs.push_back( - Args.MakeArgString(Twine("--plugin-opt=opt-remarks-filename=") + F + + Args.MakeArgString(Twine("-plugin-opt=opt-remarks-filename=") + F + Twine(".opt.ld.") + Format)); if (const Arg *A = Args.getLastArg(options::OPT_foptimization_record_passes_EQ)) CmdArgs.push_back(Args.MakeArgString( -Twine("--plugin-opt=opt-remarks-passes=") + A->getValue())); +Twine("-plugin-opt=opt-remarks-passes=") + A->getValue())); CmdArgs.push_back(Args.MakeArgString( - Twine("--plugin-opt=opt-remarks-format=") + Format.data())); + Twine("-plugin-opt=opt-remarks-format=") + Format.data())); } static void renderRemarksHotnessOptions(const ArgList &Args, ArgStringList &CmdArgs) { if (Args.hasFlag(options::OPT_fdiagnostics_show_hotness, options::OPT_fno_diagnostics_show_hotness, false)) -CmdArgs.push_back("--plugin-opt=opt-remarks-with-hotness"); +CmdArgs.push_back("-plugin-opt=opt-remarks-with-hotness"); if (const Arg *A = Args.getLastArg(options::OPT_fdiagnostics_hotness_threshold_EQ)) CmdArgs.push_back(Args.MakeArgString( -Twine("--plugin-opt=opt-remarks-hotness-threshold=") + A->getValue())); +Twine("-plugin-opt=opt-remarks-hotness-threshold=") + A->getValue())); } void tools::addPathIfExists(const Driver &D, const Twine &Path, diff --git a/clang/test/Driver/opt-record.c b/clang/test/Driver/opt-record.c index 02840f49a86f7..fd7cabb284869 100644 --- a/clang/test/Driver/opt-record.c +++ b/clang/test/Driver/opt-record.c @@ -53,28 +53,28 @@ // RUN: %clang -target x86_64-linux -### -o FOO -fuse-ld=lld -flto=thin -fdiagnostics-hotness-threshold=100 -Rpass=inline -Rpass-missed=inline -Rpass-analysis=inline %s 2>&1 | FileCheck %s -check-prefix=CHECK-PASS-RPASS // RUN: %clang -target x86_64-linux -### -o FOO -fuse-ld=lld -flto=thin -fdiagnostics-hotness-threshold=auto -Rpass=inline -Rpass-missed=inline -Rpass-analysis=inline %s 2>&1 | FileCheck %s -check
[clang] b924c8c - [clang][LTO] Remove the use of `--` for arange option
Author: Qiongsi Wu Date: 2022-10-06T20:27:55-04:00 New Revision: b924c8c71daaa1bb869c42d9afca2a09a9b94629 URL: https://github.com/llvm/llvm-project/commit/b924c8c71daaa1bb869c42d9afca2a09a9b94629 DIFF: https://github.com/llvm/llvm-project/commit/b924c8c71daaa1bb869c42d9afca2a09a9b94629.diff LOG: [clang][LTO] Remove the use of `--` for arange option https://reviews.llvm.org/D134668 removed all `--` (double dashes) when using `plugin-opt` to pass linker options and replaced them with `-`. https://reviews.llvm.org/D133092 was committed later but introduced an instance of `--`. This patch replaces the `--` with `-`. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D135400 Added: Modified: clang/lib/Driver/ToolChains/CommonArgs.cpp clang/test/Driver/debug-options-aranges.c Removed: diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index 7f20122722365..7d4efaa88405d 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -514,7 +514,7 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args, // the way out. if (Args.hasArg(options::OPT_gdwarf_aranges)) { CmdArgs.push_back( -Args.MakeArgString("--plugin-opt=-generate-arange-section")); +Args.MakeArgString("-plugin-opt=-generate-arange-section")); } // Try to pass driver level flags relevant to LTO code generation down to diff --git a/clang/test/Driver/debug-options-aranges.c b/clang/test/Driver/debug-options-aranges.c index 4dc098b7d185c..984f0e2411775 100644 --- a/clang/test/Driver/debug-options-aranges.c +++ b/clang/test/Driver/debug-options-aranges.c @@ -3,4 +3,4 @@ /// Check that the linker plugin will get -generate-arange-section. // RUN: %clang -### -g --target=x86_64-linux -flto -gdwarf-aranges %s 2>&1 | FileCheck %s // RUN: %clang -### -g --target=x86_64-linux -flto=thin -gdwarf-aranges %s 2>&1 | FileCheck %s -// CHECK: --plugin-opt=-generate-arange-section +// CHECK: "-plugin-opt=-generate-arange-section" ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] ec94f37 - [LTO][clang] Teaching Clang to Pass Plugin Options to the AIX Linker
Author: Qiongsi Wu Date: 2022-10-12T15:57:46-04:00 New Revision: ec94f372d1c13b40029519a50184258d4de24a13 URL: https://github.com/llvm/llvm-project/commit/ec94f372d1c13b40029519a50184258d4de24a13 DIFF: https://github.com/llvm/llvm-project/commit/ec94f372d1c13b40029519a50184258d4de24a13.diff LOG: [LTO][clang] Teaching Clang to Pass Plugin Options to the AIX Linker This patch teaches `clang` to use the prefix `-bplugin_opt:` (instead of `-plugin-opt`) on AIX, when passing plugin options to the linker. This patch follows https://reviews.llvm.org/D134668. We put the code that decides what plugin option prefix to use at the top of the function `tools::addLTOOptions`. The plugin option prefix, the mcpu prefix, and the opt level prefix are different on AIX. We thought about choosing the strings in a function that reads the linker name and the target triple, or we could push the logic into different derived `ToolChain` classes. But this logic would not be used anywhere else, so these alternatives looked too complicated for what they did. Therefore we are doing it the current way. That said, I am all ears for suggestions to improve this code! Subsequent code uses the `PluginOptPrefix` variable consistently instead of the hardcoded `-plugin-opt`. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D134820 Added: clang/test/Driver/lto-aix.c Modified: clang/lib/Driver/ToolChains/AIX.cpp clang/lib/Driver/ToolChains/AIX.h clang/lib/Driver/ToolChains/CommonArgs.cpp clang/lib/Driver/ToolChains/CommonArgs.h Removed: diff --git a/clang/lib/Driver/ToolChains/AIX.cpp b/clang/lib/Driver/ToolChains/AIX.cpp index 653fbeaffbd4e..748b6a3590053 100644 --- a/clang/lib/Driver/ToolChains/AIX.cpp +++ b/clang/lib/Driver/ToolChains/AIX.cpp @@ -191,6 +191,12 @@ void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA, // Specify linker input file(s). AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA); + if (D.isUsingLTO()) { +assert(!Inputs.empty() && "Must have at least one input."); +addLTOOptions(ToolChain, Args, CmdArgs, Output, Inputs[0], + D.getLTOMode() == LTOK_Thin); + } + if (Args.hasArg(options::OPT_shared) && !hasExportListLinkerOpts(CmdArgs)) { const char *CreateExportListExec = Args.MakeArgString( diff --git a/clang/lib/Driver/ToolChains/AIX.h b/clang/lib/Driver/ToolChains/AIX.h index e7ec3a5ece4dc..c9948a65b89ab 100644 --- a/clang/lib/Driver/ToolChains/AIX.h +++ b/clang/lib/Driver/ToolChains/AIX.h @@ -67,6 +67,7 @@ class LLVM_LIBRARY_VISIBILITY AIX : public ToolChain { return false; } bool isPICDefaultForced() const override { return true; } + bool HasNativeLLVMSupport() const override { return true; } void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index 7d4efaa88405d..21ad9c8b836b2 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -65,24 +65,26 @@ using namespace clang::driver::tools; using namespace clang; using namespace llvm::opt; -static void renderRpassOptions(const ArgList &Args, ArgStringList &CmdArgs) { +static void renderRpassOptions(const ArgList &Args, ArgStringList &CmdArgs, + const StringRef PluginOptPrefix) { if (const Arg *A = Args.getLastArg(options::OPT_Rpass_EQ)) -CmdArgs.push_back(Args.MakeArgString(Twine("-plugin-opt=-pass-remarks=") + - A->getValue())); +CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) + + "-pass-remarks=" + A->getValue())); if (const Arg *A = Args.getLastArg(options::OPT_Rpass_missed_EQ)) CmdArgs.push_back(Args.MakeArgString( -Twine("-plugin-opt=-pass-remarks-missed=") + A->getValue())); +Twine(PluginOptPrefix) + "-pass-remarks-missed=" + A->getValue())); if (const Arg *A = Args.getLastArg(options::OPT_Rpass_analysis_EQ)) CmdArgs.push_back(Args.MakeArgString( -Twine("-plugin-opt=-pass-remarks-analysis=") + A->getValue())); +Twine(PluginOptPrefix) + "-pass-remarks-analysis=" + A->getValue())); } static void renderRemarksOptions(const ArgList &Args, ArgStringList &CmdArgs, const llvm::Triple &Triple, const InputInfo &Input, - const InputInfo &Output) { + const InputInfo &Output, + const StringRef PluginOptPrefix) { StringRef Format = "yaml"; if (const Arg *A = Args.getLastArg(options::OPT_fsave_optimization_record_EQ)) Format = A->getValue(); @@ -96,29 +98,32 @@ static void renderRemarksOptions(const ArgList &Args,
[clang] [clang][AIX]Fix -flto-jobs for AIX. (PR #67853)
https://github.com/qiongsiwu approved this pull request. LGTM! Thanks! https://github.com/llvm/llvm-project/pull/67853 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][AIX]Fix -flto-jobs for AIX. (PR #67853)
https://github.com/qiongsiwu closed https://github.com/llvm/llvm-project/pull/67853 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 611ce24 - [PGO] Enable `-fprofile-update` for `-fprofile-generate`
Author: Qiongsi Wu Date: 2023-08-15T10:10:03-04:00 New Revision: 611ce24114aac1befac6e65d85b0daa721cf71fd URL: https://github.com/llvm/llvm-project/commit/611ce24114aac1befac6e65d85b0daa721cf71fd DIFF: https://github.com/llvm/llvm-project/commit/611ce24114aac1befac6e65d85b0daa721cf71fd.diff LOG: [PGO] Enable `-fprofile-update` for `-fprofile-generate` Currently, the `-fprofile-udpate` is ignored when `-fprofile-generate` is in effect. This patch enables `-fprofile-update` for `-fprofile-generate`. This patch continues the work from https://reviews.llvm.org/D87737, which added `-fprofile-update` in the first place. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D157280 Added: Modified: clang/docs/UsersManual.rst clang/lib/CodeGen/BackendUtil.cpp clang/test/CodeGen/tsan-instrprof-atomic.c llvm/include/llvm/Passes/PassBuilder.h llvm/include/llvm/Support/PGOOptions.h llvm/lib/Passes/PassBuilderPipelines.cpp llvm/lib/Support/PGOOptions.cpp Removed: diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst index 558e205d69c2a3..d7854d3920f4a9 100644 --- a/clang/docs/UsersManual.rst +++ b/clang/docs/UsersManual.rst @@ -2759,9 +2759,6 @@ programs using the same instrumentation method as ``-fprofile-generate``. overhead. ``prefer-atomic`` will be transformed to ``atomic`` when supported by the target, or ``single`` otherwise. - This option currently works with ``-fprofile-arcs`` and ``-fprofile-instr-generate``, - but not with ``-fprofile-generate``. - Disabling Instrumentation ^ diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index e902f7372f3ab5..3e8b2b78a3928b 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -768,7 +768,8 @@ void EmitAssemblyHelper::RunOptimizationPipeline( CodeGenOpts.InstrProfileOutput.empty() ? getDefaultProfileGenName() : CodeGenOpts.InstrProfileOutput, "", "", CodeGenOpts.MemoryProfileUsePath, nullptr, PGOOptions::IRInstr, -PGOOptions::NoCSAction, CodeGenOpts.DebugInfoForProfiling); +PGOOptions::NoCSAction, CodeGenOpts.DebugInfoForProfiling, +/*PseudoProbeForProfiling=*/false, CodeGenOpts.AtomicProfileUpdate); else if (CodeGenOpts.hasProfileIRUse()) { // -fprofile-use. auto CSAction = CodeGenOpts.hasProfileCSIRUse() ? PGOOptions::CSIRUse diff --git a/clang/test/CodeGen/tsan-instrprof-atomic.c b/clang/test/CodeGen/tsan-instrprof-atomic.c index 23402cffa46d8a..04ca7c08410992 100644 --- a/clang/test/CodeGen/tsan-instrprof-atomic.c +++ b/clang/test/CodeGen/tsan-instrprof-atomic.c @@ -1,4 +1,6 @@ // RUN: %clang_cc1 %s -emit-llvm -fprofile-instrument=clang -fprofile-update=atomic -o - | FileCheck %s +// RUN: %clang %s -S -emit-llvm -fprofile-generate -fprofile-update=atomic -o - | FileCheck %s +// RUN: %clang -O3 %s -S -emit-llvm -fprofile-generate -fprofile-update=atomic -o - | FileCheck %s // CHECK: define {{.*}}@foo // CHECK-NOT: load {{.*}}foo diff --git a/llvm/include/llvm/Passes/PassBuilder.h b/llvm/include/llvm/Passes/PassBuilder.h index fdb407263787f6..08c5b112d903a4 100644 --- a/llvm/include/llvm/Passes/PassBuilder.h +++ b/llvm/include/llvm/Passes/PassBuilder.h @@ -560,7 +560,8 @@ class PassBuilder { /// Add PGOInstrumenation passes for O0 only. void addPGOInstrPassesForO0(ModulePassManager &MPM, bool RunProfileGen, - bool IsCS, std::string ProfileFile, + bool IsCS, bool AtomicCounterUpdate, + std::string ProfileFile, std::string ProfileRemappingFile, IntrusiveRefCntPtr FS); @@ -628,7 +629,8 @@ class PassBuilder { ArrayRef Pipeline); void addPGOInstrPasses(ModulePassManager &MPM, OptimizationLevel Level, - bool RunProfileGen, bool IsCS, std::string ProfileFile, + bool RunProfileGen, bool IsCS, + bool AtomicCounterUpdate, std::string ProfileFile, std::string ProfileRemappingFile, ThinOrFullLTOPhase LTOPhase, IntrusiveRefCntPtr FS); diff --git a/llvm/include/llvm/Support/PGOOptions.h b/llvm/include/llvm/Support/PGOOptions.h index 35670c457745a5..87eb29a8de48a0 100644 --- a/llvm/include/llvm/Support/PGOOptions.h +++ b/llvm/include/llvm/Support/PGOOptions.h @@ -32,7 +32,8 @@ struct PGOOptions { IntrusiveRefCntPtr FS, PGOAction Action = NoAction, CSPGOAction CSAction = NoCSAction, bool DebugInfoForProfiling = false, - bool PseudoProbeForProfiling = false); + bool PseudoProbeForProfi
[clang] 0b66b34 - [clang][AIX] Fix Overly Strict LTO Option Checking against `data-sections` when `mxcoff-roptr` is in Effect
Author: Qiongsi Wu Date: 2023-07-11T13:24:09-04:00 New Revision: 0b66b3417c026e145708d0e20bfd05a72e79f12a URL: https://github.com/llvm/llvm-project/commit/0b66b3417c026e145708d0e20bfd05a72e79f12a DIFF: https://github.com/llvm/llvm-project/commit/0b66b3417c026e145708d0e20bfd05a72e79f12a.diff LOG: [clang][AIX] Fix Overly Strict LTO Option Checking against `data-sections` when `mxcoff-roptr` is in Effect The LTO `-mxcoff-roptr` [[ https://github.com/llvm/llvm-project/blob/c6b2d25927817bdeca99653ee3e66720f33ce3ae/clang/lib/Driver/ToolChains/CommonArgs.cpp#L750 | check ]] against data sections is overly strict and it ignores the fact that [[ https://github.com/llvm/llvm-project/blob/c6b2d25927817bdeca99653ee3e66720f33ce3ae/llvm/lib/LTO/LTOCodeGenerator.cpp#L427 | data sections is on by default on AIX ]], causing valid LTO compilation to fail when `-fdata-sections` is not explicitly specified. This patch revises the check so that an error is reported only if data sections is explicitly turned off for LTO. Reviewed By: hubert.reinterpretcast Differential Revision: https://reviews.llvm.org/D152021 Added: Modified: clang/lib/Driver/ToolChains/CommonArgs.cpp clang/test/Driver/ppc-roptr.c Removed: diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index a58058fdcd6c3d..3dcbd5b8deb8d7 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -725,13 +725,16 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args, CmdArgs.push_back( Args.MakeArgString(Twine(PluginOptPrefix) + "-function-sections=0")); + bool DataSectionsTurnedOff = false; if (Args.hasFlag(options::OPT_fdata_sections, options::OPT_fno_data_sections, - UseSeparateSections)) + UseSeparateSections)) { CmdArgs.push_back( Args.MakeArgString(Twine(PluginOptPrefix) + "-data-sections=1")); - else if (Args.hasArg(options::OPT_fno_data_sections)) + } else if (Args.hasArg(options::OPT_fno_data_sections)) { +DataSectionsTurnedOff = true; CmdArgs.push_back( Args.MakeArgString(Twine(PluginOptPrefix) + "-data-sections=0")); + } if (Args.hasArg(options::OPT_mxcoff_roptr) || Args.hasArg(options::OPT_mno_xcoff_roptr)) { @@ -744,8 +747,10 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args, << OptStr << ToolChain.getTriple().str(); if (HasRoptr) { - if (!Args.hasFlag(options::OPT_fdata_sections, -options::OPT_fno_data_sections, UseSeparateSections)) + // The data sections option is on by default on AIX. We only need to error + // out when -fno-data-sections is specified explicitly to turn off data + // sections. + if (DataSectionsTurnedOff) D.Diag(diag::err_roptr_requires_data_sections); CmdArgs.push_back( diff --git a/clang/test/Driver/ppc-roptr.c b/clang/test/Driver/ppc-roptr.c index 0ab740da9e04a5..d32bbf622ad889 100644 --- a/clang/test/Driver/ppc-roptr.c +++ b/clang/test/Driver/ppc-roptr.c @@ -12,7 +12,7 @@ // RUN: %clang -### --target=powerpc-ibm-aix-xcoff %s 2>&1 | \ // RUN: FileCheck %s --check-prefix=NO_ROPTR // RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -mxcoff-roptr -flto %s 2>&1 | \ -// RUN: FileCheck %s --check-prefixes=ROPTR,LINK,LTO_ROPTR +// RUN: FileCheck %s --check-prefixes=NO_DATA_SECTION_ERR,ROPTR,LINK,LTO_ROPTR // RUN: touch %t.o // RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -mxcoff-roptr %t.o 2>&1 | \ // RUN: FileCheck %s --check-prefix=LINK @@ -33,14 +33,14 @@ // RUN: %clang -### --target=powerpc64le-unknown-linux-gnu -mno-xcoff-roptr -flto \ // RUN: %t.o 2>&1 | FileCheck %s --check-prefix=TARGET_NOROPTR_ERR -// ROPTR: "-mxcoff-roptr" -// LINK: "-bforceimprw" -// LTO_ROPTR: "-bplugin_opt:-mxcoff-roptr" -// NO_ROPTR-NOT: "-mxcoff-roptr" -// NO_ROPTR-NOT: "-bforceimprw" - // DATA_SECTION_ERR: error: -mxcoff-roptr is supported only with -fdata-sections // NO_DATA_SECTION_ERR-NOT: error: -mxcoff-roptr is supported only with -fdata-sections // TARGET_ROPTR_ERR: error: unsupported option '-mxcoff-roptr' for target 'powerpc64le-unknown-linux-gnu' // TARGET_NOROPTR_ERR: error: unsupported option '-mno-xcoff-roptr' for target 'powerpc64le-unknown-linux-gnu' // SHARED_ERR: error: -mxcoff-roptr is not supported with -shared + +// ROPTR: "-mxcoff-roptr" +// LINK: "-bforceimprw" +// LTO_ROPTR: "-bplugin_opt:-mxcoff-roptr" +// NO_ROPTR-NOT: "-mxcoff-roptr" +// NO_ROPTR-NOT: "-bforceimprw" ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 41447f6 - [libLTO][AIX] Respect `-f[no]-integrated-as` on AIX
Author: Qiongsi Wu Date: 2023-07-12T13:22:02-04:00 New Revision: 41447f6fdfe4d67bbd130bc6035e66f3fa1ebeff URL: https://github.com/llvm/llvm-project/commit/41447f6fdfe4d67bbd130bc6035e66f3fa1ebeff DIFF: https://github.com/llvm/llvm-project/commit/41447f6fdfe4d67bbd130bc6035e66f3fa1ebeff.diff LOG: [libLTO][AIX] Respect `-f[no]-integrated-as` on AIX `libLTO` currently ignores the `-f[no-]integrated-as` flags. This patch teaches `libLTO` to respect them on AIX. The implementation consists of two parts: # Migrate `llc`'s `-no-integrated-as` option to a codegen option so that the option is available to `libLTO`/`lld`/`gold`. # Teach `clang` to pass `-no-integrated-as` accordingly to `libLTO` depending on the `-f[no-]integrated-as` flags. On platforms other than AIX, the `-f[no-]integrated-as` flags are ignored. Reviewed By: MaskRay, steven_wu Differential Revision: https://reviews.llvm.org/D152924 Added: Modified: clang/lib/Driver/ToolChains/CommonArgs.cpp clang/test/Driver/lto-aix.c llvm/include/llvm/CodeGen/CommandFlags.h llvm/lib/CodeGen/CommandFlags.cpp llvm/lib/LTO/LTOCodeGenerator.cpp llvm/test/tools/llvm-lto/aix.ll llvm/tools/llc/llc.cpp Removed: diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index 649d7ddcf8997a..496d4f5e82a663 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -692,6 +692,10 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args, } if (IsOSAIX) { +if (!ToolChain.useIntegratedAs()) + CmdArgs.push_back( + Args.MakeArgString(Twine(PluginOptPrefix) + "-no-integrated-as=1")); + // On AIX, clang assumes strict-dwarf is true if any debug option is // specified, unless it is told explicitly not to assume so. Arg *A = Args.getLastArg(options::OPT_g_Group); diff --git a/clang/test/Driver/lto-aix.c b/clang/test/Driver/lto-aix.c index c960d2f9a77755..a07dbd759fa5ff 100644 --- a/clang/test/Driver/lto-aix.c +++ b/clang/test/Driver/lto-aix.c @@ -4,7 +4,7 @@ // // LTOPATH: "-bplugin:{{.*}}libLTO.{{so|dll|dylib}}" // MCPUOPTLEVEL: "-bplugin_opt:-mcpu={{.*}}" "-bplugin_opt:-O3" -// + // More opt level option tests // RUN: %clang --target=powerpc-ibm-aix --sysroot %S/Inputs/aix_ppc_tree %s \ // RUN: -fuse-ld=ld -flto -O -### 2>&1 | FileCheck --check-prefix=O1 %s @@ -26,7 +26,7 @@ // O1: "-bplugin_opt:-O1" // O2: "-bplugin_opt:-O2" // O3: "-bplugin_opt:-O3" -// + // vec-extabi option // RUN: %clang --target=powerpc-ibm-aix --sysroot %S/Inputs/aix_ppc_tree %s \ // RUN: -fuse-ld=ld -flto -mabi=vec-extabi -### 2>&1 \ @@ -36,7 +36,7 @@ // // VECEXTABI: "-bplugin_opt:-vec-extabi" // NOVECEXTABI-NOT: "-bplugin_opt:-vec-extabi" -// + // Test debugging options // RUN: %clang --target=powerpc-ibm-aix -### %s -flto -fuse-ld=ld -gdbx 2>&1 \ // RUN: | FileCheck -check-prefix=DBX %s @@ -67,9 +67,20 @@ // // STRICT: "-bplugin_opt:-strict-dwarf=true" // NOSTRICT-NOT: "-bplugin_opt:-strict-dwarf=true" -// + // Test cspgo options // RUN: %clang --target=powerpc-ibm-aix -### %s -flto -fuse-ld=ld \ // RUN: -fcs-profile-generate 2>&1 | FileCheck -check-prefix=CSPGO %s // // CSPGO: "-bplugin_opt:-cs-profile-generate" "-bplugin_opt:-cs-profile-path=default_%m.profraw" + +// Test integrated assembler options +// RUN: %clang --target=powerpc-ibm-aix -### %s -flto -fno-integrated-as \ +// RUN: -fintegrated-as 2>&1 | FileCheck --check-prefix=INTAS %s +// RUN: %clang --target=powerpc-ibm-aix -### %s -flto -fintegrated-as \ +// RUN: -fno-integrated-as 2>&1 | FileCheck --check-prefix=NOINTAS %s +// RUN: %clang --target=powerpc-ibm-aix -### %s -flto 2>&1 \ +// RUN: | FileCheck --check-prefix=INTAS %s +// +// NOINTAS: "-bplugin_opt:-no-integrated-as=1" +// INTAS-NOT: "-bplugin_opt:-no-integrated-as" diff --git a/llvm/include/llvm/CodeGen/CommandFlags.h b/llvm/include/llvm/CodeGen/CommandFlags.h index 27794eb63de0b3..fa10ddd4447dc9 100644 --- a/llvm/include/llvm/CodeGen/CommandFlags.h +++ b/llvm/include/llvm/CodeGen/CommandFlags.h @@ -94,6 +94,8 @@ std::string getTrapFuncName(); bool getUseCtors(); +bool getDisableIntegratedAS(); + bool getRelaxELFRelocations(); bool getDataSections(); diff --git a/llvm/lib/CodeGen/CommandFlags.cpp b/llvm/lib/CodeGen/CommandFlags.cpp index 59b5decbc808c2..c34a52a6f2de90 100644 --- a/llvm/lib/CodeGen/CommandFlags.cpp +++ b/llvm/lib/CodeGen/CommandFlags.cpp @@ -81,6 +81,7 @@ CGOPT(bool, StackSymbolOrdering) CGOPT(bool, StackRealign) CGOPT(std::string, TrapFuncName) CGOPT(bool, UseCtors) +CGOPT(bool, DisableIntegratedAS) CGOPT(bool, RelaxELFRelocations) CGOPT_EXP(bool, DataSections) CGOPT_EXP(bool, FunctionSections) @@ -487,6 +488,11 @@ codegen::RegisterCodeGenFlags::RegisterCodeGenFlags() { cl::init(false)); CGB
[clang] a6e6abd - [AIX] Fix Link Issue when `-fprofile-update=[atomic|prefer-atomic]` is in Effect
Author: Qiongsi Wu Date: 2023-08-30T19:20:17-04:00 New Revision: a6e6abd76cd31011f7685bda2c95ac6468df4f65 URL: https://github.com/llvm/llvm-project/commit/a6e6abd76cd31011f7685bda2c95ac6468df4f65 DIFF: https://github.com/llvm/llvm-project/commit/a6e6abd76cd31011f7685bda2c95ac6468df4f65.diff LOG: [AIX] Fix Link Issue when `-fprofile-update=[atomic|prefer-atomic]` is in Effect https://reviews.llvm.org/D157280 enabled `-fprofile-update` for `-fprofile-generate`, but omitted adding `-latomic` to the linker command on AIX. This omission causes linking to fail due to an undefined symbol. This patch fixes the link error. Reviewed By: w2yehia Differential Revision: https://reviews.llvm.org/D159137 Added: Modified: clang/lib/Driver/ToolChains/AIX.cpp clang/test/Driver/fprofile-update.c Removed: diff --git a/clang/lib/Driver/ToolChains/AIX.cpp b/clang/lib/Driver/ToolChains/AIX.cpp index 97217eba9ca01a..6cc92238aa9abf 100644 --- a/clang/lib/Driver/ToolChains/AIX.cpp +++ b/clang/lib/Driver/ToolChains/AIX.cpp @@ -429,11 +429,20 @@ void AIX::addClangTargetOptions( void AIX::addProfileRTLibs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const { - // Add linker option -u__llvm_profile_runtime to cause runtime - // initialization to occur. - if (needsProfileRT(Args)) + if (needsProfileRT(Args)) { +// Add linker option -u__llvm_profile_runtime to cause runtime +// initialization to occur. CmdArgs.push_back(Args.MakeArgString( Twine("-u", llvm::getInstrProfRuntimeHookVarName(; + +if (const auto *A = +Args.getLastArgNoClaim(options::OPT_fprofile_update_EQ)) { + StringRef Val = A->getValue(); + if (Val == "atomic" || Val == "prefer-atomic") +CmdArgs.push_back("-latomic"); +} + } + ToolChain::addProfileRTLibs(Args, CmdArgs); } diff --git a/clang/test/Driver/fprofile-update.c b/clang/test/Driver/fprofile-update.c index 2cad883cd81717..3313a2c1cb9af4 100644 --- a/clang/test/Driver/fprofile-update.c +++ b/clang/test/Driver/fprofile-update.c @@ -12,3 +12,11 @@ // RUN: not %clang %s -c -fprofile-update=unknown 2>&1 | FileCheck %s --check-prefix=ERROR // ERROR: error: unsupported argument 'unknown' to option '-fprofile-update=' + +// AIX specific tests +// RUN: %clang -### %s --target=powerpc-unknown-aix -fprofile-generate -fprofile-update=atomic 2>&1 | FileCheck %s --check-prefix=AIX +// RUN: %clang -### %s --target=powerpc-unknown-aix -fprofile-generate -fprofile-update=prefer-atomic 2>&1 | FileCheck %s --check-prefix=AIX +// RUN: %clang -### %s --target=powerpc-unknown-aix -fprofile-generate 2>&1 | FileCheck %s --check-prefix=AIX-NOATOMIC +// RUN: %clang -### %s --target=powerpc-unknown-aix -fprofile-generate -fprofile-update=single 2>&1 | FileCheck %s --check-prefix=AIX-NOATOMIC +// AIX: "-latomic" +// AIX-NOATOMIC-NOT: "-latomic" ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 3faab85 - [AIX][LTO] Enabling Context Sensitive PGO Options
Author: Qiongsi Wu Date: 2022-11-30T10:22:26-05:00 New Revision: 3faab85c12bc1d96e144dcb6d8f75bcafa120c79 URL: https://github.com/llvm/llvm-project/commit/3faab85c12bc1d96e144dcb6d8f75bcafa120c79 DIFF: https://github.com/llvm/llvm-project/commit/3faab85c12bc1d96e144dcb6d8f75bcafa120c79.diff LOG: [AIX][LTO] Enabling Context Sensitive PGO Options This patch enables context sensitive PGO (CSPGO) for LTO on AIX. Two parts are involved: # Frontend logic is added so libLTO can understand the CSPGO related options. # Two options are added to the backend so that the LTOCodeGenerator can understand the CSPGO related options and make use of them. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D138854 Added: Modified: clang/lib/Driver/ToolChains/CommonArgs.cpp clang/test/Driver/lto-aix.c llvm/lib/LTO/LTOCodeGenerator.cpp Removed: diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index 30fca3a4c0590..cbdb51fe9d688 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -519,8 +519,7 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args, } const char *PluginOptPrefix = IsOSAIX ? "-bplugin_opt:" : "-plugin-opt="; - const char *mcpuOptPrefix = IsOSAIX ? "-mcpu=" : "mcpu="; - const char *OptLevelPrefix = IsOSAIX ? "-O" : "O"; + const char *ExtraDash = IsOSAIX ? "-" : ""; // Note, this solution is far from perfect, better to encode it into IR // metadata, but this may not be worth it, since it looks like aranges is on @@ -537,7 +536,7 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args, std::string CPU = getCPUName(D, Args, ToolChain.getTriple()); if (!CPU.empty()) CmdArgs.push_back( -Args.MakeArgString(Twine(PluginOptPrefix) + mcpuOptPrefix + CPU)); +Args.MakeArgString(Twine(PluginOptPrefix) + ExtraDash + "mcpu=" + CPU)); if (Arg *A = Args.getLastArg(options::OPT_O_Group)) { // The optimization level matches @@ -556,7 +555,7 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args, OOpt = "0"; if (!OOpt.empty()) CmdArgs.push_back( - Args.MakeArgString(Twine(PluginOptPrefix) + OptLevelPrefix + OOpt)); + Args.MakeArgString(Twine(PluginOptPrefix) + ExtraDash + "O" + OOpt)); } if (Args.hasArg(options::OPT_gsplit_dwarf)) @@ -650,24 +649,25 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args, auto *ProfileUseArg = getLastProfileUseArg(Args); if (CSPGOGenerateArg) { -CmdArgs.push_back( -Args.MakeArgString(Twine(PluginOptPrefix) + "cs-profile-generate")); +CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) + ExtraDash + + "cs-profile-generate")); if (CSPGOGenerateArg->getOption().matches( options::OPT_fcs_profile_generate_EQ)) { SmallString<128> Path(CSPGOGenerateArg->getValue()); llvm::sys::path::append(Path, "default_%m.profraw"); - CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) + + CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) + ExtraDash + "cs-profile-path=" + Path)); } else - CmdArgs.push_back(Args.MakeArgString( - Twine(PluginOptPrefix) + "cs-profile-path=default_%m.profraw")); + CmdArgs.push_back( + Args.MakeArgString(Twine(PluginOptPrefix) + ExtraDash + + "cs-profile-path=default_%m.profraw")); } else if (ProfileUseArg) { SmallString<128> Path( ProfileUseArg->getNumValues() == 0 ? "" : ProfileUseArg->getValue()); if (Path.empty() || llvm::sys::fs::is_directory(Path)) llvm::sys::path::append(Path, "default.profdata"); -CmdArgs.push_back( -Args.MakeArgString(Twine(PluginOptPrefix) + "cs-profile-path=" + Path)); +CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) + ExtraDash + + "cs-profile-path=" + Path)); } // This controls whether or not we perform JustMyCode instrumentation. diff --git a/clang/test/Driver/lto-aix.c b/clang/test/Driver/lto-aix.c index e12fa1c3afaee..c960d2f9a7775 100644 --- a/clang/test/Driver/lto-aix.c +++ b/clang/test/Driver/lto-aix.c @@ -67,3 +67,9 @@ // // STRICT: "-bplugin_opt:-strict-dwarf=true" // NOSTRICT-NOT: "-bplugin_opt:-strict-dwarf=true" +// +// Test cspgo options +// RUN: %clang --target=powerpc-ibm-aix -### %s -flto -fuse-ld=ld \ +// RUN: -fcs-profile-generate 2>&1 | FileCheck -check-prefix=CSPGO %s +// +// CSPGO: "-bplugin_opt:-cs-profile-generate" "-bplugin_opt:-cs-profile-path=default_%m.profraw" diff --git a/llvm/lib/LTO/LTOCodeGenerator.cpp b/llvm/lib/LTO/LTOCodeGenerator.cpp index
[clang] 9715af4 - [AIX][clang] Storage Locations for Constant Pointers
Author: Qiongsi Wu Date: 2023-05-15T11:31:00-04:00 New Revision: 9715af434579022b5ef31781be40b722d7e63bee URL: https://github.com/llvm/llvm-project/commit/9715af434579022b5ef31781be40b722d7e63bee DIFF: https://github.com/llvm/llvm-project/commit/9715af434579022b5ef31781be40b722d7e63bee.diff LOG: [AIX][clang] Storage Locations for Constant Pointers This patch adds clang options `-mxcoff-roptr` and `-mno-xcoff-roptr` to specify storage locations for constant pointers on AIX. When the `-mxcoff-roptr` option is in effect, constant pointers, virtual function tables, and virtual type tables are placed in read-only storage. When the `-mno-xcoff-roptr` option is in effect, pointers, virtual function tables, and virtual type tables are placed are placed in read/write storage. This patch depends on https://reviews.llvm.org/D144189. Reviewed By: hubert.reinterpretcast, stephenpeckham Differential Revision: https://reviews.llvm.org/D144190 Added: clang/test/CodeGen/PowerPC/aix-roptr.c clang/test/Driver/ppc-roptr.c Modified: clang/docs/ReleaseNotes.rst clang/include/clang/Basic/CodeGenOptions.def clang/include/clang/Basic/DiagnosticDriverKinds.td clang/include/clang/Driver/Options.td clang/lib/CodeGen/BackendUtil.cpp clang/lib/Driver/ToolChains/AIX.cpp clang/lib/Driver/ToolChains/Clang.cpp clang/lib/Driver/ToolChains/CommonArgs.cpp clang/lib/Frontend/CompilerInvocation.cpp Removed: diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 00edb842ae715..7e8dca8b31871 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -543,6 +543,12 @@ AIX Support This option is an alternative to the `--build-id=0xHEXSTRING` GNU linker option which is currently not supported by the AIX linker. +- Introduced the ``-mxcoff-roptr`` option to place constant objects with + relocatable address values in the read-only data section. This option should + be used with the ``-fdata-sections`` option, and is not supported with + ``-fno-data-sections``. When ``-mxcoff-roptr`` is in effect at link time, + read-only data sections with relocatable address values that resolve to + imported symbols are made writable. WebAssembly Support ^^^ diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def index 7151fe9d65682..c026d8e30551f 100644 --- a/clang/include/clang/Basic/CodeGenOptions.def +++ b/clang/include/clang/Basic/CodeGenOptions.def @@ -52,6 +52,7 @@ CODEGENOPT(UniqueBasicBlockSectionNames, 1, 1) ///< Set for -funique-basic-block ///< Produce unique section names with ///< basic block sections. CODEGENOPT(EnableAIXExtendedAltivecABI, 1, 0) ///< Set for -mabi=vec-extabi. Enables the extended Altivec ABI on AIX. +CODEGENOPT(XCOFFReadOnlyPointers, 1, 0) ///< Set for -mxcoff-roptr. ENUM_CODEGENOPT(FramePointer, FramePointerKind, 2, FramePointerKind::None) /// frame-pointer: all,non-leaf,none CODEGENOPT(ClearASTBeforeBackend , 1, 0) ///< Free the AST before running backend code generation. Only works with -disable-free. diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td index 27dcc0dd59f37..8a5a3ad3b7fcf 100644 --- a/clang/include/clang/Basic/DiagnosticDriverKinds.td +++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -649,6 +649,8 @@ def err_drv_invalid_object_mode : Error< "OBJECT_MODE setting %0 is not recognized and is not a valid setting">; def err_aix_unsupported_tls_model : Error<"TLS model '%0' is not yet supported on AIX">; +def err_roptr_requires_data_sections: Error<"-mxcoff-roptr is supported only with -fdata-sections">; +def err_roptr_cannot_build_shared: Error<"-mxcoff-roptr is not supported with -shared">; def err_invalid_cxx_abi : Error<"invalid C++ ABI name '%0'">; def err_unsupported_cxx_abi : Error<"C++ ABI '%0' is not supported on target triple '%1'">; diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index ac2c3c2fa718b..9d765cc6329b8 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -3907,6 +3907,9 @@ def maix_struct_return : Flag<["-"], "maix-struct-return">, def msvr4_struct_return : Flag<["-"], "msvr4-struct-return">, Group, Flags<[CC1Option]>, HelpText<"Return small structs in registers (PPC32 only)">; +def mxcoff_roptr : Flag<["-"], "mxcoff-roptr">, Group, Flags<[CC1Option]>, + HelpText<"Place constant objects with relocatable address values in the RO data section and add -bforceimprw to the linker flags (AIX only)">; +def mno_xcoff_roptr : Flag<["-"], "mno-xcoff-roptr">, Group; def mvx : Flag<["-"], "mvx">, Group; def mno_vx : Flag<["-"], "mno-vx">,
[clang] 80cf56e - [clang][AIX] Remove Newly Added Target Dependent Test Case
Author: Qiongsi Wu Date: 2023-05-15T12:54:09-04:00 New Revision: 80cf56ea1bae05298a823b96b6b545ebca33b44a URL: https://github.com/llvm/llvm-project/commit/80cf56ea1bae05298a823b96b6b545ebca33b44a DIFF: https://github.com/llvm/llvm-project/commit/80cf56ea1bae05298a823b96b6b545ebca33b44a.diff LOG: [clang][AIX] Remove Newly Added Target Dependent Test Case https://reviews.llvm.org/D144190 added a test case that is target dependent and requires assembly code generation, which fails on x64 and aarch64 buildbots. This patch removes the test case. We have test cases for code generation added in https://reviews.llvm.org/D144189 already and this removed case was nice to have. Differential Revision: https://reviews.llvm.org/D150586 Added: Modified: Removed: clang/test/CodeGen/PowerPC/aix-roptr.c diff --git a/clang/test/CodeGen/PowerPC/aix-roptr.c b/clang/test/CodeGen/PowerPC/aix-roptr.c deleted file mode 100644 index 415bfd47bd41f..0 --- a/clang/test/CodeGen/PowerPC/aix-roptr.c +++ /dev/null @@ -1,25 +0,0 @@ -// RUN: %clang_cc1 -triple=powerpc-ibm-aix-xcoff -mxcoff-roptr -fdata-sections \ -// RUN: -S <%s | FileCheck %s --check-prefix=CHECK32 -// RUN: %clang_cc1 -triple=powerpc64-ibm-aix-xcoff -mxcoff-roptr -fdata-sections \ -// RUN: -S <%s | FileCheck %s --check-prefix=CHECK64 -// RUN: not %clang_cc1 -triple=powerpc-ibm-aix-xcoff -mxcoff-roptr \ -// RUN: -S <%s 2>&1 | FileCheck %s --check-prefix=DATA_SECTION_ERR -// RUN: not %clang_cc1 -triple=powerpc64-ibm-aix-xcoff -mxcoff-roptr \ -// RUN: -S <%s 2>&1 | FileCheck %s --check-prefix=DATA_SECTION_ERR -// RUN: not %clang_cc1 -triple=powerpc64le-unknown-linux-gnu -mxcoff-roptr \ -// RUN: %s 2>&1 | FileCheck %s --check-prefix=TARGET_ROPTR_ERR - -char c1 = 10; -char* const c1_ptr = &c1; -// CHECK32: .csect c1_ptr[RO],2 -// CHECK32-NEXT: .globl c1_ptr[RO] -// CHECK32-NEXT: .align 2 -// CHECK32-NEXT: .vbyte 4, c1[RW] - -// CHECK64: .csect c1_ptr[RO],3 -// CHECK64-NEXT: .globl c1_ptr[RO] -// CHECK64-NEXT: .align 3 -// CHECK64-NEXT: .vbyte 8, c1[RW] - -// DATA_SECTION_ERR: error: -mxcoff-roptr is supported only with -fdata-sections -// TARGET_ROPTR_ERR: error: unsupported option '-mxcoff-roptr' for target 'powerpc64le-unknown-linux-gnu' ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 1b1f1b9 - [clang][AIX] Adding Revised xcoff-roptr CodeGen Test Case
Author: Qiongsi Wu Date: 2023-05-16T09:41:24-04:00 New Revision: 1b1f1b9079e2f01f963c6c7cd766d67029ba87cb URL: https://github.com/llvm/llvm-project/commit/1b1f1b9079e2f01f963c6c7cd766d67029ba87cb DIFF: https://github.com/llvm/llvm-project/commit/1b1f1b9079e2f01f963c6c7cd766d67029ba87cb.diff LOG: [clang][AIX] Adding Revised xcoff-roptr CodeGen Test Case https://reviews.llvm.org/D150586 removed a problematic test cases that caused failures on non-ppc buildbots. This patch revises the test case and adds it back. Reviewed By: hubert.reinterpretcast Differential Revision: https://reviews.llvm.org/D150597 Added: clang/test/CodeGen/PowerPC/aix-roptr.c Modified: Removed: diff --git a/clang/test/CodeGen/PowerPC/aix-roptr.c b/clang/test/CodeGen/PowerPC/aix-roptr.c new file mode 100644 index 0..8ae595c54cd84 --- /dev/null +++ b/clang/test/CodeGen/PowerPC/aix-roptr.c @@ -0,0 +1,26 @@ +// REQUIRES: powerpc-registered-target +// RUN: %clang_cc1 -triple=powerpc-ibm-aix-xcoff -mxcoff-roptr -fdata-sections \ +// RUN: -S <%s | FileCheck %s --check-prefix=CHECK32 +// RUN: %clang_cc1 -triple=powerpc64-ibm-aix-xcoff -mxcoff-roptr -fdata-sections \ +// RUN: -S <%s | FileCheck %s --check-prefix=CHECK64 +// RUN: not %clang_cc1 -triple=powerpc-ibm-aix-xcoff -mxcoff-roptr \ +// RUN: -S <%s 2>&1 | FileCheck %s --check-prefix=DATA_SECTION_ERR +// RUN: not %clang_cc1 -triple=powerpc64-ibm-aix-xcoff -mxcoff-roptr \ +// RUN: -S <%s 2>&1 | FileCheck %s --check-prefix=DATA_SECTION_ERR +// RUN: not %clang_cc1 -triple=powerpc64le-unknown-linux-gnu -mxcoff-roptr \ +// RUN: %s 2>&1 | FileCheck %s --check-prefix=TARGET_ROPTR_ERR + +char c1 = 10; +char* const c1_ptr = &c1; +// CHECK32: .csect c1_ptr[RO],2 +// CHECK32-NEXT: .globl c1_ptr[RO] +// CHECK32-NEXT: .align 2 +// CHECK32-NEXT: .vbyte 4, c1[RW] + +// CHECK64: .csect c1_ptr[RO],3 +// CHECK64-NEXT: .globl c1_ptr[RO] +// CHECK64-NEXT: .align 3 +// CHECK64-NEXT: .vbyte 8, c1[RW] + +// DATA_SECTION_ERR: error: -mxcoff-roptr is supported only with -fdata-sections +// TARGET_ROPTR_ERR: error: unsupported option '-mxcoff-roptr' for target 'powerpc64le-unknown-linux-gnu' ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 1fdbe5c - [clang][PPC] Checking Unknown Values Passed to -mcpu
Author: Qiongsi Wu Date: 2022-12-13T10:18:44-05:00 New Revision: 1fdbe5c573b920f00e5bfdbcea0e837833ae77a0 URL: https://github.com/llvm/llvm-project/commit/1fdbe5c573b920f00e5bfdbcea0e837833ae77a0 DIFF: https://github.com/llvm/llvm-project/commit/1fdbe5c573b920f00e5bfdbcea0e837833ae77a0.diff LOG: [clang][PPC] Checking Unknown Values Passed to -mcpu Currently `ppc::getPPCTargetCPU` returns an empty string when it encounters an unknown value passed to `-mcpu`. This causes `clang` to ignore unknown `-mcpu` values silently. This patch changes the behaviour of `ppc::getPPCTargetCPU` so that it passes the unknown option to the target info, so the target info can actually check if the CPU string is supported, and report an error when encountering unknown/unsupported CPU string. Reviewed By: jamieschmeiser Differential Revision: https://reviews.llvm.org/D139720 Added: Modified: clang/lib/Driver/ToolChains/Arch/PPC.cpp clang/lib/Driver/ToolChains/Arch/PPC.h clang/lib/Driver/ToolChains/CommonArgs.cpp clang/test/Driver/ppc-cpus.c Removed: diff --git a/clang/lib/Driver/ToolChains/Arch/PPC.cpp b/clang/lib/Driver/ToolChains/Arch/PPC.cpp index bcaecf4b2d980..f90a772ed5a21 100644 --- a/clang/lib/Driver/ToolChains/Arch/PPC.cpp +++ b/clang/lib/Driver/ToolChains/Arch/PPC.cpp @@ -20,46 +20,45 @@ using namespace clang::driver::tools; using namespace clang; using namespace llvm::opt; +static std::string getPPCGenericTargetCPU(const llvm::Triple &T) { + // LLVM may default to generating code for the native CPU, + // but, like gcc, we default to a more generic option for + // each architecture. (except on AIX) + if (T.isOSAIX()) +return "pwr7"; + else if (T.getArch() == llvm::Triple::ppc64le) +return "ppc64le"; + else if (T.getArch() == llvm::Triple::ppc64) +return "ppc64"; + else +return "ppc"; +} + /// getPPCTargetCPU - Get the (LLVM) name of the PowerPC cpu we are targeting. -std::string ppc::getPPCTargetCPU(const ArgList &Args) { +std::string ppc::getPPCTargetCPU(const ArgList &Args, const llvm::Triple &T) { if (Arg *A = Args.getLastArg(clang::driver::options::OPT_mcpu_EQ)) { StringRef CPUName = A->getValue(); +if (CPUName == "generic") + return getPPCGenericTargetCPU(T); + if (CPUName == "native") { std::string CPU = std::string(llvm::sys::getHostCPUName()); if (!CPU.empty() && CPU != "generic") return CPU; else -return ""; +return getPPCGenericTargetCPU(T); } return llvm::StringSwitch(CPUName) .Case("common", "generic") -.Case("440", "440") .Case("440fp", "440") -.Case("450", "450") -.Case("601", "601") -.Case("602", "602") -.Case("603", "603") -.Case("603e", "603e") -.Case("603ev", "603ev") -.Case("604", "604") -.Case("604e", "604e") -.Case("620", "620") .Case("630", "pwr3") .Case("G3", "g3") -.Case("7400", "7400") .Case("G4", "g4") -.Case("7450", "7450") .Case("G4+", "g4+") -.Case("750", "750") .Case("8548", "e500") -.Case("970", "970") .Case("G5", "g5") -.Case("a2", "a2") -.Case("e500", "e500") -.Case("e500mc", "e500mc") -.Case("e5500", "e5500") .Case("power3", "pwr3") .Case("power4", "pwr4") .Case("power5", "pwr5") @@ -71,23 +70,13 @@ std::string ppc::getPPCTargetCPU(const ArgList &Args) { .Case("power9", "pwr9") .Case("power10", "pwr10") .Case("future", "future") -.Case("pwr3", "pwr3") -.Case("pwr4", "pwr4") -.Case("pwr5", "pwr5") -.Case("pwr5x", "pwr5x") -.Case("pwr6", "pwr6") -.Case("pwr6x", "pwr6x") -.Case("pwr7", "pwr7") -.Case("pwr8", "pwr8") -.Case("pwr9", "pwr9") -.Case("pwr10", "pwr10") .Case("powerpc", "ppc") .Case("powerpc64", "ppc64") .Case("powerpc64le", "ppc64le") -.Default(""); +.Default(CPUName.data()); } - return ""; + return getPPCGenericTargetCPU(T); } const char *ppc::getPPCAsmModeForCPU(StringRef Name) { diff --git a/clang/lib/Driver/ToolChains/Arch/PPC.h b/clang/lib/Driver/ToolChains/Arch/PPC.h index e1c943955e812..cd2b47d392b65 100644 --- a/clang/lib/Driver/ToolChains/Arch/PPC.h +++ b/clang/lib/Driver/ToolChains/Arch/PPC.h @@ -35,7 +35,8 @@ enum class ReadGOTPtrMode { FloatABI getPPCFloatABI(const Driver &D, const llvm::opt::ArgList &Args); -std::string getPPCTargetCPU(const llvm::opt::ArgList &Args); +std::string getPPCTargetCPU(const llvm::opt::ArgList &Args, +const llvm::Triple &T); const char *getPPCAsmModeForCPU(StringRef Name); ReadGOTPtrMode getPPCReadGOTPtrMode(const Driver &D, const llvm::Triple &Triple,
[clang] de8deb5 - [clang][PPC] Supporting -mcpu=405
Author: Qiongsi Wu Date: 2022-12-15T10:55:26-05:00 New Revision: de8deb5189c948db89c753ff2dff65b8e7840e8b URL: https://github.com/llvm/llvm-project/commit/de8deb5189c948db89c753ff2dff65b8e7840e8b DIFF: https://github.com/llvm/llvm-project/commit/de8deb5189c948db89c753ff2dff65b8e7840e8b.diff LOG: [clang][PPC] Supporting -mcpu=405 The ClangBuiltLinux project relies on `-mcpu=405`. Before https://reviews.llvm.org/D139720, `clang` treated `-mcpu=405` implicitly in the same way as `-mcpu=generic`, because `405` was an unknown value and `clang` did not validate unknown input values. https://reviews.llvm.org/D139720 added the validation of `-mcpu` input value, and `clang` now generates an error with `-mcpu=405`. For further details of the problem, see https://github.com/ClangBuiltLinux/linux/issues/1771. This patch adds support of `-mcpu=405` explicitly, and treats it as an equivalent of `-mcpu=generic`. Reviewed By: nemanjai Differential Revision: https://reviews.llvm.org/D140080 Added: Modified: clang/lib/Driver/ToolChains/Arch/PPC.cpp clang/test/Driver/ppc-cpus.c Removed: diff --git a/clang/lib/Driver/ToolChains/Arch/PPC.cpp b/clang/lib/Driver/ToolChains/Arch/PPC.cpp index f90a772ed5a21..6ec736bc701bb 100644 --- a/clang/lib/Driver/ToolChains/Arch/PPC.cpp +++ b/clang/lib/Driver/ToolChains/Arch/PPC.cpp @@ -39,7 +39,12 @@ std::string ppc::getPPCTargetCPU(const ArgList &Args, const llvm::Triple &T) { if (Arg *A = Args.getLastArg(clang::driver::options::OPT_mcpu_EQ)) { StringRef CPUName = A->getValue(); -if (CPUName == "generic") +// Clang/LLVM does not actually support code generation +// for the 405 CPU. However, there are uses of this CPU ID +// in projects that previously used GCC and rely on Clang +// accepting it. Clang has always ignored it and passed the +// generic CPU ID to the back end. +if (CPUName == "generic" || CPUName == "405") return getPPCGenericTargetCPU(T); if (CPUName == "native") { diff --git a/clang/test/Driver/ppc-cpus.c b/clang/test/Driver/ppc-cpus.c index 08da07ec7b176..d623b25e88d95 100644 --- a/clang/test/Driver/ppc-cpus.c +++ b/clang/test/Driver/ppc-cpus.c @@ -31,3 +31,9 @@ // RUN: %clang -### -c --target=powerpc64 %s -mcpu=generic -mtune=pwr9 2>&1 | FileCheck %s --check-prefix=TUNE // TUNE: "-target-cpu" "ppc64" "-tune-cpu" "pwr9" + +/// Test mcpu options that are equivalent to "generic" +// RUN: %clang -### -c -target powerpc64 %s -mcpu=generic 2>&1 | FileCheck %s --check-prefix=GENERIC +// RUN: %clang -### -c -target powerpc64 %s -mcpu=405 2>&1 | FileCheck %s --check-prefix=GENERIC +// +// GENERIC: "-target-cpu" "ppc64" ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [AIX] Turn on `#pragma mc_func` check by default (PR #101336)
qiongsiwu wrote: > > Thank you! However, we're getting pretty late in the release cycle and so > > I'd like to see this backed out of 19.x ASAP (and given the direction the > > discussion is going, I think it should be backed out of main as well). > > @qiongsiwu will you be able to get these changes reverted today? If not, I'll > try to revert them this afternoon. CC @tstellar @tru for release manager > awareness. Yes I will get to this later today. We have discussed and it is OK at the moment to pull out this check. I will open a PR soon (to revert all the commits relevant to the check). https://github.com/llvm/llvm-project/pull/101336 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [AIX] Revert `#pragma mc_func` check (PR #102919)
https://github.com/qiongsiwu created https://github.com/llvm/llvm-project/pull/102919 https://github.com/llvm/llvm-project/pull/99888 added a specific diagnostic for `#pragma mc_func` on AIX. There are some disagreements on: 1. If the check should be on by default. Leaving the check off by default is dangerous, since it is difficult to be aware of such a check. Turning it on by default at the moment causes build failures on AIX. See https://github.com/llvm/llvm-project/pull/101336 for more details. 2. If the check can be made more general. See https://github.com/llvm/llvm-project/pull/101336#issuecomment-2269283906. This PR reverts this check from `main` so we can flush out these disagreements. >From acf020c344512b83cda3da774b68c7e425523e62 Mon Sep 17 00:00:00 2001 From: Qiongsi Wu Date: Mon, 12 Aug 2024 11:34:19 -0400 Subject: [PATCH 1/3] Revert "[NFC] changes all run lines" This reverts commit b830790547c304aa2a771ce0706b337ea5ec7a02. --- clang/test/Preprocessor/pragma_mc_func.c | 12 ++-- 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/clang/test/Preprocessor/pragma_mc_func.c b/clang/test/Preprocessor/pragma_mc_func.c index f0d3e49e5dddca..506ba05e028435 100644 --- a/clang/test/Preprocessor/pragma_mc_func.c +++ b/clang/test/Preprocessor/pragma_mc_func.c @@ -5,19 +5,19 @@ // CHECK: error: #pragma mc_func is not supported // Cases where no errors occur. -// RUN: %clang --target=powerpc64-ibm-aix -fno-err-pragma-mc-func-aix -fsyntax-only %s -// RUN: %clang --target=powerpc64-ibm-aix -ferr-pragma-mc-func-aix -fsyntax-only \ +// RUN: %clang --target=powerpc64-ibm-aix -fno-err-pragma-mc-func-aix -c -S %s +// RUN: %clang --target=powerpc64-ibm-aix -ferr-pragma-mc-func-aix -c -S \ // RUN:-fno-err-pragma-mc-func-aix %s -// RUN: %clang --target=powerpc64-ibm-aix -fsyntax-only %s +// RUN: %clang --target=powerpc64-ibm-aix -c -S %s // RUN: %clang --target=powerpc64-ibm-aix -Werror=unknown-pragmas \ -// RUN: -fno-err-pragma-mc-func-aix -fsyntax-only %s +// RUN: -fno-err-pragma-mc-func-aix -c -S %s // Cases where we have errors or warnings. // RUN: not %clang --target=powerpc64le-unknown-linux-gnu \ -// RUN: -Werror=unknown-pragmas -fno-err-pragma-mc-func-aix -fsyntax-only %s 2>&1 | \ +// RUN: -Werror=unknown-pragmas -fno-err-pragma-mc-func-aix -c -S %s 2>&1 | \ // RUN: FileCheck --check-prefix=UNUSED %s // RUN: %clang --target=powerpc64le-unknown-linux-gnu \ -// RUN: -fno-err-pragma-mc-func-aix -fsyntax-only %s 2>&1 | \ +// RUN: -fno-err-pragma-mc-func-aix -c -S %s 2>&1 | \ // RUN: FileCheck --check-prefix=UNUSED %s // UNUSED: clang: warning: argument unused during compilation: '-fno-err-pragma-mc-func-aix' [-Wunused-command-line-argument] >From f759d3ef6c65326c67dfc230d956d4c799a63a3c Mon Sep 17 00:00:00 2001 From: Qiongsi Wu Date: Mon, 12 Aug 2024 11:34:37 -0400 Subject: [PATCH 2/3] Revert "[NFC] make the case only require frontend" This reverts commit ee07547487a3502f7436968bbfc243b054c14071. --- clang/test/Preprocessor/pragma_mc_func.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/Preprocessor/pragma_mc_func.c b/clang/test/Preprocessor/pragma_mc_func.c index 506ba05e028435..e5f362f10e41a2 100644 --- a/clang/test/Preprocessor/pragma_mc_func.c +++ b/clang/test/Preprocessor/pragma_mc_func.c @@ -1,4 +1,4 @@ -// RUN: not %clang --target=powerpc64-ibm-aix -ferr-pragma-mc-func-aix -fsyntax-only \ +// RUN: not %clang --target=powerpc64-ibm-aix -ferr-pragma-mc-func-aix -c -S \ // RUN: %s 2>&1 | FileCheck %s #pragma mc_func asm_barrier {"6000"} >From 205d2c841d680966dc84cfc907b81ca86295297d Mon Sep 17 00:00:00 2001 From: Qiongsi Wu Date: Mon, 12 Aug 2024 11:35:02 -0400 Subject: [PATCH 3/3] Revert "[AIX] Detect `#pragma mc_func` (#99888)" This reverts commit 9147147b5c191c22a740f8e596e62a6de1fc4f70. --- .../clang/Basic/DiagnosticParseKinds.td | 3 --- clang/include/clang/Driver/Options.td | 7 -- clang/include/clang/Lex/PreprocessorOptions.h | 5 clang/include/clang/Parse/Parser.h| 1 - clang/lib/Driver/ToolChains/AIX.cpp | 6 - clang/lib/Parse/ParsePragma.cpp | 25 --- clang/test/Preprocessor/pragma_mc_func.c | 23 - 7 files changed, 70 deletions(-) delete mode 100644 clang/test/Preprocessor/pragma_mc_func.c diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td index f8d50d12bb9351..12aab09f285567 100644 --- a/clang/include/clang/Basic/DiagnosticParseKinds.td +++ b/clang/include/clang/Basic/DiagnosticParseKinds.td @@ -1260,9 +1260,6 @@ def warn_pragma_intrinsic_builtin : Warning< def warn_pragma_unused_expected_var : Warning< "expected '#pragma unused' argument to be a variable name">, InGroup; -// - #pragma mc_func -def err_pragma_mc_func_not_supported : - Error<"#pragma mc_func is not supported">; // - #pragma ini
[clang] [AIX] Turn on `#pragma mc_func` check by default (PR #101336)
qiongsiwu wrote: https://github.com/llvm/llvm-project/pull/102919 is created to revert this feature now. I will review our discussion and consider an improved implementation. Thanks again for the input and discussion! https://github.com/llvm/llvm-project/pull/101336 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [AIX] Revert `#pragma mc_func` check (PR #102919)
https://github.com/qiongsiwu milestoned https://github.com/llvm/llvm-project/pull/102919 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [AIX] Revert `#pragma mc_func` check (PR #102919)
https://github.com/qiongsiwu closed https://github.com/llvm/llvm-project/pull/102919 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [AIX] Revert `#pragma mc_func` check (PR #102919)
qiongsiwu wrote: /cherry-pick 123b6fc https://github.com/llvm/llvm-project/pull/102919 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [AIX] Detect `#pragma mc_func` (PR #99888)
https://github.com/qiongsiwu closed https://github.com/llvm/llvm-project/pull/99888 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [AIX] Detect `#pragma mc_func` (PR #99888)
qiongsiwu wrote: Thanks for chiming in and describing your concern @AaronBallman ! We think this feature should be in the community clang for the following reasons. 1. It is useful for a community `clang` user on AIX to be aware of uses of `#pragma mc_func` in their code. The community `clang` does not support`#pragma mc_func`, and the pragma should not be used in any situations in user code. Since `#pragma mc_func` defines code that could be executed, silently ignoring them is not an ideal behaviour. `-Werror=unknown-pragmas` can be used, but there could be many such errors that drown out the errors on `#pragma mc_func`. Reporting `#pragma mc_func` as an error all the time is unfortunately not ideal either. Some AIX system headers still contain `#pragma mc_func`, so we provide the users an option to turn off the error detection if that is the user's intention. The flip side is that if a user does include such a header, they will be aware that their code does not work and does not have to debug further. We have already implemented this check downstream. 2. The change has limited impact on other platforms. If the implementation is too heavy, I am all ears for a different way to implement this check. https://github.com/llvm/llvm-project/pull/99888 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [AIX] Detect `#pragma mc_func` (PR #99888)
qiongsiwu wrote: > this same logic can be applied to almost every pragma we don't support, but > we don't want to add special handlers for every pragma we don't support. > It doesn't seem particularly dangerous to ignore this pragma because ignoring > it means no symbol is generated for the synthesized function, so any calls to > that symbol will get errors anyway, right? Yes I agree with both statements. I have not reviewed other pragmas that we do not support, but I think this one is a bit special in that it defines functions (code) that can be executed, and we are aware of use cases where detecting the error at link time is insufficient. Eventually, this error check will be turn on all the time after AIX cleans up the system headers. I agree we should not add checks for arbitrary `pragma`s that we do not support (and probably for each case there is an argument to add such a check), but as stated above, we are aware of use cases that this check adds value. Considering that this check has limited impact on other platforms, we are providing it upstream. If the community has strong objections, I will bring this back to the team to discuss a better way going forward. https://github.com/llvm/llvm-project/pull/99888 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [AIX] Detect `#pragma mc_func` (PR #99888)
qiongsiwu wrote: > Is that not the case? It does not seem so. See [here](https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:___c,selection:(endColumn:40,endLineNumber:8,positionColumn:40,positionLineNumber:8,selectionStartColumn:40,selectionStartLineNumber:8,startColumn:40,startLineNumber:8),source:'%23include+%3Cstdio.h%3E%0A%0A//+Example+from+https://www.ibm.com/docs/en/xl-c-aix/13.1.0%3Ftopic%3Ddescriptions-pragma-mc-func%0A%0A//+Type+your+code+here,+or+load+an+example.%0Aint+add_logical(int,+int)%3B%0A%23pragma+mc_func+add_logical+%7B%227c632014%22+%227c630194%22%7D%0A/*+++addc+++r3+%3C-+r3,+r4+++*/%0A/*+++addze++r3+%3C-+r3,+carry+bit*/%0A%0Aint+main()+%7B%0A%0A++int+i,j,k%3B%0A%0A++i+%3D+4%3B%0A++k+%3D+-4%3B%0A++j+%3D+add_logical(i,k)%3B%0A++printf(%22%5Cn%5Cnresult+%3D+%25d%5Cn%5Cn%22,j)%3B%0A%7D%0A'),l:'5',n:'1',o:'C+source+%231',t:'0')),k:49.8238747553816,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:executor,i:(argsPanelShown:'1',compilationPanelShown:'0',compiler:cclang1810,compilerName:'',compilerOutShown:'0',execArgs:'',execStdin:'',fontScale:14,fontUsePx:'0',j:1,lang:___c,libs:!(),options:'',overrides:!(),runtimeTools:!(),source:1,stdinPanelShown:'0',wrap:'1'),l:'5',n:'0',o:'Executor+x86-64+clang+18.1.0+(C,+Editor+%231)',t:'0')),k:50.1761252446184,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4) for an example. It seems somehow the compiler is treating this symbol as an unknown function that is resolved at link time. Maybe a more reasonable behaviour is indeed to change the parser so that we do get the unknown identifier error? I have not spent too much time look into it to see how big a change that is. https://github.com/llvm/llvm-project/pull/99888 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [AIX] Detect `#pragma mc_func` (PR #99888)
qiongsiwu wrote: > I'm wondering why this option isn't on by default for AIX. I don't think > anyone is going to know to turn this option on, whereas if it's on by > default, users have to make a decision as to how to proceed, which seems like > the better default. Yes I agree. This is at the moment off by default only because certain AIX system headers contain `mc_func`. If the user includes such headers in their program, they may see compile errors, but there is nothing they can do to their source code to fix the problem. We are working on removing all `mc_func` uses from the system headers. Once that is done, we will flip the default behaviour so that the error check is always on. That said, I don't find it unreasonable either to turn on this error by default earlier. The user can use the `no-err` flag to intentionally turn it off. Will bring this back internall for a quick discussion. https://github.com/llvm/llvm-project/pull/99888 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [AIX] Turn on `#pragma mc_func` check by default (PR #101336)
https://github.com/qiongsiwu created https://github.com/llvm/llvm-project/pull/101336 https://github.com/llvm/llvm-project/pull/99888 added a check (and corresponding options) to flag uses of `#pragma mc_func` on AIX. This PR turns on the check by default. >From e823d1e7eb3357fc5c15b614ac5fd94d331ac630 Mon Sep 17 00:00:00 2001 From: Qiongsi Wu Date: Wed, 31 Jul 2024 10:12:59 -0400 Subject: [PATCH] Turn on mc_func check by default. --- clang/include/clang/Driver/Options.td | 2 +- clang/include/clang/Lex/PreprocessorOptions.h | 4 ++-- clang/lib/Driver/ToolChains/AIX.cpp | 2 +- clang/test/Preprocessor/pragma_mc_func.c | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index c8c56dbb51b28..7f6b8ba4d7eeb 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -8097,7 +8097,7 @@ def source_date_epoch : Separate<["-"], "source-date-epoch">, } // let Visibility = [CC1Option] defm err_pragma_mc_func_aix : BoolFOption<"err-pragma-mc-func-aix", - PreprocessorOpts<"ErrorOnPragmaMcfuncOnAIX">, DefaultFalse, + PreprocessorOpts<"ErrorOnPragmaMcfuncOnAIX">, DefaultTrue, PosFlag, NegFlag&1 | FileCheck %s // RUN: not %clang --target=powerpc64-ibm-aix -ferr-pragma-mc-func-aix -fsyntax-only \ // RUN: %s 2>&1 | FileCheck %s #pragma mc_func asm_barrier {"6000"} @@ -8,11 +9,10 @@ // RUN: %clang --target=powerpc64-ibm-aix -fno-err-pragma-mc-func-aix -fsyntax-only %s // RUN: %clang --target=powerpc64-ibm-aix -ferr-pragma-mc-func-aix -fsyntax-only \ // RUN:-fno-err-pragma-mc-func-aix %s -// RUN: %clang --target=powerpc64-ibm-aix -fsyntax-only %s // RUN: %clang --target=powerpc64-ibm-aix -Werror=unknown-pragmas \ // RUN: -fno-err-pragma-mc-func-aix -fsyntax-only %s -// Cases where we have errors or warnings. +// Cases on a non-AIX target. // RUN: not %clang --target=powerpc64le-unknown-linux-gnu \ // RUN: -Werror=unknown-pragmas -fno-err-pragma-mc-func-aix -fsyntax-only %s 2>&1 | \ // RUN: FileCheck --check-prefix=UNUSED %s ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [AIX] Detect `#pragma mc_func` (PR #99888)
qiongsiwu wrote: > My preference is for this to be on-by-default (then it shows its utility), > and I'd like to see those changes in the 19.x release (which means we'd need > to turn this around fairly quickly as we've already put out rc1). Sounds good! Thanks again for your input @AaronBallman ! https://github.com/llvm/llvm-project/pull/101336 is setup to turn on the check by default. https://github.com/llvm/llvm-project/pull/99888 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [AIX] Turn on `#pragma mc_func` check by default (PR #101336)
https://github.com/qiongsiwu updated https://github.com/llvm/llvm-project/pull/101336 >From e823d1e7eb3357fc5c15b614ac5fd94d331ac630 Mon Sep 17 00:00:00 2001 From: Qiongsi Wu Date: Wed, 31 Jul 2024 10:12:59 -0400 Subject: [PATCH 1/2] Turn on mc_func check by default. --- clang/include/clang/Driver/Options.td | 2 +- clang/include/clang/Lex/PreprocessorOptions.h | 4 ++-- clang/lib/Driver/ToolChains/AIX.cpp | 2 +- clang/test/Preprocessor/pragma_mc_func.c | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index c8c56dbb51b28..7f6b8ba4d7eeb 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -8097,7 +8097,7 @@ def source_date_epoch : Separate<["-"], "source-date-epoch">, } // let Visibility = [CC1Option] defm err_pragma_mc_func_aix : BoolFOption<"err-pragma-mc-func-aix", - PreprocessorOpts<"ErrorOnPragmaMcfuncOnAIX">, DefaultFalse, + PreprocessorOpts<"ErrorOnPragmaMcfuncOnAIX">, DefaultTrue, PosFlag, NegFlag&1 | FileCheck %s // RUN: not %clang --target=powerpc64-ibm-aix -ferr-pragma-mc-func-aix -fsyntax-only \ // RUN: %s 2>&1 | FileCheck %s #pragma mc_func asm_barrier {"6000"} @@ -8,11 +9,10 @@ // RUN: %clang --target=powerpc64-ibm-aix -fno-err-pragma-mc-func-aix -fsyntax-only %s // RUN: %clang --target=powerpc64-ibm-aix -ferr-pragma-mc-func-aix -fsyntax-only \ // RUN:-fno-err-pragma-mc-func-aix %s -// RUN: %clang --target=powerpc64-ibm-aix -fsyntax-only %s // RUN: %clang --target=powerpc64-ibm-aix -Werror=unknown-pragmas \ // RUN: -fno-err-pragma-mc-func-aix -fsyntax-only %s -// Cases where we have errors or warnings. +// Cases on a non-AIX target. // RUN: not %clang --target=powerpc64le-unknown-linux-gnu \ // RUN: -Werror=unknown-pragmas -fno-err-pragma-mc-func-aix -fsyntax-only %s 2>&1 | \ // RUN: FileCheck --check-prefix=UNUSED %s >From 16280f9527a02d61789ca310bd4418fb33112ef2 Mon Sep 17 00:00:00 2001 From: Qiongsi Wu Date: Wed, 31 Jul 2024 11:25:07 -0400 Subject: [PATCH 2/2] Remove unnecessary CC1 option. --- clang/include/clang/Driver/Options.td| 2 +- clang/lib/Driver/ToolChains/AIX.cpp | 6 ++ clang/test/Preprocessor/pragma_mc_func.c | 2 ++ 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 7f6b8ba4d7eeb..c155ff8e7003d 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -8098,7 +8098,7 @@ def source_date_epoch : Separate<["-"], "source-date-epoch">, defm err_pragma_mc_func_aix : BoolFOption<"err-pragma-mc-func-aix", PreprocessorOpts<"ErrorOnPragmaMcfuncOnAIX">, DefaultTrue, - PosFlag, NegFlag>; diff --git a/clang/lib/Driver/ToolChains/AIX.cpp b/clang/lib/Driver/ToolChains/AIX.cpp index f0e7acac688fc..aa51c1a8df58c 100644 --- a/clang/lib/Driver/ToolChains/AIX.cpp +++ b/clang/lib/Driver/ToolChains/AIX.cpp @@ -561,10 +561,8 @@ void AIX::addClangTargetOptions( options::OPT_fno_sized_deallocation)) CC1Args.push_back("-fno-sized-deallocation"); - if (Args.hasFlag(options::OPT_ferr_pragma_mc_func_aix, - options::OPT_fno_err_pragma_mc_func_aix, true)) -CC1Args.push_back("-ferr-pragma-mc-func-aix"); - else + if (!Args.hasFlag(options::OPT_ferr_pragma_mc_func_aix, +options::OPT_fno_err_pragma_mc_func_aix, true)) CC1Args.push_back("-fno-err-pragma-mc-func-aix"); } diff --git a/clang/test/Preprocessor/pragma_mc_func.c b/clang/test/Preprocessor/pragma_mc_func.c index 8d172f8490e25..bf12f7107ff5c 100644 --- a/clang/test/Preprocessor/pragma_mc_func.c +++ b/clang/test/Preprocessor/pragma_mc_func.c @@ -1,6 +1,8 @@ // RUN: not %clang --target=powerpc64-ibm-aix -fsyntax-only %s 2>&1 | FileCheck %s // RUN: not %clang --target=powerpc64-ibm-aix -ferr-pragma-mc-func-aix -fsyntax-only \ // RUN: %s 2>&1 | FileCheck %s +// RUN: not %clang --target=powerpc64-ibm-aix -fno-err-pragma-mc-func-aix \ +// RUN: -ferr-pragma-mc-func-aix -fsyntax-only %s 2>&1 | FileCheck %s #pragma mc_func asm_barrier {"6000"} // CHECK: error: #pragma mc_func is not supported ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [AIX] Turn on `#pragma mc_func` check by default (PR #101336)
@@ -562,7 +562,7 @@ void AIX::addClangTargetOptions( CC1Args.push_back("-fno-sized-deallocation"); if (Args.hasFlag(options::OPT_ferr_pragma_mc_func_aix, - options::OPT_fno_err_pragma_mc_func_aix, false)) + options::OPT_fno_err_pragma_mc_func_aix, true)) qiongsiwu wrote: Good point! Code is revised. I tried the suggested change ``` if (Args.hasArg(options::OPT_fno_err_pragma_mc_func_aix)) CC1Args.push_back("-fno-err-pragma-mc-func-aix"); ``` But it does not handle situations like `-fno-err-pragma-mc-func-aix -ferr-pragma-mc-func-aix` correctly. I think we still need to process both flags in the driver, but we only need to pass `-fno-err-pragma-mc-func-aix` to CC1. Did I miss something? https://github.com/llvm/llvm-project/pull/101336 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [AIX] Turn on `#pragma mc_func` check by default (PR #101336)
https://github.com/qiongsiwu edited https://github.com/llvm/llvm-project/pull/101336 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits