@@ -5390,29 +5390,23 @@ GenTreePtr Compiler::impTransformThis(GenTreePtr thisPtr,
5390
5390
}
5391
5391
5392
5392
//------------------------------------------------------------------------
5393
- // impCanPInvokeInline: examine information from a call to see if the call
5394
- // qualifies as an inline pinvoke.
5395
- //
5396
- // Arguments:
5397
- // block - block contaning the call, or for inlinees, block
5398
- // containing the call being inlined
5393
+ // impCanPInvokeInline: check whether PInvoke inlining should enabled in current method.
5399
5394
//
5400
5395
// Return Value:
5401
- // true if this call qualifies as an inline pinvoke , false otherwise
5396
+ // true if PInvoke inlining should be enabled in current method , false otherwise
5402
5397
//
5403
5398
// Notes:
5404
- // Checks basic legality and then a number of ambient conditions
5405
- // where we could pinvoke but choose not to
5399
+ // Checks a number of ambient conditions where we could pinvoke but choose not to
5406
5400
5407
- bool Compiler::impCanPInvokeInline(BasicBlock* block )
5401
+ bool Compiler::impCanPInvokeInline()
5408
5402
{
5409
- return impCanPInvokeInlineCallSite(block ) && getInlinePInvokeEnabled( ) && (!opts.compDbgCode ) &&
5410
- (compCodeOpt() != SMALL_CODE) && ( !opts.compNoPInvokeInlineCB) // profiler is preventing inline pinvoke
5403
+ return getInlinePInvokeEnabled( ) && (!opts.compDbgCode ) && (compCodeOpt() != SMALL_CODE ) &&
5404
+ (!opts.compNoPInvokeInlineCB) // profiler is preventing inline pinvoke
5411
5405
;
5412
5406
}
5413
5407
5414
5408
//------------------------------------------------------------------------
5415
- // impCanPInvokeInlineSallSite : basic legality checks using information
5409
+ // impCanPInvokeInlineCallSite : basic legality checks using information
5416
5410
// from a call to see if the call qualifies as an inline pinvoke.
5417
5411
//
5418
5412
// Arguments:
@@ -5441,6 +5435,17 @@ bool Compiler::impCanPInvokeInline(BasicBlock* block)
5441
5435
5442
5436
bool Compiler::impCanPInvokeInlineCallSite(BasicBlock* block)
5443
5437
{
5438
+ if (block->hasHndIndex())
5439
+ {
5440
+ return false;
5441
+ }
5442
+
5443
+ // The remaining limitations do not apply to CoreRT
5444
+ if (IsTargetAbi(CORINFO_CORERT_ABI))
5445
+ {
5446
+ return true;
5447
+ }
5448
+
5444
5449
#ifdef _TARGET_AMD64_
5445
5450
// On x64, we disable pinvoke inlining inside of try regions.
5446
5451
// Here is the comment from JIT64 explaining why:
@@ -5462,12 +5467,13 @@ bool Compiler::impCanPInvokeInlineCallSite(BasicBlock* block)
5462
5467
//
5463
5468
// A desktop test case where this seems to matter is
5464
5469
// jit\jit64\ebvts\mcpp\sources2\ijw\__clrcall\vector_ctor_dtor.02\deldtor_clr.exe
5465
- const bool inX64Try = block->hasTryIndex();
5466
- #else
5467
- const bool inX64Try = false;
5470
+ if (block->hasTryIndex())
5471
+ {
5472
+ return false;
5473
+ }
5468
5474
#endif // _TARGET_AMD64_
5469
5475
5470
- return !inX64Try && !block->hasHndIndex() ;
5476
+ return true ;
5471
5477
}
5472
5478
5473
5479
//------------------------------------------------------------------------
@@ -5533,27 +5539,38 @@ void Compiler::impCheckForPInvokeCall(
5533
5539
}
5534
5540
optNativeCallCount++;
5535
5541
5536
- if (opts.compMustInlinePInvokeCalli && methHnd == nullptr)
5542
+ if (opts.jitFlags->IsSet(JitFlags::JIT_FLAG_IL_STUB) && methHnd == nullptr)
5537
5543
{
5538
- // Always inline pinvoke.
5544
+ // PInvoke CALLI in IL stubs must be inlined
5539
5545
}
5540
5546
else
5541
5547
{
5542
- // Check legality and profitability.
5543
- if (!impCanPInvokeInline (block))
5548
+ // Check legality
5549
+ if (!impCanPInvokeInlineCallSite (block))
5544
5550
{
5545
5551
return;
5546
5552
}
5547
5553
5548
- if (info.compCompHnd->pInvokeMarshalingRequired(methHnd, sig))
5554
+ // PInvoke CALL in IL stubs must be inlined on CoreRT. Skip the ambient conditions checks and
5555
+ // profitability checks
5556
+ if (!(opts.jitFlags->IsSet(JitFlags::JIT_FLAG_IL_STUB) && IsTargetAbi(CORINFO_CORERT_ABI)))
5549
5557
{
5550
- return;
5558
+ if (impCanPInvokeInline())
5559
+ {
5560
+ return;
5561
+ }
5562
+
5563
+ // Size-speed tradeoff: don't use inline pinvoke at rarely
5564
+ // executed call sites. The non-inline version is more
5565
+ // compact.
5566
+ if (block->isRunRarely())
5567
+ {
5568
+ return;
5569
+ }
5551
5570
}
5552
5571
5553
- // Size-speed tradeoff: don't use inline pinvoke at rarely
5554
- // executed call sites. The non-inline version is more
5555
- // compact.
5556
- if (block->isRunRarely())
5572
+ // The expensive check should be last
5573
+ if (info.compCompHnd->pInvokeMarshalingRequired(methHnd, sig))
5557
5574
{
5558
5575
return;
5559
5576
}
@@ -6220,7 +6237,7 @@ bool Compiler::impIsTailCallILPattern(bool tailPrefixed,
6220
6237
((nextOpcode == CEE_NOP) || ((nextOpcode == CEE_POP) && (++cntPop == 1)))); // Next opcode = nop or exactly
6221
6238
// one pop seen so far.
6222
6239
#else
6223
- nextOpcode = (OPCODE)getU1LittleEndian(codeAddrOfNextOpcode);
6240
+ nextOpcode = (OPCODE)getU1LittleEndian(codeAddrOfNextOpcode);
6224
6241
#endif
6225
6242
6226
6243
if (isCallPopAndRet)
0 commit comments