return EntryPointPtr(EntryPointArgs.size() - 1, EntryPointArgs.data());
}
+struct JITLinkTimers {
+ TimerGroup JITLinkTimers{"llvm-jitlink timers",
+ "timers for llvm-jitlink phases"};
+ Timer LoadObjectsTimer{
+ "load", "time to load/add object files to llvm-jitlink", JITLinkTimers};
+ Timer LinkTimer{"link", "time to link object files", JITLinkTimers};
+ Timer RunTimer{"run", "time to execute jitlink'd code", JITLinkTimers};
+};
+
int main(int argc, char *argv[]) {
InitLLVM X(argc, argv);
cl::ParseCommandLineOptions(argc, argv, "llvm jitlink tool");
ExitOnErr.setBanner(std::string(argv[0]) + ": ");
+ /// If timers are enabled, create a JITLinkTimers instance.
+ std::unique_ptr<JITLinkTimers> Timers =
+ ShowTimes ? std::make_unique<JITLinkTimers>() : nullptr;
+
Session S(getFirstFileTriple());
ExitOnErr(sanitizeArguments(S));
ExitOnErr(loadProcessSymbols(S));
ExitOnErr(loadDylibs());
- TimerGroup JITLinkTimers("llvm-jitlink timers",
- "timers for llvm-jitlink phases");
{
- Timer LoadObjectsTimer(
- "load", "time to load/add object files to llvm-jitlink", JITLinkTimers);
- LoadObjectsTimer.startTimer();
+ TimeRegion TR(Timers ? &Timers->LoadObjectsTimer : nullptr);
ExitOnErr(loadObjects(S));
- LoadObjectsTimer.stopTimer();
}
JITEvaluatedSymbol EntryPoint = 0;
{
- Timer LinkTimer("link", "time to link object files", JITLinkTimers);
- LinkTimer.startTimer();
+ TimeRegion TR(Timers ? &Timers->LinkTimer : nullptr);
EntryPoint = ExitOnErr(getMainEntryPoint(S));
- LinkTimer.stopTimer();
}
if (ShowAddrs)
int Result = 0;
{
- Timer RunTimer("run", "time to execute jitlink'd code", JITLinkTimers);
- RunTimer.startTimer();
+ TimeRegion TR(Timers ? &Timers->RunTimer : nullptr);
Result = ExitOnErr(runEntryPoint(S, EntryPoint));
- RunTimer.stopTimer();
}
- if (ShowTimes)
- JITLinkTimers.print(dbgs());
-
return Result;
}