[PATCH] D103943: [X86] Add -mgeneral-regs-only support.
Wang Tianqing via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 8 23:32:18 PDT 2021
tianqing created this revision.
Herald added a subscriber: dang.
tianqing requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D103943
Files:
clang/include/clang/Driver/Options.td
clang/lib/Basic/Targets/X86.cpp
clang/lib/Driver/ToolChains/Arch/X86.cpp
clang/test/CodeGen/attr-target-general-regs-only-x86.c
clang/test/Driver/x86-mgeneral-regs-only.c
Index: clang/test/Driver/x86-mgeneral-regs-only.c
===================================================================
--- /dev/null
+++ clang/test/Driver/x86-mgeneral-regs-only.c
@@ -0,0 +1,8 @@
+// Test the -mgeneral-regs-only option on x86
+
+// RUN: %clang -target i386-unknown-linux-gnu -mgeneral-regs-only %s -### 2>&1 | FileCheck %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -mgeneral-regs-only %s -### 2>&1 | FileCheck %s
+
+// CHECK: "-target-feature" "-x87"
+// CHECK: "-target-feature" "-mmx"
+// CHECK: "-target-feature" "-sse"
Index: clang/test/CodeGen/attr-target-general-regs-only-x86.c
===================================================================
--- /dev/null
+++ clang/test/CodeGen/attr-target-general-regs-only-x86.c
@@ -0,0 +1,8 @@
+// Test general-regs-only target attribute on x86
+
+// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o - | FileCheck %s
+
+void __attribute__((target("general-regs-only"))) foo() { }
+
+// CHECK: "target-features"="{{.*}}-mmx{{.*}}-sse{{.*}}-x87{{.*}}"
Index: clang/lib/Driver/ToolChains/Arch/X86.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Arch/X86.cpp
+++ clang/lib/Driver/ToolChains/Arch/X86.cpp
@@ -142,6 +142,12 @@
Features.push_back("+ssse3");
}
+ if (Args.getLastArg(options::OPT_mgeneral_regs_only)) {
+ Features.push_back("-x87");
+ Features.push_back("-mmx");
+ Features.push_back("-sse");
+ }
+
// Translate the high level `-mretpoline` flag to the specific target feature
// flags. We also detect if the user asked for retpoline external thunks but
// failed to ask for retpolines themselves (through any of the different
Index: clang/lib/Basic/Targets/X86.cpp
===================================================================
--- clang/lib/Basic/Targets/X86.cpp
+++ clang/lib/Basic/Targets/X86.cpp
@@ -142,6 +142,17 @@
llvm::find(FeaturesVec, "-xsave") == FeaturesVec.end())
Features["xsave"] = true;
+ I = Features.find("general-regs-only");
+ if (I != Features.end()) {
+ bool HasGeneralRegsOnly = I->getValue();
+ Features.erase(I);
+ if (HasGeneralRegsOnly) {
+ setFeatureEnabled(Features, "x87", false);
+ setFeatureEnabled(Features, "mmx", false);
+ setFeatureEnabled(Features, "sse", false);
+ }
+ }
+
return true;
}
@@ -865,6 +876,7 @@
.Case("fma4", true)
.Case("fsgsbase", true)
.Case("fxsr", true)
+ .Case("general-regs-only", true)
.Case("gfni", true)
.Case("hreset", true)
.Case("invpcid", true)
Index: clang/include/clang/Driver/Options.td
===================================================================
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -3197,8 +3197,8 @@
" volatile bit-field width is dictated by the field container type. (ARM only).">>,
Group<m_arm_Features_Group>;
-def mgeneral_regs_only : Flag<["-"], "mgeneral-regs-only">, Group<m_aarch64_Features_Group>,
- HelpText<"Generate code which only uses the general purpose registers (AArch64 only)">;
+def mgeneral_regs_only : Flag<["-"], "mgeneral-regs-only">, Group<m_Group>,
+ HelpText<"Generate code which only uses the general purpose registers (AArch64/x86 only)">;
def mfix_cortex_a53_835769 : Flag<["-"], "mfix-cortex-a53-835769">,
Group<m_aarch64_Features_Group>,
HelpText<"Workaround Cortex-A53 erratum 835769 (AArch64 only)">;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103943.350789.patch
Type: text/x-patch
Size: 3562 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210609/0574ecfe/attachment-0001.bin>
More information about the cfe-commits
mailing list