History log of /art/compiler/optimizing/graph_checker.cc
Revision Date Author Comments
19b5021a49285627485675ef31276b8194269600 22-Apr-2016 Nicolas Geoffray <ngeoffray@google.com> Forbid HDeoptimize instructions in OSR methods.

Otherwise dominated instructions will assume something that
isn't necessarily correct if coming from the interpreter.

bug:28335959
bug:28249238
bug:28348878
bug:28080135

Contains fix from https://android-review.googlesource.com/#/c/220661/.

(cherry picked from commit 93a18c5d4160f632ecdb92af099574e9c7098c49)

Change-Id: I86c3f9340077caa0a3e3db896e0519e7d38d91a0
d59f3b1b7f5c1ab9f0731ff9dc60611e8d9a6ede 29-Mar-2016 Vladimir Marko <vmarko@google.com> Use iterators "before" the use node in HUserRecord<>.

Create a new template class IntrusiveForwardList<> that
mimicks std::forward_list<> except that all allocations
are handled externally. This is essentially the same as
boost::intrusive::slist<> but since we're not using Boost
we have to reinvent the wheel.

Use the new container to replace the HUseList and use the
iterators to "before" use nodes in HUserRecord<> to avoid
the extra pointer to the previous node which was used
exclusively for removing nodes from the list. This reduces
the size of the HUseListNode by 25%, 32B to 24B in 64-bit
compiler, 16B to 12B in 32-bit compiler. This translates
directly to overall memory savings for the 64-bit compiler
but due to rounding up of the arena allocations to 8B, we
do not get any improvement in the 32-bit compiler.

Compiling the Nexus 5 boot image with the 64-bit dex2oat
on host this CL reduces the memory used for compiling the
most hungry method, BatteryStats.dumpLocked(), by ~3.3MiB:

Before:
MEM: used: 47829200, allocated: 48769120, lost: 939920
Number of arenas allocated: 345,
Number of allocations: 815492, avg size: 58
...
UseListNode 13744640
...
After:
MEM: used: 44393040, allocated: 45361248, lost: 968208
Number of arenas allocated: 319,
Number of allocations: 815492, avg size: 54
...
UseListNode 10308480
...

Note that while we do not ship the 64-bit dex2oat to the
device, the JIT compilation for 64-bit processes is using
the 64-bit libart-compiler.

Bug: 28173563
Bug: 27856014

(cherry picked from commit 46817b876ab00d6b78905b80ed12b4344c522b6c)

Change-Id: Ifb2d7b357064b003244e92c0d601d81a05e56a7b
86ea7eeabe30c98bbe1651a51d03cb89776724e7 16-Feb-2016 David Brazdil <dbrazdil@google.com> Build dominator tree before generating HInstructions

Second CL in the series of merging HGraphBuilder and SsaBuilder. This
patch refactors the builders so that dominator tree can be built
before any HInstructions are generated. This puts the SsaBuilder
removal of HLoadLocals/HStoreLocals straight after HGraphBuilder's
HInstruction generation phase. Next CL will therefore be able to
merge them.

This patch also adds util classes for iterating bytecode and switch
tables which allowed to simplify the code.

Bug: 27894376
Change-Id: Ic425d298b2e6e7980481ed697230b1a0b7904526
f355c3ff08710ac2eba3aac2aacc5e65caa06b4c 30-Mar-2016 Roland Levillain <rpl@google.com> Fix Boolean to integral types conversions.

Bug: 27616343
Change-Id: I050f92045bca1b8b5d6da53547cc617f17be84b1
947eb700bec9e214a72d4747864398dc238da60c 25-Mar-2016 Vladimir Marko <vmarko@google.com> Optimizing: Reduce arena memory used by GraphChecker.

Use member variables to reuse the storage instead of
repeatedly allocating new storage for local variables.

Bug: 27690481
Change-Id: I614db9b8614d585653cfbff62e9cf7d7f0c58810
11edec7e7e8ac93f826d687b644fe700fab68993 24-Mar-2016 David Brazdil <dbrazdil@google.com> ART: Loosen a GraphChecker rule on Boolean inputs

GraphChecker tries to verify that Boolean inputs are properly typed.
This is non-trivial in the presence of simplifying optimizations
which capitalize on the fact that a Boolean value is internally
represented as an integer.

This patch removes the test from GraphChecker.

Bug: 27625564
Change-Id: Ic61ea2193765b4578550538e965ca4f80fa4b287
0f49c82076b974f65ef37d5e72b04f5345b0d7cb 22-Mar-2016 Vladimir Marko <vmarko@google.com> Optimizing: Reduce GraphChecker memory usage.

Bug: 27690481
Change-Id: I15ce5524d94fc1780da02e6471bede66b3a1b82a
5b5b9319ff970979ed47d41a41283e4faeffb602 22-Mar-2016 Roland Levillain <rpl@google.com> Fix and improve shift and rotate operations.

- Define maximum int and long shift & rotate distances as
int32_t constants, as shift & rotate distances are 32-bit
integer values.
- Consider the (long, long) inputs case as invalid for
static evaluation of shift & rotate rotations.
- Add more checks in shift & rotate operations constructors
as well as in art::GraphChecker.

Change-Id: I754b326c3a341c9cc567d1720b327dad6fcbf9d6
937e6cd515bbe7ff2f255c8fcd40bf1a575a9a16 22-Mar-2016 Roland Levillain <rpl@google.com> Tighten art::HNeg type constraints on its input.

Ensure art::HNeg is only passed a type having the kind of
its input. For a boolean, byte, short, or char input, it
means HNeg's type should be int.

Bug: 27684275
Change-Id: Ic8442c62090a8ab65590754874a14a0deb7acd8d
f6a35de9eeefb20f6446f1b4815b4dcb0161d09c 21-Mar-2016 Vladimir Marko <vmarko@google.com> Optimizing: Fix register allocator validation memory usage.

Also attribute ArenaBitVector allocations to appropriate
passes. This was used to track down the source of the
excessive memory alloactions.

Bug: 27690481

