isOpSupportedInMobile(op),
toString(op),
" is not supported in mobile module.");
- code_->instructions_.emplace_back(op, X, N);
- code_->debug_handles_.emplace_back(dbg_handle);
+ code_->instructions_with_handles_.emplace_back(
+ Instruction(op, X, N), dbg_handle);
}
bool Function::append_operator(
int64_t Function::get_debug_handle(size_t pc) const {
TORCH_CHECK(code_, "Valid code must exist.");
TORCH_CHECK(
- pc < code_->debug_handles_.size(),
+ pc < code_->instructions_with_handles_.size(),
"Module debug info index out of boundary.");
- return code_->debug_handles_[pc];
+ return code_->instructions_with_handles_[pc].debug_handle;
}
void Function::setSchema(c10::FunctionSchema schema) {
int64_t Function::getExceptionDebugHandle() const {
size_t pc = getInterpretersExceptionPC();
- return (pc < code_->debug_handles_.size()) ? code_->debug_handles_[pc] : -1;
+ // we dont do bounds check given that pc is obtained
+ // via internal method of getInterpretersExceptionPC
+ // which returns the PC of where the interpreter is.
+ // Although .at will do bounds check anyway.
+ return code_->instructions_with_handles_.at(pc).debug_handle;
}
} // namespace mobile
namespace mobile {
using Stack = std::vector<c10::IValue>;
using DebugHandle = int64_t;
+struct InstructionWithDebugHandle {
+ InstructionWithDebugHandle(Instruction inst, DebugHandle handle)
+ : instruction(inst), debug_handle(handle) {}
+ Instruction instruction;
+ DebugHandle debug_handle;
+};
+
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init)
struct Code {
// TODO: Combine instructions and debug handles vector
// into std::vector<<std::pair<Instruction, DebugHandle>>
- std::vector<Instruction> instructions_;
- std::vector<DebugHandle> debug_handles_;
+ std::vector<InstructionWithDebugHandle> instructions_with_handles_;
std::vector<c10::OperatorName> op_names_;
std::vector<std::function<void(Stack&)>> operators_;
std::vector<c10::IValue> constants_;