fhahn created this revision. fhahn added reviewers: aemerson, ab, dmgreen, SjoerdMeijer, scanon. Herald added subscribers: dang, kristof.beyls. fhahn requested review of this revision. Herald added a project: clang.
This patch adds support for `-m[no]fpf16`, ` `-m[no]fpf16fml` and `-m[no]dotprod` feature flags for ARM. The flags behave similar to specifying an -march flag with +/-{fp16,fp16fml,dotprod}, but is more convenient for users that do not want to provide a specific architecture version. There are similar flags alread, like `-mcrc`. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D113779 Files: clang/include/clang/Driver/Options.td clang/lib/Driver/ToolChains/Arch/AArch64.cpp clang/lib/Driver/ToolChains/Arch/ARM.cpp clang/test/Preprocessor/aarch64-target-features.c clang/test/Preprocessor/arm-target-features.c
Index: clang/test/Preprocessor/arm-target-features.c =================================================================== --- clang/test/Preprocessor/arm-target-features.c +++ clang/test/Preprocessor/arm-target-features.c @@ -25,6 +25,7 @@ // CHECK-V8A-ALLOW-FP-INSTR-V8A-NOT: #define __ARM_FEATURE_DOTPROD // RUN: %clang -target arm-none-linux-gnueabi -march=armv8.2-a+nofp16fml+fp16 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s +// RUN: %clang -target arm-none-linux-gnueabi -march=armv8.2-a -mnofp16fml -mfp16 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s // RUN: %clang -target arm-none-linux-gnueabi -march=armv8.2-a+nofp16+fp16fml -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s // RUN: %clang -target arm-none-linux-gnueabi -march=armv8.2-a+fp16+nofp16fml -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s // RUN: %clang -target arm-none-linux-gnueabi -march=armv8-a+fp16fml -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s @@ -77,6 +78,7 @@ // CHECK-FULLFP16-SOFT-NOT: #define __ARM_FEATURE_FP16_VECTOR_ARITHMETIC // RUN: %clang -target arm-none-linux-gnueabi -march=armv8.2a+dotprod -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-DOTPROD %s +// RUN: %clang -target arm-none-linux-gnueabi -march=armv8.2a -mdotprod -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-DOTPROD %s // CHECK-DOTPROD: #define __ARM_FEATURE_DOTPROD 1 // RUN: %clang -target armv8r-none-linux-gnu -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V8R %s Index: clang/test/Preprocessor/aarch64-target-features.c =================================================================== --- clang/test/Preprocessor/aarch64-target-features.c +++ clang/test/Preprocessor/aarch64-target-features.c @@ -199,20 +199,29 @@ // CHECK-SVE2BITPERM: __ARM_FEATURE_SVE2_BITPERM 1 // RUN: %clang -target aarch64-none-linux-gnu -march=armv8.2a+dotprod -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-DOTPROD %s +// RUN: %clang -target aarch64-none-linux-gnu -march=armv8.2a -mdotprod -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-DOTPROD %s // CHECK-DOTPROD: __ARM_FEATURE_DOTPROD 1 // On ARMv8.2-A and above, +fp16fml implies +fp16. // On ARMv8.4-A and above, +fp16 implies +fp16fml. // RUN: %clang -target aarch64-none-linux-gnueabi -march=armv8.2-a+nofp16fml+fp16 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-NOFML --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s +// RUN: %clang -target aarch64-none-linux-gnueabi -march=armv8.2-a -mnofp16fml -mfp16 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-NOFML --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s // RUN: %clang -target aarch64-none-linux-gnueabi -march=armv8.2-a+nofp16+fp16fml -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-FML --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s +// RUN: %clang -target aarch64-none-linux-gnueabi -march=armv8.2-a -mnofp16 -mfp16fml -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-FML --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s // RUN: %clang -target aarch64-none-linux-gnueabi -march=armv8.2-a+fp16+nofp16fml -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-NOFML --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s +// RUN: %clang -target aarch64-none-linux-gnueabi -march=armv8.2-a -mfp16 -mnofp16fml -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-NOFML --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s // RUN: %clang -target aarch64-none-linux-gnueabi -march=armv8-a+fp16fml -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-FML --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s +// RUN: %clang -target aarch64-none-linux-gnueabi -march=armv8-a -mfp16fml -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-FML --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s // RUN: %clang -target aarch64-none-linux-gnueabi -march=armv8-a+fp16 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-NOFML --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s +// RUN: %clang -target aarch64-none-linux-gnueabi -march=armv8-a -mfp16 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-NOFML --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s // RUN: %clang -target aarch64-none-linux-gnueabi -march=armv8.4-a+nofp16fml+fp16 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-FML --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s // RUN: %clang -target aarch64-none-linux-gnueabi -march=armv8.4-a+nofp16+fp16fml -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-FML --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s +// RUN: %clang -target aarch64-none-linux-gnueabi -march=armv8.4-a -mnofp16 -mfp16fml -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-FML --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s // RUN: %clang -target aarch64-none-linux-gnueabi -march=armv8.4-a+fp16+nofp16fml -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-NOFML --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s // RUN: %clang -target aarch64-none-linux-gnueabi -march=armv8.4-a+fp16fml -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-FML --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s +// RUN: %clang -target aarch64-none-linux-gnueabi -march=armv8.4-a -mfp16fml -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-FML --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s // RUN: %clang -target aarch64-none-linux-gnueabi -march=armv8.4-a+fp16 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-FML --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s +// RUN: %clang -target aarch64-none-linux-gnueabi -march=armv8.4-a -mfp16 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-FML --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s // CHECK-FULLFP16-FML: #define __ARM_FEATURE_FP16_FML 1 // CHECK-FULLFP16-NOFML-NOT: #define __ARM_FEATURE_FP16_FML 1 // CHECK-FULLFP16-VECTOR-SCALAR: #define __ARM_FEATURE_FP16_SCALAR_ARITHMETIC 1 Index: clang/lib/Driver/ToolChains/Arch/ARM.cpp =================================================================== --- clang/lib/Driver/ToolChains/Arch/ARM.cpp +++ clang/lib/Driver/ToolChains/Arch/ARM.cpp @@ -638,6 +638,29 @@ Features.push_back("-crc"); } + if (Arg *A = Args.getLastArg(options::OPT_mfp16, options::OPT_mnofp16)) { + if (A->getOption().matches(options::OPT_mfp16)) + Features.push_back("+fullfp16"); + else + Features.push_back("-fullfp16"); + } + + if (Arg *A = + Args.getLastArg(options::OPT_mfp16fml, options::OPT_mnofp16fml)) { + if (A->getOption().matches(options::OPT_mfp16fml)) + Features.push_back("+fp16fml"); + else + Features.push_back("-fp16fml"); + } + + if (Arg *A = + Args.getLastArg(options::OPT_mdotprod, options::OPT_mnodotprod)) { + if (A->getOption().matches(options::OPT_mdotprod)) + Features.push_back("+dotprod"); + else + Features.push_back("-dotprod"); + } + // For Arch >= ARMv8.0 && A or R profile: crypto = sha2 + aes // Rather than replace within the feature vector, determine whether each // algorithm is enabled and append this to the end of the vector. Index: clang/lib/Driver/ToolChains/Arch/AArch64.cpp =================================================================== --- clang/lib/Driver/ToolChains/Arch/AArch64.cpp +++ clang/lib/Driver/ToolChains/Arch/AArch64.cpp @@ -304,6 +304,29 @@ Features.push_back("-crc"); } + if (Arg *A = Args.getLastArg(options::OPT_mfp16, options::OPT_mnofp16)) { + if (A->getOption().matches(options::OPT_mfp16)) + Features.push_back("+fullfp16"); + else + Features.push_back("-fullfp16"); + } + + if (Arg *A = + Args.getLastArg(options::OPT_mfp16fml, options::OPT_mnofp16fml)) { + if (A->getOption().matches(options::OPT_mfp16fml)) + Features.push_back("+fp16fml"); + else + Features.push_back("-fp16fml"); + } + + if (Arg *A = + Args.getLastArg(options::OPT_mdotprod, options::OPT_mnodotprod)) { + if (A->getOption().matches(options::OPT_mdotprod)) + Features.push_back("+dotprod"); + else + Features.push_back("-dotprod"); + } + // Handle (arch-dependent) fp16fml/fullfp16 relationship. // FIXME: this fp16fml option handling will be reimplemented after the // TargetParser rewrite. Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -3308,6 +3308,18 @@ BothFlags<[NoXarchOption, CC1Option], " the AAPCS standard requirement stating that" " volatile bit-field width is dictated by the field container type. (ARM only).">>, Group<m_arm_Features_Group>; +def mfp16: Flag<["-"], "mfp16">, Group<m_arm_Features_Group>, + HelpText<"Allow use of FP16 instructions.">; +def mnofp16: Flag<["-"], "mnofp16">, Group<m_arm_Features_Group>, + HelpText<"Disallow use of FP16 instructions.">; +def mfp16fml: Flag<["-"], "mfp16fml">, Group<m_arm_Features_Group>, + HelpText<"Allow use of FP16 machine learning instructions.">; +def mnofp16fml: Flag<["-"], "mnofp16fml">, Group<m_arm_Features_Group>, + HelpText<"Disallow use of FP16 FML instructions.">; +def mdotprod: Flag<["-"], "mdotprod">, Group<m_arm_Features_Group>, + HelpText<"Allow use of dot product instructions.">; +def mnodotprod: Flag<["-"], "mnodotprod">, Group<m_arm_Features_Group>, + HelpText<"Disallow use of dot product instructions.">; def mgeneral_regs_only : Flag<["-"], "mgeneral-regs-only">, Group<m_Group>, HelpText<"Generate code which only uses the general purpose registers (AArch64/x86 only)">;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits