Skip to content

Commit

Permalink
Copy attributes from the original operation (SCF::ForOp) into the low…
Browse files Browse the repository at this point in the history
…ered version (Emitc::ForOp) (#390)
  • Loading branch information
josel-amd authored Oct 22, 2024
1 parent 2015abf commit 4b36487
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions mlir/lib/Conversion/SCFToEmitC/SCFToEmitC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ ForLowering::matchAndRewrite(ForOp forOp, OpAdaptor adaptor,
emitc::ForOp loweredFor = rewriter.create<emitc::ForOp>(
loc, adaptor.getLowerBound(), adaptor.getUpperBound(), adaptor.getStep());

// Propagate any attributes from the ODS forOp to the lowered emitc::for op.
loweredFor->setAttrs(forOp->getAttrs());

Block *loweredBody = loweredFor.getBody();

// Erase the auto-generated terminator for the lowered for op.
Expand Down
9 changes: 9 additions & 0 deletions mlir/test/Conversion/SCFToEmitC/for.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,12 @@ func.func @nested_for_yield(%arg0 : index, %arg1 : index, %arg2 : index) -> f32
// CHECK-NEXT: }
// CHECK-NEXT: return %[[VAL_4]] : f32
// CHECK-NEXT: }

func.func @loop_with_attr(%arg0 : index, %arg1 : index, %arg2 : index) {
scf.for %i0 = %arg0 to %arg1 step %arg2 {
%c1 = arith.constant 1 : index
} {test.value = 5 : index}
return
}
// CHECK-LABEL: func.func @loop_with_attr
// CHECK: {test.value = 5 : index}

0 comments on commit 4b36487

Please sign in to comment.