[llvm] Add full build section to readme (PR #179447)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 3 04:21:21 PST 2026
https://github.com/IlnurHA created https://github.com/llvm/llvm-project/pull/179447
None
>From 2283607f5a3294968f14ad179fb57c3618deeacc Mon Sep 17 00:00:00 2001
From: khaser <a-horohorin at mail.ru>
Date: Sat, 18 Oct 2025 17:23:37 +0300
Subject: [PATCH 1/8] add nix flakes & readme for it
---
.gitignore | 3 +++
README-llvm.md | 44 +++++++++++++++++++++++++++++++++++
README.md | 63 ++++++++++++++++----------------------------------
flake.lock | 61 ++++++++++++++++++++++++++++++++++++++++++++++++
flake.nix | 51 ++++++++++++++++++++++++++++++++++++++++
5 files changed, 179 insertions(+), 43 deletions(-)
create mode 100644 README-llvm.md
create mode 100644 flake.lock
create mode 100644 flake.nix
diff --git a/.gitignore b/.gitignore
index 860b8ea12abd4..0e4465ed27d42 100644
--- a/.gitignore
+++ b/.gitignore
@@ -78,3 +78,6 @@ pythonenv*
/clang/utils/analyzer/projects/*/RefScanBuildResults
# automodapi puts generated documentation files here.
/lldb/docs/python_api/
+
+.direnv
+.envrc
diff --git a/README-llvm.md b/README-llvm.md
new file mode 100644
index 0000000000000..a9b29ecbc1a3a
--- /dev/null
+++ b/README-llvm.md
@@ -0,0 +1,44 @@
+# The LLVM Compiler Infrastructure
+
+[](https://securityscorecards.dev/viewer/?uri=github.com/llvm/llvm-project)
+[](https://www.bestpractices.dev/projects/8273)
+[](https://github.com/llvm/llvm-project/actions/workflows/libcxx-build-and-test.yaml?query=event%3Aschedule)
+
+Welcome to the LLVM project!
+
+This repository contains the source code for LLVM, a toolkit for the
+construction of highly optimized compilers, optimizers, and run-time
+environments.
+
+The LLVM project has multiple components. The core of the project is
+itself called "LLVM". This contains all of the tools, libraries, and header
+files needed to process intermediate representations and convert them into
+object files. Tools include an assembler, disassembler, bitcode analyzer, and
+bitcode optimizer.
+
+C-like languages use the [Clang](https://clang.llvm.org/) frontend. This
+component compiles C, C++, Objective-C, and Objective-C++ code into LLVM bitcode
+-- and from there into object files, using LLVM.
+
+Other components include:
+the [libc++ C++ standard library](https://libcxx.llvm.org),
+the [LLD linker](https://lld.llvm.org), and more.
+
+## Getting the Source Code and Building LLVM
+
+Consult the
+[Getting Started with LLVM](https://llvm.org/docs/GettingStarted.html#getting-the-source-code-and-building-llvm)
+page for information on building and running LLVM.
+
+For information on how to contribute to the LLVM project, please take a look at
+the [Contributing to LLVM](https://llvm.org/docs/Contributing.html) guide.
+
+## Getting in touch
+
+Join the [LLVM Discourse forums](https://discourse.llvm.org/), [Discord
+chat](https://discord.gg/xS7Z362),
+[LLVM Office Hours](https://llvm.org/docs/GettingInvolved.html#office-hours) or
+[Regular sync-ups](https://llvm.org/docs/GettingInvolved.html#online-sync-ups).
+
+The LLVM project has adopted a [code of conduct](https://llvm.org/docs/CodeOfConduct.html) for
+participants to all modes of communication within the project.
diff --git a/README.md b/README.md
index a9b29ecbc1a3a..5834ad99b5402 100644
--- a/README.md
+++ b/README.md
@@ -1,44 +1,21 @@
-# The LLVM Compiler Infrastructure
+# LLVM fork to work on RISC-V V-ext vectorizing issues
+
+## Repository layout
+TODO
+
+## Getting dev shell
+* Install `nix`:
+```
+$ sh <(curl --proto '=https' --tlsv1.2 -L https://nixos.org/nix/install) --no-daemon
+```
+* Enable flakes experimental feature:
+```
+mkdir ~/.config/nix/
+echo "experimental-features = nix-command flakes" > ~/.config/nix/nix.conf
+```
+* Enter to nix shell
+```
+nix develop
+```
+* (Optional) Setup [direnv](https://github.com/direnv/direnv) to enter into nix shell automatically
-[](https://securityscorecards.dev/viewer/?uri=github.com/llvm/llvm-project)
-[](https://www.bestpractices.dev/projects/8273)
-[](https://github.com/llvm/llvm-project/actions/workflows/libcxx-build-and-test.yaml?query=event%3Aschedule)
-
-Welcome to the LLVM project!
-
-This repository contains the source code for LLVM, a toolkit for the
-construction of highly optimized compilers, optimizers, and run-time
-environments.
-
-The LLVM project has multiple components. The core of the project is
-itself called "LLVM". This contains all of the tools, libraries, and header
-files needed to process intermediate representations and convert them into
-object files. Tools include an assembler, disassembler, bitcode analyzer, and
-bitcode optimizer.
-
-C-like languages use the [Clang](https://clang.llvm.org/) frontend. This
-component compiles C, C++, Objective-C, and Objective-C++ code into LLVM bitcode
--- and from there into object files, using LLVM.
-
-Other components include:
-the [libc++ C++ standard library](https://libcxx.llvm.org),
-the [LLD linker](https://lld.llvm.org), and more.
-
-## Getting the Source Code and Building LLVM
-
-Consult the
-[Getting Started with LLVM](https://llvm.org/docs/GettingStarted.html#getting-the-source-code-and-building-llvm)
-page for information on building and running LLVM.
-
-For information on how to contribute to the LLVM project, please take a look at
-the [Contributing to LLVM](https://llvm.org/docs/Contributing.html) guide.
-
-## Getting in touch
-
-Join the [LLVM Discourse forums](https://discourse.llvm.org/), [Discord
-chat](https://discord.gg/xS7Z362),
-[LLVM Office Hours](https://llvm.org/docs/GettingInvolved.html#office-hours) or
-[Regular sync-ups](https://llvm.org/docs/GettingInvolved.html#online-sync-ups).
-
-The LLVM project has adopted a [code of conduct](https://llvm.org/docs/CodeOfConduct.html) for
-participants to all modes of communication within the project.
diff --git a/flake.lock b/flake.lock
new file mode 100644
index 0000000000000..407b3b897b5c8
--- /dev/null
+++ b/flake.lock
@@ -0,0 +1,61 @@
+{
+ "nodes": {
+ "flake-utils": {
+ "inputs": {
+ "systems": "systems"
+ },
+ "locked": {
+ "lastModified": 1731533236,
+ "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
+ "owner": "numtide",
+ "repo": "flake-utils",
+ "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
+ "type": "github"
+ },
+ "original": {
+ "owner": "numtide",
+ "repo": "flake-utils",
+ "type": "github"
+ }
+ },
+ "nixpkgs": {
+ "locked": {
+ "lastModified": 1760423683,
+ "narHash": "sha256-Tb+NYuJhWZieDZUxN6PgglB16yuqBYQeMJyYBGCXlt8=",
+ "owner": "NixOS",
+ "repo": "nixpkgs",
+ "rev": "a493e93b4a259cd9fea8073f89a7ed9b1c5a1da2",
+ "type": "github"
+ },
+ "original": {
+ "owner": "NixOS",
+ "ref": "nixos-25.05",
+ "repo": "nixpkgs",
+ "type": "github"
+ }
+ },
+ "root": {
+ "inputs": {
+ "flake-utils": "flake-utils",
+ "nixpkgs": "nixpkgs"
+ }
+ },
+ "systems": {
+ "locked": {
+ "lastModified": 1681028828,
+ "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
+ "owner": "nix-systems",
+ "repo": "default",
+ "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
+ "type": "github"
+ },
+ "original": {
+ "owner": "nix-systems",
+ "repo": "default",
+ "type": "github"
+ }
+ }
+ },
+ "root": "root",
+ "version": 7
+}
diff --git a/flake.nix b/flake.nix
new file mode 100644
index 0000000000000..fdf8102785277
--- /dev/null
+++ b/flake.nix
@@ -0,0 +1,51 @@
+{
+ description = "Flake to develop llvm toolchain";
+
+ inputs = {
+ nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
+ flake-utils.url = "github:numtide/flake-utils";
+ };
+
+ outputs = { self, nixpkgs, flake-utils }:
+ flake-utils.lib.eachDefaultSystem ( system:
+ let
+ pkgs = import nixpkgs { inherit system; };
+ gccForLibs = pkgs.stdenv.cc.cc;
+ in {
+ devShell = pkgs.mkShell {
+ name = "llvm-env";
+
+ buildInputs = with pkgs; [
+ python3
+ ninja
+ cmake
+ llvmPackages_latest.llvm
+ verilator
+ ];
+
+ # where to find libgcc
+ NIX_LDFLAGS="-L${gccForLibs}/lib/gcc/${system}/${gccForLibs.version}";
+ # teach clang about C startup file locations
+ CFLAGS="-B${gccForLibs}/lib/gcc/${system}/${gccForLibs.version} -B ${pkgs.stdenv.cc.libc}/lib";
+
+ cmakeFlags = [
+ "-DGCC_INSTALL_PREFIX=${pkgs.gcc}"
+ "-DC_INCLUDE_DIRS=${pkgs.stdenv.cc.libc.dev}/include"
+ "-GNinja"
+ # Debug for debug builds
+ "-DCMAKE_BUILD_TYPE=Release"
+ # inst will be our installation prefix
+ "-DCMAKE_INSTALL_PREFIX=../inst"
+ "-DLLVM_INSTALL_TOOLCHAIN_ONLY=ON"
+ # change this to enable the projects you need
+ "-DLLVM_ENABLE_PROJECTS=clang"
+ # enable libcxx* to come into play at runtimes
+ "-DLLVM_ENABLE_RUNTIMES=libcxx;libcxxabi"
+ # this makes llvm only to produce code for the current platform, this saves CPU time, change it to what you need
+ "-DLLVM_TARGETS_TO_BUILD=host"
+ ];
+ };
+
+ });
+}
+
>From f5b34c4a170a132e493029ece8665c9e1d983471 Mon Sep 17 00:00:00 2001
From: khaser <a-horohorin at mail.ru>
Date: Sat, 18 Oct 2025 17:26:02 +0300
Subject: [PATCH 2/8] add XIangShan RTL as submodule
---
.gitmodules | 3 +++
cpu-rtl | 1 +
2 files changed, 4 insertions(+)
create mode 100644 .gitmodules
create mode 160000 cpu-rtl
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000000000..6bdeb67487cd7
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "cpu-rtl"]
+ path = cpu-rtl
+ url = git at github.com:OpenXiangShan/XiangShan.git
diff --git a/cpu-rtl b/cpu-rtl
new file mode 160000
index 0000000000000..1f3fb10e4e6d7
--- /dev/null
+++ b/cpu-rtl
@@ -0,0 +1 @@
+Subproject commit 1f3fb10e4e6d7132dd6a4f2e64338b61ac2d39e3
>From 699a5e432cdc0358c577ab67f6f46329ee4b7e12 Mon Sep 17 00:00:00 2001
From: Andrey Khorokhorin <59027018+khaser at users.noreply.github.com>
Date: Fri, 24 Oct 2025 17:51:14 +0300
Subject: [PATCH 3/8] fix issues with flake.nix (#10)
---
README.md | 10 +++++++++-
flake.nix | 51 +++++++++++++++++++++++++++------------------------
2 files changed, 36 insertions(+), 25 deletions(-)
diff --git a/README.md b/README.md
index 5834ad99b5402..5badcbe453d30 100644
--- a/README.md
+++ b/README.md
@@ -6,7 +6,7 @@ TODO
## Getting dev shell
* Install `nix`:
```
-$ sh <(curl --proto '=https' --tlsv1.2 -L https://nixos.org/nix/install) --no-daemon
+sh <(curl --proto '=https' --tlsv1.2 -L https://nixos.org/nix/install) --no-daemon
```
* Enable flakes experimental feature:
```
@@ -19,3 +19,11 @@ nix develop
```
* (Optional) Setup [direnv](https://github.com/direnv/direnv) to enter into nix shell automatically
+
+## Building
+
+Inside nix shell:
+```
+cmake $cmakeFlags -S llvm -B build
+ninja -C build
+```
diff --git a/flake.nix b/flake.nix
index fdf8102785277..bb29b49f8bd8b 100644
--- a/flake.nix
+++ b/flake.nix
@@ -11,41 +11,44 @@
let
pkgs = import nixpkgs { inherit system; };
gccForLibs = pkgs.stdenv.cc.cc;
- in {
- devShell = pkgs.mkShell {
- name = "llvm-env";
+ in rec {
+
+ defaultPackage = pkgs.stdenv.mkDerivation {
+ name = "llvm";
+
+ dontUnpack = true;
buildInputs = with pkgs; [
python3
ninja
cmake
- llvmPackages_latest.llvm
- verilator
];
- # where to find libgcc
- NIX_LDFLAGS="-L${gccForLibs}/lib/gcc/${system}/${gccForLibs.version}";
- # teach clang about C startup file locations
- CFLAGS="-B${gccForLibs}/lib/gcc/${system}/${gccForLibs.version} -B ${pkgs.stdenv.cc.libc}/lib";
-
cmakeFlags = [
- "-DGCC_INSTALL_PREFIX=${pkgs.gcc}"
- "-DC_INCLUDE_DIRS=${pkgs.stdenv.cc.libc.dev}/include"
- "-GNinja"
- # Debug for debug builds
- "-DCMAKE_BUILD_TYPE=Release"
- # inst will be our installation prefix
- "-DCMAKE_INSTALL_PREFIX=../inst"
- "-DLLVM_INSTALL_TOOLCHAIN_ONLY=ON"
- # change this to enable the projects you need
- "-DLLVM_ENABLE_PROJECTS=clang"
- # enable libcxx* to come into play at runtimes
- "-DLLVM_ENABLE_RUNTIMES=libcxx;libcxxabi"
- # this makes llvm only to produce code for the current platform, this saves CPU time, change it to what you need
- "-DLLVM_TARGETS_TO_BUILD=host"
+ "-DUSE_DEPRECATED_GCC_INSTALL_PREFIX=1"
+ "-DGCC_INSTALL_PREFIX=${pkgs.gcc}"
+ "-DC_INCLUDE_DIRS=${pkgs.stdenv.cc.libc.dev}/include"
+ "-GNinja"
+ # Debug for debug builds
+ "-DCMAKE_BUILD_TYPE=Release"
+ # inst will be our installation prefix
+ "-DCMAKE_INSTALL_PREFIX=../inst"
+ "-DLLVM_INSTALL_TOOLCHAIN_ONLY=ON"
+ # change this to enable the projects you need
+ "-DLLVM_ENABLE_PROJECTS=clang"
+ # enable libcxx* to come into play at runtimes
+ "-DLLVM_ENABLE_RUNTIMES=libcxx;libcxxabi"
+ # this makes llvm only to produce code for the current platform, this saves CPU time, change it to what you need
+ "-DLLVM_TARGETS_TO_BUILD=host"
+ "-S ${self}/llvm"
];
};
+ devShell = (defaultPackage.overrideAttrs (oldAttrs: {
+ name = "llvm-env";
+ buildInputs = oldAttrs.buildInputs ++ (with pkgs; [ verilator ]);
+ }));
+
});
}
>From fe8e5f8dcc6d0cea48707f1754fbfe9d30ea65d5 Mon Sep 17 00:00:00 2001
From: Andrey Khorokhorin <59027018+khaser at users.noreply.github.com>
Date: Mon, 1 Dec 2025 13:01:46 +0300
Subject: [PATCH 4/8] Flake update: build sim & toolchain (#16)
---
cpu-rtl | 1 -
flake.lock | 31 +++++++++++----
flake.nix | 109 ++++++++++++++++++++++++++++++++++++++++-------------
3 files changed, 106 insertions(+), 35 deletions(-)
delete mode 160000 cpu-rtl
diff --git a/cpu-rtl b/cpu-rtl
deleted file mode 160000
index 1f3fb10e4e6d7..0000000000000
--- a/cpu-rtl
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit 1f3fb10e4e6d7132dd6a4f2e64338b61ac2d39e3
diff --git a/flake.lock b/flake.lock
index 407b3b897b5c8..85dd955dc2c66 100644
--- a/flake.lock
+++ b/flake.lock
@@ -5,11 +5,11 @@
"systems": "systems"
},
"locked": {
- "lastModified": 1731533236,
- "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
+ "lastModified": 1694529238,
+ "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
"owner": "numtide",
"repo": "flake-utils",
- "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
+ "rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
"type": "github"
},
"original": {
@@ -20,11 +20,27 @@
},
"nixpkgs": {
"locked": {
- "lastModified": 1760423683,
- "narHash": "sha256-Tb+NYuJhWZieDZUxN6PgglB16yuqBYQeMJyYBGCXlt8=",
+ "lastModified": 1762498405,
+ "narHash": "sha256-Zg/SCgCaAioc0/SVZQJxuECGPJy+OAeBcGeA5okdYDc=",
"owner": "NixOS",
"repo": "nixpkgs",
- "rev": "a493e93b4a259cd9fea8073f89a7ed9b1c5a1da2",
+ "rev": "6faeb062ee4cf4f105989d490831713cc5a43ee1",
+ "type": "github"
+ },
+ "original": {
+ "owner": "NixOS",
+ "ref": "nixos-25.05",
+ "repo": "nixpkgs",
+ "type": "github"
+ }
+ },
+ "nixpkgs-circt": {
+ "locked": {
+ "lastModified": 1696019113,
+ "narHash": "sha256-X3+DKYWJm93DRSdC5M6K5hLqzSya9BjibtBsuARoPco=",
+ "owner": "NixOS",
+ "repo": "nixpkgs",
+ "rev": "f5892ddac112a1e9b3612c39af1b72987ee5783a",
"type": "github"
},
"original": {
@@ -37,7 +53,8 @@
"root": {
"inputs": {
"flake-utils": "flake-utils",
- "nixpkgs": "nixpkgs"
+ "nixpkgs": "nixpkgs",
+ "nixpkgs-circt": "nixpkgs-circt"
}
},
"systems": {
diff --git a/flake.nix b/flake.nix
index bb29b49f8bd8b..2c0a963b32a41 100644
--- a/flake.nix
+++ b/flake.nix
@@ -3,52 +3,107 @@
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
+ nixpkgs-circt.url = "github:NixOS/nixpkgs/nixos-25.05";
flake-utils.url = "github:numtide/flake-utils";
};
- outputs = { self, nixpkgs, flake-utils }:
+ outputs = { self, nixpkgs, nixpkgs-circt, flake-utils }:
flake-utils.lib.eachDefaultSystem ( system:
let
- pkgs = import nixpkgs { inherit system; };
- gccForLibs = pkgs.stdenv.cc.cc;
+ pkgs = import nixpkgs { inherit system; config.allowUnfree = true; };
+ circt = (import nixpkgs-circt { inherit system; }).circt;
+ pkgsRV = pkgs.pkgsCross.riscv64;
+ targetLlvmLibraries = pkgsRV.llvmPackages_21;
in rec {
- defaultPackage = pkgs.stdenv.mkDerivation {
- name = "llvm";
+ defaultPackage = packages.toolchain;
- dontUnpack = true;
+ packages.toolchain = with pkgsRV; (wrapCCWith rec {
+ cc = (targetLlvmLibraries.clang-unwrapped.override {
+ src = ./.;
+ libllvm = (targetLlvmLibraries.libllvm.override { src = ./.; });
+ });
+ # libstdcxx is taken from gcc in an ad-hoc way in cc-wrapper.
+ libcxx = null;
+ extraPackages = [ targetLlvmLibraries.compiler-rt ];
+ extraBuildCommands = ''
+ rsrc="$out/resource-root"
+ mkdir "$rsrc"
+ ln -s "${lib.getLib cc}/lib/clang/*/include" "$rsrc"
+ echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags
+ ln -s "${targetLlvmLibraries.compiler-rt.out}/lib" "$rsrc/lib"
+ ln -s "${targetLlvmLibraries.compiler-rt.out}/share" "$rsrc/share"
+ '';
+ });
- buildInputs = with pkgs; [
+ packages.sim = pkgs.stdenv.mkDerivation {
+ name = "fck-china-sim";
+ # Floating derivation!!!
+ __impure = true;
+
+ src = pkgs.fetchgit {
+ url = "https://github.com/OpenXiangShan/XiangShan.git";
+ rev = "0fb84f8ddbfc9480d870f72cc903ac6453c888c9";
+ fetchSubmodules = true;
+ leaveDotGit = true;
+ sha256 = "sha256-C+y//RJxI8FwYWCs8dmYLh8ZGVNCTAnRoiOVuY913Jg=";
+ deepClone = false;
+ };
+
+ nativeBuildInputs = with pkgs; [
+ mill
+ time
+ git
+ espresso
+ verilator
python3
- ninja
- cmake
];
- cmakeFlags = [
- "-DUSE_DEPRECATED_GCC_INSTALL_PREFIX=1"
- "-DGCC_INSTALL_PREFIX=${pkgs.gcc}"
- "-DC_INCLUDE_DIRS=${pkgs.stdenv.cc.libc.dev}/include"
- "-GNinja"
- # Debug for debug builds
- "-DCMAKE_BUILD_TYPE=Release"
- # inst will be our installation prefix
- "-DCMAKE_INSTALL_PREFIX=../inst"
- "-DLLVM_INSTALL_TOOLCHAIN_ONLY=ON"
- # change this to enable the projects you need
- "-DLLVM_ENABLE_PROJECTS=clang"
- # enable libcxx* to come into play at runtimes
- "-DLLVM_ENABLE_RUNTIMES=libcxx;libcxxabi"
- # this makes llvm only to produce code for the current platform, this saves CPU time, change it to what you need
- "-DLLVM_TARGETS_TO_BUILD=host"
- "-S ${self}/llvm"
+ buildInputs = with pkgs; [
+ sqlite.dev
+ zlib.dev
+ zstd.dev
];
+
+ buildPhase = ''
+ runHook preBuild
+
+ # Copy sources
+ export NOOP_HOME=$out/src
+ echo src = $src
+ echo NOOP_HOME = $NOOP_HOME
+ mkdir -p $NOOP_HOME
+ cp -r $src/* $src/.* $NOOP_HOME
+
+ # Patch shebangs
+ chmod u+wx -R $NOOP_HOME
+ patchShebangs --build $NOOP_HOME/scripts/
+
+ # Build
+ export _JAVA_OPTIONS="-XX:+UseZGC -XX:+ZUncommit -XX:ZUncommitDelay=30"
+ FIRTOOL=${circt}/bin/firtool JVM_XMX=20G make -j8 -C $NOOP_HOME emu
+
+ runHook postBuild
+ '';
+
+ installPhase = ''
+ runHook preInstall
+
+ mkdir -p $out/bin
+ chmod u+x -R $out/src/build/
+ cp $out/src/build/verilator-compile/emu $out/bin
+ rm -rf $out/src
+
+ runHook postInstall
+ '';
};
devShell = (defaultPackage.overrideAttrs (oldAttrs: {
name = "llvm-env";
- buildInputs = oldAttrs.buildInputs ++ (with pkgs; [ verilator ]);
+ buildInputs = oldAttrs.buildInputs;
}));
+
});
}
>From 984ab8b046612f2a9759be5eb1889770a217867b Mon Sep 17 00:00:00 2001
From: Andrey Khorokhorin <59027018+khaser at users.noreply.github.com>
Date: Thu, 4 Dec 2025 11:07:29 +0300
Subject: [PATCH 5/8] Add instructions & environment for LLVM devs (#25)
---
README.md | 64 +++++++++++++++++++++++++++++++++++++++++++++++++------
flake.nix | 18 +++++++++++-----
2 files changed, 70 insertions(+), 12 deletions(-)
diff --git a/README.md b/README.md
index 5badcbe453d30..ba9b3d3c63818 100644
--- a/README.md
+++ b/README.md
@@ -1,9 +1,8 @@
# LLVM fork to work on RISC-V V-ext vectorizing issues
-## Repository layout
-TODO
+## Working on LLVM
-## Getting dev shell
+### Getting dev shell
* Install `nix`:
```
sh <(curl --proto '=https' --tlsv1.2 -L https://nixos.org/nix/install) --no-daemon
@@ -11,19 +10,70 @@ sh <(curl --proto '=https' --tlsv1.2 -L https://nixos.org/nix/install) --no-daem
* Enable flakes experimental feature:
```
mkdir ~/.config/nix/
-echo "experimental-features = nix-command flakes" > ~/.config/nix/nix.conf
+echo "experimental-features = nix-command flakes impure-derivations ca-derivations" > ~/.config/nix/nix.conf
```
* Enter to nix shell
```
-nix develop
+nix develop '.#toolchain'
```
* (Optional) Setup [direnv](https://github.com/direnv/direnv) to enter into nix shell automatically
+### Setup connection to binary cache
+#### Why is that necessary?
+Every nix package have unique hash, which can be computed before building process.
+When you build any thing, nix firstly tries to find built package across connected binary caches.
+Cross LLVM build process requires a lot of tools,
+not all of which are available as binary package in public package repositories.
+After first LLVM build (which I'am already done) all of this packages become available in our binary package cache.
-## Building
+#### Setup ssh access
+Firstly, you need setup ssh access to specified user **for `root` user in your system**.
+```
+host vityaman-nix-storage
+ user nix-storage
+ hostname 62.84.116.90
+ port 22
+ identityfile ~/.ssh/nix-storage_id_rsa
+```
+Private key can be found in telegram developers chat.
+#### Setup nix substituters
+Next, you need add our host into *substituters*.
+Usually, it can be done by adding following line into `~/.config/nix/nix.conf`:
+```
+substituters = ssh://vityaman-nix-storage
+```
+
+### Building LLVM
+Enter into nix shell:
+```
+nix develop
+```
-Inside nix shell:
+Then build libllvm in normal way:
```
cmake $cmakeFlags -S llvm -B build
ninja -C build
```
+
+After that, you can use built libllvm with upstream clang, which preinstalled in nix shell.
+Minimal example to compile code for Linux/RISC-V environment.
+```
+// inside `nix develop` shell
+riscv64-unknown-linux-gnu-clang++ hello.cpp -emit-llvm -S -o hello.ll
+../build/bin/llc -march=riscv64 --relocation-model=pic hello.ll -o hello.s
+riscv64-unknown-linux-gnu-clang++ hello.s hello.o
+```
+For details see [LLVM docs](https://llvm.org/docs/GettingStarted.html).
+
+### Running performance testing
+TODO[khaser]: not implemented yet
+
+### Running regression testing
+TODO[khaser]: not implemented yet
+
+### Misc
+Original LLVM readme can be found in [./README-llvm.md](./README-llvm.md)
+
+### Infra notes
+TODO[khaser]: write notes
+
diff --git a/flake.nix b/flake.nix
index 2c0a963b32a41..809f877db2c75 100644
--- a/flake.nix
+++ b/flake.nix
@@ -14,6 +14,7 @@
circt = (import nixpkgs-circt { inherit system; }).circt;
pkgsRV = pkgs.pkgsCross.riscv64;
targetLlvmLibraries = pkgsRV.llvmPackages_21;
+ patched-libllvm = (targetLlvmLibraries.libllvm.override { src = ./.; });
in rec {
defaultPackage = packages.toolchain;
@@ -21,7 +22,7 @@
packages.toolchain = with pkgsRV; (wrapCCWith rec {
cc = (targetLlvmLibraries.clang-unwrapped.override {
src = ./.;
- libllvm = (targetLlvmLibraries.libllvm.override { src = ./.; });
+ libllvm = patched-libllvm;
});
# libstdcxx is taken from gcc in an ad-hoc way in cc-wrapper.
libcxx = null;
@@ -98,11 +99,18 @@
'';
};
- devShell = (defaultPackage.overrideAttrs (oldAttrs: {
- name = "llvm-env";
- buildInputs = oldAttrs.buildInputs;
- }));
+ devShells.default = targetLlvmLibraries.stdenv.mkDerivation {
+ name = "devShell";
+ # buildInputs = [];
+ # ++ (with patched-libllvm; nativeBuildInputs ++ buildInputs ++ propagatedBuildInputs);
+ cmakeFlags = [
+ "-GNinja"
+ "-DCMAKE_BUILD_TYPE=Debug"
+ "-DLLVM_TARGETS_TO_BUILD=RISCV"
+ ];
+
+ };
});
}
>From a2eed9f339ab1dc04fa01e92514577d0c58cee28 Mon Sep 17 00:00:00 2001
From: Artemiy Romanov <92217834+artemiyjjj at users.noreply.github.com>
Date: Thu, 11 Dec 2025 03:43:07 +0300
Subject: [PATCH 6/8] Regression testing support (#26)
Co-authored-by: khaser <a-horohorin at mail.ru>
---
README.md | 3 ++-
flake.nix | 24 ++++++++++++++----------
2 files changed, 16 insertions(+), 11 deletions(-)
diff --git a/README.md b/README.md
index ba9b3d3c63818..96532b7c70cd5 100644
--- a/README.md
+++ b/README.md
@@ -69,7 +69,8 @@ For details see [LLVM docs](https://llvm.org/docs/GettingStarted.html).
TODO[khaser]: not implemented yet
### Running regression testing
-TODO[khaser]: not implemented yet
+Since llvm is built with tests and tools for it, run `<build_dir>/bin/llvm-lit test/Transforms/SLPVectorizer`
+to perform regression testing for SLPVectorizer test-suite.
### Misc
Original LLVM readme can be found in [./README-llvm.md](./README-llvm.md)
diff --git a/flake.nix b/flake.nix
index 809f877db2c75..0feaf0d29fa85 100644
--- a/flake.nix
+++ b/flake.nix
@@ -14,7 +14,19 @@
circt = (import nixpkgs-circt { inherit system; }).circt;
pkgsRV = pkgs.pkgsCross.riscv64;
targetLlvmLibraries = pkgsRV.llvmPackages_21;
- patched-libllvm = (targetLlvmLibraries.libllvm.override { src = ./.; });
+ llvmCmakeFlags = [
+ "-DLLVM_TARGETS_TO_BUILD=RISCV"
+ "-DLLVM_ENABLE_PROJECTS=''"
+ "-DLLVM_ENABLE_RUNTIMES=''"
+ "-DLLVM_INCLUDE_UTILS=ON"
+ "-DLLVM_INCLUDE_TESTS=ON"
+ "-DLLVM_INCLUDE_TOOLS=ON"
+ ];
+ patched-libllvm =
+ (targetLlvmLibraries.libllvm.override {
+ src = ./.;
+ devExtraCmakeFlags = llvmCmakeFlags;
+ });
in rec {
defaultPackage = packages.toolchain;
@@ -101,15 +113,7 @@
devShells.default = targetLlvmLibraries.stdenv.mkDerivation {
name = "devShell";
- # buildInputs = [];
- # ++ (with patched-libllvm; nativeBuildInputs ++ buildInputs ++ propagatedBuildInputs);
-
- cmakeFlags = [
- "-GNinja"
- "-DCMAKE_BUILD_TYPE=Debug"
- "-DLLVM_TARGETS_TO_BUILD=RISCV"
- ];
-
+ cmakeFlags = llvmCmakeFlags ++ [ "-GNinja" ];
};
});
>From 40b0bf556d26c9ae30d3a0f14adaecb862a4ec37 Mon Sep 17 00:00:00 2001
From: Andrey Khorokhorin <59027018+khaser at users.noreply.github.com>
Date: Fri, 23 Jan 2026 02:12:36 +0300
Subject: [PATCH 7/8] Update readme (#27)
---
README.md | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/README.md b/README.md
index 96532b7c70cd5..e7af7d0e24e0b 100644
--- a/README.md
+++ b/README.md
@@ -66,7 +66,7 @@ riscv64-unknown-linux-gnu-clang++ hello.s hello.o
For details see [LLVM docs](https://llvm.org/docs/GettingStarted.html).
### Running performance testing
-TODO[khaser]: not implemented yet
+See [simba repository](https://github.com/llvm-rv-vext-improvements/simba).
### Running regression testing
Since llvm is built with tests and tools for it, run `<build_dir>/bin/llvm-lit test/Transforms/SLPVectorizer`
@@ -75,6 +75,3 @@ to perform regression testing for SLPVectorizer test-suite.
### Misc
Original LLVM readme can be found in [./README-llvm.md](./README-llvm.md)
-### Infra notes
-TODO[khaser]: write notes
-
>From b2e57616f918c1f4a2cbb9728c9af92336d93def Mon Sep 17 00:00:00 2001
From: IlnurHA <Ilnur_ha at mail.ru>
Date: Tue, 3 Feb 2026 15:20:16 +0300
Subject: [PATCH 8/8] fixed formatting in README; added Full build subsection
in Build LLVM section
---
README.md | 64 +++++++++++++++++++++++++++++++++++++++++--------------
1 file changed, 48 insertions(+), 16 deletions(-)
diff --git a/README.md b/README.md
index e7af7d0e24e0b..b3a20953f0816 100644
--- a/README.md
+++ b/README.md
@@ -3,23 +3,32 @@
## Working on LLVM
### Getting dev shell
+
* Install `nix`:
-```
-sh <(curl --proto '=https' --tlsv1.2 -L https://nixos.org/nix/install) --no-daemon
-```
+
+ ```shell
+ sh <(curl --proto '=https' --tlsv1.2 -L https://nixos.org/nix/install) --no-daemon
+ ```
+
* Enable flakes experimental feature:
-```
-mkdir ~/.config/nix/
-echo "experimental-features = nix-command flakes impure-derivations ca-derivations" > ~/.config/nix/nix.conf
-```
+
+ ```shell
+ mkdir ~/.config/nix/
+ echo "experimental-features = nix-command flakes impure-derivations ca-derivations" > ~/.config/nix/nix.conf
+ ```
+
* Enter to nix shell
-```
-nix develop '.#toolchain'
-```
+
+ ```shell
+ nix develop '.#toolchain'
+ ```
+
* (Optional) Setup [direnv](https://github.com/direnv/direnv) to enter into nix shell automatically
### Setup connection to binary cache
+
#### Why is that necessary?
+
Every nix package have unique hash, which can be computed before building process.
When you build any thing, nix firstly tries to find built package across connected binary caches.
Cross LLVM build process requires a lot of tools,
@@ -27,51 +36,74 @@ not all of which are available as binary package in public package repositories.
After first LLVM build (which I'am already done) all of this packages become available in our binary package cache.
#### Setup ssh access
+
Firstly, you need setup ssh access to specified user **for `root` user in your system**.
-```
+
+```sshConfig
host vityaman-nix-storage
user nix-storage
hostname 62.84.116.90
port 22
identityfile ~/.ssh/nix-storage_id_rsa
```
+
Private key can be found in telegram developers chat.
+
#### Setup nix substituters
+
Next, you need add our host into *substituters*.
Usually, it can be done by adding following line into `~/.config/nix/nix.conf`:
-```
+
+```sshConfig
substituters = ssh://vityaman-nix-storage
```
### Building LLVM
+
+#### Partial build
+
Enter into nix shell:
-```
+
+```shell
nix develop
```
Then build libllvm in normal way:
-```
+
+```shell
cmake $cmakeFlags -S llvm -B build
ninja -C build
```
After that, you can use built libllvm with upstream clang, which preinstalled in nix shell.
Minimal example to compile code for Linux/RISC-V environment.
-```
+
+```shell
// inside `nix develop` shell
riscv64-unknown-linux-gnu-clang++ hello.cpp -emit-llvm -S -o hello.ll
../build/bin/llc -march=riscv64 --relocation-model=pic hello.ll -o hello.s
riscv64-unknown-linux-gnu-clang++ hello.s hello.o
```
+
For details see [LLVM docs](https://llvm.org/docs/GettingStarted.html).
+#### Full build
+
+To build full toolchain execute the following command:
+
+```shell
+nix build '.#toolchain'
+```
+
### Running performance testing
+
See [simba repository](https://github.com/llvm-rv-vext-improvements/simba).
### Running regression testing
+
Since llvm is built with tests and tools for it, run `<build_dir>/bin/llvm-lit test/Transforms/SLPVectorizer`
to perform regression testing for SLPVectorizer test-suite.
### Misc
-Original LLVM readme can be found in [./README-llvm.md](./README-llvm.md)
+Original LLVM readme can be found in [./README-llvm.md](./README-llvm.md)
More information about the llvm-commits
mailing list