[PATCH] D24785: [AVX512] Fix return types on __builtin_ia32_gather3XivXdi builtins
cameron.mcinally created this revision. cameron.mcinally added reviewers: delena, igorb, craig.topper. cameron.mcinally added a subscriber: cfe-commits. cameron.mcinally set the repository for this revision to rL LLVM. The return types on the AVX512 __builtin_ia32_gather3XivXdi builtins are incorrect. The return type should match the type of the pass through vector. The corresponding LLVM diff is D24744. Repository: rL LLVM https://reviews.llvm.org/D24785 Files: include/clang/Basic/BuiltinsX86.def Index: include/clang/Basic/BuiltinsX86.def === --- include/clang/Basic/BuiltinsX86.def +++ include/clang/Basic/BuiltinsX86.def @@ -1037,17 +1037,17 @@ TARGET_BUILTIN(__builtin_ia32_extractf32x4_mask, "V4fV16fIiV4fUc", "", "avx512f") TARGET_BUILTIN(__builtin_ia32_gather3div2df, "V2dV2ddC*V2LLiUci","","avx512vl") -TARGET_BUILTIN(__builtin_ia32_gather3div2di, "V4iV2LLiLLiC*V2LLiUci","","avx512vl") +TARGET_BUILTIN(__builtin_ia32_gather3div2di, "V2LLiV2LLiLLiC*V2LLiUci","","avx512vl") TARGET_BUILTIN(__builtin_ia32_gather3div4df, "V4dV4ddC*V4LLiUci","","avx512vl") -TARGET_BUILTIN(__builtin_ia32_gather3div4di, "V8iV4LLiLLiC*V4LLiUci","","avx512vl") +TARGET_BUILTIN(__builtin_ia32_gather3div4di, "V4LLiV4LLiLLiC*V4LLiUci","","avx512vl") TARGET_BUILTIN(__builtin_ia32_gather3div4sf, "V4fV4ffC*V2LLiUci","","avx512vl") TARGET_BUILTIN(__builtin_ia32_gather3div4si, "V4iV4iiC*V2LLiUci","","avx512vl") TARGET_BUILTIN(__builtin_ia32_gather3div8sf, "V4fV4ffC*V4LLiUci","","avx512vl") TARGET_BUILTIN(__builtin_ia32_gather3div8si, "V4iV4iiC*V4LLiUci","","avx512vl") TARGET_BUILTIN(__builtin_ia32_gather3siv2df, "V2dV2ddC*V4iUci","","avx512vl") -TARGET_BUILTIN(__builtin_ia32_gather3siv2di, "V4iV2LLiLLiC*V4iUci","","avx512vl") +TARGET_BUILTIN(__builtin_ia32_gather3siv2di, "V2LLiV2LLiLLiC*V4iUci","","avx512vl") TARGET_BUILTIN(__builtin_ia32_gather3siv4df, "V4dV4ddC*V4iUci","","avx512vl") -TARGET_BUILTIN(__builtin_ia32_gather3siv4di, "V8iV4LLiLLiC*V4iUci","","avx512vl") +TARGET_BUILTIN(__builtin_ia32_gather3siv4di, "V4LLiV4LLiLLiC*V4iUci","","avx512vl") TARGET_BUILTIN(__builtin_ia32_gather3siv4sf, "V4fV4ffC*V4iUci","","avx512vl") TARGET_BUILTIN(__builtin_ia32_gather3siv4si, "V4iV4iiC*V4iUci","","avx512vl") TARGET_BUILTIN(__builtin_ia32_gather3siv8sf, "V8fV8ffC*V8iUci","","avx512vl") Index: include/clang/Basic/BuiltinsX86.def === --- include/clang/Basic/BuiltinsX86.def +++ include/clang/Basic/BuiltinsX86.def @@ -1037,17 +1037,17 @@ TARGET_BUILTIN(__builtin_ia32_extractf32x4_mask, "V4fV16fIiV4fUc", "", "avx512f") TARGET_BUILTIN(__builtin_ia32_gather3div2df, "V2dV2ddC*V2LLiUci","","avx512vl") -TARGET_BUILTIN(__builtin_ia32_gather3div2di, "V4iV2LLiLLiC*V2LLiUci","","avx512vl") +TARGET_BUILTIN(__builtin_ia32_gather3div2di, "V2LLiV2LLiLLiC*V2LLiUci","","avx512vl") TARGET_BUILTIN(__builtin_ia32_gather3div4df, "V4dV4ddC*V4LLiUci","","avx512vl") -TARGET_BUILTIN(__builtin_ia32_gather3div4di, "V8iV4LLiLLiC*V4LLiUci","","avx512vl") +TARGET_BUILTIN(__builtin_ia32_gather3div4di, "V4LLiV4LLiLLiC*V4LLiUci","","avx512vl") TARGET_BUILTIN(__builtin_ia32_gather3div4sf, "V4fV4ffC*V2LLiUci","","avx512vl") TARGET_BUILTIN(__builtin_ia32_gather3div4si, "V4iV4iiC*V2LLiUci","","avx512vl") TARGET_BUILTIN(__builtin_ia32_gather3div8sf, "V4fV4ffC*V4LLiUci","","avx512vl") TARGET_BUILTIN(__builtin_ia32_gather3div8si, "V4iV4iiC*V4LLiUci","","avx512vl") TARGET_BUILTIN(__builtin_ia32_gather3siv2df, "V2dV2ddC*V4iUci","","avx512vl") -TARGET_BUILTIN(__builtin_ia32_gather3siv2di, "V4iV2LLiLLiC*V4iUci","","avx512vl") +TARGET_BUILTIN(__builtin_ia32_gather3siv2di, "V2LLiV2LLiLLiC*V4iUci","","avx512vl") TARGET_BUILTIN(__builtin_ia32_gather3siv4df, "V4dV4ddC*V4iUci","","avx512vl") -TARGET_BUILTIN(__builtin_ia32_gather3siv4di, "V8iV4LLiLLiC*V4iUci","","avx512vl") +TARGET_BUILTIN(__builtin_ia32_gather3siv4di, "V4LLiV4LLiLLiC*V4iUci","","avx512vl") TARGET_BUILTIN(__builtin_ia32_gather3siv4sf, "V4fV4ffC*V4iUci","","avx512vl") TARGET_BUILTIN(__builtin_ia32_gather3siv4si, "V4iV4iiC*V4iUci","","avx512vl") TARGET_BUILTIN(__builtin_ia32_gather3siv8sf, "V8fV8ffC*V8iUci","","avx512vl") ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r282082 - [AVX512] Fix return types on __builtin_ia32_gather3XivXdi builtins
Author: mcinally Date: Wed Sep 21 11:07:40 2016 New Revision: 282082 URL: http://llvm.org/viewvc/llvm-project?rev=282082&view=rev Log: [AVX512] Fix return types on __builtin_ia32_gather3XivXdi builtins The return types on the AVX512 __builtin_ia32_gather3XivXdi builtins are incorrect. The return type should match the type of the pass through vector. Differential Revision: https://reviews.llvm.org/D24785 -This line, and those below, will be ignored-- Minclude/clang/Basic/BuiltinsX86.def Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86.def?rev=282082&r1=282081&r2=282082&view=diff == --- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original) +++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Wed Sep 21 11:07:40 2016 @@ -1037,17 +1037,17 @@ TARGET_BUILTIN(__builtin_ia32_extractf64 TARGET_BUILTIN(__builtin_ia32_extractf32x4_mask, "V4fV16fIiV4fUc", "", "avx512f") TARGET_BUILTIN(__builtin_ia32_gather3div2df, "V2dV2ddC*V2LLiUci","","avx512vl") -TARGET_BUILTIN(__builtin_ia32_gather3div2di, "V4iV2LLiLLiC*V2LLiUci","","avx512vl") +TARGET_BUILTIN(__builtin_ia32_gather3div2di, "V2LLiV2LLiLLiC*V2LLiUci","","avx512vl") TARGET_BUILTIN(__builtin_ia32_gather3div4df, "V4dV4ddC*V4LLiUci","","avx512vl") -TARGET_BUILTIN(__builtin_ia32_gather3div4di, "V8iV4LLiLLiC*V4LLiUci","","avx512vl") +TARGET_BUILTIN(__builtin_ia32_gather3div4di, "V4LLiV4LLiLLiC*V4LLiUci","","avx512vl") TARGET_BUILTIN(__builtin_ia32_gather3div4sf, "V4fV4ffC*V2LLiUci","","avx512vl") TARGET_BUILTIN(__builtin_ia32_gather3div4si, "V4iV4iiC*V2LLiUci","","avx512vl") TARGET_BUILTIN(__builtin_ia32_gather3div8sf, "V4fV4ffC*V4LLiUci","","avx512vl") TARGET_BUILTIN(__builtin_ia32_gather3div8si, "V4iV4iiC*V4LLiUci","","avx512vl") TARGET_BUILTIN(__builtin_ia32_gather3siv2df, "V2dV2ddC*V4iUci","","avx512vl") -TARGET_BUILTIN(__builtin_ia32_gather3siv2di, "V4iV2LLiLLiC*V4iUci","","avx512vl") +TARGET_BUILTIN(__builtin_ia32_gather3siv2di, "V2LLiV2LLiLLiC*V4iUci","","avx512vl") TARGET_BUILTIN(__builtin_ia32_gather3siv4df, "V4dV4ddC*V4iUci","","avx512vl") -TARGET_BUILTIN(__builtin_ia32_gather3siv4di, "V8iV4LLiLLiC*V4iUci","","avx512vl") +TARGET_BUILTIN(__builtin_ia32_gather3siv4di, "V4LLiV4LLiLLiC*V4iUci","","avx512vl") TARGET_BUILTIN(__builtin_ia32_gather3siv4sf, "V4fV4ffC*V4iUci","","avx512vl") TARGET_BUILTIN(__builtin_ia32_gather3siv4si, "V4iV4iiC*V4iUci","","avx512vl") TARGET_BUILTIN(__builtin_ia32_gather3siv8sf, "V8fV8ffC*V8iUci","","avx512vl") ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D24785: [AVX512] Fix return types on __builtin_ia32_gather3XivXdi builtins
cameron.mcinally closed this revision. cameron.mcinally added a comment. This was fixed with r282082. My cfe-commits email is being held for moderation (not a member of the list), so there was no automatic update. Repository: rL LLVM https://reviews.llvm.org/D24785 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [mlir] [flang] Add support for -mprefer-vector-width= (PR #141380)
https://github.com/mcinally created https://github.com/llvm/llvm-project/pull/141380 This patch adds support for the -mprefer-vector-width= command line option. The parsing of this options is equivalent to Clang's and it is implemented by setting the "prefer-vector-width" function attribute. >From 05221439896aabdcadf79d15ae6875dc34f10edd Mon Sep 17 00:00:00 2001 From: Cameron McInally Date: Sat, 24 May 2025 13:35:13 -0700 Subject: [PATCH] [flang] Add support for -mprefer-vector-width= This patch adds support for the -mprefer-vector-width= command line option. The parsing of this options is equivalent to Clang's and it is implemented by setting the "prefer-vector-width" function attribute. --- clang/include/clang/Driver/Options.td| 2 +- flang/include/flang/Frontend/CodeGenOptions.h| 3 +++ .../include/flang/Optimizer/Transforms/Passes.td | 4 flang/include/flang/Tools/CrossToolHelpers.h | 3 +++ flang/lib/Frontend/CompilerInvocation.cpp| 14 ++ flang/lib/Frontend/FrontendActions.cpp | 2 ++ flang/lib/Optimizer/Passes/Pipelines.cpp | 2 +- flang/lib/Optimizer/Transforms/FunctionAttr.cpp | 5 + flang/test/Driver/prefer-vector-width.f90| 16 mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td | 1 + mlir/lib/Target/LLVMIR/ModuleImport.cpp | 4 mlir/lib/Target/LLVMIR/ModuleTranslation.cpp | 3 +++ 12 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 flang/test/Driver/prefer-vector-width.f90 diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 22261621df092..b0b642796010b 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -5480,7 +5480,7 @@ def mrecip_EQ : CommaJoined<["-"], "mrecip=">, Group, " = ( ['!'] ['vec-'] ('rcp'|'sqrt') [('h'|'s'|'d')] [':'] ) | 'all' | 'default' | 'none'">, MarshallingInfoStringVector>; def mprefer_vector_width_EQ : Joined<["-"], "mprefer-vector-width=">, Group, - Visibility<[ClangOption, CC1Option]>, + Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>, HelpText<"Specifies preferred vector width for auto-vectorization. Defaults to 'none' which allows target specific decisions.">, MarshallingInfoString>; def mstack_protector_guard_EQ : Joined<["-"], "mstack-protector-guard=">, Group, diff --git a/flang/include/flang/Frontend/CodeGenOptions.h b/flang/include/flang/Frontend/CodeGenOptions.h index 2b4e823b3fef4..61e56e51c4bbb 100644 --- a/flang/include/flang/Frontend/CodeGenOptions.h +++ b/flang/include/flang/Frontend/CodeGenOptions.h @@ -53,6 +53,9 @@ class CodeGenOptions : public CodeGenOptionsBase { /// The paths to the pass plugins that were registered using -fpass-plugin. std::vector LLVMPassPlugins; + // The prefered vector width, if requested by -mprefer-vector-width. + std::string PreferVectorWidth; + /// List of filenames passed in using the -fembed-offload-object option. These /// are offloading binaries containing device images and metadata. std::vector OffloadObjects; diff --git a/flang/include/flang/Optimizer/Transforms/Passes.td b/flang/include/flang/Optimizer/Transforms/Passes.td index b251534e1a8f6..2e932d9ad4a26 100644 --- a/flang/include/flang/Optimizer/Transforms/Passes.td +++ b/flang/include/flang/Optimizer/Transforms/Passes.td @@ -418,6 +418,10 @@ def FunctionAttr : Pass<"function-attr", "mlir::func::FuncOp"> { "module.">, Option<"unsafeFPMath", "unsafe-fp-math", "bool", /*default=*/"false", "Set the unsafe-fp-math attribute on functions in the module.">, + Option<"preferVectorWidth", "prefer-vector-width", "std::string", + /*default=*/"", + "Set the prefer-vector-width attribute on functions in the " + "module.">, Option<"tuneCPU", "tune-cpu", "std::string", /*default=*/"", "Set the tune-cpu attribute on functions in the module.">, ]; diff --git a/flang/include/flang/Tools/CrossToolHelpers.h b/flang/include/flang/Tools/CrossToolHelpers.h index 118695bbe2626..058024a4a04c5 100644 --- a/flang/include/flang/Tools/CrossToolHelpers.h +++ b/flang/include/flang/Tools/CrossToolHelpers.h @@ -102,6 +102,7 @@ struct MLIRToLLVMPassPipelineConfig : public FlangEPCallBacks { UnsafeFPMath = mathOpts.getAssociativeMath() && mathOpts.getReciprocalMath() && NoSignedZerosFPMath && ApproxFuncFPMath && mathOpts.getFPContractEnabled(); +PreferVectorWidth = opts.PreferVectorWidth; if (opts.InstrumentFunctions) { InstrumentFunctionEntry = "__cyg_profile_func_enter"; InstrumentFunctionExit = "__cyg_profile_func_exit"; @@ -126,6 +127,8 @@ struct MLIRToLLVMPassPipelineConfig : public FlangEPCallBacks { bool NoSignedZerosFPMath = false; ///< Set no-signed-zeros-fp-math attribute for functions. bool UnsafeFPMath = false; ///< Set u
[clang] [flang] [mlir] [flang] Add support for -mprefer-vector-width= (PR #141380)
mcinally wrote: This is my first patch to Flang, so please be suspicious and gentle. In particular, I am not sure if `FlangOption, FC1Option` were the correct phases to pass this option to or not. https://github.com/llvm/llvm-project/pull/141380 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [mlir] [flang] Add support for -mprefer-vector-width= (PR #141380)
https://github.com/mcinally updated https://github.com/llvm/llvm-project/pull/141380 >From 9f8619cb54a3a11e4c90af7f5156141ddc59e4d4 Mon Sep 17 00:00:00 2001 From: Cameron McInally Date: Sat, 24 May 2025 13:35:13 -0700 Subject: [PATCH] [flang] Add support for -mprefer-vector-width= This patch adds support for the -mprefer-vector-width= command line option. The parsing of this options is equivalent to Clang's and it is implemented by setting the "prefer-vector-width" function attribute. --- clang/include/clang/Driver/Options.td| 2 +- flang/include/flang/Frontend/CodeGenOptions.h| 3 +++ .../include/flang/Optimizer/Transforms/Passes.td | 4 flang/include/flang/Tools/CrossToolHelpers.h | 3 +++ flang/lib/Frontend/CompilerInvocation.cpp| 14 ++ flang/lib/Frontend/FrontendActions.cpp | 2 ++ flang/lib/Optimizer/Passes/Pipelines.cpp | 2 +- flang/lib/Optimizer/Transforms/FunctionAttr.cpp | 5 + flang/test/Driver/prefer-vector-width.f90| 16 mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td | 1 + mlir/lib/Target/LLVMIR/ModuleImport.cpp | 4 mlir/lib/Target/LLVMIR/ModuleTranslation.cpp | 3 +++ 12 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 flang/test/Driver/prefer-vector-width.f90 diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 22261621df092..b0b642796010b 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -5480,7 +5480,7 @@ def mrecip_EQ : CommaJoined<["-"], "mrecip=">, Group, " = ( ['!'] ['vec-'] ('rcp'|'sqrt') [('h'|'s'|'d')] [':'] ) | 'all' | 'default' | 'none'">, MarshallingInfoStringVector>; def mprefer_vector_width_EQ : Joined<["-"], "mprefer-vector-width=">, Group, - Visibility<[ClangOption, CC1Option]>, + Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>, HelpText<"Specifies preferred vector width for auto-vectorization. Defaults to 'none' which allows target specific decisions.">, MarshallingInfoString>; def mstack_protector_guard_EQ : Joined<["-"], "mstack-protector-guard=">, Group, diff --git a/flang/include/flang/Frontend/CodeGenOptions.h b/flang/include/flang/Frontend/CodeGenOptions.h index 2b4e823b3fef4..61e56e51c4bbb 100644 --- a/flang/include/flang/Frontend/CodeGenOptions.h +++ b/flang/include/flang/Frontend/CodeGenOptions.h @@ -53,6 +53,9 @@ class CodeGenOptions : public CodeGenOptionsBase { /// The paths to the pass plugins that were registered using -fpass-plugin. std::vector LLVMPassPlugins; + // The prefered vector width, if requested by -mprefer-vector-width. + std::string PreferVectorWidth; + /// List of filenames passed in using the -fembed-offload-object option. These /// are offloading binaries containing device images and metadata. std::vector OffloadObjects; diff --git a/flang/include/flang/Optimizer/Transforms/Passes.td b/flang/include/flang/Optimizer/Transforms/Passes.td index b251534e1a8f6..2e932d9ad4a26 100644 --- a/flang/include/flang/Optimizer/Transforms/Passes.td +++ b/flang/include/flang/Optimizer/Transforms/Passes.td @@ -418,6 +418,10 @@ def FunctionAttr : Pass<"function-attr", "mlir::func::FuncOp"> { "module.">, Option<"unsafeFPMath", "unsafe-fp-math", "bool", /*default=*/"false", "Set the unsafe-fp-math attribute on functions in the module.">, + Option<"preferVectorWidth", "prefer-vector-width", "std::string", + /*default=*/"", + "Set the prefer-vector-width attribute on functions in the " + "module.">, Option<"tuneCPU", "tune-cpu", "std::string", /*default=*/"", "Set the tune-cpu attribute on functions in the module.">, ]; diff --git a/flang/include/flang/Tools/CrossToolHelpers.h b/flang/include/flang/Tools/CrossToolHelpers.h index 118695bbe2626..058024a4a04c5 100644 --- a/flang/include/flang/Tools/CrossToolHelpers.h +++ b/flang/include/flang/Tools/CrossToolHelpers.h @@ -102,6 +102,7 @@ struct MLIRToLLVMPassPipelineConfig : public FlangEPCallBacks { UnsafeFPMath = mathOpts.getAssociativeMath() && mathOpts.getReciprocalMath() && NoSignedZerosFPMath && ApproxFuncFPMath && mathOpts.getFPContractEnabled(); +PreferVectorWidth = opts.PreferVectorWidth; if (opts.InstrumentFunctions) { InstrumentFunctionEntry = "__cyg_profile_func_enter"; InstrumentFunctionExit = "__cyg_profile_func_exit"; @@ -126,6 +127,8 @@ struct MLIRToLLVMPassPipelineConfig : public FlangEPCallBacks { bool NoSignedZerosFPMath = false; ///< Set no-signed-zeros-fp-math attribute for functions. bool UnsafeFPMath = false; ///< Set unsafe-fp-math attribute for functions. + std::string PreferVectorWidth = ""; ///< Set prefer-vector-width attribute for + ///< functions. bool NSWOnLoopVarInc = true; //
[clang] [flang] [mlir] [flang] Add support for -mprefer-vector-width= (PR #141380)
https://github.com/mcinally updated https://github.com/llvm/llvm-project/pull/141380 >From 9f8619cb54a3a11e4c90af7f5156141ddc59e4d4 Mon Sep 17 00:00:00 2001 From: Cameron McInally Date: Sat, 24 May 2025 13:35:13 -0700 Subject: [PATCH 1/2] [flang] Add support for -mprefer-vector-width= This patch adds support for the -mprefer-vector-width= command line option. The parsing of this options is equivalent to Clang's and it is implemented by setting the "prefer-vector-width" function attribute. --- clang/include/clang/Driver/Options.td| 2 +- flang/include/flang/Frontend/CodeGenOptions.h| 3 +++ .../include/flang/Optimizer/Transforms/Passes.td | 4 flang/include/flang/Tools/CrossToolHelpers.h | 3 +++ flang/lib/Frontend/CompilerInvocation.cpp| 14 ++ flang/lib/Frontend/FrontendActions.cpp | 2 ++ flang/lib/Optimizer/Passes/Pipelines.cpp | 2 +- flang/lib/Optimizer/Transforms/FunctionAttr.cpp | 5 + flang/test/Driver/prefer-vector-width.f90| 16 mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td | 1 + mlir/lib/Target/LLVMIR/ModuleImport.cpp | 4 mlir/lib/Target/LLVMIR/ModuleTranslation.cpp | 3 +++ 12 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 flang/test/Driver/prefer-vector-width.f90 diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 22261621df092..b0b642796010b 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -5480,7 +5480,7 @@ def mrecip_EQ : CommaJoined<["-"], "mrecip=">, Group, " = ( ['!'] ['vec-'] ('rcp'|'sqrt') [('h'|'s'|'d')] [':'] ) | 'all' | 'default' | 'none'">, MarshallingInfoStringVector>; def mprefer_vector_width_EQ : Joined<["-"], "mprefer-vector-width=">, Group, - Visibility<[ClangOption, CC1Option]>, + Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>, HelpText<"Specifies preferred vector width for auto-vectorization. Defaults to 'none' which allows target specific decisions.">, MarshallingInfoString>; def mstack_protector_guard_EQ : Joined<["-"], "mstack-protector-guard=">, Group, diff --git a/flang/include/flang/Frontend/CodeGenOptions.h b/flang/include/flang/Frontend/CodeGenOptions.h index 2b4e823b3fef4..61e56e51c4bbb 100644 --- a/flang/include/flang/Frontend/CodeGenOptions.h +++ b/flang/include/flang/Frontend/CodeGenOptions.h @@ -53,6 +53,9 @@ class CodeGenOptions : public CodeGenOptionsBase { /// The paths to the pass plugins that were registered using -fpass-plugin. std::vector LLVMPassPlugins; + // The prefered vector width, if requested by -mprefer-vector-width. + std::string PreferVectorWidth; + /// List of filenames passed in using the -fembed-offload-object option. These /// are offloading binaries containing device images and metadata. std::vector OffloadObjects; diff --git a/flang/include/flang/Optimizer/Transforms/Passes.td b/flang/include/flang/Optimizer/Transforms/Passes.td index b251534e1a8f6..2e932d9ad4a26 100644 --- a/flang/include/flang/Optimizer/Transforms/Passes.td +++ b/flang/include/flang/Optimizer/Transforms/Passes.td @@ -418,6 +418,10 @@ def FunctionAttr : Pass<"function-attr", "mlir::func::FuncOp"> { "module.">, Option<"unsafeFPMath", "unsafe-fp-math", "bool", /*default=*/"false", "Set the unsafe-fp-math attribute on functions in the module.">, + Option<"preferVectorWidth", "prefer-vector-width", "std::string", + /*default=*/"", + "Set the prefer-vector-width attribute on functions in the " + "module.">, Option<"tuneCPU", "tune-cpu", "std::string", /*default=*/"", "Set the tune-cpu attribute on functions in the module.">, ]; diff --git a/flang/include/flang/Tools/CrossToolHelpers.h b/flang/include/flang/Tools/CrossToolHelpers.h index 118695bbe2626..058024a4a04c5 100644 --- a/flang/include/flang/Tools/CrossToolHelpers.h +++ b/flang/include/flang/Tools/CrossToolHelpers.h @@ -102,6 +102,7 @@ struct MLIRToLLVMPassPipelineConfig : public FlangEPCallBacks { UnsafeFPMath = mathOpts.getAssociativeMath() && mathOpts.getReciprocalMath() && NoSignedZerosFPMath && ApproxFuncFPMath && mathOpts.getFPContractEnabled(); +PreferVectorWidth = opts.PreferVectorWidth; if (opts.InstrumentFunctions) { InstrumentFunctionEntry = "__cyg_profile_func_enter"; InstrumentFunctionExit = "__cyg_profile_func_exit"; @@ -126,6 +127,8 @@ struct MLIRToLLVMPassPipelineConfig : public FlangEPCallBacks { bool NoSignedZerosFPMath = false; ///< Set no-signed-zeros-fp-math attribute for functions. bool UnsafeFPMath = false; ///< Set unsafe-fp-math attribute for functions. + std::string PreferVectorWidth = ""; ///< Set prefer-vector-width attribute for + ///< functions. bool NSWOnLoopVarInc = true
[clang] [flang] [mlir] [flang] Add support for -mprefer-vector-width= (PR #141380)
@@ -2636,6 +2636,10 @@ void ModuleImport::processFunctionAttributes(llvm::Function *func, funcOp.setTargetFeaturesAttr( LLVM::TargetFeaturesAttr::get(context, attr.getValueAsString())); + if (llvm::Attribute attr = func->getFnAttribute("prefer-vector-width"); + attr.isStringAttribute()) +funcOp.setPreferVectorWidth(attr.getValueAsString()); mcinally wrote: Added tests and updated formatting. 👍 👍 https://github.com/llvm/llvm-project/pull/141380 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [mlir] [flang] Add support for -mprefer-vector-width= (PR #142073)
mcinally wrote: Thanks, @tarunprabhu! https://github.com/llvm/llvm-project/pull/142073 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [mlir] [flang] Add support for -mrecip[=] (PR #142172)
https://github.com/mcinally created https://github.com/llvm/llvm-project/pull/142172 This patch adds support for the -mrecip command line option. The parsing of this options is equivalent to Clang's and it is implemented by setting the "reciprocal-estimates" function attribute. >From e7c60252b02109d3f0e05cef7ecc7fbc4f1de197 Mon Sep 17 00:00:00 2001 From: Cameron McInally Date: Fri, 30 May 2025 08:31:31 -0700 Subject: [PATCH] [flang] Add support for -mrecip[=] This patch adds support for the -mrecip command line option. The parsing of this options is equivalent to Clang's and it is implemented by setting the "reciprocal-estimates" function attribute. --- clang/include/clang/Driver/Options.td | 3 +- flang/include/flang/Frontend/CodeGenOptions.h | 3 + .../flang/Optimizer/Transforms/Passes.td | 3 + flang/include/flang/Tools/CrossToolHelpers.h | 3 + flang/lib/Frontend/CompilerInvocation.cpp | 159 ++ flang/lib/Frontend/FrontendActions.cpp| 2 + flang/lib/Optimizer/Passes/Pipelines.cpp | 3 +- .../lib/Optimizer/Transforms/FunctionAttr.cpp | 4 + flang/test/Driver/mrecip.f90 | 27 +++ mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td | 1 + mlir/lib/Target/LLVMIR/ModuleImport.cpp | 5 + mlir/lib/Target/LLVMIR/ModuleTranslation.cpp | 3 + mlir/test/Target/LLVMIR/Import/mrecip.ll | 9 + mlir/test/Target/LLVMIR/mrecip.mlir | 8 + 14 files changed, 231 insertions(+), 2 deletions(-) create mode 100644 flang/test/Driver/mrecip.f90 create mode 100644 mlir/test/Target/LLVMIR/Import/mrecip.ll create mode 100644 mlir/test/Target/LLVMIR/mrecip.mlir diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 5ca31c253ed8f..291e9ae223805 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -5472,9 +5472,10 @@ def mno_implicit_float : Flag<["-"], "mno-implicit-float">, Group, HelpText<"Don't generate implicit floating point or vector instructions">; def mimplicit_float : Flag<["-"], "mimplicit-float">, Group; def mrecip : Flag<["-"], "mrecip">, Group, + Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>, HelpText<"Equivalent to '-mrecip=all'">; def mrecip_EQ : CommaJoined<["-"], "mrecip=">, Group, - Visibility<[ClangOption, CC1Option]>, + Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>, HelpText<"Control use of approximate reciprocal and reciprocal square root instructions followed by iterations of " "Newton-Raphson refinement. " " = ( ['!'] ['vec-'] ('rcp'|'sqrt') [('h'|'s'|'d')] [':'] ) | 'all' | 'default' | 'none'">, diff --git a/flang/include/flang/Frontend/CodeGenOptions.h b/flang/include/flang/Frontend/CodeGenOptions.h index 61e56e51c4bbb..5c1f7ef52ca14 100644 --- a/flang/include/flang/Frontend/CodeGenOptions.h +++ b/flang/include/flang/Frontend/CodeGenOptions.h @@ -56,6 +56,9 @@ class CodeGenOptions : public CodeGenOptionsBase { // The prefered vector width, if requested by -mprefer-vector-width. std::string PreferVectorWidth; + // List of reciprocal estimate sub-options. + std::string Reciprocals; + /// List of filenames passed in using the -fembed-offload-object option. These /// are offloading binaries containing device images and metadata. std::vector OffloadObjects; diff --git a/flang/include/flang/Optimizer/Transforms/Passes.td b/flang/include/flang/Optimizer/Transforms/Passes.td index 1b1970412676d..34842f9785942 100644 --- a/flang/include/flang/Optimizer/Transforms/Passes.td +++ b/flang/include/flang/Optimizer/Transforms/Passes.td @@ -429,6 +429,9 @@ def FunctionAttr : Pass<"function-attr", "mlir::func::FuncOp"> { "module.">, Option<"unsafeFPMath", "unsafe-fp-math", "bool", /*default=*/"false", "Set the unsafe-fp-math attribute on functions in the module.">, + Option<"reciprocals", "mrecip", "std::string", /*default=*/"", + "Set the reciprocal-estimates attribute on functions in the " + "module.">, Option<"preferVectorWidth", "prefer-vector-width", "std::string", /*default=*/"", "Set the prefer-vector-width attribute on functions in the " diff --git a/flang/include/flang/Tools/CrossToolHelpers.h b/flang/include/flang/Tools/CrossToolHelpers.h index 058024a4a04c5..337685c82af5f 100644 --- a/flang/include/flang/Tools/CrossToolHelpers.h +++ b/flang/include/flang/Tools/CrossToolHelpers.h @@ -102,6 +102,7 @@ struct MLIRToLLVMPassPipelineConfig : public FlangEPCallBacks { UnsafeFPMath = mathOpts.getAssociativeMath() && mathOpts.getReciprocalMath() && NoSignedZerosFPMath && ApproxFuncFPMath && mathOpts.getFPContractEnabled(); +Reciprocals = opts.Reciprocals; PreferVectorWidth = opts.PreferVectorWidth; if (opts.InstrumentFunctions) { InstrumentFunctionEntry = "__cyg_profile_func_
[clang] [flang] [mlir] [flang] Add support for -mprefer-vector-width= (PR #141380)
https://github.com/mcinally updated https://github.com/llvm/llvm-project/pull/141380 >From 9f8619cb54a3a11e4c90af7f5156141ddc59e4d4 Mon Sep 17 00:00:00 2001 From: Cameron McInally Date: Sat, 24 May 2025 13:35:13 -0700 Subject: [PATCH 1/3] [flang] Add support for -mprefer-vector-width= This patch adds support for the -mprefer-vector-width= command line option. The parsing of this options is equivalent to Clang's and it is implemented by setting the "prefer-vector-width" function attribute. --- clang/include/clang/Driver/Options.td| 2 +- flang/include/flang/Frontend/CodeGenOptions.h| 3 +++ .../include/flang/Optimizer/Transforms/Passes.td | 4 flang/include/flang/Tools/CrossToolHelpers.h | 3 +++ flang/lib/Frontend/CompilerInvocation.cpp| 14 ++ flang/lib/Frontend/FrontendActions.cpp | 2 ++ flang/lib/Optimizer/Passes/Pipelines.cpp | 2 +- flang/lib/Optimizer/Transforms/FunctionAttr.cpp | 5 + flang/test/Driver/prefer-vector-width.f90| 16 mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td | 1 + mlir/lib/Target/LLVMIR/ModuleImport.cpp | 4 mlir/lib/Target/LLVMIR/ModuleTranslation.cpp | 3 +++ 12 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 flang/test/Driver/prefer-vector-width.f90 diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 22261621df092..b0b642796010b 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -5480,7 +5480,7 @@ def mrecip_EQ : CommaJoined<["-"], "mrecip=">, Group, " = ( ['!'] ['vec-'] ('rcp'|'sqrt') [('h'|'s'|'d')] [':'] ) | 'all' | 'default' | 'none'">, MarshallingInfoStringVector>; def mprefer_vector_width_EQ : Joined<["-"], "mprefer-vector-width=">, Group, - Visibility<[ClangOption, CC1Option]>, + Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>, HelpText<"Specifies preferred vector width for auto-vectorization. Defaults to 'none' which allows target specific decisions.">, MarshallingInfoString>; def mstack_protector_guard_EQ : Joined<["-"], "mstack-protector-guard=">, Group, diff --git a/flang/include/flang/Frontend/CodeGenOptions.h b/flang/include/flang/Frontend/CodeGenOptions.h index 2b4e823b3fef4..61e56e51c4bbb 100644 --- a/flang/include/flang/Frontend/CodeGenOptions.h +++ b/flang/include/flang/Frontend/CodeGenOptions.h @@ -53,6 +53,9 @@ class CodeGenOptions : public CodeGenOptionsBase { /// The paths to the pass plugins that were registered using -fpass-plugin. std::vector LLVMPassPlugins; + // The prefered vector width, if requested by -mprefer-vector-width. + std::string PreferVectorWidth; + /// List of filenames passed in using the -fembed-offload-object option. These /// are offloading binaries containing device images and metadata. std::vector OffloadObjects; diff --git a/flang/include/flang/Optimizer/Transforms/Passes.td b/flang/include/flang/Optimizer/Transforms/Passes.td index b251534e1a8f6..2e932d9ad4a26 100644 --- a/flang/include/flang/Optimizer/Transforms/Passes.td +++ b/flang/include/flang/Optimizer/Transforms/Passes.td @@ -418,6 +418,10 @@ def FunctionAttr : Pass<"function-attr", "mlir::func::FuncOp"> { "module.">, Option<"unsafeFPMath", "unsafe-fp-math", "bool", /*default=*/"false", "Set the unsafe-fp-math attribute on functions in the module.">, + Option<"preferVectorWidth", "prefer-vector-width", "std::string", + /*default=*/"", + "Set the prefer-vector-width attribute on functions in the " + "module.">, Option<"tuneCPU", "tune-cpu", "std::string", /*default=*/"", "Set the tune-cpu attribute on functions in the module.">, ]; diff --git a/flang/include/flang/Tools/CrossToolHelpers.h b/flang/include/flang/Tools/CrossToolHelpers.h index 118695bbe2626..058024a4a04c5 100644 --- a/flang/include/flang/Tools/CrossToolHelpers.h +++ b/flang/include/flang/Tools/CrossToolHelpers.h @@ -102,6 +102,7 @@ struct MLIRToLLVMPassPipelineConfig : public FlangEPCallBacks { UnsafeFPMath = mathOpts.getAssociativeMath() && mathOpts.getReciprocalMath() && NoSignedZerosFPMath && ApproxFuncFPMath && mathOpts.getFPContractEnabled(); +PreferVectorWidth = opts.PreferVectorWidth; if (opts.InstrumentFunctions) { InstrumentFunctionEntry = "__cyg_profile_func_enter"; InstrumentFunctionExit = "__cyg_profile_func_exit"; @@ -126,6 +127,8 @@ struct MLIRToLLVMPassPipelineConfig : public FlangEPCallBacks { bool NoSignedZerosFPMath = false; ///< Set no-signed-zeros-fp-math attribute for functions. bool UnsafeFPMath = false; ///< Set unsafe-fp-math attribute for functions. + std::string PreferVectorWidth = ""; ///< Set prefer-vector-width attribute for + ///< functions. bool NSWOnLoopVarInc = true
[clang] [flang] [mlir] [flang] Add support for -mprefer-vector-width= (PR #141380)
@@ -0,0 +1,9 @@ +; RUN: mlir-translate -import-llvm -split-input-file %s | FileCheck %s + +; CHECK-LABEL: llvm.func @prefer_vector_width() +; CHECK: prefer_vector_width = "128" mcinally wrote: It does continue where the last match ended, but no problem to update. I figured since this was a one function test, there was no risk of matching another line. Just uploaded an updated patch... https://github.com/llvm/llvm-project/pull/141380 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [mlir] [flang] Add support for -mprefer-vector-width= (PR #141380)
https://github.com/mcinally updated https://github.com/llvm/llvm-project/pull/141380 >From 9f8619cb54a3a11e4c90af7f5156141ddc59e4d4 Mon Sep 17 00:00:00 2001 From: Cameron McInally Date: Sat, 24 May 2025 13:35:13 -0700 Subject: [PATCH 1/3] [flang] Add support for -mprefer-vector-width= This patch adds support for the -mprefer-vector-width= command line option. The parsing of this options is equivalent to Clang's and it is implemented by setting the "prefer-vector-width" function attribute. --- clang/include/clang/Driver/Options.td| 2 +- flang/include/flang/Frontend/CodeGenOptions.h| 3 +++ .../include/flang/Optimizer/Transforms/Passes.td | 4 flang/include/flang/Tools/CrossToolHelpers.h | 3 +++ flang/lib/Frontend/CompilerInvocation.cpp| 14 ++ flang/lib/Frontend/FrontendActions.cpp | 2 ++ flang/lib/Optimizer/Passes/Pipelines.cpp | 2 +- flang/lib/Optimizer/Transforms/FunctionAttr.cpp | 5 + flang/test/Driver/prefer-vector-width.f90| 16 mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td | 1 + mlir/lib/Target/LLVMIR/ModuleImport.cpp | 4 mlir/lib/Target/LLVMIR/ModuleTranslation.cpp | 3 +++ 12 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 flang/test/Driver/prefer-vector-width.f90 diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 22261621df092..b0b642796010b 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -5480,7 +5480,7 @@ def mrecip_EQ : CommaJoined<["-"], "mrecip=">, Group, " = ( ['!'] ['vec-'] ('rcp'|'sqrt') [('h'|'s'|'d')] [':'] ) | 'all' | 'default' | 'none'">, MarshallingInfoStringVector>; def mprefer_vector_width_EQ : Joined<["-"], "mprefer-vector-width=">, Group, - Visibility<[ClangOption, CC1Option]>, + Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>, HelpText<"Specifies preferred vector width for auto-vectorization. Defaults to 'none' which allows target specific decisions.">, MarshallingInfoString>; def mstack_protector_guard_EQ : Joined<["-"], "mstack-protector-guard=">, Group, diff --git a/flang/include/flang/Frontend/CodeGenOptions.h b/flang/include/flang/Frontend/CodeGenOptions.h index 2b4e823b3fef4..61e56e51c4bbb 100644 --- a/flang/include/flang/Frontend/CodeGenOptions.h +++ b/flang/include/flang/Frontend/CodeGenOptions.h @@ -53,6 +53,9 @@ class CodeGenOptions : public CodeGenOptionsBase { /// The paths to the pass plugins that were registered using -fpass-plugin. std::vector LLVMPassPlugins; + // The prefered vector width, if requested by -mprefer-vector-width. + std::string PreferVectorWidth; + /// List of filenames passed in using the -fembed-offload-object option. These /// are offloading binaries containing device images and metadata. std::vector OffloadObjects; diff --git a/flang/include/flang/Optimizer/Transforms/Passes.td b/flang/include/flang/Optimizer/Transforms/Passes.td index b251534e1a8f6..2e932d9ad4a26 100644 --- a/flang/include/flang/Optimizer/Transforms/Passes.td +++ b/flang/include/flang/Optimizer/Transforms/Passes.td @@ -418,6 +418,10 @@ def FunctionAttr : Pass<"function-attr", "mlir::func::FuncOp"> { "module.">, Option<"unsafeFPMath", "unsafe-fp-math", "bool", /*default=*/"false", "Set the unsafe-fp-math attribute on functions in the module.">, + Option<"preferVectorWidth", "prefer-vector-width", "std::string", + /*default=*/"", + "Set the prefer-vector-width attribute on functions in the " + "module.">, Option<"tuneCPU", "tune-cpu", "std::string", /*default=*/"", "Set the tune-cpu attribute on functions in the module.">, ]; diff --git a/flang/include/flang/Tools/CrossToolHelpers.h b/flang/include/flang/Tools/CrossToolHelpers.h index 118695bbe2626..058024a4a04c5 100644 --- a/flang/include/flang/Tools/CrossToolHelpers.h +++ b/flang/include/flang/Tools/CrossToolHelpers.h @@ -102,6 +102,7 @@ struct MLIRToLLVMPassPipelineConfig : public FlangEPCallBacks { UnsafeFPMath = mathOpts.getAssociativeMath() && mathOpts.getReciprocalMath() && NoSignedZerosFPMath && ApproxFuncFPMath && mathOpts.getFPContractEnabled(); +PreferVectorWidth = opts.PreferVectorWidth; if (opts.InstrumentFunctions) { InstrumentFunctionEntry = "__cyg_profile_func_enter"; InstrumentFunctionExit = "__cyg_profile_func_exit"; @@ -126,6 +127,8 @@ struct MLIRToLLVMPassPipelineConfig : public FlangEPCallBacks { bool NoSignedZerosFPMath = false; ///< Set no-signed-zeros-fp-math attribute for functions. bool UnsafeFPMath = false; ///< Set unsafe-fp-math attribute for functions. + std::string PreferVectorWidth = ""; ///< Set prefer-vector-width attribute for + ///< functions. bool NSWOnLoopVarInc = true
[clang] [flang] [mlir] [flang] Add support for -mprefer-vector-width= (PR #141380)
mcinally wrote: @tarunprabhu Would you mind mashing the "Merge" button? It looks like getting commit access approval is taking longer than expected. https://github.com/llvm/llvm-project/pull/141380 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [mlir] [flang] Add support for -mprefer-vector-width= (PR #141380)
mcinally wrote: Seems ok now: "Changes can be cleanly merged." If it's still not available, I may have messed something up on my side. I'll review the GitHub docs to see if I missed something... https://github.com/llvm/llvm-project/pull/141380 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [mlir] [flang] Add support for -mprefer-vector-width= (PR #141380)
@@ -126,6 +127,8 @@ struct MLIRToLLVMPassPipelineConfig : public FlangEPCallBacks { bool NoSignedZerosFPMath = false; ///< Set no-signed-zeros-fp-math attribute for functions. bool UnsafeFPMath = false; ///< Set unsafe-fp-math attribute for functions. + std::string PreferVectorWidth = ""; ///< Set prefer-vector-width attribute for mcinally wrote: If there are no objections, I'll leave this. The other std::string's in the function are initialized the same way, so probably best to stay in that style. https://github.com/llvm/llvm-project/pull/141380 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [mlir] [flang] Add support for -mprefer-vector-width= (PR #141380)
https://github.com/mcinally updated https://github.com/llvm/llvm-project/pull/141380 >From 9f8619cb54a3a11e4c90af7f5156141ddc59e4d4 Mon Sep 17 00:00:00 2001 From: Cameron McInally Date: Sat, 24 May 2025 13:35:13 -0700 Subject: [PATCH 1/3] [flang] Add support for -mprefer-vector-width= This patch adds support for the -mprefer-vector-width= command line option. The parsing of this options is equivalent to Clang's and it is implemented by setting the "prefer-vector-width" function attribute. --- clang/include/clang/Driver/Options.td| 2 +- flang/include/flang/Frontend/CodeGenOptions.h| 3 +++ .../include/flang/Optimizer/Transforms/Passes.td | 4 flang/include/flang/Tools/CrossToolHelpers.h | 3 +++ flang/lib/Frontend/CompilerInvocation.cpp| 14 ++ flang/lib/Frontend/FrontendActions.cpp | 2 ++ flang/lib/Optimizer/Passes/Pipelines.cpp | 2 +- flang/lib/Optimizer/Transforms/FunctionAttr.cpp | 5 + flang/test/Driver/prefer-vector-width.f90| 16 mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td | 1 + mlir/lib/Target/LLVMIR/ModuleImport.cpp | 4 mlir/lib/Target/LLVMIR/ModuleTranslation.cpp | 3 +++ 12 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 flang/test/Driver/prefer-vector-width.f90 diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 22261621df092..b0b642796010b 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -5480,7 +5480,7 @@ def mrecip_EQ : CommaJoined<["-"], "mrecip=">, Group, " = ( ['!'] ['vec-'] ('rcp'|'sqrt') [('h'|'s'|'d')] [':'] ) | 'all' | 'default' | 'none'">, MarshallingInfoStringVector>; def mprefer_vector_width_EQ : Joined<["-"], "mprefer-vector-width=">, Group, - Visibility<[ClangOption, CC1Option]>, + Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>, HelpText<"Specifies preferred vector width for auto-vectorization. Defaults to 'none' which allows target specific decisions.">, MarshallingInfoString>; def mstack_protector_guard_EQ : Joined<["-"], "mstack-protector-guard=">, Group, diff --git a/flang/include/flang/Frontend/CodeGenOptions.h b/flang/include/flang/Frontend/CodeGenOptions.h index 2b4e823b3fef4..61e56e51c4bbb 100644 --- a/flang/include/flang/Frontend/CodeGenOptions.h +++ b/flang/include/flang/Frontend/CodeGenOptions.h @@ -53,6 +53,9 @@ class CodeGenOptions : public CodeGenOptionsBase { /// The paths to the pass plugins that were registered using -fpass-plugin. std::vector LLVMPassPlugins; + // The prefered vector width, if requested by -mprefer-vector-width. + std::string PreferVectorWidth; + /// List of filenames passed in using the -fembed-offload-object option. These /// are offloading binaries containing device images and metadata. std::vector OffloadObjects; diff --git a/flang/include/flang/Optimizer/Transforms/Passes.td b/flang/include/flang/Optimizer/Transforms/Passes.td index b251534e1a8f6..2e932d9ad4a26 100644 --- a/flang/include/flang/Optimizer/Transforms/Passes.td +++ b/flang/include/flang/Optimizer/Transforms/Passes.td @@ -418,6 +418,10 @@ def FunctionAttr : Pass<"function-attr", "mlir::func::FuncOp"> { "module.">, Option<"unsafeFPMath", "unsafe-fp-math", "bool", /*default=*/"false", "Set the unsafe-fp-math attribute on functions in the module.">, + Option<"preferVectorWidth", "prefer-vector-width", "std::string", + /*default=*/"", + "Set the prefer-vector-width attribute on functions in the " + "module.">, Option<"tuneCPU", "tune-cpu", "std::string", /*default=*/"", "Set the tune-cpu attribute on functions in the module.">, ]; diff --git a/flang/include/flang/Tools/CrossToolHelpers.h b/flang/include/flang/Tools/CrossToolHelpers.h index 118695bbe2626..058024a4a04c5 100644 --- a/flang/include/flang/Tools/CrossToolHelpers.h +++ b/flang/include/flang/Tools/CrossToolHelpers.h @@ -102,6 +102,7 @@ struct MLIRToLLVMPassPipelineConfig : public FlangEPCallBacks { UnsafeFPMath = mathOpts.getAssociativeMath() && mathOpts.getReciprocalMath() && NoSignedZerosFPMath && ApproxFuncFPMath && mathOpts.getFPContractEnabled(); +PreferVectorWidth = opts.PreferVectorWidth; if (opts.InstrumentFunctions) { InstrumentFunctionEntry = "__cyg_profile_func_enter"; InstrumentFunctionExit = "__cyg_profile_func_exit"; @@ -126,6 +127,8 @@ struct MLIRToLLVMPassPipelineConfig : public FlangEPCallBacks { bool NoSignedZerosFPMath = false; ///< Set no-signed-zeros-fp-math attribute for functions. bool UnsafeFPMath = false; ///< Set unsafe-fp-math attribute for functions. + std::string PreferVectorWidth = ""; ///< Set prefer-vector-width attribute for + ///< functions. bool NSWOnLoopVarInc = true
[clang] [flang] [mlir] [flang] Add support for -mprefer-vector-width= (PR #142073)
mcinally wrote: PR #142269 for PPC buildbot fix. https://github.com/llvm/llvm-project/pull/142073 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [mlir] [flang] Add support for -mrecip[=] (PR #142172)
mcinally wrote: > LGTM, though, I think we'd better reuse the code from `Clang.cpp`. > `flangFrontend` already depends on `clangDriver`, so we just need to export > `ParseMRecip` and `getRefinementStep` from `clangDriver` (and probably > replace their `Driver` argument with a `DiagnosticEngine` argument, so that > it works for both clang and flang). This seems reasonable. I'll look into whether it's possible to do. > (and probably replace their `Driver` argument with a `DiagnosticEngine` > argument, so that it works for both clang and flang) It will be interesting to see if Clang allows us to change this without changing it everywhere. Changing it everywhere seems like a heavy lift. https://github.com/llvm/llvm-project/pull/142172 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [Driver] Move CommonArgs to a location visible by the Frontend Drivers (PR #142800)
https://github.com/mcinally created https://github.com/llvm/llvm-project/pull/142800 This patch moves the CommonArgs utilities into a location visible by the Frontend Drivers, so that the Frontend Drivers may share option parsing code with the Compiler Driver. This is useful when the Frontend Drivers would like to verify that their incoming options are well-formed and also not reinvent the option parsing wheel. We already see code in the Clang/Flang Drivers that is parsing and verifying its incoming options. E.g. OPT_ffp_contract. This option is parsed in the Compiler Driver, Clang Driver, and Flang Driver, all with slightly different parsing code. It would be nice if the Frontend Drivers were not required to duplicate this Compiler Driver code. That way there is no/low maintenance burden on keeping all these parsing functions in sync. Along those lines, the Frontend Drivers will now have a useful mechanism to verify their incoming options are well-formed. Currently, the Frontend Drivers trust that the Compiler Driver is not passing back junk in some cases. The Language Drivers may even accept junk with no error at all. E.g.: `clang -cc1 -mprefer-vector-width=junk test.c' With this patch, we'll now be able to tighten up incomming options to the Frontend drivers in a lightweight way. >From 918b853de8c43dacebecb42cafa6d3b8fec15b47 Mon Sep 17 00:00:00 2001 From: Cameron McInally Date: Tue, 3 Jun 2025 11:12:42 -0700 Subject: [PATCH] [Driver] Move CommonArgs to a location visible by the Frontend Drivers This patch moves the CommonArgs utilities into a location visible by the Frontend Drivers, so that the Frontend Drivers may share option parsing code with the Compiler Driver. This is useful when the Frontend Drivers would like to verify that their incoming options are well-formed and also not reinvent the option parsing wheel. We already see code in the Clang/Flang Drivers that is parsing and verifying its incoming options. E.g. OPT_ffp_contract. This option is parsed in the Compiler Driver, Clang Driver, and Flang Driver, all with slightly different parsing code. It would be nice if the Frontend Drivers were not required to duplicate this Compiler Driver code. That way there is no maintenace burden on keeping all these parsing functions in sync. Along those lines, the Frontend Drivers will now have a useful mechanism to verify their incoming options are well-formed. Currently, the Frontend Drivers trust that the Compiler Driver is not passing back junk. In some cases, the Language Drivers will accept junk with no error at all. E.g.: `clang -cc1 -mprefer-vector-width=junk test.c' With this patch, we'll now be able to tighten up incomming options to the Frontend drivers in a lightweight way. --- .../clang/Driver}/CommonArgs.h| 6 clang/lib/Driver/MultilibBuilder.cpp | 2 +- clang/lib/Driver/ToolChain.cpp| 2 +- clang/lib/Driver/ToolChains/AIX.cpp | 2 +- clang/lib/Driver/ToolChains/AMDGPU.cpp| 2 +- clang/lib/Driver/ToolChains/AVR.cpp | 2 +- clang/lib/Driver/ToolChains/Arch/AArch64.cpp | 2 +- .../lib/Driver/ToolChains/Arch/LoongArch.cpp | 2 +- clang/lib/Driver/ToolChains/Arch/Mips.cpp | 2 +- clang/lib/Driver/ToolChains/Arch/PPC.cpp | 2 +- clang/lib/Driver/ToolChains/Arch/RISCV.cpp| 2 +- clang/lib/Driver/ToolChains/BareMetal.cpp | 2 +- clang/lib/Driver/ToolChains/CSKYToolChain.cpp | 2 +- clang/lib/Driver/ToolChains/Clang.cpp | 26 ++--- clang/lib/Driver/ToolChains/CommonArgs.cpp| 29 ++- clang/lib/Driver/ToolChains/CrossWindows.cpp | 2 +- clang/lib/Driver/ToolChains/Cuda.cpp | 2 +- clang/lib/Driver/ToolChains/Cygwin.cpp| 2 +- clang/lib/Driver/ToolChains/Darwin.cpp| 2 +- clang/lib/Driver/ToolChains/DragonFly.cpp | 2 +- clang/lib/Driver/ToolChains/Flang.cpp | 2 +- clang/lib/Driver/ToolChains/FreeBSD.cpp | 2 +- clang/lib/Driver/ToolChains/Fuchsia.cpp | 2 +- clang/lib/Driver/ToolChains/Gnu.cpp | 2 +- clang/lib/Driver/ToolChains/HIPAMD.cpp| 2 +- clang/lib/Driver/ToolChains/HIPSPV.cpp| 2 +- clang/lib/Driver/ToolChains/HIPUtility.cpp| 2 +- clang/lib/Driver/ToolChains/HLSL.cpp | 2 +- clang/lib/Driver/ToolChains/Haiku.cpp | 2 +- clang/lib/Driver/ToolChains/Hexagon.cpp | 2 +- clang/lib/Driver/ToolChains/Hurd.cpp | 2 +- .../lib/Driver/ToolChains/InterfaceStubs.cpp | 2 +- clang/lib/Driver/ToolChains/Linux.cpp | 2 +- clang/lib/Driver/ToolChains/MSP430.cpp| 2 +- clang/lib/Driver/ToolChains/MSVC.cpp | 2 +- clang/lib/Driver/ToolChains/MinGW.cpp | 2 +- clang/lib/Driver/ToolChains/NaCl.cpp | 2 +- clang/lib/Driver/ToolChains/NetBSD.cpp| 2 +- clang/lib/Driver/ToolChains/OHOS.cpp | 2 +- clang/lib/Driver/ToolChains/OpenBSD.cpp |
[clang] [flang] [Driver] Move CommonArgs to a location visible by the Frontend Drivers (PR #142800)
@@ -270,6 +270,12 @@ void handleVectorizeLoopsArgs(const llvm::opt::ArgList &Args, /// Enable -fslp-vectorize based on the optimization level selected. void handleVectorizeSLPArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs); + +void ParseMPreferVectorWidthOption(clang::DiagnosticsEngine &Diags, mcinally wrote: It was, for illustrative purposes. I have no problem removing it though. https://github.com/llvm/llvm-project/pull/142800 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [Driver] Move CommonArgs to a location visible by the Frontend Drivers (PR #142800)
@@ -3167,3 +3167,30 @@ void tools::handleInterchangeLoopsArgs(const ArgList &Args, options::OPT_fno_loop_interchange, EnableInterchange)) CmdArgs.push_back("-floop-interchange"); } + +void tools::ParseMPreferVectorWidthOption(clang::DiagnosticsEngine &Diags, + const llvm::opt::ArgList &Args, + ArgStringList &CmdArgs, + bool isCompilerDriver) { + // If this was invoked by the Compiler Driver, we pass through the option + // as-is. Otherwise, if this is the Frontend Driver, we want just the value. + StringRef Out = (isCompilerDriver) ? "-mprefer-vector-width=" : ""; + + Arg *A = Args.getLastArg(clang::driver::options::OPT_mprefer_vector_width_EQ); + if (!A) +return; + + StringRef Value = A->getValue(); + unsigned Width; + + // Only "none" and Integer values are accepted by + // -mprefer-vector-width=. + if (Value != "none" && Value.getAsInteger(10, Width)) { +Diags.Report(clang::diag::err_drv_invalid_value) +<< A->getOption().getName() << Value; +return; + } + + CmdArgs.push_back(Args.MakeArgString(Out + Value)); mcinally wrote: This is awkward. I was hoping someone with more C++ expertise would have a trick to streamline it. I chose this solution so that the Compilation Driver side would be as undisturbed as possible. I also don't feel strongly that it needs to change for an initial implementation. It's something we could build out in the future as we learn more. https://github.com/llvm/llvm-project/pull/142800 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [Driver] Move CommonArgs to a location visible by the Frontend Drivers (PR #142800)
https://github.com/mcinally edited https://github.com/llvm/llvm-project/pull/142800 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [Driver] Move CommonArgs to a location visible by the Frontend Drivers (PR #142800)
https://github.com/mcinally updated https://github.com/llvm/llvm-project/pull/142800 >From 918b853de8c43dacebecb42cafa6d3b8fec15b47 Mon Sep 17 00:00:00 2001 From: Cameron McInally Date: Tue, 3 Jun 2025 11:12:42 -0700 Subject: [PATCH] [Driver] Move CommonArgs to a location visible by the Frontend Drivers This patch moves the CommonArgs utilities into a location visible by the Frontend Drivers, so that the Frontend Drivers may share option parsing code with the Compiler Driver. This is useful when the Frontend Drivers would like to verify that their incoming options are well-formed and also not reinvent the option parsing wheel. We already see code in the Clang/Flang Drivers that is parsing and verifying its incoming options. E.g. OPT_ffp_contract. This option is parsed in the Compiler Driver, Clang Driver, and Flang Driver, all with slightly different parsing code. It would be nice if the Frontend Drivers were not required to duplicate this Compiler Driver code. That way there is no maintenace burden on keeping all these parsing functions in sync. Along those lines, the Frontend Drivers will now have a useful mechanism to verify their incoming options are well-formed. Currently, the Frontend Drivers trust that the Compiler Driver is not passing back junk. In some cases, the Language Drivers will accept junk with no error at all. E.g.: `clang -cc1 -mprefer-vector-width=junk test.c' With this patch, we'll now be able to tighten up incomming options to the Frontend drivers in a lightweight way. --- .../clang/Driver}/CommonArgs.h| 6 clang/lib/Driver/MultilibBuilder.cpp | 2 +- clang/lib/Driver/ToolChain.cpp| 2 +- clang/lib/Driver/ToolChains/AIX.cpp | 2 +- clang/lib/Driver/ToolChains/AMDGPU.cpp| 2 +- clang/lib/Driver/ToolChains/AVR.cpp | 2 +- clang/lib/Driver/ToolChains/Arch/AArch64.cpp | 2 +- .../lib/Driver/ToolChains/Arch/LoongArch.cpp | 2 +- clang/lib/Driver/ToolChains/Arch/Mips.cpp | 2 +- clang/lib/Driver/ToolChains/Arch/PPC.cpp | 2 +- clang/lib/Driver/ToolChains/Arch/RISCV.cpp| 2 +- clang/lib/Driver/ToolChains/BareMetal.cpp | 2 +- clang/lib/Driver/ToolChains/CSKYToolChain.cpp | 2 +- clang/lib/Driver/ToolChains/Clang.cpp | 26 ++--- clang/lib/Driver/ToolChains/CommonArgs.cpp| 29 ++- clang/lib/Driver/ToolChains/CrossWindows.cpp | 2 +- clang/lib/Driver/ToolChains/Cuda.cpp | 2 +- clang/lib/Driver/ToolChains/Cygwin.cpp| 2 +- clang/lib/Driver/ToolChains/Darwin.cpp| 2 +- clang/lib/Driver/ToolChains/DragonFly.cpp | 2 +- clang/lib/Driver/ToolChains/Flang.cpp | 2 +- clang/lib/Driver/ToolChains/FreeBSD.cpp | 2 +- clang/lib/Driver/ToolChains/Fuchsia.cpp | 2 +- clang/lib/Driver/ToolChains/Gnu.cpp | 2 +- clang/lib/Driver/ToolChains/HIPAMD.cpp| 2 +- clang/lib/Driver/ToolChains/HIPSPV.cpp| 2 +- clang/lib/Driver/ToolChains/HIPUtility.cpp| 2 +- clang/lib/Driver/ToolChains/HLSL.cpp | 2 +- clang/lib/Driver/ToolChains/Haiku.cpp | 2 +- clang/lib/Driver/ToolChains/Hexagon.cpp | 2 +- clang/lib/Driver/ToolChains/Hurd.cpp | 2 +- .../lib/Driver/ToolChains/InterfaceStubs.cpp | 2 +- clang/lib/Driver/ToolChains/Linux.cpp | 2 +- clang/lib/Driver/ToolChains/MSP430.cpp| 2 +- clang/lib/Driver/ToolChains/MSVC.cpp | 2 +- clang/lib/Driver/ToolChains/MinGW.cpp | 2 +- clang/lib/Driver/ToolChains/NaCl.cpp | 2 +- clang/lib/Driver/ToolChains/NetBSD.cpp| 2 +- clang/lib/Driver/ToolChains/OHOS.cpp | 2 +- clang/lib/Driver/ToolChains/OpenBSD.cpp | 2 +- clang/lib/Driver/ToolChains/PS4CPU.cpp| 2 +- .../lib/Driver/ToolChains/RISCVToolchain.cpp | 2 +- clang/lib/Driver/ToolChains/SPIRV.cpp | 2 +- clang/lib/Driver/ToolChains/SPIRVOpenMP.cpp | 2 +- clang/lib/Driver/ToolChains/SYCL.cpp | 2 +- clang/lib/Driver/ToolChains/Solaris.cpp | 2 +- clang/lib/Driver/ToolChains/UEFI.cpp | 2 +- clang/lib/Driver/ToolChains/VEToolchain.cpp | 2 +- clang/lib/Driver/ToolChains/WebAssembly.cpp | 2 +- clang/lib/Driver/ToolChains/XCore.cpp | 2 +- clang/lib/Driver/ToolChains/ZOS.cpp | 2 +- clang/lib/Driver/XRayArgs.cpp | 2 +- .../unittests/Driver/MultilibBuilderTest.cpp | 2 +- clang/unittests/Driver/MultilibTest.cpp | 2 +- flang/lib/Frontend/CompilerInvocation.cpp | 20 + flang/test/Driver/prefer-vector-width.f90 | 2 +- 56 files changed, 96 insertions(+), 89 deletions(-) rename clang/{lib/Driver/ToolChains => include/clang/Driver}/CommonArgs.h (98%) diff --git a/clang/lib/Driver/ToolChains/CommonArgs.h b/clang/include/clang/Driver/CommonArgs.h similarity index 98% rename from clang/lib/Driver/ToolChains/CommonArgs.h rename to clang/include/clang/Driver
[clang] [flang] [Driver] Move CommonArgs to a location visible by the Frontend Drivers (PR #142800)
@@ -3167,3 +3167,30 @@ void tools::handleInterchangeLoopsArgs(const ArgList &Args, options::OPT_fno_loop_interchange, EnableInterchange)) CmdArgs.push_back("-floop-interchange"); } + +void tools::ParseMPreferVectorWidthOption(clang::DiagnosticsEngine &Diags, + const llvm::opt::ArgList &Args, + ArgStringList &CmdArgs, + bool isCompilerDriver) { + // If this was invoked by the Compiler Driver, we pass through the option + // as-is. Otherwise, if this is the Frontend Driver, we want just the value. + StringRef Out = (isCompilerDriver) ? "-mprefer-vector-width=" : ""; + + Arg *A = Args.getLastArg(clang::driver::options::OPT_mprefer_vector_width_EQ); + if (!A) +return; + + StringRef Value = A->getValue(); + unsigned Width; + + // Only "none" and Integer values are accepted by + // -mprefer-vector-width=. + if (Value != "none" && Value.getAsInteger(10, Width)) { +Diags.Report(clang::diag::err_drv_invalid_value) +<< A->getOption().getName() << Value; +return; + } + + CmdArgs.push_back(Args.MakeArgString(Out + Value)); mcinally wrote: Actually, I take that back. This solution is pretty slick. Sharing an update now... https://github.com/llvm/llvm-project/pull/142800 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [Driver] Move CommonArgs to a location visible by the Frontend Drivers (PR #142800)
https://github.com/mcinally updated https://github.com/llvm/llvm-project/pull/142800 >From 918b853de8c43dacebecb42cafa6d3b8fec15b47 Mon Sep 17 00:00:00 2001 From: Cameron McInally Date: Tue, 3 Jun 2025 11:12:42 -0700 Subject: [PATCH 1/3] [Driver] Move CommonArgs to a location visible by the Frontend Drivers This patch moves the CommonArgs utilities into a location visible by the Frontend Drivers, so that the Frontend Drivers may share option parsing code with the Compiler Driver. This is useful when the Frontend Drivers would like to verify that their incoming options are well-formed and also not reinvent the option parsing wheel. We already see code in the Clang/Flang Drivers that is parsing and verifying its incoming options. E.g. OPT_ffp_contract. This option is parsed in the Compiler Driver, Clang Driver, and Flang Driver, all with slightly different parsing code. It would be nice if the Frontend Drivers were not required to duplicate this Compiler Driver code. That way there is no maintenace burden on keeping all these parsing functions in sync. Along those lines, the Frontend Drivers will now have a useful mechanism to verify their incoming options are well-formed. Currently, the Frontend Drivers trust that the Compiler Driver is not passing back junk. In some cases, the Language Drivers will accept junk with no error at all. E.g.: `clang -cc1 -mprefer-vector-width=junk test.c' With this patch, we'll now be able to tighten up incomming options to the Frontend drivers in a lightweight way. --- .../clang/Driver}/CommonArgs.h| 6 clang/lib/Driver/MultilibBuilder.cpp | 2 +- clang/lib/Driver/ToolChain.cpp| 2 +- clang/lib/Driver/ToolChains/AIX.cpp | 2 +- clang/lib/Driver/ToolChains/AMDGPU.cpp| 2 +- clang/lib/Driver/ToolChains/AVR.cpp | 2 +- clang/lib/Driver/ToolChains/Arch/AArch64.cpp | 2 +- .../lib/Driver/ToolChains/Arch/LoongArch.cpp | 2 +- clang/lib/Driver/ToolChains/Arch/Mips.cpp | 2 +- clang/lib/Driver/ToolChains/Arch/PPC.cpp | 2 +- clang/lib/Driver/ToolChains/Arch/RISCV.cpp| 2 +- clang/lib/Driver/ToolChains/BareMetal.cpp | 2 +- clang/lib/Driver/ToolChains/CSKYToolChain.cpp | 2 +- clang/lib/Driver/ToolChains/Clang.cpp | 26 ++--- clang/lib/Driver/ToolChains/CommonArgs.cpp| 29 ++- clang/lib/Driver/ToolChains/CrossWindows.cpp | 2 +- clang/lib/Driver/ToolChains/Cuda.cpp | 2 +- clang/lib/Driver/ToolChains/Cygwin.cpp| 2 +- clang/lib/Driver/ToolChains/Darwin.cpp| 2 +- clang/lib/Driver/ToolChains/DragonFly.cpp | 2 +- clang/lib/Driver/ToolChains/Flang.cpp | 2 +- clang/lib/Driver/ToolChains/FreeBSD.cpp | 2 +- clang/lib/Driver/ToolChains/Fuchsia.cpp | 2 +- clang/lib/Driver/ToolChains/Gnu.cpp | 2 +- clang/lib/Driver/ToolChains/HIPAMD.cpp| 2 +- clang/lib/Driver/ToolChains/HIPSPV.cpp| 2 +- clang/lib/Driver/ToolChains/HIPUtility.cpp| 2 +- clang/lib/Driver/ToolChains/HLSL.cpp | 2 +- clang/lib/Driver/ToolChains/Haiku.cpp | 2 +- clang/lib/Driver/ToolChains/Hexagon.cpp | 2 +- clang/lib/Driver/ToolChains/Hurd.cpp | 2 +- .../lib/Driver/ToolChains/InterfaceStubs.cpp | 2 +- clang/lib/Driver/ToolChains/Linux.cpp | 2 +- clang/lib/Driver/ToolChains/MSP430.cpp| 2 +- clang/lib/Driver/ToolChains/MSVC.cpp | 2 +- clang/lib/Driver/ToolChains/MinGW.cpp | 2 +- clang/lib/Driver/ToolChains/NaCl.cpp | 2 +- clang/lib/Driver/ToolChains/NetBSD.cpp| 2 +- clang/lib/Driver/ToolChains/OHOS.cpp | 2 +- clang/lib/Driver/ToolChains/OpenBSD.cpp | 2 +- clang/lib/Driver/ToolChains/PS4CPU.cpp| 2 +- .../lib/Driver/ToolChains/RISCVToolchain.cpp | 2 +- clang/lib/Driver/ToolChains/SPIRV.cpp | 2 +- clang/lib/Driver/ToolChains/SPIRVOpenMP.cpp | 2 +- clang/lib/Driver/ToolChains/SYCL.cpp | 2 +- clang/lib/Driver/ToolChains/Solaris.cpp | 2 +- clang/lib/Driver/ToolChains/UEFI.cpp | 2 +- clang/lib/Driver/ToolChains/VEToolchain.cpp | 2 +- clang/lib/Driver/ToolChains/WebAssembly.cpp | 2 +- clang/lib/Driver/ToolChains/XCore.cpp | 2 +- clang/lib/Driver/ToolChains/ZOS.cpp | 2 +- clang/lib/Driver/XRayArgs.cpp | 2 +- .../unittests/Driver/MultilibBuilderTest.cpp | 2 +- clang/unittests/Driver/MultilibTest.cpp | 2 +- flang/lib/Frontend/CompilerInvocation.cpp | 20 + flang/test/Driver/prefer-vector-width.f90 | 2 +- 56 files changed, 96 insertions(+), 89 deletions(-) rename clang/{lib/Driver/ToolChains => include/clang/Driver}/CommonArgs.h (98%) diff --git a/clang/lib/Driver/ToolChains/CommonArgs.h b/clang/include/clang/Driver/CommonArgs.h similarity index 98% rename from clang/lib/Driver/ToolChains/CommonArgs.h rename to clang/include/clang/Dr
[clang] [flang] [Driver] Move CommonArgs to a location visible by the Frontend Drivers (PR #142800)
https://github.com/mcinally updated https://github.com/llvm/llvm-project/pull/142800 >From 918b853de8c43dacebecb42cafa6d3b8fec15b47 Mon Sep 17 00:00:00 2001 From: Cameron McInally Date: Tue, 3 Jun 2025 11:12:42 -0700 Subject: [PATCH 1/4] [Driver] Move CommonArgs to a location visible by the Frontend Drivers This patch moves the CommonArgs utilities into a location visible by the Frontend Drivers, so that the Frontend Drivers may share option parsing code with the Compiler Driver. This is useful when the Frontend Drivers would like to verify that their incoming options are well-formed and also not reinvent the option parsing wheel. We already see code in the Clang/Flang Drivers that is parsing and verifying its incoming options. E.g. OPT_ffp_contract. This option is parsed in the Compiler Driver, Clang Driver, and Flang Driver, all with slightly different parsing code. It would be nice if the Frontend Drivers were not required to duplicate this Compiler Driver code. That way there is no maintenace burden on keeping all these parsing functions in sync. Along those lines, the Frontend Drivers will now have a useful mechanism to verify their incoming options are well-formed. Currently, the Frontend Drivers trust that the Compiler Driver is not passing back junk. In some cases, the Language Drivers will accept junk with no error at all. E.g.: `clang -cc1 -mprefer-vector-width=junk test.c' With this patch, we'll now be able to tighten up incomming options to the Frontend drivers in a lightweight way. --- .../clang/Driver}/CommonArgs.h| 6 clang/lib/Driver/MultilibBuilder.cpp | 2 +- clang/lib/Driver/ToolChain.cpp| 2 +- clang/lib/Driver/ToolChains/AIX.cpp | 2 +- clang/lib/Driver/ToolChains/AMDGPU.cpp| 2 +- clang/lib/Driver/ToolChains/AVR.cpp | 2 +- clang/lib/Driver/ToolChains/Arch/AArch64.cpp | 2 +- .../lib/Driver/ToolChains/Arch/LoongArch.cpp | 2 +- clang/lib/Driver/ToolChains/Arch/Mips.cpp | 2 +- clang/lib/Driver/ToolChains/Arch/PPC.cpp | 2 +- clang/lib/Driver/ToolChains/Arch/RISCV.cpp| 2 +- clang/lib/Driver/ToolChains/BareMetal.cpp | 2 +- clang/lib/Driver/ToolChains/CSKYToolChain.cpp | 2 +- clang/lib/Driver/ToolChains/Clang.cpp | 26 ++--- clang/lib/Driver/ToolChains/CommonArgs.cpp| 29 ++- clang/lib/Driver/ToolChains/CrossWindows.cpp | 2 +- clang/lib/Driver/ToolChains/Cuda.cpp | 2 +- clang/lib/Driver/ToolChains/Cygwin.cpp| 2 +- clang/lib/Driver/ToolChains/Darwin.cpp| 2 +- clang/lib/Driver/ToolChains/DragonFly.cpp | 2 +- clang/lib/Driver/ToolChains/Flang.cpp | 2 +- clang/lib/Driver/ToolChains/FreeBSD.cpp | 2 +- clang/lib/Driver/ToolChains/Fuchsia.cpp | 2 +- clang/lib/Driver/ToolChains/Gnu.cpp | 2 +- clang/lib/Driver/ToolChains/HIPAMD.cpp| 2 +- clang/lib/Driver/ToolChains/HIPSPV.cpp| 2 +- clang/lib/Driver/ToolChains/HIPUtility.cpp| 2 +- clang/lib/Driver/ToolChains/HLSL.cpp | 2 +- clang/lib/Driver/ToolChains/Haiku.cpp | 2 +- clang/lib/Driver/ToolChains/Hexagon.cpp | 2 +- clang/lib/Driver/ToolChains/Hurd.cpp | 2 +- .../lib/Driver/ToolChains/InterfaceStubs.cpp | 2 +- clang/lib/Driver/ToolChains/Linux.cpp | 2 +- clang/lib/Driver/ToolChains/MSP430.cpp| 2 +- clang/lib/Driver/ToolChains/MSVC.cpp | 2 +- clang/lib/Driver/ToolChains/MinGW.cpp | 2 +- clang/lib/Driver/ToolChains/NaCl.cpp | 2 +- clang/lib/Driver/ToolChains/NetBSD.cpp| 2 +- clang/lib/Driver/ToolChains/OHOS.cpp | 2 +- clang/lib/Driver/ToolChains/OpenBSD.cpp | 2 +- clang/lib/Driver/ToolChains/PS4CPU.cpp| 2 +- .../lib/Driver/ToolChains/RISCVToolchain.cpp | 2 +- clang/lib/Driver/ToolChains/SPIRV.cpp | 2 +- clang/lib/Driver/ToolChains/SPIRVOpenMP.cpp | 2 +- clang/lib/Driver/ToolChains/SYCL.cpp | 2 +- clang/lib/Driver/ToolChains/Solaris.cpp | 2 +- clang/lib/Driver/ToolChains/UEFI.cpp | 2 +- clang/lib/Driver/ToolChains/VEToolchain.cpp | 2 +- clang/lib/Driver/ToolChains/WebAssembly.cpp | 2 +- clang/lib/Driver/ToolChains/XCore.cpp | 2 +- clang/lib/Driver/ToolChains/ZOS.cpp | 2 +- clang/lib/Driver/XRayArgs.cpp | 2 +- .../unittests/Driver/MultilibBuilderTest.cpp | 2 +- clang/unittests/Driver/MultilibTest.cpp | 2 +- flang/lib/Frontend/CompilerInvocation.cpp | 20 + flang/test/Driver/prefer-vector-width.f90 | 2 +- 56 files changed, 96 insertions(+), 89 deletions(-) rename clang/{lib/Driver/ToolChains => include/clang/Driver}/CommonArgs.h (98%) diff --git a/clang/lib/Driver/ToolChains/CommonArgs.h b/clang/include/clang/Driver/CommonArgs.h similarity index 98% rename from clang/lib/Driver/ToolChains/CommonArgs.h rename to clang/include/clang/Dr
[clang] [flang] [Driver] Move CommonArgs to a location visible by the Frontend Drivers (PR #142800)
https://github.com/mcinally updated https://github.com/llvm/llvm-project/pull/142800 >From 918b853de8c43dacebecb42cafa6d3b8fec15b47 Mon Sep 17 00:00:00 2001 From: Cameron McInally Date: Tue, 3 Jun 2025 11:12:42 -0700 Subject: [PATCH 1/5] [Driver] Move CommonArgs to a location visible by the Frontend Drivers This patch moves the CommonArgs utilities into a location visible by the Frontend Drivers, so that the Frontend Drivers may share option parsing code with the Compiler Driver. This is useful when the Frontend Drivers would like to verify that their incoming options are well-formed and also not reinvent the option parsing wheel. We already see code in the Clang/Flang Drivers that is parsing and verifying its incoming options. E.g. OPT_ffp_contract. This option is parsed in the Compiler Driver, Clang Driver, and Flang Driver, all with slightly different parsing code. It would be nice if the Frontend Drivers were not required to duplicate this Compiler Driver code. That way there is no maintenace burden on keeping all these parsing functions in sync. Along those lines, the Frontend Drivers will now have a useful mechanism to verify their incoming options are well-formed. Currently, the Frontend Drivers trust that the Compiler Driver is not passing back junk. In some cases, the Language Drivers will accept junk with no error at all. E.g.: `clang -cc1 -mprefer-vector-width=junk test.c' With this patch, we'll now be able to tighten up incomming options to the Frontend drivers in a lightweight way. --- .../clang/Driver}/CommonArgs.h| 6 clang/lib/Driver/MultilibBuilder.cpp | 2 +- clang/lib/Driver/ToolChain.cpp| 2 +- clang/lib/Driver/ToolChains/AIX.cpp | 2 +- clang/lib/Driver/ToolChains/AMDGPU.cpp| 2 +- clang/lib/Driver/ToolChains/AVR.cpp | 2 +- clang/lib/Driver/ToolChains/Arch/AArch64.cpp | 2 +- .../lib/Driver/ToolChains/Arch/LoongArch.cpp | 2 +- clang/lib/Driver/ToolChains/Arch/Mips.cpp | 2 +- clang/lib/Driver/ToolChains/Arch/PPC.cpp | 2 +- clang/lib/Driver/ToolChains/Arch/RISCV.cpp| 2 +- clang/lib/Driver/ToolChains/BareMetal.cpp | 2 +- clang/lib/Driver/ToolChains/CSKYToolChain.cpp | 2 +- clang/lib/Driver/ToolChains/Clang.cpp | 26 ++--- clang/lib/Driver/ToolChains/CommonArgs.cpp| 29 ++- clang/lib/Driver/ToolChains/CrossWindows.cpp | 2 +- clang/lib/Driver/ToolChains/Cuda.cpp | 2 +- clang/lib/Driver/ToolChains/Cygwin.cpp| 2 +- clang/lib/Driver/ToolChains/Darwin.cpp| 2 +- clang/lib/Driver/ToolChains/DragonFly.cpp | 2 +- clang/lib/Driver/ToolChains/Flang.cpp | 2 +- clang/lib/Driver/ToolChains/FreeBSD.cpp | 2 +- clang/lib/Driver/ToolChains/Fuchsia.cpp | 2 +- clang/lib/Driver/ToolChains/Gnu.cpp | 2 +- clang/lib/Driver/ToolChains/HIPAMD.cpp| 2 +- clang/lib/Driver/ToolChains/HIPSPV.cpp| 2 +- clang/lib/Driver/ToolChains/HIPUtility.cpp| 2 +- clang/lib/Driver/ToolChains/HLSL.cpp | 2 +- clang/lib/Driver/ToolChains/Haiku.cpp | 2 +- clang/lib/Driver/ToolChains/Hexagon.cpp | 2 +- clang/lib/Driver/ToolChains/Hurd.cpp | 2 +- .../lib/Driver/ToolChains/InterfaceStubs.cpp | 2 +- clang/lib/Driver/ToolChains/Linux.cpp | 2 +- clang/lib/Driver/ToolChains/MSP430.cpp| 2 +- clang/lib/Driver/ToolChains/MSVC.cpp | 2 +- clang/lib/Driver/ToolChains/MinGW.cpp | 2 +- clang/lib/Driver/ToolChains/NaCl.cpp | 2 +- clang/lib/Driver/ToolChains/NetBSD.cpp| 2 +- clang/lib/Driver/ToolChains/OHOS.cpp | 2 +- clang/lib/Driver/ToolChains/OpenBSD.cpp | 2 +- clang/lib/Driver/ToolChains/PS4CPU.cpp| 2 +- .../lib/Driver/ToolChains/RISCVToolchain.cpp | 2 +- clang/lib/Driver/ToolChains/SPIRV.cpp | 2 +- clang/lib/Driver/ToolChains/SPIRVOpenMP.cpp | 2 +- clang/lib/Driver/ToolChains/SYCL.cpp | 2 +- clang/lib/Driver/ToolChains/Solaris.cpp | 2 +- clang/lib/Driver/ToolChains/UEFI.cpp | 2 +- clang/lib/Driver/ToolChains/VEToolchain.cpp | 2 +- clang/lib/Driver/ToolChains/WebAssembly.cpp | 2 +- clang/lib/Driver/ToolChains/XCore.cpp | 2 +- clang/lib/Driver/ToolChains/ZOS.cpp | 2 +- clang/lib/Driver/XRayArgs.cpp | 2 +- .../unittests/Driver/MultilibBuilderTest.cpp | 2 +- clang/unittests/Driver/MultilibTest.cpp | 2 +- flang/lib/Frontend/CompilerInvocation.cpp | 20 + flang/test/Driver/prefer-vector-width.f90 | 2 +- 56 files changed, 96 insertions(+), 89 deletions(-) rename clang/{lib/Driver/ToolChains => include/clang/Driver}/CommonArgs.h (98%) diff --git a/clang/lib/Driver/ToolChains/CommonArgs.h b/clang/include/clang/Driver/CommonArgs.h similarity index 98% rename from clang/lib/Driver/ToolChains/CommonArgs.h rename to clang/include/clang/Dr
[clang] [flang] [llvm] [Driver] Move CommonArgs to a location visible by the Frontend Drivers (PR #142800)
https://github.com/mcinally updated https://github.com/llvm/llvm-project/pull/142800 >From 918b853de8c43dacebecb42cafa6d3b8fec15b47 Mon Sep 17 00:00:00 2001 From: Cameron McInally Date: Tue, 3 Jun 2025 11:12:42 -0700 Subject: [PATCH 1/9] [Driver] Move CommonArgs to a location visible by the Frontend Drivers This patch moves the CommonArgs utilities into a location visible by the Frontend Drivers, so that the Frontend Drivers may share option parsing code with the Compiler Driver. This is useful when the Frontend Drivers would like to verify that their incoming options are well-formed and also not reinvent the option parsing wheel. We already see code in the Clang/Flang Drivers that is parsing and verifying its incoming options. E.g. OPT_ffp_contract. This option is parsed in the Compiler Driver, Clang Driver, and Flang Driver, all with slightly different parsing code. It would be nice if the Frontend Drivers were not required to duplicate this Compiler Driver code. That way there is no maintenace burden on keeping all these parsing functions in sync. Along those lines, the Frontend Drivers will now have a useful mechanism to verify their incoming options are well-formed. Currently, the Frontend Drivers trust that the Compiler Driver is not passing back junk. In some cases, the Language Drivers will accept junk with no error at all. E.g.: `clang -cc1 -mprefer-vector-width=junk test.c' With this patch, we'll now be able to tighten up incomming options to the Frontend drivers in a lightweight way. --- .../clang/Driver}/CommonArgs.h| 6 clang/lib/Driver/MultilibBuilder.cpp | 2 +- clang/lib/Driver/ToolChain.cpp| 2 +- clang/lib/Driver/ToolChains/AIX.cpp | 2 +- clang/lib/Driver/ToolChains/AMDGPU.cpp| 2 +- clang/lib/Driver/ToolChains/AVR.cpp | 2 +- clang/lib/Driver/ToolChains/Arch/AArch64.cpp | 2 +- .../lib/Driver/ToolChains/Arch/LoongArch.cpp | 2 +- clang/lib/Driver/ToolChains/Arch/Mips.cpp | 2 +- clang/lib/Driver/ToolChains/Arch/PPC.cpp | 2 +- clang/lib/Driver/ToolChains/Arch/RISCV.cpp| 2 +- clang/lib/Driver/ToolChains/BareMetal.cpp | 2 +- clang/lib/Driver/ToolChains/CSKYToolChain.cpp | 2 +- clang/lib/Driver/ToolChains/Clang.cpp | 26 ++--- clang/lib/Driver/ToolChains/CommonArgs.cpp| 29 ++- clang/lib/Driver/ToolChains/CrossWindows.cpp | 2 +- clang/lib/Driver/ToolChains/Cuda.cpp | 2 +- clang/lib/Driver/ToolChains/Cygwin.cpp| 2 +- clang/lib/Driver/ToolChains/Darwin.cpp| 2 +- clang/lib/Driver/ToolChains/DragonFly.cpp | 2 +- clang/lib/Driver/ToolChains/Flang.cpp | 2 +- clang/lib/Driver/ToolChains/FreeBSD.cpp | 2 +- clang/lib/Driver/ToolChains/Fuchsia.cpp | 2 +- clang/lib/Driver/ToolChains/Gnu.cpp | 2 +- clang/lib/Driver/ToolChains/HIPAMD.cpp| 2 +- clang/lib/Driver/ToolChains/HIPSPV.cpp| 2 +- clang/lib/Driver/ToolChains/HIPUtility.cpp| 2 +- clang/lib/Driver/ToolChains/HLSL.cpp | 2 +- clang/lib/Driver/ToolChains/Haiku.cpp | 2 +- clang/lib/Driver/ToolChains/Hexagon.cpp | 2 +- clang/lib/Driver/ToolChains/Hurd.cpp | 2 +- .../lib/Driver/ToolChains/InterfaceStubs.cpp | 2 +- clang/lib/Driver/ToolChains/Linux.cpp | 2 +- clang/lib/Driver/ToolChains/MSP430.cpp| 2 +- clang/lib/Driver/ToolChains/MSVC.cpp | 2 +- clang/lib/Driver/ToolChains/MinGW.cpp | 2 +- clang/lib/Driver/ToolChains/NaCl.cpp | 2 +- clang/lib/Driver/ToolChains/NetBSD.cpp| 2 +- clang/lib/Driver/ToolChains/OHOS.cpp | 2 +- clang/lib/Driver/ToolChains/OpenBSD.cpp | 2 +- clang/lib/Driver/ToolChains/PS4CPU.cpp| 2 +- .../lib/Driver/ToolChains/RISCVToolchain.cpp | 2 +- clang/lib/Driver/ToolChains/SPIRV.cpp | 2 +- clang/lib/Driver/ToolChains/SPIRVOpenMP.cpp | 2 +- clang/lib/Driver/ToolChains/SYCL.cpp | 2 +- clang/lib/Driver/ToolChains/Solaris.cpp | 2 +- clang/lib/Driver/ToolChains/UEFI.cpp | 2 +- clang/lib/Driver/ToolChains/VEToolchain.cpp | 2 +- clang/lib/Driver/ToolChains/WebAssembly.cpp | 2 +- clang/lib/Driver/ToolChains/XCore.cpp | 2 +- clang/lib/Driver/ToolChains/ZOS.cpp | 2 +- clang/lib/Driver/XRayArgs.cpp | 2 +- .../unittests/Driver/MultilibBuilderTest.cpp | 2 +- clang/unittests/Driver/MultilibTest.cpp | 2 +- flang/lib/Frontend/CompilerInvocation.cpp | 20 + flang/test/Driver/prefer-vector-width.f90 | 2 +- 56 files changed, 96 insertions(+), 89 deletions(-) rename clang/{lib/Driver/ToolChains => include/clang/Driver}/CommonArgs.h (98%) diff --git a/clang/lib/Driver/ToolChains/CommonArgs.h b/clang/include/clang/Driver/CommonArgs.h similarity index 98% rename from clang/lib/Driver/ToolChains/CommonArgs.h rename to clang/include/clang/Dr
[clang] [flang] [llvm] [Driver] Move CommonArgs to a location visible by the Frontend Drivers (PR #142800)
https://github.com/mcinally updated https://github.com/llvm/llvm-project/pull/142800 >From 918b853de8c43dacebecb42cafa6d3b8fec15b47 Mon Sep 17 00:00:00 2001 From: Cameron McInally Date: Tue, 3 Jun 2025 11:12:42 -0700 Subject: [PATCH 1/9] [Driver] Move CommonArgs to a location visible by the Frontend Drivers This patch moves the CommonArgs utilities into a location visible by the Frontend Drivers, so that the Frontend Drivers may share option parsing code with the Compiler Driver. This is useful when the Frontend Drivers would like to verify that their incoming options are well-formed and also not reinvent the option parsing wheel. We already see code in the Clang/Flang Drivers that is parsing and verifying its incoming options. E.g. OPT_ffp_contract. This option is parsed in the Compiler Driver, Clang Driver, and Flang Driver, all with slightly different parsing code. It would be nice if the Frontend Drivers were not required to duplicate this Compiler Driver code. That way there is no maintenace burden on keeping all these parsing functions in sync. Along those lines, the Frontend Drivers will now have a useful mechanism to verify their incoming options are well-formed. Currently, the Frontend Drivers trust that the Compiler Driver is not passing back junk. In some cases, the Language Drivers will accept junk with no error at all. E.g.: `clang -cc1 -mprefer-vector-width=junk test.c' With this patch, we'll now be able to tighten up incomming options to the Frontend drivers in a lightweight way. --- .../clang/Driver}/CommonArgs.h| 6 clang/lib/Driver/MultilibBuilder.cpp | 2 +- clang/lib/Driver/ToolChain.cpp| 2 +- clang/lib/Driver/ToolChains/AIX.cpp | 2 +- clang/lib/Driver/ToolChains/AMDGPU.cpp| 2 +- clang/lib/Driver/ToolChains/AVR.cpp | 2 +- clang/lib/Driver/ToolChains/Arch/AArch64.cpp | 2 +- .../lib/Driver/ToolChains/Arch/LoongArch.cpp | 2 +- clang/lib/Driver/ToolChains/Arch/Mips.cpp | 2 +- clang/lib/Driver/ToolChains/Arch/PPC.cpp | 2 +- clang/lib/Driver/ToolChains/Arch/RISCV.cpp| 2 +- clang/lib/Driver/ToolChains/BareMetal.cpp | 2 +- clang/lib/Driver/ToolChains/CSKYToolChain.cpp | 2 +- clang/lib/Driver/ToolChains/Clang.cpp | 26 ++--- clang/lib/Driver/ToolChains/CommonArgs.cpp| 29 ++- clang/lib/Driver/ToolChains/CrossWindows.cpp | 2 +- clang/lib/Driver/ToolChains/Cuda.cpp | 2 +- clang/lib/Driver/ToolChains/Cygwin.cpp| 2 +- clang/lib/Driver/ToolChains/Darwin.cpp| 2 +- clang/lib/Driver/ToolChains/DragonFly.cpp | 2 +- clang/lib/Driver/ToolChains/Flang.cpp | 2 +- clang/lib/Driver/ToolChains/FreeBSD.cpp | 2 +- clang/lib/Driver/ToolChains/Fuchsia.cpp | 2 +- clang/lib/Driver/ToolChains/Gnu.cpp | 2 +- clang/lib/Driver/ToolChains/HIPAMD.cpp| 2 +- clang/lib/Driver/ToolChains/HIPSPV.cpp| 2 +- clang/lib/Driver/ToolChains/HIPUtility.cpp| 2 +- clang/lib/Driver/ToolChains/HLSL.cpp | 2 +- clang/lib/Driver/ToolChains/Haiku.cpp | 2 +- clang/lib/Driver/ToolChains/Hexagon.cpp | 2 +- clang/lib/Driver/ToolChains/Hurd.cpp | 2 +- .../lib/Driver/ToolChains/InterfaceStubs.cpp | 2 +- clang/lib/Driver/ToolChains/Linux.cpp | 2 +- clang/lib/Driver/ToolChains/MSP430.cpp| 2 +- clang/lib/Driver/ToolChains/MSVC.cpp | 2 +- clang/lib/Driver/ToolChains/MinGW.cpp | 2 +- clang/lib/Driver/ToolChains/NaCl.cpp | 2 +- clang/lib/Driver/ToolChains/NetBSD.cpp| 2 +- clang/lib/Driver/ToolChains/OHOS.cpp | 2 +- clang/lib/Driver/ToolChains/OpenBSD.cpp | 2 +- clang/lib/Driver/ToolChains/PS4CPU.cpp| 2 +- .../lib/Driver/ToolChains/RISCVToolchain.cpp | 2 +- clang/lib/Driver/ToolChains/SPIRV.cpp | 2 +- clang/lib/Driver/ToolChains/SPIRVOpenMP.cpp | 2 +- clang/lib/Driver/ToolChains/SYCL.cpp | 2 +- clang/lib/Driver/ToolChains/Solaris.cpp | 2 +- clang/lib/Driver/ToolChains/UEFI.cpp | 2 +- clang/lib/Driver/ToolChains/VEToolchain.cpp | 2 +- clang/lib/Driver/ToolChains/WebAssembly.cpp | 2 +- clang/lib/Driver/ToolChains/XCore.cpp | 2 +- clang/lib/Driver/ToolChains/ZOS.cpp | 2 +- clang/lib/Driver/XRayArgs.cpp | 2 +- .../unittests/Driver/MultilibBuilderTest.cpp | 2 +- clang/unittests/Driver/MultilibTest.cpp | 2 +- flang/lib/Frontend/CompilerInvocation.cpp | 20 + flang/test/Driver/prefer-vector-width.f90 | 2 +- 56 files changed, 96 insertions(+), 89 deletions(-) rename clang/{lib/Driver/ToolChains => include/clang/Driver}/CommonArgs.h (98%) diff --git a/clang/lib/Driver/ToolChains/CommonArgs.h b/clang/include/clang/Driver/CommonArgs.h similarity index 98% rename from clang/lib/Driver/ToolChains/CommonArgs.h rename to clang/include/clang/Dr
[clang] [flang] [llvm] [Driver] Move CommonArgs to a location visible by the Frontend Drivers (PR #142800)
mcinally wrote: All checks have passed, if someone wouldn't mind merging for me. Thanks in advance! https://github.com/llvm/llvm-project/pull/142800 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [Driver] Move CommonArgs to a location visible by the Frontend Drivers (PR #142800)
@@ -3167,3 +3167,29 @@ void tools::handleInterchangeLoopsArgs(const ArgList &Args, options::OPT_fno_loop_interchange, EnableInterchange)) CmdArgs.push_back("-floop-interchange"); } + +std::optional tools::ParseMPreferVectorWidthOption( +clang::DiagnosticsEngine &Diags, const llvm::opt::ArgList &Args, +ArgStringList &CmdArgs, bool isCompilerDriver) { + // If this was invoked by the Compiler Driver, we pass through the option + // as-is. Otherwise, if this is the Frontend Driver, we want just the value. + StringRef Out = isCompilerDriver ? "-mprefer-vector-width=" : ""; + + Arg *A = Args.getLastArg(clang::driver::options::OPT_mprefer_vector_width_EQ); + if (!A) +return std::nullopt; + + StringRef Value = A->getValue(); + unsigned Width __attribute((uninitialized)); + + // Only "none" and Integer values are accepted by + // -mprefer-vector-width=. + if (Value != "none" && Value.getAsInteger(10, Width)) { +Diags.Report(clang::diag::err_drv_invalid_value) +<< A->getOption().getName() << Value; +return std::nullopt; + } + + CmdArgs.push_back(Args.MakeArgString(Out + Value)); mcinally wrote: Just pushed a new patch. I like it a lot. See what you think... We were able to get rid of `isCompilerDriver` and the `clang/lib/Driver/ToolChains/Clang.cpp` change doesn't look awkward at all. https://github.com/llvm/llvm-project/pull/142800 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [Driver] Move CommonArgs to a location visible by the Frontend Drivers (PR #142800)
@@ -3167,3 +3167,29 @@ void tools::handleInterchangeLoopsArgs(const ArgList &Args, options::OPT_fno_loop_interchange, EnableInterchange)) CmdArgs.push_back("-floop-interchange"); } + +std::optional tools::ParseMPreferVectorWidthOption( +clang::DiagnosticsEngine &Diags, const llvm::opt::ArgList &Args, +ArgStringList &CmdArgs, bool isCompilerDriver) { + // If this was invoked by the Compiler Driver, we pass through the option + // as-is. Otherwise, if this is the Frontend Driver, we want just the value. + StringRef Out = (isCompilerDriver) ? "-mprefer-vector-width=" : ""; + + Arg *A = Args.getLastArg(clang::driver::options::OPT_mprefer_vector_width_EQ); + if (!A) +return std::nullopt; + + StringRef Value = A->getValue(); + unsigned Width; mcinally wrote: Looks like we can't add this. The MSVC build is failing since `__attribute((uninitialized))` isn't supported there. I'll remove this. https://github.com/llvm/llvm-project/pull/142800 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [Driver] Move CommonArgs to a location visible by the Frontend Drivers (PR #142800)
mcinally wrote: > Thanks for the changes, Cameron. > > Could you take a look at the [failing > buildkite](https://github.com/llvm/llvm-project/actions/runs/15493623574/job/43624895590?pr=142800) > and see if it is something relevant? It seems to be a Windows build. Those > are a bit flaky and a failure doesn't necessarily mean that there is a > problem with the PR, but it's probably worth taking a look just in case. Thanks! It looks like `__attribute((uninitialized))` isn't supported on Windows, so I have removed it from our patch. https://github.com/llvm/llvm-project/pull/142800 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [Driver] Move CommonArgs to a location visible by the Frontend Drivers (PR #142800)
https://github.com/mcinally updated https://github.com/llvm/llvm-project/pull/142800 >From 918b853de8c43dacebecb42cafa6d3b8fec15b47 Mon Sep 17 00:00:00 2001 From: Cameron McInally Date: Tue, 3 Jun 2025 11:12:42 -0700 Subject: [PATCH 1/2] [Driver] Move CommonArgs to a location visible by the Frontend Drivers This patch moves the CommonArgs utilities into a location visible by the Frontend Drivers, so that the Frontend Drivers may share option parsing code with the Compiler Driver. This is useful when the Frontend Drivers would like to verify that their incoming options are well-formed and also not reinvent the option parsing wheel. We already see code in the Clang/Flang Drivers that is parsing and verifying its incoming options. E.g. OPT_ffp_contract. This option is parsed in the Compiler Driver, Clang Driver, and Flang Driver, all with slightly different parsing code. It would be nice if the Frontend Drivers were not required to duplicate this Compiler Driver code. That way there is no maintenace burden on keeping all these parsing functions in sync. Along those lines, the Frontend Drivers will now have a useful mechanism to verify their incoming options are well-formed. Currently, the Frontend Drivers trust that the Compiler Driver is not passing back junk. In some cases, the Language Drivers will accept junk with no error at all. E.g.: `clang -cc1 -mprefer-vector-width=junk test.c' With this patch, we'll now be able to tighten up incomming options to the Frontend drivers in a lightweight way. --- .../clang/Driver}/CommonArgs.h| 6 clang/lib/Driver/MultilibBuilder.cpp | 2 +- clang/lib/Driver/ToolChain.cpp| 2 +- clang/lib/Driver/ToolChains/AIX.cpp | 2 +- clang/lib/Driver/ToolChains/AMDGPU.cpp| 2 +- clang/lib/Driver/ToolChains/AVR.cpp | 2 +- clang/lib/Driver/ToolChains/Arch/AArch64.cpp | 2 +- .../lib/Driver/ToolChains/Arch/LoongArch.cpp | 2 +- clang/lib/Driver/ToolChains/Arch/Mips.cpp | 2 +- clang/lib/Driver/ToolChains/Arch/PPC.cpp | 2 +- clang/lib/Driver/ToolChains/Arch/RISCV.cpp| 2 +- clang/lib/Driver/ToolChains/BareMetal.cpp | 2 +- clang/lib/Driver/ToolChains/CSKYToolChain.cpp | 2 +- clang/lib/Driver/ToolChains/Clang.cpp | 26 ++--- clang/lib/Driver/ToolChains/CommonArgs.cpp| 29 ++- clang/lib/Driver/ToolChains/CrossWindows.cpp | 2 +- clang/lib/Driver/ToolChains/Cuda.cpp | 2 +- clang/lib/Driver/ToolChains/Cygwin.cpp| 2 +- clang/lib/Driver/ToolChains/Darwin.cpp| 2 +- clang/lib/Driver/ToolChains/DragonFly.cpp | 2 +- clang/lib/Driver/ToolChains/Flang.cpp | 2 +- clang/lib/Driver/ToolChains/FreeBSD.cpp | 2 +- clang/lib/Driver/ToolChains/Fuchsia.cpp | 2 +- clang/lib/Driver/ToolChains/Gnu.cpp | 2 +- clang/lib/Driver/ToolChains/HIPAMD.cpp| 2 +- clang/lib/Driver/ToolChains/HIPSPV.cpp| 2 +- clang/lib/Driver/ToolChains/HIPUtility.cpp| 2 +- clang/lib/Driver/ToolChains/HLSL.cpp | 2 +- clang/lib/Driver/ToolChains/Haiku.cpp | 2 +- clang/lib/Driver/ToolChains/Hexagon.cpp | 2 +- clang/lib/Driver/ToolChains/Hurd.cpp | 2 +- .../lib/Driver/ToolChains/InterfaceStubs.cpp | 2 +- clang/lib/Driver/ToolChains/Linux.cpp | 2 +- clang/lib/Driver/ToolChains/MSP430.cpp| 2 +- clang/lib/Driver/ToolChains/MSVC.cpp | 2 +- clang/lib/Driver/ToolChains/MinGW.cpp | 2 +- clang/lib/Driver/ToolChains/NaCl.cpp | 2 +- clang/lib/Driver/ToolChains/NetBSD.cpp| 2 +- clang/lib/Driver/ToolChains/OHOS.cpp | 2 +- clang/lib/Driver/ToolChains/OpenBSD.cpp | 2 +- clang/lib/Driver/ToolChains/PS4CPU.cpp| 2 +- .../lib/Driver/ToolChains/RISCVToolchain.cpp | 2 +- clang/lib/Driver/ToolChains/SPIRV.cpp | 2 +- clang/lib/Driver/ToolChains/SPIRVOpenMP.cpp | 2 +- clang/lib/Driver/ToolChains/SYCL.cpp | 2 +- clang/lib/Driver/ToolChains/Solaris.cpp | 2 +- clang/lib/Driver/ToolChains/UEFI.cpp | 2 +- clang/lib/Driver/ToolChains/VEToolchain.cpp | 2 +- clang/lib/Driver/ToolChains/WebAssembly.cpp | 2 +- clang/lib/Driver/ToolChains/XCore.cpp | 2 +- clang/lib/Driver/ToolChains/ZOS.cpp | 2 +- clang/lib/Driver/XRayArgs.cpp | 2 +- .../unittests/Driver/MultilibBuilderTest.cpp | 2 +- clang/unittests/Driver/MultilibTest.cpp | 2 +- flang/lib/Frontend/CompilerInvocation.cpp | 20 + flang/test/Driver/prefer-vector-width.f90 | 2 +- 56 files changed, 96 insertions(+), 89 deletions(-) rename clang/{lib/Driver/ToolChains => include/clang/Driver}/CommonArgs.h (98%) diff --git a/clang/lib/Driver/ToolChains/CommonArgs.h b/clang/include/clang/Driver/CommonArgs.h similarity index 98% rename from clang/lib/Driver/ToolChains/CommonArgs.h rename to clang/include/clang/Dr
[clang] [flang] [Driver] Move CommonArgs to a location visible by the Frontend Drivers (PR #142800)
https://github.com/mcinally updated https://github.com/llvm/llvm-project/pull/142800 >From 918b853de8c43dacebecb42cafa6d3b8fec15b47 Mon Sep 17 00:00:00 2001 From: Cameron McInally Date: Tue, 3 Jun 2025 11:12:42 -0700 Subject: [PATCH 1/7] [Driver] Move CommonArgs to a location visible by the Frontend Drivers This patch moves the CommonArgs utilities into a location visible by the Frontend Drivers, so that the Frontend Drivers may share option parsing code with the Compiler Driver. This is useful when the Frontend Drivers would like to verify that their incoming options are well-formed and also not reinvent the option parsing wheel. We already see code in the Clang/Flang Drivers that is parsing and verifying its incoming options. E.g. OPT_ffp_contract. This option is parsed in the Compiler Driver, Clang Driver, and Flang Driver, all with slightly different parsing code. It would be nice if the Frontend Drivers were not required to duplicate this Compiler Driver code. That way there is no maintenace burden on keeping all these parsing functions in sync. Along those lines, the Frontend Drivers will now have a useful mechanism to verify their incoming options are well-formed. Currently, the Frontend Drivers trust that the Compiler Driver is not passing back junk. In some cases, the Language Drivers will accept junk with no error at all. E.g.: `clang -cc1 -mprefer-vector-width=junk test.c' With this patch, we'll now be able to tighten up incomming options to the Frontend drivers in a lightweight way. --- .../clang/Driver}/CommonArgs.h| 6 clang/lib/Driver/MultilibBuilder.cpp | 2 +- clang/lib/Driver/ToolChain.cpp| 2 +- clang/lib/Driver/ToolChains/AIX.cpp | 2 +- clang/lib/Driver/ToolChains/AMDGPU.cpp| 2 +- clang/lib/Driver/ToolChains/AVR.cpp | 2 +- clang/lib/Driver/ToolChains/Arch/AArch64.cpp | 2 +- .../lib/Driver/ToolChains/Arch/LoongArch.cpp | 2 +- clang/lib/Driver/ToolChains/Arch/Mips.cpp | 2 +- clang/lib/Driver/ToolChains/Arch/PPC.cpp | 2 +- clang/lib/Driver/ToolChains/Arch/RISCV.cpp| 2 +- clang/lib/Driver/ToolChains/BareMetal.cpp | 2 +- clang/lib/Driver/ToolChains/CSKYToolChain.cpp | 2 +- clang/lib/Driver/ToolChains/Clang.cpp | 26 ++--- clang/lib/Driver/ToolChains/CommonArgs.cpp| 29 ++- clang/lib/Driver/ToolChains/CrossWindows.cpp | 2 +- clang/lib/Driver/ToolChains/Cuda.cpp | 2 +- clang/lib/Driver/ToolChains/Cygwin.cpp| 2 +- clang/lib/Driver/ToolChains/Darwin.cpp| 2 +- clang/lib/Driver/ToolChains/DragonFly.cpp | 2 +- clang/lib/Driver/ToolChains/Flang.cpp | 2 +- clang/lib/Driver/ToolChains/FreeBSD.cpp | 2 +- clang/lib/Driver/ToolChains/Fuchsia.cpp | 2 +- clang/lib/Driver/ToolChains/Gnu.cpp | 2 +- clang/lib/Driver/ToolChains/HIPAMD.cpp| 2 +- clang/lib/Driver/ToolChains/HIPSPV.cpp| 2 +- clang/lib/Driver/ToolChains/HIPUtility.cpp| 2 +- clang/lib/Driver/ToolChains/HLSL.cpp | 2 +- clang/lib/Driver/ToolChains/Haiku.cpp | 2 +- clang/lib/Driver/ToolChains/Hexagon.cpp | 2 +- clang/lib/Driver/ToolChains/Hurd.cpp | 2 +- .../lib/Driver/ToolChains/InterfaceStubs.cpp | 2 +- clang/lib/Driver/ToolChains/Linux.cpp | 2 +- clang/lib/Driver/ToolChains/MSP430.cpp| 2 +- clang/lib/Driver/ToolChains/MSVC.cpp | 2 +- clang/lib/Driver/ToolChains/MinGW.cpp | 2 +- clang/lib/Driver/ToolChains/NaCl.cpp | 2 +- clang/lib/Driver/ToolChains/NetBSD.cpp| 2 +- clang/lib/Driver/ToolChains/OHOS.cpp | 2 +- clang/lib/Driver/ToolChains/OpenBSD.cpp | 2 +- clang/lib/Driver/ToolChains/PS4CPU.cpp| 2 +- .../lib/Driver/ToolChains/RISCVToolchain.cpp | 2 +- clang/lib/Driver/ToolChains/SPIRV.cpp | 2 +- clang/lib/Driver/ToolChains/SPIRVOpenMP.cpp | 2 +- clang/lib/Driver/ToolChains/SYCL.cpp | 2 +- clang/lib/Driver/ToolChains/Solaris.cpp | 2 +- clang/lib/Driver/ToolChains/UEFI.cpp | 2 +- clang/lib/Driver/ToolChains/VEToolchain.cpp | 2 +- clang/lib/Driver/ToolChains/WebAssembly.cpp | 2 +- clang/lib/Driver/ToolChains/XCore.cpp | 2 +- clang/lib/Driver/ToolChains/ZOS.cpp | 2 +- clang/lib/Driver/XRayArgs.cpp | 2 +- .../unittests/Driver/MultilibBuilderTest.cpp | 2 +- clang/unittests/Driver/MultilibTest.cpp | 2 +- flang/lib/Frontend/CompilerInvocation.cpp | 20 + flang/test/Driver/prefer-vector-width.f90 | 2 +- 56 files changed, 96 insertions(+), 89 deletions(-) rename clang/{lib/Driver/ToolChains => include/clang/Driver}/CommonArgs.h (98%) diff --git a/clang/lib/Driver/ToolChains/CommonArgs.h b/clang/include/clang/Driver/CommonArgs.h similarity index 98% rename from clang/lib/Driver/ToolChains/CommonArgs.h rename to clang/include/clang/Dr
[clang] [flang] [Driver] Move CommonArgs to a location visible by the Frontend Drivers (PR #142800)
mcinally wrote: It looks like we have a number of approvals and I haven't seen any objections yet. Should we go ahead with merging this in the current state? If so, I'll need help there since I don't have commit access yet. @tarunprabhu would you mind volunteering to mash the merge button again? https://github.com/llvm/llvm-project/pull/142800 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [llvm] [Driver] Move CommonArgs to a location visible by the Frontend Drivers (PR #142800)
https://github.com/mcinally updated https://github.com/llvm/llvm-project/pull/142800 >From 918b853de8c43dacebecb42cafa6d3b8fec15b47 Mon Sep 17 00:00:00 2001 From: Cameron McInally Date: Tue, 3 Jun 2025 11:12:42 -0700 Subject: [PATCH 1/8] [Driver] Move CommonArgs to a location visible by the Frontend Drivers This patch moves the CommonArgs utilities into a location visible by the Frontend Drivers, so that the Frontend Drivers may share option parsing code with the Compiler Driver. This is useful when the Frontend Drivers would like to verify that their incoming options are well-formed and also not reinvent the option parsing wheel. We already see code in the Clang/Flang Drivers that is parsing and verifying its incoming options. E.g. OPT_ffp_contract. This option is parsed in the Compiler Driver, Clang Driver, and Flang Driver, all with slightly different parsing code. It would be nice if the Frontend Drivers were not required to duplicate this Compiler Driver code. That way there is no maintenace burden on keeping all these parsing functions in sync. Along those lines, the Frontend Drivers will now have a useful mechanism to verify their incoming options are well-formed. Currently, the Frontend Drivers trust that the Compiler Driver is not passing back junk. In some cases, the Language Drivers will accept junk with no error at all. E.g.: `clang -cc1 -mprefer-vector-width=junk test.c' With this patch, we'll now be able to tighten up incomming options to the Frontend drivers in a lightweight way. --- .../clang/Driver}/CommonArgs.h| 6 clang/lib/Driver/MultilibBuilder.cpp | 2 +- clang/lib/Driver/ToolChain.cpp| 2 +- clang/lib/Driver/ToolChains/AIX.cpp | 2 +- clang/lib/Driver/ToolChains/AMDGPU.cpp| 2 +- clang/lib/Driver/ToolChains/AVR.cpp | 2 +- clang/lib/Driver/ToolChains/Arch/AArch64.cpp | 2 +- .../lib/Driver/ToolChains/Arch/LoongArch.cpp | 2 +- clang/lib/Driver/ToolChains/Arch/Mips.cpp | 2 +- clang/lib/Driver/ToolChains/Arch/PPC.cpp | 2 +- clang/lib/Driver/ToolChains/Arch/RISCV.cpp| 2 +- clang/lib/Driver/ToolChains/BareMetal.cpp | 2 +- clang/lib/Driver/ToolChains/CSKYToolChain.cpp | 2 +- clang/lib/Driver/ToolChains/Clang.cpp | 26 ++--- clang/lib/Driver/ToolChains/CommonArgs.cpp| 29 ++- clang/lib/Driver/ToolChains/CrossWindows.cpp | 2 +- clang/lib/Driver/ToolChains/Cuda.cpp | 2 +- clang/lib/Driver/ToolChains/Cygwin.cpp| 2 +- clang/lib/Driver/ToolChains/Darwin.cpp| 2 +- clang/lib/Driver/ToolChains/DragonFly.cpp | 2 +- clang/lib/Driver/ToolChains/Flang.cpp | 2 +- clang/lib/Driver/ToolChains/FreeBSD.cpp | 2 +- clang/lib/Driver/ToolChains/Fuchsia.cpp | 2 +- clang/lib/Driver/ToolChains/Gnu.cpp | 2 +- clang/lib/Driver/ToolChains/HIPAMD.cpp| 2 +- clang/lib/Driver/ToolChains/HIPSPV.cpp| 2 +- clang/lib/Driver/ToolChains/HIPUtility.cpp| 2 +- clang/lib/Driver/ToolChains/HLSL.cpp | 2 +- clang/lib/Driver/ToolChains/Haiku.cpp | 2 +- clang/lib/Driver/ToolChains/Hexagon.cpp | 2 +- clang/lib/Driver/ToolChains/Hurd.cpp | 2 +- .../lib/Driver/ToolChains/InterfaceStubs.cpp | 2 +- clang/lib/Driver/ToolChains/Linux.cpp | 2 +- clang/lib/Driver/ToolChains/MSP430.cpp| 2 +- clang/lib/Driver/ToolChains/MSVC.cpp | 2 +- clang/lib/Driver/ToolChains/MinGW.cpp | 2 +- clang/lib/Driver/ToolChains/NaCl.cpp | 2 +- clang/lib/Driver/ToolChains/NetBSD.cpp| 2 +- clang/lib/Driver/ToolChains/OHOS.cpp | 2 +- clang/lib/Driver/ToolChains/OpenBSD.cpp | 2 +- clang/lib/Driver/ToolChains/PS4CPU.cpp| 2 +- .../lib/Driver/ToolChains/RISCVToolchain.cpp | 2 +- clang/lib/Driver/ToolChains/SPIRV.cpp | 2 +- clang/lib/Driver/ToolChains/SPIRVOpenMP.cpp | 2 +- clang/lib/Driver/ToolChains/SYCL.cpp | 2 +- clang/lib/Driver/ToolChains/Solaris.cpp | 2 +- clang/lib/Driver/ToolChains/UEFI.cpp | 2 +- clang/lib/Driver/ToolChains/VEToolchain.cpp | 2 +- clang/lib/Driver/ToolChains/WebAssembly.cpp | 2 +- clang/lib/Driver/ToolChains/XCore.cpp | 2 +- clang/lib/Driver/ToolChains/ZOS.cpp | 2 +- clang/lib/Driver/XRayArgs.cpp | 2 +- .../unittests/Driver/MultilibBuilderTest.cpp | 2 +- clang/unittests/Driver/MultilibTest.cpp | 2 +- flang/lib/Frontend/CompilerInvocation.cpp | 20 + flang/test/Driver/prefer-vector-width.f90 | 2 +- 56 files changed, 96 insertions(+), 89 deletions(-) rename clang/{lib/Driver/ToolChains => include/clang/Driver}/CommonArgs.h (98%) diff --git a/clang/lib/Driver/ToolChains/CommonArgs.h b/clang/include/clang/Driver/CommonArgs.h similarity index 98% rename from clang/lib/Driver/ToolChains/CommonArgs.h rename to clang/include/clang/Dr
[clang] [flang] [llvm] [Driver] Move CommonArgs to a location visible by the Frontend Drivers (PR #142800)
mcinally wrote: It was easy enough to add. Seems like it would be useful in general too. https://github.com/llvm/llvm-project/pull/142800 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [Driver] Move CommonArgs to a location visible by the Frontend Drivers (PR #142800)
@@ -3167,3 +3167,30 @@ void tools::handleInterchangeLoopsArgs(const ArgList &Args, options::OPT_fno_loop_interchange, EnableInterchange)) CmdArgs.push_back("-floop-interchange"); } + +void tools::ParseMPreferVectorWidthOption(clang::DiagnosticsEngine &Diags, + const llvm::opt::ArgList &Args, + ArgStringList &CmdArgs, + bool isCompilerDriver) { + // If this was invoked by the Compiler Driver, we pass through the option + // as-is. Otherwise, if this is the Frontend Driver, we want just the value. + StringRef Out = (isCompilerDriver) ? "-mprefer-vector-width=" : ""; + + Arg *A = Args.getLastArg(clang::driver::options::OPT_mprefer_vector_width_EQ); + if (!A) +return; + + StringRef Value = A->getValue(); + unsigned Width; + + // Only "none" and Integer values are accepted by + // -mprefer-vector-width=. + if (Value != "none" && Value.getAsInteger(10, Width)) { +Diags.Report(clang::diag::err_drv_invalid_value) +<< A->getOption().getName() << Value; +return; + } + + CmdArgs.push_back(Args.MakeArgString(Out + Value)); mcinally wrote: > The function could take an ArgStringList*, only push Out + Value if it is > provided, and always return Value as a StringRef. That would work. It would disturb the Compiler Driver a bit to avoid warnings. We'd need to explicitly discard the results when unwanted. E.g.: `(void)ParseMPreferVectorWidthOption(...);` I wonder if we could come up with a Frontend Driver mechanism to discard everything up to and including the `=`. Then we'd just need to wrap the parsing/handling call in that mechanism. > Not sure if it would works with all options, I am not familiar with the > drivers. Same. I suggest that we delay this decision until there's a better view of the entire problem. https://github.com/llvm/llvm-project/pull/142800 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [mlir] [flang] Add support for -mrecip[=] (PR #142172)
mcinally wrote: This PR has been abandoned in hopes of using the more modular solution in #142800. https://github.com/llvm/llvm-project/pull/142172 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [mlir] [flang] Add support for -mrecip[=] (PR #142172)
https://github.com/mcinally closed https://github.com/llvm/llvm-project/pull/142172 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [Driver] Move CommonArgs to a location visible by the Frontend Drivers (PR #142800)
@@ -3167,3 +3167,30 @@ void tools::handleInterchangeLoopsArgs(const ArgList &Args, options::OPT_fno_loop_interchange, EnableInterchange)) CmdArgs.push_back("-floop-interchange"); } + +void tools::ParseMPreferVectorWidthOption(clang::DiagnosticsEngine &Diags, + const llvm::opt::ArgList &Args, + ArgStringList &CmdArgs, + bool isCompilerDriver) { + // If this was invoked by the Compiler Driver, we pass through the option + // as-is. Otherwise, if this is the Frontend Driver, we want just the value. + StringRef Out = (isCompilerDriver) ? "-mprefer-vector-width=" : ""; + + Arg *A = Args.getLastArg(clang::driver::options::OPT_mprefer_vector_width_EQ); + if (!A) +return; + + StringRef Value = A->getValue(); + unsigned Width; + + // Only "none" and Integer values are accepted by + // -mprefer-vector-width=. + if (Value != "none" && Value.getAsInteger(10, Width)) { +Diags.Report(clang::diag::err_drv_invalid_value) +<< A->getOption().getName() << Value; +return; + } + + CmdArgs.push_back(Args.MakeArgString(Out + Value)); mcinally wrote: > Just to clarify, by warnings you mean warnings when building clang itself, > right? Correct. The unused result would be a warning. > Is the real issue here that we need to validate the argument values? It is a > fairly common pattern in, e.g. > [clang/lib/Frontend/CompilerInvocation.cpp](https://github.com/llvm/llvm-project/blob/main/clang/lib/Frontend/CompilerInvocation.cpp) > to look at the ArgList and parse the arguments there. Yes, that's what we're trying to avoid. Both `Frontend/CompilerInvocation.cpp` and `Driver/FC]lang.cpp` could do verification, but we don't want to have the same/similar code in both places. This patch would let `Frontend/CompilerInvocation.cpp` and `Driver/[FC]lang.cpp` share the same parsing/handling functions. > It may be better to share the argument validation and return, say, an > optional value with the correctly parsed value if it exists. How does that > sound? I like that!! I'll wait to see if there are other ideas before updating the PR. https://github.com/llvm/llvm-project/pull/142800 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [Driver] Move CommonArgs to a location visible by the Frontend Drivers (PR #142800)
@@ -3167,3 +3167,29 @@ void tools::handleInterchangeLoopsArgs(const ArgList &Args, options::OPT_fno_loop_interchange, EnableInterchange)) CmdArgs.push_back("-floop-interchange"); } + +std::optional tools::ParseMPreferVectorWidthOption( +clang::DiagnosticsEngine &Diags, const llvm::opt::ArgList &Args, +ArgStringList &CmdArgs, bool isCompilerDriver) { + // If this was invoked by the Compiler Driver, we pass through the option + // as-is. Otherwise, if this is the Frontend Driver, we want just the value. + StringRef Out = isCompilerDriver ? "-mprefer-vector-width=" : ""; + + Arg *A = Args.getLastArg(clang::driver::options::OPT_mprefer_vector_width_EQ); + if (!A) +return std::nullopt; + + StringRef Value = A->getValue(); + unsigned Width __attribute((uninitialized)); + + // Only "none" and Integer values are accepted by + // -mprefer-vector-width=. + if (Value != "none" && Value.getAsInteger(10, Width)) { +Diags.Report(clang::diag::err_drv_invalid_value) +<< A->getOption().getName() << Value; +return std::nullopt; + } + + CmdArgs.push_back(Args.MakeArgString(Out + Value)); mcinally wrote: > The alternative would be to not add to CmdArgs here, but to do it in the > caller instead. That's a good point as well. There are plenty of `CmdArgs.push_back(...)`'s in `clang/lib/Driver/ToolChains/Clang.cpp` already, so it wouldn't be awkward. Let me code that up and we can see if we like it... https://github.com/llvm/llvm-project/pull/142800 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [Driver] Move CommonArgs to a location visible by the Frontend Drivers (PR #142800)
https://github.com/mcinally updated https://github.com/llvm/llvm-project/pull/142800 >From 918b853de8c43dacebecb42cafa6d3b8fec15b47 Mon Sep 17 00:00:00 2001 From: Cameron McInally Date: Tue, 3 Jun 2025 11:12:42 -0700 Subject: [PATCH 1/6] [Driver] Move CommonArgs to a location visible by the Frontend Drivers This patch moves the CommonArgs utilities into a location visible by the Frontend Drivers, so that the Frontend Drivers may share option parsing code with the Compiler Driver. This is useful when the Frontend Drivers would like to verify that their incoming options are well-formed and also not reinvent the option parsing wheel. We already see code in the Clang/Flang Drivers that is parsing and verifying its incoming options. E.g. OPT_ffp_contract. This option is parsed in the Compiler Driver, Clang Driver, and Flang Driver, all with slightly different parsing code. It would be nice if the Frontend Drivers were not required to duplicate this Compiler Driver code. That way there is no maintenace burden on keeping all these parsing functions in sync. Along those lines, the Frontend Drivers will now have a useful mechanism to verify their incoming options are well-formed. Currently, the Frontend Drivers trust that the Compiler Driver is not passing back junk. In some cases, the Language Drivers will accept junk with no error at all. E.g.: `clang -cc1 -mprefer-vector-width=junk test.c' With this patch, we'll now be able to tighten up incomming options to the Frontend drivers in a lightweight way. --- .../clang/Driver}/CommonArgs.h| 6 clang/lib/Driver/MultilibBuilder.cpp | 2 +- clang/lib/Driver/ToolChain.cpp| 2 +- clang/lib/Driver/ToolChains/AIX.cpp | 2 +- clang/lib/Driver/ToolChains/AMDGPU.cpp| 2 +- clang/lib/Driver/ToolChains/AVR.cpp | 2 +- clang/lib/Driver/ToolChains/Arch/AArch64.cpp | 2 +- .../lib/Driver/ToolChains/Arch/LoongArch.cpp | 2 +- clang/lib/Driver/ToolChains/Arch/Mips.cpp | 2 +- clang/lib/Driver/ToolChains/Arch/PPC.cpp | 2 +- clang/lib/Driver/ToolChains/Arch/RISCV.cpp| 2 +- clang/lib/Driver/ToolChains/BareMetal.cpp | 2 +- clang/lib/Driver/ToolChains/CSKYToolChain.cpp | 2 +- clang/lib/Driver/ToolChains/Clang.cpp | 26 ++--- clang/lib/Driver/ToolChains/CommonArgs.cpp| 29 ++- clang/lib/Driver/ToolChains/CrossWindows.cpp | 2 +- clang/lib/Driver/ToolChains/Cuda.cpp | 2 +- clang/lib/Driver/ToolChains/Cygwin.cpp| 2 +- clang/lib/Driver/ToolChains/Darwin.cpp| 2 +- clang/lib/Driver/ToolChains/DragonFly.cpp | 2 +- clang/lib/Driver/ToolChains/Flang.cpp | 2 +- clang/lib/Driver/ToolChains/FreeBSD.cpp | 2 +- clang/lib/Driver/ToolChains/Fuchsia.cpp | 2 +- clang/lib/Driver/ToolChains/Gnu.cpp | 2 +- clang/lib/Driver/ToolChains/HIPAMD.cpp| 2 +- clang/lib/Driver/ToolChains/HIPSPV.cpp| 2 +- clang/lib/Driver/ToolChains/HIPUtility.cpp| 2 +- clang/lib/Driver/ToolChains/HLSL.cpp | 2 +- clang/lib/Driver/ToolChains/Haiku.cpp | 2 +- clang/lib/Driver/ToolChains/Hexagon.cpp | 2 +- clang/lib/Driver/ToolChains/Hurd.cpp | 2 +- .../lib/Driver/ToolChains/InterfaceStubs.cpp | 2 +- clang/lib/Driver/ToolChains/Linux.cpp | 2 +- clang/lib/Driver/ToolChains/MSP430.cpp| 2 +- clang/lib/Driver/ToolChains/MSVC.cpp | 2 +- clang/lib/Driver/ToolChains/MinGW.cpp | 2 +- clang/lib/Driver/ToolChains/NaCl.cpp | 2 +- clang/lib/Driver/ToolChains/NetBSD.cpp| 2 +- clang/lib/Driver/ToolChains/OHOS.cpp | 2 +- clang/lib/Driver/ToolChains/OpenBSD.cpp | 2 +- clang/lib/Driver/ToolChains/PS4CPU.cpp| 2 +- .../lib/Driver/ToolChains/RISCVToolchain.cpp | 2 +- clang/lib/Driver/ToolChains/SPIRV.cpp | 2 +- clang/lib/Driver/ToolChains/SPIRVOpenMP.cpp | 2 +- clang/lib/Driver/ToolChains/SYCL.cpp | 2 +- clang/lib/Driver/ToolChains/Solaris.cpp | 2 +- clang/lib/Driver/ToolChains/UEFI.cpp | 2 +- clang/lib/Driver/ToolChains/VEToolchain.cpp | 2 +- clang/lib/Driver/ToolChains/WebAssembly.cpp | 2 +- clang/lib/Driver/ToolChains/XCore.cpp | 2 +- clang/lib/Driver/ToolChains/ZOS.cpp | 2 +- clang/lib/Driver/XRayArgs.cpp | 2 +- .../unittests/Driver/MultilibBuilderTest.cpp | 2 +- clang/unittests/Driver/MultilibTest.cpp | 2 +- flang/lib/Frontend/CompilerInvocation.cpp | 20 + flang/test/Driver/prefer-vector-width.f90 | 2 +- 56 files changed, 96 insertions(+), 89 deletions(-) rename clang/{lib/Driver/ToolChains => include/clang/Driver}/CommonArgs.h (98%) diff --git a/clang/lib/Driver/ToolChains/CommonArgs.h b/clang/include/clang/Driver/CommonArgs.h similarity index 98% rename from clang/lib/Driver/ToolChains/CommonArgs.h rename to clang/include/clang/Dr
[clang] [flang] [llvm] [Driver] Move CommonArgs to a location visible by the Frontend Drivers (PR #142800)
mcinally wrote: > > I had 1 minor objection, see my concern on the `uninitialized` attribute > > removal. > > Would it be simpler just to initialize the variable before use? I assume that > the attribute is present to eliminate compiler warnings about uninitialized > variables being passed by reference. I don't see the use of this anywhere > else in the code base. Does adding that attribute really provide a great deal > of meaningful context? This is looking like a better option. Some CIs don't seem to pick up the macro. I'll do some investigating, but I'm not able to reproduce with my build. https://github.com/llvm/llvm-project/pull/142800 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [mlir] [flang] Add support for -mrecip[=] (PR #143418)
https://github.com/mcinally created https://github.com/llvm/llvm-project/pull/143418 This patch adds support for the -mrecip command line option. The parsing of this options is equivalent to Clang's and it is implemented by setting the "reciprocal-estimates" function attribute. Also move the ParseMRecip(...) function to CommonArgs, so that Flang is able to make use of it as well. >From f4812aacb17aaf535f454c82e4ef29c5c9950a12 Mon Sep 17 00:00:00 2001 From: Cameron McInally Date: Mon, 9 Jun 2025 11:19:36 -0700 Subject: [PATCH] [flang] Add support for -mrecip[=] This patch adds support for the -mrecip command line option. The parsing of this options is equivalent to Clang's and it is implemented by setting the "reciprocal-estimates" function attribute. Also move the ParseMRecip(...) function to CommonArgs, so that Flang is able to make use of it as well. --- clang/include/clang/Driver/CommonArgs.h | 5 + clang/include/clang/Driver/Options.td | 3 +- clang/lib/Driver/ToolChains/Clang.cpp | 143 +- clang/lib/Driver/ToolChains/CommonArgs.cpp| 141 + flang/include/flang/Frontend/CodeGenOptions.h | 3 + .../flang/Optimizer/Transforms/Passes.td | 3 + flang/include/flang/Tools/CrossToolHelpers.h | 3 + flang/lib/Frontend/CompilerInvocation.cpp | 2 + flang/lib/Frontend/FrontendActions.cpp| 1 + flang/lib/Optimizer/Passes/Pipelines.cpp | 3 +- .../lib/Optimizer/Transforms/FunctionAttr.cpp | 4 + flang/test/Driver/mrecip.f90 | 27 mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td | 1 + mlir/lib/Target/LLVMIR/ModuleImport.cpp | 5 + mlir/lib/Target/LLVMIR/ModuleTranslation.cpp | 3 + mlir/test/Target/LLVMIR/Import/mrecip.ll | 9 ++ mlir/test/Target/LLVMIR/mrecip.mlir | 8 + 17 files changed, 222 insertions(+), 142 deletions(-) create mode 100644 flang/test/Driver/mrecip.f90 create mode 100644 mlir/test/Target/LLVMIR/Import/mrecip.ll create mode 100644 mlir/test/Target/LLVMIR/mrecip.mlir diff --git a/clang/include/clang/Driver/CommonArgs.h b/clang/include/clang/Driver/CommonArgs.h index 59b68030a4d65..9d0da81b47bba 100644 --- a/clang/include/clang/Driver/CommonArgs.h +++ b/clang/include/clang/Driver/CommonArgs.h @@ -276,6 +276,11 @@ void handleVectorizeSLPArgs(const llvm::opt::ArgList &Args, StringRef ParseMPreferVectorWidthOption(clang::DiagnosticsEngine &Diags, const llvm::opt::ArgList &Args); +// Parse -mrecip. Return the Value string if well-formed. +// Otherwise, return an empty string and issue a diagnosic message if needed. +StringRef ParseMRecipOption(clang::DiagnosticsEngine &Diags, +const llvm::opt::ArgList &Args); + } // end namespace tools } // end namespace driver } // end namespace clang diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 89c63fb3397d3..3582efd7721b0 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -5474,9 +5474,10 @@ def mno_implicit_float : Flag<["-"], "mno-implicit-float">, Group, HelpText<"Don't generate implicit floating point or vector instructions">; def mimplicit_float : Flag<["-"], "mimplicit-float">, Group; def mrecip : Flag<["-"], "mrecip">, Group, + Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>, HelpText<"Equivalent to '-mrecip=all'">; def mrecip_EQ : CommaJoined<["-"], "mrecip=">, Group, - Visibility<[ClangOption, CC1Option]>, + Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>, HelpText<"Control use of approximate reciprocal and reciprocal square root instructions followed by iterations of " "Newton-Raphson refinement. " " = ( ['!'] ['vec-'] ('rcp'|'sqrt') [('h'|'s'|'d')] [':'] ) | 'all' | 'default' | 'none'">, diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 65f101ddf1d0a..df3edcc3cd6bd 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -125,145 +125,6 @@ forAllAssociatedToolChains(Compilation &C, const JobAction &JA, // } -/// This is a helper function for validating the optional refinement step -/// parameter in reciprocal argument strings. Return false if there is an error -/// parsing the refinement step. Otherwise, return true and set the Position -/// of the refinement step in the input string. -static bool getRefinementStep(StringRef In, const Driver &D, - const Arg &A, size_t &Position) { - const char RefinementStepToken = ':'; - Position = In.find(RefinementStepToken); - if (Position != StringRef::npos) { -StringRef Option = A.getOption().getName(); -StringRef RefStep = In.substr(Position + 1); -// Allow exactly one numeric character for the additional refinement -// step parameter. This is reasonable for all current
[clang] [flang] [mlir] [flang] Add support for -mrecip[=] (PR #143418)
@@ -1549,6 +1549,9 @@ LogicalResult ModuleTranslation::convertOneFunction(LLVMFuncOp func) { if (auto tuneCpu = func.getTuneCpu()) llvmFunc->addFnAttr("tune-cpu", *tuneCpu); + if (auto reciprocalEstimates = func.getReciprocalEstimates()) mcinally wrote: It is `std::optional`: ``` ::std::optional< ::llvm::StringRef > getReciprocalEstimates(); ``` The others that return an optional `StringRef` also use `auto` as well: ``` ::std::optional< ::llvm::StringRef > getTargetCpu(); ``` I'll leave this if no objections. https://github.com/llvm/llvm-project/pull/143418 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [mlir] [flang] Add support for -mrecip[=] (PR #143418)
@@ -2636,6 +2636,11 @@ void ModuleImport::processFunctionAttributes(llvm::Function *func, funcOp.setTargetFeaturesAttr( LLVM::TargetFeaturesAttr::get(context, attr.getValueAsString())); + if (llvm::Attribute attr = func->getFnAttribute("reciprocal-estimates"); + attr.isStringAttribute()) mcinally wrote: The other examples follow this same pattern. Do you feel strongly that they should change? ``` if (llvm::Attribute attr = func->getFnAttribute("tune-cpu"); attr.isStringAttribute()) funcOp.setTuneCpuAttr(StringAttr::get(context, attr.getValueAsString())); if (llvm::Attribute attr = func->getFnAttribute("target-features"); attr.isStringAttribute()) funcOp.setTargetFeaturesAttr( LLVM::TargetFeaturesAttr::get(context, attr.getValueAsString())); if (llvm::Attribute attr = func->getFnAttribute("reciprocal-estimates"); attr.isStringAttribute()) funcOp.setReciprocalEstimatesAttr( StringAttr::get(context, attr.getValueAsString())); ``` https://github.com/llvm/llvm-project/pull/143418 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [mlir] [flang] Add support for -mrecip[=] (PR #143418)
@@ -0,0 +1,9 @@ +; RUN: mlir-translate -import-llvm -split-input-file %s | FileCheck %s + +; CHECK-LABEL: llvm.func @reciprocal_estimates() +; CHECK-SAME: reciprocal_estimates = "all" +define void @reciprocal_estimates() #0 { + ret void +} + +attributes #0 = { "reciprocal-estimates" = "all" } mcinally wrote: That was actually the Frontend test, but I'm updating it now. Thanks! This test should be fine since that's the input IR we're specifying. https://github.com/llvm/llvm-project/pull/143418 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [mlir] [flang] Add support for -mrecip[=] (PR #143418)
https://github.com/mcinally updated https://github.com/llvm/llvm-project/pull/143418 >From f4812aacb17aaf535f454c82e4ef29c5c9950a12 Mon Sep 17 00:00:00 2001 From: Cameron McInally Date: Mon, 9 Jun 2025 11:19:36 -0700 Subject: [PATCH 1/2] [flang] Add support for -mrecip[=] This patch adds support for the -mrecip command line option. The parsing of this options is equivalent to Clang's and it is implemented by setting the "reciprocal-estimates" function attribute. Also move the ParseMRecip(...) function to CommonArgs, so that Flang is able to make use of it as well. --- clang/include/clang/Driver/CommonArgs.h | 5 + clang/include/clang/Driver/Options.td | 3 +- clang/lib/Driver/ToolChains/Clang.cpp | 143 +- clang/lib/Driver/ToolChains/CommonArgs.cpp| 141 + flang/include/flang/Frontend/CodeGenOptions.h | 3 + .../flang/Optimizer/Transforms/Passes.td | 3 + flang/include/flang/Tools/CrossToolHelpers.h | 3 + flang/lib/Frontend/CompilerInvocation.cpp | 2 + flang/lib/Frontend/FrontendActions.cpp| 1 + flang/lib/Optimizer/Passes/Pipelines.cpp | 3 +- .../lib/Optimizer/Transforms/FunctionAttr.cpp | 4 + flang/test/Driver/mrecip.f90 | 27 mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td | 1 + mlir/lib/Target/LLVMIR/ModuleImport.cpp | 5 + mlir/lib/Target/LLVMIR/ModuleTranslation.cpp | 3 + mlir/test/Target/LLVMIR/Import/mrecip.ll | 9 ++ mlir/test/Target/LLVMIR/mrecip.mlir | 8 + 17 files changed, 222 insertions(+), 142 deletions(-) create mode 100644 flang/test/Driver/mrecip.f90 create mode 100644 mlir/test/Target/LLVMIR/Import/mrecip.ll create mode 100644 mlir/test/Target/LLVMIR/mrecip.mlir diff --git a/clang/include/clang/Driver/CommonArgs.h b/clang/include/clang/Driver/CommonArgs.h index 59b68030a4d65..9d0da81b47bba 100644 --- a/clang/include/clang/Driver/CommonArgs.h +++ b/clang/include/clang/Driver/CommonArgs.h @@ -276,6 +276,11 @@ void handleVectorizeSLPArgs(const llvm::opt::ArgList &Args, StringRef ParseMPreferVectorWidthOption(clang::DiagnosticsEngine &Diags, const llvm::opt::ArgList &Args); +// Parse -mrecip. Return the Value string if well-formed. +// Otherwise, return an empty string and issue a diagnosic message if needed. +StringRef ParseMRecipOption(clang::DiagnosticsEngine &Diags, +const llvm::opt::ArgList &Args); + } // end namespace tools } // end namespace driver } // end namespace clang diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 89c63fb3397d3..3582efd7721b0 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -5474,9 +5474,10 @@ def mno_implicit_float : Flag<["-"], "mno-implicit-float">, Group, HelpText<"Don't generate implicit floating point or vector instructions">; def mimplicit_float : Flag<["-"], "mimplicit-float">, Group; def mrecip : Flag<["-"], "mrecip">, Group, + Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>, HelpText<"Equivalent to '-mrecip=all'">; def mrecip_EQ : CommaJoined<["-"], "mrecip=">, Group, - Visibility<[ClangOption, CC1Option]>, + Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>, HelpText<"Control use of approximate reciprocal and reciprocal square root instructions followed by iterations of " "Newton-Raphson refinement. " " = ( ['!'] ['vec-'] ('rcp'|'sqrt') [('h'|'s'|'d')] [':'] ) | 'all' | 'default' | 'none'">, diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 65f101ddf1d0a..df3edcc3cd6bd 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -125,145 +125,6 @@ forAllAssociatedToolChains(Compilation &C, const JobAction &JA, // } -/// This is a helper function for validating the optional refinement step -/// parameter in reciprocal argument strings. Return false if there is an error -/// parsing the refinement step. Otherwise, return true and set the Position -/// of the refinement step in the input string. -static bool getRefinementStep(StringRef In, const Driver &D, - const Arg &A, size_t &Position) { - const char RefinementStepToken = ':'; - Position = In.find(RefinementStepToken); - if (Position != StringRef::npos) { -StringRef Option = A.getOption().getName(); -StringRef RefStep = In.substr(Position + 1); -// Allow exactly one numeric character for the additional refinement -// step parameter. This is reasonable for all currently-supported -// operations and architectures because we would expect that a larger value -// of refinement steps would cause the estimate "optimization" to -// under-perform the native operation. Also, if the estimate does not -// converge quickly, it probably will not ever converg
[clang] [flang] [mlir] [flang] Add support for -mrecip[=] (PR #143418)
mcinally wrote: > Thanks for the changes, Cameron. LGTM. Thanks! Would you mind merging yet again? I still don't have access yet. https://github.com/llvm/llvm-project/pull/143418 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits