2727#include " TEntryList.h"
2828#include " TFile.h"
2929#include " TFriendElement.h"
30+ #include " TInterpreter.h"
3031#include " TROOT.h" // IsImplicitMTEnabled, gCoreMutex, R__*_LOCKGUARD
3132#include " TTreeReader.h"
3233#include " TTree.h" // For MaxTreeSizeRAII. Revert when #6640 will be solved.
@@ -868,6 +869,7 @@ void RLoopManager::Jit()
868869 {
869870 R__READ_LOCKGUARD (ROOT::gCoreMutex );
870871 if (GetCodeToJit ().empty () && GetCodeToDeclare ().empty ()) {
872+ RunDeferredCalls ();
871873 R__LOG_INFO (RDFLogChannel ()) << " Nothing to jit and execute." ;
872874 return ;
873875 }
@@ -882,12 +884,37 @@ void RLoopManager::Jit()
882884
883885 TStopwatch s;
884886 s.Start ();
885- ROOT::Internal::RDF::InterpreterDeclare (codeToDeclare);
886- RDFInternal::InterpreterCalc (code, " RLoopManager::Run" );
887+ if (!codeToDeclare.empty ()) {
888+ ROOT::Internal::RDF::InterpreterDeclare (codeToDeclare);
889+ auto &funcMap = GetJitHelperFuncMap ();
890+ auto &nameMap = GetJitHelperNameMap ();
891+ auto clinfo = gInterpreter ->ClassInfo_Factory (" R_rdf" );
892+ assert (gInterpreter ->ClassInfo_IsValid (clinfo));
893+ for (auto & codeAndName : nameMap) {
894+ JitHelperFunc * & addr = funcMap[codeAndName.second ];
895+ if (!addr) {
896+ // fast fetch of the address via gInterpreter
897+ // (faster than gInterpreter->Evaluate(function name, ret), ret->GetAsPointer())
898+ auto declid = gInterpreter ->GetFunction (clinfo, codeAndName.second .c_str ());
899+ assert (declid);
900+ auto minfo = gInterpreter ->MethodInfo_Factory (declid);
901+ assert (gInterpreter ->MethodInfo_IsValid (minfo));
902+ auto mname = gInterpreter ->MethodInfo_GetMangledName (minfo);
903+ addr = reinterpret_cast <JitHelperFunc *>(gInterpreter ->FindSym (mname));
904+ gInterpreter ->MethodInfo_Delete (minfo);
905+ }
906+ }
907+ gInterpreter ->ClassInfo_Delete (clinfo);
908+ }
909+ if (!code.empty ()) {
910+ RDFInternal::InterpreterCalc (code, " RLoopManager::Run" );
911+ }
887912 s.Stop ();
888913 R__LOG_INFO (RDFLogChannel ()) << " Just-in-time compilation phase completed"
889914 << (s.RealTime () > 1e-3 ? " in " + std::to_string (s.RealTime ()) + " seconds."
890915 : " in less than 1ms." );
916+
917+ RunDeferredCalls ();
891918}
892919
893920void RLoopManager::RunDeferredCalls ()
@@ -1076,7 +1103,6 @@ void RLoopManager::RegisterJitHelperCall(const std::string &funcCode, std::share
10761103 const std::vector<std::string> &colNames, void *wkJittedNode, void *argument)
10771104{
10781105 auto &nameMap = GetJitHelperNameMap ();
1079- auto &funcMap = GetJitHelperFuncMap ();
10801106 {
10811107 R__READ_LOCKGUARD (ROOT::gCoreMutex );
10821108 auto match = nameMap.find (funcCode);
@@ -1095,15 +1121,6 @@ void RLoopManager::RegisterJitHelperCall(const std::string &funcCode, std::share
10951121 // step 1: register function (now)
10961122 std::string toDeclare = " namespace R_rdf {\n void " + registerId + funcCode + " \n }\n " ;
10971123 GetCodeToDeclare ().append (toDeclare);
1098- std::stringstream registration;
1099- registration
1100- << " (*(reinterpret_cast<std::unordered_map<std::string,void "
1101- " (*)(ROOT::Detail::RDF::RLoopManager*,std::shared_ptr<ROOT::Detail::RDF::RNodeBase> "
1102- " *,ROOT::Internal::RDF::RColumnRegister *, const std::vector<std::string> & colNames, void*,void*)>*>(" ;
1103- registration << PrettyPrintAddr ((void *)(&funcMap));
1104- registration << " )))[\" " << registerId << " \" ] = R_rdf::" << registerId << " ;\n " ;
1105- std::string registrationStr = registration.str ();
1106- GetCodeToJit ().append (registrationStr);
11071124 fJitHelperCalls .emplace_back (registerId, prevNodeOnHeap, colRegister, colNames, wkJittedNode, argument);
11081125 }
11091126}
0 commit comments