On Fri, 16 Nov 2001, Frank Heckenbach wrote:
This is simply pushing the calculated index, a min and a max from the array declaration, and calling chk.
As I said, we'll do inline checks which are faster (and probably even easier). That's really not the problem.
I'd also vote for inline check instead of function call -it may not even inflate the code on some processors.
What if the loop calls any routine which might (directly or indirectly) call Halt conditionally?
So what? A halt is a halt is a halt.
If the analysis finds that a `for' loop has an "inevitable" range error, but `Halt' is called before it, the error is not that inevitable.
Then compiler should decide that it cannot determine that it's an "inevitable" range error and should generate inline code to check each array indexing.
If an integer expression is simple enough, compile time min-max analisys can be performed, if all inputs to the expression are traceable to some values in determinable range (sort of value flow analisys).
Or to make it simple: if the range of expression is determinable at compile time, range checking can be put at the beginning of "expensive" loop. If it can be determined at runtime before entering "expensive" part of program, then do range-checking analysis before entering it, and enter "fast" version of compiled routine. If it can't tell for sure, enter "slow" version of compiled routine with inline range-checking.
At compile time heuristics determine whether routine fits the criteria for making two versions of it and doing sort of "run-time smart virtual range-checking and linking" (:-) at least it sounds good).
But, then again, it's PHASE 3. First comes PHASE1, to introduce solid range-checking and make it work. Optimizations probably come as PHASE 2, and proposed "dynamic routine version choosing" last.
Maybe it belongs in optimizer to do it, so it may be out of the scope of GPC and fit into backend? Maybe a lot of this ideas of pre-loop range checking could be done by LSR (lop strength reduction) and CSE (common subexpression elimination) passes of optimizer.
My pseudo code probably looks nothing like yours, I am not familiar with GCCs intermediate forms, which I believe are designed for optimization analysis. So I am limiting myself to prodding, having been there in the past.
You don't have to know about the intermediate forms ("tree nodes" and "rtl"). Just describing things in terms of Pascal (or C) code should be enough -- we can translate it into tree nodes then.
Is there a way to generate text file with this rtl intermediate representation, to see what's going on? Maybe it could be clearer to read than assembler(s)?
mirsad
-- This message has been made up using recycled ideas and language constructs. No plant or animal has been injured in process of making this message.