[fpc-devel] Does FPC optimize unused parameters ?
Martin
lazarus at mfriebe.de
Wed Aug 8 16:29:10 CEST 2012
Out of curiosity. Is there an optimization like this (or is it possible?
procedure Foo(a:String; B: Integer); inline; // inline is optional
begin
// EMPTY
end;
This is a plain procedure, not a method, not overloaded, not virtual.
And the parameters are both not used in the procedure (But obviously
this might also apply for none empty, if params are not used)
somewhere else might be
Foo('hello world', 1);
or
Foo('hello world', CalcSomeInt());
At that point it could be known (especially if inlined?) that the params
are not used).
So the string constant would not be needed in the app.
If not inlined, there may still be a need to satisfy calling params ABI
or whatever... But if inlined, even the integer wasn't needed.
The CalcSomeInt may be wanted of course, for side effcts....
Of course the question is who would write such code. But actually it happens
The LazLoggerDumy unit provides empty inline-able procedures. This
allows to write all the debugln in your app without plenty of $IFDEF.
Simply change the unit From LazLogger to LazLoggerDumy and logging is gone.
Of course it would be nice if FPC could drop as much of the not required
params as possible.
More information about the fpc-devel
mailing list