forked from OSchip/llvm-project
implement codegen support for rvalue-only vector subscripts, such as:
float4 test(void); float test2() { return test()[1]; } llvm-svn: 39725
This commit is contained in:
parent
08c4b9ffec
commit
a779b3df28
|
@ -453,10 +453,9 @@ RValue CodeGenFunction::EmitExpr(const Expr *E) {
|
|||
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 @@ RValue CodeGenFunction::EmitFloatingLiteral(const FloatingLiteral *E) {
|
|||
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);
|
||||
|
|
|
@ -312,6 +312,7 @@ public:
|
|||
|
||||
RValue EmitCastExpr(const CastExpr *E);
|
||||
RValue EmitCallExpr(const CallExpr *E);
|
||||
RValue EmitArraySubscriptExprRV(const ArraySubscriptExpr *E);
|
||||
|
||||
// Unary Operators.
|
||||
RValue EmitUnaryOperator(const UnaryOperator *E);
|
||||
|
|
Loading…
Reference in New Issue