Speed up fgLocalVarLiveness in minopts. (#12665)
authorPat Gavlin <pgavlin@gmail.com>
Mon, 10 Jul 2017 20:43:13 +0000 (15:43 -0500)
committerGitHub <noreply@github.com>
Mon, 10 Jul 2017 20:43:13 +0000 (15:43 -0500)
In particular:
- Do not re-sort lclVars
- Do not run LVA
- Do not set `mustInit`
- Do not set last uses
- Do not perform DSE

src/jit/codegencommon.cpp
src/jit/compiler.h
src/jit/jit.h
src/jit/liveness.cpp
src/jit/lower.cpp
src/jit/lsra.h

index fafb030..2c41293 100644 (file)
@@ -5519,16 +5519,13 @@ void CodeGen::genCheckUseBlockInit()
             continue;
         }
 
-#if CAN_DISABLE_DFA
         /* If we don't know lifetimes of variables, must be conservative */
-
-        if (compiler->opts.MinOpts())
+        if (!compiler->backendRequiresLocalVarLifetimes())
         {
             varDsc->lvMustInit = true;
             noway_assert(!varDsc->lvRegister);
         }
         else
-#endif // CAN_DISABLE_DFA
         {
             if (!varDsc->lvTracked)
             {
index 101cb09..2d5f371 100644 (file)
@@ -910,6 +910,7 @@ class LinearScanInterface
 public:
     virtual void doLinearScan()                                = 0;
     virtual void recordVarLocationsAtStartOfBB(BasicBlock* bb) = 0;
+    virtual bool willEnregisterLocalVars() const               = 0;
 };
 
 LinearScanInterface* getLinearScanAllocator(Compiler* comp);
@@ -3726,6 +3727,15 @@ public:
 
     GenTreeCall* fgGetSharedCCtor(CORINFO_CLASS_HANDLE cls);
 
+    inline bool backendRequiresLocalVarLifetimes()
+    {
+#if defined(LEGACY_BACKEND)
+        return true;
+#else
+        return !opts.MinOpts() || m_pLinearScan->willEnregisterLocalVars();
+#endif
+    }
+
     void fgLocalVarLiveness();
 
     void fgLocalVarLivenessInit();
index 2810b96..d489247 100644 (file)
@@ -407,8 +407,6 @@ typedef ptrdiff_t ssize_t;
 
 #define CSE_INTO_HANDLERS 0
 
-#define CAN_DISABLE_DFA 1 // disable data flow for minopts
-
 #define LARGE_EXPSET 1   // Track 64 or 32 assertions/copies/consts/rangechecks
 #define ASSERTION_PROP 1 // Enable value/assertion propagation
 
index a7162a0..6576c84 100644 (file)
@@ -422,11 +422,8 @@ void Compiler::fgPerBlockLocalVarLiveness()
 
     BasicBlock* block;
 
-#if CAN_DISABLE_DFA
-
-    /* If we're not optimizing at all, things are simple */
-
-    if (opts.MinOpts())
+    // If we don't require accurate local var lifetimes, things are simple.
+    if (!backendRequiresLocalVarLifetimes())
     {
         unsigned   lclNum;
         LclVarDsc* varDsc;
@@ -451,7 +448,6 @@ void Compiler::fgPerBlockLocalVarLiveness()
             VarSetOps::Assign(this, block->bbVarUse, liveAll);
             VarSetOps::Assign(this, block->bbVarDef, liveAll);
             VarSetOps::Assign(this, block->bbLiveIn, liveAll);
-            VarSetOps::Assign(this, block->bbLiveOut, liveAll);
             block->bbMemoryUse     = fullMemoryKindSet;
             block->bbMemoryDef     = fullMemoryKindSet;
             block->bbMemoryLiveIn  = fullMemoryKindSet;
@@ -465,6 +461,7 @@ void Compiler::fgPerBlockLocalVarLiveness()
                     VarSetOps::AssignNoCopy(this, block->bbLiveOut, VarSetOps::MakeEmpty(this));
                     break;
                 default:
+                    VarSetOps::Assign(this, block->bbLiveOut, liveAll);
                     break;
             }
         }
@@ -476,8 +473,6 @@ void Compiler::fgPerBlockLocalVarLiveness()
         return;
     }
 
-#endif // CAN_DISABLE_DFA
-
     // Avoid allocations in the long case.
     VarSetOps::AssignNoCopy(this, fgCurUseSet, VarSetOps::MakeEmpty(this));
     VarSetOps::AssignNoCopy(this, fgCurDefSet, VarSetOps::MakeEmpty(this));
@@ -1323,6 +1318,11 @@ public:
 
 void Compiler::fgLiveVarAnalysis(bool updateInternalOnly)
 {
+    if (!backendRequiresLocalVarLifetimes())
+    {
+        return;
+    }
+
     LiveVarAnalysis::Run(this, updateInternalOnly);
 
 #ifdef DEBUG
@@ -2772,6 +2772,13 @@ void Compiler::fgInterBlockLocalVarLiveness()
         fgExtendDbgLifetimes();
     }
 
+    // Nothing more to be done if the backend does not require accurate local var lifetimes.
+    if (!backendRequiresLocalVarLifetimes())
+    {
+        fgLocalVarLivenessDone = true;
+        return;
+    }
+
     /*-------------------------------------------------------------------------
      * Variables involved in exception-handlers and finally blocks need
      * to be specially marked
index 09a5919..78f8cc0 100644 (file)
@@ -4588,7 +4588,7 @@ void Lowering::DoPhase()
     // For now we'll take the throughput hit of recomputing local liveness but in the long term
     // we're striving to use the unified liveness computation (fgLocalVarLiveness) and stop
     // computing it separately in LSRA.
-    if (comp->lvaCount != 0)
+    if ((comp->lvaCount != 0) && comp->backendRequiresLocalVarLifetimes())
     {
         comp->lvaSortAgain = true;
     }
index f1144e3..dd9604f 100644 (file)
@@ -1171,6 +1171,11 @@ private:
     // True if there are any register candidate lclVars available for allocation.
     bool enregisterLocalVars;
 
+    virtual bool willEnregisterLocalVars() const
+    {
+        return enregisterLocalVars;
+    }
+
     // Ordered list of RefPositions
     RefPositionList refPositions;