Fix LLVM 23 compatibility: replace removed NoNaNsFPMath/NoInfsFPMath TargetOptions fields#9029
Conversation
…SION < 230 Co-authored-by: alexreinking <169273+alexreinking@users.noreply.github.com>
NoNaNsFPMath field
|
@copilot what is the replacement for this flag? Is there anything else we need to update to use a replacement API? |
…ment for removed TargetOptions fields Co-authored-by: alexreinking <169273+alexreinking@users.noreply.github.com>
The replacement for I've implemented the replacement in commit bef5472:
The |
NoNaNsFPMath fieldNoNaNsFPMath/NoInfsFPMath TargetOptions fields
| // TargetOptions in favor of these per-function attributes. | ||
| bool per_instruction_fast_math_flags = get_modflag_bool(module, "halide_per_instruction_fast_math_flags"); | ||
| if (!per_instruction_fast_math_flags) { | ||
| fn.addFnAttr("no-nans-fp-math", "true"); |
There was a problem hiding this comment.
This seems fishy. LLVM has been progressively removing these kinds of flags but I haven't seen us do this before. It's weird to have an LLVM API go from an enum to a magic string. Are you sure this is the correct fix?
|
This was indeed not the right fix (see #9039) |
llvm::TargetOptions::NoNaNsFPMathandNoInfsFPMathwere removed in LLVM 23, causing build failures across all platforms when building withhalide-llvm 23.0.0.dev85505+g69780be1. The proper replacement is to use LLVM function attributes"no-nans-fp-math"="true"and"no-infs-fp-math"="true", which convey the same information at the per-function level.Changes
src/CodeGen_Internal.cpp(get_target_options): Add#if LLVM_VERSION < 230guards aroundoptions.NoInfsFPMathandoptions.NoNaNsFPMathfor backward compatibility with LLVM < 23.src/CodeGen_Internal.cpp(set_function_attributes_from_halide_target_options): Add"no-nans-fp-math"and"no-infs-fp-math"function attributes when the module is in fast-math mode (i.e.,!per_instruction_fast_math_flags). This is the LLVM 23 replacement for the removedTargetOptionsfields, and also resolves a pre-existing FIXME comment suggesting this migration.src/CodeGen_PTX_Dev.cpp(init_module): Add#if LLVM_VERSION < 230guards aroundoptions.NoNaNsFPMathandoptions.NoInfsFPMath. Also set thehalide_per_instruction_fast_math_flagsmodule flag on the PTX GPU module so thatset_function_attributes_from_halide_target_optionscorrectly determines whether to apply the fast-math function attributes to PTX kernel functions (previously this flag was only set on host modules).🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.