[cfe-commits] r65966 - in /cfe/trunk: Driver/clang.cpp include/clang/Basic/TargetInfo.h lib/Basic/Targets.cpp

Chris Lattner sabre at nondot.org
Tue Mar 3 11:56:18 PST 2009


Author: lattner
Date: Tue Mar  3 13:56:18 2009
New Revision: 65966

URL: http://llvm.org/viewvc/llvm-project?rev=65966&view=rev
Log:
implement support for propagating *features* down to the code generator
and defining target-specific macros based on them (like __SSE3__ and 
friends).  After extensive discussion with Daniel, this work will need
driver support, which will translate things like -msse3 into a -mattr 
feature.  Until this work is done, the code in clang.cpp is disabled and
the X86TargetInfo ctor still defaults to SSE2.  With these two things
changed, this code will work.  PR3634

Modified:
    cfe/trunk/Driver/clang.cpp
    cfe/trunk/include/clang/Basic/TargetInfo.h
    cfe/trunk/lib/Basic/Targets.cpp

Modified: cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/clang.cpp?rev=65966&r1=65965&r2=65966&view=diff

==============================================================================
--- cfe/trunk/Driver/clang.cpp (original)
+++ cfe/trunk/Driver/clang.cpp Tue Mar  3 13:56:18 2009
@@ -517,10 +517,10 @@
 static llvm::cl::opt<bool>
 Ansi("ansi", llvm::cl::desc("Equivalent to specifying -std=c89."));
 
-
 static llvm::cl::list<std::string>
-TargetOptions("m", llvm::cl::Prefix, llvm::cl::value_desc("option"),
-          llvm::cl::desc("Target-specific options, such as -msse3"));
+TargetFeatures("mattr", llvm::cl::CommaSeparated,
+        llvm::cl::desc("Target specific attributes (-mattr=help for details)"));
+
 
 
 // FIXME: add:
@@ -530,19 +530,25 @@
   // Allow the target to set the default the langauge options as it sees fit.
   Target->getDefaultLangOptions(Options);
   
