This adds a new option -fauto-profile=filename to Clang. It tells the driver to schedule the auto-profile pass and passes on the name of the profile file to use.
This patch depends on the initial auto profile patch I posted a couple of weeks ago: http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20130923/188838.html Diego.
>From bcfe88d501ad4ea299f0b64ce98b375c248a45c9 Mon Sep 17 00:00:00 2001 From: Diego Novillo <[email protected]> Date: Wed, 2 Oct 2013 10:46:34 -0400 Subject: [PATCH] Add -fauto-profile to Clang's driver. This adds a new option -fauto-profile=filename to Clang. It tells the driver to schedule the auto-profile pass and passes on the name of the profile file to use. --- include/clang/Driver/Options.td | 4 ++++ include/clang/Frontend/CodeGenOptions.h | 3 +++ lib/CodeGen/BackendUtil.cpp | 12 ++++++++++++ lib/Driver/Tools.cpp | 4 ++++ lib/Frontend/CompilerInvocation.cpp | 1 + test/Driver/clang_f_opts.c | 3 +++ 6 files changed, 27 insertions(+) diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index d058249..9793386 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -363,6 +363,10 @@ def fno_autolink : Flag <["-"], "fno-autolink">, Group<f_Group>, Flags<[DriverOption, CC1Option]>, HelpText<"Disable generation of linker directives for automatic library linking">; +def fauto_profile_EQ : Joined<["-"], "fauto-profile=">, Group<f_Group>, + Flags<[DriverOption, CC1Option]>, + HelpText<"Enable automatic profile guided optimizations">; + def fblocks : Flag<["-"], "fblocks">, Group<f_Group>, Flags<[CC1Option]>, HelpText<"Enable the 'blocks' language feature">; def fbootclasspath_EQ : Joined<["-"], "fbootclasspath=">, Group<f_Group>; diff --git a/include/clang/Frontend/CodeGenOptions.h b/include/clang/Frontend/CodeGenOptions.h index 45d2bda..130cf0e 100644 --- a/include/clang/Frontend/CodeGenOptions.h +++ b/include/clang/Frontend/CodeGenOptions.h @@ -131,6 +131,9 @@ public: /// A list of dependent libraries. std::vector<std::string> DependentLibraries; + /// Name of the profile file to use with -fauto-profile. + std::string AutoProfileFile; + public: // Define accessors/mutators for code generation options of enumeration type. #define CODEGENOPT(Name, Bits, Default) diff --git a/lib/CodeGen/BackendUtil.cpp b/lib/CodeGen/BackendUtil.cpp index 9943287..b9e39f4 100644 --- a/lib/CodeGen/BackendUtil.cpp +++ b/lib/CodeGen/BackendUtil.cpp @@ -154,6 +154,14 @@ static void addObjCARCOptPass(const PassManagerBuilder &Builder, PassManagerBase PM.add(createObjCARCOptPass()); } +static void addAutoProfilePass(const PassManagerBuilder &Builder, + PassManagerBase &PM) { + const PassManagerBuilderWrapper &BuilderWrapper = + static_cast<const PassManagerBuilderWrapper&>(Builder); + const CodeGenOptions &opts = BuilderWrapper.getCGOpts(); + PM.add(createAutoProfilePass(opts.AutoProfileFile)); +} + static void addBoundsCheckingPass(const PassManagerBuilder &Builder, PassManagerBase &PM) { PM.add(createBoundsCheckingPass()); @@ -235,6 +243,10 @@ void EmitAssemblyHelper::CreatePasses(TargetMachine *TM) { PMBuilder.DisableUnitAtATime = !CodeGenOpts.UnitAtATime; PMBuilder.DisableUnrollLoops = !CodeGenOpts.UnrollLoops; + if (!CodeGenOpts.AutoProfileFile.empty()) + PMBuilder.addExtension(PassManagerBuilder::EP_EarlyAsPossible, + addAutoProfilePass); + // In ObjC ARC mode, add the main ARC optimization passes. if (LangOpts.ObjCAutoRefCount) { PMBuilder.addExtension(PassManagerBuilder::EP_EarlyAsPossible, diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 2f824cb..f16d833 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -3020,6 +3020,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, // Forward -f options with positive and negative forms; we translate // these by hand. + if (Arg *A = Args.getLastArg(options::OPT_fauto_profile_EQ)) { + StringRef fname = A->getValue(); + CmdArgs.push_back(Args.MakeArgString("-fauto-profile=" + fname)); + } if (Args.hasArg(options::OPT_mkernel)) { if (!Args.hasArg(options::OPT_fapple_kext) && types::isCXX(InputType)) diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index b0d7a0a..12a9cba 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -357,6 +357,7 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, (Opts.OptimizationLevel > 1 && !Opts.OptimizeSize)); Opts.Autolink = !Args.hasArg(OPT_fno_autolink); + Opts.AutoProfileFile = Args.getLastArgValue(OPT_fauto_profile_EQ); Opts.AsmVerbose = Args.hasArg(OPT_masm_verbose); Opts.ObjCAutoRefCountExceptions = Args.hasArg(OPT_fobjc_arc_exceptions); Opts.CUDAIsDevice = Args.hasArg(OPT_fcuda_is_device); diff --git a/test/Driver/clang_f_opts.c b/test/Driver/clang_f_opts.c index b7c579e..8e1a5da 100644 --- a/test/Driver/clang_f_opts.c +++ b/test/Driver/clang_f_opts.c @@ -44,6 +44,9 @@ // CHECK-UNROLL-LOOPS: "-funroll-loops" // CHECK-NO-UNROLL-LOOPS: "-fno-unroll-loops" +// RUN: %clang -### -S -fauto-profile=file.prof %s 2>&1 | FileCheck -check-prefix=CHECK-AUTO-PROFILE %s +// CHECK-AUTO-PROFILE: "-fauto-profile=file.prof" + // RUN: %clang -### -S -fvectorize %s 2>&1 | FileCheck -check-prefix=CHECK-VECTORIZE %s // RUN: %clang -### -S -fno-vectorize -fvectorize %s 2>&1 | FileCheck -check-prefix=CHECK-VECTORIZE %s // RUN: %clang -### -S -fno-vectorize %s 2>&1 | FileCheck -check-prefix=CHECK-NO-VECTORIZE %s -- 1.8.4
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
