bjorn3
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Versions and GitHub Sync Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
Invitee
Publish Note

Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

Your note will be visible on your profile and discoverable by anyone.
Your note is now live.
This note is visible on your profile and discoverable online.
Everyone on the web can find and read all notes of this public team.
See published notes
Unpublish note
Please check the box to agree to the Community Guidelines.
View profile
Engagement control
Commenting
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Suggest edit
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
Emoji Reply
Enable
Import from Dropbox Google Drive Gist Clipboard
   owned this note    owned this note      
Published Linked with GitHub
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
:::info **Title:** Cranelift backend for rustc **Estimate:** 1 meeting **Type:** Technical ::: # Links Meeting proposal: https://github.com/rust-lang/compiler-team/issues/257 Project: https://github.com/bjorn3/rustc_codegen_cranelift # Agenda * Announcements * Major Change Proposal (should have been on Thursday agenda): Use git subtree instead of git submodule for external deps: https://github.com/rust-lang/compiler-team/issues/266 * Cranelift # Summary * Learn more about Cranelift * Talk about how to support Cranelift work # Motivation The current LLVM backend for rustc is very good at optimizing functions. However it is not the fastest, even with optimizations disabled. When compiling in release mode this is not a big problem, but during development this can be annoying. [Cranelift](https://github.com/bytecodealliance/wasmtime/tree/master/cranelift) has the potential to improve compilation time, as it is optimized for compilation time as opposed to being optimized for good optimizations like LLVM. Over the course of the past ~1.5 year I have been working on a Cranelift based codegen backend for rustc ([rustc_codegen_cranelift](https://github.com/bjorn3/rustc_codegen_cranelift) or cg_clif for short). It is currently complete enough to compile many programs. While there are cases where LLVM is faster, Cranelift is already faster than LLVM in [many cases](https://github.com/bjorn3/rustc_codegen_cranelift/issues/878#issuecomment-597871730). # Details Rustc_codegen_cranelift is currently at a point where it may make sense to talk about bringing support in tree. We should decide on if we do want this and how. Do we want to use a submodule, like miri and clippy, or do we want to merge it in tree? We may want to talk about the key differences between LLVM and Cranelift and in particular about why Cranelift can be more suitable for debug builds. I would also like to talk about how to integrate the JIT support of cg_clif with cargo. This would need a way to compile all dependencies into one or more dylib's for cg_clif to load. It would also need a way for `cargo run` to actually request the JIT mode instead of compiling the executable and then running it. # Challenges There are several things that cg_clif doesn't support very well, or doesn't support at all * Inline assembly is completely missing. ([wasmtime#1041](https://github.com/CraneStation/cranelift/issues/444)) * SIMD is partially implemented. Some LLVM intrinsics are emulated, but there are still a lot missing. ([cg_clif#171](https://github.com/bjorn3/rustc_codegen_cranelift/issues/171)) * The target feature detection x86 doesn't work as inline assembly support is missing. There are several crates like `c2-chacha` that only work when a certain target feature is supported that is supported on most modern cpu's, but is not required by the `x86_64-unknown-linux-gnu` and similar targets. This means that they have to be patched to support this combo. * Question: Can we fix feature detection by moving them to intrinsics? (Potentially better for Miri as well.) // Centril * `cg_clif` has code to emulate/codegen an abort on certain known pieces of inline asm. If Cranelift added a `cpuid` instruction, it would be possible to use that when a `cpuid` inline asm is used. It would also be possible to define a function with the bytes forming a `cpuid` + `ret` and then call that function instead when `cpuid` inline asm is requested. // bjorn3 * ABI compatibility with C and preferably cg_llvm. ([cg_clif#10](https://github.com/bjorn3/rustc_codegen_cranelift/issues/10)) * Necessary to compile proc macros using cg_clif. * Necessary for the `objc` crate on macOS. * Because of missing optimizations in Cranelift, the sysroot rlibs are much bigger than with cg_llvm. This means that the linker has to do much more work. ([cg_clif#762](https://github.com/bjorn3/rustc_codegen_cranelift/issues/762)) * https://github.com/bjorn3/rustc_codegen_cranelift/issues/878#issuecomment-598439263 * Using `lld` may help with this. * Edit(2020-03-14): `lld` helps a bit, but it is still much slower in many cases. * Edit(2020-03-15): with firefox and vscode closed, most regressions get much smaller and some even disappear completely: https://github.com/bjorn3/rustc_codegen_cranelift/issues/878#issuecomment-599271294 * Unsized locals are not supported, because Cranelift doesn't have `alloca` support. ([cg_clif#15](https://github.com/bjorn3/rustc_codegen_cranelift/issues/15), [wasmtime#1105](https://github.com/bytecodealliance/wasmtime/issues/1105)) * I had to write [code](https://github.com/bjorn3/rustc_codegen_cranelift/commit/dcc86d306c28dc1b35e0d9b1370751da7689023a) to codegen `<Box<F> as FnOnce()>::call_once` in a way that doesn't require `alloca` because of this. * There are failing tests in the rustc test suite. Some are LLVM specific, while others are not yet implemented features or in some cases (likely) miscompilations. ([cg_clif#381](https://github.com/bjorn3/rustc_codegen_cranelift/issues/381)) * Stack unwinding is not yet supported by Cranelift. * There is work being done to create a `.eh_frame` section for backtraces. # Key design questions * Should we support cg_clif in tree? * If so, use a submodule or merge it into rust-lang/rust? * See also https://github.com/rust-lang/compiler-team/issues/257 * How to handle unimplemented features? * If there was cg_llvm ABI compatibility it would be possible to transparently fall back to cg_llvm for unimplemented features. # Random other questions =) * What is the maintainance story? (nikomatsakis) * Who beyond bjorn3 is familiar? If there are bugs, how will they be prioritized? * dylib vs other options (nikomatsakis) * As I understand it, we currently load cranelift dynamically and only if it's being used, do we wish to continue with this strategy? Will it be distributed via rustup etc? * When do we start gating UI tests on cranelift? Should we have some compiletest flag for that? (centril) * I'm wondering if having multiple backends is going to put pressure on us to go back to a `ui`/`run-pass` split in the test suite. It seems silly to re-run the front-end tests when one is focusing on backend compatibiilty issues (pnkfelix). * We can filter out run-pass tests; I had a PR for that ready (https://github.com/rust-lang/rust/pull/61719) (centril) * True, the meta-data does exist in the test files. (Just need to update `compiletest` accordingly...) (pnkfelix) * See PR above for "update accordingly" ^-- (centril) * Should we start perftesting the cranelift backend? (centril)

