Add Constant Hoisting Pass
[oota-llvm.git] / include / llvm / IR / Function.h
index fe27d9b75d4b4304c0eaa8f858d89e0c5b6b52b8..bba7ecdd2372d3cf5671d873c3bfa992ab6589cd 100644 (file)
@@ -85,7 +85,7 @@ private:
   BasicBlockListType  BasicBlocks;        ///< The basic blocks
   mutable ArgumentListType ArgumentList;  ///< The formal arguments
   ValueSymbolTable *SymTab;               ///< Symbol table of args/instructions
-  AttributeSet AttributeList;              ///< Parameter attributes
+  AttributeSet AttributeSets;             ///< Parameter attributes
 
   // HasLazyArguments is stored in Value::SubclassData.
   /*bool HasLazyArguments;*/
@@ -113,6 +113,10 @@ private:
   Function(const Function&) LLVM_DELETED_FUNCTION;
   void operator=(const Function&) LLVM_DELETED_FUNCTION;
 
+  /// Do the actual lookup of an intrinsic ID when the query could not be
+  /// answered from the cache.
+  unsigned lookupIntrinsicID() const LLVM_READONLY;
+
   /// Function ctor - If the (optional) Module argument is specified, the
   /// function is automatically inserted into the end of the function list for
   /// the module.
@@ -141,10 +145,12 @@ public:
 
   /// getIntrinsicID - This method returns the ID number of the specified
   /// function, or Intrinsic::not_intrinsic if the function is not an
-  /// instrinsic, or if the pointer is null.  This value is always defined to be
+  /// intrinsic, or if the pointer is null.  This value is always defined to be
   /// zero to allow easy checking for whether a function is intrinsic or not.
   /// The particular intrinsic functions which correspond to this value are
-  /// defined in llvm/Intrinsics.h.
+  /// defined in llvm/Intrinsics.h.  Results are cached in the LLVM context,
+  /// subsequent requests for the same ID return results much faster from the
+  /// cache.
   ///
   unsigned getIntrinsicID() const LLVM_READONLY;
   bool isIntrinsic() const { return getName().startswith("llvm."); }
@@ -153,28 +159,59 @@ public:
   /// calling convention of this function.  The enum values for the known
   /// calling conventions are defined in CallingConv.h.
   CallingConv::ID getCallingConv() const {
-    return static_cast<CallingConv::ID>(getSubclassDataFromValue() >> 1);
+    return static_cast<CallingConv::ID>(getSubclassDataFromValue() >> 2);
   }
   void setCallingConv(CallingConv::ID CC) {
-    setValueSubclassData((getSubclassDataFromValue() & 1) |
-                         (static_cast<unsigned>(CC) << 1));
+    setValueSubclassData((getSubclassDataFromValue() & 3) |
+                         (static_cast<unsigned>(CC) << 2));
   }
 
-  /// getAttributes - Return the attribute list for this Function.
-  ///
-  const AttributeSet &getAttributes() const { return AttributeList; }
+  /// @brief Return the attribute list for this Function.
+  AttributeSet getAttributes() const { return AttributeSets; }
 
-  /// setAttributes - Set the attribute list for this Function.
-  ///
-  void setAttributes(const AttributeSet &attrs) { AttributeList = attrs; }
+  /// @brief Set the attribute list for this Function.
+  void setAttributes(AttributeSet attrs) { AttributeSets = attrs; }
 
