This is an archive of the discontinued LLVM Phabricator instance.

[mlir][emitc] Add add and sub operations
ClosedPublic

Authored by marbre on May 5 2023, 8:09 AM.

Details

Summary

This adds operations for binary additive operators to EmitC. The input
arguments to these ops can be EmitC pointers and thus the operations can
be used for pointer arithmetic.

Diff Detail

Event Timeline

marbre created this revision.May 5 2023, 8:09 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 5 2023, 8:09 AM
marbre requested review of this revision.May 5 2023, 8:09 AM
marbre updated this revision to Diff 520359.May 8 2023, 7:00 AM

Updating D149963: [mlir][emitc] Add add and sub operations

Extend verifier to check emitc.sub result type.

marbre updated this revision to Diff 520654.May 9 2023, 4:19 AM

Updating D149963: [mlir][emitc] Add add and sub operations

Adds a base class for binary arithmetic operations and a custom assembly format.

marbre updated this revision to Diff 520655.May 9 2023, 4:22 AM

Updating D149963: [mlir][emitc] Add add and sub operations

Harmonize naming in the emitter.

marbre updated this revision to Diff 520664.May 9 2023, 5:33 AM

Updating D149963: [mlir][emitc] Add add and sub operations

Fix examples.

jpienaar added inline comments.May 10 2023, 6:23 AM
mlir/include/mlir/Dialect/EmitC/IR/EmitC.td
40

Is this really an add? Meaning, this would also allow to represent "adding" two classes. Why not operator_plus op that correspond to the form without adding any connotation with arithmetic? (the verifier could still flag illegal pointer usage, but don't know if we need commutative or will be doing arithmetic level optimizations here).

51

I'd be more interested in seeing what the resultant output is rather than custom and generic.

marbre added inline comments.May 10 2023, 6:32 AM
mlir/include/mlir/Dialect/EmitC/IR/EmitC.td
40

Indeed, adding two !emitc.opaque types could result in adding two classes. According to https://en.cppreference.com/w/cpp/language/operator_arithmetic the operator name of + is addition. But we can rename to operator_plus, no strong feelings here.

Commutative could be skipped.

51

You mean the generated C/C++ code added as example here?

jpienaar accepted this revision.Jun 5 2023, 7:54 AM
jpienaar added inline comments.
mlir/include/mlir/Dialect/EmitC/IR/EmitC.td
40

Good point (I was going off https://en.wikipedia.org/wiki/List_of_typographical_symbols_and_punctuation_marks and structural representation). Given C++ language already calls the operator that, I'd be fine with it (add, operator_add - probably doesn't make a difference as we'll never have both, so shorter is good). But yes lets drop commutative.

51

Yes, the generic form seems not specific to the op.

This revision is now accepted and ready to land.Jun 5 2023, 7:54 AM
This revision was automatically updated to reflect the committed changes.
marbre marked 2 inline comments as done.Jun 23 2023, 5:28 AM
marbre added inline comments.
mlir/include/mlir/Dialect/EmitC/IR/EmitC.td
51

I've added the generated code accordingly.