/* * libbinrec: a recompiling translator for machine code * Copyright (c) 2016 Andrew Church * * This software may be copied and redistributed under certain conditions; * see the file "COPYING" in the source code distribution for details. * NO WARRANTY is provided with this software. */ #include "src/rtl-internal.h" #include "tests/common.h" static unsigned int opt_flags = BINREC_OPT_DSE | BINREC_OPT_FOLD_CONSTANTS; static int add_rtl(RTLUnit *unit) { int reg1, reg2, reg3, reg4; EXPECT(reg1 = rtl_alloc_register(unit, RTLTYPE_ADDRESS)); EXPECT(rtl_add_insn(unit, RTLOP_LOAD_ARG, reg1, 0, 0, 0)); EXPECT(reg2 = rtl_alloc_register(unit, RTLTYPE_INT32)); EXPECT(rtl_add_insn(unit, RTLOP_LOAD_IMM, reg2, 0, 0, 1)); EXPECT(reg3 = rtl_alloc_register(unit, RTLTYPE_INT32)); EXPECT(rtl_add_insn(unit, RTLOP_LOAD_IMM, reg3, 0, 0, 0)); EXPECT(reg4 = rtl_alloc_register(unit, RTLTYPE_INT32)); EXPECT(rtl_add_insn(unit, RTLOP_SELECT, reg4, reg2, reg3, reg3)); EXPECT(rtl_add_insn(unit, RTLOP_STORE, 0, reg1, reg4, 0)); return EXIT_SUCCESS; } static const char expected[] = #ifdef RTL_DEBUG_OPTIMIZE "[info] Reduced r4 SELECT (always false) to MOVE from r3 at 3\n" "[info] r2 no longer used, setting death = birth\n" "[info] Folded r4 to constant value 0 at 3\n" "[info] r3 no longer used, setting death = birth\n" "[info] Dropping dead store to r2 at 1\n" "[info] Killing instruction 1\n" "[info] Dropping dead store to r3 at 2\n" "[info] Killing instruction 2\n" #endif " 0: LOAD_ARG r1, 0\n" " 1: NOP\n" " 2: NOP\n" " 3: LOAD_IMM r4, 0\n" " 4: STORE 0(r1), r4\n" "\n" "Block 0: --> [0,4] --> \n" ; #include "tests/rtl-optimize-test.i"