ZAM speedup for constructing empty vectors

This commit is contained in:
Vern Paxson 2024-01-14 09:06:47 -08:00 committed by Arne Welzel
parent 4bd0a46c29
commit 96f5de8df8
2 changed files with 28 additions and 0 deletions

View file

@ -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;
};

View file

@ -1944,6 +1944,30 @@ ExprPtr VectorCoerceExpr::Duplicate() {
return SetSucc(new VectorCoerceExpr(op_dup, GetType<VectorType>()));
}
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<VectorType>()->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<ListExpr>(op1_list);
auto new_me = make_intrusive<VectorConstructorExpr>(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();