Skip to content

Commit

Permalink
optimize candidate replacement instructions before scoring them. this…
Browse files Browse the repository at this point in the history
… leads to better scores because useless mov(0) operands disappear and we apply optimizations more aggressively (fixes #3)
  • Loading branch information
Ilfak Guilfanov authored and Igor Skochinsky committed Feb 21, 2023
1 parent 5a43d3f commit 5e4cb38
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 22 deletions.
17 changes: 0 additions & 17 deletions mba.cfg

This file was deleted.

11 changes: 8 additions & 3 deletions optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
* gooMBA plugin for Hex-Rays Decompiler.
*
*/

#include <chrono>

#include "z3++_no_warn.h"

#include "optimizer.hpp"

//--------------------------------------------------------------------------
Expand All @@ -26,7 +26,11 @@ inline void set_cmt(ea_t ea, const char *cmt)
}

//--------------------------------------------------------------------------
bool check_and_substitute(minsn_t *insn, minsn_t *cand_insn, uint z3_timeout, bool z3_assume_timeouts_correct)
static bool check_and_substitute(
minsn_t *insn,
minsn_t *cand_insn,
uint z3_timeout,
bool z3_assume_timeouts_correct)
{
bool ok = false;
int original_score = score_complexity(*insn);
Expand Down Expand Up @@ -103,7 +107,6 @@ bool optimizer_t::optimize_insn(minsn_t *insn)
{
bool success = false;
auto start_time = std::chrono::high_resolution_clock::now();
minsn_set_t candidate_set; // recall minsn_set_t is automatically sorted by complexity

if ( insn->has_side_effects(true) )
{
Expand All @@ -117,6 +120,7 @@ bool optimizer_t::optimize_insn(minsn_t *insn)

try
{
minsn_set_t candidate_set; // recall minsn_set_t is automatically sorted by complexity
auto equiv_class_start = std::chrono::high_resolution_clock::now();
if ( equiv_classes != nullptr )
equiv_classes->find_candidates(candidate_set, *insn);
Expand All @@ -137,6 +141,7 @@ bool optimizer_t::optimize_insn(minsn_t *insn)

for ( minsn_t *cand : candidate_set )
{
cand->optimize_solo(); // get rid of useless mov(#0) operands
if ( check_and_substitute(insn, cand, z3_timeout, z3_assume_timeouts_correct) )
{
if ( qgetenv("VD_MBA_LOG_PERF") )
Expand Down
2 changes: 0 additions & 2 deletions optimizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ inline void substitute(minsn_t *insn, minsn_t *cand)
insn->swap(*cand);
}

bool check_and_substitute(minsn_t *insn, const candidate_expr_t &cand);

//--------------------------------------------------------------------------
class optimizer_t
{
Expand Down

0 comments on commit 5e4cb38

Please sign in to comment.