@@ -1487,35 +1487,54 @@ PhaseStatus Compiler::fgPrepareToInstrumentMethod()
1487
1487
1488
1488
// Choose instrumentation technology.
1489
1489
//
1490
+ // We enable edge profiling by default, except when:
1491
+ // * disabled by option
1492
+ // * we are prejitting via classic ngen
1493
+ // * we are jitting osr methods
1494
+ //
1490
1495
// Currently, OSR is incompatible with edge profiling. So if OSR is enabled,
1491
1496
// always do block profiling.
1492
1497
//
1493
1498
// Note this incompatibility only exists for methods that actually have
1494
1499
// patchpoints, but we won't know that until we import.
1495
1500
//
1496
- const bool methodMayHavePatchpoints =
1497
- (opts.jitFlags ->IsSet (JitFlags::JIT_FLAG_TIER0) && (JitConfig.TC_OnStackReplacement () > 0 ));
1501
+ CLANG_FORMAT_COMMENT_ANCHOR;
1498
1502
1499
- if ((JitConfig.JitEdgeProfiling () > 0 ) && !methodMayHavePatchpoints)
1503
+ #ifdef FEATURE_READYTORUN_COMPILER
1504
+ const bool r2r = opts.IsReadyToRun ();
1505
+ #else
1506
+ const bool r2r = false ;
1507
+ #endif
1508
+ const bool prejit = opts.jitFlags ->IsSet (JitFlags::JIT_FLAG_PREJIT);
1509
+ const bool classicNgen = prejit && !r2r;
1510
+ const bool osr = (opts.jitFlags ->IsSet (JitFlags::JIT_FLAG_TIER0) && (JitConfig.TC_OnStackReplacement () > 0 ));
1511
+ const bool useEdgeProfiles = (JitConfig.JitEdgeProfiling () > 0 ) && !classicNgen && !osr;
1512
+
1513
+ if (useEdgeProfiles)
1500
1514
{
1501
1515
fgCountInstrumentor = new (this , CMK_Pgo) EfficientEdgeCountInstrumentor (this );
1502
1516
}
1503
1517
else
1504
1518
{
1505
- if (JitConfig.JitEdgeProfiling () > 0 )
1506
- {
1507
- JITDUMP (" OSR and edge profiling not yet compatible; using block profiling\n " );
1508
- }
1519
+ JITDUMP (" Using block profiling, because %s\n " ,
1520
+ (JitConfig.JitEdgeProfiling () > 0 ) ? " edge profiles disabled" : classicNgen ? " classic Ngen" : " OSR" );
1509
1521
1510
1522
fgCountInstrumentor = new (this , CMK_Pgo) BlockCountInstrumentor (this );
1511
1523
}
1512
1524
1513
- if (JitConfig.JitClassProfiling () > 0 )
1525
+ // Enable class profiling by default, when jitting.
1526
+ // Todo: we may also want this on by default for prejitting.
1527
+ //
1528
+ const bool useClassProfiles = (JitConfig.JitClassProfiling () > 0 ) && !prejit;
1529
+ if (useClassProfiles)
1514
1530
{
1515
1531
fgClassInstrumentor = new (this , CMK_Pgo) ClassProbeInstrumentor (this );
1516
1532
}
1517
1533
else
1518
1534
{
1535
+ JITDUMP (" Not doing class profiling, because %s\n " ,
1536
+ (JitConfig.JitClassProfiling () > 0 ) ? " class profiles disabled" : " prejit" );
1537
+
1519
1538
fgClassInstrumentor = new (this , CMK_Pgo) NonInstrumentor (this );
1520
1539
}
1521
1540
@@ -1575,13 +1594,29 @@ PhaseStatus Compiler::fgInstrumentMethod()
1575
1594
//
1576
1595
assert (fgClassInstrumentor->SchemaCount () == info.compClassProbeCount );
1577
1596
1578
- // Optionally, if there were no class probes and only one count probe,
1597
+ // Optionally, when jitting, if there were no class probes and only one count probe,
1579
1598
// suppress instrumentation.
1580
1599
//
1581
- if ((JitConfig.JitMinimalProfiling () > 0 ) && (fgCountInstrumentor->SchemaCount () == 1 ) &&
1582
- (fgClassInstrumentor->SchemaCount () == 0 ))
1600
+ // We leave instrumentation in place when prejitting as the sample hits in the method
1601
+ // may be used to determine if the method should be prejitted or not.
1602
+ //
1603
+ // For jitting, no information is conveyed by the count in a single=block method.
1604
+ //
1605
+ bool minimalProbeMode = false ;
1606
+
1607
+ if (opts.jitFlags ->IsSet (JitFlags::JIT_FLAG_PREJIT))
1608
+ {
1609
+ minimalProbeMode = (JitConfig.JitMinimalPrejitProfiling () > 0 );
1610
+ }
1611
+ else
1612
+ {
1613
+ minimalProbeMode = (JitConfig.JitMinimalJitProfiling () > 0 );
1614
+ }
1615
+
1616
+ if (minimalProbeMode && (fgCountInstrumentor->SchemaCount () == 1 ) && (fgClassInstrumentor->SchemaCount () == 0 ))
1583
1617
{
1584
- JITDUMP (" Not instrumenting method: only one counter, and no class probes\n " );
1618
+ JITDUMP (
1619
+ " Not instrumenting method: minimal probing enabled, and method has only one counter and no class probes\n " );
1585
1620
return PhaseStatus::MODIFIED_NOTHING;
1586
1621
}
1587
1622
0 commit comments