Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0785303

Browse files
Move the NoGC helper classification to HelperCallProperties (#105040)
Fixes a TODO and centralizes the assumptions about helpers in one place.
1 parent 49a2a55 commit 0785303

File tree

6 files changed

+58
-94
lines changed

6 files changed

+58
-94
lines changed

src/coreclr/jit/compiler.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3322,7 +3322,7 @@ inline bool Compiler::IsPotentialGCSafePoint(GenTree* tree) const
33223322
if (((tree->gtFlags & GTF_CALL) != 0))
33233323
{
33243324
// if this is not a No-GC helper
3325-
if (!tree->IsCall() || !emitter::emitNoGChelper(tree->AsCall()->GetHelperNum()))
3325+
if (!tree->IsHelperCall() || !s_helperCallProperties.IsNoGC(tree->AsCall()->GetHelperNum()))
33263326
{
33273327
// assume that we have a safe point.
33283328
return true;

src/coreclr/jit/emit.cpp

Lines changed: 3 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -2780,82 +2780,6 @@ emitter::instrDesc* emitter::emitNewInstrCnsDsp(emitAttr size, target_ssize_t cn
27802780
}
27812781
}
27822782

2783-
//------------------------------------------------------------------------
2784-
// emitNoGChelper: Returns true if garbage collection won't happen within the helper call.
2785-
//
2786-
// Notes:
2787-
// There is no need to record live pointers for such call sites.
2788-
//
2789-
// Arguments:
2790-
// helpFunc - a helper signature for the call, can be CORINFO_HELP_UNDEF, that means that the call is not a helper.
2791-
//
2792-
// Return value:
2793-
// true if GC can't happen within this call, false otherwise.
2794-
bool emitter::emitNoGChelper(CorInfoHelpFunc helpFunc)
2795-
{
2796-
// TODO-Throughput: Make this faster (maybe via a simple table of bools?)
2797-
2798-
switch (helpFunc)
2799-
{
2800-
case CORINFO_HELP_UNDEF:
2801-
return false;
2802-
2803-
case CORINFO_HELP_PROF_FCN_LEAVE:
2804-
case CORINFO_HELP_PROF_FCN_ENTER:
2805-
case CORINFO_HELP_PROF_FCN_TAILCALL:
2806-
case CORINFO_HELP_LLSH:
2807-
case CORINFO_HELP_LRSH:
2808-
case CORINFO_HELP_LRSZ:
2809-
2810-
// case CORINFO_HELP_LMUL:
2811-
// case CORINFO_HELP_LDIV:
2812-
// case CORINFO_HELP_LMOD:
2813-
// case CORINFO_HELP_ULDIV:
2814-
// case CORINFO_HELP_ULMOD:
2815-
2816-
#ifdef TARGET_X86
2817-
case CORINFO_HELP_ASSIGN_REF_EAX:
2818-
case CORINFO_HELP_ASSIGN_REF_ECX:
2819-
case CORINFO_HELP_ASSIGN_REF_EBX:
2820-
case CORINFO_HELP_ASSIGN_REF_EBP:
2821-
case CORINFO_HELP_ASSIGN_REF_ESI:
2822-
case CORINFO_HELP_ASSIGN_REF_EDI:
2823-
2824-
case CORINFO_HELP_CHECKED_ASSIGN_REF_EAX:
2825-
case CORINFO_HELP_CHECKED_ASSIGN_REF_ECX:
2826-
case CORINFO_HELP_CHECKED_ASSIGN_REF_EBX:
2827-
case CORINFO_HELP_CHECKED_ASSIGN_REF_EBP:
2828-
case CORINFO_HELP_CHECKED_ASSIGN_REF_ESI:
2829-
case CORINFO_HELP_CHECKED_ASSIGN_REF_EDI:
2830-
#endif
2831-
2832-
case CORINFO_HELP_ASSIGN_REF:
2833-
case CORINFO_HELP_CHECKED_ASSIGN_REF:
2834-
case CORINFO_HELP_ASSIGN_BYREF:
2835-
2836-
case CORINFO_HELP_GET_GCSTATIC_BASE_NOCTOR:
2837-
case CORINFO_HELP_GET_NONGCSTATIC_BASE_NOCTOR:
2838-
2839-
case CORINFO_HELP_INIT_PINVOKE_FRAME:
2840-
2841-
case CORINFO_HELP_FAIL_FAST:
2842-
case CORINFO_HELP_STACK_PROBE:
2843-
2844-
case CORINFO_HELP_CHECK_OBJ:
2845-
2846-
// never present on stack at the time of GC
2847-
case CORINFO_HELP_TAILCALL:
2848-
case CORINFO_HELP_JIT_REVERSE_PINVOKE_ENTER:
2849-
case CORINFO_HELP_JIT_REVERSE_PINVOKE_ENTER_TRACK_TRANSITIONS:
2850-
2851-
case CORINFO_HELP_VALIDATE_INDIRECT_CALL:
2852-
return true;
2853-
2854-
default:
2855-
return false;
2856-
}
2857-
}
2858-
28592783
//------------------------------------------------------------------------
28602784
// emitNoGChelper: Returns true if garbage collection won't happen within the helper call.
28612785
//
@@ -2867,14 +2791,15 @@ bool emitter::emitNoGChelper(CorInfoHelpFunc helpFunc)
28672791
//
28682792
// Return value:
28692793
// true if GC can't happen within this call, false otherwise.
2794+
//
28702795
bool emitter::emitNoGChelper(CORINFO_METHOD_HANDLE methHnd)
28712796
{
28722797
CorInfoHelpFunc helpFunc = Compiler::eeGetHelperNum(methHnd);
28732798
if (helpFunc == CORINFO_HELP_UNDEF)
28742799
{
28752800
return false;
28762801
}
2877-
return emitNoGChelper(helpFunc);
2802+
return Compiler::s_helperCallProperties.IsNoGC(helpFunc);
28782803
}
28792804

28802805
/*****************************************************************************
@@ -10430,7 +10355,7 @@ regMaskTP emitter::emitGetGCRegsSavedOrModified(CORINFO_METHOD_HANDLE methHnd)
1043010355
//
1043110356
regMaskTP emitter::emitGetGCRegsKilledByNoGCCall(CorInfoHelpFunc helper)
1043210357
{
10433-
assert(emitNoGChelper(helper));
10358+
assert(emitNoGChelper(Compiler::eeFindHelper(helper)));
1043410359
regMaskTP result;
1043510360
switch (helper)
1043610361
{

src/coreclr/jit/emit.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3159,13 +3159,14 @@ class emitter
31593159
/* The following is used to distinguish helper vs non-helper calls */
31603160
/************************************************************************/
31613161

3162-
static bool emitNoGChelper(CorInfoHelpFunc helpFunc);
3162+
private:
31633163
static bool emitNoGChelper(CORINFO_METHOD_HANDLE methHnd);
31643164

31653165
/************************************************************************/
31663166
/* The following logic keeps track of live GC ref values */
31673167
/************************************************************************/
31683168

3169+
public:
31693170
bool emitFullArgInfo; // full arg info (including non-ptr arg)?
31703171
bool emitFullGCinfo; // full GC pointer maps?
31713172
bool emitFullyInt; // fully interruptible code?

src/coreclr/jit/optimizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6104,7 +6104,7 @@ void Compiler::optRemoveRedundantZeroInits()
61046104
{
61056105
// If compMethodRequiresPInvokeFrame() returns true, lower may later
61066106
// insert a call to CORINFO_HELP_INIT_PINVOKE_FRAME but that is not a gc-safe point.
6107-
assert(emitter::emitNoGChelper(CORINFO_HELP_INIT_PINVOKE_FRAME));
6107+
assert(s_helperCallProperties.IsNoGC(CORINFO_HELP_INIT_PINVOKE_FRAME));
61086108

61096109
if (!lclDsc->HasGCPtr() || (!GetInterruptible() && !hasGCSafePoint))
61106110
{

src/coreclr/jit/utils.cpp

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,13 +1520,16 @@ void HelperCallProperties::init()
15201520
bool mutatesHeap = false; // true if any previous heap objects [are|can be] modified
15211521
bool mayRunCctor = false; // true if the helper call may cause a static constructor to be run.
15221522
bool isNoEscape = false; // true if none of the GC ref arguments can escape
1523+
bool isNoGC = false; // true is the helper cannot trigger GC
15231524

15241525
switch (helper)
15251526
{
15261527
// Arithmetic helpers that cannot throw
15271528
case CORINFO_HELP_LLSH:
15281529
case CORINFO_HELP_LRSH:
15291530
case CORINFO_HELP_LRSZ:
1531+
isNoGC = true;
1532+
FALLTHROUGH;
15301533
case CORINFO_HELP_LMUL:
15311534
case CORINFO_HELP_LNG2DBL:
15321535
case CORINFO_HELP_ULNG2DBL:
@@ -1538,7 +1541,6 @@ void HelperCallProperties::init()
15381541
case CORINFO_HELP_DBLREM:
15391542
case CORINFO_HELP_FLTROUND:
15401543
case CORINFO_HELP_DBLROUND:
1541-
15421544
isPure = true;
15431545
noThrow = true;
15441546
break;
@@ -1729,6 +1731,8 @@ void HelperCallProperties::init()
17291731

17301732
case CORINFO_HELP_GET_GCSTATIC_BASE_NOCTOR:
17311733
case CORINFO_HELP_GET_NONGCSTATIC_BASE_NOCTOR:
1734+
isNoGC = true;
1735+
FALLTHROUGH;
17321736
case CORINFO_HELP_GETDYNAMIC_GCSTATIC_BASE_NOCTOR:
17331737
case CORINFO_HELP_GETDYNAMIC_NONGCSTATIC_BASE_NOCTOR:
17341738
case CORINFO_HELP_GETPINNED_GCSTATIC_BASE_NOCTOR:
@@ -1749,24 +1753,41 @@ void HelperCallProperties::init()
17491753
nonNullReturn = true;
17501754
break;
17511755

1756+
#ifdef TARGET_X86
1757+
case CORINFO_HELP_ASSIGN_REF_EAX:
1758+
case CORINFO_HELP_ASSIGN_REF_ECX:
1759+
case CORINFO_HELP_ASSIGN_REF_EBX:
1760+
case CORINFO_HELP_ASSIGN_REF_EBP:
1761+
case CORINFO_HELP_ASSIGN_REF_ESI:
1762+
case CORINFO_HELP_ASSIGN_REF_EDI:
1763+
case CORINFO_HELP_CHECKED_ASSIGN_REF_EAX:
1764+
case CORINFO_HELP_CHECKED_ASSIGN_REF_ECX:
1765+
case CORINFO_HELP_CHECKED_ASSIGN_REF_EBX:
1766+
case CORINFO_HELP_CHECKED_ASSIGN_REF_EBP:
1767+
case CORINFO_HELP_CHECKED_ASSIGN_REF_ESI:
1768+
case CORINFO_HELP_CHECKED_ASSIGN_REF_EDI:
1769+
#endif
17521770
// GC Write barrier support
17531771
// TODO-ARM64-Bug?: Can these throw or not?
17541772
case CORINFO_HELP_ASSIGN_REF:
17551773
case CORINFO_HELP_CHECKED_ASSIGN_REF:
1756-
case CORINFO_HELP_ASSIGN_REF_ENSURE_NONHEAP:
17571774
case CORINFO_HELP_ASSIGN_BYREF:
1775+
isNoGC = true;
1776+
FALLTHROUGH;
1777+
case CORINFO_HELP_ASSIGN_REF_ENSURE_NONHEAP:
17581778
case CORINFO_HELP_BULK_WRITEBARRIER:
1759-
17601779
mutatesHeap = true;
17611780
break;
17621781

17631782
// Accessing fields (write)
17641783
case CORINFO_HELP_ARRADDR_ST:
1765-
17661784
mutatesHeap = true;
17671785
break;
17681786

17691787
// These helper calls always throw an exception
1788+
case CORINFO_HELP_FAIL_FAST:
1789+
isNoGC = true;
1790+
FALLTHROUGH;
17701791
case CORINFO_HELP_OVERFLOW:
17711792
case CORINFO_HELP_VERIFICATION:
17721793
case CORINFO_HELP_RNGCHKFAIL:
@@ -1779,17 +1800,14 @@ void HelperCallProperties::init()
17791800
case CORINFO_HELP_THROW_NOT_IMPLEMENTED:
17801801
case CORINFO_HELP_THROW_PLATFORM_NOT_SUPPORTED:
17811802
case CORINFO_HELP_THROW_TYPE_NOT_SUPPORTED:
1782-
case CORINFO_HELP_FAIL_FAST:
17831803
case CORINFO_HELP_METHOD_ACCESS_EXCEPTION:
17841804
case CORINFO_HELP_FIELD_ACCESS_EXCEPTION:
17851805
case CORINFO_HELP_CLASS_ACCESS_EXCEPTION:
1786-
17871806
alwaysThrow = true;
17881807
break;
17891808

17901809
// These helper calls may throw an exception
17911810
case CORINFO_HELP_MON_EXIT_STATIC:
1792-
17931811
break;
17941812

17951813
// This is a debugging aid; it simply returns a constant address.
@@ -1798,26 +1816,37 @@ void HelperCallProperties::init()
17981816
noThrow = true;
17991817
break;
18001818

1819+
case CORINFO_HELP_INIT_PINVOKE_FRAME:
1820+
case CORINFO_HELP_JIT_REVERSE_PINVOKE_ENTER: // Never present on stack at the time of GC.
1821+
case CORINFO_HELP_JIT_REVERSE_PINVOKE_ENTER_TRACK_TRANSITIONS:
1822+
isNoGC = true;
1823+
FALLTHROUGH;
18011824
case CORINFO_HELP_DBG_IS_JUST_MY_CODE:
18021825
case CORINFO_HELP_BBT_FCN_ENTER:
18031826
case CORINFO_HELP_POLL_GC:
18041827
case CORINFO_HELP_MON_ENTER:
18051828
case CORINFO_HELP_MON_EXIT:
18061829
case CORINFO_HELP_MON_ENTER_STATIC:
1807-
case CORINFO_HELP_JIT_REVERSE_PINVOKE_ENTER:
18081830
case CORINFO_HELP_JIT_REVERSE_PINVOKE_EXIT:
18091831
case CORINFO_HELP_GETFIELDADDR:
1810-
case CORINFO_HELP_INIT_PINVOKE_FRAME:
18111832
case CORINFO_HELP_JIT_PINVOKE_BEGIN:
18121833
case CORINFO_HELP_JIT_PINVOKE_END:
1813-
18141834
noThrow = true;
18151835
break;
18161836

1817-
// Not sure how to handle optimization involving the rest of these helpers
1818-
default:
1837+
case CORINFO_HELP_TAILCALL: // Never present on stack at the time of GC.
1838+
case CORINFO_HELP_STACK_PROBE:
1839+
case CORINFO_HELP_CHECK_OBJ:
1840+
case CORINFO_HELP_VALIDATE_INDIRECT_CALL:
1841+
case CORINFO_HELP_PROF_FCN_LEAVE:
1842+
case CORINFO_HELP_PROF_FCN_ENTER:
1843+
case CORINFO_HELP_PROF_FCN_TAILCALL:
1844+
isNoGC = true;
1845+
mutatesHeap = true; // Conservatively.
1846+
break;
18191847

1820-
// The most pessimistic results are returned for these helpers
1848+
default:
1849+
// The most pessimistic results are returned for these helpers.
18211850
mutatesHeap = true;
18221851
break;
18231852
}
@@ -1830,6 +1859,7 @@ void HelperCallProperties::init()
18301859
m_mutatesHeap[helper] = mutatesHeap;
18311860
m_mayRunCctor[helper] = mayRunCctor;
18321861
m_isNoEscape[helper] = isNoEscape;
1862+
m_isNoGC[helper] = isNoGC;
18331863
}
18341864
}
18351865

src/coreclr/jit/utils.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ class HelperCallProperties
591591
bool m_mutatesHeap[CORINFO_HELP_COUNT];
592592
bool m_mayRunCctor[CORINFO_HELP_COUNT];
593593
bool m_isNoEscape[CORINFO_HELP_COUNT];
594+
bool m_isNoGC[CORINFO_HELP_COUNT];
594595

595596
void init();
596597

@@ -655,6 +656,13 @@ class HelperCallProperties
655656
assert(helperId < CORINFO_HELP_COUNT);
656657
return m_isNoEscape[helperId];
657658
}
659+
660+
bool IsNoGC(CorInfoHelpFunc helperId)
661+
{
662+
assert(helperId > CORINFO_HELP_UNDEF);
663+
assert(helperId < CORINFO_HELP_COUNT);
664+
return m_isNoGC[helperId];
665+
}
658666
};
659667

660668
//*****************************************************************************

0 commit comments

Comments
 (0)