This is an archive of the discontinued LLVM Phabricator instance.

[mlir][llvm] Add AliasAnalysis and AccessGroup interfaces to intrinsics.
ClosedPublic

Authored by gysit on Feb 28 2023, 7:00 AM.

Details

Summary

This revision updates the memcpy, memove, and memset intrinsics to
implement the AliasAnalysis and AccessGroup interfaces. The changes
will enable the import and export of alias scope, tbaa, and
access group metadata attached to these intrinsics. It also
renames the requiresAliasScope flag to requiresAliasAnalysis since
the intrinsics also support tbaa and not only access scope metadata.

The revision still maintains the string based attribute lookup
in the translation from MLIR to LLVMIR. Using the interfaces
instead of the string based lookup is left to a followup revision.

Depends on D144851

Diff Detail

Event Timeline

gysit created this revision.Feb 28 2023, 7:00 AM
Herald added a project: Restricted Project. · View Herald Transcript
gysit requested review of this revision.Feb 28 2023, 7:00 AM
gysit added reviewers: Dinistro, frgossen, hgreving.EditedFeb 28 2023, 7:33 AM
gysit added subscribers: frgossen, hgreving.

@frgossen and @hgreving
https://reviews.llvm.org/D143654 caused problems since with the translation of alias and access group metadata.

https://reviews.llvm.org/D144851 will introduce AliasAnalysisOpInterface and AccessGroupOpInterface. These interfaces will provide access to the access group, alias scope, and tbaa metadata attributes (they also implement verification for these attributes). This revision adds the interfaces to the memcopy, memmove, and memset intrinsics. At the moment, the translation from MLIR to LLVM IR still uses the string based attribute lookup. In a follow up revision I plan to switch to using the new interfaces. Intrinsics automatically implement the interfaces if the requiresAccessGroup and requiresAliasAnalysis flags are set. Additionally, LLVM_IntrOpBase now defines the list of attributes aliasAttrs that need to be added to the argument list. Intrinsic setting the flags thus can add them as follows:

dag args = (ins Arg<LLVM_AnyPointer,"",[MemWrite]>:$dst,
                Arg<LLVM_AnyPointer,"",[MemRead]>:$src,
                AnySignlessInteger:$len, I1:$isVolatile);
// Append the alias attributes defined by LLVM_IntrOpBase.
let arguments = !con(args, aliasAttrs);

I also did an update to mlir/tools/mlir-tblgen/LLVMIRIntrinsicGen.cpp. Modifying it is a bit dangerous though since it does not have any upstream uses as far as I can tell. @hgreving you seem to have downstream uses for this? Would it make sense to move the file in the downstream project? Or am I completely mistaken and this is used somewhere (e.g. to regenerate parts of LLVMIntrinsicOps.td at some point)?

I'm not familiar with this tblgen part, so I suggest to wait for answers of the downstream users. The rest is looking nice.

gysit updated this revision to Diff 501773.Mar 2 2023, 12:29 AM

Consistently rename alias scopes to alias analysis in LLVMIRIntrinsicGen.cpp.

Dinistro accepted this revision.Mar 2 2023, 12:44 AM

After looking a bit closer over the tblgen part, I conclude that this looks good to me.

This revision is now accepted and ready to land.Mar 2 2023, 12:44 AM