From a2fb5b2bd932043fa2ccc9f99c5af7efc7729ebb Mon Sep 17 00:00:00 2001 From: tangyz <739245980@qq.com> Date: Thu, 16 Oct 2025 13:14:58 +0800 Subject: [PATCH 1/5] add const_args to --fold-constant PASS --- include/NeuraDialect/NeuraOps.td | 6 +- .../HwAgnosticOpt/FoldConstantPass.cpp | 85 +++++++++++++++++++ test/c2llvm2mlir/simple_loop/test.mlir | 39 +++++++++ 3 files changed, 127 insertions(+), 3 deletions(-) diff --git a/include/NeuraDialect/NeuraOps.td b/include/NeuraDialect/NeuraOps.td index 546aa3d2..73654ca2 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,9 +179,9 @@ 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:$indicesAndPredicate); let results = (outs AnyType:$result); // let assemblyFormat = "$base `[` $indicesAndPredicate `]` `,` $predicate attr-dict"; } diff --git a/lib/NeuraDialect/Transforms/Optimizations/HwAgnosticOpt/FoldConstantPass.cpp b/lib/NeuraDialect/Transforms/Optimizations/HwAgnosticOpt/FoldConstantPass.cpp index 03dc818e..adb73a47 100644 --- a/lib/NeuraDialect/Transforms/Optimizations/HwAgnosticOpt/FoldConstantPass.cpp +++ b/lib/NeuraDialect/Transforms/Optimizations/HwAgnosticOpt/FoldConstantPass.cpp @@ -269,6 +269,89 @@ struct FuseRemRhsConstantPattern : public FuseRhsConstantPattern { } }; +// ========================================= +// FuseGepBaseConstantPattern +// Fold 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(); + + // Check if base exists and is a constant + if (!base || !isOriginConstantOp(base)) { + return failure(); + } + + auto constant_op = dyn_cast(base.getDefiningOp()); + Attribute base_const_value = getOriginConstantValue(base); + + // Get all indices (everything after base) + SmallVector indices; + for (Value operand : gep_op.getIndicesAndPredicate()) { + indices.push_back(operand); + } + + // Create new GEP with no base but with const_base_ptr attribute + auto fused_gep = rewriter.create( + gep_op.getLoc(), + gep_op.getResult().getType(), + /*base=*/nullptr, + indices); + addConstantAttribute(fused_gep, "const_base_ptr", base_const_value); + + // Replace the original GEP + rewriter.replaceOp(gep_op, fused_gep); + + // Clean up constant if no longer used + if (constant_op->use_empty()) { + rewriter.eraseOp(constant_op); + } + + return success(); + } +}; + +// ========================================= +// FuseStoreAddrConstantPattern +// Fold 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(); + + // Check if address exists and is a constant + if (!addr || !isOriginConstantOp(addr)) { + return failure(); + } + + auto constant_op = dyn_cast(addr.getDefiningOp()); + Attribute addr_const_value = getOriginConstantValue(addr); + + // Create new Store with no addr but with const_dst_ptr attribute + auto fused_store = rewriter.create( + store_op.getLoc(), + store_op.getValue(), // Keep the value operand + /*addr=*/nullptr); // Remove addr operand + addConstantAttribute(fused_store, "const_dst_ptr", addr_const_value); + + // Replace the original Store + rewriter.replaceOp(store_op, fused_store); + + // Clean up constant if no longer used + if (constant_op->use_empty()) { + rewriter.eraseOp(constant_op); + } + + return success(); + } +}; + // ========================================= // FoldConstantPass Implementation // ========================================= @@ -294,6 +377,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/test/c2llvm2mlir/simple_loop/test.mlir b/test/c2llvm2mlir/simple_loop/test.mlir index fb0bbb78..65d90086 100644 --- a/test/c2llvm2mlir/simple_loop/test.mlir +++ b/test/c2llvm2mlir/simple_loop/test.mlir @@ -15,3 +15,42 @@ // Verifies the output values are the same for the original and re-compiled kernel. // CHECK: output: [[OUTPUT:[0-9]+\.[0-9]+]] // CHECK: output: [[OUTPUT]] + +// Test 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: neura.load +// CHECK-LLVM2NEURA: neura.fmul +// CHECK-LLVM2NEURA: neura.fadd + +// CHECK-LLVM2NEURA-MAP: func.func @_Z6kernelPfS_S_(%arg0: !llvm.ptr {llvm.nocapture, llvm.noundef, llvm.readonly}, %arg1: !llvm.ptr {llvm.nocapture, llvm.noundef}, %arg2: !llvm.ptr {llvm.nocapture, llvm.noundef, llvm.readonly}) -> !llvm.void attributes {CConv = #llvm.cconv, accelerator = "neura", dataflow_mode = "predicate", linkage = #llvm.linkage, mapping_info = {compiled_ii = 5 : i32, mapping_mode = "spatial-temporal", mapping_strategy = "heuristic", rec_mii = 5 : i32, res_mii = 2 : i32, x_tiles = 4 : i32, y_tiles = 4 : i32}, memory_effects = #llvm.memory_effects, no_unwind, passthrough = ["mustprogress", "nofree", "norecurse", "nosync", ["uwtable", "2"], ["min-legal-vector-width", "0"], ["no-trapping-math", "true"], ["stack-protector-buffer-size", "8"], ["target-cpu", "x86-64"]], target_cpu = "x86-64", target_features = #llvm.target_features<["+cmov", "+cx8", "+fxsr", "+mmx", "+sse", "+sse2", "+x87"]>, tune_cpu = "generic", unnamed_addr = 1 : i64, visibility_ = 0 : i64} { From 1ccb544f45ae144d1937259cfcbe99dc6c72dbad Mon Sep 17 00:00:00 2001 From: tangyz <739245980@qq.com> Date: Fri, 17 Oct 2025 20:13:56 +0800 Subject: [PATCH 2/5] rename lhs_value and rhs_value, update simple_loop test --- .../HwAgnosticOpt/FoldConstantPass.cpp | 31 ++++++++++--------- test/c2llvm2mlir/simple_loop/test.mlir | 19 ++++++++++-- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/lib/NeuraDialect/Transforms/Optimizations/HwAgnosticOpt/FoldConstantPass.cpp b/lib/NeuraDialect/Transforms/Optimizations/HwAgnosticOpt/FoldConstantPass.cpp index adb73a47..e6844bea 100644 --- a/lib/NeuraDialect/Transforms/Optimizations/HwAgnosticOpt/FoldConstantPass.cpp +++ b/lib/NeuraDialect/Transforms/Optimizations/HwAgnosticOpt/FoldConstantPass.cpp @@ -271,7 +271,7 @@ struct FuseRemRhsConstantPattern : public FuseRhsConstantPattern { // ========================================= // FuseGepBaseConstantPattern -// Fold constant base pointer for GEP operation +// Folds constant base pointer for GEP operation. // ========================================= struct FuseGepBaseConstantPattern : public OpRewritePattern { using OpRewritePattern::OpRewritePattern; @@ -280,7 +280,7 @@ struct FuseGepBaseConstantPattern : public OpRewritePattern { PatternRewriter &rewriter) const override { Value base = gep_op.getBase(); - // Check if base exists and is a constant + // Checks if base exists and is a constant. if (!base || !isOriginConstantOp(base)) { return failure(); } @@ -288,24 +288,25 @@ struct FuseGepBaseConstantPattern : public OpRewritePattern { auto constant_op = dyn_cast(base.getDefiningOp()); Attribute base_const_value = getOriginConstantValue(base); - // Get all indices (everything after base) + // Gets all indices (everything after base). SmallVector indices; for (Value operand : gep_op.getIndicesAndPredicate()) { indices.push_back(operand); } - // Create new GEP with no base but with const_base_ptr attribute + // Creates new GEP with no base but with lhs_value attribute. auto fused_gep = rewriter.create( gep_op.getLoc(), + // TODO: Gather all the attribute -- https://github.com/coredac/dataflow/issues/145 gep_op.getResult().getType(), /*base=*/nullptr, indices); - addConstantAttribute(fused_gep, "const_base_ptr", base_const_value); + addConstantAttribute(fused_gep, "lhs_value", base_const_value); - // Replace the original GEP + // Replaces the original GEP. rewriter.replaceOp(gep_op, fused_gep); - // Clean up constant if no longer used + // Cleans up constant if no longer used. if (constant_op->use_empty()) { rewriter.eraseOp(constant_op); } @@ -316,7 +317,7 @@ struct FuseGepBaseConstantPattern : public OpRewritePattern { // ========================================= // FuseStoreAddrConstantPattern -// Fold constant destination pointer for Store operation +// Folds constant destination pointer for Store operation. // ========================================= struct FuseStoreAddrConstantPattern : public OpRewritePattern { using OpRewritePattern::OpRewritePattern; @@ -325,7 +326,7 @@ struct FuseStoreAddrConstantPattern : public OpRewritePattern { PatternRewriter &rewriter) const override { Value addr = store_op.getAddr(); - // Check if address exists and is a constant + // Checks if address exists and is a constant. if (!addr || !isOriginConstantOp(addr)) { return failure(); } @@ -333,17 +334,17 @@ struct FuseStoreAddrConstantPattern : public OpRewritePattern { auto constant_op = dyn_cast(addr.getDefiningOp()); Attribute addr_const_value = getOriginConstantValue(addr); - // Create new Store with no addr but with const_dst_ptr attribute + // Creates new Store with no addr but with rhs_value attribute. auto fused_store = rewriter.create( store_op.getLoc(), - store_op.getValue(), // Keep the value operand - /*addr=*/nullptr); // Remove addr operand - addConstantAttribute(fused_store, "const_dst_ptr", addr_const_value); + store_op.getValue(), // Keeps the value operand. + /*addr=*/nullptr); // Removes addr operand. + addConstantAttribute(fused_store, "rhs_value", addr_const_value); - // Replace the original Store + // Replaces the original Store. rewriter.replaceOp(store_op, fused_store); - // Clean up constant if no longer used + // Cleans up constant if no longer used. if (constant_op->use_empty()) { rewriter.eraseOp(constant_op); } diff --git a/test/c2llvm2mlir/simple_loop/test.mlir b/test/c2llvm2mlir/simple_loop/test.mlir index 65d90086..2e5db35f 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 @@ -16,7 +16,7 @@ // CHECK: output: [[OUTPUT:[0-9]+\.[0-9]+]] // CHECK: output: [[OUTPUT]] -// Test LLVM to NEURA lowering +// 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 @@ -49,8 +49,21 @@ // CHECK-LLVM2NEURA: dataflow_mode = "predicate" // CHECK-LLVM2NEURA: neura.phi // CHECK-LLVM2NEURA: neura.gep +// 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 @_Z6kernelPfS_S_(%arg0: !llvm.ptr {llvm.nocapture, llvm.noundef, llvm.readonly}, %arg1: !llvm.ptr {llvm.nocapture, llvm.noundef}, %arg2: !llvm.ptr {llvm.nocapture, llvm.noundef, llvm.readonly}) -> !llvm.void attributes {CConv = #llvm.cconv, accelerator = "neura", dataflow_mode = "predicate", linkage = #llvm.linkage, mapping_info = {compiled_ii = 5 : i32, mapping_mode = "spatial-temporal", mapping_strategy = "heuristic", rec_mii = 5 : i32, res_mii = 2 : i32, x_tiles = 4 : i32, y_tiles = 4 : i32}, memory_effects = #llvm.memory_effects, no_unwind, passthrough = ["mustprogress", "nofree", "norecurse", "nosync", ["uwtable", "2"], ["min-legal-vector-width", "0"], ["no-trapping-math", "true"], ["stack-protector-buffer-size", "8"], ["target-cpu", "x86-64"]], target_cpu = "x86-64", target_features = #llvm.target_features<["+cmov", "+cx8", "+fxsr", "+mmx", "+sse", "+sse2", "+x87"]>, tune_cpu = "generic", unnamed_addr = 1 : i64, visibility_ = 0 : i64} { +// 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 From 5035e2f91be05bb3e3c4e4dcfa8936bc115e63c7 Mon Sep 17 00:00:00 2001 From: tangyz <739245980@qq.com> Date: Fri, 17 Oct 2025 23:58:29 +0800 Subject: [PATCH 3/5] replace all addConstantAttribute to lhs_value and rhs_value --- .../HwAgnosticOpt/FoldConstantPass.cpp | 52 +++++++++---------- test/c2llvm2mlir/simple_loop/test.mlir | 1 + 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/lib/NeuraDialect/Transforms/Optimizations/HwAgnosticOpt/FoldConstantPass.cpp b/lib/NeuraDialect/Transforms/Optimizations/HwAgnosticOpt/FoldConstantPass.cpp index e6844bea..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,12 +259,12 @@ 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; } }; @@ -286,22 +286,22 @@ struct FuseGepBaseConstantPattern : public OpRewritePattern { } auto constant_op = dyn_cast(base.getDefiningOp()); - Attribute base_const_value = getOriginConstantValue(base); + Attribute base_value = getOriginConstantValue(base); // Gets all indices (everything after base). SmallVector indices; - for (Value operand : gep_op.getIndicesAndPredicate()) { + 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(), - // TODO: Gather all the attribute -- https://github.com/coredac/dataflow/issues/145 gep_op.getResult().getType(), /*base=*/nullptr, indices); - addConstantAttribute(fused_gep, "lhs_value", base_const_value); + // 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); @@ -332,14 +332,14 @@ struct FuseStoreAddrConstantPattern : public OpRewritePattern { } auto constant_op = dyn_cast(addr.getDefiningOp()); - Attribute addr_const_value = getOriginConstantValue(addr); + 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_const_value); + addConstantAttribute(fused_store, "rhs_value", addr_value); // Replaces the original Store. rewriter.replaceOp(store_op, fused_store); diff --git a/test/c2llvm2mlir/simple_loop/test.mlir b/test/c2llvm2mlir/simple_loop/test.mlir index 2e5db35f..908ff439 100644 --- a/test/c2llvm2mlir/simple_loop/test.mlir +++ b/test/c2llvm2mlir/simple_loop/test.mlir @@ -49,6 +49,7 @@ // 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 From 9e19e760c9c5d27d5402b904247c485c3b7efc6c Mon Sep 17 00:00:00 2001 From: tangyz <739245980@qq.com> Date: Sat, 18 Oct 2025 00:56:24 +0800 Subject: [PATCH 4/5] rename indicesAndPredicate to indices --- include/NeuraDialect/NeuraOps.td | 4 ++-- lib/NeuraDialect/Transforms/FusePatternPass.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/NeuraDialect/NeuraOps.td b/include/NeuraDialect/NeuraOps.td index 73654ca2..4ead5f21 100644 --- a/include/NeuraDialect/NeuraOps.td +++ b/include/NeuraDialect/NeuraOps.td @@ -181,9 +181,9 @@ def Neura_StoreIndexedOp: Op { // Defines a pointer computation operation. def Neura_GEP : Op { let summary = "Pointer computation using offset indices"; - let arguments = (ins Optional:$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); } From d81a2352046e4766f2db5206b435831dc1e4ca9c Mon Sep 17 00:00:00 2001 From: tangyz <739245980@qq.com> Date: Mon, 20 Oct 2025 15:15:53 +0800 Subject: [PATCH 5/5] Update tests and passes according to fold_args_const changes --- .../HwSpecificOpt/FuseLoopControlPass.cpp | 4 ++-- .../simple_loop/simple_loop.mlir | 4 ++-- test/mapping_quality/branch_for.mlir | 24 +++++++++---------- test/neura/ctrl/branch_for.mlir | 24 +++++++++---------- test/neura/for_loop/kernel_test.mlir | 4 ++-- test/neura/for_loop/relu_test.mlir | 8 +++---- .../interpreter/basic_operation/gep.mlir | 2 +- .../constant_folding/simple_loop.mlir | 8 +++---- test/visualize/test2.mlir | 4 ++-- 9 files changed, 41 insertions(+), 41 deletions(-) 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/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];