Skip to content

Commit

Permalink
[ImportVerilog] Update to Slang 4
Browse files Browse the repository at this point in the history
Bump the Slang dependency to version 4. This version supports builds
with exceptions and RTTI fully disabled, which allows us to get rid of
the ugly glue code that tried to bridge the gap between the RTTI/EH
world of Slang and the non-RTTI/non-EH world of LLVM.
  • Loading branch information
fabianschuiki committed Jan 31, 2024
1 parent fb58da4 commit c3d2a14
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 17 deletions.
28 changes: 27 additions & 1 deletion .github/workflows/unifiedBuildTestAndInstall.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,33 @@ jobs:
${{ steps.setup-windows.outputs.setup }}
mkdir build
cd build
cmake -G Ninja -S "$(pwd)/../llvm/llvm" $EXTRA_CMAKE_ARGS -DCMAKE_BUILD_TYPE=${{ inputs.cmake_build_type }} -DBUILD_SHARED_LIBS=${{ inputs.build_shared_libs }} -DLLVM_BUILD_TOOLS=ON -DLLVM_BUILD_EXAMPLES=OFF -DLLVM_ENABLE_ASSERTIONS=${{ inputs.llvm_enable_assertions }} -DLLVM_ENABLE_PROJECTS=mlir -DLLVM_EXTERNAL_PROJECTS=circt -DLLVM_EXTERNAL_CIRCT_SOURCE_DIR=".." -DLLVM_STATIC_LINK_CXX_STDLIB=ON -DLLVM_ENABLE_TERMINFO=OFF -DLLVM_PARALLEL_LINK_JOBS=1 -DLLVM_TARGETS_TO_BUILD="host" -DLLVM_FORCE_ENABLE_STATS=${{ inputs.llvm_force_enable_stats }} -DLLVM_ENABLE_ZSTD=OFF -DVERILATOR_DISABLE=ON -DLLVM_PARALLEL_LINK_JOBS=1 -DCIRCT_RELEASE_TAG_ENABLED=ON -DCIRCT_RELEASE_TAG=firtool -DCMAKE_EXPORT_COMPILE_COMMANDS=OFF -DCMAKE_C_COMPILER=${{ inputs.cmake_c_compiler }} -DCMAKE_CXX_COMPILER=${{ inputs.cmake_cxx_compiler }} ${{ steps.configure-sccache.outputs.enable_sccache }} -DCMAKE_INSTALL_PREFIX="$(pwd)/../install" -DLLVM_INSTALL_UTILS=ON
cmake -G Ninja -S "$(pwd)/../llvm/llvm" \
$EXTRA_CMAKE_ARGS \
-DCMAKE_BUILD_TYPE=${{ inputs.cmake_build_type }} \
-DBUILD_SHARED_LIBS=${{ inputs.build_shared_libs }} \
-DLLVM_BUILD_TOOLS=ON \
-DLLVM_BUILD_EXAMPLES=OFF \
-DLLVM_ENABLE_ASSERTIONS=${{ inputs.llvm_enable_assertions }} \
-DLLVM_ENABLE_PROJECTS=mlir \
-DLLVM_EXTERNAL_PROJECTS=circt \
-DLLVM_EXTERNAL_CIRCT_SOURCE_DIR=".." \
-DLLVM_STATIC_LINK_CXX_STDLIB=ON \
-DLLVM_ENABLE_TERMINFO=OFF \
-DLLVM_PARALLEL_LINK_JOBS=1 \
-DLLVM_TARGETS_TO_BUILD="host" \
-DLLVM_FORCE_ENABLE_STATS=${{ inputs.llvm_force_enable_stats }} \
-DLLVM_ENABLE_ZSTD=OFF \
-DVERILATOR_DISABLE=ON \
-DLLVM_PARALLEL_LINK_JOBS=1 \
-DCIRCT_RELEASE_TAG_ENABLED=ON \
-DCIRCT_RELEASE_TAG=firtool \
-DCMAKE_EXPORT_COMPILE_COMMANDS=OFF \
-DCMAKE_C_COMPILER=${{ inputs.cmake_c_compiler }} \
-DCMAKE_CXX_COMPILER=${{ inputs.cmake_cxx_compiler }} \
${{ steps.configure-sccache.outputs.enable_sccache }} \
-DCMAKE_INSTALL_PREFIX="$(pwd)/../install" \
-DLLVM_INSTALL_UTILS=ON \
-DCIRCT_SLANG_FRONTEND_ENABLED=ON
# Optionally test
- name: Test CIRCT
if: inputs.runTests
Expand Down
16 changes: 8 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -546,8 +546,8 @@ if(CIRCT_SLANG_FRONTEND_ENABLED)
include(FetchContent)
FetchContent_Declare(
slang
URL https://github.com/MikePopoloski/slang/archive/refs/tags/v3.0.tar.gz
URL_HASH SHA256=02d184133525f6330a32bef492761b8ff52d0a33caed08eb51733f63cddb08e3
URL https://github.com/MikePopoloski/slang/archive/refs/tags/v4.0.tar.gz
URL_HASH SHA256=4f58535220e9d2bed9942d60fa2330d9e4efb14b5c02bedaabb8d0cc60d39f2f
)
set(FETCHCONTENT_TRY_FIND_PACKAGE_MODE "NEVER")

