blob: 1a0a78a2c6b3875853d08b6695229ab4dc9b8cc5 [file] [log] [blame]
TDYa127d668a062012-04-13 12:36:57 -07001/*
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
19#include "ir_builder.h"
TDYa127de479be2012-05-31 08:03:26 -070020#include "stringprintf.h"
TDYa127d668a062012-04-13 12:36:57 -070021#include "thread.h"
TDYa127853cd092012-04-21 22:15:31 -070022#include "utils_llvm.h"
TDYa127d668a062012-04-13 12:36:57 -070023
24#include <llvm/DerivedTypes.h>
25#include <llvm/Function.h>
26#include <llvm/InlineAsm.h>
27#include <llvm/Module.h>
28#include <llvm/Type.h>
29
30#include <vector>
31
32using namespace llvm;
33
34namespace art {
35namespace compiler_llvm {
36
TDYa127d668a062012-04-13 12:36:57 -070037
TDYa127de479be2012-05-31 08:03:26 -070038llvm::Value* RuntimeSupportBuilderX86::EmitGetCurrentThread() {
39 Function* ori_func = GetRuntimeSupportFunction(runtime_support::GetCurrentThread);
40 std::string inline_asm(StringPrintf("movl %%fs:%d, $0", Thread::SelfOffset().Int32Value()));
41 InlineAsm* func = InlineAsm::get(ori_func->getFunctionType(), inline_asm, "=r", false);
42 CallInst* thread = irb_.CreateCall(func);
43 thread->setDoesNotAccessMemory();
44 irb_.SetTBAA(thread, kTBAAConstJObject);
45 return thread;
46}
TDYa127d668a062012-04-13 12:36:57 -070047
TDYa127de479be2012-05-31 08:03:26 -070048llvm::Value* RuntimeSupportBuilderX86::EmitLoadFromThreadOffset(int64_t offset, llvm::Type* type,
49 TBAASpecialType s_ty) {
50 FunctionType* func_ty = FunctionType::get(/*Result=*/type,
51 /*isVarArg=*/false);
52 std::string inline_asm(StringPrintf("movl %%fs:%d, $0", static_cast<int>(offset)));
53 InlineAsm* func = InlineAsm::get(func_ty, inline_asm, "=r", true);
54 CallInst* result = irb_.CreateCall(func);
55 result->setOnlyReadsMemory();
56 irb_.SetTBAA(result, s_ty);
57 return result;
58}
TDYa127d668a062012-04-13 12:36:57 -070059
TDYa127de479be2012-05-31 08:03:26 -070060void RuntimeSupportBuilderX86::EmitStoreToThreadOffset(int64_t offset, llvm::Value* value,
61 TBAASpecialType s_ty) {
62 FunctionType* func_ty = FunctionType::get(/*Result=*/Type::getVoidTy(context_),
63 /*Params=*/value->getType(),
64 /*isVarArg=*/false);
65 std::string inline_asm(StringPrintf("movl $0, %%fs:%d", static_cast<int>(offset)));
66 InlineAsm* func = InlineAsm::get(func_ty, inline_asm, "r", true);
67 CallInst* call_inst = irb_.CreateCall(func, value);
68 irb_.SetTBAA(call_inst, s_ty);
69}
TDYa127853cd092012-04-21 22:15:31 -070070
TDYa127de479be2012-05-31 08:03:26 -070071void RuntimeSupportBuilderX86::EmitSetCurrentThread(llvm::Value*) {
72 /* Nothing to be done. */
TDYa127d668a062012-04-13 12:36:57 -070073}
74
75
76} // namespace compiler_llvm
77} // namespace art