From 2f0628d380fce3c55edab8ee327b232f49629092 Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Tue, 2 May 2023 07:44:21 -0700 Subject: [PATCH 1/3] Skip stp/ldp only for unwind portion of prolog/epilog --- src/coreclr/jit/codegencommon.cpp | 2 +- src/coreclr/jit/compiler.cpp | 6 ++++-- src/coreclr/jit/compiler.h | 2 ++ src/coreclr/jit/emitarm64.cpp | 12 +++--------- src/coreclr/jit/unwindamd64.cpp | 4 ++++ src/coreclr/jit/unwindarm.cpp | 4 ++++ src/coreclr/jit/unwindloongarch64.cpp | 4 ++++ src/coreclr/jit/unwindriscv64.cpp | 4 ++++ 8 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/coreclr/jit/codegencommon.cpp b/src/coreclr/jit/codegencommon.cpp index 721594e93e926..35273e0d9a6c8 100644 --- a/src/coreclr/jit/codegencommon.cpp +++ b/src/coreclr/jit/codegencommon.cpp @@ -5969,6 +5969,7 @@ void CodeGen::genFnProlog() genEstablishFramePointer(compiler->codeGen->genSPtoFPdelta(), reportUnwindData); } #endif // TARGET_AMD64 + compiler->unwindEndProlog(); //------------------------------------------------------------------------- // @@ -6296,7 +6297,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 76b30f063f020..0a28bf393398c 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 4420a7662a36c..44acc438b9442 100644 --- a/src/coreclr/jit/compiler.h +++ b/src/coreclr/jit/compiler.h @@ -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 diff --git a/src/coreclr/jit/emitarm64.cpp b/src/coreclr/jit/emitarm64.cpp index c35b9c6573256..0d18ffcc9aee3 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 b5fdf604e55ed..a91b1cce96965 100644 --- a/src/coreclr/jit/unwindamd64.cpp +++ b/src/coreclr/jit/unwindamd64.cpp @@ -86,6 +86,7 @@ short Compiler::mapRegNumToDwarfReg(regNumber reg) // void Compiler::unwindBegProlog() { + compGeneratingUnwindProlog = true; #ifdef UNIX_AMD64_ABI if (generateCFIUnwindCodes()) { @@ -129,6 +130,7 @@ void Compiler::unwindBegPrologWindows() void Compiler::unwindEndProlog() { assert(compGeneratingProlog); + compGeneratingUnwindProlog = false; } //------------------------------------------------------------------------ @@ -138,6 +140,7 @@ void Compiler::unwindEndProlog() void Compiler::unwindBegEpilog() { assert(compGeneratingEpilog); + compGeneratingUnwindEpilog = true; } //------------------------------------------------------------------------ @@ -147,6 +150,7 @@ void Compiler::unwindBegEpilog() void Compiler::unwindEndEpilog() { assert(compGeneratingEpilog); + compGeneratingUnwindEpilog = false; } //------------------------------------------------------------------------ diff --git a/src/coreclr/jit/unwindarm.cpp b/src/coreclr/jit/unwindarm.cpp index bec57b68670dd..aae8d86690ebc 100644 --- a/src/coreclr/jit/unwindarm.cpp +++ b/src/coreclr/jit/unwindarm.cpp @@ -140,6 +140,7 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX void Compiler::unwindBegProlog() { assert(compGeneratingProlog); + compGeneratingUnwindProlog = true; #if defined(FEATURE_CFI_SUPPORT) if (generateCFIUnwindCodes()) @@ -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()) @@ -186,6 +189,7 @@ void Compiler::unwindBegEpilog() void Compiler::unwindEndEpilog() { assert(compGeneratingEpilog); + compGeneratingUnwindEpilog = false; } #if defined(TARGET_ARM) diff --git a/src/coreclr/jit/unwindloongarch64.cpp b/src/coreclr/jit/unwindloongarch64.cpp index 2170961aa813c..30f86f22b53ff 100644 --- a/src/coreclr/jit/unwindloongarch64.cpp +++ b/src/coreclr/jit/unwindloongarch64.cpp @@ -891,6 +891,7 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX void Compiler::unwindBegProlog() { assert(compGeneratingProlog); + compGeneratingUnwindProlog = true; #if defined(FEATURE_CFI_SUPPORT) if (generateCFIUnwindCodes()) @@ -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()) @@ -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 diff --git a/src/coreclr/jit/unwindriscv64.cpp b/src/coreclr/jit/unwindriscv64.cpp index bc59e66321f4c..f31967e2989ae 100644 --- a/src/coreclr/jit/unwindriscv64.cpp +++ b/src/coreclr/jit/unwindriscv64.cpp @@ -669,6 +669,7 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX void Compiler::unwindBegProlog() { assert(compGeneratingProlog); + compGeneratingUnwindProlog = true; #if defined(FEATURE_CFI_SUPPORT) if (generateCFIUnwindCodes()) @@ -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()) @@ -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 From 43147d3fd052033bf200ed52e10aae13178cc978 Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Tue, 2 May 2023 07:55:09 -0700 Subject: [PATCH 2/3] Rename unwindarm.cpp -> unwindarmarch.cpp --- src/coreclr/jit/CMakeLists.txt | 4 ++-- src/coreclr/jit/{unwindarm.cpp => unwindarmarch.cpp} | 4 ---- 2 files changed, 2 insertions(+), 6 deletions(-) rename src/coreclr/jit/{unwindarm.cpp => unwindarmarch.cpp} (99%) diff --git a/src/coreclr/jit/CMakeLists.txt b/src/coreclr/jit/CMakeLists.txt index db3634b332dc0..a6eea6c6380a7 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/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 aae8d86690ebc..b64b3ff85109f 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 @@ -2583,5 +2581,3 @@ void DumpUnwindInfo(Compiler* comp, #endif // DEBUG #endif // defined(TARGET_ARM) - -#endif // TARGET_ARMARCH From 7d97cad159b8e198699192b99de3843714cf48c8 Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Tue, 2 May 2023 16:03:08 -0700 Subject: [PATCH 3/3] review feedback --- src/coreclr/jit/unwindamd64.cpp | 4 ++++ src/coreclr/jit/unwindarmarch.cpp | 4 ++++ src/coreclr/jit/unwindloongarch64.cpp | 4 ++++ src/coreclr/jit/unwindriscv64.cpp | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/src/coreclr/jit/unwindamd64.cpp b/src/coreclr/jit/unwindamd64.cpp index a91b1cce96965..549c4e9910567 100644 --- a/src/coreclr/jit/unwindamd64.cpp +++ b/src/coreclr/jit/unwindamd64.cpp @@ -86,6 +86,7 @@ short Compiler::mapRegNumToDwarfReg(regNumber reg) // void Compiler::unwindBegProlog() { + assert(!compGeneratingUnwindProlog); compGeneratingUnwindProlog = true; #ifdef UNIX_AMD64_ABI if (generateCFIUnwindCodes()) @@ -130,6 +131,7 @@ void Compiler::unwindBegPrologWindows() void Compiler::unwindEndProlog() { assert(compGeneratingProlog); + assert(compGeneratingUnwindProlog); compGeneratingUnwindProlog = false; } @@ -140,6 +142,7 @@ void Compiler::unwindEndProlog() void Compiler::unwindBegEpilog() { assert(compGeneratingEpilog); + assert(!compGeneratingUnwindEpilog); compGeneratingUnwindEpilog = true; } @@ -150,6 +153,7 @@ void Compiler::unwindBegEpilog() void Compiler::unwindEndEpilog() { assert(compGeneratingEpilog); + assert(compGeneratingUnwindEpilog); compGeneratingUnwindEpilog = false; } diff --git a/src/coreclr/jit/unwindarmarch.cpp b/src/coreclr/jit/unwindarmarch.cpp index b64b3ff85109f..b54ce016c16a5 100644 --- a/src/coreclr/jit/unwindarmarch.cpp +++ b/src/coreclr/jit/unwindarmarch.cpp @@ -138,6 +138,7 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX void Compiler::unwindBegProlog() { assert(compGeneratingProlog); + assert(!compGeneratingUnwindProlog); compGeneratingUnwindProlog = true; #if defined(FEATURE_CFI_SUPPORT) @@ -166,12 +167,14 @@ 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) @@ -187,6 +190,7 @@ void Compiler::unwindBegEpilog() void Compiler::unwindEndEpilog() { assert(compGeneratingEpilog); + assert(compGeneratingUnwindEpilog); compGeneratingUnwindEpilog = false; } diff --git a/src/coreclr/jit/unwindloongarch64.cpp b/src/coreclr/jit/unwindloongarch64.cpp index 30f86f22b53ff..3aa5fd668d40c 100644 --- a/src/coreclr/jit/unwindloongarch64.cpp +++ b/src/coreclr/jit/unwindloongarch64.cpp @@ -891,6 +891,7 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX void Compiler::unwindBegProlog() { assert(compGeneratingProlog); + assert(!compGeneratingUnwindProlog); compGeneratingUnwindProlog = true; #if defined(FEATURE_CFI_SUPPORT) @@ -919,12 +920,14 @@ 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) @@ -940,6 +943,7 @@ void Compiler::unwindBegEpilog() void Compiler::unwindEndEpilog() { assert(compGeneratingEpilog); + assert(compGeneratingUnwindEpilog); compGeneratingUnwindEpilog = false; } diff --git a/src/coreclr/jit/unwindriscv64.cpp b/src/coreclr/jit/unwindriscv64.cpp index f31967e2989ae..e1a9eb06f8e15 100644 --- a/src/coreclr/jit/unwindriscv64.cpp +++ b/src/coreclr/jit/unwindriscv64.cpp @@ -669,6 +669,7 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX void Compiler::unwindBegProlog() { assert(compGeneratingProlog); + assert(!compGeneratingUnwindProlog); compGeneratingUnwindProlog = true; #if defined(FEATURE_CFI_SUPPORT) @@ -697,12 +698,14 @@ 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) @@ -718,6 +721,7 @@ void Compiler::unwindBegEpilog() void Compiler::unwindEndEpilog() { assert(compGeneratingEpilog); + assert(compGeneratingUnwindEpilog); compGeneratingUnwindEpilog = false; }