• 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 == kThumbBUncond) {
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->flags.isNop = true;
45                     break;
46                 }
47 
48                 /*
49                  * Found real useful stuff between the branch and the target.
50                  * Need to explicitly check the lastLIRInsn here since with
51                  * method-based JIT the branch might be the last real
52                  * instruction.
53                  */
54                 if (!isPseudoOpcode(nextLIR->opcode) ||
55                     (nextLIR = (ArmLIR *) cUnit->lastLIRInsn))
56                     break;
57             }
58         }
59     }
60 }
61 
dvmCompilerApplyGlobalOptimizations(CompilationUnit * cUnit)62 void dvmCompilerApplyGlobalOptimizations(CompilationUnit *cUnit)
63 {
64     applyRedundantBranchElimination(cUnit);
65 }
66