@@ -54,17 +54,15 @@ using namespace llvm;
5454#define DEBUG_TYPE " jitlayers"
5555
5656// Snooping on which functions are being compiled, and how long it takes
57- JL_STREAM *dump_compiles_stream = NULL ;
5857extern " C" JL_DLLEXPORT
5958void jl_dump_compiles_impl (void *s)
6059{
61- dump_compiles_stream = (JL_STREAM*)s;
60+ **jl_ExecutionEngine-> get_dump_compiles_stream () = (JL_STREAM*)s;
6261}
63- JL_STREAM *dump_llvm_opt_stream = NULL ;
6462extern " C" JL_DLLEXPORT
6563void jl_dump_llvm_opt_impl (void *s)
6664{
67- dump_llvm_opt_stream = (JL_STREAM*)s;
65+ **jl_ExecutionEngine-> get_dump_llvm_opt_stream () = (JL_STREAM*)s;
6866}
6967
7068static void jl_add_to_ee (orc::ThreadSafeModule &M, StringMap<orc::ThreadSafeModule*> &NewExports);
@@ -108,7 +106,8 @@ static jl_callptr_t _jl_compile_codeinst(
108106 // caller must hold codegen_lock
109107 // and have disabled finalizers
110108 uint64_t start_time = 0 ;
111- if (dump_compiles_stream != NULL )
109+ bool timed = !!*jl_ExecutionEngine->get_dump_compiles_stream ();
110+ if (timed)
112111 start_time = jl_hrtime ();
113112
114113 assert (jl_is_code_instance (codeinst));
@@ -198,17 +197,18 @@ static jl_callptr_t _jl_compile_codeinst(
198197 }
199198
200199 uint64_t end_time = 0 ;
201- if (dump_compiles_stream != NULL )
200+ if (timed )
202201 end_time = jl_hrtime ();
203202
204203 // If logging of the compilation stream is enabled,
205204 // then dump the method-instance specialization type to the stream
206205 jl_method_instance_t *mi = codeinst->def ;
207206 if (jl_is_method (mi->def .method )) {
208- if (dump_compiles_stream != NULL ) {
209- jl_printf (dump_compiles_stream, " %" PRIu64 " \t\" " , end_time - start_time);
210- jl_static_show (dump_compiles_stream, mi->specTypes );
211- jl_printf (dump_compiles_stream, " \"\n " );
207+ auto stream = *jl_ExecutionEngine->get_dump_compiles_stream ();
208+ if (stream) {
209+ jl_printf (stream, " %" PRIu64 " \t\" " , end_time - start_time);
210+ jl_static_show (stream, mi->specTypes );
211+ jl_printf (stream, " \"\n " );
212212 }
213213 }
214214 return fptr;
@@ -480,13 +480,6 @@ CodeGenOpt::Level CodeGenOptLevelFor(int optlevel)
480480#endif
481481}
482482
483- static void addPassesForOptLevel (legacy::PassManager &PM, TargetMachine &TM, int optlevel)
484- {
485- addTargetPasses (&PM, &TM);
486- addOptimizationPasses (&PM, optlevel);
487- addMachinePasses (&PM, &TM, optlevel);
488- }
489-
490483static auto countBasicBlocks (const Function &F)
491484{
492485 return std::distance (F.begin (), F.end ());
@@ -899,7 +892,9 @@ namespace {
899892 }
900893 std::unique_ptr<legacy::PassManager> operator ()() {
901894 auto PM = std::make_unique<legacy::PassManager>();
902- addPassesForOptLevel (*PM, *TM, optlevel);
895+ addTargetPasses (PM.get (), TM->getTargetTriple (), TM->getTargetIRAnalysis ());
896+ addOptimizationPasses (PM.get (), optlevel);
897+ addMachinePasses (PM.get (), optlevel);
903898 return PM;
904899 }
905900 };
@@ -910,24 +905,27 @@ namespace {
910905 OptimizerResultT operator ()(orc::ThreadSafeModule TSM, orc::MaterializationResponsibility &R) {
911906 TSM.withModuleDo ([&](Module &M) {
912907 uint64_t start_time = 0 ;
913- if (dump_llvm_opt_stream != NULL ) {
914- // Print LLVM function statistics _before_ optimization
915- // Print all the information about this invocation as a YAML object
916- jl_printf (dump_llvm_opt_stream, " - \n " );
917- // We print the name and some statistics for each function in the module, both
918- // before optimization and again afterwards.
919- jl_printf (dump_llvm_opt_stream, " before: \n " );
920- for (auto &F : M.functions ()) {
921- if (F.isDeclaration () || F.getName ().startswith (" jfptr_" )) {
922- continue ;
908+ {
909+ auto stream = *jl_ExecutionEngine->get_dump_llvm_opt_stream ();
910+ if (stream) {
911+ // Print LLVM function statistics _before_ optimization
912+ // Print all the information about this invocation as a YAML object
913+ jl_printf (stream, " - \n " );
914+ // We print the name and some statistics for each function in the module, both
915+ // before optimization and again afterwards.
916+ jl_printf (stream, " before: \n " );
917+ for (auto &F : M.functions ()) {
918+ if (F.isDeclaration () || F.getName ().startswith (" jfptr_" )) {
919+ continue ;
920+ }
921+ // Each function is printed as a YAML object with several attributes
922+ jl_printf (stream, " \" %s\" :\n " , F.getName ().str ().c_str ());
923+ jl_printf (stream, " instructions: %u\n " , F.getInstructionCount ());
924+ jl_printf (stream, " basicblocks: %lu\n " , countBasicBlocks (F));
923925 }
924- // Each function is printed as a YAML object with several attributes
925- jl_printf (dump_llvm_opt_stream, " \" %s\" :\n " , F.getName ().str ().c_str ());
926- jl_printf (dump_llvm_opt_stream, " instructions: %u\n " , F.getInstructionCount ());
927- jl_printf (dump_llvm_opt_stream, " basicblocks: %lu\n " , countBasicBlocks (F));
928- }
929926
930- start_time = jl_hrtime ();
927+ start_time = jl_hrtime ();
928+ }
931929 }
932930
933931 JL_TIMING (LLVM_OPT);
@@ -936,20 +934,23 @@ namespace {
936934 (***PMs).run (M);
937935
938936 uint64_t end_time = 0 ;
939- if (dump_llvm_opt_stream != NULL ) {
940- end_time = jl_hrtime ();
941- jl_printf (dump_llvm_opt_stream, " time_ns: %" PRIu64 " \n " , end_time - start_time);
942- jl_printf (dump_llvm_opt_stream, " optlevel: %d\n " , optlevel);
943-
944- // Print LLVM function statistics _after_ optimization
945- jl_printf (dump_llvm_opt_stream, " after: \n " );
946- for (auto &F : M.functions ()) {
947- if (F.isDeclaration () || F.getName ().startswith (" jfptr_" )) {
948- continue ;
937+ {
938+ auto stream = *jl_ExecutionEngine->get_dump_llvm_opt_stream ();
939+ if (stream) {
940+ end_time = jl_hrtime ();
941+ jl_printf (stream, " time_ns: %" PRIu64 " \n " , end_time - start_time);
942+ jl_printf (stream, " optlevel: %d\n " , optlevel);
943+
944+ // Print LLVM function statistics _after_ optimization
945+ jl_printf (stream, " after: \n " );
946+ for (auto &F : M.functions ()) {
947+ if (F.isDeclaration () || F.getName ().startswith (" jfptr_" )) {
948+ continue ;
949+ }
950+ jl_printf (stream, " \" %s\" :\n " , F.getName ().str ().c_str ());
951+ jl_printf (stream, " instructions: %u\n " , F.getInstructionCount ());
952+ jl_printf (stream, " basicblocks: %lu\n " , countBasicBlocks (F));
949953 }
950- jl_printf (dump_llvm_opt_stream, " \" %s\" :\n " , F.getName ().str ().c_str ());
951- jl_printf (dump_llvm_opt_stream, " instructions: %u\n " , F.getInstructionCount ());
952- jl_printf (dump_llvm_opt_stream, " basicblocks: %lu\n " , countBasicBlocks (F));
953954 }
954955 }
955956 });
@@ -1166,7 +1167,7 @@ uint64_t JuliaOJIT::getFunctionAddress(StringRef Name)
11661167
11671168StringRef JuliaOJIT::getFunctionAtAddress (uint64_t Addr, jl_code_instance_t *codeinst)
11681169{
1169- static int globalUnique = 0 ;
1170+ std::lock_guard<std::mutex> lock (RLST_mutex) ;
11701171 std::string *fname = &ReverseLocalSymbolTable[(void *)(uintptr_t )Addr];
11711172 if (fname->empty ()) {
11721173 std::string string_fname;
@@ -1186,7 +1187,7 @@ StringRef JuliaOJIT::getFunctionAtAddress(uint64_t Addr, jl_code_instance_t *cod
11861187 stream_fname << " jlsys_" ;
11871188 }
11881189 const char * unadorned_name = jl_symbol_name (codeinst->def ->def .method ->name );
1189- stream_fname << unadorned_name << " _" << globalUnique ++;
1190+ stream_fname << unadorned_name << " _" << RLST_inc ++;
11901191 *fname = std::move (stream_fname.str ()); // store to ReverseLocalSymbolTable
11911192 addGlobalMapping (*fname, Addr);
11921193 }
@@ -1232,16 +1233,6 @@ const DataLayout& JuliaOJIT::getDataLayout() const
12321233 return DL;
12331234}
12341235
1235- TargetMachine &JuliaOJIT::getTargetMachine ()
1236- {
1237- return *TM;
1238- }
1239-
1240- const Triple& JuliaOJIT::getTargetTriple () const
1241- {
1242- return TM->getTargetTriple ();
1243- }
1244-
12451236std::string JuliaOJIT::getMangledName (StringRef Name)
12461237{
12471238 SmallString<128 > FullName;
@@ -1412,6 +1403,40 @@ void JuliaOJIT::shareStrings(Module &M)
14121403 GV->eraseFromParent ();
14131404}
14141405
1406+ // TargetMachine pass-through methods
1407+
1408+ std::unique_ptr<TargetMachine> JuliaOJIT::cloneTargetMachine () const
1409+ {
1410+ return std::unique_ptr<TargetMachine>(getTarget ()
1411+ .createTargetMachine (
1412+ getTargetTriple ().str (),
1413+ getTargetCPU (),
1414+ getTargetFeatureString (),
1415+ getTargetOptions (),
1416+ TM->getRelocationModel (),
1417+ TM->getCodeModel (),
1418+ TM->getOptLevel ()));
1419+ }
1420+
1421+ const Triple& JuliaOJIT::getTargetTriple () const {
1422+ return TM->getTargetTriple ();
1423+ }
1424+ StringRef JuliaOJIT::getTargetFeatureString () const {
1425+ return TM->getTargetFeatureString ();
1426+ }
1427+ StringRef JuliaOJIT::getTargetCPU () const {
1428+ return TM->getTargetCPU ();
1429+ }
1430+ const TargetOptions &JuliaOJIT::getTargetOptions () const {
1431+ return TM->Options ;
1432+ }
1433+ const Target &JuliaOJIT::getTarget () const {
1434+ return TM->getTarget ();
1435+ }
1436+ TargetIRAnalysis JuliaOJIT::getTargetIRAnalysis () const {
1437+ return TM->getTargetIRAnalysis ();
1438+ }
1439+
14151440static void jl_decorate_module (Module &M) {
14161441#if defined(_CPU_X86_64_) && defined(_OS_WINDOWS_)
14171442 // Add special values used by debuginfo to build the UnwindData table registration for Win64
0 commit comments