This is an archive of the discontinued LLVM Phabricator instance.

[clang] Produce a "multiversion" annotation in textual AST output.
ClosedPublic

Authored by tahonermann on Mar 17 2022, 2:31 PM.

Details

Summary

This change adds a "multiversion" annotation to textual AST output.
For example:

FunctionDecl 0xb6628b0 <t.c:1:1, col:13> col:5 multiversion foo 'int (void)'

Diff Detail

Event Timeline

tahonermann created this revision.Mar 17 2022, 2:31 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 17 2022, 2:31 PM
tahonermann published this revision for review.Mar 17 2022, 2:53 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 17 2022, 2:53 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Is there a need for this functionality? The text node dumper already dumps attributes associated with the function: https://godbolt.org/z/EbW8E74TT

If the change is necessary, it needs some test coverage (I'd recommend adding the test to the clang/test/AST directory).

Is there a need for this functionality? The text node dumper already dumps attributes associated with the function: https://godbolt.org/z/EbW8E74TT

If the change is necessary, it needs some test coverage (I'd recommend adding the test to the clang/test/AST directory).

I would have found this helpful while working with MV functions in the past, particularly 'target' ones. So there is perhaps some value and minimal harm to this. That said, we definitely need a test.

Is there a need for this functionality?

Not a strong need, but I found it helpful in two scenarios:

  1. A forward declaration of a multiversion function is not required to include a multiversion function attribute; later declarations might trigger multiversioning.
  2. The target attribute does not necessarily declare a multiversion function.

Some examples:

void f();
__attribute__((target("default"))) void f(); // Causes multiversioning for the prior declaration.

__attribute__((target("mmx"))) void g(); // Not a multiversion function declaration.

__attribute__((target("mmx"))) void h();
__attribute__((target("sse"))) void h(); // Causes multiversioning for the prior declaration.

I'll add a test; thank you for the hint for where to add it.

Added a test.

Rebase to acquire fixes from parent commits.

aaron.ballman accepted this revision.Mar 19 2022, 12:01 PM

LGTM (I was surprised to see the Windows CI pass with that sed invocation!)

This revision is now accepted and ready to land.Mar 19 2022, 12:01 PM

I was surprised to see the Windows CI pass with that sed invocation!

Ha! I didn't even think about that. I had copied the RUN lines from another test and only adjusted what was necessary. The bots must have Cygwin, MSYS[2], GnuWin32, or similar installed.