Import from clipboard

Paste your markdown or webpage here...

Advanced permission required

Your current role can only read. Ask the system administrator to acquire write and comment permission.

This team is disabled

Sorry, this team is disabled. You can't edit this note.

This note is locked

Sorry, only owner can edit this note.

Reach the limit

Sorry, you've reached the max length this note can be.
Please reduce the content or divide it to more notes, thank you!

Import from Gist

Import from Snippet

or

Export to Snippet

Are you sure?

Do you really want to delete this note?
All users will lose their connection.

Create a note from template

Create a note from template

Oops...
This template has been removed or transferred.
Upgrade
All
  • All
  • Team
No template.

Create a template

Upgrade

Delete template

Do you really want to delete this template?
Turn this template into a regular note and keep its content, versions, and comments.

This page need refresh

You have an incompatible client version.
Refresh to update.
New version available!
See releases notes here
Refresh to enjoy new features.
Your user state has changed.
Refresh to load new user state.

Sign in

Forgot password

or

By clicking below, you agree to our terms of service.

Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
Wallet ( )
Connect another wallet

New to HackMD? Sign up

Help

  • English
  • 中文
  • Français
  • Deutsch
  • 日本語
  • Español
  • Català
  • Ελληνικά
  • Português
  • italiano
  • Türkçe
  • Русский
  • Nederlands
  • hrvatski jezik
  • język polski
  • Українська
  • हिन्दी
  • svenska
  • Esperanto
  • dansk

Documents

Help & Tutorial

How to use Book mode

Slide Example

API Docs

Edit in VSCode

Install browser extension

Contacts

Feedback

Discord

Send us email

Resources

Releases

Pricing

Blog

Policy

Terms

Privacy

Cheatsheet

Syntax Example Reference
# Header Header 基本排版
- Unordered List
  • Unordered List
1. Ordered List
  1. Ordered List
- [ ] Todo List
  • Todo List
> Blockquote
Blockquote
**Bold font** Bold font
*Italics font* Italics font
~~Strikethrough~~ Strikethrough
19^th^ 19th
H~2~O H2O
++Inserted text++ Inserted text
==Marked text== Marked text
[link text](https:// "title") Link
![image alt](https:// "title") Image
`Code` Code 在筆記中貼入程式碼
```javascript
var i = 0;
```
var i = 0;
:smile: :smile: Emoji list
{%youtube youtube_id %} Externals
$L^aT_eX$ LaTeX
:::info
This is a alert area.
:::

This is a alert area.

Versions and GitHub Sync
Get Full History Access

  • Edit version name
  • Delete

revision author avatar     named on  

More Less

Note content is identical to the latest version.
Compare
    Choose a version
    No search result
    Version not found
Sign in to link this note to GitHub
Learn more
This note is not linked with GitHub
 

Feedback

Submission failed, please try again

Thanks for your support.

On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

Please give us some advice and help us improve HackMD.

 

Thanks for your feedback

Remove version name

Do you want to remove this version name and description?

Transfer ownership

Transfer to
    Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

      Link with GitHub

      Please authorize HackMD on GitHub
      • Please sign in to GitHub and install the HackMD app on your GitHub repo.
      • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
      Learn more  Sign in to GitHub

      Push the note to GitHub Push to GitHub Pull a file from GitHub

        Authorize again
       

      Choose which file to push to

      Select repo
      Refresh Authorize more repos
      Select branch
      Select file
      Select branch
      Choose version(s) to push
      • Save a new version and push
      • Choose from existing versions
      Include title and tags
      Available push count

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Danger Zone

      Unlink
      You will no longer receive notification when GitHub file changes after unlink.

      Syncing

      Push failed

      Push successfully