blob: d772a31480005a1be10b5b5ce76b05407d6c4a98 [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;
30 if (bb->blockType != kDalvikByteCode &&
Ben Cheng7a2697d2010-06-07 13:44:23 -070031 bb->blockType != kTraceEntryBlock)
Bill Buzbee1465db52009-09-23 17:17:35 -070032 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 Buzbee1465db52009-09-23 17:17:35 -070050static const RegLocation freshLoc = {kLocDalvikFrame, 0, 0, INVALID_REG,
51 INVALID_REG, INVALID_SREG};
buzbee23d95d02010-12-14 13:16:43 -080052
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 */
58void dvmCompilerLocalRegAlloc(CompilationUnit *cUnit)
Bill Buzbee1465db52009-09-23 17:17:35 -070059{
60 int i;
Bill Buzbee1465db52009-09-23 17:17:35 -070061 RegLocation *loc;
Bill Buzbee1465db52009-09-23 17:17:35 -070062
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 Cheng00603072010-10-28 11:13:58 -070071 GrowableListIterator iterator;
72
73 dvmGrowableListIteratorInit(&cUnit->blockList, &iterator);
Bill Buzbee1465db52009-09-23 17:17:35 -070074 /* Do type inference pass */
Ben Cheng00603072010-10-28 11:13:58 -070075 while (true) {
76 BasicBlock *bb = (BasicBlock *) dvmGrowableListIteratorNext(&iterator);
77 if (bb == NULL) break;
78 inferTypes(cUnit, bb);
Bill Buzbee1465db52009-09-23 17:17:35 -070079 }
80
buzbee23d95d02010-12-14 13:16:43 -080081 /* Remap SSA names back to original frame locations. */
82 for (i=0; i < cUnit->numSSARegs; i++) {
83 cUnit->regLocation[i].sRegLow =
Bill Buzbee1465db52009-09-23 17:17:35 -070084 DECODE_REG(dvmConvertSSARegToDalvik(cUnit, loc[i].sRegLow));
Bill Buzbee1465db52009-09-23 17:17:35 -070085 }
86}