This is an archive of the discontinued LLVM Phabricator instance.

[IRGen] Change annotation metadata to support inserting tuple of strings into annotation metadata array.
ClosedPublic

Authored by zjaffal on Apr 14 2023, 4:42 AM.

Details

Summary

Annotation metadata supports adding singular annotation strings to annotation block. This patch adds the ability to insert a tuple of strings into the metadata array.

The idea here is that each tuple of strings represents a piece of information that can be all related. It makes it easier to parse through related metadata information given it will be contained in one tuple.
For example in remarks any pass that implements annotation remarks can have different type of remarks and pass additional information for each.

The original behaviour of annotation remarks is preserved here and we can mix tuple annotations and single annotations for the same instruction.

Diff Detail

Event Timeline

zjaffal created this revision.Apr 14 2023, 4:42 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 14 2023, 4:42 AM
zjaffal requested review of this revision.Apr 14 2023, 4:42 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 14 2023, 4:42 AM

This would also require an update to https://llvm.org/docs/LangRef.html#annotation-metadata

Could you also add the motivation for this change to the description?

zjaffal updated this revision to Diff 514243.Apr 17 2023, 7:56 AM

Update LangRef.rst

zjaffal edited the summary of this revision. (Show Details)Apr 17 2023, 8:00 AM

Currently annotation metadata can only support a tuple of strings.

I think the commit message is incorrect?

For example in remarks any pass that implements annotation remarks can have different type of remarks and pass additional information for each.

Is it possible to test the new tuple behaviour using any existing remarks? Or will that be in a follow-up?

llvm/lib/CodeGen/MachineFunction.cpp
122

This pattern appears a lot; should it be pulled out into a helper function?

llvm/lib/IR/Metadata.cpp
1555

Should this be captured by reference instead of copied?

llvm/lib/Transforms/Scalar/AnnotationRemarks.cpp
66

Since AnnotationTuple is only used in AnnotationStr, we can pull it into the getString() call and eliminate the braces around the else.

Or you could write it via the ternary operator:

StringRef AnnotationStr = isa<MDString>(Op.get())) ?
                                             cast<MDString>(Op.get())->getString() :
                                             cast<MDString>(cast<MDTuple>(Op.get())->getOperand(0).get())->getString();
zjaffal updated this revision to Diff 516748.Apr 25 2023, 4:34 AM
  • Address comments
zjaffal retitled this revision from [IRGen] Change annotation metadata to support a tuple of strings. to [IRGen] Change annotation metadata to support inserting tuple of strings into annotation metadata array..Apr 25 2023, 4:35 AM
zjaffal edited the summary of this revision. (Show Details)
paquette accepted this revision.Apr 28 2023, 3:35 PM

I have one nit but other than that this LGTM

llvm/include/llvm/IR/Metadata.h
795

just return this?

This revision is now accepted and ready to land.Apr 28 2023, 3:35 PM
This revision was landed with ongoing or failed builds.May 9 2023, 7:51 AM
This revision was automatically updated to reflect the committed changes.