Hi Mindaugas, Sorry for late response but I still haven't received any messages from Harbour-devel list so I'm coping them from Harbour mail list archive. Phil - I really need your help.
> I've just finished to implement a "test" program for PCode analysis. It > is capable to test PCode for correct structure (e.g., there is no jumps > into string content) and also to find assigned but unused local variables. > I've implemented it as independent code. It reads and analyses .hrb > files, but "assigned but unused" detection can be included into > compiler. The problem is that on PCode analysis stage local names are > unknown, so, you'll see "Local 1" instead of "nCount". Offsets are PCode > offsets from start of the function, I've also included line numbers, but > I'm not sure it is always correct (not tested). 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. If we can eliminate all local variables then we can also eliminate local variable frame. > 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. > 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. > Also forcing garbage collection by "oBigObject := NIL" can force > warning. The rest warnings was real and I've fixed it in my code. If possible please commit it. > I'm also happy to find a tiny dead pcode, see __DBGACHOICE. This is not real deadcode. In dead code eliminator inside compiler I intentionally do not strip the last HB_P_ENDPROC. See harbour compiler/hbdead.c[591]. If you remove this if() statement then it will be stripped. It left the last HB_P_ENDBLOCK/HB_P_ENDPROC for some historical reasons and code which needed it but probably I've already cleaned all such code. Your PCODE analyzer detected such dummy HB_P_ENDPROC PCODE at the end of function body. > If someone want to try on your own .prg (compile it to .hrb), you can > find download on http://www.dbtopas.lt/hrb/pcoder.zip 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. best regards, Przemek _______________________________________________ Harbour mailing list [email protected] http://lists.harbour-project.org/mailman/listinfo/harbour
