[clang] 7f85c56 - [Clang][AIX][p]Enable -p Functionality
Michael Francis via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 9 08:13:56 PST 2023
Author: Michael Francis
Date: 2023-02-09T16:13:51Z
New Revision: 7f85c560b43bd1b2ebf77cc443281b474b5e19c6
URL: https://github.com/llvm/llvm-project/commit/7f85c560b43bd1b2ebf77cc443281b474b5e19c6
DIFF: https://github.com/llvm/llvm-project/commit/7f85c560b43bd1b2ebf77cc443281b474b5e19c6.diff
LOG: [Clang][AIX][p]Enable -p Functionality
This patch enables `-p` functionality into Clang on AIX and Linux
To create parity with GCC.
The purpose of the `-p` flag is similar to that of `-pg`, but the
results are analyzed with the `prof` tool as opposed to the `gprof` tool.
More details can be found in this RFC post:
https://discourse.llvm.org/t/rfc-add-p-driver-support-to-clang/66013?u=francii
On AIX, compiling with `-p` links against `mcrt0.o`
and produces a mon.out file analyzed with the `prof` tool,
while `-pg` links against `gcrt0.o` and produces a `gmon.out`file
analyzed with the `gprof` tool. The differences are therefore
only a concern when linking, so calling `-p` will push `-pg` to cc1.
An AIX test for `-p` already exists, and I recently
another test was added here:
https://github.com/llvm/llvm-project/commit/dc9846ce988b9ddfcbc42cd462d5d94b634b3161
As such, there is no AIX test case attached to this patch.
Reviewed By: daltenty
Differential Revision: https://reviews.llvm.org/D137753
Added:
Modified:
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/AIX.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/aix-ld.c
Removed:
################################################################################
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 6e7cdf131d937..9766a087eb6d9 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4179,6 +4179,7 @@ def pedantic_errors : Flag<["-", "--"], "pedantic-errors">, Group<pedantic_Group
MarshallingInfoFlag<DiagnosticOpts<"PedanticErrors">>;
def pedantic : Flag<["-", "--"], "pedantic">, Group<pedantic_Group>, Flags<[CC1Option,FlangOption,FC1Option]>,
HelpText<"Warn on language extensions">, MarshallingInfoFlag<DiagnosticOpts<"Pedantic">>;
+def p : Flag<["-"], "p">, HelpText<"Enable mcount instrumentation with prof">;
def pg : Flag<["-"], "pg">, HelpText<"Enable mcount instrumentation">, Flags<[CC1Option]>,
MarshallingInfoFlag<CodeGenOpts<"InstrumentForProfiling">>;
def pipe : Flag<["-", "--"], "pipe">,
@@ -4225,7 +4226,6 @@ defm pthread : BoolOption<"", "pthread",
LangOpts<"POSIXThreads">, DefaultFalse,
PosFlag<SetTrue, [], "Support POSIX threads in generated code">,
NegFlag<SetFalse>, BothFlags<[CC1Option]>>;
-def p : Flag<["-"], "p">;
def pie : Flag<["-"], "pie">, Group<Link_Group>;
def static_pie : Flag<["-"], "static-pie">, Group<Link_Group>;
def read__only__relocs : Separate<["-"], "read_only_relocs">;
diff --git a/clang/lib/Driver/ToolChains/AIX.cpp b/clang/lib/Driver/ToolChains/AIX.cpp
index f62b566c3946e..15560e1c81bca 100644
--- a/clang/lib/Driver/ToolChains/AIX.cpp
+++ b/clang/lib/Driver/ToolChains/AIX.cpp
@@ -271,7 +271,7 @@ void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back("-lc");
- if (Args.hasArg(options::OPT_pg)) {
+ if (Args.hasArg(options::OPT_p, options::OPT_pg)) {
CmdArgs.push_back(Args.MakeArgString((llvm::Twine("-L") + D.SysRoot) +
"/lib/profiled"));
CmdArgs.push_back(Args.MakeArgString((llvm::Twine("-L") + D.SysRoot) +
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index e7ba912403d83..3aff071d75394 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6331,7 +6331,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
}
}
if (Arg *A = Args.getLastArgNoClaim(options::OPT_p)) {
- if (!TC.getTriple().isOSAIX() && !TC.getTriple().isOSOpenBSD()) {
+ if (TC.getTriple().isOSAIX()) {
+ CmdArgs.push_back("-pg");
+ } else if (!TC.getTriple().isOSOpenBSD()) {
D.Diag(diag::err_drv_unsupported_opt_for_target)
<< A->getAsString(Args) << TripleStr;
}
diff --git a/clang/test/Driver/aix-ld.c b/clang/test/Driver/aix-ld.c
index 8f0125c272a69..38ac440aabdc6 100644
--- a/clang/test/Driver/aix-ld.c
+++ b/clang/test/Driver/aix-ld.c
@@ -135,6 +135,8 @@
// CHECK-LD32-PROF-NOT: "--no-as-needed"
// CHECK-LD32-PROF-NOT: "-lm"
// CHECK-LD32-PROF: "-lc"
+// CHECK-LD32-PROF: "-L[[SYSROOT]]/lib/profiled"
+// CHECK-LD32-PROF: "-L[[SYSROOT]]/usr/lib/profiled"
// Check powerpc64-ibm-aix7.1.0.0, 64-bit. Enable profiling.
// RUN: %clang %s -### 2>&1 \
@@ -162,6 +164,8 @@
// CHECK-LD64-PROF-NOT: "--no-as-needed"
// CHECK-LD64-PROF-NOT: "-lm"
// CHECK-LD64-PROF: "-lc"
+// CHECK-LD64-PROF: "-L[[SYSROOT]]/lib/profiled"
+// CHECK-LD64-PROF: "-L[[SYSROOT]]/usr/lib/profiled
// Check powerpc-ibm-aix7.1.0.0, 32-bit. Enable g-profiling.
// RUN: %clang %s -### 2>&1 \
More information about the cfe-commits
mailing list