Skip to content

Commit dd4af0b

Browse files
Coalesce adjacent no-GC regions on x86
1 parent 5ed2d9b commit dd4af0b

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

src/coreclr/jit/gcencode.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2124,21 +2124,35 @@ unsigned PendingArgsStack::pasEnumGCoffs(unsigned iter, unsigned* offs)
21242124
// when reporting interruptible ranges.
21252125
class NoGCRegionEncoder
21262126
{
2127-
BYTE* dest;
2127+
BYTE* dest;
2128+
unsigned lastSize = 0;
2129+
unsigned lastEndOffs = -1;
21282130
public:
2129-
size_t totalSize;
2131+
size_t totalSize = 0;
21302132

21312133
NoGCRegionEncoder(BYTE* dest)
21322134
: dest(dest)
2133-
, totalSize(0)
21342135
{
21352136
}
21362137

21372138
// This callback is called for each insGroup marked with IGF_NOGCINTERRUPT.
21382139
bool operator()(unsigned igFuncIdx, unsigned igOffs, unsigned igSize, unsigned firstInstrSize, bool isInProlog)
21392140
{
2140-
totalSize += encodeUnsigned(dest == NULL ? NULL : dest + totalSize, igOffs);
2141-
totalSize += encodeUnsigned(dest == NULL ? NULL : dest + totalSize, igSize);
2141+
unsigned size;
2142+
if (igOffs == lastEndOffs) // Coalesce adjacent intervals by re-encoding the enlarged size.
2143+
{
2144+
totalSize -= encodeUnsigned(nullptr, lastSize);
2145+
size = lastSize + igSize;
2146+
}
2147+
else
2148+
{
2149+
totalSize += encodeUnsigned(dest == nullptr ? nullptr : dest + totalSize, igOffs);
2150+
size = igSize;
2151+
}
2152+
totalSize += encodeUnsigned(dest == nullptr ? nullptr : dest + totalSize, size);
2153+
2154+
lastSize = size;
2155+
lastEndOffs = igOffs + igSize;
21422156
return true;
21432157
}
21442158
};

0 commit comments

Comments
 (0)