AliasAnalysisEvaluator.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- AliasAnalysisEvaluator.h - Alias Analysis Accuracy Evaluator -------===//
  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. ///
  15. /// This file implements a simple N^2 alias analysis accuracy evaluator. The
  16. /// analysis result is a set of statistics of how many times the AA
  17. /// infrastructure provides each kind of alias result and mod/ref result when
  18. /// queried with all pairs of pointers in the function.
  19. ///
  20. /// It can be used to evaluate a change in an alias analysis implementation,
  21. /// algorithm, or the AA pipeline infrastructure itself. It acts like a stable
  22. /// and easily tested consumer of all AA information exposed.
  23. ///
  24. /// This is inspired and adapted from code by: Naveen Neelakantam, Francesco
  25. /// Spadini, and Wojciech Stryjewski.
  26. ///
  27. //===----------------------------------------------------------------------===//
  28. #ifndef LLVM_ANALYSIS_ALIASANALYSISEVALUATOR_H
  29. #define LLVM_ANALYSIS_ALIASANALYSISEVALUATOR_H
  30. #include "llvm/IR/Function.h"
  31. #include "llvm/IR/PassManager.h"
  32. namespace llvm {
  33. class AAResults;
  34. class AAEvaluator : public PassInfoMixin<AAEvaluator> {
  35. int64_t FunctionCount;
  36. int64_t NoAliasCount, MayAliasCount, PartialAliasCount, MustAliasCount;
  37. int64_t NoModRefCount, ModCount, RefCount, ModRefCount;
  38. int64_t MustCount, MustRefCount, MustModCount, MustModRefCount;
  39. public:
  40. AAEvaluator()
  41. : FunctionCount(), NoAliasCount(), MayAliasCount(), PartialAliasCount(),
  42. MustAliasCount(), NoModRefCount(), ModCount(), RefCount(),
  43. ModRefCount(), MustCount(), MustRefCount(), MustModCount(),
  44. MustModRefCount() {}
  45. AAEvaluator(AAEvaluator &&Arg)
  46. : FunctionCount(Arg.FunctionCount), NoAliasCount(Arg.NoAliasCount),
  47. MayAliasCount(Arg.MayAliasCount),
  48. PartialAliasCount(Arg.PartialAliasCount),
  49. MustAliasCount(Arg.MustAliasCount), NoModRefCount(Arg.NoModRefCount),
  50. ModCount(Arg.ModCount), RefCount(Arg.RefCount),
  51. ModRefCount(Arg.ModRefCount), MustCount(Arg.MustCount),
  52. MustRefCount(Arg.MustRefCount), MustModCount(Arg.MustModCount),
  53. MustModRefCount(Arg.MustModRefCount) {
  54. Arg.FunctionCount = 0;
  55. }
  56. ~AAEvaluator();
  57. /// Run the pass over the function.
  58. PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
  59. private:
  60. // Allow the legacy pass to run this using an internal API.
  61. friend class AAEvalLegacyPass;
  62. void runInternal(Function &F, AAResults &AA);
  63. };
  64. /// Create a wrapper of the above for the legacy pass manager.
  65. FunctionPass *createAAEvalPass();
  66. }
  67. #endif
  68. #ifdef __GNUC__
  69. #pragma GCC diagnostic pop
  70. #endif