From 7eda5427555d7c60a256b6ebcd62428cc1433160 Mon Sep 17 00:00:00 2001 From: Bruce Forstall Date: Mon, 1 May 2017 17:59:38 -0700 Subject: [PATCH] Refactor GT_RETURNTRAP Commit migrated from https://github.com/dotnet/coreclr/commit/9dd6896c63be093b785014ace188d7c1927be7de --- src/coreclr/src/jit/codegenarm.cpp | 49 ++++++++++++++++++++++-------------- src/coreclr/src/jit/codegenarm64.cpp | 47 +++++++++++++++++++++------------- src/coreclr/src/jit/codegenlinear.h | 2 ++ 3 files changed, 61 insertions(+), 37 deletions(-) diff --git a/src/coreclr/src/jit/codegenarm.cpp b/src/coreclr/src/jit/codegenarm.cpp index 019641e..7c053a3 100644 --- a/src/coreclr/src/jit/codegenarm.cpp +++ b/src/coreclr/src/jit/codegenarm.cpp @@ -647,25 +647,8 @@ void CodeGen::genCodeForTreeNode(GenTreePtr treeNode) break; case GT_RETURNTRAP: - { - // this is nothing but a conditional call to CORINFO_HELP_STOP_FOR_GC - // based on the contents of 'data' - - GenTree* data = treeNode->gtOp.gtOp1->gtEffectiveVal(); - genConsumeIfReg(data); - GenTreeIntCon cns = intForm(TYP_INT, 0); - emit->emitInsBinary(INS_cmp, emitTypeSize(TYP_INT), data, &cns); - - BasicBlock* skipLabel = genCreateTempLabel(); - - emitJumpKind jmpEqual = genJumpKindForOper(GT_EQ, CK_SIGNED); - inst_JMP(jmpEqual, skipLabel); - // emit the call to the EE-helper that stops for GC (or other reasons) - - genEmitHelperCall(CORINFO_HELP_STOP_FOR_GC, 0, EA_UNKNOWN); - genDefineTempLabel(skipLabel); - } - break; + genCodeForReturnTrap(treeNode->AsOp()); + break; case GT_STOREIND: genCodeForStoreInd(treeNode->AsStoreInd()); @@ -1577,6 +1560,34 @@ void CodeGen::genLeaInstruction(GenTreeAddrMode* lea) } //------------------------------------------------------------------------ +// genCodeForReturnTrap: Produce code for a GT_RETURNTRAP node. +// +// Arguments: +// tree - the GT_RETURNTRAP node +// +void CodeGen::genCodeForReturnTrap(GenTreeOp* tree) +{ + assert(tree->OperGet() == GT_RETURNTRAP); + + // this is nothing but a conditional call to CORINFO_HELP_STOP_FOR_GC + // based on the contents of 'data' + + GenTree* data = tree->gtOp1->gtEffectiveVal(); + genConsumeIfReg(data); + GenTreeIntCon cns = intForm(TYP_INT, 0); + getEmitter()->emitInsBinary(INS_cmp, emitTypeSize(TYP_INT), data, &cns); + + BasicBlock* skipLabel = genCreateTempLabel(); + + emitJumpKind jmpEqual = genJumpKindForOper(GT_EQ, CK_SIGNED); + inst_JMP(jmpEqual, skipLabel); + // emit the call to the EE-helper that stops for GC (or other reasons) + + genEmitHelperCall(CORINFO_HELP_STOP_FOR_GC, 0, EA_UNKNOWN); + genDefineTempLabel(skipLabel); +} + +//------------------------------------------------------------------------ // genCodeForStoreInd: Produce code for a GT_STOREIND node. // // Arguments: diff --git a/src/coreclr/src/jit/codegenarm64.cpp b/src/coreclr/src/jit/codegenarm64.cpp index 8deeff3..f47e79d 100644 --- a/src/coreclr/src/jit/codegenarm64.cpp +++ b/src/coreclr/src/jit/codegenarm64.cpp @@ -2440,24 +2440,8 @@ void CodeGen::genCodeForTreeNode(GenTreePtr treeNode) break; case GT_RETURNTRAP: - { - // this is nothing but a conditional call to CORINFO_HELP_STOP_FOR_GC - // based on the contents of 'data' - - GenTree* data = treeNode->gtOp.gtOp1; - genConsumeRegs(data); - emit->emitIns_R_I(INS_cmp, EA_4BYTE, data->gtRegNum, 0); - - BasicBlock* skipLabel = genCreateTempLabel(); - - emitJumpKind jmpEqual = genJumpKindForOper(GT_EQ, CK_SIGNED); - inst_JMP(jmpEqual, skipLabel); - // emit the call to the EE-helper that stops for GC (or other reasons) - - genEmitHelperCall(CORINFO_HELP_STOP_FOR_GC, 0, EA_UNKNOWN); - genDefineTempLabel(skipLabel); - } - break; + genCodeForReturnTrap(treeNode->AsOp()); + break; case GT_STOREIND: genCodeForStoreInd(treeNode->AsStoreInd()); @@ -4019,6 +4003,33 @@ void CodeGen::genLeaInstruction(GenTreeAddrMode* lea) } //------------------------------------------------------------------------ +// genCodeForReturnTrap: Produce code for a GT_RETURNTRAP node. +// +// Arguments: +// tree - the GT_RETURNTRAP node +// +void CodeGen::genCodeForReturnTrap(GenTreeOp* tree) +{ + assert(tree->OperGet() == GT_RETURNTRAP); + + // this is nothing but a conditional call to CORINFO_HELP_STOP_FOR_GC + // based on the contents of 'data' + + GenTree* data = tree->gtOp1; + genConsumeRegs(data); + getEmitter()->emitIns_R_I(INS_cmp, EA_4BYTE, data->gtRegNum, 0); + + BasicBlock* skipLabel = genCreateTempLabel(); + + emitJumpKind jmpEqual = genJumpKindForOper(GT_EQ, CK_SIGNED); + inst_JMP(jmpEqual, skipLabel); + // emit the call to the EE-helper that stops for GC (or other reasons) + + genEmitHelperCall(CORINFO_HELP_STOP_FOR_GC, 0, EA_UNKNOWN); + genDefineTempLabel(skipLabel); +} + +//------------------------------------------------------------------------ // genCodeForStoreInd: Produce code for a GT_STOREIND node. // // Arguments: diff --git a/src/coreclr/src/jit/codegenlinear.h b/src/coreclr/src/jit/codegenlinear.h index 89322a9..1d711e3 100644 --- a/src/coreclr/src/jit/codegenlinear.h +++ b/src/coreclr/src/jit/codegenlinear.h @@ -174,6 +174,8 @@ void genCodeForStoreLclFld(GenTreeLclFld* tree); void genCodeForStoreLclVar(GenTreeLclVar* tree); +void genCodeForReturnTrap(GenTreeOp* tree); + void genCodeForStoreInd(GenTreeStoreInd* tree); void genCodeForCpObj(GenTreeObj* cpObjNode); -- 2.7.4