RFH: passing options from clang down to opt

I'm trying to add a new option to clang to enable my auto profile
pass. I've added this to Options.td and Driver/Tools.cpp, but I'm not
getting the option -auto-profile in cc1's invocation. I've checked
that the code to push -auto-profile is executed, but if use -v, I
don't see -auto-profile in the cc1 invocation.

Can anyone point me to some document that explains how to pass clang's
options down to opt? Failing that, what option could I look at
copying? I've tried doing what the vectorizer flags do, but they are
used to build the module pass manager, and my pass is just a function
pass.

Do I need to modify the pass manager as well?

Thanks. Diego.

diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td
index a2be903..da932e2 100644
--- a/include/clang/Driver/Options.td
+++ b/include/clang/Driver/Options.td
@@ -351,6 +351,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 : Flag<["-"], "fauto-profile">, Group<f_Group>,
+ Flags<[DriverOption, CC1Option]>,
+ HelpText<"Enable automatic profile guided optimizations">;

Actually, I think I do need to modify the PM. I need to insert the
annotations before the analysis passes execute.

Diego.

You are calling the option -auto-profile in some places and
-fauto-profile in others. Maybe it is just a typo?

In opt, the option is named '-auto-profile' when I instantiate the pass:

INITIALIZE_PASS(AutoProfile, "auto-profile", "Auto Profile loader", false,
                false)

Do I need to name it fauto-profile as well?

I'm also not sure how to schedule the pass at a specific spot in the
pass manager. I've looked around for documentation on adding flags,
but all I found was
http://llvm.org/docs/WritingAnLLVMPass.html#pass-registration which
does not seem to discuss this.

Diego.

The option handling in clang in fairly different from opt. The comment
about the mixed name was just a guess as to why you don't see the
driver passing it down to -cc1.

Once that is working, you will probably need to:

* Patch ParseCodeGenArgs to record the option
* Patch EmitAssemblyHelper::CreatePasses to set the option to enable
the pass in the pass manager (assuming that is the effect you want).

The option handling in clang in fairly different from opt. The comment
about the mixed name was just a guess as to why you don't see the
driver passing it down to -cc1.

Clang::ConstructJob is ~2k lines long. I was putting the handling of
this option too far down. I moved it up and it's now being passed.
Not sure what order needs to be kept in this function, however.

Once that is working, you will probably need to:

* Patch ParseCodeGenArgs to record the option
* Patch EmitAssemblyHelper::CreatePasses to set the option to enable
the pass in the pass manager (assuming that is the effect you want).

Thanks. That was my disconnect. I was confusing 'opt' with clang's backend.

The attached patch does what I want. Does it look like it's in the
right direction?

Thanks. Diego.

00.diff (3.71 KB)

Seems pretty reasonable.

-eric

OK, thanks for the help folks.

Diego.