[PATCH] D136192: [AIX][PGO] WIP

wael yehia via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 18 11:59:18 PDT 2022


w2yehia created this revision.
Herald added subscribers: Enna1, wenlei, hiraditya.
Herald added a project: All.
w2yehia requested review of this revision.
Herald added subscribers: llvm-commits, MaskRay.
Herald added a project: LLVM.

https://reviews.llvm.org/D136192

Files:
  clang/lib/Driver/ToolChains/AIX.cpp
  clang/lib/Driver/ToolChains/AIX.h
  compiler-rt/lib/profile/InstrProfilingRuntime.cpp
  llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp


Index: llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
===================================================================
--- llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
+++ llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
@@ -1192,7 +1192,7 @@
 bool InstrProfiling::emitRuntimeHook() {
   // We expect the linker to be invoked with -u<hook_var> flag for Linux
   // in which case there is no need to emit the external variable.
-  if (TT.isOSLinux())
+  if (TT.isOSLinux() || TT.isOSAIX())
     return false;
 
   // If the module's provided its own runtime, we don't need to do anything.
Index: compiler-rt/lib/profile/InstrProfilingRuntime.cpp
===================================================================
--- compiler-rt/lib/profile/InstrProfilingRuntime.cpp
+++ compiler-rt/lib/profile/InstrProfilingRuntime.cpp
@@ -5,7 +5,6 @@
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
-
 extern "C" {
 
 #include "InstrProfiling.h"
@@ -14,8 +13,6 @@
 COMPILER_RT_VISIBILITY int INSTR_PROF_PROFILE_RUNTIME_VAR;
 }
 
-namespace {
-
 class RegisterRuntime {
 public:
   RegisterRuntime() {
@@ -23,6 +20,9 @@
   }
 };
 
-RegisterRuntime Registration;
-
-}
+#ifdef _AIX
+COMPILER_RT_VISIBILITY
+#else
+static
+#endif
+RegisterRuntime __llvm_register_runtime;
Index: clang/lib/Driver/ToolChains/AIX.h
===================================================================
--- clang/lib/Driver/ToolChains/AIX.h
+++ clang/lib/Driver/ToolChains/AIX.h
@@ -82,6 +82,9 @@
 
   void AddMASSLibArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const;
 
+  void addProfileRTLibs(const llvm::opt::ArgList &Args,
+                        llvm::opt::ArgStringList &CmdArgs) const override;
+
   CXXStdlibType GetDefaultCXXStdlibType() const override;
 
   RuntimeLibType GetDefaultRuntimeLibType() const override;
Index: clang/lib/Driver/ToolChains/AIX.cpp
===================================================================
--- clang/lib/Driver/ToolChains/AIX.cpp
+++ clang/lib/Driver/ToolChains/AIX.cpp
@@ -417,6 +417,17 @@
     CmdArgs.push_back(Args.MakeArgString(XLOptPath));
 }
 
+void AIX::addProfileRTLibs(const llvm::opt::ArgList &Args,
+                           llvm::opt::ArgStringList &CmdArgs) const {
+  // Add linker option -u__llvm_register_runtime to cause runtime
+  // initialization module to be linked in.
+  // On AIX, we need to keep the exact global who's constructor does the
+  // initialization in order for linking with -bcdtors:csect to work.
+  if (needsProfileRT(Args))
+    CmdArgs.push_back(Args.MakeArgString(Twine("-u__llvm_register_runtime")));
+  ToolChain::addProfileRTLibs(Args, CmdArgs);
+}
+
 ToolChain::CXXStdlibType AIX::GetDefaultCXXStdlibType() const {
   return ToolChain::CST_Libcxx;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136192.468640.patch
Type: text/x-patch
Size: 2862 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221018/6164f748/attachment.bin>


More information about the llvm-commits mailing list