Ian Rogers | 4c1c283 | 2013-03-04 18:30:13 -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 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_COMPILER_LLVM_RUNTIME_SUPPORT_BUILDER_H_ |
| 18 | #define ART_COMPILER_LLVM_RUNTIME_SUPPORT_BUILDER_H_ |
Ian Rogers | 4c1c283 | 2013-03-04 18:30:13 -0800 | [diff] [blame] | 19 | |
| 20 | #include "backend_types.h" |
| 21 | #include "base/logging.h" |
Brian Carlstrom | 51c2467 | 2013-07-11 16:00:56 -0700 | [diff] [blame] | 22 | #include "runtime_support_llvm_func.h" |
Ian Rogers | 4c1c283 | 2013-03-04 18:30:13 -0800 | [diff] [blame] | 23 | |
| 24 | #include <stdint.h> |
| 25 | |
| 26 | namespace llvm { |
| 27 | class LLVMContext; |
| 28 | class Module; |
| 29 | class Function; |
| 30 | class Type; |
| 31 | class Value; |
| 32 | } |
| 33 | |
| 34 | namespace art { |
| 35 | namespace llvm { |
| 36 | |
| 37 | class IRBuilder; |
| 38 | |
| 39 | |
| 40 | class RuntimeSupportBuilder { |
| 41 | public: |
| 42 | RuntimeSupportBuilder(::llvm::LLVMContext& context, ::llvm::Module& module, IRBuilder& irb); |
| 43 | |
| 44 | /* 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); |
| 50 | virtual ::llvm::Value* EmitSetCurrentThread(::llvm::Value* thread); |
| 51 | |
| 52 | /* ShadowFrame */ |
| 53 | virtual ::llvm::Value* EmitPushShadowFrame(::llvm::Value* new_shadow_frame, |
| 54 | ::llvm::Value* method, uint32_t num_vregs); |
| 55 | virtual ::llvm::Value* EmitPushShadowFrameNoInline(::llvm::Value* new_shadow_frame, |
| 56 | ::llvm::Value* method, uint32_t num_vregs); |
| 57 | virtual void EmitPopShadowFrame(::llvm::Value* old_shadow_frame); |
| 58 | |
| 59 | /* Exception */ |
| 60 | virtual ::llvm::Value* EmitGetAndClearException(); |
| 61 | virtual ::llvm::Value* EmitIsExceptionPending(); |
| 62 | |
| 63 | /* Suspend */ |
| 64 | virtual void EmitTestSuspend(); |
| 65 | |
| 66 | /* Monitor */ |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 67 | void EmitLockObject(::llvm::Value* object); |
| 68 | void EmitUnlockObject(::llvm::Value* object); |
Ian Rogers | 4c1c283 | 2013-03-04 18:30:13 -0800 | [diff] [blame] | 69 | |
| 70 | /* MarkGCCard */ |
| 71 | virtual void EmitMarkGCCard(::llvm::Value* value, ::llvm::Value* target_addr); |
| 72 | |
| 73 | ::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 | |
| 82 | virtual ~RuntimeSupportBuilder() {} |
| 83 | |
| 84 | protected: |
| 85 | ::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 | |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 95 | } // namespace llvm |
| 96 | } // namespace art |
Ian Rogers | 4c1c283 | 2013-03-04 18:30:13 -0800 | [diff] [blame] | 97 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 98 | #endif // ART_COMPILER_LLVM_RUNTIME_SUPPORT_BUILDER_H_ |