Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 1 | //=- CFLAliasAnalysisUtils.h - Utilities for CFL Alias Analysis ----*- C++-*-=// |
| 2 | // |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 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 |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 6 | // |
| 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 | |
| 20 | namespace llvm { |
| 21 | namespace cflaa { |
| 22 | |
| 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); |
| 28 | } |
| 29 | |
| 30 | void deleted() override { removeSelfFromCache(); } |
| 31 | void allUsesReplacedWith(Value *) override { removeSelfFromCache(); } |
| 32 | |
| 33 | private: |
| 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 | |
| 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(); |
| 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 |