blob: 7c11702ba910b7e27d4960ae20604b1deeab1a75 [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#ifndef ART_SRC_COMPILER_LLVM_RUNTIME_SUPPORT_BUILDER_H_
18#define ART_SRC_COMPILER_LLVM_RUNTIME_SUPPORT_BUILDER_H_
19
TDYa127de479be2012-05-31 08:03:26 -070020#include "backend_types.h"
Elliott Hughes07ed66b2012-12-12 18:34:25 -080021#include "base/logging.h"
TDYa127d668a062012-04-13 12:36:57 -070022#include "runtime_support_func.h"
23
TDYa127de479be2012-05-31 08:03:26 -070024#include <stdint.h>
25
TDYa127d668a062012-04-13 12:36:57 -070026namespace llvm {
27 class LLVMContext;
28 class Module;
29 class Function;
TDYa127de479be2012-05-31 08:03:26 -070030 class Type;
31 class Value;
TDYa127d668a062012-04-13 12:36:57 -070032}
33
34namespace art {
35namespace compiler_llvm {
36
37class IRBuilder;
38
39
40class RuntimeSupportBuilder {
41 public:
42 RuntimeSupportBuilder(llvm::LLVMContext& context, llvm::Module& module, IRBuilder& irb);
43
TDYa127de479be2012-05-31 08:03:26 -070044 /* Thread */
45 virtual llvm::Value* EmitGetCurrentThread();
46 virtual llvm::Value* EmitLoadFromThreadOffset(int64_t offset, llvm::Type* type,
47 TBAASpecialType s_ty);
48 virtual void EmitStoreToThreadOffset(int64_t offset, llvm::Value* value,
49 TBAASpecialType s_ty);
TDYa127c1478262012-06-20 20:22:27 -070050 virtual llvm::Value* EmitSetCurrentThread(llvm::Value* thread);
TDYa127de479be2012-05-31 08:03:26 -070051
52 /* ShadowFrame */
53 virtual llvm::Value* EmitPushShadowFrame(llvm::Value* new_shadow_frame,
TDYa127ce4cc0d2012-11-18 16:59:53 -080054 llvm::Value* method, uint32_t num_vregs);
TDYa127de479be2012-05-31 08:03:26 -070055 virtual llvm::Value* EmitPushShadowFrameNoInline(llvm::Value* new_shadow_frame,
TDYa127ce4cc0d2012-11-18 16:59:53 -080056 llvm::Value* method, uint32_t num_vregs);
TDYa127de479be2012-05-31 08:03:26 -070057 virtual void EmitPopShadowFrame(llvm::Value* old_shadow_frame);
58
TDYa127823433d2012-09-26 16:03:51 -070059 /* Exception */
60 virtual llvm::Value* EmitGetAndClearException();
TDYa127de479be2012-05-31 08:03:26 -070061 virtual llvm::Value* EmitIsExceptionPending();
TDYa127823433d2012-09-26 16:03:51 -070062
63 /* Suspend */
TDYa127de479be2012-05-31 08:03:26 -070064 virtual void EmitTestSuspend();
65
TDYa127b08ed122012-06-05 23:51:19 -070066 /* Monitor */
67 virtual void EmitLockObject(llvm::Value* object);
68 virtual void EmitUnlockObject(llvm::Value* object);
69
TDYa1279a129452012-07-19 03:10:08 -070070 /* MarkGCCard */
71 virtual void EmitMarkGCCard(llvm::Value* value, llvm::Value* target_addr);
72
TDYa127d668a062012-04-13 12:36:57 -070073 llvm::Function* GetRuntimeSupportFunction(runtime_support::RuntimeId id) {
74 if (id >= 0 && id < runtime_support::MAX_ID) {
75 return runtime_support_func_decls_[id];
76 } else {
77 LOG(ERROR) << "Unknown runtime function id: " << id;
78 return NULL;
79 }
80 }
81
TDYa127d668a062012-04-13 12:36:57 -070082 virtual ~RuntimeSupportBuilder() {}
83
84 protected:
TDYa127d668a062012-04-13 12:36:57 -070085 llvm::LLVMContext& context_;
86 llvm::Module& module_;
87 IRBuilder& irb_;
88
89 private:
90 llvm::Function* runtime_support_func_decls_[runtime_support::MAX_ID];
91 bool target_runtime_support_func_[runtime_support::MAX_ID];
92};
93
94
95} // namespace compiler_llvm
96} // namespace art
97
98#endif // ART_SRC_COMPILER_LLVM_RUNTIME_SUPPORT_BUILDER_H_