LLVM API Documentation

CaptureTracking.h
Go to the documentation of this file.
00001 //===----- llvm/Analysis/CaptureTracking.h - Pointer capture ----*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file contains routines that help determine which pointers are captured.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_ANALYSIS_CAPTURETRACKING_H
00015 #define LLVM_ANALYSIS_CAPTURETRACKING_H
00016 
00017 namespace llvm {
00018 
00019   class Value;
00020   class Use;
00021   class Instruction;
00022   class DominatorTree;
00023 
00024   /// PointerMayBeCaptured - Return true if this pointer value may be captured
00025   /// by the enclosing function (which is required to exist).  This routine can
00026   /// be expensive, so consider caching the results.  The boolean ReturnCaptures
00027   /// specifies whether returning the value (or part of it) from the function
00028   /// counts as capturing it or not.  The boolean StoreCaptures specified
00029   /// whether storing the value (or part of it) into memory anywhere
00030   /// automatically counts as capturing it or not.
00031   bool PointerMayBeCaptured(const Value *V,
00032                             bool ReturnCaptures,
00033                             bool StoreCaptures);
00034 
00035   /// PointerMayBeCapturedBefore - Return true if this pointer value may be
00036   /// captured by the enclosing function (which is required to exist). If a
00037   /// DominatorTree is provided, only captures which happen before the given
00038   /// instruction are considered. This routine can be expensive, so consider
00039   /// caching the results.  The boolean ReturnCaptures specifies whether
00040   /// returning the value (or part of it) from the function counts as capturing
00041   /// it or not.  The boolean StoreCaptures specified whether storing the value
00042   /// (or part of it) into memory anywhere automatically counts as capturing it
00043   /// or not. Captures by the provided instruction are considered if the
00044   /// final parameter is true.
00045   bool PointerMayBeCapturedBefore(const Value *V, bool ReturnCaptures,
00046                                   bool StoreCaptures, const Instruction *I,
00047                                   DominatorTree *DT, bool IncludeI = false);
00048 
00049   /// This callback is used in conjunction with PointerMayBeCaptured. In
00050   /// addition to the interface here, you'll need to provide your own getters
00051   /// to see whether anything was captured.
00052   struct CaptureTracker {
00053     virtual ~CaptureTracker();
00054 
00055     /// tooManyUses - The depth of traversal has breached a limit. There may be
00056     /// capturing instructions that will not be passed into captured().
00057     virtual void tooManyUses() = 0;
00058 
00059     /// shouldExplore - This is the use of a value derived from the pointer.
00060     /// To prune the search (ie., assume that none of its users could possibly
00061     /// capture) return false. To search it, return true.
00062     ///
00063     /// U->getUser() is always an Instruction.
00064     virtual bool shouldExplore(const Use *U);
00065 
00066     /// captured - Information about the pointer was captured by the user of
00067     /// use U. Return true to stop the traversal or false to continue looking
00068     /// for more capturing instructions.
00069     virtual bool captured(const Use *U) = 0;
00070   };
00071 
00072   /// PointerMayBeCaptured - Visit the value and the values derived from it and
00073   /// find values which appear to be capturing the pointer value. This feeds
00074   /// results into and is controlled by the CaptureTracker object.
00075   void PointerMayBeCaptured(const Value *V, CaptureTracker *Tracker);
00076 } // end namespace llvm
00077 
00078 #endif