Skip to content

Wrap LLVM Intrinsics #89

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

Closed
wants to merge 1 commit into from
Closed

Wrap LLVM Intrinsics #89

wants to merge 1 commit into from

Conversation

CodaFi
Copy link
Member

@CodaFi CodaFi commented May 14, 2017

The infrastructure to generate Calls is all here in this patch. However, the interface makes no guarantees of type safety, and LLVM overloads its intrinsics, so we have a real chance to provide just the subset of commented-out calls, do some type checks, and a little introspection to dispatch to the right intrinsic overload.

Basically, what should the typesafe API look like, if any?

@vdka
Copy link
Contributor

vdka commented Sep 24, 2017

Instead of using precondition it might be best performance-wise to use assert since it is omitted in release optimized code.

@CodaFi
Copy link
Member Author

CodaFi commented Sep 24, 2017

Good catch. I'm also considering writing a tool that generates these definitions from llvm/include/llvm/IR/Intrinsics.td.

@harlanhaskins
Copy link
Member

trill-lang/TableGenSwift

@CodaFi
Copy link
Member Author

CodaFi commented Sep 24, 2017

I'm hoping it won't come to reimplementing TableGen. e.g. Huon has a little tool in Rust that parses out the different definitions from the td files.

@harlanhaskins
Copy link
Member

I mean, I think it’d be fine to write a TableGen backend in C++ as a utility here.

@CodaFi
Copy link
Member Author

CodaFi commented Oct 1, 2017

The first draft of the tool has been committed. Currently it dumps a huge file full of enums into the working directory of the tool.

@CodaFi CodaFi force-pushed the intr-alia branch 9 times, most recently from 3204f19 to 5c82ab8 Compare October 2, 2017 20:07
@CodaFi CodaFi changed the title [WIP] Wrap LLVM Intrinsics Wrap LLVM Intrinsics Oct 2, 2017
@@ -7,6 +7,11 @@ import cllvm
public struct MetadataType: IRType {
internal let llvm: LLVMTypeRef

internal init() {
// FIXME: This is just plain wrong.
self.llvm = PointerType(pointee: VoidType()).asLLVM()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this, I'm thinking I generate a fake LLVMMDNode and try to grab its type.

@@ -8,6 +8,11 @@ import cllvm
public struct TokenType: IRType {
internal let llvm: LLVMTypeRef

internal init() {
// FIXME: This is just plain wrong.
self.llvm = PointerType(pointee: VoidType()).asLLVM()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually have no idea what to do about this. @llvm.coro.id is capable of producing Tokens that are consumed by the other @llvm.coro.* functions so we clearly need some way to initialize this properly, but there's nothing I can find in the C API that will do it.

@CodaFi
Copy link
Member Author

CodaFi commented Oct 3, 2017

Oh wow, of course I'm having trouble. Nobody took the time to properly expose the getters for these types.

@CodaFi
Copy link
Member Author

CodaFi commented Oct 3, 2017

Submitted D38809 to track work getting these getters in. In the mean time I can @_silgen_name("LLVMTokenTypeInContext") but we're SOL for LLVMMetadataType at the moment.

@CodaFi
Copy link
Member Author

CodaFi commented Oct 3, 2017

#112 Disables these in the meantime and will allow me to remove these hacks.

@segiddins
Copy link
Contributor

Does this mean you won't be able to use intrinsics including LLVMSwift via swiftpm?

@CodaFi
Copy link
Member Author

CodaFi commented Oct 3, 2017

You absolutely can, you just have to run utils/instrinsics-gen then run the package build.

@CodaFi
Copy link
Member Author

CodaFi commented Oct 3, 2017

In the sense that it won't be automatic, yeah.

@CodaFi
Copy link
Member Author

CodaFi commented Oct 31, 2017

Revision just got accepted. I think this can be parked until the next point release so this API is actually usable.

@CodaFi
Copy link
Member Author

CodaFi commented Dec 22, 2017

We missed the boat for 5.0.1. Holding for 6.0 in the spring.

@CodaFi
Copy link
Member Author

CodaFi commented Mar 13, 2018

Build will be restarted once #127 gets scheduled.

@CodaFi CodaFi force-pushed the intr-alia branch 3 times, most recently from cf8bbcc to e1b2032 Compare March 14, 2018 06:05
@CodaFi CodaFi force-pushed the intr-alia branch 5 times, most recently from a007f09 to 431a5e6 Compare September 28, 2018 19:19
The LLVM Intrinsics API is large, complex, platform-dependent,
and in a constant state of flux.  LLVM has chosen to manage this
complexity with a set of TableGen definition files.  Therefore,
we must parse and interpret these files to provide a robust API.

This commit introduces a new tool, 'intrinsics-gen', to be invoked
from the top-level of the repository. The tool will read in any number
of platform-dependent TableGen files and interpret them as a Swift file
of enums with selectors.  Each of these selectors either represents an
intrinsic or a family of intrinsics that the framework is capable of
resolving to one of LLVM's "proper intrinsic" selectors.

The idea is that we do not ever ship this generated Swift file.
Instead, users that wish to use this framework with the intrinsics will
invoke 'intrinsics-gen' with the appropriate td file and SwiftPM will
handle the rest.  The API that will be committed is just the
infrastructure necessary to support this.  See the test suite for
a concrete example of how to use this.
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.

4 participants