~lattis/muon

add b_pgo support for gcc-like compilers v1 APPLIED

Owen Rafferty: 1
 add b_pgo support for gcc-like compilers

 3 files changed, 66 insertions(+), 4 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~lattis/muon/patches/34099/mbox | git am -3
Learn more about email & git

[PATCH] add b_pgo support for gcc-like compilers Export this patch

---
 include/compilers.h       |  7 +++++++
 src/backend/common_args.c | 38 ++++++++++++++++++++++++++++++++++----
 src/compilers.c           | 25 +++++++++++++++++++++++++
 3 files changed, 66 insertions(+), 4 deletions(-)

diff --git a/include/compilers.h b/include/compilers.h
index c0915d3..ee9fa7b 100644
--- a/include/compilers.h
+++ b/include/compilers.h
@@ -52,6 +52,11 @@ enum compiler_optimization_lvl {
	compiler_optimization_lvl_s,
};

enum compiler_pgo_stage {
	compiler_pgo_generate,
	compiler_pgo_use,
};

enum compiler_warning_lvl {
	compiler_warning_lvl_0,
	compiler_warning_lvl_1,
@@ -85,6 +90,7 @@ struct compiler {
		compiler_get_arg_func_1s set_std;
		compiler_get_arg_func_1s include;
		compiler_get_arg_func_1s include_system;
		compiler_get_arg_func_1i pgo;
		compiler_get_arg_func_0 pic;
		compiler_get_arg_func_0 pie;
		compiler_get_arg_func_1s sanitize;
@@ -105,6 +111,7 @@ struct linker {
		compiler_get_arg_func_0 shared;
		compiler_get_arg_func_1s soname;
		compiler_get_arg_func_1s rpath;
		compiler_get_arg_func_1i pgo;
		compiler_get_arg_func_1s sanitize;
		compiler_get_arg_func_0 allow_shlib_undefined;
		compiler_get_arg_func_0 export_dynamic;
diff --git a/src/backend/common_args.c b/src/backend/common_args.c
index 02022af..794ac4a 100644
--- a/src/backend/common_args.c
+++ b/src/backend/common_args.c
@@ -236,6 +236,21 @@ setup_optional_b_args_compiler(struct workspace *wk, const struct project *proj,
#endif

	obj opt;
	get_option_value_for_tgt(wk, proj, tgt, "b_pgo", &opt);
	if (!str_eql(get_str(wk, opt), &WKSTR("off"))) {
		uint32_t stage;
		const struct str *sl = get_str(wk, opt);
		if (str_eql(sl, &WKSTR("generate"))) {
			stage = 0;
		} else if (str_eql(sl, &WKSTR("use"))) {
			stage = 1;
		} else {
			UNREACHABLE;
			return;
		}
		push_args(wk, args, compilers[t].args.pgo(stage));
	}

	get_option_value_for_tgt(wk, proj, tgt, "b_sanitize", &opt);
	if (!str_eql(get_str(wk, opt), &WKSTR("none"))) {
		push_args(wk, args, compilers[t].args.sanitize(get_cstr(wk, opt)));
@@ -411,10 +426,25 @@ setup_optional_b_args_linker(struct workspace *wk, const struct project *proj,
	return true;
#endif

	obj b_sanitize;
	get_option_value_for_tgt(wk, proj, tgt, "b_sanitize", &b_sanitize);
	if (strcmp(get_cstr(wk, b_sanitize), "none") != 0) {
		push_args(wk, args, linkers[t].args.sanitize(get_cstr(wk, b_sanitize)));
	obj opt;
	get_option_value_for_tgt(wk, proj, tgt, "b_pgo", &opt);
	if (!str_eql(get_str(wk, opt), &WKSTR("off"))) {
		uint32_t stage;
		const struct str *sl = get_str(wk, opt);
		if (str_eql(sl, &WKSTR("generate"))) {
			stage = 0;
		} else if (str_eql(sl, &WKSTR("use"))) {
			stage = 1;
		} else {
			UNREACHABLE;
			return false;
		}
		push_args(wk, args, linkers[t].args.pgo(stage));
	}

	get_option_value_for_tgt(wk, proj, tgt, "b_sanitize", &opt);
	if (strcmp(get_cstr(wk, opt), "none") != 0) {
		push_args(wk, args, linkers[t].args.sanitize(get_cstr(wk, opt)));
	}

	return true;
diff --git a/src/compilers.c b/src/compilers.c
index 9121ed6..b193327 100644
--- a/src/compilers.c
+++ b/src/compilers.c
@@ -501,6 +501,27 @@ compiler_gcc_args_set_std(const char *std)
	return &args;
}

static const struct args *
compiler_gcc_args_pgo(uint32_t stage)
{
	COMPILER_ARGS({ NULL, NULL });

	args.len = 1;

	switch ((enum compiler_pgo_stage)stage) {
	case compiler_pgo_generate:
		argv[0] = "-fprofile-generate";
		break;
	case compiler_pgo_use:
		argv[1] = "-fprofile-correction";
		++args.len;
		argv[0] = "-fprofile-use";
		break;
	}

	return &args;
}

static const struct args *
compiler_gcc_args_pic(void)
{
@@ -624,6 +645,7 @@ build_compilers(void)
			.set_std         = compiler_arg_empty_1s,
			.include         = compiler_arg_empty_1s,
			.include_system  = compiler_arg_empty_1s,
			.pgo             = compiler_arg_empty_1i,
			.pic             = compiler_arg_empty_0,
			.pie             = compiler_arg_empty_0,
			.sanitize        = compiler_arg_empty_1s,
@@ -655,6 +677,7 @@ build_compilers(void)
	gcc.args.werror = compiler_gcc_args_werror;
	gcc.args.set_std = compiler_gcc_args_set_std;
	gcc.args.include_system = compiler_gcc_args_include_system;
	gcc.args.pgo = compiler_gcc_args_pgo;
	gcc.args.pic = compiler_gcc_args_pic;
	gcc.args.pie = compiler_gcc_args_pie;
	gcc.args.sanitize = compiler_gcc_args_sanitize;
@@ -790,6 +813,7 @@ build_linkers(void)
			.shared       = compiler_arg_empty_0,
			.soname       = compiler_arg_empty_1s,
			.rpath        = compiler_arg_empty_1s,
			.pgo          = compiler_arg_empty_1i,
			.sanitize     = compiler_arg_empty_1s,
			.allow_shlib_undefined = compiler_arg_empty_0,
			.export_dynamic = compiler_arg_empty_0,
@@ -810,6 +834,7 @@ build_linkers(void)
	gcc.args.end_group = linker_gcc_args_end_group;
	gcc.args.soname = linker_gcc_args_soname;
	gcc.args.rpath = linker_gcc_args_rpath;
	gcc.args.pgo = compiler_gcc_args_pgo;
	gcc.args.sanitize = compiler_gcc_args_sanitize;
	gcc.args.allow_shlib_undefined = linker_gcc_args_allow_shlib_undefined;
	gcc.args.export_dynamic = linker_gcc_args_export_dynamic;
-- 
2.37.1
Looks good to me, thanks.

Stone