@@ -516,6 +516,33 @@ OptimizerResultT JuliaOJIT::OptimizerT::operator()(orc::ThreadSafeModule TSM, or
516
516
return Expected<orc::ThreadSafeModule>{std::move (TSM)};
517
517
}
518
518
519
+ void JuliaOJIT::OptSelLayerT::emit (std::unique_ptr<orc::MaterializationResponsibility> R, orc::ThreadSafeModule TSM) {
520
+ size_t optlevel = ~0ull ;
521
+ TSM.withModuleDo ([&](Module &M) {
522
+ if (jl_generating_output ()) {
523
+ optlevel = 0 ;
524
+ }
525
+ else {
526
+ optlevel = std::max (static_cast <int >(jl_options.opt_level ), 0 );
527
+ size_t optlevel_min = std::max (static_cast <int >(jl_options.opt_level_min ), 0 );
528
+ for (auto &F : M.functions ()) {
529
+ if (!F.getBasicBlockList ().empty ()) {
530
+ Attribute attr = F.getFnAttribute (" julia-optimization-level" );
531
+ StringRef val = attr.getValueAsString ();
532
+ if (val != " " ) {
533
+ size_t ol = (size_t )val[0 ] - ' 0' ;
534
+ if (ol >= 0 && ol < optlevel)
535
+ optlevel = ol;
536
+ }
537
+ }
538
+ }
539
+ optlevel = std::min (std::max (optlevel, optlevel_min), this ->count );
540
+ }
541
+ });
542
+ assert (optlevel != ~0ull && " Failed to select a valid optimization level!" );
543
+ this ->optimizers [optlevel].emit (std::move (R), std::move (TSM));
544
+ }
545
+
519
546
void jl_register_jit_object (const object::ObjectFile &debugObj,
520
547
std::function<uint64_t (const StringRef &)> getLoadAddress,
521
548
std::function<void *(void *)> lookupWriteAddress);
@@ -819,7 +846,8 @@ JuliaOJIT::JuliaOJIT(TargetMachine &TM, LLVMContext *LLVMCtx)
819
846
{ES, CompileLayer1, OptimizerT (this , PM1, 1 )},
820
847
{ES, CompileLayer2, OptimizerT (this , PM2, 2 )},
821
848
{ES, CompileLayer3, OptimizerT (this , PM3, 3 )},
822
- }
849
+ },
850
+ OptSelLayer (OptimizeLayers)
823
851
{
824
852
#ifdef JL_USE_JITLINK
825
853
# if defined(_OS_DARWIN_) && defined(LLVM_SHLIB)
@@ -919,30 +947,8 @@ void JuliaOJIT::addModule(std::unique_ptr<Module> M)
919
947
}
920
948
}
921
949
#endif
922
-
923
- int optlevel;
924
- int optlevel_min;
925
- if (jl_generating_output ()) {
926
- optlevel = 0 ;
927
- }
928
- else {
929
- optlevel = jl_options.opt_level ;
930
- optlevel_min = jl_options.opt_level_min ;
931
- for (auto &F : M->functions ()) {
932
- if (!F.getBasicBlockList ().empty ()) {
933
- Attribute attr = F.getFnAttribute (" julia-optimization-level" );
934
- StringRef val = attr.getValueAsString ();
935
- if (val != " " ) {
936
- int ol = (int )val[0 ] - ' 0' ;
937
- if (ol >= 0 && ol < optlevel)
938
- optlevel = ol;
939
- }
940
- }
941
- }
942
- optlevel = std::max (optlevel, optlevel_min);
943
- }
944
950
// TODO: what is the performance characteristics of this?
945
- cantFail (OptimizeLayers[ std::max ( std::min (optlevel, 3 ), 0 )] .add (JD, orc::ThreadSafeModule (std::move (M), TSCtx)));
951
+ cantFail (OptSelLayer .add (JD, orc::ThreadSafeModule (std::move (M), TSCtx)));
946
952
// force eager compilation (for now), due to memory management specifics
947
953
// (can't handle compilation recursion)
948
954
for (auto Name : NewExports)
0 commit comments