Skip to content

Commit 7f85c56

Browse files
[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: llvm@dc9846c As such, there is no AIX test case attached to this patch. Reviewed By: daltenty Differential Revision: https://reviews.llvm.org/D137753
1 parent c65b4d6 commit 7f85c56

File tree

4 files changed

+9
-3
lines changed

4 files changed

+9
-3
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4179,6 +4179,7 @@ def pedantic_errors : Flag<["-", "--"], "pedantic-errors">, Group<pedantic_Group
41794179
MarshallingInfoFlag<DiagnosticOpts<"PedanticErrors">>;
41804180
def pedantic : Flag<["-", "--"], "pedantic">, Group<pedantic_Group>, Flags<[CC1Option,FlangOption,FC1Option]>,
41814181
HelpText<"Warn on language extensions">, MarshallingInfoFlag<DiagnosticOpts<"Pedantic">>;
4182+
def p : Flag<["-"], "p">, HelpText<"Enable mcount instrumentation with prof">;
41824183
def pg : Flag<["-"], "pg">, HelpText<"Enable mcount instrumentation">, Flags<[CC1Option]>,
41834184
MarshallingInfoFlag<CodeGenOpts<"InstrumentForProfiling">>;
41844185
def pipe : Flag<["-", "--"], "pipe">,
@@ -4225,7 +4226,6 @@ defm pthread : BoolOption<"", "pthread",
42254226
LangOpts<"POSIXThreads">, DefaultFalse,
42264227
PosFlag<SetTrue, [], "Support POSIX threads in generated code">,
42274228
NegFlag<SetFalse>, BothFlags<[CC1Option]>>;
4228-
def p : Flag<["-"], "p">;
42294229
def pie : Flag<["-"], "pie">, Group<Link_Group>;
42304230
def static_pie : Flag<["-"], "static-pie">, Group<Link_Group>;
42314231
def read__only__relocs : Separate<["-"], "read_only_relocs">;

clang/lib/Driver/ToolChains/AIX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA,
271271

272272
CmdArgs.push_back("-lc");
273273

274-
if (Args.hasArg(options::OPT_pg)) {
274+
if (Args.hasArg(options::OPT_p, options::OPT_pg)) {
275275
CmdArgs.push_back(Args.MakeArgString((llvm::Twine("-L") + D.SysRoot) +
276276
"/lib/profiled"));
277277
CmdArgs.push_back(Args.MakeArgString((llvm::Twine("-L") + D.SysRoot) +

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6331,7 +6331,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
63316331
}
63326332
}
63336333
if (Arg *A = Args.getLastArgNoClaim(options::OPT_p)) {
6334-
if (!TC.getTriple().isOSAIX() && !TC.getTriple().isOSOpenBSD()) {
6334+
if (TC.getTriple().isOSAIX()) {
6335+
CmdArgs.push_back("-pg");
6336+
} else if (!TC.getTriple().isOSOpenBSD()) {
63356337
D.Diag(diag::err_drv_unsupported_opt_for_target)
63366338
<< A->getAsString(Args) << TripleStr;
63376339
}

clang/test/Driver/aix-ld.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@
135135
// CHECK-LD32-PROF-NOT: "--no-as-needed"
136136
// CHECK-LD32-PROF-NOT: "-lm"
137137
// CHECK-LD32-PROF: "-lc"
138+
// CHECK-LD32-PROF: "-L[[SYSROOT]]/lib/profiled"
139+
// CHECK-LD32-PROF: "-L[[SYSROOT]]/usr/lib/profiled"
138140

139141
// Check powerpc64-ibm-aix7.1.0.0, 64-bit. Enable profiling.
140142
// RUN: %clang %s -### 2>&1 \
@@ -162,6 +164,8 @@
162164
// CHECK-LD64-PROF-NOT: "--no-as-needed"
163165
// CHECK-LD64-PROF-NOT: "-lm"
164166
// CHECK-LD64-PROF: "-lc"
167+
// CHECK-LD64-PROF: "-L[[SYSROOT]]/lib/profiled"
168+
// CHECK-LD64-PROF: "-L[[SYSROOT]]/usr/lib/profiled
165169

166170
// Check powerpc-ibm-aix7.1.0.0, 32-bit. Enable g-profiling.
167171
// RUN: %clang %s -### 2>&1 \

0 commit comments

Comments
 (0)