Skip to content

Commit 958437c

Browse files
committed
Merge branch 'master' of github.com:totalspectrum/spin2cpp
2 parents 6692ca7 + daf1326 commit 958437c

File tree

4 files changed

+28
-11
lines changed

4 files changed

+28
-11
lines changed

backends/asm/optimize_ir.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -982,10 +982,10 @@ static bool FuncUsesArgEx(Operand *func, Operand *arg, bool actually)
982982
return !actually;
983983
} else if (func && func->val && peek_into_func) {
984984
Function *funcObj = (Function *)func->val;
985-
if ((/*func->kind == IMM_COG_LABEL ||*/ func->kind == IMM_HUB_LABEL) && (actually || funcObj->is_leaf || FuncData(funcObj)->effectivelyLeaf) && !funcObj->has_throw) {
985+
if ((/*func->kind == IMM_COG_LABEL ||*/ func->kind == IMM_HUB_LABEL) && (actually || funcObj->is_leaf || FuncData(funcObj)->effectivelyLeaf)) {
986986
if (arg->kind != REG_ARG) return true; // subreg or smth
987987
if (arg->val < funcObj->numparams) return true; // Arg used;
988-
if (!actually && arg->val < FuncData(funcObj)->maxInlineArg) return true; // Arg clobbered
988+
if (!actually && arg->val < FuncData(funcObj)->maxClobberArg) return true; // Arg clobbered
989989
if ( ((Function *)func->val)->numparams < 0 ) return true; // varargs
990990
return false; // Arg not used
991991
}
@@ -5550,10 +5550,6 @@ AnalyzeInlineEligibility(Function *f)
55505550
return FuncData(f)->inliningFlags & ~prev_flags;
55515551
}
55525552

5553-
static inline void updateMax(int *dst, int src) {
5554-
if (*dst < src) *dst = src;
5555-
}
5556-
55575553
static bool
55585554
ShouldExpandPureFunction(IR *ir) {
55595555
Function *f = (Function *)ir->aux;
@@ -5571,6 +5567,18 @@ ShouldExpandPureFunction(IR *ir) {
55715567
return true;
55725568
}
55735569

5570+
static int getArgClobberVal(Operand *op) {
5571+
int offset = 0;
5572+
if (!op) return 0;
5573+
if (op->kind == REG_SUBREG) {
5574+
offset = op->val;
5575+
op = (Operand *)op->name;
5576+
}
5577+
if (op->kind != REG_ARG) return 0;
5578+
5579+
return op->val + offset + 1;
5580+
}
5581+
55745582
//
55755583
// expand function calls inline if appropriate
55765584
// returns 1 if anything was expanded
@@ -5585,14 +5593,16 @@ ExpandInlines(IRList *irl)
55855593
ir = irl->head;
55865594
while (ir) {
55875595
ir_next = ir->next;
5596+
updateMax(&FuncData(curfunc)->maxClobberArg, getArgClobberVal(ir->dst));
5597+
updateMax(&FuncData(curfunc)->maxClobberArg, getArgClobberVal(ir->src));
55885598
if (ir->opc == OPC_CALL) {
55895599
f = (Function *)ir->aux;
55905600
if (f && ((FuncData(f)->inliningFlags & (ASM_INLINE_SMALL_FLAG|ASM_INLINE_SINGLE_FLAG)) || ShouldExpandPureFunction(ir))) {
55915601
ReplaceIRWithInline(irl, ir, f);
55925602
FuncData(f)->actual_callsites--;
55935603
FuncData(f)->got_inlined = true;
5594-
updateMax(&FuncData(curfunc)->maxInlineArg,f->numparams);
5595-
updateMax(&FuncData(curfunc)->maxInlineArg,FuncData(f)->maxInlineArg);
5604+
updateMax(&FuncData(curfunc)->maxClobberArg,f->numparams);
5605+
updateMax(&FuncData(curfunc)->maxClobberArg,FuncData(f)->maxClobberArg);
55965606
if (!f->is_leaf && !FuncData(f)->effectivelyLeaf) non_inline_calls++; // Non-leaf inline may contain call
55975607
change = 1;
55985608
} else {
@@ -5605,7 +5615,7 @@ ExpandInlines(IRList *irl)
56055615
ir = ir_next;
56065616
}
56075617
// If inlining (or previous dead-code optimization...) removed all external calls, mark as leaf.
5608-
if (non_inline_calls==0 && !curfunc->is_leaf && !FuncData(curfunc)->effectivelyLeaf && !curfunc->has_throw) {
5618+
if (non_inline_calls==0 && !curfunc->is_leaf && !FuncData(curfunc)->effectivelyLeaf) {
56095619
FuncData(curfunc)->effectivelyLeaf = true;
56105620
change = true;
56115621
}

backends/asm/outasm.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5266,6 +5266,7 @@ static void CompileStatement(IRList *irl, IRList *cold_irl, AST *ast)
52665266
EmitMove(irl, GetArgReg(1), op, ast);
52675267
EmitMove(irl, GetArgReg(2), NewImmediate(ast->d.ival), ast);
52685268
EmitOp1(irl, OPC_CALL, longjmpfunc);
5269+
updateMax(&FuncData(curfunc)->maxClobberArg,3);
52695270
break;
52705271
case AST_LABEL:
52715272
EmitDebugComment(irl, ast);

backends/asm/outasm.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,9 @@ typedef struct ir_bedata {
135135

136136
/* set after inlining if the function has no external calls left */
137137
bool effectivelyLeaf;
138-
/* Highest arg count of all inlined functions */
139-
int maxInlineArg;
138+
/* Highest arg count clobbered */
139+
/* (beware of off-by-one errors) */
140+
int maxClobberArg;
140141

141142
/* type of calling convention */
142143
CallConvention convention;

util/util.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,9 @@ size_t to_utf8(char *s, wchar_t wcorig);
8383
// convert utf-8 sequence to wide character; n is max size of cptr
8484
size_t from_utf8(wchar_t *wcptr, const char *cptr, size_t n);
8585

86+
87+
static inline void updateMax(int *dst, int src) {
88+
if (*dst < src) *dst = src;
89+
}
90+
8691
#endif

0 commit comments

Comments
 (0)