]> granicus.if.org Git - clang/commitdiff
add codegen support for storing into a single-element ocu lvalue, such as:
authorChris Lattner <sabre@nondot.org>
Fri, 3 Aug 2007 16:28:33 +0000 (16:28 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 3 Aug 2007 16:28:33 +0000 (16:28 +0000)
    vec2.x = f;

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

CodeGen/CGExpr.cpp
CodeGen/CodeGenFunction.h

index 31b9e2f6a39047065bdf73e4c2f5a75659ce34d9..32cb02d644762e95ec37298474fa38d2a075c2de 100644 (file)
@@ -354,17 +354,23 @@ RValue CodeGenFunction::EmitLoadOfLValue(const Expr *E) {
 /// is 'Ty'.
 void CodeGenFunction::EmitStoreThroughLValue(RValue Src, LValue Dst, 
                                              QualType Ty) {
-  if (Dst.isVectorElt()) {
-    // Read/modify/write the vector, inserting the new element.
-    // FIXME: Volatility.
-    llvm::Value *Vec = Builder.CreateLoad(Dst.getVectorAddr(), "tmp");
-    Vec = Builder.CreateInsertElement(Vec, Src.getVal(),
-                                      Dst.getVectorIdx(), "vecins");
-    Builder.CreateStore(Vec, Dst.getVectorAddr());
-    return;
-  }
+  if (!Dst.isSimple()) {
+    if (Dst.isVectorElt()) {
+      // Read/modify/write the vector, inserting the new element.
+      // FIXME: Volatility.
+      llvm::Value *Vec = Builder.CreateLoad(Dst.getVectorAddr(), "tmp");
+      Vec = Builder.CreateInsertElement(Vec, Src.getVal(),
+                                        Dst.getVectorIdx(), "vecins");
+      Builder.CreateStore(Vec, Dst.getVectorAddr());
+      return;
+    }
+  
+    // If this is an update of elements of a vector, insert them as appropriate.
+    if (Dst.isOCUVectorComp())
+      return EmitStoreThroughOCUComponentLValue(Src, Dst, Ty);
   
-  assert(Dst.isSimple() && "FIXME: Don't support store to bitfield yet");
+    assert(0 && "FIXME: Don't support store to bitfield yet");
+  }
   
   llvm::Value *DstAddr = Dst.getAddress();
   if (Src.isScalar()) {
@@ -411,6 +417,29 @@ void CodeGenFunction::EmitStoreThroughLValue(RValue Src, LValue Dst,
   Builder.CreateCall(CGM.getMemCpyFn(), MemCpyOps, MemCpyOps+4);
 }
 
+void CodeGenFunction::EmitStoreThroughOCUComponentLValue(RValue Src, LValue Dst, 
+                                                         QualType Ty) {
+  // This access turns into a read/modify/write of the vector.  Load the input
+  // value now.
+  llvm::Value *Vec = Builder.CreateLoad(Dst.getOCUVectorAddr(), "tmp");
+  // FIXME: Volatility.
+  unsigned EncFields = Dst.getOCUVectorComp();
+  
+  llvm::Value *SrcVal = Src.getVal();
+  
+  // If the Src is a scalar (not a vector) it must be updating a single element.
+  if (!Ty->isVectorType()) {
+    unsigned InIdx = OCUVectorComponent::getAccessedFieldNo(0, EncFields);
+    llvm::Value *Elt = llvm::ConstantInt::get(llvm::Type::Int32Ty, InIdx);
+    Vec = Builder.CreateInsertElement(Vec, SrcVal, Elt, "tmp");
+  } else {
+    
+  }
+  
+  
+  Builder.CreateStore(Vec, Dst.getOCUVectorAddr());
+}
+
 
 LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) {
   const Decl *D = E->getDecl();
index 2ac8e8035af7357eb14490d5e0ed8def8c77d5fb..d8f1571b38bd5223eba7a99ad73fa41842bc25d4 100644 (file)
@@ -323,6 +323,7 @@ public:
   /// lvalue, where both are guaranteed to the have the same type, and that type
   /// is 'Ty'.
   void EmitStoreThroughLValue(RValue Src, LValue Dst, QualType Ty);
+  void EmitStoreThroughOCUComponentLValue(RValue Src, LValue Dst, QualType Ty);
   
   LValue EmitDeclRefLValue(const DeclRefExpr *E);
   LValue EmitStringLiteralLValue(const StringLiteral *E);