• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "md_builder.h"
19 
20 #include "llvm/IR/MDBuilder.h"
21 
22 #include <string>
23 
24 namespace art {
25 namespace llvm {
26 
27 
GetTBAASpecialType(TBAASpecialType sty_id)28 ::llvm::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:
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;
63     default:
64       LOG(FATAL) << "Unknown TBAA special type: " << sty_id;
65       break;
66     }
67   }
68   return spec_ty;
69 }
70 
GetTBAAMemoryJType(TBAASpecialType sty_id,JType jty_id)71 ::llvm::MDNode* MDBuilder::GetTBAAMemoryJType(TBAASpecialType sty_id, JType jty_id) {
72   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 
91   ::llvm::MDNode*& spec_ty = tbaa_memory_jtype_[sty_mapped_index][jty_id];
92   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 
116 }  // namespace llvm
117 }  // namespace art
118