blob: 657adc5f11d06839e3dde3e701e24ac2dee92a2e [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 Carlstrombd86bcc2013-03-10 20:26:16 -070020#include "llvm/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) {
36 case kTBAARegister: spec_ty = createTBAANode("Register", tbaa_root_); break;
37 case kTBAAStackTemp: spec_ty = createTBAANode("StackTemp", tbaa_root_); break;
38 case kTBAAHeapArray: spec_ty = createTBAANode("HeapArray", tbaa_root_); break;
39 case kTBAAHeapInstance: spec_ty = createTBAANode("HeapInstance", tbaa_root_); break;
40 case kTBAAHeapStatic: spec_ty = createTBAANode("HeapStatic", tbaa_root_); break;
41 case kTBAAJRuntime: spec_ty = createTBAANode("JRuntime", tbaa_root_); break;
TDYa127ce4cc0d2012-11-18 16:59:53 -080042 case kTBAARuntimeInfo: spec_ty = createTBAANode("RuntimeInfo",
43 GetTBAASpecialType(kTBAAJRuntime)); break;
44 case kTBAAShadowFrame: spec_ty = createTBAANode("ShadowFrame",
45 GetTBAASpecialType(kTBAAJRuntime)); break;
TDYa1271f196f12012-07-11 20:50:22 -070046 case kTBAAConstJObject: spec_ty = createTBAANode("ConstJObject", tbaa_root_, true); break;
47 default:
48 LOG(FATAL) << "Unknown TBAA special type: " << sty_id;
49 break;
50 }
51 }
52 return spec_ty;
53}
54
Ian Rogers4c1c2832013-03-04 18:30:13 -080055::llvm::MDNode* MDBuilder::GetTBAAMemoryJType(TBAASpecialType sty_id, JType jty_id) {
TDYa1271f196f12012-07-11 20:50:22 -070056 DCHECK(sty_id == kTBAAHeapArray ||
57 sty_id == kTBAAHeapInstance ||
58 sty_id == kTBAAHeapStatic) << "SpecialType must be array, instance, or static";
59
60 DCHECK_GE(jty_id, 0) << "Unknown JType: " << jty_id;
61 DCHECK_LT(jty_id, MAX_JTYPE) << "Unknown JType: " << jty_id;
62 DCHECK_NE(jty_id, kVoid) << "Can't load/store Void type!";
63
64 std::string name;
65 size_t sty_mapped_index = 0;
66 switch (sty_id) {
67 case kTBAAHeapArray: sty_mapped_index = 0; name = "HeapArray "; break;
68 case kTBAAHeapInstance: sty_mapped_index = 1; name = "HeapInstance "; break;
69 case kTBAAHeapStatic: sty_mapped_index = 2; name = "HeapStatic "; break;
70 default:
71 LOG(FATAL) << "Unknown TBAA special type: " << sty_id;
72 break;
73 }
74
Ian Rogers4c1c2832013-03-04 18:30:13 -080075 ::llvm::MDNode*& spec_ty = tbaa_memory_jtype_[sty_mapped_index][jty_id];
TDYa1271f196f12012-07-11 20:50:22 -070076 if (spec_ty != NULL) {
77 return spec_ty;
78 }
79
80 switch (jty_id) {
81 case kBoolean: name += "Boolean"; break;
82 case kByte: name += "Byte"; break;
83 case kChar: name += "Char"; break;
84 case kShort: name += "Short"; break;
85 case kInt: name += "Int"; break;
86 case kLong: name += "Long"; break;
87 case kFloat: name += "Float"; break;
88 case kDouble: name += "Double"; break;
89 case kObject: name += "Object"; break;
90 default:
91 LOG(FATAL) << "Unknown JType: " << jty_id;
92 break;
93 }
94
95 spec_ty = createTBAANode(name, GetTBAASpecialType(sty_id));
96 return spec_ty;
97}
98
99
Ian Rogers4c1c2832013-03-04 18:30:13 -0800100} // namespace llvm
TDYa1271f196f12012-07-11 20:50:22 -0700101} // namespace art