-  // If the user specified any -mfoo options, pass them to the target for
-  // validation and processing.
-  if (!TargetOptions.empty()) {
+  // If there are any -mattr options, pass them to the target for validation and
+  // processing.  The driver should have already consolidated all the
+  // target-feature settings and passed them to us in the -mattr list.  The
+  // -mattr list is treated by the code generator as a diff against the -mcpu
+  // setting, but the driver should pass all enabled options as "+" settings.
+  // This means that the target should only look at + settings.
+  if (!TargetFeatures.empty()
+      // FIXME: The driver is not quite yet ready for this.
+      && 0) {
     std::string ErrorStr;
-    int Opt = Target->HandleTargetOptions(&TargetOptions[0],
-                                          TargetOptions.size(), ErrorStr);
+    int Opt = Target->HandleTargetFeatures(&TargetFeatures[0],
+                                           TargetFeatures.size(), ErrorStr);
     if (Opt != -1) {
       if (ErrorStr.empty())
-        fprintf(stderr, "invalid command line option '%s'\n",
-                TargetOptions[Opt].c_str());
+        fprintf(stderr, "invalid feature '%s'\n",
+                TargetFeatures[Opt].c_str());
       else
-        fprintf(stderr, "command line option '%s': %s\n",
-                TargetOptions[Opt].c_str(), ErrorStr.c_str());
+        fprintf(stderr, "feature '%s': %s\n",
+                TargetFeatures[Opt].c_str(), ErrorStr.c_str());
       exit(1);
     }
   }
@@ -1253,10 +1259,6 @@
 TargetCPU("mcpu",
          llvm::cl::desc("Target a specific cpu type (-mcpu=help for details)"));
 
-static llvm::cl::list<std::string>
-TargetFeatures("mattr",
-        llvm::cl::desc("Target specific attributes (-mattr=help for details)"));
-
 static void InitializeCompileOptions(CompileOptions &Opts) {
   Opts.OptimizeSize = OptSize;
   if (OptSize) {

Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=65966&r1=65965&r2=65966&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Tue Mar  3 13:56:18 2009
@@ -249,12 +249,19 @@
   /// options. 
   virtual void getDefaultLangOptions(LangOptions &Opts) {}
 
-  /// HandleTargetOptions - Handle target-specific options like -msse2 and
-  /// friends.  An array of arguments is passed in: if they are all valid, this
-  /// should handle them and return -1.  If there is an error, the index of the
-  /// invalid argument should be returned along with an optional error string.
-  virtual int HandleTargetOptions(std::string *StrArray, unsigned NumStrs,
-                                  std::string &ErrorReason) {
+  /// HandleTargetFeatures - Handle target-specific options like -mattr=+sse2
+  /// and friends.  An array of arguments is passed in: if they are all valid,
+  /// this should handle them and return -1.  If there is an error, the index of
+  /// the invalid argument should be returned along with an optional error
+  /// string.
+  ///
+  /// Note that the driver should have already consolidated all the
+  /// target-feature settings and passed them to us in the -mattr list.  The
+  /// -mattr list is treated by the code generator as a diff against the -mcpu
+  /// setting, but the driver should pass all enabled options as "+" settings.
+  /// This means that the target should only look at + settings.
+  virtual int HandleTargetFeatures(std::string *StrArray, unsigned NumStrs,
+                                   std::string &ErrorReason) {
     if (NumStrs == 0)
       return -1;
     return 0;

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=65966&r1=65965&r2=65966&view=diff

==============================================================================
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Tue Mar  3 13:56:18 2009
@@ -420,7 +420,10 @@
   } SSELevel;
 public:
   X86TargetInfo(const std::string& triple) 
-    : TargetInfo(triple), SSELevel(SSE2) {
+    : TargetInfo(triple),
+      // FIXME: hard coding to SSE2 for now.  This should change to NoMMXSSE so
+      // that the driver controls this.
+      SSELevel(SSE2) {
     LongDoubleFormat = &llvm::APFloat::x87DoubleExtended;
   }
   virtual void getTargetBuiltins(const Builtin::Info *&Records,
@@ -449,19 +452,49 @@
   }
   virtual void getTargetDefines(std::vector<char> &Defines) const;
   
-  virtual int HandleTargetOptions(std::string *StrArray, unsigned NumStrs,
-                                  std::string &ErrorReason);
+  virtual int HandleTargetFeatures(std::string *StrArray, unsigned NumStrs,
+                                   std::string &ErrorReason);
 };
 
 /// HandleTargetOptions - Handle target-specific options like -msse2 and
 /// friends.  An array of arguments is passed in: if they are all valid, this
 /// should handle them and return -1.  If there is an error, the index of the
 /// invalid argument should be returned along with an optional error string.
-int X86TargetInfo::HandleTargetOptions(std::string *StrArray, unsigned NumStrs,
-                                       std::string &ErrorReason) {
-  if (NumStrs == 0)
-    return -1;
-  return 0;
+int X86TargetInfo::HandleTargetFeatures(std::string *StrArray, unsigned NumStrs,
+                                        std::string &ErrorReason) {
+  for (unsigned i = 0; i != NumStrs; ++i) {
+    const std::string &Feature = StrArray[i];
+    if (Feature.size() < 2) return i;
+    // Ignore explicitly disabled features.
+    if (Feature[0] == '-') continue;
+    
+    // Feature strings are of the form "+feature".
+    if (Feature[0] != '+') return i;
+    
+    // The set of supported subtarget features is defined in
+    // lib/Target/X86/X86.td.  Here we recognize and map onto our internal
+    // state.
+    if (Feature == "+mmx")
+      SSELevel = std::max(SSELevel, MMX);
+    else if (Feature == "+sse")
+      SSELevel = std::max(SSELevel, SSE1);
+    else if (Feature == "+sse2")
+      SSELevel = std::max(SSELevel, SSE2);
+    else if (Feature == "+sse3")
+      SSELevel = std::max(SSELevel, SSE3);
+    else if (Feature == "+ssse3")
+      SSELevel = std::max(SSELevel, SSSE3);
+    else if (Feature == "+sse41")
+      SSELevel = std::max(SSELevel, SSE41);
+    else if (Feature == "+sse42")
+      SSELevel = std::max(SSELevel, SSE42);
+    else if (Feature == "+64bit" || Feature == "+slow-bt-mem")
+      // Ignore these features.
+      continue;
+    else
+      return i;
+  }
+  return -1;
 }
 
 /// X86TargetInfo::getTargetDefines - Return a set of the X86-specific #defines





More information about the cfe-commits mailing list