File: hipe_sparc_cfg.erl

package info (click to toggle)
erlang 1%3A12.b.3-dfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 77,780 kB
  • ctags: 157,528
  • sloc: erlang: 664,178; ansic: 241,119; makefile: 15,725; xml: 8,378; java: 7,780; sh: 6,789; lisp: 5,396; pascal: 3,637; perl: 2,310; asm: 1,438; cpp: 975; tcl: 245; python: 21; sed: 20; awk: 15
file content (117 lines) | stat: -rw-r--r-- 3,025 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
%%% -*- erlang-indent-level: 2 -*-
%%% $Id$

-module(hipe_sparc_cfg).

-export([init/1,
         labels/1, start_label/1,
         succ/2,
         bb/2, bb_add/3]).
-export([postorder/1, reverse_postorder/1]).
-export([linearise/1]).
-export([params/1]).
-export([arity/1]). % for linear scan

-define(SPARC_CFG, true).     % needed for cfg.inc

-include("../main/hipe.hrl").
-include("hipe_sparc.hrl").
-include("../flow/cfg.hrl").
-include("../flow/cfg.inc").

%%----------------------------------------------------------------------------
%% CFG interface to SPARC
%%----------------------------------------------------------------------------

init(Defun) ->
  Code = hipe_sparc:defun_code(Defun),
  StartLab = hipe_sparc:label_label(hd(Code)),
  Data = hipe_sparc:defun_data(Defun),
  IsClosure = hipe_sparc:defun_is_closure(Defun),
  Name = hipe_sparc:defun_mfa(Defun),
  IsLeaf = hipe_sparc:defun_is_leaf(Defun),
  Formals = hipe_sparc:defun_formals(Defun),
  CFG = mk_empty_cfg(Name, StartLab, Data, IsClosure, IsLeaf, Formals),
  take_bbs(Code, CFG).

is_branch(I) ->
  case I of
    #bp{'cond'='a'} -> true;
    %% not br
    #call_tail{} -> true;
    #jmp{} -> true;
    %% not jmpl
    #pseudo_bp{} -> true; 
    %% #pseudo_br{} -> true;
    #pseudo_call{} -> true;
    #pseudo_ret{} -> true;
    #pseudo_tailcall{} -> true;
    _ -> false
  end.

branch_successors(Branch) ->
  case Branch of
    #bp{'cond'='a',label=Label} -> [Label];
    #call_tail{} -> [];
    #jmp{labels=Labels} -> Labels;
    #pseudo_bp{true_label=TrueLab,false_label=FalseLab} -> [FalseLab,TrueLab];
    %% #pseudo_br{true_label=TrueLab,false_label=FalseLab} -> [FalseLab,TrueLab];
    #pseudo_call{contlab=ContLab, sdesc=#sparc_sdesc{exnlab=ExnLab}} ->
      case ExnLab of
	[] -> [ContLab];
	_ -> [ContLab,ExnLab]
      end;
    #pseudo_ret{} -> [];
    #pseudo_tailcall{} -> []
  end.

-ifdef(REMOVE_TRIVIAL_BBS_NEEDED).
fails_to(_Instr) -> [].
-endif.

-ifdef(notdef).
redirect_jmp(I, Old, New) ->
  case I of
    #b_label{label=Label} ->
      if Old =:= Label -> I#b_label{label=New};
	 true -> I
      end;
    #pseudo_bc{true_label=TrueLab, false_label=FalseLab} ->
      I1 = if Old =:= TrueLab -> I#pseudo_bc{true_label=New};
	      true -> I
	   end,
      if Old =:= FalseLab -> I1#pseudo_bc{false_label=New};
	 true -> I1
      end;
    %% handle pseudo_call too?
    _ -> I
  end.
-endif.

mk_goto(Label) ->
  hipe_sparc:mk_b_label(Label).

is_label(I) ->
  hipe_sparc:is_label(I).

label_name(Label) ->
  hipe_sparc:label_label(Label).

mk_label(Name) ->
  hipe_sparc:mk_label(Name).

linearise(CFG) ->	% -> defun, not insn list
  MFA = function(CFG),
  Formals = params(CFG),
  Code = linearize_cfg(CFG),
  Data = data(CFG),
  VarRange = hipe_gensym:var_range(sparc),
  LabelRange = hipe_gensym:label_range(sparc),
  IsClosure = is_closure(CFG),
  IsLeaf = is_leaf(CFG),
  hipe_sparc:mk_defun(MFA, Formals, IsClosure, IsLeaf,
		      Code, Data, VarRange, LabelRange).

arity(CFG) ->
  {_M, _F, A} = function(CFG),
  A.