Skip to content

Commit

Permalink
Merge branch 'ks/hipe-patches' into dev
Browse files Browse the repository at this point in the history
* ks/hipe-patches:
  hipe: Update types and specs
  • Loading branch information
bjorng committed Nov 22, 2010
2 parents f555bf5 + 6083a1a commit 4819bd3
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 68 deletions.
6 changes: 2 additions & 4 deletions lib/hipe/icode/hipe_icode_callgraph.erl
Expand Up @@ -25,8 +25,6 @@
%% in hipe_icode_type.erl.
%%
%% Created : 7 Jun 2004 by Tobias Lindahl <tobiasl@it.uu.se>
%%
%% $Id$
%%-----------------------------------------------------------------------
-module(hipe_icode_callgraph).

Expand All @@ -48,7 +46,7 @@

-type mfa_icode() :: {mfa(), #icode{}}.

-record(icode_callgraph, {codedict :: dict(), ordered_sccs :: [[atom()]]}).
-record(icode_callgraph, {codedict :: dict(), ordered_sccs :: [[mfa()]]}).

%%------------------------------------------------------------------------
%% Exported functions
Expand Down Expand Up @@ -78,7 +76,7 @@ construct_callgraph(List) ->

to_list(#icode_callgraph{codedict = Dict, ordered_sccs = SCCs}) ->
FlatList = lists:flatten(SCCs),
[{Mod, dict:fetch(Mod, Dict)} || Mod <- FlatList].
[{MFA, dict:fetch(MFA, Dict)} || MFA <- FlatList].

%%------------------------------------------------------------------------

Expand Down
4 changes: 2 additions & 2 deletions lib/hipe/icode/hipe_icode_range.erl
Expand Up @@ -843,7 +843,7 @@ compare_with_integer(N, OldVarRange) ->

%%== Ranges ==================================================================

-spec pp_ann(#ann{} | erl_types:erl_type()) -> [string()].
-spec pp_ann(#ann{} | erl_types:erl_type()) -> string().

pp_ann(#ann{range=#range{range=R, other=false}}) ->
pp_range(R);
Expand Down Expand Up @@ -1365,7 +1365,7 @@ range_bnot(Range) ->
Minus_one = range_init({-1,-1}, false),
range_add(range_mult(Range, Minus_one), Minus_one).

-spec width(range_rep() | integer()) -> 'pos_inf' | non_neg_integer().
-spec width(range_rep() | inf_integer()) -> 'pos_inf' | non_neg_integer().

width({Min, Max}) -> inf_max([width(Min), width(Max)]);
width(pos_inf) -> pos_inf;
Expand Down
27 changes: 17 additions & 10 deletions lib/hipe/main/hipe.erl
@@ -1,20 +1,20 @@
%% -*- erlang-indent-level: 2 -*-
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 2001-2009. All Rights Reserved.
%%
%%
%% Copyright Ericsson AB 2001-2010. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
%% compliance with the License. You should have received a copy of the
%% Erlang Public License along with this software. If not, it can be
%% retrieved online at http://www.erlang.org/.
%%
%%
%% Software distributed under the License is distributed on an "AS IS"
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
%% the License for the specific language governing rights and limitations
%% under the License.
%%
%%
%% %CopyrightEnd%
%%
%% ====================================================================
Expand All @@ -25,7 +25,6 @@
%% Purpose :
%% Notes :
%% History : * 1998-01-28 Erik Johansson (happi@it.uu.se): Created.
%% CVS : $Id$
%% ====================================================================
%% @doc This is the direct interface to the HiPE compiler.
%%
Expand Down Expand Up @@ -506,7 +505,7 @@ compile(Name, File, Opts0) ->
run_compiler(Name, DisasmFun, IcodeFun, NewOpts)
end.

-spec compile_core(mod(), _, compile_file(), comp_options()) ->
-spec compile_core(mod(), cerl:c_module(), compile_file(), comp_options()) ->
{'ok', compile_ret()} | {'error', term()}.

compile_core(Name, Core0, File, Opts) ->
Expand Down Expand Up @@ -535,7 +534,7 @@ compile_core(Name, Core0, File, Opts) ->
%%
%% @see compile/3

-spec compile(mod(), _, compile_file(), comp_options()) ->
-spec compile(mod(), cerl:c_module() | [], compile_file(), comp_options()) ->
{'ok', compile_ret()} | {'error', term()}.

compile(Name, [], File, Opts) ->
Expand Down Expand Up @@ -790,7 +789,7 @@ finalize_fun(MfaIcodeList, Exports, Opts) ->
FalseVal when (FalseVal =:= undefined) orelse (FalseVal =:= false) ->
[finalize_fun_sequential(MFAIcode, Opts, #comp_servers{})
|| {_MFA, _Icode} = MFAIcode <- MfaIcodeList];
TrueVal when (TrueVal =:= true) or (TrueVal =:= debug) ->
TrueVal when (TrueVal =:= true) orelse (TrueVal =:= debug) ->
finalize_fun_concurrent(MfaIcodeList, Exports, Opts)
end.

Expand Down Expand Up @@ -939,6 +938,8 @@ assemble(CompiledCode, Closures, Exports, Options) ->
hipe_sparc_assemble:assemble(CompiledCode, Closures, Exports, Options);
powerpc ->
hipe_ppc_assemble:assemble(CompiledCode, Closures, Exports, Options);
ppc64 ->
hipe_ppc_assemble:assemble(CompiledCode, Closures, Exports, Options);
arm ->
hipe_arm_assemble:assemble(CompiledCode, Closures, Exports, Options);
x86 ->
Expand Down Expand Up @@ -1048,7 +1049,7 @@ post(Res, Icode, Options) ->
%% --------------------------------------------------------------------

%% @doc Returns the current HiPE version as a string().
-spec version() -> string().
-spec version() -> nonempty_string().

version() ->
?VERSION_STRING().
Expand Down Expand Up @@ -1390,6 +1391,8 @@ o1_opts() ->
Common;
powerpc ->
Common;
ppc64 ->
Common;
arm ->
Common -- [inline_fp]; % Pointless optimising for absent hardware
x86 ->
Expand All @@ -1411,6 +1414,8 @@ o2_opts() ->
Common;
powerpc ->
Common;
ppc64 ->
Common;
arm ->
Common;
x86 ->
Expand All @@ -1429,6 +1434,8 @@ o3_opts() ->
Common;
powerpc ->
Common;
ppc64 ->
Common;
arm ->
Common;
x86 ->
Expand Down
12 changes: 6 additions & 6 deletions lib/hipe/main/hipe_main.erl
@@ -1,20 +1,20 @@
%% -*- erlang-indent-level: 2 -*-
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 2001-2009. All Rights Reserved.
%%
%%
%% Copyright Ericsson AB 2001-2010. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
%% compliance with the License. You should have received a copy of the
%% Erlang Public License along with this software. If not, it can be
%% retrieved online at http://www.erlang.org/.
%%
%%
%% Software distributed under the License is distributed on an "AS IS"
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
%% the License for the specific language governing rights and limitations
%% under the License.
%%
%%
%% %CopyrightEnd%
%%
%% @doc This is the HiPE compiler's main "loop".
Expand Down Expand Up @@ -102,7 +102,7 @@ compile_icode(MFA, LinearIcode0, Options, Servers, DebugState) ->
?opt_start_timer("Icode"),
LinearIcode1 = icode_no_comment(LinearIcode0, Options),
IcodeCfg0 = icode_linear_to_cfg(LinearIcode1, Options),
%%hipe_icode_cfg:pp(IcodeCfg1),
%% hipe_icode_cfg:pp(IcodeCfg0),
IcodeCfg1 = icode_handle_exceptions(IcodeCfg0, MFA, Options),
IcodeCfg3 = icode_inline_bifs(IcodeCfg1, Options),
pp(IcodeCfg3, MFA, icode, pp_icode, Options, Servers),
Expand Down
5 changes: 5 additions & 0 deletions lib/hipe/rtl/hipe_rtl.erl
Expand Up @@ -354,6 +354,8 @@
phi_arglist_update/2,
phi_redirect_pred/3]).

-export_type([alub_cond/0]).

%%
%% RTL
%%
Expand Down Expand Up @@ -590,6 +592,9 @@ branch_pred(#branch{p=P}) -> P.
%% alub
%%

-type alub_cond() :: 'eq' | 'ne' | 'ge' | 'geu' | 'gt' | 'gtu' | 'le'
| 'leu' | 'lt' | 'ltu' | 'overflow' | 'not_overflow'.

mk_alub(Dst, Src1, Op, Src2, Cond, True, False) ->
mk_alub(Dst, Src1, Op, Src2, Cond, True, False, 0.5).
mk_alub(Dst, Src1, Op, Src2, Cond, True, False, P) ->
Expand Down
7 changes: 3 additions & 4 deletions lib/hipe/rtl/hipe_rtl_arith.inc
Expand Up @@ -119,7 +119,8 @@ eval_alu(Op, Arg1, Arg2) ->
%% there are cases where we can evaluate a subset of the bits, but can
%% not do a full eval-alub call (eg. a + 0 gives no carry)
%%
-spec eval_cond_bits(atom(), boolean(), boolean(), boolean(), boolean()) -> boolean().
-spec eval_cond_bits(hipe_rtl:alub_cond(), boolean(),
boolean(), boolean(), boolean()) -> boolean().

eval_cond_bits(Cond, N, Z, V, C) ->
case Cond of
Expand All @@ -146,9 +147,7 @@ eval_cond_bits(Cond, N, Z, V, C) ->
'overflow' ->
V;
'not_overflow' ->
not V;
_ ->
?EXIT({'condition code not handled',Cond})
not V
end.

eval_alub(Op, Cond, Arg1, Arg2) ->
Expand Down
43 changes: 21 additions & 22 deletions lib/hipe/rtl/hipe_rtl_ssa_const_prop.erl
Expand Up @@ -93,8 +93,6 @@
-include("../ssa/hipe_ssa_const_prop.inc").

-type bool_lattice() :: 'true' | 'false' | 'top' | 'bottom'.
-type conditional() :: 'eq' | 'ne' | 'ge' | 'geu' | 'gt' | 'gtu' | 'le'
| 'leu' | 'lt' | 'ltu' | 'overflow' | 'not_overflow'.

%%-----------------------------------------------------------------------------
%% Procedure : visit_expression/2
Expand Down Expand Up @@ -400,7 +398,7 @@ maybe_top_or_bottom([top | Rest], _) -> maybe_top_or_bottom(Rest, top);
maybe_top_or_bottom([bottom | _], _) -> bottom;
maybe_top_or_bottom([_ | Rest], TB) -> maybe_top_or_bottom(Rest, TB).

-spec partial_eval_branch(conditional(), bool_lattice(), bool_lattice(),
-spec partial_eval_branch(hipe_rtl:alub_cond(), bool_lattice(), bool_lattice(),
bool_lattice() | 0, bool_lattice() | 0) ->
bool_lattice().
partial_eval_branch(Cond, N0, Z0, V0, C0) ->
Expand Down Expand Up @@ -441,14 +439,14 @@ visit_alub(Inst, Env) ->
hipe_rtl:alub_false_label(Inst)];
top -> [];
_ ->
%if the partial branch cannot be evaluated we must execute the
% instruction at runtime.
%% if the partial branch cannot be evaluated we must execute the
%% instruction at runtime.
case partial_eval_branch(hipe_rtl:alub_cond(Inst), N, Z, C, V) of
bottom -> [hipe_rtl:alub_true_label(Inst),
hipe_rtl:alub_false_label(Inst)];
top -> [];
true -> [hipe_rtl:alub_true_label(Inst) ];
false -> [hipe_rtl:alub_false_label(Inst) ]
true -> [hipe_rtl:alub_true_label(Inst)];
false -> [hipe_rtl:alub_false_label(Inst)]
end
end,
{[], NewSSA, NewEnv} = set_to(hipe_rtl:alub_dst(Inst), NewVal, Env),
Expand Down Expand Up @@ -944,8 +942,8 @@ update_branch(Inst, Env) ->

%% some small helpers.
alub_to_move(Inst, Res, Lab) ->
[ hipe_rtl:mk_move(hipe_rtl:alub_dst(Inst), Res),
hipe_rtl:mk_goto(Lab) ].
[hipe_rtl:mk_move(hipe_rtl:alub_dst(Inst), Res),
hipe_rtl:mk_goto(Lab)].

make_alub_subst_list(bottom, _, Tail) -> Tail;
make_alub_subst_list(top, Src, _) ->
Expand All @@ -970,13 +968,13 @@ update_alub(Inst, Env) ->
%% move and the branch. We can however replace variable with constants:
S1 = make_alub_subst_list(Val1, Src1, []),
S2 = make_alub_subst_list(Val2, Src2, S1),
[ hipe_rtl:subst_uses(S2, Inst) ];
_ -> % we know where we will be going, let's find out what Dst should be.
% knowing where we are going means that at most one of the values is
% bottom, hence we can replace the alu-instr with a move.
% remember, a = b + 0 can give us enough info to know what jump to
% do without knowing the value of a. (I wonder if this will ever
% actualy happen ;)
[hipe_rtl:subst_uses(S2, Inst)];
_ -> %% we know where we will be going, let's find out what Dst should be.
%% knowing where we are going means that at most one of the values is
%% bottom, hence we can replace the alu-instr with a move.
%% remember, a = b + 0 can give us enough info to know what jump to
%% do without knowing the value of a. (I wonder if this will ever
%% actualy happen ;)
Res = case ResVal of
bottom -> % something nonconstant.
if (Val1 =:= bottom) -> Src1;
Expand All @@ -985,11 +983,12 @@ update_alub(Inst, Env) ->
_ -> hipe_rtl:mk_imm(ResVal)
end,
case CondRes of
top -> io:format("oops. something VERY bad: ~w ~w V1 & 2 ~w ~w\n",
[Inst, {ResVal, N, Z, C, V} , Val1, Val2]),
[Inst ];
true -> alub_to_move(Inst, Res, hipe_rtl:alub_true_label(Inst));
false -> alub_to_move(Inst, Res, hipe_rtl:alub_false_label(Inst))
top ->
io:format("oops. something VERY bad: ~w ~w V1 & 2 ~w ~w\n",
[Inst, {ResVal, N, Z, C, V} , Val1, Val2]),
[Inst];
true -> alub_to_move(Inst, Res, hipe_rtl:alub_true_label(Inst));
false -> alub_to_move(Inst, Res, hipe_rtl:alub_false_label(Inst))
end
end.

Expand Down Expand Up @@ -1050,7 +1049,7 @@ update_phi(Instruction, Environment) ->

%%-----------------------------------------------------------------------------

%% make sure that all precoloured rgisters are taken out of the equation.
%% make sure that all precoloured registers are taken out of the equation.
lookup_lattice_value(X, Environment) ->
case hipe_rtl_arch:is_precoloured(X) or hipe_rtl:is_const_label(X) of
true ->
Expand Down

0 comments on commit 4819bd3

Please sign in to comment.