From 8ec44a2a3435e542e62233ec05c501bf4ae7f469 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98ystein=20Hovind?= Date: Thu, 31 Oct 2024 19:05:35 +0100 Subject: [PATCH 01/17] [ImportVerilog] Bump slang --- CMakeLists.txt | 13 ++--- lib/Conversion/ImportVerilog/Expressions.cpp | 7 ++- .../ImportVerilog/FormatStrings.cpp | 8 ++-- .../ImportVerilog/ImportVerilog.cpp | 48 ++++++++++++------- .../ImportVerilog/ImportVerilogInternals.h | 2 +- lib/Conversion/ImportVerilog/Structure.cpp | 4 +- test/circt-verilog/commandline.sv | 2 +- test/circt-verilog/preprocess-errors.sv | 2 +- 8 files changed, 52 insertions(+), 34 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 059cb2337faa..f0ed08170ff6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -557,7 +557,7 @@ if(CIRCT_SLANG_FRONTEND_ENABLED) FetchContent_Declare( slang GIT_REPOSITORY https://github.com/MikePopoloski/slang.git - GIT_TAG v3.0 + GIT_TAG bad0d6ba3dec20355b0156c535bbddf2f926ab37 GIT_SHALLOW ON) set(FETCHCONTENT_TRY_FIND_PACKAGE_MODE "NEVER") @@ -573,15 +573,17 @@ if(CIRCT_SLANG_FRONTEND_ENABLED) set(CMAKE_CXX_FLAGS "") endif () set(BUILD_SHARED_LIBS OFF) + set(SLANG_USE_MIMALLOC OFF) FetchContent_MakeAvailable(slang) + set(CMAKE_CXX_STANDARD 20) + set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_FLAGS ${ORIGINAL_CMAKE_CXX_FLAGS}) set(BUILD_SHARED_LIBS ${ORIGINAL_BUILD_SHARED_LIBS}) 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 @@ -590,17 +592,16 @@ 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) + 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) else() - find_package(slang 3.0 REQUIRED) + find_package(slang 7.0 REQUIRED) endif() endif() diff --git a/lib/Conversion/ImportVerilog/Expressions.cpp b/lib/Conversion/ImportVerilog/Expressions.cpp index 6f0706ef155a..4bd4f4b14c32 100644 --- a/lib/Conversion/ImportVerilog/Expressions.cpp +++ b/lib/Conversion/ImportVerilog/Expressions.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "ImportVerilogInternals.h" +#include "slang/ast/EvalContext.h" #include "slang/ast/SystemSubroutine.h" #include "slang/syntax/AllSyntax.h" @@ -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()) { + listExpr->as_if()) { // Handle ranges. auto lowBound = context.convertToSimpleBitVector( context.convertRvalueExpression(openRange->left())); @@ -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); } diff --git a/lib/Conversion/ImportVerilog/FormatStrings.cpp b/lib/Conversion/ImportVerilog/FormatStrings.cpp index 7698ad142b71..b3b15daac18d 100644 --- a/lib/Conversion/ImportVerilog/FormatStrings.cpp +++ b/lib/Conversion/ImportVerilog/FormatStrings.cpp @@ -7,7 +7,7 @@ //===----------------------------------------------------------------------===// #include "ImportVerilogInternals.h" -#include "slang/text/SFormat.h" +#include "slang/ast/SFormat.h" using namespace mlir; using namespace circt; @@ -15,7 +15,7 @@ using namespace ImportVerilog; using moore::IntAlign; using moore::IntFormat; using moore::IntPadding; -using slang::SFormat::FormatOptions; +using slang::ast::SFormat::FormatOptions; namespace { struct FormatStringParser { @@ -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); } @@ -191,7 +191,7 @@ struct FormatStringParser { } // namespace FailureOr Context::convertFormatString( - slang::span arguments, Location loc, + std::span arguments, Location loc, IntFormat defaultFormat, bool appendNewline) { FormatStringParser parser(*this, ArrayRef(arguments.data(), arguments.size()), loc, defaultFormat); diff --git a/lib/Conversion/ImportVerilog/ImportVerilog.cpp b/lib/Conversion/ImportVerilog/ImportVerilog.cpp index 773893fa3c84..d3813d92e59c 100644 --- a/lib/Conversion/ImportVerilog/ImportVerilog.cpp +++ b/lib/Conversion/ImportVerilog/ImportVerilog.cpp @@ -23,7 +23,7 @@ #include "slang/driver/Driver.h" #include "slang/parsing/Preprocessor.h" #include "slang/syntax/SyntaxPrinter.h" -#include "slang/util/Version.h" +#include "slang/util/VersionInfo.h" using namespace mlir; using namespace circt; @@ -202,15 +202,29 @@ LogicalResult ImportDriver::prepareDriver(SourceMgr &sourceMgr) { const llvm::MemoryBuffer *mlirBuffer = sourceMgr.getMemoryBuffer(i + 1); auto slangBuffer = driver.sourceManager.assignText( mlirBuffer->getBufferIdentifier(), mlirBuffer->getBuffer()); - driver.buffers.push_back(slangBuffer); + driver.sourceLoader.addBuffer(slangBuffer); bufferFilePaths.insert({slangBuffer.id, mlirBuffer->getBufferIdentifier()}); } + for (const auto &libDir : options.libDirs) + driver.sourceLoader.addSearchDirectories(libDir); + + for (const auto &libExt : options.libExts) + driver.sourceLoader.addSearchExtension(libExt); + + for (const auto &includeDir : options.includeDirs) { + if (driver.sourceManager.addUserDirectories(includeDir)) { + return failure(); + } + } + + for (const auto &includeDir : options.includeSystemDirs) { + if (driver.sourceManager.addSystemDirectories(includeDir)) { + return failure(); + } + } + // Populate the driver options. - driver.options.includeDirs = options.includeDirs; - driver.options.includeSystemDirs = options.includeSystemDirs; - driver.options.libDirs = options.libDirs; - driver.options.libExts = options.libExts; driver.options.excludeExts.insert(options.excludeExts.begin(), options.excludeExts.end()); driver.options.ignoreDirectives = options.ignoreDirectives; @@ -221,22 +235,22 @@ LogicalResult ImportDriver::prepareDriver(SourceMgr &sourceMgr) { driver.options.librariesInheritMacros = options.librariesInheritMacros; driver.options.timeScale = options.timeScale; - driver.options.allowUseBeforeDeclare = options.allowUseBeforeDeclare; - driver.options.ignoreUnknownModules = options.ignoreUnknownModules; - driver.options.onlyLint = - options.mode == ImportVerilogOptions::Mode::OnlyLint; + driver.options.compilationFlags.emplace( + slang::ast::CompilationFlags::AllowUseBeforeDeclare, + options.allowUseBeforeDeclare); + driver.options.compilationFlags.emplace( + slang::ast::CompilationFlags::IgnoreUnknownModules, + options.ignoreUnknownModules); + driver.options.compilationFlags.emplace( + slang::ast::CompilationFlags::LintMode, + options.mode == ImportVerilogOptions::Mode::OnlyLint); driver.options.topModules = options.topModules; driver.options.paramOverrides = options.paramOverrides; driver.options.errorLimit = options.errorLimit; driver.options.warningOptions = options.warningOptions; - driver.options.suppressWarningsPaths = options.suppressWarningsPaths; driver.options.singleUnit = options.singleUnit; - driver.options.libraryFiles = options.libraryFiles; - - for (auto &dir : sourceMgr.getIncludeDirs()) - driver.options.includeDirs.push_back(dir); return success(driver.processOptions()); } @@ -318,12 +332,12 @@ LogicalResult ImportDriver::preprocessVerilog(llvm::raw_ostream &os) { diagnostics, optionBag); // Sources have to be pushed in reverse, as they form a stack in the // preprocessor. Last pushed source is processed first. - for (auto &buffer : slang::make_reverse_range(driver.buffers)) + for (auto &buffer : std::views::reverse(driver.sourceLoader.loadSources())) preprocessor.pushSource(buffer); if (failed(preprocessAndPrint(preprocessor))) return failure(); } else { - for (auto &buffer : driver.buffers) { + for (auto &buffer : driver.sourceLoader.loadSources()) { slang::BumpAllocator alloc; slang::Diagnostics diagnostics; slang::parsing::Preprocessor preprocessor(driver.sourceManager, alloc, diff --git a/lib/Conversion/ImportVerilog/ImportVerilogInternals.h b/lib/Conversion/ImportVerilog/ImportVerilogInternals.h index b045ffe00713..463b73d3857b 100644 --- a/lib/Conversion/ImportVerilog/ImportVerilogInternals.h +++ b/lib/Conversion/ImportVerilog/ImportVerilogInternals.h @@ -140,7 +140,7 @@ struct Context { /// failure if an error occurs. Returns a null value if the formatted string /// is trivially empty. Otherwise returns the formatted string. FailureOr convertFormatString( - slang::span arguments, Location loc, + std::span arguments, Location loc, moore::IntFormat defaultFormat = moore::IntFormat::Decimal, bool appendNewline = false); diff --git a/lib/Conversion/ImportVerilog/Structure.cpp b/lib/Conversion/ImportVerilog/Structure.cpp index ed785cf85833..909c9aa570bf 100644 --- a/lib/Conversion/ImportVerilog/Structure.cpp +++ b/lib/Conversion/ImportVerilog/Structure.cpp @@ -602,7 +602,7 @@ Context::convertModuleHeader(const slang::ast::InstanceBodySymbol *module) { using slang::ast::PortSymbol; using slang::ast::TypeParameterSymbol; - auto parameters = module->parameters; + auto parameters = module->getParameters(); bool hasModuleSame = false; // If there is already exist a module that has the same name with this // module ,has the same parent scope and has the same parameters we can @@ -610,7 +610,7 @@ Context::convertModuleHeader(const slang::ast::InstanceBodySymbol *module) { for (auto const &existingModule : modules) { if (module->getDeclaringDefinition() == existingModule.getFirst()->getDeclaringDefinition()) { - auto moduleParameters = existingModule.getFirst()->parameters; + auto moduleParameters = existingModule.getFirst()->getParameters(); hasModuleSame = true; for (auto it1 = parameters.begin(), it2 = moduleParameters.begin(); it1 != parameters.end() && it2 != moduleParameters.end(); diff --git a/test/circt-verilog/commandline.sv b/test/circt-verilog/commandline.sv index 32b94be04aaf..4ed83bd83b03 100644 --- a/test/circt-verilog/commandline.sv +++ b/test/circt-verilog/commandline.sv @@ -3,4 +3,4 @@ // REQUIRES: slang // CHECK-HELP: OVERVIEW: Verilog and SystemVerilog frontend -// CHECK-VERSION: slang version 3. +// CHECK-VERSION: slang version 7. diff --git a/test/circt-verilog/preprocess-errors.sv b/test/circt-verilog/preprocess-errors.sv index 814345e30ffa..325e22092fa6 100644 --- a/test/circt-verilog/preprocess-errors.sv +++ b/test/circt-verilog/preprocess-errors.sv @@ -1,5 +1,5 @@ // RUN: circt-verilog %s -E --verify-diagnostics // REQUIRES: slang -// expected-error @below {{could not find or open include file}} +// expected-error @below {{'unknown.sv': No such file or directory}} `include "unknown.sv" From a2e123754952684ab5c3a3e5aaff37f88801fe97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98ystein=20Hovind?= Date: Fri, 1 Nov 2024 17:11:43 +0100 Subject: [PATCH 02/17] [Support] Fix cxx20 infinite recursion --- include/circt/Support/FVInt.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/circt/Support/FVInt.h b/include/circt/Support/FVInt.h index dfafb5b96481..43d0153fa86b 100644 --- a/include/circt/Support/FVInt.h +++ b/include/circt/Support/FVInt.h @@ -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); } +inline bool operator!=(uint64_t a, const FVInt &b) { return b.operator!=(a); } inline raw_ostream &operator<<(raw_ostream &os, const FVInt &value) { value.print(os); From e2e653d33dc31c8cf251cdcab1815ffe601c0f9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98ystein=20Hovind?= Date: Fri, 1 Nov 2024 18:28:50 +0100 Subject: [PATCH 03/17] [ImportVerilog] Disable exceptions --- lib/Conversion/ImportVerilog/CMakeLists.txt | 5 --- .../ImportVerilog/ImportVerilog.cpp | 31 +++++-------------- 2 files changed, 8 insertions(+), 28 deletions(-) diff --git a/lib/Conversion/ImportVerilog/CMakeLists.txt b/lib/Conversion/ImportVerilog/CMakeLists.txt index d813fa908ce7..eca74e5a07d7 100644 --- a/lib/Conversion/ImportVerilog/CMakeLists.txt +++ b/lib/Conversion/ImportVerilog/CMakeLists.txt @@ -1,6 +1,4 @@ # 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 @@ -15,9 +13,6 @@ add_compile_definitions($<$: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 diff --git a/lib/Conversion/ImportVerilog/ImportVerilog.cpp b/lib/Conversion/ImportVerilog/ImportVerilog.cpp index d3813d92e59c..7bf1a1f779f5 100644 --- a/lib/Conversion/ImportVerilog/ImportVerilog.cpp +++ b/lib/Conversion/ImportVerilog/ImportVerilog.cpp @@ -355,28 +355,15 @@ LogicalResult ImportDriver::preprocessVerilog(llvm::raw_ostream &os) { // Entry Points //===----------------------------------------------------------------------===// -/// Execute a callback and report any thrown exceptions as "internal slang -/// error" MLIR diagnostics. -static LogicalResult -catchExceptions(llvm::function_ref callback) { - try { - return callback(); - } catch (const std::exception &e) { - return emitError(UnknownLoc(), "internal slang error: ") << e.what(); - } -} - /// Parse the specified Verilog inputs into the specified MLIR context. LogicalResult circt::importVerilog(SourceMgr &sourceMgr, MLIRContext *mlirContext, TimingScope &ts, ModuleOp module, const ImportVerilogOptions *options) { - return catchExceptions([&] { - ImportDriver importDriver(mlirContext, ts, options); - if (failed(importDriver.prepareDriver(sourceMgr))) - return failure(); - return importDriver.importVerilog(module); - }); + ImportDriver importDriver(mlirContext, ts, options); + if (failed(importDriver.prepareDriver(sourceMgr))) + return failure(); + return importDriver.importVerilog(module); } /// Run the files in a source manager through Slang's Verilog preprocessor and @@ -385,12 +372,10 @@ LogicalResult circt::preprocessVerilog(SourceMgr &sourceMgr, MLIRContext *mlirContext, TimingScope &ts, llvm::raw_ostream &os, const ImportVerilogOptions *options) { - return catchExceptions([&] { - ImportDriver importDriver(mlirContext, ts, options); - if (failed(importDriver.prepareDriver(sourceMgr))) - return failure(); - return importDriver.preprocessVerilog(os); - }); + ImportDriver importDriver(mlirContext, ts, options); + if (failed(importDriver.prepareDriver(sourceMgr))) + return failure(); + return importDriver.preprocessVerilog(os); } /// Entry point as an MLIR translation. From f23891a4c405ff7f16ceffc653a5407f389a542b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98ystein=20Hovind?= Date: Fri, 1 Nov 2024 18:29:10 +0100 Subject: [PATCH 04/17] [ImportVerilog] Remove unused header --- lib/Conversion/ImportVerilog/ImportVerilog.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Conversion/ImportVerilog/ImportVerilog.cpp b/lib/Conversion/ImportVerilog/ImportVerilog.cpp index 7bf1a1f779f5..371d3e26c310 100644 --- a/lib/Conversion/ImportVerilog/ImportVerilog.cpp +++ b/lib/Conversion/ImportVerilog/ImportVerilog.cpp @@ -11,7 +11,6 @@ //===----------------------------------------------------------------------===// #include "ImportVerilogInternals.h" -#include "mlir/IR/BuiltinTypes.h" #include "mlir/IR/Diagnostics.h" #include "mlir/IR/Verifier.h" #include "mlir/Support/Timing.h" From bcf2c79a0fa7300083046495921aaa9cf0146b8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98ystein=20Hovind?= Date: Fri, 1 Nov 2024 18:32:36 +0100 Subject: [PATCH 05/17] [ImportVerilog] Remove unused warning flags --- lib/Conversion/ImportVerilog/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/Conversion/ImportVerilog/CMakeLists.txt b/lib/Conversion/ImportVerilog/CMakeLists.txt index eca74e5a07d7..7db7b29b9da9 100644 --- a/lib/Conversion/ImportVerilog/CMakeLists.txt +++ b/lib/Conversion/ImportVerilog/CMakeLists.txt @@ -16,9 +16,7 @@ else () # 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 () From 64f339dacdf015766521969bd18832b87f902faa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98ystein=20Hovind?= Date: Fri, 1 Nov 2024 18:33:00 +0100 Subject: [PATCH 06/17] [ImportVerilog] Use `std::views::reverse()` --- lib/Conversion/ImportVerilog/ImportVerilog.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/Conversion/ImportVerilog/ImportVerilog.cpp b/lib/Conversion/ImportVerilog/ImportVerilog.cpp index 371d3e26c310..9558293bb032 100644 --- a/lib/Conversion/ImportVerilog/ImportVerilog.cpp +++ b/lib/Conversion/ImportVerilog/ImportVerilog.cpp @@ -91,11 +91,10 @@ class MlirDiagnosticClient : public slang::DiagnosticClient { mlirDiag << " [-W" << optionName << "]"; // Write out macro expansions, if we have any, in reverse order. - for (auto it = diag.expansionLocs.rbegin(); it != diag.expansionLocs.rend(); - it++) { + for (auto loc : std::views::reverse(diag.expansionLocs)) { auto ¬e = mlirDiag.attachNote( - convertLocation(sourceManager->getFullyOriginalLoc(*it))); - auto macroName = sourceManager->getMacroName(*it); + convertLocation(sourceManager->getFullyOriginalLoc(loc))); + auto macroName = sourceManager->getMacroName(loc); if (macroName.empty()) note << "expanded from here"; else From 9fe0c5fad899c1bbb04741d51e1b87c861317c51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98ystein=20Hovind?= Date: Sun, 10 Nov 2024 17:37:35 +0100 Subject: [PATCH 07/17] [CMake] Don't perform shallow clone of slang --- CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f0ed08170ff6..8cc4876cc73a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -557,8 +557,7 @@ if(CIRCT_SLANG_FRONTEND_ENABLED) FetchContent_Declare( slang GIT_REPOSITORY https://github.com/MikePopoloski/slang.git - GIT_TAG bad0d6ba3dec20355b0156c535bbddf2f926ab37 - 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 From 97b37dc3d07dab5298f46f8292b39e65f5af32ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98ystein=20Hovind?= Date: Sun, 10 Nov 2024 18:53:23 +0100 Subject: [PATCH 08/17] [CMake] Add hack for slang boost dependency --- CMakeLists.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8cc4876cc73a..fcd620f0904a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -599,6 +599,14 @@ if(CIRCT_SLANG_FRONTEND_ENABLED) set_target_properties(fmt PROPERTIES PUBLIC_HEADER "") 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 7.0 REQUIRED) endif() From 8df12d5b9054529831783a09899bf2c1b14b37e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98ystein=20Hovind?= Date: Sun, 10 Nov 2024 18:53:41 +0100 Subject: [PATCH 09/17] [CMake] Add comment on C++ standard --- CMakeLists.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fcd620f0904a..5f359977e651 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -551,6 +551,10 @@ 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 + 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) @@ -575,8 +579,6 @@ if(CIRCT_SLANG_FRONTEND_ENABLED) set(SLANG_USE_MIMALLOC OFF) FetchContent_MakeAvailable(slang) - set(CMAKE_CXX_STANDARD 20) - set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_FLAGS ${ORIGINAL_CMAKE_CXX_FLAGS}) set(BUILD_SHARED_LIBS ${ORIGINAL_BUILD_SHARED_LIBS}) From 0e57eccd70024eef380abea4a4856d20fd13c227 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98ystein=20Hovind?= Date: Mon, 11 Nov 2024 18:47:28 +0100 Subject: [PATCH 10/17] [CMake] Fix deprecated comment --- lib/Conversion/ImportVerilog/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/Conversion/ImportVerilog/CMakeLists.txt b/lib/Conversion/ImportVerilog/CMakeLists.txt index 7db7b29b9da9..867593804f8e 100644 --- a/lib/Conversion/ImportVerilog/CMakeLists.txt +++ b/lib/Conversion/ImportVerilog/CMakeLists.txt @@ -1,5 +1,3 @@ -# slang uses exceptions - # 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 From 6409c40e89213114ee609ce5e0d6dac66c3d5c12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98ystein=20Hovind?= Date: Mon, 11 Nov 2024 20:35:47 +0100 Subject: [PATCH 11/17] [CI] Specifically request `{gcc,g++}-11` --- .github/workflows/buildAndTest.yml | 4 ++-- .github/workflows/nightlyIntegrationTests.yml | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/buildAndTest.yml b/.github/workflows/buildAndTest.yml index 194631664bf9..1ba53628aa5a 100644 --- a/.github/workflows/buildAndTest.yml +++ b/.github/workflows/buildAndTest.yml @@ -148,8 +148,8 @@ jobs: mode: Debug assert: ON shared: ON - - cc: gcc - cxx: g++ + - cc: gcc-11 + cxx: g++-11 mode: Release assert: OFF shared: OFF diff --git a/.github/workflows/nightlyIntegrationTests.yml b/.github/workflows/nightlyIntegrationTests.yml index 4cdd1009ecba..32e4fdc57ba5 100644 --- a/.github/workflows/nightlyIntegrationTests.yml +++ b/.github/workflows/nightlyIntegrationTests.yml @@ -34,8 +34,8 @@ jobs: compiler: - cc: clang cxx: clang++ - - cc: gcc - cxx: g++ + - cc: gcc-11 + cxx: g++-11 lit-flags: ['', '--vg'] exclude: - build-type: Debug @@ -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: From 4268ba1c3438b10f630f3c46e37684f5b505a103 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98ystein=20Hovind?= Date: Thu, 14 Nov 2024 09:35:19 +0100 Subject: [PATCH 12/17] [CI] Bump circt ci builder image --- .github/workflows/buildAndTest.yml | 4 ++-- .github/workflows/nightlyIntegrationTests.yml | 2 +- .github/workflows/shortIntegrationTests.yml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/buildAndTest.yml b/.github/workflows/buildAndTest.yml index 1ba53628aa5a..b7c8ca51de68 100644 --- a/.github/workflows/buildAndTest.yml +++ b/.github/workflows/buildAndTest.yml @@ -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. @@ -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: diff --git a/.github/workflows/nightlyIntegrationTests.yml b/.github/workflows/nightlyIntegrationTests.yml index 32e4fdc57ba5..043125a8892b 100644 --- a/.github/workflows/nightlyIntegrationTests.yml +++ b/.github/workflows/nightlyIntegrationTests.yml @@ -19,7 +19,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-integration-test:v13.1 + image: ghcr.io/circt/images/circt-integration-test:v15.1 volumes: - /mnt:/__w/circt strategy: diff --git a/.github/workflows/shortIntegrationTests.yml b/.github/workflows/shortIntegrationTests.yml index 5aa9d6af2b89..4b6ca7eb3424 100644 --- a/.github/workflows/shortIntegrationTests.yml +++ b/.github/workflows/shortIntegrationTests.yml @@ -29,7 +29,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-integration-test:v13.1 + image: ghcr.io/circt/images/circt-integration-test:v15.1 volumes: - /mnt:/__w/circt strategy: From c5631dfefd96ee514a98734970ccb680b864fc3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98ystein=20Hovind?= Date: Thu, 14 Nov 2024 09:35:32 +0100 Subject: [PATCH 13/17] [CI] Build with `clang-17` --- .github/workflows/buildAndTest.yml | 4 ++-- .github/workflows/nightlyIntegrationTests.yml | 4 ++-- .github/workflows/shortIntegrationTests.yml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/buildAndTest.yml b/.github/workflows/buildAndTest.yml index b7c8ca51de68..5752c9cdb6ac 100644 --- a/.github/workflows/buildAndTest.yml +++ b/.github/workflows/buildAndTest.yml @@ -143,8 +143,8 @@ 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 diff --git a/.github/workflows/nightlyIntegrationTests.yml b/.github/workflows/nightlyIntegrationTests.yml index 043125a8892b..bb8fb05db114 100644 --- a/.github/workflows/nightlyIntegrationTests.yml +++ b/.github/workflows/nightlyIntegrationTests.yml @@ -32,8 +32,8 @@ jobs: build-shared: [ON, OFF] build-type: [Debug, Release] compiler: - - cc: clang - cxx: clang++ + - cc: clang-17 + cxx: clang++-17 - cc: gcc-11 cxx: g++-11 lit-flags: ['', '--vg'] diff --git a/.github/workflows/shortIntegrationTests.yml b/.github/workflows/shortIntegrationTests.yml index 4b6ca7eb3424..2afb0a6580d9 100644 --- a/.github/workflows/shortIntegrationTests.yml +++ b/.github/workflows/shortIntegrationTests.yml @@ -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 From 01c584421a742d2cce98466f939c7e9b46b004d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98ystein=20Hovind?= Date: Thu, 14 Nov 2024 19:26:22 +0100 Subject: [PATCH 14/17] [ImportVerilog] Add hack to avoid building `OBJECT` library target The `OBJECT` library target file generated by `llvm_add_library()` does not inherit `COMPILE_DEFINITIONS` from its transitive closure in the current implementation. To avoid generating this library, the condition `(ARG_SHARED AND ARG_STATIC) OR ARG_OBJECT` must not be satisfied. Neither `ARG_STATIC` nor `ARG_SHARED` is set at the moment, but `ARG_OBJECT` is satisfied due to `NEEDS_OBJECT_LIB` being set due to `NOT ARG_SHARED AND NOT ARG_EXCLUDE_FROM_LIBMLIR AND NOT XCODE AND NOT MSVC_IDE` being satisfied unless one of `ARG_SHARED`, `ARG_EXCLUDE_FROM_LIBMLIR`, `XCODE` or `MSVC_IDE` is satisfied. --- lib/Conversion/ImportVerilog/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/Conversion/ImportVerilog/CMakeLists.txt b/lib/Conversion/ImportVerilog/CMakeLists.txt index 867593804f8e..a2647abefec9 100644 --- a/lib/Conversion/ImportVerilog/CMakeLists.txt +++ b/lib/Conversion/ImportVerilog/CMakeLists.txt @@ -19,6 +19,10 @@ else () add_compile_options(-Wno-covered-switch-default) endif () +# HACK: Setting `XCODE` to avoid adding `OBJECT` argument to +# `llvm_add_library()`, because the resulting object does not have the +# transitively inherit `COMPILE_DEFINITIONS` from `slang_slang`. +set(XCODE ON) add_circt_translation_library(CIRCTImportVerilog Expressions.cpp FormatStrings.cpp From 4f79b7f64bd97134aa8fa5e0b4a9b65c32ba382b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98ystein=20Hovind?= Date: Thu, 14 Nov 2024 20:21:51 +0100 Subject: [PATCH 15/17] [ImportVerilog] Fix build error --- lib/Conversion/ImportVerilog/ImportVerilog.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Conversion/ImportVerilog/ImportVerilog.cpp b/lib/Conversion/ImportVerilog/ImportVerilog.cpp index 9558293bb032..8d4029f97445 100644 --- a/lib/Conversion/ImportVerilog/ImportVerilog.cpp +++ b/lib/Conversion/ImportVerilog/ImportVerilog.cpp @@ -330,7 +330,8 @@ LogicalResult ImportDriver::preprocessVerilog(llvm::raw_ostream &os) { diagnostics, optionBag); // Sources have to be pushed in reverse, as they form a stack in the // preprocessor. Last pushed source is processed first. - for (auto &buffer : std::views::reverse(driver.sourceLoader.loadSources())) + auto sources = driver.sourceLoader.loadSources(); + for (auto &buffer : std::views::reverse(sources)) preprocessor.pushSource(buffer); if (failed(preprocessAndPrint(preprocessor))) return failure(); From 1695cdf2267afbdf4ceb4d3e2e5af2eecd35a772 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98ystein=20Hovind?= Date: Fri, 15 Nov 2024 16:26:15 +0100 Subject: [PATCH 16/17] [Transforms] Use more specific type Fixes operator overload resolution error on `gcc-11`. --- lib/Transforms/StripDebugInfoWithPred.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Transforms/StripDebugInfoWithPred.cpp b/lib/Transforms/StripDebugInfoWithPred.cpp index 26e388e0e88b..54cf440edc93 100644 --- a/lib/Transforms/StripDebugInfoWithPred.cpp +++ b/lib/Transforms/StripDebugInfoWithPred.cpp @@ -57,7 +57,7 @@ struct StripDebugInfoWithPred SmallVector newLocs; if (auto resLocs = op->getAttrOfType(attributeName)) { bool changed = false; - for (auto loc : resLocs.getAsRange()) { + for (auto loc : resLocs.getAsRange()) { auto newLoc = getStrippedLoc(loc); changed |= newLoc != loc; newLocs.push_back(newLoc); From 0e128b517e50c2af102a84a50009c01fa254ac41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98ystein=20Hovind?= Date: Fri, 15 Nov 2024 16:27:23 +0100 Subject: [PATCH 17/17] [FIRRTL] Use more specific type Fixes operator overload resolution error on `gcc-11`. --- lib/Dialect/FIRRTL/FIRRTLOps.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Dialect/FIRRTL/FIRRTLOps.cpp b/lib/Dialect/FIRRTL/FIRRTLOps.cpp index d7be7ca4c88f..95c987dbbbab 100644 --- a/lib/Dialect/FIRRTL/FIRRTLOps.cpp +++ b/lib/Dialect/FIRRTL/FIRRTLOps.cpp @@ -1579,7 +1579,7 @@ LogicalResult FModuleOp::verify() { for (auto [arg, type, loc] : zip(body->getArguments(), portTypes, portLocs)) { if (arg.getType() != cast(type).getValue()) return emitOpError("block argument types should match signature types"); - if (arg.getLoc() != cast(loc)) + if (arg.getLoc() != cast(loc)) return emitOpError( "block argument locations should match signature locations"); }