blob: 2b8ec6fd07c9503a7ccad16e55c0363a86746f6f [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"
19#include "Armv5teLIR.h"
20
21/*
22 * Identify unconditional branches that jump to the immediate successor of the
23 * branch itself.
24 */
25static void applyRedundantBranchElimination(CompilationUnit *cUnit)
26{
27 Armv5teLIR *thisLIR;
28
29 for (thisLIR = (Armv5teLIR *) cUnit->firstLIRInsn;
30 thisLIR != (Armv5teLIR *) cUnit->lastLIRInsn;
31 thisLIR = NEXT_LIR(thisLIR)) {
32
33 /* Branch to the next instruction */
34 if (thisLIR->opCode == ARMV5TE_B_UNCOND) {
35 Armv5teLIR *nextLIR = thisLIR;
36
37 while (true) {
38 nextLIR = NEXT_LIR(nextLIR);
39
40 /*
41 * Is the branch target the next instruction?
42 */
43 if (nextLIR == (Armv5teLIR *) thisLIR->generic.target) {
44 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) ||
52 nextLIR->opCode == ARMV5TE_PSEUDO_ALIGN4)
53 break;
54 }
55 }
56 }
57}
58
59void dvmCompilerApplyGlobalOptimizations(CompilationUnit *cUnit)
60{
61 applyRedundantBranchElimination(cUnit);
62}