From 3e5a42de8b834cb29a33feefa240ede5f255c69f Mon Sep 17 00:00:00 2001 From: Jerry Zhao Date: Tue, 27 Feb 2024 16:30:26 -0800 Subject: [PATCH 1/7] Add script to build circt-from-source - from submodule --- .gitmodules | 3 + scripts/build-circt-from-source.sh | 97 ++++++++++++++++++++++++++++++ tools/circt | 1 + 3 files changed, 101 insertions(+) create mode 100755 scripts/build-circt-from-source.sh create mode 160000 tools/circt diff --git a/.gitmodules b/.gitmodules index 4f21369e..3aacc69d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -148,3 +148,6 @@ [submodule "generators/rocket-chip-inclusive-cache"] path = generators/rocket-chip-inclusive-cache url = https://github.com/chipsalliance/rocket-chip-inclusive-cache.git +[submodule "tools/circt"] + path = tools/circt + url = https://github.com/llvm/circt.git diff --git a/scripts/build-circt-from-source.sh b/scripts/build-circt-from-source.sh new file mode 100755 index 00000000..55370536 --- /dev/null +++ b/scripts/build-circt-from-source.sh @@ -0,0 +1,97 @@ +#!/usr/bin/env bash + +# exit script if any command fails +set -e +set -o pipefail + +RDIR=$(git rev-parse --show-toplevel) + +# get helpful utilities +source $RDIR/scripts/utils.sh + +common_setup + +# Allow user to override MAKE +[ -n "${MAKE:+x}" ] || MAKE=$(command -v gnumake || command -v gmake || command -v make) +readonly MAKE + +usage() { + echo "usage: ${0}" + echo "" + echo "Options" + echo " --prefix -p PREFIX : Install destination." + echo " --help -h : Display this message" + exit "$1" +} + +PREFIX="" + +# getopts does not support long options, and is inflexible +while [ "$1" != "" ]; +do + case $1 in + -h | -H | --help | help ) + usage 3 ;; + -p | --prefix ) + shift + PREFIX=$(realpath $1) ;; + * ) + error "invalid option $1" + usage 1 ;; + esac + shift +done + +if [ -z "$PREFIX" ] ; then + error "ERROR: Prefix not given." + exit 1 +fi + + + +echo "Cloning CIRCT submodules" +( + cd $RDIR/tools + git submodule update --init circt + cd circt + git submodule init + git submodule update +) + +echo "Building CIRCT's LLVM/MLIR" +( + cd $RDIR/tools/circt + rm -rf llvm/build + mkdir llvm/build + cd llvm/build + cmake -G Ninja ../llvm \ + -DLLVM_ENABLE_PROJECTS="mlir" \ + -DLLVM_TARGETS_TO_BUILD="host" \ + -DLLVM_ENABLE_ASSERTIONS=ON \ + -DCMAKE_BUILD_TYPE=DEBUG \ + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON + ninja +) + +echo "Building CIRCT" +( + cd $RDIR/tools/circt + rm -rf build + mkdir build + cd build + cmake -G Ninja .. \ + -DMLIR_DIR=../llvm/build/lib/cmake/mlir \ + -DLLVM_DIR=../llvm/build/lib/cmake/llvm \ + -DLLVM_ENABLE_ASSERTIONS=ON \ + -DCMAKE_BUILD_TYPE=DEBUG \ + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ + -DCMAKE_INSTALL_PREFIX=$PREFIX + ninja +) + +echo "Installing CIRCT to $PREFIX" +( + cd $RDIR/tools/circt/build + ninja install +) + diff --git a/tools/circt b/tools/circt new file mode 160000 index 00000000..9e0c1696 --- /dev/null +++ b/tools/circt @@ -0,0 +1 @@ +Subproject commit 9e0c1696f3caef4059c65774ad6b8efee91d9d9e From 2935531d8b1b4ccd8a353c6d6dcfd64dbe7ed7fd Mon Sep 17 00:00:00 2001 From: Jerry Zhao Date: Tue, 27 Feb 2024 16:39:40 -0800 Subject: [PATCH 2/7] Add --build-circt flag to build-setup --- scripts/build-setup.sh | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/scripts/build-setup.sh b/scripts/build-setup.sh index d8a08c1c..786f49ac 100755 --- a/scripts/build-setup.sh +++ b/scripts/build-setup.sh @@ -39,6 +39,7 @@ usage() { echo " --verbose -v : Verbose printout" echo " --use-unpinned-deps -ud : Use unpinned conda environment" echo " --use-lean-conda : Install a leaner version of the repository (Smaller conda env, no FireSim, no FireMarshal)" + echo " --build-circt : Builds CIRCT from source, instead of downloading the precompiled binary" echo " --skip -s N : Skip step N in the list above. Use multiple times to skip multiple steps ('-s N -s M ...')." echo " --skip-conda : Skip Conda initialization (step 1)" @@ -60,6 +61,7 @@ VERBOSE_FLAG="" USE_UNPINNED_DEPS=false USE_LEAN_CONDA=false SKIP_LIST=() +BUILD_CIRCT=false # getopts does not support long options, and is inflexible while [ "$1" != "" ]; @@ -75,6 +77,8 @@ do --use-lean-conda) USE_LEAN_CONDA=true SKIP_LIST+=(4 6 7 8 9) ;; + --build-circt) + BUILD_CIRCT=true ;; -ud | --use-unpinned-deps ) USE_UNPINNED_DEPS=true ;; --skip | -s) @@ -306,13 +310,20 @@ if run_step "10"; then PREFIX=$RISCV fi - git submodule update --init $CYDIR/tools/install-circt && - $CYDIR/tools/install-circt/bin/download-release-or-nightly-circt.sh \ - -f circt-full-static-linux-x64.tar.gz \ - -i $PREFIX \ - -v version-file \ - -x $CYDIR/conda-reqs/circt.json \ - -g null + if [ "$BUILD_CIRCT" = true ] ; then + echo "Building CIRCT from source, and installing to $PREFIX" + $CYDIR/scripts/build-circt-from-source --prefix $PREFIX + else + echo "Downloading CIRCT from nightly build" + + git submodule update --init $CYDIR/tools/install-circt && + $CYDIR/tools/install-circt/bin/download-release-or-nightly-circt.sh \ + -f circt-full-static-linux-x64.tar.gz \ + -i $PREFIX \ + -v version-file \ + -x $CYDIR/conda-reqs/circt.json \ + -g null + fi exit_if_last_command_failed fi From e958f7716824858d9b9f9b48e052fccb9d64ca40 Mon Sep 17 00:00:00 2001 From: Jerry Zhao Date: Tue, 27 Feb 2024 16:39:56 -0800 Subject: [PATCH 3/7] Build CIRCT in release mode --- scripts/build-circt-from-source.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/scripts/build-circt-from-source.sh b/scripts/build-circt-from-source.sh index 55370536..f9bb727e 100755 --- a/scripts/build-circt-from-source.sh +++ b/scripts/build-circt-from-source.sh @@ -68,7 +68,7 @@ echo "Building CIRCT's LLVM/MLIR" -DLLVM_ENABLE_PROJECTS="mlir" \ -DLLVM_TARGETS_TO_BUILD="host" \ -DLLVM_ENABLE_ASSERTIONS=ON \ - -DCMAKE_BUILD_TYPE=DEBUG \ + -DCMAKE_BUILD_TYPE=RELEASE \ -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ninja ) @@ -83,8 +83,7 @@ echo "Building CIRCT" -DMLIR_DIR=../llvm/build/lib/cmake/mlir \ -DLLVM_DIR=../llvm/build/lib/cmake/llvm \ -DLLVM_ENABLE_ASSERTIONS=ON \ - -DCMAKE_BUILD_TYPE=DEBUG \ - -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ + -DCMAKE_BUILD_TYPE=RELEASE \ -DCMAKE_INSTALL_PREFIX=$PREFIX ninja ) From 793c56ef45c799c4129e409b5a5e9a10c6c87676 Mon Sep 17 00:00:00 2001 From: Jerry Zhao Date: Tue, 27 Feb 2024 16:40:42 -0800 Subject: [PATCH 4/7] Don't checkout CIRCT with init-submods.sh --- scripts/init-submodules-no-riscv-tools-nolog.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/init-submodules-no-riscv-tools-nolog.sh b/scripts/init-submodules-no-riscv-tools-nolog.sh index 1779b8d8..e46af0ca 100755 --- a/scripts/init-submodules-no-riscv-tools-nolog.sh +++ b/scripts/init-submodules-no-riscv-tools-nolog.sh @@ -82,6 +82,7 @@ cd "$RDIR" software/spec2017 \ tools/dsptools \ tools/rocket-dsp-utils \ + tools/circt \ vlsi/hammer-mentor-plugins do "$1" "${name%/}" From 3bb2101a25827bed5e3da14b7d3978cd7a40e425 Mon Sep 17 00:00:00 2001 From: Jerry Zhao Date: Tue, 27 Feb 2024 17:01:56 -0800 Subject: [PATCH 5/7] Always checkout CIRCT/LLVM shallow --- scripts/build-circt-from-source.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/scripts/build-circt-from-source.sh b/scripts/build-circt-from-source.sh index f9bb727e..56d7966b 100755 --- a/scripts/build-circt-from-source.sh +++ b/scripts/build-circt-from-source.sh @@ -49,13 +49,17 @@ fi -echo "Cloning CIRCT submodules" +echo "Cloning CIRCT" ( cd $RDIR/tools - git submodule update --init circt - cd circt + git submodule update --init --progress circt +) +echo "Cloning CIRCT/LLVM" +( + cd $RDIR/tools/circt git submodule init - git submodule update + git config submodule.llvm.shallow true + git submodule update --recommend-shallow --progress llvm ) echo "Building CIRCT's LLVM/MLIR" From b8273d874edaae36a5c1c1d69423d0681489adfb Mon Sep 17 00:00:00 2001 From: Jerry Zhao Date: Tue, 27 Feb 2024 17:22:36 -0800 Subject: [PATCH 6/7] Set CIRCT/llvm branch --- scripts/build-circt-from-source.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/build-circt-from-source.sh b/scripts/build-circt-from-source.sh index 56d7966b..5477534d 100755 --- a/scripts/build-circt-from-source.sh +++ b/scripts/build-circt-from-source.sh @@ -58,7 +58,9 @@ echo "Cloning CIRCT/LLVM" ( cd $RDIR/tools/circt git submodule init + # The settings in circt/.gitmodules don't "stick", so force-set them here git config submodule.llvm.shallow true + git config submodule.llvm.branch main git submodule update --recommend-shallow --progress llvm ) From b23d6edaf6ecd7b62d1f2badbf8ef37640881949 Mon Sep 17 00:00:00 2001 From: Jerry Zhao Date: Wed, 28 Feb 2024 09:33:55 -0800 Subject: [PATCH 7/7] Fix build-setup.sh typo Co-authored-by: Abraham Gonzalez --- scripts/build-setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build-setup.sh b/scripts/build-setup.sh index 786f49ac..56f56506 100755 --- a/scripts/build-setup.sh +++ b/scripts/build-setup.sh @@ -312,7 +312,7 @@ if run_step "10"; then if [ "$BUILD_CIRCT" = true ] ; then echo "Building CIRCT from source, and installing to $PREFIX" - $CYDIR/scripts/build-circt-from-source --prefix $PREFIX + $CYDIR/scripts/build-circt-from-source.sh --prefix $PREFIX else echo "Downloading CIRCT from nightly build"