vcc: Track the built-in subs which static calls originate from

We use another "method" bitmask to record the built-in subs from which
static calls originate.

This allows us to indentify those subs which are called from
housekeeping only, allowing us to selectively disable compiler
optimizations.

VGC diff for the example from
https://github.com/varnishcache/varnish-cache/issues/3545#issue-824634168

```diff
@@ -2242,7 +2278,7 @@

 #define END_ if (*ctx->handling) return

-void v_matchproto_(vcl_func_f)
+void v_dont_optimize v_matchproto_(vcl_func_f)
 VGC_function_a(VRT_CTX, enum vcl_func_call_e call,
     enum vcl_func_fail_e *failp)
 {
```

Fixes #3545
parent 606977bb
......@@ -191,7 +191,9 @@ vcc_EmitProc(struct vcc *tl, struct proc *p)
maskcmp = "&";
}
if ((mask & VCL_MET_TASK_H) && (mask & ~VCL_MET_TASK_H) == 0)
if (dyn == 0 &&
(p->calledfrom & VCL_MET_TASK_H) != 0 &&
(p->calledfrom & ~VCL_MET_TASK_H) == 0)
cc_adv = "v_dont_optimize ";
else
cc_adv = "";
......@@ -210,6 +212,7 @@ vcc_EmitProc(struct vcc *tl, struct proc *p)
Fh(tl, 1, "\t.n\t\t= %d,\n", nsub);
Fh(tl, 1, "\t.nref\t\t= %d,\n", p->sym->nref);
Fh(tl, 1, "\t.called\t\t= %d\n", p->called);
Fh(tl, 1, "\t// calledfrom\t 0x%x\n", p->calledfrom);
Fh(tl, 1, "}};\n");
if (dyn) {
......
......@@ -213,6 +213,7 @@ struct proc {
unsigned called;
unsigned active;
unsigned okmask;
unsigned calledfrom;
struct token *return_tok[VCL_RET_MAX];
struct vsb *cname;
struct vsb *prologue;
......
......@@ -207,6 +207,7 @@ vcc_CheckActionRecurse(struct vcc *tl, struct proc *p, unsigned bitmap)
vcc_ErrWhere(tl, pc->t);
return (1);
}
pc->sym->proc->calledfrom |= p->calledfrom;
pc->sym->proc->called++;
pc->sym->nref += u;
if (vcc_CheckActionRecurse(tl, pc->sym->proc, bitmap)) {
......@@ -233,10 +234,12 @@ vcc_checkaction(struct vcc *tl, const struct symbol *sym)
AN(p);
AN(p->name);
if (p->method == NULL)
if (p->method == NULL) {
bitmap = ~0U;
else
} else {
bitmap = p->method->ret_bitmap;
p->calledfrom = p->method->bitval;
}
if (! vcc_CheckActionRecurse(tl, p, bitmap))
return;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment