]> granicus.if.org Git - clang/commitdiff
add support for codegen of an OCUVectorComponent as an lvalue.
authorChris Lattner <sabre@nondot.org>
Thu, 2 Aug 2007 23:37:31 +0000 (23:37 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 2 Aug 2007 23:37:31 +0000 (23:37 +0000)
We can now codegen:

  vec4.xy;

as nothing!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40769 91177308-0d34-0410-b5e6-96231b3b80d8

CodeGen/CGExpr.cpp
CodeGen/CodeGenFunction.h

index a8a7b3608f8f07ec53e2681392d41a72e64c9184..1a841f9d81d0fbdfb497b76fe1d973669a814a89 100644 (file)
@@ -253,6 +253,8 @@ LValue CodeGenFunction::EmitLValue(const Expr *E) {
     return EmitUnaryOpLValue(cast<UnaryOperator>(E));
   case Expr::ArraySubscriptExprClass:
     return EmitArraySubscriptExpr(cast<ArraySubscriptExpr>(E));
+  case Expr::OCUVectorComponentClass:
+    return EmitOCUVectorComponentExpr(cast<OCUVectorComponent>(E));
   }
 }
 
@@ -471,6 +473,16 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E) {
   return LValue::MakeAddr(Builder.CreateGEP(Base, Idx, "arrayidx"));
 }
 
+LValue CodeGenFunction::
+EmitOCUVectorComponentExpr(const OCUVectorComponent *E) {
+  // Emit the base vector as an l-value.
+  LValue Base = EmitLValue(E->getBase());
+  assert(Base.isSimple() && "Can only subscript lvalue vectors here!");
+
+  return LValue::MakeOCUVectorComp(Base.getAddress(), 
+                                   E->getEncodedElementAccess());
+}
+
 //===--------------------------------------------------------------------===//
 //                             Expression Emission
 //===--------------------------------------------------------------------===//
index d82c787eaea8c23372c76fdba9c888671fee5e16..37614e95f060217d38644a60f3051508831c233f 100644 (file)
@@ -54,6 +54,7 @@ namespace clang {
   class BinaryOperator;
   class CompoundAssignOperator;
   class ArraySubscriptExpr;
+  class OCUVectorComponent;
   class ConditionalOperator;
   class PreDefinedExpr;
   
@@ -116,26 +117,35 @@ class LValue {
   // alignment?
   
   enum {
-    Simple,    // This is a normal l-value, use getAddress().
-    VectorElt, // This is a vector element l-value (V[i]), use getVector*
-    BitField   // This is a bitfield l-value, use getBitfield*.
+    Simple,       // This is a normal l-value, use getAddress().
+    VectorElt,    // This is a vector element l-value (V[i]), use getVector*
+    BitField,     // This is a bitfield l-value, use getBitfield*.
+    OCUVectorComp // This is an ocu vector subset, use getOCUVectorComp
   } LVType;
   
   llvm::Value *V;
   
   union {
-    llvm::Value *VectorIdx;
+    llvm::Value *VectorIdx;   // Index into a vector subscript: V[i]
+    unsigned VectorComp;      // Encoded OCUVector element subset: V.xyx
   };
 public:
   bool isSimple() const { return LVType == Simple; }
   bool isVectorElt() const { return LVType == VectorElt; }
   bool isBitfield() const { return LVType == BitField; }
+  bool isOCUVectorComp() const { return LVType == OCUVectorComp; }
   
   // simple lvalue
   llvm::Value *getAddress() const { assert(isSimple()); return V; }
   // vector elt lvalue
   llvm::Value *getVectorAddr() const { assert(isVectorElt()); return V; }
   llvm::Value *getVectorIdx() const { assert(isVectorElt()); return VectorIdx; }
+  // ocu vector components.
+  unsigned getOCUVectorComp() const {
+    assert(isOCUVectorComp());
+    return VectorComp;
+  }
+  
   
   static LValue MakeAddr(llvm::Value *V) {
     LValue R;
@@ -152,6 +162,13 @@ public:
     return R;
   }
   
+  static LValue MakeOCUVectorComp(llvm::Value *Vec, unsigned Components) {
+    LValue R;
+    R.LVType = VectorElt;
+    R.V = Vec;
+    R.VectorComp = Components;
+    return R;
+  }
 };
 
 /// CodeGenFunction - This class organizes the per-function state that is used
@@ -309,6 +326,7 @@ public:
   LValue EmitPreDefinedLValue(const PreDefinedExpr *E);
   LValue EmitUnaryOpLValue(const UnaryOperator *E);
   LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E);
+  LValue EmitOCUVectorComponentExpr(const OCUVectorComponent *E);
     
   //===--------------------------------------------------------------------===//
   //                             Expression Emission