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

[ImportVerilog] Bump slang #7792

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
Draft
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
12 changes: 6 additions & 6 deletions .github/workflows/buildAndTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
name: Sanity Check
runs-on: ubuntu-latest
container:
image: ghcr.io/circt/images/circt-ci-build:20240213211952
image: ghcr.io/circt/images/circt-ci-build:20241113160334
steps:
# Clone the CIRCT repo and its submodules. Do shallow clone to save clone
# time.
Expand Down Expand Up @@ -134,7 +134,7 @@ jobs:
# John and re-run the job.
runs-on: ["self-hosted", "1ES.Pool=1ES-CIRCT-builds", "linux"]
container:
image: ghcr.io/circt/images/circt-ci-build:20240213211952
image: ghcr.io/circt/images/circt-ci-build:20241113160334
volumes:
- /mnt:/__w/circt
strategy:
Expand All @@ -143,13 +143,13 @@ jobs:
# Our PR builds are trying to test the two corners of the build matrix:
# clang + release + noassert + static
# gcc + debug + assert + shared
- cc: clang
cxx: clang++
- cc: clang-17
cxx: clang++-17
mode: Debug
assert: ON
shared: ON
- cc: gcc
cxx: g++
- cc: gcc-11
cxx: g++-11
mode: Release
assert: OFF
shared: OFF
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/nightlyIntegrationTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ jobs:
build-shared: [ON, OFF]
build-type: [Debug, Release]
compiler:
- cc: clang
cxx: clang++
- cc: gcc
cxx: g++
- cc: clang-17
cxx: clang++-17
- cc: gcc-11
cxx: g++-11
lit-flags: ['', '--vg']
exclude:
- build-type: Debug
Expand All @@ -48,7 +48,7 @@ jobs:
build-shared: ON
# TODO: This corner is failing and has been for some time. #5253.
- build-type: Release
compiler: {cc: gcc, cxx: g++}
compiler: {cc: gcc-11, cxx: g++-11}
lit-flags: --vg

steps:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/shortIntegrationTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ jobs:
build-shared: [ON]
build-type: [Release]
compiler:
- cc: clang
cxx: clang++
- cc: clang-17
cxx: clang++-17

steps:
# Clone the CIRCT repo and its submodules. Do shallow clone to save clone
Expand Down
24 changes: 17 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -554,14 +554,17 @@ llvm_canonicalize_cmake_booleans(CIRCT_SLANG_BUILD_FROM_SOURCE)
if(CIRCT_SLANG_FRONTEND_ENABLED)
message(STATUS "slang Verilog frontend is enabled")
if(CIRCT_SLANG_BUILD_FROM_SOURCE)
# slang requires C++20

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this actually needed? slang's CMakeLists already sets these.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get an error trying to build ImportVerilog due to public headers in slang requiring C++ 20 if I remove this, but perhaps there's a more principled way to solve this?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see, that makes sense. It's a little unfortunate that this is adding friction but I make extensive use of, e.g. std::span that would be hard to remove from the public headers. Hopefully LLVM / MLIR / CIRCT can upgrade to C++20 at some point across the board; it's coming up on 5 years old.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drive by comment: in general, it's OK to require c++20 (or other non-llvm-standard things like exceptions) if they're optional and can be disabled. Since slang is an optional dependency, it's OK to require c++20 when slang is being used. We just need to be sure to run a ci build with c++17 and no slang.

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Build slang as part of CIRCT (see https://sv-lang.com/building.html)
message(STATUS "Building slang from source")
include(FetchContent)
FetchContent_Declare(
slang
GIT_REPOSITORY https://github.com/MikePopoloski/slang.git
GIT_TAG v3.0
GIT_SHALLOW ON)
GIT_TAG bad0d6ba3dec20355b0156c535bbddf2f926ab37)
set(FETCHCONTENT_TRY_FIND_PACKAGE_MODE "NEVER")

