Change CaptureTracking to pass a Use* instead of a Value* when a value is
[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 #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
24 namespace 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     virtual ~CaptureTracker();
41
42     /// tooManyUses - The depth of traversal has breached a limit. There may be
43     /// capturing instructions that will not be passed into captured().
44     virtual void tooManyUses() = 0;
45
46     /// shouldExplore - This is the use of a value derived from the pointer.
47     /// To prune the search (ie., assume that none of its users could possibly
48     /// capture) return false. To search it, return true.
49     ///
50     /// U->getUser() is always an Instruction.
51     virtual bool shouldExplore(Use *U) = 0;
52
53     /// captured - Information about the pointer was captured by the user of
54     /// use U. Return true to stop the traversal or false to continue looking
55     /// for more capturing instructions.
56     virtual bool captured(Use *U) = 0;
57   };
58
59   /// PointerMayBeCaptured - Visit the value and the values derived from it and
60   /// find values which appear to be capturing the pointer value. This feeds
61   /// results into and is controlled by the CaptureTracker object.
62   void PointerMayBeCaptured(const Value *V, CaptureTracker *Tracker);
63 } // end namespace llvm
64
65 #endif