[cfe-commits] r110609 - in /cfe/trunk: include/clang/Basic/Attr.td include/clang/Parse/AttributeList.h lib/AST/AttrImpl.cpp lib/Parse/AttributeList.cpp lib/Sema/SemaDeclAttr.cpp test/Parser/cxx-altivec.cpp

John Thompson John.Thompson.JTSoftware at gmail.com
Mon Aug 9 14:53:52 PDT 2010


Author: jtsoftware
Date: Mon Aug  9 16:53:52 2010
New Revision: 110609

URL: http://llvm.org/viewvc/llvm-project?rev=110609&view=rev
Log:
Added vecreturn attribute parsing.

Modified:
    cfe/trunk/include/clang/Basic/Attr.td
    cfe/trunk/include/clang/Parse/AttributeList.h
    cfe/trunk/lib/AST/AttrImpl.cpp
    cfe/trunk/lib/Parse/AttributeList.cpp
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp
    cfe/trunk/test/Parser/cxx-altivec.cpp

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=110609&r1=110608&r2=110609&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Mon Aug  9 16:53:52 2010
@@ -376,6 +376,12 @@
   let Args = [StringArgument<"Visibility">];
 }
 
+def VecReturn : Attr {
+  let Spellings = ["vecreturn"];
+  let Subjects = [CXXRecord];
+  let DoNotEmit = 0;
+}
+
 def WarnUnusedResult : Attr {
   let Spellings = ["warn_unused_result"];
 }

Modified: cfe/trunk/include/clang/Parse/AttributeList.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/AttributeList.h?rev=110609&r1=110608&r2=110609&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/AttributeList.h (original)
+++ cfe/trunk/include/clang/Parse/AttributeList.h Mon Aug  9 16:53:52 2010
@@ -111,6 +111,7 @@
     AT_unavailable,
     AT_unused,
     AT_used,
+    AT_vecreturn,     // PS3 PPU-specific.
     AT_vector_size,
     AT_visibility,
     AT_warn_unused_result,

Modified: cfe/trunk/lib/AST/AttrImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/AttrImpl.cpp?rev=110609&r1=110608&r2=110609&view=diff
==============================================================================
--- cfe/trunk/lib/AST/AttrImpl.cpp (original)
+++ cfe/trunk/lib/AST/AttrImpl.cpp Mon Aug  9 16:53:52 2010
@@ -126,6 +126,7 @@
 DEF_SIMPLE_ATTR_CLONE(Unavailable)
 DEF_SIMPLE_ATTR_CLONE(Unused)
 DEF_SIMPLE_ATTR_CLONE(Used)
+DEF_SIMPLE_ATTR_CLONE(VecReturn)
 DEF_SIMPLE_ATTR_CLONE(WarnUnusedResult)
 DEF_SIMPLE_ATTR_CLONE(Weak)
 DEF_SIMPLE_ATTR_CLONE(WeakImport)

Modified: cfe/trunk/lib/Parse/AttributeList.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/AttributeList.cpp?rev=110609&r1=110608&r2=110609&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/AttributeList.cpp (original)
+++ cfe/trunk/lib/Parse/AttributeList.cpp Mon Aug  9 16:53:52 2010
@@ -100,6 +100,7 @@
     .Case("format_arg", AT_format_arg)
     .Case("gnu_inline", AT_gnu_inline)
     .Case("weak_import", AT_weak_import)
+    .Case("vecreturn", AT_vecreturn)
     .Case("vector_size", AT_vector_size)
     .Case("constructor", AT_constructor)
     .Case("unavailable", AT_unavailable)

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=110609&r1=110608&r2=110609&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Mon Aug  9 16:53:52 2010
@@ -687,6 +687,45 @@
     d->addAttr(::new (S.Context) AnalyzerNoReturnAttr());
 }
 
