@@ -255,79 +255,105 @@ def FunctionOpInterface : OpInterface<"FunctionOpInterface", [
255
255
BlockArgListType getArguments() { return getFunctionBody().getArguments(); }
256
256
257
257
/// Insert a single argument of type `argType` with attributes `argAttrs` and
258
- /// location `argLoc` at `argIndex`.
259
- void insertArgument(unsigned argIndex, ::mlir::Type argType, ::mlir::DictionaryAttr argAttrs,
260
- ::mlir::Location argLoc) {
261
- insertArguments({argIndex}, {argType}, {argAttrs}, {argLoc});
258
+ /// location `argLoc` at `argIndex`. Returns failure if the function cannot be
259
+ /// updated to have the new signature.
260
+ ::llvm::LogicalResult insertArgument(
261
+ unsigned argIndex, ::mlir::Type argType, ::mlir::DictionaryAttr argAttrs,
262
+ ::mlir::Location argLoc) {
263
+ return insertArguments({argIndex}, {argType}, {argAttrs}, {argLoc});
262
264
}
263
265
264
266
/// Inserts arguments with the listed types, attributes, and locations at the
265
267
/// listed indices. `argIndices` must be sorted. Arguments are inserted in the
266
268
/// order they are listed, such that arguments with identical index will
267
- /// appear in the same order that they were listed here.
268
- void insertArguments(::llvm::ArrayRef<unsigned> argIndices, ::mlir::TypeRange argTypes,
269
- ::llvm::ArrayRef<::mlir::DictionaryAttr> argAttrs,
270
- ::llvm::ArrayRef<::mlir::Location> argLocs) {
269
+ /// appear in the same order that they were listed here. Returns failure if
270
+ /// the function cannot be updated to have the new signature.
271
+ ::llvm::LogicalResult insertArguments(
272
+ ::llvm::ArrayRef<unsigned> argIndices, ::mlir::TypeRange argTypes,
273
+ ::llvm::ArrayRef<::mlir::DictionaryAttr> argAttrs,
274
+ ::llvm::ArrayRef<::mlir::Location> argLocs) {
271
275
unsigned originalNumArgs = $_op.getNumArguments();
272
276
::mlir::Type newType = $_op.getTypeWithArgsAndResults(
273
277
argIndices, argTypes, /*resultIndices=*/{}, /*resultTypes=*/{});
278
+ if (!newType)
279
+ return ::llvm::failure();
274
280
::mlir::function_interface_impl::insertFunctionArguments(
275
281
$_op, argIndices, argTypes, argAttrs, argLocs,
276
282
originalNumArgs, newType);
283
+ return ::llvm::success();
277
284
}
278
285
279
- /// Insert a single result of type `resultType` at `resultIndex`.
280
- void insertResult(unsigned resultIndex, ::mlir::Type resultType,
281
- ::mlir::DictionaryAttr resultAttrs) {
282
- insertResults({resultIndex}, {resultType}, {resultAttrs});
286
+ /// Insert a single result of type `resultType` at `resultIndex`.Returns
287
+ /// failure if the function cannot be updated to have the new signature.
288
+ ::llvm::LogicalResult insertResult(
289
+ unsigned resultIndex, ::mlir::Type resultType,
290
+ ::mlir::DictionaryAttr resultAttrs) {
291
+ return insertResults({resultIndex}, {resultType}, {resultAttrs});
283
292
}
284
293
285
294
/// Inserts results with the listed types at the listed indices.
286
295
/// `resultIndices` must be sorted. Results are inserted in the order they are
287
296
/// listed, such that results with identical index will appear in the same
288
- /// order that they were listed here.
289
- void insertResults(::llvm::ArrayRef<unsigned> resultIndices, ::mlir::TypeRange resultTypes,
290
- ::llvm::ArrayRef<::mlir::DictionaryAttr> resultAttrs) {
297
+ /// order that they were listed here. Returns failure if the function
298
+ /// cannot be updated to have the new signature.
299
+ ::llvm::LogicalResult insertResults(
300
+ ::llvm::ArrayRef<unsigned> resultIndices,
301
+ ::mlir::TypeRange resultTypes,
302
+ ::llvm::ArrayRef<::mlir::DictionaryAttr> resultAttrs) {
291
303
unsigned originalNumResults = $_op.getNumResults();
292
304
::mlir::Type newType = $_op.getTypeWithArgsAndResults(
293
305
/*argIndices=*/{}, /*argTypes=*/{}, resultIndices, resultTypes);
306
+ if (!newType)
307
+ return ::llvm::failure();
294
308
::mlir::function_interface_impl::insertFunctionResults(
295
309
$_op, resultIndices, resultTypes, resultAttrs,
296
310
originalNumResults, newType);
311
+ return ::llvm::success();
297
312
}
298
313
299
- /// Erase a single argument at `argIndex`.
300
- void eraseArgument(unsigned argIndex) {
314
+ /// Erase a single argument at `argIndex`. Returns failure if the function
315
+ /// cannot be updated to have the new signature.
316
+ ::llvm::LogicalResult eraseArgument(unsigned argIndex) {
301
317
::llvm::BitVector argsToErase($_op.getNumArguments());
302
318
argsToErase.set(argIndex);
303
- eraseArguments(argsToErase);
319
+ return eraseArguments(argsToErase);
304
320
}
305
321
306
- /// Erases the arguments listed in `argIndices`.
307
- void eraseArguments(const ::llvm::BitVector &argIndices) {
322
+ /// Erases the arguments listed in `argIndices`. Returns failure if the
323
+ /// function cannot be updated to have the new signature.
324
+ ::llvm::LogicalResult eraseArguments(const ::llvm::BitVector &argIndices) {
308
325
::mlir::Type newType = $_op.getTypeWithoutArgs(argIndices);
326
+ if (!newType)
327
+ return ::llvm::failure();
309
328
::mlir::function_interface_impl::eraseFunctionArguments(
310
329
$_op, argIndices, newType);
330
+ return ::llvm::success();
311
331
}
312
332
313
- /// Erase a single result at `resultIndex`.
314
- void eraseResult(unsigned resultIndex) {
333
+ /// Erase a single result at `resultIndex`. Returns failure if the function
334
+ /// cannot be updated to have the new signature.
335
+ LogicalResult eraseResult(unsigned resultIndex) {
315
336
::llvm::BitVector resultsToErase($_op.getNumResults());
316
337
resultsToErase.set(resultIndex);
317
- eraseResults(resultsToErase);
338
+ return eraseResults(resultsToErase);
318
339
}
319
340
320
- /// Erases the results listed in `resultIndices`.
321
- void eraseResults(const ::llvm::BitVector &resultIndices) {
341
+ /// Erases the results listed in `resultIndices`. Returns failure if the
342
+ /// function cannot be updated to have the new signature.
343
+ ::llvm::LogicalResult eraseResults(const ::llvm::BitVector &resultIndices) {
322
344
::mlir::Type newType = $_op.getTypeWithoutResults(resultIndices);
345
+ if (!newType)
346
+ return ::llvm::failure();
323
347
::mlir::function_interface_impl::eraseFunctionResults(
324
348
$_op, resultIndices, newType);
349
+ return ::llvm::success();
325
350
}
326
351
327
352
/// Return the type of this function with the specified arguments and
328
353
/// results inserted. This is used to update the function's signature in
329
354
/// the `insertArguments` and `insertResults` methods. The arrays must be
330
- /// sorted by increasing index.
355
+ /// sorted by increasing index. Return nullptr if the updated type would
356
+ /// not be valid.
331
357
::mlir::Type getTypeWithArgsAndResults(
332
358
::llvm::ArrayRef<unsigned> argIndices, ::mlir::TypeRange argTypes,
333
359
::llvm::ArrayRef<unsigned> resultIndices, ::mlir::TypeRange resultTypes) {
@@ -341,7 +367,8 @@ def FunctionOpInterface : OpInterface<"FunctionOpInterface", [
341
367
342
368
/// Return the type of this function without the specified arguments and
343
369
/// results. This is used to update the function's signature in the
344
- /// `eraseArguments` and `eraseResults` methods.
370
+ /// `eraseArguments` and `eraseResults` methods. Return nullptr if the
371
+ /// updated type would not be valid.
345
372
::mlir::Type getTypeWithoutArgsAndResults(
346
373
const ::llvm::BitVector &argIndices, const ::llvm::BitVector &resultIndices) {
347
374
::llvm::SmallVector<::mlir::Type> argStorage, resultStorage;
0 commit comments