Browse Source

Convert constant conditional branches such as "if true goto L" into


			
			
				cache-refactoring
			
			
		
Rhys Weatherley 21 years ago
parent
commit
68e3c3ed6e
  1. 6
      ChangeLog
  2. 1
      include/jit/jit-value.h
  3. 28
      jit/jit-insn.c
  4. 60
      jit/jit-value.c

6
ChangeLog

@ -1,4 +1,10 @@
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.

1
include/jit/jit-value.h

@ -90,6 +90,7 @@ jit_long jit_value_get_long_constant(jit_value_t value) JIT_NOTHROW;
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;

28
jit/jit-insn.c

@ -3547,6 +3547,20 @@ int jit_insn_branch_if
*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);
@ -3734,6 +3748,20 @@ int jit_insn_branch_if_not
*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);

60
jit/jit-value.c

@ -929,6 +929,66 @@ jit_nfloat jit_value_get_nfloat_constant(jit_value_t value)
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

Loading…
Cancel
Save