From f26852e51fc4954a07296cb7b9d0206dca10f8a2 Mon Sep 17 00:00:00 2001 From: Mike Danes Date: Sat, 16 Jun 2018 23:07:49 +0300 Subject: [PATCH] Remove Compiler::impSmallStack Memory allocation via ArenaAllocator is cheap so it's not worth having this inline array that ends up wasting 384 bytes when a larger stack is needed. Care needs to be taken when inlining to avoid allocating a new stack every time - just steal the stack of the inliner compiler (after ensuring that it is large enough). --- src/jit/compiler.h | 2 -- src/jit/importer.cpp | 29 +++++++++++++++++++++-------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/jit/compiler.h b/src/jit/compiler.h index 0a51e1f..efbf0a5 100644 --- a/src/jit/compiler.h +++ b/src/jit/compiler.h @@ -3004,8 +3004,6 @@ protected: #define SMALL_STACK_SIZE 16 // number of elements in impSmallStack - StackEntry impSmallStack[SMALL_STACK_SIZE]; // Use this array if possible - struct SavedStack // used to save/restore stack contents. { unsigned ssDepth; // number of values on stack diff --git a/src/jit/importer.cpp b/src/jit/importer.cpp index 8ec9303..0fafa77 100644 --- a/src/jit/importer.cpp +++ b/src/jit/importer.cpp @@ -17438,26 +17438,39 @@ void Compiler::impImport(BasicBlock* method) } #endif - /* Allocate the stack contents */ + Compiler* inlineRoot = impInlineRoot(); - if (info.compMaxStack <= _countof(impSmallStack)) + if (info.compMaxStack <= SMALL_STACK_SIZE) { - /* Use local variable, don't waste time allocating on the heap */ - - impStkSize = _countof(impSmallStack); - verCurrentState.esStack = impSmallStack; + impStkSize = SMALL_STACK_SIZE; } else { - impStkSize = info.compMaxStack; + impStkSize = info.compMaxStack; + } + + if (this == inlineRoot) + { + // Allocate the stack contents verCurrentState.esStack = new (this, CMK_ImpStack) StackEntry[impStkSize]; } + else + { + // This is the inlinee compiler, steal the stack from the inliner compiler + // (after ensuring that it is large enough). + if (inlineRoot->impStkSize < impStkSize) + { + inlineRoot->impStkSize = impStkSize; + inlineRoot->verCurrentState.esStack = new (this, CMK_ImpStack) StackEntry[impStkSize]; + } + + verCurrentState.esStack = inlineRoot->verCurrentState.esStack; + } // initialize the entry state at start of method verInitCurrentState(); // Initialize stuff related to figuring "spill cliques" (see spec comment for impGetSpillTmpBase). - Compiler* inlineRoot = impInlineRoot(); if (this == inlineRoot) // These are only used on the root of the inlining tree. { // We have initialized these previously, but to size 0. Make them larger. -- 2.7.4