From 3866d6715ec803cc3eef726c36fecaf54b35486d Mon Sep 17 00:00:00 2001 From: Max Bernstein Date: Tue, 28 Nov 2023 16:40:04 -0500 Subject: [PATCH] Move bailout code to general analysis function --- runtime/bytecode.cpp | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/runtime/bytecode.cpp b/runtime/bytecode.cpp index fcc94df37..b496924e9 100644 --- a/runtime/bytecode.cpp +++ b/runtime/bytecode.cpp @@ -391,25 +391,6 @@ static void analyzeDefiniteAssignment(Thread* thread, HandleScope scope(thread); MutableBytes bytecode(&scope, function.rewrittenBytecode()); word num_opcodes = rewrittenBytecodeLength(bytecode); - word num_locals = Code::cast(function.code()).nlocals(); - if (num_locals == 0) { - // Nothing to do. - DTRACE_PROBE1(python, DefiniteAssignmentBailout, "no_locals"); - return; - } - if (num_locals > 64) { - // We don't support more than 64 locals. - DTRACE_PROBE1(python, DefiniteAssignmentBailout, "too_many_locals"); - return; - } - if (isHardToAnalyze(thread, function)) { - // I don't want to deal with the block stack (yet?). - return; - } - if (num_opcodes == 0) { - // Some tests generate empty code objects. Bail out. - return; - } // Lattice definition uword top = kMaxUword; auto meet = [](uword left, uword right) { return left & right; }; @@ -479,6 +460,28 @@ static void analyzeDefiniteAssignment(Thread* thread, } void analyzeBytecode(Thread* thread, const Function& function) { + HandleScope scope(thread); + MutableBytes bytecode(&scope, function.rewrittenBytecode()); + word num_opcodes = rewrittenBytecodeLength(bytecode); + word num_locals = Code::cast(function.code()).nlocals(); + if (num_locals == 0) { + // Nothing to do. + DTRACE_PROBE1(python, DefiniteAssignmentBailout, "no_locals"); + return; + } + if (num_locals > 64) { + // We don't support more than 64 locals. + DTRACE_PROBE1(python, DefiniteAssignmentBailout, "too_many_locals"); + return; + } + if (isHardToAnalyze(thread, function)) { + // I don't want to deal with the block stack (yet?). + return; + } + if (num_opcodes == 0) { + // Some tests generate empty code objects. Bail out. + return; + } analyzeDefiniteAssignment(thread, function); }