+// PS3 PPU-specific.
+static void HandleVecReturnAttr(Decl *d, const AttributeList &Attr,
+                                       Sema &S) {
+/*
+  Returning a Vector Class in Registers
+  
+  According to the PPU ABI specifications, a class with a single member of vector type is returned in
+  memory when used as the return value of a function. This results in inefficient code when implementing
+  vector classes. To return the value in a single vector register, add the vecreturn attribute to the class
+  definition. This attribute is also applicable to struct types.
+  
+  Example:
+  
+  struct Vector
+  {
+    __vector float xyzw;
+  } __attribute__((vecreturn));
+  
+  Vector Add(Vector lhs, Vector rhs)
+  {
+    Vector result;
+    result.xyzw = vec_add(lhs.xyzw, rhs.xyzw);
+    return result; // This will be returned in a register
+  }
+*/
+  if (!isa<CXXRecordDecl>(d)) {
+    S.Diag(Attr.getLoc(), diag::err_attribute_wrong_decl_type)
+      << Attr.getName() << 9 /*class*/;
+    return;
+  }
+
+  if (d->getAttr<VecReturnAttr>()) {
+    S.Diag(Attr.getLoc(), diag::err_repeat_attribute) << "vecreturn";
+    return;
+  }
+
+  d->addAttr(::new (S.Context) VecReturnAttr());
+}
+
 static void HandleDependencyAttr(Decl *d, const AttributeList &Attr, Sema &S) {
   if (!isFunctionOrMethod(d) && !isa<ParmVarDecl>(d)) {
     S.Diag(Attr.getLoc(), diag::err_attribute_wrong_decl_type)
@@ -2181,6 +2220,7 @@
   case AttributeList::AT_noreturn:    HandleNoReturnAttr    (D, Attr, S); break;
   case AttributeList::AT_nothrow:     HandleNothrowAttr     (D, Attr, S); break;
   case AttributeList::AT_override:    HandleOverrideAttr    (D, Attr, S); break;
+  case AttributeList::AT_vecreturn:   HandleVecReturnAttr   (D, Attr, S); break;
 
   // Checker-specific.
   case AttributeList::AT_ns_returns_not_retained:

Modified: cfe/trunk/test/Parser/cxx-altivec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx-altivec.cpp?rev=110609&r1=110608&r2=110609&view=diff
==============================================================================
--- cfe/trunk/test/Parser/cxx-altivec.cpp (original)
+++ cfe/trunk/test/Parser/cxx-altivec.cpp Mon Aug  9 16:53:52 2010
@@ -126,3 +126,38 @@
 vector int v4 = (vector int)(1, 2, 3, 4);
 vector float v5 = (vector float)(1.0f, 2.0f, 3.0f, 4.0f);
 vector char v6 = (vector char)((vector int)(1+2, -2, (int)(2.0 * 3), -(5-3)));
+
+#if 0 // Not ready yet.
+// bug 7553 - Problem with '==' and vectors
+void func() {
+  vector int v10i = (vector int)(1, 2, 3, 4);
+  vector int v11i = (vector int)(1, 2, 3, 4);
+  bool r10ieq = (v10i == v11i);
+  bool r10ine = (v10i != v11i);
+  bool r10igt = (v10i > v11i);
+  bool r10ige = (v10i >= v11i);
+  bool r10ilt = (v10i < v11i);
+  bool r10ile = (v10i <= v11i);
+  vector float v10f = (vector float)(1.0f, 2.0f, 3.0f, 4.0f);
+  vector float v11f = (vector float)(1.0f, 2.0f, 3.0f, 4.0f);
+  bool r10feq = (v10f == v11f);
+  bool r10fne = (v10f != v11f);
+  bool r10fgt = (v10f > v11f);
+  bool r10fge = (v10f >= v11f);
+  bool r10flt = (v10f < v11f);
+  bool r10fle = (v10f <= v11f);
+}
+#endif
+
+// vecreturn attribute test
+struct Vector
+{
+	__vector float xyzw;
+} __attribute__((vecreturn));
+
+Vector Add(Vector lhs, Vector rhs)
+{
+	Vector result;
+	result.xyzw = vec_add(lhs.xyzw, rhs.xyzw);
+	return result; // This will (eventually) be returned in a register
+}





More information about the cfe-commits mailing list