TDYa127 | 1f196f1 | 2012-07-11 20:50:22 -0700 | [diff] [blame] | 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 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_COMPILER_LLVM_MD_BUILDER_H_ |
| 18 | #define ART_COMPILER_LLVM_MD_BUILDER_H_ |
TDYa127 | 1f196f1 | 2012-07-11 20:50:22 -0700 | [diff] [blame] | 19 | |
| 20 | #include "backend_types.h" |
| 21 | |
Brian Carlstrom | 37d4879 | 2013-03-22 14:14:45 -0700 | [diff] [blame] | 22 | #include "llvm/IR/MDBuilder.h" |
TDYa127 | 1f196f1 | 2012-07-11 20:50:22 -0700 | [diff] [blame] | 23 | |
| 24 | #include <cstring> |
| 25 | |
| 26 | namespace llvm { |
| 27 | class LLVMContext; |
| 28 | class MDNode; |
| 29 | } |
| 30 | |
| 31 | namespace art { |
Ian Rogers | 4c1c283 | 2013-03-04 18:30:13 -0800 | [diff] [blame] | 32 | namespace llvm { |
TDYa127 | 1f196f1 | 2012-07-11 20:50:22 -0700 | [diff] [blame] | 33 | |
Ian Rogers | 4c1c283 | 2013-03-04 18:30:13 -0800 | [diff] [blame] | 34 | typedef ::llvm::MDBuilder LLVMMDBuilder; |
TDYa127 | 1f196f1 | 2012-07-11 20:50:22 -0700 | [diff] [blame] | 35 | |
| 36 | class MDBuilder : public LLVMMDBuilder { |
| 37 | public: |
Brian Carlstrom | 93ba893 | 2013-07-17 21:31:49 -0700 | [diff] [blame] | 38 | explicit MDBuilder(::llvm::LLVMContext& context) |
Ian Rogers | 4c1c283 | 2013-03-04 18:30:13 -0800 | [diff] [blame] | 39 | : LLVMMDBuilder(context), tbaa_root_(createTBAARoot("Art TBAA Root")) { |
TDYa127 | 1f196f1 | 2012-07-11 20:50:22 -0700 | [diff] [blame] | 40 | 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 Rogers | 4c1c283 | 2013-03-04 18:30:13 -0800 | [diff] [blame] | 49 | ::llvm::MDNode* GetTBAASpecialType(TBAASpecialType special_ty); |
| 50 | ::llvm::MDNode* GetTBAAMemoryJType(TBAASpecialType special_ty, JType j_ty); |
TDYa127 | 1f196f1 | 2012-07-11 20:50:22 -0700 | [diff] [blame] | 51 | |
Ian Rogers | 4c1c283 | 2013-03-04 18:30:13 -0800 | [diff] [blame] | 52 | ::llvm::MDNode* GetBranchWeights(ExpectCond expect) { |
TDYa127 | 1f196f1 | 2012-07-11 20:50:22 -0700 | [diff] [blame] | 53 | DCHECK_LT(expect, MAX_EXPECT) << "MAX_EXPECT is not for branch weight"; |
| 54 | return expect_cond_[expect]; |
| 55 | } |
| 56 | |
| 57 | private: |
Ian Rogers | 4c1c283 | 2013-03-04 18:30:13 -0800 | [diff] [blame] | 58 | ::llvm::MDNode* const tbaa_root_; |
| 59 | ::llvm::MDNode* tbaa_special_type_[MAX_TBAA_SPECIAL_TYPE]; |
TDYa127 | 1f196f1 | 2012-07-11 20:50:22 -0700 | [diff] [blame] | 60 | // There are 3 categories of memory types will not alias: array element, instance field, and |
| 61 | // static field. |
Ian Rogers | 4c1c283 | 2013-03-04 18:30:13 -0800 | [diff] [blame] | 62 | ::llvm::MDNode* tbaa_memory_jtype_[3][MAX_JTYPE]; |
TDYa127 | 1f196f1 | 2012-07-11 20:50:22 -0700 | [diff] [blame] | 63 | |
Ian Rogers | 4c1c283 | 2013-03-04 18:30:13 -0800 | [diff] [blame] | 64 | ::llvm::MDNode* expect_cond_[MAX_EXPECT]; |
TDYa127 | 1f196f1 | 2012-07-11 20:50:22 -0700 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 68 | } // namespace llvm |
| 69 | } // namespace art |
TDYa127 | 1f196f1 | 2012-07-11 20:50:22 -0700 | [diff] [blame] | 70 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 71 | #endif // ART_COMPILER_LLVM_MD_BUILDER_H_ |