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) { |
| 28 | java_object_type_ = module.getTypeByName("JavaObject")->getPointerTo(); |
| 29 | java_method_type_ = module.getTypeByName("Method")->getPointerTo(); |
| 30 | java_thread_type_ = module.getTypeByName("Thread")->getPointerTo(); |
| 31 | } |
| 32 | |
| 33 | llvm::Type* IRBuilder::GetJTypeInAccurateSpace(JType jty) { |
| 34 | switch (jty) { |
| 35 | case kVoid: |
| 36 | return GetJVoidTy(); |
| 37 | |
| 38 | case kBoolean: |
| 39 | return GetJBooleanTy(); |
| 40 | |
| 41 | case kByte: |
| 42 | return GetJByteTy(); |
| 43 | |
| 44 | case kChar: |
| 45 | return GetJCharTy(); |
| 46 | |
| 47 | case kShort: |
| 48 | return GetJShortTy(); |
| 49 | |
| 50 | case kInt: |
| 51 | return GetJIntTy(); |
| 52 | |
| 53 | case kLong: |
| 54 | return GetJLongTy(); |
| 55 | |
| 56 | case kFloat: |
| 57 | return GetJFloatTy(); |
| 58 | |
| 59 | case kDouble: |
| 60 | return GetJDoubleTy(); |
| 61 | |
| 62 | case kObject: |
| 63 | return GetJObjectTy(); |
| 64 | } |
| 65 | |
| 66 | LOG(FATAL) << "Unknown java type: " << jty; |
| 67 | return NULL; |
| 68 | } |
| 69 | |
| 70 | llvm::Type* IRBuilder::GetJTypeInRegSpace(JType jty) { |
| 71 | RegCategory regcat = GetRegCategoryFromJType(jty); |
| 72 | |
| 73 | switch (regcat) { |
| 74 | case kRegUnknown: |
| 75 | case kRegZero: |
| 76 | LOG(FATAL) << "Register category \"Unknown\" or \"Zero\" does not have " |
| 77 | << "the LLVM type"; |
| 78 | return NULL; |
| 79 | |
| 80 | case kRegCat1nr: |
| 81 | return getInt32Ty(); |
| 82 | |
| 83 | case kRegCat2: |
| 84 | return getInt64Ty(); |
| 85 | |
| 86 | case kRegObject: |
| 87 | return GetJObjectTy(); |
| 88 | } |
| 89 | |
| 90 | LOG(FATAL) << "Unknown register category: " << regcat; |
| 91 | return NULL; |
| 92 | } |
| 93 | |
| 94 | llvm::Type* IRBuilder::GetJTypeInArraySpace(JType jty) { |
| 95 | switch (jty) { |
| 96 | case kVoid: |
| 97 | LOG(FATAL) << "void type should not be used in array type space"; |
| 98 | return NULL; |
| 99 | |
| 100 | case kBoolean: |
| 101 | case kByte: |
| 102 | return getInt8Ty(); |
| 103 | |
| 104 | case kChar: |
| 105 | case kShort: |
| 106 | return getInt16Ty(); |
| 107 | |
| 108 | case kInt: |
| 109 | return getInt32Ty(); |
| 110 | |
| 111 | case kLong: |
| 112 | return getInt64Ty(); |
| 113 | |
| 114 | case kFloat: |
| 115 | return getFloatTy(); |
| 116 | |
| 117 | case kDouble: |
| 118 | return getDoubleTy(); |
| 119 | |
| 120 | case kObject: |
| 121 | return GetJObjectTy(); |
| 122 | } |
| 123 | |
| 124 | LOG(FATAL) << "Unknown java type: " << jty; |
| 125 | return NULL; |
| 126 | } |
| 127 | |
| 128 | } // namespace greenland |
| 129 | } // namespace art |