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; -def mgeneral_regs_only : Flag<["-"], "mgeneral-regs-only">, Group, - HelpText<"Generate code which only uses the general purpose registers (AArch64 only)">; +def mgeneral_regs_only : Flag<["-"], "mgeneral-regs-only">, 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, HelpText<"Workaround Cortex-A53 erratum 835769 (AArch64 only)">; 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/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/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/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"