diff mbox

[v4,32/63] llvm: add support for OP_SETVAL with floats

Message ID 20170321001607.75169-33-luc.vanoostenryck@gmail.com (mailing list archive)
State Superseded, archived
Headers show

Commit Message

Luc Van Oostenryck March 21, 2017, 12:15 a.m. UTC
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 sparse-llvm.c               | 19 ++++++++++++++++++-
 validation/backend/setval.c |  7 +++++++
 2 files changed, 25 insertions(+), 1 deletion(-)
 create mode 100644 validation/backend/setval.c

Comments

Christopher Li March 24, 2017, 5:53 a.m. UTC | #1
On Mon, Mar 20, 2017 at 5:15 PM, Luc Van Oostenryck
<luc.vanoostenryck@gmail.com> wrote:
> --- a/sparse-llvm.c
> +++ b/sparse-llvm.c
> @@ -866,6 +866,23 @@ static void output_op_cast(struct function *fn, struct instruction *insn, LLVMOp
>         insn->target->priv = target;
>  }
>
> +static void output_op_setval(struct function *fn, struct instruction *insn)
> +{
> +       struct expression *val = insn->val;
> +       LLVMTypeRef dtype = symbol_type(insn->type);
> +       LLVMValueRef target;
> +
> +       switch (val->type) {
> +       case EXPR_FVALUE:
> +               target = LLVMConstReal(dtype, val->fvalue);
> +               break;
> +       default:
> +               assert(0);

If there is just one case and default, maybe "if" statement is good enough?
Switch statement is kind of over kill here.

Chris
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Luc Van Oostenryck March 24, 2017, 7:48 a.m. UTC | #2
On Thu, Mar 23, 2017 at 10:53:15PM -0700, Christopher Li wrote:
> On Mon, Mar 20, 2017 at 5:15 PM, Luc Van Oostenryck
> <luc.vanoostenryck@gmail.com> wrote:
> > --- a/sparse-llvm.c
> > +++ b/sparse-llvm.c
> > @@ -866,6 +866,23 @@ static void output_op_cast(struct function *fn, struct instruction *insn, LLVMOp
> >         insn->target->priv = target;
> >  }
> >
> > +static void output_op_setval(struct function *fn, struct instruction *insn)
> > +{
> > +       struct expression *val = insn->val;
> > +       LLVMTypeRef dtype = symbol_type(insn->type);
> > +       LLVMValueRef target;
> > +
> > +       switch (val->type) {
> > +       case EXPR_FVALUE:
> > +               target = LLVMConstReal(dtype, val->fvalue);
> > +               break;
> > +       default:
> > +               assert(0);
> 
> If there is just one case and default, maybe "if" statement is good enough?
> Switch statement is kind of over kill here.

The next patch add the case EXPR_LABEL and EXPR_STRINGs
need to be supported too.

-- Luc
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/sparse-llvm.c b/sparse-llvm.c
index 6cc01cdd9..29cb11ee3 100644
--- a/sparse-llvm.c
+++ b/sparse-llvm.c
@@ -866,6 +866,23 @@  static void output_op_cast(struct function *fn, struct instruction *insn, LLVMOp
 	insn->target->priv = target;
 }
 
+static void output_op_setval(struct function *fn, struct instruction *insn)
+{
+	struct expression *val = insn->val;
+	LLVMTypeRef dtype = symbol_type(insn->type);
+	LLVMValueRef target;
+
+	switch (val->type) {
+	case EXPR_FVALUE:
+		target = LLVMConstReal(dtype, val->fvalue);
+		break;
+	default:
+		assert(0);
+	}
+
+	insn->target->priv = target;
+}
+
 static void output_insn(struct function *fn, struct instruction *insn)
 {
 	switch (insn->opcode) {
@@ -882,7 +899,7 @@  static void output_insn(struct function *fn, struct instruction *insn)
 		assert(0);
 		break;
 	case OP_SETVAL:
-		assert(0);
+		output_op_setval(fn, insn);
 		break;
 	case OP_SWITCH:
 		output_op_switch(fn, insn);
diff --git a/validation/backend/setval.c b/validation/backend/setval.c
new file mode 100644
index 000000000..e3557571d
--- /dev/null
+++ b/validation/backend/setval.c
@@ -0,0 +1,7 @@ 
+double setfval64(void) { return 1.23; }
+float  setfval32(void) { return 1.23F; }
+
+/*
+ * check-name: setval-float
+ * check-command: ./sparsec -Wno-decl -c $file -o tmp.o
+ */