diff --git a/src/libp/caseerror.c b/src/libp/caseerror.c index d0b0c9e6fd2c5dfcc09d192b1ffff73d88c8f79f..fec44486874554beda40379409aef6ec2316b30e 100644 --- a/src/libp/caseerror.c +++ b/src/libp/caseerror.c @@ -29,10 +29,10 @@ 00425618 func_00425618 00426DE8 func_00426DE8 00426FA4 func_00426FA4 -0043005C func_0043005C -00430680 func_00430680 +0043005C get_ilod +00430680 find_recurring_mem_accesses 00430D74 func_00430D74 -004310EC func_004310EC +004310EC check_addsub_cand 00431508 candidate 00433B00 ivfactor 00439C40 getop diff --git a/src/libxmalloc/alloc.c b/src/libxmalloc/alloc.c index 61280171d7ec01b720bb51237d735e5671b0954f..bee33f099853e85e39028bb279e1736e84c59cad 100644 --- a/src/libxmalloc/alloc.c +++ b/src/libxmalloc/alloc.c @@ -242,7 +242,7 @@ void *xmalloc(ssize_t size) { 0042EB10 incorp_feedback 0042F424 appendgraph 0042F6CC controlflow -00430680 func_00430680 +00430680 find_recurring_mem_accesses 00434434 func_00434434 0043771C optinit 00439188 procinit diff --git a/src/uopt/bitvector.c b/src/uopt/bitvector.c index a496da20a23382a12fa92c6e5ec1470c47c72353..d658c0cecd56e759f13f001938937b8c56ad286e 100644 --- a/src/uopt/bitvector.c +++ b/src/uopt/bitvector.c @@ -35,7 +35,7 @@ void initbv(struct BitVector *bv, struct BitVectorBlock repeated_data) { 004150E4 add_cvtl 0041550C find_replacements 004175BC copypropagate -00430FF4 func_00430FF4 +00430FF4 setcand 00431508 candidate 004324F4 findinduct 00444A84 isearchloop diff --git a/src/uopt/bvectin.c b/src/uopt/bvectin.c index 080482dcd2cb92c5b7e1bae990b79d3827135816..bc59b4eb0f3c3aeeed5fc5160167f0ff10cb0371 100644 --- a/src/uopt/bvectin.c +++ b/src/uopt/bvectin.c @@ -13,12 +13,12 @@ 00426FA4 func_00426FA4 00428DD8 func_00428DD8 0042AADC func_0042AADC -00430680 func_00430680 -00430BF4 func_00430BF4 -00430D74 func_00430D74 -00430FF4 func_00430FF4 -004310EC func_004310EC -00431268 func_00431268 +00430680 find_recurring_mem_accesses +00430BF4 no_var_mults +00430D74 check_mpy_cand +00430FF4 setcand +004310EC check_addsub_cand +00431268 ilod_aliased 00431508 candidate 004324F4 findinduct 00447F90 check_loop_coincidence diff --git a/src/uopt/debug/dlprint.c b/src/uopt/debug/dlprint.c index 871ecc65e473c57872fff32a100e7ee0ee631c43..dbf8d41904a9442f8d2a9fc25870cfae2e641d9a 100644 --- a/src/uopt/debug/dlprint.c +++ b/src/uopt/debug/dlprint.c @@ -843,6 +843,22 @@ void dl_print_strength_reduction(struct DisplayLine *dl, struct StringRep *paren sr->len = dl->pos - sr->start; } +void dl_print_recur_info(struct DisplayLine *dl, struct StringRep *parent, struct RecurInfo *recur) +{ + if (recur == NULL) return; + struct StringRep *sr = sr_newchild(dl, parent); + + sr->start = dl->pos; + sr->type = RECUR_INFO; + sr->recur = recur; + + dl_printf(dl, "Recur: "); + dl_print_ichain(dl, sr, recur->ichain); + dl_printf(dl, " -> "); + dl_print_expr(dl, sr, recur->expr); + sr->len = dl->pos - sr->start; +} + void dl_print_liveunit(struct DisplayLine *dl, struct StringRep *parent, struct LiveUnit *liveunit) { if (liveunit == NULL) return; diff --git a/src/uopt/debug/dlprint.h b/src/uopt/debug/dlprint.h index 650fe081c9a5b304c8e126f7daa20c62ab52d0a2..3b9e1f58e814a5b3cb85f553b621d36203a4069d 100644 --- a/src/uopt/debug/dlprint.h +++ b/src/uopt/debug/dlprint.h @@ -20,6 +20,7 @@ enum TypeID { VAR_ACCESS, TREP, STRENGTH_REDUCTION, + RECUR_INFO, TEMPLOC, VARIABLE, LDATAB_ENTRY, @@ -75,6 +76,7 @@ struct StringRep { struct Variable *variable; struct LdatabEntry *ldatabEntry; struct StrengthReductionCand *cand; + struct RecurInfo *recur; struct BitVector bitvector; int reg; int regset[2]; @@ -155,6 +157,7 @@ void dl_print_expr(struct DisplayLine *dl, struct StringRep *parent, struct Expr void dl_print_ichain(struct DisplayLine *dl, struct StringRep *parent, struct IChain *ichain); void dl_print_trepimage(struct DisplayLine *dl, struct StringRep *parent, struct TrepImageThing *trepimage); void dl_print_strength_reduction(struct DisplayLine *dl, struct StringRep *parent, struct StrengthReductionCand *cand); +void dl_print_recur_info(struct DisplayLine *dl, struct StringRep *parent, struct RecurInfo *recur); void dl_print_liveunit(struct DisplayLine *dl, struct StringRep *parent, struct LiveUnit *liveunit); void dl_print_interferelist(struct DisplayLine *dl, struct StringRep *parent, struct InterfereList *interfere); void dl_print_liverange(struct DisplayLine *dl, struct StringRep *parent, struct LiveRange *liverange); diff --git a/src/uopt/debug/examine.c b/src/uopt/debug/examine.c index e62ded22a0fcfa45d398c85e953fe7222042adfc..be90dcec2bfd9ddc1b5b0daa17c5632031bd267d 100644 --- a/src/uopt/debug/examine.c +++ b/src/uopt/debug/examine.c @@ -36,24 +36,25 @@ bool member_is_pointer(struct Member *m) void dl_print_typeid(struct DisplayLine *dl, struct StringRep *sr, void *data, enum TypeID type) { switch (type) { - case EXPRESSION: dl_print_expr(dl, sr, *(void**)data); break; - case ICHAIN: dl_print_ichain(dl, sr, *(void**)data); break; - case STATEMENT: dl_print_statement(dl, sr, *(void**)data); break; - case GRAPHNODE: dl_print_graphnode(dl, sr, *(void**)data, true); break; - case GRAPHNODE_LIST: dl_print_graphnode_list(dl, sr, *(void**)data, true); break; - case VAR_ACCESS: dl_print_var_access(dl, sr, *(void**)data); break; - case TREP: dl_print_trepimage(dl, sr, *(void**)data); break; + case EXPRESSION: dl_print_expr(dl, sr, *(void**)data); break; + case ICHAIN: dl_print_ichain(dl, sr, *(void**)data); break; + case STATEMENT: dl_print_statement(dl, sr, *(void**)data); break; + case GRAPHNODE: dl_print_graphnode(dl, sr, *(void**)data, true); break; + case GRAPHNODE_LIST: dl_print_graphnode_list(dl, sr, *(void**)data, true); break; + case VAR_ACCESS: dl_print_var_access(dl, sr, *(void**)data); break; + case TREP: dl_print_trepimage(dl, sr, *(void**)data); break; case STRENGTH_REDUCTION: dl_print_strength_reduction(dl, sr, *(void**)data); break; - case TEMPLOC: dl_print_temploc(dl, *(void**)data); break; - case VARLOC: dl_print_variable(dl, *(struct VariableLocation*)data); break; - case BITVECTOR: dl_print_bitvector(dl, sr, data); break; - case BITVECTORBB: dl_print_bitvectorbb(dl, sr, data); break; - case LIVERANGE: dl_print_liverange(dl, sr, *(void**)data); break; - case LIVEUNIT: dl_print_liveunit(dl, sr, *(void**)data); break; - case INTERFERELIST: dl_print_interferelist(dl, sr, *(void**)data); break; - case REGISTER: dl_print_register(dl, sr, *(char *)data); break; - case REGSET64: dl_print_regset64(dl, sr, *(int(*)[2])data); break; - case REGBOOLARRAY: dl_print_reg_boolarray(dl, sr, *(char(*)[5])data); break; + case RECUR_INFO: dl_print_recur_info(dl, sr, *(void**)data); break; + case TEMPLOC: dl_print_temploc(dl, *(void**)data); break; + case VARLOC: dl_print_variable(dl, *(struct VariableLocation*)data); break; + case BITVECTOR: dl_print_bitvector(dl, sr, data); break; + case BITVECTORBB: dl_print_bitvectorbb(dl, sr, data); break; + case LIVERANGE: dl_print_liverange(dl, sr, *(void**)data); break; + case LIVEUNIT: dl_print_liveunit(dl, sr, *(void**)data); break; + case INTERFERELIST: dl_print_interferelist(dl, sr, *(void**)data); break; + case REGISTER: dl_print_register(dl, sr, *(char *)data); break; + case REGSET64: dl_print_regset64(dl, sr, *(int(*)[2])data); break; + case REGBOOLARRAY: dl_print_reg_boolarray(dl, sr, *(char(*)[5])data); break; // scalar types case EXPRTYPE: dl_printf(dl, "%s", exprtype_name(*(ExpressionType *)data)); break; diff --git a/src/uopt/debug/memberdata.c b/src/uopt/debug/memberdata.c index fdd6efaaf6a8d0134b7d52cf0e4fbb0b47be1f05..36e75e286420286d33ccece6dc4b9557702bf455 100644 --- a/src/uopt/debug/memberdata.c +++ b/src/uopt/debug/memberdata.c @@ -26,7 +26,7 @@ struct TrepImageThing *: TREP, \ struct Proc *: MISC, \ struct StrengthReductionCand *: STRENGTH_REDUCTION, \ - struct RecurThing *: INT, \ + struct RecurInfo *: RECUR_INFO, \ \ bool: BOOL, \ unsigned char: CHAR, \ @@ -479,7 +479,7 @@ struct Member statOutpar[] = { struct Member statStr[] = { MEMBER_LIST(struct StrengthReductionCand *, u.store.u.str.srcands, struct StrengthReductionCand, next), - MEMBER(struct RecurThing *, u.store.u.str.unk30), + MEMBER_LIST(struct RecurInfo *, u.store.u.str.recurs, struct RecurInfo, next), }; struct Member statIstr[] = { @@ -892,7 +892,15 @@ struct Member strengthReductionCandMembers[] = { MEMBER(int, iv_factor), MEMBER(struct IChain *, multiplier), MEMBER(int, mult_factor), - MEMBER(int, unk18), + MEMBER(int, tempbit), +}; +#undef PARENT_TYPE + +#define PARENT_TYPE struct RecurInfo +struct Member recurInfoMembers[] = { + MEMBER(struct IChain *, ichain), + MEMBER(struct Expression *, expr), + MEMBER(struct RecurInfo *, next), }; #undef PARENT_TYPE @@ -915,6 +923,7 @@ struct StructData gStructData[TYPE_ID_MAX] = { STRUCT_DATA_DEF(GRAPHNODE, struct Graphnode, graphnodeMembers), STRUCT_DATA_DEF(INTERFERELIST, struct InterfereList, interfereListMembers), STRUCT_DATA_DEF(STRENGTH_REDUCTION, struct StrengthReductionCand, strengthReductionCandMembers), + STRUCT_DATA_DEF(RECUR_INFO, struct RecurInfo, recurInfoMembers), }; #endif diff --git a/src/uopt/uoptcm.c b/src/uopt/uoptcm.c index 8c02d0fcdb8a3542a3a9393809e9dc81f732a391..b1bd9de4cb60c06c5eb6b11cf02996dea6c32aae 100644 --- a/src/uopt/uoptcm.c +++ b/src/uopt/uoptcm.c @@ -201,12 +201,12 @@ bool trap_implying_v(Uopcode opc, struct IChain *op1, struct IChain *op2, struct 00410204 codemotion */ void delete_unmoved_recur(struct Statement *stat, struct Graphnode *node) { - struct RecurThing *recur; - struct RecurThing *last_inpath; + struct RecurInfo *recur; + struct RecurInfo *last_inpath; bool inpath; last_inpath = NULL; - recur = stat->u.store.u.str.unk30; // always NULL in oot + recur = stat->u.store.u.str.recurs; while (recur != NULL) { if (bvectin(recur->ichain->bitpos, &node->bvs.stage1.u.cm.ppin)) { if (bvectin(recur->ichain->bitpos, &node->bvs.stage1.u.cm.ppout)) { @@ -223,7 +223,7 @@ void delete_unmoved_recur(struct Statement *stat, struct Graphnode *node) { if (!inpath) { recur->expr->count--; if (last_inpath == NULL) { - stat->u.store.u.str.unk30 = recur->next; + stat->u.store.u.str.recurs = recur->next; } else { last_inpath->next = recur->next; } diff --git a/src/uopt/uoptdata.c b/src/uopt/uoptdata.c index f8b70d6791709fc588a8ac84cc4078c941112be9..06e6ae44f40f8267e9b0b18da005dd68a4a9b8c3 100644 --- a/src/uopt/uoptdata.c +++ b/src/uopt/uoptdata.c @@ -161,7 +161,7 @@ union Bcode lastcopiedu; 0042EB10 incorp_feedback 0042F424 appendgraph 0042F6CC controlflow -00430680 func_00430680 +00430680 find_recurring_mem_accesses 00434434 func_00434434 0043771C optinit 00439188 procinit @@ -243,9 +243,9 @@ struct AllocBlock *heapptr; 00424FFC func_00424FFC 00425618 func_00425618 00426FA4 func_00426FA4 -0043005C func_0043005C -00430BF4 func_00430BF4 -00430FF4 func_00430FF4 +0043005C get_ilod +00430BF4 no_var_mults +00430FF4 setcand 004376E0 func_004376E0 00439C40 getop 0043A8F0 constexp @@ -1241,7 +1241,7 @@ int pdefno; /* 00410204 codemotion 0042020C gen_static_link -00430680 func_00430680 +00430680 find_recurring_mem_accesses 004324F4 findinduct 00439188 procinit 00444984 appendichain diff --git a/src/uopt/uoptdata.h b/src/uopt/uoptdata.h index a7416ebeb670765e23d0f9eeb748d6b286858fdf..d98b43e24e62424973cdf7ed7c4a8a1fe340bb3f 100644 --- a/src/uopt/uoptdata.h +++ b/src/uopt/uoptdata.h @@ -197,7 +197,7 @@ struct StrengthReductionCand { /* 0x0C */ int iv_factor; // c1 in the example expression /* 0x10 */ struct IChain *multiplier; // some expression multiplied by the iv, not limited to just a variable /* 0x14 */ int mult_factor; // c2 in the example expression - /* 0x18 */ int unk18; // some bitpos, maybe the temp iterator? + /* 0x18 */ int tempbit; // some bitpos, maybe the temp iterator? }; // size 0x1C // probably related to induction variables or loop invariant @@ -477,7 +477,7 @@ struct Statement { } outpar; struct { struct StrengthReductionCand *srcands; - struct RecurThing *unk30; // used when emitting vreg + struct RecurInfo *recurs; // used when emitting vreg } str; struct { Datatype dtype; // 0x2C @@ -835,11 +835,11 @@ struct TailRecParameter { /* 0x10 */ struct TailRecParameter *next; }; // size 0x14 -// Statement.u.store.u.str.unk30 -struct RecurThing { +// Information for eliminating recurring memory accesses in a loop +struct RecurInfo { /* 0x00 */ struct IChain *ichain; /* 0x04 */ struct Expression *expr; - /* 0x08 */ struct RecurThing *next; + /* 0x08 */ struct RecurInfo *next; }; // size 0xC /** @@ -905,7 +905,7 @@ struct Expression { } aux; union { struct { - /* 0x3C */ unsigned short unk3C; // some size, used before createcvtl. used with Uinn + /* 0x3C */ unsigned short unk3C; // some size, used before createcvtl. used with Uinn. bytes accessed for ilod/istr /* 0x3E */ bool overflow_attr; /* 0x3F */ unsigned char align; // see Uildv and Uilod in readnxtinst } v1; diff --git a/src/uopt/uoptemit.c b/src/uopt/uoptemit.c index 14909309214e810f962403ee8f8b134a04ec2fe6..abdd03cc432d0996b5689a3a6a2ef4aba5949fd3 100644 --- a/src/uopt/uoptemit.c +++ b/src/uopt/uoptemit.c @@ -2150,13 +2150,13 @@ block_275: uwrite(&u); } - if (inreg(bittab[expr->ichain->isop.srcand->unk18].ichain, node, ®, 0)) { + if (inreg(bittab[expr->ichain->isop.srcand->tempbit].ichain, node, ®, 0)) { genrop(Ustr, reg, expr->data.isop.datatype, sizeoftyp(expr->data.isop.datatype)); } else { DTYPE = expr->data.isop.datatype; MTYPE = Mmt; IONE = curblk; - OFFSET = bittab[expr->ichain->isop.srcand->unk18].ichain->isop.temploc->disp; + OFFSET = bittab[expr->ichain->isop.srcand->tempbit].ichain->isop.temploc->disp; if (!stack_reversed) { if (highestmdef < -OFFSET) { highestmdef = -OFFSET; @@ -3524,7 +3524,7 @@ written: uwrite(&u); } - sp58 = bittab[ichain->isop.srcand->unk18].ichain; + sp58 = bittab[ichain->isop.srcand->tempbit].ichain; if (inreg(sp58, node, ®, 0)) { genrop(Ustr, reg, sp5F, sizeoftyp(sp5F)); } else { @@ -4361,7 +4361,7 @@ static void func_0042B2C0(struct StrengthReductionCand *src, Datatype dtype, str uwrite(&u); } } else { - ichain = bittab[src->unk18].ichain; + ichain = bittab[src->tempbit].ichain; if (inreg(ichain, node, ®, 1)) { genrop(Ulod, reg, dtype, 4); } else { @@ -4467,10 +4467,10 @@ static void func_0042B890(struct Statement *stat, struct Graphnode *node) { */ static void func_0042BB4C(struct Statement *stat, struct Graphnode *node) { int reg; - struct RecurThing *recur; + struct RecurInfo *recur; bool usingReg; - for (recur = stat->u.store.u.str.unk30; recur != NULL; recur = recur->next) { + for (recur = stat->u.store.u.str.recurs; recur != NULL; recur = recur->next) { usingReg = inreg(recur->ichain, node, ®, 0); if (usingReg || recur->ichain->isvar_issvar.temploc != NULL) { func_00424FFC(recur->expr, NULL, node); diff --git a/src/uopt/uoptind.c b/src/uopt/uoptind.c index 06214e2f7998411b5cb67c94826a125a0dff9157..796ec6848a3507a10605a1e29dc1f1279564b463 100644 --- a/src/uopt/uoptind.c +++ b/src/uopt/uoptind.c @@ -16,10 +16,10 @@ #include "uoptprep.h" /* -00430680 func_00430680 +00430680 find_recurring_mem_accesses */ -static bool func_0042FEA0(struct IChain *offset_ilod, struct Statement *stat, struct Graphnode *node) { - bool result = false; +static bool check_recurring_ilod(struct IChain *offset_ilod, struct Statement *stat, struct Graphnode *node) { + bool found = false; struct Statement *search = stat; while (search != node->stat_head) { @@ -27,9 +27,10 @@ static bool func_0042FEA0(struct IChain *offset_ilod, struct Statement *stat, st if (search->opc == Uisst || search->opc == Ustr) { if (stat->u.store.ichain->isop.op1 == search->expr->ichain) { + // a statement modifies the induction variable before the offset_ilod occurs return false; } - result = exproccurred(offset_ilod, search->expr->data.isvar_issvar.assigned_value); + found = exproccurred(offset_ilod, search->expr->data.isvar_issvar.assigned_value); } else if (search->opc != Uaent && search->opc != Ubgnb && search->opc != Ucia && @@ -55,20 +56,20 @@ static bool func_0042FEA0(struct IChain *offset_ilod, struct Statement *stat, st search->opc != Uujp && search->opc != Uxpar && search->opc != Urcuf) { - result = exproccurred(offset_ilod, search->expr); - if (!result) { + found = exproccurred(offset_ilod, search->expr); + if (!found) { if (search->opc == Uistr || search->opc == Uistv || search->opc == Uirst || search->opc == Uirsv || search->opc == Umov || search->opc == Umovv || search->opc == Utpeq || search->opc == Utpne || search->opc == Utpgt || search->opc == Utpge || search->opc == Utplt || search->opc == Utple) { - result = exproccurred(offset_ilod, search->u.store.expr); + found = exproccurred(offset_ilod, search->u.store.expr); } } } - if (result) { + if (found) { return true; } } @@ -77,10 +78,10 @@ static bool func_0042FEA0(struct IChain *offset_ilod, struct Statement *stat, st } /* -0043005C func_0043005C -0043019C func_0043019C +0043005C get_ilod +0043019C copy_recurring_ilod */ -static bool func_0043005C(struct IChain *ichain, struct Expression *expr, struct Expression **dest) { +static bool get_ilod(struct IChain *offset_ilod, struct Expression *expr, struct Expression **dest) { bool result = false; switch (expr->type) { @@ -95,15 +96,15 @@ static bool func_0043005C(struct IChain *ichain, struct Expression *expr, struct break; case isop: - if (expr->ichain == ichain) { + if (expr->ichain == offset_ilod) { expr->count++; *dest = expr; result = true; } else if (optab[expr->data.isop.opc].is_binary_op) { - result = func_0043005C(ichain, expr->data.isop.op1, dest) || - func_0043005C(ichain, expr->data.isop.op2, dest); + result = get_ilod(offset_ilod, expr->data.isop.op1, dest) || + get_ilod(offset_ilod, expr->data.isop.op2, dest); } else { - return func_0043005C(ichain, expr->data.isop.op1, dest); + return get_ilod(offset_ilod, expr->data.isop.op1, dest); } break; @@ -115,10 +116,10 @@ static bool func_0043005C(struct IChain *ichain, struct Expression *expr, struct } /* -00430680 func_00430680 +00430680 find_recurring_mem_accesses */ -static void func_0043019C(struct IChain *ilod, struct Expression **expr, struct Statement *stat, struct Graphnode *node) { - bool result = false; +static void copy_recurring_ilod(struct IChain *offset_ilod, struct Expression **expr, struct Statement *stat, struct Graphnode *node) { + bool found = false; struct Statement *search = stat; do { @@ -127,7 +128,7 @@ static void func_0043019C(struct IChain *ilod, struct Expression **expr, struct if (stat->u.store.ichain->isop.op1 == search->expr->ichain) { TRAP_IF(false == false); } - result = func_0043005C(ilod, search->expr->data.isvar_issvar.assigned_value, expr); + found = get_ilod(offset_ilod, search->expr->data.isvar_issvar.assigned_value, expr); } else if (search->opc != Uaent && search->opc != Ubgnb && search->opc != Ucia && @@ -153,20 +154,20 @@ static void func_0043019C(struct IChain *ilod, struct Expression **expr, struct search->opc != Uujp && search->opc != Uxpar && search->opc != Urcuf) { - result = func_0043005C(ilod, search->expr, expr); - if (!result) { + found = get_ilod(offset_ilod, search->expr, expr); + if (!found) { if (search->opc == Uistr || search->opc == Uistv || search->opc == Uirst || search->opc == Uirsv || search->opc == Umov || search->opc == Umovv || search->opc == Utpeq || search->opc == Utpne || search->opc == Utpgt || search->opc == Utpge || search->opc == Utplt || search->opc == Utple) { - result = func_0043005C(ilod, search->u.store.expr, expr); + found = get_ilod(offset_ilod, search->u.store.expr, expr); } } } - if (result) { + if (found) { return; } } while (search != node->stat_head); @@ -174,19 +175,21 @@ static void func_0043019C(struct IChain *ilod, struct Expression **expr, struct } /* -00430680 func_00430680 +00430680 find_recurring_mem_accesses stat: increment statement + +return 0 if none found, -1 if the istr is hardcoded */ -static int func_00430354(struct IChain *ichain, int offset, struct Statement *stat, struct Graphnode *node) { +static int check_recurring_istr(struct IChain *baseaddr, int offset, struct Statement *stat, struct Graphnode *node) { struct Statement *search = stat; while (search != node->stat_head) { search = search->prev; if (search->opc == Uisst || search->opc == Ustr) { - if (stat->u.store.ichain->isop.op1 == search->expr->ichain) { // direct store to the increment...? + if (stat->u.store.ichain->isop.op1 == search->expr->ichain) { return 0; } - } else if (search->opc == Uistr && search->expr->ichain == ichain && search->u.store.u.istr.offset == offset) { + } else if (search->opc == Uistr && search->expr->ichain == baseaddr && search->u.store.u.istr.offset == offset) { if (search->u.store.expr->type == isop) { return 1; } else { @@ -199,9 +202,9 @@ static int func_00430354(struct IChain *ichain, int offset, struct Statement *st } /* -00430680 func_00430680 +00430680 find_recurring_mem_accesses */ -static bool func_0043044C(struct IChain *ichain, int arg1, struct Expression **expr, struct Statement *stat, struct Graphnode *node) { +static bool copy_recurring_istr(struct IChain *baseaddr, int offset, struct Expression **dest, struct Statement *stat, struct Graphnode *node) { struct Statement *search = stat; do { search = search->prev; @@ -210,9 +213,9 @@ static bool func_0043044C(struct IChain *ichain, int arg1, struct Expression **e if (stat->u.store.ichain->isop.op1 == search->expr->ichain) { return false; } - } else if (search->opc == Uistr && search->expr->ichain == ichain && search->u.store.u.istr.offset == arg1) { + } else if (search->opc == Uistr && search->expr->ichain == baseaddr && search->u.store.u.istr.offset == offset) { search->u.store.expr->count++; - *expr = search->u.store.expr; + *dest = search->u.store.expr; return true; } } while (search != node->stat_head); @@ -221,12 +224,12 @@ static bool func_0043044C(struct IChain *ichain, int arg1, struct Expression **e } /* -00430548 func_00430548 +00430548 insert_recur asm shared outer function's arg2 through shared stack, somehow, with outer - function storing `positive` at sp50 and this function accessing through $v0 + 11 + function storing `pos_incr` at sp50 and this function accessing through $v0 + 11 */ -static int func_00430528(int offset1, int offset2, bool positive) { - if (positive) { +static int cmp_recur(int offset1, int offset2, bool pos_incr) { + if (pos_incr) { return offset1 < offset2; } else { return offset2 < offset1; @@ -234,36 +237,35 @@ static int func_00430528(int offset1, int offset2, bool positive) { } /* -00430680 func_00430680 - uncalled +00430680 find_recurring_mem_accesses */ -static void func_00430548(struct RecurThing *recur, struct Statement *stat, bool positive) { - struct RecurThing *stat_recur; // s1 - struct RecurThing *next; - - stat_recur = stat->u.store.u.str.unk30; - if (stat_recur == NULL || - (stat_recur->ichain->isop.op1 == recur->ichain->isop.op1 && - func_00430528(recur->ichain->isop.size, stat_recur->ichain->isop.size, positive))) { - stat->u.store.u.str.unk30 = recur; - recur->next = stat_recur; +static void insert_recur(struct RecurInfo *ins, struct Statement *stat, bool pos_incr) { + struct RecurInfo *curr; // s1 + struct RecurInfo *next; + + curr = stat->u.store.u.str.recurs; + if (curr == NULL || + (curr->ichain->isop.op1 == ins->ichain->isop.op1 && + cmp_recur(ins->ichain->isop.size, curr->ichain->isop.size, pos_incr))) { + stat->u.store.u.str.recurs = ins; + ins->next = curr; } else { - next = stat_recur->next; + next = curr->next; while (next != NULL && - (recur->ichain->isop.op1 != next->ichain->isop.op1 || - func_00430528(next->ichain->isop.size, recur->ichain->isop.size, positive))) { - stat_recur = next; + !(ins->ichain->isop.op1 == next->ichain->isop.op1 && + !cmp_recur(next->ichain->isop.size, ins->ichain->isop.size, pos_incr))) { + curr = next; next = next->next; } - stat_recur->next = recur; - recur->next = next; + curr->next = ins; + ins->next = next; } } /* 00431508 candidate */ -static bool func_00430680(struct IChain *ilod, struct Graphnode *node) { +static bool find_recurring_mem_accesses(struct IChain *ilod, struct Graphnode *node) { //void *sp84; struct Statement *stat; // sp7C bool overflow; @@ -271,7 +273,7 @@ static bool func_00430680(struct IChain *ilod, struct Graphnode *node) { int mult_factor; int increment; int factor; - struct RecurThing *recur; + struct RecurInfo *recur; struct IChain *offset_ilod; bool found; struct IChain *iv_ichain; @@ -289,8 +291,12 @@ static bool func_00430680(struct IChain *ilod, struct Graphnode *node) { if (factor != 0) { increment = findincre(stat->expr->data.isvar_issvar.assigned_value); - switch (func_00430354(ilod->isop.op1, ilod->isop.size + increment * factor, stat, node)) { + switch (check_recurring_istr(ilod->isop.op1, ilod->isop.size + increment * factor, stat, node)) { case 0: + // no istrs, or the iv was modified + // look for an ilod to the next element of the array + // + // ex: if p[i] occurred, look for p[i + 1] offset_ilod = itable[ilod->table_index]; found = false; while (!found && offset_ilod != NULL) { @@ -309,10 +315,8 @@ static bool func_00430680(struct IChain *ilod, struct Graphnode *node) { return false; } - // check if offset_ilod occurred in the same node, - // before the increment statement, but after any - // assignments to the iv - if (!func_0042FEA0(offset_ilod, stat, node)) { + // check if offset_ilod came after any assignments to the iv + if (!check_recurring_ilod(offset_ilod, stat, node)) { return false; } @@ -327,6 +331,8 @@ static bool func_00430680(struct IChain *ilod, struct Graphnode *node) { return false; case 1: + // found an istr to the next element in the array, e.g. p[i + 1] = p[i]; + // just check that there's only 1 induction variable in the original ilod if (iv_ichain == NULL) { iv_ichain = stat->expr->ichain; } else if (iv_ichain != stat->expr->ichain) { @@ -356,10 +362,12 @@ static bool func_00430680(struct IChain *ilod, struct Graphnode *node) { if (factor != 0) { TRAP_IF(multiplier != NULL); increment = findincre(stat->expr->data.isvar_issvar.assigned_value); - recur = alloc_new(sizeof (struct RecurThing), &perm_heap); + recur = alloc_new(sizeof (struct RecurInfo), &perm_heap); recur->ichain = ilod; - func_00430548(recur, stat, increment * factor > 0); - if (!func_0043044C(ilod->isop.op1, ilod->isop.size + increment * factor, &recur->expr, stat, node)) { + insert_recur(recur, stat, increment * factor > 0); + + // get a pointer to the istr. If none, get the ilod + if (!copy_recurring_istr(ilod->isop.op1, ilod->isop.size + increment * factor, &recur->expr, stat, node)) { offset_ilod = itable[ilod->table_index]; found = false; do { @@ -373,7 +381,7 @@ static bool func_00430680(struct IChain *ilod, struct Graphnode *node) { offset_ilod = offset_ilod->next; } } while (!found); - func_0043019C(offset_ilod, &recur->expr, stat, node); + copy_recurring_ilod(offset_ilod, &recur->expr, stat, node); } } } @@ -389,11 +397,11 @@ static bool func_00430680(struct IChain *ilod, struct Graphnode *node) { } /* -00430BF4 func_00430BF4 -00430D74 func_00430D74 +00430BF4 no_var_mults +00430D74 check_mpy_cand 00431508 candidate */ -static bool func_00430BF4(struct IChain *ichain, struct Graphnode *node) { +static bool no_var_mults(struct IChain *ichain, struct Graphnode *node) { bool result; if (ichain->type != isop) { @@ -405,16 +413,16 @@ static bool func_00430BF4(struct IChain *ichain, struct Graphnode *node) { } if (!optab[ichain->isop.opc].is_binary_op) { - return func_00430BF4(ichain->isop.op1, node); + return no_var_mults(ichain->isop.op1, node); } if (ichain->isop.opc == Umpy) { if (ichain->isop.op1->type != isconst && ichain->isop.op2->type != isconst) { return false; } - result = func_00430BF4(ichain->isop.op1, node) && func_00430BF4(ichain->isop.op2, node); + result = no_var_mults(ichain->isop.op1, node) && no_var_mults(ichain->isop.op2, node); } else { - result = func_00430BF4(ichain->isop.op1, node) && func_00430BF4(ichain->isop.op2, node); + result = no_var_mults(ichain->isop.op1, node) && no_var_mults(ichain->isop.op2, node); } return result; @@ -422,10 +430,12 @@ static bool func_00430BF4(struct IChain *ichain, struct Graphnode *node) { /* -00430D74 func_00430D74 +00430D74 check_mpy_cand 00431508 candidate + +check if operand of a multiply is CAND */ -static bool func_00430D74(struct IChain *ichain, struct Graphnode *node) { +static bool check_mpy_cand(struct IChain *ichain, struct Graphnode *node) { bool result; switch (ichain->type) { @@ -439,6 +449,10 @@ static bool func_00430D74(struct IChain *ichain, struct Graphnode *node) { result = false; break; + // very tricky, but this ensures that at least one of the variables is iv + // + // in findinduct, CAND is intersected with ALTERS, so the overall expression must be altered. + // IV variables are always altered case isvar: case issvar: result = bvectin(ichain->bitpos, &node->bvs.stage1.u.cm.iv) || !bvectin(ichain->bitpos, &node->bvs.stage1.alters); @@ -446,12 +460,12 @@ static bool func_00430D74(struct IChain *ichain, struct Graphnode *node) { case isop: if (ichain->isop.opc == Udec || ichain->isop.opc == Uinc || ichain->isop.opc == Uneg) { - return func_00430D74(ichain->isop.op1, node); + return check_mpy_cand(ichain->isop.op1, node); } if (ichain->isop.opc == Uadd || ichain->isop.opc == Usub) { - result = func_00430D74(ichain->isop.op1, node) && func_00430D74(ichain->isop.op2, node) && - (func_00430BF4(ichain->isop.op1, node) || func_00430BF4(ichain->isop.op2, node)); + result = check_mpy_cand(ichain->isop.op1, node) && check_mpy_cand(ichain->isop.op2, node) && + (no_var_mults(ichain->isop.op1, node) || no_var_mults(ichain->isop.op2, node)); } else if (ichain->isop.opc == Uilod || ichain->isop.opc == Uirld) { result = !bvectin(ichain->bitpos, &node->bvs.stage1.alters); } else { @@ -469,18 +483,18 @@ static bool func_00430D74(struct IChain *ichain, struct Graphnode *node) { } /* -00430FF4 func_00430FF4 +00430FF4 setcand 00431508 candidate */ -static void func_00430FF4(struct IChain *ichain, struct Graphnode *node) { +static void setcand(struct IChain *ichain, struct Graphnode *node) { if (ichain->type == isop) { if (bvectin(ichain->bitpos, &node->bvs.stage1.alters)) { setbit(&node->bvs.stage1.u.cm.cand, ichain->bitpos); } - func_00430FF4(ichain->isop.op1, node); + setcand(ichain->isop.op1, node); if (optab[ichain->isop.opc].is_binary_op) { - func_00430FF4(ichain->isop.op2, node); + setcand(ichain->isop.op2, node); } } } @@ -488,7 +502,7 @@ static void func_00430FF4(struct IChain *ichain, struct Graphnode *node) { /* 00431508 candidate */ -static bool func_004310EC(struct IChain *ichain, bool *sp43, struct Graphnode *node) { +static bool check_addsub_cand(struct IChain *ichain, bool *no_isrconst, struct Graphnode *node) { bool result = false; switch (ichain->type) { @@ -499,7 +513,7 @@ static bool func_004310EC(struct IChain *ichain, bool *sp43, struct Graphnode *n break; case isrconst: - *sp43 = false; + *no_isrconst = false; // has no effect break; case isvar: @@ -511,6 +525,8 @@ static bool func_004310EC(struct IChain *ichain, bool *sp43, struct Graphnode *n if (ichain->isop.opc == Uilod || ichain->isop.opc == Uirld) { result = !bvectin(ichain->bitpos, &node->bvs.stage1.alters); } else { + // tricky, relies on the fact that nested expressions are added to bittab before larger expressions. So if + // the ichain is cand, then it already passed through candidate() and there's no need to use recursion. result = bvectin(ichain->bitpos, &node->bvs.stage1.u.cm.cand) || !bvectin(ichain->bitpos, &node->bvs.stage1.alters); } break; @@ -525,7 +541,7 @@ static bool func_004310EC(struct IChain *ichain, bool *sp43, struct Graphnode *n /* 00431508 candidate */ -static bool func_00431268(struct IChain *ichain, struct VarAccessList *list, struct Graphnode *node) { +static bool ilod_aliased(struct IChain *ilod, struct VarAccessList *list, struct Graphnode *node) { struct VarAccessList *access; bool result; @@ -533,20 +549,20 @@ static bool func_00431268(struct IChain *ichain, struct VarAccessList *list, str result = false; while (access != NULL && !result) { if (access->type == 1 && !access->unk8) { - result = slkilled(access->data.store, ichain->expr); + result = slkilled(access->data.store, ilod->expr); if (result) { if ((access->data.store->opc == Uistr || access->data.store->opc == Uirst) && - access->data.store->expr->ichain == ichain->isop.op1 && - bvectin(ichain->bitpos, &node->bvs.stage1.u.precm.expoccur)) { - result = access->data.store->u.store.u.istr.offset >= ichain->isop.size; - if (result != 0) { - result = (access->data.store->u.store.u.istr.offset - ichain->isop.size) < ichain->isop.unk24_u16; + access->data.store->expr->ichain == ilod->isop.op1 && + bvectin(ilod->bitpos, &node->bvs.stage1.u.precm.expoccur)) { + result = access->data.store->u.store.u.istr.offset >= ilod->isop.size; + if (result) { + result = (access->data.store->u.store.u.istr.offset - ilod->isop.size) < ilod->isop.unk24_u16; } if (!result) { - result = ichain->isop.size >= access->data.store->u.store.u.istr.offset; - if (result != 0) { - result = (ichain->isop.size - access->data.store->u.store.u.istr.offset) < access->data.store->u.store.size; + result = access->data.store->u.store.u.istr.offset <= ilod->isop.size; + if (result) { + result = (ilod->isop.size - access->data.store->u.store.u.istr.offset) < access->data.store->u.store.size; } } } @@ -559,22 +575,24 @@ static bool func_00431268(struct IChain *ichain, struct VarAccessList *list, str /* 00431508 candidate + +Return some number != 0 if the increments to iv are all positive or all negative */ -static int func_004313E4(struct IChain *ichain, struct Graphnode *node) { +static int all_increments(struct IChain *iv, struct Graphnode *node) { struct VarAccessList *access; - int incre_result; + int increment; int result = 0; access = node->varlisthead; while (access != NULL) { if (access->type == 1) { if ((access->data.store->opc == Uisst || access->data.store->opc == Ustr) && - access->data.store->is_increment && ichain == access->data.store->expr->ichain) { - incre_result = findincre(access->data.store->expr->data.isvar_issvar.assigned_value); + access->data.store->is_increment && iv == access->data.store->expr->ichain) { + increment = findincre(access->data.store->expr->data.isvar_issvar.assigned_value); if (result == 0 || - (incre_result > 0 && result > 0) || - (incre_result < 0 && result < 0)) { - result = incre_result; + (increment > 0 && result > 0) || + (increment < 0 && result < 0)) { + result = increment; } else { return 0; } @@ -591,7 +609,7 @@ static int func_004313E4(struct IChain *ichain, struct Graphnode *node) { determine if the expression is a candidate for operator strength reduction */ static bool candidate(struct IChain *ichain, struct Graphnode *node) { - bool sp43 = false; // ??? + bool no_isrconst = false; // sp43 bool iscand = false; // t0 bool sp41 = false; // a3 bool rhs_const = false; // sp40 @@ -621,9 +639,9 @@ static bool candidate(struct IChain *ichain, struct Graphnode *node) { iscand = false; } } else { - iscand = func_00430D74(ichain->isop.op1, node); + iscand = check_mpy_cand(ichain->isop.op1, node); if (iscand) { - func_00430FF4(ichain->isop.op1, node); + setcand(ichain->isop.op1, node); } } } else { @@ -636,29 +654,29 @@ static bool candidate(struct IChain *ichain, struct Graphnode *node) { iscand = false; } } else { - iscand = func_00430D74(ichain->isop.op2, node); + iscand = check_mpy_cand(ichain->isop.op2, node); if (iscand) { - func_00430FF4(ichain->isop.op2, node); + setcand(ichain->isop.op2, node); } } } - } else if (func_00430D74(ichain->isop.op1, node) && func_00430D74(ichain->isop.op2, node)) { + } else if (check_mpy_cand(ichain->isop.op1, node) && check_mpy_cand(ichain->isop.op2, node)) { if (ichain->isop.op2->type == isvar) { - iscand = func_00430BF4(ichain->isop.op1, node); + iscand = no_var_mults(ichain->isop.op1, node); if (iscand) { iscand = !iexproccurred(ichain->isop.op2, ichain->isop.op1); } if (iscand) { - func_00430FF4(ichain->isop.op1, node); + setcand(ichain->isop.op1, node); } setbit(&varfactor_muls, ichain->bitpos); } else if (ichain->isop.op1->type == isvar) { - iscand = func_00430BF4(ichain->isop.op2, node); + iscand = no_var_mults(ichain->isop.op2, node); if (iscand) { iscand = !iexproccurred(ichain->isop.op1, ichain->isop.op2); } if (iscand) { - func_00430FF4(ichain->isop.op2, node); + setcand(ichain->isop.op2, node); } setbit(&varfactor_muls, ichain->bitpos); } else { @@ -684,7 +702,7 @@ static bool candidate(struct IChain *ichain, struct Graphnode *node) { case issvar: iscand = false; if (bvectin(ichain->isop.op2->bitpos, &node->bvs.stage1.u.cm.iv)) { - iscand = func_004310EC(ichain->isop.op1, &sp43, node); + iscand = check_addsub_cand(ichain->isop.op1, &no_isrconst, node); } if (!bvectin(ichain->isop.op2->bitpos, &node->bvs.stage1.alters)) { if (ichain->isop.op1->type == isop) { @@ -708,15 +726,15 @@ static bool candidate(struct IChain *ichain, struct Graphnode *node) { } } } else { - if (func_004310EC(ichain->isop.op1, &sp43, node)) { + if (check_addsub_cand(ichain->isop.op1, &no_isrconst, node)) { if (bvectin(ichain->isop.op2->bitpos, &node->bvs.stage1.u.cm.cand)) { if (ichain->isop.op2->isop.opc != Uilod && ichain->isop.op2->isop.opc != Uirld) { iscand = true; } } else { - iscand = func_00430D74(ichain->isop.op2, node); + iscand = check_mpy_cand(ichain->isop.op2, node); if (iscand) { - func_00430FF4(ichain->isop.op2, node); + setcand(ichain->isop.op2, node); } } } @@ -733,7 +751,7 @@ static bool candidate(struct IChain *ichain, struct Graphnode *node) { } if (iscand) { - iscand = func_00430BF4(ichain->isop.op1, node) || func_00430BF4(ichain->isop.op2, node); + iscand = no_var_mults(ichain->isop.op1, node) || no_var_mults(ichain->isop.op2, node); } break; @@ -756,7 +774,7 @@ static bool candidate(struct IChain *ichain, struct Graphnode *node) { if (ichain->isop.op1->type == isop) { if (bvectin(ichain->isop.op1->bitpos, &node->bvs.stage1.u.cm.cand)) { if (ichain->isop.op1->isop.opc != Uilod && ichain->isop.op1->isop.opc != Uirld) { - iscand = func_004310EC(ichain->isop.op2, &sp43, node); + iscand = check_addsub_cand(ichain->isop.op2, &no_isrconst, node); } } @@ -764,29 +782,27 @@ static bool candidate(struct IChain *ichain, struct Graphnode *node) { if (ichain->isop.op2->type == isop) { if (bvectin(ichain->isop.op2->bitpos, &node->bvs.stage1.u.cm.cand)) { if (ichain->isop.op2->isop.opc != Uilod && ichain->isop.op2->isop.opc != Uirld) { - iscand = func_004310EC(ichain->isop.op1, &sp43, node); + iscand = check_addsub_cand(ichain->isop.op1, &no_isrconst, node); } } } } - } else { - if (ichain->isop.op2->type == isop) { - if (bvectin(ichain->isop.op2->bitpos, &node->bvs.stage1.u.cm.cand)) { - if (ichain->isop.op2->isop.opc != Uilod && ichain->isop.op2->isop.opc != Uirld) { - iscand = func_004310EC(ichain->isop.op1, &sp43, node); - } + } else if (ichain->isop.op2->type == isop) { + if (bvectin(ichain->isop.op2->bitpos, &node->bvs.stage1.u.cm.cand)) { + if (ichain->isop.op2->isop.opc != Uilod && ichain->isop.op2->isop.opc != Uirld) { + iscand = check_addsub_cand(ichain->isop.op1, &no_isrconst, node); } } } if (iscand) { - iscand = func_00430BF4(ichain->isop.op1, node) || func_00430BF4(ichain->isop.op2, node); + iscand = no_var_mults(ichain->isop.op1, node) || no_var_mults(ichain->isop.op2, node); } if (!iscand) { if (ichain->isop.op1->type == isvar) { if (ichain->isop.op2->type == isvar || ichain->isop.op2->type == isop) { - iscand = bvectin(ichain->isop.op1->bitpos, &node->bvs.stage1.u.cm.iv) && func_004310EC(ichain->isop.op2, &sp43, node); + iscand = bvectin(ichain->isop.op1->bitpos, &node->bvs.stage1.u.cm.iv) && check_addsub_cand(ichain->isop.op2, &no_isrconst, node); } } } @@ -794,7 +810,7 @@ static bool candidate(struct IChain *ichain, struct Graphnode *node) { if (!iscand) { if (ichain->isop.op2->type == isvar) { if (ichain->isop.op1->type == isvar || ichain->isop.op1->type == isop) { - iscand = bvectin(ichain->isop.op2->bitpos, &node->bvs.stage1.u.cm.iv) && func_004310EC(ichain->isop.op1, &sp43, node); + iscand = bvectin(ichain->isop.op2->bitpos, &node->bvs.stage1.u.cm.iv) && check_addsub_cand(ichain->isop.op1, &no_isrconst, node); } } } @@ -812,7 +828,7 @@ static bool candidate(struct IChain *ichain, struct Graphnode *node) { } if (iscand) { - sp41 = func_00431268(ichain, node->varlisthead, node); + sp41 = ilod_aliased(ichain, node->varlisthead, node); if (!sp41) { if (node->stat_tail->opc == Ucia) { if (lang == LANG_ADA || @@ -831,7 +847,7 @@ static bool candidate(struct IChain *ichain, struct Graphnode *node) { } if (iscand) { - iscand = dorecur && func_00430680(ichain, node); + iscand = dorecur && find_recurring_mem_accesses(ichain, node); } break; @@ -851,12 +867,12 @@ static bool candidate(struct IChain *ichain, struct Graphnode *node) { switch (ichain->isop.opc) { case Utpge: case Utpgt: - iscand = func_004313E4(ichain->isop.op1, node) < 0; + iscand = all_increments(ichain->isop.op1, node) < 0; break; case Utple: case Utplt: - iscand = func_004313E4(ichain->isop.op1, node) > 0; + iscand = all_increments(ichain->isop.op1, node) > 0; break; default: @@ -1259,7 +1275,7 @@ void findinduct(void) { } /* -00430680 func_00430680 +00430680 find_recurring_mem_accesses 00433B00 ivfactor 00474FC8 func_00474FC8 00477E20 func_00477E20 diff --git a/src/uopt/uoptinput.c b/src/uopt/uoptinput.c index cb6e041a734648ca9951c34f6b235ede075f2291..a7c77bd17cb188016c589bbd830234cb0baa45f4 100644 --- a/src/uopt/uoptinput.c +++ b/src/uopt/uoptinput.c @@ -1506,7 +1506,7 @@ void readnxtinst(void) { stattail->u.store.lval_av = false; stattail->u.store.store_av = false; stattail->u.store.u.str.srcands = NULL; - stattail->u.store.u.str.unk30 = 0; + stattail->u.store.u.str.recurs = NULL; expr->data.isvar_issvar.assignment = NULL; appendstorelist(); curgraphnode->varlisttail->unk8 = true; @@ -3282,7 +3282,7 @@ void readnxtinst(void) { stattail->is_increment = false; } stattail->u.store.u.str.srcands = NULL; - stattail->u.store.u.str.unk30 = 0; + stattail->u.store.u.str.recurs = NULL; stattail->suppressed_iv = false; if (!expr->data.isvar_issvar.vreg) { strkillprev(stattail); diff --git a/src/uopt/uoptkill.c b/src/uopt/uoptkill.c index 41ef985578ba558b29b3e521f4a36e263fe57c5a..7a9c8ad822f3d5e1a792f862794f183b0f4c0de1 100644 --- a/src/uopt/uoptkill.c +++ b/src/uopt/uoptkill.c @@ -201,7 +201,7 @@ bool pointtoheap(struct Expression *baseaddr) { // most of this is jankiness for fortran, pascal, and cobol /* 004123C4 varinsert -00431268 func_00431268 +00431268 ilod_aliased 004324F4 findinduct 0044B308 strkillprev 0044B448 lodkillprev diff --git a/src/uopt/uoptloc.c b/src/uopt/uoptloc.c index b3ce993afa203e752e642dba59343242f8463a78..623d3274e797d26ab2636c3c2058405a76387803 100644 --- a/src/uopt/uoptloc.c +++ b/src/uopt/uoptloc.c @@ -513,7 +513,7 @@ void istrfold(struct Statement *stmt) { stmt->outpar = false; stmt->u.store.var_access_list_item->unk8 = false; stmt->u.store.u.str.srcands = NULL; - stmt->u.store.u.str.unk30 = 0; + stmt->u.store.u.str.recurs = NULL; } /* diff --git a/src/uopt/uoptprep.c b/src/uopt/uoptprep.c index b65f36df209254970eeebe544fa8419398201311..ff98a0ca75abeb2656d796d594ff908d83ce75aa 100644 --- a/src/uopt/uoptprep.c +++ b/src/uopt/uoptprep.c @@ -136,7 +136,7 @@ bool cupaltered(struct IChain *ichain, int level, struct Proc *proc) { if (!altered && optab[ichain->isop.opc].is_binary_op) { altered = cupaltered(ichain->isop.op2, level, proc); } - + if (!altered && (ichain->isop.opc == Uiequ || ichain->isop.opc == Uineq || diff --git a/src/uopt/uoptreg1.c b/src/uopt/uoptreg1.c index ffdb61cf255aff61b977afe5567645da7c7b99ce..427210ccc643b383112625062d7eb3e575773edd 100644 --- a/src/uopt/uoptreg1.c +++ b/src/uopt/uoptreg1.c @@ -695,13 +695,13 @@ static void func_0045E5C4(struct Expression *expr, unsigned char arg1, struct Gr expr->data.isop.opc != Uirlv) && expr->ichain->isop.srcand != NULL && expr->ichain->isop.srcand != nota_candof) { - if (expr->ichain->isop.srcand->unk18 == 0) { + if (expr->ichain->isop.srcand->tempbit == 0) { ichain = alloc_new(sizeof (struct IChain), &perm_heap); *ichain = *expr->ichain->isop.srcand->target; ichain->isop.opc = Ucg1; - expr->ichain->isop.srcand->unk18 = newbit(ichain, NULL); - ichain->bitpos = expr->ichain->isop.srcand->unk18; + expr->ichain->isop.srcand->tempbit = newbit(ichain, NULL); + ichain->bitpos = expr->ichain->isop.srcand->tempbit; if ((tempdisp & 3) != 0) { tempdisp = (tempdisp - (tempdisp & 3)) + 4; @@ -716,7 +716,7 @@ static void func_0045E5C4(struct Expression *expr, unsigned char arg1, struct Gr tempdisp += 4; } } else { - ichain = bittab[expr->ichain->isop.srcand->unk18].ichain; + ichain = bittab[expr->ichain->isop.srcand->tempbit].ichain; } if ((ichain->isop.datatype != Idt && ichain->isop.datatype != Kdt) || dwopcode) { @@ -730,7 +730,7 @@ static void func_0045E5C4(struct Expression *expr, unsigned char arg1, struct Gr formlivbb(ichain, node, lu); (*lu)->store_count++; - setbit(&node->bvs.stage2.locdef, expr->ichain->isop.srcand->unk18); + setbit(&node->bvs.stage2.locdef, expr->ichain->isop.srcand->tempbit); if ((*lu)->load_count == 0) { (*lu)->firstisstr = 1; } @@ -1161,13 +1161,13 @@ static bool func_0045FBB4(struct IChain *ichain, int arg1, int arg2, struct Grap ichain->isop.opc != Uirld && ichain->isop.opc != Uirlv) { if (ichain->isop.srcand != NULL && ichain->isop.srcand != nota_candof) { - if (ichain->isop.srcand->unk18 == 0) { + if (ichain->isop.srcand->tempbit == 0) { sp40 = alloc_new(sizeof (struct IChain), &perm_heap); *sp40 = *ichain->isop.srcand->target; sp40->isop.opc = Ucg1; - ichain->isop.srcand->unk18 = newbit(sp40, NULL); - sp40->bitpos = ichain->isop.srcand->unk18; + ichain->isop.srcand->tempbit = newbit(sp40, NULL); + sp40->bitpos = ichain->isop.srcand->tempbit; if ((tempdisp & 3) != 0) { tempdisp = (tempdisp - (tempdisp & 3)) + 4; } @@ -1180,7 +1180,7 @@ static bool func_0045FBB4(struct IChain *ichain, int arg1, int arg2, struct Grap tempdisp += 4; } } else { - sp40 = bittab[ichain->isop.srcand->unk18].ichain; + sp40 = bittab[ichain->isop.srcand->tempbit].ichain; } if ((sp40->isop.datatype != Idt && sp40->isop.datatype != Kdt) || dwopcode) { @@ -1188,7 +1188,7 @@ static bool func_0045FBB4(struct IChain *ichain, int arg1, int arg2, struct Grap formlivbb(sp40, node, lu); (*lu)->store_count++; - setbit(&node->bvs.stage2.locdef, ichain->isop.srcand->unk18); + setbit(&node->bvs.stage2.locdef, ichain->isop.srcand->tempbit); if ((*lu)->load_count == 0) { (*lu)->firstisstr = true; @@ -1260,80 +1260,80 @@ static void func_00461084(struct IChain *ichain, struct Graphnode *node) { */ static void func_0046123C(struct Statement *stat, struct Graphnode *node) { struct LiveUnit *lu; - int sp58; + int loopno; bool phi_s6; - struct StrengthReductionCand *phi_s2; - struct IChain *phi_s1; + struct StrengthReductionCand *cand; + struct IChain *temp_ichain; if (stat->u.store.u.str.srcands == NULL) { return; } - phi_s2 = stat->u.store.u.str.srcands; + cand = stat->u.store.u.str.srcands; phi_s6 = mipsflag == 3 && stat->graphnode->loop != NULL; if (phi_s6) { - sp58 = stat->graphnode->loop->loopno; + loopno = stat->graphnode->loop->loopno; phi_s6 = looptab[stat->graphnode->loop->loopno].unk9 && looptab[stat->graphnode->loop->loopno].unk4 != NULL; } - while (phi_s2 != NULL) { - if (!phi_s6 || !check_ix_candidate(phi_s2->target, sp58)) { - if ((phi_s2->target->isop.datatype != Idt && phi_s2->target->isop.datatype != Kdt) || dwopcode) { - formlivbb(phi_s2->target, node, &lu); + while (cand != NULL) { + if (!phi_s6 || !check_ix_candidate(cand->target, loopno)) { + if ((cand->target->isop.datatype != Idt && cand->target->isop.datatype != Kdt) || dwopcode) { + formlivbb(cand->target, node, &lu); if (outofmem) { return; } lu->load_count += 1; - if (phi_s6 && check_ix_source(phi_s2->target, sp58)) { + if (phi_s6 && check_ix_source(cand->target, loopno)) { lu->load_count += 2; } if (lu->load_count == 1 && lu->store_count == 0) { - setbit(&node->bvs.stage2.loclive, phi_s2->target->bitpos); + setbit(&node->bvs.stage2.loclive, cand->target->bitpos); } lu->store_count += 1; - setbit(&node->bvs.stage2.locdef, phi_s2->target->bitpos); + setbit(&node->bvs.stage2.locdef, cand->target->bitpos); } - if (phi_s2->multiplier != NULL) { - if (phi_s2->target->isop.srcand == NULL || phi_s2->target->isop.srcand == nota_candof || node->in_rolled_preloop) { - func_00461084(phi_s2->multiplier, node); + if (cand->multiplier != NULL) { + if (cand->target->isop.srcand == NULL || cand->target->isop.srcand == nota_candof || node->in_rolled_preloop) { + func_00461084(cand->multiplier, node); } else { - if (phi_s2->unk18 == 0) { - phi_s1 = alloc_new(sizeof (struct IChain), &perm_heap); - *phi_s1 = *phi_s2->target; + if (cand->tempbit == 0) { + temp_ichain = alloc_new(sizeof (struct IChain), &perm_heap); + *temp_ichain = *cand->target; - phi_s1->isop.opc = Ucg1; - phi_s2->unk18 = newbit(phi_s1, NULL); - phi_s1->bitpos = phi_s2->unk18; + temp_ichain->isop.opc = Ucg1; + cand->tempbit = newbit(temp_ichain, NULL); + temp_ichain->bitpos = cand->tempbit; if ((tempdisp & 3) != 0) { tempdisp = (tempdisp - (tempdisp & 3)) + 4; } - phi_s1->isop.temploc = alloc_new(sizeof (struct Temploc), &perm_heap); + temp_ichain->isop.temploc = alloc_new(sizeof (struct Temploc), &perm_heap); if (!stack_reversed) { tempdisp += 4; - phi_s1->isop.temploc->disp = -tempdisp; + temp_ichain->isop.temploc->disp = -tempdisp; } else { - phi_s1->isop.temploc->disp = tempdisp; + temp_ichain->isop.temploc->disp = tempdisp; tempdisp += 4; } } else { - phi_s1 = bittab[phi_s2->unk18].ichain; + temp_ichain = bittab[cand->tempbit].ichain; } - if ((phi_s1->isop.datatype != Idt && phi_s1->isop.datatype != Kdt) || dwopcode) { - formlivbb(phi_s1, node, &lu); + if ((temp_ichain->isop.datatype != Idt && temp_ichain->isop.datatype != Kdt) || dwopcode) { + formlivbb(temp_ichain, node, &lu); lu->load_count++; if (lu->load_count == 1) { - setbit(&node->bvs.stage2.loclive, phi_s1->bitpos); + setbit(&node->bvs.stage2.loclive, temp_ichain->bitpos); } } } } } - phi_s2 = phi_s2->next; + cand = cand->next; } } @@ -1342,9 +1342,9 @@ static void func_0046123C(struct Statement *stat, struct Graphnode *node) { */ static void func_00461640(struct Statement *stat, struct Graphnode *node, struct LiveUnit **lu) { struct LiveUnit *sp50; - struct RecurThing *recur; + struct RecurInfo *recur; - recur = stat->u.store.u.str.unk30; + recur = stat->u.store.u.str.recurs; while (recur != NULL) { func_0045E5C4(recur->expr, 0, node, lu); if ((recur->ichain->isop.datatype != Idt && recur->ichain->isop.datatype != Kdt) || dwopcode) { diff --git a/src/uopt/uoptroll.c b/src/uopt/uoptroll.c index 6ec80267a6cef8a6ca968e3915d7a56edcfbf74d..425d0996cfef57a85e0a2cab84ea4a7b031b009c 100644 --- a/src/uopt/uoptroll.c +++ b/src/uopt/uoptroll.c @@ -1362,8 +1362,8 @@ void oneloopblockstmt(struct Statement *stat) { } stattail->u.store.u.str.srcands = NULL; - stattail->u.store.u.str.unk30 = 0; - stattail->suppressed_iv = 0; + stattail->u.store.u.str.recurs = NULL; + stattail->suppressed_iv = false; if (!phi_s1->data.isvar_issvar.vreg) { strkillprev(stattail); } @@ -2440,8 +2440,8 @@ struct Expression *str_to_temporary(int addr, struct Expression *store) { stattail->u.store.store_av = true; stattail->is_increment = false; stattail->u.store.u.str.srcands = NULL; - stattail->u.store.u.str.unk30 = 0; - stattail->suppressed_iv = 0; + stattail->u.store.u.str.recurs = NULL; + stattail->suppressed_iv = false; ret->data.isvar_issvar.assignment = stattail; appendstorelist(); curgraphnode->varlisttail->unk8 = true; @@ -3511,7 +3511,7 @@ void par_to_str(struct Statement *par, bool arg1, int disp) { stattail->u.store.u.str.srcands = NULL; stattail->u.store.lval_av = !sp5C->data.isvar_issvar.veqv; stattail->u.store.store_av = !sp5C->data.isvar_issvar.veqv; - stattail->u.store.u.str.unk30 = 0; + stattail->u.store.u.str.recurs = NULL; stattail->suppressed_iv = false; sp5C->data.isvar_issvar.assignment = stattail; if (sp5C->data.isvar_issvar.vreg == 0) { diff --git a/src/uopt/uoptscm.c b/src/uopt/uoptscm.c index e32af576a8834824e700ae987c8c0239f8a45a6a..3e03ad67d551076958b0bbe516eaaf02303b1457 100644 --- a/src/uopt/uoptscm.c +++ b/src/uopt/uoptscm.c @@ -273,7 +273,7 @@ static void func_00474FC8(struct Statement *stat, struct Graphnode *node) { if (multiplier != NULL) { srcand->multiplier = multiplier; srcand->mult_factor = mult_factor; - srcand->unk18 = 0; + srcand->tempbit = 0; if (ichain->isop.srcand != nota_candof && !node->in_rolled_preloop) { if (ichain->isop.srcand != NULL || (mult_factor * increment == 1 && factor == 0) || diff --git a/src/uopt/uopttrep.c b/src/uopt/uopttrep.c index 30df1e93e50715570170128cc5297a096bc692a4..1a3ff2dbf00234c8106afad912c10324d76733ef 100644 --- a/src/uopt/uopttrep.c +++ b/src/uopt/uopttrep.c @@ -1565,7 +1565,7 @@ void eliminduct(void) { stat->expr = stat->expr->data.isvar_issvar.assigned_value; func_00479778(stat->expr, node); } else { - stat->suppressed_iv = 1; + stat->suppressed_iv = true; if (stat->opc == Uisst) { deccount(stat->u.store.expr, node); } diff --git a/src/uopt/uoptutil.c b/src/uopt/uoptutil.c index ec95dc666d3cf61575a01bc4bb35b267f516c322..a6535c82ed651079a3204ff7fe0741c104cc9c0e 100644 --- a/src/uopt/uoptutil.c +++ b/src/uopt/uoptutil.c @@ -975,7 +975,7 @@ int newbit(struct IChain *ichain, struct LiveRange *liverange) { /* 004127C8 checkexpoccur -0042FEA0 func_0042FEA0 +0042FEA0 check_recurring_ilod 00474AF0 inpathbefore 00474C58 inpathafter 0047D000 exproccurred @@ -1797,8 +1797,8 @@ bool checkincre(struct Expression *assigned, struct Expression *var, int *result } /* -00430680 func_00430680 -004313E4 func_004313E4 +00430680 find_recurring_mem_accesses +004313E4 all_increments 00455518 func_00455518 0047EBB0 findincre */