[master] f1c47e486 add v_dont_optimize and enable it for vcl_init / vcl_fini
Nils Goroll
nils.goroll at uplex.de
Mon Mar 2 21:05:09 UTC 2020
commit f1c47e4860f213710bd58f0c41fc1f1437d6c461
Author: Nils Goroll <nils.goroll at uplex.de>
Date: Mon Mar 2 21:47:47 2020 +0100
add v_dont_optimize and enable it for vcl_init / vcl_fini
We add an attribute macro which, for gcc, will disable compiler
optimizations. The intended use are VCL subs which are called exactly
once such that any additional compilation effort is wasteful with
respect to the overall vcl.load time.
We also decorate the vcc-generated C code for vcl_init and vcl_fini
with v_dont_optimize, which is simple and easy:
void v_dont_optimize v_matchproto_(vcl_func_f)
VGC_function_vcl_fini(VRT_CTX)
void v_dont_optimize v_matchproto_(vcl_func_f)
VGC_function_vcl_init(VRT_CTX)
A more difficult improvement is left to be done: Any custom vcl subs
which are called from vcl_init and/or vcl_fini _only_ should also be
decorated with v_dont_optimize.
With the current code base, determining if a custom sub qualifies
would require helper code in vcc_xref to check all uses and return the
usage union.
As #3163 requires a similar mechanism and because we are about to
enter the pre-6.4 release freeze, the better option seems to be to
implement this "use mask" when/if #3163 gets in and come back to this
optimization then.
Closes #3230
diff --git a/include/vdef.h b/include/vdef.h
index 0a60716b0..a9111feb6 100644
--- a/include/vdef.h
+++ b/include/vdef.h
@@ -100,6 +100,12 @@
# define v_deprecated_
#endif
+#if __GNUC_PREREQ__(4,4) // added 2008-07-23
+# define v_dont_optimize __attribute__((optimize("O")))
+#else
+# define v_dont_optimize
+#endif
+
/*********************************************************************
* Pointer alignment magic
*/
diff --git a/lib/libvcc/vcc_compile.c b/lib/libvcc/vcc_compile.c
index b7ccc9cf1..1be668bfd 100644
--- a/lib/libvcc/vcc_compile.c
+++ b/lib/libvcc/vcc_compile.c
@@ -151,7 +151,16 @@ vcc_EmitProc(struct vcc *tl, struct proc *p)
AZ(VSB_finish(p->prologue));
AZ(VSB_finish(p->body));
Fh(tl, 1, "vcl_func_f %s;\n", VSB_data(p->cname));
- Fc(tl, 1, "\nvoid v_matchproto_(vcl_func_f)\n");
+ /*
+ * TODO: v_dont_optimize for custom subs called from vcl_init/fini only
+ *
+ * Needs infrastructure similar to that in #3163 : custom subs need a
+ * mask containing the builtin subs calling the custom sub. If that is
+ * no larger than VCL_MET_TASK_H, we can enable v_dont_optimize
+ */
+ Fc(tl, 1, "\nvoid %sv_matchproto_(vcl_func_f)\n",
+ p->method && p->method->bitval & VCL_MET_TASK_H ?
+ "v_dont_optimize " : "");
Fc(tl, 1, "%s(VRT_CTX)\n", VSB_data(p->cname));
Fc(tl, 1, "{\n%s\n%s}\n", VSB_data(p->prologue), VSB_data(p->body));
VSB_destroy(&p->body);
More information about the varnish-commit
mailing list