This is an archive of the discontinued LLVM Phabricator instance.

[mlir][spirv] Lower memref.reinterpret_cast
ClosedPublic

Authored by Hardcode84 on Jul 11 2023, 1:13 PM.

Details

Summary

For kernel SPIR-V, we are lowering memref to bare pointers, so reinterpret can be lowered to pointer, adjusted by offset value.

Diff Detail

Event Timeline

Hardcode84 created this revision.Jul 11 2023, 1:13 PM
Herald added a reviewer: kuhar. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
Hardcode84 requested review of this revision.Jul 11 2023, 1:13 PM
kuhar added a comment.Jul 12 2023, 1:25 PM

The logic seems fine to me, just some stylistic issues.

@antiagainst, can you also take a look?

mlir/lib/Conversion/MemRefToSPIRV/MemRefToSPIRV.cpp
260

nit: add final

265–266

For consistency with the other code in this file, this function should be defined outside of the class definition.

272–273

nit: Use llvm::formatv for the diag message: rewriter.notifyMatchFailure(op, llvm::formatv(...)). You can find examples in other spirv patterns, so this is mostly for consistency with that code.

276

nit: auto doesn't improve readability here IMO, consider spelling out the type whenever it's not obvious based on the RHS

279–280

nit: Use converter->convertType<spirv::PointerType>(...)

282–283

also here

298

nit: Location loc

antiagainst accepted this revision.Jul 12 2023, 5:21 PM

LGTM. Just a few more nits.

mlir/lib/Conversion/MemRefToSPIRV/MemRefToSPIRV.cpp
277

This assert is not necessary? The converter pretty much always exists there.

296

"failed to convert index type" to be clear.

311

Nit: I'd just do

auto acOp = rewriter.create<spirv::InBoundsPtrAccessChainOp>(loc, src, offsetValue, std::nullopt);
rewriter.replaceOp(op, acOp.getResult());

to make it indent nicer.

This revision is now accepted and ready to land.Jul 12 2023, 5:21 PM
antiagainst retitled this revision from [mlir][SPIR-V] Lower memref.reinterpret_cast to [mlir][spirv] Lower memref.reinterpret_cast.Jul 12 2023, 5:21 PM

rebase, review comments

Hardcode84 marked 8 inline comments as done.Jul 13 2023, 4:32 AM
Hardcode84 added inline comments.
mlir/lib/Conversion/MemRefToSPIRV/MemRefToSPIRV.cpp
272–273

Actually, I don't see any formatv usage in this file but I see diag usage.

311

Changed to replaceOpWithNewOp

This revision was automatically updated to reflect the committed changes.
Hardcode84 marked an inline comment as done.