{"id":13994822,"url":"https://github.com/lowRISC/riscv-llvm","last_synced_at":"2025-07-22T20:32:50.853Z","repository":{"id":47057884,"uuid":"72705138","full_name":"lowRISC/riscv-llvm","owner":"lowRISC","description":"RISC-V support for LLVM projects (LLVM, Clang, ...)","archived":false,"fork":false,"pushed_at":"2024-07-26T02:36:25.000Z","size":1533,"stargazers_count":268,"open_issues_count":47,"forks_count":55,"subscribers_count":29,"default_branch":"master","last_synced_at":"2025-06-02T11:55:37.541Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://www.lowrisc.org/llvm/status/","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lowRISC.png","metadata":{"files":{"readme":"README.mkd","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-11-03T03:24:20.000Z","updated_at":"2025-05-29T14:10:55.000Z","dependencies_parsed_at":"2024-11-19T05:44:35.173Z","dependency_job_id":"4b0d46b9-8f0b-4956-a1d7-48077d362b63","html_url":"https://github.com/lowRISC/riscv-llvm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/lowRISC/riscv-llvm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lowRISC%2Friscv-llvm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lowRISC%2Friscv-llvm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lowRISC%2Friscv-llvm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lowRISC%2Friscv-llvm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lowRISC","download_url":"https://codeload.github.com/lowRISC/riscv-llvm/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lowRISC%2Friscv-llvm/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266567520,"owners_count":23949372,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-09T14:03:07.457Z","updated_at":"2025-07-22T20:32:46.148Z","avatar_url":"https://github.com/lowRISC.png","language":"Shell","readme":"# RISC-V LLVM\n## About\nThis repository hosts a series of patches implementing a RISC-V backend for \nLLVM as well as initial tutorial material. For more information, see:\n* [September RISC-V LLVM status\nupdate](http://www.lowrisc.org/blog/2017/09/moving-risc-v-llvm-forwards/)\n* The [most recent status update to the LLVM mailing \nlist](http://lists.llvm.org/pipermail/llvm-dev/2017-August/116709.html)\n* [The lowRISC RISC-V LLVM status page](http://www.lowrisc.org/llvm/status)\n* The [initial \nRFC](http://lists.llvm.org/pipermail/llvm-dev/2016-August/103748.html) for \nmore about the implementation approach being taken with this port.\n\nOur intent is that development and code review primarily occurs upstream on \nLLVM infrastructure. However, there is value is maintaining the RISC-V backend \nimplementation as a set of clean patches. These will be continually rebased \nwith the intention that they provide a useful reference for anybody starting a \nnew LLVM backend or who wants to better understand backend implementation.\n\n## Mini FAQ\n\n### Should I be compiling my code with Clang and the RISC-V LLVM backend?\n\nIf you simply want to compile your C/C++ codebase for RISC-V then for the time \nbeing, just using GCC is a simpler starting point. Once RISC-V LLVM support is \nincluded in an official LLVM release in the future and is made slightly more \nuser friendly, the answer to this question should change.\n\n### When should I use this repository and when should I use upstream LLVM/Clang\n\nIf you find the step-by-step patch history useful for educational purposes or \nwant to check if there are any patches that I'm preparing for upstream but \nhaven't submitted yet, then using this repository may be worthwhile. In all \nother cases, and especially if you want to contribute to the effort you are \nstrongly advised to use the [upstream LLVM \nrepositories](https://llvm.org/docs/GettingStarted.html#git-mirror).\n\n### How can I build upstream LLVM+Clang and use it to cross-compile for a riscv32 target?\n\nFirst you will need a built RISC-V gcc toolchain. The linker, compiled \nlibraries, and libc header files will be used. You can build your own by \nfollowing the instructions at the [riscv-gnu-toolchain \nrepo](https://github.com/riscv/riscv-gnu-toolchain). It is sufficient to do \nthe following:\n\n    git clone --recursive https://github.com/riscv/riscv-gnu-toolchain\n    cd riscv-gnu-toolchain\n    ./configure --prefix=/your/gccinstallpath --with-arch=rv32imc --with-abi=ilp32\n    make -j9\n\nYou can then check out upstream LLVM and Clang and build it. llvm.org has \nuseful documentation on [building LLVM with \nCMake](https://llvm.org/docs/CMake.html), but you should find enough to get \nstarted below. Note that you will need to apply a single out-of-tree patch for \nriscv32-unknown-elf target support in Clang until \n[it](https://reviews.llvm.org/D46822) is reviewed and committed.\n\n    git clone https://git.llvm.org/git/llvm.git\n    cd llvm/tools\n    git clone https://git.llvm.org/git/clang.git/\n    cd clang\n    wget https://reviews.llvm.org/D46822?download=true -O baremetal.patch\n    patch -p0 \u003c baremetal.patch\n    cd ../../\n    mkdir build \u0026\u0026 cd build\n    cmake -G Ninja -DCMAKE_BUILD_TYPE=\"Debug\" \\\n      -DBUILD_SHARED_LIBS=True -DLLVM_USE_SPLIT_DWARF=True \\\n      -DLLVM_OPTIMIZED_TABLEGEN=True \\\n      -DLLVM_BUILD_TESTS=True \\\n      -DDEFAULT_SYSROOT=\"/path/to/riscv-gcc-install-path/riscv32-unknown-elf\" \\\n      -DGCC_INSTALL_PREFIX=\"/path/to/riscv-gcc-install-path\" \\\n      -DLLVM_DEFAULT_TARGET_TRIPLE=\"riscv32-unknown-elf\" \\\n      -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=\"RISCV\" ../\n    cmake --build .\n    ./bin/clang /path/to/testfile.c\n\nA few notes on the above CMake invocation and issues you might encounter:\n\n* It's possible to build LLVM with RISC-V support with a much simpler CMake \ninvocation. Ultimately you need to ensure you set \n`-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=\"RISCV\"`\n* This produces a debug build of LLVM and Clang which is significantly more \nuseful for bug reporting if you encounter any issues. The downsides are that \nit will execute more slowly and compilation requires a large amount of disk \nspace (~12G).\n* Building LLVM puts a heavy load on your linker. If you have lld installed, \nyou may find significantly less memory is required to link if you set \n`-DLLVM_ENABLE_LLD=True`. Alternatively, ensure that /bin/ld is symlinked to \nld.gold rather than ld.bfd.\n* It isn't necessary to set the default sysroot, gcc install prefix and \ndefault target triple when building clang, but doing so means you don't need \nto pass these arguments explicitly when invoking it. If you prefer, you can \nexplicitly pass these flags when cross-compiling: `-target riscv32-unknown-elf \n--sysroot=/path/to/riscv-gcc-install-path/riscv32-unknown-elf \n--gcc-toolchain=/path/to/riscv-gcc-install-path`\n* You can also compile for `riscv32-unknown-linux-elf` in conjunction with a \nmultilib toolchain as produced by the scripts in the [riscv-gnu-toolchain \nrepository](https://github.com/riscv/riscv-gnu-toolchain). Note that only the \nilp32 ABI is supported for the moment.\n\n\n## Status\nAs of May 2018, the vast majority of these patches are now upstream and most \nusers wishing to experiment with support for RISC-V in LLVM projects will \nlikely be best served by building directly from the upstream repositories. You \nmay prefer to follow this repository if you want to study how the backend is \nput together.\n\nNote that the patches in this repository are over-due for another rebase. I\nhope to address this soon.\n\nThe current patchset allows the entirety of the GCC torture suite to compile\nand run for {RV32I, RV32IM, RV32IFD}. Additionally, all torture suite\ntests compile and run for RV64I at O1, O2, O3, and Os. MC-layer support is \npresent for RV32IMAFDC+RV64IMAFDC, and codegen support for RV32IMFDC and \nRV64I. See the [lowRISC RISC-V LLVM status \npage](http://www.lowrisc.org/llvm/status) for more details.\n\n## Future plans\nAs well as the obvious implementation tasks, it is also our intent to augment \nthis patchset with copious documentation. The initial draft of this \ndocumentation is available in this repository.\n\nOur aim is that RISC-V is the cleanest and most documented LLVM backend. As \nwell as benefiting the wider LLVM community, this will make it substantially \neasier for research groups and hobbyists to explore hardware/software \nco-design with RISC-V.\n\nOur [lowRISC](http://www.lowrisc.org) project is working to produce a \ncompletely open source System-on-Chip implementing the RISC-V instruction set \narchitecture. One of the features we are pursuing is [tagged \nmemory](http://www.lowrisc.org/downloads/lowRISC-memo-2014-001.pdf). This \nrepository will eventually host compiler support for that feature, although \nthis may need time to mature before being ready to upstream and so may be \ndeveloped in a separate branch.\n\n## RFCs\nThis work has so far produced a number of request for comment (RFC) threads on \nthe LLVM mailing list:\n* [[RFC] 'Review corner' section in LLVM\nWeekly](http://lists.llvm.org/pipermail/llvm-dev/2017-August/116898.html)\n* [RFC/bikeshedding: Separation of instruction and pattern definitions in LLVM \nbackends](http://lists.llvm.org/pipermail/llvm-dev/2017-August/116635.html)\n* [[RFC] The future of the `va_arg`\ninstruction](http://lists.llvm.org/pipermail/llvm-dev/2017-August/116337.html)\n* [RFC: Setting MachineInstr flags through \nstoreRegToStackSlot](http://lists.llvm.org/pipermail/llvm-dev/2017-February/110281.html)\n* [RFC: Improving the experience of first-time \ncontributors](http://lists.llvm.org/pipermail/llvm-dev/2016-November/106696.html)\n* [[RFC] RISC-V \nbackend](http://lists.llvm.org/pipermail/llvm-dev/2016-August/103748.html)\n\n## License\nAll patches are under the [LLVM \nlicense](http://llvm.org/docs/DeveloperPolicy.html#license).\n\nThe docs/ directory is under the Creative Commons CC-BY-SA 4.0 license\n\u003chttps://creativecommons.org/licenses/by-sa/4.0/\u003e.\n\n## How to build the patchset in this repository\nThere are two things to note:\n\n1. This repository currently serves a dual purpose - providing a clean and \nconstantly rebased \"perfect\" history of the full RISC-V patchset, as well as \nbeing a way to grab all patches in one go, including those that haven't yet \nbeen committed upstream. As more and more patches are committed upstream, this \nrepository will become mainly interesting as a reference on how to implement \nan LLVM backend, and aid in understanding the RISC-V backend. If you just want \nto test out the latest RISC-V LLVM support, chekcing out and building upstream \nLLVM is probably your best choice.\n2. This LLVM and Clang work is not quite at a stage where end-users are likely \nto find it useful. However, building and trying it out is a great first step \ntowards contributing to the development effort.\n\nYou might build LLVM and Clang with these patches applied by doing something \nlike the below. See the [LLVM \ndocumentation](http://llvm.org/docs/GettingStarted.html) for more general \nguidance. You will need ~7GiB space for a debug build of LLVM+Clang.\n\n    export REV=326957 # Check the most recent commit on this repo to ensure this is correct\n    svn co http://llvm.org/svn/llvm-project/llvm/trunk@$REV llvm\n    cd llvm/tools\n    svn co http://llvm.org/svn/llvm-project/cfe/trunk@$REV clang\n    cd ..\n    for P in /path/to/riscv-llvm/*.patch; do patch -p1 \u003c $P; done\n    for P in /patch/to/riscv-llvm/clang/*.patch; do patch -d tools/clang -p1 \u003c $P; done\n    mkdir build\n    cd build\n    cmake -G Ninja -DCMAKE_BUILD_TYPE=\"Debug\" \\\n      -DBUILD_SHARED_LIBS=True -DLLVM_USE_SPLIT_DWARF=True \\\n      -DLLVM_OPTIMIZED_TABLEGEN=True \\\n      -DLLVM_BUILD_TESTS=True \\\n      -DDEFAULT_SYSROOT=\"/path/to/riscv-gcc-install-path/riscv32-unknown-elf\" \\\n      -DGCC_INSTALL_PREFIX=\"/path/to/riscv-gcc-install-path\" \\\n      -DLLVM_DEFAULT_TARGET_TRIPLE=\"riscv32-unknown-elf\" \\\n      -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=\"RISCV\" ../\n    cmake --build .\n\nYou may then want to run tests:\n\n    ./bin/llvm-lit -s -i -v test/MC/RISCV       # RISC-V MC-layer tests\n    ./bin/llvm-lit -s -i -v test/CodeGen/RISCV  # RISC-V CodeGen tests\n    ./bin/llvm-lit -s -i -v test                # All tests\n\n## Credits\nThis work has been led by [Alex Bradbury](https://twitter.com/asbradbury) at \nlowRISC CIC, a not for profit company. If your employer would like to see my \nwork on RISC-V LLVM to be sustained or to accelerate, contributing sponsorship \nand/or development time is the best way to do that.\nPlease contact asb@lowrisc.org if you would like to discuss sponsorship, or \nhave questions about code contributions that you can't discuss on the LLVM \nmailing list.\n\nThank you to everyone who has contributed review comments, suggestions, or\ncode to this patchset and related support patches: Sameer Abu Asal, Chandler\nCarruth, Ahmed Charles, Shiva Chen, Chih-Mao Chen, Kito Cheng, David Chisnall,\nSimon Cook, David Craven, Hal Finkel, Eli Friedman, Ondrej Glasnak, Mandeep\nSingh Grang, Ben Horgan, David Kipping, James Y Knight, David Majnemer, Ed\nMaste, John McCall, Dylan McKay, Azharuddin Mohammed, Tim Northover, Krzysztof\nParzyszek, Ana Pazos, Jordy Portman, Philip Reames, John Russo, Colin Schmidt,\nEd Schouten, Pavel Šnobl, Ulrich Weigand, Mario Werner, Eugene Zalenko,\nFlorian Zeitz, Leslie Zhai.\n","funding_links":[],"categories":["Shell"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FlowRISC%2Friscv-llvm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FlowRISC%2Friscv-llvm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FlowRISC%2Friscv-llvm/lists"}