[PATCH] D76571: [mlir] Start simple C++ backend

Jacques Pienaar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 22 11:45:18 PDT 2020


jpienaar created this revision.
jpienaar added a reviewer: mehdi_amini.
Herald added subscribers: llvm-commits, Joonsoo, liufengdb, aartbik, lucyrfox, mgester, arpith-jacob, nicolasvasilache, antiagainst, shauheen, burmako, rriddle, mgorny.
Herald added a project: LLVM.

Add simple C++ backend that uses dialect specific emitters & some
default/fallback emitters to emit simple MLIR modules as C++ functions. This is
useful for cases where you have a C++ compiler but no access to the codegen
(e.g., for using MLIR optimizations along with legacy or proprietary systems)
and for prototyping/debugging (e.g., found this useful to play with shape
functions). The backend itself is simple and may succeed in producing C++
output that cannot compile (e.g., it is simple/stupid and doesn't
understand/attempt to understand C++ semantics).

The fallback op emitter converts "foo.op" to "foo::op" followed by operands and
then attributes (in alphabetical order).

Multi-result functions/ops are lowered using std::tuple.

The dialect emitters are responsible for producing outputs for the attribute &
types.

Example added for builtin and standard dialect. For std.constant the
expectation is that the result type can be brace initialized with whatever the
attribute lowering of the value is. Only some basic ops supported in each of
these dialects and a couple of convenience functions added but supports a
couple of straightforward cases.

Interfaces would be a natural fit here except that there could be multiple
different emitters for the same dialect and that this is seen as not tightly
coupled with the IR/ops and so a less invasive approach is followed.

Only test to verify emit happens, not that emitted code can be compiled, will
follow up with an integration test.

Previous discussion: https://groups.google.com/a/tensorflow.org/d/msg/mlir/iOAB10Us6uo/wJ_pVQ_qBwAJ


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76571

Files:
  mlir/include/mlir/Target/Cpp.h
  mlir/lib/Target/CMakeLists.txt
  mlir/lib/Target/Cpp/TranslateToCpp.cpp
  mlir/lib/Target/Cpp/TranslateToCppRegistration.cpp
  mlir/test/Target/cpp-calls.mlir
  mlir/tools/mlir-translate/CMakeLists.txt

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76571.251906.patch
Type: text/x-patch
Size: 25911 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200322/47167deb/attachment.bin>


More information about the llvm-commits mailing list