aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2021-03-08 07:27:57 -0700
committerTom Tromey <tom@tromey.com>2021-03-08 07:28:31 -0700
commit944fd3b8126f27569a6a3552b3457ba8a8cc3f87 (patch)
treeb222df7620e4a10d3f3577239297c75595d58d41
parent33b79214629c2b1b219e82bb34aed5fb03913634 (diff)
downloadbinutils-944fd3b8126f27569a6a3552b3457ba8a8cc3f87.zip
binutils-944fd3b8126f27569a6a3552b3457ba8a8cc3f87.tar.gz
binutils-944fd3b8126f27569a6a3552b3457ba8a8cc3f87.tar.bz2
Implement OpenCL logical binary operations
This implements "&&" and "||" for OpenCL. gdb/ChangeLog 2021-03-08 Tom Tromey <tom@tromey.com> * opencl-lang.c (opencl_logical_binop_operation::evaluate): New method. * c-exp.h (class opencl_logical_binop_operation): New.
-rw-r--r--gdb/ChangeLog6
-rw-r--r--gdb/c-exp.h17
-rw-r--r--gdb/opencl-lang.c48
3 files changed, 71 insertions, 0 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 3c7d683..a729c73 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,11 @@
2021-03-08 Tom Tromey <tom@tromey.com>
+ * opencl-lang.c (opencl_logical_binop_operation::evaluate): New
+ method.
+ * c-exp.h (class opencl_logical_binop_operation): New.
+
+2021-03-08 Tom Tromey <tom@tromey.com>
+
* opencl-lang.c (opencl_structop_operation::evaluate): New
method.
* c-exp.h (class opencl_structop_operation): New.
diff --git a/gdb/c-exp.h b/gdb/c-exp.h
index 58a16d5..f75b4ae 100644
--- a/gdb/c-exp.h
+++ b/gdb/c-exp.h
@@ -186,6 +186,23 @@ public:
{ return STRUCTOP_STRUCT; }
};
+/* This handles the "&&" and "||" operations for OpenCL. */
+class opencl_logical_binop_operation
+ : public tuple_holding_operation<enum exp_opcode,
+ operation_up, operation_up>
+{
+public:
+
+ using tuple_holding_operation::tuple_holding_operation;
+
+ value *evaluate (struct type *expect_type,
+ struct expression *exp,
+ enum noside noside) override;
+
+ enum exp_opcode opcode () const override
+ { return std::get<0> (m_storage); }
+};
+
}/* namespace expr */
#endif /* C_EXP_H */
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index 3171639..cca8505 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -984,6 +984,54 @@ opencl_structop_operation::evaluate (struct type *expect_type,
}
}
+value *
+opencl_logical_binop_operation::evaluate (struct type *expect_type,
+ struct expression *exp,
+ enum noside noside)
+{
+ enum exp_opcode op = std::get<0> (m_storage);
+ value *arg1 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
+
+ /* For scalar operations we need to avoid evaluating operands
+ unnecessarily. However, for vector operations we always need to
+ evaluate both operands. Unfortunately we only know which of the
+ two cases apply after we know the type of the second operand.
+ Therefore we evaluate it once using EVAL_AVOID_SIDE_EFFECTS. */
+ value *arg2 = std::get<2> (m_storage)->evaluate (nullptr, exp,
+ EVAL_AVOID_SIDE_EFFECTS);
+ struct type *type1 = check_typedef (value_type (arg1));
+ struct type *type2 = check_typedef (value_type (arg2));
+
+ if ((type1->code () == TYPE_CODE_ARRAY && type1->is_vector ())
+ || (type2->code () == TYPE_CODE_ARRAY && type2->is_vector ()))
+ {
+ arg2 = std::get<2> (m_storage)->evaluate (nullptr, exp, noside);
+
+ return opencl_relop (nullptr, exp, noside, op, arg1, arg2);
+ }
+ else
+ {
+ /* For scalar built-in types, only evaluate the right
+ hand operand if the left hand operand compares
+ unequal(&&)/equal(||) to 0. */
+ int tmp = value_logical_not (arg1);
+
+ if (op == BINOP_LOGICAL_OR)
+ tmp = !tmp;
+
+ if (!tmp)
+ {
+ arg2 = std::get<2> (m_storage)->evaluate (nullptr, exp, noside);
+ tmp = value_logical_not (arg2);
+ if (op == BINOP_LOGICAL_OR)
+ tmp = !tmp;
+ }
+
+ type1 = language_bool_type (exp->language_defn, exp->gdbarch);
+ return value_from_longest (type1, tmp);
+ }
+}
+
} /* namespace expr */
const struct exp_descriptor exp_descriptor_opencl =