Skip to content

Commit a3bdb83

Browse files
abadamsvksnk
andauthored
Fixes for llvm trunk (#8590)
* Disable SVE patterns changed with LLVM trunk * Track changes in llvm's use of llvm::Triple vs strings --------- Co-authored-by: Volodymyr Kysenko <[email protected]>
1 parent 7356c6d commit a3bdb83

6 files changed

+57
-14
lines changed

src/CodeGen_Internal.cpp

+12-7
Original file line numberDiff line numberDiff line change
@@ -670,13 +670,18 @@ std::unique_ptr<llvm::TargetMachine> make_target_machine(const llvm::Module &mod
670670
std::string mattrs =
671671
get_md_string(module.getModuleFlag("halide_mattrs")).value_or(std::string{});
672672

673-
auto *tm = llvm_target->createTargetMachine(module.getTargetTriple(),
674-
mcpu_target,
675-
mattrs,
676-
options,
677-
use_pic ? llvm::Reloc::PIC_ : llvm::Reloc::Static,
678-
use_large_code_model ? llvm::CodeModel::Large : llvm::CodeModel::Small,
679-
CodeGenOptLevel::Aggressive);
673+
auto *tm = llvm_target->createTargetMachine(
674+
#if LLVM_VERSION >= 210
675+
module.getTargetTriple().str(),
676+
#else
677+
module.getTargetTriple(),
678+
#endif
679+
mcpu_target,
680+
mattrs,
681+
options,
682+
use_pic ? llvm::Reloc::PIC_ : llvm::Reloc::Static,
683+
use_large_code_model ? llvm::CodeModel::Large : llvm::CodeModel::Small,
684+
CodeGenOptLevel::Aggressive);
680685
return std::unique_ptr<llvm::TargetMachine>(tm);
681686
}
682687

src/CodeGen_LLVM.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,11 @@ void CodeGen_LLVM::init_codegen(const std::string &name, bool any_strict_float)
403403

404404
internal_assert(module && context);
405405

406+
#if LLVM_VERSION >= 210
407+
debug(1) << "Target triple of initial module: " << module->getTargetTriple().str() << "\n";
408+
#else
406409
debug(1) << "Target triple of initial module: " << module->getTargetTriple() << "\n";
410+
#endif
407411

408412
module->setModuleIdentifier(name);
409413

src/JITModule.cpp

+21-3
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,11 @@ void JITModule::compile_module(std::unique_ptr<llvm::Module> m, const string &fu
274274

275275
// Make the execution engine
276276
debug(2) << "Creating new execution engine\n";
277+
#if LLVM_VERSION >= 210
278+
debug(2) << "Target triple: " << m->getTargetTriple().str() << "\n";
279+
#else
277280
debug(2) << "Target triple: " << m->getTargetTriple() << "\n";
281+
#endif
278282
string error_string;
279283

280284
llvm::for_each(*m, set_function_attributes_from_halide_target_options);
@@ -313,18 +317,32 @@ void JITModule::compile_module(std::unique_ptr<llvm::Module> m, const string &fu
313317
llvm::orc::LLJITBuilderState::ObjectLinkingLayerCreator linkerBuilder;
314318
if ((target.arch == Target::Arch::X86 && target.bits == 32) ||
315319
(target.arch == Target::Arch::ARM && target.bits == 32)) {
316-
// Fallback to RTDyld-based linking to workaround errors:
317-
// i386: "JIT session error: Unsupported i386 relocation:4" (R_386_PLT32)
318-
// ARM 32bit: Unsupported target machine architecture in ELF object shared runtime-jitted-objectbuffer
320+
// Fallback to RTDyld-based linking to workaround errors:
321+
// i386: "JIT session error: Unsupported i386 relocation:4" (R_386_PLT32)
322+
// ARM 32bit: Unsupported target machine architecture in ELF object shared runtime-jitted-objectbuffer
323+
#if LLVM_VERSION >= 210
324+
linkerBuilder = [&](llvm::orc::ExecutionSession &session) {
325+
return std::make_unique<llvm::orc::RTDyldObjectLinkingLayer>(session, [&]() {
326+
return std::make_unique<HalideJITMemoryManager>(dependencies);
327+
});
328+
};
329+
#else
319330
linkerBuilder = [&](llvm::orc::ExecutionSession &session, const llvm::Triple &) {
320331
return std::make_unique<llvm::orc::RTDyldObjectLinkingLayer>(session, [&]() {
321332
return std::make_unique<HalideJITMemoryManager>(dependencies);
322333
});
323334
};
335+
#endif
324336
} else {
337+
#if LLVM_VERSION >= 210
338+
linkerBuilder = [](llvm::orc::ExecutionSession &session) {
339+
return std::make_unique<llvm::orc::ObjectLinkingLayer>(session);
340+
};
341+
#else
325342
linkerBuilder = [](llvm::orc::ExecutionSession &session, const llvm::Triple &) {
326343
return std::make_unique<llvm::orc::ObjectLinkingLayer>(session);
327344
};
345+
#endif
328346
}
329347

330348
auto JIT = llvm::cantFail(llvm::orc::LLJITBuilder()

src/LLVM_Output.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,11 @@ std::unique_ptr<llvm::Module> clone_module(const llvm::Module &module_in) {
352352
void emit_file(const llvm::Module &module_in, Internal::LLVMOStream &out,
353353
llvm::CodeGenFileType file_type) {
354354
Internal::debug(1) << "emit_file.Compiling to native code...\n";
355+
#if LLVM_VERSION >= 210
356+
Internal::debug(2) << "Target triple: " << module_in.getTargetTriple().str() << "\n";
357+
#else
355358
Internal::debug(2) << "Target triple: " << module_in.getTargetTriple() << "\n";
359+
#endif
356360

357361
auto time_start = std::chrono::high_resolution_clock::now();
358362

src/LLVM_Runtime_Linker.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,11 @@ void link_modules(std::vector<std::unique_ptr<llvm::Module>> &modules, Target t,
624624
}
625625
}
626626
module->setDataLayout(data_layout);
627+
#if LLVM_VERSION >= 210
628+
module->setTargetTriple(triple);
629+
#else
627630
module->setTargetTriple(triple.str());
631+
#endif
628632
}
629633

630634
// Link them all together
@@ -1380,7 +1384,11 @@ std::unique_ptr<llvm::Module> get_initial_module_for_ptx_device(Target target, l
13801384
}
13811385

13821386
llvm::Triple triple("nvptx64--");
1387+
#if LLVM_VERSION >= 210
1388+
modules[0]->setTargetTriple(triple);
1389+
#else
13831390
modules[0]->setTargetTriple(triple.str());
1391+
#endif
13841392

13851393
llvm::DataLayout dl("e-i64:64-v16:16-v32:32-n16:32:64");
13861394
modules[0]->setDataLayout(dl);

test/correctness/simd_op_check_sve2.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -699,10 +699,14 @@ class SimdOpCheckArmSve : public SimdOpCheckTest {
699699
Expr load_store_1 = in_im(x) * 3;
700700

701701
if (has_sve()) {
702-
// in native width, ld1b/st1b is used regardless of data type
703-
const bool allow_byte_ls = (width == target.vector_bits);
704-
add({get_sve_ls_instr("ld1", bits, bits, "", allow_byte_ls ? "b" : "")}, total_lanes, load_store_1);
705-
add({get_sve_ls_instr("st1", bits, bits, "", allow_byte_ls ? "b" : "")}, total_lanes, load_store_1);
702+
// This pattern has changed with LLVM 21, see https://github.com/halide/Halide/issues/8584 for more
703+
// details.
704+
if (Halide::Internal::get_llvm_version() <= 200) {
705+
// in native width, ld1b/st1b is used regardless of data type
706+
const bool allow_byte_ls = (width == target.vector_bits);
707+
add({get_sve_ls_instr("ld1", bits, bits, "", allow_byte_ls ? "b" : "")}, total_lanes, load_store_1);
708+
add({get_sve_ls_instr("st1", bits, bits, "", allow_byte_ls ? "b" : "")}, total_lanes, load_store_1);
709+
}
706710
} else {
707711
// vector register is not used for simple load/store
708712
string reg_prefix = (width <= 64) ? "d" : "q";

0 commit comments

Comments
 (0)