Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JIT: Extract StructSegments to its own file #104432

Merged
merged 1 commit into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading