Skip to content

Commit

Permalink
vcc: Track the built-in subs which static calls originate from
Browse files Browse the repository at this point in the history
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
#3545 (comment)

```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
  • Loading branch information
nigoroll committed Apr 10, 2021
1 parent 606977b commit cf9548e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
5 changes: 4 additions & 1 deletion lib/libvcc/vcc_compile.c
Expand Up @@ -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 = "";
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions lib/libvcc/vcc_compile.h
Expand Up @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions lib/libvcc/vcc_xref.c
Expand Up @@ -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)) {
Expand All @@ -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;
Expand Down

0 comments on commit cf9548e

Please sign in to comment.