Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1 | //===-- LegalizeDAG.cpp - Implement SelectionDAG::Legalize ----------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 081ce94 | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the SelectionDAG::Legalize method. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "llvm/CodeGen/SelectionDAG.h" |
| 15 | #include "llvm/CodeGen/MachineFunction.h" |
| 16 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 17 | #include "llvm/CodeGen/MachineJumpTableInfo.h" |
Chris Lattner | 1b98919 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/MachineModuleInfo.h" |
Dan Gohman | 12a9c08 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/PseudoSourceValue.h" |
Evan Cheng | a448bc4 | 2007-08-16 23:50:06 +0000 | [diff] [blame] | 20 | #include "llvm/Target/TargetFrameInfo.h" |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 21 | #include "llvm/Target/TargetLowering.h" |
| 22 | #include "llvm/Target/TargetData.h" |
| 23 | #include "llvm/Target/TargetMachine.h" |
| 24 | #include "llvm/Target/TargetOptions.h" |
Dan Gohman | e8b391e | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 25 | #include "llvm/Target/TargetSubtarget.h" |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 26 | #include "llvm/CallingConv.h" |
| 27 | #include "llvm/Constants.h" |
| 28 | #include "llvm/DerivedTypes.h" |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 29 | #include "llvm/Support/CommandLine.h" |
| 30 | #include "llvm/Support/Compiler.h" |
Duncan Sands | a369143 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 31 | #include "llvm/Support/MathExtras.h" |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 32 | #include "llvm/ADT/DenseMap.h" |
| 33 | #include "llvm/ADT/SmallVector.h" |
| 34 | #include "llvm/ADT/SmallPtrSet.h" |
| 35 | #include <map> |
| 36 | using namespace llvm; |
| 37 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 38 | //===----------------------------------------------------------------------===// |
| 39 | /// SelectionDAGLegalize - This takes an arbitrary SelectionDAG as input and |
| 40 | /// hacks on it until the target machine can handle it. This involves |
| 41 | /// eliminating value sizes the machine cannot handle (promoting small sizes to |
| 42 | /// large sizes or splitting up large values into small values) as well as |
| 43 | /// eliminating operations the machine cannot handle. |
| 44 | /// |
| 45 | /// This code also does a small amount of optimization and recognition of idioms |
| 46 | /// as part of its processing. For example, if a target does not support a |
| 47 | /// 'setcc' instruction efficiently, but does support 'brcc' instruction, this |
| 48 | /// will attempt merge setcc and brc instructions into brcc's. |
| 49 | /// |
| 50 | namespace { |
| 51 | class VISIBILITY_HIDDEN SelectionDAGLegalize { |
| 52 | TargetLowering &TLI; |
| 53 | SelectionDAG &DAG; |
| 54 | |
| 55 | // Libcall insertion helpers. |
| 56 | |
| 57 | /// LastCALLSEQ_END - This keeps track of the CALLSEQ_END node that has been |
| 58 | /// legalized. We use this to ensure that calls are properly serialized |
| 59 | /// against each other, including inserted libcalls. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 60 | SDValue LastCALLSEQ_END; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 61 | |
| 62 | /// IsLegalizingCall - This member is used *only* for purposes of providing |
| 63 | /// helpful assertions that a libcall isn't created while another call is |
| 64 | /// being legalized (which could lead to non-serialized call sequences). |
| 65 | bool IsLegalizingCall; |
| 66 | |
| 67 | enum LegalizeAction { |
| 68 | Legal, // The target natively supports this operation. |
| 69 | Promote, // This operation should be executed in a larger type. |
| 70 | Expand // Try to expand this to other ops, otherwise use a libcall. |
| 71 | }; |
| 72 | |
| 73 | /// ValueTypeActions - This is a bitvector that contains two bits for each |
| 74 | /// value type, where the two bits correspond to the LegalizeAction enum. |
| 75 | /// This can be queried with "getTypeAction(VT)". |
| 76 | TargetLowering::ValueTypeActionImpl ValueTypeActions; |
| 77 | |
| 78 | /// LegalizedNodes - For nodes that are of legal width, and that have more |
| 79 | /// than one use, this map indicates what regularized operand to use. This |
| 80 | /// allows us to avoid legalizing the same thing more than once. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 81 | DenseMap<SDValue, SDValue> LegalizedNodes; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 82 | |
| 83 | /// PromotedNodes - For nodes that are below legal width, and that have more |
| 84 | /// than one use, this map indicates what promoted value to use. This allows |
| 85 | /// us to avoid promoting the same thing more than once. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 86 | DenseMap<SDValue, SDValue> PromotedNodes; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 87 | |
| 88 | /// ExpandedNodes - For nodes that need to be expanded this map indicates |
Mon P Wang | 1448aad | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 89 | /// which operands are the expanded version of the input. This allows |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 90 | /// us to avoid expanding the same node more than once. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 91 | DenseMap<SDValue, std::pair<SDValue, SDValue> > ExpandedNodes; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 92 | |
| 93 | /// SplitNodes - For vector nodes that need to be split, this map indicates |
Mon P Wang | 1448aad | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 94 | /// which operands are the split version of the input. This allows us |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 95 | /// to avoid splitting the same node more than once. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 96 | std::map<SDValue, std::pair<SDValue, SDValue> > SplitNodes; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 97 | |
| 98 | /// ScalarizedNodes - For nodes that need to be converted from vector types to |
| 99 | /// scalar types, this contains the mapping of ones we have already |
| 100 | /// processed to the result. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 101 | std::map<SDValue, SDValue> ScalarizedNodes; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 102 | |
Mon P Wang | a5a239f | 2008-11-06 05:31:54 +0000 | [diff] [blame] | 103 | /// WidenNodes - For nodes that need to be widened from one vector type to |
| 104 | /// another, this contains the mapping of those that we have already widen. |
| 105 | /// This allows us to avoid widening more than once. |
Mon P Wang | 1448aad | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 106 | std::map<SDValue, SDValue> WidenNodes; |
| 107 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 108 | void AddLegalizedOperand(SDValue From, SDValue To) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 109 | LegalizedNodes.insert(std::make_pair(From, To)); |
| 110 | // If someone requests legalization of the new node, return itself. |
| 111 | if (From != To) |
| 112 | LegalizedNodes.insert(std::make_pair(To, To)); |
| 113 | } |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 114 | void AddPromotedOperand(SDValue From, SDValue To) { |
Dan Gohman | 55d1966 | 2008-07-07 17:46:23 +0000 | [diff] [blame] | 115 | bool isNew = PromotedNodes.insert(std::make_pair(From, To)).second; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 116 | assert(isNew && "Got into the map somehow?"); |
| 117 | // If someone requests legalization of the new node, return itself. |
| 118 | LegalizedNodes.insert(std::make_pair(To, To)); |
| 119 | } |
Mon P Wang | a5a239f | 2008-11-06 05:31:54 +0000 | [diff] [blame] | 120 | void AddWidenedOperand(SDValue From, SDValue To) { |
Mon P Wang | 1448aad | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 121 | bool isNew = WidenNodes.insert(std::make_pair(From, To)).second; |
| 122 | assert(isNew && "Got into the map somehow?"); |
| 123 | // If someone requests legalization of the new node, return itself. |
| 124 | LegalizedNodes.insert(std::make_pair(To, To)); |
| 125 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 126 | |
| 127 | public: |
Dan Gohman | e887fdf | 2008-07-07 18:00:37 +0000 | [diff] [blame] | 128 | explicit SelectionDAGLegalize(SelectionDAG &DAG); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 129 | |
| 130 | /// getTypeAction - Return how we should legalize values of this type, either |
| 131 | /// it is already legal or we need to expand it into multiple registers of |
| 132 | /// smaller integer type, or we need to promote it to a larger type. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 133 | LegalizeAction getTypeAction(MVT VT) const { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 134 | return (LegalizeAction)ValueTypeActions.getTypeAction(VT); |
| 135 | } |
| 136 | |
| 137 | /// isTypeLegal - Return true if this type is legal on this target. |
| 138 | /// |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 139 | bool isTypeLegal(MVT VT) const { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 140 | return getTypeAction(VT) == Legal; |
| 141 | } |
| 142 | |
| 143 | void LegalizeDAG(); |
| 144 | |
| 145 | private: |
| 146 | /// HandleOp - Legalize, Promote, or Expand the specified operand as |
| 147 | /// appropriate for its type. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 148 | void HandleOp(SDValue Op); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 149 | |
| 150 | /// LegalizeOp - We know that the specified value has a legal type. |
| 151 | /// Recursively ensure that the operands have legal types, then return the |
| 152 | /// result. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 153 | SDValue LegalizeOp(SDValue O); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 154 | |
Dan Gohman | 6d05cac | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 155 | /// UnrollVectorOp - We know that the given vector has a legal type, however |
| 156 | /// the operation it performs is not legal and is an operation that we have |
| 157 | /// no way of lowering. "Unroll" the vector, splitting out the scalars and |
| 158 | /// operating on each element individually. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 159 | SDValue UnrollVectorOp(SDValue O); |
Nate Begeman | 7c9e4b7 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 160 | |
| 161 | /// PerformInsertVectorEltInMemory - Some target cannot handle a variable |
| 162 | /// insertion index for the INSERT_VECTOR_ELT instruction. In this case, it |
| 163 | /// is necessary to spill the vector being inserted into to memory, perform |
| 164 | /// the insert there, and then read the result back. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 165 | SDValue PerformInsertVectorEltInMemory(SDValue Vec, SDValue Val, |
| 166 | SDValue Idx); |
Dan Gohman | 6d05cac | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 167 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 168 | /// PromoteOp - Given an operation that produces a value in an invalid type, |
| 169 | /// promote it to compute the value into a larger type. The produced value |
| 170 | /// will have the correct bits for the low portion of the register, but no |
| 171 | /// guarantee is made about the top bits: it may be zero, sign-extended, or |
| 172 | /// garbage. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 173 | SDValue PromoteOp(SDValue O); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 174 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 175 | /// ExpandOp - Expand the specified SDValue into its two component pieces |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 176 | /// Lo&Hi. Note that the Op MUST be an expanded type. As a result of this, |
Dan Gohman | 4fc0374 | 2008-10-01 15:07:49 +0000 | [diff] [blame] | 177 | /// the LegalizedNodes map is filled in for any results that are not expanded, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 178 | /// the ExpandedNodes map is filled in for any results that are expanded, and |
| 179 | /// the Lo/Hi values are returned. This applies to integer types and Vector |
| 180 | /// types. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 181 | void ExpandOp(SDValue O, SDValue &Lo, SDValue &Hi); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 182 | |
Mon P Wang | a5a239f | 2008-11-06 05:31:54 +0000 | [diff] [blame] | 183 | /// WidenVectorOp - Widen a vector operation to a wider type given by WidenVT |
| 184 | /// (e.g., v3i32 to v4i32). The produced value will have the correct value |
| 185 | /// for the existing elements but no guarantee is made about the new elements |
| 186 | /// at the end of the vector: it may be zero, ones, or garbage. This is useful |
| 187 | /// when we have an instruction operating on an illegal vector type and we |
| 188 | /// want to widen it to do the computation on a legal wider vector type. |
Mon P Wang | 1448aad | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 189 | SDValue WidenVectorOp(SDValue Op, MVT WidenVT); |
| 190 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 191 | /// SplitVectorOp - Given an operand of vector type, break it down into |
| 192 | /// two smaller values. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 193 | void SplitVectorOp(SDValue O, SDValue &Lo, SDValue &Hi); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 194 | |
| 195 | /// ScalarizeVectorOp - Given an operand of single-element vector type |
| 196 | /// (e.g. v1f32), convert it into the equivalent operation that returns a |
| 197 | /// scalar (e.g. f32) value. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 198 | SDValue ScalarizeVectorOp(SDValue O); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 199 | |
Mon P Wang | a5a239f | 2008-11-06 05:31:54 +0000 | [diff] [blame] | 200 | /// Useful 16 element vector type that is used to pass operands for widening. |
Mon P Wang | 1448aad | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 201 | typedef SmallVector<SDValue, 16> SDValueVector; |
| 202 | |
| 203 | /// LoadWidenVectorOp - Load a vector for a wider type. Returns true if |
| 204 | /// the LdChain contains a single load and false if it contains a token |
| 205 | /// factor for multiple loads. It takes |
| 206 | /// Result: location to return the result |
| 207 | /// LdChain: location to return the load chain |
| 208 | /// Op: load operation to widen |
| 209 | /// NVT: widen vector result type we want for the load |
| 210 | bool LoadWidenVectorOp(SDValue& Result, SDValue& LdChain, |
| 211 | SDValue Op, MVT NVT); |
| 212 | |
| 213 | /// Helper genWidenVectorLoads - Helper function to generate a set of |
| 214 | /// loads to load a vector with a resulting wider type. It takes |
| 215 | /// LdChain: list of chains for the load we have generated |
| 216 | /// Chain: incoming chain for the ld vector |
| 217 | /// BasePtr: base pointer to load from |
| 218 | /// SV: memory disambiguation source value |
| 219 | /// SVOffset: memory disambiugation offset |
| 220 | /// Alignment: alignment of the memory |
| 221 | /// isVolatile: volatile load |
| 222 | /// LdWidth: width of memory that we want to load |
| 223 | /// ResType: the wider result result type for the resulting loaded vector |
| 224 | SDValue genWidenVectorLoads(SDValueVector& LdChain, SDValue Chain, |
| 225 | SDValue BasePtr, const Value *SV, |
| 226 | int SVOffset, unsigned Alignment, |
| 227 | bool isVolatile, unsigned LdWidth, |
| 228 | MVT ResType); |
| 229 | |
| 230 | /// StoreWidenVectorOp - Stores a widen vector into non widen memory |
| 231 | /// location. It takes |
| 232 | /// ST: store node that we want to replace |
| 233 | /// Chain: incoming store chain |
| 234 | /// BasePtr: base address of where we want to store into |
| 235 | SDValue StoreWidenVectorOp(StoreSDNode *ST, SDValue Chain, |
| 236 | SDValue BasePtr); |
| 237 | |
| 238 | /// Helper genWidenVectorStores - Helper function to generate a set of |
| 239 | /// stores to store a widen vector into non widen memory |
| 240 | // It takes |
| 241 | // StChain: list of chains for the stores we have generated |
| 242 | // Chain: incoming chain for the ld vector |
| 243 | // BasePtr: base pointer to load from |
| 244 | // SV: memory disambiguation source value |
| 245 | // SVOffset: memory disambiugation offset |
| 246 | // Alignment: alignment of the memory |
| 247 | // isVolatile: volatile lod |
| 248 | // ValOp: value to store |
| 249 | // StWidth: width of memory that we want to store |
| 250 | void genWidenVectorStores(SDValueVector& StChain, SDValue Chain, |
| 251 | SDValue BasePtr, const Value *SV, |
| 252 | int SVOffset, unsigned Alignment, |
| 253 | bool isVolatile, SDValue ValOp, |
| 254 | unsigned StWidth); |
| 255 | |
Duncan Sands | d3ace28 | 2008-07-21 10:20:31 +0000 | [diff] [blame] | 256 | /// isShuffleLegal - Return non-null if a vector shuffle is legal with the |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 257 | /// specified mask and type. Targets can specify exactly which masks they |
| 258 | /// support and the code generator is tasked with not creating illegal masks. |
| 259 | /// |
| 260 | /// Note that this will also return true for shuffles that are promoted to a |
| 261 | /// different type. |
| 262 | /// |
| 263 | /// If this is a legal shuffle, this method returns the (possibly promoted) |
| 264 | /// build_vector Mask. If it's not a legal shuffle, it returns null. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 265 | SDNode *isShuffleLegal(MVT VT, SDValue Mask) const; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 266 | |
| 267 | bool LegalizeAllNodesNotLeadingTo(SDNode *N, SDNode *Dest, |
| 268 | SmallPtrSet<SDNode*, 32> &NodesLeadingTo); |
| 269 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 270 | void LegalizeSetCCOperands(SDValue &LHS, SDValue &RHS, SDValue &CC); |
Evan Cheng | 7134382 | 2008-10-15 02:05:31 +0000 | [diff] [blame] | 271 | void LegalizeSetCCCondCode(MVT VT, SDValue &LHS, SDValue &RHS, SDValue &CC); |
| 272 | void LegalizeSetCC(MVT VT, SDValue &LHS, SDValue &RHS, SDValue &CC) { |
| 273 | LegalizeSetCCOperands(LHS, RHS, CC); |
| 274 | LegalizeSetCCCondCode(VT, LHS, RHS, CC); |
| 275 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 276 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 277 | SDValue ExpandLibCall(RTLIB::Libcall LC, SDNode *Node, bool isSigned, |
| 278 | SDValue &Hi); |
| 279 | SDValue ExpandIntToFP(bool isSigned, MVT DestTy, SDValue Source); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 280 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 281 | SDValue EmitStackConvert(SDValue SrcOp, MVT SlotVT, MVT DestVT); |
| 282 | SDValue ExpandBUILD_VECTOR(SDNode *Node); |
| 283 | SDValue ExpandSCALAR_TO_VECTOR(SDNode *Node); |
Dan Gohman | 29c3cef | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 284 | SDValue LegalizeINT_TO_FP(SDValue Result, bool isSigned, MVT DestTy, SDValue Op); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 285 | SDValue ExpandLegalINT_TO_FP(bool isSigned, SDValue LegalOp, MVT DestVT); |
| 286 | SDValue PromoteLegalINT_TO_FP(SDValue LegalOp, MVT DestVT, bool isSigned); |
| 287 | SDValue PromoteLegalFP_TO_INT(SDValue LegalOp, MVT DestVT, bool isSigned); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 288 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 289 | SDValue ExpandBSWAP(SDValue Op); |
| 290 | SDValue ExpandBitCount(unsigned Opc, SDValue Op); |
| 291 | bool ExpandShift(unsigned Opc, SDValue Op, SDValue Amt, |
| 292 | SDValue &Lo, SDValue &Hi); |
| 293 | void ExpandShiftParts(unsigned NodeOp, SDValue Op, SDValue Amt, |
| 294 | SDValue &Lo, SDValue &Hi); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 295 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 296 | SDValue ExpandEXTRACT_SUBVECTOR(SDValue Op); |
| 297 | SDValue ExpandEXTRACT_VECTOR_ELT(SDValue Op); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 298 | }; |
| 299 | } |
| 300 | |
| 301 | /// isVectorShuffleLegal - Return true if a vector shuffle is legal with the |
| 302 | /// specified mask and type. Targets can specify exactly which masks they |
| 303 | /// support and the code generator is tasked with not creating illegal masks. |
| 304 | /// |
| 305 | /// Note that this will also return true for shuffles that are promoted to a |
| 306 | /// different type. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 307 | SDNode *SelectionDAGLegalize::isShuffleLegal(MVT VT, SDValue Mask) const { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 308 | switch (TLI.getOperationAction(ISD::VECTOR_SHUFFLE, VT)) { |
| 309 | default: return 0; |
| 310 | case TargetLowering::Legal: |
| 311 | case TargetLowering::Custom: |
| 312 | break; |
| 313 | case TargetLowering::Promote: { |
| 314 | // If this is promoted to a different type, convert the shuffle mask and |
| 315 | // ask if it is legal in the promoted type! |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 316 | MVT NVT = TLI.getTypeToPromoteTo(ISD::VECTOR_SHUFFLE, VT); |
Duncan Sands | d3ace28 | 2008-07-21 10:20:31 +0000 | [diff] [blame] | 317 | MVT EltVT = NVT.getVectorElementType(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 318 | |
| 319 | // If we changed # elements, change the shuffle mask. |
| 320 | unsigned NumEltsGrowth = |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 321 | NVT.getVectorNumElements() / VT.getVectorNumElements(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 322 | assert(NumEltsGrowth && "Cannot promote to vector type with fewer elts!"); |
| 323 | if (NumEltsGrowth > 1) { |
| 324 | // Renumber the elements. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 325 | SmallVector<SDValue, 8> Ops; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 326 | for (unsigned i = 0, e = Mask.getNumOperands(); i != e; ++i) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 327 | SDValue InOp = Mask.getOperand(i); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 328 | for (unsigned j = 0; j != NumEltsGrowth; ++j) { |
| 329 | if (InOp.getOpcode() == ISD::UNDEF) |
Duncan Sands | d3ace28 | 2008-07-21 10:20:31 +0000 | [diff] [blame] | 330 | Ops.push_back(DAG.getNode(ISD::UNDEF, EltVT)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 331 | else { |
Dan Gohman | faeb4a3 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 332 | unsigned InEltNo = cast<ConstantSDNode>(InOp)->getZExtValue(); |
Duncan Sands | d3ace28 | 2008-07-21 10:20:31 +0000 | [diff] [blame] | 333 | Ops.push_back(DAG.getConstant(InEltNo*NumEltsGrowth+j, EltVT)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 334 | } |
| 335 | } |
| 336 | } |
| 337 | Mask = DAG.getNode(ISD::BUILD_VECTOR, NVT, &Ops[0], Ops.size()); |
| 338 | } |
| 339 | VT = NVT; |
| 340 | break; |
| 341 | } |
| 342 | } |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 343 | return TLI.isShuffleMaskLegal(Mask, VT) ? Mask.getNode() : 0; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | SelectionDAGLegalize::SelectionDAGLegalize(SelectionDAG &dag) |
| 347 | : TLI(dag.getTargetLoweringInfo()), DAG(dag), |
| 348 | ValueTypeActions(TLI.getValueTypeActions()) { |
| 349 | assert(MVT::LAST_VALUETYPE <= 32 && |
| 350 | "Too many value types for ValueTypeActions to hold!"); |
| 351 | } |
| 352 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 353 | void SelectionDAGLegalize::LegalizeDAG() { |
| 354 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 355 | IsLegalizingCall = false; |
| 356 | |
| 357 | // The legalize process is inherently a bottom-up recursive process (users |
| 358 | // legalize their uses before themselves). Given infinite stack space, we |
| 359 | // could just start legalizing on the root and traverse the whole graph. In |
| 360 | // practice however, this causes us to run out of stack space on large basic |
| 361 | // blocks. To avoid this problem, compute an ordering of the nodes where each |
| 362 | // node is only legalized after all of its operands are legalized. |
Dan Gohman | 2d2a7a3 | 2008-09-30 18:30:35 +0000 | [diff] [blame] | 363 | DAG.AssignTopologicalOrder(); |
| 364 | for (SelectionDAG::allnodes_iterator I = DAG.allnodes_begin(), |
| 365 | E = prior(DAG.allnodes_end()); I != next(E); ++I) |
| 366 | HandleOp(SDValue(I, 0)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 367 | |
| 368 | // Finally, it's possible the root changed. Get the new root. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 369 | SDValue OldRoot = DAG.getRoot(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 370 | assert(LegalizedNodes.count(OldRoot) && "Root didn't get legalized?"); |
| 371 | DAG.setRoot(LegalizedNodes[OldRoot]); |
| 372 | |
| 373 | ExpandedNodes.clear(); |
| 374 | LegalizedNodes.clear(); |
| 375 | PromotedNodes.clear(); |
| 376 | SplitNodes.clear(); |
| 377 | ScalarizedNodes.clear(); |
Mon P Wang | 1448aad | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 378 | WidenNodes.clear(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 379 | |
| 380 | // Remove dead nodes now. |
| 381 | DAG.RemoveDeadNodes(); |
| 382 | } |
| 383 | |
| 384 | |
| 385 | /// FindCallEndFromCallStart - Given a chained node that is part of a call |
| 386 | /// sequence, find the CALLSEQ_END node that terminates the call sequence. |
| 387 | static SDNode *FindCallEndFromCallStart(SDNode *Node) { |
| 388 | if (Node->getOpcode() == ISD::CALLSEQ_END) |
| 389 | return Node; |
| 390 | if (Node->use_empty()) |
| 391 | return 0; // No CallSeqEnd |
| 392 | |
| 393 | // The chain is usually at the end. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 394 | SDValue TheChain(Node, Node->getNumValues()-1); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 395 | if (TheChain.getValueType() != MVT::Other) { |
| 396 | // Sometimes it's at the beginning. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 397 | TheChain = SDValue(Node, 0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 398 | if (TheChain.getValueType() != MVT::Other) { |
| 399 | // Otherwise, hunt for it. |
| 400 | for (unsigned i = 1, e = Node->getNumValues(); i != e; ++i) |
| 401 | if (Node->getValueType(i) == MVT::Other) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 402 | TheChain = SDValue(Node, i); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 403 | break; |
| 404 | } |
| 405 | |
| 406 | // Otherwise, we walked into a node without a chain. |
| 407 | if (TheChain.getValueType() != MVT::Other) |
| 408 | return 0; |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | for (SDNode::use_iterator UI = Node->use_begin(), |
| 413 | E = Node->use_end(); UI != E; ++UI) { |
| 414 | |
| 415 | // Make sure to only follow users of our token chain. |
Dan Gohman | 0c97f1d | 2008-07-27 20:43:25 +0000 | [diff] [blame] | 416 | SDNode *User = *UI; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 417 | for (unsigned i = 0, e = User->getNumOperands(); i != e; ++i) |
| 418 | if (User->getOperand(i) == TheChain) |
| 419 | if (SDNode *Result = FindCallEndFromCallStart(User)) |
| 420 | return Result; |
| 421 | } |
| 422 | return 0; |
| 423 | } |
| 424 | |
| 425 | /// FindCallStartFromCallEnd - Given a chained node that is part of a call |
| 426 | /// sequence, find the CALLSEQ_START node that initiates the call sequence. |
| 427 | static SDNode *FindCallStartFromCallEnd(SDNode *Node) { |
| 428 | assert(Node && "Didn't find callseq_start for a call??"); |
| 429 | if (Node->getOpcode() == ISD::CALLSEQ_START) return Node; |
| 430 | |
| 431 | assert(Node->getOperand(0).getValueType() == MVT::Other && |
| 432 | "Node doesn't have a token chain argument!"); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 433 | return FindCallStartFromCallEnd(Node->getOperand(0).getNode()); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | /// LegalizeAllNodesNotLeadingTo - Recursively walk the uses of N, looking to |
| 437 | /// see if any uses can reach Dest. If no dest operands can get to dest, |
| 438 | /// legalize them, legalize ourself, and return false, otherwise, return true. |
| 439 | /// |
| 440 | /// Keep track of the nodes we fine that actually do lead to Dest in |
| 441 | /// NodesLeadingTo. This avoids retraversing them exponential number of times. |
| 442 | /// |
| 443 | bool SelectionDAGLegalize::LegalizeAllNodesNotLeadingTo(SDNode *N, SDNode *Dest, |
| 444 | SmallPtrSet<SDNode*, 32> &NodesLeadingTo) { |
| 445 | if (N == Dest) return true; // N certainly leads to Dest :) |
| 446 | |
| 447 | // If we've already processed this node and it does lead to Dest, there is no |
| 448 | // need to reprocess it. |
| 449 | if (NodesLeadingTo.count(N)) return true; |
| 450 | |
| 451 | // If the first result of this node has been already legalized, then it cannot |
| 452 | // reach N. |
| 453 | switch (getTypeAction(N->getValueType(0))) { |
| 454 | case Legal: |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 455 | if (LegalizedNodes.count(SDValue(N, 0))) return false; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 456 | break; |
| 457 | case Promote: |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 458 | if (PromotedNodes.count(SDValue(N, 0))) return false; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 459 | break; |
| 460 | case Expand: |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 461 | if (ExpandedNodes.count(SDValue(N, 0))) return false; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 462 | break; |
| 463 | } |
| 464 | |
| 465 | // Okay, this node has not already been legalized. Check and legalize all |
| 466 | // operands. If none lead to Dest, then we can legalize this node. |
| 467 | bool OperandsLeadToDest = false; |
| 468 | for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) |
| 469 | OperandsLeadToDest |= // If an operand leads to Dest, so do we. |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 470 | LegalizeAllNodesNotLeadingTo(N->getOperand(i).getNode(), Dest, NodesLeadingTo); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 471 | |
| 472 | if (OperandsLeadToDest) { |
| 473 | NodesLeadingTo.insert(N); |
| 474 | return true; |
| 475 | } |
| 476 | |
| 477 | // Okay, this node looks safe, legalize it and return false. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 478 | HandleOp(SDValue(N, 0)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 479 | return false; |
| 480 | } |
| 481 | |
Mon P Wang | 1448aad | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 482 | /// HandleOp - Legalize, Promote, Widen, or Expand the specified operand as |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 483 | /// appropriate for its type. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 484 | void SelectionDAGLegalize::HandleOp(SDValue Op) { |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 485 | MVT VT = Op.getValueType(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 486 | switch (getTypeAction(VT)) { |
| 487 | default: assert(0 && "Bad type action!"); |
| 488 | case Legal: (void)LegalizeOp(Op); break; |
Mon P Wang | 1448aad | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 489 | case Promote: |
| 490 | if (!VT.isVector()) { |
| 491 | (void)PromoteOp(Op); |
| 492 | break; |
| 493 | } |
| 494 | else { |
| 495 | // See if we can widen otherwise use Expand to either scalarize or split |
| 496 | MVT WidenVT = TLI.getWidenVectorType(VT); |
| 497 | if (WidenVT != MVT::Other) { |
| 498 | (void) WidenVectorOp(Op, WidenVT); |
| 499 | break; |
| 500 | } |
| 501 | // else fall thru to expand since we can't widen the vector |
| 502 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 503 | case Expand: |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 504 | if (!VT.isVector()) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 505 | // If this is an illegal scalar, expand it into its two component |
| 506 | // pieces. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 507 | SDValue X, Y; |
Chris Lattner | dad577b | 2007-08-25 01:00:22 +0000 | [diff] [blame] | 508 | if (Op.getOpcode() == ISD::TargetConstant) |
| 509 | break; // Allow illegal target nodes. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 510 | ExpandOp(Op, X, Y); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 511 | } else if (VT.getVectorNumElements() == 1) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 512 | // If this is an illegal single element vector, convert it to a |
| 513 | // scalar operation. |
| 514 | (void)ScalarizeVectorOp(Op); |
| 515 | } else { |
Mon P Wang | 1448aad | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 516 | // This is an illegal multiple element vector. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 517 | // Split it in half and legalize both parts. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 518 | SDValue X, Y; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 519 | SplitVectorOp(Op, X, Y); |
| 520 | } |
| 521 | break; |
| 522 | } |
| 523 | } |
| 524 | |
| 525 | /// ExpandConstantFP - Expands the ConstantFP node to an integer constant or |
| 526 | /// a load from the constant pool. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 527 | static SDValue ExpandConstantFP(ConstantFPSDNode *CFP, bool UseCP, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 528 | SelectionDAG &DAG, TargetLowering &TLI) { |
| 529 | bool Extend = false; |
| 530 | |
| 531 | // If a FP immediate is precise when represented as a float and if the |
| 532 | // target can do an extending load from float to double, we put it into |
| 533 | // the constant pool as a float, even if it's is statically typed as a |
Chris Lattner | e718cc5 | 2008-03-05 06:46:58 +0000 | [diff] [blame] | 534 | // double. This shrinks FP constants and canonicalizes them for targets where |
| 535 | // an FP extending load is the same cost as a normal load (such as on the x87 |
| 536 | // fp stack or PPC FP unit). |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 537 | MVT VT = CFP->getValueType(0); |
Dan Gohman | c1f3a07 | 2008-09-12 18:08:03 +0000 | [diff] [blame] | 538 | ConstantFP *LLVMC = const_cast<ConstantFP*>(CFP->getConstantFPValue()); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 539 | if (!UseCP) { |
Dale Johannesen | 2fc2078 | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 540 | if (VT!=MVT::f64 && VT!=MVT::f32) |
| 541 | assert(0 && "Invalid type expansion"); |
Dale Johannesen | 49cc7ce | 2008-10-09 18:53:47 +0000 | [diff] [blame] | 542 | return DAG.getConstant(LLVMC->getValueAPF().bitcastToAPInt(), |
Evan Cheng | 354be06 | 2008-03-04 08:05:30 +0000 | [diff] [blame] | 543 | (VT == MVT::f64) ? MVT::i64 : MVT::i32); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 544 | } |
| 545 | |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 546 | MVT OrigVT = VT; |
| 547 | MVT SVT = VT; |
Evan Cheng | 354be06 | 2008-03-04 08:05:30 +0000 | [diff] [blame] | 548 | while (SVT != MVT::f32) { |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 549 | SVT = (MVT::SimpleValueType)(SVT.getSimpleVT() - 1); |
Evan Cheng | 354be06 | 2008-03-04 08:05:30 +0000 | [diff] [blame] | 550 | if (CFP->isValueValidForType(SVT, CFP->getValueAPF()) && |
| 551 | // Only do this if the target has a native EXTLOAD instruction from |
| 552 | // smaller type. |
Evan Cheng | 08c171a | 2008-10-14 21:26:46 +0000 | [diff] [blame] | 553 | TLI.isLoadExtLegal(ISD::EXTLOAD, SVT) && |
Chris Lattner | e718cc5 | 2008-03-05 06:46:58 +0000 | [diff] [blame] | 554 | TLI.ShouldShrinkFPConstant(OrigVT)) { |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 555 | const Type *SType = SVT.getTypeForMVT(); |
Evan Cheng | 354be06 | 2008-03-04 08:05:30 +0000 | [diff] [blame] | 556 | LLVMC = cast<ConstantFP>(ConstantExpr::getFPTrunc(LLVMC, SType)); |
| 557 | VT = SVT; |
| 558 | Extend = true; |
| 559 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 560 | } |
| 561 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 562 | SDValue CPIdx = DAG.getConstantPool(LLVMC, TLI.getPointerTy()); |
Dan Gohman | 04637d1 | 2008-09-16 22:05:41 +0000 | [diff] [blame] | 563 | unsigned Alignment = 1 << cast<ConstantPoolSDNode>(CPIdx)->getAlignment(); |
Evan Cheng | 354be06 | 2008-03-04 08:05:30 +0000 | [diff] [blame] | 564 | if (Extend) |
| 565 | return DAG.getExtLoad(ISD::EXTLOAD, OrigVT, DAG.getEntryNode(), |
Dan Gohman | fb020b6 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 566 | CPIdx, PseudoSourceValue::getConstantPool(), |
Dan Gohman | 04637d1 | 2008-09-16 22:05:41 +0000 | [diff] [blame] | 567 | 0, VT, false, Alignment); |
Evan Cheng | 354be06 | 2008-03-04 08:05:30 +0000 | [diff] [blame] | 568 | return DAG.getLoad(OrigVT, DAG.getEntryNode(), CPIdx, |
Dan Gohman | 04637d1 | 2008-09-16 22:05:41 +0000 | [diff] [blame] | 569 | PseudoSourceValue::getConstantPool(), 0, false, Alignment); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | |
| 573 | /// ExpandFCOPYSIGNToBitwiseOps - Expands fcopysign to a series of bitwise |
| 574 | /// operations. |
| 575 | static |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 576 | SDValue ExpandFCOPYSIGNToBitwiseOps(SDNode *Node, MVT NVT, |
| 577 | SelectionDAG &DAG, TargetLowering &TLI) { |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 578 | MVT VT = Node->getValueType(0); |
| 579 | MVT SrcVT = Node->getOperand(1).getValueType(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 580 | assert((SrcVT == MVT::f32 || SrcVT == MVT::f64) && |
| 581 | "fcopysign expansion only supported for f32 and f64"); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 582 | MVT SrcNVT = (SrcVT == MVT::f64) ? MVT::i64 : MVT::i32; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 583 | |
| 584 | // First get the sign bit of second operand. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 585 | SDValue Mask1 = (SrcVT == MVT::f64) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 586 | ? DAG.getConstantFP(BitsToDouble(1ULL << 63), SrcVT) |
| 587 | : DAG.getConstantFP(BitsToFloat(1U << 31), SrcVT); |
| 588 | Mask1 = DAG.getNode(ISD::BIT_CONVERT, SrcNVT, Mask1); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 589 | SDValue SignBit= DAG.getNode(ISD::BIT_CONVERT, SrcNVT, Node->getOperand(1)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 590 | SignBit = DAG.getNode(ISD::AND, SrcNVT, SignBit, Mask1); |
| 591 | // Shift right or sign-extend it if the two operands have different types. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 592 | int SizeDiff = SrcNVT.getSizeInBits() - NVT.getSizeInBits(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 593 | if (SizeDiff > 0) { |
| 594 | SignBit = DAG.getNode(ISD::SRL, SrcNVT, SignBit, |
| 595 | DAG.getConstant(SizeDiff, TLI.getShiftAmountTy())); |
| 596 | SignBit = DAG.getNode(ISD::TRUNCATE, NVT, SignBit); |
Chris Lattner | e6fa145 | 2008-07-10 23:46:13 +0000 | [diff] [blame] | 597 | } else if (SizeDiff < 0) { |
| 598 | SignBit = DAG.getNode(ISD::ZERO_EXTEND, NVT, SignBit); |
| 599 | SignBit = DAG.getNode(ISD::SHL, NVT, SignBit, |
| 600 | DAG.getConstant(-SizeDiff, TLI.getShiftAmountTy())); |
| 601 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 602 | |
| 603 | // Clear the sign bit of first operand. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 604 | SDValue Mask2 = (VT == MVT::f64) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 605 | ? DAG.getConstantFP(BitsToDouble(~(1ULL << 63)), VT) |
| 606 | : DAG.getConstantFP(BitsToFloat(~(1U << 31)), VT); |
| 607 | Mask2 = DAG.getNode(ISD::BIT_CONVERT, NVT, Mask2); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 608 | SDValue Result = DAG.getNode(ISD::BIT_CONVERT, NVT, Node->getOperand(0)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 609 | Result = DAG.getNode(ISD::AND, NVT, Result, Mask2); |
| 610 | |
| 611 | // Or the value with the sign bit. |
| 612 | Result = DAG.getNode(ISD::OR, NVT, Result, SignBit); |
| 613 | return Result; |
| 614 | } |
| 615 | |
Lauro Ramos Venancio | 578434f | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 616 | /// ExpandUnalignedStore - Expands an unaligned store to 2 half-size stores. |
| 617 | static |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 618 | SDValue ExpandUnalignedStore(StoreSDNode *ST, SelectionDAG &DAG, |
| 619 | TargetLowering &TLI) { |
| 620 | SDValue Chain = ST->getChain(); |
| 621 | SDValue Ptr = ST->getBasePtr(); |
| 622 | SDValue Val = ST->getValue(); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 623 | MVT VT = Val.getValueType(); |
Dale Johannesen | 0827538 | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 624 | int Alignment = ST->getAlignment(); |
| 625 | int SVOffset = ST->getSrcValueOffset(); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 626 | if (ST->getMemoryVT().isFloatingPoint() || |
| 627 | ST->getMemoryVT().isVector()) { |
Dale Johannesen | 0827538 | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 628 | // Expand to a bitconvert of the value to the integer type of the |
| 629 | // same size, then a (misaligned) int store. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 630 | MVT intVT; |
| 631 | if (VT.is128BitVector() || VT == MVT::ppcf128 || VT == MVT::f128) |
Dale Johannesen | dc0ee19 | 2008-02-27 22:36:00 +0000 | [diff] [blame] | 632 | intVT = MVT::i128; |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 633 | else if (VT.is64BitVector() || VT==MVT::f64) |
Dale Johannesen | 0827538 | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 634 | intVT = MVT::i64; |
| 635 | else if (VT==MVT::f32) |
| 636 | intVT = MVT::i32; |
| 637 | else |
Dale Johannesen | b1d1ab9 | 2008-02-28 18:36:51 +0000 | [diff] [blame] | 638 | assert(0 && "Unaligned store of unsupported type"); |
Dale Johannesen | 0827538 | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 639 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 640 | SDValue Result = DAG.getNode(ISD::BIT_CONVERT, intVT, Val); |
Dale Johannesen | 0827538 | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 641 | return DAG.getStore(Chain, Result, Ptr, ST->getSrcValue(), |
| 642 | SVOffset, ST->isVolatile(), Alignment); |
| 643 | } |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 644 | assert(ST->getMemoryVT().isInteger() && |
| 645 | !ST->getMemoryVT().isVector() && |
Dale Johannesen | 0827538 | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 646 | "Unaligned store of unknown type."); |
Lauro Ramos Venancio | 578434f | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 647 | // Get the half-size VT |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 648 | MVT NewStoredVT = |
| 649 | (MVT::SimpleValueType)(ST->getMemoryVT().getSimpleVT() - 1); |
| 650 | int NumBits = NewStoredVT.getSizeInBits(); |
Lauro Ramos Venancio | 578434f | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 651 | int IncrementSize = NumBits / 8; |
| 652 | |
| 653 | // Divide the stored value in two parts. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 654 | SDValue ShiftAmount = DAG.getConstant(NumBits, TLI.getShiftAmountTy()); |
| 655 | SDValue Lo = Val; |
| 656 | SDValue Hi = DAG.getNode(ISD::SRL, VT, Val, ShiftAmount); |
Lauro Ramos Venancio | 578434f | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 657 | |
| 658 | // Store the two parts |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 659 | SDValue Store1, Store2; |
Lauro Ramos Venancio | 578434f | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 660 | Store1 = DAG.getTruncStore(Chain, TLI.isLittleEndian()?Lo:Hi, Ptr, |
| 661 | ST->getSrcValue(), SVOffset, NewStoredVT, |
| 662 | ST->isVolatile(), Alignment); |
| 663 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
| 664 | DAG.getConstant(IncrementSize, TLI.getPointerTy())); |
Duncan Sands | a369143 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 665 | Alignment = MinAlign(Alignment, IncrementSize); |
Lauro Ramos Venancio | 578434f | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 666 | Store2 = DAG.getTruncStore(Chain, TLI.isLittleEndian()?Hi:Lo, Ptr, |
| 667 | ST->getSrcValue(), SVOffset + IncrementSize, |
| 668 | NewStoredVT, ST->isVolatile(), Alignment); |
| 669 | |
| 670 | return DAG.getNode(ISD::TokenFactor, MVT::Other, Store1, Store2); |
| 671 | } |
| 672 | |
| 673 | /// ExpandUnalignedLoad - Expands an unaligned load to 2 half-size loads. |
| 674 | static |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 675 | SDValue ExpandUnalignedLoad(LoadSDNode *LD, SelectionDAG &DAG, |
| 676 | TargetLowering &TLI) { |
Lauro Ramos Venancio | 578434f | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 677 | int SVOffset = LD->getSrcValueOffset(); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 678 | SDValue Chain = LD->getChain(); |
| 679 | SDValue Ptr = LD->getBasePtr(); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 680 | MVT VT = LD->getValueType(0); |
| 681 | MVT LoadedVT = LD->getMemoryVT(); |
| 682 | if (VT.isFloatingPoint() || VT.isVector()) { |
Dale Johannesen | 0827538 | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 683 | // Expand to a (misaligned) integer load of the same size, |
Dale Johannesen | dc0ee19 | 2008-02-27 22:36:00 +0000 | [diff] [blame] | 684 | // then bitconvert to floating point or vector. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 685 | MVT intVT; |
| 686 | if (LoadedVT.is128BitVector() || |
Dale Johannesen | f8c1e85 | 2008-03-01 03:40:57 +0000 | [diff] [blame] | 687 | LoadedVT == MVT::ppcf128 || LoadedVT == MVT::f128) |
Dale Johannesen | dc0ee19 | 2008-02-27 22:36:00 +0000 | [diff] [blame] | 688 | intVT = MVT::i128; |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 689 | else if (LoadedVT.is64BitVector() || LoadedVT == MVT::f64) |
Dale Johannesen | 0827538 | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 690 | intVT = MVT::i64; |
Chris Lattner | 4cf8a5b | 2007-11-19 21:38:03 +0000 | [diff] [blame] | 691 | else if (LoadedVT == MVT::f32) |
Dale Johannesen | 0827538 | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 692 | intVT = MVT::i32; |
| 693 | else |
Dale Johannesen | dc0ee19 | 2008-02-27 22:36:00 +0000 | [diff] [blame] | 694 | assert(0 && "Unaligned load of unsupported type"); |
Dale Johannesen | 0827538 | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 695 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 696 | SDValue newLoad = DAG.getLoad(intVT, Chain, Ptr, LD->getSrcValue(), |
Dale Johannesen | 0827538 | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 697 | SVOffset, LD->isVolatile(), |
| 698 | LD->getAlignment()); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 699 | SDValue Result = DAG.getNode(ISD::BIT_CONVERT, LoadedVT, newLoad); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 700 | if (VT.isFloatingPoint() && LoadedVT != VT) |
Dale Johannesen | 0827538 | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 701 | Result = DAG.getNode(ISD::FP_EXTEND, VT, Result); |
| 702 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 703 | SDValue Ops[] = { Result, Chain }; |
Duncan Sands | 698842f | 2008-07-02 17:40:58 +0000 | [diff] [blame] | 704 | return DAG.getMergeValues(Ops, 2); |
Dale Johannesen | 0827538 | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 705 | } |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 706 | assert(LoadedVT.isInteger() && !LoadedVT.isVector() && |
Chris Lattner | 4cf8a5b | 2007-11-19 21:38:03 +0000 | [diff] [blame] | 707 | "Unaligned load of unsupported type."); |
| 708 | |
Dale Johannesen | dc0ee19 | 2008-02-27 22:36:00 +0000 | [diff] [blame] | 709 | // Compute the new VT that is half the size of the old one. This is an |
| 710 | // integer MVT. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 711 | unsigned NumBits = LoadedVT.getSizeInBits(); |
| 712 | MVT NewLoadedVT; |
| 713 | NewLoadedVT = MVT::getIntegerVT(NumBits/2); |
Chris Lattner | 4cf8a5b | 2007-11-19 21:38:03 +0000 | [diff] [blame] | 714 | NumBits >>= 1; |
| 715 | |
| 716 | unsigned Alignment = LD->getAlignment(); |
| 717 | unsigned IncrementSize = NumBits / 8; |
Lauro Ramos Venancio | 578434f | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 718 | ISD::LoadExtType HiExtType = LD->getExtensionType(); |
| 719 | |
| 720 | // If the original load is NON_EXTLOAD, the hi part load must be ZEXTLOAD. |
| 721 | if (HiExtType == ISD::NON_EXTLOAD) |
| 722 | HiExtType = ISD::ZEXTLOAD; |
| 723 | |
| 724 | // Load the value in two parts |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 725 | SDValue Lo, Hi; |
Lauro Ramos Venancio | 578434f | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 726 | if (TLI.isLittleEndian()) { |
| 727 | Lo = DAG.getExtLoad(ISD::ZEXTLOAD, VT, Chain, Ptr, LD->getSrcValue(), |
| 728 | SVOffset, NewLoadedVT, LD->isVolatile(), Alignment); |
| 729 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
| 730 | DAG.getConstant(IncrementSize, TLI.getPointerTy())); |
| 731 | Hi = DAG.getExtLoad(HiExtType, VT, Chain, Ptr, LD->getSrcValue(), |
| 732 | SVOffset + IncrementSize, NewLoadedVT, LD->isVolatile(), |
Duncan Sands | a369143 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 733 | MinAlign(Alignment, IncrementSize)); |
Lauro Ramos Venancio | 578434f | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 734 | } else { |
| 735 | Hi = DAG.getExtLoad(HiExtType, VT, Chain, Ptr, LD->getSrcValue(), SVOffset, |
| 736 | NewLoadedVT,LD->isVolatile(), Alignment); |
| 737 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
| 738 | DAG.getConstant(IncrementSize, TLI.getPointerTy())); |
| 739 | Lo = DAG.getExtLoad(ISD::ZEXTLOAD, VT, Chain, Ptr, LD->getSrcValue(), |
| 740 | SVOffset + IncrementSize, NewLoadedVT, LD->isVolatile(), |
Duncan Sands | a369143 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 741 | MinAlign(Alignment, IncrementSize)); |
Lauro Ramos Venancio | 578434f | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | // aggregate the two parts |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 745 | SDValue ShiftAmount = DAG.getConstant(NumBits, TLI.getShiftAmountTy()); |
| 746 | SDValue Result = DAG.getNode(ISD::SHL, VT, Hi, ShiftAmount); |
Lauro Ramos Venancio | 578434f | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 747 | Result = DAG.getNode(ISD::OR, VT, Result, Lo); |
| 748 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 749 | SDValue TF = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1), |
Lauro Ramos Venancio | 578434f | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 750 | Hi.getValue(1)); |
| 751 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 752 | SDValue Ops[] = { Result, TF }; |
Duncan Sands | 698842f | 2008-07-02 17:40:58 +0000 | [diff] [blame] | 753 | return DAG.getMergeValues(Ops, 2); |
Lauro Ramos Venancio | 578434f | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 754 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 755 | |
Dan Gohman | 6d05cac | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 756 | /// UnrollVectorOp - We know that the given vector has a legal type, however |
| 757 | /// the operation it performs is not legal and is an operation that we have |
| 758 | /// no way of lowering. "Unroll" the vector, splitting out the scalars and |
| 759 | /// operating on each element individually. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 760 | SDValue SelectionDAGLegalize::UnrollVectorOp(SDValue Op) { |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 761 | MVT VT = Op.getValueType(); |
Dan Gohman | 6d05cac | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 762 | assert(isTypeLegal(VT) && |
| 763 | "Caller should expand or promote operands that are not legal!"); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 764 | assert(Op.getNode()->getNumValues() == 1 && |
Dan Gohman | 6d05cac | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 765 | "Can't unroll a vector with multiple results!"); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 766 | unsigned NE = VT.getVectorNumElements(); |
| 767 | MVT EltVT = VT.getVectorElementType(); |
Dan Gohman | 6d05cac | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 768 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 769 | SmallVector<SDValue, 8> Scalars; |
| 770 | SmallVector<SDValue, 4> Operands(Op.getNumOperands()); |
Dan Gohman | 6d05cac | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 771 | for (unsigned i = 0; i != NE; ++i) { |
| 772 | for (unsigned j = 0; j != Op.getNumOperands(); ++j) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 773 | SDValue Operand = Op.getOperand(j); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 774 | MVT OperandVT = Operand.getValueType(); |
| 775 | if (OperandVT.isVector()) { |
Dan Gohman | 6d05cac | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 776 | // A vector operand; extract a single element. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 777 | MVT OperandEltVT = OperandVT.getVectorElementType(); |
Dan Gohman | 6d05cac | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 778 | Operands[j] = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, |
| 779 | OperandEltVT, |
| 780 | Operand, |
| 781 | DAG.getConstant(i, MVT::i32)); |
| 782 | } else { |
| 783 | // A scalar operand; just use it as is. |
| 784 | Operands[j] = Operand; |
| 785 | } |
| 786 | } |
| 787 | Scalars.push_back(DAG.getNode(Op.getOpcode(), EltVT, |
| 788 | &Operands[0], Operands.size())); |
| 789 | } |
| 790 | |
| 791 | return DAG.getNode(ISD::BUILD_VECTOR, VT, &Scalars[0], Scalars.size()); |
| 792 | } |
| 793 | |
Duncan Sands | 37a3f47 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 794 | /// GetFPLibCall - Return the right libcall for the given floating point type. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 795 | static RTLIB::Libcall GetFPLibCall(MVT VT, |
Duncan Sands | 37a3f47 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 796 | RTLIB::Libcall Call_F32, |
| 797 | RTLIB::Libcall Call_F64, |
| 798 | RTLIB::Libcall Call_F80, |
| 799 | RTLIB::Libcall Call_PPCF128) { |
| 800 | return |
| 801 | VT == MVT::f32 ? Call_F32 : |
| 802 | VT == MVT::f64 ? Call_F64 : |
| 803 | VT == MVT::f80 ? Call_F80 : |
| 804 | VT == MVT::ppcf128 ? Call_PPCF128 : |
| 805 | RTLIB::UNKNOWN_LIBCALL; |
| 806 | } |
| 807 | |
Nate Begeman | 7c9e4b7 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 808 | /// PerformInsertVectorEltInMemory - Some target cannot handle a variable |
| 809 | /// insertion index for the INSERT_VECTOR_ELT instruction. In this case, it |
| 810 | /// is necessary to spill the vector being inserted into to memory, perform |
| 811 | /// the insert there, and then read the result back. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 812 | SDValue SelectionDAGLegalize:: |
| 813 | PerformInsertVectorEltInMemory(SDValue Vec, SDValue Val, SDValue Idx) { |
| 814 | SDValue Tmp1 = Vec; |
| 815 | SDValue Tmp2 = Val; |
| 816 | SDValue Tmp3 = Idx; |
Nate Begeman | 7c9e4b7 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 817 | |
| 818 | // If the target doesn't support this, we have to spill the input vector |
| 819 | // to a temporary stack slot, update the element, then reload it. This is |
| 820 | // badness. We could also load the value into a vector register (either |
| 821 | // with a "move to register" or "extload into register" instruction, then |
| 822 | // permute it into place, if the idx is a constant and if the idx is |
| 823 | // supported by the target. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 824 | MVT VT = Tmp1.getValueType(); |
| 825 | MVT EltVT = VT.getVectorElementType(); |
| 826 | MVT IdxVT = Tmp3.getValueType(); |
| 827 | MVT PtrVT = TLI.getPointerTy(); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 828 | SDValue StackPtr = DAG.CreateStackTemporary(VT); |
Nate Begeman | 7c9e4b7 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 829 | |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 830 | int SPFI = cast<FrameIndexSDNode>(StackPtr.getNode())->getIndex(); |
Nate Begeman | 7c9e4b7 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 831 | |
| 832 | // Store the vector. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 833 | SDValue Ch = DAG.getStore(DAG.getEntryNode(), Tmp1, StackPtr, |
Mon P Wang | 1448aad | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 834 | PseudoSourceValue::getFixedStack(SPFI), 0); |
Nate Begeman | 7c9e4b7 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 835 | |
| 836 | // Truncate or zero extend offset to target pointer type. |
Duncan Sands | ec142ee | 2008-06-08 20:54:56 +0000 | [diff] [blame] | 837 | unsigned CastOpc = IdxVT.bitsGT(PtrVT) ? ISD::TRUNCATE : ISD::ZERO_EXTEND; |
Nate Begeman | 7c9e4b7 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 838 | Tmp3 = DAG.getNode(CastOpc, PtrVT, Tmp3); |
| 839 | // Add the offset to the index. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 840 | unsigned EltSize = EltVT.getSizeInBits()/8; |
Nate Begeman | 7c9e4b7 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 841 | Tmp3 = DAG.getNode(ISD::MUL, IdxVT, Tmp3,DAG.getConstant(EltSize, IdxVT)); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 842 | SDValue StackPtr2 = DAG.getNode(ISD::ADD, IdxVT, Tmp3, StackPtr); |
Nate Begeman | 7c9e4b7 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 843 | // Store the scalar value. |
| 844 | Ch = DAG.getTruncStore(Ch, Tmp2, StackPtr2, |
Dan Gohman | 1fc34bc | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 845 | PseudoSourceValue::getFixedStack(SPFI), 0, EltVT); |
Nate Begeman | 7c9e4b7 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 846 | // Load the updated vector. |
Dan Gohman | 1fc34bc | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 847 | return DAG.getLoad(VT, Ch, StackPtr, |
| 848 | PseudoSourceValue::getFixedStack(SPFI), 0); |
Nate Begeman | 7c9e4b7 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 849 | } |
| 850 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 851 | /// LegalizeOp - We know that the specified value has a legal type, and |
| 852 | /// that its operands are legal. Now ensure that the operation itself |
| 853 | /// is legal, recursively ensuring that the operands' operations remain |
| 854 | /// legal. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 855 | SDValue SelectionDAGLegalize::LegalizeOp(SDValue Op) { |
Chris Lattner | dad577b | 2007-08-25 01:00:22 +0000 | [diff] [blame] | 856 | if (Op.getOpcode() == ISD::TargetConstant) // Allow illegal target nodes. |
| 857 | return Op; |
| 858 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 859 | assert(isTypeLegal(Op.getValueType()) && |
| 860 | "Caller should expand or promote operands that are not legal!"); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 861 | SDNode *Node = Op.getNode(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 862 | |
| 863 | // If this operation defines any values that cannot be represented in a |
| 864 | // register on this target, make sure to expand or promote them. |
| 865 | if (Node->getNumValues() > 1) { |
| 866 | for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) |
| 867 | if (getTypeAction(Node->getValueType(i)) != Legal) { |
| 868 | HandleOp(Op.getValue(i)); |
| 869 | assert(LegalizedNodes.count(Op) && |
| 870 | "Handling didn't add legal operands!"); |
| 871 | return LegalizedNodes[Op]; |
| 872 | } |
| 873 | } |
| 874 | |
| 875 | // Note that LegalizeOp may be reentered even from single-use nodes, which |
| 876 | // means that we always must cache transformed nodes. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 877 | DenseMap<SDValue, SDValue>::iterator I = LegalizedNodes.find(Op); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 878 | if (I != LegalizedNodes.end()) return I->second; |
| 879 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 880 | SDValue Tmp1, Tmp2, Tmp3, Tmp4; |
| 881 | SDValue Result = Op; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 882 | bool isCustom = false; |
| 883 | |
| 884 | switch (Node->getOpcode()) { |
| 885 | case ISD::FrameIndex: |
| 886 | case ISD::EntryToken: |
| 887 | case ISD::Register: |
| 888 | case ISD::BasicBlock: |
| 889 | case ISD::TargetFrameIndex: |
| 890 | case ISD::TargetJumpTable: |
| 891 | case ISD::TargetConstant: |
| 892 | case ISD::TargetConstantFP: |
| 893 | case ISD::TargetConstantPool: |
| 894 | case ISD::TargetGlobalAddress: |
| 895 | case ISD::TargetGlobalTLSAddress: |
Bill Wendling | fef0605 | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 896 | case ISD::TargetExternalSymbol: |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 897 | case ISD::VALUETYPE: |
| 898 | case ISD::SRCVALUE: |
Dan Gohman | 12a9c08 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 899 | case ISD::MEMOPERAND: |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 900 | case ISD::CONDCODE: |
Duncan Sands | c93fae3 | 2008-03-21 09:14:45 +0000 | [diff] [blame] | 901 | case ISD::ARG_FLAGS: |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 902 | // Primitives must all be legal. |
Duncan Sands | b42a44e | 2007-10-16 09:07:20 +0000 | [diff] [blame] | 903 | assert(TLI.isOperationLegal(Node->getOpcode(), Node->getValueType(0)) && |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 904 | "This must be legal!"); |
| 905 | break; |
| 906 | default: |
| 907 | if (Node->getOpcode() >= ISD::BUILTIN_OP_END) { |
| 908 | // If this is a target node, legalize it by legalizing the operands then |
| 909 | // passing it through. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 910 | SmallVector<SDValue, 8> Ops; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 911 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) |
| 912 | Ops.push_back(LegalizeOp(Node->getOperand(i))); |
| 913 | |
| 914 | Result = DAG.UpdateNodeOperands(Result.getValue(0), &Ops[0], Ops.size()); |
| 915 | |
| 916 | for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) |
| 917 | AddLegalizedOperand(Op.getValue(i), Result.getValue(i)); |
Gabor Greif | 46bf547 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 918 | return Result.getValue(Op.getResNo()); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 919 | } |
| 920 | // Otherwise this is an unhandled builtin node. splat. |
| 921 | #ifndef NDEBUG |
| 922 | cerr << "NODE: "; Node->dump(&DAG); cerr << "\n"; |
| 923 | #endif |
| 924 | assert(0 && "Do not know how to legalize this operator!"); |
| 925 | abort(); |
| 926 | case ISD::GLOBAL_OFFSET_TABLE: |
| 927 | case ISD::GlobalAddress: |
| 928 | case ISD::GlobalTLSAddress: |
Bill Wendling | fef0605 | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 929 | case ISD::ExternalSymbol: |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 930 | case ISD::ConstantPool: |
| 931 | case ISD::JumpTable: // Nothing to do. |
| 932 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 933 | default: assert(0 && "This action is not supported yet!"); |
| 934 | case TargetLowering::Custom: |
| 935 | Tmp1 = TLI.LowerOperation(Op, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 936 | if (Tmp1.getNode()) Result = Tmp1; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 937 | // FALLTHROUGH if the target doesn't want to lower this op after all. |
| 938 | case TargetLowering::Legal: |
| 939 | break; |
| 940 | } |
| 941 | break; |
| 942 | case ISD::FRAMEADDR: |
| 943 | case ISD::RETURNADDR: |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 944 | // The only option for these nodes is to custom lower them. If the target |
| 945 | // does not custom lower them, then return zero. |
| 946 | Tmp1 = TLI.LowerOperation(Op, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 947 | if (Tmp1.getNode()) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 948 | Result = Tmp1; |
| 949 | else |
| 950 | Result = DAG.getConstant(0, TLI.getPointerTy()); |
| 951 | break; |
Anton Korobeynikov | e3d7f93 | 2007-08-29 23:18:48 +0000 | [diff] [blame] | 952 | case ISD::FRAME_TO_ARGS_OFFSET: { |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 953 | MVT VT = Node->getValueType(0); |
Anton Korobeynikov | 09386bd | 2007-08-29 19:28:29 +0000 | [diff] [blame] | 954 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 955 | default: assert(0 && "This action is not supported yet!"); |
| 956 | case TargetLowering::Custom: |
| 957 | Result = TLI.LowerOperation(Op, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 958 | if (Result.getNode()) break; |
Anton Korobeynikov | 09386bd | 2007-08-29 19:28:29 +0000 | [diff] [blame] | 959 | // Fall Thru |
| 960 | case TargetLowering::Legal: |
| 961 | Result = DAG.getConstant(0, VT); |
| 962 | break; |
| 963 | } |
Anton Korobeynikov | e3d7f93 | 2007-08-29 23:18:48 +0000 | [diff] [blame] | 964 | } |
Anton Korobeynikov | 09386bd | 2007-08-29 19:28:29 +0000 | [diff] [blame] | 965 | break; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 966 | case ISD::EXCEPTIONADDR: { |
| 967 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 968 | MVT VT = Node->getValueType(0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 969 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 970 | default: assert(0 && "This action is not supported yet!"); |
| 971 | case TargetLowering::Expand: { |
| 972 | unsigned Reg = TLI.getExceptionAddressRegister(); |
Duncan Sands | c7f7d5e | 2007-12-31 18:35:50 +0000 | [diff] [blame] | 973 | Result = DAG.getCopyFromReg(Tmp1, Reg, VT); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 974 | } |
| 975 | break; |
| 976 | case TargetLowering::Custom: |
| 977 | Result = TLI.LowerOperation(Op, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 978 | if (Result.getNode()) break; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 979 | // Fall Thru |
| 980 | case TargetLowering::Legal: { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 981 | SDValue Ops[] = { DAG.getConstant(0, VT), Tmp1 }; |
Duncan Sands | 698842f | 2008-07-02 17:40:58 +0000 | [diff] [blame] | 982 | Result = DAG.getMergeValues(Ops, 2); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 983 | break; |
| 984 | } |
| 985 | } |
| 986 | } |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 987 | if (Result.getNode()->getNumValues() == 1) break; |
Duncan Sands | c7f7d5e | 2007-12-31 18:35:50 +0000 | [diff] [blame] | 988 | |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 989 | assert(Result.getNode()->getNumValues() == 2 && |
Duncan Sands | c7f7d5e | 2007-12-31 18:35:50 +0000 | [diff] [blame] | 990 | "Cannot return more than two values!"); |
| 991 | |
| 992 | // Since we produced two values, make sure to remember that we |
| 993 | // legalized both of them. |
| 994 | Tmp1 = LegalizeOp(Result); |
| 995 | Tmp2 = LegalizeOp(Result.getValue(1)); |
| 996 | AddLegalizedOperand(Op.getValue(0), Tmp1); |
| 997 | AddLegalizedOperand(Op.getValue(1), Tmp2); |
Gabor Greif | 46bf547 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 998 | return Op.getResNo() ? Tmp2 : Tmp1; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 999 | case ISD::EHSELECTION: { |
| 1000 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1001 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1002 | MVT VT = Node->getValueType(0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1003 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 1004 | default: assert(0 && "This action is not supported yet!"); |
| 1005 | case TargetLowering::Expand: { |
| 1006 | unsigned Reg = TLI.getExceptionSelectorRegister(); |
Duncan Sands | c7f7d5e | 2007-12-31 18:35:50 +0000 | [diff] [blame] | 1007 | Result = DAG.getCopyFromReg(Tmp2, Reg, VT); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1008 | } |
| 1009 | break; |
| 1010 | case TargetLowering::Custom: |
| 1011 | Result = TLI.LowerOperation(Op, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1012 | if (Result.getNode()) break; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1013 | // Fall Thru |
| 1014 | case TargetLowering::Legal: { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1015 | SDValue Ops[] = { DAG.getConstant(0, VT), Tmp2 }; |
Duncan Sands | 698842f | 2008-07-02 17:40:58 +0000 | [diff] [blame] | 1016 | Result = DAG.getMergeValues(Ops, 2); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1017 | break; |
| 1018 | } |
| 1019 | } |
| 1020 | } |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1021 | if (Result.getNode()->getNumValues() == 1) break; |
Duncan Sands | c7f7d5e | 2007-12-31 18:35:50 +0000 | [diff] [blame] | 1022 | |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1023 | assert(Result.getNode()->getNumValues() == 2 && |
Duncan Sands | c7f7d5e | 2007-12-31 18:35:50 +0000 | [diff] [blame] | 1024 | "Cannot return more than two values!"); |
| 1025 | |
| 1026 | // Since we produced two values, make sure to remember that we |
| 1027 | // legalized both of them. |
| 1028 | Tmp1 = LegalizeOp(Result); |
| 1029 | Tmp2 = LegalizeOp(Result.getValue(1)); |
| 1030 | AddLegalizedOperand(Op.getValue(0), Tmp1); |
| 1031 | AddLegalizedOperand(Op.getValue(1), Tmp2); |
Gabor Greif | 46bf547 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 1032 | return Op.getResNo() ? Tmp2 : Tmp1; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1033 | case ISD::EH_RETURN: { |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1034 | MVT VT = Node->getValueType(0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1035 | // The only "good" option for this node is to custom lower it. |
| 1036 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 1037 | default: assert(0 && "This action is not supported at all!"); |
| 1038 | case TargetLowering::Custom: |
| 1039 | Result = TLI.LowerOperation(Op, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1040 | if (Result.getNode()) break; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1041 | // Fall Thru |
| 1042 | case TargetLowering::Legal: |
| 1043 | // Target does not know, how to lower this, lower to noop |
| 1044 | Result = LegalizeOp(Node->getOperand(0)); |
| 1045 | break; |
| 1046 | } |
| 1047 | } |
| 1048 | break; |
| 1049 | case ISD::AssertSext: |
| 1050 | case ISD::AssertZext: |
| 1051 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1052 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
| 1053 | break; |
| 1054 | case ISD::MERGE_VALUES: |
| 1055 | // Legalize eliminates MERGE_VALUES nodes. |
Gabor Greif | 46bf547 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 1056 | Result = Node->getOperand(Op.getResNo()); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1057 | break; |
| 1058 | case ISD::CopyFromReg: |
| 1059 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1060 | Result = Op.getValue(0); |
| 1061 | if (Node->getNumValues() == 2) { |
| 1062 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
| 1063 | } else { |
| 1064 | assert(Node->getNumValues() == 3 && "Invalid copyfromreg!"); |
| 1065 | if (Node->getNumOperands() == 3) { |
| 1066 | Tmp2 = LegalizeOp(Node->getOperand(2)); |
| 1067 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1),Tmp2); |
| 1068 | } else { |
| 1069 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
| 1070 | } |
| 1071 | AddLegalizedOperand(Op.getValue(2), Result.getValue(2)); |
| 1072 | } |
| 1073 | // Since CopyFromReg produces two values, make sure to remember that we |
| 1074 | // legalized both of them. |
| 1075 | AddLegalizedOperand(Op.getValue(0), Result); |
| 1076 | AddLegalizedOperand(Op.getValue(1), Result.getValue(1)); |
Gabor Greif | 46bf547 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 1077 | return Result.getValue(Op.getResNo()); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1078 | case ISD::UNDEF: { |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1079 | MVT VT = Op.getValueType(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1080 | switch (TLI.getOperationAction(ISD::UNDEF, VT)) { |
| 1081 | default: assert(0 && "This action is not supported yet!"); |
| 1082 | case TargetLowering::Expand: |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1083 | if (VT.isInteger()) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1084 | Result = DAG.getConstant(0, VT); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1085 | else if (VT.isFloatingPoint()) |
| 1086 | Result = DAG.getConstantFP(APFloat(APInt(VT.getSizeInBits(), 0)), |
Dale Johannesen | 20b7635 | 2007-09-26 17:26:49 +0000 | [diff] [blame] | 1087 | VT); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1088 | else |
| 1089 | assert(0 && "Unknown value type!"); |
| 1090 | break; |
| 1091 | case TargetLowering::Legal: |
| 1092 | break; |
| 1093 | } |
| 1094 | break; |
| 1095 | } |
| 1096 | |
| 1097 | case ISD::INTRINSIC_W_CHAIN: |
| 1098 | case ISD::INTRINSIC_WO_CHAIN: |
| 1099 | case ISD::INTRINSIC_VOID: { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1100 | SmallVector<SDValue, 8> Ops; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1101 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) |
| 1102 | Ops.push_back(LegalizeOp(Node->getOperand(i))); |
| 1103 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
| 1104 | |
| 1105 | // Allow the target to custom lower its intrinsics if it wants to. |
| 1106 | if (TLI.getOperationAction(Node->getOpcode(), MVT::Other) == |
| 1107 | TargetLowering::Custom) { |
| 1108 | Tmp3 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1109 | if (Tmp3.getNode()) Result = Tmp3; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1110 | } |
| 1111 | |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1112 | if (Result.getNode()->getNumValues() == 1) break; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1113 | |
| 1114 | // Must have return value and chain result. |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1115 | assert(Result.getNode()->getNumValues() == 2 && |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1116 | "Cannot return more than two values!"); |
| 1117 | |
| 1118 | // Since loads produce two values, make sure to remember that we |
| 1119 | // legalized both of them. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1120 | AddLegalizedOperand(SDValue(Node, 0), Result.getValue(0)); |
| 1121 | AddLegalizedOperand(SDValue(Node, 1), Result.getValue(1)); |
Gabor Greif | 46bf547 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 1122 | return Result.getValue(Op.getResNo()); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1123 | } |
| 1124 | |
Dan Gohman | 472d12c | 2008-06-30 20:59:49 +0000 | [diff] [blame] | 1125 | case ISD::DBG_STOPPOINT: |
| 1126 | assert(Node->getNumOperands() == 1 && "Invalid DBG_STOPPOINT node!"); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1127 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the input chain. |
| 1128 | |
Dan Gohman | 472d12c | 2008-06-30 20:59:49 +0000 | [diff] [blame] | 1129 | switch (TLI.getOperationAction(ISD::DBG_STOPPOINT, MVT::Other)) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1130 | case TargetLowering::Promote: |
| 1131 | default: assert(0 && "This action is not supported yet!"); |
| 1132 | case TargetLowering::Expand: { |
| 1133 | MachineModuleInfo *MMI = DAG.getMachineModuleInfo(); |
| 1134 | bool useDEBUG_LOC = TLI.isOperationLegal(ISD::DEBUG_LOC, MVT::Other); |
Dan Gohman | fa607c9 | 2008-07-01 00:05:16 +0000 | [diff] [blame] | 1135 | bool useLABEL = TLI.isOperationLegal(ISD::DBG_LABEL, MVT::Other); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1136 | |
Dan Gohman | 472d12c | 2008-06-30 20:59:49 +0000 | [diff] [blame] | 1137 | const DbgStopPointSDNode *DSP = cast<DbgStopPointSDNode>(Node); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1138 | if (MMI && (useDEBUG_LOC || useLABEL)) { |
Dan Gohman | 472d12c | 2008-06-30 20:59:49 +0000 | [diff] [blame] | 1139 | const CompileUnitDesc *CompileUnit = DSP->getCompileUnit(); |
| 1140 | unsigned SrcFile = MMI->RecordSource(CompileUnit); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1141 | |
Dan Gohman | 472d12c | 2008-06-30 20:59:49 +0000 | [diff] [blame] | 1142 | unsigned Line = DSP->getLine(); |
| 1143 | unsigned Col = DSP->getColumn(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1144 | |
| 1145 | if (useDEBUG_LOC) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1146 | SDValue Ops[] = { Tmp1, DAG.getConstant(Line, MVT::i32), |
Evan Cheng | d6f5768 | 2008-07-08 20:06:39 +0000 | [diff] [blame] | 1147 | DAG.getConstant(Col, MVT::i32), |
| 1148 | DAG.getConstant(SrcFile, MVT::i32) }; |
| 1149 | Result = DAG.getNode(ISD::DEBUG_LOC, MVT::Other, Ops, 4); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1150 | } else { |
Evan Cheng | 69eda82 | 2008-02-01 02:05:57 +0000 | [diff] [blame] | 1151 | unsigned ID = MMI->RecordSourceLine(Line, Col, SrcFile); |
Dan Gohman | fa607c9 | 2008-07-01 00:05:16 +0000 | [diff] [blame] | 1152 | Result = DAG.getLabel(ISD::DBG_LABEL, Tmp1, ID); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1153 | } |
| 1154 | } else { |
| 1155 | Result = Tmp1; // chain |
| 1156 | } |
| 1157 | break; |
| 1158 | } |
Evan Cheng | d6f5768 | 2008-07-08 20:06:39 +0000 | [diff] [blame] | 1159 | case TargetLowering::Legal: { |
| 1160 | LegalizeAction Action = getTypeAction(Node->getOperand(1).getValueType()); |
| 1161 | if (Action == Legal && Tmp1 == Node->getOperand(0)) |
| 1162 | break; |
| 1163 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1164 | SmallVector<SDValue, 8> Ops; |
Evan Cheng | d6f5768 | 2008-07-08 20:06:39 +0000 | [diff] [blame] | 1165 | Ops.push_back(Tmp1); |
| 1166 | if (Action == Legal) { |
| 1167 | Ops.push_back(Node->getOperand(1)); // line # must be legal. |
| 1168 | Ops.push_back(Node->getOperand(2)); // col # must be legal. |
| 1169 | } else { |
| 1170 | // Otherwise promote them. |
| 1171 | Ops.push_back(PromoteOp(Node->getOperand(1))); |
| 1172 | Ops.push_back(PromoteOp(Node->getOperand(2))); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1173 | } |
Evan Cheng | d6f5768 | 2008-07-08 20:06:39 +0000 | [diff] [blame] | 1174 | Ops.push_back(Node->getOperand(3)); // filename must be legal. |
| 1175 | Ops.push_back(Node->getOperand(4)); // working dir # must be legal. |
| 1176 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1177 | break; |
| 1178 | } |
Evan Cheng | d6f5768 | 2008-07-08 20:06:39 +0000 | [diff] [blame] | 1179 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1180 | break; |
Evan Cheng | 2e28d62 | 2008-02-02 04:07:54 +0000 | [diff] [blame] | 1181 | |
| 1182 | case ISD::DECLARE: |
| 1183 | assert(Node->getNumOperands() == 3 && "Invalid DECLARE node!"); |
| 1184 | switch (TLI.getOperationAction(ISD::DECLARE, MVT::Other)) { |
| 1185 | default: assert(0 && "This action is not supported yet!"); |
| 1186 | case TargetLowering::Legal: |
| 1187 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1188 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the address. |
| 1189 | Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the variable. |
| 1190 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
| 1191 | break; |
Chris Lattner | 203cd05 | 2008-02-28 05:53:40 +0000 | [diff] [blame] | 1192 | case TargetLowering::Expand: |
| 1193 | Result = LegalizeOp(Node->getOperand(0)); |
| 1194 | break; |
Evan Cheng | 2e28d62 | 2008-02-02 04:07:54 +0000 | [diff] [blame] | 1195 | } |
| 1196 | break; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1197 | |
| 1198 | case ISD::DEBUG_LOC: |
| 1199 | assert(Node->getNumOperands() == 4 && "Invalid DEBUG_LOC node!"); |
| 1200 | switch (TLI.getOperationAction(ISD::DEBUG_LOC, MVT::Other)) { |
| 1201 | default: assert(0 && "This action is not supported yet!"); |
Evan Cheng | d6f5768 | 2008-07-08 20:06:39 +0000 | [diff] [blame] | 1202 | case TargetLowering::Legal: { |
| 1203 | LegalizeAction Action = getTypeAction(Node->getOperand(1).getValueType()); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1204 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Evan Cheng | d6f5768 | 2008-07-08 20:06:39 +0000 | [diff] [blame] | 1205 | if (Action == Legal && Tmp1 == Node->getOperand(0)) |
| 1206 | break; |
| 1207 | if (Action == Legal) { |
| 1208 | Tmp2 = Node->getOperand(1); |
| 1209 | Tmp3 = Node->getOperand(2); |
| 1210 | Tmp4 = Node->getOperand(3); |
| 1211 | } else { |
| 1212 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the line #. |
| 1213 | Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the col #. |
| 1214 | Tmp4 = LegalizeOp(Node->getOperand(3)); // Legalize the source file id. |
| 1215 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1216 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3, Tmp4); |
| 1217 | break; |
| 1218 | } |
Evan Cheng | d6f5768 | 2008-07-08 20:06:39 +0000 | [diff] [blame] | 1219 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1220 | break; |
| 1221 | |
Dan Gohman | fa607c9 | 2008-07-01 00:05:16 +0000 | [diff] [blame] | 1222 | case ISD::DBG_LABEL: |
| 1223 | case ISD::EH_LABEL: |
| 1224 | assert(Node->getNumOperands() == 1 && "Invalid LABEL node!"); |
| 1225 | switch (TLI.getOperationAction(Node->getOpcode(), MVT::Other)) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1226 | default: assert(0 && "This action is not supported yet!"); |
| 1227 | case TargetLowering::Legal: |
| 1228 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Dan Gohman | fa607c9 | 2008-07-01 00:05:16 +0000 | [diff] [blame] | 1229 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1230 | break; |
| 1231 | case TargetLowering::Expand: |
| 1232 | Result = LegalizeOp(Node->getOperand(0)); |
| 1233 | break; |
| 1234 | } |
| 1235 | break; |
| 1236 | |
Evan Cheng | d1d6807 | 2008-03-08 00:58:38 +0000 | [diff] [blame] | 1237 | case ISD::PREFETCH: |
| 1238 | assert(Node->getNumOperands() == 4 && "Invalid Prefetch node!"); |
| 1239 | switch (TLI.getOperationAction(ISD::PREFETCH, MVT::Other)) { |
| 1240 | default: assert(0 && "This action is not supported yet!"); |
| 1241 | case TargetLowering::Legal: |
| 1242 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1243 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the address. |
| 1244 | Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the rw specifier. |
| 1245 | Tmp4 = LegalizeOp(Node->getOperand(3)); // Legalize locality specifier. |
| 1246 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3, Tmp4); |
| 1247 | break; |
| 1248 | case TargetLowering::Expand: |
| 1249 | // It's a noop. |
| 1250 | Result = LegalizeOp(Node->getOperand(0)); |
| 1251 | break; |
| 1252 | } |
| 1253 | break; |
| 1254 | |
Andrew Lenharth | 785610d | 2008-02-16 01:24:58 +0000 | [diff] [blame] | 1255 | case ISD::MEMBARRIER: { |
| 1256 | assert(Node->getNumOperands() == 6 && "Invalid MemBarrier node!"); |
Andrew Lenharth | 0531ec5 | 2008-02-16 14:46:26 +0000 | [diff] [blame] | 1257 | switch (TLI.getOperationAction(ISD::MEMBARRIER, MVT::Other)) { |
| 1258 | default: assert(0 && "This action is not supported yet!"); |
| 1259 | case TargetLowering::Legal: { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1260 | SDValue Ops[6]; |
Andrew Lenharth | 0531ec5 | 2008-02-16 14:46:26 +0000 | [diff] [blame] | 1261 | Ops[0] = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Duncan Sands | 3ee041a | 2008-02-27 08:53:44 +0000 | [diff] [blame] | 1262 | for (int x = 1; x < 6; ++x) { |
| 1263 | Ops[x] = Node->getOperand(x); |
| 1264 | if (!isTypeLegal(Ops[x].getValueType())) |
| 1265 | Ops[x] = PromoteOp(Ops[x]); |
| 1266 | } |
Andrew Lenharth | 0531ec5 | 2008-02-16 14:46:26 +0000 | [diff] [blame] | 1267 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], 6); |
| 1268 | break; |
| 1269 | } |
| 1270 | case TargetLowering::Expand: |
| 1271 | //There is no libgcc call for this op |
| 1272 | Result = Node->getOperand(0); // Noop |
| 1273 | break; |
| 1274 | } |
Andrew Lenharth | 785610d | 2008-02-16 01:24:58 +0000 | [diff] [blame] | 1275 | break; |
| 1276 | } |
| 1277 | |
Dale Johannesen | bc18766 | 2008-08-28 02:44:49 +0000 | [diff] [blame] | 1278 | case ISD::ATOMIC_CMP_SWAP_8: |
| 1279 | case ISD::ATOMIC_CMP_SWAP_16: |
| 1280 | case ISD::ATOMIC_CMP_SWAP_32: |
| 1281 | case ISD::ATOMIC_CMP_SWAP_64: { |
Mon P Wang | 078a62d | 2008-05-05 19:05:59 +0000 | [diff] [blame] | 1282 | unsigned int num_operands = 4; |
| 1283 | assert(Node->getNumOperands() == num_operands && "Invalid Atomic node!"); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1284 | SDValue Ops[4]; |
Mon P Wang | 078a62d | 2008-05-05 19:05:59 +0000 | [diff] [blame] | 1285 | for (unsigned int x = 0; x < num_operands; ++x) |
Andrew Lenharth | 7dfe23f | 2008-03-01 21:52:34 +0000 | [diff] [blame] | 1286 | Ops[x] = LegalizeOp(Node->getOperand(x)); |
Mon P Wang | 078a62d | 2008-05-05 19:05:59 +0000 | [diff] [blame] | 1287 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], num_operands); |
| 1288 | |
| 1289 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 1290 | default: assert(0 && "This action is not supported yet!"); |
| 1291 | case TargetLowering::Custom: |
| 1292 | Result = TLI.LowerOperation(Result, DAG); |
| 1293 | break; |
| 1294 | case TargetLowering::Legal: |
| 1295 | break; |
| 1296 | } |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1297 | AddLegalizedOperand(SDValue(Node, 0), Result.getValue(0)); |
| 1298 | AddLegalizedOperand(SDValue(Node, 1), Result.getValue(1)); |
Gabor Greif | 46bf547 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 1299 | return Result.getValue(Op.getResNo()); |
Duncan Sands | ac496a1 | 2008-07-04 11:47:58 +0000 | [diff] [blame] | 1300 | } |
Dale Johannesen | bc18766 | 2008-08-28 02:44:49 +0000 | [diff] [blame] | 1301 | case ISD::ATOMIC_LOAD_ADD_8: |
| 1302 | case ISD::ATOMIC_LOAD_SUB_8: |
| 1303 | case ISD::ATOMIC_LOAD_AND_8: |
| 1304 | case ISD::ATOMIC_LOAD_OR_8: |
| 1305 | case ISD::ATOMIC_LOAD_XOR_8: |
| 1306 | case ISD::ATOMIC_LOAD_NAND_8: |
| 1307 | case ISD::ATOMIC_LOAD_MIN_8: |
| 1308 | case ISD::ATOMIC_LOAD_MAX_8: |
| 1309 | case ISD::ATOMIC_LOAD_UMIN_8: |
| 1310 | case ISD::ATOMIC_LOAD_UMAX_8: |
| 1311 | case ISD::ATOMIC_SWAP_8: |
| 1312 | case ISD::ATOMIC_LOAD_ADD_16: |
| 1313 | case ISD::ATOMIC_LOAD_SUB_16: |
| 1314 | case ISD::ATOMIC_LOAD_AND_16: |
| 1315 | case ISD::ATOMIC_LOAD_OR_16: |
| 1316 | case ISD::ATOMIC_LOAD_XOR_16: |
| 1317 | case ISD::ATOMIC_LOAD_NAND_16: |
| 1318 | case ISD::ATOMIC_LOAD_MIN_16: |
| 1319 | case ISD::ATOMIC_LOAD_MAX_16: |
| 1320 | case ISD::ATOMIC_LOAD_UMIN_16: |
| 1321 | case ISD::ATOMIC_LOAD_UMAX_16: |
| 1322 | case ISD::ATOMIC_SWAP_16: |
| 1323 | case ISD::ATOMIC_LOAD_ADD_32: |
| 1324 | case ISD::ATOMIC_LOAD_SUB_32: |
| 1325 | case ISD::ATOMIC_LOAD_AND_32: |
| 1326 | case ISD::ATOMIC_LOAD_OR_32: |
| 1327 | case ISD::ATOMIC_LOAD_XOR_32: |
| 1328 | case ISD::ATOMIC_LOAD_NAND_32: |
| 1329 | case ISD::ATOMIC_LOAD_MIN_32: |
| 1330 | case ISD::ATOMIC_LOAD_MAX_32: |
| 1331 | case ISD::ATOMIC_LOAD_UMIN_32: |
| 1332 | case ISD::ATOMIC_LOAD_UMAX_32: |
| 1333 | case ISD::ATOMIC_SWAP_32: |
| 1334 | case ISD::ATOMIC_LOAD_ADD_64: |
| 1335 | case ISD::ATOMIC_LOAD_SUB_64: |
| 1336 | case ISD::ATOMIC_LOAD_AND_64: |
| 1337 | case ISD::ATOMIC_LOAD_OR_64: |
| 1338 | case ISD::ATOMIC_LOAD_XOR_64: |
| 1339 | case ISD::ATOMIC_LOAD_NAND_64: |
| 1340 | case ISD::ATOMIC_LOAD_MIN_64: |
| 1341 | case ISD::ATOMIC_LOAD_MAX_64: |
| 1342 | case ISD::ATOMIC_LOAD_UMIN_64: |
| 1343 | case ISD::ATOMIC_LOAD_UMAX_64: |
| 1344 | case ISD::ATOMIC_SWAP_64: { |
Mon P Wang | 078a62d | 2008-05-05 19:05:59 +0000 | [diff] [blame] | 1345 | unsigned int num_operands = 3; |
| 1346 | assert(Node->getNumOperands() == num_operands && "Invalid Atomic node!"); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1347 | SDValue Ops[3]; |
Mon P Wang | 078a62d | 2008-05-05 19:05:59 +0000 | [diff] [blame] | 1348 | for (unsigned int x = 0; x < num_operands; ++x) |
| 1349 | Ops[x] = LegalizeOp(Node->getOperand(x)); |
| 1350 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], num_operands); |
Duncan Sands | ac496a1 | 2008-07-04 11:47:58 +0000 | [diff] [blame] | 1351 | |
Andrew Lenharth | 7dfe23f | 2008-03-01 21:52:34 +0000 | [diff] [blame] | 1352 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
Andrew Lenharth | e44f390 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 1353 | default: assert(0 && "This action is not supported yet!"); |
Andrew Lenharth | 7dfe23f | 2008-03-01 21:52:34 +0000 | [diff] [blame] | 1354 | case TargetLowering::Custom: |
| 1355 | Result = TLI.LowerOperation(Result, DAG); |
| 1356 | break; |
| 1357 | case TargetLowering::Legal: |
Andrew Lenharth | e44f390 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 1358 | break; |
| 1359 | } |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1360 | AddLegalizedOperand(SDValue(Node, 0), Result.getValue(0)); |
| 1361 | AddLegalizedOperand(SDValue(Node, 1), Result.getValue(1)); |
Gabor Greif | 46bf547 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 1362 | return Result.getValue(Op.getResNo()); |
Duncan Sands | ac496a1 | 2008-07-04 11:47:58 +0000 | [diff] [blame] | 1363 | } |
Scott Michel | f2e2b70 | 2007-08-08 23:23:31 +0000 | [diff] [blame] | 1364 | case ISD::Constant: { |
| 1365 | ConstantSDNode *CN = cast<ConstantSDNode>(Node); |
| 1366 | unsigned opAction = |
| 1367 | TLI.getOperationAction(ISD::Constant, CN->getValueType(0)); |
| 1368 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1369 | // We know we don't need to expand constants here, constants only have one |
| 1370 | // value and we check that it is fine above. |
| 1371 | |
Scott Michel | f2e2b70 | 2007-08-08 23:23:31 +0000 | [diff] [blame] | 1372 | if (opAction == TargetLowering::Custom) { |
| 1373 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1374 | if (Tmp1.getNode()) |
Scott Michel | f2e2b70 | 2007-08-08 23:23:31 +0000 | [diff] [blame] | 1375 | Result = Tmp1; |
| 1376 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1377 | break; |
Scott Michel | f2e2b70 | 2007-08-08 23:23:31 +0000 | [diff] [blame] | 1378 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1379 | case ISD::ConstantFP: { |
| 1380 | // Spill FP immediates to the constant pool if the target cannot directly |
| 1381 | // codegen them. Targets often have some immediate values that can be |
| 1382 | // efficiently generated into an FP register without a load. We explicitly |
| 1383 | // leave these constants as ConstantFP nodes for the target to deal with. |
| 1384 | ConstantFPSDNode *CFP = cast<ConstantFPSDNode>(Node); |
| 1385 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1386 | switch (TLI.getOperationAction(ISD::ConstantFP, CFP->getValueType(0))) { |
| 1387 | default: assert(0 && "This action is not supported yet!"); |
Nate Begeman | e2ba64f | 2008-02-14 08:57:00 +0000 | [diff] [blame] | 1388 | case TargetLowering::Legal: |
| 1389 | break; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1390 | case TargetLowering::Custom: |
| 1391 | Tmp3 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1392 | if (Tmp3.getNode()) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1393 | Result = Tmp3; |
| 1394 | break; |
| 1395 | } |
| 1396 | // FALLTHROUGH |
Nate Begeman | e2ba64f | 2008-02-14 08:57:00 +0000 | [diff] [blame] | 1397 | case TargetLowering::Expand: { |
| 1398 | // Check to see if this FP immediate is already legal. |
| 1399 | bool isLegal = false; |
| 1400 | for (TargetLowering::legal_fpimm_iterator I = TLI.legal_fpimm_begin(), |
| 1401 | E = TLI.legal_fpimm_end(); I != E; ++I) { |
| 1402 | if (CFP->isExactlyValue(*I)) { |
| 1403 | isLegal = true; |
| 1404 | break; |
| 1405 | } |
| 1406 | } |
| 1407 | // If this is a legal constant, turn it into a TargetConstantFP node. |
| 1408 | if (isLegal) |
| 1409 | break; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1410 | Result = ExpandConstantFP(CFP, true, DAG, TLI); |
| 1411 | } |
Nate Begeman | e2ba64f | 2008-02-14 08:57:00 +0000 | [diff] [blame] | 1412 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1413 | break; |
| 1414 | } |
| 1415 | case ISD::TokenFactor: |
| 1416 | if (Node->getNumOperands() == 2) { |
| 1417 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1418 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1419 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 1420 | } else if (Node->getNumOperands() == 3) { |
| 1421 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1422 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1423 | Tmp3 = LegalizeOp(Node->getOperand(2)); |
| 1424 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
| 1425 | } else { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1426 | SmallVector<SDValue, 8> Ops; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1427 | // Legalize the operands. |
| 1428 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) |
| 1429 | Ops.push_back(LegalizeOp(Node->getOperand(i))); |
| 1430 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
| 1431 | } |
| 1432 | break; |
| 1433 | |
| 1434 | case ISD::FORMAL_ARGUMENTS: |
| 1435 | case ISD::CALL: |
| 1436 | // The only option for this is to custom lower it. |
| 1437 | Tmp3 = TLI.LowerOperation(Result.getValue(0), DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1438 | assert(Tmp3.getNode() && "Target didn't custom lower this node!"); |
Dale Johannesen | ac24627 | 2008-03-05 19:14:03 +0000 | [diff] [blame] | 1439 | // A call within a calling sequence must be legalized to something |
| 1440 | // other than the normal CALLSEQ_END. Violating this gets Legalize |
| 1441 | // into an infinite loop. |
| 1442 | assert ((!IsLegalizingCall || |
| 1443 | Node->getOpcode() != ISD::CALL || |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1444 | Tmp3.getNode()->getOpcode() != ISD::CALLSEQ_END) && |
Dale Johannesen | ac24627 | 2008-03-05 19:14:03 +0000 | [diff] [blame] | 1445 | "Nested CALLSEQ_START..CALLSEQ_END not supported."); |
Bill Wendling | 22f8deb | 2007-11-13 00:44:25 +0000 | [diff] [blame] | 1446 | |
| 1447 | // The number of incoming and outgoing values should match; unless the final |
| 1448 | // outgoing value is a flag. |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1449 | assert((Tmp3.getNode()->getNumValues() == Result.getNode()->getNumValues() || |
| 1450 | (Tmp3.getNode()->getNumValues() == Result.getNode()->getNumValues() + 1 && |
| 1451 | Tmp3.getNode()->getValueType(Tmp3.getNode()->getNumValues() - 1) == |
Bill Wendling | 22f8deb | 2007-11-13 00:44:25 +0000 | [diff] [blame] | 1452 | MVT::Flag)) && |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1453 | "Lowering call/formal_arguments produced unexpected # results!"); |
| 1454 | |
| 1455 | // Since CALL/FORMAL_ARGUMENTS nodes produce multiple values, make sure to |
| 1456 | // remember that we legalized all of them, so it doesn't get relegalized. |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1457 | for (unsigned i = 0, e = Tmp3.getNode()->getNumValues(); i != e; ++i) { |
| 1458 | if (Tmp3.getNode()->getValueType(i) == MVT::Flag) |
Bill Wendling | 22f8deb | 2007-11-13 00:44:25 +0000 | [diff] [blame] | 1459 | continue; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1460 | Tmp1 = LegalizeOp(Tmp3.getValue(i)); |
Gabor Greif | 46bf547 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 1461 | if (Op.getResNo() == i) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1462 | Tmp2 = Tmp1; |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1463 | AddLegalizedOperand(SDValue(Node, i), Tmp1); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1464 | } |
| 1465 | return Tmp2; |
Christopher Lamb | b768c2e | 2007-07-26 07:34:40 +0000 | [diff] [blame] | 1466 | case ISD::EXTRACT_SUBREG: { |
| 1467 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1468 | ConstantSDNode *idx = dyn_cast<ConstantSDNode>(Node->getOperand(1)); |
| 1469 | assert(idx && "Operand must be a constant"); |
Dan Gohman | faeb4a3 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1470 | Tmp2 = DAG.getTargetConstant(idx->getAPIntValue(), idx->getValueType(0)); |
Christopher Lamb | b768c2e | 2007-07-26 07:34:40 +0000 | [diff] [blame] | 1471 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 1472 | } |
| 1473 | break; |
| 1474 | case ISD::INSERT_SUBREG: { |
| 1475 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1476 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1477 | ConstantSDNode *idx = dyn_cast<ConstantSDNode>(Node->getOperand(2)); |
| 1478 | assert(idx && "Operand must be a constant"); |
Dan Gohman | faeb4a3 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1479 | Tmp3 = DAG.getTargetConstant(idx->getAPIntValue(), idx->getValueType(0)); |
Christopher Lamb | b768c2e | 2007-07-26 07:34:40 +0000 | [diff] [blame] | 1480 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
| 1481 | } |
| 1482 | break; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1483 | case ISD::BUILD_VECTOR: |
| 1484 | switch (TLI.getOperationAction(ISD::BUILD_VECTOR, Node->getValueType(0))) { |
| 1485 | default: assert(0 && "This action is not supported yet!"); |
| 1486 | case TargetLowering::Custom: |
| 1487 | Tmp3 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1488 | if (Tmp3.getNode()) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1489 | Result = Tmp3; |
| 1490 | break; |
| 1491 | } |
| 1492 | // FALLTHROUGH |
| 1493 | case TargetLowering::Expand: |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1494 | Result = ExpandBUILD_VECTOR(Result.getNode()); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1495 | break; |
| 1496 | } |
| 1497 | break; |
| 1498 | case ISD::INSERT_VECTOR_ELT: |
| 1499 | Tmp1 = LegalizeOp(Node->getOperand(0)); // InVec |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1500 | Tmp3 = LegalizeOp(Node->getOperand(2)); // InEltNo |
Nate Begeman | 6fb7ebd | 2008-02-13 06:43:04 +0000 | [diff] [blame] | 1501 | |
| 1502 | // The type of the value to insert may not be legal, even though the vector |
| 1503 | // type is legal. Legalize/Promote accordingly. We do not handle Expand |
| 1504 | // here. |
| 1505 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 1506 | default: assert(0 && "Cannot expand insert element operand"); |
| 1507 | case Legal: Tmp2 = LegalizeOp(Node->getOperand(1)); break; |
| 1508 | case Promote: Tmp2 = PromoteOp(Node->getOperand(1)); break; |
Mon P Wang | 1448aad | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 1509 | case Expand: |
| 1510 | // FIXME: An alternative would be to check to see if the target is not |
| 1511 | // going to custom lower this operation, we could bitcast to half elt |
| 1512 | // width and perform two inserts at that width, if that is legal. |
| 1513 | Tmp2 = Node->getOperand(1); |
| 1514 | break; |
Nate Begeman | 6fb7ebd | 2008-02-13 06:43:04 +0000 | [diff] [blame] | 1515 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1516 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
| 1517 | |
| 1518 | switch (TLI.getOperationAction(ISD::INSERT_VECTOR_ELT, |
| 1519 | Node->getValueType(0))) { |
| 1520 | default: assert(0 && "This action is not supported yet!"); |
| 1521 | case TargetLowering::Legal: |
| 1522 | break; |
| 1523 | case TargetLowering::Custom: |
Nate Begeman | 11f2e1d | 2008-01-05 20:47:37 +0000 | [diff] [blame] | 1524 | Tmp4 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1525 | if (Tmp4.getNode()) { |
Nate Begeman | 11f2e1d | 2008-01-05 20:47:37 +0000 | [diff] [blame] | 1526 | Result = Tmp4; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1527 | break; |
| 1528 | } |
| 1529 | // FALLTHROUGH |
Mon P Wang | 1448aad | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 1530 | case TargetLowering::Promote: |
| 1531 | // Fall thru for vector case |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1532 | case TargetLowering::Expand: { |
| 1533 | // If the insert index is a constant, codegen this as a scalar_to_vector, |
| 1534 | // then a shuffle that inserts it into the right position in the vector. |
| 1535 | if (ConstantSDNode *InsertPos = dyn_cast<ConstantSDNode>(Tmp3)) { |
Nate Begeman | 6fb7ebd | 2008-02-13 06:43:04 +0000 | [diff] [blame] | 1536 | // SCALAR_TO_VECTOR requires that the type of the value being inserted |
| 1537 | // match the element type of the vector being created. |
| 1538 | if (Tmp2.getValueType() == |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1539 | Op.getValueType().getVectorElementType()) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1540 | SDValue ScVec = DAG.getNode(ISD::SCALAR_TO_VECTOR, |
Nate Begeman | 6fb7ebd | 2008-02-13 06:43:04 +0000 | [diff] [blame] | 1541 | Tmp1.getValueType(), Tmp2); |
| 1542 | |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1543 | unsigned NumElts = Tmp1.getValueType().getVectorNumElements(); |
| 1544 | MVT ShufMaskVT = |
| 1545 | MVT::getIntVectorWithNumElements(NumElts); |
| 1546 | MVT ShufMaskEltVT = ShufMaskVT.getVectorElementType(); |
Nate Begeman | 6fb7ebd | 2008-02-13 06:43:04 +0000 | [diff] [blame] | 1547 | |
| 1548 | // We generate a shuffle of InVec and ScVec, so the shuffle mask |
| 1549 | // should be 0,1,2,3,4,5... with the appropriate element replaced with |
| 1550 | // elt 0 of the RHS. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1551 | SmallVector<SDValue, 8> ShufOps; |
Nate Begeman | 6fb7ebd | 2008-02-13 06:43:04 +0000 | [diff] [blame] | 1552 | for (unsigned i = 0; i != NumElts; ++i) { |
Dan Gohman | faeb4a3 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1553 | if (i != InsertPos->getZExtValue()) |
Nate Begeman | 6fb7ebd | 2008-02-13 06:43:04 +0000 | [diff] [blame] | 1554 | ShufOps.push_back(DAG.getConstant(i, ShufMaskEltVT)); |
| 1555 | else |
| 1556 | ShufOps.push_back(DAG.getConstant(NumElts, ShufMaskEltVT)); |
| 1557 | } |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1558 | SDValue ShufMask = DAG.getNode(ISD::BUILD_VECTOR, ShufMaskVT, |
Nate Begeman | 6fb7ebd | 2008-02-13 06:43:04 +0000 | [diff] [blame] | 1559 | &ShufOps[0], ShufOps.size()); |
| 1560 | |
| 1561 | Result = DAG.getNode(ISD::VECTOR_SHUFFLE, Tmp1.getValueType(), |
| 1562 | Tmp1, ScVec, ShufMask); |
| 1563 | Result = LegalizeOp(Result); |
| 1564 | break; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1565 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1566 | } |
Nate Begeman | 7c9e4b7 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 1567 | Result = PerformInsertVectorEltInMemory(Tmp1, Tmp2, Tmp3); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1568 | break; |
| 1569 | } |
| 1570 | } |
| 1571 | break; |
| 1572 | case ISD::SCALAR_TO_VECTOR: |
| 1573 | if (!TLI.isTypeLegal(Node->getOperand(0).getValueType())) { |
| 1574 | Result = LegalizeOp(ExpandSCALAR_TO_VECTOR(Node)); |
| 1575 | break; |
| 1576 | } |
| 1577 | |
| 1578 | Tmp1 = LegalizeOp(Node->getOperand(0)); // InVal |
| 1579 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 1580 | switch (TLI.getOperationAction(ISD::SCALAR_TO_VECTOR, |
| 1581 | Node->getValueType(0))) { |
| 1582 | default: assert(0 && "This action is not supported yet!"); |
| 1583 | case TargetLowering::Legal: |
| 1584 | break; |
| 1585 | case TargetLowering::Custom: |
| 1586 | Tmp3 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1587 | if (Tmp3.getNode()) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1588 | Result = Tmp3; |
| 1589 | break; |
| 1590 | } |
| 1591 | // FALLTHROUGH |
| 1592 | case TargetLowering::Expand: |
| 1593 | Result = LegalizeOp(ExpandSCALAR_TO_VECTOR(Node)); |
| 1594 | break; |
| 1595 | } |
| 1596 | break; |
| 1597 | case ISD::VECTOR_SHUFFLE: |
| 1598 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the input vectors, |
| 1599 | Tmp2 = LegalizeOp(Node->getOperand(1)); // but not the shuffle mask. |
| 1600 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
| 1601 | |
| 1602 | // Allow targets to custom lower the SHUFFLEs they support. |
| 1603 | switch (TLI.getOperationAction(ISD::VECTOR_SHUFFLE,Result.getValueType())) { |
| 1604 | default: assert(0 && "Unknown operation action!"); |
| 1605 | case TargetLowering::Legal: |
| 1606 | assert(isShuffleLegal(Result.getValueType(), Node->getOperand(2)) && |
| 1607 | "vector shuffle should not be created if not legal!"); |
| 1608 | break; |
| 1609 | case TargetLowering::Custom: |
| 1610 | Tmp3 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1611 | if (Tmp3.getNode()) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1612 | Result = Tmp3; |
| 1613 | break; |
| 1614 | } |
| 1615 | // FALLTHROUGH |
| 1616 | case TargetLowering::Expand: { |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1617 | MVT VT = Node->getValueType(0); |
| 1618 | MVT EltVT = VT.getVectorElementType(); |
| 1619 | MVT PtrVT = TLI.getPointerTy(); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1620 | SDValue Mask = Node->getOperand(2); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1621 | unsigned NumElems = Mask.getNumOperands(); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1622 | SmallVector<SDValue,8> Ops; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1623 | for (unsigned i = 0; i != NumElems; ++i) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1624 | SDValue Arg = Mask.getOperand(i); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1625 | if (Arg.getOpcode() == ISD::UNDEF) { |
| 1626 | Ops.push_back(DAG.getNode(ISD::UNDEF, EltVT)); |
| 1627 | } else { |
| 1628 | assert(isa<ConstantSDNode>(Arg) && "Invalid VECTOR_SHUFFLE mask!"); |
Dan Gohman | faeb4a3 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1629 | unsigned Idx = cast<ConstantSDNode>(Arg)->getZExtValue(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1630 | if (Idx < NumElems) |
| 1631 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, EltVT, Tmp1, |
| 1632 | DAG.getConstant(Idx, PtrVT))); |
| 1633 | else |
| 1634 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, EltVT, Tmp2, |
| 1635 | DAG.getConstant(Idx - NumElems, PtrVT))); |
| 1636 | } |
| 1637 | } |
| 1638 | Result = DAG.getNode(ISD::BUILD_VECTOR, VT, &Ops[0], Ops.size()); |
| 1639 | break; |
| 1640 | } |
| 1641 | case TargetLowering::Promote: { |
| 1642 | // Change base type to a different vector type. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1643 | MVT OVT = Node->getValueType(0); |
| 1644 | MVT NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1645 | |
| 1646 | // Cast the two input vectors. |
| 1647 | Tmp1 = DAG.getNode(ISD::BIT_CONVERT, NVT, Tmp1); |
| 1648 | Tmp2 = DAG.getNode(ISD::BIT_CONVERT, NVT, Tmp2); |
| 1649 | |
| 1650 | // Convert the shuffle mask to the right # elements. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1651 | Tmp3 = SDValue(isShuffleLegal(OVT, Node->getOperand(2)), 0); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1652 | assert(Tmp3.getNode() && "Shuffle not legal?"); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1653 | Result = DAG.getNode(ISD::VECTOR_SHUFFLE, NVT, Tmp1, Tmp2, Tmp3); |
| 1654 | Result = DAG.getNode(ISD::BIT_CONVERT, OVT, Result); |
| 1655 | break; |
| 1656 | } |
| 1657 | } |
| 1658 | break; |
| 1659 | |
| 1660 | case ISD::EXTRACT_VECTOR_ELT: |
| 1661 | Tmp1 = Node->getOperand(0); |
| 1662 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1663 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 1664 | Result = ExpandEXTRACT_VECTOR_ELT(Result); |
| 1665 | break; |
| 1666 | |
| 1667 | case ISD::EXTRACT_SUBVECTOR: |
| 1668 | Tmp1 = Node->getOperand(0); |
| 1669 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1670 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 1671 | Result = ExpandEXTRACT_SUBVECTOR(Result); |
| 1672 | break; |
| 1673 | |
Mon P Wang | 1448aad | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 1674 | case ISD::CONCAT_VECTORS: { |
| 1675 | // Use extract/insert/build vector for now. We might try to be |
| 1676 | // more clever later. |
| 1677 | MVT PtrVT = TLI.getPointerTy(); |
| 1678 | SmallVector<SDValue, 8> Ops; |
| 1679 | unsigned NumOperands = Node->getNumOperands(); |
| 1680 | for (unsigned i=0; i < NumOperands; ++i) { |
| 1681 | SDValue SubOp = Node->getOperand(i); |
| 1682 | MVT VVT = SubOp.getNode()->getValueType(0); |
| 1683 | MVT EltVT = VVT.getVectorElementType(); |
| 1684 | unsigned NumSubElem = VVT.getVectorNumElements(); |
| 1685 | for (unsigned j=0; j < NumSubElem; ++j) { |
| 1686 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, EltVT, SubOp, |
| 1687 | DAG.getConstant(j, PtrVT))); |
| 1688 | } |
| 1689 | } |
| 1690 | return LegalizeOp(DAG.getNode(ISD::BUILD_VECTOR, Node->getValueType(0), |
| 1691 | &Ops[0], Ops.size())); |
| 1692 | } |
| 1693 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1694 | case ISD::CALLSEQ_START: { |
| 1695 | SDNode *CallEnd = FindCallEndFromCallStart(Node); |
| 1696 | |
| 1697 | // Recursively Legalize all of the inputs of the call end that do not lead |
| 1698 | // to this call start. This ensures that any libcalls that need be inserted |
| 1699 | // are inserted *before* the CALLSEQ_START. |
| 1700 | {SmallPtrSet<SDNode*, 32> NodesLeadingTo; |
| 1701 | for (unsigned i = 0, e = CallEnd->getNumOperands(); i != e; ++i) |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1702 | LegalizeAllNodesNotLeadingTo(CallEnd->getOperand(i).getNode(), Node, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1703 | NodesLeadingTo); |
| 1704 | } |
| 1705 | |
| 1706 | // Now that we legalized all of the inputs (which may have inserted |
| 1707 | // libcalls) create the new CALLSEQ_START node. |
| 1708 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1709 | |
| 1710 | // Merge in the last call, to ensure that this call start after the last |
| 1711 | // call ended. |
| 1712 | if (LastCALLSEQ_END.getOpcode() != ISD::EntryToken) { |
| 1713 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1714 | Tmp1 = LegalizeOp(Tmp1); |
| 1715 | } |
| 1716 | |
| 1717 | // Do not try to legalize the target-specific arguments (#1+). |
| 1718 | if (Tmp1 != Node->getOperand(0)) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1719 | SmallVector<SDValue, 8> Ops(Node->op_begin(), Node->op_end()); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1720 | Ops[0] = Tmp1; |
| 1721 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
| 1722 | } |
| 1723 | |
| 1724 | // Remember that the CALLSEQ_START is legalized. |
| 1725 | AddLegalizedOperand(Op.getValue(0), Result); |
| 1726 | if (Node->getNumValues() == 2) // If this has a flag result, remember it. |
| 1727 | AddLegalizedOperand(Op.getValue(1), Result.getValue(1)); |
| 1728 | |
| 1729 | // Now that the callseq_start and all of the non-call nodes above this call |
| 1730 | // sequence have been legalized, legalize the call itself. During this |
| 1731 | // process, no libcalls can/will be inserted, guaranteeing that no calls |
| 1732 | // can overlap. |
| 1733 | assert(!IsLegalizingCall && "Inconsistent sequentialization of calls!"); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1734 | // Note that we are selecting this call! |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1735 | LastCALLSEQ_END = SDValue(CallEnd, 0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1736 | IsLegalizingCall = true; |
| 1737 | |
| 1738 | // Legalize the call, starting from the CALLSEQ_END. |
| 1739 | LegalizeOp(LastCALLSEQ_END); |
| 1740 | assert(!IsLegalizingCall && "CALLSEQ_END should have cleared this!"); |
| 1741 | return Result; |
| 1742 | } |
| 1743 | case ISD::CALLSEQ_END: |
| 1744 | // If the CALLSEQ_START node hasn't been legalized first, legalize it. This |
| 1745 | // will cause this node to be legalized as well as handling libcalls right. |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1746 | if (LastCALLSEQ_END.getNode() != Node) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1747 | LegalizeOp(SDValue(FindCallStartFromCallEnd(Node), 0)); |
| 1748 | DenseMap<SDValue, SDValue>::iterator I = LegalizedNodes.find(Op); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1749 | assert(I != LegalizedNodes.end() && |
| 1750 | "Legalizing the call start should have legalized this node!"); |
| 1751 | return I->second; |
| 1752 | } |
| 1753 | |
| 1754 | // Otherwise, the call start has been legalized and everything is going |
| 1755 | // according to plan. Just legalize ourselves normally here. |
| 1756 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1757 | // Do not try to legalize the target-specific arguments (#1+), except for |
| 1758 | // an optional flag input. |
| 1759 | if (Node->getOperand(Node->getNumOperands()-1).getValueType() != MVT::Flag){ |
| 1760 | if (Tmp1 != Node->getOperand(0)) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1761 | SmallVector<SDValue, 8> Ops(Node->op_begin(), Node->op_end()); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1762 | Ops[0] = Tmp1; |
| 1763 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
| 1764 | } |
| 1765 | } else { |
| 1766 | Tmp2 = LegalizeOp(Node->getOperand(Node->getNumOperands()-1)); |
| 1767 | if (Tmp1 != Node->getOperand(0) || |
| 1768 | Tmp2 != Node->getOperand(Node->getNumOperands()-1)) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1769 | SmallVector<SDValue, 8> Ops(Node->op_begin(), Node->op_end()); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1770 | Ops[0] = Tmp1; |
| 1771 | Ops.back() = Tmp2; |
| 1772 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
| 1773 | } |
| 1774 | } |
| 1775 | assert(IsLegalizingCall && "Call sequence imbalance between start/end?"); |
| 1776 | // This finishes up call legalization. |
| 1777 | IsLegalizingCall = false; |
| 1778 | |
| 1779 | // If the CALLSEQ_END node has a flag, remember that we legalized it. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1780 | AddLegalizedOperand(SDValue(Node, 0), Result.getValue(0)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1781 | if (Node->getNumValues() == 2) |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1782 | AddLegalizedOperand(SDValue(Node, 1), Result.getValue(1)); |
Gabor Greif | 46bf547 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 1783 | return Result.getValue(Op.getResNo()); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1784 | case ISD::DYNAMIC_STACKALLOC: { |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1785 | MVT VT = Node->getValueType(0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1786 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1787 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the size. |
| 1788 | Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the alignment. |
| 1789 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
| 1790 | |
| 1791 | Tmp1 = Result.getValue(0); |
| 1792 | Tmp2 = Result.getValue(1); |
Evan Cheng | a448bc4 | 2007-08-16 23:50:06 +0000 | [diff] [blame] | 1793 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1794 | default: assert(0 && "This action is not supported yet!"); |
| 1795 | case TargetLowering::Expand: { |
| 1796 | unsigned SPReg = TLI.getStackPointerRegisterToSaveRestore(); |
| 1797 | assert(SPReg && "Target cannot require DYNAMIC_STACKALLOC expansion and" |
| 1798 | " not tell us which reg is the stack pointer!"); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1799 | SDValue Chain = Tmp1.getOperand(0); |
Bill Wendling | 22f8deb | 2007-11-13 00:44:25 +0000 | [diff] [blame] | 1800 | |
| 1801 | // Chain the dynamic stack allocation so that it doesn't modify the stack |
| 1802 | // pointer when other instructions are using the stack. |
Chris Lattner | fe5d402 | 2008-10-11 22:08:30 +0000 | [diff] [blame] | 1803 | Chain = DAG.getCALLSEQ_START(Chain, DAG.getIntPtrConstant(0, true)); |
Bill Wendling | 22f8deb | 2007-11-13 00:44:25 +0000 | [diff] [blame] | 1804 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1805 | SDValue Size = Tmp2.getOperand(1); |
| 1806 | SDValue SP = DAG.getCopyFromReg(Chain, SPReg, VT); |
Evan Cheng | a448bc4 | 2007-08-16 23:50:06 +0000 | [diff] [blame] | 1807 | Chain = SP.getValue(1); |
Dan Gohman | faeb4a3 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1808 | unsigned Align = cast<ConstantSDNode>(Tmp3)->getZExtValue(); |
Evan Cheng | a448bc4 | 2007-08-16 23:50:06 +0000 | [diff] [blame] | 1809 | unsigned StackAlign = |
| 1810 | TLI.getTargetMachine().getFrameInfo()->getStackAlignment(); |
| 1811 | if (Align > StackAlign) |
Evan Cheng | 51ce038 | 2007-08-17 18:02:22 +0000 | [diff] [blame] | 1812 | SP = DAG.getNode(ISD::AND, VT, SP, |
| 1813 | DAG.getConstant(-(uint64_t)Align, VT)); |
Evan Cheng | a448bc4 | 2007-08-16 23:50:06 +0000 | [diff] [blame] | 1814 | Tmp1 = DAG.getNode(ISD::SUB, VT, SP, Size); // Value |
Bill Wendling | 22f8deb | 2007-11-13 00:44:25 +0000 | [diff] [blame] | 1815 | Chain = DAG.getCopyToReg(Chain, SPReg, Tmp1); // Output chain |
| 1816 | |
Chris Lattner | fe5d402 | 2008-10-11 22:08:30 +0000 | [diff] [blame] | 1817 | Tmp2 = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(0, true), |
| 1818 | DAG.getIntPtrConstant(0, true), SDValue()); |
Bill Wendling | 22f8deb | 2007-11-13 00:44:25 +0000 | [diff] [blame] | 1819 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1820 | Tmp1 = LegalizeOp(Tmp1); |
| 1821 | Tmp2 = LegalizeOp(Tmp2); |
| 1822 | break; |
| 1823 | } |
| 1824 | case TargetLowering::Custom: |
| 1825 | Tmp3 = TLI.LowerOperation(Tmp1, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1826 | if (Tmp3.getNode()) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1827 | Tmp1 = LegalizeOp(Tmp3); |
| 1828 | Tmp2 = LegalizeOp(Tmp3.getValue(1)); |
| 1829 | } |
| 1830 | break; |
| 1831 | case TargetLowering::Legal: |
| 1832 | break; |
| 1833 | } |
| 1834 | // Since this op produce two values, make sure to remember that we |
| 1835 | // legalized both of them. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1836 | AddLegalizedOperand(SDValue(Node, 0), Tmp1); |
| 1837 | AddLegalizedOperand(SDValue(Node, 1), Tmp2); |
Gabor Greif | 46bf547 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 1838 | return Op.getResNo() ? Tmp2 : Tmp1; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1839 | } |
| 1840 | case ISD::INLINEASM: { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1841 | SmallVector<SDValue, 8> Ops(Node->op_begin(), Node->op_end()); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1842 | bool Changed = false; |
| 1843 | // Legalize all of the operands of the inline asm, in case they are nodes |
| 1844 | // that need to be expanded or something. Note we skip the asm string and |
| 1845 | // all of the TargetConstant flags. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1846 | SDValue Op = LegalizeOp(Ops[0]); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1847 | Changed = Op != Ops[0]; |
| 1848 | Ops[0] = Op; |
| 1849 | |
| 1850 | bool HasInFlag = Ops.back().getValueType() == MVT::Flag; |
| 1851 | for (unsigned i = 2, e = Ops.size()-HasInFlag; i < e; ) { |
Dan Gohman | faeb4a3 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1852 | unsigned NumVals = cast<ConstantSDNode>(Ops[i])->getZExtValue() >> 3; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1853 | for (++i; NumVals; ++i, --NumVals) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1854 | SDValue Op = LegalizeOp(Ops[i]); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1855 | if (Op != Ops[i]) { |
| 1856 | Changed = true; |
| 1857 | Ops[i] = Op; |
| 1858 | } |
| 1859 | } |
| 1860 | } |
| 1861 | |
| 1862 | if (HasInFlag) { |
| 1863 | Op = LegalizeOp(Ops.back()); |
| 1864 | Changed |= Op != Ops.back(); |
| 1865 | Ops.back() = Op; |
| 1866 | } |
| 1867 | |
| 1868 | if (Changed) |
| 1869 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
| 1870 | |
| 1871 | // INLINE asm returns a chain and flag, make sure to add both to the map. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1872 | AddLegalizedOperand(SDValue(Node, 0), Result.getValue(0)); |
| 1873 | AddLegalizedOperand(SDValue(Node, 1), Result.getValue(1)); |
Gabor Greif | 46bf547 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 1874 | return Result.getValue(Op.getResNo()); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1875 | } |
| 1876 | case ISD::BR: |
| 1877 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1878 | // Ensure that libcalls are emitted before a branch. |
| 1879 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1880 | Tmp1 = LegalizeOp(Tmp1); |
| 1881 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 1882 | |
| 1883 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
| 1884 | break; |
| 1885 | case ISD::BRIND: |
| 1886 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1887 | // Ensure that libcalls are emitted before a branch. |
| 1888 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1889 | Tmp1 = LegalizeOp(Tmp1); |
| 1890 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 1891 | |
| 1892 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 1893 | default: assert(0 && "Indirect target must be legal type (pointer)!"); |
| 1894 | case Legal: |
| 1895 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the condition. |
| 1896 | break; |
| 1897 | } |
| 1898 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 1899 | break; |
| 1900 | case ISD::BR_JT: |
| 1901 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1902 | // Ensure that libcalls are emitted before a branch. |
| 1903 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1904 | Tmp1 = LegalizeOp(Tmp1); |
| 1905 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 1906 | |
| 1907 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the jumptable node. |
| 1908 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
| 1909 | |
| 1910 | switch (TLI.getOperationAction(ISD::BR_JT, MVT::Other)) { |
| 1911 | default: assert(0 && "This action is not supported yet!"); |
| 1912 | case TargetLowering::Legal: break; |
| 1913 | case TargetLowering::Custom: |
| 1914 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1915 | if (Tmp1.getNode()) Result = Tmp1; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1916 | break; |
| 1917 | case TargetLowering::Expand: { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1918 | SDValue Chain = Result.getOperand(0); |
| 1919 | SDValue Table = Result.getOperand(1); |
| 1920 | SDValue Index = Result.getOperand(2); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1921 | |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1922 | MVT PTy = TLI.getPointerTy(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1923 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1924 | unsigned EntrySize = MF.getJumpTableInfo()->getEntrySize(); |
| 1925 | Index= DAG.getNode(ISD::MUL, PTy, Index, DAG.getConstant(EntrySize, PTy)); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1926 | SDValue Addr = DAG.getNode(ISD::ADD, PTy, Index, Table); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1927 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1928 | SDValue LD; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1929 | switch (EntrySize) { |
| 1930 | default: assert(0 && "Size of jump table not supported yet."); break; |
Dan Gohman | 12a9c08 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 1931 | case 4: LD = DAG.getLoad(MVT::i32, Chain, Addr, |
Dan Gohman | fb020b6 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 1932 | PseudoSourceValue::getJumpTable(), 0); break; |
Dan Gohman | 12a9c08 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 1933 | case 8: LD = DAG.getLoad(MVT::i64, Chain, Addr, |
Dan Gohman | fb020b6 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 1934 | PseudoSourceValue::getJumpTable(), 0); break; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1935 | } |
| 1936 | |
Evan Cheng | 6fb0676 | 2007-11-09 01:32:10 +0000 | [diff] [blame] | 1937 | Addr = LD; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1938 | if (TLI.getTargetMachine().getRelocationModel() == Reloc::PIC_) { |
| 1939 | // For PIC, the sequence is: |
| 1940 | // BRIND(load(Jumptable + index) + RelocBase) |
Evan Cheng | 6fb0676 | 2007-11-09 01:32:10 +0000 | [diff] [blame] | 1941 | // RelocBase can be JumpTable, GOT or some sort of global base. |
| 1942 | if (PTy != MVT::i32) |
| 1943 | Addr = DAG.getNode(ISD::SIGN_EXTEND, PTy, Addr); |
| 1944 | Addr = DAG.getNode(ISD::ADD, PTy, Addr, |
| 1945 | TLI.getPICJumpTableRelocBase(Table, DAG)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1946 | } |
Evan Cheng | 6fb0676 | 2007-11-09 01:32:10 +0000 | [diff] [blame] | 1947 | Result = DAG.getNode(ISD::BRIND, MVT::Other, LD.getValue(1), Addr); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1948 | } |
| 1949 | } |
| 1950 | break; |
| 1951 | case ISD::BRCOND: |
| 1952 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1953 | // Ensure that libcalls are emitted before a return. |
| 1954 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1955 | Tmp1 = LegalizeOp(Tmp1); |
| 1956 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 1957 | |
| 1958 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 1959 | case Expand: assert(0 && "It's impossible to expand bools"); |
| 1960 | case Legal: |
| 1961 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the condition. |
| 1962 | break; |
Dan Gohman | 07961cd | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 1963 | case Promote: { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1964 | Tmp2 = PromoteOp(Node->getOperand(1)); // Promote the condition. |
| 1965 | |
| 1966 | // The top bits of the promoted condition are not necessarily zero, ensure |
| 1967 | // that the value is properly zero extended. |
Dan Gohman | 07961cd | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 1968 | unsigned BitWidth = Tmp2.getValueSizeInBits(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1969 | if (!DAG.MaskedValueIsZero(Tmp2, |
Dan Gohman | 07961cd | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 1970 | APInt::getHighBitsSet(BitWidth, BitWidth-1))) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1971 | Tmp2 = DAG.getZeroExtendInReg(Tmp2, MVT::i1); |
| 1972 | break; |
| 1973 | } |
Dan Gohman | 07961cd | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 1974 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1975 | |
| 1976 | // Basic block destination (Op#2) is always legal. |
| 1977 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
| 1978 | |
| 1979 | switch (TLI.getOperationAction(ISD::BRCOND, MVT::Other)) { |
| 1980 | default: assert(0 && "This action is not supported yet!"); |
| 1981 | case TargetLowering::Legal: break; |
| 1982 | case TargetLowering::Custom: |
| 1983 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1984 | if (Tmp1.getNode()) Result = Tmp1; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1985 | break; |
| 1986 | case TargetLowering::Expand: |
| 1987 | // Expand brcond's setcc into its constituent parts and create a BR_CC |
| 1988 | // Node. |
| 1989 | if (Tmp2.getOpcode() == ISD::SETCC) { |
| 1990 | Result = DAG.getNode(ISD::BR_CC, MVT::Other, Tmp1, Tmp2.getOperand(2), |
| 1991 | Tmp2.getOperand(0), Tmp2.getOperand(1), |
| 1992 | Node->getOperand(2)); |
| 1993 | } else { |
| 1994 | Result = DAG.getNode(ISD::BR_CC, MVT::Other, Tmp1, |
| 1995 | DAG.getCondCode(ISD::SETNE), Tmp2, |
| 1996 | DAG.getConstant(0, Tmp2.getValueType()), |
| 1997 | Node->getOperand(2)); |
| 1998 | } |
| 1999 | break; |
| 2000 | } |
| 2001 | break; |
| 2002 | case ISD::BR_CC: |
| 2003 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 2004 | // Ensure that libcalls are emitted before a branch. |
| 2005 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 2006 | Tmp1 = LegalizeOp(Tmp1); |
| 2007 | Tmp2 = Node->getOperand(2); // LHS |
| 2008 | Tmp3 = Node->getOperand(3); // RHS |
| 2009 | Tmp4 = Node->getOperand(1); // CC |
| 2010 | |
Dale Johannesen | 32100b2 | 2008-11-07 22:54:33 +0000 | [diff] [blame] | 2011 | LegalizeSetCC(TLI.getSetCCResultType(Tmp2), Tmp2, Tmp3, Tmp4); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2012 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 2013 | |
Evan Cheng | 7134382 | 2008-10-15 02:05:31 +0000 | [diff] [blame] | 2014 | // If we didn't get both a LHS and RHS back from LegalizeSetCC, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2015 | // the LHS is a legal SETCC itself. In this case, we need to compare |
| 2016 | // the result against zero to select between true and false values. |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2017 | if (Tmp3.getNode() == 0) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2018 | Tmp3 = DAG.getConstant(0, Tmp2.getValueType()); |
| 2019 | Tmp4 = DAG.getCondCode(ISD::SETNE); |
| 2020 | } |
| 2021 | |
| 2022 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp4, Tmp2, Tmp3, |
| 2023 | Node->getOperand(4)); |
| 2024 | |
| 2025 | switch (TLI.getOperationAction(ISD::BR_CC, Tmp3.getValueType())) { |
| 2026 | default: assert(0 && "Unexpected action for BR_CC!"); |
| 2027 | case TargetLowering::Legal: break; |
| 2028 | case TargetLowering::Custom: |
| 2029 | Tmp4 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2030 | if (Tmp4.getNode()) Result = Tmp4; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2031 | break; |
| 2032 | } |
| 2033 | break; |
| 2034 | case ISD::LOAD: { |
| 2035 | LoadSDNode *LD = cast<LoadSDNode>(Node); |
| 2036 | Tmp1 = LegalizeOp(LD->getChain()); // Legalize the chain. |
| 2037 | Tmp2 = LegalizeOp(LD->getBasePtr()); // Legalize the base pointer. |
| 2038 | |
| 2039 | ISD::LoadExtType ExtType = LD->getExtensionType(); |
| 2040 | if (ExtType == ISD::NON_EXTLOAD) { |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2041 | MVT VT = Node->getValueType(0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2042 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, LD->getOffset()); |
| 2043 | Tmp3 = Result.getValue(0); |
| 2044 | Tmp4 = Result.getValue(1); |
| 2045 | |
| 2046 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 2047 | default: assert(0 && "This action is not supported yet!"); |
Lauro Ramos Venancio | 578434f | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2048 | case TargetLowering::Legal: |
| 2049 | // If this is an unaligned load and the target doesn't support it, |
| 2050 | // expand it. |
| 2051 | if (!TLI.allowsUnalignedMemoryAccesses()) { |
| 2052 | unsigned ABIAlignment = TLI.getTargetData()-> |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2053 | getABITypeAlignment(LD->getMemoryVT().getTypeForMVT()); |
Lauro Ramos Venancio | 578434f | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2054 | if (LD->getAlignment() < ABIAlignment){ |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2055 | Result = ExpandUnalignedLoad(cast<LoadSDNode>(Result.getNode()), DAG, |
Lauro Ramos Venancio | 578434f | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2056 | TLI); |
| 2057 | Tmp3 = Result.getOperand(0); |
| 2058 | Tmp4 = Result.getOperand(1); |
Dale Johannesen | 0827538 | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 2059 | Tmp3 = LegalizeOp(Tmp3); |
| 2060 | Tmp4 = LegalizeOp(Tmp4); |
Lauro Ramos Venancio | 578434f | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2061 | } |
| 2062 | } |
| 2063 | break; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2064 | case TargetLowering::Custom: |
| 2065 | Tmp1 = TLI.LowerOperation(Tmp3, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2066 | if (Tmp1.getNode()) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2067 | Tmp3 = LegalizeOp(Tmp1); |
| 2068 | Tmp4 = LegalizeOp(Tmp1.getValue(1)); |
| 2069 | } |
| 2070 | break; |
| 2071 | case TargetLowering::Promote: { |
| 2072 | // Only promote a load of vector type to another. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2073 | assert(VT.isVector() && "Cannot promote this load!"); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2074 | // Change base type to a different vector type. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2075 | MVT NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), VT); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2076 | |
| 2077 | Tmp1 = DAG.getLoad(NVT, Tmp1, Tmp2, LD->getSrcValue(), |
| 2078 | LD->getSrcValueOffset(), |
| 2079 | LD->isVolatile(), LD->getAlignment()); |
| 2080 | Tmp3 = LegalizeOp(DAG.getNode(ISD::BIT_CONVERT, VT, Tmp1)); |
| 2081 | Tmp4 = LegalizeOp(Tmp1.getValue(1)); |
| 2082 | break; |
| 2083 | } |
| 2084 | } |
| 2085 | // Since loads produce two values, make sure to remember that we |
| 2086 | // legalized both of them. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2087 | AddLegalizedOperand(SDValue(Node, 0), Tmp3); |
| 2088 | AddLegalizedOperand(SDValue(Node, 1), Tmp4); |
Gabor Greif | 46bf547 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 2089 | return Op.getResNo() ? Tmp4 : Tmp3; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2090 | } else { |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2091 | MVT SrcVT = LD->getMemoryVT(); |
| 2092 | unsigned SrcWidth = SrcVT.getSizeInBits(); |
Duncan Sands | 082524c | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2093 | int SVOffset = LD->getSrcValueOffset(); |
| 2094 | unsigned Alignment = LD->getAlignment(); |
| 2095 | bool isVolatile = LD->isVolatile(); |
| 2096 | |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2097 | if (SrcWidth != SrcVT.getStoreSizeInBits() && |
Duncan Sands | 082524c | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2098 | // Some targets pretend to have an i1 loading operation, and actually |
| 2099 | // load an i8. This trick is correct for ZEXTLOAD because the top 7 |
| 2100 | // bits are guaranteed to be zero; it helps the optimizers understand |
| 2101 | // that these bits are zero. It is also useful for EXTLOAD, since it |
| 2102 | // tells the optimizers that those bits are undefined. It would be |
| 2103 | // nice to have an effective generic way of getting these benefits... |
| 2104 | // Until such a way is found, don't insist on promoting i1 here. |
| 2105 | (SrcVT != MVT::i1 || |
Evan Cheng | 08c171a | 2008-10-14 21:26:46 +0000 | [diff] [blame] | 2106 | TLI.getLoadExtAction(ExtType, MVT::i1) == TargetLowering::Promote)) { |
Duncan Sands | 082524c | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2107 | // Promote to a byte-sized load if not loading an integral number of |
| 2108 | // bytes. For example, promote EXTLOAD:i20 -> EXTLOAD:i24. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2109 | unsigned NewWidth = SrcVT.getStoreSizeInBits(); |
| 2110 | MVT NVT = MVT::getIntegerVT(NewWidth); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2111 | SDValue Ch; |
Duncan Sands | 082524c | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2112 | |
| 2113 | // The extra bits are guaranteed to be zero, since we stored them that |
| 2114 | // way. A zext load from NVT thus automatically gives zext from SrcVT. |
| 2115 | |
| 2116 | ISD::LoadExtType NewExtType = |
| 2117 | ExtType == ISD::ZEXTLOAD ? ISD::ZEXTLOAD : ISD::EXTLOAD; |
| 2118 | |
| 2119 | Result = DAG.getExtLoad(NewExtType, Node->getValueType(0), |
| 2120 | Tmp1, Tmp2, LD->getSrcValue(), SVOffset, |
| 2121 | NVT, isVolatile, Alignment); |
| 2122 | |
| 2123 | Ch = Result.getValue(1); // The chain. |
| 2124 | |
| 2125 | if (ExtType == ISD::SEXTLOAD) |
| 2126 | // Having the top bits zero doesn't help when sign extending. |
| 2127 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(), |
| 2128 | Result, DAG.getValueType(SrcVT)); |
| 2129 | else if (ExtType == ISD::ZEXTLOAD || NVT == Result.getValueType()) |
| 2130 | // All the top bits are guaranteed to be zero - inform the optimizers. |
| 2131 | Result = DAG.getNode(ISD::AssertZext, Result.getValueType(), Result, |
| 2132 | DAG.getValueType(SrcVT)); |
| 2133 | |
| 2134 | Tmp1 = LegalizeOp(Result); |
| 2135 | Tmp2 = LegalizeOp(Ch); |
| 2136 | } else if (SrcWidth & (SrcWidth - 1)) { |
| 2137 | // If not loading a power-of-2 number of bits, expand as two loads. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2138 | assert(SrcVT.isExtended() && !SrcVT.isVector() && |
Duncan Sands | 082524c | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2139 | "Unsupported extload!"); |
| 2140 | unsigned RoundWidth = 1 << Log2_32(SrcWidth); |
| 2141 | assert(RoundWidth < SrcWidth); |
| 2142 | unsigned ExtraWidth = SrcWidth - RoundWidth; |
| 2143 | assert(ExtraWidth < RoundWidth); |
| 2144 | assert(!(RoundWidth % 8) && !(ExtraWidth % 8) && |
| 2145 | "Load size not an integral number of bytes!"); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2146 | MVT RoundVT = MVT::getIntegerVT(RoundWidth); |
| 2147 | MVT ExtraVT = MVT::getIntegerVT(ExtraWidth); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2148 | SDValue Lo, Hi, Ch; |
Duncan Sands | 082524c | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2149 | unsigned IncrementSize; |
| 2150 | |
| 2151 | if (TLI.isLittleEndian()) { |
| 2152 | // EXTLOAD:i24 -> ZEXTLOAD:i16 | (shl EXTLOAD@+2:i8, 16) |
| 2153 | // Load the bottom RoundWidth bits. |
| 2154 | Lo = DAG.getExtLoad(ISD::ZEXTLOAD, Node->getValueType(0), Tmp1, Tmp2, |
| 2155 | LD->getSrcValue(), SVOffset, RoundVT, isVolatile, |
| 2156 | Alignment); |
| 2157 | |
| 2158 | // Load the remaining ExtraWidth bits. |
| 2159 | IncrementSize = RoundWidth / 8; |
| 2160 | Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2, |
| 2161 | DAG.getIntPtrConstant(IncrementSize)); |
| 2162 | Hi = DAG.getExtLoad(ExtType, Node->getValueType(0), Tmp1, Tmp2, |
| 2163 | LD->getSrcValue(), SVOffset + IncrementSize, |
| 2164 | ExtraVT, isVolatile, |
| 2165 | MinAlign(Alignment, IncrementSize)); |
| 2166 | |
| 2167 | // Build a factor node to remember that this load is independent of the |
| 2168 | // other one. |
| 2169 | Ch = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1), |
| 2170 | Hi.getValue(1)); |
| 2171 | |
| 2172 | // Move the top bits to the right place. |
| 2173 | Hi = DAG.getNode(ISD::SHL, Hi.getValueType(), Hi, |
| 2174 | DAG.getConstant(RoundWidth, TLI.getShiftAmountTy())); |
| 2175 | |
| 2176 | // Join the hi and lo parts. |
| 2177 | Result = DAG.getNode(ISD::OR, Node->getValueType(0), Lo, Hi); |
Lauro Ramos Venancio | 578434f | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2178 | } else { |
Duncan Sands | 082524c | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2179 | // Big endian - avoid unaligned loads. |
| 2180 | // EXTLOAD:i24 -> (shl EXTLOAD:i16, 8) | ZEXTLOAD@+2:i8 |
| 2181 | // Load the top RoundWidth bits. |
| 2182 | Hi = DAG.getExtLoad(ExtType, Node->getValueType(0), Tmp1, Tmp2, |
| 2183 | LD->getSrcValue(), SVOffset, RoundVT, isVolatile, |
| 2184 | Alignment); |
| 2185 | |
| 2186 | // Load the remaining ExtraWidth bits. |
| 2187 | IncrementSize = RoundWidth / 8; |
| 2188 | Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2, |
| 2189 | DAG.getIntPtrConstant(IncrementSize)); |
| 2190 | Lo = DAG.getExtLoad(ISD::ZEXTLOAD, Node->getValueType(0), Tmp1, Tmp2, |
| 2191 | LD->getSrcValue(), SVOffset + IncrementSize, |
| 2192 | ExtraVT, isVolatile, |
| 2193 | MinAlign(Alignment, IncrementSize)); |
| 2194 | |
| 2195 | // Build a factor node to remember that this load is independent of the |
| 2196 | // other one. |
| 2197 | Ch = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1), |
| 2198 | Hi.getValue(1)); |
| 2199 | |
| 2200 | // Move the top bits to the right place. |
| 2201 | Hi = DAG.getNode(ISD::SHL, Hi.getValueType(), Hi, |
| 2202 | DAG.getConstant(ExtraWidth, TLI.getShiftAmountTy())); |
| 2203 | |
| 2204 | // Join the hi and lo parts. |
| 2205 | Result = DAG.getNode(ISD::OR, Node->getValueType(0), Lo, Hi); |
| 2206 | } |
| 2207 | |
| 2208 | Tmp1 = LegalizeOp(Result); |
| 2209 | Tmp2 = LegalizeOp(Ch); |
| 2210 | } else { |
Evan Cheng | 08c171a | 2008-10-14 21:26:46 +0000 | [diff] [blame] | 2211 | switch (TLI.getLoadExtAction(ExtType, SrcVT)) { |
Duncan Sands | 082524c | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2212 | default: assert(0 && "This action is not supported yet!"); |
| 2213 | case TargetLowering::Custom: |
| 2214 | isCustom = true; |
| 2215 | // FALLTHROUGH |
| 2216 | case TargetLowering::Legal: |
| 2217 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, LD->getOffset()); |
| 2218 | Tmp1 = Result.getValue(0); |
| 2219 | Tmp2 = Result.getValue(1); |
| 2220 | |
| 2221 | if (isCustom) { |
| 2222 | Tmp3 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2223 | if (Tmp3.getNode()) { |
Duncan Sands | 082524c | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2224 | Tmp1 = LegalizeOp(Tmp3); |
| 2225 | Tmp2 = LegalizeOp(Tmp3.getValue(1)); |
| 2226 | } |
| 2227 | } else { |
| 2228 | // If this is an unaligned load and the target doesn't support it, |
| 2229 | // expand it. |
| 2230 | if (!TLI.allowsUnalignedMemoryAccesses()) { |
| 2231 | unsigned ABIAlignment = TLI.getTargetData()-> |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2232 | getABITypeAlignment(LD->getMemoryVT().getTypeForMVT()); |
Duncan Sands | 082524c | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2233 | if (LD->getAlignment() < ABIAlignment){ |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2234 | Result = ExpandUnalignedLoad(cast<LoadSDNode>(Result.getNode()), DAG, |
Duncan Sands | 082524c | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2235 | TLI); |
| 2236 | Tmp1 = Result.getOperand(0); |
| 2237 | Tmp2 = Result.getOperand(1); |
| 2238 | Tmp1 = LegalizeOp(Tmp1); |
| 2239 | Tmp2 = LegalizeOp(Tmp2); |
| 2240 | } |
Lauro Ramos Venancio | 578434f | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2241 | } |
| 2242 | } |
Duncan Sands | 082524c | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2243 | break; |
| 2244 | case TargetLowering::Expand: |
| 2245 | // f64 = EXTLOAD f32 should expand to LOAD, FP_EXTEND |
| 2246 | if (SrcVT == MVT::f32 && Node->getValueType(0) == MVT::f64) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2247 | SDValue Load = DAG.getLoad(SrcVT, Tmp1, Tmp2, LD->getSrcValue(), |
Duncan Sands | 082524c | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2248 | LD->getSrcValueOffset(), |
| 2249 | LD->isVolatile(), LD->getAlignment()); |
| 2250 | Result = DAG.getNode(ISD::FP_EXTEND, Node->getValueType(0), Load); |
| 2251 | Tmp1 = LegalizeOp(Result); // Relegalize new nodes. |
| 2252 | Tmp2 = LegalizeOp(Load.getValue(1)); |
| 2253 | break; |
| 2254 | } |
| 2255 | assert(ExtType != ISD::EXTLOAD &&"EXTLOAD should always be supported!"); |
| 2256 | // Turn the unsupported load into an EXTLOAD followed by an explicit |
| 2257 | // zero/sign extend inreg. |
| 2258 | Result = DAG.getExtLoad(ISD::EXTLOAD, Node->getValueType(0), |
| 2259 | Tmp1, Tmp2, LD->getSrcValue(), |
| 2260 | LD->getSrcValueOffset(), SrcVT, |
| 2261 | LD->isVolatile(), LD->getAlignment()); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2262 | SDValue ValRes; |
Duncan Sands | 082524c | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2263 | if (ExtType == ISD::SEXTLOAD) |
| 2264 | ValRes = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(), |
| 2265 | Result, DAG.getValueType(SrcVT)); |
| 2266 | else |
| 2267 | ValRes = DAG.getZeroExtendInReg(Result, SrcVT); |
| 2268 | Tmp1 = LegalizeOp(ValRes); // Relegalize new nodes. |
| 2269 | Tmp2 = LegalizeOp(Result.getValue(1)); // Relegalize new nodes. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2270 | break; |
| 2271 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2272 | } |
Duncan Sands | 082524c | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2273 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2274 | // Since loads produce two values, make sure to remember that we legalized |
| 2275 | // both of them. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2276 | AddLegalizedOperand(SDValue(Node, 0), Tmp1); |
| 2277 | AddLegalizedOperand(SDValue(Node, 1), Tmp2); |
Gabor Greif | 46bf547 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 2278 | return Op.getResNo() ? Tmp2 : Tmp1; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2279 | } |
| 2280 | } |
| 2281 | case ISD::EXTRACT_ELEMENT: { |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2282 | MVT OpTy = Node->getOperand(0).getValueType(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2283 | switch (getTypeAction(OpTy)) { |
| 2284 | default: assert(0 && "EXTRACT_ELEMENT action for type unimplemented!"); |
| 2285 | case Legal: |
Dan Gohman | faeb4a3 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2286 | if (cast<ConstantSDNode>(Node->getOperand(1))->getZExtValue()) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2287 | // 1 -> Hi |
| 2288 | Result = DAG.getNode(ISD::SRL, OpTy, Node->getOperand(0), |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2289 | DAG.getConstant(OpTy.getSizeInBits()/2, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2290 | TLI.getShiftAmountTy())); |
| 2291 | Result = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0), Result); |
| 2292 | } else { |
| 2293 | // 0 -> Lo |
| 2294 | Result = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0), |
| 2295 | Node->getOperand(0)); |
| 2296 | } |
| 2297 | break; |
| 2298 | case Expand: |
| 2299 | // Get both the low and high parts. |
| 2300 | ExpandOp(Node->getOperand(0), Tmp1, Tmp2); |
Dan Gohman | faeb4a3 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2301 | if (cast<ConstantSDNode>(Node->getOperand(1))->getZExtValue()) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2302 | Result = Tmp2; // 1 -> Hi |
| 2303 | else |
| 2304 | Result = Tmp1; // 0 -> Lo |
| 2305 | break; |
| 2306 | } |
| 2307 | break; |
| 2308 | } |
| 2309 | |
| 2310 | case ISD::CopyToReg: |
| 2311 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 2312 | |
| 2313 | assert(isTypeLegal(Node->getOperand(2).getValueType()) && |
| 2314 | "Register type must be legal!"); |
| 2315 | // Legalize the incoming value (must be a legal type). |
| 2316 | Tmp2 = LegalizeOp(Node->getOperand(2)); |
| 2317 | if (Node->getNumValues() == 1) { |
| 2318 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1), Tmp2); |
| 2319 | } else { |
| 2320 | assert(Node->getNumValues() == 2 && "Unknown CopyToReg"); |
| 2321 | if (Node->getNumOperands() == 4) { |
| 2322 | Tmp3 = LegalizeOp(Node->getOperand(3)); |
| 2323 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1), Tmp2, |
| 2324 | Tmp3); |
| 2325 | } else { |
| 2326 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1),Tmp2); |
| 2327 | } |
| 2328 | |
| 2329 | // Since this produces two values, make sure to remember that we legalized |
| 2330 | // both of them. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2331 | AddLegalizedOperand(SDValue(Node, 0), Result.getValue(0)); |
| 2332 | AddLegalizedOperand(SDValue(Node, 1), Result.getValue(1)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2333 | return Result; |
| 2334 | } |
| 2335 | break; |
| 2336 | |
| 2337 | case ISD::RET: |
| 2338 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 2339 | |
| 2340 | // Ensure that libcalls are emitted before a return. |
| 2341 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 2342 | Tmp1 = LegalizeOp(Tmp1); |
| 2343 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 2344 | |
| 2345 | switch (Node->getNumOperands()) { |
| 2346 | case 3: // ret val |
| 2347 | Tmp2 = Node->getOperand(1); |
| 2348 | Tmp3 = Node->getOperand(2); // Signness |
| 2349 | switch (getTypeAction(Tmp2.getValueType())) { |
| 2350 | case Legal: |
| 2351 | Result = DAG.UpdateNodeOperands(Result, Tmp1, LegalizeOp(Tmp2), Tmp3); |
| 2352 | break; |
| 2353 | case Expand: |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2354 | if (!Tmp2.getValueType().isVector()) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2355 | SDValue Lo, Hi; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2356 | ExpandOp(Tmp2, Lo, Hi); |
| 2357 | |
| 2358 | // Big endian systems want the hi reg first. |
Duncan Sands | 9ff8fbf | 2008-02-11 10:37:04 +0000 | [diff] [blame] | 2359 | if (TLI.isBigEndian()) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2360 | std::swap(Lo, Hi); |
| 2361 | |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2362 | if (Hi.getNode()) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2363 | Result = DAG.getNode(ISD::RET, MVT::Other, Tmp1, Lo, Tmp3, Hi,Tmp3); |
| 2364 | else |
| 2365 | Result = DAG.getNode(ISD::RET, MVT::Other, Tmp1, Lo, Tmp3); |
| 2366 | Result = LegalizeOp(Result); |
| 2367 | } else { |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2368 | SDNode *InVal = Tmp2.getNode(); |
Gabor Greif | 46bf547 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 2369 | int InIx = Tmp2.getResNo(); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2370 | unsigned NumElems = InVal->getValueType(InIx).getVectorNumElements(); |
| 2371 | MVT EVT = InVal->getValueType(InIx).getVectorElementType(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2372 | |
| 2373 | // Figure out if there is a simple type corresponding to this Vector |
| 2374 | // type. If so, convert to the vector type. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2375 | MVT TVT = MVT::getVectorVT(EVT, NumElems); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2376 | if (TLI.isTypeLegal(TVT)) { |
| 2377 | // Turn this into a return of the vector type. |
| 2378 | Tmp2 = LegalizeOp(Tmp2); |
| 2379 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
| 2380 | } else if (NumElems == 1) { |
| 2381 | // Turn this into a return of the scalar type. |
| 2382 | Tmp2 = ScalarizeVectorOp(Tmp2); |
| 2383 | Tmp2 = LegalizeOp(Tmp2); |
| 2384 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
| 2385 | |
| 2386 | // FIXME: Returns of gcc generic vectors smaller than a legal type |
| 2387 | // should be returned in integer registers! |
| 2388 | |
| 2389 | // The scalarized value type may not be legal, e.g. it might require |
| 2390 | // promotion or expansion. Relegalize the return. |
| 2391 | Result = LegalizeOp(Result); |
| 2392 | } else { |
| 2393 | // FIXME: Returns of gcc generic vectors larger than a legal vector |
| 2394 | // type should be returned by reference! |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2395 | SDValue Lo, Hi; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2396 | SplitVectorOp(Tmp2, Lo, Hi); |
| 2397 | Result = DAG.getNode(ISD::RET, MVT::Other, Tmp1, Lo, Tmp3, Hi,Tmp3); |
| 2398 | Result = LegalizeOp(Result); |
| 2399 | } |
| 2400 | } |
| 2401 | break; |
| 2402 | case Promote: |
| 2403 | Tmp2 = PromoteOp(Node->getOperand(1)); |
| 2404 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
| 2405 | Result = LegalizeOp(Result); |
| 2406 | break; |
| 2407 | } |
| 2408 | break; |
| 2409 | case 1: // ret void |
| 2410 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 2411 | break; |
| 2412 | default: { // ret <values> |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2413 | SmallVector<SDValue, 8> NewValues; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2414 | NewValues.push_back(Tmp1); |
| 2415 | for (unsigned i = 1, e = Node->getNumOperands(); i < e; i += 2) |
| 2416 | switch (getTypeAction(Node->getOperand(i).getValueType())) { |
| 2417 | case Legal: |
| 2418 | NewValues.push_back(LegalizeOp(Node->getOperand(i))); |
| 2419 | NewValues.push_back(Node->getOperand(i+1)); |
| 2420 | break; |
| 2421 | case Expand: { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2422 | SDValue Lo, Hi; |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2423 | assert(!Node->getOperand(i).getValueType().isExtended() && |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2424 | "FIXME: TODO: implement returning non-legal vector types!"); |
| 2425 | ExpandOp(Node->getOperand(i), Lo, Hi); |
| 2426 | NewValues.push_back(Lo); |
| 2427 | NewValues.push_back(Node->getOperand(i+1)); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2428 | if (Hi.getNode()) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2429 | NewValues.push_back(Hi); |
| 2430 | NewValues.push_back(Node->getOperand(i+1)); |
| 2431 | } |
| 2432 | break; |
| 2433 | } |
| 2434 | case Promote: |
| 2435 | assert(0 && "Can't promote multiple return value yet!"); |
| 2436 | } |
| 2437 | |
| 2438 | if (NewValues.size() == Node->getNumOperands()) |
| 2439 | Result = DAG.UpdateNodeOperands(Result, &NewValues[0],NewValues.size()); |
| 2440 | else |
| 2441 | Result = DAG.getNode(ISD::RET, MVT::Other, |
| 2442 | &NewValues[0], NewValues.size()); |
| 2443 | break; |
| 2444 | } |
| 2445 | } |
| 2446 | |
| 2447 | if (Result.getOpcode() == ISD::RET) { |
| 2448 | switch (TLI.getOperationAction(Result.getOpcode(), MVT::Other)) { |
| 2449 | default: assert(0 && "This action is not supported yet!"); |
| 2450 | case TargetLowering::Legal: break; |
| 2451 | case TargetLowering::Custom: |
| 2452 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2453 | if (Tmp1.getNode()) Result = Tmp1; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2454 | break; |
| 2455 | } |
| 2456 | } |
| 2457 | break; |
| 2458 | case ISD::STORE: { |
| 2459 | StoreSDNode *ST = cast<StoreSDNode>(Node); |
| 2460 | Tmp1 = LegalizeOp(ST->getChain()); // Legalize the chain. |
| 2461 | Tmp2 = LegalizeOp(ST->getBasePtr()); // Legalize the pointer. |
| 2462 | int SVOffset = ST->getSrcValueOffset(); |
| 2463 | unsigned Alignment = ST->getAlignment(); |
| 2464 | bool isVolatile = ST->isVolatile(); |
| 2465 | |
| 2466 | if (!ST->isTruncatingStore()) { |
| 2467 | // Turn 'store float 1.0, Ptr' -> 'store int 0x12345678, Ptr' |
| 2468 | // FIXME: We shouldn't do this for TargetConstantFP's. |
| 2469 | // FIXME: move this to the DAG Combiner! Note that we can't regress due |
| 2470 | // to phase ordering between legalized code and the dag combiner. This |
| 2471 | // probably means that we need to integrate dag combiner and legalizer |
| 2472 | // together. |
Dale Johannesen | 2fc2078 | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 2473 | // We generally can't do this one for long doubles. |
Chris Lattner | e8671c5 | 2007-10-13 06:35:54 +0000 | [diff] [blame] | 2474 | if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(ST->getValue())) { |
Chris Lattner | 19f229a | 2007-10-15 05:46:06 +0000 | [diff] [blame] | 2475 | if (CFP->getValueType(0) == MVT::f32 && |
| 2476 | getTypeAction(MVT::i32) == Legal) { |
Dan Gohman | 3950976 | 2008-03-11 00:11:06 +0000 | [diff] [blame] | 2477 | Tmp3 = DAG.getConstant(CFP->getValueAPF(). |
Dale Johannesen | 49cc7ce | 2008-10-09 18:53:47 +0000 | [diff] [blame] | 2478 | bitcastToAPInt().zextOrTrunc(32), |
Dale Johannesen | 1616e90 | 2007-09-11 18:32:33 +0000 | [diff] [blame] | 2479 | MVT::i32); |
Dale Johannesen | 2fc2078 | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 2480 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
| 2481 | SVOffset, isVolatile, Alignment); |
| 2482 | break; |
| 2483 | } else if (CFP->getValueType(0) == MVT::f64) { |
Chris Lattner | 19f229a | 2007-10-15 05:46:06 +0000 | [diff] [blame] | 2484 | // If this target supports 64-bit registers, do a single 64-bit store. |
| 2485 | if (getTypeAction(MVT::i64) == Legal) { |
Dale Johannesen | 49cc7ce | 2008-10-09 18:53:47 +0000 | [diff] [blame] | 2486 | Tmp3 = DAG.getConstant(CFP->getValueAPF().bitcastToAPInt(). |
Dan Gohman | 3950976 | 2008-03-11 00:11:06 +0000 | [diff] [blame] | 2487 | zextOrTrunc(64), MVT::i64); |
Chris Lattner | 19f229a | 2007-10-15 05:46:06 +0000 | [diff] [blame] | 2488 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
| 2489 | SVOffset, isVolatile, Alignment); |
| 2490 | break; |
Duncan Sands | 2418bec | 2008-06-13 19:07:40 +0000 | [diff] [blame] | 2491 | } else if (getTypeAction(MVT::i32) == Legal && !ST->isVolatile()) { |
Chris Lattner | 19f229a | 2007-10-15 05:46:06 +0000 | [diff] [blame] | 2492 | // Otherwise, if the target supports 32-bit registers, use 2 32-bit |
| 2493 | // stores. If the target supports neither 32- nor 64-bits, this |
| 2494 | // xform is certainly not worth it. |
Dale Johannesen | 49cc7ce | 2008-10-09 18:53:47 +0000 | [diff] [blame] | 2495 | const APInt &IntVal =CFP->getValueAPF().bitcastToAPInt(); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2496 | SDValue Lo = DAG.getConstant(APInt(IntVal).trunc(32), MVT::i32); |
| 2497 | SDValue Hi = DAG.getConstant(IntVal.lshr(32).trunc(32), MVT::i32); |
Duncan Sands | 9ff8fbf | 2008-02-11 10:37:04 +0000 | [diff] [blame] | 2498 | if (TLI.isBigEndian()) std::swap(Lo, Hi); |
Chris Lattner | 19f229a | 2007-10-15 05:46:06 +0000 | [diff] [blame] | 2499 | |
| 2500 | Lo = DAG.getStore(Tmp1, Lo, Tmp2, ST->getSrcValue(), |
| 2501 | SVOffset, isVolatile, Alignment); |
| 2502 | Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2, |
Chris Lattner | 5872a36 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 2503 | DAG.getIntPtrConstant(4)); |
Chris Lattner | 19f229a | 2007-10-15 05:46:06 +0000 | [diff] [blame] | 2504 | Hi = DAG.getStore(Tmp1, Hi, Tmp2, ST->getSrcValue(), SVOffset+4, |
Duncan Sands | a369143 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 2505 | isVolatile, MinAlign(Alignment, 4U)); |
Chris Lattner | 19f229a | 2007-10-15 05:46:06 +0000 | [diff] [blame] | 2506 | |
| 2507 | Result = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo, Hi); |
| 2508 | break; |
| 2509 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2510 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2511 | } |
| 2512 | |
Dan Gohman | 9a4c92c | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 2513 | switch (getTypeAction(ST->getMemoryVT())) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2514 | case Legal: { |
| 2515 | Tmp3 = LegalizeOp(ST->getValue()); |
| 2516 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp3, Tmp2, |
| 2517 | ST->getOffset()); |
| 2518 | |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2519 | MVT VT = Tmp3.getValueType(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2520 | switch (TLI.getOperationAction(ISD::STORE, VT)) { |
| 2521 | default: assert(0 && "This action is not supported yet!"); |
Lauro Ramos Venancio | 578434f | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2522 | case TargetLowering::Legal: |
| 2523 | // If this is an unaligned store and the target doesn't support it, |
| 2524 | // expand it. |
| 2525 | if (!TLI.allowsUnalignedMemoryAccesses()) { |
| 2526 | unsigned ABIAlignment = TLI.getTargetData()-> |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2527 | getABITypeAlignment(ST->getMemoryVT().getTypeForMVT()); |
Lauro Ramos Venancio | 578434f | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2528 | if (ST->getAlignment() < ABIAlignment) |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2529 | Result = ExpandUnalignedStore(cast<StoreSDNode>(Result.getNode()), DAG, |
Lauro Ramos Venancio | 578434f | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2530 | TLI); |
| 2531 | } |
| 2532 | break; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2533 | case TargetLowering::Custom: |
| 2534 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2535 | if (Tmp1.getNode()) Result = Tmp1; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2536 | break; |
| 2537 | case TargetLowering::Promote: |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2538 | assert(VT.isVector() && "Unknown legal promote case!"); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2539 | Tmp3 = DAG.getNode(ISD::BIT_CONVERT, |
| 2540 | TLI.getTypeToPromoteTo(ISD::STORE, VT), Tmp3); |
| 2541 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, |
| 2542 | ST->getSrcValue(), SVOffset, isVolatile, |
| 2543 | Alignment); |
| 2544 | break; |
| 2545 | } |
| 2546 | break; |
| 2547 | } |
| 2548 | case Promote: |
Mon P Wang | 1448aad | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 2549 | if (!ST->getMemoryVT().isVector()) { |
| 2550 | // Truncate the value and store the result. |
| 2551 | Tmp3 = PromoteOp(ST->getValue()); |
| 2552 | Result = DAG.getTruncStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
| 2553 | SVOffset, ST->getMemoryVT(), |
| 2554 | isVolatile, Alignment); |
| 2555 | break; |
| 2556 | } |
| 2557 | // Fall thru to expand for vector |
| 2558 | case Expand: { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2559 | unsigned IncrementSize = 0; |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2560 | SDValue Lo, Hi; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2561 | |
| 2562 | // If this is a vector type, then we have to calculate the increment as |
| 2563 | // the product of the element size in bytes, and the number of elements |
| 2564 | // in the high half of the vector. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2565 | if (ST->getValue().getValueType().isVector()) { |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2566 | SDNode *InVal = ST->getValue().getNode(); |
Gabor Greif | 46bf547 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 2567 | int InIx = ST->getValue().getResNo(); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2568 | MVT InVT = InVal->getValueType(InIx); |
| 2569 | unsigned NumElems = InVT.getVectorNumElements(); |
| 2570 | MVT EVT = InVT.getVectorElementType(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2571 | |
| 2572 | // Figure out if there is a simple type corresponding to this Vector |
| 2573 | // type. If so, convert to the vector type. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2574 | MVT TVT = MVT::getVectorVT(EVT, NumElems); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2575 | if (TLI.isTypeLegal(TVT)) { |
| 2576 | // Turn this into a normal store of the vector type. |
Dan Gohman | e9f633d | 2008-02-15 18:11:59 +0000 | [diff] [blame] | 2577 | Tmp3 = LegalizeOp(ST->getValue()); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2578 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
| 2579 | SVOffset, isVolatile, Alignment); |
| 2580 | Result = LegalizeOp(Result); |
| 2581 | break; |
| 2582 | } else if (NumElems == 1) { |
| 2583 | // Turn this into a normal store of the scalar type. |
Dan Gohman | e9f633d | 2008-02-15 18:11:59 +0000 | [diff] [blame] | 2584 | Tmp3 = ScalarizeVectorOp(ST->getValue()); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2585 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
| 2586 | SVOffset, isVolatile, Alignment); |
| 2587 | // The scalarized value type may not be legal, e.g. it might require |
| 2588 | // promotion or expansion. Relegalize the scalar store. |
| 2589 | Result = LegalizeOp(Result); |
| 2590 | break; |
| 2591 | } else { |
Mon P Wang | 1448aad | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 2592 | // Check if we have widen this node with another value |
| 2593 | std::map<SDValue, SDValue>::iterator I = |
| 2594 | WidenNodes.find(ST->getValue()); |
| 2595 | if (I != WidenNodes.end()) { |
| 2596 | Result = StoreWidenVectorOp(ST, Tmp1, Tmp2); |
| 2597 | break; |
| 2598 | } |
| 2599 | else { |
| 2600 | SplitVectorOp(ST->getValue(), Lo, Hi); |
| 2601 | IncrementSize = Lo.getNode()->getValueType(0).getVectorNumElements() * |
| 2602 | EVT.getSizeInBits()/8; |
| 2603 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2604 | } |
| 2605 | } else { |
Dan Gohman | e9f633d | 2008-02-15 18:11:59 +0000 | [diff] [blame] | 2606 | ExpandOp(ST->getValue(), Lo, Hi); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2607 | IncrementSize = Hi.getNode() ? Hi.getValueType().getSizeInBits()/8 : 0; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2608 | |
Richard Pennington | 73ae9e4 | 2008-09-25 16:15:10 +0000 | [diff] [blame] | 2609 | if (Hi.getNode() && TLI.isBigEndian()) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2610 | std::swap(Lo, Hi); |
| 2611 | } |
| 2612 | |
| 2613 | Lo = DAG.getStore(Tmp1, Lo, Tmp2, ST->getSrcValue(), |
| 2614 | SVOffset, isVolatile, Alignment); |
| 2615 | |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2616 | if (Hi.getNode() == NULL) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2617 | // Must be int <-> float one-to-one expansion. |
| 2618 | Result = Lo; |
| 2619 | break; |
| 2620 | } |
| 2621 | |
| 2622 | Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2, |
Chris Lattner | 5872a36 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 2623 | DAG.getIntPtrConstant(IncrementSize)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2624 | assert(isTypeLegal(Tmp2.getValueType()) && |
| 2625 | "Pointers must be legal!"); |
| 2626 | SVOffset += IncrementSize; |
Duncan Sands | a369143 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 2627 | Alignment = MinAlign(Alignment, IncrementSize); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2628 | Hi = DAG.getStore(Tmp1, Hi, Tmp2, ST->getSrcValue(), |
| 2629 | SVOffset, isVolatile, Alignment); |
| 2630 | Result = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo, Hi); |
| 2631 | break; |
Mon P Wang | 1448aad | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 2632 | } // case Expand |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2633 | } |
| 2634 | } else { |
Chris Lattner | 3bc0850 | 2008-01-17 19:59:44 +0000 | [diff] [blame] | 2635 | switch (getTypeAction(ST->getValue().getValueType())) { |
| 2636 | case Legal: |
| 2637 | Tmp3 = LegalizeOp(ST->getValue()); |
| 2638 | break; |
| 2639 | case Promote: |
Mon P Wang | 1448aad | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 2640 | if (!ST->getValue().getValueType().isVector()) { |
| 2641 | // We can promote the value, the truncstore will still take care of it. |
| 2642 | Tmp3 = PromoteOp(ST->getValue()); |
| 2643 | break; |
| 2644 | } |
| 2645 | // Vector case falls through to expand |
Chris Lattner | 3bc0850 | 2008-01-17 19:59:44 +0000 | [diff] [blame] | 2646 | case Expand: |
| 2647 | // Just store the low part. This may become a non-trunc store, so make |
| 2648 | // sure to use getTruncStore, not UpdateNodeOperands below. |
| 2649 | ExpandOp(ST->getValue(), Tmp3, Tmp4); |
| 2650 | return DAG.getTruncStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
| 2651 | SVOffset, MVT::i8, isVolatile, Alignment); |
| 2652 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2653 | |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2654 | MVT StVT = ST->getMemoryVT(); |
| 2655 | unsigned StWidth = StVT.getSizeInBits(); |
Duncan Sands | 4067666 | 2008-01-22 07:17:34 +0000 | [diff] [blame] | 2656 | |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2657 | if (StWidth != StVT.getStoreSizeInBits()) { |
Duncan Sands | 4067666 | 2008-01-22 07:17:34 +0000 | [diff] [blame] | 2658 | // Promote to a byte-sized store with upper bits zero if not |
| 2659 | // storing an integral number of bytes. For example, promote |
| 2660 | // TRUNCSTORE:i1 X -> TRUNCSTORE:i8 (and X, 1) |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2661 | MVT NVT = MVT::getIntegerVT(StVT.getStoreSizeInBits()); |
Duncan Sands | 4067666 | 2008-01-22 07:17:34 +0000 | [diff] [blame] | 2662 | Tmp3 = DAG.getZeroExtendInReg(Tmp3, StVT); |
| 2663 | Result = DAG.getTruncStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
| 2664 | SVOffset, NVT, isVolatile, Alignment); |
| 2665 | } else if (StWidth & (StWidth - 1)) { |
| 2666 | // If not storing a power-of-2 number of bits, expand as two stores. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2667 | assert(StVT.isExtended() && !StVT.isVector() && |
Duncan Sands | 4067666 | 2008-01-22 07:17:34 +0000 | [diff] [blame] | 2668 | "Unsupported truncstore!"); |
| 2669 | unsigned RoundWidth = 1 << Log2_32(StWidth); |
| 2670 | assert(RoundWidth < StWidth); |
| 2671 | unsigned ExtraWidth = StWidth - RoundWidth; |
| 2672 | assert(ExtraWidth < RoundWidth); |
| 2673 | assert(!(RoundWidth % 8) && !(ExtraWidth % 8) && |
| 2674 | "Store size not an integral number of bytes!"); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2675 | MVT RoundVT = MVT::getIntegerVT(RoundWidth); |
| 2676 | MVT ExtraVT = MVT::getIntegerVT(ExtraWidth); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2677 | SDValue Lo, Hi; |
Duncan Sands | 4067666 | 2008-01-22 07:17:34 +0000 | [diff] [blame] | 2678 | unsigned IncrementSize; |
| 2679 | |
| 2680 | if (TLI.isLittleEndian()) { |
| 2681 | // TRUNCSTORE:i24 X -> TRUNCSTORE:i16 X, TRUNCSTORE@+2:i8 (srl X, 16) |
| 2682 | // Store the bottom RoundWidth bits. |
| 2683 | Lo = DAG.getTruncStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
| 2684 | SVOffset, RoundVT, |
| 2685 | isVolatile, Alignment); |
| 2686 | |
| 2687 | // Store the remaining ExtraWidth bits. |
| 2688 | IncrementSize = RoundWidth / 8; |
| 2689 | Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2, |
| 2690 | DAG.getIntPtrConstant(IncrementSize)); |
| 2691 | Hi = DAG.getNode(ISD::SRL, Tmp3.getValueType(), Tmp3, |
| 2692 | DAG.getConstant(RoundWidth, TLI.getShiftAmountTy())); |
| 2693 | Hi = DAG.getTruncStore(Tmp1, Hi, Tmp2, ST->getSrcValue(), |
| 2694 | SVOffset + IncrementSize, ExtraVT, isVolatile, |
| 2695 | MinAlign(Alignment, IncrementSize)); |
| 2696 | } else { |
| 2697 | // Big endian - avoid unaligned stores. |
| 2698 | // TRUNCSTORE:i24 X -> TRUNCSTORE:i16 (srl X, 8), TRUNCSTORE@+2:i8 X |
| 2699 | // Store the top RoundWidth bits. |
| 2700 | Hi = DAG.getNode(ISD::SRL, Tmp3.getValueType(), Tmp3, |
| 2701 | DAG.getConstant(ExtraWidth, TLI.getShiftAmountTy())); |
| 2702 | Hi = DAG.getTruncStore(Tmp1, Hi, Tmp2, ST->getSrcValue(), SVOffset, |
| 2703 | RoundVT, isVolatile, Alignment); |
| 2704 | |
| 2705 | // Store the remaining ExtraWidth bits. |
| 2706 | IncrementSize = RoundWidth / 8; |
| 2707 | Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2, |
| 2708 | DAG.getIntPtrConstant(IncrementSize)); |
| 2709 | Lo = DAG.getTruncStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
| 2710 | SVOffset + IncrementSize, ExtraVT, isVolatile, |
| 2711 | MinAlign(Alignment, IncrementSize)); |
Lauro Ramos Venancio | 578434f | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2712 | } |
Duncan Sands | 4067666 | 2008-01-22 07:17:34 +0000 | [diff] [blame] | 2713 | |
| 2714 | // The order of the stores doesn't matter. |
| 2715 | Result = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo, Hi); |
| 2716 | } else { |
| 2717 | if (Tmp1 != ST->getChain() || Tmp3 != ST->getValue() || |
| 2718 | Tmp2 != ST->getBasePtr()) |
| 2719 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp3, Tmp2, |
| 2720 | ST->getOffset()); |
| 2721 | |
| 2722 | switch (TLI.getTruncStoreAction(ST->getValue().getValueType(), StVT)) { |
| 2723 | default: assert(0 && "This action is not supported yet!"); |
| 2724 | case TargetLowering::Legal: |
| 2725 | // If this is an unaligned store and the target doesn't support it, |
| 2726 | // expand it. |
| 2727 | if (!TLI.allowsUnalignedMemoryAccesses()) { |
| 2728 | unsigned ABIAlignment = TLI.getTargetData()-> |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2729 | getABITypeAlignment(ST->getMemoryVT().getTypeForMVT()); |
Duncan Sands | 4067666 | 2008-01-22 07:17:34 +0000 | [diff] [blame] | 2730 | if (ST->getAlignment() < ABIAlignment) |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2731 | Result = ExpandUnalignedStore(cast<StoreSDNode>(Result.getNode()), DAG, |
Duncan Sands | 4067666 | 2008-01-22 07:17:34 +0000 | [diff] [blame] | 2732 | TLI); |
| 2733 | } |
| 2734 | break; |
| 2735 | case TargetLowering::Custom: |
| 2736 | Result = TLI.LowerOperation(Result, DAG); |
| 2737 | break; |
| 2738 | case Expand: |
| 2739 | // TRUNCSTORE:i16 i32 -> STORE i16 |
| 2740 | assert(isTypeLegal(StVT) && "Do not know how to expand this store!"); |
| 2741 | Tmp3 = DAG.getNode(ISD::TRUNCATE, StVT, Tmp3); |
| 2742 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), SVOffset, |
| 2743 | isVolatile, Alignment); |
| 2744 | break; |
| 2745 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2746 | } |
| 2747 | } |
| 2748 | break; |
| 2749 | } |
| 2750 | case ISD::PCMARKER: |
| 2751 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 2752 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
| 2753 | break; |
| 2754 | case ISD::STACKSAVE: |
| 2755 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 2756 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 2757 | Tmp1 = Result.getValue(0); |
| 2758 | Tmp2 = Result.getValue(1); |
| 2759 | |
| 2760 | switch (TLI.getOperationAction(ISD::STACKSAVE, MVT::Other)) { |
| 2761 | default: assert(0 && "This action is not supported yet!"); |
| 2762 | case TargetLowering::Legal: break; |
| 2763 | case TargetLowering::Custom: |
| 2764 | Tmp3 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2765 | if (Tmp3.getNode()) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2766 | Tmp1 = LegalizeOp(Tmp3); |
| 2767 | Tmp2 = LegalizeOp(Tmp3.getValue(1)); |
| 2768 | } |
| 2769 | break; |
| 2770 | case TargetLowering::Expand: |
| 2771 | // Expand to CopyFromReg if the target set |
| 2772 | // StackPointerRegisterToSaveRestore. |
| 2773 | if (unsigned SP = TLI.getStackPointerRegisterToSaveRestore()) { |
| 2774 | Tmp1 = DAG.getCopyFromReg(Result.getOperand(0), SP, |
| 2775 | Node->getValueType(0)); |
| 2776 | Tmp2 = Tmp1.getValue(1); |
| 2777 | } else { |
| 2778 | Tmp1 = DAG.getNode(ISD::UNDEF, Node->getValueType(0)); |
| 2779 | Tmp2 = Node->getOperand(0); |
| 2780 | } |
| 2781 | break; |
| 2782 | } |
| 2783 | |
| 2784 | // Since stacksave produce two values, make sure to remember that we |
| 2785 | // legalized both of them. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2786 | AddLegalizedOperand(SDValue(Node, 0), Tmp1); |
| 2787 | AddLegalizedOperand(SDValue(Node, 1), Tmp2); |
Gabor Greif | 46bf547 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 2788 | return Op.getResNo() ? Tmp2 : Tmp1; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2789 | |
| 2790 | case ISD::STACKRESTORE: |
| 2791 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 2792 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. |
| 2793 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 2794 | |
| 2795 | switch (TLI.getOperationAction(ISD::STACKRESTORE, MVT::Other)) { |
| 2796 | default: assert(0 && "This action is not supported yet!"); |
| 2797 | case TargetLowering::Legal: break; |
| 2798 | case TargetLowering::Custom: |
| 2799 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2800 | if (Tmp1.getNode()) Result = Tmp1; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2801 | break; |
| 2802 | case TargetLowering::Expand: |
| 2803 | // Expand to CopyToReg if the target set |
| 2804 | // StackPointerRegisterToSaveRestore. |
| 2805 | if (unsigned SP = TLI.getStackPointerRegisterToSaveRestore()) { |
| 2806 | Result = DAG.getCopyToReg(Tmp1, SP, Tmp2); |
| 2807 | } else { |
| 2808 | Result = Tmp1; |
| 2809 | } |
| 2810 | break; |
| 2811 | } |
| 2812 | break; |
| 2813 | |
| 2814 | case ISD::READCYCLECOUNTER: |
| 2815 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain |
| 2816 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 2817 | switch (TLI.getOperationAction(ISD::READCYCLECOUNTER, |
| 2818 | Node->getValueType(0))) { |
| 2819 | default: assert(0 && "This action is not supported yet!"); |
| 2820 | case TargetLowering::Legal: |
| 2821 | Tmp1 = Result.getValue(0); |
| 2822 | Tmp2 = Result.getValue(1); |
| 2823 | break; |
| 2824 | case TargetLowering::Custom: |
| 2825 | Result = TLI.LowerOperation(Result, DAG); |
| 2826 | Tmp1 = LegalizeOp(Result.getValue(0)); |
| 2827 | Tmp2 = LegalizeOp(Result.getValue(1)); |
| 2828 | break; |
| 2829 | } |
| 2830 | |
| 2831 | // Since rdcc produce two values, make sure to remember that we legalized |
| 2832 | // both of them. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2833 | AddLegalizedOperand(SDValue(Node, 0), Tmp1); |
| 2834 | AddLegalizedOperand(SDValue(Node, 1), Tmp2); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2835 | return Result; |
| 2836 | |
| 2837 | case ISD::SELECT: |
| 2838 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 2839 | case Expand: assert(0 && "It's impossible to expand bools"); |
| 2840 | case Legal: |
| 2841 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the condition. |
| 2842 | break; |
Dan Gohman | 07961cd | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 2843 | case Promote: { |
Mon P Wang | 1448aad | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 2844 | assert(!Node->getOperand(0).getValueType().isVector() && "not possible"); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2845 | Tmp1 = PromoteOp(Node->getOperand(0)); // Promote the condition. |
| 2846 | // Make sure the condition is either zero or one. |
Dan Gohman | 07961cd | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 2847 | unsigned BitWidth = Tmp1.getValueSizeInBits(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2848 | if (!DAG.MaskedValueIsZero(Tmp1, |
Dan Gohman | 07961cd | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 2849 | APInt::getHighBitsSet(BitWidth, BitWidth-1))) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2850 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, MVT::i1); |
| 2851 | break; |
| 2852 | } |
Dan Gohman | 07961cd | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 2853 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2854 | Tmp2 = LegalizeOp(Node->getOperand(1)); // TrueVal |
| 2855 | Tmp3 = LegalizeOp(Node->getOperand(2)); // FalseVal |
| 2856 | |
| 2857 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
| 2858 | |
| 2859 | switch (TLI.getOperationAction(ISD::SELECT, Tmp2.getValueType())) { |
| 2860 | default: assert(0 && "This action is not supported yet!"); |
| 2861 | case TargetLowering::Legal: break; |
| 2862 | case TargetLowering::Custom: { |
| 2863 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2864 | if (Tmp1.getNode()) Result = Tmp1; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2865 | break; |
| 2866 | } |
| 2867 | case TargetLowering::Expand: |
| 2868 | if (Tmp1.getOpcode() == ISD::SETCC) { |
| 2869 | Result = DAG.getSelectCC(Tmp1.getOperand(0), Tmp1.getOperand(1), |
| 2870 | Tmp2, Tmp3, |
| 2871 | cast<CondCodeSDNode>(Tmp1.getOperand(2))->get()); |
| 2872 | } else { |
| 2873 | Result = DAG.getSelectCC(Tmp1, |
| 2874 | DAG.getConstant(0, Tmp1.getValueType()), |
| 2875 | Tmp2, Tmp3, ISD::SETNE); |
| 2876 | } |
| 2877 | break; |
| 2878 | case TargetLowering::Promote: { |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2879 | MVT NVT = |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2880 | TLI.getTypeToPromoteTo(ISD::SELECT, Tmp2.getValueType()); |
| 2881 | unsigned ExtOp, TruncOp; |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2882 | if (Tmp2.getValueType().isVector()) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2883 | ExtOp = ISD::BIT_CONVERT; |
| 2884 | TruncOp = ISD::BIT_CONVERT; |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2885 | } else if (Tmp2.getValueType().isInteger()) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2886 | ExtOp = ISD::ANY_EXTEND; |
| 2887 | TruncOp = ISD::TRUNCATE; |
| 2888 | } else { |
| 2889 | ExtOp = ISD::FP_EXTEND; |
| 2890 | TruncOp = ISD::FP_ROUND; |
| 2891 | } |
| 2892 | // Promote each of the values to the new type. |
| 2893 | Tmp2 = DAG.getNode(ExtOp, NVT, Tmp2); |
| 2894 | Tmp3 = DAG.getNode(ExtOp, NVT, Tmp3); |
| 2895 | // Perform the larger operation, then round down. |
| 2896 | Result = DAG.getNode(ISD::SELECT, NVT, Tmp1, Tmp2,Tmp3); |
Chris Lattner | 5872a36 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 2897 | if (TruncOp != ISD::FP_ROUND) |
| 2898 | Result = DAG.getNode(TruncOp, Node->getValueType(0), Result); |
| 2899 | else |
| 2900 | Result = DAG.getNode(TruncOp, Node->getValueType(0), Result, |
| 2901 | DAG.getIntPtrConstant(0)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2902 | break; |
| 2903 | } |
| 2904 | } |
| 2905 | break; |
| 2906 | case ISD::SELECT_CC: { |
| 2907 | Tmp1 = Node->getOperand(0); // LHS |
| 2908 | Tmp2 = Node->getOperand(1); // RHS |
| 2909 | Tmp3 = LegalizeOp(Node->getOperand(2)); // True |
| 2910 | Tmp4 = LegalizeOp(Node->getOperand(3)); // False |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2911 | SDValue CC = Node->getOperand(4); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2912 | |
Dale Johannesen | 32100b2 | 2008-11-07 22:54:33 +0000 | [diff] [blame] | 2913 | LegalizeSetCC(TLI.getSetCCResultType(Tmp1), Tmp1, Tmp2, CC); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2914 | |
Evan Cheng | 7134382 | 2008-10-15 02:05:31 +0000 | [diff] [blame] | 2915 | // If we didn't get both a LHS and RHS back from LegalizeSetCC, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2916 | // the LHS is a legal SETCC itself. In this case, we need to compare |
| 2917 | // the result against zero to select between true and false values. |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2918 | if (Tmp2.getNode() == 0) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2919 | Tmp2 = DAG.getConstant(0, Tmp1.getValueType()); |
| 2920 | CC = DAG.getCondCode(ISD::SETNE); |
| 2921 | } |
| 2922 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3, Tmp4, CC); |
| 2923 | |
| 2924 | // Everything is legal, see if we should expand this op or something. |
| 2925 | switch (TLI.getOperationAction(ISD::SELECT_CC, Tmp3.getValueType())) { |
| 2926 | default: assert(0 && "This action is not supported yet!"); |
| 2927 | case TargetLowering::Legal: break; |
| 2928 | case TargetLowering::Custom: |
| 2929 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2930 | if (Tmp1.getNode()) Result = Tmp1; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2931 | break; |
| 2932 | } |
| 2933 | break; |
| 2934 | } |
| 2935 | case ISD::SETCC: |
| 2936 | Tmp1 = Node->getOperand(0); |
| 2937 | Tmp2 = Node->getOperand(1); |
| 2938 | Tmp3 = Node->getOperand(2); |
Evan Cheng | 7134382 | 2008-10-15 02:05:31 +0000 | [diff] [blame] | 2939 | LegalizeSetCC(Node->getValueType(0), Tmp1, Tmp2, Tmp3); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2940 | |
| 2941 | // If we had to Expand the SetCC operands into a SELECT node, then it may |
| 2942 | // not always be possible to return a true LHS & RHS. In this case, just |
| 2943 | // return the value we legalized, returned in the LHS |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2944 | if (Tmp2.getNode() == 0) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2945 | Result = Tmp1; |
| 2946 | break; |
| 2947 | } |
| 2948 | |
| 2949 | switch (TLI.getOperationAction(ISD::SETCC, Tmp1.getValueType())) { |
| 2950 | default: assert(0 && "Cannot handle this action for SETCC yet!"); |
| 2951 | case TargetLowering::Custom: |
| 2952 | isCustom = true; |
| 2953 | // FALLTHROUGH. |
| 2954 | case TargetLowering::Legal: |
| 2955 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
| 2956 | if (isCustom) { |
| 2957 | Tmp4 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2958 | if (Tmp4.getNode()) Result = Tmp4; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2959 | } |
| 2960 | break; |
| 2961 | case TargetLowering::Promote: { |
| 2962 | // First step, figure out the appropriate operation to use. |
| 2963 | // Allow SETCC to not be supported for all legal data types |
| 2964 | // Mostly this targets FP |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2965 | MVT NewInTy = Node->getOperand(0).getValueType(); |
| 2966 | MVT OldVT = NewInTy; OldVT = OldVT; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2967 | |
| 2968 | // Scan for the appropriate larger type to use. |
| 2969 | while (1) { |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2970 | NewInTy = (MVT::SimpleValueType)(NewInTy.getSimpleVT()+1); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2971 | |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2972 | assert(NewInTy.isInteger() == OldVT.isInteger() && |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2973 | "Fell off of the edge of the integer world"); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2974 | assert(NewInTy.isFloatingPoint() == OldVT.isFloatingPoint() && |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2975 | "Fell off of the edge of the floating point world"); |
| 2976 | |
| 2977 | // If the target supports SETCC of this type, use it. |
| 2978 | if (TLI.isOperationLegal(ISD::SETCC, NewInTy)) |
| 2979 | break; |
| 2980 | } |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2981 | if (NewInTy.isInteger()) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2982 | assert(0 && "Cannot promote Legal Integer SETCC yet"); |
| 2983 | else { |
| 2984 | Tmp1 = DAG.getNode(ISD::FP_EXTEND, NewInTy, Tmp1); |
| 2985 | Tmp2 = DAG.getNode(ISD::FP_EXTEND, NewInTy, Tmp2); |
| 2986 | } |
| 2987 | Tmp1 = LegalizeOp(Tmp1); |
| 2988 | Tmp2 = LegalizeOp(Tmp2); |
| 2989 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
| 2990 | Result = LegalizeOp(Result); |
| 2991 | break; |
| 2992 | } |
| 2993 | case TargetLowering::Expand: |
| 2994 | // Expand a setcc node into a select_cc of the same condition, lhs, and |
| 2995 | // rhs that selects between const 1 (true) and const 0 (false). |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2996 | MVT VT = Node->getValueType(0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2997 | Result = DAG.getNode(ISD::SELECT_CC, VT, Tmp1, Tmp2, |
| 2998 | DAG.getConstant(1, VT), DAG.getConstant(0, VT), |
| 2999 | Tmp3); |
| 3000 | break; |
| 3001 | } |
| 3002 | break; |
Nate Begeman | 9a1ce15 | 2008-05-12 19:40:03 +0000 | [diff] [blame] | 3003 | case ISD::VSETCC: { |
| 3004 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
| 3005 | Tmp2 = LegalizeOp(Node->getOperand(1)); // RHS |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3006 | SDValue CC = Node->getOperand(2); |
Nate Begeman | 9a1ce15 | 2008-05-12 19:40:03 +0000 | [diff] [blame] | 3007 | |
| 3008 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, CC); |
| 3009 | |
| 3010 | // Everything is legal, see if we should expand this op or something. |
| 3011 | switch (TLI.getOperationAction(ISD::VSETCC, Tmp1.getValueType())) { |
| 3012 | default: assert(0 && "This action is not supported yet!"); |
| 3013 | case TargetLowering::Legal: break; |
| 3014 | case TargetLowering::Custom: |
| 3015 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3016 | if (Tmp1.getNode()) Result = Tmp1; |
Nate Begeman | 9a1ce15 | 2008-05-12 19:40:03 +0000 | [diff] [blame] | 3017 | break; |
| 3018 | } |
| 3019 | break; |
| 3020 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3021 | |
| 3022 | case ISD::SHL_PARTS: |
| 3023 | case ISD::SRA_PARTS: |
| 3024 | case ISD::SRL_PARTS: { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3025 | SmallVector<SDValue, 8> Ops; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3026 | bool Changed = false; |
| 3027 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) { |
| 3028 | Ops.push_back(LegalizeOp(Node->getOperand(i))); |
| 3029 | Changed |= Ops.back() != Node->getOperand(i); |
| 3030 | } |
| 3031 | if (Changed) |
| 3032 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
| 3033 | |
| 3034 | switch (TLI.getOperationAction(Node->getOpcode(), |
| 3035 | Node->getValueType(0))) { |
| 3036 | default: assert(0 && "This action is not supported yet!"); |
| 3037 | case TargetLowering::Legal: break; |
| 3038 | case TargetLowering::Custom: |
| 3039 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3040 | if (Tmp1.getNode()) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3041 | SDValue Tmp2, RetVal(0, 0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3042 | for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) { |
| 3043 | Tmp2 = LegalizeOp(Tmp1.getValue(i)); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3044 | AddLegalizedOperand(SDValue(Node, i), Tmp2); |
Gabor Greif | 46bf547 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 3045 | if (i == Op.getResNo()) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3046 | RetVal = Tmp2; |
| 3047 | } |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3048 | assert(RetVal.getNode() && "Illegal result number"); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3049 | return RetVal; |
| 3050 | } |
| 3051 | break; |
| 3052 | } |
| 3053 | |
| 3054 | // Since these produce multiple values, make sure to remember that we |
| 3055 | // legalized all of them. |
| 3056 | for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3057 | AddLegalizedOperand(SDValue(Node, i), Result.getValue(i)); |
Gabor Greif | 46bf547 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 3058 | return Result.getValue(Op.getResNo()); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3059 | } |
| 3060 | |
| 3061 | // Binary operators |
| 3062 | case ISD::ADD: |
| 3063 | case ISD::SUB: |
| 3064 | case ISD::MUL: |
| 3065 | case ISD::MULHS: |
| 3066 | case ISD::MULHU: |
| 3067 | case ISD::UDIV: |
| 3068 | case ISD::SDIV: |
| 3069 | case ISD::AND: |
| 3070 | case ISD::OR: |
| 3071 | case ISD::XOR: |
| 3072 | case ISD::SHL: |
| 3073 | case ISD::SRL: |
| 3074 | case ISD::SRA: |
| 3075 | case ISD::FADD: |
| 3076 | case ISD::FSUB: |
| 3077 | case ISD::FMUL: |
| 3078 | case ISD::FDIV: |
Dan Gohman | 6d05cac | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3079 | case ISD::FPOW: |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3080 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
| 3081 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 3082 | case Expand: assert(0 && "Not possible"); |
| 3083 | case Legal: |
| 3084 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the RHS. |
| 3085 | break; |
| 3086 | case Promote: |
| 3087 | Tmp2 = PromoteOp(Node->getOperand(1)); // Promote the RHS. |
| 3088 | break; |
| 3089 | } |
Nate Begeman | bb1ce94 | 2008-07-29 15:49:41 +0000 | [diff] [blame] | 3090 | |
| 3091 | if ((Node->getOpcode() == ISD::SHL || |
| 3092 | Node->getOpcode() == ISD::SRL || |
| 3093 | Node->getOpcode() == ISD::SRA) && |
| 3094 | !Node->getValueType(0).isVector()) { |
| 3095 | if (TLI.getShiftAmountTy().bitsLT(Tmp2.getValueType())) |
| 3096 | Tmp2 = DAG.getNode(ISD::TRUNCATE, TLI.getShiftAmountTy(), Tmp2); |
| 3097 | else if (TLI.getShiftAmountTy().bitsGT(Tmp2.getValueType())) |
| 3098 | Tmp2 = DAG.getNode(ISD::ANY_EXTEND, TLI.getShiftAmountTy(), Tmp2); |
| 3099 | } |
| 3100 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3101 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Mon P Wang | bff5d9c | 2008-11-10 04:46:22 +0000 | [diff] [blame] | 3102 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3103 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 3104 | default: assert(0 && "BinOp legalize operation not supported"); |
| 3105 | case TargetLowering::Legal: break; |
| 3106 | case TargetLowering::Custom: |
| 3107 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3108 | if (Tmp1.getNode()) { |
Nate Begeman | bb1ce94 | 2008-07-29 15:49:41 +0000 | [diff] [blame] | 3109 | Result = Tmp1; |
| 3110 | break; |
Nate Begeman | 7569e76 | 2008-07-29 19:07:27 +0000 | [diff] [blame] | 3111 | } |
Nate Begeman | bb1ce94 | 2008-07-29 15:49:41 +0000 | [diff] [blame] | 3112 | // Fall through if the custom lower can't deal with the operation |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3113 | case TargetLowering::Expand: { |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3114 | MVT VT = Op.getValueType(); |
Mon P Wang | 1448aad | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 3115 | |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3116 | // See if multiply or divide can be lowered using two-result operations. |
| 3117 | SDVTList VTs = DAG.getVTList(VT, VT); |
| 3118 | if (Node->getOpcode() == ISD::MUL) { |
| 3119 | // We just need the low half of the multiply; try both the signed |
| 3120 | // and unsigned forms. If the target supports both SMUL_LOHI and |
| 3121 | // UMUL_LOHI, form a preference by checking which forms of plain |
| 3122 | // MULH it supports. |
| 3123 | bool HasSMUL_LOHI = TLI.isOperationLegal(ISD::SMUL_LOHI, VT); |
| 3124 | bool HasUMUL_LOHI = TLI.isOperationLegal(ISD::UMUL_LOHI, VT); |
| 3125 | bool HasMULHS = TLI.isOperationLegal(ISD::MULHS, VT); |
| 3126 | bool HasMULHU = TLI.isOperationLegal(ISD::MULHU, VT); |
| 3127 | unsigned OpToUse = 0; |
| 3128 | if (HasSMUL_LOHI && !HasMULHS) { |
| 3129 | OpToUse = ISD::SMUL_LOHI; |
| 3130 | } else if (HasUMUL_LOHI && !HasMULHU) { |
| 3131 | OpToUse = ISD::UMUL_LOHI; |
| 3132 | } else if (HasSMUL_LOHI) { |
| 3133 | OpToUse = ISD::SMUL_LOHI; |
| 3134 | } else if (HasUMUL_LOHI) { |
| 3135 | OpToUse = ISD::UMUL_LOHI; |
| 3136 | } |
| 3137 | if (OpToUse) { |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3138 | Result = SDValue(DAG.getNode(OpToUse, VTs, Tmp1, Tmp2).getNode(), 0); |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3139 | break; |
| 3140 | } |
| 3141 | } |
| 3142 | if (Node->getOpcode() == ISD::MULHS && |
| 3143 | TLI.isOperationLegal(ISD::SMUL_LOHI, VT)) { |
Chris Lattner | 4818865 | 2008-10-04 21:27:46 +0000 | [diff] [blame] | 3144 | Result = SDValue(DAG.getNode(ISD::SMUL_LOHI, VTs, Tmp1, Tmp2).getNode(), |
| 3145 | 1); |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3146 | break; |
| 3147 | } |
| 3148 | if (Node->getOpcode() == ISD::MULHU && |
| 3149 | TLI.isOperationLegal(ISD::UMUL_LOHI, VT)) { |
Chris Lattner | 4818865 | 2008-10-04 21:27:46 +0000 | [diff] [blame] | 3150 | Result = SDValue(DAG.getNode(ISD::UMUL_LOHI, VTs, Tmp1, Tmp2).getNode(), |
| 3151 | 1); |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3152 | break; |
| 3153 | } |
| 3154 | if (Node->getOpcode() == ISD::SDIV && |
| 3155 | TLI.isOperationLegal(ISD::SDIVREM, VT)) { |
Chris Lattner | 4818865 | 2008-10-04 21:27:46 +0000 | [diff] [blame] | 3156 | Result = SDValue(DAG.getNode(ISD::SDIVREM, VTs, Tmp1, Tmp2).getNode(), |
| 3157 | 0); |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3158 | break; |
| 3159 | } |
| 3160 | if (Node->getOpcode() == ISD::UDIV && |
| 3161 | TLI.isOperationLegal(ISD::UDIVREM, VT)) { |
Chris Lattner | 4818865 | 2008-10-04 21:27:46 +0000 | [diff] [blame] | 3162 | Result = SDValue(DAG.getNode(ISD::UDIVREM, VTs, Tmp1, Tmp2).getNode(), |
| 3163 | 0); |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3164 | break; |
| 3165 | } |
Mon P Wang | 1448aad | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 3166 | |
Dan Gohman | 6d05cac | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3167 | // Check to see if we have a libcall for this operator. |
| 3168 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
| 3169 | bool isSigned = false; |
| 3170 | switch (Node->getOpcode()) { |
| 3171 | case ISD::UDIV: |
| 3172 | case ISD::SDIV: |
| 3173 | if (VT == MVT::i32) { |
| 3174 | LC = Node->getOpcode() == ISD::UDIV |
Mon P Wang | 1448aad | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 3175 | ? RTLIB::UDIV_I32 : RTLIB::SDIV_I32; |
Dan Gohman | 6d05cac | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3176 | isSigned = Node->getOpcode() == ISD::SDIV; |
| 3177 | } |
| 3178 | break; |
Chris Lattner | 4818865 | 2008-10-04 21:27:46 +0000 | [diff] [blame] | 3179 | case ISD::MUL: |
| 3180 | if (VT == MVT::i32) |
| 3181 | LC = RTLIB::MUL_I32; |
| 3182 | break; |
Dan Gohman | 6d05cac | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3183 | case ISD::FPOW: |
Duncan Sands | 37a3f47 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 3184 | LC = GetFPLibCall(VT, RTLIB::POW_F32, RTLIB::POW_F64, RTLIB::POW_F80, |
| 3185 | RTLIB::POW_PPCF128); |
Dan Gohman | 6d05cac | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3186 | break; |
| 3187 | default: break; |
| 3188 | } |
| 3189 | if (LC != RTLIB::UNKNOWN_LIBCALL) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3190 | SDValue Dummy; |
Duncan Sands | f1db7c8 | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 3191 | Result = ExpandLibCall(LC, Node, isSigned, Dummy); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3192 | break; |
| 3193 | } |
Mon P Wang | 1448aad | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 3194 | |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3195 | assert(Node->getValueType(0).isVector() && |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3196 | "Cannot expand this binary operator!"); |
| 3197 | // Expand the operation into a bunch of nasty scalar code. |
Dan Gohman | 6d05cac | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3198 | Result = LegalizeOp(UnrollVectorOp(Op)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3199 | break; |
| 3200 | } |
| 3201 | case TargetLowering::Promote: { |
| 3202 | switch (Node->getOpcode()) { |
| 3203 | default: assert(0 && "Do not know how to promote this BinOp!"); |
| 3204 | case ISD::AND: |
| 3205 | case ISD::OR: |
| 3206 | case ISD::XOR: { |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3207 | MVT OVT = Node->getValueType(0); |
| 3208 | MVT NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT); |
| 3209 | assert(OVT.isVector() && "Cannot promote this BinOp!"); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3210 | // Bit convert each of the values to the new type. |
| 3211 | Tmp1 = DAG.getNode(ISD::BIT_CONVERT, NVT, Tmp1); |
| 3212 | Tmp2 = DAG.getNode(ISD::BIT_CONVERT, NVT, Tmp2); |
| 3213 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 3214 | // Bit convert the result back the original type. |
| 3215 | Result = DAG.getNode(ISD::BIT_CONVERT, OVT, Result); |
| 3216 | break; |
| 3217 | } |
| 3218 | } |
| 3219 | } |
| 3220 | } |
| 3221 | break; |
| 3222 | |
Dan Gohman | 475cd73 | 2007-10-05 14:17:22 +0000 | [diff] [blame] | 3223 | case ISD::SMUL_LOHI: |
| 3224 | case ISD::UMUL_LOHI: |
| 3225 | case ISD::SDIVREM: |
| 3226 | case ISD::UDIVREM: |
| 3227 | // These nodes will only be produced by target-specific lowering, so |
| 3228 | // they shouldn't be here if they aren't legal. |
Duncan Sands | b42a44e | 2007-10-16 09:07:20 +0000 | [diff] [blame] | 3229 | assert(TLI.isOperationLegal(Node->getOpcode(), Node->getValueType(0)) && |
Dan Gohman | 475cd73 | 2007-10-05 14:17:22 +0000 | [diff] [blame] | 3230 | "This must be legal!"); |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3231 | |
| 3232 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
| 3233 | Tmp2 = LegalizeOp(Node->getOperand(1)); // RHS |
| 3234 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Dan Gohman | 475cd73 | 2007-10-05 14:17:22 +0000 | [diff] [blame] | 3235 | break; |
| 3236 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3237 | case ISD::FCOPYSIGN: // FCOPYSIGN does not require LHS/RHS to match type! |
| 3238 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
| 3239 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 3240 | case Expand: assert(0 && "Not possible"); |
| 3241 | case Legal: |
| 3242 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the RHS. |
| 3243 | break; |
| 3244 | case Promote: |
| 3245 | Tmp2 = PromoteOp(Node->getOperand(1)); // Promote the RHS. |
| 3246 | break; |
| 3247 | } |
| 3248 | |
| 3249 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 3250 | |
| 3251 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 3252 | default: assert(0 && "Operation not supported"); |
| 3253 | case TargetLowering::Custom: |
| 3254 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3255 | if (Tmp1.getNode()) Result = Tmp1; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3256 | break; |
| 3257 | case TargetLowering::Legal: break; |
| 3258 | case TargetLowering::Expand: { |
| 3259 | // If this target supports fabs/fneg natively and select is cheap, |
| 3260 | // do this efficiently. |
| 3261 | if (!TLI.isSelectExpensive() && |
| 3262 | TLI.getOperationAction(ISD::FABS, Tmp1.getValueType()) == |
| 3263 | TargetLowering::Legal && |
| 3264 | TLI.getOperationAction(ISD::FNEG, Tmp1.getValueType()) == |
| 3265 | TargetLowering::Legal) { |
| 3266 | // Get the sign bit of the RHS. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3267 | MVT IVT = |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3268 | Tmp2.getValueType() == MVT::f32 ? MVT::i32 : MVT::i64; |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3269 | SDValue SignBit = DAG.getNode(ISD::BIT_CONVERT, IVT, Tmp2); |
Scott Michel | 502151f | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 3270 | SignBit = DAG.getSetCC(TLI.getSetCCResultType(SignBit), |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3271 | SignBit, DAG.getConstant(0, IVT), ISD::SETLT); |
| 3272 | // Get the absolute value of the result. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3273 | SDValue AbsVal = DAG.getNode(ISD::FABS, Tmp1.getValueType(), Tmp1); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3274 | // Select between the nabs and abs value based on the sign bit of |
| 3275 | // the input. |
| 3276 | Result = DAG.getNode(ISD::SELECT, AbsVal.getValueType(), SignBit, |
| 3277 | DAG.getNode(ISD::FNEG, AbsVal.getValueType(), |
| 3278 | AbsVal), |
| 3279 | AbsVal); |
| 3280 | Result = LegalizeOp(Result); |
| 3281 | break; |
| 3282 | } |
| 3283 | |
| 3284 | // Otherwise, do bitwise ops! |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3285 | MVT NVT = |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3286 | Node->getValueType(0) == MVT::f32 ? MVT::i32 : MVT::i64; |
| 3287 | Result = ExpandFCOPYSIGNToBitwiseOps(Node, NVT, DAG, TLI); |
| 3288 | Result = DAG.getNode(ISD::BIT_CONVERT, Node->getValueType(0), Result); |
| 3289 | Result = LegalizeOp(Result); |
| 3290 | break; |
| 3291 | } |
| 3292 | } |
| 3293 | break; |
| 3294 | |
| 3295 | case ISD::ADDC: |
| 3296 | case ISD::SUBC: |
| 3297 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 3298 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 3299 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 3300 | // Since this produces two values, make sure to remember that we legalized |
| 3301 | // both of them. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3302 | AddLegalizedOperand(SDValue(Node, 0), Result.getValue(0)); |
| 3303 | AddLegalizedOperand(SDValue(Node, 1), Result.getValue(1)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3304 | return Result; |
| 3305 | |
| 3306 | case ISD::ADDE: |
| 3307 | case ISD::SUBE: |
| 3308 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 3309 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 3310 | Tmp3 = LegalizeOp(Node->getOperand(2)); |
| 3311 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
| 3312 | // Since this produces two values, make sure to remember that we legalized |
| 3313 | // both of them. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3314 | AddLegalizedOperand(SDValue(Node, 0), Result.getValue(0)); |
| 3315 | AddLegalizedOperand(SDValue(Node, 1), Result.getValue(1)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3316 | return Result; |
| 3317 | |
| 3318 | case ISD::BUILD_PAIR: { |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3319 | MVT PairTy = Node->getValueType(0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3320 | // TODO: handle the case where the Lo and Hi operands are not of legal type |
| 3321 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Lo |
| 3322 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Hi |
| 3323 | switch (TLI.getOperationAction(ISD::BUILD_PAIR, PairTy)) { |
| 3324 | case TargetLowering::Promote: |
| 3325 | case TargetLowering::Custom: |
| 3326 | assert(0 && "Cannot promote/custom this yet!"); |
| 3327 | case TargetLowering::Legal: |
| 3328 | if (Tmp1 != Node->getOperand(0) || Tmp2 != Node->getOperand(1)) |
| 3329 | Result = DAG.getNode(ISD::BUILD_PAIR, PairTy, Tmp1, Tmp2); |
| 3330 | break; |
| 3331 | case TargetLowering::Expand: |
| 3332 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, PairTy, Tmp1); |
| 3333 | Tmp2 = DAG.getNode(ISD::ANY_EXTEND, PairTy, Tmp2); |
| 3334 | Tmp2 = DAG.getNode(ISD::SHL, PairTy, Tmp2, |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3335 | DAG.getConstant(PairTy.getSizeInBits()/2, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3336 | TLI.getShiftAmountTy())); |
| 3337 | Result = DAG.getNode(ISD::OR, PairTy, Tmp1, Tmp2); |
| 3338 | break; |
| 3339 | } |
| 3340 | break; |
| 3341 | } |
| 3342 | |
| 3343 | case ISD::UREM: |
| 3344 | case ISD::SREM: |
| 3345 | case ISD::FREM: |
| 3346 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
| 3347 | Tmp2 = LegalizeOp(Node->getOperand(1)); // RHS |
| 3348 | |
| 3349 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 3350 | case TargetLowering::Promote: assert(0 && "Cannot promote this yet!"); |
| 3351 | case TargetLowering::Custom: |
| 3352 | isCustom = true; |
| 3353 | // FALLTHROUGH |
| 3354 | case TargetLowering::Legal: |
| 3355 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 3356 | if (isCustom) { |
| 3357 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3358 | if (Tmp1.getNode()) Result = Tmp1; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3359 | } |
| 3360 | break; |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3361 | case TargetLowering::Expand: { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3362 | unsigned DivOpc= (Node->getOpcode() == ISD::UREM) ? ISD::UDIV : ISD::SDIV; |
| 3363 | bool isSigned = DivOpc == ISD::SDIV; |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3364 | MVT VT = Node->getValueType(0); |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3365 | |
| 3366 | // See if remainder can be lowered using two-result operations. |
| 3367 | SDVTList VTs = DAG.getVTList(VT, VT); |
| 3368 | if (Node->getOpcode() == ISD::SREM && |
| 3369 | TLI.isOperationLegal(ISD::SDIVREM, VT)) { |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3370 | Result = SDValue(DAG.getNode(ISD::SDIVREM, VTs, Tmp1, Tmp2).getNode(), 1); |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3371 | break; |
| 3372 | } |
| 3373 | if (Node->getOpcode() == ISD::UREM && |
| 3374 | TLI.isOperationLegal(ISD::UDIVREM, VT)) { |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3375 | Result = SDValue(DAG.getNode(ISD::UDIVREM, VTs, Tmp1, Tmp2).getNode(), 1); |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3376 | break; |
| 3377 | } |
| 3378 | |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3379 | if (VT.isInteger()) { |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3380 | if (TLI.getOperationAction(DivOpc, VT) == |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3381 | TargetLowering::Legal) { |
| 3382 | // X % Y -> X-X/Y*Y |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3383 | Result = DAG.getNode(DivOpc, VT, Tmp1, Tmp2); |
| 3384 | Result = DAG.getNode(ISD::MUL, VT, Result, Tmp2); |
| 3385 | Result = DAG.getNode(ISD::SUB, VT, Tmp1, Result); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3386 | } else if (VT.isVector()) { |
Dan Gohman | 3e3fd8c | 2007-11-05 23:35:22 +0000 | [diff] [blame] | 3387 | Result = LegalizeOp(UnrollVectorOp(Op)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3388 | } else { |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3389 | assert(VT == MVT::i32 && |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3390 | "Cannot expand this binary operator!"); |
| 3391 | RTLIB::Libcall LC = Node->getOpcode() == ISD::UREM |
| 3392 | ? RTLIB::UREM_I32 : RTLIB::SREM_I32; |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3393 | SDValue Dummy; |
Duncan Sands | f1db7c8 | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 3394 | Result = ExpandLibCall(LC, Node, isSigned, Dummy); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3395 | } |
Dan Gohman | 59b4b10 | 2007-11-06 22:11:54 +0000 | [diff] [blame] | 3396 | } else { |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3397 | assert(VT.isFloatingPoint() && |
Dan Gohman | 59b4b10 | 2007-11-06 22:11:54 +0000 | [diff] [blame] | 3398 | "remainder op must have integer or floating-point type"); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3399 | if (VT.isVector()) { |
Dan Gohman | 3e3fd8c | 2007-11-05 23:35:22 +0000 | [diff] [blame] | 3400 | Result = LegalizeOp(UnrollVectorOp(Op)); |
| 3401 | } else { |
| 3402 | // Floating point mod -> fmod libcall. |
Duncan Sands | 37a3f47 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 3403 | RTLIB::Libcall LC = GetFPLibCall(VT, RTLIB::REM_F32, RTLIB::REM_F64, |
| 3404 | RTLIB::REM_F80, RTLIB::REM_PPCF128); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3405 | SDValue Dummy; |
Duncan Sands | f1db7c8 | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 3406 | Result = ExpandLibCall(LC, Node, false/*sign irrelevant*/, Dummy); |
Dan Gohman | 3e3fd8c | 2007-11-05 23:35:22 +0000 | [diff] [blame] | 3407 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3408 | } |
| 3409 | break; |
| 3410 | } |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3411 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3412 | break; |
| 3413 | case ISD::VAARG: { |
| 3414 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 3415 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. |
| 3416 | |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3417 | MVT VT = Node->getValueType(0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3418 | switch (TLI.getOperationAction(Node->getOpcode(), MVT::Other)) { |
| 3419 | default: assert(0 && "This action is not supported yet!"); |
| 3420 | case TargetLowering::Custom: |
| 3421 | isCustom = true; |
| 3422 | // FALLTHROUGH |
| 3423 | case TargetLowering::Legal: |
| 3424 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
| 3425 | Result = Result.getValue(0); |
| 3426 | Tmp1 = Result.getValue(1); |
| 3427 | |
| 3428 | if (isCustom) { |
| 3429 | Tmp2 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3430 | if (Tmp2.getNode()) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3431 | Result = LegalizeOp(Tmp2); |
| 3432 | Tmp1 = LegalizeOp(Tmp2.getValue(1)); |
| 3433 | } |
| 3434 | } |
| 3435 | break; |
| 3436 | case TargetLowering::Expand: { |
Dan Gohman | 12a9c08 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 3437 | const Value *V = cast<SrcValueSDNode>(Node->getOperand(2))->getValue(); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3438 | SDValue VAList = DAG.getLoad(TLI.getPointerTy(), Tmp1, Tmp2, V, 0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3439 | // Increment the pointer, VAList, to the next vaarg |
Duncan Sands | 55a4c23 | 2008-11-03 11:51:11 +0000 | [diff] [blame] | 3440 | Tmp3 = DAG.getNode(ISD::ADD, TLI.getPointerTy(), VAList, |
| 3441 | DAG.getConstant(TLI.getTargetData()->getABITypeSize(VT.getTypeForMVT()), |
| 3442 | TLI.getPointerTy())); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3443 | // Store the incremented VAList to the legalized pointer |
Dan Gohman | 12a9c08 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 3444 | Tmp3 = DAG.getStore(VAList.getValue(1), Tmp3, Tmp2, V, 0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3445 | // Load the actual argument out of the pointer VAList |
| 3446 | Result = DAG.getLoad(VT, Tmp3, VAList, NULL, 0); |
| 3447 | Tmp1 = LegalizeOp(Result.getValue(1)); |
| 3448 | Result = LegalizeOp(Result); |
| 3449 | break; |
| 3450 | } |
| 3451 | } |
| 3452 | // Since VAARG produces two values, make sure to remember that we |
| 3453 | // legalized both of them. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3454 | AddLegalizedOperand(SDValue(Node, 0), Result); |
| 3455 | AddLegalizedOperand(SDValue(Node, 1), Tmp1); |
Gabor Greif | 46bf547 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 3456 | return Op.getResNo() ? Tmp1 : Result; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3457 | } |
| 3458 | |
| 3459 | case ISD::VACOPY: |
| 3460 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 3461 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the dest pointer. |
| 3462 | Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the source pointer. |
| 3463 | |
| 3464 | switch (TLI.getOperationAction(ISD::VACOPY, MVT::Other)) { |
| 3465 | default: assert(0 && "This action is not supported yet!"); |
| 3466 | case TargetLowering::Custom: |
| 3467 | isCustom = true; |
| 3468 | // FALLTHROUGH |
| 3469 | case TargetLowering::Legal: |
| 3470 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3, |
| 3471 | Node->getOperand(3), Node->getOperand(4)); |
| 3472 | if (isCustom) { |
| 3473 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3474 | if (Tmp1.getNode()) Result = Tmp1; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3475 | } |
| 3476 | break; |
| 3477 | case TargetLowering::Expand: |
| 3478 | // This defaults to loading a pointer from the input and storing it to the |
| 3479 | // output, returning the chain. |
Dan Gohman | 12a9c08 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 3480 | const Value *VD = cast<SrcValueSDNode>(Node->getOperand(3))->getValue(); |
| 3481 | const Value *VS = cast<SrcValueSDNode>(Node->getOperand(4))->getValue(); |
Dan Gohman | 6b9a08e | 2008-04-17 02:09:26 +0000 | [diff] [blame] | 3482 | Tmp4 = DAG.getLoad(TLI.getPointerTy(), Tmp1, Tmp3, VS, 0); |
| 3483 | Result = DAG.getStore(Tmp4.getValue(1), Tmp4, Tmp2, VD, 0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3484 | break; |
| 3485 | } |
| 3486 | break; |
| 3487 | |
| 3488 | case ISD::VAEND: |
| 3489 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 3490 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. |
| 3491 | |
| 3492 | switch (TLI.getOperationAction(ISD::VAEND, MVT::Other)) { |
| 3493 | default: assert(0 && "This action is not supported yet!"); |
| 3494 | case TargetLowering::Custom: |
| 3495 | isCustom = true; |
| 3496 | // FALLTHROUGH |
| 3497 | case TargetLowering::Legal: |
| 3498 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
| 3499 | if (isCustom) { |
| 3500 | Tmp1 = TLI.LowerOperation(Tmp1, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3501 | if (Tmp1.getNode()) Result = Tmp1; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3502 | } |
| 3503 | break; |
| 3504 | case TargetLowering::Expand: |
| 3505 | Result = Tmp1; // Default to a no-op, return the chain |
| 3506 | break; |
| 3507 | } |
| 3508 | break; |
| 3509 | |
| 3510 | case ISD::VASTART: |
| 3511 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 3512 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. |
| 3513 | |
| 3514 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
| 3515 | |
| 3516 | switch (TLI.getOperationAction(ISD::VASTART, MVT::Other)) { |
| 3517 | default: assert(0 && "This action is not supported yet!"); |
| 3518 | case TargetLowering::Legal: break; |
| 3519 | case TargetLowering::Custom: |
| 3520 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3521 | if (Tmp1.getNode()) Result = Tmp1; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3522 | break; |
| 3523 | } |
| 3524 | break; |
| 3525 | |
| 3526 | case ISD::ROTL: |
| 3527 | case ISD::ROTR: |
| 3528 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
| 3529 | Tmp2 = LegalizeOp(Node->getOperand(1)); // RHS |
| 3530 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 3531 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 3532 | default: |
| 3533 | assert(0 && "ROTL/ROTR legalize operation not supported"); |
| 3534 | break; |
| 3535 | case TargetLowering::Legal: |
| 3536 | break; |
| 3537 | case TargetLowering::Custom: |
| 3538 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3539 | if (Tmp1.getNode()) Result = Tmp1; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3540 | break; |
| 3541 | case TargetLowering::Promote: |
| 3542 | assert(0 && "Do not know how to promote ROTL/ROTR"); |
| 3543 | break; |
| 3544 | case TargetLowering::Expand: |
| 3545 | assert(0 && "Do not know how to expand ROTL/ROTR"); |
| 3546 | break; |
| 3547 | } |
| 3548 | break; |
| 3549 | |
| 3550 | case ISD::BSWAP: |
| 3551 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Op |
| 3552 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 3553 | case TargetLowering::Custom: |
| 3554 | assert(0 && "Cannot custom legalize this yet!"); |
| 3555 | case TargetLowering::Legal: |
| 3556 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 3557 | break; |
| 3558 | case TargetLowering::Promote: { |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3559 | MVT OVT = Tmp1.getValueType(); |
| 3560 | MVT NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT); |
| 3561 | unsigned DiffBits = NVT.getSizeInBits() - OVT.getSizeInBits(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3562 | |
| 3563 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Tmp1); |
| 3564 | Tmp1 = DAG.getNode(ISD::BSWAP, NVT, Tmp1); |
| 3565 | Result = DAG.getNode(ISD::SRL, NVT, Tmp1, |
| 3566 | DAG.getConstant(DiffBits, TLI.getShiftAmountTy())); |
| 3567 | break; |
| 3568 | } |
| 3569 | case TargetLowering::Expand: |
| 3570 | Result = ExpandBSWAP(Tmp1); |
| 3571 | break; |
| 3572 | } |
| 3573 | break; |
| 3574 | |
| 3575 | case ISD::CTPOP: |
| 3576 | case ISD::CTTZ: |
| 3577 | case ISD::CTLZ: |
| 3578 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Op |
| 3579 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
Scott Michel | 48b63e6 | 2007-07-30 21:00:31 +0000 | [diff] [blame] | 3580 | case TargetLowering::Custom: |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3581 | case TargetLowering::Legal: |
| 3582 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Scott Michel | 48b63e6 | 2007-07-30 21:00:31 +0000 | [diff] [blame] | 3583 | if (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0)) == |
Scott Michel | bc62b41 | 2007-08-02 02:22:46 +0000 | [diff] [blame] | 3584 | TargetLowering::Custom) { |
| 3585 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3586 | if (Tmp1.getNode()) { |
Scott Michel | bc62b41 | 2007-08-02 02:22:46 +0000 | [diff] [blame] | 3587 | Result = Tmp1; |
| 3588 | } |
Scott Michel | 48b63e6 | 2007-07-30 21:00:31 +0000 | [diff] [blame] | 3589 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3590 | break; |
| 3591 | case TargetLowering::Promote: { |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3592 | MVT OVT = Tmp1.getValueType(); |
| 3593 | MVT NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3594 | |
| 3595 | // Zero extend the argument. |
| 3596 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Tmp1); |
| 3597 | // Perform the larger operation, then subtract if needed. |
| 3598 | Tmp1 = DAG.getNode(Node->getOpcode(), Node->getValueType(0), Tmp1); |
| 3599 | switch (Node->getOpcode()) { |
| 3600 | case ISD::CTPOP: |
| 3601 | Result = Tmp1; |
| 3602 | break; |
| 3603 | case ISD::CTTZ: |
| 3604 | //if Tmp1 == sizeinbits(NVT) then Tmp1 = sizeinbits(Old VT) |
Scott Michel | 502151f | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 3605 | Tmp2 = DAG.getSetCC(TLI.getSetCCResultType(Tmp1), Tmp1, |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3606 | DAG.getConstant(NVT.getSizeInBits(), NVT), |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3607 | ISD::SETEQ); |
| 3608 | Result = DAG.getNode(ISD::SELECT, NVT, Tmp2, |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3609 | DAG.getConstant(OVT.getSizeInBits(), NVT), Tmp1); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3610 | break; |
| 3611 | case ISD::CTLZ: |
| 3612 | // Tmp1 = Tmp1 - (sizeinbits(NVT) - sizeinbits(Old VT)) |
| 3613 | Result = DAG.getNode(ISD::SUB, NVT, Tmp1, |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3614 | DAG.getConstant(NVT.getSizeInBits() - |
| 3615 | OVT.getSizeInBits(), NVT)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3616 | break; |
| 3617 | } |
| 3618 | break; |
| 3619 | } |
| 3620 | case TargetLowering::Expand: |
| 3621 | Result = ExpandBitCount(Node->getOpcode(), Tmp1); |
| 3622 | break; |
| 3623 | } |
| 3624 | break; |
| 3625 | |
| 3626 | // Unary operators |
| 3627 | case ISD::FABS: |
| 3628 | case ISD::FNEG: |
| 3629 | case ISD::FSQRT: |
| 3630 | case ISD::FSIN: |
| 3631 | case ISD::FCOS: |
Dale Johannesen | 92b3308 | 2008-09-04 00:47:13 +0000 | [diff] [blame] | 3632 | case ISD::FLOG: |
| 3633 | case ISD::FLOG2: |
| 3634 | case ISD::FLOG10: |
| 3635 | case ISD::FEXP: |
| 3636 | case ISD::FEXP2: |
Dan Gohman | c8b20e2 | 2008-08-21 17:55:02 +0000 | [diff] [blame] | 3637 | case ISD::FTRUNC: |
| 3638 | case ISD::FFLOOR: |
| 3639 | case ISD::FCEIL: |
| 3640 | case ISD::FRINT: |
| 3641 | case ISD::FNEARBYINT: |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3642 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 3643 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 3644 | case TargetLowering::Promote: |
| 3645 | case TargetLowering::Custom: |
| 3646 | isCustom = true; |
| 3647 | // FALLTHROUGH |
| 3648 | case TargetLowering::Legal: |
| 3649 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 3650 | if (isCustom) { |
| 3651 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3652 | if (Tmp1.getNode()) Result = Tmp1; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3653 | } |
| 3654 | break; |
| 3655 | case TargetLowering::Expand: |
| 3656 | switch (Node->getOpcode()) { |
| 3657 | default: assert(0 && "Unreachable!"); |
| 3658 | case ISD::FNEG: |
| 3659 | // Expand Y = FNEG(X) -> Y = SUB -0.0, X |
| 3660 | Tmp2 = DAG.getConstantFP(-0.0, Node->getValueType(0)); |
| 3661 | Result = DAG.getNode(ISD::FSUB, Node->getValueType(0), Tmp2, Tmp1); |
| 3662 | break; |
| 3663 | case ISD::FABS: { |
| 3664 | // Expand Y = FABS(X) -> Y = (X >u 0.0) ? X : fneg(X). |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3665 | MVT VT = Node->getValueType(0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3666 | Tmp2 = DAG.getConstantFP(0.0, VT); |
Scott Michel | 502151f | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 3667 | Tmp2 = DAG.getSetCC(TLI.getSetCCResultType(Tmp1), Tmp1, Tmp2, |
Nate Begeman | 8bb3cb3 | 2008-03-14 00:53:31 +0000 | [diff] [blame] | 3668 | ISD::SETUGT); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3669 | Tmp3 = DAG.getNode(ISD::FNEG, VT, Tmp1); |
| 3670 | Result = DAG.getNode(ISD::SELECT, VT, Tmp2, Tmp1, Tmp3); |
| 3671 | break; |
| 3672 | } |
Evan Cheng | 1fac695 | 2008-09-09 23:35:53 +0000 | [diff] [blame] | 3673 | case ISD::FSQRT: |
| 3674 | case ISD::FSIN: |
| 3675 | case ISD::FCOS: |
Dale Johannesen | 92b3308 | 2008-09-04 00:47:13 +0000 | [diff] [blame] | 3676 | case ISD::FLOG: |
| 3677 | case ISD::FLOG2: |
| 3678 | case ISD::FLOG10: |
| 3679 | case ISD::FEXP: |
| 3680 | case ISD::FEXP2: |
Dan Gohman | b215823 | 2008-08-21 18:38:14 +0000 | [diff] [blame] | 3681 | case ISD::FTRUNC: |
| 3682 | case ISD::FFLOOR: |
| 3683 | case ISD::FCEIL: |
| 3684 | case ISD::FRINT: |
Evan Cheng | 1fac695 | 2008-09-09 23:35:53 +0000 | [diff] [blame] | 3685 | case ISD::FNEARBYINT: { |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3686 | MVT VT = Node->getValueType(0); |
Dan Gohman | 6d05cac | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3687 | |
| 3688 | // Expand unsupported unary vector operators by unrolling them. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3689 | if (VT.isVector()) { |
Dan Gohman | 6d05cac | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3690 | Result = LegalizeOp(UnrollVectorOp(Op)); |
| 3691 | break; |
| 3692 | } |
| 3693 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3694 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
| 3695 | switch(Node->getOpcode()) { |
| 3696 | case ISD::FSQRT: |
Duncan Sands | 37a3f47 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 3697 | LC = GetFPLibCall(VT, RTLIB::SQRT_F32, RTLIB::SQRT_F64, |
| 3698 | RTLIB::SQRT_F80, RTLIB::SQRT_PPCF128); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3699 | break; |
| 3700 | case ISD::FSIN: |
Duncan Sands | 37a3f47 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 3701 | LC = GetFPLibCall(VT, RTLIB::SIN_F32, RTLIB::SIN_F64, |
| 3702 | RTLIB::SIN_F80, RTLIB::SIN_PPCF128); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3703 | break; |
| 3704 | case ISD::FCOS: |
Duncan Sands | 37a3f47 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 3705 | LC = GetFPLibCall(VT, RTLIB::COS_F32, RTLIB::COS_F64, |
| 3706 | RTLIB::COS_F80, RTLIB::COS_PPCF128); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3707 | break; |
Dale Johannesen | 92b3308 | 2008-09-04 00:47:13 +0000 | [diff] [blame] | 3708 | case ISD::FLOG: |
| 3709 | LC = GetFPLibCall(VT, RTLIB::LOG_F32, RTLIB::LOG_F64, |
| 3710 | RTLIB::LOG_F80, RTLIB::LOG_PPCF128); |
| 3711 | break; |
| 3712 | case ISD::FLOG2: |
| 3713 | LC = GetFPLibCall(VT, RTLIB::LOG2_F32, RTLIB::LOG2_F64, |
| 3714 | RTLIB::LOG2_F80, RTLIB::LOG2_PPCF128); |
| 3715 | break; |
| 3716 | case ISD::FLOG10: |
| 3717 | LC = GetFPLibCall(VT, RTLIB::LOG10_F32, RTLIB::LOG10_F64, |
| 3718 | RTLIB::LOG10_F80, RTLIB::LOG10_PPCF128); |
| 3719 | break; |
| 3720 | case ISD::FEXP: |
| 3721 | LC = GetFPLibCall(VT, RTLIB::EXP_F32, RTLIB::EXP_F64, |
| 3722 | RTLIB::EXP_F80, RTLIB::EXP_PPCF128); |
| 3723 | break; |
| 3724 | case ISD::FEXP2: |
| 3725 | LC = GetFPLibCall(VT, RTLIB::EXP2_F32, RTLIB::EXP2_F64, |
| 3726 | RTLIB::EXP2_F80, RTLIB::EXP2_PPCF128); |
| 3727 | break; |
Dan Gohman | b215823 | 2008-08-21 18:38:14 +0000 | [diff] [blame] | 3728 | case ISD::FTRUNC: |
| 3729 | LC = GetFPLibCall(VT, RTLIB::TRUNC_F32, RTLIB::TRUNC_F64, |
| 3730 | RTLIB::TRUNC_F80, RTLIB::TRUNC_PPCF128); |
| 3731 | break; |
| 3732 | case ISD::FFLOOR: |
| 3733 | LC = GetFPLibCall(VT, RTLIB::FLOOR_F32, RTLIB::FLOOR_F64, |
| 3734 | RTLIB::FLOOR_F80, RTLIB::FLOOR_PPCF128); |
| 3735 | break; |
| 3736 | case ISD::FCEIL: |
| 3737 | LC = GetFPLibCall(VT, RTLIB::CEIL_F32, RTLIB::CEIL_F64, |
| 3738 | RTLIB::CEIL_F80, RTLIB::CEIL_PPCF128); |
| 3739 | break; |
| 3740 | case ISD::FRINT: |
| 3741 | LC = GetFPLibCall(VT, RTLIB::RINT_F32, RTLIB::RINT_F64, |
| 3742 | RTLIB::RINT_F80, RTLIB::RINT_PPCF128); |
| 3743 | break; |
| 3744 | case ISD::FNEARBYINT: |
| 3745 | LC = GetFPLibCall(VT, RTLIB::NEARBYINT_F32, RTLIB::NEARBYINT_F64, |
| 3746 | RTLIB::NEARBYINT_F80, RTLIB::NEARBYINT_PPCF128); |
| 3747 | break; |
Evan Cheng | 1fac695 | 2008-09-09 23:35:53 +0000 | [diff] [blame] | 3748 | break; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3749 | default: assert(0 && "Unreachable!"); |
| 3750 | } |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3751 | SDValue Dummy; |
Duncan Sands | f1db7c8 | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 3752 | Result = ExpandLibCall(LC, Node, false/*sign irrelevant*/, Dummy); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3753 | break; |
| 3754 | } |
| 3755 | } |
| 3756 | break; |
| 3757 | } |
| 3758 | break; |
| 3759 | case ISD::FPOWI: { |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3760 | MVT VT = Node->getValueType(0); |
Dan Gohman | 6d05cac | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3761 | |
| 3762 | // Expand unsupported unary vector operators by unrolling them. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3763 | if (VT.isVector()) { |
Dan Gohman | 6d05cac | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3764 | Result = LegalizeOp(UnrollVectorOp(Op)); |
| 3765 | break; |
| 3766 | } |
| 3767 | |
| 3768 | // We always lower FPOWI into a libcall. No target support for it yet. |
Duncan Sands | 37a3f47 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 3769 | RTLIB::Libcall LC = GetFPLibCall(VT, RTLIB::POWI_F32, RTLIB::POWI_F64, |
| 3770 | RTLIB::POWI_F80, RTLIB::POWI_PPCF128); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3771 | SDValue Dummy; |
Duncan Sands | f1db7c8 | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 3772 | Result = ExpandLibCall(LC, Node, false/*sign irrelevant*/, Dummy); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3773 | break; |
| 3774 | } |
| 3775 | case ISD::BIT_CONVERT: |
| 3776 | if (!isTypeLegal(Node->getOperand(0).getValueType())) { |
Chris Lattner | b7d0aaa | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 3777 | Result = EmitStackConvert(Node->getOperand(0), Node->getValueType(0), |
| 3778 | Node->getValueType(0)); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3779 | } else if (Op.getOperand(0).getValueType().isVector()) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3780 | // The input has to be a vector type, we have to either scalarize it, pack |
| 3781 | // it, or convert it based on whether the input vector type is legal. |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3782 | SDNode *InVal = Node->getOperand(0).getNode(); |
Gabor Greif | 46bf547 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 3783 | int InIx = Node->getOperand(0).getResNo(); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3784 | unsigned NumElems = InVal->getValueType(InIx).getVectorNumElements(); |
| 3785 | MVT EVT = InVal->getValueType(InIx).getVectorElementType(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3786 | |
| 3787 | // Figure out if there is a simple type corresponding to this Vector |
| 3788 | // type. If so, convert to the vector type. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3789 | MVT TVT = MVT::getVectorVT(EVT, NumElems); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3790 | if (TLI.isTypeLegal(TVT)) { |
| 3791 | // Turn this into a bit convert of the vector input. |
| 3792 | Result = DAG.getNode(ISD::BIT_CONVERT, Node->getValueType(0), |
| 3793 | LegalizeOp(Node->getOperand(0))); |
| 3794 | break; |
| 3795 | } else if (NumElems == 1) { |
| 3796 | // Turn this into a bit convert of the scalar input. |
| 3797 | Result = DAG.getNode(ISD::BIT_CONVERT, Node->getValueType(0), |
| 3798 | ScalarizeVectorOp(Node->getOperand(0))); |
| 3799 | break; |
| 3800 | } else { |
| 3801 | // FIXME: UNIMP! Store then reload |
| 3802 | assert(0 && "Cast from unsupported vector type not implemented yet!"); |
| 3803 | } |
| 3804 | } else { |
| 3805 | switch (TLI.getOperationAction(ISD::BIT_CONVERT, |
| 3806 | Node->getOperand(0).getValueType())) { |
| 3807 | default: assert(0 && "Unknown operation action!"); |
| 3808 | case TargetLowering::Expand: |
Chris Lattner | b7d0aaa | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 3809 | Result = EmitStackConvert(Node->getOperand(0), Node->getValueType(0), |
| 3810 | Node->getValueType(0)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3811 | break; |
| 3812 | case TargetLowering::Legal: |
| 3813 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 3814 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 3815 | break; |
| 3816 | } |
| 3817 | } |
| 3818 | break; |
Mon P Wang | 73d3154 | 2008-11-10 20:54:11 +0000 | [diff] [blame] | 3819 | case ISD::CONVERT_RNDSAT: { |
| 3820 | ISD::CvtCode CvtCode = cast<CvtRndSatSDNode>(Node)->getCvtCode(); |
| 3821 | switch (CvtCode) { |
| 3822 | default: assert(0 && "Unknown cvt code!"); |
| 3823 | case ISD::CVT_SF: |
| 3824 | case ISD::CVT_UF: |
| 3825 | break; |
| 3826 | case ISD::CVT_FF: |
| 3827 | case ISD::CVT_FS: |
| 3828 | case ISD::CVT_FU: |
| 3829 | case ISD::CVT_SS: |
| 3830 | case ISD::CVT_SU: |
| 3831 | case ISD::CVT_US: |
| 3832 | case ISD::CVT_UU: { |
| 3833 | SDValue DTyOp = Node->getOperand(1); |
| 3834 | SDValue STyOp = Node->getOperand(2); |
| 3835 | SDValue RndOp = Node->getOperand(3); |
| 3836 | SDValue SatOp = Node->getOperand(4); |
| 3837 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3838 | case Expand: assert(0 && "Shouldn't need to expand other operators here!"); |
| 3839 | case Legal: |
| 3840 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 3841 | Result = DAG.UpdateNodeOperands(Result, Tmp1, DTyOp, STyOp, |
| 3842 | RndOp, SatOp); |
| 3843 | if (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0)) == |
| 3844 | TargetLowering::Custom) { |
| 3845 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 3846 | if (Tmp1.getNode()) Result = Tmp1; |
| 3847 | } |
| 3848 | break; |
| 3849 | case Promote: |
| 3850 | Result = PromoteOp(Node->getOperand(0)); |
| 3851 | // For FP, make Op1 a i32 |
| 3852 | |
| 3853 | Result = DAG.getConvertRndSat(Result.getValueType(), Result, |
| 3854 | DTyOp, STyOp, RndOp, SatOp, CvtCode); |
| 3855 | break; |
| 3856 | } |
| 3857 | break; |
| 3858 | } |
| 3859 | } // end switch CvtCode |
| 3860 | break; |
| 3861 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3862 | // Conversion operators. The source and destination have different types. |
| 3863 | case ISD::SINT_TO_FP: |
| 3864 | case ISD::UINT_TO_FP: { |
| 3865 | bool isSigned = Node->getOpcode() == ISD::SINT_TO_FP; |
Dan Gohman | 29c3cef | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 3866 | Result = LegalizeINT_TO_FP(Result, isSigned, |
| 3867 | Node->getValueType(0), Node->getOperand(0)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3868 | break; |
| 3869 | } |
| 3870 | case ISD::TRUNCATE: |
| 3871 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3872 | case Legal: |
| 3873 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 3874 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 3875 | break; |
| 3876 | case Expand: |
| 3877 | ExpandOp(Node->getOperand(0), Tmp1, Tmp2); |
| 3878 | |
| 3879 | // Since the result is legal, we should just be able to truncate the low |
| 3880 | // part of the source. |
| 3881 | Result = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0), Tmp1); |
| 3882 | break; |
| 3883 | case Promote: |
| 3884 | Result = PromoteOp(Node->getOperand(0)); |
| 3885 | Result = DAG.getNode(ISD::TRUNCATE, Op.getValueType(), Result); |
| 3886 | break; |
| 3887 | } |
| 3888 | break; |
| 3889 | |
| 3890 | case ISD::FP_TO_SINT: |
| 3891 | case ISD::FP_TO_UINT: |
| 3892 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3893 | case Legal: |
| 3894 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 3895 | |
| 3896 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))){ |
| 3897 | default: assert(0 && "Unknown operation action!"); |
| 3898 | case TargetLowering::Custom: |
| 3899 | isCustom = true; |
| 3900 | // FALLTHROUGH |
| 3901 | case TargetLowering::Legal: |
| 3902 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 3903 | if (isCustom) { |
| 3904 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3905 | if (Tmp1.getNode()) Result = Tmp1; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3906 | } |
| 3907 | break; |
| 3908 | case TargetLowering::Promote: |
| 3909 | Result = PromoteLegalFP_TO_INT(Tmp1, Node->getValueType(0), |
| 3910 | Node->getOpcode() == ISD::FP_TO_SINT); |
| 3911 | break; |
| 3912 | case TargetLowering::Expand: |
| 3913 | if (Node->getOpcode() == ISD::FP_TO_UINT) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3914 | SDValue True, False; |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3915 | MVT VT = Node->getOperand(0).getValueType(); |
| 3916 | MVT NVT = Node->getValueType(0); |
Dale Johannesen | 958b08b | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 3917 | const uint64_t zero[] = {0, 0}; |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3918 | APFloat apf = APFloat(APInt(VT.getSizeInBits(), 2, zero)); |
| 3919 | APInt x = APInt::getSignBit(NVT.getSizeInBits()); |
Dan Gohman | 88ae8c5 | 2008-02-29 01:44:25 +0000 | [diff] [blame] | 3920 | (void)apf.convertFromAPInt(x, false, APFloat::rmNearestTiesToEven); |
Dale Johannesen | 958b08b | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 3921 | Tmp2 = DAG.getConstantFP(apf, VT); |
Scott Michel | 502151f | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 3922 | Tmp3 = DAG.getSetCC(TLI.getSetCCResultType(Node->getOperand(0)), |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3923 | Node->getOperand(0), Tmp2, ISD::SETLT); |
| 3924 | True = DAG.getNode(ISD::FP_TO_SINT, NVT, Node->getOperand(0)); |
| 3925 | False = DAG.getNode(ISD::FP_TO_SINT, NVT, |
| 3926 | DAG.getNode(ISD::FSUB, VT, Node->getOperand(0), |
| 3927 | Tmp2)); |
| 3928 | False = DAG.getNode(ISD::XOR, NVT, False, |
Dan Gohman | 88ae8c5 | 2008-02-29 01:44:25 +0000 | [diff] [blame] | 3929 | DAG.getConstant(x, NVT)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3930 | Result = DAG.getNode(ISD::SELECT, NVT, Tmp3, True, False); |
| 3931 | break; |
| 3932 | } else { |
| 3933 | assert(0 && "Do not know how to expand FP_TO_SINT yet!"); |
| 3934 | } |
| 3935 | break; |
| 3936 | } |
| 3937 | break; |
| 3938 | case Expand: { |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3939 | MVT VT = Op.getValueType(); |
| 3940 | MVT OVT = Node->getOperand(0).getValueType(); |
Dale Johannesen | d3b6af3 | 2007-10-11 23:32:15 +0000 | [diff] [blame] | 3941 | // Convert ppcf128 to i32 |
Dale Johannesen | 3d8578b | 2007-10-10 01:01:31 +0000 | [diff] [blame] | 3942 | if (OVT == MVT::ppcf128 && VT == MVT::i32) { |
Chris Lattner | 5872a36 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 3943 | if (Node->getOpcode() == ISD::FP_TO_SINT) { |
| 3944 | Result = DAG.getNode(ISD::FP_ROUND_INREG, MVT::ppcf128, |
| 3945 | Node->getOperand(0), DAG.getValueType(MVT::f64)); |
| 3946 | Result = DAG.getNode(ISD::FP_ROUND, MVT::f64, Result, |
| 3947 | DAG.getIntPtrConstant(1)); |
| 3948 | Result = DAG.getNode(ISD::FP_TO_SINT, VT, Result); |
| 3949 | } else { |
Dale Johannesen | d3b6af3 | 2007-10-11 23:32:15 +0000 | [diff] [blame] | 3950 | const uint64_t TwoE31[] = {0x41e0000000000000LL, 0}; |
| 3951 | APFloat apf = APFloat(APInt(128, 2, TwoE31)); |
| 3952 | Tmp2 = DAG.getConstantFP(apf, OVT); |
| 3953 | // X>=2^31 ? (int)(X-2^31)+0x80000000 : (int)X |
| 3954 | // FIXME: generated code sucks. |
| 3955 | Result = DAG.getNode(ISD::SELECT_CC, VT, Node->getOperand(0), Tmp2, |
| 3956 | DAG.getNode(ISD::ADD, MVT::i32, |
| 3957 | DAG.getNode(ISD::FP_TO_SINT, VT, |
| 3958 | DAG.getNode(ISD::FSUB, OVT, |
| 3959 | Node->getOperand(0), Tmp2)), |
| 3960 | DAG.getConstant(0x80000000, MVT::i32)), |
| 3961 | DAG.getNode(ISD::FP_TO_SINT, VT, |
| 3962 | Node->getOperand(0)), |
| 3963 | DAG.getCondCode(ISD::SETGE)); |
| 3964 | } |
Dale Johannesen | 3d8578b | 2007-10-10 01:01:31 +0000 | [diff] [blame] | 3965 | break; |
| 3966 | } |
Dan Gohman | ec51f64 | 2008-03-10 23:03:31 +0000 | [diff] [blame] | 3967 | // Convert f32 / f64 to i32 / i64 / i128. |
Duncan Sands | f68dffb | 2008-07-17 02:36:29 +0000 | [diff] [blame] | 3968 | RTLIB::Libcall LC = (Node->getOpcode() == ISD::FP_TO_SINT) ? |
| 3969 | RTLIB::getFPTOSINT(OVT, VT) : RTLIB::getFPTOUINT(OVT, VT); |
| 3970 | assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unexpectd fp-to-int conversion!"); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3971 | SDValue Dummy; |
Duncan Sands | f1db7c8 | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 3972 | Result = ExpandLibCall(LC, Node, false/*sign irrelevant*/, Dummy); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 3973 | break; |
| 3974 | } |
| 3975 | case Promote: |
| 3976 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 3977 | Result = DAG.UpdateNodeOperands(Result, LegalizeOp(Tmp1)); |
| 3978 | Result = LegalizeOp(Result); |
| 3979 | break; |
| 3980 | } |
| 3981 | break; |
| 3982 | |
Chris Lattner | 56ecde3 | 2008-01-16 06:57:07 +0000 | [diff] [blame] | 3983 | case ISD::FP_EXTEND: { |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3984 | MVT DstVT = Op.getValueType(); |
| 3985 | MVT SrcVT = Op.getOperand(0).getValueType(); |
Chris Lattner | 5872a36 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 3986 | if (TLI.getConvertAction(SrcVT, DstVT) == TargetLowering::Expand) { |
| 3987 | // The only other way we can lower this is to turn it into a STORE, |
| 3988 | // LOAD pair, targetting a temporary location (a stack slot). |
| 3989 | Result = EmitStackConvert(Node->getOperand(0), SrcVT, DstVT); |
| 3990 | break; |
Chris Lattner | 56ecde3 | 2008-01-16 06:57:07 +0000 | [diff] [blame] | 3991 | } |
| 3992 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3993 | case Expand: assert(0 && "Shouldn't need to expand other operators here!"); |
| 3994 | case Legal: |
| 3995 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 3996 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 3997 | break; |
| 3998 | case Promote: |
| 3999 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4000 | Result = DAG.getNode(ISD::FP_EXTEND, Op.getValueType(), Tmp1); |
| 4001 | break; |
| 4002 | } |
| 4003 | break; |
Chris Lattner | 5872a36 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4004 | } |
Dale Johannesen | 8f83a6b | 2007-08-09 01:04:01 +0000 | [diff] [blame] | 4005 | case ISD::FP_ROUND: { |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4006 | MVT DstVT = Op.getValueType(); |
| 4007 | MVT SrcVT = Op.getOperand(0).getValueType(); |
Chris Lattner | 5872a36 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4008 | if (TLI.getConvertAction(SrcVT, DstVT) == TargetLowering::Expand) { |
| 4009 | if (SrcVT == MVT::ppcf128) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4010 | SDValue Lo; |
Dale Johannesen | a0d3608 | 2008-01-20 01:18:38 +0000 | [diff] [blame] | 4011 | ExpandOp(Node->getOperand(0), Lo, Result); |
Chris Lattner | 5872a36 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4012 | // Round it the rest of the way (e.g. to f32) if needed. |
Dale Johannesen | a0d3608 | 2008-01-20 01:18:38 +0000 | [diff] [blame] | 4013 | if (DstVT!=MVT::f64) |
| 4014 | Result = DAG.getNode(ISD::FP_ROUND, DstVT, Result, Op.getOperand(1)); |
Chris Lattner | 5872a36 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4015 | break; |
Dale Johannesen | 8f83a6b | 2007-08-09 01:04:01 +0000 | [diff] [blame] | 4016 | } |
Chris Lattner | 5872a36 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4017 | // The only other way we can lower this is to turn it into a STORE, |
| 4018 | // LOAD pair, targetting a temporary location (a stack slot). |
| 4019 | Result = EmitStackConvert(Node->getOperand(0), DstVT, DstVT); |
| 4020 | break; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4021 | } |
Chris Lattner | 56ecde3 | 2008-01-16 06:57:07 +0000 | [diff] [blame] | 4022 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 4023 | case Expand: assert(0 && "Shouldn't need to expand other operators here!"); |
| 4024 | case Legal: |
| 4025 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | 5872a36 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4026 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
Chris Lattner | 56ecde3 | 2008-01-16 06:57:07 +0000 | [diff] [blame] | 4027 | break; |
| 4028 | case Promote: |
| 4029 | Tmp1 = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 5872a36 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4030 | Result = DAG.getNode(ISD::FP_ROUND, Op.getValueType(), Tmp1, |
| 4031 | Node->getOperand(1)); |
Chris Lattner | 56ecde3 | 2008-01-16 06:57:07 +0000 | [diff] [blame] | 4032 | break; |
| 4033 | } |
| 4034 | break; |
Chris Lattner | 5872a36 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4035 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4036 | case ISD::ANY_EXTEND: |
| 4037 | case ISD::ZERO_EXTEND: |
| 4038 | case ISD::SIGN_EXTEND: |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4039 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 4040 | case Expand: assert(0 && "Shouldn't need to expand other operators here!"); |
| 4041 | case Legal: |
| 4042 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Scott Michel | ac54d00 | 2008-04-30 00:26:38 +0000 | [diff] [blame] | 4043 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Scott Michel | ac7091c | 2008-02-15 23:05:48 +0000 | [diff] [blame] | 4044 | if (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0)) == |
| 4045 | TargetLowering::Custom) { |
Scott Michel | ac54d00 | 2008-04-30 00:26:38 +0000 | [diff] [blame] | 4046 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 4047 | if (Tmp1.getNode()) Result = Tmp1; |
Scott Michel | ac7091c | 2008-02-15 23:05:48 +0000 | [diff] [blame] | 4048 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4049 | break; |
| 4050 | case Promote: |
| 4051 | switch (Node->getOpcode()) { |
| 4052 | case ISD::ANY_EXTEND: |
| 4053 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4054 | Result = DAG.getNode(ISD::ANY_EXTEND, Op.getValueType(), Tmp1); |
| 4055 | break; |
| 4056 | case ISD::ZERO_EXTEND: |
| 4057 | Result = PromoteOp(Node->getOperand(0)); |
| 4058 | Result = DAG.getNode(ISD::ANY_EXTEND, Op.getValueType(), Result); |
| 4059 | Result = DAG.getZeroExtendInReg(Result, |
| 4060 | Node->getOperand(0).getValueType()); |
| 4061 | break; |
| 4062 | case ISD::SIGN_EXTEND: |
| 4063 | Result = PromoteOp(Node->getOperand(0)); |
| 4064 | Result = DAG.getNode(ISD::ANY_EXTEND, Op.getValueType(), Result); |
| 4065 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(), |
| 4066 | Result, |
| 4067 | DAG.getValueType(Node->getOperand(0).getValueType())); |
| 4068 | break; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4069 | } |
| 4070 | } |
| 4071 | break; |
| 4072 | case ISD::FP_ROUND_INREG: |
| 4073 | case ISD::SIGN_EXTEND_INREG: { |
| 4074 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4075 | MVT ExtraVT = cast<VTSDNode>(Node->getOperand(1))->getVT(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4076 | |
| 4077 | // If this operation is not supported, convert it to a shl/shr or load/store |
| 4078 | // pair. |
| 4079 | switch (TLI.getOperationAction(Node->getOpcode(), ExtraVT)) { |
| 4080 | default: assert(0 && "This action not supported for this op yet!"); |
| 4081 | case TargetLowering::Legal: |
| 4082 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
| 4083 | break; |
| 4084 | case TargetLowering::Expand: |
| 4085 | // If this is an integer extend and shifts are supported, do that. |
| 4086 | if (Node->getOpcode() == ISD::SIGN_EXTEND_INREG) { |
| 4087 | // NOTE: we could fall back on load/store here too for targets without |
| 4088 | // SAR. However, it is doubtful that any exist. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4089 | unsigned BitsDiff = Node->getValueType(0).getSizeInBits() - |
| 4090 | ExtraVT.getSizeInBits(); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4091 | SDValue ShiftCst = DAG.getConstant(BitsDiff, TLI.getShiftAmountTy()); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4092 | Result = DAG.getNode(ISD::SHL, Node->getValueType(0), |
| 4093 | Node->getOperand(0), ShiftCst); |
| 4094 | Result = DAG.getNode(ISD::SRA, Node->getValueType(0), |
| 4095 | Result, ShiftCst); |
| 4096 | } else if (Node->getOpcode() == ISD::FP_ROUND_INREG) { |
| 4097 | // The only way we can lower this is to turn it into a TRUNCSTORE, |
| 4098 | // EXTLOAD pair, targetting a temporary location (a stack slot). |
| 4099 | |
| 4100 | // NOTE: there is a choice here between constantly creating new stack |
| 4101 | // slots and always reusing the same one. We currently always create |
| 4102 | // new ones, as reuse may inhibit scheduling. |
Chris Lattner | 59370bd | 2008-01-16 07:51:34 +0000 | [diff] [blame] | 4103 | Result = EmitStackConvert(Node->getOperand(0), ExtraVT, |
| 4104 | Node->getValueType(0)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4105 | } else { |
| 4106 | assert(0 && "Unknown op"); |
| 4107 | } |
| 4108 | break; |
| 4109 | } |
| 4110 | break; |
| 4111 | } |
Duncan Sands | 38947cd | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 4112 | case ISD::TRAMPOLINE: { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4113 | SDValue Ops[6]; |
Duncan Sands | 38947cd | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 4114 | for (unsigned i = 0; i != 6; ++i) |
| 4115 | Ops[i] = LegalizeOp(Node->getOperand(i)); |
| 4116 | Result = DAG.UpdateNodeOperands(Result, Ops, 6); |
| 4117 | // The only option for this node is to custom lower it. |
| 4118 | Result = TLI.LowerOperation(Result, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 4119 | assert(Result.getNode() && "Should always custom lower!"); |
Duncan Sands | 7407a9f | 2007-09-11 14:10:23 +0000 | [diff] [blame] | 4120 | |
| 4121 | // Since trampoline produces two values, make sure to remember that we |
| 4122 | // legalized both of them. |
| 4123 | Tmp1 = LegalizeOp(Result.getValue(1)); |
| 4124 | Result = LegalizeOp(Result); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4125 | AddLegalizedOperand(SDValue(Node, 0), Result); |
| 4126 | AddLegalizedOperand(SDValue(Node, 1), Tmp1); |
Gabor Greif | 46bf547 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 4127 | return Op.getResNo() ? Tmp1 : Result; |
Duncan Sands | 38947cd | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 4128 | } |
Dan Gohman | e8e4a41 | 2008-05-14 00:43:10 +0000 | [diff] [blame] | 4129 | case ISD::FLT_ROUNDS_: { |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4130 | MVT VT = Node->getValueType(0); |
Anton Korobeynikov | c915e27 | 2007-11-15 23:25:33 +0000 | [diff] [blame] | 4131 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 4132 | default: assert(0 && "This action not supported for this op yet!"); |
| 4133 | case TargetLowering::Custom: |
| 4134 | Result = TLI.LowerOperation(Op, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 4135 | if (Result.getNode()) break; |
Anton Korobeynikov | c915e27 | 2007-11-15 23:25:33 +0000 | [diff] [blame] | 4136 | // Fall Thru |
| 4137 | case TargetLowering::Legal: |
| 4138 | // If this operation is not supported, lower it to constant 1 |
| 4139 | Result = DAG.getConstant(1, VT); |
| 4140 | break; |
| 4141 | } |
Dan Gohman | e09dc8c | 2008-05-12 16:07:15 +0000 | [diff] [blame] | 4142 | break; |
Anton Korobeynikov | c915e27 | 2007-11-15 23:25:33 +0000 | [diff] [blame] | 4143 | } |
Chris Lattner | e99bbb7 | 2008-01-15 21:58:08 +0000 | [diff] [blame] | 4144 | case ISD::TRAP: { |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4145 | MVT VT = Node->getValueType(0); |
Anton Korobeynikov | 39d40ba | 2008-01-15 07:02:33 +0000 | [diff] [blame] | 4146 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 4147 | default: assert(0 && "This action not supported for this op yet!"); |
Chris Lattner | e99bbb7 | 2008-01-15 21:58:08 +0000 | [diff] [blame] | 4148 | case TargetLowering::Legal: |
| 4149 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 4150 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 4151 | break; |
Anton Korobeynikov | 39d40ba | 2008-01-15 07:02:33 +0000 | [diff] [blame] | 4152 | case TargetLowering::Custom: |
| 4153 | Result = TLI.LowerOperation(Op, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 4154 | if (Result.getNode()) break; |
Anton Korobeynikov | 39d40ba | 2008-01-15 07:02:33 +0000 | [diff] [blame] | 4155 | // Fall Thru |
Chris Lattner | e99bbb7 | 2008-01-15 21:58:08 +0000 | [diff] [blame] | 4156 | case TargetLowering::Expand: |
Anton Korobeynikov | 39d40ba | 2008-01-15 07:02:33 +0000 | [diff] [blame] | 4157 | // If this operation is not supported, lower it to 'abort()' call |
Chris Lattner | e99bbb7 | 2008-01-15 21:58:08 +0000 | [diff] [blame] | 4158 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Anton Korobeynikov | 39d40ba | 2008-01-15 07:02:33 +0000 | [diff] [blame] | 4159 | TargetLowering::ArgListTy Args; |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4160 | std::pair<SDValue,SDValue> CallResult = |
Duncan Sands | ead972e | 2008-02-14 17:28:50 +0000 | [diff] [blame] | 4161 | TLI.LowerCallTo(Tmp1, Type::VoidTy, |
Dale Johannesen | 67cc9b6 | 2008-09-26 19:31:26 +0000 | [diff] [blame] | 4162 | false, false, false, false, CallingConv::C, false, |
Bill Wendling | fef0605 | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 4163 | DAG.getExternalSymbol("abort", TLI.getPointerTy()), |
Chris Lattner | 88e0393 | 2008-01-15 22:09:33 +0000 | [diff] [blame] | 4164 | Args, DAG); |
Anton Korobeynikov | 39d40ba | 2008-01-15 07:02:33 +0000 | [diff] [blame] | 4165 | Result = CallResult.second; |
| 4166 | break; |
| 4167 | } |
Chris Lattner | e99bbb7 | 2008-01-15 21:58:08 +0000 | [diff] [blame] | 4168 | break; |
Anton Korobeynikov | 39d40ba | 2008-01-15 07:02:33 +0000 | [diff] [blame] | 4169 | } |
Bill Wendling | 913dcf3 | 2008-11-22 00:22:52 +0000 | [diff] [blame] | 4170 | |
Bill Wendling | 8062b07 | 2008-11-24 01:38:29 +0000 | [diff] [blame^] | 4171 | case ISD::SADDO: |
| 4172 | case ISD::UADDO: { |
Bill Wendling | 913dcf3 | 2008-11-22 00:22:52 +0000 | [diff] [blame] | 4173 | SDValue LHS = LegalizeOp(Node->getOperand(0)); |
| 4174 | SDValue RHS = LegalizeOp(Node->getOperand(1)); |
| 4175 | |
| 4176 | SDValue Sum = DAG.getNode(ISD::ADD, LHS.getValueType(), LHS, RHS); |
| 4177 | MVT OType = SDValue(Node, 1).getValueType(); |
Bill Wendling | 8062b07 | 2008-11-24 01:38:29 +0000 | [diff] [blame^] | 4178 | SDValue Cmp = DAG.getSetCC(OType, Sum, LHS, |
| 4179 | (Node->getOpcode() == ISD::SADDO) ? |
| 4180 | ISD::SETLT : ISD::SETULT); |
Bill Wendling | 913dcf3 | 2008-11-22 00:22:52 +0000 | [diff] [blame] | 4181 | |
| 4182 | MVT ValueVTs[] = { LHS.getValueType(), OType }; |
| 4183 | SDValue Ops[] = { Sum, Cmp }; |
| 4184 | |
| 4185 | Result = DAG.getMergeValues(DAG.getVTList(&ValueVTs[0], 2), &Ops[0], 2); |
| 4186 | SDNode *RNode = Result.getNode(); |
| 4187 | DAG.ReplaceAllUsesOfValueWith(SDValue(Node, 0), SDValue(RNode, 0)); |
| 4188 | DAG.ReplaceAllUsesOfValueWith(SDValue(Node, 1), SDValue(RNode, 1)); |
| 4189 | break; |
| 4190 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4191 | } |
| 4192 | |
| 4193 | assert(Result.getValueType() == Op.getValueType() && |
| 4194 | "Bad legalization!"); |
| 4195 | |
| 4196 | // Make sure that the generated code is itself legal. |
| 4197 | if (Result != Op) |
| 4198 | Result = LegalizeOp(Result); |
| 4199 | |
| 4200 | // Note that LegalizeOp may be reentered even from single-use nodes, which |
| 4201 | // means that we always must cache transformed nodes. |
| 4202 | AddLegalizedOperand(Op, Result); |
| 4203 | return Result; |
| 4204 | } |
| 4205 | |
| 4206 | /// PromoteOp - Given an operation that produces a value in an invalid type, |
| 4207 | /// promote it to compute the value into a larger type. The produced value will |
| 4208 | /// have the correct bits for the low portion of the register, but no guarantee |
| 4209 | /// is made about the top bits: it may be zero, sign-extended, or garbage. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4210 | SDValue SelectionDAGLegalize::PromoteOp(SDValue Op) { |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4211 | MVT VT = Op.getValueType(); |
| 4212 | MVT NVT = TLI.getTypeToTransformTo(VT); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4213 | assert(getTypeAction(VT) == Promote && |
| 4214 | "Caller should expand or legalize operands that are not promotable!"); |
Duncan Sands | ec142ee | 2008-06-08 20:54:56 +0000 | [diff] [blame] | 4215 | assert(NVT.bitsGT(VT) && NVT.isInteger() == VT.isInteger() && |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4216 | "Cannot promote to smaller type!"); |
| 4217 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4218 | SDValue Tmp1, Tmp2, Tmp3; |
| 4219 | SDValue Result; |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 4220 | SDNode *Node = Op.getNode(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4221 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4222 | DenseMap<SDValue, SDValue>::iterator I = PromotedNodes.find(Op); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4223 | if (I != PromotedNodes.end()) return I->second; |
| 4224 | |
| 4225 | switch (Node->getOpcode()) { |
| 4226 | case ISD::CopyFromReg: |
| 4227 | assert(0 && "CopyFromReg must be legal!"); |
| 4228 | default: |
| 4229 | #ifndef NDEBUG |
| 4230 | cerr << "NODE: "; Node->dump(&DAG); cerr << "\n"; |
| 4231 | #endif |
| 4232 | assert(0 && "Do not know how to promote this operator!"); |
| 4233 | abort(); |
| 4234 | case ISD::UNDEF: |
| 4235 | Result = DAG.getNode(ISD::UNDEF, NVT); |
| 4236 | break; |
| 4237 | case ISD::Constant: |
| 4238 | if (VT != MVT::i1) |
| 4239 | Result = DAG.getNode(ISD::SIGN_EXTEND, NVT, Op); |
| 4240 | else |
| 4241 | Result = DAG.getNode(ISD::ZERO_EXTEND, NVT, Op); |
| 4242 | assert(isa<ConstantSDNode>(Result) && "Didn't constant fold zext?"); |
| 4243 | break; |
| 4244 | case ISD::ConstantFP: |
| 4245 | Result = DAG.getNode(ISD::FP_EXTEND, NVT, Op); |
| 4246 | assert(isa<ConstantFPSDNode>(Result) && "Didn't constant fold fp_extend?"); |
| 4247 | break; |
| 4248 | |
| 4249 | case ISD::SETCC: |
Scott Michel | 502151f | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 4250 | assert(isTypeLegal(TLI.getSetCCResultType(Node->getOperand(0))) |
Nate Begeman | 8bb3cb3 | 2008-03-14 00:53:31 +0000 | [diff] [blame] | 4251 | && "SetCC type is not legal??"); |
Scott Michel | 502151f | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 4252 | Result = DAG.getNode(ISD::SETCC, |
Nate Begeman | 8bb3cb3 | 2008-03-14 00:53:31 +0000 | [diff] [blame] | 4253 | TLI.getSetCCResultType(Node->getOperand(0)), |
| 4254 | Node->getOperand(0), Node->getOperand(1), |
| 4255 | Node->getOperand(2)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4256 | break; |
| 4257 | |
| 4258 | case ISD::TRUNCATE: |
| 4259 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 4260 | case Legal: |
| 4261 | Result = LegalizeOp(Node->getOperand(0)); |
Duncan Sands | ec142ee | 2008-06-08 20:54:56 +0000 | [diff] [blame] | 4262 | assert(Result.getValueType().bitsGE(NVT) && |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4263 | "This truncation doesn't make sense!"); |
Duncan Sands | ec142ee | 2008-06-08 20:54:56 +0000 | [diff] [blame] | 4264 | if (Result.getValueType().bitsGT(NVT)) // Truncate to NVT instead of VT |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4265 | Result = DAG.getNode(ISD::TRUNCATE, NVT, Result); |
| 4266 | break; |
| 4267 | case Promote: |
| 4268 | // The truncation is not required, because we don't guarantee anything |
| 4269 | // about high bits anyway. |
| 4270 | Result = PromoteOp(Node->getOperand(0)); |
| 4271 | break; |
| 4272 | case Expand: |
| 4273 | ExpandOp(Node->getOperand(0), Tmp1, Tmp2); |
| 4274 | // Truncate the low part of the expanded value to the result type |
| 4275 | Result = DAG.getNode(ISD::TRUNCATE, NVT, Tmp1); |
| 4276 | } |
| 4277 | break; |
| 4278 | case ISD::SIGN_EXTEND: |
| 4279 | case ISD::ZERO_EXTEND: |
| 4280 | case ISD::ANY_EXTEND: |
| 4281 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 4282 | case Expand: assert(0 && "BUG: Smaller reg should have been promoted!"); |
| 4283 | case Legal: |
| 4284 | // Input is legal? Just do extend all the way to the larger type. |
| 4285 | Result = DAG.getNode(Node->getOpcode(), NVT, Node->getOperand(0)); |
| 4286 | break; |
| 4287 | case Promote: |
| 4288 | // Promote the reg if it's smaller. |
| 4289 | Result = PromoteOp(Node->getOperand(0)); |
| 4290 | // The high bits are not guaranteed to be anything. Insert an extend. |
| 4291 | if (Node->getOpcode() == ISD::SIGN_EXTEND) |
| 4292 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Result, |
| 4293 | DAG.getValueType(Node->getOperand(0).getValueType())); |
| 4294 | else if (Node->getOpcode() == ISD::ZERO_EXTEND) |
| 4295 | Result = DAG.getZeroExtendInReg(Result, |
| 4296 | Node->getOperand(0).getValueType()); |
| 4297 | break; |
| 4298 | } |
| 4299 | break; |
Mon P Wang | 73d3154 | 2008-11-10 20:54:11 +0000 | [diff] [blame] | 4300 | case ISD::CONVERT_RNDSAT: { |
| 4301 | ISD::CvtCode CvtCode = cast<CvtRndSatSDNode>(Node)->getCvtCode(); |
| 4302 | assert ((CvtCode == ISD::CVT_SS || CvtCode == ISD::CVT_SU || |
| 4303 | CvtCode == ISD::CVT_US || CvtCode == ISD::CVT_UU || |
| 4304 | CvtCode == ISD::CVT_SF || CvtCode == ISD::CVT_UF) && |
| 4305 | "can only promote integers"); |
| 4306 | Result = DAG.getConvertRndSat(NVT, Node->getOperand(0), |
| 4307 | Node->getOperand(1), Node->getOperand(2), |
| 4308 | Node->getOperand(3), Node->getOperand(4), |
| 4309 | CvtCode); |
| 4310 | break; |
| 4311 | |
| 4312 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4313 | case ISD::BIT_CONVERT: |
Chris Lattner | b7d0aaa | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 4314 | Result = EmitStackConvert(Node->getOperand(0), Node->getValueType(0), |
| 4315 | Node->getValueType(0)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4316 | Result = PromoteOp(Result); |
| 4317 | break; |
| 4318 | |
| 4319 | case ISD::FP_EXTEND: |
| 4320 | assert(0 && "Case not implemented. Dynamically dead with 2 FP types!"); |
| 4321 | case ISD::FP_ROUND: |
| 4322 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 4323 | case Expand: assert(0 && "BUG: Cannot expand FP regs!"); |
| 4324 | case Promote: assert(0 && "Unreachable with 2 FP types!"); |
| 4325 | case Legal: |
Chris Lattner | 5872a36 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4326 | if (Node->getConstantOperandVal(1) == 0) { |
| 4327 | // Input is legal? Do an FP_ROUND_INREG. |
| 4328 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Node->getOperand(0), |
| 4329 | DAG.getValueType(VT)); |
| 4330 | } else { |
| 4331 | // Just remove the truncate, it isn't affecting the value. |
| 4332 | Result = DAG.getNode(ISD::FP_ROUND, NVT, Node->getOperand(0), |
| 4333 | Node->getOperand(1)); |
| 4334 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4335 | break; |
| 4336 | } |
| 4337 | break; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4338 | case ISD::SINT_TO_FP: |
| 4339 | case ISD::UINT_TO_FP: |
| 4340 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 4341 | case Legal: |
| 4342 | // No extra round required here. |
| 4343 | Result = DAG.getNode(Node->getOpcode(), NVT, Node->getOperand(0)); |
| 4344 | break; |
| 4345 | |
| 4346 | case Promote: |
| 4347 | Result = PromoteOp(Node->getOperand(0)); |
| 4348 | if (Node->getOpcode() == ISD::SINT_TO_FP) |
| 4349 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(), |
| 4350 | Result, |
| 4351 | DAG.getValueType(Node->getOperand(0).getValueType())); |
| 4352 | else |
| 4353 | Result = DAG.getZeroExtendInReg(Result, |
| 4354 | Node->getOperand(0).getValueType()); |
| 4355 | // No extra round required here. |
| 4356 | Result = DAG.getNode(Node->getOpcode(), NVT, Result); |
| 4357 | break; |
| 4358 | case Expand: |
| 4359 | Result = ExpandIntToFP(Node->getOpcode() == ISD::SINT_TO_FP, NVT, |
| 4360 | Node->getOperand(0)); |
| 4361 | // Round if we cannot tolerate excess precision. |
| 4362 | if (NoExcessFPPrecision) |
| 4363 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 4364 | DAG.getValueType(VT)); |
| 4365 | break; |
| 4366 | } |
| 4367 | break; |
| 4368 | |
| 4369 | case ISD::SIGN_EXTEND_INREG: |
| 4370 | Result = PromoteOp(Node->getOperand(0)); |
| 4371 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Result, |
| 4372 | Node->getOperand(1)); |
| 4373 | break; |
| 4374 | case ISD::FP_TO_SINT: |
| 4375 | case ISD::FP_TO_UINT: |
| 4376 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 4377 | case Legal: |
| 4378 | case Expand: |
| 4379 | Tmp1 = Node->getOperand(0); |
| 4380 | break; |
| 4381 | case Promote: |
| 4382 | // The input result is prerounded, so we don't have to do anything |
| 4383 | // special. |
| 4384 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4385 | break; |
| 4386 | } |
| 4387 | // If we're promoting a UINT to a larger size, check to see if the new node |
| 4388 | // will be legal. If it isn't, check to see if FP_TO_SINT is legal, since |
| 4389 | // we can use that instead. This allows us to generate better code for |
| 4390 | // FP_TO_UINT for small destination sizes on targets where FP_TO_UINT is not |
| 4391 | // legal, such as PowerPC. |
| 4392 | if (Node->getOpcode() == ISD::FP_TO_UINT && |
| 4393 | !TLI.isOperationLegal(ISD::FP_TO_UINT, NVT) && |
| 4394 | (TLI.isOperationLegal(ISD::FP_TO_SINT, NVT) || |
| 4395 | TLI.getOperationAction(ISD::FP_TO_SINT, NVT)==TargetLowering::Custom)){ |
| 4396 | Result = DAG.getNode(ISD::FP_TO_SINT, NVT, Tmp1); |
| 4397 | } else { |
| 4398 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1); |
| 4399 | } |
| 4400 | break; |
| 4401 | |
| 4402 | case ISD::FABS: |
| 4403 | case ISD::FNEG: |
| 4404 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4405 | assert(Tmp1.getValueType() == NVT); |
| 4406 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1); |
| 4407 | // NOTE: we do not have to do any extra rounding here for |
| 4408 | // NoExcessFPPrecision, because we know the input will have the appropriate |
| 4409 | // precision, and these operations don't modify precision at all. |
| 4410 | break; |
| 4411 | |
Dale Johannesen | 92b3308 | 2008-09-04 00:47:13 +0000 | [diff] [blame] | 4412 | case ISD::FLOG: |
| 4413 | case ISD::FLOG2: |
| 4414 | case ISD::FLOG10: |
| 4415 | case ISD::FEXP: |
| 4416 | case ISD::FEXP2: |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4417 | case ISD::FSQRT: |
| 4418 | case ISD::FSIN: |
| 4419 | case ISD::FCOS: |
Dan Gohman | b215823 | 2008-08-21 18:38:14 +0000 | [diff] [blame] | 4420 | case ISD::FTRUNC: |
| 4421 | case ISD::FFLOOR: |
| 4422 | case ISD::FCEIL: |
| 4423 | case ISD::FRINT: |
| 4424 | case ISD::FNEARBYINT: |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4425 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4426 | assert(Tmp1.getValueType() == NVT); |
| 4427 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1); |
| 4428 | if (NoExcessFPPrecision) |
| 4429 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 4430 | DAG.getValueType(VT)); |
| 4431 | break; |
| 4432 | |
Evan Cheng | 1fac695 | 2008-09-09 23:35:53 +0000 | [diff] [blame] | 4433 | case ISD::FPOW: |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4434 | case ISD::FPOWI: { |
Evan Cheng | 1fac695 | 2008-09-09 23:35:53 +0000 | [diff] [blame] | 4435 | // Promote f32 pow(i) to f64 pow(i). Note that this could insert a libcall |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4436 | // directly as well, which may be better. |
| 4437 | Tmp1 = PromoteOp(Node->getOperand(0)); |
Evan Cheng | 1fac695 | 2008-09-09 23:35:53 +0000 | [diff] [blame] | 4438 | Tmp2 = Node->getOperand(1); |
| 4439 | if (Node->getOpcode() == ISD::FPOW) |
| 4440 | Tmp2 = PromoteOp(Tmp2); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4441 | assert(Tmp1.getValueType() == NVT); |
Evan Cheng | 1fac695 | 2008-09-09 23:35:53 +0000 | [diff] [blame] | 4442 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4443 | if (NoExcessFPPrecision) |
| 4444 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 4445 | DAG.getValueType(VT)); |
| 4446 | break; |
| 4447 | } |
| 4448 | |
Dale Johannesen | bc18766 | 2008-08-28 02:44:49 +0000 | [diff] [blame] | 4449 | case ISD::ATOMIC_CMP_SWAP_8: |
| 4450 | case ISD::ATOMIC_CMP_SWAP_16: |
| 4451 | case ISD::ATOMIC_CMP_SWAP_32: |
| 4452 | case ISD::ATOMIC_CMP_SWAP_64: { |
Mon P Wang | 6bde9ec | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 4453 | AtomicSDNode* AtomNode = cast<AtomicSDNode>(Node); |
Andrew Lenharth | e44f390 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 4454 | Tmp2 = PromoteOp(Node->getOperand(2)); |
| 4455 | Tmp3 = PromoteOp(Node->getOperand(3)); |
Mon P Wang | 6bde9ec | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 4456 | Result = DAG.getAtomic(Node->getOpcode(), AtomNode->getChain(), |
| 4457 | AtomNode->getBasePtr(), Tmp2, Tmp3, |
Dan Gohman | c70fa75 | 2008-06-25 16:07:49 +0000 | [diff] [blame] | 4458 | AtomNode->getSrcValue(), |
Mon P Wang | 6bde9ec | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 4459 | AtomNode->getAlignment()); |
Andrew Lenharth | e44f390 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 4460 | // Remember that we legalized the chain. |
| 4461 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1))); |
| 4462 | break; |
| 4463 | } |
Dale Johannesen | bc18766 | 2008-08-28 02:44:49 +0000 | [diff] [blame] | 4464 | case ISD::ATOMIC_LOAD_ADD_8: |
| 4465 | case ISD::ATOMIC_LOAD_SUB_8: |
| 4466 | case ISD::ATOMIC_LOAD_AND_8: |
| 4467 | case ISD::ATOMIC_LOAD_OR_8: |
| 4468 | case ISD::ATOMIC_LOAD_XOR_8: |
| 4469 | case ISD::ATOMIC_LOAD_NAND_8: |
| 4470 | case ISD::ATOMIC_LOAD_MIN_8: |
| 4471 | case ISD::ATOMIC_LOAD_MAX_8: |
| 4472 | case ISD::ATOMIC_LOAD_UMIN_8: |
| 4473 | case ISD::ATOMIC_LOAD_UMAX_8: |
| 4474 | case ISD::ATOMIC_SWAP_8: |
| 4475 | case ISD::ATOMIC_LOAD_ADD_16: |
| 4476 | case ISD::ATOMIC_LOAD_SUB_16: |
| 4477 | case ISD::ATOMIC_LOAD_AND_16: |
| 4478 | case ISD::ATOMIC_LOAD_OR_16: |
| 4479 | case ISD::ATOMIC_LOAD_XOR_16: |
| 4480 | case ISD::ATOMIC_LOAD_NAND_16: |
| 4481 | case ISD::ATOMIC_LOAD_MIN_16: |
| 4482 | case ISD::ATOMIC_LOAD_MAX_16: |
| 4483 | case ISD::ATOMIC_LOAD_UMIN_16: |
| 4484 | case ISD::ATOMIC_LOAD_UMAX_16: |
| 4485 | case ISD::ATOMIC_SWAP_16: |
| 4486 | case ISD::ATOMIC_LOAD_ADD_32: |
| 4487 | case ISD::ATOMIC_LOAD_SUB_32: |
| 4488 | case ISD::ATOMIC_LOAD_AND_32: |
| 4489 | case ISD::ATOMIC_LOAD_OR_32: |
| 4490 | case ISD::ATOMIC_LOAD_XOR_32: |
| 4491 | case ISD::ATOMIC_LOAD_NAND_32: |
| 4492 | case ISD::ATOMIC_LOAD_MIN_32: |
| 4493 | case ISD::ATOMIC_LOAD_MAX_32: |
| 4494 | case ISD::ATOMIC_LOAD_UMIN_32: |
| 4495 | case ISD::ATOMIC_LOAD_UMAX_32: |
| 4496 | case ISD::ATOMIC_SWAP_32: |
| 4497 | case ISD::ATOMIC_LOAD_ADD_64: |
| 4498 | case ISD::ATOMIC_LOAD_SUB_64: |
| 4499 | case ISD::ATOMIC_LOAD_AND_64: |
| 4500 | case ISD::ATOMIC_LOAD_OR_64: |
| 4501 | case ISD::ATOMIC_LOAD_XOR_64: |
| 4502 | case ISD::ATOMIC_LOAD_NAND_64: |
| 4503 | case ISD::ATOMIC_LOAD_MIN_64: |
| 4504 | case ISD::ATOMIC_LOAD_MAX_64: |
| 4505 | case ISD::ATOMIC_LOAD_UMIN_64: |
| 4506 | case ISD::ATOMIC_LOAD_UMAX_64: |
| 4507 | case ISD::ATOMIC_SWAP_64: { |
Mon P Wang | 6bde9ec | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 4508 | AtomicSDNode* AtomNode = cast<AtomicSDNode>(Node); |
Andrew Lenharth | e44f390 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 4509 | Tmp2 = PromoteOp(Node->getOperand(2)); |
Mon P Wang | 6bde9ec | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 4510 | Result = DAG.getAtomic(Node->getOpcode(), AtomNode->getChain(), |
| 4511 | AtomNode->getBasePtr(), Tmp2, |
Dan Gohman | c70fa75 | 2008-06-25 16:07:49 +0000 | [diff] [blame] | 4512 | AtomNode->getSrcValue(), |
Mon P Wang | 6bde9ec | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 4513 | AtomNode->getAlignment()); |
Andrew Lenharth | e44f390 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 4514 | // Remember that we legalized the chain. |
| 4515 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1))); |
| 4516 | break; |
| 4517 | } |
| 4518 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4519 | case ISD::AND: |
| 4520 | case ISD::OR: |
| 4521 | case ISD::XOR: |
| 4522 | case ISD::ADD: |
| 4523 | case ISD::SUB: |
| 4524 | case ISD::MUL: |
| 4525 | // The input may have strange things in the top bits of the registers, but |
| 4526 | // these operations don't care. They may have weird bits going out, but |
| 4527 | // that too is okay if they are integer operations. |
| 4528 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4529 | Tmp2 = PromoteOp(Node->getOperand(1)); |
| 4530 | assert(Tmp1.getValueType() == NVT && Tmp2.getValueType() == NVT); |
| 4531 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 4532 | break; |
| 4533 | case ISD::FADD: |
| 4534 | case ISD::FSUB: |
| 4535 | case ISD::FMUL: |
| 4536 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4537 | Tmp2 = PromoteOp(Node->getOperand(1)); |
| 4538 | assert(Tmp1.getValueType() == NVT && Tmp2.getValueType() == NVT); |
| 4539 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 4540 | |
| 4541 | // Floating point operations will give excess precision that we may not be |
| 4542 | // able to tolerate. If we DO allow excess precision, just leave it, |
| 4543 | // otherwise excise it. |
| 4544 | // FIXME: Why would we need to round FP ops more than integer ones? |
| 4545 | // Is Round(Add(Add(A,B),C)) != Round(Add(Round(Add(A,B)), C)) |
| 4546 | if (NoExcessFPPrecision) |
| 4547 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 4548 | DAG.getValueType(VT)); |
| 4549 | break; |
| 4550 | |
| 4551 | case ISD::SDIV: |
| 4552 | case ISD::SREM: |
| 4553 | // These operators require that their input be sign extended. |
| 4554 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4555 | Tmp2 = PromoteOp(Node->getOperand(1)); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4556 | if (NVT.isInteger()) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4557 | Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp1, |
| 4558 | DAG.getValueType(VT)); |
| 4559 | Tmp2 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp2, |
| 4560 | DAG.getValueType(VT)); |
| 4561 | } |
| 4562 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 4563 | |
| 4564 | // Perform FP_ROUND: this is probably overly pessimistic. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4565 | if (NVT.isFloatingPoint() && NoExcessFPPrecision) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4566 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 4567 | DAG.getValueType(VT)); |
| 4568 | break; |
| 4569 | case ISD::FDIV: |
| 4570 | case ISD::FREM: |
| 4571 | case ISD::FCOPYSIGN: |
| 4572 | // These operators require that their input be fp extended. |
| 4573 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
Chris Lattner | 5872a36 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4574 | case Expand: assert(0 && "not implemented"); |
| 4575 | case Legal: Tmp1 = LegalizeOp(Node->getOperand(0)); break; |
| 4576 | case Promote: Tmp1 = PromoteOp(Node->getOperand(0)); break; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4577 | } |
| 4578 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
Chris Lattner | 5872a36 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4579 | case Expand: assert(0 && "not implemented"); |
| 4580 | case Legal: Tmp2 = LegalizeOp(Node->getOperand(1)); break; |
| 4581 | case Promote: Tmp2 = PromoteOp(Node->getOperand(1)); break; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4582 | } |
| 4583 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 4584 | |
| 4585 | // Perform FP_ROUND: this is probably overly pessimistic. |
| 4586 | if (NoExcessFPPrecision && Node->getOpcode() != ISD::FCOPYSIGN) |
| 4587 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 4588 | DAG.getValueType(VT)); |
| 4589 | break; |
| 4590 | |
| 4591 | case ISD::UDIV: |
| 4592 | case ISD::UREM: |
| 4593 | // These operators require that their input be zero extended. |
| 4594 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4595 | Tmp2 = PromoteOp(Node->getOperand(1)); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4596 | assert(NVT.isInteger() && "Operators don't apply to FP!"); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4597 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, VT); |
| 4598 | Tmp2 = DAG.getZeroExtendInReg(Tmp2, VT); |
| 4599 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 4600 | break; |
| 4601 | |
| 4602 | case ISD::SHL: |
| 4603 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4604 | Result = DAG.getNode(ISD::SHL, NVT, Tmp1, Node->getOperand(1)); |
| 4605 | break; |
| 4606 | case ISD::SRA: |
| 4607 | // The input value must be properly sign extended. |
| 4608 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4609 | Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp1, |
| 4610 | DAG.getValueType(VT)); |
| 4611 | Result = DAG.getNode(ISD::SRA, NVT, Tmp1, Node->getOperand(1)); |
| 4612 | break; |
| 4613 | case ISD::SRL: |
| 4614 | // The input value must be properly zero extended. |
| 4615 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4616 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, VT); |
| 4617 | Result = DAG.getNode(ISD::SRL, NVT, Tmp1, Node->getOperand(1)); |
| 4618 | break; |
| 4619 | |
| 4620 | case ISD::VAARG: |
| 4621 | Tmp1 = Node->getOperand(0); // Get the chain. |
| 4622 | Tmp2 = Node->getOperand(1); // Get the pointer. |
| 4623 | if (TLI.getOperationAction(ISD::VAARG, VT) == TargetLowering::Custom) { |
| 4624 | Tmp3 = DAG.getVAArg(VT, Tmp1, Tmp2, Node->getOperand(2)); |
Duncan Sands | ac496a1 | 2008-07-04 11:47:58 +0000 | [diff] [blame] | 4625 | Result = TLI.LowerOperation(Tmp3, DAG); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4626 | } else { |
Dan Gohman | 12a9c08 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 4627 | const Value *V = cast<SrcValueSDNode>(Node->getOperand(2))->getValue(); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4628 | SDValue VAList = DAG.getLoad(TLI.getPointerTy(), Tmp1, Tmp2, V, 0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4629 | // Increment the pointer, VAList, to the next vaarg |
| 4630 | Tmp3 = DAG.getNode(ISD::ADD, TLI.getPointerTy(), VAList, |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4631 | DAG.getConstant(VT.getSizeInBits()/8, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4632 | TLI.getPointerTy())); |
| 4633 | // Store the incremented VAList to the legalized pointer |
Dan Gohman | 12a9c08 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 4634 | Tmp3 = DAG.getStore(VAList.getValue(1), Tmp3, Tmp2, V, 0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4635 | // Load the actual argument out of the pointer VAList |
| 4636 | Result = DAG.getExtLoad(ISD::EXTLOAD, NVT, Tmp3, VAList, NULL, 0, VT); |
| 4637 | } |
| 4638 | // Remember that we legalized the chain. |
| 4639 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1))); |
| 4640 | break; |
| 4641 | |
| 4642 | case ISD::LOAD: { |
| 4643 | LoadSDNode *LD = cast<LoadSDNode>(Node); |
| 4644 | ISD::LoadExtType ExtType = ISD::isNON_EXTLoad(Node) |
| 4645 | ? ISD::EXTLOAD : LD->getExtensionType(); |
| 4646 | Result = DAG.getExtLoad(ExtType, NVT, |
| 4647 | LD->getChain(), LD->getBasePtr(), |
| 4648 | LD->getSrcValue(), LD->getSrcValueOffset(), |
Dan Gohman | 9a4c92c | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 4649 | LD->getMemoryVT(), |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4650 | LD->isVolatile(), |
| 4651 | LD->getAlignment()); |
| 4652 | // Remember that we legalized the chain. |
| 4653 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1))); |
| 4654 | break; |
| 4655 | } |
Scott Michel | 67224b2 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 4656 | case ISD::SELECT: { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4657 | Tmp2 = PromoteOp(Node->getOperand(1)); // Legalize the op0 |
| 4658 | Tmp3 = PromoteOp(Node->getOperand(2)); // Legalize the op1 |
Scott Michel | 67224b2 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 4659 | |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4660 | MVT VT2 = Tmp2.getValueType(); |
Scott Michel | 67224b2 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 4661 | assert(VT2 == Tmp3.getValueType() |
Scott Michel | 7b54de0 | 2008-06-03 19:13:20 +0000 | [diff] [blame] | 4662 | && "PromoteOp SELECT: Operands 2 and 3 ValueTypes don't match"); |
| 4663 | // Ensure that the resulting node is at least the same size as the operands' |
| 4664 | // value types, because we cannot assume that TLI.getSetCCValueType() is |
| 4665 | // constant. |
| 4666 | Result = DAG.getNode(ISD::SELECT, VT2, Node->getOperand(0), Tmp2, Tmp3); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4667 | break; |
Scott Michel | 67224b2 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 4668 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4669 | case ISD::SELECT_CC: |
| 4670 | Tmp2 = PromoteOp(Node->getOperand(2)); // True |
| 4671 | Tmp3 = PromoteOp(Node->getOperand(3)); // False |
| 4672 | Result = DAG.getNode(ISD::SELECT_CC, NVT, Node->getOperand(0), |
| 4673 | Node->getOperand(1), Tmp2, Tmp3, Node->getOperand(4)); |
| 4674 | break; |
| 4675 | case ISD::BSWAP: |
| 4676 | Tmp1 = Node->getOperand(0); |
| 4677 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Tmp1); |
| 4678 | Tmp1 = DAG.getNode(ISD::BSWAP, NVT, Tmp1); |
| 4679 | Result = DAG.getNode(ISD::SRL, NVT, Tmp1, |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4680 | DAG.getConstant(NVT.getSizeInBits() - |
| 4681 | VT.getSizeInBits(), |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4682 | TLI.getShiftAmountTy())); |
| 4683 | break; |
| 4684 | case ISD::CTPOP: |
| 4685 | case ISD::CTTZ: |
| 4686 | case ISD::CTLZ: |
| 4687 | // Zero extend the argument |
| 4688 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Node->getOperand(0)); |
| 4689 | // Perform the larger operation, then subtract if needed. |
| 4690 | Tmp1 = DAG.getNode(Node->getOpcode(), NVT, Tmp1); |
| 4691 | switch(Node->getOpcode()) { |
| 4692 | case ISD::CTPOP: |
| 4693 | Result = Tmp1; |
| 4694 | break; |
| 4695 | case ISD::CTTZ: |
| 4696 | // if Tmp1 == sizeinbits(NVT) then Tmp1 = sizeinbits(Old VT) |
Scott Michel | 502151f | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 4697 | Tmp2 = DAG.getSetCC(TLI.getSetCCResultType(Tmp1), Tmp1, |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4698 | DAG.getConstant(NVT.getSizeInBits(), NVT), |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4699 | ISD::SETEQ); |
| 4700 | Result = DAG.getNode(ISD::SELECT, NVT, Tmp2, |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4701 | DAG.getConstant(VT.getSizeInBits(), NVT), Tmp1); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4702 | break; |
| 4703 | case ISD::CTLZ: |
| 4704 | //Tmp1 = Tmp1 - (sizeinbits(NVT) - sizeinbits(Old VT)) |
| 4705 | Result = DAG.getNode(ISD::SUB, NVT, Tmp1, |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4706 | DAG.getConstant(NVT.getSizeInBits() - |
| 4707 | VT.getSizeInBits(), NVT)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4708 | break; |
| 4709 | } |
| 4710 | break; |
| 4711 | case ISD::EXTRACT_SUBVECTOR: |
| 4712 | Result = PromoteOp(ExpandEXTRACT_SUBVECTOR(Op)); |
| 4713 | break; |
| 4714 | case ISD::EXTRACT_VECTOR_ELT: |
| 4715 | Result = PromoteOp(ExpandEXTRACT_VECTOR_ELT(Op)); |
| 4716 | break; |
| 4717 | } |
| 4718 | |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 4719 | assert(Result.getNode() && "Didn't set a result!"); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4720 | |
| 4721 | // Make sure the result is itself legal. |
| 4722 | Result = LegalizeOp(Result); |
| 4723 | |
| 4724 | // Remember that we promoted this! |
| 4725 | AddPromotedOperand(Op, Result); |
| 4726 | return Result; |
| 4727 | } |
| 4728 | |
| 4729 | /// ExpandEXTRACT_VECTOR_ELT - Expand an EXTRACT_VECTOR_ELT operation into |
| 4730 | /// a legal EXTRACT_VECTOR_ELT operation, scalar code, or memory traffic, |
| 4731 | /// based on the vector type. The return type of this matches the element type |
| 4732 | /// of the vector, which may not be legal for the target. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4733 | SDValue SelectionDAGLegalize::ExpandEXTRACT_VECTOR_ELT(SDValue Op) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4734 | // We know that operand #0 is the Vec vector. If the index is a constant |
| 4735 | // or if the invec is a supported hardware type, we can use it. Otherwise, |
| 4736 | // lower to a store then an indexed load. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4737 | SDValue Vec = Op.getOperand(0); |
| 4738 | SDValue Idx = Op.getOperand(1); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4739 | |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4740 | MVT TVT = Vec.getValueType(); |
| 4741 | unsigned NumElems = TVT.getVectorNumElements(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4742 | |
| 4743 | switch (TLI.getOperationAction(ISD::EXTRACT_VECTOR_ELT, TVT)) { |
| 4744 | default: assert(0 && "This action is not supported yet!"); |
| 4745 | case TargetLowering::Custom: { |
| 4746 | Vec = LegalizeOp(Vec); |
| 4747 | Op = DAG.UpdateNodeOperands(Op, Vec, Idx); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4748 | SDValue Tmp3 = TLI.LowerOperation(Op, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 4749 | if (Tmp3.getNode()) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4750 | return Tmp3; |
| 4751 | break; |
| 4752 | } |
| 4753 | case TargetLowering::Legal: |
| 4754 | if (isTypeLegal(TVT)) { |
| 4755 | Vec = LegalizeOp(Vec); |
| 4756 | Op = DAG.UpdateNodeOperands(Op, Vec, Idx); |
Christopher Lamb | cc021a0 | 2007-07-26 03:33:13 +0000 | [diff] [blame] | 4757 | return Op; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4758 | } |
| 4759 | break; |
Mon P Wang | 1448aad | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 4760 | case TargetLowering::Promote: |
| 4761 | assert(TVT.isVector() && "not vector type"); |
| 4762 | // fall thru to expand since vectors are by default are promote |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4763 | case TargetLowering::Expand: |
| 4764 | break; |
| 4765 | } |
| 4766 | |
| 4767 | if (NumElems == 1) { |
| 4768 | // This must be an access of the only element. Return it. |
| 4769 | Op = ScalarizeVectorOp(Vec); |
| 4770 | } else if (!TLI.isTypeLegal(TVT) && isa<ConstantSDNode>(Idx)) { |
Nate Begeman | 2b10fde | 2008-01-29 02:24:00 +0000 | [diff] [blame] | 4771 | unsigned NumLoElts = 1 << Log2_32(NumElems-1); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4772 | ConstantSDNode *CIdx = cast<ConstantSDNode>(Idx); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4773 | SDValue Lo, Hi; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4774 | SplitVectorOp(Vec, Lo, Hi); |
Dan Gohman | faeb4a3 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 4775 | if (CIdx->getZExtValue() < NumLoElts) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4776 | Vec = Lo; |
| 4777 | } else { |
| 4778 | Vec = Hi; |
Dan Gohman | faeb4a3 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 4779 | Idx = DAG.getConstant(CIdx->getZExtValue() - NumLoElts, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4780 | Idx.getValueType()); |
| 4781 | } |
| 4782 | |
| 4783 | // It's now an extract from the appropriate high or low part. Recurse. |
| 4784 | Op = DAG.UpdateNodeOperands(Op, Vec, Idx); |
| 4785 | Op = ExpandEXTRACT_VECTOR_ELT(Op); |
| 4786 | } else { |
| 4787 | // Store the value to a temporary stack slot, then LOAD the scalar |
| 4788 | // element back out. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4789 | SDValue StackPtr = DAG.CreateStackTemporary(Vec.getValueType()); |
| 4790 | SDValue Ch = DAG.getStore(DAG.getEntryNode(), Vec, StackPtr, NULL, 0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4791 | |
| 4792 | // Add the offset to the index. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4793 | unsigned EltSize = Op.getValueType().getSizeInBits()/8; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4794 | Idx = DAG.getNode(ISD::MUL, Idx.getValueType(), Idx, |
| 4795 | DAG.getConstant(EltSize, Idx.getValueType())); |
Bill Wendling | 60f7b4d | 2007-10-18 08:32:37 +0000 | [diff] [blame] | 4796 | |
Duncan Sands | ec142ee | 2008-06-08 20:54:56 +0000 | [diff] [blame] | 4797 | if (Idx.getValueType().bitsGT(TLI.getPointerTy())) |
Chris Lattner | 9f9b880 | 2007-10-19 16:47:35 +0000 | [diff] [blame] | 4798 | Idx = DAG.getNode(ISD::TRUNCATE, TLI.getPointerTy(), Idx); |
Bill Wendling | 60f7b4d | 2007-10-18 08:32:37 +0000 | [diff] [blame] | 4799 | else |
Chris Lattner | 9f9b880 | 2007-10-19 16:47:35 +0000 | [diff] [blame] | 4800 | Idx = DAG.getNode(ISD::ZERO_EXTEND, TLI.getPointerTy(), Idx); |
Bill Wendling | 60f7b4d | 2007-10-18 08:32:37 +0000 | [diff] [blame] | 4801 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4802 | StackPtr = DAG.getNode(ISD::ADD, Idx.getValueType(), Idx, StackPtr); |
| 4803 | |
| 4804 | Op = DAG.getLoad(Op.getValueType(), Ch, StackPtr, NULL, 0); |
| 4805 | } |
| 4806 | return Op; |
| 4807 | } |
| 4808 | |
| 4809 | /// ExpandEXTRACT_SUBVECTOR - Expand a EXTRACT_SUBVECTOR operation. For now |
| 4810 | /// we assume the operation can be split if it is not already legal. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4811 | SDValue SelectionDAGLegalize::ExpandEXTRACT_SUBVECTOR(SDValue Op) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4812 | // We know that operand #0 is the Vec vector. For now we assume the index |
| 4813 | // is a constant and that the extracted result is a supported hardware type. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4814 | SDValue Vec = Op.getOperand(0); |
| 4815 | SDValue Idx = LegalizeOp(Op.getOperand(1)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4816 | |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4817 | unsigned NumElems = Vec.getValueType().getVectorNumElements(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4818 | |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4819 | if (NumElems == Op.getValueType().getVectorNumElements()) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4820 | // This must be an access of the desired vector length. Return it. |
| 4821 | return Vec; |
| 4822 | } |
| 4823 | |
| 4824 | ConstantSDNode *CIdx = cast<ConstantSDNode>(Idx); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4825 | SDValue Lo, Hi; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4826 | SplitVectorOp(Vec, Lo, Hi); |
Dan Gohman | faeb4a3 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 4827 | if (CIdx->getZExtValue() < NumElems/2) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4828 | Vec = Lo; |
| 4829 | } else { |
| 4830 | Vec = Hi; |
Dan Gohman | faeb4a3 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 4831 | Idx = DAG.getConstant(CIdx->getZExtValue() - NumElems/2, |
| 4832 | Idx.getValueType()); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4833 | } |
| 4834 | |
| 4835 | // It's now an extract from the appropriate high or low part. Recurse. |
| 4836 | Op = DAG.UpdateNodeOperands(Op, Vec, Idx); |
| 4837 | return ExpandEXTRACT_SUBVECTOR(Op); |
| 4838 | } |
| 4839 | |
| 4840 | /// LegalizeSetCCOperands - Attempts to create a legal LHS and RHS for a SETCC |
| 4841 | /// with condition CC on the current target. This usually involves legalizing |
| 4842 | /// or promoting the arguments. In the case where LHS and RHS must be expanded, |
| 4843 | /// there may be no choice but to create a new SetCC node to represent the |
| 4844 | /// legalized value of setcc lhs, rhs. In this case, the value is returned in |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4845 | /// LHS, and the SDValue returned in RHS has a nil SDNode value. |
| 4846 | void SelectionDAGLegalize::LegalizeSetCCOperands(SDValue &LHS, |
| 4847 | SDValue &RHS, |
| 4848 | SDValue &CC) { |
| 4849 | SDValue Tmp1, Tmp2, Tmp3, Result; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4850 | |
| 4851 | switch (getTypeAction(LHS.getValueType())) { |
| 4852 | case Legal: |
| 4853 | Tmp1 = LegalizeOp(LHS); // LHS |
| 4854 | Tmp2 = LegalizeOp(RHS); // RHS |
| 4855 | break; |
| 4856 | case Promote: |
| 4857 | Tmp1 = PromoteOp(LHS); // LHS |
| 4858 | Tmp2 = PromoteOp(RHS); // RHS |
| 4859 | |
| 4860 | // If this is an FP compare, the operands have already been extended. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4861 | if (LHS.getValueType().isInteger()) { |
| 4862 | MVT VT = LHS.getValueType(); |
| 4863 | MVT NVT = TLI.getTypeToTransformTo(VT); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4864 | |
| 4865 | // Otherwise, we have to insert explicit sign or zero extends. Note |
| 4866 | // that we could insert sign extends for ALL conditions, but zero extend |
| 4867 | // is cheaper on many machines (an AND instead of two shifts), so prefer |
| 4868 | // it. |
| 4869 | switch (cast<CondCodeSDNode>(CC)->get()) { |
| 4870 | default: assert(0 && "Unknown integer comparison!"); |
| 4871 | case ISD::SETEQ: |
| 4872 | case ISD::SETNE: |
| 4873 | case ISD::SETUGE: |
| 4874 | case ISD::SETUGT: |
| 4875 | case ISD::SETULE: |
| 4876 | case ISD::SETULT: |
| 4877 | // ALL of these operations will work if we either sign or zero extend |
| 4878 | // the operands (including the unsigned comparisons!). Zero extend is |
| 4879 | // usually a simpler/cheaper operation, so prefer it. |
| 4880 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, VT); |
| 4881 | Tmp2 = DAG.getZeroExtendInReg(Tmp2, VT); |
| 4882 | break; |
| 4883 | case ISD::SETGE: |
| 4884 | case ISD::SETGT: |
| 4885 | case ISD::SETLT: |
| 4886 | case ISD::SETLE: |
| 4887 | Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp1, |
| 4888 | DAG.getValueType(VT)); |
| 4889 | Tmp2 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp2, |
| 4890 | DAG.getValueType(VT)); |
Evan Cheng | d901b66 | 2008-10-13 18:46:18 +0000 | [diff] [blame] | 4891 | Tmp1 = LegalizeOp(Tmp1); // Relegalize new nodes. |
| 4892 | Tmp2 = LegalizeOp(Tmp2); // Relegalize new nodes. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4893 | break; |
| 4894 | } |
| 4895 | } |
| 4896 | break; |
| 4897 | case Expand: { |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4898 | MVT VT = LHS.getValueType(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4899 | if (VT == MVT::f32 || VT == MVT::f64) { |
| 4900 | // Expand into one or more soft-fp libcall(s). |
Evan Cheng | 2410863 | 2008-07-01 21:35:46 +0000 | [diff] [blame] | 4901 | RTLIB::Libcall LC1 = RTLIB::UNKNOWN_LIBCALL, LC2 = RTLIB::UNKNOWN_LIBCALL; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4902 | switch (cast<CondCodeSDNode>(CC)->get()) { |
| 4903 | case ISD::SETEQ: |
| 4904 | case ISD::SETOEQ: |
| 4905 | LC1 = (VT == MVT::f32) ? RTLIB::OEQ_F32 : RTLIB::OEQ_F64; |
| 4906 | break; |
| 4907 | case ISD::SETNE: |
| 4908 | case ISD::SETUNE: |
| 4909 | LC1 = (VT == MVT::f32) ? RTLIB::UNE_F32 : RTLIB::UNE_F64; |
| 4910 | break; |
| 4911 | case ISD::SETGE: |
| 4912 | case ISD::SETOGE: |
| 4913 | LC1 = (VT == MVT::f32) ? RTLIB::OGE_F32 : RTLIB::OGE_F64; |
| 4914 | break; |
| 4915 | case ISD::SETLT: |
| 4916 | case ISD::SETOLT: |
| 4917 | LC1 = (VT == MVT::f32) ? RTLIB::OLT_F32 : RTLIB::OLT_F64; |
| 4918 | break; |
| 4919 | case ISD::SETLE: |
| 4920 | case ISD::SETOLE: |
| 4921 | LC1 = (VT == MVT::f32) ? RTLIB::OLE_F32 : RTLIB::OLE_F64; |
| 4922 | break; |
| 4923 | case ISD::SETGT: |
| 4924 | case ISD::SETOGT: |
| 4925 | LC1 = (VT == MVT::f32) ? RTLIB::OGT_F32 : RTLIB::OGT_F64; |
| 4926 | break; |
| 4927 | case ISD::SETUO: |
| 4928 | LC1 = (VT == MVT::f32) ? RTLIB::UO_F32 : RTLIB::UO_F64; |
| 4929 | break; |
| 4930 | case ISD::SETO: |
| 4931 | LC1 = (VT == MVT::f32) ? RTLIB::O_F32 : RTLIB::O_F64; |
| 4932 | break; |
| 4933 | default: |
| 4934 | LC1 = (VT == MVT::f32) ? RTLIB::UO_F32 : RTLIB::UO_F64; |
| 4935 | switch (cast<CondCodeSDNode>(CC)->get()) { |
| 4936 | case ISD::SETONE: |
| 4937 | // SETONE = SETOLT | SETOGT |
| 4938 | LC1 = (VT == MVT::f32) ? RTLIB::OLT_F32 : RTLIB::OLT_F64; |
| 4939 | // Fallthrough |
| 4940 | case ISD::SETUGT: |
| 4941 | LC2 = (VT == MVT::f32) ? RTLIB::OGT_F32 : RTLIB::OGT_F64; |
| 4942 | break; |
| 4943 | case ISD::SETUGE: |
| 4944 | LC2 = (VT == MVT::f32) ? RTLIB::OGE_F32 : RTLIB::OGE_F64; |
| 4945 | break; |
| 4946 | case ISD::SETULT: |
| 4947 | LC2 = (VT == MVT::f32) ? RTLIB::OLT_F32 : RTLIB::OLT_F64; |
| 4948 | break; |
| 4949 | case ISD::SETULE: |
| 4950 | LC2 = (VT == MVT::f32) ? RTLIB::OLE_F32 : RTLIB::OLE_F64; |
| 4951 | break; |
| 4952 | case ISD::SETUEQ: |
| 4953 | LC2 = (VT == MVT::f32) ? RTLIB::OEQ_F32 : RTLIB::OEQ_F64; |
| 4954 | break; |
| 4955 | default: assert(0 && "Unsupported FP setcc!"); |
| 4956 | } |
| 4957 | } |
Duncan Sands | f19591c | 2008-06-30 10:19:09 +0000 | [diff] [blame] | 4958 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4959 | SDValue Dummy; |
| 4960 | SDValue Ops[2] = { LHS, RHS }; |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 4961 | Tmp1 = ExpandLibCall(LC1, DAG.getMergeValues(Ops, 2).getNode(), |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4962 | false /*sign irrelevant*/, Dummy); |
| 4963 | Tmp2 = DAG.getConstant(0, MVT::i32); |
| 4964 | CC = DAG.getCondCode(TLI.getCmpLibcallCC(LC1)); |
| 4965 | if (LC2 != RTLIB::UNKNOWN_LIBCALL) { |
Scott Michel | 502151f | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 4966 | Tmp1 = DAG.getNode(ISD::SETCC, TLI.getSetCCResultType(Tmp1), Tmp1, Tmp2, |
Nate Begeman | 8bb3cb3 | 2008-03-14 00:53:31 +0000 | [diff] [blame] | 4967 | CC); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 4968 | LHS = ExpandLibCall(LC2, DAG.getMergeValues(Ops, 2).getNode(), |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4969 | false /*sign irrelevant*/, Dummy); |
Scott Michel | 502151f | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 4970 | Tmp2 = DAG.getNode(ISD::SETCC, TLI.getSetCCResultType(LHS), LHS, Tmp2, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4971 | DAG.getCondCode(TLI.getCmpLibcallCC(LC2))); |
| 4972 | Tmp1 = DAG.getNode(ISD::OR, Tmp1.getValueType(), Tmp1, Tmp2); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4973 | Tmp2 = SDValue(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4974 | } |
Evan Cheng | 18a1ab1 | 2008-07-07 07:18:09 +0000 | [diff] [blame] | 4975 | LHS = LegalizeOp(Tmp1); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4976 | RHS = Tmp2; |
| 4977 | return; |
| 4978 | } |
| 4979 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4980 | SDValue LHSLo, LHSHi, RHSLo, RHSHi; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 4981 | ExpandOp(LHS, LHSLo, LHSHi); |
Dale Johannesen | 472d15d | 2007-10-06 01:24:11 +0000 | [diff] [blame] | 4982 | ExpandOp(RHS, RHSLo, RHSHi); |
| 4983 | ISD::CondCode CCCode = cast<CondCodeSDNode>(CC)->get(); |
| 4984 | |
| 4985 | if (VT==MVT::ppcf128) { |
| 4986 | // FIXME: This generated code sucks. We want to generate |
Dale Johannesen | 26317b6 | 2008-09-12 00:30:56 +0000 | [diff] [blame] | 4987 | // FCMPU crN, hi1, hi2 |
Dale Johannesen | 472d15d | 2007-10-06 01:24:11 +0000 | [diff] [blame] | 4988 | // BNE crN, L: |
Dale Johannesen | 26317b6 | 2008-09-12 00:30:56 +0000 | [diff] [blame] | 4989 | // FCMPU crN, lo1, lo2 |
Dale Johannesen | 472d15d | 2007-10-06 01:24:11 +0000 | [diff] [blame] | 4990 | // The following can be improved, but not that much. |
Dale Johannesen | 26317b6 | 2008-09-12 00:30:56 +0000 | [diff] [blame] | 4991 | Tmp1 = DAG.getSetCC(TLI.getSetCCResultType(LHSHi), LHSHi, RHSHi, |
| 4992 | ISD::SETOEQ); |
Scott Michel | 502151f | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 4993 | Tmp2 = DAG.getSetCC(TLI.getSetCCResultType(LHSLo), LHSLo, RHSLo, CCCode); |
Dale Johannesen | 472d15d | 2007-10-06 01:24:11 +0000 | [diff] [blame] | 4994 | Tmp3 = DAG.getNode(ISD::AND, Tmp1.getValueType(), Tmp1, Tmp2); |
Dale Johannesen | 26317b6 | 2008-09-12 00:30:56 +0000 | [diff] [blame] | 4995 | Tmp1 = DAG.getSetCC(TLI.getSetCCResultType(LHSHi), LHSHi, RHSHi, |
| 4996 | ISD::SETUNE); |
Scott Michel | 502151f | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 4997 | Tmp2 = DAG.getSetCC(TLI.getSetCCResultType(LHSHi), LHSHi, RHSHi, CCCode); |
Dale Johannesen | 472d15d | 2007-10-06 01:24:11 +0000 | [diff] [blame] | 4998 | Tmp1 = DAG.getNode(ISD::AND, Tmp1.getValueType(), Tmp1, Tmp2); |
| 4999 | Tmp1 = DAG.getNode(ISD::OR, Tmp1.getValueType(), Tmp1, Tmp3); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5000 | Tmp2 = SDValue(); |
Dale Johannesen | 472d15d | 2007-10-06 01:24:11 +0000 | [diff] [blame] | 5001 | break; |
| 5002 | } |
| 5003 | |
| 5004 | switch (CCCode) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5005 | case ISD::SETEQ: |
| 5006 | case ISD::SETNE: |
| 5007 | if (RHSLo == RHSHi) |
| 5008 | if (ConstantSDNode *RHSCST = dyn_cast<ConstantSDNode>(RHSLo)) |
| 5009 | if (RHSCST->isAllOnesValue()) { |
| 5010 | // Comparison to -1. |
| 5011 | Tmp1 = DAG.getNode(ISD::AND, LHSLo.getValueType(), LHSLo, LHSHi); |
| 5012 | Tmp2 = RHSLo; |
| 5013 | break; |
| 5014 | } |
| 5015 | |
| 5016 | Tmp1 = DAG.getNode(ISD::XOR, LHSLo.getValueType(), LHSLo, RHSLo); |
| 5017 | Tmp2 = DAG.getNode(ISD::XOR, LHSLo.getValueType(), LHSHi, RHSHi); |
| 5018 | Tmp1 = DAG.getNode(ISD::OR, Tmp1.getValueType(), Tmp1, Tmp2); |
| 5019 | Tmp2 = DAG.getConstant(0, Tmp1.getValueType()); |
| 5020 | break; |
| 5021 | default: |
| 5022 | // If this is a comparison of the sign bit, just look at the top part. |
| 5023 | // X > -1, x < 0 |
| 5024 | if (ConstantSDNode *CST = dyn_cast<ConstantSDNode>(RHS)) |
| 5025 | if ((cast<CondCodeSDNode>(CC)->get() == ISD::SETLT && |
Dan Gohman | 9d24dc7 | 2008-03-13 22:13:53 +0000 | [diff] [blame] | 5026 | CST->isNullValue()) || // X < 0 |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5027 | (cast<CondCodeSDNode>(CC)->get() == ISD::SETGT && |
| 5028 | CST->isAllOnesValue())) { // X > -1 |
| 5029 | Tmp1 = LHSHi; |
| 5030 | Tmp2 = RHSHi; |
| 5031 | break; |
| 5032 | } |
| 5033 | |
| 5034 | // FIXME: This generated code sucks. |
| 5035 | ISD::CondCode LowCC; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5036 | switch (CCCode) { |
| 5037 | default: assert(0 && "Unknown integer setcc!"); |
| 5038 | case ISD::SETLT: |
| 5039 | case ISD::SETULT: LowCC = ISD::SETULT; break; |
| 5040 | case ISD::SETGT: |
| 5041 | case ISD::SETUGT: LowCC = ISD::SETUGT; break; |
| 5042 | case ISD::SETLE: |
| 5043 | case ISD::SETULE: LowCC = ISD::SETULE; break; |
| 5044 | case ISD::SETGE: |
| 5045 | case ISD::SETUGE: LowCC = ISD::SETUGE; break; |
| 5046 | } |
| 5047 | |
| 5048 | // Tmp1 = lo(op1) < lo(op2) // Always unsigned comparison |
| 5049 | // Tmp2 = hi(op1) < hi(op2) // Signedness depends on operands |
| 5050 | // dest = hi(op1) == hi(op2) ? Tmp1 : Tmp2; |
| 5051 | |
| 5052 | // NOTE: on targets without efficient SELECT of bools, we can always use |
| 5053 | // this identity: (B1 ? B2 : B3) --> (B1 & B2)|(!B1&B3) |
| 5054 | TargetLowering::DAGCombinerInfo DagCombineInfo(DAG, false, true, NULL); |
Scott Michel | 502151f | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 5055 | Tmp1 = TLI.SimplifySetCC(TLI.getSetCCResultType(LHSLo), LHSLo, RHSLo, |
Nate Begeman | 8bb3cb3 | 2008-03-14 00:53:31 +0000 | [diff] [blame] | 5056 | LowCC, false, DagCombineInfo); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5057 | if (!Tmp1.getNode()) |
Scott Michel | 502151f | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 5058 | Tmp1 = DAG.getSetCC(TLI.getSetCCResultType(LHSLo), LHSLo, RHSLo, LowCC); |
| 5059 | Tmp2 = TLI.SimplifySetCC(TLI.getSetCCResultType(LHSHi), LHSHi, RHSHi, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5060 | CCCode, false, DagCombineInfo); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5061 | if (!Tmp2.getNode()) |
Scott Michel | 502151f | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 5062 | Tmp2 = DAG.getNode(ISD::SETCC, TLI.getSetCCResultType(LHSHi), LHSHi, |
Nate Begeman | 8bb3cb3 | 2008-03-14 00:53:31 +0000 | [diff] [blame] | 5063 | RHSHi,CC); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5064 | |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5065 | ConstantSDNode *Tmp1C = dyn_cast<ConstantSDNode>(Tmp1.getNode()); |
| 5066 | ConstantSDNode *Tmp2C = dyn_cast<ConstantSDNode>(Tmp2.getNode()); |
Dan Gohman | 9d24dc7 | 2008-03-13 22:13:53 +0000 | [diff] [blame] | 5067 | if ((Tmp1C && Tmp1C->isNullValue()) || |
| 5068 | (Tmp2C && Tmp2C->isNullValue() && |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5069 | (CCCode == ISD::SETLE || CCCode == ISD::SETGE || |
| 5070 | CCCode == ISD::SETUGE || CCCode == ISD::SETULE)) || |
Dan Gohman | 9d24dc7 | 2008-03-13 22:13:53 +0000 | [diff] [blame] | 5071 | (Tmp2C && Tmp2C->getAPIntValue() == 1 && |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5072 | (CCCode == ISD::SETLT || CCCode == ISD::SETGT || |
| 5073 | CCCode == ISD::SETUGT || CCCode == ISD::SETULT))) { |
| 5074 | // low part is known false, returns high part. |
| 5075 | // For LE / GE, if high part is known false, ignore the low part. |
| 5076 | // For LT / GT, if high part is known true, ignore the low part. |
| 5077 | Tmp1 = Tmp2; |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5078 | Tmp2 = SDValue(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5079 | } else { |
Scott Michel | 502151f | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 5080 | Result = TLI.SimplifySetCC(TLI.getSetCCResultType(LHSHi), LHSHi, RHSHi, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5081 | ISD::SETEQ, false, DagCombineInfo); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5082 | if (!Result.getNode()) |
Scott Michel | 502151f | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 5083 | Result=DAG.getSetCC(TLI.getSetCCResultType(LHSHi), LHSHi, RHSHi, |
Nate Begeman | 8bb3cb3 | 2008-03-14 00:53:31 +0000 | [diff] [blame] | 5084 | ISD::SETEQ); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5085 | Result = LegalizeOp(DAG.getNode(ISD::SELECT, Tmp1.getValueType(), |
| 5086 | Result, Tmp1, Tmp2)); |
| 5087 | Tmp1 = Result; |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5088 | Tmp2 = SDValue(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5089 | } |
| 5090 | } |
| 5091 | } |
| 5092 | } |
| 5093 | LHS = Tmp1; |
| 5094 | RHS = Tmp2; |
| 5095 | } |
| 5096 | |
Evan Cheng | 7134382 | 2008-10-15 02:05:31 +0000 | [diff] [blame] | 5097 | /// LegalizeSetCCCondCode - Legalize a SETCC with given LHS and RHS and |
| 5098 | /// condition code CC on the current target. This routine assumes LHS and rHS |
| 5099 | /// have already been legalized by LegalizeSetCCOperands. It expands SETCC with |
| 5100 | /// illegal condition code into AND / OR of multiple SETCC values. |
| 5101 | void SelectionDAGLegalize::LegalizeSetCCCondCode(MVT VT, |
| 5102 | SDValue &LHS, SDValue &RHS, |
| 5103 | SDValue &CC) { |
| 5104 | MVT OpVT = LHS.getValueType(); |
| 5105 | ISD::CondCode CCCode = cast<CondCodeSDNode>(CC)->get(); |
| 5106 | switch (TLI.getCondCodeAction(CCCode, OpVT)) { |
| 5107 | default: assert(0 && "Unknown condition code action!"); |
| 5108 | case TargetLowering::Legal: |
| 5109 | // Nothing to do. |
| 5110 | break; |
| 5111 | case TargetLowering::Expand: { |
| 5112 | ISD::CondCode CC1 = ISD::SETCC_INVALID, CC2 = ISD::SETCC_INVALID; |
| 5113 | unsigned Opc = 0; |
| 5114 | switch (CCCode) { |
| 5115 | default: assert(0 && "Don't know how to expand this condition!"); abort(); |
Dan Gohman | 2b5b9ca | 2008-10-21 03:12:54 +0000 | [diff] [blame] | 5116 | case ISD::SETOEQ: CC1 = ISD::SETEQ; CC2 = ISD::SETO; Opc = ISD::AND; break; |
| 5117 | case ISD::SETOGT: CC1 = ISD::SETGT; CC2 = ISD::SETO; Opc = ISD::AND; break; |
| 5118 | case ISD::SETOGE: CC1 = ISD::SETGE; CC2 = ISD::SETO; Opc = ISD::AND; break; |
| 5119 | case ISD::SETOLT: CC1 = ISD::SETLT; CC2 = ISD::SETO; Opc = ISD::AND; break; |
| 5120 | case ISD::SETOLE: CC1 = ISD::SETLE; CC2 = ISD::SETO; Opc = ISD::AND; break; |
| 5121 | case ISD::SETONE: CC1 = ISD::SETNE; CC2 = ISD::SETO; Opc = ISD::AND; break; |
| 5122 | case ISD::SETUEQ: CC1 = ISD::SETEQ; CC2 = ISD::SETUO; Opc = ISD::OR; break; |
| 5123 | case ISD::SETUGT: CC1 = ISD::SETGT; CC2 = ISD::SETUO; Opc = ISD::OR; break; |
| 5124 | case ISD::SETUGE: CC1 = ISD::SETGE; CC2 = ISD::SETUO; Opc = ISD::OR; break; |
| 5125 | case ISD::SETULT: CC1 = ISD::SETLT; CC2 = ISD::SETUO; Opc = ISD::OR; break; |
| 5126 | case ISD::SETULE: CC1 = ISD::SETLE; CC2 = ISD::SETUO; Opc = ISD::OR; break; |
| 5127 | case ISD::SETUNE: CC1 = ISD::SETNE; CC2 = ISD::SETUO; Opc = ISD::OR; break; |
Evan Cheng | 7134382 | 2008-10-15 02:05:31 +0000 | [diff] [blame] | 5128 | // FIXME: Implement more expansions. |
| 5129 | } |
| 5130 | |
| 5131 | SDValue SetCC1 = DAG.getSetCC(VT, LHS, RHS, CC1); |
| 5132 | SDValue SetCC2 = DAG.getSetCC(VT, LHS, RHS, CC2); |
| 5133 | LHS = DAG.getNode(Opc, VT, SetCC1, SetCC2); |
| 5134 | RHS = SDValue(); |
| 5135 | CC = SDValue(); |
| 5136 | break; |
| 5137 | } |
| 5138 | } |
| 5139 | } |
| 5140 | |
Chris Lattner | b7d0aaa | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 5141 | /// EmitStackConvert - Emit a store/load combination to the stack. This stores |
| 5142 | /// SrcOp to a stack slot of type SlotVT, truncating it if needed. It then does |
| 5143 | /// a load from the stack slot to DestVT, extending it if needed. |
| 5144 | /// The resultant code need not be legal. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5145 | SDValue SelectionDAGLegalize::EmitStackConvert(SDValue SrcOp, |
| 5146 | MVT SlotVT, |
| 5147 | MVT DestVT) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5148 | // Create the stack frame object. |
Mon P Wang | 55854cc | 2008-07-05 20:40:31 +0000 | [diff] [blame] | 5149 | unsigned SrcAlign = TLI.getTargetData()->getPrefTypeAlignment( |
| 5150 | SrcOp.getValueType().getTypeForMVT()); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5151 | SDValue FIPtr = DAG.CreateStackTemporary(SlotVT, SrcAlign); |
Mon P Wang | 55854cc | 2008-07-05 20:40:31 +0000 | [diff] [blame] | 5152 | |
Dan Gohman | 20e3796 | 2008-02-11 18:58:42 +0000 | [diff] [blame] | 5153 | FrameIndexSDNode *StackPtrFI = cast<FrameIndexSDNode>(FIPtr); |
Dan Gohman | 12a9c08 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5154 | int SPFI = StackPtrFI->getIndex(); |
Mon P Wang | 55854cc | 2008-07-05 20:40:31 +0000 | [diff] [blame] | 5155 | |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5156 | unsigned SrcSize = SrcOp.getValueType().getSizeInBits(); |
| 5157 | unsigned SlotSize = SlotVT.getSizeInBits(); |
| 5158 | unsigned DestSize = DestVT.getSizeInBits(); |
Mon P Wang | 55854cc | 2008-07-05 20:40:31 +0000 | [diff] [blame] | 5159 | unsigned DestAlign = TLI.getTargetData()->getPrefTypeAlignment( |
| 5160 | DestVT.getTypeForMVT()); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5161 | |
Chris Lattner | b7d0aaa | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 5162 | // Emit a store to the stack slot. Use a truncstore if the input value is |
| 5163 | // later than DestVT. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5164 | SDValue Store; |
Mon P Wang | 55854cc | 2008-07-05 20:40:31 +0000 | [diff] [blame] | 5165 | |
Chris Lattner | b7d0aaa | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 5166 | if (SrcSize > SlotSize) |
Dan Gohman | 12a9c08 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5167 | Store = DAG.getTruncStore(DAG.getEntryNode(), SrcOp, FIPtr, |
Dan Gohman | 1fc34bc | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 5168 | PseudoSourceValue::getFixedStack(SPFI), 0, |
| 5169 | SlotVT, false, SrcAlign); |
Chris Lattner | b7d0aaa | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 5170 | else { |
| 5171 | assert(SrcSize == SlotSize && "Invalid store"); |
Dan Gohman | 12a9c08 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5172 | Store = DAG.getStore(DAG.getEntryNode(), SrcOp, FIPtr, |
Dan Gohman | 1fc34bc | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 5173 | PseudoSourceValue::getFixedStack(SPFI), 0, |
Mon P Wang | 55854cc | 2008-07-05 20:40:31 +0000 | [diff] [blame] | 5174 | false, SrcAlign); |
Chris Lattner | b7d0aaa | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 5175 | } |
| 5176 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5177 | // Result is a load from the stack slot. |
Chris Lattner | b7d0aaa | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 5178 | if (SlotSize == DestSize) |
Mon P Wang | 55854cc | 2008-07-05 20:40:31 +0000 | [diff] [blame] | 5179 | return DAG.getLoad(DestVT, Store, FIPtr, NULL, 0, false, DestAlign); |
Chris Lattner | b7d0aaa | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 5180 | |
| 5181 | assert(SlotSize < DestSize && "Unknown extension!"); |
Mon P Wang | 55854cc | 2008-07-05 20:40:31 +0000 | [diff] [blame] | 5182 | return DAG.getExtLoad(ISD::EXTLOAD, DestVT, Store, FIPtr, NULL, 0, SlotVT, |
| 5183 | false, DestAlign); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5184 | } |
| 5185 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5186 | SDValue SelectionDAGLegalize::ExpandSCALAR_TO_VECTOR(SDNode *Node) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5187 | // Create a vector sized/aligned stack slot, store the value to element #0, |
| 5188 | // then load the whole vector back out. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5189 | SDValue StackPtr = DAG.CreateStackTemporary(Node->getValueType(0)); |
Dan Gohman | 12a9c08 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5190 | |
Dan Gohman | 20e3796 | 2008-02-11 18:58:42 +0000 | [diff] [blame] | 5191 | FrameIndexSDNode *StackPtrFI = cast<FrameIndexSDNode>(StackPtr); |
Dan Gohman | 12a9c08 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5192 | int SPFI = StackPtrFI->getIndex(); |
| 5193 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5194 | SDValue Ch = DAG.getStore(DAG.getEntryNode(), Node->getOperand(0), StackPtr, |
Dan Gohman | 1fc34bc | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 5195 | PseudoSourceValue::getFixedStack(SPFI), 0); |
Dan Gohman | 12a9c08 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5196 | return DAG.getLoad(Node->getValueType(0), Ch, StackPtr, |
Dan Gohman | 1fc34bc | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 5197 | PseudoSourceValue::getFixedStack(SPFI), 0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5198 | } |
| 5199 | |
| 5200 | |
| 5201 | /// ExpandBUILD_VECTOR - Expand a BUILD_VECTOR node on targets that don't |
| 5202 | /// support the operation, but do support the resultant vector type. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5203 | SDValue SelectionDAGLegalize::ExpandBUILD_VECTOR(SDNode *Node) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5204 | |
| 5205 | // If the only non-undef value is the low element, turn this into a |
| 5206 | // SCALAR_TO_VECTOR node. If this is { X, X, X, X }, determine X. |
| 5207 | unsigned NumElems = Node->getNumOperands(); |
| 5208 | bool isOnlyLowElement = true; |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5209 | SDValue SplatValue = Node->getOperand(0); |
Chris Lattner | d8cee73 | 2008-03-09 00:29:42 +0000 | [diff] [blame] | 5210 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5211 | // FIXME: it would be far nicer to change this into map<SDValue,uint64_t> |
Chris Lattner | d8cee73 | 2008-03-09 00:29:42 +0000 | [diff] [blame] | 5212 | // and use a bitmask instead of a list of elements. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5213 | std::map<SDValue, std::vector<unsigned> > Values; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5214 | Values[SplatValue].push_back(0); |
| 5215 | bool isConstant = true; |
| 5216 | if (!isa<ConstantFPSDNode>(SplatValue) && !isa<ConstantSDNode>(SplatValue) && |
| 5217 | SplatValue.getOpcode() != ISD::UNDEF) |
| 5218 | isConstant = false; |
| 5219 | |
| 5220 | for (unsigned i = 1; i < NumElems; ++i) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5221 | SDValue V = Node->getOperand(i); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5222 | Values[V].push_back(i); |
| 5223 | if (V.getOpcode() != ISD::UNDEF) |
| 5224 | isOnlyLowElement = false; |
| 5225 | if (SplatValue != V) |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5226 | SplatValue = SDValue(0,0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5227 | |
| 5228 | // If this isn't a constant element or an undef, we can't use a constant |
| 5229 | // pool load. |
| 5230 | if (!isa<ConstantFPSDNode>(V) && !isa<ConstantSDNode>(V) && |
| 5231 | V.getOpcode() != ISD::UNDEF) |
| 5232 | isConstant = false; |
| 5233 | } |
| 5234 | |
| 5235 | if (isOnlyLowElement) { |
| 5236 | // If the low element is an undef too, then this whole things is an undef. |
| 5237 | if (Node->getOperand(0).getOpcode() == ISD::UNDEF) |
| 5238 | return DAG.getNode(ISD::UNDEF, Node->getValueType(0)); |
| 5239 | // Otherwise, turn this into a scalar_to_vector node. |
| 5240 | return DAG.getNode(ISD::SCALAR_TO_VECTOR, Node->getValueType(0), |
| 5241 | Node->getOperand(0)); |
| 5242 | } |
| 5243 | |
| 5244 | // If all elements are constants, create a load from the constant pool. |
| 5245 | if (isConstant) { |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5246 | MVT VT = Node->getValueType(0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5247 | std::vector<Constant*> CV; |
| 5248 | for (unsigned i = 0, e = NumElems; i != e; ++i) { |
| 5249 | if (ConstantFPSDNode *V = |
| 5250 | dyn_cast<ConstantFPSDNode>(Node->getOperand(i))) { |
Dan Gohman | c1f3a07 | 2008-09-12 18:08:03 +0000 | [diff] [blame] | 5251 | CV.push_back(const_cast<ConstantFP *>(V->getConstantFPValue())); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5252 | } else if (ConstantSDNode *V = |
Chris Lattner | 5e0610f | 2008-04-20 00:41:09 +0000 | [diff] [blame] | 5253 | dyn_cast<ConstantSDNode>(Node->getOperand(i))) { |
Dan Gohman | c1f3a07 | 2008-09-12 18:08:03 +0000 | [diff] [blame] | 5254 | CV.push_back(const_cast<ConstantInt *>(V->getConstantIntValue())); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5255 | } else { |
| 5256 | assert(Node->getOperand(i).getOpcode() == ISD::UNDEF); |
Chris Lattner | 5e0610f | 2008-04-20 00:41:09 +0000 | [diff] [blame] | 5257 | const Type *OpNTy = |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5258 | Node->getOperand(0).getValueType().getTypeForMVT(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5259 | CV.push_back(UndefValue::get(OpNTy)); |
| 5260 | } |
| 5261 | } |
| 5262 | Constant *CP = ConstantVector::get(CV); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5263 | SDValue CPIdx = DAG.getConstantPool(CP, TLI.getPointerTy()); |
Dan Gohman | 04637d1 | 2008-09-16 22:05:41 +0000 | [diff] [blame] | 5264 | unsigned Alignment = 1 << cast<ConstantPoolSDNode>(CPIdx)->getAlignment(); |
Dan Gohman | 12a9c08 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5265 | return DAG.getLoad(VT, DAG.getEntryNode(), CPIdx, |
Dan Gohman | 04637d1 | 2008-09-16 22:05:41 +0000 | [diff] [blame] | 5266 | PseudoSourceValue::getConstantPool(), 0, |
| 5267 | false, Alignment); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5268 | } |
| 5269 | |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5270 | if (SplatValue.getNode()) { // Splat of one value? |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5271 | // Build the shuffle constant vector: <0, 0, 0, 0> |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5272 | MVT MaskVT = MVT::getIntVectorWithNumElements(NumElems); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5273 | SDValue Zero = DAG.getConstant(0, MaskVT.getVectorElementType()); |
| 5274 | std::vector<SDValue> ZeroVec(NumElems, Zero); |
| 5275 | SDValue SplatMask = DAG.getNode(ISD::BUILD_VECTOR, MaskVT, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5276 | &ZeroVec[0], ZeroVec.size()); |
| 5277 | |
| 5278 | // If the target supports VECTOR_SHUFFLE and this shuffle mask, use it. |
| 5279 | if (isShuffleLegal(Node->getValueType(0), SplatMask)) { |
| 5280 | // Get the splatted value into the low element of a vector register. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5281 | SDValue LowValVec = |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5282 | DAG.getNode(ISD::SCALAR_TO_VECTOR, Node->getValueType(0), SplatValue); |
| 5283 | |
| 5284 | // Return shuffle(LowValVec, undef, <0,0,0,0>) |
| 5285 | return DAG.getNode(ISD::VECTOR_SHUFFLE, Node->getValueType(0), LowValVec, |
| 5286 | DAG.getNode(ISD::UNDEF, Node->getValueType(0)), |
| 5287 | SplatMask); |
| 5288 | } |
| 5289 | } |
| 5290 | |
| 5291 | // If there are only two unique elements, we may be able to turn this into a |
| 5292 | // vector shuffle. |
| 5293 | if (Values.size() == 2) { |
Chris Lattner | d8cee73 | 2008-03-09 00:29:42 +0000 | [diff] [blame] | 5294 | // Get the two values in deterministic order. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5295 | SDValue Val1 = Node->getOperand(1); |
| 5296 | SDValue Val2; |
| 5297 | std::map<SDValue, std::vector<unsigned> >::iterator MI = Values.begin(); |
Chris Lattner | d8cee73 | 2008-03-09 00:29:42 +0000 | [diff] [blame] | 5298 | if (MI->first != Val1) |
| 5299 | Val2 = MI->first; |
| 5300 | else |
| 5301 | Val2 = (++MI)->first; |
| 5302 | |
| 5303 | // If Val1 is an undef, make sure end ends up as Val2, to ensure that our |
| 5304 | // vector shuffle has the undef vector on the RHS. |
| 5305 | if (Val1.getOpcode() == ISD::UNDEF) |
| 5306 | std::swap(Val1, Val2); |
| 5307 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5308 | // Build the shuffle constant vector: e.g. <0, 4, 0, 4> |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5309 | MVT MaskVT = MVT::getIntVectorWithNumElements(NumElems); |
| 5310 | MVT MaskEltVT = MaskVT.getVectorElementType(); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5311 | std::vector<SDValue> MaskVec(NumElems); |
Chris Lattner | d8cee73 | 2008-03-09 00:29:42 +0000 | [diff] [blame] | 5312 | |
| 5313 | // Set elements of the shuffle mask for Val1. |
| 5314 | std::vector<unsigned> &Val1Elts = Values[Val1]; |
| 5315 | for (unsigned i = 0, e = Val1Elts.size(); i != e; ++i) |
| 5316 | MaskVec[Val1Elts[i]] = DAG.getConstant(0, MaskEltVT); |
| 5317 | |
| 5318 | // Set elements of the shuffle mask for Val2. |
| 5319 | std::vector<unsigned> &Val2Elts = Values[Val2]; |
| 5320 | for (unsigned i = 0, e = Val2Elts.size(); i != e; ++i) |
| 5321 | if (Val2.getOpcode() != ISD::UNDEF) |
| 5322 | MaskVec[Val2Elts[i]] = DAG.getConstant(NumElems, MaskEltVT); |
| 5323 | else |
| 5324 | MaskVec[Val2Elts[i]] = DAG.getNode(ISD::UNDEF, MaskEltVT); |
| 5325 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5326 | SDValue ShuffleMask = DAG.getNode(ISD::BUILD_VECTOR, MaskVT, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5327 | &MaskVec[0], MaskVec.size()); |
| 5328 | |
Chris Lattner | d8cee73 | 2008-03-09 00:29:42 +0000 | [diff] [blame] | 5329 | // If the target supports SCALAR_TO_VECTOR and this shuffle mask, use it. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5330 | if (TLI.isOperationLegal(ISD::SCALAR_TO_VECTOR, Node->getValueType(0)) && |
| 5331 | isShuffleLegal(Node->getValueType(0), ShuffleMask)) { |
Chris Lattner | d8cee73 | 2008-03-09 00:29:42 +0000 | [diff] [blame] | 5332 | Val1 = DAG.getNode(ISD::SCALAR_TO_VECTOR, Node->getValueType(0), Val1); |
| 5333 | Val2 = DAG.getNode(ISD::SCALAR_TO_VECTOR, Node->getValueType(0), Val2); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5334 | SDValue Ops[] = { Val1, Val2, ShuffleMask }; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5335 | |
| 5336 | // Return shuffle(LoValVec, HiValVec, <0,1,0,1>) |
Chris Lattner | d8cee73 | 2008-03-09 00:29:42 +0000 | [diff] [blame] | 5337 | return DAG.getNode(ISD::VECTOR_SHUFFLE, Node->getValueType(0), Ops, 3); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5338 | } |
| 5339 | } |
| 5340 | |
| 5341 | // Otherwise, we can't handle this case efficiently. Allocate a sufficiently |
| 5342 | // aligned object on the stack, store each element into it, then load |
| 5343 | // the result as a vector. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5344 | MVT VT = Node->getValueType(0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5345 | // Create the stack frame object. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5346 | SDValue FIPtr = DAG.CreateStackTemporary(VT); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5347 | |
| 5348 | // Emit a store of each element to the stack slot. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5349 | SmallVector<SDValue, 8> Stores; |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5350 | unsigned TypeByteSize = Node->getOperand(0).getValueType().getSizeInBits()/8; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5351 | // Store (in the right endianness) the elements to memory. |
| 5352 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) { |
| 5353 | // Ignore undef elements. |
| 5354 | if (Node->getOperand(i).getOpcode() == ISD::UNDEF) continue; |
| 5355 | |
| 5356 | unsigned Offset = TypeByteSize*i; |
| 5357 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5358 | SDValue Idx = DAG.getConstant(Offset, FIPtr.getValueType()); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5359 | Idx = DAG.getNode(ISD::ADD, FIPtr.getValueType(), FIPtr, Idx); |
| 5360 | |
| 5361 | Stores.push_back(DAG.getStore(DAG.getEntryNode(), Node->getOperand(i), Idx, |
| 5362 | NULL, 0)); |
| 5363 | } |
| 5364 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5365 | SDValue StoreChain; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5366 | if (!Stores.empty()) // Not all undef elements? |
| 5367 | StoreChain = DAG.getNode(ISD::TokenFactor, MVT::Other, |
| 5368 | &Stores[0], Stores.size()); |
| 5369 | else |
| 5370 | StoreChain = DAG.getEntryNode(); |
| 5371 | |
| 5372 | // Result is a load from the stack slot. |
| 5373 | return DAG.getLoad(VT, StoreChain, FIPtr, NULL, 0); |
| 5374 | } |
| 5375 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5376 | void SelectionDAGLegalize::ExpandShiftParts(unsigned NodeOp, |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5377 | SDValue Op, SDValue Amt, |
| 5378 | SDValue &Lo, SDValue &Hi) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5379 | // Expand the subcomponents. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5380 | SDValue LHSL, LHSH; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5381 | ExpandOp(Op, LHSL, LHSH); |
| 5382 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5383 | SDValue Ops[] = { LHSL, LHSH, Amt }; |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5384 | MVT VT = LHSL.getValueType(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5385 | Lo = DAG.getNode(NodeOp, DAG.getNodeValueTypes(VT, VT), 2, Ops, 3); |
| 5386 | Hi = Lo.getValue(1); |
| 5387 | } |
| 5388 | |
| 5389 | |
| 5390 | /// ExpandShift - Try to find a clever way to expand this shift operation out to |
| 5391 | /// smaller elements. If we can't find a way that is more efficient than a |
| 5392 | /// libcall on this target, return false. Otherwise, return true with the |
| 5393 | /// low-parts expanded into Lo and Hi. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5394 | bool SelectionDAGLegalize::ExpandShift(unsigned Opc, SDValue Op,SDValue Amt, |
| 5395 | SDValue &Lo, SDValue &Hi) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5396 | assert((Opc == ISD::SHL || Opc == ISD::SRA || Opc == ISD::SRL) && |
| 5397 | "This is not a shift!"); |
| 5398 | |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5399 | MVT NVT = TLI.getTypeToTransformTo(Op.getValueType()); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5400 | SDValue ShAmt = LegalizeOp(Amt); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5401 | MVT ShTy = ShAmt.getValueType(); |
| 5402 | unsigned ShBits = ShTy.getSizeInBits(); |
| 5403 | unsigned VTBits = Op.getValueType().getSizeInBits(); |
| 5404 | unsigned NVTBits = NVT.getSizeInBits(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5405 | |
Chris Lattner | 8c93145 | 2007-10-14 20:35:12 +0000 | [diff] [blame] | 5406 | // Handle the case when Amt is an immediate. |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5407 | if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Amt.getNode())) { |
Dan Gohman | faeb4a3 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 5408 | unsigned Cst = CN->getZExtValue(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5409 | // Expand the incoming operand to be shifted, so that we have its parts |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5410 | SDValue InL, InH; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5411 | ExpandOp(Op, InL, InH); |
| 5412 | switch(Opc) { |
| 5413 | case ISD::SHL: |
| 5414 | if (Cst > VTBits) { |
| 5415 | Lo = DAG.getConstant(0, NVT); |
| 5416 | Hi = DAG.getConstant(0, NVT); |
| 5417 | } else if (Cst > NVTBits) { |
| 5418 | Lo = DAG.getConstant(0, NVT); |
| 5419 | Hi = DAG.getNode(ISD::SHL, NVT, InL, DAG.getConstant(Cst-NVTBits,ShTy)); |
| 5420 | } else if (Cst == NVTBits) { |
| 5421 | Lo = DAG.getConstant(0, NVT); |
| 5422 | Hi = InL; |
| 5423 | } else { |
| 5424 | Lo = DAG.getNode(ISD::SHL, NVT, InL, DAG.getConstant(Cst, ShTy)); |
| 5425 | Hi = DAG.getNode(ISD::OR, NVT, |
| 5426 | DAG.getNode(ISD::SHL, NVT, InH, DAG.getConstant(Cst, ShTy)), |
| 5427 | DAG.getNode(ISD::SRL, NVT, InL, DAG.getConstant(NVTBits-Cst, ShTy))); |
| 5428 | } |
| 5429 | return true; |
| 5430 | case ISD::SRL: |
| 5431 | if (Cst > VTBits) { |
| 5432 | Lo = DAG.getConstant(0, NVT); |
| 5433 | Hi = DAG.getConstant(0, NVT); |
| 5434 | } else if (Cst > NVTBits) { |
| 5435 | Lo = DAG.getNode(ISD::SRL, NVT, InH, DAG.getConstant(Cst-NVTBits,ShTy)); |
| 5436 | Hi = DAG.getConstant(0, NVT); |
| 5437 | } else if (Cst == NVTBits) { |
| 5438 | Lo = InH; |
| 5439 | Hi = DAG.getConstant(0, NVT); |
| 5440 | } else { |
| 5441 | Lo = DAG.getNode(ISD::OR, NVT, |
| 5442 | DAG.getNode(ISD::SRL, NVT, InL, DAG.getConstant(Cst, ShTy)), |
| 5443 | DAG.getNode(ISD::SHL, NVT, InH, DAG.getConstant(NVTBits-Cst, ShTy))); |
| 5444 | Hi = DAG.getNode(ISD::SRL, NVT, InH, DAG.getConstant(Cst, ShTy)); |
| 5445 | } |
| 5446 | return true; |
| 5447 | case ISD::SRA: |
| 5448 | if (Cst > VTBits) { |
| 5449 | Hi = Lo = DAG.getNode(ISD::SRA, NVT, InH, |
| 5450 | DAG.getConstant(NVTBits-1, ShTy)); |
| 5451 | } else if (Cst > NVTBits) { |
| 5452 | Lo = DAG.getNode(ISD::SRA, NVT, InH, |
| 5453 | DAG.getConstant(Cst-NVTBits, ShTy)); |
| 5454 | Hi = DAG.getNode(ISD::SRA, NVT, InH, |
| 5455 | DAG.getConstant(NVTBits-1, ShTy)); |
| 5456 | } else if (Cst == NVTBits) { |
| 5457 | Lo = InH; |
| 5458 | Hi = DAG.getNode(ISD::SRA, NVT, InH, |
| 5459 | DAG.getConstant(NVTBits-1, ShTy)); |
| 5460 | } else { |
| 5461 | Lo = DAG.getNode(ISD::OR, NVT, |
| 5462 | DAG.getNode(ISD::SRL, NVT, InL, DAG.getConstant(Cst, ShTy)), |
| 5463 | DAG.getNode(ISD::SHL, NVT, InH, DAG.getConstant(NVTBits-Cst, ShTy))); |
| 5464 | Hi = DAG.getNode(ISD::SRA, NVT, InH, DAG.getConstant(Cst, ShTy)); |
| 5465 | } |
| 5466 | return true; |
| 5467 | } |
| 5468 | } |
| 5469 | |
| 5470 | // Okay, the shift amount isn't constant. However, if we can tell that it is |
| 5471 | // >= 32 or < 32, we can still simplify it, without knowing the actual value. |
Dan Gohman | ece0a88 | 2008-02-20 16:57:27 +0000 | [diff] [blame] | 5472 | APInt Mask = APInt::getHighBitsSet(ShBits, ShBits - Log2_32(NVTBits)); |
| 5473 | APInt KnownZero, KnownOne; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5474 | DAG.ComputeMaskedBits(Amt, Mask, KnownZero, KnownOne); |
| 5475 | |
Dan Gohman | eb3f117 | 2008-02-22 01:12:31 +0000 | [diff] [blame] | 5476 | // If we know that if any of the high bits of the shift amount are one, then |
| 5477 | // we can do this as a couple of simple shifts. |
Dan Gohman | ece0a88 | 2008-02-20 16:57:27 +0000 | [diff] [blame] | 5478 | if (KnownOne.intersects(Mask)) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5479 | // Mask out the high bit, which we know is set. |
| 5480 | Amt = DAG.getNode(ISD::AND, Amt.getValueType(), Amt, |
Dan Gohman | ece0a88 | 2008-02-20 16:57:27 +0000 | [diff] [blame] | 5481 | DAG.getConstant(~Mask, Amt.getValueType())); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5482 | |
| 5483 | // Expand the incoming operand to be shifted, so that we have its parts |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5484 | SDValue InL, InH; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5485 | ExpandOp(Op, InL, InH); |
| 5486 | switch(Opc) { |
| 5487 | case ISD::SHL: |
| 5488 | Lo = DAG.getConstant(0, NVT); // Low part is zero. |
| 5489 | Hi = DAG.getNode(ISD::SHL, NVT, InL, Amt); // High part from Lo part. |
| 5490 | return true; |
| 5491 | case ISD::SRL: |
| 5492 | Hi = DAG.getConstant(0, NVT); // Hi part is zero. |
| 5493 | Lo = DAG.getNode(ISD::SRL, NVT, InH, Amt); // Lo part from Hi part. |
| 5494 | return true; |
| 5495 | case ISD::SRA: |
| 5496 | Hi = DAG.getNode(ISD::SRA, NVT, InH, // Sign extend high part. |
| 5497 | DAG.getConstant(NVTBits-1, Amt.getValueType())); |
| 5498 | Lo = DAG.getNode(ISD::SRA, NVT, InH, Amt); // Lo part from Hi part. |
| 5499 | return true; |
| 5500 | } |
| 5501 | } |
| 5502 | |
Dan Gohman | eb3f117 | 2008-02-22 01:12:31 +0000 | [diff] [blame] | 5503 | // If we know that the high bits of the shift amount are all zero, then we can |
| 5504 | // do this as a couple of simple shifts. |
| 5505 | if ((KnownZero & Mask) == Mask) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5506 | // Compute 32-amt. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5507 | SDValue Amt2 = DAG.getNode(ISD::SUB, Amt.getValueType(), |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5508 | DAG.getConstant(NVTBits, Amt.getValueType()), |
| 5509 | Amt); |
| 5510 | |
| 5511 | // Expand the incoming operand to be shifted, so that we have its parts |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5512 | SDValue InL, InH; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5513 | ExpandOp(Op, InL, InH); |
| 5514 | switch(Opc) { |
| 5515 | case ISD::SHL: |
| 5516 | Lo = DAG.getNode(ISD::SHL, NVT, InL, Amt); |
| 5517 | Hi = DAG.getNode(ISD::OR, NVT, |
| 5518 | DAG.getNode(ISD::SHL, NVT, InH, Amt), |
| 5519 | DAG.getNode(ISD::SRL, NVT, InL, Amt2)); |
| 5520 | return true; |
| 5521 | case ISD::SRL: |
| 5522 | Hi = DAG.getNode(ISD::SRL, NVT, InH, Amt); |
| 5523 | Lo = DAG.getNode(ISD::OR, NVT, |
| 5524 | DAG.getNode(ISD::SRL, NVT, InL, Amt), |
| 5525 | DAG.getNode(ISD::SHL, NVT, InH, Amt2)); |
| 5526 | return true; |
| 5527 | case ISD::SRA: |
| 5528 | Hi = DAG.getNode(ISD::SRA, NVT, InH, Amt); |
| 5529 | Lo = DAG.getNode(ISD::OR, NVT, |
| 5530 | DAG.getNode(ISD::SRL, NVT, InL, Amt), |
| 5531 | DAG.getNode(ISD::SHL, NVT, InH, Amt2)); |
| 5532 | return true; |
| 5533 | } |
| 5534 | } |
| 5535 | |
| 5536 | return false; |
| 5537 | } |
| 5538 | |
| 5539 | |
| 5540 | // ExpandLibCall - Expand a node into a call to a libcall. If the result value |
| 5541 | // does not fit into a register, return the lo part and set the hi part to the |
| 5542 | // by-reg argument. If it does fit into a single register, return the result |
| 5543 | // and leave the Hi part unset. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5544 | SDValue SelectionDAGLegalize::ExpandLibCall(RTLIB::Libcall LC, SDNode *Node, |
| 5545 | bool isSigned, SDValue &Hi) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5546 | assert(!IsLegalizingCall && "Cannot overlap legalization of calls!"); |
| 5547 | // The input chain to this libcall is the entry node of the function. |
| 5548 | // Legalizing the call will automatically add the previous call to the |
| 5549 | // dependence. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5550 | SDValue InChain = DAG.getEntryNode(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5551 | |
| 5552 | TargetLowering::ArgListTy Args; |
| 5553 | TargetLowering::ArgListEntry Entry; |
| 5554 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) { |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5555 | MVT ArgVT = Node->getOperand(i).getValueType(); |
| 5556 | const Type *ArgTy = ArgVT.getTypeForMVT(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5557 | Entry.Node = Node->getOperand(i); Entry.Ty = ArgTy; |
| 5558 | Entry.isSExt = isSigned; |
Duncan Sands | ead972e | 2008-02-14 17:28:50 +0000 | [diff] [blame] | 5559 | Entry.isZExt = !isSigned; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5560 | Args.push_back(Entry); |
| 5561 | } |
Bill Wendling | fef0605 | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 5562 | SDValue Callee = DAG.getExternalSymbol(TLI.getLibcallName(LC), |
Mon P Wang | 1448aad | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 5563 | TLI.getPointerTy()); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5564 | |
| 5565 | // Splice the libcall in wherever FindInputOutputChains tells us to. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5566 | const Type *RetTy = Node->getValueType(0).getTypeForMVT(); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5567 | std::pair<SDValue,SDValue> CallInfo = |
Dale Johannesen | 67cc9b6 | 2008-09-26 19:31:26 +0000 | [diff] [blame] | 5568 | TLI.LowerCallTo(InChain, RetTy, isSigned, !isSigned, false, false, |
| 5569 | CallingConv::C, false, Callee, Args, DAG); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5570 | |
| 5571 | // Legalize the call sequence, starting with the chain. This will advance |
| 5572 | // the LastCALLSEQ_END to the legalized version of the CALLSEQ_END node that |
| 5573 | // was added by LowerCallTo (guaranteeing proper serialization of calls). |
| 5574 | LegalizeOp(CallInfo.second); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5575 | SDValue Result; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5576 | switch (getTypeAction(CallInfo.first.getValueType())) { |
| 5577 | default: assert(0 && "Unknown thing"); |
| 5578 | case Legal: |
| 5579 | Result = CallInfo.first; |
| 5580 | break; |
| 5581 | case Expand: |
| 5582 | ExpandOp(CallInfo.first, Result, Hi); |
| 5583 | break; |
| 5584 | } |
| 5585 | return Result; |
| 5586 | } |
| 5587 | |
Dan Gohman | 29c3cef | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 5588 | /// LegalizeINT_TO_FP - Legalize a [US]INT_TO_FP operation. |
| 5589 | /// |
| 5590 | SDValue SelectionDAGLegalize:: |
| 5591 | LegalizeINT_TO_FP(SDValue Result, bool isSigned, MVT DestTy, SDValue Op) { |
| 5592 | bool isCustom = false; |
| 5593 | SDValue Tmp1; |
| 5594 | switch (getTypeAction(Op.getValueType())) { |
| 5595 | case Legal: |
| 5596 | switch (TLI.getOperationAction(isSigned ? ISD::SINT_TO_FP : ISD::UINT_TO_FP, |
| 5597 | Op.getValueType())) { |
| 5598 | default: assert(0 && "Unknown operation action!"); |
| 5599 | case TargetLowering::Custom: |
| 5600 | isCustom = true; |
| 5601 | // FALLTHROUGH |
| 5602 | case TargetLowering::Legal: |
| 5603 | Tmp1 = LegalizeOp(Op); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5604 | if (Result.getNode()) |
Dan Gohman | 29c3cef | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 5605 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 5606 | else |
| 5607 | Result = DAG.getNode(isSigned ? ISD::SINT_TO_FP : ISD::UINT_TO_FP, |
| 5608 | DestTy, Tmp1); |
| 5609 | if (isCustom) { |
| 5610 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5611 | if (Tmp1.getNode()) Result = Tmp1; |
Dan Gohman | 29c3cef | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 5612 | } |
| 5613 | break; |
| 5614 | case TargetLowering::Expand: |
| 5615 | Result = ExpandLegalINT_TO_FP(isSigned, LegalizeOp(Op), DestTy); |
| 5616 | break; |
| 5617 | case TargetLowering::Promote: |
| 5618 | Result = PromoteLegalINT_TO_FP(LegalizeOp(Op), DestTy, isSigned); |
| 5619 | break; |
| 5620 | } |
| 5621 | break; |
| 5622 | case Expand: |
| 5623 | Result = ExpandIntToFP(isSigned, DestTy, Op); |
| 5624 | break; |
| 5625 | case Promote: |
| 5626 | Tmp1 = PromoteOp(Op); |
| 5627 | if (isSigned) { |
| 5628 | Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, Tmp1.getValueType(), |
| 5629 | Tmp1, DAG.getValueType(Op.getValueType())); |
| 5630 | } else { |
| 5631 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, |
| 5632 | Op.getValueType()); |
| 5633 | } |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5634 | if (Result.getNode()) |
Dan Gohman | 29c3cef | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 5635 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 5636 | else |
| 5637 | Result = DAG.getNode(isSigned ? ISD::SINT_TO_FP : ISD::UINT_TO_FP, |
| 5638 | DestTy, Tmp1); |
| 5639 | Result = LegalizeOp(Result); // The 'op' is not necessarily legal! |
| 5640 | break; |
| 5641 | } |
| 5642 | return Result; |
| 5643 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5644 | |
| 5645 | /// ExpandIntToFP - Expand a [US]INT_TO_FP operation. |
| 5646 | /// |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5647 | SDValue SelectionDAGLegalize:: |
| 5648 | ExpandIntToFP(bool isSigned, MVT DestTy, SDValue Source) { |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5649 | MVT SourceVT = Source.getValueType(); |
Dan Gohman | 8b232ff | 2008-03-11 01:59:03 +0000 | [diff] [blame] | 5650 | bool ExpandSource = getTypeAction(SourceVT) == Expand; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5651 | |
Dan Gohman | 29c3cef | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 5652 | // Expand unsupported int-to-fp vector casts by unrolling them. |
| 5653 | if (DestTy.isVector()) { |
| 5654 | if (!ExpandSource) |
| 5655 | return LegalizeOp(UnrollVectorOp(Source)); |
| 5656 | MVT DestEltTy = DestTy.getVectorElementType(); |
| 5657 | if (DestTy.getVectorNumElements() == 1) { |
| 5658 | SDValue Scalar = ScalarizeVectorOp(Source); |
| 5659 | SDValue Result = LegalizeINT_TO_FP(SDValue(), isSigned, |
| 5660 | DestEltTy, Scalar); |
| 5661 | return DAG.getNode(ISD::BUILD_VECTOR, DestTy, Result); |
| 5662 | } |
| 5663 | SDValue Lo, Hi; |
| 5664 | SplitVectorOp(Source, Lo, Hi); |
| 5665 | MVT SplitDestTy = MVT::getVectorVT(DestEltTy, |
| 5666 | DestTy.getVectorNumElements() / 2); |
| 5667 | SDValue LoResult = LegalizeINT_TO_FP(SDValue(), isSigned, SplitDestTy, Lo); |
| 5668 | SDValue HiResult = LegalizeINT_TO_FP(SDValue(), isSigned, SplitDestTy, Hi); |
Evan Cheng | d901b66 | 2008-10-13 18:46:18 +0000 | [diff] [blame] | 5669 | return LegalizeOp(DAG.getNode(ISD::CONCAT_VECTORS, DestTy, LoResult, |
| 5670 | HiResult)); |
Dan Gohman | 29c3cef | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 5671 | } |
| 5672 | |
Evan Cheng | f99a775 | 2008-04-01 02:18:22 +0000 | [diff] [blame] | 5673 | // Special case for i32 source to take advantage of UINTTOFP_I32_F32, etc. |
| 5674 | if (!isSigned && SourceVT != MVT::i32) { |
Dan Gohman | a193dba | 2008-03-05 02:07:31 +0000 | [diff] [blame] | 5675 | // The integer value loaded will be incorrectly if the 'sign bit' of the |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5676 | // incoming integer is set. To handle this, we dynamically test to see if |
| 5677 | // it is set, and, if so, add a fudge factor. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5678 | SDValue Hi; |
Dan Gohman | 8b232ff | 2008-03-11 01:59:03 +0000 | [diff] [blame] | 5679 | if (ExpandSource) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5680 | SDValue Lo; |
Dan Gohman | 8b232ff | 2008-03-11 01:59:03 +0000 | [diff] [blame] | 5681 | ExpandOp(Source, Lo, Hi); |
| 5682 | Source = DAG.getNode(ISD::BUILD_PAIR, SourceVT, Lo, Hi); |
| 5683 | } else { |
| 5684 | // The comparison for the sign bit will use the entire operand. |
| 5685 | Hi = Source; |
| 5686 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5687 | |
Dale Johannesen | 96db796 | 2008-11-04 20:52:49 +0000 | [diff] [blame] | 5688 | // Check to see if the target has a custom way to lower this. If so, use |
| 5689 | // it. (Note we've already expanded the operand in this case.) |
Dale Johannesen | a359b8b | 2008-10-21 20:50:01 +0000 | [diff] [blame] | 5690 | switch (TLI.getOperationAction(ISD::UINT_TO_FP, SourceVT)) { |
| 5691 | default: assert(0 && "This action not implemented for this operation!"); |
| 5692 | case TargetLowering::Legal: |
| 5693 | case TargetLowering::Expand: |
| 5694 | break; // This case is handled below. |
| 5695 | case TargetLowering::Custom: { |
| 5696 | SDValue NV = TLI.LowerOperation(DAG.getNode(ISD::UINT_TO_FP, DestTy, |
| 5697 | Source), DAG); |
| 5698 | if (NV.getNode()) |
| 5699 | return LegalizeOp(NV); |
| 5700 | break; // The target decided this was legal after all |
| 5701 | } |
| 5702 | } |
| 5703 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5704 | // If this is unsigned, and not supported, first perform the conversion to |
| 5705 | // signed, then adjust the result if the sign bit is set. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5706 | SDValue SignedConv = ExpandIntToFP(true, DestTy, Source); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5707 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5708 | SDValue SignSet = DAG.getSetCC(TLI.getSetCCResultType(Hi), Hi, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5709 | DAG.getConstant(0, Hi.getValueType()), |
| 5710 | ISD::SETLT); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5711 | SDValue Zero = DAG.getIntPtrConstant(0), Four = DAG.getIntPtrConstant(4); |
| 5712 | SDValue CstOffset = DAG.getNode(ISD::SELECT, Zero.getValueType(), |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5713 | SignSet, Four, Zero); |
| 5714 | uint64_t FF = 0x5f800000ULL; |
| 5715 | if (TLI.isLittleEndian()) FF <<= 32; |
Dan Gohman | a193dba | 2008-03-05 02:07:31 +0000 | [diff] [blame] | 5716 | static Constant *FudgeFactor = ConstantInt::get(Type::Int64Ty, FF); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5717 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5718 | SDValue CPIdx = DAG.getConstantPool(FudgeFactor, TLI.getPointerTy()); |
Dan Gohman | 04637d1 | 2008-09-16 22:05:41 +0000 | [diff] [blame] | 5719 | unsigned Alignment = 1 << cast<ConstantPoolSDNode>(CPIdx)->getAlignment(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5720 | CPIdx = DAG.getNode(ISD::ADD, TLI.getPointerTy(), CPIdx, CstOffset); |
Dan Gohman | dc5901a | 2008-09-22 22:40:08 +0000 | [diff] [blame] | 5721 | Alignment = std::min(Alignment, 4u); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5722 | SDValue FudgeInReg; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5723 | if (DestTy == MVT::f32) |
Dan Gohman | 12a9c08 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5724 | FudgeInReg = DAG.getLoad(MVT::f32, DAG.getEntryNode(), CPIdx, |
Dan Gohman | 04637d1 | 2008-09-16 22:05:41 +0000 | [diff] [blame] | 5725 | PseudoSourceValue::getConstantPool(), 0, |
| 5726 | false, Alignment); |
Duncan Sands | ec142ee | 2008-06-08 20:54:56 +0000 | [diff] [blame] | 5727 | else if (DestTy.bitsGT(MVT::f32)) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5728 | // FIXME: Avoid the extend by construction the right constantpool? |
Dale Johannesen | b17a7a2 | 2007-09-16 16:51:49 +0000 | [diff] [blame] | 5729 | FudgeInReg = DAG.getExtLoad(ISD::EXTLOAD, DestTy, DAG.getEntryNode(), |
Dan Gohman | 12a9c08 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5730 | CPIdx, |
Dan Gohman | fb020b6 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 5731 | PseudoSourceValue::getConstantPool(), 0, |
Dan Gohman | 04637d1 | 2008-09-16 22:05:41 +0000 | [diff] [blame] | 5732 | MVT::f32, false, Alignment); |
Dale Johannesen | 2fc2078 | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 5733 | else |
| 5734 | assert(0 && "Unexpected conversion"); |
| 5735 | |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5736 | MVT SCVT = SignedConv.getValueType(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5737 | if (SCVT != DestTy) { |
| 5738 | // Destination type needs to be expanded as well. The FADD now we are |
| 5739 | // constructing will be expanded into a libcall. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5740 | if (SCVT.getSizeInBits() != DestTy.getSizeInBits()) { |
| 5741 | assert(SCVT.getSizeInBits() * 2 == DestTy.getSizeInBits()); |
Dan Gohman | c98645c | 2008-03-05 01:08:17 +0000 | [diff] [blame] | 5742 | SignedConv = DAG.getNode(ISD::BUILD_PAIR, DestTy, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5743 | SignedConv, SignedConv.getValue(1)); |
| 5744 | } |
| 5745 | SignedConv = DAG.getNode(ISD::BIT_CONVERT, DestTy, SignedConv); |
| 5746 | } |
| 5747 | return DAG.getNode(ISD::FADD, DestTy, SignedConv, FudgeInReg); |
| 5748 | } |
| 5749 | |
| 5750 | // Check to see if the target has a custom way to lower this. If so, use it. |
Dan Gohman | c98645c | 2008-03-05 01:08:17 +0000 | [diff] [blame] | 5751 | switch (TLI.getOperationAction(ISD::SINT_TO_FP, SourceVT)) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5752 | default: assert(0 && "This action not implemented for this operation!"); |
| 5753 | case TargetLowering::Legal: |
| 5754 | case TargetLowering::Expand: |
| 5755 | break; // This case is handled below. |
| 5756 | case TargetLowering::Custom: { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5757 | SDValue NV = TLI.LowerOperation(DAG.getNode(ISD::SINT_TO_FP, DestTy, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5758 | Source), DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5759 | if (NV.getNode()) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5760 | return LegalizeOp(NV); |
| 5761 | break; // The target decided this was legal after all |
| 5762 | } |
| 5763 | } |
| 5764 | |
| 5765 | // Expand the source, then glue it back together for the call. We must expand |
| 5766 | // the source in case it is shared (this pass of legalize must traverse it). |
Dan Gohman | 8b232ff | 2008-03-11 01:59:03 +0000 | [diff] [blame] | 5767 | if (ExpandSource) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5768 | SDValue SrcLo, SrcHi; |
Dan Gohman | 8b232ff | 2008-03-11 01:59:03 +0000 | [diff] [blame] | 5769 | ExpandOp(Source, SrcLo, SrcHi); |
| 5770 | Source = DAG.getNode(ISD::BUILD_PAIR, SourceVT, SrcLo, SrcHi); |
| 5771 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5772 | |
Duncan Sands | f68dffb | 2008-07-17 02:36:29 +0000 | [diff] [blame] | 5773 | RTLIB::Libcall LC = isSigned ? |
| 5774 | RTLIB::getSINTTOFP(SourceVT, DestTy) : |
| 5775 | RTLIB::getUINTTOFP(SourceVT, DestTy); |
| 5776 | assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unknown int value type"); |
| 5777 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5778 | Source = DAG.getNode(ISD::SINT_TO_FP, DestTy, Source); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5779 | SDValue HiPart; |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5780 | SDValue Result = ExpandLibCall(LC, Source.getNode(), isSigned, HiPart); |
| 5781 | if (Result.getValueType() != DestTy && HiPart.getNode()) |
Dan Gohman | ec51f64 | 2008-03-10 23:03:31 +0000 | [diff] [blame] | 5782 | Result = DAG.getNode(ISD::BUILD_PAIR, DestTy, Result, HiPart); |
| 5783 | return Result; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5784 | } |
| 5785 | |
| 5786 | /// ExpandLegalINT_TO_FP - This function is responsible for legalizing a |
| 5787 | /// INT_TO_FP operation of the specified operand when the target requests that |
| 5788 | /// we expand it. At this point, we know that the result and operand types are |
| 5789 | /// legal for the target. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5790 | SDValue SelectionDAGLegalize::ExpandLegalINT_TO_FP(bool isSigned, |
| 5791 | SDValue Op0, |
| 5792 | MVT DestVT) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5793 | if (Op0.getValueType() == MVT::i32) { |
| 5794 | // simple 32-bit [signed|unsigned] integer to float/double expansion |
| 5795 | |
Chris Lattner | 0aeb1d0 | 2008-01-16 07:03:22 +0000 | [diff] [blame] | 5796 | // Get the stack frame index of a 8 byte buffer. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5797 | SDValue StackSlot = DAG.CreateStackTemporary(MVT::f64); |
Chris Lattner | 0aeb1d0 | 2008-01-16 07:03:22 +0000 | [diff] [blame] | 5798 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5799 | // word offset constant for Hi/Lo address computation |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5800 | SDValue WordOff = DAG.getConstant(sizeof(int), TLI.getPointerTy()); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5801 | // set up Hi and Lo (into buffer) address based on endian |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5802 | SDValue Hi = StackSlot; |
| 5803 | SDValue Lo = DAG.getNode(ISD::ADD, TLI.getPointerTy(), StackSlot,WordOff); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5804 | if (TLI.isLittleEndian()) |
| 5805 | std::swap(Hi, Lo); |
| 5806 | |
| 5807 | // if signed map to unsigned space |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5808 | SDValue Op0Mapped; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5809 | if (isSigned) { |
| 5810 | // constant used to invert sign bit (signed to unsigned mapping) |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5811 | SDValue SignBit = DAG.getConstant(0x80000000u, MVT::i32); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5812 | Op0Mapped = DAG.getNode(ISD::XOR, MVT::i32, Op0, SignBit); |
| 5813 | } else { |
| 5814 | Op0Mapped = Op0; |
| 5815 | } |
| 5816 | // store the lo of the constructed double - based on integer input |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5817 | SDValue Store1 = DAG.getStore(DAG.getEntryNode(), |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5818 | Op0Mapped, Lo, NULL, 0); |
| 5819 | // initial hi portion of constructed double |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5820 | SDValue InitialHi = DAG.getConstant(0x43300000u, MVT::i32); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5821 | // store the hi of the constructed double - biased exponent |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5822 | SDValue Store2=DAG.getStore(Store1, InitialHi, Hi, NULL, 0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5823 | // load the constructed double |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5824 | SDValue Load = DAG.getLoad(MVT::f64, Store2, StackSlot, NULL, 0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5825 | // FP constant to bias correct the final result |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5826 | SDValue Bias = DAG.getConstantFP(isSigned ? |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5827 | BitsToDouble(0x4330000080000000ULL) |
| 5828 | : BitsToDouble(0x4330000000000000ULL), |
| 5829 | MVT::f64); |
| 5830 | // subtract the bias |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5831 | SDValue Sub = DAG.getNode(ISD::FSUB, MVT::f64, Load, Bias); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5832 | // final result |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5833 | SDValue Result; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5834 | // handle final rounding |
| 5835 | if (DestVT == MVT::f64) { |
| 5836 | // do nothing |
| 5837 | Result = Sub; |
Duncan Sands | ec142ee | 2008-06-08 20:54:56 +0000 | [diff] [blame] | 5838 | } else if (DestVT.bitsLT(MVT::f64)) { |
Chris Lattner | 5872a36 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 5839 | Result = DAG.getNode(ISD::FP_ROUND, DestVT, Sub, |
| 5840 | DAG.getIntPtrConstant(0)); |
Duncan Sands | ec142ee | 2008-06-08 20:54:56 +0000 | [diff] [blame] | 5841 | } else if (DestVT.bitsGT(MVT::f64)) { |
Dale Johannesen | b17a7a2 | 2007-09-16 16:51:49 +0000 | [diff] [blame] | 5842 | Result = DAG.getNode(ISD::FP_EXTEND, DestVT, Sub); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5843 | } |
| 5844 | return Result; |
| 5845 | } |
| 5846 | assert(!isSigned && "Legalize cannot Expand SINT_TO_FP for i64 yet"); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5847 | SDValue Tmp1 = DAG.getNode(ISD::SINT_TO_FP, DestVT, Op0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5848 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5849 | SDValue SignSet = DAG.getSetCC(TLI.getSetCCResultType(Op0), Op0, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5850 | DAG.getConstant(0, Op0.getValueType()), |
| 5851 | ISD::SETLT); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5852 | SDValue Zero = DAG.getIntPtrConstant(0), Four = DAG.getIntPtrConstant(4); |
| 5853 | SDValue CstOffset = DAG.getNode(ISD::SELECT, Zero.getValueType(), |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5854 | SignSet, Four, Zero); |
| 5855 | |
| 5856 | // If the sign bit of the integer is set, the large number will be treated |
| 5857 | // as a negative number. To counteract this, the dynamic code adds an |
| 5858 | // offset depending on the data type. |
| 5859 | uint64_t FF; |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5860 | switch (Op0.getValueType().getSimpleVT()) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5861 | default: assert(0 && "Unsupported integer type!"); |
| 5862 | case MVT::i8 : FF = 0x43800000ULL; break; // 2^8 (as a float) |
| 5863 | case MVT::i16: FF = 0x47800000ULL; break; // 2^16 (as a float) |
| 5864 | case MVT::i32: FF = 0x4F800000ULL; break; // 2^32 (as a float) |
| 5865 | case MVT::i64: FF = 0x5F800000ULL; break; // 2^64 (as a float) |
| 5866 | } |
| 5867 | if (TLI.isLittleEndian()) FF <<= 32; |
| 5868 | static Constant *FudgeFactor = ConstantInt::get(Type::Int64Ty, FF); |
| 5869 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5870 | SDValue CPIdx = DAG.getConstantPool(FudgeFactor, TLI.getPointerTy()); |
Dan Gohman | 04637d1 | 2008-09-16 22:05:41 +0000 | [diff] [blame] | 5871 | unsigned Alignment = 1 << cast<ConstantPoolSDNode>(CPIdx)->getAlignment(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5872 | CPIdx = DAG.getNode(ISD::ADD, TLI.getPointerTy(), CPIdx, CstOffset); |
Dan Gohman | dc5901a | 2008-09-22 22:40:08 +0000 | [diff] [blame] | 5873 | Alignment = std::min(Alignment, 4u); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5874 | SDValue FudgeInReg; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5875 | if (DestVT == MVT::f32) |
Dan Gohman | 12a9c08 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5876 | FudgeInReg = DAG.getLoad(MVT::f32, DAG.getEntryNode(), CPIdx, |
Dan Gohman | 04637d1 | 2008-09-16 22:05:41 +0000 | [diff] [blame] | 5877 | PseudoSourceValue::getConstantPool(), 0, |
| 5878 | false, Alignment); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5879 | else { |
Dan Gohman | 12a9c08 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5880 | FudgeInReg = |
| 5881 | LegalizeOp(DAG.getExtLoad(ISD::EXTLOAD, DestVT, |
| 5882 | DAG.getEntryNode(), CPIdx, |
Dan Gohman | fb020b6 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 5883 | PseudoSourceValue::getConstantPool(), 0, |
Dan Gohman | 04637d1 | 2008-09-16 22:05:41 +0000 | [diff] [blame] | 5884 | MVT::f32, false, Alignment)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5885 | } |
| 5886 | |
| 5887 | return DAG.getNode(ISD::FADD, DestVT, Tmp1, FudgeInReg); |
| 5888 | } |
| 5889 | |
| 5890 | /// PromoteLegalINT_TO_FP - This function is responsible for legalizing a |
| 5891 | /// *INT_TO_FP operation of the specified operand when the target requests that |
| 5892 | /// we promote it. At this point, we know that the result and operand types are |
| 5893 | /// legal for the target, and that there is a legal UINT_TO_FP or SINT_TO_FP |
| 5894 | /// operation that takes a larger input. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5895 | SDValue SelectionDAGLegalize::PromoteLegalINT_TO_FP(SDValue LegalOp, |
| 5896 | MVT DestVT, |
| 5897 | bool isSigned) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5898 | // First step, figure out the appropriate *INT_TO_FP operation to use. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5899 | MVT NewInTy = LegalOp.getValueType(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5900 | |
| 5901 | unsigned OpToUse = 0; |
| 5902 | |
| 5903 | // Scan for the appropriate larger type to use. |
| 5904 | while (1) { |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5905 | NewInTy = (MVT::SimpleValueType)(NewInTy.getSimpleVT()+1); |
| 5906 | assert(NewInTy.isInteger() && "Ran out of possibilities!"); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5907 | |
| 5908 | // If the target supports SINT_TO_FP of this type, use it. |
| 5909 | switch (TLI.getOperationAction(ISD::SINT_TO_FP, NewInTy)) { |
| 5910 | default: break; |
| 5911 | case TargetLowering::Legal: |
| 5912 | if (!TLI.isTypeLegal(NewInTy)) |
| 5913 | break; // Can't use this datatype. |
| 5914 | // FALL THROUGH. |
| 5915 | case TargetLowering::Custom: |
| 5916 | OpToUse = ISD::SINT_TO_FP; |
| 5917 | break; |
| 5918 | } |
| 5919 | if (OpToUse) break; |
| 5920 | if (isSigned) continue; |
| 5921 | |
| 5922 | // If the target supports UINT_TO_FP of this type, use it. |
| 5923 | switch (TLI.getOperationAction(ISD::UINT_TO_FP, NewInTy)) { |
| 5924 | default: break; |
| 5925 | case TargetLowering::Legal: |
| 5926 | if (!TLI.isTypeLegal(NewInTy)) |
| 5927 | break; // Can't use this datatype. |
| 5928 | // FALL THROUGH. |
| 5929 | case TargetLowering::Custom: |
| 5930 | OpToUse = ISD::UINT_TO_FP; |
| 5931 | break; |
| 5932 | } |
| 5933 | if (OpToUse) break; |
| 5934 | |
| 5935 | // Otherwise, try a larger type. |
| 5936 | } |
| 5937 | |
| 5938 | // Okay, we found the operation and type to use. Zero extend our input to the |
| 5939 | // desired type then run the operation on it. |
| 5940 | return DAG.getNode(OpToUse, DestVT, |
| 5941 | DAG.getNode(isSigned ? ISD::SIGN_EXTEND : ISD::ZERO_EXTEND, |
| 5942 | NewInTy, LegalOp)); |
| 5943 | } |
| 5944 | |
| 5945 | /// PromoteLegalFP_TO_INT - This function is responsible for legalizing a |
| 5946 | /// FP_TO_*INT operation of the specified operand when the target requests that |
| 5947 | /// we promote it. At this point, we know that the result and operand types are |
| 5948 | /// legal for the target, and that there is a legal FP_TO_UINT or FP_TO_SINT |
| 5949 | /// operation that returns a larger result. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5950 | SDValue SelectionDAGLegalize::PromoteLegalFP_TO_INT(SDValue LegalOp, |
| 5951 | MVT DestVT, |
| 5952 | bool isSigned) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5953 | // First step, figure out the appropriate FP_TO*INT operation to use. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5954 | MVT NewOutTy = DestVT; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5955 | |
| 5956 | unsigned OpToUse = 0; |
| 5957 | |
| 5958 | // Scan for the appropriate larger type to use. |
| 5959 | while (1) { |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5960 | NewOutTy = (MVT::SimpleValueType)(NewOutTy.getSimpleVT()+1); |
| 5961 | assert(NewOutTy.isInteger() && "Ran out of possibilities!"); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5962 | |
| 5963 | // If the target supports FP_TO_SINT returning this type, use it. |
| 5964 | switch (TLI.getOperationAction(ISD::FP_TO_SINT, NewOutTy)) { |
| 5965 | default: break; |
| 5966 | case TargetLowering::Legal: |
| 5967 | if (!TLI.isTypeLegal(NewOutTy)) |
| 5968 | break; // Can't use this datatype. |
| 5969 | // FALL THROUGH. |
| 5970 | case TargetLowering::Custom: |
| 5971 | OpToUse = ISD::FP_TO_SINT; |
| 5972 | break; |
| 5973 | } |
| 5974 | if (OpToUse) break; |
| 5975 | |
| 5976 | // If the target supports FP_TO_UINT of this type, use it. |
| 5977 | switch (TLI.getOperationAction(ISD::FP_TO_UINT, NewOutTy)) { |
| 5978 | default: break; |
| 5979 | case TargetLowering::Legal: |
| 5980 | if (!TLI.isTypeLegal(NewOutTy)) |
| 5981 | break; // Can't use this datatype. |
| 5982 | // FALL THROUGH. |
| 5983 | case TargetLowering::Custom: |
| 5984 | OpToUse = ISD::FP_TO_UINT; |
| 5985 | break; |
| 5986 | } |
| 5987 | if (OpToUse) break; |
| 5988 | |
| 5989 | // Otherwise, try a larger type. |
| 5990 | } |
| 5991 | |
Chris Lattner | dfb947d | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 5992 | |
| 5993 | // Okay, we found the operation and type to use. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5994 | SDValue Operation = DAG.getNode(OpToUse, NewOutTy, LegalOp); |
Duncan Sands | ac496a1 | 2008-07-04 11:47:58 +0000 | [diff] [blame] | 5995 | |
Chris Lattner | dfb947d | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 5996 | // If the operation produces an invalid type, it must be custom lowered. Use |
| 5997 | // the target lowering hooks to expand it. Just keep the low part of the |
| 5998 | // expanded operation, we know that we're truncating anyway. |
| 5999 | if (getTypeAction(NewOutTy) == Expand) { |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6000 | Operation = SDValue(TLI.ReplaceNodeResults(Operation.getNode(), DAG), 0); |
| 6001 | assert(Operation.getNode() && "Didn't return anything"); |
Chris Lattner | dfb947d | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6002 | } |
Duncan Sands | ac496a1 | 2008-07-04 11:47:58 +0000 | [diff] [blame] | 6003 | |
Chris Lattner | dfb947d | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6004 | // Truncate the result of the extended FP_TO_*INT operation to the desired |
| 6005 | // size. |
| 6006 | return DAG.getNode(ISD::TRUNCATE, DestVT, Operation); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6007 | } |
| 6008 | |
| 6009 | /// ExpandBSWAP - Open code the operations for BSWAP of the specified operation. |
| 6010 | /// |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6011 | SDValue SelectionDAGLegalize::ExpandBSWAP(SDValue Op) { |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6012 | MVT VT = Op.getValueType(); |
| 6013 | MVT SHVT = TLI.getShiftAmountTy(); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6014 | SDValue Tmp1, Tmp2, Tmp3, Tmp4, Tmp5, Tmp6, Tmp7, Tmp8; |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6015 | switch (VT.getSimpleVT()) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6016 | default: assert(0 && "Unhandled Expand type in BSWAP!"); abort(); |
| 6017 | case MVT::i16: |
| 6018 | Tmp2 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(8, SHVT)); |
| 6019 | Tmp1 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(8, SHVT)); |
| 6020 | return DAG.getNode(ISD::OR, VT, Tmp1, Tmp2); |
| 6021 | case MVT::i32: |
| 6022 | Tmp4 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(24, SHVT)); |
| 6023 | Tmp3 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(8, SHVT)); |
| 6024 | Tmp2 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(8, SHVT)); |
| 6025 | Tmp1 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(24, SHVT)); |
| 6026 | Tmp3 = DAG.getNode(ISD::AND, VT, Tmp3, DAG.getConstant(0xFF0000, VT)); |
| 6027 | Tmp2 = DAG.getNode(ISD::AND, VT, Tmp2, DAG.getConstant(0xFF00, VT)); |
| 6028 | Tmp4 = DAG.getNode(ISD::OR, VT, Tmp4, Tmp3); |
| 6029 | Tmp2 = DAG.getNode(ISD::OR, VT, Tmp2, Tmp1); |
| 6030 | return DAG.getNode(ISD::OR, VT, Tmp4, Tmp2); |
| 6031 | case MVT::i64: |
| 6032 | Tmp8 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(56, SHVT)); |
| 6033 | Tmp7 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(40, SHVT)); |
| 6034 | Tmp6 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(24, SHVT)); |
| 6035 | Tmp5 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(8, SHVT)); |
| 6036 | Tmp4 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(8, SHVT)); |
| 6037 | Tmp3 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(24, SHVT)); |
| 6038 | Tmp2 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(40, SHVT)); |
| 6039 | Tmp1 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(56, SHVT)); |
| 6040 | Tmp7 = DAG.getNode(ISD::AND, VT, Tmp7, DAG.getConstant(255ULL<<48, VT)); |
| 6041 | Tmp6 = DAG.getNode(ISD::AND, VT, Tmp6, DAG.getConstant(255ULL<<40, VT)); |
| 6042 | Tmp5 = DAG.getNode(ISD::AND, VT, Tmp5, DAG.getConstant(255ULL<<32, VT)); |
| 6043 | Tmp4 = DAG.getNode(ISD::AND, VT, Tmp4, DAG.getConstant(255ULL<<24, VT)); |
| 6044 | Tmp3 = DAG.getNode(ISD::AND, VT, Tmp3, DAG.getConstant(255ULL<<16, VT)); |
| 6045 | Tmp2 = DAG.getNode(ISD::AND, VT, Tmp2, DAG.getConstant(255ULL<<8 , VT)); |
| 6046 | Tmp8 = DAG.getNode(ISD::OR, VT, Tmp8, Tmp7); |
| 6047 | Tmp6 = DAG.getNode(ISD::OR, VT, Tmp6, Tmp5); |
| 6048 | Tmp4 = DAG.getNode(ISD::OR, VT, Tmp4, Tmp3); |
| 6049 | Tmp2 = DAG.getNode(ISD::OR, VT, Tmp2, Tmp1); |
| 6050 | Tmp8 = DAG.getNode(ISD::OR, VT, Tmp8, Tmp6); |
| 6051 | Tmp4 = DAG.getNode(ISD::OR, VT, Tmp4, Tmp2); |
| 6052 | return DAG.getNode(ISD::OR, VT, Tmp8, Tmp4); |
| 6053 | } |
| 6054 | } |
| 6055 | |
| 6056 | /// ExpandBitCount - Expand the specified bitcount instruction into operations. |
| 6057 | /// |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6058 | SDValue SelectionDAGLegalize::ExpandBitCount(unsigned Opc, SDValue Op) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6059 | switch (Opc) { |
| 6060 | default: assert(0 && "Cannot expand this yet!"); |
| 6061 | case ISD::CTPOP: { |
| 6062 | static const uint64_t mask[6] = { |
| 6063 | 0x5555555555555555ULL, 0x3333333333333333ULL, |
| 6064 | 0x0F0F0F0F0F0F0F0FULL, 0x00FF00FF00FF00FFULL, |
| 6065 | 0x0000FFFF0000FFFFULL, 0x00000000FFFFFFFFULL |
| 6066 | }; |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6067 | MVT VT = Op.getValueType(); |
| 6068 | MVT ShVT = TLI.getShiftAmountTy(); |
| 6069 | unsigned len = VT.getSizeInBits(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6070 | for (unsigned i = 0; (1U << i) <= (len / 2); ++i) { |
| 6071 | //x = (x & mask[i][len/8]) + (x >> (1 << i) & mask[i][len/8]) |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6072 | SDValue Tmp2 = DAG.getConstant(mask[i], VT); |
| 6073 | SDValue Tmp3 = DAG.getConstant(1ULL << i, ShVT); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6074 | Op = DAG.getNode(ISD::ADD, VT, DAG.getNode(ISD::AND, VT, Op, Tmp2), |
| 6075 | DAG.getNode(ISD::AND, VT, |
| 6076 | DAG.getNode(ISD::SRL, VT, Op, Tmp3),Tmp2)); |
| 6077 | } |
| 6078 | return Op; |
| 6079 | } |
| 6080 | case ISD::CTLZ: { |
| 6081 | // for now, we do this: |
| 6082 | // x = x | (x >> 1); |
| 6083 | // x = x | (x >> 2); |
| 6084 | // ... |
| 6085 | // x = x | (x >>16); |
| 6086 | // x = x | (x >>32); // for 64-bit input |
| 6087 | // return popcount(~x); |
| 6088 | // |
| 6089 | // but see also: http://www.hackersdelight.org/HDcode/nlz.cc |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6090 | MVT VT = Op.getValueType(); |
| 6091 | MVT ShVT = TLI.getShiftAmountTy(); |
| 6092 | unsigned len = VT.getSizeInBits(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6093 | for (unsigned i = 0; (1U << i) <= (len / 2); ++i) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6094 | SDValue Tmp3 = DAG.getConstant(1ULL << i, ShVT); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6095 | Op = DAG.getNode(ISD::OR, VT, Op, DAG.getNode(ISD::SRL, VT, Op, Tmp3)); |
| 6096 | } |
| 6097 | Op = DAG.getNode(ISD::XOR, VT, Op, DAG.getConstant(~0ULL, VT)); |
| 6098 | return DAG.getNode(ISD::CTPOP, VT, Op); |
| 6099 | } |
| 6100 | case ISD::CTTZ: { |
| 6101 | // for now, we use: { return popcount(~x & (x - 1)); } |
| 6102 | // unless the target has ctlz but not ctpop, in which case we use: |
| 6103 | // { return 32 - nlz(~x & (x-1)); } |
| 6104 | // see also http://www.hackersdelight.org/HDcode/ntz.cc |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6105 | MVT VT = Op.getValueType(); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6106 | SDValue Tmp2 = DAG.getConstant(~0ULL, VT); |
| 6107 | SDValue Tmp3 = DAG.getNode(ISD::AND, VT, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6108 | DAG.getNode(ISD::XOR, VT, Op, Tmp2), |
| 6109 | DAG.getNode(ISD::SUB, VT, Op, DAG.getConstant(1, VT))); |
| 6110 | // If ISD::CTLZ is legal and CTPOP isn't, then do that instead. |
| 6111 | if (!TLI.isOperationLegal(ISD::CTPOP, VT) && |
| 6112 | TLI.isOperationLegal(ISD::CTLZ, VT)) |
| 6113 | return DAG.getNode(ISD::SUB, VT, |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6114 | DAG.getConstant(VT.getSizeInBits(), VT), |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6115 | DAG.getNode(ISD::CTLZ, VT, Tmp3)); |
| 6116 | return DAG.getNode(ISD::CTPOP, VT, Tmp3); |
| 6117 | } |
| 6118 | } |
| 6119 | } |
| 6120 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6121 | /// ExpandOp - Expand the specified SDValue into its two component pieces |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6122 | /// Lo&Hi. Note that the Op MUST be an expanded type. As a result of this, the |
Dan Gohman | 4fc0374 | 2008-10-01 15:07:49 +0000 | [diff] [blame] | 6123 | /// LegalizedNodes map is filled in for any results that are not expanded, the |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6124 | /// ExpandedNodes map is filled in for any results that are expanded, and the |
| 6125 | /// Lo/Hi values are returned. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6126 | void SelectionDAGLegalize::ExpandOp(SDValue Op, SDValue &Lo, SDValue &Hi){ |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6127 | MVT VT = Op.getValueType(); |
| 6128 | MVT NVT = TLI.getTypeToTransformTo(VT); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6129 | SDNode *Node = Op.getNode(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6130 | assert(getTypeAction(VT) == Expand && "Not an expanded type!"); |
Duncan Sands | ec142ee | 2008-06-08 20:54:56 +0000 | [diff] [blame] | 6131 | assert(((NVT.isInteger() && NVT.bitsLT(VT)) || VT.isFloatingPoint() || |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6132 | VT.isVector()) && "Cannot expand to FP value or to larger int value!"); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6133 | |
| 6134 | // See if we already expanded it. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6135 | DenseMap<SDValue, std::pair<SDValue, SDValue> >::iterator I |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6136 | = ExpandedNodes.find(Op); |
| 6137 | if (I != ExpandedNodes.end()) { |
| 6138 | Lo = I->second.first; |
| 6139 | Hi = I->second.second; |
| 6140 | return; |
| 6141 | } |
| 6142 | |
| 6143 | switch (Node->getOpcode()) { |
| 6144 | case ISD::CopyFromReg: |
| 6145 | assert(0 && "CopyFromReg must be legal!"); |
Dale Johannesen | 3d8578b | 2007-10-10 01:01:31 +0000 | [diff] [blame] | 6146 | case ISD::FP_ROUND_INREG: |
| 6147 | if (VT == MVT::ppcf128 && |
| 6148 | TLI.getOperationAction(ISD::FP_ROUND_INREG, VT) == |
| 6149 | TargetLowering::Custom) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6150 | SDValue SrcLo, SrcHi, Src; |
Dale Johannesen | d3b6af3 | 2007-10-11 23:32:15 +0000 | [diff] [blame] | 6151 | ExpandOp(Op.getOperand(0), SrcLo, SrcHi); |
| 6152 | Src = DAG.getNode(ISD::BUILD_PAIR, VT, SrcLo, SrcHi); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6153 | SDValue Result = TLI.LowerOperation( |
Dale Johannesen | d3b6af3 | 2007-10-11 23:32:15 +0000 | [diff] [blame] | 6154 | DAG.getNode(ISD::FP_ROUND_INREG, VT, Src, Op.getOperand(1)), DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6155 | assert(Result.getNode()->getOpcode() == ISD::BUILD_PAIR); |
| 6156 | Lo = Result.getNode()->getOperand(0); |
| 6157 | Hi = Result.getNode()->getOperand(1); |
Dale Johannesen | 3d8578b | 2007-10-10 01:01:31 +0000 | [diff] [blame] | 6158 | break; |
| 6159 | } |
| 6160 | // fall through |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6161 | default: |
| 6162 | #ifndef NDEBUG |
| 6163 | cerr << "NODE: "; Node->dump(&DAG); cerr << "\n"; |
| 6164 | #endif |
| 6165 | assert(0 && "Do not know how to expand this operator!"); |
| 6166 | abort(); |
Dan Gohman | 550c846 | 2008-02-27 01:52:30 +0000 | [diff] [blame] | 6167 | case ISD::EXTRACT_ELEMENT: |
| 6168 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Dan Gohman | faeb4a3 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 6169 | if (cast<ConstantSDNode>(Node->getOperand(1))->getZExtValue()) |
Dan Gohman | 550c846 | 2008-02-27 01:52:30 +0000 | [diff] [blame] | 6170 | return ExpandOp(Hi, Lo, Hi); |
Dan Gohman | 7e7aa2c | 2008-02-27 19:44:57 +0000 | [diff] [blame] | 6171 | return ExpandOp(Lo, Lo, Hi); |
Dale Johannesen | 2ff963d | 2007-10-31 00:32:36 +0000 | [diff] [blame] | 6172 | case ISD::EXTRACT_VECTOR_ELT: |
Dale Johannesen | 2ff963d | 2007-10-31 00:32:36 +0000 | [diff] [blame] | 6173 | // ExpandEXTRACT_VECTOR_ELT tolerates invalid result types. |
| 6174 | Lo = ExpandEXTRACT_VECTOR_ELT(Op); |
| 6175 | return ExpandOp(Lo, Lo, Hi); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6176 | case ISD::UNDEF: |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6177 | Lo = DAG.getNode(ISD::UNDEF, NVT); |
| 6178 | Hi = DAG.getNode(ISD::UNDEF, NVT); |
| 6179 | break; |
| 6180 | case ISD::Constant: { |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6181 | unsigned NVTBits = NVT.getSizeInBits(); |
Dan Gohman | 97f1f8e | 2008-03-03 22:20:46 +0000 | [diff] [blame] | 6182 | const APInt &Cst = cast<ConstantSDNode>(Node)->getAPIntValue(); |
| 6183 | Lo = DAG.getConstant(APInt(Cst).trunc(NVTBits), NVT); |
| 6184 | Hi = DAG.getConstant(Cst.lshr(NVTBits).trunc(NVTBits), NVT); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6185 | break; |
| 6186 | } |
| 6187 | case ISD::ConstantFP: { |
| 6188 | ConstantFPSDNode *CFP = cast<ConstantFPSDNode>(Node); |
Dale Johannesen | 2aef569 | 2007-10-11 18:07:22 +0000 | [diff] [blame] | 6189 | if (CFP->getValueType(0) == MVT::ppcf128) { |
Dale Johannesen | 49cc7ce | 2008-10-09 18:53:47 +0000 | [diff] [blame] | 6190 | APInt api = CFP->getValueAPF().bitcastToAPInt(); |
Dale Johannesen | 2aef569 | 2007-10-11 18:07:22 +0000 | [diff] [blame] | 6191 | Lo = DAG.getConstantFP(APFloat(APInt(64, 1, &api.getRawData()[1])), |
| 6192 | MVT::f64); |
| 6193 | Hi = DAG.getConstantFP(APFloat(APInt(64, 1, &api.getRawData()[0])), |
| 6194 | MVT::f64); |
| 6195 | break; |
| 6196 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6197 | Lo = ExpandConstantFP(CFP, false, DAG, TLI); |
| 6198 | if (getTypeAction(Lo.getValueType()) == Expand) |
| 6199 | ExpandOp(Lo, Lo, Hi); |
| 6200 | break; |
| 6201 | } |
| 6202 | case ISD::BUILD_PAIR: |
| 6203 | // Return the operands. |
| 6204 | Lo = Node->getOperand(0); |
| 6205 | Hi = Node->getOperand(1); |
| 6206 | break; |
Chris Lattner | dfb947d | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6207 | |
| 6208 | case ISD::MERGE_VALUES: |
Chris Lattner | 1b66f82 | 2007-11-24 19:12:15 +0000 | [diff] [blame] | 6209 | if (Node->getNumValues() == 1) { |
| 6210 | ExpandOp(Op.getOperand(0), Lo, Hi); |
| 6211 | break; |
| 6212 | } |
Chris Lattner | dfb947d | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6213 | // FIXME: For now only expand i64,chain = MERGE_VALUES (x, y) |
Gabor Greif | 46bf547 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 6214 | assert(Op.getResNo() == 0 && Node->getNumValues() == 2 && |
Chris Lattner | dfb947d | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6215 | Op.getValue(1).getValueType() == MVT::Other && |
| 6216 | "unhandled MERGE_VALUES"); |
| 6217 | ExpandOp(Op.getOperand(0), Lo, Hi); |
| 6218 | // Remember that we legalized the chain. |
| 6219 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Op.getOperand(1))); |
| 6220 | break; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6221 | |
| 6222 | case ISD::SIGN_EXTEND_INREG: |
| 6223 | ExpandOp(Node->getOperand(0), Lo, Hi); |
| 6224 | // sext_inreg the low part if needed. |
| 6225 | Lo = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Lo, Node->getOperand(1)); |
| 6226 | |
| 6227 | // The high part gets the sign extension from the lo-part. This handles |
| 6228 | // things like sextinreg V:i64 from i8. |
| 6229 | Hi = DAG.getNode(ISD::SRA, NVT, Lo, |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6230 | DAG.getConstant(NVT.getSizeInBits()-1, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6231 | TLI.getShiftAmountTy())); |
| 6232 | break; |
| 6233 | |
| 6234 | case ISD::BSWAP: { |
| 6235 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6236 | SDValue TempLo = DAG.getNode(ISD::BSWAP, NVT, Hi); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6237 | Hi = DAG.getNode(ISD::BSWAP, NVT, Lo); |
| 6238 | Lo = TempLo; |
| 6239 | break; |
| 6240 | } |
| 6241 | |
| 6242 | case ISD::CTPOP: |
| 6243 | ExpandOp(Node->getOperand(0), Lo, Hi); |
| 6244 | Lo = DAG.getNode(ISD::ADD, NVT, // ctpop(HL) -> ctpop(H)+ctpop(L) |
| 6245 | DAG.getNode(ISD::CTPOP, NVT, Lo), |
| 6246 | DAG.getNode(ISD::CTPOP, NVT, Hi)); |
| 6247 | Hi = DAG.getConstant(0, NVT); |
| 6248 | break; |
| 6249 | |
| 6250 | case ISD::CTLZ: { |
| 6251 | // ctlz (HL) -> ctlz(H) != 32 ? ctlz(H) : (ctlz(L)+32) |
| 6252 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6253 | SDValue BitsC = DAG.getConstant(NVT.getSizeInBits(), NVT); |
| 6254 | SDValue HLZ = DAG.getNode(ISD::CTLZ, NVT, Hi); |
| 6255 | SDValue TopNotZero = DAG.getSetCC(TLI.getSetCCResultType(HLZ), HLZ, BitsC, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6256 | ISD::SETNE); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6257 | SDValue LowPart = DAG.getNode(ISD::CTLZ, NVT, Lo); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6258 | LowPart = DAG.getNode(ISD::ADD, NVT, LowPart, BitsC); |
| 6259 | |
| 6260 | Lo = DAG.getNode(ISD::SELECT, NVT, TopNotZero, HLZ, LowPart); |
| 6261 | Hi = DAG.getConstant(0, NVT); |
| 6262 | break; |
| 6263 | } |
| 6264 | |
| 6265 | case ISD::CTTZ: { |
| 6266 | // cttz (HL) -> cttz(L) != 32 ? cttz(L) : (cttz(H)+32) |
| 6267 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6268 | SDValue BitsC = DAG.getConstant(NVT.getSizeInBits(), NVT); |
| 6269 | SDValue LTZ = DAG.getNode(ISD::CTTZ, NVT, Lo); |
| 6270 | SDValue BotNotZero = DAG.getSetCC(TLI.getSetCCResultType(LTZ), LTZ, BitsC, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6271 | ISD::SETNE); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6272 | SDValue HiPart = DAG.getNode(ISD::CTTZ, NVT, Hi); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6273 | HiPart = DAG.getNode(ISD::ADD, NVT, HiPart, BitsC); |
| 6274 | |
| 6275 | Lo = DAG.getNode(ISD::SELECT, NVT, BotNotZero, LTZ, HiPart); |
| 6276 | Hi = DAG.getConstant(0, NVT); |
| 6277 | break; |
| 6278 | } |
| 6279 | |
| 6280 | case ISD::VAARG: { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6281 | SDValue Ch = Node->getOperand(0); // Legalize the chain. |
| 6282 | SDValue Ptr = Node->getOperand(1); // Legalize the pointer. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6283 | Lo = DAG.getVAArg(NVT, Ch, Ptr, Node->getOperand(2)); |
| 6284 | Hi = DAG.getVAArg(NVT, Lo.getValue(1), Ptr, Node->getOperand(2)); |
| 6285 | |
| 6286 | // Remember that we legalized the chain. |
| 6287 | Hi = LegalizeOp(Hi); |
| 6288 | AddLegalizedOperand(Op.getValue(1), Hi.getValue(1)); |
Duncan Sands | 9ff8fbf | 2008-02-11 10:37:04 +0000 | [diff] [blame] | 6289 | if (TLI.isBigEndian()) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6290 | std::swap(Lo, Hi); |
| 6291 | break; |
| 6292 | } |
| 6293 | |
| 6294 | case ISD::LOAD: { |
| 6295 | LoadSDNode *LD = cast<LoadSDNode>(Node); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6296 | SDValue Ch = LD->getChain(); // Legalize the chain. |
| 6297 | SDValue Ptr = LD->getBasePtr(); // Legalize the pointer. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6298 | ISD::LoadExtType ExtType = LD->getExtensionType(); |
Dan Gohman | 29c3cef | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 6299 | const Value *SV = LD->getSrcValue(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6300 | int SVOffset = LD->getSrcValueOffset(); |
| 6301 | unsigned Alignment = LD->getAlignment(); |
| 6302 | bool isVolatile = LD->isVolatile(); |
| 6303 | |
| 6304 | if (ExtType == ISD::NON_EXTLOAD) { |
Dan Gohman | 29c3cef | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 6305 | Lo = DAG.getLoad(NVT, Ch, Ptr, SV, SVOffset, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6306 | isVolatile, Alignment); |
| 6307 | if (VT == MVT::f32 || VT == MVT::f64) { |
| 6308 | // f32->i32 or f64->i64 one to one expansion. |
| 6309 | // Remember that we legalized the chain. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6310 | AddLegalizedOperand(SDValue(Node, 1), LegalizeOp(Lo.getValue(1))); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6311 | // Recursively expand the new load. |
| 6312 | if (getTypeAction(NVT) == Expand) |
| 6313 | ExpandOp(Lo, Lo, Hi); |
| 6314 | break; |
| 6315 | } |
| 6316 | |
| 6317 | // Increment the pointer to the other half. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6318 | unsigned IncrementSize = Lo.getValueType().getSizeInBits()/8; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6319 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
Chris Lattner | 5872a36 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 6320 | DAG.getIntPtrConstant(IncrementSize)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6321 | SVOffset += IncrementSize; |
Duncan Sands | a369143 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 6322 | Alignment = MinAlign(Alignment, IncrementSize); |
Dan Gohman | 29c3cef | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 6323 | Hi = DAG.getLoad(NVT, Ch, Ptr, SV, SVOffset, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6324 | isVolatile, Alignment); |
| 6325 | |
| 6326 | // Build a factor node to remember that this load is independent of the |
| 6327 | // other one. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6328 | SDValue TF = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1), |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6329 | Hi.getValue(1)); |
| 6330 | |
| 6331 | // Remember that we legalized the chain. |
| 6332 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(TF)); |
Duncan Sands | 9ff8fbf | 2008-02-11 10:37:04 +0000 | [diff] [blame] | 6333 | if (TLI.isBigEndian()) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6334 | std::swap(Lo, Hi); |
| 6335 | } else { |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6336 | MVT EVT = LD->getMemoryVT(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6337 | |
Dale Johannesen | 2550e3a | 2007-10-19 20:29:00 +0000 | [diff] [blame] | 6338 | if ((VT == MVT::f64 && EVT == MVT::f32) || |
| 6339 | (VT == MVT::ppcf128 && (EVT==MVT::f64 || EVT==MVT::f32))) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6340 | // f64 = EXTLOAD f32 should expand to LOAD, FP_EXTEND |
Dan Gohman | 29c3cef | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 6341 | SDValue Load = DAG.getLoad(EVT, Ch, Ptr, SV, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6342 | SVOffset, isVolatile, Alignment); |
| 6343 | // Remember that we legalized the chain. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6344 | AddLegalizedOperand(SDValue(Node, 1), LegalizeOp(Load.getValue(1))); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6345 | ExpandOp(DAG.getNode(ISD::FP_EXTEND, VT, Load), Lo, Hi); |
| 6346 | break; |
| 6347 | } |
| 6348 | |
| 6349 | if (EVT == NVT) |
Dan Gohman | 29c3cef | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 6350 | Lo = DAG.getLoad(NVT, Ch, Ptr, SV, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6351 | SVOffset, isVolatile, Alignment); |
| 6352 | else |
Dan Gohman | 29c3cef | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 6353 | Lo = DAG.getExtLoad(ExtType, NVT, Ch, Ptr, SV, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6354 | SVOffset, EVT, isVolatile, |
| 6355 | Alignment); |
| 6356 | |
| 6357 | // Remember that we legalized the chain. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6358 | AddLegalizedOperand(SDValue(Node, 1), LegalizeOp(Lo.getValue(1))); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6359 | |
| 6360 | if (ExtType == ISD::SEXTLOAD) { |
| 6361 | // The high part is obtained by SRA'ing all but one of the bits of the |
| 6362 | // lo part. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6363 | unsigned LoSize = Lo.getValueType().getSizeInBits(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6364 | Hi = DAG.getNode(ISD::SRA, NVT, Lo, |
| 6365 | DAG.getConstant(LoSize-1, TLI.getShiftAmountTy())); |
| 6366 | } else if (ExtType == ISD::ZEXTLOAD) { |
| 6367 | // The high part is just a zero. |
| 6368 | Hi = DAG.getConstant(0, NVT); |
| 6369 | } else /* if (ExtType == ISD::EXTLOAD) */ { |
| 6370 | // The high part is undefined. |
| 6371 | Hi = DAG.getNode(ISD::UNDEF, NVT); |
| 6372 | } |
| 6373 | } |
| 6374 | break; |
| 6375 | } |
| 6376 | case ISD::AND: |
| 6377 | case ISD::OR: |
| 6378 | case ISD::XOR: { // Simple logical operators -> two trivial pieces. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6379 | SDValue LL, LH, RL, RH; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6380 | ExpandOp(Node->getOperand(0), LL, LH); |
| 6381 | ExpandOp(Node->getOperand(1), RL, RH); |
| 6382 | Lo = DAG.getNode(Node->getOpcode(), NVT, LL, RL); |
| 6383 | Hi = DAG.getNode(Node->getOpcode(), NVT, LH, RH); |
| 6384 | break; |
| 6385 | } |
| 6386 | case ISD::SELECT: { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6387 | SDValue LL, LH, RL, RH; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6388 | ExpandOp(Node->getOperand(1), LL, LH); |
| 6389 | ExpandOp(Node->getOperand(2), RL, RH); |
| 6390 | if (getTypeAction(NVT) == Expand) |
| 6391 | NVT = TLI.getTypeToExpandTo(NVT); |
| 6392 | Lo = DAG.getNode(ISD::SELECT, NVT, Node->getOperand(0), LL, RL); |
| 6393 | if (VT != MVT::f32) |
| 6394 | Hi = DAG.getNode(ISD::SELECT, NVT, Node->getOperand(0), LH, RH); |
| 6395 | break; |
| 6396 | } |
| 6397 | case ISD::SELECT_CC: { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6398 | SDValue TL, TH, FL, FH; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6399 | ExpandOp(Node->getOperand(2), TL, TH); |
| 6400 | ExpandOp(Node->getOperand(3), FL, FH); |
| 6401 | if (getTypeAction(NVT) == Expand) |
| 6402 | NVT = TLI.getTypeToExpandTo(NVT); |
| 6403 | Lo = DAG.getNode(ISD::SELECT_CC, NVT, Node->getOperand(0), |
| 6404 | Node->getOperand(1), TL, FL, Node->getOperand(4)); |
| 6405 | if (VT != MVT::f32) |
| 6406 | Hi = DAG.getNode(ISD::SELECT_CC, NVT, Node->getOperand(0), |
| 6407 | Node->getOperand(1), TH, FH, Node->getOperand(4)); |
| 6408 | break; |
| 6409 | } |
| 6410 | case ISD::ANY_EXTEND: |
| 6411 | // The low part is any extension of the input (which degenerates to a copy). |
| 6412 | Lo = DAG.getNode(ISD::ANY_EXTEND, NVT, Node->getOperand(0)); |
| 6413 | // The high part is undefined. |
| 6414 | Hi = DAG.getNode(ISD::UNDEF, NVT); |
| 6415 | break; |
| 6416 | case ISD::SIGN_EXTEND: { |
| 6417 | // The low part is just a sign extension of the input (which degenerates to |
| 6418 | // a copy). |
| 6419 | Lo = DAG.getNode(ISD::SIGN_EXTEND, NVT, Node->getOperand(0)); |
| 6420 | |
| 6421 | // The high part is obtained by SRA'ing all but one of the bits of the lo |
| 6422 | // part. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6423 | unsigned LoSize = Lo.getValueType().getSizeInBits(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6424 | Hi = DAG.getNode(ISD::SRA, NVT, Lo, |
| 6425 | DAG.getConstant(LoSize-1, TLI.getShiftAmountTy())); |
| 6426 | break; |
| 6427 | } |
| 6428 | case ISD::ZERO_EXTEND: |
| 6429 | // The low part is just a zero extension of the input (which degenerates to |
| 6430 | // a copy). |
| 6431 | Lo = DAG.getNode(ISD::ZERO_EXTEND, NVT, Node->getOperand(0)); |
| 6432 | |
| 6433 | // The high part is just a zero. |
| 6434 | Hi = DAG.getConstant(0, NVT); |
| 6435 | break; |
| 6436 | |
| 6437 | case ISD::TRUNCATE: { |
| 6438 | // The input value must be larger than this value. Expand *it*. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6439 | SDValue NewLo; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6440 | ExpandOp(Node->getOperand(0), NewLo, Hi); |
| 6441 | |
| 6442 | // The low part is now either the right size, or it is closer. If not the |
| 6443 | // right size, make an illegal truncate so we recursively expand it. |
| 6444 | if (NewLo.getValueType() != Node->getValueType(0)) |
| 6445 | NewLo = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0), NewLo); |
| 6446 | ExpandOp(NewLo, Lo, Hi); |
| 6447 | break; |
| 6448 | } |
| 6449 | |
| 6450 | case ISD::BIT_CONVERT: { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6451 | SDValue Tmp; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6452 | if (TLI.getOperationAction(ISD::BIT_CONVERT, VT) == TargetLowering::Custom){ |
| 6453 | // If the target wants to, allow it to lower this itself. |
| 6454 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 6455 | case Expand: assert(0 && "cannot expand FP!"); |
| 6456 | case Legal: Tmp = LegalizeOp(Node->getOperand(0)); break; |
| 6457 | case Promote: Tmp = PromoteOp (Node->getOperand(0)); break; |
| 6458 | } |
| 6459 | Tmp = TLI.LowerOperation(DAG.getNode(ISD::BIT_CONVERT, VT, Tmp), DAG); |
| 6460 | } |
| 6461 | |
| 6462 | // f32 / f64 must be expanded to i32 / i64. |
| 6463 | if (VT == MVT::f32 || VT == MVT::f64) { |
| 6464 | Lo = DAG.getNode(ISD::BIT_CONVERT, NVT, Node->getOperand(0)); |
| 6465 | if (getTypeAction(NVT) == Expand) |
| 6466 | ExpandOp(Lo, Lo, Hi); |
| 6467 | break; |
| 6468 | } |
| 6469 | |
| 6470 | // If source operand will be expanded to the same type as VT, i.e. |
| 6471 | // i64 <- f64, i32 <- f32, expand the source operand instead. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6472 | MVT VT0 = Node->getOperand(0).getValueType(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6473 | if (getTypeAction(VT0) == Expand && TLI.getTypeToTransformTo(VT0) == VT) { |
| 6474 | ExpandOp(Node->getOperand(0), Lo, Hi); |
| 6475 | break; |
| 6476 | } |
| 6477 | |
| 6478 | // Turn this into a load/store pair by default. |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6479 | if (Tmp.getNode() == 0) |
Chris Lattner | b7d0aaa | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 6480 | Tmp = EmitStackConvert(Node->getOperand(0), VT, VT); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6481 | |
| 6482 | ExpandOp(Tmp, Lo, Hi); |
| 6483 | break; |
| 6484 | } |
| 6485 | |
Chris Lattner | dfb947d | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6486 | case ISD::READCYCLECOUNTER: { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6487 | assert(TLI.getOperationAction(ISD::READCYCLECOUNTER, VT) == |
| 6488 | TargetLowering::Custom && |
| 6489 | "Must custom expand ReadCycleCounter"); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6490 | SDValue Tmp = TLI.LowerOperation(Op, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6491 | assert(Tmp.getNode() && "Node must be custom expanded!"); |
Chris Lattner | dfb947d | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6492 | ExpandOp(Tmp.getValue(0), Lo, Hi); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6493 | AddLegalizedOperand(SDValue(Node, 1), // Remember we legalized the chain. |
Chris Lattner | dfb947d | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6494 | LegalizeOp(Tmp.getValue(1))); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6495 | break; |
Chris Lattner | dfb947d | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6496 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6497 | |
Dale Johannesen | 44eb537 | 2008-10-03 19:41:08 +0000 | [diff] [blame] | 6498 | case ISD::ATOMIC_CMP_SWAP_64: { |
| 6499 | // This operation does not need a loop. |
| 6500 | SDValue Tmp = TLI.LowerOperation(Op, DAG); |
| 6501 | assert(Tmp.getNode() && "Node must be custom expanded!"); |
| 6502 | ExpandOp(Tmp.getValue(0), Lo, Hi); |
| 6503 | AddLegalizedOperand(SDValue(Node, 1), // Remember we legalized the chain. |
| 6504 | LegalizeOp(Tmp.getValue(1))); |
| 6505 | break; |
| 6506 | } |
| 6507 | |
Dale Johannesen | f160d80 | 2008-10-02 18:53:47 +0000 | [diff] [blame] | 6508 | case ISD::ATOMIC_LOAD_ADD_64: |
| 6509 | case ISD::ATOMIC_LOAD_SUB_64: |
| 6510 | case ISD::ATOMIC_LOAD_AND_64: |
| 6511 | case ISD::ATOMIC_LOAD_OR_64: |
| 6512 | case ISD::ATOMIC_LOAD_XOR_64: |
| 6513 | case ISD::ATOMIC_LOAD_NAND_64: |
Dale Johannesen | 44eb537 | 2008-10-03 19:41:08 +0000 | [diff] [blame] | 6514 | case ISD::ATOMIC_SWAP_64: { |
| 6515 | // These operations require a loop to be generated. We can't do that yet, |
| 6516 | // so substitute a target-dependent pseudo and expand that later. |
Dale Johannesen | f160d80 | 2008-10-02 18:53:47 +0000 | [diff] [blame] | 6517 | SDValue In2Lo, In2Hi, In2; |
| 6518 | ExpandOp(Op.getOperand(2), In2Lo, In2Hi); |
| 6519 | In2 = DAG.getNode(ISD::BUILD_PAIR, VT, In2Lo, In2Hi); |
Dale Johannesen | 44eb537 | 2008-10-03 19:41:08 +0000 | [diff] [blame] | 6520 | AtomicSDNode* Anode = cast<AtomicSDNode>(Node); |
| 6521 | SDValue Replace = |
| 6522 | DAG.getAtomic(Op.getOpcode(), Op.getOperand(0), Op.getOperand(1), In2, |
| 6523 | Anode->getSrcValue(), Anode->getAlignment()); |
| 6524 | SDValue Result = TLI.LowerOperation(Replace, DAG); |
Dale Johannesen | f160d80 | 2008-10-02 18:53:47 +0000 | [diff] [blame] | 6525 | ExpandOp(Result.getValue(0), Lo, Hi); |
| 6526 | // Remember that we legalized the chain. |
| 6527 | AddLegalizedOperand(SDValue(Node,1), LegalizeOp(Result.getValue(1))); |
Andrew Lenharth | 8158082 | 2008-03-05 01:15:49 +0000 | [diff] [blame] | 6528 | break; |
| 6529 | } |
| 6530 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6531 | // These operators cannot be expanded directly, emit them as calls to |
| 6532 | // library functions. |
| 6533 | case ISD::FP_TO_SINT: { |
| 6534 | if (TLI.getOperationAction(ISD::FP_TO_SINT, VT) == TargetLowering::Custom) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6535 | SDValue Op; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6536 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 6537 | case Expand: assert(0 && "cannot expand FP!"); |
| 6538 | case Legal: Op = LegalizeOp(Node->getOperand(0)); break; |
| 6539 | case Promote: Op = PromoteOp (Node->getOperand(0)); break; |
| 6540 | } |
| 6541 | |
| 6542 | Op = TLI.LowerOperation(DAG.getNode(ISD::FP_TO_SINT, VT, Op), DAG); |
| 6543 | |
| 6544 | // Now that the custom expander is done, expand the result, which is still |
| 6545 | // VT. |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6546 | if (Op.getNode()) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6547 | ExpandOp(Op, Lo, Hi); |
| 6548 | break; |
| 6549 | } |
| 6550 | } |
| 6551 | |
Duncan Sands | f68dffb | 2008-07-17 02:36:29 +0000 | [diff] [blame] | 6552 | RTLIB::Libcall LC = RTLIB::getFPTOSINT(Node->getOperand(0).getValueType(), |
| 6553 | VT); |
| 6554 | assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unexpected uint-to-fp conversion!"); |
| 6555 | Lo = ExpandLibCall(LC, Node, false/*sign irrelevant*/, Hi); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6556 | break; |
| 6557 | } |
| 6558 | |
| 6559 | case ISD::FP_TO_UINT: { |
| 6560 | if (TLI.getOperationAction(ISD::FP_TO_UINT, VT) == TargetLowering::Custom) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6561 | SDValue Op; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6562 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 6563 | case Expand: assert(0 && "cannot expand FP!"); |
| 6564 | case Legal: Op = LegalizeOp(Node->getOperand(0)); break; |
| 6565 | case Promote: Op = PromoteOp (Node->getOperand(0)); break; |
| 6566 | } |
| 6567 | |
| 6568 | Op = TLI.LowerOperation(DAG.getNode(ISD::FP_TO_UINT, VT, Op), DAG); |
| 6569 | |
| 6570 | // Now that the custom expander is done, expand the result. |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6571 | if (Op.getNode()) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6572 | ExpandOp(Op, Lo, Hi); |
| 6573 | break; |
| 6574 | } |
| 6575 | } |
| 6576 | |
Duncan Sands | f68dffb | 2008-07-17 02:36:29 +0000 | [diff] [blame] | 6577 | RTLIB::Libcall LC = RTLIB::getFPTOUINT(Node->getOperand(0).getValueType(), |
| 6578 | VT); |
| 6579 | assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unexpected fp-to-uint conversion!"); |
| 6580 | Lo = ExpandLibCall(LC, Node, false/*sign irrelevant*/, Hi); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6581 | break; |
| 6582 | } |
| 6583 | |
| 6584 | case ISD::SHL: { |
| 6585 | // If the target wants custom lowering, do so. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6586 | SDValue ShiftAmt = LegalizeOp(Node->getOperand(1)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6587 | if (TLI.getOperationAction(ISD::SHL, VT) == TargetLowering::Custom) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6588 | SDValue Op = DAG.getNode(ISD::SHL, VT, Node->getOperand(0), ShiftAmt); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6589 | Op = TLI.LowerOperation(Op, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6590 | if (Op.getNode()) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6591 | // Now that the custom expander is done, expand the result, which is |
| 6592 | // still VT. |
| 6593 | ExpandOp(Op, Lo, Hi); |
| 6594 | break; |
| 6595 | } |
| 6596 | } |
| 6597 | |
| 6598 | // If ADDC/ADDE are supported and if the shift amount is a constant 1, emit |
| 6599 | // this X << 1 as X+X. |
| 6600 | if (ConstantSDNode *ShAmt = dyn_cast<ConstantSDNode>(ShiftAmt)) { |
Dan Gohman | 9d24dc7 | 2008-03-13 22:13:53 +0000 | [diff] [blame] | 6601 | if (ShAmt->getAPIntValue() == 1 && TLI.isOperationLegal(ISD::ADDC, NVT) && |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6602 | TLI.isOperationLegal(ISD::ADDE, NVT)) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6603 | SDValue LoOps[2], HiOps[3]; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6604 | ExpandOp(Node->getOperand(0), LoOps[0], HiOps[0]); |
| 6605 | SDVTList VTList = DAG.getVTList(LoOps[0].getValueType(), MVT::Flag); |
| 6606 | LoOps[1] = LoOps[0]; |
| 6607 | Lo = DAG.getNode(ISD::ADDC, VTList, LoOps, 2); |
| 6608 | |
| 6609 | HiOps[1] = HiOps[0]; |
| 6610 | HiOps[2] = Lo.getValue(1); |
| 6611 | Hi = DAG.getNode(ISD::ADDE, VTList, HiOps, 3); |
| 6612 | break; |
| 6613 | } |
| 6614 | } |
| 6615 | |
| 6616 | // If we can emit an efficient shift operation, do so now. |
| 6617 | if (ExpandShift(ISD::SHL, Node->getOperand(0), ShiftAmt, Lo, Hi)) |
| 6618 | break; |
| 6619 | |
| 6620 | // If this target supports SHL_PARTS, use it. |
| 6621 | TargetLowering::LegalizeAction Action = |
| 6622 | TLI.getOperationAction(ISD::SHL_PARTS, NVT); |
| 6623 | if ((Action == TargetLowering::Legal && TLI.isTypeLegal(NVT)) || |
| 6624 | Action == TargetLowering::Custom) { |
| 6625 | ExpandShiftParts(ISD::SHL_PARTS, Node->getOperand(0), ShiftAmt, Lo, Hi); |
| 6626 | break; |
| 6627 | } |
| 6628 | |
| 6629 | // Otherwise, emit a libcall. |
Duncan Sands | f1db7c8 | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 6630 | Lo = ExpandLibCall(RTLIB::SHL_I64, Node, false/*left shift=unsigned*/, Hi); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6631 | break; |
| 6632 | } |
| 6633 | |
| 6634 | case ISD::SRA: { |
| 6635 | // If the target wants custom lowering, do so. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6636 | SDValue ShiftAmt = LegalizeOp(Node->getOperand(1)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6637 | if (TLI.getOperationAction(ISD::SRA, VT) == TargetLowering::Custom) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6638 | SDValue Op = DAG.getNode(ISD::SRA, VT, Node->getOperand(0), ShiftAmt); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6639 | Op = TLI.LowerOperation(Op, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6640 | if (Op.getNode()) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6641 | // Now that the custom expander is done, expand the result, which is |
| 6642 | // still VT. |
| 6643 | ExpandOp(Op, Lo, Hi); |
| 6644 | break; |
| 6645 | } |
| 6646 | } |
| 6647 | |
| 6648 | // If we can emit an efficient shift operation, do so now. |
| 6649 | if (ExpandShift(ISD::SRA, Node->getOperand(0), ShiftAmt, Lo, Hi)) |
| 6650 | break; |
| 6651 | |
| 6652 | // If this target supports SRA_PARTS, use it. |
| 6653 | TargetLowering::LegalizeAction Action = |
| 6654 | TLI.getOperationAction(ISD::SRA_PARTS, NVT); |
| 6655 | if ((Action == TargetLowering::Legal && TLI.isTypeLegal(NVT)) || |
| 6656 | Action == TargetLowering::Custom) { |
| 6657 | ExpandShiftParts(ISD::SRA_PARTS, Node->getOperand(0), ShiftAmt, Lo, Hi); |
| 6658 | break; |
| 6659 | } |
| 6660 | |
| 6661 | // Otherwise, emit a libcall. |
Duncan Sands | f1db7c8 | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 6662 | Lo = ExpandLibCall(RTLIB::SRA_I64, Node, true/*ashr is signed*/, Hi); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6663 | break; |
| 6664 | } |
| 6665 | |
| 6666 | case ISD::SRL: { |
| 6667 | // If the target wants custom lowering, do so. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6668 | SDValue ShiftAmt = LegalizeOp(Node->getOperand(1)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6669 | if (TLI.getOperationAction(ISD::SRL, VT) == TargetLowering::Custom) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6670 | SDValue Op = DAG.getNode(ISD::SRL, VT, Node->getOperand(0), ShiftAmt); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6671 | Op = TLI.LowerOperation(Op, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6672 | if (Op.getNode()) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6673 | // Now that the custom expander is done, expand the result, which is |
| 6674 | // still VT. |
| 6675 | ExpandOp(Op, Lo, Hi); |
| 6676 | break; |
| 6677 | } |
| 6678 | } |
| 6679 | |
| 6680 | // If we can emit an efficient shift operation, do so now. |
| 6681 | if (ExpandShift(ISD::SRL, Node->getOperand(0), ShiftAmt, Lo, Hi)) |
| 6682 | break; |
| 6683 | |
| 6684 | // If this target supports SRL_PARTS, use it. |
| 6685 | TargetLowering::LegalizeAction Action = |
| 6686 | TLI.getOperationAction(ISD::SRL_PARTS, NVT); |
| 6687 | if ((Action == TargetLowering::Legal && TLI.isTypeLegal(NVT)) || |
| 6688 | Action == TargetLowering::Custom) { |
| 6689 | ExpandShiftParts(ISD::SRL_PARTS, Node->getOperand(0), ShiftAmt, Lo, Hi); |
| 6690 | break; |
| 6691 | } |
| 6692 | |
| 6693 | // Otherwise, emit a libcall. |
Duncan Sands | f1db7c8 | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 6694 | Lo = ExpandLibCall(RTLIB::SRL_I64, Node, false/*lshr is unsigned*/, Hi); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6695 | break; |
| 6696 | } |
| 6697 | |
| 6698 | case ISD::ADD: |
| 6699 | case ISD::SUB: { |
| 6700 | // If the target wants to custom expand this, let them. |
| 6701 | if (TLI.getOperationAction(Node->getOpcode(), VT) == |
| 6702 | TargetLowering::Custom) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6703 | SDValue Result = TLI.LowerOperation(Op, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6704 | if (Result.getNode()) { |
Duncan Sands | 4c3885b | 2008-06-22 09:42:16 +0000 | [diff] [blame] | 6705 | ExpandOp(Result, Lo, Hi); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6706 | break; |
| 6707 | } |
| 6708 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6709 | // Expand the subcomponents. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6710 | SDValue LHSL, LHSH, RHSL, RHSH; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6711 | ExpandOp(Node->getOperand(0), LHSL, LHSH); |
| 6712 | ExpandOp(Node->getOperand(1), RHSL, RHSH); |
| 6713 | SDVTList VTList = DAG.getVTList(LHSL.getValueType(), MVT::Flag); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6714 | SDValue LoOps[2], HiOps[3]; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6715 | LoOps[0] = LHSL; |
| 6716 | LoOps[1] = RHSL; |
| 6717 | HiOps[0] = LHSH; |
| 6718 | HiOps[1] = RHSH; |
Andrew Lenharth | 97c315a | 2008-10-07 18:27:23 +0000 | [diff] [blame] | 6719 | |
Andrew Lenharth | a23d699 | 2008-10-07 17:03:15 +0000 | [diff] [blame] | 6720 | //cascaded check to see if any smaller size has a a carry flag. |
| 6721 | unsigned OpV = Node->getOpcode() == ISD::ADD ? ISD::ADDC : ISD::SUBC; |
| 6722 | bool hasCarry = false; |
Andrew Lenharth | 97c315a | 2008-10-07 18:27:23 +0000 | [diff] [blame] | 6723 | for (unsigned BitSize = NVT.getSizeInBits(); BitSize != 0; BitSize /= 2) { |
| 6724 | MVT AVT = MVT::getIntegerVT(BitSize); |
| 6725 | if (TLI.isOperationLegal(OpV, AVT)) { |
| 6726 | hasCarry = true; |
| 6727 | break; |
| 6728 | } |
| 6729 | } |
| 6730 | |
Andrew Lenharth | a23d699 | 2008-10-07 17:03:15 +0000 | [diff] [blame] | 6731 | if(hasCarry) { |
Andrew Lenharth | 5e81446 | 2008-10-07 14:15:42 +0000 | [diff] [blame] | 6732 | if (Node->getOpcode() == ISD::ADD) { |
| 6733 | Lo = DAG.getNode(ISD::ADDC, VTList, LoOps, 2); |
| 6734 | HiOps[2] = Lo.getValue(1); |
| 6735 | Hi = DAG.getNode(ISD::ADDE, VTList, HiOps, 3); |
| 6736 | } else { |
| 6737 | Lo = DAG.getNode(ISD::SUBC, VTList, LoOps, 2); |
| 6738 | HiOps[2] = Lo.getValue(1); |
| 6739 | Hi = DAG.getNode(ISD::SUBE, VTList, HiOps, 3); |
| 6740 | } |
| 6741 | break; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6742 | } else { |
Andrew Lenharth | 5e81446 | 2008-10-07 14:15:42 +0000 | [diff] [blame] | 6743 | if (Node->getOpcode() == ISD::ADD) { |
| 6744 | Lo = DAG.getNode(ISD::ADD, VTList, LoOps, 2); |
| 6745 | Hi = DAG.getNode(ISD::ADD, VTList, HiOps, 2); |
Andrew Lenharth | a23d699 | 2008-10-07 17:03:15 +0000 | [diff] [blame] | 6746 | SDValue Cmp1 = DAG.getSetCC(TLI.getSetCCResultType(Lo), |
| 6747 | Lo, LoOps[0], ISD::SETULT); |
Andrew Lenharth | 5e81446 | 2008-10-07 14:15:42 +0000 | [diff] [blame] | 6748 | SDValue Carry1 = DAG.getNode(ISD::SELECT, NVT, Cmp1, |
| 6749 | DAG.getConstant(1, NVT), |
| 6750 | DAG.getConstant(0, NVT)); |
Andrew Lenharth | a23d699 | 2008-10-07 17:03:15 +0000 | [diff] [blame] | 6751 | SDValue Cmp2 = DAG.getSetCC(TLI.getSetCCResultType(Lo), |
| 6752 | Lo, LoOps[1], ISD::SETULT); |
Andrew Lenharth | 5e81446 | 2008-10-07 14:15:42 +0000 | [diff] [blame] | 6753 | SDValue Carry2 = DAG.getNode(ISD::SELECT, NVT, Cmp2, |
| 6754 | DAG.getConstant(1, NVT), |
| 6755 | Carry1); |
| 6756 | Hi = DAG.getNode(ISD::ADD, NVT, Hi, Carry2); |
| 6757 | } else { |
| 6758 | Lo = DAG.getNode(ISD::SUB, VTList, LoOps, 2); |
| 6759 | Hi = DAG.getNode(ISD::SUB, VTList, HiOps, 2); |
| 6760 | SDValue Cmp = DAG.getSetCC(NVT, LoOps[0], LoOps[1], ISD::SETULT); |
| 6761 | SDValue Borrow = DAG.getNode(ISD::SELECT, NVT, Cmp, |
| 6762 | DAG.getConstant(1, NVT), |
| 6763 | DAG.getConstant(0, NVT)); |
| 6764 | Hi = DAG.getNode(ISD::SUB, NVT, Hi, Borrow); |
| 6765 | } |
| 6766 | break; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6767 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6768 | } |
| 6769 | |
| 6770 | case ISD::ADDC: |
| 6771 | case ISD::SUBC: { |
| 6772 | // Expand the subcomponents. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6773 | SDValue LHSL, LHSH, RHSL, RHSH; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6774 | ExpandOp(Node->getOperand(0), LHSL, LHSH); |
| 6775 | ExpandOp(Node->getOperand(1), RHSL, RHSH); |
| 6776 | SDVTList VTList = DAG.getVTList(LHSL.getValueType(), MVT::Flag); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6777 | SDValue LoOps[2] = { LHSL, RHSL }; |
| 6778 | SDValue HiOps[3] = { LHSH, RHSH }; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6779 | |
| 6780 | if (Node->getOpcode() == ISD::ADDC) { |
| 6781 | Lo = DAG.getNode(ISD::ADDC, VTList, LoOps, 2); |
| 6782 | HiOps[2] = Lo.getValue(1); |
| 6783 | Hi = DAG.getNode(ISD::ADDE, VTList, HiOps, 3); |
| 6784 | } else { |
| 6785 | Lo = DAG.getNode(ISD::SUBC, VTList, LoOps, 2); |
| 6786 | HiOps[2] = Lo.getValue(1); |
| 6787 | Hi = DAG.getNode(ISD::SUBE, VTList, HiOps, 3); |
| 6788 | } |
| 6789 | // Remember that we legalized the flag. |
| 6790 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Hi.getValue(1))); |
| 6791 | break; |
| 6792 | } |
| 6793 | case ISD::ADDE: |
| 6794 | case ISD::SUBE: { |
| 6795 | // Expand the subcomponents. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6796 | SDValue LHSL, LHSH, RHSL, RHSH; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6797 | ExpandOp(Node->getOperand(0), LHSL, LHSH); |
| 6798 | ExpandOp(Node->getOperand(1), RHSL, RHSH); |
| 6799 | SDVTList VTList = DAG.getVTList(LHSL.getValueType(), MVT::Flag); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6800 | SDValue LoOps[3] = { LHSL, RHSL, Node->getOperand(2) }; |
| 6801 | SDValue HiOps[3] = { LHSH, RHSH }; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6802 | |
| 6803 | Lo = DAG.getNode(Node->getOpcode(), VTList, LoOps, 3); |
| 6804 | HiOps[2] = Lo.getValue(1); |
| 6805 | Hi = DAG.getNode(Node->getOpcode(), VTList, HiOps, 3); |
| 6806 | |
| 6807 | // Remember that we legalized the flag. |
| 6808 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Hi.getValue(1))); |
| 6809 | break; |
| 6810 | } |
| 6811 | case ISD::MUL: { |
| 6812 | // If the target wants to custom expand this, let them. |
| 6813 | if (TLI.getOperationAction(ISD::MUL, VT) == TargetLowering::Custom) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6814 | SDValue New = TLI.LowerOperation(Op, DAG); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6815 | if (New.getNode()) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6816 | ExpandOp(New, Lo, Hi); |
| 6817 | break; |
| 6818 | } |
| 6819 | } |
| 6820 | |
| 6821 | bool HasMULHS = TLI.isOperationLegal(ISD::MULHS, NVT); |
| 6822 | bool HasMULHU = TLI.isOperationLegal(ISD::MULHU, NVT); |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 6823 | bool HasSMUL_LOHI = TLI.isOperationLegal(ISD::SMUL_LOHI, NVT); |
| 6824 | bool HasUMUL_LOHI = TLI.isOperationLegal(ISD::UMUL_LOHI, NVT); |
| 6825 | if (HasMULHU || HasMULHS || HasUMUL_LOHI || HasSMUL_LOHI) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6826 | SDValue LL, LH, RL, RH; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6827 | ExpandOp(Node->getOperand(0), LL, LH); |
| 6828 | ExpandOp(Node->getOperand(1), RL, RH); |
Dan Gohman | 07961cd | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 6829 | unsigned OuterBitSize = Op.getValueSizeInBits(); |
| 6830 | unsigned InnerBitSize = RH.getValueSizeInBits(); |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 6831 | unsigned LHSSB = DAG.ComputeNumSignBits(Op.getOperand(0)); |
| 6832 | unsigned RHSSB = DAG.ComputeNumSignBits(Op.getOperand(1)); |
Dan Gohman | 2594d94 | 2008-03-10 20:42:19 +0000 | [diff] [blame] | 6833 | APInt HighMask = APInt::getHighBitsSet(OuterBitSize, InnerBitSize); |
| 6834 | if (DAG.MaskedValueIsZero(Node->getOperand(0), HighMask) && |
| 6835 | DAG.MaskedValueIsZero(Node->getOperand(1), HighMask)) { |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 6836 | // The inputs are both zero-extended. |
| 6837 | if (HasUMUL_LOHI) { |
| 6838 | // We can emit a umul_lohi. |
| 6839 | Lo = DAG.getNode(ISD::UMUL_LOHI, DAG.getVTList(NVT, NVT), LL, RL); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6840 | Hi = SDValue(Lo.getNode(), 1); |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 6841 | break; |
| 6842 | } |
| 6843 | if (HasMULHU) { |
| 6844 | // We can emit a mulhu+mul. |
| 6845 | Lo = DAG.getNode(ISD::MUL, NVT, LL, RL); |
| 6846 | Hi = DAG.getNode(ISD::MULHU, NVT, LL, RL); |
| 6847 | break; |
| 6848 | } |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 6849 | } |
Dan Gohman | 07961cd | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 6850 | if (LHSSB > InnerBitSize && RHSSB > InnerBitSize) { |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 6851 | // The input values are both sign-extended. |
| 6852 | if (HasSMUL_LOHI) { |
| 6853 | // We can emit a smul_lohi. |
| 6854 | Lo = DAG.getNode(ISD::SMUL_LOHI, DAG.getVTList(NVT, NVT), LL, RL); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6855 | Hi = SDValue(Lo.getNode(), 1); |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 6856 | break; |
| 6857 | } |
| 6858 | if (HasMULHS) { |
| 6859 | // We can emit a mulhs+mul. |
| 6860 | Lo = DAG.getNode(ISD::MUL, NVT, LL, RL); |
| 6861 | Hi = DAG.getNode(ISD::MULHS, NVT, LL, RL); |
| 6862 | break; |
| 6863 | } |
| 6864 | } |
| 6865 | if (HasUMUL_LOHI) { |
| 6866 | // Lo,Hi = umul LHS, RHS. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6867 | SDValue UMulLOHI = DAG.getNode(ISD::UMUL_LOHI, |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 6868 | DAG.getVTList(NVT, NVT), LL, RL); |
| 6869 | Lo = UMulLOHI; |
| 6870 | Hi = UMulLOHI.getValue(1); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6871 | RH = DAG.getNode(ISD::MUL, NVT, LL, RH); |
| 6872 | LH = DAG.getNode(ISD::MUL, NVT, LH, RL); |
| 6873 | Hi = DAG.getNode(ISD::ADD, NVT, Hi, RH); |
| 6874 | Hi = DAG.getNode(ISD::ADD, NVT, Hi, LH); |
| 6875 | break; |
| 6876 | } |
Dale Johannesen | 612c88b | 2007-10-24 22:26:08 +0000 | [diff] [blame] | 6877 | if (HasMULHU) { |
| 6878 | Lo = DAG.getNode(ISD::MUL, NVT, LL, RL); |
| 6879 | Hi = DAG.getNode(ISD::MULHU, NVT, LL, RL); |
| 6880 | RH = DAG.getNode(ISD::MUL, NVT, LL, RH); |
| 6881 | LH = DAG.getNode(ISD::MUL, NVT, LH, RL); |
| 6882 | Hi = DAG.getNode(ISD::ADD, NVT, Hi, RH); |
| 6883 | Hi = DAG.getNode(ISD::ADD, NVT, Hi, LH); |
| 6884 | break; |
| 6885 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6886 | } |
| 6887 | |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 6888 | // If nothing else, we can make a libcall. |
Duncan Sands | f1db7c8 | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 6889 | Lo = ExpandLibCall(RTLIB::MUL_I64, Node, false/*sign irrelevant*/, Hi); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6890 | break; |
| 6891 | } |
| 6892 | case ISD::SDIV: |
Duncan Sands | f1db7c8 | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 6893 | Lo = ExpandLibCall(RTLIB::SDIV_I64, Node, true, Hi); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6894 | break; |
| 6895 | case ISD::UDIV: |
Duncan Sands | f1db7c8 | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 6896 | Lo = ExpandLibCall(RTLIB::UDIV_I64, Node, true, Hi); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6897 | break; |
| 6898 | case ISD::SREM: |
Duncan Sands | f1db7c8 | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 6899 | Lo = ExpandLibCall(RTLIB::SREM_I64, Node, true, Hi); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6900 | break; |
| 6901 | case ISD::UREM: |
Duncan Sands | f1db7c8 | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 6902 | Lo = ExpandLibCall(RTLIB::UREM_I64, Node, true, Hi); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6903 | break; |
| 6904 | |
| 6905 | case ISD::FADD: |
Duncan Sands | f1db7c8 | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 6906 | Lo = ExpandLibCall(GetFPLibCall(VT, RTLIB::ADD_F32, |
| 6907 | RTLIB::ADD_F64, |
| 6908 | RTLIB::ADD_F80, |
| 6909 | RTLIB::ADD_PPCF128), |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6910 | Node, false, Hi); |
| 6911 | break; |
| 6912 | case ISD::FSUB: |
Duncan Sands | f1db7c8 | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 6913 | Lo = ExpandLibCall(GetFPLibCall(VT, RTLIB::SUB_F32, |
| 6914 | RTLIB::SUB_F64, |
| 6915 | RTLIB::SUB_F80, |
| 6916 | RTLIB::SUB_PPCF128), |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6917 | Node, false, Hi); |
| 6918 | break; |
| 6919 | case ISD::FMUL: |
Duncan Sands | f1db7c8 | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 6920 | Lo = ExpandLibCall(GetFPLibCall(VT, RTLIB::MUL_F32, |
| 6921 | RTLIB::MUL_F64, |
| 6922 | RTLIB::MUL_F80, |
| 6923 | RTLIB::MUL_PPCF128), |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6924 | Node, false, Hi); |
| 6925 | break; |
| 6926 | case ISD::FDIV: |
Duncan Sands | f1db7c8 | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 6927 | Lo = ExpandLibCall(GetFPLibCall(VT, RTLIB::DIV_F32, |
| 6928 | RTLIB::DIV_F64, |
| 6929 | RTLIB::DIV_F80, |
| 6930 | RTLIB::DIV_PPCF128), |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6931 | Node, false, Hi); |
| 6932 | break; |
Duncan Sands | f68dffb | 2008-07-17 02:36:29 +0000 | [diff] [blame] | 6933 | case ISD::FP_EXTEND: { |
Dale Johannesen | 4c14d51 | 2007-10-12 01:37:08 +0000 | [diff] [blame] | 6934 | if (VT == MVT::ppcf128) { |
| 6935 | assert(Node->getOperand(0).getValueType()==MVT::f32 || |
| 6936 | Node->getOperand(0).getValueType()==MVT::f64); |
| 6937 | const uint64_t zero = 0; |
| 6938 | if (Node->getOperand(0).getValueType()==MVT::f32) |
| 6939 | Hi = DAG.getNode(ISD::FP_EXTEND, MVT::f64, Node->getOperand(0)); |
| 6940 | else |
| 6941 | Hi = Node->getOperand(0); |
| 6942 | Lo = DAG.getConstantFP(APFloat(APInt(64, 1, &zero)), MVT::f64); |
| 6943 | break; |
| 6944 | } |
Duncan Sands | f68dffb | 2008-07-17 02:36:29 +0000 | [diff] [blame] | 6945 | RTLIB::Libcall LC = RTLIB::getFPEXT(Node->getOperand(0).getValueType(), VT); |
| 6946 | assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported FP_EXTEND!"); |
| 6947 | Lo = ExpandLibCall(LC, Node, true, Hi); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6948 | break; |
Duncan Sands | f68dffb | 2008-07-17 02:36:29 +0000 | [diff] [blame] | 6949 | } |
| 6950 | case ISD::FP_ROUND: { |
| 6951 | RTLIB::Libcall LC = RTLIB::getFPROUND(Node->getOperand(0).getValueType(), |
| 6952 | VT); |
| 6953 | assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported FP_ROUND!"); |
| 6954 | Lo = ExpandLibCall(LC, Node, true, Hi); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6955 | break; |
Duncan Sands | f68dffb | 2008-07-17 02:36:29 +0000 | [diff] [blame] | 6956 | } |
Evan Cheng | 5316b39 | 2008-09-09 23:02:14 +0000 | [diff] [blame] | 6957 | case ISD::FSQRT: |
| 6958 | case ISD::FSIN: |
| 6959 | case ISD::FCOS: |
Dale Johannesen | 92b3308 | 2008-09-04 00:47:13 +0000 | [diff] [blame] | 6960 | case ISD::FLOG: |
| 6961 | case ISD::FLOG2: |
| 6962 | case ISD::FLOG10: |
| 6963 | case ISD::FEXP: |
| 6964 | case ISD::FEXP2: |
Dan Gohman | b215823 | 2008-08-21 18:38:14 +0000 | [diff] [blame] | 6965 | case ISD::FTRUNC: |
| 6966 | case ISD::FFLOOR: |
| 6967 | case ISD::FCEIL: |
| 6968 | case ISD::FRINT: |
| 6969 | case ISD::FNEARBYINT: |
Evan Cheng | 1fac695 | 2008-09-09 23:35:53 +0000 | [diff] [blame] | 6970 | case ISD::FPOW: |
| 6971 | case ISD::FPOWI: { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6972 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
| 6973 | switch(Node->getOpcode()) { |
| 6974 | case ISD::FSQRT: |
Duncan Sands | 37a3f47 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 6975 | LC = GetFPLibCall(VT, RTLIB::SQRT_F32, RTLIB::SQRT_F64, |
| 6976 | RTLIB::SQRT_F80, RTLIB::SQRT_PPCF128); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6977 | break; |
| 6978 | case ISD::FSIN: |
Duncan Sands | 37a3f47 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 6979 | LC = GetFPLibCall(VT, RTLIB::SIN_F32, RTLIB::SIN_F64, |
| 6980 | RTLIB::SIN_F80, RTLIB::SIN_PPCF128); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6981 | break; |
| 6982 | case ISD::FCOS: |
Duncan Sands | 37a3f47 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 6983 | LC = GetFPLibCall(VT, RTLIB::COS_F32, RTLIB::COS_F64, |
| 6984 | RTLIB::COS_F80, RTLIB::COS_PPCF128); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 6985 | break; |
Dale Johannesen | 92b3308 | 2008-09-04 00:47:13 +0000 | [diff] [blame] | 6986 | case ISD::FLOG: |
| 6987 | LC = GetFPLibCall(VT, RTLIB::LOG_F32, RTLIB::LOG_F64, |
| 6988 | RTLIB::LOG_F80, RTLIB::LOG_PPCF128); |
| 6989 | break; |
| 6990 | case ISD::FLOG2: |
| 6991 | LC = GetFPLibCall(VT, RTLIB::LOG2_F32, RTLIB::LOG2_F64, |
| 6992 | RTLIB::LOG2_F80, RTLIB::LOG2_PPCF128); |
| 6993 | break; |
| 6994 | case ISD::FLOG10: |
| 6995 | LC = GetFPLibCall(VT, RTLIB::LOG10_F32, RTLIB::LOG10_F64, |
| 6996 | RTLIB::LOG10_F80, RTLIB::LOG10_PPCF128); |
| 6997 | break; |
| 6998 | case ISD::FEXP: |
| 6999 | LC = GetFPLibCall(VT, RTLIB::EXP_F32, RTLIB::EXP_F64, |
| 7000 | RTLIB::EXP_F80, RTLIB::EXP_PPCF128); |
| 7001 | break; |
| 7002 | case ISD::FEXP2: |
| 7003 | LC = GetFPLibCall(VT, RTLIB::EXP2_F32, RTLIB::EXP2_F64, |
| 7004 | RTLIB::EXP2_F80, RTLIB::EXP2_PPCF128); |
| 7005 | break; |
Dan Gohman | b215823 | 2008-08-21 18:38:14 +0000 | [diff] [blame] | 7006 | case ISD::FTRUNC: |
| 7007 | LC = GetFPLibCall(VT, RTLIB::TRUNC_F32, RTLIB::TRUNC_F64, |
| 7008 | RTLIB::TRUNC_F80, RTLIB::TRUNC_PPCF128); |
| 7009 | break; |
| 7010 | case ISD::FFLOOR: |
| 7011 | LC = GetFPLibCall(VT, RTLIB::FLOOR_F32, RTLIB::FLOOR_F64, |
| 7012 | RTLIB::FLOOR_F80, RTLIB::FLOOR_PPCF128); |
| 7013 | break; |
| 7014 | case ISD::FCEIL: |
| 7015 | LC = GetFPLibCall(VT, RTLIB::CEIL_F32, RTLIB::CEIL_F64, |
| 7016 | RTLIB::CEIL_F80, RTLIB::CEIL_PPCF128); |
| 7017 | break; |
| 7018 | case ISD::FRINT: |
| 7019 | LC = GetFPLibCall(VT, RTLIB::RINT_F32, RTLIB::RINT_F64, |
| 7020 | RTLIB::RINT_F80, RTLIB::RINT_PPCF128); |
| 7021 | break; |
| 7022 | case ISD::FNEARBYINT: |
| 7023 | LC = GetFPLibCall(VT, RTLIB::NEARBYINT_F32, RTLIB::NEARBYINT_F64, |
| 7024 | RTLIB::NEARBYINT_F80, RTLIB::NEARBYINT_PPCF128); |
| 7025 | break; |
Evan Cheng | 5316b39 | 2008-09-09 23:02:14 +0000 | [diff] [blame] | 7026 | case ISD::FPOW: |
| 7027 | LC = GetFPLibCall(VT, RTLIB::POW_F32, RTLIB::POW_F64, RTLIB::POW_F80, |
| 7028 | RTLIB::POW_PPCF128); |
| 7029 | break; |
| 7030 | case ISD::FPOWI: |
| 7031 | LC = GetFPLibCall(VT, RTLIB::POWI_F32, RTLIB::POWI_F64, RTLIB::POWI_F80, |
| 7032 | RTLIB::POWI_PPCF128); |
| 7033 | break; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7034 | default: assert(0 && "Unreachable!"); |
| 7035 | } |
Duncan Sands | f1db7c8 | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 7036 | Lo = ExpandLibCall(LC, Node, false, Hi); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7037 | break; |
| 7038 | } |
| 7039 | case ISD::FABS: { |
Dale Johannesen | 5707ef8 | 2007-10-12 19:02:17 +0000 | [diff] [blame] | 7040 | if (VT == MVT::ppcf128) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7041 | SDValue Tmp; |
Dale Johannesen | 5707ef8 | 2007-10-12 19:02:17 +0000 | [diff] [blame] | 7042 | ExpandOp(Node->getOperand(0), Lo, Tmp); |
| 7043 | Hi = DAG.getNode(ISD::FABS, NVT, Tmp); |
| 7044 | // lo = hi==fabs(hi) ? lo : -lo; |
| 7045 | Lo = DAG.getNode(ISD::SELECT_CC, NVT, Hi, Tmp, |
| 7046 | Lo, DAG.getNode(ISD::FNEG, NVT, Lo), |
| 7047 | DAG.getCondCode(ISD::SETEQ)); |
| 7048 | break; |
| 7049 | } |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7050 | SDValue Mask = (VT == MVT::f64) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7051 | ? DAG.getConstantFP(BitsToDouble(~(1ULL << 63)), VT) |
| 7052 | : DAG.getConstantFP(BitsToFloat(~(1U << 31)), VT); |
| 7053 | Mask = DAG.getNode(ISD::BIT_CONVERT, NVT, Mask); |
| 7054 | Lo = DAG.getNode(ISD::BIT_CONVERT, NVT, Node->getOperand(0)); |
| 7055 | Lo = DAG.getNode(ISD::AND, NVT, Lo, Mask); |
| 7056 | if (getTypeAction(NVT) == Expand) |
| 7057 | ExpandOp(Lo, Lo, Hi); |
| 7058 | break; |
| 7059 | } |
| 7060 | case ISD::FNEG: { |
Dale Johannesen | 5707ef8 | 2007-10-12 19:02:17 +0000 | [diff] [blame] | 7061 | if (VT == MVT::ppcf128) { |
| 7062 | ExpandOp(Node->getOperand(0), Lo, Hi); |
| 7063 | Lo = DAG.getNode(ISD::FNEG, MVT::f64, Lo); |
| 7064 | Hi = DAG.getNode(ISD::FNEG, MVT::f64, Hi); |
| 7065 | break; |
| 7066 | } |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7067 | SDValue Mask = (VT == MVT::f64) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7068 | ? DAG.getConstantFP(BitsToDouble(1ULL << 63), VT) |
| 7069 | : DAG.getConstantFP(BitsToFloat(1U << 31), VT); |
| 7070 | Mask = DAG.getNode(ISD::BIT_CONVERT, NVT, Mask); |
| 7071 | Lo = DAG.getNode(ISD::BIT_CONVERT, NVT, Node->getOperand(0)); |
| 7072 | Lo = DAG.getNode(ISD::XOR, NVT, Lo, Mask); |
| 7073 | if (getTypeAction(NVT) == Expand) |
| 7074 | ExpandOp(Lo, Lo, Hi); |
| 7075 | break; |
| 7076 | } |
| 7077 | case ISD::FCOPYSIGN: { |
| 7078 | Lo = ExpandFCOPYSIGNToBitwiseOps(Node, NVT, DAG, TLI); |
| 7079 | if (getTypeAction(NVT) == Expand) |
| 7080 | ExpandOp(Lo, Lo, Hi); |
| 7081 | break; |
| 7082 | } |
| 7083 | case ISD::SINT_TO_FP: |
| 7084 | case ISD::UINT_TO_FP: { |
| 7085 | bool isSigned = Node->getOpcode() == ISD::SINT_TO_FP; |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 7086 | MVT SrcVT = Node->getOperand(0).getValueType(); |
Dale Johannesen | 6a779c8 | 2008-03-18 17:28:38 +0000 | [diff] [blame] | 7087 | |
| 7088 | // Promote the operand if needed. Do this before checking for |
| 7089 | // ppcf128 so conversions of i16 and i8 work. |
| 7090 | if (getTypeAction(SrcVT) == Promote) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7091 | SDValue Tmp = PromoteOp(Node->getOperand(0)); |
Dale Johannesen | 6a779c8 | 2008-03-18 17:28:38 +0000 | [diff] [blame] | 7092 | Tmp = isSigned |
| 7093 | ? DAG.getNode(ISD::SIGN_EXTEND_INREG, Tmp.getValueType(), Tmp, |
| 7094 | DAG.getValueType(SrcVT)) |
| 7095 | : DAG.getZeroExtendInReg(Tmp, SrcVT); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 7096 | Node = DAG.UpdateNodeOperands(Op, Tmp).getNode(); |
Dale Johannesen | 6a779c8 | 2008-03-18 17:28:38 +0000 | [diff] [blame] | 7097 | SrcVT = Node->getOperand(0).getValueType(); |
| 7098 | } |
| 7099 | |
Dan Gohman | ec51f64 | 2008-03-10 23:03:31 +0000 | [diff] [blame] | 7100 | if (VT == MVT::ppcf128 && SrcVT == MVT::i32) { |
Dan Gohman | 84d0096 | 2008-02-25 21:39:34 +0000 | [diff] [blame] | 7101 | static const uint64_t zero = 0; |
Dale Johannesen | 4c14d51 | 2007-10-12 01:37:08 +0000 | [diff] [blame] | 7102 | if (isSigned) { |
| 7103 | Hi = LegalizeOp(DAG.getNode(ISD::SINT_TO_FP, MVT::f64, |
| 7104 | Node->getOperand(0))); |
| 7105 | Lo = DAG.getConstantFP(APFloat(APInt(64, 1, &zero)), MVT::f64); |
| 7106 | } else { |
Dan Gohman | 84d0096 | 2008-02-25 21:39:34 +0000 | [diff] [blame] | 7107 | static const uint64_t TwoE32[] = { 0x41f0000000000000LL, 0 }; |
Dale Johannesen | 4c14d51 | 2007-10-12 01:37:08 +0000 | [diff] [blame] | 7108 | Hi = LegalizeOp(DAG.getNode(ISD::SINT_TO_FP, MVT::f64, |
| 7109 | Node->getOperand(0))); |
| 7110 | Lo = DAG.getConstantFP(APFloat(APInt(64, 1, &zero)), MVT::f64); |
| 7111 | Hi = DAG.getNode(ISD::BUILD_PAIR, VT, Lo, Hi); |
Dale Johannesen | 9aec5b2 | 2007-10-12 17:52:03 +0000 | [diff] [blame] | 7112 | // X>=0 ? {(f64)x, 0} : {(f64)x, 0} + 2^32 |
Dale Johannesen | 4c14d51 | 2007-10-12 01:37:08 +0000 | [diff] [blame] | 7113 | ExpandOp(DAG.getNode(ISD::SELECT_CC, MVT::ppcf128, Node->getOperand(0), |
| 7114 | DAG.getConstant(0, MVT::i32), |
| 7115 | DAG.getNode(ISD::FADD, MVT::ppcf128, Hi, |
| 7116 | DAG.getConstantFP( |
| 7117 | APFloat(APInt(128, 2, TwoE32)), |
| 7118 | MVT::ppcf128)), |
| 7119 | Hi, |
| 7120 | DAG.getCondCode(ISD::SETLT)), |
| 7121 | Lo, Hi); |
| 7122 | } |
| 7123 | break; |
| 7124 | } |
Dale Johannesen | 9aec5b2 | 2007-10-12 17:52:03 +0000 | [diff] [blame] | 7125 | if (VT == MVT::ppcf128 && SrcVT == MVT::i64 && !isSigned) { |
| 7126 | // si64->ppcf128 done by libcall, below |
Dan Gohman | 84d0096 | 2008-02-25 21:39:34 +0000 | [diff] [blame] | 7127 | static const uint64_t TwoE64[] = { 0x43f0000000000000LL, 0 }; |
Dale Johannesen | 9aec5b2 | 2007-10-12 17:52:03 +0000 | [diff] [blame] | 7128 | ExpandOp(DAG.getNode(ISD::SINT_TO_FP, MVT::ppcf128, Node->getOperand(0)), |
| 7129 | Lo, Hi); |
| 7130 | Hi = DAG.getNode(ISD::BUILD_PAIR, VT, Lo, Hi); |
| 7131 | // x>=0 ? (ppcf128)(i64)x : (ppcf128)(i64)x + 2^64 |
| 7132 | ExpandOp(DAG.getNode(ISD::SELECT_CC, MVT::ppcf128, Node->getOperand(0), |
| 7133 | DAG.getConstant(0, MVT::i64), |
| 7134 | DAG.getNode(ISD::FADD, MVT::ppcf128, Hi, |
| 7135 | DAG.getConstantFP( |
| 7136 | APFloat(APInt(128, 2, TwoE64)), |
| 7137 | MVT::ppcf128)), |
| 7138 | Hi, |
| 7139 | DAG.getCondCode(ISD::SETLT)), |
| 7140 | Lo, Hi); |
| 7141 | break; |
| 7142 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7143 | |
Dan Gohman | ec51f64 | 2008-03-10 23:03:31 +0000 | [diff] [blame] | 7144 | Lo = ExpandIntToFP(Node->getOpcode() == ISD::SINT_TO_FP, VT, |
| 7145 | Node->getOperand(0)); |
Evan Cheng | a874003 | 2008-04-01 01:50:16 +0000 | [diff] [blame] | 7146 | if (getTypeAction(Lo.getValueType()) == Expand) |
Evan Cheng | 4a2f6df | 2008-04-01 01:51:26 +0000 | [diff] [blame] | 7147 | // float to i32 etc. can be 'expanded' to a single node. |
Evan Cheng | a874003 | 2008-04-01 01:50:16 +0000 | [diff] [blame] | 7148 | ExpandOp(Lo, Lo, Hi); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7149 | break; |
| 7150 | } |
| 7151 | } |
| 7152 | |
| 7153 | // Make sure the resultant values have been legalized themselves, unless this |
| 7154 | // is a type that requires multi-step expansion. |
| 7155 | if (getTypeAction(NVT) != Expand && NVT != MVT::isVoid) { |
| 7156 | Lo = LegalizeOp(Lo); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 7157 | if (Hi.getNode()) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7158 | // Don't legalize the high part if it is expanded to a single node. |
| 7159 | Hi = LegalizeOp(Hi); |
| 7160 | } |
| 7161 | |
| 7162 | // Remember in a map if the values will be reused later. |
Dan Gohman | 55d1966 | 2008-07-07 17:46:23 +0000 | [diff] [blame] | 7163 | bool isNew = |
| 7164 | ExpandedNodes.insert(std::make_pair(Op, std::make_pair(Lo, Hi))).second; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7165 | assert(isNew && "Value already expanded?!?"); |
| 7166 | } |
| 7167 | |
| 7168 | /// SplitVectorOp - Given an operand of vector type, break it down into |
| 7169 | /// two smaller values, still of vector type. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7170 | void SelectionDAGLegalize::SplitVectorOp(SDValue Op, SDValue &Lo, |
| 7171 | SDValue &Hi) { |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 7172 | assert(Op.getValueType().isVector() && "Cannot split non-vector type!"); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 7173 | SDNode *Node = Op.getNode(); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 7174 | unsigned NumElements = Op.getValueType().getVectorNumElements(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7175 | assert(NumElements > 1 && "Cannot split a single element vector!"); |
Nate Begeman | 4a365ad | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7176 | |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 7177 | MVT NewEltVT = Op.getValueType().getVectorElementType(); |
Nate Begeman | 4a365ad | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7178 | |
| 7179 | unsigned NewNumElts_Lo = 1 << Log2_32(NumElements-1); |
| 7180 | unsigned NewNumElts_Hi = NumElements - NewNumElts_Lo; |
| 7181 | |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 7182 | MVT NewVT_Lo = MVT::getVectorVT(NewEltVT, NewNumElts_Lo); |
| 7183 | MVT NewVT_Hi = MVT::getVectorVT(NewEltVT, NewNumElts_Hi); |
Nate Begeman | 4a365ad | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7184 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7185 | // See if we already split it. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7186 | std::map<SDValue, std::pair<SDValue, SDValue> >::iterator I |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7187 | = SplitNodes.find(Op); |
| 7188 | if (I != SplitNodes.end()) { |
| 7189 | Lo = I->second.first; |
| 7190 | Hi = I->second.second; |
| 7191 | return; |
| 7192 | } |
| 7193 | |
| 7194 | switch (Node->getOpcode()) { |
| 7195 | default: |
| 7196 | #ifndef NDEBUG |
| 7197 | Node->dump(&DAG); |
| 7198 | #endif |
| 7199 | assert(0 && "Unhandled operation in SplitVectorOp!"); |
Chris Lattner | 3dec33a | 2007-11-19 20:21:32 +0000 | [diff] [blame] | 7200 | case ISD::UNDEF: |
| 7201 | Lo = DAG.getNode(ISD::UNDEF, NewVT_Lo); |
| 7202 | Hi = DAG.getNode(ISD::UNDEF, NewVT_Hi); |
| 7203 | break; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7204 | case ISD::BUILD_PAIR: |
| 7205 | Lo = Node->getOperand(0); |
| 7206 | Hi = Node->getOperand(1); |
| 7207 | break; |
Dan Gohman | b3228dc | 2007-09-28 23:53:40 +0000 | [diff] [blame] | 7208 | case ISD::INSERT_VECTOR_ELT: { |
Nate Begeman | 7c9e4b7 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 7209 | if (ConstantSDNode *Idx = dyn_cast<ConstantSDNode>(Node->getOperand(2))) { |
| 7210 | SplitVectorOp(Node->getOperand(0), Lo, Hi); |
Dan Gohman | faeb4a3 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 7211 | unsigned Index = Idx->getZExtValue(); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7212 | SDValue ScalarOp = Node->getOperand(1); |
Nate Begeman | 7c9e4b7 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 7213 | if (Index < NewNumElts_Lo) |
| 7214 | Lo = DAG.getNode(ISD::INSERT_VECTOR_ELT, NewVT_Lo, Lo, ScalarOp, |
| 7215 | DAG.getIntPtrConstant(Index)); |
| 7216 | else |
| 7217 | Hi = DAG.getNode(ISD::INSERT_VECTOR_ELT, NewVT_Hi, Hi, ScalarOp, |
| 7218 | DAG.getIntPtrConstant(Index - NewNumElts_Lo)); |
| 7219 | break; |
| 7220 | } |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7221 | SDValue Tmp = PerformInsertVectorEltInMemory(Node->getOperand(0), |
Nate Begeman | 7c9e4b7 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 7222 | Node->getOperand(1), |
| 7223 | Node->getOperand(2)); |
| 7224 | SplitVectorOp(Tmp, Lo, Hi); |
Dan Gohman | b3228dc | 2007-09-28 23:53:40 +0000 | [diff] [blame] | 7225 | break; |
| 7226 | } |
Chris Lattner | 587c46d | 2007-11-19 21:16:54 +0000 | [diff] [blame] | 7227 | case ISD::VECTOR_SHUFFLE: { |
| 7228 | // Build the low part. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7229 | SDValue Mask = Node->getOperand(2); |
| 7230 | SmallVector<SDValue, 8> Ops; |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 7231 | MVT PtrVT = TLI.getPointerTy(); |
Chris Lattner | 587c46d | 2007-11-19 21:16:54 +0000 | [diff] [blame] | 7232 | |
| 7233 | // Insert all of the elements from the input that are needed. We use |
| 7234 | // buildvector of extractelement here because the input vectors will have |
| 7235 | // to be legalized, so this makes the code simpler. |
| 7236 | for (unsigned i = 0; i != NewNumElts_Lo; ++i) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7237 | SDValue IdxNode = Mask.getOperand(i); |
Nate Begeman | 8bb3cb3 | 2008-03-14 00:53:31 +0000 | [diff] [blame] | 7238 | if (IdxNode.getOpcode() == ISD::UNDEF) { |
| 7239 | Ops.push_back(DAG.getNode(ISD::UNDEF, NewEltVT)); |
| 7240 | continue; |
| 7241 | } |
Dan Gohman | faeb4a3 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 7242 | unsigned Idx = cast<ConstantSDNode>(IdxNode)->getZExtValue(); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7243 | SDValue InVec = Node->getOperand(0); |
Chris Lattner | 587c46d | 2007-11-19 21:16:54 +0000 | [diff] [blame] | 7244 | if (Idx >= NumElements) { |
| 7245 | InVec = Node->getOperand(1); |
| 7246 | Idx -= NumElements; |
| 7247 | } |
| 7248 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, NewEltVT, InVec, |
| 7249 | DAG.getConstant(Idx, PtrVT))); |
| 7250 | } |
| 7251 | Lo = DAG.getNode(ISD::BUILD_VECTOR, NewVT_Lo, &Ops[0], Ops.size()); |
| 7252 | Ops.clear(); |
| 7253 | |
| 7254 | for (unsigned i = NewNumElts_Lo; i != NumElements; ++i) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7255 | SDValue IdxNode = Mask.getOperand(i); |
Nate Begeman | 8bb3cb3 | 2008-03-14 00:53:31 +0000 | [diff] [blame] | 7256 | if (IdxNode.getOpcode() == ISD::UNDEF) { |
| 7257 | Ops.push_back(DAG.getNode(ISD::UNDEF, NewEltVT)); |
| 7258 | continue; |
| 7259 | } |
Dan Gohman | faeb4a3 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 7260 | unsigned Idx = cast<ConstantSDNode>(IdxNode)->getZExtValue(); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7261 | SDValue InVec = Node->getOperand(0); |
Chris Lattner | 587c46d | 2007-11-19 21:16:54 +0000 | [diff] [blame] | 7262 | if (Idx >= NumElements) { |
| 7263 | InVec = Node->getOperand(1); |
| 7264 | Idx -= NumElements; |
| 7265 | } |
| 7266 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, NewEltVT, InVec, |
| 7267 | DAG.getConstant(Idx, PtrVT))); |
| 7268 | } |
Mon P Wang | 2e89b11 | 2008-07-25 01:30:26 +0000 | [diff] [blame] | 7269 | Hi = DAG.getNode(ISD::BUILD_VECTOR, NewVT_Hi, &Ops[0], Ops.size()); |
Chris Lattner | 587c46d | 2007-11-19 21:16:54 +0000 | [diff] [blame] | 7270 | break; |
| 7271 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7272 | case ISD::BUILD_VECTOR: { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7273 | SmallVector<SDValue, 8> LoOps(Node->op_begin(), |
Nate Begeman | 4a365ad | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7274 | Node->op_begin()+NewNumElts_Lo); |
| 7275 | Lo = DAG.getNode(ISD::BUILD_VECTOR, NewVT_Lo, &LoOps[0], LoOps.size()); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7276 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7277 | SmallVector<SDValue, 8> HiOps(Node->op_begin()+NewNumElts_Lo, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7278 | Node->op_end()); |
Nate Begeman | 4a365ad | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7279 | Hi = DAG.getNode(ISD::BUILD_VECTOR, NewVT_Hi, &HiOps[0], HiOps.size()); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7280 | break; |
| 7281 | } |
| 7282 | case ISD::CONCAT_VECTORS: { |
Nate Begeman | 4a365ad | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7283 | // FIXME: Handle non-power-of-two vectors? |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7284 | unsigned NewNumSubvectors = Node->getNumOperands() / 2; |
| 7285 | if (NewNumSubvectors == 1) { |
| 7286 | Lo = Node->getOperand(0); |
| 7287 | Hi = Node->getOperand(1); |
| 7288 | } else { |
Mon P Wang | bff5d9c | 2008-11-10 04:46:22 +0000 | [diff] [blame] | 7289 | SmallVector<SDValue, 8> LoOps(Node->op_begin(), |
| 7290 | Node->op_begin()+NewNumSubvectors); |
Nate Begeman | 4a365ad | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7291 | Lo = DAG.getNode(ISD::CONCAT_VECTORS, NewVT_Lo, &LoOps[0], LoOps.size()); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7292 | |
Mon P Wang | bff5d9c | 2008-11-10 04:46:22 +0000 | [diff] [blame] | 7293 | SmallVector<SDValue, 8> HiOps(Node->op_begin()+NewNumSubvectors, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7294 | Node->op_end()); |
Nate Begeman | 4a365ad | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7295 | Hi = DAG.getNode(ISD::CONCAT_VECTORS, NewVT_Hi, &HiOps[0], HiOps.size()); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7296 | } |
| 7297 | break; |
| 7298 | } |
Mon P Wang | bff5d9c | 2008-11-10 04:46:22 +0000 | [diff] [blame] | 7299 | case ISD::EXTRACT_SUBVECTOR: { |
| 7300 | SDValue Vec = Op.getOperand(0); |
| 7301 | SDValue Idx = Op.getOperand(1); |
| 7302 | MVT IdxVT = Idx.getValueType(); |
| 7303 | |
| 7304 | Lo = DAG.getNode(ISD::EXTRACT_SUBVECTOR, NewVT_Lo, Vec, Idx); |
| 7305 | ConstantSDNode *CIdx = dyn_cast<ConstantSDNode>(Idx); |
| 7306 | if (CIdx) { |
| 7307 | Hi = DAG.getNode(ISD::EXTRACT_SUBVECTOR, NewVT_Hi, Vec, |
| 7308 | DAG.getConstant(CIdx->getZExtValue() + NewNumElts_Lo, |
| 7309 | IdxVT)); |
| 7310 | } else { |
| 7311 | Idx = DAG.getNode(ISD::ADD, IdxVT, Idx, |
| 7312 | DAG.getConstant(NewNumElts_Lo, IdxVT)); |
| 7313 | Hi = DAG.getNode(ISD::EXTRACT_SUBVECTOR, NewVT_Hi, Vec, Idx); |
| 7314 | } |
| 7315 | break; |
| 7316 | } |
Dan Gohman | d5d4c87 | 2007-10-17 14:48:28 +0000 | [diff] [blame] | 7317 | case ISD::SELECT: { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7318 | SDValue Cond = Node->getOperand(0); |
Dan Gohman | d5d4c87 | 2007-10-17 14:48:28 +0000 | [diff] [blame] | 7319 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7320 | SDValue LL, LH, RL, RH; |
Dan Gohman | d5d4c87 | 2007-10-17 14:48:28 +0000 | [diff] [blame] | 7321 | SplitVectorOp(Node->getOperand(1), LL, LH); |
| 7322 | SplitVectorOp(Node->getOperand(2), RL, RH); |
| 7323 | |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 7324 | if (Cond.getValueType().isVector()) { |
Dan Gohman | d5d4c87 | 2007-10-17 14:48:28 +0000 | [diff] [blame] | 7325 | // Handle a vector merge. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7326 | SDValue CL, CH; |
Dan Gohman | d5d4c87 | 2007-10-17 14:48:28 +0000 | [diff] [blame] | 7327 | SplitVectorOp(Cond, CL, CH); |
Nate Begeman | 4a365ad | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7328 | Lo = DAG.getNode(Node->getOpcode(), NewVT_Lo, CL, LL, RL); |
| 7329 | Hi = DAG.getNode(Node->getOpcode(), NewVT_Hi, CH, LH, RH); |
Dan Gohman | d5d4c87 | 2007-10-17 14:48:28 +0000 | [diff] [blame] | 7330 | } else { |
| 7331 | // Handle a simple select with vector operands. |
Nate Begeman | 4a365ad | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7332 | Lo = DAG.getNode(Node->getOpcode(), NewVT_Lo, Cond, LL, RL); |
| 7333 | Hi = DAG.getNode(Node->getOpcode(), NewVT_Hi, Cond, LH, RH); |
Dan Gohman | d5d4c87 | 2007-10-17 14:48:28 +0000 | [diff] [blame] | 7334 | } |
| 7335 | break; |
| 7336 | } |
Chris Lattner | c747145 | 2008-06-30 02:43:01 +0000 | [diff] [blame] | 7337 | case ISD::SELECT_CC: { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7338 | SDValue CondLHS = Node->getOperand(0); |
| 7339 | SDValue CondRHS = Node->getOperand(1); |
| 7340 | SDValue CondCode = Node->getOperand(4); |
Chris Lattner | c747145 | 2008-06-30 02:43:01 +0000 | [diff] [blame] | 7341 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7342 | SDValue LL, LH, RL, RH; |
Chris Lattner | c747145 | 2008-06-30 02:43:01 +0000 | [diff] [blame] | 7343 | SplitVectorOp(Node->getOperand(2), LL, LH); |
| 7344 | SplitVectorOp(Node->getOperand(3), RL, RH); |
| 7345 | |
| 7346 | // Handle a simple select with vector operands. |
| 7347 | Lo = DAG.getNode(ISD::SELECT_CC, NewVT_Lo, CondLHS, CondRHS, |
| 7348 | LL, RL, CondCode); |
| 7349 | Hi = DAG.getNode(ISD::SELECT_CC, NewVT_Hi, CondLHS, CondRHS, |
| 7350 | LH, RH, CondCode); |
| 7351 | break; |
| 7352 | } |
Nate Begeman | 9a1ce15 | 2008-05-12 19:40:03 +0000 | [diff] [blame] | 7353 | case ISD::VSETCC: { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7354 | SDValue LL, LH, RL, RH; |
Nate Begeman | 9a1ce15 | 2008-05-12 19:40:03 +0000 | [diff] [blame] | 7355 | SplitVectorOp(Node->getOperand(0), LL, LH); |
| 7356 | SplitVectorOp(Node->getOperand(1), RL, RH); |
| 7357 | Lo = DAG.getNode(ISD::VSETCC, NewVT_Lo, LL, RL, Node->getOperand(2)); |
| 7358 | Hi = DAG.getNode(ISD::VSETCC, NewVT_Hi, LH, RH, Node->getOperand(2)); |
| 7359 | break; |
| 7360 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7361 | case ISD::ADD: |
| 7362 | case ISD::SUB: |
| 7363 | case ISD::MUL: |
| 7364 | case ISD::FADD: |
| 7365 | case ISD::FSUB: |
| 7366 | case ISD::FMUL: |
| 7367 | case ISD::SDIV: |
| 7368 | case ISD::UDIV: |
| 7369 | case ISD::FDIV: |
Dan Gohman | 6d05cac | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 7370 | case ISD::FPOW: |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7371 | case ISD::AND: |
| 7372 | case ISD::OR: |
Dan Gohman | 9e1b7ee | 2007-11-19 15:15:03 +0000 | [diff] [blame] | 7373 | case ISD::XOR: |
| 7374 | case ISD::UREM: |
| 7375 | case ISD::SREM: |
| 7376 | case ISD::FREM: { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7377 | SDValue LL, LH, RL, RH; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7378 | SplitVectorOp(Node->getOperand(0), LL, LH); |
| 7379 | SplitVectorOp(Node->getOperand(1), RL, RH); |
| 7380 | |
Nate Begeman | 4a365ad | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7381 | Lo = DAG.getNode(Node->getOpcode(), NewVT_Lo, LL, RL); |
| 7382 | Hi = DAG.getNode(Node->getOpcode(), NewVT_Hi, LH, RH); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7383 | break; |
| 7384 | } |
Dan Gohman | 29c3cef | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 7385 | case ISD::FP_ROUND: |
Dan Gohman | 6d05cac | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 7386 | case ISD::FPOWI: { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7387 | SDValue L, H; |
Dan Gohman | 6d05cac | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 7388 | SplitVectorOp(Node->getOperand(0), L, H); |
| 7389 | |
Nate Begeman | 4a365ad | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7390 | Lo = DAG.getNode(Node->getOpcode(), NewVT_Lo, L, Node->getOperand(1)); |
| 7391 | Hi = DAG.getNode(Node->getOpcode(), NewVT_Hi, H, Node->getOperand(1)); |
Dan Gohman | 6d05cac | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 7392 | break; |
| 7393 | } |
| 7394 | case ISD::CTTZ: |
| 7395 | case ISD::CTLZ: |
| 7396 | case ISD::CTPOP: |
| 7397 | case ISD::FNEG: |
| 7398 | case ISD::FABS: |
| 7399 | case ISD::FSQRT: |
| 7400 | case ISD::FSIN: |
Nate Begeman | 78246ca | 2007-11-17 03:58:34 +0000 | [diff] [blame] | 7401 | case ISD::FCOS: |
Dale Johannesen | 92b3308 | 2008-09-04 00:47:13 +0000 | [diff] [blame] | 7402 | case ISD::FLOG: |
| 7403 | case ISD::FLOG2: |
| 7404 | case ISD::FLOG10: |
| 7405 | case ISD::FEXP: |
| 7406 | case ISD::FEXP2: |
Nate Begeman | 78246ca | 2007-11-17 03:58:34 +0000 | [diff] [blame] | 7407 | case ISD::FP_TO_SINT: |
| 7408 | case ISD::FP_TO_UINT: |
| 7409 | case ISD::SINT_TO_FP: |
Dan Gohman | 29c3cef | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 7410 | case ISD::UINT_TO_FP: |
| 7411 | case ISD::TRUNCATE: |
| 7412 | case ISD::ANY_EXTEND: |
| 7413 | case ISD::SIGN_EXTEND: |
| 7414 | case ISD::ZERO_EXTEND: |
| 7415 | case ISD::FP_EXTEND: { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7416 | SDValue L, H; |
Dan Gohman | 6d05cac | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 7417 | SplitVectorOp(Node->getOperand(0), L, H); |
| 7418 | |
Nate Begeman | 4a365ad | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7419 | Lo = DAG.getNode(Node->getOpcode(), NewVT_Lo, L); |
| 7420 | Hi = DAG.getNode(Node->getOpcode(), NewVT_Hi, H); |
Dan Gohman | 6d05cac | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 7421 | break; |
| 7422 | } |
Mon P Wang | 73d3154 | 2008-11-10 20:54:11 +0000 | [diff] [blame] | 7423 | case ISD::CONVERT_RNDSAT: { |
| 7424 | ISD::CvtCode CvtCode = cast<CvtRndSatSDNode>(Node)->getCvtCode(); |
| 7425 | SDValue L, H; |
| 7426 | SplitVectorOp(Node->getOperand(0), L, H); |
| 7427 | SDValue DTyOpL = DAG.getValueType(NewVT_Lo); |
| 7428 | SDValue DTyOpH = DAG.getValueType(NewVT_Hi); |
| 7429 | SDValue STyOpL = DAG.getValueType(L.getValueType()); |
| 7430 | SDValue STyOpH = DAG.getValueType(H.getValueType()); |
| 7431 | |
| 7432 | SDValue RndOp = Node->getOperand(3); |
| 7433 | SDValue SatOp = Node->getOperand(4); |
| 7434 | |
| 7435 | Lo = DAG.getConvertRndSat(NewVT_Lo, L, DTyOpL, STyOpL, |
| 7436 | RndOp, SatOp, CvtCode); |
| 7437 | Hi = DAG.getConvertRndSat(NewVT_Hi, H, DTyOpH, STyOpH, |
| 7438 | RndOp, SatOp, CvtCode); |
| 7439 | break; |
| 7440 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7441 | case ISD::LOAD: { |
| 7442 | LoadSDNode *LD = cast<LoadSDNode>(Node); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7443 | SDValue Ch = LD->getChain(); |
| 7444 | SDValue Ptr = LD->getBasePtr(); |
Dan Gohman | 29c3cef | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 7445 | ISD::LoadExtType ExtType = LD->getExtensionType(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7446 | const Value *SV = LD->getSrcValue(); |
| 7447 | int SVOffset = LD->getSrcValueOffset(); |
Dan Gohman | 29c3cef | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 7448 | MVT MemoryVT = LD->getMemoryVT(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7449 | unsigned Alignment = LD->getAlignment(); |
| 7450 | bool isVolatile = LD->isVolatile(); |
| 7451 | |
Dan Gohman | 29c3cef | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 7452 | assert(LD->isUnindexed() && "Indexed vector loads are not supported yet!"); |
| 7453 | SDValue Offset = DAG.getNode(ISD::UNDEF, Ptr.getValueType()); |
| 7454 | |
| 7455 | MVT MemNewEltVT = MemoryVT.getVectorElementType(); |
| 7456 | MVT MemNewVT_Lo = MVT::getVectorVT(MemNewEltVT, NewNumElts_Lo); |
| 7457 | MVT MemNewVT_Hi = MVT::getVectorVT(MemNewEltVT, NewNumElts_Hi); |
| 7458 | |
| 7459 | Lo = DAG.getLoad(ISD::UNINDEXED, ExtType, |
| 7460 | NewVT_Lo, Ch, Ptr, Offset, |
| 7461 | SV, SVOffset, MemNewVT_Lo, isVolatile, Alignment); |
| 7462 | unsigned IncrementSize = NewNumElts_Lo * MemNewEltVT.getSizeInBits()/8; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7463 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
Chris Lattner | 5872a36 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 7464 | DAG.getIntPtrConstant(IncrementSize)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7465 | SVOffset += IncrementSize; |
Duncan Sands | a369143 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 7466 | Alignment = MinAlign(Alignment, IncrementSize); |
Dan Gohman | 29c3cef | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 7467 | Hi = DAG.getLoad(ISD::UNINDEXED, ExtType, |
| 7468 | NewVT_Hi, Ch, Ptr, Offset, |
| 7469 | SV, SVOffset, MemNewVT_Hi, isVolatile, Alignment); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7470 | |
| 7471 | // Build a factor node to remember that this load is independent of the |
| 7472 | // other one. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7473 | SDValue TF = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1), |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7474 | Hi.getValue(1)); |
| 7475 | |
| 7476 | // Remember that we legalized the chain. |
| 7477 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(TF)); |
| 7478 | break; |
| 7479 | } |
| 7480 | case ISD::BIT_CONVERT: { |
| 7481 | // We know the result is a vector. The input may be either a vector or a |
| 7482 | // scalar value. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7483 | SDValue InOp = Node->getOperand(0); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 7484 | if (!InOp.getValueType().isVector() || |
| 7485 | InOp.getValueType().getVectorNumElements() == 1) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7486 | // The input is a scalar or single-element vector. |
| 7487 | // Lower to a store/load so that it can be split. |
| 7488 | // FIXME: this could be improved probably. |
Mon P Wang | 36b59ac | 2008-07-15 05:28:34 +0000 | [diff] [blame] | 7489 | unsigned LdAlign = TLI.getTargetData()->getPrefTypeAlignment( |
| 7490 | Op.getValueType().getTypeForMVT()); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7491 | SDValue Ptr = DAG.CreateStackTemporary(InOp.getValueType(), LdAlign); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 7492 | int FI = cast<FrameIndexSDNode>(Ptr.getNode())->getIndex(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7493 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7494 | SDValue St = DAG.getStore(DAG.getEntryNode(), |
Dan Gohman | 12a9c08 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 7495 | InOp, Ptr, |
Dan Gohman | 1fc34bc | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 7496 | PseudoSourceValue::getFixedStack(FI), 0); |
Dan Gohman | 12a9c08 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 7497 | InOp = DAG.getLoad(Op.getValueType(), St, Ptr, |
Dan Gohman | 1fc34bc | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 7498 | PseudoSourceValue::getFixedStack(FI), 0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7499 | } |
| 7500 | // Split the vector and convert each of the pieces now. |
| 7501 | SplitVectorOp(InOp, Lo, Hi); |
Nate Begeman | 4a365ad | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7502 | Lo = DAG.getNode(ISD::BIT_CONVERT, NewVT_Lo, Lo); |
| 7503 | Hi = DAG.getNode(ISD::BIT_CONVERT, NewVT_Hi, Hi); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7504 | break; |
| 7505 | } |
| 7506 | } |
| 7507 | |
| 7508 | // Remember in a map if the values will be reused later. |
| 7509 | bool isNew = |
| 7510 | SplitNodes.insert(std::make_pair(Op, std::make_pair(Lo, Hi))).second; |
| 7511 | assert(isNew && "Value already split?!?"); |
| 7512 | } |
| 7513 | |
| 7514 | |
| 7515 | /// ScalarizeVectorOp - Given an operand of single-element vector type |
| 7516 | /// (e.g. v1f32), convert it into the equivalent operation that returns a |
| 7517 | /// scalar (e.g. f32) value. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7518 | SDValue SelectionDAGLegalize::ScalarizeVectorOp(SDValue Op) { |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 7519 | assert(Op.getValueType().isVector() && "Bad ScalarizeVectorOp invocation!"); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 7520 | SDNode *Node = Op.getNode(); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 7521 | MVT NewVT = Op.getValueType().getVectorElementType(); |
| 7522 | assert(Op.getValueType().getVectorNumElements() == 1); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7523 | |
| 7524 | // See if we already scalarized it. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7525 | std::map<SDValue, SDValue>::iterator I = ScalarizedNodes.find(Op); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7526 | if (I != ScalarizedNodes.end()) return I->second; |
| 7527 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7528 | SDValue Result; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7529 | switch (Node->getOpcode()) { |
| 7530 | default: |
| 7531 | #ifndef NDEBUG |
| 7532 | Node->dump(&DAG); cerr << "\n"; |
| 7533 | #endif |
| 7534 | assert(0 && "Unknown vector operation in ScalarizeVectorOp!"); |
| 7535 | case ISD::ADD: |
| 7536 | case ISD::FADD: |
| 7537 | case ISD::SUB: |
| 7538 | case ISD::FSUB: |
| 7539 | case ISD::MUL: |
| 7540 | case ISD::FMUL: |
| 7541 | case ISD::SDIV: |
| 7542 | case ISD::UDIV: |
| 7543 | case ISD::FDIV: |
| 7544 | case ISD::SREM: |
| 7545 | case ISD::UREM: |
| 7546 | case ISD::FREM: |
Dan Gohman | 6d05cac | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 7547 | case ISD::FPOW: |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7548 | case ISD::AND: |
| 7549 | case ISD::OR: |
| 7550 | case ISD::XOR: |
| 7551 | Result = DAG.getNode(Node->getOpcode(), |
| 7552 | NewVT, |
| 7553 | ScalarizeVectorOp(Node->getOperand(0)), |
| 7554 | ScalarizeVectorOp(Node->getOperand(1))); |
| 7555 | break; |
| 7556 | case ISD::FNEG: |
| 7557 | case ISD::FABS: |
| 7558 | case ISD::FSQRT: |
| 7559 | case ISD::FSIN: |
| 7560 | case ISD::FCOS: |
Dale Johannesen | 92b3308 | 2008-09-04 00:47:13 +0000 | [diff] [blame] | 7561 | case ISD::FLOG: |
| 7562 | case ISD::FLOG2: |
| 7563 | case ISD::FLOG10: |
| 7564 | case ISD::FEXP: |
| 7565 | case ISD::FEXP2: |
Dan Gohman | 29c3cef | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 7566 | case ISD::FP_TO_SINT: |
| 7567 | case ISD::FP_TO_UINT: |
| 7568 | case ISD::SINT_TO_FP: |
| 7569 | case ISD::UINT_TO_FP: |
| 7570 | case ISD::SIGN_EXTEND: |
| 7571 | case ISD::ZERO_EXTEND: |
| 7572 | case ISD::ANY_EXTEND: |
| 7573 | case ISD::TRUNCATE: |
| 7574 | case ISD::FP_EXTEND: |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7575 | Result = DAG.getNode(Node->getOpcode(), |
| 7576 | NewVT, |
| 7577 | ScalarizeVectorOp(Node->getOperand(0))); |
| 7578 | break; |
Mon P Wang | 73d3154 | 2008-11-10 20:54:11 +0000 | [diff] [blame] | 7579 | case ISD::CONVERT_RNDSAT: { |
| 7580 | SDValue Op0 = ScalarizeVectorOp(Node->getOperand(0)); |
| 7581 | Result = DAG.getConvertRndSat(NewVT, Op0, |
| 7582 | DAG.getValueType(NewVT), |
| 7583 | DAG.getValueType(Op0.getValueType()), |
| 7584 | Node->getOperand(3), |
| 7585 | Node->getOperand(4), |
| 7586 | cast<CvtRndSatSDNode>(Node)->getCvtCode()); |
| 7587 | break; |
| 7588 | } |
Dan Gohman | ae4c2f8 | 2007-10-12 14:13:46 +0000 | [diff] [blame] | 7589 | case ISD::FPOWI: |
Dan Gohman | 29c3cef | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 7590 | case ISD::FP_ROUND: |
Dan Gohman | ae4c2f8 | 2007-10-12 14:13:46 +0000 | [diff] [blame] | 7591 | Result = DAG.getNode(Node->getOpcode(), |
| 7592 | NewVT, |
| 7593 | ScalarizeVectorOp(Node->getOperand(0)), |
| 7594 | Node->getOperand(1)); |
| 7595 | break; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7596 | case ISD::LOAD: { |
| 7597 | LoadSDNode *LD = cast<LoadSDNode>(Node); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7598 | SDValue Ch = LegalizeOp(LD->getChain()); // Legalize the chain. |
| 7599 | SDValue Ptr = LegalizeOp(LD->getBasePtr()); // Legalize the pointer. |
Dan Gohman | 29c3cef | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 7600 | ISD::LoadExtType ExtType = LD->getExtensionType(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7601 | const Value *SV = LD->getSrcValue(); |
| 7602 | int SVOffset = LD->getSrcValueOffset(); |
Dan Gohman | 29c3cef | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 7603 | MVT MemoryVT = LD->getMemoryVT(); |
| 7604 | unsigned Alignment = LD->getAlignment(); |
| 7605 | bool isVolatile = LD->isVolatile(); |
| 7606 | |
| 7607 | assert(LD->isUnindexed() && "Indexed vector loads are not supported yet!"); |
| 7608 | SDValue Offset = DAG.getNode(ISD::UNDEF, Ptr.getValueType()); |
| 7609 | |
| 7610 | Result = DAG.getLoad(ISD::UNINDEXED, ExtType, |
| 7611 | NewVT, Ch, Ptr, Offset, SV, SVOffset, |
| 7612 | MemoryVT.getVectorElementType(), |
| 7613 | isVolatile, Alignment); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7614 | |
| 7615 | // Remember that we legalized the chain. |
| 7616 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1))); |
| 7617 | break; |
| 7618 | } |
| 7619 | case ISD::BUILD_VECTOR: |
| 7620 | Result = Node->getOperand(0); |
| 7621 | break; |
| 7622 | case ISD::INSERT_VECTOR_ELT: |
| 7623 | // Returning the inserted scalar element. |
| 7624 | Result = Node->getOperand(1); |
| 7625 | break; |
| 7626 | case ISD::CONCAT_VECTORS: |
| 7627 | assert(Node->getOperand(0).getValueType() == NewVT && |
| 7628 | "Concat of non-legal vectors not yet supported!"); |
| 7629 | Result = Node->getOperand(0); |
| 7630 | break; |
| 7631 | case ISD::VECTOR_SHUFFLE: { |
| 7632 | // Figure out if the scalar is the LHS or RHS and return it. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7633 | SDValue EltNum = Node->getOperand(2).getOperand(0); |
Dan Gohman | faeb4a3 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 7634 | if (cast<ConstantSDNode>(EltNum)->getZExtValue()) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7635 | Result = ScalarizeVectorOp(Node->getOperand(1)); |
| 7636 | else |
| 7637 | Result = ScalarizeVectorOp(Node->getOperand(0)); |
| 7638 | break; |
| 7639 | } |
| 7640 | case ISD::EXTRACT_SUBVECTOR: |
Mon P Wang | 927daf5 | 2008-11-06 22:52:21 +0000 | [diff] [blame] | 7641 | Result = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, NewVT, Node->getOperand(0), |
Mon P Wang | bff5d9c | 2008-11-10 04:46:22 +0000 | [diff] [blame] | 7642 | Node->getOperand(1)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7643 | break; |
Evan Cheng | 2cc16e7 | 2008-05-16 17:19:05 +0000 | [diff] [blame] | 7644 | case ISD::BIT_CONVERT: { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7645 | SDValue Op0 = Op.getOperand(0); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 7646 | if (Op0.getValueType().getVectorNumElements() == 1) |
Evan Cheng | 2cc16e7 | 2008-05-16 17:19:05 +0000 | [diff] [blame] | 7647 | Op0 = ScalarizeVectorOp(Op0); |
| 7648 | Result = DAG.getNode(ISD::BIT_CONVERT, NewVT, Op0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7649 | break; |
Evan Cheng | 2cc16e7 | 2008-05-16 17:19:05 +0000 | [diff] [blame] | 7650 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7651 | case ISD::SELECT: |
| 7652 | Result = DAG.getNode(ISD::SELECT, NewVT, Op.getOperand(0), |
| 7653 | ScalarizeVectorOp(Op.getOperand(1)), |
| 7654 | ScalarizeVectorOp(Op.getOperand(2))); |
| 7655 | break; |
Chris Lattner | c747145 | 2008-06-30 02:43:01 +0000 | [diff] [blame] | 7656 | case ISD::SELECT_CC: |
| 7657 | Result = DAG.getNode(ISD::SELECT_CC, NewVT, Node->getOperand(0), |
| 7658 | Node->getOperand(1), |
| 7659 | ScalarizeVectorOp(Op.getOperand(2)), |
| 7660 | ScalarizeVectorOp(Op.getOperand(3)), |
| 7661 | Node->getOperand(4)); |
| 7662 | break; |
Nate Begeman | 78ca4f9 | 2008-05-12 23:09:43 +0000 | [diff] [blame] | 7663 | case ISD::VSETCC: { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7664 | SDValue Op0 = ScalarizeVectorOp(Op.getOperand(0)); |
| 7665 | SDValue Op1 = ScalarizeVectorOp(Op.getOperand(1)); |
Nate Begeman | 78ca4f9 | 2008-05-12 23:09:43 +0000 | [diff] [blame] | 7666 | Result = DAG.getNode(ISD::SETCC, TLI.getSetCCResultType(Op0), Op0, Op1, |
| 7667 | Op.getOperand(2)); |
| 7668 | Result = DAG.getNode(ISD::SELECT, NewVT, Result, |
| 7669 | DAG.getConstant(-1ULL, NewVT), |
| 7670 | DAG.getConstant(0ULL, NewVT)); |
| 7671 | break; |
| 7672 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7673 | } |
| 7674 | |
| 7675 | if (TLI.isTypeLegal(NewVT)) |
| 7676 | Result = LegalizeOp(Result); |
| 7677 | bool isNew = ScalarizedNodes.insert(std::make_pair(Op, Result)).second; |
| 7678 | assert(isNew && "Value already scalarized?"); |
| 7679 | return Result; |
| 7680 | } |
| 7681 | |
| 7682 | |
Mon P Wang | 1448aad | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 7683 | SDValue SelectionDAGLegalize::WidenVectorOp(SDValue Op, MVT WidenVT) { |
| 7684 | std::map<SDValue, SDValue>::iterator I = WidenNodes.find(Op); |
| 7685 | if (I != WidenNodes.end()) return I->second; |
| 7686 | |
| 7687 | MVT VT = Op.getValueType(); |
| 7688 | assert(VT.isVector() && "Cannot widen non-vector type!"); |
| 7689 | |
| 7690 | SDValue Result; |
| 7691 | SDNode *Node = Op.getNode(); |
| 7692 | MVT EVT = VT.getVectorElementType(); |
| 7693 | |
| 7694 | unsigned NumElts = VT.getVectorNumElements(); |
| 7695 | unsigned NewNumElts = WidenVT.getVectorNumElements(); |
| 7696 | assert(NewNumElts > NumElts && "Cannot widen to smaller type!"); |
| 7697 | assert(NewNumElts < 17); |
| 7698 | |
| 7699 | // When widen is called, it is assumed that it is more efficient to use a |
| 7700 | // wide type. The default action is to widen to operation to a wider legal |
| 7701 | // vector type and then do the operation if it is legal by calling LegalizeOp |
| 7702 | // again. If there is no vector equivalent, we will unroll the operation, do |
| 7703 | // it, and rebuild the vector. If most of the operations are vectorizible to |
| 7704 | // the legal type, the resulting code will be more efficient. If this is not |
| 7705 | // the case, the resulting code will preform badly as we end up generating |
| 7706 | // code to pack/unpack the results. It is the function that calls widen |
Mon P Wang | a5a239f | 2008-11-06 05:31:54 +0000 | [diff] [blame] | 7707 | // that is responsible for seeing this doesn't happen. |
Mon P Wang | 1448aad | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 7708 | switch (Node->getOpcode()) { |
| 7709 | default: |
| 7710 | #ifndef NDEBUG |
| 7711 | Node->dump(&DAG); |
| 7712 | #endif |
| 7713 | assert(0 && "Unexpected operation in WidenVectorOp!"); |
| 7714 | break; |
| 7715 | case ISD::CopyFromReg: |
Mon P Wang | 257e1c7 | 2008-11-15 06:05:52 +0000 | [diff] [blame] | 7716 | assert(0 && "CopyFromReg doesn't need widening!"); |
Mon P Wang | 1448aad | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 7717 | case ISD::Constant: |
| 7718 | case ISD::ConstantFP: |
| 7719 | // To build a vector of these elements, clients should call BuildVector |
| 7720 | // and with each element instead of creating a node with a vector type |
| 7721 | assert(0 && "Unexpected operation in WidenVectorOp!"); |
| 7722 | case ISD::VAARG: |
| 7723 | // Variable Arguments with vector types doesn't make any sense to me |
| 7724 | assert(0 && "Unexpected operation in WidenVectorOp!"); |
| 7725 | break; |
Mon P Wang | 257e1c7 | 2008-11-15 06:05:52 +0000 | [diff] [blame] | 7726 | case ISD::UNDEF: |
| 7727 | Result = DAG.getNode(ISD::UNDEF, WidenVT); |
| 7728 | break; |
Mon P Wang | 1448aad | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 7729 | case ISD::BUILD_VECTOR: { |
| 7730 | // Build a vector with undefined for the new nodes |
| 7731 | SDValueVector NewOps(Node->op_begin(), Node->op_end()); |
| 7732 | for (unsigned i = NumElts; i < NewNumElts; ++i) { |
| 7733 | NewOps.push_back(DAG.getNode(ISD::UNDEF,EVT)); |
| 7734 | } |
| 7735 | Result = DAG.getNode(ISD::BUILD_VECTOR, WidenVT, &NewOps[0], NewOps.size()); |
| 7736 | break; |
| 7737 | } |
| 7738 | case ISD::INSERT_VECTOR_ELT: { |
| 7739 | SDValue Tmp1 = WidenVectorOp(Node->getOperand(0), WidenVT); |
| 7740 | Result = DAG.getNode(ISD::INSERT_VECTOR_ELT, WidenVT, Tmp1, |
| 7741 | Node->getOperand(1), Node->getOperand(2)); |
| 7742 | break; |
| 7743 | } |
| 7744 | case ISD::VECTOR_SHUFFLE: { |
| 7745 | SDValue Tmp1 = WidenVectorOp(Node->getOperand(0), WidenVT); |
| 7746 | SDValue Tmp2 = WidenVectorOp(Node->getOperand(1), WidenVT); |
| 7747 | // VECTOR_SHUFFLE 3rd operand must be a constant build vector that is |
| 7748 | // used as permutation array. We build the vector here instead of widening |
| 7749 | // because we don't want to legalize and have it turned to something else. |
| 7750 | SDValue PermOp = Node->getOperand(2); |
| 7751 | SDValueVector NewOps; |
| 7752 | MVT PVT = PermOp.getValueType().getVectorElementType(); |
| 7753 | for (unsigned i = 0; i < NumElts; ++i) { |
| 7754 | if (PermOp.getOperand(i).getOpcode() == ISD::UNDEF) { |
| 7755 | NewOps.push_back(PermOp.getOperand(i)); |
| 7756 | } else { |
| 7757 | unsigned Idx = |
| 7758 | cast<ConstantSDNode>(PermOp.getOperand(i))->getZExtValue(); |
| 7759 | if (Idx < NumElts) { |
| 7760 | NewOps.push_back(PermOp.getOperand(i)); |
| 7761 | } |
| 7762 | else { |
| 7763 | NewOps.push_back(DAG.getConstant(Idx + NewNumElts - NumElts, |
| 7764 | PermOp.getOperand(i).getValueType())); |
| 7765 | } |
| 7766 | } |
| 7767 | } |
| 7768 | for (unsigned i = NumElts; i < NewNumElts; ++i) { |
| 7769 | NewOps.push_back(DAG.getNode(ISD::UNDEF,PVT)); |
| 7770 | } |
| 7771 | |
| 7772 | SDValue Tmp3 = DAG.getNode(ISD::BUILD_VECTOR, |
| 7773 | MVT::getVectorVT(PVT, NewOps.size()), |
| 7774 | &NewOps[0], NewOps.size()); |
| 7775 | |
| 7776 | Result = DAG.getNode(ISD::VECTOR_SHUFFLE, WidenVT, Tmp1, Tmp2, Tmp3); |
| 7777 | break; |
| 7778 | } |
| 7779 | case ISD::LOAD: { |
| 7780 | // If the load widen returns true, we can use a single load for the |
| 7781 | // vector. Otherwise, it is returning a token factor for multiple |
| 7782 | // loads. |
| 7783 | SDValue TFOp; |
| 7784 | if (LoadWidenVectorOp(Result, TFOp, Op, WidenVT)) |
| 7785 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(TFOp.getValue(1))); |
| 7786 | else |
| 7787 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(TFOp.getValue(0))); |
| 7788 | break; |
| 7789 | } |
| 7790 | |
| 7791 | case ISD::BIT_CONVERT: { |
| 7792 | SDValue Tmp1 = Node->getOperand(0); |
| 7793 | // Converts between two different types so we need to determine |
| 7794 | // the correct widen type for the input operand. |
| 7795 | MVT TVT = Tmp1.getValueType(); |
| 7796 | assert(TVT.isVector() && "can not widen non vector type"); |
| 7797 | MVT TEVT = TVT.getVectorElementType(); |
| 7798 | assert(WidenVT.getSizeInBits() % EVT.getSizeInBits() == 0 && |
| 7799 | "can not widen bit bit convert that are not multiple of element type"); |
| 7800 | MVT TWidenVT = MVT::getVectorVT(TEVT, |
| 7801 | WidenVT.getSizeInBits()/EVT.getSizeInBits()); |
| 7802 | Tmp1 = WidenVectorOp(Tmp1, TWidenVT); |
| 7803 | assert(Tmp1.getValueType().getSizeInBits() == WidenVT.getSizeInBits()); |
| 7804 | Result = DAG.getNode(Node->getOpcode(), WidenVT, Tmp1); |
| 7805 | |
| 7806 | TargetLowering::LegalizeAction action = |
| 7807 | TLI.getOperationAction(Node->getOpcode(), WidenVT); |
| 7808 | switch (action) { |
| 7809 | default: assert(0 && "action not supported"); |
| 7810 | case TargetLowering::Legal: |
| 7811 | break; |
| 7812 | case TargetLowering::Promote: |
| 7813 | // We defer the promotion to when we legalize the op |
| 7814 | break; |
| 7815 | case TargetLowering::Expand: |
| 7816 | // Expand the operation into a bunch of nasty scalar code. |
| 7817 | Result = LegalizeOp(UnrollVectorOp(Result)); |
| 7818 | break; |
| 7819 | } |
| 7820 | break; |
| 7821 | } |
| 7822 | |
| 7823 | case ISD::SINT_TO_FP: |
| 7824 | case ISD::UINT_TO_FP: |
| 7825 | case ISD::FP_TO_SINT: |
| 7826 | case ISD::FP_TO_UINT: { |
| 7827 | SDValue Tmp1 = Node->getOperand(0); |
| 7828 | // Converts between two different types so we need to determine |
| 7829 | // the correct widen type for the input operand. |
| 7830 | MVT TVT = Tmp1.getValueType(); |
| 7831 | assert(TVT.isVector() && "can not widen non vector type"); |
| 7832 | MVT TEVT = TVT.getVectorElementType(); |
| 7833 | MVT TWidenVT = MVT::getVectorVT(TEVT, NewNumElts); |
| 7834 | Tmp1 = WidenVectorOp(Tmp1, TWidenVT); |
| 7835 | assert(Tmp1.getValueType().getVectorNumElements() == NewNumElts); |
| 7836 | Result = DAG.getNode(Node->getOpcode(), WidenVT, Tmp1); |
| 7837 | |
| 7838 | TargetLowering::LegalizeAction action = |
| 7839 | TLI.getOperationAction(Node->getOpcode(), WidenVT); |
| 7840 | switch (action) { |
| 7841 | default: assert(0 && "action not supported"); |
| 7842 | case TargetLowering::Legal: |
| 7843 | break; |
| 7844 | case TargetLowering::Promote: |
| 7845 | // We defer the promotion to when we legalize the op |
| 7846 | break; |
| 7847 | case TargetLowering::Expand: |
| 7848 | // Expand the operation into a bunch of nasty scalar code. |
| 7849 | Result = LegalizeOp(UnrollVectorOp(Result)); |
| 7850 | break; |
| 7851 | } |
| 7852 | break; |
| 7853 | } |
| 7854 | |
| 7855 | case ISD::FP_EXTEND: |
| 7856 | assert(0 && "Case not implemented. Dynamically dead with 2 FP types!"); |
| 7857 | case ISD::TRUNCATE: |
| 7858 | case ISD::SIGN_EXTEND: |
| 7859 | case ISD::ZERO_EXTEND: |
| 7860 | case ISD::ANY_EXTEND: |
| 7861 | case ISD::FP_ROUND: |
| 7862 | case ISD::SIGN_EXTEND_INREG: |
| 7863 | case ISD::FABS: |
| 7864 | case ISD::FNEG: |
| 7865 | case ISD::FSQRT: |
| 7866 | case ISD::FSIN: |
Mon P Wang | 257e1c7 | 2008-11-15 06:05:52 +0000 | [diff] [blame] | 7867 | case ISD::FCOS: |
| 7868 | case ISD::CTPOP: |
| 7869 | case ISD::CTTZ: |
| 7870 | case ISD::CTLZ: { |
Mon P Wang | 1448aad | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 7871 | // Unary op widening |
| 7872 | SDValue Tmp1; |
| 7873 | TargetLowering::LegalizeAction action = |
| 7874 | TLI.getOperationAction(Node->getOpcode(), WidenVT); |
| 7875 | |
| 7876 | Tmp1 = WidenVectorOp(Node->getOperand(0), WidenVT); |
| 7877 | assert(Tmp1.getValueType() == WidenVT); |
| 7878 | Result = DAG.getNode(Node->getOpcode(), WidenVT, Tmp1); |
| 7879 | switch (action) { |
| 7880 | default: assert(0 && "action not supported"); |
| 7881 | case TargetLowering::Legal: |
| 7882 | break; |
| 7883 | case TargetLowering::Promote: |
| 7884 | // We defer the promotion to when we legalize the op |
| 7885 | break; |
| 7886 | case TargetLowering::Expand: |
| 7887 | // Expand the operation into a bunch of nasty scalar code. |
| 7888 | Result = LegalizeOp(UnrollVectorOp(Result)); |
| 7889 | break; |
| 7890 | } |
| 7891 | break; |
| 7892 | } |
Mon P Wang | 73d3154 | 2008-11-10 20:54:11 +0000 | [diff] [blame] | 7893 | case ISD::CONVERT_RNDSAT: { |
| 7894 | SDValue RndOp = Node->getOperand(3); |
| 7895 | SDValue SatOp = Node->getOperand(4); |
| 7896 | |
| 7897 | TargetLowering::LegalizeAction action = |
| 7898 | TLI.getOperationAction(Node->getOpcode(), WidenVT); |
| 7899 | |
| 7900 | SDValue SrcOp = Node->getOperand(0); |
| 7901 | |
| 7902 | // Converts between two different types so we need to determine |
| 7903 | // the correct widen type for the input operand. |
| 7904 | MVT SVT = SrcOp.getValueType(); |
| 7905 | assert(SVT.isVector() && "can not widen non vector type"); |
| 7906 | MVT SEVT = SVT.getVectorElementType(); |
| 7907 | MVT SWidenVT = MVT::getVectorVT(SEVT, NewNumElts); |
| 7908 | |
| 7909 | SrcOp = WidenVectorOp(SrcOp, SWidenVT); |
| 7910 | assert(SrcOp.getValueType() == WidenVT); |
| 7911 | SDValue DTyOp = DAG.getValueType(WidenVT); |
| 7912 | SDValue STyOp = DAG.getValueType(SrcOp.getValueType()); |
| 7913 | ISD::CvtCode CvtCode = cast<CvtRndSatSDNode>(Node)->getCvtCode(); |
| 7914 | |
| 7915 | Result = DAG.getConvertRndSat(WidenVT, SrcOp, DTyOp, STyOp, |
| 7916 | RndOp, SatOp, CvtCode); |
| 7917 | switch (action) { |
| 7918 | default: assert(0 && "action not supported"); |
| 7919 | case TargetLowering::Legal: |
| 7920 | break; |
| 7921 | case TargetLowering::Promote: |
| 7922 | // We defer the promotion to when we legalize the op |
| 7923 | break; |
| 7924 | case TargetLowering::Expand: |
| 7925 | // Expand the operation into a bunch of nasty scalar code. |
| 7926 | Result = LegalizeOp(UnrollVectorOp(Result)); |
| 7927 | break; |
| 7928 | } |
| 7929 | break; |
| 7930 | } |
Mon P Wang | 1448aad | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 7931 | case ISD::FPOW: |
| 7932 | case ISD::FPOWI: |
| 7933 | case ISD::ADD: |
| 7934 | case ISD::SUB: |
| 7935 | case ISD::MUL: |
| 7936 | case ISD::MULHS: |
| 7937 | case ISD::MULHU: |
| 7938 | case ISD::AND: |
| 7939 | case ISD::OR: |
| 7940 | case ISD::XOR: |
| 7941 | case ISD::FADD: |
| 7942 | case ISD::FSUB: |
| 7943 | case ISD::FMUL: |
| 7944 | case ISD::SDIV: |
| 7945 | case ISD::SREM: |
| 7946 | case ISD::FDIV: |
| 7947 | case ISD::FREM: |
| 7948 | case ISD::FCOPYSIGN: |
| 7949 | case ISD::UDIV: |
| 7950 | case ISD::UREM: |
| 7951 | case ISD::BSWAP: { |
| 7952 | // Binary op widening |
| 7953 | TargetLowering::LegalizeAction action = |
| 7954 | TLI.getOperationAction(Node->getOpcode(), WidenVT); |
| 7955 | |
| 7956 | SDValue Tmp1 = WidenVectorOp(Node->getOperand(0), WidenVT); |
| 7957 | SDValue Tmp2 = WidenVectorOp(Node->getOperand(1), WidenVT); |
| 7958 | assert(Tmp1.getValueType() == WidenVT && Tmp2.getValueType() == WidenVT); |
| 7959 | Result = DAG.getNode(Node->getOpcode(), WidenVT, Tmp1, Tmp2); |
| 7960 | switch (action) { |
| 7961 | default: assert(0 && "action not supported"); |
| 7962 | case TargetLowering::Legal: |
| 7963 | break; |
| 7964 | case TargetLowering::Promote: |
| 7965 | // We defer the promotion to when we legalize the op |
| 7966 | break; |
| 7967 | case TargetLowering::Expand: |
| 7968 | // Expand the operation into a bunch of nasty scalar code by first |
| 7969 | // Widening to the right type and then unroll the beast. |
| 7970 | Result = LegalizeOp(UnrollVectorOp(Result)); |
| 7971 | break; |
| 7972 | } |
| 7973 | break; |
| 7974 | } |
| 7975 | |
| 7976 | case ISD::SHL: |
| 7977 | case ISD::SRA: |
| 7978 | case ISD::SRL: { |
| 7979 | // Binary op with one non vector operand |
| 7980 | TargetLowering::LegalizeAction action = |
| 7981 | TLI.getOperationAction(Node->getOpcode(), WidenVT); |
| 7982 | |
| 7983 | SDValue Tmp1 = WidenVectorOp(Node->getOperand(0), WidenVT); |
| 7984 | assert(Tmp1.getValueType() == WidenVT); |
| 7985 | Result = DAG.getNode(Node->getOpcode(), WidenVT, Tmp1, Node->getOperand(1)); |
| 7986 | switch (action) { |
| 7987 | default: assert(0 && "action not supported"); |
| 7988 | case TargetLowering::Legal: |
| 7989 | break; |
| 7990 | case TargetLowering::Promote: |
| 7991 | // We defer the promotion to when we legalize the op |
| 7992 | break; |
| 7993 | case TargetLowering::Expand: |
| 7994 | // Expand the operation into a bunch of nasty scalar code. |
| 7995 | Result = LegalizeOp(UnrollVectorOp(Result)); |
| 7996 | break; |
| 7997 | } |
| 7998 | break; |
| 7999 | } |
| 8000 | case ISD::EXTRACT_VECTOR_ELT: { |
| 8001 | SDValue Tmp1 = WidenVectorOp(Node->getOperand(0), WidenVT); |
| 8002 | assert(Tmp1.getValueType() == WidenVT); |
| 8003 | Result = DAG.getNode(Node->getOpcode(), EVT, Tmp1, Node->getOperand(1)); |
| 8004 | break; |
| 8005 | } |
| 8006 | case ISD::CONCAT_VECTORS: { |
| 8007 | // We concurrently support only widen on a multiple of the incoming vector. |
| 8008 | // We could widen on a multiple of the incoming operand if necessary. |
| 8009 | unsigned NumConcat = NewNumElts / NumElts; |
| 8010 | assert(NewNumElts % NumElts == 0 && "Can widen only a multiple of vector"); |
| 8011 | std::vector<SDValue> UnOps(NumElts, DAG.getNode(ISD::UNDEF, |
| 8012 | VT.getVectorElementType())); |
| 8013 | SDValue UndefVal = DAG.getNode(ISD::BUILD_VECTOR, VT, |
| 8014 | &UnOps[0], UnOps.size()); |
| 8015 | SmallVector<SDValue, 8> MOps; |
| 8016 | MOps.push_back(Op); |
| 8017 | for (unsigned i = 1; i != NumConcat; ++i) { |
| 8018 | MOps.push_back(UndefVal); |
| 8019 | } |
| 8020 | Result = LegalizeOp(DAG.getNode(ISD::CONCAT_VECTORS, WidenVT, |
| 8021 | &MOps[0], MOps.size())); |
| 8022 | break; |
| 8023 | } |
| 8024 | case ISD::EXTRACT_SUBVECTOR: { |
Mon P Wang | 257e1c7 | 2008-11-15 06:05:52 +0000 | [diff] [blame] | 8025 | SDValue Tmp1 = Node->getOperand(0); |
| 8026 | SDValue Idx = Node->getOperand(1); |
| 8027 | ConstantSDNode *CIdx = dyn_cast<ConstantSDNode>(Idx); |
| 8028 | if (CIdx && CIdx->getZExtValue() == 0) { |
| 8029 | // Since we are access the start of the vector, the incoming |
| 8030 | // vector type might be the proper. |
| 8031 | MVT Tmp1VT = Tmp1.getValueType(); |
| 8032 | if (Tmp1VT == WidenVT) |
| 8033 | return Tmp1; |
| 8034 | else { |
| 8035 | unsigned Tmp1VTNumElts = Tmp1VT.getVectorNumElements(); |
| 8036 | if (Tmp1VTNumElts < NewNumElts) |
| 8037 | Result = WidenVectorOp(Tmp1, WidenVT); |
| 8038 | else |
| 8039 | Result = DAG.getNode(ISD::EXTRACT_SUBVECTOR, WidenVT, Tmp1, Idx); |
| 8040 | } |
| 8041 | } else if (NewNumElts % NumElts == 0) { |
| 8042 | // Widen the extracted subvector. |
| 8043 | unsigned NumConcat = NewNumElts / NumElts; |
| 8044 | SDValue UndefVal = DAG.getNode(ISD::UNDEF, VT); |
| 8045 | SmallVector<SDValue, 8> MOps; |
| 8046 | MOps.push_back(Op); |
| 8047 | for (unsigned i = 1; i != NumConcat; ++i) { |
| 8048 | MOps.push_back(UndefVal); |
| 8049 | } |
| 8050 | Result = LegalizeOp(DAG.getNode(ISD::CONCAT_VECTORS, WidenVT, |
| 8051 | &MOps[0], MOps.size())); |
| 8052 | } else { |
| 8053 | assert(0 && "can not widen extract subvector"); |
| 8054 | // This could be implemented using insert and build vector but I would |
| 8055 | // like to see when this happens. |
| 8056 | } |
Mon P Wang | 1448aad | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8057 | break; |
| 8058 | } |
| 8059 | |
| 8060 | case ISD::SELECT: { |
| 8061 | TargetLowering::LegalizeAction action = |
| 8062 | TLI.getOperationAction(Node->getOpcode(), WidenVT); |
| 8063 | |
| 8064 | // Determine new condition widen type and widen |
| 8065 | SDValue Cond1 = Node->getOperand(0); |
| 8066 | MVT CondVT = Cond1.getValueType(); |
| 8067 | assert(CondVT.isVector() && "can not widen non vector type"); |
| 8068 | MVT CondEVT = CondVT.getVectorElementType(); |
| 8069 | MVT CondWidenVT = MVT::getVectorVT(CondEVT, NewNumElts); |
| 8070 | Cond1 = WidenVectorOp(Cond1, CondWidenVT); |
| 8071 | assert(Cond1.getValueType() == CondWidenVT && "Condition not widen"); |
| 8072 | |
| 8073 | SDValue Tmp1 = WidenVectorOp(Node->getOperand(1), WidenVT); |
| 8074 | SDValue Tmp2 = WidenVectorOp(Node->getOperand(2), WidenVT); |
| 8075 | assert(Tmp1.getValueType() == WidenVT && Tmp2.getValueType() == WidenVT); |
| 8076 | Result = DAG.getNode(Node->getOpcode(), WidenVT, Cond1, Tmp1, Tmp2); |
| 8077 | switch (action) { |
| 8078 | default: assert(0 && "action not supported"); |
| 8079 | case TargetLowering::Legal: |
| 8080 | break; |
| 8081 | case TargetLowering::Promote: |
| 8082 | // We defer the promotion to when we legalize the op |
| 8083 | break; |
| 8084 | case TargetLowering::Expand: |
| 8085 | // Expand the operation into a bunch of nasty scalar code by first |
| 8086 | // Widening to the right type and then unroll the beast. |
| 8087 | Result = LegalizeOp(UnrollVectorOp(Result)); |
| 8088 | break; |
| 8089 | } |
| 8090 | break; |
| 8091 | } |
| 8092 | |
| 8093 | case ISD::SELECT_CC: { |
| 8094 | TargetLowering::LegalizeAction action = |
| 8095 | TLI.getOperationAction(Node->getOpcode(), WidenVT); |
| 8096 | |
| 8097 | // Determine new condition widen type and widen |
| 8098 | SDValue Cond1 = Node->getOperand(0); |
| 8099 | SDValue Cond2 = Node->getOperand(1); |
| 8100 | MVT CondVT = Cond1.getValueType(); |
| 8101 | assert(CondVT.isVector() && "can not widen non vector type"); |
| 8102 | assert(CondVT == Cond2.getValueType() && "mismatch lhs/rhs"); |
| 8103 | MVT CondEVT = CondVT.getVectorElementType(); |
| 8104 | MVT CondWidenVT = MVT::getVectorVT(CondEVT, NewNumElts); |
| 8105 | Cond1 = WidenVectorOp(Cond1, CondWidenVT); |
| 8106 | Cond2 = WidenVectorOp(Cond2, CondWidenVT); |
| 8107 | assert(Cond1.getValueType() == CondWidenVT && |
| 8108 | Cond2.getValueType() == CondWidenVT && "condition not widen"); |
| 8109 | |
| 8110 | SDValue Tmp1 = WidenVectorOp(Node->getOperand(2), WidenVT); |
| 8111 | SDValue Tmp2 = WidenVectorOp(Node->getOperand(3), WidenVT); |
| 8112 | assert(Tmp1.getValueType() == WidenVT && Tmp2.getValueType() == WidenVT && |
| 8113 | "operands not widen"); |
| 8114 | Result = DAG.getNode(Node->getOpcode(), WidenVT, Cond1, Cond2, Tmp1, |
| 8115 | Tmp2, Node->getOperand(4)); |
| 8116 | switch (action) { |
| 8117 | default: assert(0 && "action not supported"); |
| 8118 | case TargetLowering::Legal: |
| 8119 | break; |
| 8120 | case TargetLowering::Promote: |
| 8121 | // We defer the promotion to when we legalize the op |
| 8122 | break; |
| 8123 | case TargetLowering::Expand: |
| 8124 | // Expand the operation into a bunch of nasty scalar code by first |
| 8125 | // Widening to the right type and then unroll the beast. |
| 8126 | Result = LegalizeOp(UnrollVectorOp(Result)); |
| 8127 | break; |
| 8128 | } |
| 8129 | break; |
Mon P Wang | 42ac14e | 2008-10-30 18:21:52 +0000 | [diff] [blame] | 8130 | } |
| 8131 | case ISD::VSETCC: { |
| 8132 | // Determine widen for the operand |
| 8133 | SDValue Tmp1 = Node->getOperand(0); |
| 8134 | MVT TmpVT = Tmp1.getValueType(); |
| 8135 | assert(TmpVT.isVector() && "can not widen non vector type"); |
| 8136 | MVT TmpEVT = TmpVT.getVectorElementType(); |
| 8137 | MVT TmpWidenVT = MVT::getVectorVT(TmpEVT, NewNumElts); |
| 8138 | Tmp1 = WidenVectorOp(Tmp1, TmpWidenVT); |
| 8139 | SDValue Tmp2 = WidenVectorOp(Node->getOperand(1), TmpWidenVT); |
| 8140 | Result = DAG.getNode(Node->getOpcode(), WidenVT, Tmp1, Tmp2, |
| 8141 | Node->getOperand(2)); |
Mon P Wang | 1448aad | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8142 | break; |
| 8143 | } |
Mon P Wang | 1448aad | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8144 | case ISD::ATOMIC_CMP_SWAP_8: |
| 8145 | case ISD::ATOMIC_CMP_SWAP_16: |
| 8146 | case ISD::ATOMIC_CMP_SWAP_32: |
| 8147 | case ISD::ATOMIC_CMP_SWAP_64: |
| 8148 | case ISD::ATOMIC_LOAD_ADD_8: |
| 8149 | case ISD::ATOMIC_LOAD_SUB_8: |
| 8150 | case ISD::ATOMIC_LOAD_AND_8: |
| 8151 | case ISD::ATOMIC_LOAD_OR_8: |
| 8152 | case ISD::ATOMIC_LOAD_XOR_8: |
| 8153 | case ISD::ATOMIC_LOAD_NAND_8: |
| 8154 | case ISD::ATOMIC_LOAD_MIN_8: |
| 8155 | case ISD::ATOMIC_LOAD_MAX_8: |
| 8156 | case ISD::ATOMIC_LOAD_UMIN_8: |
| 8157 | case ISD::ATOMIC_LOAD_UMAX_8: |
| 8158 | case ISD::ATOMIC_SWAP_8: |
| 8159 | case ISD::ATOMIC_LOAD_ADD_16: |
| 8160 | case ISD::ATOMIC_LOAD_SUB_16: |
| 8161 | case ISD::ATOMIC_LOAD_AND_16: |
| 8162 | case ISD::ATOMIC_LOAD_OR_16: |
| 8163 | case ISD::ATOMIC_LOAD_XOR_16: |
| 8164 | case ISD::ATOMIC_LOAD_NAND_16: |
| 8165 | case ISD::ATOMIC_LOAD_MIN_16: |
| 8166 | case ISD::ATOMIC_LOAD_MAX_16: |
| 8167 | case ISD::ATOMIC_LOAD_UMIN_16: |
| 8168 | case ISD::ATOMIC_LOAD_UMAX_16: |
| 8169 | case ISD::ATOMIC_SWAP_16: |
| 8170 | case ISD::ATOMIC_LOAD_ADD_32: |
| 8171 | case ISD::ATOMIC_LOAD_SUB_32: |
| 8172 | case ISD::ATOMIC_LOAD_AND_32: |
| 8173 | case ISD::ATOMIC_LOAD_OR_32: |
| 8174 | case ISD::ATOMIC_LOAD_XOR_32: |
| 8175 | case ISD::ATOMIC_LOAD_NAND_32: |
| 8176 | case ISD::ATOMIC_LOAD_MIN_32: |
| 8177 | case ISD::ATOMIC_LOAD_MAX_32: |
| 8178 | case ISD::ATOMIC_LOAD_UMIN_32: |
| 8179 | case ISD::ATOMIC_LOAD_UMAX_32: |
| 8180 | case ISD::ATOMIC_SWAP_32: |
| 8181 | case ISD::ATOMIC_LOAD_ADD_64: |
| 8182 | case ISD::ATOMIC_LOAD_SUB_64: |
| 8183 | case ISD::ATOMIC_LOAD_AND_64: |
| 8184 | case ISD::ATOMIC_LOAD_OR_64: |
| 8185 | case ISD::ATOMIC_LOAD_XOR_64: |
| 8186 | case ISD::ATOMIC_LOAD_NAND_64: |
| 8187 | case ISD::ATOMIC_LOAD_MIN_64: |
| 8188 | case ISD::ATOMIC_LOAD_MAX_64: |
| 8189 | case ISD::ATOMIC_LOAD_UMIN_64: |
| 8190 | case ISD::ATOMIC_LOAD_UMAX_64: |
| 8191 | case ISD::ATOMIC_SWAP_64: { |
| 8192 | // For now, we assume that using vectors for these operations don't make |
| 8193 | // much sense so we just split it. We return an empty result |
| 8194 | SDValue X, Y; |
| 8195 | SplitVectorOp(Op, X, Y); |
| 8196 | return Result; |
| 8197 | break; |
| 8198 | } |
| 8199 | |
| 8200 | } // end switch (Node->getOpcode()) |
| 8201 | |
| 8202 | assert(Result.getNode() && "Didn't set a result!"); |
| 8203 | if (Result != Op) |
| 8204 | Result = LegalizeOp(Result); |
| 8205 | |
Mon P Wang | a5a239f | 2008-11-06 05:31:54 +0000 | [diff] [blame] | 8206 | AddWidenedOperand(Op, Result); |
Mon P Wang | 1448aad | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8207 | return Result; |
| 8208 | } |
| 8209 | |
| 8210 | // Utility function to find a legal vector type and its associated element |
| 8211 | // type from a preferred width and whose vector type must be the same size |
| 8212 | // as the VVT. |
| 8213 | // TLI: Target lowering used to determine legal types |
| 8214 | // Width: Preferred width of element type |
| 8215 | // VVT: Vector value type whose size we must match. |
| 8216 | // Returns VecEVT and EVT - the vector type and its associated element type |
| 8217 | static void FindWidenVecType(TargetLowering &TLI, unsigned Width, MVT VVT, |
| 8218 | MVT& EVT, MVT& VecEVT) { |
| 8219 | // We start with the preferred width, make it a power of 2 and see if |
| 8220 | // we can find a vector type of that width. If not, we reduce it by |
| 8221 | // another power of 2. If we have widen the type, a vector of bytes should |
| 8222 | // always be legal. |
| 8223 | assert(TLI.isTypeLegal(VVT)); |
| 8224 | unsigned EWidth = Width + 1; |
| 8225 | do { |
| 8226 | assert(EWidth > 0); |
| 8227 | EWidth = (1 << Log2_32(EWidth-1)); |
| 8228 | EVT = MVT::getIntegerVT(EWidth); |
| 8229 | unsigned NumEVT = VVT.getSizeInBits()/EWidth; |
| 8230 | VecEVT = MVT::getVectorVT(EVT, NumEVT); |
| 8231 | } while (!TLI.isTypeLegal(VecEVT) || |
| 8232 | VVT.getSizeInBits() != VecEVT.getSizeInBits()); |
| 8233 | } |
| 8234 | |
| 8235 | SDValue SelectionDAGLegalize::genWidenVectorLoads(SDValueVector& LdChain, |
| 8236 | SDValue Chain, |
| 8237 | SDValue BasePtr, |
| 8238 | const Value *SV, |
| 8239 | int SVOffset, |
| 8240 | unsigned Alignment, |
| 8241 | bool isVolatile, |
| 8242 | unsigned LdWidth, |
| 8243 | MVT ResType) { |
| 8244 | // We assume that we have good rules to handle loading power of two loads so |
| 8245 | // we break down the operations to power of 2 loads. The strategy is to |
| 8246 | // load the largest power of 2 that we can easily transform to a legal vector |
| 8247 | // and then insert into that vector, and the cast the result into the legal |
| 8248 | // vector that we want. This avoids unnecessary stack converts. |
| 8249 | // TODO: If the Ldwidth is legal, alignment is the same as the LdWidth, and |
| 8250 | // the load is nonvolatile, we an use a wider load for the value. |
| 8251 | // Find a vector length we can load a large chunk |
| 8252 | MVT EVT, VecEVT; |
| 8253 | unsigned EVTWidth; |
| 8254 | FindWidenVecType(TLI, LdWidth, ResType, EVT, VecEVT); |
| 8255 | EVTWidth = EVT.getSizeInBits(); |
| 8256 | |
| 8257 | SDValue LdOp = DAG.getLoad(EVT, Chain, BasePtr, SV, SVOffset, |
| 8258 | isVolatile, Alignment); |
| 8259 | SDValue VecOp = DAG.getNode(ISD::SCALAR_TO_VECTOR, VecEVT, LdOp); |
| 8260 | LdChain.push_back(LdOp.getValue(1)); |
| 8261 | |
| 8262 | // Check if we can load the element with one instruction |
| 8263 | if (LdWidth == EVTWidth) { |
| 8264 | return DAG.getNode(ISD::BIT_CONVERT, ResType, VecOp); |
| 8265 | } |
| 8266 | |
| 8267 | // The vector element order is endianness dependent. |
| 8268 | unsigned Idx = 1; |
| 8269 | LdWidth -= EVTWidth; |
| 8270 | unsigned Offset = 0; |
| 8271 | |
| 8272 | while (LdWidth > 0) { |
| 8273 | unsigned Increment = EVTWidth / 8; |
| 8274 | Offset += Increment; |
| 8275 | BasePtr = DAG.getNode(ISD::ADD, BasePtr.getValueType(), BasePtr, |
| 8276 | DAG.getIntPtrConstant(Increment)); |
| 8277 | |
| 8278 | if (LdWidth < EVTWidth) { |
| 8279 | // Our current type we are using is too large, use a smaller size by |
| 8280 | // using a smaller power of 2 |
| 8281 | unsigned oEVTWidth = EVTWidth; |
| 8282 | FindWidenVecType(TLI, LdWidth, ResType, EVT, VecEVT); |
| 8283 | EVTWidth = EVT.getSizeInBits(); |
| 8284 | // Readjust position and vector position based on new load type |
Mon P Wang | 257e1c7 | 2008-11-15 06:05:52 +0000 | [diff] [blame] | 8285 | Idx = Idx * (oEVTWidth/EVTWidth); |
Mon P Wang | 1448aad | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8286 | VecOp = DAG.getNode(ISD::BIT_CONVERT, VecEVT, VecOp); |
| 8287 | } |
| 8288 | |
| 8289 | SDValue LdOp = DAG.getLoad(EVT, Chain, BasePtr, SV, |
| 8290 | SVOffset+Offset, isVolatile, |
| 8291 | MinAlign(Alignment, Offset)); |
| 8292 | LdChain.push_back(LdOp.getValue(1)); |
| 8293 | VecOp = DAG.getNode(ISD::INSERT_VECTOR_ELT, VecEVT, VecOp, LdOp, |
| 8294 | DAG.getIntPtrConstant(Idx++)); |
| 8295 | |
| 8296 | LdWidth -= EVTWidth; |
| 8297 | } |
| 8298 | |
| 8299 | return DAG.getNode(ISD::BIT_CONVERT, ResType, VecOp); |
| 8300 | } |
| 8301 | |
| 8302 | bool SelectionDAGLegalize::LoadWidenVectorOp(SDValue& Result, |
| 8303 | SDValue& TFOp, |
| 8304 | SDValue Op, |
| 8305 | MVT NVT) { |
| 8306 | // TODO: Add support for ConcatVec and the ability to load many vector |
| 8307 | // types (e.g., v4i8). This will not work when a vector register |
| 8308 | // to memory mapping is strange (e.g., vector elements are not |
| 8309 | // stored in some sequential order). |
| 8310 | |
| 8311 | // It must be true that the widen vector type is bigger than where |
| 8312 | // we need to load from. |
| 8313 | LoadSDNode *LD = cast<LoadSDNode>(Op.getNode()); |
| 8314 | MVT LdVT = LD->getMemoryVT(); |
| 8315 | assert(LdVT.isVector() && NVT.isVector()); |
| 8316 | assert(LdVT.getVectorElementType() == NVT.getVectorElementType()); |
| 8317 | |
| 8318 | // Load information |
| 8319 | SDValue Chain = LD->getChain(); |
| 8320 | SDValue BasePtr = LD->getBasePtr(); |
| 8321 | int SVOffset = LD->getSrcValueOffset(); |
| 8322 | unsigned Alignment = LD->getAlignment(); |
| 8323 | bool isVolatile = LD->isVolatile(); |
| 8324 | const Value *SV = LD->getSrcValue(); |
| 8325 | unsigned int LdWidth = LdVT.getSizeInBits(); |
| 8326 | |
| 8327 | // Load value as a large register |
| 8328 | SDValueVector LdChain; |
| 8329 | Result = genWidenVectorLoads(LdChain, Chain, BasePtr, SV, SVOffset, |
| 8330 | Alignment, isVolatile, LdWidth, NVT); |
| 8331 | |
| 8332 | if (LdChain.size() == 1) { |
| 8333 | TFOp = LdChain[0]; |
| 8334 | return true; |
| 8335 | } |
| 8336 | else { |
| 8337 | TFOp=DAG.getNode(ISD::TokenFactor, MVT::Other, &LdChain[0], LdChain.size()); |
| 8338 | return false; |
| 8339 | } |
| 8340 | } |
| 8341 | |
| 8342 | |
| 8343 | void SelectionDAGLegalize::genWidenVectorStores(SDValueVector& StChain, |
| 8344 | SDValue Chain, |
| 8345 | SDValue BasePtr, |
| 8346 | const Value *SV, |
| 8347 | int SVOffset, |
| 8348 | unsigned Alignment, |
| 8349 | bool isVolatile, |
Mon P Wang | 257e1c7 | 2008-11-15 06:05:52 +0000 | [diff] [blame] | 8350 | SDValue ValOp, |
Mon P Wang | 1448aad | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8351 | unsigned StWidth) { |
| 8352 | // Breaks the stores into a series of power of 2 width stores. For any |
| 8353 | // width, we convert the vector to the vector of element size that we |
| 8354 | // want to store. This avoids requiring a stack convert. |
| 8355 | |
| 8356 | // Find a width of the element type we can store with |
| 8357 | MVT VVT = ValOp.getValueType(); |
| 8358 | MVT EVT, VecEVT; |
| 8359 | unsigned EVTWidth; |
| 8360 | FindWidenVecType(TLI, StWidth, VVT, EVT, VecEVT); |
| 8361 | EVTWidth = EVT.getSizeInBits(); |
| 8362 | |
| 8363 | SDValue VecOp = DAG.getNode(ISD::BIT_CONVERT, VecEVT, ValOp); |
| 8364 | SDValue EOp = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, EVT, VecOp, |
Mon P Wang | 927daf5 | 2008-11-06 22:52:21 +0000 | [diff] [blame] | 8365 | DAG.getIntPtrConstant(0)); |
Mon P Wang | 1448aad | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8366 | SDValue StOp = DAG.getStore(Chain, EOp, BasePtr, SV, SVOffset, |
| 8367 | isVolatile, Alignment); |
| 8368 | StChain.push_back(StOp); |
| 8369 | |
| 8370 | // Check if we are done |
| 8371 | if (StWidth == EVTWidth) { |
| 8372 | return; |
| 8373 | } |
| 8374 | |
| 8375 | unsigned Idx = 1; |
| 8376 | StWidth -= EVTWidth; |
| 8377 | unsigned Offset = 0; |
| 8378 | |
| 8379 | while (StWidth > 0) { |
| 8380 | unsigned Increment = EVTWidth / 8; |
| 8381 | Offset += Increment; |
| 8382 | BasePtr = DAG.getNode(ISD::ADD, BasePtr.getValueType(), BasePtr, |
| 8383 | DAG.getIntPtrConstant(Increment)); |
| 8384 | |
| 8385 | if (StWidth < EVTWidth) { |
| 8386 | // Our current type we are using is too large, use a smaller size by |
| 8387 | // using a smaller power of 2 |
| 8388 | unsigned oEVTWidth = EVTWidth; |
| 8389 | FindWidenVecType(TLI, StWidth, VVT, EVT, VecEVT); |
| 8390 | EVTWidth = EVT.getSizeInBits(); |
| 8391 | // Readjust position and vector position based on new load type |
Mon P Wang | 257e1c7 | 2008-11-15 06:05:52 +0000 | [diff] [blame] | 8392 | Idx = Idx * (oEVTWidth/EVTWidth); |
Mon P Wang | 1448aad | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8393 | VecOp = DAG.getNode(ISD::BIT_CONVERT, VecEVT, VecOp); |
| 8394 | } |
| 8395 | |
| 8396 | EOp = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, EVT, VecOp, |
Mon P Wang | 257e1c7 | 2008-11-15 06:05:52 +0000 | [diff] [blame] | 8397 | DAG.getIntPtrConstant(Idx++)); |
Mon P Wang | 1448aad | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8398 | StChain.push_back(DAG.getStore(Chain, EOp, BasePtr, SV, |
| 8399 | SVOffset + Offset, isVolatile, |
| 8400 | MinAlign(Alignment, Offset))); |
| 8401 | StWidth -= EVTWidth; |
| 8402 | } |
| 8403 | } |
| 8404 | |
| 8405 | |
| 8406 | SDValue SelectionDAGLegalize::StoreWidenVectorOp(StoreSDNode *ST, |
| 8407 | SDValue Chain, |
| 8408 | SDValue BasePtr) { |
| 8409 | // TODO: It might be cleaner if we can use SplitVector and have more legal |
| 8410 | // vector types that can be stored into memory (e.g., v4xi8 can |
| 8411 | // be stored as a word). This will not work when a vector register |
| 8412 | // to memory mapping is strange (e.g., vector elements are not |
| 8413 | // stored in some sequential order). |
| 8414 | |
| 8415 | MVT StVT = ST->getMemoryVT(); |
| 8416 | SDValue ValOp = ST->getValue(); |
| 8417 | |
| 8418 | // Check if we have widen this node with another value |
| 8419 | std::map<SDValue, SDValue>::iterator I = WidenNodes.find(ValOp); |
| 8420 | if (I != WidenNodes.end()) |
| 8421 | ValOp = I->second; |
| 8422 | |
| 8423 | MVT VVT = ValOp.getValueType(); |
| 8424 | |
| 8425 | // It must be true that we the widen vector type is bigger than where |
| 8426 | // we need to store. |
| 8427 | assert(StVT.isVector() && VVT.isVector()); |
| 8428 | assert(StVT.getSizeInBits() < VVT.getSizeInBits()); |
| 8429 | assert(StVT.getVectorElementType() == VVT.getVectorElementType()); |
| 8430 | |
| 8431 | // Store value |
| 8432 | SDValueVector StChain; |
| 8433 | genWidenVectorStores(StChain, Chain, BasePtr, ST->getSrcValue(), |
| 8434 | ST->getSrcValueOffset(), ST->getAlignment(), |
| 8435 | ST->isVolatile(), ValOp, StVT.getSizeInBits()); |
| 8436 | if (StChain.size() == 1) |
| 8437 | return StChain[0]; |
| 8438 | else |
| 8439 | return DAG.getNode(ISD::TokenFactor, MVT::Other,&StChain[0],StChain.size()); |
| 8440 | } |
| 8441 | |
| 8442 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 8443 | // SelectionDAG::Legalize - This is the entry point for the file. |
| 8444 | // |
| 8445 | void SelectionDAG::Legalize() { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 8446 | /// run - This is the main entry point to this class. |
| 8447 | /// |
| 8448 | SelectionDAGLegalize(*this).LegalizeDAG(); |
| 8449 | } |
| 8450 | |