# Force Slang to be built as a static library to avoid messing around with
Expand All @@ -576,6 +579,7 @@ if(CIRCT_SLANG_FRONTEND_ENABLED)
set(CMAKE_CXX_FLAGS "")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MSVC /EHsc is probably not needed now?

endif ()
set(BUILD_SHARED_LIBS OFF)
set(SLANG_USE_MIMALLOC OFF)
FetchContent_MakeAvailable(slang)

set(CMAKE_CXX_FLAGS ${ORIGINAL_CMAKE_CXX_FLAGS})
Expand All @@ -584,7 +588,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 @@ -593,17 +596,24 @@ if(CIRCT_SLANG_FRONTEND_ENABLED)
# statically link slang into the CIRCTImportVerilog library, but seems to be
# harder than it ought to be.
set_property(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it seems like all this install / export stuff shouldn't be needed but I'm not enough of a CMake expert to know offhand how to fix it.

GLOBAL APPEND PROPERTY CIRCT_EXPORTS slang_slang unordered_dense fmt)
GLOBAL APPEND PROPERTY CIRCT_EXPORTS slang_slang fmt)

# Disable the installation of headers coming from third-party libraries. We
# won't use those APIs directly. Just make them static libraries for the sake
# of running slang normally.
set_target_properties(fmt PROPERTIES PUBLIC_HEADER "")
set_target_properties(unordered_dense PROPERTIES PUBLIC_HEADER "")

install(TARGETS slang_slang unordered_dense fmt EXPORT CIRCTTargets)
install(TARGETS slang_slang fmt EXPORT CIRCTTargets)

# Match the behavior of slang_slang, which installs its own vendored
# boost_unordered if it does not a system-wide boost installation.
find_package(Boost 1.82.0 QUIET)
if(NOT Boost_FOUND)
set_property(GLOBAL APPEND PROPERTY CIRCT_EXPORTS boost_unordered)
install(TARGETS boost_unordered EXPORT CIRCTTargets)
endif()
else()
find_package(slang 3.0 REQUIRED)
find_package(slang 7.0 REQUIRED)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Ask slang to mint a release so that this version includes everything that we need, including MikePopoloski/slang#1164.

endif()
endif()

