[ORC] Add early-out to OL_applyQueryPhase1.
authorLang Hames <lhames@gmail.com>
Tue, 14 Dec 2021 07:30:24 +0000 (18:30 +1100)
committerLang Hames <lhames@gmail.com>
Tue, 14 Dec 2021 23:01:02 +0000 (10:01 +1100)
If all symbols in a lookup match before we reach the end of the search order
then bail out of the search-order loop early.

This should reduce unnecessary contention on the session lock and improve
readability of the debug logs.

llvm/lib/ExecutionEngine/Orc/Core.cpp

index b06dff1..aa82cf3 100644 (file)
@@ -2491,10 +2491,19 @@ void ExecutionSession::OL_applyQueryPhase1(
       }
     }
 
-    // If we get here then we've moved on to the next JITDylib.
-    LLVM_DEBUG(dbgs() << "Phase 1 moving to next JITDylib.\n");
-    ++IPLS->CurSearchOrderIndex;
-    IPLS->NewJITDylib = true;
+    if (IPLS->DefGeneratorCandidates.empty() &&
+        IPLS->DefGeneratorNonCandidates.empty()) {
+      // Early out if there are no remaining symbols.
+      LLVM_DEBUG(dbgs() << "All symbols matched.\n");
+      IPLS->CurSearchOrderIndex = IPLS->SearchOrder.size();
+      break;
+    } else {
+      // If we get here then we've moved on to the next JITDylib with candidates
+      // remaining.
+      LLVM_DEBUG(dbgs() << "Phase 1 moving to next JITDylib.\n");
+      ++IPLS->CurSearchOrderIndex;
+      IPLS->NewJITDylib = true;
+    }
   }
 
   // Remove any weakly referenced candidates that could not be found/generated.