Skip to content

Commit 27763a1

Browse files
authored
Use AArch64 assembly syntax on macOS with LLVM<22 (#8710)
1 parent c98f92b commit 27763a1

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/CodeGen_Internal.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,16 @@ 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+
#if LLVM_VERSION < 200
674+
if (triple.isMacOSX() && triple.isAArch64()) {
675+
// The generic syntax variant is able to display the arguments to SDOT
676+
// while the Apple-specific one is bugged. See this GitHub issue for
677+
// more info: https://github.com/llvm/llvm-project/issues/151330
678+
const char *args[] = {"llc", "-aarch64-neon-syntax=generic"};
679+
cl::ParseCommandLineOptions(2, args, "Halide compiler\n");
680+
}
681+
#endif
682+
673683
auto *tm = llvm_target->createTargetMachine(
674684
#if LLVM_VERSION >= 210
675685
triple,

src/LLVM_Output.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,8 @@ void emit_file(const llvm::Module &module_in, Internal::LLVMOStream &out,
388388
// https://groups.google.com/g/llvm-dev/c/HoS07gXx0p8
389389
llvm::legacy::PassManager pass_manager;
390390

391-
pass_manager.add(new llvm::TargetLibraryInfoWrapperPass(llvm::Triple(module->getTargetTriple())));
391+
const auto &triple = llvm::Triple(module->getTargetTriple());
392+
pass_manager.add(new llvm::TargetLibraryInfoWrapperPass(triple));
392393

393394
// Make sure things marked as always-inline get inlined
394395
pass_manager.add(llvm::createAlwaysInlinerLegacyPass());
@@ -400,6 +401,17 @@ void emit_file(const llvm::Module &module_in, Internal::LLVMOStream &out,
400401
// Override default to generate verbose assembly.
401402
target_machine->Options.MCOptions.AsmVerbose = true;
402403

404+
#if 200 <= LLVM_VERSION && LLVM_VERSION < 220
405+
if (triple.isMacOSX() && triple.isAArch64()) {
406+
// The AArch64 syntax variant is able to display the arguments to SDOT
407+
// while the Darwin-specific one is bugged. See this GitHub issue for
408+
// more info: https://github.com/llvm/llvm-project/issues/151330
409+
enum { Generic = 0,
410+
Apple = 1 } variant = Generic;
411+
target_machine->Options.MCOptions.OutputAsmVariant = variant;
412+
}
413+
#endif
414+
403415
// Ask the target to add backend passes as necessary.
404416
target_machine->addPassesToEmitFile(pass_manager, out, nullptr, file_type);
405417

0 commit comments

Comments
 (0)