Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CIR] New assembly format for function type return #1391

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dkolsen-pgi
Copy link
Collaborator

Change the assembly format for cir::FuncType from

!cir.func<!returnType (!argType)>

to

!cir.func<(!argType) -> !returnType>

This change (1) is easier to parse because it doesn't require lookahead, (2) is consistent with the format of ClangIR FuncOp assembly, and (3) is consistent with function types in other MLIR dialects.

Change all the tests to use or to expect the new format for function types.

The contents and the semantics of cir::FuncType are unchanged. Only the assembly format is being changed. Functions that return void in C or C++ are still represented in MLIR as having no return type.

Most of the changes are in parseFuncType and printFuncType and the functions they call in CIRTypes.cpp.

A FuncType::verify function was added to check that an explicit return type is not cir::VoidType.

FuncType::isVoid() was renamed to FuncType::hasVoidReturn()

Some comments for FuncType were improved.

An llvm_unreachable was added to StructType::getKindAsStr to suppress a compiler warning and to catch a memory error that corrupts the RecordKind field. (This was a drive-by fix and has nothing to do with the rest of this change.)

Change the assembly format for `cir::FuncType` from
```
!cir.func<!returnType (!argType)>
```
to
```
!cir.func<(!argType) -> !returnType>
```

This change (1) is easier to parse because it doesn't require lookahead,
(2) is consistent with the format of ClangIR `FuncOp` assembly, and
(3) is consistent with function types in other MLIR dialects.

Change all the tests to use or to expect the new format for function
types.

The contents and the semantics of `cir::FuncType` are unchanged.  Only
the assembly format is being changed.  Functions that return `void` in C
or C++ are still represented in MLIR as having no return type.

Most of the changes are in `parseFuncType` and `printFuncType` and the
functions they call in `CIRTypes.cpp`.

A `FuncType::verify` function was added to check that an explicit return
type is not `cir::VoidType`.

`FuncType::isVoid()` was renamed to `FuncType::hasVoidReturn()`

Some comments for `FuncType` were improved.

An `llvm_unreachable` was added to `StructType::getKindAsStr` to
suppress a compiler warning and to catch a memory error that corrupts
the `RecordKind` field.  (This was a drive-by fix and has nothing to do
with the rest of this change.)
@dkolsen-pgi
Copy link
Collaborator Author

I considered renaming FuncType::getReturnType and FuncType::getReturnTypes so that the difference between them was more clear. But I struggled to find the right names. So instead I just made the documentation for those functions more clear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant