Factor out helper to get late arg for given index
authorJoseph Tremoulet <jotrem@microsoft.com>
Tue, 31 Jan 2017 22:44:58 +0000 (17:44 -0500)
committerJoseph Tremoulet <jotrem@microsoft.com>
Sat, 4 Feb 2017 01:49:07 +0000 (20:49 -0500)
Simple no-diff refactoring to avoid copy-paste proliferation of this
snippet.

src/jit/compiler.cpp
src/jit/compiler.h
src/jit/morph.cpp
src/jit/valuenum.cpp

index bdf527f..2d03085 100644 (file)
@@ -6697,16 +6697,7 @@ Compiler::NodeToIntMap* Compiler::FindReachableNodesInNodeTestData()
                         if (arg->gtFlags & GTF_LATE_ARG)
                         {
                             // Find the corresponding late arg.
-                            GenTreePtr lateArg = nullptr;
-                            for (unsigned j = 0; j < call->fgArgInfo->ArgCount(); j++)
-                            {
-                                if (call->fgArgInfo->ArgTable()[j]->argNum == i)
-                                {
-                                    lateArg = call->fgArgInfo->ArgTable()[j]->node;
-                                    break;
-                                }
-                            }
-                            assert(lateArg != nullptr);
+                            GenTreePtr lateArg = call->fgArgInfo->GetLateArg(i);
                             if (GetNodeTestData()->Lookup(lateArg, &tlAndN))
                             {
                                 reachable->Set(lateArg, 0);
index 82228b6..3eca93d 100644 (file)
@@ -1342,6 +1342,9 @@ public:
     {
         return argsComplete;
     }
+
+    // Get the late arg for arg at position argIndex.  Caller must ensure this position has a late arg.
+    GenTreePtr GetLateArg(unsigned argIndex);
 };
 
 #ifdef DEBUG
index e5f8c79..8fec725 100644 (file)
@@ -2431,6 +2431,22 @@ void fgArgInfo::EvalArgsToTemps()
 #endif
 }
 
+// Get the late arg for arg at position argIndex.
+// argIndex - 0-based position to get late arg for.
+//            Caller must ensure this position has a late arg.
+GenTreePtr fgArgInfo::GetLateArg(unsigned argIndex)
+{
+    for (unsigned j = 0; j < this->ArgCount(); j++)
+    {
+        if (this->ArgTable()[j]->argNum == argIndex)
+        {
+            return this->ArgTable()[j]->node;
+        }
+    }
+    // Caller must ensure late arg exists.
+    unreached();
+}
+
 void fgArgInfo::RecordStkLevel(unsigned stkLvl)
 {
     assert(!IsUninitialized(stkLvl));
index a1010a7..aad4b2e 100644 (file)
@@ -6975,16 +6975,7 @@ void Compiler::fgValueNumberCall(GenTreeCall* call)
         if (arg->OperGet() == GT_ARGPLACE)
         {
             // Find the corresponding late arg.
-            GenTreePtr lateArg = nullptr;
-            for (unsigned j = 0; j < call->fgArgInfo->ArgCount(); j++)
-            {
-                if (call->fgArgInfo->ArgTable()[j]->argNum == i)
-                {
-                    lateArg = call->fgArgInfo->ArgTable()[j]->node;
-                    break;
-                }
-            }
-            assert(lateArg != nullptr);
+            GenTreePtr lateArg = call->fgArgInfo->GetLateArg(i);
             assert(lateArg->gtVNPair.BothDefined());
             arg->gtVNPair   = lateArg->gtVNPair;
             updatedArgPlace = true;