1
%%% -*- erlang-indent-level: 2 -*-
7
labels/1, start_label/1,
10
-export([postorder/1]).
11
-export([linearise/1]).
12
-export([params/1, reverse_postorder/1]).
13
-export([arity/1]). % for linear scan
14
%%-export([redirect_jmp/3]).
16
%%% these tell cfg.inc what to define (ugly as hell)
17
-define(BREADTH_ORDER,true). % for linear scan
18
-define(PARAMS_NEEDED,true).
19
-define(START_LABEL_UPDATE_NEEDED,true).
20
-include("../flow/cfg.inc").
21
-include("hipe_arm.hrl").
24
Code = hipe_arm:defun_code(Defun),
25
StartLab = hipe_arm:label_label(hd(Code)),
26
Data = hipe_arm:defun_data(Defun),
27
IsClosure = hipe_arm:defun_is_closure(Defun),
28
Name = hipe_arm:defun_mfa(Defun),
29
IsLeaf = hipe_arm:defun_is_leaf(Defun),
30
Formals = hipe_arm:defun_formals(Defun),
32
CFG0 = mk_empty_cfg(Name, StartLab, Data,
33
IsClosure, IsLeaf, Formals, Extra),
39
#b_label{'cond'='al'} -> true;
41
#pseudo_blr{} -> true;
43
#pseudo_call{} -> true;
44
#pseudo_switch{} -> true;
45
#pseudo_tailcall{} -> true;
49
branch_successors(Branch) ->
52
#b_label{'cond'='al',label=Label} -> [Label];
53
#pseudo_bc{true_label=TrueLab,false_label=FalseLab} -> [FalseLab,TrueLab];
56
#pseudo_call{contlab=ContLab, sdesc=#arm_sdesc{exnlab=ExnLab}} ->
61
#pseudo_switch{labels=Labels} -> Labels;
62
#pseudo_tailcall{} -> []
65
-ifdef(REMOVE_TRIVIAL_BBS_NEEDED).
66
fails_to(_Instr) -> [].
70
redirect_jmp(I, Old, New) ->
72
#b_label{label=Label} ->
73
if Old =:= Label -> I#b_label{label=New};
76
#pseudo_bc{true_label=TrueLab, false_label=FalseLab} ->
77
I1 = if Old =:= TrueLab -> I#pseudo_bc{true_label=New};
80
if Old =:= FalseLab -> I1#pseudo_bc{false_label=New};
83
%% handle pseudo_call too?
89
hipe_arm:mk_b_label(Label).
95
hipe_arm:label_label(Label).
98
hipe_arm:mk_label(Name).
100
linearise(CFG) -> % -> defun, not insn list
102
Formals = params(CFG),
103
Code = linearize_cfg(CFG),
105
VarRange = hipe_gensym:var_range(arm),
106
LabelRange = hipe_gensym:label_range(arm),
107
IsClosure = is_closure(CFG),
108
IsLeaf = is_leaf(CFG),
109
hipe_arm:mk_defun(Fun, Formals, IsClosure, IsLeaf,
110
Code, Data, VarRange, LabelRange).
113
#arm_mfa{a=Arity} = function(CFG),