blob: 4331557a4a12bd4fd375c269e0f3e072fa37b140 [file] [log] [blame]
TDYa1271f196f12012-07-11 20:50:22 -07001/*
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 "md_builder.h"
19
Brian Carlstrom37d48792013-03-22 14:14:45 -070020#include "llvm/IR/MDBuilder.h"
TDYa1271f196f12012-07-11 20:50:22 -070021
22#include <string>
23
24namespace art {
Ian Rogers4c1c2832013-03-04 18:30:13 -080025namespace llvm {
TDYa1271f196f12012-07-11 20:50:22 -070026
27
Ian Rogers4c1c2832013-03-04 18:30:13 -080028::llvm::MDNode* MDBuilder::GetTBAASpecialType(TBAASpecialType sty_id) {
TDYa1271f196f12012-07-11 20:50:22 -070029 DCHECK_GE(sty_id, 0) << "Unknown TBAA special type: " << sty_id;
30 DCHECK_LT(sty_id, MAX_TBAA_SPECIAL_TYPE) << "Unknown TBAA special type: " << sty_id;
31 DCHECK(tbaa_root_ != NULL);
32
Ian Rogers4c1c2832013-03-04 18:30:13 -080033 ::llvm::MDNode*& spec_ty = tbaa_special_type_[sty_id];
TDYa1271f196f12012-07-11 20:50:22 -070034 if (spec_ty == NULL) {
35 switch (sty_id) {
Brian Carlstromf69863b2013-07-17 21:53:13 -070036 case kTBAARegister:
37 spec_ty = createTBAANode("Register", tbaa_root_);
38 break;
39 case kTBAAStackTemp:
40 spec_ty = createTBAANode("StackTemp", tbaa_root_);
41 break;
42 case kTBAAHeapArray:
43 spec_ty = createTBAANode("HeapArray", tbaa_root_);
44 break;
45 case kTBAAHeapInstance:
46 spec_ty = createTBAANode("HeapInstance", tbaa_root_);
47 break;
48 case kTBAAHeapStatic:
49 spec_ty = createTBAANode("HeapStatic", tbaa_root_);
50 break;
51 case kTBAAJRuntime:
52 spec_ty = createTBAANode("JRuntime", tbaa_root_);
53 break;
54 case kTBAARuntimeInfo:
55 spec_ty = createTBAANode("RuntimeInfo", GetTBAASpecialType(kTBAAJRuntime));
56 break;
57 case kTBAAShadowFrame:
58 spec_ty = createTBAANode("ShadowFrame", GetTBAASpecialType(kTBAAJRuntime));
59 break;
60 case kTBAAConstJObject:
61 spec_ty = createTBAANode("ConstJObject", tbaa_root_, true);
62 break;
TDYa1271f196f12012-07-11 20:50:22 -070063 default:
64 LOG(FATAL) << "Unknown TBAA special type: " << sty_id;
65 break;
66 }
67 }
68 return spec_ty;
69}
70
Ian Rogers4c1c2832013-03-04 18:30:13 -080071::llvm::MDNode* MDBuilder::GetTBAAMemoryJType(TBAASpecialType sty_id, JType jty_id) {
TDYa1271f196f12012-07-11 20:50:22 -070072 DCHECK(sty_id == kTBAAHeapArray ||
73 sty_id == kTBAAHeapInstance ||
74 sty_id == kTBAAHeapStatic) << "SpecialType must be array, instance, or static";
75
76 DCHECK_GE(jty_id, 0) << "Unknown JType: " << jty_id;
77 DCHECK_LT(jty_id, MAX_JTYPE) << "Unknown JType: " << jty_id;
78 DCHECK_NE(jty_id, kVoid) << "Can't load/store Void type!";
79
80 std::string name;
81 size_t sty_mapped_index = 0;
82 switch (sty_id) {
83 case kTBAAHeapArray: sty_mapped_index = 0; name = "HeapArray "; break;
84 case kTBAAHeapInstance: sty_mapped_index = 1; name = "HeapInstance "; break;
85 case kTBAAHeapStatic: sty_mapped_index = 2; name = "HeapStatic "; break;
86 default:
87 LOG(FATAL) << "Unknown TBAA special type: " << sty_id;
88 break;
89 }
90
Ian Rogers4c1c2832013-03-04 18:30:13 -080091 ::llvm::MDNode*& spec_ty = tbaa_memory_jtype_[sty_mapped_index][jty_id];
TDYa1271f196f12012-07-11 20:50:22 -070092 if (spec_ty != NULL) {
93 return spec_ty;
94 }
95
96 switch (jty_id) {
97 case kBoolean: name += "Boolean"; break;
98 case kByte: name += "Byte"; break;
99 case kChar: name += "Char"; break;
100 case kShort: name += "Short"; break;
101 case kInt: name += "Int"; break;
102 case kLong: name += "Long"; break;
103 case kFloat: name += "Float"; break;
104 case kDouble: name += "Double"; break;
105 case kObject: name += "Object"; break;
106 default:
107 LOG(FATAL) << "Unknown JType: " << jty_id;
108 break;
109 }
110
111 spec_ty = createTBAANode(name, GetTBAASpecialType(sty_id));
112 return spec_ty;
113}
114
115
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700116} // namespace llvm
117} // namespace art