@@ -183,8 +183,8 @@ CGIOperandList::CGIOperandList(const Record *R) : TheDef(R) {
183
183
// If we have no explicit sub-op dag, but have an top-level encoder
184
184
// method, the single encoder will multiple sub-ops, itself.
185
185
OpInfo.EncoderMethodNames [0 ] = EncoderMethod;
186
- for ( unsigned j = 1 ; j < NumOps; ++j)
187
- OpInfo.DoNotEncode [j ] = true ;
186
+ OpInfo. DoNotEncode . set ();
187
+ OpInfo.DoNotEncode [0 ] = false ;
188
188
}
189
189
190
190
MIOperandNo += NumOps;
@@ -199,36 +199,31 @@ CGIOperandList::CGIOperandList(const Record *R) : TheDef(R) {
199
199
// / specified name, abort.
200
200
// /
201
201
unsigned CGIOperandList::getOperandNamed (StringRef Name) const {
202
- unsigned OpIdx;
203
- if (hasOperandNamed (Name, OpIdx) )
204
- return OpIdx;
202
+ std::optional< unsigned > OpIdx = findOperandNamed (Name) ;
203
+ if (OpIdx)
204
+ return * OpIdx;
205
205
PrintFatalError (TheDef->getLoc (), " '" + TheDef->getName () +
206
206
" ' does not have an operand named '$" +
207
207
Name + " '!" );
208
208
}
209
209
210
- // / hasOperandNamed - Query whether the instruction has an operand of the
211
- // / given name. If so, return true and set OpIdx to the index of the
212
- // / operand. Otherwise, return false.
213
- bool CGIOperandList::hasOperandNamed (StringRef Name, unsigned &OpIdx) const {
210
+ // / findOperandNamed - Query whether the instruction has an operand of the
211
+ // / given name. If so, the index of the operand. Otherwise, return std::nullopt.
212
+ std::optional<unsigned > CGIOperandList::findOperandNamed (StringRef Name) const {
214
213
assert (!Name.empty () && " Cannot search for operand with no name!" );
215
- for (unsigned i = 0 , e = OperandList.size (); i != e; ++i)
216
- if (OperandList[i].Name == Name) {
217
- OpIdx = i;
218
- return true ;
219
- }
220
- return false ;
214
+ for (const auto &[Index, Opnd] : enumerate(OperandList))
215
+ if (Opnd.Name == Name)
216
+ return Index;
217
+ return std::nullopt;
221
218
}
222
219
223
- bool CGIOperandList::hasSubOperandAlias (
224
- StringRef Name, std::pair< unsigned , unsigned > &SubOp ) const {
220
+ std::optional<std::pair< unsigned , unsigned >>
221
+ CGIOperandList::findSubOperandAlias (StringRef Name ) const {
225
222
assert (!Name.empty () && " Cannot search for operand with no name!" );
226
223
auto SubOpIter = SubOpAliases.find (Name);
227
- if (SubOpIter != SubOpAliases.end ()) {
228
- SubOp = SubOpIter->second ;
229
- return true ;
230
- }
231
- return false ;
224
+ if (SubOpIter != SubOpAliases.end ())
225
+ return SubOpIter->second ;
226
+ return std::nullopt;
232
227
}
233
228
234
229
std::pair<unsigned , unsigned >
@@ -251,9 +246,7 @@ CGIOperandList::ParseOperandName(StringRef Op, bool AllowWholeOp) {
251
246
OpName = OpName.substr (0 , DotIdx);
252
247
}
253
248
254
- unsigned OpIdx;
255
-
256
- if (std::pair<unsigned , unsigned > SubOp; hasSubOperandAlias (OpName, SubOp)) {
249
+ if (auto SubOp = findSubOperandAlias (OpName)) {
257
250
// Found a name for a piece of an operand, just return it directly.
258
251
if (!SubOpName.empty ()) {
259
252
PrintFatalError (
@@ -262,10 +255,10 @@ CGIOperandList::ParseOperandName(StringRef Op, bool AllowWholeOp) {
262
255
" : Cannot use dotted suboperand name within suboperand '" +
263
256
OpName + " '" );
264
257
}
265
- return SubOp;
258
+ return * SubOp;
266
259
}
267
260
268
- OpIdx = getOperandNamed (OpName);
261
+ unsigned OpIdx = getOperandNamed (OpName);
269
262
270
263
if (SubOpName.empty ()) { // If no suboperand name was specified:
271
264
// If one was needed, throw.
0 commit comments