diff --git a/include/NeuraDialect/NeuraOps.td b/include/NeuraDialect/NeuraOps.td index 546aa3d2..4ead5f21 100644 --- a/include/NeuraDialect/NeuraOps.td +++ b/include/NeuraDialect/NeuraOps.td @@ -145,7 +145,7 @@ def Neura_LoadOp : Op { // Defines a store operation. def Neura_StoreOp : Op { - let arguments = (ins AnyType:$value, AnyType:$addr); + let arguments = (ins AnyType:$value, Optional:$addr); let results = (outs); // let assemblyFormat = "$value `,` $addr `,` attr-dict"; } @@ -179,11 +179,11 @@ def Neura_StoreIndexedOp: Op { } // Defines a pointer computation operation. -def Neura_GEP : Op { +def Neura_GEP : Op { let summary = "Pointer computation using offset indices"; - let arguments = (ins AnyType:$base, Variadic:$indicesAndPredicate); + let arguments = (ins Optional:$base, Variadic:$indices); let results = (outs AnyType:$result); - // let assemblyFormat = "$base `[` $indicesAndPredicate `]` `,` $predicate attr-dict"; + // let assemblyFormat = "$base `[` $indices `]` `,` $predicate attr-dict"; } // Defines a conditional branch operation. diff --git a/lib/NeuraDialect/Transforms/FusePatternPass.cpp b/lib/NeuraDialect/Transforms/FusePatternPass.cpp index ab47d383..21a19705 100644 --- a/lib/NeuraDialect/Transforms/FusePatternPass.cpp +++ b/lib/NeuraDialect/Transforms/FusePatternPass.cpp @@ -129,7 +129,7 @@ struct FuseGepLoadPattern : public OpRewritePattern { // Creates the fused operation with base and indices from gep. SmallVector indexValues; - for (auto gepIndex : gep_op.getIndicesAndPredicate()) { + for (auto gepIndex : gep_op.getIndices()) { indexValues.push_back(gepIndex); } @@ -161,7 +161,7 @@ struct FuseGepStorePattern : public OpRewritePattern { // Creates the fused operation with base and indices from gep. SmallVector indexValues; - for (auto gepIndex : gep_op.getIndicesAndPredicate()) { + for (auto gepIndex : gep_op.getIndices()) { indexValues.push_back(gepIndex); } diff --git a/lib/NeuraDialect/Transforms/Optimizations/HwAgnosticOpt/FoldConstantPass.cpp b/lib/NeuraDialect/Transforms/Optimizations/HwAgnosticOpt/FoldConstantPass.cpp index 03dc818e..88848a46 100644 --- a/lib/NeuraDialect/Transforms/Optimizations/HwAgnosticOpt/FoldConstantPass.cpp +++ b/lib/NeuraDialect/Transforms/Optimizations/HwAgnosticOpt/FoldConstantPass.cpp @@ -108,12 +108,12 @@ struct FuseRhsConstantPattern : public OpRewritePattern { virtual Operation * createOpWithFusedRhsConstant(OpType op, Value non_const_operand, - Attribute rhs_const_value, + Attribute rhs_value, PatternRewriter &rewriter) const = 0; LogicalResult matchAndRewrite(OpType op, PatternRewriter &rewriter) const override { - if (op->hasAttr("rhs_const_value")) { + if (op->hasAttr("rhs_value")) { // Already fused with a constant on the right-hand side. return failure(); } @@ -127,9 +127,9 @@ struct FuseRhsConstantPattern : public OpRewritePattern { if (rhs_is_const) { auto constant_op = dyn_cast(rhs.getDefiningOp()); - Attribute rhs_const_value = getOriginConstantValue(rhs); + Attribute rhs_value = getOriginConstantValue(rhs); Operation *fused_op = - createOpWithFusedRhsConstant(op, lhs, rhs_const_value, rewriter); + createOpWithFusedRhsConstant(op, lhs, rhs_value, rewriter); rewriter.replaceOp(op, fused_op->getResults()); if (constant_op->use_empty()) { @@ -141,9 +141,9 @@ struct FuseRhsConstantPattern : public OpRewritePattern { if (lhs_is_const && !rhs_is_const && isCommutative()) { auto constant_op = dyn_cast(lhs.getDefiningOp()); - Attribute lhs_const_value = getOriginConstantValue(lhs); + Attribute lhs_value = getOriginConstantValue(lhs); Operation *fused_op = - createOpWithFusedRhsConstant(op, rhs, lhs_const_value, rewriter); + createOpWithFusedRhsConstant(op, rhs, lhs_value, rewriter); rewriter.replaceOp(op, fused_op->getResults()); if (constant_op->use_empty()) { @@ -163,12 +163,12 @@ struct FuseAddRhsConstantPattern : public FuseRhsConstantPattern { Operation * createOpWithFusedRhsConstant(neura::AddOp op, Value non_const_operand, - Attribute rhs_const_value, + Attribute rhs_value, PatternRewriter &rewriter) const override { auto fused_op = rewriter.create( op.getLoc(), op.getResult().getType(), non_const_operand, /*rhs=*/nullptr); - addConstantAttribute(fused_op, "rhs_const_value", rhs_const_value); + addConstantAttribute(fused_op, "rhs_value", rhs_value); return fused_op; } }; @@ -178,12 +178,12 @@ struct FuseSubRhsConstantPattern : public FuseRhsConstantPattern { Operation * createOpWithFusedRhsConstant(neura::SubOp op, Value non_const_operand, - Attribute rhs_const_value, + Attribute rhs_value, PatternRewriter &rewriter) const override { auto fused_op = rewriter.create( op.getLoc(), op.getResult().getType(), non_const_operand, /*rhs=*/nullptr); - addConstantAttribute(fused_op, "rhs_const_value", rhs_const_value); + addConstantAttribute(fused_op, "rhs_value", rhs_value); return fused_op; } }; @@ -195,12 +195,12 @@ struct FuseMulRhsConstantPattern : public FuseRhsConstantPattern { Operation * createOpWithFusedRhsConstant(neura::MulOp op, Value non_const_operand, - Attribute rhs_const_value, + Attribute rhs_value, PatternRewriter &rewriter) const override { auto fused_op = rewriter.create( op.getLoc(), op.getResult().getType(), non_const_operand, /*rhs=*/nullptr); - addConstantAttribute(fused_op, "rhs_const_value", rhs_const_value); + addConstantAttribute(fused_op, "rhs_value", rhs_value); return fused_op; } }; @@ -211,12 +211,12 @@ struct FuseICmpRhsConstantPattern Operation * createOpWithFusedRhsConstant(neura::ICmpOp op, Value non_const_operand, - Attribute rhs_const_value, + Attribute rhs_value, PatternRewriter &rewriter) const override { auto fused_op = rewriter.create( op.getLoc(), op.getResult().getType(), non_const_operand, /*rhs=*/nullptr, op.getCmpType()); - addConstantAttribute(fused_op, "rhs_const_value", rhs_const_value); + addConstantAttribute(fused_op, "rhs_value", rhs_value); return fused_op; } }; @@ -229,12 +229,12 @@ struct FuseFAddRhsConstantPattern Operation * createOpWithFusedRhsConstant(neura::FAddOp op, Value non_const_operand, - Attribute rhs_const_value, + Attribute rhs_value, PatternRewriter &rewriter) const override { auto fused_op = rewriter.create( op.getLoc(), op.getResult().getType(), non_const_operand, /*rhs=*/nullptr); - addConstantAttribute(fused_op, "rhs_const_value", rhs_const_value); + addConstantAttribute(fused_op, "rhs_value", rhs_value); return fused_op; } }; @@ -244,12 +244,12 @@ struct FuseDivRhsConstantPattern : public FuseRhsConstantPattern { Operation * createOpWithFusedRhsConstant(neura::DivOp op, Value non_const_operand, - Attribute rhs_const_value, + Attribute rhs_value, PatternRewriter &rewriter) const override { auto fused_op = rewriter.create( op.getLoc(), op.getResult().getType(), non_const_operand, /*rhs=*/nullptr); - addConstantAttribute(fused_op, "rhs_const_value", rhs_const_value); + addConstantAttribute(fused_op, "rhs_value", rhs_value); return fused_op; } }; @@ -259,16 +259,100 @@ struct FuseRemRhsConstantPattern : public FuseRhsConstantPattern { Operation * createOpWithFusedRhsConstant(neura::RemOp op, Value non_const_operand, - Attribute rhs_const_value, + Attribute rhs_value, PatternRewriter &rewriter) const override { auto fused_op = rewriter.create( op.getLoc(), op.getResult().getType(), non_const_operand, /*rhs=*/nullptr); - addConstantAttribute(fused_op, "rhs_const_value", rhs_const_value); + addConstantAttribute(fused_op, "rhs_value", rhs_value); return fused_op; } }; +// ========================================= +// FuseGepBaseConstantPattern +// Folds constant base pointer for GEP operation. +// ========================================= +struct FuseGepBaseConstantPattern : public OpRewritePattern { + using OpRewritePattern::OpRewritePattern; + + LogicalResult matchAndRewrite(neura::GEP gep_op, + PatternRewriter &rewriter) const override { + Value base = gep_op.getBase(); + + // Checks if base exists and is a constant. + if (!base || !isOriginConstantOp(base)) { + return failure(); + } + + auto constant_op = dyn_cast(base.getDefiningOp()); + Attribute base_value = getOriginConstantValue(base); + + // Gets all indices (everything after base). + SmallVector indices; + for (Value operand : gep_op.getIndices()) { + indices.push_back(operand); + } + + // Creates new GEP with no base but with lhs_value attribute. + auto fused_gep = rewriter.create( + gep_op.getLoc(), + gep_op.getResult().getType(), + /*base=*/nullptr, + indices); + // TODO: Gather all the attribute -- https://github.com/coredac/dataflow/issues/145 + addConstantAttribute(fused_gep, "lhs_value", base_value); + + // Replaces the original GEP. + rewriter.replaceOp(gep_op, fused_gep); + + // Cleans up constant if no longer used. + if (constant_op->use_empty()) { + rewriter.eraseOp(constant_op); + } + + return success(); + } +}; + +// ========================================= +// FuseStoreAddrConstantPattern +// Folds constant destination pointer for Store operation. +// ========================================= +struct FuseStoreAddrConstantPattern : public OpRewritePattern { + using OpRewritePattern::OpRewritePattern; + + LogicalResult matchAndRewrite(neura::StoreOp store_op, + PatternRewriter &rewriter) const override { + Value addr = store_op.getAddr(); + + // Checks if address exists and is a constant. + if (!addr || !isOriginConstantOp(addr)) { + return failure(); + } + + auto constant_op = dyn_cast(addr.getDefiningOp()); + Attribute addr_value = getOriginConstantValue(addr); + + // Creates new Store with no addr but with rhs_value attribute. + auto fused_store = rewriter.create( + store_op.getLoc(), + store_op.getValue(), // Keeps the value operand. + /*addr=*/nullptr); // Removes addr operand. + addConstantAttribute(fused_store, "rhs_value", addr_value); + + // Replaces the original Store. + rewriter.replaceOp(store_op, fused_store); + + // Cleans up constant if no longer used. + if (constant_op->use_empty()) { + rewriter.eraseOp(constant_op); + } + + return success(); + } +}; + // ========================================= // FoldConstantPass Implementation // ========================================= @@ -294,6 +378,8 @@ struct FoldConstantPass patterns.add(&getContext()); patterns.add(&getContext()); + patterns.add(&getContext()); + patterns.add(&getContext()); FrozenRewritePatternSet frozen(std::move(patterns)); // Applies to every region inside the module (regardless of func type, diff --git a/lib/NeuraDialect/Transforms/Optimizations/HwSpecificOpt/FuseLoopControlPass.cpp b/lib/NeuraDialect/Transforms/Optimizations/HwSpecificOpt/FuseLoopControlPass.cpp index 96fb2ab7..2d83679b 100644 --- a/lib/NeuraDialect/Transforms/Optimizations/HwSpecificOpt/FuseLoopControlPass.cpp +++ b/lib/NeuraDialect/Transforms/Optimizations/HwSpecificOpt/FuseLoopControlPass.cpp @@ -106,8 +106,8 @@ class LoopInfo { // Finds the constant attribute for a value. Attribute findConstantAttribute(Operation *op) { // Checks if the operation has a constant attribute. - if (op && op->hasAttr("rhs_const_value")) { - return op->getAttr("rhs_const_value"); + if (op && op->hasAttr("rhs_value")) { + return op->getAttr("rhs_value"); } // If the value is already a constant, return it. diff --git a/test/c2llvm2mlir/simple_loop/test.mlir b/test/c2llvm2mlir/simple_loop/test.mlir index fb0bbb78..908ff439 100644 --- a/test/c2llvm2mlir/simple_loop/test.mlir +++ b/test/c2llvm2mlir/simple_loop/test.mlir @@ -1,7 +1,7 @@ // Compiles the original kernel. // RUN: clang++ kernel.cpp -o %t-kernel.out -// Compiles the original kernel to mlir, then lower back to llvm, eventually binary. +// Compiles the original kernel to mlir, then lowers back to llvm, eventually binary. // RUN: clang++ -S -emit-llvm -o %t-kernel.ll kernel.cpp // RUN: mlir-translate --import-llvm %t-kernel.ll -o %t-kernel.mlir // RUN: mlir-opt %t-kernel.mlir | mlir-translate -mlir-to-llvmir -o %t-kernel_back.ll @@ -15,3 +15,56 @@ // Verifies the output values are the same for the original and re-compiled kernel. // CHECK: output: [[OUTPUT:[0-9]+\.[0-9]+]] // CHECK: output: [[OUTPUT]] + +// Tests LLVM to NEURA lowering. +// RUN: clang++ -S -emit-llvm -O3 -fno-unroll-loops -fno-vectorize -ffp-contract=off kernel.cpp -o %t-kernel.ll +// RUN: mlir-translate --import-llvm %t-kernel.ll -o %t-kernel.mlir + +// RUN: mlir-neura-opt --assign-accelerator \ +// RUN: --lower-llvm-to-neura \ +// RUN: --promote-func-arg-to-const \ +// RUN: --fold-constant \ +// RUN: --canonicalize-live-in \ +// RUN: --leverage-predicated-value \ +// RUN: --transform-ctrl-to-data-flow \ +// RUN: --view-op-graph \ +// RUN: --architecture-spec=../../arch_spec/architecture.yaml \ +// RUN: --insert-data-mov %t-kernel.mlir -o %t-kernel-neura.mlir +// RUN: FileCheck %s --check-prefix=CHECK-LLVM2NEURA < %t-kernel-neura.mlir + +// RUN: mlir-neura-opt --assign-accelerator \ +// RUN: --lower-llvm-to-neura \ +// RUN: --promote-func-arg-to-const \ +// RUN: --fold-constant \ +// RUN: --canonicalize-live-in \ +// RUN: --leverage-predicated-value \ +// RUN: --transform-ctrl-to-data-flow \ +// RUN: --view-op-graph \ +// RUN: --architecture-spec=../../arch_spec/architecture.yaml \ +// RUN: --insert-data-mov \ +// RUN: --map-to-accelerator="mapping-strategy=heuristic backtrack-config=customized=5,3" %t-kernel.mlir -o %t-kernel-mapped.mlir +// RUN: FileCheck %s --check-prefix=CHECK-LLVM2NEURA-MAP < %t-kernel-mapped.mlir + +// CHECK-LLVM2NEURA: accelerator = "neura" +// CHECK-LLVM2NEURA: dataflow_mode = "predicate" +// CHECK-LLVM2NEURA: neura.phi +// CHECK-LLVM2NEURA: neura.gep +// CHECK-LLVM2NEURA-SAME: operandSegmentSizes = array +// CHECK-LLVM2NEURA-SAME: lhs_value +// CHECK-LLVM2NEURA: neura.load +// CHECK-LLVM2NEURA: neura.fmul +// CHECK-LLVM2NEURA: neura.fadd +// CHECK-LLVM2NEURA: neura.store +// CHECK-LLVM2NEURA-SAME: rhs_value + +// CHECK-LLVM2NEURA-MAP: func.func @ +// CHECK-LLVM2NEURA-MAP-SAME: accelerator = "neura" +// CHECK-LLVM2NEURA-MAP-SAME: dataflow_mode = "predicate" +// CHECK-LLVM2NEURA-MAP-SAME: mapping_info = { +// CHECK-LLVM2NEURA-MAP-SAME: compiled_ii = 5 : i32, +// CHECK-LLVM2NEURA-MAP-SAME: mapping_mode = "spatial-temporal" +// CHECK-LLVM2NEURA-MAP-SAME: mapping_strategy = "heuristic" +// CHECK-LLVM2NEURA-MAP-SAME: rec_mii = 5 : i32 +// CHECK-LLVM2NEURA-MAP-SAME: res_mii = 2 : i32 +// CHECK-LLVM2NEURA-MAP-SAME: x_tiles = 4 : i32 +// CHECK-LLVM2NEURA-MAP-SAME: y_tiles = 4 : i32} \ No newline at end of file diff --git a/test/controflow_fuse/simple_loop/simple_loop.mlir b/test/controflow_fuse/simple_loop/simple_loop.mlir index a136f9a7..a05ad8a9 100644 --- a/test/controflow_fuse/simple_loop/simple_loop.mlir +++ b/test/controflow_fuse/simple_loop/simple_loop.mlir @@ -196,8 +196,8 @@ module attributes {} { // FUSE-NEXT: %7 = neura.grant_predicate %5, %valid : !neura.data, i1>, !neura.data -> !neura.data, i1> // FUSE-NEXT: %8 = neura.grant_predicate %3, %valid : !neura.data, i1>, !neura.data -> !neura.data, i1> // FUSE-NEXT: %9 = neura.load_indexed %7[%nextindex : !neura.data] !neura.data, i1> : !neura.data -// FUSE-NEXT: %10 = "neura.mul"(%9) {rhs_const_value = 2 : i32} : (!neura.data) -> !neura.data -// FUSE-NEXT: %11 = "neura.add"(%10) {rhs_const_value = 1 : i32} : (!neura.data) -> !neura.data +// FUSE-NEXT: %10 = "neura.mul"(%9) {rhs_value = 2 : i32} : (!neura.data) -> !neura.data +// FUSE-NEXT: %11 = "neura.add"(%10) {rhs_value = 1 : i32} : (!neura.data) -> !neura.data // FUSE-NEXT: neura.store_indexed %11 to %8[%nextindex : !neura.data] !neura.data, i1> : !neura.data // FUSE-NEXT: neura.ctrl_mov %7 -> %4 : !neura.data, i1> !neura.data, i1> // FUSE-NEXT: neura.ctrl_mov %8 -> %2 : !neura.data, i1> !neura.data, i1> diff --git a/test/mapping_quality/branch_for.mlir b/test/mapping_quality/branch_for.mlir index f2dd20dc..05349589 100644 --- a/test/mapping_quality/branch_for.mlir +++ b/test/mapping_quality/branch_for.mlir @@ -109,9 +109,9 @@ func.func @loop_test() -> f32 { // CANONICALIZE-NEXT: %1 = "neura.constant"() <{value = 0.000000e+00 : f32}> : () -> f32 // CANONICALIZE-NEXT: neura.br %0, %1 : i64, f32 to ^bb1 // CANONICALIZE-NEXT: ^bb1(%2: i64, %3: f32): // 2 preds: ^bb0, ^bb1 -// CANONICALIZE-NEXT: %4 = "neura.fadd"(%3) {rhs_const_value = 3.000000e+00 : f32} : (f32) -> f32 -// CANONICALIZE-NEXT: %5 = "neura.add"(%2) {rhs_const_value = 1 : i64} : (i64) -> i64 -// CANONICALIZE-NEXT: %6 = "neura.icmp"(%5) <{cmpType = "slt"}> {rhs_const_value = 10 : i64} : (i64) -> i1 +// CANONICALIZE-NEXT: %4 = "neura.fadd"(%3) {rhs_value = 3.000000e+00 : f32} : (f32) -> f32 +// CANONICALIZE-NEXT: %5 = "neura.add"(%2) {rhs_value = 1 : i64} : (i64) -> i64 +// CANONICALIZE-NEXT: %6 = "neura.icmp"(%5) <{cmpType = "slt"}> {rhs_value = 10 : i64} : (i64) -> i1 // CANONICALIZE-NEXT: neura.cond_br %6 : i1 then %5, %4 : i64, f32 to ^bb1 else %4 : f32 to ^bb2 // CANONICALIZE-NEXT: ^bb2(%7: f32): // pred: ^bb1 // CANONICALIZE-NEXT: "neura.return"(%7) : (f32) -> () @@ -126,9 +126,9 @@ func.func @loop_test() -> f32 { // CTRL2DATA-NEXT: %5 = "neura.phi"(%4, %3) : (!neura.data, !neura.data) -> !neura.data // CTRL2DATA-NEXT: %6 = neura.reserve : !neura.data // CTRL2DATA-NEXT: %7 = "neura.phi"(%6, %1) : (!neura.data, !neura.data) -> !neura.data -// CTRL2DATA-NEXT: %8 = "neura.fadd"(%5) {rhs_const_value = 3.000000e+00 : f32} : (!neura.data) -> !neura.data -// CTRL2DATA-NEXT: %9 = "neura.add"(%7) {rhs_const_value = 1 : i64} : (!neura.data) -> !neura.data -// CTRL2DATA-NEXT: %10 = "neura.icmp"(%9) <{cmpType = "slt"}> {rhs_const_value = 10 : i64} : (!neura.data) -> !neura.data +// CTRL2DATA-NEXT: %8 = "neura.fadd"(%5) {rhs_value = 3.000000e+00 : f32} : (!neura.data) -> !neura.data +// CTRL2DATA-NEXT: %9 = "neura.add"(%7) {rhs_value = 1 : i64} : (!neura.data) -> !neura.data +// CTRL2DATA-NEXT: %10 = "neura.icmp"(%9) <{cmpType = "slt"}> {rhs_value = 10 : i64} : (!neura.data) -> !neura.data // CTRL2DATA-NEXT: %11 = neura.grant_predicate %9, %10 : !neura.data, !neura.data -> !neura.data // CTRL2DATA-NEXT: neura.ctrl_mov %11 -> %6 : !neura.data !neura.data // CTRL2DATA-NEXT: %12 = neura.grant_predicate %8, %10 : !neura.data, !neura.data -> !neura.data @@ -145,9 +145,9 @@ func.func @loop_test() -> f32 { // FUSE-NEXT: %3 = "neura.phi"(%2, %1) : (!neura.data, !neura.data) -> !neura.data // FUSE-NEXT: %4 = neura.reserve : !neura.data // FUSE-NEXT: %5 = "neura.phi"(%4, %0) : (!neura.data, !neura.data) -> !neura.data -// FUSE-NEXT: %6 = "neura.fadd"(%3) {rhs_const_value = 3.000000e+00 : f32} : (!neura.data) -> !neura.data -// FUSE-NEXT: %7 = "neura.add"(%5) {rhs_const_value = 1 : i64} : (!neura.data) -> !neura.data -// FUSE-NEXT: %8 = "neura.icmp"(%7) <{cmpType = "slt"}> {rhs_const_value = 10 : i64} : (!neura.data) -> !neura.data +// FUSE-NEXT: %6 = "neura.fadd"(%3) {rhs_value = 3.000000e+00 : f32} : (!neura.data) -> !neura.data +// FUSE-NEXT: %7 = "neura.add"(%5) {rhs_value = 1 : i64} : (!neura.data) -> !neura.data +// FUSE-NEXT: %8 = "neura.icmp"(%7) <{cmpType = "slt"}> {rhs_value = 10 : i64} : (!neura.data) -> !neura.data // FUSE-NEXT: %9 = neura.grant_predicate %7, %8 : !neura.data, !neura.data -> !neura.data // FUSE-NEXT: neura.ctrl_mov %9 -> %4 : !neura.data !neura.data // FUSE-NEXT: %10 = neura.grant_predicate %6, %8 : !neura.data, !neura.data -> !neura.data @@ -167,11 +167,11 @@ func.func @loop_test() -> f32 { // MOV-NEXT: %6 = "neura.data_mov"(%0) : (!neura.data) -> !neura.data // MOV-NEXT: %7 = "neura.phi"(%5, %6) : (!neura.data, !neura.data) -> !neura.data // MOV-NEXT: %8 = "neura.data_mov"(%4) : (!neura.data) -> !neura.data -// MOV-NEXT: %9 = "neura.fadd"(%8) {rhs_const_value = 3.000000e+00 : f32} : (!neura.data) -> !neura.data +// MOV-NEXT: %9 = "neura.fadd"(%8) {rhs_value = 3.000000e+00 : f32} : (!neura.data) -> !neura.data // MOV-NEXT: %10 = "neura.data_mov"(%7) : (!neura.data) -> !neura.data -// MOV-NEXT: %11 = "neura.add"(%10) {rhs_const_value = 1 : i64} : (!neura.data) -> !neura.data +// MOV-NEXT: %11 = "neura.add"(%10) {rhs_value = 1 : i64} : (!neura.data) -> !neura.data // MOV-NEXT: %12 = "neura.data_mov"(%11) : (!neura.data) -> !neura.data -// MOV-NEXT: %13 = "neura.icmp"(%12) <{cmpType = "slt"}> {rhs_const_value = 10 : i64} : (!neura.data) -> !neura.data +// MOV-NEXT: %13 = "neura.icmp"(%12) <{cmpType = "slt"}> {rhs_value = 10 : i64} : (!neura.data) -> !neura.data // MOV-NEXT: %14 = "neura.data_mov"(%11) : (!neura.data) -> !neura.data // MOV-NEXT: %15 = "neura.data_mov"(%13) : (!neura.data) -> !neura.data // MOV-NEXT: %16 = neura.grant_predicate %14, %15 : !neura.data, !neura.data -> !neura.data diff --git a/test/neura/ctrl/branch_for.mlir b/test/neura/ctrl/branch_for.mlir index 958777f8..40837e08 100644 --- a/test/neura/ctrl/branch_for.mlir +++ b/test/neura/ctrl/branch_for.mlir @@ -115,9 +115,9 @@ func.func @loop_test() -> f32 { // CANONICALIZE-NEXT: %1 = "neura.constant"() <{value = 0.000000e+00 : f32}> : () -> f32 // CANONICALIZE-NEXT: neura.br %0, %1 : i64, f32 to ^bb1 // CANONICALIZE-NEXT: ^bb1(%2: i64, %3: f32): // 2 preds: ^bb0, ^bb1 -// CANONICALIZE-NEXT: %4 = "neura.fadd"(%3) {rhs_const_value = 3.000000e+00 : f32} : (f32) -> f32 -// CANONICALIZE-NEXT: %5 = "neura.add"(%2) {rhs_const_value = 1 : i64} : (i64) -> i64 -// CANONICALIZE-NEXT: %6 = "neura.icmp"(%5) <{cmpType = "slt"}> {rhs_const_value = 10 : i64} : (i64) -> i1 +// CANONICALIZE-NEXT: %4 = "neura.fadd"(%3) {rhs_value = 3.000000e+00 : f32} : (f32) -> f32 +// CANONICALIZE-NEXT: %5 = "neura.add"(%2) {rhs_value = 1 : i64} : (i64) -> i64 +// CANONICALIZE-NEXT: %6 = "neura.icmp"(%5) <{cmpType = "slt"}> {rhs_value = 10 : i64} : (i64) -> i1 // CANONICALIZE-NEXT: neura.cond_br %6 : i1 then %5, %4 : i64, f32 to ^bb1 else %4 : f32 to ^bb2 // CANONICALIZE-NEXT: ^bb2(%7: f32): // pred: ^bb1 // CANONICALIZE-NEXT: "neura.return"(%7) : (f32) -> () @@ -132,9 +132,9 @@ func.func @loop_test() -> f32 { // CTRL2DATA-NEXT: %5 = "neura.phi"(%4, %3) : (!neura.data, !neura.data) -> !neura.data // CTRL2DATA-NEXT: %6 = neura.reserve : !neura.data // CTRL2DATA-NEXT: %7 = "neura.phi"(%6, %1) : (!neura.data, !neura.data) -> !neura.data -// CTRL2DATA-NEXT: %8 = "neura.fadd"(%5) {rhs_const_value = 3.000000e+00 : f32} : (!neura.data) -> !neura.data -// CTRL2DATA-NEXT: %9 = "neura.add"(%7) {rhs_const_value = 1 : i64} : (!neura.data) -> !neura.data -// CTRL2DATA-NEXT: %10 = "neura.icmp"(%9) <{cmpType = "slt"}> {rhs_const_value = 10 : i64} : (!neura.data) -> !neura.data +// CTRL2DATA-NEXT: %8 = "neura.fadd"(%5) {rhs_value = 3.000000e+00 : f32} : (!neura.data) -> !neura.data +// CTRL2DATA-NEXT: %9 = "neura.add"(%7) {rhs_value = 1 : i64} : (!neura.data) -> !neura.data +// CTRL2DATA-NEXT: %10 = "neura.icmp"(%9) <{cmpType = "slt"}> {rhs_value = 10 : i64} : (!neura.data) -> !neura.data // CTRL2DATA-NEXT: %11 = neura.grant_predicate %9, %10 : !neura.data, !neura.data -> !neura.data // CTRL2DATA-NEXT: neura.ctrl_mov %11 -> %6 : !neura.data !neura.data // CTRL2DATA-NEXT: %12 = neura.grant_predicate %8, %10 : !neura.data, !neura.data -> !neura.data @@ -151,9 +151,9 @@ func.func @loop_test() -> f32 { // FUSE-NEXT: %3 = "neura.phi"(%2, %1) : (!neura.data, !neura.data) -> !neura.data // FUSE-NEXT: %4 = neura.reserve : !neura.data // FUSE-NEXT: %5 = "neura.phi"(%4, %0) : (!neura.data, !neura.data) -> !neura.data -// FUSE-NEXT: %6 = "neura.fadd"(%3) {rhs_const_value = 3.000000e+00 : f32} : (!neura.data) -> !neura.data -// FUSE-NEXT: %7 = "neura.add"(%5) {rhs_const_value = 1 : i64} : (!neura.data) -> !neura.data -// FUSE-NEXT: %8 = "neura.icmp"(%7) <{cmpType = "slt"}> {rhs_const_value = 10 : i64} : (!neura.data) -> !neura.data +// FUSE-NEXT: %6 = "neura.fadd"(%3) {rhs_value = 3.000000e+00 : f32} : (!neura.data) -> !neura.data +// FUSE-NEXT: %7 = "neura.add"(%5) {rhs_value = 1 : i64} : (!neura.data) -> !neura.data +// FUSE-NEXT: %8 = "neura.icmp"(%7) <{cmpType = "slt"}> {rhs_value = 10 : i64} : (!neura.data) -> !neura.data // FUSE-NEXT: %9 = neura.grant_predicate %7, %8 : !neura.data, !neura.data -> !neura.data // FUSE-NEXT: neura.ctrl_mov %9 -> %4 : !neura.data !neura.data // FUSE-NEXT: %10 = neura.grant_predicate %6, %8 : !neura.data, !neura.data -> !neura.data @@ -173,11 +173,11 @@ func.func @loop_test() -> f32 { // MOV-NEXT: %6 = "neura.data_mov"(%0) : (!neura.data) -> !neura.data // MOV-NEXT: %7 = "neura.phi"(%5, %6) : (!neura.data, !neura.data) -> !neura.data // MOV-NEXT: %8 = "neura.data_mov"(%4) : (!neura.data) -> !neura.data -// MOV-NEXT: %9 = "neura.fadd"(%8) {rhs_const_value = 3.000000e+00 : f32} : (!neura.data) -> !neura.data +// MOV-NEXT: %9 = "neura.fadd"(%8) {rhs_value = 3.000000e+00 : f32} : (!neura.data) -> !neura.data // MOV-NEXT: %10 = "neura.data_mov"(%7) : (!neura.data) -> !neura.data -// MOV-NEXT: %11 = "neura.add"(%10) {rhs_const_value = 1 : i64} : (!neura.data) -> !neura.data +// MOV-NEXT: %11 = "neura.add"(%10) {rhs_value = 1 : i64} : (!neura.data) -> !neura.data // MOV-NEXT: %12 = "neura.data_mov"(%11) : (!neura.data) -> !neura.data -// MOV-NEXT: %13 = "neura.icmp"(%12) <{cmpType = "slt"}> {rhs_const_value = 10 : i64} : (!neura.data) -> !neura.data +// MOV-NEXT: %13 = "neura.icmp"(%12) <{cmpType = "slt"}> {rhs_value = 10 : i64} : (!neura.data) -> !neura.data // MOV-NEXT: %14 = "neura.data_mov"(%11) : (!neura.data) -> !neura.data // MOV-NEXT: %15 = "neura.data_mov"(%13) : (!neura.data) -> !neura.data // MOV-NEXT: %16 = neura.grant_predicate %14, %15 : !neura.data, !neura.data -> !neura.data diff --git a/test/neura/for_loop/kernel_test.mlir b/test/neura/for_loop/kernel_test.mlir index 0c443ea1..2dd9ca74 100644 --- a/test/neura/for_loop/kernel_test.mlir +++ b/test/neura/for_loop/kernel_test.mlir @@ -46,9 +46,9 @@ // CHECK-NEXT: %6 = "neura.load"(%1) : (!neura.data) -> !neura.data // CHECK-NEXT: neura.br %3, %6, %0, %2, %1, %4, %5 : !neura.data, !neura.data, !neura.data, !neura.data, !neura.data, !neura.data, !neura.data to ^bb1 // CHECK-NEXT: ^bb1(%7: !neura.data, %8: !neura.data, %9: !neura.data, %10: !neura.data, %11: !neura.data, %12: !neura.data, %13: !neura.data): // 2 preds: ^bb0, ^bb1 -// CHECK-NEXT: %14 = "neura.gep"(%9, %7) : (!neura.data, !neura.data) -> !neura.data +// CHECK-NEXT: %14 = "neura.gep"(%9, %7) <{operandSegmentSizes = array}> : (!neura.data, !neura.data) -> !neura.data // CHECK-NEXT: %15 = "neura.load"(%14) : (!neura.data) -> !neura.data -// CHECK-NEXT: %16 = "neura.gep"(%10, %7) : (!neura.data, !neura.data) -> !neura.data +// CHECK-NEXT: %16 = "neura.gep"(%10, %7) <{operandSegmentSizes = array}> : (!neura.data, !neura.data) -> !neura.data // CHECK-NEXT: %17 = "neura.load"(%16) : (!neura.data) -> !neura.data // CHECK-NEXT: %18 = "neura.fmul"(%15, %17) : (!neura.data, !neura.data) -> !neura.data // CHECK-NEXT: %19 = "neura.fadd"(%8, %18) : (!neura.data, !neura.data) -> !neura.data diff --git a/test/neura/for_loop/relu_test.mlir b/test/neura/for_loop/relu_test.mlir index 43a01992..193931b5 100644 --- a/test/neura/for_loop/relu_test.mlir +++ b/test/neura/for_loop/relu_test.mlir @@ -30,12 +30,12 @@ // CHECK-NEXT: ^bb1: // pred: ^bb4 // CHECK-NEXT: "neura.return"() : () -> () // CHECK-NEXT: ^bb2(%6: i64, %7: !llvm.ptr, %8: i32, %9: !llvm.ptr, %10: i64, %11: i64): // 2 preds: ^bb0, ^bb4 -// CHECK-NEXT: %12 = "neura.gep"(%7, %6) : (!llvm.ptr, i64) -> !llvm.ptr +// CHECK-NEXT: %12 = "neura.gep"(%7, %6) <{operandSegmentSizes = array}> : (!llvm.ptr, i64) -> !llvm.ptr // CHECK-NEXT: %13 = "neura.load"(%12) : (!llvm.ptr) -> i32 // CHECK-NEXT: %14 = "neura.icmp"(%13, %8) <{cmpType = "sgt"}> : (i32, i32) -> i1 // CHECK-NEXT: neura.cond_br %14 : i1 then %9, %6, %13, %10, %11, %7, %8 : !llvm.ptr, i64, i32, i64, i64, !llvm.ptr, i32 to ^bb3 else %6, %10, %11, %7, %8, %9 : i64, i64, i64, !llvm.ptr, i32, !llvm.ptr to ^bb4 // CHECK-NEXT: ^bb3(%15: !llvm.ptr, %16: i64, %17: i32, %18: i64, %19: i64, %20: !llvm.ptr, %21: i32): // pred: ^bb2 -// CHECK-NEXT: %22 = "neura.gep"(%15, %16) : (!llvm.ptr, i64) -> !llvm.ptr +// CHECK-NEXT: %22 = "neura.gep"(%15, %16) <{operandSegmentSizes = array}> : (!llvm.ptr, i64) -> !llvm.ptr // CHECK-NEXT: %23 = "neura.load"(%22) : (!llvm.ptr) -> i32 // CHECK-NEXT: %24 = "neura.add"(%23, %17) : (i32, i32) -> i32 // CHECK-NEXT: "neura.store"(%24, %22) : (i32, !llvm.ptr) -> () @@ -73,7 +73,7 @@ // CTRL2DATA-NEXT: %21 = "neura.phi"(%20, %1) : (!neura.data, !neura.data) -> !neura.data // CTRL2DATA-NEXT: %22 = neura.reserve : !neura.data // CTRL2DATA-NEXT: %23 = "neura.phi"(%22, %5) : (!neura.data, !neura.data) -> !neura.data -// CTRL2DATA-NEXT: %24 = "neura.gep"(%21, %23) : (!neura.data, !neura.data) -> !neura.data +// CTRL2DATA-NEXT: %24 = "neura.gep"(%21, %23) <{operandSegmentSizes = array}> : (!neura.data, !neura.data) -> !neura.data // CTRL2DATA-NEXT: %25 = "neura.load"(%24) : (!neura.data) -> !neura.data // CTRL2DATA-NEXT: %26 = "neura.icmp"(%25, %19) <{cmpType = "sgt"}> : (!neura.data, !neura.data) -> !neura.data // CTRL2DATA-NEXT: %27 = neura.grant_predicate %17, %26 : !neura.data, !neura.data -> !neura.data @@ -90,7 +90,7 @@ // CTRL2DATA-NEXT: %38 = neura.grant_predicate %21, %34 : !neura.data, !neura.data -> !neura.data // CTRL2DATA-NEXT: %39 = neura.grant_predicate %19, %34 : !neura.data, !neura.data -> !neura.data // CTRL2DATA-NEXT: %40 = neura.grant_predicate %17, %34 : !neura.data, !neura.data -> !neura.data -// CTRL2DATA-NEXT: %41 = "neura.gep"(%27, %28) : (!neura.data, !neura.data) -> !neura.data +// CTRL2DATA-NEXT: %41 = "neura.gep"(%27, %28) <{operandSegmentSizes = array}> : (!neura.data, !neura.data) -> !neura.data // CTRL2DATA-NEXT: %42 = "neura.load"(%41) : (!neura.data) -> !neura.data // CTRL2DATA-NEXT: %43 = "neura.add"(%42, %29) : (!neura.data, !neura.data) -> !neura.data // CTRL2DATA-NEXT: "neura.store"(%43, %41) : (!neura.data, !neura.data) -> () diff --git a/test/neura/interpreter/basic_operation/gep.mlir b/test/neura/interpreter/basic_operation/gep.mlir index 465b0a68..c60a799c 100644 --- a/test/neura/interpreter/basic_operation/gep.mlir +++ b/test/neura/interpreter/basic_operation/gep.mlir @@ -3,7 +3,7 @@ func.func @test_gep_simple() -> i32 { %base = arith.constant 0 : i32 %idx = arith.constant 2 : i32 - %gep = "neura.gep"(%base, %idx) { strides = [4] } : (i32, i32) -> i32 + %gep = "neura.gep"(%base, %idx) <{operandSegmentSizes = array}> {strides = [4]} : (i32, i32) -> i32 // CHECK: [neura-interpreter] └─ Final GEP result: base = 0, total offset = 8, final address = 8, [pred = 1] return %gep : i32 diff --git a/test/optimization/constant_folding/simple_loop.mlir b/test/optimization/constant_folding/simple_loop.mlir index d8027b28..19aa172e 100644 --- a/test/optimization/constant_folding/simple_loop.mlir +++ b/test/optimization/constant_folding/simple_loop.mlir @@ -33,14 +33,14 @@ module { // FOLD-NEXT: %2 = "neura.constant"() <{value = 0 : i64}> : () -> i64 // FOLD-NEXT: neura.br %2 : i64 to ^bb1 // FOLD-NEXT: ^bb1(%3: i64): // 2 preds: ^bb0, ^bb2 -// FOLD-NEXT: %4 = "neura.icmp"(%3) <{cmpType = "slt"}> {rhs_const_value = 128 : i64} : (i64) -> i1 +// FOLD-NEXT: %4 = "neura.icmp"(%3) <{cmpType = "slt"}> {rhs_value = 128 : i64} : (i64) -> i1 // FOLD-NEXT: neura.cond_br %4 : i1 then to ^bb2 else to ^bb3 // FOLD-NEXT: ^bb2: // pred: ^bb1 // FOLD-NEXT: %5 = neura.load_indexed %0[%3 : i64] memref : i32 -// FOLD-NEXT: %6 = "neura.mul"(%5) {rhs_const_value = 2 : i32} : (i32) -> i32 -// FOLD-NEXT: %7 = "neura.add"(%5) {rhs_const_value = 1 : i32} : (i32) -> i32 +// FOLD-NEXT: %6 = "neura.mul"(%5) {rhs_value = 2 : i32} : (i32) -> i32 +// FOLD-NEXT: %7 = "neura.add"(%5) {rhs_value = 1 : i32} : (i32) -> i32 // FOLD-NEXT: neura.store_indexed %7 to %1[%3 : i64] memref : i32 -// FOLD-NEXT: %8 = "neura.add"(%3) {rhs_const_value = 1 : i64} : (i64) -> i64 +// FOLD-NEXT: %8 = "neura.add"(%3) {rhs_value = 1 : i64} : (i64) -> i64 // FOLD-NEXT: neura.br %8 : i64 to ^bb1 // FOLD-NEXT: ^bb3: // pred: ^bb1 // FOLD-NEXT: "neura.return"() : () -> () diff --git a/test/visualize/test2.mlir b/test/visualize/test2.mlir index 7a152997..fbdb21b7 100644 --- a/test/visualize/test2.mlir +++ b/test/visualize/test2.mlir @@ -17,9 +17,9 @@ func.func @test_print_op_graph(%a: f32, %b: f32) -> f32 { // CHECK-GRAPH: digraph G // CHECK-GRAPH: label = "func.func : ()\n\naccelerator: \"neura\"\nfunction_type: (f32, f32) -> f32\nsym_name: \"test_print_op_graph..."; // CHECK-GRAPH: label = "neura.constant : (!neura.data)\n\nvalue: \"%arg0\"", shape = ellipse, style = filled]; -// CHECK-GRAPH: label = "neura.fadd : (!neura.data)\n\nrhs_const_value: \"%arg1\"", shape = ellipse, style = filled]; +// CHECK-GRAPH: label = "neura.fadd : (!neura.data)\n\nrhs_value: \"%arg1\"", shape = ellipse, style = filled]; // CHECK-GRAPH: digraph G // CHECK-GRAPH: label = "func.func : ()\n\naccelerator: \"neura\"\ndataflow_mode: \"predicate\"\nfunction_type: (f32, f32) -> f32\nsym_name: \"test_print_op_graph..."; // CHECK-GRAPH: label = "neura.constant : (!neura.data)\n\nvalue: \"%arg0\"", shape = ellipse, style = filled]; // CHECK-GRAPH: label = "neura.data_mov : (!neura.data) -// CHECK-GRAPH: label = "neura.fadd : (!neura.data)\n\nrhs_const_value: \"%arg1\"", shape = ellipse, style = filled]; +// CHECK-GRAPH: label = "neura.fadd : (!neura.data)\n\nrhs_value: \"%arg1\"", shape = ellipse, style = filled];