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 #ifndef ART_COMPILER_LLVM_MD_BUILDER_H_ 18 #define ART_COMPILER_LLVM_MD_BUILDER_H_ 19 20 #include "backend_types.h" 21 22 #include "llvm/IR/MDBuilder.h" 23 24 #include <cstring> 25 26 namespace llvm { 27 class LLVMContext; 28 class MDNode; 29 } 30 31 namespace art { 32 namespace llvm { 33 34 typedef ::llvm::MDBuilder LLVMMDBuilder; 35 36 class MDBuilder : public LLVMMDBuilder { 37 public: MDBuilder(::llvm::LLVMContext & context)38 explicit MDBuilder(::llvm::LLVMContext& context) 39 : LLVMMDBuilder(context), tbaa_root_(createTBAARoot("Art TBAA Root")) { 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 49 ::llvm::MDNode* GetTBAASpecialType(TBAASpecialType special_ty); 50 ::llvm::MDNode* GetTBAAMemoryJType(TBAASpecialType special_ty, JType j_ty); 51 GetBranchWeights(ExpectCond expect)52 ::llvm::MDNode* GetBranchWeights(ExpectCond expect) { 53 DCHECK_LT(expect, MAX_EXPECT) << "MAX_EXPECT is not for branch weight"; 54 return expect_cond_[expect]; 55 } 56 57 private: 58 ::llvm::MDNode* const tbaa_root_; 59 ::llvm::MDNode* tbaa_special_type_[MAX_TBAA_SPECIAL_TYPE]; 60 // There are 3 categories of memory types will not alias: array element, instance field, and 61 // static field. 62 ::llvm::MDNode* tbaa_memory_jtype_[3][MAX_JTYPE]; 63 64 ::llvm::MDNode* expect_cond_[MAX_EXPECT]; 65 }; 66 67 68 } // namespace llvm 69 } // namespace art 70 71 #endif // ART_COMPILER_LLVM_MD_BUILDER_H_ 72