TDYa127 | aba6112 | 2012-05-04 18:28:36 -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 | |
| 18 | #include "tbaa_info.h" |
| 19 | |
| 20 | #include <llvm/ADT/SmallVector.h> |
| 21 | #include <llvm/ADT/StringRef.h> |
| 22 | #include <llvm/Constants.h> |
| 23 | #include <llvm/Metadata.h> |
| 24 | #include <llvm/Type.h> |
| 25 | |
| 26 | |
| 27 | namespace art { |
| 28 | namespace compiler_llvm { |
| 29 | |
| 30 | |
| 31 | llvm::MDNode* TBAAInfo::GetRootType() { |
| 32 | if (root_ == NULL) { |
| 33 | root_ = GenTBAANode("Art TBAA Root"); |
| 34 | } |
| 35 | return root_; |
| 36 | } |
| 37 | |
| 38 | llvm::MDNode* TBAAInfo::GetSpecialType(TBAASpecialType sty_id) { |
| 39 | DCHECK_GE(sty_id, 0) << "Unknown TBAA special type: " << sty_id; |
| 40 | DCHECK_LT(sty_id, MAX_TBAA_SPECIAL_TYPE) << "Unknown TBAA special type: " << sty_id; |
| 41 | |
| 42 | llvm::MDNode*& spec_ty = special_type_[sty_id]; |
| 43 | if (spec_ty == NULL) { |
| 44 | switch (sty_id) { |
| 45 | case kTBAARegister: spec_ty = GenTBAANode("Register", GetRootType()); break; |
| 46 | case kTBAAStackTemp: spec_ty = GenTBAANode("StackTemp", GetRootType()); break; |
| 47 | case kTBAAMemory: spec_ty = GenTBAANode("Memory", GetRootType()); break; |
| 48 | case kTBAAMemoryArray: spec_ty = GenTBAANode("MemoryArray", GetRootType()); break; |
| 49 | case kTBAAMemoryIdentified: spec_ty = GenTBAANode("MemoryIdentified", GetRootType()); break; |
| 50 | case kTBAAMemoryStatic: spec_ty = GenTBAANode("MemoryStatic", GetRootType()); break; |
TDYa127 | 8ca1005 | 2012-05-05 19:57:06 -0700 | [diff] [blame^] | 51 | case kTBAAJRuntime: spec_ty = GenTBAANode("JRuntime", GetRootType()); break; |
TDYa127 | aba6112 | 2012-05-04 18:28:36 -0700 | [diff] [blame] | 52 | case kTBAARuntimeInfo: spec_ty = GenTBAANode("RuntimeInfo", GetRootType()); break; |
| 53 | case kTBAAConstJObject: spec_ty = GenTBAANode("ConstJObject", GetRootType(), true); break; |
| 54 | default: |
| 55 | LOG(FATAL) << "Unknown TBAA special type: " << sty_id; |
| 56 | break; |
| 57 | } |
| 58 | } |
| 59 | return spec_ty; |
| 60 | } |
| 61 | |
| 62 | llvm::MDNode* TBAAInfo::GenTBAANode(llvm::StringRef name, llvm::MDNode* parent, bool read_only) { |
| 63 | llvm::SmallVector<llvm::Value*, 3> array_ref; |
| 64 | |
| 65 | array_ref.push_back(llvm::MDString::get(context_, name)); |
| 66 | if (parent != NULL) { |
| 67 | array_ref.push_back(parent); |
| 68 | } |
| 69 | if (read_only != false) { |
| 70 | array_ref.push_back(llvm::ConstantInt::get(llvm::Type::getInt1Ty(context_), read_only)); |
| 71 | } |
| 72 | |
| 73 | return llvm::MDNode::get(context_, array_ref); |
| 74 | } |
| 75 | |
| 76 | |
| 77 | } // namespace compiler_llvm |
| 78 | } // namespace art |