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

Extend llvmcall with support for entering declarations. #8673

Closed
wants to merge 2 commits into from
Closed

Extend llvmcall with support for entering declarations. #8673

wants to merge 2 commits into from

Conversation

maleadt
Copy link
Member

@maleadt maleadt commented Oct 13, 2014

This PR adds support to llvmcall for inserting required declarations in the module. This is useful when you want to llvmcall intrinsics, because LLVM refuses to parse IR with undeclared identifiers (for example, see this thread).

The idea behind this solution is to allow passing a tuple (decls, ir)as first argument to llvmcall, where currently only an IR string or a pointer to a LLVM function is allowed. The decls IR is then pasted before the function llvmcall generates. In order to avoid duplicate declarations, which LLVM does not like, a global set keeps track of the declarations added to the current module.

Example usage:

function floor(x::Float64)
  llvmcall(
    ("""declare double @llvm.floor.f64(double)""",
     """%2 = call double @llvm.floor.f64(double %0)
        ret double %2"""),
    Float64, (Float64,), x)
end

As mentioned in issue #8308 I also tried other approaches, such as automatically parsing identifiers in the IR, but that turned out pretty fragile.

@maleadt
Copy link
Member Author

maleadt commented Oct 13, 2014

I don't get why the OSX buildbot fails -- llvmcallDecls is definitely declared at the top of ccall.cpp...

@tkelman
Copy link
Contributor

tkelman commented Oct 14, 2014

If llvmcallDecls is used on every OS, then you should move its declaration before the #if defined(__linux__) || defined(__FreeBSD__) on line 8

@maleadt
Copy link
Member Author

maleadt commented Oct 14, 2014

Of course, how silly of me...

@maleadt
Copy link
Member Author

maleadt commented Oct 20, 2014

I'm moving this PR over to #8740, sorry for the noise.

@maleadt maleadt closed this Oct 20, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants