Skip to content

Commit 2f68c1a

Browse files
committed
Explain why the last child of CheckAny/SwitchField is emitted differently
1 parent bc91cb2 commit 2f68c1a

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

llvm/utils/TableGen/DecoderTableEmitter.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ void DecoderTableEmitter::emitCheckAnyNode(const CheckAnyNode *N,
204204
emitNode(Child, Indent + 1);
205205
}
206206

207+
// Don't emit OPC_Scope for the last child so that we leave the current scope
208+
// if it fails. Otherwise, we would need some kind of OPC_LeaveScope opcode.
207209
const DecoderTreeNode *Child = *std::prev(N->child_end());
208210

209211
emitComment(Indent) << LS << "try {\n";
@@ -242,6 +244,10 @@ void DecoderTableEmitter::emitSwitchFieldNode(const SwitchFieldNode *N,
242244
emitComment(Indent) << "}\n";
243245
}
244246

247+
// Don't emit the size of the last child and instead emit a sentinel value,
248+
// which tells the interpreter that this is the last case. The interpreter
249+
// doesn't need to know its size because SwitchField node never falls through
250+
// (we either successfully decode an instruction, or leave the current scope).
245251
auto [Val, Child] = *std::prev(N->case_end());
246252
emitStartLine();
247253
emitULEB128(Val);

0 commit comments

Comments
 (0)