1 //===- ScopedNoAliasAA.h - Scoped No-Alias Alias Analysis -------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
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"
29 /// A simple AA result which uses scoped-noalias metadata to answer queries.
30 class ScopedNoAliasAAResult
: public AAResultBase
<ScopedNoAliasAAResult
> {
31 friend AAResultBase
<ScopedNoAliasAAResult
>;
34 /// Handle invalidation events from the new pass manager.
36 /// By definition, this result is stateless and so remains valid.
37 bool invalidate(Function
&, const PreservedAnalyses
&,
38 FunctionAnalysisManager::Invalidator
&) {
42 AliasResult
alias(const MemoryLocation
&LocA
, const MemoryLocation
&LocB
);
43 ModRefInfo
getModRefInfo(const CallBase
*Call
, const MemoryLocation
&Loc
);
44 ModRefInfo
getModRefInfo(const CallBase
*Call1
, const CallBase
*Call2
);
47 bool mayAliasInScopes(const MDNode
*Scopes
, const MDNode
*NoAlias
) const;
50 /// Analysis pass providing a never-invalidated alias analysis result.
51 class ScopedNoAliasAA
: public AnalysisInfoMixin
<ScopedNoAliasAA
> {
52 friend AnalysisInfoMixin
<ScopedNoAliasAA
>;
54 static AnalysisKey Key
;
57 using Result
= ScopedNoAliasAAResult
;
59 ScopedNoAliasAAResult
run(Function
&F
, FunctionAnalysisManager
&AM
);
62 /// Legacy wrapper pass to provide the ScopedNoAliasAAResult object.
63 class ScopedNoAliasAAWrapperPass
: public ImmutablePass
{
64 std::unique_ptr
<ScopedNoAliasAAResult
> Result
;
69 ScopedNoAliasAAWrapperPass();
71 ScopedNoAliasAAResult
&getResult() { return *Result
; }
72 const ScopedNoAliasAAResult
&getResult() const { return *Result
; }
74 bool doInitialization(Module
&M
) override
;
75 bool doFinalization(Module
&M
) override
;
76 void getAnalysisUsage(AnalysisUsage
&AU
) const override
;
79 //===--------------------------------------------------------------------===//
81 // createScopedNoAliasAAWrapperPass - This pass implements metadata-based
82 // scoped noalias analysis.
84 ImmutablePass
*createScopedNoAliasAAWrapperPass();
86 } // end namespace llvm
88 #endif // LLVM_ANALYSIS_SCOPEDNOALIASAA_H