1//===- TypeBasedAliasAnalysis.h - Type-Based 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//
9/// \file
10/// This is the interface for a metadata-based TBAA. See the source file for
11/// details on the algorithm.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_ANALYSIS_TYPEBASEDALIASANALYSIS_H
16#define LLVM_ANALYSIS_TYPEBASEDALIASANALYSIS_H
17
18#include "llvm/Analysis/AliasAnalysis.h"
19#include "llvm/IR/PassManager.h"
20#include "llvm/Pass.h"
21#include <memory>
22
23namespace llvm {
24
25class CallBase;
26class Function;
27class MDNode;
28class MemoryLocation;
29
30/// A simple AA result that uses TBAA metadata to answer queries.
31class TypeBasedAAResult : public AAResultBase<TypeBasedAAResult> {
32  friend AAResultBase<TypeBasedAAResult>;
33
34public:
35  /// Handle invalidation events from the new pass manager.
36  ///
37  /// By definition, this result is stateless and so remains valid.
38  bool invalidate(Function &, const PreservedAnalyses &,
39                  FunctionAnalysisManager::Invalidator &) {
40    return false;
41  }
42
43  AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB,
44                    AAQueryInfo &AAQI);
45  bool pointsToConstantMemory(const MemoryLocation &Loc, AAQueryInfo &AAQI,
46                              bool OrLocal);
47  FunctionModRefBehavior getModRefBehavior(const CallBase *Call);
48  FunctionModRefBehavior getModRefBehavior(const Function *F);
49  ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc,
50                           AAQueryInfo &AAQI);
51  ModRefInfo getModRefInfo(const CallBase *Call1, const CallBase *Call2,
52                           AAQueryInfo &AAQI);
53
54private:
55  bool Aliases(const MDNode *A, const MDNode *B) const;
56};
57
58/// Analysis pass providing a never-invalidated alias analysis result.
59class TypeBasedAA : public AnalysisInfoMixin<TypeBasedAA> {
60  friend AnalysisInfoMixin<TypeBasedAA>;
61
62  static AnalysisKey Key;
63
64public:
65  using Result = TypeBasedAAResult;
66
67  TypeBasedAAResult run(Function &F, FunctionAnalysisManager &AM);
68};
69
70/// Legacy wrapper pass to provide the TypeBasedAAResult object.
71class TypeBasedAAWrapperPass : public ImmutablePass {
72  std::unique_ptr<TypeBasedAAResult> Result;
73
74public:
75  static char ID;
76
77  TypeBasedAAWrapperPass();
78
79  TypeBasedAAResult &getResult() { return *Result; }
80  const TypeBasedAAResult &getResult() const { return *Result; }
81
82  bool doInitialization(Module &M) override;
83  bool doFinalization(Module &M) override;
84  void getAnalysisUsage(AnalysisUsage &AU) const override;
85};
86
87//===--------------------------------------------------------------------===//
88//
89// createTypeBasedAAWrapperPass - This pass implements metadata-based
90// type-based alias analysis.
91//
92ImmutablePass *createTypeBasedAAWrapperPass();
93
94} // end namespace llvm
95
96#endif // LLVM_ANALYSIS_TYPEBASEDALIASANALYSIS_H
97