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

Backport all EmitC commits #131

Merged
merged 21 commits into from
Mar 12, 2024
Merged

Conversation

mgehre-amd
Copy link
Collaborator

I didn't do any changes beyond resolving conflicts with our local EmitC changes (array type & subscript op).

aniragil and others added 6 commits March 11, 2024 15:51
Add an emitc.expression operation that models C expressions, and provide
transforms to form and fold expressions. The translator emits the body
of
emitc.expression ops as a single C expression.
This expression is emitted by default as the RHS of an EmitC SSA value,
but if
possible, expressions with a single use that is not another expression
are
instead inlined. Specific expression's inlining can be fine tuned by
lowering
passes and transforms.
When operations are modified in-place, the rewriter must be notified.
This commit fixes `mlir/test/Dialect/EmitC/transforms.mlir` when running
with `MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS` enabled.
…tributes (llvm#76066)

The parser and printer of string attributes were changed to handle
escape sequences. Therefore, we no longer require a custom parser and
printer. Verification is moved from the parser to the verifier
accordingly.
The `verbatim` operation produces no results and the value is emitted as
is followed by a line break ('\n' character) during translation.

Note: Use with caution. This operation can have arbitrary effects on the
semantics of the emitted code. Use semantically more meaningful
operations whenever possible. Additionally this op is *NOT* intended to
be used to inject large snippets of code.

This operation can be used in situations where a more suitable operation
is not yet implemented in the dialect or where preprocessor directives
interfere with the structure of the code.

Co-authored-by: Marius Brehler <marius.brehler@iml.fraunhofer.de>
The uses of the attribute were removed in code review of llvm#79584, but
it's definition was inadvertently kept.
@mgehre-amd mgehre-amd requested a review from TinaAMD March 11, 2024 15:26
@mgehre-amd mgehre-amd marked this pull request as draft March 11, 2024 15:27
marbre and others added 14 commits March 11, 2024 16:33
…lvm#79612)

This adds a `func`, `call` and `return` operation to the EmitC dialect,
closely related to the corresponding operations of the Func dialect. In
contrast to the operations of the Func dialect, the EmitC operations do
not support multiple results. The `emitc.func` op features a
`specifiers` argument that for example allows, with corresponding
support in the emitter, to emit `inline static` functions.

Furthermore, this adds patterns and a pass to convert the Func dialect
to EmitC. A `func.func` op that is `private` is converted to
`emitc.func` with a `"static"` specifier.
This adds a conversion from an externaly defined `func.func`, a
`func.func` without function body, to an `emitc.func` with an `extern`
specifier.
This adds the `emitc.declare_func` operation that allows to emit the
declaration of an `emitc.func` at a specific location.
This allows to omit the default valued attributes and therefore write
more compact code.
As part of the renaming the Standard dialect to Func dialect, *support*
for the `func.constant` operation was added to the emitter. However, the
emitter cannot emit function types. Hence the emission for a snippet
like

```
%0 = func.constant @myFN : (f32) -> f32

func.func private @myFN(%arg0: f32) -> f32 {
  return %arg0 : f32
}
```

failes with `func.mlir:1:6: error: cannot emit type '(f32) -> f32'`.
This removes `func.constant` from the emitter.
…#82770)

When creating a new block in (conversion) rewrite patterns,
`OpBuilder::createBlock` must be used. Otherwise, no
`notifyBlockInserted` notification is sent to the listener.

Note: The dialect conversion relies on listener notifications to keep
track of IR modifications. Creating blocks without the builder API can
lead to memory leaks during rollback.
This adds operations for the logical operators AND, NOT and OR.
This adds operations for bitwise operators. Furthermore, an UnaryOp
class and a helper to print unary operations are introduced.
Make it use and refer to `emitc.yield` and also fix type issues.
This adds a `CExpression` trait and replaces the `isCExpression()`
function.
This adds the `CExpression` trait to additional ops to allow to use
these ops within the expression operation. Furthermore, the operator
precedence is defined for those ops.
This adds operations for the unary minus and the unary plus operator.
This adds patterns and a pass to convert the Arith dialect to EmitC. For
now, this covers arithemtic binary ops operating on floating point
types.

It is not checked within the patterns whether the types, such as the
Tensor type, are supported in the respective EmitC operations. If
unsupported types should be converted, the conversion will fail anyway
because no legal EmitC operation can be created. This can clearly be
improved in a follow up, also resulting in better error messages.
Functions for such checks should not solely be used in the conversions
and should also be (re)used in the verifier.
@mgehre-amd mgehre-amd force-pushed the matthias.backport_emitc branch from 4735bee to 1dc743d Compare March 11, 2024 15:36
* Add a conversion from `arith.constant` to `emitc.constant`.
* Drop the translation for `arith.constant`s.
@mgehre-amd mgehre-amd force-pushed the matthias.backport_emitc branch from 1dc743d to 86a976b Compare March 11, 2024 15:38
@mgehre-amd mgehre-amd marked this pull request as ready for review March 11, 2024 15:38
Copy link

@TinaAMD TinaAMD left a comment

Choose a reason for hiding this comment

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

Thank you!

@mgehre-amd mgehre-amd merged commit 15893ae into feature/fused-ops Mar 12, 2024
6 checks passed
@mgehre-amd mgehre-amd deleted the matthias.backport_emitc branch March 12, 2024 08:28
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.

6 participants