https://github.com/antoyo/rustc_codegen_gcc Skip to content Sign up * Why GitHub? Features - + Mobile - + Actions - + Codespaces - + Packages - + Security - + Code review - + Issues - + Integrations - + GitHub Sponsors - + Customer stories- * Team * Enterprise * Explore + Explore GitHub - Learn and contribute + Topics - + Collections - + Trending - + Learning Lab - + Open source guides - Connect with others + The ReadME Project - + Events - + Community forum - + GitHub Education - + GitHub Stars program - * Marketplace * Pricing Plans - + Compare plans - + Contact Sales - + Education - [ ] [search-key] * # In this repository All GitHub | Jump to | * No suggested jump to results * # In this repository All GitHub | Jump to | * # In this user All GitHub | Jump to | * # In this repository All GitHub | Jump to | Sign in Sign up {{ message }} antoyo / rustc_codegen_gcc * Sponsor Sponsor antoyo/rustc_codegen_gcc * Notifications * Star 344 * Fork 4 libgccjit AOT codegen for rustc View license 344 stars 4 forks Star Notifications * Code * Issues 2 * Pull requests 2 * Actions * Projects 0 * Wiki * Security * Insights More * Code * Issues * Pull requests * Actions * Projects * Wiki * Security * Insights master Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags 5 branches 0 tags Code Clone HTTPS GitHub CLI [https://github.com/a] Use Git or checkout with SVN using the web URL. [gh repo clone antoyo] Work fast with our official CLI. Learn more. * Open with GitHub Desktop * Download ZIP Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Go back Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Go back Launching Xcode If nothing happens, download Xcode and try again. Go back Launching Visual Studio Code Your codespace will open once ready. There was a problem preparing your codespace, please try again. Latest commit @antoyo antoyo Implement popcount intrinsic manually (#43) ... 8b191d7 Jul 4, 2021 Implement popcount intrinsic manually (#43) 8b191d7 Git stats * 100 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time .github Run UI tests in CI (#34) Jun 18, 2021 build_sysroot Add dummy author info in case none is configured (#36) Jun 23, 2021 example Remove warnings (#37) Jun 25, 2021 gcc-patches Fix bswap for 128-bit integers Jun 2, 2021 gcc-test-backend Implement popcount intrinsic manually (#43) Jul 4, 2021 patches Implement and fix rotate intrinsic Jun 11, 2021 src Implement popcount intrinsic manually (#43) Jul 4, 2021 tests Fix tests May 22, 2021 .gitignore Fix inline assembly May 22, 2021 Cargo.lock Remove warnings (#37) Jun 25, 2021 Cargo.toml Send llvm-args to libgccjit (#45) Jul 3, 2021 LICENSE-APACHE License under a dual MIT / Apache-2.0 May 25, 2021 LICENSE-MIT License under a dual MIT / Apache-2.0 May 25, 2021 NOTICE Add GPLv3 license and notice Jul 2, 2021 Readme.md Update readme Jun 23, 2021 cargo.sh Initial commit Sep 3, 2020 clean_all.sh Initial commit Sep 3, 2020 config.sh Add config for gcc build directory Oct 2, 2020 gcc_path Update readme May 23, 2021 gpl-3.0.txt Add GPLv3 license and notice Jul 2, 2021 prepare.sh Initial commit Sep 3, 2020 rust-toolchain Update to nightly-2021-06-14 Jun 18, 2021 rustup.sh Initial commit Sep 3, 2020 test.sh Remove warnings (#37) Jun 25, 2021 View code WIP libgccjit codegen backend for rust Motivation Building Usage Cargo Rustc Env vars Debugging Readme.md WIP libgccjit codegen backend for rust This is a GCC codegen for rustc, which means it can be loaded by the existing rustc frontend, but benefits from GCC: more architectures are supported and GCC's optimizations are used. Despite its name, libgccjit can be used for ahead-of-time compilation, as is used here. Motivation The primary goal of this project is to be able to compile Rust code on platforms unsupported by LLVM. A secondary goal is to check if using the gcc backend will provide any run-time speed improvement for the programs compiled using rustc. Building This requires a patched libgccjit in order to work. The patches in the folder gcc-patches need to be applied. (Those patches should work when applied on master, but in case it doesn't work, they are known to work when applied on 079c23cfe079f203d5df83fea8e92a60c7d7e878.) You can also use my fork of gcc which already includes these patches. Put the path to your custom build of libgccjit in the file gcc_path. $ git clone https://github.com/antoyo/rustc_codegen_gcc.git $ cd rustc_codegen_gcc $ ./prepare.sh # download and patch sysroot src and install hyperfine for benchmarking $ ./test.sh --release Usage $cg_gccjit_dir is the directory you cloned this repo into in the following instructions. Cargo $ CHANNEL="release" $cg_gccjit_dir/cargo.sh run If you compiled cg_gccjit in debug mode (aka you didn't pass --release to ./test.sh) you should use CHANNEL="debug" instead or omit CHANNEL="release" completely. Rustc You should prefer using the Cargo method. $ rustc +$(cat $cg_gccjit_dir/rust-toolchain) -Cpanic=abort -Zcodegen-backend=$cg_gccjit_dir/target/release/librustc_codegen_gcc.so --sysroot $cg_gccjit_dir/build_sysroot/sysroot my_crate.rs Env vars CG_GCCJIT_INCR_CACHE_DISABLED Don't cache object files in the incremental cache. Useful during development of cg_gccjit to make it possible to use incremental mode for all analyses performed by rustc without caching object files when their content should have been changed by a change to cg_gccjit. CG_GCCJIT_DISPLAY_CG_TIME Display the time it took to perform codegen for a crate Debugging Sometimes, libgccjit will crash and output an error like this: during RTL pass: expand libgccjit.so: error: in expmed_mode_index, at expmed.h:249 0x7f0da2e61a35 expmed_mode_index ../../../gcc/gcc/expmed.h:249 0x7f0da2e61aa4 expmed_op_cost_ptr ../../../gcc/gcc/expmed.h:271 0x7f0da2e620dc sdiv_cost_ptr ../../../gcc/gcc/expmed.h:540 0x7f0da2e62129 sdiv_cost ../../../gcc/gcc/expmed.h:558 0x7f0da2e73c12 expand_divmod(int, tree_code, machine_mode, rtx_def*, rtx_def*, rtx_def*, int) ../../../gcc/gcc/expmed.c:4335 0x7f0da2ea1423 expand_expr_real_2(separate_ops*, rtx_def*, machine_mode, expand_modifier) ../../../gcc/gcc/expr.c:9240 0x7f0da2cd1a1e expand_gimple_stmt_1 ../../../gcc/gcc/cfgexpand.c:3796 0x7f0da2cd1c30 expand_gimple_stmt ../../../gcc/gcc/cfgexpand.c:3857 0x7f0da2cd90a9 expand_gimple_basic_block ../../../gcc/gcc/cfgexpand.c:5898 0x7f0da2cdade8 execute ../../../gcc/gcc/cfgexpand.c:6582 To see the code which causes this error, call the following function: gcc_jit_context_dump_to_file(ctxt, "/tmp/output.c", 1 /* update_locations */) This will create a C-like file and add the locations into the IR pointing to this C file. Then, rerun the program and it will output the location in the second line: libgccjit.so: /tmp/something.c:61322:0: error: in expmed_mode_index, at expmed.h:249 Or add a breakpoint to add_error in gdb and print the line number using: p loc->m_line About libgccjit AOT codegen for rustc Topics hacktoberfest Resources Readme License View license Releases No releases published Sponsor this project * * patreon patreon.com/antoyo Learn more about GitHub Sponsors Packages 0 No packages published Contributors 3 * @antoyo antoyo * @dkm dkm Marc Poulhies * @bjorn3 bjorn3 Languages * Rust 97.5% * Shell 2.5% * (c) 2021 GitHub, Inc. * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.