Skip to content

Commit f01051d

Browse files
Krzysztof Parzyszektstellar
authored andcommitted
[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. (cherry picked from commit 2ecda9e)
1 parent 61c8cf9 commit f01051d

File tree

2 files changed

+42
-42
lines changed

2 files changed

+42
-42
lines changed

clang/lib/Driver/ToolChains/Hexagon.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,23 +72,25 @@ static void handleHVXTargetFeatures(const Driver &D, const ArgList &Args,
7272
(Cpu.back() == 'T' || Cpu.back() == 't' ? Cpu.drop_back(1) : Cpu).str();
7373
HasHVX = false;
7474

75-
// Handle -mhvx, -mhvx=, -mno-hvx. If both present, -mhvx= wins over -mhvx.
76-
auto argOrNull = [&Args](auto FlagOn, auto FlagOff) -> Arg* {
77-
if (Arg *A = Args.getLastArg(FlagOn, FlagOff)) {
78-
if (A->getOption().matches(FlagOn))
79-
return A;
80-
}
81-
return nullptr;
82-
};
83-
84-
Arg *HvxBareA =
85-
argOrNull(options::OPT_mhexagon_hvx, options::OPT_mno_hexagon_hvx);
86-
Arg *HvxVerA =
87-
argOrNull(options::OPT_mhexagon_hvx_EQ, options::OPT_mno_hexagon_hvx);
75+
// Handle -mhvx, -mhvx=, -mno-hvx. If versioned and versionless flags
76+
// are both present, the last one wins.
77+
Arg *HvxEnablingArg =
78+
Args.getLastArg(options::OPT_mhexagon_hvx, options::OPT_mhexagon_hvx_EQ,
79+
options::OPT_mno_hexagon_hvx);
80+
if (HvxEnablingArg) {
81+
if (HvxEnablingArg->getOption().matches(options::OPT_mno_hexagon_hvx))
82+
HvxEnablingArg = nullptr;
83+
}
8884

89-
if (Arg *A = HvxVerA ? HvxVerA : HvxBareA) {
90-
if (A->getOption().matches(options::OPT_mhexagon_hvx_EQ))
91-
HvxVer = StringRef(A->getValue()).lower(); // lower produces std:string
85+
if (HvxEnablingArg) {
86+
// If -mhvx[=] was given, it takes precedence.
87+
if (Arg *A = Args.getLastArg(options::OPT_mhexagon_hvx,
88+
options::OPT_mhexagon_hvx_EQ)) {
89+
// If the version was given, set HvxVer. Otherwise HvxVer
90+
// will remain equal to the CPU version.
91+
if (A->getOption().matches(options::OPT_mhexagon_hvx_EQ))
92+
HvxVer = StringRef(A->getValue()).lower();
93+
}
9294
HasHVX = true;
9395
Features.push_back(makeFeature(Twine("hvx") + HvxVer, true));
9496
} else if (Arg *A = Args.getLastArg(options::OPT_mno_hexagon_hvx)) {

clang/test/Driver/hexagon-hvx.c

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,23 @@
5454
// RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V68 %s
5555
// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v69 \
5656
// RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V69 %s
57+
// Infer HVX version from CPU version:
58+
// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv60 -mhvx \
59+
// RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V60 %s
60+
// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv62 -mhvx \
61+
// RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V62 %s
62+
// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv65 -mhvx \
63+
// RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V65 %s
64+
// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv66 -mhvx \
65+
// RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V66 %s
66+
// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv67 -mhvx \
67+
// RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V67 %s
68+
// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv67t -mhvx \
69+
// RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V67 %s
70+
// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv68 -mhvx \
71+
// RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V68 %s
72+
// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv69 -mhvx \
73+
// RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V69 %s
5774

5875
// Direct version flag with different CPU version:
5976
// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v60 -mv62 \
@@ -73,19 +90,19 @@
7390

7491
// Direct version flag with different CPU version and versionless -mhvx:
7592
// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v60 -mv62 -mhvx \
76-
// RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V60 %s
77-
// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v62 -mv65 -mhvx \
7893
// RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V62 %s
79-
// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v65 -mv66 -mhvx \
94+
// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v62 -mv65 -mhvx \
8095
// RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V65 %s
81-
// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v66 -mv67 -mhvx \
96+
// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v65 -mv66 -mhvx \
8297
// RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V66 %s
83-
// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v67 -mv68 -mhvx \
98+
// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v66 -mv67 -mhvx \
8499
// RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V67 %s
85-
// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v68 -mv69 -mhvx \
100+
// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v67 -mv68 -mhvx \
86101
// RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V68 %s
87-
// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v69 -mv60 -mhvx \
102+
// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v68 -mv69 -mhvx \
88103
// RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V69 %s
104+
// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v69 -mv60 -mhvx \
105+
// RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V60 %s
89106

90107
// Direct version flag with different CPU version, versionless -mhvx
91108
// and -mno-hvx. The -mno-hvx cancels -mhvx=, versionless -mhvx wins:
@@ -121,25 +138,6 @@
121138
// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv60 -mhvx -mno-hvx -mhvx=v69 \
122139
// RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V69 %s
123140

124-
// Infer HVX version from CPU version:
125-
126-
// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv60 -mhvx \
127-
// RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V60 %s
128-
// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv62 -mhvx \
129-
// RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V62 %s
130-
// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv65 -mhvx \
131-
// RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V65 %s
132-
// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv66 -mhvx \
133-
// RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V66 %s
134-
// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv67 -mhvx \
135-
// RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V67 %s
136-
// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv67t -mhvx \
137-
// RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V67 %s
138-
// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv68 -mhvx \
139-
// RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V68 %s
140-
// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv69 -mhvx \
141-
// RUN: 2>&1 | FileCheck -check-prefix=CHECK-HVX-V69 %s
142-
143141
// Infer HVX length from flag:
144142

145143
// CHECK-HVX-L64: "-target-feature" "+hvx-length64b"

0 commit comments

Comments
 (0)