diff --git a/src/coreclr/jit/CMakeLists.txt b/src/coreclr/jit/CMakeLists.txt index db3634b332dc06..a6eea6c6380a7b 100644 --- a/src/coreclr/jit/CMakeLists.txt +++ b/src/coreclr/jit/CMakeLists.txt @@ -210,7 +210,7 @@ set( JIT_ARM_SOURCES lsraarmarch.cpp lsraarm.cpp targetarm.cpp - unwindarm.cpp + unwindarmarch.cpp ) set( JIT_I386_SOURCES @@ -238,7 +238,7 @@ set( JIT_ARM64_SOURCES simd.cpp simdashwintrinsic.cpp targetarm64.cpp - unwindarm.cpp + unwindarmarch.cpp unwindarm64.cpp hwintrinsicarm64.cpp hwintrinsiccodegenarm64.cpp diff --git a/src/coreclr/jit/codegencommon.cpp b/src/coreclr/jit/codegencommon.cpp index d567518ffbb1b1..c0aa4c78f726bf 100644 --- a/src/coreclr/jit/codegencommon.cpp +++ b/src/coreclr/jit/codegencommon.cpp @@ -5970,6 +5970,7 @@ void CodeGen::genFnProlog() genEstablishFramePointer(compiler->codeGen->genSPtoFPdelta(), reportUnwindData); } #endif // TARGET_AMD64 + compiler->unwindEndProlog(); //------------------------------------------------------------------------- // @@ -6297,7 +6298,6 @@ void CodeGen::genFnProlog() #endif // defined(DEBUG) && defined(TARGET_XARCH) GetEmitter()->emitEndProlog(); - compiler->unwindEndProlog(); } #ifdef _PREFAST_ #pragma warning(pop) diff --git a/src/coreclr/jit/compiler.cpp b/src/coreclr/jit/compiler.cpp index 510cb750378d0f..b75d0feccda566 100644 --- a/src/coreclr/jit/compiler.cpp +++ b/src/coreclr/jit/compiler.cpp @@ -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; diff --git a/src/coreclr/jit/compiler.h b/src/coreclr/jit/compiler.h index 4fc53728d118c4..56924953818371 100644 --- a/src/coreclr/jit/compiler.h +++ b/src/coreclr/jit/compiler.h @@ -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 diff --git a/src/coreclr/jit/emitarm64.cpp b/src/coreclr/jit/emitarm64.cpp index c35b9c65732566..0d18ffcc9aee3a 100644 --- a/src/coreclr/jit/emitarm64.cpp +++ b/src/coreclr/jit/emitarm64.cpp @@ -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; } diff --git a/src/coreclr/jit/unwindamd64.cpp b/src/coreclr/jit/unwindamd64.cpp index b5fdf604e55ed8..549c4e9910567c 100644 --- a/src/coreclr/jit/unwindamd64.cpp +++ b/src/coreclr/jit/unwindamd64.cpp @@ -86,6 +86,8 @@ short Compiler::mapRegNumToDwarfReg(regNumber reg) // void Compiler::unwindBegProlog() { + assert(!compGeneratingUnwindProlog); + compGeneratingUnwindProlog = true; #ifdef UNIX_AMD64_ABI if (generateCFIUnwindCodes()) { @@ -129,6 +131,8 @@ void Compiler::unwindBegPrologWindows() void Compiler::unwindEndProlog() { assert(compGeneratingProlog); + assert(compGeneratingUnwindProlog); + compGeneratingUnwindProlog = false; } //------------------------------------------------------------------------ @@ -138,6 +142,8 @@ void Compiler::unwindEndProlog() void Compiler::unwindBegEpilog() { assert(compGeneratingEpilog); + assert(!compGeneratingUnwindEpilog); + compGeneratingUnwindEpilog = true; } //------------------------------------------------------------------------ @@ -147,6 +153,8 @@ void Compiler::unwindBegEpilog() void Compiler::unwindEndEpilog() { assert(compGeneratingEpilog); + assert(compGeneratingUnwindEpilog); + compGeneratingUnwindEpilog = false; } //------------------------------------------------------------------------ diff --git a/src/coreclr/jit/unwindarm.cpp b/src/coreclr/jit/unwindarmarch.cpp similarity index 99% rename from src/coreclr/jit/unwindarm.cpp rename to src/coreclr/jit/unwindarmarch.cpp index bec57b68670dd2..b54ce016c16a52 100644 --- a/src/coreclr/jit/unwindarm.cpp +++ b/src/coreclr/jit/unwindarmarch.cpp @@ -126,8 +126,6 @@ short Compiler::mapRegNumToDwarfReg(regNumber reg) } #endif // TARGET_ARM && FEATURE_CFI_SUPPORT -#ifdef TARGET_ARMARCH - /*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XX XX @@ -140,6 +138,8 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX void Compiler::unwindBegProlog() { assert(compGeneratingProlog); + assert(!compGeneratingUnwindProlog); + compGeneratingUnwindProlog = true; #if defined(FEATURE_CFI_SUPPORT) if (generateCFIUnwindCodes()) @@ -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()) @@ -186,6 +190,8 @@ void Compiler::unwindBegEpilog() void Compiler::unwindEndEpilog() { assert(compGeneratingEpilog); + assert(compGeneratingUnwindEpilog); + compGeneratingUnwindEpilog = false; } #if defined(TARGET_ARM) @@ -2579,5 +2585,3 @@ void DumpUnwindInfo(Compiler* comp, #endif // DEBUG #endif // defined(TARGET_ARM) - -#endif // TARGET_ARMARCH diff --git a/src/coreclr/jit/unwindloongarch64.cpp b/src/coreclr/jit/unwindloongarch64.cpp index 2170961aa813c4..3aa5fd668d40c6 100644 --- a/src/coreclr/jit/unwindloongarch64.cpp +++ b/src/coreclr/jit/unwindloongarch64.cpp @@ -891,6 +891,8 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX void Compiler::unwindBegProlog() { assert(compGeneratingProlog); + assert(!compGeneratingUnwindProlog); + compGeneratingUnwindProlog = true; #if defined(FEATURE_CFI_SUPPORT) if (generateCFIUnwindCodes()) @@ -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()) @@ -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 diff --git a/src/coreclr/jit/unwindriscv64.cpp b/src/coreclr/jit/unwindriscv64.cpp index bc59e66321f4c8..e1a9eb06f8e153 100644 --- a/src/coreclr/jit/unwindriscv64.cpp +++ b/src/coreclr/jit/unwindriscv64.cpp @@ -669,6 +669,8 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX void Compiler::unwindBegProlog() { assert(compGeneratingProlog); + assert(!compGeneratingUnwindProlog); + compGeneratingUnwindProlog = true; #if defined(FEATURE_CFI_SUPPORT) if (generateCFIUnwindCodes()) @@ -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()) @@ -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