| Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -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 |  | 
 | 17 | #include "ir_builder.h" | 
 | 18 |  | 
 | 19 | #include <llvm/Module.h> | 
 | 20 |  | 
 | 21 | using namespace art::compiler_llvm; | 
 | 22 |  | 
 | 23 |  | 
 | 24 | //---------------------------------------------------------------------------- | 
 | 25 | // General | 
 | 26 | //---------------------------------------------------------------------------- | 
 | 27 |  | 
 | 28 | IRBuilder::IRBuilder(llvm::LLVMContext& context, llvm::Module& module) | 
 | 29 | : LLVMIRBuilder(context) { | 
 | 30 |  | 
 | 31 |   // Get java object type from module | 
 | 32 |   llvm::Type* jobject_struct_type = | 
 | 33 |     llvm::StructType::create(context, "JavaObject"); | 
 | 34 |   jobject_type_ = jobject_struct_type->getPointerTo(); | 
 | 35 | } | 
 | 36 |  | 
 | 37 |  | 
 | 38 | //---------------------------------------------------------------------------- | 
 | 39 | // Type Helper Function | 
 | 40 | //---------------------------------------------------------------------------- | 
 | 41 |  | 
 | 42 | llvm::Type* IRBuilder::getJTypeInAccurateSpace(JType jty) { | 
 | 43 |   switch (jty) { | 
 | 44 |   case kVoid: | 
 | 45 |     return getJVoidTy(); | 
 | 46 |  | 
 | 47 |   case kBoolean: | 
 | 48 |     return getJBooleanTy(); | 
 | 49 |  | 
 | 50 |   case kByte: | 
 | 51 |     return getJByteTy(); | 
 | 52 |  | 
 | 53 |   case kChar: | 
 | 54 |     return getJCharTy(); | 
 | 55 |  | 
 | 56 |   case kShort: | 
 | 57 |     return getJShortTy(); | 
 | 58 |  | 
 | 59 |   case kInt: | 
 | 60 |     return getJIntTy(); | 
 | 61 |  | 
 | 62 |   case kLong: | 
 | 63 |     return getJLongTy(); | 
 | 64 |  | 
 | 65 |   case kFloat: | 
 | 66 |     return getJFloatTy(); | 
 | 67 |  | 
 | 68 |   case kDouble: | 
 | 69 |     return getJDoubleTy(); | 
 | 70 |  | 
 | 71 |   case kObject: | 
 | 72 |     return getJObjectTy(); | 
 | 73 |   } | 
 | 74 |  | 
 | 75 |   LOG(FATAL) << "Unknown java type: " << jty; | 
 | 76 |   return NULL; | 
 | 77 | } | 
 | 78 |  | 
 | 79 |  | 
 | 80 | llvm::Type* IRBuilder::getJTypeInRegSpace(JType jty) { | 
 | 81 |   switch (GetRegCategoryFromJType(jty)) { | 
 | 82 |   case kRegUnknown: | 
 | 83 |   case kRegZero: | 
 | 84 |     return NULL; | 
 | 85 |  | 
 | 86 |   case kRegCat1nr: | 
 | 87 |     return getInt32Ty(); | 
 | 88 |  | 
 | 89 |   case kRegCat2: | 
 | 90 |     return getInt64Ty(); | 
 | 91 |  | 
 | 92 |   case kRegObject: | 
 | 93 |     return getJObjectTy(); | 
 | 94 |   } | 
 | 95 |  | 
 | 96 |   return NULL; | 
 | 97 | } | 
 | 98 |  | 
 | 99 |  | 
 | 100 | llvm::Type* IRBuilder::getJTypeInArraySpace(JType jty) { | 
 | 101 |   switch (jty) { | 
 | 102 |   case kVoid: | 
 | 103 |     return NULL; | 
 | 104 |  | 
 | 105 |   case kBoolean: | 
 | 106 |   case kByte: | 
 | 107 |     return getInt8Ty(); | 
 | 108 |  | 
 | 109 |   case kChar: | 
 | 110 |   case kShort: | 
 | 111 |     return getInt16Ty(); | 
 | 112 |  | 
 | 113 |   case kInt: | 
 | 114 |     return getInt32Ty(); | 
 | 115 |  | 
 | 116 |   case kLong: | 
 | 117 |     return getInt64Ty(); | 
 | 118 |  | 
 | 119 |   case kFloat: | 
 | 120 |     return getFloatTy(); | 
 | 121 |  | 
 | 122 |   case kDouble: | 
 | 123 |     return getDoubleTy(); | 
 | 124 |  | 
 | 125 |   case kObject: | 
 | 126 |     return getJObjectTy(); | 
 | 127 |   } | 
 | 128 |  | 
 | 129 |   return NULL; | 
 | 130 | } |