Shih-wei Liao | e94d9b2 | 2012-05-22 09:01:24 -0700 | [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 | |
| 17 | #include "ir_builder.h" |
| 18 | |
| 19 | #include <llvm/Module.h> |
| 20 | |
| 21 | namespace art { |
| 22 | namespace greenland { |
| 23 | |
| 24 | IRBuilder::IRBuilder(llvm::LLVMContext& context, llvm::Module& module, |
| 25 | IntrinsicHelper& intrinsic_helper) |
| 26 | : LLVMIRBuilder(context), java_object_type_(NULL), java_method_type_(NULL), |
| 27 | java_thread_type_(NULL), intrinsic_helper_(intrinsic_helper) { |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame^] | 28 | // JavaObject must be defined in the module |
Shih-wei Liao | e94d9b2 | 2012-05-22 09:01:24 -0700 | [diff] [blame] | 29 | java_object_type_ = module.getTypeByName("JavaObject")->getPointerTo(); |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame^] | 30 | |
| 31 | // If type of Method is not explicitly defined in the module, use JavaObject* |
| 32 | llvm::Type* type = module.getTypeByName("Method"); |
| 33 | if (type != NULL) { |
| 34 | java_method_type_ = type->getPointerTo(); |
| 35 | } else { |
| 36 | java_method_type_ = java_object_type_; |
| 37 | } |
| 38 | |
| 39 | // If type of Thread is not explicitly defined in the module, use JavaObject* |
| 40 | type = module.getTypeByName("Thread"); |
| 41 | if (type != NULL) { |
| 42 | java_thread_type_ = type->getPointerTo(); |
| 43 | } else { |
| 44 | java_thread_type_ = java_object_type_; |
| 45 | } |
Shih-wei Liao | e94d9b2 | 2012-05-22 09:01:24 -0700 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | llvm::Type* IRBuilder::GetJTypeInAccurateSpace(JType jty) { |
| 49 | switch (jty) { |
| 50 | case kVoid: |
| 51 | return GetJVoidTy(); |
| 52 | |
| 53 | case kBoolean: |
| 54 | return GetJBooleanTy(); |
| 55 | |
| 56 | case kByte: |
| 57 | return GetJByteTy(); |
| 58 | |
| 59 | case kChar: |
| 60 | return GetJCharTy(); |
| 61 | |
| 62 | case kShort: |
| 63 | return GetJShortTy(); |
| 64 | |
| 65 | case kInt: |
| 66 | return GetJIntTy(); |
| 67 | |
| 68 | case kLong: |
| 69 | return GetJLongTy(); |
| 70 | |
| 71 | case kFloat: |
| 72 | return GetJFloatTy(); |
| 73 | |
| 74 | case kDouble: |
| 75 | return GetJDoubleTy(); |
| 76 | |
| 77 | case kObject: |
| 78 | return GetJObjectTy(); |
| 79 | } |
| 80 | |
| 81 | LOG(FATAL) << "Unknown java type: " << jty; |
| 82 | return NULL; |
| 83 | } |
| 84 | |
| 85 | llvm::Type* IRBuilder::GetJTypeInRegSpace(JType jty) { |
| 86 | RegCategory regcat = GetRegCategoryFromJType(jty); |
| 87 | |
| 88 | switch (regcat) { |
| 89 | case kRegUnknown: |
| 90 | case kRegZero: |
| 91 | LOG(FATAL) << "Register category \"Unknown\" or \"Zero\" does not have " |
| 92 | << "the LLVM type"; |
| 93 | return NULL; |
| 94 | |
| 95 | case kRegCat1nr: |
| 96 | return getInt32Ty(); |
| 97 | |
| 98 | case kRegCat2: |
| 99 | return getInt64Ty(); |
| 100 | |
| 101 | case kRegObject: |
| 102 | return GetJObjectTy(); |
| 103 | } |
| 104 | |
| 105 | LOG(FATAL) << "Unknown register category: " << regcat; |
| 106 | return NULL; |
| 107 | } |
| 108 | |
| 109 | llvm::Type* IRBuilder::GetJTypeInArraySpace(JType jty) { |
| 110 | switch (jty) { |
| 111 | case kVoid: |
| 112 | LOG(FATAL) << "void type should not be used in array type space"; |
| 113 | return NULL; |
| 114 | |
| 115 | case kBoolean: |
| 116 | case kByte: |
| 117 | return getInt8Ty(); |
| 118 | |
| 119 | case kChar: |
| 120 | case kShort: |
| 121 | return getInt16Ty(); |
| 122 | |
| 123 | case kInt: |
| 124 | return getInt32Ty(); |
| 125 | |
| 126 | case kLong: |
| 127 | return getInt64Ty(); |
| 128 | |
| 129 | case kFloat: |
| 130 | return getFloatTy(); |
| 131 | |
| 132 | case kDouble: |
| 133 | return getDoubleTy(); |
| 134 | |
| 135 | case kObject: |
| 136 | return GetJObjectTy(); |
| 137 | } |
| 138 | |
| 139 | LOG(FATAL) << "Unknown java type: " << jty; |
| 140 | return NULL; |
| 141 | } |
| 142 | |
| 143 | } // namespace greenland |
| 144 | } // namespace art |