Skip to content

Commit

Permalink
Skip stp/ldp only for unwind portion of prolog/epilog (#85657)
Browse files Browse the repository at this point in the history
* Skip stp/ldp only for unwind portion of prolog/epilog

* Rename unwindarm.cpp -> unwindarmarch.cpp

* review feedback
  • Loading branch information
kunalspathak authored May 3, 2023
1 parent 56eff9f commit 372b01f
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/coreclr/jit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ set( JIT_ARM_SOURCES
lsraarmarch.cpp
lsraarm.cpp
targetarm.cpp
unwindarm.cpp
unwindarmarch.cpp
)

set( JIT_I386_SOURCES
Expand Down Expand Up @@ -238,7 +238,7 @@ set( JIT_ARM64_SOURCES
simd.cpp
simdashwintrinsic.cpp
targetarm64.cpp
unwindarm.cpp
unwindarmarch.cpp
unwindarm64.cpp
hwintrinsicarm64.cpp
hwintrinsiccodegenarm64.cpp
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/codegencommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5970,6 +5970,7 @@ void CodeGen::genFnProlog()
genEstablishFramePointer(compiler->codeGen->genSPtoFPdelta(), reportUnwindData);
}
#endif // TARGET_AMD64
compiler->unwindEndProlog();

//-------------------------------------------------------------------------
//
Expand Down Expand Up @@ -6297,7 +6298,6 @@ void CodeGen::genFnProlog()
#endif // defined(DEBUG) && defined(TARGET_XARCH)

GetEmitter()->emitEndProlog();
compiler->unwindEndProlog();
}
#ifdef _PREFAST_
#pragma warning(pop)
Expand Down
6 changes: 4 additions & 2 deletions src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1928,8 +1928,10 @@ void Compiler::compInit(ArenaAllocator* pAlloc,
compNeedsGSSecurityCookie = false;
compGSReorderStackLayout = false;

compGeneratingProlog = false;
compGeneratingEpilog = false;
compGeneratingProlog = false;
compGeneratingEpilog = false;
compGeneratingUnwindProlog = false;
compGeneratingUnwindEpilog = false;

compPostImportationCleanupDone = false;
compLSRADone = false;
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -9289,6 +9289,8 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

bool compGeneratingProlog;
bool compGeneratingEpilog;
bool compGeneratingUnwindProlog;
bool compGeneratingUnwindEpilog;
bool compNeedsGSSecurityCookie; // There is an unsafe buffer (or localloc) on the stack.
// Insert cookie on frame and code to check the cookie, like VC++ -GS.
bool compGSReorderStackLayout; // There is an unsafe buffer on the stack, reorder locals and make local
Expand Down
12 changes: 3 additions & 9 deletions src/coreclr/jit/emitarm64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16645,18 +16645,12 @@ emitter::RegisterOrder emitter::IsOptimizableLdrStrWithPair(
return eRO_none;
}

// Don't remove instructions whilst in prologs or epilogs, as these contain "unwindable"
// parts, where we need to report unwind codes to the OS,
if (emitIGisInProlog(emitCurIG) || emitIGisInEpilog(emitCurIG))
if (emitComp->compGeneratingUnwindProlog || emitComp->compGeneratingUnwindEpilog)
{
// Don't remove instructions while generating "unwind" part of prologs or epilogs,
// because for those instructions, we need to report unwind codes to the OS.
return eRO_none;
}
#ifdef FEATURE_EH_FUNCLETS
if (emitIGisInFuncletProlog(emitCurIG) || emitIGisInFuncletEpilog(emitCurIG))
{
return eRO_none;
}
#endif

return optimisationOrder;
}
Expand Down
8 changes: 8 additions & 0 deletions src/coreclr/jit/unwindamd64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ short Compiler::mapRegNumToDwarfReg(regNumber reg)
//
void Compiler::unwindBegProlog()
{
assert(!compGeneratingUnwindProlog);
compGeneratingUnwindProlog = true;
#ifdef UNIX_AMD64_ABI
if (generateCFIUnwindCodes())
{
Expand Down Expand Up @@ -129,6 +131,8 @@ void Compiler::unwindBegPrologWindows()
void Compiler::unwindEndProlog()
{
assert(compGeneratingProlog);
assert(compGeneratingUnwindProlog);
compGeneratingUnwindProlog = false;
}

//------------------------------------------------------------------------
Expand All @@ -138,6 +142,8 @@ void Compiler::unwindEndProlog()
void Compiler::unwindBegEpilog()
{
assert(compGeneratingEpilog);
assert(!compGeneratingUnwindEpilog);
compGeneratingUnwindEpilog = true;
}

//------------------------------------------------------------------------
Expand All @@ -147,6 +153,8 @@ void Compiler::unwindBegEpilog()
void Compiler::unwindEndEpilog()
{
assert(compGeneratingEpilog);
assert(compGeneratingUnwindEpilog);
compGeneratingUnwindEpilog = false;
}

//------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,6 @@ short Compiler::mapRegNumToDwarfReg(regNumber reg)
}
#endif // TARGET_ARM && FEATURE_CFI_SUPPORT

#ifdef TARGET_ARMARCH

/*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XX XX
Expand All @@ -140,6 +138,8 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
void Compiler::unwindBegProlog()
{
assert(compGeneratingProlog);
assert(!compGeneratingUnwindProlog);
compGeneratingUnwindProlog = true;

#if defined(FEATURE_CFI_SUPPORT)
if (generateCFIUnwindCodes())
Expand Down Expand Up @@ -167,11 +167,15 @@ void Compiler::unwindBegProlog()
void Compiler::unwindEndProlog()
{
assert(compGeneratingProlog);
assert(compGeneratingUnwindProlog);
compGeneratingUnwindProlog = false;
}

void Compiler::unwindBegEpilog()
{
assert(compGeneratingEpilog);
assert(!compGeneratingUnwindEpilog);
compGeneratingUnwindEpilog = true;

#if defined(FEATURE_CFI_SUPPORT)
if (generateCFIUnwindCodes())
Expand All @@ -186,6 +190,8 @@ void Compiler::unwindBegEpilog()
void Compiler::unwindEndEpilog()
{
assert(compGeneratingEpilog);
assert(compGeneratingUnwindEpilog);
compGeneratingUnwindEpilog = false;
}

#if defined(TARGET_ARM)
Expand Down Expand Up @@ -2579,5 +2585,3 @@ void DumpUnwindInfo(Compiler* comp,
#endif // DEBUG

#endif // defined(TARGET_ARM)

#endif // TARGET_ARMARCH
8 changes: 8 additions & 0 deletions src/coreclr/jit/unwindloongarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,8 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
void Compiler::unwindBegProlog()
{
assert(compGeneratingProlog);
assert(!compGeneratingUnwindProlog);
compGeneratingUnwindProlog = true;

#if defined(FEATURE_CFI_SUPPORT)
if (generateCFIUnwindCodes())
Expand Down Expand Up @@ -918,11 +920,15 @@ void Compiler::unwindBegProlog()
void Compiler::unwindEndProlog()
{
assert(compGeneratingProlog);
assert(compGeneratingUnwindProlog);
compGeneratingUnwindProlog = false;
}

void Compiler::unwindBegEpilog()
{
assert(compGeneratingEpilog);
assert(!compGeneratingUnwindEpilog);
compGeneratingUnwindEpilog = true;

#if defined(FEATURE_CFI_SUPPORT)
if (generateCFIUnwindCodes())
Expand All @@ -937,6 +943,8 @@ void Compiler::unwindBegEpilog()
void Compiler::unwindEndEpilog()
{
assert(compGeneratingEpilog);
assert(compGeneratingUnwindEpilog);
compGeneratingUnwindEpilog = false;
}

// The instructions between the last captured "current state" and the current instruction
Expand Down
8 changes: 8 additions & 0 deletions src/coreclr/jit/unwindriscv64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,8 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
void Compiler::unwindBegProlog()
{
assert(compGeneratingProlog);
assert(!compGeneratingUnwindProlog);
compGeneratingUnwindProlog = true;

#if defined(FEATURE_CFI_SUPPORT)
if (generateCFIUnwindCodes())
Expand Down Expand Up @@ -696,11 +698,15 @@ void Compiler::unwindBegProlog()
void Compiler::unwindEndProlog()
{
assert(compGeneratingProlog);
assert(compGeneratingUnwindProlog);
compGeneratingUnwindProlog = false;
}

void Compiler::unwindBegEpilog()
{
assert(compGeneratingEpilog);
assert(!compGeneratingUnwindEpilog);
compGeneratingUnwindEpilog = true;

#if defined(FEATURE_CFI_SUPPORT)
if (generateCFIUnwindCodes())
Expand All @@ -715,6 +721,8 @@ void Compiler::unwindBegEpilog()
void Compiler::unwindEndEpilog()
{
assert(compGeneratingEpilog);
assert(compGeneratingUnwindEpilog);
compGeneratingUnwindEpilog = false;
}

// The instructions between the last captured "current state" and the current instruction
Expand Down

0 comments on commit 372b01f

Please sign in to comment.