diff --git a/src/Expr.h b/src/Expr.h index a45a1528b8..1a56cddea3 100644 --- a/src/Expr.h +++ b/src/Expr.h @@ -1310,6 +1310,10 @@ public: // Optimization-related: ExprPtr Duplicate() override; + bool IsReduced(Reducer* c) const override; + bool WillTransform(Reducer* c) const override; + ExprPtr Reduce(Reducer* c, StmtPtr& red_stmt) override; + protected: ValPtr Fold(Val* v) const override; }; diff --git a/src/script_opt/Expr.cc b/src/script_opt/Expr.cc index 1198c3b573..ec69f0fe0c 100644 --- a/src/script_opt/Expr.cc +++ b/src/script_opt/Expr.cc @@ -1944,6 +1944,30 @@ ExprPtr VectorCoerceExpr::Duplicate() { return SetSucc(new VectorCoerceExpr(op_dup, GetType())); } +bool VectorCoerceExpr::IsReduced(Reducer* c) const { + if ( WillTransform(c) ) + return NonReduced(this); + + return UnaryExpr::IsReduced(c); +} + +bool VectorCoerceExpr::WillTransform(Reducer* c) const { + return op->Tag() == EXPR_VECTOR_CONSTRUCTOR && op->GetType()->IsUnspecifiedVector(); +} + +ExprPtr VectorCoerceExpr::Reduce(Reducer* c, StmtPtr& red_stmt) { + if ( WillTransform(c) ) { + auto op1_list = op->GetOp1(); + ASSERT(op1_list->Tag() == EXPR_LIST); + auto empty_list = cast_intrusive(op1_list); + auto new_me = make_intrusive(empty_list, type); + auto red_e = new_me->Reduce(c, red_stmt); + return TransformMe(std::move(red_e), c, red_stmt); + } + + return UnaryExpr::Reduce(c, red_stmt); +} + ExprPtr ScheduleExpr::Duplicate() { auto when_d = when->Duplicate(); auto event_d = event->Duplicate()->AsEventExprPtr();