Skip to content

Commit 984ab8b

Browse files
authored
Add instructions & environment for LLVM devs (#25)
1 parent fe8e5f8 commit 984ab8b

File tree

2 files changed

+70
-12
lines changed

2 files changed

+70
-12
lines changed

README.md

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,79 @@
11
# LLVM fork to work on RISC-V V-ext vectorizing issues
22

3-
## Repository layout
4-
TODO
3+
## Working on LLVM
54

6-
## Getting dev shell
5+
### Getting dev shell
76
* Install `nix`:
87
```
98
sh <(curl --proto '=https' --tlsv1.2 -L https://nixos.org/nix/install) --no-daemon
109
```
1110
* Enable flakes experimental feature:
1211
```
1312
mkdir ~/.config/nix/
14-
echo "experimental-features = nix-command flakes" > ~/.config/nix/nix.conf
13+
echo "experimental-features = nix-command flakes impure-derivations ca-derivations" > ~/.config/nix/nix.conf
1514
```
1615
* Enter to nix shell
1716
```
18-
nix develop
17+
nix develop '.#toolchain'
1918
```
2019
* (Optional) Setup [direnv](https://github.com/direnv/direnv) to enter into nix shell automatically
2120

21+
### Setup connection to binary cache
22+
#### Why is that necessary?
23+
Every nix package have unique hash, which can be computed before building process.
24+
When you build any thing, nix firstly tries to find built package across connected binary caches.
25+
Cross LLVM build process requires a lot of tools,
26+
not all of which are available as binary package in public package repositories.
27+
After first LLVM build (which I'am already done) all of this packages become available in our binary package cache.
2228

23-
## Building
29+
#### Setup ssh access
30+
Firstly, you need setup ssh access to specified user **for `root` user in your system**.
31+
```
32+
host vityaman-nix-storage
33+
user nix-storage
34+
hostname 62.84.116.90
35+
port 22
36+
identityfile ~/.ssh/nix-storage_id_rsa
37+
```
38+
Private key can be found in telegram developers chat.
39+
#### Setup nix substituters
40+
Next, you need add our host into *substituters*.
41+
Usually, it can be done by adding following line into `~/.config/nix/nix.conf`:
42+
```
43+
substituters = ssh://vityaman-nix-storage
44+
```
45+
46+
### Building LLVM
47+
Enter into nix shell:
48+
```
49+
nix develop
50+
```
2451

25-
Inside nix shell:
52+
Then build libllvm in normal way:
2653
```
2754
cmake $cmakeFlags -S llvm -B build
2855
ninja -C build
2956
```
57+
58+
After that, you can use built libllvm with upstream clang, which preinstalled in nix shell.
59+
Minimal example to compile code for Linux/RISC-V environment.
60+
```
61+
// inside `nix develop` shell
62+
riscv64-unknown-linux-gnu-clang++ hello.cpp -emit-llvm -S -o hello.ll
63+
../build/bin/llc -march=riscv64 --relocation-model=pic hello.ll -o hello.s
64+
riscv64-unknown-linux-gnu-clang++ hello.s hello.o
65+
```
66+
For details see [LLVM docs](https://llvm.org/docs/GettingStarted.html).
67+
68+
### Running performance testing
69+
TODO[khaser]: not implemented yet
70+
71+
### Running regression testing
72+
TODO[khaser]: not implemented yet
73+
74+
### Misc
75+
Original LLVM readme can be found in [./README-llvm.md](./README-llvm.md)
76+
77+
### Infra notes
78+
TODO[khaser]: write notes
79+

flake.nix

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@
1414
circt = (import nixpkgs-circt { inherit system; }).circt;
1515
pkgsRV = pkgs.pkgsCross.riscv64;
1616
targetLlvmLibraries = pkgsRV.llvmPackages_21;
17+
patched-libllvm = (targetLlvmLibraries.libllvm.override { src = ./.; });
1718
in rec {
1819

1920
defaultPackage = packages.toolchain;
2021

2122
packages.toolchain = with pkgsRV; (wrapCCWith rec {
2223
cc = (targetLlvmLibraries.clang-unwrapped.override {
2324
src = ./.;
24-
libllvm = (targetLlvmLibraries.libllvm.override { src = ./.; });
25+
libllvm = patched-libllvm;
2526
});
2627
# libstdcxx is taken from gcc in an ad-hoc way in cc-wrapper.
2728
libcxx = null;
@@ -98,11 +99,18 @@
9899
'';
99100
};
100101

101-
devShell = (defaultPackage.overrideAttrs (oldAttrs: {
102-
name = "llvm-env";
103-
buildInputs = oldAttrs.buildInputs;
104-
}));
102+
devShells.default = targetLlvmLibraries.stdenv.mkDerivation {
103+
name = "devShell";
104+
# buildInputs = [];
105+
# ++ (with patched-libllvm; nativeBuildInputs ++ buildInputs ++ propagatedBuildInputs);
105106

107+
cmakeFlags = [
108+
"-GNinja"
109+
"-DCMAKE_BUILD_TYPE=Debug"
110+
"-DLLVM_TARGETS_TO_BUILD=RISCV"
111+
];
112+
113+
};
106114

107115
});
108116
}

0 commit comments

Comments
 (0)