TDYa127 | d668a06 | 2012-04-13 12:36:57 -0700 | [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 "runtime_support_builder_x86.h" |
| 18 | |
Elliott Hughes | e222ee0 | 2012-12-13 14:41:43 -0800 | [diff] [blame] | 19 | #include "base/stringprintf.h" |
TDYa127 | d668a06 | 2012-04-13 12:36:57 -0700 | [diff] [blame] | 20 | #include "ir_builder.h" |
| 21 | #include "thread.h" |
TDYa127 | 853cd09 | 2012-04-21 22:15:31 -0700 | [diff] [blame] | 22 | #include "utils_llvm.h" |
TDYa127 | d668a06 | 2012-04-13 12:36:57 -0700 | [diff] [blame] | 23 | |
Brian Carlstrom | 37d4879 | 2013-03-22 14:14:45 -0700 | [diff] [blame] | 24 | #include <llvm/IR/DerivedTypes.h> |
| 25 | #include <llvm/IR/Function.h> |
| 26 | #include <llvm/IR/InlineAsm.h> |
| 27 | #include <llvm/IR/Module.h> |
| 28 | #include <llvm/IR/Type.h> |
TDYa127 | d668a06 | 2012-04-13 12:36:57 -0700 | [diff] [blame] | 29 | |
| 30 | #include <vector> |
| 31 | |
Brian Carlstrom | 3e3d591 | 2013-07-18 00:19:45 -0700 | [diff] [blame] | 32 | using ::llvm::CallInst; |
| 33 | using ::llvm::Function; |
| 34 | using ::llvm::FunctionType; |
| 35 | using ::llvm::InlineAsm; |
| 36 | using ::llvm::Type; |
| 37 | using ::llvm::UndefValue; |
| 38 | using ::llvm::Value; |
TDYa127 | d668a06 | 2012-04-13 12:36:57 -0700 | [diff] [blame] | 39 | |
| 40 | namespace art { |
Ian Rogers | 4c1c283 | 2013-03-04 18:30:13 -0800 | [diff] [blame] | 41 | namespace llvm { |
TDYa127 | d668a06 | 2012-04-13 12:36:57 -0700 | [diff] [blame] | 42 | |
TDYa127 | d668a06 | 2012-04-13 12:36:57 -0700 | [diff] [blame] | 43 | |
Brian Carlstrom | 3e3d591 | 2013-07-18 00:19:45 -0700 | [diff] [blame] | 44 | Value* RuntimeSupportBuilderX86::EmitGetCurrentThread() { |
TDYa127 | de479be | 2012-05-31 08:03:26 -0700 | [diff] [blame] | 45 | Function* ori_func = GetRuntimeSupportFunction(runtime_support::GetCurrentThread); |
TDYa127 | 823433d | 2012-09-26 16:03:51 -0700 | [diff] [blame] | 46 | std::string inline_asm(StringPrintf("mov %%fs:%d, $0", Thread::SelfOffset().Int32Value())); |
TDYa127 | de479be | 2012-05-31 08:03:26 -0700 | [diff] [blame] | 47 | InlineAsm* func = InlineAsm::get(ori_func->getFunctionType(), inline_asm, "=r", false); |
| 48 | CallInst* thread = irb_.CreateCall(func); |
| 49 | thread->setDoesNotAccessMemory(); |
| 50 | irb_.SetTBAA(thread, kTBAAConstJObject); |
| 51 | return thread; |
| 52 | } |
TDYa127 | d668a06 | 2012-04-13 12:36:57 -0700 | [diff] [blame] | 53 | |
Brian Carlstrom | 3e3d591 | 2013-07-18 00:19:45 -0700 | [diff] [blame] | 54 | Value* RuntimeSupportBuilderX86::EmitLoadFromThreadOffset(int64_t offset, Type* type, |
| 55 | TBAASpecialType s_ty) { |
TDYa127 | de479be | 2012-05-31 08:03:26 -0700 | [diff] [blame] | 56 | FunctionType* func_ty = FunctionType::get(/*Result=*/type, |
| 57 | /*isVarArg=*/false); |
TDYa127 | 823433d | 2012-09-26 16:03:51 -0700 | [diff] [blame] | 58 | std::string inline_asm(StringPrintf("mov %%fs:%d, $0", static_cast<int>(offset))); |
TDYa127 | de479be | 2012-05-31 08:03:26 -0700 | [diff] [blame] | 59 | InlineAsm* func = InlineAsm::get(func_ty, inline_asm, "=r", true); |
| 60 | CallInst* result = irb_.CreateCall(func); |
| 61 | result->setOnlyReadsMemory(); |
| 62 | irb_.SetTBAA(result, s_ty); |
| 63 | return result; |
| 64 | } |
TDYa127 | d668a06 | 2012-04-13 12:36:57 -0700 | [diff] [blame] | 65 | |
Brian Carlstrom | 3e3d591 | 2013-07-18 00:19:45 -0700 | [diff] [blame] | 66 | void RuntimeSupportBuilderX86::EmitStoreToThreadOffset(int64_t offset, Value* value, |
TDYa127 | de479be | 2012-05-31 08:03:26 -0700 | [diff] [blame] | 67 | TBAASpecialType s_ty) { |
| 68 | FunctionType* func_ty = FunctionType::get(/*Result=*/Type::getVoidTy(context_), |
| 69 | /*Params=*/value->getType(), |
| 70 | /*isVarArg=*/false); |
TDYa127 | 823433d | 2012-09-26 16:03:51 -0700 | [diff] [blame] | 71 | std::string inline_asm(StringPrintf("mov $0, %%fs:%d", static_cast<int>(offset))); |
TDYa127 | de479be | 2012-05-31 08:03:26 -0700 | [diff] [blame] | 72 | InlineAsm* func = InlineAsm::get(func_ty, inline_asm, "r", true); |
| 73 | CallInst* call_inst = irb_.CreateCall(func, value); |
| 74 | irb_.SetTBAA(call_inst, s_ty); |
| 75 | } |
TDYa127 | 853cd09 | 2012-04-21 22:15:31 -0700 | [diff] [blame] | 76 | |
Brian Carlstrom | 3e3d591 | 2013-07-18 00:19:45 -0700 | [diff] [blame] | 77 | Value* RuntimeSupportBuilderX86::EmitSetCurrentThread(Value*) { |
TDYa127 | de479be | 2012-05-31 08:03:26 -0700 | [diff] [blame] | 78 | /* Nothing to be done. */ |
Brian Carlstrom | 3e3d591 | 2013-07-18 00:19:45 -0700 | [diff] [blame] | 79 | return UndefValue::get(irb_.getJObjectTy()); |
TDYa127 | d668a06 | 2012-04-13 12:36:57 -0700 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 83 | } // namespace llvm |
| 84 | } // namespace art |