Skip to content

Commit

Permalink
[DSLX:bytecode] Avoid unnecessary unique_ptr construction.
Browse files Browse the repository at this point in the history
unique_ptr is for moving, https://abseil.io/tips/187

PiperOrigin-RevId: 586460302
  • Loading branch information
cdleary authored and copybara-github committed Nov 29, 2023
1 parent aebb40c commit e114257
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
2 changes: 2 additions & 0 deletions xls/dslx/bytecode/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,9 @@ cc_library(
"//xls/dslx:import_data",
"//xls/dslx:interp_value",
"//xls/dslx:interp_value_helpers",
"//xls/dslx:value_format_descriptor",
"//xls/dslx/frontend:ast",
"//xls/dslx/frontend:pos",
"//xls/dslx/type_system:concrete_type",
"//xls/dslx/type_system:parametric_env",
"//xls/dslx/type_system:type_info",
Expand Down
18 changes: 11 additions & 7 deletions xls/dslx/bytecode/bytecode_interpreter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,19 @@
#include "xls/dslx/bytecode/bytecode.h"
#include "xls/dslx/bytecode/bytecode_cache_interface.h"
#include "xls/dslx/bytecode/bytecode_emitter.h"
#include "xls/dslx/bytecode/bytecode_interpreter_options.h"
#include "xls/dslx/bytecode/frame.h"
#include "xls/dslx/bytecode/interpreter_stack.h"
#include "xls/dslx/errors.h"
#include "xls/dslx/frontend/ast.h"
#include "xls/dslx/frontend/pos.h"
#include "xls/dslx/import_data.h"
#include "xls/dslx/interp_value.h"
#include "xls/dslx/interp_value_helpers.h"
#include "xls/dslx/type_system/concrete_type.h"
#include "xls/dslx/type_system/parametric_env.h"
#include "xls/dslx/type_system/type_info.h"
#include "xls/dslx/value_format_descriptor.h"
#include "xls/ir/big_int.h"
#include "xls/ir/bits.h"
#include "xls/ir/bits_ops.h"
Expand Down Expand Up @@ -82,13 +86,13 @@ constexpr int64_t kChannelTraceIndentation = 2;
ImportData* import_data, BytecodeFunction* bf,
const std::vector<InterpValue>& args,
const BytecodeInterpreterOptions& options) {
XLS_ASSIGN_OR_RETURN(auto interpreter, BytecodeInterpreter::CreateUnique(
import_data, bf, args, options));
XLS_RETURN_IF_ERROR(interpreter->Run());
BytecodeInterpreter interpreter(import_data, options);
XLS_RETURN_IF_ERROR(interpreter.InitFrame(bf, args, bf->type_info()));
XLS_RETURN_IF_ERROR(interpreter.Run());
if (options.validate_final_stack_depth()) {
XLS_RET_CHECK_EQ(interpreter->stack_.size(), 1);
XLS_RET_CHECK_EQ(interpreter.stack_.size(), 1);
}
return interpreter->stack_.PeekOrDie();
return interpreter.stack_.PeekOrDie();
}

BytecodeInterpreter::BytecodeInterpreter(
Expand Down Expand Up @@ -1442,7 +1446,7 @@ absl::Status BytecodeInterpreter::RunBuiltinMap(const Bytecode& bytecode) {
Bytecode(span, Bytecode::Op::kStore, Bytecode::SlotIndex(1)));

// Top-of-loop marker.
int top_of_loop_index = bytecodes.size();
size_t top_of_loop_index = bytecodes.size();
bytecodes.push_back(Bytecode(span, Bytecode::Op::kJumpDest));

// Extract element N and call the mapping fn on that value.
Expand All @@ -1468,7 +1472,7 @@ absl::Status BytecodeInterpreter::RunBuiltinMap(const Bytecode& bytecode) {
Bytecode(span, Bytecode::Op::kLoad, Bytecode::SlotIndex(1)));
bytecodes.push_back(
Bytecode(span, Bytecode::Op::kLiteral,
InterpValue::MakeU32(elements->size())));
InterpValue::MakeU32(static_cast<uint32_t>(elements->size()))));
bytecodes.push_back(Bytecode(span, Bytecode::Op::kLt));

// If true, jump to top-of-loop, else create the result array.
Expand Down
5 changes: 4 additions & 1 deletion xls/dslx/bytecode/bytecode_interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
#include "xls/dslx/bytecode/interpreter_stack.h"
#include "xls/dslx/frontend/ast.h"
#include "xls/dslx/import_data.h"
#include "xls/dslx/interp_value.h"
#include "xls/dslx/type_system/parametric_env.h"
#include "xls/dslx/type_system/type_info.h"

namespace xls::dslx {

Expand Down Expand Up @@ -77,6 +79,7 @@ class BytecodeInterpreter {
BytecodeInterpreter(ImportData* import_data,
const BytecodeInterpreterOptions& options);

// Creates a new interpreter object with an initialized entry frame.
static absl::StatusOr<std::unique_ptr<BytecodeInterpreter>> CreateUnique(
ImportData* import_data, BytecodeFunction* bf,
const std::vector<InterpValue>& args,
Expand Down Expand Up @@ -242,7 +245,7 @@ class ProcConfigBytecodeInterpreter : public BytecodeInterpreter {

// The execution state that a proc may be left in after a call to
// ProcInstance::Run.
enum class ProcExecutionState {
enum class ProcExecutionState : uint8_t {
// The proc tick completed.
kCompleted,
// The proc tick was blocked on a blocking receive.
Expand Down

0 comments on commit e114257

Please sign in to comment.