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.

Commit migrated from https://github.com/dotnet/coreclr/commit/2e0cc331a72b2473317f9652646bcc6796ece449

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

index 755859a..ef20943 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 366a060..41c3435 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);
     }