CFLAliasAnalysisUtils.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. //=- CFLAliasAnalysisUtils.h - Utilities for CFL Alias Analysis ----*- C++-*-=//
  2. //
  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
  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. #ifndef LLVM_ANALYSIS_CFLALIASANALYSISUTILS_H
  14. #define LLVM_ANALYSIS_CFLALIASANALYSISUTILS_H
  15. #include "llvm/IR/Function.h"
  16. #include "llvm/IR/ValueHandle.h"
  17. namespace llvm {
  18. namespace cflaa {
  19. template <typename AAResult> struct FunctionHandle final : public CallbackVH {
  20. FunctionHandle(Function *Fn, AAResult *Result)
  21. : CallbackVH(Fn), Result(Result) {
  22. assert(Fn != nullptr);
  23. assert(Result != nullptr);
  24. }
  25. void deleted() override { removeSelfFromCache(); }
  26. void allUsesReplacedWith(Value *) override { removeSelfFromCache(); }
  27. private:
  28. AAResult *Result;
  29. void removeSelfFromCache() {
  30. assert(Result != nullptr);
  31. auto *Val = getValPtr();
  32. Result->evict(cast<Function>(Val));
  33. setValPtr(nullptr);
  34. }
  35. };
  36. static inline const Function *parentFunctionOfValue(const Value *Val) {
  37. if (auto *Inst = dyn_cast<Instruction>(Val)) {
  38. auto *Bb = Inst->getParent();
  39. return Bb->getParent();
  40. }
  41. if (auto *Arg = dyn_cast<Argument>(Val))
  42. return Arg->getParent();
  43. return nullptr;
  44. } // namespace cflaa
  45. } // namespace llvm
  46. }
  47. #endif // LLVM_ANALYSIS_CFLALIASANALYSISUTILS_H