LLVM API Documentation
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, // This vector type should be split into smaller vectors. 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(MVT VT) const { 00078 switch (ValueTypeActions.getTypeAction(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(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(MVT VT) const { 00113 return ValueTypeActions.getTypeAction(VT) == TargetLowering::Legal; 00114 } 00115 00116 /// IgnoreNodeResults - Pretend all of this node's results are legal. 00117 /// FIXME: Remove once PR2957 is done. 00118 bool IgnoreNodeResults(SDNode *N) const { 00119 return N->getOpcode() == ISD::TargetConstant || 00120 IgnoredNodesResultsSet.count(N); 00121 } 00122 00123 /// IgnoredNode - Set of nodes whose result don't need to be legal. 00124 /// FIXME: Remove once PR2957 is done. 00125 DenseSet<SDNode*> IgnoredNodesResultsSet; 00126 00127 /// PromotedIntegers - For integer nodes that are below legal width, this map 00128 /// indicates what promoted value to use. 00129 DenseMap<SDValue, SDValue> PromotedIntegers; 00130 00131 /// ExpandedIntegers - For integer nodes that need to be expanded this map 00132 /// indicates which operands are the expanded version of the input. 00133 DenseMap<SDValue, std::pair<SDValue, SDValue> > ExpandedIntegers; 00134 00135 /// SoftenedFloats - For floating point nodes converted to integers of 00136 /// the same size, this map indicates the converted value to use. 00137 DenseMap<SDValue, SDValue> SoftenedFloats; 00138 00139 /// ExpandedFloats - For float nodes that need to be expanded this map 00140 /// indicates which operands are the expanded version of the input. 00141 DenseMap<SDValue, std::pair<SDValue, SDValue> > ExpandedFloats; 00142 00143 /// ScalarizedVectors - For nodes that are <1 x ty>, this map indicates the 00144 /// scalar value of type 'ty' to use. 00145 DenseMap<SDValue, SDValue> ScalarizedVectors; 00146 00147 /// SplitVectors - For nodes that need to be split this map indicates 00148 /// which operands are the expanded version of the input. 00149 DenseMap<SDValue, std::pair<SDValue, SDValue> > SplitVectors; 00150 00151 /// WidenedVectors - For vector nodes that need to be widened, indicates 00152 /// the widened value to use. 00153 DenseMap<SDValue, SDValue> WidenedVectors; 00154 00155 /// ReplacedValues - For values that have been replaced with another, 00156 /// indicates the replacement value to use. 00157 DenseMap<SDValue, SDValue> ReplacedValues; 00158 00159 /// Worklist - This defines a worklist of nodes to process. In order to be 00160 /// pushed onto this worklist, all operands of a node must have already been 00161 /// processed. 00162 SmallVector<SDNode*, 128> Worklist; 00163 00164 public: 00165 explicit DAGTypeLegalizer(SelectionDAG &dag) 00166 : TLI(dag.getTargetLoweringInfo()), DAG(dag), 00167 ValueTypeActions(TLI.getValueTypeActions()) { 00168 assert(MVT::LAST_VALUETYPE <= 32 && 00169 "Too many value types for ValueTypeActions to hold!"); 00170 } 00171 00172 /// run - This is the main entry point for the type legalizer. This does a 00173 /// top-down traversal of the dag, legalizing types as it goes. Returns 00174 /// "true" if it made any changes. 00175 bool run(); 00176 00177 void NoteDeletion(SDNode *Old, SDNode *New) { 00178 ExpungeNode(Old); 00179 ExpungeNode(New); 00180 for (unsigned i = 0, e = Old->getNumValues(); i != e; ++i) 00181 ReplacedValues[SDValue(Old, i)] = SDValue(New, i); 00182 } 00183 00184 private: 00185 SDNode *AnalyzeNewNode(SDNode *N); 00186 void AnalyzeNewValue(SDValue &Val); 00187 void ExpungeNode(SDNode *N); 00188 void PerformExpensiveChecks(); 00189 void RemapValue(SDValue &N); 00190 00191 // Common routines. 00192 SDValue BitConvertToInteger(SDValue Op); 00193 SDValue CreateStackStoreLoad(SDValue Op, MVT DestVT); 00194 bool CustomLowerResults(SDNode *N, MVT VT, bool LegalizeResult); 00195 SDValue GetVectorElementPointer(SDValue VecPtr, MVT EltVT, SDValue Index); 00196 SDValue JoinIntegers(SDValue Lo, SDValue Hi); 00197 SDValue LibCallify(RTLIB::Libcall LC, SDNode *N, bool isSigned); 00198 SDValue MakeLibCall(RTLIB::Libcall LC, MVT RetVT, 00199 const SDValue *Ops, unsigned NumOps, bool isSigned, 00200 DebugLoc dl); 00201 SDValue PromoteTargetBoolean(SDValue Bool, MVT VT); 00202 void ReplaceValueWith(SDValue From, SDValue To); 00203 void ReplaceValueWithHelper(SDValue From, SDValue To); 00204 void SetIgnoredNodeResult(SDNode* N); 00205 void SplitInteger(SDValue Op, SDValue &Lo, SDValue &Hi); 00206 void SplitInteger(SDValue Op, MVT LoVT, MVT HiVT, 00207 SDValue &Lo, SDValue &Hi); 00208 00209 //===--------------------------------------------------------------------===// 00210 // Integer Promotion Support: LegalizeIntegerTypes.cpp 00211 //===--------------------------------------------------------------------===// 00212 00213 /// GetPromotedInteger - Given a processed operand Op which was promoted to a 00214 /// larger integer type, this returns the promoted value. The low bits of the 00215 /// promoted value corresponding to the original type are exactly equal to Op. 00216 /// The extra bits contain rubbish, so the promoted value may need to be zero- 00217 /// or sign-extended from the original type before it is usable (the helpers 00218 /// SExtPromotedInteger and ZExtPromotedInteger can do this for you). 00219 /// For example, if Op is an i16 and was promoted to an i32, then this method 00220 /// returns an i32, the lower 16 bits of which coincide with Op, and the upper 00221 /// 16 bits of which contain rubbish. 00222 SDValue GetPromotedInteger(SDValue Op) { 00223 SDValue &PromotedOp = PromotedIntegers[Op]; 00224 RemapValue(PromotedOp); 00225 assert(PromotedOp.getNode() && "Operand wasn't promoted?"); 00226 return PromotedOp; 00227 } 00228 void SetPromotedInteger(SDValue Op, SDValue Result); 00229 00230 /// SExtPromotedInteger - Get a promoted operand and sign extend it to the 00231 /// final size. 00232 SDValue SExtPromotedInteger(SDValue Op) { 00233 MVT OldVT = Op.getValueType(); 00234 Op = GetPromotedInteger(Op); 00235 return DAG.getNode(ISD::SIGN_EXTEND_INREG, Op.getValueType(), Op, 00236 DAG.getValueType(OldVT)); 00237 } 00238 00239 /// ZExtPromotedInteger - Get a promoted operand and zero extend it to the 00240 /// final size. 00241 SDValue ZExtPromotedInteger(SDValue Op) { 00242 MVT OldVT = Op.getValueType(); 00243 Op = GetPromotedInteger(Op); 00244 return DAG.getZeroExtendInReg(Op, OldVT); 00245 } 00246 00247 // Integer Result Promotion. 00248 void PromoteIntegerResult(SDNode *N, unsigned ResNo); 00249 SDValue PromoteIntRes_AssertSext(SDNode *N); 00250 SDValue PromoteIntRes_AssertZext(SDNode *N); 00251 SDValue PromoteIntRes_Atomic1(AtomicSDNode *N); 00252 SDValue PromoteIntRes_Atomic2(AtomicSDNode *N); 00253 SDValue PromoteIntRes_BIT_CONVERT(SDNode *N); 00254 SDValue PromoteIntRes_BSWAP(SDNode *N); 00255 SDValue PromoteIntRes_BUILD_PAIR(SDNode *N); 00256 SDValue PromoteIntRes_Constant(SDNode *N); 00257 SDValue PromoteIntRes_CONVERT_RNDSAT(SDNode *N); 00258 SDValue PromoteIntRes_CTLZ(SDNode *N); 00259 SDValue PromoteIntRes_CTPOP(SDNode *N); 00260 SDValue PromoteIntRes_CTTZ(SDNode *N); 00261 SDValue PromoteIntRes_EXTRACT_VECTOR_ELT(SDNode *N); 00262 SDValue PromoteIntRes_FP_TO_XINT(SDNode *N); 00263 SDValue PromoteIntRes_INT_EXTEND(SDNode *N); 00264 SDValue PromoteIntRes_LOAD(LoadSDNode *N); 00265 SDValue PromoteIntRes_Overflow(SDNode *N); 00266 SDValue PromoteIntRes_SADDSUBO(SDNode *N, unsigned ResNo); 00267 SDValue PromoteIntRes_SDIV(SDNode *N); 00268 SDValue PromoteIntRes_SELECT(SDNode *N); 00269 SDValue PromoteIntRes_SELECT_CC(SDNode *N); 00270 SDValue PromoteIntRes_SETCC(SDNode *N); 00271 SDValue PromoteIntRes_SHL(SDNode *N); 00272 SDValue PromoteIntRes_SimpleIntBinOp(SDNode *N); 00273 SDValue PromoteIntRes_SIGN_EXTEND_INREG(SDNode *N); 00274 SDValue PromoteIntRes_SRA(SDNode *N); 00275 SDValue PromoteIntRes_SRL(SDNode *N); 00276 SDValue PromoteIntRes_TRUNCATE(SDNode *N); 00277 SDValue PromoteIntRes_UADDSUBO(SDNode *N, unsigned ResNo); 00278 SDValue PromoteIntRes_UDIV(SDNode *N); 00279 SDValue PromoteIntRes_UNDEF(SDNode *N); 00280 SDValue PromoteIntRes_VAARG(SDNode *N); 00281 SDValue PromoteIntRes_XMULO(SDNode *N, unsigned ResNo); 00282 00283 // Integer Operand Promotion. 00284 bool PromoteIntegerOperand(SDNode *N, unsigned OperandNo); 00285 SDValue PromoteIntOp_ANY_EXTEND(SDNode *N); 00286 SDValue PromoteIntOp_BUILD_PAIR(SDNode *N); 00287 SDValue PromoteIntOp_BR_CC(SDNode *N, unsigned OpNo); 00288 SDValue PromoteIntOp_BRCOND(SDNode *N, unsigned OpNo); 00289 SDValue PromoteIntOp_BUILD_VECTOR(SDNode *N); 00290 SDValue PromoteIntOp_CONVERT_RNDSAT(SDNode *N); 00291 SDValue PromoteIntOp_INSERT_VECTOR_ELT(SDNode *N, unsigned OpNo); 00292 SDValue PromoteIntOp_MEMBARRIER(SDNode *N); 00293 SDValue PromoteIntOp_SELECT(SDNode *N, unsigned OpNo); 00294 SDValue PromoteIntOp_SELECT_CC(SDNode *N, unsigned OpNo); 00295 SDValue PromoteIntOp_SETCC(SDNode *N, unsigned OpNo); 00296 SDValue PromoteIntOp_Shift(SDNode *N); 00297 SDValue PromoteIntOp_SIGN_EXTEND(SDNode *N); 00298 SDValue PromoteIntOp_SINT_TO_FP(SDNode *N); 00299 SDValue PromoteIntOp_STORE(StoreSDNode *N, unsigned OpNo); 00300 SDValue PromoteIntOp_TRUNCATE(SDNode *N); 00301 SDValue PromoteIntOp_UINT_TO_FP(SDNode *N); 00302 SDValue PromoteIntOp_ZERO_EXTEND(SDNode *N); 00303 00304 void PromoteSetCCOperands(SDValue &LHS,SDValue &RHS, ISD::CondCode Code); 00305 00306 //===--------------------------------------------------------------------===// 00307 // Integer Expansion Support: LegalizeIntegerTypes.cpp 00308 //===--------------------------------------------------------------------===// 00309 00310 /// GetExpandedInteger - Given a processed operand Op which was expanded into 00311 /// two integers of half the size, this returns the two halves. The low bits 00312 /// of Op are exactly equal to the bits of Lo; the high bits exactly equal Hi. 00313 /// For example, if Op is an i64 which was expanded into two i32's, then this 00314 /// method returns the two i32's, with Lo being equal to the lower 32 bits of 00315 /// Op, and Hi being equal to the upper 32 bits. 00316 void GetExpandedInteger(SDValue Op, SDValue &Lo, SDValue &Hi); 00317 void SetExpandedInteger(SDValue Op, SDValue Lo, SDValue Hi); 00318 00319 // Integer Result Expansion. 00320 void ExpandIntegerResult(SDNode *N, unsigned ResNo); 00321 void ExpandIntRes_ANY_EXTEND (SDNode *N, SDValue &Lo, SDValue &Hi); 00322 void ExpandIntRes_AssertSext (SDNode *N, SDValue &Lo, SDValue &Hi); 00323 void ExpandIntRes_AssertZext (SDNode *N, SDValue &Lo, SDValue &Hi); 00324 void ExpandIntRes_Constant (SDNode *N, SDValue &Lo, SDValue &Hi); 00325 void ExpandIntRes_CTLZ (SDNode *N, SDValue &Lo, SDValue &Hi); 00326 void ExpandIntRes_CTPOP (SDNode *N, SDValue &Lo, SDValue &Hi); 00327 void ExpandIntRes_CTTZ (SDNode *N, SDValue &Lo, SDValue &Hi); 00328 void ExpandIntRes_LOAD (LoadSDNode *N, SDValue &Lo, SDValue &Hi); 00329 void ExpandIntRes_SIGN_EXTEND (SDNode *N, SDValue &Lo, SDValue &Hi); 00330 void ExpandIntRes_SIGN_EXTEND_INREG (SDNode *N, SDValue &Lo, SDValue &Hi); 00331 void ExpandIntRes_TRUNCATE (SDNode *N, SDValue &Lo, SDValue &Hi); 00332 void ExpandIntRes_ZERO_EXTEND (SDNode *N, SDValue &Lo, SDValue &Hi); 00333 void ExpandIntRes_FP_TO_SINT (SDNode *N, SDValue &Lo, SDValue &Hi); 00334 void ExpandIntRes_FP_TO_UINT (SDNode *N, SDValue &Lo, SDValue &Hi); 00335 00336 void ExpandIntRes_Logical (SDNode *N, SDValue &Lo, SDValue &Hi); 00337 void ExpandIntRes_ADDSUB (SDNode *N, SDValue &Lo, SDValue &Hi); 00338 void ExpandIntRes_ADDSUBC (SDNode *N, SDValue &Lo, SDValue &Hi); 00339 void ExpandIntRes_ADDSUBE (SDNode *N, SDValue &Lo, SDValue &Hi); 00340 void ExpandIntRes_BSWAP (SDNode *N, SDValue &Lo, SDValue &Hi); 00341 void ExpandIntRes_MUL (SDNode *N, SDValue &Lo, SDValue &Hi); 00342 void ExpandIntRes_SDIV (SDNode *N, SDValue &Lo, SDValue &Hi); 00343 void ExpandIntRes_SREM (SDNode *N, SDValue &Lo, SDValue &Hi); 00344 void ExpandIntRes_UDIV (SDNode *N, SDValue &Lo, SDValue &Hi); 00345 void ExpandIntRes_UREM (SDNode *N, SDValue &Lo, SDValue &Hi); 00346 void ExpandIntRes_Shift (SDNode *N, SDValue &Lo, SDValue &Hi); 00347 00348 void ExpandShiftByConstant(SDNode *N, unsigned Amt, 00349 SDValue &Lo, SDValue &Hi); 00350 bool ExpandShiftWithKnownAmountBit(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_FABS(SDNode *N); 00392 SDValue SoftenFloatRes_FADD(SDNode *N); 00393 SDValue SoftenFloatRes_FCEIL(SDNode *N); 00394 SDValue SoftenFloatRes_FCOPYSIGN(SDNode *N); 00395 SDValue SoftenFloatRes_FCOS(SDNode *N); 00396 SDValue SoftenFloatRes_FDIV(SDNode *N); 00397 SDValue SoftenFloatRes_FEXP(SDNode *N); 00398 SDValue SoftenFloatRes_FEXP2(SDNode *N); 00399 SDValue SoftenFloatRes_FFLOOR(SDNode *N); 00400 SDValue SoftenFloatRes_FLOG(SDNode *N); 00401 SDValue SoftenFloatRes_FLOG2(SDNode *N); 00402 SDValue SoftenFloatRes_FLOG10(SDNode *N); 00403 SDValue SoftenFloatRes_FMUL(SDNode *N); 00404 SDValue SoftenFloatRes_FNEARBYINT(SDNode *N); 00405 SDValue SoftenFloatRes_FNEG(SDNode *N); 00406 SDValue SoftenFloatRes_FP_EXTEND(SDNode *N); 00407 SDValue SoftenFloatRes_FP_ROUND(SDNode *N); 00408 SDValue SoftenFloatRes_FPOW(SDNode *N); 00409 SDValue SoftenFloatRes_FPOWI(SDNode *N); 00410 SDValue SoftenFloatRes_FRINT(SDNode *N); 00411 SDValue SoftenFloatRes_FSIN(SDNode *N); 00412 SDValue SoftenFloatRes_FSQRT(SDNode *N); 00413 SDValue SoftenFloatRes_FSUB(SDNode *N); 00414 SDValue SoftenFloatRes_FTRUNC(SDNode *N); 00415 SDValue SoftenFloatRes_LOAD(SDNode *N); 00416 SDValue SoftenFloatRes_SELECT(SDNode *N); 00417 SDValue SoftenFloatRes_SELECT_CC(SDNode *N); 00418 SDValue SoftenFloatRes_XINT_TO_FP(SDNode *N); 00419 00420 // Operand Float to Integer Conversion. 00421 bool SoftenFloatOperand(SDNode *N, unsigned OpNo); 00422 SDValue SoftenFloatOp_BIT_CONVERT(SDNode *N); 00423 SDValue SoftenFloatOp_BR_CC(SDNode *N); 00424 SDValue SoftenFloatOp_FP_ROUND(SDNode *N); 00425 SDValue SoftenFloatOp_FP_TO_SINT(SDNode *N); 00426 SDValue SoftenFloatOp_FP_TO_UINT(SDNode *N); 00427 SDValue SoftenFloatOp_SELECT_CC(SDNode *N); 00428 SDValue SoftenFloatOp_SETCC(SDNode *N); 00429 SDValue SoftenFloatOp_STORE(SDNode *N, unsigned OpNo); 00430 00431 void SoftenSetCCOperands(SDValue &NewLHS, SDValue &NewRHS, 00432 ISD::CondCode &CCCode, DebugLoc dl); 00433 00434 //===--------------------------------------------------------------------===// 00435 // Float Expansion Support: LegalizeFloatTypes.cpp 00436 //===--------------------------------------------------------------------===// 00437 00438 /// GetExpandedFloat - Given a processed operand Op which was expanded into 00439 /// two floating point values of half the size, this returns the two halves. 00440 /// The low bits of Op are exactly equal to the bits of Lo; the high bits 00441 /// exactly equal Hi. For example, if Op is a ppcf128 which was expanded 00442 /// into two f64's, then this method returns the two f64's, with Lo being 00443 /// equal to the lower 64 bits of Op, and Hi to the upper 64 bits. 00444 void GetExpandedFloat(SDValue Op, SDValue &Lo, SDValue &Hi); 00445 void SetExpandedFloat(SDValue Op, SDValue Lo, SDValue Hi); 00446 00447 // Float Result Expansion. 00448 void ExpandFloatResult(SDNode *N, unsigned ResNo); 00449 void ExpandFloatRes_ConstantFP(SDNode *N, SDValue &Lo, SDValue &Hi); 00450 void ExpandFloatRes_FABS (SDNode *N, SDValue &Lo, SDValue &Hi); 00451 void ExpandFloatRes_FADD (SDNode *N, SDValue &Lo, SDValue &Hi); 00452 void ExpandFloatRes_FCEIL (SDNode *N, SDValue &Lo, SDValue &Hi); 00453 void ExpandFloatRes_FCOS (SDNode *N, SDValue &Lo, SDValue &Hi); 00454 void ExpandFloatRes_FDIV (SDNode *N, SDValue &Lo, SDValue &Hi); 00455 void ExpandFloatRes_FEXP (SDNode *N, SDValue &Lo, SDValue &Hi); 00456 void ExpandFloatRes_FEXP2 (SDNode *N, SDValue &Lo, SDValue &Hi); 00457 void ExpandFloatRes_FFLOOR (SDNode *N, SDValue &Lo, SDValue &Hi); 00458 void ExpandFloatRes_FLOG (SDNode *N, SDValue &Lo, SDValue &Hi); 00459 void ExpandFloatRes_FLOG2 (SDNode *N, SDValue &Lo, SDValue &Hi); 00460 void ExpandFloatRes_FLOG10 (SDNode *N, SDValue &Lo, SDValue &Hi); 00461 void ExpandFloatRes_FMUL (SDNode *N, SDValue &Lo, SDValue &Hi); 00462 void ExpandFloatRes_FNEARBYINT(SDNode *N, SDValue &Lo, SDValue &Hi); 00463 void ExpandFloatRes_FNEG (SDNode *N, SDValue &Lo, SDValue &Hi); 00464 void ExpandFloatRes_FP_EXTEND (SDNode *N, SDValue &Lo, SDValue &Hi); 00465 void ExpandFloatRes_FPOW (SDNode *N, SDValue &Lo, SDValue &Hi); 00466 void ExpandFloatRes_FPOWI (SDNode *N, SDValue &Lo, SDValue &Hi); 00467 void ExpandFloatRes_FRINT (SDNode *N, SDValue &Lo, SDValue &Hi); 00468 void ExpandFloatRes_FSIN (SDNode *N, SDValue &Lo, SDValue &Hi); 00469 void ExpandFloatRes_FSQRT (SDNode *N, SDValue &Lo, SDValue &Hi); 00470 void ExpandFloatRes_FSUB (SDNode *N, SDValue &Lo, SDValue &Hi); 00471 void ExpandFloatRes_FTRUNC (SDNode *N, SDValue &Lo, SDValue &Hi); 00472 void ExpandFloatRes_LOAD (SDNode *N, SDValue &Lo, SDValue &Hi); 00473 void ExpandFloatRes_XINT_TO_FP(SDNode *N, SDValue &Lo, SDValue &Hi); 00474 00475 // Float Operand Expansion. 00476 bool ExpandFloatOperand(SDNode *N, unsigned OperandNo); 00477 SDValue ExpandFloatOp_BR_CC(SDNode *N); 00478 SDValue ExpandFloatOp_FP_ROUND(SDNode *N); 00479 SDValue ExpandFloatOp_FP_TO_SINT(SDNode *N); 00480 SDValue ExpandFloatOp_FP_TO_UINT(SDNode *N); 00481 SDValue ExpandFloatOp_SELECT_CC(SDNode *N); 00482 SDValue ExpandFloatOp_SETCC(SDNode *N); 00483 SDValue ExpandFloatOp_STORE(SDNode *N, unsigned OpNo); 00484 00485 void FloatExpandSetCCOperands(SDValue &NewLHS, SDValue &NewRHS, 00486 ISD::CondCode &CCCode, DebugLoc dl); 00487 00488 //===--------------------------------------------------------------------===// 00489 // Scalarization Support: LegalizeVectorTypes.cpp 00490 //===--------------------------------------------------------------------===// 00491 00492 /// GetScalarizedVector - Given a processed one-element vector Op which was 00493 /// scalarized to its element type, this returns the element. For example, 00494 /// if Op is a v1i32, Op = < i32 val >, this method returns val, an i32. 00495 SDValue GetScalarizedVector(SDValue Op) { 00496 SDValue &ScalarizedOp = ScalarizedVectors[Op]; 00497 RemapValue(ScalarizedOp); 00498 assert(ScalarizedOp.getNode() && "Operand wasn't scalarized?"); 00499 return ScalarizedOp; 00500 } 00501 void SetScalarizedVector(SDValue Op, SDValue Result); 00502 00503 // Vector Result Scalarization: <1 x ty> -> ty. 00504 void ScalarizeVectorResult(SDNode *N, unsigned OpNo); 00505 SDValue ScalarizeVecRes_BinOp(SDNode *N); 00506 SDValue ScalarizeVecRes_ShiftOp(SDNode *N); 00507 SDValue ScalarizeVecRes_UnaryOp(SDNode *N); 00508 00509 SDValue ScalarizeVecRes_BIT_CONVERT(SDNode *N); 00510 SDValue ScalarizeVecRes_CONVERT_RNDSAT(SDNode *N); 00511 SDValue ScalarizeVecRes_EXTRACT_SUBVECTOR(SDNode *N); 00512 SDValue ScalarizeVecRes_FPOWI(SDNode *N); 00513 SDValue ScalarizeVecRes_INSERT_VECTOR_ELT(SDNode *N); 00514 SDValue ScalarizeVecRes_LOAD(LoadSDNode *N); 00515 SDValue ScalarizeVecRes_SCALAR_TO_VECTOR(SDNode *N); 00516 SDValue ScalarizeVecRes_SELECT(SDNode *N); 00517 SDValue ScalarizeVecRes_SELECT_CC(SDNode *N); 00518 SDValue ScalarizeVecRes_UNDEF(SDNode *N); 00519 SDValue ScalarizeVecRes_VECTOR_SHUFFLE(SDNode *N); 00520 SDValue ScalarizeVecRes_VSETCC(SDNode *N); 00521 00522 // Vector Operand Scalarization: <1 x ty> -> ty. 00523 bool ScalarizeVectorOperand(SDNode *N, unsigned OpNo); 00524 SDValue ScalarizeVecOp_BIT_CONVERT(SDNode *N); 00525 SDValue ScalarizeVecOp_CONCAT_VECTORS(SDNode *N); 00526 SDValue ScalarizeVecOp_EXTRACT_VECTOR_ELT(SDNode *N); 00527 SDValue ScalarizeVecOp_STORE(StoreSDNode *N, unsigned OpNo); 00528 00529 //===--------------------------------------------------------------------===// 00530 // Vector Splitting Support: LegalizeVectorTypes.cpp 00531 //===--------------------------------------------------------------------===// 00532 00533 /// GetSplitVector - Given a processed vector Op which was split into smaller 00534 /// vectors, this method returns the smaller vectors. The first elements of 00535 /// Op coincide with the elements of Lo; the remaining elements of Op coincide 00536 /// with the elements of Hi: Op is what you would get by concatenating Lo and 00537 /// Hi. For example, if Op is a v8i32 that was split into two v4i32's, then 00538 /// this method returns the two v4i32's, with Lo corresponding to the first 4 00539 /// elements of Op, and Hi to the last 4 elements. 00540 void GetSplitVector(SDValue Op, SDValue &Lo, SDValue &Hi); 00541 void SetSplitVector(SDValue Op, SDValue Lo, SDValue Hi); 00542 00543 // Vector Result Splitting: <128 x ty> -> 2 x <64 x ty>. 00544 void SplitVectorResult(SDNode *N, unsigned OpNo); 00545 void SplitVecRes_BinOp(SDNode *N, SDValue &Lo, SDValue &Hi); 00546 void SplitVecRes_UnaryOp(SDNode *N, SDValue &Lo, SDValue &Hi); 00547 00548 void SplitVecRes_BIT_CONVERT(SDNode *N, SDValue &Lo, SDValue &Hi); 00549 void SplitVecRes_BUILD_PAIR(SDNode *N, SDValue &Lo, SDValue &Hi); 00550 void SplitVecRes_BUILD_VECTOR(SDNode *N, SDValue &Lo, SDValue &Hi); 00551 void SplitVecRes_CONCAT_VECTORS(SDNode *N, SDValue &Lo, SDValue &Hi); 00552 void SplitVecRes_CONVERT_RNDSAT(SDNode *N, SDValue &Lo, SDValue &Hi); 00553 void SplitVecRes_EXTRACT_SUBVECTOR(SDNode *N, SDValue &Lo, SDValue &Hi); 00554 void SplitVecRes_FPOWI(SDNode *N, SDValue &Lo, SDValue &Hi); 00555 void SplitVecRes_INSERT_VECTOR_ELT(SDNode *N, SDValue &Lo, SDValue &Hi); 00556 void SplitVecRes_LOAD(LoadSDNode *N, SDValue &Lo, SDValue &Hi); 00557 void SplitVecRes_SCALAR_TO_VECTOR(SDNode *N, SDValue &Lo, SDValue &Hi); 00558 void SplitVecRes_UNDEF(SDNode *N, SDValue &Lo, SDValue &Hi); 00559 void SplitVecRes_VECTOR_SHUFFLE(SDNode *N, SDValue &Lo, SDValue &Hi); 00560 void SplitVecRes_VSETCC(SDNode *N, SDValue &Lo, SDValue &Hi); 00561 00562 // Vector Operand Splitting: <128 x ty> -> 2 x <64 x ty>. 00563 bool SplitVectorOperand(SDNode *N, unsigned OpNo); 00564 SDValue SplitVecOp_UnaryOp(SDNode *N); 00565 00566 SDValue SplitVecOp_BIT_CONVERT(SDNode *N); 00567 SDValue SplitVecOp_EXTRACT_SUBVECTOR(SDNode *N); 00568 SDValue SplitVecOp_EXTRACT_VECTOR_ELT(SDNode *N); 00569 SDValue SplitVecOp_STORE(StoreSDNode *N, unsigned OpNo); 00570 SDValue SplitVecOp_VECTOR_SHUFFLE(SDNode *N, unsigned OpNo); 00571 00572 //===--------------------------------------------------------------------===// 00573 // Vector Widening Support: LegalizeVectorTypes.cpp 00574 //===--------------------------------------------------------------------===// 00575 00576 /// GetWidenedVector - Given a processed vector Op which was widened into a 00577 /// larger vector, this method returns the larger vector. The elements of 00578 /// the returned vector consist of the elements of Op followed by elements 00579 /// containing rubbish. For example, if Op is a v2i32 that was widened to a 00580 /// v4i32, then this method returns a v4i32 for which the first two elements 00581 /// are the same as those of Op, while the last two elements contain rubbish. 00582 SDValue GetWidenedVector(SDValue Op) { 00583 SDValue &WidenedOp = WidenedVectors[Op]; 00584 RemapValue(WidenedOp); 00585 assert(WidenedOp.getNode() && "Operand wasn't widened?"); 00586 return WidenedOp; 00587 } 00588 void SetWidenedVector(SDValue Op, SDValue Result); 00589 00590 // Widen Vector Result Promotion. 00591 void WidenVectorResult(SDNode *N, unsigned ResNo); 00592 SDValue WidenVecRes_BIT_CONVERT(SDNode* N); 00593 SDValue WidenVecRes_BUILD_VECTOR(SDNode* N); 00594 SDValue WidenVecRes_CONCAT_VECTORS(SDNode* N); 00595 SDValue WidenVecRes_CONVERT_RNDSAT(SDNode* N); 00596 SDValue WidenVecRes_EXTRACT_SUBVECTOR(SDNode* N); 00597 SDValue WidenVecRes_INSERT_VECTOR_ELT(SDNode* N); 00598 SDValue WidenVecRes_LOAD(SDNode* N); 00599 SDValue WidenVecRes_SCALAR_TO_VECTOR(SDNode* N); 00600 SDValue WidenVecRes_SELECT(SDNode* N); 00601 SDValue WidenVecRes_SELECT_CC(SDNode* N); 00602 SDValue WidenVecRes_UNDEF(SDNode *N); 00603 SDValue WidenVecRes_VECTOR_SHUFFLE(SDNode *N); 00604 SDValue WidenVecRes_VSETCC(SDNode* N); 00605 00606 SDValue WidenVecRes_Binary(SDNode *N); 00607 SDValue WidenVecRes_Convert(SDNode *N); 00608 SDValue WidenVecRes_Shift(SDNode *N); 00609 SDValue WidenVecRes_Unary(SDNode *N); 00610 00611 // Widen Vector Operand. 00612 bool WidenVectorOperand(SDNode *N, unsigned ResNo); 00613 SDValue WidenVecOp_BIT_CONVERT(SDNode *N); 00614 SDValue WidenVecOp_CONCAT_VECTORS(SDNode *N); 00615 SDValue WidenVecOp_EXTRACT_VECTOR_ELT(SDNode *N); 00616 SDValue WidenVecOp_STORE(SDNode* N); 00617 00618 SDValue WidenVecOp_Convert(SDNode *N); 00619 00620 //===--------------------------------------------------------------------===// 00621 // Vector Widening Utilities Support: LegalizeVectorTypes.cpp 00622 //===--------------------------------------------------------------------===// 00623 00624 /// Helper genWidenVectorLoads - Helper function to generate a set of 00625 /// loads to load a vector with a resulting wider type. It takes 00626 /// ExtType: Extension type 00627 /// LdChain: list of chains for the load we have generated. 00628 /// Chain: incoming chain for the ld vector. 00629 /// BasePtr: base pointer to load from. 00630 /// SV: memory disambiguation source value. 00631 /// SVOffset: memory disambiugation offset. 00632 /// Alignment: alignment of the memory. 00633 /// isVolatile: volatile load. 00634 /// LdWidth: width of memory that we want to load. 00635 /// ResType: the wider result result type for the resulting vector. 00636 /// dl: DebugLoc to be applied to new nodes 00637 SDValue GenWidenVectorLoads(SmallVector<SDValue, 16>& LdChain, SDValue Chain, 00638 SDValue BasePtr, const Value *SV, 00639 int SVOffset, unsigned Alignment, 00640 bool isVolatile, unsigned LdWidth, 00641 MVT ResType, DebugLoc dl); 00642 00643 /// Helper genWidenVectorStores - Helper function to generate a set of 00644 /// stores to store a widen vector into non widen memory 00645 /// It takes 00646 /// StChain: list of chains for the stores we have generated 00647 /// Chain: incoming chain for the ld vector 00648 /// BasePtr: base pointer to load from 00649 /// SV: memory disambiguation source value 00650 /// SVOffset: memory disambiugation offset 00651 /// Alignment: alignment of the memory 00652 /// isVolatile: volatile lod 00653 /// ValOp: value to store 00654 /// StWidth: width of memory that we want to store 00655 /// dl: DebugLoc to be applied to new nodes 00656 void GenWidenVectorStores(SmallVector<SDValue, 16>& StChain, SDValue Chain, 00657 SDValue BasePtr, const Value *SV, 00658 int SVOffset, unsigned Alignment, 00659 bool isVolatile, SDValue ValOp, 00660 unsigned StWidth, DebugLoc dl); 00661 00662 /// Modifies a vector input (widen or narrows) to a vector of NVT. The 00663 /// input vector must have the same element type as NVT. 00664 SDValue ModifyToType(SDValue InOp, MVT WidenVT); 00665 00666 00667 //===--------------------------------------------------------------------===// 00668 // Generic Splitting: LegalizeTypesGeneric.cpp 00669 //===--------------------------------------------------------------------===// 00670 00671 // Legalization methods which only use that the illegal type is split into two 00672 // not necessarily identical types. As such they can be used for splitting 00673 // vectors and expanding integers and floats. 00674 00675 void GetSplitOp(SDValue Op, SDValue &Lo, SDValue &Hi) { 00676 if (Op.getValueType().isVector()) 00677 GetSplitVector(Op, Lo, Hi); 00678 else if (Op.getValueType().isInteger()) 00679 GetExpandedInteger(Op, Lo, Hi); 00680 else 00681 GetExpandedFloat(Op, Lo, Hi); 00682 } 00683 00684 /// GetSplitDestVTs - Compute the VTs needed for the low/hi parts of a type 00685 /// which is split (or expanded) into two not necessarily identical pieces. 00686 void GetSplitDestVTs(MVT InVT, MVT &LoVT, MVT &HiVT); 00687 00688 // Generic Result Splitting. 00689 void SplitRes_MERGE_VALUES(SDNode *N, SDValue &Lo, SDValue &Hi); 00690 void SplitRes_SELECT (SDNode *N, SDValue &Lo, SDValue &Hi); 00691 void SplitRes_SELECT_CC (SDNode *N, SDValue &Lo, SDValue &Hi); 00692 void SplitRes_UNDEF (SDNode *N, SDValue &Lo, SDValue &Hi); 00693 00694 //===--------------------------------------------------------------------===// 00695 // Generic Expansion: LegalizeTypesGeneric.cpp 00696 //===--------------------------------------------------------------------===// 00697 00698 // Legalization methods which only use that the illegal type is split into two 00699 // identical types of half the size, and that the Lo/Hi part is stored first 00700 // in memory on little/big-endian machines, followed by the Hi/Lo part. As 00701 // such they can be used for expanding integers and floats. 00702 00703 void GetExpandedOp(SDValue Op, SDValue &Lo, SDValue &Hi) { 00704 if (Op.getValueType().isInteger()) 00705 GetExpandedInteger(Op, Lo, Hi); 00706 else 00707 GetExpandedFloat(Op, Lo, Hi); 00708 } 00709 00710 // Generic Result Expansion. 00711 void ExpandRes_BIT_CONVERT (SDNode *N, SDValue &Lo, SDValue &Hi); 00712 void ExpandRes_BUILD_PAIR (SDNode *N, SDValue &Lo, SDValue &Hi); 00713 void ExpandRes_EXTRACT_ELEMENT (SDNode *N, SDValue &Lo, SDValue &Hi); 00714 void ExpandRes_EXTRACT_VECTOR_ELT(SDNode *N, SDValue &Lo, SDValue &Hi); 00715 void ExpandRes_NormalLoad (SDNode *N, SDValue &Lo, SDValue &Hi); 00716 void ExpandRes_VAARG (SDNode *N, SDValue &Lo, SDValue &Hi); 00717 00718 // Generic Operand Expansion. 00719 SDValue ExpandOp_BIT_CONVERT (SDNode *N); 00720 SDValue ExpandOp_BUILD_VECTOR (SDNode *N); 00721 SDValue ExpandOp_EXTRACT_ELEMENT (SDNode *N); 00722 SDValue ExpandOp_INSERT_VECTOR_ELT(SDNode *N); 00723 SDValue ExpandOp_SCALAR_TO_VECTOR (SDNode *N); 00724 SDValue ExpandOp_NormalStore (SDNode *N, unsigned OpNo); 00725 }; 00726 00727 } // end namespace llvm. 00728 00729 #endif