@@ -94,6 +94,19 @@ static void lowerYield(SmallVector<Value> &resultVariables,
94
94
rewriter.eraseOp (yield);
95
95
}
96
96
97
+ // Lower the contents of an scf::if/scf::index_switch regions to an
98
+ // emitc::if/emitc::switch regions. The contents of the lowering region is
99
+ // moved into the respective lowered region, but the scf::yield is replaced not
100
+ // only with an emitc::yield, but also with a sequence of emitc::assign ops that
101
+ // set the yielded values into the result variables.
102
+ static void lowerRegion (SmallVector<Value> &resultVariables,
103
+ PatternRewriter &rewriter, Region ®ion,
104
+ Region &loweredRegion) {
105
+ rewriter.inlineRegionBefore (region, loweredRegion, loweredRegion.end ());
106
+ Operation *terminator = loweredRegion.back ().getTerminator ();
107
+ lowerYield (resultVariables, rewriter, cast<scf::YieldOp>(terminator));
108
+ }
109
+
97
110
LogicalResult ForLowering::matchAndRewrite (ForOp forOp,
98
111
PatternRewriter &rewriter) const {
99
112
Location loc = forOp.getLoc ();
@@ -145,18 +158,6 @@ LogicalResult IfLowering::matchAndRewrite(IfOp ifOp,
145
158
SmallVector<Value> resultVariables =
146
159
createVariablesForResults (ifOp, rewriter);
147
160
148
- // Utility function to lower the contents of an scf::if region to an emitc::if
149
- // region. The contents of the scf::if regions is moved into the respective
150
- // emitc::if regions, but the scf::yield is replaced not only with an
151
- // emitc::yield, but also with a sequence of emitc::assign ops that set the
152
- // yielded values into the result variables.
153
- auto lowerRegion = [&resultVariables, &rewriter](Region ®ion,
154
- Region &loweredRegion) {
155
- rewriter.inlineRegionBefore (region, loweredRegion, loweredRegion.end ());
156
- Operation *terminator = loweredRegion.back ().getTerminator ();
157
- lowerYield (resultVariables, rewriter, cast<scf::YieldOp>(terminator));
158
- };
159
-
160
161
Region &thenRegion = ifOp.getThenRegion ();
161
162
Region &elseRegion = ifOp.getElseRegion ();
162
163
@@ -196,18 +197,6 @@ IndexSwitchOpLowering::matchAndRewrite(IndexSwitchOp indexSwitchOp,
196
197
SmallVector<Value> resultVariables =
197
198
createVariablesForResults (indexSwitchOp, rewriter);
198
199
199
- // Utility function to lower the contents of an scf::index_switch regions to
200
- // an emitc::switch regions. The contents of the scf::index_switch regions is
201
- // moved into the respective emitc::switch regions, but the scf::yield is
202
- // replaced not only with an emitc::yield, but also with a sequence of
203
- // emitc::assign ops that set the yielded values into the result variables.
204
- auto lowerRegion = [&resultVariables, &rewriter](Region ®ion,
205
- Region &loweredRegion) {
206
- rewriter.inlineRegionBefore (region, loweredRegion, loweredRegion.end ());
207
- Operation *terminator = loweredRegion.back ().getTerminator ();
208
- lowerYield (resultVariables, rewriter, cast<scf::YieldOp>(terminator));
209
- };
210
-
211
200
auto loweredSwitch = rewriter.create <emitc::SwitchOp>(
212
201
loc, indexSwitchOp.getArg (), indexSwitchOp.getCases (),
213
202
indexSwitchOp.getNumCases ());
0 commit comments