aboutsummaryrefslogtreecommitdiffstats
path: root/lib/hipe/llvm/hipe_llvm.erl
diff options
context:
space:
mode:
authorMagnus Lång <[email protected]>2016-05-04 15:15:31 +0200
committerMagnus Lång <[email protected]>2016-05-04 17:53:36 +0200
commit3d9b2a2b4ad7f24b7297fe2133ac65dafd297f87 (patch)
tree9c8b1f14b84f7ccfff1f36c54b7c521587dd7371 /lib/hipe/llvm/hipe_llvm.erl
parent6a1290f534164d1a5771dba37c23124652b9f7c9 (diff)
downloadotp-3d9b2a2b4ad7f24b7297fe2133ac65dafd297f87.tar.gz
otp-3d9b2a2b4ad7f24b7297fe2133ac65dafd297f87.tar.bz2
otp-3d9b2a2b4ad7f24b7297fe2133ac65dafd297f87.zip
hipe_llvm: Syntax compatibility with 3.7-3.8
Diffstat (limited to 'lib/hipe/llvm/hipe_llvm.erl')
-rw-r--r--lib/hipe/llvm/hipe_llvm.erl49
1 files changed, 36 insertions, 13 deletions
diff --git a/lib/hipe/llvm/hipe_llvm.erl b/lib/hipe/llvm/hipe_llvm.erl
index 5e33731a2b..b2997f2d92 100644
--- a/lib/hipe/llvm/hipe_llvm.erl
+++ b/lib/hipe/llvm/hipe_llvm.erl
@@ -234,7 +234,7 @@
function_arg_type_list/1
]).
--export([pp_ins_list/2, pp_ins/2]).
+-export([pp_ins_list/3, pp_ins/3]).
%%-----------------------------------------------------------------------------
@@ -765,13 +765,17 @@ function_arg_type_list(#llvm_fun{arg_type_list=Arg_type_list}) ->
%% Pretty-printer Functions
%%----------------------------------------------------------------------------
-%% @doc Pretty-print a list of LLVM instructions to a Device.
-pp_ins_list(_Dev, []) -> ok;
-pp_ins_list(Dev, [I|Is]) ->
- pp_ins(Dev, I),
- pp_ins_list(Dev, Is).
+-type llvm_version() :: {Major :: integer(), Minor :: integer()}.
-pp_ins(Dev, I) ->
+%% @doc Pretty-print a list of LLVM instructions to a Device, using syntax
+%% compatible with LLVM v. Major.Minor
+-spec pp_ins_list(file:io_device(), llvm_version(), [llvm_instr()]) -> ok.
+pp_ins_list(_Dev, _Ver, []) -> ok;
+pp_ins_list(Dev, Ver={_,_}, [I|Is]) ->
+ pp_ins(Dev, Ver, I),
+ pp_ins_list(Dev, Ver, Is).
+
+pp_ins(Dev, Ver, I) ->
case indent(I) of
true -> write(Dev, " ");
false -> ok
@@ -861,6 +865,10 @@ pp_ins(Dev, I) ->
true -> write(Dev, "volatile ");
false -> ok
end,
+ case Ver >= {3,7} of false -> ok; true ->
+ pp_type(Dev, pointer_type(load_p_type(I))),
+ write(Dev, ", ")
+ end,
pp_type(Dev, load_p_type(I)),
write(Dev, [" ", load_pointer(I), " "]),
case load_alignment(I) of
@@ -897,6 +905,10 @@ pp_ins(Dev, I) ->
true -> write(Dev, "inbounds ");
false -> ok
end,
+ case Ver >= {3,7} of false -> ok; true ->
+ pp_type(Dev, pointer_type(getelementptr_p_type(I))),
+ write(Dev, ", ")
+ end,
pp_type(Dev, getelementptr_p_type(I)),
write(Dev, [" ", getelementptr_value(I)]),
pp_typed_idxs(Dev, getelementptr_typed_idxs(I)),
@@ -958,12 +970,16 @@ pp_ins(Dev, I) ->
pp_args(Dev, fun_def_arglist(I)),
write(Dev, ") "),
pp_options(Dev, fun_def_fn_attrs(I)),
+ case Ver >= {3,7} of false -> ok; true ->
+ write(Dev, "personality i32 (i32, i64, i8*,i8*)* "
+ "@__gcc_personality_v0 ")
+ end,
case fun_def_align(I) of
[] -> ok;
N -> write(Dev, ["align ", N])
end,
write(Dev, "{\n"),
- pp_ins_list(Dev, fun_def_body(I)),
+ pp_ins_list(Dev, Ver, fun_def_body(I)),
write(Dev, "}\n");
#llvm_fun_decl{} ->
write(Dev, "declare "),
@@ -992,8 +1008,12 @@ pp_ins(Dev, I) ->
pp_type(Dev, const_decl_type(I)),
write(Dev, [" ", const_decl_value(I), "\n"]);
#llvm_landingpad{} ->
- write(Dev, "landingpad { i8*, i32 } personality i32 (i32, i64, i8*,i8*)*
- @__gcc_personality_v0 cleanup\n");
+ write(Dev, "landingpad { i8*, i32 } "),
+ case Ver < {3,7} of false -> ok; true ->
+ write(Dev, "personality i32 (i32, i64, i8*,i8*)* "
+ "@__gcc_personality_v0 ")
+ end,
+ write(Dev, "cleanup\n");
#llvm_asm{} ->
write(Dev, [asm_instruction(I), "\n"]);
#llvm_adj_stack{} ->
@@ -1002,9 +1022,12 @@ pp_ins(Dev, I) ->
pp_type(Dev, adj_stack_type(I)),
write(Dev, [" ", adj_stack_offset(I),")\n"]);
#llvm_branch_meta{} ->
- write(Dev, ["!", branch_meta_id(I), " = metadata !{metadata !\"branch_weights\",
- i32 ", branch_meta_true_weight(I), ", i32 ",
- branch_meta_false_weight(I), "}\n"]);
+ write(Dev, ["!", branch_meta_id(I), " = "]),
+ if Ver < {3,6} -> write(Dev, "metadata !{metadata ");
+ Ver >= {3,6} -> write(Dev, "!{ ")
+ end,
+ write(Dev, ["!\"branch_weights\", i32 ", branch_meta_true_weight(I),
+ ", i32 ", branch_meta_false_weight(I), "}\n"]);
Other ->
exit({?MODULE, pp_ins, {"Unknown LLVM instruction", Other}})
end.