blob: 02f999a5b913d6ea3597358429b63a293baa96d9 [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//=- CFLAliasAnalysisUtils.h - Utilities for CFL Alias Analysis ----*- C++-*-=//
2//
Andrew Walbran16937d02019-10-22 13:54:20 +01003// 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
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01006//
7//===----------------------------------------------------------------------===//
8// \file
9// These are the utilities/helpers used by the CFL Alias Analyses available in
10// tree, i.e. Steensgaard's and Andersens'.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_ANALYSIS_CFLALIASANALYSISUTILS_H
15#define LLVM_ANALYSIS_CFLALIASANALYSISUTILS_H
16
17#include "llvm/IR/Function.h"
18#include "llvm/IR/ValueHandle.h"
19
20namespace llvm {
21namespace cflaa {
22
23template <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);
28 }
29
30 void deleted() override { removeSelfFromCache(); }
31 void allUsesReplacedWith(Value *) override { removeSelfFromCache(); }
32
33private:
34 AAResult *Result;
35
36 void removeSelfFromCache() {
37 assert(Result != nullptr);
38 auto *Val = getValPtr();
39 Result->evict(cast<Function>(Val));
40 setValPtr(nullptr);
41 }
42};
43
44static inline const Function *parentFunctionOfValue(const Value *Val) {
45 if (auto *Inst = dyn_cast<Instruction>(Val)) {
46 auto *Bb = Inst->getParent();
47 return Bb->getParent();
48 }
49
50 if (auto *Arg = dyn_cast<Argument>(Val))
51 return Arg->getParent();
52 return nullptr;
53} // namespace cflaa
54} // namespace llvm
55}
56
57#endif // LLVM_ANALYSIS_CFLALIASANALYSISUTILS_H