~rdoering/ubuntu/intrepid/erlang/fix-535090

« back to all changes in this revision

Viewing changes to lib/hipe/sparc/hipe_sparc_peephole.erl

  • Committer: Bazaar Package Importer
  • Author(s): Soren Hansen
  • Date: 2007-05-01 16:57:10 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20070501165710-2sapk0hp2gf3o0ip
Tags: 1:11.b.4-2ubuntu1
* Merge with Debian Unstable. Remaining changes:
  - Add -fno-stack-protector to fix broken crypto_drv.
* DebianMaintainerField update.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
%%%----------------------------------------------------------------------
7
7
 
12
12
 
13
13
-include("hipe_sparc.hrl").
14
14
 
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
19
18
 
20
19
 
21
20
%%>----------------------------------------------------------------------<
22
 
%  Procedure : peep/1
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.
 
21
%% Procedure : peep/1
 
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
%%>----------------------------------------------------------------------<
 
35
 
36
36
peep(LinearCode) -> 
37
 
    case ?DO_PEEP of
38
 
        true ->
39
 
            peep(LinearCode, [], []);
40
 
        _ ->
41
 
            LinearCode
42
 
    end.
43
 
 
 
37
    peep(LinearCode, [], []).
44
38
 
45
39
%% MoveSelfSimple
46
40
%% --------------
66
60
%% --------------
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
71
65
        true -> 
72
66
            case hipe_sparc:is_imm(SrcImm) of
73
67
                true ->
81
75
    end;
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
86
80
        true -> 
87
81
            case hipe_sparc:is_imm(SrcImm) of
88
82
                true ->
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
103
97
        true ->
104
98
            peep(Insns, [I|Ack], [elimBinALMDouble|Lst]);
105
99
        false ->
116
110
%% ElimSet0
117
111
%% --------
118
112
peep([I=#move{dst=Dst, src={sparc_imm, Val}}|Insns], Ack, Lst) ->
119
 
    case (Val==0) of
 
113
    case (Val =:= 0) of
120
114
        true ->
121
115
            peep(Insns, 
122
116
                 [#alu{dst=Dst, src1=Dst, op='xor', src2=Dst}|Ack], 
189
183
%% -------------
190
184
%% Used by ElimMDPow2 clause of peep(..)
191
185
log2(Nr) -> log2(Nr, 0).
192
 
log2(0, _) -> {false, 0, positive};
 
186
 
 
187
log2(0, _) ->
 
188
    {false, 0, positive};
193
189
log2(Nr, I) ->
194
190
    case (Nr band 1) =:= 1 of
195
191
        false ->