GithubHelp home page GithubHelp logo

isabella232 / riscv-llvm Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sifive/riscv-llvm

1.0 1.0 0.0 966.16 MB

SiFive's LLVM working tree

Shell 0.28% JavaScript 0.04% Ruby 0.01% C++ 66.78% Python 2.18% Perl 0.11% C 15.76% PHP 0.01% Emacs Lisp 0.02% Objective-C 1.39% OCaml 0.12% Common Lisp 0.01% Smalltalk 0.01% Fortran 0.01% SuperCollider 0.01% R 0.01% Go 0.15% C# 0.03% Assembly 13.13% Ada 0.01%

riscv-llvm's Introduction

RISC-V LLVM

NOTICE

The code in this repo is now quite out of date compared to master llvm plus all the RISC-V patches that were added here have now been upstreamed.

However, the build instructions themselves are still a good quick-start guide.

I've updated the commands below to clone llvm from the official llvm repository, not from here, and to account for RISC-V now having been upgraded to non-experimental status.

About

This repository adds support for various aspects of the RISC-V instruction set to the Clang C/C++ compiler and LLVM back end.

The "master" branch follows official LLVM.

The "dev" branch at the moment contains mostly patches developed by the LowRISC project that have not yet been upstreamed to the official LLVM repository. It is updated from the master branch regularly. As more patches are committed to upstream LLVM the differences will become smaller, but the intention is to add other patches here so people can conveniently use them in advance of them being accepted into upstream.

How can I build LLVM+Clang and use it to cross-compile for a riscv target?

As well as this repository, you will need the RISC-V gcc toolchain. If you don't have RISC-V hardware then you will want to have QEMU to run your programs.

The following bash commands have been tested on a fresh Ubuntu install (e.g. Amazon EC2 Ubuntu 16.04 LTS ami-0e32ec5bc225539f5 and 18.04 LTS ami-0bbe6b35405ecebdb) and are known to result in a working RISC-V LLVM.

If you already have recent RISC-V gnu tools and/or qemu in your PATH then you can omit the steps to download and build those.

At the moment the clang driver does not successfully find the gnu linker and libraries so you need to explicitly use gcc to link your object files. This should be fixed soon.

By default clang is generating rv32imac/rv64imac code but you can override this, and in particular if you have floating point hardware you can add "-march=rv32gc" (or rv64gc) to the clang command line to get FPU instructions with a soft float ABI (scalar FP function arguments and results passed in integer registers).

sudo apt-get update
sudo apt-get -y dist-upgrade

The dist-upgrade can pop up a text GUI and ask questions (for example I've seen them about updating grub), which eats input already pasted, so it's best to wait for the result from the above two lines by themselves before proceeding.

sudo apt-get -y install \
  binutils build-essential libtool texinfo \
  gzip zip unzip patchutils curl git \
  make cmake ninja-build automake bison flex gperf \
  grep sed gawk python bc \
  zlib1g-dev libexpat1-dev libmpc-dev \
  libglib2.0-dev libfdt-dev libpixman-1-dev 

mkdir riscv
cd riscv
mkdir _install
export PATH=`pwd`/_install/bin:$PATH
hash -r

# gcc, binutils, newlib
git clone --recursive https://github.com/riscv/riscv-gnu-toolchain
pushd riscv-gnu-toolchain
./configure --prefix=`pwd`/../_install --enable-multilib
make -j`nproc`

# qemu
make -j`nproc` build-qemu
popd

# LLVM
git clone https://github.com/llvm/llvm-project.git riscv-llvm
#git clone https://github.com/sifive/riscv-llvm
pushd riscv-llvm
ln -s ../../clang llvm/tools || true
mkdir _build
cd _build
cmake -G Ninja -DCMAKE_BUILD_TYPE="Release" \
  -DBUILD_SHARED_LIBS=True -DLLVM_USE_SPLIT_DWARF=True \
  -DCMAKE_INSTALL_PREFIX="../../_install" \
  -DLLVM_OPTIMIZED_TABLEGEN=True -DLLVM_BUILD_TESTS=False \
  -DDEFAULT_SYSROOT="../../_install/riscv64-unknown-elf" \
  -DLLVM_DEFAULT_TARGET_TRIPLE="riscv64-unknown-elf" \
  -DLLVM_TARGETS_TO_BUILD="RISCV" \
  ../llvm
cmake --build . --target install
popd

# Sanity test your new RISC-V LLVM
cat >hello.c <<END
#include <stdio.h>

int main(){
  printf("Hello RISCV!\n");
  return 0;
}
END

# 32 bit
clang -O -c hello.c --target=riscv32
riscv64-unknown-elf-gcc hello.o -o hello -march=rv32imac -mabi=ilp32
qemu-riscv32 hello

# 64 bit
clang -O -c hello.c
riscv64-unknown-elf-gcc hello.o -o hello -march=rv64imac -mabi=lp64
qemu-riscv64 hello

riscv-llvm's People

Contributors

akyrtzi avatar arsenm avatar chandlerc avatar chapuni avatar cunningbaldrick avatar d0k avatar ddunbar avatar djasper avatar douggregor avatar dwblaikie avatar echristo avatar eefriedman avatar ericwf avatar espindola avatar isanbard avatar kcc avatar lattner avatar majnemer avatar nlewycky avatar resistor avatar rjmccall avatar rksimon avatar rnk avatar rotateright avatar rui314 avatar stoklund avatar tkremenek avatar tobiasgrosser avatar topperc avatar zygoloid avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.