diff --git a/service/class-merging/ModelMethodMerger.cpp b/service/class-merging/ModelMethodMerger.cpp index 1907e03adb6..a35b81cff30 100644 --- a/service/class-merging/ModelMethodMerger.cpp +++ b/service/class-merging/ModelMethodMerger.cpp @@ -320,7 +320,7 @@ void ModelMethodMerger::fix_visibility() { auto call_sites = method_reference::collect_call_refs(m_scope, vmethods_created); for (const auto& callsite : call_sites) { - auto insn = callsite.insn; + auto insn = callsite.mie->insn; always_assert(opcode::is_invoke_direct(insn->opcode())); insn->set_opcode(OPCODE_INVOKE_VIRTUAL); } diff --git a/service/method-dedup/ConstantLifting.cpp b/service/method-dedup/ConstantLifting.cpp index f036669eae0..0438b463983 100644 --- a/service/method-dedup/ConstantLifting.cpp +++ b/service/method-dedup/ConstantLifting.cpp @@ -167,7 +167,7 @@ std::vector ConstantLifting::lift_constants_from( auto call_sites = method_reference::collect_call_refs(scope, lifted); for (const auto& callsite : call_sites) { auto meth = callsite.caller; - auto insn = callsite.insn; + auto insn = callsite.mie->insn; const auto callee = resolve_method(insn->get_method(), opcode_to_search(insn)); always_assert(callee != nullptr); diff --git a/service/method-dedup/NormalizeConstructor.cpp b/service/method-dedup/NormalizeConstructor.cpp index 07934c866f4..43f841e3da2 100644 --- a/service/method-dedup/NormalizeConstructor.cpp +++ b/service/method-dedup/NormalizeConstructor.cpp @@ -556,7 +556,7 @@ uint32_t dedup_constructors(const std::vector& classes, redex_assert(new_callee != old_callee); auto new_field_id_to_arg_id = methods_summaries[new_callee]->field_id_to_origin; - auto insn = callsite.insn; + auto insn = callsite.mie->insn; insn->set_method(new_callee); reorder_callsite_args(old_field_id_to_arg_id, new_field_id_to_arg_id, insn); } diff --git a/service/reference-update/MethodReference.cpp b/service/reference-update/MethodReference.cpp index 66664a8340a..0d66a483637 100644 --- a/service/reference-update/MethodReference.cpp +++ b/service/reference-update/MethodReference.cpp @@ -7,10 +7,8 @@ #include "MethodReference.h" -#include "ControlFlow.h" #include "IRList.h" #include "Resolver.h" -#include "ScopedCFG.h" #include "Show.h" #include "Trace.h" #include "Walkers.h" @@ -67,20 +65,19 @@ void patch_callsite(const CallSite& callsite, const NewCallee& new_callee) { SHOW(new_callee.method), SHOW(callsite.caller)); auto code = callsite.caller->get_code(); - cfg::ScopedCFG cfg(code); - auto insn = callsite.insn; - auto iterator = cfg->find_insn(insn); + auto iterator = code->iterator_to(*callsite.mie); + auto insn = callsite.mie->insn; if (new_callee.additional_args != boost::none) { const auto& args = new_callee.additional_args.get(); auto old_size = insn->srcs_size(); insn->set_srcs_size(old_size + args.size()); size_t pos = old_size; for (uint32_t arg : args) { - auto reg = cfg->allocate_temp(); + auto reg = code->allocate_temp(); // Seems it is different from dasm(OPCODE_CONST, {{VREG, reg}, {LITERAL, // arg}}) which will cause instruction_lowering crash. Why? auto load_const = make_load_const(reg, arg); - cfg->insert_before(iterator, load_const); + code->insert_before(iterator, load_const); insn->set_src(pos++, reg); } } @@ -96,8 +93,7 @@ void update_call_refs_simple( } auto patcher = [&](DexMethod* meth, IRCode& code) { - cfg::ScopedCFG cfg(&code); - for (auto& mie : cfg::InstructionIterable(*cfg)) { + for (auto& mie : InstructionIterable(code)) { auto insn = mie.insn; if (!insn->has_method()) { continue; @@ -140,8 +136,8 @@ CallSites collect_call_refs(const Scope& scope, const T& callees) { if (!code) { return call_sites; } - cfg::ScopedCFG cfg(code); - for (auto& mie : cfg::InstructionIterable(*cfg)) { + + for (auto& mie : InstructionIterable(caller->get_code())) { auto insn = mie.insn; if (!insn->has_method()) { continue; @@ -154,7 +150,7 @@ CallSites collect_call_refs(const Scope& scope, const T& callees) { continue; } - call_sites.emplace_back(caller, insn, callee); + call_sites.emplace_back(caller, &mie, callee); TRACE(REFU, 9, " Found call %s from %s", SHOW(insn), SHOW(caller)); } @@ -203,8 +199,7 @@ int wrap_instance_call_with_static( } auto code = method->get_code(); if (code) { - cfg::ScopedCFG cfg(code); - for (auto& mie : cfg::InstructionIterable(*cfg)) { + for (auto& mie : InstructionIterable(code)) { IRInstruction* insn = mie.insn; if (insn->opcode() != OPCODE_INVOKE_VIRTUAL) { continue; diff --git a/service/reference-update/MethodReference.h b/service/reference-update/MethodReference.h index 8b21e628fc2..993181541d7 100644 --- a/service/reference-update/MethodReference.h +++ b/service/reference-update/MethodReference.h @@ -13,6 +13,8 @@ #include "DexStore.h" #include "IRInstruction.h" +struct MethodItemEntry; + using OrderedMethodSet = std::set; namespace method_reference { @@ -20,10 +22,10 @@ namespace method_reference { // A callsite instruction in caller. mie should always contain an IRInstruction. struct CallSite { DexMethod* caller; - IRInstruction* insn; + MethodItemEntry* mie; DexMethod* callee; - CallSite(DexMethod* caller, IRInstruction* insn, DexMethod* callee) - : caller(caller), insn(insn), callee(callee) {} + CallSite(DexMethod* caller, MethodItemEntry* mie, DexMethod* callee) + : caller(caller), mie(mie), callee(callee) {} }; using CallSites = std::vector; diff --git a/service/reference-update/TypeReference.cpp b/service/reference-update/TypeReference.cpp index 845b237b697..806dbc5b81b 100644 --- a/service/reference-update/TypeReference.cpp +++ b/service/reference-update/TypeReference.cpp @@ -7,10 +7,8 @@ #include "TypeReference.h" -#include "ControlFlow.h" #include "MethodReference.h" #include "Resolver.h" -#include "ScopedCFG.h" #include "Show.h" #include "Trace.h" #include "Walkers.h" @@ -499,8 +497,7 @@ void update_method_signature_type_references( // Ensure that no method references left that still refer old types. walk::parallel::code(scope, [&old_types](DexMethod*, IRCode& code) { - cfg::ScopedCFG cfg(&code); - for (auto& mie : InstructionIterable(*cfg)) { + for (auto& mie : InstructionIterable(code)) { auto insn = mie.insn; if (insn->has_method()) { auto proto = insn->get_method()->get_proto(); @@ -535,8 +532,7 @@ void update_field_type_references( walk::parallel::fields(scope, update_field); walk::parallel::code(scope, [&old_to_new](DexMethod*, IRCode& code) { - cfg::ScopedCFG cfg(&code); - for (auto& mie : InstructionIterable(*cfg)) { + for (auto& mie : InstructionIterable(code)) { auto insn = mie.insn; if (insn->has_field()) { const auto ref_type = insn->get_field()->get_type(); @@ -579,22 +575,12 @@ void fix_colliding_dmethods( num_additional_args[meth] = arg_count; auto code = meth->get_code(); - cfg::ScopedCFG cfg(code); - auto block = cfg->entry_block(); - auto last_loading = block->get_last_param_loading_insn(); for (size_t i = 0; i < arg_count; ++i) { - auto new_param_reg = cfg->allocate_temp(); + auto new_param_reg = code->allocate_temp(); + auto params = code->get_param_instructions(); auto new_param_load = new IRInstruction(IOPCODE_LOAD_PARAM); new_param_load->set_dest(new_param_reg); - if (last_loading != block->end()) { - cfg->insert_after(block->to_cfg_instruction_iterator(last_loading), - new_param_load); - } else { - cfg->insert_before(block->to_cfg_instruction_iterator( - block->get_first_non_param_loading_insn()), - new_param_load); - } - last_loading = block->get_last_param_loading_insn(); + code->insert_before(params.end(), new_param_load); } TRACE(REFU, 9, @@ -605,8 +591,7 @@ void fix_colliding_dmethods( walk::parallel::code(scope, [&](DexMethod* meth, IRCode& code) { method_reference::CallSites callsites; - cfg::ScopedCFG cfg(&code); - for (auto& mie : InstructionIterable(*cfg)) { + for (auto& mie : InstructionIterable(code)) { auto insn = mie.insn; if (!insn->has_method()) { continue; @@ -618,7 +603,7 @@ void fix_colliding_dmethods( num_additional_args.find(callee) == num_additional_args.end()) { continue; } - callsites.emplace_back(meth, insn, callee); + callsites.emplace_back(meth, &mie, callee); } for (const auto& callsite : callsites) {