From: Bill Schmidt Date: Fri, 1 Feb 2013 02:14:03 +0000 (+0000) Subject: Enable -fno-altivec, -mno-altivec for PowerPC. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=199402b9e081dedc28e19ab6e727470b34f2f64d;p=clang Enable -fno-altivec, -mno-altivec for PowerPC. Introduces these negation forms explicitly and uses them to control a new "altivec" target feature for PowerPC. This allows avoiding generating Altivec instructions on processors that support Altivec. The new test case verifies that the Altivec "lvx" instruction is not used when -fno-altivec is present on the command line. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174140 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index 49195085b1..a3dd71d065 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -291,6 +291,7 @@ def faccess_control : Flag<["-"], "faccess-control">, Group; def fallow_unsupported : Flag<["-"], "fallow-unsupported">, Group; def faltivec : Flag<["-"], "faltivec">, Group, Flags<[CC1Option]>, HelpText<"Enable AltiVec vector initializer syntax">; +def fno_altivec : Flag<["-"], "fno-altivec">, Group, Flags<[CC1Option]>; def fapple_kext : Flag<["-"], "fapple-kext">, Group, Flags<[CC1Option]>, HelpText<"Use Apple's kernel extensions ABI">; def fapple_pragma_pack : Flag<["-"], "fapple-pragma-pack">, Group, Flags<[CC1Option]>, @@ -809,6 +810,7 @@ def m64 : Flag<["-"], "m64">, Group, Flags<[DriverOption]>; def mabi_EQ : Joined<["-"], "mabi=">, Group; def march_EQ : Joined<["-"], "march=">, Group; def maltivec : Flag<["-"], "maltivec">, Alias; +def mno_altivec : Flag<["-"], "mno-altivec">, Alias; def mcmodel_EQ : Joined<["-"], "mcmodel=">, Group; def mconstant_cfstrings : Flag<["-"], "mconstant-cfstrings">, Group; def mcpu_EQ : Joined<["-"], "mcpu=">, Group; diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index 27984dfbf4..4d0a833d23 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -711,6 +711,12 @@ public: virtual void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const; + virtual void getDefaultFeatures(llvm::StringMap &Features) const; + + virtual bool setFeatureEnabled(llvm::StringMap &Features, + StringRef Name, + bool Enabled) const; + virtual bool hasFeature(StringRef Feature) const; virtual void getGCCRegNames(const char * const *&Names, @@ -907,7 +913,32 @@ void PPCTargetInfo::getTargetDefines(const LangOptions &Opts, if (defs & ArchDefinePwr6) { Builder.defineMacro("_ARCH_PWR5"); Builder.defineMacro("_ARCH_PWR6"); + } +} + +void PPCTargetInfo::getDefaultFeatures(llvm::StringMap &Features) const { + Features["altivec"] = llvm::StringSwitch(CPU) + .Case("7400", true) + .Case("g4", true) + .Case("7450", true) + .Case("g4+", true) + .Case("970", true) + .Case("g5", true) + .Case("pwr6", true) + .Case("pwr7", true) + .Case("ppc64", true) + .Default(false); +} + +bool PPCTargetInfo::setFeatureEnabled(llvm::StringMap &Features, + StringRef Name, + bool Enabled) const { + if (Name == "altivec") { + Features[Name] = Enabled; + return true; } + + return false; } bool PPCTargetInfo::hasFeature(StringRef Feature) const { diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index cb7cc2381d..844367ee44 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -1084,6 +1084,12 @@ void Clang::AddPPCTargetArgs(const ArgList &Args, CmdArgs.push_back("-target-cpu"); CmdArgs.push_back(Args.MakeArgString(TargetCPUName.c_str())); } + + // Allow override of the Altivec feature. + if (Args.hasFlag(options::OPT_fno_altivec, options::OPT_faltivec, false)) { + CmdArgs.push_back("-target-feature"); + CmdArgs.push_back("-altivec"); + } } void Clang::AddSparcTargetArgs(const ArgList &Args, diff --git a/test/CodeGen/ppc-no-altivec.c b/test/CodeGen/ppc-no-altivec.c new file mode 100644 index 0000000000..1830f268dd --- /dev/null +++ b/test/CodeGen/ppc-no-altivec.c @@ -0,0 +1,12 @@ +// REQUIRES: ppc64-registered-target +// RUN: %clang_cc1 %s -triple=powerpc64-unknown-linux-gnu -S -o - | FileCheck %s + +typedef char v8qi __attribute__((vector_size (8))); + +extern v8qi x, y; + +v8qi foo (void) { + return x + y; +} + +// CHECK-NOT: lvx