Add ability to inject custom lowering passes from user code

This is the first in a series of pull request that work towards type legalization for better vectorization of non-native vectors, and to support pnacl's 128-bit hard requirement. 

This PR adds the ability to append custom passes to lowering from user code. For us it will be useful for writing tests. Seemed like a worthy front-end feature in general though, so I pulled it out into its own PR for consideration.
No objection.

On Thu, Nov 13, 2014 at 9:08 AM, Dillon Sharlet <notifications@github.com>
wrote:

> In src/Lower.cpp:
>
> > @@ -1867,7 +1867,19 @@ Stmt lower(Function f, const Target &t) {
> >      debug(1) << "Simplifying...\n";
> >      s = common_subexpression_elimination(s);
> >      s = simplify(s);
> > -    debug(1) << "Lowering after final simplification:\n" << s << "\n\n";
> > +
> > +    if (!custom_passes.empty()) {
> > +        debug(2) << "Lowering after final simplification:\n" << s << "\n\n";
> > +        for (size_t i = 0; i < custom_passes.size(); i++) {
> > +            debug(1) << "Running custom lowering pass " << i << "...\n";
> > +            s = custom_passes[i]->mutate(s);
> > +            if (i + 1 < custom_passes.size()) {
> > +                debug(2) << "Lowering after custom pass " << i << ":\n" << s << "\n\n";
> > +            }
> > +        }
> > +    }
> > +
> > +    debug(1) << "Final lowered statement:\n" << s << "\n\n";
>
> I'd like to make a small change here: I think that if I were writing a
> custom lowering pass, it would be nice to see the lowering before and after
> the custom passes even at debug(1). Or even the lowering between every
> custom pass. More specifically, it would be nice *not* to have to turn on
> debug == 2 to see all the custom lowerings. In some programs, debug == 2
> generates waaay too much IR. In that situation, debugging the custom
> lowering becomes really unwieldy.
>
> If no objection, I will make this change later today and then I think this
> would be ready to merge?
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/halide/Halide/pull/548/files#r20305998>.
>