* [PATCH 0/4] builtin: teach sparse to linearize __builtin_fma()
@ 2020-09-05 11:12 Luc Van Oostenryck
2020-09-05 11:12 ` [PATCH 1/4] add support for a new instruction: OP_FMA Luc Van Oostenryck
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Luc Van Oostenryck @ 2020-09-05 11:12 UTC (permalink / raw)
To: linux-sparse; +Cc: Luc Van Oostenryck
This series is the second part experimenting with adding the
infrastructure needed for the linearization of builtins.
The first part added support for __builtin_unreachable()
but this builtin has no arguments and no return value.
Now, there is an example showing how to do it when arguments
and/or a return value are present.
Luc Van Oostenryck (4):
add support for a new instruction: OP_FMA
builtin: allow linearization to fail
builtin: add declaration for __builtin_fma{,f,l}()
builtin: teach sparse to linearize __builtin_fma()
builtin.c | 3 +++
linearize.c | 29 +++++++++++++++++++++++++++--
opcode.def | 1 +
3 files changed, 31 insertions(+), 2 deletions(-)
--
2.28.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/4] add support for a new instruction: OP_FMA
2020-09-05 11:12 [PATCH 0/4] builtin: teach sparse to linearize __builtin_fma() Luc Van Oostenryck
@ 2020-09-05 11:12 ` Luc Van Oostenryck
2020-09-05 11:12 ` [PATCH 2/4] builtin: allow linearization to fail Luc Van Oostenryck
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Luc Van Oostenryck @ 2020-09-05 11:12 UTC (permalink / raw)
To: linux-sparse; +Cc: Luc Van Oostenryck
This will be the instruction for fused multiply-add
but the motivation for it is some experimentation with
the linearization of builtins.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
linearize.c | 2 ++
opcode.def | 1 +
2 files changed, 3 insertions(+)
diff --git a/linearize.c b/linearize.c
index 5a8e74970d98..1a2677713123 100644
--- a/linearize.c
+++ b/linearize.c
@@ -244,6 +244,7 @@ static const char *opcodes[] = {
/* Special three-input */
[OP_SEL] = "select",
+ [OP_FMA] = "fma",
/* Memory */
[OP_LOAD] = "load",
@@ -461,6 +462,7 @@ const char *show_instruction(struct instruction *insn)
break;
case OP_SEL:
+ case OP_FMA:
buf += sprintf(buf, "%s <- %s, %s, %s", show_pseudo(insn->target),
show_pseudo(insn->src1), show_pseudo(insn->src2), show_pseudo(insn->src3));
break;
diff --git a/opcode.def b/opcode.def
index 2583e2f4a602..58fe9983cbc2 100644
--- a/opcode.def
+++ b/opcode.def
@@ -91,6 +91,7 @@ OPCODE(SLICE, BADOP, BADOP, BADOP, 1, OPF_TARGET)
/* Select - three input values */
OPCODE(SEL, BADOP, BADOP, BADOP, 3, OPF_TARGET)
+OPCODE(FMA, BADOP, BADOP, BADOP, 3, OPF_TARGET)
/* Memory */
OPCODE(LOAD, BADOP, BADOP, BADOP, 1, OPF_TARGET)
--
2.28.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/4] builtin: allow linearization to fail
2020-09-05 11:12 [PATCH 0/4] builtin: teach sparse to linearize __builtin_fma() Luc Van Oostenryck
2020-09-05 11:12 ` [PATCH 1/4] add support for a new instruction: OP_FMA Luc Van Oostenryck
@ 2020-09-05 11:12 ` Luc Van Oostenryck
2020-09-05 11:12 ` [PATCH 3/4] builtin: add declaration for __builtin_fma{,f,l}() Luc Van Oostenryck
2020-09-05 11:12 ` [PATCH 4/4] builtin: teach sparse to linearize __builtin_fma() Luc Van Oostenryck
3 siblings, 0 replies; 5+ messages in thread
From: Luc Van Oostenryck @ 2020-09-05 11:12 UTC (permalink / raw)
To: linux-sparse; +Cc: Luc Van Oostenryck
Allow the linearization of builtins to fail and continue with
the normal linearization of OP_CALLs. The motivation for this
is for the linearization of target specific builtins.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
linearize.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/linearize.c b/linearize.c
index 1a2677713123..bf55045bcbce 100644
--- a/linearize.c
+++ b/linearize.c
@@ -1513,8 +1513,11 @@ static pseudo_t linearize_call_expression(struct entrypoint *ep, struct expressi
fntype = fn->ctype;
// handle builtins
- if (fntype->op && fntype->op->linearize)
- return fntype->op->linearize(ep, expr);
+ if (fntype->op && fntype->op->linearize) {
+ retval = fntype->op->linearize(ep, expr);
+ if (retval)
+ return retval;
+ }
ctype = &fntype->ctype;
if (fntype->type == SYM_NODE)
--
2.28.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/4] builtin: add declaration for __builtin_fma{,f,l}()
2020-09-05 11:12 [PATCH 0/4] builtin: teach sparse to linearize __builtin_fma() Luc Van Oostenryck
2020-09-05 11:12 ` [PATCH 1/4] add support for a new instruction: OP_FMA Luc Van Oostenryck
2020-09-05 11:12 ` [PATCH 2/4] builtin: allow linearization to fail Luc Van Oostenryck
@ 2020-09-05 11:12 ` Luc Van Oostenryck
2020-09-05 11:12 ` [PATCH 4/4] builtin: teach sparse to linearize __builtin_fma() Luc Van Oostenryck
3 siblings, 0 replies; 5+ messages in thread
From: Luc Van Oostenryck @ 2020-09-05 11:12 UTC (permalink / raw)
To: linux-sparse; +Cc: Luc Van Oostenryck
The motivation for this is to experiment with adding infrastructure
for the linearization of builtins.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
builtin.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/builtin.c b/builtin.c
index 2e9be8be8adb..26b612dc401b 100644
--- a/builtin.c
+++ b/builtin.c
@@ -490,6 +490,9 @@ static const struct builtin_fn builtins_common[] = {
{ "__builtin_ffs", &int_ctype, 0, { &int_ctype }, .op = &ffs_op },
{ "__builtin_ffsl", &int_ctype, 0, { &long_ctype }, .op = &ffs_op },
{ "__builtin_ffsll", &int_ctype, 0, { &llong_ctype }, .op = &ffs_op },
+ { "__builtin_fma", &double_ctype, 0, { &double_ctype, &double_ctype, &double_ctype }},
+ { "__builtin_fmaf", &float_ctype, 0, { &float_ctype, &float_ctype, &float_ctype }},
+ { "__builtin_fmal", &ldouble_ctype, 0, { &ldouble_ctype, &ldouble_ctype, &ldouble_ctype }},
{ "__builtin_frame_address", &ptr_ctype, 0, { &uint_ctype }},
{ "__builtin_free", &void_ctype, 0, { &ptr_ctype }},
{ "__builtin_huge_val", &double_ctype, 0 },
--
2.28.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 4/4] builtin: teach sparse to linearize __builtin_fma()
2020-09-05 11:12 [PATCH 0/4] builtin: teach sparse to linearize __builtin_fma() Luc Van Oostenryck
` (2 preceding siblings ...)
2020-09-05 11:12 ` [PATCH 3/4] builtin: add declaration for __builtin_fma{,f,l}() Luc Van Oostenryck
@ 2020-09-05 11:12 ` Luc Van Oostenryck
3 siblings, 0 replies; 5+ messages in thread
From: Luc Van Oostenryck @ 2020-09-05 11:12 UTC (permalink / raw)
To: linux-sparse; +Cc: Luc Van Oostenryck
The support for the linearization of builtins was already
added for __builtin_unreachable() but this builtin has
no arguments and no return value.
So, to complete the experience of builtin linearization,
add the linearization of __builtin_fma().
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
linearize.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/linearize.c b/linearize.c
index bf55045bcbce..7157ba511671 100644
--- a/linearize.c
+++ b/linearize.c
@@ -2585,6 +2585,23 @@ struct entrypoint *linearize_symbol(struct symbol *sym)
* Builtin functions
*/
+static pseudo_t linearize_fma(struct entrypoint *ep, struct expression *expr)
+{
+ struct instruction *insn = alloc_typed_instruction(OP_FMA, expr->ctype);
+ struct expression *arg;
+
+ PREPARE_PTR_LIST(expr->args, arg);
+ insn->src1 = linearize_expression(ep, arg);
+ NEXT_PTR_LIST(arg)
+ insn->src2 = linearize_expression(ep, arg);
+ NEXT_PTR_LIST(arg)
+ insn->src3 = linearize_expression(ep, arg);
+ FINISH_PTR_LIST(arg);
+
+ add_one_insn(ep, insn);
+ return insn->target = alloc_pseudo(insn);
+}
+
static pseudo_t linearize_unreachable(struct entrypoint *ep, struct expression *exp)
{
add_unreachable(ep);
@@ -2597,6 +2614,9 @@ static struct sym_init {
struct symbol_op op;
} builtins_table[] = {
// must be declared in builtin.c:declare_builtins[]
+ { "__builtin_fma", linearize_fma },
+ { "__builtin_fmaf", linearize_fma },
+ { "__builtin_fmal", linearize_fma },
{ "__builtin_unreachable", linearize_unreachable },
{ }
};
--
2.28.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-09-05 11:12 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-05 11:12 [PATCH 0/4] builtin: teach sparse to linearize __builtin_fma() Luc Van Oostenryck
2020-09-05 11:12 ` [PATCH 1/4] add support for a new instruction: OP_FMA Luc Van Oostenryck
2020-09-05 11:12 ` [PATCH 2/4] builtin: allow linearization to fail Luc Van Oostenryck
2020-09-05 11:12 ` [PATCH 3/4] builtin: add declaration for __builtin_fma{,f,l}() Luc Van Oostenryck
2020-09-05 11:12 ` [PATCH 4/4] builtin: teach sparse to linearize __builtin_fma() Luc Van Oostenryck
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.