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
parent b169266e
......@@ -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
*/
......
......@@ -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);
......
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