1. Remove ranges from itinerary data.
[oota-llvm.git] / include / llvm / Target / TargetLowering.h
index 96305c2b6a290d6dc1b4ad1aa8149d1f662a1cf1..734eda042b8452a7da4f6b8af3c56a7c1ae39b04 100644 (file)
@@ -12,6 +12,7 @@
 //
 //  1. Which ValueTypes are natively supported by the target.
 //  2. Which operations are supported for supported ValueTypes.
+//  3. Cost thresholds for alternative implementations of certain operations.
 //
 // In addition it has a few other components, like information about FP
 // immediates.
@@ -26,6 +27,7 @@
 #include <vector>
 
 namespace llvm {
+  class Value;
   class Function;
   class TargetMachine;
   class TargetData;
@@ -33,6 +35,8 @@ namespace llvm {
   class SDNode;
   class SDOperand;
   class SelectionDAG;
+  class MachineBasicBlock;
+  class MachineInstr;
 
 //===----------------------------------------------------------------------===//
 /// TargetLowering - This class defines information used to lower LLVM code to
@@ -79,7 +83,15 @@ public:
   /// isSetCCExpensive - Return true if the setcc operation is expensive for
   /// this target.
   bool isSetCCExpensive() const { return SetCCIsExpensive; }
-
+  
+  /// isIntDivCheap() - Return true if integer divide is usually cheaper than
+  /// a sequence of several shifts, adds, and multiplies for this target.
+  bool isIntDivCheap() const { return IntDivIsCheap; }
+
+  /// isPow2DivCheap() - Return true if pow2 div is cheaper than a chain of
+  /// srl/add/sra.
+  bool isPow2DivCheap() const { return Pow2DivIsCheap; }
+  
   /// getSetCCResultTy - Return the ValueType of the result of setcc operations.
   ///
   MVT::ValueType getSetCCResultTy() const { return SetCCResultTy; }
@@ -96,11 +108,11 @@ public:
     assert(RC && "This value type is not natively supported!");
     return RC;
   }
-
-  /// hasNativeSupportFor - Return true if the target has native support for the
+  
+  /// isTypeLegal - Return true if the target has native support for the
   /// specified value type.  This means that it has a register that directly
   /// holds it without promotions or expansions.
-  bool hasNativeSupportFor(MVT::ValueType VT) const {
+  bool isTypeLegal(MVT::ValueType VT) const {
     return RegClassForVT[VT] != 0;
   }
 
@@ -130,15 +142,17 @@ public:
     return LegalFPImmediates.end();
   }
 
-  /// getOperationAction - Return how this operation should be
+  /// getOperationAction - Return how this operation should be treated: either
+  /// it is legal, needs to be promoted to a larger size, needs to be
+  /// expanded to some other code sequence, or the target has a custom expander
+  /// for it.
   LegalizeAction getOperationAction(unsigned Op, MVT::ValueType VT) const {
     return (LegalizeAction)((OpActions[Op] >> (2*VT)) & 3);
   }
-
-  /// hasNativeSupportForOperation - Return true if this operation is legal for
-  /// this type.
-  ///
-  bool hasNativeSupportForOperation(unsigned Op, MVT::ValueType VT) const {
+  
+  /// isOperationLegal - Return true if the specified operation is legal on this
+  /// target.
+  bool isOperationLegal(unsigned Op, MVT::ValueType VT) const {
     return getOperationAction(Op, VT) == Legal;
   }
 
@@ -152,8 +166,8 @@ public:
       NVT = (MVT::ValueType)(NVT+1);
       assert(MVT::isInteger(NVT) == MVT::isInteger(VT) && NVT != MVT::isVoid &&
              "Didn't find type to promote to!");
-    } while (!hasNativeSupportFor(NVT) ||
-             getOperationAction(Op, NVT) == Promote);
+    } while (!isTypeLegal(NVT) ||
+              getOperationAction(Op, NVT) == Promote);
     return NVT;
   }
 
