From e74bb965da55b6cff06773043302b56684da7635 Mon Sep 17 00:00:00 2001 From: Megan Wachs Date: Mon, 5 Aug 2024 10:32:55 -0700 Subject: [PATCH 01/14] bump llvm to tip of main --- llvm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm b/llvm index 0870afaaaccd..5689cccead7b 160000 --- a/llvm +++ b/llvm @@ -1 +1 @@ -Subproject commit 0870afaaaccde5b4bae37abfc982207ffafb8332 +Subproject commit 5689cccead7b70d8eeae4c641e8078e6d3c50b9a From d952f291de8e4b846f03cf20ab6eb32f04f14b46 Mon Sep 17 00:00:00 2001 From: Megan Wachs Date: Mon, 5 Aug 2024 13:43:23 -0700 Subject: [PATCH 02/14] Update FirMemLowering.cpp --- lib/Conversion/SeqToSV/FirMemLowering.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Conversion/SeqToSV/FirMemLowering.cpp b/lib/Conversion/SeqToSV/FirMemLowering.cpp index 8ae7c0a9649e..7844268b6dc2 100644 --- a/lib/Conversion/SeqToSV/FirMemLowering.cpp +++ b/lib/Conversion/SeqToSV/FirMemLowering.cpp @@ -9,6 +9,7 @@ #include "FirMemLowering.h" #include "mlir/IR/Threading.h" #include "llvm/Support/Debug.h" +#include "llvm/ADT/MapVector.h" using namespace circt; using namespace hw; From 80e2a805024174a56f3c896c13e0e078df2a4c6c Mon Sep 17 00:00:00 2001 From: Megan Wachs Date: Mon, 5 Aug 2024 14:10:08 -0700 Subject: [PATCH 03/14] Update FirMemLowering.cpp --- lib/Conversion/SeqToSV/FirMemLowering.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Conversion/SeqToSV/FirMemLowering.cpp b/lib/Conversion/SeqToSV/FirMemLowering.cpp index 7844268b6dc2..e8c745fb6f26 100644 --- a/lib/Conversion/SeqToSV/FirMemLowering.cpp +++ b/lib/Conversion/SeqToSV/FirMemLowering.cpp @@ -8,8 +8,8 @@ #include "FirMemLowering.h" #include "mlir/IR/Threading.h" -#include "llvm/Support/Debug.h" #include "llvm/ADT/MapVector.h" +#include "llvm/Support/Debug.h" using namespace circt; using namespace hw; From d46c557086d96ca825aab3a33a44d2759c99ed0b Mon Sep 17 00:00:00 2001 From: Megan Wachs Date: Mon, 5 Aug 2024 16:11:28 -0700 Subject: [PATCH 04/14] Update FirMemLowering.h --- lib/Conversion/SeqToSV/FirMemLowering.h | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Conversion/SeqToSV/FirMemLowering.h b/lib/Conversion/SeqToSV/FirMemLowering.h index 079535f613c4..1320a208c038 100644 --- a/lib/Conversion/SeqToSV/FirMemLowering.h +++ b/lib/Conversion/SeqToSV/FirMemLowering.h @@ -10,6 +10,7 @@ #ifndef CONVERSION_SEQTOSV_FIRMEMLOWERING_H #define CONVERSION_SEQTOSV_FIRMEMLOWERING_H +#include "llvm/ADT/MapVector.h" #include "circt/Dialect/HW/HWOps.h" #include "circt/Dialect/Seq/SeqOps.h" #include "circt/Support/LLVM.h" From c9e9d352300956f37c174bbe8772ba6ce8197aaa Mon Sep 17 00:00:00 2001 From: Megan Wachs Date: Tue, 6 Aug 2024 09:24:11 -0700 Subject: [PATCH 05/14] Update FirMemLowering.h --- lib/Conversion/SeqToSV/FirMemLowering.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Conversion/SeqToSV/FirMemLowering.h b/lib/Conversion/SeqToSV/FirMemLowering.h index 1320a208c038..edb9a80611ca 100644 --- a/lib/Conversion/SeqToSV/FirMemLowering.h +++ b/lib/Conversion/SeqToSV/FirMemLowering.h @@ -10,12 +10,12 @@ #ifndef CONVERSION_SEQTOSV_FIRMEMLOWERING_H #define CONVERSION_SEQTOSV_FIRMEMLOWERING_H -#include "llvm/ADT/MapVector.h" #include "circt/Dialect/HW/HWOps.h" #include "circt/Dialect/Seq/SeqOps.h" #include "circt/Support/LLVM.h" #include "circt/Support/Namespace.h" #include "circt/Support/SymCache.h" +#include "llvm/ADT/MapVector.h" namespace circt { From 9e76c9d9f1c484295c2fae658586f972ad425795 Mon Sep 17 00:00:00 2001 From: Megan Wachs Date: Tue, 6 Aug 2024 11:36:27 -0700 Subject: [PATCH 06/14] Update Dedup.cpp --- lib/Dialect/Arc/Transforms/Dedup.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Dialect/Arc/Transforms/Dedup.cpp b/lib/Dialect/Arc/Transforms/Dedup.cpp index d75601e6ff54..27c31a1e94d8 100644 --- a/lib/Dialect/Arc/Transforms/Dedup.cpp +++ b/lib/Dialect/Arc/Transforms/Dedup.cpp @@ -6,6 +6,7 @@ // //===----------------------------------------------------------------------===// +#include #include "circt/Dialect/Arc/ArcOps.h" #include "circt/Dialect/Arc/ArcPasses.h" #include "mlir/IR/BuiltinAttributes.h" From b36efbea5e185dc79de86692e6029c6563651d3b Mon Sep 17 00:00:00 2001 From: Megan Wachs Date: Tue, 6 Aug 2024 14:06:32 -0700 Subject: [PATCH 07/14] Update Dedup.cpp --- lib/Dialect/Arc/Transforms/Dedup.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Dialect/Arc/Transforms/Dedup.cpp b/lib/Dialect/Arc/Transforms/Dedup.cpp index 27c31a1e94d8..53e904d38c4c 100644 --- a/lib/Dialect/Arc/Transforms/Dedup.cpp +++ b/lib/Dialect/Arc/Transforms/Dedup.cpp @@ -6,7 +6,6 @@ // //===----------------------------------------------------------------------===// -#include #include "circt/Dialect/Arc/ArcOps.h" #include "circt/Dialect/Arc/ArcPasses.h" #include "mlir/IR/BuiltinAttributes.h" @@ -14,6 +13,7 @@ #include "llvm/ADT/SetVector.h" #include "llvm/Support/Debug.h" #include "llvm/Support/SHA256.h" +#include #define DEBUG_TYPE "arc-dedup" From 5b374ed4b46469a64e1c1e56bce3ad7f9b84d542 Mon Sep 17 00:00:00 2001 From: Megan Wachs Date: Tue, 6 Aug 2024 14:57:57 -0700 Subject: [PATCH 08/14] Update circt-verilog.cpp --- tools/circt-verilog/circt-verilog.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/circt-verilog/circt-verilog.cpp b/tools/circt-verilog/circt-verilog.cpp index 36c84f67f9d1..304cb64b1c59 100644 --- a/tools/circt-verilog/circt-verilog.cpp +++ b/tools/circt-verilog/circt-verilog.cpp @@ -16,6 +16,7 @@ #include "circt/Conversion/MooreToCore.h" #include "circt/Dialect/Moore/MoorePasses.h" #include "circt/Support/Version.h" +#include "mlir/IR/AsmState.h" #include "mlir/IR/BuiltinOps.h" #include "mlir/Pass/PassManager.h" #include "mlir/Support/FileUtilities.h" From 225985abf80a51ac44f62fc809b97f5ff1892757 Mon Sep 17 00:00:00 2001 From: Megan Wachs Date: Wed, 7 Aug 2024 10:13:40 -0700 Subject: [PATCH 09/14] Update SimOps.cpp --- lib/Dialect/Sim/SimOps.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Dialect/Sim/SimOps.cpp b/lib/Dialect/Sim/SimOps.cpp index 8d7c3c96c805..648c939600ac 100644 --- a/lib/Dialect/Sim/SimOps.cpp +++ b/lib/Dialect/Sim/SimOps.cpp @@ -15,6 +15,7 @@ #include "circt/Dialect/SV/SVOps.h" #include "mlir/IR/PatternMatch.h" #include "mlir/Interfaces/FunctionImplementation.h" +#include "llvm/ADT/MapVector.h" using namespace mlir; using namespace circt; From 673f3a9d598d28d6ba48aa710336b34c274ade6b Mon Sep 17 00:00:00 2001 From: Megan Wachs Date: Wed, 7 Aug 2024 12:07:50 -0700 Subject: [PATCH 10/14] fix om-linker --- tools/om-linker/om-linker.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/om-linker/om-linker.cpp b/tools/om-linker/om-linker.cpp index e5a4da154198..bd1e8fea3577 100644 --- a/tools/om-linker/om-linker.cpp +++ b/tools/om-linker/om-linker.cpp @@ -20,6 +20,7 @@ #include "circt/Dialect/SV/SVDialect.h" #include "circt/Dialect/Verif/VerifDialect.h" #include "circt/Support/Version.h" +#include "mlir/Bytecode/BytecodeWriter.h" #include "mlir/IR/BuiltinOps.h" #include "mlir/IR/Threading.h" #include "mlir/Parser/Parser.h" From 6a8996f7059d27c61d57e4ca404c2ca86949313c Mon Sep 17 00:00:00 2001 From: Fabian Schuiki Date: Fri, 9 Aug 2024 10:58:00 -0700 Subject: [PATCH 11/14] Fix MooreToCore conversion --- lib/Conversion/MooreToCore/MooreToCore.cpp | 15 ++++++++------- test/Conversion/MooreToCore/basic.mlir | 6 +++--- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/Conversion/MooreToCore/MooreToCore.cpp b/lib/Conversion/MooreToCore/MooreToCore.cpp index 6ea5561eb685..d115d7c86ece 100644 --- a/lib/Conversion/MooreToCore/MooreToCore.cpp +++ b/lib/Conversion/MooreToCore/MooreToCore.cpp @@ -158,7 +158,7 @@ struct VariableOpConversion : public OpConversionPattern { LogicalResult matchAndRewrite(VariableOp op, OpAdaptor adaptor, ConversionPatternRewriter &rewriter) const override { - Type resultType = typeConverter->convertType(op.getResult().getType()); + Type resultType = typeConverter->convertType(op.getType().getNestedType()); Value init = adaptor.getInitial(); // TODO: Unsupport x/z, so the initial value is 0. if (!init && cast(op.getResult().getType()).getDomain() == @@ -660,18 +660,19 @@ static void populateLegality(ConversionTarget &target) { static void populateTypeConversion(TypeConverter &typeConverter) { typeConverter.addConversion([&](IntType type) { - return mlir::IntegerType::get(type.getContext(), type.getWidth()); + return IntegerType::get(type.getContext(), type.getWidth()); }); typeConverter.addConversion([&](RefType type) -> std::optional { - if (isa(type.getNestedType())) - return mlir::IntegerType::get(type.getContext(), - type.getBitSize().value()); - return std::nullopt; + auto innerType = typeConverter.convertType(type.getNestedType()); + if (innerType) + return hw::InOutType::get(innerType); + return {}; }); // Valid target types. - typeConverter.addConversion([](mlir::IntegerType type) { return type; }); + typeConverter.addConversion([](IntegerType type) { return type; }); + typeConverter.addTargetMaterialization( [&](mlir::OpBuilder &builder, mlir::Type resultType, mlir::ValueRange inputs, diff --git a/test/Conversion/MooreToCore/basic.mlir b/test/Conversion/MooreToCore/basic.mlir index a516525be4a0..d7cc1123b83a 100644 --- a/test/Conversion/MooreToCore/basic.mlir +++ b/test/Conversion/MooreToCore/basic.mlir @@ -212,13 +212,13 @@ moore.module private @Null() { // CHECK-SAME: %[[V0:.*]] : i1, in // CHECK-SAME: %[[V1:.*]] : i1, out out0 : i1) { moore.module @Top(in %arg0 : !moore.l1, in %arg1 : !moore.l1, out out0 : !moore.l1) { -// CHECK-NEXT: %[[V2:.*]] = hw.instance "inst_0" @SubModule_0(a: %[[V0]]: i1, b: %[[V1]]: i1) -> (c: i1) + // CHECK-NEXT: %[[V2:.*]] = hw.instance "inst_0" @SubModule_0(a: %[[V0]]: i1, b: %[[V1]]: i1) -> (c: i1) %inst_0.c = moore.instance "inst_0" @SubModule_0(a: %arg0 : !moore.l1, b: %arg1 : !moore.l1) -> (c: !moore.l1) -// CHECK-NEXT: %[[V3:.*]] = hw.instance "inst_1" @SubModule_0(a: %[[V2]]: i1, b: %[[V1]]: i1) -> (c: i1) + // CHECK-NEXT: %[[V3:.*]] = hw.instance "inst_1" @SubModule_0(a: %[[V2]]: i1, b: %[[V1]]: i1) -> (c: i1) %inst_1.c = moore.instance "inst_1" @SubModule_0(a: %inst_0.c : !moore.l1, b: %arg1 : !moore.l1) -> (c: !moore.l1) -// CHECK-NEXT: hw.output %[[V3]] : i1 + // CHECK-NEXT: hw.output %[[V3]] : i1 moore.output %inst_1.c : !moore.l1 } From edeee079e8f36d7b903bb462e69926c4bdbab801 Mon Sep 17 00:00:00 2001 From: Fabian Schuiki Date: Fri, 9 Aug 2024 11:09:28 -0700 Subject: [PATCH 12/14] Fix FlattenIO pass --- lib/Dialect/HW/Transforms/FlattenIO.cpp | 3 +-- test/Dialect/HW/flatten-io.mlir | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/Dialect/HW/Transforms/FlattenIO.cpp b/lib/Dialect/HW/Transforms/FlattenIO.cpp index d23ef099d195..13954bb88f56 100644 --- a/lib/Dialect/HW/Transforms/FlattenIO.cpp +++ b/lib/Dialect/HW/Transforms/FlattenIO.cpp @@ -171,7 +171,6 @@ class FlattenIOTypeConverter : public TypeConverter { results.push_back(type); else { for (auto field : structType.getElements()) - results.push_back(field.type); } return success(); @@ -187,7 +186,7 @@ class FlattenIOTypeConverter : public TypeConverter { ValueRange inputs, Location loc) { auto structType = getStructType(type); assert(structType && "expected struct type"); - auto result = builder.create(loc, structType, inputs); + auto result = builder.create(loc, type, inputs); return result.getResult(); }); } diff --git a/test/Dialect/HW/flatten-io.mlir b/test/Dialect/HW/flatten-io.mlir index 7273c4d6356e..b76e79fb5f6d 100644 --- a/test/Dialect/HW/flatten-io.mlir +++ b/test/Dialect/HW/flatten-io.mlir @@ -37,11 +37,11 @@ hw.module @level2(in %in : !Struct2, out out: !Struct2) { hw.type_scope @foo { hw.typedecl @bar : !Struct1 } -!ScopedStruct = !hw.typealias<@foo::@bar,!Struct1> +!ScopedStruct = !hw.typealias<@foo::@bar, !Struct1> // BASIC-LABEL: hw.module @scoped(in %arg0 : i32, in %in.a : i1, in %in.b : i2, in %arg1 : i32, out out0 : i32, out out.a : i1, out out.b : i2, out out1 : i32) { -// BASIC-NEXT: %0 = hw.struct_create (%in.a, %in.b) : !hw.struct -// BASIC-NEXT: %a, %b = hw.struct_explode %0 : !hw.struct +// BASIC-NEXT: %0 = hw.struct_create (%in.a, %in.b) : !hw.typealias<@foo::@bar, !hw.struct> +// BASIC-NEXT: %a, %b = hw.struct_explode %0 : !hw.typealias<@foo::@bar, !hw.struct> // BASIC-NEXT: hw.output %arg0, %a, %b, %arg1 : i32, i1, i2, i32 // BASIC-NEXT: } hw.module @scoped(in %arg0 : i32, in %in : !ScopedStruct, in %arg1: i32, out out0 : i32, out out: !ScopedStruct, out out1: i32) { From d1a9b0fd4f794301d7715e89fa81d257931d0e05 Mon Sep 17 00:00:00 2001 From: Fabian Schuiki Date: Fri, 9 Aug 2024 11:14:26 -0700 Subject: [PATCH 13/14] Fix VerifToSMT pass --- test/Conversion/VerifToSMT/verif-to-smt.mlir | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/Conversion/VerifToSMT/verif-to-smt.mlir b/test/Conversion/VerifToSMT/verif-to-smt.mlir index b73dd35520f2..92b828b23c9e 100644 --- a/test/Conversion/VerifToSMT/verif-to-smt.mlir +++ b/test/Conversion/VerifToSMT/verif-to-smt.mlir @@ -11,15 +11,15 @@ func.func @test(%arg0: !smt.bv<1>) -> (i1, i1, i1) { // CHECK: [[EQ:%.+]] = smt.solver() : () -> i1 // CHECK: [[IN0:%.+]] = smt.declare_fun : !smt.bv<32> - // CHECK: [[V0:%.+]] = builtin.unrealized_conversion_cast [[IN0]] : !smt.bv<32> to i32 // CHECK: [[IN1:%.+]] = smt.declare_fun : !smt.bv<32> - // CHECK: [[V1:%.+]] = builtin.unrealized_conversion_cast [[IN1]] : !smt.bv<32> to i32 - // CHECK: [[V2:%.+]]:2 = "some_op"([[V0]], [[V1]]) : (i32, i32) -> (i32, i32) - // CHECK: [[V3:%.+]] = builtin.unrealized_conversion_cast [[V2]]#0 : i32 to !smt.bv<32> - // CHECK: [[V4:%.+]] = smt.distinct [[IN0]], [[V3]] : !smt.bv<32> - // CHECK: [[V5:%.+]] = builtin.unrealized_conversion_cast [[V2]]#1 : i32 to !smt.bv<32> - // CHECK: [[V6:%.+]] = smt.distinct [[IN1]], [[V5]] : !smt.bv<32> - // CHECK: [[V7:%.+]] = smt.or [[V4]], [[V6]] + // CHECK-DAG: [[V0:%.+]] = builtin.unrealized_conversion_cast [[IN0]] : !smt.bv<32> to i32 + // CHECK-DAG: [[V1:%.+]] = builtin.unrealized_conversion_cast [[IN1]] : !smt.bv<32> to i32 + // CHECK-DAG: [[V2:%.+]]:2 = "some_op"([[V0]], [[V1]]) : (i32, i32) -> (i32, i32) + // CHECK-DAG: [[V3:%.+]] = builtin.unrealized_conversion_cast [[V2]]#0 : i32 to !smt.bv<32> + // CHECK-DAG: [[V4:%.+]] = smt.distinct [[IN0]], [[V3]] : !smt.bv<32> + // CHECK-DAG: [[V5:%.+]] = builtin.unrealized_conversion_cast [[V2]]#1 : i32 to !smt.bv<32> + // CHECK-DAG: [[V6:%.+]] = smt.distinct [[IN1]], [[V5]] : !smt.bv<32> + // CHECK-DAG: [[V7:%.+]] = smt.or [[V4]], [[V6]] // CHECK: smt.assert [[V7]] // CHECK: [[FALSE:%.+]] = arith.constant false // CHECK: [[TRUE:%.+]] = arith.constant true From b04d5c4367933d2b9570b87c417cd68cd9e05e8f Mon Sep 17 00:00:00 2001 From: Will Dietz Date: Fri, 9 Aug 2024 17:07:09 -0500 Subject: [PATCH 14/14] Drop unused structtype, per reviewer feedback. Thanks! Co-authored-by: Fabian Schuiki --- lib/Dialect/HW/Transforms/FlattenIO.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/Dialect/HW/Transforms/FlattenIO.cpp b/lib/Dialect/HW/Transforms/FlattenIO.cpp index 13954bb88f56..63e827c46cad 100644 --- a/lib/Dialect/HW/Transforms/FlattenIO.cpp +++ b/lib/Dialect/HW/Transforms/FlattenIO.cpp @@ -184,8 +184,6 @@ class FlattenIOTypeConverter : public TypeConverter { addTargetMaterialization([](OpBuilder &builder, hw::TypeAliasType type, ValueRange inputs, Location loc) { - auto structType = getStructType(type); - assert(structType && "expected struct type"); auto result = builder.create(loc, type, inputs); return result.getResult(); });