This is an archive of the discontinued LLVM Phabricator instance.

[MLIR][LLVM] Inline LLVM::StackSaveOp and LLVM::StackRestoreOp.
ClosedPublic

Authored by definelicht on Apr 11 2023, 6:22 AM.

Details

Summary

Support LLVM::StackSaveOp and LLVM::StackRestoreOp in the LLVM dialect
inliner in MLIR.

Inserts new LLVM::StackSaveOp and LLVM::StackRestoreOp intrinsics when
dynamic allocas are detected in the inlined blocks. This may result in
multiple saves/restores in the same block if some are already present in
the caller, which is legal IR, but is cleaned up in LLVM. There is not
yet a canonicalization pattern for this on LLVM dialect in MLIR.

Diff Detail

Event Timeline

definelicht created this revision.Apr 11 2023, 6:22 AM
Herald added a reviewer: dcaballe. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
definelicht requested review of this revision.Apr 11 2023, 6:22 AM

Update naming and documentation to reflect dynamic alloca support.

Dinistro accepted this revision.Apr 11 2023, 11:15 PM

LGTM, just added a minor NIT comment.

mlir/lib/Dialect/LLVMIR/IR/LLVMInlining.cpp
81

NIT: I would prefer an llvm::any_of here.

This revision is now accepted and ready to land.Apr 11 2023, 11:15 PM

LGTM!

It would be good to double check before landing if LLVM somehow handles existing stack save and restore calls in the callable.

mlir/lib/Dialect/LLVMIR/IR/LLVMInlining.cpp
43

nit: I would start a new sentence after here (during code generation. The handler inserts ...)

57–58

nit: part of the entry block and not dynamic?

74

nit: I would drop this check and move the hasDynamicAlloca check from the end to the beginning of the outer loop to save one level of indention.

definelicht marked 4 inline comments as done.
definelicht edited the summary of this revision. (Show Details)

Address review comments and add additional inline documentation.