@@ -186,6 +200,39 @@ public:
     return NumElementsForVT[VT];
   }
 
+  /// This function returns the maximum number of store operations permitted
+  /// to replace a call to llvm.memset. The value is set by the target at the
+  /// performance threshold for such a replacement.
+  /// @brief Get maximum # of store operations permitted for llvm.memset
+  unsigned getMaxStoresPerMemSet() const { return maxStoresPerMemSet; }
+
+  /// This function returns the maximum number of store operations permitted
+  /// to replace a call to llvm.memcpy. The value is set by the target at the
+  /// performance threshold for such a replacement.
+  /// @brief Get maximum # of store operations permitted for llvm.memcpy
+  unsigned getMaxStoresPerMemCpy() const { return maxStoresPerMemCpy; }
+
+  /// This function returns the maximum number of store operations permitted
+  /// to replace a call to llvm.memmove. The value is set by the target at the
+  /// performance threshold for such a replacement.
+  /// @brief Get maximum # of store operations permitted for llvm.memmove
+  unsigned getMaxStoresPerMemMove() const { return maxStoresPerMemMove; }
+
+  /// This function returns true if the target allows unaligned memory accesses.
+  /// This is used, for example, in situations where an array copy/move/set is 
+  /// converted to a sequence of store operations. It's use helps to ensure that
+  /// such replacements don't generate code that causes an alignment error 
+  /// (trap) on the target machine. 
+  /// @brief Determine if the target supports unaligned memory accesses.
+  bool allowsUnalignedMemoryAccesses() const 
+    { return allowUnalignedMemoryAccesses; }
+  
+  /// usesUnderscoreSetJmpLongJmp - Determine if we should use _setjmp or setjmp
+  /// to implement llvm.setjmp.
+  bool usesUnderscoreSetJmpLongJmp() const {
+    return UseUnderscoreSetJmpLongJmp;
+  }
+
   //===--------------------------------------------------------------------===//
   // TargetLowering Configuration Methods - These methods should be invoked by
   // the derived class constructor to configure this object for the target.
@@ -211,11 +258,28 @@ protected:
     ShiftAmtHandling = OORSA;
   }
 
+  /// setUseUnderscoreSetJmpLongJmp - Indicate whether this target prefers to
+  /// use _setjmp and _longjmp to or implement llvm.setjmp/llvm.longjmp or
+  /// the non _ versions.  Defaults to false.
+  void setUseUnderscoreSetJmpLongJmp(bool Val) {
+    UseUnderscoreSetJmpLongJmp = Val;
+  }
+  
   /// setSetCCIxExpensive - This is a short term hack for targets that codegen
   /// setcc as a conditional branch.  This encourages the code generator to fold
   /// setcc operations into other operations if possible.
   void setSetCCIsExpensive() { SetCCIsExpensive = true; }
 
+  /// setIntDivIsCheap - Tells the code generator that integer divide is
+  /// expensive, and if possible, should be replaced by an alternate sequence
+  /// of instructions not containing an integer divide.
+  void setIntDivIsCheap(bool isCheap = true) { IntDivIsCheap = isCheap; }
+  
+  /// setPow2DivIsCheap - Tells the code generator that it shouldn't generate
+  /// srl/add/sra for a signed divide by power of two, and let the target handle
+  /// it.
+  void setPow2DivIsCheap(bool isCheap = true) { Pow2DivIsCheap = isCheap; }
+  
   /// addRegisterClass - Add the specified register class as an available
   /// regclass for the specified value type.  This indicates the selector can
   /// handle values of that class natively.
