Commit 94c3bffd by Martin

Release 2022.1

0 parents
LLVM framework for IP Core Extensions - RISC-V
==============================================
This project contains script and patches for downloading and building modified LLVM framework.
The LLVM framework is modified to support operations with added FP data types (packed half and packed single FP types). It also supports SWAR data types and operations.
LLVM version
------------
The script builds LLVM version 13.0.0 (git commit 3186b18b998124a6b577f8274a10b7ee8b634c18).
Tools/libraries necessary for building LLVM
-------------------------------------------
* **git** - is necessary for downloading and patching of the original LLVM (the GIT has to have configured user/email)
A user and an email can be configured in GIT with the following commands
$ git config --global user.name "Your Name"
$ git config --global user.email "youremail@yourdomain.com"
* **patch** for applying patches on the original LLVM
* **make**,**gcc**,**binutils**,**libc** - standard make and GCC compiler for compilation
Building
--------
The compiler for RISC-V is built simply with command
./run_riscv.sh all
The script with option 'all' downloads, patches and builts the compiler for RISC-V in subdirectory 'install-riscv'.
Updating
--------
If the repository is already cloned and built and the patches have been changed, the following steps can be performed to build LLVM with changed patches.
cd <repository>
git pull
./run_riscv packclean
./run_riscv patch
./run_riscv build
Using for RISC-V
----------------
The compiler is configured to use binutils tools with prefix 'riscv64-daiteq-elf-'. The compiler can used if the output directory 'install-riscv/bin' is added to environment variable PATH.
$ export PATH=<path-to-llvm>/install/bin:${PATH}
llvm/clang - added and affected options for RISC-V target
=========================================================
- added architecture extensions (for using with 'march' option)
- zfh - enable half FP
- x-fph - enable packed half FP
- x-fps - enable packed single FP
- x-swar - enable support for SWAR data types and operations
Example: -march=rv64imafdzfh_x-fph_x-fps_x-swar
- msoft-float - set all FP operations in all precisions as soft-float
- msoft_fp_half - set all half FP operations as soft-float
- msoft_fp_single - set all single FP operations as soft-float
- msoft_fp_double - set all double FP operations as soft-float
- mhard_fp_half - set all half FP operations as hard-float
- mhard_fp_single - set all single FP operations as hard-float
- mhard_fp_double - set all double FP operations as hard-float
- msoft_fops_half - set selected half FP operations as soft-float (selected with a set of characters)
- msoft_fops_single - set selected single FP operations as soft-float (selected with a set of characters)
- msoft_fops_double - set selected double FP operations as soft-float (selected with a set of characters)
- mhard_fops_half - set selected half FP operations as soft-float (selected with a set of characters)
- mhard_fops_single - set selected single FP operations as soft-float (selected with a set of characters)
- mhard_fops_double - set selected double FP operations as soft-float (selected with a set of characters)
- menable_packedhalf - for RISC-V is not necessary - packed half FP ops are enabled with extension 'x-fph'
- menable_packedsingle - for RISC-V is not necessary - packed single FP ops are enabled with extension 'x-fps'
- daiteq_fpu_type - select FP precisions which have all operations as hard-float
- msoft-half - set which half FP operations are in soft-float with a numeric code
- msoft-single - set which single FP operations are in soft-float with a numeric code
- msoft-double - set which double FP operations are in soft-float with a numeric code
- daiteq_swar_enable - for RISC-V is not necessary - SWAR extension is enabled with architecture extension 'x-swar'
- daiteq_swar_type - select SWAR type for automatically added SWAR operations
- print_sf_uid - print unique identification string for architecture extensions and selection of soft-float operations
This diff could not be displayed because it is too large.
#!/bin/bash
LLVM_NAME=llvm
LLVM_VERSION=13.0.0
LLVM_SERVER="https://github.com/llvm/llvm-project.git"
#LLVM_GIT_BRANCH="release/10.x"
#LLVM_GIT_COMMIT="ef32c611aa214dea855364efd7ba451ec5ec3f74"
#LLVM_GIT_COMMIT="3186b18b998124a6b577f8274a10b7ee8b634c18"
# release/13.x (2021/09/06)
LLVM_GIT_BRANCH="release/13.x"
LLVM_GIT_COMMIT="181739213aa00de40a5bc6fbb1c578ce25b78d39"
DAITEQ_BRANCH="daiteq"
TGT_TRIPLE=riscv64-daiteq-none-elf
HOST_TRIPLE=x86_64-linux-gnu
CURDIR="$(pwd)"
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# number of cores used for make
MAKE_CORES=$(nproc --all)
DIR_SRCS=${CURDIR}/source
DIR_BLD=${CURDIR}/build-riscv
DIR_INST=${CURDIR}/install-riscv
DIR_PTCH=${SCRIPTDIR}/patches
DIR_DEBUG=${CURDIR}/debug-riscv
GENDIRS="${DIR_SRCS} ${DIR_BLD} ${DIR_INST}"
#DN_BUUNP=${DIR_UPCK}/${BU_NAME}-${BU_VERSION}
CCMAKE_ARGS="-D CMAKE_BUILD_TYPE=Release \
-D BUILD_SHARED_LIBS=ON \
-D LLVM_ENABLE_Z3_SOLVER=OFF \
-D CMAKE_INSTALL_PREFIX=${DIR_INST} \
-D LLVM_DEFAULT_TARGET_TRIPLE=${TGT_TRIPLE} \
-D LLVM_EXTERNAL_CLANG_SOURCE_DIR=${DIR_SRCS}/clang \
-D LLVM_EXTERNAL_CLANG_TOOLS_EXTRA_SOURCE_DIR=${DIR_SRCS}/clang-tools-extra \
-D LLVM_EXTERNAL_COMPILER_RT_SOURCE_DIR=${DIR_SRCS}/compiler-rt \
-D LLVM_INCLUDE_DOCS=OFF \
-D LLVM_ENABLE_OCAMLDOC=OFF \
-D LLVM_INSTALL_BINUTILS_SYMLINKS=ON \
-D LLVM_TARGETS_TO_BUILD=RISCV \
-D LLVM_TARGET_ARCH=riscv64 \
-D LLVM_TOOL_CLANG_BUILD=ON \
-D LLVM_TOOL_CLANG_TOOLS_EXTRA_BUILD=ON \
-D CLANG_INCLUDE_TESTS=ON \
-D CLANG_VENDOR=daiteq-esa \
-D LLVM_TOOL_COMPILER_RT_BUILD=OFF"
# -D COMPILER_RT_USE_BUILTINS_LIBRARY=ON
CCMAKE_DEBUG_ARGS="-D CMAKE_BUILD_TYPE:STRING=Debug \
-D LLVM_ENABLE_ASSERTIONS:BOOL=ON \
-D BUILD_SHARED_LIBS=ON \
-D LLVM_ENABLE_Z3_SOLVER=OFF \
-D CMAKE_INSTALL_PREFIX=${DIR_INST} \
-D LLVM_DEFAULT_TARGET_TRIPLE=${TGT_TRIPLE} \
-D LLVM_EXTERNAL_CLANG_SOURCE_DIR=${DIR_SRCS}/clang \
-D LLVM_EXTERNAL_CLANG_TOOLS_EXTRA_SOURCE_DIR=${DIR_SRCS}/clang-tools-extra \
-D LLVM_EXTERNAL_COMPILER_RT_SOURCE_DIR=${DIR_SRCS}/compiler-rt \
-D LLVM_INCLUDE_DOCS=OFF \
-D LLVM_ENABLE_OCAMLDOC=OFF \
-D LLVM_INSTALL_BINUTILS_SYMLINKS=ON \
-D LLVM_TARGETS_TO_BUILD=RISCV \
-D LLVM_TARGET_ARCH=riscv64 \
-D LLVM_TOOL_CLANG_BUILD=ON \
-D LLVM_TOOL_CLANG_TOOLS_EXTRA_BUILD=ON \
-D CLANG_INCLUDE_TESTS=ON \
-D CLANG_VENDOR=daiteq-esa \
-D LLVM_TOOL_COMPILER_RT_BUILD=OFF"
prepare_dirs() {
for d in ${GENDIRS}
do
echo "Create directory ${d}"
mkdir -p ${d}
done
}
download_source() {
mkdir -p ${DIR_SRCS}
if [ "$(ls -A ${DIR_SRCS})" ]
then
echo "Repository is already cloned ... check consistency"
else
git clone --progress -n --branch ${LLVM_GIT_BRANCH} ${LLVM_SERVER} ${DIR_SRCS}
fi
cd ${DIR_SRCS}
# is there already working branch
if [ $(git branch --list ${DAITEQ_BRANCH}) ]
then
# already exists
git checkout ${DAITEQ_BRANCH}
else
# no work branch
git reset --hard ${LLVM_GIT_COMMIT}
git branch ${DAITEQ_BRANCH}
git checkout ${DAITEQ_BRANCH}
fi
cd ${CURDIR}
}
apply_patches() {
if [ ! -e ${DIR_PTCH} ]
then
echo "There is not a directory with patches"
exit 1
fi
cd ${DIR_SRCS}
# change branch to ours
git checkout ${DAITEQ_BRANCH}
# reset to the source LLVM commit
git reset --hard ${LLVM_GIT_COMMIT}
# check applying patches
for p in `ls ${DIR_PTCH}/*.txt | sort -V`
do
echo "Use patch ${p}"
git apply --check --whitespace=fix ${p}
echo vysledek = $?
if [[ $? != 0 ]]; then
echo " Patch cannot be applied."
cd ${CURDIR}
break
fi
git am --whitespace=fix ${p}
done
cd ${CURDIR}
}
do_configure() {
if [ ! -e ${DIR_SRCS} ]
then
echo "There is no unpacked files with source codes"
exit 1
fi
mkdir -p ${DIR_BLD}
cd ${DIR_BLD}
CONF=1
if [ -f CMakeCache.txt ]
then
echo "Compilation is already configured - try it again."
#CONF=0
fi
if [ ${CONF} -eq 1 ]
then
cmake ${CCMAKE_ARGS} ${DIR_SRCS}/llvm
if [ $? -ne 0 ]
then
echo "E: configure failed"
exit 1
fi
fi
}
build_source() {
mkdir -p ${DIR_BLD}
cd ${DIR_BLD}
if [ ! -f Makefile ]
then
echo "Compilation is not configured - run configuration."
do_configure
fi
make -j ${MAKE_CORES}
if [ $? -ne 0 ]
then
echo "E: make failed"
exit 1
fi
cd ${CURDIR}
}
build_debug() {
if [ ! -e ${DIR_SRCS} ]
then
echo "There is no unpacked files with source codes"
exit 1
fi
mkdir -p ${DIR_DEBUG}
cd ${DIR_DEBUG}
if [ -f CMakeCache.txt ]
then
echo "Compilation is already configured - try it again."
#CONF=0
else
cmake ${CCMAKE_DEBUG_ARGS} ${DIR_SRCS}/llvm
if [ $? -ne 0 ]
then
echo "E: configure failed"
exit 1
fi
fi
make -j ${MAKE_CORES}
if [ $? -ne 0 ]
then
echo "E: make debug failed"
exit 1
fi
cd ${CURDIR}
}
install_pkg() {
mkdir -p ${DIR_INST}
cd ${DIR_BLD}
make install
cd ${CURDIR}
}
clean_build() {
echo "Removing build and install directories."
rm -rf ${DIR_BLD} ${DIR_INST}
}
clean_unpacked() {
echo "Removing patches from the repository."
cd ${DIR_SRCS}
# change branch to ours
git checkout ${DAITEQ_BRANCH}
# reset to the source LLVM commit
git reset --hard ${LLVM_GIT_COMMIT}
# check applying patches
cd ${CURDIR}
}
distclean_all() {
echo "Removing all download and generated files and directories."
rm -rf ${GENDIRS}
}
# ##############################################################################
print_help() {
echo "The script needs one argument - required operation:"
echo " all - do all steps (get,patch,config,build,install)"
echo " get - download source package if it doesn't exist"
echo " patch - patch original package"
echo " config - perform configuration in build directory (cmake)"
echo " build - build LLVM package (make)"
echo " install - install LLVM to the output directory"
echo " clean - remove generated files (build and install dirs.)"
echo " packclean - remove unpacked files (unpack dir.)"
echo " distclean - remove all generated files and directories"
echo " debug - build debug version of LLVM package"
}
# ##############################################################################
# main ...
echo "Script for preparing patched LLVM for RISC-V IP core extensions."
if [ "$#" -ne 1 ]
then
print_help
exit 0
fi
case $1 in
"all" )
#echo "do all"
download_source
apply_patches
do_configure
build_source
install_pkg
;;
"get" )
#echo "do clone LLVM"
download_source
;;
"patch" )
#echo "do patch"
apply_patches
;;
"config" )
#echo "do configure"
do_configure
;;
"build" )
#echo "do build"
build_source
;;
"install" )
#echo "do install"
install_pkg
;;
"clean" )
#echo "do clean"
clean_build
;;
"packclean" )
#echo "do packclean"
clean_unpacked
;;
"distclean" )
#echo "do distclean"
distclean_all
;;
"debug" )
#echo "do debug"
build_debug
;;
* )
echo "E: Unsupported operation"
print_help
exit 1
;;
esac
#!/bin/bash
LLVM_NAME=llvm
LLVM_VERSION=13.0.0
LLVM_SERVER="https://github.com/llvm/llvm-project.git"
#LLVM_GIT_BRANCH="release/10.x"
#LLVM_GIT_COMMIT="ef32c611aa214dea855364efd7ba451ec5ec3f74"
#LLVM_GIT_COMMIT="3186b18b998124a6b577f8274a10b7ee8b634c18"
# release/13.x (2021/09/06)
LLVM_GIT_BRANCH="release/13.x"
LLVM_GIT_COMMIT="181739213aa00de40a5bc6fbb1c578ce25b78d39"
DAITEQ_BRANCH="daiteq"
TGT_TRIPLE=sparc-daiteq-none-elf
HOST_TRIPLE=x86_64-linux-gnu
CURDIR="$(pwd)"
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# number of cores used for make
MAKE_CORES=$(nproc --all)
DIR_SRCS=${CURDIR}/source
DIR_BLD=${CURDIR}/build-sparc
DIR_INST=${CURDIR}/install-sparc
DIR_PTCH=${SCRIPTDIR}/patches
DIR_DEBUG=${CURDIR}/debug-sparc
GENDIRS="${DIR_SRCS} ${DIR_BLD} ${DIR_INST}"
#DN_BUUNP=${DIR_UPCK}/${BU_NAME}-${BU_VERSION}
CCMAKE_ARGS="-D CMAKE_BUILD_TYPE=Release \
-D BUILD_SHARED_LIBS=ON \
-D LLVM_ENABLE_Z3_SOLVER=OFF \
-D CMAKE_INSTALL_PREFIX=${DIR_INST} \
-D LLVM_DEFAULT_TARGET_TRIPLE=${TGT_TRIPLE} \
-D LLVM_EXTERNAL_CLANG_SOURCE_DIR=${DIR_SRCS}/clang \
-D LLVM_EXTERNAL_CLANG_TOOLS_EXTRA_SOURCE_DIR=${DIR_SRCS}/clang-tools-extra \
-D LLVM_EXTERNAL_COMPILER_RT_SOURCE_DIR=${DIR_SRCS}/compiler-rt \
-D LLVM_INCLUDE_DOCS=OFF \
-D LLVM_ENABLE_OCAMLDOC=OFF \
-D LLVM_INSTALL_BINUTILS_SYMLINKS=ON \
-D LLVM_TARGETS_TO_BUILD=Sparc \
-D LLVM_TARGET_ARCH=sparc \
-D LLVM_TOOL_CLANG_BUILD=ON \
-D LLVM_TOOL_CLANG_TOOLS_EXTRA_BUILD=ON \
-D CLANG_INCLUDE_TESTS=ON \
-D CLANG_VENDOR=daiteq-esa \
-D LLVM_TOOL_COMPILER_RT_BUILD=OFF"
# -D COMPILER_RT_USE_BUILTINS_LIBRARY=ON
CCMAKE_DEBUG_ARGS="-D CMAKE_BUILD_TYPE:STRING=Debug \
-D LLVM_ENABLE_ASSERTIONS:BOOL=ON \
-D BUILD_SHARED_LIBS=ON \
-D LLVM_ENABLE_Z3_SOLVER=OFF \
-D CMAKE_INSTALL_PREFIX=${DIR_INST} \
-D LLVM_DEFAULT_TARGET_TRIPLE=${TGT_TRIPLE} \
-D LLVM_EXTERNAL_CLANG_SOURCE_DIR=${DIR_SRCS}/clang \
-D LLVM_EXTERNAL_CLANG_TOOLS_EXTRA_SOURCE_DIR=${DIR_SRCS}/clang-tools-extra \
-D LLVM_EXTERNAL_COMPILER_RT_SOURCE_DIR=${DIR_SRCS}/compiler-rt \
-D LLVM_INCLUDE_DOCS=OFF \
-D LLVM_ENABLE_OCAMLDOC=OFF \
-D LLVM_INSTALL_BINUTILS_SYMLINKS=ON \
-D LLVM_TARGETS_TO_BUILD=Sparc \
-D LLVM_TARGET_ARCH=sparc \
-D LLVM_TOOL_CLANG_BUILD=ON \
-D LLVM_TOOL_CLANG_TOOLS_EXTRA_BUILD=ON \
-D CLANG_INCLUDE_TESTS=ON \
-D CLANG_VENDOR=daiteq-esa \
-D LLVM_TOOL_COMPILER_RT_BUILD=OFF"
prepare_dirs() {
for d in ${GENDIRS}
do
echo "Create directory ${d}"
mkdir -p ${d}
done
}
download_source() {
mkdir -p ${DIR_SRCS}
if [ "$(ls -A ${DIR_SRCS})" ]
then
echo "Repository is already cloned ... check consistency"
else
git clone --progress -n --branch ${LLVM_GIT_BRANCH} ${LLVM_SERVER} ${DIR_SRCS}
fi
cd ${DIR_SRCS}
# is there already working branch
if [ $(git branch --list ${DAITEQ_BRANCH}) ]
then
# already exists
git checkout ${DAITEQ_BRANCH}
else
# no work branch
git reset --hard ${LLVM_GIT_COMMIT}
git branch ${DAITEQ_BRANCH}
git checkout ${DAITEQ_BRANCH}
fi
cd ${CURDIR}
}
apply_patches() {
if [ ! -e ${DIR_PTCH} ]
then
echo "There is not a directory with patches"
exit 1
fi
cd ${DIR_SRCS}
# change branch to ours
git checkout ${DAITEQ_BRANCH}
# reset to the source LLVM commit
git reset --hard ${LLVM_GIT_COMMIT}
# check applying patches
for p in `ls ${DIR_PTCH}/*.txt | sort -V`
do
echo "Use patch ${p}"
git apply --check --whitespace=fix ${p}
echo vysledek = $?
if [[ $? != 0 ]]; then
echo " Patch cannot be applied."
cd ${CURDIR}
break
fi
git am --whitespace=fix ${p}
done
cd ${CURDIR}
}
do_configure() {
if [ ! -e ${DIR_SRCS} ]
then
echo "There is no unpacked files with source codes"
exit 1
fi
mkdir -p ${DIR_BLD}
cd ${DIR_BLD}
CONF=1
if [ -f CMakeCache.txt ]
then
echo "Compilation is already configured - try it again."
#CONF=0
fi
if [ ${CONF} -eq 1 ]
then
cmake ${CCMAKE_ARGS} ${DIR_SRCS}/llvm
if [ $? -ne 0 ]
then
echo "E: configure failed"
exit 1
fi
fi
}
build_source() {
mkdir -p ${DIR_BLD}
cd ${DIR_BLD}
if [ ! -f Makefile ]
then
echo "Compilation is not configured - run configuration."
do_configure
fi
make -j ${MAKE_CORES}
if [ $? -ne 0 ]
then
echo "E: make failed"
exit 1
fi
cd ${CURDIR}
}
build_debug() {
if [ ! -e ${DIR_SRCS} ]
then
echo "There is no unpacked files with source codes"
exit 1
fi
mkdir -p ${DIR_DEBUG}
cd ${DIR_DEBUG}
if [ -f CMakeCache.txt ]
then
echo "Compilation is already configured - try it again."
#CONF=0
else
cmake ${CCMAKE_DEBUG_ARGS} ${DIR_SRCS}/llvm
if [ $? -ne 0 ]
then
echo "E: configure failed"
exit 1
fi
fi
make -j ${MAKE_CORES}
if [ $? -ne 0 ]
then
echo "E: make debug failed"
exit 1
fi
cd ${CURDIR}
}
install_pkg() {
mkdir -p ${DIR_INST}
cd ${DIR_BLD}
make install
cd ${CURDIR}
}
clean_build() {
echo "Removing build and install directories."
rm -rf ${DIR_BLD} ${DIR_INST}
}
clean_unpacked() {
echo "Removing patches from the repository."
cd ${DIR_SRCS}
# change branch to ours
git checkout ${DAITEQ_BRANCH}
# reset to the source LLVM commit
git reset --hard ${LLVM_GIT_COMMIT}
# check applying patches
cd ${CURDIR}
}
distclean_all() {
echo "Removing all download and generated files and directories."
rm -rf ${GENDIRS}
}
# ##############################################################################
print_help() {
echo "The script needs one argument - required operation:"
echo " all - do all steps (get,patch,config,build,install)"
echo " get - download source package if it doesn't exist"
echo " patch - patch original package"
echo " config - perform configuration in build directory (cmake)"
echo " build - build LLVM package (make)"
echo " install - install LLVM to the output directory"
echo " clean - remove generated files (build and install dirs.)"
echo " packclean - remove unpacked files (unpack dir.)"
echo " distclean - remove all generated files and directories"
echo " debug - build debug version of LLVM package"
}
# ##############################################################################
# main ...
echo "Script for preparing patched LLVM for LEON IP core extensions."
if [ "$#" -ne 1 ]
then
print_help
exit 0
fi
case $1 in
"all" )
#echo "do all"
download_source
apply_patches
do_configure
build_source
install_pkg
;;
"get" )
#echo "do clone LLVM"
download_source
;;
"patch" )
#echo "do patch"
apply_patches
;;
"config" )
#echo "do configure"
do_configure
;;
"build" )
#echo "do build"
build_source
;;
"install" )
#echo "do install"
install_pkg
;;
"clean" )
#echo "do clean"
clean_build
;;
"packclean" )
#echo "do packclean"
clean_unpacked
;;
"distclean" )
#echo "do distclean"
distclean_all
;;
"debug" )
#echo "do debug"
build_debug
;;
* )
echo "E: Unsupported operation"
print_help
exit 1
;;
esac
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!