Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion include/NeuraDialect/NeuraPasses.td
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ def CanonicalizeLiveIn : Pass<"canonicalize-live-in", "ModuleOp"> {
This pass applies canonicalization transformations to Neura dialect operations.
The canonicalization includes:
1. Converting all live-in values of each basic block to block arguments.
2. Promoting function arguments to neura constant operations.
}];
let constructor = "neura::createCanonicalizeLiveInPass()";
}
Expand Down
2 changes: 2 additions & 0 deletions lib/NeuraDialect/NeuraPasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ void mlir::neura::registerNeuraConversionPassPipeline() {
pm.addPass(mlir::createPrintOpGraphPass(os));

pm.addPass(mlir::neura::createCanonicalizeCastPass());
pm.addPass(mlir::neura::createPromoteFuncArgToConstPass());
pm.addPass(mlir::neura::createFoldConstantPass());
pm.addPass(mlir::neura::createCanonicalizeLiveInPass());
pm.addPass(mlir::neura::createLeveragePredicatedValuePass());
pm.addPass(mlir::createPrintOpGraphPass(os));
Expand Down
32 changes: 2 additions & 30 deletions lib/NeuraDialect/Transforms/CanonicalizeLiveInPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,6 @@ using namespace mlir;
#include "NeuraDialect/NeuraPasses.h.inc"

namespace {
LogicalResult promoteFunctionArgsToConstants(Region &region) {
if (region.empty()) {
return success();
}

Block &entry_block = region.front();
OpBuilder builder(&entry_block, entry_block.begin());

// Collects all function arguments.
SmallVector<BlockArgument, 4> args(entry_block.getArguments().begin(),
entry_block.getArguments().end());

// Creates a constant operation for each function argument.
for (auto [idx, arg] : llvm::enumerate(args)) {
auto const_op = builder.create<neura::ConstantOp>(
arg.getLoc(), arg.getType(),
builder.getStringAttr("\%arg" + std::to_string(idx)));
arg.replaceAllUsesWith(const_op.getResult());
}

return success();
}

LogicalResult promoteLiveInValuesToBlockArgs(Region &region) {
if (region.empty()) {
return success();
Expand Down Expand Up @@ -286,8 +263,8 @@ LogicalResult promoteLiveInValuesToBlockArgs(Region &region) {
if (needs_update) {
OpBuilder builder(cond_br_op);
builder.create<neura::CondBr>(
cond_br_op.getLoc(), cond_br_op.getCondition(),
true_operands, false_operands, cond_br_op.getTrueDest(),
cond_br_op.getLoc(), cond_br_op.getCondition(), true_operands,
false_operands, cond_br_op.getTrueDest(),
cond_br_op.getFalseDest());
cond_br_op.erase();
}
Expand Down Expand Up @@ -336,11 +313,6 @@ struct CanonicalizeLiveInPass
return;
}

if (failed(promoteFunctionArgsToConstants(*region))) {
signalPassFailure();
return;
}

if (failed(promoteLiveInValuesToBlockArgs(*region))) {
signalPassFailure();
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ struct FuseRhsConstantPattern : public OpRewritePattern<OpType> {
Value rhs = op.getRhs();

if (isOriginConstantOp(lhs)) {
assert(false && "LHS constant folding not implemented yet.");
llvm::errs() << "LHS constant folding not supported yet.\n";
return failure();
}

Expand Down
1 change: 1 addition & 0 deletions test/affine2neura/bert/bert_node1/bert_node1.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// RUN: --lower-builtin-to-neura \
// RUN: --lower-llvm-to-neura \
// RUN: --canonicalize-cast \
// RUN: --promote-func-arg-to-const \
// RUN: --canonicalize-live-in \
// RUN: --leverage-predicated-value \
// RUN: --transform-ctrl-to-data-flow \
Expand Down
1 change: 1 addition & 0 deletions test/affine2neura/bert/bert_node28/bert_node28.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// RUN: --lower-builtin-to-neura \
// RUN: --lower-llvm-to-neura \
// RUN: --canonicalize-cast \
// RUN: --promote-func-arg-to-const \
// RUN: --canonicalize-live-in \
// RUN: --leverage-predicated-value \
// RUN: --transform-ctrl-to-data-flow \
Expand Down
2 changes: 2 additions & 0 deletions test/c2llvm2mlir/nested_loop/test.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

// RUN: mlir-neura-opt --assign-accelerator \
// RUN: --lower-llvm-to-neura \
// RUN: --promote-func-arg-to-const \
// RUN: --canonicalize-live-in \
// RUN: --leverage-predicated-value \
// RUN: --transform-ctrl-to-data-flow \
Expand All @@ -11,6 +12,7 @@

// RUN: mlir-neura-opt --assign-accelerator \
// RUN: --lower-llvm-to-neura \
// RUN: --promote-func-arg-to-const \
// RUN: --canonicalize-live-in \
// RUN: --leverage-predicated-value \
// RUN: --transform-ctrl-to-data-flow \
Expand Down
1 change: 1 addition & 0 deletions test/controflow_fuse/complex_nested/complex_nested.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// RUN: --lower-builtin-to-neura \
// RUN: --lower-llvm-to-neura \
// RUN: --canonicalize-cast \
// RUN: --promote-func-arg-to-const \
// RUN: --canonicalize-live-in \
// RUN: --leverage-predicated-value \
// RUN: --transform-ctrl-to-data-flow \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// RUN: --lower-builtin-to-neura \
// RUN: --lower-llvm-to-neura \
// RUN: --canonicalize-cast \
// RUN: --promote-func-arg-to-const \
// RUN: --canonicalize-live-in \
// RUN: --leverage-predicated-value \
// RUN: --transform-ctrl-to-data-flow \
Expand Down
2 changes: 2 additions & 0 deletions test/controflow_fuse/perfect_nested/perfect_nested.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
// RUN: --lower-builtin-to-neura \
// RUN: --lower-llvm-to-neura \
// RUN: --canonicalize-cast \
// RUN: --promote-func-arg-to-const \
// RUN: --canonicalize-live-in \
// RUN: --leverage-predicated-value \
// RUN: --transform-ctrl-to-data-flow \
Expand All @@ -35,6 +36,7 @@
// RUN: --lower-builtin-to-neura \
// RUN: --lower-llvm-to-neura \
// RUN: --canonicalize-cast \
// RUN: --promote-func-arg-to-const \
// RUN: --fold-constant \
// RUN: --canonicalize-live-in \
// RUN: --leverage-predicated-value \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
// RUN: --lower-builtin-to-neura \
// RUN: --lower-llvm-to-neura \
// RUN: --canonicalize-cast \
// RUN: --promote-func-arg-to-const \
// RUN: --canonicalize-live-in \
// RUN: --leverage-predicated-value \
// RUN: --transform-ctrl-to-data-flow \
Expand Down
4 changes: 4 additions & 0 deletions test/controflow_fuse/simple_loop/simple_loop.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// RUN: --lower-builtin-to-neura \
// RUN: --lower-llvm-to-neura \
// RUN: --canonicalize-cast \
// RUN: --promote-func-arg-to-const \
// RUN: --canonicalize-live-in | FileCheck %s --check-prefix=CANONICALIZE

// RUN: mlir-neura-opt %t-llvm.mlir \
Expand All @@ -27,6 +28,7 @@
// RUN: --lower-builtin-to-neura \
// RUN: --lower-llvm-to-neura \
// RUN: --canonicalize-cast \
// RUN: --promote-func-arg-to-const \
// RUN: --canonicalize-live-in \
// RUN: --leverage-predicated-value \
// RUN: --transform-ctrl-to-data-flow | FileCheck %s -check-prefix=CTRL2DATA
Expand All @@ -38,6 +40,7 @@
// RUN: --lower-builtin-to-neura \
// RUN: --lower-llvm-to-neura \
// RUN: --canonicalize-cast \
// RUN: --promote-func-arg-to-const \
// RUN: --fold-constant \
// RUN: --canonicalize-live-in \
// RUN: --leverage-predicated-value \
Expand All @@ -54,6 +57,7 @@
// RUN: --lower-builtin-to-neura \
// RUN: --lower-llvm-to-neura \
// RUN: --canonicalize-cast \
// RUN: --promote-func-arg-to-const \
// RUN: --fold-constant \
// RUN: --canonicalize-live-in \
// RUN: --leverage-predicated-value \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// RUN: --lower-builtin-to-neura \
// RUN: --lower-llvm-to-neura \
// RUN: --canonicalize-cast \
// RUN: --promote-func-arg-to-const \
// RUN: --canonicalize-live-in \
// RUN: | FileCheck %s --check-prefix=CANONICALIZE

Expand All @@ -28,6 +29,7 @@
// RUN: --lower-builtin-to-neura \
// RUN: --lower-llvm-to-neura \
// RUN: --canonicalize-cast \
// RUN: --promote-func-arg-to-const \
// RUN: --canonicalize-live-in \
// RUN: --leverage-predicated-value \
// RUN: --transform-ctrl-to-data-flow | FileCheck %s -check-prefix=CTRL2DATA
Expand All @@ -39,6 +41,7 @@
// RUN: --lower-builtin-to-neura \
// RUN: --lower-llvm-to-neura \
// RUN: --canonicalize-cast \
// RUN: --promote-func-arg-to-const \
// RUN: --fold-constant \
// RUN: --canonicalize-live-in \
// RUN: --leverage-predicated-value \
Expand All @@ -55,6 +58,7 @@
// RUN: --lower-builtin-to-neura \
// RUN: --lower-llvm-to-neura \
// RUN: --canonicalize-cast \
// RUN: --promote-func-arg-to-const \
// RUN: --fold-constant \
// RUN: --canonicalize-live-in \
// RUN: --leverage-predicated-value \
Expand Down
2 changes: 2 additions & 0 deletions test/neura/ctrl/branch.mlir
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// RUN: mlir-neura-opt %s \
// RUN: --assign-accelerator \
// RUN: --lower-llvm-to-neura \
// RUN: --promote-func-arg-to-const \
// RUN: --canonicalize-live-in \
// RUN: --leverage-predicated-value \
// RUN: | FileCheck %s

// RUN: mlir-neura-opt %s \
// RUN: --assign-accelerator \
// RUN: --lower-llvm-to-neura \
// RUN: --promote-func-arg-to-const \
// RUN: --canonicalize-live-in \
// RUN: --leverage-predicated-value \
// RUN: --transform-ctrl-to-data-flow \
Expand Down
6 changes: 6 additions & 0 deletions test/neura/ctrl/branch_for.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
// RUN: mlir-neura-opt %s \
// RUN: --assign-accelerator \
// RUN: --lower-llvm-to-neura \
// RUN: --promote-func-arg-to-const \
// RUN: --fold-constant \
// RUN: --canonicalize-live-in \
// RUN: | FileCheck %s -check-prefix=CANONICALIZE

// RUN: mlir-neura-opt %s \
// RUN: --assign-accelerator \
// RUN: --lower-llvm-to-neura \
// RUN: --promote-func-arg-to-const \
// RUN: --fold-constant \
// RUN: --canonicalize-live-in \
// RUN: --leverage-predicated-value \
Expand All @@ -23,6 +25,7 @@
// RUN: mlir-neura-opt %s \
// RUN: --assign-accelerator \
// RUN: --lower-llvm-to-neura \
// RUN: --promote-func-arg-to-const \
// RUN: --fold-constant \
// RUN: --canonicalize-live-in \
// RUN: --leverage-predicated-value \
Expand All @@ -33,6 +36,7 @@
// RUN: mlir-neura-opt %s \
// RUN: --assign-accelerator \
// RUN: --lower-llvm-to-neura \
// RUN: --promote-func-arg-to-const \
// RUN: --fold-constant \
// RUN: --canonicalize-live-in \
// RUN: --leverage-predicated-value \
Expand All @@ -44,6 +48,7 @@
// RUN: mlir-neura-opt %s \
// RUN: --assign-accelerator \
// RUN: --lower-llvm-to-neura \
// RUN: --promote-func-arg-to-const \
// RUN: --fold-constant \
// RUN: --canonicalize-live-in \
// RUN: --leverage-predicated-value \
Expand All @@ -57,6 +62,7 @@
// RUN: mlir-neura-opt %s \
// RUN: --assign-accelerator \
// RUN: --lower-llvm-to-neura \
// RUN: --promote-func-arg-to-const \
// RUN: --fold-constant \
// RUN: --canonicalize-live-in \
// RUN: --leverage-predicated-value \
Expand Down
2 changes: 2 additions & 0 deletions test/neura/ctrl/branch_with_and_without_arg.mlir
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// RUN: mlir-neura-opt %s \
// RUN: --assign-accelerator \
// RUN: --lower-llvm-to-neura \
// RUN: --promote-func-arg-to-const \
// RUN: --canonicalize-live-in \
// RUN: --leverage-predicated-value \
// RUN: | FileCheck %s

// RUN: mlir-neura-opt %s \
// RUN: --assign-accelerator \
// RUN: --lower-llvm-to-neura \
// RUN: --promote-func-arg-to-const \
// RUN: --canonicalize-live-in \
// RUN: --leverage-predicated-value \
// RUN: --transform-ctrl-to-data-flow \
Expand Down
2 changes: 2 additions & 0 deletions test/neura/ctrl/branch_without_arg.mlir
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// RUN: mlir-neura-opt %s \
// RUN: --assign-accelerator \
// RUN: --lower-llvm-to-neura \
// RUN: --promote-func-arg-to-const \
// RUN: --canonicalize-live-in \
// RUN: --leverage-predicated-value \
// RUN: | FileCheck %s

// RUN: mlir-neura-opt %s \
// RUN: --assign-accelerator \
// RUN: --lower-llvm-to-neura \
// RUN: --promote-func-arg-to-const \
// RUN: --canonicalize-live-in \
// RUN: --leverage-predicated-value \
// RUN: --transform-ctrl-to-data-flow \
Expand Down
1 change: 1 addition & 0 deletions test/neura/ctrl/for_with_if.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// RUN: --lower-builtin-to-neura \
// RUN: --lower-llvm-to-neura \
// RUN: --canonicalize-cast \
// RUN: --promote-func-arg-to-const \
// RUN: --canonicalize-live-in \
// RUN: --leverage-predicated-value \
// RUN: --transform-ctrl-to-data-flow | FileCheck %s -check-prefix=CTRL2DATA
Expand Down
2 changes: 2 additions & 0 deletions test/neura/ctrl/nested_branch.mlir
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// RUN: mlir-neura-opt %s \
// RUN: --assign-accelerator \
// RUN: --lower-llvm-to-neura \
// RUN: --promote-func-arg-to-const \
// RUN: --canonicalize-live-in \
// RUN: --leverage-predicated-value \
// RUN: | FileCheck %s

// RUN: mlir-neura-opt %s \
// RUN: --assign-accelerator \
// RUN: --lower-llvm-to-neura \
// RUN: --promote-func-arg-to-const \
// RUN: --canonicalize-live-in \
// RUN: --leverage-predicated-value \
// RUN: --transform-ctrl-to-data-flow \
Expand Down
3 changes: 3 additions & 0 deletions test/neura/for_loop/kernel_test.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
// RUN: mlir-neura-opt %t-kernel.mlir\
// RUN: --assign-accelerator \
// RUN: --lower-llvm-to-neura \
// RUN: --promote-func-arg-to-const \
// RUN: --canonicalize-live-in \
// RUN: --leverage-predicated-value \
// RUN: | FileCheck %s

// RUN: mlir-neura-opt %t-kernel.mlir\
// RUN: --assign-accelerator \
// RUN: --lower-llvm-to-neura \
// RUN: --promote-func-arg-to-const \
// RUN: --canonicalize-live-in \
// RUN: --leverage-predicated-value \
// RUN: --transform-ctrl-to-data-flow \
Expand All @@ -24,6 +26,7 @@
// RUN: mlir-neura-opt %t-kernel.mlir\
// RUN: --assign-accelerator \
// RUN: --lower-llvm-to-neura \
// RUN: --promote-func-arg-to-const \
// RUN: --canonicalize-live-in \
// RUN: --leverage-predicated-value \
// RUN: --transform-ctrl-to-data-flow \
Expand Down
2 changes: 2 additions & 0 deletions test/neura/for_loop/relu_test.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
// RUN: mlir-neura-opt %t-relu.mlir\
// RUN: --assign-accelerator \
// RUN: --lower-llvm-to-neura \
// RUN: --promote-func-arg-to-const \
// RUN: --canonicalize-live-in \
// RUN: | FileCheck %s

// RUN: mlir-neura-opt %t-relu.mlir\
// RUN: --assign-accelerator \
// RUN: --lower-llvm-to-neura \
// RUN: --promote-func-arg-to-const \
// RUN: --canonicalize-live-in \
// RUN: --leverage-predicated-value \
// RUN: --transform-ctrl-to-data-flow \
Expand Down
2 changes: 2 additions & 0 deletions test/neura/fusion/test.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# RUN: mlir-translate --import-llvm %t-kernel.ll -o %t-kernel.mlir
# RUN: mlir-neura-opt --architecture-spec=%S/../../arch_spec/architecture.yaml --assign-accelerator \
# RUN: --lower-llvm-to-neura \
# RUN: --promote-func-arg-to-const \
# RUN: --canonicalize-live-in \
# RUN: --leverage-predicated-value \
# RUN: --fold-constant \
Expand All @@ -13,6 +14,7 @@

# RUN: mlir-neura-opt --architecture-spec=%S/../../arch_spec/architecture.yaml --assign-accelerator \
# RUN: --lower-llvm-to-neura \
# RUN: --promote-func-arg-to-const \
# RUN: --canonicalize-live-in \
# RUN: --leverage-predicated-value \
# RUN: --fold-constant \
Expand Down
1 change: 1 addition & 0 deletions test/neura/steer_ctrl/for_with_if.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// RUN: --lower-builtin-to-neura \
// RUN: --lower-llvm-to-neura \
// RUN: --canonicalize-cast \
// RUN: --promote-func-arg-to-const \
// RUN: --canonicalize-live-in \
// RUN: --leverage-predicated-value \
// RUN: --transform-ctrl-to-data-flow \
Expand Down
Loading