AliasAnalysisEvaluator.h 2.7 KB

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