This is an archive of the discontinued LLVM Phabricator instance.

[AIX][PGO] Enable linux style PGO on AIX
ClosedPublic

Authored by w2yehia on May 3 2022, 8:27 AM.

Details

Summary

This patch switches the PGO implementation on AIX from using the runtime registration-based section tracking to the __start_SECNAME/__stop_SECNAME based.
In order to enable the recognition of __start_SECNAME/__stop_SECNAME symbols in the AIX linker, the -bdbg:namedsects:ss needs to be used.

Diff Detail

Event Timeline

w2yehia created this revision.May 3 2022, 8:27 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 3 2022, 8:27 AM
w2yehia requested review of this revision.May 3 2022, 8:27 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 3 2022, 8:27 AM
jsji added reviewers: MaskRay, Restricted Project.May 3 2022, 8:40 AM
jsji added inline comments.May 3 2022, 8:40 AM
compiler-rt/lib/profile/InstrProfilingPlatformLinux.c
11

What is the major reason that we want to share the file with Linux? Would it be better to have AIX on its own file?

Forking InstrProfilingPlatformLinux.c looks good to me. The misnomer *Linux.c file works with a number of ELF operating systems. Developers know that one feature working on one OS will likely work on others.

w2yehia added inline comments.May 3 2022, 9:45 AM
compiler-rt/lib/profile/InstrProfilingPlatformLinux.c
11

The main reason is the non-trivial amount of code duplication we will have if we split the AIX into its own file.

jsji accepted this revision as: jsji.May 3 2022, 9:50 AM

LGTM. Thanks.

This revision is now accepted and ready to land.May 3 2022, 9:50 AM
davidxl added a subscriber: davidxl.May 3 2022, 2:06 PM
davidxl added inline comments.
compiler-rt/lib/profile/InstrProfilingPlatformLinux.c
235

Why is this needed? For objects compiled with older compiler?

w2yehia added inline comments.May 4 2022, 6:01 AM
compiler-rt/lib/profile/InstrProfilingPlatformLinux.c
235

For objects compiled with older compiler?

Yes. On AIX, we would like to allow old object files to be linkable (and function correctly) with the new compiler. On AIX, old object files really mean object files compiled with LLVM 13.0 or newer.

w2yehia updated this revision to Diff 427024.May 4 2022, 8:53 AM

Add dummy variables to allow linking in general against the profile-rt on AIX in the default linking model (-bcdtos:all).

@davidxl @MaskRay @jsji FYI, please review the addition on line 242 of compiler-rt/lib/profile/InstrProfilingPlatformLinux.c

davidxl accepted this revision.May 4 2022, 9:25 AM

lgtm

MaskRay accepted this revision.May 4 2022, 9:30 AM
MaskRay added inline comments.
compiler-rt/lib/profile/InstrProfilingPlatformLinux.c
253

This has a -Wzero-length-array warning in -pedantic mode.

llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
860

You may place AIX before others for a relatively alphabetical order.

w2yehia updated this revision to Diff 427067.May 4 2022, 10:51 AM

Address one comment.

w2yehia marked an inline comment as done.May 4 2022, 10:56 AM
w2yehia added inline comments.
compiler-rt/lib/profile/InstrProfilingPlatformLinux.c
253

sorry but what's the correct way to resolve this on all platforms?
I see -Wno-pedantic is used when building this file if(FUCHSIA OR UNIX). Should I add -Wno-pedantic if such flag is supported by the build compiler in general?

MaskRay accepted this revision.May 4 2022, 11:03 AM
MaskRay added inline comments.
compiler-rt/lib/profile/InstrProfilingPlatformLinux.c
253

Many people don't build AIX so this isn't a problem for them (most build bots).

If you want suppress the warning for the AIX specific code, you may use

#pragma GCC diagnostic ignored "-Wpedantic"

This works with both GCC and Clang. I do not know how IBM XL/C behaves.

w2yehia added inline comments.May 4 2022, 11:32 AM
compiler-rt/lib/profile/InstrProfilingPlatformLinux.c
253

Right, I forgot this is guarded by the _AIX macro.
Since we already build with -Wno-pedantic on AIX, I don't need to suppress anything, right?
Here's the code in cmake that adds it. AIX is UNIX.

compiler-rt/lib/profile/CMakeLists.txt:
     89 if(FUCHSIA OR UNIX)
     90  set(EXTRA_FLAGS
     91      -fPIC
     92      -Wno-pedantic)
     93 endif()
w2yehia updated this revision to Diff 427085.May 4 2022, 11:34 AM
MaskRay added inline comments.May 4 2022, 12:00 PM
compiler-rt/lib/profile/InstrProfilingPlatformLinux.c
253

If you will not add -Wpedantic in the future, landing just the current form LGTM.

This revision was landed with ongoing or failed builds.May 4 2022, 9:11 PM
This revision was automatically updated to reflect the committed changes.
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptMay 4 2022, 9:11 PM
Herald added subscribers: Restricted Project, cfe-commits. · View Herald Transcript