[llvm] [clang] [X86] Support CFE flags for APX features (PR #74199)

2023-12-04 Thread Shengchen Kan via cfe-commits

https://github.com/KanRobert closed 
https://github.com/llvm/llvm-project/pull/74199
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [X86] Support CFE flags for APX features (PR #74199)

2023-12-04 Thread Shengchen Kan via cfe-commits

KanRobert wrote:

@phoebewang Thanks for the review!

https://github.com/llvm/llvm-project/pull/74199
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [X86] Support CFE flags for APX features (PR #74199)

2023-12-04 Thread Shengchen Kan via cfe-commits

https://github.com/KanRobert updated 
https://github.com/llvm/llvm-project/pull/74199

>From 246d6e2bc3f6fb60623b5d4c3f07b53c628ed88a Mon Sep 17 00:00:00 2001
From: Shengchen Kan 
Date: Sat, 2 Dec 2023 23:52:53 +0800
Subject: [PATCH 1/7] [X86] Support CFE flags for APX features

Positive options: -mapx-features=
Negative options: -mno-apx-features=

-m[no-]apx-features is designed to be able to control separate APX
features.

Besides, we also support the flag -m[no-]apxf, which can be used like an
alias of -m[no-]apx-features=< all APX features covered by CPUID APX_F>

Behaviour when positive and negative options are used together:

For boolean flags, the last one wins

-mapxf   -mno-apxf   -> -mno-apxf
-mno-apxf   -mapxf   -> -mapxf

For flags that take a set as arguments, it sets the mask by order of the
flags

-mapx-features=egpr,ndd  -mno-apx-features=egpr  ->   -egpr,+ndd
-mapx-features=egpr  -mno-apx-features=egpr,ndd  ->   -egpr,-ndd
-mno-apx-features=egpr  -mapx-features=egpr,ndd  ->   +egpr,+ndd
-mno-apx-features=egpr,ndd  -mapx-features=egpr  ->   -ndd,+egpr

The design is aligned with gcc
https://gcc.gnu.org/pipermail/gcc-patches/2023-August/628905.html
---
 clang/include/clang/Driver/Options.td |  6 
 clang/lib/Basic/Targets/X86.cpp   | 34 +++
 clang/lib/Basic/Targets/X86.h |  6 
 clang/lib/Driver/ToolChains/Arch/X86.cpp  | 15 
 clang/test/Driver/apxf-target-features.c  | 25 ++
 .../llvm/TargetParser/X86TargetParser.def |  6 
 llvm/lib/Target/X86/X86.td|  6 
 llvm/lib/TargetParser/X86TargetParser.cpp |  8 +
 8 files changed, 106 insertions(+)
 create mode 100644 clang/test/Driver/apxf-target-features.c

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 19d04e82aed4d..631c5ad1c015d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5999,6 +5999,12 @@ def mno_gather : Flag<["-"], "mno-gather">, 
Group,
  HelpText<"Disable generation of gather instructions in 
auto-vectorization(x86 only)">;
 def mno_scatter : Flag<["-"], "mno-scatter">, Group,
   HelpText<"Disable generation of scatter instructions in 
auto-vectorization(x86 only)">;
+def mapx_features_EQ : CommaJoined<["-"], "mapx-features=">, 
Group,
+HelpText<"Enable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,cf">;
+def mno_apx_features_EQ : CommaJoined<["-"], "mno-apx-features=">, 
Group,
+HelpText<"Disable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,cf">;
+def mapxf : Flag<["-"], "mapxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx","ndd","ccmp","cf"]>;
+def mno_apxf : Flag<["-"], "mno-apxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx","ndd","ccmp","cf"]>;
 } // let Flags = [TargetSpecific]
 
 // VE feature flags
diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index 85d0697ad63ca..9392211aa6fdf 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -428,6 +428,18 @@ bool 
X86TargetInfo::handleTargetFeatures(std::vector ,
   HasX87 = true;
 } else if (Feature == "+fullbf16") {
   HasFullBFloat16 = true;
+} else if (Feature == "+egpr") {
+  HasEGPR = true;
+} else if (Feature == "+push2pop2") {
+  HasPush2Pop2 = true;
+} else if (Feature == "+ppx") {
+  HasPPX = true;
+} else if (Feature == "+ndd") {
+  HasNDD = true;
+} else if (Feature == "+ccmp") {
+  HasCCMP = true;
+} else if (Feature == "+cf") {
+  HasCF = true;
 }
 
 X86SSEEnum Level = llvm::StringSwitch(Feature)
