[VENTUS][RISCV][feat] Building libclc library into object file other than archive file

In our previous design, the libclc library is built into static library which make the generated
ELF file having a large size, now we change compiler and linker option to make generated ELF file size much smaller, detail information can be seen in this pull request https://github.com/THU-DSP-LAB/pocl/pull/11
This commit is contained in:
zhoujing 2023-07-17 21:39:02 +08:00
parent cb6fe8a2a1
commit b8223e72bd
5 changed files with 38 additions and 34 deletions

View File

@ -176,10 +176,10 @@ build_libclc() {
-DCMAKE_LLAsm_COMPILER_WORKS=ON \
-DCMAKE_CLC_COMPILER_WORKS=ON \
-DCMAKE_CLC_COMPILER_FORCED=ON \
-DCMAKE_LLAsm_FLAGS="-target riscv32 -mcpu=ventus-gpgpu -cl-std=CL2.0 -Dcl_khr_fp64" \
-DCMAKE_CLC_FLAGS="-target riscv32 -mcpu=ventus-gpgpu -cl-std=CL2.0 -I${DIR}/libclc/generic/include -Dcl_khr_fp64" \
-DCMAKE_LLAsm_FLAGS="-target riscv32 -mcpu=ventus-gpgpu -cl-std=CL2.0 -Dcl_khr_fp64 -ffunction-sections -fdata-sections" \
-DCMAKE_CLC_FLAGS="-target riscv32 -mcpu=ventus-gpgpu -cl-std=CL2.0 -I${DIR}/libclc/generic/include -Dcl_khr_fp64 -ffunction-sections -fdata-sections"\
-DLIBCLC_TARGETS_TO_BUILD="riscv32--" \
-DCMAKE_CXX_FLAGS="-I ${DIR}/llvm/include/ -std=c++17 -Dcl_khr_fp64" \
-DCMAKE_CXX_FLAGS="-I ${DIR}/llvm/include/ -std=c++17 -Dcl_khr_fp64 -ffunction-sections -fdata-sections" \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_INSTALL_PREFIX=${VENTUS_INSTALL_PREFIX} \
@ -187,8 +187,8 @@ build_libclc() {
ninja
ninja install
# TODO: There are bugs in linking all libclc object files now
echo "************* Building riscv32 libclc library archive file ************"
bash ${DIR}/libclc/build_riscv32_archive.sh ${VENTUS_INSTALL_PREFIX}/bin ${LIBCLC_BUILD_DIR}/riscv32--.bc ${LIBCLC_BUILD_DIR} || true
echo "************* Building riscv32 libclc object file ************"
bash ${DIR}/libclc/build_riscv32clc.sh ${DIR}/libclc ${LIBCLC_BUILD_DIR} ${VENTUS_INSTALL_PREFIX} || true
DstDir=${VENTUS_INSTALL_PREFIX}/share/pocl
if [ ! -d "${DstDir}" ]; then

View File

@ -49,7 +49,8 @@ void RISCVTargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) {
llvm::Triple Triple = getTriple();
bool isRV32 = Triple.isRISCV32();
// Only OpenCL language needs special address mapping
if(Opts.OpenCL) {
// FIXME: when meeting C code here is not valid !!
if(Opts.OpenCL || Opts.getOpenCLVersionString().size()) {
UseAddrSpaceMapMangling = true;
AddrSpaceMap = &VentusAddrSpaceMap;
if(isRV32)

View File

@ -1,26 +0,0 @@
#!/usr/bin/bash
BIN_DIR=$1
BITCODE_FILE=$2
BUILD_DIR=$3
ARCHIVE_FILE_PREFIX=${BUILD_DIR}/riscv32--
COMPILER_FLAGS="-target riscv32 -mcpu=ventus-gpgpu"
if [ ! -d "${BIN_DIR}" ]; then
echo "ERROR: LLVM binary directory does not exist!"
exit 1
fi
if [ ! -f "${BITCODE_FILE}" ]; then
echo "ERROR: Not a file: ${BITCODE_FILE}"
exit 1
fi
LLVM_DIS=${BIN_DIR}/llvm-dis
LLVM_LLC=${BIN_DIR}/llc
LLVM_CLANG=${BIN_DIR}/clang
LLVM_AR=${BIN_DIR}/llvm-ar
${LLVM_DIS} ${BITCODE_FILE} -o ${ARCHIVE_FILE_PREFIX}.ll
${LLVM_LLC} --filetype=obj ${ARCHIVE_FILE_PREFIX}.ll -o ${ARCHIVE_FILE_PREFIX}.o
${LLVM_AR} rcs ${ARCHIVE_FILE_PREFIX}.a ${ARCHIVE_FILE_PREFIX}.o

28
libclc/build_riscv32clc.sh Executable file
View File

@ -0,0 +1,28 @@
#!/usr/bin/bash
LIBCLC_DIR=$1
LIBCLC_BUILD_DIR=$2
BINARY_DIR=$3
# Collect all the object files in build directory
OBJECT_FILE_LIST=""
for item in $(find ${LIBCLC_BUILD_DIR} -name "*.bc.o")
do
OBJECT_FILE_LIST="${OBJECT_FILE_LIST} ${item}"
done
# Compile other left IR files
for item in $(ls ${LIBCLC_DIR}/generic/lib | grep ll)
do
${BINARY_DIR}/bin/clang -target riscv32 -mcpu=ventus-gpgpu \
-cl-std=CL2.0 \
-ffunction-sections -fdata-sections \
-c ${LIBCLC_DIR}/generic/lib/${item} \
-o ${LIBCLC_BUILD_DIR}/${item}.o
OBJECT_FILE_LIST="${OBJECT_FILE_LIST} ${LIBCLC_BUILD_DIR}/${item}.o"
done
${BINARY_DIR}/bin/ld.lld --relocatable ${OBJECT_FILE_LIST} \
--allow-multiple-definition \
-o ${LIBCLC_BUILD_DIR}/riscv32clc.o
cp ${LIBCLC_BUILD_DIR}/riscv32clc.o ${BINARY_DIR}/lib

View File

@ -1,7 +1,8 @@
if(NOT CMAKE_CLC_COMPILE_OBJECT)
set(CMAKE_CLC_COMPILE_OBJECT
"<CMAKE_CLC_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE> -emit-llvm")
"<CMAKE_CLC_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE> -emit-llvm"
"<CMAKE_CLC_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT>.o -c <SOURCE>")
if( CMAKE_BUILD_TYPE STREQUAL "Debug" )
# This is only for depveloper's option to build debug
list(APPEND CMAKE_CLC_COMPILE_OBJECT
@ -14,7 +15,7 @@ endif()
if(NOT CMAKE_CLC_CREATE_STATIC_LIBRARY)
set(CMAKE_CLC_CREATE_STATIC_LIBRARY
"<CMAKE_CLC_ARCHIVE> -o <TARGET> <OBJECTS>")
"<CMAKE_CLC_ARCHIVE> -o <TARGET> <OBJECTS>")
endif()
set(CMAKE_INCLUDE_FLAG_CLC "-I")