Home | History | Annotate | Download | only in arm
      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 /*
     18  * This file contains register alloction support and is intended to be
     19  * included by:
     20  *
     21  *        Codegen-$(TARGET_ARCH_VARIANT).c
     22  *
     23  */
     24 
     25 #include "compiler/CompilerUtility.h"
     26 #include "compiler/CompilerIR.h"
     27 #include "compiler/Dataflow.h"
     28 #include "compiler/codegen/arm/ArmLIR.h"
     29 
     30 static inline int dvmCompilerS2VReg(CompilationUnit *cUnit, int sReg)
     31 {
     32     assert(sReg != INVALID_SREG);
     33     return DECODE_REG(dvmConvertSSARegToDalvik(cUnit, sReg));
     34 }
     35 
     36 /* Reset the tracker to unknown state */
     37 static inline void dvmCompilerResetNullCheck(CompilationUnit *cUnit)
     38 {
     39     dvmClearAllBits(cUnit->regPool->nullCheckedRegs);
     40 }
     41 
     42 /*
     43  * Get the "real" sreg number associated with an sReg slot.  In general,
     44  * sReg values passed through codegen are the SSA names created by
     45  * dataflow analysis and refer to slot numbers in the cUnit->regLocation
     46  * array.  However, renaming is accomplished by simply replacing RegLocation
     47  * entries in the cUnit->reglocation[] array.  Therefore, when location
     48  * records for operands are first created, we need to ask the locRecord
     49  * identified by the dataflow pass what it's new name is.
     50  */
     51 
     52 static inline int dvmCompilerSRegHi(int lowSreg) {
     53     return (lowSreg == INVALID_SREG) ? INVALID_SREG : lowSreg + 1;
     54 }
     55 
     56 
     57 static inline bool dvmCompilerLiveOut(CompilationUnit *cUnit, int sReg)
     58 {
     59     //TODO: fully implement
     60     return true;
     61 }
     62 
     63 static inline int dvmCompilerSSASrc(MIR *mir, int num)
     64 {
     65     assert(mir->ssaRep->numUses > num);
     66     return mir->ssaRep->uses[num];
     67 }
     68 
     69 extern RegLocation dvmCompilerEvalLoc(CompilationUnit *cUnit, RegLocation loc,
     70                                       int regClass, bool update);
     71 /* Mark a temp register as dead.  Does not affect allocation state. */
     72 extern void dvmCompilerClobber(CompilationUnit *cUnit, int reg);
     73 
     74 extern RegLocation dvmCompilerUpdateLoc(CompilationUnit *cUnit,
     75                                         RegLocation loc);
     76 
     77 /* see comments for updateLoc */
     78 extern RegLocation dvmCompilerUpdateLocWide(CompilationUnit *cUnit,
     79                                             RegLocation loc);
     80 
     81 /* Clobber all of the temps that might be used by a handler. */
     82 extern void dvmCompilerClobberHandlerRegs(CompilationUnit *cUnit);
     83 
     84 extern void dvmCompilerMarkLive(CompilationUnit *cUnit, int reg, int sReg);
     85 
     86 extern void dvmCompilerMarkDirty(CompilationUnit *cUnit, int reg);
     87 
     88 extern void dvmCompilerMarkPair(CompilationUnit *cUnit, int lowReg,
     89                                 int highReg);
     90 
     91 extern void dvmCompilerMarkClean(CompilationUnit *cUnit, int reg);
     92 
     93 extern void dvmCompilerResetDef(CompilationUnit *cUnit, int reg);
     94 
     95 extern void dvmCompilerResetDefLoc(CompilationUnit *cUnit, RegLocation rl);
     96 
     97 /* Set up temp & preserved register pools specialized by target */
     98 extern void dvmCompilerInitPool(RegisterInfo *regs, int *regNums, int num);
     99 
    100 /*
    101  * Mark the beginning and end LIR of a def sequence.  Note that
    102  * on entry start points to the LIR prior to the beginning of the
    103  * sequence.
    104  */
    105 extern void dvmCompilerMarkDef(CompilationUnit *cUnit, RegLocation rl,
    106                                LIR *start, LIR *finish);
    107 /*
    108  * Mark the beginning and end LIR of a def sequence.  Note that
    109  * on entry start points to the LIR prior to the beginning of the
    110  * sequence.
    111  */
    112 extern void dvmCompilerMarkDefWide(CompilationUnit *cUnit, RegLocation rl,
    113                                    LIR *start, LIR *finish);
    114 
    115 extern RegLocation dvmCompilerGetSrcWide(CompilationUnit *cUnit, MIR *mir,
    116                                          int low, int high);
    117 
    118 extern RegLocation dvmCompilerGetDestWide(CompilationUnit *cUnit, MIR *mir,
    119                                           int low, int high);
    120 // Get the LocRecord associated with an SSA name use.
    121 extern RegLocation dvmCompilerGetSrc(CompilationUnit *cUnit, MIR *mir, int num);
    122 
    123 // Get the LocRecord associated with an SSA name def.
    124 extern RegLocation dvmCompilerGetDest(CompilationUnit *cUnit, MIR *mir,
    125                                       int num);
    126 
    127 extern RegLocation dvmCompilerGetReturnWide(CompilationUnit *cUnit);
    128 
    129 /* Clobber all regs that might be used by an external C call */
    130 extern void dvmCompilerClobberCallRegs(CompilationUnit *cUnit);
    131 
    132 extern RegisterInfo *dvmCompilerIsTemp(CompilationUnit *cUnit, int reg);
    133 
    134 extern void dvmCompilerMarkInUse(CompilationUnit *cUnit, int reg);
    135 
    136 extern int dvmCompilerAllocTemp(CompilationUnit *cUnit);
    137 
    138 extern int dvmCompilerAllocTempFloat(CompilationUnit *cUnit);
    139 
    140 //REDO: too many assumptions.
    141 extern int dvmCompilerAllocTempDouble(CompilationUnit *cUnit);
    142 
    143 extern void dvmCompilerFreeTemp(CompilationUnit *cUnit, int reg);
    144 
    145 extern void dvmCompilerResetDefLocWide(CompilationUnit *cUnit, RegLocation rl);
    146 
    147 extern void dvmCompilerResetDefTracking(CompilationUnit *cUnit);
    148 
    149 /* Kill the corresponding bit in the null-checked register list */
    150 extern void dvmCompilerKillNullCheckedLoc(CompilationUnit *cUnit,
    151                                           RegLocation loc);
    152 
    153 //FIXME - this needs to also check the preserved pool.
    154 extern RegisterInfo *dvmCompilerIsLive(CompilationUnit *cUnit, int reg);
    155 
    156 /* To be used when explicitly managing register use */
    157 extern void dvmCompilerLockAllTemps(CompilationUnit *cUnit);
    158 
    159 extern void dvmCompilerFlushAllRegs(CompilationUnit *cUnit);
    160 
    161 extern RegLocation dvmCompilerGetReturnWideAlt(CompilationUnit *cUnit);
    162 
    163 extern RegLocation dvmCompilerGetReturn(CompilationUnit *cUnit);
    164 
    165 extern RegLocation dvmCompilerGetReturnAlt(CompilationUnit *cUnit);
    166 
    167 /* Clobber any temp associated with an sReg.  Could be in either class */
    168 extern void dvmCompilerClobberSReg(CompilationUnit *cUnit, int sReg);
    169 
    170 /* Return a temp if one is available, -1 otherwise */
    171 extern int dvmCompilerAllocFreeTemp(CompilationUnit *cUnit);
    172 
    173 /*
    174  * Similar to dvmCompilerAllocTemp(), but forces the allocation of a specific
    175  * register.  No check is made to see if the register was previously
    176  * allocated.  Use with caution.
    177  */
    178 extern void dvmCompilerLockTemp(CompilationUnit *cUnit, int reg);
    179 
    180 extern RegLocation dvmCompilerWideToNarrow(CompilationUnit *cUnit,
    181                                            RegLocation rl);
    182 
    183 /*
    184  * Free all allocated temps in the temp pools.  Note that this does
    185  * not affect the "liveness" of a temp register, which will stay
    186  * live until it is either explicitly killed or reallocated.
    187  */
    188 extern void dvmCompilerResetRegPool(CompilationUnit *cUnit);
    189 
    190 extern void dvmCompilerClobberAllRegs(CompilationUnit *cUnit);
    191 
    192 extern void dvmCompilerResetDefTracking(CompilationUnit *cUnit);
    193