1 //===----- llvm/Analysis/CaptureTracking.h - Pointer capture ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains routines that help determine which pointers are captured.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_ANALYSIS_CAPTURETRACKING_H
15 #define LLVM_ANALYSIS_CAPTURETRACKING_H
17 #include "llvm/Constants.h"
18 #include "llvm/Instructions.h"
19 #include "llvm/Analysis/AliasAnalysis.h"
20 #include "llvm/Support/CallSite.h"
23 /// PointerMayBeCaptured - Return true if this pointer value may be captured
24 /// by the enclosing function (which is required to exist). This routine can
25 /// be expensive, so consider caching the results. The boolean ReturnCaptures
26 /// specifies whether returning the value (or part of it) from the function
27 /// counts as capturing it or not. The boolean StoreCaptures specified
28 /// whether storing the value (or part of it) into memory anywhere
29 /// automatically counts as capturing it or not.
30 bool PointerMayBeCaptured(const Value *V,
34 /// This callback is used in conjunction with PointerMayBeCaptured. In
35 /// addition to the interface here, you'll need to provide your own getters
36 /// to see whether anything was captured.
37 struct CaptureTracker {
38 virtual ~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;
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.
48 /// U->getUser() is always an Instruction.
49 virtual bool shouldExplore(Use *U);
51 /// captured - Information about the pointer was captured by the user of
52 /// use U. Return true to stop the traversal or false to continue looking
53 /// for more capturing instructions.
54 virtual bool captured(Use *U) = 0;
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