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.

llvm-svn: 174140
This commit is contained in:
Bill Schmidt 2013-02-01 02:14:03 +00:00
parent af02bbe84f
commit 2fe4c67374
4 changed files with 51 additions and 0 deletions

View File

@ -291,6 +291,7 @@ def faccess_control : Flag<["-"], "faccess-control">, Group<f_Group>;
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_Group>, Flags<[DriverOption]>;
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>;

View File

@ -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(const LangOptions &Opts,
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 {

View File

@ -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,

View File

@ -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