Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:12

0001 //===- llvm/Analysis/DomConditionCache.h ------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // Cache for branch conditions that affect a certain value for use by
0010 // ValueTracking. Unlike AssumptionCache, this class does not perform any
0011 // automatic analysis or invalidation. The caller is responsible for registering
0012 // all relevant branches (and re-registering them if they change), and for
0013 // removing invalidated values from the cache.
0014 //
0015 //===----------------------------------------------------------------------===//
0016 
0017 #ifndef LLVM_ANALYSIS_DOMCONDITIONCACHE_H
0018 #define LLVM_ANALYSIS_DOMCONDITIONCACHE_H
0019 
0020 #include "llvm/ADT/ArrayRef.h"
0021 #include "llvm/ADT/DenseMap.h"
0022 #include "llvm/ADT/SmallVector.h"
0023 
0024 namespace llvm {
0025 
0026 class Value;
0027 class BranchInst;
0028 
0029 class DomConditionCache {
0030 private:
0031   /// A map of values about which a branch might be providing information.
0032   using AffectedValuesMap = DenseMap<Value *, SmallVector<BranchInst *, 1>>;
0033   AffectedValuesMap AffectedValues;
0034 
0035 public:
0036   /// Add a branch condition to the cache.
0037   void registerBranch(BranchInst *BI);
0038 
0039   /// Remove a value from the cache, e.g. because it will be erased.
0040   void removeValue(Value *V) { AffectedValues.erase(V); }
0041 
0042   /// Access the list of branches which affect this value.
0043   ArrayRef<BranchInst *> conditionsFor(const Value *V) const {
0044     auto AVI = AffectedValues.find_as(const_cast<Value *>(V));
0045     if (AVI == AffectedValues.end())
0046       return ArrayRef<BranchInst *>();
0047 
0048     return AVI->second;
0049   }
0050 };
0051 
0052 } // end namespace llvm
0053 
0054 #endif // LLVM_ANALYSIS_DOMCONDITIONCACHE_H