1 //===- llvm/Analysis/EphemeralValuesCache.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 // This pass caches ephemeral values, i.e., values that are only used by 10 // @llvm.assume intrinsics, for cheap access after the initial collection. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef LLVM_ANALYSIS_EPHEMERALVALUESCACHE_H 15 #define LLVM_ANALYSIS_EPHEMERALVALUESCACHE_H 16 17 #include "llvm/ADT/SmallPtrSet.h" 18 #include "llvm/IR/PassManager.h" 19 #include "llvm/Support/Compiler.h" 20 21 namespace llvm { 22 23 class Function; 24 class AssumptionCache; 25 class Value; 26 27 /// A cache of ephemeral values within a function. 28 class EphemeralValuesCache { 29 SmallPtrSet<const Value *, 32> EphValues; 30 Function &F; 31 AssumptionCache &AC; 32 bool Collected = false; 33 34 LLVM_ABI void collectEphemeralValues(); 35 36 public: EphemeralValuesCache(Function & F,AssumptionCache & AC)37 EphemeralValuesCache(Function &F, AssumptionCache &AC) : F(F), AC(AC) {} clear()38 void clear() { 39 EphValues.clear(); 40 Collected = false; 41 } ephValues()42 const SmallPtrSetImpl<const Value *> &ephValues() { 43 if (!Collected) 44 collectEphemeralValues(); 45 return EphValues; 46 } 47 }; 48 49 class EphemeralValuesAnalysis 50 : public AnalysisInfoMixin<EphemeralValuesAnalysis> { 51 friend AnalysisInfoMixin<EphemeralValuesAnalysis>; 52 LLVM_ABI static AnalysisKey Key; 53 54 public: 55 using Result = EphemeralValuesCache; 56 LLVM_ABI Result run(Function &F, FunctionAnalysisManager &FAM); 57 }; 58 59 } // namespace llvm 60 61 #endif // LLVM_ANALYSIS_EPHEMERALVALUESCACHE_H 62