From b61eeabfc64bcd44d9352bb75b9d24b65d0c1f07 Mon Sep 17 00:00:00 2001 From: Martin Neupauer Date: Mon, 28 Nov 2022 18:16:24 +0000 Subject: SERVER-71641 Move append instruction methods to a single translation unit --- src/mongo/db/exec/sbe/vm/vm.cpp | 92 +++++++++++++++++++++++++++++++++++++---- src/mongo/db/exec/sbe/vm/vm.h | 76 +++++++++------------------------- 2 files changed, 104 insertions(+), 64 deletions(-) diff --git a/src/mongo/db/exec/sbe/vm/vm.cpp b/src/mongo/db/exec/sbe/vm/vm.cpp index 2aaf691087c..f601579a48e 100644 --- a/src/mongo/db/exec/sbe/vm/vm.cpp +++ b/src/mongo/db/exec/sbe/vm/vm.cpp @@ -341,6 +341,14 @@ void CodeFragment::appendLocalLambda(int codePosition) { offset += writeToMemory(offset, codeOffset); } +void CodeFragment::appendPop() { + appendSimpleInstruction(Instruction::pop); +} + +void CodeFragment::appendSwap() { + appendSimpleInstruction(Instruction::swap); +} + void CodeFragment::appendCmp3w(Instruction::Parameter lhs, Instruction::Parameter rhs) { appendSimpleInstruction(Instruction::cmp3w, lhs, rhs); } @@ -399,6 +407,30 @@ void CodeFragment::appendNot(Instruction::Parameter input) { appendSimpleInstruction(Instruction::logicNot, input); } +void CodeFragment::appendLess(Instruction::Parameter lhs, Instruction::Parameter rhs) { + appendSimpleInstruction(Instruction::less, lhs, rhs); +} + +void CodeFragment::appendLessEq(Instruction::Parameter lhs, Instruction::Parameter rhs) { + appendSimpleInstruction(Instruction::lessEq, lhs, rhs); +} + +void CodeFragment::appendGreater(Instruction::Parameter lhs, Instruction::Parameter rhs) { + appendSimpleInstruction(Instruction::greater, lhs, rhs); +} + +void CodeFragment::appendGreaterEq(Instruction::Parameter lhs, Instruction::Parameter rhs) { + appendSimpleInstruction(Instruction::greaterEq, lhs, rhs); +} + +void CodeFragment::appendEq(Instruction::Parameter lhs, Instruction::Parameter rhs) { + appendSimpleInstruction(Instruction::eq, lhs, rhs); +} + +void CodeFragment::appendNeq(Instruction::Parameter lhs, Instruction::Parameter rhs) { + appendSimpleInstruction(Instruction::neq, lhs, rhs); +} + template void CodeFragment::appendSimpleInstruction(Instruction::Tags tag, Ts&&... params) { Instruction i; @@ -460,6 +492,10 @@ void CodeFragment::appendCollCmp3w(Instruction::Parameter lhs, appendSimpleInstruction(Instruction::collCmp3w, collator, lhs, rhs); } +void CodeFragment::appendFillEmpty() { + appendSimpleInstruction(Instruction::fillEmpty); +} + void CodeFragment::appendFillEmpty(Instruction::Constants k) { Instruction i; i.tag = Instruction::fillEmptyImm; @@ -510,6 +546,10 @@ void CodeFragment::appendGetArraySize(Instruction::Parameter input) { appendSimpleInstruction(Instruction::getArraySize, input); } +void CodeFragment::appendSetField() { + appendSimpleInstruction(Instruction::setField); +} + void CodeFragment::appendSum() { appendSimpleInstruction(Instruction::aggSum); } @@ -582,6 +622,22 @@ void CodeFragment::appendIsRecordId(Instruction::Parameter input) { appendSimpleInstruction(Instruction::isRecordId, input); } +void CodeFragment::appendIsMinKey(Instruction::Parameter input) { + appendSimpleInstruction(Instruction::isMinKey, input); +} + +void CodeFragment::appendIsMaxKey(Instruction::Parameter input) { + appendSimpleInstruction(Instruction::isMaxKey, input); +} + +void CodeFragment::appendIsTimestamp(Instruction::Parameter input) { + appendSimpleInstruction(Instruction::isTimestamp, input); +} + +void CodeFragment::appendTraverseP() { + appendSimpleInstruction(Instruction::traverseP); +} + void CodeFragment::appendTraverseP(int codePosition, Instruction::Constants k) { Instruction i; i.tag = Instruction::traversePImm; @@ -597,6 +653,10 @@ void CodeFragment::appendTraverseP(int codePosition, Instruction::Constants k) { offset += writeToMemory(offset, codeOffset); } +void CodeFragment::appendTraverseF() { + appendSimpleInstruction(Instruction::traverseF); +} + void CodeFragment::appendTraverseF(int codePosition, Instruction::Constants k) { Instruction i; i.tag = Instruction::traverseFImm; @@ -612,6 +672,10 @@ void CodeFragment::appendTraverseF(int codePosition, Instruction::Constants k) { offset += writeToMemory(offset, codeOffset); } +void CodeFragment::appendTraverseCellValues() { + appendSimpleInstruction(Instruction::traverseCsiCellValues); +} + void CodeFragment::appendTraverseCellValues(int codePosition) { Instruction i; i.tag = Instruction::traverseCsiCellValues; @@ -626,6 +690,10 @@ void CodeFragment::appendTraverseCellValues(int codePosition) { offset += writeToMemory(offset, codeOffset); } +void CodeFragment::appendTraverseCellTypes() { + appendSimpleInstruction(Instruction::traverseCsiCellTypes); +} + void CodeFragment::appendTraverseCellTypes(int codePosition) { Instruction i; i.tag = Instruction::traverseCsiCellTypes; @@ -726,6 +794,10 @@ void CodeFragment::appendJumpNothing(int jumpOffset) { offset += writeToMemory(offset, jumpOffset); } +void CodeFragment::appendRet() { + appendSimpleInstruction(Instruction::ret); +} + void CodeFragment::appendAllocStack(uint32_t size) { Instruction i; i.tag = Instruction::allocStack; @@ -737,6 +809,10 @@ void CodeFragment::appendAllocStack(uint32_t size) { offset += writeToMemory(offset, size); } +void CodeFragment::appendFail() { + appendSimpleInstruction(Instruction::fail); +} + FastTuple ByteCode::getField(value::TypeTags objTag, value::Value objValue, value::TypeTags fieldTag, @@ -4952,6 +5028,15 @@ void ByteCode::swapStack() { auto [rhsOwned, rhsTag, rhsValue] = getFromStack(0); auto [lhsOwned, lhsTag, lhsValue] = getFromStack(1); + // Swap values only if they are not physically same. This is necessary for the + // "swap and pop" idiom for returning a value from the top of the stack (used + // by ELocalBind). For example, consider the case where a series of swap, pop, + // swap, pop... instructions are executed and the value at stack[0] and + // stack[1] are physically identical, but stack[1] is owned and stack[0] is + // not. After swapping them, the 'pop' instruction would free the owned one and + // leave the unowned value dangling. The only exception to this is shallow + // values (values which fit directly inside a 64 bit Value and don't need + // to be freed explicitly). if (rhsValue == lhsValue && rhsTag == lhsTag) { if (rhsOwned && !isShallowType(rhsTag)) { reportSwapFailure(); @@ -6218,13 +6303,6 @@ bool ByteCode::runPredicate(const CodeFragment* code) { return pass; } -/** - * Explicit instantiations - */ -template void CodeFragment::appendSimpleInstruction<>(Instruction::Tags); -template void CodeFragment::appendSimpleInstruction( - Instruction::Tags, Instruction::Parameter&); - } // namespace vm } // namespace sbe } // namespace mongo diff --git a/src/mongo/db/exec/sbe/vm/vm.h b/src/mongo/db/exec/sbe/vm/vm.h index 72af6dec2af..d50a52b4e56 100644 --- a/src/mongo/db/exec/sbe/vm/vm.h +++ b/src/mongo/db/exec/sbe/vm/vm.h @@ -755,12 +755,8 @@ public: void appendMoveVal(value::SlotAccessor* accessor); void appendLocalVal(FrameId frameId, int variable, bool moveFrom); void appendLocalLambda(int codePosition); - void appendPop() { - appendSimpleInstruction(Instruction::pop); - } - void appendSwap() { - appendSimpleInstruction(Instruction::swap); - } + void appendPop(); + void appendSwap(); void appendAdd(Instruction::Parameter lhs, Instruction::Parameter rhs); void appendSub(Instruction::Parameter lhs, Instruction::Parameter rhs); void appendMul(Instruction::Parameter lhs, Instruction::Parameter rhs); @@ -769,24 +765,12 @@ public: void appendMod(Instruction::Parameter lhs, Instruction::Parameter rhs); void appendNegate(Instruction::Parameter input); void appendNot(Instruction::Parameter input); - void appendLess(Instruction::Parameter lhs, Instruction::Parameter rhs) { - appendSimpleInstruction(Instruction::less, lhs, rhs); - } - void appendLessEq(Instruction::Parameter lhs, Instruction::Parameter rhs) { - appendSimpleInstruction(Instruction::lessEq, lhs, rhs); - } - void appendGreater(Instruction::Parameter lhs, Instruction::Parameter rhs) { - appendSimpleInstruction(Instruction::greater, lhs, rhs); - } - void appendGreaterEq(Instruction::Parameter lhs, Instruction::Parameter rhs) { - appendSimpleInstruction(Instruction::greaterEq, lhs, rhs); - } - void appendEq(Instruction::Parameter lhs, Instruction::Parameter rhs) { - appendSimpleInstruction(Instruction::eq, lhs, rhs); - } - void appendNeq(Instruction::Parameter lhs, Instruction::Parameter rhs) { - appendSimpleInstruction(Instruction::neq, lhs, rhs); - } + void appendLess(Instruction::Parameter lhs, Instruction::Parameter rhs); + void appendLessEq(Instruction::Parameter lhs, Instruction::Parameter rhs); + void appendGreater(Instruction::Parameter lhs, Instruction::Parameter rhs); + void appendGreaterEq(Instruction::Parameter lhs, Instruction::Parameter rhs); + void appendEq(Instruction::Parameter lhs, Instruction::Parameter rhs); + void appendNeq(Instruction::Parameter lhs, Instruction::Parameter rhs); void appendCmp3w(Instruction::Parameter lhs, Instruction::Parameter rhs); void appendCollLess(Instruction::Parameter lhs, @@ -817,34 +801,22 @@ public: Instruction::Parameter rhs, Instruction::Parameter collator); - void appendFillEmpty() { - appendSimpleInstruction(Instruction::fillEmpty); - } + void appendFillEmpty(); void appendFillEmpty(Instruction::Constants k); void appendGetField(Instruction::Parameter lhs, Instruction::Parameter rhs); void appendGetField(Instruction::Parameter input, StringData fieldName); void appendGetElement(Instruction::Parameter lhs, Instruction::Parameter rhs); void appendCollComparisonKey(Instruction::Parameter lhs, Instruction::Parameter rhs); void appendGetFieldOrElement(Instruction::Parameter lhs, Instruction::Parameter rhs); - void appendTraverseP() { - appendSimpleInstruction(Instruction::traverseP); - } + void appendTraverseP(); void appendTraverseP(int codePosition, Instruction::Constants k); - void appendTraverseF() { - appendSimpleInstruction(Instruction::traverseF); - } + void appendTraverseF(); void appendTraverseF(int codePosition, Instruction::Constants k); - void appendTraverseCellValues() { - appendSimpleInstruction(Instruction::traverseCsiCellValues); - } + void appendTraverseCellValues(); void appendTraverseCellValues(int codePosition); - void appendTraverseCellTypes() { - appendSimpleInstruction(Instruction::traverseCsiCellTypes); - } + void appendTraverseCellTypes(); void appendTraverseCellTypes(int codePosition); - void appendSetField() { - appendSimpleInstruction(Instruction::setField); - } + void appendSetField(); void appendGetArraySize(Instruction::Parameter input); void appendDateTrunc(TimeUnit unit, int64_t binSize, TimeZone timezone, DayOfWeek startOfWeek); @@ -866,27 +838,17 @@ public: void appendIsNaN(Instruction::Parameter input); void appendIsInfinity(Instruction::Parameter input); void appendIsRecordId(Instruction::Parameter input); - void appendIsMinKey(Instruction::Parameter input) { - appendSimpleInstruction(Instruction::isMinKey, input); - } - void appendIsMaxKey(Instruction::Parameter input) { - appendSimpleInstruction(Instruction::isMaxKey, input); - } - void appendIsTimestamp(Instruction::Parameter input) { - appendSimpleInstruction(Instruction::isTimestamp, input); - } + void appendIsMinKey(Instruction::Parameter input); + void appendIsMaxKey(Instruction::Parameter input); + void appendIsTimestamp(Instruction::Parameter input); void appendTypeMatch(Instruction::Parameter input, uint32_t mask); void appendFunction(Builtin f, ArityType arity); void appendJump(int jumpOffset); void appendJumpTrue(int jumpOffset); void appendJumpNothing(int jumpOffset); - void appendRet() { - appendSimpleInstruction(Instruction::ret); - } + void appendRet(); void appendAllocStack(uint32_t size); - void appendFail() { - appendSimpleInstruction(Instruction::fail); - } + void appendFail(); void appendNumericConvert(value::TypeTags targetTag); void appendApplyClassicMatcher(const MatchExpression*); -- cgit v1.2.1