Home | History | Annotate | Download | only in patches
      1 From 4ad30819eb30d7c72336cc61cabd85b42a350aac Mon Sep 17 00:00:00 2001
      2 From: Tim Murray <timmurray (a] google.com>
      3 Date: Thu, 3 Apr 2014 13:38:15 -0700
      4 Subject: [PATCH 3/4] Add support for RenderScript specific options.
      5 
      6 These include __attribute((kernel)), 64-bit longs, and RGBA vector syntax.
      7 
      8 Change-Id: I592e5ea2abc86269a941e0497ac11665fb562aa0
      9 ---
     10  include/clang/AST/Type.h            |  8 ++++----
     11  include/clang/Basic/Attr.td         |  5 +++++
     12  include/clang/Basic/LangOptions.def |  1 +
     13  lib/Basic/Targets.cpp               |  2 ++
     14  lib/Sema/SemaDeclAttr.cpp           | 13 +++++++++++++
     15  lib/Sema/SemaExprMember.cpp         | 17 +++++++++++++++++
     16  6 files changed, 42 insertions(+), 4 deletions(-)
     17 
     18 diff --git a/include/clang/AST/Type.h b/include/clang/AST/Type.h
     19 index 001a87e..7be6fcd 100644
     20 --- a/include/clang/AST/Type.h
     21 +++ b/include/clang/AST/Type.h
     22 @@ -2593,10 +2593,10 @@ public:
     23    static int getPointAccessorIdx(char c) {
     24      switch (c) {
     25      default: return -1;
     26 -    case 'x': return 0;
     27 -    case 'y': return 1;
     28 -    case 'z': return 2;
     29 -    case 'w': return 3;
     30 +    case 'x': case 'r': return 0;
     31 +    case 'y': case 'g': return 1;
     32 +    case 'z': case 'b': return 2;
     33 +    case 'w': case 'a': return 3;
     34      }
     35    }
     36    static int getNumericAccessorIdx(char c) {
     37 diff --git a/include/clang/Basic/Attr.td b/include/clang/Basic/Attr.td
     38 index 12a8517..7360683 100644
     39 --- a/include/clang/Basic/Attr.td
     40 +++ b/include/clang/Basic/Attr.td
     41 @@ -612,6 +612,11 @@ def OpenCLConstantAddressSpace : TypeAttr {
     42    let Documentation = [Undocumented];
     43  }
     44  
     45 +def Kernel : Attr {
     46 +  let Spellings = [GNU<"kernel">];
     47 +  let Documentation = [Undocumented];
     48 +}
     49 +
     50  def Deprecated : InheritableAttr {
     51    let Spellings = [GCC<"deprecated">, Declspec<"deprecated">,
     52                     CXX11<"","deprecated">];
     53 diff --git a/include/clang/Basic/LangOptions.def b/include/clang/Basic/LangOptions.def
     54 index 22662e0..7b21482 100644
     55 --- a/include/clang/Basic/LangOptions.def
     56 +++ b/include/clang/Basic/LangOptions.def
     57 @@ -123,6 +123,7 @@ LANGOPT(OpenCLVersion     , 32, 0, "OpenCL version")
     58  LANGOPT(NativeHalfType    , 1, 0, "Native half type support")
     59  LANGOPT(CUDA              , 1, 0, "CUDA")
     60  LANGOPT(OpenMP            , 1, 0, "OpenMP support")
     61 +LANGOPT(Renderscript      , 1, 0, "RenderScript")
     62  
     63  LANGOPT(AssumeSaneOperatorNew , 1, 1, "implicit __attribute__((malloc)) for C++'s new operators")
     64  LANGOPT(SizedDeallocation , 1, 0, "enable sized deallocation functions")
     65 diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp
     66 index 3d294ce..fd59c00 100644
     67 --- a/lib/Basic/Targets.cpp
     68 +++ b/lib/Basic/Targets.cpp
     69 @@ -3984,6 +3984,8 @@ public:
     70          FPU |= FPARMV8;
     71        else if (Features[i] == "+neon")
     72          FPU |= NeonFPU;
     73 +      else if (Features[i] == "+long64")
     74 +        LongWidth = LongAlign = 64;  // RenderScript uses a 64-bit long type
     75        else if (Features[i] == "+hwdiv")
     76          HWDiv |= HWDivThumb;
     77        else if (Features[i] == "+hwdiv-arm")
     78 diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp
     79 index 5f60783..38b3c45 100644
     80 --- a/lib/Sema/SemaDeclAttr.cpp
     81 +++ b/lib/Sema/SemaDeclAttr.cpp
     82 @@ -1396,6 +1396,16 @@ static void handleTLSModelAttr(Sema &S, Decl *D,
     83                            Attr.getAttributeSpellingListIndex()));
     84  }
     85  
     86 +static void handleKernelAttr(Sema &S, Decl *D, const AttributeList &Attr) {
     87 +  if (S.LangOpts.Renderscript) {
     88 +    D->addAttr(::new (S.Context) 
     89 +               KernelAttr(Attr.getRange(), S.Context,
     90 +                          Attr.getAttributeSpellingListIndex()));
     91 +  } else {
     92 +    S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << "kernel";
     93 +  }
     94 +}
     95 +
     96  static void handleMallocAttr(Sema &S, Decl *D, const AttributeList &Attr) {
     97    if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
     98      QualType RetTy = FD->getReturnType();
     99 @@ -4130,6 +4140,9 @@ static void ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D,
    100    case AttributeList::AT_CUDALaunchBounds:
    101      handleLaunchBoundsAttr(S, D, Attr);
    102      break;
    103 +  case AttributeList::AT_Kernel:
    104 +    handleKernelAttr(S, D, Attr);
    105 +    break;
    106    case AttributeList::AT_Malloc:
    107      handleMallocAttr(S, D, Attr);
    108      break;
    109 diff --git a/lib/Sema/SemaExprMember.cpp b/lib/Sema/SemaExprMember.cpp
    110 index 354dfcf..c4a1780 100644
    111 --- a/lib/Sema/SemaExprMember.cpp
    112 +++ b/lib/Sema/SemaExprMember.cpp
    113 @@ -267,6 +267,20 @@ Sema::BuildPossibleImplicitMemberExpr(const CXXScopeSpec &SS,
    114    llvm_unreachable("unexpected instance member access kind");
    115  }
    116  
    117 +/// Determine whether input char is from rgba component set.
    118 +static bool
    119 +IsRGBA(char c) {
    120 +  switch (c) {
    121 +  case 'r':
    122 +  case 'g':
    123 +  case 'b':
    124 +  case 'a':
    125 +    return true;
    126 +  default:
    127 +    return false;
    128 +  }
    129 +}
    130 +
    131  /// Check an ext-vector component access expression.
    132  ///
    133  /// VK should be set in advance to the value kind of the base
    134 @@ -306,7 +320,10 @@ CheckExtVectorComponent(Sema &S, QualType baseType, ExprValueKind &VK,
    135      HalvingSwizzle = true;
    136    } else if (!HexSwizzle &&
    137               (Idx = vecType->getPointAccessorIdx(*compStr)) != -1) {
    138 +    bool HasRGBA = IsRGBA(*compStr);
    139      do {
    140 +      if (HasRGBA != IsRGBA(*compStr))
    141 +        break;
    142        if (HasIndex[Idx]) HasRepeated = true;
    143        HasIndex[Idx] = true;
    144        compStr++;
    145 -- 
    146 1.9.1.423.g4596e3a
    147 
    148