diff --git a/src/CodeGen_Internal.cpp b/src/CodeGen_Internal.cpp index 903f7768ca65..5c36ea58aae3 100644 --- a/src/CodeGen_Internal.cpp +++ b/src/CodeGen_Internal.cpp @@ -666,12 +666,17 @@ std::unique_ptr make_target_machine(const llvm::Module &mod bool use_large_code_model = false; get_md_bool(module.getModuleFlag("halide_use_large_code_model"), use_large_code_model); +#if LLVM_VERSION >= 180 + const auto opt_level = llvm::CodeGenOptLevel::Aggressive; +#else + const auto opt_level = llvm::CodeGenOpt::Aggressive; +#endif auto *tm = llvm_target->createTargetMachine(module.getTargetTriple(), /*CPU target=*/"", /*Features=*/"", options, use_pic ? llvm::Reloc::PIC_ : llvm::Reloc::Static, use_large_code_model ? llvm::CodeModel::Large : llvm::CodeModel::Small, - llvm::CodeGenOpt::Aggressive); + opt_level); return std::unique_ptr(tm); } diff --git a/src/CodeGen_PTX_Dev.cpp b/src/CodeGen_PTX_Dev.cpp index 2793457ccec9..2a47e591c503 100644 --- a/src/CodeGen_PTX_Dev.cpp +++ b/src/CodeGen_PTX_Dev.cpp @@ -623,12 +623,17 @@ vector CodeGen_PTX_Dev::compile_to_src() { options.NoZerosInBSS = false; options.GuaranteedTailCallOpt = false; +#if LLVM_VERSION >= 180 + const auto opt_level = CodeGenOptLevel::Aggressive; +#else + const auto opt_level = CodeGenOpt::Aggressive; +#endif std::unique_ptr target_machine(llvm_target->createTargetMachine(triple.str(), mcpu_target(), mattrs(), options, llvm::Reloc::PIC_, llvm::CodeModel::Small, - CodeGenOpt::Aggressive)); + opt_level)); internal_assert(target_machine.get()) << "Could not allocate target machine!"; @@ -724,10 +729,14 @@ vector CodeGen_PTX_Dev::compile_to_src() { // Output string stream +#if LLVM_VERSION >= 180 + const auto file_type = ::llvm::CodeGenFileType::AssemblyFile; +#else + const auto file_type = ::llvm::CGFT_AssemblyFile; +#endif // Ask the target to add backend passes as necessary. bool fail = target_machine->addPassesToEmitFile(module_pass_manager, ostream, nullptr, - ::llvm::CGFT_AssemblyFile, - true); + file_type, true); internal_assert(!fail) << "Failed to set up passes to emit PTX source\n"; module_pass_manager.run(*module); diff --git a/src/JITModule.cpp b/src/JITModule.cpp index 169f96acfcbc..eb274bc6c59d 100644 --- a/src/JITModule.cpp +++ b/src/JITModule.cpp @@ -334,7 +334,11 @@ void JITModule::compile_module(std::unique_ptr m, const string &fu // Build TargetMachine llvm::orc::JITTargetMachineBuilder tm_builder(llvm::Triple(m->getTargetTriple())); tm_builder.setOptions(options); +#if LLVM_VERSION >= 180 + tm_builder.setCodeGenOptLevel(CodeGenOptLevel::Aggressive); +#else tm_builder.setCodeGenOptLevel(CodeGenOpt::Aggressive); +#endif if (target.arch == Target::Arch::RISCV) { tm_builder.setCodeModel(llvm::CodeModel::Medium); } diff --git a/src/LLVM_Output.cpp b/src/LLVM_Output.cpp index 04af5aff3609..4952fc981877 100644 --- a/src/LLVM_Output.cpp +++ b/src/LLVM_Output.cpp @@ -425,11 +425,19 @@ std::unique_ptr compile_module_to_llvm_module(const Module &module } void compile_llvm_module_to_object(llvm::Module &module, Internal::LLVMOStream &out) { +#if LLVM_VERSION >= 180 + emit_file(module, out, llvm::CodeGenFileType::ObjectFile); +#else emit_file(module, out, llvm::CGFT_ObjectFile); +#endif } void compile_llvm_module_to_assembly(llvm::Module &module, Internal::LLVMOStream &out) { +#if LLVM_VERSION >= 180 + emit_file(module, out, llvm::CodeGenFileType::AssemblyFile); +#else emit_file(module, out, llvm::CGFT_AssemblyFile); +#endif } void compile_llvm_module_to_llvm_bitcode(llvm::Module &module, Internal::LLVMOStream &out) {