diff options
author | Jan Kotas <jkotas@microsoft.com> | 2016-01-24 21:43:42 -0800 |
---|---|---|
committer | Jan Kotas <jkotas@microsoft.com> | 2016-01-24 21:43:42 -0800 |
commit | dbe16c169ad9c10a48acee89d424852458cb5ca0 (patch) | |
tree | 627c13f0b69349381f98ce58da95c464a2ae04b9 /src | |
parent | 9489767df726d4bde4900c56734b19fecea087cd (diff) | |
download | coreclr-dbe16c169ad9c10a48acee89d424852458cb5ca0.tar.gz coreclr-dbe16c169ad9c10a48acee89d424852458cb5ca0.tar.bz2 coreclr-dbe16c169ad9c10a48acee89d424852458cb5ca0.zip |
Revert "Generate P/Invoke transitions for CoreRT."
Diffstat (limited to 'src')
-rw-r--r-- | src/inc/corinfo.h | 20 | ||||
-rw-r--r-- | src/inc/corjit.h | 8 | ||||
-rw-r--r-- | src/inc/jithelpers.h | 3 | ||||
-rw-r--r-- | src/jit/codegencommon.cpp | 24 | ||||
-rw-r--r-- | src/jit/codegenlegacy.cpp | 14 | ||||
-rw-r--r-- | src/jit/compiler.h | 4 | ||||
-rw-r--r-- | src/jit/flowgraph.cpp | 12 | ||||
-rw-r--r-- | src/jit/gentree.h | 2 | ||||
-rw-r--r-- | src/jit/lclvars.cpp | 80 | ||||
-rw-r--r-- | src/jit/liveness.cpp | 115 | ||||
-rw-r--r-- | src/jit/lower.cpp | 96 | ||||
-rw-r--r-- | src/jit/regalloc.cpp | 20 | ||||
-rw-r--r-- | src/vm/jitinterface.cpp | 14 | ||||
-rw-r--r-- | src/vm/jitinterface.h | 2 | ||||
-rw-r--r-- | src/zap/zapinfo.cpp | 13 | ||||
-rw-r--r-- | src/zap/zapinfo.h | 4 |
16 files changed, 159 insertions, 272 deletions
diff --git a/src/inc/corinfo.h b/src/inc/corinfo.h index f6481a7e39..fef412678a 100644 --- a/src/inc/corinfo.h +++ b/src/inc/corinfo.h @@ -232,11 +232,11 @@ TODO: Talk about initializing strutures before use #if COR_JIT_EE_VERSION > 460 // Update this one -SELECTANY const GUID JITEEVersionIdentifier = { /* b26841f8-74d6-4fc9-9d81-6500cd662549 */ - 0xb26841f8, - 0x74d6, - 0x4fc9, - { 0x9d, 0x81, 0x65, 0x0, 0xcd, 0x66, 0x25, 0x49 } +SELECTANY const GUID JITEEVersionIdentifier = { /* f7be09f3-9ca7-42fd-b0ca-f97c0499f5a3 */ + 0xf7be09f3, + 0x9ca7, + 0x42fd, + {0xb0, 0xca, 0xf9, 0x7c, 0x04, 0x99, 0xf5, 0xa3} }; #else @@ -695,9 +695,6 @@ enum CorInfoHelpFunc CORINFO_HELP_THROW_ARGUMENTOUTOFRANGEEXCEPTION, // throw ArgumentOutOfRangeException #endif - CORINFO_HELP_JIT_PINVOKE_BEGIN, // Transition to preemptive mode before a P/Invoke, frame is the first argument - CORINFO_HELP_JIT_PINVOKE_END, // Transition to cooperative mode after a P/Invoke, frame is the first argument - CORINFO_HELP_COUNT, }; @@ -3647,9 +3644,10 @@ public: ) = 0; // return address of fixup area for late-bound PInvoke calls. - virtual void getAddressOfPInvokeFixup( - CORINFO_METHOD_HANDLE method, - CORINFO_CONST_LOOKUP *pLookup) = 0; + virtual void* getAddressOfPInvokeFixup( + CORINFO_METHOD_HANDLE method, + void **ppIndirection = NULL + ) = 0; // Generate a cookie based on the signature that would needs to be passed // to CORINFO_HELP_PINVOKE_CALLI diff --git a/src/inc/corjit.h b/src/inc/corjit.h index 4313e2e38a..8612d954df 100644 --- a/src/inc/corjit.h +++ b/src/inc/corjit.h @@ -124,15 +124,17 @@ enum CorJitFlag #ifdef MDIL CORJIT_FLG_MDIL = 0x00004000, // Generate MDIL code instead of machine code +#else // MDIL + CORJIT_FLG_UNUSED7 = 0x00004000, +#endif // MDIL +#ifdef MDIL // Safe to overlap with CORJIT_FLG_MAKEFINALCODE below. Not used by the JIT, used internally by NGen only. CORJIT_FLG_MINIMAL_MDIL = 0x00008000, // Generate MDIL code suitable for use to bind other assemblies. // Safe to overlap with CORJIT_FLG_READYTORUN below. Not used by the JIT, used internally by NGen only. CORJIT_FLG_NO_MDIL = 0x00010000, // Generate an MDIL section but no code or CTL. Not used by the JIT, used internally by NGen only. -#else // MDIL - CORJIT_FLG_PINVOKE_USE_HELPERS = 0x00004000, // Use JIT_PINVOKE_{BEGIN,END} helpers instead of generating transitions inline. -#endif +#endif // MDIL #if defined(FEATURE_INTERPRETER) CORJIT_FLG_MAKEFINALCODE = 0x00008000, // Use the final code generator, i.e., not the interpreter. diff --git a/src/inc/jithelpers.h b/src/inc/jithelpers.h index eac9c45151..bd3ad544fb 100644 --- a/src/inc/jithelpers.h +++ b/src/inc/jithelpers.h @@ -403,9 +403,6 @@ #endif // COR_JIT_EE_VERSION - JITHELPER1(CORINFO_HELP_JIT_PINVOKE_BEGIN, NULL, CORINFO_HELP_SIG_UNDEF, MDIL_HELP_UNDEF) - JITHELPER1(CORINFO_HELP_JIT_PINVOKE_END, NULL, CORINFO_HELP_SIG_UNDEF, MDIL_HELP_UNDEF) - #undef JITHELPER1 #undef DYNAMICJITHELPER1 #undef JITHELPER diff --git a/src/jit/codegencommon.cpp b/src/jit/codegencommon.cpp index 71b324327e..4830342e84 100644 --- a/src/jit/codegencommon.cpp +++ b/src/jit/codegencommon.cpp @@ -7557,7 +7557,6 @@ void CodeGen::genPrologPadForReJit() regMaskTP CodeGen::genPInvokeMethodProlog(regMaskTP initRegs) { assert(compiler->compGeneratingProlog); - noway_assert(!compiler->opts.ShouldUsePInvokeHelpers()); noway_assert(compiler->info.compCallUnmanaged); CORINFO_EE_INFO * pInfo = compiler->eeGetEEInfo(); @@ -7777,7 +7776,6 @@ regMaskTP CodeGen::genPInvokeMethodProlog(regMaskTP initRegs) void CodeGen::genPInvokeMethodEpilog() { noway_assert(compiler->info.compCallUnmanaged); - noway_assert(!compiler->opts.ShouldUsePInvokeHelpers()); noway_assert(compiler->compCurBB == compiler->genReturnBB || (compiler->compTailCallUsed && (compiler->compCurBB->bbJumpKind == BBJ_THROW)) || (compiler->compJmpOpUsed && (compiler->compCurBB->bbFlags & BBF_HAS_JMP))); @@ -8519,23 +8517,13 @@ void CodeGen::genFnProlog() // since they are trashed by the jithelper call to setup the PINVOKE frame if (compiler->info.compCallUnmanaged) { - excludeMask |= RBM_PINVOKE_FRAME; + excludeMask |= (RBM_PINVOKE_FRAME | RBM_PINVOKE_TCB | RBM_PINVOKE_SCRATCH); - assert(!compiler->opts.ShouldUsePInvokeHelpers() || compiler->info.compLvFrameListRoot == BAD_VAR_NUM); - if (!compiler->opts.ShouldUsePInvokeHelpers()) - { - noway_assert(compiler->info.compLvFrameListRoot < compiler->lvaCount); - - excludeMask |= (RBM_PINVOKE_TCB | RBM_PINVOKE_SCRATCH); - - // We also must exclude the register used by compLvFrameListRoot when it is enregistered - // - LclVarDsc * varDsc = &compiler->lvaTable[compiler->info.compLvFrameListRoot]; - if (varDsc->lvRegister) - { - excludeMask |= genRegMask(varDsc->lvRegNum); - } - } + // We also must exclude the register used by compLvFrameListRoot when it is enregistered + // + LclVarDsc * varDsc = &compiler->lvaTable[compiler->info.compLvFrameListRoot]; + if (varDsc->lvRegister) + excludeMask |= genRegMask(varDsc->lvRegNum); } #endif // INLINE_NDIRECT diff --git a/src/jit/codegenlegacy.cpp b/src/jit/codegenlegacy.cpp index 233c1631df..5d518a1e19 100644 --- a/src/jit/codegenlegacy.cpp +++ b/src/jit/codegenlegacy.cpp @@ -19684,15 +19684,15 @@ regMaskTP CodeGen::genCodeForCall(GenTreePtr call, else { noway_assert(callType == CT_USER_FUNC); - - CORINFO_CONST_LOOKUP lookup; - comp->info.compCompHnd->getAddressOfPInvokeFixup(methHnd, &lookup); - if (lookup.accessType == IAT_PVALUE) + + void* pAddr; + addr = compiler->info.compCompHnd->getAddressOfPInvokeFixup(methHnd, (void**)&pAddr); + if (addr != NULL) { #if CPU_LOAD_STORE_ARCH // Load the address into a register, indirect it and call through a register indCallReg = regSet.rsGrabReg(RBM_ALLINT); // Grab an available register to use for the CALL indirection - instGen_Set_Reg_To_Imm(EA_HANDLE_CNS_RELOC, indCallReg, (ssize_t)lookup.addr); + instGen_Set_Reg_To_Imm(EA_HANDLE_CNS_RELOC, indCallReg, (ssize_t)addr); getEmitter()->emitIns_R_R_I(INS_ldr, EA_PTRSIZE, indCallReg, indCallReg, 0); regTracker.rsTrackRegTrash(indCallReg); // Now make the call "call indCallReg" @@ -19718,14 +19718,12 @@ regMaskTP CodeGen::genCodeForCall(GenTreePtr call, } else { - assert(lookup.accessType == IAT_PPVALUE); - // Double-indirection. Load the address into a register // and call indirectly through a register indCallReg = regSet.rsGrabReg(RBM_ALLINT); // Grab an available register to use for the CALL indirection #if CPU_LOAD_STORE_ARCH - instGen_Set_Reg_To_Imm(EA_HANDLE_CNS_RELOC, indCallReg, (ssize_t)lookup.addr); + instGen_Set_Reg_To_Imm(EA_HANDLE_CNS_RELOC, indCallReg, (ssize_t)pAddr); getEmitter()->emitIns_R_R_I(INS_ldr, EA_PTRSIZE, indCallReg, indCallReg, 0); getEmitter()->emitIns_R_R_I(INS_ldr, EA_PTRSIZE, indCallReg, indCallReg, 0); regTracker.rsTrackRegTrash(indCallReg); diff --git a/src/jit/compiler.h b/src/jit/compiler.h index b9babbddbc..71cb1a30cd 100644 --- a/src/jit/compiler.h +++ b/src/jit/compiler.h @@ -7527,10 +7527,6 @@ public : inline bool IsReadyToRun() { return false; } #endif - // true if we should use the PINVOKE_{BEGIN,END} helpers instead of generating - // PInvoke transitions inline (e.g. when targeting CoreRT). - inline bool ShouldUsePInvokeHelpers() { return (eeFlags & CORJIT_FLG_PINVOKE_USE_HELPERS) != 0; } - // true if we must generate compatible code with Jit64 quirks inline bool IsJit64Compat() { diff --git a/src/jit/flowgraph.cpp b/src/jit/flowgraph.cpp index 8cdbd96c70..39fd0a6f49 100644 --- a/src/jit/flowgraph.cpp +++ b/src/jit/flowgraph.cpp @@ -8237,12 +8237,7 @@ void Compiler::fgAddInternal() #if INLINE_NDIRECT if (info.compCallUnmanaged != 0) { - // The P/Invoke helpers only require a frame variable, so only allocate the - // TCB variable if we're not using them. - if (!opts.ShouldUsePInvokeHelpers()) - { - info.compLvFrameListRoot = lvaGrabTemp(false DEBUGARG("Pinvoke FrameListRoot")); - } + info.compLvFrameListRoot = lvaGrabTemp(false DEBUGARG("Pinvoke FrameListRoot")); lvaInlinedPInvokeFrameVar = lvaGrabTempWithImplicitUse(false DEBUGARG("Pinvoke FrameVar")); @@ -8253,9 +8248,8 @@ void Compiler::fgAddInternal() varDsc->lvExactSize = eeGetEEInfo()->inlinedCallFrameInfo.size; #if FEATURE_FIXED_OUT_ARGS // Grab and reserve space for TCB, Frame regs used in PInvoke epilog to pop the inlined frame. - // See genPInvokeMethodEpilog() for use of the grabbed var. This is only necessary if we are - // not using the P/Invoke helpers. - if (!opts.ShouldUsePInvokeHelpers() && compJmpOpUsed) + // See genPInvokeMethodEpilog() for use of the grabbed var. + if (compJmpOpUsed) { lvaPInvokeFrameRegSaveVar = lvaGrabTempWithImplicitUse(false DEBUGARG("PInvokeFrameRegSave Var")); varDsc = &lvaTable[lvaPInvokeFrameRegSaveVar]; diff --git a/src/jit/gentree.h b/src/jit/gentree.h index c41e15209b..9756dcbd6a 100644 --- a/src/jit/gentree.h +++ b/src/jit/gentree.h @@ -2108,7 +2108,7 @@ struct GenTreeLclVar: public GenTreeLclVarCommon DEBUG_ARG(largeNode)), gtLclILoffs(ilOffs) { - assert(OperIsLocal(oper) || OperIsLocalAddr(oper)); + assert(OperIsLocal(oper)); } #if DEBUGGABLE_GENTREE diff --git a/src/jit/lclvars.cpp b/src/jit/lclvars.cpp index 024fb41fa3..afe8aaf408 100644 --- a/src/jit/lclvars.cpp +++ b/src/jit/lclvars.cpp @@ -2159,21 +2159,17 @@ void Compiler::lvaDecRefCnts(GenTreePtr tree) if ((tree->gtOper == GT_CALL) && (tree->gtFlags & GTF_CALL_UNMANAGED)) { - assert(!opts.ShouldUsePInvokeHelpers() || info.compLvFrameListRoot == BAD_VAR_NUM); - if (!opts.ShouldUsePInvokeHelpers()) - { - /* Get the special variable descriptor */ - - lclNum = info.compLvFrameListRoot; - - noway_assert(lclNum <= lvaCount); - varDsc = lvaTable + lclNum; + /* Get the special variable descriptor */ - /* Decrement the reference counts twice */ + lclNum = info.compLvFrameListRoot; + + noway_assert(lclNum <= lvaCount); + varDsc = lvaTable + lclNum; + + /* Decrement the reference counts twice */ - varDsc->decRefCnts(compCurBB->getBBWeight(this), this); - varDsc->decRefCnts(compCurBB->getBBWeight(this), this); - } + varDsc->decRefCnts(compCurBB->getBBWeight(this), this); + varDsc->decRefCnts(compCurBB->getBBWeight(this), this); } else { @@ -2218,21 +2214,17 @@ void Compiler::lvaIncRefCnts(GenTreePtr tree) if ((tree->gtOper == GT_CALL) && (tree->gtFlags & GTF_CALL_UNMANAGED)) { - assert(!opts.ShouldUsePInvokeHelpers() || info.compLvFrameListRoot == BAD_VAR_NUM); - if (!opts.ShouldUsePInvokeHelpers()) - { - /* Get the special variable descriptor */ - - lclNum = info.compLvFrameListRoot; - - noway_assert(lclNum <= lvaCount); - varDsc = lvaTable + lclNum; + /* Get the special variable descriptor */ - /* Increment the reference counts twice */ + lclNum = info.compLvFrameListRoot; + + noway_assert(lclNum <= lvaCount); + varDsc = lvaTable + lclNum; + + /* Increment the reference counts twice */ - varDsc->incRefCnts(compCurBB->getBBWeight(this), this); - varDsc->incRefCnts(compCurBB->getBBWeight(this), this); - } + varDsc->incRefCnts(compCurBB->getBBWeight(this), this); + varDsc->incRefCnts(compCurBB->getBBWeight(this), this); } else { @@ -2808,20 +2800,16 @@ void Compiler::lvaMarkLclRefs(GenTreePtr tree) /* Is this a call to unmanaged code ? */ if (tree->gtOper == GT_CALL && tree->gtFlags & GTF_CALL_UNMANAGED) { - assert(!opts.ShouldUsePInvokeHelpers() || info.compLvFrameListRoot == BAD_VAR_NUM); - if (!opts.ShouldUsePInvokeHelpers()) - { - /* Get the special variable descriptor */ - - unsigned lclNum = info.compLvFrameListRoot; + /* Get the special variable descriptor */ - noway_assert(lclNum <= lvaCount); - LclVarDsc * varDsc = lvaTable + lclNum; + unsigned lclNum = info.compLvFrameListRoot; + + noway_assert(lclNum <= lvaCount); + LclVarDsc * varDsc = lvaTable + lclNum; - /* Increment the ref counts twice */ - varDsc->incRefCnts(lvaMarkRefsWeight, this); - varDsc->incRefCnts(lvaMarkRefsWeight, this); - } + /* Increment the ref counts twice */ + varDsc->incRefCnts(lvaMarkRefsWeight, this); + varDsc->incRefCnts(lvaMarkRefsWeight, this); } #endif @@ -3178,19 +3166,15 @@ void Compiler::lvaMarkLocalVars() if (info.compCallUnmanaged != 0) { - assert(!opts.ShouldUsePInvokeHelpers() || info.compLvFrameListRoot == BAD_VAR_NUM); - if (!opts.ShouldUsePInvokeHelpers()) - { - noway_assert(info.compLvFrameListRoot >= info.compLocalsCount && - info.compLvFrameListRoot < lvaCount); + noway_assert(info.compLvFrameListRoot >= info.compLocalsCount && + info.compLvFrameListRoot < lvaCount); - lvaTable[info.compLvFrameListRoot].lvType = TYP_I_IMPL; + lvaTable[info.compLvFrameListRoot].lvType = TYP_I_IMPL; - /* Set the refCnt, it is used in the prolog and return block(s) */ + /* Set the refCnt, it is used in the prolog and return block(s) */ - lvaTable[info.compLvFrameListRoot].lvRefCnt = 2; - lvaTable[info.compLvFrameListRoot].lvRefCntWtd = 2 * BB_UNITY_WEIGHT; - } + lvaTable[info.compLvFrameListRoot].lvRefCnt = 2; + lvaTable[info.compLvFrameListRoot].lvRefCntWtd = 2 * BB_UNITY_WEIGHT; } #endif diff --git a/src/jit/liveness.cpp b/src/jit/liveness.cpp index 7de58587f4..fc22a69eba 100644 --- a/src/jit/liveness.cpp +++ b/src/jit/liveness.cpp @@ -437,23 +437,19 @@ void Compiler::fgPerStatementLocalVarLiveness(GenTreePtr startNode, GenTreePtr a // This ensures that the block->bbVarUse will contain // the FrameRoot local var if is it a tracked variable. - if ((tree->gtCall.IsUnmanaged() || (tree->gtCall.IsTailCall() && info.compCallUnmanaged))) + if (tree->gtCall.IsUnmanaged() || (tree->gtCall.IsTailCall() && info.compCallUnmanaged)) { - assert(!opts.ShouldUsePInvokeHelpers() || info.compLvFrameListRoot == BAD_VAR_NUM); - if (!opts.ShouldUsePInvokeHelpers()) - { - /* Get the TCB local and mark it as used */ + /* Get the TCB local and mark it as used */ - noway_assert(info.compLvFrameListRoot < lvaCount); + noway_assert(info.compLvFrameListRoot < lvaCount); - LclVarDsc* varDsc = &lvaTable[info.compLvFrameListRoot]; + LclVarDsc* varDsc = &lvaTable[info.compLvFrameListRoot]; - if (varDsc->lvTracked) + if (varDsc->lvTracked) + { + if (!VarSetOps::IsMember(this, fgCurDefSet, varDsc->lvVarIndex)) { - if (!VarSetOps::IsMember(this, fgCurDefSet, varDsc->lvVarIndex)) - { - VarSetOps::AddElemD(this, fgCurUseSet, varDsc->lvVarIndex); - } + VarSetOps::AddElemD(this, fgCurUseSet, varDsc->lvVarIndex); } } } @@ -633,21 +629,17 @@ void Compiler::fgPerBlockLocalVarLiveness() /* Get the TCB local and mark it as used */ - if (block->bbJumpKind == BBJ_RETURN && info.compCallUnmanaged) + if (block->bbJumpKind == BBJ_RETURN && info.compCallUnmanaged) { - assert(!opts.ShouldUsePInvokeHelpers() || info.compLvFrameListRoot == BAD_VAR_NUM); - if (!opts.ShouldUsePInvokeHelpers()) - { - noway_assert(info.compLvFrameListRoot < lvaCount); + noway_assert(info.compLvFrameListRoot < lvaCount); - LclVarDsc * varDsc = &lvaTable[info.compLvFrameListRoot]; + LclVarDsc * varDsc = &lvaTable[info.compLvFrameListRoot]; - if (varDsc->lvTracked) + if (varDsc->lvTracked) + { + if (!VarSetOps::IsMember(this, fgCurDefSet, varDsc->lvVarIndex)) { - if (!VarSetOps::IsMember(this, fgCurDefSet, varDsc->lvVarIndex)) - { - VarSetOps::AddElemD(this, fgCurUseSet, varDsc->lvVarIndex); - } + VarSetOps::AddElemD(this, fgCurUseSet, varDsc->lvVarIndex); } } } @@ -1750,25 +1742,21 @@ SKIP_QMARK: if (tree->gtCall.IsTailCall() && info.compCallUnmanaged) { - assert(!opts.ShouldUsePInvokeHelpers() || info.compLvFrameListRoot == BAD_VAR_NUM); - if (!opts.ShouldUsePInvokeHelpers()) - { - /* Get the TCB local and make it live */ + /* Get the TCB local and make it live */ - noway_assert(info.compLvFrameListRoot < lvaCount); + noway_assert(info.compLvFrameListRoot < lvaCount); - LclVarDsc* frameVarDsc = &lvaTable[info.compLvFrameListRoot]; + LclVarDsc* frameVarDsc = &lvaTable[info.compLvFrameListRoot]; - if (frameVarDsc->lvTracked) - { - VARSET_TP VARSET_INIT_NOCOPY(varBit, VarSetOps::MakeSingleton(this, frameVarDsc->lvVarIndex)); + if (frameVarDsc->lvTracked) + { + VARSET_TP VARSET_INIT_NOCOPY(varBit, VarSetOps::MakeSingleton(this, frameVarDsc->lvVarIndex)); - VarSetOps::AddElemD(this, life, frameVarDsc->lvVarIndex); + VarSetOps::AddElemD(this, life, frameVarDsc->lvVarIndex); - /* Record interference with other live variables */ + /* Record interference with other live variables */ - fgMarkIntf(life, varBit); - } + fgMarkIntf(life, varBit); } } @@ -1782,41 +1770,38 @@ SKIP_QMARK: if (tree->gtCall.IsUnmanaged()) { /* Get the TCB local and make it live */ - assert(!opts.ShouldUsePInvokeHelpers() || info.compLvFrameListRoot == BAD_VAR_NUM); - if (!opts.ShouldUsePInvokeHelpers()) - { - noway_assert(info.compLvFrameListRoot < lvaCount); - LclVarDsc* frameVarDsc = &lvaTable[info.compLvFrameListRoot]; + noway_assert(info.compLvFrameListRoot < lvaCount); - if (frameVarDsc->lvTracked) - { - unsigned varIndex = frameVarDsc->lvVarIndex; - noway_assert(varIndex < lvaTrackedCount); + LclVarDsc* frameVarDsc = &lvaTable[info.compLvFrameListRoot]; - // Is the variable already known to be alive? - // - if (VarSetOps::IsMember(this, life, varIndex)) - { - // Since we may call this multiple times, clear the GTF_CALL_M_FRAME_VAR_DEATH if set. - // - tree->gtCall.gtCallMoreFlags &= ~GTF_CALL_M_FRAME_VAR_DEATH; - } - else - { - // The variable is just coming to life - // Since this is a backwards walk of the trees - // that makes this change in liveness a 'last-use' - // - VarSetOps::AddElemD(this, life, varIndex); - tree->gtCall.gtCallMoreFlags |= GTF_CALL_M_FRAME_VAR_DEATH; - } + if (frameVarDsc->lvTracked) + { + unsigned varIndex = frameVarDsc->lvVarIndex; + noway_assert(varIndex < lvaTrackedCount); - // Record an interference with the other live variables + // Is the variable already known to be alive? + // + if (VarSetOps::IsMember(this, life, varIndex)) + { + // Since we may call this multiple times, clear the GTF_CALL_M_FRAME_VAR_DEATH if set. + // + tree->gtCall.gtCallMoreFlags &= ~GTF_CALL_M_FRAME_VAR_DEATH; + } + else + { + // The variable is just coming to life + // Since this is a backwards walk of the trees + // that makes this change in liveness a 'last-use' // - VARSET_TP VARSET_INIT_NOCOPY(varBit, VarSetOps::MakeSingleton(this, varIndex)); - fgMarkIntf(life, varBit); + VarSetOps::AddElemD(this, life, varIndex); + tree->gtCall.gtCallMoreFlags |= GTF_CALL_M_FRAME_VAR_DEATH; } + + // Record an interference with the other live variables + // + VARSET_TP VARSET_INIT_NOCOPY(varBit, VarSetOps::MakeSingleton(this, varIndex)); + fgMarkIntf(life, varBit); } /* Do we have any live variables? */ diff --git a/src/jit/lower.cpp b/src/jit/lower.cpp index ae02b1fc5e..68fa2c335a 100644 --- a/src/jit/lower.cpp +++ b/src/jit/lower.cpp @@ -2475,21 +2475,6 @@ void Lowering::InsertPInvokeMethodProlog() noway_assert(comp->info.compCallUnmanaged); noway_assert(comp->lvaInlinedPInvokeFrameVar != BAD_VAR_NUM); - if (comp->opts.ShouldUsePInvokeHelpers()) - { - // Initialize the P/Invoke frame by calling CORINFO_HELP_INIT_PINVOKE_FRAME - - GenTree* frameAddr = new(comp, GT_LCL_VAR_ADDR) - GenTreeLclVar(GT_LCL_VAR_ADDR, TYP_BYREF, comp->lvaInlinedPInvokeFrameVar, BAD_IL_OFFSET); - - GenTree* helperCall = comp->gtNewHelperCallNode(CORINFO_HELP_INIT_PINVOKE_FRAME, TYP_VOID, 0, comp->gtNewArgList(frameAddr)); - - GenTreeStmt* stmt = LowerMorphAndSeqTree(helperCall); - comp->fgInsertStmtAtBeg(comp->fgFirstBB, stmt); - - return; - } - CORINFO_EE_INFO* pInfo = comp->eeGetEEInfo(); const CORINFO_EE_INFO::InlinedCallFrameInfo& callFrameInfo = pInfo->inlinedCallFrameInfo; @@ -2570,11 +2555,6 @@ void Lowering::InsertPInvokeMethodEpilog(BasicBlock *returnBB assert(returnBB != nullptr); assert(comp->info.compCallUnmanaged); - if (comp->opts.ShouldUsePInvokeHelpers()) - { - return; - } - // Method doing Pinvoke calls has exactly one return block unless it has "jmp" or tail calls. #ifdef DEBUG bool endsWithTailCallOrJmp = false; @@ -2632,6 +2612,14 @@ void Lowering::InsertPInvokeMethodEpilog(BasicBlock *returnBB // field of the frame (methodHandle may be indirected & have a reloc) void Lowering::InsertPInvokeCallProlog(GenTreeCall* call) { + // emit the following sequence + // + // frame.callTarget := methodHandle + // (x86) frame.callSiteTracker = SP + // frame.callSiteReturnAddress = return address + // thread->gcState = 0 + // (non-stub) - update top Frame on TCB + // GenTree* insertBefore = call; if (call->gtCallType == CT_INDIRECT) { @@ -2645,29 +2633,6 @@ void Lowering::InsertPInvokeCallProlog(GenTreeCall* call) noway_assert(comp->lvaInlinedPInvokeFrameVar != BAD_VAR_NUM); - if (comp->opts.ShouldUsePInvokeHelpers()) - { - // First argument is the address of the frame variable. - GenTree* frameAddr = new(comp, GT_LCL_VAR_ADDR) - GenTreeLclVar(GT_LCL_VAR_ADDR, TYP_BYREF, comp->lvaInlinedPInvokeFrameVar, BAD_IL_OFFSET); - - // Insert call to CORINFO_HELP_JIT_PINVOKE_BEGIN - GenTree* helperCall = comp->gtNewHelperCallNode(CORINFO_HELP_JIT_PINVOKE_BEGIN, TYP_VOID, 0, comp->gtNewArgList(frameAddr)); - - comp->fgMorphTree(helperCall); - comp->fgInsertTreeBeforeAsEmbedded(helperCall, insertBefore, comp->compCurStmt->AsStmt(), currBlock); - return; - } - - // emit the following sequence - // - // frame.callTarget := methodHandle - // (x86) frame.callSiteTracker = SP - // frame.callSiteReturnAddress = return address - // thread->gcState = 0 - // (non-stub) - update top Frame on TCB - // - // ---------------------------------------------------------------------------------- // Setup frame.callSiteTarget (what it referred to in the JIT) // The actual field is Frame.m_Datum which has many different uses and meanings. @@ -2786,26 +2751,10 @@ void Lowering::InsertPInvokeCallProlog(GenTreeCall* call) comp->fgInsertTreeBeforeAsEmbedded(storeGCState, insertBefore, comp->compCurStmt->AsStmt(), currBlock); } + // insert the code that goes after every inlined pinvoke call void Lowering::InsertPInvokeCallEpilog(GenTreeCall* call) { - if (comp->opts.ShouldUsePInvokeHelpers()) - { - noway_assert(comp->lvaInlinedPInvokeFrameVar != BAD_VAR_NUM); - - // First argument is the address of the frame variable. - GenTree* frameAddr = new(comp, GT_LCL_VAR) - GenTreeLclVar(GT_LCL_VAR, TYP_BYREF, comp->lvaInlinedPInvokeFrameVar, BAD_IL_OFFSET); - frameAddr->gtOper = GT_LCL_VAR_ADDR; - - // Insert call to CORINFO_HELP_JIT_PINVOKE_END - GenTree* helperCall = comp->gtNewHelperCallNode(CORINFO_HELP_JIT_PINVOKE_END, TYP_VOID, 0, comp->gtNewArgList(frameAddr)); - - comp->fgMorphTree(helperCall); - comp->fgInsertTreeAfterAsEmbedded(helperCall, call, comp->compCurStmt->AsStmt(), currBlock); - return; - } - CORINFO_EE_INFO* pInfo = comp->eeGetEEInfo(); GenTreeStmt* newStmt; GenTreeStmt* topStmt = comp->compCurStmt->AsStmt(); @@ -2862,28 +2811,25 @@ GenTree* Lowering::LowerNonvirtPinvokeCall(GenTreeCall* call) if (call->gtCallType != CT_INDIRECT) { + GenTree* indir = nullptr; + noway_assert(call->gtCallType == CT_USER_FUNC); CORINFO_METHOD_HANDLE methHnd = call->gtCallMethHnd; - CORINFO_CONST_LOOKUP lookup; - comp->info.compCompHnd->getAddressOfPInvokeFixup(methHnd, &lookup); + void* pAddr; + addr = comp->info.compCompHnd->getAddressOfPInvokeFixup(methHnd, (void**)&pAddr); - switch (lookup.accessType) + if (addr != nullptr) { - case IAT_VALUE: - // No need for any indirection. The target is already correct. - break; - - case IAT_PVALUE: - result = Ind(AddrGen(lookup.addr)); - break; - - case IAT_PPVALUE: - result = Ind(Ind(AddrGen(lookup.addr))); - break; + indir = Ind(AddrGen(addr)); + } + else + { + // double indirection + indir = Ind(Ind(AddrGen(pAddr))); } + result = indir; } - InsertPInvokeCallEpilog(call); return result; diff --git a/src/jit/regalloc.cpp b/src/jit/regalloc.cpp index 0059362e60..78ca194ff3 100644 --- a/src/jit/regalloc.cpp +++ b/src/jit/regalloc.cpp @@ -6439,21 +6439,15 @@ void Compiler::rpPredictRegUse() // it must not be in a register trashed by the callee if (info.compCallUnmanaged != 0) { - assert(!opts.ShouldUsePInvokeHelpers() || info.compLvFrameListRoot == BAD_VAR_NUM); - if (!opts.ShouldUsePInvokeHelpers()) - { - noway_assert(info.compLvFrameListRoot < lvaCount); - - LclVarDsc * pinvokeVarDsc = &lvaTable[info.compLvFrameListRoot]; + LclVarDsc * pinvokeVarDsc = &lvaTable[info.compLvFrameListRoot]; - if (pinvokeVarDsc->lvTracked) - { - rpRecordRegIntf(RBM_CALLEE_TRASH, VarSetOps::MakeSingleton(this, pinvokeVarDsc->lvVarIndex) - DEBUGARG("compLvFrameListRoot")); + if (pinvokeVarDsc->lvTracked) + { + rpRecordRegIntf(RBM_CALLEE_TRASH, VarSetOps::MakeSingleton(this, pinvokeVarDsc->lvVarIndex) + DEBUGARG("compLvFrameListRoot")); - // We would prefer to have this be enregister in the PINVOKE_TCB register - pinvokeVarDsc->addPrefReg(RBM_PINVOKE_TCB, this); - } + // We would prefer to have this be enregister in the PINVOKE_TCB register + pinvokeVarDsc->addPrefReg(RBM_PINVOKE_TCB, this); } //If we're using a single return block, the p/invoke epilog code trashes ESI and EDI (in the diff --git a/src/vm/jitinterface.cpp b/src/vm/jitinterface.cpp index ab5c59a8f8..519ccc266c 100644 --- a/src/vm/jitinterface.cpp +++ b/src/vm/jitinterface.cpp @@ -9953,8 +9953,8 @@ void* CEEInfo::getPInvokeUnmanagedTarget(CORINFO_METHOD_HANDLE method, /*********************************************************************/ // return address of fixup area for late-bound N/Direct calls. -void CEEInfo::getAddressOfPInvokeFixup(CORINFO_METHOD_HANDLE method, - CORINFO_CONST_LOOKUP *pLookup) +void* CEEInfo::getAddressOfPInvokeFixup(CORINFO_METHOD_HANDLE method, + void **ppIndirection) { CONTRACTL { SO_TOLERANT; @@ -9963,16 +9963,22 @@ void CEEInfo::getAddressOfPInvokeFixup(CORINFO_METHOD_HANDLE method, MODE_PREEMPTIVE; } CONTRACTL_END; + void * result = NULL; + + if (ppIndirection != NULL) + *ppIndirection = NULL; + JIT_TO_EE_TRANSITION_LEAF(); MethodDesc* ftn = GetMethod(method); _ASSERTE(ftn->IsNDirect()); NDirectMethodDesc *pMD = (NDirectMethodDesc*)ftn; - pLookup->accessType = IAT_PVALUE; - pLookup->addr = (LPVOID)&(pMD->GetWriteableData()->m_pNDirectTarget); + result = (LPVOID)&(pMD->GetWriteableData()->m_pNDirectTarget); EE_TO_JIT_TRANSITION_LEAF(); + + return result; } diff --git a/src/vm/jitinterface.h b/src/vm/jitinterface.h index c2fa7a1744..0035715e34 100644 --- a/src/vm/jitinterface.h +++ b/src/vm/jitinterface.h @@ -911,7 +911,7 @@ public: CORINFO_VARARGS_HANDLE getVarArgsHandle(CORINFO_SIG_INFO *sig, void **ppIndirection); bool canGetVarArgsHandle(CORINFO_SIG_INFO *sig); void* getPInvokeUnmanagedTarget(CORINFO_METHOD_HANDLE method, void **ppIndirection); - void getAddressOfPInvokeFixup(CORINFO_METHOD_HANDLE method, CORINFO_CONST_LOOKUP *pLookup); + void* getAddressOfPInvokeFixup(CORINFO_METHOD_HANDLE method, void **ppIndirection); CORINFO_JUST_MY_CODE_HANDLE getJustMyCodeHandle(CORINFO_METHOD_HANDLE method, CORINFO_JUST_MY_CODE_HANDLE **ppIndirection); void GetProfilingHandle( diff --git a/src/zap/zapinfo.cpp b/src/zap/zapinfo.cpp index 5258dfef24..e3c2759e82 100644 --- a/src/zap/zapinfo.cpp +++ b/src/zap/zapinfo.cpp @@ -2731,9 +2731,9 @@ void * ZapInfo::getPInvokeUnmanagedTarget(CORINFO_METHOD_HANDLE method, void **p return NULL; } -void ZapInfo::getAddressOfPInvokeFixup(CORINFO_METHOD_HANDLE method, CORINFO_CONST_LOOKUP *pLookup) +void * ZapInfo::getAddressOfPInvokeFixup(CORINFO_METHOD_HANDLE method,void **ppIndirection) { - _ASSERTE(pLookup != NULL); + _ASSERTE(ppIndirection != NULL); m_pImage->m_pPreloader->AddMethodToTransitiveClosureOfInstantiations(method); @@ -2741,9 +2741,8 @@ void ZapInfo::getAddressOfPInvokeFixup(CORINFO_METHOD_HANDLE method, CORINFO_CON if (moduleHandle == m_pImage->m_hModule && m_pImage->m_pPreloader->CanEmbedMethodHandle(method, m_currentMethodHandle)) { - pLookup->accessType = IAT_PVALUE; - pLookup->addr = PVOID(m_pImage->GetWrappers()->GetAddrOfPInvokeFixup(method)); - return; + *ppIndirection = NULL; + return PVOID(m_pImage->GetWrappers()->GetAddrOfPInvokeFixup(method)); } // @@ -2756,8 +2755,8 @@ void ZapInfo::getAddressOfPInvokeFixup(CORINFO_METHOD_HANDLE method, CORINFO_CON ZapImport * pImport = m_pImage->GetImportTable()->GetIndirectPInvokeTargetImport(method); AppendConditionalImport(pImport); - pLookup->accessType = IAT_PPVALUE; - pLookup->addr = pImport; + *ppIndirection = pImport; + return NULL; } CORINFO_JUST_MY_CODE_HANDLE ZapInfo::getJustMyCodeHandle( diff --git a/src/zap/zapinfo.h b/src/zap/zapinfo.h index e32d2068d5..1d16c9b760 100644 --- a/src/zap/zapinfo.h +++ b/src/zap/zapinfo.h @@ -430,8 +430,8 @@ public: void **ppIndirection); void * getPInvokeUnmanagedTarget(CORINFO_METHOD_HANDLE method, void **ppIndirection); - void getAddressOfPInvokeFixup(CORINFO_METHOD_HANDLE method, - CORINFO_CONST_LOOKUP *pLookup); + void * getAddressOfPInvokeFixup(CORINFO_METHOD_HANDLE method, + void **ppIndirection); CORINFO_JUST_MY_CODE_HANDLE getJustMyCodeHandle( CORINFO_METHOD_HANDLE method, CORINFO_JUST_MY_CODE_HANDLE **ppIndirection); |