Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit ba30fd2

Browse files
committed
Address CR feedback.
1 parent d33c840 commit ba30fd2

File tree

4 files changed

+78
-21
lines changed

4 files changed

+78
-21
lines changed

src/inc/corjit.h

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ enum CorJitFlag
8585
CORJIT_FLG_GCPOLL_CALLS = 0x00000040, // Emit calls to JIT_POLLGC for thread suspension.
8686
CORJIT_FLG_MCJIT_BACKGROUND = 0x00000080, // Calling from multicore JIT background thread, do not call JitComplete
8787

88-
#ifdef FEATURE_LEGACYNETCF
88+
#if defined(FEATURE_LEGACYNETCF)
8989

9090
CORJIT_FLG_NETCF_QUIRKS = 0x00000100, // Mimic .NetCF JIT's quirks for generated code (currently just inlining heuristics)
9191

@@ -121,25 +121,33 @@ enum CorJitFlag
121121

122122
#endif // !defined(_TARGET_X86_) && !defined(_TARGET_AMD64_)
123123

124-
#ifdef MDIL
124+
#if defined(MDIL)
125+
125126
CORJIT_FLG_MDIL = 0x00004000, // Generate MDIL code instead of machine code
126127

127128
// Safe to overlap with CORJIT_FLG_MAKEFINALCODE below. Not used by the JIT, used internally by NGen only.
128129
CORJIT_FLG_MINIMAL_MDIL = 0x00008000, // Generate MDIL code suitable for use to bind other assemblies.
129130

130131
// Safe to overlap with CORJIT_FLG_READYTORUN below. Not used by the JIT, used internally by NGen only.
131132
CORJIT_FLG_NO_MDIL = 0x00010000, // Generate an MDIL section but no code or CTL. Not used by the JIT, used internally by NGen only.
132-
#else // MDIL
133+
134+
#else // defined(MDIL)
135+
133136
CORJIT_FLG_CFI_UNWIND = 0x00004000, // Emit CFI unwind info
134-
#endif // MDIL
135137

136138
#if defined(FEATURE_INTERPRETER)
139+
137140
CORJIT_FLG_MAKEFINALCODE = 0x00008000, // Use the final code generator, i.e., not the interpreter.
138-
#endif // FEATURE_INTERPRETER
139141

140-
#ifdef FEATURE_READYTORUN_COMPILER
142+
#endif // defined(FEATURE_INTERPRETER)
143+
144+
#if defined(FEATURE_READYTORUN_COMPILER)
145+
141146
CORJIT_FLG_READYTORUN = 0x00010000, // Use version-resilient code generation
142-
#endif
147+
148+
#endif // defined(FEATURE_READYTORUN_COMPILER)
149+
150+
#endif // !defined(MDIL)
143151

144152
CORJIT_FLG_PROF_ENTERLEAVE = 0x00020000, // Instrument prologues/epilogues
145153
CORJIT_FLG_PROF_REJIT_NOPS = 0x00040000, // Insert NOPs to ensure code is re-jitable