Expand All @@ -558,11 +558,12 @@ if(CIRCT_SLANG_FRONTEND_ENABLED)
set(ORIGINAL_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})

if (MSVC)
set(CMAKE_CXX_FLAGS "/EHsc")
# MSVC seems to build without exception support by default anyway.
else ()
set(CMAKE_CXX_FLAGS "")
set(CMAKE_CXX_FLAGS "-fno-exceptions -fno-rtti")
endif ()
set(BUILD_SHARED_LIBS OFF)
set(SLANG_USE_MIMALLOC OFF)
FetchContent_MakeAvailable(slang)

set(CMAKE_CXX_FLAGS ${ORIGINAL_CMAKE_CXX_FLAGS})
Expand All @@ -571,7 +572,6 @@ if(CIRCT_SLANG_FRONTEND_ENABLED)
if(BUILD_SHARED_LIBS)
set_target_properties(slang_slang PROPERTIES POSITION_INDEPENDENT_CODE ON)
set_target_properties(fmt PROPERTIES POSITION_INDEPENDENT_CODE ON)
set_target_properties(unordered_dense PROPERTIES POSITION_INDEPENDENT_CODE ON)
endif()

# The following feels *very* hacky, but CMake complains about the
Expand All @@ -580,10 +580,10 @@ if(CIRCT_SLANG_FRONTEND_ENABLED)
# statically link slang into the CIRCTImportVerilog library, but seems to be
# harder than it ought to be.
set_property(
GLOBAL APPEND PROPERTY CIRCT_EXPORTS slang_slang unordered_dense fmt)
install(TARGETS slang_slang unordered_dense fmt EXPORT CIRCTTargets)
GLOBAL APPEND PROPERTY CIRCT_EXPORTS slang_slang fmt)
install(TARGETS slang_slang fmt EXPORT CIRCTTargets)
else()
find_package(slang 3.0 REQUIRED)
find_package(slang 4.0 REQUIRED)
endif()
endif()

Expand Down
7 changes: 0 additions & 7 deletions lib/Conversion/ImportVerilog/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# slang uses exceptions
set(LLVM_REQUIRES_EH ON)
set(LLVM_REQUIRES_RTTI ON)

# For ABI compatibility, define the DEBUG macro in debug builds. Slang sets this
# internally. If we don't set this here as well, header-defined things like the
# destructor of `Driver`, which is generated in ImportVerilog's compilation
Expand All @@ -15,9 +11,6 @@ add_compile_definitions($<$<CONFIG:Debug>:DEBUG>)
if (MSVC)
# No idea what to put here
else ()
# slang uses exceptions; we intercept these in ImportVerilog
add_compile_options(-fexceptions)
add_compile_options(-frtti)
# slang has some classes with virtual funcs but non-virtual destructor.
add_compile_options(-Wno-non-virtual-dtor)
# some other warnings we've seen
Expand Down
2 changes: 1 addition & 1 deletion test/circt-verilog/commandline.sv
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
// REQUIRES: slang

// CHECK-HELP: OVERVIEW: Verilog and SystemVerilog frontend
// CHECK-VERSION: slang version 3.
// CHECK-VERSION: slang version 4.

0 comments on commit c3d2a14

Please sign in to comment.