Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements the @nonans decorator to enable some LLVM vectorizations #31862

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions base/compiler/ssair/legacy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ function replace_code_newstyle!(ci::CodeInfo, ir::IRCode, nargs::Int)
ci.linetable = ir.linetable
ci.ssavaluetypes = ir.types
ci.ssaflags = ir.flags
for metanode in ir.meta
nlw0 marked this conversation as resolved.
Show resolved Hide resolved
push!(ci.code, metanode)
push!(ci.codelocs, 1)
push!(ci.ssavaluetypes, Any)
push!(ci.ssaflags, 0x00)
end
# Translate BB Edges to statement edges
# (and undo normalization for now)
for i = 1:length(ci.code)
Expand Down
1 change: 1 addition & 0 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,7 @@ export
@nospecialize,
@specialize,
@polly,
@nonans,

@assert,
@__dot__,
Expand Down
17 changes: 17 additions & 0 deletions base/expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,23 @@ macro polly(ex)
esc(isa(ex, Expr) ? pushmeta!(ex, :polly) : ex)
end

"""
@nonans

Allows the compiler to assume no NaNs on floating-point operations.

```julia
@nonans function mathfunc(x)
#=
Function Definition
=#
end
```
"""
macro nonans(ex)
nlw0 marked this conversation as resolved.
Show resolved Hide resolved
vchuravy marked this conversation as resolved.
Show resolved Hide resolved
esc(isa(ex, Expr) ? pushmeta!(ex, :nonans) : ex)
end

## some macro utilities ##

function pushmeta!(ex::Expr, sym::Symbol, args::Any...)
Expand Down
2 changes: 2 additions & 0 deletions src/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ jl_sym_t *throw_undef_if_not_sym; jl_sym_t *getfield_undefref_sym;
jl_sym_t *gc_preserve_begin_sym; jl_sym_t *gc_preserve_end_sym;
jl_sym_t *escape_sym;
jl_sym_t *aliasscope_sym; jl_sym_t *popaliasscope_sym;
jl_sym_t *nonans_sym;

static uint8_t flisp_system_image[] = {
#include <julia_flisp.boot.inc>
Expand Down Expand Up @@ -367,6 +368,7 @@ void jl_init_frontend(void)
do_sym = jl_symbol("do");
aliasscope_sym = jl_symbol("aliasscope");
popaliasscope_sym = jl_symbol("popaliasscope");
nonans_sym = jl_symbol("nonans");
}

JL_DLLEXPORT void jl_lisp_prompt(void)
Expand Down
4 changes: 4 additions & 0 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5618,6 +5618,10 @@ static std::unique_ptr<Module> emit_function(
f->addFnAttr(Attribute::NoInline);
}

if (jl_has_meta(stmts, nonans_sym)) {
f->addFnAttr("no-nans-fp-math", "true");
}

if (returninfo.cc == jl_returninfo_t::Union) {
f->addAttribute(1, Attribute::getWithDereferenceableBytes(jl_LLVMContext, returninfo.union_bytes));
f->addAttribute(1, Attribute::getWithAlignment(jl_LLVMContext, returninfo.union_align));
Expand Down
1 change: 1 addition & 0 deletions src/julia_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,7 @@ extern jl_sym_t *throw_undef_if_not_sym; extern jl_sym_t *getfield_undefref_sym;
extern jl_sym_t *gc_preserve_begin_sym; extern jl_sym_t *gc_preserve_end_sym;
extern jl_sym_t *failed_sym; extern jl_sym_t *done_sym; extern jl_sym_t *runnable_sym;
extern jl_sym_t *escape_sym;
extern jl_sym_t *nonans_sym;

struct _jl_sysimg_fptrs_t;

Expand Down