-
Notifications
You must be signed in to change notification settings - Fork 383
[ImportVerilog] Add HierarchicalNames.cpp to support hierarchical names. #7382
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] Add HierarchicalNames.cpp to support hierarchical names. #7382
Conversation
4fc101c to
3c3ab48
Compare
|
Really cool seeing this PR touching a really annoying and difficult corner of SystemVerilog 🥳! I agree with you @hailongSun2000: simply accessing hierarchical names through the One thing that would be great is if our solution to hierarchical paths wouldn't just magically refer to something defined in another module, but if we actually used SSA values (and maybe special module ports) to represent the hierarchical path. For example, when you see a hierarchical path @dtzWill has done a lot of awesome work on FIRRTL references/probes that we could draw a lot of inspiration from 🥇. We could take a similar approach and pass around references/pointers in the hierarchy: module A;
B b();
assign b.c.y = b.c.x + 1;
endmodule
module B;
C c();
endmodule
module C;
int x = 42;
int y;
endmodulemoore.module @A() {
%b.href.c.x, %b.href.c.y = moore.instance "b" @B() -> (href.c.x: !moore.ref<i32>, href.c.y: !moore.ref<i32>)
%0 = moore.read %b.href.c.x : <i32> // read `b.c.x`
%1 = moore.constant 1 : i32
%2 = moore.add %0, %1 : i32
moore.assign %b.href.c.y, %2 : <i32> // assign `b.c.y`
}
moore.module @B(
out %href.c.x : !moore.ref<i32>,
out %href.c.y : !moore.ref<i32>
) {
%c.href.x, %c.href.y = moore.instance "c" @C() -> (href.x: !moore.ref<i32>, href.y: !moore.ref<i32>)
moore.output %c.href.x, %c.href.y
}
moore.module @C(
out %href.x : !moore.ref<i32>,
out %href.y : !moore.ref<i32>
) {
%0 = moore.constant 42 : i32
%x = moore.variable %0 : i32
%y = moore.variable : i32
moore.output %x, %y // return references to the hierarchically-accessed values
}A potentially very nice part of materializing hierarchical references as actual references being passed around the hierarchy is that we may be able to write optimization passes later that turn these hierarchical references into regular ports. In the example above, we may later on figure out that
To implement something like the reference-passing above, we would already have to know which variables are accessed via hierarchical paths when we convert a module body. Because if a variable is accessed through a hierarchical path, we have to create additional ports to make sure we can pass its reference around. To know this, we may have to do a pre-pass over the entire AST to find all hierarchical names, and determine what exactly they access and through which modules the references have to pass. In the example above, the path What do you think about that @hailongSun2000, @dtzSiFive? |
|
It looks like so reasonable! Let me get this straight.
This is the first step. |
b692188 to
f6b1e50
Compare
|
A lot of cases are not considered. Such as |
28c0763 to
be5d86d
Compare
be5d86d to
b58e91a
Compare
|
I think I cannot mark |
cfba379 to
7c2876c
Compare
bb6d878 to
56999b8
Compare
56999b8 to
e0191bf
Compare
55663e3 to
69b2d2c
Compare
69b2d2c to
475e5bb
Compare
| // CHECK: [[RD_SC1_SD_Z:%.+]] = moore.read %subC1.subD.z : <i32> | ||
| // CHECK: moore.variable [[RD_SC1_SD_Z]] : <i32> | ||
| int u = subC1.subD.z; | ||
| // assign subC2.subD.z = u; |
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'll fix this later.
|
Hey, @fabianschuiki! I update this PR! Please check it, thanks in advance 😃! |
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.
Really really cool! Thanks a lot for working this out 🥳 And it's great to have all those tests around! 💯
475e5bb to
0d4cd40
Compare
Based on the SystemVerilog IEEE Std 1800-2017 § 23.6 Hierarchical names. Hierarchical names are separated into upward and downward. For example:
Therefore, we mark upward as
outputsand downward asinputs, meanwhile, all hierarchical names are marked asRefType.Unsupported cases:
However, we don't support hierarchical names invoked by two irrelevant modules at the same level. For example:
And we also don't support hierarchical names existing in the repeat modules. For example: