CFLAliasAnalysisUtils.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //=- CFLAliasAnalysisUtils.h - Utilities for CFL Alias Analysis ----*- C++-*-=//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. // \file
  14. // These are the utilities/helpers used by the CFL Alias Analyses available in
  15. // tree, i.e. Steensgaard's and Andersens'.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_ANALYSIS_CFLALIASANALYSISUTILS_H
  19. #define LLVM_ANALYSIS_CFLALIASANALYSISUTILS_H
  20. #include "llvm/IR/Function.h"
  21. #include "llvm/IR/ValueHandle.h"
  22. namespace llvm {
  23. namespace cflaa {
  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);
  29. }
  30. void deleted() override { removeSelfFromCache(); }
  31. void allUsesReplacedWith(Value *) override { removeSelfFromCache(); }
  32. private:
  33. AAResult *Result;
  34. void removeSelfFromCache() {
  35. assert(Result != nullptr);
  36. auto *Val = getValPtr();
  37. Result->evict(cast<Function>(Val));
  38. setValPtr(nullptr);
  39. }
  40. };
  41. static inline const Function *parentFunctionOfValue(const Value *Val) {
  42. if (auto *Inst = dyn_cast<Instruction>(Val)) {
  43. auto *Bb = Inst->getParent();
  44. return Bb->getParent();
  45. }
  46. if (auto *Arg = dyn_cast<Argument>(Val))
  47. return Arg->getParent();
  48. return nullptr;
  49. } // namespace cflaa
  50. } // namespace llvm
  51. }
  52. #endif // LLVM_ANALYSIS_CFLALIASANALYSISUTILS_H
  53. #ifdef __GNUC__
  54. #pragma GCC diagnostic pop
  55. #endif