@@ -262,29 +326,39 @@ public:
   typedef std::vector<std::pair<SDOperand, const Type*> > ArgListTy;
   virtual std::pair<SDOperand, SDOperand>
   LowerCallTo(SDOperand Chain, const Type *RetTy, bool isVarArg,
-              SDOperand Callee, ArgListTy &Args, SelectionDAG &DAG) = 0;
-
+              unsigned CallingConv, bool isTailCall, SDOperand Callee,
+              ArgListTy &Args, SelectionDAG &DAG) = 0;
+
+  /// LowerReturnTo - This hook lowers a return instruction into the appropriate
+  /// legal ISD::RET node for the target's current ABI.  This method is optional
+  /// and is intended for targets that need non-standard behavior.
+  virtual SDOperand LowerReturnTo(SDOperand Chain, SDOperand Op, 
+                                  SelectionDAG &DAG);
+  
   /// LowerVAStart - This lowers the llvm.va_start intrinsic.  If not
-  /// implemented, this method prints a message and aborts.
-  virtual std::pair<SDOperand, SDOperand>
-  LowerVAStart(SDOperand Chain, SelectionDAG &DAG);
+  /// implemented, this method prints a message and aborts.  This method should
+  /// return the modified chain value.  Note that VAListPtr* correspond to the
+  /// llvm.va_start operand.
+  virtual SDOperand LowerVAStart(SDOperand Chain, SDOperand VAListP,
+                                 Value *VAListV, SelectionDAG &DAG);
 
   /// LowerVAEnd - This lowers llvm.va_end and returns the resultant chain.  If
   /// not implemented, this defaults to a noop.
-  virtual SDOperand LowerVAEnd(SDOperand Chain, SDOperand L, SelectionDAG &DAG);
-
-  /// LowerVACopy - This lowers llvm.va_copy and returns the resultant
-  /// value/chain pair.  If not implemented, this defaults to returning the
-  /// input operand.
-  virtual std::pair<SDOperand,SDOperand>
-  LowerVACopy(SDOperand Chain, SDOperand L, SelectionDAG &DAG);
-
-  /// LowerVAArgNext - This lowers the vaarg and vanext instructions (depending
-  /// on whether the first argument is true).  If not implemented, this prints a
-  /// message and aborts.
+  virtual SDOperand LowerVAEnd(SDOperand Chain, SDOperand LP, Value *LV,
+                               SelectionDAG &DAG);
+
+  /// LowerVACopy - This lowers llvm.va_copy and returns the resultant chain.
+  /// If not implemented, this defaults to loading a pointer from the input and
+  /// storing it to the output.
+  virtual SDOperand LowerVACopy(SDOperand Chain, SDOperand SrcP, Value *SrcV,
+                                SDOperand DestP, Value *DestV,
+                                SelectionDAG &DAG);
+
+  /// LowerVAArg - This lowers the vaarg instruction.  If not implemented, this
+  /// prints a message and aborts.
   virtual std::pair<SDOperand,SDOperand>
-  LowerVAArgNext(bool isVANext, SDOperand Chain, SDOperand VAList,
-                 const Type *ArgTy, SelectionDAG &DAG);
+  LowerVAArg(SDOperand Chain, SDOperand VAListP, Value *VAListV,
+             const Type *ArgTy, SelectionDAG &DAG);
 
   /// LowerFrameReturnAddress - This hook lowers a call to llvm.returnaddress or
   /// llvm.frameaddress (depending on the value of the first argument).  The
@@ -298,8 +372,19 @@ public:
   /// which are registered to use 'custom' lowering.  This callback is invoked.
   /// If the target has no operations that require custom lowering, it need not
   /// implement this.  The default implementation of this aborts.
-  virtual SDOperand LowerOperation(SDOperand Op);
+  virtual SDOperand LowerOperation(SDOperand Op, SelectionDAG &DAG);
 
+  //===--------------------------------------------------------------------===//
+  // Scheduler hooks
+  //
+  
+  // InsertAtEndOfBasicBlock - This method should be implemented by targets that
+  // mark instructions with the 'usesCustomDAGSchedInserter' flag.  These
+  // instructions are special in various ways, which require special support to
+  // insert.  The specified MachineInstr is created but not inserted into any
+  // basic blocks, and the scheduler passes ownership of it to this method.
+  virtual MachineBasicBlock *InsertAtEndOfBasicBlock(MachineInstr *MI,
+                                                     MachineBasicBlock *MBB);
 
 private:
   TargetMachine &TM;
