[fpc-pascal] -OoASMCSE
Florian Klämpfl
florian at freepascal.org
Sat Dec 31 20:25:24 CET 2011
Am 31.12.2011 20:04, schrieb Bernd:
> 2011/12/31 Jonas Maebe <jonas.maebe at elis.ugent.be>:
>
>> * compiler/i386/daopt386.pas: data flow analysis (DFA, collects information about what each register holds)
>> * compiler/i386/csopt386.pas: common subexpression elimination based on information collected by DFA
>> * compiler/i386/rropt386.pas: register renaming based on the information collected by DFA
>
>
> Ok, this is a lot of code.
> I have removed it all ;-)
>
> I'm now playing around with this, trying to understand how the data
> looks like. I have replaced the original CSE() function with the
> following:
>
> function RemoveReload(asml: TAsmList; first, last: tai; pass: longint): boolean;
> var
> p : taicpu;
> begin
> if pass > 0 then exit;
>
> writeln;
> writeln('block:');
> p := taicpu(first);
> repeat
> case p.typ of
> ait_label:
> begin
> writeln('label');
> end;
>
> ait_instruction:
> begin
> writeln(p.GetString);
> end;
> end;
>
> if p <> last then
> p := taicpu(p.Next);
> until p = last;
>
> Result := False;
> end;
>
> This does nothing (I hope), only print something to the console:
>
> Compiling i386/testus.pas
>
> block:
> label
> [sub ???,???]
> label
> [mov ???,???]
> [mov ???,???]
> [mov ???,???]
> [mov ???,???]
> [dec ???]
> label
> [inc ???]
> [movsx ???,???]
> [mov ???,???]
> [sar ???,???]
> [mov ???,???]
> [mov ???,???]
> [movsx ???,???]
> [mov ???,???]
> [sar ???,???]
> [mov ???,???]
> [mov ???,???]
> [mov ???,???]
> [mov ???,???]
> [add ???,???]
> [adc ???,???]
> [mov ???,???]
> [mov ???,???]
> label
> [cmp ???,???]
> [j ???]
> label
> label
> [mov ???,???]
> [mov ???,???]
> [mov ???,???]
> [add ???,???]
> [ret]
>
> This looks good already ;-) I can even recognize my short test program
> (the for loop, the qword addition) even with all the question marks.
> This leads me to the first question: why are there question marks? Is
> it not yet known which registers will be used at this stage of
> compilation or am I just using the wrong method to dump it to the
> console?
>
> I have the following simple algorithm in mind:
> start at the beginning of the block, one instruction after the other,
> maintain a list of instructions, its empty at the beginning.
>
> repeat
> * if i come across a mov instruction and the exact same instruction is
> in my list
> already then remove it from the code.
>
> * if there comes a label then clear the list
>
> * if an instruction changes something (register or memory) that any of
> the instructions in my list depend upon then remove the affected
> instruction from the list.
>
> next instruction
> until end of block
>
> Would something like this work already?
Basically yes.
>
> Now I need to find out the following things or how do I get them out
> of the properties of the taicpu class:
> * which registers does an instruction write to (if any)
> * which memory does it write to (if any)
> * which registers does it read from
> * which memory does it read from
Well, this is what most of the code in daopt386 already provides.
>
> and:
> how can I for debugging purposes dump the instructions to the console,
> so that its easier for me so see what I have, are there any helper
> functions?
I use typically -al to debug assembler generation
More information about the fpc-pascal
mailing list