Author: Krzysztof Parzyszek Date: 2022-02-08T09:06:15-08:00 New Revision: 2ecda9ec9cc89b87ce2e56452229c9444beabf21
URL: https://github.com/llvm/llvm-project/commit/2ecda9ec9cc89b87ce2e56452229c9444beabf21 DIFF: https://github.com/llvm/llvm-project/commit/2ecda9ec9cc89b87ce2e56452229c9444beabf21.diff LOG: [Hexagon] Alter meaning of versionless -mhvx The documentation for the official (downstream) Qualcomm Hexagon Clang states that -mhvx sets the HVX version to be the same as the CPU version. The current implementation upstream would use the most recent versioned -mhvx= flag first (if present), then the CPU version. Change the upstream behavior to match the documented behavior of the downstream compiler. Added: Modified: clang/lib/Driver/ToolChains/Hexagon.cpp clang/test/Driver/hexagon-hvx.c Removed: ################################################################################ diff --git a/clang/lib/Driver/ToolChains/Hexagon.cpp b/clang/lib/Driver/ToolChains/Hexagon.cpp index ba3040636604f..e772122f5ff5e 100644 --- a/clang/lib/Driver/ToolChains/Hexagon.cpp +++ b/clang/lib/Driver/ToolChains/Hexagon.cpp @@ -72,23 +72,25 @@ static void handleHVXTargetFeatures(const Driver &D, const ArgList &Args, (Cpu.back() == 'T' || Cpu.back() == 't' ? Cpu.drop_back(1) : Cpu).str(); HasHVX = false; - // Handle -mhvx, -mhvx=, -mno-hvx. If both present, -mhvx= wins over -mhvx. - auto argOrNull = [&Args](auto FlagOn, auto FlagOff) -> Arg* { - if (Arg *A = Args.getLastArg(FlagOn, FlagOff)) { - if (A->getOption().matches(FlagOn)) - return A; - } - return nullptr; - }; - - Arg *HvxBareA = - argOrNull(options::OPT_mhexagon_hvx, options::OPT_mno_hexagon_hvx); - Arg *HvxVerA = - argOrNull(options::OPT_mhexagon_hvx_EQ, options::OPT_mno_hexagon_hvx); + // Handle -mhvx, -mhvx=, -mno-hvx. If versioned and versionless flags + // are both present, the last one wins. + Arg *HvxEnablingArg = + Args.getLastArg(options::OPT_mhexagon_hvx, options::OPT_mhexagon_hvx_EQ, + options::OPT_mno_hexagon_hvx); + if (HvxEnablingArg) { + if (HvxEnablingArg->getOption().matches(options::OPT_mno_hexagon_hvx)) + HvxEnablingArg = nullptr; + } - if (Arg *A = HvxVerA ? HvxVerA : HvxBareA) { - if (A->getOption().matches(options::OPT_mhexagon_hvx_EQ)) - HvxVer = StringRef(A->getValue()).lower(); // lower produces std:string + if (HvxEnablingArg) { + // If -mhvx[=] was given, it takes precedence. + if (Arg *A = Args.getLastArg(options::OPT_mhexagon_hvx, + options::OPT_mhexagon_hvx_EQ)) { + // If the version was given, set HvxVer. Otherwise HvxVer + // will remain equal to the CPU version. + if (A->getOption().matches(options::OPT_mhexagon_hvx_EQ)) + HvxVer = StringRef(A->getValue()).lower(); + } HasHVX = true; Features.push_back(makeFeature(Twine("hvx") + HvxVer, true)); } else if (Arg *A = Args.getLastArg(options::OPT_mno_hexagon_hvx)) { diff --git a/clang/test/Driver/hexagon-hvx.c b/clang/test/Driver/hexagon-hvx.c index 10bb8fe9327f0..385774824cb0a 100644 --- a/clang/test/Driver/hexagon-hvx.c +++ b/clang/test/Driver/hexagon-hvx.c @@ -54,6 +54,23 @@ // RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V68 %s // RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v69 \ // RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V69 %s +// Infer HVX version from CPU version: +// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv60 -mhvx \ +// RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V60 %s +// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv62 -mhvx \ +// RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V62 %s +// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv65 -mhvx \ +// RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V65 %s +// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv66 -mhvx \ +// RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V66 %s +// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv67 -mhvx \ +// RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V67 %s +// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv67t -mhvx \ +// RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V67 %s +// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv68 -mhvx \ +// RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V68 %s +// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv69 -mhvx \ +// RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V69 %s // Direct version flag with diff erent CPU version: // RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v60 -mv62 \ @@ -73,19 +90,19 @@ // Direct version flag with diff erent CPU version and versionless -mhvx: // RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v60 -mv62 -mhvx \ -// RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V60 %s -// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v62 -mv65 -mhvx \ // RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V62 %s -// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v65 -mv66 -mhvx \ +// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v62 -mv65 -mhvx \ // RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V65 %s -// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v66 -mv67 -mhvx \ +// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v65 -mv66 -mhvx \ // RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V66 %s -// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v67 -mv68 -mhvx \ +// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v66 -mv67 -mhvx \ // RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V67 %s -// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v68 -mv69 -mhvx \ +// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v67 -mv68 -mhvx \ // RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V68 %s -// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v69 -mv60 -mhvx \ +// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v68 -mv69 -mhvx \ // RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V69 %s +// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v69 -mv60 -mhvx \ +// RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V60 %s // Direct version flag with diff erent CPU version, versionless -mhvx // and -mno-hvx. The -mno-hvx cancels -mhvx=, versionless -mhvx wins: @@ -121,25 +138,6 @@ // RUN: %clang -c %s -### -target hexagon-unknown-elf -mv60 -mhvx -mno-hvx -mhvx=v69 \ // RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V69 %s -// Infer HVX version from CPU version: - -// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv60 -mhvx \ -// RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V60 %s -// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv62 -mhvx \ -// RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V62 %s -// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv65 -mhvx \ -// RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V65 %s -// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv66 -mhvx \ -// RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V66 %s -// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv67 -mhvx \ -// RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V67 %s -// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv67t -mhvx \ -// RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V67 %s -// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv68 -mhvx \ -// RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V68 %s -// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv69 -mhvx \ -// RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V69 %s - // Infer HVX length from flag: // CHECK-HVX-L64: "-target-feature" "+hvx-length64b" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits