LLVM  3.7.0
CaptureTracking.h
Go to the documentation of this file.
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 namespace llvm {
18 
19  class Value;
20  class Use;
21  class Instruction;
22  class DominatorTree;
23 
24  /// PointerMayBeCaptured - Return true if this pointer value may be captured
25  /// by the enclosing function (which is required to exist). This routine can
26  /// be expensive, so consider caching the results. The boolean ReturnCaptures
27  /// specifies whether returning the value (or part of it) from the function
28  /// counts as capturing it or not. The boolean StoreCaptures specified
29  /// whether storing the value (or part of it) into memory anywhere
30  /// automatically counts as capturing it or not.
31  bool PointerMayBeCaptured(const Value *V,
32  bool ReturnCaptures,
33  bool StoreCaptures);
34 
35  /// PointerMayBeCapturedBefore - Return true if this pointer value may be
36  /// captured by the enclosing function (which is required to exist). If a
37  /// DominatorTree is provided, only captures which happen before the given
38  /// instruction are considered. This routine can be expensive, so consider
39  /// caching the results. The boolean ReturnCaptures specifies whether
40  /// returning the value (or part of it) from the function counts as capturing
41  /// it or not. The boolean StoreCaptures specified whether storing the value
42  /// (or part of it) into memory anywhere automatically counts as capturing it
43  /// or not. Captures by the provided instruction are considered if the
44  /// final parameter is true.
45  bool PointerMayBeCapturedBefore(const Value *V, bool ReturnCaptures,
46  bool StoreCaptures, const Instruction *I,
47  DominatorTree *DT, bool IncludeI = false);
48 
49  /// This callback is used in conjunction with PointerMayBeCaptured. In
50  /// addition to the interface here, you'll need to provide your own getters
51  /// to see whether anything was captured.
52  struct CaptureTracker {
53  virtual ~CaptureTracker();
54 
55  /// tooManyUses - The depth of traversal has breached a limit. There may be
56  /// capturing instructions that will not be passed into captured().
57  virtual void tooManyUses() = 0;
58 
59  /// shouldExplore - This is the use of a value derived from the pointer.
60  /// To prune the search (ie., assume that none of its users could possibly
61  /// capture) return false. To search it, return true.
62  ///
63  /// U->getUser() is always an Instruction.
64  virtual bool shouldExplore(const Use *U);
65 
66  /// captured - Information about the pointer was captured by the user of
67  /// use U. Return true to stop the traversal or false to continue looking
68  /// for more capturing instructions.
69  virtual bool captured(const Use *U) = 0;
70  };
71 
72  /// PointerMayBeCaptured - Visit the value and the values derived from it and
73  /// find values which appear to be capturing the pointer value. This feeds
74  /// results into and is controlled by the CaptureTracker object.
75  void PointerMayBeCaptured(const Value *V, CaptureTracker *Tracker);
76 } // end namespace llvm
77 
78 #endif
virtual void tooManyUses()=0
tooManyUses - The depth of traversal has breached a limit.
This callback is used in conjunction with PointerMayBeCaptured.
virtual bool shouldExplore(const Use *U)
shouldExplore - This is the use of a value derived from the pointer.
A Use represents the edge between a Value definition and its users.
Definition: Use.h:69
virtual bool captured(const Use *U)=0
captured - Information about the pointer was captured by the user of use U.
bool PointerMayBeCaptured(const Value *V, bool ReturnCaptures, bool StoreCaptures)
PointerMayBeCaptured - Return true if this pointer value may be captured by the enclosing function (w...
#define I(x, y, z)
Definition: MD5.cpp:54
LLVM Value Representation.
Definition: Value.h:69
bool PointerMayBeCapturedBefore(const Value *V, bool ReturnCaptures, bool StoreCaptures, const Instruction *I, DominatorTree *DT, bool IncludeI=false)
PointerMayBeCapturedBefore - Return true if this pointer value may be captured by the enclosing funct...