• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef ART_COMPILER_LLVM_RUNTIME_SUPPORT_BUILDER_H_
18 #define ART_COMPILER_LLVM_RUNTIME_SUPPORT_BUILDER_H_
19 
20 #include "backend_types.h"
21 #include "base/logging.h"
22 #include "runtime_support_llvm_func.h"
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 */
67   virtual void EmitLockObject(::llvm::Value* object);
68   virtual void EmitUnlockObject(::llvm::Value* object);
69 
70   /* MarkGCCard */
71   virtual void EmitMarkGCCard(::llvm::Value* value, ::llvm::Value* target_addr);
72 
GetRuntimeSupportFunction(runtime_support::RuntimeId id)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 
~RuntimeSupportBuilder()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 
95 }  // namespace llvm
96 }  // namespace art
97 
98 #endif  // ART_COMPILER_LLVM_RUNTIME_SUPPORT_BUILDER_H_
99