Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

167 lines
7.5 KiB

  1. //===- LibCallSemantics.h - Describe library semantics --------------------===//
  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 defines interfaces that can be used to describe language specific
  11. // runtime library interfaces (e.g. libc, libm, etc) to LLVM optimizers.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_ANALYSIS_LIBCALLSEMANTICS_H
  15. #define LLVM_ANALYSIS_LIBCALLSEMANTICS_H
  16. #include "llvm/Analysis/AliasAnalysis.h"
  17. namespace llvm {
  18. /// LibCallLocationInfo - This struct describes a set of memory locations that
  19. /// are accessed by libcalls. Identification of a location is doing with a
  20. /// simple callback function.
  21. ///
  22. /// For example, the LibCallInfo may be set up to model the behavior of
  23. /// standard libm functions. The location that they may be interested in is
  24. /// an abstract location that represents errno for the current target. In
  25. /// this case, a location for errno is anything such that the predicate
  26. /// returns true. On Mac OS/X, this predicate would return true if the
  27. /// pointer is the result of a call to "__error()".
  28. ///
  29. /// Locations can also be defined in a constant-sensitive way. For example,
  30. /// it is possible to define a location that returns true iff it is passed
  31. /// into the call as a specific argument. This is useful for modeling things
  32. /// like "printf", which can store to memory, but only through pointers passed
  33. /// with a '%n' constraint.
  34. ///
  35. struct LibCallLocationInfo {
  36. // TODO: Flags: isContextSensitive etc.
  37. /// isLocation - Return a LocResult if the specified pointer refers to this
  38. /// location for the specified call site. This returns "Yes" if we can tell
  39. /// that the pointer *does definitely* refer to the location, "No" if we can
  40. /// tell that the location *definitely does not* refer to the location, and
  41. /// returns "Unknown" if we cannot tell for certain.
  42. enum LocResult {
  43. Yes, No, Unknown
  44. };
  45. LocResult (*isLocation)(ImmutableCallSite CS,
  46. const AliasAnalysis::Location &Loc);
  47. };
  48. /// LibCallFunctionInfo - Each record in the array of FunctionInfo structs
  49. /// records the behavior of one libcall that is known by the optimizer. This
  50. /// captures things like the side effects of the call. Side effects are
  51. /// modeled both universally (in the readnone/readonly) sense, but also
  52. /// potentially against a set of abstract locations defined by the optimizer.
  53. /// This allows an optimizer to define that some libcall (e.g. sqrt) is
  54. /// side-effect free except that it might modify errno (thus, the call is
  55. /// *not* universally readonly). Or it might say that the side effects
  56. /// are unknown other than to say that errno is not modified.
  57. ///
  58. struct LibCallFunctionInfo {
  59. /// Name - This is the name of the libcall this describes.
  60. const char *Name;
  61. /// TODO: Constant folding function: Constant* vector -> Constant*.
  62. /// UniversalBehavior - This captures the absolute mod/ref behavior without
  63. /// any specific context knowledge. For example, if the function is known
  64. /// to be readonly, this would be set to 'ref'. If known to be readnone,
  65. /// this is set to NoModRef.
  66. AliasAnalysis::ModRefResult UniversalBehavior;
  67. /// LocationMRInfo - This pair captures info about whether a specific
  68. /// location is modified or referenced by a libcall.
  69. struct LocationMRInfo {
  70. /// LocationID - ID # of the accessed location or ~0U for array end.
  71. unsigned LocationID;
  72. /// MRInfo - Mod/Ref info for this location.
  73. AliasAnalysis::ModRefResult MRInfo;
  74. };
  75. /// DetailsType - Indicate the sense of the LocationDetails array. This
  76. /// controls how the LocationDetails array is interpreted.
  77. enum {
  78. /// DoesOnly - If DetailsType is set to DoesOnly, then we know that the
  79. /// *only* mod/ref behavior of this function is captured by the
  80. /// LocationDetails array. If we are trying to say that 'sqrt' can only
  81. /// modify errno, we'd have the {errnoloc,mod} in the LocationDetails
  82. /// array and have DetailsType set to DoesOnly.
  83. DoesOnly,
  84. /// DoesNot - If DetailsType is set to DoesNot, then the sense of the
  85. /// LocationDetails array is completely inverted. This means that we *do
  86. /// not* know everything about the side effects of this libcall, but we do
  87. /// know things that the libcall cannot do. This is useful for complex
  88. /// functions like 'ctime' which have crazy mod/ref behavior, but are
  89. /// known to never read or write errno. In this case, we'd have
  90. /// {errnoloc,modref} in the LocationDetails array and DetailsType would
  91. /// be set to DoesNot, indicating that ctime does not read or write the
  92. /// errno location.
  93. DoesNot
  94. } DetailsType;
  95. /// LocationDetails - This is a pointer to an array of LocationMRInfo
  96. /// structs which indicates the behavior of the libcall w.r.t. specific
  97. /// locations. For example, if this libcall is known to only modify
  98. /// 'errno', it would have a LocationDetails array with the errno ID and
  99. /// 'mod' in it. See the DetailsType field for how this is interpreted.
  100. ///
  101. /// In the "DoesOnly" case, this information is 'may' information for: there
  102. /// is no guarantee that the specified side effect actually does happen,
  103. /// just that it could. In the "DoesNot" case, this is 'must not' info.
  104. ///
  105. /// If this pointer is null, no details are known.
  106. ///
  107. const LocationMRInfo *LocationDetails;
  108. };
  109. /// LibCallInfo - Abstract interface to query about library call information.
  110. /// Instances of this class return known information about some set of
  111. /// libcalls.
  112. ///
  113. class LibCallInfo {
  114. // Implementation details of this object, private.
  115. mutable void *Impl;
  116. mutable const LibCallLocationInfo *Locations;
  117. mutable unsigned NumLocations;
  118. public:
  119. LibCallInfo() : Impl(0), Locations(0), NumLocations(0) {}
  120. virtual ~LibCallInfo();
  121. //===------------------------------------------------------------------===//
  122. // Accessor Methods: Efficient access to contained data.
  123. //===------------------------------------------------------------------===//
  124. /// getLocationInfo - Return information about the specified LocationID.
  125. const LibCallLocationInfo &getLocationInfo(unsigned LocID) const;
  126. /// getFunctionInfo - Return the LibCallFunctionInfo object corresponding to
  127. /// the specified function if we have it. If not, return null.
  128. const LibCallFunctionInfo *getFunctionInfo(const Function *F) const;
  129. //===------------------------------------------------------------------===//
  130. // Implementation Methods: Subclasses should implement these.
  131. //===------------------------------------------------------------------===//
  132. /// getLocationInfo - Return descriptors for the locations referenced by
  133. /// this set of libcalls.
  134. virtual unsigned getLocationInfo(const LibCallLocationInfo *&Array) const {
  135. return 0;
  136. }
  137. /// getFunctionInfoArray - Return an array of descriptors that describe the
  138. /// set of libcalls represented by this LibCallInfo object. This array is
  139. /// terminated by an entry with a NULL name.
  140. virtual const LibCallFunctionInfo *getFunctionInfoArray() const = 0;
  141. };
  142. } // end namespace llvm
  143. #endif