Skip to content

Initial ORCJIT Bindings #102

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

Conversation

harlanhaskins
Copy link
Member

This patch provides an initial set of ORCJIT bindings. They're incomplete, and the ORC API will evolve past this in the near future.

/// - ctx: A void pointer pointing to a retained ORCJIT instance.
/// - Returns: A callable address of a compiled function, or 0 if no such
/// function was found.
func orcjitSymbolResolver(symbol: UnsafePointer<Int8>?,
Copy link
Member

Choose a reason for hiding this comment

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

Is this meant to be public?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope, it’s only used as a shim passed into the Orc bindings. It calls into the public symbol resolvers.

@CodaFi
Copy link
Member

CodaFi commented Sep 17, 2017

From a cursory glance, this is missing

  • LLVMOrcGetMangledSymbol
  • LLVMOrcDisposeMangledSymbol
  • LLVMOrcCreateIndirectStub
  • LLVMOrcSetIndirectStubPointer

@CodaFi CodaFi closed this Sep 17, 2017
@CodaFi CodaFi reopened this Sep 17, 2017
return jit.resolver.address(of: String(cString: cString), in: jit) ?? 0
}

public class ORCJIT {
Copy link
Member

Choose a reason for hiding this comment

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

This should be documented like mad (and at the top of this file).


private var sharedObjectBuffers = [LLVMSharedObjectBufferRef]()

public enum Error: Swift.Error {
Copy link
Member

Choose a reason for hiding this comment

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

Documentation here too.

/// The strategy that ORCJIT should use to compile a specific module.
public enum CompilationStrategy {
/// The IR will be compiled lazily, one function at a time.
case lazy
Copy link
Member

Choose a reason for hiding this comment

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

The JIT provides LLVMOrcCreateLazyCompileCallback to be fired when it resolves symbols. We could wrap this and let the user pass us a block.

/// - Returns: `nil` if the symbol could not be found, otherwise the opaque
/// address of a C function pointer that can be called to execute
/// the compiled code.
func address(of symbol: String, in jit: ORCJIT) -> UInt64?
Copy link
Member

Choose a reason for hiding this comment

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

Can we provide a public typealias for LLVMOrcTargetAddress instead of using UInt64?


/// Runs a series of symbol resolvers in order, stopping when the first resolver
/// finds a valid symbol.
public struct CompoundSymbolResolver: SymbolResolver {
Copy link
Member Author

Choose a reason for hiding this comment

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

@CodaFi should compound resolvers just...be the default? i.e. should ORCJIT always keep a chain of resolvers and run them, defaulting to the simple resolver?

Copy link
Member

Choose a reason for hiding this comment

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

Ooh, neat. Sure, sounds good. Then symbol resolution is a fold with ??.

@CodaFi
Copy link
Member

CodaFi commented Oct 23, 2018

Subsumed by #158

@CodaFi CodaFi closed this Oct 23, 2018
@CodaFi CodaFi deleted the theyre-taking-the-hobbits-to-isengard branch October 23, 2018 03:55
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