Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
| 19 | namespace art { |
| 20 | |
| 21 | void 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 Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 26 | for (HInstructionIterator inst_it(block->GetInstructions()); !inst_it.Done(); |
| 27 | inst_it.Advance()) { |
| 28 | inst_it.Current()->Accept(this); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 29 | } |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | void PrepareForRegisterAllocation::VisitNullCheck(HNullCheck* check) { |
| 34 | check->ReplaceWith(check->InputAt(0)); |
| 35 | } |
| 36 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 37 | void PrepareForRegisterAllocation::VisitDivZeroCheck(HDivZeroCheck* check) { |
| 38 | check->ReplaceWith(check->InputAt(0)); |
| 39 | } |
| 40 | |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 41 | void PrepareForRegisterAllocation::VisitBoundsCheck(HBoundsCheck* check) { |
| 42 | check->ReplaceWith(check->InputAt(0)); |
| 43 | } |
| 44 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 45 | void PrepareForRegisterAllocation::VisitBoundType(HBoundType* bound_type) { |
| 46 | bound_type->ReplaceWith(bound_type->InputAt(0)); |
| 47 | bound_type->GetBlock()->RemoveInstruction(bound_type); |
| 48 | } |
| 49 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 50 | void PrepareForRegisterAllocation::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 51 | 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 Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 59 | } |
| 60 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 61 | void PrepareForRegisterAllocation::VisitCondition(HCondition* condition) { |
| 62 | bool needs_materialization = false; |
David Brazdil | 0534beb | 2015-04-01 17:00:59 +0100 | [diff] [blame] | 63 | if (!condition->GetUses().HasOnlyOneUse() || !condition->GetEnvUses().IsEmpty()) { |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 64 | needs_materialization = true; |
| 65 | } else { |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 66 | HInstruction* user = condition->GetUses().GetFirst()->GetUser(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 67 | if (!user->IsIf() && !user->IsDeoptimize()) { |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 68 | 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 Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 82 | } // namespace art |