Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for building CIRCT from source #1806

Merged
merged 7 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
102 changes: 102 additions & 0 deletions scripts/build-circt-from-source.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/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"
(
cd $RDIR/tools
git submodule update --init --progress circt
)
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
)

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=RELEASE \
-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=RELEASE \
-DCMAKE_INSTALL_PREFIX=$PREFIX
ninja
)

echo "Installing CIRCT to $PREFIX"
(
cd $RDIR/tools/circt/build
ninja install
)

25 changes: 18 additions & 7 deletions scripts/build-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand All @@ -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" != "" ];
Expand All @@ -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)
Expand Down Expand Up @@ -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.sh --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

Expand Down
1 change: 1 addition & 0 deletions scripts/init-submodules-no-riscv-tools-nolog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ cd "$RDIR"
software/spec2017 \
tools/dsptools \
tools/rocket-dsp-utils \
tools/circt \
vlsi/hammer-mentor-plugins
do
"$1" "${name%/}"
Expand Down
1 change: 1 addition & 0 deletions tools/circt
Submodule circt added at 9e0c16
Loading