From 7021d41fe3b62767918233ec9004a9a6a3e29de8 Mon Sep 17 00:00:00 2001 From: Aleksey Demakov Date: Mon, 28 May 2007 09:00:54 +0000 Subject: [PATCH] do not use copy propagation for addressable and volatile values --- ChangeLog | 5 +++ jit/jit-live.c | 99 +++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 95 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4f0c4f2..e706a05 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2007-05-28 Aleksey Demakov + + * jit/jit-live.c (forward_propagation, backward_propagation): do not + optimize addressable and volatile values. + 2007-05-28 Aleksey Demakov * jit/jit-live.c (_jit_function_compute_liveness) diff --git a/jit/jit-live.c b/jit/jit-live.c index 53c2b96..faa7666 100644 --- a/jit/jit-live.c +++ b/jit/jit-live.c @@ -19,6 +19,7 @@ */ #include "jit-internal.h" +#include #define USE_FORWARD_PROPAGATION 1 #define USE_BACKWARD_PROPAGATION 1 @@ -134,6 +135,11 @@ compute_liveness_for_block(jit_block_t block) /* There is no next use of this value and it is not live on exit from the block. So we can discard the entire instruction as it will have no effect */ +#ifdef _JIT_COMPILE_DEBUG + printf("liveness analysis: optimize away instruction '"); + jit_dump_insn(stdout, block->func, insn); + printf("'\n"); +#endif insn->opcode = (short)JIT_OP_NOP; continue; } @@ -163,7 +169,7 @@ compute_liveness_for_block(jit_block_t block) } } -#if USE_FORWARD_PROPAGATION || USE_BACKWARD_PROPAGATION +#if defined(USE_FORWARD_PROPAGATION) || defined(USE_BACKWARD_PROPAGATION) static int is_copy_opcode(int opcode) { @@ -237,26 +243,43 @@ forward_propagation(jit_block_t block) continue; } - /* Copy to itself could be safely discarded */ + /* Discard copy to itself */ if(dest == value) { +#ifdef _JIT_COMPILE_DEBUG + printf("forward copy propagation: optimize away copy to itself in '"); + jit_dump_insn(stdout, block->func, insn); + printf("'\n"); +#endif insn->opcode = (short)JIT_OP_NOP; optimized = 1; continue; } /* Not smart enough to tell when it is safe to optimize copying - to a value used in other basic block. So just give up. */ + to a value that is used in other basic blocks or may be + aliased. */ if(!dest->is_temporary) { continue; } + if(dest->is_addressable || dest->is_volatile) + { + continue; + } iter2 = iter; while((insn2 = jit_insn_iter_next(&iter2)) != 0) { - flags2 = insn2->flags; + /* Skip NOP instructions, which may have arguments left + over from when the instruction was replaced, but which + are not relevant to our analysis */ + if(insn->opcode == JIT_OP_NOP) + { + continue; + } + flags2 = insn2->flags; if((flags2 & JIT_INSN_DEST_OTHER_FLAGS) == 0) { if((flags2 & JIT_INSN_DEST_IS_VALUE) == 0) @@ -268,6 +291,15 @@ forward_propagation(jit_block_t block) } else if(insn2->dest == dest) { +#ifdef _JIT_COMPILE_DEBUG + printf("forward copy propagation: in '"); + jit_dump_insn(stdout, block->func, insn2); + printf("' replace "); + jit_dump_value(stdout, block->func, insn2->dest, 0); + printf(" with "); + jit_dump_value(stdout, block->func, value, 0); + printf("'\n"); +#endif insn2->dest = value; optimized = 1; } @@ -276,6 +308,15 @@ forward_propagation(jit_block_t block) { if(insn2->value1 == dest) { +#ifdef _JIT_COMPILE_DEBUG + printf("forward copy propagation: in '"); + jit_dump_insn(stdout, block->func, insn2); + printf("' replace "); + jit_dump_value(stdout, block->func, insn2->value1, 0); + printf(" with "); + jit_dump_value(stdout, block->func, value, 0); + printf("'\n"); +#endif insn2->value1 = value; optimized = 1; } @@ -284,6 +325,15 @@ forward_propagation(jit_block_t block) { if(insn2->value2 == dest) { +#ifdef _JIT_COMPILE_DEBUG + printf("forward copy propagation: in '"); + jit_dump_insn(stdout, block->func, insn2); + printf("' replace "); + jit_dump_value(stdout, block->func, insn2->value2, 0); + printf(" with "); + jit_dump_value(stdout, block->func, value, 0); + printf("'\n"); +#endif insn2->value2 = value; optimized = 1; } @@ -295,7 +345,7 @@ forward_propagation(jit_block_t block) } #endif -#if USE_BACKWARD_PROPAGATION +#ifdef USE_BACKWARD_PROPAGATION /* * Perform simple copy propagation within basic block for the case when a * temporary value is stored to another value. This replaces instructions @@ -338,16 +388,29 @@ backward_propagation(jit_block_t block) { continue; } + if(dest->is_addressable || dest->is_volatile) + { + continue; + } value = insn->value1; if(value == 0) { continue; } + if(value->is_addressable || value->is_volatile) + { + continue; + } - /* Copy to itself could be safely discarded */ + /* Discard copy to itself */ if(dest == value) { +#ifdef _JIT_COMPILE_DEBUG + printf("backward copy propagation: optimize away copy to itself in '"); + jit_dump_insn(stdout, block->func, insn); + printf("'\n"); +#endif insn->opcode = (short)JIT_OP_NOP; optimized = 1; continue; @@ -362,8 +425,15 @@ backward_propagation(jit_block_t block) iter2 = iter; while((insn2 = jit_insn_iter_previous(&iter2)) != 0) { - flags2 = insn2->flags; + /* Skip NOP instructions, which may have arguments left + over from when the instruction was replaced, but which + are not relevant to our analysis */ + if(insn->opcode == JIT_OP_NOP) + { + continue; + } + flags2 = insn2->flags; if((flags2 & JIT_INSN_DEST_OTHER_FLAGS) == 0) { if(insn2->dest == dest) @@ -374,6 +444,17 @@ backward_propagation(jit_block_t block) { if((flags2 & JIT_INSN_DEST_IS_VALUE) == 0) { +#ifdef _JIT_COMPILE_DEBUG + printf("backward copy propagation: in '"); + jit_dump_insn(stdout, block->func, insn2); + printf("' replace "); + jit_dump_value(stdout, block->func, insn2->dest, 0); + printf(" with "); + jit_dump_value(stdout, block->func, dest, 0); + printf(" and optimize away '"); + jit_dump_insn(stdout, block->func, insn); + printf("'\n"); +#endif insn->opcode = (short)JIT_OP_NOP; insn2->dest = dest; optimized = 1; @@ -470,7 +551,7 @@ void _jit_function_compute_liveness(jit_function_t func) /* Perform peephole optimization on branches to branches */ _jit_block_peephole_branch(block); -#if USE_FORWARD_PROPAGATION +#ifdef USE_FORWARD_PROPAGATION /* Perform forward copy propagation for the block */ forward_propagation(block); #endif @@ -481,7 +562,7 @@ void _jit_function_compute_liveness(jit_function_t func) /* Compute the liveness flags for the block */ compute_liveness_for_block(block); -#if USE_BACKWARD_PROPAGATION +#ifdef USE_BACKWARD_PROPAGATION /* Perform backward copy propagation for the block */ if(backward_propagation(block)) { -- 2.47.3