[Alignment][NFC] Support compile time constants
[llvm-core.git] / include / llvm / Analysis / ScopedNoAliasAA.h
blobdae733bd20152348ba5400d1a78824b6614b419e
1 //===- ScopedNoAliasAA.h - Scoped No-Alias 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 scoped no-alias analysis.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_ANALYSIS_SCOPEDNOALIASAA_H
15 #define LLVM_ANALYSIS_SCOPEDNOALIASAA_H
17 #include "llvm/Analysis/AliasAnalysis.h"
18 #include "llvm/IR/InstrTypes.h"
19 #include "llvm/IR/PassManager.h"
20 #include "llvm/Pass.h"
21 #include <memory>
23 namespace llvm {
25 class Function;
26 class MDNode;
27 class MemoryLocation;
29 /// A simple AA result which uses scoped-noalias metadata to answer queries.
30 class ScopedNoAliasAAResult : public AAResultBase<ScopedNoAliasAAResult> {
31 friend AAResultBase<ScopedNoAliasAAResult>;
33 public:
34 /// Handle invalidation events from the new pass manager.
35 ///
36 /// By definition, this result is stateless and so remains valid.
37 bool invalidate(Function &, const PreservedAnalyses &,
38 FunctionAnalysisManager::Invalidator &) {
39 return false;
42 AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB,
43 AAQueryInfo &AAQI);
44 ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc,
45 AAQueryInfo &AAQI);
46 ModRefInfo getModRefInfo(const CallBase *Call1, const CallBase *Call2,
47 AAQueryInfo &AAQI);
49 private:
50 bool mayAliasInScopes(const MDNode *Scopes, const MDNode *NoAlias) const;
53 /// Analysis pass providing a never-invalidated alias analysis result.
54 class ScopedNoAliasAA : public AnalysisInfoMixin<ScopedNoAliasAA> {
55 friend AnalysisInfoMixin<ScopedNoAliasAA>;
57 static AnalysisKey Key;
59 public:
60 using Result = ScopedNoAliasAAResult;
62 ScopedNoAliasAAResult run(Function &F, FunctionAnalysisManager &AM);
65 /// Legacy wrapper pass to provide the ScopedNoAliasAAResult object.
66 class ScopedNoAliasAAWrapperPass : public ImmutablePass {
67 std::unique_ptr<ScopedNoAliasAAResult> Result;
69 public:
70 static char ID;
72 ScopedNoAliasAAWrapperPass();
74 ScopedNoAliasAAResult &getResult() { return *Result; }
75 const ScopedNoAliasAAResult &getResult() const { return *Result; }
77 bool doInitialization(Module &M) override;
78 bool doFinalization(Module &M) override;
79 void getAnalysisUsage(AnalysisUsage &AU) const override;
82 //===--------------------------------------------------------------------===//
84 // createScopedNoAliasAAWrapperPass - This pass implements metadata-based
85 // scoped noalias analysis.
87 ImmutablePass *createScopedNoAliasAAWrapperPass();
89 } // end namespace llvm
91 #endif // LLVM_ANALYSIS_SCOPEDNOALIASAA_H