-
Notifications
You must be signed in to change notification settings - Fork 420
[InnerSymbolTable] Expose a method to add an InnerSymTarget. #9446
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| //===- InnerSymbolTableTest.cpp - HW inner symbol table tests -------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! Thanks for adding this! 💯 |
||
|
|
||
| #include "circt/Dialect/HW/InnerSymbolTable.h" | ||
| #include "circt/Dialect/HW/HWDialect.h" | ||
| #include "mlir/IR/BuiltinOps.h" | ||
| #include "mlir/Parser/Parser.h" | ||
| #include "gtest/gtest.h" | ||
|
|
||
| using namespace mlir; | ||
| using namespace circt; | ||
| using namespace hw; | ||
|
|
||
| namespace { | ||
|
|
||
| constexpr StringLiteral testModuleString = R"mlir( | ||
| hw.module @foo(in %in : i1 {hw.exportPort = #hw<innerSym@port0>}) { | ||
| %wire0 = hw.wire %in sym @wire0 : i1 | ||
| %wire1 = hw.wire %in : i1 | ||
| hw.output | ||
| } | ||
| )mlir"; | ||
|
|
||
| TEST(InnerSymbolTableTest, Create) { | ||
| MLIRContext context; | ||
| context.loadDialect<HWDialect>(); | ||
|
|
||
| Block block; | ||
| LogicalResult parseResult = | ||
| parseSourceString(testModuleString, &block, &context); | ||
|
|
||
| ASSERT_TRUE(succeeded(parseResult)); | ||
|
|
||
| Operation *testOp = &block.front(); | ||
|
|
||
| InnerSymbolTable innerSymbolTable(testOp); | ||
|
|
||
| ASSERT_TRUE(innerSymbolTable.lookup("port0")); | ||
| ASSERT_TRUE(innerSymbolTable.lookup("wire0")); | ||
| } | ||
|
|
||
| TEST(InnerSymbolTableTest, Add) { | ||
| MLIRContext context; | ||
| context.loadDialect<HWDialect>(); | ||
|
|
||
| Block block; | ||
| LogicalResult parseResult = | ||
| parseSourceString(testModuleString, &block, &context); | ||
|
|
||
| ASSERT_TRUE(succeeded(parseResult)); | ||
|
|
||
| Operation *testOp = &block.front(); | ||
|
|
||
| InnerSymbolTable innerSymbolTable(testOp); | ||
|
|
||
| auto name = StringAttr::get(&context, "wire1"); | ||
|
|
||
| ASSERT_FALSE(innerSymbolTable.lookup(name)); | ||
|
|
||
| Operation *wire1 = testOp->getRegions().front().front().front().getNextNode(); | ||
|
|
||
| auto innerSymTarget = InnerSymTarget{wire1}; | ||
|
|
||
| LogicalResult result1 = innerSymbolTable.add(name, innerSymTarget); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably we want to update Otherwise, constructing a new inner symbol table over I could see Related: The way to get a reasonable new inner symbol name is using ISN (InnerSymbolNamespace), or utilities like those in The tentative plan was to unify IST and ISN, so maybe not worth this until then, and users manually update their IST as desired?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe I should just put effort into unifying IST and ISN... I don't need to get this in before that |
||
|
|
||
| ASSERT_TRUE(succeeded(result1)); | ||
| ASSERT_TRUE(innerSymbolTable.lookup(name)); | ||
|
|
||
| context.getDiagEngine().registerHandler([&](Diagnostic &diag) { | ||
| ASSERT_EQ(diag.getSeverity(), DiagnosticSeverity::Error); | ||
| ASSERT_EQ(diag.str(), "redefinition of inner symbol named 'wire1'"); | ||
| }); | ||
|
|
||
| LogicalResult result2 = innerSymbolTable.add(name, innerSymTarget); | ||
|
|
||
| ASSERT_FALSE(succeeded(result2)); | ||
| } | ||
|
|
||
| } // namespace | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this isn't a thing, but should it be noted that this generates a diagnostic for the failure case?