ART: fix errors
Revert "Revert "Null check elimination improvement""

This reverts commit 31aa97cfec5ee76b2f2496464e1b6f9e11d21a29.

..and thereby brings back change 380165, which was reverted
because it was buggy.

Three problems with the original CL:

  1.  The author ran the pre-submit tests, but used -j24 and
      failed to search the output for fail messages.
  2.  The new null check analysis pass uses an interative
      approach to identify whether a null check is needed.  It
      is possible that the null-check-required state may
      oscillate, and a logic error caused it to stick in the
      "no check needed" state.
  3.  Our old nemesis Dalvik untyped constants, in which 0 values
      can be used both as object reference and non-object references.
      This CL conservatively treats all CONST definitions as
      potential object definitions for the purposes of null
      check elimination.

Change-Id: I3c1744e44318276e42989502a314585e56ac57a0
Quick compiler compile-time/memory use improvement

This CL delivers a surprisingly large reduction in compile time,
as well as a significant reduction in memory usage by conditionally
removing a CFG construction feature introduced to support LLVM
bitcode generation.

In short, bitcode requires all potential exception edges to be
explicitly present in the CFG.  The Quick compiler (based on the
old JIT), can ignore, at least for the purposes of dataflow
analysis, potential throw points that do not have a corresponding
catch block.

To support LLVM, we create a target basic block for every
potentially throwing instruction to give us a destination for
the exception edge.  Then, following the check elimination pass,
we remove blocks whose edges have gone away.

However, if we're not using LLVM, we can skip the creation of
those things in the first place.  The savings are significant.

Single-threaded compilation time on the host looks to be reduced
by something in the vicinity of 10%.  We create roughly 60% fewer
basic blocks (and, importantly, the creation of fewer basic
block nodes has a multiplying effect on memory use reduction
because it results in fewer dataflow bitmaps).

Some basic block redution stats:

boot: 2325802 before, 844846 after.
Phonesky: 485472 before, 156014 after.
PlusOne: 806232 before, 243156 after.
Thinkfree: 864498 before, 264858 after.

Another nice side effect of this change is giving the basic
block optimization pass generally larger scope.

For arena memusage in the boot class path (compiled on the host):

          Average            Max
Before:    50,863         88,017,820
After:     41,964          4,914,208

The huge reduction in max arena memory usage is due to the
collapsing of a large initialization method.  Specifically, with complete
exception edges org.ccil.cowan.tagsoup.Scheme requires 13,802
basic blocks.  With exception edges collapsed, it requires 4.

This change also caused 2 latent bugs to surface.

1) The dex parsing code did not expect that the target of a switch statement
could reside in the middle of the same basic block ended by that same switch
statement.

2) The x86 backend introduced a 5-operand LIR instruction for indexed memops.
However, there was no corresponding change to the use/def mask creation code.
Thus, the 5th operand was never included in the use/def mask.  This allowed
the instruction scheduling code to incorrectly move a use above a definition.
We didn't see this before because the affected x86 instructions were only used
for aget/aput, and prior to this CL those Dalvik opcodes caused a basic
block break because of the implied exception edge - which prevented the code
motion.

And finally, also included is some minor tuning of register use weighting.

Change-Id: I3f2cab7136dba2bded71e9e33b452b95e8fffc0e
More compile-time tuning

Another round of compile-time tuning, this time yeilding in the
vicinity of 3% total reduction in compile time (which means about
double that for the Quick Compile portion).

Primary improvements are skipping the basic block combine optimization
pass when using Quick (because we already have big blocks), combining
the null check elimination and type inference passes, and limiting
expensive local value number analysis to only those blocks which
might benefit from it.

Following this CL, the actual compile phase consumes roughly 60%
of the total dex2oat time on the host, and 55% on the target (Note,
I'm subtracting out the Deduping time here, which the timing logger
normally counts against the compiler).

A sample breakdown of the compilation time follows (this taken on
PlusOne.apk w/ a Nexus 4):

39.00% -> MIR2LIR: 1374.90 (Note: includes local optimization & scheduling)
10.25% -> MIROpt:SSATransform: 361.31
 8.45% -> BuildMIRGraph: 297.80
 7.55% -> Assemble: 266.16
 6.87% -> MIROpt:NCE_TypeInference: 242.22
 5.56% -> Dedupe: 196.15
 3.45% -> MIROpt:BBOpt: 121.53
 3.20% -> RegisterAllocation: 112.69
 3.00% -> PcMappingTable: 105.65
 2.90% -> GcMap: 102.22
 2.68% -> Launchpads: 94.50
 1.16% -> MIROpt:InitRegLoc: 40.94
 1.16% -> Cleanup: 40.93
 1.10% -> MIROpt:CodeLayout: 38.80
 0.97% -> MIROpt:ConstantProp: 34.35
 0.96% -> MIROpt:UseCount: 33.75
 0.86% -> MIROpt:CheckFilters: 30.28
 0.44% -> SpecialMIR2LIR: 15.53
 0.44% -> MIROpt:BBCombine: 15.41

(cherry pick of 9e8e234af4430abe8d144414e272cd72d215b5f3)

Change-Id: I86c665fa7e88b75eb75629a99fd292ff8c449969
Art: fix basic block optimization pass

A bracket mismatch in Change 70885 inadvertently prevented the basic
block optimization pass from running in most cases.  Fixed here.

Change-Id: I33f2687904cc05c90f74fb3bdc8f312d009cc0ac
Added pass framework

The patch adds a Middle-End pass system and normalizes the current
 passes into the pass framework.

Passes have:
 - A start, work, and end functions.
 - A gate to determine to apply the pass.
 - Can provide a CFG dump folder.

mir_dataflow.cc, mir_graph.cc, mir_optimization.cc, ssa_transformation.cc:
 - Changed due to moving code into bb_optimizations.cc.
 - Moved certain functions from private to public due to needed from the passes.

pass.cc, pass.h:
 - Pass base class

pass_driver.cc, pass_driver.h:
 - The pass driver implementation.

frontend.cc:
 - Replace the function calls to the passes with the pass driver.

Change-Id: I88cd82efbf6499df9e6c7f135d7e294dd724a079
Signed-off-by: Jean Christophe Beyler <jean.christophe.beyler@intel.com>
Remove the link from dalvik instruction back to kMirOpCheck.

Free the MIR::meta for another use on PUT/GET instructions.

Change-Id: I39ee5122227f449212cf6960e11b9561b8a6de7b