]> granicus.if.org Git - clang/commitdiff
Enable -fno-altivec, -mno-altivec for PowerPC.
authorBill Schmidt <wschmidt@linux.vnet.ibm.com>
Fri, 1 Feb 2013 02:14:03 +0000 (02:14 +0000)
committerBill Schmidt <wschmidt@linux.vnet.ibm.com>
Fri, 1 Feb 2013 02:14:03 +0000 (02:14 +0000)
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

include/clang/Driver/Options.td
lib/Basic/Targets.cpp
lib/Driver/Tools.cpp
test/CodeGen/ppc-no-altivec.c [new file with mode: 0644]

index 49195085b12bbf19b58b312e4040ae018296faaf..a3dd71d0655e2aca1492b5475123b87c137fdd71 100644 (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>;
index 27984dfbf4b38ffcbaf2b3de797d2585825fba49..4d0a833d23da61b7b0de00e6f017cf2d363aca21 100644 (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 {
index cb7cc2381daff401a302362cc48bae9137723362..844367ee441e9e97f6e9585710329c06feebc4ff 100644 (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,
diff --git a/test/CodeGen/ppc-no-altivec.c b/test/CodeGen/ppc-no-altivec.c
new file mode 100644 (file)
index 0000000..1830f26
--- /dev/null
@@ -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