This is an archive of the discontinued LLVM Phabricator instance.

[MLIR][LLVM] Support inlining of LLVM::AllocaOp.
ClosedPublic

Authored by definelicht on Jan 24 2023, 12:42 AM.

Details

Summary

If inlining into an LLVM function, move allocas of constant size from
the callee's entry block to the new entry block, as this will fold into
the prologue/epilogue code during code generation.

We still allow inlining allocas even if we cannot do this
post-processing (i.e., when we are not inlining into an LLVM::FuncOp),
since this is an optimization (and thus not necessary for correctness).

Depends on D141682

Diff Detail

Event Timeline

definelicht created this revision.Jan 24 2023, 12:42 AM
Herald added a project: Restricted Project. · View Herald Transcript
definelicht requested review of this revision.Jan 24 2023, 12:42 AM

Purged outdated comment.

Update signature and tests.

Updated tests to not return alloca'ed pointers, since this is nonsensical code.
Changed function signature to take the inlined blocks directly.

tblah added a subscriber: tblah.Jan 26 2023, 3:42 AM
gysit accepted this revision.Jan 26 2023, 4:08 AM

LGTM!

mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
2861–2862

nit: What about changing to

"Conservatively move only alloca operations that are part of the entry block and do not inspect nested regions, since they may execute conditionally or have other unknown semantics."

?

2951

ultra nit: alloca -> Alloca

This revision is now accepted and ready to land.Jan 26 2023, 4:08 AM
definelicht marked an inline comment as done.

Update inline comment.

definelicht marked an inline comment as done.Jan 26 2023, 4:21 AM

Address ultra nit on capitalization.

This revision was automatically updated to reflect the committed changes.