[mini] Eliminate some sources of quadratic behavior. Improves on #7809. (#9100)
commita2899e50f9fc4e67ac8bb17bdc64e160b0deda35
authorRodrigo Kumpera <kumpera@users.noreply.github.com>
Wed, 13 Jun 2018 18:37:17 +0000 (13 14:37 -0400)
committerAlexander Köplinger <alex.koeplinger@outlook.com>
Wed, 13 Jun 2018 18:37:17 +0000 (13 20:37 +0200)
tree3d37159a424a6358390b6158a78b03660a33f342
parent9d777bf78d7724a7247503146c89e0a6f93d435e
[mini] Eliminate some sources of quadratic behavior. Improves on #7809. (#9100)

* [mini] Change region formation pivot from BB to EH clause.

The original BB region computation would loop all BBs and search which EH clause each of them.
EH search is implemented as a linear search, meaning performance was count(BB) * count(clauses).
Since each clause generates at least one BB, it's quadratic on the number of clauses.

Degenerate methods, with tens of thousands of EH clauses, would lead to minutes of JIT time.

New code loops over the clauses and mark all BBs covered by each of them. Given EH ranges are a much
smaller subset of all BBs, this performs significantly better. It remains possible to construct methods
that leads to degenerate compilation times, but it's less likely now.

* [mini] Bound the size of a linked list during liveness.

The `visited` linked list can grown to tens of thousands of entries with some degenerate methods.
This change uses a stack allocated array and switches to a hashtable on overflow.

* [mini] Change printf to g_print

* [mini][amd64] Limit more precise branch target optimization based on number of basic blocks.

On amd64 we update branch target data before each BB is emitted. This has quadratic behavior on number of basic blocks
and can lead to excessive compilation times in degenerate cases.

Limit the increased precision to methods with less than 800 basic blocks.

Reduces compilation time of #7809 by 88% (from 44s to 5s).
mono/mini/liveness.c
mono/mini/method-to-ir.c
mono/mini/mini-amd64.c