blob: 3d11f9df5bd2b0f1fcf81c2f75519922e6976408 [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
Elliott Hughese222ee02012-12-13 14:41:43 -080019#include "base/stringprintf.h"
TDYa127d668a062012-04-13 12:36:57 -070020#include "ir_builder.h"
21#include "thread.h"
TDYa127853cd092012-04-21 22:15:31 -070022#include "utils_llvm.h"
TDYa127d668a062012-04-13 12:36:57 -070023
Brian Carlstrom37d48792013-03-22 14:14:45 -070024#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>
TDYa127d668a062012-04-13 12:36:57 -070029
30#include <vector>
31
Brian Carlstrom3e3d5912013-07-18 00:19:45 -070032using ::llvm::CallInst;
33using ::llvm::Function;
34using ::llvm::FunctionType;
35using ::llvm::InlineAsm;
36using ::llvm::Type;
37using ::llvm::UndefValue;
38using ::llvm::Value;
TDYa127d668a062012-04-13 12:36:57 -070039
40namespace art {
Ian Rogers4c1c2832013-03-04 18:30:13 -080041namespace llvm {
TDYa127d668a062012-04-13 12:36:57 -070042
TDYa127d668a062012-04-13 12:36:57 -070043
Brian Carlstrom3e3d5912013-07-18 00:19:45 -070044Value* RuntimeSupportBuilderX86::EmitGetCurrentThread() {
TDYa127de479be2012-05-31 08:03:26 -070045 Function* ori_func = GetRuntimeSupportFunction(runtime_support::GetCurrentThread);
TDYa127823433d2012-09-26 16:03:51 -070046 std::string inline_asm(StringPrintf("mov %%fs:%d, $0", Thread::SelfOffset().Int32Value()));
TDYa127de479be2012-05-31 08:03:26 -070047 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}
TDYa127d668a062012-04-13 12:36:57 -070053
Brian Carlstrom3e3d5912013-07-18 00:19:45 -070054Value* RuntimeSupportBuilderX86::EmitLoadFromThreadOffset(int64_t offset, Type* type,
55 TBAASpecialType s_ty) {
TDYa127de479be2012-05-31 08:03:26 -070056 FunctionType* func_ty = FunctionType::get(/*Result=*/type,
57 /*isVarArg=*/false);
TDYa127823433d2012-09-26 16:03:51 -070058 std::string inline_asm(StringPrintf("mov %%fs:%d, $0", static_cast<int>(offset)));
TDYa127de479be2012-05-31 08:03:26 -070059 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}
TDYa127d668a062012-04-13 12:36:57 -070065
Brian Carlstrom3e3d5912013-07-18 00:19:45 -070066void RuntimeSupportBuilderX86::EmitStoreToThreadOffset(int64_t offset, Value* value,
TDYa127de479be2012-05-31 08:03:26 -070067 TBAASpecialType s_ty) {
68 FunctionType* func_ty = FunctionType::get(/*Result=*/Type::getVoidTy(context_),
69 /*Params=*/value->getType(),
70 /*isVarArg=*/false);
TDYa127823433d2012-09-26 16:03:51 -070071 std::string inline_asm(StringPrintf("mov $0, %%fs:%d", static_cast<int>(offset)));
TDYa127de479be2012-05-31 08:03:26 -070072 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}
TDYa127853cd092012-04-21 22:15:31 -070076
Brian Carlstrom3e3d5912013-07-18 00:19:45 -070077Value* RuntimeSupportBuilderX86::EmitSetCurrentThread(Value*) {
TDYa127de479be2012-05-31 08:03:26 -070078 /* Nothing to be done. */
Brian Carlstrom3e3d5912013-07-18 00:19:45 -070079 return UndefValue::get(irb_.getJObjectTy());
TDYa127d668a062012-04-13 12:36:57 -070080}
81
82
Brian Carlstrom7934ac22013-07-26 10:54:15 -070083} // namespace llvm
84} // namespace art