Skip to content

Commit 23c932f

Browse files
committed
Added peek-args optimization flag
1 parent 49830fd commit 23c932f

File tree

5 files changed

+14
-2
lines changed

5 files changed

+14
-2
lines changed

Changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Version 7.0.4
2+
- Added `-Opeek-args` optimization flag (the optimization was always there, this provides a way to disable it)
23
- Fixed an issue with casting to different size in nucode
34
- Fixed incorrect line info in some DEBUG statements
45
- Fixed incorrect re-use of parameter registers near functions that have an ABORT or THROW

backends/asm/optimize_ir.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -974,11 +974,13 @@ static bool isMulDivFunc(Operand *func) {
974974
// Set "actually" if you only care about the call actually using the current value
975975
static bool FuncUsesArgEx(Operand *func, Operand *arg, bool actually)
976976
{
977+
bool peek_into_func = curfunc ? (curfunc->optimize_flags & OPT_PEEK_ARGS)
978+
: (gl_optimize_flags & OPT_PEEK_ARGS);
977979
if (isMulDivFunc(func)) {
978980
return (arg == muldiva || arg == muldivb);
979981
} else if (arg == muldiva || arg == muldivb) {
980982
return !actually;
981-
} else if (func && func->val) {
983+
} else if (func && func->val && peek_into_func) {
982984
Function *funcObj = (Function *)func->val;
983985
if ((/*func->kind == IMM_COG_LABEL ||*/ func->kind == IMM_HUB_LABEL) && (actually || funcObj->is_leaf || FuncData(funcObj)->effectivelyLeaf) && !funcObj->has_throw) {
984986
if (arg->kind != REG_ARG) return true; // subreg or smth

cmdline.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ static FlagTable optflag[] = {
542542
{ "cold-code", OPT_COLD_CODE},
543543
{ "spin-relax-memory", OPT_SPIN_RELAXMEM},
544544
{ "fast-inline-asm", OPT_FASTASM },
545+
{ "peek-args", OPT_PEEK_ARGS },
545546
{ "experimental", OPT_EXPERIMENTAL },
546547
{ "all", OPT_FLAGS_ALL },
547548
};

doc/general.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,13 @@ If a method is called only once in a whole program, it is expanded inline at the
439439

440440
If two functions have identical code, output only one copy of the function. Currently only checked in the assembly backend, bytecode is still to come.
441441

442+
### Peek into function calls to see which registers are used (-O2, -Opeek-args)
443+
444+
Looks into function definitions to determine whether an argument register is
445+
used there. By default it is assumed that all argument registers may be
446+
changed within a function, but with this optimization we check for some special
447+
cases to save having to copy arguments to other registers.
448+
442449
### Common Subexpression Elimination (-O2, -Ocse)
443450

444451
Code like:

frontends/common.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ extern int gl_optimize_flags; /* flags for optimization */
195195
#define OPT_MERGE_DUPLICATES 0x00800000 /* merge duplicate functions */
196196
#define OPT_SPIN_RELAXMEM 0x01000000 /* relax strict memory semantics for Spin */
197197
#define OPT_FASTASM 0x02000000 /* optimize inline assembly invocation */
198+
#define OPT_PEEK_ARGS 0x04000000 /* peek into functions to see if arg registers can be reused */
198199
#define OPT_EXPERIMENTAL 0x80000000 /* gate new or experimental optimizations */
199200
#define OPT_FLAGS_ALL 0xffffffff
200201

@@ -207,7 +208,7 @@ extern int gl_optimize_flags; /* flags for optimization */
207208
// default optimization (-O1) for ASM output
208209
#define DEFAULT_ASM_OPTS (OPT_ASM_BASIC|OPT_DEADCODE|OPT_REMOVE_UNUSED_FUNCS|OPT_INLINE_SMALLFUNCS|OPT_AUTO_FCACHE|OPT_LOOP_BASIC|OPT_TAIL_CALLS|OPT_SPECIAL_FUNCS|OPT_CORDIC_REORDER|OPT_LOCAL_REUSE|OPT_LOOP_BASIC)
209210
// extras added with -O2
210-
#define EXTRA_ASM_OPTS (OPT_INLINE_SINGLEUSE|OPT_PERFORM_CSE|OPT_PERFORM_LOOPREDUCE|OPT_REMOVE_HUB_BSS|OPT_EXPERIMENTAL|OPT_AGGRESSIVE_MEM|OPT_MERGE_DUPLICATES)
211+
#define EXTRA_ASM_OPTS (OPT_INLINE_SINGLEUSE|OPT_PERFORM_CSE|OPT_PERFORM_LOOPREDUCE|OPT_REMOVE_HUB_BSS|OPT_EXPERIMENTAL|OPT_AGGRESSIVE_MEM|OPT_MERGE_DUPLICATES|OPT_PEEK_ARGS)
211212

212213
// default optimization (-O1) for bytecode output; defaults to much less optimization than asm
213214
#define DEFAULT_BYTECODE_OPTS (OPT_REMOVE_UNUSED_FUNCS|OPT_REMOVE_FEATURES|OPT_DEADCODE|OPT_MAKE_MACROS|OPT_SPECIAL_FUNCS|OPT_PEEPHOLE|OPT_LOOP_BASIC)

0 commit comments

Comments
 (0)