Skip to content

Commit 6a1e9ca

Browse files
pytorchbotGithub Executorch
authored andcommitted
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-source-id: 260974726 Pull Request resolved: #7608 Co-authored-by: Github Executorch <[email protected]>
1 parent 5e39f74 commit 6a1e9ca

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

runtime/executor/method.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -712,10 +712,13 @@ Error Method::init(executorch_flatbuffer::ExecutionPlan* s_plan) {
712712
"Null instruction at index %zu",
713713
instr_idx);
714714

715+
const void* instr_args = instruction->instr_args();
715716
switch (instruction->instr_args_type()) {
716717
case executorch_flatbuffer::InstructionArguments::KernelCall: {
717-
const auto arg_idxs =
718-
instruction->instr_args_as_KernelCall()->args();
718+
const auto* instr_args_as_KernelCall =
719+
static_cast<const executorch_flatbuffer::KernelCall*>(
720+
instr_args);
721+
const auto arg_idxs = instr_args_as_KernelCall->args();
719722
ET_CHECK_OR_RETURN_ERROR(
720723
arg_idxs != nullptr, InvalidProgram, "KernelCall args missing");
721724
auto res = gen_instruction_arguments(
@@ -729,7 +732,7 @@ Error Method::init(executorch_flatbuffer::ExecutionPlan* s_plan) {
729732
}
730733
chain_instruction_arg_lists[instr_idx] = res.get();
731734
auto err = resolve_operator(
732-
instruction->instr_args_as_KernelCall()->op_index(),
735+
instr_args_as_KernelCall->op_index(),
733736
chain_instruction_kernels,
734737
instr_idx,
735738
res.get(),
@@ -744,7 +747,9 @@ Error Method::init(executorch_flatbuffer::ExecutionPlan* s_plan) {
744747
} break;
745748
case executorch_flatbuffer::InstructionArguments::DelegateCall: {
746749
const auto arg_idxs =
747-
instruction->instr_args_as_DelegateCall()->args();
750+
static_cast<const executorch_flatbuffer::DelegateCall*>(
751+
instr_args)
752+
->args();
748753
ET_CHECK_OR_RETURN_ERROR(
749754
arg_idxs != nullptr,
750755
InvalidProgram,
@@ -764,7 +769,9 @@ Error Method::init(executorch_flatbuffer::ExecutionPlan* s_plan) {
764769
// Validate the index at load time so we can trust it during
765770
// execution.
766771
auto index =
767-
instruction->instr_args_as_JumpFalseCall()->cond_value_index();
772+
static_cast<const executorch_flatbuffer::JumpFalseCall*>(
773+
instr_args)
774+
->cond_value_index();
768775
ET_CHECK_OR_RETURN_ERROR(
769776
index >= 0 && index < n_value_,
770777
InvalidProgram,

0 commit comments

Comments
 (0)