Skip to content

Commit

Permalink
[Moore] Fix mem2reg for variables with non-packed types
Browse files Browse the repository at this point in the history
Only attempt to promote variables with packed types during mem2reg. Also
run the `basic.sv` test of ImportVerilog through `circt-verilog` as a
sanity check of the transformations done by the tool.
  • Loading branch information
fabianschuiki committed Aug 12, 2024
1 parent 00f1404 commit b89f54f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/circt/Dialect/Moore/MooreOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ def NamedConstantOp : MooreOp<"named_constant", [
}];
}

def StringConstantOp : MooreOp<"string_constant", [Pure, ConstantLike]> {
def StringConstantOp : MooreOp<"string_constant", [Pure]> {
let summary = "Produce a constant string value";
let description = [{
Produces a constant value of string type.
Expand Down
6 changes: 6 additions & 0 deletions lib/Dialect/Moore/MooreOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,12 @@ SmallVector<MemorySlot> VariableOp::getPromotableSlots() {
if (mlir::mayBeGraphRegion(*getOperation()->getParentRegion()) ||
getInitial())
return {};

// Ensure that `getDefaultValue` can conjure up a default value for the
// variable's type.
if (!isa<PackedType>(getType().getNestedType()))
return {};

return {MemorySlot{getResult(), getType().getNestedType()}};
}

Expand Down
1 change: 1 addition & 0 deletions test/Conversion/ImportVerilog/basic.sv
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// RUN: circt-translate --import-verilog %s | FileCheck %s
// RUN: circt-verilog --ir-moore %s
// REQUIRES: slang

// Internal issue in Slang v3 about jump depending on uninitialised value.
Expand Down

0 comments on commit b89f54f

Please sign in to comment.