| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 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 "Dalvik.h" |
| 18 | #include "vm/compiler/CompilerInternals.h" |
| Bill Buzbee | 89efc3d | 2009-07-28 11:22:22 -0700 | [diff] [blame] | 19 | #include "ArmLIR.h" |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 20 | |
| 21 | /* |
| 22 | * Identify unconditional branches that jump to the immediate successor of the |
| 23 | * branch itself. |
| 24 | */ |
| 25 | static void applyRedundantBranchElimination(CompilationUnit *cUnit) |
| 26 | { |
| Bill Buzbee | 89efc3d | 2009-07-28 11:22:22 -0700 | [diff] [blame] | 27 | ArmLIR *thisLIR; |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 28 | |
| Bill Buzbee | 89efc3d | 2009-07-28 11:22:22 -0700 | [diff] [blame] | 29 | for (thisLIR = (ArmLIR *) cUnit->firstLIRInsn; |
| 30 | thisLIR != (ArmLIR *) cUnit->lastLIRInsn; |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 31 | thisLIR = NEXT_LIR(thisLIR)) { |
| 32 | |
| 33 | /* Branch to the next instruction */ |
| Bill Buzbee | 89efc3d | 2009-07-28 11:22:22 -0700 | [diff] [blame] | 34 | if (thisLIR->opCode == THUMB_B_UNCOND) { |
| 35 | ArmLIR *nextLIR = thisLIR; |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 36 | |
| 37 | while (true) { |
| 38 | nextLIR = NEXT_LIR(nextLIR); |
| 39 | |
| 40 | /* |
| 41 | * Is the branch target the next instruction? |
| 42 | */ |
| Bill Buzbee | 89efc3d | 2009-07-28 11:22:22 -0700 | [diff] [blame] | 43 | if (nextLIR == (ArmLIR *) thisLIR->generic.target) { |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 44 | thisLIR->isNop = true; |
| 45 | break; |
| 46 | } |
| 47 | |
| 48 | /* |
| 49 | * Found real useful stuff between the branch and the target |
| 50 | */ |
| Ben Cheng | 6d57609 | 2009-09-01 17:01:58 -0700 | [diff] [blame^] | 51 | if (!isPseudoOpCode(nextLIR->opCode)) |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 52 | break; |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | void dvmCompilerApplyGlobalOptimizations(CompilationUnit *cUnit) |
| 59 | { |
| 60 | applyRedundantBranchElimination(cUnit); |
| 61 | } |