This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Lower DimOp to LLVM for unranked memrefs.
ClosedPublic

Authored by pifon2a on Aug 5 2020, 2:03 PM.

Diff Detail

Event Timeline

pifon2a created this revision.Aug 5 2020, 2:03 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 5 2020, 2:03 PM
pifon2a requested review of this revision.Aug 5 2020, 2:03 PM
herhut added inline comments.Aug 6 2020, 12:33 AM
mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp
2400

Should this be a helper in UnrankedMemRefDescriptor? This will likely get used in other places (we already to it in some hlo cast operation I think). Something like getOffsetPtr getSizesPtr and getStridesPtr which return the pointer to index?

2439

Just fall through to the implementation below? If it is dynamic, i being constant does not help.

2451

Why does this need rank explicit and the above does not?

mlir/lib/Dialect/StandardOps/IR/Ops.cpp
1345–1346

Nit: You could cast to ShapedType and then query hasRank. We have a cast to shaped type below already.

1346

Remove extra {}

pifon2a updated this revision to Diff 283524.Aug 6 2020, 1:35 AM
pifon2a marked 5 inline comments as done.

Address the comments and fix mlir-cpu-runner tests in cmake.

mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp
2400

Definitely, I was planning to do that when lowering memrefcast ops. It is also not trivial, because this code uses TypeConverter and addressSpace that are not a part of UnrankedMemRefDescriptor. I don't think it should be a member of the descriptor. But it can be a useful utility. Not in this CL.

2439

i left the old code pretty much untouched. Thanks for noticing. These two different size methods are emit different code. See the comment below.

2451

the one with the rank emits GEPs and they use rank to construct array type with shapes (it is not really needed though).
the one without the rank emits ExtractElementOp .

herhut added inline comments.Aug 6 2020, 2:25 AM
mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp
2439

So you could do if (!memRefType.isDynamicDim(i)) and otherwise fall through to the below case, removing the extra rank. Otherwise we have the same code essentially twice here.

2451

So can we just drop it here?

herhut accepted this revision.Aug 6 2020, 2:41 AM

Thanks for clarifying!

mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp
2439

So, discussed this offline. The difference here is that using this form of size creates better code and hence is used here. Having a static index enables this.

Maybe it would be nice if size could do this internally but that is not for this PR. @ftynse WDYT

This revision is now accepted and ready to land.Aug 6 2020, 2:41 AM
This revision was automatically updated to reflect the committed changes.