r174140 - Enable -fno-altivec, -mno-altivec for PowerPC.

Dmitri Gribenko gribozavr at gmail.com
Thu Jan 31 18:48:28 PST 2013


On Fri, Feb 1, 2013 at 4:14 AM, Bill Schmidt
<wschmidt at linux.vnet.ibm.com> wrote:
> Author: wschmidt
> Date: Thu Jan 31 20:14:03 2013
> New Revision: 174140
>
> URL: http://llvm.org/viewvc/llvm-project?rev=174140&view=rev
> Log:
> 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.
>
> Added:
>     cfe/trunk/test/CodeGen/ppc-no-altivec.c
> Modified:
>     cfe/trunk/include/clang/Driver/Options.td
>     cfe/trunk/lib/Basic/Targets.cpp
>     cfe/trunk/lib/Driver/Tools.cpp
>
> Modified: cfe/trunk/include/clang/Driver/Options.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=174140&r1=174139&r2=174140&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Driver/Options.td (original)
> +++ cfe/trunk/include/clang/Driver/Options.td Thu Jan 31 20:14:03 2013
> @@ -291,6 +291,7 @@ def faccess_control : Flag<["-"], "facce
>  def fallow_unsupported : Flag<["-"], "fallow-unsupported">, Group<f_Group>;
>  def faltivec : Flag<["-"], "faltivec">, Group<f_Group>, Flags<[CC1Option]>,
>    HelpText<"Enable AltiVec vector initializer syntax">;
> +def fno_altivec : Flag<["-"], "fno-altivec">, Group<f_Group>, Flags<[CC1Option]>;
>  def fapple_kext : Flag<["-"], "fapple-kext">, Group<f_Group>, Flags<[CC1Option]>,
>    HelpText<"Use Apple's kernel extensions ABI">;
>  def fapple_pragma_pack : Flag<["-"], "fapple-pragma-pack">, Group<f_Group>, Flags<[CC1Option]>,
> @@ -809,6 +810,7 @@ def m64 : Flag<["-"], "m64">, Group<m_Gr
>  def mabi_EQ : Joined<["-"], "mabi=">, Group<m_Group>;
>  def march_EQ : Joined<["-"], "march=">, Group<m_Group>;
>  def maltivec : Flag<["-"], "maltivec">, Alias<faltivec>;
> +def mno_altivec : Flag<["-"], "mno-altivec">, Alias<fno_altivec>;
>  def mcmodel_EQ : Joined<["-"], "mcmodel=">, Group<m_Group>;
>  def mconstant_cfstrings : Flag<["-"], "mconstant-cfstrings">, Group<clang_ignored_m_Group>;
>  def mcpu_EQ : Joined<["-"], "mcpu=">, Group<m_Group>;
>
> Modified: cfe/trunk/lib/Basic/Targets.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=174140&r1=174139&r2=174140&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Basic/Targets.cpp (original)
> +++ cfe/trunk/lib/Basic/Targets.cpp Thu Jan 31 20:14:03 2013
> @@ -711,6 +711,12 @@ public:
>    virtual void getTargetDefines(const LangOptions &Opts,
>                                  MacroBuilder &Builder) const;
>
> +  virtual void getDefaultFeatures(llvm::StringMap<bool> &Features) const;
> +
> +  virtual bool setFeatureEnabled(llvm::StringMap<bool> &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(con
>    if (defs & ArchDefinePwr6) {
>      Builder.defineMacro("_ARCH_PWR5");
>      Builder.defineMacro("_ARCH_PWR6");
> +  }
> +}
> +
> +void PPCTargetInfo::getDefaultFeatures(llvm::StringMap<bool> &Features) const {
> +  Features["altivec"] = llvm::StringSwitch<bool>(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<bool> &Features,
> +                                         StringRef Name,
> +                                         bool Enabled) const {
> +  if (Name == "altivec") {
> +    Features[Name] = Enabled;
> +    return true;
>    }
> +
> +  return false;
>  }
>
>  bool PPCTargetInfo::hasFeature(StringRef Feature) const {
>
> Modified: cfe/trunk/lib/Driver/Tools.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=174140&r1=174139&r2=174140&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Driver/Tools.cpp (original)
> +++ cfe/trunk/lib/Driver/Tools.cpp Thu Jan 31 20:14:03 2013
> @@ -1084,6 +1084,12 @@ void Clang::AddPPCTargetArgs(const ArgLi
>      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,
>
> Added: cfe/trunk/test/CodeGen/ppc-no-altivec.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ppc-no-altivec.c?rev=174140&view=auto
> ==============================================================================
> --- cfe/trunk/test/CodeGen/ppc-no-altivec.c (added)
> +++ cfe/trunk/test/CodeGen/ppc-no-altivec.c Thu Jan 31 20:14:03 2013
> @@ -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

Hi Bill,

In general, we avoid doing such end-to-end tests.  This change can be
easily tested with a driver test.  I guess it should go into
test/Driver/altivec.cpp, and you can get the idea from
test/Driver/arm-mfpu.c.  Please add tests for different combinations
of both flags.

You can also add tests for different CPUs (this is currently not
tested, if I understand correctly).

Dmitri

-- 
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/



More information about the cfe-commits mailing list