@@ -36,8 +36,8 @@ struct IdiomRecognizerPass : public IdiomRecognizerBase<IdiomRecognizerPass> {
36
36
IdiomRecognizerPass () = default ;
37
37
void runOnOperation () override ;
38
38
void recognizeCall (CallOp call);
39
- void raiseStdFind (CallOp call);
40
- void raiseIteratorBeginEnd (CallOp call);
39
+ bool raiseStdFind (CallOp call);
40
+ bool raiseIteratorBeginEnd (CallOp call);
41
41
42
42
// Handle pass options
43
43
struct Options {
@@ -88,14 +88,14 @@ struct IdiomRecognizerPass : public IdiomRecognizerBase<IdiomRecognizerPass> {
88
88
};
89
89
} // namespace
90
90
91
- void IdiomRecognizerPass::raiseStdFind (CallOp call) {
91
+ bool IdiomRecognizerPass::raiseStdFind (CallOp call) {
92
92
// FIXME: tablegen all of this function.
93
93
if (call.getNumOperands () != 3 )
94
- return ;
94
+ return false ;
95
95
96
96
auto callExprAttr = call.getAstAttr ();
97
97
if (!callExprAttr || !callExprAttr.isStdFunctionCall (" find" )) {
98
- return ;
98
+ return false ;
99
99
}
100
100
101
101
if (opts.emitRemarkFoundCalls ())
@@ -109,6 +109,7 @@ void IdiomRecognizerPass::raiseStdFind(CallOp call) {
109
109
110
110
call.replaceAllUsesWith (findOp);
111
111
call.erase ();
112
+ return true ;
112
113
}
113
114
114
115
static bool isIteratorLikeType (mlir::Type t) {
@@ -128,24 +129,24 @@ static bool isIteratorInStdContainter(mlir::Type t) {
128
129
return isStdArrayType (t);
129
130
}
130
131
131
- void IdiomRecognizerPass::raiseIteratorBeginEnd (CallOp call) {
132
+ bool IdiomRecognizerPass::raiseIteratorBeginEnd (CallOp call) {
132
133
// FIXME: tablegen all of this function.
133
134
CIRBaseBuilderTy builder (getContext ());
134
135
135
136
if (call.getNumOperands () != 1 || call.getNumResults () != 1 )
136
- return ;
137
+ return false ;
137
138
138
139
auto callExprAttr = call.getAstAttr ();
139
140
if (!callExprAttr)
140
- return ;
141
+ return false ;
141
142
142
143
if (!isIteratorLikeType (call.getResult (0 ).getType ()))
143
- return ;
144
+ return false ;
144
145
145
146
// First argument is the container "this" pointer.
146
147
auto thisPtr = call.getOperand (0 ).getType ().dyn_cast <PointerType>();
147
148
if (!thisPtr || !isIteratorInStdContainter (thisPtr.getPointee ()))
148
- return ;
149
+ return false ;
149
150
150
151
builder.setInsertionPointAfter (call.getOperation ());
151
152
mlir::Operation *iterOp;
@@ -162,16 +163,20 @@ void IdiomRecognizerPass::raiseIteratorBeginEnd(CallOp call) {
162
163
call.getLoc (), call.getResult (0 ).getType (), call.getCalleeAttr (),
163
164
call.getOperand (0 ));
164
165
} else {
165
- return ;
166
+ return false ;
166
167
}
167
168
168
169
call.replaceAllUsesWith (iterOp);
169
170
call.erase ();
171
+ return true ;
170
172
}
171
173
172
174
void IdiomRecognizerPass::recognizeCall (CallOp call) {
173
- raiseIteratorBeginEnd (call);
174
- raiseStdFind (call);
175
+ if (raiseIteratorBeginEnd (call))
176
+ return ;
177
+
178
+ if (raiseStdFind (call))
179
+ return ;
175
180
}
176
181
177
182
void IdiomRecognizerPass::runOnOperation () {
0 commit comments