[llvm] e8e7581 - [llvm-jitlink] Print session report even if entry-point lookup errors out.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Thu May 19 10:51:27 PDT 2022


Author: Lang Hames
Date: 2022-05-19T10:51:20-07:00
New Revision: e8e7581fb10d974c6e5cf475f40164035288442f

URL: https://github.com/llvm/llvm-project/commit/e8e7581fb10d974c6e5cf475f40164035288442f
DIFF: https://github.com/llvm/llvm-project/commit/e8e7581fb10d974c6e5cf475f40164035288442f.diff

LOG: [llvm-jitlink] Print session report even if entry-point lookup errors out.

Added: 
    

Modified: 
    llvm/tools/llvm-jitlink/llvm-jitlink.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
index 0b8df595a2e64..d202e8bf316ff 100644
--- a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
+++ b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
@@ -1941,6 +1941,36 @@ static Expected<JITEvaluatedSymbol> getOrcRuntimeEntryPoint(Session &S) {
   return S.ES.lookup(S.JDSearchOrder, S.ES.intern(RuntimeEntryPoint));
 }
 
+static Expected<JITEvaluatedSymbol> getEntryPoint(Session &S) {
+  JITEvaluatedSymbol EntryPoint;
+
+  // Find the entry-point function unconditionally, since we want to force
+  // it to be materialized to collect stats.
+  if (auto EP = getMainEntryPoint(S))
+    EntryPoint = *EP;
+  else
+    return EP.takeError();
+  LLVM_DEBUG({
+    dbgs() << "Using entry point \"" << EntryPointName
+           << "\": " << formatv("{0:x16}", EntryPoint.getAddress()) << "\n";
+  });
+
+  // If we're running with the ORC runtime then replace the entry-point
+  // with the __orc_rt_run_program symbol.
+  if (!OrcRuntime.empty()) {
+    if (auto EP = getOrcRuntimeEntryPoint(S))
+      EntryPoint = *EP;
+    else
+      return EP.takeError();
+    LLVM_DEBUG({
+      dbgs() << "(called via __orc_rt_run_program_wrapper at "
+             << formatv("{0:x16}", EntryPoint.getAddress()) << ")\n";
+    });
+  }
+
+  return EntryPoint;
+}
+
 static Expected<int> runWithRuntime(Session &S, ExecutorAddr EntryPointAddr) {
   StringRef DemangledEntryPoint = EntryPointName;
   const auto &TT = S.ES.getExecutorProcessControl().getTargetTriple();
@@ -2002,48 +2032,31 @@ int main(int argc, char *argv[]) {
   if (ShowInitialExecutionSessionState)
     S->ES.dump(outs());
 
-  JITEvaluatedSymbol EntryPoint = nullptr;
+  Expected<JITEvaluatedSymbol> EntryPoint(nullptr);
   {
+    ExpectedAsOutParameter<JITEvaluatedSymbol> _(&EntryPoint);
     TimeRegion TR(Timers ? &Timers->LinkTimer : nullptr);
-    // Find the entry-point function unconditionally, since we want to force
-    // it to be materialized to collect stats.
-    if (auto EP = getMainEntryPoint(*S))
-      EntryPoint = *EP;
-    else {
-      reportLLVMJITLinkError(EP.takeError());
-      exit(1);
-    }
-    LLVM_DEBUG({
-      dbgs() << "Using entry point \"" << EntryPointName
-             << "\": " << formatv("{0:x16}", EntryPoint.getAddress()) << "\n";
-    });
-
-    // If we're running with the ORC runtime then replace the entry-point
-    // with the __orc_rt_run_program symbol.
-    if (!OrcRuntime.empty()) {
-      if (auto EP = getOrcRuntimeEntryPoint(*S))
-        EntryPoint = *EP;
-      else {
-        reportLLVMJITLinkError(EP.takeError());
-        exit(1);
-      }
-      LLVM_DEBUG({
-        dbgs() << "(called via __orc_rt_run_program_wrapper at "
-               << formatv("{0:x16}", EntryPoint.getAddress()) << ")\n";
-      });
-    }
+    EntryPoint = getEntryPoint(*S);
   }
 
+  // Print any reports regardless of whether we succeeded or failed.
   if (ShowEntryExecutionSessionState)
     S->ES.dump(outs());
 
   if (ShowAddrs)
     S->dumpSessionInfo(outs());
 
-  ExitOnErr(runChecks(*S));
-
   dumpSessionStats(*S);
 
+  if (!EntryPoint) {
+    if (Timers)
+      Timers->JITLinkTG.printAll(errs());
+    reportLLVMJITLinkError(EntryPoint.takeError());
+    exit(1);
+  }
+
+  ExitOnErr(runChecks(*S));
+
   if (NoExec)
     return 0;
 
@@ -2053,16 +2066,19 @@ int main(int argc, char *argv[]) {
     TimeRegion TR(Timers ? &Timers->RunTimer : nullptr);
     if (!OrcRuntime.empty())
       Result =
-          ExitOnErr(runWithRuntime(*S, ExecutorAddr(EntryPoint.getAddress())));
+          ExitOnErr(runWithRuntime(*S, ExecutorAddr(EntryPoint->getAddress())));
     else
       Result = ExitOnErr(
-          runWithoutRuntime(*S, ExecutorAddr(EntryPoint.getAddress())));
+          runWithoutRuntime(*S, ExecutorAddr(EntryPoint->getAddress())));
   }
 
   // Destroy the session.
   ExitOnErr(S->ES.endSession());
   S.reset();
 
+  if (Timers)
+    Timers->JITLinkTG.printAll(errs());
+
   // If the executing code set a test result override then use that.
   if (UseTestResultOverride)
     Result = TestResultOverride;


        


More information about the llvm-commits mailing list