blob: e2752b17c713e7ab42e8e951efb1e0102d7b4db8 [file] [log] [blame]
Bill Buzbee1465db52009-09-23 17:17:35 -07001/*
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 Buzbee1465db52009-09-23 17:17:35 -070021/*
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 */
27static void inferTypes(CompilationUnit *cUnit, BasicBlock *bb)
28{
29 MIR *mir;
Ben Cheng32115a92011-03-22 14:09:09 -070030 if (bb->blockType != kDalvikByteCode && bb->blockType != kEntryBlock)
Bill Buzbee1465db52009-09-23 17:17:35 -070031 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 Buzbee1465db52009-09-23 17:17:35 -070049static const RegLocation freshLoc = {kLocDalvikFrame, 0, 0, INVALID_REG,
50 INVALID_REG, INVALID_SREG};
buzbee23d95d02010-12-14 13:16:43 -080051
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 */
57void dvmCompilerLocalRegAlloc(CompilationUnit *cUnit)
Bill Buzbee1465db52009-09-23 17:17:35 -070058{
59 int i;
Bill Buzbee1465db52009-09-23 17:17:35 -070060 RegLocation *loc;
Bill Buzbee1465db52009-09-23 17:17:35 -070061
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 Cheng00603072010-10-28 11:13:58 -070070 GrowableListIterator iterator;
71
72 dvmGrowableListIteratorInit(&cUnit->blockList, &iterator);
Bill Buzbee1465db52009-09-23 17:17:35 -070073 /* Do type inference pass */
Ben Cheng00603072010-10-28 11:13:58 -070074 while (true) {
75 BasicBlock *bb = (BasicBlock *) dvmGrowableListIteratorNext(&iterator);
76 if (bb == NULL) break;
77 inferTypes(cUnit, bb);
Bill Buzbee1465db52009-09-23 17:17:35 -070078 }
79
buzbee23d95d02010-12-14 13:16:43 -080080 /* Remap SSA names back to original frame locations. */
81 for (i=0; i < cUnit->numSSARegs; i++) {
82 cUnit->regLocation[i].sRegLow =
Bill Buzbee1465db52009-09-23 17:17:35 -070083 DECODE_REG(dvmConvertSSARegToDalvik(cUnit, loc[i].sRegLow));
Bill Buzbee1465db52009-09-23 17:17:35 -070084 }
85}