blob: 2b8f9839385d3c52e3133692aa4352ed6ece5c30 [file] [log] [blame]
TDYa127aba61122012-05-04 18:28:36 -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 "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
27namespace art {
28namespace compiler_llvm {
29
30
31llvm::MDNode* TBAAInfo::GetRootType() {
32 if (root_ == NULL) {
33 root_ = GenTBAANode("Art TBAA Root");
34 }
35 return root_;
36}
37
38llvm::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;
51 case kTBAARuntimeInfo: spec_ty = GenTBAANode("RuntimeInfo", GetRootType()); break;
52 case kTBAAConstJObject: spec_ty = GenTBAANode("ConstJObject", GetRootType(), true); break;
53 default:
54 LOG(FATAL) << "Unknown TBAA special type: " << sty_id;
55 break;
56 }
57 }
58 return spec_ty;
59}
60
61llvm::MDNode* TBAAInfo::GenTBAANode(llvm::StringRef name, llvm::MDNode* parent, bool read_only) {
62 llvm::SmallVector<llvm::Value*, 3> array_ref;
63
64 array_ref.push_back(llvm::MDString::get(context_, name));
65 if (parent != NULL) {
66 array_ref.push_back(parent);
67 }
68 if (read_only != false) {
69 array_ref.push_back(llvm::ConstantInt::get(llvm::Type::getInt1Ty(context_), read_only));
70 }
71
72 return llvm::MDNode::get(context_, array_ref);
73}
74
75
76} // namespace compiler_llvm
77} // namespace art