src/jit/codegencommon.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8522,7 +8522,7 @@ void CodeGen::genFnProlog()
85228522
{
85238523
excludeMask |= RBM_PINVOKE_FRAME;
85248524

8525-
assert(!compiler->opts.ShouldUsePInvokeHelpers() || compiler->info.compLvFrameListRoot == BAD_VAR_NUM);
8525+
assert((!compiler->opts.ShouldUsePInvokeHelpers()) || (compiler->info.compLvFrameListRoot == BAD_VAR_NUM));
85268526
if (!compiler->opts.ShouldUsePInvokeHelpers())
85278527
{
85288528
noway_assert(compiler->info.compLvFrameListRoot < compiler->lvaCount);

src/jit/lower.cpp

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2477,7 +2477,10 @@ void Lowering::InsertPInvokeMethodProlog()
24772477

24782478
if (comp->opts.ShouldUsePInvokeHelpers())
24792479
{
2480-
// Initialize the P/Invoke frame by calling CORINFO_HELP_INIT_PINVOKE_FRAME
2480+
// Initialize the P/Invoke frame by calling CORINFO_HELP_INIT_PINVOKE_FRAME:
2481+
//
2482+
// OpaqueFrame opaqueFrame;
2483+
// CORINFO_HELP_INIT_PINVOKE_FRAME(&opaqueFrame);
24812484

24822485
GenTree* frameAddr = new(comp, GT_LCL_VAR_ADDR)
24832486
GenTreeLclVar(GT_LCL_VAR_ADDR, TYP_BYREF, comp->lvaInlinedPInvokeFrameVar, BAD_IL_OFFSET);
@@ -2845,6 +2848,55 @@ GenTree* Lowering::LowerNonvirtPinvokeCall(GenTreeCall* call)
28452848
//------------------------------------------------------
28462849
// Non-virtual/Indirect calls: PInvoke calls.
28472850

2851+
// PInvoke lowering varies depending on the flags passed in by the EE. By default,
2852+
// GC transitions are generated inline; if CORJIT_FLG2_USE_PINVOKE_HELPERS is specified,
2853+
// GC transitions are instead performed using helper calls. Examples of each case are given
2854+
// below. Note that the data structure that is used to store information about a call frame
2855+
// containing any P/Invoke calls is initialized in the method prolog (see
2856+
// InsertPInvokeMethod{Prolog,Epilog} for details).
2857+
//
2858+
// Inline transitions:
2859+
// InlinedCallFrame inlinedCallFrame;
2860+
//
2861+
// ...
2862+
//
2863+
// // Set up frame information
2864+
// inlinedCallFrame.callTarget = methodHandle;
2865+
// inlinedCallFrame.callSiteTracker = SP; (x86 only)
2866+
// inlinedCallFrame.callSiteReturnAddress = &label; (the address of the instruction immediately following the call)
2867+
// thread->m_pFrame = &inlinedCallFrame; (non-IL-stub only)
2868+
//
2869+
// // Switch the thread's GC mode to preemptive mode
2870+
// thread->m_fPreemptiveGCDisabled = 0;
2871+
//
2872+
// // Call the unmanged method
2873+
// target();
2874+
//
2875+
// // Switch the thread's GC mode back to cooperative mode
2876+
// thread->m_fPreemptiveGCDisabled = 1;
2877+
//
2878+
// // Rendezvous with a running collection if necessary
2879+
// if (g_TrapReturningThreads)
2880+
// RareDisablePreemptiveGC();
2881+
//
2882+
// Transistions using helpers:
2883+
//
2884+
// OpaqueFrame opaqueFrame;
2885+
//
2886+
// ...
2887+
//
2888+
// // Call the JIT_PINVOKE_BEGIN helper
2889+
// JIT_PINVOKE_BEGIN(&opaqueFrame);
2890+
//
2891+
// // Call the unmanaged method
2892+
// target();
2893+
//
2894+
// // Call the JIT_PINVOKE_END helper
2895+
// JIT_PINVOKE_END(&opaqueFrame);
2896+
//
2897+
// Note that the JIT_PINVOKE_{BEGIN.END} helpers currently use the default calling convention for the target platform.
2898+
// They may be changed in the near future s.t. they preserve all register values.
2899+
28482900
GenTree* result = nullptr;
28492901
void* addr = nullptr;
28502902

src/jit/regalloc.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6438,21 +6438,18 @@ void Compiler::rpPredictRegUse()
64386438
// it must not be in a register trashed by the callee
64396439
if (info.compCallUnmanaged != 0)
64406440
{
6441-
assert(!opts.ShouldUsePInvokeHelpers() || info.compLvFrameListRoot == BAD_VAR_NUM);
6442-
if (!opts.ShouldUsePInvokeHelpers())
6443-
{
6444-
noway_assert(info.compLvFrameListRoot < lvaCount);
6441+
assert(!opts.ShouldUsePInvokeHelpers());
6442+
noway_assert(info.compLvFrameListRoot < lvaCount);
64456443

6446-
LclVarDsc * pinvokeVarDsc = &lvaTable[info.compLvFrameListRoot];
6444+
LclVarDsc * pinvokeVarDsc = &lvaTable[info.compLvFrameListRoot];
64476445

6448-
if (pinvokeVarDsc->lvTracked)
6449-
{
6450-
rpRecordRegIntf(RBM_CALLEE_TRASH, VarSetOps::MakeSingleton(this, pinvokeVarDsc->lvVarIndex)
6451-
DEBUGARG("compLvFrameListRoot"));
6446+
if (pinvokeVarDsc->lvTracked)
6447+
{
6448+
rpRecordRegIntf(RBM_CALLEE_TRASH, VarSetOps::MakeSingleton(this, pinvokeVarDsc->lvVarIndex)
6449+
DEBUGARG("compLvFrameListRoot"));
64526450

6453-
// We would prefer to have this be enregister in the PINVOKE_TCB register
6454-
pinvokeVarDsc->addPrefReg(RBM_PINVOKE_TCB, this);
6455-
}
6451+
// We would prefer to have this be enregister in the PINVOKE_TCB register
6452+
pinvokeVarDsc->addPrefReg(RBM_PINVOKE_TCB, this);
64566453
}
64576454

64586455
//If we're using a single return block, the p/invoke epilog code trashes ESI and EDI (in the

0 commit comments

Comments
 (0)