[SV] Allow constantX/Z to have non-integer types (#2338)

This commit allows constantX/Z op to have non-integer types.
This commit is contained in:
Hideto Ueno 2021-12-15 03:05:28 +09:00 committed by GitHub
parent 80f70835e5
commit 2cb8bf3817
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 56 additions and 6 deletions

View File

@ -90,8 +90,14 @@ def ConstantXOp : SVOp<"constantX", [NoSideEffect, HasCustomSSAName]> {
}];
let arguments = (ins);
let results = (outs HWIntegerType:$result);
let results = (outs HWValueType:$result);
let assemblyFormat = " attr-dict `:` type($result)";
let verifier = "return ::verify$cppClass(*this);";
let extraClassDeclaration = [{
int64_t getWidth() {
return hw::getBitWidth(getType());
}
}];
}
def ConstantZOp : SVOp<"constantZ", [NoSideEffect, HasCustomSSAName]> {
@ -102,8 +108,14 @@ def ConstantZOp : SVOp<"constantZ", [NoSideEffect, HasCustomSSAName]> {
}];
let arguments = (ins);
let results = (outs HWIntegerType:$result);
let results = (outs HWValueType:$result);
let assemblyFormat = " attr-dict `:` type($result)";
let verifier = "return ::verify$cppClass(*this);";
let extraClassDeclaration = [{
int64_t getWidth() {
return hw::getBitWidth(getType());
}
}];
}
def LocalParamOp : SVOp<"localparam",

View File

@ -1884,12 +1884,12 @@ SubExprInfo ExprEmitter::visitVerbatimExprOp(Operation *op, ArrayAttr symbols) {
}
SubExprInfo ExprEmitter::visitSV(ConstantXOp op) {
os << op.getType().getWidth() << "'bx";
os << op.getWidth() << "'bx";
return {Unary, IsUnsigned};
}
SubExprInfo ExprEmitter::visitSV(ConstantZOp op) {
os << op.getType().getWidth() << "'bz";
os << op.getWidth() << "'bz";
return {Unary, IsUnsigned};
}

View File

@ -170,18 +170,32 @@ void ConstantXOp::getAsmResultNames(
function_ref<void(Value, StringRef)> setNameFn) {
SmallVector<char, 32> specialNameBuffer;
llvm::raw_svector_ostream specialName(specialNameBuffer);
specialName << "x_" << getType();
specialName << "x_i" << getWidth();
setNameFn(getResult(), specialName.str());
}
static LogicalResult verifyConstantXOp(ConstantXOp op) {
// We don't allow zero width constant or unknown width.
if (op.getWidth() <= 0)
return op.emitError("unsupported type");
return success();
}
void ConstantZOp::getAsmResultNames(
function_ref<void(Value, StringRef)> setNameFn) {
SmallVector<char, 32> specialNameBuffer;
llvm::raw_svector_ostream specialName(specialNameBuffer);
specialName << "z_" << getType();
specialName << "z_i" << getWidth();
setNameFn(getResult(), specialName.str());
}
static LogicalResult verifyConstantZOp(ConstantZOp op) {
// We don't allow zero width constant or unknown type.
if (op.getWidth() <= 0)
return op.emitError("unsupported type");
return success();
}
//===----------------------------------------------------------------------===//
// LocalParamOp
//===----------------------------------------------------------------------===//

View File

@ -445,6 +445,16 @@ hw.module @struct_field_inout2(%a: !hw.inout<struct<b: !hw.struct<c: i1>>>) {
sv.assign %1, %true : i1
}
// CHECK-LABEL: module AggregateConstantXZ(
hw.module @AggregateConstantXZ() -> (res1: !hw.struct<foo: i2, bar: !hw.array<3xi4>>,
res2: !hw.struct<foo: i2, bar: !hw.array<3xi4>>) {
%0 = sv.constantX : !hw.struct<foo: i2, bar: !hw.array<3xi4>>
%1 = sv.constantZ : !hw.struct<foo: i2, bar: !hw.array<3xi4>>
// CHECK: assign res1 = 14'bx
// CHECK: assign res2 = 14'bz
hw.output %0, %1 : !hw.struct<foo: i2, bar: !hw.array<3xi4>>, !hw.struct<foo: i2, bar: !hw.array<3xi4>>
}
// CHECK-LABEL: issue508
// https://github.com/llvm/circt/issues/508
hw.module @issue508(%in1: i1, %in2: i1) {

View File

@ -199,3 +199,17 @@ hw.module @part_select1() {
// expected-error @+1 {{slice width should not be greater than input width}}
%c = sv.indexed_part_select %r1[%c2 : 20] : i10,i3
}
// -----
hw.module @ZeroWidthConstantX() {
// expected-error @+1 {{unsupported type}}
%0 = sv.constantX : !hw.struct<>
}
// -----
hw.module @ZeroWidthConstantZ() {
// expected-error @+1 {{unsupported type}}
%0 = sv.constantZ : !hw.struct<>
}