Skip to content

Conversation

@tonykuttai
Copy link

@tonykuttai tonykuttai commented Oct 18, 2025

Add support for the #pragma comment (copyright, "Copyright info") directive for AIX.

This builds on top of PR #159096

Refernce: XL documentation for #pragma comment

@@ -0,0 +1,110 @@
// REQUIRES: powerpc-registered-target, system-aix, clang

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this test fits with the LLVM unit testing philosophy.

My understanding is that we have tests

  • for the front-end generation of the aix.copyright.comment metadata, and
  • for the transformation of the aix.copyright.comment metadata to implicit.ref, etc.

What we do not have are targeted tests that specifically verify that the transformation is run at the right point in the various possible pipelines.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right. Removed this test.

Copy link
Author

@tonykuttai tonykuttai Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What we do not have are targeted tests that specifically verify that the transformation is run at the right point in the various possible pipelines.

Added the opt levels testing to llvm/test/Transforms/CopyrightMetadata/copyright-metadata.ll. Do we need an end-to-end test ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a end-to-end test ?

I can't say that we shouldn't have one. It is just that I am not aware of there being any in upstream LLVM that involve the linker (except when it's an lld test).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find anything similar as well.

@tonykuttai tonykuttai force-pushed the tvarghese/pragma-comment-copyright branch from 438f04c to cfa6019 Compare October 21, 2025 14:22
@tonykuttai tonykuttai force-pushed the tvarghese/pragma-comment-copyright branch from 252f063 to 82254ee Compare October 22, 2025 11:58
@tonykuttai
Copy link
Author

Added the test clang/test/CodeGen/PowerPC/pragma-comment-copyright-aix-modules.cpp to test the C++ 20 Modules getting ignored in the importing TU.

Copy link

@hubert-reinterpretcast hubert-reinterpretcast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some partial review comments...

Comment on lines 4 to 7
; RUN: opt --O0 -S %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-O0
; RUN: opt --O1 -S %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-ON
; RUN: opt --O2 -S %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-ON
; RUN: opt --O3 -S %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-ON

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar enough with how the pipelines are built between different tools (clang, opt, etc.) to know if this is the right way to check that the pass is in the pipeline at the right place (especially for LTO).

@w2yehia @mandlebug, your input would be appreciated.

; - Emits the string in a dedicated read-only csect
;
; CHECK-ASM: .ref __aix_copyright_str
; CHECK-ASM: .csect __aix_copyright[RO],2

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the churn. The check in llvm/test/Transforms/CopyrightMetadata/copyright-metadata.ll for constant in the IR is sufficient for establishing that we are generating as read-only, so the testing request from #1 (comment) was already satisfied (and we don't need this test just to cover that).

It is still a question whether we want to group the strings into one csect (which probably has no effect except under "full" LTO where it will increase the chance of the string being kept).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, sure. Removing the llvm/test/CodeGen/PowerPC/pragma-comment-copyright-aix.ll.

It is still a question whether we want to group the strings into one csect (which probably has no effect except under "full" LTO where it will increase the chance of the string being kept).

Are there any downsides to the current approach ? I think it is cleaner to group them seperately in a csect.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any downsides to the current approach ?

It generates "false positives" to the question of whether the content associated with the copyright string was actually retained/relevant to the result.

Copy link

@hubert-reinterpretcast hubert-reinterpretcast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add updates to existing tests so that they continue to pass. For example, llvm/test/Other/new-pm-defaults.ll fails with:

# .---command stderr------------
# | /llvm/test/Other/new-pm-defaults.ll:241:23: error: CHECK-DEFAULT-NEXT: is not on the line after the previous match
# | ; CHECK-DEFAULT-NEXT: Running pass: EliminateAvailableExternallyPass
# |                       ^
# | <stdin>:100:1: note: 'next' match was here
# | Running pass: EliminateAvailableExternallyPass on [module]
# | ^
# | <stdin>:98:28: note: previous match ended here
# | Running pass: GlobalDCEPass on [module]
# |                            ^
# | <stdin>:99:1: note: non-matching line after previous match is here
# | Running pass: CopyrightMetadataPass on [module]
# | ^

@mandlebug mandlebug force-pushed the XCOFFAssociatedMetadata branch from 325741a to 4d6f365 Compare December 3, 2025 20:37
@tonykuttai tonykuttai force-pushed the tvarghese/pragma-comment-copyright branch from 19a0c93 to a2904ba Compare December 5, 2025 05:55
@tonykuttai
Copy link
Author

Rebased the branch with latest updates from mandlebug:XCOFFAssociatedMetadata

MODULE_PASS("constmerge", ConstantMergePass())
MODULE_PASS("coro-cleanup", CoroCleanupPass())
MODULE_PASS("coro-early", CoroEarlyPass())
MODULE_PASS("copyright-metadata", CopyrightMetadataPass())
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name of this pass should be updated too so it is independent of the word "copyright". Nothing in the IR refers to copyright. To make it easier for people to understand, the pass name should reflect the IR meta data it is processing.

Copy link
Author

@tonykuttai tonykuttai Dec 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about LowerCommentStringPass or LowerLoadTimeCommentPass?

// Input IR:
// !comment_string.loadtime = !{!"Copyright"}
// Output IR:
// @__loadtime_copyright_str = internal constant [N x i8] c"Copyright\00",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename this to __loadtime_comment_str.

// !comment_string.loadtime = !{!"Copyright"}
// Output IR:
// @__loadtime_copyright_str = internal constant [N x i8] c"Copyright\00",
// section "__copyright_comment"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this can be renamed too. Something like __loadtime_comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants