mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Merge remote-tracking branch 'origin/topic/vern/ZAM-empty-hook-opt'
* origin/topic/vern/ZAM-empty-hook-opt: ZAM optimization now removes hook calls to hooks without any bodies
This commit is contained in:
commit
9efa12b055
3 changed files with 28 additions and 6 deletions
|
@ -1458,6 +1458,7 @@ protected:
|
||||||
bool IsFoldableBiF() const;
|
bool IsFoldableBiF() const;
|
||||||
bool AllConstArgs() const;
|
bool AllConstArgs() const;
|
||||||
bool CheckForBuiltin() const;
|
bool CheckForBuiltin() const;
|
||||||
|
bool IsEmptyHook() const;
|
||||||
ExprPtr TransformToBuiltin();
|
ExprPtr TransformToBuiltin();
|
||||||
|
|
||||||
ExprPtr func;
|
ExprPtr func;
|
||||||
|
|
|
@ -2249,7 +2249,7 @@ ExprPtr CallExpr::Inline(Inliner* inl) {
|
||||||
|
|
||||||
bool CallExpr::IsReduced(Reducer* c) const { return func->IsSingleton(c) && args->IsReduced(c) && ! WillTransform(c); }
|
bool CallExpr::IsReduced(Reducer* c) const { return func->IsSingleton(c) && args->IsReduced(c) && ! WillTransform(c); }
|
||||||
|
|
||||||
bool CallExpr::WillTransform(Reducer* c) const { return CheckForBuiltin() || IsFoldableBiF(); }
|
bool CallExpr::WillTransform(Reducer* c) const { return CheckForBuiltin() || IsFoldableBiF() || IsEmptyHook(); }
|
||||||
|
|
||||||
bool CallExpr::HasReducedOps(Reducer* c) const {
|
bool CallExpr::HasReducedOps(Reducer* c) const {
|
||||||
if ( WillTransform(c) )
|
if ( WillTransform(c) )
|
||||||
|
@ -2280,6 +2280,12 @@ ExprPtr CallExpr::Reduce(Reducer* c, StmtPtr& red_stmt) {
|
||||||
if ( ! func->IsSingleton(c) )
|
if ( ! func->IsSingleton(c) )
|
||||||
func = func->ReduceToSingleton(c, red_stmt);
|
func = func->ReduceToSingleton(c, red_stmt);
|
||||||
|
|
||||||
|
if ( IsEmptyHook() ) {
|
||||||
|
// Reduce the arguments to pick up any side effects they include.
|
||||||
|
(void)args->Reduce(c, red_stmt);
|
||||||
|
return with_location_of(make_intrusive<ConstExpr>(val_mgr->True()), this);
|
||||||
|
}
|
||||||
|
|
||||||
StmtPtr red2_stmt = args->ReduceToSingletons(c);
|
StmtPtr red2_stmt = args->ReduceToSingletons(c);
|
||||||
|
|
||||||
red_stmt = MergeStmts(red_stmt, std::move(red2_stmt));
|
red_stmt = MergeStmts(red_stmt, std::move(red2_stmt));
|
||||||
|
@ -2357,6 +2363,22 @@ ExprPtr CallExpr::TransformToBuiltin() {
|
||||||
return with_location_of(make_intrusive<ScriptOptBuiltinExpr>(kf, this_ptr), this);
|
return with_location_of(make_intrusive<ScriptOptBuiltinExpr>(kf, this_ptr), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CallExpr::IsEmptyHook() const {
|
||||||
|
if ( func->Tag() != EXPR_NAME )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
auto func_id = func->AsNameExpr()->IdPtr();
|
||||||
|
auto func_val = func_id->GetVal();
|
||||||
|
|
||||||
|
if ( ! func_val || ! func_id->IsGlobal() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if ( func_id->GetType()->AsFuncType()->Flavor() != FUNC_FLAVOR_HOOK )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return ! func_val->AsFuncVal()->Get()->HasBodies();
|
||||||
|
}
|
||||||
|
|
||||||
ExprPtr LambdaExpr::Duplicate() { return SetSucc(new LambdaExpr(this)); }
|
ExprPtr LambdaExpr::Duplicate() { return SetSucc(new LambdaExpr(this)); }
|
||||||
|
|
||||||
bool LambdaExpr::IsReduced(Reducer* c) const {
|
bool LambdaExpr::IsReduced(Reducer* c) const {
|
||||||
|
|
|
@ -119,7 +119,7 @@ StmtPtr ExprStmt::DoReduce(Reducer* c) {
|
||||||
|
|
||||||
auto t = e->Tag();
|
auto t = e->Tag();
|
||||||
|
|
||||||
if ( t == EXPR_NOP )
|
if ( t == EXPR_NOP || t == EXPR_CONST )
|
||||||
return TransformMe(make_intrusive<NullStmt>(), c);
|
return TransformMe(make_intrusive<NullStmt>(), c);
|
||||||
|
|
||||||
if ( c->Optimizing() ) {
|
if ( c->Optimizing() ) {
|
||||||
|
@ -138,10 +138,9 @@ StmtPtr ExprStmt::DoReduce(Reducer* c) {
|
||||||
|
|
||||||
StmtPtr red_e_stmt;
|
StmtPtr red_e_stmt;
|
||||||
|
|
||||||
if ( t == EXPR_CALL )
|
if ( t == EXPR_CALL && ! e->WillTransform(c) )
|
||||||
// A bare call. If we reduce it regularly, if
|
// A bare call. If we reduce it regularly, if it has a non-void
|
||||||
// it has a non-void type it'll generate an
|
// type it'll generate an assignment to a temporary.
|
||||||
// assignment to a temporary.
|
|
||||||
red_e_stmt = e->ReduceToSingletons(c);
|
red_e_stmt = e->ReduceToSingletons(c);
|
||||||
else {
|
else {
|
||||||
e = e->Reduce(c, red_e_stmt);
|
e = e->Reduce(c, red_e_stmt);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue