@@ -174,7 +174,11 @@ static Module *jl_Module;
174174#endif
175175static MDBuilder *mbuilder;
176176static std::map<int , std::string> argNumberStrings;
177+ #ifdef LLVM38
178+ static legacy::FunctionPassManager *FPM;
179+ #else
177180static FunctionPassManager *FPM;
181+ #endif
178182
179183#ifdef LLVM37
180184// No DataLayout pass needed anymore.
@@ -926,7 +930,7 @@ void jl_extern_c(jl_function_t *f, jl_value_t *rt, jl_value_t *argt, char *name)
926930 if (llvmf) {
927931 #ifndef LLVM35
928932 new GlobalAlias (llvmf->getType (), GlobalValue::ExternalLinkage, name, llvmf, llvmf->getParent ());
929- #elif defined(LLVM37)
933+ #elif defined(LLVM37) && !defined(LLVM38)
930934 GlobalAlias::create (cast<PointerType>(llvmf->getType ()),
931935 GlobalValue::ExternalLinkage, name, llvmf, llvmf->getParent ());
932936 #else
@@ -4239,7 +4243,9 @@ static Function *emit_function(jl_lambda_info_t *lam)
42394243 continue ;
42404244 ditypes.push_back (julia_type_to_di (jl_tparam (lam->specTypes ,i),ctx.dbuilder ,false ));
42414245 }
4242- #ifdef LLVM36
4246+ #ifdef LLVM38
4247+ subrty = ctx.dbuilder ->createSubroutineType (ctx.dbuilder ->getOrCreateTypeArray (ditypes));
4248+ #elif defined(LLVM36)
42434249 subrty = ctx.dbuilder ->createSubroutineType (topfile,ctx.dbuilder ->getOrCreateTypeArray (ditypes));
42444250#else
42454251 subrty = ctx.dbuilder ->createSubroutineType (topfile,ctx.dbuilder ->getOrCreateArray (ditypes));
@@ -5025,7 +5031,10 @@ static void init_julia_llvm_env(Module *m)
50255031 // Third argument (length(argv))
50265032 diargs.push_back (julia_type_to_di ((jl_value_t *)jl_int32_type,&dbuilder,false ));
50275033
5028- #ifdef LLVM36
5034+ #ifdef LLVM38
5035+ jl_di_func_sig = dbuilder.createSubroutineType (
5036+ dbuilder.getOrCreateTypeArray (diargs));
5037+ #elif defined(LLVM36)
50295038 jl_di_func_sig = dbuilder.createSubroutineType (julia_h,
50305039 dbuilder.getOrCreateTypeArray (diargs));
50315040#else
@@ -5500,7 +5509,11 @@ static void init_julia_llvm_env(Module *m)
55005509 add_named_global (diff_gc_total_bytes_func, (void *)*jl_gc_diff_total_bytes);
55015510
55025511 // set up optimization passes
5512+ #ifdef LLVM38
5513+ FPM = new legacy::FunctionPassManager (m);
5514+ #else
55035515 FPM = new FunctionPassManager (m);
5516+ #endif
55045517
55055518#ifdef LLVM37
55065519// No DataLayout pass needed anymore.
@@ -5527,9 +5540,18 @@ static void init_julia_llvm_env(Module *m)
55275540#ifndef LLVM37
55285541 jl_TargetMachine->addAnalysisPasses (*FPM);
55295542#endif
5543+ #ifdef LLVM38
5544+ FPM->add (createTypeBasedAAWrapperPass ());
5545+ #else
55305546 FPM->add (createTypeBasedAliasAnalysisPass ());
5531- if (jl_options.opt_level >=1 )
5547+ #endif
5548+ if (jl_options.opt_level >=1 ) {
5549+ #ifdef LLVM38
5550+ FPM->add (createBasicAAWrapperPass ());
5551+ #else
55325552 FPM->add (createBasicAliasAnalysisPass ());
5553+ #endif
5554+ }
55335555 // list of passes from vmkit
55345556 FPM->add (createCFGSimplificationPass ()); // Clean up disgusting code
55355557 FPM->add (createPromoteMemoryToRegisterPass ());// Kill useless allocas
@@ -5614,6 +5636,50 @@ static void init_julia_llvm_env(Module *m)
56145636 FPM->doInitialization ();
56155637}
56165638
5639+ // Helper to figure out what features to set for the LLVM target
5640+ // If the user specifies native ( or does not specify ) we default
5641+ // using the API provided by LLVM
5642+ static inline SmallVector<std::string,10 > getTargetFeatures () {
5643+ StringMap<bool > HostFeatures;
5644+ if ( !strcmp (jl_options.cpu_target ," native" ) )
5645+ {
5646+ // On earlier versions of LLVM this is empty
5647+ llvm::sys::getHostCPUFeatures (HostFeatures);
5648+ }
5649+
5650+ // Platform specific overides follow
5651+ #if defined(_CPU_X86_64_) || defined(_CPU_X86_)
5652+ #ifndef USE_MCJIT
5653+ // Temporarily disable Haswell BMI2 features due to LLVM bug.
5654+ HostFeatures[" bmi2" ] = false ;
5655+ HostFeatures[" avx2" ] = false ;
5656+ #endif
5657+ #ifdef V128_BUG
5658+ HostFeatures[" avx" ] = false ;
5659+ #endif
5660+ #endif
5661+
5662+ // Figure out if we know the cpu_target
5663+ std::string cpu = strcmp (jl_options.cpu_target ," native" ) ? jl_options.cpu_target : sys::getHostCPUName ();
5664+ if (cpu.empty () || cpu == " generic" ) {
5665+ jl_printf (JL_STDERR, " WARNING: unable to determine host cpu name.\n " );
5666+ #ifdef _CPU_ARM_
5667+ // Check if this is required when you have read the features directly from the processor
5668+ // the processors that don't have VFP are old and (hopefully) rare. this affects the platform calling convention.
5669+ HostFeatures[" vfp2" ] = true ;
5670+ #endif
5671+ }
5672+
5673+ SmallVector<std::string,10 > attr;
5674+ for ( StringMap<bool >::const_iterator it = HostFeatures.begin (); it != HostFeatures.end (); it++ )
5675+ {
5676+ std::string att = it->getValue () ? it->getKey ().str () :
5677+ std::string (" -" ) + it->getKey ().str ();
5678+ attr.append ( 1 , att );
5679+ }
5680+ return attr;
5681+ }
5682+
56175683extern " C" void jl_init_codegen (void )
56185684{
56195685#if defined(_OS_WINDOWS_) && defined(_CPU_X86_64_)
@@ -5679,19 +5745,7 @@ extern "C" void jl_init_codegen(void)
56795745#ifdef USE_MCJIT
56805746 jl_mcjmm = new SectionMemoryManager ();
56815747#endif
5682- const char *mattr[] = {
5683- #if defined(_CPU_X86_64_) || defined(_CPU_X86_)
5684- #ifndef USE_MCJIT
5685- // Temporarily disable Haswell BMI2 features due to LLVM bug.
5686- " -bmi2" , " -avx2" ,
5687- #endif
5688- #ifdef V128_BUG
5689- " -avx" ,
5690- #endif
5691- #endif
5692- " " , // padding to make sure this isn't an empty array (ref #11817)
5693- };
5694- SmallVector<std::string, 4 > MAttrs (mattr, mattr+sizeof (mattr)/sizeof (mattr[0 ]));
5748+
56955749#ifdef LLVM36
56965750 EngineBuilder eb (std::move (std::unique_ptr<Module>(engine_module)));
56975751#else
@@ -5725,17 +5779,12 @@ extern "C" void jl_init_codegen(void)
57255779#endif
57265780#endif
57275781 std::string TheCPU = strcmp (jl_options.cpu_target ," native" ) ? jl_options.cpu_target : sys::getHostCPUName ();
5728- if (TheCPU.empty () || TheCPU == " generic" ) {
5729- jl_printf (JL_STDERR, " WARNING: unable to determine host cpu name.\n " );
5730- #ifdef _CPU_ARM_
5731- MAttrs.append (1 , " +vfp2" ); // the processors that don't have VFP are old and (hopefully) rare. this affects the platform calling convention.
5732- #endif
5733- }
5782+ SmallVector<std::string, 10 > targetFeatures = getTargetFeatures ( );
57345783 TargetMachine *targetMachine = eb.selectTarget (
57355784 TheTriple,
57365785 " " ,
57375786 TheCPU,
5738- MAttrs );
5787+ targetFeatures );
57395788 assert (targetMachine && " Failed to select target machine -"
57405789 " Is the LLVM backend for this CPU enabled?" );
57415790 jl_TargetMachine = targetMachine->getTarget ().createTargetMachine (
0 commit comments