31
31
%%----------------------------------------------------------------------
33
-type(io_device() :: any()). % XXX: DOES NOT BELONG HERE
33
-type io_device() :: any(). % XXX: DOES NOT BELONG HERE
35
35
%%----------------------------------------------------------------------
36
36
%% Prototypes for exported functions which are Icode specific
37
37
%%----------------------------------------------------------------------
39
-spec(labels/1 :: (#cfg{}) -> [icode_lbl()]).
40
-spec(postorder/1 :: (#cfg{}) -> [icode_lbl()]).
41
-spec(reverse_postorder/1 :: (#cfg{}) -> [icode_lbl()]).
43
-spec(is_visited/2 :: (icode_lbl(), gb_tree()) -> bool()).
44
-spec(visit/2 :: (icode_lbl(), gb_tree()) -> gb_tree()).
46
-spec(bb/2 :: (#cfg{}, icode_lbl()) -> 'not_found' | bb()).
47
-spec(bb_add/3 :: (#cfg{}, icode_lbl(), bb()) -> #cfg{}).
48
-spec(pred/2 :: (#cfg{}, icode_lbl()) -> [icode_lbl()]).
49
-spec(succ/2 :: (#cfg{}, icode_lbl()) -> [icode_lbl()]).
50
-spec(redirect/4 :: (#cfg{}, icode_lbl(), icode_lbl(), icode_lbl()) -> #cfg{}).
39
-spec labels(#cfg{}) -> [icode_lbl()].
40
-spec postorder(#cfg{}) -> [icode_lbl()].
41
-spec reverse_postorder(#cfg{}) -> [icode_lbl()].
43
-spec is_visited(icode_lbl(), gb_tree()) -> bool().
44
-spec visit(icode_lbl(), gb_tree()) -> gb_tree().
46
-spec bb(#cfg{}, icode_lbl()) -> 'not_found' | bb().
47
-spec bb_add(#cfg{}, icode_lbl(), bb()) -> #cfg{}.
48
-spec pred(#cfg{}, icode_lbl()) -> [icode_lbl()].
49
-spec succ(#cfg{}, icode_lbl()) -> [icode_lbl()].
50
-spec redirect(#cfg{}, icode_lbl(), icode_lbl(), icode_lbl()) -> #cfg{}.
52
52
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54
54
%% Interface to Icode
57
-spec(linear_to_cfg/1 :: (#icode{}) -> #cfg{}).
57
-spec linear_to_cfg(#icode{}) -> #cfg{}.
58
59
linear_to_cfg(LinearIcode) ->
59
60
%% hipe_icode_pp:pp(Icode),
60
61
Code = hipe_icode:icode_code(LinearIcode),
84
85
%% remove_blocks(CFG, [Lbl|Lbls]) ->
85
86
%% remove_blocks(bb_remove(CFG, Lbl), Lbls).
87
-spec(is_label/1 :: (icode_instr()) -> bool()).
88
-spec is_label(icode_instr()) -> bool().
89
90
hipe_icode:is_label(Instr).
104
105
hipe_icode:fails_to(Instr).
106
107
%% True if instr has no effect.
107
-spec(is_comment/1 :: (icode_instr()) -> bool()).
108
-spec is_comment(icode_instr()) -> bool().
108
109
is_comment(Instr) ->
109
110
hipe_icode:is_comment(Instr).
111
112
%% True if instr is just a jump (no side-effects).
112
-spec(is_goto/1 :: (icode_instr()) -> bool()).
113
-spec is_goto(icode_instr()) -> bool().
113
114
is_goto(Instr) ->
114
115
hipe_icode:is_goto(Instr).
116
-spec(is_branch/1 :: (icode_instr()) -> bool()).
117
-spec is_branch(icode_instr()) -> bool().
117
118
is_branch(Instr) ->
118
119
hipe_icode:is_branch(Instr).
120
-spec(is_pure_branch/1 :: (icode_instr()) -> bool()).
121
-spec is_pure_branch(icode_instr()) -> bool().
121
122
is_pure_branch(Instr) ->
123
124
#icode_if{} -> true;
158
159
%%----------------------------------------------------------------------------
160
-spec(pp/1 :: (#cfg{}) -> 'ok').
161
-spec pp(#cfg{}) -> 'ok'.
162
164
hipe_icode_pp:pp(cfg_to_linear(CFG)).
164
-spec(pp/2 :: (io_device(), #cfg{}) -> 'ok').
166
-spec pp(io_device(), #cfg{}) -> 'ok'.
166
169
hipe_icode_pp:pp(Dev, cfg_to_linear(CFG)).
168
171
%%----------------------------------------------------------------------------
170
-spec(cfg_to_linear/1 :: (#cfg{}) -> #icode{}).
173
-spec cfg_to_linear(#cfg{}) -> #icode{}.
171
174
cfg_to_linear(CFG) ->
172
175
Code = linearize_cfg(CFG),
173
176
IsClosure = is_closure(CFG),