LLVM API Documentation

LegalizeTypes.h

Go to the documentation of this file.
00001 //===-- LegalizeTypes.h - Definition of the DAG Type Legalizer class ------===//
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 defines the DAGTypeLegalizer class.  This is a private interface
00011 // shared between the code that implements the SelectionDAG::LegalizeTypes
00012 // method.
00013 //
00014 //===----------------------------------------------------------------------===//
00015 
00016 #ifndef SELECTIONDAG_LEGALIZETYPES_H
00017 #define SELECTIONDAG_LEGALIZETYPES_H
00018 
00019 #define DEBUG_TYPE "legalize-types"
00020 #include "llvm/CodeGen/SelectionDAG.h"
00021 #include "llvm/Target/TargetLowering.h"
00022 #include "llvm/ADT/DenseMap.h"
00023 #include "llvm/ADT/DenseSet.h"
00024 #include "llvm/Support/Compiler.h"
00025 #include "llvm/Support/Debug.h"
00026 
00027 namespace llvm {
00028 
00029 //===----------------------------------------------------------------------===//
00030 /// DAGTypeLegalizer - This takes an arbitrary SelectionDAG as input and hacks
00031 /// on it until only value types the target machine can handle are left.  This
00032 /// involves promoting small sizes to large sizes or splitting up large values
00033 /// into small values.
00034 ///
00035 class VISIBILITY_HIDDEN DAGTypeLegalizer {
00036   TargetLowering &TLI;
00037   SelectionDAG &DAG;
00038 public:
00039   // NodeIdFlags - This pass uses the NodeId on the SDNodes to hold information
00040   // about the state of the node.  The enum has all the values.
00041   enum NodeIdFlags {
00042     /// ReadyToProcess - All operands have been processed, so this node is ready
00043     /// to be handled.
00044     ReadyToProcess = 0,
00045 
00046     /// NewNode - This is a new node, not before seen, that was created in the
00047     /// process of legalizing some other node.
00048     NewNode = -1,
00049 
00050     /// Unanalyzed - This node's ID needs to be set to the number of its
00051     /// unprocessed operands.
00052     Unanalyzed = -2,
00053 
00054     /// Processed - This is a node that has already been processed.
00055     Processed = -3
00056 
00057     // 1+ - This is a node which has this many unprocessed operands.
00058   };
00059 private:
00060   enum LegalizeAction {
00061     Legal,           // The target natively supports this type.
00062     PromoteInteger,  // Replace this integer type with a larger one.
00063     ExpandInteger,   // Split this integer type into two of half the size.
00064     SoftenFloat,     // Convert this float type to a same size integer type.
00065     ExpandFloat,     // Split this float type into two of half the size.
00066     ScalarizeVector, // Replace this one-element vector with its element type.
00067     SplitVector,     // Split this vector type into two of half the size.
00068     WidenVector      // This vector type should be widened into a larger vector.
00069   };
00070 
00071   /// ValueTypeActions - This is a bitvector that contains two bits for each
00072   /// simple value type, where the two bits correspond to the LegalizeAction
00073   /// enum from TargetLowering.  This can be queried with "getTypeAction(VT)".
00074   TargetLowering::ValueTypeActionImpl ValueTypeActions;
00075 
00076   /// getTypeAction - Return how we should legalize values of this type.
00077   LegalizeAction getTypeAction(EVT VT) const {
00078     switch (ValueTypeActions.getTypeAction(*DAG.getContext(), VT)) {
00079     default:
00080       assert(false && "Unknown legalize action!");
00081     case TargetLowering::Legal:
00082       return Legal;
00083     case TargetLowering::Promote:
00084       // Promote can mean
00085       //   1) For integers, use a larger integer type (e.g. i8 -> i32).
00086       //   2) For vectors, use a wider vector type (e.g. v3i32 -> v4i32).
00087       if (!VT.isVector())
00088         return PromoteInteger;
00089       else
00090         return WidenVector;
00091     case TargetLowering::Expand:
00092       // Expand can mean
00093       // 1) split scalar in half, 2) convert a float to an integer,
00094       // 3) scalarize a single-element vector, 4) split a vector in two.
00095       if (!VT.isVector()) {
00096         if (VT.isInteger())
00097           return ExpandInteger;
00098         else if (VT.getSizeInBits() ==
00099                  TLI.getTypeToTransformTo(*DAG.getContext(), VT).getSizeInBits())
00100           return SoftenFloat;
00101         else
00102           return ExpandFloat;
00103       } else if (VT.getVectorNumElements() == 1) {
00104         return ScalarizeVector;
00105       } else {
00106         return SplitVector;
00107       }
00108     }
00109   }
00110 
00111   /// isTypeLegal - Return true if this type is legal on this target.
00112   bool isTypeLegal(EVT VT) const {
00113     return (ValueTypeActions.getTypeAction(*DAG.getContext(), VT) == 
00114             TargetLowering::Legal);
00115   }
00116 
00117   /// IgnoreNodeResults - Pretend all of this node's results are legal.
00118   bool IgnoreNodeResults(SDNode *N) const {
00119     return N->getOpcode() == ISD::TargetConstant;
00120   }
00121 
00122   /// PromotedIntegers - For integer nodes that are below legal width, this map
00123   /// indicates what promoted value to use.
00124   DenseMap<SDValue, SDValue> PromotedIntegers;
00125 
00126   /// ExpandedIntegers - For integer nodes that need to be expanded this map
00127   /// indicates which operands are the expanded version of the input.
00128   DenseMap<SDValue, std::pair<SDValue, SDValue> > ExpandedIntegers;
00129 
00130   /// SoftenedFloats - For floating point nodes converted to integers of
00131   /// the same size, this map indicates the converted value to use.
00132   DenseMap<SDValue, SDValue> SoftenedFloats;
00133 
00134   /// ExpandedFloats - For float nodes that need to be expanded this map
00135   /// indicates which operands are the expanded version of the input.
00136   DenseMap<SDValue, std::pair<SDValue, SDValue> > ExpandedFloats;
00137 
00138   /// ScalarizedVectors - For nodes that are <1 x ty>, this map indicates the
00139   /// scalar value of type 'ty' to use.
00140   DenseMap<SDValue, SDValue> ScalarizedVectors;
00141 
00142   /// SplitVectors - For nodes that need to be split this map indicates
00143   /// which operands are the expanded version of the input.
00144   DenseMap<SDValue, std::pair<SDValue, SDValue> > SplitVectors;
00145 
00146   /// WidenedVectors - For vector nodes that need to be widened, indicates
00147   /// the widened value to use.
00148   DenseMap<SDValue, SDValue> WidenedVectors;
00149 
00150   /// ReplacedValues - For values that have been replaced with another,
00151   /// indicates the replacement value to use.
00152   DenseMap<SDValue, SDValue> ReplacedValues;
00153 
00154   /// Worklist - This defines a worklist of nodes to process.  In order to be
00155   /// pushed onto this worklist, all operands of a node must have already been
00156   /// processed.
00157   SmallVector<SDNode*, 128> Worklist;
00158 
00159 public:
00160   explicit DAGTypeLegalizer(SelectionDAG &dag)
00161     : TLI(dag.getTargetLoweringInfo()), DAG(dag),
00162     ValueTypeActions(TLI.getValueTypeActions()) {
00163     assert(MVT::LAST_VALUETYPE <= MVT::MAX_ALLOWED_VALUETYPE &&
00164            "Too many value types for ValueTypeActions to hold!");
00165   }
00166 
00167   /// run - This is the main entry point for the type legalizer.  This does a
00168   /// top-down traversal of the dag, legalizing types as it goes.  Returns
00169   /// "true" if it made any changes.
00170   bool run();
00171 
00172   void NoteDeletion(SDNode *Old, SDNode *New) {
00173     ExpungeNode(Old);
00174     ExpungeNode(New);
00175     for (unsigned i = 0, e = Old->getNumValues(); i != e; ++i)
00176       ReplacedValues[SDValue(Old, i)] = SDValue(New, i);
00177   }
00178 
00179 private:
00180   SDNode *AnalyzeNewNode(SDNode *N);
00181   void AnalyzeNewValue(SDValue &Val);
00182   void ExpungeNode(SDNode *N);
00183   void PerformExpensiveChecks();
00184   void RemapValue(SDValue &N);
00185 
00186   // Common routines.
00187   SDValue BitConvertToInteger(SDValue Op);
00188   SDValue BitConvertVectorToIntegerVector(SDValue Op);
00189   SDValue CreateStackStoreLoad(SDValue Op, EVT DestVT);
00190   bool CustomLowerNode(SDNode *N, EVT VT, bool LegalizeResult);
00191   SDValue GetVectorElementPointer(SDValue VecPtr, EVT EltVT, SDValue Index);
00192   SDValue JoinIntegers(SDValue Lo, SDValue Hi);
00193   SDValue LibCallify(RTLIB::Libcall LC, SDNode *N, bool isSigned);
00194   SDValue MakeLibCall(RTLIB::Libcall LC, EVT RetVT,
00195                       const SDValue *Ops, unsigned NumOps, bool isSigned,
00196                       DebugLoc dl);
00197   SDValue PromoteTargetBoolean(SDValue Bool, EVT VT);
00198   void ReplaceValueWith(SDValue From, SDValue To);
00199   void ReplaceValueWithHelper(SDValue From, SDValue To);
00200   void SplitInteger(SDValue Op, SDValue &Lo, SDValue &Hi);
00201   void SplitInteger(SDValue Op, EVT LoVT, EVT HiVT,
00202                     SDValue &Lo, SDValue &Hi);
00203 
00204   //===--------------------------------------------------------------------===//
00205   // Integer Promotion Support: LegalizeIntegerTypes.cpp
00206   //===--------------------------------------------------------------------===//
00207 
00208   /// GetPromotedInteger - Given a processed operand Op which was promoted to a
00209   /// larger integer type, this returns the promoted value.  The low bits of the
00210   /// promoted value corresponding to the original type are exactly equal to Op.
00211   /// The extra bits contain rubbish, so the promoted value may need to be zero-
00212   /// or sign-extended from the original type before it is usable (the helpers
00213   /// SExtPromotedInteger and ZExtPromotedInteger can do this for you).
00214   /// For example, if Op is an i16 and was promoted to an i32, then this method
00215   /// returns an i32, the lower 16 bits of which coincide with Op, and the upper
00216   /// 16 bits of which contain rubbish.
00217   SDValue GetPromotedInteger(SDValue Op) {
00218     SDValue &PromotedOp = PromotedIntegers[Op];
00219     RemapValue(PromotedOp);
00220     assert(PromotedOp.getNode() && "Operand wasn't promoted?");
00221     return PromotedOp;
00222   }
00223   void SetPromotedInteger(SDValue Op, SDValue Result);
00224 
00225   /// SExtPromotedInteger - Get a promoted operand and sign extend it to the
00226   /// final size.
00227   SDValue SExtPromotedInteger(SDValue Op) {
00228     EVT OldVT = Op.getValueType();
00229     DebugLoc dl = Op.getDebugLoc();
00230     Op = GetPromotedInteger(Op);
00231     return DAG.getNode(ISD::SIGN_EXTEND_INREG, dl, Op.getValueType(), Op,
00232                        DAG.getValueType(OldVT));
00233   }
00234 
00235   /// ZExtPromotedInteger - Get a promoted operand and zero extend it to the
00236   /// final size.
00237   SDValue ZExtPromotedInteger(SDValue Op) {
00238     EVT OldVT = Op.getValueType();
00239     DebugLoc dl = Op.getDebugLoc();
00240     Op = GetPromotedInteger(Op);
00241     return DAG.getZeroExtendInReg(Op, dl, OldVT);
00242   }
00243 
00244   // Integer Result Promotion.
00245   void PromoteIntegerResult(SDNode *N, unsigned ResNo);
00246   SDValue PromoteIntRes_AssertSext(SDNode *N);
00247   SDValue PromoteIntRes_AssertZext(SDNode *N);
00248   SDValue PromoteIntRes_Atomic1(AtomicSDNode *N);
00249   SDValue PromoteIntRes_Atomic2(AtomicSDNode *N);
00250   SDValue PromoteIntRes_BIT_CONVERT(SDNode *N);
00251   SDValue PromoteIntRes_BSWAP(SDNode *N);
00252   SDValue PromoteIntRes_BUILD_PAIR(SDNode *N);
00253   SDValue PromoteIntRes_Constant(SDNode *N);
00254   SDValue PromoteIntRes_CONVERT_RNDSAT(SDNode *N);
00255   SDValue PromoteIntRes_CTLZ(SDNode *N);
00256   SDValue PromoteIntRes_CTPOP(SDNode *N);
00257   SDValue PromoteIntRes_CTTZ(SDNode *N);
00258   SDValue PromoteIntRes_EXTRACT_VECTOR_ELT(SDNode *N);
00259   SDValue PromoteIntRes_FP_TO_XINT(SDNode *N);
00260   SDValue PromoteIntRes_INT_EXTEND(SDNode *N);
00261   SDValue PromoteIntRes_LOAD(LoadSDNode *N);
00262   SDValue PromoteIntRes_Overflow(SDNode *N);
00263   SDValue PromoteIntRes_SADDSUBO(SDNode *N, unsigned ResNo);
00264   SDValue PromoteIntRes_SDIV(SDNode *N);
00265   SDValue PromoteIntRes_SELECT(SDNode *N);
00266   SDValue PromoteIntRes_SELECT_CC(SDNode *N);
00267   SDValue PromoteIntRes_SETCC(SDNode *N);
00268   SDValue PromoteIntRes_SHL(SDNode *N);
00269   SDValue PromoteIntRes_SimpleIntBinOp(SDNode *N);
00270   SDValue PromoteIntRes_SIGN_EXTEND_INREG(SDNode *N);
00271   SDValue PromoteIntRes_SRA(SDNode *N);
00272   SDValue PromoteIntRes_SRL(SDNode *N);
00273   SDValue PromoteIntRes_TRUNCATE(SDNode *N);
00274   SDValue PromoteIntRes_UADDSUBO(SDNode *N, unsigned ResNo);
00275   SDValue PromoteIntRes_UDIV(SDNode *N);
00276   SDValue PromoteIntRes_UNDEF(SDNode *N);
00277   SDValue PromoteIntRes_VAARG(SDNode *N);
00278   SDValue PromoteIntRes_XMULO(SDNode *N, unsigned ResNo);
00279 
00280   // Integer Operand Promotion.
00281   bool PromoteIntegerOperand(SDNode *N, unsigned OperandNo);
00282   SDValue PromoteIntOp_ANY_EXTEND(SDNode *N);
00283   SDValue PromoteIntOp_BIT_CONVERT(SDNode *N);
00284   SDValue PromoteIntOp_BUILD_PAIR(SDNode *N);
00285   SDValue PromoteIntOp_BR_CC(SDNode *N, unsigned OpNo);
00286   SDValue PromoteIntOp_BRCOND(SDNode *N, unsigned OpNo);
00287   SDValue PromoteIntOp_BUILD_VECTOR(SDNode *N);
00288   SDValue PromoteIntOp_CONVERT_RNDSAT(SDNode *N);
00289   SDValue PromoteIntOp_INSERT_VECTOR_ELT(SDNode *N, unsigned OpNo);
00290   SDValue PromoteIntOp_MEMBARRIER(SDNode *N);
00291   SDValue PromoteIntOp_SCALAR_TO_VECTOR(SDNode *N);
00292   SDValue PromoteIntOp_SELECT(SDNode *N, unsigned OpNo);
00293   SDValue PromoteIntOp_SELECT_CC(SDNode *N, unsigned OpNo);
00294   SDValue PromoteIntOp_SETCC(SDNode *N, unsigned OpNo);
00295   SDValue PromoteIntOp_Shift(SDNode *N);
00296   SDValue PromoteIntOp_SIGN_EXTEND(SDNode *N);
00297   SDValue PromoteIntOp_SINT_TO_FP(SDNode *N);
00298   SDValue PromoteIntOp_STORE(StoreSDNode *N, unsigned OpNo);
00299   SDValue PromoteIntOp_TRUNCATE(SDNode *N);
00300   SDValue PromoteIntOp_UINT_TO_FP(SDNode *N);
00301   SDValue PromoteIntOp_ZERO_EXTEND(SDNode *N);
00302 
00303   void PromoteSetCCOperands(SDValue &LHS,SDValue &RHS, ISD::CondCode Code);
00304 
00305   //===--------------------------------------------------------------------===//
00306   // Integer Expansion Support: LegalizeIntegerTypes.cpp
00307   //===--------------------------------------------------------------------===//
00308 
00309   /// GetExpandedInteger - Given a processed operand Op which was expanded into
00310   /// two integers of half the size, this returns the two halves.  The low bits
00311   /// of Op are exactly equal to the bits of Lo; the high bits exactly equal Hi.
00312   /// For example, if Op is an i64 which was expanded into two i32's, then this
00313   /// method returns the two i32's, with Lo being equal to the lower 32 bits of
00314   /// Op, and Hi being equal to the upper 32 bits.
00315   void GetExpandedInteger(SDValue Op, SDValue &Lo, SDValue &Hi);
00316   void SetExpandedInteger(SDValue Op, SDValue Lo, SDValue Hi);
00317 
00318   // Integer Result Expansion.
00319   void ExpandIntegerResult(SDNode *N, unsigned ResNo);
00320   void ExpandIntRes_ANY_EXTEND        (SDNode *N, SDValue &Lo, SDValue &Hi);
00321   void ExpandIntRes_AssertSext        (SDNode *N, SDValue &Lo, SDValue &Hi);
00322   void ExpandIntRes_AssertZext        (SDNode *N, SDValue &Lo, SDValue &Hi);
00323   void ExpandIntRes_Constant          (SDNode *N, SDValue &Lo, SDValue &Hi);
00324   void ExpandIntRes_CTLZ              (SDNode *N, SDValue &Lo, SDValue &Hi);
00325   void ExpandIntRes_CTPOP             (SDNode *N, SDValue &Lo, SDValue &Hi);
00326   void ExpandIntRes_CTTZ              (SDNode *N, SDValue &Lo, SDValue &Hi);
00327   void ExpandIntRes_LOAD          (LoadSDNode *N, SDValue &Lo, SDValue &Hi);
00328   void ExpandIntRes_SIGN_EXTEND       (SDNode *N, SDValue &Lo, SDValue &Hi);
00329   void ExpandIntRes_SIGN_EXTEND_INREG (SDNode *N, SDValue &Lo, SDValue &Hi);
00330   void ExpandIntRes_TRUNCATE          (SDNode *N, SDValue &Lo, SDValue &Hi);
00331   void ExpandIntRes_ZERO_EXTEND       (SDNode *N, SDValue &Lo, SDValue &Hi);
00332   void ExpandIntRes_FP_TO_SINT        (SDNode *N, SDValue &Lo, SDValue &Hi);
00333   void ExpandIntRes_FP_TO_UINT        (SDNode *N, SDValue &Lo, SDValue &Hi);
00334 
00335   void ExpandIntRes_Logical           (SDNode *N, SDValue &Lo, SDValue &Hi);
00336   void ExpandIntRes_ADDSUB            (SDNode *N, SDValue &Lo, SDValue &Hi);
00337   void ExpandIntRes_ADDSUBC           (SDNode *N, SDValue &Lo, SDValue &Hi);
00338   void ExpandIntRes_ADDSUBE           (SDNode *N, SDValue &Lo, SDValue &Hi);
00339   void ExpandIntRes_BSWAP             (SDNode *N, SDValue &Lo, SDValue &Hi);
00340   void ExpandIntRes_MUL               (SDNode *N, SDValue &Lo, SDValue &Hi);
00341   void ExpandIntRes_SDIV              (SDNode *N, SDValue &Lo, SDValue &Hi);
00342   void ExpandIntRes_SREM              (SDNode *N, SDValue &Lo, SDValue &Hi);
00343   void ExpandIntRes_UDIV              (SDNode *N, SDValue &Lo, SDValue &Hi);
00344   void ExpandIntRes_UREM              (SDNode *N, SDValue &Lo, SDValue &Hi);
00345   void ExpandIntRes_Shift             (SDNode *N, SDValue &Lo, SDValue &Hi);
00346 
00347   void ExpandShiftByConstant(SDNode *N, unsigned Amt,
00348                              SDValue &Lo, SDValue &Hi);
00349   bool ExpandShiftWithKnownAmountBit(SDNode *N, SDValue &Lo, SDValue &Hi);
00350   bool ExpandShiftWithUnknownAmountBit(SDNode *N, SDValue &Lo, SDValue &Hi);
00351 
00352   // Integer Operand Expansion.
00353   bool ExpandIntegerOperand(SDNode *N, unsigned OperandNo);
00354   SDValue ExpandIntOp_BIT_CONVERT(SDNode *N);
00355   SDValue ExpandIntOp_BR_CC(SDNode *N);
00356   SDValue ExpandIntOp_BUILD_VECTOR(SDNode *N);
00357   SDValue ExpandIntOp_EXTRACT_ELEMENT(SDNode *N);
00358   SDValue ExpandIntOp_SELECT_CC(SDNode *N);
00359   SDValue ExpandIntOp_SETCC(SDNode *N);
00360   SDValue ExpandIntOp_Shift(SDNode *N);
00361   SDValue ExpandIntOp_SINT_TO_FP(SDNode *N);
00362   SDValue ExpandIntOp_STORE(StoreSDNode *N, unsigned OpNo);
00363   SDValue ExpandIntOp_TRUNCATE(SDNode *N);
00364   SDValue ExpandIntOp_UINT_TO_FP(SDNode *N);
00365 
00366   void IntegerExpandSetCCOperands(SDValue &NewLHS, SDValue &NewRHS,
00367                                   ISD::CondCode &CCCode, DebugLoc dl);
00368 
00369   //===--------------------------------------------------------------------===//
00370   // Float to Integer Conversion Support: LegalizeFloatTypes.cpp
00371   //===--------------------------------------------------------------------===//
00372 
00373   /// GetSoftenedFloat - Given a processed operand Op which was converted to an
00374   /// integer of the same size, this returns the integer.  The integer contains
00375   /// exactly the same bits as Op - only the type changed.  For example, if Op
00376   /// is an f32 which was softened to an i32, then this method returns an i32,
00377   /// the bits of which coincide with those of Op.
00378   SDValue GetSoftenedFloat(SDValue Op) {
00379     SDValue &SoftenedOp = SoftenedFloats[Op];
00380     RemapValue(SoftenedOp);
00381     assert(SoftenedOp.getNode() && "Operand wasn't converted to integer?");
00382     return SoftenedOp;
00383   }
00384   void SetSoftenedFloat(SDValue Op, SDValue Result);
00385 
00386   // Result Float to Integer Conversion.
00387   void SoftenFloatResult(SDNode *N, unsigned OpNo);
00388   SDValue SoftenFloatRes_BIT_CONVERT(SDNode *N);
00389   SDValue SoftenFloatRes_BUILD_PAIR(SDNode *N);
00390   SDValue SoftenFloatRes_ConstantFP(ConstantFPSDNode *N);
00391   SDValue SoftenFloatRes_EXTRACT_VECTOR_ELT(SDNode *N);
00392   SDValue SoftenFloatRes_FABS(SDNode *N);
00393   SDValue SoftenFloatRes_FADD(SDNode *N);
00394   SDValue SoftenFloatRes_FCEIL(SDNode *N);
00395   SDValue SoftenFloatRes_FCOPYSIGN(SDNode *N);
00396   SDValue SoftenFloatRes_FCOS(SDNode *N);
00397   SDValue SoftenFloatRes_FDIV(SDNode *N);
00398   SDValue SoftenFloatRes_FEXP(SDNode *N);
00399   SDValue SoftenFloatRes_FEXP2(SDNode *N);
00400   SDValue SoftenFloatRes_FFLOOR(SDNode *N);
00401   SDValue SoftenFloatRes_FLOG(SDNode *N);
00402   SDValue SoftenFloatRes_FLOG2(SDNode *N);
00403   SDValue SoftenFloatRes_FLOG10(SDNode *N);
00404   SDValue SoftenFloatRes_FMUL(SDNode *N);
00405   SDValue SoftenFloatRes_FNEARBYINT(SDNode *N);
00406   SDValue SoftenFloatRes_FNEG(SDNode *N);
00407   SDValue SoftenFloatRes_FP_EXTEND(SDNode *N);
00408   SDValue SoftenFloatRes_FP_ROUND(SDNode *N);
00409   SDValue SoftenFloatRes_FPOW(SDNode *N);
00410   SDValue SoftenFloatRes_FPOWI(SDNode *N);
00411   SDValue SoftenFloatRes_FREM(SDNode *N);
00412   SDValue SoftenFloatRes_FRINT(SDNode *N);
00413   SDValue SoftenFloatRes_FSIN(SDNode *N);
00414   SDValue SoftenFloatRes_FSQRT(SDNode *N);
00415   SDValue SoftenFloatRes_FSUB(SDNode *N);
00416   SDValue SoftenFloatRes_FTRUNC(SDNode *N);
00417   SDValue SoftenFloatRes_LOAD(SDNode *N);
00418   SDValue SoftenFloatRes_SELECT(SDNode *N);
00419   SDValue SoftenFloatRes_SELECT_CC(SDNode *N);
00420   SDValue SoftenFloatRes_UNDEF(SDNode *N);
00421   SDValue SoftenFloatRes_VAARG(SDNode *N);
00422   SDValue SoftenFloatRes_XINT_TO_FP(SDNode *N);
00423 
00424   // Operand Float to Integer Conversion.
00425   bool SoftenFloatOperand(SDNode *N, unsigned OpNo);
00426   SDValue SoftenFloatOp_BIT_CONVERT(SDNode *N);
00427   SDValue SoftenFloatOp_BR_CC(SDNode *N);
00428   SDValue SoftenFloatOp_FP_ROUND(SDNode *N);
00429   SDValue SoftenFloatOp_FP_TO_SINT(SDNode *N);
00430   SDValue SoftenFloatOp_FP_TO_UINT(SDNode *N);
00431   SDValue SoftenFloatOp_SELECT_CC(SDNode *N);
00432   SDValue SoftenFloatOp_SETCC(SDNode *N);
00433   SDValue SoftenFloatOp_STORE(SDNode *N, unsigned OpNo);
00434 
00435   void SoftenSetCCOperands(SDValue &NewLHS, SDValue &NewRHS,
00436                            ISD::CondCode &CCCode, DebugLoc dl);
00437 
00438   //===--------------------------------------------------------------------===//
00439   // Float Expansion Support: LegalizeFloatTypes.cpp
00440   //===--------------------------------------------------------------------===//
00441 
00442   /// GetExpandedFloat - Given a processed operand Op which was expanded into
00443   /// two floating point values of half the size, this returns the two halves.
00444   /// The low bits of Op are exactly equal to the bits of Lo; the high bits
00445   /// exactly equal Hi.  For example, if Op is a ppcf128 which was expanded
00446   /// into two f64's, then this method returns the two f64's, with Lo being
00447   /// equal to the lower 64 bits of Op, and Hi to the upper 64 bits.
00448   void GetExpandedFloat(SDValue Op, SDValue &Lo, SDValue &Hi);
00449   void SetExpandedFloat(SDValue Op, SDValue Lo, SDValue Hi);
00450 
00451   // Float Result Expansion.
00452   void ExpandFloatResult(SDNode *N, unsigned ResNo);
00453   void ExpandFloatRes_ConstantFP(SDNode *N, SDValue &Lo, SDValue &Hi);
00454   void ExpandFloatRes_FABS      (SDNode *N, SDValue &Lo, SDValue &Hi);
00455   void ExpandFloatRes_FADD      (SDNode *N, SDValue &Lo, SDValue &Hi);
00456   void ExpandFloatRes_FCEIL     (SDNode *N, SDValue &Lo, SDValue &Hi);
00457   void ExpandFloatRes_FCOS      (SDNode *N, SDValue &Lo, SDValue &Hi);
00458   void ExpandFloatRes_FDIV      (SDNode *N, SDValue &Lo, SDValue &Hi);
00459   void ExpandFloatRes_FEXP      (SDNode *N, SDValue &Lo, SDValue &Hi);
00460   void ExpandFloatRes_FEXP2     (SDNode *N, SDValue &Lo, SDValue &Hi);
00461   void ExpandFloatRes_FFLOOR    (SDNode *N, SDValue &Lo, SDValue &Hi);
00462   void ExpandFloatRes_FLOG      (SDNode *N, SDValue &Lo, SDValue &Hi);
00463   void ExpandFloatRes_FLOG2     (SDNode *N, SDValue &Lo, SDValue &Hi);
00464   void ExpandFloatRes_FLOG10    (SDNode *N, SDValue &Lo, SDValue &Hi);
00465   void ExpandFloatRes_FMUL      (SDNode *N, SDValue &Lo, SDValue &Hi);
00466   void ExpandFloatRes_FNEARBYINT(SDNode *N, SDValue &Lo, SDValue &Hi);
00467   void ExpandFloatRes_FNEG      (SDNode *N, SDValue &Lo, SDValue &Hi);
00468   void ExpandFloatRes_FP_EXTEND (SDNode *N, SDValue &Lo, SDValue &Hi);
00469   void ExpandFloatRes_FPOW      (SDNode *N, SDValue &Lo, SDValue &Hi);
00470   void ExpandFloatRes_FPOWI     (SDNode *N, SDValue &Lo, SDValue &Hi);
00471   void ExpandFloatRes_FRINT     (SDNode *N, SDValue &Lo, SDValue &Hi);
00472   void ExpandFloatRes_FSIN      (SDNode *N, SDValue &Lo, SDValue &Hi);
00473   void ExpandFloatRes_FSQRT     (SDNode *N, SDValue &Lo, SDValue &Hi);
00474   void ExpandFloatRes_FSUB      (SDNode *N, SDValue &Lo, SDValue &Hi);
00475   void ExpandFloatRes_FTRUNC    (SDNode *N, SDValue &Lo, SDValue &Hi);
00476   void ExpandFloatRes_LOAD      (SDNode *N, SDValue &Lo, SDValue &Hi);
00477   void ExpandFloatRes_XINT_TO_FP(SDNode *N, SDValue &Lo, SDValue &Hi);
00478 
00479   // Float Operand Expansion.
00480   bool ExpandFloatOperand(SDNode *N, unsigned OperandNo);
00481   SDValue ExpandFloatOp_BR_CC(SDNode *N);
00482   SDValue ExpandFloatOp_FP_ROUND(SDNode *N);
00483   SDValue ExpandFloatOp_FP_TO_SINT(SDNode *N);
00484   SDValue ExpandFloatOp_FP_TO_UINT(SDNode *N);
00485   SDValue ExpandFloatOp_SELECT_CC(SDNode *N);
00486   SDValue ExpandFloatOp_SETCC(SDNode *N);
00487   SDValue ExpandFloatOp_STORE(SDNode *N, unsigned OpNo);
00488 
00489   void FloatExpandSetCCOperands(SDValue &NewLHS, SDValue &NewRHS,
00490                                 ISD::CondCode &CCCode, DebugLoc dl);
00491 
00492   //===--------------------------------------------------------------------===//
00493   // Scalarization Support: LegalizeVectorTypes.cpp
00494   //===--------------------------------------------------------------------===//
00495 
00496   /// GetScalarizedVector - Given a processed one-element vector Op which was
00497   /// scalarized to its element type, this returns the element.  For example,
00498   /// if Op is a v1i32, Op = < i32 val >, this method returns val, an i32.
00499   SDValue GetScalarizedVector(SDValue Op) {
00500     SDValue &ScalarizedOp = ScalarizedVectors[Op];
00501     RemapValue(ScalarizedOp);
00502     assert(ScalarizedOp.getNode() && "Operand wasn't scalarized?");
00503     return ScalarizedOp;
00504   }
00505   void SetScalarizedVector(SDValue Op, SDValue Result);
00506 
00507   // Vector Result Scalarization: <1 x ty> -> ty.
00508   void ScalarizeVectorResult(SDNode *N, unsigned OpNo);
00509   SDValue ScalarizeVecRes_BinOp(SDNode *N);
00510   SDValue ScalarizeVecRes_UnaryOp(SDNode *N);
00511 
00512   SDValue ScalarizeVecRes_BIT_CONVERT(SDNode *N);
00513   SDValue ScalarizeVecRes_CONVERT_RNDSAT(SDNode *N);
00514   SDValue ScalarizeVecRes_EXTRACT_SUBVECTOR(SDNode *N);
00515   SDValue ScalarizeVecRes_FPOWI(SDNode *N);
00516   SDValue ScalarizeVecRes_INSERT_VECTOR_ELT(SDNode *N);
00517   SDValue ScalarizeVecRes_LOAD(LoadSDNode *N);
00518   SDValue ScalarizeVecRes_SCALAR_TO_VECTOR(SDNode *N);
00519   SDValue ScalarizeVecRes_SELECT(SDNode *N);
00520   SDValue ScalarizeVecRes_SELECT_CC(SDNode *N);
00521   SDValue ScalarizeVecRes_SETCC(SDNode *N);
00522   SDValue ScalarizeVecRes_UNDEF(SDNode *N);
00523   SDValue ScalarizeVecRes_VECTOR_SHUFFLE(SDNode *N);
00524   SDValue ScalarizeVecRes_VSETCC(SDNode *N);
00525 
00526   // Vector Operand Scalarization: <1 x ty> -> ty.
00527   bool ScalarizeVectorOperand(SDNode *N, unsigned OpNo);
00528   SDValue ScalarizeVecOp_BIT_CONVERT(SDNode *N);
00529   SDValue ScalarizeVecOp_CONCAT_VECTORS(SDNode *N);
00530   SDValue ScalarizeVecOp_EXTRACT_VECTOR_ELT(SDNode *N);
00531   SDValue ScalarizeVecOp_STORE(StoreSDNode *N, unsigned OpNo);
00532 
00533   //===--------------------------------------------------------------------===//
00534   // Vector Splitting Support: LegalizeVectorTypes.cpp
00535   //===--------------------------------------------------------------------===//
00536 
00537   /// GetSplitVector - Given a processed vector Op which was split into vectors
00538   /// of half the size, this method returns the halves.  The first elements of
00539   /// Op coincide with the elements of Lo; the remaining elements of Op coincide
00540   /// with the elements of Hi: Op is what you would get by concatenating Lo and
00541   /// Hi.  For example, if Op is a v8i32 that was split into two v4i32's, then
00542   /// this method returns the two v4i32's, with Lo corresponding to the first 4
00543   /// elements of Op, and Hi to the last 4 elements.
00544   void GetSplitVector(SDValue Op, SDValue &Lo, SDValue &Hi);
00545   void SetSplitVector(SDValue Op, SDValue Lo, SDValue Hi);
00546 
00547   // Vector Result Splitting: <128 x ty> -> 2 x <64 x ty>.
00548   void SplitVectorResult(SDNode *N, unsigned OpNo);
00549   void SplitVecRes_BinOp(SDNode *N, SDValue &Lo, SDValue &Hi);
00550   void SplitVecRes_UnaryOp(SDNode *N, SDValue &Lo, SDValue &Hi);
00551 
00552   void SplitVecRes_BIT_CONVERT(SDNode *N, SDValue &Lo, SDValue &Hi);
00553   void SplitVecRes_BUILD_PAIR(SDNode *N, SDValue &Lo, SDValue &Hi);
00554   void SplitVecRes_BUILD_VECTOR(SDNode *N, SDValue &Lo, SDValue &Hi);
00555   void SplitVecRes_CONCAT_VECTORS(SDNode *N, SDValue &Lo, SDValue &Hi);
00556   void SplitVecRes_CONVERT_RNDSAT(SDNode *N, SDValue &Lo, SDValue &Hi);
00557   void SplitVecRes_EXTRACT_SUBVECTOR(SDNode *N, SDValue &Lo, SDValue &Hi);
00558   void SplitVecRes_FPOWI(SDNode *N, SDValue &Lo, SDValue &Hi);
00559   void SplitVecRes_INSERT_VECTOR_ELT(SDNode *N, SDValue &Lo, SDValue &Hi);
00560   void SplitVecRes_LOAD(LoadSDNode *N, SDValue &Lo, SDValue &Hi);
00561   void SplitVecRes_SCALAR_TO_VECTOR(SDNode *N, SDValue &Lo, SDValue &Hi);
00562   void SplitVecRes_SETCC(SDNode *N, SDValue &Lo, SDValue &Hi);
00563   void SplitVecRes_UNDEF(SDNode *N, SDValue &Lo, SDValue &Hi);
00564   void SplitVecRes_VECTOR_SHUFFLE(ShuffleVectorSDNode *N, SDValue &Lo,
00565                                   SDValue &Hi);
00566 
00567   // Vector Operand Splitting: <128 x ty> -> 2 x <64 x ty>.
00568   bool SplitVectorOperand(SDNode *N, unsigned OpNo);
00569   SDValue SplitVecOp_UnaryOp(SDNode *N);
00570 
00571   SDValue SplitVecOp_BIT_CONVERT(SDNode *N);
00572   SDValue SplitVecOp_EXTRACT_SUBVECTOR(SDNode *N);
00573   SDValue SplitVecOp_EXTRACT_VECTOR_ELT(SDNode *N);
00574   SDValue SplitVecOp_STORE(StoreSDNode *N, unsigned OpNo);
00575 
00576   //===--------------------------------------------------------------------===//
00577   // Vector Widening Support: LegalizeVectorTypes.cpp
00578   //===--------------------------------------------------------------------===//
00579 
00580   /// GetWidenedVector - Given a processed vector Op which was widened into a
00581   /// larger vector, this method returns the larger vector.  The elements of
00582   /// the returned vector consist of the elements of Op followed by elements
00583   /// containing rubbish.  For example, if Op is a v2i32 that was widened to a
00584   /// v4i32, then this method returns a v4i32 for which the first two elements
00585   /// are the same as those of Op, while the last two elements contain rubbish.
00586   SDValue GetWidenedVector(SDValue Op) {
00587     SDValue &WidenedOp = WidenedVectors[Op];
00588     RemapValue(WidenedOp);
00589     assert(WidenedOp.getNode() && "Operand wasn't widened?");
00590     return WidenedOp;
00591   }
00592   void SetWidenedVector(SDValue Op, SDValue Result);
00593 
00594   // Widen Vector Result Promotion.
00595   void WidenVectorResult(SDNode *N, unsigned ResNo);
00596   SDValue WidenVecRes_BIT_CONVERT(SDNode* N);
00597   SDValue WidenVecRes_BUILD_VECTOR(SDNode* N);
00598   SDValue WidenVecRes_CONCAT_VECTORS(SDNode* N);
00599   SDValue WidenVecRes_CONVERT_RNDSAT(SDNode* N);
00600   SDValue WidenVecRes_EXTRACT_SUBVECTOR(SDNode* N);
00601   SDValue WidenVecRes_INSERT_VECTOR_ELT(SDNode* N);
00602   SDValue WidenVecRes_LOAD(SDNode* N);
00603   SDValue WidenVecRes_SCALAR_TO_VECTOR(SDNode* N);
00604   SDValue WidenVecRes_SELECT(SDNode* N);
00605   SDValue WidenVecRes_SELECT_CC(SDNode* N);
00606   SDValue WidenVecRes_UNDEF(SDNode *N);
00607   SDValue WidenVecRes_VECTOR_SHUFFLE(ShuffleVectorSDNode *N);
00608   SDValue WidenVecRes_VSETCC(SDNode* N);
00609 
00610   SDValue WidenVecRes_Binary(SDNode *N);
00611   SDValue WidenVecRes_Convert(SDNode *N);
00612   SDValue WidenVecRes_Shift(SDNode *N);
00613   SDValue WidenVecRes_Unary(SDNode *N);
00614 
00615   // Widen Vector Operand.
00616   bool WidenVectorOperand(SDNode *N, unsigned ResNo);
00617   SDValue WidenVecOp_BIT_CONVERT(SDNode *N);
00618   SDValue WidenVecOp_CONCAT_VECTORS(SDNode *N);
00619   SDValue WidenVecOp_EXTRACT_VECTOR_ELT(SDNode *N);
00620   SDValue WidenVecOp_STORE(SDNode* N);
00621 
00622   SDValue WidenVecOp_Convert(SDNode *N);
00623 
00624   //===--------------------------------------------------------------------===//
00625   // Vector Widening Utilities Support: LegalizeVectorTypes.cpp
00626   //===--------------------------------------------------------------------===//
00627 
00628   /// Helper genWidenVectorLoads - Helper function to generate a set of
00629   /// loads to load a vector with a resulting wider type. It takes
00630   ///   ExtType: Extension type
00631   ///   LdChain: list of chains for the load we have generated.
00632   ///   Chain:   incoming chain for the ld vector.
00633   ///   BasePtr: base pointer to load from.
00634   ///   SV:         memory disambiguation source value.
00635   ///   SVOffset:   memory disambiugation offset.
00636   ///   Alignment:  alignment of the memory.
00637   ///   isVolatile: volatile load.
00638   ///   LdWidth:    width of memory that we want to load.
00639   ///   ResType:    the wider result result type for the resulting vector.
00640   ///   dl:         DebugLoc to be applied to new nodes
00641   SDValue GenWidenVectorLoads(SmallVector<SDValue, 16>& LdChain, SDValue Chain,
00642                               SDValue BasePtr, const Value *SV,
00643                               int SVOffset, unsigned Alignment,
00644                               bool isVolatile, unsigned LdWidth,
00645                               EVT ResType, DebugLoc dl);
00646 
00647   /// Helper genWidenVectorStores - Helper function to generate a set of
00648   /// stores to store a widen vector into non widen memory
00649   /// It takes
00650   ///   StChain: list of chains for the stores we have generated
00651   ///   Chain:   incoming chain for the ld vector
00652   ///   BasePtr: base pointer to load from
00653   ///   SV:      memory disambiguation source value
00654   ///   SVOffset:   memory disambiugation offset
00655   ///   Alignment:  alignment of the memory
00656   ///   isVolatile: volatile lod
00657   ///   ValOp:   value to store
00658   ///   StWidth: width of memory that we want to store
00659   ///   dl:         DebugLoc to be applied to new nodes
00660   void GenWidenVectorStores(SmallVector<SDValue, 16>& StChain, SDValue Chain,
00661                             SDValue BasePtr, const Value *SV,
00662                             int SVOffset, unsigned Alignment,
00663                             bool isVolatile, SDValue ValOp,
00664                             unsigned StWidth, DebugLoc dl);
00665 
00666   /// Modifies a vector input (widen or narrows) to a vector of NVT.  The
00667   /// input vector must have the same element type as NVT.
00668   SDValue ModifyToType(SDValue InOp, EVT WidenVT);
00669 
00670 
00671   //===--------------------------------------------------------------------===//
00672   // Generic Splitting: LegalizeTypesGeneric.cpp
00673   //===--------------------------------------------------------------------===//
00674 
00675   // Legalization methods which only use that the illegal type is split into two
00676   // not necessarily identical types.  As such they can be used for splitting
00677   // vectors and expanding integers and floats.
00678 
00679   void GetSplitOp(SDValue Op, SDValue &Lo, SDValue &Hi) {
00680     if (Op.getValueType().isVector())
00681       GetSplitVector(Op, Lo, Hi);
00682     else if (Op.getValueType().isInteger())
00683       GetExpandedInteger(Op, Lo, Hi);
00684     else
00685       GetExpandedFloat(Op, Lo, Hi);
00686   }
00687 
00688   /// GetSplitDestVTs - Compute the VTs needed for the low/hi parts of a type
00689   /// which is split (or expanded) into two not necessarily identical pieces.
00690   void GetSplitDestVTs(EVT InVT, EVT &LoVT, EVT &HiVT);
00691 
00692   /// GetPairElements - Use ISD::EXTRACT_ELEMENT nodes to extract the low and
00693   /// high parts of the given value.
00694   void GetPairElements(SDValue Pair, SDValue &Lo, SDValue &Hi);
00695 
00696   // Generic Result Splitting.
00697   void SplitRes_MERGE_VALUES(SDNode *N, SDValue &Lo, SDValue &Hi);
00698   void SplitRes_SELECT      (SDNode *N, SDValue &Lo, SDValue &Hi);
00699   void SplitRes_SELECT_CC   (SDNode *N, SDValue &Lo, SDValue &Hi);
00700   void SplitRes_UNDEF       (SDNode *N, SDValue &Lo, SDValue &Hi);
00701 
00702   //===--------------------------------------------------------------------===//
00703   // Generic Expansion: LegalizeTypesGeneric.cpp
00704   //===--------------------------------------------------------------------===//
00705 
00706   // Legalization methods which only use that the illegal type is split into two
00707   // identical types of half the size, and that the Lo/Hi part is stored first
00708   // in memory on little/big-endian machines, followed by the Hi/Lo part.  As
00709   // such they can be used for expanding integers and floats.
00710 
00711   void GetExpandedOp(SDValue Op, SDValue &Lo, SDValue &Hi) {
00712     if (Op.getValueType().isInteger())
00713       GetExpandedInteger(Op, Lo, Hi);
00714     else
00715       GetExpandedFloat(Op, Lo, Hi);
00716   }
00717 
00718   // Generic Result Expansion.
00719   void ExpandRes_BIT_CONVERT       (SDNode *N, SDValue &Lo, SDValue &Hi);
00720   void ExpandRes_BUILD_PAIR        (SDNode *N, SDValue &Lo, SDValue &Hi);
00721   void ExpandRes_EXTRACT_ELEMENT   (SDNode *N, SDValue &Lo, SDValue &Hi);
00722   void ExpandRes_EXTRACT_VECTOR_ELT(SDNode *N, SDValue &Lo, SDValue &Hi);
00723   void ExpandRes_NormalLoad        (SDNode *N, SDValue &Lo, SDValue &Hi);
00724   void ExpandRes_VAARG             (SDNode *N, SDValue &Lo, SDValue &Hi);
00725 
00726   // Generic Operand Expansion.
00727   SDValue ExpandOp_BIT_CONVERT      (SDNode *N);
00728   SDValue ExpandOp_BUILD_VECTOR     (SDNode *N);
00729   SDValue ExpandOp_EXTRACT_ELEMENT  (SDNode *N);
00730   SDValue ExpandOp_INSERT_VECTOR_ELT(SDNode *N);
00731   SDValue ExpandOp_SCALAR_TO_VECTOR (SDNode *N);
00732   SDValue ExpandOp_NormalStore      (SDNode *N, unsigned OpNo);
00733 };
00734 
00735 } // end namespace llvm.
00736 
00737 #endif