blob: 40e1f0786e7696d9568703986099e0ecbb08d47e [file] [log] [blame]
Ben Chenge9695e52009-06-16 16:11:47 -07001/*
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 Buzbee89efc3d2009-07-28 11:22:22 -070019#include "ArmLIR.h"
Ben Chenge9695e52009-06-16 16:11:47 -070020
21/*
22 * Identify unconditional branches that jump to the immediate successor of the
23 * branch itself.
24 */
25static void applyRedundantBranchElimination(CompilationUnit *cUnit)
26{
Bill Buzbee89efc3d2009-07-28 11:22:22 -070027 ArmLIR *thisLIR;
Ben Chenge9695e52009-06-16 16:11:47 -070028
Bill Buzbee89efc3d2009-07-28 11:22:22 -070029 for (thisLIR = (ArmLIR *) cUnit->firstLIRInsn;
30 thisLIR != (ArmLIR *) cUnit->lastLIRInsn;
Ben Chenge9695e52009-06-16 16:11:47 -070031 thisLIR = NEXT_LIR(thisLIR)) {
32
33 /* Branch to the next instruction */
Bill Buzbee89efc3d2009-07-28 11:22:22 -070034 if (thisLIR->opCode == THUMB_B_UNCOND) {
35 ArmLIR *nextLIR = thisLIR;
Ben Chenge9695e52009-06-16 16:11:47 -070036
37 while (true) {
38 nextLIR = NEXT_LIR(nextLIR);
39
40 /*
41 * Is the branch target the next instruction?
42 */
Bill Buzbee89efc3d2009-07-28 11:22:22 -070043 if (nextLIR == (ArmLIR *) thisLIR->generic.target) {
Ben Chenge9695e52009-06-16 16:11:47 -070044 thisLIR->isNop = true;
45 break;
46 }
47
48 /*
49 * Found real useful stuff between the branch and the target
50 */
51 if (!isPseudoOpCode(nextLIR->opCode) ||
Bill Buzbee89efc3d2009-07-28 11:22:22 -070052 nextLIR->opCode == ARM_PSEUDO_ALIGN4)
Ben Chenge9695e52009-06-16 16:11:47 -070053 break;
54 }
55 }
56 }
57}
58
59void dvmCompilerApplyGlobalOptimizations(CompilationUnit *cUnit)
60{
61 applyRedundantBranchElimination(cUnit);
62}