Skip to content

Commit 4b36487

Browse files
authored
Copy attributes from the original operation (SCF::ForOp) into the lowered version (Emitc::ForOp) (#390)
1 parent 2015abf commit 4b36487

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

mlir/lib/Conversion/SCFToEmitC/SCFToEmitC.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ ForLowering::matchAndRewrite(ForOp forOp, OpAdaptor adaptor,
118118
emitc::ForOp loweredFor = rewriter.create<emitc::ForOp>(
119119
loc, adaptor.getLowerBound(), adaptor.getUpperBound(), adaptor.getStep());
120120

121+
// Propagate any attributes from the ODS forOp to the lowered emitc::for op.
122+
loweredFor->setAttrs(forOp->getAttrs());
123+
121124
Block *loweredBody = loweredFor.getBody();
122125

123126
// Erase the auto-generated terminator for the lowered for op.

mlir/test/Conversion/SCFToEmitC/for.mlir

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,12 @@ func.func @nested_for_yield(%arg0 : index, %arg1 : index, %arg2 : index) -> f32
9898
// CHECK-NEXT: }
9999
// CHECK-NEXT: return %[[VAL_4]] : f32
100100
// CHECK-NEXT: }
101+
102+
func.func @loop_with_attr(%arg0 : index, %arg1 : index, %arg2 : index) {
103+
scf.for %i0 = %arg0 to %arg1 step %arg2 {
104+
%c1 = arith.constant 1 : index
105+
} {test.value = 5 : index}
106+
return
107+
}
108+
// CHECK-LABEL: func.func @loop_with_attr
109+
// CHECK: {test.value = 5 : index}

0 commit comments

Comments
 (0)