Przemyslaw Czerpak wrote:
It looks very nice. Can youy add it to compiler?
In such case we can make two things:
1. we can extract local file name (hb_compLocalVariableName())
2. we can activate this analyse phase before HB_P_NOOP optimization
and strip unnecessary code by filing it with NOOP pcodes.
I've not implemented noop'ing of unused assignment yet. Only warning
implemented. I find it a good solution. Warning is -w3 level, so, it
will popup for many developers, since it is default level.
I think we need a test time for this recursive pcode tree tracing code.
Developers will report wrong warnings (if they exists), but wrong
noop'ing will make compiler very unstable.
We can try implement nooping later. It will optimize some
nI := 0
but will not help a lot for not useful assignment:
nI := LEN(aaI[5])
and
nI := ASCAN(aI, {|x| x[3] == cSomething})
I see developer code fixing a good problem solution. Warning level could
be reduced to -w2, like 'variable declared but not used', to force
developers more find possible bugs and optimize .prg code.
It was nice to run it on my code and also on Harbour core (not contribs)
.prg files. Results are below. There are two standard warnings:
1) "CLASS ..." generates "nScope := 1", but if programmer provides scope
for first defined data, this "nScope := 1" is redundant.
Yes it is but it's hard to detect it and create workaround using PP only.
I've renamed this var to _nowarn_nScope and optimizer does not
genereates warninig for such prefixed variables. Solution a little
hackish, but I can't find quickly a good solution. Perhaps, some
pseudo-function like HB_SYMBOL_UNUSED() could be a solution. But this
funtion should not be changed by preprocessor. It should "survive" to
pcode optimizer. Pcode optimizer will strip it, but will not generate
warning.
2) "METHOD ... CLASS ..." generates "LOCAL Self := QSELF()". If "Self"
is unused, this assignment and local variable are redundant. Do not
forget to count this local when counting locals of methods!
It's yet another problem. Here we even have additional place for
optimization. We can eliminate local variable self and use HB_P_PUSHSELF
what should be a little bit faster and will need less PCODE bytes.
The only one problem is detecting that Self local variable is not used
inside codeblocks and detached. Because now compiler generate code
"on line" then we cannot easy implement it in compiler. But it should
possible to add such optimization to your code. It will be enough to
check if variable is not used by reference, inside codeblocks or
assigned (POP). If it's used only as readonly and assigned by popping
HB_P_PUSHSELF then we can replace all HB_P_PUSHLOCAL[NEAR] <n> wit
HB_P_PUSHSELF and reduce number of local variables. If we reduce all then
we can eliminate HB_P_[LARGE][V]FRAME.
Done. There are some restrictions (in my code) on this optimisation but
it will work, if Self := QELSF() is done before first branching
instruction. So, it will work for:
METHOD ... CLASS ...
HB_P_FRAME is eliminated by some hbmain.c code. I think it will be
easier to do it in hb_compOptimizePCode() by striping HB_P_FRAME 0,0,
instead of memmove() of whole pcode, but I didn't tried to move this
code. It could be done intentionally this way.
Very nice job. I would like to ask to integrate it with compiler.
If you will need any help then I'll do what I can.
We can add new -k? switch which will enable such optimization or
make it part of -kJ. The problem can be only with warnings. They
should be optional. Now we can use -w4 but sooner or later we will
need sth to enable/disable different compiler warnings for some
extensions which are not valid for each Clipper code. I'll think
about it.
Warning generation is put under -w3. Self := QSELF() optimisation and
'declared but unused code' optimisation is done if jump optimisation
enabled.
After new warnings appeared not all code compiles. I've fixed core code
except:
utils/hbdoc/* - many unused assignment and variables
utils/hbmake.prg - many unused assignment and variables
these are marked with #pragma -w2.
I've not touched contribs, I hope authors can help to fix it, because
sometimes in case of 'variable assigned but unused' we should not delete
assignment, but fix hidden bug.
Some files compiles with a few output format switches, ex., -gc3 -gc0:
bin\b32\harbour.exe -n -iinclude -q0 -w3 -es2 -km -gc3 -gc0
-oobj\b32\ utils\hbmake\hbmake.prg
May be it is OK, but I want to say it, because it can hide some bug in
make files.
I've also noticed, gencc.c is under pure GPL license, but I know you
support idea of more free license. You are the only author of this
file and I guess you can change licenses text if you want.
Best regards,
Mindaugas
_______________________________________________
Harbour mailing list
[email protected]
http://lists.harbour-project.org/mailman/listinfo/harbour