Skip to content

Commit a83f0f3

Browse files
authored
Merge pull request #155 from ShangkunLi/enable-promote-funargs-in
Explictly use promote-func-arg-to-constant pass
2 parents 81d782e + a588170 commit a83f0f3

File tree

25 files changed

+48
-32
lines changed

25 files changed

+48
-32
lines changed

include/NeuraDialect/NeuraPasses.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ def CanonicalizeLiveIn : Pass<"canonicalize-live-in", "ModuleOp"> {
8181
This pass applies canonicalization transformations to Neura dialect operations.
8282
The canonicalization includes:
8383
1. Converting all live-in values of each basic block to block arguments.
84-
2. Promoting function arguments to neura constant operations.
8584
}];
8685
let constructor = "neura::createCanonicalizeLiveInPass()";
8786
}

lib/NeuraDialect/NeuraPasses.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ void mlir::neura::registerNeuraConversionPassPipeline() {
2626
pm.addPass(mlir::createPrintOpGraphPass(os));
2727

2828
pm.addPass(mlir::neura::createCanonicalizeCastPass());
29+
pm.addPass(mlir::neura::createPromoteFuncArgToConstPass());
30+
pm.addPass(mlir::neura::createFoldConstantPass());
2931
pm.addPass(mlir::neura::createCanonicalizeLiveInPass());
3032
pm.addPass(mlir::neura::createLeveragePredicatedValuePass());
3133
pm.addPass(mlir::createPrintOpGraphPass(os));

lib/NeuraDialect/Transforms/CanonicalizeLiveInPass.cpp

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,6 @@ using namespace mlir;
1717
#include "NeuraDialect/NeuraPasses.h.inc"
1818

1919
namespace {
20-
LogicalResult promoteFunctionArgsToConstants(Region &region) {
21-
if (region.empty()) {
22-
return success();
23-
}
24-
25-
Block &entry_block = region.front();
26-
OpBuilder builder(&entry_block, entry_block.begin());
27-
28-
// Collects all function arguments.
29-
SmallVector<BlockArgument, 4> args(entry_block.getArguments().begin(),
30-
entry_block.getArguments().end());
31-
32-
// Creates a constant operation for each function argument.
33-
for (auto [idx, arg] : llvm::enumerate(args)) {
34-
auto const_op = builder.create<neura::ConstantOp>(
35-
arg.getLoc(), arg.getType(),
36-
builder.getStringAttr("\%arg" + std::to_string(idx)));
37-
arg.replaceAllUsesWith(const_op.getResult());
38-
}
39-
40-
return success();
41-
}
42-
4320
LogicalResult promoteLiveInValuesToBlockArgs(Region &region) {
4421
if (region.empty()) {
4522
return success();
@@ -286,8 +263,8 @@ LogicalResult promoteLiveInValuesToBlockArgs(Region &region) {
286263
if (needs_update) {
287264
OpBuilder builder(cond_br_op);
288265
builder.create<neura::CondBr>(
289-
cond_br_op.getLoc(), cond_br_op.getCondition(),
290-
true_operands, false_operands, cond_br_op.getTrueDest(),
266+
cond_br_op.getLoc(), cond_br_op.getCondition(), true_operands,
267+
false_operands, cond_br_op.getTrueDest(),
291268
cond_br_op.getFalseDest());
292269
cond_br_op.erase();
293270
}
@@ -336,11 +313,6 @@ struct CanonicalizeLiveInPass
336313
return;
337314
}
338315

339-
if (failed(promoteFunctionArgsToConstants(*region))) {
340-
signalPassFailure();
341-
return;
342-
}
343-
344316
if (failed(promoteLiveInValuesToBlockArgs(*region))) {
345317
signalPassFailure();
346318
return;

lib/NeuraDialect/Transforms/Optimizations/HwAgnosticOpt/FoldConstantPass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ struct FuseRhsConstantPattern : public OpRewritePattern<OpType> {
111111
Value rhs = op.getRhs();
112112

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

test/affine2neura/bert/bert_node1/bert_node1.mlir

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
// RUN: --lower-builtin-to-neura \
1515
// RUN: --lower-llvm-to-neura \
1616
// RUN: --canonicalize-cast \
17+
// RUN: --promote-func-arg-to-const \
1718
// RUN: --canonicalize-live-in \
1819
// RUN: --leverage-predicated-value \
1920
// RUN: --transform-ctrl-to-data-flow \

test/affine2neura/bert/bert_node28/bert_node28.mlir

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
// RUN: --lower-builtin-to-neura \
1515
// RUN: --lower-llvm-to-neura \
1616
// RUN: --canonicalize-cast \
17+
// RUN: --promote-func-arg-to-const \
1718
// RUN: --canonicalize-live-in \
1819
// RUN: --leverage-predicated-value \
1920
// RUN: --transform-ctrl-to-data-flow \

test/c2llvm2mlir/nested_loop/test.mlir

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

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

1213
// RUN: mlir-neura-opt --assign-accelerator \
1314
// RUN: --lower-llvm-to-neura \
15+
// RUN: --promote-func-arg-to-const \
1416
// RUN: --canonicalize-live-in \
1517
// RUN: --leverage-predicated-value \
1618
// RUN: --transform-ctrl-to-data-flow \

test/controflow_fuse/complex_nested/complex_nested.mlir

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
// RUN: --lower-builtin-to-neura \
1515
// RUN: --lower-llvm-to-neura \
1616
// RUN: --canonicalize-cast \
17+
// RUN: --promote-func-arg-to-const \
1718
// RUN: --canonicalize-live-in \
1819
// RUN: --leverage-predicated-value \
1920
// RUN: --transform-ctrl-to-data-flow \

test/controflow_fuse/non_perfect_nested/non_perfect_nested.mlir

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
// RUN: --lower-builtin-to-neura \
1515
// RUN: --lower-llvm-to-neura \
1616
// RUN: --canonicalize-cast \
17+
// RUN: --promote-func-arg-to-const \
1718
// RUN: --canonicalize-live-in \
1819
// RUN: --leverage-predicated-value \
1920
// RUN: --transform-ctrl-to-data-flow \

test/controflow_fuse/perfect_nested/perfect_nested.mlir

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
// RUN: --lower-builtin-to-neura \
2424
// RUN: --lower-llvm-to-neura \
2525
// RUN: --canonicalize-cast \
26+
// RUN: --promote-func-arg-to-const \
2627
// RUN: --canonicalize-live-in \
2728
// RUN: --leverage-predicated-value \
2829
// RUN: --transform-ctrl-to-data-flow \
@@ -35,6 +36,7 @@
3536
// RUN: --lower-builtin-to-neura \
3637
// RUN: --lower-llvm-to-neura \
3738
// RUN: --canonicalize-cast \
39+
// RUN: --promote-func-arg-to-const \
3840
// RUN: --fold-constant \
3941
// RUN: --canonicalize-live-in \
4042
// RUN: --leverage-predicated-value \

0 commit comments

Comments
 (0)