mirror of https://github.com/inolen/redream.git
Constant Propagation Pass: Minor Fixes
This commit is contained in:
parent
4ba9885aab
commit
d8a4a623f4
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
struct ir;
|
||||
|
||||
|
||||
void cpro_run(struct ir *ir);
|
||||
void cprop_run(struct ir *ir);
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -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")) {
|
||||
|
|
Loading…
Reference in New Issue