1 /* 2 * Copyright (C) 2010 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 Arm-specific register alloction support. 19 */ 20 21 #include "compiler/CompilerUtility.h" 22 #include "compiler/CompilerIR.h" 23 #include "compiler/Dataflow.h" 24 #include "ArmLIR.h" 25 #include "Codegen.h" 26 #include "compiler/codegen/Ralloc.h" 27 28 /* 29 * Register usage for 16-bit Thumb systems: 30 * r0-r3: Temp/argument 31 * lr(r14): Temp for translations, return address for handlers 32 * rSELF(r6): Pointer to Thread 33 * rFP(r5): Dalvik frame pointer 34 * r4, r7: Temp for translations 35 * r8, r9, r10: Temp preserved across C calls 36 * r11, ip(r12): Temp not preserved across C calls 37 * 38 * Register usage for 32-bit Thumb systems: 39 * r0-r3: Temp/argument 40 * lr(r14): Temp for translations, return address for handlers 41 * rSELF(r6): Pointer to Thread 42 * rFP(r5): Dalvik frame pointer 43 * r4, r7: Temp for translations 44 * r8, r9, r10 Temp preserved across C calls 45 * r11, ip(r12): Temp not preserved across C calls 46 * fp0-fp15: Hot temps, not preserved across C calls 47 * fp16-fp31: Promotion pool 48 * 49 */ 50 51 /* Clobber all regs that might be used by an external C call */ 52 extern void dvmCompilerClobberCallRegs(CompilationUnit *cUnit) 53 { 54 dvmCompilerClobber(cUnit, r0); 55 dvmCompilerClobber(cUnit, r1); 56 dvmCompilerClobber(cUnit, r2); 57 dvmCompilerClobber(cUnit, r3); 58 dvmCompilerClobber(cUnit, r9); // Need to do this?, be conservative 59 dvmCompilerClobber(cUnit, r11); 60 dvmCompilerClobber(cUnit, r12); 61 dvmCompilerClobber(cUnit, r14lr); 62 } 63 64 /* Clobber all of the temps that might be used by a handler. */ 65 extern void dvmCompilerClobberHandlerRegs(CompilationUnit *cUnit) 66 { 67 //TUNING: reduce the set of regs used by handlers. Only a few need lots. 68 dvmCompilerClobberCallRegs(cUnit); 69 dvmCompilerClobber(cUnit, r4PC); 70 dvmCompilerClobber(cUnit, r7); 71 dvmCompilerClobber(cUnit, r8); 72 dvmCompilerClobber(cUnit, r9); 73 dvmCompilerClobber(cUnit, r10); 74 } 75 76 extern RegLocation dvmCompilerGetReturnWide(CompilationUnit *cUnit) 77 { 78 RegLocation res = LOC_C_RETURN_WIDE; 79 dvmCompilerClobber(cUnit, r0); 80 dvmCompilerClobber(cUnit, r1); 81 dvmCompilerMarkInUse(cUnit, r0); 82 dvmCompilerMarkInUse(cUnit, r1); 83 dvmCompilerMarkPair(cUnit, res.lowReg, res.highReg); 84 return res; 85 } 86 87 extern RegLocation dvmCompilerGetReturnWideAlt(CompilationUnit *cUnit) 88 { 89 RegLocation res = LOC_C_RETURN_WIDE; 90 res.lowReg = r2; 91 res.highReg = r3; 92 dvmCompilerClobber(cUnit, r2); 93 dvmCompilerClobber(cUnit, r3); 94 dvmCompilerMarkInUse(cUnit, r2); 95 dvmCompilerMarkInUse(cUnit, r3); 96 dvmCompilerMarkPair(cUnit, res.lowReg, res.highReg); 97 return res; 98 } 99 100 extern RegLocation dvmCompilerGetReturn(CompilationUnit *cUnit) 101 { 102 RegLocation res = LOC_C_RETURN; 103 dvmCompilerClobber(cUnit, r0); 104 dvmCompilerMarkInUse(cUnit, r0); 105 return res; 106 } 107 108 extern RegLocation dvmCompilerGetReturnAlt(CompilationUnit *cUnit) 109 { 110 RegLocation res = LOC_C_RETURN; 111 res.lowReg = r1; 112 dvmCompilerClobber(cUnit, r1); 113 dvmCompilerMarkInUse(cUnit, r1); 114 return res; 115 } 116