From 5a98277b6c3f8dde27e7ce404e2dcb7ec5999aa2 Mon Sep 17 00:00:00 2001 From: Mirek Klimos Date: Mon, 1 Jul 2013 17:45:46 -0700 Subject: [PATCH] Replace ContSend by CGetL+CUnsetL The behavior of ContSend is equivalent to CGetL+CUnsetL. Let's kill this unnecessary opcode. Let's remove this logic from ContRaise opcode as well. --- hphp/compiler/analysis/emitter.cpp | 21 +++++++++++++------ hphp/doc/bytecode.specification | 11 ++-------- hphp/runtime/vm/bytecode.cpp | 12 ----------- hphp/runtime/vm/hhbc.h | 3 +-- hphp/runtime/vm/jit/hhbctranslator.cpp | 14 ------------- hphp/runtime/vm/jit/hhbctranslator.h | 1 - hphp/runtime/vm/jit/irtranslator.cpp | 4 ---- hphp/runtime/vm/jit/translator-instrs.h | 1 - hphp/runtime/vm/jit/translator.cpp | 5 +---- hphp/test/quick/debugger/flow_gen.php.expectf | 4 ++++ hphp/test/quick/debugger/flow_gen.php.in | 2 ++ 11 files changed, 25 insertions(+), 53 deletions(-) diff --git a/hphp/compiler/analysis/emitter.cpp b/hphp/compiler/analysis/emitter.cpp index 219c4f0bb..462914357 100644 --- a/hphp/compiler/analysis/emitter.cpp +++ b/hphp/compiler/analysis/emitter.cpp @@ -7050,12 +7050,21 @@ static void emitContinuationMethod(UnitEmitter& ue, FuncEmitter* fe, ue.emitIVA(m == METH_SEND || m == METH_RAISE); const Offset ehStart = ue.bcPos(); - static Op mOps[] = { - OpNull, - OpContSend, - OpContRaise, - }; - ue.emitOp(mOps[m]); + switch(m) { + case METH_NEXT: + ue.emitOp(OpNull); + break; + case METH_RAISE: + ue.emitOp(OpContRaise); + // intentional fallthrough to push the exception on the stack + case METH_SEND: + ue.emitOp(OpCGetL); ue.emitIVA(0); + ue.emitOp(OpUnsetL); ue.emitIVA(0); + break; + default: + not_reached(); + } + ue.emitOp(OpContEnter); ue.emitOp(OpContStopped); ue.emitOp(OpNull); diff --git a/hphp/doc/bytecode.specification b/hphp/doc/bytecode.specification index a21bc5378..48c268ab7 100644 --- a/hphp/doc/bytecode.specification +++ b/hphp/doc/bytecode.specification @@ -3732,17 +3732,10 @@ ContCheck [] -> [] object. If the continuation is finished, already running, or not yet started and is enabled, an exception will be thrown. -ContSend [] -> [C] - - Prepare continuation to receive a value. $this must be a Continuation object - that passed ContCheck check. The value in local 0 is moved to the stack - for sending to the Continuation by ContEnter. - -ContRaise [] -> [C:Obj:Exception] +ContRaise [] -> [] Prepare continuation to receive a thrown exception. $this must be a - Continuation object that passed ContCheck check. The exception in - local 0 is moved to the stack for sending to the Continuation by ContEnter. + Continuation object that passed ContCheck check. ContValid [] -> [C:Bool] diff --git a/hphp/runtime/vm/bytecode.cpp b/hphp/runtime/vm/bytecode.cpp index 0718844e1..412733f3c 100644 --- a/hphp/runtime/vm/bytecode.cpp +++ b/hphp/runtime/vm/bytecode.cpp @@ -6865,23 +6865,11 @@ inline void OPTBLD_INLINE VMExecutionContext::iopContCheck(PC& pc) { cont->preNext(); } -inline void OPTBLD_INLINE VMExecutionContext::iopContSend(PC& pc) { - NEXT(); - - // prepare value to be sent by ContEnter - tvCopy(*frame_local(m_fp, 0), *m_stack.allocTV()); - tvWriteUninit(frame_local(m_fp, 0)); -} - inline void OPTBLD_INLINE VMExecutionContext::iopContRaise(PC& pc) { NEXT(); c_Continuation* cont = this_continuation(m_fp); assert(cont->m_label); --cont->m_label; - - // prepare exception to be sent by ContEnter - tvCopy(*frame_local(m_fp, 0), *m_stack.allocTV()); - tvWriteUninit(frame_local(m_fp, 0)); } inline void OPTBLD_INLINE VMExecutionContext::iopContValid(PC& pc) { diff --git a/hphp/runtime/vm/hhbc.h b/hphp/runtime/vm/hhbc.h index 5054a7a4b..9bf90867d 100644 --- a/hphp/runtime/vm/hhbc.h +++ b/hphp/runtime/vm/hhbc.h @@ -553,8 +553,7 @@ enum SetOpOp { O(ContSuspendK, ONE(IVA), TWO(CV,CV), NOV, CF) \ O(ContRetC, NA, ONE(CV), NOV, CF_TF) \ O(ContCheck, ONE(IVA), NOV, NOV, NF) \ - O(ContSend, NA, NOV, ONE(CV), NF) \ - O(ContRaise, NA, NOV, ONE(CV), NF) \ + O(ContRaise, NA, NOV, NOV, NF) \ O(ContValid, NA, NOV, ONE(CV), NF) \ O(ContKey, NA, NOV, ONE(CV), NF) \ O(ContCurrent, NA, NOV, ONE(CV), NF) \ diff --git a/hphp/runtime/vm/jit/hhbctranslator.cpp b/hphp/runtime/vm/jit/hhbctranslator.cpp index 4e04d86a0..db4370a40 100644 --- a/hphp/runtime/vm/jit/hhbctranslator.cpp +++ b/hphp/runtime/vm/jit/hhbctranslator.cpp @@ -1190,24 +1190,12 @@ void HhbcTranslator::emitContCheck(bool checkStarted) { gen(ContPreNext, getExitSlowTrace(), cont); } -void HhbcTranslator::emitContSend() { - assert(curClass()); - - // prepare value to be sent by ContEnter - push(gen(LdLoc, Type::Cell, LocalId(0), m_tb->fp())); - gen(StLoc, LocalId(0), m_tb->fp(), m_tb->genDefUninit()); -} - void HhbcTranslator::emitContRaise() { assert(curClass()); SSATmp* cont = gen(LdThis, m_tb->fp()); SSATmp* label = gen(LdRaw, Type::Int, cont, cns(RawMemSlot::ContLabel)); label = gen(OpSub, label, cns(1)); gen(StRaw, cont, cns(RawMemSlot::ContLabel), label); - - // prepare value to be sent by ContEnter - push(gen(LdLoc, Type::Cell, LocalId(0), m_tb->fp())); - gen(StLoc, LocalId(0), m_tb->fp(), m_tb->genDefUninit()); } void HhbcTranslator::emitContValid() { @@ -3339,8 +3327,6 @@ uint32_t localOutputId(const NormalizedInstruction& inst) { case OpUnpackCont: case OpContSuspend: case OpContRetC: - case OpContSend: - case OpContRaise: return 0; case OpSetWithRefLM: diff --git a/hphp/runtime/vm/jit/hhbctranslator.h b/hphp/runtime/vm/jit/hhbctranslator.h index 200b36f25..df160c601 100644 --- a/hphp/runtime/vm/jit/hhbctranslator.h +++ b/hphp/runtime/vm/jit/hhbctranslator.h @@ -381,7 +381,6 @@ struct HhbcTranslator { void emitContSuspendK(int64_t labelId); void emitContRetC(); void emitContCheck(bool checkStarted); - void emitContSend(); void emitContRaise(); void emitContValid(); void emitContKey(); diff --git a/hphp/runtime/vm/jit/irtranslator.cpp b/hphp/runtime/vm/jit/irtranslator.cpp index 3c845b5b7..013612ee5 100644 --- a/hphp/runtime/vm/jit/irtranslator.cpp +++ b/hphp/runtime/vm/jit/irtranslator.cpp @@ -568,10 +568,6 @@ void Translator::translateContCheck(const NormalizedInstruction& i) { HHIR_EMIT(ContCheck, i.imm[0].u_IVA); } -void Translator::translateContSend(const NormalizedInstruction& i) { - HHIR_EMIT(ContSend); -} - void Translator::translateContRaise(const NormalizedInstruction& i) { HHIR_EMIT(ContRaise); } diff --git a/hphp/runtime/vm/jit/translator-instrs.h b/hphp/runtime/vm/jit/translator-instrs.h index e8b081c5b..9fd4fd6d4 100644 --- a/hphp/runtime/vm/jit/translator-instrs.h +++ b/hphp/runtime/vm/jit/translator-instrs.h @@ -134,7 +134,6 @@ CASE(ContSuspendK) \ CASE(ContRetC) \ CASE(ContCheck) \ - CASE(ContSend) \ CASE(ContRaise) \ CASE(ContValid) \ CASE(ContKey) \ diff --git a/hphp/runtime/vm/jit/translator.cpp b/hphp/runtime/vm/jit/translator.cpp index dcd3da942..65c3f6c52 100644 --- a/hphp/runtime/vm/jit/translator.cpp +++ b/hphp/runtime/vm/jit/translator.cpp @@ -1270,8 +1270,7 @@ static const struct { { OpContSuspendK,{Local|StackTop2, None, OutNone, -2 }}, { OpContRetC, {Local|Stack1, None, OutNone, -1 }}, { OpContCheck, {None, None, OutNone, 0 }}, - { OpContSend, {Local, Stack1, OutUnknown, 1 }}, - { OpContRaise, {Local, Stack1, OutUnknown, 1 }}, + { OpContRaise, {None, None, OutNone, 0 }}, { OpContValid, {None, Stack1, OutBoolean, 1 }}, { OpContKey, {None, Stack1, OutUnknown, 1 }}, { OpContCurrent, {None, Stack1, OutUnknown, 1 }}, @@ -1841,8 +1840,6 @@ void Translator::getInputs(SrcKey startSk, case OpContSuspend: case OpContSuspendK: case OpContRetC: - case OpContSend: - case OpContRaise: loc = 0; break; diff --git a/hphp/test/quick/debugger/flow_gen.php.expectf b/hphp/test/quick/debugger/flow_gen.php.expectf index d9615da5c..c7b243013 100644 --- a/hphp/test/quick/debugger/flow_gen.php.expectf +++ b/hphp/test/quick/debugger/flow_gen.php.expectf @@ -53,6 +53,8 @@ Break at Continuation::send() step Break at Continuation::send() step +Break at Continuation::send() +step Break at genFoo$continuation() on line 11 of %s/flow_gen.php 10 11 function genFoo($a) { @@ -112,6 +114,8 @@ Break at Continuation::send() step Break at Continuation::send() step +Break at Continuation::send() +step Break at genFoo$continuation() on line 11 of %s/flow_gen.php 10 11 function genFoo($a) { diff --git a/hphp/test/quick/debugger/flow_gen.php.in b/hphp/test/quick/debugger/flow_gen.php.in index 23cd686b3..0003e68ea 100644 --- a/hphp/test/quick/debugger/flow_gen.php.in +++ b/hphp/test/quick/debugger/flow_gen.php.in @@ -12,6 +12,7 @@ step step step step +step next next next @@ -23,6 +24,7 @@ step step step step +step next next next