1 //=- CFLAliasAnalysisUtils.h - Utilities for CFL Alias Analysis ----*- C++-*-=//
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
7 //===----------------------------------------------------------------------===//
9 // These are the utilities/helpers used by the CFL Alias Analyses available in
10 // tree, i.e. Steensgaard's and Andersens'.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_ANALYSIS_CFLALIASANALYSISUTILS_H
15 #define LLVM_ANALYSIS_CFLALIASANALYSISUTILS_H
17 #include "llvm/IR/Function.h"
18 #include "llvm/IR/ValueHandle.h"
23 template <typename AAResult
> struct FunctionHandle final
: public CallbackVH
{
24 FunctionHandle(Function
*Fn
, AAResult
*Result
)
25 : CallbackVH(Fn
), Result(Result
) {
26 assert(Fn
!= nullptr);
27 assert(Result
!= nullptr);
30 void deleted() override
{ removeSelfFromCache(); }
31 void allUsesReplacedWith(Value
*) override
{ removeSelfFromCache(); }
36 void removeSelfFromCache() {
37 assert(Result
!= nullptr);
38 auto *Val
= getValPtr();
39 Result
->evict(cast
<Function
>(Val
));
44 static inline const Function
*parentFunctionOfValue(const Value
*Val
) {
45 if (auto *Inst
= dyn_cast
<Instruction
>(Val
)) {
46 auto *Bb
= Inst
->getParent();
47 return Bb
->getParent();
50 if (auto *Arg
= dyn_cast
<Argument
>(Val
))
51 return Arg
->getParent();
57 #endif // LLVM_ANALYSIS_CFLALIASANALYSISUTILS_H