• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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"
19 #include "ArmLIR.h"
20 
21 /*
22  * Identify unconditional branches that jump to the immediate successor of the
23  * branch itself.
24  */
applyRedundantBranchElimination(CompilationUnit * cUnit)25 static void applyRedundantBranchElimination(CompilationUnit *cUnit)
26 {
27     ArmLIR *thisLIR;
28 
29     for (thisLIR = (ArmLIR *) cUnit->firstLIRInsn;
30          thisLIR != (ArmLIR *) cUnit->lastLIRInsn;
31          thisLIR = NEXT_LIR(thisLIR)) {
32 
33         /* Branch to the next instruction */
34         if (thisLIR->opCode == THUMB_B_UNCOND) {
35             ArmLIR *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 == (ArmLIR *) 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 == ARM_PSEUDO_ALIGN4)
53                     break;
54             }
55         }
56     }
57 }
58 
dvmCompilerApplyGlobalOptimizations(CompilationUnit * cUnit)59 void dvmCompilerApplyGlobalOptimizations(CompilationUnit *cUnit)
60 {
61     applyRedundantBranchElimination(cUnit);
62 }
63