@@ -324,6 +409,17 @@ private:
   /// setcc operations into other operations if possible.
   bool SetCCIsExpensive;
 
+  /// IntDivIsCheap - Tells the code generator not to expand integer divides by
+  /// constants into a sequence of muls, adds, and shifts.  This is a hack until
+  /// a real cost model is in place.  If we ever optimize for size, this will be
+  /// set to true unconditionally.
+  bool IntDivIsCheap;
+  
+  /// Pow2DivIsCheap - Tells the code generator that it shouldn't generate
+  /// srl/add/sra for a signed divide by power of two, and let the target handle
+  /// it.
+  bool Pow2DivIsCheap;
+  
   /// SetCCResultTy - The type that SetCC operations use.  This defaults to the
   /// PointerTy.
   MVT::ValueType SetCCResultTy;
@@ -331,6 +427,10 @@ private:
   /// SetCCResultContents - Information about the contents of the high-bits in
   /// the result of a setcc comparison operation.
   SetCCResultValue SetCCResultContents;
+  
+  /// UseUnderscoreSetJmpLongJmp - This target prefers to use _setjmp and
+  /// _longjmp to implement llvm.setjmp/llvm.longjmp.  Defaults to false.
+  bool UseUnderscoreSetJmpLongJmp;
 
   /// RegClassForVT - This indicates the default register class to use for
   /// each ValueType the target supports natively.
@@ -360,6 +460,47 @@ private:
 
   std::vector<std::pair<MVT::ValueType,
                         TargetRegisterClass*> > AvailableRegClasses;
+
+protected:
+  /// When lowering %llvm.memset this field specifies the maximum number of
+  /// store operations that may be substituted for the call to memset. Targets
+  /// must set this value based on the cost threshold for that target. Targets
+  /// should assume that the memset will be done using as many of the largest
+  /// store operations first, followed by smaller ones, if necessary, per
+  /// alignment restrictions. For example, storing 9 bytes on a 32-bit machine
+  /// with 16-bit alignment would result in four 2-byte stores and one 1-byte
+  /// store.  This only applies to setting a constant array of a constant size.
+  /// @brief Specify maximum number of store instructions per memset call.
+  unsigned maxStoresPerMemSet;
+
+  /// When lowering %llvm.memcpy this field specifies the maximum number of
+  /// store operations that may be substituted for a call to memcpy. Targets
+  /// must set this value based on the cost threshold for that target. Targets
+  /// should assume that the memcpy will be done using as many of the largest
+  /// store operations first, followed by smaller ones, if necessary, per
+  /// alignment restrictions. For example, storing 7 bytes on a 32-bit machine
+  /// with 32-bit alignment would result in one 4-byte store, a one 2-byte store
+  /// and one 1-byte store. This only applies to copying a constant array of
+  /// constant size.
+  /// @brief Specify maximum bytes of store instructions per memcpy call.
+  unsigned maxStoresPerMemCpy;
+
+  /// When lowering %llvm.memmove this field specifies the maximum number of
+  /// store instructions that may be substituted for a call to memmove. Targets
+  /// must set this value based on the cost threshold for that target. Targets
+  /// should assume that the memmove will be done using as many of the largest
+  /// store operations first, followed by smaller ones, if necessary, per
+  /// alignment restrictions. For example, moving 9 bytes on a 32-bit machine
+  /// with 8-bit alignment would result in nine 1-byte stores.  This only
+  /// applies to copying a constant array of constant size.
+  /// @brief Specify maximum bytes of store instructions per memmove call.
+  unsigned maxStoresPerMemMove;
+
+  /// This field specifies whether the target machine permits unaligned memory
+  /// accesses.  This is used, for example, to determine the size of store 
+  /// operations when copying small arrays and other similar tasks.
+  /// @brief Indicate whether the target permits unaligned memory accesses.
+  bool allowUnalignedMemoryAccesses;
 };
 } // end llvm namespace