| 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; |
| 30 | if (bb->blockType != kDalvikByteCode && |
| Ben Cheng | 7a2697d | 2010-06-07 13:44:23 -0700 | [diff] [blame] | 31 | bb->blockType != kTraceEntryBlock) |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 32 | return; |
| 33 | |
| 34 | for (mir = bb->firstMIRInsn; mir; mir = mir->next) { |
| 35 | SSARepresentation *ssaRep = mir->ssaRep; |
| 36 | if (ssaRep) { |
| 37 | int i; |
| 38 | for (i=0; ssaRep->fpUse && i< ssaRep->numUses; i++) { |
| 39 | if (ssaRep->fpUse[i]) |
| 40 | cUnit->regLocation[ssaRep->uses[i]].fp = true; |
| 41 | } |
| 42 | for (i=0; ssaRep->fpDef && i< ssaRep->numDefs; i++) { |
| 43 | if (ssaRep->fpDef[i]) |
| 44 | cUnit->regLocation[ssaRep->defs[i]].fp = true; |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 50 | static const RegLocation freshLoc = {kLocDalvikFrame, 0, 0, INVALID_REG, |
| 51 | INVALID_REG, INVALID_SREG}; |
| buzbee | 23d95d0 | 2010-12-14 13:16:43 -0800 | [diff] [blame] | 52 | |
| 53 | /* |
| 54 | * Local register allocation for simple traces. Most of the work for |
| 55 | * local allocation is done on the fly. Here we do some initialization |
| 56 | * and type inference. |
| 57 | */ |
| 58 | void dvmCompilerLocalRegAlloc(CompilationUnit *cUnit) |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 59 | { |
| 60 | int i; |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 61 | RegLocation *loc; |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 62 | |
| 63 | /* Allocate the location map */ |
| 64 | loc = (RegLocation*)dvmCompilerNew(cUnit->numSSARegs * sizeof(*loc), true); |
| 65 | for (i=0; i< cUnit->numSSARegs; i++) { |
| 66 | loc[i] = freshLoc; |
| 67 | loc[i].sRegLow = i; |
| 68 | } |
| 69 | cUnit->regLocation = loc; |
| 70 | |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 71 | GrowableListIterator iterator; |
| 72 | |
| 73 | dvmGrowableListIteratorInit(&cUnit->blockList, &iterator); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 74 | /* Do type inference pass */ |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 75 | while (true) { |
| 76 | BasicBlock *bb = (BasicBlock *) dvmGrowableListIteratorNext(&iterator); |
| 77 | if (bb == NULL) break; |
| 78 | inferTypes(cUnit, bb); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| buzbee | 23d95d0 | 2010-12-14 13:16:43 -0800 | [diff] [blame] | 81 | /* Remap SSA names back to original frame locations. */ |
| 82 | for (i=0; i < cUnit->numSSARegs; i++) { |
| 83 | cUnit->regLocation[i].sRegLow = |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 84 | DECODE_REG(dvmConvertSSARegToDalvik(cUnit, loc[i].sRegLow)); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 85 | } |
| 86 | } |