Expand Down
4 changes: 2 additions & 2 deletions include/circt/Support/FVInt.h
Original file line number Diff line number Diff line change
Expand Up @@ -646,8 +646,8 @@ inline FVInt operator-(uint64_t a, const FVInt &b) {

inline FVInt operator-(const APInt &a, const FVInt &b) { return FVInt(a) - b; }

inline bool operator==(uint64_t a, const FVInt &b) { return b == a; }
inline bool operator!=(uint64_t a, const FVInt &b) { return b != a; }
inline bool operator==(uint64_t a, const FVInt &b) { return b.operator==(a); }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this related to the slang version? Is it picking up some overzealous global operator in slang somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a consequence of building circt code with C++ 20 for the first time, where https://timsong-cpp.github.io/cppwp/n4868/over.match#oper-3.4.4 has come into play. If my analysis is correct, operator resolution of == in { return b == a; } where a: uint64_t and b: const FVInt &b resolved to inline bool operator==(uint64_t a, const FVInt &b) { return b == a; } , i.e. itself, leading to infinite recursion.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, just an artifact of C++20 and not anything slang is doing. Maybe you can just ifdef out these overloads when compiling in C++20 mode.

inline bool operator!=(uint64_t a, const FVInt &b) { return b.operator!=(a); }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any tips on how to best deal with https://timsong-cpp.github.io/cppwp/n4868/over.match#oper-3.4.4 in a codebase that still needs to support older standards?


inline raw_ostream &operator<<(raw_ostream &os, const FVInt &value) {
value.print(os);
Expand Down
17 changes: 8 additions & 9 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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This really shouldn't be necessary; ideally adding the slang lib as a target should bring along its public compile definitions. Is there something I should be fixing on the slang side to do away with this here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for taking a look here @MikePopoloski, it's much appreciated. I'm not good enough at CMake to answer all of your comments, but I'm hoping that somebody more qualified can chime in where needed.

Expand All @@ -15,15 +11,10 @@ add_compile_definitions($<$<CONFIG:Debug>:DEBUG>)
if (MSVC)
# No idea what to put here
else ()
# slang uses exceptions; we intercept these in ImportVerilog

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you not specify slang include directories as being -isystem so that you don't need these warning suppressions?

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
add_compile_options(-Wno-c++98-compat-extra-semi)
add_compile_options(-Wno-ctad-maybe-unsupported)
add_compile_options(-Wno-cast-qual)
# visitor switch statements cover all cases but have default
add_compile_options(-Wno-covered-switch-default)
endif ()
Expand All @@ -50,3 +41,11 @@ add_circt_translation_library(CIRCTImportVerilog
PRIVATE
slang_slang
)

# HACK: When `OBJECT` argument is passed to `llvm_add_library()`,
# `COMPILE_DEFINITIONS` are not correctly inherited. For that reason,
# we manually set it here.
if(TARGET obj.CIRCTImportVerilog)
get_target_property(compile_defs Boost::headers INTERFACE_COMPILE_DEFINITIONS)
target_compile_definitions(obj.CIRCTImportVerilog PRIVATE ${compile_defs})
endif()
7 changes: 5 additions & 2 deletions lib/Conversion/ImportVerilog/Expressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//

#include "ImportVerilogInternals.h"
#include "slang/ast/EvalContext.h"
#include "slang/ast/SystemSubroutine.h"
#include "slang/syntax/AllSyntax.h"

Expand Down Expand Up @@ -526,7 +527,7 @@ struct RvalueExprVisitor {
// The open range list on the right-hand side of the inside operator is a
// comma-separated list of expressions or ranges.
if (const auto *openRange =
listExpr->as_if<slang::ast::OpenRangeExpression>()) {
listExpr->as_if<slang::ast::ValueRangeExpression>()) {
// Handle ranges.
auto lowBound = context.convertToSimpleBitVector(
context.convertRvalueExpression(openRange->left()));
Expand Down Expand Up @@ -1022,7 +1023,9 @@ slang::ConstantValue
Context::evaluateConstant(const slang::ast::Expression &expr) {
using slang::ast::EvalFlags;
slang::ast::EvalContext evalContext(
compilation, EvalFlags::CacheResults | EvalFlags::SpecparamsAllowed);
slang::ast::ASTContext(compilation.getRoot(),
slang::ast::LookupLocation::max),
EvalFlags::CacheResults | EvalFlags::SpecparamsAllowed);
return expr.eval(evalContext);
}

Expand Down
8 changes: 4 additions & 4 deletions lib/Conversion/ImportVerilog/FormatStrings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
//===----------------------------------------------------------------------===//

#include "ImportVerilogInternals.h"
#include "slang/text/SFormat.h"
#include "slang/ast/SFormat.h"

using namespace mlir;
using namespace circt;
using namespace ImportVerilog;
using moore::IntAlign;
using moore::IntFormat;
using moore::IntPadding;
using slang::SFormat::FormatOptions;
using slang::ast::SFormat::FormatOptions;

namespace {
struct FormatStringParser {
Expand Down Expand Up @@ -87,7 +87,7 @@ struct FormatStringParser {
auto onError = [&](auto, auto, auto, auto) {
assert(false && "Slang should have already reported all errors");
};
slang::SFormat::parse(format, onText, onArg, onError);
slang::ast::SFormat::parse(format, onText, onArg, onError);
return failure(anyFailure);
}

Expand Down Expand Up @@ -191,7 +191,7 @@ struct FormatStringParser {
} // namespace

FailureOr<Value> Context::convertFormatString(
slang::span<const slang::ast::Expression *const> arguments, Location loc,
std::span<const slang::ast::Expression *const> arguments, Location loc,
IntFormat defaultFormat, bool appendNewline) {
FormatStringParser parser(*this, ArrayRef(arguments.data(), arguments.size()),
loc, defaultFormat);
Expand Down
Loading
Loading