From 11a6f7ab973ae89dea076e9978200fae5c8b1e87 Mon Sep 17 00:00:00 2001 From: sandeep Date: Sat, 10 Nov 2001 06:42:23 +0000 Subject: [PATCH] Added initial cseCostEstimation function, this I think will grow over a period of time git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1554 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- src/ds390/main.c | 26 ++++++++++++++++++++++++++ src/mcs51/main.c | 27 +++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/src/ds390/main.c b/src/ds390/main.c index 17c9e482..b905d3ce 100644 --- a/src/ds390/main.c +++ b/src/ds390/main.c @@ -201,6 +201,31 @@ _ds390_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts) return TRUE; } +/* Do CSE estimation */ +static bool cseCostEstimation (iCode *ic, iCode *pdic) +{ + operand *result = IC_RESULT(ic); + operand *right = IC_RIGHT(ic); + operand *left = IC_LEFT(ic); + sym_link *result_type = operandType(result); + sym_link *right_type = (right ? operandType(right) : 0); + sym_link *left_type = (left ? operandType(left) : 0); + + /* if it is a pointer then return ok for now */ + if (IC_RESULT(ic) && IS_PTR(result_type)) return 1; + + /* if bitwise | add & subtract then no since mcs51 is pretty good at it + so we will cse only if they are local (i.e. both ic & pdic belong to + the same basic block */ + if (IS_BITWISE_OP(ic) || ic->op == '+' || ic->op == '-') { + /* then if they are the same Basic block then ok */ + if (ic->eBBlockNum == pdic->eBBlockNum) return 1; + else return 0; + } + + /* for others it is cheaper to do the cse */ + return 1; +} /** $1 is always the basename. $2 is always the output file. $3 varies @@ -296,5 +321,6 @@ PORT ds390_port = 1, /* transform != to !(a == b) */ 0, /* leave == */ TRUE, /* we support array initializers. */ + cseCostEstimation, PORT_MAGIC }; diff --git a/src/mcs51/main.c b/src/mcs51/main.c index c20e8037..f4f5ba70 100644 --- a/src/mcs51/main.c +++ b/src/mcs51/main.c @@ -120,6 +120,32 @@ _mcs51_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts) return FALSE; } +/* Do CSE estimation */ +static bool cseCostEstimation (iCode *ic, iCode *pdic) +{ + operand *result = IC_RESULT(ic); + operand *right = IC_RIGHT(ic); + operand *left = IC_LEFT(ic); + sym_link *result_type = operandType(result); + sym_link *right_type = (right ? operandType(right) : 0); + sym_link *left_type = (left ? operandType(left) : 0); + + /* if it is a pointer then return ok for now */ + if (IC_RESULT(ic) && IS_PTR(result_type)) return 1; + + /* if bitwise | add & subtract then no since mcs51 is pretty good at it + so we will cse only if they are local (i.e. both ic & pdic belong to + the same basic block */ + if (IS_BITWISE_OP(ic) || ic->op == '+' || ic->op == '-') { + /* then if they are the same Basic block then ok */ + if (ic->eBBlockNum == pdic->eBBlockNum) return 1; + else return 0; + } + + /* for others it is cheaper to do the cse */ + return 1; +} + /** $1 is always the basename. $2 is always the output file. $3 varies @@ -216,5 +242,6 @@ PORT mcs51_port = 1, /* transform != to !(a == b) */ 0, /* leave == */ FALSE, /* No array initializer support. */ + cseCostEstimation, PORT_MAGIC }; -- 2.47.2