Change-Id: Ib895984cb7c04e24cbc7abbd8322079bab8ab100
22c4922c6b31e154a6814c4abe9015d9ba156911 18-Mar-2016 Roland Levillain <rpl@google.com> Ensure art::HRor support boolean, byte, short and char inputs.

Also extend tests covering the IntegerRotateLeft,
LongRotateLeft, IntegerRotateRight and LongRotateRight
intrinsics and their translation into an art::HRor
instruction.

Bug: 27682579
Change-Id: I89f6ea6a7315659a172482bf09875cfb7e7422a1
a5c4a4060edd03eda017abebc85f24cffb083ba7 15-Mar-2016 Roland Levillain <rpl@google.com> Make art::HCompare support boolean, byte, short and char inputs.

Also extend tests covering the IntegerSignum, LongSignum,
IntegerCompare and LongCompare intrinsics and their
translation into an art::HCompare instruction.

Bug: 27629913
Change-Id: I0afc75ee6e82602b01ec348bbb36a08e8abb8bb8
916cc1d504f10a24f43b384e035fdecbe6a74b4c 18-Feb-2016 Nicolas Geoffray <ngeoffray@google.com> Implement polymorphic inlining.

For example, before:
HInvokeVirtual

After:
If (receiver == Foo) {
// inlined code.
} else if (receiver == Bar) {
// inlined code
} else {
// HInvokeVirtual or HDeoptimize(receiver != Baz)
}

Change-Id: I5ce305aef8f39f8294bf2b2bcfe60e0dddcfdbec
badd826664896d4a9628a5a89b78016894aa414b 02-Feb-2016 David Brazdil <dbrazdil@google.com> ART: Run SsaBuilder from HGraphBuilder

First step towards merging the two passes, which will later result in
HGraphBuilder directly producing SSA form. This CL mostly just updates
tests broken by not being able to inspect the pre-SSA form.

Using HLocals outside the HGraphBuilder is now deprecated.

Bug: 27150508
Change-Id: I00fb6050580f409dcc5aa5b5aa3a536d6e8d759e
74eb1b264691c4eb399d0858015a7fc13c476ac6 14-Dec-2015 David Brazdil <dbrazdil@google.com> ART: Implement HSelect

This patch adds a new HIR instruction to Optimizing. HSelect returns
one of two inputs based on the outcome of a condition.

This is only initial implementation which:
- defines the new instruction,
- repurposes BooleanSimplifier to emit it,
- extends InstructionSimplifier to statically resolve it,
- updates existing code and tests accordingly.

Code generators currently emit fallback if/then/else code and will be
updated in follow-up CLs to use platform-specific conditional moves
when possible.

Change-Id: Ib61b17146487ebe6b55350c2b589f0b971dcaaee
09aa147f0891ef28a95d89e8ad61c429f82ddd5b 19-Jan-2016 Nicolas Geoffray <ngeoffray@google.com> Disable DCE when there are irreducible loops.

Also ensure an instruction that requires an environment
does have one.

Change-Id: I41a8460e05ef320f872197d3be7847e7ffaa6ee8
6de1938e562b0d06e462512dd806166e754035ea 08-Jan-2016 David Brazdil <dbrazdil@google.com> ART: Remove incorrect HFakeString optimization

Simplification of HFakeString assumes that it cannot be used until
String.<init> is called which is not true and causes different
behaviour between the compiler and the interpreter. This patch
removes the optimization together with the HFakeString instruction.

Instead, HNewInstance is generated and an empty String allocated
until it is replaced with the result of the StringFactory call. This
is consistent with the behaviour of the interpreter but is too
conservative. A follow-up CL will attempt to optimize out the initial
allocation when possible.

Bug: 26457745
Bug: 26486014

Change-Id: I7139e37ed00a880715bfc234896a930fde670c44
15bd22849ee6a1ffb3fb3630f686c2870bdf1bbc 05-Jan-2016 Nicolas Geoffray <ngeoffray@google.com> Implement irreducible loop support in optimizing.

So we don't fallback to the interpreter in the presence of
irreducible loops.

Implications:
- A loop pre-header does not necessarily dominate a loop header.
- Non-constant redundant phis will be kept in loop headers, to
satisfy our linear scan register allocation algorithm.
- while-graph optimizations, such as gvn, licm, lse, and dce
need to know when they are dealing with irreducible loops.

Change-Id: I2cea8934ce0b40162d215353497c7f77d6c9137e
f555258861aea7df8af9c2241ab761227fd2f66a 27-Dec-2015 David Brazdil <dbrazdil@google.com> ART: Create BoundType for CheckCast early

ReferenceTypePropagation creates a BoundType for each CheckCast and
replaces all dominated uses of the casted object with it. This does
not include Phi uses on the boundary of the dominated scope, reducing
typing precision. This patch creates the BoundType in Builder, causing
SsaBuilder to replace uses of the object automatically.

Bug: 26081304

Change-Id: I083979155cccb348071ff58cb9060a896ed7d2ac
4833f5a1990c76bc2be89504225fb13cca22bedf 16-Dec-2015 David Brazdil <dbrazdil@google.com> ART: Refactor SsaBuilder for more precise typing info

This reverts commit 68289a531484d26214e09f1eadd9833531a3bc3c.

Now uses Primitive::Is64BitType instead of Primitive::ComponentSize
because it was incorrectly optimized by GCC.

Bug: 26208284
Bug: 24252151
Bug: 24252100
Bug: 22538329
Bug: 25786318

Change-Id: Ib39f3da2b92bc5be5d76f4240a77567d82c6bebe
f5f64efda943000168d34bfe44ccbbadd284e55f 15-Dec-2015 Nicolas Geoffray <ngeoffray@google.com> Detect phi cycles.

Having reference and non-reference phi equivalent, only happened
for the 0/null constant. To avoid such occurences, we must
detect phi cycles.

bug:25493693

Change-Id: Ie1a8460c3abacca96c299da107fa4407e17dd792
68289a531484d26214e09f1eadd9833531a3bc3c 16-Dec-2015 Alex Light <allight@google.com> Revert "ART: Refactor SsaBuilder for more precise typing info"

