Skip to content

Commit

Permalink
Fixes for top-of-tree Halide (#7850)
Browse files Browse the repository at this point in the history
* Fixes for top-of-tree Halide

* I am a bonehead
  • Loading branch information
steven-johnson authored Sep 15, 2023
1 parent d7760f5 commit ab4067f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/CodeGen_Internal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -666,12 +666,17 @@ std::unique_ptr<llvm::TargetMachine> 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<llvm::TargetMachine>(tm);
}

Expand Down
15 changes: 12 additions & 3 deletions src/CodeGen_PTX_Dev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -623,12 +623,17 @@ vector<char> 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<TargetMachine>
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!";

Expand Down Expand Up @@ -724,10 +729,14 @@ vector<char> 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);

Expand Down
4 changes: 4 additions & 0 deletions src/JITModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,11 @@ void JITModule::compile_module(std::unique_ptr<llvm::Module> 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);
}
Expand Down
8 changes: 8 additions & 0 deletions src/LLVM_Output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,11 +425,19 @@ std::unique_ptr<llvm::Module> 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) {
Expand Down

0 comments on commit ab4067f

Please sign in to comment.