Constant Propagation Pass: Minor Fixes

This commit is contained in:
joseph 2016-12-18 17:45:59 -06:00 committed by Anthony Pesch
parent 4ba9885aab
commit d8a4a623f4
4 changed files with 13 additions and 22 deletions

View File

@ -322,7 +322,7 @@ void jit_compile_block(struct jit *jit, uint32_t guest_addr) {
/* run optimization passes */
lse_run(&ir);
cpro_run(&ir);
cprop_run(&ir);
esimp_run(&ir);
dce_run(&ir);
ra_run(&ir, jit->backend->registers, jit->backend->num_registers);

View File

@ -7,25 +7,13 @@ DEFINE_STAT(constant_propagations_removed, "constant propagations removed");
DEFINE_STAT(could_optimize_binary_op, "constant binary operations possible");
DEFINE_STAT(could_optimize_unary_op, "constant unary operations possible");
void cpro_run(struct ir *ir) {
void cprop_run(struct ir *ir) {
list_for_each_entry(instr, &ir->instrs, struct ir_instr, it) {
/* Skip instructions which do not perform any operations */
if(instr->op == OP_DEBUG_INFO || instr->op == OP_LABEL)
continue;
/* Profile the number of possible constant propagation optimizations */
if (instr->arg[0] && instr->arg[1] && ir_is_constant(instr->arg[0]) &&
ir_is_constant(instr->arg[1])) {
STAT_could_optimize_binary_op++;
}
else if (instr->arg[0] && !instr->arg[1] && ir_is_constant(instr->arg[0])){
STAT_could_optimize_unary_op++;
}
/* Simplify binary ops with constant arguments */
if(instr->arg[0] && ir_is_constant(instr->arg[0]) &&
instr->arg[1] && ir_is_constant(instr->arg[1]))
instr->arg[1] && ir_is_constant(instr->arg[1]) &&
instr->result)
{
uint64_t lhs = ir_zext_constant(instr->arg[0]);
uint64_t rhs = ir_zext_constant(instr->arg[1]);
@ -60,13 +48,15 @@ void cpro_run(struct ir *ir) {
result = ir_alloc_int(ir, lhs ^ rhs, instr->result->type);
break;
default:
STAT_could_optimize_binary_op++;
continue;
}
ir_replace_uses(instr->result, result);
STAT_constant_propagations_removed++;
}
/* Simplify constant unary ops */
else if(instr->arg[0] && !instr->arg[1] && ir_is_constant(instr->arg[0])) {
else if(instr->arg[0] && !instr->arg[1] && ir_is_constant(instr->arg[0]) &&
instr->result) {
uint64_t arg = ir_zext_constant(instr->arg[0]);
struct ir_value *result;
switch(instr->op)
@ -78,6 +68,7 @@ void cpro_run(struct ir *ir) {
result = ir_alloc_int(ir, ~arg, instr->result->type);
break;
default:
STAT_could_optimize_unary_op++;
continue;
}
ir_replace_uses(instr->result, result);

View File

@ -4,7 +4,7 @@
struct ir;
void cpro_run(struct ir *ir);
void cprop_run(struct ir *ir);
#endif

View File

@ -15,7 +15,7 @@
#include "sys/filesystem.h"
DEFINE_OPTION_INT(help, 0, "Show help");
DEFINE_OPTION_STRING(pass, "lse,cpro,cve,esimp,dce,ra",
DEFINE_OPTION_STRING(pass, "lse,cprop,cve,esimp,dce,ra",
"Comma-separated list of passes to run");
DEFINE_STAT(ir_instrs_total, "total ir instructions");
@ -78,8 +78,8 @@ static void process_file(struct jit *jit, const char *filename,
while (name) {
if (!strcmp(name, "lse")) {
lse_run(&ir);
} else if (!strcmp(name, "cpro")){
cpro_run(&ir);
} else if (!strcmp(name, "cprop")){
cprop_run(&ir);
} else if (!strcmp(name, "cve")) {
cve_run(&ir);
} else if (!strcmp(name, "dce")) {