mirror of
https://github.com/cc65/cc65.git
synced 2025-08-08 22:25:28 +00:00
So far the built-in inlining of several known standard function was always (!) enabled and the option -Os enabled additional, potentially unsafe inlining of some of those functions.
There were two aspects of this behavior that were considered undesirable: - Although the safe inlining is in general desirable it should only be enabled if asked for it - like any other optimization. - The option name -Os implies that it is a safe option, the potentially unsafe inlining should have a more explicit name. So now: - The option -Os enables the safe inlining. - The new option --eagerly-inline-funcs enables the potentially unsafe inlining (including the safe inlining). Additionally was added: - The option --inline-stdfuncs that does like -Os enable the safe inlining but doesn't enable optimizations. - The pragma inline-stdfuncs that works identical to --inline-stdfuncs. - The pragma allow-eager-inline that enables the potentially unsafe inlining but doesn't include the safe inlining. That means that by itself it only marks code as safe for potentially unsafe inlining but doesn't actually enable any inlining.
This commit is contained in:
104
doc/cc65.sgml
104
doc/cc65.sgml
@@ -58,7 +58,7 @@ Short options:
|
||||
-O Optimize code
|
||||
-Oi Optimize code, inline more code
|
||||
-Or Enable register variables
|
||||
-Os Inline some known functions
|
||||
-Os Inline some standard functions
|
||||
-T Include source as comment
|
||||
-V Print the compiler version number
|
||||
-W warning[,...] Suppress warnings
|
||||
@@ -88,9 +88,11 @@ Long options:
|
||||
--debug-opt name Debug optimization steps
|
||||
--dep-target target Use this dependency target
|
||||
--disable-opt name Disable an optimization step
|
||||
--eagerly-inline-funcs Eagerly inline some known functions
|
||||
--enable-opt name Enable an optimization step
|
||||
--help Help (this text)
|
||||
--include-dir dir Set an include directory search path
|
||||
--inline-stdfuncs Inline some standard functions
|
||||
--list-opt-steps List all optimizer steps and exit
|
||||
--list-warnings List available warning types for -W
|
||||
--local-strings Emit string literals immediately
|
||||
@@ -219,11 +221,53 @@ Here is a description of all the command line options:
|
||||
symbols in a special section in the object file.
|
||||
|
||||
|
||||
<label id="option-eagerly-inline-funcs">
|
||||
<tag><tt>--eagerly-inline-funcs</tt></tag>
|
||||
|
||||
Have the compiler eagerly inline these functions from the C library:
|
||||
<itemize>
|
||||
<item><tt/memcpy()/
|
||||
<item><tt/memset()/
|
||||
<item><tt/strcmp()/
|
||||
<item><tt/strcpy()/
|
||||
<item><tt/strlen()/
|
||||
<item>most of the functions declared in <tt/<ctype.h>/
|
||||
</itemize>
|
||||
|
||||
Note: This has two consequences:
|
||||
<itemize>
|
||||
<item>You may not use names of standard C functions for your own functions.
|
||||
If you do that, your program is not standard-compliant anyway; but,
|
||||
using <tt/--eagerly-inline-funcs/ actually will break things.
|
||||
<p>
|
||||
<item>The inlined string and memory functions will not handle strings or
|
||||
memory areas larger than 255 bytes. Similarly, the inlined <tt/is..()/
|
||||
functions will not work with values outside the char. range (such as
|
||||
<tt/EOF/).
|
||||
<p>
|
||||
</itemize>
|
||||
|
||||
<tt/--eagerly-inline-funcs/ implies the <tt/<ref id="option-inline-stdfuncs"
|
||||
name="--inline-stdfuncs"/ command line option.
|
||||
|
||||
See also <tt/<ref id="pragma-allow-eager-inline" name="#pragma allow-eager-inline">/.
|
||||
|
||||
|
||||
<tag><tt>-h, --help</tt></tag>
|
||||
|
||||
Print the short option summary shown above.
|
||||
|
||||
|
||||
<label id="option-inline-stdfuncs">
|
||||
<tag><tt>--inline-stdfuncs</tt></tag>
|
||||
|
||||
Allow the compiler to inline some standard functions from the C library like
|
||||
strlen. This will not only remove the overhead for a function call, but will
|
||||
make the code visible for the optimizer. See also the <tt/<ref id="option-O"
|
||||
name="-Os"/ command line option and <tt/<ref id="pragma-inline-stdfuncs"
|
||||
name="#pragma inline-stdfuncs">/.
|
||||
|
||||
|
||||
<label id="option-list-warnings">
|
||||
<tag><tt>--list-warnings</tt></tag>
|
||||
|
||||
@@ -444,23 +488,13 @@ Here is a description of all the command line options:
|
||||
name="--register-vars">/ command line option, and the <ref
|
||||
id="register-vars" name="discussion of register variables"> below.
|
||||
|
||||
Using <tt/-Os/ will force the compiler to inline some known functions from
|
||||
the C library like strlen. Note: This has two consequences:
|
||||
<p>
|
||||
<itemize>
|
||||
<item>You may not use names of standard C functions in your own code. If you
|
||||
do that, your program is not standard compliant anyway, but using
|
||||
<tt/-Os/ will actually break things.
|
||||
<p>
|
||||
<item>The inlined string and memory functions will not handle strings or
|
||||
memory areas larger than 255 bytes. Similarly, the inlined <tt/is..()/
|
||||
functions will not work with values outside the char. range (such as
|
||||
<tt/EOF/).
|
||||
<p>
|
||||
</itemize>
|
||||
<p>
|
||||
Using <tt/-Os/ will allow the compiler to inline some standard functions
|
||||
from the C library like strlen. This will not only remove the overhead
|
||||
for a function call, but will make the code visible for the optimizer.
|
||||
See also <tt/<ref id="option-inline-stdfuncs" name="--inline-stdfuncs"/.
|
||||
|
||||
It is possible to concatenate the modifiers for <tt/-O/. For example, to
|
||||
enable register variables and inlining of known functions, you may use
|
||||
enable register variables and inlining of standard functions, you may use
|
||||
<tt/-Ors/.
|
||||
|
||||
|
||||
@@ -518,6 +552,7 @@ Here is a description of all the command line options:
|
||||
</descrip><p>
|
||||
|
||||
|
||||
|
||||
<sect>Input and output<p>
|
||||
|
||||
The compiler will accept one C file per invocation and create a file with
|
||||
@@ -626,7 +661,6 @@ This cc65 version has some extensions to the ISO C standard.
|
||||
For functions that are <tt/fastcall/, the rightmost parameter is not
|
||||
pushed on the stack but left in the primary register when the function
|
||||
is called. That significantly reduces the cost of calling those functions.
|
||||
<newline><newline>
|
||||
<p>
|
||||
|
||||
<item> There is another calling convention named "cdecl". Variadic functions
|
||||
@@ -652,7 +686,7 @@ This cc65 version has some extensions to the ISO C standard.
|
||||
For functions that are <tt/cdecl/, the rightmost parameter is pushed
|
||||
onto the stack before the function is called. That increases the cost
|
||||
of calling those functions, especially when they are called from many
|
||||
places.<newline><newline>
|
||||
places.
|
||||
<p>
|
||||
|
||||
<item> There are two pseudo variables named <tt/__AX__/ and <tt/__EAX__/.
|
||||
@@ -825,6 +859,11 @@ The compiler defines several macros at startup:
|
||||
This macro expands to the date of translation of the preprocessing
|
||||
translation unit in the form "Mmm dd yyyy".
|
||||
|
||||
<tag><tt>__EAGERLY_INLINE_FUNCS__</tt></tag>
|
||||
|
||||
Is defined if the compiler was called with the <tt/<ref id="option-eagerly-inline-funcs"
|
||||
name="--eagerly-inline-funcs"/ command line option.
|
||||
|
||||
<tag><tt>__FILE__</tt></tag>
|
||||
|
||||
This macro expands to a string containing the name of the C source file.
|
||||
@@ -912,6 +951,7 @@ The compiler defines several macros at startup:
|
||||
</descrip>
|
||||
|
||||
|
||||
|
||||
<sect>#pragmas<label id="pragmas"><p>
|
||||
|
||||
The compiler understands some pragmas that may be used to change code
|
||||
@@ -920,6 +960,19 @@ If the first parameter is <tt/push/, the old value is saved onto a stack
|
||||
before changing it. The value may later be restored by using the <tt/pop/
|
||||
parameter with the <tt/#pragma/.
|
||||
|
||||
|
||||
<sect1><tt>#pragma allow-eager-inline ([push,] on|off)</tt><label id="pragma-allow-eager-inline"><p>
|
||||
|
||||
Allow eager inlining of known functions. If the argument is "off", eager
|
||||
inlining is disabled, otherwise it is enabled. Please note that (in contrast
|
||||
to the <tt/<ref id="option-eagerly-inline-funcs" name="--eagerly-inline-funcs"/
|
||||
command line option) this pragma does not imply the <tt/<ref id="option-inline-stdfuncs"
|
||||
name="--inline-stdfuncs"/ command line option. Rather it marks code to be safe for
|
||||
eager inlining of known functions if inlining of standard functions is enabled.
|
||||
|
||||
The <tt/#pragma/ understands the push and pop parameters as explained above.
|
||||
|
||||
|
||||
<sect1><tt>#pragma bss-name ([push,] <name>)</tt><label id="pragma-bss-name"><p>
|
||||
|
||||
This pragma changes the name used for the BSS segment (the BSS segment
|
||||
@@ -993,6 +1046,7 @@ parameter with the <tt/#pragma/.
|
||||
|
||||
The <tt/#pragma/ understands the push and pop parameters as explained above.
|
||||
|
||||
|
||||
<sect1><tt>#pragma code-name ([push,] <name>)</tt><label id="pragma-code-name"><p>
|
||||
|
||||
This pragma changes the name used for the CODE segment (the CODE segment
|
||||
@@ -1039,6 +1093,17 @@ parameter with the <tt/#pragma/.
|
||||
</verb></tscreen>
|
||||
|
||||
|
||||
<sect1><tt>#pragma inline-stdfuncs ([push,] on|off)</tt><label id="pragma-inline-stdfuncs"><p>
|
||||
|
||||
Allow the compiler to inline some standard functions from the C library like
|
||||
strlen. If the argument is "off", inlining is disabled, otherwise it is enabled.
|
||||
|
||||
See also the the <tt/<ref id="option-inline-stdfuncs" name="--inline-stdfuncs"/
|
||||
command line option.
|
||||
|
||||
The <tt/#pragma/ understands the push and pop parameters as explained above.
|
||||
|
||||
|
||||
<sect1><tt>#pragma local-strings ([push,] on|off)</tt><label id="pragma-local-strings"><p>
|
||||
|
||||
When "on", emit string literals to the data segment when they're encountered
|
||||
@@ -1193,7 +1258,6 @@ parameter with the <tt/#pragma/.
|
||||
|
||||
|
||||
|
||||
|
||||
<sect>Register variables<label id="register-vars"><p>
|
||||
|
||||
The runtime for all supported platforms has 6 bytes of zero page space
|
||||
|
@@ -54,9 +54,9 @@ Short options:
|
||||
-L path Specify a library search path
|
||||
-Ln name Create a VICE label file
|
||||
-O Optimize code
|
||||
-Oi Optimize code, inline functions
|
||||
-Oi Optimize code, inline more code
|
||||
-Or Optimize code, honour the register keyword
|
||||
-Os Optimize code, inline known C funtions
|
||||
-Os Optimize code, inline standard funtions
|
||||
-S Compile but don't assemble and link
|
||||
-T Include source as comment
|
||||
-V Print the version number
|
||||
|
@@ -89,9 +89,9 @@ unsigned char __fastcall__ toascii (unsigned char c);
|
||||
** #undef'ing the macroes.
|
||||
** Please note that the following macroes do NOT handle EOF correctly, as
|
||||
** stated in the manual. If you need correct behaviour for EOF, don't
|
||||
** use -Os, or #undefine the following macroes.
|
||||
** use --eagerly-inline-funcs, or #undefine the following macroes.
|
||||
*/
|
||||
#ifdef __OPT_s__
|
||||
#ifdef __EAGERLY_INLINE_FUNCS__
|
||||
|
||||
#define isalnum(c) (__AX__ = (c), \
|
||||
__asm__ ("tay"), \
|
||||
|
@@ -335,17 +335,22 @@ void Compile (const char* FileName)
|
||||
** changes using #pragma later.
|
||||
*/
|
||||
if (IS_Get (&Optimize)) {
|
||||
long CodeSize = IS_Get (&CodeSizeFactor);
|
||||
DefineNumericMacro ("__OPT__", 1);
|
||||
}
|
||||
{
|
||||
long CodeSize = IS_Get (&CodeSizeFactor);
|
||||
if (CodeSize > 100) {
|
||||
DefineNumericMacro ("__OPT_i__", CodeSize);
|
||||
}
|
||||
}
|
||||
if (IS_Get (&EnableRegVars)) {
|
||||
DefineNumericMacro ("__OPT_r__", 1);
|
||||
}
|
||||
if (IS_Get (&InlineStdFuncs)) {
|
||||
DefineNumericMacro ("__OPT_s__", 1);
|
||||
}
|
||||
if (IS_Get (&EagerlyInlineFuncs)) {
|
||||
DefineNumericMacro ("__EAGERLY_INLINE_FUNCS__", 1);
|
||||
}
|
||||
|
||||
/* __TIME__ and __DATE__ macros */
|
||||
|
@@ -53,7 +53,8 @@ unsigned RegisterSpace = 6; /* Space available for register vars */
|
||||
/* Stackable options */
|
||||
IntStack WritableStrings = INTSTACK(0); /* Literal strings are r/w */
|
||||
IntStack LocalStrings = INTSTACK(0); /* Emit string literals immediately */
|
||||
IntStack InlineStdFuncs = INTSTACK(0); /* Inline some known functions */
|
||||
IntStack InlineStdFuncs = INTSTACK(0); /* Inline some standard functions */
|
||||
IntStack EagerlyInlineFuncs = INTSTACK(0); /* Eagerly inline some known functions */
|
||||
IntStack EnableRegVars = INTSTACK(0); /* Enable register variables */
|
||||
IntStack AllowRegVarAddr = INTSTACK(0); /* Allow taking addresses of register vars */
|
||||
IntStack RegVarsToCallStack = INTSTACK(0); /* Save reg variables on call stack */
|
||||
|
@@ -61,7 +61,8 @@ extern unsigned RegisterSpace; /* Space available for register
|
||||
/* Stackable options */
|
||||
extern IntStack WritableStrings; /* Literal strings are r/w */
|
||||
extern IntStack LocalStrings; /* Emit string literals immediately */
|
||||
extern IntStack InlineStdFuncs; /* Inline some known functions */
|
||||
extern IntStack InlineStdFuncs; /* Inline some standard functions */
|
||||
extern IntStack EagerlyInlineFuncs; /* Eagerly inline some known functions */
|
||||
extern IntStack EnableRegVars; /* Enable register variables */
|
||||
extern IntStack AllowRegVarAddr; /* Allow taking addresses of register vars */
|
||||
extern IntStack RegVarsToCallStack; /* Save reg variables on call stack */
|
||||
|
@@ -88,7 +88,7 @@ static void Usage (void)
|
||||
" -O\t\t\t\tOptimize code\n"
|
||||
" -Oi\t\t\t\tOptimize code, inline more code\n"
|
||||
" -Or\t\t\t\tEnable register variables\n"
|
||||
" -Os\t\t\t\tInline some known functions\n"
|
||||
" -Os\t\t\t\tInline some standard functions\n"
|
||||
" -T\t\t\t\tInclude source as comment\n"
|
||||
" -V\t\t\t\tPrint the compiler version number\n"
|
||||
" -W warning[,...]\t\tSuppress warnings\n"
|
||||
@@ -118,9 +118,11 @@ static void Usage (void)
|
||||
" --debug-opt name\t\tDebug optimization steps\n"
|
||||
" --dep-target target\t\tUse this dependency target\n"
|
||||
" --disable-opt name\t\tDisable an optimization step\n"
|
||||
" --eagerly-inline-funcs\t\tEagerly inline some known functions\n"
|
||||
" --enable-opt name\t\tEnable an optimization step\n"
|
||||
" --help\t\t\tHelp (this text)\n"
|
||||
" --include-dir dir\t\tSet an include directory search path\n"
|
||||
" --inline-stdfuncs\t\tInline some standard functions\n"
|
||||
" --list-opt-steps\t\tList all optimizer steps and exit\n"
|
||||
" --list-warnings\t\tList available warning types for -W\n"
|
||||
" --local-strings\t\tEmit string literals immediately\n"
|
||||
@@ -581,6 +583,16 @@ static void OptDisableOpt (const char* Opt attribute ((unused)), const char* Arg
|
||||
|
||||
|
||||
|
||||
static void OptEagerlyInlineFuncs (const char* Opt attribute((unused)),
|
||||
const char* Arg attribute((unused)))
|
||||
/* Eagerly inline some known functions */
|
||||
{
|
||||
IS_Set (&InlineStdFuncs, 1);
|
||||
IS_Set (&EagerlyInlineFuncs, 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void OptEnableOpt (const char* Opt attribute ((unused)), const char* Arg)
|
||||
/* Enable an optimization step */
|
||||
{
|
||||
@@ -608,6 +620,15 @@ static void OptIncludeDir (const char* Opt attribute ((unused)), const char* Arg
|
||||
|
||||
|
||||
|
||||
static void OptInlineStdFuncs (const char* Opt attribute((unused)),
|
||||
const char* Arg attribute((unused)))
|
||||
/* Inline some standard functions */
|
||||
{
|
||||
IS_Set (&InlineStdFuncs, 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void OptListOptSteps (const char* Opt attribute ((unused)),
|
||||
const char* Arg attribute ((unused)))
|
||||
/* List all optimizer steps */
|
||||
@@ -835,9 +856,11 @@ int main (int argc, char* argv[])
|
||||
{ "--debug-opt-output", 0, OptDebugOptOutput },
|
||||
{ "--dep-target", 1, OptDepTarget },
|
||||
{ "--disable-opt", 1, OptDisableOpt },
|
||||
{ "--eagerly-inline-funcs", 0, OptEagerlyInlineFuncs },
|
||||
{ "--enable-opt", 1, OptEnableOpt },
|
||||
{ "--help", 0, OptHelp },
|
||||
{ "--include-dir", 1, OptIncludeDir },
|
||||
{ "--inline-stdfuncs", 0, OptInlineStdFuncs },
|
||||
{ "--list-opt-steps", 0, OptListOptSteps },
|
||||
{ "--list-warnings", 0, OptListWarnings },
|
||||
{ "--local-strings", 0, OptLocalStrings },
|
||||
|
@@ -64,6 +64,7 @@
|
||||
typedef enum {
|
||||
PRAGMA_ILLEGAL = -1,
|
||||
PRAGMA_ALIGN,
|
||||
PRAGMA_ALLOW_EAGER_INLINE,
|
||||
PRAGMA_BSS_NAME,
|
||||
PRAGMA_BSSSEG, /* obsolete */
|
||||
PRAGMA_CHARMAP,
|
||||
@@ -74,6 +75,7 @@ typedef enum {
|
||||
PRAGMA_CODESIZE,
|
||||
PRAGMA_DATA_NAME,
|
||||
PRAGMA_DATASEG, /* obsolete */
|
||||
PRAGMA_INLINE_STDFUNCS,
|
||||
PRAGMA_LOCAL_STRINGS,
|
||||
PRAGMA_OPTIMIZE,
|
||||
PRAGMA_REGVARADDR,
|
||||
@@ -97,6 +99,7 @@ static const struct Pragma {
|
||||
pragma_t Tok; /* Token */
|
||||
} Pragmas[PRAGMA_COUNT] = {
|
||||
{ "align", PRAGMA_ALIGN },
|
||||
{ "allow-eager-inline", PRAGMA_ALLOW_EAGER_INLINE },
|
||||
{ "bss-name", PRAGMA_BSS_NAME },
|
||||
{ "bssseg", PRAGMA_BSSSEG }, /* obsolete */
|
||||
{ "charmap", PRAGMA_CHARMAP },
|
||||
@@ -107,6 +110,7 @@ static const struct Pragma {
|
||||
{ "codesize", PRAGMA_CODESIZE },
|
||||
{ "data-name", PRAGMA_DATA_NAME },
|
||||
{ "dataseg", PRAGMA_DATASEG }, /* obsolete */
|
||||
{ "inline-stdfuncs", PRAGMA_INLINE_STDFUNCS },
|
||||
{ "local-strings", PRAGMA_LOCAL_STRINGS },
|
||||
{ "optimize", PRAGMA_OPTIMIZE },
|
||||
{ "register-vars", PRAGMA_REGISTER_VARS },
|
||||
@@ -703,6 +707,10 @@ static void ParsePragma (void)
|
||||
IntPragma (&B, &DataAlignment, 1, 4096);
|
||||
break;
|
||||
|
||||
case PRAGMA_ALLOW_EAGER_INLINE:
|
||||
FlagPragma (&B, &EagerlyInlineFuncs);
|
||||
break;
|
||||
|
||||
case PRAGMA_BSSSEG:
|
||||
Warning ("#pragma bssseg is obsolete, please use #pragma bss-name instead");
|
||||
/* FALLTHROUGH */
|
||||
@@ -739,6 +747,10 @@ static void ParsePragma (void)
|
||||
SegNamePragma (&B, SEG_DATA);
|
||||
break;
|
||||
|
||||
case PRAGMA_INLINE_STDFUNCS:
|
||||
FlagPragma (&B, &InlineStdFuncs);
|
||||
break;
|
||||
|
||||
case PRAGMA_LOCAL_STRINGS:
|
||||
FlagPragma (&B, &LocalStrings);
|
||||
break;
|
||||
|
@@ -261,6 +261,8 @@ static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
||||
goto ExitPoint;
|
||||
}
|
||||
|
||||
if (IS_Get (&InlineStdFuncs)) {
|
||||
|
||||
/* We've generated the complete code for the function now and know the
|
||||
** types of all parameters. Check for situations where better code can
|
||||
** be generated. If such a situation is detected, throw away the
|
||||
@@ -324,7 +326,11 @@ static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
||||
*/
|
||||
*Expr = Arg1.Expr;
|
||||
|
||||
} else if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.IVal <= 256 &&
|
||||
/* Bail out, no need for further processing */
|
||||
goto ExitPoint;
|
||||
}
|
||||
|
||||
if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.IVal <= 256 &&
|
||||
ED_IsRVal (&Arg2.Expr) && ED_IsLocConst (&Arg2.Expr) &&
|
||||
ED_IsRVal (&Arg1.Expr) && ED_IsLocStack (&Arg1.Expr) &&
|
||||
(Arg1.Expr.IVal - StackPtr) + Arg3.Expr.IVal < 256) {
|
||||
@@ -398,7 +404,11 @@ static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
||||
*/
|
||||
*Expr = Arg1.Expr;
|
||||
|
||||
} else if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.IVal <= 256 &&
|
||||
/* Bail out, no need for further processing */
|
||||
goto ExitPoint;
|
||||
}
|
||||
|
||||
if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.IVal <= 256 &&
|
||||
ED_IsRVal (&Arg2.Expr) && ED_IsLocStack (&Arg2.Expr) &&
|
||||
(Arg2.Expr.IVal - StackPtr) + Arg3.Expr.IVal < 256 &&
|
||||
ED_IsRVal (&Arg1.Expr) && ED_IsLocConst (&Arg1.Expr)) {
|
||||
@@ -472,7 +482,11 @@ static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
||||
*/
|
||||
*Expr = Arg1.Expr;
|
||||
|
||||
} else if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.IVal <= 256 &&
|
||||
/* Bail out, no need for further processing */
|
||||
goto ExitPoint;
|
||||
}
|
||||
|
||||
if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.IVal <= 256 &&
|
||||
ED_IsRVal (&Arg2.Expr) && ED_IsLocStack (&Arg2.Expr) &&
|
||||
(Offs = ED_GetStackOffs (&Arg2.Expr, 0)) == 0) {
|
||||
|
||||
@@ -509,14 +523,15 @@ static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
||||
ED_MakeRValExpr (Expr);
|
||||
Expr->Type = GetFuncReturn (Expr->Type);
|
||||
|
||||
} else {
|
||||
/* Bail out, no need for further processing */
|
||||
goto ExitPoint;
|
||||
}
|
||||
}
|
||||
|
||||
/* The function result is an rvalue in the primary register */
|
||||
ED_MakeRValExpr (Expr);
|
||||
Expr->Type = GetFuncReturn (Expr->Type);
|
||||
|
||||
}
|
||||
|
||||
ExitPoint:
|
||||
/* We expect the closing brace */
|
||||
ConsumeRParen ();
|
||||
@@ -595,6 +610,8 @@ static void StdFunc_memset (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
||||
goto ExitPoint;
|
||||
}
|
||||
|
||||
if (IS_Get (&InlineStdFuncs)) {
|
||||
|
||||
/* We've generated the complete code for the function now and know the
|
||||
** types of all parameters. Check for situations where better code can
|
||||
** be generated. If such a situation is detected, throw away the
|
||||
@@ -652,7 +669,11 @@ static void StdFunc_memset (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
||||
*/
|
||||
*Expr = Arg1.Expr;
|
||||
|
||||
} else if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.IVal <= 256 &&
|
||||
/* Bail out, no need for further processing */
|
||||
goto ExitPoint;
|
||||
}
|
||||
|
||||
if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.IVal <= 256 &&
|
||||
ED_IsConstAbsInt (&Arg2.Expr) &&
|
||||
ED_IsRVal (&Arg1.Expr) && ED_IsLocStack (&Arg1.Expr) &&
|
||||
(Arg1.Expr.IVal - StackPtr) + Arg3.Expr.IVal < 256) {
|
||||
@@ -680,7 +701,11 @@ static void StdFunc_memset (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
||||
*/
|
||||
*Expr = Arg1.Expr;
|
||||
|
||||
} else if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.IVal <= 256 &&
|
||||
/* Bail out, no need for further processing */
|
||||
goto ExitPoint;
|
||||
}
|
||||
|
||||
if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.IVal <= 256 &&
|
||||
ED_IsConstAbsInt (&Arg2.Expr) &&
|
||||
(Arg2.Expr.IVal != 0 || IS_Get (&CodeSizeFactor) > 200)) {
|
||||
|
||||
@@ -721,14 +746,15 @@ static void StdFunc_memset (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
||||
ED_MakeRValExpr (Expr);
|
||||
Expr->Type = GetFuncReturn (Expr->Type);
|
||||
|
||||
} else {
|
||||
/* Bail out, no need for further processing */
|
||||
goto ExitPoint;
|
||||
}
|
||||
}
|
||||
|
||||
/* The function result is an rvalue in the primary register */
|
||||
ED_MakeRValExpr (Expr);
|
||||
Expr->Type = GetFuncReturn (Expr->Type);
|
||||
|
||||
}
|
||||
|
||||
ExitPoint:
|
||||
/* We expect the closing brace */
|
||||
ConsumeRParen ();
|
||||
@@ -790,6 +816,8 @@ static void StdFunc_strcmp (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
||||
ECount1 = ECount2;
|
||||
}
|
||||
|
||||
if (IS_Get (&InlineStdFuncs)) {
|
||||
|
||||
/* If the second argument is the empty string literal, we can generate
|
||||
** more efficient code.
|
||||
*/
|
||||
@@ -841,8 +869,7 @@ static void StdFunc_strcmp (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
||||
(ED_IsLVal (&Arg2.Expr) && ED_IsLocRegister (&Arg2.Expr))) &&
|
||||
((ED_IsRVal (&Arg1.Expr) && ED_IsLocConst (&Arg1.Expr)) ||
|
||||
(ED_IsLVal (&Arg1.Expr) && ED_IsLocRegister (&Arg1.Expr))) &&
|
||||
(IS_Get (&InlineStdFuncs) || (ECount1 > 0 && ECount1 < 256))) {
|
||||
|
||||
(IS_Get (&EagerlyInlineFuncs) || (ECount1 > 0 && ECount1 < 256))) {
|
||||
|
||||
unsigned Entry, Loop, Fin; /* Labels */
|
||||
const char* Load;
|
||||
@@ -886,8 +913,7 @@ static void StdFunc_strcmp (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
||||
} else if ((IS_Get (&CodeSizeFactor) > 190) &&
|
||||
((ED_IsRVal (&Arg2.Expr) && ED_IsLocConst (&Arg2.Expr)) ||
|
||||
(ED_IsLVal (&Arg2.Expr) && ED_IsLocRegister (&Arg2.Expr))) &&
|
||||
(IS_Get (&InlineStdFuncs) || (ECount1 > 0 && ECount1 < 256))) {
|
||||
|
||||
(IS_Get (&EagerlyInlineFuncs) || (ECount1 > 0 && ECount1 < 256))) {
|
||||
|
||||
unsigned Entry, Loop, Fin; /* Labels */
|
||||
const char* Compare;
|
||||
@@ -925,7 +951,7 @@ static void StdFunc_strcmp (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
||||
AddCodeLine ("bcs %s", LocalLabelName (Fin));
|
||||
AddCodeLine ("ldx #$FF");
|
||||
g_defcodelabel (Fin);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* The function result is an rvalue in the primary register */
|
||||
@@ -983,6 +1009,8 @@ static void StdFunc_strcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
||||
/* Get the element count of argument 1 if it is an array */
|
||||
ECount = ArrayElementCount (&Arg1);
|
||||
|
||||
if (IS_Get (&InlineStdFuncs)) {
|
||||
|
||||
/* We've generated the complete code for the function now and know the
|
||||
** types of all parameters. Check for situations where better code can
|
||||
** be generated. If such a situation is detected, throw away the
|
||||
@@ -992,7 +1020,7 @@ static void StdFunc_strcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
||||
(ED_IsLVal (&Arg2.Expr) && ED_IsLocRegister (&Arg2.Expr))) &&
|
||||
((ED_IsRVal (&Arg1.Expr) && ED_IsLocConst (&Arg1.Expr)) ||
|
||||
(ED_IsLVal (&Arg1.Expr) && ED_IsLocRegister (&Arg1.Expr))) &&
|
||||
(IS_Get (&InlineStdFuncs) ||
|
||||
(IS_Get (&EagerlyInlineFuncs) ||
|
||||
(ECount != UNSPECIFIED && ECount < 256))) {
|
||||
|
||||
const char* Load;
|
||||
@@ -1025,7 +1053,11 @@ static void StdFunc_strcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
||||
/* strcpy returns argument #1 */
|
||||
*Expr = Arg1.Expr;
|
||||
|
||||
} else if (ED_IsRVal (&Arg2.Expr) && ED_IsLocStack (&Arg2.Expr) &&
|
||||
/* Bail out, no need for further processing */
|
||||
goto ExitPoint;
|
||||
}
|
||||
|
||||
if (ED_IsRVal (&Arg2.Expr) && ED_IsLocStack (&Arg2.Expr) &&
|
||||
StackPtr >= -255 &&
|
||||
ED_IsRVal (&Arg1.Expr) && ED_IsLocConst (&Arg1.Expr)) {
|
||||
|
||||
@@ -1068,7 +1100,11 @@ static void StdFunc_strcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
||||
/* strcpy returns argument #1 */
|
||||
*Expr = Arg1.Expr;
|
||||
|
||||
} else if (ED_IsRVal (&Arg2.Expr) && ED_IsLocConst (&Arg2.Expr) &&
|
||||
/* Bail out, no need for further processing */
|
||||
goto ExitPoint;
|
||||
}
|
||||
|
||||
if (ED_IsRVal (&Arg2.Expr) && ED_IsLocConst (&Arg2.Expr) &&
|
||||
ED_IsRVal (&Arg1.Expr) && ED_IsLocStack (&Arg1.Expr) &&
|
||||
StackPtr >= -255) {
|
||||
|
||||
@@ -1111,14 +1147,16 @@ static void StdFunc_strcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
||||
/* strcpy returns argument #1 */
|
||||
*Expr = Arg1.Expr;
|
||||
|
||||
} else {
|
||||
/* Bail out, no need for further processing */
|
||||
goto ExitPoint;
|
||||
}
|
||||
}
|
||||
|
||||
/* The function result is an rvalue in the primary register */
|
||||
ED_MakeRValExpr (Expr);
|
||||
Expr->Type = GetFuncReturn (Expr->Type);
|
||||
|
||||
}
|
||||
|
||||
ExitPoint:
|
||||
/* We expect the closing brace */
|
||||
ConsumeRParen ();
|
||||
}
|
||||
@@ -1142,8 +1180,6 @@ static void StdFunc_strlen (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
||||
long ECount;
|
||||
unsigned L;
|
||||
|
||||
|
||||
|
||||
/* Setup the argument type string */
|
||||
ArgType[1].C = GetDefaultChar () | T_QUAL_CONST;
|
||||
|
||||
@@ -1175,6 +1211,8 @@ static void StdFunc_strlen (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
||||
/* Do type conversion */
|
||||
TypeConversion (&Arg, ArgType);
|
||||
|
||||
if (IS_Get (&Optimize)) {
|
||||
|
||||
/* If the expression is a literal, and if string literals are read
|
||||
** only, we can calculate the length of the string and remove it
|
||||
** from the literal pool. Otherwise we have to calculate the length
|
||||
@@ -1188,12 +1226,19 @@ static void StdFunc_strlen (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
||||
/* We don't need the literal any longer */
|
||||
ReleaseLiteral (Arg.LVal);
|
||||
|
||||
/* We will inline strlen for arrays with constant addresses, if either the
|
||||
** inlining was forced on the command line, or the array is smaller than
|
||||
** 256, so the inlining is considered safe.
|
||||
/* Bail out, no need for further improvements */
|
||||
goto ExitPoint;
|
||||
}
|
||||
}
|
||||
|
||||
if (IS_Get (&InlineStdFuncs)) {
|
||||
|
||||
/* We will inline strlen for arrays with constant addresses, if either
|
||||
** requested on the command line, or the array is smaller than 256,
|
||||
** so the inlining is considered safe.
|
||||
*/
|
||||
} else if (ED_IsLocConst (&Arg) && IsArray &&
|
||||
(IS_Get (&InlineStdFuncs) || IsByteIndex)) {
|
||||
if (ED_IsLocConst (&Arg) && IsArray &&
|
||||
(IS_Get (&EagerlyInlineFuncs) || IsByteIndex)) {
|
||||
|
||||
/* Generate the strlen code */
|
||||
L = GetLocalLabel ();
|
||||
@@ -1209,10 +1254,14 @@ static void StdFunc_strlen (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
||||
ED_MakeRValExpr (Expr);
|
||||
Expr->Type = type_size_t;
|
||||
|
||||
/* Bail out, no need for further processing */
|
||||
goto ExitPoint;
|
||||
}
|
||||
|
||||
/* We will inline strlen for arrays on the stack, if the array is
|
||||
** completely within the reach of a byte sized index register.
|
||||
*/
|
||||
} else if (ED_IsLocStack (&Arg) && IsArray && IsByteIndex &&
|
||||
if (ED_IsLocStack (&Arg) && IsArray && IsByteIndex &&
|
||||
(Arg.IVal - StackPtr) + ECount < 256) {
|
||||
|
||||
/* Calculate the true stack offset */
|
||||
@@ -1234,12 +1283,16 @@ static void StdFunc_strlen (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
||||
ED_MakeRValExpr (Expr);
|
||||
Expr->Type = type_size_t;
|
||||
|
||||
/* Bail out, no need for further processing */
|
||||
goto ExitPoint;
|
||||
}
|
||||
|
||||
/* strlen for a string that is pointed to by a register variable will only
|
||||
** get inlined if requested on the command line, since we cannot know how
|
||||
** big the buffer actually is, so inlining is not always safe.
|
||||
*/
|
||||
} else if (ED_IsLocRegister (&Arg) && ED_IsLVal (&Arg) && IsPtr &&
|
||||
IS_Get (&InlineStdFuncs)) {
|
||||
if (ED_IsLocRegister (&Arg) && ED_IsLVal (&Arg) && IsPtr &&
|
||||
IS_Get (&EagerlyInlineFuncs)) {
|
||||
|
||||
/* Generate the strlen code */
|
||||
L = GetLocalLabel ();
|
||||
@@ -1255,11 +1308,15 @@ static void StdFunc_strlen (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
||||
ED_MakeRValExpr (Expr);
|
||||
Expr->Type = type_size_t;
|
||||
|
||||
/* Bail out, no need for further processing */
|
||||
goto ExitPoint;
|
||||
}
|
||||
|
||||
/* Last check: We will inline a generic strlen routine if inlining was
|
||||
** requested on the command line, and the code size factor is more than
|
||||
** 400 (code is 13 bytes vs. 3 for a jsr call).
|
||||
*/
|
||||
} else if (IS_Get (&CodeSizeFactor) > 400 && IS_Get (&InlineStdFuncs)) {
|
||||
if (IS_Get (&CodeSizeFactor) > 400 && IS_Get (&EagerlyInlineFuncs)) {
|
||||
|
||||
/* Load the expression into the primary */
|
||||
LoadExpr (CF_NONE, &Arg);
|
||||
@@ -1280,7 +1337,10 @@ static void StdFunc_strlen (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
||||
ED_MakeRValExpr (Expr);
|
||||
Expr->Type = type_size_t;
|
||||
|
||||
} else {
|
||||
/* Bail out, no need for further processing */
|
||||
goto ExitPoint;
|
||||
}
|
||||
}
|
||||
|
||||
/* Load the expression into the primary */
|
||||
LoadExpr (CF_NONE, &Arg);
|
||||
@@ -1292,8 +1352,7 @@ static void StdFunc_strlen (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
|
||||
ED_MakeRValExpr (Expr);
|
||||
Expr->Type = type_size_t;
|
||||
|
||||
}
|
||||
|
||||
ExitPoint:
|
||||
/* We expect the closing brace */
|
||||
ConsumeRParen ();
|
||||
}
|
||||
|
Reference in New Issue
Block a user