LLVM API Documentation

TargetLowering.h

Go to the documentation of this file.
00001 //===-- llvm/Target/TargetLowering.h - Target Lowering Info -----*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file describes how to lower LLVM code to machine code.  This has two
00011 // main components:
00012 //
00013 //  1. Which ValueTypes are natively supported by the target.
00014 //  2. Which operations are supported for supported ValueTypes.
00015 //  3. Cost thresholds for alternative implementations of certain operations.
00016 //
00017 // In addition it has a few other components, like information about FP
00018 // immediates.
00019 //
00020 //===----------------------------------------------------------------------===//
00021 
00022 #ifndef LLVM_TARGET_TARGETLOWERING_H
00023 #define LLVM_TARGET_TARGETLOWERING_H
00024 
00025 #include "llvm/InlineAsm.h"
00026 #include "llvm/CodeGen/SelectionDAGNodes.h"
00027 #include "llvm/CodeGen/RuntimeLibcalls.h"
00028 #include "llvm/ADT/APFloat.h"
00029 #include "llvm/ADT/DenseMap.h"
00030 #include "llvm/ADT/SmallSet.h"
00031 #include "llvm/ADT/STLExtras.h"
00032 #include "llvm/CodeGen/DebugLoc.h"
00033 #include <climits>
00034 #include <map>
00035 #include <vector>
00036 
00037 namespace llvm {
00038   class AllocaInst;
00039   class CallInst;
00040   class Function;
00041   class FastISel;
00042   class MachineBasicBlock;
00043   class MachineFunction;
00044   class MachineFrameInfo;
00045   class MachineInstr;
00046   class MachineModuleInfo;
00047   class DwarfWriter;
00048   class SDNode;
00049   class SDValue;
00050   class SelectionDAG;
00051   class TargetData;
00052   class TargetMachine;
00053   class TargetRegisterClass;
00054   class TargetSubtarget;
00055   class Value;
00056 
00057 //===----------------------------------------------------------------------===//
00058 /// TargetLowering - This class defines information used to lower LLVM code to
00059 /// legal SelectionDAG operators that the target instruction selector can accept
00060 /// natively.
00061 ///
00062 /// This class also defines callbacks that targets must implement to lower
00063 /// target-specific constructs to SelectionDAG operators.
00064 ///
00065 class TargetLowering {
00066 public:
00067   /// LegalizeAction - This enum indicates whether operations are valid for a
00068   /// target, and if not, what action should be used to make them valid.
00069   enum LegalizeAction {
00070     Legal,      // The target natively supports this operation.
00071     Promote,    // This operation should be executed in a larger type.
00072     Expand,     // Try to expand this to other ops, otherwise use a libcall.
00073     Custom      // Use the LowerOperation hook to implement custom lowering.
00074   };
00075 
00076   enum OutOfRangeShiftAmount {
00077     Undefined,  // Oversized shift amounts are undefined (default).
00078     Mask,       // Shift amounts are auto masked (anded) to value size.
00079     Extend      // Oversized shift pulls in zeros or sign bits.
00080   };
00081 
00082   enum BooleanContent { // How the target represents true/false values.
00083     UndefinedBooleanContent,    // Only bit 0 counts, the rest can hold garbage.
00084     ZeroOrOneBooleanContent,        // All bits zero except for bit 0.
00085     ZeroOrNegativeOneBooleanContent // All bits equal to bit 0.
00086   };
00087 
00088   enum SchedPreference {
00089     SchedulingForLatency,          // Scheduling for shortest total latency.
00090     SchedulingForRegPressure       // Scheduling for lowest register pressure.
00091   };
00092 
00093   explicit TargetLowering(TargetMachine &TM);
00094   virtual ~TargetLowering();
00095 
00096   TargetMachine &getTargetMachine() const { return TM; }
00097   const TargetData *getTargetData() const { return TD; }
00098 
00099   bool isBigEndian() const { return !IsLittleEndian; }
00100   bool isLittleEndian() const { return IsLittleEndian; }
00101   MVT getPointerTy() const { return PointerTy; }
00102   MVT getShiftAmountTy() const { return ShiftAmountTy; }
00103   OutOfRangeShiftAmount getShiftAmountFlavor() const {return ShiftAmtHandling; }
00104 
00105   /// usesGlobalOffsetTable - Return true if this target uses a GOT for PIC
00106   /// codegen.
00107   bool usesGlobalOffsetTable() const { return UsesGlobalOffsetTable; }
00108 
00109   /// isSelectExpensive - Return true if the select operation is expensive for
00110   /// this target.
00111   bool isSelectExpensive() const { return SelectIsExpensive; }
00112   
00113   /// isIntDivCheap() - Return true if integer divide is usually cheaper than
00114   /// a sequence of several shifts, adds, and multiplies for this target.
00115   bool isIntDivCheap() const { return IntDivIsCheap; }
00116 
00117   /// isPow2DivCheap() - Return true if pow2 div is cheaper than a chain of
00118   /// srl/add/sra.
00119   bool isPow2DivCheap() const { return Pow2DivIsCheap; }
00120 
00121   /// getSetCCResultType - Return the ValueType of the result of SETCC
00122   /// operations.  Also used to obtain the target's preferred type for
00123   /// the condition operand of SELECT and BRCOND nodes.  In the case of
00124   /// BRCOND the argument passed is MVT::Other since there are no other
00125   /// operands to get a type hint from.
00126   virtual MVT getSetCCResultType(MVT VT) const;
00127 
00128   /// getBooleanContents - For targets without i1 registers, this gives the
00129   /// nature of the high-bits of boolean values held in types wider than i1.
00130   /// "Boolean values" are special true/false values produced by nodes like
00131   /// SETCC and consumed (as the condition) by nodes like SELECT and BRCOND.
00132   /// Not to be confused with general values promoted from i1.
00133   BooleanContent getBooleanContents() const { return BooleanContents;}
00134 
00135   /// getSchedulingPreference - Return target scheduling preference.
00136   SchedPreference getSchedulingPreference() const {
00137     return SchedPreferenceInfo;
00138   }
00139 
00140   /// getRegClassFor - Return the register class that should be used for the
00141   /// specified value type.  This may only be called on legal types.
00142   TargetRegisterClass *getRegClassFor(MVT VT) const {
00143     assert((unsigned)VT.getSimpleVT() < array_lengthof(RegClassForVT));
00144     TargetRegisterClass *RC = RegClassForVT[VT.getSimpleVT()];
00145     assert(RC && "This value type is not natively supported!");
00146     return RC;
00147   }
00148 
00149   /// isTypeLegal - Return true if the target has native support for the
00150   /// specified value type.  This means that it has a register that directly
00151   /// holds it without promotions or expansions.
00152   bool isTypeLegal(MVT VT) const {
00153     assert(!VT.isSimple() ||
00154            (unsigned)VT.getSimpleVT() < array_lengthof(RegClassForVT));
00155     return VT.isSimple() && RegClassForVT[VT.getSimpleVT()] != 0;
00156   }
00157 
00158   class ValueTypeActionImpl {
00159     /// ValueTypeActions - This is a bitvector that contains two bits for each
00160     /// value type, where the two bits correspond to the LegalizeAction enum.
00161     /// This can be queried with "getTypeAction(VT)".
00162     uint32_t ValueTypeActions[2];
00163   public:
00164     ValueTypeActionImpl() {
00165       ValueTypeActions[0] = ValueTypeActions[1] = 0;
00166     }
00167     ValueTypeActionImpl(const ValueTypeActionImpl &RHS) {
00168       ValueTypeActions[0] = RHS.ValueTypeActions[0];
00169       ValueTypeActions[1] = RHS.ValueTypeActions[1];
00170     }
00171     
00172     LegalizeAction getTypeAction(MVT VT) const {
00173       if (VT.isExtended()) {
00174         if (VT.isVector()) {
00175           return VT.isPow2VectorType() ? Expand : Promote;
00176         }
00177         if (VT.isInteger())
00178           // First promote to a power-of-two size, then expand if necessary.
00179           return VT == VT.getRoundIntegerType() ? Expand : Promote;
00180         assert(0 && "Unsupported extended type!");
00181         return Legal;
00182       }
00183       unsigned I = VT.getSimpleVT();
00184       assert(I<4*array_lengthof(ValueTypeActions)*sizeof(ValueTypeActions[0]));
00185       return (LegalizeAction)((ValueTypeActions[I>>4] >> ((2*I) & 31)) & 3);
00186     }
00187     void setTypeAction(MVT VT, LegalizeAction Action) {
00188       unsigned I = VT.getSimpleVT();
00189       assert(I<4*array_lengthof(ValueTypeActions)*sizeof(ValueTypeActions[0]));
00190       ValueTypeActions[I>>4] |= Action << ((I*2) & 31);
00191     }
00192   };
00193   
00194   const ValueTypeActionImpl &getValueTypeActions() const {
00195     return ValueTypeActions;
00196   }
00197 
00198   /// getTypeAction - Return how we should legalize values of this type, either
00199   /// it is already legal (return 'Legal') or we need to promote it to a larger
00200   /// type (return 'Promote'), or we need to expand it into multiple registers
00201   /// of smaller integer type (return 'Expand').  'Custom' is not an option.
00202   LegalizeAction getTypeAction(MVT VT) const {
00203     return ValueTypeActions.getTypeAction(VT);
00204   }
00205 
00206   /// getTypeToTransformTo - For types supported by the target, this is an
00207   /// identity function.  For types that must be promoted to larger types, this
00208   /// returns the larger type to promote to.  For integer types that are larger
00209   /// than the largest integer register, this contains one step in the expansion
00210   /// to get to the smaller register. For illegal floating point types, this
00211   /// returns the integer type to transform to.
00212   MVT getTypeToTransformTo(MVT VT) const {
00213     if (VT.isSimple()) {
00214       assert((unsigned)VT.getSimpleVT() < array_lengthof(TransformToType));
00215       MVT NVT = TransformToType[VT.getSimpleVT()];
00216       assert(getTypeAction(NVT) != Promote &&
00217              "Promote may not follow Expand or Promote");
00218       return NVT;
00219     }
00220 
00221     if (VT.isVector()) {
00222       MVT NVT = VT.getPow2VectorType();
00223       if (NVT == VT) {
00224         // Vector length is a power of 2 - split to half the size.
00225         unsigned NumElts = VT.getVectorNumElements();
00226         MVT EltVT = VT.getVectorElementType();
00227         return (NumElts == 1) ? EltVT : MVT::getVectorVT(EltVT, NumElts / 2);
00228       }
00229       // Promote to a power of two size, avoiding multi-step promotion.
00230       return getTypeAction(NVT) == Promote ? getTypeToTransformTo(NVT) : NVT;
00231     } else if (VT.isInteger()) {
00232       MVT NVT = VT.getRoundIntegerType();
00233       if (NVT == VT)
00234         // Size is a power of two - expand to half the size.
00235         return MVT::getIntegerVT(VT.getSizeInBits() / 2);
00236       else
00237         // Promote to a power of two size, avoiding multi-step promotion.
00238         return getTypeAction(NVT) == Promote ? getTypeToTransformTo(NVT) : NVT;
00239     }
00240     assert(0 && "Unsupported extended type!");
00241     return MVT(); // Not reached
00242   }
00243 
00244   /// getTypeToExpandTo - For types supported by the target, this is an
00245   /// identity function.  For types that must be expanded (i.e. integer types
00246   /// that are larger than the largest integer register or illegal floating
00247   /// point types), this returns the largest legal type it will be expanded to.
00248   MVT getTypeToExpandTo(MVT VT) const {
00249     assert(!VT.isVector());
00250     while (true) {
00251       switch (getTypeAction(VT)) {
00252       case Legal:
00253         return VT;
00254       case Expand:
00255         VT = getTypeToTransformTo(VT);
00256         break;
00257       default:
00258         assert(false && "Type is not legal nor is it to be expanded!");
00259         return VT;
00260       }
00261     }
00262     return VT;
00263   }
00264 
00265   /// getVectorTypeBreakdown - Vector types are broken down into some number of
00266   /// legal first class types.  For example, MVT::v8f32 maps to 2 MVT::v4f32
00267   /// with Altivec or SSE1, or 8 promoted MVT::f64 values with the X86 FP stack.
00268   /// Similarly, MVT::v2i64 turns into 4 MVT::i32 values with both PPC and X86.
00269   ///
00270   /// This method returns the number of registers needed, and the VT for each
00271   /// register.  It also returns the VT and quantity of the intermediate values
00272   /// before they are promoted/expanded.
00273   ///
00274   unsigned getVectorTypeBreakdown(MVT VT,
00275                                   MVT &IntermediateVT,
00276                                   unsigned &NumIntermediates,
00277                                   MVT &RegisterVT) const;
00278 
00279   /// getTgtMemIntrinsic: Given an intrinsic, checks if on the target the
00280   /// intrinsic will need to map to a MemIntrinsicNode (touches memory). If
00281   /// this is the case, it returns true and store the intrinsic
00282   /// information into the IntrinsicInfo that was passed to the function.
00283   typedef struct IntrinsicInfo { 
00284     unsigned     opc;         // target opcode
00285     MVT          memVT;       // memory VT
00286     const Value* ptrVal;      // value representing memory location
00287     int          offset;      // offset off of ptrVal 
00288     unsigned     align;       // alignment
00289     bool         vol;         // is volatile?
00290     bool         readMem;     // reads memory?
00291     bool         writeMem;    // writes memory?
00292   } IntrinisicInfo;
00293 
00294   virtual bool getTgtMemIntrinsic(IntrinsicInfo& Info,
00295                                   CallInst &I, unsigned Intrinsic) {
00296     return false;
00297   }
00298 
00299   /// getWidenVectorType: given a vector type, returns the type to widen to
00300   /// (e.g., v7i8 to v8i8). If the vector type is legal, it returns itself.
00301   /// If there is no vector type that we want to widen to, returns MVT::Other
00302   /// When and were to widen is target dependent based on the cost of
00303   /// scalarizing vs using the wider vector type.
00304   virtual MVT getWidenVectorType(MVT VT) const;
00305 
00306   typedef std::vector<APFloat>::const_iterator legal_fpimm_iterator;
00307   legal_fpimm_iterator legal_fpimm_begin() const {
00308     return LegalFPImmediates.begin();
00309   }
00310   legal_fpimm_iterator legal_fpimm_end() const {
00311     return LegalFPImmediates.end();
00312   }
00313   
00314   /// isShuffleMaskLegal - Targets can use this to indicate that they only
00315   /// support *some* VECTOR_SHUFFLE operations, those with specific masks.
00316   /// By default, if a target supports the VECTOR_SHUFFLE node, all mask values
00317   /// are assumed to be legal.
00318   virtual bool isShuffleMaskLegal(SDValue Mask, MVT VT) const {
00319     return true;
00320   }
00321 
00322   /// isVectorClearMaskLegal - Similar to isShuffleMaskLegal. This is
00323   /// used by Targets can use this to indicate if there is a suitable
00324   /// VECTOR_SHUFFLE that can be used to replace a VAND with a constant
00325   /// pool entry.
00326   virtual bool isVectorClearMaskLegal(const std::vector<SDValue> &BVOps,
00327                                       MVT EVT,
00328                                       SelectionDAG &DAG) const {
00329     return false;
00330   }
00331 
00332   /// getOperationAction - Return how this operation should be treated: either
00333   /// it is legal, needs to be promoted to a larger size, needs to be
00334   /// expanded to some other code sequence, or the target has a custom expander
00335   /// for it.
00336   LegalizeAction getOperationAction(unsigned Op, MVT VT) const {
00337     if (VT.isExtended()) return Expand;
00338     assert(Op < array_lengthof(OpActions) &&
00339            (unsigned)VT.getSimpleVT() < sizeof(OpActions[0])*4 &&
00340            "Table isn't big enough!");
00341     return (LegalizeAction)((OpActions[Op] >> (2*VT.getSimpleVT())) & 3);
00342   }
00343 
00344   /// isOperationLegalOrCustom - Return true if the specified operation is
00345   /// legal on this target or can be made legal with custom lowering. This
00346   /// is used to help guide high-level lowering decisions.
00347   bool isOperationLegalOrCustom(unsigned Op, MVT VT) const {
00348     return (VT == MVT::Other || isTypeLegal(VT)) &&
00349       (getOperationAction(Op, VT) == Legal ||
00350        getOperationAction(Op, VT) == Custom);
00351   }
00352 
00353   /// isOperationLegal - Return true if the specified operation is legal on this
00354   /// target.
00355   bool isOperationLegal(unsigned Op, MVT VT) const {
00356     return (VT == MVT::Other || isTypeLegal(VT)) &&
00357            getOperationAction(Op, VT) == Legal;
00358   }
00359 
00360   /// getLoadExtAction - Return how this load with extension should be treated:
00361   /// either it is legal, needs to be promoted to a larger size, needs to be
00362   /// expanded to some other code sequence, or the target has a custom expander
00363   /// for it.
00364   LegalizeAction getLoadExtAction(unsigned LType, MVT VT) const {
00365     assert(LType < array_lengthof(LoadExtActions) &&
00366            (unsigned)VT.getSimpleVT() < sizeof(LoadExtActions[0])*4 &&
00367            "Table isn't big enough!");
00368     return (LegalizeAction)((LoadExtActions[LType] >> (2*VT.getSimpleVT())) & 3);
00369   }
00370 
00371   /// isLoadExtLegal - Return true if the specified load with extension is legal
00372   /// on this target.
00373   bool isLoadExtLegal(unsigned LType, MVT VT) const {
00374     return VT.isSimple() &&
00375       (getLoadExtAction(LType, VT) == Legal ||
00376        getLoadExtAction(LType, VT) == Custom);
00377   }
00378 
00379   /// getTruncStoreAction - Return how this store with truncation should be
00380   /// treated: either it is legal, needs to be promoted to a larger size, needs
00381   /// to be expanded to some other code sequence, or the target has a custom
00382   /// expander for it.
00383   LegalizeAction getTruncStoreAction(MVT ValVT,
00384                                      MVT MemVT) const {
00385     assert((unsigned)ValVT.getSimpleVT() < array_lengthof(TruncStoreActions) &&
00386            (unsigned)MemVT.getSimpleVT() < sizeof(TruncStoreActions[0])*4 &&
00387            "Table isn't big enough!");
00388     return (LegalizeAction)((TruncStoreActions[ValVT.getSimpleVT()] >>
00389                              (2*MemVT.getSimpleVT())) & 3);
00390   }
00391 
00392   /// isTruncStoreLegal - Return true if the specified store with truncation is
00393   /// legal on this target.
00394   bool isTruncStoreLegal(MVT ValVT, MVT MemVT) const {
00395     return isTypeLegal(ValVT) && MemVT.isSimple() &&
00396       (getTruncStoreAction(ValVT, MemVT) == Legal ||
00397        getTruncStoreAction(ValVT, MemVT) == Custom);
00398   }
00399 
00400   /// getIndexedLoadAction - Return how the indexed load should be treated:
00401   /// either it is legal, needs to be promoted to a larger size, needs to be
00402   /// expanded to some other code sequence, or the target has a custom expander
00403   /// for it.
00404   LegalizeAction
00405   getIndexedLoadAction(unsigned IdxMode, MVT VT) const {
00406     assert(IdxMode < array_lengthof(IndexedModeActions[0]) &&
00407            (unsigned)VT.getSimpleVT() < sizeof(IndexedModeActions[0][0])*4 &&
00408            "Table isn't big enough!");
00409     return (LegalizeAction)((IndexedModeActions[0][IdxMode] >>
00410                              (2*VT.getSimpleVT())) & 3);
00411   }
00412 
00413   /// isIndexedLoadLegal - Return true if the specified indexed load is legal
00414   /// on this target.
00415   bool isIndexedLoadLegal(unsigned IdxMode, MVT VT) const {
00416     return VT.isSimple() &&
00417       (getIndexedLoadAction(IdxMode, VT) == Legal ||
00418        getIndexedLoadAction(IdxMode, VT) == Custom);
00419   }
00420 
00421   /// getIndexedStoreAction - Return how the indexed store should be treated:
00422   /// either it is legal, needs to be promoted to a larger size, needs to be
00423   /// expanded to some other code sequence, or the target has a custom expander
00424   /// for it.
00425   LegalizeAction
00426   getIndexedStoreAction(unsigned IdxMode, MVT VT) const {
00427     assert(IdxMode < array_lengthof(IndexedModeActions[1]) &&
00428            (unsigned)VT.getSimpleVT() < sizeof(IndexedModeActions[1][0])*4 &&
00429            "Table isn't big enough!");
00430     return (LegalizeAction)((IndexedModeActions[1][IdxMode] >>
00431                              (2*VT.getSimpleVT())) & 3);
00432   }  
00433 
00434   /// isIndexedStoreLegal - Return true if the specified indexed load is legal
00435   /// on this target.
00436   bool isIndexedStoreLegal(unsigned IdxMode, MVT VT) const {
00437     return VT.isSimple() &&
00438       (getIndexedStoreAction(IdxMode, VT) == Legal ||
00439        getIndexedStoreAction(IdxMode, VT) == Custom);
00440   }
00441 
00442   /// getConvertAction - Return how the conversion should be treated:
00443   /// either it is legal, needs to be promoted to a larger size, needs to be
00444   /// expanded to some other code sequence, or the target has a custom expander
00445   /// for it.
00446   LegalizeAction
00447   getConvertAction(MVT FromVT, MVT ToVT) const {
00448     assert((unsigned)FromVT.getSimpleVT() < array_lengthof(ConvertActions) &&
00449            (unsigned)ToVT.getSimpleVT() < sizeof(ConvertActions[0])*4 &&
00450            "Table isn't big enough!");
00451     return (LegalizeAction)((ConvertActions[FromVT.getSimpleVT()] >>
00452                              (2*ToVT.getSimpleVT())) & 3);
00453   }
00454 
00455   /// isConvertLegal - Return true if the specified conversion is legal
00456   /// on this target.
00457   bool isConvertLegal(MVT FromVT, MVT ToVT) const {
00458     return isTypeLegal(FromVT) && isTypeLegal(ToVT) &&
00459       (getConvertAction(FromVT, ToVT) == Legal ||
00460        getConvertAction(FromVT, ToVT) == Custom);
00461   }
00462 
00463   /// getCondCodeAction - Return how the condition code should be treated:
00464   /// either it is legal, needs to be expanded to some other code sequence,
00465   /// or the target has a custom expander for it.
00466   LegalizeAction
00467   getCondCodeAction(ISD::CondCode CC, MVT VT) const {
00468     assert((unsigned)CC < array_lengthof(CondCodeActions) &&
00469            (unsigned)VT.getSimpleVT() < sizeof(CondCodeActions[0])*4 &&
00470            "Table isn't big enough!");
00471     LegalizeAction Action = (LegalizeAction)
00472       ((CondCodeActions[CC] >> (2*VT.getSimpleVT())) & 3);
00473     assert(Action != Promote && "Can't promote condition code!");
00474     return Action;
00475   }
00476 
00477   /// isCondCodeLegal - Return true if the specified condition code is legal
00478   /// on this target.
00479   bool isCondCodeLegal(ISD::CondCode CC, MVT VT) const {
00480     return getCondCodeAction(CC, VT) == Legal ||
00481            getCondCodeAction(CC, VT) == Custom;
00482   }
00483 
00484 
00485   /// getTypeToPromoteTo - If the action for this operation is to promote, this
00486   /// method returns the ValueType to promote to.
00487   MVT getTypeToPromoteTo(unsigned Op, MVT VT) const {
00488     assert(getOperationAction(Op, VT) == Promote &&
00489            "This operation isn't promoted!");
00490 
00491     // See if this has an explicit type specified.
00492     std::map<std::pair<unsigned, MVT::SimpleValueType>,
00493              MVT::SimpleValueType>::const_iterator PTTI =
00494       PromoteToType.find(std::make_pair(Op, VT.getSimpleVT()));
00495     if (PTTI != PromoteToType.end()) return PTTI->second;
00496 
00497     assert((VT.isInteger() || VT.isFloatingPoint()) &&
00498            "Cannot autopromote this type, add it with AddPromotedToType.");
00499     
00500     MVT NVT = VT;
00501     do {
00502       NVT = (MVT::SimpleValueType)(NVT.getSimpleVT()+1);
00503       assert(NVT.isInteger() == VT.isInteger() && NVT != MVT::isVoid &&
00504              "Didn't find type to promote to!");
00505     } while (!isTypeLegal(NVT) ||
00506               getOperationAction(Op, NVT) == Promote);
00507     return NVT;
00508   }
00509 
00510   /// getValueType - Return the MVT corresponding to this LLVM type.
00511   /// This is fixed by the LLVM operations except for the pointer size.  If
00512   /// AllowUnknown is true, this will return MVT::Other for types with no MVT
00513   /// counterpart (e.g. structs), otherwise it will assert.
00514   MVT getValueType(const Type *Ty, bool AllowUnknown = false) const {
00515     MVT VT = MVT::getMVT(Ty, AllowUnknown);
00516     return VT == MVT::iPTR ? PointerTy : VT;
00517   }
00518 
00519   /// getByValTypeAlignment - Return the desired alignment for ByVal aggregate
00520   /// function arguments in the caller parameter area.  This is the actual
00521   /// alignment, not its logarithm.
00522   virtual unsigned getByValTypeAlignment(const Type *Ty) const;
00523   
00524   /// getRegisterType - Return the type of registers that this ValueType will
00525   /// eventually require.
00526   MVT getRegisterType(MVT VT) const {
00527     if (VT.isSimple()) {
00528       assert((unsigned)VT.getSimpleVT() < array_lengthof(RegisterTypeForVT));
00529       return RegisterTypeForVT[VT.getSimpleVT()];
00530     }
00531     if (VT.isVector()) {
00532       MVT VT1, RegisterVT;
00533       unsigned NumIntermediates;
00534       (void)getVectorTypeBreakdown(VT, VT1, NumIntermediates, RegisterVT);
00535       return RegisterVT;
00536     }
00537     if (VT.isInteger()) {
00538       return getRegisterType(getTypeToTransformTo(VT));
00539     }
00540     assert(0 && "Unsupported extended type!");
00541     return MVT(); // Not reached
00542   }
00543 
00544   /// getNumRegisters - Return the number of registers that this ValueType will
00545   /// eventually require.  This is one for any types promoted to live in larger
00546   /// registers, but may be more than one for types (like i64) that are split
00547   /// into pieces.  For types like i140, which are first promoted then expanded,
00548   /// it is the number of registers needed to hold all the bits of the original
00549   /// type.  For an i140 on a 32 bit machine this means 5 registers.
00550   unsigned getNumRegisters(MVT VT) const {
00551     if (VT.isSimple()) {
00552       assert((unsigned)VT.getSimpleVT() < array_lengthof(NumRegistersForVT));
00553       return NumRegistersForVT[VT.getSimpleVT()];
00554     }
00555     if (VT.isVector()) {
00556       MVT VT1, VT2;
00557       unsigned NumIntermediates;
00558       return getVectorTypeBreakdown(VT, VT1, NumIntermediates, VT2);
00559     }
00560     if (VT.isInteger()) {
00561       unsigned BitWidth = VT.getSizeInBits();
00562       unsigned RegWidth = getRegisterType(VT).getSizeInBits();
00563       return (BitWidth + RegWidth - 1) / RegWidth;
00564     }
00565     assert(0 && "Unsupported extended type!");
00566     return 0; // Not reached
00567   }
00568 
00569   /// ShouldShrinkFPConstant - If true, then instruction selection should
00570   /// seek to shrink the FP constant of the specified type to a smaller type
00571   /// in order to save space and / or reduce runtime.
00572   virtual bool ShouldShrinkFPConstant(MVT VT) const { return true; }
00573 
00574   /// hasTargetDAGCombine - If true, the target has custom DAG combine
00575   /// transformations that it can perform for the specified node.
00576   bool hasTargetDAGCombine(ISD::NodeType NT) const {
00577     assert(unsigned(NT >> 3) < array_lengthof(TargetDAGCombineArray));
00578     return TargetDAGCombineArray[NT >> 3] & (1 << (NT&7));
00579   }
00580 
00581   /// This function returns the maximum number of store operations permitted
00582   /// to replace a call to llvm.memset. The value is set by the target at the
00583   /// performance threshold for such a replacement.
00584   /// @brief Get maximum # of store operations permitted for llvm.memset
00585   unsigned getMaxStoresPerMemset() const { return maxStoresPerMemset; }
00586 
00587   /// This function returns the maximum number of store operations permitted
00588   /// to replace a call to llvm.memcpy. The value is set by the target at the
00589   /// performance threshold for such a replacement.
00590   /// @brief Get maximum # of store operations permitted for llvm.memcpy
00591   unsigned getMaxStoresPerMemcpy() const { return maxStoresPerMemcpy; }
00592 
00593   /// This function returns the maximum number of store operations permitted
00594   /// to replace a call to llvm.memmove. The value is set by the target at the
00595   /// performance threshold for such a replacement.
00596   /// @brief Get maximum # of store operations permitted for llvm.memmove
00597   unsigned getMaxStoresPerMemmove() const { return maxStoresPerMemmove; }
00598 
00599   /// This function returns true if the target allows unaligned memory accesses.
00600   /// This is used, for example, in situations where an array copy/move/set is 
00601   /// converted to a sequence of store operations. It's use helps to ensure that
00602   /// such replacements don't generate code that causes an alignment error 
00603   /// (trap) on the target machine. 
00604   /// @brief Determine if the target supports unaligned memory accesses.
00605   bool allowsUnalignedMemoryAccesses() const {
00606     return allowUnalignedMemoryAccesses;
00607   }
00608 
00609   /// getOptimalMemOpType - Returns the target specific optimal type for load
00610   /// and store operations as a result of memset, memcpy, and memmove lowering.
00611   /// It returns MVT::iAny if SelectionDAG should be responsible for
00612   /// determining it.
00613   virtual MVT getOptimalMemOpType(uint64_t Size, unsigned Align,
00614                                   bool isSrcConst, bool isSrcStr) const {
00615     return MVT::iAny;
00616   }
00617   
00618   /// usesUnderscoreSetJmp - Determine if we should use _setjmp or setjmp
00619   /// to implement llvm.setjmp.
00620   bool usesUnderscoreSetJmp() const {
00621     return UseUnderscoreSetJmp;
00622   }
00623 
00624   /// usesUnderscoreLongJmp - Determine if we should use _longjmp or longjmp
00625   /// to implement llvm.longjmp.
00626   bool usesUnderscoreLongJmp() const {
00627     return UseUnderscoreLongJmp;
00628   }
00629 
00630   /// getStackPointerRegisterToSaveRestore - If a physical register, this
00631   /// specifies the register that llvm.savestack/llvm.restorestack should save
00632   /// and restore.
00633   unsigned getStackPointerRegisterToSaveRestore() const {
00634     return StackPointerRegisterToSaveRestore;
00635   }
00636 
00637   /// getExceptionAddressRegister - If a physical register, this returns
00638   /// the register that receives the exception address on entry to a landing
00639   /// pad.
00640   unsigned getExceptionAddressRegister() const {
00641     return ExceptionPointerRegister;
00642   }
00643 
00644   /// getExceptionSelectorRegister - If a physical register, this returns
00645   /// the register that receives the exception typeid on entry to a landing
00646   /// pad.
00647   unsigned getExceptionSelectorRegister() const {
00648     return ExceptionSelectorRegister;
00649   }
00650 
00651   /// getJumpBufSize - returns the target's jmp_buf size in bytes (if never
00652   /// set, the default is 200)
00653   unsigned getJumpBufSize() const {
00654     return JumpBufSize;
00655   }
00656 
00657   /// getJumpBufAlignment - returns the target's jmp_buf alignment in bytes
00658   /// (if never set, the default is 0)
00659   unsigned getJumpBufAlignment() const {
00660     return JumpBufAlignment;
00661   }
00662 
00663   /// getIfCvtBlockLimit - returns the target specific if-conversion block size
00664   /// limit. Any block whose size is greater should not be predicated.
00665   unsigned getIfCvtBlockSizeLimit() const {
00666     return IfCvtBlockSizeLimit;
00667   }
00668 
00669   /// getIfCvtDupBlockLimit - returns the target specific size limit for a
00670   /// block to be considered for duplication. Any block whose size is greater
00671   /// should not be duplicated to facilitate its predication.
00672   unsigned getIfCvtDupBlockSizeLimit() const {
00673     return IfCvtDupBlockSizeLimit;
00674   }
00675 
00676   /// getPrefLoopAlignment - return the preferred loop alignment.
00677   ///
00678   unsigned getPrefLoopAlignment() const {
00679     return PrefLoopAlignment;
00680   }
00681   
00682   /// getPreIndexedAddressParts - returns true by value, base pointer and
00683   /// offset pointer and addressing mode by reference if the node's address
00684   /// can be legally represented as pre-indexed load / store address.
00685   virtual bool getPreIndexedAddressParts(SDNode *N, SDValue &Base,
00686                                          SDValue &Offset,
00687                                          ISD::MemIndexedMode &AM,
00688                                          SelectionDAG &DAG) const {
00689     return false;
00690   }
00691   
00692   /// getPostIndexedAddressParts - returns true by value, base pointer and
00693   /// offset pointer and addressing mode by reference if this node can be
00694   /// combined with a load / store to form a post-indexed load / store.
00695   virtual bool getPostIndexedAddressParts(SDNode *N, SDNode *Op,
00696                                           SDValue &Base, SDValue &Offset,
00697                                           ISD::MemIndexedMode &AM,
00698                                           SelectionDAG &DAG) const {
00699     return false;
00700   }
00701   
00702   /// getPICJumpTableRelocaBase - Returns relocation base for the given PIC
00703   /// jumptable.
00704   virtual SDValue getPICJumpTableRelocBase(SDValue Table,
00705                                              SelectionDAG &DAG) const;
00706 
00707   /// isOffsetFoldingLegal - Return true if folding a constant offset
00708   /// with the given GlobalAddress is legal.  It is frequently not legal in
00709   /// PIC relocation models.
00710   virtual bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const;
00711 
00712   //===--------------------------------------------------------------------===//
00713   // TargetLowering Optimization Methods
00714   //
00715   
00716   /// TargetLoweringOpt - A convenience struct that encapsulates a DAG, and two
00717   /// SDValues for returning information from TargetLowering to its clients
00718   /// that want to combine 
00719   struct TargetLoweringOpt {
00720     SelectionDAG &DAG;
00721     SDValue Old;
00722     SDValue New;
00723 
00724     explicit TargetLoweringOpt(SelectionDAG &InDAG) : DAG(InDAG) {}
00725     
00726     bool CombineTo(SDValue O, SDValue N) { 
00727       Old = O; 
00728       New = N; 
00729       return true;
00730     }
00731     
00732     /// ShrinkDemandedConstant - Check to see if the specified operand of the 
00733     /// specified instruction is a constant integer.  If so, check to see if
00734     /// there are any bits set in the constant that are not demanded.  If so,
00735     /// shrink the constant and return true.
00736     bool ShrinkDemandedConstant(SDValue Op, const APInt &Demanded);
00737   };
00738                                                 
00739   /// SimplifyDemandedBits - Look at Op.  At this point, we know that only the
00740   /// DemandedMask bits of the result of Op are ever used downstream.  If we can
00741   /// use this information to simplify Op, create a new simplified DAG node and
00742   /// return true, returning the original and new nodes in Old and New. 
00743   /// Otherwise, analyze the expression and return a mask of KnownOne and 
00744   /// KnownZero bits for the expression (used to simplify the caller).  
00745   /// The KnownZero/One bits may only be accurate for those bits in the 
00746   /// DemandedMask.
00747   bool SimplifyDemandedBits(SDValue Op, const APInt &DemandedMask, 
00748                             APInt &KnownZero, APInt &KnownOne,
00749                             TargetLoweringOpt &TLO, unsigned Depth = 0) const;
00750   
00751   /// computeMaskedBitsForTargetNode - Determine which of the bits specified in
00752   /// Mask are known to be either zero or one and return them in the 
00753   /// KnownZero/KnownOne bitsets.
00754   virtual void computeMaskedBitsForTargetNode(const SDValue Op,
00755                                               const APInt &Mask,
00756                                               APInt &KnownZero, 
00757                                               APInt &KnownOne,
00758                                               const SelectionDAG &DAG,
00759                                               unsigned Depth = 0) const;
00760 
00761   /// ComputeNumSignBitsForTargetNode - This method can be implemented by
00762   /// targets that want to expose additional information about sign bits to the
00763   /// DAG Combiner.
00764   virtual unsigned ComputeNumSignBitsForTargetNode(SDValue Op,
00765                                                    unsigned Depth = 0) const;
00766   
00767   struct DAGCombinerInfo {
00768     void *DC;  // The DAG Combiner object.
00769     bool BeforeLegalize;
00770     bool CalledByLegalizer;
00771   public:
00772     SelectionDAG &DAG;
00773     
00774     DAGCombinerInfo(SelectionDAG &dag, bool bl, bool cl, void *dc)
00775       : DC(dc), BeforeLegalize(bl), CalledByLegalizer(cl), DAG(dag) {}
00776     
00777     bool isBeforeLegalize() const { return BeforeLegalize; }
00778     bool isCalledByLegalizer() const { return CalledByLegalizer; }
00779     
00780     void AddToWorklist(SDNode *N);
00781     SDValue CombineTo(SDNode *N, const std::vector<SDValue> &To);
00782     SDValue CombineTo(SDNode *N, SDValue Res);
00783     SDValue CombineTo(SDNode *N, SDValue Res0, SDValue Res1);
00784 
00785     void CommitTargetLoweringOpt(const TargetLoweringOpt &TLO);
00786   };
00787 
00788   /// SimplifySetCC - Try to simplify a setcc built with the specified operands 
00789   /// and cc. If it is unable to simplify it, return a null SDValue.
00790   SDValue SimplifySetCC(MVT VT, SDValue N0, SDValue N1,
00791                           ISD::CondCode Cond, bool foldBooleans,
00792                           DAGCombinerInfo &DCI, DebugLoc dl) const;
00793 
00794   /// isGAPlusOffset - Returns true (and the GlobalValue and the offset) if the
00795   /// node is a GlobalAddress + offset.
00796   virtual bool
00797   isGAPlusOffset(SDNode *N, GlobalValue* &GA, int64_t &Offset) const;
00798 
00799   /// isConsecutiveLoad - Return true if LD (which must be a LoadSDNode) is
00800   /// loading 'Bytes' bytes from a location that is 'Dist' units away from the
00801   /// location that the 'Base' load is loading from.
00802   bool isConsecutiveLoad(SDNode *LD, SDNode *Base, unsigned Bytes, int Dist,
00803                          const MachineFrameInfo *MFI) const;
00804 
00805   /// PerformDAGCombine - This method will be invoked for all target nodes and
00806   /// for any target-independent nodes that the target has registered with
00807   /// invoke it for.
00808   ///
00809   /// The semantics are as follows:
00810   /// Return Value:
00811   ///   SDValue.Val == 0   - No change was made
00812   ///   SDValue.Val == N   - N was replaced, is dead, and is already handled.
00813   ///   otherwise          - N should be replaced by the returned Operand.
00814   ///
00815   /// In addition, methods provided by DAGCombinerInfo may be used to perform
00816   /// more complex transformations.
00817   ///
00818   virtual SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const;
00819   
00820   //===--------------------------------------------------------------------===//
00821   // TargetLowering Configuration Methods - These methods should be invoked by
00822   // the derived class constructor to configure this object for the target.
00823   //
00824 
00825 protected:
00826   /// setUsesGlobalOffsetTable - Specify that this target does or doesn't use a
00827   /// GOT for PC-relative code.
00828   void setUsesGlobalOffsetTable(bool V) { UsesGlobalOffsetTable = V; }
00829 
00830   /// setShiftAmountType - Describe the type that should be used for shift
00831   /// amounts.  This type defaults to the pointer type.
00832   void setShiftAmountType(MVT VT) { ShiftAmountTy = VT; }
00833 
00834   /// setBooleanContents - Specify how the target extends the result of a
00835   /// boolean value from i1 to a wider type.  See getBooleanContents.
00836   void setBooleanContents(BooleanContent Ty) { BooleanContents = Ty; }
00837 
00838   /// setSchedulingPreference - Specify the target scheduling preference.
00839   void setSchedulingPreference(SchedPreference Pref) {
00840     SchedPreferenceInfo = Pref;
00841   }
00842 
00843   /// setShiftAmountFlavor - Describe how the target handles out of range shift
00844   /// amounts.
00845   void setShiftAmountFlavor(OutOfRangeShiftAmount OORSA) {
00846     ShiftAmtHandling = OORSA;
00847   }
00848 
00849   /// setUseUnderscoreSetJmp - Indicate whether this target prefers to
00850   /// use _setjmp to implement llvm.setjmp or the non _ version.
00851   /// Defaults to false.
00852   void setUseUnderscoreSetJmp(bool Val) {
00853     UseUnderscoreSetJmp = Val;
00854   }
00855 
00856   /// setUseUnderscoreLongJmp - Indicate whether this target prefers to
00857   /// use _longjmp to implement llvm.longjmp or the non _ version.
00858   /// Defaults to false.
00859   void setUseUnderscoreLongJmp(bool Val) {
00860     UseUnderscoreLongJmp = Val;
00861   }
00862 
00863   /// setStackPointerRegisterToSaveRestore - If set to a physical register, this
00864   /// specifies the register that llvm.savestack/llvm.restorestack should save
00865   /// and restore.
00866   void setStackPointerRegisterToSaveRestore(unsigned R) {
00867     StackPointerRegisterToSaveRestore = R;
00868   }
00869   
00870   /// setExceptionPointerRegister - If set to a physical register, this sets
00871   /// the register that receives the exception address on entry to a landing
00872   /// pad.
00873   void setExceptionPointerRegister(unsigned R) {
00874     ExceptionPointerRegister = R;
00875   }
00876 
00877   /// setExceptionSelectorRegister - If set to a physical register, this sets
00878   /// the register that receives the exception typeid on entry to a landing
00879   /// pad.
00880   void setExceptionSelectorRegister(unsigned R) {
00881     ExceptionSelectorRegister = R;
00882   }
00883 
00884   /// SelectIsExpensive - Tells the code generator not to expand operations
00885   /// into sequences that use the select operations if possible.
00886   void setSelectIsExpensive() { SelectIsExpensive = true; }
00887 
00888   /// setIntDivIsCheap - Tells the code generator that integer divide is
00889   /// expensive, and if possible, should be replaced by an alternate sequence
00890   /// of instructions not containing an integer divide.
00891   void setIntDivIsCheap(bool isCheap = true) { IntDivIsCheap = isCheap; }
00892   
00893   /// setPow2DivIsCheap - Tells the code generator that it shouldn't generate
00894   /// srl/add/sra for a signed divide by power of two, and let the target handle
00895   /// it.
00896   void setPow2DivIsCheap(bool isCheap = true) { Pow2DivIsCheap = isCheap; }
00897   
00898   /// addRegisterClass - Add the specified register class as an available
00899   /// regclass for the specified value type.  This indicates the selector can
00900   /// handle values of that class natively.
00901   void addRegisterClass(MVT VT, TargetRegisterClass *RC) {
00902     assert((unsigned)VT.getSimpleVT() < array_lengthof(RegClassForVT));
00903     AvailableRegClasses.push_back(std::make_pair(VT, RC));
00904     RegClassForVT[VT.getSimpleVT()] = RC;
00905   }
00906 
00907   /// computeRegisterProperties - Once all of the register classes are added,
00908   /// this allows us to compute derived properties we expose.
00909   void computeRegisterProperties();
00910 
00911   /// setOperationAction - Indicate that the specified operation does not work
00912   /// with the specified type and indicate what to do about it.
00913   void setOperationAction(unsigned Op, MVT VT,
00914                           LegalizeAction Action) {
00915     assert((unsigned)VT.getSimpleVT() < sizeof(OpActions[0])*4 &&
00916            Op < array_lengthof(OpActions) && "Table isn't big enough!");
00917     OpActions[Op] &= ~(uint64_t(3UL) << VT.getSimpleVT()*2);
00918     OpActions[Op] |= (uint64_t)Action << VT.getSimpleVT()*2;
00919   }
00920   
00921   /// setLoadExtAction - Indicate that the specified load with extension does
00922   /// not work with the with specified type and indicate what to do about it.
00923   void setLoadExtAction(unsigned ExtType, MVT VT,
00924                       LegalizeAction Action) {
00925     assert((unsigned)VT.getSimpleVT() < sizeof(LoadExtActions[0])*4 &&
00926            ExtType < array_lengthof(LoadExtActions) &&
00927            "Table isn't big enough!");
00928     LoadExtActions[ExtType] &= ~(uint64_t(3UL) << VT.getSimpleVT()*2);
00929     LoadExtActions[ExtType] |= (uint64_t)Action << VT.getSimpleVT()*2;
00930   }
00931   
00932   /// setTruncStoreAction - Indicate that the specified truncating store does
00933   /// not work with the with specified type and indicate what to do about it.
00934   void setTruncStoreAction(MVT ValVT, MVT MemVT,
00935                            LegalizeAction Action) {
00936     assert((unsigned)ValVT.getSimpleVT() < array_lengthof(TruncStoreActions) &&
00937            (unsigned)MemVT.getSimpleVT() < sizeof(TruncStoreActions[0])*4 &&
00938            "Table isn't big enough!");
00939     TruncStoreActions[ValVT.getSimpleVT()] &= ~(uint64_t(3UL) <<
00940                                                 MemVT.getSimpleVT()*2);
00941     TruncStoreActions[ValVT.getSimpleVT()] |= (uint64_t)Action <<
00942       MemVT.getSimpleVT()*2;
00943   }
00944 
00945   /// setIndexedLoadAction - Indicate that the specified indexed load does or
00946   /// does not work with the with specified type and indicate what to do abort
00947   /// it. NOTE: All indexed mode loads are initialized to Expand in
00948   /// TargetLowering.cpp
00949   void setIndexedLoadAction(unsigned IdxMode, MVT VT,
00950                             LegalizeAction Action) {
00951     assert((unsigned)VT.getSimpleVT() < sizeof(IndexedModeActions[0])*4 &&
00952            IdxMode < array_lengthof(IndexedModeActions[0]) &&
00953            "Table isn't big enough!");
00954     IndexedModeActions[0][IdxMode] &= ~(uint64_t(3UL) << VT.getSimpleVT()*2);
00955     IndexedModeActions[0][IdxMode] |= (uint64_t)Action << VT.getSimpleVT()*2;
00956   }
00957   
00958   /// setIndexedStoreAction - Indicate that the specified indexed store does or
00959   /// does not work with the with specified type and indicate what to do about
00960   /// it. NOTE: All indexed mode stores are initialized to Expand in
00961   /// TargetLowering.cpp
00962   void setIndexedStoreAction(unsigned IdxMode, MVT VT,
00963                              LegalizeAction Action) {
00964     assert((unsigned)VT.getSimpleVT() < sizeof(IndexedModeActions[1][0])*4 &&
00965            IdxMode < array_lengthof(IndexedModeActions[1]) &&
00966            "Table isn't big enough!");
00967     IndexedModeActions[1][IdxMode] &= ~(uint64_t(3UL) << VT.getSimpleVT()*2);
00968     IndexedModeActions[1][IdxMode] |= (uint64_t)Action << VT.getSimpleVT()*2;
00969   }
00970   
00971   /// setConvertAction - Indicate that the specified conversion does or does
00972   /// not work with the with specified type and indicate what to do about it.
00973   void setConvertAction(MVT FromVT, MVT ToVT,
00974                         LegalizeAction Action) {
00975     assert((unsigned)FromVT.getSimpleVT() < array_lengthof(ConvertActions) &&
00976            (unsigned)ToVT.getSimpleVT() < sizeof(ConvertActions[0])*4 &&
00977            "Table isn't big enough!");
00978     ConvertActions[FromVT.getSimpleVT()] &= ~(uint64_t(3UL) <<
00979                                               ToVT.getSimpleVT()*2);
00980     ConvertActions[FromVT.getSimpleVT()] |= (uint64_t)Action <<
00981       ToVT.getSimpleVT()*2;
00982   }
00983 
00984   /// setCondCodeAction - Indicate that the specified condition code is or isn't
00985   /// supported on the target and indicate what to do about it.
00986   void setCondCodeAction(ISD::CondCode CC, MVT VT, LegalizeAction Action) {
00987     assert((unsigned)VT.getSimpleVT() < sizeof(CondCodeActions[0])*4 &&
00988            (unsigned)CC < array_lengthof(CondCodeActions) &&
00989            "Table isn't big enough!");
00990     CondCodeActions[(unsigned)CC] &= ~(uint64_t(3UL) << VT.getSimpleVT()*2);
00991     CondCodeActions[(unsigned)CC] |= (uint64_t)Action << VT.getSimpleVT()*2;
00992   }
00993 
00994   /// AddPromotedToType - If Opc/OrigVT is specified as being promoted, the
00995   /// promotion code defaults to trying a larger integer/fp until it can find
00996   /// one that works.  If that default is insufficient, this method can be used
00997   /// by the target to override the default.
00998   void AddPromotedToType(unsigned Opc, MVT OrigVT, MVT DestVT) {
00999     PromoteToType[std::make_pair(Opc, OrigVT.getSimpleVT())] =
01000       DestVT.getSimpleVT();
01001   }
01002 
01003   /// addLegalFPImmediate - Indicate that this target can instruction select
01004   /// the specified FP immediate natively.
01005   void addLegalFPImmediate(const APFloat& Imm) {
01006     LegalFPImmediates.push_back(Imm);
01007   }
01008 
01009   /// setTargetDAGCombine - Targets should invoke this method for each target
01010   /// independent node that they want to provide a custom DAG combiner for by
01011   /// implementing the PerformDAGCombine virtual method.
01012   void setTargetDAGCombine(ISD::NodeType NT) {
01013     assert(unsigned(NT >> 3) < array_lengthof(TargetDAGCombineArray));
01014     TargetDAGCombineArray[NT >> 3] |= 1 << (NT&7);
01015   }
01016   
01017   /// setJumpBufSize - Set the target's required jmp_buf buffer size (in
01018   /// bytes); default is 200
01019   void setJumpBufSize(unsigned Size) {
01020     JumpBufSize = Size;
01021   }
01022 
01023   /// setJumpBufAlignment - Set the target's required jmp_buf buffer
01024   /// alignment (in bytes); default is 0
01025   void setJumpBufAlignment(unsigned Align) {
01026     JumpBufAlignment = Align;
01027   }
01028 
01029   /// setIfCvtBlockSizeLimit - Set the target's if-conversion block size
01030   /// limit (in number of instructions); default is 2.
01031   void setIfCvtBlockSizeLimit(unsigned Limit) {
01032     IfCvtBlockSizeLimit = Limit;
01033   }
01034   
01035   /// setIfCvtDupBlockSizeLimit - Set the target's block size limit (in number
01036   /// of instructions) to be considered for code duplication during
01037   /// if-conversion; default is 2.
01038   void setIfCvtDupBlockSizeLimit(unsigned Limit) {
01039     IfCvtDupBlockSizeLimit = Limit;
01040   }
01041 
01042   /// setPrefLoopAlignment - Set the target's preferred loop alignment. Default
01043   /// alignment is zero, it means the target does not care about loop alignment.
01044   void setPrefLoopAlignment(unsigned Align) {
01045     PrefLoopAlignment = Align;
01046   }
01047   
01048 public:
01049 
01050   virtual const TargetSubtarget *getSubtarget() {
01051     assert(0 && "Not Implemented");
01052     return NULL;    // this is here to silence compiler errors
01053   }
01054   //===--------------------------------------------------------------------===//
01055   // Lowering methods - These methods must be implemented by targets so that
01056   // the SelectionDAGLowering code knows how to lower these.
01057   //
01058 
01059   /// LowerArguments - This hook must be implemented to indicate how we should
01060   /// lower the arguments for the specified function, into the specified DAG.
01061   virtual void
01062   LowerArguments(Function &F, SelectionDAG &DAG,
01063                  SmallVectorImpl<SDValue>& ArgValues, DebugLoc dl);
01064 
01065   /// LowerCallTo - This hook lowers an abstract call to a function into an
01066   /// actual call.  This returns a pair of operands.  The first element is the
01067   /// return value for the function (if RetTy is not VoidTy).  The second
01068   /// element is the outgoing token chain.
01069   struct ArgListEntry {
01070     SDValue Node;
01071     const Type* Ty;
01072     bool isSExt  : 1;
01073     bool isZExt  : 1;
01074     bool isInReg : 1;
01075     bool isSRet  : 1;
01076     bool isNest  : 1;
01077     bool isByVal : 1;
01078     uint16_t Alignment;
01079 
01080     ArgListEntry() : isSExt(false), isZExt(false), isInReg(false),
01081       isSRet(false), isNest(false), isByVal(false), Alignment(0) { }
01082   };
01083   typedef std::vector<ArgListEntry> ArgListTy;
01084   virtual std::pair<SDValue, SDValue>
01085   LowerCallTo(SDValue Chain, const Type *RetTy, bool RetSExt, bool RetZExt,
01086               bool isVarArg, bool isInreg, unsigned CallingConv, 
01087               bool isTailCall, SDValue Callee, ArgListTy &Args, 
01088               SelectionDAG &DAG, DebugLoc dl);
01089 
01090   /// EmitTargetCodeForMemcpy - Emit target-specific code that performs a
01091   /// memcpy. This can be used by targets to provide code sequences for cases
01092   /// that don't fit the target's parameters for simple loads/stores and can be
01093   /// more efficient than using a library call. This function can return a null
01094   /// SDValue if the target declines to use custom code and a different
01095   /// lowering strategy should be used.
01096   /// 
01097   /// If AlwaysInline is true, the size is constant and the target should not
01098   /// emit any calls and is strongly encouraged to attempt to emit inline code
01099   /// even if it is beyond the usual threshold because this intrinsic is being
01100   /// expanded in a place where calls are not feasible (e.g. within the prologue
01101   /// for another call). If the target chooses to decline an AlwaysInline
01102   /// request here, legalize will resort to using simple loads and stores.
01103   virtual SDValue
01104   EmitTargetCodeForMemcpy(SelectionDAG &DAG,
01105                           SDValue Chain,
01106                           SDValue Op1, SDValue Op2,
01107                           SDValue Op3, unsigned Align,
01108                           bool AlwaysInline,
01109                           const Value *DstSV, uint64_t DstOff,
01110                           const Value *SrcSV, uint64_t SrcOff) {
01111     return SDValue();
01112   }
01113 
01114   /// EmitTargetCodeForMemmove - Emit target-specific code that performs a
01115   /// memmove. This can be used by targets to provide code sequences for cases
01116   /// that don't fit the target's parameters for simple loads/stores and can be
01117   /// more efficient than using a library call. This function can return a null
01118   /// SDValue if the target declines to use custom code and a different
01119   /// lowering strategy should be used.
01120   virtual SDValue
01121   EmitTargetCodeForMemmove(SelectionDAG &DAG,
01122                            SDValue Chain,
01123                            SDValue Op1, SDValue Op2,
01124                            SDValue Op3, unsigned Align,
01125                            const Value *DstSV, uint64_t DstOff,
01126                            const Value *SrcSV, uint64_t SrcOff) {
01127     return SDValue();
01128   }
01129 
01130   /// EmitTargetCodeForMemset - Emit target-specific code that performs a
01131   /// memset. This can be used by targets to provide code sequences for cases
01132   /// that don't fit the target's parameters for simple stores and can be more
01133   /// efficient than using a library call. This function can return a null
01134   /// SDValue if the target declines to use custom code and a different
01135   /// lowering strategy should be used.
01136   virtual SDValue
01137   EmitTargetCodeForMemset(SelectionDAG &DAG,
01138                           SDValue Chain,
01139                           SDValue Op1, SDValue Op2,
01140                           SDValue Op3, unsigned Align,
01141                           const Value *DstSV, uint64_t DstOff) {
01142     return SDValue();
01143   }
01144 
01145   /// LowerOperationWrapper - This callback is invoked by the type legalizer
01146   /// to legalize nodes with an illegal operand type but legal result types.
01147   /// It replaces the LowerOperation callback in the type Legalizer.
01148   /// The reason we can not do away with LowerOperation entirely is that
01149   /// LegalizeDAG isn't yet ready to use this callback.
01150   /// TODO: Consider merging with ReplaceNodeResults.
01151 
01152   /// The target places new result values for the node in Results (their number
01153   /// and types must exactly match those of the original return values of
01154   /// the node), or leaves Results empty, which indicates that the node is not
01155   /// to be custom lowered after all.
01156   /// The default implementation calls LowerOperation.
01157   virtual void LowerOperationWrapper(SDNode *N,
01158                                      SmallVectorImpl<SDValue> &Results,
01159                                      SelectionDAG &DAG);
01160 
01161   /// LowerOperation - This callback is invoked for operations that are 
01162   /// unsupported by the target, which are registered to use 'custom' lowering,
01163   /// and whose defined values are all legal.
01164   /// If the target has no operations that require custom lowering, it need not
01165   /// implement this.  The default implementation of this aborts.
01166   virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG);
01167 
01168   /// ReplaceNodeResults - This callback is invoked when a node result type is
01169   /// illegal for the target, and the operation was registered to use 'custom'
01170   /// lowering for that result type.  The target places new result values for
01171   /// the node in Results (their number and types must exactly match those of
01172   /// the original return values of the node), or leaves Results empty, which
01173   /// indicates that the node is not to be custom lowered after all.
01174   ///
01175   /// If the target has no operations that require custom lowering, it need not
01176   /// implement this.  The default implementation aborts.
01177   virtual void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue> &Results,
01178                                   SelectionDAG &DAG) {
01179     assert(0 && "ReplaceNodeResults not implemented for this target!");
01180   }
01181 
01182   /// IsEligibleForTailCallOptimization - Check whether the call is eligible for
01183   /// tail call optimization. Targets which want to do tail call optimization
01184   /// should override this function. 
01185   virtual bool IsEligibleForTailCallOptimization(CallSDNode *Call, 
01186                                                  SDValue Ret, 
01187                                                  SelectionDAG &DAG) const {
01188     return false;
01189   }
01190 
01191   /// CheckTailCallReturnConstraints - Check whether CALL node immediatly
01192   /// preceeds the RET node and whether the return uses the result of the node
01193   /// or is a void return. This function can be used by the target to determine
01194   /// eligiblity of tail call optimization.
01195   static bool CheckTailCallReturnConstraints(CallSDNode *TheCall, SDValue Ret) {
01196     unsigned NumOps = Ret.getNumOperands();
01197     if ((NumOps == 1 &&
01198        (Ret.getOperand(0) == SDValue(TheCall,1) ||
01199         Ret.getOperand(0) == SDValue(TheCall,0))) ||
01200       (NumOps > 1 &&
01201        Ret.getOperand(0) == SDValue(TheCall,
01202                                     TheCall->getNumValues()-1) &&
01203        Ret.getOperand(1) == SDValue(TheCall,0)))
01204       return true;
01205     return false;
01206   }
01207 
01208   /// GetPossiblePreceedingTailCall - Get preceeding TailCallNodeOpCode node if
01209   /// it exists. Skip a possible ISD::TokenFactor.
01210   static SDValue GetPossiblePreceedingTailCall(SDValue Chain,
01211                                                  unsigned TailCallNodeOpCode) {
01212     if (Chain.getOpcode() == TailCallNodeOpCode) {
01213       return Chain;
01214     } else if (Chain.getOpcode() == ISD::TokenFactor) {
01215       if (Chain.getNumOperands() &&
01216           Chain.getOperand(0).getOpcode() == TailCallNodeOpCode)
01217         return Chain.getOperand(0);
01218     }
01219     return Chain;
01220   }
01221 
01222   /// getTargetNodeName() - This method returns the name of a target specific
01223   /// DAG node.
01224   virtual const char *getTargetNodeName(unsigned Opcode) const;
01225 
01226   /// createFastISel - This method returns a target specific FastISel object,
01227   /// or null if the target does not support "fast" ISel.
01228   virtual FastISel *
01229   createFastISel(MachineFunction &,
01230                  MachineModuleInfo *, DwarfWriter *,
01231                  DenseMap<const Value *, unsigned> &,
01232                  DenseMap<const BasicBlock *, MachineBasicBlock *> &,
01233                  DenseMap<const AllocaInst *, int> &
01234 #ifndef NDEBUG
01235                  , SmallSet<Instruction*, 8> &CatchInfoLost
01236 #endif
01237                  ) {
01238     return 0;
01239   }
01240 
01241   //===--------------------------------------------------------------------===//
01242   // Inline Asm Support hooks
01243   //
01244   
01245   enum ConstraintType {
01246     C_Register,            // Constraint represents specific register(s).
01247     C_RegisterClass,       // Constraint represents any of register(s) in class.
01248     C_Memory,              // Memory constraint.
01249     C_Other,               // Something else.
01250     C_Unknown              // Unsupported constraint.
01251   };
01252   
01253   /// AsmOperandInfo - This contains information for each constraint that we are
01254   /// lowering.
01255   struct AsmOperandInfo : public InlineAsm::ConstraintInfo {
01256     /// ConstraintCode - This contains the actual string for the code, like "m".
01257     /// TargetLowering picks the 'best' code from ConstraintInfo::Codes that
01258     /// most closely matches the operand.
01259     std::string ConstraintCode;
01260 
01261     /// ConstraintType - Information about the constraint code, e.g. Register,
01262     /// RegisterClass, Memory, Other, Unknown.
01263     TargetLowering::ConstraintType ConstraintType;
01264   
01265     /// CallOperandval - If this is the result output operand or a
01266     /// clobber, this is null, otherwise it is the incoming operand to the
01267     /// CallInst.  This gets modified as the asm is processed.
01268     Value *CallOperandVal;
01269   
01270     /// ConstraintVT - The ValueType for the operand value.
01271     MVT ConstraintVT;
01272     
01273     /// isMatchingInputConstraint - Return true of this is an input operand that
01274     /// is a matching constraint like "4".
01275     bool isMatchingInputConstraint() const;
01276     
01277     /// getMatchedOperand - If this is an input matching constraint, this method
01278     /// returns the output operand it matches.
01279     unsigned getMatchedOperand() const;
01280   
01281     AsmOperandInfo(const InlineAsm::ConstraintInfo &info)
01282       : InlineAsm::ConstraintInfo(info), 
01283         ConstraintType(TargetLowering::C_Unknown),
01284         CallOperandVal(0), ConstraintVT(MVT::Other) {
01285     }
01286   };
01287 
01288   /// ComputeConstraintToUse - Determines the constraint code and constraint
01289   /// type to use for the specific AsmOperandInfo, setting
01290   /// OpInfo.ConstraintCode and OpInfo.ConstraintType.  If the actual operand
01291   /// being passed in is available, it can be passed in as Op, otherwise an
01292   /// empty SDValue can be passed. If hasMemory is true it means one of the asm
01293   /// constraint of the inline asm instruction being processed is 'm'.
01294   virtual void ComputeConstraintToUse(AsmOperandInfo &OpInfo,
01295                                       SDValue Op,
01296                                       bool hasMemory,
01297                                       SelectionDAG *DAG = 0) const;
01298   
01299   /// getConstraintType - Given a constraint, return the type of constraint it
01300   /// is for this target.
01301   virtual ConstraintType getConstraintType(const std::string &Constraint) const;
01302   
01303   /// getRegClassForInlineAsmConstraint - Given a constraint letter (e.g. "r"),
01304   /// return a list of registers that can be used to satisfy the constraint.
01305   /// This should only be used for C_RegisterClass constraints.
01306   virtual std::vector<unsigned> 
01307   getRegClassForInlineAsmConstraint(const std::string &Constraint,
01308                                     MVT VT) const;
01309 
01310   /// getRegForInlineAsmConstraint - Given a physical register constraint (e.g.
01311   /// {edx}), return the register number and the register class for the
01312   /// register.
01313   ///
01314   /// Given a register class constraint, like 'r', if this corresponds directly
01315   /// to an LLVM register class, return a register of 0 and the register class
01316   /// pointer.
01317   ///
01318   /// This should only be used for C_Register constraints.  On error,
01319   /// this returns a register number of 0 and a null register class pointer..
01320   virtual std::pair<unsigned, const TargetRegisterClass*> 
01321     getRegForInlineAsmConstraint(const std::string &Constraint,
01322                                  MVT VT) const;
01323   
01324   /// LowerXConstraint - try to replace an X constraint, which matches anything,
01325   /// with another that has more specific requirements based on the type of the
01326   /// corresponding operand.  This returns null if there is no replacement to
01327   /// make.
01328   virtual const char *LowerXConstraint(MVT ConstraintVT) const;
01329   
01330   /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops
01331   /// vector.  If it is invalid, don't add anything to Ops. If hasMemory is true
01332   /// it means one of the asm constraint of the inline asm instruction being
01333   /// processed is 'm'.
01334   virtual void LowerAsmOperandForConstraint(SDValue Op, char ConstraintLetter,
01335                                             bool hasMemory,
01336                                             std::vector<SDValue> &Ops,
01337                                             SelectionDAG &DAG) const;
01338   
01339   //===--------------------------------------------------------------------===//
01340   // Scheduler hooks
01341   //
01342   
01343   // EmitInstrWithCustomInserter - This method should be implemented by targets
01344   // that mark instructions with the 'usesCustomDAGSchedInserter' flag.  These
01345   // instructions are special in various ways, which require special support to
01346   // insert.  The specified MachineInstr is created but not inserted into any
01347   // basic blocks, and the scheduler passes ownership of it to this method.
01348   virtual MachineBasicBlock *EmitInstrWithCustomInserter(MachineInstr *MI,
01349                                                         MachineBasicBlock *MBB);
01350 
01351   //===--------------------------------------------------------------------===//
01352   // Addressing mode description hooks (used by LSR etc).
01353   //
01354 
01355   /// AddrMode - This represents an addressing mode of:
01356   ///    BaseGV + BaseOffs + BaseReg + Scale*ScaleReg
01357   /// If BaseGV is null,  there is no BaseGV.
01358   /// If BaseOffs is zero, there is no base offset.
01359   /// If HasBaseReg is false, there is no base register.
01360   /// If Scale is zero, there is no ScaleReg.  Scale of 1 indicates a reg with
01361   /// no scale.
01362   ///
01363   struct AddrMode {
01364     GlobalValue *BaseGV;
01365     int64_t      BaseOffs;
01366     bool         HasBaseReg;
01367     int64_t      Scale;
01368     AddrMode() : BaseGV(0), BaseOffs(0), HasBaseReg(false), Scale(0) {}
01369   };
01370   
01371   /// isLegalAddressingMode - Return true if the addressing mode represented by
01372   /// AM is legal for this target, for a load/store of the specified type.
01373   /// TODO: Handle pre/postinc as well.
01374   virtual bool isLegalAddressingMode(const AddrMode &AM, const Type *Ty) const;
01375 
01376   /// isTruncateFree - Return true if it's free to truncate a value of
01377   /// type Ty1 to type Ty2. e.g. On x86 it's free to truncate a i32 value in
01378   /// register EAX to i16 by referencing its sub-register AX.
01379   virtual bool isTruncateFree(const Type *Ty1, const Type *Ty2) const {
01380     return false;
01381   }
01382 
01383   virtual bool isTruncateFree(MVT VT1, MVT VT2) const {
01384     return false;
01385   }
01386   
01387   //===--------------------------------------------------------------------===//
01388   // Div utility functions
01389   //
01390   SDValue BuildSDIV(SDNode *N, SelectionDAG &DAG, 
01391                       std::vector<SDNode*>* Created) const;
01392   SDValue BuildUDIV(SDNode *N, SelectionDAG &DAG, 
01393                       std::vector<SDNode*>* Created) const;
01394 
01395 
01396   //===--------------------------------------------------------------------===//
01397   // Runtime Library hooks
01398   //
01399 
01400   /// setLibcallName - Rename the default libcall routine name for the specified
01401   /// libcall.
01402   void setLibcallName(RTLIB::Libcall Call, const char *Name) {
01403     LibcallRoutineNames[Call] = Name;
01404   }
01405 
01406   /// getLibcallName - Get the libcall routine name for the specified libcall.
01407   ///
01408   const char *getLibcallName(RTLIB::Libcall Call) const {
01409     return LibcallRoutineNames[Call];
01410   }
01411 
01412   /// setCmpLibcallCC - Override the default CondCode to be used to test the
01413   /// result of the comparison libcall against zero.
01414   void setCmpLibcallCC(RTLIB::Libcall Call, ISD::CondCode CC) {
01415     CmpLibcallCCs[Call] = CC;
01416   }
01417 
01418   /// getCmpLibcallCC - Get the CondCode that's to be used to test the result of
01419   /// the comparison libcall against zero.
01420   ISD::CondCode getCmpLibcallCC(RTLIB::Libcall Call) const {
01421     return CmpLibcallCCs[Call];
01422   }
01423 
01424 private:
01425   TargetMachine &TM;
01426   const TargetData *TD;
01427 
01428   /// PointerTy - The type to use for pointers, usually i32 or i64.
01429   ///
01430   MVT PointerTy;
01431 
01432   /// IsLittleEndian - True if this is a little endian target.
01433   ///
01434   bool IsLittleEndian;
01435 
01436   /// UsesGlobalOffsetTable - True if this target uses a GOT for PIC codegen.
01437   ///
01438   bool UsesGlobalOffsetTable;
01439   
01440   /// SelectIsExpensive - Tells the code generator not to expand operations
01441   /// into sequences that use the select operations if possible.
01442   bool SelectIsExpensive;
01443 
01444   /// IntDivIsCheap - Tells the code generator not to expand integer divides by
01445   /// constants into a sequence of muls, adds, and shifts.  This is a hack until
01446   /// a real cost model is in place.  If we ever optimize for size, this will be
01447   /// set to true unconditionally.
01448   bool IntDivIsCheap;
01449   
01450   /// Pow2DivIsCheap - Tells the code generator that it shouldn't generate
01451   /// srl/add/sra for a signed divide by power of two, and let the target handle
01452   /// it.
01453   bool Pow2DivIsCheap;
01454   
01455   /// UseUnderscoreSetJmp - This target prefers to use _setjmp to implement
01456   /// llvm.setjmp.  Defaults to false.
01457   bool UseUnderscoreSetJmp;
01458 
01459   /// UseUnderscoreLongJmp - This target prefers to use _longjmp to implement
01460   /// llvm.longjmp.  Defaults to false.
01461   bool UseUnderscoreLongJmp;
01462 
01463   /// ShiftAmountTy - The type to use for shift amounts, usually i8 or whatever
01464   /// PointerTy is.
01465   MVT ShiftAmountTy;
01466 
01467   OutOfRangeShiftAmount ShiftAmtHandling;
01468 
01469   /// BooleanContents - Information about the contents of the high-bits in
01470   /// boolean values held in a type wider than i1.  See getBooleanContents.
01471   BooleanContent BooleanContents;
01472 
01473   /// SchedPreferenceInfo - The target scheduling preference: shortest possible
01474   /// total cycles or lowest register usage.
01475   SchedPreference SchedPreferenceInfo;
01476   
01477   /// JumpBufSize - The size, in bytes, of the target's jmp_buf buffers
01478   unsigned JumpBufSize;
01479   
01480   /// JumpBufAlignment - The alignment, in bytes, of the target's jmp_buf
01481   /// buffers
01482   unsigned JumpBufAlignment;
01483 
01484   /// IfCvtBlockSizeLimit - The maximum allowed size for a block to be
01485   /// if-converted.
01486   unsigned IfCvtBlockSizeLimit;
01487   
01488   /// IfCvtDupBlockSizeLimit - The maximum allowed size for a block to be
01489   /// duplicated during if-conversion.
01490   unsigned IfCvtDupBlockSizeLimit;
01491 
01492   /// PrefLoopAlignment - The perferred loop alignment.
01493   ///
01494   unsigned PrefLoopAlignment;
01495 
01496   /// StackPointerRegisterToSaveRestore - If set to a physical register, this
01497   /// specifies the register that llvm.savestack/llvm.restorestack should save
01498   /// and restore.
01499   unsigned StackPointerRegisterToSaveRestore;
01500 
01501   /// ExceptionPointerRegister - If set to a physical register, this specifies
01502   /// the register that receives the exception address on entry to a landing
01503   /// pad.
01504   unsigned ExceptionPointerRegister;
01505 
01506   /// ExceptionSelectorRegister - If set to a physical register, this specifies
01507   /// the register that receives the exception typeid on entry to a landing
01508   /// pad.
01509   unsigned ExceptionSelectorRegister;
01510 
01511   /// RegClassForVT - This indicates the default register class to use for
01512   /// each ValueType the target supports natively.
01513   TargetRegisterClass *RegClassForVT[MVT::LAST_VALUETYPE];
01514   unsigned char NumRegistersForVT[MVT::LAST_VALUETYPE];
01515   MVT RegisterTypeForVT[MVT::LAST_VALUETYPE];
01516 
01517   /// TransformToType - For any value types we are promoting or expanding, this
01518   /// contains the value type that we are changing to.  For Expanded types, this
01519   /// contains one step of the expand (e.g. i64 -> i32), even if there are
01520   /// multiple steps required (e.g. i64 -> i16).  For types natively supported
01521   /// by the system, this holds the same type (e.g. i32 -> i32).
01522   MVT TransformToType[MVT::LAST_VALUETYPE];
01523 
01524   /// OpActions - For each operation and each value type, keep a LegalizeAction
01525   /// that indicates how instruction selection should deal with the operation.
01526   /// Most operations are Legal (aka, supported natively by the target), but
01527   /// operations that are not should be described.  Note that operations on
01528   /// non-legal value types are not described here.
01529   uint64_t OpActions[ISD::BUILTIN_OP_END];
01530   
01531   /// LoadExtActions - For each load of load extension type and each value type,
01532   /// keep a LegalizeAction that indicates how instruction selection should deal
01533   /// with the load.
01534   uint64_t LoadExtActions[ISD::LAST_LOADEXT_TYPE];
01535   
01536   /// TruncStoreActions - For each truncating store, keep a LegalizeAction that
01537   /// indicates how instruction selection should deal with the store.
01538   uint64_t TruncStoreActions[MVT::LAST_VALUETYPE];
01539 
01540   /// IndexedModeActions - For each indexed mode and each value type, keep a
01541   /// pair of LegalizeAction that indicates how instruction selection should
01542   /// deal with the load / store.
01543   uint64_t IndexedModeActions[2][ISD::LAST_INDEXED_MODE];
01544   
01545   /// ConvertActions - For each conversion from source type to destination type,
01546   /// keep a LegalizeAction that indicates how instruction selection should
01547   /// deal with the conversion.
01548   /// Currently, this is used only for floating->floating conversions
01549   /// (FP_EXTEND and FP_ROUND).
01550   uint64_t ConvertActions[MVT::LAST_VALUETYPE];
01551 
01552   /// CondCodeActions - For each condition code (ISD::CondCode) keep a
01553   /// LegalizeAction that indicates how instruction selection should
01554   /// deal with the condition code.
01555   uint64_t CondCodeActions[ISD::SETCC_INVALID];
01556 
01557   ValueTypeActionImpl ValueTypeActions;
01558 
01559   std::vector<APFloat> LegalFPImmediates;
01560 
01561   std::vector<std::pair<MVT, TargetRegisterClass*> > AvailableRegClasses;
01562 
01563   /// TargetDAGCombineArray - Targets can specify ISD nodes that they would
01564   /// like PerformDAGCombine callbacks for by calling setTargetDAGCombine(),
01565   /// which sets a bit in this array.
01566   unsigned char
01567   TargetDAGCombineArray[(ISD::BUILTIN_OP_END+CHAR_BIT-1)/CHAR_BIT];
01568   
01569   /// PromoteToType - For operations that must be promoted to a specific type,
01570   /// this holds the destination type.  This map should be sparse, so don't hold
01571   /// it as an array.
01572   ///
01573   /// Targets add entries to this map with AddPromotedToType(..), clients access
01574   /// this with getTypeToPromoteTo(..).
01575   std::map<std::pair<unsigned, MVT::SimpleValueType>, MVT::SimpleValueType>
01576     PromoteToType;
01577 
01578   /// LibcallRoutineNames - Stores the name each libcall.
01579   ///
01580   const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL];
01581 
01582   /// CmpLibcallCCs - The ISD::CondCode that should be used to test the result
01583   /// of each of the comparison libcall against zero.
01584   ISD::CondCode CmpLibcallCCs[RTLIB::UNKNOWN_LIBCALL];
01585 
01586 protected:
01587   /// When lowering @llvm.memset this field specifies the maximum number of
01588   /// store operations that may be substituted for the call to memset. Targets
01589   /// must set this value based on the cost threshold for that target. Targets
01590   /// should assume that the memset will be done using as many of the largest
01591   /// store operations first, followed by smaller ones, if necessary, per
01592   /// alignment restrictions. For example, storing 9 bytes on a 32-bit machine
01593   /// with 16-bit alignment would result in four 2-byte stores and one 1-byte
01594   /// store.  This only applies to setting a constant array of a constant size.
01595   /// @brief Specify maximum number of store instructions per memset call.
01596   unsigned maxStoresPerMemset;
01597 
01598   /// When lowering @llvm.memcpy this field specifies the maximum number of
01599   /// store operations that may be substituted for a call to memcpy. Targets
01600   /// must set this value based on the cost threshold for that target. Targets
01601   /// should assume that the memcpy will be done using as many of the largest
01602   /// store operations first, followed by smaller ones, if necessary, per
01603   /// alignment restrictions. For example, storing 7 bytes on a 32-bit machine
01604   /// with 32-bit alignment would result in one 4-byte store, a one 2-byte store
01605   /// and one 1-byte store. This only applies to copying a constant array of
01606   /// constant size.
01607   /// @brief Specify maximum bytes of store instructions per memcpy call.
01608   unsigned maxStoresPerMemcpy;
01609 
01610   /// When lowering @llvm.memmove this field specifies the maximum number of
01611   /// store instructions that may be substituted for a call to memmove. Targets
01612   /// must set this value based on the cost threshold for that target. Targets
01613   /// should assume that the memmove will be done using as many of the largest
01614   /// store operations first, followed by smaller ones, if necessary, per
01615   /// alignment restrictions. For example, moving 9 bytes on a 32-bit machine
01616   /// with 8-bit alignment would result in nine 1-byte stores.  This only
01617   /// applies to copying a constant array of constant size.
01618   /// @brief Specify maximum bytes of store instructions per memmove call.
01619   unsigned maxStoresPerMemmove;
01620 
01621   /// This field specifies whether the target machine permits unaligned memory
01622   /// accesses.  This is used, for example, to determine the size of store 
01623   /// operations when copying small arrays and other similar tasks.
01624   /// @brief Indicate whether the target permits unaligned memory accesses.
01625   bool allowUnalignedMemoryAccesses;
01626 };
01627 } // end llvm namespace
01628 
01629 #endif