From 8580e9586003b41dfd26b6c15fc49da12dc4cf1e Mon Sep 17 00:00:00 2001 From: Aaron Orenstein Date: Mon, 7 Nov 2022 11:25:20 -0800 Subject: [PATCH] Support for some missing instructions Summary: - Exit - Sub Reviewed By: edwinsmith Differential Revision: D41082845 fbshipit-source-id: e33577c411cb01c54513ee89c9d6c910e28d80ca --- .../hack/src/hackc/ir/conversions/textual/decls.rs | 2 ++ hphp/hack/src/hackc/ir/conversions/textual/hack.rs | 2 ++ .../hackc/ir/conversions/textual/lower/instrs.rs | 26 +++++++++++++--------- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/hphp/hack/src/hackc/ir/conversions/textual/decls.rs b/hphp/hack/src/hackc/ir/conversions/textual/decls.rs index 85dec5ee9b2..0692b7d5b72 100644 --- a/hphp/hack/src/hackc/ir/conversions/textual/decls.rs +++ b/hphp/hack/src/hackc/ir/conversions/textual/decls.rs @@ -68,6 +68,8 @@ pub fn write_decls(w: &mut dyn std::io::Write) -> Result<()> { | Hhbc::Modulo | Hhbc::Sub => declare_function(w, &name, &[ty!(mixed), ty!(mixed)], ty!(mixed))?, + Hhbc::Exit => declare_function(w, &name, &[ty!(mixed)], ty!(noreturn))?, + Hhbc::IsTypeInt | Hhbc::IsTypeNull | Hhbc::IsTypeStr => { declare_function(w, &name, &[ty!(mixed)], ty!(bool))? } diff --git a/hphp/hack/src/hackc/ir/conversions/textual/hack.rs b/hphp/hack/src/hackc/ir/conversions/textual/hack.rs index e349f450701..c87660bcf62 100644 --- a/hphp/hack/src/hackc/ir/conversions/textual/hack.rs +++ b/hphp/hack/src/hackc/ir/conversions/textual/hack.rs @@ -43,6 +43,8 @@ pub(crate) enum Hhbc { CmpNeq, #[strum(props(Function = "hhbc_cmp_same"))] CmpSame, + #[strum(props(Function = "hhbc_exit"))] + Exit, #[strum(props(Function = "hhbc_is_type_int"))] IsTypeInt, #[strum(props(Function = "hhbc_is_type_null"))] diff --git a/hphp/hack/src/hackc/ir/conversions/textual/lower/instrs.rs b/hphp/hack/src/hackc/ir/conversions/textual/lower/instrs.rs index 942c5168eff..088972855c0 100644 --- a/hphp/hack/src/hackc/ir/conversions/textual/lower/instrs.rs +++ b/hphp/hack/src/hackc/ir/conversions/textual/lower/instrs.rs @@ -8,6 +8,7 @@ use ir::instr::CmpOp; use ir::instr::HasLoc; use ir::instr::HasOperands; use ir::instr::Hhbc; +use ir::instr::Terminator; use ir::Func; use ir::FuncBuilder; use ir::FuncBuilderEx as _; @@ -48,7 +49,7 @@ struct LowerInstrs<'a> { } impl LowerInstrs<'_> { - fn handle_with_builtin(&self, builder: &mut FuncBuilder<'_>, instr: &Instr) -> Instr { + fn handle_with_builtin(&self, builder: &mut FuncBuilder<'_>, instr: &Instr) -> Option { let builtin = match instr { Instr::Hhbc(Hhbc::CmpOp(_, CmpOp::Eq, _)) => hack::Builtin::Hhbc(hack::Hhbc::CmpEq), Instr::Hhbc(Hhbc::CmpOp(_, CmpOp::Gt, _)) => hack::Builtin::Hhbc(hack::Hhbc::CmpGt), @@ -86,9 +87,10 @@ impl LowerInstrs<'_> { Instr::Hhbc(Hhbc::NewObjS(..)) => hack::Builtin::Hhbc(hack::Hhbc::NewObj), Instr::Hhbc(Hhbc::Not(..)) => hack::Builtin::Hhbc(hack::Hhbc::Not), Instr::Hhbc(Hhbc::Print(..)) => hack::Builtin::Hhbc(hack::Hhbc::Print), - _ => unreachable!("Unhandled Instr: {instr:#?}"), + Instr::Hhbc(Hhbc::Sub(..)) => hack::Builtin::Hhbc(hack::Hhbc::Sub), + _ => return None, }; - builder.hack_builtin(builtin, instr.operands(), instr.loc_id()) + Some(builder.hack_builtin(builtin, instr.operands(), instr.loc_id())) } fn verify_ret_type_c(&self, builder: &mut FuncBuilder<'_>, vid: ValueId, loc: LocId) -> Instr { @@ -108,15 +110,12 @@ impl LowerInstrs<'_> { impl TransformInstr for LowerInstrs<'_> { fn apply(&mut self, _iid: InstrId, instr: Instr, builder: &mut FuncBuilder<'_>) -> Instr { + if let Some(instr) = self.handle_with_builtin(builder, &instr) { + self.changed = true; + return instr; + } + let instr = match instr { - Instr::Hhbc( - Hhbc::CmpOp(..) - | Hhbc::IsTypeC(..) - | Hhbc::Modulo(..) - | Hhbc::NewObjS(..) - | Hhbc::Not(..) - | Hhbc::Print(..), - ) => self.handle_with_builtin(builder, &instr), Instr::Hhbc(Hhbc::LateBoundCls(loc)) => { if self.method_info.unwrap().is_static { let this = builder.emit(Instr::Hhbc(Hhbc::This(loc))); @@ -126,6 +125,11 @@ impl TransformInstr for LowerInstrs<'_> { builder.hack_builtin(hack::Builtin::GetStaticClass, &[this], loc) } } + Instr::Terminator(Terminator::Exit(..)) => { + let builtin = hack::Builtin::Hhbc(hack::Hhbc::Exit); + builder.emit_hack_builtin(builtin, instr.operands(), instr.loc_id()); + Instr::unreachable() + } Instr::Hhbc(Hhbc::VerifyRetTypeC(vid, loc)) => { self.verify_ret_type_c(builder, vid, loc) } -- 2.11.4.GIT