-  /// addFnAttr - Add function attributes to this function.
-  ///
+  /// @brief Add function attributes to this function.
   void addFnAttr(Attribute::AttrKind N) {
-    setAttributes(AttributeList.addAttribute(getContext(),
+    setAttributes(AttributeSets.addAttribute(getContext(),
                                              AttributeSet::FunctionIndex, N));
   }
 
+  /// @brief Remove function attributes from this function.
+  void removeFnAttr(Attribute::AttrKind N) {
+    setAttributes(AttributeSets.removeAttribute(
+        getContext(), AttributeSet::FunctionIndex, N));
+  }
+
+  /// @brief Add function attributes to this function.
+  void addFnAttr(StringRef Kind) {
+    setAttributes(
+      AttributeSets.addAttribute(getContext(),
+                                 AttributeSet::FunctionIndex, Kind));
+  }
+  void addFnAttr(StringRef Kind, StringRef Value) {
+    setAttributes(
+      AttributeSets.addAttribute(getContext(),
+                                 AttributeSet::FunctionIndex, Kind, Value));
+  }
+
+  /// @brief Return true if the function has the attribute.
+  bool hasFnAttribute(Attribute::AttrKind Kind) const {
+    return AttributeSets.hasAttribute(AttributeSet::FunctionIndex, Kind);
+  }
+  bool hasFnAttribute(StringRef Kind) const {
+    return AttributeSets.hasAttribute(AttributeSet::FunctionIndex, Kind);
+  }
+
+  /// @brief Return the attribute for the given attribute kind.
+  Attribute getFnAttribute(Attribute::AttrKind Kind) const {
+    return AttributeSets.getAttribute(AttributeSet::FunctionIndex, Kind);
+  }
+  Attribute getFnAttribute(StringRef Kind) const {
+    return AttributeSets.getAttribute(AttributeSet::FunctionIndex, Kind);
+  }
+
   /// hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm
   ///                             to use during code generation.
   bool hasGC() const;
@@ -193,12 +230,12 @@ public:
 
   /// @brief Extract the alignment for a call or parameter (0=unknown).
   unsigned getParamAlignment(unsigned i) const {
-    return AttributeList.getParamAlignment(i);
+    return AttributeSets.getParamAlignment(i);
   }
 
   /// @brief Determine if the function does not access memory.
   bool doesNotAccessMemory() const {
-    return AttributeList.hasAttribute(AttributeSet::FunctionIndex,
+    return AttributeSets.hasAttribute(AttributeSet::FunctionIndex,
                                       Attribute::ReadNone);
   }
   void setDoesNotAccessMemory() {
@@ -208,7 +245,7 @@ public:
   /// @brief Determine if the function does not access or only reads memory.
   bool onlyReadsMemory() const {
     return doesNotAccessMemory() ||
-      AttributeList.hasAttribute(AttributeSet::FunctionIndex,
+      AttributeSets.hasAttribute(AttributeSet::FunctionIndex,
                                  Attribute::ReadOnly);
   }
   void setOnlyReadsMemory() {
@@ -217,7 +254,7 @@ public:
 
   /// @brief Determine if the function cannot return.
   bool doesNotReturn() const {
-    return AttributeList.hasAttribute(AttributeSet::FunctionIndex,
+    return AttributeSets.hasAttribute(AttributeSet::FunctionIndex,
                                       Attribute::NoReturn);
   }
   void setDoesNotReturn() {
@@ -226,7 +263,7 @@ public:
 
   /// @brief Determine if the function cannot unwind.
   bool doesNotThrow() const {
-    return AttributeList.hasAttribute(AttributeSet::FunctionIndex,
+    return AttributeSets.hasAttribute(AttributeSet::FunctionIndex,
                                       Attribute::NoUnwind);
   }
   void setDoesNotThrow() {
@@ -235,7 +272,7 @@ public:
 
   /// @brief Determine if the call cannot be duplicated.
   bool cannotDuplicate() const {
-    return AttributeList.hasAttribute(AttributeSet::FunctionIndex,
+    return AttributeSets.hasAttribute(AttributeSet::FunctionIndex,
                                       Attribute::NoDuplicate);
   }
   void setCannotDuplicate() {
@@ -245,7 +282,7 @@ public:
   /// @brief True if the ABI mandates (or the user requested) that this
   /// function be in a unwind table.
   bool hasUWTable() const {
-    return AttributeList.hasAttribute(AttributeSet::FunctionIndex,
+    return AttributeSets.hasAttribute(AttributeSet::FunctionIndex,
                                       Attribute::UWTable);
   }
   void setHasUWTable() {
@@ -260,13 +297,13 @@ public:
   /// @brief Determine if the function returns a structure through first
   /// pointer argument.
   bool hasStructRetAttr() const {
-    return AttributeList.hasAttribute(1, Attribute::StructRet);
+    return AttributeSets.hasAttribute(1, Attribute::StructRet);
   }
 
   /// @brief Determine if the parameter does not alias other parameters.
   /// @param n The parameter to check. 1 is the first parameter, 0 is the return
   bool doesNotAlias(unsigned n) const {
-    return AttributeList.hasAttribute(n, Attribute::NoAlias);
+    return AttributeSets.hasAttribute(n, Attribute::NoAlias);
   }
   void setDoesNotAlias(unsigned n) {
     addAttribute(n, Attribute::NoAlias);
@@ -275,12 +312,27 @@ public:
   /// @brief Determine if the parameter can be captured.
   /// @param n The parameter to check. 1 is the first parameter, 0 is the return
   bool doesNotCapture(unsigned n) const {
-    return AttributeList.hasAttribute(n, Attribute::NoCapture);
+    return AttributeSets.hasAttribute(n, Attribute::NoCapture);
   }
   void setDoesNotCapture(unsigned n) {
     addAttribute(n, Attribute::NoCapture);
   }
 
+  bool doesNotAccessMemory(unsigned n) const {
+    return AttributeSets.hasAttribute(n, Attribute::ReadNone);
+  }
+  void setDoesNotAccessMemory(unsigned n) {
+    addAttribute(n, Attribute::ReadNone);
+  }
+
+  bool onlyReadsMemory(unsigned n) const {
+    return doesNotAccessMemory(n) ||
+      AttributeSets.hasAttribute(n, Attribute::ReadOnly);
+  }
+  void setOnlyReadsMemory(unsigned n) {
+    addAttribute(n, Attribute::ReadOnly);
+  }
+
   /// copyAttributesFrom - copy all additional attributes (those not needed to
   /// create a Function) from the Function Src to this one.
   void copyAttributesFrom(const GlobalValue *Src);
@@ -375,6 +427,13 @@ public:
   size_t arg_size() const;
   bool arg_empty() const;
 
+  bool hasPrefixData() const {
+    return getSubclassDataFromValue() & 2;
+  }
+
+  Constant *getPrefixData() const;
+  void setPrefixData(Constant *PrefixData);
+
   /// viewCFG - This function is meant for use from the debugger.  You can just
   /// say 'call F->viewCFG()' and a ghostview window should pop up from the
   /// program, displaying the CFG of the current function with the code for each