CaptureTracking.h revision 7912ef97ffde3ab3334143ddfb4cafdf04e2ebfc
1//===----- llvm/Analysis/CaptureTracking.h - Pointer capture ----*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file contains routines that help determine which pointers are captured. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef LLVM_ANALYSIS_CAPTURETRACKING_H 15#define LLVM_ANALYSIS_CAPTURETRACKING_H 16 17#include "llvm/Constants.h" 18#include "llvm/Instructions.h" 19#include "llvm/Analysis/AliasAnalysis.h" 20#include "llvm/ADT/SmallSet.h" 21#include "llvm/ADT/SmallVector.h" 22#include "llvm/Support/CallSite.h" 23 24namespace llvm { 25 /// PointerMayBeCaptured - Return true if this pointer value may be captured 26 /// by the enclosing function (which is required to exist). This routine can 27 /// be expensive, so consider caching the results. The boolean ReturnCaptures 28 /// specifies whether returning the value (or part of it) from the function 29 /// counts as capturing it or not. The boolean StoreCaptures specified 30 /// whether storing the value (or part of it) into memory anywhere 31 /// automatically counts as capturing it or not. 32 bool PointerMayBeCaptured(const Value *V, 33 bool ReturnCaptures, 34 bool StoreCaptures); 35 36 /// This callback is used in conjunction with PointerMayBeCaptured. In 37 /// addition to the interface here, you'll need to provide your own getters 38 /// to see whether anything was captured. 39 struct CaptureTracker { 40 /// tooManyUses - The depth of traversal has breached a limit. There may be 41 /// capturing instructions that will not be passed into captured(). 42 virtual void tooManyUses() = 0; 43 44 /// shouldExplore - This is the use of a value derived from the pointer. 45 /// To prune the search (ie., assume that none of its users could possibly 46 /// capture) return false. To search it, return true. 47 /// 48 /// U->getUser() is always an Instruction. 49 virtual bool shouldExplore(Use *U) = 0; 50 51 /// captured - The instruction I captured the pointer. Return true to 52 /// stop the traversal or false to continue looking for more capturing 53 /// instructions. 54 virtual bool captured(Instruction *I) = 0; 55 }; 56 57 /// PointerMayBeCaptured - Visit the value and the values derived from it and 58 /// find values which appear to be capturing the pointer value. This feeds 59 /// results into and is controlled by the CaptureTracker object. 60 void PointerMayBeCaptured(const Value *V, CaptureTracker *Tracker); 61} // end namespace llvm 62 63#endif 64