Path: blob/main/contrib/llvm-project/llvm/lib/Transforms/ObjCARC/ProvenanceAnalysis.h
35268 views
//===- ProvenanceAnalysis.h - ObjC ARC Optimization -------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8/// \file9///10/// This file declares a special form of Alias Analysis called ``Provenance11/// Analysis''. The word ``provenance'' refers to the history of the ownership12/// of an object. Thus ``Provenance Analysis'' is an analysis which attempts to13/// use various techniques to determine if locally14///15/// WARNING: This file knows about certain library functions. It recognizes them16/// by name, and hardwires knowledge of their semantics.17///18/// WARNING: This file knows about how certain Objective-C library functions are19/// used. Naive LLVM IR transformations which would otherwise be20/// behavior-preserving may break these assumptions.21//22//===----------------------------------------------------------------------===//2324#ifndef LLVM_LIB_TRANSFORMS_OBJCARC_PROVENANCEANALYSIS_H25#define LLVM_LIB_TRANSFORMS_OBJCARC_PROVENANCEANALYSIS_H2627#include "llvm/ADT/DenseMap.h"28#include "llvm/IR/PassManager.h"29#include "llvm/IR/ValueHandle.h"30#include <utility>3132namespace llvm {3334class AAResults;35class PHINode;36class SelectInst;37class Value;3839namespace objcarc {4041/// This is similar to BasicAliasAnalysis, and it uses many of the same42/// techniques, except it uses special ObjC-specific reasoning about pointer43/// relationships.44///45/// In this context ``Provenance'' is defined as the history of an object's46/// ownership. Thus ``Provenance Analysis'' is defined by using the notion of47/// an ``independent provenance source'' of a pointer to determine whether or48/// not two pointers have the same provenance source and thus could49/// potentially be related.50class ProvenanceAnalysis {51AAResults *AA;5253using ValuePairTy = std::pair<const Value *, const Value *>;54using CachedResultsTy = DenseMap<ValuePairTy, bool>;5556CachedResultsTy CachedResults;5758DenseMap<const Value *, std::pair<WeakVH, WeakTrackingVH>>59UnderlyingObjCPtrCache;6061bool relatedCheck(const Value *A, const Value *B);62bool relatedSelect(const SelectInst *A, const Value *B);63bool relatedPHI(const PHINode *A, const Value *B);6465public:66ProvenanceAnalysis() = default;67ProvenanceAnalysis(const ProvenanceAnalysis &) = delete;68ProvenanceAnalysis &operator=(const ProvenanceAnalysis &) = delete;6970void setAA(AAResults *aa) { AA = aa; }7172AAResults *getAA() const { return AA; }7374bool related(const Value *A, const Value *B);7576void clear() {77CachedResults.clear();78UnderlyingObjCPtrCache.clear();79}80};8182} // end namespace objcarc8384} // end namespace llvm8586#endif // LLVM_LIB_TRANSFORMS_OBJCARC_PROVENANCEANALYSIS_H878889