Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 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 "CompilerInternals.h" |
| 19 | #include "Dataflow.h" |
| 20 | |
Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 21 | /* |
| 22 | * Quick & dirty - make FP usage sticky. This is strictly a hint - local |
| 23 | * code generation will handle misses. It might be worthwhile to collaborate |
| 24 | * with dx/dexopt to avoid reusing the same Dalvik temp for values of |
| 25 | * different types. |
| 26 | */ |
| 27 | static void inferTypes(CompilationUnit *cUnit, BasicBlock *bb) |
| 28 | { |
| 29 | MIR *mir; |
Ben Cheng | 32115a9 | 2011-03-22 14:09:09 -0700 | [diff] [blame] | 30 | if (bb->blockType != kDalvikByteCode && bb->blockType != kEntryBlock) |
Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 31 | return; |
| 32 | |
| 33 | for (mir = bb->firstMIRInsn; mir; mir = mir->next) { |
| 34 | SSARepresentation *ssaRep = mir->ssaRep; |
| 35 | if (ssaRep) { |
| 36 | int i; |
| 37 | for (i=0; ssaRep->fpUse && i< ssaRep->numUses; i++) { |
| 38 | if (ssaRep->fpUse[i]) |
| 39 | cUnit->regLocation[ssaRep->uses[i]].fp = true; |
| 40 | } |
| 41 | for (i=0; ssaRep->fpDef && i< ssaRep->numDefs; i++) { |
| 42 | if (ssaRep->fpDef[i]) |
| 43 | cUnit->regLocation[ssaRep->defs[i]].fp = true; |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | |
Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 49 | static const RegLocation freshLoc = {kLocDalvikFrame, 0, 0, INVALID_REG, |
| 50 | INVALID_REG, INVALID_SREG}; |
buzbee | 23d95d0 | 2010-12-14 13:16:43 -0800 | [diff] [blame] | 51 | |
| 52 | /* |
| 53 | * Local register allocation for simple traces. Most of the work for |
| 54 | * local allocation is done on the fly. Here we do some initialization |
| 55 | * and type inference. |
| 56 | */ |
| 57 | void dvmCompilerLocalRegAlloc(CompilationUnit *cUnit) |
Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 58 | { |
| 59 | int i; |
Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 60 | RegLocation *loc; |
Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 61 | |
| 62 | /* Allocate the location map */ |
| 63 | loc = (RegLocation*)dvmCompilerNew(cUnit->numSSARegs * sizeof(*loc), true); |
| 64 | for (i=0; i< cUnit->numSSARegs; i++) { |
| 65 | loc[i] = freshLoc; |
| 66 | loc[i].sRegLow = i; |
| 67 | } |
| 68 | cUnit->regLocation = loc; |
| 69 | |
Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 70 | GrowableListIterator iterator; |
| 71 | |
| 72 | dvmGrowableListIteratorInit(&cUnit->blockList, &iterator); |
Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 73 | /* Do type inference pass */ |
Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 74 | while (true) { |
| 75 | BasicBlock *bb = (BasicBlock *) dvmGrowableListIteratorNext(&iterator); |
| 76 | if (bb == NULL) break; |
| 77 | inferTypes(cUnit, bb); |
Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 78 | } |
| 79 | |
buzbee | 23d95d0 | 2010-12-14 13:16:43 -0800 | [diff] [blame] | 80 | /* Remap SSA names back to original frame locations. */ |
| 81 | for (i=0; i < cUnit->numSSARegs; i++) { |
| 82 | cUnit->regLocation[i].sRegLow = |
Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 83 | DECODE_REG(dvmConvertSSARegToDalvik(cUnit, loc[i].sRegLow)); |
Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 84 | } |
| 85 | } |