From 505d8a2d364b3012455068d433ccec73cac38a50 Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Wed, 8 Jan 2020 20:17:50 +0000 Subject: Add option to enable/disable boxing Only affects atomic types, not structs. Accepts three options: - "-u always": always boxes - "-u never": never boxes - "-u smart": inserts a comparison of sizes, and boxes only if the item is bigger than a pointer. "smart" is smart in name only; I expected the comparison to be optimised away (since the sizes of the types are known at compile-time), but it seems to run significantly slower than the other options. Steps to improve: - try making the comparison compile-time (or, if it already is, find out why it's so slow); --- sinter.c | 52 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 14 deletions(-) (limited to 'sinter.c') diff --git a/sinter.c b/sinter.c index 1021d86..0eaeb85 100644 --- a/sinter.c +++ b/sinter.c @@ -19,6 +19,8 @@ static char *input_filename; static char *output_filename; static format_t format; +static boxing_rule_t boxing_rules; + extern FILE *yyin; int yyparse(void); @@ -71,7 +73,7 @@ void prologue() { case LLVM_INTERMEDIATE: case BITCODE: case INTERPRET: - llvm_codegen_prologue(input_filename); + llvm_codegen_prologue(input_filename, boxing_rules); break; case GRAPHVIZ: @@ -133,9 +135,12 @@ int main(int argc, char **argv) { output_filename = 0; format = LLVM_INTERMEDIATE; + boxing_rules = ALWAYS_BOX; verbose = 0; - while ((c = getopt(argc, argv, "bghilo:qsv")) != -1) { + debug("\n"); + + while ((c = getopt(argc, argv, "bghilo:qsu:v")) != -1) { switch (c) { case 'b': format = BITCODE; @@ -146,17 +151,19 @@ int main(int argc, char **argv) { break; case 'h': - printf( "usage: %s [options] \n" - "-b Specify bitcode-format output\n" - "-c Compile mode\n" - "-g Output a Graphviz .dot file\n" - "-h Print this help message\n" - "-i Interpret mode\n" - "-l Specify human-readable output\n" - "-o Specify output filename\n" - "-q Quiet (default)\n" - "-s Output S-expression description\n" - "-v Verbose\n", + printf( +"usage: %s [options] \n" +"-b Specify bitcode-format output\n" +"-c Compile mode\n" +"-g Output a Graphviz .dot file\n" +"-h Print this help message\n" +"-i Interpret mode\n" +"-l Specify human-readable output\n" +"-o Specify output filename\n" +"-q Quiet (default)\n" +"-s Output S-expression description\n" +"-u Set the boxing rule: always, never, or smart\n" +"-v Verbose\n", argv[0]); exit(0); @@ -169,7 +176,7 @@ int main(int argc, char **argv) { break; case 'o': - output_filename = optarg; + output_filename = strdup(optarg); break; case 'q': @@ -180,6 +187,23 @@ int main(int argc, char **argv) { format = SINTER; break; + case 'u': + if (!strcmp(optarg, "always")) { + boxing_rules = ALWAYS_BOX; + + } else if (!strcmp(optarg, "never")) { + boxing_rules = NEVER_BOX; + + } else if (!strcmp(optarg, "smart")) { + boxing_rules = SMART_BOX; + + } else { + error(INVALID_ARGUMENTS, + "%s is not a valid option for -u\n", optarg); + + } + break; + case 'v': verbose = 1; break; -- cgit v1.2.1