Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 "compiler_llvm.h" |
| 18 | |
Shih-wei Liao | 26e9307 | 2012-05-30 19:13:08 -0700 | [diff] [blame] | 19 | #include "backend_options.h" |
Shih-wei Liao | c4c9881 | 2012-03-10 21:55:51 -0800 | [diff] [blame] | 20 | #include "class_linker.h" |
Logan Chien | 8b977d3 | 2012-02-21 19:14:55 +0800 | [diff] [blame] | 21 | #include "compilation_unit.h" |
Logan Chien | f7015fd | 2012-03-18 01:19:37 +0800 | [diff] [blame] | 22 | #include "compiled_method.h" |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 23 | #include "compiler.h" |
| 24 | #include "ir_builder.h" |
Logan Chien | 88894ee | 2012-02-13 16:42:22 +0800 | [diff] [blame] | 25 | #include "jni_compiler.h" |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 26 | #ifndef ART_USE_DEXLANG_FRONTEND |
| 27 | # include "method_compiler.h" |
| 28 | #endif |
Logan Chien | 4dd96f5 | 2012-02-29 01:26:58 +0800 | [diff] [blame] | 29 | #include "oat_compilation_unit.h" |
Logan Chien | 0c717dd | 2012-03-28 18:31:07 +0800 | [diff] [blame] | 30 | #include "oat_file.h" |
Logan Chien | 7f76761 | 2012-03-01 18:54:49 +0800 | [diff] [blame] | 31 | #include "stl_util.h" |
TDYa127 | eead4ac | 2012-06-03 07:15:25 -0700 | [diff] [blame] | 32 | #include "stub_compiler.h" |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 33 | #include "utils_llvm.h" |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 34 | |
Logan Chien | dd7cf5b | 2012-03-01 12:55:19 +0800 | [diff] [blame] | 35 | #include <llvm/LinkAllPasses.h> |
| 36 | #include <llvm/LinkAllVMCore.h> |
Logan Chien | 013b6f2 | 2012-03-02 17:20:33 +0800 | [diff] [blame] | 37 | #include <llvm/Support/ManagedStatic.h> |
Logan Chien | 8b977d3 | 2012-02-21 19:14:55 +0800 | [diff] [blame] | 38 | #include <llvm/Support/TargetSelect.h> |
| 39 | #include <llvm/Support/Threading.h> |
| 40 | |
Shih-wei Liao | bb33f2f | 2012-08-23 13:20:00 -0700 | [diff] [blame] | 41 | #if defined(ART_USE_QUICK_COMPILER) |
| 42 | namespace art { |
| 43 | void oatCompileMethodToGBC(Compiler& compiler, |
| 44 | const DexFile::CodeItem* code_item, |
| 45 | uint32_t access_flags, InvokeType invoke_type, |
| 46 | uint32_t method_idx, jobject class_loader, |
| 47 | const DexFile& dex_file, |
| 48 | llvm::Module* module, |
| 49 | llvm::LLVMContext* context, |
| 50 | greenland::IntrinsicHelper* intrinsic_helper, |
| 51 | greenland::IRBuilder* irb); |
| 52 | } |
| 53 | #endif |
| 54 | |
Logan Chien | 013b6f2 | 2012-03-02 17:20:33 +0800 | [diff] [blame] | 55 | namespace llvm { |
| 56 | extern bool TimePassesIsEnabled; |
| 57 | } |
| 58 | |
Shih-wei Liao | fc34adb | 2012-03-07 08:51:44 -0800 | [diff] [blame] | 59 | namespace { |
Logan Chien | 8b977d3 | 2012-02-21 19:14:55 +0800 | [diff] [blame] | 60 | |
Shih-wei Liao | fc34adb | 2012-03-07 08:51:44 -0800 | [diff] [blame] | 61 | pthread_once_t llvm_initialized = PTHREAD_ONCE_INIT; |
| 62 | |
| 63 | void InitializeLLVM() { |
Logan Chien | c3f8fa5 | 2012-05-11 11:23:39 +0800 | [diff] [blame] | 64 | // Initialize LLVM internal data structure for multithreading |
| 65 | llvm::llvm_start_multithreaded(); |
| 66 | |
Logan Chien | 013b6f2 | 2012-03-02 17:20:33 +0800 | [diff] [blame] | 67 | // NOTE: Uncomment following line to show the time consumption of LLVM passes |
| 68 | //llvm::TimePassesIsEnabled = true; |
| 69 | |
Shih-wei Liao | 26e9307 | 2012-05-30 19:13:08 -0700 | [diff] [blame] | 70 | // Initialize LLVM target-specific options. |
| 71 | art::compiler_llvm::InitialBackendOptions(); |
Logan Chien | c3f8fa5 | 2012-05-11 11:23:39 +0800 | [diff] [blame] | 72 | |
Shih-wei Liao | 1335a95 | 2012-07-23 18:03:00 -0700 | [diff] [blame] | 73 | // Initialize LLVM target, MC subsystem, asm printer, and asm parser. |
| 74 | #if defined(ART_TARGET) |
| 75 | // Don't initialize all targets on device. Just initialize the device's native target |
| 76 | llvm::InitializeNativeTarget(); |
| 77 | llvm::InitializeNativeTargetAsmPrinter(); |
| 78 | llvm::InitializeNativeTargetAsmParser(); |
| 79 | #else |
Logan Chien | 8b977d3 | 2012-02-21 19:14:55 +0800 | [diff] [blame] | 80 | llvm::InitializeAllTargets(); |
| 81 | llvm::InitializeAllTargetMCs(); |
| 82 | llvm::InitializeAllAsmPrinters(); |
| 83 | llvm::InitializeAllAsmParsers(); |
Shih-wei Liao | 1335a95 | 2012-07-23 18:03:00 -0700 | [diff] [blame] | 84 | #endif |
Logan Chien | 8b977d3 | 2012-02-21 19:14:55 +0800 | [diff] [blame] | 85 | |
Logan Chien | dd7cf5b | 2012-03-01 12:55:19 +0800 | [diff] [blame] | 86 | // Initialize LLVM optimization passes |
| 87 | llvm::PassRegistry ®istry = *llvm::PassRegistry::getPassRegistry(); |
| 88 | |
| 89 | llvm::initializeCore(registry); |
| 90 | llvm::initializeScalarOpts(registry); |
| 91 | llvm::initializeIPO(registry); |
| 92 | llvm::initializeAnalysis(registry); |
| 93 | llvm::initializeIPA(registry); |
| 94 | llvm::initializeTransformUtils(registry); |
| 95 | llvm::initializeInstCombine(registry); |
| 96 | llvm::initializeInstrumentation(registry); |
| 97 | llvm::initializeTarget(registry); |
Logan Chien | 8b977d3 | 2012-02-21 19:14:55 +0800 | [diff] [blame] | 98 | } |
| 99 | |
Logan Chien | f130655 | 2012-03-16 11:17:53 +0800 | [diff] [blame] | 100 | // The Guard to Shutdown LLVM |
Logan Chien | aeb5303 | 2012-03-18 02:29:38 +0800 | [diff] [blame] | 101 | // llvm::llvm_shutdown_obj llvm_guard; |
| 102 | // TODO: We are commenting out this line because this will cause SEGV from |
| 103 | // time to time. |
| 104 | // Two reasons: (1) the order of the destruction of static objects, or |
| 105 | // (2) dlopen/dlclose side-effect on static objects. |
Shih-wei Liao | fc34adb | 2012-03-07 08:51:44 -0800 | [diff] [blame] | 106 | |
| 107 | } // anonymous namespace |
| 108 | |
| 109 | |
| 110 | namespace art { |
| 111 | namespace compiler_llvm { |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 112 | |
| 113 | |
Logan Chien | e75a8cc | 2012-02-24 12:26:43 +0800 | [diff] [blame] | 114 | llvm::Module* makeLLVMModuleContents(llvm::Module* module); |
Logan Chien | 42e0e15 | 2012-01-13 15:42:36 +0800 | [diff] [blame] | 115 | |
| 116 | |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 117 | CompilerLLVM::CompilerLLVM(Compiler* compiler, InstructionSet insn_set) |
Logan Chien | 971bf3f | 2012-05-01 15:47:55 +0800 | [diff] [blame] | 118 | : compiler_(compiler), insn_set_(insn_set), |
| 119 | num_cunits_lock_("compilation unit counter lock"), num_cunits_(0), |
| 120 | plt_(insn_set) { |
Shih-wei Liao | fc34adb | 2012-03-07 08:51:44 -0800 | [diff] [blame] | 121 | |
| 122 | // Initialize LLVM libraries |
| 123 | pthread_once(&llvm_initialized, InitializeLLVM); |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | |
| 127 | CompilerLLVM::~CompilerLLVM() { |
| 128 | } |
| 129 | |
| 130 | |
Logan Chien | 971bf3f | 2012-05-01 15:47:55 +0800 | [diff] [blame] | 131 | CompilationUnit* CompilerLLVM::AllocateCompilationUnit() { |
| 132 | MutexLock GUARD(num_cunits_lock_); |
TDYa127 | b672d1e | 2012-06-28 21:21:45 -0700 | [diff] [blame] | 133 | CompilationUnit* cunit = new CompilationUnit(this, num_cunits_++); |
| 134 | if (!bitcode_filename_.empty()) { |
| 135 | cunit->SetBitcodeFileName(StringPrintf("%s-%zu", bitcode_filename_.c_str(), num_cunits_-1)); |
| 136 | } |
| 137 | return cunit; |
Logan Chien | df57614 | 2012-03-20 17:36:32 +0800 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | |
Logan Chien | 7f76761 | 2012-03-01 18:54:49 +0800 | [diff] [blame] | 141 | CompiledMethod* CompilerLLVM:: |
Shih-wei Liao | bb33f2f | 2012-08-23 13:20:00 -0700 | [diff] [blame] | 142 | CompileDexMethod(OatCompilationUnit* oat_compilation_unit, InvokeType invoke_type) { |
Logan Chien | 971bf3f | 2012-05-01 15:47:55 +0800 | [diff] [blame] | 143 | UniquePtr<CompilationUnit> cunit(AllocateCompilationUnit()); |
Logan Chien | 8ba2fc5 | 2012-04-23 09:10:46 +0800 | [diff] [blame] | 144 | |
Shih-wei Liao | bb33f2f | 2012-08-23 13:20:00 -0700 | [diff] [blame] | 145 | #if defined(ART_USE_DEXLANG_FRONTEND) |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 146 | // Run DexLang for Dex to Greenland Bitcode |
| 147 | UniquePtr<greenland::DexLang> dex_lang( |
| 148 | new greenland::DexLang(*cunit->GetDexLangContext(), *compiler_, |
| 149 | *oat_compilation_unit)); |
| 150 | |
| 151 | llvm::Function* func = dex_lang->Build(); |
| 152 | CHECK(func != NULL); |
| 153 | |
| 154 | cunit->Materialize(); |
| 155 | |
| 156 | return new CompiledMethod(cunit->GetInstructionSet(), |
| 157 | cunit->GetCompiledCode()); |
Shih-wei Liao | bb33f2f | 2012-08-23 13:20:00 -0700 | [diff] [blame] | 158 | #elif defined(ART_USE_QUICK_COMPILER) |
| 159 | std::string methodName(PrettyMethod(oat_compilation_unit->GetDexMethodIndex(), |
| 160 | *oat_compilation_unit->GetDexFile())); |
Shih-wei Liao | 8593d88 | 2012-08-09 19:08:34 -0700 | [diff] [blame^] | 161 | if ((methodName.find("gdata2.AndroidGDataClient.createAndExecuteMethod") != std::string::npos) |
| 162 | || (methodName.find("hG.a") != std::string::npos) |
| 163 | || (methodName.find("hT.a(hV, java.lang.String, java.lang.String, java") != std::string::npos) |
| 164 | || (methodName.find("AndroidHttpTransport.exchange") != std::string::npos) |
| 165 | || (methodName.find("javax.crypto.Cipher.getCipher") != std::string::npos) |
| 166 | || (methodName.find("libcore.io.IoBridge.available") != std::string::npos) |
| 167 | || (methodName.find("gov.nist.javax.sip.message.SIPMessage.computeContentLength") != std::string::npos) |
| 168 | || (methodName.find("gov.nist.javax.sip.message.SIPMessage.encode") != std::string::npos) |
| 169 | || (methodName.find("android.appwidget.AppWidgetHostView.updateAppWidget") != std::string::npos) |
| 170 | || (methodName.find("android.content.SyncStorageEngine.readAccountInfoLocked") != std::string::npos) |
| 171 | || (methodName.find("android.view.AccessibilityInteractionController.findAccessibilityNodeInfosByTextUiThread") != std::string::npos) |
| 172 | || (methodName.find("android.webkit.BrowserFrame.downloadStart") != std::string::npos) |
| 173 | || (methodName.find("com.android.internal.os.ZygoteConnection.handleChildProc") != std::string::npos) |
| 174 | || (methodName.find("com.android.internal.widget.LockPatternUtils.passwordToHash") != std::string::npos) |
| 175 | || (methodName.find("com.android.internal.os.ZygoteConnection.runOnce") != std::string::npos) |
| 176 | || (methodName.find("com.google.android.gles_jni.GLImpl.allowIndirectBuffers") != std::string::npos) |
| 177 | || (methodName.find("com.google.android.mms.util.DrmConvertSession.convert") != std::string::npos) |
| 178 | || (methodName.find("com.android.server.BackupManagerService$PerformFullRestoreTask.readAppManifest") != std::string::npos) |
| 179 | || (methodName.find("com.android.server.BackupManagerService.bindToAgentSynchronous") != std::string::npos) |
| 180 | || (methodName.find("org.apache.xalan.templates.ElemElement.execute") != std::string::npos) |
| 181 | || (methodName.find("com.android.server.am.ActivityManagerService.getPackageForIntentSender") != std::string::npos) |
| 182 | || (methodName.find("com.android.server.am.ActivityManagerService.startNextMatchingActivity") != std::string::npos) |
| 183 | || (methodName.find("com.android.server.wm.WindowManagerService.viewServerWindowCommand") != std::string::npos) |
| 184 | || (methodName.find("org.apache.xml.serializer.OutputPropertiesFactory.getDefaultMethodProperties") != std::string::npos) |
| 185 | // APK |
| 186 | || (methodName.find("org.codehaus.jackson.map.ser.std.ObjectArraySerializer") != std::string::npos) |
| 187 | || (methodName.find("com.android.providers.downloads.DrmConvertSession.convert") != std::string::npos) |
| 188 | || (methodName.find("com.android.providers.downloads.DownloadThread.run") != std::string::npos) |
| 189 | || (methodName.find("com.android.calendar.AllInOneActivity.parseViewAction") != std::string::npos) |
| 190 | || (methodName.find("com.android.vcard.VCardEntryCommitter.pushIntoContentResolver") != std::string::npos) |
| 191 | || (methodName.find("com.google.android.apps.books.model.VolumeMetadata.earliestPossibleSegmentIndexForPosition") != std::string::npos) |
| 192 | || (methodName.find("com.google.android.auth.GoogleAuthSession.authenticate") != std::string::npos) |
| 193 | || (methodName.find("com.google.android.syncadapters.bookmarks.BookmarksSyncAdapter") != std::string::npos) |
| 194 | || (methodName.find("com.google.analytics.tracking.android.GoogleAnalytics.getTracker") != std::string::npos) |
| 195 | || (methodName.find("com.google.apps") != std::string::npos) |
| 196 | || (methodName.find("com.android.email.MessagingController.processPendingDeletesSynchronous") != std::string::npos) |
| 197 | || (methodName.find("com.google.android.gm.provider.MailEngine.getHttpClient") != std::string::npos) |
| 198 | || (methodName.find("com.google.android.gms.auth.login.GLSUser") != std::string::npos) |
| 199 | || (methodName.find("com.google.android.backup.BackupTransportService$1.nextRestorePackage") != std::string::npos) |
| 200 | || (methodName.find("com.google.earth.EarthActivity$1.run") != std::string::npos) |
| 201 | || (methodName.find("com.google.android.gsf") != std::string::npos) |
| 202 | || (methodName.find("com.google.googlenav.api.c.a") != std::string::npos) |
| 203 | || (methodName.find("com.google.android.music.sync.api.MusicApiClientImpl") != std::string::npos) |
| 204 | || (methodName.find("com.google.android.music.utils.MusicTagUtils.getGenreName") != std::string::npos) |
| 205 | || (methodName.find("com.google.android.finsky.billing.challenge.ClientLoginApi$2.onErrorResponse") != std::string::npos) |
| 206 | || (methodName.find("com.google.android.apps.plus") != std::string::npos) |
| 207 | || (methodName.find("com.android.settings.ApnEditor") != std::string::npos) |
| 208 | || (methodName.find("com.samsung.dmexthandler.PhoneDataService$1.getIPv6SettingsValue") != std::string::npos) |
| 209 | || (methodName.find("com.samsung.syncservice.SyncmlService.getClientPwd") != std::string::npos) |
| 210 | || (methodName.find("com.android.systemui.statusbar.BaseStatusBar.applyLegacyRowBackground") != std::string::npos) |
| 211 | || (methodName.find("com.tf") != std::string::npos) |
| 212 | || (methodName.find("com.google.android.searchcommon.util.JavaNetHttpHelper.extractCharset") != std::string::npos) |
| 213 | || (methodName.find("com.google.android.youtube.core.utils.Util.getAppVersionCode") != std::string::npos) |
| 214 | || (methodName.find("com.google.android.ytremote.backend.deviceauth.DeviceAuthenticator.encryptToken") != std::string::npos) |
| 215 | || (methodName.find("com.google.android.maps.KeyHelper.getSignatureFingerprint") != std::string::npos) |
| 216 | || (methodName.find("com.android.commands.content.Content$Command.execute") != std::string::npos) |
| 217 | || (methodName.find("com.android.uiautomator.core.InteractionController.getSystemLongPressTime") != std::string::npos) |
| 218 | ) { |
Shih-wei Liao | bb33f2f | 2012-08-23 13:20:00 -0700 | [diff] [blame] | 219 | // Use iceland |
| 220 | UniquePtr<MethodCompiler> method_compiler( |
| 221 | new MethodCompiler(cunit.get(), compiler_, oat_compilation_unit)); |
| 222 | |
| 223 | return method_compiler->Compile(); |
| 224 | } else { |
| 225 | // Use quick |
| 226 | llvm::LLVMContext* context = cunit->GetLLVMContext(); |
| 227 | llvm::Module* module = cunit->GetModule(); |
| 228 | greenland::IntrinsicHelper* intrinsic_helper = &cunit->GetDexLangContext()->GetIntrinsicHelper(); |
| 229 | UniquePtr<greenland::IRBuilder> greenland_irbuilder( |
| 230 | new greenland::IRBuilder(*context, *module, *intrinsic_helper)); |
| 231 | oatCompileMethodToGBC(*compiler_, |
| 232 | oat_compilation_unit->GetCodeItem(), |
| 233 | oat_compilation_unit->access_flags_, |
| 234 | invoke_type, |
| 235 | oat_compilation_unit->GetDexMethodIndex(), |
| 236 | oat_compilation_unit->GetClassLoader(), |
| 237 | *oat_compilation_unit->GetDexFile(), |
| 238 | module, |
| 239 | context, |
| 240 | intrinsic_helper, |
| 241 | greenland_irbuilder.get() |
| 242 | ); |
| 243 | |
| 244 | cunit->SetCompiler(compiler_); |
| 245 | cunit->SetOatCompilationUnit(oat_compilation_unit); |
| 246 | |
| 247 | cunit->Materialize(); |
| 248 | |
| 249 | return new CompiledMethod(cunit->GetInstructionSet(), |
| 250 | cunit->GetCompiledCode()); |
| 251 | } |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 252 | #else |
Logan Chien | 8b977d3 | 2012-02-21 19:14:55 +0800 | [diff] [blame] | 253 | UniquePtr<MethodCompiler> method_compiler( |
Logan Chien | 971bf3f | 2012-05-01 15:47:55 +0800 | [diff] [blame] | 254 | new MethodCompiler(cunit.get(), compiler_, oat_compilation_unit)); |
Logan Chien | 8b977d3 | 2012-02-21 19:14:55 +0800 | [diff] [blame] | 255 | |
Logan Chien | 7f76761 | 2012-03-01 18:54:49 +0800 | [diff] [blame] | 256 | return method_compiler->Compile(); |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 257 | #endif |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 258 | } |
Logan Chien | 8342616 | 2011-12-09 09:29:50 +0800 | [diff] [blame] | 259 | |
| 260 | |
Logan Chien | 7f76761 | 2012-03-01 18:54:49 +0800 | [diff] [blame] | 261 | CompiledMethod* CompilerLLVM:: |
| 262 | CompileNativeMethod(OatCompilationUnit* oat_compilation_unit) { |
Logan Chien | 971bf3f | 2012-05-01 15:47:55 +0800 | [diff] [blame] | 263 | UniquePtr<CompilationUnit> cunit(AllocateCompilationUnit()); |
Logan Chien | 8ba2fc5 | 2012-04-23 09:10:46 +0800 | [diff] [blame] | 264 | |
Logan Chien | 8b977d3 | 2012-02-21 19:14:55 +0800 | [diff] [blame] | 265 | UniquePtr<JniCompiler> jni_compiler( |
Logan Chien | 971bf3f | 2012-05-01 15:47:55 +0800 | [diff] [blame] | 266 | new JniCompiler(cunit.get(), *compiler_, oat_compilation_unit)); |
Logan Chien | 8b977d3 | 2012-02-21 19:14:55 +0800 | [diff] [blame] | 267 | |
Logan Chien | 7f76761 | 2012-03-01 18:54:49 +0800 | [diff] [blame] | 268 | return jni_compiler->Compile(); |
Logan Chien | 88894ee | 2012-02-13 16:42:22 +0800 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | |
Logan Chien | f04364f | 2012-02-10 12:01:39 +0800 | [diff] [blame] | 272 | CompiledInvokeStub* CompilerLLVM::CreateInvokeStub(bool is_static, |
| 273 | char const *shorty) { |
Logan Chien | 971bf3f | 2012-05-01 15:47:55 +0800 | [diff] [blame] | 274 | UniquePtr<CompilationUnit> cunit(AllocateCompilationUnit()); |
Logan Chien | 8ba2fc5 | 2012-04-23 09:10:46 +0800 | [diff] [blame] | 275 | |
TDYa127 | eead4ac | 2012-06-03 07:15:25 -0700 | [diff] [blame] | 276 | UniquePtr<StubCompiler> stub_compiler( |
Logan Chien | 971bf3f | 2012-05-01 15:47:55 +0800 | [diff] [blame] | 277 | new StubCompiler(cunit.get(), *compiler_)); |
Logan Chien | 8b977d3 | 2012-02-21 19:14:55 +0800 | [diff] [blame] | 278 | |
Logan Chien | 7a2a23a | 2012-06-06 11:01:00 +0800 | [diff] [blame] | 279 | return stub_compiler->CreateInvokeStub(is_static, shorty); |
| 280 | } |
TDYa127 | eead4ac | 2012-06-03 07:15:25 -0700 | [diff] [blame] | 281 | |
TDYa127 | eead4ac | 2012-06-03 07:15:25 -0700 | [diff] [blame] | 282 | |
Logan Chien | 7a2a23a | 2012-06-06 11:01:00 +0800 | [diff] [blame] | 283 | CompiledInvokeStub* CompilerLLVM::CreateProxyStub(char const *shorty) { |
Logan Chien | 971bf3f | 2012-05-01 15:47:55 +0800 | [diff] [blame] | 284 | UniquePtr<CompilationUnit> cunit(AllocateCompilationUnit()); |
Logan Chien | 7a2a23a | 2012-06-06 11:01:00 +0800 | [diff] [blame] | 285 | |
| 286 | UniquePtr<StubCompiler> stub_compiler( |
Logan Chien | 971bf3f | 2012-05-01 15:47:55 +0800 | [diff] [blame] | 287 | new StubCompiler(cunit.get(), *compiler_)); |
Logan Chien | 7a2a23a | 2012-06-06 11:01:00 +0800 | [diff] [blame] | 288 | |
| 289 | return stub_compiler->CreateProxyStub(shorty); |
Logan Chien | f04364f | 2012-02-10 12:01:39 +0800 | [diff] [blame] | 290 | } |
| 291 | |
Logan Chien | 8342616 | 2011-12-09 09:29:50 +0800 | [diff] [blame] | 292 | } // namespace compiler_llvm |
| 293 | } // namespace art |
Shih-wei Liao | c4c9881 | 2012-03-10 21:55:51 -0800 | [diff] [blame] | 294 | |
Logan Chien | 106b2a0 | 2012-03-18 04:41:38 +0800 | [diff] [blame] | 295 | inline static art::compiler_llvm::CompilerLLVM* ContextOf(art::Compiler& compiler) { |
| 296 | void *compiler_context = compiler.GetCompilerContext(); |
| 297 | CHECK(compiler_context != NULL); |
| 298 | return reinterpret_cast<art::compiler_llvm::CompilerLLVM*>(compiler_context); |
| 299 | } |
| 300 | |
| 301 | inline static const art::compiler_llvm::CompilerLLVM* ContextOf(const art::Compiler& compiler) { |
| 302 | void *compiler_context = compiler.GetCompilerContext(); |
| 303 | CHECK(compiler_context != NULL); |
| 304 | return reinterpret_cast<const art::compiler_llvm::CompilerLLVM*>(compiler_context); |
| 305 | } |
| 306 | |
| 307 | extern "C" void ArtInitCompilerContext(art::Compiler& compiler) { |
| 308 | CHECK(compiler.GetCompilerContext() == NULL); |
| 309 | |
| 310 | art::compiler_llvm::CompilerLLVM* compiler_llvm = |
| 311 | new art::compiler_llvm::CompilerLLVM(&compiler, |
| 312 | compiler.GetInstructionSet()); |
| 313 | |
| 314 | compiler.SetCompilerContext(compiler_llvm); |
| 315 | } |
| 316 | |
Logan Chien | 971bf3f | 2012-05-01 15:47:55 +0800 | [diff] [blame] | 317 | extern "C" void ArtUnInitCompilerContext(art::Compiler& compiler) { |
| 318 | delete ContextOf(compiler); |
| 319 | compiler.SetCompilerContext(NULL); |
| 320 | } |
Elliott Hughes | 3fa1b7e | 2012-03-13 17:06:22 -0700 | [diff] [blame] | 321 | extern "C" art::CompiledMethod* ArtCompileMethod(art::Compiler& compiler, |
Shih-wei Liao | c4c9881 | 2012-03-10 21:55:51 -0800 | [diff] [blame] | 322 | const art::DexFile::CodeItem* code_item, |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 323 | uint32_t access_flags, |
| 324 | art::InvokeType invoke_type, |
| 325 | uint32_t method_idx, |
Shih-wei Liao | cd05a62 | 2012-08-15 00:02:05 -0700 | [diff] [blame] | 326 | jobject class_loader, |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 327 | const art::DexFile& dex_file) { |
Shih-wei Liao | c4c9881 | 2012-03-10 21:55:51 -0800 | [diff] [blame] | 328 | art::ClassLinker *class_linker = art::Runtime::Current()->GetClassLinker(); |
Shih-wei Liao | c4c9881 | 2012-03-10 21:55:51 -0800 | [diff] [blame] | 329 | |
| 330 | art::OatCompilationUnit oat_compilation_unit( |
Shih-wei Liao | cd05a62 | 2012-08-15 00:02:05 -0700 | [diff] [blame] | 331 | class_loader, class_linker, dex_file, code_item, |
Shih-wei Liao | c4c9881 | 2012-03-10 21:55:51 -0800 | [diff] [blame] | 332 | method_idx, access_flags); |
TDYa127 | 0200d07 | 2012-04-17 20:55:08 -0700 | [diff] [blame] | 333 | art::compiler_llvm::CompilerLLVM* compiler_llvm = ContextOf(compiler); |
Shih-wei Liao | bb33f2f | 2012-08-23 13:20:00 -0700 | [diff] [blame] | 334 | art::CompiledMethod* result = compiler_llvm->CompileDexMethod(&oat_compilation_unit, invoke_type); |
TDYa127 | 0200d07 | 2012-04-17 20:55:08 -0700 | [diff] [blame] | 335 | return result; |
Shih-wei Liao | c4c9881 | 2012-03-10 21:55:51 -0800 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | extern "C" art::CompiledMethod* ArtJniCompileMethod(art::Compiler& compiler, |
| 339 | uint32_t access_flags, uint32_t method_idx, |
Shih-wei Liao | c4c9881 | 2012-03-10 21:55:51 -0800 | [diff] [blame] | 340 | const art::DexFile& dex_file) { |
Shih-wei Liao | c4c9881 | 2012-03-10 21:55:51 -0800 | [diff] [blame] | 341 | art::ClassLinker *class_linker = art::Runtime::Current()->GetClassLinker(); |
Shih-wei Liao | c4c9881 | 2012-03-10 21:55:51 -0800 | [diff] [blame] | 342 | |
| 343 | art::OatCompilationUnit oat_compilation_unit( |
Shih-wei Liao | cd05a62 | 2012-08-15 00:02:05 -0700 | [diff] [blame] | 344 | NULL, class_linker, dex_file, NULL, |
Shih-wei Liao | c4c9881 | 2012-03-10 21:55:51 -0800 | [diff] [blame] | 345 | method_idx, access_flags); |
| 346 | |
Logan Chien | 106b2a0 | 2012-03-18 04:41:38 +0800 | [diff] [blame] | 347 | art::compiler_llvm::CompilerLLVM* compiler_llvm = ContextOf(compiler); |
Elliott Hughes | 6f4976c | 2012-03-13 21:19:01 -0700 | [diff] [blame] | 348 | art::CompiledMethod* result = compiler_llvm->CompileNativeMethod(&oat_compilation_unit); |
Elliott Hughes | 13b835a | 2012-03-13 19:45:22 -0700 | [diff] [blame] | 349 | return result; |
Shih-wei Liao | c4c9881 | 2012-03-10 21:55:51 -0800 | [diff] [blame] | 350 | } |
| 351 | |
Logan Chien | 7a2a23a | 2012-06-06 11:01:00 +0800 | [diff] [blame] | 352 | extern "C" art::CompiledInvokeStub* ArtCreateInvokeStub(art::Compiler& compiler, |
| 353 | bool is_static, |
| 354 | const char* shorty, |
| 355 | uint32_t shorty_len) { |
TDYa127 | 0200d07 | 2012-04-17 20:55:08 -0700 | [diff] [blame] | 356 | art::compiler_llvm::CompilerLLVM* compiler_llvm = ContextOf(compiler); |
| 357 | art::CompiledInvokeStub* result = compiler_llvm->CreateInvokeStub(is_static, shorty); |
TDYa127 | 0200d07 | 2012-04-17 20:55:08 -0700 | [diff] [blame] | 358 | return result; |
Logan Chien | 106b2a0 | 2012-03-18 04:41:38 +0800 | [diff] [blame] | 359 | } |
| 360 | |
Logan Chien | 7a2a23a | 2012-06-06 11:01:00 +0800 | [diff] [blame] | 361 | extern "C" art::CompiledInvokeStub* ArtCreateProxyStub(art::Compiler& compiler, |
| 362 | const char* shorty, |
| 363 | uint32_t shorty_len) { |
| 364 | art::compiler_llvm::CompilerLLVM* compiler_llvm = ContextOf(compiler); |
| 365 | art::CompiledInvokeStub* result = compiler_llvm->CreateProxyStub(shorty); |
Logan Chien | 7a2a23a | 2012-06-06 11:01:00 +0800 | [diff] [blame] | 366 | return result; |
| 367 | } |
| 368 | |
Logan Chien | 106b2a0 | 2012-03-18 04:41:38 +0800 | [diff] [blame] | 369 | extern "C" void compilerLLVMSetBitcodeFileName(art::Compiler& compiler, |
| 370 | std::string const& filename) { |
| 371 | ContextOf(compiler)->SetBitcodeFileName(filename); |
Shih-wei Liao | c4c9881 | 2012-03-10 21:55:51 -0800 | [diff] [blame] | 372 | } |