1 //=- CFLAliasAnalysisUtils.h - Utilities for CFL Alias Analysis ----*- C++-*-=// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // \file 10 // These are the utilities/helpers used by the CFL Alias Analyses available in 11 // tree, i.e. Steensgaard's and Andersens'. 12 // 13 //===----------------------------------------------------------------------===// 14 15 #ifndef LLVM_ANALYSIS_CFLALIASANALYSISUTILS_H 16 #define LLVM_ANALYSIS_CFLALIASANALYSISUTILS_H 17 18 #include "llvm/IR/Function.h" 19 #include "llvm/IR/ValueHandle.h" 20 21 namespace llvm { 22 namespace cflaa { 23 24 template <typename AAResult> struct FunctionHandle final : public CallbackVH { 25 FunctionHandle(Function *Fn, AAResult *Result) 26 : CallbackVH(Fn), Result(Result) { 27 assert(Fn != nullptr); 28 assert(Result != nullptr); 29 } 30 31 void deleted() override { removeSelfFromCache(); } 32 void allUsesReplacedWith(Value *) override { removeSelfFromCache(); } 33 34 private: 35 AAResult *Result; 36 37 void removeSelfFromCache() { 38 assert(Result != nullptr); 39 auto *Val = getValPtr(); 40 Result->evict(cast<Function>(Val)); 41 setValPtr(nullptr); 42 } 43 }; 44 45 static inline const Function *parentFunctionOfValue(const Value *Val) { 46 if (auto *Inst = dyn_cast<Instruction>(Val)) { 47 auto *Bb = Inst->getParent(); 48 return Bb->getParent(); 49 } 50 51 if (auto *Arg = dyn_cast<Argument>(Val)) 52 return Arg->getParent(); 53 return nullptr; 54 } // namespace cflaa 55 } // namespace llvm 56 } 57 58 #endif // LLVM_ANALYSIS_CFLALIASANALYSISUTILS_H 59