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] [SROA] [Mem2Reg][Canonicalizers]Support Passes for Nested Type #7158

Merged
merged 117 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 115 commits
Commits
Show all changes
117 commits
Select commit Hold shift + click to select a range
2ce348a
Support ref for struct
mingzheTerapines Jun 12, 2024
1087294
Merge branch 'mingzhe-structRef' of https://github.com/Terapines/circ…
mingzheTerapines Jun 12, 2024
6b0c27d
Support union Ref
mingzheTerapines Jun 12, 2024
998c897
Merge remote-tracking branch 'upstream/main' into mingzhe-structRef
mingzheTerapines Jun 13, 2024
3a93a88
Merge branch 'llvm:main' into mingzhe-structRef
mingzheTerapines Jun 13, 2024
6315b9f
Merge branch 'llvm:main' into mingzhe-structRef
mingzheTerapines Jun 14, 2024
86d1085
Add anystructtype and anyuniontype
mingzheTerapines Jun 14, 2024
6784863
Merge branch 'llvm:main' into mingzhe-structRef
mingzheTerapines Jun 17, 2024
36fc520
Merge branch 'llvm:main' into mingzhe-structRef
mingzheTerapines Jun 19, 2024
75d9576
Merge branch 'llvm:main' into mingzhe-structRef
mingzheTerapines Jun 20, 2024
f337e17
Merge branch 'llvm:main' into mingzhe-structRef
mingzheTerapines Jun 21, 2024
e773355
Merge branch 'llvm:main' into mingzhe-structRef
mingzheTerapines Jun 21, 2024
2484024
update struct createOP
mingzheTerapines Jun 21, 2024
4c1d4ce
Merge branch 'mingzhe-structRef' of https://github.com/Terapines/circ…
mingzheTerapines Jun 21, 2024
611fde9
Merge branch 'llvm:main' into mingzhe-structRef
mingzheTerapines Jun 24, 2024
daf927a
Update
mingzheTerapines Jun 24, 2024
616817b
Merge branch 'llvm:main' into mingzhe-structRef
mingzheTerapines Jun 25, 2024
5a933a9
Merge branch 'mingzhe-structRef' of https://github.com/Terapines/circ…
mingzheTerapines Jun 25, 2024
fb8e5fa
Merge branch 'mingzhe-structRef' of https://github.com/Terapines/circ…
mingzheTerapines Jun 25, 2024
7f47b1a
Merge branch 'mingzhe-structRef' of https://github.com/Terapines/circ…
mingzheTerapines Jun 25, 2024
a90d2fb
Merge branch 'mingzhe-structRef' of https://github.com/Terapines/circ…
mingzheTerapines Jun 25, 2024
91f9e45
Merge branch 'mingzhe-structRef' of https://github.com/Terapines/circ…
mingzheTerapines Jun 25, 2024
343b163
Merge branch 'mingzhe-structRef' of https://github.com/Terapines/circ…
mingzheTerapines Jun 25, 2024
0bbb6f4
Merge branch 'mingzhe-structRef' of https://github.com/Terapines/circ…
mingzheTerapines Jun 25, 2024
d9918ef
co
mingzheTerapines Jun 25, 2024
b686552
Support union verifier
mingzheTerapines Jun 25, 2024
9f1ad05
Emit error for classType
mingzheTerapines Jun 25, 2024
8c715d5
annotation update
mingzheTerapines Jun 25, 2024
c9c9a0c
Add name for unioncreateop
mingzheTerapines Jun 25, 2024
b3defeb
Add name for unioncreateop
mingzheTerapines Jun 25, 2024
5e0b7a2
Merge branch 'mingzhe-structRef' of https://github.com/Terapines/circ…
mingzheTerapines Jun 25, 2024
82113d2
Support DestructurableAllocationOpInterface for
mingzheTerapines Jun 26, 2024
e373c9c
Support DestructurableAllocationOpInterface for
mingzheTerapines Jun 26, 2024
3c2ecfb
Merge branch 'llvm:main' into mingzhe-structRef
mingzheTerapines Jun 26, 2024
3e2d86a
Merge branch 'mingzhe-structRef' of https://github.com/Terapines/circ…
mingzheTerapines Jun 26, 2024
1c9ac9c
Merge branch 'llvm:main' into mingzhe-structRef
mingzheTerapines Jun 27, 2024
472a9c6
Remove destructble for structCreateOp
mingzheTerapines Jun 27, 2024
46f5d07
Remove destructble for structCreateOp
mingzheTerapines Jun 27, 2024
9e71863
Merge branch 'mingzhe-structRef' of https://github.com/Terapines/circ…
mingzheTerapines Jun 27, 2024
caff1b5
Merge branch 'mingzhe-structRef' of https://github.com/Terapines/circ…
mingzheTerapines Jun 27, 2024
4590dee
Merge branch 'mingzhe-structRef' of https://github.com/Terapines/circ…
mingzheTerapines Jun 27, 2024
95cb36e
Merge branch 'mingzhe-structRef' of https://github.com/Terapines/circ…
mingzheTerapines Jun 27, 2024
6fd656e
Merge branch 'mingzhe-structRef' of https://github.com/Terapines/circ…
mingzheTerapines Jun 27, 2024
5fb4952
Merge branch 'mingzhe-structRef' of https://github.com/Terapines/circ…
mingzheTerapines Jun 27, 2024
6dafb6c
Merge branch 'mingzhe-structRef' of https://github.com/Terapines/circ…
mingzheTerapines Jun 27, 2024
0f269b4
Merge branch 'mingzhe-structRef' of https://github.com/Terapines/circ…
mingzheTerapines Jun 27, 2024
c5dac0a
Merge branch 'mingzhe-structRef' of https://github.com/Terapines/circ…
mingzheTerapines Jun 27, 2024
00fa2d1
Merge branch 'llvm:main' into mingzhe-structRef
mingzheTerapines Jun 28, 2024
2891766
Merge branch 'main' of https://github.com/llvm/circt into mingzhe-str…
mingzheTerapines Jun 28, 2024
112ccb9
Support readOp
mingzheTerapines Jun 28, 2024
53c5b85
Fix bugs
mingzheTerapines Jun 28, 2024
6564705
Remove nested check
mingzheTerapines Jun 28, 2024
513f193
Fix bugs
mingzheTerapines Jun 28, 2024
0de2c04
Fix bugs
mingzheTerapines Jun 28, 2024
935bb08
Fix bugs
mingzheTerapines Jun 28, 2024
27b0eae
Fix bugs
mingzheTerapines Jun 28, 2024
4174bae
Merge branch 'llvm:main' into mingzhe-structRef
mingzheTerapines Jul 1, 2024
7002a92
Apply suggestions from code review
mingzheTerapines Jul 1, 2024
8fda84c
Change logic
mingzheTerapines Jul 1, 2024
ed6a11a
Change logic
mingzheTerapines Jul 1, 2024
ed106d4
Merge branch 'mingzhe-structRef' of https://github.com/Terapines/circ…
mingzheTerapines Jul 1, 2024
e381731
Remove useless code
mingzheTerapines Jul 1, 2024
7525a06
Remove useless code
mingzheTerapines Jul 1, 2024
3a07fee
Merge branch 'mingzhe-structRef' of https://github.com/Terapines/circ…
mingzheTerapines Jul 1, 2024
9051d82
add pass SROA
mingzheTerapines Jul 2, 2024
c31f135
Merge remote-tracking branch 'upstream/main' into mingzhe-structRef
mingzheTerapines Jul 2, 2024
7f58188
destrucable type implement
mingzheTerapines Jul 2, 2024
68c769f
destrucable type implement
mingzheTerapines Jul 2, 2024
40292e0
Merge branch 'mingzhe-structRef' of https://github.com/Terapines/circ…
mingzheTerapines Jul 2, 2024
9b41e35
fix clang
mingzheTerapines Jul 2, 2024
dca11ed
Add refType
mingzheTerapines Jul 2, 2024
a196659
Add refType
mingzheTerapines Jul 2, 2024
a44e570
Merge branch 'mingzhe-structRef' of https://github.com/Terapines/circ…
mingzheTerapines Jul 2, 2024
e432430
Merge branch 'mingzhe-structRef' of https://github.com/Terapines/circ…
mingzheTerapines Jul 2, 2024
1255a25
Merge branch 'mingzhe-structRef' of https://github.com/Terapines/circ…
mingzheTerapines Jul 2, 2024
ad7704f
Merge branch 'mingzhe-structRef' of https://github.com/Terapines/circ…
mingzheTerapines Jul 2, 2024
d4c7494
Merge branch 'mingzhe-structRef' of https://github.com/Terapines/circ…
mingzheTerapines Jul 2, 2024
ea4e93d
Merge branch 'mingzhe-structRef' of https://github.com/Terapines/circ…
mingzheTerapines Jul 2, 2024
8a184b1
Merge branch 'mingzhe-structRef' of https://github.com/Terapines/circ…
mingzheTerapines Jul 2, 2024
8b42aed
Merge branch 'llvm:main' into mingzhe-structRef
mingzheTerapines Jul 3, 2024
eb5abdc
Complete
mingzheTerapines Jul 3, 2024
a756609
Fix test bug
mingzheTerapines Jul 3, 2024
f2901e9
Add related test
mingzheTerapines Jul 3, 2024
1ccbd63
replace variable with constant
mingzheTerapines Jul 3, 2024
f4972ea
Update new test
mingzheTerapines Jul 4, 2024
3ce5c69
Merge branch 'llvm:main' into mingzhe-structRef
mingzheTerapines Jul 4, 2024
23d57b2
Support other assignOp case, no SROA will be used
mingzheTerapines Jul 4, 2024
dd69b41
Fix bugs
mingzheTerapines Jul 4, 2024
a2837fc
Disable for global
mingzheTerapines Jul 4, 2024
e5212f5
Disable for global
mingzheTerapines Jul 4, 2024
aac2043
Merge branch 'mingzhe-structRef' of https://github.com/Terapines/circ…
mingzheTerapines Jul 4, 2024
27d2c2f
Merge remote-tracking branch 'upstream/main' into mingzhe-structRef
mingzheTerapines Jul 5, 2024
f986f04
Only handle local struct for SROA
mingzheTerapines Jul 5, 2024
74216a7
Only handle local struct for SROA
mingzheTerapines Jul 5, 2024
58d197e
Merge branch 'mingzhe-structRef' of https://github.com/Terapines/circ…
mingzheTerapines Jul 5, 2024
3f4dfb4
Merge branch 'mingzhe-structRef' of https://github.com/Terapines/circ…
mingzheTerapines Jul 5, 2024
2ec746b
Merge branch 'mingzhe-structRef' of https://github.com/Terapines/circ…
mingzheTerapines Jul 5, 2024
7477144
Merge branch 'mingzhe-structRef' of https://github.com/Terapines/circ…
mingzheTerapines Jul 5, 2024
3246aca
Merge branch 'mingzhe-structRef' of https://github.com/Terapines/circ…
mingzheTerapines Jul 5, 2024
ac22fc0
Merge branch 'llvm:main' into mingzhe-structRef
mingzheTerapines Jul 8, 2024
1e56b8f
Merge branch 'llvm:main' into mingzhe-structRef
mingzheTerapines Jul 9, 2024
c4c0ba1
Merge branch 'llvm:main' into mingzhe-structRef
mingzheTerapines Jul 10, 2024
9f2fdc3
Let non-module level struct operation be different
mingzheTerapines Jul 10, 2024
8581d09
Custom struct_injectOp
mingzheTerapines Jul 10, 2024
756e865
Fix tests
mingzheTerapines Jul 10, 2024
5814d45
Support canonicalizers pass for struct
mingzheTerapines Jul 12, 2024
41bc228
Merge branch 'llvm:main' into mingzhe-structRef
mingzheTerapines Jul 12, 2024
2ecc338
Merge branch 'llvm:main' into mingzhe-structRef
mingzheTerapines Jul 15, 2024
1dea784
Support new Mem2Reg naming
mingzheTerapines Jul 15, 2024
aade8db
Add test for struct inject fold
mingzheTerapines Jul 15, 2024
9e3d24b
Support moorecreateOp folding
mingzheTerapines Jul 15, 2024
121cc35
Support fold for other struct-related Ops.
mingzheTerapines Jul 15, 2024
ca95f62
Support fold for other struct-related Ops.
mingzheTerapines Jul 15, 2024
316cc06
Merge branch 'mingzhe-structRef' of https://github.com/Terapines/circ…
mingzheTerapines Jul 15, 2024
2f740fb
Merge branch 'llvm:main' into mingzhe-structRef
mingzheTerapines Jul 16, 2024
e9ec6d5
Remove useless code
mingzheTerapines Jul 18, 2024
5eeb43a
Merge branch 'llvm:main' into mingzhe-structRef
mingzheTerapines Jul 18, 2024
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
86 changes: 58 additions & 28 deletions include/circt/Dialect/Moore/MooreOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ def ProcedureOp : MooreOp<"procedure", [
//===----------------------------------------------------------------------===//

def VariableOp : MooreOp<"variable", [
DeclareOpInterfaceMethods<DestructurableAllocationOpInterface>,
DeclareOpInterfaceMethods<PromotableAllocationOpInterface>,
DeclareOpInterfaceMethods<OpAsmOpInterface, ["getAsmResultNames"]>,
OptionalTypesMatchWith<"initial value and variable types match",
Expand Down Expand Up @@ -412,6 +413,7 @@ def ConstantOp : MooreOp<"constant", [Pure]> {
let results = (outs IntType:$result);
let hasCustomAssemblyFormat = 1;
let hasVerifier = 1;
let hasFolder = 1;
let builders = [
OpBuilder<(ins "IntType":$type, "const APInt &":$value)>,
OpBuilder<(ins "IntType":$type, "int64_t":$value)>,
Expand Down Expand Up @@ -965,7 +967,7 @@ def ExtractRefOp : MooreOp<"extract_ref"> {
}];
}

def StructCreateOp : MooreOp<"struct_create", [SameOperandsAndResultType]> {
def StructCreateOp : MooreOp<"struct_create", [Pure]> {
let summary = "Struct Create operation";
let description = [{
A structure represents a collection of data types
Expand All @@ -990,15 +992,18 @@ def StructCreateOp : MooreOp<"struct_create", [SameOperandsAndResultType]> {
```
See IEEE 1800-2017 § 7.2. "Structures".
}];
let arguments = (ins UnpackedType:$input);
let results = (outs UnpackedType:$result);
let hasCustomAssemblyFormat = 1;
let arguments = (ins Variadic<UnpackedType>:$input);
let results = (outs RefType:$result);
let assemblyFormat = [{
$input attr-dict `:` type($input)
$input attr-dict `:` type($input) `->` type($result)
}];
mingzheTerapines marked this conversation as resolved.
Show resolved Hide resolved
let hasVerifier = 1;
let hasFolder = 1;
}

def StructExtractOp : MooreOp<"struct_extract"> {
def StructExtractOp : MooreOp<"struct_extract", [
DeclareOpInterfaceMethods<DestructurableAccessorOpInterface>
]> {
let summary = "Struct Extract operation";
let description = [{
Structures can be converted to bits preserving the bit pattern.
Expand Down Expand Up @@ -1026,16 +1031,29 @@ def StructExtractOp : MooreOp<"struct_extract"> {
```
See IEEE 1800-2017 § 7.2.1 "Assigning to structures".
}];
let arguments = (ins StrAttr:$memberName, UnpackedType:$input);
let arguments = (ins StrAttr:$fieldName, Arg<RefType, "", [MemRead]>:$input);
let results = (outs UnpackedType:$result);
let assemblyFormat = [{
$input `,` $memberName attr-dict `:`
type($input) `->`
type($result)
$input `,` $fieldName attr-dict `:` type($input) `->` type($result)
}];
mingzheTerapines marked this conversation as resolved.
Show resolved Hide resolved
let hasVerifier = 1;
let hasFolder = 1;
}

def StructExtractRefOp : MooreOp<"struct_extract_ref", [
DeclareOpInterfaceMethods<DestructurableAccessorOpInterface>
]> {
let summary = "Struct Extract operation";
let arguments = (ins StrAttr:$fieldName, RefType:$input);
let results = (outs RefType:$result);
mingzheTerapines marked this conversation as resolved.
Show resolved Hide resolved
let assemblyFormat = [{
$input `,` $fieldName attr-dict `:`
type($input) `->` type($result)
}];
let hasVerifier = 1;
}

def StructInjectOp : MooreOp<"struct_inject"> {
def StructInjectOp : MooreOp<"struct_inject", [Pure]> {
let summary = "Struct Field operation";
let description = [{
A structure can be assigned as a whole and passed to
Expand All @@ -1059,16 +1077,16 @@ def StructInjectOp : MooreOp<"struct_inject"> {
```
See IEEE 1800-2017 § 7.2. "Assigning to structures".
}];
let arguments = (ins UnpackedType:$LHS, StrAttr:$memberName,
UnpackedType:$RHS);
let results = (outs UnpackedType:$result);
let assemblyFormat = [{
$LHS `,` $memberName `,` $RHS
attr-dict `:` type($LHS) type($RHS) `->` type($result)
}];
let arguments = (ins RefType:$input, StrAttr:$fieldName,
UnpackedType:$newValue);
let results = (outs RefType:$result);
let hasCustomAssemblyFormat = 1;
let hasVerifier = 1;
let hasFolder = 1;
let hasCanonicalizeMethod = true;
}

def UnionCreateOp : MooreOp<"union_create"> {
def UnionCreateOp : MooreOp<"union_create", [Pure]> {
let summary = "Union Create operation";
let description = [{
A union is a data type that represents a single piece
Expand All @@ -1093,12 +1111,12 @@ def UnionCreateOp : MooreOp<"union_create"> {
```
See IEEE 1800-2017 § 7.3 "Unions"
}];
let arguments = (ins StrAttr:$unionName, UnpackedType:$input);
let arguments = (ins UnpackedType:$input, StrAttr:$fieldName);
let results = (outs UnpackedType:$result);
let assemblyFormat = [{
$unionName `,` $input attr-dict `:`
type($input) `->` type($result)
$input attr-dict `:` type($input) `->` type($result)
}];
let hasVerifier = 1;
}

def UnionExtractOp : MooreOp<"union_extract"> {
Expand All @@ -1124,17 +1142,29 @@ def UnionExtractOp : MooreOp<"union_extract"> {
```
See IEEE 1800-2017 § 7.3.1 "Packed unions"
}];
let arguments = (ins StrAttr:$memberName, UnpackedType:$input);
let arguments = (ins StrAttr:$fieldName, UnpackedType:$input);
let results = (outs UnpackedType:$result);
let assemblyFormat = [{
$input `,` $memberName attr-dict `:`
type($input) `->` type($result)
$input `,` $fieldName attr-dict `:`
type($input) `->` type($result)
}];
let hasVerifier = 1;
}

def UnionExtractRefOp : MooreOp<"union_extract_ref"> {
let summary = "Union Extract operation";
let arguments = (ins StrAttr:$fieldName, RefType:$input);
let results = (outs RefType:$result);
let assemblyFormat = [{
$input `,` $fieldName attr-dict `:`
type($input) `->` type($result)
}];
let hasVerifier = 1;
}

def ConditionalOp : MooreOp<"conditional",[
RecursiveMemoryEffects,
NoRegionArguments,
NoRegionArguments,
SingleBlockImplicitTerminator<"moore::YieldOp">
]> {
let summary = "Conditional operation";
Expand Down Expand Up @@ -1174,8 +1204,8 @@ def ConditionalOp : MooreOp<"conditional",[
}

def YieldOp : MooreOp<"yield", [
Pure,
Terminator,
Pure,
Terminator,
HasParent<"ConditionalOp">
]> {
let summary = "conditional yield and termination operation";
Expand Down
1 change: 1 addition & 0 deletions include/circt/Dialect/Moore/MooreTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "mlir/IR/BuiltinAttributes.h"
#include "mlir/IR/Location.h"
#include "mlir/IR/Types.h"
#include "mlir/Interfaces/MemorySlotInterfaces.h"
#include <variant>

namespace circt {
Expand Down
29 changes: 24 additions & 5 deletions include/circt/Dialect/Moore/MooreTypes.td
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
include "circt/Dialect/Moore/MooreDialect.td"
include "mlir/IR/AttrTypeBase.td"
include "mlir/IR/EnumAttr.td"
include "mlir/Interfaces/MemorySlotInterfaces.td"

class MooreTypeDef<string name, list<Trait> traits = [],
string baseCppClass = "::mlir::Type">
Expand Down Expand Up @@ -284,9 +285,16 @@ class StructLikeType<
let assemblyFormat = [{
`<` custom<Members>($members) `>`
}];
let extraClassDeclaration = [{
std::optional<DenseMap<Attribute, Type>> getSubelementIndexMap();
Type getTypeAtIndex(Attribute index);
std::optional<uint32_t> getFieldIndex(StringAttr nameField);
}];
}

def StructType : StructLikeType<"Struct", [], "moore::PackedType"> {
def StructType : StructLikeType<"Struct", [
DeclareTypeInterfaceMethods<DestructurableTypeInterface
>], "moore::PackedType"> {
let mnemonic = "struct";
let summary = "a packed struct type";
let description = [{
Expand All @@ -296,7 +304,9 @@ def StructType : StructLikeType<"Struct", [], "moore::PackedType"> {
}

def UnpackedStructType : StructLikeType<
"UnpackedStruct", [], "moore::UnpackedType"
"UnpackedStruct", [
DeclareTypeInterfaceMethods<DestructurableTypeInterface
>], "moore::UnpackedType"
> {
let mnemonic = "ustruct";
let summary = "an unpacked struct type";
Expand All @@ -305,7 +315,9 @@ def UnpackedStructType : StructLikeType<
}];
}

def UnionType : StructLikeType<"Union", [], "moore::PackedType"> {
def UnionType : StructLikeType<"Union", [
DeclareTypeInterfaceMethods<DestructurableTypeInterface
>], "moore::PackedType"> {
let mnemonic = "union";
let summary = "a packed union type";
let description = [{
Expand All @@ -316,7 +328,9 @@ def UnionType : StructLikeType<"Union", [], "moore::PackedType"> {


def UnpackedUnionType : StructLikeType<
"UnpackedUnion", [], "moore::UnpackedType"
"UnpackedUnion", [
DeclareTypeInterfaceMethods<DestructurableTypeInterface
>], "moore::UnpackedType"
> {
let mnemonic = "uunion";
let summary = "an unpacked union type";
Expand All @@ -329,7 +343,9 @@ def UnpackedUnionType : StructLikeType<
// Reference type wrapper
//===----------------------------------------------------------------------===//

def RefType : MooreTypeDef<"Ref", [], "moore::UnpackedType">{
def RefType : MooreTypeDef<"Ref", [
DeclareTypeInterfaceMethods<DestructurableTypeInterface
>], "moore::UnpackedType">{
let mnemonic = "ref";
let description = [{
A wrapper is used to wrap any SystemVerilog type. It's aimed to work for
Expand All @@ -352,6 +368,9 @@ def RefType : MooreTypeDef<"Ref", [], "moore::UnpackedType">{
std::optional<unsigned> getBitSize() {
return getNestedType().getBitSize();
};
std::optional<DenseMap<Attribute, Type>> getSubelementIndexMap();
Type getTypeAtIndex(Attribute index);
std::optional<uint32_t> getFieldIndex(StringAttr nameField);
}];
}

Expand Down
37 changes: 35 additions & 2 deletions lib/Conversion/ImportVerilog/Expressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ struct RvalueExprVisitor {
return {};
}

if (auto refOp = lhs.getDefiningOp<moore::StructExtractRefOp>()) {
auto input = refOp.getInput();
if (isa<moore::SVModuleOp>(input.getDefiningOp()->getParentOp())) {
refOp.getInputMutable();
refOp->erase();
builder.create<moore::StructInjectOp>(loc, input.getType(), input,
refOp.getFieldNameAttr(), rhs);
return rhs;
}
}
if (expr.isNonBlocking())
builder.create<moore::NonBlockingAssignOp>(loc, lhs, rhs);
else
Expand Down Expand Up @@ -461,7 +471,7 @@ struct RvalueExprVisitor {
Value visit(const slang::ast::MemberAccessExpression &expr) {
auto type = context.convertType(*expr.type);
auto valueType = expr.value().type;
auto value = context.convertRvalueExpression(expr.value());
auto value = context.convertLvalueExpression(expr.value());
if (!type || !value)
return {};
if (valueType->isStruct()) {
Expand All @@ -472,7 +482,9 @@ struct RvalueExprVisitor {
return builder.create<moore::UnionExtractOp>(
loc, type, builder.getStringAttr(expr.member.name), value);
}
llvm_unreachable("unsupported symbol kind");
mlir::emitError(loc, "expression of type ")
<< value.getType() << " cannot be accessed";
return {};
}

// Handle set membership operator.
Expand Down Expand Up @@ -653,6 +665,27 @@ struct LvalueExprVisitor {
lowBit);
}

Value visit(const slang::ast::MemberAccessExpression &expr) {
auto type = context.convertType(*expr.type);
auto valueType = expr.value().type;
auto value = context.convertLvalueExpression(expr.value());
if (!type || !value)
return {};
if (valueType->isStruct()) {
return builder.create<moore::StructExtractRefOp>(
loc, moore::RefType::get(cast<moore::UnpackedType>(type)),
builder.getStringAttr(expr.member.name), value);
}
if (valueType->isPackedUnion() || valueType->isUnpackedUnion()) {
return builder.create<moore::UnionExtractRefOp>(
loc, moore::RefType::get(cast<moore::UnpackedType>(type)),
builder.getStringAttr(expr.member.name), value);
}
mlir::emitError(loc, "expression of type ")
<< value.getType() << " cannot be accessed";
return {};
}

// Handle range bits selections.
Value visit(const slang::ast::RangeSelectExpression &expr) {
auto type = context.convertType(*expr.type);
Expand Down
11 changes: 11 additions & 0 deletions lib/Conversion/ImportVerilog/Structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,17 @@ struct MemberVisitor {
if (!lhs || !rhs)
return failure();

if (auto refOp = lhs.getDefiningOp<moore::StructExtractRefOp>()) {
auto input = refOp.getInput();
if (isa<moore::SVModuleOp>(input.getDefiningOp()->getParentOp())) {
refOp.getInputMutable();
refOp->erase();
builder.create<moore::StructInjectOp>(loc, input.getType(), input,
refOp.getFieldNameAttr(), rhs);
return success();
}
}

builder.create<moore::ContinuousAssignOp>(loc, lhs, rhs);
return success();
}
Expand Down
Loading
Loading