This reverts commit d9510dfc32349eeb4f2145c801f7ba1d5bccfb12.

Bug: 26208284

Bug: 24252151
Bug: 24252100
Bug: 22538329
Bug: 25786318

Change-Id: I5f491becdf076ff51d437d490405ec4e1586c010
d9510dfc32349eeb4f2145c801f7ba1d5bccfb12 05-Nov-2015 David Brazdil <dbrazdil@google.com> ART: Refactor SsaBuilder for more precise typing info

This patch refactors the SsaBuilder to do the following:

1) All phis are constructed live and marked dead if not used or proved
to be conflicting.

2) Primitive type propagation, now not a separate pass, identifies
conflicting types and marks corresponding phis dead.

3) When compiling --debuggable, DeadPhiHandling used to revive phis
which had only environmental uses but did not attempt to resolve
conflicts. This pass was removed as obsolete and is now superseded
by primitive type propagation (identifying conflicting phis) and
SsaDeadPhiEliminiation (keeping phis live if debuggable + env use).

4) Resolving conflicts requires correct primitive type information
on all instructions. This was not the case for ArrayGet instructions
which can have ambiguous types in the bytecode. To this end,
SsaBuilder now runs reference type propagation and types ArrayGets
from the type of the input array.

5) With RTP being run inside the SsaBuilder, it is not necessary to
run it as a separate optimization pass. Optimizations can now assume
that all instructions of type kPrimNot have reference type info after
SsaBuilder (with the exception of NullConstant).

6) Graph now contains a reference type to be assigned to NullConstant.
All reference type instructions therefore have RTI, as now enforced
by the SsaChecker.

Bug: 24252151
Bug: 24252100
Bug: 22538329
Bug: 25786318

Change-Id: I7a3aee1ff66c82d64b4846611c547af17e91d260
40a04bf64e5837fa48aceaffe970c9984c94084a 11-Dec-2015 Scott Wakeling <scott.wakeling@linaro.org> Replace rotate patterns and invokes with HRor IR.

Replace constant and register version bitfield rotate patterns, and
rotateRight/Left intrinsic invokes, with new HRor IR.

Where k is constant and r is a register, with the UShr and Shl on
either side of a |, +, or ^, the following patterns are replaced:

x >>> #k OP x << #(reg_size - k)
x >>> #k OP x << #-k

