From ba0986ac66e3a22d211ad3707ad037fdc10910af Mon Sep 17 00:00:00 2001 From: Martin Neupauer Date: Mon, 15 May 2023 16:50:05 +0000 Subject: SERVER-76896 Add direct access for two common slot accessors --- src/mongo/db/exec/sbe/values/slot.h | 5 +++++ src/mongo/db/exec/sbe/vm/vm.cpp | 30 +++++++++++++++++++++++++++++- src/mongo/db/exec/sbe/vm/vm.h | 6 ++++++ src/mongo/db/exec/sbe/vm/vm_printer.cpp | 2 ++ 4 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/mongo/db/exec/sbe/values/slot.h b/src/mongo/db/exec/sbe/values/slot.h index fdbf99605b7..3b07477a921 100644 --- a/src/mongo/db/exec/sbe/values/slot.h +++ b/src/mongo/db/exec/sbe/values/slot.h @@ -70,6 +70,11 @@ public: * make a deep copy. The returned value is owned by the caller. */ virtual std::pair copyOrMoveValue() = 0; + + template + bool is() const { + return dynamic_cast(this) != nullptr; + } }; /** diff --git a/src/mongo/db/exec/sbe/vm/vm.cpp b/src/mongo/db/exec/sbe/vm/vm.cpp index 5bdcc7496a2..2f7c1bee391 100644 --- a/src/mongo/db/exec/sbe/vm/vm.cpp +++ b/src/mongo/db/exec/sbe/vm/vm.cpp @@ -33,6 +33,7 @@ #include "mongo/platform/basic.h" #include "mongo/db/exec/sbe/expressions/expression.h" +#include "mongo/db/exec/sbe/expressions/runtime_environment.h" #include "mongo/db/exec/sbe/vm/vm.h" #include "mongo/db/exec/sbe/vm/vm_printer.h" @@ -77,6 +78,8 @@ namespace vm { int Instruction::stackOffset[Instruction::Tags::lastInstruction] = { 1, // pushConstVal 1, // pushAccessVal + 1, // pushOwnedAccessorVal + 1, // pushEnvAccessorVal 1, // pushMoveVal 1, // pushLocalVal 1, // pushMoveLocalVal @@ -480,8 +483,15 @@ void CodeFragment::appendConstVal(value::TypeTags tag, value::Value val) { void CodeFragment::appendAccessVal(value::SlotAccessor* accessor) { Instruction i; - i.tag = Instruction::pushAccessVal; + i.tag = [](value::SlotAccessor* accessor) { + if (accessor->is()) { + return Instruction::pushOwnedAccessorVal; + } else if (accessor->is()) { + return Instruction::pushEnvAccessorVal; + } + return Instruction::pushAccessVal; + }(accessor); auto offset = allocateSpace(sizeof(Instruction) + sizeof(accessor)); offset += writeToMemory(offset, i); @@ -7247,6 +7257,24 @@ void ByteCode::runInternal(const CodeFragment* code, int64_t position) { break; } + case Instruction::pushOwnedAccessorVal: { + auto accessor = readFromMemory(pcPointer); + pcPointer += sizeof(accessor); + + auto [tag, val] = accessor->getViewOfValue(); + pushStack(false, tag, val); + + break; + } + case Instruction::pushEnvAccessorVal: { + auto accessor = readFromMemory(pcPointer); + pcPointer += sizeof(accessor); + + auto [tag, val] = accessor->getViewOfValue(); + pushStack(false, tag, val); + + break; + } case Instruction::pushMoveVal: { auto accessor = readFromMemory(pcPointer); pcPointer += sizeof(accessor); diff --git a/src/mongo/db/exec/sbe/vm/vm.h b/src/mongo/db/exec/sbe/vm/vm.h index 2f43bdf5bb6..17b3eb29b7f 100644 --- a/src/mongo/db/exec/sbe/vm/vm.h +++ b/src/mongo/db/exec/sbe/vm/vm.h @@ -265,6 +265,8 @@ struct Instruction { enum Tags { pushConstVal, pushAccessVal, + pushOwnedAccessorVal, + pushEnvAccessorVal, pushMoveVal, pushLocalVal, pushMoveLocalVal, @@ -433,6 +435,10 @@ struct Instruction { return "pushConstVal"; case pushAccessVal: return "pushAccessVal"; + case pushOwnedAccessorVal: + return "pushOwnedAccessorVal"; + case pushEnvAccessorVal: + return "pushEnvAccessorVal"; case pushMoveVal: return "pushMoveVal"; case pushLocalVal: diff --git a/src/mongo/db/exec/sbe/vm/vm_printer.cpp b/src/mongo/db/exec/sbe/vm/vm_printer.cpp index 921463cab28..e545136cb56 100644 --- a/src/mongo/db/exec/sbe/vm/vm_printer.cpp +++ b/src/mongo/db/exec/sbe/vm/vm_printer.cpp @@ -296,6 +296,8 @@ public: .writeValueToStream(tag, val); break; } + case Instruction::pushOwnedAccessorVal: + case Instruction::pushEnvAccessorVal: case Instruction::pushAccessVal: case Instruction::pushMoveVal: { auto accessor = readFromMemory(pcPointer); -- cgit v1.2.1