diff options
author | mikaelpeltier <mikaelpeltier@google.com> | 2014-04-24 17:26:46 +0200 |
---|---|---|
committer | mikaelpeltier <mikaelpeltier@google.com> | 2014-04-24 17:26:46 +0200 |
commit | 53ff02be852b38ca8db0862fa6017069d507eb9e (patch) | |
tree | 0ce2df9cb0f6231ff922e4eed74b12b00d4aad75 /dx | |
parent | 0c8aa9309588ff03e4589ab789f96f32790a0d68 (diff) | |
download | toolchain_jack-53ff02be852b38ca8db0862fa6017069d507eb9e.zip toolchain_jack-53ff02be852b38ca8db0862fa6017069d507eb9e.tar.gz toolchain_jack-53ff02be852b38ca8db0862fa6017069d507eb9e.tar.bz2 |
Remove move param combiner optimization
- Jack generates only one move-param instruction by parameters, thus
this optimization is useless.
Change-Id: Ib2869ea9ed0a4cf99d0f2408d4962989835c2d9d
Diffstat (limited to 'dx')
-rw-r--r-- | dx/src/com/android/jack/dx/ssa/MoveParamCombiner.java | 157 | ||||
-rw-r--r-- | dx/src/com/android/jack/dx/ssa/Optimizer.java | 6 |
2 files changed, 1 insertions, 162 deletions
diff --git a/dx/src/com/android/jack/dx/ssa/MoveParamCombiner.java b/dx/src/com/android/jack/dx/ssa/MoveParamCombiner.java deleted file mode 100644 index 29141f0..0000000 --- a/dx/src/com/android/jack/dx/ssa/MoveParamCombiner.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.jack.dx.ssa; - -import com.android.jack.dx.rop.code.CstInsn; -import com.android.jack.dx.rop.code.LocalItem; -import com.android.jack.dx.rop.code.RegOps; -import com.android.jack.dx.rop.code.RegisterSpec; -import com.android.jack.dx.rop.cst.CstInteger; - -import java.util.HashSet; -import java.util.List; - -/** - * Combine identical move-param insns, which may result from Ropper's - * handling of synchronized methods. - */ -public class MoveParamCombiner { - - /** method to process */ - private final SsaMethod ssaMeth; - - /** - * Processes a method with this optimization step. - * - * @param ssaMethod method to process - */ - public static void process(SsaMethod ssaMethod) { - new MoveParamCombiner(ssaMethod).run(); - } - - private MoveParamCombiner(SsaMethod ssaMeth) { - this.ssaMeth = ssaMeth; - } - - /** - * Runs this optimization step. - */ - private void run() { - // This will contain the definition specs for each parameter - final RegisterSpec[] paramSpecs = new RegisterSpec[ssaMeth.getParamWidth()]; - - // Insns to delete when all done - final HashSet<SsaInsn> deletedInsns = new HashSet<SsaInsn>(); - - ssaMeth.forEachInsn(new SsaInsn.Visitor() { - @Override - public void visitMoveInsn(NormalSsaInsn insn) {} - - @Override - public void visitPhiInsn(PhiInsn phi) {} - - @Override - public void visitNonMoveInsn(NormalSsaInsn insn) { - if (insn.getOpcode().getOpcode() != RegOps.MOVE_PARAM) { - return; - } - - int param = getParamIndex(insn); - - if (paramSpecs[param] == null) { - paramSpecs[param] = insn.getResult(); - } else { - final RegisterSpec specA = paramSpecs[param]; - final RegisterSpec specB = insn.getResult(); - LocalItem localA = specA.getLocalItem(); - LocalItem localB = specB.getLocalItem(); - LocalItem newLocal; - - /* - * Is there local information to preserve? - */ - -if (localA == null) { - newLocal = localB; - } else if (localB == null) { - newLocal = localA; - } else if (localA.equals(localB)) { - newLocal = localA; - } else { - /* - * Oddly, these two identical move-params have distinct - * debug info. We'll just keep them distinct. - */ - return; - } - - ssaMeth.getDefinitionForRegister(specA.getReg()).setResultLocal(newLocal); - - /* - * Map all uses of specB to specA - */ - - RegisterMapper mapper = new RegisterMapper() { - @Override - /** @inheritDoc */ - public int getNewRegisterCount() { - return ssaMeth.getRegCount(); - } - - @Override - /** @inheritDoc */ - public RegisterSpec map(RegisterSpec registerSpec) { - if (registerSpec.getReg() == specB.getReg()) { - return specA; - } - - return registerSpec; - } - }; - - List<SsaInsn> uses = ssaMeth.getUseListForRegister(specB.getReg()); - - // Use list is modified by mapSourceRegisters - for (int i = uses.size() - 1; i >= 0; i--) { - SsaInsn use = uses.get(i); - use.mapSourceRegisters(mapper); - } - - deletedInsns.add(insn); - } - - } - }); - - ssaMeth.deleteInsns(deletedInsns); - } - - /** - * Returns the parameter index associated with a move-param insn. Does - * not verify that the insn is a move-param insn. - * - * @param insn {@code non-null;} a move-param insn - * @return {@code >=0;} parameter index - */ - private int getParamIndex(NormalSsaInsn insn) { - CstInsn cstInsn = (CstInsn) (insn.getOriginalRopInsn()); - - int param = ((CstInteger) cstInsn.getConstant()).getValue(); - return param; - } - -} diff --git a/dx/src/com/android/jack/dx/ssa/Optimizer.java b/dx/src/com/android/jack/dx/ssa/Optimizer.java index 35d6460..42c6d28 100644 --- a/dx/src/com/android/jack/dx/ssa/Optimizer.java +++ b/dx/src/com/android/jack/dx/ssa/Optimizer.java @@ -34,7 +34,7 @@ public class Optimizer { /** optional optimizer steps */ public enum OptionalStep { - MOVE_PARAM_COMBINER, SCCP, LITERAL_UPGRADE, CONST_COLLECTOR, ESCAPE_ANALYSIS + SCCP, LITERAL_UPGRADE, CONST_COLLECTOR, ESCAPE_ANALYSIS } /** @@ -152,10 +152,6 @@ public class Optimizer { private static void runSsaFormSteps(SsaMethod ssaMeth, EnumSet<OptionalStep> steps) { boolean needsDeadCodeRemover = true; - if (steps.contains(OptionalStep.MOVE_PARAM_COMBINER)) { - MoveParamCombiner.process(ssaMeth); - } - if (steps.contains(OptionalStep.SCCP)) { SCCP.process(ssaMeth); DeadCodeRemover.process(ssaMeth); |