1 //=- CFLAliasAnalysisUtils.h - Utilities for CFL Alias Analysis ----*- C++-*-=//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // These are the utilities/helpers used by the CFL Alias Analyses available in
11 // tree, i.e. Steensgaard's and Andersens'.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_ANALYSIS_CFLALIASANALYSISUTILS_H
16 #define LLVM_ANALYSIS_CFLALIASANALYSISUTILS_H
18 #include "llvm/IR/Function.h"
19 #include "llvm/IR/ValueHandle.h"
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);
31 void deleted() override { removeSelfFromCache(); }
32 void allUsesReplacedWith(Value *) override { removeSelfFromCache(); }
37 void removeSelfFromCache() {
38 assert(Result != nullptr);
39 auto *Val = getValPtr();
40 Result->evict(cast<Function>(Val));
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();
51 if (auto *Arg = dyn_cast<Argument>(Val))
52 return Arg->getParent();
58 #endif // LLVM_ANALYSIS_CFLALIASANALYSISUTILS_H