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

Skip stp/ldp only for unwind portion of prolog/epilog #85657

Merged
merged 4 commits into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 1 addition & 1 deletion src/coreclr/jit/codegencommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5969,6 +5969,7 @@ void CodeGen::genFnProlog()
genEstablishFramePointer(compiler->codeGen->genSPtoFPdelta(), reportUnwindData);
}
#endif // TARGET_AMD64
compiler->unwindEndProlog();

//-------------------------------------------------------------------------
//
Expand Down Expand Up @@ -6296,7 +6297,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 @@ -9271,6 +9271,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
4 changes: 4 additions & 0 deletions src/coreclr/jit/unwindamd64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ short Compiler::mapRegNumToDwarfReg(regNumber reg)
//
void Compiler::unwindBegProlog()
{
compGeneratingUnwindProlog = true;
kunalspathak marked this conversation as resolved.
Show resolved Hide resolved
#ifdef UNIX_AMD64_ABI
if (generateCFIUnwindCodes())
{
Expand Down Expand Up @@ -129,6 +130,7 @@ void Compiler::unwindBegPrologWindows()
void Compiler::unwindEndProlog()
{
assert(compGeneratingProlog);
compGeneratingUnwindProlog = false;
kunalspathak marked this conversation as resolved.
Show resolved Hide resolved
}

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

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

//------------------------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/jit/unwindarm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
void Compiler::unwindBegProlog()
{
assert(compGeneratingProlog);
compGeneratingUnwindProlog = true;

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

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

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

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

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

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

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

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

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

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

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

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