Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:19

0001 //===- TypeBasedAliasAnalysis.h - Type-Based Alias Analysis -----*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 /// \file
0010 /// This is the interface for a metadata-based TBAA. See the source file for
0011 /// details on the algorithm.
0012 //
0013 //===----------------------------------------------------------------------===//
0014 
0015 #ifndef LLVM_ANALYSIS_TYPEBASEDALIASANALYSIS_H
0016 #define LLVM_ANALYSIS_TYPEBASEDALIASANALYSIS_H
0017 
0018 #include "llvm/Analysis/AliasAnalysis.h"
0019 #include "llvm/IR/PassManager.h"
0020 #include "llvm/Pass.h"
0021 #include <memory>
0022 
0023 namespace llvm {
0024 
0025 class CallBase;
0026 class Function;
0027 class MDNode;
0028 class MemoryLocation;
0029 
0030 /// A simple AA result that uses TBAA metadata to answer queries.
0031 class TypeBasedAAResult : public AAResultBase {
0032   /// True if type sanitizer is enabled. When TypeSanitizer is used, don't use
0033   /// TBAA information for alias analysis as  this might cause us to remove
0034   /// memory accesses that we need to verify at runtime.
0035   bool UsingTypeSanitizer;
0036 
0037 public:
0038   TypeBasedAAResult(bool UsingTypeSanitizer)
0039       : UsingTypeSanitizer(UsingTypeSanitizer) {}
0040 
0041   /// Handle invalidation events from the new pass manager.
0042   ///
0043   /// By definition, this result is stateless and so remains valid.
0044   bool invalidate(Function &, const PreservedAnalyses &,
0045                   FunctionAnalysisManager::Invalidator &) {
0046     return false;
0047   }
0048 
0049   AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB,
0050                     AAQueryInfo &AAQI, const Instruction *CtxI);
0051   ModRefInfo getModRefInfoMask(const MemoryLocation &Loc, AAQueryInfo &AAQI,
0052                                bool IgnoreLocals);
0053 
0054   MemoryEffects getMemoryEffects(const CallBase *Call, AAQueryInfo &AAQI);
0055   MemoryEffects getMemoryEffects(const Function *F);
0056   ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc,
0057                            AAQueryInfo &AAQI);
0058   ModRefInfo getModRefInfo(const CallBase *Call1, const CallBase *Call2,
0059                            AAQueryInfo &AAQI);
0060 
0061 private:
0062   bool Aliases(const MDNode *A, const MDNode *B) const;
0063 
0064   /// Returns true if TBAA metadata should be used, that is if TBAA is enabled
0065   /// and type sanitizer is not used.
0066   bool shouldUseTBAA() const;
0067 };
0068 
0069 /// Analysis pass providing a never-invalidated alias analysis result.
0070 class TypeBasedAA : public AnalysisInfoMixin<TypeBasedAA> {
0071   friend AnalysisInfoMixin<TypeBasedAA>;
0072 
0073   static AnalysisKey Key;
0074 
0075 public:
0076   using Result = TypeBasedAAResult;
0077 
0078   TypeBasedAAResult run(Function &F, FunctionAnalysisManager &AM);
0079 };
0080 
0081 /// Legacy wrapper pass to provide the TypeBasedAAResult object.
0082 class TypeBasedAAWrapperPass : public ImmutablePass {
0083   std::unique_ptr<TypeBasedAAResult> Result;
0084 
0085 public:
0086   static char ID;
0087 
0088   TypeBasedAAWrapperPass();
0089 
0090   TypeBasedAAResult &getResult() { return *Result; }
0091   const TypeBasedAAResult &getResult() const { return *Result; }
0092 
0093   bool doInitialization(Module &M) override;
0094   bool doFinalization(Module &M) override;
0095   void getAnalysisUsage(AnalysisUsage &AU) const override;
0096 };
0097 
0098 //===--------------------------------------------------------------------===//
0099 //
0100 // createTypeBasedAAWrapperPass - This pass implements metadata-based
0101 // type-based alias analysis.
0102 //
0103 ImmutablePass *createTypeBasedAAWrapperPass();
0104 
0105 } // end namespace llvm
0106 
0107 #endif // LLVM_ANALYSIS_TYPEBASEDALIASANALYSIS_H