diff options
| author | Sean Silva <silvasean@google.com> | 2019-10-18 16:02:56 -0700 |
|---|---|---|
| committer | A. Unique TensorFlower <gardener@tensorflow.org> | 2019-10-18 16:03:28 -0700 |
| commit | 9c9a7e9268bdd4fe3433ea4499eebbd74e015919 (patch) | |
| tree | 6bc78019d8569d99e489ea0d912fceaba05cb0e0 /mlir/lib/Dialect/LLVMIR | |
| parent | 9e7e297da33be70ec41335800c05b554f5de065b (diff) | |
| download | bcm5719-llvm-9c9a7e9268bdd4fe3433ea4499eebbd74e015919.tar.gz bcm5719-llvm-9c9a7e9268bdd4fe3433ea4499eebbd74e015919.zip | |
Add support for function result attributes.
This allows dialect-specific attributes to be attached to func results. (or more specifically, FunctionLike ops).
For example:
```
func @f() -> (i32 {my_dialect.some_attr = 3})
```
This attaches my_dialect.some_attr with value 3 to the first result of func @f.
Another more complex example:
```
func @g() -> (i32, f32 {my_dialect.some_attr = "foo", other_dialect.some_other_attr = [1,2,3]}, i1)
```
Here, the second result has two attributes attached.
PiperOrigin-RevId: 275564165
Diffstat (limited to 'mlir/lib/Dialect/LLVMIR')
| -rw-r--r-- | mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp index 23e3889c049..618ee231f9e 100644 --- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp @@ -1115,6 +1115,21 @@ unsigned LLVMFuncOp::getNumFuncArguments() { return getType().getUnderlyingType()->getFunctionNumParams(); } +// Hook for OpTrait::FunctionLike, returns the number of function results. +// Depends on the type attribute being correct as checked by verifyType +unsigned LLVMFuncOp::getNumFuncResults() { + llvm::FunctionType *funcType = + cast<llvm::FunctionType>(getType().getUnderlyingType()); + // We model LLVM functions that return void as having zero results, + // and all others as having one result. + // If we modeled a void return as one result, then it would be possible to + // attach an MLIR result attribute to it, and it isn't clear what semantics we + // would assign to that. + if (funcType->getReturnType()->isVoidTy()) + return 0; + return 1; +} + static LogicalResult verify(LLVMFuncOp op) { if (op.isExternal()) return success(); |

