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
23 class OrderedBasicBlock;
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,
36 /// PointerMayBeCapturedBefore - Return true if this pointer value may be
37 /// captured by the enclosing function (which is required to exist). If a
38 /// DominatorTree is provided, only captures which happen before the given
39 /// instruction are considered. This routine can be expensive, so consider
40 /// caching the results. The boolean ReturnCaptures specifies whether
41 /// returning the value (or part of it) from the function counts as capturing
42 /// it or not. The boolean StoreCaptures specified whether storing the value
43 /// (or part of it) into memory anywhere automatically counts as capturing it
44 /// or not. Captures by the provided instruction are considered if the
45 /// final parameter is true. An ordered basic block in \p OBB could be used
46 /// to speed up capture-tracker queries.
47 bool PointerMayBeCapturedBefore(const Value *V, bool ReturnCaptures,
48 bool StoreCaptures, const Instruction *I,
49 DominatorTree *DT, bool IncludeI = false,
50 OrderedBasicBlock *OBB = nullptr);
52 /// This callback is used in conjunction with PointerMayBeCaptured. In
53 /// addition to the interface here, you'll need to provide your own getters
54 /// to see whether anything was captured.
55 struct CaptureTracker {
56 virtual ~CaptureTracker();
58 /// tooManyUses - The depth of traversal has breached a limit. There may be
59 /// capturing instructions that will not be passed into captured().
60 virtual void tooManyUses() = 0;
62 /// shouldExplore - This is the use of a value derived from the pointer.
63 /// To prune the search (ie., assume that none of its users could possibly
64 /// capture) return false. To search it, return true.
66 /// U->getUser() is always an Instruction.
67 virtual bool shouldExplore(const Use *U);
69 /// captured - Information about the pointer was captured by the user of
70 /// use U. Return true to stop the traversal or false to continue looking
71 /// for more capturing instructions.
72 virtual bool captured(const Use *U) = 0;
75 /// PointerMayBeCaptured - Visit the value and the values derived from it and
76 /// find values which appear to be capturing the pointer value. This feeds
77 /// results into and is controlled by the CaptureTracker object.
78 void PointerMayBeCaptured(const Value *V, CaptureTracker *Tracker);
79 } // end namespace llvm