1
1
%%%----------------------------------------------------------------------
2
2
%%% File : hipe_sparc_peephole.erl
3
3
%%% Author : Christoffer Vikstrom <chvi3471@student.uu.se>
4
%%% Purpose : Contain peephole optimisations for sparc-assembler code.
4
%%% Purpose : Do peephole optimisations on SPARC assembler code.
5
5
%%% Created : 16 Feb 2004 by Christoffer Vikstr�m <chvi3471@student.uu.se>
6
6
%%%----------------------------------------------------------------------
13
13
-include("hipe_sparc.hrl").
15
-define(DO_PEEP, true).
16
15
%%-define(DO_LOGGING, true). % Uncomment this to get peephole opts logged to..
17
16
-define(LOG_FILE, "peepcount.txt"). % ..this file..
18
17
-define(LOG_DIR, "/home/chvi3471/otp/tests/"). % ..in this dir
21
20
%%>----------------------------------------------------------------------<
23
% Purpose : Function that does peephole optimizations. It works by
24
% moving a window over the code and looking at a sequence of
25
% a few instructions. Replaces long sequences of instructions
26
% with shorter ones and removes unnecesary ones.
27
% Arguments : LinearCode - List of pseudo sparc-assembler records.
28
% Res - Returned list of pseudo sparc-assembler records.
29
% Kept reversed, until it is returned.
30
% Lst - List of optimizations done. For debuging.
31
% Return : An optimized list of pseudo sparc-assembler records with
32
% (hopefully) fewer or faster instructions.
33
% Notes : Creates a file in the users home directory that contain
34
% analysis information, if macro ?DO_LOGGING is defined.
22
%% Purpose : Function that does peephole optimizations. It works by
23
%% moving a window over the code and looking at a sequence of
24
%% a few instructions. Replaces long sequences of instructions
25
%% with shorter ones and removes unnecesary ones.
26
%% Arguments : LinearCode - List of pseudo sparc-assembler records.
27
%% Res - Returned list of pseudo sparc-assembler records.
28
%% Kept reversed, until it is returned.
29
%% Lst - List of optimizations done. For debuging.
30
%% Return : An optimized list of pseudo sparc-assembler records with
31
%% (hopefully) fewer or faster instructions.
32
%% Notes : Creates a file in the users home directory that contain
33
%% analysis information, if macro ?DO_LOGGING is defined.
35
34
%%>----------------------------------------------------------------------<
36
36
peep(LinearCode) ->
39
peep(LinearCode, [], []);
37
peep(LinearCode, [], []).
67
61
peep([M=#move{dst=Dst, src=SrcImm},
68
62
A=#alu{dst=Dst, src1=Dst, op=Op, src2=Src2}|Insns], Ack, Lst) ->
69
case (Op=='+') or (Op=='and') or (Op=='or') or (Op=='xor') or
70
(Op=='xnor') or (Op=='andn') of
63
case (Op =:= '+') orelse (Op =:= 'and') orelse (Op =:= 'or') orelse
64
(Op =:= 'xor') orelse (Op =:= 'xnor') orelse (Op =:= 'andn') of
72
66
case hipe_sparc:is_imm(SrcImm) of
82
76
peep([M=#move{dst=Dst, src=SrcImm},
83
77
A=#alu{dst=Dst, src1=Src1, op=Op, src2=Dst}|Insns], Ack, Lst) ->
84
case (Op=='+') or (Op=='and') or (Op=='or') or (Op=='xor') or
85
(Op=='xnor') or (Op=='andn') of
78
case (Op =:= '+') orelse (Op =:= 'and') orelse (Op =:= 'or') orelse
79
(Op =:= 'xor') orelse (Op =:= 'xnor') orelse (Op =:= 'andn') of
87
81
case hipe_sparc:is_imm(SrcImm) of
99
93
%% ElimBinALMDouble
100
94
%% ----------------
101
95
peep([M=#move{dst=Dst}, I=#alu{dst=Dst,src1=Src1,src2=Src2}|Insns],Ack,Lst) ->
102
case (Dst/=Src1) and (Dst/=Src2) of
96
case (Dst =/= Src1) andalso (Dst =/= Src2) of
104
98
peep(Insns, [I|Ack], [elimBinALMDouble|Lst]);
118
112
peep([I=#move{dst=Dst, src={sparc_imm, Val}}|Insns], Ack, Lst) ->
122
116
[#alu{dst=Dst, src1=Dst, op='xor', src2=Dst}|Ack],