aboutsummaryrefslogtreecommitdiffstats
path: root/backend/Selection.v
diff options
context:
space:
mode:
authorXavier Leroy <xavier.leroy@college-de-france.fr>2020-06-25 11:21:31 +0200
committerXavier Leroy <xavierleroy@users.noreply.github.com>2020-06-25 16:58:46 +0200
commit7fe7aabe4bac5a2250f31045797fce663ec65848 (patch)
tree48f2b77bd6f689c1b0be63261c39ce1490982f36 /backend/Selection.v
parentc6b86fd5719388301295f9ab4b07b57653e0d8c6 (diff)
downloadcompcert-kvx-7fe7aabe4bac5a2250f31045797fce663ec65848.tar.gz
compcert-kvx-7fe7aabe4bac5a2250f31045797fce663ec65848.zip
Eliminate known builtins whose result is ignored
A typical example is `(void) __builtin_sel(a, b, c)`. It is safe to generate zero code for these uses of builtins because builtins whose semantics are known to the compiler are pure. Other builtins with side effects (e.g. `__builtin_trap`) are not known and will remain in the compiled code. It is useful to generate zero code for these uses of builtins because some of them (e.g. `__builtin_sel`) must be transformed into proper CminorSel expressions during instruction selection. Otherwise, they propagate all the way to ExpandAsm, causing a "not implemented" error there.
Diffstat (limited to 'backend/Selection.v')
-rw-r--r--backend/Selection.v21
1 files changed, 15 insertions, 6 deletions
diff --git a/backend/Selection.v b/backend/Selection.v
index c9771d99..480b09a2 100644
--- a/backend/Selection.v
+++ b/backend/Selection.v
@@ -252,6 +252,10 @@ Function sel_known_builtin (bf: builtin_function) (args: exprlist) :=
None
end.
+(** A CminorSel statement that does nothing, like [Sskip], but reduces. *)
+
+Definition Sno_op := Sseq Sskip Sskip.
+
(** Builtin functions in general *)
Definition sel_builtin_default (optid: option ident) (ef: external_function)
@@ -261,17 +265,22 @@ Definition sel_builtin_default (optid: option ident) (ef: external_function)
Definition sel_builtin (optid: option ident) (ef: external_function)
(args: list Cminor.expr) :=
- match optid, ef with
- | Some id, EF_builtin name sg =>
+ match ef with
+ | EF_builtin name sg =>
match lookup_builtin_function name sg with
| Some bf =>
- match sel_known_builtin bf (sel_exprlist args) with
- | Some a => Sassign id a
- | None => sel_builtin_default optid ef args
+ match optid with
+ | Some id =>
+ match sel_known_builtin bf (sel_exprlist args) with
+ | Some a => Sassign id a
+ | None => sel_builtin_default optid ef args
+ end
+ | None =>
+ Sno_op (**r builtins with semantics are pure *)
end
| None => sel_builtin_default optid ef args
end
- | _, _ =>
+ | _ =>
sel_builtin_default optid ef args
end.