Move the CapturesBefore tracker from AA into CaptureTracking
[oota-llvm.git] / include / llvm / Analysis / CaptureTracking.h
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.
44   bool PointerMayBeCapturedBefore(const Value *V, bool ReturnCaptures,
45                                   bool StoreCaptures, const Instruction *I,
46                                   DominatorTree *DT);
47
48   /// This callback is used in conjunction with PointerMayBeCaptured. In
49   /// addition to the interface here, you'll need to provide your own getters
50   /// to see whether anything was captured.
51   struct CaptureTracker {
52     virtual ~CaptureTracker();
53
54     /// tooManyUses - The depth of traversal has breached a limit. There may be
55     /// capturing instructions that will not be passed into captured().
56     virtual void tooManyUses() = 0;
57
58     /// shouldExplore - This is the use of a value derived from the pointer.
59     /// To prune the search (ie., assume that none of its users could possibly
60     /// capture) return false. To search it, return true.
61     ///
62     /// U->getUser() is always an Instruction.
63     virtual bool shouldExplore(const Use *U);
64
65     /// captured - Information about the pointer was captured by the user of
66     /// use U. Return true to stop the traversal or false to continue looking
67     /// for more capturing instructions.
68     virtual bool captured(const Use *U) = 0;
69   };
70
71   /// PointerMayBeCaptured - Visit the value and the values derived from it and
72   /// find values which appear to be capturing the pointer value. This feeds
73   /// results into and is controlled by the CaptureTracker object.
74   void PointerMayBeCaptured(const Value *V, CaptureTracker *Tracker);
75 } // end namespace llvm
76
77 #endif