<div dir="ltr">Sorry, but I strongly oppose to the road you're suggesting here. As I said before the Pass*Manager* is entirely the wrong place to handle OptNone, the absolutely the wrong design. It makes sense for function *only*, and immediately breaks down everywhere else. Frankly, OptNone should take no role in this particular discussion, and I feel like so far it has because "We've always done it this way".<div><br></div><div>Second, I don't completely subscribe to the arguments towards not-skippable passes. Fundamentally: Who decides whether a pass is skippable or not? _When_ is a pass skippable, when isn't it? Neither the Pass nor the PassManager may actually decide that. The only things that do are the pipeline builder and the bisecter. Pipeline builder here means the driver tool that constructs and executes the pipeline (like clang or opt), not PassBuilder. We can achieve that if we put this feature into the instrumentation instead.  Here we have the right amount of control, at least cost and minimal complexity. Then, all we need to is get the default treatment right. If we can agree on whether we truly want to not skip some passes 90% of the time, than we can just encode that as an overrideable default, such as by tracking a list of non-skippable passes right there in the implementation.</div><div><br></div><div>Cheers,</div><div>Philip</div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Oct 1, 2018 at 9:16 PM David Greene <<a href="mailto:dag@cray.com">dag@cray.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Fedor Sergeev <<a href="mailto:fedor.sergeev@azul.com" target="_blank">fedor.sergeev@azul.com</a>> writes:<br>
<br>
> I'm not sure that I fully gather which part of pipeline<br>
> construction/execution and which<br>
> object interaction do you mean when talking about "query hooks" or<br>
> "run the pass".<br>
><br>
> Right now we have the following objects:<br>
>    - OptBisect, which is pass-instrumentation object<br>
>    - PassBuilder object that constructs the pipeline<br>
>    - PassManager object that controls the pass execution<br>
>    - Pass object, which is being constructed for PassBuilder and then<br>
> executed with PassManager<br>
><br>
> At construction time there are:<br>
>   Pass, OptBisect, PassBuilder objects<br>
> and at execution time there are:<br>
>   Pass, OptBisect, PassManager objects<br>
> which of those do you see interacting when you talk about "query hooks"?<br>
<br>
There are more objects involved, I think.  I am specifically thinking of<br>
TargetMachine and TargetTransformInfo.  The former is used by various<br>
codegen passes to determine what to do and how to do it.  I'm supposing<br>
it may be reasonable to extend that interface to support a pass asking<br>
what it needs to do at a bare minimum to produce functional code.  I<br>
really don't have a good idea what that looks like however.<br>
TargetMachine may be the wrong place for it.<br>
<br>
TargetTransformInfo plays a similar role for IR/non-codegen passes.<br>
Again, TTI may or may not be the right place to put such a query<br>
interface, but it seems in-line with the role TTI plays.<br>
<br>
Again, this isn't something that needs to be solved right now, but in<br>
my head the model looks something like this:<br>
<br>
MySchedulingPass::run() {<br>
  DelaySlotDescriptor = TM.getDelaySlotInfo();<br>
  InterlockDescriptor = TM.getSoftwareInterlocks();<br>
  VLIWDescriptor = TM.getBundleInfo();<br>
<br>
  if (PassInstrumentor.getOptLevel() == OptLevel::None) {<br>
    // Schedule only for the above constraints (e.g. fill all delay slots<br>
    // with nops, identifying the branches needing to be filled via<br>
    // DelaySlotDescriptor).<br>
    ...<br>
  }<br>
  else {<br>
    // Do full scheduling.<br>
    ...<br>
  }<br>
}<br>
<br>
This is just quickly thrown together and is likely not the right<br>
interface, but hopefully the idea comes across.<br>
<br>
> My mental model of "not skippable" handling:<br>
>   - OptBisect is the controlling object.<br>
>   - at construction time it tracks objects being constructed and<br>
> stores its "skippable"/"unskippable" properties.<br>
>   - at run-time PassManager asks OptBisect and it reports whether to<br>
> skip the pass or not.<br>
>     PassManager acts accordingly.<br>
<br>
Sure, that makes sense.<br>
<br>
> "run the pass at full optimization" is something that I dont see a<br>
> clear mental model of.<br>
> Obviously it is the Pass itself that can run itself at full<br>
> optimization *if* it gets control.<br>
> PassManager can pass the control to the Pass.<br>
> OptBisect does not run at all, it just advises the PassManager.<br>
> How Pass decides that it runs at full optimization/half optimization?<br>
<br>
The above hints at it.  A pass this is not skippable may very well be<br>
able to run in a "degraded" mode, where it does the bare minimum to<br>
produce functional code.  That degraded mode could be used by OptBisect<br>
to narrow the pieces of the pass that are wrong (e.g. it fails in normal<br>
mode but passes in degraded mode).<br>
<br>
Andy identified three things OptBisect could do with a pass: run it,<br>
skip it or run it at OptLevel::None.<br>
<br>
If the pass is skipped, that's all handled in the PassManager and the<br>
pass isn't even aware of it.<br>
<br>
That leaves two choices.  Either the pass is fully run or it is run in<br>
degraded mode (OptLevel::None).  What I was trying to get at is that I<br>
think there are really only two states: either the pass is fully run<br>
(not skipped) or it is run in degraded mode.  For almost all passes<br>
"degraded mode" is the same thing as not running the pass at all<br>
(degraded mode == skip).  What "degraded mode" means for a pass is<br>
likely a decision to be made among the pass and other entities, such as<br>
target info.<br>
<br>
At registration time, we can encode Andy's three choices:<br>
<br>
// PassManager can not run the pass at all.<br>
registerPass(MyPass, PassInstrumentor::DegradeMode::Skip);<br>
<br>
// PassManager must run the pass, but it can tell the pass to<br>
// run in degraded mode.<br>
registerPass(MyOtherPass, PassInstrumentor::DegradeMode::OptNone);<br>
<br>
// PassManager must run the pass and the pass must operate as it always<br>
// does, even when "bisected out."<br>
registerPass(MyThirdPass, PassInstrumentor::DegradeMode::Default);<br>
<br>
I'm saying we don't really need DegradeMode::Default as the pass itself<br>
can decide to just ignore OptLevel::None and always run as it normally<br>
does, depending on what TargetMachine/TargetTransformInfo/whatever tell<br>
it to do (or if the pass itself knows enough to ignore OptLevel::None).<br>
<br>
I feel like we're getting into the weeds, though.  :)<br>
<br>
                           -David<br>
</blockquote></div>