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

Backported all emitc-related commits from upstream #170

Merged
merged 12 commits into from
Apr 29, 2024

Conversation

mgehre-amd
Copy link
Collaborator

@mgehre-amd mgehre-amd commented Apr 26, 2024

Backported all emitc-related commits from upstream

git log ..upstream/main -- \
mlir/include/mlir/Dialect/EmitC \
mlir/include/mlir/Target/Cpp \
mlir/lib/Conversion/ArithToEmitC \
mlir/lib/Conversion/FuncToEmitC \
mlir/lib/Conversion/MemRefToEmitC \
mlir/lib/Conversion/SCFToEmitC \
mlir/lib/Dialect/EmitC \
mlir/lib/Target/Cpp \
mlir/test/Conversion/ArithToEmitC \
mlir/test/Conversion/FuncToEmitC \
mlir/test/Conversion/MemRefToEmitC \
mlir/test/Conversion/SCFToEmitC \
mlir/test/Dialect/EmitC \
mlir/test/Target/Cpp

fyi @TinaAMD

kchibisov and others added 12 commits April 26, 2024 08:38
Make form-expressions not create `emitc.expression`s for operations
inside the `emitc.expression`s, since they are invalid.
Important to consider that `arith` has wrap around semantics, and in C++
signed overflow is UB.
Unless the operation guarantees that no signed overflow happens, we will
perform the arithmetic in an equivalent unsigned type.
`bool` also doesn't wrap around in C++, and is not addressed here.
Expose function objects that call into `llvm::isa` and
`llvm::isa_and_present`, such that these type checks can be used as
predicates in generic algorithms.

Before this change, `llvm::isa*` functions cannot be easily used without
knowing both the argument type and the checked types, which leads to
them being wrapped in lambdas. For example:
```c++
llvm::all_of(myTypes,
             [](auto type) { return llvm::isa<VectorType>(type); });
```

With this PR the example above becomes:
```c++
llvm::all_of(myTypes, llvm::IsaPred<VectorType>);
```

As an alternative solution, I considered redefining `isa*` as function
objects, but I decided against doing that because it would create
asymmetry with other cast *functions* and could break code that depends
on them being actual functions.
llvm#86266)

For pointer types the indices are restricted to one integer-like
operand.
For opaque types no further restrictions are made.
- Remove trailing type from value attributes as emitc.opaque attributes
are untyped.
- Replace invalid trailing * in opaque type by wrapping it into an
!emitc.ptr.
Restrict the types which are valid for EmitC operations. Use what is
currently supported by the emitter as restriction. Define a utility
functions for valid types, such that they can be used to restrict the
operations in table gen as well as being available for reuse in dialect
conversions.
This adds
- `emitc.global` and `emitc.get_global` ops to model global variables
similar to how `memref.global` and `memref.get_global` work.
- translation of those ops to C++
- lowering of `memref.global` and `memref.get_global` into those ops

---------

Co-authored-by: Simon Camphausen <simon.camphausen@iml.fraunhofer.de>
…free function calls. (llvm#89356)

This change cleans up call sites. Next step is to mark the member
functions deprecated.

See https://mlir.llvm.org/deprecation and
https://discourse.llvm.org/t/preferred-casting-style-going-forward.
mlir/include/mlir/Target/Cpp/CppEmitter.h:27:45: error: unknown type name 'raw_ostream'; did you mean 'llvm::raw_ostream'?
   27 | LogicalResult translateToCpp(Operation *op, raw_ostream &os,
      |                                             ^~~~~~~~~~~
      |                                             llvm::raw_ostream
Copy link
Collaborator

@josel-amd josel-amd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is not much to review here. But the new predicates sound handy.

Copy link
Collaborator

@josel-amd josel-amd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing much to review here. The isa predicate sounds handy.

@cferry-AMD
Copy link
Collaborator

LGTM

@mgehre-amd mgehre-amd merged commit 86e0d41 into feature/fused-ops Apr 29, 2024
4 checks passed
@mgehre-amd mgehre-amd deleted the matthias.backport_emitc branch April 29, 2024 13:55
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.

8 participants