[master] cf9548efe vcc: Track the built-in subs which static calls originate from
Nils Goroll
nils.goroll at uplex.de
Sat Apr 10 12:34:06 UTC 2021
commit cf9548efe2770e1597c49903f065572aaad96fd6
Author: Nils Goroll <nils.goroll at uplex.de>
Date: Sat Apr 10 14:18:22 2021 +0200
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
diff --git a/lib/libvcc/vcc_compile.c b/lib/libvcc/vcc_compile.c
index 906567977..88c8baf5b 100644
--- a/lib/libvcc/vcc_compile.c
+++ b/lib/libvcc/vcc_compile.c
@@ -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) {
diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h
index b52c53216..1ec423b30 100644
--- a/lib/libvcc/vcc_compile.h
+++ b/lib/libvcc/vcc_compile.h
@@ -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;
diff --git a/lib/libvcc/vcc_xref.c b/lib/libvcc/vcc_xref.c
index e3351ec48..433f5e7b8 100644
--- a/lib/libvcc/vcc_xref.c
+++ b/lib/libvcc/vcc_xref.c
@@ -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;
More information about the varnish-commit
mailing list