x >>> r OP x << (#reg_size - r)
x >>> (#reg_size - r) OP x << r

x >>> r OP x << -r
x >>> -r OP x << r

Implemented for ARM/ARM64 & X86/X86_64.

Tests changed to not be inlined to prevent optimization from folding
them out. Additional tests added for constant rotate amounts.

Change-Id: I5847d104c0a0348e5792be6c5072ce5090ca2c34
4a34277c55279ba57ab361f7580db846a201d9b1 30-Nov-2015 Aart Bik <ajcbik@google.com> Dynamic BCE (based on induction range analysis)

Rationale:
A rewritten dynamic BCE that uses induction variable analysis
to generate the run-time tests before a loop in order to
eliminate bounds-checks from its body. This CL removes now
obsoleted induction related code inside the BCE module.
Also, the dynamic test generation is placed more strategically,
since we missed a few cases where static analysis does better.

Most significant performance improvements (filtering noise) is about:

Linpack +20%
LU > +10%

Change-Id: I03d7631857154b6a131b132f26a2dc568af1b3a1
3fc7f357170311689c4c31007a5e168ddea321d5 21-Nov-2015 Aart Bik <ajcbik@google.com> Accept synthetic phi nodes and general names for blocks.

Rationale: these changes were already approved as part of the dynamic
bce changes, but I am now sending them out separately.

Change-Id: I3564bac9f6a0b6a89466457836ff54ad09164faf
d59c70627cc42878cc30b46bd29ff497b4483b22 21-Nov-2015 Aart Bik <ajcbik@google.com> Revert "Dynamic BCE (based on induction range analysis)"

This reverts commit 0b5849be045c5683d4a6b6b6c306abadba5f0fcc.


Change-Id: Id33f5da42bbdfb1aff7e2281417c8a7aa492df05
Rationale: so close :-( but bullhead-userdebug (linux) build in git_mnc-dr-dev-plus-aosp reported a breakage with a type inconsistency (long vs int in probably the codegen of dynamic bce); no time to investigate and fix this fully before my trip, so rolling back for now
0b5849be045c5683d4a6b6b6c306abadba5f0fcc 19-Oct-2015 Aart Bik <ajcbik@google.com> Dynamic BCE (based on induction range analysis)

Rationale: A rewritten dynamic BCE that uses induction variable analysis
to generate the run-time tests before a loop in order to
eliminate bounds-checks from its body. This CL removes now
obsoleted induction related code inside the BCE module.
Also, the dynamic test generation is placed more strategically,
since we missed a few cases where static analysis does better.

Most significant performance improvements (after filtering noise) is about:
Linpack +20%
LU > +10%

Change-Id: I4e7b8bab0288beff6f98a14856e3536103d32742
d8ef0c69330f74f325f7671236ca6bf44b7ec9c9 10-Nov-2015 David Brazdil <dbrazdil@google.com> ART: Remove unnecessary helper method from GraphChecker

Change-Id: I59f50a559da560033f4c9407d83b68fc5d64bd3c
d26a411adee1e71b3f09dd604ab9b23018037138 10-Nov-2015 David Brazdil <dbrazdil@google.com> ART: Refactor iteration over normal/exceptional successors

Add helper methods on HBasicBlock which return ArrayRef with the
suitable sub-array of the `successors_` list.

Change-Id: I66c83bb56f2984d7550bf77c48110af4087515a8
81e479e5f768fd8ff46c2a894640a094d12800e2 10-Nov-2015 David Brazdil <dbrazdil@google.com> ART: Fix critical edge checks in GraphChecker

Previous CL I5a13b8bb74509b48f5d628906f7158af007f99ae fixed logic for
splitting critical edges. The same logic is used in GraphChecker when
testing critical edges weren't introduced by a pass. This patch updates
it too.

Bug: 25493695
Bug: 25454012
Change-Id: I56226c82324ee55ae2fbe7262608dd2868d930f1
db51efb3617d15f1cd9e5ff0cc2d934777014e9a 06-Nov-2015 David Brazdil <dbrazdil@google.com> ART: Fix critical edge splitting under try/catch

A critical edge would not be split if the predecessor ends with
TryBoundary. This would eventually trip liveness analysis because
a back edge block would have smaller liveness position than a nested
loop.

Another implication of this change is that an edge between a loop's
pre-header ending with TryBoundary and the header will be split,
guaranteeing that a pre-header always has just one successor.

Bug: 25493695
Bug: 25454012
Change-Id: I5a13b8bb74509b48f5d628906f7158af007f99ae
b554b5a5ae3cdc66969d61be20783a8af816206e 06-Nov-2015 Vladimir Marko <vmarko@google.com> Optimizing: Remove unused ArtMethod* input from HInvokeStaticOrDirect.

Change-Id: Iea99fa683440673ff517e246f35fade96600f229
9bc436160b4af99067973affb0b1008de9a2b04c 05-Nov-2015 David Brazdil <dbrazdil@google.com> ART: Fix simplification of catch blocks in the presence of dead code

Simplification of catch blocks transforms the code so that catch
blocks have only exceptional predecessors. However, it is invoked
before trivially dead code is eliminated which breaks simple
assumptions such as the fact that a catch block cannot start with
move-exception if it has non-exceptional predecessors. This patch
fixes the algorithm to work under these relaxed conditions.

Bug: 25494450
Bug: 25492628
Change-Id: Idc8d010102a4b8b9a6cd918b98d6e11d1838db0c
655e585073ac271cc9afa7c9d6ff5ab4dbe4b72e 12-Oct-2015 Vladimir Marko <vmarko@google.com> Optimizing: Move GraphChecker memory allocations to arena.

Bug: 18120045
Change-Id: I3934158e6ea4868d9baa1dfcc53b603ca6c521e2
ec7802a102d49ab5c17495118d4fe0bcc7287beb 01-Oct-2015 Vladimir Marko <vmarko@google.com> Add DCHECKs to ArenaVector and ScopedArenaVector.

Implement dchecked_vector<> template that DCHECK()s element
access and insert()/emplace()/erase() positions. Change the
ArenaVector<> and ScopedArenaVector<> aliases to use the new
template instead of std::vector<>. Remove DCHECK()s that
have now become unnecessary from the Optimizing compiler.

Change-Id: Ib8506bd30d223f68f52bd4476c76d9991acacadc
fe57faa2e0349418dda38e77ef1c0ac29db75f4d 18-Sep-2015 Mark Mendell <mark.p.mendell@intel.com> [optimizing] Add basic PackedSwitch support

Add HPackedSwitch, and generate it from the builder. Code generators
convert this to a series of compare/branch tests. Better implementation
in the code generators as a real jump table will follow as separate CLs.

Change-Id: If14736fa4d62809b6ae95280148c55682e856911
Signed-off-by: Mark Mendell <mark.p.mendell@intel.com>
3eaa32f72b6abd807964134aad4c158946dc92e3 18-Sep-2015 David Brazdil <dbrazdil@google.com> ART: Delete catch phis for undefined vregs.

SSA builder assumed that (eagerly created) catch phis for undefined
vregs must be dead and will be deleted by dead phi elimination. This,
however, does not hold for --debuggable because the catch phis might
be revived for their environment uses. This patch modifies the builder
to delete the phis itself.

Bug: 24054676
Change-Id: Iaa5f2487ff1c38353b44cb89c709bbff1ecd73cc
fa6b93c4b69e6d7ddfa2a4ed0aff01b0608c5a3a 15-Sep-2015 Vladimir Marko <vmarko@google.com> Optimizing: Tag arena allocations in HGraph.

Replace GrowableArray with ArenaVector in HGraph and related
classes HEnvironment, HLoopInformation, HInvoke and HPhi,
and tag allocations with new arena allocation types.

Change-Id: I3d79897af405b9a1a5b98bfc372e70fe0b3bc40d
77a48ae01bbc5b05ca009cf09e2fcb53e4c8ff23 15-Sep-2015 David Brazdil <dbrazdil@google.com> Revert "Revert "ART: Register allocation and runtime support for try/catch""

The original CL triggered b/24084144 which has been fixed
by Ib72e12a018437c404e82f7ad414554c66a4c6f8c.

This reverts commit 659562aaf133c41b8d90ec9216c07646f0f14362.

Change-Id: Id8980436172457d0fcb276349c4405f7c4110a55
659562aaf133c41b8d90ec9216c07646f0f14362 14-Sep-2015 David Brazdil <dbrazdil@google.com> Revert "ART: Register allocation and runtime support for try/catch"

Breaks libcore test org.apache.harmony.security.tests.java.security.KeyStorePrivateKeyEntryTest#testGetCertificateChain. Need to investigate.

This reverts commit b022fa1300e6d78639b3b910af0cf85c43df44bb.

Change-Id: Ib24d3a80064d963d273e557a93469c95f37b1f6f
b022fa1300e6d78639b3b910af0cf85c43df44bb 20-Aug-2015 David Brazdil <dbrazdil@google.com> ART: Register allocation and runtime support for try/catch

This patch completes a series of CLs that add support for try/catch
in the Optimizing compiler. With it, Optimizing can compile all
methods containing try/catch, provided they don't contain catch loops.
Future work will focus on improving performance of the generated code.

SsaLivenessAnalysis was updated to propagate liveness information of
instructions live at catch blocks, and to keep location information on
instructions which may be caught by catch phis.

RegisterAllocator was extended to spill values used after catch, and
to allocate spill slots for catch phis. Catch phis generated for the
same vreg share a spill slot as the raw value must be the same.

Location builders and slow paths were updated to reflect the fact that
throwing an exception may not lead to escaping the method.

Instruction code generators are forbidden from using of implicit null
checks in try blocks as live registers need to be saved before handing
over to the runtime.

CodeGenerator emits a stack map for each catch block, storing locations
of catch phis. CodeInfo and StackMapStream recognize this new type of
stack map and store them separate from other stack maps to avoid dex_pc
conflicts.

After having found the target catch block to deliver an exception to,
QuickExceptionHandler looks up the dex register maps at the throwing
instruction and the catch block and copies the values over to their
respective locations.

The runtime-support approach was selected because it allows for the
best performance in the normal control-flow path, since no propagation
of catch phi values is necessary until the exception is thrown. In
addition, it also greatly simplifies the register allocation phase.

ConstantHoisting was removed from LICMTest because it instantiated
(now abstract) HConstant and was bogus anyway (constants are always in
the entry block).

Change-Id: Ie31038ad8e3ee0c13a5bbbbaf5f0b3e532310e4e
6058455d486219994921b63a2d774dc9908415a2 03-Sep-2015 Vladimir Marko <vmarko@google.com> Optimizing: Tag basic block allocations with their source.

Replace GrowableArray with ArenaVector in HBasicBlock and,
to track the source of allocations, assign one new and two
Quick's arena allocation types to these vectors. Rename
kArenaAllocSuccessor to kArenaAllocSuccessors.

Bug: 23736311
Change-Id: Ib52e51698890675bde61f007fe6039338cf1a025
145acc5361deb769eed998f057bc23abaef6e116 03-Sep-2015 Vladimir Marko <vmarko@google.com> Revert "Optimizing: Tag basic block allocations with their source."

Reverting so that we can have more discussion about the STL API.

This reverts commit 91e11c0c840193c6822e66846020b6647de243d5.

Change-Id: I187fe52f2c16b6e7c5c9d49c42921eb6c7063dba
91e11c0c840193c6822e66846020b6647de243d5 02-Sep-2015 Vladimir Marko <vmarko@google.com> Optimizing: Tag basic block allocations with their source.

Replace GrowableArray with ArenaVector in HBasicBlock and,
to track the source of allocations, assign one new and two
Quick's arena allocation types to these vectors. Rename
kArenaAllocSuccessor to kArenaAllocSuccessors.

Bug: 23736311
Change-Id: I984aef6e615ae2380a532f5c6726af21015f43f5
ec16f79a4d0aeff319bf52139a0c82de3080d73c 19-Aug-2015 David Brazdil <dbrazdil@google.com> ART: Refactor try/catch block info, store exception type

This patch replaces HBasicBlock fields storing try/catch info with a
single TryCatchInformation data structure, saving memory for the
majority of non-try/catch blocks. It also changes builder to store
the exception type for catch blocks.

Change-Id: Ib3e43f7db247e6915d67c267fc62410420e230c9
29fc008c9689e9036a3f5e3bd186bbfb5de3cb82 18-Aug-2015 David Brazdil <dbrazdil@google.com> ART: Revert storing of exceptional predecessors

After change of the approach for try/catch register allocation, it is
no longer necessary to record instructions which might throw into a
catch block.

Change-Id: I7ef12ed06c49a35280029810975fa2a50fe4a424
b618adebbc19e50d7b1aa2f11b84341beb3c64dc 29-Jul-2015 David Brazdil <dbrazdil@google.com> ART: Store and check exceptional predecessors

Future CL on register allocation for try/catch will require the
knowledge of instructions which throw into a catch block. This patch
stores that information with the basic block and verifies it in the
graph checker.

More checks on try catch also added to the graph checker and an order
of exception handlers is enforced in TryBoundary successors.

Change-Id: I3034c610791ea51d96724bcca97f49ec6ecf2af3
ffee3d33f3ea39aa6031c3d2ff29c4806c8dcc51 06-Jul-2015 David Brazdil <dbrazdil@google.com> ART: Build SSA form when try/catch is present

This patch implements support for try/catch in the SsaBuilder.
Values of locals are propagated from throwing sites inside try
blocks to their respective catch blocks and phis ("catch phis")
are created when necessary.

Change-Id: I0736565c2c4ff3f9f0924b6e3a785a50023f875a
b7a4790e5a2884e62f6dc85aca1455b145e2a7db 29-Jun-2015 Nicolas Geoffray <ngeoffray@google.com> Revert "Revert "Do not update the type of something we already know.""

This reverts commit 63107a804ce17db9789051e1fe310d99d1dae1cb.

bug:22116987

(cherry picked from commit f9a199571417b5a5a62d94d05a064077e14dd2c4)

Change-Id: Ia516f2cbce6d22df37f3a0854abdd0b54d3ea72d
f9a199571417b5a5a62d94d05a064077e14dd2c4 29-Jun-2015 Nicolas Geoffray <ngeoffray@google.com> Revert "Revert "Do not update the type of something we already know.""

This reverts commit 63107a804ce17db9789051e1fe310d99d1dae1cb.

bug:22116987
Change-Id: I49a376a5bd2073a69babe122ec0d26e5d2f82461
63107a804ce17db9789051e1fe310d99d1dae1cb 29-Jun-2015 Calin Juravle <calin@google.com> Revert "Do not update the type of something we already know."

This reverts commit 30eb58c548bee08468f68eb140a74a51dd7d9b43.

Change-Id: Icd959e868160fc3ee7031dd2927554ac5b21d40f
30eb58c548bee08468f68eb140a74a51dd7d9b43 29-Jun-2015 Nicolas Geoffray <ngeoffray@google.com> Do not update the type of something we already know.

This is both an optimization to avoid unneeded nodes,
and correctness to avoid replacing the second input
of `HInstanceOf` and `HCheckCast` to something that is
not `HLoadClass`.

bug:22116987

Change-Id: I4907197a9002883d7cae8265a9642512b6201396
fc6a86ab2b70781e72b807c1798b83829ca7f931 26-Jun-2015 David Brazdil <dbrazdil@google.com> Revert "Revert "ART: Implement try/catch blocks in Builder""

This patch enables the GraphBuilder to generate blocks and edges which
represent the exceptional control flow when try/catch blocks are
present in the code. Actual compilation is still delegated to Quick
and Baseline ignores the additional code.

To represent the relationship between try and catch blocks, Builder
splits the edges which enter/exit a try block and links the newly
created blocks to the corresponding exception handlers. This layout
will later enable the SsaBuilder to correctly infer the dominators of
the catch blocks and to produce the appropriate reverse post ordering.
It will not, however, allow for building the complete SSA form of the
catch blocks and consequently optimizing such blocks.

To this end, a new TryBoundary control-flow instruction is introduced.
Codegen treats it the same as a Goto but it allows for additional
successors (the handlers).

This reverts commit 3e18738bd338e9f8363b26bc895f38c0ec682824.

Change-Id: I4f5ea961848a0b83d8db3673763861633e9bfcfb
3e18738bd338e9f8363b26bc895f38c0ec682824 26-Jun-2015 David Brazdil <dbrazdil@google.com> Revert "ART: Implement try/catch blocks in Builder"

Causes OutOfMemory issues, need to investigate.

This reverts commit 0b5c7d1994b76090afcc825e737f2b8c546da2f8.

Change-Id: I263e6cc4df5f9a56ad2ce44e18932ca51d7e349f
0b5c7d1994b76090afcc825e737f2b8c546da2f8 11-Jun-2015 David Brazdil <dbrazdil@google.com> ART: Implement try/catch blocks in Builder

This patch enables the GraphBuilder to generate blocks and edges which
represent the exceptional control flow when try/catch blocks are
present in the code. Actual compilation is still delegated to Quick
and Baseline ignores the additional code.

To represent the relationship between try and catch blocks, Builder
splits the edges which enter/exit a try block and links the newly
created blocks to the corresponding exception handlers. This layout
will later enable the SsaBuilder to correctly infer the dominators of
the catch blocks and to produce the appropriate reverse post ordering.
It will not, however, allow for building the complete SSA form of the
catch blocks and consequently optimizing such blocks.

To this end, a new TryBoundary control-flow instruction is introduced.
Codegen treats it the same as a Goto but it allows for additional
successors (the handlers).

Change-Id: I415b985596d5bebb7b1bb358a46e08b7b04bb53a
1d8b49fad0798fef57a0e2f799dbd51e29812120 12-May-2015 Calin Juravle <calin@google.com> Revert "Add new rule to the graph checker."

This reverts commit 9d50775046a51941f86cced03593c61c89ae615e.

Change-Id: I9533116bbaef5fd5d2944c4ebebd2f01b0047e34
9d50775046a51941f86cced03593c61c89ae615e 11-May-2015 Calin Juravle <calin@google.com> Add new rule to the graph checker.

Phis typed as `reference` should not have equivalents after building the
SSA.

Change-Id: I9cac189362583ef7c9c7defd3da7338f419f2f94
0a23d74dc2751440822960eab218be4cb8843647 07-May-2015 Nicolas Geoffray <ngeoffray@google.com> Add a parent environment to HEnvironment.

This code has no functionality change. It adds a placeholder
for chaining inlined frames.

Change-Id: I5ec57335af76ee406052345b947aad98a6a4423a
db216f4d49ea1561a74261c29f1264952232728a 05-May-2015 Nicolas Geoffray <ngeoffray@google.com> Relax the only one back-edge restriction.

The rule is in the way for better register allocation, as
it creates an artificial join point between multiple paths.

Change-Id: Ia4392890f95bcea56d143138f28ddce6c572ad58
6db49a74e8402d3b6c66536ea7ec988144c05d24 28-Apr-2015 Nicolas Geoffray <ngeoffray@google.com> Update the remaining input index of phis after deleting an input.

bug:20715803
bug:20690906

(cherry picked from commit 5d7b7f81ed5455893f984752c00571ef27cc97c5)

Change-Id: Ie55739601b8d6fedc830d6e19d8a053392047d34
5d7b7f81ed5455893f984752c00571ef27cc97c5 28-Apr-2015 Nicolas Geoffray <ngeoffray@google.com> Update the remaining input index of phis after deleting an input.

bug:20715803
bug:20690906

Change-Id: Iaf08f0c30d629e766be2b04815dc3e38b6e7ff35
1152c926076a760490085c4497c3f117fa8da891 24-Apr-2015 Mark Mendell <mark.p.mendell@intel.com> [optimizing] Rename HasArrayAccesses and check it

Since the flag is only used to see if there is a HBoundsCheck, rename
HasArrayAccesses() to HasBoundsChecks().

Add a check in graph_checker to see that the flag is set if we see a
HBoundsCheck instruction.

Change-Id: I10fe92897374fb247082152dd75c3611cc40ff30
Signed-off-by: Mark Mendell <mark.p.mendell@intel.com>
4c0eb42259d790fddcd9978b66328dbb3ab65615 24-Apr-2015 Roland Levillain <rpl@google.com> Ensure inlined static calls perform clinit checks in Optimizing.

Calls to static methods have implicit class initialization
(clinit) checks of the method's declaring class in
Optimizing. However, when such a static call is inlined,
the implicit clinit check vanishes, possibly leading to an
incorrect behavior.

To ensure that inlining static methods does not change the
behavior of a program, add explicit class initialization
checks (art::HClinitCheck) as well as load class
instructions (art::HLoadClass) as last input of static
calls (art::HInvokeStaticOrDirect) in Optimizing' control
flow graphs, when the declaring class is reachable and not
known to be already initialized. Then when considering the
inlining of a static method call, proceed only if the method
has no implicit clinit check requirement.

The added explicit clinit checks are already removed by the
art::PrepareForRegisterAllocation visitor. This CL also
extends this visitor to turn explicit clinit checks from
static invokes into implicit ones after the inlining step,
by removing the added art::HLoadClass nodes mentioned
hereinbefore.

Change-Id: I9ba452b8bd09ae1fdd9a3797ef556e3e7e19c651
2d7352ba5311b8f57427b91b7a891e61497373c1 20-Apr-2015 David Brazdil <dbrazdil@google.com> ART: Dead block removal

Adds a new pass which finds all unreachable blocks, typically due to
simplifying an if-condition to a constant, and removes them from the
graph. The patch also slightly generalizes the graph-transforming
operations.

Change-Id: Iff7c97f1d10b52886f3cd7401689ebe1bfdbf456
c3d743fa2a26effcb35627d8a1338029c86e582a 22-Apr-2015 David Brazdil <dbrazdil@google.com> ART: Update last_instruction when adding Phis

HBasicBlock::InsertPhiAfter would not update the last_instruction
pointer when adding at the end of the list. This could cause problems
when iterating over phis backwards. Fortunately, we don't do that
anywhere in the existing code.

Change-Id: I4487265bf2cf3d3819623fafd7ce7c359bac190e
7d275379bf490a87805852129e3fe2e8afe961e7 21-Apr-2015 David Brazdil <dbrazdil@google.com> ART: Update loop info of all nested loops when inlining

When inlining into a nested loop, the inliner would only add the new
blocks into the innermost loop info object. This patch fixes that and
modifies SsaChecker to verify the property.

Change-Id: I21d343a6f7d972f5b7420701f816c65ab3f20566
2fa194bf16678e9e8f9e2653e47cb703dbbc9738 20-Apr-2015 David Brazdil <dbrazdil@google.com> ART: Extend list of instructions accepted as boolean inputs

Previous change allowed integer Phis as inputs of instructions
expecting a boolean type. This list, however, was not exhaustive as
binary operations And, Or and Xor are also valid inputs. This patch
extends the list in SSAChecker.

Change-Id: I5b5c9e7a17992cc4987e3a078ee23ea80028ecfc
a4f8831d6533e4fe5aed18433099e1130d95a877 16-Apr-2015 Calin Juravle <calin@google.com> Remove duplicates phis created during SSA transformation

When creating equivalent phis we copy the inputs of the original phi
which may be improperly typed. This will be fixed during the type
propagation but as a result we may have two equivalent phis with the
same type for the same dex register. This is correct but generates more
code and prevent some optimizations.

This CL adds another step in the SSA builder to remove the extra Phi
nodes created due to equality operators.

The graph checker verifies that for a given dex register not two phis
have the same type.

Also, replace zero int constant with null constant when we compare a
reference against null.

Change-Id: Id37cc11a016ea767c7e351575e003d822a9d2e60
13b4718ecd52a674b25eac106e654d8e89872750 15-Apr-2015 David Brazdil <dbrazdil@google.com> ART: Remove DCHECKs for boolean type

Since bool and int are interchangeable types, checking whether an
input is kPrimBoolean can fail when replaced with 0/1 constant or
a phi. This patch removes the problematic DCHECKs, adds a best-effort
verification into SSAChecker but leaves the phi case empty until a
suitable analysis is implemented.

Change-Id: I31e8daf27dd33d2fd74049b82bed1cb7c240c8c6
8d5b8b295930aaa43255c4f0b74ece3ee8b43a47 24-Mar-2015 David Brazdil <dbrazdil@google.com> ART: Force constants into the entry block

Optimizations such as GVN and BCE make the assumption that all
constants are located in the entry block of the CFG, but not all
passes adhere to this rule.

This patch makes constructors of constants private and only accessible
to friend classes - HGraph for int/long constants and SsaBuilder for
float/double - which ensure that they are placed correctly and not
duplicated.

Note that the ArenaAllocatorAdapter was modified to not increment
the ArenaAllocator's internal reference counter in order to allow
for use of ArenaSafeMap inside an arena-allocated objects. Because
their destructor is not called, the counter does not get decremented.

Change-Id: I36a4fa29ae34fb905cdefd482ccbf386cff14166
46e2a3915aa68c77426b71e95b9f3658250646b7 16-Mar-2015 David Brazdil <dbrazdil@google.com> ART: Boolean simplifier

The optimization recognizes the negation pattern generated by 'javac'
and replaces it with a single condition. To this end, boolean values
are now consistently assumed to be represented by an integer.

This is a first optimization which deletes blocks from the HGraph and
does so by replacing the corresponding entries with null. Hence,
existing code can continue indexing the list of blocks with the block
ID, but must check for null when iterating over the list.

Change-Id: I7779da69cfa925c6521938ad0bcc11bc52335583
e0fe7ae36180863e45cbb9d1e6e9c30b1b1a949c 09-Mar-2015 Nicolas Geoffray <ngeoffray@google.com> Make the SSA builder honor the debuggable flag.

This requires to properly type phis that are only
used by environments, and discard phis with incomptable types.
The code generators do not handle these conflicting types. In
the process, ensure a phi has a type that does not depend
on the order of the inputs (for example (char, short) -> short),
and set int for int-like types. We can refine this later.

Change-Id: I60ab601d6d00b1cbf18623ee4ff1795aa28f84a1
1abb4191a2e56d8dbf518efcaeefb266c1acdf2b 17-Feb-2015 David Brazdil <dbrazdil@google.com> Optimizing: Speed up HInstruction use removal

Similarly to a previous commit on HEnvironment use removal, this patch
adds links from instructions to their respective inputs' use lists for
contant-time removal at the cost of doubling the size of input lists
(from one pointer per entry to two). Manual testing shows that this
significantly reduces the time required to transform HGraph to SSA
form for some huge methods.

Change-Id: I8dc3e4b0c48a50ac1481eb55c31093b99f4dc29f
d6138ef1ea13d07ae555542f8898b30d89e9ac9a 18-Feb-2015 Nicolas Geoffray <ngeoffray@google.com> Ensure the graph is correctly typed.

We used to be forgiving because of HIntConstant(0) also being
used for null. We now create a special HNullConstant for such uses.

Also, we need to run the dead phi elimination twice during ssa
building to ensure the correctness.

Change-Id: If479efa3680d3358800aebb1cca692fa2d94f6e5
276d9daaedfbff716339f94d55e6eff98b7434c6 02-Feb-2015 Nicolas Geoffray <ngeoffray@google.com> Inline methods with multiple blocks.

Change-Id: I3431af60e97fae230e0b6e98bcf0acc0ee9abf8c
ed59619b370ef23ffbb25d1d01f615e60a9262b6 23-Jan-2015 David Brazdil <dbrazdil@google.com> Optimizing: Speed up HEnvironment use removal

Removal of use records from HEnvironment vregs involved iterating over
potentially large linked lists which made compilation of huge methods
very slow. This patch turns use lists into doubly-linked lists, stores
pointers to the relevant nodes inside HEnvironment and subsequently
turns the removals into constant-time operations.

Change-Id: I0e1d4d782fd624e7b8075af75d4adf0a0634a1ee
5c4405e8ca4a0c1ee2d7759e650530c9aff77fd0 21-Jan-2015 Roland Levillain <rpl@google.com> Improve error messages in art::GraphChecker and art::SSAChecker

- Add an art::GraphChecker::AddError helper.
- Use StringPrintf instead of std::stringstream.
- Rephrase some error messages.

Change-Id: Ia741e9e67cb5122f086a7383a2bc02d60ca637df
aecbd26b29c6122d1eacfd67e0bd5aa26b96eebb 19-Jan-2015 Roland Levillain <rpl@google.com> Ensure HCondition nodes on objects are either HEqual or HNotEqual

Change-Id: I47efae209b7ab931d7d314e5b37582a7e21085d5
9ee66183d8e046ea661f642ba884626f16b46e06 16-Jan-2015 Nicolas Geoffray <ngeoffray@google.com> Constant fold after inlining.

- Inlining opens up new opportunities for constant folding.
- Fix a bug in constant folder where the result type was not
correctly set for the folding of a HCompare.
- Improve graph checker's coverage.

Change-Id: I0943bf8ff65505c4addc4a555a526b55e00b5268
7c5367badfe61b96c5836d495d286cee64861579 17-Dec-2014 Nicolas Geoffray <ngeoffray@google.com> Fix ids and remove invoke when inlining.

Bugs found by Razvan Lupusoru.

Change-Id: I3a5a9af280d8700d18f52abb4a2cff0e3a9aac74
3159674c0863f53cfbc1913d493550221ac47f02 24-Nov-2014 Nicolas Geoffray <ngeoffray@google.com> Fix a bug in the type analysis phase of optimizing.

Dex code can lead to the creation of a phi with one
float input and one integer input. Since the SSA builder trusts
the verifier, it assumes that the integer input must be converted
to float. However, when the register is not used afterwards, the
verifier hasn't ensured that. Therefore, the compiler must remove
the phi prior to doing type propagation.

Change-Id: Idcd51c4dccce827c59d1f2b253bc1c919bc07df5
91356c028022180dfbe54ed7f5f465041c8b23ff 07-Nov-2014 Andreas Gampe <agampe@google.com> ART: Use std::vector in GraphChecker

(Temporarily) move GraphChecker to use std::vector for errors, as
std::strings need to be destructed.

Bug: 18120045
Change-Id: I7d38001e6b1f3cee14299194d4515b985541d656
6c82d40eb142771086f5531998de2273ba5cc08c 13-Oct-2014 Roland Levillain <rpl@google.com> Have HInstruction::StrictlyDominates compute strict dominance.

Change-Id: I3a4fa133268615fb4ce54a0bcb43e0c2458cc865
a8069ce1c3caa4f9b1651988986f3732152c186d 01-Oct-2014 Roland Levillain <rpl@google.com> Improve art::SSAChecker::VisitInstruction.

Actually inspect the uses of an instruction to ensure the
latter dominates all of the former, instead of browsing the
inputs of this instruction (to ensure they dominate the
instruction).

Also check instruction domination with respect to environment
uses.

Change-Id: I967f34a45f48930607bf9683180d02e7c27b4e06
6b46923ff0197c95f1e7ea0bc730961df6725cc9 25-Sep-2014 Roland Levillain <rpl@google.com> Optimizing compiler: check inputs & uses definitions in CFG.

Ensure each input and each use of an instruction is defined
in a block of the control-flow graph.

Change-Id: If4a83b02825230329b0b4fd84255dcb7c3219684
7e53b415e5e587cd7961978f6da7347248f40b29 23-Sep-2014 Roland Levillain <rpl@google.com> Optimizing compiler: ensure loop header dominates loop's blocks.

Change-Id: I6b2f1fdaac9f91dc5d9901cc2ad4c83745e90e70
6b879ddc0959df1cec871f0d41f11cce35a11716 22-Sep-2014 Roland Levillain <rpl@google.com> Add loop- and phi-related checks in the optimizing compiler.

- Ensure the pre-header block is first in the list of
predecessors of a loop header.
- Ensure the loop header has only two predecessors and that
only the second one is the back edge.
- Ensure there is only one back edge per loop.
- Ensure the first input of a phi is not itself.
- Ensure the number of phi inputs is the same as the number
of its predecessors.
- Ensure phi input at index I either comes from the Ith
predecessor or from a block that dominates this
predecessor.

Change-Id: I4db5c68cfbc9b74d2d03125753d0143ece625378
ccc07a9579c554443cd03a306ca9b4f943fd2a93 16-Sep-2014 Roland Levillain <rpl@google.com> Add CFG and SSA form checkers in the optimizing compiler.

Checks performed on control-flow graphs:
- Ensure that the predecessors and successors of a basic block are
consistent within a control-flow graph.
- Ensure basic blocks end with a branch instruction.
- Detect phi functions listed in non-phi instruction lists and vice
versa.
- Ensure a block's instructions (and phi functions) are associated
with this very block.

Checks performed on SSA form graphs:
- Ensure an instruction dominates all its uses.
- Ensure there are no critical edges.

Change-Id: I1c12b4a61ecf608682152c897980ababa7eca847