Skip to content

[Immediate] Switch immediate mode from MCJIT to LLJIT. #29863

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

Merged
merged 2 commits into from
Mar 6, 2020
Merged

[Immediate] Switch immediate mode from MCJIT to LLJIT. #29863

merged 2 commits into from
Mar 6, 2020

Conversation

lhames
Copy link
Contributor

@lhames lhames commented Feb 15, 2020

This patch switch's the underlying implementation of Swift's immediate mode from MCJIT to LLJIT.

LLJIT is a simple LLVM IR JIT. Its interface is similar to MCJIT, but its implementation is based on LLVM's newer ORC APIs. This initial patch does not make use of any of LLJIT/ORC's advanced features, but will provide better diagnostics when JIT'd code fails to link. Once LLJIT has proven usable in this basic configuration we can start experimenting with more advanced features, including lazy compilation.

LLJIT is a simple LLVM IR JIT. Its interface is similar to MCJIT, but its
implementation is based on LLVM's newer ORC APIs. This initial patch does not
make use of any of LLJIT/ORC's advanced features, but will provide better
diagnostics when JIT'd code fails to link. Once LLJIT has proven usable in
this basic configuration we can start experimenting with more advanced
features, including lazy compilation.
@lhames lhames requested a review from DougGregor February 15, 2020 02:21
@lhames
Copy link
Contributor Author

lhames commented Feb 15, 2020

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 7a0754b

@lhames
Copy link
Contributor Author

lhames commented Feb 15, 2020

We're failing on Linux in runAsMain(...). Best guess off the top of my head is that this is due to runAsMain not setting an envp argument. I'll try fixing that tomorrow.

Copy link
Member

@DougGregor DougGregor left a comment

Choose a reason for hiding this comment

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

Awesome!

@lhames
Copy link
Contributor Author

lhames commented Feb 25, 2020

@swift-ci test windows

@lhames
Copy link
Contributor Author

lhames commented Feb 25, 2020

Hrm. Let's try that again...

@swift-ci test platform windows

This matches MCJIT's default, and may solve some of the linux test failures
seen in #29863.
@lhames
Copy link
Contributor Author

lhames commented Mar 5, 2020

@swift-ci Please test

@swift-ci
Copy link
Contributor

swift-ci commented Mar 5, 2020

Build failed
Swift Test Linux Platform
Git Sha - 1767167

@swift-ci
Copy link
Contributor

swift-ci commented Mar 6, 2020

Build failed
Swift Test OS X Platform
Git Sha - 1767167

@dexonsmith
Copy link
Contributor

@swift-ci smoke test

@lhames
Copy link
Contributor Author

lhames commented Mar 6, 2020

Thanks Duncan!

What’s the bar for merging? Is a pass on the smoke tests enough?

@dexonsmith
Copy link
Contributor

Thanks Duncan!

What’s the bar for merging? Is a pass on the smoke tests enough?

I'm not really the expert for this repo. Looking above, those are the only two with the "Required" badge. But it's moot since the smoke test also crashed out with java.io.EOFException and it looks like infrastructure issues again.

@shahmishal , are you comfortable merging this despite the lack of signal?

@shahmishal
Copy link
Member

@swift-ci test

@shahmishal
Copy link
Member

01:13:23.356 Failing Tests (5):
01:13:23.356     Swift(linux-x86_64) :: execution/interpret-with-dependencies-linux.swift
01:13:23.356     Swift(linux-x86_64) :: Interpreter/shebang-env.swift
01:13:23.356     Swift(linux-x86_64) :: Interpreter/unused-type.swift
01:13:23.356     Swift(linux-x86_64) :: Interpreter/fractal.swift
01:13:23.356     Swift(linux-x86_64) :: Interpreter/mandelbrot.swift

Are these expected failures with this change?
https://ci.swift.org/job/swift-PR-Linux-smoke-test/20766/console

We need to make sure these checks are green before merging the change into master branch.

@swift-ci
Copy link
Contributor

swift-ci commented Mar 6, 2020

Build failed
Swift Test Linux Platform
Git Sha - 1767167

@lhames
Copy link
Contributor Author

lhames commented Mar 6, 2020

@swift-ci test

@lhames
Copy link
Contributor Author

lhames commented Mar 6, 2020

@shahmishal Those tests depended on the LLVM fix in swiftlang/llvm-project@0051515 . I can’t tell whether that had been merged before those CI tests ran. I’m re-running them now...

@lhames
Copy link
Contributor Author

lhames commented Mar 6, 2020

@swift-ci smoke test

@swift-ci
Copy link
Contributor

swift-ci commented Mar 6, 2020

Build failed
Swift Test Linux Platform
Git Sha - 1767167

@lhames lhames merged commit 1d5c008 into swiftlang:master Mar 6, 2020
@lhames lhames deleted the switch-imm-to-lljit branch March 6, 2020 17:12
@lhames
Copy link
Contributor Author

lhames commented Mar 7, 2020

rdar://problem/57405697

@compnerd
Copy link
Member

compnerd commented Mar 8, 2020

@lhames - seems that this is causing some problems on Windows due to the import symbol not being setup in the JIT. IIRC, I had made some changes to the MCJIT to actually synthesize the import symbols which may be missing from LLJIT? Any idea on that?

https://ci-external.swift.org/job/oss-swift-windows-x86_64-vs2019/322/

@lhames
Copy link
Contributor Author

lhames commented Mar 8, 2020

Hi Saleem. I’m on the road today, but can take a look tomorrow.

Can you point me to the import symbol synthesis code? On Windows LLJIT should be using RuntimeDyldCOFF, but if the synthesis code is in MCJIT I will just need to replicate that in LLJIT, which should be a relatively quick fix.

@compnerd
Copy link
Member

compnerd commented Mar 9, 2020

@lhames hmm, I'll take a quick glance, but its been far too long (~3 years?) since I added that. The IAT is similar to the PLT/GOT except that it is per module rather than AS-wide. Each imported symbol has a synthetic symbol __imp_<symbol> that has the pointer to the function. IIRC, each entry is 32-bits (since even 64-bit programs have limited addressing on Windows). The bit that is missing is just the synthesis of the synthetic for all of the imported functions.

e.g.

__imp_printf:
    .quad printf
__imp_stderr:
    .quad stderr

(note that it contains both function and data addresses)

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.

6 participants