Skip to content

Commit 64af4c5

Browse files
committed
[mlir][emitc] Ignore literal in form-expression
Literal is always inlined, so there's no need to form expressions with it as well.
1 parent 0c3aabb commit 64af4c5

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

mlir/lib/Dialect/EmitC/Transforms/FormExpressions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct FormExpressionsPass
3838
auto matchFun = [&](Operation *op) {
3939
if (isa<emitc::CExpressionInterface>(*op) &&
4040
!op->getParentOfType<emitc::ExpressionOp>() &&
41-
op->getNumResults() == 1)
41+
!isa<emitc::LiteralOp>(op) && op->getNumResults() == 1)
4242
createExpression(op, builder);
4343
};
4444
rootOp->walk(matchFun);

mlir/test/Dialect/EmitC/form-expressions.mlir

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ func.func @opaque_type_expression(%arg0: i32, %arg1: !emitc.opaque<"T0">, %arg2
192192
%c = emitc.cmp lt, %b, %arg2 :(i32, i32) -> i1
193193
return %c : i1
194194
}
195+
<<<<<<< HEAD
195196

196197
// CHECK-LABEL: func.func @expression_with_constant(
197198
// CHECK-SAME: %[[VAL_0:.*]]: i32) -> i32 {
@@ -228,3 +229,5 @@ func.func @expression_with_literal(%arg0: i32) -> i1 {
228229
%c = emitc.cmp lt, %b, %arg0 :(i32, i32) -> i1
229230
return %c : i1
230231
}
232+
=======
233+
>>>>>>> 6a27d24c62dd ([mlir][emitc] Ignore literal in form-expression)

mlir/test/Target/Cpp/expressions.mlir

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ emitc.func @expression_with_call_opaque_with_args_array(%0 : i32, %1 : i32) {
472472
// CPP-DECLTOP-NEXT: }
473473

474474
func.func @expression_with_literal(%arg0 : i32) -> i1 {
475-
%ret = emitc.expression noinline : i1 {
475+
%ret = emitc.expression %arg0 noinline : (i32) -> i1 {
476476
%literal1 = emitc.literal "1" : i32
477477
%literal2 = emitc.literal "2" : i32
478478
%add = add %literal1, %arg0 : (i32, i32) -> i32
@@ -495,9 +495,9 @@ func.func @expression_with_literal(%arg0 : i32) -> i1 {
495495
// CPP-DECLTOP-NEXT: }
496496

497497
func.func @single_literal_in_expression() -> i32 {
498-
%result = emitc.expression : i32 {
499-
%lit = emitc.literal "42" : i32
500-
emitc.yield %lit : i32
498+
%ret = emitc.expression : () -> i32 {
499+
%literal = emitc.literal "42" : i32
500+
emitc.yield %literal : i32
501501
}
502-
return %result : i32
502+
return %ret : i32
503503
}

0 commit comments

Comments
 (0)