Allocate space for siLatestTrackedScopes on demand
authorMike Danes <onemihaid@hotmail.com>
Sat, 16 Jun 2018 15:56:36 +0000 (18:56 +0300)
committerMike Danes <onemihaid@hotmail.com>
Sat, 30 Jun 2018 19:34:10 +0000 (22:34 +0300)
By the time siLatestTrackedScopes is needed the number of tracked variables is known so we can allocate an array of suitable size. Defaulting to lclMAX_TRACKED requires 4 kbytes and for many small methods that's a waste.

src/jit/codegen.h
src/jit/scopeinfo.cpp

index 755859ad0bc9246bdda27e158c67bda5e31cbba4..ef2094347ef0e239660016ebc1a6047fadee01ac 100644 (file)
@@ -626,7 +626,7 @@ protected:
 
     // Tracks the last entry for each tracked register variable
 
-    siScope* siLatestTrackedScopes[lclMAX_TRACKED];
+    siScope** siLatestTrackedScopes;
 
     IL_OFFSET siLastEndOffs; // IL offset of the (exclusive) end of the last block processed
 
index 366a060d54b8b18d9d6b4f74b466ecf2dc971a7f..41c343548f67d4adbd5b1e32298254d677087870 100644 (file)
@@ -377,19 +377,33 @@ void CodeGen::siInit()
 
     if (compiler->info.compVarScopesCount == 0)
     {
-        return;
+        siLatestTrackedScopes = nullptr;
     }
-
+    else
+    {
 #if FEATURE_EH_FUNCLETS
-    siInFuncletRegion = false;
+        siInFuncletRegion = false;
 #endif // FEATURE_EH_FUNCLETS
 
-    for (unsigned i = 0; i < lclMAX_TRACKED; i++)
-    {
-        siLatestTrackedScopes[i] = nullptr;
-    }
+        unsigned scopeCount = compiler->lvaTrackedCount;
 
-    compiler->compResetScopeLists();
+        if (scopeCount == 0)
+        {
+            siLatestTrackedScopes = nullptr;
+        }
+        else
+        {
+            siLatestTrackedScopes =
+                static_cast<siScope**>(compiler->compGetMemArray(scopeCount, sizeof(siScope*), CMK_SiScope));
+
+            for (unsigned i = 0; i < scopeCount; i++)
+            {
+                siLatestTrackedScopes[i] = nullptr;
+            }
+        }
+
+        compiler->compResetScopeLists();
+    }
 }
 
 /*****************************************************************************
@@ -669,8 +683,6 @@ void CodeGen::siUpdate()
         LclVarDsc* lclVar = &compiler->lvaTable[lclNum];
         assert(lclVar->lvTracked);
 #endif
-
-        siScope* scope = siLatestTrackedScopes[varIndex];
         siEndTrackedScope(varIndex);
     }