1 //===- llvm/Analysis/DomConditionCache.h ------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // Cache for branch conditions that affect a certain value for use by 10 // ValueTracking. Unlike AssumptionCache, this class does not perform any 11 // automatic analysis or invalidation. The caller is responsible for registering 12 // all relevant branches (and re-registering them if they change), and for 13 // removing invalidated values from the cache. 14 // 15 //===----------------------------------------------------------------------===// 16 17 #ifndef LLVM_ANALYSIS_DOMCONDITIONCACHE_H 18 #define LLVM_ANALYSIS_DOMCONDITIONCACHE_H 19 20 #include "llvm/ADT/ArrayRef.h" 21 #include "llvm/ADT/DenseMap.h" 22 #include "llvm/ADT/SmallVector.h" 23 24 namespace llvm { 25 26 class Value; 27 class BranchInst; 28 29 class DomConditionCache { 30 private: 31 /// A map of values about which a branch might be providing information. 32 using AffectedValuesMap = DenseMap<Value *, SmallVector<BranchInst *, 1>>; 33 AffectedValuesMap AffectedValues; 34 35 public: 36 /// Add a branch condition to the cache. 37 void registerBranch(BranchInst *BI); 38 39 /// Remove a value from the cache, e.g. because it will be erased. 40 void removeValue(Value *V) { AffectedValues.erase(V); } 41 42 /// Access the list of branches which affect this value. 43 ArrayRef<BranchInst *> conditionsFor(const Value *V) const { 44 auto AVI = AffectedValues.find_as(const_cast<Value *>(V)); 45 if (AVI == AffectedValues.end()) 46 return ArrayRef<BranchInst *>(); 47 48 return AVI->second; 49 } 50 }; 51 52 } // end namespace llvm 53 54 #endif // LLVM_ANALYSIS_DOMCONDITIONCACHE_H 55