blob: 1246f9bd2b9f96716f33d7c1b0377d7e0be2e1a2 [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
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_COMPILER_LLVM_MD_BUILDER_H_
18#define ART_COMPILER_LLVM_MD_BUILDER_H_
TDYa1271f196f12012-07-11 20:50:22 -070019
20#include "backend_types.h"
21
Brian Carlstrom37d48792013-03-22 14:14:45 -070022#include "llvm/IR/MDBuilder.h"
TDYa1271f196f12012-07-11 20:50:22 -070023
24#include <cstring>
25
26namespace llvm {
27 class LLVMContext;
28 class MDNode;
29}
30
31namespace art {
Ian Rogers4c1c2832013-03-04 18:30:13 -080032namespace llvm {
TDYa1271f196f12012-07-11 20:50:22 -070033
Ian Rogers4c1c2832013-03-04 18:30:13 -080034typedef ::llvm::MDBuilder LLVMMDBuilder;
TDYa1271f196f12012-07-11 20:50:22 -070035
36class MDBuilder : public LLVMMDBuilder {
37 public:
Brian Carlstrom93ba8932013-07-17 21:31:49 -070038 explicit MDBuilder(::llvm::LLVMContext& context)
Ian Rogers4c1c2832013-03-04 18:30:13 -080039 : LLVMMDBuilder(context), tbaa_root_(createTBAARoot("Art TBAA Root")) {
TDYa1271f196f12012-07-11 20:50:22 -070040 std::memset(tbaa_special_type_, 0, sizeof(tbaa_special_type_));
41 std::memset(tbaa_memory_jtype_, 0, sizeof(tbaa_memory_jtype_));
42
43 // Pre-generate the MDNode for static branch prediction
44 // 64 and 4 are the llvm.expect's default values
45 expect_cond_[kLikely] = createBranchWeights(64, 4);
46 expect_cond_[kUnlikely] = createBranchWeights(4, 64);
47 }
48
Ian Rogers4c1c2832013-03-04 18:30:13 -080049 ::llvm::MDNode* GetTBAASpecialType(TBAASpecialType special_ty);
50 ::llvm::MDNode* GetTBAAMemoryJType(TBAASpecialType special_ty, JType j_ty);
TDYa1271f196f12012-07-11 20:50:22 -070051
Ian Rogers4c1c2832013-03-04 18:30:13 -080052 ::llvm::MDNode* GetBranchWeights(ExpectCond expect) {
TDYa1271f196f12012-07-11 20:50:22 -070053 DCHECK_LT(expect, MAX_EXPECT) << "MAX_EXPECT is not for branch weight";
54 return expect_cond_[expect];
55 }
56
57 private:
Ian Rogers4c1c2832013-03-04 18:30:13 -080058 ::llvm::MDNode* const tbaa_root_;
59 ::llvm::MDNode* tbaa_special_type_[MAX_TBAA_SPECIAL_TYPE];
TDYa1271f196f12012-07-11 20:50:22 -070060 // There are 3 categories of memory types will not alias: array element, instance field, and
61 // static field.
Ian Rogers4c1c2832013-03-04 18:30:13 -080062 ::llvm::MDNode* tbaa_memory_jtype_[3][MAX_JTYPE];
TDYa1271f196f12012-07-11 20:50:22 -070063
Ian Rogers4c1c2832013-03-04 18:30:13 -080064 ::llvm::MDNode* expect_cond_[MAX_EXPECT];
TDYa1271f196f12012-07-11 20:50:22 -070065};
66
67
Brian Carlstrom7934ac22013-07-26 10:54:15 -070068} // namespace llvm
69} // namespace art
TDYa1271f196f12012-07-11 20:50:22 -070070
Brian Carlstromfc0e3212013-07-17 14:40:12 -070071#endif // ART_COMPILER_LLVM_MD_BUILDER_H_