Skip to content

Commit a34ed3d

Browse files
address comments
1 parent a039b2a commit a34ed3d

File tree

3 files changed

+6
-20
lines changed

3 files changed

+6
-20
lines changed

mlir/docs/Tutorials/Toy/Ch-6.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,6 @@ enough for our use case.
8181
LLVMTypeConverter typeConverter(&getContext());
8282
```
8383
84-
For the `toy.print` lowering, we need a special type converter to ensure that
85-
the pattern receives a `memref` value in its adaptor. If we were to use the
86-
LLVM type converter, it would receive an `llvm.struct`, which is the normal
87-
lowering of a `memref` type to LLVM. If we were to use no type converter at
88-
all, it would receive a value with the original tensor type. (Note: The dialect
89-
conversion driver currently passes the "most recently mapped value", i.e., a
90-
value of unspecified type. This is a bug in the conversion driver.)
91-
9284
### Conversion Patterns
9385
9486
Now that the conversion target has been defined, we need to provide the patterns

mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class PrintOpLowering : public OpConversionPattern<toy::PrintOp> {
108108

109109
// Generate a call to printf for the current element of the loop.
110110
auto elementLoad =
111-
memref::LoadOp::create(rewriter, loc, adaptor.getInput(), loopIvs);
111+
memref::LoadOp::create(rewriter, loc, op.getInput(), loopIvs);
112112
LLVM::CallOp::create(rewriter, loc, getPrintfType(context), printfRef,
113113
ArrayRef<Value>({formatSpecifierCst, elementLoad}));
114114

@@ -221,11 +221,8 @@ void ToyToLLVMLoweringPass::runOnOperation() {
221221
populateFuncToLLVMConversionPatterns(typeConverter, patterns);
222222

223223
// The only remaining operation to lower from the `toy` dialect, is the
224-
// PrintOp. An identity converter is needed because the PrintOp lowering
225-
// operates on MemRefType instead of the lowered LLVM struct type.
226-
TypeConverter identityConverter;
227-
identityConverter.addConversion([](Type type) { return type; });
228-
patterns.add<PrintOpLowering>(identityConverter, &getContext());
224+
// PrintOp.
225+
patterns.add<PrintOpLowering>(&getContext());
229226

230227
// We want to completely lower to LLVM, so we use a `FullConversion`. This
231228
// ensures that only legal operations will remain after the conversion.

mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class PrintOpLowering : public OpConversionPattern<toy::PrintOp> {
108108

109109
// Generate a call to printf for the current element of the loop.
110110
auto elementLoad =
111-
memref::LoadOp::create(rewriter, loc, adaptor.getInput(), loopIvs);
111+
memref::LoadOp::create(rewriter, loc, op.getInput(), loopIvs);
112112
LLVM::CallOp::create(rewriter, loc, getPrintfType(context), printfRef,
113113
ArrayRef<Value>({formatSpecifierCst, elementLoad}));
114114

@@ -222,11 +222,8 @@ void ToyToLLVMLoweringPass::runOnOperation() {
222222
populateFuncToLLVMConversionPatterns(typeConverter, patterns);
223223

224224
// The only remaining operation to lower from the `toy` dialect, is the
225-
// PrintOp. An identity converter is needed because the PrintOp lowering
226-
// operates on MemRefType instead of the lowered LLVM struct type.
227-
TypeConverter identityConverter;
228-
identityConverter.addConversion([](Type type) { return type; });
229-
patterns.add<PrintOpLowering>(identityConverter, &getContext());
225+
// PrintOp.
226+
patterns.add<PrintOpLowering>(&getContext());
230227

231228
// We want to completely lower to LLVM, so we use a `FullConversion`. This
232229
// ensures that only legal operations will remain after the conversion.

0 commit comments

Comments
 (0)