[PATCH] D33758: [globalisel][tablegen] Partially fix compile-time regressions by converting matcher to state-machine(s)

Daniel Sanders via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 1 01:17:30 PDT 2017


dsanders added a comment.

In https://reviews.llvm.org/D33758#769689, @kristof.beyls wrote:

> > Replace the matcher if-statements for each rule with a state-machine. This
> >  significantly reduces compile time, memory allocations, and cumulative memory
> >  allocation when compiling AArch64InstructionSelector.cpp.o after r303259 is
> >  recommitted.
>
> My guess is that the compiler compile time goes down simply because tablegen produces far less code?


That's right. Instead of generating C++ and having the compiler optimize a single massive function, it's compiling a single copy of each predicate and chaining them together with a table.

> Do you also have an insight of how using a state machine "interpreter" changes the run-time of the compiler itself compared to using the "directly-compiled" generated C++ code?
>  I can't predict really how the different tradeoffs in both approaches will affect the compiler's run-time performance in the end, so it would be nice to share insights you may have for this.

I haven't measured it yet since the priority so far has been to get the compile times back down to a reasonable level. Once I've finished posting the patches for review I'll take a look at the run-time effect.

My intuition is that the compiler was unlikely to have optimized the previous implementation very well (particularly since it didn't inline the single-use lambdas) and assuming that's the case, the overhead of the interpreter is likely to be limited to the cost of the table lookups. It's possible that it will turn out to be faster since the previous implementation had no chance of fitting into an instruction cache whereas the new code may fit on some machines. On machines where it doesn't fit, some paths are more common than others so it may still be able to use the instruction cache better than the old implementation did.

> Also, if we end up using a state machine for this, I think it'd be a good idea to, after the design settles, write a blog post or something similar to explain how the state machine works, as I've heard from many people that reverse engineering the DAGISel-produced state machine was hard due to limited or no documentation on it.

Ok.


https://reviews.llvm.org/D33758





More information about the llvm-commits mailing list