brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.8 KiB · bc946fa Raw
88 lines · c
1//===- ProvenanceAnalysis.h - ObjC ARC Optimization -------------*- 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-exception6//7//===----------------------------------------------------------------------===//8//9/// \file10///11/// This file declares a special form of Alias Analysis called ``Provenance12/// Analysis''. The word ``provenance'' refers to the history of the ownership13/// of an object. Thus ``Provenance Analysis'' is an analysis which attempts to14/// use various techniques to determine if locally15///16/// WARNING: This file knows about certain library functions. It recognizes them17/// by name, and hardwires knowledge of their semantics.18///19/// WARNING: This file knows about how certain Objective-C library functions are20/// used. Naive LLVM IR transformations which would otherwise be21/// behavior-preserving may break these assumptions.22//23//===----------------------------------------------------------------------===//24 25#ifndef LLVM_LIB_TRANSFORMS_OBJCARC_PROVENANCEANALYSIS_H26#define LLVM_LIB_TRANSFORMS_OBJCARC_PROVENANCEANALYSIS_H27 28#include "llvm/ADT/DenseMap.h"29#include "llvm/IR/PassManager.h"30#include "llvm/IR/ValueHandle.h"31#include <utility>32 33namespace llvm {34 35class AAResults;36class PHINode;37class SelectInst;38class Value;39 40namespace objcarc {41 42/// This is similar to BasicAliasAnalysis, and it uses many of the same43/// techniques, except it uses special ObjC-specific reasoning about pointer44/// relationships.45///46/// In this context ``Provenance'' is defined as the history of an object's47/// ownership. Thus ``Provenance Analysis'' is defined by using the notion of48/// an ``independent provenance source'' of a pointer to determine whether or49/// not two pointers have the same provenance source and thus could50/// potentially be related.51class ProvenanceAnalysis {52  AAResults *AA;53 54  using ValuePairTy = std::pair<const Value *, const Value *>;55  using CachedResultsTy = DenseMap<ValuePairTy, bool>;56 57  CachedResultsTy CachedResults;58 59  DenseMap<const Value *, std::pair<WeakVH, WeakTrackingVH>>60      UnderlyingObjCPtrCache;61 62  bool relatedCheck(const Value *A, const Value *B);63  bool relatedSelect(const SelectInst *A, const Value *B);64  bool relatedPHI(const PHINode *A, const Value *B);65 66public:67  ProvenanceAnalysis() = default;68  ProvenanceAnalysis(const ProvenanceAnalysis &) = delete;69  ProvenanceAnalysis &operator=(const ProvenanceAnalysis &) = delete;70 71  void setAA(AAResults *aa) { AA = aa; }72 73  AAResults *getAA() const { return AA; }74 75  bool related(const Value *A, const Value *B);76 77  void clear() {78    CachedResults.clear();79    UnderlyingObjCPtrCache.clear();80  }81};82 83} // end namespace objcarc84 85} // end namespace llvm86 87#endif // LLVM_LIB_TRANSFORMS_OBJCARC_PROVENANCEANALYSIS_H88