From b525fd9ac2748064eb07ba9e2f1300e91d7488ac Mon Sep 17 00:00:00 2001 From: Github Executorch Date: Fri, 10 Jan 2025 14:56:09 -0800 Subject: [PATCH] Reduce size of Method::init Apply the same technique as #7603 to Method::init Differential Revision: [D68041869](https://our.internmc.facebook.com/intern/diff/D68041869/) [ghstack-poisoned] --- runtime/executor/method.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/runtime/executor/method.cpp b/runtime/executor/method.cpp index 90d4c71953b..94c669b967f 100644 --- a/runtime/executor/method.cpp +++ b/runtime/executor/method.cpp @@ -688,10 +688,13 @@ Error Method::init(executorch_flatbuffer::ExecutionPlan* s_plan) { "Null instruction at index %zu", instr_idx); + const void* instr_args = instruction->instr_args(); switch (instruction->instr_args_type()) { case executorch_flatbuffer::InstructionArguments::KernelCall: { - const auto arg_idxs = - instruction->instr_args_as_KernelCall()->args(); + const auto* instr_args_as_KernelCall = + static_cast( + instr_args); + const auto arg_idxs = instr_args_as_KernelCall->args(); ET_CHECK_OR_RETURN_ERROR( arg_idxs != nullptr, InvalidProgram, "KernelCall args missing"); auto res = gen_instruction_arguments( @@ -705,7 +708,7 @@ Error Method::init(executorch_flatbuffer::ExecutionPlan* s_plan) { } chain_instruction_arg_lists[instr_idx] = res.get(); auto err = resolve_operator( - instruction->instr_args_as_KernelCall()->op_index(), + instr_args_as_KernelCall->op_index(), chain_instruction_kernels, instr_idx, res.get(), @@ -720,7 +723,9 @@ Error Method::init(executorch_flatbuffer::ExecutionPlan* s_plan) { } break; case executorch_flatbuffer::InstructionArguments::DelegateCall: { const auto arg_idxs = - instruction->instr_args_as_DelegateCall()->args(); + static_cast( + instr_args) + ->args(); ET_CHECK_OR_RETURN_ERROR( arg_idxs != nullptr, InvalidProgram, @@ -740,7 +745,9 @@ Error Method::init(executorch_flatbuffer::ExecutionPlan* s_plan) { // Validate the index at load time so we can trust it during // execution. auto index = - instruction->instr_args_as_JumpFalseCall()->cond_value_index(); + static_cast( + instr_args) + ->cond_value_index(); ET_CHECK_OR_RETURN_ERROR( index >= 0 && index < n_value_, InvalidProgram,