Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1 | //===-- LegalizeDAG.cpp - Implement SelectionDAG::Legalize ----------------===// |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2 | // |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by the LLVM research group and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 7 | // |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the SelectionDAG::Legalize method. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "llvm/CodeGen/SelectionDAG.h" |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 15 | #include "llvm/CodeGen/MachineFunction.h" |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 16 | #include "llvm/CodeGen/MachineFrameInfo.h" |
Jim Laskey | acd80ac | 2006-12-14 19:17:33 +0000 | [diff] [blame] | 17 | #include "llvm/CodeGen/MachineJumpTableInfo.h" |
Evan Cheng | 61bbbab | 2007-08-16 23:50:06 +0000 | [diff] [blame] | 18 | #include "llvm/Target/TargetFrameInfo.h" |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 19 | #include "llvm/Target/TargetLowering.h" |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 20 | #include "llvm/Target/TargetData.h" |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 21 | #include "llvm/Target/TargetMachine.h" |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 22 | #include "llvm/Target/TargetOptions.h" |
Chris Lattner | adf6a96 | 2005-05-13 18:50:42 +0000 | [diff] [blame] | 23 | #include "llvm/CallingConv.h" |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 24 | #include "llvm/Constants.h" |
Reid Spencer | c103057 | 2007-01-19 21:13:56 +0000 | [diff] [blame] | 25 | #include "llvm/DerivedTypes.h" |
Chris Lattner | 5e46a19 | 2006-04-02 03:07:27 +0000 | [diff] [blame] | 26 | #include "llvm/Support/MathExtras.h" |
| 27 | #include "llvm/Support/CommandLine.h" |
Chris Lattner | a4f0b3a | 2006-08-27 12:54:02 +0000 | [diff] [blame] | 28 | #include "llvm/Support/Compiler.h" |
Chris Lattner | 7971514 | 2007-02-03 01:12:36 +0000 | [diff] [blame] | 29 | #include "llvm/ADT/DenseMap.h" |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 30 | #include "llvm/ADT/SmallVector.h" |
Chris Lattner | 00755df | 2007-02-04 00:27:56 +0000 | [diff] [blame] | 31 | #include "llvm/ADT/SmallPtrSet.h" |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 32 | #include <map> |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 33 | using namespace llvm; |
| 34 | |
Chris Lattner | 5e46a19 | 2006-04-02 03:07:27 +0000 | [diff] [blame] | 35 | #ifndef NDEBUG |
| 36 | static cl::opt<bool> |
| 37 | ViewLegalizeDAGs("view-legalize-dags", cl::Hidden, |
| 38 | cl::desc("Pop up a window to show dags before legalize")); |
| 39 | #else |
| 40 | static const bool ViewLegalizeDAGs = 0; |
| 41 | #endif |
| 42 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 43 | //===----------------------------------------------------------------------===// |
| 44 | /// SelectionDAGLegalize - This takes an arbitrary SelectionDAG as input and |
| 45 | /// hacks on it until the target machine can handle it. This involves |
| 46 | /// eliminating value sizes the machine cannot handle (promoting small sizes to |
| 47 | /// large sizes or splitting up large values into small values) as well as |
| 48 | /// eliminating operations the machine cannot handle. |
| 49 | /// |
| 50 | /// This code also does a small amount of optimization and recognition of idioms |
| 51 | /// as part of its processing. For example, if a target does not support a |
| 52 | /// 'setcc' instruction efficiently, but does support 'brcc' instruction, this |
| 53 | /// will attempt merge setcc and brc instructions into brcc's. |
| 54 | /// |
| 55 | namespace { |
Chris Lattner | 360e820 | 2006-06-28 21:58:30 +0000 | [diff] [blame] | 56 | class VISIBILITY_HIDDEN SelectionDAGLegalize { |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 57 | TargetLowering &TLI; |
| 58 | SelectionDAG &DAG; |
| 59 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 60 | // Libcall insertion helpers. |
| 61 | |
| 62 | /// LastCALLSEQ_END - This keeps track of the CALLSEQ_END node that has been |
| 63 | /// legalized. We use this to ensure that calls are properly serialized |
| 64 | /// against each other, including inserted libcalls. |
| 65 | SDOperand LastCALLSEQ_END; |
| 66 | |
| 67 | /// IsLegalizingCall - This member is used *only* for purposes of providing |
| 68 | /// helpful assertions that a libcall isn't created while another call is |
| 69 | /// being legalized (which could lead to non-serialized call sequences). |
| 70 | bool IsLegalizingCall; |
| 71 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 72 | enum LegalizeAction { |
Chris Lattner | 68a17fe | 2006-01-29 08:42:06 +0000 | [diff] [blame] | 73 | Legal, // The target natively supports this operation. |
| 74 | Promote, // This operation should be executed in a larger type. |
Chris Lattner | d74ea2b | 2006-05-24 17:04:05 +0000 | [diff] [blame] | 75 | Expand // Try to expand this to other ops, otherwise use a libcall. |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 76 | }; |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 77 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 78 | /// ValueTypeActions - This is a bitvector that contains two bits for each |
| 79 | /// value type, where the two bits correspond to the LegalizeAction enum. |
| 80 | /// This can be queried with "getTypeAction(VT)". |
Chris Lattner | 68a17fe | 2006-01-29 08:42:06 +0000 | [diff] [blame] | 81 | TargetLowering::ValueTypeActionImpl ValueTypeActions; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 82 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 83 | /// LegalizedNodes - For nodes that are of legal width, and that have more |
| 84 | /// than one use, this map indicates what regularized operand to use. This |
| 85 | /// allows us to avoid legalizing the same thing more than once. |
Chris Lattner | 718071c | 2007-02-04 00:50:02 +0000 | [diff] [blame] | 86 | DenseMap<SDOperand, SDOperand> LegalizedNodes; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 87 | |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 88 | /// PromotedNodes - For nodes that are below legal width, and that have more |
| 89 | /// than one use, this map indicates what promoted value to use. This allows |
| 90 | /// us to avoid promoting the same thing more than once. |
Chris Lattner | 40030bf | 2007-02-04 01:17:38 +0000 | [diff] [blame] | 91 | DenseMap<SDOperand, SDOperand> PromotedNodes; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 92 | |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 93 | /// ExpandedNodes - For nodes that need to be expanded this map indicates |
| 94 | /// which which operands are the expanded version of the input. This allows |
| 95 | /// us to avoid expanding the same node more than once. |
Chris Lattner | 40030bf | 2007-02-04 01:17:38 +0000 | [diff] [blame] | 96 | DenseMap<SDOperand, std::pair<SDOperand, SDOperand> > ExpandedNodes; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 97 | |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 98 | /// SplitNodes - For vector nodes that need to be split, this map indicates |
| 99 | /// which which operands are the split version of the input. This allows us |
| 100 | /// to avoid splitting the same node more than once. |
| 101 | std::map<SDOperand, std::pair<SDOperand, SDOperand> > SplitNodes; |
| 102 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 103 | /// ScalarizedNodes - For nodes that need to be converted from vector types to |
| 104 | /// scalar types, this contains the mapping of ones we have already |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 105 | /// processed to the result. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 106 | std::map<SDOperand, SDOperand> ScalarizedNodes; |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 107 | |
Chris Lattner | 8afc48e | 2005-01-07 22:28:47 +0000 | [diff] [blame] | 108 | void AddLegalizedOperand(SDOperand From, SDOperand To) { |
Chris Lattner | 69a889e | 2005-12-20 00:53:54 +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)); |
Chris Lattner | 8afc48e | 2005-01-07 22:28:47 +0000 | [diff] [blame] | 113 | } |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 114 | void AddPromotedOperand(SDOperand From, SDOperand To) { |
Chris Lattner | 40030bf | 2007-02-04 01:17:38 +0000 | [diff] [blame] | 115 | bool isNew = PromotedNodes.insert(std::make_pair(From, To)); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 116 | assert(isNew && "Got into the map somehow?"); |
Chris Lattner | 69a889e | 2005-12-20 00:53:54 +0000 | [diff] [blame] | 117 | // If someone requests legalization of the new node, return itself. |
| 118 | LegalizedNodes.insert(std::make_pair(To, To)); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 119 | } |
Chris Lattner | 8afc48e | 2005-01-07 22:28:47 +0000 | [diff] [blame] | 120 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 121 | public: |
| 122 | |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 123 | SelectionDAGLegalize(SelectionDAG &DAG); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 124 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 125 | /// getTypeAction - Return how we should legalize values of this type, either |
| 126 | /// it is already legal or we need to expand it into multiple registers of |
| 127 | /// smaller integer type, or we need to promote it to a larger type. |
| 128 | LegalizeAction getTypeAction(MVT::ValueType VT) const { |
Chris Lattner | 68a17fe | 2006-01-29 08:42:06 +0000 | [diff] [blame] | 129 | return (LegalizeAction)ValueTypeActions.getTypeAction(VT); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | /// isTypeLegal - Return true if this type is legal on this target. |
| 133 | /// |
| 134 | bool isTypeLegal(MVT::ValueType VT) const { |
| 135 | return getTypeAction(VT) == Legal; |
| 136 | } |
| 137 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 138 | void LegalizeDAG(); |
| 139 | |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 140 | private: |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 141 | /// HandleOp - Legalize, Promote, or Expand the specified operand as |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 142 | /// appropriate for its type. |
| 143 | void HandleOp(SDOperand Op); |
| 144 | |
| 145 | /// LegalizeOp - We know that the specified value has a legal type. |
| 146 | /// Recursively ensure that the operands have legal types, then return the |
| 147 | /// result. |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 148 | SDOperand LegalizeOp(SDOperand O); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 149 | |
| 150 | /// PromoteOp - Given an operation that produces a value in an invalid type, |
| 151 | /// promote it to compute the value into a larger type. The produced value |
| 152 | /// will have the correct bits for the low portion of the register, but no |
| 153 | /// guarantee is made about the top bits: it may be zero, sign-extended, or |
| 154 | /// garbage. |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 155 | SDOperand PromoteOp(SDOperand O); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 156 | |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 157 | /// ExpandOp - Expand the specified SDOperand into its two component pieces |
| 158 | /// Lo&Hi. Note that the Op MUST be an expanded type. As a result of this, |
| 159 | /// the LegalizeNodes map is filled in for any results that are not expanded, |
| 160 | /// the ExpandedNodes map is filled in for any results that are expanded, and |
| 161 | /// the Lo/Hi values are returned. This applies to integer types and Vector |
| 162 | /// types. |
| 163 | void ExpandOp(SDOperand O, SDOperand &Lo, SDOperand &Hi); |
| 164 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 165 | /// SplitVectorOp - Given an operand of vector type, break it down into |
| 166 | /// two smaller values. |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 167 | void SplitVectorOp(SDOperand O, SDOperand &Lo, SDOperand &Hi); |
| 168 | |
Dan Gohman | 89b20c0 | 2007-06-27 14:06:22 +0000 | [diff] [blame] | 169 | /// ScalarizeVectorOp - Given an operand of single-element vector type |
| 170 | /// (e.g. v1f32), convert it into the equivalent operation that returns a |
| 171 | /// scalar (e.g. f32) value. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 172 | SDOperand ScalarizeVectorOp(SDOperand O); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 173 | |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 174 | /// isShuffleLegal - Return true if a vector shuffle is legal with the |
| 175 | /// specified mask and type. Targets can specify exactly which masks they |
| 176 | /// support and the code generator is tasked with not creating illegal masks. |
| 177 | /// |
| 178 | /// Note that this will also return true for shuffles that are promoted to a |
| 179 | /// different type. |
| 180 | /// |
| 181 | /// If this is a legal shuffle, this method returns the (possibly promoted) |
| 182 | /// build_vector Mask. If it's not a legal shuffle, it returns null. |
| 183 | SDNode *isShuffleLegal(MVT::ValueType VT, SDOperand Mask) const; |
| 184 | |
Chris Lattner | c9cf4f1 | 2006-07-26 23:55:56 +0000 | [diff] [blame] | 185 | bool LegalizeAllNodesNotLeadingTo(SDNode *N, SDNode *Dest, |
Chris Lattner | 00755df | 2007-02-04 00:27:56 +0000 | [diff] [blame] | 186 | SmallPtrSet<SDNode*, 32> &NodesLeadingTo); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 187 | |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 188 | void LegalizeSetCCOperands(SDOperand &LHS, SDOperand &RHS, SDOperand &CC); |
| 189 | |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 190 | SDOperand CreateStackTemporary(MVT::ValueType VT); |
| 191 | |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 192 | SDOperand ExpandLibCall(const char *Name, SDNode *Node, bool isSigned, |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 193 | SDOperand &Hi); |
| 194 | SDOperand ExpandIntToFP(bool isSigned, MVT::ValueType DestTy, |
| 195 | SDOperand Source); |
Chris Lattner | cad063f | 2005-07-16 00:19:57 +0000 | [diff] [blame] | 196 | |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 197 | SDOperand ExpandBIT_CONVERT(MVT::ValueType DestVT, SDOperand SrcOp); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 198 | SDOperand ExpandBUILD_VECTOR(SDNode *Node); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 199 | SDOperand ExpandSCALAR_TO_VECTOR(SDNode *Node); |
Jim Laskey | 6269ed1 | 2005-08-17 00:39:29 +0000 | [diff] [blame] | 200 | SDOperand ExpandLegalINT_TO_FP(bool isSigned, |
| 201 | SDOperand LegalOp, |
| 202 | MVT::ValueType DestVT); |
Nate Begeman | 5a8441e | 2005-07-16 02:02:34 +0000 | [diff] [blame] | 203 | SDOperand PromoteLegalINT_TO_FP(SDOperand LegalOp, MVT::ValueType DestVT, |
| 204 | bool isSigned); |
Chris Lattner | 1618beb | 2005-07-29 00:11:56 +0000 | [diff] [blame] | 205 | SDOperand PromoteLegalFP_TO_INT(SDOperand LegalOp, MVT::ValueType DestVT, |
| 206 | bool isSigned); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 207 | |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 208 | SDOperand ExpandBSWAP(SDOperand Op); |
| 209 | SDOperand ExpandBitCount(unsigned Opc, SDOperand Op); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 210 | bool ExpandShift(unsigned Opc, SDOperand Op, SDOperand Amt, |
| 211 | SDOperand &Lo, SDOperand &Hi); |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 212 | void ExpandShiftParts(unsigned NodeOp, SDOperand Op, SDOperand Amt, |
| 213 | SDOperand &Lo, SDOperand &Hi); |
Chris Lattner | b9fa3bc | 2005-05-12 04:49:08 +0000 | [diff] [blame] | 214 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 215 | SDOperand ExpandEXTRACT_SUBVECTOR(SDOperand Op); |
Chris Lattner | 4aab2f4 | 2006-04-02 05:06:04 +0000 | [diff] [blame] | 216 | SDOperand ExpandEXTRACT_VECTOR_ELT(SDOperand Op); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 217 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 218 | SDOperand getIntPtrConstant(uint64_t Val) { |
| 219 | return DAG.getConstant(Val, TLI.getPointerTy()); |
| 220 | } |
| 221 | }; |
| 222 | } |
| 223 | |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 224 | /// isVectorShuffleLegal - Return true if a vector shuffle is legal with the |
| 225 | /// specified mask and type. Targets can specify exactly which masks they |
| 226 | /// support and the code generator is tasked with not creating illegal masks. |
| 227 | /// |
| 228 | /// Note that this will also return true for shuffles that are promoted to a |
| 229 | /// different type. |
| 230 | SDNode *SelectionDAGLegalize::isShuffleLegal(MVT::ValueType VT, |
| 231 | SDOperand Mask) const { |
| 232 | switch (TLI.getOperationAction(ISD::VECTOR_SHUFFLE, VT)) { |
| 233 | default: return 0; |
| 234 | case TargetLowering::Legal: |
| 235 | case TargetLowering::Custom: |
| 236 | break; |
| 237 | case TargetLowering::Promote: { |
| 238 | // If this is promoted to a different type, convert the shuffle mask and |
| 239 | // ask if it is legal in the promoted type! |
| 240 | MVT::ValueType NVT = TLI.getTypeToPromoteTo(ISD::VECTOR_SHUFFLE, VT); |
| 241 | |
| 242 | // If we changed # elements, change the shuffle mask. |
| 243 | unsigned NumEltsGrowth = |
| 244 | MVT::getVectorNumElements(NVT) / MVT::getVectorNumElements(VT); |
| 245 | assert(NumEltsGrowth && "Cannot promote to vector type with fewer elts!"); |
| 246 | if (NumEltsGrowth > 1) { |
| 247 | // Renumber the elements. |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 248 | SmallVector<SDOperand, 8> Ops; |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 249 | for (unsigned i = 0, e = Mask.getNumOperands(); i != e; ++i) { |
| 250 | SDOperand InOp = Mask.getOperand(i); |
| 251 | for (unsigned j = 0; j != NumEltsGrowth; ++j) { |
| 252 | if (InOp.getOpcode() == ISD::UNDEF) |
| 253 | Ops.push_back(DAG.getNode(ISD::UNDEF, MVT::i32)); |
| 254 | else { |
| 255 | unsigned InEltNo = cast<ConstantSDNode>(InOp)->getValue(); |
| 256 | Ops.push_back(DAG.getConstant(InEltNo*NumEltsGrowth+j, MVT::i32)); |
| 257 | } |
| 258 | } |
| 259 | } |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 260 | Mask = DAG.getNode(ISD::BUILD_VECTOR, NVT, &Ops[0], Ops.size()); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 261 | } |
| 262 | VT = NVT; |
| 263 | break; |
| 264 | } |
| 265 | } |
| 266 | return TLI.isShuffleMaskLegal(Mask, VT) ? Mask.Val : 0; |
| 267 | } |
| 268 | |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 269 | SelectionDAGLegalize::SelectionDAGLegalize(SelectionDAG &dag) |
| 270 | : TLI(dag.getTargetLoweringInfo()), DAG(dag), |
| 271 | ValueTypeActions(TLI.getValueTypeActions()) { |
Nate Begeman | 6a64861 | 2005-11-29 05:45:29 +0000 | [diff] [blame] | 272 | assert(MVT::LAST_VALUETYPE <= 32 && |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 273 | "Too many value types for ValueTypeActions to hold!"); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 274 | } |
| 275 | |
Chris Lattner | e10e6f7 | 2007-06-18 21:28:10 +0000 | [diff] [blame] | 276 | /// ComputeTopDownOrdering - Compute a top-down ordering of the dag, where Order |
| 277 | /// contains all of a nodes operands before it contains the node. |
| 278 | static void ComputeTopDownOrdering(SelectionDAG &DAG, |
| 279 | SmallVector<SDNode*, 64> &Order) { |
| 280 | |
| 281 | DenseMap<SDNode*, unsigned> Visited; |
| 282 | std::vector<SDNode*> Worklist; |
| 283 | Worklist.reserve(128); |
Chris Lattner | 32fca00 | 2005-10-06 01:20:27 +0000 | [diff] [blame] | 284 | |
Chris Lattner | e10e6f7 | 2007-06-18 21:28:10 +0000 | [diff] [blame] | 285 | // Compute ordering from all of the leaves in the graphs, those (like the |
| 286 | // entry node) that have no operands. |
| 287 | for (SelectionDAG::allnodes_iterator I = DAG.allnodes_begin(), |
| 288 | E = DAG.allnodes_end(); I != E; ++I) { |
| 289 | if (I->getNumOperands() == 0) { |
| 290 | Visited[I] = 0 - 1U; |
| 291 | Worklist.push_back(I); |
| 292 | } |
Chris Lattner | 32fca00 | 2005-10-06 01:20:27 +0000 | [diff] [blame] | 293 | } |
| 294 | |
Chris Lattner | e10e6f7 | 2007-06-18 21:28:10 +0000 | [diff] [blame] | 295 | while (!Worklist.empty()) { |
| 296 | SDNode *N = Worklist.back(); |
| 297 | Worklist.pop_back(); |
| 298 | |
| 299 | if (++Visited[N] != N->getNumOperands()) |
| 300 | continue; // Haven't visited all operands yet |
| 301 | |
| 302 | Order.push_back(N); |
| 303 | |
| 304 | // Now that we have N in, add anything that uses it if all of their operands |
| 305 | // are now done. |
| 306 | for (SDNode::use_iterator UI = N->use_begin(), E = N->use_end(); |
| 307 | UI != E; ++UI) |
| 308 | Worklist.push_back(*UI); |
| 309 | } |
| 310 | |
| 311 | assert(Order.size() == Visited.size() && |
| 312 | Order.size() == |
| 313 | (unsigned)std::distance(DAG.allnodes_begin(), DAG.allnodes_end()) && |
| 314 | "Error: DAG is cyclic!"); |
Chris Lattner | 32fca00 | 2005-10-06 01:20:27 +0000 | [diff] [blame] | 315 | } |
| 316 | |
Chris Lattner | 1618beb | 2005-07-29 00:11:56 +0000 | [diff] [blame] | 317 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 318 | void SelectionDAGLegalize::LegalizeDAG() { |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 319 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 320 | IsLegalizingCall = false; |
| 321 | |
Chris Lattner | ab510a7 | 2005-10-02 17:49:46 +0000 | [diff] [blame] | 322 | // The legalize process is inherently a bottom-up recursive process (users |
| 323 | // legalize their uses before themselves). Given infinite stack space, we |
| 324 | // could just start legalizing on the root and traverse the whole graph. In |
| 325 | // practice however, this causes us to run out of stack space on large basic |
Chris Lattner | 32fca00 | 2005-10-06 01:20:27 +0000 | [diff] [blame] | 326 | // blocks. To avoid this problem, compute an ordering of the nodes where each |
| 327 | // node is only legalized after all of its operands are legalized. |
Chris Lattner | 0ed4417 | 2007-02-04 01:20:02 +0000 | [diff] [blame] | 328 | SmallVector<SDNode*, 64> Order; |
Chris Lattner | e10e6f7 | 2007-06-18 21:28:10 +0000 | [diff] [blame] | 329 | ComputeTopDownOrdering(DAG, Order); |
Chris Lattner | ab510a7 | 2005-10-02 17:49:46 +0000 | [diff] [blame] | 330 | |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 331 | for (unsigned i = 0, e = Order.size(); i != e; ++i) |
| 332 | HandleOp(SDOperand(Order[i], 0)); |
Chris Lattner | 32fca00 | 2005-10-06 01:20:27 +0000 | [diff] [blame] | 333 | |
| 334 | // Finally, it's possible the root changed. Get the new root. |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 335 | SDOperand OldRoot = DAG.getRoot(); |
Chris Lattner | 32fca00 | 2005-10-06 01:20:27 +0000 | [diff] [blame] | 336 | assert(LegalizedNodes.count(OldRoot) && "Root didn't get legalized?"); |
| 337 | DAG.setRoot(LegalizedNodes[OldRoot]); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 338 | |
| 339 | ExpandedNodes.clear(); |
| 340 | LegalizedNodes.clear(); |
Chris Lattner | 71c42a0 | 2005-01-16 01:11:45 +0000 | [diff] [blame] | 341 | PromotedNodes.clear(); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 342 | SplitNodes.clear(); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 343 | ScalarizedNodes.clear(); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 344 | |
| 345 | // Remove dead nodes now. |
Chris Lattner | 190a418 | 2006-08-04 17:45:20 +0000 | [diff] [blame] | 346 | DAG.RemoveDeadNodes(); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 347 | } |
| 348 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 349 | |
| 350 | /// FindCallEndFromCallStart - Given a chained node that is part of a call |
| 351 | /// sequence, find the CALLSEQ_END node that terminates the call sequence. |
| 352 | static SDNode *FindCallEndFromCallStart(SDNode *Node) { |
| 353 | if (Node->getOpcode() == ISD::CALLSEQ_END) |
| 354 | return Node; |
| 355 | if (Node->use_empty()) |
| 356 | return 0; // No CallSeqEnd |
| 357 | |
| 358 | // The chain is usually at the end. |
| 359 | SDOperand TheChain(Node, Node->getNumValues()-1); |
| 360 | if (TheChain.getValueType() != MVT::Other) { |
| 361 | // Sometimes it's at the beginning. |
| 362 | TheChain = SDOperand(Node, 0); |
| 363 | if (TheChain.getValueType() != MVT::Other) { |
| 364 | // Otherwise, hunt for it. |
| 365 | for (unsigned i = 1, e = Node->getNumValues(); i != e; ++i) |
| 366 | if (Node->getValueType(i) == MVT::Other) { |
| 367 | TheChain = SDOperand(Node, i); |
| 368 | break; |
| 369 | } |
| 370 | |
| 371 | // Otherwise, we walked into a node without a chain. |
| 372 | if (TheChain.getValueType() != MVT::Other) |
| 373 | return 0; |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | for (SDNode::use_iterator UI = Node->use_begin(), |
| 378 | E = Node->use_end(); UI != E; ++UI) { |
| 379 | |
| 380 | // Make sure to only follow users of our token chain. |
| 381 | SDNode *User = *UI; |
| 382 | for (unsigned i = 0, e = User->getNumOperands(); i != e; ++i) |
| 383 | if (User->getOperand(i) == TheChain) |
| 384 | if (SDNode *Result = FindCallEndFromCallStart(User)) |
| 385 | return Result; |
| 386 | } |
| 387 | return 0; |
| 388 | } |
| 389 | |
| 390 | /// FindCallStartFromCallEnd - Given a chained node that is part of a call |
| 391 | /// sequence, find the CALLSEQ_START node that initiates the call sequence. |
| 392 | static SDNode *FindCallStartFromCallEnd(SDNode *Node) { |
| 393 | assert(Node && "Didn't find callseq_start for a call??"); |
| 394 | if (Node->getOpcode() == ISD::CALLSEQ_START) return Node; |
| 395 | |
| 396 | assert(Node->getOperand(0).getValueType() == MVT::Other && |
| 397 | "Node doesn't have a token chain argument!"); |
| 398 | return FindCallStartFromCallEnd(Node->getOperand(0).Val); |
| 399 | } |
| 400 | |
| 401 | /// LegalizeAllNodesNotLeadingTo - Recursively walk the uses of N, looking to |
| 402 | /// see if any uses can reach Dest. If no dest operands can get to dest, |
| 403 | /// legalize them, legalize ourself, and return false, otherwise, return true. |
Chris Lattner | c9cf4f1 | 2006-07-26 23:55:56 +0000 | [diff] [blame] | 404 | /// |
| 405 | /// Keep track of the nodes we fine that actually do lead to Dest in |
| 406 | /// NodesLeadingTo. This avoids retraversing them exponential number of times. |
| 407 | /// |
| 408 | bool SelectionDAGLegalize::LegalizeAllNodesNotLeadingTo(SDNode *N, SDNode *Dest, |
Chris Lattner | 00755df | 2007-02-04 00:27:56 +0000 | [diff] [blame] | 409 | SmallPtrSet<SDNode*, 32> &NodesLeadingTo) { |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 410 | if (N == Dest) return true; // N certainly leads to Dest :) |
| 411 | |
Chris Lattner | c9cf4f1 | 2006-07-26 23:55:56 +0000 | [diff] [blame] | 412 | // If we've already processed this node and it does lead to Dest, there is no |
| 413 | // need to reprocess it. |
| 414 | if (NodesLeadingTo.count(N)) return true; |
| 415 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 416 | // If the first result of this node has been already legalized, then it cannot |
| 417 | // reach N. |
| 418 | switch (getTypeAction(N->getValueType(0))) { |
| 419 | case Legal: |
| 420 | if (LegalizedNodes.count(SDOperand(N, 0))) return false; |
| 421 | break; |
| 422 | case Promote: |
| 423 | if (PromotedNodes.count(SDOperand(N, 0))) return false; |
| 424 | break; |
| 425 | case Expand: |
| 426 | if (ExpandedNodes.count(SDOperand(N, 0))) return false; |
| 427 | break; |
| 428 | } |
| 429 | |
| 430 | // Okay, this node has not already been legalized. Check and legalize all |
| 431 | // operands. If none lead to Dest, then we can legalize this node. |
| 432 | bool OperandsLeadToDest = false; |
| 433 | for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) |
| 434 | OperandsLeadToDest |= // If an operand leads to Dest, so do we. |
Chris Lattner | c9cf4f1 | 2006-07-26 23:55:56 +0000 | [diff] [blame] | 435 | LegalizeAllNodesNotLeadingTo(N->getOperand(i).Val, Dest, NodesLeadingTo); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 436 | |
Chris Lattner | c9cf4f1 | 2006-07-26 23:55:56 +0000 | [diff] [blame] | 437 | if (OperandsLeadToDest) { |
| 438 | NodesLeadingTo.insert(N); |
| 439 | return true; |
| 440 | } |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 441 | |
| 442 | // Okay, this node looks safe, legalize it and return false. |
Chris Lattner | 80edfb3 | 2006-04-17 22:10:08 +0000 | [diff] [blame] | 443 | HandleOp(SDOperand(N, 0)); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 444 | return false; |
| 445 | } |
| 446 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 447 | /// HandleOp - Legalize, Promote, or Expand the specified operand as |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 448 | /// appropriate for its type. |
| 449 | void SelectionDAGLegalize::HandleOp(SDOperand Op) { |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 450 | MVT::ValueType VT = Op.getValueType(); |
| 451 | switch (getTypeAction(VT)) { |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 452 | default: assert(0 && "Bad type action!"); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 453 | case Legal: (void)LegalizeOp(Op); break; |
| 454 | case Promote: (void)PromoteOp(Op); break; |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 455 | case Expand: |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 456 | if (!MVT::isVector(VT)) { |
| 457 | // If this is an illegal scalar, expand it into its two component |
| 458 | // pieces. |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 459 | SDOperand X, Y; |
Chris Lattner | 09ec1b0 | 2007-08-25 01:00:22 +0000 | [diff] [blame] | 460 | if (Op.getOpcode() == ISD::TargetConstant) |
| 461 | break; // Allow illegal target nodes. |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 462 | ExpandOp(Op, X, Y); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 463 | } else if (MVT::getVectorNumElements(VT) == 1) { |
| 464 | // If this is an illegal single element vector, convert it to a |
| 465 | // scalar operation. |
| 466 | (void)ScalarizeVectorOp(Op); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 467 | } else { |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 468 | // Otherwise, this is an illegal multiple element vector. |
| 469 | // Split it in half and legalize both parts. |
| 470 | SDOperand X, Y; |
| 471 | SplitVectorOp(Op, X, Y); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 472 | } |
| 473 | break; |
| 474 | } |
| 475 | } |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 476 | |
Evan Cheng | 9f87788 | 2006-12-13 20:57:08 +0000 | [diff] [blame] | 477 | /// ExpandConstantFP - Expands the ConstantFP node to an integer constant or |
| 478 | /// a load from the constant pool. |
| 479 | static SDOperand ExpandConstantFP(ConstantFPSDNode *CFP, bool UseCP, |
Evan Cheng | 279101e | 2006-12-12 22:19:28 +0000 | [diff] [blame] | 480 | SelectionDAG &DAG, TargetLowering &TLI) { |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 481 | bool Extend = false; |
| 482 | |
| 483 | // If a FP immediate is precise when represented as a float and if the |
| 484 | // target can do an extending load from float to double, we put it into |
| 485 | // the constant pool as a float, even if it's is statically typed as a |
| 486 | // double. |
| 487 | MVT::ValueType VT = CFP->getValueType(0); |
| 488 | bool isDouble = VT == MVT::f64; |
Dale Johannesen | 118cd9d | 2007-09-16 16:51:49 +0000 | [diff] [blame] | 489 | ConstantFP *LLVMC = ConstantFP::get(MVT::getTypeForValueType(VT), |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 490 | CFP->getValueAPF()); |
Evan Cheng | 9f87788 | 2006-12-13 20:57:08 +0000 | [diff] [blame] | 491 | if (!UseCP) { |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 492 | if (VT!=MVT::f64 && VT!=MVT::f32) |
| 493 | assert(0 && "Invalid type expansion"); |
Dale Johannesen | 9d5f456 | 2007-09-12 03:30:33 +0000 | [diff] [blame] | 494 | return DAG.getConstant(LLVMC->getValueAPF().convertToAPInt().getZExtValue(), |
| 495 | isDouble ? MVT::i64 : MVT::i32); |
Evan Cheng | 279101e | 2006-12-12 22:19:28 +0000 | [diff] [blame] | 496 | } |
| 497 | |
Dale Johannesen | f04afdb | 2007-08-30 00:23:21 +0000 | [diff] [blame] | 498 | if (isDouble && CFP->isValueValidForType(MVT::f32, CFP->getValueAPF()) && |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 499 | // Only do this if the target has a native EXTLOAD instruction from f32. |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 500 | // Do not try to be clever about long doubles (so far) |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 501 | TLI.isLoadXLegal(ISD::EXTLOAD, MVT::f32)) { |
| 502 | LLVMC = cast<ConstantFP>(ConstantExpr::getFPTrunc(LLVMC,Type::FloatTy)); |
| 503 | VT = MVT::f32; |
| 504 | Extend = true; |
| 505 | } |
| 506 | |
| 507 | SDOperand CPIdx = DAG.getConstantPool(LLVMC, TLI.getPointerTy()); |
| 508 | if (Extend) { |
| 509 | return DAG.getExtLoad(ISD::EXTLOAD, MVT::f64, DAG.getEntryNode(), |
| 510 | CPIdx, NULL, 0, MVT::f32); |
| 511 | } else { |
| 512 | return DAG.getLoad(VT, DAG.getEntryNode(), CPIdx, NULL, 0); |
| 513 | } |
| 514 | } |
| 515 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 516 | |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 517 | /// ExpandFCOPYSIGNToBitwiseOps - Expands fcopysign to a series of bitwise |
| 518 | /// operations. |
| 519 | static |
| 520 | SDOperand ExpandFCOPYSIGNToBitwiseOps(SDNode *Node, MVT::ValueType NVT, |
| 521 | SelectionDAG &DAG, TargetLowering &TLI) { |
Evan Cheng | 068c5f4 | 2007-01-05 21:31:51 +0000 | [diff] [blame] | 522 | MVT::ValueType VT = Node->getValueType(0); |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 523 | MVT::ValueType SrcVT = Node->getOperand(1).getValueType(); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 524 | assert((SrcVT == MVT::f32 || SrcVT == MVT::f64) && |
| 525 | "fcopysign expansion only supported for f32 and f64"); |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 526 | MVT::ValueType SrcNVT = (SrcVT == MVT::f64) ? MVT::i64 : MVT::i32; |
Evan Cheng | 068c5f4 | 2007-01-05 21:31:51 +0000 | [diff] [blame] | 527 | |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 528 | // First get the sign bit of second operand. |
Evan Cheng | 068c5f4 | 2007-01-05 21:31:51 +0000 | [diff] [blame] | 529 | SDOperand Mask1 = (SrcVT == MVT::f64) |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 530 | ? DAG.getConstantFP(BitsToDouble(1ULL << 63), SrcVT) |
| 531 | : DAG.getConstantFP(BitsToFloat(1U << 31), SrcVT); |
Evan Cheng | 068c5f4 | 2007-01-05 21:31:51 +0000 | [diff] [blame] | 532 | Mask1 = DAG.getNode(ISD::BIT_CONVERT, SrcNVT, Mask1); |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 533 | SDOperand SignBit= DAG.getNode(ISD::BIT_CONVERT, SrcNVT, Node->getOperand(1)); |
Evan Cheng | 068c5f4 | 2007-01-05 21:31:51 +0000 | [diff] [blame] | 534 | SignBit = DAG.getNode(ISD::AND, SrcNVT, SignBit, Mask1); |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 535 | // Shift right or sign-extend it if the two operands have different types. |
| 536 | int SizeDiff = MVT::getSizeInBits(SrcNVT) - MVT::getSizeInBits(NVT); |
| 537 | if (SizeDiff > 0) { |
| 538 | SignBit = DAG.getNode(ISD::SRL, SrcNVT, SignBit, |
| 539 | DAG.getConstant(SizeDiff, TLI.getShiftAmountTy())); |
| 540 | SignBit = DAG.getNode(ISD::TRUNCATE, NVT, SignBit); |
| 541 | } else if (SizeDiff < 0) |
| 542 | SignBit = DAG.getNode(ISD::SIGN_EXTEND, NVT, SignBit); |
Evan Cheng | 068c5f4 | 2007-01-05 21:31:51 +0000 | [diff] [blame] | 543 | |
| 544 | // Clear the sign bit of first operand. |
| 545 | SDOperand Mask2 = (VT == MVT::f64) |
| 546 | ? DAG.getConstantFP(BitsToDouble(~(1ULL << 63)), VT) |
| 547 | : DAG.getConstantFP(BitsToFloat(~(1U << 31)), VT); |
| 548 | Mask2 = DAG.getNode(ISD::BIT_CONVERT, NVT, Mask2); |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 549 | SDOperand Result = DAG.getNode(ISD::BIT_CONVERT, NVT, Node->getOperand(0)); |
Evan Cheng | 068c5f4 | 2007-01-05 21:31:51 +0000 | [diff] [blame] | 550 | Result = DAG.getNode(ISD::AND, NVT, Result, Mask2); |
| 551 | |
| 552 | // Or the value with the sign bit. |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 553 | Result = DAG.getNode(ISD::OR, NVT, Result, SignBit); |
| 554 | return Result; |
| 555 | } |
| 556 | |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 557 | /// ExpandUnalignedStore - Expands an unaligned store to 2 half-size stores. |
| 558 | static |
| 559 | SDOperand ExpandUnalignedStore(StoreSDNode *ST, SelectionDAG &DAG, |
| 560 | TargetLowering &TLI) { |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 561 | SDOperand Chain = ST->getChain(); |
| 562 | SDOperand Ptr = ST->getBasePtr(); |
| 563 | SDOperand Val = ST->getValue(); |
| 564 | MVT::ValueType VT = Val.getValueType(); |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 565 | int Alignment = ST->getAlignment(); |
| 566 | int SVOffset = ST->getSrcValueOffset(); |
| 567 | if (MVT::isFloatingPoint(ST->getStoredVT())) { |
| 568 | // Expand to a bitconvert of the value to the integer type of the |
| 569 | // same size, then a (misaligned) int store. |
| 570 | MVT::ValueType intVT; |
| 571 | if (VT==MVT::f64) |
| 572 | intVT = MVT::i64; |
| 573 | else if (VT==MVT::f32) |
| 574 | intVT = MVT::i32; |
| 575 | else |
| 576 | assert(0 && "Unaligned load of unsupported floating point type"); |
| 577 | |
| 578 | SDOperand Result = DAG.getNode(ISD::BIT_CONVERT, intVT, Val); |
| 579 | return DAG.getStore(Chain, Result, Ptr, ST->getSrcValue(), |
| 580 | SVOffset, ST->isVolatile(), Alignment); |
| 581 | } |
| 582 | assert(MVT::isInteger(ST->getStoredVT()) && |
| 583 | "Unaligned store of unknown type."); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 584 | // Get the half-size VT |
| 585 | MVT::ValueType NewStoredVT = ST->getStoredVT() - 1; |
| 586 | int NumBits = MVT::getSizeInBits(NewStoredVT); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 587 | int IncrementSize = NumBits / 8; |
| 588 | |
| 589 | // Divide the stored value in two parts. |
| 590 | SDOperand ShiftAmount = DAG.getConstant(NumBits, TLI.getShiftAmountTy()); |
| 591 | SDOperand Lo = Val; |
| 592 | SDOperand Hi = DAG.getNode(ISD::SRL, VT, Val, ShiftAmount); |
| 593 | |
| 594 | // Store the two parts |
| 595 | SDOperand Store1, Store2; |
| 596 | Store1 = DAG.getTruncStore(Chain, TLI.isLittleEndian()?Lo:Hi, Ptr, |
| 597 | ST->getSrcValue(), SVOffset, NewStoredVT, |
| 598 | ST->isVolatile(), Alignment); |
| 599 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
| 600 | DAG.getConstant(IncrementSize, TLI.getPointerTy())); |
| 601 | Store2 = DAG.getTruncStore(Chain, TLI.isLittleEndian()?Hi:Lo, Ptr, |
| 602 | ST->getSrcValue(), SVOffset + IncrementSize, |
| 603 | NewStoredVT, ST->isVolatile(), Alignment); |
| 604 | |
| 605 | return DAG.getNode(ISD::TokenFactor, MVT::Other, Store1, Store2); |
| 606 | } |
| 607 | |
| 608 | /// ExpandUnalignedLoad - Expands an unaligned load to 2 half-size loads. |
| 609 | static |
| 610 | SDOperand ExpandUnalignedLoad(LoadSDNode *LD, SelectionDAG &DAG, |
| 611 | TargetLowering &TLI) { |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 612 | int SVOffset = LD->getSrcValueOffset(); |
| 613 | SDOperand Chain = LD->getChain(); |
| 614 | SDOperand Ptr = LD->getBasePtr(); |
| 615 | MVT::ValueType VT = LD->getValueType(0); |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 616 | MVT::ValueType LoadedVT = LD->getLoadedVT(); |
| 617 | if (MVT::isFloatingPoint(VT)) { |
| 618 | // Expand to a (misaligned) integer load of the same size, |
| 619 | // then bitconvert to floating point. |
| 620 | MVT::ValueType intVT; |
| 621 | if (LoadedVT==MVT::f64) |
| 622 | intVT = MVT::i64; |
| 623 | else if (LoadedVT==MVT::f32) |
| 624 | intVT = MVT::i32; |
| 625 | else |
| 626 | assert(0 && "Unaligned load of unsupported floating point type"); |
| 627 | |
| 628 | SDOperand newLoad = DAG.getLoad(intVT, Chain, Ptr, LD->getSrcValue(), |
| 629 | SVOffset, LD->isVolatile(), |
| 630 | LD->getAlignment()); |
| 631 | SDOperand Result = DAG.getNode(ISD::BIT_CONVERT, LoadedVT, newLoad); |
| 632 | if (LoadedVT != VT) |
| 633 | Result = DAG.getNode(ISD::FP_EXTEND, VT, Result); |
| 634 | |
| 635 | SDOperand Ops[] = { Result, Chain }; |
| 636 | return DAG.getNode(ISD::MERGE_VALUES, DAG.getVTList(VT, MVT::Other), |
| 637 | Ops, 2); |
| 638 | } |
| 639 | assert(MVT::isInteger(LoadedVT) && "Unaligned load of unsupported type."); |
| 640 | MVT::ValueType NewLoadedVT = LoadedVT - 1; |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 641 | int NumBits = MVT::getSizeInBits(NewLoadedVT); |
| 642 | int Alignment = LD->getAlignment(); |
| 643 | int IncrementSize = NumBits / 8; |
| 644 | ISD::LoadExtType HiExtType = LD->getExtensionType(); |
| 645 | |
| 646 | // If the original load is NON_EXTLOAD, the hi part load must be ZEXTLOAD. |
| 647 | if (HiExtType == ISD::NON_EXTLOAD) |
| 648 | HiExtType = ISD::ZEXTLOAD; |
| 649 | |
| 650 | // Load the value in two parts |
| 651 | SDOperand Lo, Hi; |
| 652 | if (TLI.isLittleEndian()) { |
| 653 | Lo = DAG.getExtLoad(ISD::ZEXTLOAD, VT, Chain, Ptr, LD->getSrcValue(), |
| 654 | SVOffset, NewLoadedVT, LD->isVolatile(), Alignment); |
| 655 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
| 656 | DAG.getConstant(IncrementSize, TLI.getPointerTy())); |
| 657 | Hi = DAG.getExtLoad(HiExtType, VT, Chain, Ptr, LD->getSrcValue(), |
| 658 | SVOffset + IncrementSize, NewLoadedVT, LD->isVolatile(), |
| 659 | Alignment); |
| 660 | } else { |
| 661 | Hi = DAG.getExtLoad(HiExtType, VT, Chain, Ptr, LD->getSrcValue(), SVOffset, |
| 662 | NewLoadedVT,LD->isVolatile(), Alignment); |
| 663 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
| 664 | DAG.getConstant(IncrementSize, TLI.getPointerTy())); |
| 665 | Lo = DAG.getExtLoad(ISD::ZEXTLOAD, VT, Chain, Ptr, LD->getSrcValue(), |
| 666 | SVOffset + IncrementSize, NewLoadedVT, LD->isVolatile(), |
| 667 | Alignment); |
| 668 | } |
| 669 | |
| 670 | // aggregate the two parts |
| 671 | SDOperand ShiftAmount = DAG.getConstant(NumBits, TLI.getShiftAmountTy()); |
| 672 | SDOperand Result = DAG.getNode(ISD::SHL, VT, Hi, ShiftAmount); |
| 673 | Result = DAG.getNode(ISD::OR, VT, Result, Lo); |
| 674 | |
| 675 | SDOperand TF = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1), |
| 676 | Hi.getValue(1)); |
| 677 | |
| 678 | SDOperand Ops[] = { Result, TF }; |
| 679 | return DAG.getNode(ISD::MERGE_VALUES, DAG.getVTList(VT, MVT::Other), Ops, 2); |
| 680 | } |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 681 | |
Dan Gohman | a346615 | 2007-07-13 20:14:11 +0000 | [diff] [blame] | 682 | /// LegalizeOp - We know that the specified value has a legal type, and |
| 683 | /// that its operands are legal. Now ensure that the operation itself |
| 684 | /// is legal, recursively ensuring that the operands' operations remain |
| 685 | /// legal. |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 686 | SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) { |
Chris Lattner | 09ec1b0 | 2007-08-25 01:00:22 +0000 | [diff] [blame] | 687 | if (Op.getOpcode() == ISD::TargetConstant) // Allow illegal target nodes. |
| 688 | return Op; |
| 689 | |
Chris Lattner | c9c60f6 | 2005-08-24 16:35:28 +0000 | [diff] [blame] | 690 | assert(isTypeLegal(Op.getValueType()) && |
Chris Lattner | e3304a3 | 2005-01-08 20:35:13 +0000 | [diff] [blame] | 691 | "Caller should expand or promote operands that are not legal!"); |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 692 | SDNode *Node = Op.Val; |
Chris Lattner | e3304a3 | 2005-01-08 20:35:13 +0000 | [diff] [blame] | 693 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 694 | // If this operation defines any values that cannot be represented in a |
Chris Lattner | e3304a3 | 2005-01-08 20:35:13 +0000 | [diff] [blame] | 695 | // register on this target, make sure to expand or promote them. |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 696 | if (Node->getNumValues() > 1) { |
| 697 | for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 698 | if (getTypeAction(Node->getValueType(i)) != Legal) { |
| 699 | HandleOp(Op.getValue(i)); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 700 | assert(LegalizedNodes.count(Op) && |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 701 | "Handling didn't add legal operands!"); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 702 | return LegalizedNodes[Op]; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 703 | } |
| 704 | } |
| 705 | |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 706 | // Note that LegalizeOp may be reentered even from single-use nodes, which |
| 707 | // means that we always must cache transformed nodes. |
Chris Lattner | 718071c | 2007-02-04 00:50:02 +0000 | [diff] [blame] | 708 | DenseMap<SDOperand, SDOperand>::iterator I = LegalizedNodes.find(Op); |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 709 | if (I != LegalizedNodes.end()) return I->second; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 710 | |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 711 | SDOperand Tmp1, Tmp2, Tmp3, Tmp4; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 712 | SDOperand Result = Op; |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 713 | bool isCustom = false; |
| 714 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 715 | switch (Node->getOpcode()) { |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 716 | case ISD::FrameIndex: |
| 717 | case ISD::EntryToken: |
| 718 | case ISD::Register: |
| 719 | case ISD::BasicBlock: |
| 720 | case ISD::TargetFrameIndex: |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 721 | case ISD::TargetJumpTable: |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 722 | case ISD::TargetConstant: |
Chris Lattner | 3181a77 | 2006-01-29 06:26:56 +0000 | [diff] [blame] | 723 | case ISD::TargetConstantFP: |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 724 | case ISD::TargetConstantPool: |
| 725 | case ISD::TargetGlobalAddress: |
Lauro Ramos Venancio | b3a0417 | 2007-04-20 21:38:10 +0000 | [diff] [blame] | 726 | case ISD::TargetGlobalTLSAddress: |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 727 | case ISD::TargetExternalSymbol: |
| 728 | case ISD::VALUETYPE: |
| 729 | case ISD::SRCVALUE: |
| 730 | case ISD::STRING: |
| 731 | case ISD::CONDCODE: |
| 732 | // Primitives must all be legal. |
| 733 | assert(TLI.isOperationLegal(Node->getValueType(0), Node->getValueType(0)) && |
| 734 | "This must be legal!"); |
| 735 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 736 | default: |
Chris Lattner | d73cc5d | 2005-05-14 06:34:48 +0000 | [diff] [blame] | 737 | if (Node->getOpcode() >= ISD::BUILTIN_OP_END) { |
| 738 | // If this is a target node, legalize it by legalizing the operands then |
| 739 | // passing it through. |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 740 | SmallVector<SDOperand, 8> Ops; |
Chris Lattner | c5d7d7c | 2006-05-17 18:00:08 +0000 | [diff] [blame] | 741 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) |
Chris Lattner | d73cc5d | 2005-05-14 06:34:48 +0000 | [diff] [blame] | 742 | Ops.push_back(LegalizeOp(Node->getOperand(i))); |
Chris Lattner | c5d7d7c | 2006-05-17 18:00:08 +0000 | [diff] [blame] | 743 | |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 744 | Result = DAG.UpdateNodeOperands(Result.getValue(0), &Ops[0], Ops.size()); |
Chris Lattner | d73cc5d | 2005-05-14 06:34:48 +0000 | [diff] [blame] | 745 | |
| 746 | for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) |
| 747 | AddLegalizedOperand(Op.getValue(i), Result.getValue(i)); |
| 748 | return Result.getValue(Op.ResNo); |
| 749 | } |
| 750 | // Otherwise this is an unhandled builtin node. splat. |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 751 | #ifndef NDEBUG |
Dan Gohman | 3983358 | 2007-06-04 16:17:33 +0000 | [diff] [blame] | 752 | cerr << "NODE: "; Node->dump(&DAG); cerr << "\n"; |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 753 | #endif |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 754 | assert(0 && "Do not know how to legalize this operator!"); |
| 755 | abort(); |
Lauro Ramos Venancio | 0d3b678 | 2007-04-20 23:02:39 +0000 | [diff] [blame] | 756 | case ISD::GLOBAL_OFFSET_TABLE: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 757 | case ISD::GlobalAddress: |
Lauro Ramos Venancio | b3a0417 | 2007-04-20 21:38:10 +0000 | [diff] [blame] | 758 | case ISD::GlobalTLSAddress: |
Chris Lattner | 03c0cf8 | 2005-01-07 21:45:56 +0000 | [diff] [blame] | 759 | case ISD::ExternalSymbol: |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 760 | case ISD::ConstantPool: |
| 761 | case ISD::JumpTable: // Nothing to do. |
Chris Lattner | 0c8fbe3 | 2005-11-17 06:41:44 +0000 | [diff] [blame] | 762 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 763 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 764 | case TargetLowering::Custom: |
| 765 | Tmp1 = TLI.LowerOperation(Op, DAG); |
| 766 | if (Tmp1.Val) Result = Tmp1; |
| 767 | // FALLTHROUGH if the target doesn't want to lower this op after all. |
Chris Lattner | 0c8fbe3 | 2005-11-17 06:41:44 +0000 | [diff] [blame] | 768 | case TargetLowering::Legal: |
Chris Lattner | 0c8fbe3 | 2005-11-17 06:41:44 +0000 | [diff] [blame] | 769 | break; |
| 770 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 771 | break; |
Nate Begeman | bcc5f36 | 2007-01-29 22:58:52 +0000 | [diff] [blame] | 772 | case ISD::FRAMEADDR: |
| 773 | case ISD::RETURNADDR: |
| 774 | // The only option for these nodes is to custom lower them. If the target |
| 775 | // does not custom lower them, then return zero. |
| 776 | Tmp1 = TLI.LowerOperation(Op, DAG); |
| 777 | if (Tmp1.Val) |
| 778 | Result = Tmp1; |
| 779 | else |
| 780 | Result = DAG.getConstant(0, TLI.getPointerTy()); |
| 781 | break; |
Anton Korobeynikov | 055c544 | 2007-08-29 23:18:48 +0000 | [diff] [blame] | 782 | case ISD::FRAME_TO_ARGS_OFFSET: { |
Anton Korobeynikov | 066f7b4 | 2007-08-29 19:28:29 +0000 | [diff] [blame] | 783 | MVT::ValueType VT = Node->getValueType(0); |
| 784 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 785 | default: assert(0 && "This action is not supported yet!"); |
| 786 | case TargetLowering::Custom: |
| 787 | Result = TLI.LowerOperation(Op, DAG); |
| 788 | if (Result.Val) break; |
| 789 | // Fall Thru |
| 790 | case TargetLowering::Legal: |
| 791 | Result = DAG.getConstant(0, VT); |
| 792 | break; |
| 793 | } |
Anton Korobeynikov | 055c544 | 2007-08-29 23:18:48 +0000 | [diff] [blame] | 794 | } |
Anton Korobeynikov | 066f7b4 | 2007-08-29 19:28:29 +0000 | [diff] [blame] | 795 | break; |
Jim Laskey | 2bc210d | 2007-02-22 15:37:19 +0000 | [diff] [blame] | 796 | case ISD::EXCEPTIONADDR: { |
| 797 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 798 | MVT::ValueType VT = Node->getValueType(0); |
| 799 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 800 | default: assert(0 && "This action is not supported yet!"); |
| 801 | case TargetLowering::Expand: { |
Jim Laskey | 8782d48 | 2007-02-28 20:43:58 +0000 | [diff] [blame] | 802 | unsigned Reg = TLI.getExceptionAddressRegister(); |
Jim Laskey | 2bc210d | 2007-02-22 15:37:19 +0000 | [diff] [blame] | 803 | Result = DAG.getCopyFromReg(Tmp1, Reg, VT).getValue(Op.ResNo); |
| 804 | } |
| 805 | break; |
| 806 | case TargetLowering::Custom: |
| 807 | Result = TLI.LowerOperation(Op, DAG); |
| 808 | if (Result.Val) break; |
| 809 | // Fall Thru |
Chris Lattner | eb7f34f | 2007-04-27 17:12:52 +0000 | [diff] [blame] | 810 | case TargetLowering::Legal: { |
| 811 | SDOperand Ops[] = { DAG.getConstant(0, VT), Tmp1 }; |
| 812 | Result = DAG.getNode(ISD::MERGE_VALUES, DAG.getVTList(VT, MVT::Other), |
| 813 | Ops, 2).getValue(Op.ResNo); |
Jim Laskey | 2bc210d | 2007-02-22 15:37:19 +0000 | [diff] [blame] | 814 | break; |
| 815 | } |
| 816 | } |
Chris Lattner | eb7f34f | 2007-04-27 17:12:52 +0000 | [diff] [blame] | 817 | } |
Jim Laskey | 2bc210d | 2007-02-22 15:37:19 +0000 | [diff] [blame] | 818 | break; |
Jim Laskey | 8782d48 | 2007-02-28 20:43:58 +0000 | [diff] [blame] | 819 | case ISD::EHSELECTION: { |
| 820 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 821 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 822 | MVT::ValueType VT = Node->getValueType(0); |
| 823 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 824 | default: assert(0 && "This action is not supported yet!"); |
| 825 | case TargetLowering::Expand: { |
| 826 | unsigned Reg = TLI.getExceptionSelectorRegister(); |
| 827 | Result = DAG.getCopyFromReg(Tmp2, Reg, VT).getValue(Op.ResNo); |
| 828 | } |
| 829 | break; |
| 830 | case TargetLowering::Custom: |
| 831 | Result = TLI.LowerOperation(Op, DAG); |
| 832 | if (Result.Val) break; |
| 833 | // Fall Thru |
Chris Lattner | eb7f34f | 2007-04-27 17:12:52 +0000 | [diff] [blame] | 834 | case TargetLowering::Legal: { |
| 835 | SDOperand Ops[] = { DAG.getConstant(0, VT), Tmp2 }; |
| 836 | Result = DAG.getNode(ISD::MERGE_VALUES, DAG.getVTList(VT, MVT::Other), |
| 837 | Ops, 2).getValue(Op.ResNo); |
Jim Laskey | 8782d48 | 2007-02-28 20:43:58 +0000 | [diff] [blame] | 838 | break; |
| 839 | } |
| 840 | } |
Chris Lattner | eb7f34f | 2007-04-27 17:12:52 +0000 | [diff] [blame] | 841 | } |
Jim Laskey | 8782d48 | 2007-02-28 20:43:58 +0000 | [diff] [blame] | 842 | break; |
Nick Lewycky | 6d4b711 | 2007-07-14 15:11:14 +0000 | [diff] [blame] | 843 | case ISD::EH_RETURN: { |
Anton Korobeynikov | 2365f51 | 2007-07-14 14:06:15 +0000 | [diff] [blame] | 844 | MVT::ValueType VT = Node->getValueType(0); |
| 845 | // The only "good" option for this node is to custom lower it. |
| 846 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 847 | default: assert(0 && "This action is not supported at all!"); |
| 848 | case TargetLowering::Custom: |
| 849 | Result = TLI.LowerOperation(Op, DAG); |
| 850 | if (Result.Val) break; |
| 851 | // Fall Thru |
| 852 | case TargetLowering::Legal: |
| 853 | // Target does not know, how to lower this, lower to noop |
| 854 | Result = LegalizeOp(Node->getOperand(0)); |
| 855 | break; |
| 856 | } |
Nick Lewycky | 6d4b711 | 2007-07-14 15:11:14 +0000 | [diff] [blame] | 857 | } |
Anton Korobeynikov | 2365f51 | 2007-07-14 14:06:15 +0000 | [diff] [blame] | 858 | break; |
Chris Lattner | 08951a3 | 2005-09-02 01:15:01 +0000 | [diff] [blame] | 859 | case ISD::AssertSext: |
| 860 | case ISD::AssertZext: |
| 861 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 862 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
Chris Lattner | 08951a3 | 2005-09-02 01:15:01 +0000 | [diff] [blame] | 863 | break; |
Chris Lattner | 308575b | 2005-11-20 22:56:56 +0000 | [diff] [blame] | 864 | case ISD::MERGE_VALUES: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 865 | // Legalize eliminates MERGE_VALUES nodes. |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 866 | Result = Node->getOperand(Op.ResNo); |
| 867 | break; |
Chris Lattner | 69a5215 | 2005-01-14 22:38:01 +0000 | [diff] [blame] | 868 | case ISD::CopyFromReg: |
| 869 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 870 | Result = Op.getValue(0); |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 871 | if (Node->getNumValues() == 2) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 872 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 873 | } else { |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 874 | assert(Node->getNumValues() == 3 && "Invalid copyfromreg!"); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 875 | if (Node->getNumOperands() == 3) { |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 876 | Tmp2 = LegalizeOp(Node->getOperand(2)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 877 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1),Tmp2); |
| 878 | } else { |
| 879 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
| 880 | } |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 881 | AddLegalizedOperand(Op.getValue(2), Result.getValue(2)); |
| 882 | } |
Chris Lattner | 13c184d | 2005-01-28 06:27:38 +0000 | [diff] [blame] | 883 | // Since CopyFromReg produces two values, make sure to remember that we |
| 884 | // legalized both of them. |
| 885 | AddLegalizedOperand(Op.getValue(0), Result); |
| 886 | AddLegalizedOperand(Op.getValue(1), Result.getValue(1)); |
| 887 | return Result.getValue(Op.ResNo); |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 888 | case ISD::UNDEF: { |
| 889 | MVT::ValueType VT = Op.getValueType(); |
| 890 | switch (TLI.getOperationAction(ISD::UNDEF, VT)) { |
Nate Begeman | ea19cd5 | 2005-04-02 00:41:14 +0000 | [diff] [blame] | 891 | default: assert(0 && "This action is not supported yet!"); |
| 892 | case TargetLowering::Expand: |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 893 | if (MVT::isInteger(VT)) |
| 894 | Result = DAG.getConstant(0, VT); |
| 895 | else if (MVT::isFloatingPoint(VT)) |
| 896 | Result = DAG.getConstantFP(0, VT); |
| 897 | else |
| 898 | assert(0 && "Unknown value type!"); |
| 899 | break; |
Nate Begeman | ea19cd5 | 2005-04-02 00:41:14 +0000 | [diff] [blame] | 900 | case TargetLowering::Legal: |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 901 | break; |
| 902 | } |
| 903 | break; |
| 904 | } |
Chris Lattner | d1f04d4 | 2006-03-24 02:26:29 +0000 | [diff] [blame] | 905 | |
Chris Lattner | 48b61a7 | 2006-03-28 00:40:33 +0000 | [diff] [blame] | 906 | case ISD::INTRINSIC_W_CHAIN: |
| 907 | case ISD::INTRINSIC_WO_CHAIN: |
| 908 | case ISD::INTRINSIC_VOID: { |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 909 | SmallVector<SDOperand, 8> Ops; |
Chris Lattner | d1f04d4 | 2006-03-24 02:26:29 +0000 | [diff] [blame] | 910 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) |
| 911 | Ops.push_back(LegalizeOp(Node->getOperand(i))); |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 912 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 10d7fa6 | 2006-03-26 09:12:51 +0000 | [diff] [blame] | 913 | |
| 914 | // Allow the target to custom lower its intrinsics if it wants to. |
Chris Lattner | 48b61a7 | 2006-03-28 00:40:33 +0000 | [diff] [blame] | 915 | if (TLI.getOperationAction(Node->getOpcode(), MVT::Other) == |
Chris Lattner | 10d7fa6 | 2006-03-26 09:12:51 +0000 | [diff] [blame] | 916 | TargetLowering::Custom) { |
| 917 | Tmp3 = TLI.LowerOperation(Result, DAG); |
| 918 | if (Tmp3.Val) Result = Tmp3; |
Chris Lattner | 13fc2f1 | 2006-03-27 20:28:29 +0000 | [diff] [blame] | 919 | } |
| 920 | |
| 921 | if (Result.Val->getNumValues() == 1) break; |
| 922 | |
| 923 | // Must have return value and chain result. |
| 924 | assert(Result.Val->getNumValues() == 2 && |
| 925 | "Cannot return more than two values!"); |
| 926 | |
| 927 | // Since loads produce two values, make sure to remember that we |
| 928 | // legalized both of them. |
| 929 | AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0)); |
| 930 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
| 931 | return Result.getValue(Op.ResNo); |
Chris Lattner | d1f04d4 | 2006-03-24 02:26:29 +0000 | [diff] [blame] | 932 | } |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 933 | |
| 934 | case ISD::LOCATION: |
| 935 | assert(Node->getNumOperands() == 5 && "Invalid LOCATION node!"); |
| 936 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the input chain. |
| 937 | |
| 938 | switch (TLI.getOperationAction(ISD::LOCATION, MVT::Other)) { |
| 939 | case TargetLowering::Promote: |
| 940 | default: assert(0 && "This action is not supported yet!"); |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 941 | case TargetLowering::Expand: { |
Jim Laskey | 44c3b9f | 2007-01-26 21:22:28 +0000 | [diff] [blame] | 942 | MachineModuleInfo *MMI = DAG.getMachineModuleInfo(); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 943 | bool useDEBUG_LOC = TLI.isOperationLegal(ISD::DEBUG_LOC, MVT::Other); |
Jim Laskey | 1ee2925 | 2007-01-26 14:34:52 +0000 | [diff] [blame] | 944 | bool useLABEL = TLI.isOperationLegal(ISD::LABEL, MVT::Other); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 945 | |
Jim Laskey | 44c3b9f | 2007-01-26 21:22:28 +0000 | [diff] [blame] | 946 | if (MMI && (useDEBUG_LOC || useLABEL)) { |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 947 | const std::string &FName = |
| 948 | cast<StringSDNode>(Node->getOperand(3))->getValue(); |
| 949 | const std::string &DirName = |
| 950 | cast<StringSDNode>(Node->getOperand(4))->getValue(); |
Jim Laskey | 44c3b9f | 2007-01-26 21:22:28 +0000 | [diff] [blame] | 951 | unsigned SrcFile = MMI->RecordSource(DirName, FName); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 952 | |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 953 | SmallVector<SDOperand, 8> Ops; |
Jim Laskey | e81aecb | 2005-12-21 20:51:37 +0000 | [diff] [blame] | 954 | Ops.push_back(Tmp1); // chain |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 955 | SDOperand LineOp = Node->getOperand(1); |
| 956 | SDOperand ColOp = Node->getOperand(2); |
| 957 | |
| 958 | if (useDEBUG_LOC) { |
| 959 | Ops.push_back(LineOp); // line # |
| 960 | Ops.push_back(ColOp); // col # |
| 961 | Ops.push_back(DAG.getConstant(SrcFile, MVT::i32)); // source file id |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 962 | Result = DAG.getNode(ISD::DEBUG_LOC, MVT::Other, &Ops[0], Ops.size()); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 963 | } else { |
Jim Laskey | d0e58e3 | 2006-02-15 19:34:44 +0000 | [diff] [blame] | 964 | unsigned Line = cast<ConstantSDNode>(LineOp)->getValue(); |
| 965 | unsigned Col = cast<ConstantSDNode>(ColOp)->getValue(); |
Jim Laskey | 44c3b9f | 2007-01-26 21:22:28 +0000 | [diff] [blame] | 966 | unsigned ID = MMI->RecordLabel(Line, Col, SrcFile); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 967 | Ops.push_back(DAG.getConstant(ID, MVT::i32)); |
Jim Laskey | 1ee2925 | 2007-01-26 14:34:52 +0000 | [diff] [blame] | 968 | Result = DAG.getNode(ISD::LABEL, MVT::Other,&Ops[0],Ops.size()); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 969 | } |
Jim Laskey | e81aecb | 2005-12-21 20:51:37 +0000 | [diff] [blame] | 970 | } else { |
| 971 | Result = Tmp1; // chain |
| 972 | } |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 973 | break; |
Chris Lattner | e773673 | 2005-12-18 23:54:29 +0000 | [diff] [blame] | 974 | } |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 975 | case TargetLowering::Legal: |
Chris Lattner | 9ad17c9 | 2005-12-01 18:21:35 +0000 | [diff] [blame] | 976 | if (Tmp1 != Node->getOperand(0) || |
| 977 | getTypeAction(Node->getOperand(1).getValueType()) == Promote) { |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 978 | SmallVector<SDOperand, 8> Ops; |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 979 | Ops.push_back(Tmp1); |
Chris Lattner | 9ad17c9 | 2005-12-01 18:21:35 +0000 | [diff] [blame] | 980 | if (getTypeAction(Node->getOperand(1).getValueType()) == Legal) { |
| 981 | Ops.push_back(Node->getOperand(1)); // line # must be legal. |
| 982 | Ops.push_back(Node->getOperand(2)); // col # must be legal. |
| 983 | } else { |
| 984 | // Otherwise promote them. |
| 985 | Ops.push_back(PromoteOp(Node->getOperand(1))); |
| 986 | Ops.push_back(PromoteOp(Node->getOperand(2))); |
| 987 | } |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 988 | Ops.push_back(Node->getOperand(3)); // filename must be legal. |
| 989 | Ops.push_back(Node->getOperand(4)); // working dir # must be legal. |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 990 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 991 | } |
| 992 | break; |
| 993 | } |
| 994 | break; |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 995 | |
| 996 | case ISD::DEBUG_LOC: |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 997 | assert(Node->getNumOperands() == 4 && "Invalid DEBUG_LOC node!"); |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 998 | switch (TLI.getOperationAction(ISD::DEBUG_LOC, MVT::Other)) { |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 999 | default: assert(0 && "This action is not supported yet!"); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1000 | case TargetLowering::Legal: |
| 1001 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1002 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the line #. |
| 1003 | Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the col #. |
| 1004 | Tmp4 = LegalizeOp(Node->getOperand(3)); // Legalize the source file id. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1005 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3, Tmp4); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1006 | break; |
| 1007 | } |
| 1008 | break; |
| 1009 | |
Jim Laskey | 1ee2925 | 2007-01-26 14:34:52 +0000 | [diff] [blame] | 1010 | case ISD::LABEL: |
| 1011 | assert(Node->getNumOperands() == 2 && "Invalid LABEL node!"); |
| 1012 | switch (TLI.getOperationAction(ISD::LABEL, MVT::Other)) { |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1013 | default: assert(0 && "This action is not supported yet!"); |
| 1014 | case TargetLowering::Legal: |
| 1015 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1016 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the label id. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1017 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 1018 | break; |
Chris Lattner | a9569f1 | 2007-03-03 19:21:38 +0000 | [diff] [blame] | 1019 | case TargetLowering::Expand: |
| 1020 | Result = LegalizeOp(Node->getOperand(0)); |
| 1021 | break; |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 1022 | } |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 1023 | break; |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 1024 | |
Scott Michel | c1513d2 | 2007-08-08 23:23:31 +0000 | [diff] [blame] | 1025 | case ISD::Constant: { |
| 1026 | ConstantSDNode *CN = cast<ConstantSDNode>(Node); |
| 1027 | unsigned opAction = |
| 1028 | TLI.getOperationAction(ISD::Constant, CN->getValueType(0)); |
| 1029 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1030 | // We know we don't need to expand constants here, constants only have one |
| 1031 | // value and we check that it is fine above. |
| 1032 | |
Scott Michel | c1513d2 | 2007-08-08 23:23:31 +0000 | [diff] [blame] | 1033 | if (opAction == TargetLowering::Custom) { |
| 1034 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 1035 | if (Tmp1.Val) |
| 1036 | Result = Tmp1; |
| 1037 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1038 | break; |
Scott Michel | c1513d2 | 2007-08-08 23:23:31 +0000 | [diff] [blame] | 1039 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1040 | case ISD::ConstantFP: { |
| 1041 | // Spill FP immediates to the constant pool if the target cannot directly |
| 1042 | // codegen them. Targets often have some immediate values that can be |
| 1043 | // efficiently generated into an FP register without a load. We explicitly |
| 1044 | // leave these constants as ConstantFP nodes for the target to deal with. |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1045 | ConstantFPSDNode *CFP = cast<ConstantFPSDNode>(Node); |
| 1046 | |
| 1047 | // Check to see if this FP immediate is already legal. |
| 1048 | bool isLegal = false; |
| 1049 | for (TargetLowering::legal_fpimm_iterator I = TLI.legal_fpimm_begin(), |
| 1050 | E = TLI.legal_fpimm_end(); I != E; ++I) |
| 1051 | if (CFP->isExactlyValue(*I)) { |
| 1052 | isLegal = true; |
| 1053 | break; |
| 1054 | } |
| 1055 | |
Chris Lattner | 3181a77 | 2006-01-29 06:26:56 +0000 | [diff] [blame] | 1056 | // If this is a legal constant, turn it into a TargetConstantFP node. |
| 1057 | if (isLegal) { |
Dale Johannesen | f04afdb | 2007-08-30 00:23:21 +0000 | [diff] [blame] | 1058 | Result = DAG.getTargetConstantFP(CFP->getValueAPF(), |
| 1059 | CFP->getValueType(0)); |
Chris Lattner | 3181a77 | 2006-01-29 06:26:56 +0000 | [diff] [blame] | 1060 | break; |
| 1061 | } |
| 1062 | |
| 1063 | switch (TLI.getOperationAction(ISD::ConstantFP, CFP->getValueType(0))) { |
| 1064 | default: assert(0 && "This action is not supported yet!"); |
| 1065 | case TargetLowering::Custom: |
| 1066 | Tmp3 = TLI.LowerOperation(Result, DAG); |
| 1067 | if (Tmp3.Val) { |
| 1068 | Result = Tmp3; |
| 1069 | break; |
| 1070 | } |
| 1071 | // FALLTHROUGH |
| 1072 | case TargetLowering::Expand: |
Evan Cheng | 279101e | 2006-12-12 22:19:28 +0000 | [diff] [blame] | 1073 | Result = ExpandConstantFP(CFP, true, DAG, TLI); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1074 | } |
| 1075 | break; |
| 1076 | } |
Chris Lattner | 040c11c | 2005-11-09 18:48:57 +0000 | [diff] [blame] | 1077 | case ISD::TokenFactor: |
| 1078 | if (Node->getNumOperands() == 2) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1079 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1080 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1081 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 1082 | } else if (Node->getNumOperands() == 3) { |
| 1083 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1084 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1085 | Tmp3 = LegalizeOp(Node->getOperand(2)); |
| 1086 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | 040c11c | 2005-11-09 18:48:57 +0000 | [diff] [blame] | 1087 | } else { |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1088 | SmallVector<SDOperand, 8> Ops; |
Chris Lattner | 040c11c | 2005-11-09 18:48:57 +0000 | [diff] [blame] | 1089 | // Legalize the operands. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1090 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) |
| 1091 | Ops.push_back(LegalizeOp(Node->getOperand(i))); |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1092 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | a385e9b | 2005-01-13 17:59:25 +0000 | [diff] [blame] | 1093 | } |
Chris Lattner | a385e9b | 2005-01-13 17:59:25 +0000 | [diff] [blame] | 1094 | break; |
Chris Lattner | fdfded5 | 2006-04-12 16:20:43 +0000 | [diff] [blame] | 1095 | |
| 1096 | case ISD::FORMAL_ARGUMENTS: |
Chris Lattner | f4ec817 | 2006-05-16 22:53:20 +0000 | [diff] [blame] | 1097 | case ISD::CALL: |
Chris Lattner | fdfded5 | 2006-04-12 16:20:43 +0000 | [diff] [blame] | 1098 | // The only option for this is to custom lower it. |
Chris Lattner | b248e16 | 2006-05-17 17:55:45 +0000 | [diff] [blame] | 1099 | Tmp3 = TLI.LowerOperation(Result.getValue(0), DAG); |
| 1100 | assert(Tmp3.Val && "Target didn't custom lower this node!"); |
| 1101 | assert(Tmp3.Val->getNumValues() == Result.Val->getNumValues() && |
| 1102 | "Lowering call/formal_arguments produced unexpected # results!"); |
Chris Lattner | e2e4173 | 2006-05-16 05:49:56 +0000 | [diff] [blame] | 1103 | |
Chris Lattner | f4ec817 | 2006-05-16 22:53:20 +0000 | [diff] [blame] | 1104 | // Since CALL/FORMAL_ARGUMENTS nodes produce multiple values, make sure to |
Chris Lattner | e2e4173 | 2006-05-16 05:49:56 +0000 | [diff] [blame] | 1105 | // remember that we legalized all of them, so it doesn't get relegalized. |
Chris Lattner | b248e16 | 2006-05-17 17:55:45 +0000 | [diff] [blame] | 1106 | for (unsigned i = 0, e = Tmp3.Val->getNumValues(); i != e; ++i) { |
| 1107 | Tmp1 = LegalizeOp(Tmp3.getValue(i)); |
Chris Lattner | e2e4173 | 2006-05-16 05:49:56 +0000 | [diff] [blame] | 1108 | if (Op.ResNo == i) |
| 1109 | Tmp2 = Tmp1; |
| 1110 | AddLegalizedOperand(SDOperand(Node, i), Tmp1); |
| 1111 | } |
| 1112 | return Tmp2; |
Christopher Lamb | 557c363 | 2007-07-26 07:34:40 +0000 | [diff] [blame] | 1113 | case ISD::EXTRACT_SUBREG: { |
| 1114 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1115 | ConstantSDNode *idx = dyn_cast<ConstantSDNode>(Node->getOperand(1)); |
| 1116 | assert(idx && "Operand must be a constant"); |
| 1117 | Tmp2 = DAG.getTargetConstant(idx->getValue(), idx->getValueType(0)); |
| 1118 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 1119 | } |
| 1120 | break; |
| 1121 | case ISD::INSERT_SUBREG: { |
| 1122 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1123 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1124 | ConstantSDNode *idx = dyn_cast<ConstantSDNode>(Node->getOperand(2)); |
| 1125 | assert(idx && "Operand must be a constant"); |
| 1126 | Tmp3 = DAG.getTargetConstant(idx->getValue(), idx->getValueType(0)); |
| 1127 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
| 1128 | } |
| 1129 | break; |
Chris Lattner | b2827b0 | 2006-03-19 00:52:58 +0000 | [diff] [blame] | 1130 | case ISD::BUILD_VECTOR: |
| 1131 | switch (TLI.getOperationAction(ISD::BUILD_VECTOR, Node->getValueType(0))) { |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1132 | default: assert(0 && "This action is not supported yet!"); |
| 1133 | case TargetLowering::Custom: |
| 1134 | Tmp3 = TLI.LowerOperation(Result, DAG); |
| 1135 | if (Tmp3.Val) { |
| 1136 | Result = Tmp3; |
| 1137 | break; |
| 1138 | } |
| 1139 | // FALLTHROUGH |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 1140 | case TargetLowering::Expand: |
| 1141 | Result = ExpandBUILD_VECTOR(Result.Val); |
Chris Lattner | b2827b0 | 2006-03-19 00:52:58 +0000 | [diff] [blame] | 1142 | break; |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1143 | } |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1144 | break; |
| 1145 | case ISD::INSERT_VECTOR_ELT: |
| 1146 | Tmp1 = LegalizeOp(Node->getOperand(0)); // InVec |
| 1147 | Tmp2 = LegalizeOp(Node->getOperand(1)); // InVal |
| 1148 | Tmp3 = LegalizeOp(Node->getOperand(2)); // InEltNo |
| 1149 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
| 1150 | |
| 1151 | switch (TLI.getOperationAction(ISD::INSERT_VECTOR_ELT, |
| 1152 | Node->getValueType(0))) { |
| 1153 | default: assert(0 && "This action is not supported yet!"); |
| 1154 | case TargetLowering::Legal: |
| 1155 | break; |
| 1156 | case TargetLowering::Custom: |
| 1157 | Tmp3 = TLI.LowerOperation(Result, DAG); |
| 1158 | if (Tmp3.Val) { |
| 1159 | Result = Tmp3; |
| 1160 | break; |
| 1161 | } |
| 1162 | // FALLTHROUGH |
| 1163 | case TargetLowering::Expand: { |
Chris Lattner | 8d5a894 | 2006-04-17 19:21:01 +0000 | [diff] [blame] | 1164 | // If the insert index is a constant, codegen this as a scalar_to_vector, |
| 1165 | // then a shuffle that inserts it into the right position in the vector. |
| 1166 | if (ConstantSDNode *InsertPos = dyn_cast<ConstantSDNode>(Tmp3)) { |
| 1167 | SDOperand ScVec = DAG.getNode(ISD::SCALAR_TO_VECTOR, |
| 1168 | Tmp1.getValueType(), Tmp2); |
| 1169 | |
| 1170 | unsigned NumElts = MVT::getVectorNumElements(Tmp1.getValueType()); |
| 1171 | MVT::ValueType ShufMaskVT = MVT::getIntVectorWithNumElements(NumElts); |
Dan Gohman | 51eaa86 | 2007-06-14 22:58:02 +0000 | [diff] [blame] | 1172 | MVT::ValueType ShufMaskEltVT = MVT::getVectorElementType(ShufMaskVT); |
Chris Lattner | 8d5a894 | 2006-04-17 19:21:01 +0000 | [diff] [blame] | 1173 | |
| 1174 | // We generate a shuffle of InVec and ScVec, so the shuffle mask should |
| 1175 | // be 0,1,2,3,4,5... with the appropriate element replaced with elt 0 of |
| 1176 | // the RHS. |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 1177 | SmallVector<SDOperand, 8> ShufOps; |
Chris Lattner | 8d5a894 | 2006-04-17 19:21:01 +0000 | [diff] [blame] | 1178 | for (unsigned i = 0; i != NumElts; ++i) { |
| 1179 | if (i != InsertPos->getValue()) |
| 1180 | ShufOps.push_back(DAG.getConstant(i, ShufMaskEltVT)); |
| 1181 | else |
| 1182 | ShufOps.push_back(DAG.getConstant(NumElts, ShufMaskEltVT)); |
| 1183 | } |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 1184 | SDOperand ShufMask = DAG.getNode(ISD::BUILD_VECTOR, ShufMaskVT, |
| 1185 | &ShufOps[0], ShufOps.size()); |
Chris Lattner | 8d5a894 | 2006-04-17 19:21:01 +0000 | [diff] [blame] | 1186 | |
| 1187 | Result = DAG.getNode(ISD::VECTOR_SHUFFLE, Tmp1.getValueType(), |
| 1188 | Tmp1, ScVec, ShufMask); |
| 1189 | Result = LegalizeOp(Result); |
| 1190 | break; |
| 1191 | } |
| 1192 | |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1193 | // If the target doesn't support this, we have to spill the input vector |
| 1194 | // to a temporary stack slot, update the element, then reload it. This is |
| 1195 | // badness. We could also load the value into a vector register (either |
| 1196 | // with a "move to register" or "extload into register" instruction, then |
| 1197 | // permute it into place, if the idx is a constant and if the idx is |
| 1198 | // supported by the target. |
Evan Cheng | f6bf87f | 2006-04-08 01:46:37 +0000 | [diff] [blame] | 1199 | MVT::ValueType VT = Tmp1.getValueType(); |
| 1200 | MVT::ValueType EltVT = Tmp2.getValueType(); |
| 1201 | MVT::ValueType IdxVT = Tmp3.getValueType(); |
| 1202 | MVT::ValueType PtrVT = TLI.getPointerTy(); |
| 1203 | SDOperand StackPtr = CreateStackTemporary(VT); |
Evan Cheng | eb0b461 | 2006-03-31 01:27:51 +0000 | [diff] [blame] | 1204 | // Store the vector. |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 1205 | SDOperand Ch = DAG.getStore(DAG.getEntryNode(), Tmp1, StackPtr, NULL, 0); |
Evan Cheng | eb0b461 | 2006-03-31 01:27:51 +0000 | [diff] [blame] | 1206 | |
| 1207 | // Truncate or zero extend offset to target pointer type. |
Evan Cheng | f6bf87f | 2006-04-08 01:46:37 +0000 | [diff] [blame] | 1208 | unsigned CastOpc = (IdxVT > PtrVT) ? ISD::TRUNCATE : ISD::ZERO_EXTEND; |
| 1209 | Tmp3 = DAG.getNode(CastOpc, PtrVT, Tmp3); |
Evan Cheng | eb0b461 | 2006-03-31 01:27:51 +0000 | [diff] [blame] | 1210 | // Add the offset to the index. |
Evan Cheng | f6bf87f | 2006-04-08 01:46:37 +0000 | [diff] [blame] | 1211 | unsigned EltSize = MVT::getSizeInBits(EltVT)/8; |
| 1212 | Tmp3 = DAG.getNode(ISD::MUL, IdxVT, Tmp3,DAG.getConstant(EltSize, IdxVT)); |
| 1213 | SDOperand StackPtr2 = DAG.getNode(ISD::ADD, IdxVT, Tmp3, StackPtr); |
Evan Cheng | eb0b461 | 2006-03-31 01:27:51 +0000 | [diff] [blame] | 1214 | // Store the scalar value. |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 1215 | Ch = DAG.getStore(Ch, Tmp2, StackPtr2, NULL, 0); |
Evan Cheng | eb0b461 | 2006-03-31 01:27:51 +0000 | [diff] [blame] | 1216 | // Load the updated vector. |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1217 | Result = DAG.getLoad(VT, Ch, StackPtr, NULL, 0); |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1218 | break; |
| 1219 | } |
| 1220 | } |
| 1221 | break; |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 1222 | case ISD::SCALAR_TO_VECTOR: |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 1223 | if (!TLI.isTypeLegal(Node->getOperand(0).getValueType())) { |
| 1224 | Result = LegalizeOp(ExpandSCALAR_TO_VECTOR(Node)); |
| 1225 | break; |
| 1226 | } |
| 1227 | |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 1228 | Tmp1 = LegalizeOp(Node->getOperand(0)); // InVal |
| 1229 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 1230 | switch (TLI.getOperationAction(ISD::SCALAR_TO_VECTOR, |
| 1231 | Node->getValueType(0))) { |
| 1232 | default: assert(0 && "This action is not supported yet!"); |
| 1233 | case TargetLowering::Legal: |
| 1234 | break; |
Chris Lattner | 4d3abee | 2006-03-19 06:47:21 +0000 | [diff] [blame] | 1235 | case TargetLowering::Custom: |
| 1236 | Tmp3 = TLI.LowerOperation(Result, DAG); |
| 1237 | if (Tmp3.Val) { |
| 1238 | Result = Tmp3; |
| 1239 | break; |
| 1240 | } |
| 1241 | // FALLTHROUGH |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 1242 | case TargetLowering::Expand: |
| 1243 | Result = LegalizeOp(ExpandSCALAR_TO_VECTOR(Node)); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 1244 | break; |
| 1245 | } |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 1246 | break; |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 1247 | case ISD::VECTOR_SHUFFLE: |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 1248 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the input vectors, |
| 1249 | Tmp2 = LegalizeOp(Node->getOperand(1)); // but not the shuffle mask. |
| 1250 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
| 1251 | |
| 1252 | // Allow targets to custom lower the SHUFFLEs they support. |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 1253 | switch (TLI.getOperationAction(ISD::VECTOR_SHUFFLE,Result.getValueType())) { |
| 1254 | default: assert(0 && "Unknown operation action!"); |
| 1255 | case TargetLowering::Legal: |
| 1256 | assert(isShuffleLegal(Result.getValueType(), Node->getOperand(2)) && |
| 1257 | "vector shuffle should not be created if not legal!"); |
| 1258 | break; |
| 1259 | case TargetLowering::Custom: |
Evan Cheng | 18dd6d0 | 2006-04-05 06:07:11 +0000 | [diff] [blame] | 1260 | Tmp3 = TLI.LowerOperation(Result, DAG); |
| 1261 | if (Tmp3.Val) { |
| 1262 | Result = Tmp3; |
| 1263 | break; |
| 1264 | } |
| 1265 | // FALLTHROUGH |
| 1266 | case TargetLowering::Expand: { |
| 1267 | MVT::ValueType VT = Node->getValueType(0); |
Dan Gohman | 51eaa86 | 2007-06-14 22:58:02 +0000 | [diff] [blame] | 1268 | MVT::ValueType EltVT = MVT::getVectorElementType(VT); |
Evan Cheng | 18dd6d0 | 2006-04-05 06:07:11 +0000 | [diff] [blame] | 1269 | MVT::ValueType PtrVT = TLI.getPointerTy(); |
| 1270 | SDOperand Mask = Node->getOperand(2); |
| 1271 | unsigned NumElems = Mask.getNumOperands(); |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 1272 | SmallVector<SDOperand,8> Ops; |
Evan Cheng | 18dd6d0 | 2006-04-05 06:07:11 +0000 | [diff] [blame] | 1273 | for (unsigned i = 0; i != NumElems; ++i) { |
| 1274 | SDOperand Arg = Mask.getOperand(i); |
| 1275 | if (Arg.getOpcode() == ISD::UNDEF) { |
| 1276 | Ops.push_back(DAG.getNode(ISD::UNDEF, EltVT)); |
| 1277 | } else { |
| 1278 | assert(isa<ConstantSDNode>(Arg) && "Invalid VECTOR_SHUFFLE mask!"); |
| 1279 | unsigned Idx = cast<ConstantSDNode>(Arg)->getValue(); |
| 1280 | if (Idx < NumElems) |
| 1281 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, EltVT, Tmp1, |
| 1282 | DAG.getConstant(Idx, PtrVT))); |
| 1283 | else |
| 1284 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, EltVT, Tmp2, |
| 1285 | DAG.getConstant(Idx - NumElems, PtrVT))); |
| 1286 | } |
| 1287 | } |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 1288 | Result = DAG.getNode(ISD::BUILD_VECTOR, VT, &Ops[0], Ops.size()); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 1289 | break; |
Evan Cheng | 18dd6d0 | 2006-04-05 06:07:11 +0000 | [diff] [blame] | 1290 | } |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 1291 | case TargetLowering::Promote: { |
| 1292 | // Change base type to a different vector type. |
| 1293 | MVT::ValueType OVT = Node->getValueType(0); |
| 1294 | MVT::ValueType NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT); |
| 1295 | |
| 1296 | // Cast the two input vectors. |
| 1297 | Tmp1 = DAG.getNode(ISD::BIT_CONVERT, NVT, Tmp1); |
| 1298 | Tmp2 = DAG.getNode(ISD::BIT_CONVERT, NVT, Tmp2); |
| 1299 | |
| 1300 | // Convert the shuffle mask to the right # elements. |
| 1301 | Tmp3 = SDOperand(isShuffleLegal(OVT, Node->getOperand(2)), 0); |
| 1302 | assert(Tmp3.Val && "Shuffle not legal?"); |
| 1303 | Result = DAG.getNode(ISD::VECTOR_SHUFFLE, NVT, Tmp1, Tmp2, Tmp3); |
| 1304 | Result = DAG.getNode(ISD::BIT_CONVERT, OVT, Result); |
| 1305 | break; |
| 1306 | } |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 1307 | } |
| 1308 | break; |
Chris Lattner | 384504c | 2006-03-21 20:44:12 +0000 | [diff] [blame] | 1309 | |
| 1310 | case ISD::EXTRACT_VECTOR_ELT: |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 1311 | Tmp1 = Node->getOperand(0); |
Chris Lattner | 384504c | 2006-03-21 20:44:12 +0000 | [diff] [blame] | 1312 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1313 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 1314 | Result = ExpandEXTRACT_VECTOR_ELT(Result); |
Chris Lattner | 384504c | 2006-03-21 20:44:12 +0000 | [diff] [blame] | 1315 | break; |
| 1316 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 1317 | case ISD::EXTRACT_SUBVECTOR: |
| 1318 | Tmp1 = Node->getOperand(0); |
| 1319 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1320 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 1321 | Result = ExpandEXTRACT_SUBVECTOR(Result); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 1322 | break; |
| 1323 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1324 | case ISD::CALLSEQ_START: { |
| 1325 | SDNode *CallEnd = FindCallEndFromCallStart(Node); |
| 1326 | |
| 1327 | // Recursively Legalize all of the inputs of the call end that do not lead |
| 1328 | // to this call start. This ensures that any libcalls that need be inserted |
| 1329 | // are inserted *before* the CALLSEQ_START. |
Chris Lattner | 00755df | 2007-02-04 00:27:56 +0000 | [diff] [blame] | 1330 | {SmallPtrSet<SDNode*, 32> NodesLeadingTo; |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1331 | for (unsigned i = 0, e = CallEnd->getNumOperands(); i != e; ++i) |
Chris Lattner | c9cf4f1 | 2006-07-26 23:55:56 +0000 | [diff] [blame] | 1332 | LegalizeAllNodesNotLeadingTo(CallEnd->getOperand(i).Val, Node, |
| 1333 | NodesLeadingTo); |
| 1334 | } |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1335 | |
| 1336 | // Now that we legalized all of the inputs (which may have inserted |
| 1337 | // libcalls) create the new CALLSEQ_START node. |
| 1338 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1339 | |
| 1340 | // Merge in the last call, to ensure that this call start after the last |
| 1341 | // call ended. |
Chris Lattner | c5d7d7c | 2006-05-17 18:00:08 +0000 | [diff] [blame] | 1342 | if (LastCALLSEQ_END.getOpcode() != ISD::EntryToken) { |
Chris Lattner | b248e16 | 2006-05-17 17:55:45 +0000 | [diff] [blame] | 1343 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1344 | Tmp1 = LegalizeOp(Tmp1); |
| 1345 | } |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1346 | |
| 1347 | // Do not try to legalize the target-specific arguments (#1+). |
| 1348 | if (Tmp1 != Node->getOperand(0)) { |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1349 | SmallVector<SDOperand, 8> Ops(Node->op_begin(), Node->op_end()); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1350 | Ops[0] = Tmp1; |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1351 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1352 | } |
| 1353 | |
| 1354 | // Remember that the CALLSEQ_START is legalized. |
Chris Lattner | 4b653a0 | 2006-02-14 00:55:02 +0000 | [diff] [blame] | 1355 | AddLegalizedOperand(Op.getValue(0), Result); |
| 1356 | if (Node->getNumValues() == 2) // If this has a flag result, remember it. |
| 1357 | AddLegalizedOperand(Op.getValue(1), Result.getValue(1)); |
| 1358 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1359 | // Now that the callseq_start and all of the non-call nodes above this call |
| 1360 | // sequence have been legalized, legalize the call itself. During this |
| 1361 | // process, no libcalls can/will be inserted, guaranteeing that no calls |
| 1362 | // can overlap. |
| 1363 | assert(!IsLegalizingCall && "Inconsistent sequentialization of calls!"); |
| 1364 | SDOperand InCallSEQ = LastCALLSEQ_END; |
| 1365 | // Note that we are selecting this call! |
| 1366 | LastCALLSEQ_END = SDOperand(CallEnd, 0); |
| 1367 | IsLegalizingCall = true; |
| 1368 | |
| 1369 | // Legalize the call, starting from the CALLSEQ_END. |
| 1370 | LegalizeOp(LastCALLSEQ_END); |
| 1371 | assert(!IsLegalizingCall && "CALLSEQ_END should have cleared this!"); |
| 1372 | return Result; |
| 1373 | } |
Chris Lattner | 16cd04d | 2005-05-12 23:24:06 +0000 | [diff] [blame] | 1374 | case ISD::CALLSEQ_END: |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1375 | // If the CALLSEQ_START node hasn't been legalized first, legalize it. This |
| 1376 | // will cause this node to be legalized as well as handling libcalls right. |
| 1377 | if (LastCALLSEQ_END.Val != Node) { |
| 1378 | LegalizeOp(SDOperand(FindCallStartFromCallEnd(Node), 0)); |
Chris Lattner | 718071c | 2007-02-04 00:50:02 +0000 | [diff] [blame] | 1379 | DenseMap<SDOperand, SDOperand>::iterator I = LegalizedNodes.find(Op); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1380 | assert(I != LegalizedNodes.end() && |
| 1381 | "Legalizing the call start should have legalized this node!"); |
| 1382 | return I->second; |
| 1383 | } |
| 1384 | |
| 1385 | // Otherwise, the call start has been legalized and everything is going |
| 1386 | // according to plan. Just legalize ourselves normally here. |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1387 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | 70814bc | 2006-01-29 07:58:15 +0000 | [diff] [blame] | 1388 | // Do not try to legalize the target-specific arguments (#1+), except for |
| 1389 | // an optional flag input. |
| 1390 | if (Node->getOperand(Node->getNumOperands()-1).getValueType() != MVT::Flag){ |
| 1391 | if (Tmp1 != Node->getOperand(0)) { |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1392 | SmallVector<SDOperand, 8> Ops(Node->op_begin(), Node->op_end()); |
Chris Lattner | 70814bc | 2006-01-29 07:58:15 +0000 | [diff] [blame] | 1393 | Ops[0] = Tmp1; |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1394 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 70814bc | 2006-01-29 07:58:15 +0000 | [diff] [blame] | 1395 | } |
| 1396 | } else { |
| 1397 | Tmp2 = LegalizeOp(Node->getOperand(Node->getNumOperands()-1)); |
| 1398 | if (Tmp1 != Node->getOperand(0) || |
| 1399 | Tmp2 != Node->getOperand(Node->getNumOperands()-1)) { |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1400 | SmallVector<SDOperand, 8> Ops(Node->op_begin(), Node->op_end()); |
Chris Lattner | 70814bc | 2006-01-29 07:58:15 +0000 | [diff] [blame] | 1401 | Ops[0] = Tmp1; |
| 1402 | Ops.back() = Tmp2; |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1403 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 70814bc | 2006-01-29 07:58:15 +0000 | [diff] [blame] | 1404 | } |
Chris Lattner | 6a54289 | 2006-01-24 05:48:21 +0000 | [diff] [blame] | 1405 | } |
Chris Lattner | 4b653a0 | 2006-02-14 00:55:02 +0000 | [diff] [blame] | 1406 | assert(IsLegalizingCall && "Call sequence imbalance between start/end?"); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1407 | // This finishes up call legalization. |
| 1408 | IsLegalizingCall = false; |
Chris Lattner | 4b653a0 | 2006-02-14 00:55:02 +0000 | [diff] [blame] | 1409 | |
| 1410 | // If the CALLSEQ_END node has a flag, remember that we legalized it. |
| 1411 | AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0)); |
| 1412 | if (Node->getNumValues() == 2) |
| 1413 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
| 1414 | return Result.getValue(Op.ResNo); |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1415 | case ISD::DYNAMIC_STACKALLOC: { |
Evan Cheng | 61bbbab | 2007-08-16 23:50:06 +0000 | [diff] [blame] | 1416 | MVT::ValueType VT = Node->getValueType(0); |
Chris Lattner | fa404e8 | 2005-01-09 19:03:49 +0000 | [diff] [blame] | 1417 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1418 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the size. |
| 1419 | Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the alignment. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1420 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | fa404e8 | 2005-01-09 19:03:49 +0000 | [diff] [blame] | 1421 | |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1422 | Tmp1 = Result.getValue(0); |
Chris Lattner | 5f65229 | 2006-01-15 08:43:08 +0000 | [diff] [blame] | 1423 | Tmp2 = Result.getValue(1); |
Evan Cheng | 61bbbab | 2007-08-16 23:50:06 +0000 | [diff] [blame] | 1424 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1425 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1426 | case TargetLowering::Expand: { |
| 1427 | unsigned SPReg = TLI.getStackPointerRegisterToSaveRestore(); |
| 1428 | assert(SPReg && "Target cannot require DYNAMIC_STACKALLOC expansion and" |
| 1429 | " not tell us which reg is the stack pointer!"); |
| 1430 | SDOperand Chain = Tmp1.getOperand(0); |
| 1431 | SDOperand Size = Tmp2.getOperand(1); |
Evan Cheng | 61bbbab | 2007-08-16 23:50:06 +0000 | [diff] [blame] | 1432 | SDOperand SP = DAG.getCopyFromReg(Chain, SPReg, VT); |
| 1433 | Chain = SP.getValue(1); |
| 1434 | unsigned Align = cast<ConstantSDNode>(Tmp3)->getValue(); |
| 1435 | unsigned StackAlign = |
| 1436 | TLI.getTargetMachine().getFrameInfo()->getStackAlignment(); |
| 1437 | if (Align > StackAlign) |
Evan Cheng | 3e20bba | 2007-08-17 18:02:22 +0000 | [diff] [blame] | 1438 | SP = DAG.getNode(ISD::AND, VT, SP, |
| 1439 | DAG.getConstant(-(uint64_t)Align, VT)); |
Evan Cheng | 61bbbab | 2007-08-16 23:50:06 +0000 | [diff] [blame] | 1440 | Tmp1 = DAG.getNode(ISD::SUB, VT, SP, Size); // Value |
| 1441 | Tmp2 = DAG.getCopyToReg(Chain, SPReg, Tmp1); // Output chain |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1442 | Tmp1 = LegalizeOp(Tmp1); |
| 1443 | Tmp2 = LegalizeOp(Tmp2); |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1444 | break; |
| 1445 | } |
| 1446 | case TargetLowering::Custom: |
Chris Lattner | 5f65229 | 2006-01-15 08:43:08 +0000 | [diff] [blame] | 1447 | Tmp3 = TLI.LowerOperation(Tmp1, DAG); |
| 1448 | if (Tmp3.Val) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1449 | Tmp1 = LegalizeOp(Tmp3); |
| 1450 | Tmp2 = LegalizeOp(Tmp3.getValue(1)); |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1451 | } |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1452 | break; |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1453 | case TargetLowering::Legal: |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1454 | break; |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1455 | } |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1456 | // Since this op produce two values, make sure to remember that we |
| 1457 | // legalized both of them. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1458 | AddLegalizedOperand(SDOperand(Node, 0), Tmp1); |
| 1459 | AddLegalizedOperand(SDOperand(Node, 1), Tmp2); |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1460 | return Op.ResNo ? Tmp2 : Tmp1; |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1461 | } |
Chris Lattner | 25a022c | 2006-07-11 01:40:09 +0000 | [diff] [blame] | 1462 | case ISD::INLINEASM: { |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1463 | SmallVector<SDOperand, 8> Ops(Node->op_begin(), Node->op_end()); |
Chris Lattner | 25a022c | 2006-07-11 01:40:09 +0000 | [diff] [blame] | 1464 | bool Changed = false; |
| 1465 | // Legalize all of the operands of the inline asm, in case they are nodes |
| 1466 | // that need to be expanded or something. Note we skip the asm string and |
| 1467 | // all of the TargetConstant flags. |
| 1468 | SDOperand Op = LegalizeOp(Ops[0]); |
| 1469 | Changed = Op != Ops[0]; |
| 1470 | Ops[0] = Op; |
| 1471 | |
| 1472 | bool HasInFlag = Ops.back().getValueType() == MVT::Flag; |
| 1473 | for (unsigned i = 2, e = Ops.size()-HasInFlag; i < e; ) { |
| 1474 | unsigned NumVals = cast<ConstantSDNode>(Ops[i])->getValue() >> 3; |
| 1475 | for (++i; NumVals; ++i, --NumVals) { |
| 1476 | SDOperand Op = LegalizeOp(Ops[i]); |
| 1477 | if (Op != Ops[i]) { |
| 1478 | Changed = true; |
| 1479 | Ops[i] = Op; |
| 1480 | } |
| 1481 | } |
Chris Lattner | ce7518c | 2006-01-26 22:24:51 +0000 | [diff] [blame] | 1482 | } |
Chris Lattner | 25a022c | 2006-07-11 01:40:09 +0000 | [diff] [blame] | 1483 | |
| 1484 | if (HasInFlag) { |
| 1485 | Op = LegalizeOp(Ops.back()); |
| 1486 | Changed |= Op != Ops.back(); |
| 1487 | Ops.back() = Op; |
| 1488 | } |
| 1489 | |
| 1490 | if (Changed) |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1491 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | ce7518c | 2006-01-26 22:24:51 +0000 | [diff] [blame] | 1492 | |
| 1493 | // INLINE asm returns a chain and flag, make sure to add both to the map. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1494 | AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0)); |
Chris Lattner | ce7518c | 2006-01-26 22:24:51 +0000 | [diff] [blame] | 1495 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
| 1496 | return Result.getValue(Op.ResNo); |
Chris Lattner | 25a022c | 2006-07-11 01:40:09 +0000 | [diff] [blame] | 1497 | } |
Chris Lattner | c7af179 | 2005-01-07 22:12:08 +0000 | [diff] [blame] | 1498 | case ISD::BR: |
| 1499 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1500 | // Ensure that libcalls are emitted before a branch. |
| 1501 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1502 | Tmp1 = LegalizeOp(Tmp1); |
| 1503 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 1504 | |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1505 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
Chris Lattner | c7af179 | 2005-01-07 22:12:08 +0000 | [diff] [blame] | 1506 | break; |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 1507 | case ISD::BRIND: |
| 1508 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1509 | // Ensure that libcalls are emitted before a branch. |
| 1510 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1511 | Tmp1 = LegalizeOp(Tmp1); |
| 1512 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 1513 | |
| 1514 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 1515 | default: assert(0 && "Indirect target must be legal type (pointer)!"); |
| 1516 | case Legal: |
| 1517 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the condition. |
| 1518 | break; |
| 1519 | } |
| 1520 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 1521 | break; |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 1522 | case ISD::BR_JT: |
| 1523 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1524 | // Ensure that libcalls are emitted before a branch. |
| 1525 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1526 | Tmp1 = LegalizeOp(Tmp1); |
| 1527 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 1528 | |
| 1529 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the jumptable node. |
| 1530 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
| 1531 | |
| 1532 | switch (TLI.getOperationAction(ISD::BR_JT, MVT::Other)) { |
| 1533 | default: assert(0 && "This action is not supported yet!"); |
| 1534 | case TargetLowering::Legal: break; |
| 1535 | case TargetLowering::Custom: |
| 1536 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 1537 | if (Tmp1.Val) Result = Tmp1; |
| 1538 | break; |
| 1539 | case TargetLowering::Expand: { |
| 1540 | SDOperand Chain = Result.getOperand(0); |
| 1541 | SDOperand Table = Result.getOperand(1); |
| 1542 | SDOperand Index = Result.getOperand(2); |
| 1543 | |
| 1544 | MVT::ValueType PTy = TLI.getPointerTy(); |
Jim Laskey | acd80ac | 2006-12-14 19:17:33 +0000 | [diff] [blame] | 1545 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1546 | unsigned EntrySize = MF.getJumpTableInfo()->getEntrySize(); |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 1547 | Index= DAG.getNode(ISD::MUL, PTy, Index, DAG.getConstant(EntrySize, PTy)); |
| 1548 | SDOperand Addr = DAG.getNode(ISD::ADD, PTy, Index, Table); |
Jim Laskey | acd80ac | 2006-12-14 19:17:33 +0000 | [diff] [blame] | 1549 | |
| 1550 | SDOperand LD; |
| 1551 | switch (EntrySize) { |
| 1552 | default: assert(0 && "Size of jump table not supported yet."); break; |
| 1553 | case 4: LD = DAG.getLoad(MVT::i32, Chain, Addr, NULL, 0); break; |
| 1554 | case 8: LD = DAG.getLoad(MVT::i64, Chain, Addr, NULL, 0); break; |
| 1555 | } |
| 1556 | |
| 1557 | if (TLI.getTargetMachine().getRelocationModel() == Reloc::PIC_) { |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 1558 | // For PIC, the sequence is: |
| 1559 | // BRIND(load(Jumptable + index) + RelocBase) |
| 1560 | // RelocBase is the JumpTable on PPC and X86, GOT on Alpha |
| 1561 | SDOperand Reloc; |
| 1562 | if (TLI.usesGlobalOffsetTable()) |
| 1563 | Reloc = DAG.getNode(ISD::GLOBAL_OFFSET_TABLE, PTy); |
| 1564 | else |
| 1565 | Reloc = Table; |
Evan Cheng | d063189 | 2006-10-31 02:31:00 +0000 | [diff] [blame] | 1566 | Addr = (PTy != MVT::i32) ? DAG.getNode(ISD::SIGN_EXTEND, PTy, LD) : LD; |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 1567 | Addr = DAG.getNode(ISD::ADD, PTy, Addr, Reloc); |
| 1568 | Result = DAG.getNode(ISD::BRIND, MVT::Other, LD.getValue(1), Addr); |
| 1569 | } else { |
| 1570 | Result = DAG.getNode(ISD::BRIND, MVT::Other, LD.getValue(1), LD); |
| 1571 | } |
| 1572 | } |
| 1573 | } |
| 1574 | break; |
Chris Lattner | c18ae4c | 2005-01-07 08:19:42 +0000 | [diff] [blame] | 1575 | case ISD::BRCOND: |
| 1576 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1577 | // Ensure that libcalls are emitted before a return. |
| 1578 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1579 | Tmp1 = LegalizeOp(Tmp1); |
| 1580 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 1581 | |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 1582 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 1583 | case Expand: assert(0 && "It's impossible to expand bools"); |
| 1584 | case Legal: |
| 1585 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the condition. |
| 1586 | break; |
| 1587 | case Promote: |
| 1588 | Tmp2 = PromoteOp(Node->getOperand(1)); // Promote the condition. |
Chris Lattner | f990817 | 2006-11-27 04:39:56 +0000 | [diff] [blame] | 1589 | |
| 1590 | // The top bits of the promoted condition are not necessarily zero, ensure |
| 1591 | // that the value is properly zero extended. |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1592 | if (!DAG.MaskedValueIsZero(Tmp2, |
Chris Lattner | f990817 | 2006-11-27 04:39:56 +0000 | [diff] [blame] | 1593 | MVT::getIntVTBitMask(Tmp2.getValueType())^1)) |
| 1594 | Tmp2 = DAG.getZeroExtendInReg(Tmp2, MVT::i1); |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 1595 | break; |
| 1596 | } |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 1597 | |
| 1598 | // Basic block destination (Op#2) is always legal. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1599 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 1600 | |
| 1601 | switch (TLI.getOperationAction(ISD::BRCOND, MVT::Other)) { |
| 1602 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 1603 | case TargetLowering::Legal: break; |
| 1604 | case TargetLowering::Custom: |
| 1605 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 1606 | if (Tmp1.Val) Result = Tmp1; |
| 1607 | break; |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 1608 | case TargetLowering::Expand: |
| 1609 | // Expand brcond's setcc into its constituent parts and create a BR_CC |
| 1610 | // Node. |
| 1611 | if (Tmp2.getOpcode() == ISD::SETCC) { |
| 1612 | Result = DAG.getNode(ISD::BR_CC, MVT::Other, Tmp1, Tmp2.getOperand(2), |
| 1613 | Tmp2.getOperand(0), Tmp2.getOperand(1), |
| 1614 | Node->getOperand(2)); |
| 1615 | } else { |
| 1616 | Result = DAG.getNode(ISD::BR_CC, MVT::Other, Tmp1, |
| 1617 | DAG.getCondCode(ISD::SETNE), Tmp2, |
| 1618 | DAG.getConstant(0, Tmp2.getValueType()), |
| 1619 | Node->getOperand(2)); |
| 1620 | } |
| 1621 | break; |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 1622 | } |
| 1623 | break; |
| 1624 | case ISD::BR_CC: |
| 1625 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1626 | // Ensure that libcalls are emitted before a branch. |
| 1627 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1628 | Tmp1 = LegalizeOp(Tmp1); |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 1629 | Tmp2 = Node->getOperand(2); // LHS |
| 1630 | Tmp3 = Node->getOperand(3); // RHS |
| 1631 | Tmp4 = Node->getOperand(1); // CC |
| 1632 | |
| 1633 | LegalizeSetCCOperands(Tmp2, Tmp3, Tmp4); |
Evan Cheng | 722cb36 | 2006-12-18 22:55:34 +0000 | [diff] [blame] | 1634 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 1635 | |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 1636 | // If we didn't get both a LHS and RHS back from LegalizeSetCCOperands, |
| 1637 | // the LHS is a legal SETCC itself. In this case, we need to compare |
| 1638 | // the result against zero to select between true and false values. |
| 1639 | if (Tmp3.Val == 0) { |
| 1640 | Tmp3 = DAG.getConstant(0, Tmp2.getValueType()); |
| 1641 | Tmp4 = DAG.getCondCode(ISD::SETNE); |
Chris Lattner | 181b7a3 | 2005-12-17 23:46:46 +0000 | [diff] [blame] | 1642 | } |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 1643 | |
| 1644 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp4, Tmp2, Tmp3, |
| 1645 | Node->getOperand(4)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 1646 | |
Chris Lattner | 181b7a3 | 2005-12-17 23:46:46 +0000 | [diff] [blame] | 1647 | switch (TLI.getOperationAction(ISD::BR_CC, Tmp3.getValueType())) { |
| 1648 | default: assert(0 && "Unexpected action for BR_CC!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 1649 | case TargetLowering::Legal: break; |
| 1650 | case TargetLowering::Custom: |
| 1651 | Tmp4 = TLI.LowerOperation(Result, DAG); |
| 1652 | if (Tmp4.Val) Result = Tmp4; |
Chris Lattner | 181b7a3 | 2005-12-17 23:46:46 +0000 | [diff] [blame] | 1653 | break; |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 1654 | } |
Chris Lattner | c18ae4c | 2005-01-07 08:19:42 +0000 | [diff] [blame] | 1655 | break; |
Evan Cheng | f3fd9fe | 2005-12-23 07:29:34 +0000 | [diff] [blame] | 1656 | case ISD::LOAD: { |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1657 | LoadSDNode *LD = cast<LoadSDNode>(Node); |
| 1658 | Tmp1 = LegalizeOp(LD->getChain()); // Legalize the chain. |
| 1659 | Tmp2 = LegalizeOp(LD->getBasePtr()); // Legalize the base pointer. |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 1660 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1661 | ISD::LoadExtType ExtType = LD->getExtensionType(); |
| 1662 | if (ExtType == ISD::NON_EXTLOAD) { |
| 1663 | MVT::ValueType VT = Node->getValueType(0); |
| 1664 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, LD->getOffset()); |
| 1665 | Tmp3 = Result.getValue(0); |
| 1666 | Tmp4 = Result.getValue(1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 1667 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1668 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 1669 | default: assert(0 && "This action is not supported yet!"); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 1670 | case TargetLowering::Legal: |
| 1671 | // If this is an unaligned load and the target doesn't support it, |
| 1672 | // expand it. |
| 1673 | if (!TLI.allowsUnalignedMemoryAccesses()) { |
| 1674 | unsigned ABIAlignment = TLI.getTargetData()-> |
| 1675 | getABITypeAlignment(MVT::getTypeForValueType(LD->getLoadedVT())); |
| 1676 | if (LD->getAlignment() < ABIAlignment){ |
| 1677 | Result = ExpandUnalignedLoad(cast<LoadSDNode>(Result.Val), DAG, |
| 1678 | TLI); |
| 1679 | Tmp3 = Result.getOperand(0); |
| 1680 | Tmp4 = Result.getOperand(1); |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 1681 | Tmp3 = LegalizeOp(Tmp3); |
| 1682 | Tmp4 = LegalizeOp(Tmp4); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 1683 | } |
| 1684 | } |
| 1685 | break; |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1686 | case TargetLowering::Custom: |
| 1687 | Tmp1 = TLI.LowerOperation(Tmp3, DAG); |
| 1688 | if (Tmp1.Val) { |
| 1689 | Tmp3 = LegalizeOp(Tmp1); |
| 1690 | Tmp4 = LegalizeOp(Tmp1.getValue(1)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 1691 | } |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1692 | break; |
| 1693 | case TargetLowering::Promote: { |
| 1694 | // Only promote a load of vector type to another. |
| 1695 | assert(MVT::isVector(VT) && "Cannot promote this load!"); |
| 1696 | // Change base type to a different vector type. |
| 1697 | MVT::ValueType NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), VT); |
| 1698 | |
| 1699 | Tmp1 = DAG.getLoad(NVT, Tmp1, Tmp2, LD->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 1700 | LD->getSrcValueOffset(), |
| 1701 | LD->isVolatile(), LD->getAlignment()); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1702 | Tmp3 = LegalizeOp(DAG.getNode(ISD::BIT_CONVERT, VT, Tmp1)); |
| 1703 | Tmp4 = LegalizeOp(Tmp1.getValue(1)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1704 | break; |
Andrew Lenharth | 9d416f7 | 2005-06-30 19:22:37 +0000 | [diff] [blame] | 1705 | } |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1706 | } |
| 1707 | // Since loads produce two values, make sure to remember that we |
| 1708 | // legalized both of them. |
| 1709 | AddLegalizedOperand(SDOperand(Node, 0), Tmp3); |
| 1710 | AddLegalizedOperand(SDOperand(Node, 1), Tmp4); |
| 1711 | return Op.ResNo ? Tmp4 : Tmp3; |
| 1712 | } else { |
Evan Cheng | 2e49f09 | 2006-10-11 07:10:22 +0000 | [diff] [blame] | 1713 | MVT::ValueType SrcVT = LD->getLoadedVT(); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1714 | switch (TLI.getLoadXAction(ExtType, SrcVT)) { |
| 1715 | default: assert(0 && "This action is not supported yet!"); |
| 1716 | case TargetLowering::Promote: |
| 1717 | assert(SrcVT == MVT::i1 && |
| 1718 | "Can only promote extending LOAD from i1 -> i8!"); |
| 1719 | Result = DAG.getExtLoad(ExtType, Node->getValueType(0), Tmp1, Tmp2, |
| 1720 | LD->getSrcValue(), LD->getSrcValueOffset(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 1721 | MVT::i8, LD->isVolatile(), LD->getAlignment()); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1722 | Tmp1 = Result.getValue(0); |
| 1723 | Tmp2 = Result.getValue(1); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1724 | break; |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1725 | case TargetLowering::Custom: |
| 1726 | isCustom = true; |
| 1727 | // FALLTHROUGH |
| 1728 | case TargetLowering::Legal: |
| 1729 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, LD->getOffset()); |
| 1730 | Tmp1 = Result.getValue(0); |
| 1731 | Tmp2 = Result.getValue(1); |
| 1732 | |
| 1733 | if (isCustom) { |
| 1734 | Tmp3 = TLI.LowerOperation(Result, DAG); |
| 1735 | if (Tmp3.Val) { |
| 1736 | Tmp1 = LegalizeOp(Tmp3); |
| 1737 | Tmp2 = LegalizeOp(Tmp3.getValue(1)); |
| 1738 | } |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 1739 | } else { |
| 1740 | // If this is an unaligned load and the target doesn't support it, |
| 1741 | // expand it. |
| 1742 | if (!TLI.allowsUnalignedMemoryAccesses()) { |
| 1743 | unsigned ABIAlignment = TLI.getTargetData()-> |
| 1744 | getABITypeAlignment(MVT::getTypeForValueType(LD->getLoadedVT())); |
| 1745 | if (LD->getAlignment() < ABIAlignment){ |
| 1746 | Result = ExpandUnalignedLoad(cast<LoadSDNode>(Result.Val), DAG, |
| 1747 | TLI); |
| 1748 | Tmp1 = Result.getOperand(0); |
| 1749 | Tmp2 = Result.getOperand(1); |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 1750 | Tmp1 = LegalizeOp(Tmp1); |
| 1751 | Tmp2 = LegalizeOp(Tmp2); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 1752 | } |
| 1753 | } |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1754 | } |
| 1755 | break; |
| 1756 | case TargetLowering::Expand: |
| 1757 | // f64 = EXTLOAD f32 should expand to LOAD, FP_EXTEND |
| 1758 | if (SrcVT == MVT::f32 && Node->getValueType(0) == MVT::f64) { |
| 1759 | SDOperand Load = DAG.getLoad(SrcVT, Tmp1, Tmp2, LD->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 1760 | LD->getSrcValueOffset(), |
| 1761 | LD->isVolatile(), LD->getAlignment()); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1762 | Result = DAG.getNode(ISD::FP_EXTEND, Node->getValueType(0), Load); |
| 1763 | Tmp1 = LegalizeOp(Result); // Relegalize new nodes. |
| 1764 | Tmp2 = LegalizeOp(Load.getValue(1)); |
| 1765 | break; |
| 1766 | } |
Chris Lattner | fea997a | 2007-02-01 04:55:59 +0000 | [diff] [blame] | 1767 | assert(ExtType != ISD::EXTLOAD &&"EXTLOAD should always be supported!"); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1768 | // Turn the unsupported load into an EXTLOAD followed by an explicit |
| 1769 | // zero/sign extend inreg. |
| 1770 | Result = DAG.getExtLoad(ISD::EXTLOAD, Node->getValueType(0), |
| 1771 | Tmp1, Tmp2, LD->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 1772 | LD->getSrcValueOffset(), SrcVT, |
| 1773 | LD->isVolatile(), LD->getAlignment()); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1774 | SDOperand ValRes; |
| 1775 | if (ExtType == ISD::SEXTLOAD) |
| 1776 | ValRes = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(), |
| 1777 | Result, DAG.getValueType(SrcVT)); |
| 1778 | else |
| 1779 | ValRes = DAG.getZeroExtendInReg(Result, SrcVT); |
| 1780 | Tmp1 = LegalizeOp(ValRes); // Relegalize new nodes. |
| 1781 | Tmp2 = LegalizeOp(Result.getValue(1)); // Relegalize new nodes. |
| 1782 | break; |
| 1783 | } |
| 1784 | // Since loads produce two values, make sure to remember that we legalized |
| 1785 | // both of them. |
| 1786 | AddLegalizedOperand(SDOperand(Node, 0), Tmp1); |
| 1787 | AddLegalizedOperand(SDOperand(Node, 1), Tmp2); |
| 1788 | return Op.ResNo ? Tmp2 : Tmp1; |
Chris Lattner | 01ff721 | 2005-04-10 22:54:25 +0000 | [diff] [blame] | 1789 | } |
Chris Lattner | 01ff721 | 2005-04-10 22:54:25 +0000 | [diff] [blame] | 1790 | } |
Nate Begeman | 5dc897b | 2005-10-19 00:06:56 +0000 | [diff] [blame] | 1791 | case ISD::EXTRACT_ELEMENT: { |
| 1792 | MVT::ValueType OpTy = Node->getOperand(0).getValueType(); |
| 1793 | switch (getTypeAction(OpTy)) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1794 | default: assert(0 && "EXTRACT_ELEMENT action for type unimplemented!"); |
Nate Begeman | 5dc897b | 2005-10-19 00:06:56 +0000 | [diff] [blame] | 1795 | case Legal: |
| 1796 | if (cast<ConstantSDNode>(Node->getOperand(1))->getValue()) { |
| 1797 | // 1 -> Hi |
| 1798 | Result = DAG.getNode(ISD::SRL, OpTy, Node->getOperand(0), |
| 1799 | DAG.getConstant(MVT::getSizeInBits(OpTy)/2, |
| 1800 | TLI.getShiftAmountTy())); |
| 1801 | Result = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0), Result); |
| 1802 | } else { |
| 1803 | // 0 -> Lo |
| 1804 | Result = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0), |
| 1805 | Node->getOperand(0)); |
| 1806 | } |
Nate Begeman | 5dc897b | 2005-10-19 00:06:56 +0000 | [diff] [blame] | 1807 | break; |
| 1808 | case Expand: |
| 1809 | // Get both the low and high parts. |
| 1810 | ExpandOp(Node->getOperand(0), Tmp1, Tmp2); |
| 1811 | if (cast<ConstantSDNode>(Node->getOperand(1))->getValue()) |
| 1812 | Result = Tmp2; // 1 -> Hi |
| 1813 | else |
| 1814 | Result = Tmp1; // 0 -> Lo |
| 1815 | break; |
| 1816 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1817 | break; |
Nate Begeman | 5dc897b | 2005-10-19 00:06:56 +0000 | [diff] [blame] | 1818 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1819 | |
| 1820 | case ISD::CopyToReg: |
| 1821 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 1822 | |
Chris Lattner | c9c60f6 | 2005-08-24 16:35:28 +0000 | [diff] [blame] | 1823 | assert(isTypeLegal(Node->getOperand(2).getValueType()) && |
Chris Lattner | d5d0f9b | 2005-08-16 21:55:35 +0000 | [diff] [blame] | 1824 | "Register type must be legal!"); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 1825 | // Legalize the incoming value (must be a legal type). |
Chris Lattner | d5d0f9b | 2005-08-16 21:55:35 +0000 | [diff] [blame] | 1826 | Tmp2 = LegalizeOp(Node->getOperand(2)); |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 1827 | if (Node->getNumValues() == 1) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1828 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1), Tmp2); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 1829 | } else { |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 1830 | assert(Node->getNumValues() == 2 && "Unknown CopyToReg"); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1831 | if (Node->getNumOperands() == 4) { |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 1832 | Tmp3 = LegalizeOp(Node->getOperand(3)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1833 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1), Tmp2, |
| 1834 | Tmp3); |
| 1835 | } else { |
| 1836 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1),Tmp2); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 1837 | } |
| 1838 | |
| 1839 | // Since this produces two values, make sure to remember that we legalized |
| 1840 | // both of them. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1841 | AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0)); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 1842 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1843 | return Result; |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 1844 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1845 | break; |
| 1846 | |
| 1847 | case ISD::RET: |
| 1848 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1849 | |
| 1850 | // Ensure that libcalls are emitted before a return. |
| 1851 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1852 | Tmp1 = LegalizeOp(Tmp1); |
| 1853 | LastCALLSEQ_END = DAG.getEntryNode(); |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 1854 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1855 | switch (Node->getNumOperands()) { |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 1856 | case 3: // ret val |
Evan Cheng | 98f8aeb | 2006-04-11 06:33:39 +0000 | [diff] [blame] | 1857 | Tmp2 = Node->getOperand(1); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 1858 | Tmp3 = Node->getOperand(2); // Signness |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 1859 | switch (getTypeAction(Tmp2.getValueType())) { |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1860 | case Legal: |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 1861 | Result = DAG.UpdateNodeOperands(Result, Tmp1, LegalizeOp(Tmp2), Tmp3); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1862 | break; |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 1863 | case Expand: |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 1864 | if (!MVT::isVector(Tmp2.getValueType())) { |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 1865 | SDOperand Lo, Hi; |
| 1866 | ExpandOp(Tmp2, Lo, Hi); |
Chris Lattner | edf2e8d | 2007-03-06 20:01:06 +0000 | [diff] [blame] | 1867 | |
| 1868 | // Big endian systems want the hi reg first. |
| 1869 | if (!TLI.isLittleEndian()) |
| 1870 | std::swap(Lo, Hi); |
| 1871 | |
Evan Cheng | 13acce3 | 2006-12-11 19:27:14 +0000 | [diff] [blame] | 1872 | if (Hi.Val) |
| 1873 | Result = DAG.getNode(ISD::RET, MVT::Other, Tmp1, Lo, Tmp3, Hi,Tmp3); |
| 1874 | else |
| 1875 | Result = DAG.getNode(ISD::RET, MVT::Other, Tmp1, Lo, Tmp3); |
Chris Lattner | f921a51 | 2006-08-21 20:24:53 +0000 | [diff] [blame] | 1876 | Result = LegalizeOp(Result); |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 1877 | } else { |
| 1878 | SDNode *InVal = Tmp2.Val; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 1879 | unsigned NumElems = MVT::getVectorNumElements(InVal->getValueType(0)); |
| 1880 | MVT::ValueType EVT = MVT::getVectorElementType(InVal->getValueType(0)); |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 1881 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 1882 | // Figure out if there is a simple type corresponding to this Vector |
Reid Spencer | ac9dcb9 | 2007-02-15 03:39:18 +0000 | [diff] [blame] | 1883 | // type. If so, convert to the vector type. |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 1884 | MVT::ValueType TVT = MVT::getVectorType(EVT, NumElems); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 1885 | if (TLI.isTypeLegal(TVT)) { |
Reid Spencer | ac9dcb9 | 2007-02-15 03:39:18 +0000 | [diff] [blame] | 1886 | // Turn this into a return of the vector type. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 1887 | Tmp2 = LegalizeOp(Tmp2); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 1888 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 1889 | } else if (NumElems == 1) { |
| 1890 | // Turn this into a return of the scalar type. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 1891 | Tmp2 = ScalarizeVectorOp(Tmp2); |
| 1892 | Tmp2 = LegalizeOp(Tmp2); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 1893 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | b49e52c | 2006-04-11 02:00:08 +0000 | [diff] [blame] | 1894 | |
| 1895 | // FIXME: Returns of gcc generic vectors smaller than a legal type |
| 1896 | // should be returned in integer registers! |
| 1897 | |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 1898 | // The scalarized value type may not be legal, e.g. it might require |
| 1899 | // promotion or expansion. Relegalize the return. |
| 1900 | Result = LegalizeOp(Result); |
| 1901 | } else { |
Chris Lattner | b49e52c | 2006-04-11 02:00:08 +0000 | [diff] [blame] | 1902 | // FIXME: Returns of gcc generic vectors larger than a legal vector |
| 1903 | // type should be returned by reference! |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 1904 | SDOperand Lo, Hi; |
| 1905 | SplitVectorOp(Tmp2, Lo, Hi); |
Chris Lattner | fea997a | 2007-02-01 04:55:59 +0000 | [diff] [blame] | 1906 | Result = DAG.getNode(ISD::RET, MVT::Other, Tmp1, Lo, Tmp3, Hi,Tmp3); |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 1907 | Result = LegalizeOp(Result); |
| 1908 | } |
| 1909 | } |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 1910 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1911 | case Promote: |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 1912 | Tmp2 = PromoteOp(Node->getOperand(1)); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 1913 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1914 | Result = LegalizeOp(Result); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 1915 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1916 | } |
| 1917 | break; |
| 1918 | case 1: // ret void |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1919 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1920 | break; |
| 1921 | default: { // ret <values> |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1922 | SmallVector<SDOperand, 8> NewValues; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1923 | NewValues.push_back(Tmp1); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 1924 | for (unsigned i = 1, e = Node->getNumOperands(); i < e; i += 2) |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1925 | switch (getTypeAction(Node->getOperand(i).getValueType())) { |
| 1926 | case Legal: |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 1927 | NewValues.push_back(LegalizeOp(Node->getOperand(i))); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 1928 | NewValues.push_back(Node->getOperand(i+1)); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1929 | break; |
| 1930 | case Expand: { |
| 1931 | SDOperand Lo, Hi; |
Dan Gohman | 6595cb3 | 2007-06-27 16:08:04 +0000 | [diff] [blame] | 1932 | assert(!MVT::isExtendedVT(Node->getOperand(i).getValueType()) && |
Chris Lattner | b49e52c | 2006-04-11 02:00:08 +0000 | [diff] [blame] | 1933 | "FIXME: TODO: implement returning non-legal vector types!"); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1934 | ExpandOp(Node->getOperand(i), Lo, Hi); |
| 1935 | NewValues.push_back(Lo); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 1936 | NewValues.push_back(Node->getOperand(i+1)); |
Evan Cheng | 13acce3 | 2006-12-11 19:27:14 +0000 | [diff] [blame] | 1937 | if (Hi.Val) { |
| 1938 | NewValues.push_back(Hi); |
| 1939 | NewValues.push_back(Node->getOperand(i+1)); |
| 1940 | } |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 1941 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1942 | } |
| 1943 | case Promote: |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 1944 | assert(0 && "Can't promote multiple return value yet!"); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1945 | } |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1946 | |
| 1947 | if (NewValues.size() == Node->getNumOperands()) |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1948 | Result = DAG.UpdateNodeOperands(Result, &NewValues[0],NewValues.size()); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1949 | else |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1950 | Result = DAG.getNode(ISD::RET, MVT::Other, |
| 1951 | &NewValues[0], NewValues.size()); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1952 | break; |
| 1953 | } |
| 1954 | } |
Evan Cheng | 17c428e | 2006-01-06 00:41:43 +0000 | [diff] [blame] | 1955 | |
Chris Lattner | 6862dbc | 2006-01-29 21:02:23 +0000 | [diff] [blame] | 1956 | if (Result.getOpcode() == ISD::RET) { |
| 1957 | switch (TLI.getOperationAction(Result.getOpcode(), MVT::Other)) { |
| 1958 | default: assert(0 && "This action is not supported yet!"); |
| 1959 | case TargetLowering::Legal: break; |
| 1960 | case TargetLowering::Custom: |
| 1961 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 1962 | if (Tmp1.Val) Result = Tmp1; |
| 1963 | break; |
| 1964 | } |
Evan Cheng | 17c428e | 2006-01-06 00:41:43 +0000 | [diff] [blame] | 1965 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1966 | break; |
Evan Cheng | f3fd9fe | 2005-12-23 07:29:34 +0000 | [diff] [blame] | 1967 | case ISD::STORE: { |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 1968 | StoreSDNode *ST = cast<StoreSDNode>(Node); |
| 1969 | Tmp1 = LegalizeOp(ST->getChain()); // Legalize the chain. |
| 1970 | Tmp2 = LegalizeOp(ST->getBasePtr()); // Legalize the pointer. |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 1971 | int SVOffset = ST->getSrcValueOffset(); |
| 1972 | unsigned Alignment = ST->getAlignment(); |
| 1973 | bool isVolatile = ST->isVolatile(); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1974 | |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 1975 | if (!ST->isTruncatingStore()) { |
Chris Lattner | d93d46e | 2006-12-12 04:18:56 +0000 | [diff] [blame] | 1976 | // Turn 'store float 1.0, Ptr' -> 'store int 0x12345678, Ptr' |
| 1977 | // FIXME: We shouldn't do this for TargetConstantFP's. |
| 1978 | // FIXME: move this to the DAG Combiner! Note that we can't regress due |
| 1979 | // to phase ordering between legalized code and the dag combiner. This |
| 1980 | // probably means that we need to integrate dag combiner and legalizer |
| 1981 | // together. |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 1982 | // We generally can't do this one for long doubles. |
| 1983 | if (ConstantFPSDNode *CFP =dyn_cast<ConstantFPSDNode>(ST->getValue())) { |
Chris Lattner | d93d46e | 2006-12-12 04:18:56 +0000 | [diff] [blame] | 1984 | if (CFP->getValueType(0) == MVT::f32) { |
Dale Johannesen | 9d5f456 | 2007-09-12 03:30:33 +0000 | [diff] [blame] | 1985 | Tmp3 = DAG.getConstant((uint32_t)CFP->getValueAPF(). |
| 1986 | convertToAPInt().getZExtValue(), |
Dale Johannesen | 3f6eb74 | 2007-09-11 18:32:33 +0000 | [diff] [blame] | 1987 | MVT::i32); |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 1988 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
| 1989 | SVOffset, isVolatile, Alignment); |
| 1990 | break; |
| 1991 | } else if (CFP->getValueType(0) == MVT::f64) { |
Dale Johannesen | 9d5f456 | 2007-09-12 03:30:33 +0000 | [diff] [blame] | 1992 | Tmp3 = DAG.getConstant(CFP->getValueAPF().convertToAPInt(). |
| 1993 | getZExtValue(), MVT::i64); |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 1994 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
| 1995 | SVOffset, isVolatile, Alignment); |
| 1996 | break; |
Chris Lattner | d93d46e | 2006-12-12 04:18:56 +0000 | [diff] [blame] | 1997 | } |
Chris Lattner | d93d46e | 2006-12-12 04:18:56 +0000 | [diff] [blame] | 1998 | } |
| 1999 | |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2000 | switch (getTypeAction(ST->getStoredVT())) { |
| 2001 | case Legal: { |
| 2002 | Tmp3 = LegalizeOp(ST->getValue()); |
| 2003 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp3, Tmp2, |
| 2004 | ST->getOffset()); |
Evan Cheng | f3fd9fe | 2005-12-23 07:29:34 +0000 | [diff] [blame] | 2005 | |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2006 | MVT::ValueType VT = Tmp3.getValueType(); |
| 2007 | switch (TLI.getOperationAction(ISD::STORE, VT)) { |
| 2008 | default: assert(0 && "This action is not supported yet!"); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2009 | case TargetLowering::Legal: |
| 2010 | // If this is an unaligned store and the target doesn't support it, |
| 2011 | // expand it. |
| 2012 | if (!TLI.allowsUnalignedMemoryAccesses()) { |
| 2013 | unsigned ABIAlignment = TLI.getTargetData()-> |
| 2014 | getABITypeAlignment(MVT::getTypeForValueType(ST->getStoredVT())); |
| 2015 | if (ST->getAlignment() < ABIAlignment) |
| 2016 | Result = ExpandUnalignedStore(cast<StoreSDNode>(Result.Val), DAG, |
| 2017 | TLI); |
| 2018 | } |
| 2019 | break; |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2020 | case TargetLowering::Custom: |
| 2021 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2022 | if (Tmp1.Val) Result = Tmp1; |
| 2023 | break; |
| 2024 | case TargetLowering::Promote: |
| 2025 | assert(MVT::isVector(VT) && "Unknown legal promote case!"); |
| 2026 | Tmp3 = DAG.getNode(ISD::BIT_CONVERT, |
| 2027 | TLI.getTypeToPromoteTo(ISD::STORE, VT), Tmp3); |
| 2028 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2029 | ST->getSrcValue(), SVOffset, isVolatile, |
| 2030 | Alignment); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2031 | break; |
| 2032 | } |
| 2033 | break; |
| 2034 | } |
| 2035 | case Promote: |
| 2036 | // Truncate the value and store the result. |
| 2037 | Tmp3 = PromoteOp(ST->getValue()); |
| 2038 | Result = DAG.getTruncStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2039 | SVOffset, ST->getStoredVT(), |
| 2040 | isVolatile, Alignment); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2041 | break; |
| 2042 | |
| 2043 | case Expand: |
| 2044 | unsigned IncrementSize = 0; |
| 2045 | SDOperand Lo, Hi; |
| 2046 | |
| 2047 | // If this is a vector type, then we have to calculate the increment as |
| 2048 | // the product of the element size in bytes, and the number of elements |
| 2049 | // in the high half of the vector. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2050 | if (MVT::isVector(ST->getValue().getValueType())) { |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2051 | SDNode *InVal = ST->getValue().Val; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2052 | unsigned NumElems = MVT::getVectorNumElements(InVal->getValueType(0)); |
| 2053 | MVT::ValueType EVT = MVT::getVectorElementType(InVal->getValueType(0)); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2054 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2055 | // Figure out if there is a simple type corresponding to this Vector |
Reid Spencer | ac9dcb9 | 2007-02-15 03:39:18 +0000 | [diff] [blame] | 2056 | // type. If so, convert to the vector type. |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2057 | MVT::ValueType TVT = MVT::getVectorType(EVT, NumElems); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2058 | if (TLI.isTypeLegal(TVT)) { |
Reid Spencer | ac9dcb9 | 2007-02-15 03:39:18 +0000 | [diff] [blame] | 2059 | // Turn this into a normal store of the vector type. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2060 | Tmp3 = LegalizeOp(Node->getOperand(1)); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2061 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2062 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2063 | Result = LegalizeOp(Result); |
| 2064 | break; |
| 2065 | } else if (NumElems == 1) { |
| 2066 | // Turn this into a normal store of the scalar type. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2067 | Tmp3 = ScalarizeVectorOp(Node->getOperand(1)); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2068 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2069 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2070 | // The scalarized value type may not be legal, e.g. it might require |
| 2071 | // promotion or expansion. Relegalize the scalar store. |
| 2072 | Result = LegalizeOp(Result); |
| 2073 | break; |
| 2074 | } else { |
| 2075 | SplitVectorOp(Node->getOperand(1), Lo, Hi); |
| 2076 | IncrementSize = NumElems/2 * MVT::getSizeInBits(EVT)/8; |
| 2077 | } |
| 2078 | } else { |
| 2079 | ExpandOp(Node->getOperand(1), Lo, Hi); |
Evan Cheng | 7b2b5c8 | 2006-12-12 19:53:13 +0000 | [diff] [blame] | 2080 | IncrementSize = Hi.Val ? MVT::getSizeInBits(Hi.getValueType())/8 : 0; |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2081 | |
| 2082 | if (!TLI.isLittleEndian()) |
| 2083 | std::swap(Lo, Hi); |
| 2084 | } |
| 2085 | |
| 2086 | Lo = DAG.getStore(Tmp1, Lo, Tmp2, ST->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2087 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 7b2b5c8 | 2006-12-12 19:53:13 +0000 | [diff] [blame] | 2088 | |
| 2089 | if (Hi.Val == NULL) { |
| 2090 | // Must be int <-> float one-to-one expansion. |
| 2091 | Result = Lo; |
| 2092 | break; |
| 2093 | } |
| 2094 | |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2095 | Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2, |
| 2096 | getIntPtrConstant(IncrementSize)); |
| 2097 | assert(isTypeLegal(Tmp2.getValueType()) && |
| 2098 | "Pointers must be legal!"); |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2099 | SVOffset += IncrementSize; |
| 2100 | if (Alignment > IncrementSize) |
| 2101 | Alignment = IncrementSize; |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2102 | Hi = DAG.getStore(Tmp1, Hi, Tmp2, ST->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2103 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2104 | Result = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo, Hi); |
| 2105 | break; |
| 2106 | } |
| 2107 | } else { |
| 2108 | // Truncating store |
| 2109 | assert(isTypeLegal(ST->getValue().getValueType()) && |
| 2110 | "Cannot handle illegal TRUNCSTORE yet!"); |
| 2111 | Tmp3 = LegalizeOp(ST->getValue()); |
| 2112 | |
| 2113 | // The only promote case we handle is TRUNCSTORE:i1 X into |
| 2114 | // -> TRUNCSTORE:i8 (and X, 1) |
| 2115 | if (ST->getStoredVT() == MVT::i1 && |
| 2116 | TLI.getStoreXAction(MVT::i1) == TargetLowering::Promote) { |
| 2117 | // Promote the bool to a mask then store. |
| 2118 | Tmp3 = DAG.getNode(ISD::AND, Tmp3.getValueType(), Tmp3, |
| 2119 | DAG.getConstant(1, Tmp3.getValueType())); |
| 2120 | Result = DAG.getTruncStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2121 | SVOffset, MVT::i8, |
| 2122 | isVolatile, Alignment); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2123 | } else if (Tmp1 != ST->getChain() || Tmp3 != ST->getValue() || |
| 2124 | Tmp2 != ST->getBasePtr()) { |
| 2125 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp3, Tmp2, |
| 2126 | ST->getOffset()); |
| 2127 | } |
| 2128 | |
| 2129 | MVT::ValueType StVT = cast<StoreSDNode>(Result.Val)->getStoredVT(); |
| 2130 | switch (TLI.getStoreXAction(StVT)) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2131 | default: assert(0 && "This action is not supported yet!"); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2132 | case TargetLowering::Legal: |
| 2133 | // If this is an unaligned store and the target doesn't support it, |
| 2134 | // expand it. |
| 2135 | if (!TLI.allowsUnalignedMemoryAccesses()) { |
| 2136 | unsigned ABIAlignment = TLI.getTargetData()-> |
| 2137 | getABITypeAlignment(MVT::getTypeForValueType(ST->getStoredVT())); |
| 2138 | if (ST->getAlignment() < ABIAlignment) |
| 2139 | Result = ExpandUnalignedStore(cast<StoreSDNode>(Result.Val), DAG, |
| 2140 | TLI); |
| 2141 | } |
| 2142 | break; |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2143 | case TargetLowering::Custom: |
| 2144 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2145 | if (Tmp1.Val) Result = Tmp1; |
| 2146 | break; |
Evan Cheng | f3fd9fe | 2005-12-23 07:29:34 +0000 | [diff] [blame] | 2147 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2148 | } |
| 2149 | break; |
Evan Cheng | f3fd9fe | 2005-12-23 07:29:34 +0000 | [diff] [blame] | 2150 | } |
Andrew Lenharth | 9576212 | 2005-03-31 21:24:06 +0000 | [diff] [blame] | 2151 | case ISD::PCMARKER: |
| 2152 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2153 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
Andrew Lenharth | 9576212 | 2005-03-31 21:24:06 +0000 | [diff] [blame] | 2154 | break; |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2155 | case ISD::STACKSAVE: |
| 2156 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2157 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 2158 | Tmp1 = Result.getValue(0); |
| 2159 | Tmp2 = Result.getValue(1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2160 | |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2161 | switch (TLI.getOperationAction(ISD::STACKSAVE, MVT::Other)) { |
| 2162 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2163 | case TargetLowering::Legal: break; |
| 2164 | case TargetLowering::Custom: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2165 | Tmp3 = TLI.LowerOperation(Result, DAG); |
| 2166 | if (Tmp3.Val) { |
| 2167 | Tmp1 = LegalizeOp(Tmp3); |
| 2168 | Tmp2 = LegalizeOp(Tmp3.getValue(1)); |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2169 | } |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2170 | break; |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2171 | case TargetLowering::Expand: |
Chris Lattner | 4f0d8e4 | 2006-01-13 17:48:44 +0000 | [diff] [blame] | 2172 | // Expand to CopyFromReg if the target set |
| 2173 | // StackPointerRegisterToSaveRestore. |
| 2174 | if (unsigned SP = TLI.getStackPointerRegisterToSaveRestore()) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2175 | Tmp1 = DAG.getCopyFromReg(Result.getOperand(0), SP, |
Chris Lattner | 4f0d8e4 | 2006-01-13 17:48:44 +0000 | [diff] [blame] | 2176 | Node->getValueType(0)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2177 | Tmp2 = Tmp1.getValue(1); |
Chris Lattner | 4f0d8e4 | 2006-01-13 17:48:44 +0000 | [diff] [blame] | 2178 | } else { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2179 | Tmp1 = DAG.getNode(ISD::UNDEF, Node->getValueType(0)); |
| 2180 | Tmp2 = Node->getOperand(0); |
Chris Lattner | 4f0d8e4 | 2006-01-13 17:48:44 +0000 | [diff] [blame] | 2181 | } |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2182 | break; |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2183 | } |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2184 | |
| 2185 | // Since stacksave produce two values, make sure to remember that we |
| 2186 | // legalized both of them. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2187 | AddLegalizedOperand(SDOperand(Node, 0), Tmp1); |
| 2188 | AddLegalizedOperand(SDOperand(Node, 1), Tmp2); |
| 2189 | return Op.ResNo ? Tmp2 : Tmp1; |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2190 | |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2191 | case ISD::STACKRESTORE: |
| 2192 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 2193 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2194 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2195 | |
| 2196 | switch (TLI.getOperationAction(ISD::STACKRESTORE, MVT::Other)) { |
| 2197 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2198 | case TargetLowering::Legal: break; |
| 2199 | case TargetLowering::Custom: |
| 2200 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2201 | if (Tmp1.Val) Result = Tmp1; |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2202 | break; |
| 2203 | case TargetLowering::Expand: |
Chris Lattner | 4f0d8e4 | 2006-01-13 17:48:44 +0000 | [diff] [blame] | 2204 | // Expand to CopyToReg if the target set |
| 2205 | // StackPointerRegisterToSaveRestore. |
| 2206 | if (unsigned SP = TLI.getStackPointerRegisterToSaveRestore()) { |
| 2207 | Result = DAG.getCopyToReg(Tmp1, SP, Tmp2); |
| 2208 | } else { |
| 2209 | Result = Tmp1; |
| 2210 | } |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2211 | break; |
| 2212 | } |
| 2213 | break; |
| 2214 | |
Andrew Lenharth | 51b8d54 | 2005-11-11 16:47:30 +0000 | [diff] [blame] | 2215 | case ISD::READCYCLECOUNTER: |
| 2216 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2217 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Evan Cheng | f0b3ba6 | 2006-11-29 08:26:18 +0000 | [diff] [blame] | 2218 | switch (TLI.getOperationAction(ISD::READCYCLECOUNTER, |
| 2219 | Node->getValueType(0))) { |
| 2220 | default: assert(0 && "This action is not supported yet!"); |
Evan Cheng | 6a16c5a | 2006-11-29 19:13:47 +0000 | [diff] [blame] | 2221 | case TargetLowering::Legal: |
| 2222 | Tmp1 = Result.getValue(0); |
| 2223 | Tmp2 = Result.getValue(1); |
| 2224 | break; |
Evan Cheng | f0b3ba6 | 2006-11-29 08:26:18 +0000 | [diff] [blame] | 2225 | case TargetLowering::Custom: |
| 2226 | Result = TLI.LowerOperation(Result, DAG); |
Evan Cheng | 6a16c5a | 2006-11-29 19:13:47 +0000 | [diff] [blame] | 2227 | Tmp1 = LegalizeOp(Result.getValue(0)); |
| 2228 | Tmp2 = LegalizeOp(Result.getValue(1)); |
Evan Cheng | f0b3ba6 | 2006-11-29 08:26:18 +0000 | [diff] [blame] | 2229 | break; |
| 2230 | } |
Andrew Lenharth | 49c709f | 2005-12-02 04:56:24 +0000 | [diff] [blame] | 2231 | |
| 2232 | // Since rdcc produce two values, make sure to remember that we legalized |
| 2233 | // both of them. |
Evan Cheng | 6a16c5a | 2006-11-29 19:13:47 +0000 | [diff] [blame] | 2234 | AddLegalizedOperand(SDOperand(Node, 0), Tmp1); |
| 2235 | AddLegalizedOperand(SDOperand(Node, 1), Tmp2); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2236 | return Result; |
Andrew Lenharth | f70e30b | 2005-11-20 21:32:07 +0000 | [diff] [blame] | 2237 | |
Chris Lattner | 2ee743f | 2005-01-14 22:08:15 +0000 | [diff] [blame] | 2238 | case ISD::SELECT: |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 2239 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 2240 | case Expand: assert(0 && "It's impossible to expand bools"); |
| 2241 | case Legal: |
| 2242 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the condition. |
| 2243 | break; |
| 2244 | case Promote: |
| 2245 | Tmp1 = PromoteOp(Node->getOperand(0)); // Promote the condition. |
Chris Lattner | b6c8060 | 2006-11-28 01:03:30 +0000 | [diff] [blame] | 2246 | // Make sure the condition is either zero or one. |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2247 | if (!DAG.MaskedValueIsZero(Tmp1, |
Chris Lattner | b6c8060 | 2006-11-28 01:03:30 +0000 | [diff] [blame] | 2248 | MVT::getIntVTBitMask(Tmp1.getValueType())^1)) |
| 2249 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, MVT::i1); |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 2250 | break; |
| 2251 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2252 | Tmp2 = LegalizeOp(Node->getOperand(1)); // TrueVal |
Chris Lattner | 2ee743f | 2005-01-14 22:08:15 +0000 | [diff] [blame] | 2253 | Tmp3 = LegalizeOp(Node->getOperand(2)); // FalseVal |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2254 | |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2255 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2256 | |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 2257 | switch (TLI.getOperationAction(ISD::SELECT, Tmp2.getValueType())) { |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2258 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2259 | case TargetLowering::Legal: break; |
| 2260 | case TargetLowering::Custom: { |
| 2261 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2262 | if (Tmp1.Val) Result = Tmp1; |
| 2263 | break; |
| 2264 | } |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 2265 | case TargetLowering::Expand: |
| 2266 | if (Tmp1.getOpcode() == ISD::SETCC) { |
| 2267 | Result = DAG.getSelectCC(Tmp1.getOperand(0), Tmp1.getOperand(1), |
| 2268 | Tmp2, Tmp3, |
| 2269 | cast<CondCodeSDNode>(Tmp1.getOperand(2))->get()); |
| 2270 | } else { |
| 2271 | Result = DAG.getSelectCC(Tmp1, |
| 2272 | DAG.getConstant(0, Tmp1.getValueType()), |
| 2273 | Tmp2, Tmp3, ISD::SETNE); |
| 2274 | } |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2275 | break; |
| 2276 | case TargetLowering::Promote: { |
| 2277 | MVT::ValueType NVT = |
| 2278 | TLI.getTypeToPromoteTo(ISD::SELECT, Tmp2.getValueType()); |
| 2279 | unsigned ExtOp, TruncOp; |
Evan Cheng | 41f6cbb | 2006-04-12 16:33:18 +0000 | [diff] [blame] | 2280 | if (MVT::isVector(Tmp2.getValueType())) { |
| 2281 | ExtOp = ISD::BIT_CONVERT; |
| 2282 | TruncOp = ISD::BIT_CONVERT; |
| 2283 | } else if (MVT::isInteger(Tmp2.getValueType())) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2284 | ExtOp = ISD::ANY_EXTEND; |
| 2285 | TruncOp = ISD::TRUNCATE; |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2286 | } else { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2287 | ExtOp = ISD::FP_EXTEND; |
| 2288 | TruncOp = ISD::FP_ROUND; |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2289 | } |
| 2290 | // Promote each of the values to the new type. |
| 2291 | Tmp2 = DAG.getNode(ExtOp, NVT, Tmp2); |
| 2292 | Tmp3 = DAG.getNode(ExtOp, NVT, Tmp3); |
| 2293 | // Perform the larger operation, then round down. |
| 2294 | Result = DAG.getNode(ISD::SELECT, NVT, Tmp1, Tmp2,Tmp3); |
| 2295 | Result = DAG.getNode(TruncOp, Node->getValueType(0), Result); |
| 2296 | break; |
| 2297 | } |
| 2298 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2299 | break; |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 2300 | case ISD::SELECT_CC: { |
| 2301 | Tmp1 = Node->getOperand(0); // LHS |
| 2302 | Tmp2 = Node->getOperand(1); // RHS |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 2303 | Tmp3 = LegalizeOp(Node->getOperand(2)); // True |
| 2304 | Tmp4 = LegalizeOp(Node->getOperand(3)); // False |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 2305 | SDOperand CC = Node->getOperand(4); |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 2306 | |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 2307 | LegalizeSetCCOperands(Tmp1, Tmp2, CC); |
| 2308 | |
| 2309 | // If we didn't get both a LHS and RHS back from LegalizeSetCCOperands, |
| 2310 | // the LHS is a legal SETCC itself. In this case, we need to compare |
| 2311 | // the result against zero to select between true and false values. |
| 2312 | if (Tmp2.Val == 0) { |
| 2313 | Tmp2 = DAG.getConstant(0, Tmp1.getValueType()); |
| 2314 | CC = DAG.getCondCode(ISD::SETNE); |
| 2315 | } |
| 2316 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3, Tmp4, CC); |
| 2317 | |
| 2318 | // Everything is legal, see if we should expand this op or something. |
| 2319 | switch (TLI.getOperationAction(ISD::SELECT_CC, Tmp3.getValueType())) { |
| 2320 | default: assert(0 && "This action is not supported yet!"); |
| 2321 | case TargetLowering::Legal: break; |
| 2322 | case TargetLowering::Custom: |
| 2323 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2324 | if (Tmp1.Val) Result = Tmp1; |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 2325 | break; |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 2326 | } |
| 2327 | break; |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 2328 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2329 | case ISD::SETCC: |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 2330 | Tmp1 = Node->getOperand(0); |
| 2331 | Tmp2 = Node->getOperand(1); |
| 2332 | Tmp3 = Node->getOperand(2); |
| 2333 | LegalizeSetCCOperands(Tmp1, Tmp2, Tmp3); |
| 2334 | |
| 2335 | // If we had to Expand the SetCC operands into a SELECT node, then it may |
| 2336 | // not always be possible to return a true LHS & RHS. In this case, just |
| 2337 | // return the value we legalized, returned in the LHS |
| 2338 | if (Tmp2.Val == 0) { |
| 2339 | Result = Tmp1; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2340 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2341 | } |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 2342 | |
Chris Lattner | 73e142f | 2006-01-30 22:43:50 +0000 | [diff] [blame] | 2343 | switch (TLI.getOperationAction(ISD::SETCC, Tmp1.getValueType())) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2344 | default: assert(0 && "Cannot handle this action for SETCC yet!"); |
| 2345 | case TargetLowering::Custom: |
| 2346 | isCustom = true; |
| 2347 | // FALLTHROUGH. |
| 2348 | case TargetLowering::Legal: |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 2349 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2350 | if (isCustom) { |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 2351 | Tmp4 = TLI.LowerOperation(Result, DAG); |
| 2352 | if (Tmp4.Val) Result = Tmp4; |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2353 | } |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 2354 | break; |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 2355 | case TargetLowering::Promote: { |
| 2356 | // First step, figure out the appropriate operation to use. |
| 2357 | // Allow SETCC to not be supported for all legal data types |
| 2358 | // Mostly this targets FP |
| 2359 | MVT::ValueType NewInTy = Node->getOperand(0).getValueType(); |
Chris Lattner | 00755df | 2007-02-04 00:27:56 +0000 | [diff] [blame] | 2360 | MVT::ValueType OldVT = NewInTy; OldVT = OldVT; |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 2361 | |
| 2362 | // Scan for the appropriate larger type to use. |
| 2363 | while (1) { |
| 2364 | NewInTy = (MVT::ValueType)(NewInTy+1); |
| 2365 | |
| 2366 | assert(MVT::isInteger(NewInTy) == MVT::isInteger(OldVT) && |
| 2367 | "Fell off of the edge of the integer world"); |
| 2368 | assert(MVT::isFloatingPoint(NewInTy) == MVT::isFloatingPoint(OldVT) && |
| 2369 | "Fell off of the edge of the floating point world"); |
| 2370 | |
| 2371 | // If the target supports SETCC of this type, use it. |
Chris Lattner | 1ccf26a | 2005-12-22 05:23:45 +0000 | [diff] [blame] | 2372 | if (TLI.isOperationLegal(ISD::SETCC, NewInTy)) |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 2373 | break; |
| 2374 | } |
| 2375 | if (MVT::isInteger(NewInTy)) |
| 2376 | assert(0 && "Cannot promote Legal Integer SETCC yet"); |
| 2377 | else { |
| 2378 | Tmp1 = DAG.getNode(ISD::FP_EXTEND, NewInTy, Tmp1); |
| 2379 | Tmp2 = DAG.getNode(ISD::FP_EXTEND, NewInTy, Tmp2); |
| 2380 | } |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2381 | Tmp1 = LegalizeOp(Tmp1); |
| 2382 | Tmp2 = LegalizeOp(Tmp2); |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 2383 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Evan Cheng | 433f8ac | 2006-01-17 19:47:13 +0000 | [diff] [blame] | 2384 | Result = LegalizeOp(Result); |
Andrew Lenharth | 5e3efbc | 2005-08-29 20:46:51 +0000 | [diff] [blame] | 2385 | break; |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 2386 | } |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 2387 | case TargetLowering::Expand: |
| 2388 | // Expand a setcc node into a select_cc of the same condition, lhs, and |
| 2389 | // rhs that selects between const 1 (true) and const 0 (false). |
| 2390 | MVT::ValueType VT = Node->getValueType(0); |
| 2391 | Result = DAG.getNode(ISD::SELECT_CC, VT, Tmp1, Tmp2, |
| 2392 | DAG.getConstant(1, VT), DAG.getConstant(0, VT), |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 2393 | Tmp3); |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 2394 | break; |
| 2395 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2396 | break; |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 2397 | case ISD::MEMSET: |
| 2398 | case ISD::MEMCPY: |
| 2399 | case ISD::MEMMOVE: { |
Chris Lattner | deb692e | 2005-02-01 18:38:28 +0000 | [diff] [blame] | 2400 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Chain |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 2401 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Pointer |
| 2402 | |
| 2403 | if (Node->getOpcode() == ISD::MEMSET) { // memset = ubyte |
| 2404 | switch (getTypeAction(Node->getOperand(2).getValueType())) { |
| 2405 | case Expand: assert(0 && "Cannot expand a byte!"); |
| 2406 | case Legal: |
Chris Lattner | deb692e | 2005-02-01 18:38:28 +0000 | [diff] [blame] | 2407 | Tmp3 = LegalizeOp(Node->getOperand(2)); |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 2408 | break; |
| 2409 | case Promote: |
Chris Lattner | deb692e | 2005-02-01 18:38:28 +0000 | [diff] [blame] | 2410 | Tmp3 = PromoteOp(Node->getOperand(2)); |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 2411 | break; |
| 2412 | } |
| 2413 | } else { |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2414 | Tmp3 = LegalizeOp(Node->getOperand(2)); // memcpy/move = pointer, |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 2415 | } |
Chris Lattner | 272455b | 2005-02-02 03:44:41 +0000 | [diff] [blame] | 2416 | |
| 2417 | SDOperand Tmp4; |
| 2418 | switch (getTypeAction(Node->getOperand(3).getValueType())) { |
Chris Lattner | 6814f15 | 2005-07-13 01:42:45 +0000 | [diff] [blame] | 2419 | case Expand: { |
| 2420 | // Length is too big, just take the lo-part of the length. |
| 2421 | SDOperand HiPart; |
Chris Lattner | fa9aa2b | 2006-11-07 04:11:44 +0000 | [diff] [blame] | 2422 | ExpandOp(Node->getOperand(3), Tmp4, HiPart); |
Chris Lattner | 6814f15 | 2005-07-13 01:42:45 +0000 | [diff] [blame] | 2423 | break; |
| 2424 | } |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 2425 | case Legal: |
| 2426 | Tmp4 = LegalizeOp(Node->getOperand(3)); |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 2427 | break; |
| 2428 | case Promote: |
| 2429 | Tmp4 = PromoteOp(Node->getOperand(3)); |
Chris Lattner | 272455b | 2005-02-02 03:44:41 +0000 | [diff] [blame] | 2430 | break; |
| 2431 | } |
| 2432 | |
| 2433 | SDOperand Tmp5; |
| 2434 | switch (getTypeAction(Node->getOperand(4).getValueType())) { // uint |
| 2435 | case Expand: assert(0 && "Cannot expand this yet!"); |
| 2436 | case Legal: |
| 2437 | Tmp5 = LegalizeOp(Node->getOperand(4)); |
| 2438 | break; |
| 2439 | case Promote: |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 2440 | Tmp5 = PromoteOp(Node->getOperand(4)); |
| 2441 | break; |
| 2442 | } |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2443 | |
| 2444 | switch (TLI.getOperationAction(Node->getOpcode(), MVT::Other)) { |
| 2445 | default: assert(0 && "This action not implemented for this operation!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2446 | case TargetLowering::Custom: |
| 2447 | isCustom = true; |
| 2448 | // FALLTHROUGH |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2449 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2450 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3, Tmp4, Tmp5); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2451 | if (isCustom) { |
| 2452 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2453 | if (Tmp1.Val) Result = Tmp1; |
| 2454 | } |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2455 | break; |
| 2456 | case TargetLowering::Expand: { |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 2457 | // Otherwise, the target does not support this operation. Lower the |
| 2458 | // operation to an explicit libcall as appropriate. |
| 2459 | MVT::ValueType IntPtr = TLI.getPointerTy(); |
Owen Anderson | a69571c | 2006-05-03 01:29:57 +0000 | [diff] [blame] | 2460 | const Type *IntPtrTy = TLI.getTargetData()->getIntPtrType(); |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 2461 | TargetLowering::ArgListTy Args; |
| 2462 | TargetLowering::ArgListEntry Entry; |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 2463 | |
Reid Spencer | 3bfbf4e | 2005-01-12 14:53:45 +0000 | [diff] [blame] | 2464 | const char *FnName = 0; |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 2465 | if (Node->getOpcode() == ISD::MEMSET) { |
Anton Korobeynikov | d0b82b3 | 2007-03-07 16:25:09 +0000 | [diff] [blame] | 2466 | Entry.Node = Tmp2; Entry.Ty = IntPtrTy; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 2467 | Args.push_back(Entry); |
Chris Lattner | dca7abe | 2006-02-20 06:38:35 +0000 | [diff] [blame] | 2468 | // Extend the (previously legalized) ubyte argument to be an int value |
| 2469 | // for the call. |
| 2470 | if (Tmp3.getValueType() > MVT::i32) |
| 2471 | Tmp3 = DAG.getNode(ISD::TRUNCATE, MVT::i32, Tmp3); |
| 2472 | else |
| 2473 | Tmp3 = DAG.getNode(ISD::ZERO_EXTEND, MVT::i32, Tmp3); |
Anton Korobeynikov | d0b82b3 | 2007-03-07 16:25:09 +0000 | [diff] [blame] | 2474 | Entry.Node = Tmp3; Entry.Ty = Type::Int32Ty; Entry.isSExt = true; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 2475 | Args.push_back(Entry); |
Anton Korobeynikov | d0b82b3 | 2007-03-07 16:25:09 +0000 | [diff] [blame] | 2476 | Entry.Node = Tmp4; Entry.Ty = IntPtrTy; Entry.isSExt = false; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 2477 | Args.push_back(Entry); |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 2478 | |
| 2479 | FnName = "memset"; |
| 2480 | } else if (Node->getOpcode() == ISD::MEMCPY || |
| 2481 | Node->getOpcode() == ISD::MEMMOVE) { |
Anton Korobeynikov | b25fe82 | 2007-02-01 08:39:52 +0000 | [diff] [blame] | 2482 | Entry.Ty = IntPtrTy; |
Reid Spencer | b47b25c | 2007-01-03 04:22:32 +0000 | [diff] [blame] | 2483 | Entry.Node = Tmp2; Args.push_back(Entry); |
| 2484 | Entry.Node = Tmp3; Args.push_back(Entry); |
| 2485 | Entry.Node = Tmp4; Args.push_back(Entry); |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 2486 | FnName = Node->getOpcode() == ISD::MEMMOVE ? "memmove" : "memcpy"; |
| 2487 | } else { |
| 2488 | assert(0 && "Unknown op!"); |
| 2489 | } |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 2490 | |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 2491 | std::pair<SDOperand,SDOperand> CallResult = |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 2492 | TLI.LowerCallTo(Tmp1, Type::VoidTy, false, false, CallingConv::C, false, |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 2493 | DAG.getExternalSymbol(FnName, IntPtr), Args, DAG); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2494 | Result = CallResult.second; |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2495 | break; |
| 2496 | } |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 2497 | } |
| 2498 | break; |
| 2499 | } |
Chris Lattner | 52d08bd | 2005-05-09 20:23:03 +0000 | [diff] [blame] | 2500 | |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 2501 | case ISD::SHL_PARTS: |
| 2502 | case ISD::SRA_PARTS: |
| 2503 | case ISD::SRL_PARTS: { |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 2504 | SmallVector<SDOperand, 8> Ops; |
Chris Lattner | 84f6788 | 2005-01-20 18:52:28 +0000 | [diff] [blame] | 2505 | bool Changed = false; |
| 2506 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) { |
| 2507 | Ops.push_back(LegalizeOp(Node->getOperand(i))); |
| 2508 | Changed |= Ops.back() != Node->getOperand(i); |
| 2509 | } |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2510 | if (Changed) |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 2511 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 2512 | |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 2513 | switch (TLI.getOperationAction(Node->getOpcode(), |
| 2514 | Node->getValueType(0))) { |
| 2515 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2516 | case TargetLowering::Legal: break; |
| 2517 | case TargetLowering::Custom: |
| 2518 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2519 | if (Tmp1.Val) { |
| 2520 | SDOperand Tmp2, RetVal(0, 0); |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 2521 | for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2522 | Tmp2 = LegalizeOp(Tmp1.getValue(i)); |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 2523 | AddLegalizedOperand(SDOperand(Node, i), Tmp2); |
| 2524 | if (i == Op.ResNo) |
Evan Cheng | 12f2274 | 2006-01-19 04:54:52 +0000 | [diff] [blame] | 2525 | RetVal = Tmp2; |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 2526 | } |
Chris Lattner | 269f8c0 | 2006-01-10 19:43:26 +0000 | [diff] [blame] | 2527 | assert(RetVal.Val && "Illegal result number"); |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 2528 | return RetVal; |
| 2529 | } |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 2530 | break; |
| 2531 | } |
| 2532 | |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 2533 | // Since these produce multiple values, make sure to remember that we |
| 2534 | // legalized all of them. |
| 2535 | for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) |
| 2536 | AddLegalizedOperand(SDOperand(Node, i), Result.getValue(i)); |
| 2537 | return Result.getValue(Op.ResNo); |
Chris Lattner | 84f6788 | 2005-01-20 18:52:28 +0000 | [diff] [blame] | 2538 | } |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 2539 | |
| 2540 | // Binary operators |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2541 | case ISD::ADD: |
| 2542 | case ISD::SUB: |
| 2543 | case ISD::MUL: |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 2544 | case ISD::MULHS: |
| 2545 | case ISD::MULHU: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2546 | case ISD::UDIV: |
| 2547 | case ISD::SDIV: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2548 | case ISD::AND: |
| 2549 | case ISD::OR: |
| 2550 | case ISD::XOR: |
Chris Lattner | 03c0cf8 | 2005-01-07 21:45:56 +0000 | [diff] [blame] | 2551 | case ISD::SHL: |
| 2552 | case ISD::SRL: |
| 2553 | case ISD::SRA: |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 2554 | case ISD::FADD: |
| 2555 | case ISD::FSUB: |
| 2556 | case ISD::FMUL: |
| 2557 | case ISD::FDIV: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2558 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
Andrew Lenharth | f2eb139 | 2005-07-05 19:52:39 +0000 | [diff] [blame] | 2559 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 2560 | case Expand: assert(0 && "Not possible"); |
| 2561 | case Legal: |
| 2562 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the RHS. |
| 2563 | break; |
| 2564 | case Promote: |
| 2565 | Tmp2 = PromoteOp(Node->getOperand(1)); // Promote the RHS. |
| 2566 | break; |
| 2567 | } |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2568 | |
| 2569 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2570 | |
Andrew Lenharth | e8f65f1 | 2005-12-24 23:42:32 +0000 | [diff] [blame] | 2571 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
Chris Lattner | bc70cf8 | 2006-04-02 03:57:31 +0000 | [diff] [blame] | 2572 | default: assert(0 && "BinOp legalize operation not supported"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2573 | case TargetLowering::Legal: break; |
| 2574 | case TargetLowering::Custom: |
| 2575 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2576 | if (Tmp1.Val) Result = Tmp1; |
Andrew Lenharth | 57030e3 | 2005-12-25 01:07:37 +0000 | [diff] [blame] | 2577 | break; |
Chris Lattner | bc70cf8 | 2006-04-02 03:57:31 +0000 | [diff] [blame] | 2578 | case TargetLowering::Expand: { |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 2579 | if (Node->getValueType(0) == MVT::i32) { |
| 2580 | switch (Node->getOpcode()) { |
| 2581 | default: assert(0 && "Do not know how to expand this integer BinOp!"); |
| 2582 | case ISD::UDIV: |
| 2583 | case ISD::SDIV: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 2584 | RTLIB::Libcall LC = Node->getOpcode() == ISD::UDIV |
| 2585 | ? RTLIB::UDIV_I32 : RTLIB::SDIV_I32; |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 2586 | SDOperand Dummy; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 2587 | bool isSigned = Node->getOpcode() == ISD::SDIV; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 2588 | Result = ExpandLibCall(TLI.getLibcallName(LC), Node, isSigned, Dummy); |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 2589 | }; |
| 2590 | break; |
| 2591 | } |
| 2592 | |
Chris Lattner | bc70cf8 | 2006-04-02 03:57:31 +0000 | [diff] [blame] | 2593 | assert(MVT::isVector(Node->getValueType(0)) && |
| 2594 | "Cannot expand this binary operator!"); |
| 2595 | // Expand the operation into a bunch of nasty scalar code. |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 2596 | SmallVector<SDOperand, 8> Ops; |
Dan Gohman | 51eaa86 | 2007-06-14 22:58:02 +0000 | [diff] [blame] | 2597 | MVT::ValueType EltVT = MVT::getVectorElementType(Node->getValueType(0)); |
Chris Lattner | bc70cf8 | 2006-04-02 03:57:31 +0000 | [diff] [blame] | 2598 | MVT::ValueType PtrVT = TLI.getPointerTy(); |
| 2599 | for (unsigned i = 0, e = MVT::getVectorNumElements(Node->getValueType(0)); |
| 2600 | i != e; ++i) { |
| 2601 | SDOperand Idx = DAG.getConstant(i, PtrVT); |
| 2602 | SDOperand LHS = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, EltVT, Tmp1, Idx); |
| 2603 | SDOperand RHS = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, EltVT, Tmp2, Idx); |
| 2604 | Ops.push_back(DAG.getNode(Node->getOpcode(), EltVT, LHS, RHS)); |
| 2605 | } |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 2606 | Result = DAG.getNode(ISD::BUILD_VECTOR, Node->getValueType(0), |
| 2607 | &Ops[0], Ops.size()); |
Chris Lattner | bc70cf8 | 2006-04-02 03:57:31 +0000 | [diff] [blame] | 2608 | break; |
| 2609 | } |
Evan Cheng | cc98761 | 2006-04-12 21:20:24 +0000 | [diff] [blame] | 2610 | case TargetLowering::Promote: { |
| 2611 | switch (Node->getOpcode()) { |
| 2612 | default: assert(0 && "Do not know how to promote this BinOp!"); |
| 2613 | case ISD::AND: |
| 2614 | case ISD::OR: |
| 2615 | case ISD::XOR: { |
| 2616 | MVT::ValueType OVT = Node->getValueType(0); |
| 2617 | MVT::ValueType NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT); |
| 2618 | assert(MVT::isVector(OVT) && "Cannot promote this BinOp!"); |
| 2619 | // Bit convert each of the values to the new type. |
| 2620 | Tmp1 = DAG.getNode(ISD::BIT_CONVERT, NVT, Tmp1); |
| 2621 | Tmp2 = DAG.getNode(ISD::BIT_CONVERT, NVT, Tmp2); |
| 2622 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 2623 | // Bit convert the result back the original type. |
| 2624 | Result = DAG.getNode(ISD::BIT_CONVERT, OVT, Result); |
| 2625 | break; |
| 2626 | } |
| 2627 | } |
| 2628 | } |
Andrew Lenharth | e8f65f1 | 2005-12-24 23:42:32 +0000 | [diff] [blame] | 2629 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2630 | break; |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 2631 | |
| 2632 | case ISD::FCOPYSIGN: // FCOPYSIGN does not require LHS/RHS to match type! |
| 2633 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
| 2634 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 2635 | case Expand: assert(0 && "Not possible"); |
| 2636 | case Legal: |
| 2637 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the RHS. |
| 2638 | break; |
| 2639 | case Promote: |
| 2640 | Tmp2 = PromoteOp(Node->getOperand(1)); // Promote the RHS. |
| 2641 | break; |
| 2642 | } |
| 2643 | |
| 2644 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 2645 | |
| 2646 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 2647 | default: assert(0 && "Operation not supported"); |
| 2648 | case TargetLowering::Custom: |
| 2649 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2650 | if (Tmp1.Val) Result = Tmp1; |
Chris Lattner | 8f4191d | 2006-03-13 06:08:38 +0000 | [diff] [blame] | 2651 | break; |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 2652 | case TargetLowering::Legal: break; |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 2653 | case TargetLowering::Expand: { |
Evan Cheng | 636c753 | 2007-01-05 23:33:44 +0000 | [diff] [blame] | 2654 | // If this target supports fabs/fneg natively and select is cheap, |
| 2655 | // do this efficiently. |
| 2656 | if (!TLI.isSelectExpensive() && |
| 2657 | TLI.getOperationAction(ISD::FABS, Tmp1.getValueType()) == |
| 2658 | TargetLowering::Legal && |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 2659 | TLI.getOperationAction(ISD::FNEG, Tmp1.getValueType()) == |
Evan Cheng | 636c753 | 2007-01-05 23:33:44 +0000 | [diff] [blame] | 2660 | TargetLowering::Legal) { |
Chris Lattner | 8f4191d | 2006-03-13 06:08:38 +0000 | [diff] [blame] | 2661 | // Get the sign bit of the RHS. |
| 2662 | MVT::ValueType IVT = |
| 2663 | Tmp2.getValueType() == MVT::f32 ? MVT::i32 : MVT::i64; |
| 2664 | SDOperand SignBit = DAG.getNode(ISD::BIT_CONVERT, IVT, Tmp2); |
| 2665 | SignBit = DAG.getSetCC(TLI.getSetCCResultTy(), |
| 2666 | SignBit, DAG.getConstant(0, IVT), ISD::SETLT); |
| 2667 | // Get the absolute value of the result. |
| 2668 | SDOperand AbsVal = DAG.getNode(ISD::FABS, Tmp1.getValueType(), Tmp1); |
| 2669 | // Select between the nabs and abs value based on the sign bit of |
| 2670 | // the input. |
| 2671 | Result = DAG.getNode(ISD::SELECT, AbsVal.getValueType(), SignBit, |
| 2672 | DAG.getNode(ISD::FNEG, AbsVal.getValueType(), |
| 2673 | AbsVal), |
| 2674 | AbsVal); |
| 2675 | Result = LegalizeOp(Result); |
| 2676 | break; |
| 2677 | } |
| 2678 | |
| 2679 | // Otherwise, do bitwise ops! |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 2680 | MVT::ValueType NVT = |
| 2681 | Node->getValueType(0) == MVT::f32 ? MVT::i32 : MVT::i64; |
| 2682 | Result = ExpandFCOPYSIGNToBitwiseOps(Node, NVT, DAG, TLI); |
| 2683 | Result = DAG.getNode(ISD::BIT_CONVERT, Node->getValueType(0), Result); |
| 2684 | Result = LegalizeOp(Result); |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 2685 | break; |
| 2686 | } |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 2687 | } |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 2688 | break; |
| 2689 | |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 2690 | case ISD::ADDC: |
| 2691 | case ISD::SUBC: |
| 2692 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 2693 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 2694 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 2695 | // Since this produces two values, make sure to remember that we legalized |
| 2696 | // both of them. |
| 2697 | AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0)); |
| 2698 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
| 2699 | return Result; |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2700 | |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 2701 | case ISD::ADDE: |
| 2702 | case ISD::SUBE: |
| 2703 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 2704 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 2705 | Tmp3 = LegalizeOp(Node->getOperand(2)); |
| 2706 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
| 2707 | // Since this produces two values, make sure to remember that we legalized |
| 2708 | // both of them. |
| 2709 | AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0)); |
| 2710 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
| 2711 | return Result; |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 2712 | |
Nate Begeman | 419f8b6 | 2005-10-18 00:27:41 +0000 | [diff] [blame] | 2713 | case ISD::BUILD_PAIR: { |
| 2714 | MVT::ValueType PairTy = Node->getValueType(0); |
| 2715 | // TODO: handle the case where the Lo and Hi operands are not of legal type |
| 2716 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Lo |
| 2717 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Hi |
| 2718 | switch (TLI.getOperationAction(ISD::BUILD_PAIR, PairTy)) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2719 | case TargetLowering::Promote: |
| 2720 | case TargetLowering::Custom: |
| 2721 | assert(0 && "Cannot promote/custom this yet!"); |
Nate Begeman | 419f8b6 | 2005-10-18 00:27:41 +0000 | [diff] [blame] | 2722 | case TargetLowering::Legal: |
| 2723 | if (Tmp1 != Node->getOperand(0) || Tmp2 != Node->getOperand(1)) |
| 2724 | Result = DAG.getNode(ISD::BUILD_PAIR, PairTy, Tmp1, Tmp2); |
| 2725 | break; |
Nate Begeman | 419f8b6 | 2005-10-18 00:27:41 +0000 | [diff] [blame] | 2726 | case TargetLowering::Expand: |
| 2727 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, PairTy, Tmp1); |
| 2728 | Tmp2 = DAG.getNode(ISD::ANY_EXTEND, PairTy, Tmp2); |
| 2729 | Tmp2 = DAG.getNode(ISD::SHL, PairTy, Tmp2, |
| 2730 | DAG.getConstant(MVT::getSizeInBits(PairTy)/2, |
| 2731 | TLI.getShiftAmountTy())); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2732 | Result = DAG.getNode(ISD::OR, PairTy, Tmp1, Tmp2); |
Nate Begeman | 419f8b6 | 2005-10-18 00:27:41 +0000 | [diff] [blame] | 2733 | break; |
| 2734 | } |
| 2735 | break; |
| 2736 | } |
| 2737 | |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 2738 | case ISD::UREM: |
| 2739 | case ISD::SREM: |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 2740 | case ISD::FREM: |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 2741 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
| 2742 | Tmp2 = LegalizeOp(Node->getOperand(1)); // RHS |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2743 | |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 2744 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2745 | case TargetLowering::Promote: assert(0 && "Cannot promote this yet!"); |
| 2746 | case TargetLowering::Custom: |
| 2747 | isCustom = true; |
| 2748 | // FALLTHROUGH |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 2749 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2750 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2751 | if (isCustom) { |
| 2752 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2753 | if (Tmp1.Val) Result = Tmp1; |
| 2754 | } |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 2755 | break; |
Chris Lattner | 4c64dd7 | 2005-08-03 20:31:37 +0000 | [diff] [blame] | 2756 | case TargetLowering::Expand: |
Evan Cheng | 6b5578f | 2006-09-18 23:28:33 +0000 | [diff] [blame] | 2757 | unsigned DivOpc= (Node->getOpcode() == ISD::UREM) ? ISD::UDIV : ISD::SDIV; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 2758 | bool isSigned = DivOpc == ISD::SDIV; |
Chris Lattner | 4c64dd7 | 2005-08-03 20:31:37 +0000 | [diff] [blame] | 2759 | if (MVT::isInteger(Node->getValueType(0))) { |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 2760 | if (TLI.getOperationAction(DivOpc, Node->getValueType(0)) == |
| 2761 | TargetLowering::Legal) { |
| 2762 | // X % Y -> X-X/Y*Y |
| 2763 | MVT::ValueType VT = Node->getValueType(0); |
Evan Cheng | 6b5578f | 2006-09-18 23:28:33 +0000 | [diff] [blame] | 2764 | Result = DAG.getNode(DivOpc, VT, Tmp1, Tmp2); |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 2765 | Result = DAG.getNode(ISD::MUL, VT, Result, Tmp2); |
| 2766 | Result = DAG.getNode(ISD::SUB, VT, Tmp1, Result); |
| 2767 | } else { |
| 2768 | assert(Node->getValueType(0) == MVT::i32 && |
| 2769 | "Cannot expand this binary operator!"); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 2770 | RTLIB::Libcall LC = Node->getOpcode() == ISD::UREM |
| 2771 | ? RTLIB::UREM_I32 : RTLIB::SREM_I32; |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 2772 | SDOperand Dummy; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 2773 | Result = ExpandLibCall(TLI.getLibcallName(LC), Node, isSigned, Dummy); |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 2774 | } |
Chris Lattner | 4c64dd7 | 2005-08-03 20:31:37 +0000 | [diff] [blame] | 2775 | } else { |
| 2776 | // Floating point mod -> fmod libcall. |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 2777 | RTLIB::Libcall LC = Node->getValueType(0) == MVT::f32 |
| 2778 | ? RTLIB::REM_F32 : RTLIB::REM_F64; |
Chris Lattner | 4c64dd7 | 2005-08-03 20:31:37 +0000 | [diff] [blame] | 2779 | SDOperand Dummy; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 2780 | Result = ExpandLibCall(TLI.getLibcallName(LC), Node, |
| 2781 | false/*sign irrelevant*/, Dummy); |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 2782 | } |
| 2783 | break; |
| 2784 | } |
| 2785 | break; |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 2786 | case ISD::VAARG: { |
| 2787 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 2788 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. |
| 2789 | |
Chris Lattner | 5c62f33 | 2006-01-28 07:42:08 +0000 | [diff] [blame] | 2790 | MVT::ValueType VT = Node->getValueType(0); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 2791 | switch (TLI.getOperationAction(Node->getOpcode(), MVT::Other)) { |
| 2792 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2793 | case TargetLowering::Custom: |
| 2794 | isCustom = true; |
| 2795 | // FALLTHROUGH |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 2796 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2797 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
| 2798 | Result = Result.getValue(0); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2799 | Tmp1 = Result.getValue(1); |
| 2800 | |
| 2801 | if (isCustom) { |
| 2802 | Tmp2 = TLI.LowerOperation(Result, DAG); |
| 2803 | if (Tmp2.Val) { |
| 2804 | Result = LegalizeOp(Tmp2); |
| 2805 | Tmp1 = LegalizeOp(Tmp2.getValue(1)); |
| 2806 | } |
| 2807 | } |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 2808 | break; |
| 2809 | case TargetLowering::Expand: { |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2810 | SrcValueSDNode *SV = cast<SrcValueSDNode>(Node->getOperand(2)); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 2811 | SDOperand VAList = DAG.getLoad(TLI.getPointerTy(), Tmp1, Tmp2, |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2812 | SV->getValue(), SV->getOffset()); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 2813 | // Increment the pointer, VAList, to the next vaarg |
| 2814 | Tmp3 = DAG.getNode(ISD::ADD, TLI.getPointerTy(), VAList, |
| 2815 | DAG.getConstant(MVT::getSizeInBits(VT)/8, |
| 2816 | TLI.getPointerTy())); |
| 2817 | // Store the incremented VAList to the legalized pointer |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2818 | Tmp3 = DAG.getStore(VAList.getValue(1), Tmp3, Tmp2, SV->getValue(), |
| 2819 | SV->getOffset()); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 2820 | // Load the actual argument out of the pointer VAList |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2821 | Result = DAG.getLoad(VT, Tmp3, VAList, NULL, 0); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2822 | Tmp1 = LegalizeOp(Result.getValue(1)); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 2823 | Result = LegalizeOp(Result); |
| 2824 | break; |
| 2825 | } |
| 2826 | } |
| 2827 | // Since VAARG produces two values, make sure to remember that we |
| 2828 | // legalized both of them. |
| 2829 | AddLegalizedOperand(SDOperand(Node, 0), Result); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2830 | AddLegalizedOperand(SDOperand(Node, 1), Tmp1); |
| 2831 | return Op.ResNo ? Tmp1 : Result; |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 2832 | } |
| 2833 | |
| 2834 | case ISD::VACOPY: |
| 2835 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 2836 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the dest pointer. |
| 2837 | Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the source pointer. |
| 2838 | |
| 2839 | switch (TLI.getOperationAction(ISD::VACOPY, MVT::Other)) { |
| 2840 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2841 | case TargetLowering::Custom: |
| 2842 | isCustom = true; |
| 2843 | // FALLTHROUGH |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 2844 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2845 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3, |
| 2846 | Node->getOperand(3), Node->getOperand(4)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2847 | if (isCustom) { |
| 2848 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2849 | if (Tmp1.Val) Result = Tmp1; |
| 2850 | } |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 2851 | break; |
| 2852 | case TargetLowering::Expand: |
| 2853 | // This defaults to loading a pointer from the input and storing it to the |
| 2854 | // output, returning the chain. |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2855 | SrcValueSDNode *SVD = cast<SrcValueSDNode>(Node->getOperand(3)); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2856 | SrcValueSDNode *SVS = cast<SrcValueSDNode>(Node->getOperand(4)); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2857 | Tmp4 = DAG.getLoad(TLI.getPointerTy(), Tmp1, Tmp3, SVD->getValue(), |
| 2858 | SVD->getOffset()); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2859 | Result = DAG.getStore(Tmp4.getValue(1), Tmp4, Tmp2, SVS->getValue(), |
| 2860 | SVS->getOffset()); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 2861 | break; |
| 2862 | } |
| 2863 | break; |
| 2864 | |
| 2865 | case ISD::VAEND: |
| 2866 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 2867 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. |
| 2868 | |
| 2869 | switch (TLI.getOperationAction(ISD::VAEND, MVT::Other)) { |
| 2870 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2871 | case TargetLowering::Custom: |
| 2872 | isCustom = true; |
| 2873 | // FALLTHROUGH |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 2874 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2875 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2876 | if (isCustom) { |
| 2877 | Tmp1 = TLI.LowerOperation(Tmp1, DAG); |
| 2878 | if (Tmp1.Val) Result = Tmp1; |
| 2879 | } |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 2880 | break; |
| 2881 | case TargetLowering::Expand: |
| 2882 | Result = Tmp1; // Default to a no-op, return the chain |
| 2883 | break; |
| 2884 | } |
| 2885 | break; |
| 2886 | |
| 2887 | case ISD::VASTART: |
| 2888 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 2889 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. |
| 2890 | |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2891 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
| 2892 | |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 2893 | switch (TLI.getOperationAction(ISD::VASTART, MVT::Other)) { |
| 2894 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2895 | case TargetLowering::Legal: break; |
| 2896 | case TargetLowering::Custom: |
| 2897 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2898 | if (Tmp1.Val) Result = Tmp1; |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 2899 | break; |
| 2900 | } |
| 2901 | break; |
| 2902 | |
Nate Begeman | 35ef913 | 2006-01-11 21:21:00 +0000 | [diff] [blame] | 2903 | case ISD::ROTL: |
| 2904 | case ISD::ROTR: |
| 2905 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
| 2906 | Tmp2 = LegalizeOp(Node->getOperand(1)); // RHS |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2907 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Scott Michel | c9dc114 | 2007-04-02 21:36:32 +0000 | [diff] [blame] | 2908 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 2909 | default: |
| 2910 | assert(0 && "ROTL/ROTR legalize operation not supported"); |
| 2911 | break; |
| 2912 | case TargetLowering::Legal: |
| 2913 | break; |
| 2914 | case TargetLowering::Custom: |
| 2915 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2916 | if (Tmp1.Val) Result = Tmp1; |
| 2917 | break; |
| 2918 | case TargetLowering::Promote: |
| 2919 | assert(0 && "Do not know how to promote ROTL/ROTR"); |
| 2920 | break; |
| 2921 | case TargetLowering::Expand: |
| 2922 | assert(0 && "Do not know how to expand ROTL/ROTR"); |
| 2923 | break; |
| 2924 | } |
Nate Begeman | 35ef913 | 2006-01-11 21:21:00 +0000 | [diff] [blame] | 2925 | break; |
| 2926 | |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 2927 | case ISD::BSWAP: |
| 2928 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Op |
| 2929 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2930 | case TargetLowering::Custom: |
| 2931 | assert(0 && "Cannot custom legalize this yet!"); |
| 2932 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2933 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2934 | break; |
| 2935 | case TargetLowering::Promote: { |
| 2936 | MVT::ValueType OVT = Tmp1.getValueType(); |
| 2937 | MVT::ValueType NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT); |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 2938 | unsigned DiffBits = MVT::getSizeInBits(NVT) - MVT::getSizeInBits(OVT); |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 2939 | |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2940 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Tmp1); |
| 2941 | Tmp1 = DAG.getNode(ISD::BSWAP, NVT, Tmp1); |
| 2942 | Result = DAG.getNode(ISD::SRL, NVT, Tmp1, |
| 2943 | DAG.getConstant(DiffBits, TLI.getShiftAmountTy())); |
| 2944 | break; |
| 2945 | } |
| 2946 | case TargetLowering::Expand: |
| 2947 | Result = ExpandBSWAP(Tmp1); |
| 2948 | break; |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 2949 | } |
| 2950 | break; |
| 2951 | |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 2952 | case ISD::CTPOP: |
| 2953 | case ISD::CTTZ: |
| 2954 | case ISD::CTLZ: |
| 2955 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Op |
| 2956 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
Scott Michel | 910b66d | 2007-07-30 21:00:31 +0000 | [diff] [blame] | 2957 | case TargetLowering::Custom: |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 2958 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2959 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Scott Michel | 910b66d | 2007-07-30 21:00:31 +0000 | [diff] [blame] | 2960 | if (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0)) == |
Scott Michel | 335f4f7 | 2007-08-02 02:22:46 +0000 | [diff] [blame] | 2961 | TargetLowering::Custom) { |
| 2962 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2963 | if (Tmp1.Val) { |
| 2964 | Result = Tmp1; |
| 2965 | } |
Scott Michel | 910b66d | 2007-07-30 21:00:31 +0000 | [diff] [blame] | 2966 | } |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 2967 | break; |
| 2968 | case TargetLowering::Promote: { |
| 2969 | MVT::ValueType OVT = Tmp1.getValueType(); |
| 2970 | MVT::ValueType NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT); |
Chris Lattner | edb1add | 2005-05-11 04:51:16 +0000 | [diff] [blame] | 2971 | |
| 2972 | // Zero extend the argument. |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 2973 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Tmp1); |
| 2974 | // Perform the larger operation, then subtract if needed. |
| 2975 | Tmp1 = DAG.getNode(Node->getOpcode(), Node->getValueType(0), Tmp1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2976 | switch (Node->getOpcode()) { |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 2977 | case ISD::CTPOP: |
| 2978 | Result = Tmp1; |
| 2979 | break; |
| 2980 | case ISD::CTTZ: |
| 2981 | //if Tmp1 == sizeinbits(NVT) then Tmp1 = sizeinbits(Old VT) |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 2982 | Tmp2 = DAG.getSetCC(TLI.getSetCCResultTy(), Tmp1, |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 2983 | DAG.getConstant(MVT::getSizeInBits(NVT), NVT), |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 2984 | ISD::SETEQ); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 2985 | Result = DAG.getNode(ISD::SELECT, NVT, Tmp2, |
Scott Michel | 910b66d | 2007-07-30 21:00:31 +0000 | [diff] [blame] | 2986 | DAG.getConstant(MVT::getSizeInBits(OVT),NVT), Tmp1); |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 2987 | break; |
| 2988 | case ISD::CTLZ: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2989 | // Tmp1 = Tmp1 - (sizeinbits(NVT) - sizeinbits(Old VT)) |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 2990 | Result = DAG.getNode(ISD::SUB, NVT, Tmp1, |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 2991 | DAG.getConstant(MVT::getSizeInBits(NVT) - |
| 2992 | MVT::getSizeInBits(OVT), NVT)); |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 2993 | break; |
| 2994 | } |
| 2995 | break; |
| 2996 | } |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 2997 | case TargetLowering::Expand: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2998 | Result = ExpandBitCount(Node->getOpcode(), Tmp1); |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 2999 | break; |
| 3000 | } |
| 3001 | break; |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 3002 | |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3003 | // Unary operators |
| 3004 | case ISD::FABS: |
| 3005 | case ISD::FNEG: |
Chris Lattner | da6ba87 | 2005-04-28 21:44:33 +0000 | [diff] [blame] | 3006 | case ISD::FSQRT: |
| 3007 | case ISD::FSIN: |
| 3008 | case ISD::FCOS: |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3009 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 3010 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3011 | case TargetLowering::Promote: |
| 3012 | case TargetLowering::Custom: |
Evan Cheng | 59ad781 | 2006-01-31 18:14:25 +0000 | [diff] [blame] | 3013 | isCustom = true; |
| 3014 | // FALLTHROUGH |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3015 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3016 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Evan Cheng | 59ad781 | 2006-01-31 18:14:25 +0000 | [diff] [blame] | 3017 | if (isCustom) { |
| 3018 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 3019 | if (Tmp1.Val) Result = Tmp1; |
| 3020 | } |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3021 | break; |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3022 | case TargetLowering::Expand: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3023 | switch (Node->getOpcode()) { |
| 3024 | default: assert(0 && "Unreachable!"); |
| 3025 | case ISD::FNEG: |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3026 | // Expand Y = FNEG(X) -> Y = SUB -0.0, X |
| 3027 | Tmp2 = DAG.getConstantFP(-0.0, Node->getValueType(0)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3028 | Result = DAG.getNode(ISD::FSUB, Node->getValueType(0), Tmp2, Tmp1); |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 3029 | break; |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 3030 | case ISD::FABS: { |
Chris Lattner | 4af6e0d | 2005-04-02 05:26:37 +0000 | [diff] [blame] | 3031 | // Expand Y = FABS(X) -> Y = (X >u 0.0) ? X : fneg(X). |
| 3032 | MVT::ValueType VT = Node->getValueType(0); |
| 3033 | Tmp2 = DAG.getConstantFP(0.0, VT); |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 3034 | Tmp2 = DAG.getSetCC(TLI.getSetCCResultTy(), Tmp1, Tmp2, ISD::SETUGT); |
Chris Lattner | 4af6e0d | 2005-04-02 05:26:37 +0000 | [diff] [blame] | 3035 | Tmp3 = DAG.getNode(ISD::FNEG, VT, Tmp1); |
| 3036 | Result = DAG.getNode(ISD::SELECT, VT, Tmp2, Tmp1, Tmp3); |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 3037 | break; |
| 3038 | } |
| 3039 | case ISD::FSQRT: |
| 3040 | case ISD::FSIN: |
| 3041 | case ISD::FCOS: { |
| 3042 | MVT::ValueType VT = Node->getValueType(0); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3043 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 3044 | switch(Node->getOpcode()) { |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3045 | case ISD::FSQRT: |
| 3046 | LC = VT == MVT::f32 ? RTLIB::SQRT_F32 : RTLIB::SQRT_F64; |
| 3047 | break; |
| 3048 | case ISD::FSIN: |
| 3049 | LC = VT == MVT::f32 ? RTLIB::SIN_F32 : RTLIB::SIN_F64; |
| 3050 | break; |
| 3051 | case ISD::FCOS: |
| 3052 | LC = VT == MVT::f32 ? RTLIB::COS_F32 : RTLIB::COS_F64; |
| 3053 | break; |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 3054 | default: assert(0 && "Unreachable!"); |
| 3055 | } |
Nate Begeman | 2ac4fc0 | 2005-08-04 21:43:28 +0000 | [diff] [blame] | 3056 | SDOperand Dummy; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3057 | Result = ExpandLibCall(TLI.getLibcallName(LC), Node, |
| 3058 | false/*sign irrelevant*/, Dummy); |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 3059 | break; |
| 3060 | } |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3061 | } |
| 3062 | break; |
| 3063 | } |
| 3064 | break; |
Chris Lattner | 6ddf8ed | 2006-09-09 06:03:30 +0000 | [diff] [blame] | 3065 | case ISD::FPOWI: { |
| 3066 | // We always lower FPOWI into a libcall. No target support it yet. |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3067 | RTLIB::Libcall LC = Node->getValueType(0) == MVT::f32 |
| 3068 | ? RTLIB::POWI_F32 : RTLIB::POWI_F64; |
Chris Lattner | 6ddf8ed | 2006-09-09 06:03:30 +0000 | [diff] [blame] | 3069 | SDOperand Dummy; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3070 | Result = ExpandLibCall(TLI.getLibcallName(LC), Node, |
| 3071 | false/*sign irrelevant*/, Dummy); |
Chris Lattner | 6ddf8ed | 2006-09-09 06:03:30 +0000 | [diff] [blame] | 3072 | break; |
| 3073 | } |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 3074 | case ISD::BIT_CONVERT: |
Chris Lattner | 67993f7 | 2006-01-23 07:30:46 +0000 | [diff] [blame] | 3075 | if (!isTypeLegal(Node->getOperand(0).getValueType())) { |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 3076 | Result = ExpandBIT_CONVERT(Node->getValueType(0), Node->getOperand(0)); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3077 | } else if (MVT::isVector(Op.getOperand(0).getValueType())) { |
| 3078 | // The input has to be a vector type, we have to either scalarize it, pack |
| 3079 | // it, or convert it based on whether the input vector type is legal. |
| 3080 | SDNode *InVal = Node->getOperand(0).Val; |
| 3081 | unsigned NumElems = MVT::getVectorNumElements(InVal->getValueType(0)); |
| 3082 | MVT::ValueType EVT = MVT::getVectorElementType(InVal->getValueType(0)); |
| 3083 | |
| 3084 | // Figure out if there is a simple type corresponding to this Vector |
| 3085 | // type. If so, convert to the vector type. |
| 3086 | MVT::ValueType TVT = MVT::getVectorType(EVT, NumElems); |
| 3087 | if (TLI.isTypeLegal(TVT)) { |
Dan Gohman | 07a9676 | 2007-07-16 14:29:03 +0000 | [diff] [blame] | 3088 | // Turn this into a bit convert of the vector input. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3089 | Result = DAG.getNode(ISD::BIT_CONVERT, Node->getValueType(0), |
| 3090 | LegalizeOp(Node->getOperand(0))); |
| 3091 | break; |
| 3092 | } else if (NumElems == 1) { |
| 3093 | // Turn this into a bit convert of the scalar input. |
| 3094 | Result = DAG.getNode(ISD::BIT_CONVERT, Node->getValueType(0), |
| 3095 | ScalarizeVectorOp(Node->getOperand(0))); |
| 3096 | break; |
| 3097 | } else { |
| 3098 | // FIXME: UNIMP! Store then reload |
| 3099 | assert(0 && "Cast from unsupported vector type not implemented yet!"); |
| 3100 | } |
Chris Lattner | 67993f7 | 2006-01-23 07:30:46 +0000 | [diff] [blame] | 3101 | } else { |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 3102 | switch (TLI.getOperationAction(ISD::BIT_CONVERT, |
| 3103 | Node->getOperand(0).getValueType())) { |
| 3104 | default: assert(0 && "Unknown operation action!"); |
| 3105 | case TargetLowering::Expand: |
| 3106 | Result = ExpandBIT_CONVERT(Node->getValueType(0), Node->getOperand(0)); |
| 3107 | break; |
| 3108 | case TargetLowering::Legal: |
| 3109 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3110 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 3111 | break; |
| 3112 | } |
| 3113 | } |
| 3114 | break; |
Chris Lattner | d1f04d4 | 2006-03-24 02:26:29 +0000 | [diff] [blame] | 3115 | |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3116 | // Conversion operators. The source and destination have different types. |
Chris Lattner | ae0aacb | 2005-01-08 08:08:56 +0000 | [diff] [blame] | 3117 | case ISD::SINT_TO_FP: |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3118 | case ISD::UINT_TO_FP: { |
| 3119 | bool isSigned = Node->getOpcode() == ISD::SINT_TO_FP; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3120 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3121 | case Legal: |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 3122 | switch (TLI.getOperationAction(Node->getOpcode(), |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3123 | Node->getOperand(0).getValueType())) { |
| 3124 | default: assert(0 && "Unknown operation action!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3125 | case TargetLowering::Custom: |
| 3126 | isCustom = true; |
| 3127 | // FALLTHROUGH |
| 3128 | case TargetLowering::Legal: |
| 3129 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3130 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3131 | if (isCustom) { |
| 3132 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 3133 | if (Tmp1.Val) Result = Tmp1; |
| 3134 | } |
| 3135 | break; |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3136 | case TargetLowering::Expand: |
Jim Laskey | 6269ed1 | 2005-08-17 00:39:29 +0000 | [diff] [blame] | 3137 | Result = ExpandLegalINT_TO_FP(isSigned, |
| 3138 | LegalizeOp(Node->getOperand(0)), |
| 3139 | Node->getValueType(0)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3140 | break; |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3141 | case TargetLowering::Promote: |
| 3142 | Result = PromoteLegalINT_TO_FP(LegalizeOp(Node->getOperand(0)), |
| 3143 | Node->getValueType(0), |
| 3144 | isSigned); |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3145 | break; |
Andrew Lenharth | 5b5b8c2 | 2005-11-30 06:43:03 +0000 | [diff] [blame] | 3146 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3147 | break; |
Chris Lattner | b00a642 | 2005-01-07 22:37:48 +0000 | [diff] [blame] | 3148 | case Expand: |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3149 | Result = ExpandIntToFP(Node->getOpcode() == ISD::SINT_TO_FP, |
| 3150 | Node->getValueType(0), Node->getOperand(0)); |
| 3151 | break; |
| 3152 | case Promote: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3153 | Tmp1 = PromoteOp(Node->getOperand(0)); |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3154 | if (isSigned) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3155 | Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, Tmp1.getValueType(), |
| 3156 | Tmp1, DAG.getValueType(Node->getOperand(0).getValueType())); |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3157 | } else { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3158 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, |
| 3159 | Node->getOperand(0).getValueType()); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 3160 | } |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3161 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 3162 | Result = LegalizeOp(Result); // The 'op' is not necessarily legal! |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3163 | break; |
| 3164 | } |
| 3165 | break; |
| 3166 | } |
| 3167 | case ISD::TRUNCATE: |
| 3168 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3169 | case Legal: |
| 3170 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3171 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3172 | break; |
| 3173 | case Expand: |
| 3174 | ExpandOp(Node->getOperand(0), Tmp1, Tmp2); |
| 3175 | |
| 3176 | // Since the result is legal, we should just be able to truncate the low |
| 3177 | // part of the source. |
| 3178 | Result = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0), Tmp1); |
| 3179 | break; |
| 3180 | case Promote: |
| 3181 | Result = PromoteOp(Node->getOperand(0)); |
| 3182 | Result = DAG.getNode(ISD::TRUNCATE, Op.getValueType(), Result); |
| 3183 | break; |
| 3184 | } |
| 3185 | break; |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 3186 | |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3187 | case ISD::FP_TO_SINT: |
| 3188 | case ISD::FP_TO_UINT: |
| 3189 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3190 | case Legal: |
Chris Lattner | f1fa74e | 2005-07-30 00:04:12 +0000 | [diff] [blame] | 3191 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 3192 | |
Chris Lattner | 1618beb | 2005-07-29 00:11:56 +0000 | [diff] [blame] | 3193 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))){ |
| 3194 | default: assert(0 && "Unknown operation action!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3195 | case TargetLowering::Custom: |
| 3196 | isCustom = true; |
| 3197 | // FALLTHROUGH |
| 3198 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3199 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3200 | if (isCustom) { |
| 3201 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 3202 | if (Tmp1.Val) Result = Tmp1; |
| 3203 | } |
| 3204 | break; |
| 3205 | case TargetLowering::Promote: |
| 3206 | Result = PromoteLegalFP_TO_INT(Tmp1, Node->getValueType(0), |
| 3207 | Node->getOpcode() == ISD::FP_TO_SINT); |
| 3208 | break; |
Chris Lattner | 1618beb | 2005-07-29 00:11:56 +0000 | [diff] [blame] | 3209 | case TargetLowering::Expand: |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 3210 | if (Node->getOpcode() == ISD::FP_TO_UINT) { |
| 3211 | SDOperand True, False; |
| 3212 | MVT::ValueType VT = Node->getOperand(0).getValueType(); |
| 3213 | MVT::ValueType NVT = Node->getValueType(0); |
Dale Johannesen | f4d4832 | 2007-09-19 17:53:26 +0000 | [diff] [blame^] | 3214 | unsigned ShiftAmt = MVT::getSizeInBits(NVT)-1; |
| 3215 | Tmp2 = DAG.getConstantFP(APFloat(APInt(MVT::getSizeInBits(VT), |
| 3216 | 1ULL << ShiftAmt)), VT); |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 3217 | Tmp3 = DAG.getSetCC(TLI.getSetCCResultTy(), |
| 3218 | Node->getOperand(0), Tmp2, ISD::SETLT); |
| 3219 | True = DAG.getNode(ISD::FP_TO_SINT, NVT, Node->getOperand(0)); |
| 3220 | False = DAG.getNode(ISD::FP_TO_SINT, NVT, |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 3221 | DAG.getNode(ISD::FSUB, VT, Node->getOperand(0), |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 3222 | Tmp2)); |
| 3223 | False = DAG.getNode(ISD::XOR, NVT, False, |
| 3224 | DAG.getConstant(1ULL << ShiftAmt, NVT)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3225 | Result = DAG.getNode(ISD::SELECT, NVT, Tmp3, True, False); |
| 3226 | break; |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 3227 | } else { |
| 3228 | assert(0 && "Do not know how to expand FP_TO_SINT yet!"); |
| 3229 | } |
| 3230 | break; |
Chris Lattner | 07dffd6 | 2005-08-26 00:14:16 +0000 | [diff] [blame] | 3231 | } |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3232 | break; |
Evan Cheng | 6af00d5 | 2006-12-13 01:57:55 +0000 | [diff] [blame] | 3233 | case Expand: { |
| 3234 | // Convert f32 / f64 to i32 / i64. |
| 3235 | MVT::ValueType VT = Op.getValueType(); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3236 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
Evan Cheng | 6af00d5 | 2006-12-13 01:57:55 +0000 | [diff] [blame] | 3237 | switch (Node->getOpcode()) { |
| 3238 | case ISD::FP_TO_SINT: |
| 3239 | if (Node->getOperand(0).getValueType() == MVT::f32) |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3240 | LC = (VT == MVT::i32) |
| 3241 | ? RTLIB::FPTOSINT_F32_I32 : RTLIB::FPTOSINT_F32_I64; |
Evan Cheng | 6af00d5 | 2006-12-13 01:57:55 +0000 | [diff] [blame] | 3242 | else |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3243 | LC = (VT == MVT::i32) |
| 3244 | ? RTLIB::FPTOSINT_F64_I32 : RTLIB::FPTOSINT_F64_I64; |
Evan Cheng | 6af00d5 | 2006-12-13 01:57:55 +0000 | [diff] [blame] | 3245 | break; |
| 3246 | case ISD::FP_TO_UINT: |
| 3247 | if (Node->getOperand(0).getValueType() == MVT::f32) |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3248 | LC = (VT == MVT::i32) |
| 3249 | ? RTLIB::FPTOUINT_F32_I32 : RTLIB::FPTOSINT_F32_I64; |
Evan Cheng | 6af00d5 | 2006-12-13 01:57:55 +0000 | [diff] [blame] | 3250 | else |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3251 | LC = (VT == MVT::i32) |
| 3252 | ? RTLIB::FPTOUINT_F64_I32 : RTLIB::FPTOSINT_F64_I64; |
Evan Cheng | 6af00d5 | 2006-12-13 01:57:55 +0000 | [diff] [blame] | 3253 | break; |
| 3254 | default: assert(0 && "Unreachable!"); |
| 3255 | } |
| 3256 | SDOperand Dummy; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3257 | Result = ExpandLibCall(TLI.getLibcallName(LC), Node, |
| 3258 | false/*sign irrelevant*/, Dummy); |
Evan Cheng | 6af00d5 | 2006-12-13 01:57:55 +0000 | [diff] [blame] | 3259 | break; |
| 3260 | } |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3261 | case Promote: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3262 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 3263 | Result = DAG.UpdateNodeOperands(Result, LegalizeOp(Tmp1)); |
| 3264 | Result = LegalizeOp(Result); |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3265 | break; |
| 3266 | } |
| 3267 | break; |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 3268 | |
Dale Johannesen | ab081c7 | 2007-08-09 17:27:48 +0000 | [diff] [blame] | 3269 | case ISD::FP_EXTEND: |
Dale Johannesen | 5411a39 | 2007-08-09 01:04:01 +0000 | [diff] [blame] | 3270 | case ISD::FP_ROUND: { |
| 3271 | MVT::ValueType newVT = Op.getValueType(); |
| 3272 | MVT::ValueType oldVT = Op.getOperand(0).getValueType(); |
| 3273 | if (TLI.getConvertAction(oldVT, newVT) == TargetLowering::Expand) { |
Dale Johannesen | ab081c7 | 2007-08-09 17:27:48 +0000 | [diff] [blame] | 3274 | // The only way we can lower this is to turn it into a STORE, |
Dale Johannesen | 5411a39 | 2007-08-09 01:04:01 +0000 | [diff] [blame] | 3275 | // LOAD pair, targetting a temporary location (a stack slot). |
| 3276 | |
| 3277 | // NOTE: there is a choice here between constantly creating new stack |
| 3278 | // slots and always reusing the same one. We currently always create |
| 3279 | // new ones, as reuse may inhibit scheduling. |
Dale Johannesen | ab081c7 | 2007-08-09 17:27:48 +0000 | [diff] [blame] | 3280 | MVT::ValueType slotVT = |
| 3281 | (Node->getOpcode() == ISD::FP_EXTEND) ? oldVT : newVT; |
| 3282 | const Type *Ty = MVT::getTypeForValueType(slotVT); |
Dale Johannesen | 5411a39 | 2007-08-09 01:04:01 +0000 | [diff] [blame] | 3283 | uint64_t TySize = TLI.getTargetData()->getTypeSize(Ty); |
| 3284 | unsigned Align = TLI.getTargetData()->getPrefTypeAlignment(Ty); |
| 3285 | MachineFunction &MF = DAG.getMachineFunction(); |
| 3286 | int SSFI = |
| 3287 | MF.getFrameInfo()->CreateStackObject(TySize, Align); |
| 3288 | SDOperand StackSlot = DAG.getFrameIndex(SSFI, TLI.getPointerTy()); |
Dale Johannesen | ab081c7 | 2007-08-09 17:27:48 +0000 | [diff] [blame] | 3289 | if (Node->getOpcode() == ISD::FP_EXTEND) { |
| 3290 | Result = DAG.getStore(DAG.getEntryNode(), Node->getOperand(0), |
| 3291 | StackSlot, NULL, 0); |
| 3292 | Result = DAG.getExtLoad(ISD::EXTLOAD, newVT, |
| 3293 | Result, StackSlot, NULL, 0, oldVT); |
| 3294 | } else { |
| 3295 | Result = DAG.getTruncStore(DAG.getEntryNode(), Node->getOperand(0), |
| 3296 | StackSlot, NULL, 0, newVT); |
| 3297 | Result = DAG.getLoad(newVT, Result, StackSlot, NULL, 0, newVT); |
| 3298 | } |
Dale Johannesen | 5411a39 | 2007-08-09 01:04:01 +0000 | [diff] [blame] | 3299 | break; |
| 3300 | } |
Dale Johannesen | 849f214 | 2007-07-03 00:53:03 +0000 | [diff] [blame] | 3301 | } |
| 3302 | // FALL THROUGH |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 3303 | case ISD::ANY_EXTEND: |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3304 | case ISD::ZERO_EXTEND: |
| 3305 | case ISD::SIGN_EXTEND: |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3306 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3307 | case Expand: assert(0 && "Shouldn't need to expand other operators here!"); |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3308 | case Legal: |
| 3309 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3310 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3311 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3312 | case Promote: |
| 3313 | switch (Node->getOpcode()) { |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 3314 | case ISD::ANY_EXTEND: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3315 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 3316 | Result = DAG.getNode(ISD::ANY_EXTEND, Op.getValueType(), Tmp1); |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 3317 | break; |
Chris Lattner | 1713e73 | 2005-01-16 00:38:00 +0000 | [diff] [blame] | 3318 | case ISD::ZERO_EXTEND: |
| 3319 | Result = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 3320 | Result = DAG.getNode(ISD::ANY_EXTEND, Op.getValueType(), Result); |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 3321 | Result = DAG.getZeroExtendInReg(Result, |
| 3322 | Node->getOperand(0).getValueType()); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3323 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3324 | case ISD::SIGN_EXTEND: |
Chris Lattner | 1713e73 | 2005-01-16 00:38:00 +0000 | [diff] [blame] | 3325 | Result = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 3326 | Result = DAG.getNode(ISD::ANY_EXTEND, Op.getValueType(), Result); |
Chris Lattner | 1713e73 | 2005-01-16 00:38:00 +0000 | [diff] [blame] | 3327 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(), |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 3328 | Result, |
| 3329 | DAG.getValueType(Node->getOperand(0).getValueType())); |
Chris Lattner | 1713e73 | 2005-01-16 00:38:00 +0000 | [diff] [blame] | 3330 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3331 | case ISD::FP_EXTEND: |
Chris Lattner | 1713e73 | 2005-01-16 00:38:00 +0000 | [diff] [blame] | 3332 | Result = PromoteOp(Node->getOperand(0)); |
| 3333 | if (Result.getValueType() != Op.getValueType()) |
| 3334 | // Dynamically dead while we have only 2 FP types. |
| 3335 | Result = DAG.getNode(ISD::FP_EXTEND, Op.getValueType(), Result); |
| 3336 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3337 | case ISD::FP_ROUND: |
Chris Lattner | f8161d8 | 2005-01-16 05:06:12 +0000 | [diff] [blame] | 3338 | Result = PromoteOp(Node->getOperand(0)); |
| 3339 | Result = DAG.getNode(Node->getOpcode(), Op.getValueType(), Result); |
| 3340 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3341 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3342 | } |
| 3343 | break; |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 3344 | case ISD::FP_ROUND_INREG: |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 3345 | case ISD::SIGN_EXTEND_INREG: { |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 3346 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 3347 | MVT::ValueType ExtraVT = cast<VTSDNode>(Node->getOperand(1))->getVT(); |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 3348 | |
| 3349 | // If this operation is not supported, convert it to a shl/shr or load/store |
| 3350 | // pair. |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 3351 | switch (TLI.getOperationAction(Node->getOpcode(), ExtraVT)) { |
| 3352 | default: assert(0 && "This action not supported for this op yet!"); |
| 3353 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3354 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 3355 | break; |
| 3356 | case TargetLowering::Expand: |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 3357 | // If this is an integer extend and shifts are supported, do that. |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 3358 | if (Node->getOpcode() == ISD::SIGN_EXTEND_INREG) { |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 3359 | // NOTE: we could fall back on load/store here too for targets without |
| 3360 | // SAR. However, it is doubtful that any exist. |
| 3361 | unsigned BitsDiff = MVT::getSizeInBits(Node->getValueType(0)) - |
| 3362 | MVT::getSizeInBits(ExtraVT); |
Chris Lattner | 27ff112 | 2005-01-22 00:31:52 +0000 | [diff] [blame] | 3363 | SDOperand ShiftCst = DAG.getConstant(BitsDiff, TLI.getShiftAmountTy()); |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 3364 | Result = DAG.getNode(ISD::SHL, Node->getValueType(0), |
| 3365 | Node->getOperand(0), ShiftCst); |
| 3366 | Result = DAG.getNode(ISD::SRA, Node->getValueType(0), |
| 3367 | Result, ShiftCst); |
| 3368 | } else if (Node->getOpcode() == ISD::FP_ROUND_INREG) { |
Jim Laskey | 2d84c4c | 2006-10-11 17:52:19 +0000 | [diff] [blame] | 3369 | // The only way we can lower this is to turn it into a TRUNCSTORE, |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 3370 | // EXTLOAD pair, targetting a temporary location (a stack slot). |
| 3371 | |
| 3372 | // NOTE: there is a choice here between constantly creating new stack |
| 3373 | // slots and always reusing the same one. We currently always create |
| 3374 | // new ones, as reuse may inhibit scheduling. |
| 3375 | const Type *Ty = MVT::getTypeForValueType(ExtraVT); |
Chris Lattner | 44b2c50 | 2007-04-28 06:42:38 +0000 | [diff] [blame] | 3376 | uint64_t TySize = TLI.getTargetData()->getTypeSize(Ty); |
Chris Lattner | d2b7cec | 2007-02-14 05:52:17 +0000 | [diff] [blame] | 3377 | unsigned Align = TLI.getTargetData()->getPrefTypeAlignment(Ty); |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 3378 | MachineFunction &MF = DAG.getMachineFunction(); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 3379 | int SSFI = |
Chris Lattner | 44b2c50 | 2007-04-28 06:42:38 +0000 | [diff] [blame] | 3380 | MF.getFrameInfo()->CreateStackObject(TySize, Align); |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 3381 | SDOperand StackSlot = DAG.getFrameIndex(SSFI, TLI.getPointerTy()); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 3382 | Result = DAG.getTruncStore(DAG.getEntryNode(), Node->getOperand(0), |
| 3383 | StackSlot, NULL, 0, ExtraVT); |
Chris Lattner | 5f056bf | 2005-07-10 01:55:33 +0000 | [diff] [blame] | 3384 | Result = DAG.getExtLoad(ISD::EXTLOAD, Node->getValueType(0), |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 3385 | Result, StackSlot, NULL, 0, ExtraVT); |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 3386 | } else { |
| 3387 | assert(0 && "Unknown op"); |
| 3388 | } |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 3389 | break; |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 3390 | } |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 3391 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3392 | } |
Duncan Sands | 36397f5 | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 3393 | case ISD::TRAMPOLINE: { |
| 3394 | SDOperand Ops[6]; |
| 3395 | for (unsigned i = 0; i != 6; ++i) |
| 3396 | Ops[i] = LegalizeOp(Node->getOperand(i)); |
| 3397 | Result = DAG.UpdateNodeOperands(Result, Ops, 6); |
| 3398 | // The only option for this node is to custom lower it. |
| 3399 | Result = TLI.LowerOperation(Result, DAG); |
| 3400 | assert(Result.Val && "Should always custom lower!"); |
Duncan Sands | f7331b3 | 2007-09-11 14:10:23 +0000 | [diff] [blame] | 3401 | |
| 3402 | // Since trampoline produces two values, make sure to remember that we |
| 3403 | // legalized both of them. |
| 3404 | Tmp1 = LegalizeOp(Result.getValue(1)); |
| 3405 | Result = LegalizeOp(Result); |
| 3406 | AddLegalizedOperand(SDOperand(Node, 0), Result); |
| 3407 | AddLegalizedOperand(SDOperand(Node, 1), Tmp1); |
| 3408 | return Op.ResNo ? Tmp1 : Result; |
Duncan Sands | 36397f5 | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 3409 | } |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 3410 | } |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3411 | |
Chris Lattner | 4ddd283 | 2006-04-08 04:13:17 +0000 | [diff] [blame] | 3412 | assert(Result.getValueType() == Op.getValueType() && |
| 3413 | "Bad legalization!"); |
| 3414 | |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3415 | // Make sure that the generated code is itself legal. |
| 3416 | if (Result != Op) |
| 3417 | Result = LegalizeOp(Result); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3418 | |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 3419 | // Note that LegalizeOp may be reentered even from single-use nodes, which |
| 3420 | // means that we always must cache transformed nodes. |
| 3421 | AddLegalizedOperand(Op, Result); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3422 | return Result; |
| 3423 | } |
| 3424 | |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3425 | /// PromoteOp - Given an operation that produces a value in an invalid type, |
| 3426 | /// promote it to compute the value into a larger type. The produced value will |
| 3427 | /// have the correct bits for the low portion of the register, but no guarantee |
| 3428 | /// is made about the top bits: it may be zero, sign-extended, or garbage. |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3429 | SDOperand SelectionDAGLegalize::PromoteOp(SDOperand Op) { |
| 3430 | MVT::ValueType VT = Op.getValueType(); |
Chris Lattner | 71c42a0 | 2005-01-16 01:11:45 +0000 | [diff] [blame] | 3431 | MVT::ValueType NVT = TLI.getTypeToTransformTo(VT); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3432 | assert(getTypeAction(VT) == Promote && |
| 3433 | "Caller should expand or legalize operands that are not promotable!"); |
| 3434 | assert(NVT > VT && MVT::isInteger(NVT) == MVT::isInteger(VT) && |
| 3435 | "Cannot promote to smaller type!"); |
| 3436 | |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3437 | SDOperand Tmp1, Tmp2, Tmp3; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3438 | SDOperand Result; |
| 3439 | SDNode *Node = Op.Val; |
| 3440 | |
Chris Lattner | 40030bf | 2007-02-04 01:17:38 +0000 | [diff] [blame] | 3441 | DenseMap<SDOperand, SDOperand>::iterator I = PromotedNodes.find(Op); |
Chris Lattner | 6fdcb25 | 2005-09-02 20:32:45 +0000 | [diff] [blame] | 3442 | if (I != PromotedNodes.end()) return I->second; |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 3443 | |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3444 | switch (Node->getOpcode()) { |
Chris Lattner | d5d0f9b | 2005-08-16 21:55:35 +0000 | [diff] [blame] | 3445 | case ISD::CopyFromReg: |
| 3446 | assert(0 && "CopyFromReg must be legal!"); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3447 | default: |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 3448 | #ifndef NDEBUG |
Dan Gohman | 3983358 | 2007-06-04 16:17:33 +0000 | [diff] [blame] | 3449 | cerr << "NODE: "; Node->dump(&DAG); cerr << "\n"; |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 3450 | #endif |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3451 | assert(0 && "Do not know how to promote this operator!"); |
| 3452 | abort(); |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 3453 | case ISD::UNDEF: |
| 3454 | Result = DAG.getNode(ISD::UNDEF, NVT); |
| 3455 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3456 | case ISD::Constant: |
Chris Lattner | ec176e3 | 2005-08-30 16:56:19 +0000 | [diff] [blame] | 3457 | if (VT != MVT::i1) |
| 3458 | Result = DAG.getNode(ISD::SIGN_EXTEND, NVT, Op); |
| 3459 | else |
| 3460 | Result = DAG.getNode(ISD::ZERO_EXTEND, NVT, Op); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3461 | assert(isa<ConstantSDNode>(Result) && "Didn't constant fold zext?"); |
| 3462 | break; |
| 3463 | case ISD::ConstantFP: |
| 3464 | Result = DAG.getNode(ISD::FP_EXTEND, NVT, Op); |
| 3465 | assert(isa<ConstantFPSDNode>(Result) && "Didn't constant fold fp_extend?"); |
| 3466 | break; |
Chris Lattner | ef5cd1d | 2005-01-18 17:54:55 +0000 | [diff] [blame] | 3467 | |
Chris Lattner | 82fbfb6 | 2005-01-18 02:59:52 +0000 | [diff] [blame] | 3468 | case ISD::SETCC: |
Chris Lattner | c9c60f6 | 2005-08-24 16:35:28 +0000 | [diff] [blame] | 3469 | assert(isTypeLegal(TLI.getSetCCResultTy()) && "SetCC type is not legal??"); |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 3470 | Result = DAG.getNode(ISD::SETCC, TLI.getSetCCResultTy(),Node->getOperand(0), |
| 3471 | Node->getOperand(1), Node->getOperand(2)); |
Chris Lattner | 82fbfb6 | 2005-01-18 02:59:52 +0000 | [diff] [blame] | 3472 | break; |
Chris Lattner | fdfded5 | 2006-04-12 16:20:43 +0000 | [diff] [blame] | 3473 | |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3474 | case ISD::TRUNCATE: |
| 3475 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3476 | case Legal: |
| 3477 | Result = LegalizeOp(Node->getOperand(0)); |
| 3478 | assert(Result.getValueType() >= NVT && |
| 3479 | "This truncation doesn't make sense!"); |
| 3480 | if (Result.getValueType() > NVT) // Truncate to NVT instead of VT |
| 3481 | Result = DAG.getNode(ISD::TRUNCATE, NVT, Result); |
| 3482 | break; |
Chris Lattner | e76ad6d | 2005-01-28 22:52:50 +0000 | [diff] [blame] | 3483 | case Promote: |
| 3484 | // The truncation is not required, because we don't guarantee anything |
| 3485 | // about high bits anyway. |
| 3486 | Result = PromoteOp(Node->getOperand(0)); |
| 3487 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3488 | case Expand: |
Nate Begeman | 79e46ac | 2005-04-04 00:57:08 +0000 | [diff] [blame] | 3489 | ExpandOp(Node->getOperand(0), Tmp1, Tmp2); |
| 3490 | // Truncate the low part of the expanded value to the result type |
Chris Lattner | e21c305 | 2005-08-01 18:16:37 +0000 | [diff] [blame] | 3491 | Result = DAG.getNode(ISD::TRUNCATE, NVT, Tmp1); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3492 | } |
| 3493 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3494 | case ISD::SIGN_EXTEND: |
| 3495 | case ISD::ZERO_EXTEND: |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 3496 | case ISD::ANY_EXTEND: |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3497 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3498 | case Expand: assert(0 && "BUG: Smaller reg should have been promoted!"); |
| 3499 | case Legal: |
| 3500 | // Input is legal? Just do extend all the way to the larger type. |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3501 | Result = DAG.getNode(Node->getOpcode(), NVT, Node->getOperand(0)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3502 | break; |
| 3503 | case Promote: |
| 3504 | // Promote the reg if it's smaller. |
| 3505 | Result = PromoteOp(Node->getOperand(0)); |
| 3506 | // The high bits are not guaranteed to be anything. Insert an extend. |
| 3507 | if (Node->getOpcode() == ISD::SIGN_EXTEND) |
Chris Lattner | 595dc54 | 2005-02-04 18:39:19 +0000 | [diff] [blame] | 3508 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Result, |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 3509 | DAG.getValueType(Node->getOperand(0).getValueType())); |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 3510 | else if (Node->getOpcode() == ISD::ZERO_EXTEND) |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 3511 | Result = DAG.getZeroExtendInReg(Result, |
| 3512 | Node->getOperand(0).getValueType()); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3513 | break; |
| 3514 | } |
| 3515 | break; |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 3516 | case ISD::BIT_CONVERT: |
| 3517 | Result = ExpandBIT_CONVERT(Node->getValueType(0), Node->getOperand(0)); |
| 3518 | Result = PromoteOp(Result); |
| 3519 | break; |
| 3520 | |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3521 | case ISD::FP_EXTEND: |
| 3522 | assert(0 && "Case not implemented. Dynamically dead with 2 FP types!"); |
| 3523 | case ISD::FP_ROUND: |
| 3524 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3525 | case Expand: assert(0 && "BUG: Cannot expand FP regs!"); |
| 3526 | case Promote: assert(0 && "Unreachable with 2 FP types!"); |
| 3527 | case Legal: |
| 3528 | // Input is legal? Do an FP_ROUND_INREG. |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3529 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Node->getOperand(0), |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 3530 | DAG.getValueType(VT)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3531 | break; |
| 3532 | } |
| 3533 | break; |
| 3534 | |
| 3535 | case ISD::SINT_TO_FP: |
| 3536 | case ISD::UINT_TO_FP: |
| 3537 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3538 | case Legal: |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 3539 | // No extra round required here. |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3540 | Result = DAG.getNode(Node->getOpcode(), NVT, Node->getOperand(0)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3541 | break; |
| 3542 | |
| 3543 | case Promote: |
| 3544 | Result = PromoteOp(Node->getOperand(0)); |
| 3545 | if (Node->getOpcode() == ISD::SINT_TO_FP) |
| 3546 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(), |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 3547 | Result, |
| 3548 | DAG.getValueType(Node->getOperand(0).getValueType())); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3549 | else |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 3550 | Result = DAG.getZeroExtendInReg(Result, |
| 3551 | Node->getOperand(0).getValueType()); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 3552 | // No extra round required here. |
| 3553 | Result = DAG.getNode(Node->getOpcode(), NVT, Result); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3554 | break; |
| 3555 | case Expand: |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 3556 | Result = ExpandIntToFP(Node->getOpcode() == ISD::SINT_TO_FP, NVT, |
| 3557 | Node->getOperand(0)); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 3558 | // Round if we cannot tolerate excess precision. |
| 3559 | if (NoExcessFPPrecision) |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 3560 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 3561 | DAG.getValueType(VT)); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 3562 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3563 | } |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3564 | break; |
| 3565 | |
Chris Lattner | 5e3c5b4 | 2005-12-09 17:32:47 +0000 | [diff] [blame] | 3566 | case ISD::SIGN_EXTEND_INREG: |
| 3567 | Result = PromoteOp(Node->getOperand(0)); |
| 3568 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Result, |
| 3569 | Node->getOperand(1)); |
| 3570 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3571 | case ISD::FP_TO_SINT: |
| 3572 | case ISD::FP_TO_UINT: |
| 3573 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3574 | case Legal: |
Evan Cheng | 0b1b9dc | 2006-12-16 02:10:30 +0000 | [diff] [blame] | 3575 | case Expand: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3576 | Tmp1 = Node->getOperand(0); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3577 | break; |
| 3578 | case Promote: |
| 3579 | // The input result is prerounded, so we don't have to do anything |
| 3580 | // special. |
| 3581 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 3582 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3583 | } |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 3584 | // If we're promoting a UINT to a larger size, check to see if the new node |
| 3585 | // will be legal. If it isn't, check to see if FP_TO_SINT is legal, since |
| 3586 | // we can use that instead. This allows us to generate better code for |
| 3587 | // FP_TO_UINT for small destination sizes on targets where FP_TO_UINT is not |
| 3588 | // legal, such as PowerPC. |
| 3589 | if (Node->getOpcode() == ISD::FP_TO_UINT && |
Chris Lattner | c9c60f6 | 2005-08-24 16:35:28 +0000 | [diff] [blame] | 3590 | !TLI.isOperationLegal(ISD::FP_TO_UINT, NVT) && |
Nate Begeman | b7f6ef1 | 2005-10-25 23:47:25 +0000 | [diff] [blame] | 3591 | (TLI.isOperationLegal(ISD::FP_TO_SINT, NVT) || |
| 3592 | TLI.getOperationAction(ISD::FP_TO_SINT, NVT)==TargetLowering::Custom)){ |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 3593 | Result = DAG.getNode(ISD::FP_TO_SINT, NVT, Tmp1); |
| 3594 | } else { |
| 3595 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1); |
| 3596 | } |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3597 | break; |
| 3598 | |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3599 | case ISD::FABS: |
| 3600 | case ISD::FNEG: |
| 3601 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 3602 | assert(Tmp1.getValueType() == NVT); |
| 3603 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1); |
| 3604 | // NOTE: we do not have to do any extra rounding here for |
| 3605 | // NoExcessFPPrecision, because we know the input will have the appropriate |
| 3606 | // precision, and these operations don't modify precision at all. |
| 3607 | break; |
| 3608 | |
Chris Lattner | da6ba87 | 2005-04-28 21:44:33 +0000 | [diff] [blame] | 3609 | case ISD::FSQRT: |
| 3610 | case ISD::FSIN: |
| 3611 | case ISD::FCOS: |
| 3612 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 3613 | assert(Tmp1.getValueType() == NVT); |
| 3614 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3615 | if (NoExcessFPPrecision) |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 3616 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 3617 | DAG.getValueType(VT)); |
Chris Lattner | da6ba87 | 2005-04-28 21:44:33 +0000 | [diff] [blame] | 3618 | break; |
| 3619 | |
Chris Lattner | 8b2d42c | 2007-03-03 23:43:21 +0000 | [diff] [blame] | 3620 | case ISD::FPOWI: { |
| 3621 | // Promote f32 powi to f64 powi. Note that this could insert a libcall |
| 3622 | // directly as well, which may be better. |
| 3623 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 3624 | assert(Tmp1.getValueType() == NVT); |
| 3625 | Result = DAG.getNode(ISD::FPOWI, NVT, Tmp1, Node->getOperand(1)); |
| 3626 | if (NoExcessFPPrecision) |
| 3627 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 3628 | DAG.getValueType(VT)); |
| 3629 | break; |
| 3630 | } |
| 3631 | |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3632 | case ISD::AND: |
| 3633 | case ISD::OR: |
| 3634 | case ISD::XOR: |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 3635 | case ISD::ADD: |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3636 | case ISD::SUB: |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 3637 | case ISD::MUL: |
| 3638 | // The input may have strange things in the top bits of the registers, but |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 3639 | // these operations don't care. They may have weird bits going out, but |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 3640 | // that too is okay if they are integer operations. |
| 3641 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 3642 | Tmp2 = PromoteOp(Node->getOperand(1)); |
| 3643 | assert(Tmp1.getValueType() == NVT && Tmp2.getValueType() == NVT); |
| 3644 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 3645 | break; |
| 3646 | case ISD::FADD: |
| 3647 | case ISD::FSUB: |
| 3648 | case ISD::FMUL: |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 3649 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 3650 | Tmp2 = PromoteOp(Node->getOperand(1)); |
| 3651 | assert(Tmp1.getValueType() == NVT && Tmp2.getValueType() == NVT); |
| 3652 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 3653 | |
| 3654 | // Floating point operations will give excess precision that we may not be |
| 3655 | // able to tolerate. If we DO allow excess precision, just leave it, |
| 3656 | // otherwise excise it. |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3657 | // FIXME: Why would we need to round FP ops more than integer ones? |
| 3658 | // Is Round(Add(Add(A,B),C)) != Round(Add(Round(Add(A,B)), C)) |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 3659 | if (NoExcessFPPrecision) |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 3660 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 3661 | DAG.getValueType(VT)); |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 3662 | break; |
| 3663 | |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3664 | case ISD::SDIV: |
| 3665 | case ISD::SREM: |
| 3666 | // These operators require that their input be sign extended. |
| 3667 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 3668 | Tmp2 = PromoteOp(Node->getOperand(1)); |
| 3669 | if (MVT::isInteger(NVT)) { |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 3670 | Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp1, |
| 3671 | DAG.getValueType(VT)); |
| 3672 | Tmp2 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp2, |
| 3673 | DAG.getValueType(VT)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3674 | } |
| 3675 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 3676 | |
| 3677 | // Perform FP_ROUND: this is probably overly pessimistic. |
| 3678 | if (MVT::isFloatingPoint(NVT) && NoExcessFPPrecision) |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 3679 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 3680 | DAG.getValueType(VT)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3681 | break; |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 3682 | case ISD::FDIV: |
| 3683 | case ISD::FREM: |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 3684 | case ISD::FCOPYSIGN: |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 3685 | // These operators require that their input be fp extended. |
Nate Begeman | ec57fd9 | 2006-05-09 18:20:51 +0000 | [diff] [blame] | 3686 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3687 | case Legal: |
| 3688 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 3689 | break; |
| 3690 | case Promote: |
| 3691 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 3692 | break; |
| 3693 | case Expand: |
| 3694 | assert(0 && "not implemented"); |
| 3695 | } |
| 3696 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 3697 | case Legal: |
| 3698 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 3699 | break; |
| 3700 | case Promote: |
| 3701 | Tmp2 = PromoteOp(Node->getOperand(1)); |
| 3702 | break; |
| 3703 | case Expand: |
| 3704 | assert(0 && "not implemented"); |
| 3705 | } |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 3706 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 3707 | |
| 3708 | // Perform FP_ROUND: this is probably overly pessimistic. |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 3709 | if (NoExcessFPPrecision && Node->getOpcode() != ISD::FCOPYSIGN) |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 3710 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 3711 | DAG.getValueType(VT)); |
| 3712 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3713 | |
| 3714 | case ISD::UDIV: |
| 3715 | case ISD::UREM: |
| 3716 | // These operators require that their input be zero extended. |
| 3717 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 3718 | Tmp2 = PromoteOp(Node->getOperand(1)); |
| 3719 | assert(MVT::isInteger(NVT) && "Operators don't apply to FP!"); |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 3720 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, VT); |
| 3721 | Tmp2 = DAG.getZeroExtendInReg(Tmp2, VT); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3722 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 3723 | break; |
| 3724 | |
| 3725 | case ISD::SHL: |
| 3726 | Tmp1 = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3727 | Result = DAG.getNode(ISD::SHL, NVT, Tmp1, Node->getOperand(1)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3728 | break; |
| 3729 | case ISD::SRA: |
| 3730 | // The input value must be properly sign extended. |
| 3731 | Tmp1 = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 3732 | Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp1, |
| 3733 | DAG.getValueType(VT)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3734 | Result = DAG.getNode(ISD::SRA, NVT, Tmp1, Node->getOperand(1)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3735 | break; |
| 3736 | case ISD::SRL: |
| 3737 | // The input value must be properly zero extended. |
| 3738 | Tmp1 = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 3739 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, VT); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3740 | Result = DAG.getNode(ISD::SRL, NVT, Tmp1, Node->getOperand(1)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3741 | break; |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 3742 | |
| 3743 | case ISD::VAARG: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3744 | Tmp1 = Node->getOperand(0); // Get the chain. |
| 3745 | Tmp2 = Node->getOperand(1); // Get the pointer. |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 3746 | if (TLI.getOperationAction(ISD::VAARG, VT) == TargetLowering::Custom) { |
| 3747 | Tmp3 = DAG.getVAArg(VT, Tmp1, Tmp2, Node->getOperand(2)); |
| 3748 | Result = TLI.CustomPromoteOperation(Tmp3, DAG); |
| 3749 | } else { |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 3750 | SrcValueSDNode *SV = cast<SrcValueSDNode>(Node->getOperand(2)); |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 3751 | SDOperand VAList = DAG.getLoad(TLI.getPointerTy(), Tmp1, Tmp2, |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 3752 | SV->getValue(), SV->getOffset()); |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 3753 | // Increment the pointer, VAList, to the next vaarg |
| 3754 | Tmp3 = DAG.getNode(ISD::ADD, TLI.getPointerTy(), VAList, |
| 3755 | DAG.getConstant(MVT::getSizeInBits(VT)/8, |
| 3756 | TLI.getPointerTy())); |
| 3757 | // Store the incremented VAList to the legalized pointer |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 3758 | Tmp3 = DAG.getStore(VAList.getValue(1), Tmp3, Tmp2, SV->getValue(), |
| 3759 | SV->getOffset()); |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 3760 | // Load the actual argument out of the pointer VAList |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 3761 | Result = DAG.getExtLoad(ISD::EXTLOAD, NVT, Tmp3, VAList, NULL, 0, VT); |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 3762 | } |
| 3763 | // Remember that we legalized the chain. |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3764 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1))); |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 3765 | break; |
| 3766 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 3767 | case ISD::LOAD: { |
| 3768 | LoadSDNode *LD = cast<LoadSDNode>(Node); |
Evan Cheng | 62f2a3c | 2006-10-10 07:51:21 +0000 | [diff] [blame] | 3769 | ISD::LoadExtType ExtType = ISD::isNON_EXTLoad(Node) |
| 3770 | ? ISD::EXTLOAD : LD->getExtensionType(); |
| 3771 | Result = DAG.getExtLoad(ExtType, NVT, |
| 3772 | LD->getChain(), LD->getBasePtr(), |
Chris Lattner | 55b5708 | 2006-10-10 18:54:19 +0000 | [diff] [blame] | 3773 | LD->getSrcValue(), LD->getSrcValueOffset(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 3774 | LD->getLoadedVT(), |
| 3775 | LD->isVolatile(), |
| 3776 | LD->getAlignment()); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3777 | // Remember that we legalized the chain. |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3778 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1))); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3779 | break; |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 3780 | } |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3781 | case ISD::SELECT: |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3782 | Tmp2 = PromoteOp(Node->getOperand(1)); // Legalize the op0 |
| 3783 | Tmp3 = PromoteOp(Node->getOperand(2)); // Legalize the op1 |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3784 | Result = DAG.getNode(ISD::SELECT, NVT, Node->getOperand(0), Tmp2, Tmp3); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3785 | break; |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 3786 | case ISD::SELECT_CC: |
| 3787 | Tmp2 = PromoteOp(Node->getOperand(2)); // True |
| 3788 | Tmp3 = PromoteOp(Node->getOperand(3)); // False |
| 3789 | Result = DAG.getNode(ISD::SELECT_CC, NVT, Node->getOperand(0), |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3790 | Node->getOperand(1), Tmp2, Tmp3, Node->getOperand(4)); |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 3791 | break; |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 3792 | case ISD::BSWAP: |
| 3793 | Tmp1 = Node->getOperand(0); |
| 3794 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Tmp1); |
| 3795 | Tmp1 = DAG.getNode(ISD::BSWAP, NVT, Tmp1); |
| 3796 | Result = DAG.getNode(ISD::SRL, NVT, Tmp1, |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 3797 | DAG.getConstant(MVT::getSizeInBits(NVT) - |
| 3798 | MVT::getSizeInBits(VT), |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 3799 | TLI.getShiftAmountTy())); |
| 3800 | break; |
Andrew Lenharth | fecf095 | 2005-05-04 19:11:05 +0000 | [diff] [blame] | 3801 | case ISD::CTPOP: |
| 3802 | case ISD::CTTZ: |
| 3803 | case ISD::CTLZ: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3804 | // Zero extend the argument |
| 3805 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Node->getOperand(0)); |
Andrew Lenharth | fecf095 | 2005-05-04 19:11:05 +0000 | [diff] [blame] | 3806 | // Perform the larger operation, then subtract if needed. |
| 3807 | Tmp1 = DAG.getNode(Node->getOpcode(), NVT, Tmp1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3808 | switch(Node->getOpcode()) { |
Andrew Lenharth | fecf095 | 2005-05-04 19:11:05 +0000 | [diff] [blame] | 3809 | case ISD::CTPOP: |
| 3810 | Result = Tmp1; |
| 3811 | break; |
| 3812 | case ISD::CTTZ: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3813 | // if Tmp1 == sizeinbits(NVT) then Tmp1 = sizeinbits(Old VT) |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 3814 | Tmp2 = DAG.getSetCC(TLI.getSetCCResultTy(), Tmp1, |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 3815 | DAG.getConstant(MVT::getSizeInBits(NVT), NVT), |
| 3816 | ISD::SETEQ); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 3817 | Result = DAG.getNode(ISD::SELECT, NVT, Tmp2, |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 3818 | DAG.getConstant(MVT::getSizeInBits(VT), NVT), Tmp1); |
Andrew Lenharth | fecf095 | 2005-05-04 19:11:05 +0000 | [diff] [blame] | 3819 | break; |
| 3820 | case ISD::CTLZ: |
| 3821 | //Tmp1 = Tmp1 - (sizeinbits(NVT) - sizeinbits(Old VT)) |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 3822 | Result = DAG.getNode(ISD::SUB, NVT, Tmp1, |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 3823 | DAG.getConstant(MVT::getSizeInBits(NVT) - |
| 3824 | MVT::getSizeInBits(VT), NVT)); |
Andrew Lenharth | fecf095 | 2005-05-04 19:11:05 +0000 | [diff] [blame] | 3825 | break; |
| 3826 | } |
| 3827 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3828 | case ISD::EXTRACT_SUBVECTOR: |
| 3829 | Result = PromoteOp(ExpandEXTRACT_SUBVECTOR(Op)); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 3830 | break; |
Chris Lattner | 4aab2f4 | 2006-04-02 05:06:04 +0000 | [diff] [blame] | 3831 | case ISD::EXTRACT_VECTOR_ELT: |
| 3832 | Result = PromoteOp(ExpandEXTRACT_VECTOR_ELT(Op)); |
| 3833 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3834 | } |
| 3835 | |
| 3836 | assert(Result.Val && "Didn't set a result!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3837 | |
| 3838 | // Make sure the result is itself legal. |
| 3839 | Result = LegalizeOp(Result); |
| 3840 | |
| 3841 | // Remember that we promoted this! |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3842 | AddPromotedOperand(Op, Result); |
| 3843 | return Result; |
| 3844 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3845 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3846 | /// ExpandEXTRACT_VECTOR_ELT - Expand an EXTRACT_VECTOR_ELT operation into |
| 3847 | /// a legal EXTRACT_VECTOR_ELT operation, scalar code, or memory traffic, |
| 3848 | /// based on the vector type. The return type of this matches the element type |
| 3849 | /// of the vector, which may not be legal for the target. |
| 3850 | SDOperand SelectionDAGLegalize::ExpandEXTRACT_VECTOR_ELT(SDOperand Op) { |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 3851 | // We know that operand #0 is the Vec vector. If the index is a constant |
| 3852 | // or if the invec is a supported hardware type, we can use it. Otherwise, |
| 3853 | // lower to a store then an indexed load. |
| 3854 | SDOperand Vec = Op.getOperand(0); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3855 | SDOperand Idx = Op.getOperand(1); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 3856 | |
| 3857 | SDNode *InVal = Vec.Val; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3858 | MVT::ValueType TVT = InVal->getValueType(0); |
| 3859 | unsigned NumElems = MVT::getVectorNumElements(TVT); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 3860 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3861 | switch (TLI.getOperationAction(ISD::EXTRACT_VECTOR_ELT, TVT)) { |
| 3862 | default: assert(0 && "This action is not supported yet!"); |
| 3863 | case TargetLowering::Custom: { |
| 3864 | Vec = LegalizeOp(Vec); |
| 3865 | Op = DAG.UpdateNodeOperands(Op, Vec, Idx); |
| 3866 | SDOperand Tmp3 = TLI.LowerOperation(Op, DAG); |
| 3867 | if (Tmp3.Val) |
| 3868 | return Tmp3; |
| 3869 | break; |
| 3870 | } |
| 3871 | case TargetLowering::Legal: |
| 3872 | if (isTypeLegal(TVT)) { |
| 3873 | Vec = LegalizeOp(Vec); |
| 3874 | Op = DAG.UpdateNodeOperands(Op, Vec, Idx); |
Christopher Lamb | 844228a | 2007-07-26 03:33:13 +0000 | [diff] [blame] | 3875 | return Op; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3876 | } |
| 3877 | break; |
| 3878 | case TargetLowering::Expand: |
| 3879 | break; |
| 3880 | } |
| 3881 | |
| 3882 | if (NumElems == 1) { |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 3883 | // This must be an access of the only element. Return it. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3884 | Op = ScalarizeVectorOp(Vec); |
| 3885 | } else if (!TLI.isTypeLegal(TVT) && isa<ConstantSDNode>(Idx)) { |
| 3886 | ConstantSDNode *CIdx = cast<ConstantSDNode>(Idx); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 3887 | SDOperand Lo, Hi; |
| 3888 | SplitVectorOp(Vec, Lo, Hi); |
| 3889 | if (CIdx->getValue() < NumElems/2) { |
| 3890 | Vec = Lo; |
| 3891 | } else { |
| 3892 | Vec = Hi; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3893 | Idx = DAG.getConstant(CIdx->getValue() - NumElems/2, |
| 3894 | Idx.getValueType()); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 3895 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3896 | |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 3897 | // It's now an extract from the appropriate high or low part. Recurse. |
| 3898 | Op = DAG.UpdateNodeOperands(Op, Vec, Idx); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3899 | Op = ExpandEXTRACT_VECTOR_ELT(Op); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 3900 | } else { |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3901 | // Store the value to a temporary stack slot, then LOAD the scalar |
| 3902 | // element back out. |
| 3903 | SDOperand StackPtr = CreateStackTemporary(Vec.getValueType()); |
| 3904 | SDOperand Ch = DAG.getStore(DAG.getEntryNode(), Vec, StackPtr, NULL, 0); |
| 3905 | |
| 3906 | // Add the offset to the index. |
| 3907 | unsigned EltSize = MVT::getSizeInBits(Op.getValueType())/8; |
| 3908 | Idx = DAG.getNode(ISD::MUL, Idx.getValueType(), Idx, |
| 3909 | DAG.getConstant(EltSize, Idx.getValueType())); |
| 3910 | StackPtr = DAG.getNode(ISD::ADD, Idx.getValueType(), Idx, StackPtr); |
| 3911 | |
| 3912 | Op = DAG.getLoad(Op.getValueType(), Ch, StackPtr, NULL, 0); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 3913 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3914 | return Op; |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 3915 | } |
| 3916 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3917 | /// ExpandEXTRACT_SUBVECTOR - Expand a EXTRACT_SUBVECTOR operation. For now |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 3918 | /// we assume the operation can be split if it is not already legal. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3919 | SDOperand SelectionDAGLegalize::ExpandEXTRACT_SUBVECTOR(SDOperand Op) { |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 3920 | // We know that operand #0 is the Vec vector. For now we assume the index |
| 3921 | // is a constant and that the extracted result is a supported hardware type. |
| 3922 | SDOperand Vec = Op.getOperand(0); |
| 3923 | SDOperand Idx = LegalizeOp(Op.getOperand(1)); |
| 3924 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3925 | unsigned NumElems = MVT::getVectorNumElements(Vec.getValueType()); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 3926 | |
| 3927 | if (NumElems == MVT::getVectorNumElements(Op.getValueType())) { |
| 3928 | // This must be an access of the desired vector length. Return it. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3929 | return Vec; |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 3930 | } |
| 3931 | |
| 3932 | ConstantSDNode *CIdx = cast<ConstantSDNode>(Idx); |
| 3933 | SDOperand Lo, Hi; |
| 3934 | SplitVectorOp(Vec, Lo, Hi); |
| 3935 | if (CIdx->getValue() < NumElems/2) { |
| 3936 | Vec = Lo; |
| 3937 | } else { |
| 3938 | Vec = Hi; |
| 3939 | Idx = DAG.getConstant(CIdx->getValue() - NumElems/2, Idx.getValueType()); |
| 3940 | } |
| 3941 | |
| 3942 | // It's now an extract from the appropriate high or low part. Recurse. |
| 3943 | Op = DAG.UpdateNodeOperands(Op, Vec, Idx); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3944 | return ExpandEXTRACT_SUBVECTOR(Op); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 3945 | } |
| 3946 | |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 3947 | /// LegalizeSetCCOperands - Attempts to create a legal LHS and RHS for a SETCC |
| 3948 | /// with condition CC on the current target. This usually involves legalizing |
| 3949 | /// or promoting the arguments. In the case where LHS and RHS must be expanded, |
| 3950 | /// there may be no choice but to create a new SetCC node to represent the |
| 3951 | /// legalized value of setcc lhs, rhs. In this case, the value is returned in |
| 3952 | /// LHS, and the SDOperand returned in RHS has a nil SDNode value. |
| 3953 | void SelectionDAGLegalize::LegalizeSetCCOperands(SDOperand &LHS, |
| 3954 | SDOperand &RHS, |
| 3955 | SDOperand &CC) { |
| 3956 | SDOperand Tmp1, Tmp2, Result; |
| 3957 | |
| 3958 | switch (getTypeAction(LHS.getValueType())) { |
| 3959 | case Legal: |
| 3960 | Tmp1 = LegalizeOp(LHS); // LHS |
| 3961 | Tmp2 = LegalizeOp(RHS); // RHS |
| 3962 | break; |
| 3963 | case Promote: |
| 3964 | Tmp1 = PromoteOp(LHS); // LHS |
| 3965 | Tmp2 = PromoteOp(RHS); // RHS |
| 3966 | |
| 3967 | // If this is an FP compare, the operands have already been extended. |
| 3968 | if (MVT::isInteger(LHS.getValueType())) { |
| 3969 | MVT::ValueType VT = LHS.getValueType(); |
| 3970 | MVT::ValueType NVT = TLI.getTypeToTransformTo(VT); |
| 3971 | |
| 3972 | // Otherwise, we have to insert explicit sign or zero extends. Note |
| 3973 | // that we could insert sign extends for ALL conditions, but zero extend |
| 3974 | // is cheaper on many machines (an AND instead of two shifts), so prefer |
| 3975 | // it. |
| 3976 | switch (cast<CondCodeSDNode>(CC)->get()) { |
| 3977 | default: assert(0 && "Unknown integer comparison!"); |
| 3978 | case ISD::SETEQ: |
| 3979 | case ISD::SETNE: |
| 3980 | case ISD::SETUGE: |
| 3981 | case ISD::SETUGT: |
| 3982 | case ISD::SETULE: |
| 3983 | case ISD::SETULT: |
| 3984 | // ALL of these operations will work if we either sign or zero extend |
| 3985 | // the operands (including the unsigned comparisons!). Zero extend is |
| 3986 | // usually a simpler/cheaper operation, so prefer it. |
| 3987 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, VT); |
| 3988 | Tmp2 = DAG.getZeroExtendInReg(Tmp2, VT); |
| 3989 | break; |
| 3990 | case ISD::SETGE: |
| 3991 | case ISD::SETGT: |
| 3992 | case ISD::SETLT: |
| 3993 | case ISD::SETLE: |
| 3994 | Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp1, |
| 3995 | DAG.getValueType(VT)); |
| 3996 | Tmp2 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp2, |
| 3997 | DAG.getValueType(VT)); |
| 3998 | break; |
| 3999 | } |
| 4000 | } |
| 4001 | break; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4002 | case Expand: { |
| 4003 | MVT::ValueType VT = LHS.getValueType(); |
| 4004 | if (VT == MVT::f32 || VT == MVT::f64) { |
| 4005 | // Expand into one or more soft-fp libcall(s). |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4006 | RTLIB::Libcall LC1, LC2 = RTLIB::UNKNOWN_LIBCALL; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4007 | switch (cast<CondCodeSDNode>(CC)->get()) { |
| 4008 | case ISD::SETEQ: |
| 4009 | case ISD::SETOEQ: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4010 | LC1 = (VT == MVT::f32) ? RTLIB::OEQ_F32 : RTLIB::OEQ_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4011 | break; |
| 4012 | case ISD::SETNE: |
| 4013 | case ISD::SETUNE: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4014 | LC1 = (VT == MVT::f32) ? RTLIB::UNE_F32 : RTLIB::UNE_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4015 | break; |
| 4016 | case ISD::SETGE: |
| 4017 | case ISD::SETOGE: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4018 | LC1 = (VT == MVT::f32) ? RTLIB::OGE_F32 : RTLIB::OGE_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4019 | break; |
| 4020 | case ISD::SETLT: |
| 4021 | case ISD::SETOLT: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4022 | LC1 = (VT == MVT::f32) ? RTLIB::OLT_F32 : RTLIB::OLT_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4023 | break; |
| 4024 | case ISD::SETLE: |
| 4025 | case ISD::SETOLE: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4026 | LC1 = (VT == MVT::f32) ? RTLIB::OLE_F32 : RTLIB::OLE_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4027 | break; |
| 4028 | case ISD::SETGT: |
| 4029 | case ISD::SETOGT: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4030 | LC1 = (VT == MVT::f32) ? RTLIB::OGT_F32 : RTLIB::OGT_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4031 | break; |
| 4032 | case ISD::SETUO: |
Evan Cheng | d385fd6 | 2007-01-31 09:29:11 +0000 | [diff] [blame] | 4033 | LC1 = (VT == MVT::f32) ? RTLIB::UO_F32 : RTLIB::UO_F64; |
| 4034 | break; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4035 | case ISD::SETO: |
Evan Cheng | 5efdecc | 2007-02-03 00:43:46 +0000 | [diff] [blame] | 4036 | LC1 = (VT == MVT::f32) ? RTLIB::O_F32 : RTLIB::O_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4037 | break; |
| 4038 | default: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4039 | LC1 = (VT == MVT::f32) ? RTLIB::UO_F32 : RTLIB::UO_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4040 | switch (cast<CondCodeSDNode>(CC)->get()) { |
| 4041 | case ISD::SETONE: |
| 4042 | // SETONE = SETOLT | SETOGT |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4043 | LC1 = (VT == MVT::f32) ? RTLIB::OLT_F32 : RTLIB::OLT_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4044 | // Fallthrough |
| 4045 | case ISD::SETUGT: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4046 | LC2 = (VT == MVT::f32) ? RTLIB::OGT_F32 : RTLIB::OGT_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4047 | break; |
| 4048 | case ISD::SETUGE: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4049 | LC2 = (VT == MVT::f32) ? RTLIB::OGE_F32 : RTLIB::OGE_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4050 | break; |
| 4051 | case ISD::SETULT: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4052 | LC2 = (VT == MVT::f32) ? RTLIB::OLT_F32 : RTLIB::OLT_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4053 | break; |
| 4054 | case ISD::SETULE: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4055 | LC2 = (VT == MVT::f32) ? RTLIB::OLE_F32 : RTLIB::OLE_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4056 | break; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4057 | case ISD::SETUEQ: |
| 4058 | LC2 = (VT == MVT::f32) ? RTLIB::OEQ_F32 : RTLIB::OEQ_F64; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4059 | break; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4060 | default: assert(0 && "Unsupported FP setcc!"); |
| 4061 | } |
| 4062 | } |
| 4063 | |
| 4064 | SDOperand Dummy; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4065 | Tmp1 = ExpandLibCall(TLI.getLibcallName(LC1), |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 4066 | DAG.getNode(ISD::MERGE_VALUES, VT, LHS, RHS).Val, |
Reid Spencer | b47b25c | 2007-01-03 04:22:32 +0000 | [diff] [blame] | 4067 | false /*sign irrelevant*/, Dummy); |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4068 | Tmp2 = DAG.getConstant(0, MVT::i32); |
Evan Cheng | d385fd6 | 2007-01-31 09:29:11 +0000 | [diff] [blame] | 4069 | CC = DAG.getCondCode(TLI.getCmpLibcallCC(LC1)); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4070 | if (LC2 != RTLIB::UNKNOWN_LIBCALL) { |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4071 | Tmp1 = DAG.getNode(ISD::SETCC, TLI.getSetCCResultTy(), Tmp1, Tmp2, CC); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4072 | LHS = ExpandLibCall(TLI.getLibcallName(LC2), |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 4073 | DAG.getNode(ISD::MERGE_VALUES, VT, LHS, RHS).Val, |
Reid Spencer | b47b25c | 2007-01-03 04:22:32 +0000 | [diff] [blame] | 4074 | false /*sign irrelevant*/, Dummy); |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4075 | Tmp2 = DAG.getNode(ISD::SETCC, TLI.getSetCCResultTy(), LHS, Tmp2, |
Evan Cheng | d385fd6 | 2007-01-31 09:29:11 +0000 | [diff] [blame] | 4076 | DAG.getCondCode(TLI.getCmpLibcallCC(LC2))); |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4077 | Tmp1 = DAG.getNode(ISD::OR, Tmp1.getValueType(), Tmp1, Tmp2); |
| 4078 | Tmp2 = SDOperand(); |
| 4079 | } |
| 4080 | LHS = Tmp1; |
| 4081 | RHS = Tmp2; |
| 4082 | return; |
| 4083 | } |
| 4084 | |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 4085 | SDOperand LHSLo, LHSHi, RHSLo, RHSHi; |
| 4086 | ExpandOp(LHS, LHSLo, LHSHi); |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4087 | ExpandOp(RHS, RHSLo, RHSHi); |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 4088 | switch (cast<CondCodeSDNode>(CC)->get()) { |
| 4089 | case ISD::SETEQ: |
| 4090 | case ISD::SETNE: |
| 4091 | if (RHSLo == RHSHi) |
| 4092 | if (ConstantSDNode *RHSCST = dyn_cast<ConstantSDNode>(RHSLo)) |
| 4093 | if (RHSCST->isAllOnesValue()) { |
| 4094 | // Comparison to -1. |
| 4095 | Tmp1 = DAG.getNode(ISD::AND, LHSLo.getValueType(), LHSLo, LHSHi); |
| 4096 | Tmp2 = RHSLo; |
| 4097 | break; |
| 4098 | } |
| 4099 | |
| 4100 | Tmp1 = DAG.getNode(ISD::XOR, LHSLo.getValueType(), LHSLo, RHSLo); |
| 4101 | Tmp2 = DAG.getNode(ISD::XOR, LHSLo.getValueType(), LHSHi, RHSHi); |
| 4102 | Tmp1 = DAG.getNode(ISD::OR, Tmp1.getValueType(), Tmp1, Tmp2); |
| 4103 | Tmp2 = DAG.getConstant(0, Tmp1.getValueType()); |
| 4104 | break; |
| 4105 | default: |
| 4106 | // If this is a comparison of the sign bit, just look at the top part. |
| 4107 | // X > -1, x < 0 |
| 4108 | if (ConstantSDNode *CST = dyn_cast<ConstantSDNode>(RHS)) |
| 4109 | if ((cast<CondCodeSDNode>(CC)->get() == ISD::SETLT && |
| 4110 | CST->getValue() == 0) || // X < 0 |
| 4111 | (cast<CondCodeSDNode>(CC)->get() == ISD::SETGT && |
| 4112 | CST->isAllOnesValue())) { // X > -1 |
| 4113 | Tmp1 = LHSHi; |
| 4114 | Tmp2 = RHSHi; |
| 4115 | break; |
| 4116 | } |
| 4117 | |
| 4118 | // FIXME: This generated code sucks. |
| 4119 | ISD::CondCode LowCC; |
Evan Cheng | 2e67781 | 2007-02-08 22:16:19 +0000 | [diff] [blame] | 4120 | ISD::CondCode CCCode = cast<CondCodeSDNode>(CC)->get(); |
| 4121 | switch (CCCode) { |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 4122 | default: assert(0 && "Unknown integer setcc!"); |
| 4123 | case ISD::SETLT: |
| 4124 | case ISD::SETULT: LowCC = ISD::SETULT; break; |
| 4125 | case ISD::SETGT: |
| 4126 | case ISD::SETUGT: LowCC = ISD::SETUGT; break; |
| 4127 | case ISD::SETLE: |
| 4128 | case ISD::SETULE: LowCC = ISD::SETULE; break; |
| 4129 | case ISD::SETGE: |
| 4130 | case ISD::SETUGE: LowCC = ISD::SETUGE; break; |
| 4131 | } |
| 4132 | |
| 4133 | // Tmp1 = lo(op1) < lo(op2) // Always unsigned comparison |
| 4134 | // Tmp2 = hi(op1) < hi(op2) // Signedness depends on operands |
| 4135 | // dest = hi(op1) == hi(op2) ? Tmp1 : Tmp2; |
| 4136 | |
| 4137 | // NOTE: on targets without efficient SELECT of bools, we can always use |
| 4138 | // this identity: (B1 ? B2 : B3) --> (B1 & B2)|(!B1&B3) |
Evan Cheng | 2e67781 | 2007-02-08 22:16:19 +0000 | [diff] [blame] | 4139 | TargetLowering::DAGCombinerInfo DagCombineInfo(DAG, false, true, NULL); |
| 4140 | Tmp1 = TLI.SimplifySetCC(TLI.getSetCCResultTy(), LHSLo, RHSLo, LowCC, |
| 4141 | false, DagCombineInfo); |
| 4142 | if (!Tmp1.Val) |
| 4143 | Tmp1 = DAG.getSetCC(TLI.getSetCCResultTy(), LHSLo, RHSLo, LowCC); |
| 4144 | Tmp2 = TLI.SimplifySetCC(TLI.getSetCCResultTy(), LHSHi, RHSHi, |
| 4145 | CCCode, false, DagCombineInfo); |
| 4146 | if (!Tmp2.Val) |
| 4147 | Tmp2 = DAG.getNode(ISD::SETCC, TLI.getSetCCResultTy(), LHSHi, RHSHi, CC); |
| 4148 | |
| 4149 | ConstantSDNode *Tmp1C = dyn_cast<ConstantSDNode>(Tmp1.Val); |
| 4150 | ConstantSDNode *Tmp2C = dyn_cast<ConstantSDNode>(Tmp2.Val); |
| 4151 | if ((Tmp1C && Tmp1C->getValue() == 0) || |
| 4152 | (Tmp2C && Tmp2C->getValue() == 0 && |
| 4153 | (CCCode == ISD::SETLE || CCCode == ISD::SETGE || |
| 4154 | CCCode == ISD::SETUGE || CCCode == ISD::SETULE)) || |
| 4155 | (Tmp2C && Tmp2C->getValue() == 1 && |
| 4156 | (CCCode == ISD::SETLT || CCCode == ISD::SETGT || |
| 4157 | CCCode == ISD::SETUGT || CCCode == ISD::SETULT))) { |
| 4158 | // low part is known false, returns high part. |
| 4159 | // For LE / GE, if high part is known false, ignore the low part. |
| 4160 | // For LT / GT, if high part is known true, ignore the low part. |
| 4161 | Tmp1 = Tmp2; |
| 4162 | Tmp2 = SDOperand(); |
| 4163 | } else { |
| 4164 | Result = TLI.SimplifySetCC(TLI.getSetCCResultTy(), LHSHi, RHSHi, |
| 4165 | ISD::SETEQ, false, DagCombineInfo); |
| 4166 | if (!Result.Val) |
| 4167 | Result=DAG.getSetCC(TLI.getSetCCResultTy(), LHSHi, RHSHi, ISD::SETEQ); |
| 4168 | Result = LegalizeOp(DAG.getNode(ISD::SELECT, Tmp1.getValueType(), |
| 4169 | Result, Tmp1, Tmp2)); |
| 4170 | Tmp1 = Result; |
| 4171 | Tmp2 = SDOperand(); |
| 4172 | } |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 4173 | } |
| 4174 | } |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4175 | } |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 4176 | LHS = Tmp1; |
| 4177 | RHS = Tmp2; |
| 4178 | } |
| 4179 | |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 4180 | /// ExpandBIT_CONVERT - Expand a BIT_CONVERT node into a store/load combination. |
Chris Lattner | 232348d | 2005-12-23 00:52:30 +0000 | [diff] [blame] | 4181 | /// The resultant code need not be legal. Note that SrcOp is the input operand |
| 4182 | /// to the BIT_CONVERT, not the BIT_CONVERT node itself. |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 4183 | SDOperand SelectionDAGLegalize::ExpandBIT_CONVERT(MVT::ValueType DestVT, |
| 4184 | SDOperand SrcOp) { |
| 4185 | // Create the stack frame object. |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4186 | SDOperand FIPtr = CreateStackTemporary(DestVT); |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 4187 | |
| 4188 | // Emit a store to the stack slot. |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 4189 | SDOperand Store = DAG.getStore(DAG.getEntryNode(), SrcOp, FIPtr, NULL, 0); |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 4190 | // Result is a load from the stack slot. |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 4191 | return DAG.getLoad(DestVT, Store, FIPtr, NULL, 0); |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 4192 | } |
| 4193 | |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 4194 | SDOperand SelectionDAGLegalize::ExpandSCALAR_TO_VECTOR(SDNode *Node) { |
| 4195 | // Create a vector sized/aligned stack slot, store the value to element #0, |
| 4196 | // then load the whole vector back out. |
| 4197 | SDOperand StackPtr = CreateStackTemporary(Node->getValueType(0)); |
Evan Cheng | 786225a | 2006-10-05 23:01:46 +0000 | [diff] [blame] | 4198 | SDOperand Ch = DAG.getStore(DAG.getEntryNode(), Node->getOperand(0), StackPtr, |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 4199 | NULL, 0); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 4200 | return DAG.getLoad(Node->getValueType(0), Ch, StackPtr, NULL, 0); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 4201 | } |
| 4202 | |
| 4203 | |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4204 | /// ExpandBUILD_VECTOR - Expand a BUILD_VECTOR node on targets that don't |
Dan Gohman | 07a9676 | 2007-07-16 14:29:03 +0000 | [diff] [blame] | 4205 | /// support the operation, but do support the resultant vector type. |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4206 | SDOperand SelectionDAGLegalize::ExpandBUILD_VECTOR(SDNode *Node) { |
| 4207 | |
| 4208 | // If the only non-undef value is the low element, turn this into a |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 4209 | // SCALAR_TO_VECTOR node. If this is { X, X, X, X }, determine X. |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 4210 | unsigned NumElems = Node->getNumOperands(); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4211 | bool isOnlyLowElement = true; |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 4212 | SDOperand SplatValue = Node->getOperand(0); |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 4213 | std::map<SDOperand, std::vector<unsigned> > Values; |
| 4214 | Values[SplatValue].push_back(0); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 4215 | bool isConstant = true; |
| 4216 | if (!isa<ConstantFPSDNode>(SplatValue) && !isa<ConstantSDNode>(SplatValue) && |
| 4217 | SplatValue.getOpcode() != ISD::UNDEF) |
| 4218 | isConstant = false; |
| 4219 | |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 4220 | for (unsigned i = 1; i < NumElems; ++i) { |
| 4221 | SDOperand V = Node->getOperand(i); |
Chris Lattner | 89a1b38 | 2006-04-19 23:17:50 +0000 | [diff] [blame] | 4222 | Values[V].push_back(i); |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 4223 | if (V.getOpcode() != ISD::UNDEF) |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4224 | isOnlyLowElement = false; |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 4225 | if (SplatValue != V) |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 4226 | SplatValue = SDOperand(0,0); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 4227 | |
| 4228 | // If this isn't a constant element or an undef, we can't use a constant |
| 4229 | // pool load. |
| 4230 | if (!isa<ConstantFPSDNode>(V) && !isa<ConstantSDNode>(V) && |
| 4231 | V.getOpcode() != ISD::UNDEF) |
| 4232 | isConstant = false; |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4233 | } |
| 4234 | |
| 4235 | if (isOnlyLowElement) { |
| 4236 | // If the low element is an undef too, then this whole things is an undef. |
| 4237 | if (Node->getOperand(0).getOpcode() == ISD::UNDEF) |
| 4238 | return DAG.getNode(ISD::UNDEF, Node->getValueType(0)); |
| 4239 | // Otherwise, turn this into a scalar_to_vector node. |
| 4240 | return DAG.getNode(ISD::SCALAR_TO_VECTOR, Node->getValueType(0), |
| 4241 | Node->getOperand(0)); |
| 4242 | } |
| 4243 | |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 4244 | // If all elements are constants, create a load from the constant pool. |
| 4245 | if (isConstant) { |
| 4246 | MVT::ValueType VT = Node->getValueType(0); |
| 4247 | const Type *OpNTy = |
| 4248 | MVT::getTypeForValueType(Node->getOperand(0).getValueType()); |
| 4249 | std::vector<Constant*> CV; |
| 4250 | for (unsigned i = 0, e = NumElems; i != e; ++i) { |
| 4251 | if (ConstantFPSDNode *V = |
| 4252 | dyn_cast<ConstantFPSDNode>(Node->getOperand(i))) { |
Dale Johannesen | f04afdb | 2007-08-30 00:23:21 +0000 | [diff] [blame] | 4253 | CV.push_back(ConstantFP::get(OpNTy, V->getValueAPF())); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 4254 | } else if (ConstantSDNode *V = |
| 4255 | dyn_cast<ConstantSDNode>(Node->getOperand(i))) { |
Reid Spencer | b83eb64 | 2006-10-20 07:07:24 +0000 | [diff] [blame] | 4256 | CV.push_back(ConstantInt::get(OpNTy, V->getValue())); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 4257 | } else { |
| 4258 | assert(Node->getOperand(i).getOpcode() == ISD::UNDEF); |
| 4259 | CV.push_back(UndefValue::get(OpNTy)); |
| 4260 | } |
| 4261 | } |
Reid Spencer | 9d6565a | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 4262 | Constant *CP = ConstantVector::get(CV); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 4263 | SDOperand CPIdx = DAG.getConstantPool(CP, TLI.getPointerTy()); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 4264 | return DAG.getLoad(VT, DAG.getEntryNode(), CPIdx, NULL, 0); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 4265 | } |
| 4266 | |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 4267 | if (SplatValue.Val) { // Splat of one value? |
| 4268 | // Build the shuffle constant vector: <0, 0, 0, 0> |
| 4269 | MVT::ValueType MaskVT = |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 4270 | MVT::getIntVectorWithNumElements(NumElems); |
Dan Gohman | 51eaa86 | 2007-06-14 22:58:02 +0000 | [diff] [blame] | 4271 | SDOperand Zero = DAG.getConstant(0, MVT::getVectorElementType(MaskVT)); |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 4272 | std::vector<SDOperand> ZeroVec(NumElems, Zero); |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 4273 | SDOperand SplatMask = DAG.getNode(ISD::BUILD_VECTOR, MaskVT, |
| 4274 | &ZeroVec[0], ZeroVec.size()); |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 4275 | |
| 4276 | // If the target supports VECTOR_SHUFFLE and this shuffle mask, use it. |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 4277 | if (isShuffleLegal(Node->getValueType(0), SplatMask)) { |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 4278 | // Get the splatted value into the low element of a vector register. |
| 4279 | SDOperand LowValVec = |
| 4280 | DAG.getNode(ISD::SCALAR_TO_VECTOR, Node->getValueType(0), SplatValue); |
| 4281 | |
| 4282 | // Return shuffle(LowValVec, undef, <0,0,0,0>) |
| 4283 | return DAG.getNode(ISD::VECTOR_SHUFFLE, Node->getValueType(0), LowValVec, |
| 4284 | DAG.getNode(ISD::UNDEF, Node->getValueType(0)), |
| 4285 | SplatMask); |
| 4286 | } |
| 4287 | } |
| 4288 | |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 4289 | // If there are only two unique elements, we may be able to turn this into a |
| 4290 | // vector shuffle. |
| 4291 | if (Values.size() == 2) { |
| 4292 | // Build the shuffle constant vector: e.g. <0, 4, 0, 4> |
| 4293 | MVT::ValueType MaskVT = |
| 4294 | MVT::getIntVectorWithNumElements(NumElems); |
| 4295 | std::vector<SDOperand> MaskVec(NumElems); |
| 4296 | unsigned i = 0; |
| 4297 | for (std::map<SDOperand,std::vector<unsigned> >::iterator I=Values.begin(), |
| 4298 | E = Values.end(); I != E; ++I) { |
| 4299 | for (std::vector<unsigned>::iterator II = I->second.begin(), |
| 4300 | EE = I->second.end(); II != EE; ++II) |
Dan Gohman | 51eaa86 | 2007-06-14 22:58:02 +0000 | [diff] [blame] | 4301 | MaskVec[*II] = DAG.getConstant(i, MVT::getVectorElementType(MaskVT)); |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 4302 | i += NumElems; |
| 4303 | } |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 4304 | SDOperand ShuffleMask = DAG.getNode(ISD::BUILD_VECTOR, MaskVT, |
| 4305 | &MaskVec[0], MaskVec.size()); |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 4306 | |
| 4307 | // If the target supports VECTOR_SHUFFLE and this shuffle mask, use it. |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 4308 | if (TLI.isOperationLegal(ISD::SCALAR_TO_VECTOR, Node->getValueType(0)) && |
| 4309 | isShuffleLegal(Node->getValueType(0), ShuffleMask)) { |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 4310 | SmallVector<SDOperand, 8> Ops; |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 4311 | for(std::map<SDOperand,std::vector<unsigned> >::iterator I=Values.begin(), |
| 4312 | E = Values.end(); I != E; ++I) { |
| 4313 | SDOperand Op = DAG.getNode(ISD::SCALAR_TO_VECTOR, Node->getValueType(0), |
| 4314 | I->first); |
| 4315 | Ops.push_back(Op); |
| 4316 | } |
| 4317 | Ops.push_back(ShuffleMask); |
| 4318 | |
| 4319 | // Return shuffle(LoValVec, HiValVec, <0,1,0,1>) |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 4320 | return DAG.getNode(ISD::VECTOR_SHUFFLE, Node->getValueType(0), |
| 4321 | &Ops[0], Ops.size()); |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 4322 | } |
| 4323 | } |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4324 | |
| 4325 | // Otherwise, we can't handle this case efficiently. Allocate a sufficiently |
| 4326 | // aligned object on the stack, store each element into it, then load |
| 4327 | // the result as a vector. |
| 4328 | MVT::ValueType VT = Node->getValueType(0); |
| 4329 | // Create the stack frame object. |
| 4330 | SDOperand FIPtr = CreateStackTemporary(VT); |
| 4331 | |
| 4332 | // Emit a store of each element to the stack slot. |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 4333 | SmallVector<SDOperand, 8> Stores; |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4334 | unsigned TypeByteSize = |
| 4335 | MVT::getSizeInBits(Node->getOperand(0).getValueType())/8; |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4336 | // Store (in the right endianness) the elements to memory. |
| 4337 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) { |
| 4338 | // Ignore undef elements. |
| 4339 | if (Node->getOperand(i).getOpcode() == ISD::UNDEF) continue; |
| 4340 | |
Chris Lattner | 841c882 | 2006-03-22 01:46:54 +0000 | [diff] [blame] | 4341 | unsigned Offset = TypeByteSize*i; |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4342 | |
| 4343 | SDOperand Idx = DAG.getConstant(Offset, FIPtr.getValueType()); |
| 4344 | Idx = DAG.getNode(ISD::ADD, FIPtr.getValueType(), FIPtr, Idx); |
| 4345 | |
Evan Cheng | 786225a | 2006-10-05 23:01:46 +0000 | [diff] [blame] | 4346 | Stores.push_back(DAG.getStore(DAG.getEntryNode(), Node->getOperand(i), Idx, |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 4347 | NULL, 0)); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4348 | } |
| 4349 | |
| 4350 | SDOperand StoreChain; |
| 4351 | if (!Stores.empty()) // Not all undef elements? |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 4352 | StoreChain = DAG.getNode(ISD::TokenFactor, MVT::Other, |
| 4353 | &Stores[0], Stores.size()); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4354 | else |
| 4355 | StoreChain = DAG.getEntryNode(); |
| 4356 | |
| 4357 | // Result is a load from the stack slot. |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 4358 | return DAG.getLoad(VT, StoreChain, FIPtr, NULL, 0); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4359 | } |
| 4360 | |
| 4361 | /// CreateStackTemporary - Create a stack temporary, suitable for holding the |
| 4362 | /// specified value type. |
| 4363 | SDOperand SelectionDAGLegalize::CreateStackTemporary(MVT::ValueType VT) { |
| 4364 | MachineFrameInfo *FrameInfo = DAG.getMachineFunction().getFrameInfo(); |
| 4365 | unsigned ByteSize = MVT::getSizeInBits(VT)/8; |
Chris Lattner | 58092e3 | 2007-01-20 22:35:55 +0000 | [diff] [blame] | 4366 | const Type *Ty = MVT::getTypeForValueType(VT); |
Chris Lattner | d2b7cec | 2007-02-14 05:52:17 +0000 | [diff] [blame] | 4367 | unsigned StackAlign = (unsigned)TLI.getTargetData()->getPrefTypeAlignment(Ty); |
Chris Lattner | 58092e3 | 2007-01-20 22:35:55 +0000 | [diff] [blame] | 4368 | int FrameIdx = FrameInfo->CreateStackObject(ByteSize, StackAlign); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4369 | return DAG.getFrameIndex(FrameIdx, TLI.getPointerTy()); |
| 4370 | } |
| 4371 | |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 4372 | void SelectionDAGLegalize::ExpandShiftParts(unsigned NodeOp, |
| 4373 | SDOperand Op, SDOperand Amt, |
| 4374 | SDOperand &Lo, SDOperand &Hi) { |
| 4375 | // Expand the subcomponents. |
| 4376 | SDOperand LHSL, LHSH; |
| 4377 | ExpandOp(Op, LHSL, LHSH); |
| 4378 | |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 4379 | SDOperand Ops[] = { LHSL, LHSH, Amt }; |
Chris Lattner | f9f37fc | 2006-08-14 23:53:35 +0000 | [diff] [blame] | 4380 | MVT::ValueType VT = LHSL.getValueType(); |
| 4381 | Lo = DAG.getNode(NodeOp, DAG.getNodeValueTypes(VT, VT), 2, Ops, 3); |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 4382 | Hi = Lo.getValue(1); |
| 4383 | } |
| 4384 | |
| 4385 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 4386 | /// ExpandShift - Try to find a clever way to expand this shift operation out to |
| 4387 | /// smaller elements. If we can't find a way that is more efficient than a |
| 4388 | /// libcall on this target, return false. Otherwise, return true with the |
| 4389 | /// low-parts expanded into Lo and Hi. |
| 4390 | bool SelectionDAGLegalize::ExpandShift(unsigned Opc, SDOperand Op,SDOperand Amt, |
| 4391 | SDOperand &Lo, SDOperand &Hi) { |
| 4392 | assert((Opc == ISD::SHL || Opc == ISD::SRA || Opc == ISD::SRL) && |
| 4393 | "This is not a shift!"); |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 4394 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 4395 | MVT::ValueType NVT = TLI.getTypeToTransformTo(Op.getValueType()); |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 4396 | SDOperand ShAmt = LegalizeOp(Amt); |
| 4397 | MVT::ValueType ShTy = ShAmt.getValueType(); |
| 4398 | unsigned VTBits = MVT::getSizeInBits(Op.getValueType()); |
| 4399 | unsigned NVTBits = MVT::getSizeInBits(NVT); |
| 4400 | |
| 4401 | // Handle the case when Amt is an immediate. Other cases are currently broken |
| 4402 | // and are disabled. |
| 4403 | if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Amt.Val)) { |
| 4404 | unsigned Cst = CN->getValue(); |
| 4405 | // Expand the incoming operand to be shifted, so that we have its parts |
| 4406 | SDOperand InL, InH; |
| 4407 | ExpandOp(Op, InL, InH); |
| 4408 | switch(Opc) { |
| 4409 | case ISD::SHL: |
| 4410 | if (Cst > VTBits) { |
| 4411 | Lo = DAG.getConstant(0, NVT); |
| 4412 | Hi = DAG.getConstant(0, NVT); |
| 4413 | } else if (Cst > NVTBits) { |
| 4414 | Lo = DAG.getConstant(0, NVT); |
| 4415 | Hi = DAG.getNode(ISD::SHL, NVT, InL, DAG.getConstant(Cst-NVTBits,ShTy)); |
Chris Lattner | ee27f57 | 2005-04-11 20:08:52 +0000 | [diff] [blame] | 4416 | } else if (Cst == NVTBits) { |
| 4417 | Lo = DAG.getConstant(0, NVT); |
| 4418 | Hi = InL; |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 4419 | } else { |
| 4420 | Lo = DAG.getNode(ISD::SHL, NVT, InL, DAG.getConstant(Cst, ShTy)); |
| 4421 | Hi = DAG.getNode(ISD::OR, NVT, |
| 4422 | DAG.getNode(ISD::SHL, NVT, InH, DAG.getConstant(Cst, ShTy)), |
| 4423 | DAG.getNode(ISD::SRL, NVT, InL, DAG.getConstant(NVTBits-Cst, ShTy))); |
| 4424 | } |
| 4425 | return true; |
| 4426 | case ISD::SRL: |
| 4427 | if (Cst > VTBits) { |
| 4428 | Lo = DAG.getConstant(0, NVT); |
| 4429 | Hi = DAG.getConstant(0, NVT); |
| 4430 | } else if (Cst > NVTBits) { |
| 4431 | Lo = DAG.getNode(ISD::SRL, NVT, InH, DAG.getConstant(Cst-NVTBits,ShTy)); |
| 4432 | Hi = DAG.getConstant(0, NVT); |
Chris Lattner | ee27f57 | 2005-04-11 20:08:52 +0000 | [diff] [blame] | 4433 | } else if (Cst == NVTBits) { |
| 4434 | Lo = InH; |
| 4435 | Hi = DAG.getConstant(0, NVT); |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 4436 | } else { |
| 4437 | Lo = DAG.getNode(ISD::OR, NVT, |
| 4438 | DAG.getNode(ISD::SRL, NVT, InL, DAG.getConstant(Cst, ShTy)), |
| 4439 | DAG.getNode(ISD::SHL, NVT, InH, DAG.getConstant(NVTBits-Cst, ShTy))); |
| 4440 | Hi = DAG.getNode(ISD::SRL, NVT, InH, DAG.getConstant(Cst, ShTy)); |
| 4441 | } |
| 4442 | return true; |
| 4443 | case ISD::SRA: |
| 4444 | if (Cst > VTBits) { |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 4445 | Hi = Lo = DAG.getNode(ISD::SRA, NVT, InH, |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 4446 | DAG.getConstant(NVTBits-1, ShTy)); |
| 4447 | } else if (Cst > NVTBits) { |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 4448 | Lo = DAG.getNode(ISD::SRA, NVT, InH, |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 4449 | DAG.getConstant(Cst-NVTBits, ShTy)); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 4450 | Hi = DAG.getNode(ISD::SRA, NVT, InH, |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 4451 | DAG.getConstant(NVTBits-1, ShTy)); |
Chris Lattner | ee27f57 | 2005-04-11 20:08:52 +0000 | [diff] [blame] | 4452 | } else if (Cst == NVTBits) { |
| 4453 | Lo = InH; |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 4454 | Hi = DAG.getNode(ISD::SRA, NVT, InH, |
Chris Lattner | ee27f57 | 2005-04-11 20:08:52 +0000 | [diff] [blame] | 4455 | DAG.getConstant(NVTBits-1, ShTy)); |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 4456 | } else { |
| 4457 | Lo = DAG.getNode(ISD::OR, NVT, |
| 4458 | DAG.getNode(ISD::SRL, NVT, InL, DAG.getConstant(Cst, ShTy)), |
| 4459 | DAG.getNode(ISD::SHL, NVT, InH, DAG.getConstant(NVTBits-Cst, ShTy))); |
| 4460 | Hi = DAG.getNode(ISD::SRA, NVT, InH, DAG.getConstant(Cst, ShTy)); |
| 4461 | } |
| 4462 | return true; |
| 4463 | } |
| 4464 | } |
Chris Lattner | 0ea26ca | 2006-09-20 03:38:48 +0000 | [diff] [blame] | 4465 | |
| 4466 | // Okay, the shift amount isn't constant. However, if we can tell that it is |
| 4467 | // >= 32 or < 32, we can still simplify it, without knowing the actual value. |
| 4468 | uint64_t Mask = NVTBits, KnownZero, KnownOne; |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 4469 | DAG.ComputeMaskedBits(Amt, Mask, KnownZero, KnownOne); |
Chris Lattner | 0ea26ca | 2006-09-20 03:38:48 +0000 | [diff] [blame] | 4470 | |
| 4471 | // If we know that the high bit of the shift amount is one, then we can do |
| 4472 | // this as a couple of simple shifts. |
| 4473 | if (KnownOne & Mask) { |
| 4474 | // Mask out the high bit, which we know is set. |
| 4475 | Amt = DAG.getNode(ISD::AND, Amt.getValueType(), Amt, |
| 4476 | DAG.getConstant(NVTBits-1, Amt.getValueType())); |
| 4477 | |
| 4478 | // Expand the incoming operand to be shifted, so that we have its parts |
| 4479 | SDOperand InL, InH; |
| 4480 | ExpandOp(Op, InL, InH); |
| 4481 | switch(Opc) { |
| 4482 | case ISD::SHL: |
| 4483 | Lo = DAG.getConstant(0, NVT); // Low part is zero. |
| 4484 | Hi = DAG.getNode(ISD::SHL, NVT, InL, Amt); // High part from Lo part. |
| 4485 | return true; |
| 4486 | case ISD::SRL: |
| 4487 | Hi = DAG.getConstant(0, NVT); // Hi part is zero. |
| 4488 | Lo = DAG.getNode(ISD::SRL, NVT, InH, Amt); // Lo part from Hi part. |
| 4489 | return true; |
| 4490 | case ISD::SRA: |
| 4491 | Hi = DAG.getNode(ISD::SRA, NVT, InH, // Sign extend high part. |
| 4492 | DAG.getConstant(NVTBits-1, Amt.getValueType())); |
| 4493 | Lo = DAG.getNode(ISD::SRA, NVT, InH, Amt); // Lo part from Hi part. |
| 4494 | return true; |
| 4495 | } |
| 4496 | } |
| 4497 | |
| 4498 | // If we know that the high bit of the shift amount is zero, then we can do |
| 4499 | // this as a couple of simple shifts. |
| 4500 | if (KnownZero & Mask) { |
| 4501 | // Compute 32-amt. |
| 4502 | SDOperand Amt2 = DAG.getNode(ISD::SUB, Amt.getValueType(), |
| 4503 | DAG.getConstant(NVTBits, Amt.getValueType()), |
| 4504 | Amt); |
| 4505 | |
| 4506 | // Expand the incoming operand to be shifted, so that we have its parts |
| 4507 | SDOperand InL, InH; |
| 4508 | ExpandOp(Op, InL, InH); |
| 4509 | switch(Opc) { |
| 4510 | case ISD::SHL: |
| 4511 | Lo = DAG.getNode(ISD::SHL, NVT, InL, Amt); |
| 4512 | Hi = DAG.getNode(ISD::OR, NVT, |
| 4513 | DAG.getNode(ISD::SHL, NVT, InH, Amt), |
| 4514 | DAG.getNode(ISD::SRL, NVT, InL, Amt2)); |
| 4515 | return true; |
| 4516 | case ISD::SRL: |
| 4517 | Hi = DAG.getNode(ISD::SRL, NVT, InH, Amt); |
| 4518 | Lo = DAG.getNode(ISD::OR, NVT, |
| 4519 | DAG.getNode(ISD::SRL, NVT, InL, Amt), |
| 4520 | DAG.getNode(ISD::SHL, NVT, InH, Amt2)); |
| 4521 | return true; |
| 4522 | case ISD::SRA: |
| 4523 | Hi = DAG.getNode(ISD::SRA, NVT, InH, Amt); |
| 4524 | Lo = DAG.getNode(ISD::OR, NVT, |
| 4525 | DAG.getNode(ISD::SRL, NVT, InL, Amt), |
| 4526 | DAG.getNode(ISD::SHL, NVT, InH, Amt2)); |
| 4527 | return true; |
| 4528 | } |
| 4529 | } |
| 4530 | |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 4531 | return false; |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 4532 | } |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4533 | |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 4534 | |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4535 | // ExpandLibCall - Expand a node into a call to a libcall. If the result value |
| 4536 | // does not fit into a register, return the lo part and set the hi part to the |
| 4537 | // by-reg argument. If it does fit into a single register, return the result |
| 4538 | // and leave the Hi part unset. |
| 4539 | SDOperand SelectionDAGLegalize::ExpandLibCall(const char *Name, SDNode *Node, |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 4540 | bool isSigned, SDOperand &Hi) { |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 4541 | assert(!IsLegalizingCall && "Cannot overlap legalization of calls!"); |
| 4542 | // The input chain to this libcall is the entry node of the function. |
| 4543 | // Legalizing the call will automatically add the previous call to the |
| 4544 | // dependence. |
| 4545 | SDOperand InChain = DAG.getEntryNode(); |
| 4546 | |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4547 | TargetLowering::ArgListTy Args; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 4548 | TargetLowering::ArgListEntry Entry; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4549 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) { |
| 4550 | MVT::ValueType ArgVT = Node->getOperand(i).getValueType(); |
| 4551 | const Type *ArgTy = MVT::getTypeForValueType(ArgVT); |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 4552 | Entry.Node = Node->getOperand(i); Entry.Ty = ArgTy; |
Anton Korobeynikov | d0b82b3 | 2007-03-07 16:25:09 +0000 | [diff] [blame] | 4553 | Entry.isSExt = isSigned; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 4554 | Args.push_back(Entry); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4555 | } |
| 4556 | SDOperand Callee = DAG.getExternalSymbol(Name, TLI.getPointerTy()); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 4557 | |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 4558 | // Splice the libcall in wherever FindInputOutputChains tells us to. |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4559 | const Type *RetTy = MVT::getTypeForValueType(Node->getValueType(0)); |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 4560 | std::pair<SDOperand,SDOperand> CallInfo = |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 4561 | TLI.LowerCallTo(InChain, RetTy, isSigned, false, CallingConv::C, false, |
Chris Lattner | adf6a96 | 2005-05-13 18:50:42 +0000 | [diff] [blame] | 4562 | Callee, Args, DAG); |
Chris Lattner | b9fa3bc | 2005-05-12 04:49:08 +0000 | [diff] [blame] | 4563 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 4564 | // Legalize the call sequence, starting with the chain. This will advance |
| 4565 | // the LastCALLSEQ_END to the legalized version of the CALLSEQ_END node that |
| 4566 | // was added by LowerCallTo (guaranteeing proper serialization of calls). |
| 4567 | LegalizeOp(CallInfo.second); |
Chris Lattner | 99c25b8 | 2005-09-02 20:26:58 +0000 | [diff] [blame] | 4568 | SDOperand Result; |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 4569 | switch (getTypeAction(CallInfo.first.getValueType())) { |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4570 | default: assert(0 && "Unknown thing"); |
| 4571 | case Legal: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4572 | Result = CallInfo.first; |
Chris Lattner | 99c25b8 | 2005-09-02 20:26:58 +0000 | [diff] [blame] | 4573 | break; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4574 | case Expand: |
Chris Lattner | 99c25b8 | 2005-09-02 20:26:58 +0000 | [diff] [blame] | 4575 | ExpandOp(CallInfo.first, Result, Hi); |
Chris Lattner | 99c25b8 | 2005-09-02 20:26:58 +0000 | [diff] [blame] | 4576 | break; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4577 | } |
Chris Lattner | 99c25b8 | 2005-09-02 20:26:58 +0000 | [diff] [blame] | 4578 | return Result; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4579 | } |
| 4580 | |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 4581 | |
Evan Cheng | 4c6cfad | 2007-04-27 07:33:31 +0000 | [diff] [blame] | 4582 | /// ExpandIntToFP - Expand a [US]INT_TO_FP operation. |
| 4583 | /// |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4584 | SDOperand SelectionDAGLegalize:: |
| 4585 | ExpandIntToFP(bool isSigned, MVT::ValueType DestTy, SDOperand Source) { |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4586 | assert(getTypeAction(Source.getValueType()) == Expand && |
| 4587 | "This is not an expansion!"); |
| 4588 | assert(Source.getValueType() == MVT::i64 && "Only handle expand from i64!"); |
| 4589 | |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 4590 | if (!isSigned) { |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 4591 | assert(Source.getValueType() == MVT::i64 && |
| 4592 | "This only works for 64-bit -> FP"); |
| 4593 | // The 64-bit value loaded will be incorrectly if the 'sign bit' of the |
| 4594 | // incoming integer is set. To handle this, we dynamically test to see if |
| 4595 | // it is set, and, if so, add a fudge factor. |
| 4596 | SDOperand Lo, Hi; |
| 4597 | ExpandOp(Source, Lo, Hi); |
| 4598 | |
Chris Lattner | 66de05b | 2005-05-13 04:45:13 +0000 | [diff] [blame] | 4599 | // If this is unsigned, and not supported, first perform the conversion to |
| 4600 | // signed, then adjust the result if the sign bit is set. |
| 4601 | SDOperand SignedConv = ExpandIntToFP(true, DestTy, |
| 4602 | DAG.getNode(ISD::BUILD_PAIR, Source.getValueType(), Lo, Hi)); |
| 4603 | |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 4604 | SDOperand SignSet = DAG.getSetCC(TLI.getSetCCResultTy(), Hi, |
| 4605 | DAG.getConstant(0, Hi.getValueType()), |
| 4606 | ISD::SETLT); |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 4607 | SDOperand Zero = getIntPtrConstant(0), Four = getIntPtrConstant(4); |
| 4608 | SDOperand CstOffset = DAG.getNode(ISD::SELECT, Zero.getValueType(), |
| 4609 | SignSet, Four, Zero); |
Chris Lattner | 383203b | 2005-05-12 18:52:34 +0000 | [diff] [blame] | 4610 | uint64_t FF = 0x5f800000ULL; |
| 4611 | if (TLI.isLittleEndian()) FF <<= 32; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 4612 | static Constant *FudgeFactor = ConstantInt::get(Type::Int64Ty, FF); |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 4613 | |
Chris Lattner | 5839bf2 | 2005-08-26 17:15:30 +0000 | [diff] [blame] | 4614 | SDOperand CPIdx = DAG.getConstantPool(FudgeFactor, TLI.getPointerTy()); |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 4615 | CPIdx = DAG.getNode(ISD::ADD, TLI.getPointerTy(), CPIdx, CstOffset); |
| 4616 | SDOperand FudgeInReg; |
| 4617 | if (DestTy == MVT::f32) |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 4618 | FudgeInReg = DAG.getLoad(MVT::f32, DAG.getEntryNode(), CPIdx, NULL, 0); |
Dale Johannesen | 118cd9d | 2007-09-16 16:51:49 +0000 | [diff] [blame] | 4619 | else if (MVT::getSizeInBits(DestTy) > MVT::getSizeInBits(MVT::f32)) |
Evan Cheng | 4c6cfad | 2007-04-27 07:33:31 +0000 | [diff] [blame] | 4620 | // FIXME: Avoid the extend by construction the right constantpool? |
Dale Johannesen | 118cd9d | 2007-09-16 16:51:49 +0000 | [diff] [blame] | 4621 | FudgeInReg = DAG.getExtLoad(ISD::EXTLOAD, DestTy, DAG.getEntryNode(), |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 4622 | CPIdx, NULL, 0, MVT::f32); |
| 4623 | else |
| 4624 | assert(0 && "Unexpected conversion"); |
| 4625 | |
Evan Cheng | 4c6cfad | 2007-04-27 07:33:31 +0000 | [diff] [blame] | 4626 | MVT::ValueType SCVT = SignedConv.getValueType(); |
| 4627 | if (SCVT != DestTy) { |
| 4628 | // Destination type needs to be expanded as well. The FADD now we are |
| 4629 | // constructing will be expanded into a libcall. |
| 4630 | if (MVT::getSizeInBits(SCVT) != MVT::getSizeInBits(DestTy)) { |
| 4631 | assert(SCVT == MVT::i32 && DestTy == MVT::f64); |
| 4632 | SignedConv = DAG.getNode(ISD::BUILD_PAIR, MVT::i64, |
| 4633 | SignedConv, SignedConv.getValue(1)); |
| 4634 | } |
| 4635 | SignedConv = DAG.getNode(ISD::BIT_CONVERT, DestTy, SignedConv); |
| 4636 | } |
Chris Lattner | 473a990 | 2005-09-29 06:44:39 +0000 | [diff] [blame] | 4637 | return DAG.getNode(ISD::FADD, DestTy, SignedConv, FudgeInReg); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4638 | } |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 4639 | |
Chris Lattner | a88a260 | 2005-05-14 05:33:54 +0000 | [diff] [blame] | 4640 | // Check to see if the target has a custom way to lower this. If so, use it. |
| 4641 | switch (TLI.getOperationAction(ISD::SINT_TO_FP, Source.getValueType())) { |
| 4642 | default: assert(0 && "This action not implemented for this operation!"); |
| 4643 | case TargetLowering::Legal: |
| 4644 | case TargetLowering::Expand: |
| 4645 | break; // This case is handled below. |
Chris Lattner | 07dffd6 | 2005-08-26 00:14:16 +0000 | [diff] [blame] | 4646 | case TargetLowering::Custom: { |
| 4647 | SDOperand NV = TLI.LowerOperation(DAG.getNode(ISD::SINT_TO_FP, DestTy, |
| 4648 | Source), DAG); |
| 4649 | if (NV.Val) |
| 4650 | return LegalizeOp(NV); |
| 4651 | break; // The target decided this was legal after all |
| 4652 | } |
Chris Lattner | a88a260 | 2005-05-14 05:33:54 +0000 | [diff] [blame] | 4653 | } |
| 4654 | |
Chris Lattner | 13689e2 | 2005-05-12 07:00:44 +0000 | [diff] [blame] | 4655 | // Expand the source, then glue it back together for the call. We must expand |
| 4656 | // the source in case it is shared (this pass of legalize must traverse it). |
| 4657 | SDOperand SrcLo, SrcHi; |
| 4658 | ExpandOp(Source, SrcLo, SrcHi); |
| 4659 | Source = DAG.getNode(ISD::BUILD_PAIR, Source.getValueType(), SrcLo, SrcHi); |
| 4660 | |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4661 | RTLIB::Libcall LC; |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 4662 | if (DestTy == MVT::f32) |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4663 | LC = RTLIB::SINTTOFP_I64_F32; |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 4664 | else { |
| 4665 | assert(DestTy == MVT::f64 && "Unknown fp value type!"); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4666 | LC = RTLIB::SINTTOFP_I64_F64; |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 4667 | } |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 4668 | |
Evan Cheng | 4c6cfad | 2007-04-27 07:33:31 +0000 | [diff] [blame] | 4669 | assert(TLI.getLibcallName(LC) && "Don't know how to expand this SINT_TO_FP!"); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 4670 | Source = DAG.getNode(ISD::SINT_TO_FP, DestTy, Source); |
| 4671 | SDOperand UnusedHiPart; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4672 | return ExpandLibCall(TLI.getLibcallName(LC), Source.Val, isSigned, |
| 4673 | UnusedHiPart); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4674 | } |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 4675 | |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 4676 | /// ExpandLegalINT_TO_FP - This function is responsible for legalizing a |
| 4677 | /// INT_TO_FP operation of the specified operand when the target requests that |
| 4678 | /// we expand it. At this point, we know that the result and operand types are |
| 4679 | /// legal for the target. |
| 4680 | SDOperand SelectionDAGLegalize::ExpandLegalINT_TO_FP(bool isSigned, |
| 4681 | SDOperand Op0, |
| 4682 | MVT::ValueType DestVT) { |
| 4683 | if (Op0.getValueType() == MVT::i32) { |
| 4684 | // simple 32-bit [signed|unsigned] integer to float/double expansion |
| 4685 | |
Chris Lattner | 58092e3 | 2007-01-20 22:35:55 +0000 | [diff] [blame] | 4686 | // get the stack frame index of a 8 byte buffer, pessimistically aligned |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 4687 | MachineFunction &MF = DAG.getMachineFunction(); |
Chris Lattner | 58092e3 | 2007-01-20 22:35:55 +0000 | [diff] [blame] | 4688 | const Type *F64Type = MVT::getTypeForValueType(MVT::f64); |
| 4689 | unsigned StackAlign = |
Chris Lattner | d2b7cec | 2007-02-14 05:52:17 +0000 | [diff] [blame] | 4690 | (unsigned)TLI.getTargetData()->getPrefTypeAlignment(F64Type); |
Chris Lattner | 58092e3 | 2007-01-20 22:35:55 +0000 | [diff] [blame] | 4691 | int SSFI = MF.getFrameInfo()->CreateStackObject(8, StackAlign); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 4692 | // get address of 8 byte buffer |
| 4693 | SDOperand StackSlot = DAG.getFrameIndex(SSFI, TLI.getPointerTy()); |
| 4694 | // word offset constant for Hi/Lo address computation |
| 4695 | SDOperand WordOff = DAG.getConstant(sizeof(int), TLI.getPointerTy()); |
| 4696 | // set up Hi and Lo (into buffer) address based on endian |
Chris Lattner | 408c428 | 2006-03-23 05:29:04 +0000 | [diff] [blame] | 4697 | SDOperand Hi = StackSlot; |
| 4698 | SDOperand Lo = DAG.getNode(ISD::ADD, TLI.getPointerTy(), StackSlot,WordOff); |
| 4699 | if (TLI.isLittleEndian()) |
| 4700 | std::swap(Hi, Lo); |
| 4701 | |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 4702 | // if signed map to unsigned space |
| 4703 | SDOperand Op0Mapped; |
| 4704 | if (isSigned) { |
| 4705 | // constant used to invert sign bit (signed to unsigned mapping) |
| 4706 | SDOperand SignBit = DAG.getConstant(0x80000000u, MVT::i32); |
| 4707 | Op0Mapped = DAG.getNode(ISD::XOR, MVT::i32, Op0, SignBit); |
| 4708 | } else { |
| 4709 | Op0Mapped = Op0; |
| 4710 | } |
| 4711 | // store the lo of the constructed double - based on integer input |
Evan Cheng | 786225a | 2006-10-05 23:01:46 +0000 | [diff] [blame] | 4712 | SDOperand Store1 = DAG.getStore(DAG.getEntryNode(), |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 4713 | Op0Mapped, Lo, NULL, 0); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 4714 | // initial hi portion of constructed double |
| 4715 | SDOperand InitialHi = DAG.getConstant(0x43300000u, MVT::i32); |
| 4716 | // store the hi of the constructed double - biased exponent |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 4717 | SDOperand Store2=DAG.getStore(Store1, InitialHi, Hi, NULL, 0); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 4718 | // load the constructed double |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 4719 | SDOperand Load = DAG.getLoad(MVT::f64, Store2, StackSlot, NULL, 0); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 4720 | // FP constant to bias correct the final result |
| 4721 | SDOperand Bias = DAG.getConstantFP(isSigned ? |
| 4722 | BitsToDouble(0x4330000080000000ULL) |
| 4723 | : BitsToDouble(0x4330000000000000ULL), |
| 4724 | MVT::f64); |
| 4725 | // subtract the bias |
| 4726 | SDOperand Sub = DAG.getNode(ISD::FSUB, MVT::f64, Load, Bias); |
| 4727 | // final result |
| 4728 | SDOperand Result; |
| 4729 | // handle final rounding |
| 4730 | if (DestVT == MVT::f64) { |
| 4731 | // do nothing |
| 4732 | Result = Sub; |
Dale Johannesen | 118cd9d | 2007-09-16 16:51:49 +0000 | [diff] [blame] | 4733 | } else if (MVT::getSizeInBits(DestVT) < MVT::getSizeInBits(MVT::f64)) { |
| 4734 | Result = DAG.getNode(ISD::FP_ROUND, DestVT, Sub); |
| 4735 | } else if (MVT::getSizeInBits(DestVT) > MVT::getSizeInBits(MVT::f64)) { |
| 4736 | Result = DAG.getNode(ISD::FP_EXTEND, DestVT, Sub); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 4737 | } |
| 4738 | return Result; |
| 4739 | } |
| 4740 | assert(!isSigned && "Legalize cannot Expand SINT_TO_FP for i64 yet"); |
| 4741 | SDOperand Tmp1 = DAG.getNode(ISD::SINT_TO_FP, DestVT, Op0); |
| 4742 | |
| 4743 | SDOperand SignSet = DAG.getSetCC(TLI.getSetCCResultTy(), Op0, |
| 4744 | DAG.getConstant(0, Op0.getValueType()), |
| 4745 | ISD::SETLT); |
| 4746 | SDOperand Zero = getIntPtrConstant(0), Four = getIntPtrConstant(4); |
| 4747 | SDOperand CstOffset = DAG.getNode(ISD::SELECT, Zero.getValueType(), |
| 4748 | SignSet, Four, Zero); |
| 4749 | |
| 4750 | // If the sign bit of the integer is set, the large number will be treated |
| 4751 | // as a negative number. To counteract this, the dynamic code adds an |
| 4752 | // offset depending on the data type. |
| 4753 | uint64_t FF; |
| 4754 | switch (Op0.getValueType()) { |
| 4755 | default: assert(0 && "Unsupported integer type!"); |
| 4756 | case MVT::i8 : FF = 0x43800000ULL; break; // 2^8 (as a float) |
| 4757 | case MVT::i16: FF = 0x47800000ULL; break; // 2^16 (as a float) |
| 4758 | case MVT::i32: FF = 0x4F800000ULL; break; // 2^32 (as a float) |
| 4759 | case MVT::i64: FF = 0x5F800000ULL; break; // 2^64 (as a float) |
| 4760 | } |
| 4761 | if (TLI.isLittleEndian()) FF <<= 32; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 4762 | static Constant *FudgeFactor = ConstantInt::get(Type::Int64Ty, FF); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 4763 | |
| 4764 | SDOperand CPIdx = DAG.getConstantPool(FudgeFactor, TLI.getPointerTy()); |
| 4765 | CPIdx = DAG.getNode(ISD::ADD, TLI.getPointerTy(), CPIdx, CstOffset); |
| 4766 | SDOperand FudgeInReg; |
| 4767 | if (DestVT == MVT::f32) |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 4768 | FudgeInReg = DAG.getLoad(MVT::f32, DAG.getEntryNode(), CPIdx, NULL, 0); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 4769 | else { |
| 4770 | assert(DestVT == MVT::f64 && "Unexpected conversion"); |
| 4771 | FudgeInReg = LegalizeOp(DAG.getExtLoad(ISD::EXTLOAD, MVT::f64, |
| 4772 | DAG.getEntryNode(), CPIdx, |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 4773 | NULL, 0, MVT::f32)); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 4774 | } |
| 4775 | |
| 4776 | return DAG.getNode(ISD::FADD, DestVT, Tmp1, FudgeInReg); |
| 4777 | } |
| 4778 | |
| 4779 | /// PromoteLegalINT_TO_FP - This function is responsible for legalizing a |
| 4780 | /// *INT_TO_FP operation of the specified operand when the target requests that |
| 4781 | /// we promote it. At this point, we know that the result and operand types are |
| 4782 | /// legal for the target, and that there is a legal UINT_TO_FP or SINT_TO_FP |
| 4783 | /// operation that takes a larger input. |
| 4784 | SDOperand SelectionDAGLegalize::PromoteLegalINT_TO_FP(SDOperand LegalOp, |
| 4785 | MVT::ValueType DestVT, |
| 4786 | bool isSigned) { |
| 4787 | // First step, figure out the appropriate *INT_TO_FP operation to use. |
| 4788 | MVT::ValueType NewInTy = LegalOp.getValueType(); |
| 4789 | |
| 4790 | unsigned OpToUse = 0; |
| 4791 | |
| 4792 | // Scan for the appropriate larger type to use. |
| 4793 | while (1) { |
| 4794 | NewInTy = (MVT::ValueType)(NewInTy+1); |
| 4795 | assert(MVT::isInteger(NewInTy) && "Ran out of possibilities!"); |
| 4796 | |
| 4797 | // If the target supports SINT_TO_FP of this type, use it. |
| 4798 | switch (TLI.getOperationAction(ISD::SINT_TO_FP, NewInTy)) { |
| 4799 | default: break; |
| 4800 | case TargetLowering::Legal: |
| 4801 | if (!TLI.isTypeLegal(NewInTy)) |
| 4802 | break; // Can't use this datatype. |
| 4803 | // FALL THROUGH. |
| 4804 | case TargetLowering::Custom: |
| 4805 | OpToUse = ISD::SINT_TO_FP; |
| 4806 | break; |
| 4807 | } |
| 4808 | if (OpToUse) break; |
| 4809 | if (isSigned) continue; |
| 4810 | |
| 4811 | // If the target supports UINT_TO_FP of this type, use it. |
| 4812 | switch (TLI.getOperationAction(ISD::UINT_TO_FP, NewInTy)) { |
| 4813 | default: break; |
| 4814 | case TargetLowering::Legal: |
| 4815 | if (!TLI.isTypeLegal(NewInTy)) |
| 4816 | break; // Can't use this datatype. |
| 4817 | // FALL THROUGH. |
| 4818 | case TargetLowering::Custom: |
| 4819 | OpToUse = ISD::UINT_TO_FP; |
| 4820 | break; |
| 4821 | } |
| 4822 | if (OpToUse) break; |
| 4823 | |
| 4824 | // Otherwise, try a larger type. |
| 4825 | } |
| 4826 | |
| 4827 | // Okay, we found the operation and type to use. Zero extend our input to the |
| 4828 | // desired type then run the operation on it. |
| 4829 | return DAG.getNode(OpToUse, DestVT, |
| 4830 | DAG.getNode(isSigned ? ISD::SIGN_EXTEND : ISD::ZERO_EXTEND, |
| 4831 | NewInTy, LegalOp)); |
| 4832 | } |
| 4833 | |
| 4834 | /// PromoteLegalFP_TO_INT - This function is responsible for legalizing a |
| 4835 | /// FP_TO_*INT operation of the specified operand when the target requests that |
| 4836 | /// we promote it. At this point, we know that the result and operand types are |
| 4837 | /// legal for the target, and that there is a legal FP_TO_UINT or FP_TO_SINT |
| 4838 | /// operation that returns a larger result. |
| 4839 | SDOperand SelectionDAGLegalize::PromoteLegalFP_TO_INT(SDOperand LegalOp, |
| 4840 | MVT::ValueType DestVT, |
| 4841 | bool isSigned) { |
| 4842 | // First step, figure out the appropriate FP_TO*INT operation to use. |
| 4843 | MVT::ValueType NewOutTy = DestVT; |
| 4844 | |
| 4845 | unsigned OpToUse = 0; |
| 4846 | |
| 4847 | // Scan for the appropriate larger type to use. |
| 4848 | while (1) { |
| 4849 | NewOutTy = (MVT::ValueType)(NewOutTy+1); |
| 4850 | assert(MVT::isInteger(NewOutTy) && "Ran out of possibilities!"); |
| 4851 | |
| 4852 | // If the target supports FP_TO_SINT returning this type, use it. |
| 4853 | switch (TLI.getOperationAction(ISD::FP_TO_SINT, NewOutTy)) { |
| 4854 | default: break; |
| 4855 | case TargetLowering::Legal: |
| 4856 | if (!TLI.isTypeLegal(NewOutTy)) |
| 4857 | break; // Can't use this datatype. |
| 4858 | // FALL THROUGH. |
| 4859 | case TargetLowering::Custom: |
| 4860 | OpToUse = ISD::FP_TO_SINT; |
| 4861 | break; |
| 4862 | } |
| 4863 | if (OpToUse) break; |
| 4864 | |
| 4865 | // If the target supports FP_TO_UINT of this type, use it. |
| 4866 | switch (TLI.getOperationAction(ISD::FP_TO_UINT, NewOutTy)) { |
| 4867 | default: break; |
| 4868 | case TargetLowering::Legal: |
| 4869 | if (!TLI.isTypeLegal(NewOutTy)) |
| 4870 | break; // Can't use this datatype. |
| 4871 | // FALL THROUGH. |
| 4872 | case TargetLowering::Custom: |
| 4873 | OpToUse = ISD::FP_TO_UINT; |
| 4874 | break; |
| 4875 | } |
| 4876 | if (OpToUse) break; |
| 4877 | |
| 4878 | // Otherwise, try a larger type. |
| 4879 | } |
| 4880 | |
| 4881 | // Okay, we found the operation and type to use. Truncate the result of the |
| 4882 | // extended FP_TO_*INT operation to the desired size. |
| 4883 | return DAG.getNode(ISD::TRUNCATE, DestVT, |
| 4884 | DAG.getNode(OpToUse, NewOutTy, LegalOp)); |
| 4885 | } |
| 4886 | |
| 4887 | /// ExpandBSWAP - Open code the operations for BSWAP of the specified operation. |
| 4888 | /// |
| 4889 | SDOperand SelectionDAGLegalize::ExpandBSWAP(SDOperand Op) { |
| 4890 | MVT::ValueType VT = Op.getValueType(); |
| 4891 | MVT::ValueType SHVT = TLI.getShiftAmountTy(); |
| 4892 | SDOperand Tmp1, Tmp2, Tmp3, Tmp4, Tmp5, Tmp6, Tmp7, Tmp8; |
| 4893 | switch (VT) { |
| 4894 | default: assert(0 && "Unhandled Expand type in BSWAP!"); abort(); |
| 4895 | case MVT::i16: |
| 4896 | Tmp2 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(8, SHVT)); |
| 4897 | Tmp1 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(8, SHVT)); |
| 4898 | return DAG.getNode(ISD::OR, VT, Tmp1, Tmp2); |
| 4899 | case MVT::i32: |
| 4900 | Tmp4 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(24, SHVT)); |
| 4901 | Tmp3 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(8, SHVT)); |
| 4902 | Tmp2 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(8, SHVT)); |
| 4903 | Tmp1 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(24, SHVT)); |
| 4904 | Tmp3 = DAG.getNode(ISD::AND, VT, Tmp3, DAG.getConstant(0xFF0000, VT)); |
| 4905 | Tmp2 = DAG.getNode(ISD::AND, VT, Tmp2, DAG.getConstant(0xFF00, VT)); |
| 4906 | Tmp4 = DAG.getNode(ISD::OR, VT, Tmp4, Tmp3); |
| 4907 | Tmp2 = DAG.getNode(ISD::OR, VT, Tmp2, Tmp1); |
| 4908 | return DAG.getNode(ISD::OR, VT, Tmp4, Tmp2); |
| 4909 | case MVT::i64: |
| 4910 | Tmp8 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(56, SHVT)); |
| 4911 | Tmp7 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(40, SHVT)); |
| 4912 | Tmp6 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(24, SHVT)); |
| 4913 | Tmp5 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(8, SHVT)); |
| 4914 | Tmp4 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(8, SHVT)); |
| 4915 | Tmp3 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(24, SHVT)); |
| 4916 | Tmp2 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(40, SHVT)); |
| 4917 | Tmp1 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(56, SHVT)); |
| 4918 | Tmp7 = DAG.getNode(ISD::AND, VT, Tmp7, DAG.getConstant(255ULL<<48, VT)); |
| 4919 | Tmp6 = DAG.getNode(ISD::AND, VT, Tmp6, DAG.getConstant(255ULL<<40, VT)); |
| 4920 | Tmp5 = DAG.getNode(ISD::AND, VT, Tmp5, DAG.getConstant(255ULL<<32, VT)); |
| 4921 | Tmp4 = DAG.getNode(ISD::AND, VT, Tmp4, DAG.getConstant(255ULL<<24, VT)); |
| 4922 | Tmp3 = DAG.getNode(ISD::AND, VT, Tmp3, DAG.getConstant(255ULL<<16, VT)); |
| 4923 | Tmp2 = DAG.getNode(ISD::AND, VT, Tmp2, DAG.getConstant(255ULL<<8 , VT)); |
| 4924 | Tmp8 = DAG.getNode(ISD::OR, VT, Tmp8, Tmp7); |
| 4925 | Tmp6 = DAG.getNode(ISD::OR, VT, Tmp6, Tmp5); |
| 4926 | Tmp4 = DAG.getNode(ISD::OR, VT, Tmp4, Tmp3); |
| 4927 | Tmp2 = DAG.getNode(ISD::OR, VT, Tmp2, Tmp1); |
| 4928 | Tmp8 = DAG.getNode(ISD::OR, VT, Tmp8, Tmp6); |
| 4929 | Tmp4 = DAG.getNode(ISD::OR, VT, Tmp4, Tmp2); |
| 4930 | return DAG.getNode(ISD::OR, VT, Tmp8, Tmp4); |
| 4931 | } |
| 4932 | } |
| 4933 | |
| 4934 | /// ExpandBitCount - Expand the specified bitcount instruction into operations. |
| 4935 | /// |
| 4936 | SDOperand SelectionDAGLegalize::ExpandBitCount(unsigned Opc, SDOperand Op) { |
| 4937 | switch (Opc) { |
| 4938 | default: assert(0 && "Cannot expand this yet!"); |
| 4939 | case ISD::CTPOP: { |
| 4940 | static const uint64_t mask[6] = { |
| 4941 | 0x5555555555555555ULL, 0x3333333333333333ULL, |
| 4942 | 0x0F0F0F0F0F0F0F0FULL, 0x00FF00FF00FF00FFULL, |
| 4943 | 0x0000FFFF0000FFFFULL, 0x00000000FFFFFFFFULL |
| 4944 | }; |
| 4945 | MVT::ValueType VT = Op.getValueType(); |
| 4946 | MVT::ValueType ShVT = TLI.getShiftAmountTy(); |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 4947 | unsigned len = MVT::getSizeInBits(VT); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 4948 | for (unsigned i = 0; (1U << i) <= (len / 2); ++i) { |
| 4949 | //x = (x & mask[i][len/8]) + (x >> (1 << i) & mask[i][len/8]) |
| 4950 | SDOperand Tmp2 = DAG.getConstant(mask[i], VT); |
| 4951 | SDOperand Tmp3 = DAG.getConstant(1ULL << i, ShVT); |
| 4952 | Op = DAG.getNode(ISD::ADD, VT, DAG.getNode(ISD::AND, VT, Op, Tmp2), |
| 4953 | DAG.getNode(ISD::AND, VT, |
| 4954 | DAG.getNode(ISD::SRL, VT, Op, Tmp3),Tmp2)); |
| 4955 | } |
| 4956 | return Op; |
| 4957 | } |
| 4958 | case ISD::CTLZ: { |
| 4959 | // for now, we do this: |
| 4960 | // x = x | (x >> 1); |
| 4961 | // x = x | (x >> 2); |
| 4962 | // ... |
| 4963 | // x = x | (x >>16); |
| 4964 | // x = x | (x >>32); // for 64-bit input |
| 4965 | // return popcount(~x); |
| 4966 | // |
| 4967 | // but see also: http://www.hackersdelight.org/HDcode/nlz.cc |
| 4968 | MVT::ValueType VT = Op.getValueType(); |
| 4969 | MVT::ValueType ShVT = TLI.getShiftAmountTy(); |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 4970 | unsigned len = MVT::getSizeInBits(VT); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 4971 | for (unsigned i = 0; (1U << i) <= (len / 2); ++i) { |
| 4972 | SDOperand Tmp3 = DAG.getConstant(1ULL << i, ShVT); |
| 4973 | Op = DAG.getNode(ISD::OR, VT, Op, DAG.getNode(ISD::SRL, VT, Op, Tmp3)); |
| 4974 | } |
| 4975 | Op = DAG.getNode(ISD::XOR, VT, Op, DAG.getConstant(~0ULL, VT)); |
| 4976 | return DAG.getNode(ISD::CTPOP, VT, Op); |
| 4977 | } |
| 4978 | case ISD::CTTZ: { |
| 4979 | // for now, we use: { return popcount(~x & (x - 1)); } |
| 4980 | // unless the target has ctlz but not ctpop, in which case we use: |
| 4981 | // { return 32 - nlz(~x & (x-1)); } |
| 4982 | // see also http://www.hackersdelight.org/HDcode/ntz.cc |
| 4983 | MVT::ValueType VT = Op.getValueType(); |
| 4984 | SDOperand Tmp2 = DAG.getConstant(~0ULL, VT); |
| 4985 | SDOperand Tmp3 = DAG.getNode(ISD::AND, VT, |
| 4986 | DAG.getNode(ISD::XOR, VT, Op, Tmp2), |
| 4987 | DAG.getNode(ISD::SUB, VT, Op, DAG.getConstant(1, VT))); |
| 4988 | // If ISD::CTLZ is legal and CTPOP isn't, then do that instead. |
| 4989 | if (!TLI.isOperationLegal(ISD::CTPOP, VT) && |
| 4990 | TLI.isOperationLegal(ISD::CTLZ, VT)) |
| 4991 | return DAG.getNode(ISD::SUB, VT, |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 4992 | DAG.getConstant(MVT::getSizeInBits(VT), VT), |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 4993 | DAG.getNode(ISD::CTLZ, VT, Tmp3)); |
| 4994 | return DAG.getNode(ISD::CTPOP, VT, Tmp3); |
| 4995 | } |
| 4996 | } |
| 4997 | } |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 4998 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 4999 | /// ExpandOp - Expand the specified SDOperand into its two component pieces |
| 5000 | /// Lo&Hi. Note that the Op MUST be an expanded type. As a result of this, the |
| 5001 | /// LegalizeNodes map is filled in for any results that are not expanded, the |
| 5002 | /// ExpandedNodes map is filled in for any results that are expanded, and the |
| 5003 | /// Lo/Hi values are returned. |
| 5004 | void SelectionDAGLegalize::ExpandOp(SDOperand Op, SDOperand &Lo, SDOperand &Hi){ |
| 5005 | MVT::ValueType VT = Op.getValueType(); |
Chris Lattner | 71c42a0 | 2005-01-16 01:11:45 +0000 | [diff] [blame] | 5006 | MVT::ValueType NVT = TLI.getTypeToTransformTo(VT); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5007 | SDNode *Node = Op.Val; |
| 5008 | assert(getTypeAction(VT) == Expand && "Not an expanded type!"); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 5009 | assert(((MVT::isInteger(NVT) && NVT < VT) || MVT::isFloatingPoint(VT) || |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5010 | MVT::isVector(VT)) && |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5011 | "Cannot expand to FP value or to larger int value!"); |
| 5012 | |
Chris Lattner | 6fdcb25 | 2005-09-02 20:32:45 +0000 | [diff] [blame] | 5013 | // See if we already expanded it. |
Chris Lattner | 40030bf | 2007-02-04 01:17:38 +0000 | [diff] [blame] | 5014 | DenseMap<SDOperand, std::pair<SDOperand, SDOperand> >::iterator I |
Chris Lattner | 6fdcb25 | 2005-09-02 20:32:45 +0000 | [diff] [blame] | 5015 | = ExpandedNodes.find(Op); |
| 5016 | if (I != ExpandedNodes.end()) { |
| 5017 | Lo = I->second.first; |
| 5018 | Hi = I->second.second; |
| 5019 | return; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5020 | } |
| 5021 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5022 | switch (Node->getOpcode()) { |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 5023 | case ISD::CopyFromReg: |
| 5024 | assert(0 && "CopyFromReg must be legal!"); |
| 5025 | default: |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 5026 | #ifndef NDEBUG |
Dan Gohman | 3983358 | 2007-06-04 16:17:33 +0000 | [diff] [blame] | 5027 | cerr << "NODE: "; Node->dump(&DAG); cerr << "\n"; |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 5028 | #endif |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5029 | assert(0 && "Do not know how to expand this operator!"); |
| 5030 | abort(); |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 5031 | case ISD::UNDEF: |
Evan Cheng | aa975c1 | 2006-12-16 02:20:50 +0000 | [diff] [blame] | 5032 | NVT = TLI.getTypeToExpandTo(VT); |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 5033 | Lo = DAG.getNode(ISD::UNDEF, NVT); |
| 5034 | Hi = DAG.getNode(ISD::UNDEF, NVT); |
| 5035 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5036 | case ISD::Constant: { |
| 5037 | uint64_t Cst = cast<ConstantSDNode>(Node)->getValue(); |
| 5038 | Lo = DAG.getConstant(Cst, NVT); |
| 5039 | Hi = DAG.getConstant(Cst >> MVT::getSizeInBits(NVT), NVT); |
| 5040 | break; |
| 5041 | } |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 5042 | case ISD::ConstantFP: { |
| 5043 | ConstantFPSDNode *CFP = cast<ConstantFPSDNode>(Node); |
Evan Cheng | 279101e | 2006-12-12 22:19:28 +0000 | [diff] [blame] | 5044 | Lo = ExpandConstantFP(CFP, false, DAG, TLI); |
Evan Cheng | 9f87788 | 2006-12-13 20:57:08 +0000 | [diff] [blame] | 5045 | if (getTypeAction(Lo.getValueType()) == Expand) |
| 5046 | ExpandOp(Lo, Lo, Hi); |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 5047 | break; |
| 5048 | } |
Chris Lattner | d4e50bb | 2005-03-28 22:03:13 +0000 | [diff] [blame] | 5049 | case ISD::BUILD_PAIR: |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5050 | // Return the operands. |
| 5051 | Lo = Node->getOperand(0); |
| 5052 | Hi = Node->getOperand(1); |
Chris Lattner | d4e50bb | 2005-03-28 22:03:13 +0000 | [diff] [blame] | 5053 | break; |
Chris Lattner | 58f7963 | 2005-12-12 22:27:43 +0000 | [diff] [blame] | 5054 | |
| 5055 | case ISD::SIGN_EXTEND_INREG: |
| 5056 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Chris Lattner | 4bdd275 | 2006-10-06 17:34:12 +0000 | [diff] [blame] | 5057 | // sext_inreg the low part if needed. |
| 5058 | Lo = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Lo, Node->getOperand(1)); |
| 5059 | |
| 5060 | // The high part gets the sign extension from the lo-part. This handles |
| 5061 | // things like sextinreg V:i64 from i8. |
Chris Lattner | 58f7963 | 2005-12-12 22:27:43 +0000 | [diff] [blame] | 5062 | Hi = DAG.getNode(ISD::SRA, NVT, Lo, |
| 5063 | DAG.getConstant(MVT::getSizeInBits(NVT)-1, |
| 5064 | TLI.getShiftAmountTy())); |
Chris Lattner | 58f7963 | 2005-12-12 22:27:43 +0000 | [diff] [blame] | 5065 | break; |
Chris Lattner | d4e50bb | 2005-03-28 22:03:13 +0000 | [diff] [blame] | 5066 | |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 5067 | case ISD::BSWAP: { |
| 5068 | ExpandOp(Node->getOperand(0), Lo, Hi); |
| 5069 | SDOperand TempLo = DAG.getNode(ISD::BSWAP, NVT, Hi); |
| 5070 | Hi = DAG.getNode(ISD::BSWAP, NVT, Lo); |
| 5071 | Lo = TempLo; |
| 5072 | break; |
| 5073 | } |
| 5074 | |
Chris Lattner | edb1add | 2005-05-11 04:51:16 +0000 | [diff] [blame] | 5075 | case ISD::CTPOP: |
| 5076 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Chris Lattner | 9b583b4 | 2005-05-11 05:09:47 +0000 | [diff] [blame] | 5077 | Lo = DAG.getNode(ISD::ADD, NVT, // ctpop(HL) -> ctpop(H)+ctpop(L) |
| 5078 | DAG.getNode(ISD::CTPOP, NVT, Lo), |
| 5079 | DAG.getNode(ISD::CTPOP, NVT, Hi)); |
Chris Lattner | edb1add | 2005-05-11 04:51:16 +0000 | [diff] [blame] | 5080 | Hi = DAG.getConstant(0, NVT); |
| 5081 | break; |
| 5082 | |
Chris Lattner | 39a8f33 | 2005-05-12 19:05:01 +0000 | [diff] [blame] | 5083 | case ISD::CTLZ: { |
| 5084 | // ctlz (HL) -> ctlz(H) != 32 ? ctlz(H) : (ctlz(L)+32) |
Chris Lattner | 3becf20 | 2005-05-12 19:27:51 +0000 | [diff] [blame] | 5085 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Chris Lattner | 39a8f33 | 2005-05-12 19:05:01 +0000 | [diff] [blame] | 5086 | SDOperand BitsC = DAG.getConstant(MVT::getSizeInBits(NVT), NVT); |
| 5087 | SDOperand HLZ = DAG.getNode(ISD::CTLZ, NVT, Hi); |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 5088 | SDOperand TopNotZero = DAG.getSetCC(TLI.getSetCCResultTy(), HLZ, BitsC, |
| 5089 | ISD::SETNE); |
Chris Lattner | 39a8f33 | 2005-05-12 19:05:01 +0000 | [diff] [blame] | 5090 | SDOperand LowPart = DAG.getNode(ISD::CTLZ, NVT, Lo); |
| 5091 | LowPart = DAG.getNode(ISD::ADD, NVT, LowPart, BitsC); |
| 5092 | |
| 5093 | Lo = DAG.getNode(ISD::SELECT, NVT, TopNotZero, HLZ, LowPart); |
| 5094 | Hi = DAG.getConstant(0, NVT); |
| 5095 | break; |
| 5096 | } |
| 5097 | |
| 5098 | case ISD::CTTZ: { |
| 5099 | // cttz (HL) -> cttz(L) != 32 ? cttz(L) : (cttz(H)+32) |
Chris Lattner | 3becf20 | 2005-05-12 19:27:51 +0000 | [diff] [blame] | 5100 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Chris Lattner | 39a8f33 | 2005-05-12 19:05:01 +0000 | [diff] [blame] | 5101 | SDOperand BitsC = DAG.getConstant(MVT::getSizeInBits(NVT), NVT); |
| 5102 | SDOperand LTZ = DAG.getNode(ISD::CTTZ, NVT, Lo); |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 5103 | SDOperand BotNotZero = DAG.getSetCC(TLI.getSetCCResultTy(), LTZ, BitsC, |
| 5104 | ISD::SETNE); |
Chris Lattner | 39a8f33 | 2005-05-12 19:05:01 +0000 | [diff] [blame] | 5105 | SDOperand HiPart = DAG.getNode(ISD::CTTZ, NVT, Hi); |
| 5106 | HiPart = DAG.getNode(ISD::ADD, NVT, HiPart, BitsC); |
| 5107 | |
| 5108 | Lo = DAG.getNode(ISD::SELECT, NVT, BotNotZero, LTZ, HiPart); |
| 5109 | Hi = DAG.getConstant(0, NVT); |
| 5110 | break; |
| 5111 | } |
Chris Lattner | edb1add | 2005-05-11 04:51:16 +0000 | [diff] [blame] | 5112 | |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 5113 | case ISD::VAARG: { |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5114 | SDOperand Ch = Node->getOperand(0); // Legalize the chain. |
| 5115 | SDOperand Ptr = Node->getOperand(1); // Legalize the pointer. |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 5116 | Lo = DAG.getVAArg(NVT, Ch, Ptr, Node->getOperand(2)); |
| 5117 | Hi = DAG.getVAArg(NVT, Lo.getValue(1), Ptr, Node->getOperand(2)); |
| 5118 | |
| 5119 | // Remember that we legalized the chain. |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5120 | Hi = LegalizeOp(Hi); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 5121 | AddLegalizedOperand(Op.getValue(1), Hi.getValue(1)); |
| 5122 | if (!TLI.isLittleEndian()) |
| 5123 | std::swap(Lo, Hi); |
| 5124 | break; |
| 5125 | } |
| 5126 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5127 | case ISD::LOAD: { |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 5128 | LoadSDNode *LD = cast<LoadSDNode>(Node); |
| 5129 | SDOperand Ch = LD->getChain(); // Legalize the chain. |
| 5130 | SDOperand Ptr = LD->getBasePtr(); // Legalize the pointer. |
| 5131 | ISD::LoadExtType ExtType = LD->getExtensionType(); |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 5132 | int SVOffset = LD->getSrcValueOffset(); |
| 5133 | unsigned Alignment = LD->getAlignment(); |
| 5134 | bool isVolatile = LD->isVolatile(); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5135 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 5136 | if (ExtType == ISD::NON_EXTLOAD) { |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 5137 | Lo = DAG.getLoad(NVT, Ch, Ptr, LD->getSrcValue(), SVOffset, |
| 5138 | isVolatile, Alignment); |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 5139 | if (VT == MVT::f32 || VT == MVT::f64) { |
| 5140 | // f32->i32 or f64->i64 one to one expansion. |
| 5141 | // Remember that we legalized the chain. |
| 5142 | AddLegalizedOperand(SDOperand(Node, 1), LegalizeOp(Lo.getValue(1))); |
Evan Cheng | 9f87788 | 2006-12-13 20:57:08 +0000 | [diff] [blame] | 5143 | // Recursively expand the new load. |
| 5144 | if (getTypeAction(NVT) == Expand) |
| 5145 | ExpandOp(Lo, Lo, Hi); |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 5146 | break; |
| 5147 | } |
Chris Lattner | ec39a45 | 2005-01-19 18:02:17 +0000 | [diff] [blame] | 5148 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 5149 | // Increment the pointer to the other half. |
| 5150 | unsigned IncrementSize = MVT::getSizeInBits(Lo.getValueType())/8; |
| 5151 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
| 5152 | getIntPtrConstant(IncrementSize)); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5153 | SVOffset += IncrementSize; |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 5154 | if (Alignment > IncrementSize) |
| 5155 | Alignment = IncrementSize; |
| 5156 | Hi = DAG.getLoad(NVT, Ch, Ptr, LD->getSrcValue(), SVOffset, |
| 5157 | isVolatile, Alignment); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 5158 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 5159 | // Build a factor node to remember that this load is independent of the |
| 5160 | // other one. |
| 5161 | SDOperand TF = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1), |
| 5162 | Hi.getValue(1)); |
| 5163 | |
| 5164 | // Remember that we legalized the chain. |
| 5165 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(TF)); |
| 5166 | if (!TLI.isLittleEndian()) |
| 5167 | std::swap(Lo, Hi); |
| 5168 | } else { |
Evan Cheng | 2e49f09 | 2006-10-11 07:10:22 +0000 | [diff] [blame] | 5169 | MVT::ValueType EVT = LD->getLoadedVT(); |
Evan Cheng | 548f611 | 2006-12-13 03:19:57 +0000 | [diff] [blame] | 5170 | |
| 5171 | if (VT == MVT::f64 && EVT == MVT::f32) { |
| 5172 | // f64 = EXTLOAD f32 should expand to LOAD, FP_EXTEND |
| 5173 | SDOperand Load = DAG.getLoad(EVT, Ch, Ptr, LD->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 5174 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 548f611 | 2006-12-13 03:19:57 +0000 | [diff] [blame] | 5175 | // Remember that we legalized the chain. |
| 5176 | AddLegalizedOperand(SDOperand(Node, 1), LegalizeOp(Load.getValue(1))); |
| 5177 | ExpandOp(DAG.getNode(ISD::FP_EXTEND, VT, Load), Lo, Hi); |
| 5178 | break; |
| 5179 | } |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 5180 | |
| 5181 | if (EVT == NVT) |
| 5182 | Lo = DAG.getLoad(NVT, Ch, Ptr, LD->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 5183 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 5184 | else |
| 5185 | Lo = DAG.getExtLoad(ExtType, NVT, Ch, Ptr, LD->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 5186 | SVOffset, EVT, isVolatile, |
| 5187 | Alignment); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 5188 | |
| 5189 | // Remember that we legalized the chain. |
| 5190 | AddLegalizedOperand(SDOperand(Node, 1), LegalizeOp(Lo.getValue(1))); |
| 5191 | |
| 5192 | if (ExtType == ISD::SEXTLOAD) { |
| 5193 | // The high part is obtained by SRA'ing all but one of the bits of the |
| 5194 | // lo part. |
| 5195 | unsigned LoSize = MVT::getSizeInBits(Lo.getValueType()); |
| 5196 | Hi = DAG.getNode(ISD::SRA, NVT, Lo, |
| 5197 | DAG.getConstant(LoSize-1, TLI.getShiftAmountTy())); |
| 5198 | } else if (ExtType == ISD::ZEXTLOAD) { |
| 5199 | // The high part is just a zero. |
| 5200 | Hi = DAG.getConstant(0, NVT); |
| 5201 | } else /* if (ExtType == ISD::EXTLOAD) */ { |
| 5202 | // The high part is undefined. |
| 5203 | Hi = DAG.getNode(ISD::UNDEF, NVT); |
| 5204 | } |
| 5205 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5206 | break; |
| 5207 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5208 | case ISD::AND: |
| 5209 | case ISD::OR: |
| 5210 | case ISD::XOR: { // Simple logical operators -> two trivial pieces. |
| 5211 | SDOperand LL, LH, RL, RH; |
| 5212 | ExpandOp(Node->getOperand(0), LL, LH); |
| 5213 | ExpandOp(Node->getOperand(1), RL, RH); |
| 5214 | Lo = DAG.getNode(Node->getOpcode(), NVT, LL, RL); |
| 5215 | Hi = DAG.getNode(Node->getOpcode(), NVT, LH, RH); |
| 5216 | break; |
| 5217 | } |
| 5218 | case ISD::SELECT: { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 5219 | SDOperand LL, LH, RL, RH; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5220 | ExpandOp(Node->getOperand(1), LL, LH); |
| 5221 | ExpandOp(Node->getOperand(2), RL, RH); |
Evan Cheng | 19103b1 | 2006-12-15 22:42:55 +0000 | [diff] [blame] | 5222 | if (getTypeAction(NVT) == Expand) |
| 5223 | NVT = TLI.getTypeToExpandTo(NVT); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 5224 | Lo = DAG.getNode(ISD::SELECT, NVT, Node->getOperand(0), LL, RL); |
Evan Cheng | 19103b1 | 2006-12-15 22:42:55 +0000 | [diff] [blame] | 5225 | if (VT != MVT::f32) |
| 5226 | Hi = DAG.getNode(ISD::SELECT, NVT, Node->getOperand(0), LH, RH); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5227 | break; |
| 5228 | } |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 5229 | case ISD::SELECT_CC: { |
| 5230 | SDOperand TL, TH, FL, FH; |
| 5231 | ExpandOp(Node->getOperand(2), TL, TH); |
| 5232 | ExpandOp(Node->getOperand(3), FL, FH); |
Evan Cheng | 19103b1 | 2006-12-15 22:42:55 +0000 | [diff] [blame] | 5233 | if (getTypeAction(NVT) == Expand) |
| 5234 | NVT = TLI.getTypeToExpandTo(NVT); |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 5235 | Lo = DAG.getNode(ISD::SELECT_CC, NVT, Node->getOperand(0), |
| 5236 | Node->getOperand(1), TL, FL, Node->getOperand(4)); |
Evan Cheng | 19103b1 | 2006-12-15 22:42:55 +0000 | [diff] [blame] | 5237 | if (VT != MVT::f32) |
| 5238 | Hi = DAG.getNode(ISD::SELECT_CC, NVT, Node->getOperand(0), |
| 5239 | Node->getOperand(1), TH, FH, Node->getOperand(4)); |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 5240 | break; |
| 5241 | } |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5242 | case ISD::ANY_EXTEND: |
| 5243 | // The low part is any extension of the input (which degenerates to a copy). |
| 5244 | Lo = DAG.getNode(ISD::ANY_EXTEND, NVT, Node->getOperand(0)); |
| 5245 | // The high part is undefined. |
| 5246 | Hi = DAG.getNode(ISD::UNDEF, NVT); |
| 5247 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5248 | case ISD::SIGN_EXTEND: { |
| 5249 | // The low part is just a sign extension of the input (which degenerates to |
| 5250 | // a copy). |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5251 | Lo = DAG.getNode(ISD::SIGN_EXTEND, NVT, Node->getOperand(0)); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 5252 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5253 | // The high part is obtained by SRA'ing all but one of the bits of the lo |
| 5254 | // part. |
Chris Lattner | 2dad454 | 2005-01-12 18:19:52 +0000 | [diff] [blame] | 5255 | unsigned LoSize = MVT::getSizeInBits(Lo.getValueType()); |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5256 | Hi = DAG.getNode(ISD::SRA, NVT, Lo, |
| 5257 | DAG.getConstant(LoSize-1, TLI.getShiftAmountTy())); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5258 | break; |
| 5259 | } |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5260 | case ISD::ZERO_EXTEND: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5261 | // The low part is just a zero extension of the input (which degenerates to |
| 5262 | // a copy). |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5263 | Lo = DAG.getNode(ISD::ZERO_EXTEND, NVT, Node->getOperand(0)); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 5264 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5265 | // The high part is just a zero. |
| 5266 | Hi = DAG.getConstant(0, NVT); |
| 5267 | break; |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 5268 | |
Chris Lattner | 4c948eb | 2007-02-13 23:55:16 +0000 | [diff] [blame] | 5269 | case ISD::TRUNCATE: { |
| 5270 | // The input value must be larger than this value. Expand *it*. |
| 5271 | SDOperand NewLo; |
| 5272 | ExpandOp(Node->getOperand(0), NewLo, Hi); |
| 5273 | |
| 5274 | // The low part is now either the right size, or it is closer. If not the |
| 5275 | // right size, make an illegal truncate so we recursively expand it. |
| 5276 | if (NewLo.getValueType() != Node->getValueType(0)) |
| 5277 | NewLo = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0), NewLo); |
| 5278 | ExpandOp(NewLo, Lo, Hi); |
| 5279 | break; |
| 5280 | } |
| 5281 | |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 5282 | case ISD::BIT_CONVERT: { |
Chris Lattner | f3f333d | 2006-09-09 00:20:27 +0000 | [diff] [blame] | 5283 | SDOperand Tmp; |
| 5284 | if (TLI.getOperationAction(ISD::BIT_CONVERT, VT) == TargetLowering::Custom){ |
| 5285 | // If the target wants to, allow it to lower this itself. |
| 5286 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 5287 | case Expand: assert(0 && "cannot expand FP!"); |
| 5288 | case Legal: Tmp = LegalizeOp(Node->getOperand(0)); break; |
| 5289 | case Promote: Tmp = PromoteOp (Node->getOperand(0)); break; |
| 5290 | } |
| 5291 | Tmp = TLI.LowerOperation(DAG.getNode(ISD::BIT_CONVERT, VT, Tmp), DAG); |
| 5292 | } |
| 5293 | |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 5294 | // f32 / f64 must be expanded to i32 / i64. |
Evan Cheng | 13acce3 | 2006-12-11 19:27:14 +0000 | [diff] [blame] | 5295 | if (VT == MVT::f32 || VT == MVT::f64) { |
| 5296 | Lo = DAG.getNode(ISD::BIT_CONVERT, NVT, Node->getOperand(0)); |
Evan Cheng | 19103b1 | 2006-12-15 22:42:55 +0000 | [diff] [blame] | 5297 | if (getTypeAction(NVT) == Expand) |
| 5298 | ExpandOp(Lo, Lo, Hi); |
Evan Cheng | 7b2b5c8 | 2006-12-12 19:53:13 +0000 | [diff] [blame] | 5299 | break; |
| 5300 | } |
| 5301 | |
| 5302 | // If source operand will be expanded to the same type as VT, i.e. |
| 5303 | // i64 <- f64, i32 <- f32, expand the source operand instead. |
| 5304 | MVT::ValueType VT0 = Node->getOperand(0).getValueType(); |
| 5305 | if (getTypeAction(VT0) == Expand && TLI.getTypeToTransformTo(VT0) == VT) { |
| 5306 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 5307 | break; |
| 5308 | } |
| 5309 | |
Chris Lattner | f3f333d | 2006-09-09 00:20:27 +0000 | [diff] [blame] | 5310 | // Turn this into a load/store pair by default. |
| 5311 | if (Tmp.Val == 0) |
Evan Cheng | 13acce3 | 2006-12-11 19:27:14 +0000 | [diff] [blame] | 5312 | Tmp = ExpandBIT_CONVERT(VT, Node->getOperand(0)); |
Chris Lattner | f3f333d | 2006-09-09 00:20:27 +0000 | [diff] [blame] | 5313 | |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 5314 | ExpandOp(Tmp, Lo, Hi); |
| 5315 | break; |
| 5316 | } |
Andrew Lenharth | f70e30b | 2005-11-20 21:32:07 +0000 | [diff] [blame] | 5317 | |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5318 | case ISD::READCYCLECOUNTER: |
Chris Lattner | 308575b | 2005-11-20 22:56:56 +0000 | [diff] [blame] | 5319 | assert(TLI.getOperationAction(ISD::READCYCLECOUNTER, VT) == |
| 5320 | TargetLowering::Custom && |
| 5321 | "Must custom expand ReadCycleCounter"); |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5322 | Lo = TLI.LowerOperation(Op, DAG); |
| 5323 | assert(Lo.Val && "Node must be custom expanded!"); |
| 5324 | Hi = Lo.getValue(1); |
Chris Lattner | 308575b | 2005-11-20 22:56:56 +0000 | [diff] [blame] | 5325 | AddLegalizedOperand(SDOperand(Node, 1), // Remember we legalized the chain. |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5326 | LegalizeOp(Lo.getValue(2))); |
Andrew Lenharth | f70e30b | 2005-11-20 21:32:07 +0000 | [diff] [blame] | 5327 | break; |
| 5328 | |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 5329 | // These operators cannot be expanded directly, emit them as calls to |
| 5330 | // library functions. |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5331 | case ISD::FP_TO_SINT: { |
Chris Lattner | 80a3e94 | 2005-07-29 00:33:32 +0000 | [diff] [blame] | 5332 | if (TLI.getOperationAction(ISD::FP_TO_SINT, VT) == TargetLowering::Custom) { |
Chris Lattner | f20d183 | 2005-07-30 01:40:57 +0000 | [diff] [blame] | 5333 | SDOperand Op; |
| 5334 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 5335 | case Expand: assert(0 && "cannot expand FP!"); |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5336 | case Legal: Op = LegalizeOp(Node->getOperand(0)); break; |
| 5337 | case Promote: Op = PromoteOp (Node->getOperand(0)); break; |
Chris Lattner | f20d183 | 2005-07-30 01:40:57 +0000 | [diff] [blame] | 5338 | } |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 5339 | |
Chris Lattner | f20d183 | 2005-07-30 01:40:57 +0000 | [diff] [blame] | 5340 | Op = TLI.LowerOperation(DAG.getNode(ISD::FP_TO_SINT, VT, Op), DAG); |
| 5341 | |
Chris Lattner | 80a3e94 | 2005-07-29 00:33:32 +0000 | [diff] [blame] | 5342 | // Now that the custom expander is done, expand the result, which is still |
| 5343 | // VT. |
Chris Lattner | 07dffd6 | 2005-08-26 00:14:16 +0000 | [diff] [blame] | 5344 | if (Op.Val) { |
| 5345 | ExpandOp(Op, Lo, Hi); |
| 5346 | break; |
| 5347 | } |
Chris Lattner | 80a3e94 | 2005-07-29 00:33:32 +0000 | [diff] [blame] | 5348 | } |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 5349 | |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5350 | RTLIB::Libcall LC; |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 5351 | if (Node->getOperand(0).getValueType() == MVT::f32) |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5352 | LC = RTLIB::FPTOSINT_F32_I64; |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 5353 | else |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5354 | LC = RTLIB::FPTOSINT_F64_I64; |
| 5355 | Lo = ExpandLibCall(TLI.getLibcallName(LC), Node, |
| 5356 | false/*sign irrelevant*/, Hi); |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 5357 | break; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5358 | } |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 5359 | |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5360 | case ISD::FP_TO_UINT: { |
Chris Lattner | 80a3e94 | 2005-07-29 00:33:32 +0000 | [diff] [blame] | 5361 | if (TLI.getOperationAction(ISD::FP_TO_UINT, VT) == TargetLowering::Custom) { |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5362 | SDOperand Op; |
| 5363 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 5364 | case Expand: assert(0 && "cannot expand FP!"); |
| 5365 | case Legal: Op = LegalizeOp(Node->getOperand(0)); break; |
| 5366 | case Promote: Op = PromoteOp (Node->getOperand(0)); break; |
| 5367 | } |
| 5368 | |
| 5369 | Op = TLI.LowerOperation(DAG.getNode(ISD::FP_TO_UINT, VT, Op), DAG); |
| 5370 | |
| 5371 | // Now that the custom expander is done, expand the result. |
Chris Lattner | 07dffd6 | 2005-08-26 00:14:16 +0000 | [diff] [blame] | 5372 | if (Op.Val) { |
| 5373 | ExpandOp(Op, Lo, Hi); |
| 5374 | break; |
| 5375 | } |
Chris Lattner | 80a3e94 | 2005-07-29 00:33:32 +0000 | [diff] [blame] | 5376 | } |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 5377 | |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5378 | RTLIB::Libcall LC; |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 5379 | if (Node->getOperand(0).getValueType() == MVT::f32) |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5380 | LC = RTLIB::FPTOUINT_F32_I64; |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 5381 | else |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5382 | LC = RTLIB::FPTOUINT_F64_I64; |
| 5383 | Lo = ExpandLibCall(TLI.getLibcallName(LC), Node, |
| 5384 | false/*sign irrelevant*/, Hi); |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 5385 | break; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5386 | } |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 5387 | |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 5388 | case ISD::SHL: { |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 5389 | // If the target wants custom lowering, do so. |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 5390 | SDOperand ShiftAmt = LegalizeOp(Node->getOperand(1)); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 5391 | if (TLI.getOperationAction(ISD::SHL, VT) == TargetLowering::Custom) { |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5392 | SDOperand Op = DAG.getNode(ISD::SHL, VT, Node->getOperand(0), ShiftAmt); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 5393 | Op = TLI.LowerOperation(Op, DAG); |
| 5394 | if (Op.Val) { |
| 5395 | // Now that the custom expander is done, expand the result, which is |
| 5396 | // still VT. |
| 5397 | ExpandOp(Op, Lo, Hi); |
| 5398 | break; |
| 5399 | } |
| 5400 | } |
| 5401 | |
Chris Lattner | 79980b0 | 2006-09-13 03:50:39 +0000 | [diff] [blame] | 5402 | // If ADDC/ADDE are supported and if the shift amount is a constant 1, emit |
| 5403 | // this X << 1 as X+X. |
| 5404 | if (ConstantSDNode *ShAmt = dyn_cast<ConstantSDNode>(ShiftAmt)) { |
| 5405 | if (ShAmt->getValue() == 1 && TLI.isOperationLegal(ISD::ADDC, NVT) && |
| 5406 | TLI.isOperationLegal(ISD::ADDE, NVT)) { |
| 5407 | SDOperand LoOps[2], HiOps[3]; |
| 5408 | ExpandOp(Node->getOperand(0), LoOps[0], HiOps[0]); |
| 5409 | SDVTList VTList = DAG.getVTList(LoOps[0].getValueType(), MVT::Flag); |
| 5410 | LoOps[1] = LoOps[0]; |
| 5411 | Lo = DAG.getNode(ISD::ADDC, VTList, LoOps, 2); |
| 5412 | |
| 5413 | HiOps[1] = HiOps[0]; |
| 5414 | HiOps[2] = Lo.getValue(1); |
| 5415 | Hi = DAG.getNode(ISD::ADDE, VTList, HiOps, 3); |
| 5416 | break; |
| 5417 | } |
| 5418 | } |
| 5419 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5420 | // If we can emit an efficient shift operation, do so now. |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 5421 | if (ExpandShift(ISD::SHL, Node->getOperand(0), ShiftAmt, Lo, Hi)) |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5422 | break; |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 5423 | |
| 5424 | // If this target supports SHL_PARTS, use it. |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 5425 | TargetLowering::LegalizeAction Action = |
| 5426 | TLI.getOperationAction(ISD::SHL_PARTS, NVT); |
| 5427 | if ((Action == TargetLowering::Legal && TLI.isTypeLegal(NVT)) || |
| 5428 | Action == TargetLowering::Custom) { |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 5429 | ExpandShiftParts(ISD::SHL_PARTS, Node->getOperand(0), ShiftAmt, Lo, Hi); |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 5430 | break; |
| 5431 | } |
| 5432 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5433 | // Otherwise, emit a libcall. |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5434 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::SHL_I64), Node, |
| 5435 | false/*left shift=unsigned*/, Hi); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5436 | break; |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 5437 | } |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5438 | |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 5439 | case ISD::SRA: { |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 5440 | // If the target wants custom lowering, do so. |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 5441 | SDOperand ShiftAmt = LegalizeOp(Node->getOperand(1)); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 5442 | if (TLI.getOperationAction(ISD::SRA, VT) == TargetLowering::Custom) { |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5443 | SDOperand Op = DAG.getNode(ISD::SRA, VT, Node->getOperand(0), ShiftAmt); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 5444 | Op = TLI.LowerOperation(Op, DAG); |
| 5445 | if (Op.Val) { |
| 5446 | // Now that the custom expander is done, expand the result, which is |
| 5447 | // still VT. |
| 5448 | ExpandOp(Op, Lo, Hi); |
| 5449 | break; |
| 5450 | } |
| 5451 | } |
| 5452 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5453 | // If we can emit an efficient shift operation, do so now. |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 5454 | if (ExpandShift(ISD::SRA, Node->getOperand(0), ShiftAmt, Lo, Hi)) |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5455 | break; |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 5456 | |
| 5457 | // If this target supports SRA_PARTS, use it. |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 5458 | TargetLowering::LegalizeAction Action = |
| 5459 | TLI.getOperationAction(ISD::SRA_PARTS, NVT); |
| 5460 | if ((Action == TargetLowering::Legal && TLI.isTypeLegal(NVT)) || |
| 5461 | Action == TargetLowering::Custom) { |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 5462 | ExpandShiftParts(ISD::SRA_PARTS, Node->getOperand(0), ShiftAmt, Lo, Hi); |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 5463 | break; |
| 5464 | } |
| 5465 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5466 | // Otherwise, emit a libcall. |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5467 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::SRA_I64), Node, |
| 5468 | true/*ashr is signed*/, Hi); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5469 | break; |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 5470 | } |
| 5471 | |
| 5472 | case ISD::SRL: { |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 5473 | // If the target wants custom lowering, do so. |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 5474 | SDOperand ShiftAmt = LegalizeOp(Node->getOperand(1)); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 5475 | if (TLI.getOperationAction(ISD::SRL, VT) == TargetLowering::Custom) { |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5476 | SDOperand Op = DAG.getNode(ISD::SRL, VT, Node->getOperand(0), ShiftAmt); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 5477 | Op = TLI.LowerOperation(Op, DAG); |
| 5478 | if (Op.Val) { |
| 5479 | // Now that the custom expander is done, expand the result, which is |
| 5480 | // still VT. |
| 5481 | ExpandOp(Op, Lo, Hi); |
| 5482 | break; |
| 5483 | } |
| 5484 | } |
| 5485 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5486 | // If we can emit an efficient shift operation, do so now. |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 5487 | if (ExpandShift(ISD::SRL, Node->getOperand(0), ShiftAmt, Lo, Hi)) |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5488 | break; |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 5489 | |
| 5490 | // If this target supports SRL_PARTS, use it. |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 5491 | TargetLowering::LegalizeAction Action = |
| 5492 | TLI.getOperationAction(ISD::SRL_PARTS, NVT); |
| 5493 | if ((Action == TargetLowering::Legal && TLI.isTypeLegal(NVT)) || |
| 5494 | Action == TargetLowering::Custom) { |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 5495 | ExpandShiftParts(ISD::SRL_PARTS, Node->getOperand(0), ShiftAmt, Lo, Hi); |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 5496 | break; |
| 5497 | } |
| 5498 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5499 | // Otherwise, emit a libcall. |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5500 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::SRL_I64), Node, |
| 5501 | false/*lshr is unsigned*/, Hi); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5502 | break; |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 5503 | } |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5504 | |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 5505 | case ISD::ADD: |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5506 | case ISD::SUB: { |
| 5507 | // If the target wants to custom expand this, let them. |
| 5508 | if (TLI.getOperationAction(Node->getOpcode(), VT) == |
| 5509 | TargetLowering::Custom) { |
| 5510 | Op = TLI.LowerOperation(Op, DAG); |
| 5511 | if (Op.Val) { |
| 5512 | ExpandOp(Op, Lo, Hi); |
| 5513 | break; |
| 5514 | } |
| 5515 | } |
| 5516 | |
| 5517 | // Expand the subcomponents. |
| 5518 | SDOperand LHSL, LHSH, RHSL, RHSH; |
| 5519 | ExpandOp(Node->getOperand(0), LHSL, LHSH); |
| 5520 | ExpandOp(Node->getOperand(1), RHSL, RHSH); |
Chris Lattner | 79980b0 | 2006-09-13 03:50:39 +0000 | [diff] [blame] | 5521 | SDVTList VTList = DAG.getVTList(LHSL.getValueType(), MVT::Flag); |
| 5522 | SDOperand LoOps[2], HiOps[3]; |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 5523 | LoOps[0] = LHSL; |
| 5524 | LoOps[1] = RHSL; |
| 5525 | HiOps[0] = LHSH; |
| 5526 | HiOps[1] = RHSH; |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 5527 | if (Node->getOpcode() == ISD::ADD) { |
Chris Lattner | 79980b0 | 2006-09-13 03:50:39 +0000 | [diff] [blame] | 5528 | Lo = DAG.getNode(ISD::ADDC, VTList, LoOps, 2); |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 5529 | HiOps[2] = Lo.getValue(1); |
Chris Lattner | 79980b0 | 2006-09-13 03:50:39 +0000 | [diff] [blame] | 5530 | Hi = DAG.getNode(ISD::ADDE, VTList, HiOps, 3); |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 5531 | } else { |
Chris Lattner | 79980b0 | 2006-09-13 03:50:39 +0000 | [diff] [blame] | 5532 | Lo = DAG.getNode(ISD::SUBC, VTList, LoOps, 2); |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 5533 | HiOps[2] = Lo.getValue(1); |
Chris Lattner | 79980b0 | 2006-09-13 03:50:39 +0000 | [diff] [blame] | 5534 | Hi = DAG.getNode(ISD::SUBE, VTList, HiOps, 3); |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 5535 | } |
Chris Lattner | 84f6788 | 2005-01-20 18:52:28 +0000 | [diff] [blame] | 5536 | break; |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5537 | } |
Chris Lattner | b429f73 | 2007-05-17 18:15:41 +0000 | [diff] [blame] | 5538 | |
| 5539 | case ISD::ADDC: |
| 5540 | case ISD::SUBC: { |
| 5541 | // Expand the subcomponents. |
| 5542 | SDOperand LHSL, LHSH, RHSL, RHSH; |
| 5543 | ExpandOp(Node->getOperand(0), LHSL, LHSH); |
| 5544 | ExpandOp(Node->getOperand(1), RHSL, RHSH); |
| 5545 | SDVTList VTList = DAG.getVTList(LHSL.getValueType(), MVT::Flag); |
| 5546 | SDOperand LoOps[2] = { LHSL, RHSL }; |
| 5547 | SDOperand HiOps[3] = { LHSH, RHSH }; |
| 5548 | |
| 5549 | if (Node->getOpcode() == ISD::ADDC) { |
| 5550 | Lo = DAG.getNode(ISD::ADDC, VTList, LoOps, 2); |
| 5551 | HiOps[2] = Lo.getValue(1); |
| 5552 | Hi = DAG.getNode(ISD::ADDE, VTList, HiOps, 3); |
| 5553 | } else { |
| 5554 | Lo = DAG.getNode(ISD::SUBC, VTList, LoOps, 2); |
| 5555 | HiOps[2] = Lo.getValue(1); |
| 5556 | Hi = DAG.getNode(ISD::SUBE, VTList, HiOps, 3); |
| 5557 | } |
| 5558 | // Remember that we legalized the flag. |
| 5559 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Hi.getValue(1))); |
| 5560 | break; |
| 5561 | } |
| 5562 | case ISD::ADDE: |
| 5563 | case ISD::SUBE: { |
| 5564 | // Expand the subcomponents. |
| 5565 | SDOperand LHSL, LHSH, RHSL, RHSH; |
| 5566 | ExpandOp(Node->getOperand(0), LHSL, LHSH); |
| 5567 | ExpandOp(Node->getOperand(1), RHSL, RHSH); |
| 5568 | SDVTList VTList = DAG.getVTList(LHSL.getValueType(), MVT::Flag); |
| 5569 | SDOperand LoOps[3] = { LHSL, RHSL, Node->getOperand(2) }; |
| 5570 | SDOperand HiOps[3] = { LHSH, RHSH }; |
| 5571 | |
| 5572 | Lo = DAG.getNode(Node->getOpcode(), VTList, LoOps, 3); |
| 5573 | HiOps[2] = Lo.getValue(1); |
| 5574 | Hi = DAG.getNode(Node->getOpcode(), VTList, HiOps, 3); |
| 5575 | |
| 5576 | // Remember that we legalized the flag. |
| 5577 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Hi.getValue(1))); |
| 5578 | break; |
| 5579 | } |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 5580 | case ISD::MUL: { |
Chris Lattner | 7d7bffe | 2006-09-16 00:09:24 +0000 | [diff] [blame] | 5581 | // If the target wants to custom expand this, let them. |
| 5582 | if (TLI.getOperationAction(ISD::MUL, VT) == TargetLowering::Custom) { |
Chris Lattner | 8829dc8 | 2006-09-16 05:08:34 +0000 | [diff] [blame] | 5583 | SDOperand New = TLI.LowerOperation(Op, DAG); |
| 5584 | if (New.Val) { |
| 5585 | ExpandOp(New, Lo, Hi); |
Chris Lattner | 7d7bffe | 2006-09-16 00:09:24 +0000 | [diff] [blame] | 5586 | break; |
| 5587 | } |
| 5588 | } |
| 5589 | |
Evan Cheng | 3f4fd0f | 2006-09-01 18:17:58 +0000 | [diff] [blame] | 5590 | bool HasMULHS = TLI.isOperationLegal(ISD::MULHS, NVT); |
| 5591 | bool HasMULHU = TLI.isOperationLegal(ISD::MULHU, NVT); |
Evan Cheng | 3f4fd0f | 2006-09-01 18:17:58 +0000 | [diff] [blame] | 5592 | if (HasMULHS || HasMULHU) { |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 5593 | SDOperand LL, LH, RL, RH; |
| 5594 | ExpandOp(Node->getOperand(0), LL, LH); |
| 5595 | ExpandOp(Node->getOperand(1), RL, RH); |
Nate Begeman | 56eb868 | 2005-08-30 02:44:00 +0000 | [diff] [blame] | 5596 | unsigned SH = MVT::getSizeInBits(RH.getValueType())-1; |
Nate Begeman | 2cbba89 | 2006-12-11 02:23:46 +0000 | [diff] [blame] | 5597 | // FIXME: Move this to the dag combiner. |
Nate Begeman | 56eb868 | 2005-08-30 02:44:00 +0000 | [diff] [blame] | 5598 | // MULHS implicitly sign extends its inputs. Check to see if ExpandOp |
| 5599 | // extended the sign bit of the low half through the upper half, and if so |
| 5600 | // emit a MULHS instead of the alternate sequence that is valid for any |
| 5601 | // i64 x i64 multiply. |
Evan Cheng | 3f4fd0f | 2006-09-01 18:17:58 +0000 | [diff] [blame] | 5602 | if (HasMULHS && |
Nate Begeman | 56eb868 | 2005-08-30 02:44:00 +0000 | [diff] [blame] | 5603 | // is RH an extension of the sign bit of RL? |
| 5604 | RH.getOpcode() == ISD::SRA && RH.getOperand(0) == RL && |
| 5605 | RH.getOperand(1).getOpcode() == ISD::Constant && |
| 5606 | cast<ConstantSDNode>(RH.getOperand(1))->getValue() == SH && |
| 5607 | // is LH an extension of the sign bit of LL? |
| 5608 | LH.getOpcode() == ISD::SRA && LH.getOperand(0) == LL && |
| 5609 | LH.getOperand(1).getOpcode() == ISD::Constant && |
| 5610 | cast<ConstantSDNode>(LH.getOperand(1))->getValue() == SH) { |
Chris Lattner | a89654b | 2006-09-16 00:21:44 +0000 | [diff] [blame] | 5611 | // Low part: |
| 5612 | Lo = DAG.getNode(ISD::MUL, NVT, LL, RL); |
| 5613 | // High part: |
Nate Begeman | 56eb868 | 2005-08-30 02:44:00 +0000 | [diff] [blame] | 5614 | Hi = DAG.getNode(ISD::MULHS, NVT, LL, RL); |
Chris Lattner | a89654b | 2006-09-16 00:21:44 +0000 | [diff] [blame] | 5615 | break; |
Evan Cheng | 3f4fd0f | 2006-09-01 18:17:58 +0000 | [diff] [blame] | 5616 | } else if (HasMULHU) { |
Chris Lattner | a89654b | 2006-09-16 00:21:44 +0000 | [diff] [blame] | 5617 | // Low part: |
| 5618 | Lo = DAG.getNode(ISD::MUL, NVT, LL, RL); |
| 5619 | |
| 5620 | // High part: |
Nate Begeman | 56eb868 | 2005-08-30 02:44:00 +0000 | [diff] [blame] | 5621 | Hi = DAG.getNode(ISD::MULHU, NVT, LL, RL); |
| 5622 | RH = DAG.getNode(ISD::MUL, NVT, LL, RH); |
| 5623 | LH = DAG.getNode(ISD::MUL, NVT, LH, RL); |
| 5624 | Hi = DAG.getNode(ISD::ADD, NVT, Hi, RH); |
| 5625 | Hi = DAG.getNode(ISD::ADD, NVT, Hi, LH); |
Chris Lattner | a89654b | 2006-09-16 00:21:44 +0000 | [diff] [blame] | 5626 | break; |
Nate Begeman | 56eb868 | 2005-08-30 02:44:00 +0000 | [diff] [blame] | 5627 | } |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 5628 | } |
Evan Cheng | 3f4fd0f | 2006-09-01 18:17:58 +0000 | [diff] [blame] | 5629 | |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5630 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::MUL_I64), Node, |
| 5631 | false/*sign irrelevant*/, Hi); |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 5632 | break; |
| 5633 | } |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5634 | case ISD::SDIV: |
| 5635 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::SDIV_I64), Node, true, Hi); |
| 5636 | break; |
| 5637 | case ISD::UDIV: |
| 5638 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::UDIV_I64), Node, true, Hi); |
| 5639 | break; |
| 5640 | case ISD::SREM: |
| 5641 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::SREM_I64), Node, true, Hi); |
| 5642 | break; |
| 5643 | case ISD::UREM: |
| 5644 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::UREM_I64), Node, true, Hi); |
| 5645 | break; |
Evan Cheng | 5c9ce18 | 2006-12-12 21:51:17 +0000 | [diff] [blame] | 5646 | |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 5647 | case ISD::FADD: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5648 | Lo = ExpandLibCall(TLI.getLibcallName((VT == MVT::f32) |
| 5649 | ? RTLIB::ADD_F32 : RTLIB::ADD_F64), |
| 5650 | Node, false, Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 5651 | break; |
| 5652 | case ISD::FSUB: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5653 | Lo = ExpandLibCall(TLI.getLibcallName((VT == MVT::f32) |
| 5654 | ? RTLIB::SUB_F32 : RTLIB::SUB_F64), |
| 5655 | Node, false, Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 5656 | break; |
| 5657 | case ISD::FMUL: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5658 | Lo = ExpandLibCall(TLI.getLibcallName((VT == MVT::f32) |
| 5659 | ? RTLIB::MUL_F32 : RTLIB::MUL_F64), |
| 5660 | Node, false, Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 5661 | break; |
| 5662 | case ISD::FDIV: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5663 | Lo = ExpandLibCall(TLI.getLibcallName((VT == MVT::f32) |
| 5664 | ? RTLIB::DIV_F32 : RTLIB::DIV_F64), |
| 5665 | Node, false, Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 5666 | break; |
| 5667 | case ISD::FP_EXTEND: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5668 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::FPEXT_F32_F64), Node, true,Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 5669 | break; |
| 5670 | case ISD::FP_ROUND: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5671 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::FPROUND_F64_F32),Node,true,Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 5672 | break; |
Lauro Ramos Venancio | c90f089 | 2007-08-15 22:13:27 +0000 | [diff] [blame] | 5673 | case ISD::FPOWI: |
| 5674 | Lo = ExpandLibCall(TLI.getLibcallName((VT == MVT::f32) |
| 5675 | ? RTLIB::POWI_F32 : RTLIB::POWI_F64), |
| 5676 | Node, false, Hi); |
| 5677 | break; |
Evan Cheng | 98ff3b9 | 2006-12-13 02:38:13 +0000 | [diff] [blame] | 5678 | case ISD::FSQRT: |
| 5679 | case ISD::FSIN: |
| 5680 | case ISD::FCOS: { |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5681 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
Evan Cheng | 98ff3b9 | 2006-12-13 02:38:13 +0000 | [diff] [blame] | 5682 | switch(Node->getOpcode()) { |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5683 | case ISD::FSQRT: |
| 5684 | LC = (VT == MVT::f32) ? RTLIB::SQRT_F32 : RTLIB::SQRT_F64; |
| 5685 | break; |
| 5686 | case ISD::FSIN: |
| 5687 | LC = (VT == MVT::f32) ? RTLIB::SIN_F32 : RTLIB::SIN_F64; |
| 5688 | break; |
| 5689 | case ISD::FCOS: |
| 5690 | LC = (VT == MVT::f32) ? RTLIB::COS_F32 : RTLIB::COS_F64; |
| 5691 | break; |
Evan Cheng | 98ff3b9 | 2006-12-13 02:38:13 +0000 | [diff] [blame] | 5692 | default: assert(0 && "Unreachable!"); |
| 5693 | } |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5694 | Lo = ExpandLibCall(TLI.getLibcallName(LC), Node, false, Hi); |
Evan Cheng | 98ff3b9 | 2006-12-13 02:38:13 +0000 | [diff] [blame] | 5695 | break; |
| 5696 | } |
Evan Cheng | 966bf24 | 2006-12-16 00:52:40 +0000 | [diff] [blame] | 5697 | case ISD::FABS: { |
| 5698 | SDOperand Mask = (VT == MVT::f64) |
| 5699 | ? DAG.getConstantFP(BitsToDouble(~(1ULL << 63)), VT) |
| 5700 | : DAG.getConstantFP(BitsToFloat(~(1U << 31)), VT); |
| 5701 | Mask = DAG.getNode(ISD::BIT_CONVERT, NVT, Mask); |
| 5702 | Lo = DAG.getNode(ISD::BIT_CONVERT, NVT, Node->getOperand(0)); |
| 5703 | Lo = DAG.getNode(ISD::AND, NVT, Lo, Mask); |
| 5704 | if (getTypeAction(NVT) == Expand) |
| 5705 | ExpandOp(Lo, Lo, Hi); |
| 5706 | break; |
| 5707 | } |
| 5708 | case ISD::FNEG: { |
| 5709 | SDOperand Mask = (VT == MVT::f64) |
| 5710 | ? DAG.getConstantFP(BitsToDouble(1ULL << 63), VT) |
| 5711 | : DAG.getConstantFP(BitsToFloat(1U << 31), VT); |
| 5712 | Mask = DAG.getNode(ISD::BIT_CONVERT, NVT, Mask); |
| 5713 | Lo = DAG.getNode(ISD::BIT_CONVERT, NVT, Node->getOperand(0)); |
| 5714 | Lo = DAG.getNode(ISD::XOR, NVT, Lo, Mask); |
| 5715 | if (getTypeAction(NVT) == Expand) |
| 5716 | ExpandOp(Lo, Lo, Hi); |
| 5717 | break; |
| 5718 | } |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 5719 | case ISD::FCOPYSIGN: { |
| 5720 | Lo = ExpandFCOPYSIGNToBitwiseOps(Node, NVT, DAG, TLI); |
| 5721 | if (getTypeAction(NVT) == Expand) |
| 5722 | ExpandOp(Lo, Lo, Hi); |
| 5723 | break; |
| 5724 | } |
Evan Cheng | 7df28dc | 2006-12-19 01:44:04 +0000 | [diff] [blame] | 5725 | case ISD::SINT_TO_FP: |
| 5726 | case ISD::UINT_TO_FP: { |
| 5727 | bool isSigned = Node->getOpcode() == ISD::SINT_TO_FP; |
| 5728 | MVT::ValueType SrcVT = Node->getOperand(0).getValueType(); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5729 | RTLIB::Libcall LC; |
Evan Cheng | 7df28dc | 2006-12-19 01:44:04 +0000 | [diff] [blame] | 5730 | if (Node->getOperand(0).getValueType() == MVT::i64) { |
| 5731 | if (VT == MVT::f32) |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5732 | LC = isSigned ? RTLIB::SINTTOFP_I64_F32 : RTLIB::UINTTOFP_I64_F32; |
Evan Cheng | 7df28dc | 2006-12-19 01:44:04 +0000 | [diff] [blame] | 5733 | else |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5734 | LC = isSigned ? RTLIB::SINTTOFP_I64_F64 : RTLIB::UINTTOFP_I64_F64; |
Evan Cheng | 7df28dc | 2006-12-19 01:44:04 +0000 | [diff] [blame] | 5735 | } else { |
| 5736 | if (VT == MVT::f32) |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5737 | LC = isSigned ? RTLIB::SINTTOFP_I32_F32 : RTLIB::UINTTOFP_I32_F32; |
Evan Cheng | 7df28dc | 2006-12-19 01:44:04 +0000 | [diff] [blame] | 5738 | else |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5739 | LC = isSigned ? RTLIB::SINTTOFP_I32_F64 : RTLIB::UINTTOFP_I32_F64; |
Evan Cheng | 7df28dc | 2006-12-19 01:44:04 +0000 | [diff] [blame] | 5740 | } |
| 5741 | |
| 5742 | // Promote the operand if needed. |
| 5743 | if (getTypeAction(SrcVT) == Promote) { |
| 5744 | SDOperand Tmp = PromoteOp(Node->getOperand(0)); |
| 5745 | Tmp = isSigned |
| 5746 | ? DAG.getNode(ISD::SIGN_EXTEND_INREG, Tmp.getValueType(), Tmp, |
| 5747 | DAG.getValueType(SrcVT)) |
| 5748 | : DAG.getZeroExtendInReg(Tmp, SrcVT); |
| 5749 | Node = DAG.UpdateNodeOperands(Op, Tmp).Val; |
| 5750 | } |
Evan Cheng | 4c6cfad | 2007-04-27 07:33:31 +0000 | [diff] [blame] | 5751 | |
| 5752 | const char *LibCall = TLI.getLibcallName(LC); |
| 5753 | if (LibCall) |
| 5754 | Lo = ExpandLibCall(TLI.getLibcallName(LC), Node, isSigned, Hi); |
| 5755 | else { |
| 5756 | Lo = ExpandIntToFP(Node->getOpcode() == ISD::SINT_TO_FP, VT, |
| 5757 | Node->getOperand(0)); |
| 5758 | if (getTypeAction(Lo.getValueType()) == Expand) |
| 5759 | ExpandOp(Lo, Lo, Hi); |
| 5760 | } |
Evan Cheng | 7df28dc | 2006-12-19 01:44:04 +0000 | [diff] [blame] | 5761 | break; |
| 5762 | } |
Evan Cheng | 98ff3b9 | 2006-12-13 02:38:13 +0000 | [diff] [blame] | 5763 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5764 | |
Chris Lattner | 8339736 | 2005-12-21 18:02:52 +0000 | [diff] [blame] | 5765 | // Make sure the resultant values have been legalized themselves, unless this |
| 5766 | // is a type that requires multi-step expansion. |
| 5767 | if (getTypeAction(NVT) != Expand && NVT != MVT::isVoid) { |
| 5768 | Lo = LegalizeOp(Lo); |
Evan Cheng | 13acce3 | 2006-12-11 19:27:14 +0000 | [diff] [blame] | 5769 | if (Hi.Val) |
| 5770 | // Don't legalize the high part if it is expanded to a single node. |
| 5771 | Hi = LegalizeOp(Hi); |
Chris Lattner | 8339736 | 2005-12-21 18:02:52 +0000 | [diff] [blame] | 5772 | } |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 5773 | |
| 5774 | // Remember in a map if the values will be reused later. |
Chris Lattner | 40030bf | 2007-02-04 01:17:38 +0000 | [diff] [blame] | 5775 | bool isNew = ExpandedNodes.insert(std::make_pair(Op, std::make_pair(Lo, Hi))); |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 5776 | assert(isNew && "Value already expanded?!?"); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5777 | } |
| 5778 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5779 | /// SplitVectorOp - Given an operand of vector type, break it down into |
| 5780 | /// two smaller values, still of vector type. |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 5781 | void SelectionDAGLegalize::SplitVectorOp(SDOperand Op, SDOperand &Lo, |
| 5782 | SDOperand &Hi) { |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5783 | assert(MVT::isVector(Op.getValueType()) && "Cannot split non-vector type!"); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 5784 | SDNode *Node = Op.Val; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5785 | unsigned NumElements = MVT::getVectorNumElements(Node->getValueType(0)); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 5786 | assert(NumElements > 1 && "Cannot split a single element vector!"); |
| 5787 | unsigned NewNumElts = NumElements/2; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5788 | MVT::ValueType NewEltVT = MVT::getVectorElementType(Node->getValueType(0)); |
| 5789 | MVT::ValueType NewVT = MVT::getVectorType(NewEltVT, NewNumElts); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 5790 | |
| 5791 | // See if we already split it. |
| 5792 | std::map<SDOperand, std::pair<SDOperand, SDOperand> >::iterator I |
| 5793 | = SplitNodes.find(Op); |
| 5794 | if (I != SplitNodes.end()) { |
| 5795 | Lo = I->second.first; |
| 5796 | Hi = I->second.second; |
| 5797 | return; |
| 5798 | } |
| 5799 | |
| 5800 | switch (Node->getOpcode()) { |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 5801 | default: |
| 5802 | #ifndef NDEBUG |
Dan Gohman | 3983358 | 2007-06-04 16:17:33 +0000 | [diff] [blame] | 5803 | Node->dump(&DAG); |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 5804 | #endif |
| 5805 | assert(0 && "Unhandled operation in SplitVectorOp!"); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5806 | case ISD::BUILD_PAIR: |
| 5807 | Lo = Node->getOperand(0); |
| 5808 | Hi = Node->getOperand(1); |
| 5809 | break; |
| 5810 | case ISD::BUILD_VECTOR: { |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 5811 | SmallVector<SDOperand, 8> LoOps(Node->op_begin(), |
| 5812 | Node->op_begin()+NewNumElts); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5813 | Lo = DAG.getNode(ISD::BUILD_VECTOR, NewVT, &LoOps[0], LoOps.size()); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 5814 | |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 5815 | SmallVector<SDOperand, 8> HiOps(Node->op_begin()+NewNumElts, |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5816 | Node->op_end()); |
| 5817 | Hi = DAG.getNode(ISD::BUILD_VECTOR, NewVT, &HiOps[0], HiOps.size()); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 5818 | break; |
| 5819 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5820 | case ISD::CONCAT_VECTORS: { |
| 5821 | unsigned NewNumSubvectors = Node->getNumOperands() / 2; |
| 5822 | if (NewNumSubvectors == 1) { |
| 5823 | Lo = Node->getOperand(0); |
| 5824 | Hi = Node->getOperand(1); |
| 5825 | } else { |
| 5826 | SmallVector<SDOperand, 8> LoOps(Node->op_begin(), |
| 5827 | Node->op_begin()+NewNumSubvectors); |
| 5828 | Lo = DAG.getNode(ISD::CONCAT_VECTORS, NewVT, &LoOps[0], LoOps.size()); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 5829 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5830 | SmallVector<SDOperand, 8> HiOps(Node->op_begin()+NewNumSubvectors, |
| 5831 | Node->op_end()); |
| 5832 | Hi = DAG.getNode(ISD::CONCAT_VECTORS, NewVT, &HiOps[0], HiOps.size()); |
| 5833 | } |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 5834 | break; |
| 5835 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5836 | case ISD::ADD: |
| 5837 | case ISD::SUB: |
| 5838 | case ISD::MUL: |
| 5839 | case ISD::FADD: |
| 5840 | case ISD::FSUB: |
| 5841 | case ISD::FMUL: |
| 5842 | case ISD::SDIV: |
| 5843 | case ISD::UDIV: |
| 5844 | case ISD::FDIV: |
| 5845 | case ISD::AND: |
| 5846 | case ISD::OR: |
| 5847 | case ISD::XOR: { |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 5848 | SDOperand LL, LH, RL, RH; |
| 5849 | SplitVectorOp(Node->getOperand(0), LL, LH); |
| 5850 | SplitVectorOp(Node->getOperand(1), RL, RH); |
| 5851 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5852 | Lo = DAG.getNode(Node->getOpcode(), NewVT, LL, RL); |
| 5853 | Hi = DAG.getNode(Node->getOpcode(), NewVT, LH, RH); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 5854 | break; |
| 5855 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5856 | case ISD::LOAD: { |
| 5857 | LoadSDNode *LD = cast<LoadSDNode>(Node); |
| 5858 | SDOperand Ch = LD->getChain(); |
| 5859 | SDOperand Ptr = LD->getBasePtr(); |
| 5860 | const Value *SV = LD->getSrcValue(); |
| 5861 | int SVOffset = LD->getSrcValueOffset(); |
| 5862 | unsigned Alignment = LD->getAlignment(); |
| 5863 | bool isVolatile = LD->isVolatile(); |
| 5864 | |
| 5865 | Lo = DAG.getLoad(NewVT, Ch, Ptr, SV, SVOffset, isVolatile, Alignment); |
| 5866 | unsigned IncrementSize = NewNumElts * MVT::getSizeInBits(NewEltVT)/8; |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 5867 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
| 5868 | getIntPtrConstant(IncrementSize)); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5869 | SVOffset += IncrementSize; |
| 5870 | if (Alignment > IncrementSize) |
| 5871 | Alignment = IncrementSize; |
| 5872 | Hi = DAG.getLoad(NewVT, Ch, Ptr, SV, SVOffset, isVolatile, Alignment); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 5873 | |
| 5874 | // Build a factor node to remember that this load is independent of the |
| 5875 | // other one. |
| 5876 | SDOperand TF = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1), |
| 5877 | Hi.getValue(1)); |
| 5878 | |
| 5879 | // Remember that we legalized the chain. |
| 5880 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(TF)); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 5881 | break; |
| 5882 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5883 | case ISD::BIT_CONVERT: { |
Chris Lattner | 7692eb4 | 2006-03-23 21:16:34 +0000 | [diff] [blame] | 5884 | // We know the result is a vector. The input may be either a vector or a |
| 5885 | // scalar value. |
Dan Gohman | 10a7aa6 | 2007-06-29 00:09:08 +0000 | [diff] [blame] | 5886 | SDOperand InOp = Node->getOperand(0); |
| 5887 | if (!MVT::isVector(InOp.getValueType()) || |
| 5888 | MVT::getVectorNumElements(InOp.getValueType()) == 1) { |
| 5889 | // The input is a scalar or single-element vector. |
| 5890 | // Lower to a store/load so that it can be split. |
| 5891 | // FIXME: this could be improved probably. |
| 5892 | SDOperand Ptr = CreateStackTemporary(InOp.getValueType()); |
Chris Lattner | 7692eb4 | 2006-03-23 21:16:34 +0000 | [diff] [blame] | 5893 | |
Evan Cheng | 786225a | 2006-10-05 23:01:46 +0000 | [diff] [blame] | 5894 | SDOperand St = DAG.getStore(DAG.getEntryNode(), |
Dan Gohman | 10a7aa6 | 2007-06-29 00:09:08 +0000 | [diff] [blame] | 5895 | InOp, Ptr, NULL, 0); |
| 5896 | InOp = DAG.getLoad(Op.getValueType(), St, Ptr, NULL, 0); |
Chris Lattner | 7692eb4 | 2006-03-23 21:16:34 +0000 | [diff] [blame] | 5897 | } |
Dan Gohman | 10a7aa6 | 2007-06-29 00:09:08 +0000 | [diff] [blame] | 5898 | // Split the vector and convert each of the pieces now. |
| 5899 | SplitVectorOp(InOp, Lo, Hi); |
| 5900 | Lo = DAG.getNode(ISD::BIT_CONVERT, NewVT, Lo); |
| 5901 | Hi = DAG.getNode(ISD::BIT_CONVERT, NewVT, Hi); |
| 5902 | break; |
Chris Lattner | 7692eb4 | 2006-03-23 21:16:34 +0000 | [diff] [blame] | 5903 | } |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 5904 | } |
| 5905 | |
| 5906 | // Remember in a map if the values will be reused later. |
Chris Lattner | 40030bf | 2007-02-04 01:17:38 +0000 | [diff] [blame] | 5907 | bool isNew = |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 5908 | SplitNodes.insert(std::make_pair(Op, std::make_pair(Lo, Hi))).second; |
Dan Gohman | 10a7aa6 | 2007-06-29 00:09:08 +0000 | [diff] [blame] | 5909 | assert(isNew && "Value already split?!?"); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 5910 | } |
| 5911 | |
| 5912 | |
Dan Gohman | 89b20c0 | 2007-06-27 14:06:22 +0000 | [diff] [blame] | 5913 | /// ScalarizeVectorOp - Given an operand of single-element vector type |
| 5914 | /// (e.g. v1f32), convert it into the equivalent operation that returns a |
| 5915 | /// scalar (e.g. f32) value. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5916 | SDOperand SelectionDAGLegalize::ScalarizeVectorOp(SDOperand Op) { |
| 5917 | assert(MVT::isVector(Op.getValueType()) && |
| 5918 | "Bad ScalarizeVectorOp invocation!"); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 5919 | SDNode *Node = Op.Val; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5920 | MVT::ValueType NewVT = MVT::getVectorElementType(Op.getValueType()); |
| 5921 | assert(MVT::getVectorNumElements(Op.getValueType()) == 1); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 5922 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5923 | // See if we already scalarized it. |
| 5924 | std::map<SDOperand, SDOperand>::iterator I = ScalarizedNodes.find(Op); |
| 5925 | if (I != ScalarizedNodes.end()) return I->second; |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 5926 | |
| 5927 | SDOperand Result; |
| 5928 | switch (Node->getOpcode()) { |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 5929 | default: |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 5930 | #ifndef NDEBUG |
Dan Gohman | 3983358 | 2007-06-04 16:17:33 +0000 | [diff] [blame] | 5931 | Node->dump(&DAG); cerr << "\n"; |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 5932 | #endif |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5933 | assert(0 && "Unknown vector operation in ScalarizeVectorOp!"); |
| 5934 | case ISD::ADD: |
| 5935 | case ISD::FADD: |
| 5936 | case ISD::SUB: |
| 5937 | case ISD::FSUB: |
| 5938 | case ISD::MUL: |
| 5939 | case ISD::FMUL: |
| 5940 | case ISD::SDIV: |
| 5941 | case ISD::UDIV: |
| 5942 | case ISD::FDIV: |
| 5943 | case ISD::SREM: |
| 5944 | case ISD::UREM: |
| 5945 | case ISD::FREM: |
| 5946 | case ISD::AND: |
| 5947 | case ISD::OR: |
| 5948 | case ISD::XOR: |
| 5949 | Result = DAG.getNode(Node->getOpcode(), |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 5950 | NewVT, |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5951 | ScalarizeVectorOp(Node->getOperand(0)), |
| 5952 | ScalarizeVectorOp(Node->getOperand(1))); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 5953 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5954 | case ISD::FNEG: |
| 5955 | case ISD::FABS: |
| 5956 | case ISD::FSQRT: |
| 5957 | case ISD::FSIN: |
| 5958 | case ISD::FCOS: |
| 5959 | Result = DAG.getNode(Node->getOpcode(), |
| 5960 | NewVT, |
| 5961 | ScalarizeVectorOp(Node->getOperand(0))); |
| 5962 | break; |
| 5963 | case ISD::LOAD: { |
| 5964 | LoadSDNode *LD = cast<LoadSDNode>(Node); |
| 5965 | SDOperand Ch = LegalizeOp(LD->getChain()); // Legalize the chain. |
| 5966 | SDOperand Ptr = LegalizeOp(LD->getBasePtr()); // Legalize the pointer. |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 5967 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5968 | const Value *SV = LD->getSrcValue(); |
| 5969 | int SVOffset = LD->getSrcValueOffset(); |
| 5970 | Result = DAG.getLoad(NewVT, Ch, Ptr, SV, SVOffset, |
| 5971 | LD->isVolatile(), LD->getAlignment()); |
| 5972 | |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 5973 | // Remember that we legalized the chain. |
| 5974 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1))); |
| 5975 | break; |
| 5976 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5977 | case ISD::BUILD_VECTOR: |
| 5978 | Result = Node->getOperand(0); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 5979 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5980 | case ISD::INSERT_VECTOR_ELT: |
| 5981 | // Returning the inserted scalar element. |
| 5982 | Result = Node->getOperand(1); |
| 5983 | break; |
| 5984 | case ISD::CONCAT_VECTORS: |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 5985 | assert(Node->getOperand(0).getValueType() == NewVT && |
| 5986 | "Concat of non-legal vectors not yet supported!"); |
| 5987 | Result = Node->getOperand(0); |
| 5988 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5989 | case ISD::VECTOR_SHUFFLE: { |
| 5990 | // Figure out if the scalar is the LHS or RHS and return it. |
| 5991 | SDOperand EltNum = Node->getOperand(2).getOperand(0); |
| 5992 | if (cast<ConstantSDNode>(EltNum)->getValue()) |
| 5993 | Result = ScalarizeVectorOp(Node->getOperand(1)); |
| 5994 | else |
| 5995 | Result = ScalarizeVectorOp(Node->getOperand(0)); |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 5996 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5997 | } |
| 5998 | case ISD::EXTRACT_SUBVECTOR: |
| 5999 | Result = Node->getOperand(0); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 6000 | assert(Result.getValueType() == NewVT); |
| 6001 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6002 | case ISD::BIT_CONVERT: |
| 6003 | Result = DAG.getNode(ISD::BIT_CONVERT, NewVT, Op.getOperand(0)); |
Chris Lattner | 5b2316e | 2006-03-28 20:24:43 +0000 | [diff] [blame] | 6004 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6005 | case ISD::SELECT: |
Chris Lattner | b22e35a | 2006-04-08 22:22:57 +0000 | [diff] [blame] | 6006 | Result = DAG.getNode(ISD::SELECT, NewVT, Op.getOperand(0), |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6007 | ScalarizeVectorOp(Op.getOperand(1)), |
| 6008 | ScalarizeVectorOp(Op.getOperand(2))); |
Chris Lattner | b22e35a | 2006-04-08 22:22:57 +0000 | [diff] [blame] | 6009 | break; |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6010 | } |
| 6011 | |
| 6012 | if (TLI.isTypeLegal(NewVT)) |
| 6013 | Result = LegalizeOp(Result); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6014 | bool isNew = ScalarizedNodes.insert(std::make_pair(Op, Result)).second; |
| 6015 | assert(isNew && "Value already scalarized?"); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6016 | return Result; |
| 6017 | } |
| 6018 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6019 | |
| 6020 | // SelectionDAG::Legalize - This is the entry point for the file. |
| 6021 | // |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 6022 | void SelectionDAG::Legalize() { |
Chris Lattner | 5e46a19 | 2006-04-02 03:07:27 +0000 | [diff] [blame] | 6023 | if (ViewLegalizeDAGs) viewGraph(); |
| 6024 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6025 | /// run - This is the main entry point to this class. |
| 6026 | /// |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 6027 | SelectionDAGLegalize(*this).LegalizeDAG(); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6028 | } |
| 6029 | |