diff options
| author | Nicolas Vasilache <ntv@google.com> | 2019-09-24 11:21:04 -0700 |
|---|---|---|
| committer | A. Unique TensorFlower <gardener@tensorflow.org> | 2019-09-24 11:21:49 -0700 |
| commit | 42d8fa667bcdb81ad305e64a4d6fb0ff1cc4cc3d (patch) | |
| tree | 0ee6fa9213a13fb449229dc95f43905d6d1b0f78 /mlir/examples/toy | |
| parent | 74cdbf5909e57b42b6ed5b3b6eea4f76448a7d48 (diff) | |
| download | bcm5719-llvm-42d8fa667bcdb81ad305e64a4d6fb0ff1cc4cc3d.tar.gz bcm5719-llvm-42d8fa667bcdb81ad305e64a4d6fb0ff1cc4cc3d.zip | |
Normalize lowering of MemRef types
The RFC for unifying Linalg and Affine compilation passes into an end-to-end flow with a predictable ABI and linkage to external function calls raised the question of why we have variable sized descriptors for memrefs depending on whether they have static or dynamic dimensions (https://groups.google.com/a/tensorflow.org/forum/#!topic/mlir/MaL8m2nXuio).
This CL standardizes the ABI on the rank of the memrefs.
The LLVM struct for a memref becomes equivalent to:
```
template <typename Elem, size_t Rank>
struct {
Elem *ptr;
int64_t sizes[Rank];
};
```
PiperOrigin-RevId: 270947276
Diffstat (limited to 'mlir/examples/toy')
| -rw-r--r-- | mlir/examples/toy/Ch5/mlir/LateLowering.cpp | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/mlir/examples/toy/Ch5/mlir/LateLowering.cpp b/mlir/examples/toy/Ch5/mlir/LateLowering.cpp index 95585f93407..28dc7174a4f 100644 --- a/mlir/examples/toy/Ch5/mlir/LateLowering.cpp +++ b/mlir/examples/toy/Ch5/mlir/LateLowering.cpp @@ -149,6 +149,7 @@ public: // Create our loop nest now using namespace edsc; + using extractvalue = intrinsics::ValueBuilder<LLVM::ExtractValueOp>; using llvmCall = intrinsics::ValueBuilder<LLVM::CallOp>; ScopedContext scope(rewriter, loc); ValueHandle zero = intrinsics::constant_index(0); @@ -157,26 +158,36 @@ public: IndexedValue iOp(operand); IndexHandle i, j, M(vOp.ub(0)); + auto *dialect = op->getContext()->getRegisteredDialect<LLVM::LLVMDialect>(); + auto i8PtrTy = LLVM::LLVMType::getInt8Ty(dialect).getPointerTo(); + ValueHandle fmtEol(getConstantCharBuffer(rewriter, loc, "\n")); if (vOp.rank() == 1) { // clang-format off LoopBuilder(&i, zero, M, 1)([&]{ llvmCall(retTy, rewriter.getSymbolRefAttr(printfFunc), - {fmtCst, iOp(i)}); + {extractvalue(i8PtrTy, fmtCst, rewriter.getIndexArrayAttr(0)), + iOp(i)}); }); - llvmCall(retTy, rewriter.getSymbolRefAttr(printfFunc), {fmtEol}); + llvmCall(retTy, rewriter.getSymbolRefAttr(printfFunc), + {extractvalue(i8PtrTy, fmtEol, rewriter.getIndexArrayAttr(0))}); // clang-format on } else { IndexHandle N(vOp.ub(1)); // clang-format off LoopBuilder(&i, zero, M, 1)([&]{ LoopBuilder(&j, zero, N, 1)([&]{ - llvmCall(retTy, - rewriter.getSymbolRefAttr(printfFunc), - {fmtCst, iOp(i, j)}); + llvmCall( + retTy, + rewriter.getSymbolRefAttr(printfFunc), + {extractvalue(i8PtrTy, fmtCst, rewriter.getIndexArrayAttr(0)), + iOp(i, j)}); }); - llvmCall(retTy, rewriter.getSymbolRefAttr(printfFunc), {fmtEol}); + llvmCall( + retTy, + rewriter.getSymbolRefAttr(printfFunc), + {extractvalue(i8PtrTy, fmtEol, rewriter.getIndexArrayAttr(0))}); }); // clang-format on } |

