From: MaartenBrock Date: Sun, 28 Dec 2008 21:39:44 +0000 (+0000) Subject: * src/mcs51/peeph.def (177.e): replaced notVolatile(%3) with X-Git-Url: https://git.gag.com/?p=fw%2Fsdcc;a=commitdiff_plain;h=c6306c2fbf7c546ffebe284ffeb4ea55ed765811 * src/mcs51/peeph.def (177.e): replaced notVolatile(%3) with operandsNotRelated(%1 %3), had to change (a)r%1 to (a)%1 for this to work (177.j): added new rule * src/SDCCsymt.h: added RESULT_TYPE_GPTR * src/SDCCast.c (processParms): use RESULT_TYPE_GPTR for generic ptr parms, (decorateType CAST): propagate storage class to generic pointer results git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@5305 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index 152b3965..acb7824f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2008-12-28 Maarten Brock + + * src/mcs51/peeph.def (177.e): replaced notVolatile(%3) with + operandsNotRelated(%1 %3), had to change (a)r%1 to (a)%1 for this to work + (177.j): added new rule + * src/SDCCsymt.h: added RESULT_TYPE_GPTR + * src/SDCCast.c (processParms): use RESULT_TYPE_GPTR for generic ptr parms, + (decorateType CAST): propagate storage class to generic pointer results + 2008-12-27 Philipp Klaus Krause * device/lib/z80/string.c, diff --git a/src/SDCCast.c b/src/SDCCast.c index 896a9f6b..bdae3d5a 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -925,7 +925,7 @@ processParms (ast *func, (*actParm)->left = newAst_LINK (defParm->type); (*actParm)->right = pTree; (*actParm)->decorated = 0; /* force typechecking */ - decorateType (*actParm, resultType); + decorateType (*actParm, IS_GENPTR (defParm->type) ? RESULT_TYPE_GPTR : resultType); } /* make a copy and change the regparm type to the defined parm */ @@ -3873,7 +3873,6 @@ decorateType (ast * tree, RESULT_TYPE resultType) changePointer(LTYPE(tree)); checkTypeSanity(LETYPE(tree), "(cast)"); - /* if 'from' and 'to' are the same remove the superfluous cast, * this helps other optimizations */ if (compareTypeExact (LTYPE(tree), RTYPE(tree), -1) == 1) @@ -3903,33 +3902,41 @@ decorateType (ast * tree, RESULT_TYPE resultType) #if 0 /* if the right is a literal replace the tree */ - if (IS_LITERAL (RETYPE (tree))) { - if (!IS_PTR (LTYPE (tree))) { - tree->type = EX_VALUE; - tree->opval.val = - valCastLiteral (LTYPE (tree), - floatFromVal (valFromType (RETYPE (tree)))); - tree->left = NULL; - tree->right = NULL; - TTYPE (tree) = tree->opval.val->type; - tree->values.literalFromCast = 1; - } else if (IS_GENPTR(LTYPE(tree)) && !IS_PTR(RTYPE(tree)) && - ((int) ulFromVal(valFromType(RETYPE(tree)))) !=0 ) /* special case of NULL */ { - sym_link *rest = LTYPE(tree)->next; - werrorfl (tree->filename, tree->lineno, W_LITERAL_GENERIC); - TTYPE(tree) = newLink(DECLARATOR); - DCL_TYPE(TTYPE(tree)) = FPOINTER; - TTYPE(tree)->next = rest; - tree->left->opval.lnk = TTYPE(tree); - LRVAL (tree) = 1; - } else { - TTYPE (tree) = LTYPE (tree); - LRVAL (tree) = 1; - } - } else { + if (IS_LITERAL (RETYPE (tree))) + { + if (!IS_PTR (LTYPE (tree))) + { + tree->type = EX_VALUE; + tree->opval.val = + valCastLiteral (LTYPE (tree), + floatFromVal (valFromType (RETYPE (tree)))); + tree->left = NULL; + tree->right = NULL; + TTYPE (tree) = tree->opval.val->type; + tree->values.literalFromCast = 1; + } + else if (IS_GENPTR(LTYPE(tree)) && !IS_PTR(RTYPE(tree)) && + ((int) ulFromVal(valFromType(RETYPE(tree)))) !=0 ) /* special case of NULL */ + { + sym_link *rest = LTYPE(tree)->next; + werrorfl (tree->filename, tree->lineno, W_LITERAL_GENERIC); + TTYPE(tree) = newLink(DECLARATOR); + DCL_TYPE(TTYPE(tree)) = FPOINTER; + TTYPE(tree)->next = rest; + tree->left->opval.lnk = TTYPE(tree); + LRVAL (tree) = 1; + } + else + { TTYPE (tree) = LTYPE (tree); LRVAL (tree) = 1; - } + } + } + else + { + TTYPE (tree) = LTYPE (tree); + LRVAL (tree) = 1; + } #else #if 0 // this is already checked, now this could be explicit /* if pointer to struct then check names */ @@ -3943,49 +3950,47 @@ decorateType (ast * tree, RESULT_TYPE resultType) #endif if (IS_ADDRESS_OF_OP(tree->right) && IS_AST_SYM_VALUE (tree->right->left) - && SPEC_ABSA (AST_SYMBOL (tree->right->left)->etype)) { - - symbol * sym = AST_SYMBOL (tree->right->left); - unsigned int gptype = 0; - unsigned int addr = SPEC_ADDR (sym->etype); + && SPEC_ABSA (AST_SYMBOL (tree->right->left)->etype)) + { + symbol * sym = AST_SYMBOL (tree->right->left); + unsigned int gptype = 0; + unsigned int addr = SPEC_ADDR (sym->etype); - if (IS_GENPTR (LTYPE (tree)) && ((GPTRSIZE > FPTRSIZE) - || TARGET_IS_PIC16) ) - { - switch (SPEC_SCLS (sym->etype)) - { - case S_CODE: - gptype = GPTYPE_CODE; - break; - case S_XDATA: - gptype = GPTYPE_FAR; - break; - case S_DATA: - case S_IDATA: - gptype = GPTYPE_NEAR; - break; - case S_PDATA: - gptype = GPTYPE_XSTACK; - break; - default: - gptype = 0; + if (IS_GENPTR (LTYPE (tree)) && ((GPTRSIZE > FPTRSIZE) || TARGET_IS_PIC16) ) + { + switch (SPEC_SCLS (sym->etype)) + { + case S_CODE: + gptype = GPTYPE_CODE; + break; + case S_XDATA: + gptype = GPTYPE_FAR; + break; + case S_DATA: + case S_IDATA: + gptype = GPTYPE_NEAR; + break; + case S_PDATA: + gptype = GPTYPE_XSTACK; + break; + default: + gptype = 0; - if(TARGET_IS_PIC16 && (SPEC_SCLS(sym->etype) == S_FIXED)) - gptype = GPTYPE_NEAR; - } - addr |= gptype << (8*(GPTRSIZE - 1)); - } + if(TARGET_IS_PIC16 && (SPEC_SCLS(sym->etype) == S_FIXED)) + gptype = GPTYPE_NEAR; + } + addr |= gptype << (8*(GPTRSIZE - 1)); + } - tree->type = EX_VALUE; - tree->opval.val = - valCastLiteral (LTYPE (tree), addr); - TTYPE (tree) = tree->opval.val->type; - TETYPE (tree) = getSpec (TTYPE (tree)); - tree->left = NULL; - tree->right = NULL; - tree->values.literalFromCast = 1; - return tree; - } + tree->type = EX_VALUE; + tree->opval.val = valCastLiteral (LTYPE (tree), addr); + TTYPE (tree) = tree->opval.val->type; + TETYPE (tree) = getSpec (TTYPE (tree)); + tree->left = NULL; + tree->right = NULL; + tree->values.literalFromCast = 1; + return tree; + } /* handle offsetof macro: */ /* #define offsetof(TYPE, MEMBER) \ */ @@ -3995,84 +4000,91 @@ decorateType (ast * tree, RESULT_TYPE resultType) && tree->right->left->opval.op == PTR_OP && IS_AST_OP (tree->right->left->left) && tree->right->left->left->opval.op == CAST - && IS_AST_LIT_VALUE(tree->right->left->left->right)) { - - symbol *element = getStructElement ( - SPEC_STRUCT (LETYPE(tree->right->left)), - AST_SYMBOL(tree->right->left->right) - ); - - if (element) { - tree->type = EX_VALUE; - tree->opval.val = valCastLiteral ( - LTYPE (tree), - element->offset - + floatFromVal (valFromType (RTYPE (tree->right->left->left))) + && IS_AST_LIT_VALUE(tree->right->left->left->right)) + { + symbol *element = getStructElement ( + SPEC_STRUCT (LETYPE(tree->right->left)), + AST_SYMBOL(tree->right->left->right) ); - TTYPE (tree) = tree->opval.val->type; - TETYPE (tree) = getSpec (TTYPE (tree)); - tree->left = NULL; - tree->right = NULL; - return tree; - } + if (element) + { + tree->type = EX_VALUE; + tree->opval.val = valCastLiteral ( + LTYPE (tree), + element->offset + + floatFromVal (valFromType (RTYPE (tree->right->left->left))) + ); + + TTYPE (tree) = tree->opval.val->type; + TETYPE (tree) = getSpec (TTYPE (tree)); + tree->left = NULL; + tree->right = NULL; + return tree; + } } /* if the right is a literal replace the tree */ - if (IS_LITERAL (RETYPE (tree))) { - #if 0 - if (IS_PTR (LTYPE (tree)) && !IS_GENPTR (LTYPE (tree)) ) { - /* rewrite (type *)litaddr - as &temp - and define type at litaddr temp - (but only if type's storage class is not generic) - */ - ast *newTree = newNode ('&', NULL, NULL); - symbol *sym; - - TTYPE (newTree) = LTYPE (tree); - TETYPE (newTree) = getSpec(LTYPE (tree)); - - /* define a global symbol at the casted address*/ - sym = newSymbol(genSymName (0), 0); - sym->type = LTYPE (tree)->next; - if (!sym->type) - sym->type = newLink (V_VOID); - sym->etype = getSpec(sym->type); - SPEC_SCLS (sym->etype) = sclsFromPtr (LTYPE (tree)); - sym->lineDef = tree->lineno; - sym->cdef = 1; - sym->isref = 1; - SPEC_STAT (sym->etype) = 1; - SPEC_ADDR(sym->etype) = floatFromVal (valFromType (RTYPE (tree))); - SPEC_ABSA(sym->etype) = 1; - addSym (SymbolTab, sym, sym->name, 0, 0, 0); - allocGlobal (sym); - - newTree->left = newAst_VALUE(symbolVal(sym)); - newTree->left->filename = tree->filename; - newTree->left->lineno = tree->lineno; - LTYPE (newTree) = sym->type; - LETYPE (newTree) = sym->etype; - LLVAL (newTree) = 1; - LRVAL (newTree) = 0; - TLVAL (newTree) = 1; - return newTree; - } - #endif - if (!IS_PTR (LTYPE (tree))) { - tree->type = EX_VALUE; - tree->opval.val = - valCastLiteral (LTYPE (tree), - floatFromVal (valFromType (RTYPE (tree)))); - TTYPE (tree) = tree->opval.val->type; - tree->left = NULL; - tree->right = NULL; - tree->values.literalFromCast = 1; - TETYPE (tree) = getSpec (TTYPE (tree)); - return tree; + if (IS_LITERAL (RETYPE (tree))) + { + #if 0 + if (IS_PTR (LTYPE (tree)) && !IS_GENPTR (LTYPE (tree)) ) + { + /* rewrite (type *)litaddr + as &temp + and define type at litaddr temp + (but only if type's storage class is not generic) + */ + ast *newTree = newNode ('&', NULL, NULL); + symbol *sym; + + TTYPE (newTree) = LTYPE (tree); + TETYPE (newTree) = getSpec(LTYPE (tree)); + + /* define a global symbol at the casted address*/ + sym = newSymbol(genSymName (0), 0); + sym->type = LTYPE (tree)->next; + if (!sym->type) + sym->type = newLink (V_VOID); + sym->etype = getSpec(sym->type); + SPEC_SCLS (sym->etype) = sclsFromPtr (LTYPE (tree)); + sym->lineDef = tree->lineno; + sym->cdef = 1; + sym->isref = 1; + SPEC_STAT (sym->etype) = 1; + SPEC_ADDR(sym->etype) = floatFromVal (valFromType (RTYPE (tree))); + SPEC_ABSA(sym->etype) = 1; + addSym (SymbolTab, sym, sym->name, 0, 0, 0); + allocGlobal (sym); + + newTree->left = newAst_VALUE(symbolVal(sym)); + newTree->left->filename = tree->filename; + newTree->left->lineno = tree->lineno; + LTYPE (newTree) = sym->type; + LETYPE (newTree) = sym->etype; + LLVAL (newTree) = 1; + LRVAL (newTree) = 0; + TLVAL (newTree) = 1; + return newTree; + } + #endif + if (!IS_PTR (LTYPE (tree))) + { + tree->type = EX_VALUE; + tree->opval.val = + valCastLiteral (LTYPE (tree), floatFromVal (valFromType (RTYPE (tree)))); + TTYPE (tree) = tree->opval.val->type; + tree->left = NULL; + tree->right = NULL; + tree->values.literalFromCast = 1; + TETYPE (tree) = getSpec (TTYPE (tree)); + return tree; + } + } + if (IS_GENPTR (LTYPE (tree)) && IS_PTR (RTYPE (tree)) && !IS_GENPTR (RTYPE (tree)) && (resultType != RESULT_TYPE_GPTR)) + { + DCL_TYPE (LTYPE (tree)) = DCL_TYPE (RTYPE (tree)); } - } TTYPE (tree) = LTYPE (tree); LRVAL (tree) = 1; diff --git a/src/SDCCsymt.h b/src/SDCCsymt.h index 8fa773c7..c85d1d6e 100644 --- a/src/SDCCsymt.h +++ b/src/SDCCsymt.h @@ -583,6 +583,7 @@ typedef enum RESULT_TYPE_INT, RESULT_TYPE_OTHER, /* operands will be promoted to int */ RESULT_TYPE_IFX, + RESULT_TYPE_GPTR, /* operands will be promoted to generic ptr */ } RESULT_TYPE; /* forward definitions for the symbol table related functions */ diff --git a/src/mcs51/peeph.def b/src/mcs51/peeph.def index d2206dcb..08f8b022 100644 --- a/src/mcs51/peeph.def +++ b/src/mcs51/peeph.def @@ -1332,14 +1332,13 @@ replace restart { } if notVolatile(%1 %2),operandsNotRelated(%1 %2 %3) // applies to f.e. bug-607243.c -// also check notVolatile %3, as it will return FALSE if it's @r%1 replace { - mov r%1,%2 - mov ar%1,%3 + mov %1,%2 + mov a%1,%3 } by { - ; peephole 177.e removed redundant mov - mov ar%1,%3 -} if notVolatile %2 %3 + ; peephole 177.e removed redundant mov %1,%2 + mov a%1,%3 +} if notVolatile(%2), operandsNotRelated(%1 %3) replace { mov ar%1,%2 @@ -1377,6 +1376,16 @@ replace { mov r%2,a } +replace { + mov r%1,%2 + mov ar%3,r%1 + mov r%1,%4 +} by { + ; peephole 177.j optimized mov sequence + mov r%3,%2 + mov r%1,%4 +} + replace { mov a,%1 mov b,a