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