[cfe-commits] r40780 - in /cfe/trunk/CodeGen: CGExpr.cpp CodeGenFunction.h

Chris Lattner sabre at nondot.org
Fri Aug 3 09:18:34 PDT 2007


Author: lattner
Date: Fri Aug  3 11:18:34 2007
New Revision: 40780

URL: http://llvm.org/viewvc/llvm-project?rev=40780&view=rev
Log:
refactor handling of ocuvector lvalue->rvalue codegen into its own method.

Modified:
    cfe/trunk/CodeGen/CGExpr.cpp
    cfe/trunk/CodeGen/CodeGenFunction.h

Modified: cfe/trunk/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGExpr.cpp?rev=40780&r1=40779&r2=40780&view=diff

==============================================================================
--- cfe/trunk/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/CodeGen/CGExpr.cpp Fri Aug  3 11:18:34 2007
@@ -285,58 +285,65 @@
 
   // If this is a reference to a subset of the elements of a vector, either
   // shuffle the input or extract/insert them as appropriate.
-  if (LV.isOCUVectorComp()) {
-    llvm::Value *Vec = Builder.CreateLoad(LV.getOCUVectorAddr(), "tmp");
-
-    unsigned EncFields = LV.getOCUVectorComp();
+  if (LV.isOCUVectorComp())
+    return EmitLoadOfOCUComponentLValue(LV, ExprType);
+  
+  assert(0 && "Bitfield ref not impl!");
+}
 
-    // If the result of the expression is a non-vector type, we must be
-    // extracting a single element.  Just codegen as an extractelement.
-    if (!isa<VectorType>(ExprType)) {
-      unsigned InIdx = OCUVectorComponent::getAccessedFieldNo(0, EncFields);
-      llvm::Value *Elt = llvm::ConstantInt::get(llvm::Type::Int32Ty, InIdx);
-      return RValue::get(Builder.CreateExtractElement(Vec, Elt, "tmp"));
-    }
-    
-    // If the source and destination have the same number of elements, use a
-    // vector shuffle instead of insert/extracts.
-    unsigned NumResultElts = cast<VectorType>(ExprType)->getNumElements();
-    unsigned NumSourceElts =
-      cast<llvm::VectorType>(Vec->getType())->getNumElements();
-    
-    if (NumResultElts == NumSourceElts) {
-      llvm::SmallVector<llvm::Constant*, 4> Mask;
-      for (unsigned i = 0; i != NumResultElts; ++i) {
-        unsigned InIdx = OCUVectorComponent::getAccessedFieldNo(i, EncFields);
-        Mask.push_back(llvm::ConstantInt::get(llvm::Type::Int32Ty, InIdx));
-      }
-      
-      llvm::Value *MaskV = llvm::ConstantVector::get(&Mask[0], Mask.size());
-      Vec = Builder.CreateShuffleVector(Vec,
-                                        llvm::UndefValue::get(Vec->getType()),
-                                        MaskV, "tmp");
-      return RValue::get(Vec);
-    }
-    
-    // Start out with an undef of the result type.
-    llvm::Value *Result = llvm::UndefValue::get(ConvertType(ExprType));
-    
-    // Extract/Insert each element of the result.
+// If this is a reference to a subset of the elements of a vector, either
+// shuffle the input or extract/insert them as appropriate.
+RValue CodeGenFunction::EmitLoadOfOCUComponentLValue(LValue LV,
+                                                     QualType ExprType) {
+  llvm::Value *Vec = Builder.CreateLoad(LV.getOCUVectorAddr(), "tmp");
+  
+  unsigned EncFields = LV.getOCUVectorComp();
+  
+  // If the result of the expression is a non-vector type, we must be
+  // extracting a single element.  Just codegen as an extractelement.
+  if (!isa<VectorType>(ExprType)) {
+    unsigned InIdx = OCUVectorComponent::getAccessedFieldNo(0, EncFields);
+    llvm::Value *Elt = llvm::ConstantInt::get(llvm::Type::Int32Ty, InIdx);
+    return RValue::get(Builder.CreateExtractElement(Vec, Elt, "tmp"));
+  }
+  
+  // If the source and destination have the same number of elements, use a
+  // vector shuffle instead of insert/extracts.
+  unsigned NumResultElts = cast<VectorType>(ExprType)->getNumElements();
+  unsigned NumSourceElts =
+    cast<llvm::VectorType>(Vec->getType())->getNumElements();
+  
+  if (NumResultElts == NumSourceElts) {
+    llvm::SmallVector<llvm::Constant*, 4> Mask;
     for (unsigned i = 0; i != NumResultElts; ++i) {
       unsigned InIdx = OCUVectorComponent::getAccessedFieldNo(i, EncFields);
-      llvm::Value *Elt = llvm::ConstantInt::get(llvm::Type::Int32Ty, InIdx);
-      Elt = Builder.CreateExtractElement(Vec, Elt, "tmp");
-
-      llvm::Value *OutIdx = llvm::ConstantInt::get(llvm::Type::Int32Ty, i);
-      Result = Builder.CreateInsertElement(Result, Elt, OutIdx, "tmp");
+      Mask.push_back(llvm::ConstantInt::get(llvm::Type::Int32Ty, InIdx));
     }
     
-    return RValue::get(Result);
+    llvm::Value *MaskV = llvm::ConstantVector::get(&Mask[0], Mask.size());
+    Vec = Builder.CreateShuffleVector(Vec,
+                                      llvm::UndefValue::get(Vec->getType()),
+                                      MaskV, "tmp");
+    return RValue::get(Vec);
   }
   
-  assert(0 && "Bitfield ref not impl!");
+  // Start out with an undef of the result type.
+  llvm::Value *Result = llvm::UndefValue::get(ConvertType(ExprType));
+  
+  // Extract/Insert each element of the result.
+  for (unsigned i = 0; i != NumResultElts; ++i) {
+    unsigned InIdx = OCUVectorComponent::getAccessedFieldNo(i, EncFields);
+    llvm::Value *Elt = llvm::ConstantInt::get(llvm::Type::Int32Ty, InIdx);
+    Elt = Builder.CreateExtractElement(Vec, Elt, "tmp");
+    
+    llvm::Value *OutIdx = llvm::ConstantInt::get(llvm::Type::Int32Ty, i);
+    Result = Builder.CreateInsertElement(Result, Elt, OutIdx, "tmp");
+  }
+  
+  return RValue::get(Result);
 }
 
+
 RValue CodeGenFunction::EmitLoadOfLValue(const Expr *E) {
   return EmitLoadOfLValue(EmitLValue(E), E->getType());
 }

Modified: cfe/trunk/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CodeGenFunction.h?rev=40780&r1=40779&r2=40780&view=diff

==============================================================================
--- cfe/trunk/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/CodeGen/CodeGenFunction.h Fri Aug  3 11:18:34 2007
@@ -316,7 +316,9 @@
   /// rvalue, returning the rvalue.
   RValue EmitLoadOfLValue(const Expr *E);
   RValue EmitLoadOfLValue(LValue V, QualType LVType);
+  RValue EmitLoadOfOCUComponentLValue(LValue V, QualType LVType);
 
+  
   /// EmitStoreThroughLValue - Store the specified rvalue into the specified
   /// lvalue, where both are guaranteed to the have the same type, and that type
   /// is 'Ty'.





More information about the cfe-commits mailing list