CaptureTracking.h 3.5 KB

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