diff options
author | Martin Neupauer <xmaton@messengeruser.com> | 2023-05-17 13:03:29 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2023-05-17 14:51:30 +0000 |
commit | b86eacc32461d660420a0b64d88c17afc25acf2d (patch) | |
tree | ca80e7d598f2ab2f98adfc30a0133ba723780bbe | |
parent | ebddcadadbcd8e5a1f867772963475d48766dfeb (diff) | |
download | mongo-b86eacc32461d660420a0b64d88c17afc25acf2d.tar.gz |
SERVER-76896 Add direct access for two common slot accessors
-rw-r--r-- | src/mongo/db/exec/sbe/values/slot.h | 5 | ||||
-rw-r--r-- | src/mongo/db/exec/sbe/vm/vm.cpp | 30 | ||||
-rw-r--r-- | src/mongo/db/exec/sbe/vm/vm.h | 6 | ||||
-rw-r--r-- | src/mongo/db/exec/sbe/vm/vm_printer.cpp | 2 |
4 files changed, 42 insertions, 1 deletions
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<TypeTags, Value> copyOrMoveValue() = 0; + + template <typename T> + bool is() const { + return dynamic_cast<const T*>(this) != nullptr; + } }; /** diff --git a/src/mongo/db/exec/sbe/vm/vm.cpp b/src/mongo/db/exec/sbe/vm/vm.cpp index 92c23c9e7ce..d3ad34e2b06 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<value::OwnedValueAccessor>()) { + return Instruction::pushOwnedAccessorVal; + } else if (accessor->is<RuntimeEnvironment::Accessor>()) { + return Instruction::pushEnvAccessorVal; + } + return Instruction::pushAccessVal; + }(accessor); auto offset = allocateSpace(sizeof(Instruction) + sizeof(accessor)); offset += writeToMemory(offset, i); @@ -6644,6 +6654,24 @@ void ByteCode::runInternal(const CodeFragment* code, int64_t position) { break; } + case Instruction::pushOwnedAccessorVal: { + auto accessor = readFromMemory<value::OwnedValueAccessor*>(pcPointer); + pcPointer += sizeof(accessor); + + auto [tag, val] = accessor->getViewOfValue(); + pushStack(false, tag, val); + + break; + } + case Instruction::pushEnvAccessorVal: { + auto accessor = readFromMemory<RuntimeEnvironment::Accessor*>(pcPointer); + pcPointer += sizeof(accessor); + + auto [tag, val] = accessor->getViewOfValue(); + pushStack(false, tag, val); + + break; + } case Instruction::pushMoveVal: { auto accessor = readFromMemory<value::SlotAccessor*>(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 0ac3306db05..820c9c656fc 100644 --- a/src/mongo/db/exec/sbe/vm/vm.h +++ b/src/mongo/db/exec/sbe/vm/vm.h @@ -264,6 +264,8 @@ struct Instruction { enum Tags { pushConstVal, pushAccessVal, + pushOwnedAccessorVal, + pushEnvAccessorVal, pushMoveVal, pushLocalVal, pushMoveLocalVal, @@ -432,6 +434,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<value::SlotAccessor*>(pcPointer); |