| buzbee | 7520ee7 | 2010-09-17 16:01:49 -0700 | [diff] [blame] | 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 codegen and support common to all supported |
| 19 | * X86 variants. It is included by: |
| 20 | * |
| 21 | * Codegen-$(TARGET_ARCH_VARIANT).c |
| 22 | * |
| 23 | * which combines this common code with specific support found in the |
| 24 | * applicable directory below this one. |
| 25 | */ |
| 26 | |
| Dan Bornstein | 675b642 | 2010-11-19 16:01:25 -0800 | [diff] [blame] | 27 | static int opcodeCoverage[kNumDalvikInstructions]; |
| buzbee | 7520ee7 | 2010-09-17 16:01:49 -0700 | [diff] [blame] | 28 | static intptr_t templateEntryOffsets[TEMPLATE_LAST_MARK]; |
| 29 | |
| 30 | /* |
| 31 | * The following are the first-level codegen routines that analyze the format |
| 32 | * of each bytecode then either dispatch special purpose codegen routines |
| 33 | * or produce corresponding Thumb instructions directly. |
| 34 | */ |
| 35 | |
| 36 | #if 0 |
| 37 | static bool handleFmt10t_Fmt20t_Fmt30t(CompilationUnit *cUnit, MIR *mir, |
| 38 | BasicBlock *bb, X86LIR *labelList) |
| 39 | { |
| 40 | /* For OP_GOTO, OP_GOTO_16, and OP_GOTO_32 */ |
| 41 | return true; |
| 42 | } |
| 43 | |
| 44 | static bool handleFmt10x(CompilationUnit *cUnit, MIR *mir) |
| 45 | { |
| 46 | return true; |
| 47 | } |
| 48 | |
| 49 | static bool handleFmt11n_Fmt31i(CompilationUnit *cUnit, MIR *mir) |
| 50 | { |
| 51 | return true; |
| 52 | } |
| 53 | |
| 54 | static bool handleFmt21h(CompilationUnit *cUnit, MIR *mir) |
| 55 | { |
| 56 | return true; |
| 57 | } |
| 58 | |
| 59 | static bool handleFmt20bc(CompilationUnit *cUnit, MIR *mir) |
| 60 | { |
| 61 | return true; |
| 62 | } |
| 63 | |
| 64 | static bool handleFmt21c_Fmt31c(CompilationUnit *cUnit, MIR *mir) |
| 65 | { |
| 66 | return true; |
| 67 | } |
| 68 | |
| 69 | static bool handleFmt11x(CompilationUnit *cUnit, MIR *mir) |
| 70 | { |
| 71 | return true; |
| 72 | } |
| 73 | |
| 74 | static bool handleFmt12x(CompilationUnit *cUnit, MIR *mir) |
| 75 | { |
| 76 | return true; |
| 77 | } |
| 78 | |
| 79 | static bool handleFmt21s(CompilationUnit *cUnit, MIR *mir) |
| 80 | { |
| 81 | return true; |
| 82 | } |
| 83 | |
| 84 | static bool handleFmt21t(CompilationUnit *cUnit, MIR *mir, BasicBlock *bb, |
| 85 | X86LIR *labelList) |
| 86 | { |
| 87 | return true; |
| 88 | } |
| 89 | |
| 90 | static bool handleFmt22b_Fmt22s(CompilationUnit *cUnit, MIR *mir) |
| 91 | { |
| 92 | return true; |
| 93 | } |
| 94 | |
| 95 | static bool handleFmt22c(CompilationUnit *cUnit, MIR *mir) |
| 96 | { |
| 97 | return true; |
| 98 | } |
| 99 | |
| 100 | static bool handleFmt22cs(CompilationUnit *cUnit, MIR *mir) |
| 101 | { |
| 102 | return true; |
| 103 | } |
| 104 | |
| 105 | static bool handleFmt22t(CompilationUnit *cUnit, MIR *mir, BasicBlock *bb, |
| 106 | X86LIR *labelList) |
| 107 | { |
| 108 | return true; |
| 109 | } |
| 110 | |
| 111 | static bool handleFmt22x_Fmt32x(CompilationUnit *cUnit, MIR *mir) |
| 112 | { |
| 113 | return true; |
| 114 | } |
| 115 | |
| 116 | static bool handleFmt23x(CompilationUnit *cUnit, MIR *mir) |
| 117 | { |
| 118 | return true; |
| 119 | } |
| 120 | |
| 121 | static bool handleFmt31t(CompilationUnit *cUnit, MIR *mir) |
| 122 | { |
| 123 | return true; |
| 124 | } |
| 125 | |
| 126 | static bool handleFmt35c_3rc(CompilationUnit *cUnit, MIR *mir, BasicBlock *bb, |
| 127 | X86LIR *labelList) |
| 128 | { |
| 129 | return true; |
| 130 | } |
| 131 | |
| 132 | static bool handleFmt35ms_3rms(CompilationUnit *cUnit, MIR *mir, |
| 133 | BasicBlock *bb, X86LIR *labelList) |
| 134 | { |
| 135 | return true; |
| 136 | } |
| 137 | |
| 138 | /* |
| 139 | * NOTE: Handles both range and non-range versions (arguments |
| 140 | * have already been normalized by this point). |
| 141 | */ |
| 142 | static bool handleExecuteInline(CompilationUnit *cUnit, MIR *mir) |
| 143 | { |
| 144 | return true; |
| 145 | } |
| 146 | |
| 147 | static bool handleFmt51l(CompilationUnit *cUnit, MIR *mir) |
| 148 | { |
| 149 | return true; |
| 150 | } |
| 151 | #endif |
| 152 | |
| 153 | |
| 154 | void dvmCompilerMIR2LIR(CompilationUnit *cUnit) |
| 155 | { |
| 156 | } |
| 157 | |
| 158 | /* Accept the work and start compiling */ |
| 159 | bool dvmCompilerDoWork(CompilerWorkOrder *work) |
| 160 | { |
| 161 | bool res; |
| 162 | |
| 163 | if (gDvmJit.codeCacheFull) { |
| 164 | return false; |
| 165 | } |
| 166 | |
| 167 | switch (work->kind) { |
| 168 | case kWorkOrderTrace: |
| 169 | /* Start compilation with maximally allowed trace length */ |
| 170 | res = dvmCompileTrace(work->info, JIT_MAX_TRACE_LEN, &work->result, |
| 171 | work->bailPtr, 0 /* no hints */); |
| 172 | break; |
| 173 | case kWorkOrderTraceDebug: { |
| 174 | bool oldPrintMe = gDvmJit.printMe; |
| 175 | gDvmJit.printMe = true; |
| 176 | /* Start compilation with maximally allowed trace length */ |
| 177 | res = dvmCompileTrace(work->info, JIT_MAX_TRACE_LEN, &work->result, |
| 178 | work->bailPtr, 0 /* no hints */); |
| 179 | gDvmJit.printMe = oldPrintMe; |
| 180 | break; |
| 181 | } |
| 182 | default: |
| 183 | res = false; |
| 184 | LOGE("Jit: unknown work order type"); |
| 185 | assert(0); // Bail if debug build, discard otherwise |
| 186 | } |
| 187 | return res; |
| 188 | } |
| 189 | |
| 190 | /* Architectural-specific debugging helpers go here */ |
| 191 | void dvmCompilerArchDump(void) |
| 192 | { |
| 193 | /* Print compiled opcode in this VM instance */ |
| 194 | int i, start, streak; |
| 195 | char buf[1024]; |
| 196 | |
| 197 | streak = i = 0; |
| 198 | buf[0] = 0; |
| Dan Bornstein | 675b642 | 2010-11-19 16:01:25 -0800 | [diff] [blame] | 199 | while (opcodeCoverage[i] == 0 && i < kNumDalvikInstructions) { |
| buzbee | 7520ee7 | 2010-09-17 16:01:49 -0700 | [diff] [blame] | 200 | i++; |
| 201 | } |
| Dan Bornstein | 675b642 | 2010-11-19 16:01:25 -0800 | [diff] [blame] | 202 | if (i == kNumDalvikInstructions) { |
| buzbee | 7520ee7 | 2010-09-17 16:01:49 -0700 | [diff] [blame] | 203 | return; |
| 204 | } |
| Dan Bornstein | 675b642 | 2010-11-19 16:01:25 -0800 | [diff] [blame] | 205 | for (start = i++, streak = 1; i < kNumDalvikInstructions; i++) { |
| buzbee | 7520ee7 | 2010-09-17 16:01:49 -0700 | [diff] [blame] | 206 | if (opcodeCoverage[i]) { |
| 207 | streak++; |
| 208 | } else { |
| 209 | if (streak == 1) { |
| 210 | sprintf(buf+strlen(buf), "%x,", start); |
| 211 | } else { |
| 212 | sprintf(buf+strlen(buf), "%x-%x,", start, start + streak - 1); |
| 213 | } |
| 214 | streak = 0; |
| Dan Bornstein | 675b642 | 2010-11-19 16:01:25 -0800 | [diff] [blame] | 215 | while (opcodeCoverage[i] == 0 && i < kNumDalvikInstructions) { |
| buzbee | 7520ee7 | 2010-09-17 16:01:49 -0700 | [diff] [blame] | 216 | i++; |
| 217 | } |
| Dan Bornstein | 675b642 | 2010-11-19 16:01:25 -0800 | [diff] [blame] | 218 | if (i < kNumDalvikInstructions) { |
| buzbee | 7520ee7 | 2010-09-17 16:01:49 -0700 | [diff] [blame] | 219 | streak = 1; |
| 220 | start = i; |
| 221 | } |
| 222 | } |
| 223 | } |
| 224 | if (streak) { |
| 225 | if (streak == 1) { |
| 226 | sprintf(buf+strlen(buf), "%x", start); |
| 227 | } else { |
| 228 | sprintf(buf+strlen(buf), "%x-%x", start, start + streak - 1); |
| 229 | } |
| 230 | } |
| 231 | if (strlen(buf)) { |
| 232 | LOGD("dalvik.vm.jit.op = %s", buf); |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | /* Common initialization routine for an architecture family */ |
| 237 | bool dvmCompilerArchInit() |
| 238 | { |
| 239 | return dvmCompilerArchVariantInit(); |
| 240 | } |
| 241 | |
| 242 | void *dvmCompilerGetInterpretTemplate() |
| 243 | { |
| 244 | return (void*) ((int)gDvmJit.codeCache + |
| 245 | templateEntryOffsets[TEMPLATE_INTERPRET]); |
| 246 | } |
| 247 | |
| 248 | void dvmCompilerInitializeRegAlloc(CompilationUnit *cUnit) |
| 249 | { |
| 250 | } |