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; |
| 489 | ConstantFP *LLVMC = ConstantFP::get(isDouble ? Type::DoubleTy : |
| 490 | Type::FloatTy, CFP->getValue()); |
Evan Cheng | 9f87788 | 2006-12-13 20:57:08 +0000 | [diff] [blame] | 491 | if (!UseCP) { |
Evan Cheng | 279101e | 2006-12-12 22:19:28 +0000 | [diff] [blame] | 492 | double Val = LLVMC->getValue(); |
| 493 | return isDouble |
| 494 | ? DAG.getConstant(DoubleToBits(Val), MVT::i64) |
| 495 | : DAG.getConstant(FloatToBits(Val), MVT::i32); |
| 496 | } |
| 497 | |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 498 | if (isDouble && CFP->isExactlyValue((float)CFP->getValue()) && |
| 499 | // Only do this if the target has a native EXTLOAD instruction from f32. |
| 500 | TLI.isLoadXLegal(ISD::EXTLOAD, MVT::f32)) { |
| 501 | LLVMC = cast<ConstantFP>(ConstantExpr::getFPTrunc(LLVMC,Type::FloatTy)); |
| 502 | VT = MVT::f32; |
| 503 | Extend = true; |
| 504 | } |
| 505 | |
| 506 | SDOperand CPIdx = DAG.getConstantPool(LLVMC, TLI.getPointerTy()); |
| 507 | if (Extend) { |
| 508 | return DAG.getExtLoad(ISD::EXTLOAD, MVT::f64, DAG.getEntryNode(), |
| 509 | CPIdx, NULL, 0, MVT::f32); |
| 510 | } else { |
| 511 | return DAG.getLoad(VT, DAG.getEntryNode(), CPIdx, NULL, 0); |
| 512 | } |
| 513 | } |
| 514 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 515 | |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 516 | /// ExpandFCOPYSIGNToBitwiseOps - Expands fcopysign to a series of bitwise |
| 517 | /// operations. |
| 518 | static |
| 519 | SDOperand ExpandFCOPYSIGNToBitwiseOps(SDNode *Node, MVT::ValueType NVT, |
| 520 | SelectionDAG &DAG, TargetLowering &TLI) { |
Evan Cheng | 068c5f4 | 2007-01-05 21:31:51 +0000 | [diff] [blame] | 521 | MVT::ValueType VT = Node->getValueType(0); |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 522 | MVT::ValueType SrcVT = Node->getOperand(1).getValueType(); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 523 | assert((SrcVT == MVT::f32 || SrcVT == MVT::f64) && |
| 524 | "fcopysign expansion only supported for f32 and f64"); |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 525 | MVT::ValueType SrcNVT = (SrcVT == MVT::f64) ? MVT::i64 : MVT::i32; |
Evan Cheng | 068c5f4 | 2007-01-05 21:31:51 +0000 | [diff] [blame] | 526 | |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 527 | // First get the sign bit of second operand. |
Evan Cheng | 068c5f4 | 2007-01-05 21:31:51 +0000 | [diff] [blame] | 528 | SDOperand Mask1 = (SrcVT == MVT::f64) |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 529 | ? DAG.getConstantFP(BitsToDouble(1ULL << 63), SrcVT) |
| 530 | : DAG.getConstantFP(BitsToFloat(1U << 31), SrcVT); |
Evan Cheng | 068c5f4 | 2007-01-05 21:31:51 +0000 | [diff] [blame] | 531 | Mask1 = DAG.getNode(ISD::BIT_CONVERT, SrcNVT, Mask1); |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 532 | SDOperand SignBit= DAG.getNode(ISD::BIT_CONVERT, SrcNVT, Node->getOperand(1)); |
Evan Cheng | 068c5f4 | 2007-01-05 21:31:51 +0000 | [diff] [blame] | 533 | SignBit = DAG.getNode(ISD::AND, SrcNVT, SignBit, Mask1); |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 534 | // Shift right or sign-extend it if the two operands have different types. |
| 535 | int SizeDiff = MVT::getSizeInBits(SrcNVT) - MVT::getSizeInBits(NVT); |
| 536 | if (SizeDiff > 0) { |
| 537 | SignBit = DAG.getNode(ISD::SRL, SrcNVT, SignBit, |
| 538 | DAG.getConstant(SizeDiff, TLI.getShiftAmountTy())); |
| 539 | SignBit = DAG.getNode(ISD::TRUNCATE, NVT, SignBit); |
| 540 | } else if (SizeDiff < 0) |
| 541 | SignBit = DAG.getNode(ISD::SIGN_EXTEND, NVT, SignBit); |
Evan Cheng | 068c5f4 | 2007-01-05 21:31:51 +0000 | [diff] [blame] | 542 | |
| 543 | // Clear the sign bit of first operand. |
| 544 | SDOperand Mask2 = (VT == MVT::f64) |
| 545 | ? DAG.getConstantFP(BitsToDouble(~(1ULL << 63)), VT) |
| 546 | : DAG.getConstantFP(BitsToFloat(~(1U << 31)), VT); |
| 547 | Mask2 = DAG.getNode(ISD::BIT_CONVERT, NVT, Mask2); |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 548 | SDOperand Result = DAG.getNode(ISD::BIT_CONVERT, NVT, Node->getOperand(0)); |
Evan Cheng | 068c5f4 | 2007-01-05 21:31:51 +0000 | [diff] [blame] | 549 | Result = DAG.getNode(ISD::AND, NVT, Result, Mask2); |
| 550 | |
| 551 | // Or the value with the sign bit. |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 552 | Result = DAG.getNode(ISD::OR, NVT, Result, SignBit); |
| 553 | return Result; |
| 554 | } |
| 555 | |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 556 | /// ExpandUnalignedStore - Expands an unaligned store to 2 half-size stores. |
| 557 | static |
| 558 | SDOperand ExpandUnalignedStore(StoreSDNode *ST, SelectionDAG &DAG, |
| 559 | TargetLowering &TLI) { |
| 560 | assert(MVT::isInteger(ST->getStoredVT()) && |
| 561 | "Non integer unaligned stores not implemented."); |
| 562 | int SVOffset = ST->getSrcValueOffset(); |
| 563 | SDOperand Chain = ST->getChain(); |
| 564 | SDOperand Ptr = ST->getBasePtr(); |
| 565 | SDOperand Val = ST->getValue(); |
| 566 | MVT::ValueType VT = Val.getValueType(); |
| 567 | // Get the half-size VT |
| 568 | MVT::ValueType NewStoredVT = ST->getStoredVT() - 1; |
| 569 | int NumBits = MVT::getSizeInBits(NewStoredVT); |
| 570 | int Alignment = ST->getAlignment(); |
| 571 | int IncrementSize = NumBits / 8; |
| 572 | |
| 573 | // Divide the stored value in two parts. |
| 574 | SDOperand ShiftAmount = DAG.getConstant(NumBits, TLI.getShiftAmountTy()); |
| 575 | SDOperand Lo = Val; |
| 576 | SDOperand Hi = DAG.getNode(ISD::SRL, VT, Val, ShiftAmount); |
| 577 | |
| 578 | // Store the two parts |
| 579 | SDOperand Store1, Store2; |
| 580 | Store1 = DAG.getTruncStore(Chain, TLI.isLittleEndian()?Lo:Hi, Ptr, |
| 581 | ST->getSrcValue(), SVOffset, NewStoredVT, |
| 582 | ST->isVolatile(), Alignment); |
| 583 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
| 584 | DAG.getConstant(IncrementSize, TLI.getPointerTy())); |
| 585 | Store2 = DAG.getTruncStore(Chain, TLI.isLittleEndian()?Hi:Lo, Ptr, |
| 586 | ST->getSrcValue(), SVOffset + IncrementSize, |
| 587 | NewStoredVT, ST->isVolatile(), Alignment); |
| 588 | |
| 589 | return DAG.getNode(ISD::TokenFactor, MVT::Other, Store1, Store2); |
| 590 | } |
| 591 | |
| 592 | /// ExpandUnalignedLoad - Expands an unaligned load to 2 half-size loads. |
| 593 | static |
| 594 | SDOperand ExpandUnalignedLoad(LoadSDNode *LD, SelectionDAG &DAG, |
| 595 | TargetLowering &TLI) { |
| 596 | assert(MVT::isInteger(LD->getLoadedVT()) && |
| 597 | "Non integer unaligned loads not implemented."); |
| 598 | int SVOffset = LD->getSrcValueOffset(); |
| 599 | SDOperand Chain = LD->getChain(); |
| 600 | SDOperand Ptr = LD->getBasePtr(); |
| 601 | MVT::ValueType VT = LD->getValueType(0); |
| 602 | MVT::ValueType NewLoadedVT = LD->getLoadedVT() - 1; |
| 603 | int NumBits = MVT::getSizeInBits(NewLoadedVT); |
| 604 | int Alignment = LD->getAlignment(); |
| 605 | int IncrementSize = NumBits / 8; |
| 606 | ISD::LoadExtType HiExtType = LD->getExtensionType(); |
| 607 | |
| 608 | // If the original load is NON_EXTLOAD, the hi part load must be ZEXTLOAD. |
| 609 | if (HiExtType == ISD::NON_EXTLOAD) |
| 610 | HiExtType = ISD::ZEXTLOAD; |
| 611 | |
| 612 | // Load the value in two parts |
| 613 | SDOperand Lo, Hi; |
| 614 | if (TLI.isLittleEndian()) { |
| 615 | Lo = DAG.getExtLoad(ISD::ZEXTLOAD, VT, Chain, Ptr, LD->getSrcValue(), |
| 616 | SVOffset, NewLoadedVT, LD->isVolatile(), Alignment); |
| 617 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
| 618 | DAG.getConstant(IncrementSize, TLI.getPointerTy())); |
| 619 | Hi = DAG.getExtLoad(HiExtType, VT, Chain, Ptr, LD->getSrcValue(), |
| 620 | SVOffset + IncrementSize, NewLoadedVT, LD->isVolatile(), |
| 621 | Alignment); |
| 622 | } else { |
| 623 | Hi = DAG.getExtLoad(HiExtType, VT, Chain, Ptr, LD->getSrcValue(), SVOffset, |
| 624 | NewLoadedVT,LD->isVolatile(), Alignment); |
| 625 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
| 626 | DAG.getConstant(IncrementSize, TLI.getPointerTy())); |
| 627 | Lo = DAG.getExtLoad(ISD::ZEXTLOAD, VT, Chain, Ptr, LD->getSrcValue(), |
| 628 | SVOffset + IncrementSize, NewLoadedVT, LD->isVolatile(), |
| 629 | Alignment); |
| 630 | } |
| 631 | |
| 632 | // aggregate the two parts |
| 633 | SDOperand ShiftAmount = DAG.getConstant(NumBits, TLI.getShiftAmountTy()); |
| 634 | SDOperand Result = DAG.getNode(ISD::SHL, VT, Hi, ShiftAmount); |
| 635 | Result = DAG.getNode(ISD::OR, VT, Result, Lo); |
| 636 | |
| 637 | SDOperand TF = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1), |
| 638 | Hi.getValue(1)); |
| 639 | |
| 640 | SDOperand Ops[] = { Result, TF }; |
| 641 | return DAG.getNode(ISD::MERGE_VALUES, DAG.getVTList(VT, MVT::Other), Ops, 2); |
| 642 | } |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 643 | |
Dan Gohman | a346615 | 2007-07-13 20:14:11 +0000 | [diff] [blame] | 644 | /// LegalizeOp - We know that the specified value has a legal type, and |
| 645 | /// that its operands are legal. Now ensure that the operation itself |
| 646 | /// is legal, recursively ensuring that the operands' operations remain |
| 647 | /// legal. |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 648 | SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) { |
Chris Lattner | 09ec1b0 | 2007-08-25 01:00:22 +0000 | [diff] [blame] | 649 | if (Op.getOpcode() == ISD::TargetConstant) // Allow illegal target nodes. |
| 650 | return Op; |
| 651 | |
Chris Lattner | c9c60f6 | 2005-08-24 16:35:28 +0000 | [diff] [blame] | 652 | assert(isTypeLegal(Op.getValueType()) && |
Chris Lattner | e3304a3 | 2005-01-08 20:35:13 +0000 | [diff] [blame] | 653 | "Caller should expand or promote operands that are not legal!"); |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 654 | SDNode *Node = Op.Val; |
Chris Lattner | e3304a3 | 2005-01-08 20:35:13 +0000 | [diff] [blame] | 655 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 656 | // If this operation defines any values that cannot be represented in a |
Chris Lattner | e3304a3 | 2005-01-08 20:35:13 +0000 | [diff] [blame] | 657 | // register on this target, make sure to expand or promote them. |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 658 | if (Node->getNumValues() > 1) { |
| 659 | for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 660 | if (getTypeAction(Node->getValueType(i)) != Legal) { |
| 661 | HandleOp(Op.getValue(i)); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 662 | assert(LegalizedNodes.count(Op) && |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 663 | "Handling didn't add legal operands!"); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 664 | return LegalizedNodes[Op]; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 665 | } |
| 666 | } |
| 667 | |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 668 | // Note that LegalizeOp may be reentered even from single-use nodes, which |
| 669 | // means that we always must cache transformed nodes. |
Chris Lattner | 718071c | 2007-02-04 00:50:02 +0000 | [diff] [blame] | 670 | DenseMap<SDOperand, SDOperand>::iterator I = LegalizedNodes.find(Op); |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 671 | if (I != LegalizedNodes.end()) return I->second; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 672 | |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 673 | SDOperand Tmp1, Tmp2, Tmp3, Tmp4; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 674 | SDOperand Result = Op; |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 675 | bool isCustom = false; |
| 676 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 677 | switch (Node->getOpcode()) { |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 678 | case ISD::FrameIndex: |
| 679 | case ISD::EntryToken: |
| 680 | case ISD::Register: |
| 681 | case ISD::BasicBlock: |
| 682 | case ISD::TargetFrameIndex: |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 683 | case ISD::TargetJumpTable: |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 684 | case ISD::TargetConstant: |
Chris Lattner | 3181a77 | 2006-01-29 06:26:56 +0000 | [diff] [blame] | 685 | case ISD::TargetConstantFP: |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 686 | case ISD::TargetConstantPool: |
| 687 | case ISD::TargetGlobalAddress: |
Lauro Ramos Venancio | b3a0417 | 2007-04-20 21:38:10 +0000 | [diff] [blame] | 688 | case ISD::TargetGlobalTLSAddress: |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 689 | case ISD::TargetExternalSymbol: |
| 690 | case ISD::VALUETYPE: |
| 691 | case ISD::SRCVALUE: |
| 692 | case ISD::STRING: |
| 693 | case ISD::CONDCODE: |
| 694 | // Primitives must all be legal. |
| 695 | assert(TLI.isOperationLegal(Node->getValueType(0), Node->getValueType(0)) && |
| 696 | "This must be legal!"); |
| 697 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 698 | default: |
Chris Lattner | d73cc5d | 2005-05-14 06:34:48 +0000 | [diff] [blame] | 699 | if (Node->getOpcode() >= ISD::BUILTIN_OP_END) { |
| 700 | // If this is a target node, legalize it by legalizing the operands then |
| 701 | // passing it through. |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 702 | SmallVector<SDOperand, 8> Ops; |
Chris Lattner | c5d7d7c | 2006-05-17 18:00:08 +0000 | [diff] [blame] | 703 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) |
Chris Lattner | d73cc5d | 2005-05-14 06:34:48 +0000 | [diff] [blame] | 704 | Ops.push_back(LegalizeOp(Node->getOperand(i))); |
Chris Lattner | c5d7d7c | 2006-05-17 18:00:08 +0000 | [diff] [blame] | 705 | |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 706 | Result = DAG.UpdateNodeOperands(Result.getValue(0), &Ops[0], Ops.size()); |
Chris Lattner | d73cc5d | 2005-05-14 06:34:48 +0000 | [diff] [blame] | 707 | |
| 708 | for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) |
| 709 | AddLegalizedOperand(Op.getValue(i), Result.getValue(i)); |
| 710 | return Result.getValue(Op.ResNo); |
| 711 | } |
| 712 | // Otherwise this is an unhandled builtin node. splat. |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 713 | #ifndef NDEBUG |
Dan Gohman | 3983358 | 2007-06-04 16:17:33 +0000 | [diff] [blame] | 714 | cerr << "NODE: "; Node->dump(&DAG); cerr << "\n"; |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 715 | #endif |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 716 | assert(0 && "Do not know how to legalize this operator!"); |
| 717 | abort(); |
Lauro Ramos Venancio | 0d3b678 | 2007-04-20 23:02:39 +0000 | [diff] [blame] | 718 | case ISD::GLOBAL_OFFSET_TABLE: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 719 | case ISD::GlobalAddress: |
Lauro Ramos Venancio | b3a0417 | 2007-04-20 21:38:10 +0000 | [diff] [blame] | 720 | case ISD::GlobalTLSAddress: |
Chris Lattner | 03c0cf8 | 2005-01-07 21:45:56 +0000 | [diff] [blame] | 721 | case ISD::ExternalSymbol: |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 722 | case ISD::ConstantPool: |
| 723 | case ISD::JumpTable: // Nothing to do. |
Chris Lattner | 0c8fbe3 | 2005-11-17 06:41:44 +0000 | [diff] [blame] | 724 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 725 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 726 | case TargetLowering::Custom: |
| 727 | Tmp1 = TLI.LowerOperation(Op, DAG); |
| 728 | if (Tmp1.Val) Result = Tmp1; |
| 729 | // 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] | 730 | case TargetLowering::Legal: |
Chris Lattner | 0c8fbe3 | 2005-11-17 06:41:44 +0000 | [diff] [blame] | 731 | break; |
| 732 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 733 | break; |
Nate Begeman | bcc5f36 | 2007-01-29 22:58:52 +0000 | [diff] [blame] | 734 | case ISD::FRAMEADDR: |
| 735 | case ISD::RETURNADDR: |
| 736 | // The only option for these nodes is to custom lower them. If the target |
| 737 | // does not custom lower them, then return zero. |
| 738 | Tmp1 = TLI.LowerOperation(Op, DAG); |
| 739 | if (Tmp1.Val) |
| 740 | Result = Tmp1; |
| 741 | else |
| 742 | Result = DAG.getConstant(0, TLI.getPointerTy()); |
| 743 | break; |
Anton Korobeynikov | 055c544 | 2007-08-29 23:18:48 +0000 | [diff] [blame^] | 744 | case ISD::FRAME_TO_ARGS_OFFSET: { |
Anton Korobeynikov | 066f7b4 | 2007-08-29 19:28:29 +0000 | [diff] [blame] | 745 | MVT::ValueType VT = Node->getValueType(0); |
| 746 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 747 | default: assert(0 && "This action is not supported yet!"); |
| 748 | case TargetLowering::Custom: |
| 749 | Result = TLI.LowerOperation(Op, DAG); |
| 750 | if (Result.Val) break; |
| 751 | // Fall Thru |
| 752 | case TargetLowering::Legal: |
| 753 | Result = DAG.getConstant(0, VT); |
| 754 | break; |
| 755 | } |
Anton Korobeynikov | 055c544 | 2007-08-29 23:18:48 +0000 | [diff] [blame^] | 756 | } |
Anton Korobeynikov | 066f7b4 | 2007-08-29 19:28:29 +0000 | [diff] [blame] | 757 | break; |
Jim Laskey | 2bc210d | 2007-02-22 15:37:19 +0000 | [diff] [blame] | 758 | case ISD::EXCEPTIONADDR: { |
| 759 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 760 | MVT::ValueType VT = Node->getValueType(0); |
| 761 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 762 | default: assert(0 && "This action is not supported yet!"); |
| 763 | case TargetLowering::Expand: { |
Jim Laskey | 8782d48 | 2007-02-28 20:43:58 +0000 | [diff] [blame] | 764 | unsigned Reg = TLI.getExceptionAddressRegister(); |
Jim Laskey | 2bc210d | 2007-02-22 15:37:19 +0000 | [diff] [blame] | 765 | Result = DAG.getCopyFromReg(Tmp1, Reg, VT).getValue(Op.ResNo); |
| 766 | } |
| 767 | break; |
| 768 | case TargetLowering::Custom: |
| 769 | Result = TLI.LowerOperation(Op, DAG); |
| 770 | if (Result.Val) break; |
| 771 | // Fall Thru |
Chris Lattner | eb7f34f | 2007-04-27 17:12:52 +0000 | [diff] [blame] | 772 | case TargetLowering::Legal: { |
| 773 | SDOperand Ops[] = { DAG.getConstant(0, VT), Tmp1 }; |
| 774 | Result = DAG.getNode(ISD::MERGE_VALUES, DAG.getVTList(VT, MVT::Other), |
| 775 | Ops, 2).getValue(Op.ResNo); |
Jim Laskey | 2bc210d | 2007-02-22 15:37:19 +0000 | [diff] [blame] | 776 | break; |
| 777 | } |
| 778 | } |
Chris Lattner | eb7f34f | 2007-04-27 17:12:52 +0000 | [diff] [blame] | 779 | } |
Jim Laskey | 2bc210d | 2007-02-22 15:37:19 +0000 | [diff] [blame] | 780 | break; |
Jim Laskey | 8782d48 | 2007-02-28 20:43:58 +0000 | [diff] [blame] | 781 | case ISD::EHSELECTION: { |
| 782 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 783 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 784 | MVT::ValueType VT = Node->getValueType(0); |
| 785 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 786 | default: assert(0 && "This action is not supported yet!"); |
| 787 | case TargetLowering::Expand: { |
| 788 | unsigned Reg = TLI.getExceptionSelectorRegister(); |
| 789 | Result = DAG.getCopyFromReg(Tmp2, Reg, VT).getValue(Op.ResNo); |
| 790 | } |
| 791 | break; |
| 792 | case TargetLowering::Custom: |
| 793 | Result = TLI.LowerOperation(Op, DAG); |
| 794 | if (Result.Val) break; |
| 795 | // Fall Thru |
Chris Lattner | eb7f34f | 2007-04-27 17:12:52 +0000 | [diff] [blame] | 796 | case TargetLowering::Legal: { |
| 797 | SDOperand Ops[] = { DAG.getConstant(0, VT), Tmp2 }; |
| 798 | Result = DAG.getNode(ISD::MERGE_VALUES, DAG.getVTList(VT, MVT::Other), |
| 799 | Ops, 2).getValue(Op.ResNo); |
Jim Laskey | 8782d48 | 2007-02-28 20:43:58 +0000 | [diff] [blame] | 800 | break; |
| 801 | } |
| 802 | } |
Chris Lattner | eb7f34f | 2007-04-27 17:12:52 +0000 | [diff] [blame] | 803 | } |
Jim Laskey | 8782d48 | 2007-02-28 20:43:58 +0000 | [diff] [blame] | 804 | break; |
Nick Lewycky | 6d4b711 | 2007-07-14 15:11:14 +0000 | [diff] [blame] | 805 | case ISD::EH_RETURN: { |
Anton Korobeynikov | 2365f51 | 2007-07-14 14:06:15 +0000 | [diff] [blame] | 806 | MVT::ValueType VT = Node->getValueType(0); |
| 807 | // The only "good" option for this node is to custom lower it. |
| 808 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 809 | default: assert(0 && "This action is not supported at all!"); |
| 810 | case TargetLowering::Custom: |
| 811 | Result = TLI.LowerOperation(Op, DAG); |
| 812 | if (Result.Val) break; |
| 813 | // Fall Thru |
| 814 | case TargetLowering::Legal: |
| 815 | // Target does not know, how to lower this, lower to noop |
| 816 | Result = LegalizeOp(Node->getOperand(0)); |
| 817 | break; |
| 818 | } |
Nick Lewycky | 6d4b711 | 2007-07-14 15:11:14 +0000 | [diff] [blame] | 819 | } |
Anton Korobeynikov | 2365f51 | 2007-07-14 14:06:15 +0000 | [diff] [blame] | 820 | break; |
Chris Lattner | 08951a3 | 2005-09-02 01:15:01 +0000 | [diff] [blame] | 821 | case ISD::AssertSext: |
| 822 | case ISD::AssertZext: |
| 823 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 824 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
Chris Lattner | 08951a3 | 2005-09-02 01:15:01 +0000 | [diff] [blame] | 825 | break; |
Chris Lattner | 308575b | 2005-11-20 22:56:56 +0000 | [diff] [blame] | 826 | case ISD::MERGE_VALUES: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 827 | // Legalize eliminates MERGE_VALUES nodes. |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 828 | Result = Node->getOperand(Op.ResNo); |
| 829 | break; |
Chris Lattner | 69a5215 | 2005-01-14 22:38:01 +0000 | [diff] [blame] | 830 | case ISD::CopyFromReg: |
| 831 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 832 | Result = Op.getValue(0); |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 833 | if (Node->getNumValues() == 2) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 834 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 835 | } else { |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 836 | assert(Node->getNumValues() == 3 && "Invalid copyfromreg!"); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 837 | if (Node->getNumOperands() == 3) { |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 838 | Tmp2 = LegalizeOp(Node->getOperand(2)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 839 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1),Tmp2); |
| 840 | } else { |
| 841 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
| 842 | } |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 843 | AddLegalizedOperand(Op.getValue(2), Result.getValue(2)); |
| 844 | } |
Chris Lattner | 13c184d | 2005-01-28 06:27:38 +0000 | [diff] [blame] | 845 | // Since CopyFromReg produces two values, make sure to remember that we |
| 846 | // legalized both of them. |
| 847 | AddLegalizedOperand(Op.getValue(0), Result); |
| 848 | AddLegalizedOperand(Op.getValue(1), Result.getValue(1)); |
| 849 | return Result.getValue(Op.ResNo); |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 850 | case ISD::UNDEF: { |
| 851 | MVT::ValueType VT = Op.getValueType(); |
| 852 | switch (TLI.getOperationAction(ISD::UNDEF, VT)) { |
Nate Begeman | ea19cd5 | 2005-04-02 00:41:14 +0000 | [diff] [blame] | 853 | default: assert(0 && "This action is not supported yet!"); |
| 854 | case TargetLowering::Expand: |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 855 | if (MVT::isInteger(VT)) |
| 856 | Result = DAG.getConstant(0, VT); |
| 857 | else if (MVT::isFloatingPoint(VT)) |
| 858 | Result = DAG.getConstantFP(0, VT); |
| 859 | else |
| 860 | assert(0 && "Unknown value type!"); |
| 861 | break; |
Nate Begeman | ea19cd5 | 2005-04-02 00:41:14 +0000 | [diff] [blame] | 862 | case TargetLowering::Legal: |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 863 | break; |
| 864 | } |
| 865 | break; |
| 866 | } |
Chris Lattner | d1f04d4 | 2006-03-24 02:26:29 +0000 | [diff] [blame] | 867 | |
Chris Lattner | 48b61a7 | 2006-03-28 00:40:33 +0000 | [diff] [blame] | 868 | case ISD::INTRINSIC_W_CHAIN: |
| 869 | case ISD::INTRINSIC_WO_CHAIN: |
| 870 | case ISD::INTRINSIC_VOID: { |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 871 | SmallVector<SDOperand, 8> Ops; |
Chris Lattner | d1f04d4 | 2006-03-24 02:26:29 +0000 | [diff] [blame] | 872 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) |
| 873 | Ops.push_back(LegalizeOp(Node->getOperand(i))); |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 874 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 10d7fa6 | 2006-03-26 09:12:51 +0000 | [diff] [blame] | 875 | |
| 876 | // Allow the target to custom lower its intrinsics if it wants to. |
Chris Lattner | 48b61a7 | 2006-03-28 00:40:33 +0000 | [diff] [blame] | 877 | if (TLI.getOperationAction(Node->getOpcode(), MVT::Other) == |
Chris Lattner | 10d7fa6 | 2006-03-26 09:12:51 +0000 | [diff] [blame] | 878 | TargetLowering::Custom) { |
| 879 | Tmp3 = TLI.LowerOperation(Result, DAG); |
| 880 | if (Tmp3.Val) Result = Tmp3; |
Chris Lattner | 13fc2f1 | 2006-03-27 20:28:29 +0000 | [diff] [blame] | 881 | } |
| 882 | |
| 883 | if (Result.Val->getNumValues() == 1) break; |
| 884 | |
| 885 | // Must have return value and chain result. |
| 886 | assert(Result.Val->getNumValues() == 2 && |
| 887 | "Cannot return more than two values!"); |
| 888 | |
| 889 | // Since loads produce two values, make sure to remember that we |
| 890 | // legalized both of them. |
| 891 | AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0)); |
| 892 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
| 893 | return Result.getValue(Op.ResNo); |
Chris Lattner | d1f04d4 | 2006-03-24 02:26:29 +0000 | [diff] [blame] | 894 | } |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 895 | |
| 896 | case ISD::LOCATION: |
| 897 | assert(Node->getNumOperands() == 5 && "Invalid LOCATION node!"); |
| 898 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the input chain. |
| 899 | |
| 900 | switch (TLI.getOperationAction(ISD::LOCATION, MVT::Other)) { |
| 901 | case TargetLowering::Promote: |
| 902 | default: assert(0 && "This action is not supported yet!"); |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 903 | case TargetLowering::Expand: { |
Jim Laskey | 44c3b9f | 2007-01-26 21:22:28 +0000 | [diff] [blame] | 904 | MachineModuleInfo *MMI = DAG.getMachineModuleInfo(); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 905 | bool useDEBUG_LOC = TLI.isOperationLegal(ISD::DEBUG_LOC, MVT::Other); |
Jim Laskey | 1ee2925 | 2007-01-26 14:34:52 +0000 | [diff] [blame] | 906 | bool useLABEL = TLI.isOperationLegal(ISD::LABEL, MVT::Other); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 907 | |
Jim Laskey | 44c3b9f | 2007-01-26 21:22:28 +0000 | [diff] [blame] | 908 | if (MMI && (useDEBUG_LOC || useLABEL)) { |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 909 | const std::string &FName = |
| 910 | cast<StringSDNode>(Node->getOperand(3))->getValue(); |
| 911 | const std::string &DirName = |
| 912 | cast<StringSDNode>(Node->getOperand(4))->getValue(); |
Jim Laskey | 44c3b9f | 2007-01-26 21:22:28 +0000 | [diff] [blame] | 913 | unsigned SrcFile = MMI->RecordSource(DirName, FName); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 914 | |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 915 | SmallVector<SDOperand, 8> Ops; |
Jim Laskey | e81aecb | 2005-12-21 20:51:37 +0000 | [diff] [blame] | 916 | Ops.push_back(Tmp1); // chain |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 917 | SDOperand LineOp = Node->getOperand(1); |
| 918 | SDOperand ColOp = Node->getOperand(2); |
| 919 | |
| 920 | if (useDEBUG_LOC) { |
| 921 | Ops.push_back(LineOp); // line # |
| 922 | Ops.push_back(ColOp); // col # |
| 923 | Ops.push_back(DAG.getConstant(SrcFile, MVT::i32)); // source file id |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 924 | Result = DAG.getNode(ISD::DEBUG_LOC, MVT::Other, &Ops[0], Ops.size()); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 925 | } else { |
Jim Laskey | d0e58e3 | 2006-02-15 19:34:44 +0000 | [diff] [blame] | 926 | unsigned Line = cast<ConstantSDNode>(LineOp)->getValue(); |
| 927 | unsigned Col = cast<ConstantSDNode>(ColOp)->getValue(); |
Jim Laskey | 44c3b9f | 2007-01-26 21:22:28 +0000 | [diff] [blame] | 928 | unsigned ID = MMI->RecordLabel(Line, Col, SrcFile); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 929 | Ops.push_back(DAG.getConstant(ID, MVT::i32)); |
Jim Laskey | 1ee2925 | 2007-01-26 14:34:52 +0000 | [diff] [blame] | 930 | Result = DAG.getNode(ISD::LABEL, MVT::Other,&Ops[0],Ops.size()); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 931 | } |
Jim Laskey | e81aecb | 2005-12-21 20:51:37 +0000 | [diff] [blame] | 932 | } else { |
| 933 | Result = Tmp1; // chain |
| 934 | } |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 935 | break; |
Chris Lattner | e773673 | 2005-12-18 23:54:29 +0000 | [diff] [blame] | 936 | } |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 937 | case TargetLowering::Legal: |
Chris Lattner | 9ad17c9 | 2005-12-01 18:21:35 +0000 | [diff] [blame] | 938 | if (Tmp1 != Node->getOperand(0) || |
| 939 | getTypeAction(Node->getOperand(1).getValueType()) == Promote) { |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 940 | SmallVector<SDOperand, 8> Ops; |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 941 | Ops.push_back(Tmp1); |
Chris Lattner | 9ad17c9 | 2005-12-01 18:21:35 +0000 | [diff] [blame] | 942 | if (getTypeAction(Node->getOperand(1).getValueType()) == Legal) { |
| 943 | Ops.push_back(Node->getOperand(1)); // line # must be legal. |
| 944 | Ops.push_back(Node->getOperand(2)); // col # must be legal. |
| 945 | } else { |
| 946 | // Otherwise promote them. |
| 947 | Ops.push_back(PromoteOp(Node->getOperand(1))); |
| 948 | Ops.push_back(PromoteOp(Node->getOperand(2))); |
| 949 | } |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 950 | Ops.push_back(Node->getOperand(3)); // filename must be legal. |
| 951 | Ops.push_back(Node->getOperand(4)); // working dir # must be legal. |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 952 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 953 | } |
| 954 | break; |
| 955 | } |
| 956 | break; |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 957 | |
| 958 | case ISD::DEBUG_LOC: |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 959 | assert(Node->getNumOperands() == 4 && "Invalid DEBUG_LOC node!"); |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 960 | switch (TLI.getOperationAction(ISD::DEBUG_LOC, MVT::Other)) { |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 961 | default: assert(0 && "This action is not supported yet!"); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 962 | case TargetLowering::Legal: |
| 963 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 964 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the line #. |
| 965 | Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the col #. |
| 966 | Tmp4 = LegalizeOp(Node->getOperand(3)); // Legalize the source file id. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 967 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3, Tmp4); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 968 | break; |
| 969 | } |
| 970 | break; |
| 971 | |
Jim Laskey | 1ee2925 | 2007-01-26 14:34:52 +0000 | [diff] [blame] | 972 | case ISD::LABEL: |
| 973 | assert(Node->getNumOperands() == 2 && "Invalid LABEL node!"); |
| 974 | switch (TLI.getOperationAction(ISD::LABEL, MVT::Other)) { |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 975 | default: assert(0 && "This action is not supported yet!"); |
| 976 | case TargetLowering::Legal: |
| 977 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 978 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the label id. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 979 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 980 | break; |
Chris Lattner | a9569f1 | 2007-03-03 19:21:38 +0000 | [diff] [blame] | 981 | case TargetLowering::Expand: |
| 982 | Result = LegalizeOp(Node->getOperand(0)); |
| 983 | break; |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 984 | } |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 985 | break; |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 986 | |
Scott Michel | c1513d2 | 2007-08-08 23:23:31 +0000 | [diff] [blame] | 987 | case ISD::Constant: { |
| 988 | ConstantSDNode *CN = cast<ConstantSDNode>(Node); |
| 989 | unsigned opAction = |
| 990 | TLI.getOperationAction(ISD::Constant, CN->getValueType(0)); |
| 991 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 992 | // We know we don't need to expand constants here, constants only have one |
| 993 | // value and we check that it is fine above. |
| 994 | |
Scott Michel | c1513d2 | 2007-08-08 23:23:31 +0000 | [diff] [blame] | 995 | if (opAction == TargetLowering::Custom) { |
| 996 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 997 | if (Tmp1.Val) |
| 998 | Result = Tmp1; |
| 999 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1000 | break; |
Scott Michel | c1513d2 | 2007-08-08 23:23:31 +0000 | [diff] [blame] | 1001 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1002 | case ISD::ConstantFP: { |
| 1003 | // Spill FP immediates to the constant pool if the target cannot directly |
| 1004 | // codegen them. Targets often have some immediate values that can be |
| 1005 | // efficiently generated into an FP register without a load. We explicitly |
| 1006 | // leave these constants as ConstantFP nodes for the target to deal with. |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1007 | ConstantFPSDNode *CFP = cast<ConstantFPSDNode>(Node); |
| 1008 | |
| 1009 | // Check to see if this FP immediate is already legal. |
| 1010 | bool isLegal = false; |
| 1011 | for (TargetLowering::legal_fpimm_iterator I = TLI.legal_fpimm_begin(), |
| 1012 | E = TLI.legal_fpimm_end(); I != E; ++I) |
| 1013 | if (CFP->isExactlyValue(*I)) { |
| 1014 | isLegal = true; |
| 1015 | break; |
| 1016 | } |
| 1017 | |
Chris Lattner | 3181a77 | 2006-01-29 06:26:56 +0000 | [diff] [blame] | 1018 | // If this is a legal constant, turn it into a TargetConstantFP node. |
| 1019 | if (isLegal) { |
| 1020 | Result = DAG.getTargetConstantFP(CFP->getValue(), CFP->getValueType(0)); |
| 1021 | break; |
| 1022 | } |
| 1023 | |
| 1024 | switch (TLI.getOperationAction(ISD::ConstantFP, CFP->getValueType(0))) { |
| 1025 | default: assert(0 && "This action is not supported yet!"); |
| 1026 | case TargetLowering::Custom: |
| 1027 | Tmp3 = TLI.LowerOperation(Result, DAG); |
| 1028 | if (Tmp3.Val) { |
| 1029 | Result = Tmp3; |
| 1030 | break; |
| 1031 | } |
| 1032 | // FALLTHROUGH |
| 1033 | case TargetLowering::Expand: |
Evan Cheng | 279101e | 2006-12-12 22:19:28 +0000 | [diff] [blame] | 1034 | Result = ExpandConstantFP(CFP, true, DAG, TLI); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1035 | } |
| 1036 | break; |
| 1037 | } |
Chris Lattner | 040c11c | 2005-11-09 18:48:57 +0000 | [diff] [blame] | 1038 | case ISD::TokenFactor: |
| 1039 | if (Node->getNumOperands() == 2) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1040 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1041 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1042 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 1043 | } else if (Node->getNumOperands() == 3) { |
| 1044 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1045 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1046 | Tmp3 = LegalizeOp(Node->getOperand(2)); |
| 1047 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | 040c11c | 2005-11-09 18:48:57 +0000 | [diff] [blame] | 1048 | } else { |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1049 | SmallVector<SDOperand, 8> Ops; |
Chris Lattner | 040c11c | 2005-11-09 18:48:57 +0000 | [diff] [blame] | 1050 | // Legalize the operands. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1051 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) |
| 1052 | Ops.push_back(LegalizeOp(Node->getOperand(i))); |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1053 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | a385e9b | 2005-01-13 17:59:25 +0000 | [diff] [blame] | 1054 | } |
Chris Lattner | a385e9b | 2005-01-13 17:59:25 +0000 | [diff] [blame] | 1055 | break; |
Chris Lattner | fdfded5 | 2006-04-12 16:20:43 +0000 | [diff] [blame] | 1056 | |
| 1057 | case ISD::FORMAL_ARGUMENTS: |
Chris Lattner | f4ec817 | 2006-05-16 22:53:20 +0000 | [diff] [blame] | 1058 | case ISD::CALL: |
Chris Lattner | fdfded5 | 2006-04-12 16:20:43 +0000 | [diff] [blame] | 1059 | // The only option for this is to custom lower it. |
Chris Lattner | b248e16 | 2006-05-17 17:55:45 +0000 | [diff] [blame] | 1060 | Tmp3 = TLI.LowerOperation(Result.getValue(0), DAG); |
| 1061 | assert(Tmp3.Val && "Target didn't custom lower this node!"); |
| 1062 | assert(Tmp3.Val->getNumValues() == Result.Val->getNumValues() && |
| 1063 | "Lowering call/formal_arguments produced unexpected # results!"); |
Chris Lattner | e2e4173 | 2006-05-16 05:49:56 +0000 | [diff] [blame] | 1064 | |
Chris Lattner | f4ec817 | 2006-05-16 22:53:20 +0000 | [diff] [blame] | 1065 | // Since CALL/FORMAL_ARGUMENTS nodes produce multiple values, make sure to |
Chris Lattner | e2e4173 | 2006-05-16 05:49:56 +0000 | [diff] [blame] | 1066 | // 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] | 1067 | for (unsigned i = 0, e = Tmp3.Val->getNumValues(); i != e; ++i) { |
| 1068 | Tmp1 = LegalizeOp(Tmp3.getValue(i)); |
Chris Lattner | e2e4173 | 2006-05-16 05:49:56 +0000 | [diff] [blame] | 1069 | if (Op.ResNo == i) |
| 1070 | Tmp2 = Tmp1; |
| 1071 | AddLegalizedOperand(SDOperand(Node, i), Tmp1); |
| 1072 | } |
| 1073 | return Tmp2; |
Christopher Lamb | 557c363 | 2007-07-26 07:34:40 +0000 | [diff] [blame] | 1074 | case ISD::EXTRACT_SUBREG: { |
| 1075 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1076 | ConstantSDNode *idx = dyn_cast<ConstantSDNode>(Node->getOperand(1)); |
| 1077 | assert(idx && "Operand must be a constant"); |
| 1078 | Tmp2 = DAG.getTargetConstant(idx->getValue(), idx->getValueType(0)); |
| 1079 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 1080 | } |
| 1081 | break; |
| 1082 | case ISD::INSERT_SUBREG: { |
| 1083 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1084 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1085 | ConstantSDNode *idx = dyn_cast<ConstantSDNode>(Node->getOperand(2)); |
| 1086 | assert(idx && "Operand must be a constant"); |
| 1087 | Tmp3 = DAG.getTargetConstant(idx->getValue(), idx->getValueType(0)); |
| 1088 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
| 1089 | } |
| 1090 | break; |
Chris Lattner | b2827b0 | 2006-03-19 00:52:58 +0000 | [diff] [blame] | 1091 | case ISD::BUILD_VECTOR: |
| 1092 | switch (TLI.getOperationAction(ISD::BUILD_VECTOR, Node->getValueType(0))) { |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1093 | default: assert(0 && "This action is not supported yet!"); |
| 1094 | case TargetLowering::Custom: |
| 1095 | Tmp3 = TLI.LowerOperation(Result, DAG); |
| 1096 | if (Tmp3.Val) { |
| 1097 | Result = Tmp3; |
| 1098 | break; |
| 1099 | } |
| 1100 | // FALLTHROUGH |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 1101 | case TargetLowering::Expand: |
| 1102 | Result = ExpandBUILD_VECTOR(Result.Val); |
Chris Lattner | b2827b0 | 2006-03-19 00:52:58 +0000 | [diff] [blame] | 1103 | break; |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1104 | } |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1105 | break; |
| 1106 | case ISD::INSERT_VECTOR_ELT: |
| 1107 | Tmp1 = LegalizeOp(Node->getOperand(0)); // InVec |
| 1108 | Tmp2 = LegalizeOp(Node->getOperand(1)); // InVal |
| 1109 | Tmp3 = LegalizeOp(Node->getOperand(2)); // InEltNo |
| 1110 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
| 1111 | |
| 1112 | switch (TLI.getOperationAction(ISD::INSERT_VECTOR_ELT, |
| 1113 | Node->getValueType(0))) { |
| 1114 | default: assert(0 && "This action is not supported yet!"); |
| 1115 | case TargetLowering::Legal: |
| 1116 | break; |
| 1117 | case TargetLowering::Custom: |
| 1118 | Tmp3 = TLI.LowerOperation(Result, DAG); |
| 1119 | if (Tmp3.Val) { |
| 1120 | Result = Tmp3; |
| 1121 | break; |
| 1122 | } |
| 1123 | // FALLTHROUGH |
| 1124 | case TargetLowering::Expand: { |
Chris Lattner | 8d5a894 | 2006-04-17 19:21:01 +0000 | [diff] [blame] | 1125 | // If the insert index is a constant, codegen this as a scalar_to_vector, |
| 1126 | // then a shuffle that inserts it into the right position in the vector. |
| 1127 | if (ConstantSDNode *InsertPos = dyn_cast<ConstantSDNode>(Tmp3)) { |
| 1128 | SDOperand ScVec = DAG.getNode(ISD::SCALAR_TO_VECTOR, |
| 1129 | Tmp1.getValueType(), Tmp2); |
| 1130 | |
| 1131 | unsigned NumElts = MVT::getVectorNumElements(Tmp1.getValueType()); |
| 1132 | MVT::ValueType ShufMaskVT = MVT::getIntVectorWithNumElements(NumElts); |
Dan Gohman | 51eaa86 | 2007-06-14 22:58:02 +0000 | [diff] [blame] | 1133 | MVT::ValueType ShufMaskEltVT = MVT::getVectorElementType(ShufMaskVT); |
Chris Lattner | 8d5a894 | 2006-04-17 19:21:01 +0000 | [diff] [blame] | 1134 | |
| 1135 | // We generate a shuffle of InVec and ScVec, so the shuffle mask should |
| 1136 | // be 0,1,2,3,4,5... with the appropriate element replaced with elt 0 of |
| 1137 | // the RHS. |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 1138 | SmallVector<SDOperand, 8> ShufOps; |
Chris Lattner | 8d5a894 | 2006-04-17 19:21:01 +0000 | [diff] [blame] | 1139 | for (unsigned i = 0; i != NumElts; ++i) { |
| 1140 | if (i != InsertPos->getValue()) |
| 1141 | ShufOps.push_back(DAG.getConstant(i, ShufMaskEltVT)); |
| 1142 | else |
| 1143 | ShufOps.push_back(DAG.getConstant(NumElts, ShufMaskEltVT)); |
| 1144 | } |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 1145 | SDOperand ShufMask = DAG.getNode(ISD::BUILD_VECTOR, ShufMaskVT, |
| 1146 | &ShufOps[0], ShufOps.size()); |
Chris Lattner | 8d5a894 | 2006-04-17 19:21:01 +0000 | [diff] [blame] | 1147 | |
| 1148 | Result = DAG.getNode(ISD::VECTOR_SHUFFLE, Tmp1.getValueType(), |
| 1149 | Tmp1, ScVec, ShufMask); |
| 1150 | Result = LegalizeOp(Result); |
| 1151 | break; |
| 1152 | } |
| 1153 | |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1154 | // If the target doesn't support this, we have to spill the input vector |
| 1155 | // to a temporary stack slot, update the element, then reload it. This is |
| 1156 | // badness. We could also load the value into a vector register (either |
| 1157 | // with a "move to register" or "extload into register" instruction, then |
| 1158 | // permute it into place, if the idx is a constant and if the idx is |
| 1159 | // supported by the target. |
Evan Cheng | f6bf87f | 2006-04-08 01:46:37 +0000 | [diff] [blame] | 1160 | MVT::ValueType VT = Tmp1.getValueType(); |
| 1161 | MVT::ValueType EltVT = Tmp2.getValueType(); |
| 1162 | MVT::ValueType IdxVT = Tmp3.getValueType(); |
| 1163 | MVT::ValueType PtrVT = TLI.getPointerTy(); |
| 1164 | SDOperand StackPtr = CreateStackTemporary(VT); |
Evan Cheng | eb0b461 | 2006-03-31 01:27:51 +0000 | [diff] [blame] | 1165 | // Store the vector. |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 1166 | SDOperand Ch = DAG.getStore(DAG.getEntryNode(), Tmp1, StackPtr, NULL, 0); |
Evan Cheng | eb0b461 | 2006-03-31 01:27:51 +0000 | [diff] [blame] | 1167 | |
| 1168 | // Truncate or zero extend offset to target pointer type. |
Evan Cheng | f6bf87f | 2006-04-08 01:46:37 +0000 | [diff] [blame] | 1169 | unsigned CastOpc = (IdxVT > PtrVT) ? ISD::TRUNCATE : ISD::ZERO_EXTEND; |
| 1170 | Tmp3 = DAG.getNode(CastOpc, PtrVT, Tmp3); |
Evan Cheng | eb0b461 | 2006-03-31 01:27:51 +0000 | [diff] [blame] | 1171 | // Add the offset to the index. |
Evan Cheng | f6bf87f | 2006-04-08 01:46:37 +0000 | [diff] [blame] | 1172 | unsigned EltSize = MVT::getSizeInBits(EltVT)/8; |
| 1173 | Tmp3 = DAG.getNode(ISD::MUL, IdxVT, Tmp3,DAG.getConstant(EltSize, IdxVT)); |
| 1174 | SDOperand StackPtr2 = DAG.getNode(ISD::ADD, IdxVT, Tmp3, StackPtr); |
Evan Cheng | eb0b461 | 2006-03-31 01:27:51 +0000 | [diff] [blame] | 1175 | // Store the scalar value. |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 1176 | Ch = DAG.getStore(Ch, Tmp2, StackPtr2, NULL, 0); |
Evan Cheng | eb0b461 | 2006-03-31 01:27:51 +0000 | [diff] [blame] | 1177 | // Load the updated vector. |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1178 | Result = DAG.getLoad(VT, Ch, StackPtr, NULL, 0); |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1179 | break; |
| 1180 | } |
| 1181 | } |
| 1182 | break; |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 1183 | case ISD::SCALAR_TO_VECTOR: |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 1184 | if (!TLI.isTypeLegal(Node->getOperand(0).getValueType())) { |
| 1185 | Result = LegalizeOp(ExpandSCALAR_TO_VECTOR(Node)); |
| 1186 | break; |
| 1187 | } |
| 1188 | |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 1189 | Tmp1 = LegalizeOp(Node->getOperand(0)); // InVal |
| 1190 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 1191 | switch (TLI.getOperationAction(ISD::SCALAR_TO_VECTOR, |
| 1192 | Node->getValueType(0))) { |
| 1193 | default: assert(0 && "This action is not supported yet!"); |
| 1194 | case TargetLowering::Legal: |
| 1195 | break; |
Chris Lattner | 4d3abee | 2006-03-19 06:47:21 +0000 | [diff] [blame] | 1196 | case TargetLowering::Custom: |
| 1197 | Tmp3 = TLI.LowerOperation(Result, DAG); |
| 1198 | if (Tmp3.Val) { |
| 1199 | Result = Tmp3; |
| 1200 | break; |
| 1201 | } |
| 1202 | // FALLTHROUGH |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 1203 | case TargetLowering::Expand: |
| 1204 | Result = LegalizeOp(ExpandSCALAR_TO_VECTOR(Node)); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 1205 | break; |
| 1206 | } |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 1207 | break; |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 1208 | case ISD::VECTOR_SHUFFLE: |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 1209 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the input vectors, |
| 1210 | Tmp2 = LegalizeOp(Node->getOperand(1)); // but not the shuffle mask. |
| 1211 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
| 1212 | |
| 1213 | // Allow targets to custom lower the SHUFFLEs they support. |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 1214 | switch (TLI.getOperationAction(ISD::VECTOR_SHUFFLE,Result.getValueType())) { |
| 1215 | default: assert(0 && "Unknown operation action!"); |
| 1216 | case TargetLowering::Legal: |
| 1217 | assert(isShuffleLegal(Result.getValueType(), Node->getOperand(2)) && |
| 1218 | "vector shuffle should not be created if not legal!"); |
| 1219 | break; |
| 1220 | case TargetLowering::Custom: |
Evan Cheng | 18dd6d0 | 2006-04-05 06:07:11 +0000 | [diff] [blame] | 1221 | Tmp3 = TLI.LowerOperation(Result, DAG); |
| 1222 | if (Tmp3.Val) { |
| 1223 | Result = Tmp3; |
| 1224 | break; |
| 1225 | } |
| 1226 | // FALLTHROUGH |
| 1227 | case TargetLowering::Expand: { |
| 1228 | MVT::ValueType VT = Node->getValueType(0); |
Dan Gohman | 51eaa86 | 2007-06-14 22:58:02 +0000 | [diff] [blame] | 1229 | MVT::ValueType EltVT = MVT::getVectorElementType(VT); |
Evan Cheng | 18dd6d0 | 2006-04-05 06:07:11 +0000 | [diff] [blame] | 1230 | MVT::ValueType PtrVT = TLI.getPointerTy(); |
| 1231 | SDOperand Mask = Node->getOperand(2); |
| 1232 | unsigned NumElems = Mask.getNumOperands(); |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 1233 | SmallVector<SDOperand,8> Ops; |
Evan Cheng | 18dd6d0 | 2006-04-05 06:07:11 +0000 | [diff] [blame] | 1234 | for (unsigned i = 0; i != NumElems; ++i) { |
| 1235 | SDOperand Arg = Mask.getOperand(i); |
| 1236 | if (Arg.getOpcode() == ISD::UNDEF) { |
| 1237 | Ops.push_back(DAG.getNode(ISD::UNDEF, EltVT)); |
| 1238 | } else { |
| 1239 | assert(isa<ConstantSDNode>(Arg) && "Invalid VECTOR_SHUFFLE mask!"); |
| 1240 | unsigned Idx = cast<ConstantSDNode>(Arg)->getValue(); |
| 1241 | if (Idx < NumElems) |
| 1242 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, EltVT, Tmp1, |
| 1243 | DAG.getConstant(Idx, PtrVT))); |
| 1244 | else |
| 1245 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, EltVT, Tmp2, |
| 1246 | DAG.getConstant(Idx - NumElems, PtrVT))); |
| 1247 | } |
| 1248 | } |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 1249 | Result = DAG.getNode(ISD::BUILD_VECTOR, VT, &Ops[0], Ops.size()); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 1250 | break; |
Evan Cheng | 18dd6d0 | 2006-04-05 06:07:11 +0000 | [diff] [blame] | 1251 | } |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 1252 | case TargetLowering::Promote: { |
| 1253 | // Change base type to a different vector type. |
| 1254 | MVT::ValueType OVT = Node->getValueType(0); |
| 1255 | MVT::ValueType NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT); |
| 1256 | |
| 1257 | // Cast the two input vectors. |
| 1258 | Tmp1 = DAG.getNode(ISD::BIT_CONVERT, NVT, Tmp1); |
| 1259 | Tmp2 = DAG.getNode(ISD::BIT_CONVERT, NVT, Tmp2); |
| 1260 | |
| 1261 | // Convert the shuffle mask to the right # elements. |
| 1262 | Tmp3 = SDOperand(isShuffleLegal(OVT, Node->getOperand(2)), 0); |
| 1263 | assert(Tmp3.Val && "Shuffle not legal?"); |
| 1264 | Result = DAG.getNode(ISD::VECTOR_SHUFFLE, NVT, Tmp1, Tmp2, Tmp3); |
| 1265 | Result = DAG.getNode(ISD::BIT_CONVERT, OVT, Result); |
| 1266 | break; |
| 1267 | } |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 1268 | } |
| 1269 | break; |
Chris Lattner | 384504c | 2006-03-21 20:44:12 +0000 | [diff] [blame] | 1270 | |
| 1271 | case ISD::EXTRACT_VECTOR_ELT: |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 1272 | Tmp1 = Node->getOperand(0); |
Chris Lattner | 384504c | 2006-03-21 20:44:12 +0000 | [diff] [blame] | 1273 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1274 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 1275 | Result = ExpandEXTRACT_VECTOR_ELT(Result); |
Chris Lattner | 384504c | 2006-03-21 20:44:12 +0000 | [diff] [blame] | 1276 | break; |
| 1277 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 1278 | case ISD::EXTRACT_SUBVECTOR: |
| 1279 | Tmp1 = Node->getOperand(0); |
| 1280 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1281 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 1282 | Result = ExpandEXTRACT_SUBVECTOR(Result); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 1283 | break; |
| 1284 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1285 | case ISD::CALLSEQ_START: { |
| 1286 | SDNode *CallEnd = FindCallEndFromCallStart(Node); |
| 1287 | |
| 1288 | // Recursively Legalize all of the inputs of the call end that do not lead |
| 1289 | // to this call start. This ensures that any libcalls that need be inserted |
| 1290 | // are inserted *before* the CALLSEQ_START. |
Chris Lattner | 00755df | 2007-02-04 00:27:56 +0000 | [diff] [blame] | 1291 | {SmallPtrSet<SDNode*, 32> NodesLeadingTo; |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1292 | for (unsigned i = 0, e = CallEnd->getNumOperands(); i != e; ++i) |
Chris Lattner | c9cf4f1 | 2006-07-26 23:55:56 +0000 | [diff] [blame] | 1293 | LegalizeAllNodesNotLeadingTo(CallEnd->getOperand(i).Val, Node, |
| 1294 | NodesLeadingTo); |
| 1295 | } |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1296 | |
| 1297 | // Now that we legalized all of the inputs (which may have inserted |
| 1298 | // libcalls) create the new CALLSEQ_START node. |
| 1299 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1300 | |
| 1301 | // Merge in the last call, to ensure that this call start after the last |
| 1302 | // call ended. |
Chris Lattner | c5d7d7c | 2006-05-17 18:00:08 +0000 | [diff] [blame] | 1303 | if (LastCALLSEQ_END.getOpcode() != ISD::EntryToken) { |
Chris Lattner | b248e16 | 2006-05-17 17:55:45 +0000 | [diff] [blame] | 1304 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1305 | Tmp1 = LegalizeOp(Tmp1); |
| 1306 | } |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1307 | |
| 1308 | // Do not try to legalize the target-specific arguments (#1+). |
| 1309 | if (Tmp1 != Node->getOperand(0)) { |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1310 | SmallVector<SDOperand, 8> Ops(Node->op_begin(), Node->op_end()); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1311 | Ops[0] = Tmp1; |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1312 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1313 | } |
| 1314 | |
| 1315 | // Remember that the CALLSEQ_START is legalized. |
Chris Lattner | 4b653a0 | 2006-02-14 00:55:02 +0000 | [diff] [blame] | 1316 | AddLegalizedOperand(Op.getValue(0), Result); |
| 1317 | if (Node->getNumValues() == 2) // If this has a flag result, remember it. |
| 1318 | AddLegalizedOperand(Op.getValue(1), Result.getValue(1)); |
| 1319 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1320 | // Now that the callseq_start and all of the non-call nodes above this call |
| 1321 | // sequence have been legalized, legalize the call itself. During this |
| 1322 | // process, no libcalls can/will be inserted, guaranteeing that no calls |
| 1323 | // can overlap. |
| 1324 | assert(!IsLegalizingCall && "Inconsistent sequentialization of calls!"); |
| 1325 | SDOperand InCallSEQ = LastCALLSEQ_END; |
| 1326 | // Note that we are selecting this call! |
| 1327 | LastCALLSEQ_END = SDOperand(CallEnd, 0); |
| 1328 | IsLegalizingCall = true; |
| 1329 | |
| 1330 | // Legalize the call, starting from the CALLSEQ_END. |
| 1331 | LegalizeOp(LastCALLSEQ_END); |
| 1332 | assert(!IsLegalizingCall && "CALLSEQ_END should have cleared this!"); |
| 1333 | return Result; |
| 1334 | } |
Chris Lattner | 16cd04d | 2005-05-12 23:24:06 +0000 | [diff] [blame] | 1335 | case ISD::CALLSEQ_END: |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1336 | // If the CALLSEQ_START node hasn't been legalized first, legalize it. This |
| 1337 | // will cause this node to be legalized as well as handling libcalls right. |
| 1338 | if (LastCALLSEQ_END.Val != Node) { |
| 1339 | LegalizeOp(SDOperand(FindCallStartFromCallEnd(Node), 0)); |
Chris Lattner | 718071c | 2007-02-04 00:50:02 +0000 | [diff] [blame] | 1340 | DenseMap<SDOperand, SDOperand>::iterator I = LegalizedNodes.find(Op); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1341 | assert(I != LegalizedNodes.end() && |
| 1342 | "Legalizing the call start should have legalized this node!"); |
| 1343 | return I->second; |
| 1344 | } |
| 1345 | |
| 1346 | // Otherwise, the call start has been legalized and everything is going |
| 1347 | // according to plan. Just legalize ourselves normally here. |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1348 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | 70814bc | 2006-01-29 07:58:15 +0000 | [diff] [blame] | 1349 | // Do not try to legalize the target-specific arguments (#1+), except for |
| 1350 | // an optional flag input. |
| 1351 | if (Node->getOperand(Node->getNumOperands()-1).getValueType() != MVT::Flag){ |
| 1352 | if (Tmp1 != Node->getOperand(0)) { |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1353 | SmallVector<SDOperand, 8> Ops(Node->op_begin(), Node->op_end()); |
Chris Lattner | 70814bc | 2006-01-29 07:58:15 +0000 | [diff] [blame] | 1354 | Ops[0] = Tmp1; |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1355 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 70814bc | 2006-01-29 07:58:15 +0000 | [diff] [blame] | 1356 | } |
| 1357 | } else { |
| 1358 | Tmp2 = LegalizeOp(Node->getOperand(Node->getNumOperands()-1)); |
| 1359 | if (Tmp1 != Node->getOperand(0) || |
| 1360 | Tmp2 != Node->getOperand(Node->getNumOperands()-1)) { |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1361 | SmallVector<SDOperand, 8> Ops(Node->op_begin(), Node->op_end()); |
Chris Lattner | 70814bc | 2006-01-29 07:58:15 +0000 | [diff] [blame] | 1362 | Ops[0] = Tmp1; |
| 1363 | Ops.back() = Tmp2; |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1364 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 70814bc | 2006-01-29 07:58:15 +0000 | [diff] [blame] | 1365 | } |
Chris Lattner | 6a54289 | 2006-01-24 05:48:21 +0000 | [diff] [blame] | 1366 | } |
Chris Lattner | 4b653a0 | 2006-02-14 00:55:02 +0000 | [diff] [blame] | 1367 | assert(IsLegalizingCall && "Call sequence imbalance between start/end?"); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1368 | // This finishes up call legalization. |
| 1369 | IsLegalizingCall = false; |
Chris Lattner | 4b653a0 | 2006-02-14 00:55:02 +0000 | [diff] [blame] | 1370 | |
| 1371 | // If the CALLSEQ_END node has a flag, remember that we legalized it. |
| 1372 | AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0)); |
| 1373 | if (Node->getNumValues() == 2) |
| 1374 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
| 1375 | return Result.getValue(Op.ResNo); |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1376 | case ISD::DYNAMIC_STACKALLOC: { |
Evan Cheng | 61bbbab | 2007-08-16 23:50:06 +0000 | [diff] [blame] | 1377 | MVT::ValueType VT = Node->getValueType(0); |
Chris Lattner | fa404e8 | 2005-01-09 19:03:49 +0000 | [diff] [blame] | 1378 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1379 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the size. |
| 1380 | Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the alignment. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1381 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | fa404e8 | 2005-01-09 19:03:49 +0000 | [diff] [blame] | 1382 | |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1383 | Tmp1 = Result.getValue(0); |
Chris Lattner | 5f65229 | 2006-01-15 08:43:08 +0000 | [diff] [blame] | 1384 | Tmp2 = Result.getValue(1); |
Evan Cheng | 61bbbab | 2007-08-16 23:50:06 +0000 | [diff] [blame] | 1385 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1386 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1387 | case TargetLowering::Expand: { |
| 1388 | unsigned SPReg = TLI.getStackPointerRegisterToSaveRestore(); |
| 1389 | assert(SPReg && "Target cannot require DYNAMIC_STACKALLOC expansion and" |
| 1390 | " not tell us which reg is the stack pointer!"); |
| 1391 | SDOperand Chain = Tmp1.getOperand(0); |
| 1392 | SDOperand Size = Tmp2.getOperand(1); |
Evan Cheng | 61bbbab | 2007-08-16 23:50:06 +0000 | [diff] [blame] | 1393 | SDOperand SP = DAG.getCopyFromReg(Chain, SPReg, VT); |
| 1394 | Chain = SP.getValue(1); |
| 1395 | unsigned Align = cast<ConstantSDNode>(Tmp3)->getValue(); |
| 1396 | unsigned StackAlign = |
| 1397 | TLI.getTargetMachine().getFrameInfo()->getStackAlignment(); |
| 1398 | if (Align > StackAlign) |
Evan Cheng | 3e20bba | 2007-08-17 18:02:22 +0000 | [diff] [blame] | 1399 | SP = DAG.getNode(ISD::AND, VT, SP, |
| 1400 | DAG.getConstant(-(uint64_t)Align, VT)); |
Evan Cheng | 61bbbab | 2007-08-16 23:50:06 +0000 | [diff] [blame] | 1401 | Tmp1 = DAG.getNode(ISD::SUB, VT, SP, Size); // Value |
| 1402 | Tmp2 = DAG.getCopyToReg(Chain, SPReg, Tmp1); // Output chain |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1403 | Tmp1 = LegalizeOp(Tmp1); |
| 1404 | Tmp2 = LegalizeOp(Tmp2); |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1405 | break; |
| 1406 | } |
| 1407 | case TargetLowering::Custom: |
Chris Lattner | 5f65229 | 2006-01-15 08:43:08 +0000 | [diff] [blame] | 1408 | Tmp3 = TLI.LowerOperation(Tmp1, DAG); |
| 1409 | if (Tmp3.Val) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1410 | Tmp1 = LegalizeOp(Tmp3); |
| 1411 | Tmp2 = LegalizeOp(Tmp3.getValue(1)); |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1412 | } |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1413 | break; |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1414 | case TargetLowering::Legal: |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1415 | break; |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1416 | } |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1417 | // Since this op produce two values, make sure to remember that we |
| 1418 | // legalized both of them. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1419 | AddLegalizedOperand(SDOperand(Node, 0), Tmp1); |
| 1420 | AddLegalizedOperand(SDOperand(Node, 1), Tmp2); |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1421 | return Op.ResNo ? Tmp2 : Tmp1; |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1422 | } |
Chris Lattner | 25a022c | 2006-07-11 01:40:09 +0000 | [diff] [blame] | 1423 | case ISD::INLINEASM: { |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1424 | SmallVector<SDOperand, 8> Ops(Node->op_begin(), Node->op_end()); |
Chris Lattner | 25a022c | 2006-07-11 01:40:09 +0000 | [diff] [blame] | 1425 | bool Changed = false; |
| 1426 | // Legalize all of the operands of the inline asm, in case they are nodes |
| 1427 | // that need to be expanded or something. Note we skip the asm string and |
| 1428 | // all of the TargetConstant flags. |
| 1429 | SDOperand Op = LegalizeOp(Ops[0]); |
| 1430 | Changed = Op != Ops[0]; |
| 1431 | Ops[0] = Op; |
| 1432 | |
| 1433 | bool HasInFlag = Ops.back().getValueType() == MVT::Flag; |
| 1434 | for (unsigned i = 2, e = Ops.size()-HasInFlag; i < e; ) { |
| 1435 | unsigned NumVals = cast<ConstantSDNode>(Ops[i])->getValue() >> 3; |
| 1436 | for (++i; NumVals; ++i, --NumVals) { |
| 1437 | SDOperand Op = LegalizeOp(Ops[i]); |
| 1438 | if (Op != Ops[i]) { |
| 1439 | Changed = true; |
| 1440 | Ops[i] = Op; |
| 1441 | } |
| 1442 | } |
Chris Lattner | ce7518c | 2006-01-26 22:24:51 +0000 | [diff] [blame] | 1443 | } |
Chris Lattner | 25a022c | 2006-07-11 01:40:09 +0000 | [diff] [blame] | 1444 | |
| 1445 | if (HasInFlag) { |
| 1446 | Op = LegalizeOp(Ops.back()); |
| 1447 | Changed |= Op != Ops.back(); |
| 1448 | Ops.back() = Op; |
| 1449 | } |
| 1450 | |
| 1451 | if (Changed) |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1452 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | ce7518c | 2006-01-26 22:24:51 +0000 | [diff] [blame] | 1453 | |
| 1454 | // 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] | 1455 | AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0)); |
Chris Lattner | ce7518c | 2006-01-26 22:24:51 +0000 | [diff] [blame] | 1456 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
| 1457 | return Result.getValue(Op.ResNo); |
Chris Lattner | 25a022c | 2006-07-11 01:40:09 +0000 | [diff] [blame] | 1458 | } |
Chris Lattner | c7af179 | 2005-01-07 22:12:08 +0000 | [diff] [blame] | 1459 | case ISD::BR: |
| 1460 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1461 | // Ensure that libcalls are emitted before a branch. |
| 1462 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1463 | Tmp1 = LegalizeOp(Tmp1); |
| 1464 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 1465 | |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1466 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
Chris Lattner | c7af179 | 2005-01-07 22:12:08 +0000 | [diff] [blame] | 1467 | break; |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 1468 | case ISD::BRIND: |
| 1469 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1470 | // Ensure that libcalls are emitted before a branch. |
| 1471 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1472 | Tmp1 = LegalizeOp(Tmp1); |
| 1473 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 1474 | |
| 1475 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 1476 | default: assert(0 && "Indirect target must be legal type (pointer)!"); |
| 1477 | case Legal: |
| 1478 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the condition. |
| 1479 | break; |
| 1480 | } |
| 1481 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 1482 | break; |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 1483 | case ISD::BR_JT: |
| 1484 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1485 | // Ensure that libcalls are emitted before a branch. |
| 1486 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1487 | Tmp1 = LegalizeOp(Tmp1); |
| 1488 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 1489 | |
| 1490 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the jumptable node. |
| 1491 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
| 1492 | |
| 1493 | switch (TLI.getOperationAction(ISD::BR_JT, MVT::Other)) { |
| 1494 | default: assert(0 && "This action is not supported yet!"); |
| 1495 | case TargetLowering::Legal: break; |
| 1496 | case TargetLowering::Custom: |
| 1497 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 1498 | if (Tmp1.Val) Result = Tmp1; |
| 1499 | break; |
| 1500 | case TargetLowering::Expand: { |
| 1501 | SDOperand Chain = Result.getOperand(0); |
| 1502 | SDOperand Table = Result.getOperand(1); |
| 1503 | SDOperand Index = Result.getOperand(2); |
| 1504 | |
| 1505 | MVT::ValueType PTy = TLI.getPointerTy(); |
Jim Laskey | acd80ac | 2006-12-14 19:17:33 +0000 | [diff] [blame] | 1506 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1507 | unsigned EntrySize = MF.getJumpTableInfo()->getEntrySize(); |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 1508 | Index= DAG.getNode(ISD::MUL, PTy, Index, DAG.getConstant(EntrySize, PTy)); |
| 1509 | SDOperand Addr = DAG.getNode(ISD::ADD, PTy, Index, Table); |
Jim Laskey | acd80ac | 2006-12-14 19:17:33 +0000 | [diff] [blame] | 1510 | |
| 1511 | SDOperand LD; |
| 1512 | switch (EntrySize) { |
| 1513 | default: assert(0 && "Size of jump table not supported yet."); break; |
| 1514 | case 4: LD = DAG.getLoad(MVT::i32, Chain, Addr, NULL, 0); break; |
| 1515 | case 8: LD = DAG.getLoad(MVT::i64, Chain, Addr, NULL, 0); break; |
| 1516 | } |
| 1517 | |
| 1518 | if (TLI.getTargetMachine().getRelocationModel() == Reloc::PIC_) { |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 1519 | // For PIC, the sequence is: |
| 1520 | // BRIND(load(Jumptable + index) + RelocBase) |
| 1521 | // RelocBase is the JumpTable on PPC and X86, GOT on Alpha |
| 1522 | SDOperand Reloc; |
| 1523 | if (TLI.usesGlobalOffsetTable()) |
| 1524 | Reloc = DAG.getNode(ISD::GLOBAL_OFFSET_TABLE, PTy); |
| 1525 | else |
| 1526 | Reloc = Table; |
Evan Cheng | d063189 | 2006-10-31 02:31:00 +0000 | [diff] [blame] | 1527 | Addr = (PTy != MVT::i32) ? DAG.getNode(ISD::SIGN_EXTEND, PTy, LD) : LD; |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 1528 | Addr = DAG.getNode(ISD::ADD, PTy, Addr, Reloc); |
| 1529 | Result = DAG.getNode(ISD::BRIND, MVT::Other, LD.getValue(1), Addr); |
| 1530 | } else { |
| 1531 | Result = DAG.getNode(ISD::BRIND, MVT::Other, LD.getValue(1), LD); |
| 1532 | } |
| 1533 | } |
| 1534 | } |
| 1535 | break; |
Chris Lattner | c18ae4c | 2005-01-07 08:19:42 +0000 | [diff] [blame] | 1536 | case ISD::BRCOND: |
| 1537 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1538 | // Ensure that libcalls are emitted before a return. |
| 1539 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1540 | Tmp1 = LegalizeOp(Tmp1); |
| 1541 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 1542 | |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 1543 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 1544 | case Expand: assert(0 && "It's impossible to expand bools"); |
| 1545 | case Legal: |
| 1546 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the condition. |
| 1547 | break; |
| 1548 | case Promote: |
| 1549 | Tmp2 = PromoteOp(Node->getOperand(1)); // Promote the condition. |
Chris Lattner | f990817 | 2006-11-27 04:39:56 +0000 | [diff] [blame] | 1550 | |
| 1551 | // The top bits of the promoted condition are not necessarily zero, ensure |
| 1552 | // that the value is properly zero extended. |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1553 | if (!DAG.MaskedValueIsZero(Tmp2, |
Chris Lattner | f990817 | 2006-11-27 04:39:56 +0000 | [diff] [blame] | 1554 | MVT::getIntVTBitMask(Tmp2.getValueType())^1)) |
| 1555 | Tmp2 = DAG.getZeroExtendInReg(Tmp2, MVT::i1); |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 1556 | break; |
| 1557 | } |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 1558 | |
| 1559 | // Basic block destination (Op#2) is always legal. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1560 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 1561 | |
| 1562 | switch (TLI.getOperationAction(ISD::BRCOND, MVT::Other)) { |
| 1563 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 1564 | case TargetLowering::Legal: break; |
| 1565 | case TargetLowering::Custom: |
| 1566 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 1567 | if (Tmp1.Val) Result = Tmp1; |
| 1568 | break; |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 1569 | case TargetLowering::Expand: |
| 1570 | // Expand brcond's setcc into its constituent parts and create a BR_CC |
| 1571 | // Node. |
| 1572 | if (Tmp2.getOpcode() == ISD::SETCC) { |
| 1573 | Result = DAG.getNode(ISD::BR_CC, MVT::Other, Tmp1, Tmp2.getOperand(2), |
| 1574 | Tmp2.getOperand(0), Tmp2.getOperand(1), |
| 1575 | Node->getOperand(2)); |
| 1576 | } else { |
| 1577 | Result = DAG.getNode(ISD::BR_CC, MVT::Other, Tmp1, |
| 1578 | DAG.getCondCode(ISD::SETNE), Tmp2, |
| 1579 | DAG.getConstant(0, Tmp2.getValueType()), |
| 1580 | Node->getOperand(2)); |
| 1581 | } |
| 1582 | break; |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 1583 | } |
| 1584 | break; |
| 1585 | case ISD::BR_CC: |
| 1586 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1587 | // Ensure that libcalls are emitted before a branch. |
| 1588 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1589 | Tmp1 = LegalizeOp(Tmp1); |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 1590 | Tmp2 = Node->getOperand(2); // LHS |
| 1591 | Tmp3 = Node->getOperand(3); // RHS |
| 1592 | Tmp4 = Node->getOperand(1); // CC |
| 1593 | |
| 1594 | LegalizeSetCCOperands(Tmp2, Tmp3, Tmp4); |
Evan Cheng | 722cb36 | 2006-12-18 22:55:34 +0000 | [diff] [blame] | 1595 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 1596 | |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 1597 | // If we didn't get both a LHS and RHS back from LegalizeSetCCOperands, |
| 1598 | // the LHS is a legal SETCC itself. In this case, we need to compare |
| 1599 | // the result against zero to select between true and false values. |
| 1600 | if (Tmp3.Val == 0) { |
| 1601 | Tmp3 = DAG.getConstant(0, Tmp2.getValueType()); |
| 1602 | Tmp4 = DAG.getCondCode(ISD::SETNE); |
Chris Lattner | 181b7a3 | 2005-12-17 23:46:46 +0000 | [diff] [blame] | 1603 | } |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 1604 | |
| 1605 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp4, Tmp2, Tmp3, |
| 1606 | Node->getOperand(4)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 1607 | |
Chris Lattner | 181b7a3 | 2005-12-17 23:46:46 +0000 | [diff] [blame] | 1608 | switch (TLI.getOperationAction(ISD::BR_CC, Tmp3.getValueType())) { |
| 1609 | default: assert(0 && "Unexpected action for BR_CC!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 1610 | case TargetLowering::Legal: break; |
| 1611 | case TargetLowering::Custom: |
| 1612 | Tmp4 = TLI.LowerOperation(Result, DAG); |
| 1613 | if (Tmp4.Val) Result = Tmp4; |
Chris Lattner | 181b7a3 | 2005-12-17 23:46:46 +0000 | [diff] [blame] | 1614 | break; |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 1615 | } |
Chris Lattner | c18ae4c | 2005-01-07 08:19:42 +0000 | [diff] [blame] | 1616 | break; |
Evan Cheng | f3fd9fe | 2005-12-23 07:29:34 +0000 | [diff] [blame] | 1617 | case ISD::LOAD: { |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1618 | LoadSDNode *LD = cast<LoadSDNode>(Node); |
| 1619 | Tmp1 = LegalizeOp(LD->getChain()); // Legalize the chain. |
| 1620 | Tmp2 = LegalizeOp(LD->getBasePtr()); // Legalize the base pointer. |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 1621 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1622 | ISD::LoadExtType ExtType = LD->getExtensionType(); |
| 1623 | if (ExtType == ISD::NON_EXTLOAD) { |
| 1624 | MVT::ValueType VT = Node->getValueType(0); |
| 1625 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, LD->getOffset()); |
| 1626 | Tmp3 = Result.getValue(0); |
| 1627 | Tmp4 = Result.getValue(1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 1628 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1629 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 1630 | default: assert(0 && "This action is not supported yet!"); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 1631 | case TargetLowering::Legal: |
| 1632 | // If this is an unaligned load and the target doesn't support it, |
| 1633 | // expand it. |
| 1634 | if (!TLI.allowsUnalignedMemoryAccesses()) { |
| 1635 | unsigned ABIAlignment = TLI.getTargetData()-> |
| 1636 | getABITypeAlignment(MVT::getTypeForValueType(LD->getLoadedVT())); |
| 1637 | if (LD->getAlignment() < ABIAlignment){ |
| 1638 | Result = ExpandUnalignedLoad(cast<LoadSDNode>(Result.Val), DAG, |
| 1639 | TLI); |
| 1640 | Tmp3 = Result.getOperand(0); |
| 1641 | Tmp4 = Result.getOperand(1); |
| 1642 | LegalizeOp(Tmp3); |
| 1643 | LegalizeOp(Tmp4); |
| 1644 | } |
| 1645 | } |
| 1646 | break; |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1647 | case TargetLowering::Custom: |
| 1648 | Tmp1 = TLI.LowerOperation(Tmp3, DAG); |
| 1649 | if (Tmp1.Val) { |
| 1650 | Tmp3 = LegalizeOp(Tmp1); |
| 1651 | Tmp4 = LegalizeOp(Tmp1.getValue(1)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 1652 | } |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1653 | break; |
| 1654 | case TargetLowering::Promote: { |
| 1655 | // Only promote a load of vector type to another. |
| 1656 | assert(MVT::isVector(VT) && "Cannot promote this load!"); |
| 1657 | // Change base type to a different vector type. |
| 1658 | MVT::ValueType NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), VT); |
| 1659 | |
| 1660 | Tmp1 = DAG.getLoad(NVT, Tmp1, Tmp2, LD->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 1661 | LD->getSrcValueOffset(), |
| 1662 | LD->isVolatile(), LD->getAlignment()); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1663 | Tmp3 = LegalizeOp(DAG.getNode(ISD::BIT_CONVERT, VT, Tmp1)); |
| 1664 | Tmp4 = LegalizeOp(Tmp1.getValue(1)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1665 | break; |
Andrew Lenharth | 9d416f7 | 2005-06-30 19:22:37 +0000 | [diff] [blame] | 1666 | } |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1667 | } |
| 1668 | // Since loads produce two values, make sure to remember that we |
| 1669 | // legalized both of them. |
| 1670 | AddLegalizedOperand(SDOperand(Node, 0), Tmp3); |
| 1671 | AddLegalizedOperand(SDOperand(Node, 1), Tmp4); |
| 1672 | return Op.ResNo ? Tmp4 : Tmp3; |
| 1673 | } else { |
Evan Cheng | 2e49f09 | 2006-10-11 07:10:22 +0000 | [diff] [blame] | 1674 | MVT::ValueType SrcVT = LD->getLoadedVT(); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1675 | switch (TLI.getLoadXAction(ExtType, SrcVT)) { |
| 1676 | default: assert(0 && "This action is not supported yet!"); |
| 1677 | case TargetLowering::Promote: |
| 1678 | assert(SrcVT == MVT::i1 && |
| 1679 | "Can only promote extending LOAD from i1 -> i8!"); |
| 1680 | Result = DAG.getExtLoad(ExtType, Node->getValueType(0), Tmp1, Tmp2, |
| 1681 | LD->getSrcValue(), LD->getSrcValueOffset(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 1682 | MVT::i8, LD->isVolatile(), LD->getAlignment()); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1683 | Tmp1 = Result.getValue(0); |
| 1684 | Tmp2 = Result.getValue(1); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1685 | break; |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1686 | case TargetLowering::Custom: |
| 1687 | isCustom = true; |
| 1688 | // FALLTHROUGH |
| 1689 | case TargetLowering::Legal: |
| 1690 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, LD->getOffset()); |
| 1691 | Tmp1 = Result.getValue(0); |
| 1692 | Tmp2 = Result.getValue(1); |
| 1693 | |
| 1694 | if (isCustom) { |
| 1695 | Tmp3 = TLI.LowerOperation(Result, DAG); |
| 1696 | if (Tmp3.Val) { |
| 1697 | Tmp1 = LegalizeOp(Tmp3); |
| 1698 | Tmp2 = LegalizeOp(Tmp3.getValue(1)); |
| 1699 | } |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 1700 | } else { |
| 1701 | // If this is an unaligned load and the target doesn't support it, |
| 1702 | // expand it. |
| 1703 | if (!TLI.allowsUnalignedMemoryAccesses()) { |
| 1704 | unsigned ABIAlignment = TLI.getTargetData()-> |
| 1705 | getABITypeAlignment(MVT::getTypeForValueType(LD->getLoadedVT())); |
| 1706 | if (LD->getAlignment() < ABIAlignment){ |
| 1707 | Result = ExpandUnalignedLoad(cast<LoadSDNode>(Result.Val), DAG, |
| 1708 | TLI); |
| 1709 | Tmp1 = Result.getOperand(0); |
| 1710 | Tmp2 = Result.getOperand(1); |
| 1711 | LegalizeOp(Tmp1); |
| 1712 | LegalizeOp(Tmp2); |
| 1713 | } |
| 1714 | } |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1715 | } |
| 1716 | break; |
| 1717 | case TargetLowering::Expand: |
| 1718 | // f64 = EXTLOAD f32 should expand to LOAD, FP_EXTEND |
| 1719 | if (SrcVT == MVT::f32 && Node->getValueType(0) == MVT::f64) { |
| 1720 | SDOperand Load = DAG.getLoad(SrcVT, Tmp1, Tmp2, LD->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 1721 | LD->getSrcValueOffset(), |
| 1722 | LD->isVolatile(), LD->getAlignment()); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1723 | Result = DAG.getNode(ISD::FP_EXTEND, Node->getValueType(0), Load); |
| 1724 | Tmp1 = LegalizeOp(Result); // Relegalize new nodes. |
| 1725 | Tmp2 = LegalizeOp(Load.getValue(1)); |
| 1726 | break; |
| 1727 | } |
Chris Lattner | fea997a | 2007-02-01 04:55:59 +0000 | [diff] [blame] | 1728 | assert(ExtType != ISD::EXTLOAD &&"EXTLOAD should always be supported!"); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1729 | // Turn the unsupported load into an EXTLOAD followed by an explicit |
| 1730 | // zero/sign extend inreg. |
| 1731 | Result = DAG.getExtLoad(ISD::EXTLOAD, Node->getValueType(0), |
| 1732 | Tmp1, Tmp2, LD->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 1733 | LD->getSrcValueOffset(), SrcVT, |
| 1734 | LD->isVolatile(), LD->getAlignment()); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1735 | SDOperand ValRes; |
| 1736 | if (ExtType == ISD::SEXTLOAD) |
| 1737 | ValRes = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(), |
| 1738 | Result, DAG.getValueType(SrcVT)); |
| 1739 | else |
| 1740 | ValRes = DAG.getZeroExtendInReg(Result, SrcVT); |
| 1741 | Tmp1 = LegalizeOp(ValRes); // Relegalize new nodes. |
| 1742 | Tmp2 = LegalizeOp(Result.getValue(1)); // Relegalize new nodes. |
| 1743 | break; |
| 1744 | } |
| 1745 | // Since loads produce two values, make sure to remember that we legalized |
| 1746 | // both of them. |
| 1747 | AddLegalizedOperand(SDOperand(Node, 0), Tmp1); |
| 1748 | AddLegalizedOperand(SDOperand(Node, 1), Tmp2); |
| 1749 | return Op.ResNo ? Tmp2 : Tmp1; |
Chris Lattner | 01ff721 | 2005-04-10 22:54:25 +0000 | [diff] [blame] | 1750 | } |
Chris Lattner | 01ff721 | 2005-04-10 22:54:25 +0000 | [diff] [blame] | 1751 | } |
Nate Begeman | 5dc897b | 2005-10-19 00:06:56 +0000 | [diff] [blame] | 1752 | case ISD::EXTRACT_ELEMENT: { |
| 1753 | MVT::ValueType OpTy = Node->getOperand(0).getValueType(); |
| 1754 | switch (getTypeAction(OpTy)) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1755 | default: assert(0 && "EXTRACT_ELEMENT action for type unimplemented!"); |
Nate Begeman | 5dc897b | 2005-10-19 00:06:56 +0000 | [diff] [blame] | 1756 | case Legal: |
| 1757 | if (cast<ConstantSDNode>(Node->getOperand(1))->getValue()) { |
| 1758 | // 1 -> Hi |
| 1759 | Result = DAG.getNode(ISD::SRL, OpTy, Node->getOperand(0), |
| 1760 | DAG.getConstant(MVT::getSizeInBits(OpTy)/2, |
| 1761 | TLI.getShiftAmountTy())); |
| 1762 | Result = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0), Result); |
| 1763 | } else { |
| 1764 | // 0 -> Lo |
| 1765 | Result = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0), |
| 1766 | Node->getOperand(0)); |
| 1767 | } |
Nate Begeman | 5dc897b | 2005-10-19 00:06:56 +0000 | [diff] [blame] | 1768 | break; |
| 1769 | case Expand: |
| 1770 | // Get both the low and high parts. |
| 1771 | ExpandOp(Node->getOperand(0), Tmp1, Tmp2); |
| 1772 | if (cast<ConstantSDNode>(Node->getOperand(1))->getValue()) |
| 1773 | Result = Tmp2; // 1 -> Hi |
| 1774 | else |
| 1775 | Result = Tmp1; // 0 -> Lo |
| 1776 | break; |
| 1777 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1778 | break; |
Nate Begeman | 5dc897b | 2005-10-19 00:06:56 +0000 | [diff] [blame] | 1779 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1780 | |
| 1781 | case ISD::CopyToReg: |
| 1782 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 1783 | |
Chris Lattner | c9c60f6 | 2005-08-24 16:35:28 +0000 | [diff] [blame] | 1784 | assert(isTypeLegal(Node->getOperand(2).getValueType()) && |
Chris Lattner | d5d0f9b | 2005-08-16 21:55:35 +0000 | [diff] [blame] | 1785 | "Register type must be legal!"); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 1786 | // Legalize the incoming value (must be a legal type). |
Chris Lattner | d5d0f9b | 2005-08-16 21:55:35 +0000 | [diff] [blame] | 1787 | Tmp2 = LegalizeOp(Node->getOperand(2)); |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 1788 | if (Node->getNumValues() == 1) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1789 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1), Tmp2); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 1790 | } else { |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 1791 | assert(Node->getNumValues() == 2 && "Unknown CopyToReg"); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1792 | if (Node->getNumOperands() == 4) { |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 1793 | Tmp3 = LegalizeOp(Node->getOperand(3)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1794 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1), Tmp2, |
| 1795 | Tmp3); |
| 1796 | } else { |
| 1797 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1),Tmp2); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 1798 | } |
| 1799 | |
| 1800 | // Since this produces two values, make sure to remember that we legalized |
| 1801 | // both of them. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1802 | AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0)); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 1803 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1804 | return Result; |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 1805 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1806 | break; |
| 1807 | |
| 1808 | case ISD::RET: |
| 1809 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1810 | |
| 1811 | // Ensure that libcalls are emitted before a return. |
| 1812 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1813 | Tmp1 = LegalizeOp(Tmp1); |
| 1814 | LastCALLSEQ_END = DAG.getEntryNode(); |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 1815 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1816 | switch (Node->getNumOperands()) { |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 1817 | case 3: // ret val |
Evan Cheng | 98f8aeb | 2006-04-11 06:33:39 +0000 | [diff] [blame] | 1818 | Tmp2 = Node->getOperand(1); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 1819 | Tmp3 = Node->getOperand(2); // Signness |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 1820 | switch (getTypeAction(Tmp2.getValueType())) { |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1821 | case Legal: |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 1822 | Result = DAG.UpdateNodeOperands(Result, Tmp1, LegalizeOp(Tmp2), Tmp3); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1823 | break; |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 1824 | case Expand: |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 1825 | if (!MVT::isVector(Tmp2.getValueType())) { |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 1826 | SDOperand Lo, Hi; |
| 1827 | ExpandOp(Tmp2, Lo, Hi); |
Chris Lattner | edf2e8d | 2007-03-06 20:01:06 +0000 | [diff] [blame] | 1828 | |
| 1829 | // Big endian systems want the hi reg first. |
| 1830 | if (!TLI.isLittleEndian()) |
| 1831 | std::swap(Lo, Hi); |
| 1832 | |
Evan Cheng | 13acce3 | 2006-12-11 19:27:14 +0000 | [diff] [blame] | 1833 | if (Hi.Val) |
| 1834 | Result = DAG.getNode(ISD::RET, MVT::Other, Tmp1, Lo, Tmp3, Hi,Tmp3); |
| 1835 | else |
| 1836 | Result = DAG.getNode(ISD::RET, MVT::Other, Tmp1, Lo, Tmp3); |
Chris Lattner | f921a51 | 2006-08-21 20:24:53 +0000 | [diff] [blame] | 1837 | Result = LegalizeOp(Result); |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 1838 | } else { |
| 1839 | SDNode *InVal = Tmp2.Val; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 1840 | unsigned NumElems = MVT::getVectorNumElements(InVal->getValueType(0)); |
| 1841 | MVT::ValueType EVT = MVT::getVectorElementType(InVal->getValueType(0)); |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 1842 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 1843 | // Figure out if there is a simple type corresponding to this Vector |
Reid Spencer | ac9dcb9 | 2007-02-15 03:39:18 +0000 | [diff] [blame] | 1844 | // type. If so, convert to the vector type. |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 1845 | MVT::ValueType TVT = MVT::getVectorType(EVT, NumElems); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 1846 | if (TLI.isTypeLegal(TVT)) { |
Reid Spencer | ac9dcb9 | 2007-02-15 03:39:18 +0000 | [diff] [blame] | 1847 | // Turn this into a return of the vector type. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 1848 | Tmp2 = LegalizeOp(Tmp2); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 1849 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 1850 | } else if (NumElems == 1) { |
| 1851 | // Turn this into a return of the scalar type. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 1852 | Tmp2 = ScalarizeVectorOp(Tmp2); |
| 1853 | Tmp2 = LegalizeOp(Tmp2); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 1854 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | b49e52c | 2006-04-11 02:00:08 +0000 | [diff] [blame] | 1855 | |
| 1856 | // FIXME: Returns of gcc generic vectors smaller than a legal type |
| 1857 | // should be returned in integer registers! |
| 1858 | |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 1859 | // The scalarized value type may not be legal, e.g. it might require |
| 1860 | // promotion or expansion. Relegalize the return. |
| 1861 | Result = LegalizeOp(Result); |
| 1862 | } else { |
Chris Lattner | b49e52c | 2006-04-11 02:00:08 +0000 | [diff] [blame] | 1863 | // FIXME: Returns of gcc generic vectors larger than a legal vector |
| 1864 | // type should be returned by reference! |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 1865 | SDOperand Lo, Hi; |
| 1866 | SplitVectorOp(Tmp2, Lo, Hi); |
Chris Lattner | fea997a | 2007-02-01 04:55:59 +0000 | [diff] [blame] | 1867 | Result = DAG.getNode(ISD::RET, MVT::Other, Tmp1, Lo, Tmp3, Hi,Tmp3); |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 1868 | Result = LegalizeOp(Result); |
| 1869 | } |
| 1870 | } |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 1871 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1872 | case Promote: |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 1873 | Tmp2 = PromoteOp(Node->getOperand(1)); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 1874 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1875 | Result = LegalizeOp(Result); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 1876 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1877 | } |
| 1878 | break; |
| 1879 | case 1: // ret void |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1880 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1881 | break; |
| 1882 | default: { // ret <values> |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1883 | SmallVector<SDOperand, 8> NewValues; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1884 | NewValues.push_back(Tmp1); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 1885 | for (unsigned i = 1, e = Node->getNumOperands(); i < e; i += 2) |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1886 | switch (getTypeAction(Node->getOperand(i).getValueType())) { |
| 1887 | case Legal: |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 1888 | NewValues.push_back(LegalizeOp(Node->getOperand(i))); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 1889 | NewValues.push_back(Node->getOperand(i+1)); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1890 | break; |
| 1891 | case Expand: { |
| 1892 | SDOperand Lo, Hi; |
Dan Gohman | 6595cb3 | 2007-06-27 16:08:04 +0000 | [diff] [blame] | 1893 | assert(!MVT::isExtendedVT(Node->getOperand(i).getValueType()) && |
Chris Lattner | b49e52c | 2006-04-11 02:00:08 +0000 | [diff] [blame] | 1894 | "FIXME: TODO: implement returning non-legal vector types!"); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1895 | ExpandOp(Node->getOperand(i), Lo, Hi); |
| 1896 | NewValues.push_back(Lo); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 1897 | NewValues.push_back(Node->getOperand(i+1)); |
Evan Cheng | 13acce3 | 2006-12-11 19:27:14 +0000 | [diff] [blame] | 1898 | if (Hi.Val) { |
| 1899 | NewValues.push_back(Hi); |
| 1900 | NewValues.push_back(Node->getOperand(i+1)); |
| 1901 | } |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 1902 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1903 | } |
| 1904 | case Promote: |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 1905 | assert(0 && "Can't promote multiple return value yet!"); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1906 | } |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1907 | |
| 1908 | if (NewValues.size() == Node->getNumOperands()) |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1909 | Result = DAG.UpdateNodeOperands(Result, &NewValues[0],NewValues.size()); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1910 | else |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1911 | Result = DAG.getNode(ISD::RET, MVT::Other, |
| 1912 | &NewValues[0], NewValues.size()); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1913 | break; |
| 1914 | } |
| 1915 | } |
Evan Cheng | 17c428e | 2006-01-06 00:41:43 +0000 | [diff] [blame] | 1916 | |
Chris Lattner | 6862dbc | 2006-01-29 21:02:23 +0000 | [diff] [blame] | 1917 | if (Result.getOpcode() == ISD::RET) { |
| 1918 | switch (TLI.getOperationAction(Result.getOpcode(), MVT::Other)) { |
| 1919 | default: assert(0 && "This action is not supported yet!"); |
| 1920 | case TargetLowering::Legal: break; |
| 1921 | case TargetLowering::Custom: |
| 1922 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 1923 | if (Tmp1.Val) Result = Tmp1; |
| 1924 | break; |
| 1925 | } |
Evan Cheng | 17c428e | 2006-01-06 00:41:43 +0000 | [diff] [blame] | 1926 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1927 | break; |
Evan Cheng | f3fd9fe | 2005-12-23 07:29:34 +0000 | [diff] [blame] | 1928 | case ISD::STORE: { |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 1929 | StoreSDNode *ST = cast<StoreSDNode>(Node); |
| 1930 | Tmp1 = LegalizeOp(ST->getChain()); // Legalize the chain. |
| 1931 | Tmp2 = LegalizeOp(ST->getBasePtr()); // Legalize the pointer. |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 1932 | int SVOffset = ST->getSrcValueOffset(); |
| 1933 | unsigned Alignment = ST->getAlignment(); |
| 1934 | bool isVolatile = ST->isVolatile(); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1935 | |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 1936 | if (!ST->isTruncatingStore()) { |
Chris Lattner | d93d46e | 2006-12-12 04:18:56 +0000 | [diff] [blame] | 1937 | // Turn 'store float 1.0, Ptr' -> 'store int 0x12345678, Ptr' |
| 1938 | // FIXME: We shouldn't do this for TargetConstantFP's. |
| 1939 | // FIXME: move this to the DAG Combiner! Note that we can't regress due |
| 1940 | // to phase ordering between legalized code and the dag combiner. This |
| 1941 | // probably means that we need to integrate dag combiner and legalizer |
| 1942 | // together. |
| 1943 | if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(ST->getValue())) { |
| 1944 | if (CFP->getValueType(0) == MVT::f32) { |
| 1945 | Tmp3 = DAG.getConstant(FloatToBits(CFP->getValue()), MVT::i32); |
| 1946 | } else { |
| 1947 | assert(CFP->getValueType(0) == MVT::f64 && "Unknown FP type!"); |
| 1948 | Tmp3 = DAG.getConstant(DoubleToBits(CFP->getValue()), MVT::i64); |
| 1949 | } |
| 1950 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 1951 | SVOffset, isVolatile, Alignment); |
Chris Lattner | d93d46e | 2006-12-12 04:18:56 +0000 | [diff] [blame] | 1952 | break; |
| 1953 | } |
| 1954 | |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 1955 | switch (getTypeAction(ST->getStoredVT())) { |
| 1956 | case Legal: { |
| 1957 | Tmp3 = LegalizeOp(ST->getValue()); |
| 1958 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp3, Tmp2, |
| 1959 | ST->getOffset()); |
Evan Cheng | f3fd9fe | 2005-12-23 07:29:34 +0000 | [diff] [blame] | 1960 | |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 1961 | MVT::ValueType VT = Tmp3.getValueType(); |
| 1962 | switch (TLI.getOperationAction(ISD::STORE, VT)) { |
| 1963 | default: assert(0 && "This action is not supported yet!"); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 1964 | case TargetLowering::Legal: |
| 1965 | // If this is an unaligned store and the target doesn't support it, |
| 1966 | // expand it. |
| 1967 | if (!TLI.allowsUnalignedMemoryAccesses()) { |
| 1968 | unsigned ABIAlignment = TLI.getTargetData()-> |
| 1969 | getABITypeAlignment(MVT::getTypeForValueType(ST->getStoredVT())); |
| 1970 | if (ST->getAlignment() < ABIAlignment) |
| 1971 | Result = ExpandUnalignedStore(cast<StoreSDNode>(Result.Val), DAG, |
| 1972 | TLI); |
| 1973 | } |
| 1974 | break; |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 1975 | case TargetLowering::Custom: |
| 1976 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 1977 | if (Tmp1.Val) Result = Tmp1; |
| 1978 | break; |
| 1979 | case TargetLowering::Promote: |
| 1980 | assert(MVT::isVector(VT) && "Unknown legal promote case!"); |
| 1981 | Tmp3 = DAG.getNode(ISD::BIT_CONVERT, |
| 1982 | TLI.getTypeToPromoteTo(ISD::STORE, VT), Tmp3); |
| 1983 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 1984 | ST->getSrcValue(), SVOffset, isVolatile, |
| 1985 | Alignment); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 1986 | break; |
| 1987 | } |
| 1988 | break; |
| 1989 | } |
| 1990 | case Promote: |
| 1991 | // Truncate the value and store the result. |
| 1992 | Tmp3 = PromoteOp(ST->getValue()); |
| 1993 | Result = DAG.getTruncStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 1994 | SVOffset, ST->getStoredVT(), |
| 1995 | isVolatile, Alignment); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 1996 | break; |
| 1997 | |
| 1998 | case Expand: |
| 1999 | unsigned IncrementSize = 0; |
| 2000 | SDOperand Lo, Hi; |
| 2001 | |
| 2002 | // If this is a vector type, then we have to calculate the increment as |
| 2003 | // the product of the element size in bytes, and the number of elements |
| 2004 | // in the high half of the vector. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2005 | if (MVT::isVector(ST->getValue().getValueType())) { |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2006 | SDNode *InVal = ST->getValue().Val; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2007 | unsigned NumElems = MVT::getVectorNumElements(InVal->getValueType(0)); |
| 2008 | MVT::ValueType EVT = MVT::getVectorElementType(InVal->getValueType(0)); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2009 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2010 | // Figure out if there is a simple type corresponding to this Vector |
Reid Spencer | ac9dcb9 | 2007-02-15 03:39:18 +0000 | [diff] [blame] | 2011 | // type. If so, convert to the vector type. |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2012 | MVT::ValueType TVT = MVT::getVectorType(EVT, NumElems); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2013 | if (TLI.isTypeLegal(TVT)) { |
Reid Spencer | ac9dcb9 | 2007-02-15 03:39:18 +0000 | [diff] [blame] | 2014 | // Turn this into a normal store of the vector type. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2015 | Tmp3 = LegalizeOp(Node->getOperand(1)); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2016 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2017 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2018 | Result = LegalizeOp(Result); |
| 2019 | break; |
| 2020 | } else if (NumElems == 1) { |
| 2021 | // Turn this into a normal store of the scalar type. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2022 | Tmp3 = ScalarizeVectorOp(Node->getOperand(1)); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2023 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2024 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2025 | // The scalarized value type may not be legal, e.g. it might require |
| 2026 | // promotion or expansion. Relegalize the scalar store. |
| 2027 | Result = LegalizeOp(Result); |
| 2028 | break; |
| 2029 | } else { |
| 2030 | SplitVectorOp(Node->getOperand(1), Lo, Hi); |
| 2031 | IncrementSize = NumElems/2 * MVT::getSizeInBits(EVT)/8; |
| 2032 | } |
| 2033 | } else { |
| 2034 | ExpandOp(Node->getOperand(1), Lo, Hi); |
Evan Cheng | 7b2b5c8 | 2006-12-12 19:53:13 +0000 | [diff] [blame] | 2035 | IncrementSize = Hi.Val ? MVT::getSizeInBits(Hi.getValueType())/8 : 0; |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2036 | |
| 2037 | if (!TLI.isLittleEndian()) |
| 2038 | std::swap(Lo, Hi); |
| 2039 | } |
| 2040 | |
| 2041 | Lo = DAG.getStore(Tmp1, Lo, Tmp2, ST->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2042 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 7b2b5c8 | 2006-12-12 19:53:13 +0000 | [diff] [blame] | 2043 | |
| 2044 | if (Hi.Val == NULL) { |
| 2045 | // Must be int <-> float one-to-one expansion. |
| 2046 | Result = Lo; |
| 2047 | break; |
| 2048 | } |
| 2049 | |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2050 | Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2, |
| 2051 | getIntPtrConstant(IncrementSize)); |
| 2052 | assert(isTypeLegal(Tmp2.getValueType()) && |
| 2053 | "Pointers must be legal!"); |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2054 | SVOffset += IncrementSize; |
| 2055 | if (Alignment > IncrementSize) |
| 2056 | Alignment = IncrementSize; |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2057 | Hi = DAG.getStore(Tmp1, Hi, Tmp2, ST->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2058 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2059 | Result = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo, Hi); |
| 2060 | break; |
| 2061 | } |
| 2062 | } else { |
| 2063 | // Truncating store |
| 2064 | assert(isTypeLegal(ST->getValue().getValueType()) && |
| 2065 | "Cannot handle illegal TRUNCSTORE yet!"); |
| 2066 | Tmp3 = LegalizeOp(ST->getValue()); |
| 2067 | |
| 2068 | // The only promote case we handle is TRUNCSTORE:i1 X into |
| 2069 | // -> TRUNCSTORE:i8 (and X, 1) |
| 2070 | if (ST->getStoredVT() == MVT::i1 && |
| 2071 | TLI.getStoreXAction(MVT::i1) == TargetLowering::Promote) { |
| 2072 | // Promote the bool to a mask then store. |
| 2073 | Tmp3 = DAG.getNode(ISD::AND, Tmp3.getValueType(), Tmp3, |
| 2074 | DAG.getConstant(1, Tmp3.getValueType())); |
| 2075 | Result = DAG.getTruncStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2076 | SVOffset, MVT::i8, |
| 2077 | isVolatile, Alignment); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2078 | } else if (Tmp1 != ST->getChain() || Tmp3 != ST->getValue() || |
| 2079 | Tmp2 != ST->getBasePtr()) { |
| 2080 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp3, Tmp2, |
| 2081 | ST->getOffset()); |
| 2082 | } |
| 2083 | |
| 2084 | MVT::ValueType StVT = cast<StoreSDNode>(Result.Val)->getStoredVT(); |
| 2085 | switch (TLI.getStoreXAction(StVT)) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2086 | default: assert(0 && "This action is not supported yet!"); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2087 | case TargetLowering::Legal: |
| 2088 | // If this is an unaligned store and the target doesn't support it, |
| 2089 | // expand it. |
| 2090 | if (!TLI.allowsUnalignedMemoryAccesses()) { |
| 2091 | unsigned ABIAlignment = TLI.getTargetData()-> |
| 2092 | getABITypeAlignment(MVT::getTypeForValueType(ST->getStoredVT())); |
| 2093 | if (ST->getAlignment() < ABIAlignment) |
| 2094 | Result = ExpandUnalignedStore(cast<StoreSDNode>(Result.Val), DAG, |
| 2095 | TLI); |
| 2096 | } |
| 2097 | break; |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2098 | case TargetLowering::Custom: |
| 2099 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2100 | if (Tmp1.Val) Result = Tmp1; |
| 2101 | break; |
Evan Cheng | f3fd9fe | 2005-12-23 07:29:34 +0000 | [diff] [blame] | 2102 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2103 | } |
| 2104 | break; |
Evan Cheng | f3fd9fe | 2005-12-23 07:29:34 +0000 | [diff] [blame] | 2105 | } |
Andrew Lenharth | 9576212 | 2005-03-31 21:24:06 +0000 | [diff] [blame] | 2106 | case ISD::PCMARKER: |
| 2107 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2108 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
Andrew Lenharth | 9576212 | 2005-03-31 21:24:06 +0000 | [diff] [blame] | 2109 | break; |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2110 | case ISD::STACKSAVE: |
| 2111 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2112 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 2113 | Tmp1 = Result.getValue(0); |
| 2114 | Tmp2 = Result.getValue(1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2115 | |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2116 | switch (TLI.getOperationAction(ISD::STACKSAVE, MVT::Other)) { |
| 2117 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2118 | case TargetLowering::Legal: break; |
| 2119 | case TargetLowering::Custom: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2120 | Tmp3 = TLI.LowerOperation(Result, DAG); |
| 2121 | if (Tmp3.Val) { |
| 2122 | Tmp1 = LegalizeOp(Tmp3); |
| 2123 | Tmp2 = LegalizeOp(Tmp3.getValue(1)); |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2124 | } |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2125 | break; |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2126 | case TargetLowering::Expand: |
Chris Lattner | 4f0d8e4 | 2006-01-13 17:48:44 +0000 | [diff] [blame] | 2127 | // Expand to CopyFromReg if the target set |
| 2128 | // StackPointerRegisterToSaveRestore. |
| 2129 | if (unsigned SP = TLI.getStackPointerRegisterToSaveRestore()) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2130 | Tmp1 = DAG.getCopyFromReg(Result.getOperand(0), SP, |
Chris Lattner | 4f0d8e4 | 2006-01-13 17:48:44 +0000 | [diff] [blame] | 2131 | Node->getValueType(0)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2132 | Tmp2 = Tmp1.getValue(1); |
Chris Lattner | 4f0d8e4 | 2006-01-13 17:48:44 +0000 | [diff] [blame] | 2133 | } else { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2134 | Tmp1 = DAG.getNode(ISD::UNDEF, Node->getValueType(0)); |
| 2135 | Tmp2 = Node->getOperand(0); |
Chris Lattner | 4f0d8e4 | 2006-01-13 17:48:44 +0000 | [diff] [blame] | 2136 | } |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2137 | break; |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2138 | } |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2139 | |
| 2140 | // Since stacksave produce two values, make sure to remember that we |
| 2141 | // legalized both of them. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2142 | AddLegalizedOperand(SDOperand(Node, 0), Tmp1); |
| 2143 | AddLegalizedOperand(SDOperand(Node, 1), Tmp2); |
| 2144 | return Op.ResNo ? Tmp2 : Tmp1; |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2145 | |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2146 | case ISD::STACKRESTORE: |
| 2147 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 2148 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2149 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2150 | |
| 2151 | switch (TLI.getOperationAction(ISD::STACKRESTORE, MVT::Other)) { |
| 2152 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2153 | case TargetLowering::Legal: break; |
| 2154 | case TargetLowering::Custom: |
| 2155 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2156 | if (Tmp1.Val) Result = Tmp1; |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2157 | break; |
| 2158 | case TargetLowering::Expand: |
Chris Lattner | 4f0d8e4 | 2006-01-13 17:48:44 +0000 | [diff] [blame] | 2159 | // Expand to CopyToReg if the target set |
| 2160 | // StackPointerRegisterToSaveRestore. |
| 2161 | if (unsigned SP = TLI.getStackPointerRegisterToSaveRestore()) { |
| 2162 | Result = DAG.getCopyToReg(Tmp1, SP, Tmp2); |
| 2163 | } else { |
| 2164 | Result = Tmp1; |
| 2165 | } |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2166 | break; |
| 2167 | } |
| 2168 | break; |
| 2169 | |
Andrew Lenharth | 51b8d54 | 2005-11-11 16:47:30 +0000 | [diff] [blame] | 2170 | case ISD::READCYCLECOUNTER: |
| 2171 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2172 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Evan Cheng | f0b3ba6 | 2006-11-29 08:26:18 +0000 | [diff] [blame] | 2173 | switch (TLI.getOperationAction(ISD::READCYCLECOUNTER, |
| 2174 | Node->getValueType(0))) { |
| 2175 | default: assert(0 && "This action is not supported yet!"); |
Evan Cheng | 6a16c5a | 2006-11-29 19:13:47 +0000 | [diff] [blame] | 2176 | case TargetLowering::Legal: |
| 2177 | Tmp1 = Result.getValue(0); |
| 2178 | Tmp2 = Result.getValue(1); |
| 2179 | break; |
Evan Cheng | f0b3ba6 | 2006-11-29 08:26:18 +0000 | [diff] [blame] | 2180 | case TargetLowering::Custom: |
| 2181 | Result = TLI.LowerOperation(Result, DAG); |
Evan Cheng | 6a16c5a | 2006-11-29 19:13:47 +0000 | [diff] [blame] | 2182 | Tmp1 = LegalizeOp(Result.getValue(0)); |
| 2183 | Tmp2 = LegalizeOp(Result.getValue(1)); |
Evan Cheng | f0b3ba6 | 2006-11-29 08:26:18 +0000 | [diff] [blame] | 2184 | break; |
| 2185 | } |
Andrew Lenharth | 49c709f | 2005-12-02 04:56:24 +0000 | [diff] [blame] | 2186 | |
| 2187 | // Since rdcc produce two values, make sure to remember that we legalized |
| 2188 | // both of them. |
Evan Cheng | 6a16c5a | 2006-11-29 19:13:47 +0000 | [diff] [blame] | 2189 | AddLegalizedOperand(SDOperand(Node, 0), Tmp1); |
| 2190 | AddLegalizedOperand(SDOperand(Node, 1), Tmp2); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2191 | return Result; |
Andrew Lenharth | f70e30b | 2005-11-20 21:32:07 +0000 | [diff] [blame] | 2192 | |
Chris Lattner | 2ee743f | 2005-01-14 22:08:15 +0000 | [diff] [blame] | 2193 | case ISD::SELECT: |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 2194 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 2195 | case Expand: assert(0 && "It's impossible to expand bools"); |
| 2196 | case Legal: |
| 2197 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the condition. |
| 2198 | break; |
| 2199 | case Promote: |
| 2200 | Tmp1 = PromoteOp(Node->getOperand(0)); // Promote the condition. |
Chris Lattner | b6c8060 | 2006-11-28 01:03:30 +0000 | [diff] [blame] | 2201 | // Make sure the condition is either zero or one. |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2202 | if (!DAG.MaskedValueIsZero(Tmp1, |
Chris Lattner | b6c8060 | 2006-11-28 01:03:30 +0000 | [diff] [blame] | 2203 | MVT::getIntVTBitMask(Tmp1.getValueType())^1)) |
| 2204 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, MVT::i1); |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 2205 | break; |
| 2206 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2207 | Tmp2 = LegalizeOp(Node->getOperand(1)); // TrueVal |
Chris Lattner | 2ee743f | 2005-01-14 22:08:15 +0000 | [diff] [blame] | 2208 | Tmp3 = LegalizeOp(Node->getOperand(2)); // FalseVal |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2209 | |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2210 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2211 | |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 2212 | switch (TLI.getOperationAction(ISD::SELECT, Tmp2.getValueType())) { |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2213 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2214 | case TargetLowering::Legal: break; |
| 2215 | case TargetLowering::Custom: { |
| 2216 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2217 | if (Tmp1.Val) Result = Tmp1; |
| 2218 | break; |
| 2219 | } |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 2220 | case TargetLowering::Expand: |
| 2221 | if (Tmp1.getOpcode() == ISD::SETCC) { |
| 2222 | Result = DAG.getSelectCC(Tmp1.getOperand(0), Tmp1.getOperand(1), |
| 2223 | Tmp2, Tmp3, |
| 2224 | cast<CondCodeSDNode>(Tmp1.getOperand(2))->get()); |
| 2225 | } else { |
| 2226 | Result = DAG.getSelectCC(Tmp1, |
| 2227 | DAG.getConstant(0, Tmp1.getValueType()), |
| 2228 | Tmp2, Tmp3, ISD::SETNE); |
| 2229 | } |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2230 | break; |
| 2231 | case TargetLowering::Promote: { |
| 2232 | MVT::ValueType NVT = |
| 2233 | TLI.getTypeToPromoteTo(ISD::SELECT, Tmp2.getValueType()); |
| 2234 | unsigned ExtOp, TruncOp; |
Evan Cheng | 41f6cbb | 2006-04-12 16:33:18 +0000 | [diff] [blame] | 2235 | if (MVT::isVector(Tmp2.getValueType())) { |
| 2236 | ExtOp = ISD::BIT_CONVERT; |
| 2237 | TruncOp = ISD::BIT_CONVERT; |
| 2238 | } else if (MVT::isInteger(Tmp2.getValueType())) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2239 | ExtOp = ISD::ANY_EXTEND; |
| 2240 | TruncOp = ISD::TRUNCATE; |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2241 | } else { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2242 | ExtOp = ISD::FP_EXTEND; |
| 2243 | TruncOp = ISD::FP_ROUND; |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2244 | } |
| 2245 | // Promote each of the values to the new type. |
| 2246 | Tmp2 = DAG.getNode(ExtOp, NVT, Tmp2); |
| 2247 | Tmp3 = DAG.getNode(ExtOp, NVT, Tmp3); |
| 2248 | // Perform the larger operation, then round down. |
| 2249 | Result = DAG.getNode(ISD::SELECT, NVT, Tmp1, Tmp2,Tmp3); |
| 2250 | Result = DAG.getNode(TruncOp, Node->getValueType(0), Result); |
| 2251 | break; |
| 2252 | } |
| 2253 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2254 | break; |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 2255 | case ISD::SELECT_CC: { |
| 2256 | Tmp1 = Node->getOperand(0); // LHS |
| 2257 | Tmp2 = Node->getOperand(1); // RHS |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 2258 | Tmp3 = LegalizeOp(Node->getOperand(2)); // True |
| 2259 | Tmp4 = LegalizeOp(Node->getOperand(3)); // False |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 2260 | SDOperand CC = Node->getOperand(4); |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 2261 | |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 2262 | LegalizeSetCCOperands(Tmp1, Tmp2, CC); |
| 2263 | |
| 2264 | // If we didn't get both a LHS and RHS back from LegalizeSetCCOperands, |
| 2265 | // the LHS is a legal SETCC itself. In this case, we need to compare |
| 2266 | // the result against zero to select between true and false values. |
| 2267 | if (Tmp2.Val == 0) { |
| 2268 | Tmp2 = DAG.getConstant(0, Tmp1.getValueType()); |
| 2269 | CC = DAG.getCondCode(ISD::SETNE); |
| 2270 | } |
| 2271 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3, Tmp4, CC); |
| 2272 | |
| 2273 | // Everything is legal, see if we should expand this op or something. |
| 2274 | switch (TLI.getOperationAction(ISD::SELECT_CC, Tmp3.getValueType())) { |
| 2275 | default: assert(0 && "This action is not supported yet!"); |
| 2276 | case TargetLowering::Legal: break; |
| 2277 | case TargetLowering::Custom: |
| 2278 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2279 | if (Tmp1.Val) Result = Tmp1; |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 2280 | break; |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 2281 | } |
| 2282 | break; |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 2283 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2284 | case ISD::SETCC: |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 2285 | Tmp1 = Node->getOperand(0); |
| 2286 | Tmp2 = Node->getOperand(1); |
| 2287 | Tmp3 = Node->getOperand(2); |
| 2288 | LegalizeSetCCOperands(Tmp1, Tmp2, Tmp3); |
| 2289 | |
| 2290 | // If we had to Expand the SetCC operands into a SELECT node, then it may |
| 2291 | // not always be possible to return a true LHS & RHS. In this case, just |
| 2292 | // return the value we legalized, returned in the LHS |
| 2293 | if (Tmp2.Val == 0) { |
| 2294 | Result = Tmp1; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2295 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2296 | } |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 2297 | |
Chris Lattner | 73e142f | 2006-01-30 22:43:50 +0000 | [diff] [blame] | 2298 | switch (TLI.getOperationAction(ISD::SETCC, Tmp1.getValueType())) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2299 | default: assert(0 && "Cannot handle this action for SETCC yet!"); |
| 2300 | case TargetLowering::Custom: |
| 2301 | isCustom = true; |
| 2302 | // FALLTHROUGH. |
| 2303 | case TargetLowering::Legal: |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 2304 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2305 | if (isCustom) { |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 2306 | Tmp4 = TLI.LowerOperation(Result, DAG); |
| 2307 | if (Tmp4.Val) Result = Tmp4; |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2308 | } |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 2309 | break; |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 2310 | case TargetLowering::Promote: { |
| 2311 | // First step, figure out the appropriate operation to use. |
| 2312 | // Allow SETCC to not be supported for all legal data types |
| 2313 | // Mostly this targets FP |
| 2314 | MVT::ValueType NewInTy = Node->getOperand(0).getValueType(); |
Chris Lattner | 00755df | 2007-02-04 00:27:56 +0000 | [diff] [blame] | 2315 | MVT::ValueType OldVT = NewInTy; OldVT = OldVT; |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 2316 | |
| 2317 | // Scan for the appropriate larger type to use. |
| 2318 | while (1) { |
| 2319 | NewInTy = (MVT::ValueType)(NewInTy+1); |
| 2320 | |
| 2321 | assert(MVT::isInteger(NewInTy) == MVT::isInteger(OldVT) && |
| 2322 | "Fell off of the edge of the integer world"); |
| 2323 | assert(MVT::isFloatingPoint(NewInTy) == MVT::isFloatingPoint(OldVT) && |
| 2324 | "Fell off of the edge of the floating point world"); |
| 2325 | |
| 2326 | // If the target supports SETCC of this type, use it. |
Chris Lattner | 1ccf26a | 2005-12-22 05:23:45 +0000 | [diff] [blame] | 2327 | if (TLI.isOperationLegal(ISD::SETCC, NewInTy)) |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 2328 | break; |
| 2329 | } |
| 2330 | if (MVT::isInteger(NewInTy)) |
| 2331 | assert(0 && "Cannot promote Legal Integer SETCC yet"); |
| 2332 | else { |
| 2333 | Tmp1 = DAG.getNode(ISD::FP_EXTEND, NewInTy, Tmp1); |
| 2334 | Tmp2 = DAG.getNode(ISD::FP_EXTEND, NewInTy, Tmp2); |
| 2335 | } |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2336 | Tmp1 = LegalizeOp(Tmp1); |
| 2337 | Tmp2 = LegalizeOp(Tmp2); |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 2338 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Evan Cheng | 433f8ac | 2006-01-17 19:47:13 +0000 | [diff] [blame] | 2339 | Result = LegalizeOp(Result); |
Andrew Lenharth | 5e3efbc | 2005-08-29 20:46:51 +0000 | [diff] [blame] | 2340 | break; |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 2341 | } |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 2342 | case TargetLowering::Expand: |
| 2343 | // Expand a setcc node into a select_cc of the same condition, lhs, and |
| 2344 | // rhs that selects between const 1 (true) and const 0 (false). |
| 2345 | MVT::ValueType VT = Node->getValueType(0); |
| 2346 | Result = DAG.getNode(ISD::SELECT_CC, VT, Tmp1, Tmp2, |
| 2347 | DAG.getConstant(1, VT), DAG.getConstant(0, VT), |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 2348 | Tmp3); |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 2349 | break; |
| 2350 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2351 | break; |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 2352 | case ISD::MEMSET: |
| 2353 | case ISD::MEMCPY: |
| 2354 | case ISD::MEMMOVE: { |
Chris Lattner | deb692e | 2005-02-01 18:38:28 +0000 | [diff] [blame] | 2355 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Chain |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 2356 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Pointer |
| 2357 | |
| 2358 | if (Node->getOpcode() == ISD::MEMSET) { // memset = ubyte |
| 2359 | switch (getTypeAction(Node->getOperand(2).getValueType())) { |
| 2360 | case Expand: assert(0 && "Cannot expand a byte!"); |
| 2361 | case Legal: |
Chris Lattner | deb692e | 2005-02-01 18:38:28 +0000 | [diff] [blame] | 2362 | Tmp3 = LegalizeOp(Node->getOperand(2)); |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 2363 | break; |
| 2364 | case Promote: |
Chris Lattner | deb692e | 2005-02-01 18:38:28 +0000 | [diff] [blame] | 2365 | Tmp3 = PromoteOp(Node->getOperand(2)); |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 2366 | break; |
| 2367 | } |
| 2368 | } else { |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2369 | Tmp3 = LegalizeOp(Node->getOperand(2)); // memcpy/move = pointer, |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 2370 | } |
Chris Lattner | 272455b | 2005-02-02 03:44:41 +0000 | [diff] [blame] | 2371 | |
| 2372 | SDOperand Tmp4; |
| 2373 | switch (getTypeAction(Node->getOperand(3).getValueType())) { |
Chris Lattner | 6814f15 | 2005-07-13 01:42:45 +0000 | [diff] [blame] | 2374 | case Expand: { |
| 2375 | // Length is too big, just take the lo-part of the length. |
| 2376 | SDOperand HiPart; |
Chris Lattner | fa9aa2b | 2006-11-07 04:11:44 +0000 | [diff] [blame] | 2377 | ExpandOp(Node->getOperand(3), Tmp4, HiPart); |
Chris Lattner | 6814f15 | 2005-07-13 01:42:45 +0000 | [diff] [blame] | 2378 | break; |
| 2379 | } |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 2380 | case Legal: |
| 2381 | Tmp4 = LegalizeOp(Node->getOperand(3)); |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 2382 | break; |
| 2383 | case Promote: |
| 2384 | Tmp4 = PromoteOp(Node->getOperand(3)); |
Chris Lattner | 272455b | 2005-02-02 03:44:41 +0000 | [diff] [blame] | 2385 | break; |
| 2386 | } |
| 2387 | |
| 2388 | SDOperand Tmp5; |
| 2389 | switch (getTypeAction(Node->getOperand(4).getValueType())) { // uint |
| 2390 | case Expand: assert(0 && "Cannot expand this yet!"); |
| 2391 | case Legal: |
| 2392 | Tmp5 = LegalizeOp(Node->getOperand(4)); |
| 2393 | break; |
| 2394 | case Promote: |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 2395 | Tmp5 = PromoteOp(Node->getOperand(4)); |
| 2396 | break; |
| 2397 | } |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2398 | |
| 2399 | switch (TLI.getOperationAction(Node->getOpcode(), MVT::Other)) { |
| 2400 | default: assert(0 && "This action not implemented for this operation!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2401 | case TargetLowering::Custom: |
| 2402 | isCustom = true; |
| 2403 | // FALLTHROUGH |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2404 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2405 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3, Tmp4, Tmp5); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2406 | if (isCustom) { |
| 2407 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2408 | if (Tmp1.Val) Result = Tmp1; |
| 2409 | } |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2410 | break; |
| 2411 | case TargetLowering::Expand: { |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 2412 | // Otherwise, the target does not support this operation. Lower the |
| 2413 | // operation to an explicit libcall as appropriate. |
| 2414 | MVT::ValueType IntPtr = TLI.getPointerTy(); |
Owen Anderson | a69571c | 2006-05-03 01:29:57 +0000 | [diff] [blame] | 2415 | const Type *IntPtrTy = TLI.getTargetData()->getIntPtrType(); |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 2416 | TargetLowering::ArgListTy Args; |
| 2417 | TargetLowering::ArgListEntry Entry; |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 2418 | |
Reid Spencer | 3bfbf4e | 2005-01-12 14:53:45 +0000 | [diff] [blame] | 2419 | const char *FnName = 0; |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 2420 | if (Node->getOpcode() == ISD::MEMSET) { |
Anton Korobeynikov | d0b82b3 | 2007-03-07 16:25:09 +0000 | [diff] [blame] | 2421 | Entry.Node = Tmp2; Entry.Ty = IntPtrTy; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 2422 | Args.push_back(Entry); |
Chris Lattner | dca7abe | 2006-02-20 06:38:35 +0000 | [diff] [blame] | 2423 | // Extend the (previously legalized) ubyte argument to be an int value |
| 2424 | // for the call. |
| 2425 | if (Tmp3.getValueType() > MVT::i32) |
| 2426 | Tmp3 = DAG.getNode(ISD::TRUNCATE, MVT::i32, Tmp3); |
| 2427 | else |
| 2428 | Tmp3 = DAG.getNode(ISD::ZERO_EXTEND, MVT::i32, Tmp3); |
Anton Korobeynikov | d0b82b3 | 2007-03-07 16:25:09 +0000 | [diff] [blame] | 2429 | Entry.Node = Tmp3; Entry.Ty = Type::Int32Ty; Entry.isSExt = true; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 2430 | Args.push_back(Entry); |
Anton Korobeynikov | d0b82b3 | 2007-03-07 16:25:09 +0000 | [diff] [blame] | 2431 | Entry.Node = Tmp4; Entry.Ty = IntPtrTy; Entry.isSExt = false; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 2432 | Args.push_back(Entry); |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 2433 | |
| 2434 | FnName = "memset"; |
| 2435 | } else if (Node->getOpcode() == ISD::MEMCPY || |
| 2436 | Node->getOpcode() == ISD::MEMMOVE) { |
Anton Korobeynikov | b25fe82 | 2007-02-01 08:39:52 +0000 | [diff] [blame] | 2437 | Entry.Ty = IntPtrTy; |
Reid Spencer | b47b25c | 2007-01-03 04:22:32 +0000 | [diff] [blame] | 2438 | Entry.Node = Tmp2; Args.push_back(Entry); |
| 2439 | Entry.Node = Tmp3; Args.push_back(Entry); |
| 2440 | Entry.Node = Tmp4; Args.push_back(Entry); |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 2441 | FnName = Node->getOpcode() == ISD::MEMMOVE ? "memmove" : "memcpy"; |
| 2442 | } else { |
| 2443 | assert(0 && "Unknown op!"); |
| 2444 | } |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 2445 | |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 2446 | std::pair<SDOperand,SDOperand> CallResult = |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 2447 | TLI.LowerCallTo(Tmp1, Type::VoidTy, false, false, CallingConv::C, false, |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 2448 | DAG.getExternalSymbol(FnName, IntPtr), Args, DAG); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2449 | Result = CallResult.second; |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2450 | break; |
| 2451 | } |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 2452 | } |
| 2453 | break; |
| 2454 | } |
Chris Lattner | 52d08bd | 2005-05-09 20:23:03 +0000 | [diff] [blame] | 2455 | |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 2456 | case ISD::SHL_PARTS: |
| 2457 | case ISD::SRA_PARTS: |
| 2458 | case ISD::SRL_PARTS: { |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 2459 | SmallVector<SDOperand, 8> Ops; |
Chris Lattner | 84f6788 | 2005-01-20 18:52:28 +0000 | [diff] [blame] | 2460 | bool Changed = false; |
| 2461 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) { |
| 2462 | Ops.push_back(LegalizeOp(Node->getOperand(i))); |
| 2463 | Changed |= Ops.back() != Node->getOperand(i); |
| 2464 | } |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2465 | if (Changed) |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 2466 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 2467 | |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 2468 | switch (TLI.getOperationAction(Node->getOpcode(), |
| 2469 | Node->getValueType(0))) { |
| 2470 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2471 | case TargetLowering::Legal: break; |
| 2472 | case TargetLowering::Custom: |
| 2473 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2474 | if (Tmp1.Val) { |
| 2475 | SDOperand Tmp2, RetVal(0, 0); |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 2476 | for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2477 | Tmp2 = LegalizeOp(Tmp1.getValue(i)); |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 2478 | AddLegalizedOperand(SDOperand(Node, i), Tmp2); |
| 2479 | if (i == Op.ResNo) |
Evan Cheng | 12f2274 | 2006-01-19 04:54:52 +0000 | [diff] [blame] | 2480 | RetVal = Tmp2; |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 2481 | } |
Chris Lattner | 269f8c0 | 2006-01-10 19:43:26 +0000 | [diff] [blame] | 2482 | assert(RetVal.Val && "Illegal result number"); |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 2483 | return RetVal; |
| 2484 | } |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 2485 | break; |
| 2486 | } |
| 2487 | |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 2488 | // Since these produce multiple values, make sure to remember that we |
| 2489 | // legalized all of them. |
| 2490 | for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) |
| 2491 | AddLegalizedOperand(SDOperand(Node, i), Result.getValue(i)); |
| 2492 | return Result.getValue(Op.ResNo); |
Chris Lattner | 84f6788 | 2005-01-20 18:52:28 +0000 | [diff] [blame] | 2493 | } |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 2494 | |
| 2495 | // Binary operators |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2496 | case ISD::ADD: |
| 2497 | case ISD::SUB: |
| 2498 | case ISD::MUL: |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 2499 | case ISD::MULHS: |
| 2500 | case ISD::MULHU: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2501 | case ISD::UDIV: |
| 2502 | case ISD::SDIV: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2503 | case ISD::AND: |
| 2504 | case ISD::OR: |
| 2505 | case ISD::XOR: |
Chris Lattner | 03c0cf8 | 2005-01-07 21:45:56 +0000 | [diff] [blame] | 2506 | case ISD::SHL: |
| 2507 | case ISD::SRL: |
| 2508 | case ISD::SRA: |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 2509 | case ISD::FADD: |
| 2510 | case ISD::FSUB: |
| 2511 | case ISD::FMUL: |
| 2512 | case ISD::FDIV: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2513 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
Andrew Lenharth | f2eb139 | 2005-07-05 19:52:39 +0000 | [diff] [blame] | 2514 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 2515 | case Expand: assert(0 && "Not possible"); |
| 2516 | case Legal: |
| 2517 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the RHS. |
| 2518 | break; |
| 2519 | case Promote: |
| 2520 | Tmp2 = PromoteOp(Node->getOperand(1)); // Promote the RHS. |
| 2521 | break; |
| 2522 | } |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2523 | |
| 2524 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2525 | |
Andrew Lenharth | e8f65f1 | 2005-12-24 23:42:32 +0000 | [diff] [blame] | 2526 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
Chris Lattner | bc70cf8 | 2006-04-02 03:57:31 +0000 | [diff] [blame] | 2527 | default: assert(0 && "BinOp legalize operation not supported"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2528 | case TargetLowering::Legal: break; |
| 2529 | case TargetLowering::Custom: |
| 2530 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2531 | if (Tmp1.Val) Result = Tmp1; |
Andrew Lenharth | 57030e3 | 2005-12-25 01:07:37 +0000 | [diff] [blame] | 2532 | break; |
Chris Lattner | bc70cf8 | 2006-04-02 03:57:31 +0000 | [diff] [blame] | 2533 | case TargetLowering::Expand: { |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 2534 | if (Node->getValueType(0) == MVT::i32) { |
| 2535 | switch (Node->getOpcode()) { |
| 2536 | default: assert(0 && "Do not know how to expand this integer BinOp!"); |
| 2537 | case ISD::UDIV: |
| 2538 | case ISD::SDIV: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 2539 | RTLIB::Libcall LC = Node->getOpcode() == ISD::UDIV |
| 2540 | ? RTLIB::UDIV_I32 : RTLIB::SDIV_I32; |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 2541 | SDOperand Dummy; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 2542 | bool isSigned = Node->getOpcode() == ISD::SDIV; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 2543 | Result = ExpandLibCall(TLI.getLibcallName(LC), Node, isSigned, Dummy); |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 2544 | }; |
| 2545 | break; |
| 2546 | } |
| 2547 | |
Chris Lattner | bc70cf8 | 2006-04-02 03:57:31 +0000 | [diff] [blame] | 2548 | assert(MVT::isVector(Node->getValueType(0)) && |
| 2549 | "Cannot expand this binary operator!"); |
| 2550 | // Expand the operation into a bunch of nasty scalar code. |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 2551 | SmallVector<SDOperand, 8> Ops; |
Dan Gohman | 51eaa86 | 2007-06-14 22:58:02 +0000 | [diff] [blame] | 2552 | MVT::ValueType EltVT = MVT::getVectorElementType(Node->getValueType(0)); |
Chris Lattner | bc70cf8 | 2006-04-02 03:57:31 +0000 | [diff] [blame] | 2553 | MVT::ValueType PtrVT = TLI.getPointerTy(); |
| 2554 | for (unsigned i = 0, e = MVT::getVectorNumElements(Node->getValueType(0)); |
| 2555 | i != e; ++i) { |
| 2556 | SDOperand Idx = DAG.getConstant(i, PtrVT); |
| 2557 | SDOperand LHS = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, EltVT, Tmp1, Idx); |
| 2558 | SDOperand RHS = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, EltVT, Tmp2, Idx); |
| 2559 | Ops.push_back(DAG.getNode(Node->getOpcode(), EltVT, LHS, RHS)); |
| 2560 | } |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 2561 | Result = DAG.getNode(ISD::BUILD_VECTOR, Node->getValueType(0), |
| 2562 | &Ops[0], Ops.size()); |
Chris Lattner | bc70cf8 | 2006-04-02 03:57:31 +0000 | [diff] [blame] | 2563 | break; |
| 2564 | } |
Evan Cheng | cc98761 | 2006-04-12 21:20:24 +0000 | [diff] [blame] | 2565 | case TargetLowering::Promote: { |
| 2566 | switch (Node->getOpcode()) { |
| 2567 | default: assert(0 && "Do not know how to promote this BinOp!"); |
| 2568 | case ISD::AND: |
| 2569 | case ISD::OR: |
| 2570 | case ISD::XOR: { |
| 2571 | MVT::ValueType OVT = Node->getValueType(0); |
| 2572 | MVT::ValueType NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT); |
| 2573 | assert(MVT::isVector(OVT) && "Cannot promote this BinOp!"); |
| 2574 | // Bit convert each of the values to the new type. |
| 2575 | Tmp1 = DAG.getNode(ISD::BIT_CONVERT, NVT, Tmp1); |
| 2576 | Tmp2 = DAG.getNode(ISD::BIT_CONVERT, NVT, Tmp2); |
| 2577 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 2578 | // Bit convert the result back the original type. |
| 2579 | Result = DAG.getNode(ISD::BIT_CONVERT, OVT, Result); |
| 2580 | break; |
| 2581 | } |
| 2582 | } |
| 2583 | } |
Andrew Lenharth | e8f65f1 | 2005-12-24 23:42:32 +0000 | [diff] [blame] | 2584 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2585 | break; |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 2586 | |
| 2587 | case ISD::FCOPYSIGN: // FCOPYSIGN does not require LHS/RHS to match type! |
| 2588 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
| 2589 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 2590 | case Expand: assert(0 && "Not possible"); |
| 2591 | case Legal: |
| 2592 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the RHS. |
| 2593 | break; |
| 2594 | case Promote: |
| 2595 | Tmp2 = PromoteOp(Node->getOperand(1)); // Promote the RHS. |
| 2596 | break; |
| 2597 | } |
| 2598 | |
| 2599 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 2600 | |
| 2601 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 2602 | default: assert(0 && "Operation not supported"); |
| 2603 | case TargetLowering::Custom: |
| 2604 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2605 | if (Tmp1.Val) Result = Tmp1; |
Chris Lattner | 8f4191d | 2006-03-13 06:08:38 +0000 | [diff] [blame] | 2606 | break; |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 2607 | case TargetLowering::Legal: break; |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 2608 | case TargetLowering::Expand: { |
Evan Cheng | 636c753 | 2007-01-05 23:33:44 +0000 | [diff] [blame] | 2609 | // If this target supports fabs/fneg natively and select is cheap, |
| 2610 | // do this efficiently. |
| 2611 | if (!TLI.isSelectExpensive() && |
| 2612 | TLI.getOperationAction(ISD::FABS, Tmp1.getValueType()) == |
| 2613 | TargetLowering::Legal && |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 2614 | TLI.getOperationAction(ISD::FNEG, Tmp1.getValueType()) == |
Evan Cheng | 636c753 | 2007-01-05 23:33:44 +0000 | [diff] [blame] | 2615 | TargetLowering::Legal) { |
Chris Lattner | 8f4191d | 2006-03-13 06:08:38 +0000 | [diff] [blame] | 2616 | // Get the sign bit of the RHS. |
| 2617 | MVT::ValueType IVT = |
| 2618 | Tmp2.getValueType() == MVT::f32 ? MVT::i32 : MVT::i64; |
| 2619 | SDOperand SignBit = DAG.getNode(ISD::BIT_CONVERT, IVT, Tmp2); |
| 2620 | SignBit = DAG.getSetCC(TLI.getSetCCResultTy(), |
| 2621 | SignBit, DAG.getConstant(0, IVT), ISD::SETLT); |
| 2622 | // Get the absolute value of the result. |
| 2623 | SDOperand AbsVal = DAG.getNode(ISD::FABS, Tmp1.getValueType(), Tmp1); |
| 2624 | // Select between the nabs and abs value based on the sign bit of |
| 2625 | // the input. |
| 2626 | Result = DAG.getNode(ISD::SELECT, AbsVal.getValueType(), SignBit, |
| 2627 | DAG.getNode(ISD::FNEG, AbsVal.getValueType(), |
| 2628 | AbsVal), |
| 2629 | AbsVal); |
| 2630 | Result = LegalizeOp(Result); |
| 2631 | break; |
| 2632 | } |
| 2633 | |
| 2634 | // Otherwise, do bitwise ops! |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 2635 | MVT::ValueType NVT = |
| 2636 | Node->getValueType(0) == MVT::f32 ? MVT::i32 : MVT::i64; |
| 2637 | Result = ExpandFCOPYSIGNToBitwiseOps(Node, NVT, DAG, TLI); |
| 2638 | Result = DAG.getNode(ISD::BIT_CONVERT, Node->getValueType(0), Result); |
| 2639 | Result = LegalizeOp(Result); |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 2640 | break; |
| 2641 | } |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 2642 | } |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 2643 | break; |
| 2644 | |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 2645 | case ISD::ADDC: |
| 2646 | case ISD::SUBC: |
| 2647 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 2648 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 2649 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 2650 | // Since this produces two values, make sure to remember that we legalized |
| 2651 | // both of them. |
| 2652 | AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0)); |
| 2653 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
| 2654 | return Result; |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2655 | |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 2656 | case ISD::ADDE: |
| 2657 | case ISD::SUBE: |
| 2658 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 2659 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 2660 | Tmp3 = LegalizeOp(Node->getOperand(2)); |
| 2661 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
| 2662 | // Since this produces two values, make sure to remember that we legalized |
| 2663 | // both of them. |
| 2664 | AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0)); |
| 2665 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
| 2666 | return Result; |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 2667 | |
Nate Begeman | 419f8b6 | 2005-10-18 00:27:41 +0000 | [diff] [blame] | 2668 | case ISD::BUILD_PAIR: { |
| 2669 | MVT::ValueType PairTy = Node->getValueType(0); |
| 2670 | // TODO: handle the case where the Lo and Hi operands are not of legal type |
| 2671 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Lo |
| 2672 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Hi |
| 2673 | switch (TLI.getOperationAction(ISD::BUILD_PAIR, PairTy)) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2674 | case TargetLowering::Promote: |
| 2675 | case TargetLowering::Custom: |
| 2676 | assert(0 && "Cannot promote/custom this yet!"); |
Nate Begeman | 419f8b6 | 2005-10-18 00:27:41 +0000 | [diff] [blame] | 2677 | case TargetLowering::Legal: |
| 2678 | if (Tmp1 != Node->getOperand(0) || Tmp2 != Node->getOperand(1)) |
| 2679 | Result = DAG.getNode(ISD::BUILD_PAIR, PairTy, Tmp1, Tmp2); |
| 2680 | break; |
Nate Begeman | 419f8b6 | 2005-10-18 00:27:41 +0000 | [diff] [blame] | 2681 | case TargetLowering::Expand: |
| 2682 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, PairTy, Tmp1); |
| 2683 | Tmp2 = DAG.getNode(ISD::ANY_EXTEND, PairTy, Tmp2); |
| 2684 | Tmp2 = DAG.getNode(ISD::SHL, PairTy, Tmp2, |
| 2685 | DAG.getConstant(MVT::getSizeInBits(PairTy)/2, |
| 2686 | TLI.getShiftAmountTy())); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2687 | Result = DAG.getNode(ISD::OR, PairTy, Tmp1, Tmp2); |
Nate Begeman | 419f8b6 | 2005-10-18 00:27:41 +0000 | [diff] [blame] | 2688 | break; |
| 2689 | } |
| 2690 | break; |
| 2691 | } |
| 2692 | |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 2693 | case ISD::UREM: |
| 2694 | case ISD::SREM: |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 2695 | case ISD::FREM: |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 2696 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
| 2697 | Tmp2 = LegalizeOp(Node->getOperand(1)); // RHS |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2698 | |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 2699 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2700 | case TargetLowering::Promote: assert(0 && "Cannot promote this yet!"); |
| 2701 | case TargetLowering::Custom: |
| 2702 | isCustom = true; |
| 2703 | // FALLTHROUGH |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 2704 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2705 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2706 | if (isCustom) { |
| 2707 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2708 | if (Tmp1.Val) Result = Tmp1; |
| 2709 | } |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 2710 | break; |
Chris Lattner | 4c64dd7 | 2005-08-03 20:31:37 +0000 | [diff] [blame] | 2711 | case TargetLowering::Expand: |
Evan Cheng | 6b5578f | 2006-09-18 23:28:33 +0000 | [diff] [blame] | 2712 | unsigned DivOpc= (Node->getOpcode() == ISD::UREM) ? ISD::UDIV : ISD::SDIV; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 2713 | bool isSigned = DivOpc == ISD::SDIV; |
Chris Lattner | 4c64dd7 | 2005-08-03 20:31:37 +0000 | [diff] [blame] | 2714 | if (MVT::isInteger(Node->getValueType(0))) { |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 2715 | if (TLI.getOperationAction(DivOpc, Node->getValueType(0)) == |
| 2716 | TargetLowering::Legal) { |
| 2717 | // X % Y -> X-X/Y*Y |
| 2718 | MVT::ValueType VT = Node->getValueType(0); |
Evan Cheng | 6b5578f | 2006-09-18 23:28:33 +0000 | [diff] [blame] | 2719 | Result = DAG.getNode(DivOpc, VT, Tmp1, Tmp2); |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 2720 | Result = DAG.getNode(ISD::MUL, VT, Result, Tmp2); |
| 2721 | Result = DAG.getNode(ISD::SUB, VT, Tmp1, Result); |
| 2722 | } else { |
| 2723 | assert(Node->getValueType(0) == MVT::i32 && |
| 2724 | "Cannot expand this binary operator!"); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 2725 | RTLIB::Libcall LC = Node->getOpcode() == ISD::UREM |
| 2726 | ? RTLIB::UREM_I32 : RTLIB::SREM_I32; |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 2727 | SDOperand Dummy; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 2728 | Result = ExpandLibCall(TLI.getLibcallName(LC), Node, isSigned, Dummy); |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 2729 | } |
Chris Lattner | 4c64dd7 | 2005-08-03 20:31:37 +0000 | [diff] [blame] | 2730 | } else { |
| 2731 | // Floating point mod -> fmod libcall. |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 2732 | RTLIB::Libcall LC = Node->getValueType(0) == MVT::f32 |
| 2733 | ? RTLIB::REM_F32 : RTLIB::REM_F64; |
Chris Lattner | 4c64dd7 | 2005-08-03 20:31:37 +0000 | [diff] [blame] | 2734 | SDOperand Dummy; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 2735 | Result = ExpandLibCall(TLI.getLibcallName(LC), Node, |
| 2736 | false/*sign irrelevant*/, Dummy); |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 2737 | } |
| 2738 | break; |
| 2739 | } |
| 2740 | break; |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 2741 | case ISD::VAARG: { |
| 2742 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 2743 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. |
| 2744 | |
Chris Lattner | 5c62f33 | 2006-01-28 07:42:08 +0000 | [diff] [blame] | 2745 | MVT::ValueType VT = Node->getValueType(0); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 2746 | switch (TLI.getOperationAction(Node->getOpcode(), MVT::Other)) { |
| 2747 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2748 | case TargetLowering::Custom: |
| 2749 | isCustom = true; |
| 2750 | // FALLTHROUGH |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 2751 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2752 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
| 2753 | Result = Result.getValue(0); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2754 | Tmp1 = Result.getValue(1); |
| 2755 | |
| 2756 | if (isCustom) { |
| 2757 | Tmp2 = TLI.LowerOperation(Result, DAG); |
| 2758 | if (Tmp2.Val) { |
| 2759 | Result = LegalizeOp(Tmp2); |
| 2760 | Tmp1 = LegalizeOp(Tmp2.getValue(1)); |
| 2761 | } |
| 2762 | } |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 2763 | break; |
| 2764 | case TargetLowering::Expand: { |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2765 | SrcValueSDNode *SV = cast<SrcValueSDNode>(Node->getOperand(2)); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 2766 | SDOperand VAList = DAG.getLoad(TLI.getPointerTy(), Tmp1, Tmp2, |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2767 | SV->getValue(), SV->getOffset()); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 2768 | // Increment the pointer, VAList, to the next vaarg |
| 2769 | Tmp3 = DAG.getNode(ISD::ADD, TLI.getPointerTy(), VAList, |
| 2770 | DAG.getConstant(MVT::getSizeInBits(VT)/8, |
| 2771 | TLI.getPointerTy())); |
| 2772 | // Store the incremented VAList to the legalized pointer |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2773 | Tmp3 = DAG.getStore(VAList.getValue(1), Tmp3, Tmp2, SV->getValue(), |
| 2774 | SV->getOffset()); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 2775 | // Load the actual argument out of the pointer VAList |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2776 | Result = DAG.getLoad(VT, Tmp3, VAList, NULL, 0); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2777 | Tmp1 = LegalizeOp(Result.getValue(1)); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 2778 | Result = LegalizeOp(Result); |
| 2779 | break; |
| 2780 | } |
| 2781 | } |
| 2782 | // Since VAARG produces two values, make sure to remember that we |
| 2783 | // legalized both of them. |
| 2784 | AddLegalizedOperand(SDOperand(Node, 0), Result); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2785 | AddLegalizedOperand(SDOperand(Node, 1), Tmp1); |
| 2786 | return Op.ResNo ? Tmp1 : Result; |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 2787 | } |
| 2788 | |
| 2789 | case ISD::VACOPY: |
| 2790 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 2791 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the dest pointer. |
| 2792 | Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the source pointer. |
| 2793 | |
| 2794 | switch (TLI.getOperationAction(ISD::VACOPY, MVT::Other)) { |
| 2795 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2796 | case TargetLowering::Custom: |
| 2797 | isCustom = true; |
| 2798 | // FALLTHROUGH |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 2799 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2800 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3, |
| 2801 | Node->getOperand(3), Node->getOperand(4)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2802 | if (isCustom) { |
| 2803 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2804 | if (Tmp1.Val) Result = Tmp1; |
| 2805 | } |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 2806 | break; |
| 2807 | case TargetLowering::Expand: |
| 2808 | // This defaults to loading a pointer from the input and storing it to the |
| 2809 | // output, returning the chain. |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2810 | SrcValueSDNode *SVD = cast<SrcValueSDNode>(Node->getOperand(3)); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2811 | SrcValueSDNode *SVS = cast<SrcValueSDNode>(Node->getOperand(4)); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2812 | Tmp4 = DAG.getLoad(TLI.getPointerTy(), Tmp1, Tmp3, SVD->getValue(), |
| 2813 | SVD->getOffset()); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2814 | Result = DAG.getStore(Tmp4.getValue(1), Tmp4, Tmp2, SVS->getValue(), |
| 2815 | SVS->getOffset()); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 2816 | break; |
| 2817 | } |
| 2818 | break; |
| 2819 | |
| 2820 | case ISD::VAEND: |
| 2821 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 2822 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. |
| 2823 | |
| 2824 | switch (TLI.getOperationAction(ISD::VAEND, MVT::Other)) { |
| 2825 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2826 | case TargetLowering::Custom: |
| 2827 | isCustom = true; |
| 2828 | // FALLTHROUGH |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 2829 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2830 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2831 | if (isCustom) { |
| 2832 | Tmp1 = TLI.LowerOperation(Tmp1, DAG); |
| 2833 | if (Tmp1.Val) Result = Tmp1; |
| 2834 | } |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 2835 | break; |
| 2836 | case TargetLowering::Expand: |
| 2837 | Result = Tmp1; // Default to a no-op, return the chain |
| 2838 | break; |
| 2839 | } |
| 2840 | break; |
| 2841 | |
| 2842 | case ISD::VASTART: |
| 2843 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 2844 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. |
| 2845 | |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2846 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
| 2847 | |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 2848 | switch (TLI.getOperationAction(ISD::VASTART, MVT::Other)) { |
| 2849 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2850 | case TargetLowering::Legal: break; |
| 2851 | case TargetLowering::Custom: |
| 2852 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2853 | if (Tmp1.Val) Result = Tmp1; |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 2854 | break; |
| 2855 | } |
| 2856 | break; |
| 2857 | |
Nate Begeman | 35ef913 | 2006-01-11 21:21:00 +0000 | [diff] [blame] | 2858 | case ISD::ROTL: |
| 2859 | case ISD::ROTR: |
| 2860 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
| 2861 | Tmp2 = LegalizeOp(Node->getOperand(1)); // RHS |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2862 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Scott Michel | c9dc114 | 2007-04-02 21:36:32 +0000 | [diff] [blame] | 2863 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 2864 | default: |
| 2865 | assert(0 && "ROTL/ROTR legalize operation not supported"); |
| 2866 | break; |
| 2867 | case TargetLowering::Legal: |
| 2868 | break; |
| 2869 | case TargetLowering::Custom: |
| 2870 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2871 | if (Tmp1.Val) Result = Tmp1; |
| 2872 | break; |
| 2873 | case TargetLowering::Promote: |
| 2874 | assert(0 && "Do not know how to promote ROTL/ROTR"); |
| 2875 | break; |
| 2876 | case TargetLowering::Expand: |
| 2877 | assert(0 && "Do not know how to expand ROTL/ROTR"); |
| 2878 | break; |
| 2879 | } |
Nate Begeman | 35ef913 | 2006-01-11 21:21:00 +0000 | [diff] [blame] | 2880 | break; |
| 2881 | |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 2882 | case ISD::BSWAP: |
| 2883 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Op |
| 2884 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2885 | case TargetLowering::Custom: |
| 2886 | assert(0 && "Cannot custom legalize this yet!"); |
| 2887 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2888 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2889 | break; |
| 2890 | case TargetLowering::Promote: { |
| 2891 | MVT::ValueType OVT = Tmp1.getValueType(); |
| 2892 | MVT::ValueType NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT); |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 2893 | unsigned DiffBits = MVT::getSizeInBits(NVT) - MVT::getSizeInBits(OVT); |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 2894 | |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2895 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Tmp1); |
| 2896 | Tmp1 = DAG.getNode(ISD::BSWAP, NVT, Tmp1); |
| 2897 | Result = DAG.getNode(ISD::SRL, NVT, Tmp1, |
| 2898 | DAG.getConstant(DiffBits, TLI.getShiftAmountTy())); |
| 2899 | break; |
| 2900 | } |
| 2901 | case TargetLowering::Expand: |
| 2902 | Result = ExpandBSWAP(Tmp1); |
| 2903 | break; |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 2904 | } |
| 2905 | break; |
| 2906 | |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 2907 | case ISD::CTPOP: |
| 2908 | case ISD::CTTZ: |
| 2909 | case ISD::CTLZ: |
| 2910 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Op |
| 2911 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
Scott Michel | 910b66d | 2007-07-30 21:00:31 +0000 | [diff] [blame] | 2912 | case TargetLowering::Custom: |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 2913 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2914 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Scott Michel | 910b66d | 2007-07-30 21:00:31 +0000 | [diff] [blame] | 2915 | if (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0)) == |
Scott Michel | 335f4f7 | 2007-08-02 02:22:46 +0000 | [diff] [blame] | 2916 | TargetLowering::Custom) { |
| 2917 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2918 | if (Tmp1.Val) { |
| 2919 | Result = Tmp1; |
| 2920 | } |
Scott Michel | 910b66d | 2007-07-30 21:00:31 +0000 | [diff] [blame] | 2921 | } |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 2922 | break; |
| 2923 | case TargetLowering::Promote: { |
| 2924 | MVT::ValueType OVT = Tmp1.getValueType(); |
| 2925 | MVT::ValueType NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT); |
Chris Lattner | edb1add | 2005-05-11 04:51:16 +0000 | [diff] [blame] | 2926 | |
| 2927 | // Zero extend the argument. |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 2928 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Tmp1); |
| 2929 | // Perform the larger operation, then subtract if needed. |
| 2930 | Tmp1 = DAG.getNode(Node->getOpcode(), Node->getValueType(0), Tmp1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2931 | switch (Node->getOpcode()) { |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 2932 | case ISD::CTPOP: |
| 2933 | Result = Tmp1; |
| 2934 | break; |
| 2935 | case ISD::CTTZ: |
| 2936 | //if Tmp1 == sizeinbits(NVT) then Tmp1 = sizeinbits(Old VT) |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 2937 | Tmp2 = DAG.getSetCC(TLI.getSetCCResultTy(), Tmp1, |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 2938 | DAG.getConstant(MVT::getSizeInBits(NVT), NVT), |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 2939 | ISD::SETEQ); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 2940 | Result = DAG.getNode(ISD::SELECT, NVT, Tmp2, |
Scott Michel | 910b66d | 2007-07-30 21:00:31 +0000 | [diff] [blame] | 2941 | DAG.getConstant(MVT::getSizeInBits(OVT),NVT), Tmp1); |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 2942 | break; |
| 2943 | case ISD::CTLZ: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2944 | // Tmp1 = Tmp1 - (sizeinbits(NVT) - sizeinbits(Old VT)) |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 2945 | Result = DAG.getNode(ISD::SUB, NVT, Tmp1, |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 2946 | DAG.getConstant(MVT::getSizeInBits(NVT) - |
| 2947 | MVT::getSizeInBits(OVT), NVT)); |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 2948 | break; |
| 2949 | } |
| 2950 | break; |
| 2951 | } |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 2952 | case TargetLowering::Expand: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2953 | Result = ExpandBitCount(Node->getOpcode(), Tmp1); |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 2954 | break; |
| 2955 | } |
| 2956 | break; |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 2957 | |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 2958 | // Unary operators |
| 2959 | case ISD::FABS: |
| 2960 | case ISD::FNEG: |
Chris Lattner | da6ba87 | 2005-04-28 21:44:33 +0000 | [diff] [blame] | 2961 | case ISD::FSQRT: |
| 2962 | case ISD::FSIN: |
| 2963 | case ISD::FCOS: |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 2964 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 2965 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2966 | case TargetLowering::Promote: |
| 2967 | case TargetLowering::Custom: |
Evan Cheng | 59ad781 | 2006-01-31 18:14:25 +0000 | [diff] [blame] | 2968 | isCustom = true; |
| 2969 | // FALLTHROUGH |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 2970 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2971 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Evan Cheng | 59ad781 | 2006-01-31 18:14:25 +0000 | [diff] [blame] | 2972 | if (isCustom) { |
| 2973 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2974 | if (Tmp1.Val) Result = Tmp1; |
| 2975 | } |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 2976 | break; |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 2977 | case TargetLowering::Expand: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2978 | switch (Node->getOpcode()) { |
| 2979 | default: assert(0 && "Unreachable!"); |
| 2980 | case ISD::FNEG: |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 2981 | // Expand Y = FNEG(X) -> Y = SUB -0.0, X |
| 2982 | Tmp2 = DAG.getConstantFP(-0.0, Node->getValueType(0)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2983 | Result = DAG.getNode(ISD::FSUB, Node->getValueType(0), Tmp2, Tmp1); |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 2984 | break; |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 2985 | case ISD::FABS: { |
Chris Lattner | 4af6e0d | 2005-04-02 05:26:37 +0000 | [diff] [blame] | 2986 | // Expand Y = FABS(X) -> Y = (X >u 0.0) ? X : fneg(X). |
| 2987 | MVT::ValueType VT = Node->getValueType(0); |
| 2988 | Tmp2 = DAG.getConstantFP(0.0, VT); |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 2989 | Tmp2 = DAG.getSetCC(TLI.getSetCCResultTy(), Tmp1, Tmp2, ISD::SETUGT); |
Chris Lattner | 4af6e0d | 2005-04-02 05:26:37 +0000 | [diff] [blame] | 2990 | Tmp3 = DAG.getNode(ISD::FNEG, VT, Tmp1); |
| 2991 | Result = DAG.getNode(ISD::SELECT, VT, Tmp2, Tmp1, Tmp3); |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 2992 | break; |
| 2993 | } |
| 2994 | case ISD::FSQRT: |
| 2995 | case ISD::FSIN: |
| 2996 | case ISD::FCOS: { |
| 2997 | MVT::ValueType VT = Node->getValueType(0); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 2998 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 2999 | switch(Node->getOpcode()) { |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3000 | case ISD::FSQRT: |
| 3001 | LC = VT == MVT::f32 ? RTLIB::SQRT_F32 : RTLIB::SQRT_F64; |
| 3002 | break; |
| 3003 | case ISD::FSIN: |
| 3004 | LC = VT == MVT::f32 ? RTLIB::SIN_F32 : RTLIB::SIN_F64; |
| 3005 | break; |
| 3006 | case ISD::FCOS: |
| 3007 | LC = VT == MVT::f32 ? RTLIB::COS_F32 : RTLIB::COS_F64; |
| 3008 | break; |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 3009 | default: assert(0 && "Unreachable!"); |
| 3010 | } |
Nate Begeman | 2ac4fc0 | 2005-08-04 21:43:28 +0000 | [diff] [blame] | 3011 | SDOperand Dummy; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3012 | Result = ExpandLibCall(TLI.getLibcallName(LC), Node, |
| 3013 | false/*sign irrelevant*/, Dummy); |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 3014 | break; |
| 3015 | } |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3016 | } |
| 3017 | break; |
| 3018 | } |
| 3019 | break; |
Chris Lattner | 6ddf8ed | 2006-09-09 06:03:30 +0000 | [diff] [blame] | 3020 | case ISD::FPOWI: { |
| 3021 | // We always lower FPOWI into a libcall. No target support it yet. |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3022 | RTLIB::Libcall LC = Node->getValueType(0) == MVT::f32 |
| 3023 | ? RTLIB::POWI_F32 : RTLIB::POWI_F64; |
Chris Lattner | 6ddf8ed | 2006-09-09 06:03:30 +0000 | [diff] [blame] | 3024 | SDOperand Dummy; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3025 | Result = ExpandLibCall(TLI.getLibcallName(LC), Node, |
| 3026 | false/*sign irrelevant*/, Dummy); |
Chris Lattner | 6ddf8ed | 2006-09-09 06:03:30 +0000 | [diff] [blame] | 3027 | break; |
| 3028 | } |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 3029 | case ISD::BIT_CONVERT: |
Chris Lattner | 67993f7 | 2006-01-23 07:30:46 +0000 | [diff] [blame] | 3030 | if (!isTypeLegal(Node->getOperand(0).getValueType())) { |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 3031 | Result = ExpandBIT_CONVERT(Node->getValueType(0), Node->getOperand(0)); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3032 | } else if (MVT::isVector(Op.getOperand(0).getValueType())) { |
| 3033 | // The input has to be a vector type, we have to either scalarize it, pack |
| 3034 | // it, or convert it based on whether the input vector type is legal. |
| 3035 | SDNode *InVal = Node->getOperand(0).Val; |
| 3036 | unsigned NumElems = MVT::getVectorNumElements(InVal->getValueType(0)); |
| 3037 | MVT::ValueType EVT = MVT::getVectorElementType(InVal->getValueType(0)); |
| 3038 | |
| 3039 | // Figure out if there is a simple type corresponding to this Vector |
| 3040 | // type. If so, convert to the vector type. |
| 3041 | MVT::ValueType TVT = MVT::getVectorType(EVT, NumElems); |
| 3042 | if (TLI.isTypeLegal(TVT)) { |
Dan Gohman | 07a9676 | 2007-07-16 14:29:03 +0000 | [diff] [blame] | 3043 | // Turn this into a bit convert of the vector input. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3044 | Result = DAG.getNode(ISD::BIT_CONVERT, Node->getValueType(0), |
| 3045 | LegalizeOp(Node->getOperand(0))); |
| 3046 | break; |
| 3047 | } else if (NumElems == 1) { |
| 3048 | // Turn this into a bit convert of the scalar input. |
| 3049 | Result = DAG.getNode(ISD::BIT_CONVERT, Node->getValueType(0), |
| 3050 | ScalarizeVectorOp(Node->getOperand(0))); |
| 3051 | break; |
| 3052 | } else { |
| 3053 | // FIXME: UNIMP! Store then reload |
| 3054 | assert(0 && "Cast from unsupported vector type not implemented yet!"); |
| 3055 | } |
Chris Lattner | 67993f7 | 2006-01-23 07:30:46 +0000 | [diff] [blame] | 3056 | } else { |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 3057 | switch (TLI.getOperationAction(ISD::BIT_CONVERT, |
| 3058 | Node->getOperand(0).getValueType())) { |
| 3059 | default: assert(0 && "Unknown operation action!"); |
| 3060 | case TargetLowering::Expand: |
| 3061 | Result = ExpandBIT_CONVERT(Node->getValueType(0), Node->getOperand(0)); |
| 3062 | break; |
| 3063 | case TargetLowering::Legal: |
| 3064 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3065 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 3066 | break; |
| 3067 | } |
| 3068 | } |
| 3069 | break; |
Chris Lattner | d1f04d4 | 2006-03-24 02:26:29 +0000 | [diff] [blame] | 3070 | |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3071 | // Conversion operators. The source and destination have different types. |
Chris Lattner | ae0aacb | 2005-01-08 08:08:56 +0000 | [diff] [blame] | 3072 | case ISD::SINT_TO_FP: |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3073 | case ISD::UINT_TO_FP: { |
| 3074 | bool isSigned = Node->getOpcode() == ISD::SINT_TO_FP; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3075 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3076 | case Legal: |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 3077 | switch (TLI.getOperationAction(Node->getOpcode(), |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3078 | Node->getOperand(0).getValueType())) { |
| 3079 | default: assert(0 && "Unknown operation action!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3080 | case TargetLowering::Custom: |
| 3081 | isCustom = true; |
| 3082 | // FALLTHROUGH |
| 3083 | case TargetLowering::Legal: |
| 3084 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3085 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3086 | if (isCustom) { |
| 3087 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 3088 | if (Tmp1.Val) Result = Tmp1; |
| 3089 | } |
| 3090 | break; |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3091 | case TargetLowering::Expand: |
Jim Laskey | 6269ed1 | 2005-08-17 00:39:29 +0000 | [diff] [blame] | 3092 | Result = ExpandLegalINT_TO_FP(isSigned, |
| 3093 | LegalizeOp(Node->getOperand(0)), |
| 3094 | Node->getValueType(0)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3095 | break; |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3096 | case TargetLowering::Promote: |
| 3097 | Result = PromoteLegalINT_TO_FP(LegalizeOp(Node->getOperand(0)), |
| 3098 | Node->getValueType(0), |
| 3099 | isSigned); |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3100 | break; |
Andrew Lenharth | 5b5b8c2 | 2005-11-30 06:43:03 +0000 | [diff] [blame] | 3101 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3102 | break; |
Chris Lattner | b00a642 | 2005-01-07 22:37:48 +0000 | [diff] [blame] | 3103 | case Expand: |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3104 | Result = ExpandIntToFP(Node->getOpcode() == ISD::SINT_TO_FP, |
| 3105 | Node->getValueType(0), Node->getOperand(0)); |
| 3106 | break; |
| 3107 | case Promote: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3108 | Tmp1 = PromoteOp(Node->getOperand(0)); |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3109 | if (isSigned) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3110 | Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, Tmp1.getValueType(), |
| 3111 | Tmp1, DAG.getValueType(Node->getOperand(0).getValueType())); |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3112 | } else { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3113 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, |
| 3114 | Node->getOperand(0).getValueType()); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 3115 | } |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3116 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 3117 | Result = LegalizeOp(Result); // The 'op' is not necessarily legal! |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3118 | break; |
| 3119 | } |
| 3120 | break; |
| 3121 | } |
| 3122 | case ISD::TRUNCATE: |
| 3123 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3124 | case Legal: |
| 3125 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3126 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3127 | break; |
| 3128 | case Expand: |
| 3129 | ExpandOp(Node->getOperand(0), Tmp1, Tmp2); |
| 3130 | |
| 3131 | // Since the result is legal, we should just be able to truncate the low |
| 3132 | // part of the source. |
| 3133 | Result = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0), Tmp1); |
| 3134 | break; |
| 3135 | case Promote: |
| 3136 | Result = PromoteOp(Node->getOperand(0)); |
| 3137 | Result = DAG.getNode(ISD::TRUNCATE, Op.getValueType(), Result); |
| 3138 | break; |
| 3139 | } |
| 3140 | break; |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 3141 | |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3142 | case ISD::FP_TO_SINT: |
| 3143 | case ISD::FP_TO_UINT: |
| 3144 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3145 | case Legal: |
Chris Lattner | f1fa74e | 2005-07-30 00:04:12 +0000 | [diff] [blame] | 3146 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 3147 | |
Chris Lattner | 1618beb | 2005-07-29 00:11:56 +0000 | [diff] [blame] | 3148 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))){ |
| 3149 | default: assert(0 && "Unknown operation action!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3150 | case TargetLowering::Custom: |
| 3151 | isCustom = true; |
| 3152 | // FALLTHROUGH |
| 3153 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3154 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3155 | if (isCustom) { |
| 3156 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 3157 | if (Tmp1.Val) Result = Tmp1; |
| 3158 | } |
| 3159 | break; |
| 3160 | case TargetLowering::Promote: |
| 3161 | Result = PromoteLegalFP_TO_INT(Tmp1, Node->getValueType(0), |
| 3162 | Node->getOpcode() == ISD::FP_TO_SINT); |
| 3163 | break; |
Chris Lattner | 1618beb | 2005-07-29 00:11:56 +0000 | [diff] [blame] | 3164 | case TargetLowering::Expand: |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 3165 | if (Node->getOpcode() == ISD::FP_TO_UINT) { |
| 3166 | SDOperand True, False; |
| 3167 | MVT::ValueType VT = Node->getOperand(0).getValueType(); |
| 3168 | MVT::ValueType NVT = Node->getValueType(0); |
| 3169 | unsigned ShiftAmt = MVT::getSizeInBits(Node->getValueType(0))-1; |
| 3170 | Tmp2 = DAG.getConstantFP((double)(1ULL << ShiftAmt), VT); |
| 3171 | Tmp3 = DAG.getSetCC(TLI.getSetCCResultTy(), |
| 3172 | Node->getOperand(0), Tmp2, ISD::SETLT); |
| 3173 | True = DAG.getNode(ISD::FP_TO_SINT, NVT, Node->getOperand(0)); |
| 3174 | False = DAG.getNode(ISD::FP_TO_SINT, NVT, |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 3175 | DAG.getNode(ISD::FSUB, VT, Node->getOperand(0), |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 3176 | Tmp2)); |
| 3177 | False = DAG.getNode(ISD::XOR, NVT, False, |
| 3178 | DAG.getConstant(1ULL << ShiftAmt, NVT)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3179 | Result = DAG.getNode(ISD::SELECT, NVT, Tmp3, True, False); |
| 3180 | break; |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 3181 | } else { |
| 3182 | assert(0 && "Do not know how to expand FP_TO_SINT yet!"); |
| 3183 | } |
| 3184 | break; |
Chris Lattner | 07dffd6 | 2005-08-26 00:14:16 +0000 | [diff] [blame] | 3185 | } |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3186 | break; |
Evan Cheng | 6af00d5 | 2006-12-13 01:57:55 +0000 | [diff] [blame] | 3187 | case Expand: { |
| 3188 | // Convert f32 / f64 to i32 / i64. |
| 3189 | MVT::ValueType VT = Op.getValueType(); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3190 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
Evan Cheng | 6af00d5 | 2006-12-13 01:57:55 +0000 | [diff] [blame] | 3191 | switch (Node->getOpcode()) { |
| 3192 | case ISD::FP_TO_SINT: |
| 3193 | if (Node->getOperand(0).getValueType() == MVT::f32) |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3194 | LC = (VT == MVT::i32) |
| 3195 | ? RTLIB::FPTOSINT_F32_I32 : RTLIB::FPTOSINT_F32_I64; |
Evan Cheng | 6af00d5 | 2006-12-13 01:57:55 +0000 | [diff] [blame] | 3196 | else |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3197 | LC = (VT == MVT::i32) |
| 3198 | ? RTLIB::FPTOSINT_F64_I32 : RTLIB::FPTOSINT_F64_I64; |
Evan Cheng | 6af00d5 | 2006-12-13 01:57:55 +0000 | [diff] [blame] | 3199 | break; |
| 3200 | case ISD::FP_TO_UINT: |
| 3201 | if (Node->getOperand(0).getValueType() == MVT::f32) |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3202 | LC = (VT == MVT::i32) |
| 3203 | ? RTLIB::FPTOUINT_F32_I32 : RTLIB::FPTOSINT_F32_I64; |
Evan Cheng | 6af00d5 | 2006-12-13 01:57:55 +0000 | [diff] [blame] | 3204 | else |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3205 | LC = (VT == MVT::i32) |
| 3206 | ? RTLIB::FPTOUINT_F64_I32 : RTLIB::FPTOSINT_F64_I64; |
Evan Cheng | 6af00d5 | 2006-12-13 01:57:55 +0000 | [diff] [blame] | 3207 | break; |
| 3208 | default: assert(0 && "Unreachable!"); |
| 3209 | } |
| 3210 | SDOperand Dummy; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3211 | Result = ExpandLibCall(TLI.getLibcallName(LC), Node, |
| 3212 | false/*sign irrelevant*/, Dummy); |
Evan Cheng | 6af00d5 | 2006-12-13 01:57:55 +0000 | [diff] [blame] | 3213 | break; |
| 3214 | } |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3215 | case Promote: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3216 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 3217 | Result = DAG.UpdateNodeOperands(Result, LegalizeOp(Tmp1)); |
| 3218 | Result = LegalizeOp(Result); |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3219 | break; |
| 3220 | } |
| 3221 | break; |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 3222 | |
Dale Johannesen | ab081c7 | 2007-08-09 17:27:48 +0000 | [diff] [blame] | 3223 | case ISD::FP_EXTEND: |
Dale Johannesen | 5411a39 | 2007-08-09 01:04:01 +0000 | [diff] [blame] | 3224 | case ISD::FP_ROUND: { |
| 3225 | MVT::ValueType newVT = Op.getValueType(); |
| 3226 | MVT::ValueType oldVT = Op.getOperand(0).getValueType(); |
| 3227 | if (TLI.getConvertAction(oldVT, newVT) == TargetLowering::Expand) { |
Dale Johannesen | ab081c7 | 2007-08-09 17:27:48 +0000 | [diff] [blame] | 3228 | // 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] | 3229 | // LOAD pair, targetting a temporary location (a stack slot). |
| 3230 | |
| 3231 | // NOTE: there is a choice here between constantly creating new stack |
| 3232 | // slots and always reusing the same one. We currently always create |
| 3233 | // new ones, as reuse may inhibit scheduling. |
Dale Johannesen | ab081c7 | 2007-08-09 17:27:48 +0000 | [diff] [blame] | 3234 | MVT::ValueType slotVT = |
| 3235 | (Node->getOpcode() == ISD::FP_EXTEND) ? oldVT : newVT; |
| 3236 | const Type *Ty = MVT::getTypeForValueType(slotVT); |
Dale Johannesen | 5411a39 | 2007-08-09 01:04:01 +0000 | [diff] [blame] | 3237 | uint64_t TySize = TLI.getTargetData()->getTypeSize(Ty); |
| 3238 | unsigned Align = TLI.getTargetData()->getPrefTypeAlignment(Ty); |
| 3239 | MachineFunction &MF = DAG.getMachineFunction(); |
| 3240 | int SSFI = |
| 3241 | MF.getFrameInfo()->CreateStackObject(TySize, Align); |
| 3242 | SDOperand StackSlot = DAG.getFrameIndex(SSFI, TLI.getPointerTy()); |
Dale Johannesen | ab081c7 | 2007-08-09 17:27:48 +0000 | [diff] [blame] | 3243 | if (Node->getOpcode() == ISD::FP_EXTEND) { |
| 3244 | Result = DAG.getStore(DAG.getEntryNode(), Node->getOperand(0), |
| 3245 | StackSlot, NULL, 0); |
| 3246 | Result = DAG.getExtLoad(ISD::EXTLOAD, newVT, |
| 3247 | Result, StackSlot, NULL, 0, oldVT); |
| 3248 | } else { |
| 3249 | Result = DAG.getTruncStore(DAG.getEntryNode(), Node->getOperand(0), |
| 3250 | StackSlot, NULL, 0, newVT); |
| 3251 | Result = DAG.getLoad(newVT, Result, StackSlot, NULL, 0, newVT); |
| 3252 | } |
Dale Johannesen | 5411a39 | 2007-08-09 01:04:01 +0000 | [diff] [blame] | 3253 | break; |
| 3254 | } |
Dale Johannesen | 849f214 | 2007-07-03 00:53:03 +0000 | [diff] [blame] | 3255 | } |
| 3256 | // FALL THROUGH |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 3257 | case ISD::ANY_EXTEND: |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3258 | case ISD::ZERO_EXTEND: |
| 3259 | case ISD::SIGN_EXTEND: |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3260 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3261 | case Expand: assert(0 && "Shouldn't need to expand other operators here!"); |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3262 | case Legal: |
| 3263 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3264 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3265 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3266 | case Promote: |
| 3267 | switch (Node->getOpcode()) { |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 3268 | case ISD::ANY_EXTEND: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3269 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 3270 | Result = DAG.getNode(ISD::ANY_EXTEND, Op.getValueType(), Tmp1); |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 3271 | break; |
Chris Lattner | 1713e73 | 2005-01-16 00:38:00 +0000 | [diff] [blame] | 3272 | case ISD::ZERO_EXTEND: |
| 3273 | Result = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 3274 | Result = DAG.getNode(ISD::ANY_EXTEND, Op.getValueType(), Result); |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 3275 | Result = DAG.getZeroExtendInReg(Result, |
| 3276 | Node->getOperand(0).getValueType()); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3277 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3278 | case ISD::SIGN_EXTEND: |
Chris Lattner | 1713e73 | 2005-01-16 00:38:00 +0000 | [diff] [blame] | 3279 | Result = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 3280 | Result = DAG.getNode(ISD::ANY_EXTEND, Op.getValueType(), Result); |
Chris Lattner | 1713e73 | 2005-01-16 00:38:00 +0000 | [diff] [blame] | 3281 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(), |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 3282 | Result, |
| 3283 | DAG.getValueType(Node->getOperand(0).getValueType())); |
Chris Lattner | 1713e73 | 2005-01-16 00:38:00 +0000 | [diff] [blame] | 3284 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3285 | case ISD::FP_EXTEND: |
Chris Lattner | 1713e73 | 2005-01-16 00:38:00 +0000 | [diff] [blame] | 3286 | Result = PromoteOp(Node->getOperand(0)); |
| 3287 | if (Result.getValueType() != Op.getValueType()) |
| 3288 | // Dynamically dead while we have only 2 FP types. |
| 3289 | Result = DAG.getNode(ISD::FP_EXTEND, Op.getValueType(), Result); |
| 3290 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3291 | case ISD::FP_ROUND: |
Chris Lattner | f8161d8 | 2005-01-16 05:06:12 +0000 | [diff] [blame] | 3292 | Result = PromoteOp(Node->getOperand(0)); |
| 3293 | Result = DAG.getNode(Node->getOpcode(), Op.getValueType(), Result); |
| 3294 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3295 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3296 | } |
| 3297 | break; |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 3298 | case ISD::FP_ROUND_INREG: |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 3299 | case ISD::SIGN_EXTEND_INREG: { |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 3300 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 3301 | MVT::ValueType ExtraVT = cast<VTSDNode>(Node->getOperand(1))->getVT(); |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 3302 | |
| 3303 | // If this operation is not supported, convert it to a shl/shr or load/store |
| 3304 | // pair. |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 3305 | switch (TLI.getOperationAction(Node->getOpcode(), ExtraVT)) { |
| 3306 | default: assert(0 && "This action not supported for this op yet!"); |
| 3307 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3308 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 3309 | break; |
| 3310 | case TargetLowering::Expand: |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 3311 | // If this is an integer extend and shifts are supported, do that. |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 3312 | if (Node->getOpcode() == ISD::SIGN_EXTEND_INREG) { |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 3313 | // NOTE: we could fall back on load/store here too for targets without |
| 3314 | // SAR. However, it is doubtful that any exist. |
| 3315 | unsigned BitsDiff = MVT::getSizeInBits(Node->getValueType(0)) - |
| 3316 | MVT::getSizeInBits(ExtraVT); |
Chris Lattner | 27ff112 | 2005-01-22 00:31:52 +0000 | [diff] [blame] | 3317 | SDOperand ShiftCst = DAG.getConstant(BitsDiff, TLI.getShiftAmountTy()); |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 3318 | Result = DAG.getNode(ISD::SHL, Node->getValueType(0), |
| 3319 | Node->getOperand(0), ShiftCst); |
| 3320 | Result = DAG.getNode(ISD::SRA, Node->getValueType(0), |
| 3321 | Result, ShiftCst); |
| 3322 | } else if (Node->getOpcode() == ISD::FP_ROUND_INREG) { |
Jim Laskey | 2d84c4c | 2006-10-11 17:52:19 +0000 | [diff] [blame] | 3323 | // 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] | 3324 | // EXTLOAD pair, targetting a temporary location (a stack slot). |
| 3325 | |
| 3326 | // NOTE: there is a choice here between constantly creating new stack |
| 3327 | // slots and always reusing the same one. We currently always create |
| 3328 | // new ones, as reuse may inhibit scheduling. |
| 3329 | const Type *Ty = MVT::getTypeForValueType(ExtraVT); |
Chris Lattner | 44b2c50 | 2007-04-28 06:42:38 +0000 | [diff] [blame] | 3330 | uint64_t TySize = TLI.getTargetData()->getTypeSize(Ty); |
Chris Lattner | d2b7cec | 2007-02-14 05:52:17 +0000 | [diff] [blame] | 3331 | unsigned Align = TLI.getTargetData()->getPrefTypeAlignment(Ty); |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 3332 | MachineFunction &MF = DAG.getMachineFunction(); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 3333 | int SSFI = |
Chris Lattner | 44b2c50 | 2007-04-28 06:42:38 +0000 | [diff] [blame] | 3334 | MF.getFrameInfo()->CreateStackObject(TySize, Align); |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 3335 | SDOperand StackSlot = DAG.getFrameIndex(SSFI, TLI.getPointerTy()); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 3336 | Result = DAG.getTruncStore(DAG.getEntryNode(), Node->getOperand(0), |
| 3337 | StackSlot, NULL, 0, ExtraVT); |
Chris Lattner | 5f056bf | 2005-07-10 01:55:33 +0000 | [diff] [blame] | 3338 | Result = DAG.getExtLoad(ISD::EXTLOAD, Node->getValueType(0), |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 3339 | Result, StackSlot, NULL, 0, ExtraVT); |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 3340 | } else { |
| 3341 | assert(0 && "Unknown op"); |
| 3342 | } |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 3343 | break; |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 3344 | } |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 3345 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3346 | } |
Duncan Sands | 36397f5 | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 3347 | case ISD::ADJUST_TRAMP: { |
| 3348 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 3349 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 3350 | default: assert(0 && "This action is not supported yet!"); |
| 3351 | case TargetLowering::Custom: |
| 3352 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 3353 | Result = TLI.LowerOperation(Result, DAG); |
| 3354 | if (Result.Val) break; |
| 3355 | // FALL THROUGH |
| 3356 | case TargetLowering::Expand: |
| 3357 | Result = Tmp1; |
| 3358 | break; |
| 3359 | } |
| 3360 | break; |
| 3361 | } |
| 3362 | case ISD::TRAMPOLINE: { |
| 3363 | SDOperand Ops[6]; |
| 3364 | for (unsigned i = 0; i != 6; ++i) |
| 3365 | Ops[i] = LegalizeOp(Node->getOperand(i)); |
| 3366 | Result = DAG.UpdateNodeOperands(Result, Ops, 6); |
| 3367 | // The only option for this node is to custom lower it. |
| 3368 | Result = TLI.LowerOperation(Result, DAG); |
| 3369 | assert(Result.Val && "Should always custom lower!"); |
| 3370 | break; |
| 3371 | } |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 3372 | } |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3373 | |
Chris Lattner | 4ddd283 | 2006-04-08 04:13:17 +0000 | [diff] [blame] | 3374 | assert(Result.getValueType() == Op.getValueType() && |
| 3375 | "Bad legalization!"); |
| 3376 | |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3377 | // Make sure that the generated code is itself legal. |
| 3378 | if (Result != Op) |
| 3379 | Result = LegalizeOp(Result); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3380 | |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 3381 | // Note that LegalizeOp may be reentered even from single-use nodes, which |
| 3382 | // means that we always must cache transformed nodes. |
| 3383 | AddLegalizedOperand(Op, Result); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3384 | return Result; |
| 3385 | } |
| 3386 | |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3387 | /// PromoteOp - Given an operation that produces a value in an invalid type, |
| 3388 | /// promote it to compute the value into a larger type. The produced value will |
| 3389 | /// have the correct bits for the low portion of the register, but no guarantee |
| 3390 | /// 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] | 3391 | SDOperand SelectionDAGLegalize::PromoteOp(SDOperand Op) { |
| 3392 | MVT::ValueType VT = Op.getValueType(); |
Chris Lattner | 71c42a0 | 2005-01-16 01:11:45 +0000 | [diff] [blame] | 3393 | MVT::ValueType NVT = TLI.getTypeToTransformTo(VT); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3394 | assert(getTypeAction(VT) == Promote && |
| 3395 | "Caller should expand or legalize operands that are not promotable!"); |
| 3396 | assert(NVT > VT && MVT::isInteger(NVT) == MVT::isInteger(VT) && |
| 3397 | "Cannot promote to smaller type!"); |
| 3398 | |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3399 | SDOperand Tmp1, Tmp2, Tmp3; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3400 | SDOperand Result; |
| 3401 | SDNode *Node = Op.Val; |
| 3402 | |
Chris Lattner | 40030bf | 2007-02-04 01:17:38 +0000 | [diff] [blame] | 3403 | DenseMap<SDOperand, SDOperand>::iterator I = PromotedNodes.find(Op); |
Chris Lattner | 6fdcb25 | 2005-09-02 20:32:45 +0000 | [diff] [blame] | 3404 | if (I != PromotedNodes.end()) return I->second; |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 3405 | |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3406 | switch (Node->getOpcode()) { |
Chris Lattner | d5d0f9b | 2005-08-16 21:55:35 +0000 | [diff] [blame] | 3407 | case ISD::CopyFromReg: |
| 3408 | assert(0 && "CopyFromReg must be legal!"); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3409 | default: |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 3410 | #ifndef NDEBUG |
Dan Gohman | 3983358 | 2007-06-04 16:17:33 +0000 | [diff] [blame] | 3411 | cerr << "NODE: "; Node->dump(&DAG); cerr << "\n"; |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 3412 | #endif |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3413 | assert(0 && "Do not know how to promote this operator!"); |
| 3414 | abort(); |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 3415 | case ISD::UNDEF: |
| 3416 | Result = DAG.getNode(ISD::UNDEF, NVT); |
| 3417 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3418 | case ISD::Constant: |
Chris Lattner | ec176e3 | 2005-08-30 16:56:19 +0000 | [diff] [blame] | 3419 | if (VT != MVT::i1) |
| 3420 | Result = DAG.getNode(ISD::SIGN_EXTEND, NVT, Op); |
| 3421 | else |
| 3422 | Result = DAG.getNode(ISD::ZERO_EXTEND, NVT, Op); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3423 | assert(isa<ConstantSDNode>(Result) && "Didn't constant fold zext?"); |
| 3424 | break; |
| 3425 | case ISD::ConstantFP: |
| 3426 | Result = DAG.getNode(ISD::FP_EXTEND, NVT, Op); |
| 3427 | assert(isa<ConstantFPSDNode>(Result) && "Didn't constant fold fp_extend?"); |
| 3428 | break; |
Chris Lattner | ef5cd1d | 2005-01-18 17:54:55 +0000 | [diff] [blame] | 3429 | |
Chris Lattner | 82fbfb6 | 2005-01-18 02:59:52 +0000 | [diff] [blame] | 3430 | case ISD::SETCC: |
Chris Lattner | c9c60f6 | 2005-08-24 16:35:28 +0000 | [diff] [blame] | 3431 | assert(isTypeLegal(TLI.getSetCCResultTy()) && "SetCC type is not legal??"); |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 3432 | Result = DAG.getNode(ISD::SETCC, TLI.getSetCCResultTy(),Node->getOperand(0), |
| 3433 | Node->getOperand(1), Node->getOperand(2)); |
Chris Lattner | 82fbfb6 | 2005-01-18 02:59:52 +0000 | [diff] [blame] | 3434 | break; |
Chris Lattner | fdfded5 | 2006-04-12 16:20:43 +0000 | [diff] [blame] | 3435 | |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3436 | case ISD::TRUNCATE: |
| 3437 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3438 | case Legal: |
| 3439 | Result = LegalizeOp(Node->getOperand(0)); |
| 3440 | assert(Result.getValueType() >= NVT && |
| 3441 | "This truncation doesn't make sense!"); |
| 3442 | if (Result.getValueType() > NVT) // Truncate to NVT instead of VT |
| 3443 | Result = DAG.getNode(ISD::TRUNCATE, NVT, Result); |
| 3444 | break; |
Chris Lattner | e76ad6d | 2005-01-28 22:52:50 +0000 | [diff] [blame] | 3445 | case Promote: |
| 3446 | // The truncation is not required, because we don't guarantee anything |
| 3447 | // about high bits anyway. |
| 3448 | Result = PromoteOp(Node->getOperand(0)); |
| 3449 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3450 | case Expand: |
Nate Begeman | 79e46ac | 2005-04-04 00:57:08 +0000 | [diff] [blame] | 3451 | ExpandOp(Node->getOperand(0), Tmp1, Tmp2); |
| 3452 | // Truncate the low part of the expanded value to the result type |
Chris Lattner | e21c305 | 2005-08-01 18:16:37 +0000 | [diff] [blame] | 3453 | Result = DAG.getNode(ISD::TRUNCATE, NVT, Tmp1); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3454 | } |
| 3455 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3456 | case ISD::SIGN_EXTEND: |
| 3457 | case ISD::ZERO_EXTEND: |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 3458 | case ISD::ANY_EXTEND: |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3459 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3460 | case Expand: assert(0 && "BUG: Smaller reg should have been promoted!"); |
| 3461 | case Legal: |
| 3462 | // 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] | 3463 | Result = DAG.getNode(Node->getOpcode(), NVT, Node->getOperand(0)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3464 | break; |
| 3465 | case Promote: |
| 3466 | // Promote the reg if it's smaller. |
| 3467 | Result = PromoteOp(Node->getOperand(0)); |
| 3468 | // The high bits are not guaranteed to be anything. Insert an extend. |
| 3469 | if (Node->getOpcode() == ISD::SIGN_EXTEND) |
Chris Lattner | 595dc54 | 2005-02-04 18:39:19 +0000 | [diff] [blame] | 3470 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Result, |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 3471 | DAG.getValueType(Node->getOperand(0).getValueType())); |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 3472 | else if (Node->getOpcode() == ISD::ZERO_EXTEND) |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 3473 | Result = DAG.getZeroExtendInReg(Result, |
| 3474 | Node->getOperand(0).getValueType()); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3475 | break; |
| 3476 | } |
| 3477 | break; |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 3478 | case ISD::BIT_CONVERT: |
| 3479 | Result = ExpandBIT_CONVERT(Node->getValueType(0), Node->getOperand(0)); |
| 3480 | Result = PromoteOp(Result); |
| 3481 | break; |
| 3482 | |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3483 | case ISD::FP_EXTEND: |
| 3484 | assert(0 && "Case not implemented. Dynamically dead with 2 FP types!"); |
| 3485 | case ISD::FP_ROUND: |
| 3486 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3487 | case Expand: assert(0 && "BUG: Cannot expand FP regs!"); |
| 3488 | case Promote: assert(0 && "Unreachable with 2 FP types!"); |
| 3489 | case Legal: |
| 3490 | // Input is legal? Do an FP_ROUND_INREG. |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3491 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Node->getOperand(0), |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 3492 | DAG.getValueType(VT)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3493 | break; |
| 3494 | } |
| 3495 | break; |
| 3496 | |
| 3497 | case ISD::SINT_TO_FP: |
| 3498 | case ISD::UINT_TO_FP: |
| 3499 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3500 | case Legal: |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 3501 | // No extra round required here. |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3502 | Result = DAG.getNode(Node->getOpcode(), NVT, Node->getOperand(0)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3503 | break; |
| 3504 | |
| 3505 | case Promote: |
| 3506 | Result = PromoteOp(Node->getOperand(0)); |
| 3507 | if (Node->getOpcode() == ISD::SINT_TO_FP) |
| 3508 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(), |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 3509 | Result, |
| 3510 | DAG.getValueType(Node->getOperand(0).getValueType())); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3511 | else |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 3512 | Result = DAG.getZeroExtendInReg(Result, |
| 3513 | Node->getOperand(0).getValueType()); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 3514 | // No extra round required here. |
| 3515 | Result = DAG.getNode(Node->getOpcode(), NVT, Result); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3516 | break; |
| 3517 | case Expand: |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 3518 | Result = ExpandIntToFP(Node->getOpcode() == ISD::SINT_TO_FP, NVT, |
| 3519 | Node->getOperand(0)); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 3520 | // Round if we cannot tolerate excess precision. |
| 3521 | if (NoExcessFPPrecision) |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 3522 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 3523 | DAG.getValueType(VT)); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 3524 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3525 | } |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3526 | break; |
| 3527 | |
Chris Lattner | 5e3c5b4 | 2005-12-09 17:32:47 +0000 | [diff] [blame] | 3528 | case ISD::SIGN_EXTEND_INREG: |
| 3529 | Result = PromoteOp(Node->getOperand(0)); |
| 3530 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Result, |
| 3531 | Node->getOperand(1)); |
| 3532 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3533 | case ISD::FP_TO_SINT: |
| 3534 | case ISD::FP_TO_UINT: |
| 3535 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3536 | case Legal: |
Evan Cheng | 0b1b9dc | 2006-12-16 02:10:30 +0000 | [diff] [blame] | 3537 | case Expand: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3538 | Tmp1 = Node->getOperand(0); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3539 | break; |
| 3540 | case Promote: |
| 3541 | // The input result is prerounded, so we don't have to do anything |
| 3542 | // special. |
| 3543 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 3544 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3545 | } |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 3546 | // If we're promoting a UINT to a larger size, check to see if the new node |
| 3547 | // will be legal. If it isn't, check to see if FP_TO_SINT is legal, since |
| 3548 | // we can use that instead. This allows us to generate better code for |
| 3549 | // FP_TO_UINT for small destination sizes on targets where FP_TO_UINT is not |
| 3550 | // legal, such as PowerPC. |
| 3551 | if (Node->getOpcode() == ISD::FP_TO_UINT && |
Chris Lattner | c9c60f6 | 2005-08-24 16:35:28 +0000 | [diff] [blame] | 3552 | !TLI.isOperationLegal(ISD::FP_TO_UINT, NVT) && |
Nate Begeman | b7f6ef1 | 2005-10-25 23:47:25 +0000 | [diff] [blame] | 3553 | (TLI.isOperationLegal(ISD::FP_TO_SINT, NVT) || |
| 3554 | TLI.getOperationAction(ISD::FP_TO_SINT, NVT)==TargetLowering::Custom)){ |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 3555 | Result = DAG.getNode(ISD::FP_TO_SINT, NVT, Tmp1); |
| 3556 | } else { |
| 3557 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1); |
| 3558 | } |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3559 | break; |
| 3560 | |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3561 | case ISD::FABS: |
| 3562 | case ISD::FNEG: |
| 3563 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 3564 | assert(Tmp1.getValueType() == NVT); |
| 3565 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1); |
| 3566 | // NOTE: we do not have to do any extra rounding here for |
| 3567 | // NoExcessFPPrecision, because we know the input will have the appropriate |
| 3568 | // precision, and these operations don't modify precision at all. |
| 3569 | break; |
| 3570 | |
Chris Lattner | da6ba87 | 2005-04-28 21:44:33 +0000 | [diff] [blame] | 3571 | case ISD::FSQRT: |
| 3572 | case ISD::FSIN: |
| 3573 | case ISD::FCOS: |
| 3574 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 3575 | assert(Tmp1.getValueType() == NVT); |
| 3576 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3577 | if (NoExcessFPPrecision) |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 3578 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 3579 | DAG.getValueType(VT)); |
Chris Lattner | da6ba87 | 2005-04-28 21:44:33 +0000 | [diff] [blame] | 3580 | break; |
| 3581 | |
Chris Lattner | 8b2d42c | 2007-03-03 23:43:21 +0000 | [diff] [blame] | 3582 | case ISD::FPOWI: { |
| 3583 | // Promote f32 powi to f64 powi. Note that this could insert a libcall |
| 3584 | // directly as well, which may be better. |
| 3585 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 3586 | assert(Tmp1.getValueType() == NVT); |
| 3587 | Result = DAG.getNode(ISD::FPOWI, NVT, Tmp1, Node->getOperand(1)); |
| 3588 | if (NoExcessFPPrecision) |
| 3589 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 3590 | DAG.getValueType(VT)); |
| 3591 | break; |
| 3592 | } |
| 3593 | |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3594 | case ISD::AND: |
| 3595 | case ISD::OR: |
| 3596 | case ISD::XOR: |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 3597 | case ISD::ADD: |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3598 | case ISD::SUB: |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 3599 | case ISD::MUL: |
| 3600 | // 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] | 3601 | // 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] | 3602 | // that too is okay if they are integer operations. |
| 3603 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 3604 | Tmp2 = PromoteOp(Node->getOperand(1)); |
| 3605 | assert(Tmp1.getValueType() == NVT && Tmp2.getValueType() == NVT); |
| 3606 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 3607 | break; |
| 3608 | case ISD::FADD: |
| 3609 | case ISD::FSUB: |
| 3610 | case ISD::FMUL: |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 3611 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 3612 | Tmp2 = PromoteOp(Node->getOperand(1)); |
| 3613 | assert(Tmp1.getValueType() == NVT && Tmp2.getValueType() == NVT); |
| 3614 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 3615 | |
| 3616 | // Floating point operations will give excess precision that we may not be |
| 3617 | // able to tolerate. If we DO allow excess precision, just leave it, |
| 3618 | // otherwise excise it. |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3619 | // FIXME: Why would we need to round FP ops more than integer ones? |
| 3620 | // 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] | 3621 | if (NoExcessFPPrecision) |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 3622 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 3623 | DAG.getValueType(VT)); |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 3624 | break; |
| 3625 | |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3626 | case ISD::SDIV: |
| 3627 | case ISD::SREM: |
| 3628 | // These operators require that their input be sign extended. |
| 3629 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 3630 | Tmp2 = PromoteOp(Node->getOperand(1)); |
| 3631 | if (MVT::isInteger(NVT)) { |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 3632 | Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp1, |
| 3633 | DAG.getValueType(VT)); |
| 3634 | Tmp2 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp2, |
| 3635 | DAG.getValueType(VT)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3636 | } |
| 3637 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 3638 | |
| 3639 | // Perform FP_ROUND: this is probably overly pessimistic. |
| 3640 | if (MVT::isFloatingPoint(NVT) && NoExcessFPPrecision) |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 3641 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 3642 | DAG.getValueType(VT)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3643 | break; |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 3644 | case ISD::FDIV: |
| 3645 | case ISD::FREM: |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 3646 | case ISD::FCOPYSIGN: |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 3647 | // These operators require that their input be fp extended. |
Nate Begeman | ec57fd9 | 2006-05-09 18:20:51 +0000 | [diff] [blame] | 3648 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3649 | case Legal: |
| 3650 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 3651 | break; |
| 3652 | case Promote: |
| 3653 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 3654 | break; |
| 3655 | case Expand: |
| 3656 | assert(0 && "not implemented"); |
| 3657 | } |
| 3658 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 3659 | case Legal: |
| 3660 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 3661 | break; |
| 3662 | case Promote: |
| 3663 | Tmp2 = PromoteOp(Node->getOperand(1)); |
| 3664 | break; |
| 3665 | case Expand: |
| 3666 | assert(0 && "not implemented"); |
| 3667 | } |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 3668 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 3669 | |
| 3670 | // Perform FP_ROUND: this is probably overly pessimistic. |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 3671 | if (NoExcessFPPrecision && Node->getOpcode() != ISD::FCOPYSIGN) |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 3672 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 3673 | DAG.getValueType(VT)); |
| 3674 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3675 | |
| 3676 | case ISD::UDIV: |
| 3677 | case ISD::UREM: |
| 3678 | // These operators require that their input be zero extended. |
| 3679 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 3680 | Tmp2 = PromoteOp(Node->getOperand(1)); |
| 3681 | assert(MVT::isInteger(NVT) && "Operators don't apply to FP!"); |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 3682 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, VT); |
| 3683 | Tmp2 = DAG.getZeroExtendInReg(Tmp2, VT); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3684 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 3685 | break; |
| 3686 | |
| 3687 | case ISD::SHL: |
| 3688 | Tmp1 = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3689 | Result = DAG.getNode(ISD::SHL, NVT, Tmp1, Node->getOperand(1)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3690 | break; |
| 3691 | case ISD::SRA: |
| 3692 | // The input value must be properly sign extended. |
| 3693 | Tmp1 = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 3694 | Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp1, |
| 3695 | DAG.getValueType(VT)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3696 | Result = DAG.getNode(ISD::SRA, NVT, Tmp1, Node->getOperand(1)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3697 | break; |
| 3698 | case ISD::SRL: |
| 3699 | // The input value must be properly zero extended. |
| 3700 | Tmp1 = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 3701 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, VT); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3702 | Result = DAG.getNode(ISD::SRL, NVT, Tmp1, Node->getOperand(1)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3703 | break; |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 3704 | |
| 3705 | case ISD::VAARG: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3706 | Tmp1 = Node->getOperand(0); // Get the chain. |
| 3707 | Tmp2 = Node->getOperand(1); // Get the pointer. |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 3708 | if (TLI.getOperationAction(ISD::VAARG, VT) == TargetLowering::Custom) { |
| 3709 | Tmp3 = DAG.getVAArg(VT, Tmp1, Tmp2, Node->getOperand(2)); |
| 3710 | Result = TLI.CustomPromoteOperation(Tmp3, DAG); |
| 3711 | } else { |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 3712 | SrcValueSDNode *SV = cast<SrcValueSDNode>(Node->getOperand(2)); |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 3713 | SDOperand VAList = DAG.getLoad(TLI.getPointerTy(), Tmp1, Tmp2, |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 3714 | SV->getValue(), SV->getOffset()); |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 3715 | // Increment the pointer, VAList, to the next vaarg |
| 3716 | Tmp3 = DAG.getNode(ISD::ADD, TLI.getPointerTy(), VAList, |
| 3717 | DAG.getConstant(MVT::getSizeInBits(VT)/8, |
| 3718 | TLI.getPointerTy())); |
| 3719 | // Store the incremented VAList to the legalized pointer |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 3720 | Tmp3 = DAG.getStore(VAList.getValue(1), Tmp3, Tmp2, SV->getValue(), |
| 3721 | SV->getOffset()); |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 3722 | // Load the actual argument out of the pointer VAList |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 3723 | Result = DAG.getExtLoad(ISD::EXTLOAD, NVT, Tmp3, VAList, NULL, 0, VT); |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 3724 | } |
| 3725 | // Remember that we legalized the chain. |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3726 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1))); |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 3727 | break; |
| 3728 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 3729 | case ISD::LOAD: { |
| 3730 | LoadSDNode *LD = cast<LoadSDNode>(Node); |
Evan Cheng | 62f2a3c | 2006-10-10 07:51:21 +0000 | [diff] [blame] | 3731 | ISD::LoadExtType ExtType = ISD::isNON_EXTLoad(Node) |
| 3732 | ? ISD::EXTLOAD : LD->getExtensionType(); |
| 3733 | Result = DAG.getExtLoad(ExtType, NVT, |
| 3734 | LD->getChain(), LD->getBasePtr(), |
Chris Lattner | 55b5708 | 2006-10-10 18:54:19 +0000 | [diff] [blame] | 3735 | LD->getSrcValue(), LD->getSrcValueOffset(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 3736 | LD->getLoadedVT(), |
| 3737 | LD->isVolatile(), |
| 3738 | LD->getAlignment()); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3739 | // Remember that we legalized the chain. |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3740 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1))); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3741 | break; |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 3742 | } |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3743 | case ISD::SELECT: |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3744 | Tmp2 = PromoteOp(Node->getOperand(1)); // Legalize the op0 |
| 3745 | Tmp3 = PromoteOp(Node->getOperand(2)); // Legalize the op1 |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3746 | Result = DAG.getNode(ISD::SELECT, NVT, Node->getOperand(0), Tmp2, Tmp3); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3747 | break; |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 3748 | case ISD::SELECT_CC: |
| 3749 | Tmp2 = PromoteOp(Node->getOperand(2)); // True |
| 3750 | Tmp3 = PromoteOp(Node->getOperand(3)); // False |
| 3751 | Result = DAG.getNode(ISD::SELECT_CC, NVT, Node->getOperand(0), |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3752 | Node->getOperand(1), Tmp2, Tmp3, Node->getOperand(4)); |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 3753 | break; |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 3754 | case ISD::BSWAP: |
| 3755 | Tmp1 = Node->getOperand(0); |
| 3756 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Tmp1); |
| 3757 | Tmp1 = DAG.getNode(ISD::BSWAP, NVT, Tmp1); |
| 3758 | Result = DAG.getNode(ISD::SRL, NVT, Tmp1, |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 3759 | DAG.getConstant(MVT::getSizeInBits(NVT) - |
| 3760 | MVT::getSizeInBits(VT), |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 3761 | TLI.getShiftAmountTy())); |
| 3762 | break; |
Andrew Lenharth | fecf095 | 2005-05-04 19:11:05 +0000 | [diff] [blame] | 3763 | case ISD::CTPOP: |
| 3764 | case ISD::CTTZ: |
| 3765 | case ISD::CTLZ: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3766 | // Zero extend the argument |
| 3767 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Node->getOperand(0)); |
Andrew Lenharth | fecf095 | 2005-05-04 19:11:05 +0000 | [diff] [blame] | 3768 | // Perform the larger operation, then subtract if needed. |
| 3769 | Tmp1 = DAG.getNode(Node->getOpcode(), NVT, Tmp1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3770 | switch(Node->getOpcode()) { |
Andrew Lenharth | fecf095 | 2005-05-04 19:11:05 +0000 | [diff] [blame] | 3771 | case ISD::CTPOP: |
| 3772 | Result = Tmp1; |
| 3773 | break; |
| 3774 | case ISD::CTTZ: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3775 | // if Tmp1 == sizeinbits(NVT) then Tmp1 = sizeinbits(Old VT) |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 3776 | Tmp2 = DAG.getSetCC(TLI.getSetCCResultTy(), Tmp1, |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 3777 | DAG.getConstant(MVT::getSizeInBits(NVT), NVT), |
| 3778 | ISD::SETEQ); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 3779 | Result = DAG.getNode(ISD::SELECT, NVT, Tmp2, |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 3780 | DAG.getConstant(MVT::getSizeInBits(VT), NVT), Tmp1); |
Andrew Lenharth | fecf095 | 2005-05-04 19:11:05 +0000 | [diff] [blame] | 3781 | break; |
| 3782 | case ISD::CTLZ: |
| 3783 | //Tmp1 = Tmp1 - (sizeinbits(NVT) - sizeinbits(Old VT)) |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 3784 | Result = DAG.getNode(ISD::SUB, NVT, Tmp1, |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 3785 | DAG.getConstant(MVT::getSizeInBits(NVT) - |
| 3786 | MVT::getSizeInBits(VT), NVT)); |
Andrew Lenharth | fecf095 | 2005-05-04 19:11:05 +0000 | [diff] [blame] | 3787 | break; |
| 3788 | } |
| 3789 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3790 | case ISD::EXTRACT_SUBVECTOR: |
| 3791 | Result = PromoteOp(ExpandEXTRACT_SUBVECTOR(Op)); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 3792 | break; |
Chris Lattner | 4aab2f4 | 2006-04-02 05:06:04 +0000 | [diff] [blame] | 3793 | case ISD::EXTRACT_VECTOR_ELT: |
| 3794 | Result = PromoteOp(ExpandEXTRACT_VECTOR_ELT(Op)); |
| 3795 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3796 | } |
| 3797 | |
| 3798 | assert(Result.Val && "Didn't set a result!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3799 | |
| 3800 | // Make sure the result is itself legal. |
| 3801 | Result = LegalizeOp(Result); |
| 3802 | |
| 3803 | // Remember that we promoted this! |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3804 | AddPromotedOperand(Op, Result); |
| 3805 | return Result; |
| 3806 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3807 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3808 | /// ExpandEXTRACT_VECTOR_ELT - Expand an EXTRACT_VECTOR_ELT operation into |
| 3809 | /// a legal EXTRACT_VECTOR_ELT operation, scalar code, or memory traffic, |
| 3810 | /// based on the vector type. The return type of this matches the element type |
| 3811 | /// of the vector, which may not be legal for the target. |
| 3812 | SDOperand SelectionDAGLegalize::ExpandEXTRACT_VECTOR_ELT(SDOperand Op) { |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 3813 | // We know that operand #0 is the Vec vector. If the index is a constant |
| 3814 | // or if the invec is a supported hardware type, we can use it. Otherwise, |
| 3815 | // lower to a store then an indexed load. |
| 3816 | SDOperand Vec = Op.getOperand(0); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3817 | SDOperand Idx = Op.getOperand(1); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 3818 | |
| 3819 | SDNode *InVal = Vec.Val; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3820 | MVT::ValueType TVT = InVal->getValueType(0); |
| 3821 | unsigned NumElems = MVT::getVectorNumElements(TVT); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 3822 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3823 | switch (TLI.getOperationAction(ISD::EXTRACT_VECTOR_ELT, TVT)) { |
| 3824 | default: assert(0 && "This action is not supported yet!"); |
| 3825 | case TargetLowering::Custom: { |
| 3826 | Vec = LegalizeOp(Vec); |
| 3827 | Op = DAG.UpdateNodeOperands(Op, Vec, Idx); |
| 3828 | SDOperand Tmp3 = TLI.LowerOperation(Op, DAG); |
| 3829 | if (Tmp3.Val) |
| 3830 | return Tmp3; |
| 3831 | break; |
| 3832 | } |
| 3833 | case TargetLowering::Legal: |
| 3834 | if (isTypeLegal(TVT)) { |
| 3835 | Vec = LegalizeOp(Vec); |
| 3836 | Op = DAG.UpdateNodeOperands(Op, Vec, Idx); |
Christopher Lamb | 844228a | 2007-07-26 03:33:13 +0000 | [diff] [blame] | 3837 | return Op; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3838 | } |
| 3839 | break; |
| 3840 | case TargetLowering::Expand: |
| 3841 | break; |
| 3842 | } |
| 3843 | |
| 3844 | if (NumElems == 1) { |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 3845 | // This must be an access of the only element. Return it. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3846 | Op = ScalarizeVectorOp(Vec); |
| 3847 | } else if (!TLI.isTypeLegal(TVT) && isa<ConstantSDNode>(Idx)) { |
| 3848 | ConstantSDNode *CIdx = cast<ConstantSDNode>(Idx); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 3849 | SDOperand Lo, Hi; |
| 3850 | SplitVectorOp(Vec, Lo, Hi); |
| 3851 | if (CIdx->getValue() < NumElems/2) { |
| 3852 | Vec = Lo; |
| 3853 | } else { |
| 3854 | Vec = Hi; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3855 | Idx = DAG.getConstant(CIdx->getValue() - NumElems/2, |
| 3856 | Idx.getValueType()); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 3857 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3858 | |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 3859 | // It's now an extract from the appropriate high or low part. Recurse. |
| 3860 | Op = DAG.UpdateNodeOperands(Op, Vec, Idx); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3861 | Op = ExpandEXTRACT_VECTOR_ELT(Op); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 3862 | } else { |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3863 | // Store the value to a temporary stack slot, then LOAD the scalar |
| 3864 | // element back out. |
| 3865 | SDOperand StackPtr = CreateStackTemporary(Vec.getValueType()); |
| 3866 | SDOperand Ch = DAG.getStore(DAG.getEntryNode(), Vec, StackPtr, NULL, 0); |
| 3867 | |
| 3868 | // Add the offset to the index. |
| 3869 | unsigned EltSize = MVT::getSizeInBits(Op.getValueType())/8; |
| 3870 | Idx = DAG.getNode(ISD::MUL, Idx.getValueType(), Idx, |
| 3871 | DAG.getConstant(EltSize, Idx.getValueType())); |
| 3872 | StackPtr = DAG.getNode(ISD::ADD, Idx.getValueType(), Idx, StackPtr); |
| 3873 | |
| 3874 | Op = DAG.getLoad(Op.getValueType(), Ch, StackPtr, NULL, 0); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 3875 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3876 | return Op; |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 3877 | } |
| 3878 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3879 | /// ExpandEXTRACT_SUBVECTOR - Expand a EXTRACT_SUBVECTOR operation. For now |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 3880 | /// 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] | 3881 | SDOperand SelectionDAGLegalize::ExpandEXTRACT_SUBVECTOR(SDOperand Op) { |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 3882 | // We know that operand #0 is the Vec vector. For now we assume the index |
| 3883 | // is a constant and that the extracted result is a supported hardware type. |
| 3884 | SDOperand Vec = Op.getOperand(0); |
| 3885 | SDOperand Idx = LegalizeOp(Op.getOperand(1)); |
| 3886 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3887 | unsigned NumElems = MVT::getVectorNumElements(Vec.getValueType()); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 3888 | |
| 3889 | if (NumElems == MVT::getVectorNumElements(Op.getValueType())) { |
| 3890 | // This must be an access of the desired vector length. Return it. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3891 | return Vec; |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 3892 | } |
| 3893 | |
| 3894 | ConstantSDNode *CIdx = cast<ConstantSDNode>(Idx); |
| 3895 | SDOperand Lo, Hi; |
| 3896 | SplitVectorOp(Vec, Lo, Hi); |
| 3897 | if (CIdx->getValue() < NumElems/2) { |
| 3898 | Vec = Lo; |
| 3899 | } else { |
| 3900 | Vec = Hi; |
| 3901 | Idx = DAG.getConstant(CIdx->getValue() - NumElems/2, Idx.getValueType()); |
| 3902 | } |
| 3903 | |
| 3904 | // It's now an extract from the appropriate high or low part. Recurse. |
| 3905 | Op = DAG.UpdateNodeOperands(Op, Vec, Idx); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3906 | return ExpandEXTRACT_SUBVECTOR(Op); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 3907 | } |
| 3908 | |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 3909 | /// LegalizeSetCCOperands - Attempts to create a legal LHS and RHS for a SETCC |
| 3910 | /// with condition CC on the current target. This usually involves legalizing |
| 3911 | /// or promoting the arguments. In the case where LHS and RHS must be expanded, |
| 3912 | /// there may be no choice but to create a new SetCC node to represent the |
| 3913 | /// legalized value of setcc lhs, rhs. In this case, the value is returned in |
| 3914 | /// LHS, and the SDOperand returned in RHS has a nil SDNode value. |
| 3915 | void SelectionDAGLegalize::LegalizeSetCCOperands(SDOperand &LHS, |
| 3916 | SDOperand &RHS, |
| 3917 | SDOperand &CC) { |
| 3918 | SDOperand Tmp1, Tmp2, Result; |
| 3919 | |
| 3920 | switch (getTypeAction(LHS.getValueType())) { |
| 3921 | case Legal: |
| 3922 | Tmp1 = LegalizeOp(LHS); // LHS |
| 3923 | Tmp2 = LegalizeOp(RHS); // RHS |
| 3924 | break; |
| 3925 | case Promote: |
| 3926 | Tmp1 = PromoteOp(LHS); // LHS |
| 3927 | Tmp2 = PromoteOp(RHS); // RHS |
| 3928 | |
| 3929 | // If this is an FP compare, the operands have already been extended. |
| 3930 | if (MVT::isInteger(LHS.getValueType())) { |
| 3931 | MVT::ValueType VT = LHS.getValueType(); |
| 3932 | MVT::ValueType NVT = TLI.getTypeToTransformTo(VT); |
| 3933 | |
| 3934 | // Otherwise, we have to insert explicit sign or zero extends. Note |
| 3935 | // that we could insert sign extends for ALL conditions, but zero extend |
| 3936 | // is cheaper on many machines (an AND instead of two shifts), so prefer |
| 3937 | // it. |
| 3938 | switch (cast<CondCodeSDNode>(CC)->get()) { |
| 3939 | default: assert(0 && "Unknown integer comparison!"); |
| 3940 | case ISD::SETEQ: |
| 3941 | case ISD::SETNE: |
| 3942 | case ISD::SETUGE: |
| 3943 | case ISD::SETUGT: |
| 3944 | case ISD::SETULE: |
| 3945 | case ISD::SETULT: |
| 3946 | // ALL of these operations will work if we either sign or zero extend |
| 3947 | // the operands (including the unsigned comparisons!). Zero extend is |
| 3948 | // usually a simpler/cheaper operation, so prefer it. |
| 3949 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, VT); |
| 3950 | Tmp2 = DAG.getZeroExtendInReg(Tmp2, VT); |
| 3951 | break; |
| 3952 | case ISD::SETGE: |
| 3953 | case ISD::SETGT: |
| 3954 | case ISD::SETLT: |
| 3955 | case ISD::SETLE: |
| 3956 | Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp1, |
| 3957 | DAG.getValueType(VT)); |
| 3958 | Tmp2 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp2, |
| 3959 | DAG.getValueType(VT)); |
| 3960 | break; |
| 3961 | } |
| 3962 | } |
| 3963 | break; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 3964 | case Expand: { |
| 3965 | MVT::ValueType VT = LHS.getValueType(); |
| 3966 | if (VT == MVT::f32 || VT == MVT::f64) { |
| 3967 | // Expand into one or more soft-fp libcall(s). |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3968 | RTLIB::Libcall LC1, LC2 = RTLIB::UNKNOWN_LIBCALL; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 3969 | switch (cast<CondCodeSDNode>(CC)->get()) { |
| 3970 | case ISD::SETEQ: |
| 3971 | case ISD::SETOEQ: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3972 | LC1 = (VT == MVT::f32) ? RTLIB::OEQ_F32 : RTLIB::OEQ_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 3973 | break; |
| 3974 | case ISD::SETNE: |
| 3975 | case ISD::SETUNE: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3976 | LC1 = (VT == MVT::f32) ? RTLIB::UNE_F32 : RTLIB::UNE_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 3977 | break; |
| 3978 | case ISD::SETGE: |
| 3979 | case ISD::SETOGE: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3980 | LC1 = (VT == MVT::f32) ? RTLIB::OGE_F32 : RTLIB::OGE_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 3981 | break; |
| 3982 | case ISD::SETLT: |
| 3983 | case ISD::SETOLT: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3984 | LC1 = (VT == MVT::f32) ? RTLIB::OLT_F32 : RTLIB::OLT_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 3985 | break; |
| 3986 | case ISD::SETLE: |
| 3987 | case ISD::SETOLE: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3988 | LC1 = (VT == MVT::f32) ? RTLIB::OLE_F32 : RTLIB::OLE_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 3989 | break; |
| 3990 | case ISD::SETGT: |
| 3991 | case ISD::SETOGT: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3992 | LC1 = (VT == MVT::f32) ? RTLIB::OGT_F32 : RTLIB::OGT_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 3993 | break; |
| 3994 | case ISD::SETUO: |
Evan Cheng | d385fd6 | 2007-01-31 09:29:11 +0000 | [diff] [blame] | 3995 | LC1 = (VT == MVT::f32) ? RTLIB::UO_F32 : RTLIB::UO_F64; |
| 3996 | break; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 3997 | case ISD::SETO: |
Evan Cheng | 5efdecc | 2007-02-03 00:43:46 +0000 | [diff] [blame] | 3998 | LC1 = (VT == MVT::f32) ? RTLIB::O_F32 : RTLIB::O_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 3999 | break; |
| 4000 | default: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4001 | LC1 = (VT == MVT::f32) ? RTLIB::UO_F32 : RTLIB::UO_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4002 | switch (cast<CondCodeSDNode>(CC)->get()) { |
| 4003 | case ISD::SETONE: |
| 4004 | // SETONE = SETOLT | SETOGT |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4005 | LC1 = (VT == MVT::f32) ? RTLIB::OLT_F32 : RTLIB::OLT_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4006 | // Fallthrough |
| 4007 | case ISD::SETUGT: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4008 | LC2 = (VT == MVT::f32) ? RTLIB::OGT_F32 : RTLIB::OGT_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4009 | break; |
| 4010 | case ISD::SETUGE: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4011 | LC2 = (VT == MVT::f32) ? RTLIB::OGE_F32 : RTLIB::OGE_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4012 | break; |
| 4013 | case ISD::SETULT: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4014 | LC2 = (VT == MVT::f32) ? RTLIB::OLT_F32 : RTLIB::OLT_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4015 | break; |
| 4016 | case ISD::SETULE: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4017 | LC2 = (VT == MVT::f32) ? RTLIB::OLE_F32 : RTLIB::OLE_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4018 | break; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4019 | case ISD::SETUEQ: |
| 4020 | LC2 = (VT == MVT::f32) ? RTLIB::OEQ_F32 : RTLIB::OEQ_F64; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4021 | break; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4022 | default: assert(0 && "Unsupported FP setcc!"); |
| 4023 | } |
| 4024 | } |
| 4025 | |
| 4026 | SDOperand Dummy; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4027 | Tmp1 = ExpandLibCall(TLI.getLibcallName(LC1), |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 4028 | DAG.getNode(ISD::MERGE_VALUES, VT, LHS, RHS).Val, |
Reid Spencer | b47b25c | 2007-01-03 04:22:32 +0000 | [diff] [blame] | 4029 | false /*sign irrelevant*/, Dummy); |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4030 | Tmp2 = DAG.getConstant(0, MVT::i32); |
Evan Cheng | d385fd6 | 2007-01-31 09:29:11 +0000 | [diff] [blame] | 4031 | CC = DAG.getCondCode(TLI.getCmpLibcallCC(LC1)); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4032 | if (LC2 != RTLIB::UNKNOWN_LIBCALL) { |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4033 | Tmp1 = DAG.getNode(ISD::SETCC, TLI.getSetCCResultTy(), Tmp1, Tmp2, CC); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4034 | LHS = ExpandLibCall(TLI.getLibcallName(LC2), |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 4035 | DAG.getNode(ISD::MERGE_VALUES, VT, LHS, RHS).Val, |
Reid Spencer | b47b25c | 2007-01-03 04:22:32 +0000 | [diff] [blame] | 4036 | false /*sign irrelevant*/, Dummy); |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4037 | Tmp2 = DAG.getNode(ISD::SETCC, TLI.getSetCCResultTy(), LHS, Tmp2, |
Evan Cheng | d385fd6 | 2007-01-31 09:29:11 +0000 | [diff] [blame] | 4038 | DAG.getCondCode(TLI.getCmpLibcallCC(LC2))); |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4039 | Tmp1 = DAG.getNode(ISD::OR, Tmp1.getValueType(), Tmp1, Tmp2); |
| 4040 | Tmp2 = SDOperand(); |
| 4041 | } |
| 4042 | LHS = Tmp1; |
| 4043 | RHS = Tmp2; |
| 4044 | return; |
| 4045 | } |
| 4046 | |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 4047 | SDOperand LHSLo, LHSHi, RHSLo, RHSHi; |
| 4048 | ExpandOp(LHS, LHSLo, LHSHi); |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4049 | ExpandOp(RHS, RHSLo, RHSHi); |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 4050 | switch (cast<CondCodeSDNode>(CC)->get()) { |
| 4051 | case ISD::SETEQ: |
| 4052 | case ISD::SETNE: |
| 4053 | if (RHSLo == RHSHi) |
| 4054 | if (ConstantSDNode *RHSCST = dyn_cast<ConstantSDNode>(RHSLo)) |
| 4055 | if (RHSCST->isAllOnesValue()) { |
| 4056 | // Comparison to -1. |
| 4057 | Tmp1 = DAG.getNode(ISD::AND, LHSLo.getValueType(), LHSLo, LHSHi); |
| 4058 | Tmp2 = RHSLo; |
| 4059 | break; |
| 4060 | } |
| 4061 | |
| 4062 | Tmp1 = DAG.getNode(ISD::XOR, LHSLo.getValueType(), LHSLo, RHSLo); |
| 4063 | Tmp2 = DAG.getNode(ISD::XOR, LHSLo.getValueType(), LHSHi, RHSHi); |
| 4064 | Tmp1 = DAG.getNode(ISD::OR, Tmp1.getValueType(), Tmp1, Tmp2); |
| 4065 | Tmp2 = DAG.getConstant(0, Tmp1.getValueType()); |
| 4066 | break; |
| 4067 | default: |
| 4068 | // If this is a comparison of the sign bit, just look at the top part. |
| 4069 | // X > -1, x < 0 |
| 4070 | if (ConstantSDNode *CST = dyn_cast<ConstantSDNode>(RHS)) |
| 4071 | if ((cast<CondCodeSDNode>(CC)->get() == ISD::SETLT && |
| 4072 | CST->getValue() == 0) || // X < 0 |
| 4073 | (cast<CondCodeSDNode>(CC)->get() == ISD::SETGT && |
| 4074 | CST->isAllOnesValue())) { // X > -1 |
| 4075 | Tmp1 = LHSHi; |
| 4076 | Tmp2 = RHSHi; |
| 4077 | break; |
| 4078 | } |
| 4079 | |
| 4080 | // FIXME: This generated code sucks. |
| 4081 | ISD::CondCode LowCC; |
Evan Cheng | 2e67781 | 2007-02-08 22:16:19 +0000 | [diff] [blame] | 4082 | ISD::CondCode CCCode = cast<CondCodeSDNode>(CC)->get(); |
| 4083 | switch (CCCode) { |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 4084 | default: assert(0 && "Unknown integer setcc!"); |
| 4085 | case ISD::SETLT: |
| 4086 | case ISD::SETULT: LowCC = ISD::SETULT; break; |
| 4087 | case ISD::SETGT: |
| 4088 | case ISD::SETUGT: LowCC = ISD::SETUGT; break; |
| 4089 | case ISD::SETLE: |
| 4090 | case ISD::SETULE: LowCC = ISD::SETULE; break; |
| 4091 | case ISD::SETGE: |
| 4092 | case ISD::SETUGE: LowCC = ISD::SETUGE; break; |
| 4093 | } |
| 4094 | |
| 4095 | // Tmp1 = lo(op1) < lo(op2) // Always unsigned comparison |
| 4096 | // Tmp2 = hi(op1) < hi(op2) // Signedness depends on operands |
| 4097 | // dest = hi(op1) == hi(op2) ? Tmp1 : Tmp2; |
| 4098 | |
| 4099 | // NOTE: on targets without efficient SELECT of bools, we can always use |
| 4100 | // this identity: (B1 ? B2 : B3) --> (B1 & B2)|(!B1&B3) |
Evan Cheng | 2e67781 | 2007-02-08 22:16:19 +0000 | [diff] [blame] | 4101 | TargetLowering::DAGCombinerInfo DagCombineInfo(DAG, false, true, NULL); |
| 4102 | Tmp1 = TLI.SimplifySetCC(TLI.getSetCCResultTy(), LHSLo, RHSLo, LowCC, |
| 4103 | false, DagCombineInfo); |
| 4104 | if (!Tmp1.Val) |
| 4105 | Tmp1 = DAG.getSetCC(TLI.getSetCCResultTy(), LHSLo, RHSLo, LowCC); |
| 4106 | Tmp2 = TLI.SimplifySetCC(TLI.getSetCCResultTy(), LHSHi, RHSHi, |
| 4107 | CCCode, false, DagCombineInfo); |
| 4108 | if (!Tmp2.Val) |
| 4109 | Tmp2 = DAG.getNode(ISD::SETCC, TLI.getSetCCResultTy(), LHSHi, RHSHi, CC); |
| 4110 | |
| 4111 | ConstantSDNode *Tmp1C = dyn_cast<ConstantSDNode>(Tmp1.Val); |
| 4112 | ConstantSDNode *Tmp2C = dyn_cast<ConstantSDNode>(Tmp2.Val); |
| 4113 | if ((Tmp1C && Tmp1C->getValue() == 0) || |
| 4114 | (Tmp2C && Tmp2C->getValue() == 0 && |
| 4115 | (CCCode == ISD::SETLE || CCCode == ISD::SETGE || |
| 4116 | CCCode == ISD::SETUGE || CCCode == ISD::SETULE)) || |
| 4117 | (Tmp2C && Tmp2C->getValue() == 1 && |
| 4118 | (CCCode == ISD::SETLT || CCCode == ISD::SETGT || |
| 4119 | CCCode == ISD::SETUGT || CCCode == ISD::SETULT))) { |
| 4120 | // low part is known false, returns high part. |
| 4121 | // For LE / GE, if high part is known false, ignore the low part. |
| 4122 | // For LT / GT, if high part is known true, ignore the low part. |
| 4123 | Tmp1 = Tmp2; |
| 4124 | Tmp2 = SDOperand(); |
| 4125 | } else { |
| 4126 | Result = TLI.SimplifySetCC(TLI.getSetCCResultTy(), LHSHi, RHSHi, |
| 4127 | ISD::SETEQ, false, DagCombineInfo); |
| 4128 | if (!Result.Val) |
| 4129 | Result=DAG.getSetCC(TLI.getSetCCResultTy(), LHSHi, RHSHi, ISD::SETEQ); |
| 4130 | Result = LegalizeOp(DAG.getNode(ISD::SELECT, Tmp1.getValueType(), |
| 4131 | Result, Tmp1, Tmp2)); |
| 4132 | Tmp1 = Result; |
| 4133 | Tmp2 = SDOperand(); |
| 4134 | } |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 4135 | } |
| 4136 | } |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4137 | } |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 4138 | LHS = Tmp1; |
| 4139 | RHS = Tmp2; |
| 4140 | } |
| 4141 | |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 4142 | /// ExpandBIT_CONVERT - Expand a BIT_CONVERT node into a store/load combination. |
Chris Lattner | 232348d | 2005-12-23 00:52:30 +0000 | [diff] [blame] | 4143 | /// The resultant code need not be legal. Note that SrcOp is the input operand |
| 4144 | /// to the BIT_CONVERT, not the BIT_CONVERT node itself. |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 4145 | SDOperand SelectionDAGLegalize::ExpandBIT_CONVERT(MVT::ValueType DestVT, |
| 4146 | SDOperand SrcOp) { |
| 4147 | // Create the stack frame object. |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4148 | SDOperand FIPtr = CreateStackTemporary(DestVT); |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 4149 | |
| 4150 | // Emit a store to the stack slot. |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 4151 | SDOperand Store = DAG.getStore(DAG.getEntryNode(), SrcOp, FIPtr, NULL, 0); |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 4152 | // Result is a load from the stack slot. |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 4153 | return DAG.getLoad(DestVT, Store, FIPtr, NULL, 0); |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 4154 | } |
| 4155 | |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 4156 | SDOperand SelectionDAGLegalize::ExpandSCALAR_TO_VECTOR(SDNode *Node) { |
| 4157 | // Create a vector sized/aligned stack slot, store the value to element #0, |
| 4158 | // then load the whole vector back out. |
| 4159 | SDOperand StackPtr = CreateStackTemporary(Node->getValueType(0)); |
Evan Cheng | 786225a | 2006-10-05 23:01:46 +0000 | [diff] [blame] | 4160 | SDOperand Ch = DAG.getStore(DAG.getEntryNode(), Node->getOperand(0), StackPtr, |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 4161 | NULL, 0); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 4162 | return DAG.getLoad(Node->getValueType(0), Ch, StackPtr, NULL, 0); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 4163 | } |
| 4164 | |
| 4165 | |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4166 | /// ExpandBUILD_VECTOR - Expand a BUILD_VECTOR node on targets that don't |
Dan Gohman | 07a9676 | 2007-07-16 14:29:03 +0000 | [diff] [blame] | 4167 | /// support the operation, but do support the resultant vector type. |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4168 | SDOperand SelectionDAGLegalize::ExpandBUILD_VECTOR(SDNode *Node) { |
| 4169 | |
| 4170 | // 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] | 4171 | // 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] | 4172 | unsigned NumElems = Node->getNumOperands(); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4173 | bool isOnlyLowElement = true; |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 4174 | SDOperand SplatValue = Node->getOperand(0); |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 4175 | std::map<SDOperand, std::vector<unsigned> > Values; |
| 4176 | Values[SplatValue].push_back(0); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 4177 | bool isConstant = true; |
| 4178 | if (!isa<ConstantFPSDNode>(SplatValue) && !isa<ConstantSDNode>(SplatValue) && |
| 4179 | SplatValue.getOpcode() != ISD::UNDEF) |
| 4180 | isConstant = false; |
| 4181 | |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 4182 | for (unsigned i = 1; i < NumElems; ++i) { |
| 4183 | SDOperand V = Node->getOperand(i); |
Chris Lattner | 89a1b38 | 2006-04-19 23:17:50 +0000 | [diff] [blame] | 4184 | Values[V].push_back(i); |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 4185 | if (V.getOpcode() != ISD::UNDEF) |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4186 | isOnlyLowElement = false; |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 4187 | if (SplatValue != V) |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 4188 | SplatValue = SDOperand(0,0); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 4189 | |
| 4190 | // If this isn't a constant element or an undef, we can't use a constant |
| 4191 | // pool load. |
| 4192 | if (!isa<ConstantFPSDNode>(V) && !isa<ConstantSDNode>(V) && |
| 4193 | V.getOpcode() != ISD::UNDEF) |
| 4194 | isConstant = false; |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4195 | } |
| 4196 | |
| 4197 | if (isOnlyLowElement) { |
| 4198 | // If the low element is an undef too, then this whole things is an undef. |
| 4199 | if (Node->getOperand(0).getOpcode() == ISD::UNDEF) |
| 4200 | return DAG.getNode(ISD::UNDEF, Node->getValueType(0)); |
| 4201 | // Otherwise, turn this into a scalar_to_vector node. |
| 4202 | return DAG.getNode(ISD::SCALAR_TO_VECTOR, Node->getValueType(0), |
| 4203 | Node->getOperand(0)); |
| 4204 | } |
| 4205 | |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 4206 | // If all elements are constants, create a load from the constant pool. |
| 4207 | if (isConstant) { |
| 4208 | MVT::ValueType VT = Node->getValueType(0); |
| 4209 | const Type *OpNTy = |
| 4210 | MVT::getTypeForValueType(Node->getOperand(0).getValueType()); |
| 4211 | std::vector<Constant*> CV; |
| 4212 | for (unsigned i = 0, e = NumElems; i != e; ++i) { |
| 4213 | if (ConstantFPSDNode *V = |
| 4214 | dyn_cast<ConstantFPSDNode>(Node->getOperand(i))) { |
| 4215 | CV.push_back(ConstantFP::get(OpNTy, V->getValue())); |
| 4216 | } else if (ConstantSDNode *V = |
| 4217 | dyn_cast<ConstantSDNode>(Node->getOperand(i))) { |
Reid Spencer | b83eb64 | 2006-10-20 07:07:24 +0000 | [diff] [blame] | 4218 | CV.push_back(ConstantInt::get(OpNTy, V->getValue())); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 4219 | } else { |
| 4220 | assert(Node->getOperand(i).getOpcode() == ISD::UNDEF); |
| 4221 | CV.push_back(UndefValue::get(OpNTy)); |
| 4222 | } |
| 4223 | } |
Reid Spencer | 9d6565a | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 4224 | Constant *CP = ConstantVector::get(CV); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 4225 | SDOperand CPIdx = DAG.getConstantPool(CP, TLI.getPointerTy()); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 4226 | return DAG.getLoad(VT, DAG.getEntryNode(), CPIdx, NULL, 0); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 4227 | } |
| 4228 | |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 4229 | if (SplatValue.Val) { // Splat of one value? |
| 4230 | // Build the shuffle constant vector: <0, 0, 0, 0> |
| 4231 | MVT::ValueType MaskVT = |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 4232 | MVT::getIntVectorWithNumElements(NumElems); |
Dan Gohman | 51eaa86 | 2007-06-14 22:58:02 +0000 | [diff] [blame] | 4233 | SDOperand Zero = DAG.getConstant(0, MVT::getVectorElementType(MaskVT)); |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 4234 | std::vector<SDOperand> ZeroVec(NumElems, Zero); |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 4235 | SDOperand SplatMask = DAG.getNode(ISD::BUILD_VECTOR, MaskVT, |
| 4236 | &ZeroVec[0], ZeroVec.size()); |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 4237 | |
| 4238 | // If the target supports VECTOR_SHUFFLE and this shuffle mask, use it. |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 4239 | if (isShuffleLegal(Node->getValueType(0), SplatMask)) { |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 4240 | // Get the splatted value into the low element of a vector register. |
| 4241 | SDOperand LowValVec = |
| 4242 | DAG.getNode(ISD::SCALAR_TO_VECTOR, Node->getValueType(0), SplatValue); |
| 4243 | |
| 4244 | // Return shuffle(LowValVec, undef, <0,0,0,0>) |
| 4245 | return DAG.getNode(ISD::VECTOR_SHUFFLE, Node->getValueType(0), LowValVec, |
| 4246 | DAG.getNode(ISD::UNDEF, Node->getValueType(0)), |
| 4247 | SplatMask); |
| 4248 | } |
| 4249 | } |
| 4250 | |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 4251 | // If there are only two unique elements, we may be able to turn this into a |
| 4252 | // vector shuffle. |
| 4253 | if (Values.size() == 2) { |
| 4254 | // Build the shuffle constant vector: e.g. <0, 4, 0, 4> |
| 4255 | MVT::ValueType MaskVT = |
| 4256 | MVT::getIntVectorWithNumElements(NumElems); |
| 4257 | std::vector<SDOperand> MaskVec(NumElems); |
| 4258 | unsigned i = 0; |
| 4259 | for (std::map<SDOperand,std::vector<unsigned> >::iterator I=Values.begin(), |
| 4260 | E = Values.end(); I != E; ++I) { |
| 4261 | for (std::vector<unsigned>::iterator II = I->second.begin(), |
| 4262 | EE = I->second.end(); II != EE; ++II) |
Dan Gohman | 51eaa86 | 2007-06-14 22:58:02 +0000 | [diff] [blame] | 4263 | MaskVec[*II] = DAG.getConstant(i, MVT::getVectorElementType(MaskVT)); |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 4264 | i += NumElems; |
| 4265 | } |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 4266 | SDOperand ShuffleMask = DAG.getNode(ISD::BUILD_VECTOR, MaskVT, |
| 4267 | &MaskVec[0], MaskVec.size()); |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 4268 | |
| 4269 | // If the target supports VECTOR_SHUFFLE and this shuffle mask, use it. |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 4270 | if (TLI.isOperationLegal(ISD::SCALAR_TO_VECTOR, Node->getValueType(0)) && |
| 4271 | isShuffleLegal(Node->getValueType(0), ShuffleMask)) { |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 4272 | SmallVector<SDOperand, 8> Ops; |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 4273 | for(std::map<SDOperand,std::vector<unsigned> >::iterator I=Values.begin(), |
| 4274 | E = Values.end(); I != E; ++I) { |
| 4275 | SDOperand Op = DAG.getNode(ISD::SCALAR_TO_VECTOR, Node->getValueType(0), |
| 4276 | I->first); |
| 4277 | Ops.push_back(Op); |
| 4278 | } |
| 4279 | Ops.push_back(ShuffleMask); |
| 4280 | |
| 4281 | // Return shuffle(LoValVec, HiValVec, <0,1,0,1>) |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 4282 | return DAG.getNode(ISD::VECTOR_SHUFFLE, Node->getValueType(0), |
| 4283 | &Ops[0], Ops.size()); |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 4284 | } |
| 4285 | } |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4286 | |
| 4287 | // Otherwise, we can't handle this case efficiently. Allocate a sufficiently |
| 4288 | // aligned object on the stack, store each element into it, then load |
| 4289 | // the result as a vector. |
| 4290 | MVT::ValueType VT = Node->getValueType(0); |
| 4291 | // Create the stack frame object. |
| 4292 | SDOperand FIPtr = CreateStackTemporary(VT); |
| 4293 | |
| 4294 | // Emit a store of each element to the stack slot. |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 4295 | SmallVector<SDOperand, 8> Stores; |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4296 | unsigned TypeByteSize = |
| 4297 | MVT::getSizeInBits(Node->getOperand(0).getValueType())/8; |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4298 | // Store (in the right endianness) the elements to memory. |
| 4299 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) { |
| 4300 | // Ignore undef elements. |
| 4301 | if (Node->getOperand(i).getOpcode() == ISD::UNDEF) continue; |
| 4302 | |
Chris Lattner | 841c882 | 2006-03-22 01:46:54 +0000 | [diff] [blame] | 4303 | unsigned Offset = TypeByteSize*i; |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4304 | |
| 4305 | SDOperand Idx = DAG.getConstant(Offset, FIPtr.getValueType()); |
| 4306 | Idx = DAG.getNode(ISD::ADD, FIPtr.getValueType(), FIPtr, Idx); |
| 4307 | |
Evan Cheng | 786225a | 2006-10-05 23:01:46 +0000 | [diff] [blame] | 4308 | Stores.push_back(DAG.getStore(DAG.getEntryNode(), Node->getOperand(i), Idx, |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 4309 | NULL, 0)); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4310 | } |
| 4311 | |
| 4312 | SDOperand StoreChain; |
| 4313 | if (!Stores.empty()) // Not all undef elements? |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 4314 | StoreChain = DAG.getNode(ISD::TokenFactor, MVT::Other, |
| 4315 | &Stores[0], Stores.size()); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4316 | else |
| 4317 | StoreChain = DAG.getEntryNode(); |
| 4318 | |
| 4319 | // Result is a load from the stack slot. |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 4320 | return DAG.getLoad(VT, StoreChain, FIPtr, NULL, 0); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4321 | } |
| 4322 | |
| 4323 | /// CreateStackTemporary - Create a stack temporary, suitable for holding the |
| 4324 | /// specified value type. |
| 4325 | SDOperand SelectionDAGLegalize::CreateStackTemporary(MVT::ValueType VT) { |
| 4326 | MachineFrameInfo *FrameInfo = DAG.getMachineFunction().getFrameInfo(); |
| 4327 | unsigned ByteSize = MVT::getSizeInBits(VT)/8; |
Chris Lattner | 58092e3 | 2007-01-20 22:35:55 +0000 | [diff] [blame] | 4328 | const Type *Ty = MVT::getTypeForValueType(VT); |
Chris Lattner | d2b7cec | 2007-02-14 05:52:17 +0000 | [diff] [blame] | 4329 | unsigned StackAlign = (unsigned)TLI.getTargetData()->getPrefTypeAlignment(Ty); |
Chris Lattner | 58092e3 | 2007-01-20 22:35:55 +0000 | [diff] [blame] | 4330 | int FrameIdx = FrameInfo->CreateStackObject(ByteSize, StackAlign); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4331 | return DAG.getFrameIndex(FrameIdx, TLI.getPointerTy()); |
| 4332 | } |
| 4333 | |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 4334 | void SelectionDAGLegalize::ExpandShiftParts(unsigned NodeOp, |
| 4335 | SDOperand Op, SDOperand Amt, |
| 4336 | SDOperand &Lo, SDOperand &Hi) { |
| 4337 | // Expand the subcomponents. |
| 4338 | SDOperand LHSL, LHSH; |
| 4339 | ExpandOp(Op, LHSL, LHSH); |
| 4340 | |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 4341 | SDOperand Ops[] = { LHSL, LHSH, Amt }; |
Chris Lattner | f9f37fc | 2006-08-14 23:53:35 +0000 | [diff] [blame] | 4342 | MVT::ValueType VT = LHSL.getValueType(); |
| 4343 | Lo = DAG.getNode(NodeOp, DAG.getNodeValueTypes(VT, VT), 2, Ops, 3); |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 4344 | Hi = Lo.getValue(1); |
| 4345 | } |
| 4346 | |
| 4347 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 4348 | /// ExpandShift - Try to find a clever way to expand this shift operation out to |
| 4349 | /// smaller elements. If we can't find a way that is more efficient than a |
| 4350 | /// libcall on this target, return false. Otherwise, return true with the |
| 4351 | /// low-parts expanded into Lo and Hi. |
| 4352 | bool SelectionDAGLegalize::ExpandShift(unsigned Opc, SDOperand Op,SDOperand Amt, |
| 4353 | SDOperand &Lo, SDOperand &Hi) { |
| 4354 | assert((Opc == ISD::SHL || Opc == ISD::SRA || Opc == ISD::SRL) && |
| 4355 | "This is not a shift!"); |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 4356 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 4357 | MVT::ValueType NVT = TLI.getTypeToTransformTo(Op.getValueType()); |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 4358 | SDOperand ShAmt = LegalizeOp(Amt); |
| 4359 | MVT::ValueType ShTy = ShAmt.getValueType(); |
| 4360 | unsigned VTBits = MVT::getSizeInBits(Op.getValueType()); |
| 4361 | unsigned NVTBits = MVT::getSizeInBits(NVT); |
| 4362 | |
| 4363 | // Handle the case when Amt is an immediate. Other cases are currently broken |
| 4364 | // and are disabled. |
| 4365 | if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Amt.Val)) { |
| 4366 | unsigned Cst = CN->getValue(); |
| 4367 | // Expand the incoming operand to be shifted, so that we have its parts |
| 4368 | SDOperand InL, InH; |
| 4369 | ExpandOp(Op, InL, InH); |
| 4370 | switch(Opc) { |
| 4371 | case ISD::SHL: |
| 4372 | if (Cst > VTBits) { |
| 4373 | Lo = DAG.getConstant(0, NVT); |
| 4374 | Hi = DAG.getConstant(0, NVT); |
| 4375 | } else if (Cst > NVTBits) { |
| 4376 | Lo = DAG.getConstant(0, NVT); |
| 4377 | Hi = DAG.getNode(ISD::SHL, NVT, InL, DAG.getConstant(Cst-NVTBits,ShTy)); |
Chris Lattner | ee27f57 | 2005-04-11 20:08:52 +0000 | [diff] [blame] | 4378 | } else if (Cst == NVTBits) { |
| 4379 | Lo = DAG.getConstant(0, NVT); |
| 4380 | Hi = InL; |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 4381 | } else { |
| 4382 | Lo = DAG.getNode(ISD::SHL, NVT, InL, DAG.getConstant(Cst, ShTy)); |
| 4383 | Hi = DAG.getNode(ISD::OR, NVT, |
| 4384 | DAG.getNode(ISD::SHL, NVT, InH, DAG.getConstant(Cst, ShTy)), |
| 4385 | DAG.getNode(ISD::SRL, NVT, InL, DAG.getConstant(NVTBits-Cst, ShTy))); |
| 4386 | } |
| 4387 | return true; |
| 4388 | case ISD::SRL: |
| 4389 | if (Cst > VTBits) { |
| 4390 | Lo = DAG.getConstant(0, NVT); |
| 4391 | Hi = DAG.getConstant(0, NVT); |
| 4392 | } else if (Cst > NVTBits) { |
| 4393 | Lo = DAG.getNode(ISD::SRL, NVT, InH, DAG.getConstant(Cst-NVTBits,ShTy)); |
| 4394 | Hi = DAG.getConstant(0, NVT); |
Chris Lattner | ee27f57 | 2005-04-11 20:08:52 +0000 | [diff] [blame] | 4395 | } else if (Cst == NVTBits) { |
| 4396 | Lo = InH; |
| 4397 | Hi = DAG.getConstant(0, NVT); |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 4398 | } else { |
| 4399 | Lo = DAG.getNode(ISD::OR, NVT, |
| 4400 | DAG.getNode(ISD::SRL, NVT, InL, DAG.getConstant(Cst, ShTy)), |
| 4401 | DAG.getNode(ISD::SHL, NVT, InH, DAG.getConstant(NVTBits-Cst, ShTy))); |
| 4402 | Hi = DAG.getNode(ISD::SRL, NVT, InH, DAG.getConstant(Cst, ShTy)); |
| 4403 | } |
| 4404 | return true; |
| 4405 | case ISD::SRA: |
| 4406 | if (Cst > VTBits) { |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 4407 | Hi = Lo = DAG.getNode(ISD::SRA, NVT, InH, |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 4408 | DAG.getConstant(NVTBits-1, ShTy)); |
| 4409 | } else if (Cst > NVTBits) { |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 4410 | Lo = DAG.getNode(ISD::SRA, NVT, InH, |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 4411 | DAG.getConstant(Cst-NVTBits, ShTy)); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 4412 | Hi = DAG.getNode(ISD::SRA, NVT, InH, |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 4413 | DAG.getConstant(NVTBits-1, ShTy)); |
Chris Lattner | ee27f57 | 2005-04-11 20:08:52 +0000 | [diff] [blame] | 4414 | } else if (Cst == NVTBits) { |
| 4415 | Lo = InH; |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 4416 | Hi = DAG.getNode(ISD::SRA, NVT, InH, |
Chris Lattner | ee27f57 | 2005-04-11 20:08:52 +0000 | [diff] [blame] | 4417 | DAG.getConstant(NVTBits-1, ShTy)); |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 4418 | } else { |
| 4419 | Lo = DAG.getNode(ISD::OR, NVT, |
| 4420 | DAG.getNode(ISD::SRL, NVT, InL, DAG.getConstant(Cst, ShTy)), |
| 4421 | DAG.getNode(ISD::SHL, NVT, InH, DAG.getConstant(NVTBits-Cst, ShTy))); |
| 4422 | Hi = DAG.getNode(ISD::SRA, NVT, InH, DAG.getConstant(Cst, ShTy)); |
| 4423 | } |
| 4424 | return true; |
| 4425 | } |
| 4426 | } |
Chris Lattner | 0ea26ca | 2006-09-20 03:38:48 +0000 | [diff] [blame] | 4427 | |
| 4428 | // Okay, the shift amount isn't constant. However, if we can tell that it is |
| 4429 | // >= 32 or < 32, we can still simplify it, without knowing the actual value. |
| 4430 | uint64_t Mask = NVTBits, KnownZero, KnownOne; |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 4431 | DAG.ComputeMaskedBits(Amt, Mask, KnownZero, KnownOne); |
Chris Lattner | 0ea26ca | 2006-09-20 03:38:48 +0000 | [diff] [blame] | 4432 | |
| 4433 | // If we know that the high bit of the shift amount is one, then we can do |
| 4434 | // this as a couple of simple shifts. |
| 4435 | if (KnownOne & Mask) { |
| 4436 | // Mask out the high bit, which we know is set. |
| 4437 | Amt = DAG.getNode(ISD::AND, Amt.getValueType(), Amt, |
| 4438 | DAG.getConstant(NVTBits-1, Amt.getValueType())); |
| 4439 | |
| 4440 | // Expand the incoming operand to be shifted, so that we have its parts |
| 4441 | SDOperand InL, InH; |
| 4442 | ExpandOp(Op, InL, InH); |
| 4443 | switch(Opc) { |
| 4444 | case ISD::SHL: |
| 4445 | Lo = DAG.getConstant(0, NVT); // Low part is zero. |
| 4446 | Hi = DAG.getNode(ISD::SHL, NVT, InL, Amt); // High part from Lo part. |
| 4447 | return true; |
| 4448 | case ISD::SRL: |
| 4449 | Hi = DAG.getConstant(0, NVT); // Hi part is zero. |
| 4450 | Lo = DAG.getNode(ISD::SRL, NVT, InH, Amt); // Lo part from Hi part. |
| 4451 | return true; |
| 4452 | case ISD::SRA: |
| 4453 | Hi = DAG.getNode(ISD::SRA, NVT, InH, // Sign extend high part. |
| 4454 | DAG.getConstant(NVTBits-1, Amt.getValueType())); |
| 4455 | Lo = DAG.getNode(ISD::SRA, NVT, InH, Amt); // Lo part from Hi part. |
| 4456 | return true; |
| 4457 | } |
| 4458 | } |
| 4459 | |
| 4460 | // If we know that the high bit of the shift amount is zero, then we can do |
| 4461 | // this as a couple of simple shifts. |
| 4462 | if (KnownZero & Mask) { |
| 4463 | // Compute 32-amt. |
| 4464 | SDOperand Amt2 = DAG.getNode(ISD::SUB, Amt.getValueType(), |
| 4465 | DAG.getConstant(NVTBits, Amt.getValueType()), |
| 4466 | Amt); |
| 4467 | |
| 4468 | // Expand the incoming operand to be shifted, so that we have its parts |
| 4469 | SDOperand InL, InH; |
| 4470 | ExpandOp(Op, InL, InH); |
| 4471 | switch(Opc) { |
| 4472 | case ISD::SHL: |
| 4473 | Lo = DAG.getNode(ISD::SHL, NVT, InL, Amt); |
| 4474 | Hi = DAG.getNode(ISD::OR, NVT, |
| 4475 | DAG.getNode(ISD::SHL, NVT, InH, Amt), |
| 4476 | DAG.getNode(ISD::SRL, NVT, InL, Amt2)); |
| 4477 | return true; |
| 4478 | case ISD::SRL: |
| 4479 | Hi = DAG.getNode(ISD::SRL, NVT, InH, Amt); |
| 4480 | Lo = DAG.getNode(ISD::OR, NVT, |
| 4481 | DAG.getNode(ISD::SRL, NVT, InL, Amt), |
| 4482 | DAG.getNode(ISD::SHL, NVT, InH, Amt2)); |
| 4483 | return true; |
| 4484 | case ISD::SRA: |
| 4485 | Hi = DAG.getNode(ISD::SRA, NVT, InH, Amt); |
| 4486 | Lo = DAG.getNode(ISD::OR, NVT, |
| 4487 | DAG.getNode(ISD::SRL, NVT, InL, Amt), |
| 4488 | DAG.getNode(ISD::SHL, NVT, InH, Amt2)); |
| 4489 | return true; |
| 4490 | } |
| 4491 | } |
| 4492 | |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 4493 | return false; |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 4494 | } |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4495 | |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 4496 | |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4497 | // ExpandLibCall - Expand a node into a call to a libcall. If the result value |
| 4498 | // does not fit into a register, return the lo part and set the hi part to the |
| 4499 | // by-reg argument. If it does fit into a single register, return the result |
| 4500 | // and leave the Hi part unset. |
| 4501 | SDOperand SelectionDAGLegalize::ExpandLibCall(const char *Name, SDNode *Node, |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 4502 | bool isSigned, SDOperand &Hi) { |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 4503 | assert(!IsLegalizingCall && "Cannot overlap legalization of calls!"); |
| 4504 | // The input chain to this libcall is the entry node of the function. |
| 4505 | // Legalizing the call will automatically add the previous call to the |
| 4506 | // dependence. |
| 4507 | SDOperand InChain = DAG.getEntryNode(); |
| 4508 | |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4509 | TargetLowering::ArgListTy Args; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 4510 | TargetLowering::ArgListEntry Entry; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4511 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) { |
| 4512 | MVT::ValueType ArgVT = Node->getOperand(i).getValueType(); |
| 4513 | const Type *ArgTy = MVT::getTypeForValueType(ArgVT); |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 4514 | Entry.Node = Node->getOperand(i); Entry.Ty = ArgTy; |
Anton Korobeynikov | d0b82b3 | 2007-03-07 16:25:09 +0000 | [diff] [blame] | 4515 | Entry.isSExt = isSigned; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 4516 | Args.push_back(Entry); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4517 | } |
| 4518 | SDOperand Callee = DAG.getExternalSymbol(Name, TLI.getPointerTy()); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 4519 | |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 4520 | // Splice the libcall in wherever FindInputOutputChains tells us to. |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4521 | const Type *RetTy = MVT::getTypeForValueType(Node->getValueType(0)); |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 4522 | std::pair<SDOperand,SDOperand> CallInfo = |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 4523 | TLI.LowerCallTo(InChain, RetTy, isSigned, false, CallingConv::C, false, |
Chris Lattner | adf6a96 | 2005-05-13 18:50:42 +0000 | [diff] [blame] | 4524 | Callee, Args, DAG); |
Chris Lattner | b9fa3bc | 2005-05-12 04:49:08 +0000 | [diff] [blame] | 4525 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 4526 | // Legalize the call sequence, starting with the chain. This will advance |
| 4527 | // the LastCALLSEQ_END to the legalized version of the CALLSEQ_END node that |
| 4528 | // was added by LowerCallTo (guaranteeing proper serialization of calls). |
| 4529 | LegalizeOp(CallInfo.second); |
Chris Lattner | 99c25b8 | 2005-09-02 20:26:58 +0000 | [diff] [blame] | 4530 | SDOperand Result; |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 4531 | switch (getTypeAction(CallInfo.first.getValueType())) { |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4532 | default: assert(0 && "Unknown thing"); |
| 4533 | case Legal: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4534 | Result = CallInfo.first; |
Chris Lattner | 99c25b8 | 2005-09-02 20:26:58 +0000 | [diff] [blame] | 4535 | break; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4536 | case Expand: |
Chris Lattner | 99c25b8 | 2005-09-02 20:26:58 +0000 | [diff] [blame] | 4537 | ExpandOp(CallInfo.first, Result, Hi); |
Chris Lattner | 99c25b8 | 2005-09-02 20:26:58 +0000 | [diff] [blame] | 4538 | break; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4539 | } |
Chris Lattner | 99c25b8 | 2005-09-02 20:26:58 +0000 | [diff] [blame] | 4540 | return Result; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4541 | } |
| 4542 | |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 4543 | |
Evan Cheng | 4c6cfad | 2007-04-27 07:33:31 +0000 | [diff] [blame] | 4544 | /// ExpandIntToFP - Expand a [US]INT_TO_FP operation. |
| 4545 | /// |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4546 | SDOperand SelectionDAGLegalize:: |
| 4547 | ExpandIntToFP(bool isSigned, MVT::ValueType DestTy, SDOperand Source) { |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4548 | assert(getTypeAction(Source.getValueType()) == Expand && |
| 4549 | "This is not an expansion!"); |
| 4550 | assert(Source.getValueType() == MVT::i64 && "Only handle expand from i64!"); |
| 4551 | |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 4552 | if (!isSigned) { |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 4553 | assert(Source.getValueType() == MVT::i64 && |
| 4554 | "This only works for 64-bit -> FP"); |
| 4555 | // The 64-bit value loaded will be incorrectly if the 'sign bit' of the |
| 4556 | // incoming integer is set. To handle this, we dynamically test to see if |
| 4557 | // it is set, and, if so, add a fudge factor. |
| 4558 | SDOperand Lo, Hi; |
| 4559 | ExpandOp(Source, Lo, Hi); |
| 4560 | |
Chris Lattner | 66de05b | 2005-05-13 04:45:13 +0000 | [diff] [blame] | 4561 | // If this is unsigned, and not supported, first perform the conversion to |
| 4562 | // signed, then adjust the result if the sign bit is set. |
| 4563 | SDOperand SignedConv = ExpandIntToFP(true, DestTy, |
| 4564 | DAG.getNode(ISD::BUILD_PAIR, Source.getValueType(), Lo, Hi)); |
| 4565 | |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 4566 | SDOperand SignSet = DAG.getSetCC(TLI.getSetCCResultTy(), Hi, |
| 4567 | DAG.getConstant(0, Hi.getValueType()), |
| 4568 | ISD::SETLT); |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 4569 | SDOperand Zero = getIntPtrConstant(0), Four = getIntPtrConstant(4); |
| 4570 | SDOperand CstOffset = DAG.getNode(ISD::SELECT, Zero.getValueType(), |
| 4571 | SignSet, Four, Zero); |
Chris Lattner | 383203b | 2005-05-12 18:52:34 +0000 | [diff] [blame] | 4572 | uint64_t FF = 0x5f800000ULL; |
| 4573 | if (TLI.isLittleEndian()) FF <<= 32; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 4574 | static Constant *FudgeFactor = ConstantInt::get(Type::Int64Ty, FF); |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 4575 | |
Chris Lattner | 5839bf2 | 2005-08-26 17:15:30 +0000 | [diff] [blame] | 4576 | SDOperand CPIdx = DAG.getConstantPool(FudgeFactor, TLI.getPointerTy()); |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 4577 | CPIdx = DAG.getNode(ISD::ADD, TLI.getPointerTy(), CPIdx, CstOffset); |
| 4578 | SDOperand FudgeInReg; |
| 4579 | if (DestTy == MVT::f32) |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 4580 | FudgeInReg = DAG.getLoad(MVT::f32, DAG.getEntryNode(), CPIdx, NULL, 0); |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 4581 | else { |
| 4582 | assert(DestTy == MVT::f64 && "Unexpected conversion"); |
Evan Cheng | 4c6cfad | 2007-04-27 07:33:31 +0000 | [diff] [blame] | 4583 | // FIXME: Avoid the extend by construction the right constantpool? |
Chris Lattner | 5f056bf | 2005-07-10 01:55:33 +0000 | [diff] [blame] | 4584 | FudgeInReg = DAG.getExtLoad(ISD::EXTLOAD, MVT::f64, DAG.getEntryNode(), |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 4585 | CPIdx, NULL, 0, MVT::f32); |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 4586 | } |
Evan Cheng | 4c6cfad | 2007-04-27 07:33:31 +0000 | [diff] [blame] | 4587 | MVT::ValueType SCVT = SignedConv.getValueType(); |
| 4588 | if (SCVT != DestTy) { |
| 4589 | // Destination type needs to be expanded as well. The FADD now we are |
| 4590 | // constructing will be expanded into a libcall. |
| 4591 | if (MVT::getSizeInBits(SCVT) != MVT::getSizeInBits(DestTy)) { |
| 4592 | assert(SCVT == MVT::i32 && DestTy == MVT::f64); |
| 4593 | SignedConv = DAG.getNode(ISD::BUILD_PAIR, MVT::i64, |
| 4594 | SignedConv, SignedConv.getValue(1)); |
| 4595 | } |
| 4596 | SignedConv = DAG.getNode(ISD::BIT_CONVERT, DestTy, SignedConv); |
| 4597 | } |
Chris Lattner | 473a990 | 2005-09-29 06:44:39 +0000 | [diff] [blame] | 4598 | return DAG.getNode(ISD::FADD, DestTy, SignedConv, FudgeInReg); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4599 | } |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 4600 | |
Chris Lattner | a88a260 | 2005-05-14 05:33:54 +0000 | [diff] [blame] | 4601 | // Check to see if the target has a custom way to lower this. If so, use it. |
| 4602 | switch (TLI.getOperationAction(ISD::SINT_TO_FP, Source.getValueType())) { |
| 4603 | default: assert(0 && "This action not implemented for this operation!"); |
| 4604 | case TargetLowering::Legal: |
| 4605 | case TargetLowering::Expand: |
| 4606 | break; // This case is handled below. |
Chris Lattner | 07dffd6 | 2005-08-26 00:14:16 +0000 | [diff] [blame] | 4607 | case TargetLowering::Custom: { |
| 4608 | SDOperand NV = TLI.LowerOperation(DAG.getNode(ISD::SINT_TO_FP, DestTy, |
| 4609 | Source), DAG); |
| 4610 | if (NV.Val) |
| 4611 | return LegalizeOp(NV); |
| 4612 | break; // The target decided this was legal after all |
| 4613 | } |
Chris Lattner | a88a260 | 2005-05-14 05:33:54 +0000 | [diff] [blame] | 4614 | } |
| 4615 | |
Chris Lattner | 13689e2 | 2005-05-12 07:00:44 +0000 | [diff] [blame] | 4616 | // Expand the source, then glue it back together for the call. We must expand |
| 4617 | // the source in case it is shared (this pass of legalize must traverse it). |
| 4618 | SDOperand SrcLo, SrcHi; |
| 4619 | ExpandOp(Source, SrcLo, SrcHi); |
| 4620 | Source = DAG.getNode(ISD::BUILD_PAIR, Source.getValueType(), SrcLo, SrcHi); |
| 4621 | |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4622 | RTLIB::Libcall LC; |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 4623 | if (DestTy == MVT::f32) |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4624 | LC = RTLIB::SINTTOFP_I64_F32; |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 4625 | else { |
| 4626 | assert(DestTy == MVT::f64 && "Unknown fp value type!"); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4627 | LC = RTLIB::SINTTOFP_I64_F64; |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 4628 | } |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 4629 | |
Evan Cheng | 4c6cfad | 2007-04-27 07:33:31 +0000 | [diff] [blame] | 4630 | 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] | 4631 | Source = DAG.getNode(ISD::SINT_TO_FP, DestTy, Source); |
| 4632 | SDOperand UnusedHiPart; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4633 | return ExpandLibCall(TLI.getLibcallName(LC), Source.Val, isSigned, |
| 4634 | UnusedHiPart); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4635 | } |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 4636 | |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 4637 | /// ExpandLegalINT_TO_FP - This function is responsible for legalizing a |
| 4638 | /// INT_TO_FP operation of the specified operand when the target requests that |
| 4639 | /// we expand it. At this point, we know that the result and operand types are |
| 4640 | /// legal for the target. |
| 4641 | SDOperand SelectionDAGLegalize::ExpandLegalINT_TO_FP(bool isSigned, |
| 4642 | SDOperand Op0, |
| 4643 | MVT::ValueType DestVT) { |
| 4644 | if (Op0.getValueType() == MVT::i32) { |
| 4645 | // simple 32-bit [signed|unsigned] integer to float/double expansion |
| 4646 | |
Chris Lattner | 58092e3 | 2007-01-20 22:35:55 +0000 | [diff] [blame] | 4647 | // get the stack frame index of a 8 byte buffer, pessimistically aligned |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 4648 | MachineFunction &MF = DAG.getMachineFunction(); |
Chris Lattner | 58092e3 | 2007-01-20 22:35:55 +0000 | [diff] [blame] | 4649 | const Type *F64Type = MVT::getTypeForValueType(MVT::f64); |
| 4650 | unsigned StackAlign = |
Chris Lattner | d2b7cec | 2007-02-14 05:52:17 +0000 | [diff] [blame] | 4651 | (unsigned)TLI.getTargetData()->getPrefTypeAlignment(F64Type); |
Chris Lattner | 58092e3 | 2007-01-20 22:35:55 +0000 | [diff] [blame] | 4652 | int SSFI = MF.getFrameInfo()->CreateStackObject(8, StackAlign); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 4653 | // get address of 8 byte buffer |
| 4654 | SDOperand StackSlot = DAG.getFrameIndex(SSFI, TLI.getPointerTy()); |
| 4655 | // word offset constant for Hi/Lo address computation |
| 4656 | SDOperand WordOff = DAG.getConstant(sizeof(int), TLI.getPointerTy()); |
| 4657 | // set up Hi and Lo (into buffer) address based on endian |
Chris Lattner | 408c428 | 2006-03-23 05:29:04 +0000 | [diff] [blame] | 4658 | SDOperand Hi = StackSlot; |
| 4659 | SDOperand Lo = DAG.getNode(ISD::ADD, TLI.getPointerTy(), StackSlot,WordOff); |
| 4660 | if (TLI.isLittleEndian()) |
| 4661 | std::swap(Hi, Lo); |
| 4662 | |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 4663 | // if signed map to unsigned space |
| 4664 | SDOperand Op0Mapped; |
| 4665 | if (isSigned) { |
| 4666 | // constant used to invert sign bit (signed to unsigned mapping) |
| 4667 | SDOperand SignBit = DAG.getConstant(0x80000000u, MVT::i32); |
| 4668 | Op0Mapped = DAG.getNode(ISD::XOR, MVT::i32, Op0, SignBit); |
| 4669 | } else { |
| 4670 | Op0Mapped = Op0; |
| 4671 | } |
| 4672 | // store the lo of the constructed double - based on integer input |
Evan Cheng | 786225a | 2006-10-05 23:01:46 +0000 | [diff] [blame] | 4673 | SDOperand Store1 = DAG.getStore(DAG.getEntryNode(), |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 4674 | Op0Mapped, Lo, NULL, 0); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 4675 | // initial hi portion of constructed double |
| 4676 | SDOperand InitialHi = DAG.getConstant(0x43300000u, MVT::i32); |
| 4677 | // store the hi of the constructed double - biased exponent |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 4678 | SDOperand Store2=DAG.getStore(Store1, InitialHi, Hi, NULL, 0); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 4679 | // load the constructed double |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 4680 | SDOperand Load = DAG.getLoad(MVT::f64, Store2, StackSlot, NULL, 0); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 4681 | // FP constant to bias correct the final result |
| 4682 | SDOperand Bias = DAG.getConstantFP(isSigned ? |
| 4683 | BitsToDouble(0x4330000080000000ULL) |
| 4684 | : BitsToDouble(0x4330000000000000ULL), |
| 4685 | MVT::f64); |
| 4686 | // subtract the bias |
| 4687 | SDOperand Sub = DAG.getNode(ISD::FSUB, MVT::f64, Load, Bias); |
| 4688 | // final result |
| 4689 | SDOperand Result; |
| 4690 | // handle final rounding |
| 4691 | if (DestVT == MVT::f64) { |
| 4692 | // do nothing |
| 4693 | Result = Sub; |
| 4694 | } else { |
| 4695 | // if f32 then cast to f32 |
| 4696 | Result = DAG.getNode(ISD::FP_ROUND, MVT::f32, Sub); |
| 4697 | } |
| 4698 | return Result; |
| 4699 | } |
| 4700 | assert(!isSigned && "Legalize cannot Expand SINT_TO_FP for i64 yet"); |
| 4701 | SDOperand Tmp1 = DAG.getNode(ISD::SINT_TO_FP, DestVT, Op0); |
| 4702 | |
| 4703 | SDOperand SignSet = DAG.getSetCC(TLI.getSetCCResultTy(), Op0, |
| 4704 | DAG.getConstant(0, Op0.getValueType()), |
| 4705 | ISD::SETLT); |
| 4706 | SDOperand Zero = getIntPtrConstant(0), Four = getIntPtrConstant(4); |
| 4707 | SDOperand CstOffset = DAG.getNode(ISD::SELECT, Zero.getValueType(), |
| 4708 | SignSet, Four, Zero); |
| 4709 | |
| 4710 | // If the sign bit of the integer is set, the large number will be treated |
| 4711 | // as a negative number. To counteract this, the dynamic code adds an |
| 4712 | // offset depending on the data type. |
| 4713 | uint64_t FF; |
| 4714 | switch (Op0.getValueType()) { |
| 4715 | default: assert(0 && "Unsupported integer type!"); |
| 4716 | case MVT::i8 : FF = 0x43800000ULL; break; // 2^8 (as a float) |
| 4717 | case MVT::i16: FF = 0x47800000ULL; break; // 2^16 (as a float) |
| 4718 | case MVT::i32: FF = 0x4F800000ULL; break; // 2^32 (as a float) |
| 4719 | case MVT::i64: FF = 0x5F800000ULL; break; // 2^64 (as a float) |
| 4720 | } |
| 4721 | if (TLI.isLittleEndian()) FF <<= 32; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 4722 | static Constant *FudgeFactor = ConstantInt::get(Type::Int64Ty, FF); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 4723 | |
| 4724 | SDOperand CPIdx = DAG.getConstantPool(FudgeFactor, TLI.getPointerTy()); |
| 4725 | CPIdx = DAG.getNode(ISD::ADD, TLI.getPointerTy(), CPIdx, CstOffset); |
| 4726 | SDOperand FudgeInReg; |
| 4727 | if (DestVT == MVT::f32) |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 4728 | FudgeInReg = DAG.getLoad(MVT::f32, DAG.getEntryNode(), CPIdx, NULL, 0); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 4729 | else { |
| 4730 | assert(DestVT == MVT::f64 && "Unexpected conversion"); |
| 4731 | FudgeInReg = LegalizeOp(DAG.getExtLoad(ISD::EXTLOAD, MVT::f64, |
| 4732 | DAG.getEntryNode(), CPIdx, |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 4733 | NULL, 0, MVT::f32)); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 4734 | } |
| 4735 | |
| 4736 | return DAG.getNode(ISD::FADD, DestVT, Tmp1, FudgeInReg); |
| 4737 | } |
| 4738 | |
| 4739 | /// PromoteLegalINT_TO_FP - This function is responsible for legalizing a |
| 4740 | /// *INT_TO_FP operation of the specified operand when the target requests that |
| 4741 | /// we promote it. At this point, we know that the result and operand types are |
| 4742 | /// legal for the target, and that there is a legal UINT_TO_FP or SINT_TO_FP |
| 4743 | /// operation that takes a larger input. |
| 4744 | SDOperand SelectionDAGLegalize::PromoteLegalINT_TO_FP(SDOperand LegalOp, |
| 4745 | MVT::ValueType DestVT, |
| 4746 | bool isSigned) { |
| 4747 | // First step, figure out the appropriate *INT_TO_FP operation to use. |
| 4748 | MVT::ValueType NewInTy = LegalOp.getValueType(); |
| 4749 | |
| 4750 | unsigned OpToUse = 0; |
| 4751 | |
| 4752 | // Scan for the appropriate larger type to use. |
| 4753 | while (1) { |
| 4754 | NewInTy = (MVT::ValueType)(NewInTy+1); |
| 4755 | assert(MVT::isInteger(NewInTy) && "Ran out of possibilities!"); |
| 4756 | |
| 4757 | // If the target supports SINT_TO_FP of this type, use it. |
| 4758 | switch (TLI.getOperationAction(ISD::SINT_TO_FP, NewInTy)) { |
| 4759 | default: break; |
| 4760 | case TargetLowering::Legal: |
| 4761 | if (!TLI.isTypeLegal(NewInTy)) |
| 4762 | break; // Can't use this datatype. |
| 4763 | // FALL THROUGH. |
| 4764 | case TargetLowering::Custom: |
| 4765 | OpToUse = ISD::SINT_TO_FP; |
| 4766 | break; |
| 4767 | } |
| 4768 | if (OpToUse) break; |
| 4769 | if (isSigned) continue; |
| 4770 | |
| 4771 | // If the target supports UINT_TO_FP of this type, use it. |
| 4772 | switch (TLI.getOperationAction(ISD::UINT_TO_FP, NewInTy)) { |
| 4773 | default: break; |
| 4774 | case TargetLowering::Legal: |
| 4775 | if (!TLI.isTypeLegal(NewInTy)) |
| 4776 | break; // Can't use this datatype. |
| 4777 | // FALL THROUGH. |
| 4778 | case TargetLowering::Custom: |
| 4779 | OpToUse = ISD::UINT_TO_FP; |
| 4780 | break; |
| 4781 | } |
| 4782 | if (OpToUse) break; |
| 4783 | |
| 4784 | // Otherwise, try a larger type. |
| 4785 | } |
| 4786 | |
| 4787 | // Okay, we found the operation and type to use. Zero extend our input to the |
| 4788 | // desired type then run the operation on it. |
| 4789 | return DAG.getNode(OpToUse, DestVT, |
| 4790 | DAG.getNode(isSigned ? ISD::SIGN_EXTEND : ISD::ZERO_EXTEND, |
| 4791 | NewInTy, LegalOp)); |
| 4792 | } |
| 4793 | |
| 4794 | /// PromoteLegalFP_TO_INT - This function is responsible for legalizing a |
| 4795 | /// FP_TO_*INT operation of the specified operand when the target requests that |
| 4796 | /// we promote it. At this point, we know that the result and operand types are |
| 4797 | /// legal for the target, and that there is a legal FP_TO_UINT or FP_TO_SINT |
| 4798 | /// operation that returns a larger result. |
| 4799 | SDOperand SelectionDAGLegalize::PromoteLegalFP_TO_INT(SDOperand LegalOp, |
| 4800 | MVT::ValueType DestVT, |
| 4801 | bool isSigned) { |
| 4802 | // First step, figure out the appropriate FP_TO*INT operation to use. |
| 4803 | MVT::ValueType NewOutTy = DestVT; |
| 4804 | |
| 4805 | unsigned OpToUse = 0; |
| 4806 | |
| 4807 | // Scan for the appropriate larger type to use. |
| 4808 | while (1) { |
| 4809 | NewOutTy = (MVT::ValueType)(NewOutTy+1); |
| 4810 | assert(MVT::isInteger(NewOutTy) && "Ran out of possibilities!"); |
| 4811 | |
| 4812 | // If the target supports FP_TO_SINT returning this type, use it. |
| 4813 | switch (TLI.getOperationAction(ISD::FP_TO_SINT, NewOutTy)) { |
| 4814 | default: break; |
| 4815 | case TargetLowering::Legal: |
| 4816 | if (!TLI.isTypeLegal(NewOutTy)) |
| 4817 | break; // Can't use this datatype. |
| 4818 | // FALL THROUGH. |
| 4819 | case TargetLowering::Custom: |
| 4820 | OpToUse = ISD::FP_TO_SINT; |
| 4821 | break; |
| 4822 | } |
| 4823 | if (OpToUse) break; |
| 4824 | |
| 4825 | // If the target supports FP_TO_UINT of this type, use it. |
| 4826 | switch (TLI.getOperationAction(ISD::FP_TO_UINT, NewOutTy)) { |
| 4827 | default: break; |
| 4828 | case TargetLowering::Legal: |
| 4829 | if (!TLI.isTypeLegal(NewOutTy)) |
| 4830 | break; // Can't use this datatype. |
| 4831 | // FALL THROUGH. |
| 4832 | case TargetLowering::Custom: |
| 4833 | OpToUse = ISD::FP_TO_UINT; |
| 4834 | break; |
| 4835 | } |
| 4836 | if (OpToUse) break; |
| 4837 | |
| 4838 | // Otherwise, try a larger type. |
| 4839 | } |
| 4840 | |
| 4841 | // Okay, we found the operation and type to use. Truncate the result of the |
| 4842 | // extended FP_TO_*INT operation to the desired size. |
| 4843 | return DAG.getNode(ISD::TRUNCATE, DestVT, |
| 4844 | DAG.getNode(OpToUse, NewOutTy, LegalOp)); |
| 4845 | } |
| 4846 | |
| 4847 | /// ExpandBSWAP - Open code the operations for BSWAP of the specified operation. |
| 4848 | /// |
| 4849 | SDOperand SelectionDAGLegalize::ExpandBSWAP(SDOperand Op) { |
| 4850 | MVT::ValueType VT = Op.getValueType(); |
| 4851 | MVT::ValueType SHVT = TLI.getShiftAmountTy(); |
| 4852 | SDOperand Tmp1, Tmp2, Tmp3, Tmp4, Tmp5, Tmp6, Tmp7, Tmp8; |
| 4853 | switch (VT) { |
| 4854 | default: assert(0 && "Unhandled Expand type in BSWAP!"); abort(); |
| 4855 | case MVT::i16: |
| 4856 | Tmp2 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(8, SHVT)); |
| 4857 | Tmp1 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(8, SHVT)); |
| 4858 | return DAG.getNode(ISD::OR, VT, Tmp1, Tmp2); |
| 4859 | case MVT::i32: |
| 4860 | Tmp4 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(24, SHVT)); |
| 4861 | Tmp3 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(8, SHVT)); |
| 4862 | Tmp2 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(8, SHVT)); |
| 4863 | Tmp1 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(24, SHVT)); |
| 4864 | Tmp3 = DAG.getNode(ISD::AND, VT, Tmp3, DAG.getConstant(0xFF0000, VT)); |
| 4865 | Tmp2 = DAG.getNode(ISD::AND, VT, Tmp2, DAG.getConstant(0xFF00, VT)); |
| 4866 | Tmp4 = DAG.getNode(ISD::OR, VT, Tmp4, Tmp3); |
| 4867 | Tmp2 = DAG.getNode(ISD::OR, VT, Tmp2, Tmp1); |
| 4868 | return DAG.getNode(ISD::OR, VT, Tmp4, Tmp2); |
| 4869 | case MVT::i64: |
| 4870 | Tmp8 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(56, SHVT)); |
| 4871 | Tmp7 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(40, SHVT)); |
| 4872 | Tmp6 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(24, SHVT)); |
| 4873 | Tmp5 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(8, SHVT)); |
| 4874 | Tmp4 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(8, SHVT)); |
| 4875 | Tmp3 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(24, SHVT)); |
| 4876 | Tmp2 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(40, SHVT)); |
| 4877 | Tmp1 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(56, SHVT)); |
| 4878 | Tmp7 = DAG.getNode(ISD::AND, VT, Tmp7, DAG.getConstant(255ULL<<48, VT)); |
| 4879 | Tmp6 = DAG.getNode(ISD::AND, VT, Tmp6, DAG.getConstant(255ULL<<40, VT)); |
| 4880 | Tmp5 = DAG.getNode(ISD::AND, VT, Tmp5, DAG.getConstant(255ULL<<32, VT)); |
| 4881 | Tmp4 = DAG.getNode(ISD::AND, VT, Tmp4, DAG.getConstant(255ULL<<24, VT)); |
| 4882 | Tmp3 = DAG.getNode(ISD::AND, VT, Tmp3, DAG.getConstant(255ULL<<16, VT)); |
| 4883 | Tmp2 = DAG.getNode(ISD::AND, VT, Tmp2, DAG.getConstant(255ULL<<8 , VT)); |
| 4884 | Tmp8 = DAG.getNode(ISD::OR, VT, Tmp8, Tmp7); |
| 4885 | Tmp6 = DAG.getNode(ISD::OR, VT, Tmp6, Tmp5); |
| 4886 | Tmp4 = DAG.getNode(ISD::OR, VT, Tmp4, Tmp3); |
| 4887 | Tmp2 = DAG.getNode(ISD::OR, VT, Tmp2, Tmp1); |
| 4888 | Tmp8 = DAG.getNode(ISD::OR, VT, Tmp8, Tmp6); |
| 4889 | Tmp4 = DAG.getNode(ISD::OR, VT, Tmp4, Tmp2); |
| 4890 | return DAG.getNode(ISD::OR, VT, Tmp8, Tmp4); |
| 4891 | } |
| 4892 | } |
| 4893 | |
| 4894 | /// ExpandBitCount - Expand the specified bitcount instruction into operations. |
| 4895 | /// |
| 4896 | SDOperand SelectionDAGLegalize::ExpandBitCount(unsigned Opc, SDOperand Op) { |
| 4897 | switch (Opc) { |
| 4898 | default: assert(0 && "Cannot expand this yet!"); |
| 4899 | case ISD::CTPOP: { |
| 4900 | static const uint64_t mask[6] = { |
| 4901 | 0x5555555555555555ULL, 0x3333333333333333ULL, |
| 4902 | 0x0F0F0F0F0F0F0F0FULL, 0x00FF00FF00FF00FFULL, |
| 4903 | 0x0000FFFF0000FFFFULL, 0x00000000FFFFFFFFULL |
| 4904 | }; |
| 4905 | MVT::ValueType VT = Op.getValueType(); |
| 4906 | MVT::ValueType ShVT = TLI.getShiftAmountTy(); |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 4907 | unsigned len = MVT::getSizeInBits(VT); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 4908 | for (unsigned i = 0; (1U << i) <= (len / 2); ++i) { |
| 4909 | //x = (x & mask[i][len/8]) + (x >> (1 << i) & mask[i][len/8]) |
| 4910 | SDOperand Tmp2 = DAG.getConstant(mask[i], VT); |
| 4911 | SDOperand Tmp3 = DAG.getConstant(1ULL << i, ShVT); |
| 4912 | Op = DAG.getNode(ISD::ADD, VT, DAG.getNode(ISD::AND, VT, Op, Tmp2), |
| 4913 | DAG.getNode(ISD::AND, VT, |
| 4914 | DAG.getNode(ISD::SRL, VT, Op, Tmp3),Tmp2)); |
| 4915 | } |
| 4916 | return Op; |
| 4917 | } |
| 4918 | case ISD::CTLZ: { |
| 4919 | // for now, we do this: |
| 4920 | // x = x | (x >> 1); |
| 4921 | // x = x | (x >> 2); |
| 4922 | // ... |
| 4923 | // x = x | (x >>16); |
| 4924 | // x = x | (x >>32); // for 64-bit input |
| 4925 | // return popcount(~x); |
| 4926 | // |
| 4927 | // but see also: http://www.hackersdelight.org/HDcode/nlz.cc |
| 4928 | MVT::ValueType VT = Op.getValueType(); |
| 4929 | MVT::ValueType ShVT = TLI.getShiftAmountTy(); |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 4930 | unsigned len = MVT::getSizeInBits(VT); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 4931 | for (unsigned i = 0; (1U << i) <= (len / 2); ++i) { |
| 4932 | SDOperand Tmp3 = DAG.getConstant(1ULL << i, ShVT); |
| 4933 | Op = DAG.getNode(ISD::OR, VT, Op, DAG.getNode(ISD::SRL, VT, Op, Tmp3)); |
| 4934 | } |
| 4935 | Op = DAG.getNode(ISD::XOR, VT, Op, DAG.getConstant(~0ULL, VT)); |
| 4936 | return DAG.getNode(ISD::CTPOP, VT, Op); |
| 4937 | } |
| 4938 | case ISD::CTTZ: { |
| 4939 | // for now, we use: { return popcount(~x & (x - 1)); } |
| 4940 | // unless the target has ctlz but not ctpop, in which case we use: |
| 4941 | // { return 32 - nlz(~x & (x-1)); } |
| 4942 | // see also http://www.hackersdelight.org/HDcode/ntz.cc |
| 4943 | MVT::ValueType VT = Op.getValueType(); |
| 4944 | SDOperand Tmp2 = DAG.getConstant(~0ULL, VT); |
| 4945 | SDOperand Tmp3 = DAG.getNode(ISD::AND, VT, |
| 4946 | DAG.getNode(ISD::XOR, VT, Op, Tmp2), |
| 4947 | DAG.getNode(ISD::SUB, VT, Op, DAG.getConstant(1, VT))); |
| 4948 | // If ISD::CTLZ is legal and CTPOP isn't, then do that instead. |
| 4949 | if (!TLI.isOperationLegal(ISD::CTPOP, VT) && |
| 4950 | TLI.isOperationLegal(ISD::CTLZ, VT)) |
| 4951 | return DAG.getNode(ISD::SUB, VT, |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 4952 | DAG.getConstant(MVT::getSizeInBits(VT), VT), |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 4953 | DAG.getNode(ISD::CTLZ, VT, Tmp3)); |
| 4954 | return DAG.getNode(ISD::CTPOP, VT, Tmp3); |
| 4955 | } |
| 4956 | } |
| 4957 | } |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 4958 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 4959 | /// ExpandOp - Expand the specified SDOperand into its two component pieces |
| 4960 | /// Lo&Hi. Note that the Op MUST be an expanded type. As a result of this, the |
| 4961 | /// LegalizeNodes map is filled in for any results that are not expanded, the |
| 4962 | /// ExpandedNodes map is filled in for any results that are expanded, and the |
| 4963 | /// Lo/Hi values are returned. |
| 4964 | void SelectionDAGLegalize::ExpandOp(SDOperand Op, SDOperand &Lo, SDOperand &Hi){ |
| 4965 | MVT::ValueType VT = Op.getValueType(); |
Chris Lattner | 71c42a0 | 2005-01-16 01:11:45 +0000 | [diff] [blame] | 4966 | MVT::ValueType NVT = TLI.getTypeToTransformTo(VT); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 4967 | SDNode *Node = Op.Val; |
| 4968 | assert(getTypeAction(VT) == Expand && "Not an expanded type!"); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 4969 | assert(((MVT::isInteger(NVT) && NVT < VT) || MVT::isFloatingPoint(VT) || |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4970 | MVT::isVector(VT)) && |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 4971 | "Cannot expand to FP value or to larger int value!"); |
| 4972 | |
Chris Lattner | 6fdcb25 | 2005-09-02 20:32:45 +0000 | [diff] [blame] | 4973 | // See if we already expanded it. |
Chris Lattner | 40030bf | 2007-02-04 01:17:38 +0000 | [diff] [blame] | 4974 | DenseMap<SDOperand, std::pair<SDOperand, SDOperand> >::iterator I |
Chris Lattner | 6fdcb25 | 2005-09-02 20:32:45 +0000 | [diff] [blame] | 4975 | = ExpandedNodes.find(Op); |
| 4976 | if (I != ExpandedNodes.end()) { |
| 4977 | Lo = I->second.first; |
| 4978 | Hi = I->second.second; |
| 4979 | return; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 4980 | } |
| 4981 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 4982 | switch (Node->getOpcode()) { |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 4983 | case ISD::CopyFromReg: |
| 4984 | assert(0 && "CopyFromReg must be legal!"); |
| 4985 | default: |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 4986 | #ifndef NDEBUG |
Dan Gohman | 3983358 | 2007-06-04 16:17:33 +0000 | [diff] [blame] | 4987 | cerr << "NODE: "; Node->dump(&DAG); cerr << "\n"; |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 4988 | #endif |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 4989 | assert(0 && "Do not know how to expand this operator!"); |
| 4990 | abort(); |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 4991 | case ISD::UNDEF: |
Evan Cheng | aa975c1 | 2006-12-16 02:20:50 +0000 | [diff] [blame] | 4992 | NVT = TLI.getTypeToExpandTo(VT); |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 4993 | Lo = DAG.getNode(ISD::UNDEF, NVT); |
| 4994 | Hi = DAG.getNode(ISD::UNDEF, NVT); |
| 4995 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 4996 | case ISD::Constant: { |
| 4997 | uint64_t Cst = cast<ConstantSDNode>(Node)->getValue(); |
| 4998 | Lo = DAG.getConstant(Cst, NVT); |
| 4999 | Hi = DAG.getConstant(Cst >> MVT::getSizeInBits(NVT), NVT); |
| 5000 | break; |
| 5001 | } |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 5002 | case ISD::ConstantFP: { |
| 5003 | ConstantFPSDNode *CFP = cast<ConstantFPSDNode>(Node); |
Evan Cheng | 279101e | 2006-12-12 22:19:28 +0000 | [diff] [blame] | 5004 | Lo = ExpandConstantFP(CFP, false, DAG, TLI); |
Evan Cheng | 9f87788 | 2006-12-13 20:57:08 +0000 | [diff] [blame] | 5005 | if (getTypeAction(Lo.getValueType()) == Expand) |
| 5006 | ExpandOp(Lo, Lo, Hi); |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 5007 | break; |
| 5008 | } |
Chris Lattner | d4e50bb | 2005-03-28 22:03:13 +0000 | [diff] [blame] | 5009 | case ISD::BUILD_PAIR: |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5010 | // Return the operands. |
| 5011 | Lo = Node->getOperand(0); |
| 5012 | Hi = Node->getOperand(1); |
Chris Lattner | d4e50bb | 2005-03-28 22:03:13 +0000 | [diff] [blame] | 5013 | break; |
Chris Lattner | 58f7963 | 2005-12-12 22:27:43 +0000 | [diff] [blame] | 5014 | |
| 5015 | case ISD::SIGN_EXTEND_INREG: |
| 5016 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Chris Lattner | 4bdd275 | 2006-10-06 17:34:12 +0000 | [diff] [blame] | 5017 | // sext_inreg the low part if needed. |
| 5018 | Lo = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Lo, Node->getOperand(1)); |
| 5019 | |
| 5020 | // The high part gets the sign extension from the lo-part. This handles |
| 5021 | // things like sextinreg V:i64 from i8. |
Chris Lattner | 58f7963 | 2005-12-12 22:27:43 +0000 | [diff] [blame] | 5022 | Hi = DAG.getNode(ISD::SRA, NVT, Lo, |
| 5023 | DAG.getConstant(MVT::getSizeInBits(NVT)-1, |
| 5024 | TLI.getShiftAmountTy())); |
Chris Lattner | 58f7963 | 2005-12-12 22:27:43 +0000 | [diff] [blame] | 5025 | break; |
Chris Lattner | d4e50bb | 2005-03-28 22:03:13 +0000 | [diff] [blame] | 5026 | |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 5027 | case ISD::BSWAP: { |
| 5028 | ExpandOp(Node->getOperand(0), Lo, Hi); |
| 5029 | SDOperand TempLo = DAG.getNode(ISD::BSWAP, NVT, Hi); |
| 5030 | Hi = DAG.getNode(ISD::BSWAP, NVT, Lo); |
| 5031 | Lo = TempLo; |
| 5032 | break; |
| 5033 | } |
| 5034 | |
Chris Lattner | edb1add | 2005-05-11 04:51:16 +0000 | [diff] [blame] | 5035 | case ISD::CTPOP: |
| 5036 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Chris Lattner | 9b583b4 | 2005-05-11 05:09:47 +0000 | [diff] [blame] | 5037 | Lo = DAG.getNode(ISD::ADD, NVT, // ctpop(HL) -> ctpop(H)+ctpop(L) |
| 5038 | DAG.getNode(ISD::CTPOP, NVT, Lo), |
| 5039 | DAG.getNode(ISD::CTPOP, NVT, Hi)); |
Chris Lattner | edb1add | 2005-05-11 04:51:16 +0000 | [diff] [blame] | 5040 | Hi = DAG.getConstant(0, NVT); |
| 5041 | break; |
| 5042 | |
Chris Lattner | 39a8f33 | 2005-05-12 19:05:01 +0000 | [diff] [blame] | 5043 | case ISD::CTLZ: { |
| 5044 | // ctlz (HL) -> ctlz(H) != 32 ? ctlz(H) : (ctlz(L)+32) |
Chris Lattner | 3becf20 | 2005-05-12 19:27:51 +0000 | [diff] [blame] | 5045 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Chris Lattner | 39a8f33 | 2005-05-12 19:05:01 +0000 | [diff] [blame] | 5046 | SDOperand BitsC = DAG.getConstant(MVT::getSizeInBits(NVT), NVT); |
| 5047 | SDOperand HLZ = DAG.getNode(ISD::CTLZ, NVT, Hi); |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 5048 | SDOperand TopNotZero = DAG.getSetCC(TLI.getSetCCResultTy(), HLZ, BitsC, |
| 5049 | ISD::SETNE); |
Chris Lattner | 39a8f33 | 2005-05-12 19:05:01 +0000 | [diff] [blame] | 5050 | SDOperand LowPart = DAG.getNode(ISD::CTLZ, NVT, Lo); |
| 5051 | LowPart = DAG.getNode(ISD::ADD, NVT, LowPart, BitsC); |
| 5052 | |
| 5053 | Lo = DAG.getNode(ISD::SELECT, NVT, TopNotZero, HLZ, LowPart); |
| 5054 | Hi = DAG.getConstant(0, NVT); |
| 5055 | break; |
| 5056 | } |
| 5057 | |
| 5058 | case ISD::CTTZ: { |
| 5059 | // cttz (HL) -> cttz(L) != 32 ? cttz(L) : (cttz(H)+32) |
Chris Lattner | 3becf20 | 2005-05-12 19:27:51 +0000 | [diff] [blame] | 5060 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Chris Lattner | 39a8f33 | 2005-05-12 19:05:01 +0000 | [diff] [blame] | 5061 | SDOperand BitsC = DAG.getConstant(MVT::getSizeInBits(NVT), NVT); |
| 5062 | SDOperand LTZ = DAG.getNode(ISD::CTTZ, NVT, Lo); |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 5063 | SDOperand BotNotZero = DAG.getSetCC(TLI.getSetCCResultTy(), LTZ, BitsC, |
| 5064 | ISD::SETNE); |
Chris Lattner | 39a8f33 | 2005-05-12 19:05:01 +0000 | [diff] [blame] | 5065 | SDOperand HiPart = DAG.getNode(ISD::CTTZ, NVT, Hi); |
| 5066 | HiPart = DAG.getNode(ISD::ADD, NVT, HiPart, BitsC); |
| 5067 | |
| 5068 | Lo = DAG.getNode(ISD::SELECT, NVT, BotNotZero, LTZ, HiPart); |
| 5069 | Hi = DAG.getConstant(0, NVT); |
| 5070 | break; |
| 5071 | } |
Chris Lattner | edb1add | 2005-05-11 04:51:16 +0000 | [diff] [blame] | 5072 | |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 5073 | case ISD::VAARG: { |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5074 | SDOperand Ch = Node->getOperand(0); // Legalize the chain. |
| 5075 | SDOperand Ptr = Node->getOperand(1); // Legalize the pointer. |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 5076 | Lo = DAG.getVAArg(NVT, Ch, Ptr, Node->getOperand(2)); |
| 5077 | Hi = DAG.getVAArg(NVT, Lo.getValue(1), Ptr, Node->getOperand(2)); |
| 5078 | |
| 5079 | // Remember that we legalized the chain. |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5080 | Hi = LegalizeOp(Hi); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 5081 | AddLegalizedOperand(Op.getValue(1), Hi.getValue(1)); |
| 5082 | if (!TLI.isLittleEndian()) |
| 5083 | std::swap(Lo, Hi); |
| 5084 | break; |
| 5085 | } |
| 5086 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5087 | case ISD::LOAD: { |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 5088 | LoadSDNode *LD = cast<LoadSDNode>(Node); |
| 5089 | SDOperand Ch = LD->getChain(); // Legalize the chain. |
| 5090 | SDOperand Ptr = LD->getBasePtr(); // Legalize the pointer. |
| 5091 | ISD::LoadExtType ExtType = LD->getExtensionType(); |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 5092 | int SVOffset = LD->getSrcValueOffset(); |
| 5093 | unsigned Alignment = LD->getAlignment(); |
| 5094 | bool isVolatile = LD->isVolatile(); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5095 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 5096 | if (ExtType == ISD::NON_EXTLOAD) { |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 5097 | Lo = DAG.getLoad(NVT, Ch, Ptr, LD->getSrcValue(), SVOffset, |
| 5098 | isVolatile, Alignment); |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 5099 | if (VT == MVT::f32 || VT == MVT::f64) { |
| 5100 | // f32->i32 or f64->i64 one to one expansion. |
| 5101 | // Remember that we legalized the chain. |
| 5102 | AddLegalizedOperand(SDOperand(Node, 1), LegalizeOp(Lo.getValue(1))); |
Evan Cheng | 9f87788 | 2006-12-13 20:57:08 +0000 | [diff] [blame] | 5103 | // Recursively expand the new load. |
| 5104 | if (getTypeAction(NVT) == Expand) |
| 5105 | ExpandOp(Lo, Lo, Hi); |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 5106 | break; |
| 5107 | } |
Chris Lattner | ec39a45 | 2005-01-19 18:02:17 +0000 | [diff] [blame] | 5108 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 5109 | // Increment the pointer to the other half. |
| 5110 | unsigned IncrementSize = MVT::getSizeInBits(Lo.getValueType())/8; |
| 5111 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
| 5112 | getIntPtrConstant(IncrementSize)); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5113 | SVOffset += IncrementSize; |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 5114 | if (Alignment > IncrementSize) |
| 5115 | Alignment = IncrementSize; |
| 5116 | Hi = DAG.getLoad(NVT, Ch, Ptr, LD->getSrcValue(), SVOffset, |
| 5117 | isVolatile, Alignment); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 5118 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 5119 | // Build a factor node to remember that this load is independent of the |
| 5120 | // other one. |
| 5121 | SDOperand TF = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1), |
| 5122 | Hi.getValue(1)); |
| 5123 | |
| 5124 | // Remember that we legalized the chain. |
| 5125 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(TF)); |
| 5126 | if (!TLI.isLittleEndian()) |
| 5127 | std::swap(Lo, Hi); |
| 5128 | } else { |
Evan Cheng | 2e49f09 | 2006-10-11 07:10:22 +0000 | [diff] [blame] | 5129 | MVT::ValueType EVT = LD->getLoadedVT(); |
Evan Cheng | 548f611 | 2006-12-13 03:19:57 +0000 | [diff] [blame] | 5130 | |
| 5131 | if (VT == MVT::f64 && EVT == MVT::f32) { |
| 5132 | // f64 = EXTLOAD f32 should expand to LOAD, FP_EXTEND |
| 5133 | SDOperand Load = DAG.getLoad(EVT, Ch, Ptr, LD->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 5134 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 548f611 | 2006-12-13 03:19:57 +0000 | [diff] [blame] | 5135 | // Remember that we legalized the chain. |
| 5136 | AddLegalizedOperand(SDOperand(Node, 1), LegalizeOp(Load.getValue(1))); |
| 5137 | ExpandOp(DAG.getNode(ISD::FP_EXTEND, VT, Load), Lo, Hi); |
| 5138 | break; |
| 5139 | } |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 5140 | |
| 5141 | if (EVT == NVT) |
| 5142 | Lo = DAG.getLoad(NVT, Ch, Ptr, LD->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 5143 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 5144 | else |
| 5145 | Lo = DAG.getExtLoad(ExtType, NVT, Ch, Ptr, LD->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 5146 | SVOffset, EVT, isVolatile, |
| 5147 | Alignment); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 5148 | |
| 5149 | // Remember that we legalized the chain. |
| 5150 | AddLegalizedOperand(SDOperand(Node, 1), LegalizeOp(Lo.getValue(1))); |
| 5151 | |
| 5152 | if (ExtType == ISD::SEXTLOAD) { |
| 5153 | // The high part is obtained by SRA'ing all but one of the bits of the |
| 5154 | // lo part. |
| 5155 | unsigned LoSize = MVT::getSizeInBits(Lo.getValueType()); |
| 5156 | Hi = DAG.getNode(ISD::SRA, NVT, Lo, |
| 5157 | DAG.getConstant(LoSize-1, TLI.getShiftAmountTy())); |
| 5158 | } else if (ExtType == ISD::ZEXTLOAD) { |
| 5159 | // The high part is just a zero. |
| 5160 | Hi = DAG.getConstant(0, NVT); |
| 5161 | } else /* if (ExtType == ISD::EXTLOAD) */ { |
| 5162 | // The high part is undefined. |
| 5163 | Hi = DAG.getNode(ISD::UNDEF, NVT); |
| 5164 | } |
| 5165 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5166 | break; |
| 5167 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5168 | case ISD::AND: |
| 5169 | case ISD::OR: |
| 5170 | case ISD::XOR: { // Simple logical operators -> two trivial pieces. |
| 5171 | SDOperand LL, LH, RL, RH; |
| 5172 | ExpandOp(Node->getOperand(0), LL, LH); |
| 5173 | ExpandOp(Node->getOperand(1), RL, RH); |
| 5174 | Lo = DAG.getNode(Node->getOpcode(), NVT, LL, RL); |
| 5175 | Hi = DAG.getNode(Node->getOpcode(), NVT, LH, RH); |
| 5176 | break; |
| 5177 | } |
| 5178 | case ISD::SELECT: { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 5179 | SDOperand LL, LH, RL, RH; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5180 | ExpandOp(Node->getOperand(1), LL, LH); |
| 5181 | ExpandOp(Node->getOperand(2), RL, RH); |
Evan Cheng | 19103b1 | 2006-12-15 22:42:55 +0000 | [diff] [blame] | 5182 | if (getTypeAction(NVT) == Expand) |
| 5183 | NVT = TLI.getTypeToExpandTo(NVT); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 5184 | Lo = DAG.getNode(ISD::SELECT, NVT, Node->getOperand(0), LL, RL); |
Evan Cheng | 19103b1 | 2006-12-15 22:42:55 +0000 | [diff] [blame] | 5185 | if (VT != MVT::f32) |
| 5186 | Hi = DAG.getNode(ISD::SELECT, NVT, Node->getOperand(0), LH, RH); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5187 | break; |
| 5188 | } |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 5189 | case ISD::SELECT_CC: { |
| 5190 | SDOperand TL, TH, FL, FH; |
| 5191 | ExpandOp(Node->getOperand(2), TL, TH); |
| 5192 | ExpandOp(Node->getOperand(3), FL, FH); |
Evan Cheng | 19103b1 | 2006-12-15 22:42:55 +0000 | [diff] [blame] | 5193 | if (getTypeAction(NVT) == Expand) |
| 5194 | NVT = TLI.getTypeToExpandTo(NVT); |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 5195 | Lo = DAG.getNode(ISD::SELECT_CC, NVT, Node->getOperand(0), |
| 5196 | Node->getOperand(1), TL, FL, Node->getOperand(4)); |
Evan Cheng | 19103b1 | 2006-12-15 22:42:55 +0000 | [diff] [blame] | 5197 | if (VT != MVT::f32) |
| 5198 | Hi = DAG.getNode(ISD::SELECT_CC, NVT, Node->getOperand(0), |
| 5199 | Node->getOperand(1), TH, FH, Node->getOperand(4)); |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 5200 | break; |
| 5201 | } |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5202 | case ISD::ANY_EXTEND: |
| 5203 | // The low part is any extension of the input (which degenerates to a copy). |
| 5204 | Lo = DAG.getNode(ISD::ANY_EXTEND, NVT, Node->getOperand(0)); |
| 5205 | // The high part is undefined. |
| 5206 | Hi = DAG.getNode(ISD::UNDEF, NVT); |
| 5207 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5208 | case ISD::SIGN_EXTEND: { |
| 5209 | // The low part is just a sign extension of the input (which degenerates to |
| 5210 | // a copy). |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5211 | Lo = DAG.getNode(ISD::SIGN_EXTEND, NVT, Node->getOperand(0)); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 5212 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5213 | // The high part is obtained by SRA'ing all but one of the bits of the lo |
| 5214 | // part. |
Chris Lattner | 2dad454 | 2005-01-12 18:19:52 +0000 | [diff] [blame] | 5215 | unsigned LoSize = MVT::getSizeInBits(Lo.getValueType()); |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5216 | Hi = DAG.getNode(ISD::SRA, NVT, Lo, |
| 5217 | DAG.getConstant(LoSize-1, TLI.getShiftAmountTy())); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5218 | break; |
| 5219 | } |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5220 | case ISD::ZERO_EXTEND: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5221 | // The low part is just a zero extension of the input (which degenerates to |
| 5222 | // a copy). |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5223 | Lo = DAG.getNode(ISD::ZERO_EXTEND, NVT, Node->getOperand(0)); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 5224 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5225 | // The high part is just a zero. |
| 5226 | Hi = DAG.getConstant(0, NVT); |
| 5227 | break; |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 5228 | |
Chris Lattner | 4c948eb | 2007-02-13 23:55:16 +0000 | [diff] [blame] | 5229 | case ISD::TRUNCATE: { |
| 5230 | // The input value must be larger than this value. Expand *it*. |
| 5231 | SDOperand NewLo; |
| 5232 | ExpandOp(Node->getOperand(0), NewLo, Hi); |
| 5233 | |
| 5234 | // The low part is now either the right size, or it is closer. If not the |
| 5235 | // right size, make an illegal truncate so we recursively expand it. |
| 5236 | if (NewLo.getValueType() != Node->getValueType(0)) |
| 5237 | NewLo = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0), NewLo); |
| 5238 | ExpandOp(NewLo, Lo, Hi); |
| 5239 | break; |
| 5240 | } |
| 5241 | |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 5242 | case ISD::BIT_CONVERT: { |
Chris Lattner | f3f333d | 2006-09-09 00:20:27 +0000 | [diff] [blame] | 5243 | SDOperand Tmp; |
| 5244 | if (TLI.getOperationAction(ISD::BIT_CONVERT, VT) == TargetLowering::Custom){ |
| 5245 | // If the target wants to, allow it to lower this itself. |
| 5246 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 5247 | case Expand: assert(0 && "cannot expand FP!"); |
| 5248 | case Legal: Tmp = LegalizeOp(Node->getOperand(0)); break; |
| 5249 | case Promote: Tmp = PromoteOp (Node->getOperand(0)); break; |
| 5250 | } |
| 5251 | Tmp = TLI.LowerOperation(DAG.getNode(ISD::BIT_CONVERT, VT, Tmp), DAG); |
| 5252 | } |
| 5253 | |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 5254 | // f32 / f64 must be expanded to i32 / i64. |
Evan Cheng | 13acce3 | 2006-12-11 19:27:14 +0000 | [diff] [blame] | 5255 | if (VT == MVT::f32 || VT == MVT::f64) { |
| 5256 | Lo = DAG.getNode(ISD::BIT_CONVERT, NVT, Node->getOperand(0)); |
Evan Cheng | 19103b1 | 2006-12-15 22:42:55 +0000 | [diff] [blame] | 5257 | if (getTypeAction(NVT) == Expand) |
| 5258 | ExpandOp(Lo, Lo, Hi); |
Evan Cheng | 7b2b5c8 | 2006-12-12 19:53:13 +0000 | [diff] [blame] | 5259 | break; |
| 5260 | } |
| 5261 | |
| 5262 | // If source operand will be expanded to the same type as VT, i.e. |
| 5263 | // i64 <- f64, i32 <- f32, expand the source operand instead. |
| 5264 | MVT::ValueType VT0 = Node->getOperand(0).getValueType(); |
| 5265 | if (getTypeAction(VT0) == Expand && TLI.getTypeToTransformTo(VT0) == VT) { |
| 5266 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 5267 | break; |
| 5268 | } |
| 5269 | |
Chris Lattner | f3f333d | 2006-09-09 00:20:27 +0000 | [diff] [blame] | 5270 | // Turn this into a load/store pair by default. |
| 5271 | if (Tmp.Val == 0) |
Evan Cheng | 13acce3 | 2006-12-11 19:27:14 +0000 | [diff] [blame] | 5272 | Tmp = ExpandBIT_CONVERT(VT, Node->getOperand(0)); |
Chris Lattner | f3f333d | 2006-09-09 00:20:27 +0000 | [diff] [blame] | 5273 | |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 5274 | ExpandOp(Tmp, Lo, Hi); |
| 5275 | break; |
| 5276 | } |
Andrew Lenharth | f70e30b | 2005-11-20 21:32:07 +0000 | [diff] [blame] | 5277 | |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5278 | case ISD::READCYCLECOUNTER: |
Chris Lattner | 308575b | 2005-11-20 22:56:56 +0000 | [diff] [blame] | 5279 | assert(TLI.getOperationAction(ISD::READCYCLECOUNTER, VT) == |
| 5280 | TargetLowering::Custom && |
| 5281 | "Must custom expand ReadCycleCounter"); |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5282 | Lo = TLI.LowerOperation(Op, DAG); |
| 5283 | assert(Lo.Val && "Node must be custom expanded!"); |
| 5284 | Hi = Lo.getValue(1); |
Chris Lattner | 308575b | 2005-11-20 22:56:56 +0000 | [diff] [blame] | 5285 | AddLegalizedOperand(SDOperand(Node, 1), // Remember we legalized the chain. |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5286 | LegalizeOp(Lo.getValue(2))); |
Andrew Lenharth | f70e30b | 2005-11-20 21:32:07 +0000 | [diff] [blame] | 5287 | break; |
| 5288 | |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 5289 | // These operators cannot be expanded directly, emit them as calls to |
| 5290 | // library functions. |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5291 | case ISD::FP_TO_SINT: { |
Chris Lattner | 80a3e94 | 2005-07-29 00:33:32 +0000 | [diff] [blame] | 5292 | if (TLI.getOperationAction(ISD::FP_TO_SINT, VT) == TargetLowering::Custom) { |
Chris Lattner | f20d183 | 2005-07-30 01:40:57 +0000 | [diff] [blame] | 5293 | SDOperand Op; |
| 5294 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 5295 | case Expand: assert(0 && "cannot expand FP!"); |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5296 | case Legal: Op = LegalizeOp(Node->getOperand(0)); break; |
| 5297 | case Promote: Op = PromoteOp (Node->getOperand(0)); break; |
Chris Lattner | f20d183 | 2005-07-30 01:40:57 +0000 | [diff] [blame] | 5298 | } |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 5299 | |
Chris Lattner | f20d183 | 2005-07-30 01:40:57 +0000 | [diff] [blame] | 5300 | Op = TLI.LowerOperation(DAG.getNode(ISD::FP_TO_SINT, VT, Op), DAG); |
| 5301 | |
Chris Lattner | 80a3e94 | 2005-07-29 00:33:32 +0000 | [diff] [blame] | 5302 | // Now that the custom expander is done, expand the result, which is still |
| 5303 | // VT. |
Chris Lattner | 07dffd6 | 2005-08-26 00:14:16 +0000 | [diff] [blame] | 5304 | if (Op.Val) { |
| 5305 | ExpandOp(Op, Lo, Hi); |
| 5306 | break; |
| 5307 | } |
Chris Lattner | 80a3e94 | 2005-07-29 00:33:32 +0000 | [diff] [blame] | 5308 | } |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 5309 | |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5310 | RTLIB::Libcall LC; |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 5311 | if (Node->getOperand(0).getValueType() == MVT::f32) |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5312 | LC = RTLIB::FPTOSINT_F32_I64; |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 5313 | else |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5314 | LC = RTLIB::FPTOSINT_F64_I64; |
| 5315 | Lo = ExpandLibCall(TLI.getLibcallName(LC), Node, |
| 5316 | false/*sign irrelevant*/, Hi); |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 5317 | break; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5318 | } |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 5319 | |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5320 | case ISD::FP_TO_UINT: { |
Chris Lattner | 80a3e94 | 2005-07-29 00:33:32 +0000 | [diff] [blame] | 5321 | if (TLI.getOperationAction(ISD::FP_TO_UINT, VT) == TargetLowering::Custom) { |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5322 | SDOperand Op; |
| 5323 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 5324 | case Expand: assert(0 && "cannot expand FP!"); |
| 5325 | case Legal: Op = LegalizeOp(Node->getOperand(0)); break; |
| 5326 | case Promote: Op = PromoteOp (Node->getOperand(0)); break; |
| 5327 | } |
| 5328 | |
| 5329 | Op = TLI.LowerOperation(DAG.getNode(ISD::FP_TO_UINT, VT, Op), DAG); |
| 5330 | |
| 5331 | // Now that the custom expander is done, expand the result. |
Chris Lattner | 07dffd6 | 2005-08-26 00:14:16 +0000 | [diff] [blame] | 5332 | if (Op.Val) { |
| 5333 | ExpandOp(Op, Lo, Hi); |
| 5334 | break; |
| 5335 | } |
Chris Lattner | 80a3e94 | 2005-07-29 00:33:32 +0000 | [diff] [blame] | 5336 | } |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 5337 | |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5338 | RTLIB::Libcall LC; |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 5339 | if (Node->getOperand(0).getValueType() == MVT::f32) |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5340 | LC = RTLIB::FPTOUINT_F32_I64; |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 5341 | else |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5342 | LC = RTLIB::FPTOUINT_F64_I64; |
| 5343 | Lo = ExpandLibCall(TLI.getLibcallName(LC), Node, |
| 5344 | false/*sign irrelevant*/, Hi); |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 5345 | break; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5346 | } |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 5347 | |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 5348 | case ISD::SHL: { |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 5349 | // If the target wants custom lowering, do so. |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 5350 | SDOperand ShiftAmt = LegalizeOp(Node->getOperand(1)); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 5351 | if (TLI.getOperationAction(ISD::SHL, VT) == TargetLowering::Custom) { |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5352 | SDOperand Op = DAG.getNode(ISD::SHL, VT, Node->getOperand(0), ShiftAmt); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 5353 | Op = TLI.LowerOperation(Op, DAG); |
| 5354 | if (Op.Val) { |
| 5355 | // Now that the custom expander is done, expand the result, which is |
| 5356 | // still VT. |
| 5357 | ExpandOp(Op, Lo, Hi); |
| 5358 | break; |
| 5359 | } |
| 5360 | } |
| 5361 | |
Chris Lattner | 79980b0 | 2006-09-13 03:50:39 +0000 | [diff] [blame] | 5362 | // If ADDC/ADDE are supported and if the shift amount is a constant 1, emit |
| 5363 | // this X << 1 as X+X. |
| 5364 | if (ConstantSDNode *ShAmt = dyn_cast<ConstantSDNode>(ShiftAmt)) { |
| 5365 | if (ShAmt->getValue() == 1 && TLI.isOperationLegal(ISD::ADDC, NVT) && |
| 5366 | TLI.isOperationLegal(ISD::ADDE, NVT)) { |
| 5367 | SDOperand LoOps[2], HiOps[3]; |
| 5368 | ExpandOp(Node->getOperand(0), LoOps[0], HiOps[0]); |
| 5369 | SDVTList VTList = DAG.getVTList(LoOps[0].getValueType(), MVT::Flag); |
| 5370 | LoOps[1] = LoOps[0]; |
| 5371 | Lo = DAG.getNode(ISD::ADDC, VTList, LoOps, 2); |
| 5372 | |
| 5373 | HiOps[1] = HiOps[0]; |
| 5374 | HiOps[2] = Lo.getValue(1); |
| 5375 | Hi = DAG.getNode(ISD::ADDE, VTList, HiOps, 3); |
| 5376 | break; |
| 5377 | } |
| 5378 | } |
| 5379 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5380 | // If we can emit an efficient shift operation, do so now. |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 5381 | if (ExpandShift(ISD::SHL, Node->getOperand(0), ShiftAmt, Lo, Hi)) |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5382 | break; |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 5383 | |
| 5384 | // If this target supports SHL_PARTS, use it. |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 5385 | TargetLowering::LegalizeAction Action = |
| 5386 | TLI.getOperationAction(ISD::SHL_PARTS, NVT); |
| 5387 | if ((Action == TargetLowering::Legal && TLI.isTypeLegal(NVT)) || |
| 5388 | Action == TargetLowering::Custom) { |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 5389 | ExpandShiftParts(ISD::SHL_PARTS, Node->getOperand(0), ShiftAmt, Lo, Hi); |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 5390 | break; |
| 5391 | } |
| 5392 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5393 | // Otherwise, emit a libcall. |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5394 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::SHL_I64), Node, |
| 5395 | false/*left shift=unsigned*/, Hi); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5396 | break; |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 5397 | } |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5398 | |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 5399 | case ISD::SRA: { |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 5400 | // If the target wants custom lowering, do so. |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 5401 | SDOperand ShiftAmt = LegalizeOp(Node->getOperand(1)); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 5402 | if (TLI.getOperationAction(ISD::SRA, VT) == TargetLowering::Custom) { |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5403 | SDOperand Op = DAG.getNode(ISD::SRA, VT, Node->getOperand(0), ShiftAmt); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 5404 | Op = TLI.LowerOperation(Op, DAG); |
| 5405 | if (Op.Val) { |
| 5406 | // Now that the custom expander is done, expand the result, which is |
| 5407 | // still VT. |
| 5408 | ExpandOp(Op, Lo, Hi); |
| 5409 | break; |
| 5410 | } |
| 5411 | } |
| 5412 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5413 | // If we can emit an efficient shift operation, do so now. |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 5414 | if (ExpandShift(ISD::SRA, Node->getOperand(0), ShiftAmt, Lo, Hi)) |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5415 | break; |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 5416 | |
| 5417 | // If this target supports SRA_PARTS, use it. |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 5418 | TargetLowering::LegalizeAction Action = |
| 5419 | TLI.getOperationAction(ISD::SRA_PARTS, NVT); |
| 5420 | if ((Action == TargetLowering::Legal && TLI.isTypeLegal(NVT)) || |
| 5421 | Action == TargetLowering::Custom) { |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 5422 | ExpandShiftParts(ISD::SRA_PARTS, Node->getOperand(0), ShiftAmt, Lo, Hi); |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 5423 | break; |
| 5424 | } |
| 5425 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5426 | // Otherwise, emit a libcall. |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5427 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::SRA_I64), Node, |
| 5428 | true/*ashr is signed*/, Hi); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5429 | break; |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 5430 | } |
| 5431 | |
| 5432 | case ISD::SRL: { |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 5433 | // If the target wants custom lowering, do so. |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 5434 | SDOperand ShiftAmt = LegalizeOp(Node->getOperand(1)); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 5435 | if (TLI.getOperationAction(ISD::SRL, VT) == TargetLowering::Custom) { |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5436 | SDOperand Op = DAG.getNode(ISD::SRL, VT, Node->getOperand(0), ShiftAmt); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 5437 | Op = TLI.LowerOperation(Op, DAG); |
| 5438 | if (Op.Val) { |
| 5439 | // Now that the custom expander is done, expand the result, which is |
| 5440 | // still VT. |
| 5441 | ExpandOp(Op, Lo, Hi); |
| 5442 | break; |
| 5443 | } |
| 5444 | } |
| 5445 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5446 | // If we can emit an efficient shift operation, do so now. |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 5447 | if (ExpandShift(ISD::SRL, Node->getOperand(0), ShiftAmt, Lo, Hi)) |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5448 | break; |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 5449 | |
| 5450 | // If this target supports SRL_PARTS, use it. |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 5451 | TargetLowering::LegalizeAction Action = |
| 5452 | TLI.getOperationAction(ISD::SRL_PARTS, NVT); |
| 5453 | if ((Action == TargetLowering::Legal && TLI.isTypeLegal(NVT)) || |
| 5454 | Action == TargetLowering::Custom) { |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 5455 | ExpandShiftParts(ISD::SRL_PARTS, Node->getOperand(0), ShiftAmt, Lo, Hi); |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 5456 | break; |
| 5457 | } |
| 5458 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5459 | // Otherwise, emit a libcall. |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5460 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::SRL_I64), Node, |
| 5461 | false/*lshr is unsigned*/, Hi); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5462 | break; |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 5463 | } |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5464 | |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 5465 | case ISD::ADD: |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5466 | case ISD::SUB: { |
| 5467 | // If the target wants to custom expand this, let them. |
| 5468 | if (TLI.getOperationAction(Node->getOpcode(), VT) == |
| 5469 | TargetLowering::Custom) { |
| 5470 | Op = TLI.LowerOperation(Op, DAG); |
| 5471 | if (Op.Val) { |
| 5472 | ExpandOp(Op, Lo, Hi); |
| 5473 | break; |
| 5474 | } |
| 5475 | } |
| 5476 | |
| 5477 | // Expand the subcomponents. |
| 5478 | SDOperand LHSL, LHSH, RHSL, RHSH; |
| 5479 | ExpandOp(Node->getOperand(0), LHSL, LHSH); |
| 5480 | ExpandOp(Node->getOperand(1), RHSL, RHSH); |
Chris Lattner | 79980b0 | 2006-09-13 03:50:39 +0000 | [diff] [blame] | 5481 | SDVTList VTList = DAG.getVTList(LHSL.getValueType(), MVT::Flag); |
| 5482 | SDOperand LoOps[2], HiOps[3]; |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 5483 | LoOps[0] = LHSL; |
| 5484 | LoOps[1] = RHSL; |
| 5485 | HiOps[0] = LHSH; |
| 5486 | HiOps[1] = RHSH; |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 5487 | if (Node->getOpcode() == ISD::ADD) { |
Chris Lattner | 79980b0 | 2006-09-13 03:50:39 +0000 | [diff] [blame] | 5488 | Lo = DAG.getNode(ISD::ADDC, VTList, LoOps, 2); |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 5489 | HiOps[2] = Lo.getValue(1); |
Chris Lattner | 79980b0 | 2006-09-13 03:50:39 +0000 | [diff] [blame] | 5490 | Hi = DAG.getNode(ISD::ADDE, VTList, HiOps, 3); |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 5491 | } else { |
Chris Lattner | 79980b0 | 2006-09-13 03:50:39 +0000 | [diff] [blame] | 5492 | Lo = DAG.getNode(ISD::SUBC, VTList, LoOps, 2); |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 5493 | HiOps[2] = Lo.getValue(1); |
Chris Lattner | 79980b0 | 2006-09-13 03:50:39 +0000 | [diff] [blame] | 5494 | Hi = DAG.getNode(ISD::SUBE, VTList, HiOps, 3); |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 5495 | } |
Chris Lattner | 84f6788 | 2005-01-20 18:52:28 +0000 | [diff] [blame] | 5496 | break; |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5497 | } |
Chris Lattner | b429f73 | 2007-05-17 18:15:41 +0000 | [diff] [blame] | 5498 | |
| 5499 | case ISD::ADDC: |
| 5500 | case ISD::SUBC: { |
| 5501 | // Expand the subcomponents. |
| 5502 | SDOperand LHSL, LHSH, RHSL, RHSH; |
| 5503 | ExpandOp(Node->getOperand(0), LHSL, LHSH); |
| 5504 | ExpandOp(Node->getOperand(1), RHSL, RHSH); |
| 5505 | SDVTList VTList = DAG.getVTList(LHSL.getValueType(), MVT::Flag); |
| 5506 | SDOperand LoOps[2] = { LHSL, RHSL }; |
| 5507 | SDOperand HiOps[3] = { LHSH, RHSH }; |
| 5508 | |
| 5509 | if (Node->getOpcode() == ISD::ADDC) { |
| 5510 | Lo = DAG.getNode(ISD::ADDC, VTList, LoOps, 2); |
| 5511 | HiOps[2] = Lo.getValue(1); |
| 5512 | Hi = DAG.getNode(ISD::ADDE, VTList, HiOps, 3); |
| 5513 | } else { |
| 5514 | Lo = DAG.getNode(ISD::SUBC, VTList, LoOps, 2); |
| 5515 | HiOps[2] = Lo.getValue(1); |
| 5516 | Hi = DAG.getNode(ISD::SUBE, VTList, HiOps, 3); |
| 5517 | } |
| 5518 | // Remember that we legalized the flag. |
| 5519 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Hi.getValue(1))); |
| 5520 | break; |
| 5521 | } |
| 5522 | case ISD::ADDE: |
| 5523 | case ISD::SUBE: { |
| 5524 | // Expand the subcomponents. |
| 5525 | SDOperand LHSL, LHSH, RHSL, RHSH; |
| 5526 | ExpandOp(Node->getOperand(0), LHSL, LHSH); |
| 5527 | ExpandOp(Node->getOperand(1), RHSL, RHSH); |
| 5528 | SDVTList VTList = DAG.getVTList(LHSL.getValueType(), MVT::Flag); |
| 5529 | SDOperand LoOps[3] = { LHSL, RHSL, Node->getOperand(2) }; |
| 5530 | SDOperand HiOps[3] = { LHSH, RHSH }; |
| 5531 | |
| 5532 | Lo = DAG.getNode(Node->getOpcode(), VTList, LoOps, 3); |
| 5533 | HiOps[2] = Lo.getValue(1); |
| 5534 | Hi = DAG.getNode(Node->getOpcode(), VTList, HiOps, 3); |
| 5535 | |
| 5536 | // Remember that we legalized the flag. |
| 5537 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Hi.getValue(1))); |
| 5538 | break; |
| 5539 | } |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 5540 | case ISD::MUL: { |
Chris Lattner | 7d7bffe | 2006-09-16 00:09:24 +0000 | [diff] [blame] | 5541 | // If the target wants to custom expand this, let them. |
| 5542 | if (TLI.getOperationAction(ISD::MUL, VT) == TargetLowering::Custom) { |
Chris Lattner | 8829dc8 | 2006-09-16 05:08:34 +0000 | [diff] [blame] | 5543 | SDOperand New = TLI.LowerOperation(Op, DAG); |
| 5544 | if (New.Val) { |
| 5545 | ExpandOp(New, Lo, Hi); |
Chris Lattner | 7d7bffe | 2006-09-16 00:09:24 +0000 | [diff] [blame] | 5546 | break; |
| 5547 | } |
| 5548 | } |
| 5549 | |
Evan Cheng | 3f4fd0f | 2006-09-01 18:17:58 +0000 | [diff] [blame] | 5550 | bool HasMULHS = TLI.isOperationLegal(ISD::MULHS, NVT); |
| 5551 | bool HasMULHU = TLI.isOperationLegal(ISD::MULHU, NVT); |
Evan Cheng | 3f4fd0f | 2006-09-01 18:17:58 +0000 | [diff] [blame] | 5552 | if (HasMULHS || HasMULHU) { |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 5553 | SDOperand LL, LH, RL, RH; |
| 5554 | ExpandOp(Node->getOperand(0), LL, LH); |
| 5555 | ExpandOp(Node->getOperand(1), RL, RH); |
Nate Begeman | 56eb868 | 2005-08-30 02:44:00 +0000 | [diff] [blame] | 5556 | unsigned SH = MVT::getSizeInBits(RH.getValueType())-1; |
Nate Begeman | 2cbba89 | 2006-12-11 02:23:46 +0000 | [diff] [blame] | 5557 | // FIXME: Move this to the dag combiner. |
Nate Begeman | 56eb868 | 2005-08-30 02:44:00 +0000 | [diff] [blame] | 5558 | // MULHS implicitly sign extends its inputs. Check to see if ExpandOp |
| 5559 | // extended the sign bit of the low half through the upper half, and if so |
| 5560 | // emit a MULHS instead of the alternate sequence that is valid for any |
| 5561 | // i64 x i64 multiply. |
Evan Cheng | 3f4fd0f | 2006-09-01 18:17:58 +0000 | [diff] [blame] | 5562 | if (HasMULHS && |
Nate Begeman | 56eb868 | 2005-08-30 02:44:00 +0000 | [diff] [blame] | 5563 | // is RH an extension of the sign bit of RL? |
| 5564 | RH.getOpcode() == ISD::SRA && RH.getOperand(0) == RL && |
| 5565 | RH.getOperand(1).getOpcode() == ISD::Constant && |
| 5566 | cast<ConstantSDNode>(RH.getOperand(1))->getValue() == SH && |
| 5567 | // is LH an extension of the sign bit of LL? |
| 5568 | LH.getOpcode() == ISD::SRA && LH.getOperand(0) == LL && |
| 5569 | LH.getOperand(1).getOpcode() == ISD::Constant && |
| 5570 | cast<ConstantSDNode>(LH.getOperand(1))->getValue() == SH) { |
Chris Lattner | a89654b | 2006-09-16 00:21:44 +0000 | [diff] [blame] | 5571 | // Low part: |
| 5572 | Lo = DAG.getNode(ISD::MUL, NVT, LL, RL); |
| 5573 | // High part: |
Nate Begeman | 56eb868 | 2005-08-30 02:44:00 +0000 | [diff] [blame] | 5574 | Hi = DAG.getNode(ISD::MULHS, NVT, LL, RL); |
Chris Lattner | a89654b | 2006-09-16 00:21:44 +0000 | [diff] [blame] | 5575 | break; |
Evan Cheng | 3f4fd0f | 2006-09-01 18:17:58 +0000 | [diff] [blame] | 5576 | } else if (HasMULHU) { |
Chris Lattner | a89654b | 2006-09-16 00:21:44 +0000 | [diff] [blame] | 5577 | // Low part: |
| 5578 | Lo = DAG.getNode(ISD::MUL, NVT, LL, RL); |
| 5579 | |
| 5580 | // High part: |
Nate Begeman | 56eb868 | 2005-08-30 02:44:00 +0000 | [diff] [blame] | 5581 | Hi = DAG.getNode(ISD::MULHU, NVT, LL, RL); |
| 5582 | RH = DAG.getNode(ISD::MUL, NVT, LL, RH); |
| 5583 | LH = DAG.getNode(ISD::MUL, NVT, LH, RL); |
| 5584 | Hi = DAG.getNode(ISD::ADD, NVT, Hi, RH); |
| 5585 | Hi = DAG.getNode(ISD::ADD, NVT, Hi, LH); |
Chris Lattner | a89654b | 2006-09-16 00:21:44 +0000 | [diff] [blame] | 5586 | break; |
Nate Begeman | 56eb868 | 2005-08-30 02:44:00 +0000 | [diff] [blame] | 5587 | } |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 5588 | } |
Evan Cheng | 3f4fd0f | 2006-09-01 18:17:58 +0000 | [diff] [blame] | 5589 | |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5590 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::MUL_I64), Node, |
| 5591 | false/*sign irrelevant*/, Hi); |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 5592 | break; |
| 5593 | } |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5594 | case ISD::SDIV: |
| 5595 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::SDIV_I64), Node, true, Hi); |
| 5596 | break; |
| 5597 | case ISD::UDIV: |
| 5598 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::UDIV_I64), Node, true, Hi); |
| 5599 | break; |
| 5600 | case ISD::SREM: |
| 5601 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::SREM_I64), Node, true, Hi); |
| 5602 | break; |
| 5603 | case ISD::UREM: |
| 5604 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::UREM_I64), Node, true, Hi); |
| 5605 | break; |
Evan Cheng | 5c9ce18 | 2006-12-12 21:51:17 +0000 | [diff] [blame] | 5606 | |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 5607 | case ISD::FADD: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5608 | Lo = ExpandLibCall(TLI.getLibcallName((VT == MVT::f32) |
| 5609 | ? RTLIB::ADD_F32 : RTLIB::ADD_F64), |
| 5610 | Node, false, Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 5611 | break; |
| 5612 | case ISD::FSUB: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5613 | Lo = ExpandLibCall(TLI.getLibcallName((VT == MVT::f32) |
| 5614 | ? RTLIB::SUB_F32 : RTLIB::SUB_F64), |
| 5615 | Node, false, Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 5616 | break; |
| 5617 | case ISD::FMUL: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5618 | Lo = ExpandLibCall(TLI.getLibcallName((VT == MVT::f32) |
| 5619 | ? RTLIB::MUL_F32 : RTLIB::MUL_F64), |
| 5620 | Node, false, Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 5621 | break; |
| 5622 | case ISD::FDIV: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5623 | Lo = ExpandLibCall(TLI.getLibcallName((VT == MVT::f32) |
| 5624 | ? RTLIB::DIV_F32 : RTLIB::DIV_F64), |
| 5625 | Node, false, Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 5626 | break; |
| 5627 | case ISD::FP_EXTEND: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5628 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::FPEXT_F32_F64), Node, true,Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 5629 | break; |
| 5630 | case ISD::FP_ROUND: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5631 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::FPROUND_F64_F32),Node,true,Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 5632 | break; |
Lauro Ramos Venancio | c90f089 | 2007-08-15 22:13:27 +0000 | [diff] [blame] | 5633 | case ISD::FPOWI: |
| 5634 | Lo = ExpandLibCall(TLI.getLibcallName((VT == MVT::f32) |
| 5635 | ? RTLIB::POWI_F32 : RTLIB::POWI_F64), |
| 5636 | Node, false, Hi); |
| 5637 | break; |
Evan Cheng | 98ff3b9 | 2006-12-13 02:38:13 +0000 | [diff] [blame] | 5638 | case ISD::FSQRT: |
| 5639 | case ISD::FSIN: |
| 5640 | case ISD::FCOS: { |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5641 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
Evan Cheng | 98ff3b9 | 2006-12-13 02:38:13 +0000 | [diff] [blame] | 5642 | switch(Node->getOpcode()) { |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5643 | case ISD::FSQRT: |
| 5644 | LC = (VT == MVT::f32) ? RTLIB::SQRT_F32 : RTLIB::SQRT_F64; |
| 5645 | break; |
| 5646 | case ISD::FSIN: |
| 5647 | LC = (VT == MVT::f32) ? RTLIB::SIN_F32 : RTLIB::SIN_F64; |
| 5648 | break; |
| 5649 | case ISD::FCOS: |
| 5650 | LC = (VT == MVT::f32) ? RTLIB::COS_F32 : RTLIB::COS_F64; |
| 5651 | break; |
Evan Cheng | 98ff3b9 | 2006-12-13 02:38:13 +0000 | [diff] [blame] | 5652 | default: assert(0 && "Unreachable!"); |
| 5653 | } |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5654 | Lo = ExpandLibCall(TLI.getLibcallName(LC), Node, false, Hi); |
Evan Cheng | 98ff3b9 | 2006-12-13 02:38:13 +0000 | [diff] [blame] | 5655 | break; |
| 5656 | } |
Evan Cheng | 966bf24 | 2006-12-16 00:52:40 +0000 | [diff] [blame] | 5657 | case ISD::FABS: { |
| 5658 | SDOperand Mask = (VT == MVT::f64) |
| 5659 | ? DAG.getConstantFP(BitsToDouble(~(1ULL << 63)), VT) |
| 5660 | : DAG.getConstantFP(BitsToFloat(~(1U << 31)), VT); |
| 5661 | Mask = DAG.getNode(ISD::BIT_CONVERT, NVT, Mask); |
| 5662 | Lo = DAG.getNode(ISD::BIT_CONVERT, NVT, Node->getOperand(0)); |
| 5663 | Lo = DAG.getNode(ISD::AND, NVT, Lo, Mask); |
| 5664 | if (getTypeAction(NVT) == Expand) |
| 5665 | ExpandOp(Lo, Lo, Hi); |
| 5666 | break; |
| 5667 | } |
| 5668 | case ISD::FNEG: { |
| 5669 | SDOperand Mask = (VT == MVT::f64) |
| 5670 | ? DAG.getConstantFP(BitsToDouble(1ULL << 63), VT) |
| 5671 | : DAG.getConstantFP(BitsToFloat(1U << 31), VT); |
| 5672 | Mask = DAG.getNode(ISD::BIT_CONVERT, NVT, Mask); |
| 5673 | Lo = DAG.getNode(ISD::BIT_CONVERT, NVT, Node->getOperand(0)); |
| 5674 | Lo = DAG.getNode(ISD::XOR, NVT, Lo, Mask); |
| 5675 | if (getTypeAction(NVT) == Expand) |
| 5676 | ExpandOp(Lo, Lo, Hi); |
| 5677 | break; |
| 5678 | } |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 5679 | case ISD::FCOPYSIGN: { |
| 5680 | Lo = ExpandFCOPYSIGNToBitwiseOps(Node, NVT, DAG, TLI); |
| 5681 | if (getTypeAction(NVT) == Expand) |
| 5682 | ExpandOp(Lo, Lo, Hi); |
| 5683 | break; |
| 5684 | } |
Evan Cheng | 7df28dc | 2006-12-19 01:44:04 +0000 | [diff] [blame] | 5685 | case ISD::SINT_TO_FP: |
| 5686 | case ISD::UINT_TO_FP: { |
| 5687 | bool isSigned = Node->getOpcode() == ISD::SINT_TO_FP; |
| 5688 | MVT::ValueType SrcVT = Node->getOperand(0).getValueType(); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5689 | RTLIB::Libcall LC; |
Evan Cheng | 7df28dc | 2006-12-19 01:44:04 +0000 | [diff] [blame] | 5690 | if (Node->getOperand(0).getValueType() == MVT::i64) { |
| 5691 | if (VT == MVT::f32) |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5692 | LC = isSigned ? RTLIB::SINTTOFP_I64_F32 : RTLIB::UINTTOFP_I64_F32; |
Evan Cheng | 7df28dc | 2006-12-19 01:44:04 +0000 | [diff] [blame] | 5693 | else |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5694 | LC = isSigned ? RTLIB::SINTTOFP_I64_F64 : RTLIB::UINTTOFP_I64_F64; |
Evan Cheng | 7df28dc | 2006-12-19 01:44:04 +0000 | [diff] [blame] | 5695 | } else { |
| 5696 | if (VT == MVT::f32) |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5697 | LC = isSigned ? RTLIB::SINTTOFP_I32_F32 : RTLIB::UINTTOFP_I32_F32; |
Evan Cheng | 7df28dc | 2006-12-19 01:44:04 +0000 | [diff] [blame] | 5698 | else |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5699 | LC = isSigned ? RTLIB::SINTTOFP_I32_F64 : RTLIB::UINTTOFP_I32_F64; |
Evan Cheng | 7df28dc | 2006-12-19 01:44:04 +0000 | [diff] [blame] | 5700 | } |
| 5701 | |
| 5702 | // Promote the operand if needed. |
| 5703 | if (getTypeAction(SrcVT) == Promote) { |
| 5704 | SDOperand Tmp = PromoteOp(Node->getOperand(0)); |
| 5705 | Tmp = isSigned |
| 5706 | ? DAG.getNode(ISD::SIGN_EXTEND_INREG, Tmp.getValueType(), Tmp, |
| 5707 | DAG.getValueType(SrcVT)) |
| 5708 | : DAG.getZeroExtendInReg(Tmp, SrcVT); |
| 5709 | Node = DAG.UpdateNodeOperands(Op, Tmp).Val; |
| 5710 | } |
Evan Cheng | 4c6cfad | 2007-04-27 07:33:31 +0000 | [diff] [blame] | 5711 | |
| 5712 | const char *LibCall = TLI.getLibcallName(LC); |
| 5713 | if (LibCall) |
| 5714 | Lo = ExpandLibCall(TLI.getLibcallName(LC), Node, isSigned, Hi); |
| 5715 | else { |
| 5716 | Lo = ExpandIntToFP(Node->getOpcode() == ISD::SINT_TO_FP, VT, |
| 5717 | Node->getOperand(0)); |
| 5718 | if (getTypeAction(Lo.getValueType()) == Expand) |
| 5719 | ExpandOp(Lo, Lo, Hi); |
| 5720 | } |
Evan Cheng | 7df28dc | 2006-12-19 01:44:04 +0000 | [diff] [blame] | 5721 | break; |
| 5722 | } |
Evan Cheng | 98ff3b9 | 2006-12-13 02:38:13 +0000 | [diff] [blame] | 5723 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5724 | |
Chris Lattner | 8339736 | 2005-12-21 18:02:52 +0000 | [diff] [blame] | 5725 | // Make sure the resultant values have been legalized themselves, unless this |
| 5726 | // is a type that requires multi-step expansion. |
| 5727 | if (getTypeAction(NVT) != Expand && NVT != MVT::isVoid) { |
| 5728 | Lo = LegalizeOp(Lo); |
Evan Cheng | 13acce3 | 2006-12-11 19:27:14 +0000 | [diff] [blame] | 5729 | if (Hi.Val) |
| 5730 | // Don't legalize the high part if it is expanded to a single node. |
| 5731 | Hi = LegalizeOp(Hi); |
Chris Lattner | 8339736 | 2005-12-21 18:02:52 +0000 | [diff] [blame] | 5732 | } |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 5733 | |
| 5734 | // Remember in a map if the values will be reused later. |
Chris Lattner | 40030bf | 2007-02-04 01:17:38 +0000 | [diff] [blame] | 5735 | 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] | 5736 | assert(isNew && "Value already expanded?!?"); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5737 | } |
| 5738 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5739 | /// SplitVectorOp - Given an operand of vector type, break it down into |
| 5740 | /// two smaller values, still of vector type. |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 5741 | void SelectionDAGLegalize::SplitVectorOp(SDOperand Op, SDOperand &Lo, |
| 5742 | SDOperand &Hi) { |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5743 | assert(MVT::isVector(Op.getValueType()) && "Cannot split non-vector type!"); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 5744 | SDNode *Node = Op.Val; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5745 | unsigned NumElements = MVT::getVectorNumElements(Node->getValueType(0)); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 5746 | assert(NumElements > 1 && "Cannot split a single element vector!"); |
| 5747 | unsigned NewNumElts = NumElements/2; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5748 | MVT::ValueType NewEltVT = MVT::getVectorElementType(Node->getValueType(0)); |
| 5749 | MVT::ValueType NewVT = MVT::getVectorType(NewEltVT, NewNumElts); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 5750 | |
| 5751 | // See if we already split it. |
| 5752 | std::map<SDOperand, std::pair<SDOperand, SDOperand> >::iterator I |
| 5753 | = SplitNodes.find(Op); |
| 5754 | if (I != SplitNodes.end()) { |
| 5755 | Lo = I->second.first; |
| 5756 | Hi = I->second.second; |
| 5757 | return; |
| 5758 | } |
| 5759 | |
| 5760 | switch (Node->getOpcode()) { |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 5761 | default: |
| 5762 | #ifndef NDEBUG |
Dan Gohman | 3983358 | 2007-06-04 16:17:33 +0000 | [diff] [blame] | 5763 | Node->dump(&DAG); |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 5764 | #endif |
| 5765 | assert(0 && "Unhandled operation in SplitVectorOp!"); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5766 | case ISD::BUILD_PAIR: |
| 5767 | Lo = Node->getOperand(0); |
| 5768 | Hi = Node->getOperand(1); |
| 5769 | break; |
| 5770 | case ISD::BUILD_VECTOR: { |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 5771 | SmallVector<SDOperand, 8> LoOps(Node->op_begin(), |
| 5772 | Node->op_begin()+NewNumElts); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5773 | Lo = DAG.getNode(ISD::BUILD_VECTOR, NewVT, &LoOps[0], LoOps.size()); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 5774 | |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 5775 | SmallVector<SDOperand, 8> HiOps(Node->op_begin()+NewNumElts, |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5776 | Node->op_end()); |
| 5777 | Hi = DAG.getNode(ISD::BUILD_VECTOR, NewVT, &HiOps[0], HiOps.size()); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 5778 | break; |
| 5779 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5780 | case ISD::CONCAT_VECTORS: { |
| 5781 | unsigned NewNumSubvectors = Node->getNumOperands() / 2; |
| 5782 | if (NewNumSubvectors == 1) { |
| 5783 | Lo = Node->getOperand(0); |
| 5784 | Hi = Node->getOperand(1); |
| 5785 | } else { |
| 5786 | SmallVector<SDOperand, 8> LoOps(Node->op_begin(), |
| 5787 | Node->op_begin()+NewNumSubvectors); |
| 5788 | Lo = DAG.getNode(ISD::CONCAT_VECTORS, NewVT, &LoOps[0], LoOps.size()); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 5789 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5790 | SmallVector<SDOperand, 8> HiOps(Node->op_begin()+NewNumSubvectors, |
| 5791 | Node->op_end()); |
| 5792 | Hi = DAG.getNode(ISD::CONCAT_VECTORS, NewVT, &HiOps[0], HiOps.size()); |
| 5793 | } |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 5794 | break; |
| 5795 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5796 | case ISD::ADD: |
| 5797 | case ISD::SUB: |
| 5798 | case ISD::MUL: |
| 5799 | case ISD::FADD: |
| 5800 | case ISD::FSUB: |
| 5801 | case ISD::FMUL: |
| 5802 | case ISD::SDIV: |
| 5803 | case ISD::UDIV: |
| 5804 | case ISD::FDIV: |
| 5805 | case ISD::AND: |
| 5806 | case ISD::OR: |
| 5807 | case ISD::XOR: { |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 5808 | SDOperand LL, LH, RL, RH; |
| 5809 | SplitVectorOp(Node->getOperand(0), LL, LH); |
| 5810 | SplitVectorOp(Node->getOperand(1), RL, RH); |
| 5811 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5812 | Lo = DAG.getNode(Node->getOpcode(), NewVT, LL, RL); |
| 5813 | Hi = DAG.getNode(Node->getOpcode(), NewVT, LH, RH); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 5814 | break; |
| 5815 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5816 | case ISD::LOAD: { |
| 5817 | LoadSDNode *LD = cast<LoadSDNode>(Node); |
| 5818 | SDOperand Ch = LD->getChain(); |
| 5819 | SDOperand Ptr = LD->getBasePtr(); |
| 5820 | const Value *SV = LD->getSrcValue(); |
| 5821 | int SVOffset = LD->getSrcValueOffset(); |
| 5822 | unsigned Alignment = LD->getAlignment(); |
| 5823 | bool isVolatile = LD->isVolatile(); |
| 5824 | |
| 5825 | Lo = DAG.getLoad(NewVT, Ch, Ptr, SV, SVOffset, isVolatile, Alignment); |
| 5826 | unsigned IncrementSize = NewNumElts * MVT::getSizeInBits(NewEltVT)/8; |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 5827 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
| 5828 | getIntPtrConstant(IncrementSize)); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5829 | SVOffset += IncrementSize; |
| 5830 | if (Alignment > IncrementSize) |
| 5831 | Alignment = IncrementSize; |
| 5832 | Hi = DAG.getLoad(NewVT, Ch, Ptr, SV, SVOffset, isVolatile, Alignment); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 5833 | |
| 5834 | // Build a factor node to remember that this load is independent of the |
| 5835 | // other one. |
| 5836 | SDOperand TF = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1), |
| 5837 | Hi.getValue(1)); |
| 5838 | |
| 5839 | // Remember that we legalized the chain. |
| 5840 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(TF)); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 5841 | break; |
| 5842 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5843 | case ISD::BIT_CONVERT: { |
Chris Lattner | 7692eb4 | 2006-03-23 21:16:34 +0000 | [diff] [blame] | 5844 | // We know the result is a vector. The input may be either a vector or a |
| 5845 | // scalar value. |
Dan Gohman | 10a7aa6 | 2007-06-29 00:09:08 +0000 | [diff] [blame] | 5846 | SDOperand InOp = Node->getOperand(0); |
| 5847 | if (!MVT::isVector(InOp.getValueType()) || |
| 5848 | MVT::getVectorNumElements(InOp.getValueType()) == 1) { |
| 5849 | // The input is a scalar or single-element vector. |
| 5850 | // Lower to a store/load so that it can be split. |
| 5851 | // FIXME: this could be improved probably. |
| 5852 | SDOperand Ptr = CreateStackTemporary(InOp.getValueType()); |
Chris Lattner | 7692eb4 | 2006-03-23 21:16:34 +0000 | [diff] [blame] | 5853 | |
Evan Cheng | 786225a | 2006-10-05 23:01:46 +0000 | [diff] [blame] | 5854 | SDOperand St = DAG.getStore(DAG.getEntryNode(), |
Dan Gohman | 10a7aa6 | 2007-06-29 00:09:08 +0000 | [diff] [blame] | 5855 | InOp, Ptr, NULL, 0); |
| 5856 | InOp = DAG.getLoad(Op.getValueType(), St, Ptr, NULL, 0); |
Chris Lattner | 7692eb4 | 2006-03-23 21:16:34 +0000 | [diff] [blame] | 5857 | } |
Dan Gohman | 10a7aa6 | 2007-06-29 00:09:08 +0000 | [diff] [blame] | 5858 | // Split the vector and convert each of the pieces now. |
| 5859 | SplitVectorOp(InOp, Lo, Hi); |
| 5860 | Lo = DAG.getNode(ISD::BIT_CONVERT, NewVT, Lo); |
| 5861 | Hi = DAG.getNode(ISD::BIT_CONVERT, NewVT, Hi); |
| 5862 | break; |
Chris Lattner | 7692eb4 | 2006-03-23 21:16:34 +0000 | [diff] [blame] | 5863 | } |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 5864 | } |
| 5865 | |
| 5866 | // Remember in a map if the values will be reused later. |
Chris Lattner | 40030bf | 2007-02-04 01:17:38 +0000 | [diff] [blame] | 5867 | bool isNew = |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 5868 | SplitNodes.insert(std::make_pair(Op, std::make_pair(Lo, Hi))).second; |
Dan Gohman | 10a7aa6 | 2007-06-29 00:09:08 +0000 | [diff] [blame] | 5869 | assert(isNew && "Value already split?!?"); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 5870 | } |
| 5871 | |
| 5872 | |
Dan Gohman | 89b20c0 | 2007-06-27 14:06:22 +0000 | [diff] [blame] | 5873 | /// ScalarizeVectorOp - Given an operand of single-element vector type |
| 5874 | /// (e.g. v1f32), convert it into the equivalent operation that returns a |
| 5875 | /// scalar (e.g. f32) value. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5876 | SDOperand SelectionDAGLegalize::ScalarizeVectorOp(SDOperand Op) { |
| 5877 | assert(MVT::isVector(Op.getValueType()) && |
| 5878 | "Bad ScalarizeVectorOp invocation!"); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 5879 | SDNode *Node = Op.Val; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5880 | MVT::ValueType NewVT = MVT::getVectorElementType(Op.getValueType()); |
| 5881 | assert(MVT::getVectorNumElements(Op.getValueType()) == 1); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 5882 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5883 | // See if we already scalarized it. |
| 5884 | std::map<SDOperand, SDOperand>::iterator I = ScalarizedNodes.find(Op); |
| 5885 | if (I != ScalarizedNodes.end()) return I->second; |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 5886 | |
| 5887 | SDOperand Result; |
| 5888 | switch (Node->getOpcode()) { |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 5889 | default: |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 5890 | #ifndef NDEBUG |
Dan Gohman | 3983358 | 2007-06-04 16:17:33 +0000 | [diff] [blame] | 5891 | Node->dump(&DAG); cerr << "\n"; |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 5892 | #endif |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5893 | assert(0 && "Unknown vector operation in ScalarizeVectorOp!"); |
| 5894 | case ISD::ADD: |
| 5895 | case ISD::FADD: |
| 5896 | case ISD::SUB: |
| 5897 | case ISD::FSUB: |
| 5898 | case ISD::MUL: |
| 5899 | case ISD::FMUL: |
| 5900 | case ISD::SDIV: |
| 5901 | case ISD::UDIV: |
| 5902 | case ISD::FDIV: |
| 5903 | case ISD::SREM: |
| 5904 | case ISD::UREM: |
| 5905 | case ISD::FREM: |
| 5906 | case ISD::AND: |
| 5907 | case ISD::OR: |
| 5908 | case ISD::XOR: |
| 5909 | Result = DAG.getNode(Node->getOpcode(), |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 5910 | NewVT, |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5911 | ScalarizeVectorOp(Node->getOperand(0)), |
| 5912 | ScalarizeVectorOp(Node->getOperand(1))); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 5913 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5914 | case ISD::FNEG: |
| 5915 | case ISD::FABS: |
| 5916 | case ISD::FSQRT: |
| 5917 | case ISD::FSIN: |
| 5918 | case ISD::FCOS: |
| 5919 | Result = DAG.getNode(Node->getOpcode(), |
| 5920 | NewVT, |
| 5921 | ScalarizeVectorOp(Node->getOperand(0))); |
| 5922 | break; |
| 5923 | case ISD::LOAD: { |
| 5924 | LoadSDNode *LD = cast<LoadSDNode>(Node); |
| 5925 | SDOperand Ch = LegalizeOp(LD->getChain()); // Legalize the chain. |
| 5926 | SDOperand Ptr = LegalizeOp(LD->getBasePtr()); // Legalize the pointer. |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 5927 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5928 | const Value *SV = LD->getSrcValue(); |
| 5929 | int SVOffset = LD->getSrcValueOffset(); |
| 5930 | Result = DAG.getLoad(NewVT, Ch, Ptr, SV, SVOffset, |
| 5931 | LD->isVolatile(), LD->getAlignment()); |
| 5932 | |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 5933 | // Remember that we legalized the chain. |
| 5934 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1))); |
| 5935 | break; |
| 5936 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5937 | case ISD::BUILD_VECTOR: |
| 5938 | Result = Node->getOperand(0); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 5939 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5940 | case ISD::INSERT_VECTOR_ELT: |
| 5941 | // Returning the inserted scalar element. |
| 5942 | Result = Node->getOperand(1); |
| 5943 | break; |
| 5944 | case ISD::CONCAT_VECTORS: |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 5945 | assert(Node->getOperand(0).getValueType() == NewVT && |
| 5946 | "Concat of non-legal vectors not yet supported!"); |
| 5947 | Result = Node->getOperand(0); |
| 5948 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5949 | case ISD::VECTOR_SHUFFLE: { |
| 5950 | // Figure out if the scalar is the LHS or RHS and return it. |
| 5951 | SDOperand EltNum = Node->getOperand(2).getOperand(0); |
| 5952 | if (cast<ConstantSDNode>(EltNum)->getValue()) |
| 5953 | Result = ScalarizeVectorOp(Node->getOperand(1)); |
| 5954 | else |
| 5955 | Result = ScalarizeVectorOp(Node->getOperand(0)); |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 5956 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5957 | } |
| 5958 | case ISD::EXTRACT_SUBVECTOR: |
| 5959 | Result = Node->getOperand(0); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 5960 | assert(Result.getValueType() == NewVT); |
| 5961 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5962 | case ISD::BIT_CONVERT: |
| 5963 | Result = DAG.getNode(ISD::BIT_CONVERT, NewVT, Op.getOperand(0)); |
Chris Lattner | 5b2316e | 2006-03-28 20:24:43 +0000 | [diff] [blame] | 5964 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5965 | case ISD::SELECT: |
Chris Lattner | b22e35a | 2006-04-08 22:22:57 +0000 | [diff] [blame] | 5966 | Result = DAG.getNode(ISD::SELECT, NewVT, Op.getOperand(0), |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5967 | ScalarizeVectorOp(Op.getOperand(1)), |
| 5968 | ScalarizeVectorOp(Op.getOperand(2))); |
Chris Lattner | b22e35a | 2006-04-08 22:22:57 +0000 | [diff] [blame] | 5969 | break; |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 5970 | } |
| 5971 | |
| 5972 | if (TLI.isTypeLegal(NewVT)) |
| 5973 | Result = LegalizeOp(Result); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5974 | bool isNew = ScalarizedNodes.insert(std::make_pair(Op, Result)).second; |
| 5975 | assert(isNew && "Value already scalarized?"); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 5976 | return Result; |
| 5977 | } |
| 5978 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5979 | |
| 5980 | // SelectionDAG::Legalize - This is the entry point for the file. |
| 5981 | // |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 5982 | void SelectionDAG::Legalize() { |
Chris Lattner | 5e46a19 | 2006-04-02 03:07:27 +0000 | [diff] [blame] | 5983 | if (ViewLegalizeDAGs) viewGraph(); |
| 5984 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5985 | /// run - This is the main entry point to this class. |
| 5986 | /// |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 5987 | SelectionDAGLegalize(*this).LegalizeDAG(); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5988 | } |
| 5989 | |