unconditional branches.
+2004-05-20 Rhys Weatherley <rweather@southern-storm.com.au>
+
+ * include/jit/jit-value.h, jit/jit-insn.c, jit/jit-value.c:
+ convert constant conditional branches such as "if true goto L" into
+ unconditional branches.
+
2004-05-15 Rhys Weatherley <rweather@southern-storm.com.au>
* tools/gen-apply.c: fix a macro generation bug for Win32 systems.
jit_float32 jit_value_get_float32_constant(jit_value_t value) JIT_NOTHROW;
jit_float64 jit_value_get_float64_constant(jit_value_t value) JIT_NOTHROW;
jit_nfloat jit_value_get_nfloat_constant(jit_value_t value) JIT_NOTHROW;
+int jit_value_is_true(jit_value_t value) JIT_NOTHROW;
int jit_constant_convert
(jit_constant_t *result, const jit_constant_t *value,
jit_type_t type, int overflow_check) JIT_NOTHROW;
*label = (func->builder->next_label)++;
}
+ /* If the condition is constant, then convert it into either
+ an unconditional branch or a fall-through, as appropriate */
+ if(jit_value_is_constant(value))
+ {
+ if(jit_value_is_true(value))
+ {
+ return jit_insn_branch(func, label);
+ }
+ else
+ {
+ return 1;
+ }
+ }
+
/* Determine if we can replace a previous comparison instruction */
block = func->builder->current_block;
insn = _jit_block_get_last(block);
*label = (func->builder->next_label)++;
}
+ /* If the condition is constant, then convert it into either
+ an unconditional branch or a fall-through, as appropriate */
+ if(jit_value_is_constant(value))
+ {
+ if(!jit_value_is_true(value))
+ {
+ return jit_insn_branch(func, label);
+ }
+ else
+ {
+ return 1;
+ }
+ }
+
/* Determine if we can replace a previous comparison instruction */
block = func->builder->current_block;
insn = _jit_block_get_last(block);
return (jit_nfloat)0.0;
}
+/*@
+ * @deftypefun int jit_value_is_true (jit_value_t value)
+ * Determine if @code{value} is constant and non-zero.
+ * @end deftypefun
+@*/
+int jit_value_is_true(jit_value_t value)
+{
+ if(!value || !(value->is_constant))
+ {
+ return 0;
+ }
+ else if(value->is_nint_constant)
+ {
+ return (value->address != 0);
+ }
+ else
+ {
+ switch(jit_type_normalize(value->type)->kind)
+ {
+ case JIT_TYPE_LONG:
+ case JIT_TYPE_ULONG:
+ {
+ if(jit_value_get_long_constant(value) != 0)
+ {
+ return 1;
+ }
+ }
+ break;
+
+ case JIT_TYPE_FLOAT32:
+ {
+ if(jit_value_get_float32_constant(value) != (jit_float32)0.0)
+ {
+ return 1;
+ }
+ }
+ break;
+
+ case JIT_TYPE_FLOAT64:
+ {
+ if(jit_value_get_float64_constant(value) != (jit_float64)0.0)
+ {
+ return 1;
+ }
+ }
+ break;
+
+ case JIT_TYPE_NFLOAT:
+ {
+ if(jit_value_get_nfloat_constant(value) != (jit_nfloat)0.0)
+ {
+ return 1;
+ }
+ }
+ break;
+ }
+ return 0;
+ }
+}
+
/*@
* @deftypefun int jit_constant_convert ({jit_constant_t *} result, {const jit_constant_t *} value, jit_type_t type, int overflow_check)
* Convert a the constant @code{value} into a new @code{type}, and