Skip to content

Commit

Permalink
JIT: Extract StructSegments to its own file (#104432)
Browse files Browse the repository at this point in the history
Also move the function to compute the significant segments for a class
handle from `Promotion` to `Compiler`.
  • Loading branch information
jakobbotsch authored Jul 4, 2024
1 parent e78b72b commit 4071a31
Show file tree
Hide file tree
Showing 8 changed files with 432 additions and 416 deletions.
2 changes: 2 additions & 0 deletions src/coreclr/jit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ set( JIT_SOURCES
ssabuilder.cpp
ssarenamestate.cpp
stacklevelsetter.cpp
structsegments.cpp
switchrecognition.cpp
treelifeupdater.cpp
unwind.cpp
Expand Down Expand Up @@ -379,6 +380,7 @@ set( JIT_HEADERS
ssaconfig.h
ssarenamestate.h
stacklevelsetter.h
structsegments.h
target.h
targetx86.h
targetamd64.h
Expand Down
62 changes: 62 additions & 0 deletions src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1990,6 +1990,7 @@ void Compiler::compInit(ArenaAllocator* pAlloc,
m_outlinedCompositeSsaNums = nullptr;
m_nodeToLoopMemoryBlockMap = nullptr;
m_signatureToLookupInfoMap = nullptr;
m_significantSegmentsMap = nullptr;
fgSsaPassesCompleted = 0;
fgSsaValid = false;
fgVNPassesCompleted = 0;
Expand Down Expand Up @@ -8373,6 +8374,67 @@ void Compiler::TransferTestDataToNode(GenTree* from, GenTree* to)

#endif // DEBUG

//------------------------------------------------------------------------
// GetSignificantSegments:
// Compute a segment tree containing all significant (non-padding) segments
// for the specified class layout.
//
// Parameters:
// layout - The layout
//
// Returns:
// Segment tree containing all significant parts of the layout.
//
const StructSegments& Compiler::GetSignificantSegments(ClassLayout* layout)
{
StructSegments* cached;
if ((m_significantSegmentsMap != nullptr) && m_significantSegmentsMap->Lookup(layout, &cached))
{
return *cached;
}

COMP_HANDLE compHnd = info.compCompHnd;

StructSegments* newSegments = new (this, CMK_Promotion) StructSegments(getAllocator(CMK_Promotion));

if (layout->IsBlockLayout())
{
newSegments->Add(StructSegments::Segment(0, layout->GetSize()));
}
else
{
CORINFO_TYPE_LAYOUT_NODE nodes[256];
size_t numNodes = ArrLen(nodes);
GetTypeLayoutResult result = compHnd->getTypeLayout(layout->GetClassHandle(), nodes, &numNodes);

if (result != GetTypeLayoutResult::Success)
{
newSegments->Add(StructSegments::Segment(0, layout->GetSize()));
}
else
{
for (size_t i = 0; i < numNodes; i++)
{
const CORINFO_TYPE_LAYOUT_NODE& node = nodes[i];
if ((node.type != CORINFO_TYPE_VALUECLASS) || (node.simdTypeHnd != NO_CLASS_HANDLE) ||
node.hasSignificantPadding)
{
newSegments->Add(StructSegments::Segment(node.offset, node.offset + node.size));
}
}
}
}

if (m_significantSegmentsMap == nullptr)
{
m_significantSegmentsMap = new (this, CMK_Promotion) ClassLayoutStructSegmentsMap(getAllocator(CMK_Promotion));
}

m_significantSegmentsMap->Set(layout, newSegments);

return *newSegments;
}

/*
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Expand Down
6 changes: 6 additions & 0 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include "valuenum.h"
#include "scev.h"
#include "namedintrinsiclist.h"
#include "structsegments.h"
#ifdef LATE_DISASM
#include "disasm.h"
#endif
Expand Down Expand Up @@ -5630,6 +5631,11 @@ class Compiler
return m_signatureToLookupInfoMap;
}

const StructSegments& GetSignificantSegments(ClassLayout* layout);

typedef JitHashTable<ClassLayout*, JitPtrKeyFuncs<ClassLayout>, class StructSegments*> ClassLayoutStructSegmentsMap;
ClassLayoutStructSegmentsMap* m_significantSegmentsMap;

#ifdef SWIFT_SUPPORT
typedef JitHashTable<CORINFO_CLASS_HANDLE, JitPtrKeyFuncs<struct CORINFO_CLASS_STRUCT_>, CORINFO_SWIFT_LOWERING*> SwiftLoweringMap;
SwiftLoweringMap* m_swiftLoweringCache;
Expand Down
Loading

0 comments on commit 4071a31

Please sign in to comment.