@@ -927,6 +939,16 @@ void X86TargetInfo::getTargetDefines(const LangOptions 
,
 Builder.defineMacro("__USERMSR__");
   if (HasCRC32)
 Builder.defineMacro("__CRC32__");
+  if (HasEGPR)
+Builder.defineMacro("__EGPR__");
+  if (HasPush2Pop2)
+Builder.defineMacro("__PUSH2POP2__");
+  if (HasNDD)
+Builder.defineMacro("__NDD__");
+  if (HasCCMP)
+Builder.defineMacro("__CCMP__");
+  if (HasCF)
+Builder.defineMacro("__CF__");
 
   // Each case falls through to the previous one here.
   switch (SSELevel) {
@@ -1122,6 +1144,12 @@ bool X86TargetInfo::isValidFeatureName(StringRef Name) 
const {
   .Case("xsavec", true)
   .Case("xsaves", true)
   .Case("xsaveopt", true)
+  .Case("egpr", true)
+  .Case("push2pop2", true)
+  .Case("ppx", true)
+  .Case("ndd", true)
+  .Case("ccmp", true)
+  .Case("cf", true)
   .Default(false);
 }
 
@@ -1238,6 +1266,12 @@ bool X86TargetInfo::hasFeature(StringRef Feature) const {
   .Case("xsaves", HasXSAVES)
   .Case("xsaveopt", HasXSAVEOPT)
   .Case("fullbf16", HasFullBFloat16)
+  .Case("egpr", HasEGPR)
+  .Case("push2pop2", HasPush2Pop2)
+  .Case("ppx", HasPPX)
+  .Case("ndd", HasNDD)
+  .Case("ccmp", HasCCMP)
+  .Case("cf", HasCF)
   

[llvm] [clang] [X86] Support CFE flags for APX features (PR #74199)

2023-12-04 Thread Shengchen Kan via cfe-commits

https://github.com/KanRobert edited 
https://github.com/llvm/llvm-project/pull/74199
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [X86] Support CFE flags for APX features (PR #74199)

2023-12-04 Thread Shengchen Kan via cfe-commits


@@ -422,3 +422,28 @@
 
 // RUN: touch %t.o
 // RUN: %clang -fdriver-only -Werror --target=x86_64-pc-linux-gnu 
-mharden-sls=all %t.o -o /dev/null 2>&1 | count 0
+// RUN: %clang -target x86_64-unknown-linux-gnu -mapxf %s -### -o %t.o 2>&1 | 
FileCheck -check-prefix=APXF %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -mno-apxf %s -### -o %t.o 2>&1 
| FileCheck -check-prefix=NO-APXF %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -mno-apxf -mapxf %s -### -o 
%t.o 2>&1 | FileCheck -check-prefix=APXF %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -mapxf -mno-apxf %s -### -o 
%t.o 2>&1 | FileCheck -check-prefix=NO-APXF %s
+//
+// APXF: "-target-feature" "+egpr" "-target-feature" "+push2pop2" 
"-target-feature" "+ppx"
+// NO-APXF: "-target-feature" "-egpr" "-target-feature" "-push2pop2" 
"-target-feature" "-ppx"
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -mapx-features=egpr,ndd %s 
-### -o %t.o 2>&1 | FileCheck -check-prefix=EGPR-NDD %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -mapx-features=egpr 
-mapx-features=ndd %s -### -o %t.o 2>&1 | FileCheck -check-prefix=EGPR-NDD %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -mno-apx-features=egpr 
-mno-apx-features=ndd %s -### -o %t.o 2>&1 | FileCheck 
-check-prefix=NO-EGPR-NO-NDD %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -mno-apx-features=egpr 
-mapx-features=egpr,ndd %s -### -o %t.o 2>&1 | FileCheck -check-prefix=EGPR-NDD 
%s
+// RUN: %clang -target x86_64-unknown-linux-gnu -mno-apx-features=egpr,ndd 
-mapx-features=egpr %s -### -o %t.o 2>&1 | FileCheck -check-prefix=EGPR-NO-NDD 
%s
+// RUN: %clang -target x86_64-unknown-linux-gnu -mapx-features=egpr,ndd 
-mno-apx-features=egpr %s -### -o %t.o 2>&1 | FileCheck 
-check-prefix=NO-EGPR-NDD %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -mapx-features=egpr 
-mno-apx-features=egpr,ndd %s -### -o %t.o 2>&1 | FileCheck 
-check-prefix=NO-EGPR-NO-NDD %s
+//
+// EGPR-NDD: "-target-feature" "+egpr" "-target-feature" "+ndd"
+// EGPR-NO-NDD: "-target-feature" "-ndd" "-target-feature" "+egpr"
+// NO-EGPR-NDD: "-target-feature" "+ndd" "-target-feature" "-egpr"
+// NO-EGPR-NO-NDD: "-target-feature" "-egpr" "-target-feature" "-ndd"
+

KanRobert wrote:

Done

https://github.com/llvm/llvm-project/pull/74199
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [X86] Support CFE flags for APX features (PR #74199)

2023-12-04 Thread Shengchen Kan via cfe-commits

https://github.com/KanRobert updated 
https://github.com/llvm/llvm-project/pull/74199

>From 246d6e2bc3f6fb60623b5d4c3f07b53c628ed88a Mon Sep 17 00:00:00 2001
From: Shengchen Kan 
Date: Sat, 2 Dec 2023 23:52:53 +0800
Subject: [PATCH 1/6] [X86] Support CFE flags for APX features

Positive options: -mapx-features=
Negative options: -mno-apx-features=

-m[no-]apx-features is designed to be able to control separate APX
features.

Besides, we also support the flag -m[no-]apxf, which can be used like an
alias of -m[no-]apx-features=< all APX features covered by CPUID APX_F>

Behaviour when positive and negative options are used together:

For boolean flags, the last one wins

-mapxf   -mno-apxf   -> -mno-apxf
-mno-apxf   -mapxf   -> -mapxf

For flags that take a set as arguments, it sets the mask by order of the
flags

-mapx-features=egpr,ndd  -mno-apx-features=egpr  ->   -egpr,+ndd
-mapx-features=egpr  -mno-apx-features=egpr,ndd  ->   -egpr,-ndd
-mno-apx-features=egpr  -mapx-features=egpr,ndd  ->   +egpr,+ndd
-mno-apx-features=egpr,ndd  -mapx-features=egpr  ->   -ndd,+egpr

The design is aligned with gcc
https://gcc.gnu.org/pipermail/gcc-patches/2023-August/628905.html
---
 clang/include/clang/Driver/Options.td |  6 
 clang/lib/Basic/Targets/X86.cpp   | 34 +++
 clang/lib/Basic/Targets/X86.h |  6 
 clang/lib/Driver/ToolChains/Arch/X86.cpp  | 15 
 clang/test/Driver/apxf-target-features.c  | 25 ++
 .../llvm/TargetParser/X86TargetParser.def |  6 
 llvm/lib/Target/X86/X86.td|  6 
 llvm/lib/TargetParser/X86TargetParser.cpp |  8 +
 8 files changed, 106 insertions(+)
 create mode 100644 clang/test/Driver/apxf-target-features.c

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 19d04e82aed4d..631c5ad1c015d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5999,6 +5999,12 @@ def mno_gather : Flag<["-"], "mno-gather">, 
Group,
  HelpText<"Disable generation of gather instructions in 
auto-vectorization(x86 only)">;
 def mno_scatter : Flag<["-"], "mno-scatter">, Group,
   HelpText<"Disable generation of scatter instructions in 
auto-vectorization(x86 only)">;
+def mapx_features_EQ : CommaJoined<["-"], "mapx-features=">, 
Group,
+HelpText<"Enable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,cf">;
+def mno_apx_features_EQ : CommaJoined<["-"], "mno-apx-features=">, 
Group,
+HelpText<"Disable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,cf">;
+def mapxf : Flag<["-"], "mapxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx","ndd","ccmp","cf"]>;
+def mno_apxf : Flag<["-"], "mno-apxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx","ndd","ccmp","cf"]>;
 } // let Flags = [TargetSpecific]
 
 // VE feature flags
diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index 85d0697ad63ca..9392211aa6fdf 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -428,6 +428,18 @@ bool 
X86TargetInfo::handleTargetFeatures(std::vector ,
   HasX87 = true;
 } else if (Feature == "+fullbf16") {
   HasFullBFloat16 = true;
+} else if (Feature == "+egpr") {
+  HasEGPR = true;
+} else if (Feature == "+push2pop2") {
+  HasPush2Pop2 = true;
+} else if (Feature == "+ppx") {
+  HasPPX = true;
+} else if (Feature == "+ndd") {
+  HasNDD = true;
+} else if (Feature == "+ccmp") {
+  HasCCMP = true;
+} else if (Feature == "+cf") {
+  HasCF = true;
 }
 
 X86SSEEnum Level = llvm::StringSwitch(Feature)
@@ -927,6 +939,16 @@ void X86TargetInfo::getTargetDefines(const LangOptions 
,
 Builder.defineMacro("__USERMSR__");
   if (HasCRC32)
 Builder.defineMacro("__CRC32__");
+  if (HasEGPR)
+Builder.defineMacro("__EGPR__");
+  if (HasPush2Pop2)
+Builder.defineMacro("__PUSH2POP2__");
+  if (HasNDD)
+Builder.defineMacro("__NDD__");
+  if (HasCCMP)
+Builder.defineMacro("__CCMP__");
+  if (HasCF)
+Builder.defineMacro("__CF__");
 
   // Each case falls through to the previous one here.
   switch (SSELevel) {
@@ -1122,6 +1144,12 @@ bool X86TargetInfo::isValidFeatureName(StringRef Name) 
const {
   .Case("xsavec", true)
   .Case("xsaves", true)
   .Case("xsaveopt", true)
+  .Case("egpr", true)
+  .Case("push2pop2", true)
+  .Case("ppx", true)
+  .Case("ndd", true)
+  .Case("ccmp", true)
+  .Case("cf", true)
   .Default(false);
 }
 
@@ -1238,6 +1266,12 @@ bool X86TargetInfo::hasFeature(StringRef Feature) const {
   .Case("xsaves", HasXSAVES)
   .Case("xsaveopt", HasXSAVEOPT)
   .Case("fullbf16", HasFullBFloat16)
+  .Case("egpr", HasEGPR)
+  .Case("push2pop2", HasPush2Pop2)
+  .Case("ppx", HasPPX)
+  .Case("ndd", HasNDD)
+  .Case("ccmp", HasCCMP)
+  .Case("cf", HasCF)
   

[llvm] [clang] [X86] Support CFE flags for APX features (PR #74199)

2023-12-03 Thread Shengchen Kan via cfe-commits

https://github.com/KanRobert updated 
https://github.com/llvm/llvm-project/pull/74199

>From 246d6e2bc3f6fb60623b5d4c3f07b53c628ed88a Mon Sep 17 00:00:00 2001
From: Shengchen Kan 
Date: Sat, 2 Dec 2023 23:52:53 +0800
Subject: [PATCH 1/5] [X86] Support CFE flags for APX features

Positive options: -mapx-features=
Negative options: -mno-apx-features=

-m[no-]apx-features is designed to be able to control separate APX
features.

Besides, we also support the flag -m[no-]apxf, which can be used like an
alias of -m[no-]apx-features=< all APX features covered by CPUID APX_F>

Behaviour when positive and negative options are used together:

For boolean flags, the last one wins

-mapxf   -mno-apxf   -> -mno-apxf
-mno-apxf   -mapxf   -> -mapxf

For flags that take a set as arguments, it sets the mask by order of the
flags

-mapx-features=egpr,ndd  -mno-apx-features=egpr  ->   -egpr,+ndd
-mapx-features=egpr  -mno-apx-features=egpr,ndd  ->   -egpr,-ndd
-mno-apx-features=egpr  -mapx-features=egpr,ndd  ->   +egpr,+ndd
-mno-apx-features=egpr,ndd  -mapx-features=egpr  ->   -ndd,+egpr

The design is aligned with gcc
https://gcc.gnu.org/pipermail/gcc-patches/2023-August/628905.html
---
 clang/include/clang/Driver/Options.td |  6 
 clang/lib/Basic/Targets/X86.cpp   | 34 +++
 clang/lib/Basic/Targets/X86.h |  6 
 clang/lib/Driver/ToolChains/Arch/X86.cpp  | 15 
 clang/test/Driver/apxf-target-features.c  | 25 ++
 .../llvm/TargetParser/X86TargetParser.def |  6 
 llvm/lib/Target/X86/X86.td|  6 
 llvm/lib/TargetParser/X86TargetParser.cpp |  8 +
 8 files changed, 106 insertions(+)
 create mode 100644 clang/test/Driver/apxf-target-features.c

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 19d04e82aed4d..631c5ad1c015d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5999,6 +5999,12 @@ def mno_gather : Flag<["-"], "mno-gather">, 
Group,
  HelpText<"Disable generation of gather instructions in 
auto-vectorization(x86 only)">;
 def mno_scatter : Flag<["-"], "mno-scatter">, Group,
   HelpText<"Disable generation of scatter instructions in 
auto-vectorization(x86 only)">;
+def mapx_features_EQ : CommaJoined<["-"], "mapx-features=">, 
Group,
+HelpText<"Enable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,cf">;
+def mno_apx_features_EQ : CommaJoined<["-"], "mno-apx-features=">, 
Group,
+HelpText<"Disable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,cf">;
+def mapxf : Flag<["-"], "mapxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx","ndd","ccmp","cf"]>;
+def mno_apxf : Flag<["-"], "mno-apxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx","ndd","ccmp","cf"]>;
 } // let Flags = [TargetSpecific]
 
 // VE feature flags
diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index 85d0697ad63ca..9392211aa6fdf 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -428,6 +428,18 @@ bool 
X86TargetInfo::handleTargetFeatures(std::vector ,
   HasX87 = true;
 } else if (Feature == "+fullbf16") {
   HasFullBFloat16 = true;
+} else if (Feature == "+egpr") {
+  HasEGPR = true;
+} else if (Feature == "+push2pop2") {
+  HasPush2Pop2 = true;
+} else if (Feature == "+ppx") {
+  HasPPX = true;
+} else if (Feature == "+ndd") {
+  HasNDD = true;
+} else if (Feature == "+ccmp") {
+  HasCCMP = true;
+} else if (Feature == "+cf") {
+  HasCF = true;
 }
 
 X86SSEEnum Level = llvm::StringSwitch(Feature)
@@ -927,6 +939,16 @@ void X86TargetInfo::getTargetDefines(const LangOptions 
,
 Builder.defineMacro("__USERMSR__");
   if (HasCRC32)
 Builder.defineMacro("__CRC32__");
+  if (HasEGPR)
+Builder.defineMacro("__EGPR__");
+  if (HasPush2Pop2)
+Builder.defineMacro("__PUSH2POP2__");
+  if (HasNDD)
+Builder.defineMacro("__NDD__");
+  if (HasCCMP)
+Builder.defineMacro("__CCMP__");
+  if (HasCF)
+Builder.defineMacro("__CF__");
 
   // Each case falls through to the previous one here.
   switch (SSELevel) {
@@ -1122,6 +1144,12 @@ bool X86TargetInfo::isValidFeatureName(StringRef Name) 
const {
   .Case("xsavec", true)
   .Case("xsaves", true)
   .Case("xsaveopt", true)
+  .Case("egpr", true)
+  .Case("push2pop2", true)
+  .Case("ppx", true)
+  .Case("ndd", true)
+  .Case("ccmp", true)
+  .Case("cf", true)
   .Default(false);
 }
 
@@ -1238,6 +1266,12 @@ bool X86TargetInfo::hasFeature(StringRef Feature) const {
   .Case("xsaves", HasXSAVES)
   .Case("xsaveopt", HasXSAVEOPT)
   .Case("fullbf16", HasFullBFloat16)
+  .Case("egpr", HasEGPR)
+  .Case("push2pop2", HasPush2Pop2)
+  .Case("ppx", HasPPX)
+  .Case("ndd", HasNDD)
+  .Case("ccmp", HasCCMP)
+  .Case("cf", HasCF)
   

[llvm] [clang] [X86] Support CFE flags for APX features (PR #74199)

2023-12-03 Thread Shengchen Kan via cfe-commits


@@ -927,6 +939,16 @@ void X86TargetInfo::getTargetDefines(const LangOptions 
,
 Builder.defineMacro("__USERMSR__");
   if (HasCRC32)
 Builder.defineMacro("__CRC32__");
+  if (HasEGPR)
+Builder.defineMacro("__EGPR__");
+  if (HasPush2Pop2)
+Builder.defineMacro("__PUSH2POP2__");
+  if (HasNDD)

KanRobert wrote:

Yes, done.

https://github.com/llvm/llvm-project/pull/74199
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [X86] Support CFE flags for APX features (PR #74199)

2023-12-03 Thread Phoebe Wang via cfe-commits


@@ -5999,6 +5999,12 @@ def mno_gather : Flag<["-"], "mno-gather">, 
Group,
  HelpText<"Disable generation of gather instructions in 
auto-vectorization(x86 only)">;
 def mno_scatter : Flag<["-"], "mno-scatter">, Group,
   HelpText<"Disable generation of scatter instructions in 
auto-vectorization(x86 only)">;
+def mapx_features_EQ : CommaJoined<["-"], "mapx-features=">, 
Group,
+HelpText<"Enable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,cf">;
+def mno_apx_features_EQ : CommaJoined<["-"], "mno-apx-features=">, 
Group,
+HelpText<"Disable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,cf">;
+def mapxf : Flag<["-"], "mapxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx"]>;
+def mno_apxf : Flag<["-"], "mno-apxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx"]>;

phoebewang wrote:

You should comment in code for record not commit message.

https://github.com/llvm/llvm-project/pull/74199
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [X86] Support CFE flags for APX features (PR #74199)

2023-12-03 Thread Shengchen Kan via cfe-commits

https://github.com/KanRobert updated 
https://github.com/llvm/llvm-project/pull/74199

>From 246d6e2bc3f6fb60623b5d4c3f07b53c628ed88a Mon Sep 17 00:00:00 2001
From: Shengchen Kan 
Date: Sat, 2 Dec 2023 23:52:53 +0800
Subject: [PATCH 1/4] [X86] Support CFE flags for APX features

Positive options: -mapx-features=
Negative options: -mno-apx-features=

-m[no-]apx-features is designed to be able to control separate APX
features.

Besides, we also support the flag -m[no-]apxf, which can be used like an
alias of -m[no-]apx-features=< all APX features covered by CPUID APX_F>

Behaviour when positive and negative options are used together:

For boolean flags, the last one wins

-mapxf   -mno-apxf   -> -mno-apxf
-mno-apxf   -mapxf   -> -mapxf

For flags that take a set as arguments, it sets the mask by order of the
flags

-mapx-features=egpr,ndd  -mno-apx-features=egpr  ->   -egpr,+ndd
-mapx-features=egpr  -mno-apx-features=egpr,ndd  ->   -egpr,-ndd
-mno-apx-features=egpr  -mapx-features=egpr,ndd  ->   +egpr,+ndd
-mno-apx-features=egpr,ndd  -mapx-features=egpr  ->   -ndd,+egpr

The design is aligned with gcc
https://gcc.gnu.org/pipermail/gcc-patches/2023-August/628905.html
---
 clang/include/clang/Driver/Options.td |  6 
 clang/lib/Basic/Targets/X86.cpp   | 34 +++
 clang/lib/Basic/Targets/X86.h |  6 
 clang/lib/Driver/ToolChains/Arch/X86.cpp  | 15 
 clang/test/Driver/apxf-target-features.c  | 25 ++
 .../llvm/TargetParser/X86TargetParser.def |  6 
 llvm/lib/Target/X86/X86.td|  6 
 llvm/lib/TargetParser/X86TargetParser.cpp |  8 +
 8 files changed, 106 insertions(+)
 create mode 100644 clang/test/Driver/apxf-target-features.c

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 19d04e82aed4d..631c5ad1c015d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5999,6 +5999,12 @@ def mno_gather : Flag<["-"], "mno-gather">, 
Group,
  HelpText<"Disable generation of gather instructions in 
auto-vectorization(x86 only)">;
 def mno_scatter : Flag<["-"], "mno-scatter">, Group,
   HelpText<"Disable generation of scatter instructions in 
auto-vectorization(x86 only)">;
+def mapx_features_EQ : CommaJoined<["-"], "mapx-features=">, 
Group,
+HelpText<"Enable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,cf">;
+def mno_apx_features_EQ : CommaJoined<["-"], "mno-apx-features=">, 
Group,
+HelpText<"Disable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,cf">;
+def mapxf : Flag<["-"], "mapxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx","ndd","ccmp","cf"]>;
+def mno_apxf : Flag<["-"], "mno-apxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx","ndd","ccmp","cf"]>;
 } // let Flags = [TargetSpecific]
 
 // VE feature flags
diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index 85d0697ad63ca..9392211aa6fdf 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -428,6 +428,18 @@ bool 
X86TargetInfo::handleTargetFeatures(std::vector ,
   HasX87 = true;
 } else if (Feature == "+fullbf16") {
   HasFullBFloat16 = true;
+} else if (Feature == "+egpr") {
+  HasEGPR = true;
+} else if (Feature == "+push2pop2") {
+  HasPush2Pop2 = true;
+} else if (Feature == "+ppx") {
+  HasPPX = true;
+} else if (Feature == "+ndd") {
+  HasNDD = true;
+} else if (Feature == "+ccmp") {
+  HasCCMP = true;
+} else if (Feature == "+cf") {
+  HasCF = true;
 }
 
 X86SSEEnum Level = llvm::StringSwitch(Feature)
@@ -927,6 +939,16 @@ void X86TargetInfo::getTargetDefines(const LangOptions 
,
 Builder.defineMacro("__USERMSR__");
   if (HasCRC32)
 Builder.defineMacro("__CRC32__");
+  if (HasEGPR)
+Builder.defineMacro("__EGPR__");
+  if (HasPush2Pop2)
+Builder.defineMacro("__PUSH2POP2__");
+  if (HasNDD)
+Builder.defineMacro("__NDD__");
+  if (HasCCMP)
+Builder.defineMacro("__CCMP__");
+  if (HasCF)
+Builder.defineMacro("__CF__");
 
   // Each case falls through to the previous one here.
   switch (SSELevel) {
@@ -1122,6 +1144,12 @@ bool X86TargetInfo::isValidFeatureName(StringRef Name) 
const {
   .Case("xsavec", true)
   .Case("xsaves", true)
   .Case("xsaveopt", true)
+  .Case("egpr", true)
+  .Case("push2pop2", true)
+  .Case("ppx", true)
+  .Case("ndd", true)
+  .Case("ccmp", true)
+  .Case("cf", true)
   .Default(false);
 }
 
@@ -1238,6 +1266,12 @@ bool X86TargetInfo::hasFeature(StringRef Feature) const {
   .Case("xsaves", HasXSAVES)
   .Case("xsaveopt", HasXSAVEOPT)
   .Case("fullbf16", HasFullBFloat16)
+  .Case("egpr", HasEGPR)
+  .Case("push2pop2", HasPush2Pop2)
+  .Case("ppx", HasPPX)
+  .Case("ndd", HasNDD)
+  .Case("ccmp", HasCCMP)
+  .Case("cf", HasCF)
   

[llvm] [clang] [X86] Support CFE flags for APX features (PR #74199)

2023-12-03 Thread Phoebe Wang via cfe-commits


@@ -422,3 +422,28 @@
 
 // RUN: touch %t.o
 // RUN: %clang -fdriver-only -Werror --target=x86_64-pc-linux-gnu 
-mharden-sls=all %t.o -o /dev/null 2>&1 | count 0
+// RUN: %clang -target x86_64-unknown-linux-gnu -mapxf %s -### -o %t.o 2>&1 | 
FileCheck -check-prefix=APXF %s

phoebewang wrote:

Missing tests for macro defines

https://github.com/llvm/llvm-project/pull/74199
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [X86] Support CFE flags for APX features (PR #74199)

2023-12-03 Thread Phoebe Wang via cfe-commits


@@ -422,3 +422,28 @@
 
 // RUN: touch %t.o
 // RUN: %clang -fdriver-only -Werror --target=x86_64-pc-linux-gnu 
-mharden-sls=all %t.o -o /dev/null 2>&1 | count 0
+// RUN: %clang -target x86_64-unknown-linux-gnu -mapxf %s -### -o %t.o 2>&1 | 
FileCheck -check-prefix=APXF %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -mno-apxf %s -### -o %t.o 2>&1 
| FileCheck -check-prefix=NO-APXF %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -mno-apxf -mapxf %s -### -o 
%t.o 2>&1 | FileCheck -check-prefix=APXF %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -mapxf -mno-apxf %s -### -o 
%t.o 2>&1 | FileCheck -check-prefix=NO-APXF %s
+//
+// APXF: "-target-feature" "+egpr" "-target-feature" "+push2pop2" 
"-target-feature" "+ppx"
+// NO-APXF: "-target-feature" "-egpr" "-target-feature" "-push2pop2" 
"-target-feature" "-ppx"
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -mapx-features=egpr,ndd %s 
-### -o %t.o 2>&1 | FileCheck -check-prefix=EGPR-NDD %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -mapx-features=egpr 
-mapx-features=ndd %s -### -o %t.o 2>&1 | FileCheck -check-prefix=EGPR-NDD %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -mno-apx-features=egpr 
-mno-apx-features=ndd %s -### -o %t.o 2>&1 | FileCheck 
-check-prefix=NO-EGPR-NO-NDD %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -mno-apx-features=egpr 
-mapx-features=egpr,ndd %s -### -o %t.o 2>&1 | FileCheck -check-prefix=EGPR-NDD 
%s
+// RUN: %clang -target x86_64-unknown-linux-gnu -mno-apx-features=egpr,ndd 
-mapx-features=egpr %s -### -o %t.o 2>&1 | FileCheck -check-prefix=EGPR-NO-NDD 
%s
+// RUN: %clang -target x86_64-unknown-linux-gnu -mapx-features=egpr,ndd 
-mno-apx-features=egpr %s -### -o %t.o 2>&1 | FileCheck 
-check-prefix=NO-EGPR-NDD %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -mapx-features=egpr 
-mno-apx-features=egpr,ndd %s -### -o %t.o 2>&1 | FileCheck 
-check-prefix=NO-EGPR-NO-NDD %s
+//
+// EGPR-NDD: "-target-feature" "+egpr" "-target-feature" "+ndd"
+// EGPR-NO-NDD: "-target-feature" "-ndd" "-target-feature" "+egpr"
+// NO-EGPR-NDD: "-target-feature" "+ndd" "-target-feature" "-egpr"
+// NO-EGPR-NO-NDD: "-target-feature" "-egpr" "-target-feature" "-ndd"
+

phoebewang wrote:

Missing tests for "push2pop2", "ppx", "ccmp" and "cf"

https://github.com/llvm/llvm-project/pull/74199
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [X86] Support CFE flags for APX features (PR #74199)

2023-12-03 Thread Shengchen Kan via cfe-commits


@@ -5999,6 +5999,12 @@ def mno_gather : Flag<["-"], "mno-gather">, 
Group,
  HelpText<"Disable generation of gather instructions in 
auto-vectorization(x86 only)">;
 def mno_scatter : Flag<["-"], "mno-scatter">, Group,
   HelpText<"Disable generation of scatter instructions in 
auto-vectorization(x86 only)">;
+def mapx_features_EQ : CommaJoined<["-"], "mapx-features=">, 
Group,
+HelpText<"Enable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,cf">;
+def mno_apx_features_EQ : CommaJoined<["-"], "mno-apx-features=">, 
Group,
+HelpText<"Disable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,cf">;
+def mapxf : Flag<["-"], "mapxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx"]>;
+def mno_apxf : Flag<["-"], "mno-apxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx"]>;

KanRobert wrote:

Explained in the description.

https://github.com/llvm/llvm-project/pull/74199
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [X86] Support CFE flags for APX features (PR #74199)

2023-12-03 Thread Shengchen Kan via cfe-commits

https://github.com/KanRobert edited 
https://github.com/llvm/llvm-project/pull/74199
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [X86] Support CFE flags for APX features (PR #74199)

2023-12-03 Thread Phoebe Wang via cfe-commits


@@ -927,6 +939,16 @@ void X86TargetInfo::getTargetDefines(const LangOptions 
,
 Builder.defineMacro("__USERMSR__");
   if (HasCRC32)
 Builder.defineMacro("__CRC32__");
+  if (HasEGPR)
+Builder.defineMacro("__EGPR__");
+  if (HasPush2Pop2)
+Builder.defineMacro("__PUSH2POP2__");
+  if (HasNDD)

phoebewang wrote:

Missing PPX?

https://github.com/llvm/llvm-project/pull/74199
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [X86] Support CFE flags for APX features (PR #74199)

2023-12-03 Thread Phoebe Wang via cfe-commits


@@ -5999,6 +5999,12 @@ def mno_gather : Flag<["-"], "mno-gather">, 
Group,
  HelpText<"Disable generation of gather instructions in 
auto-vectorization(x86 only)">;
 def mno_scatter : Flag<["-"], "mno-scatter">, Group,
   HelpText<"Disable generation of scatter instructions in 
auto-vectorization(x86 only)">;
+def mapx_features_EQ : CommaJoined<["-"], "mapx-features=">, 
Group,
+HelpText<"Enable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,cf">;
+def mno_apx_features_EQ : CommaJoined<["-"], "mno-apx-features=">, 
Group,
+HelpText<"Disable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,cf">;
+def mapxf : Flag<["-"], "mapxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx"]>;
+def mno_apxf : Flag<["-"], "mno-apxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx"]>;

phoebewang wrote:

The commit message mentions `alias of -m[no-]apx-features=< all APX features 
covered by CPUID APX_F>`, why only 3 here?

https://github.com/llvm/llvm-project/pull/74199
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [X86] Support CFE flags for APX features (PR #74199)

2023-12-03 Thread Shengchen Kan via cfe-commits

https://github.com/KanRobert updated 
https://github.com/llvm/llvm-project/pull/74199

>From 246d6e2bc3f6fb60623b5d4c3f07b53c628ed88a Mon Sep 17 00:00:00 2001
From: Shengchen Kan 
Date: Sat, 2 Dec 2023 23:52:53 +0800
Subject: [PATCH 1/3] [X86] Support CFE flags for APX features

Positive options: -mapx-features=
Negative options: -mno-apx-features=

-m[no-]apx-features is designed to be able to control separate APX
features.

Besides, we also support the flag -m[no-]apxf, which can be used like an
alias of -m[no-]apx-features=< all APX features covered by CPUID APX_F>

Behaviour when positive and negative options are used together:

For boolean flags, the last one wins

-mapxf   -mno-apxf   -> -mno-apxf
-mno-apxf   -mapxf   -> -mapxf

For flags that take a set as arguments, it sets the mask by order of the
flags

-mapx-features=egpr,ndd  -mno-apx-features=egpr  ->   -egpr,+ndd
-mapx-features=egpr  -mno-apx-features=egpr,ndd  ->   -egpr,-ndd
-mno-apx-features=egpr  -mapx-features=egpr,ndd  ->   +egpr,+ndd
-mno-apx-features=egpr,ndd  -mapx-features=egpr  ->   -ndd,+egpr

The design is aligned with gcc
https://gcc.gnu.org/pipermail/gcc-patches/2023-August/628905.html
---
 clang/include/clang/Driver/Options.td |  6 
 clang/lib/Basic/Targets/X86.cpp   | 34 +++
 clang/lib/Basic/Targets/X86.h |  6 
 clang/lib/Driver/ToolChains/Arch/X86.cpp  | 15 
 clang/test/Driver/apxf-target-features.c  | 25 ++
 .../llvm/TargetParser/X86TargetParser.def |  6 
 llvm/lib/Target/X86/X86.td|  6 
 llvm/lib/TargetParser/X86TargetParser.cpp |  8 +
 8 files changed, 106 insertions(+)
 create mode 100644 clang/test/Driver/apxf-target-features.c

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 19d04e82aed4d..631c5ad1c015d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5999,6 +5999,12 @@ def mno_gather : Flag<["-"], "mno-gather">, 
Group,
  HelpText<"Disable generation of gather instructions in 
auto-vectorization(x86 only)">;
 def mno_scatter : Flag<["-"], "mno-scatter">, Group,
   HelpText<"Disable generation of scatter instructions in 
auto-vectorization(x86 only)">;
+def mapx_features_EQ : CommaJoined<["-"], "mapx-features=">, 
Group,
+HelpText<"Enable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,cf">;
+def mno_apx_features_EQ : CommaJoined<["-"], "mno-apx-features=">, 
Group,
+HelpText<"Disable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,cf">;
+def mapxf : Flag<["-"], "mapxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx","ndd","ccmp","cf"]>;
+def mno_apxf : Flag<["-"], "mno-apxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx","ndd","ccmp","cf"]>;
 } // let Flags = [TargetSpecific]
 
 // VE feature flags
diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index 85d0697ad63ca..9392211aa6fdf 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -428,6 +428,18 @@ bool 
X86TargetInfo::handleTargetFeatures(std::vector ,
   HasX87 = true;
 } else if (Feature == "+fullbf16") {
   HasFullBFloat16 = true;
+} else if (Feature == "+egpr") {
+  HasEGPR = true;
+} else if (Feature == "+push2pop2") {
+  HasPush2Pop2 = true;
+} else if (Feature == "+ppx") {
+  HasPPX = true;
+} else if (Feature == "+ndd") {
+  HasNDD = true;
+} else if (Feature == "+ccmp") {
+  HasCCMP = true;
+} else if (Feature == "+cf") {
+  HasCF = true;
 }
 
 X86SSEEnum Level = llvm::StringSwitch(Feature)
@@ -927,6 +939,16 @@ void X86TargetInfo::getTargetDefines(const LangOptions 
,
 Builder.defineMacro("__USERMSR__");
   if (HasCRC32)
 Builder.defineMacro("__CRC32__");
+  if (HasEGPR)
+Builder.defineMacro("__EGPR__");
+  if (HasPush2Pop2)
+Builder.defineMacro("__PUSH2POP2__");
+  if (HasNDD)
+Builder.defineMacro("__NDD__");
+  if (HasCCMP)
+Builder.defineMacro("__CCMP__");
+  if (HasCF)
+Builder.defineMacro("__CF__");
 
   // Each case falls through to the previous one here.
   switch (SSELevel) {
@@ -1122,6 +1144,12 @@ bool X86TargetInfo::isValidFeatureName(StringRef Name) 
const {
   .Case("xsavec", true)
   .Case("xsaves", true)
   .Case("xsaveopt", true)
+  .Case("egpr", true)
+  .Case("push2pop2", true)
+  .Case("ppx", true)
+  .Case("ndd", true)
+  .Case("ccmp", true)
+  .Case("cf", true)
   .Default(false);
 }
 
@@ -1238,6 +1266,12 @@ bool X86TargetInfo::hasFeature(StringRef Feature) const {
   .Case("xsaves", HasXSAVES)
   .Case("xsaveopt", HasXSAVEOPT)
   .Case("fullbf16", HasFullBFloat16)
+  .Case("egpr", HasEGPR)
+  .Case("push2pop2", HasPush2Pop2)
+  .Case("ppx", HasPPX)
+  .Case("ndd", HasNDD)
+  .Case("ccmp", HasCCMP)
+  .Case("cf", HasCF)
   

[llvm] [clang] [X86] Support CFE flags for APX features (PR #74199)

2023-12-03 Thread Shengchen Kan via cfe-commits

https://github.com/KanRobert updated 
https://github.com/llvm/llvm-project/pull/74199

>From 246d6e2bc3f6fb60623b5d4c3f07b53c628ed88a Mon Sep 17 00:00:00 2001
From: Shengchen Kan 
Date: Sat, 2 Dec 2023 23:52:53 +0800
Subject: [PATCH 1/2] [X86] Support CFE flags for APX features

Positive options: -mapx-features=
Negative options: -mno-apx-features=

-m[no-]apx-features is designed to be able to control separate APX
features.

Besides, we also support the flag -m[no-]apxf, which can be used like an
alias of -m[no-]apx-features=< all APX features covered by CPUID APX_F>

Behaviour when positive and negative options are used together:

For boolean flags, the last one wins

-mapxf   -mno-apxf   -> -mno-apxf
-mno-apxf   -mapxf   -> -mapxf

For flags that take a set as arguments, it sets the mask by order of the
flags

-mapx-features=egpr,ndd  -mno-apx-features=egpr  ->   -egpr,+ndd
-mapx-features=egpr  -mno-apx-features=egpr,ndd  ->   -egpr,-ndd
-mno-apx-features=egpr  -mapx-features=egpr,ndd  ->   +egpr,+ndd
-mno-apx-features=egpr,ndd  -mapx-features=egpr  ->   -ndd,+egpr

The design is aligned with gcc
https://gcc.gnu.org/pipermail/gcc-patches/2023-August/628905.html
---
 clang/include/clang/Driver/Options.td |  6 
 clang/lib/Basic/Targets/X86.cpp   | 34 +++
 clang/lib/Basic/Targets/X86.h |  6 
 clang/lib/Driver/ToolChains/Arch/X86.cpp  | 15 
 clang/test/Driver/apxf-target-features.c  | 25 ++
 .../llvm/TargetParser/X86TargetParser.def |  6 
 llvm/lib/Target/X86/X86.td|  6 
 llvm/lib/TargetParser/X86TargetParser.cpp |  8 +
 8 files changed, 106 insertions(+)
 create mode 100644 clang/test/Driver/apxf-target-features.c

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 19d04e82aed4d..631c5ad1c015d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5999,6 +5999,12 @@ def mno_gather : Flag<["-"], "mno-gather">, 
Group,
  HelpText<"Disable generation of gather instructions in 
auto-vectorization(x86 only)">;
 def mno_scatter : Flag<["-"], "mno-scatter">, Group,
   HelpText<"Disable generation of scatter instructions in 
auto-vectorization(x86 only)">;
+def mapx_features_EQ : CommaJoined<["-"], "mapx-features=">, 
Group,
+HelpText<"Enable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,cf">;
+def mno_apx_features_EQ : CommaJoined<["-"], "mno-apx-features=">, 
Group,
+HelpText<"Disable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,cf">;
+def mapxf : Flag<["-"], "mapxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx","ndd","ccmp","cf"]>;
+def mno_apxf : Flag<["-"], "mno-apxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx","ndd","ccmp","cf"]>;
 } // let Flags = [TargetSpecific]
 
 // VE feature flags
diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index 85d0697ad63ca..9392211aa6fdf 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -428,6 +428,18 @@ bool 
X86TargetInfo::handleTargetFeatures(std::vector ,
   HasX87 = true;
 } else if (Feature == "+fullbf16") {
   HasFullBFloat16 = true;
+} else if (Feature == "+egpr") {
+  HasEGPR = true;
+} else if (Feature == "+push2pop2") {
+  HasPush2Pop2 = true;
+} else if (Feature == "+ppx") {
+  HasPPX = true;
+} else if (Feature == "+ndd") {
+  HasNDD = true;
+} else if (Feature == "+ccmp") {
+  HasCCMP = true;
+} else if (Feature == "+cf") {
+  HasCF = true;
 }
 
 X86SSEEnum Level = llvm::StringSwitch(Feature)
@@ -927,6 +939,16 @@ void X86TargetInfo::getTargetDefines(const LangOptions 
,
 Builder.defineMacro("__USERMSR__");
   if (HasCRC32)
 Builder.defineMacro("__CRC32__");
+  if (HasEGPR)
+Builder.defineMacro("__EGPR__");
+  if (HasPush2Pop2)
+Builder.defineMacro("__PUSH2POP2__");
+  if (HasNDD)
+Builder.defineMacro("__NDD__");
+  if (HasCCMP)
+Builder.defineMacro("__CCMP__");
+  if (HasCF)
+Builder.defineMacro("__CF__");
 
   // Each case falls through to the previous one here.
   switch (SSELevel) {
@@ -1122,6 +1144,12 @@ bool X86TargetInfo::isValidFeatureName(StringRef Name) 
const {
   .Case("xsavec", true)
   .Case("xsaves", true)
   .Case("xsaveopt", true)
+  .Case("egpr", true)
+  .Case("push2pop2", true)
+  .Case("ppx", true)
+  .Case("ndd", true)
+  .Case("ccmp", true)
+  .Case("cf", true)
   .Default(false);
 }
 
@@ -1238,6 +1266,12 @@ bool X86TargetInfo::hasFeature(StringRef Feature) const {
   .Case("xsaves", HasXSAVES)
   .Case("xsaveopt", HasXSAVEOPT)
   .Case("fullbf16", HasFullBFloat16)
+  .Case("egpr", HasEGPR)
+  .Case("push2pop2", HasPush2Pop2)
+  .Case("ppx", HasPPX)
+  .Case("ndd", HasNDD)
+  .Case("ccmp", HasCCMP)
+  .Case("cf", HasCF)
   

[llvm] [clang] [X86] Support CFE flags for APX features (PR #74199)

2023-12-02 Thread Shengchen Kan via cfe-commits

https://github.com/KanRobert created 
https://github.com/llvm/llvm-project/pull/74199

Positive options: -mapx-features=
Negative options: -mno-apx-features=

-m[no-]apx-features is designed to be able to control separate APX
features.

Besides, we also support the flag -m[no-]apxf, which can be used like an
alias of -m[no-]apx-features=< all APX features covered by CPUID APX_F>

Behaviour when positive and negative options are used together:

For boolean flags, the last one wins

-mapxf   -mno-apxf   -> -mno-apxf
-mno-apxf   -mapxf   -> -mapxf

For flags that take a set as arguments, it sets the mask by order of the
flags

-mapx-features=egpr,ndd  -mno-apx-features=egpr  ->   -egpr,+ndd
-mapx-features=egpr  -mno-apx-features=egpr,ndd  ->   -egpr,-ndd
-mno-apx-features=egpr  -mapx-features=egpr,ndd  ->   +egpr,+ndd
-mno-apx-features=egpr,ndd  -mapx-features=egpr  ->   -ndd,+egpr

The design is aligned with gcc
https://gcc.gnu.org/pipermail/gcc-patches/2023-August/628905.html


>From 246d6e2bc3f6fb60623b5d4c3f07b53c628ed88a Mon Sep 17 00:00:00 2001
From: Shengchen Kan 
Date: Sat, 2 Dec 2023 23:52:53 +0800
Subject: [PATCH] [X86] Support CFE flags for APX features

Positive options: -mapx-features=
Negative options: -mno-apx-features=

-m[no-]apx-features is designed to be able to control separate APX
features.

Besides, we also support the flag -m[no-]apxf, which can be used like an
alias of -m[no-]apx-features=< all APX features covered by CPUID APX_F>

Behaviour when positive and negative options are used together:

For boolean flags, the last one wins

-mapxf   -mno-apxf   -> -mno-apxf
-mno-apxf   -mapxf   -> -mapxf

For flags that take a set as arguments, it sets the mask by order of the
flags

-mapx-features=egpr,ndd  -mno-apx-features=egpr  ->   -egpr,+ndd
-mapx-features=egpr  -mno-apx-features=egpr,ndd  ->   -egpr,-ndd
-mno-apx-features=egpr  -mapx-features=egpr,ndd  ->   +egpr,+ndd
-mno-apx-features=egpr,ndd  -mapx-features=egpr  ->   -ndd,+egpr

The design is aligned with gcc
https://gcc.gnu.org/pipermail/gcc-patches/2023-August/628905.html
---
 clang/include/clang/Driver/Options.td |  6 
 clang/lib/Basic/Targets/X86.cpp   | 34 +++
 clang/lib/Basic/Targets/X86.h |  6 
 clang/lib/Driver/ToolChains/Arch/X86.cpp  | 15 
 clang/test/Driver/apxf-target-features.c  | 25 ++
 .../llvm/TargetParser/X86TargetParser.def |  6 
 llvm/lib/Target/X86/X86.td|  6 
 llvm/lib/TargetParser/X86TargetParser.cpp |  8 +
 8 files changed, 106 insertions(+)
 create mode 100644 clang/test/Driver/apxf-target-features.c

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 19d04e82aed4d..631c5ad1c015d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5999,6 +5999,12 @@ def mno_gather : Flag<["-"], "mno-gather">, 
Group,
  HelpText<"Disable generation of gather instructions in 
auto-vectorization(x86 only)">;
 def mno_scatter : Flag<["-"], "mno-scatter">, Group,
   HelpText<"Disable generation of scatter instructions in 
auto-vectorization(x86 only)">;
+def mapx_features_EQ : CommaJoined<["-"], "mapx-features=">, 
Group,
+HelpText<"Enable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,cf">;
+def mno_apx_features_EQ : CommaJoined<["-"], "mno-apx-features=">, 
Group,
+HelpText<"Disable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,cf">;
+def mapxf : Flag<["-"], "mapxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx","ndd","ccmp","cf"]>;
+def mno_apxf : Flag<["-"], "mno-apxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx","ndd","ccmp","cf"]>;
 } // let Flags = [TargetSpecific]
 
 // VE feature flags
diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index 85d0697ad63ca..9392211aa6fdf 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -428,6 +428,18 @@ bool 
X86TargetInfo::handleTargetFeatures(std::vector ,
   HasX87 = true;
 } else if (Feature == "+fullbf16") {
   HasFullBFloat16 = true;
+} else if (Feature == "+egpr") {
+  HasEGPR = true;
+} else if (Feature == "+push2pop2") {
+  HasPush2Pop2 = true;
+} else if (Feature == "+ppx") {
+  HasPPX = true;
+} else if (Feature == "+ndd") {
+  HasNDD = true;
+} else if (Feature == "+ccmp") {
+  HasCCMP = true;
+} else if (Feature == "+cf") {
+  HasCF = true;
 }
 
 X86SSEEnum Level = llvm::StringSwitch(Feature)
@@ -927,6 +939,16 @@ void X86TargetInfo::getTargetDefines(const LangOptions 
,
 Builder.defineMacro("__USERMSR__");
   if (HasCRC32)
 Builder.defineMacro("__CRC32__");
+  if (HasEGPR)
+Builder.defineMacro("__EGPR__");
+  if (HasPush2Pop2)
+Builder.defineMacro("__PUSH2POP2__");
+  if (HasNDD)
+Builder.defineMacro("__NDD__");
+  if (HasCCMP)
+