<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Mar 31, 2014 at 9:27 AM, Diego Novillo <span dir="ltr"><<a href="mailto:dnovillo@google.com" target="_blank">dnovillo@google.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">+richardsmith +tobias<br>
<br>
I could not convince phabricator to add Richard and Tobias to the<br>
reviewers line. I looked in its list of users and neither of you seem<br>
to be registered. Maybe I was looking for the wrong IDs?<br></blockquote><div><br></div><div>FYI, my phabricator user id is 'rsmith'.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Thanks. Diego.<br>
<br>
On Mon, Mar 31, 2014 at 12:26 PM, Diego Novillo <<a href="mailto:dnovillo@google.com">dnovillo@google.com</a>> wrote:<br>
> This patch adds a new flag -Rpass=. The flag indicates the name<br>
> of the optimization pass that should emit remarks stating when it<br>
> made a transformation to the code.<br>
><br>
> This implements the design I proposed in:<br>
><br>
> <a href="https://docs.google.com/document/d/1FYUatSjZZO-zmFBxjOiuOzAy9mhHA8hqdvklZv68WuQ/edit?usp=sharing" target="_blank">https://docs.google.com/document/d/1FYUatSjZZO-zmFBxjOiuOzAy9mhHA8hqdvklZv68WuQ/edit?usp=sharing</a><br>

