blob: f5d8d82571514b2650ffd48da986516a1a6c4914 [file] [log] [blame]
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "prepare_for_register_allocation.h"
18
19namespace art {
20
21void PrepareForRegisterAllocation::Run() {
22 // Order does not matter.
23 for (HReversePostOrderIterator it(*GetGraph()); !it.Done(); it.Advance()) {
24 HBasicBlock* block = it.Current();
25 // No need to visit the phis.
Andreas Gampe277ccbd2014-11-03 21:36:10 -080026 for (HInstructionIterator inst_it(block->GetInstructions()); !inst_it.Done();
27 inst_it.Advance()) {
28 inst_it.Current()->Accept(this);
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +010029 }
30 }
31}
32
33void PrepareForRegisterAllocation::VisitNullCheck(HNullCheck* check) {
34 check->ReplaceWith(check->InputAt(0));
35}
36
Calin Juravled0d48522014-11-04 16:40:20 +000037void PrepareForRegisterAllocation::VisitDivZeroCheck(HDivZeroCheck* check) {
38 check->ReplaceWith(check->InputAt(0));
39}
40
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +010041void PrepareForRegisterAllocation::VisitBoundsCheck(HBoundsCheck* check) {
42 check->ReplaceWith(check->InputAt(0));
43}
44
Calin Juravleb1498f62015-02-16 13:13:29 +000045void PrepareForRegisterAllocation::VisitBoundType(HBoundType* bound_type) {
46 bound_type->ReplaceWith(bound_type->InputAt(0));
47 bound_type->GetBlock()->RemoveInstruction(bound_type);
48}
49
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010050void PrepareForRegisterAllocation::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +000051 HLoadClass* cls = check->GetLoadClass();
52 check->ReplaceWith(cls);
53 if (check->GetPrevious() == cls) {
54 // Pass the initialization duty to the `HLoadClass` instruction,
55 // and remove the instruction from the graph.
56 cls->SetMustGenerateClinitCheck();
57 check->GetBlock()->RemoveInstruction(check);
58 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010059}
60
Nicolas Geoffray360231a2014-10-08 21:07:48 +010061void PrepareForRegisterAllocation::VisitCondition(HCondition* condition) {
62 bool needs_materialization = false;
David Brazdil0534beb2015-04-01 17:00:59 +010063 if (!condition->GetUses().HasOnlyOneUse() || !condition->GetEnvUses().IsEmpty()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +010064 needs_materialization = true;
65 } else {
David Brazdiled596192015-01-23 10:39:45 +000066 HInstruction* user = condition->GetUses().GetFirst()->GetUser();
Mingyao Yangd43b3ac2015-04-01 14:03:04 -070067 if (!user->IsIf() && !user->IsDeoptimize()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +010068 needs_materialization = true;
69 } else {
70 // TODO: if there is no intervening instructions with side-effect between this condition
71 // and the If instruction, we should move the condition just before the If.
72 if (condition->GetNext() != user) {
73 needs_materialization = true;
74 }
75 }
76 }
77 if (!needs_materialization) {
78 condition->ClearNeedsMaterialization();
79 }
80}
81
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +010082} // namespace art