[master] d86a90ee6 vcc: Repurpose (struct proc).called and add info to struct vcl_sub

Nils Goroll nils.goroll at uplex.de
Mon Feb 8 17:52:03 UTC 2021


commit d86a90ee699e02b1e61b738107e26d057ec34886
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Fri Jan 29 14:37:35 2021 +0100

    vcc: Repurpose (struct proc).called and add info to struct vcl_sub
    
    The .called attribute was not used.
    
    We now increment it only for custom subs which are actually called
    statically (with "call"), that is, not for the builtin subs. This is
    to simplify and clarify the use case in the next commits.
    
    The increment happens for each VCC walk of the SUBs.
    
    We also add the number of symbolic references and calls to (struct
    vcl_sub) of the VGC to facilitate reviews and debugging.

diff --git a/include/vcc_interface.h b/include/vcc_interface.h
index 32f09b970..4c2a5c295 100644
--- a/include/vcc_interface.h
+++ b/include/vcc_interface.h
@@ -92,4 +92,6 @@ struct vcl_sub {
 	const struct VCL_conf	*vcl_conf;
 	vcl_func_f		*func;
 	unsigned		n;
+	unsigned		nref;
+	unsigned		called;
 };
diff --git a/lib/libvcc/vcc_compile.c b/lib/libvcc/vcc_compile.c
index 78457763d..f3a87aa39 100644
--- a/lib/libvcc/vcc_compile.c
+++ b/lib/libvcc/vcc_compile.c
@@ -176,6 +176,7 @@ vcc_EmitProc(struct vcc *tl, struct proc *p)
 	AZ(VSB_finish(p->cname));
 	AZ(VSB_finish(p->prologue));
 	AZ(VSB_finish(p->body));
+	AN(p->sym);
 
 	Fh(tl, 1, "vcl_func_f %s;\n", VSB_data(p->cname));
 	Fh(tl, 1, "const struct vcl_sub sub_%s[1] = {{\n",
@@ -185,7 +186,9 @@ vcc_EmitProc(struct vcc *tl, struct proc *p)
 	Fh(tl, 1, "\t.name\t\t= \"%.*s\",\n", PF(p->name));
 	Fh(tl, 1, "\t.vcl_conf\t= &VCL_conf,\n");
 	Fh(tl, 1, "\t.func\t\t= %s,\n", VSB_data(p->cname));
-	Fh(tl, 1, "\t.n\t\t= %d\n", tl->nsub++);
+	Fh(tl, 1, "\t.n\t\t= %d,\n", tl->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, "}};\n");
 	/*
 	 * TODO: v_dont_optimize for custom subs called from vcl_init/fini only
diff --git a/lib/libvcc/vcc_xref.c b/lib/libvcc/vcc_xref.c
index c2e63ed76..55a4198de 100644
--- a/lib/libvcc/vcc_xref.c
+++ b/lib/libvcc/vcc_xref.c
@@ -203,6 +203,7 @@ vcc_CheckActionRecurse(struct vcc *tl, struct proc *p, unsigned bitmap)
 			vcc_ErrWhere(tl, pc->t);
 			return (1);
 		}
+		pc->sym->proc->called++;
 		if (vcc_CheckActionRecurse(tl, pc->sym->proc, bitmap)) {
 			VSB_printf(tl->sb, "\n...called from \"%.*s\"\n",
 			    PF(p->name));
@@ -212,7 +213,6 @@ vcc_CheckActionRecurse(struct vcc *tl, struct proc *p, unsigned bitmap)
 		p->okmask &= pc->sym->proc->okmask;
 	}
 	p->active = 0;
-	p->called++;
 	return (0);
 }
 


More information about the varnish-commit mailing list