blob: f5232aa69c59cbecf9562d65ecab05745cbcd1bc [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
20#include "llvm/Support/MDBuilder.h"
21
22#include <string>
23
24namespace art {
25namespace compiler_llvm {
26
27
28llvm::MDNode* MDBuilder::GetTBAASpecialType(TBAASpecialType sty_id) {
29 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
33 llvm::MDNode*& spec_ty = tbaa_special_type_[sty_id];
34 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;
42 case kTBAARuntimeInfo: spec_ty = createTBAANode("RuntimeInfo", tbaa_root_); break;
43 case kTBAAShadowFrame: spec_ty = createTBAANode("ShadowFrame", tbaa_root_); break;
44 case kTBAAConstJObject: spec_ty = createTBAANode("ConstJObject", tbaa_root_, true); break;
45 default:
46 LOG(FATAL) << "Unknown TBAA special type: " << sty_id;
47 break;
48 }
49 }
50 return spec_ty;
51}
52
53llvm::MDNode* MDBuilder::GetTBAAMemoryJType(TBAASpecialType sty_id, JType jty_id) {
54 DCHECK(sty_id == kTBAAHeapArray ||
55 sty_id == kTBAAHeapInstance ||
56 sty_id == kTBAAHeapStatic) << "SpecialType must be array, instance, or static";
57
58 DCHECK_GE(jty_id, 0) << "Unknown JType: " << jty_id;
59 DCHECK_LT(jty_id, MAX_JTYPE) << "Unknown JType: " << jty_id;
60 DCHECK_NE(jty_id, kVoid) << "Can't load/store Void type!";
61
62 std::string name;
63 size_t sty_mapped_index = 0;
64 switch (sty_id) {
65 case kTBAAHeapArray: sty_mapped_index = 0; name = "HeapArray "; break;
66 case kTBAAHeapInstance: sty_mapped_index = 1; name = "HeapInstance "; break;
67 case kTBAAHeapStatic: sty_mapped_index = 2; name = "HeapStatic "; break;
68 default:
69 LOG(FATAL) << "Unknown TBAA special type: " << sty_id;
70 break;
71 }
72
73 llvm::MDNode*& spec_ty = tbaa_memory_jtype_[sty_mapped_index][jty_id];
74 if (spec_ty != NULL) {
75 return spec_ty;
76 }
77
78 switch (jty_id) {
79 case kBoolean: name += "Boolean"; break;
80 case kByte: name += "Byte"; break;
81 case kChar: name += "Char"; break;
82 case kShort: name += "Short"; break;
83 case kInt: name += "Int"; break;
84 case kLong: name += "Long"; break;
85 case kFloat: name += "Float"; break;
86 case kDouble: name += "Double"; break;
87 case kObject: name += "Object"; break;
88 default:
89 LOG(FATAL) << "Unknown JType: " << jty_id;
90 break;
91 }
92
93 spec_ty = createTBAANode(name, GetTBAASpecialType(sty_id));
94 return spec_ty;
95}
96
97
98} // namespace compiler_llvm
99} // namespace art