Skip to content

Commit 4071a31

Browse files
authored
JIT: Extract StructSegments to its own file (#104432)
Also move the function to compute the significant segments for a class handle from `Promotion` to `Compiler`.
1 parent e78b72b commit 4071a31

File tree

8 files changed

+432
-416
lines changed

8 files changed

+432
-416
lines changed

src/coreclr/jit/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ set( JIT_SOURCES
178178
ssabuilder.cpp
179179
ssarenamestate.cpp
180180
stacklevelsetter.cpp
181+
structsegments.cpp
181182
switchrecognition.cpp
182183
treelifeupdater.cpp
183184
unwind.cpp
@@ -379,6 +380,7 @@ set( JIT_HEADERS
379380
ssaconfig.h
380381
ssarenamestate.h
381382
stacklevelsetter.h
383+
structsegments.h
382384
target.h
383385
targetx86.h
384386
targetamd64.h

src/coreclr/jit/compiler.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1990,6 +1990,7 @@ void Compiler::compInit(ArenaAllocator* pAlloc,
19901990
m_outlinedCompositeSsaNums = nullptr;
19911991
m_nodeToLoopMemoryBlockMap = nullptr;
19921992
m_signatureToLookupInfoMap = nullptr;
1993+
m_significantSegmentsMap = nullptr;
19931994
fgSsaPassesCompleted = 0;
19941995
fgSsaValid = false;
19951996
fgVNPassesCompleted = 0;
@@ -8373,6 +8374,67 @@ void Compiler::TransferTestDataToNode(GenTree* from, GenTree* to)
83738374

83748375
#endif // DEBUG
83758376

8377+
//------------------------------------------------------------------------
8378+
// GetSignificantSegments:
8379+
// Compute a segment tree containing all significant (non-padding) segments
8380+
// for the specified class layout.
8381+
//
8382+
// Parameters:
8383+
// layout - The layout
8384+
//
8385+
// Returns:
8386+
// Segment tree containing all significant parts of the layout.
8387+
//
8388+
const StructSegments& Compiler::GetSignificantSegments(ClassLayout* layout)
8389+
{
8390+
StructSegments* cached;
8391+
if ((m_significantSegmentsMap != nullptr) && m_significantSegmentsMap->Lookup(layout, &cached))
8392+
{
8393+
return *cached;
8394+
}
8395+
8396+
COMP_HANDLE compHnd = info.compCompHnd;
8397+
8398+
StructSegments* newSegments = new (this, CMK_Promotion) StructSegments(getAllocator(CMK_Promotion));
8399+
8400+
if (layout->IsBlockLayout())
8401+
{
8402+
newSegments->Add(StructSegments::Segment(0, layout->GetSize()));
8403+
}
8404+
else
8405+
{
8406+
CORINFO_TYPE_LAYOUT_NODE nodes[256];
8407+
size_t numNodes = ArrLen(nodes);
8408+
GetTypeLayoutResult result = compHnd->getTypeLayout(layout->GetClassHandle(), nodes, &numNodes);
8409+
8410+
if (result != GetTypeLayoutResult::Success)
8411+
{
8412+
newSegments->Add(StructSegments::Segment(0, layout->GetSize()));
8413+
}
8414+
else
8415+
{
8416+
for (size_t i = 0; i < numNodes; i++)
8417+
{
8418+
const CORINFO_TYPE_LAYOUT_NODE& node = nodes[i];
8419+
if ((node.type != CORINFO_TYPE_VALUECLASS) || (node.simdTypeHnd != NO_CLASS_HANDLE) ||
8420+
node.hasSignificantPadding)
8421+
{
8422+
newSegments->Add(StructSegments::Segment(node.offset, node.offset + node.size));
8423+
}
8424+
}
8425+
}
8426+
}
8427+
8428+
if (m_significantSegmentsMap == nullptr)
8429+
{
8430+
m_significantSegmentsMap = new (this, CMK_Promotion) ClassLayoutStructSegmentsMap(getAllocator(CMK_Promotion));
8431+
}
8432+
8433+
m_significantSegmentsMap->Set(layout, newSegments);
8434+
8435+
return *newSegments;
8436+
}
8437+
83768438
/*
83778439
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
83788440
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

src/coreclr/jit/compiler.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
4343
#include "valuenum.h"
4444
#include "scev.h"
4545
#include "namedintrinsiclist.h"
46+
#include "structsegments.h"
4647
#ifdef LATE_DISASM
4748
#include "disasm.h"
4849
#endif
@@ -5630,6 +5631,11 @@ class Compiler
56305631
return m_signatureToLookupInfoMap;
56315632
}
56325633

5634+
const StructSegments& GetSignificantSegments(ClassLayout* layout);
5635+
5636+
typedef JitHashTable<ClassLayout*, JitPtrKeyFuncs<ClassLayout>, class StructSegments*> ClassLayoutStructSegmentsMap;
5637+
ClassLayoutStructSegmentsMap* m_significantSegmentsMap;
5638+
56335639
#ifdef SWIFT_SUPPORT
56345640
typedef JitHashTable<CORINFO_CLASS_HANDLE, JitPtrKeyFuncs<struct CORINFO_CLASS_STRUCT_>, CORINFO_SWIFT_LOWERING*> SwiftLoweringMap;
56355641
SwiftLoweringMap* m_swiftLoweringCache;

0 commit comments

Comments
 (0)