><br>
> The patch is still WIP:<br>
><br>
> 1- I still need to add tests. Both in the front and middle end.<br>
><br>
> 2- The diagnostic is emitted with a confusing [-WRpass] suffix. I'm<br>
>    not quite sure how to remove that. I think it's related to diagnostic<br>
>    groups?<br>
><br>
> <a href="http://llvm-reviews.chandlerc.com/D3226" target="_blank">http://llvm-reviews.chandlerc.com/D3226</a><br>
><br>
> Files:<br>
>   include/clang/Basic/DiagnosticDriverKinds.td<br>
>   include/clang/Basic/DiagnosticFrontendKinds.td<br>
>   include/clang/Basic/DiagnosticGroups.td<br>
>   include/clang/Driver/Options.td<br>
>   include/clang/Frontend/CodeGenOptions.h<br>
>   lib/CodeGen/CodeGenAction.cpp<br>
>   lib/Driver/Tools.cpp<br>
>   lib/Frontend/CompilerInvocation.cpp<br>
><br>
> Index: include/clang/Basic/DiagnosticDriverKinds.td<br>
> ===================================================================<br>
> --- include/clang/Basic/DiagnosticDriverKinds.td<br>
> +++ include/clang/Basic/DiagnosticDriverKinds.td<br>
> @@ -111,6 +111,8 @@<br>
>    "unknown or ill-formed Objective-C runtime '%0'">;<br>
>  def err_drv_emit_llvm_link : Error<<br>
>     "-emit-llvm cannot be used when linking">;<br>
> +def err_drv_optimization_report_pattern : Error<<br>
> +  "%0 in '%1'">;<br>
><br>
>  def warn_O4_is_O3 : Warning<"-O4 is equivalent to -O3">, InGroup<Deprecated>;<br>
>  def warn_drv_optimization_value : Warning<"optimization level '%0' is unsupported; using '%1%2' instead">,<br>
> Index: include/clang/Basic/DiagnosticFrontendKinds.td<br>
> ===================================================================<br>
> --- include/clang/Basic/DiagnosticFrontendKinds.td<br>
> +++ include/clang/Basic/DiagnosticFrontendKinds.td<br>
> @@ -32,6 +32,9 @@<br>
>  def remark_fe_backend_plugin: Remark<"%0">, CatBackend, InGroup<RemarkBackendPlugin>;<br>
>  def note_fe_backend_plugin: Note<"%0">, CatBackend;<br>
><br>
> +def remark_fe_backend_optimization_report: Remark<"%0">, CatBackend,<br>
> +    InGroup<BackendOptimizationReport>;<br>
> +<br>
>  def err_fe_invalid_code_complete_file : Error<<br>
>      "cannot locate code-completion file %0">, DefaultFatal;<br>
>  def err_fe_stdout_binary : Error<"unable to change standard output to binary">,<br>
> Index: include/clang/Basic/DiagnosticGroups.td<br>
> ===================================================================<br>
> --- include/clang/Basic/DiagnosticGroups.td<br>
> +++ include/clang/Basic/DiagnosticGroups.td<br>
> @@ -662,3 +662,4 @@<br>
>  def BackendFrameLargerThan : DiagGroup<"frame-larger-than">;<br>
>  def BackendPlugin : DiagGroup<"backend-plugin">;<br>
>  def RemarkBackendPlugin : DiagGroup<"remark-backend-plugin">;<br>
> +def BackendOptimizationReport : DiagGroup<"Rpass">;<br>
> Index: include/clang/Driver/Options.td<br>
> ===================================================================<br>
> --- include/clang/Driver/Options.td<br>
> +++ include/clang/Driver/Options.td<br>
> @@ -60,6 +60,7 @@<br>
>  def M_Group               : OptionGroup<"<M group>">, Group<CompileOnly_Group>;<br>
>  def T_Group               : OptionGroup<"<T group>">;<br>
>  def O_Group               : OptionGroup<"<O group>">, Group<CompileOnly_Group>;<br>
> +def R_Group               : OptionGroup<"<R group>">, Group<CompileOnly_Group>;<br>
>  def W_Group               : OptionGroup<"<W group>">, Group<CompileOnly_Group>;<br>
>  def d_Group               : OptionGroup<"<d group>">;<br>
>  def f_Group               : OptionGroup<"<f group>">, Group<CompileOnly_Group>;<br>
> @@ -253,7 +254,8 @@<br>
>  def Qunused_arguments : Flag<["-"], "Qunused-arguments">, Flags<[DriverOption, CoreOption]>,<br>
>    HelpText<"Don't emit warning for unused driver arguments">;<br>
>  def Q : Flag<["-"], "Q">;<br>
> -def R : Flag<["-"], "R">;<br>
> +def Rpass_EQ : Joined<["-"], "Rpass=">, Group<R_Group>, Flags<[CC1Option]>,<br>
> +  HelpText<"Report transformations performed by optimization passes">;<br>
>  def S : Flag<["-"], "S">, Flags<[DriverOption,CC1Option]>, Group<Action_Group>,<br>
>    HelpText<"Only run preprocess and compilation steps">;<br>
>  def Tbss : JoinedOrSeparate<["-"], "Tbss">, Group<T_Group>;<br>
> Index: include/clang/Frontend/CodeGenOptions.h<br>
> ===================================================================<br>
> --- include/clang/Frontend/CodeGenOptions.h<br>
> +++ include/clang/Frontend/CodeGenOptions.h<br>
> @@ -16,6 +16,7 @@<br>
><br>
>  #include <string><br>
>  #include <vector><br>
> +#include "llvm/Support/Regex.h"<br>
><br>
>  namespace clang {<br>
><br>
> @@ -145,6 +146,13 @@<br>
>    /// Name of the profile file to use as input for -fprofile-instr-use<br>
>    std::string InstrProfileInput;<br>
><br>
> +  /// Regular expression to select optimizations for which we should enable<br>
> +  /// optimization reports. Transformation passes whose name matches this<br>
> +  /// expression (and support this feature), will emit a diagnostic<br>
> +  /// whenever they perform a transformation. This is enabled by the<br>
> +  /// -Rpass=regexp flag.<br>
> +  llvm::Regex *OptimizationReportPattern;<br>
> +<br>
>  public:<br>
>    // Define accessors/mutators for code generation options of enumeration type.<br>
>  #define CODEGENOPT(Name, Bits, Default)<br>
> Index: lib/CodeGen/CodeGenAction.cpp<br>
> ===================================================================<br>
> --- lib/CodeGen/CodeGenAction.cpp<br>
> +++ lib/CodeGen/CodeGenAction.cpp<br>
> @@ -20,6 +20,7 @@<br>
>  #include "clang/Frontend/FrontendDiagnostic.h"<br>
>  #include "llvm/ADT/SmallString.h"<br>
>  #include "llvm/Bitcode/ReaderWriter.h"<br>
> +#include "llvm/IR/DebugInfo.h"<br>
>  #include "llvm/IR/DiagnosticInfo.h"<br>
>  #include "llvm/IR/DiagnosticPrinter.h"<br>
>  #include "llvm/IR/LLVMContext.h"<br>
> @@ -220,6 +221,11 @@<br>
>      /// \return True if the diagnostic has been successfully reported, false<br>
>      /// otherwise.<br>
>      bool StackSizeDiagHandler(const llvm::DiagnosticInfoStackSize &D);<br>
> +    /// \brief Specialized handler for the optimization report diagnostic.<br>
> +    /// \return True if the diagnostic has been successfully reported, false<br>
> +    /// otherwise.<br>
> +    bool<br>
> +    OptimizationReportHandler(const llvm::DiagnosticInfoOptimizationReport &D);<br>
>    };<br>
><br>
>    void BackendConsumer::anchor() {}<br>
> @@ -374,6 +380,27 @@<br>
>    return true;<br>
>  }<br>
><br>
> +bool BackendConsumer::OptimizationReportHandler(<br>
> +    const llvm::DiagnosticInfoOptimizationReport &D) {<br>
> +  if (CodeGenOpts.OptimizationReportPattern->match(D.getPassName())) {<br>
> +    SourceLocation Loc;<br>
> +    // FIXME: This should be done earlier.<br>
> +    Diags.setDiagnosticMapping(diag::remark_fe_backend_optimization_report,<br>
> +                               diag::Mapping::MAP_REMARK, Loc);<br>
> +    // FIXME: There should be a way of transferring the DILocation<br>
> +    // content into a SourceLocation. We are building the location string<br>
> +    // unnecessarily.<br>
> +    DILocation DIL(D.getDebugLoc().getAsMDNode(D.getFunction().getContext()));<br>
> +    StringRef FileName = DIL.getFilename();<br>
> +    unsigned LineNum = DIL.getLineNumber();<br>
> +    unsigned ColumnNum = DIL.getColumnNumber();<br>
> +    Diags.Report(Loc, diag::remark_fe_backend_optimization_report)<br>
> +        << Twine(FileName + ":" + Twine(LineNum) + ":" + Twine(ColumnNum) +<br>
> +                 ": " + D.getMsg()).str();<br>
> +  }<br>
> +  return true;<br>
> +}<br>
> +<br>
>  /// \brief This function is invoked when the backend needs<br>
>  /// to report something to the user.<br>
>  void BackendConsumer::DiagnosticHandlerImpl(const DiagnosticInfo &DI) {<br>
> @@ -391,6 +418,10 @@<br>
>        return;<br>
>      ComputeDiagID(Severity, backend_frame_larger_than, DiagID);<br>
>      break;<br>
> +  case llvm::DK_OptimizationReport:<br>
> +    if (CodeGenOpts.OptimizationReportPattern)<br>
> +      OptimizationReportHandler(cast<DiagnosticInfoOptimizationReport>(DI));<br>
> +    return;<br>
>    default:<br>
>      // Plugin IDs are not bound to any value as they are set dynamically.<br>
>      ComputeDiagRemarkID(Severity, backend_plugin, DiagID);<br>
> Index: lib/Driver/Tools.cpp<br>
> ===================================================================<br>
> --- lib/Driver/Tools.cpp<br>
> +++ lib/Driver/Tools.cpp<br>
> @@ -3293,6 +3293,10 @@<br>
>        A->render(Args, CmdArgs);<br>
>    }<br>
><br>
> +  if (Arg *A = Args.getLastArg(options::OPT_Rpass_EQ)) {<br>
> +    A->render(Args, CmdArgs);<br>
> +  }<br>
> +<br>
>    if (Args.hasArg(options::OPT_mkernel)) {<br>
>      if (!Args.hasArg(options::OPT_fapple_kext) && types::isCXX(InputType))<br>
>        CmdArgs.push_back("-fapple-kext");<br>
> Index: lib/Frontend/CompilerInvocation.cpp<br>
> ===================================================================<br>
> --- lib/Frontend/CompilerInvocation.cpp<br>
> +++ lib/Frontend/CompilerInvocation.cpp<br>
> @@ -520,6 +520,23 @@<br>
><br>
>    Opts.DependentLibraries = Args.getAllArgValues(OPT_dependent_lib);<br>
><br>
> +  if (Arg *A = Args.getLastArg(OPT_Rpass_EQ)) {<br>
> +    StringRef Val = A->getValue();<br>
> +    std::string RegexError;<br>
> +    Opts.OptimizationReportPattern = new llvm::Regex(Val);<br>
> +    if (!Opts.OptimizationReportPattern->isValid(RegexError)) {<br>
> +      Diags.Report(diag::err_drv_optimization_report_pattern)<br>
> +          << RegexError << A->getAsString(Args);<br>
> +      delete Opts.OptimizationReportPattern;<br>
> +      Opts.OptimizationReportPattern = 0;<br>
> +    } else {<br>
> +      // Optimization report diagnostics need to extract location information<br>
> +      // from the instructions they are emitted on. When -Rpass is used,<br>
> +      // enable line table generation.<br>
> +      Opts.setDebugInfo(CodeGenOptions::DebugLineTablesOnly);<br>
> +    }<br>
> +  }<br>
> +<br>
>    return Success;<br>
>  }<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>