AliasAnalysisEvaluator.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. #include "llvm/Pass.h"
  33. namespace llvm {
  34. class AAResults;
  35. class AAEvaluator : public PassInfoMixin<AAEvaluator> {
  36. int64_t FunctionCount = 0;
  37. int64_t NoAliasCount = 0, MayAliasCount = 0, PartialAliasCount = 0;
  38. int64_t MustAliasCount = 0;
  39. int64_t NoModRefCount = 0, ModCount = 0, RefCount = 0, ModRefCount = 0;
  40. int64_t MustCount = 0, MustRefCount = 0, MustModCount = 0;
  41. int64_t MustModRefCount = 0;
  42. public:
  43. AAEvaluator() = default;
  44. AAEvaluator(AAEvaluator &&Arg)
  45. : FunctionCount(Arg.FunctionCount), NoAliasCount(Arg.NoAliasCount),
  46. MayAliasCount(Arg.MayAliasCount),
  47. PartialAliasCount(Arg.PartialAliasCount),
  48. MustAliasCount(Arg.MustAliasCount), NoModRefCount(Arg.NoModRefCount),
  49. ModCount(Arg.ModCount), RefCount(Arg.RefCount),
  50. ModRefCount(Arg.ModRefCount), MustCount(Arg.MustCount),
  51. MustRefCount(Arg.MustRefCount), MustModCount(Arg.MustModCount),
  52. MustModRefCount(Arg.MustModRefCount) {
  53. Arg.FunctionCount = 0;
  54. }
  55. ~AAEvaluator();
  56. /// Run the pass over the function.
  57. PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
  58. private:
  59. // Allow the legacy pass to run this using an internal API.
  60. friend class AAEvalLegacyPass;
  61. void runInternal(Function &F, AAResults &AA);
  62. };
  63. /// Create a wrapper of the above for the legacy pass manager.
  64. FunctionPass *createAAEvalPass();
  65. }
  66. #endif
  67. #ifdef __GNUC__
  68. #pragma GCC diagnostic pop
  69. #endif