[cfe-commits] r39725 - in /cfe/cfe/trunk/CodeGen: CGExpr.cpp CodeGenFunction.h
clattner at cs.uiuc.edu
clattner at cs.uiuc.edu
Wed Jul 11 09:47:34 PDT 2007
Author: clattner
Date: Wed Jul 11 11:47:34 2007
New Revision: 39725
URL: http://llvm.org/viewvc/llvm-project?rev=39725&view=rev
Log:
implement codegen support for rvalue-only vector subscripts, such as:
float4 test(void);
float test2() {
return test()[1];
}
Modified:
cfe/cfe/trunk/CodeGen/CGExpr.cpp
cfe/cfe/trunk/CodeGen/CodeGenFunction.h
Modified: cfe/cfe/trunk/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/CodeGen/CGExpr.cpp?rev=39725&r1=39724&r2=39725&view=diff
==============================================================================
--- cfe/cfe/trunk/CodeGen/CGExpr.cpp (original)
+++ cfe/cfe/trunk/CodeGen/CGExpr.cpp Wed Jul 11 11:47:34 2007
@@ -453,10 +453,9 @@
if (const EnumConstantDecl *EC =
dyn_cast<EnumConstantDecl>(cast<DeclRefExpr>(E)->getDecl()))
return RValue::get(llvm::ConstantInt::get(EC->getInitVal()));
-
- // FALLTHROUGH
- case Expr::ArraySubscriptExprClass:
return EmitLoadOfLValue(E);
+ case Expr::ArraySubscriptExprClass:
+ return EmitArraySubscriptExprRV(cast<ArraySubscriptExpr>(E));
case Expr::StringLiteralClass:
return RValue::get(EmitLValue(E).getAddress());
@@ -489,6 +488,29 @@
E->getValue()));
}
+
+RValue CodeGenFunction::EmitArraySubscriptExprRV(const ArraySubscriptExpr *E) {
+ // Emit subscript expressions in rvalue context's. For most cases, this just
+ // loads the lvalue formed by the subscript expr. However, we have to be
+ // careful, because the base of a vector subscript is occasionally an rvalue,
+ // so we can't get it as an lvalue.
+ if (!E->getBase()->getType()->isVectorType())
+ return EmitLoadOfLValue(E);
+
+ // Handle the vector case. The base must be a vector, the index must be an
+ // integer value.
+ QualType BaseTy, IdxTy;
+ llvm::Value *Base =
+ EmitExprWithUsualUnaryConversions(E->getBase(), BaseTy).getVal();
+ llvm::Value *Idx =
+ EmitExprWithUsualUnaryConversions(E->getIdx(), IdxTy).getVal();
+
+ // FIXME: Convert Idx to i32 type.
+
+ return RValue::get(Builder.CreateExtractElement(Base, Idx, "vecext"));
+}
+
+
RValue CodeGenFunction::EmitCastExpr(const CastExpr *E) {
QualType SrcTy;
RValue Src = EmitExprWithUsualUnaryConversions(E->getSubExpr(), SrcTy);
Modified: cfe/cfe/trunk/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/CodeGen/CodeGenFunction.h?rev=39725&r1=39724&r2=39725&view=diff
==============================================================================
--- cfe/cfe/trunk/CodeGen/CodeGenFunction.h (original)
+++ cfe/cfe/trunk/CodeGen/CodeGenFunction.h Wed Jul 11 11:47:34 2007
@@ -312,6 +312,7 @@
RValue EmitCastExpr(const CastExpr *E);
RValue EmitCallExpr(const CallExpr *E);
+ RValue EmitArraySubscriptExprRV(const ArraySubscriptExpr *E);
// Unary Operators.
RValue EmitUnaryOperator(const UnaryOperator *E);
More information about the cfe-commits
mailing list