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" |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 26 | #include "llvm/Support/Alignment.h" |
Chris Lattner | 5e46a19 | 2006-04-02 03:07:27 +0000 | [diff] [blame] | 27 | #include "llvm/Support/CommandLine.h" |
Chris Lattner | a4f0b3a | 2006-08-27 12:54:02 +0000 | [diff] [blame] | 28 | #include "llvm/Support/Compiler.h" |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 29 | #include "llvm/Support/MathExtras.h" |
Chris Lattner | 7971514 | 2007-02-03 01:12:36 +0000 | [diff] [blame] | 30 | #include "llvm/ADT/DenseMap.h" |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 31 | #include "llvm/ADT/SmallVector.h" |
Chris Lattner | 00755df | 2007-02-04 00:27:56 +0000 | [diff] [blame] | 32 | #include "llvm/ADT/SmallPtrSet.h" |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 33 | #include <map> |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 34 | using namespace llvm; |
| 35 | |
Chris Lattner | 5e46a19 | 2006-04-02 03:07:27 +0000 | [diff] [blame] | 36 | #ifndef NDEBUG |
| 37 | static cl::opt<bool> |
| 38 | ViewLegalizeDAGs("view-legalize-dags", cl::Hidden, |
| 39 | cl::desc("Pop up a window to show dags before legalize")); |
| 40 | #else |
| 41 | static const bool ViewLegalizeDAGs = 0; |
| 42 | #endif |
| 43 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 44 | //===----------------------------------------------------------------------===// |
| 45 | /// SelectionDAGLegalize - This takes an arbitrary SelectionDAG as input and |
| 46 | /// hacks on it until the target machine can handle it. This involves |
| 47 | /// eliminating value sizes the machine cannot handle (promoting small sizes to |
| 48 | /// large sizes or splitting up large values into small values) as well as |
| 49 | /// eliminating operations the machine cannot handle. |
| 50 | /// |
| 51 | /// This code also does a small amount of optimization and recognition of idioms |
| 52 | /// as part of its processing. For example, if a target does not support a |
| 53 | /// 'setcc' instruction efficiently, but does support 'brcc' instruction, this |
| 54 | /// will attempt merge setcc and brc instructions into brcc's. |
| 55 | /// |
| 56 | namespace { |
Chris Lattner | 360e820 | 2006-06-28 21:58:30 +0000 | [diff] [blame] | 57 | class VISIBILITY_HIDDEN SelectionDAGLegalize { |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 58 | TargetLowering &TLI; |
| 59 | SelectionDAG &DAG; |
| 60 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 61 | // Libcall insertion helpers. |
| 62 | |
| 63 | /// LastCALLSEQ_END - This keeps track of the CALLSEQ_END node that has been |
| 64 | /// legalized. We use this to ensure that calls are properly serialized |
| 65 | /// against each other, including inserted libcalls. |
| 66 | SDOperand LastCALLSEQ_END; |
| 67 | |
| 68 | /// IsLegalizingCall - This member is used *only* for purposes of providing |
| 69 | /// helpful assertions that a libcall isn't created while another call is |
| 70 | /// being legalized (which could lead to non-serialized call sequences). |
| 71 | bool IsLegalizingCall; |
| 72 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 73 | enum LegalizeAction { |
Chris Lattner | 68a17fe | 2006-01-29 08:42:06 +0000 | [diff] [blame] | 74 | Legal, // The target natively supports this operation. |
| 75 | Promote, // This operation should be executed in a larger type. |
Chris Lattner | d74ea2b | 2006-05-24 17:04:05 +0000 | [diff] [blame] | 76 | Expand // Try to expand this to other ops, otherwise use a libcall. |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 77 | }; |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 78 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 79 | /// ValueTypeActions - This is a bitvector that contains two bits for each |
| 80 | /// value type, where the two bits correspond to the LegalizeAction enum. |
| 81 | /// This can be queried with "getTypeAction(VT)". |
Chris Lattner | 68a17fe | 2006-01-29 08:42:06 +0000 | [diff] [blame] | 82 | TargetLowering::ValueTypeActionImpl ValueTypeActions; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 83 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 84 | /// LegalizedNodes - For nodes that are of legal width, and that have more |
| 85 | /// than one use, this map indicates what regularized operand to use. This |
| 86 | /// allows us to avoid legalizing the same thing more than once. |
Chris Lattner | 718071c | 2007-02-04 00:50:02 +0000 | [diff] [blame] | 87 | DenseMap<SDOperand, SDOperand> LegalizedNodes; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 88 | |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 89 | /// PromotedNodes - For nodes that are below legal width, and that have more |
| 90 | /// than one use, this map indicates what promoted value to use. This allows |
| 91 | /// us to avoid promoting the same thing more than once. |
Chris Lattner | 40030bf | 2007-02-04 01:17:38 +0000 | [diff] [blame] | 92 | DenseMap<SDOperand, SDOperand> PromotedNodes; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 93 | |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 94 | /// ExpandedNodes - For nodes that need to be expanded this map indicates |
| 95 | /// which which operands are the expanded version of the input. This allows |
| 96 | /// us to avoid expanding the same node more than once. |
Chris Lattner | 40030bf | 2007-02-04 01:17:38 +0000 | [diff] [blame] | 97 | DenseMap<SDOperand, std::pair<SDOperand, SDOperand> > ExpandedNodes; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 98 | |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 99 | /// SplitNodes - For vector nodes that need to be split, this map indicates |
| 100 | /// which which operands are the split version of the input. This allows us |
| 101 | /// to avoid splitting the same node more than once. |
| 102 | std::map<SDOperand, std::pair<SDOperand, SDOperand> > SplitNodes; |
| 103 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 104 | /// ScalarizedNodes - For nodes that need to be converted from vector types to |
| 105 | /// scalar types, this contains the mapping of ones we have already |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 106 | /// processed to the result. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 107 | std::map<SDOperand, SDOperand> ScalarizedNodes; |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 108 | |
Chris Lattner | 8afc48e | 2005-01-07 22:28:47 +0000 | [diff] [blame] | 109 | void AddLegalizedOperand(SDOperand From, SDOperand To) { |
Chris Lattner | 69a889e | 2005-12-20 00:53:54 +0000 | [diff] [blame] | 110 | LegalizedNodes.insert(std::make_pair(From, To)); |
| 111 | // If someone requests legalization of the new node, return itself. |
| 112 | if (From != To) |
| 113 | LegalizedNodes.insert(std::make_pair(To, To)); |
Chris Lattner | 8afc48e | 2005-01-07 22:28:47 +0000 | [diff] [blame] | 114 | } |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 115 | void AddPromotedOperand(SDOperand From, SDOperand To) { |
Chris Lattner | 40030bf | 2007-02-04 01:17:38 +0000 | [diff] [blame] | 116 | bool isNew = PromotedNodes.insert(std::make_pair(From, To)); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 117 | assert(isNew && "Got into the map somehow?"); |
Chris Lattner | 69a889e | 2005-12-20 00:53:54 +0000 | [diff] [blame] | 118 | // If someone requests legalization of the new node, return itself. |
| 119 | LegalizedNodes.insert(std::make_pair(To, To)); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 120 | } |
Chris Lattner | 8afc48e | 2005-01-07 22:28:47 +0000 | [diff] [blame] | 121 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 122 | public: |
| 123 | |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 124 | SelectionDAGLegalize(SelectionDAG &DAG); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 125 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 126 | /// getTypeAction - Return how we should legalize values of this type, either |
| 127 | /// it is already legal or we need to expand it into multiple registers of |
| 128 | /// smaller integer type, or we need to promote it to a larger type. |
| 129 | LegalizeAction getTypeAction(MVT::ValueType VT) const { |
Chris Lattner | 68a17fe | 2006-01-29 08:42:06 +0000 | [diff] [blame] | 130 | return (LegalizeAction)ValueTypeActions.getTypeAction(VT); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | /// isTypeLegal - Return true if this type is legal on this target. |
| 134 | /// |
| 135 | bool isTypeLegal(MVT::ValueType VT) const { |
| 136 | return getTypeAction(VT) == Legal; |
| 137 | } |
| 138 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 139 | void LegalizeDAG(); |
| 140 | |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 141 | private: |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 142 | /// HandleOp - Legalize, Promote, or Expand the specified operand as |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 143 | /// appropriate for its type. |
| 144 | void HandleOp(SDOperand Op); |
| 145 | |
| 146 | /// LegalizeOp - We know that the specified value has a legal type. |
| 147 | /// Recursively ensure that the operands have legal types, then return the |
| 148 | /// result. |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 149 | SDOperand LegalizeOp(SDOperand O); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 150 | |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 151 | /// UnrollVectorOp - We know that the given vector has a legal type, however |
| 152 | /// the operation it performs is not legal and is an operation that we have |
| 153 | /// no way of lowering. "Unroll" the vector, splitting out the scalars and |
| 154 | /// operating on each element individually. |
| 155 | SDOperand UnrollVectorOp(SDOperand O); |
| 156 | |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 157 | /// PromoteOp - Given an operation that produces a value in an invalid type, |
| 158 | /// promote it to compute the value into a larger type. The produced value |
| 159 | /// will have the correct bits for the low portion of the register, but no |
| 160 | /// guarantee is made about the top bits: it may be zero, sign-extended, or |
| 161 | /// garbage. |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 162 | SDOperand PromoteOp(SDOperand O); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 163 | |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 164 | /// ExpandOp - Expand the specified SDOperand into its two component pieces |
| 165 | /// Lo&Hi. Note that the Op MUST be an expanded type. As a result of this, |
| 166 | /// the LegalizeNodes map is filled in for any results that are not expanded, |
| 167 | /// the ExpandedNodes map is filled in for any results that are expanded, and |
| 168 | /// the Lo/Hi values are returned. This applies to integer types and Vector |
| 169 | /// types. |
| 170 | void ExpandOp(SDOperand O, SDOperand &Lo, SDOperand &Hi); |
| 171 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 172 | /// SplitVectorOp - Given an operand of vector type, break it down into |
| 173 | /// two smaller values. |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 174 | void SplitVectorOp(SDOperand O, SDOperand &Lo, SDOperand &Hi); |
| 175 | |
Dan Gohman | 89b20c0 | 2007-06-27 14:06:22 +0000 | [diff] [blame] | 176 | /// ScalarizeVectorOp - Given an operand of single-element vector type |
| 177 | /// (e.g. v1f32), convert it into the equivalent operation that returns a |
| 178 | /// scalar (e.g. f32) value. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 179 | SDOperand ScalarizeVectorOp(SDOperand O); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 180 | |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 181 | /// isShuffleLegal - Return true if a vector shuffle is legal with the |
| 182 | /// specified mask and type. Targets can specify exactly which masks they |
| 183 | /// support and the code generator is tasked with not creating illegal masks. |
| 184 | /// |
| 185 | /// Note that this will also return true for shuffles that are promoted to a |
| 186 | /// different type. |
| 187 | /// |
| 188 | /// If this is a legal shuffle, this method returns the (possibly promoted) |
| 189 | /// build_vector Mask. If it's not a legal shuffle, it returns null. |
| 190 | SDNode *isShuffleLegal(MVT::ValueType VT, SDOperand Mask) const; |
| 191 | |
Chris Lattner | c9cf4f1 | 2006-07-26 23:55:56 +0000 | [diff] [blame] | 192 | bool LegalizeAllNodesNotLeadingTo(SDNode *N, SDNode *Dest, |
Chris Lattner | 00755df | 2007-02-04 00:27:56 +0000 | [diff] [blame] | 193 | SmallPtrSet<SDNode*, 32> &NodesLeadingTo); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 194 | |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 195 | void LegalizeSetCCOperands(SDOperand &LHS, SDOperand &RHS, SDOperand &CC); |
| 196 | |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 197 | SDOperand ExpandLibCall(const char *Name, SDNode *Node, bool isSigned, |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 198 | SDOperand &Hi); |
| 199 | SDOperand ExpandIntToFP(bool isSigned, MVT::ValueType DestTy, |
| 200 | SDOperand Source); |
Chris Lattner | cad063f | 2005-07-16 00:19:57 +0000 | [diff] [blame] | 201 | |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 202 | SDOperand ExpandBIT_CONVERT(MVT::ValueType DestVT, SDOperand SrcOp); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 203 | SDOperand ExpandBUILD_VECTOR(SDNode *Node); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 204 | SDOperand ExpandSCALAR_TO_VECTOR(SDNode *Node); |
Jim Laskey | 6269ed1 | 2005-08-17 00:39:29 +0000 | [diff] [blame] | 205 | SDOperand ExpandLegalINT_TO_FP(bool isSigned, |
| 206 | SDOperand LegalOp, |
| 207 | MVT::ValueType DestVT); |
Nate Begeman | 5a8441e | 2005-07-16 02:02:34 +0000 | [diff] [blame] | 208 | SDOperand PromoteLegalINT_TO_FP(SDOperand LegalOp, MVT::ValueType DestVT, |
| 209 | bool isSigned); |
Chris Lattner | 1618beb | 2005-07-29 00:11:56 +0000 | [diff] [blame] | 210 | SDOperand PromoteLegalFP_TO_INT(SDOperand LegalOp, MVT::ValueType DestVT, |
| 211 | bool isSigned); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 212 | |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 213 | SDOperand ExpandBSWAP(SDOperand Op); |
| 214 | SDOperand ExpandBitCount(unsigned Opc, SDOperand Op); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 215 | bool ExpandShift(unsigned Opc, SDOperand Op, SDOperand Amt, |
| 216 | SDOperand &Lo, SDOperand &Hi); |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 217 | void ExpandShiftParts(unsigned NodeOp, SDOperand Op, SDOperand Amt, |
| 218 | SDOperand &Lo, SDOperand &Hi); |
Chris Lattner | b9fa3bc | 2005-05-12 04:49:08 +0000 | [diff] [blame] | 219 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 220 | SDOperand ExpandEXTRACT_SUBVECTOR(SDOperand Op); |
Chris Lattner | 4aab2f4 | 2006-04-02 05:06:04 +0000 | [diff] [blame] | 221 | SDOperand ExpandEXTRACT_VECTOR_ELT(SDOperand Op); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 222 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 223 | SDOperand getIntPtrConstant(uint64_t Val) { |
| 224 | return DAG.getConstant(Val, TLI.getPointerTy()); |
| 225 | } |
| 226 | }; |
| 227 | } |
| 228 | |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 229 | /// isVectorShuffleLegal - Return true if a vector shuffle is legal with the |
| 230 | /// specified mask and type. Targets can specify exactly which masks they |
| 231 | /// support and the code generator is tasked with not creating illegal masks. |
| 232 | /// |
| 233 | /// Note that this will also return true for shuffles that are promoted to a |
| 234 | /// different type. |
| 235 | SDNode *SelectionDAGLegalize::isShuffleLegal(MVT::ValueType VT, |
| 236 | SDOperand Mask) const { |
| 237 | switch (TLI.getOperationAction(ISD::VECTOR_SHUFFLE, VT)) { |
| 238 | default: return 0; |
| 239 | case TargetLowering::Legal: |
| 240 | case TargetLowering::Custom: |
| 241 | break; |
| 242 | case TargetLowering::Promote: { |
| 243 | // If this is promoted to a different type, convert the shuffle mask and |
| 244 | // ask if it is legal in the promoted type! |
| 245 | MVT::ValueType NVT = TLI.getTypeToPromoteTo(ISD::VECTOR_SHUFFLE, VT); |
| 246 | |
| 247 | // If we changed # elements, change the shuffle mask. |
| 248 | unsigned NumEltsGrowth = |
| 249 | MVT::getVectorNumElements(NVT) / MVT::getVectorNumElements(VT); |
| 250 | assert(NumEltsGrowth && "Cannot promote to vector type with fewer elts!"); |
| 251 | if (NumEltsGrowth > 1) { |
| 252 | // Renumber the elements. |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 253 | SmallVector<SDOperand, 8> Ops; |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 254 | for (unsigned i = 0, e = Mask.getNumOperands(); i != e; ++i) { |
| 255 | SDOperand InOp = Mask.getOperand(i); |
| 256 | for (unsigned j = 0; j != NumEltsGrowth; ++j) { |
| 257 | if (InOp.getOpcode() == ISD::UNDEF) |
| 258 | Ops.push_back(DAG.getNode(ISD::UNDEF, MVT::i32)); |
| 259 | else { |
| 260 | unsigned InEltNo = cast<ConstantSDNode>(InOp)->getValue(); |
| 261 | Ops.push_back(DAG.getConstant(InEltNo*NumEltsGrowth+j, MVT::i32)); |
| 262 | } |
| 263 | } |
| 264 | } |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 265 | Mask = DAG.getNode(ISD::BUILD_VECTOR, NVT, &Ops[0], Ops.size()); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 266 | } |
| 267 | VT = NVT; |
| 268 | break; |
| 269 | } |
| 270 | } |
| 271 | return TLI.isShuffleMaskLegal(Mask, VT) ? Mask.Val : 0; |
| 272 | } |
| 273 | |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 274 | SelectionDAGLegalize::SelectionDAGLegalize(SelectionDAG &dag) |
| 275 | : TLI(dag.getTargetLoweringInfo()), DAG(dag), |
| 276 | ValueTypeActions(TLI.getValueTypeActions()) { |
Nate Begeman | 6a64861 | 2005-11-29 05:45:29 +0000 | [diff] [blame] | 277 | assert(MVT::LAST_VALUETYPE <= 32 && |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 278 | "Too many value types for ValueTypeActions to hold!"); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 279 | } |
| 280 | |
Chris Lattner | e10e6f7 | 2007-06-18 21:28:10 +0000 | [diff] [blame] | 281 | /// ComputeTopDownOrdering - Compute a top-down ordering of the dag, where Order |
| 282 | /// contains all of a nodes operands before it contains the node. |
| 283 | static void ComputeTopDownOrdering(SelectionDAG &DAG, |
| 284 | SmallVector<SDNode*, 64> &Order) { |
| 285 | |
| 286 | DenseMap<SDNode*, unsigned> Visited; |
| 287 | std::vector<SDNode*> Worklist; |
| 288 | Worklist.reserve(128); |
Chris Lattner | 32fca00 | 2005-10-06 01:20:27 +0000 | [diff] [blame] | 289 | |
Chris Lattner | e10e6f7 | 2007-06-18 21:28:10 +0000 | [diff] [blame] | 290 | // Compute ordering from all of the leaves in the graphs, those (like the |
| 291 | // entry node) that have no operands. |
| 292 | for (SelectionDAG::allnodes_iterator I = DAG.allnodes_begin(), |
| 293 | E = DAG.allnodes_end(); I != E; ++I) { |
| 294 | if (I->getNumOperands() == 0) { |
| 295 | Visited[I] = 0 - 1U; |
| 296 | Worklist.push_back(I); |
| 297 | } |
Chris Lattner | 32fca00 | 2005-10-06 01:20:27 +0000 | [diff] [blame] | 298 | } |
| 299 | |
Chris Lattner | e10e6f7 | 2007-06-18 21:28:10 +0000 | [diff] [blame] | 300 | while (!Worklist.empty()) { |
| 301 | SDNode *N = Worklist.back(); |
| 302 | Worklist.pop_back(); |
| 303 | |
| 304 | if (++Visited[N] != N->getNumOperands()) |
| 305 | continue; // Haven't visited all operands yet |
| 306 | |
| 307 | Order.push_back(N); |
| 308 | |
| 309 | // Now that we have N in, add anything that uses it if all of their operands |
| 310 | // are now done. |
| 311 | for (SDNode::use_iterator UI = N->use_begin(), E = N->use_end(); |
| 312 | UI != E; ++UI) |
| 313 | Worklist.push_back(*UI); |
| 314 | } |
| 315 | |
| 316 | assert(Order.size() == Visited.size() && |
| 317 | Order.size() == |
| 318 | (unsigned)std::distance(DAG.allnodes_begin(), DAG.allnodes_end()) && |
| 319 | "Error: DAG is cyclic!"); |
Chris Lattner | 32fca00 | 2005-10-06 01:20:27 +0000 | [diff] [blame] | 320 | } |
| 321 | |
Chris Lattner | 1618beb | 2005-07-29 00:11:56 +0000 | [diff] [blame] | 322 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 323 | void SelectionDAGLegalize::LegalizeDAG() { |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 324 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 325 | IsLegalizingCall = false; |
| 326 | |
Chris Lattner | ab510a7 | 2005-10-02 17:49:46 +0000 | [diff] [blame] | 327 | // The legalize process is inherently a bottom-up recursive process (users |
| 328 | // legalize their uses before themselves). Given infinite stack space, we |
| 329 | // could just start legalizing on the root and traverse the whole graph. In |
| 330 | // 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] | 331 | // blocks. To avoid this problem, compute an ordering of the nodes where each |
| 332 | // node is only legalized after all of its operands are legalized. |
Chris Lattner | 0ed4417 | 2007-02-04 01:20:02 +0000 | [diff] [blame] | 333 | SmallVector<SDNode*, 64> Order; |
Chris Lattner | e10e6f7 | 2007-06-18 21:28:10 +0000 | [diff] [blame] | 334 | ComputeTopDownOrdering(DAG, Order); |
Chris Lattner | ab510a7 | 2005-10-02 17:49:46 +0000 | [diff] [blame] | 335 | |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 336 | for (unsigned i = 0, e = Order.size(); i != e; ++i) |
| 337 | HandleOp(SDOperand(Order[i], 0)); |
Chris Lattner | 32fca00 | 2005-10-06 01:20:27 +0000 | [diff] [blame] | 338 | |
| 339 | // Finally, it's possible the root changed. Get the new root. |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 340 | SDOperand OldRoot = DAG.getRoot(); |
Chris Lattner | 32fca00 | 2005-10-06 01:20:27 +0000 | [diff] [blame] | 341 | assert(LegalizedNodes.count(OldRoot) && "Root didn't get legalized?"); |
| 342 | DAG.setRoot(LegalizedNodes[OldRoot]); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 343 | |
| 344 | ExpandedNodes.clear(); |
| 345 | LegalizedNodes.clear(); |
Chris Lattner | 71c42a0 | 2005-01-16 01:11:45 +0000 | [diff] [blame] | 346 | PromotedNodes.clear(); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 347 | SplitNodes.clear(); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 348 | ScalarizedNodes.clear(); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 349 | |
| 350 | // Remove dead nodes now. |
Chris Lattner | 190a418 | 2006-08-04 17:45:20 +0000 | [diff] [blame] | 351 | DAG.RemoveDeadNodes(); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 352 | } |
| 353 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 354 | |
| 355 | /// FindCallEndFromCallStart - Given a chained node that is part of a call |
| 356 | /// sequence, find the CALLSEQ_END node that terminates the call sequence. |
| 357 | static SDNode *FindCallEndFromCallStart(SDNode *Node) { |
| 358 | if (Node->getOpcode() == ISD::CALLSEQ_END) |
| 359 | return Node; |
| 360 | if (Node->use_empty()) |
| 361 | return 0; // No CallSeqEnd |
| 362 | |
| 363 | // The chain is usually at the end. |
| 364 | SDOperand TheChain(Node, Node->getNumValues()-1); |
| 365 | if (TheChain.getValueType() != MVT::Other) { |
| 366 | // Sometimes it's at the beginning. |
| 367 | TheChain = SDOperand(Node, 0); |
| 368 | if (TheChain.getValueType() != MVT::Other) { |
| 369 | // Otherwise, hunt for it. |
| 370 | for (unsigned i = 1, e = Node->getNumValues(); i != e; ++i) |
| 371 | if (Node->getValueType(i) == MVT::Other) { |
| 372 | TheChain = SDOperand(Node, i); |
| 373 | break; |
| 374 | } |
| 375 | |
| 376 | // Otherwise, we walked into a node without a chain. |
| 377 | if (TheChain.getValueType() != MVT::Other) |
| 378 | return 0; |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | for (SDNode::use_iterator UI = Node->use_begin(), |
| 383 | E = Node->use_end(); UI != E; ++UI) { |
| 384 | |
| 385 | // Make sure to only follow users of our token chain. |
| 386 | SDNode *User = *UI; |
| 387 | for (unsigned i = 0, e = User->getNumOperands(); i != e; ++i) |
| 388 | if (User->getOperand(i) == TheChain) |
| 389 | if (SDNode *Result = FindCallEndFromCallStart(User)) |
| 390 | return Result; |
| 391 | } |
| 392 | return 0; |
| 393 | } |
| 394 | |
| 395 | /// FindCallStartFromCallEnd - Given a chained node that is part of a call |
| 396 | /// sequence, find the CALLSEQ_START node that initiates the call sequence. |
| 397 | static SDNode *FindCallStartFromCallEnd(SDNode *Node) { |
| 398 | assert(Node && "Didn't find callseq_start for a call??"); |
| 399 | if (Node->getOpcode() == ISD::CALLSEQ_START) return Node; |
| 400 | |
| 401 | assert(Node->getOperand(0).getValueType() == MVT::Other && |
| 402 | "Node doesn't have a token chain argument!"); |
| 403 | return FindCallStartFromCallEnd(Node->getOperand(0).Val); |
| 404 | } |
| 405 | |
| 406 | /// LegalizeAllNodesNotLeadingTo - Recursively walk the uses of N, looking to |
| 407 | /// see if any uses can reach Dest. If no dest operands can get to dest, |
| 408 | /// legalize them, legalize ourself, and return false, otherwise, return true. |
Chris Lattner | c9cf4f1 | 2006-07-26 23:55:56 +0000 | [diff] [blame] | 409 | /// |
| 410 | /// Keep track of the nodes we fine that actually do lead to Dest in |
| 411 | /// NodesLeadingTo. This avoids retraversing them exponential number of times. |
| 412 | /// |
| 413 | bool SelectionDAGLegalize::LegalizeAllNodesNotLeadingTo(SDNode *N, SDNode *Dest, |
Chris Lattner | 00755df | 2007-02-04 00:27:56 +0000 | [diff] [blame] | 414 | SmallPtrSet<SDNode*, 32> &NodesLeadingTo) { |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 415 | if (N == Dest) return true; // N certainly leads to Dest :) |
| 416 | |
Chris Lattner | c9cf4f1 | 2006-07-26 23:55:56 +0000 | [diff] [blame] | 417 | // If we've already processed this node and it does lead to Dest, there is no |
| 418 | // need to reprocess it. |
| 419 | if (NodesLeadingTo.count(N)) return true; |
| 420 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 421 | // If the first result of this node has been already legalized, then it cannot |
| 422 | // reach N. |
| 423 | switch (getTypeAction(N->getValueType(0))) { |
| 424 | case Legal: |
| 425 | if (LegalizedNodes.count(SDOperand(N, 0))) return false; |
| 426 | break; |
| 427 | case Promote: |
| 428 | if (PromotedNodes.count(SDOperand(N, 0))) return false; |
| 429 | break; |
| 430 | case Expand: |
| 431 | if (ExpandedNodes.count(SDOperand(N, 0))) return false; |
| 432 | break; |
| 433 | } |
| 434 | |
| 435 | // Okay, this node has not already been legalized. Check and legalize all |
| 436 | // operands. If none lead to Dest, then we can legalize this node. |
| 437 | bool OperandsLeadToDest = false; |
| 438 | for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) |
| 439 | OperandsLeadToDest |= // If an operand leads to Dest, so do we. |
Chris Lattner | c9cf4f1 | 2006-07-26 23:55:56 +0000 | [diff] [blame] | 440 | LegalizeAllNodesNotLeadingTo(N->getOperand(i).Val, Dest, NodesLeadingTo); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 441 | |
Chris Lattner | c9cf4f1 | 2006-07-26 23:55:56 +0000 | [diff] [blame] | 442 | if (OperandsLeadToDest) { |
| 443 | NodesLeadingTo.insert(N); |
| 444 | return true; |
| 445 | } |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 446 | |
| 447 | // Okay, this node looks safe, legalize it and return false. |
Chris Lattner | 80edfb3 | 2006-04-17 22:10:08 +0000 | [diff] [blame] | 448 | HandleOp(SDOperand(N, 0)); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 449 | return false; |
| 450 | } |
| 451 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 452 | /// HandleOp - Legalize, Promote, or Expand the specified operand as |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 453 | /// appropriate for its type. |
| 454 | void SelectionDAGLegalize::HandleOp(SDOperand Op) { |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 455 | MVT::ValueType VT = Op.getValueType(); |
| 456 | switch (getTypeAction(VT)) { |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 457 | default: assert(0 && "Bad type action!"); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 458 | case Legal: (void)LegalizeOp(Op); break; |
| 459 | case Promote: (void)PromoteOp(Op); break; |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 460 | case Expand: |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 461 | if (!MVT::isVector(VT)) { |
| 462 | // If this is an illegal scalar, expand it into its two component |
| 463 | // pieces. |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 464 | SDOperand X, Y; |
Chris Lattner | 09ec1b0 | 2007-08-25 01:00:22 +0000 | [diff] [blame] | 465 | if (Op.getOpcode() == ISD::TargetConstant) |
| 466 | break; // Allow illegal target nodes. |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 467 | ExpandOp(Op, X, Y); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 468 | } else if (MVT::getVectorNumElements(VT) == 1) { |
| 469 | // If this is an illegal single element vector, convert it to a |
| 470 | // scalar operation. |
| 471 | (void)ScalarizeVectorOp(Op); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 472 | } else { |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 473 | // Otherwise, this is an illegal multiple element vector. |
| 474 | // Split it in half and legalize both parts. |
| 475 | SDOperand X, Y; |
| 476 | SplitVectorOp(Op, X, Y); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 477 | } |
| 478 | break; |
| 479 | } |
| 480 | } |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 481 | |
Evan Cheng | 9f87788 | 2006-12-13 20:57:08 +0000 | [diff] [blame] | 482 | /// ExpandConstantFP - Expands the ConstantFP node to an integer constant or |
| 483 | /// a load from the constant pool. |
| 484 | static SDOperand ExpandConstantFP(ConstantFPSDNode *CFP, bool UseCP, |
Evan Cheng | 279101e | 2006-12-12 22:19:28 +0000 | [diff] [blame] | 485 | SelectionDAG &DAG, TargetLowering &TLI) { |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 486 | bool Extend = false; |
| 487 | |
| 488 | // If a FP immediate is precise when represented as a float and if the |
| 489 | // target can do an extending load from float to double, we put it into |
| 490 | // the constant pool as a float, even if it's is statically typed as a |
| 491 | // double. |
| 492 | MVT::ValueType VT = CFP->getValueType(0); |
| 493 | bool isDouble = VT == MVT::f64; |
Dale Johannesen | 118cd9d | 2007-09-16 16:51:49 +0000 | [diff] [blame] | 494 | ConstantFP *LLVMC = ConstantFP::get(MVT::getTypeForValueType(VT), |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 495 | CFP->getValueAPF()); |
Evan Cheng | 9f87788 | 2006-12-13 20:57:08 +0000 | [diff] [blame] | 496 | if (!UseCP) { |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 497 | if (VT!=MVT::f64 && VT!=MVT::f32) |
| 498 | assert(0 && "Invalid type expansion"); |
Dale Johannesen | 9d5f456 | 2007-09-12 03:30:33 +0000 | [diff] [blame] | 499 | return DAG.getConstant(LLVMC->getValueAPF().convertToAPInt().getZExtValue(), |
| 500 | isDouble ? MVT::i64 : MVT::i32); |
Evan Cheng | 279101e | 2006-12-12 22:19:28 +0000 | [diff] [blame] | 501 | } |
| 502 | |
Dale Johannesen | f04afdb | 2007-08-30 00:23:21 +0000 | [diff] [blame] | 503 | if (isDouble && CFP->isValueValidForType(MVT::f32, CFP->getValueAPF()) && |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 504 | // Only do this if the target has a native EXTLOAD instruction from f32. |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 505 | // Do not try to be clever about long doubles (so far) |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 506 | TLI.isLoadXLegal(ISD::EXTLOAD, MVT::f32)) { |
| 507 | LLVMC = cast<ConstantFP>(ConstantExpr::getFPTrunc(LLVMC,Type::FloatTy)); |
| 508 | VT = MVT::f32; |
| 509 | Extend = true; |
| 510 | } |
| 511 | |
| 512 | SDOperand CPIdx = DAG.getConstantPool(LLVMC, TLI.getPointerTy()); |
| 513 | if (Extend) { |
| 514 | return DAG.getExtLoad(ISD::EXTLOAD, MVT::f64, DAG.getEntryNode(), |
| 515 | CPIdx, NULL, 0, MVT::f32); |
| 516 | } else { |
| 517 | return DAG.getLoad(VT, DAG.getEntryNode(), CPIdx, NULL, 0); |
| 518 | } |
| 519 | } |
| 520 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 521 | |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 522 | /// ExpandFCOPYSIGNToBitwiseOps - Expands fcopysign to a series of bitwise |
| 523 | /// operations. |
| 524 | static |
| 525 | SDOperand ExpandFCOPYSIGNToBitwiseOps(SDNode *Node, MVT::ValueType NVT, |
| 526 | SelectionDAG &DAG, TargetLowering &TLI) { |
Evan Cheng | 068c5f4 | 2007-01-05 21:31:51 +0000 | [diff] [blame] | 527 | MVT::ValueType VT = Node->getValueType(0); |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 528 | MVT::ValueType SrcVT = Node->getOperand(1).getValueType(); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 529 | assert((SrcVT == MVT::f32 || SrcVT == MVT::f64) && |
| 530 | "fcopysign expansion only supported for f32 and f64"); |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 531 | MVT::ValueType SrcNVT = (SrcVT == MVT::f64) ? MVT::i64 : MVT::i32; |
Evan Cheng | 068c5f4 | 2007-01-05 21:31:51 +0000 | [diff] [blame] | 532 | |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 533 | // First get the sign bit of second operand. |
Evan Cheng | 068c5f4 | 2007-01-05 21:31:51 +0000 | [diff] [blame] | 534 | SDOperand Mask1 = (SrcVT == MVT::f64) |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 535 | ? DAG.getConstantFP(BitsToDouble(1ULL << 63), SrcVT) |
| 536 | : DAG.getConstantFP(BitsToFloat(1U << 31), SrcVT); |
Evan Cheng | 068c5f4 | 2007-01-05 21:31:51 +0000 | [diff] [blame] | 537 | Mask1 = DAG.getNode(ISD::BIT_CONVERT, SrcNVT, Mask1); |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 538 | SDOperand SignBit= DAG.getNode(ISD::BIT_CONVERT, SrcNVT, Node->getOperand(1)); |
Evan Cheng | 068c5f4 | 2007-01-05 21:31:51 +0000 | [diff] [blame] | 539 | SignBit = DAG.getNode(ISD::AND, SrcNVT, SignBit, Mask1); |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 540 | // Shift right or sign-extend it if the two operands have different types. |
| 541 | int SizeDiff = MVT::getSizeInBits(SrcNVT) - MVT::getSizeInBits(NVT); |
| 542 | if (SizeDiff > 0) { |
| 543 | SignBit = DAG.getNode(ISD::SRL, SrcNVT, SignBit, |
| 544 | DAG.getConstant(SizeDiff, TLI.getShiftAmountTy())); |
| 545 | SignBit = DAG.getNode(ISD::TRUNCATE, NVT, SignBit); |
| 546 | } else if (SizeDiff < 0) |
| 547 | SignBit = DAG.getNode(ISD::SIGN_EXTEND, NVT, SignBit); |
Evan Cheng | 068c5f4 | 2007-01-05 21:31:51 +0000 | [diff] [blame] | 548 | |
| 549 | // Clear the sign bit of first operand. |
| 550 | SDOperand Mask2 = (VT == MVT::f64) |
| 551 | ? DAG.getConstantFP(BitsToDouble(~(1ULL << 63)), VT) |
| 552 | : DAG.getConstantFP(BitsToFloat(~(1U << 31)), VT); |
| 553 | Mask2 = DAG.getNode(ISD::BIT_CONVERT, NVT, Mask2); |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 554 | SDOperand Result = DAG.getNode(ISD::BIT_CONVERT, NVT, Node->getOperand(0)); |
Evan Cheng | 068c5f4 | 2007-01-05 21:31:51 +0000 | [diff] [blame] | 555 | Result = DAG.getNode(ISD::AND, NVT, Result, Mask2); |
| 556 | |
| 557 | // Or the value with the sign bit. |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 558 | Result = DAG.getNode(ISD::OR, NVT, Result, SignBit); |
| 559 | return Result; |
| 560 | } |
| 561 | |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 562 | /// ExpandUnalignedStore - Expands an unaligned store to 2 half-size stores. |
| 563 | static |
| 564 | SDOperand ExpandUnalignedStore(StoreSDNode *ST, SelectionDAG &DAG, |
| 565 | TargetLowering &TLI) { |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 566 | SDOperand Chain = ST->getChain(); |
| 567 | SDOperand Ptr = ST->getBasePtr(); |
| 568 | SDOperand Val = ST->getValue(); |
| 569 | MVT::ValueType VT = Val.getValueType(); |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 570 | int Alignment = ST->getAlignment(); |
| 571 | int SVOffset = ST->getSrcValueOffset(); |
| 572 | if (MVT::isFloatingPoint(ST->getStoredVT())) { |
| 573 | // Expand to a bitconvert of the value to the integer type of the |
| 574 | // same size, then a (misaligned) int store. |
| 575 | MVT::ValueType intVT; |
| 576 | if (VT==MVT::f64) |
| 577 | intVT = MVT::i64; |
| 578 | else if (VT==MVT::f32) |
| 579 | intVT = MVT::i32; |
| 580 | else |
| 581 | assert(0 && "Unaligned load of unsupported floating point type"); |
| 582 | |
| 583 | SDOperand Result = DAG.getNode(ISD::BIT_CONVERT, intVT, Val); |
| 584 | return DAG.getStore(Chain, Result, Ptr, ST->getSrcValue(), |
| 585 | SVOffset, ST->isVolatile(), Alignment); |
| 586 | } |
| 587 | assert(MVT::isInteger(ST->getStoredVT()) && |
| 588 | "Unaligned store of unknown type."); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 589 | // Get the half-size VT |
| 590 | MVT::ValueType NewStoredVT = ST->getStoredVT() - 1; |
| 591 | int NumBits = MVT::getSizeInBits(NewStoredVT); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 592 | int IncrementSize = NumBits / 8; |
| 593 | |
| 594 | // Divide the stored value in two parts. |
| 595 | SDOperand ShiftAmount = DAG.getConstant(NumBits, TLI.getShiftAmountTy()); |
| 596 | SDOperand Lo = Val; |
| 597 | SDOperand Hi = DAG.getNode(ISD::SRL, VT, Val, ShiftAmount); |
| 598 | |
| 599 | // Store the two parts |
| 600 | SDOperand Store1, Store2; |
| 601 | Store1 = DAG.getTruncStore(Chain, TLI.isLittleEndian()?Lo:Hi, Ptr, |
| 602 | ST->getSrcValue(), SVOffset, NewStoredVT, |
| 603 | ST->isVolatile(), Alignment); |
| 604 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
| 605 | DAG.getConstant(IncrementSize, TLI.getPointerTy())); |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 606 | Alignment = MinAlign(Alignment, IncrementSize); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 607 | Store2 = DAG.getTruncStore(Chain, TLI.isLittleEndian()?Hi:Lo, Ptr, |
| 608 | ST->getSrcValue(), SVOffset + IncrementSize, |
| 609 | NewStoredVT, ST->isVolatile(), Alignment); |
| 610 | |
| 611 | return DAG.getNode(ISD::TokenFactor, MVT::Other, Store1, Store2); |
| 612 | } |
| 613 | |
| 614 | /// ExpandUnalignedLoad - Expands an unaligned load to 2 half-size loads. |
| 615 | static |
| 616 | SDOperand ExpandUnalignedLoad(LoadSDNode *LD, SelectionDAG &DAG, |
| 617 | TargetLowering &TLI) { |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 618 | int SVOffset = LD->getSrcValueOffset(); |
| 619 | SDOperand Chain = LD->getChain(); |
| 620 | SDOperand Ptr = LD->getBasePtr(); |
| 621 | MVT::ValueType VT = LD->getValueType(0); |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 622 | MVT::ValueType LoadedVT = LD->getLoadedVT(); |
| 623 | if (MVT::isFloatingPoint(VT)) { |
| 624 | // Expand to a (misaligned) integer load of the same size, |
| 625 | // then bitconvert to floating point. |
| 626 | MVT::ValueType intVT; |
| 627 | if (LoadedVT==MVT::f64) |
| 628 | intVT = MVT::i64; |
| 629 | else if (LoadedVT==MVT::f32) |
| 630 | intVT = MVT::i32; |
| 631 | else |
| 632 | assert(0 && "Unaligned load of unsupported floating point type"); |
| 633 | |
| 634 | SDOperand newLoad = DAG.getLoad(intVT, Chain, Ptr, LD->getSrcValue(), |
| 635 | SVOffset, LD->isVolatile(), |
| 636 | LD->getAlignment()); |
| 637 | SDOperand Result = DAG.getNode(ISD::BIT_CONVERT, LoadedVT, newLoad); |
| 638 | if (LoadedVT != VT) |
| 639 | Result = DAG.getNode(ISD::FP_EXTEND, VT, Result); |
| 640 | |
| 641 | SDOperand Ops[] = { Result, Chain }; |
| 642 | return DAG.getNode(ISD::MERGE_VALUES, DAG.getVTList(VT, MVT::Other), |
| 643 | Ops, 2); |
| 644 | } |
| 645 | assert(MVT::isInteger(LoadedVT) && "Unaligned load of unsupported type."); |
| 646 | MVT::ValueType NewLoadedVT = LoadedVT - 1; |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 647 | int NumBits = MVT::getSizeInBits(NewLoadedVT); |
| 648 | int Alignment = LD->getAlignment(); |
| 649 | int IncrementSize = NumBits / 8; |
| 650 | ISD::LoadExtType HiExtType = LD->getExtensionType(); |
| 651 | |
| 652 | // If the original load is NON_EXTLOAD, the hi part load must be ZEXTLOAD. |
| 653 | if (HiExtType == ISD::NON_EXTLOAD) |
| 654 | HiExtType = ISD::ZEXTLOAD; |
| 655 | |
| 656 | // Load the value in two parts |
| 657 | SDOperand Lo, Hi; |
| 658 | if (TLI.isLittleEndian()) { |
| 659 | Lo = DAG.getExtLoad(ISD::ZEXTLOAD, VT, Chain, Ptr, LD->getSrcValue(), |
| 660 | SVOffset, NewLoadedVT, LD->isVolatile(), Alignment); |
| 661 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
| 662 | DAG.getConstant(IncrementSize, TLI.getPointerTy())); |
| 663 | Hi = DAG.getExtLoad(HiExtType, VT, Chain, Ptr, LD->getSrcValue(), |
| 664 | SVOffset + IncrementSize, NewLoadedVT, LD->isVolatile(), |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 665 | MinAlign(Alignment, IncrementSize)); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 666 | } else { |
| 667 | Hi = DAG.getExtLoad(HiExtType, VT, Chain, Ptr, LD->getSrcValue(), SVOffset, |
| 668 | NewLoadedVT,LD->isVolatile(), Alignment); |
| 669 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
| 670 | DAG.getConstant(IncrementSize, TLI.getPointerTy())); |
| 671 | Lo = DAG.getExtLoad(ISD::ZEXTLOAD, VT, Chain, Ptr, LD->getSrcValue(), |
| 672 | SVOffset + IncrementSize, NewLoadedVT, LD->isVolatile(), |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 673 | MinAlign(Alignment, IncrementSize)); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 674 | } |
| 675 | |
| 676 | // aggregate the two parts |
| 677 | SDOperand ShiftAmount = DAG.getConstant(NumBits, TLI.getShiftAmountTy()); |
| 678 | SDOperand Result = DAG.getNode(ISD::SHL, VT, Hi, ShiftAmount); |
| 679 | Result = DAG.getNode(ISD::OR, VT, Result, Lo); |
| 680 | |
| 681 | SDOperand TF = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1), |
| 682 | Hi.getValue(1)); |
| 683 | |
| 684 | SDOperand Ops[] = { Result, TF }; |
| 685 | return DAG.getNode(ISD::MERGE_VALUES, DAG.getVTList(VT, MVT::Other), Ops, 2); |
| 686 | } |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 687 | |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 688 | /// UnrollVectorOp - We know that the given vector has a legal type, however |
| 689 | /// the operation it performs is not legal and is an operation that we have |
| 690 | /// no way of lowering. "Unroll" the vector, splitting out the scalars and |
| 691 | /// operating on each element individually. |
| 692 | SDOperand SelectionDAGLegalize::UnrollVectorOp(SDOperand Op) { |
| 693 | MVT::ValueType VT = Op.getValueType(); |
| 694 | assert(isTypeLegal(VT) && |
| 695 | "Caller should expand or promote operands that are not legal!"); |
| 696 | assert(Op.Val->getNumValues() == 1 && |
| 697 | "Can't unroll a vector with multiple results!"); |
| 698 | unsigned NE = MVT::getVectorNumElements(VT); |
| 699 | MVT::ValueType EltVT = MVT::getVectorElementType(VT); |
| 700 | |
| 701 | SmallVector<SDOperand, 8> Scalars; |
| 702 | SmallVector<SDOperand, 4> Operands(Op.getNumOperands()); |
| 703 | for (unsigned i = 0; i != NE; ++i) { |
| 704 | for (unsigned j = 0; j != Op.getNumOperands(); ++j) { |
| 705 | SDOperand Operand = Op.getOperand(j); |
| 706 | MVT::ValueType OperandVT = Operand.getValueType(); |
| 707 | if (MVT::isVector(OperandVT)) { |
| 708 | // A vector operand; extract a single element. |
| 709 | MVT::ValueType OperandEltVT = MVT::getVectorElementType(OperandVT); |
| 710 | Operands[j] = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, |
| 711 | OperandEltVT, |
| 712 | Operand, |
| 713 | DAG.getConstant(i, MVT::i32)); |
| 714 | } else { |
| 715 | // A scalar operand; just use it as is. |
| 716 | Operands[j] = Operand; |
| 717 | } |
| 718 | } |
| 719 | Scalars.push_back(DAG.getNode(Op.getOpcode(), EltVT, |
| 720 | &Operands[0], Operands.size())); |
| 721 | } |
| 722 | |
| 723 | return DAG.getNode(ISD::BUILD_VECTOR, VT, &Scalars[0], Scalars.size()); |
| 724 | } |
| 725 | |
Dan Gohman | a346615 | 2007-07-13 20:14:11 +0000 | [diff] [blame] | 726 | /// LegalizeOp - We know that the specified value has a legal type, and |
| 727 | /// that its operands are legal. Now ensure that the operation itself |
| 728 | /// is legal, recursively ensuring that the operands' operations remain |
| 729 | /// legal. |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 730 | SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) { |
Chris Lattner | 09ec1b0 | 2007-08-25 01:00:22 +0000 | [diff] [blame] | 731 | if (Op.getOpcode() == ISD::TargetConstant) // Allow illegal target nodes. |
| 732 | return Op; |
| 733 | |
Chris Lattner | c9c60f6 | 2005-08-24 16:35:28 +0000 | [diff] [blame] | 734 | assert(isTypeLegal(Op.getValueType()) && |
Chris Lattner | e3304a3 | 2005-01-08 20:35:13 +0000 | [diff] [blame] | 735 | "Caller should expand or promote operands that are not legal!"); |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 736 | SDNode *Node = Op.Val; |
Chris Lattner | e3304a3 | 2005-01-08 20:35:13 +0000 | [diff] [blame] | 737 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 738 | // If this operation defines any values that cannot be represented in a |
Chris Lattner | e3304a3 | 2005-01-08 20:35:13 +0000 | [diff] [blame] | 739 | // register on this target, make sure to expand or promote them. |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 740 | if (Node->getNumValues() > 1) { |
| 741 | for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 742 | if (getTypeAction(Node->getValueType(i)) != Legal) { |
| 743 | HandleOp(Op.getValue(i)); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 744 | assert(LegalizedNodes.count(Op) && |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 745 | "Handling didn't add legal operands!"); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 746 | return LegalizedNodes[Op]; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 747 | } |
| 748 | } |
| 749 | |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 750 | // Note that LegalizeOp may be reentered even from single-use nodes, which |
| 751 | // means that we always must cache transformed nodes. |
Chris Lattner | 718071c | 2007-02-04 00:50:02 +0000 | [diff] [blame] | 752 | DenseMap<SDOperand, SDOperand>::iterator I = LegalizedNodes.find(Op); |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 753 | if (I != LegalizedNodes.end()) return I->second; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 754 | |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 755 | SDOperand Tmp1, Tmp2, Tmp3, Tmp4; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 756 | SDOperand Result = Op; |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 757 | bool isCustom = false; |
| 758 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 759 | switch (Node->getOpcode()) { |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 760 | case ISD::FrameIndex: |
| 761 | case ISD::EntryToken: |
| 762 | case ISD::Register: |
| 763 | case ISD::BasicBlock: |
| 764 | case ISD::TargetFrameIndex: |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 765 | case ISD::TargetJumpTable: |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 766 | case ISD::TargetConstant: |
Chris Lattner | 3181a77 | 2006-01-29 06:26:56 +0000 | [diff] [blame] | 767 | case ISD::TargetConstantFP: |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 768 | case ISD::TargetConstantPool: |
| 769 | case ISD::TargetGlobalAddress: |
Lauro Ramos Venancio | b3a0417 | 2007-04-20 21:38:10 +0000 | [diff] [blame] | 770 | case ISD::TargetGlobalTLSAddress: |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 771 | case ISD::TargetExternalSymbol: |
| 772 | case ISD::VALUETYPE: |
| 773 | case ISD::SRCVALUE: |
| 774 | case ISD::STRING: |
| 775 | case ISD::CONDCODE: |
| 776 | // Primitives must all be legal. |
Duncan Sands | a7c97a7 | 2007-10-16 09:07:20 +0000 | [diff] [blame] | 777 | assert(TLI.isOperationLegal(Node->getOpcode(), Node->getValueType(0)) && |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 778 | "This must be legal!"); |
| 779 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 780 | default: |
Chris Lattner | d73cc5d | 2005-05-14 06:34:48 +0000 | [diff] [blame] | 781 | if (Node->getOpcode() >= ISD::BUILTIN_OP_END) { |
| 782 | // If this is a target node, legalize it by legalizing the operands then |
| 783 | // passing it through. |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 784 | SmallVector<SDOperand, 8> Ops; |
Chris Lattner | c5d7d7c | 2006-05-17 18:00:08 +0000 | [diff] [blame] | 785 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) |
Chris Lattner | d73cc5d | 2005-05-14 06:34:48 +0000 | [diff] [blame] | 786 | Ops.push_back(LegalizeOp(Node->getOperand(i))); |
Chris Lattner | c5d7d7c | 2006-05-17 18:00:08 +0000 | [diff] [blame] | 787 | |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 788 | Result = DAG.UpdateNodeOperands(Result.getValue(0), &Ops[0], Ops.size()); |
Chris Lattner | d73cc5d | 2005-05-14 06:34:48 +0000 | [diff] [blame] | 789 | |
| 790 | for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) |
| 791 | AddLegalizedOperand(Op.getValue(i), Result.getValue(i)); |
| 792 | return Result.getValue(Op.ResNo); |
| 793 | } |
| 794 | // Otherwise this is an unhandled builtin node. splat. |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 795 | #ifndef NDEBUG |
Dan Gohman | 3983358 | 2007-06-04 16:17:33 +0000 | [diff] [blame] | 796 | cerr << "NODE: "; Node->dump(&DAG); cerr << "\n"; |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 797 | #endif |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 798 | assert(0 && "Do not know how to legalize this operator!"); |
| 799 | abort(); |
Lauro Ramos Venancio | 0d3b678 | 2007-04-20 23:02:39 +0000 | [diff] [blame] | 800 | case ISD::GLOBAL_OFFSET_TABLE: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 801 | case ISD::GlobalAddress: |
Lauro Ramos Venancio | b3a0417 | 2007-04-20 21:38:10 +0000 | [diff] [blame] | 802 | case ISD::GlobalTLSAddress: |
Chris Lattner | 03c0cf8 | 2005-01-07 21:45:56 +0000 | [diff] [blame] | 803 | case ISD::ExternalSymbol: |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 804 | case ISD::ConstantPool: |
| 805 | case ISD::JumpTable: // Nothing to do. |
Chris Lattner | 0c8fbe3 | 2005-11-17 06:41:44 +0000 | [diff] [blame] | 806 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 807 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 808 | case TargetLowering::Custom: |
| 809 | Tmp1 = TLI.LowerOperation(Op, DAG); |
| 810 | if (Tmp1.Val) Result = Tmp1; |
| 811 | // 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] | 812 | case TargetLowering::Legal: |
Chris Lattner | 0c8fbe3 | 2005-11-17 06:41:44 +0000 | [diff] [blame] | 813 | break; |
| 814 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 815 | break; |
Nate Begeman | bcc5f36 | 2007-01-29 22:58:52 +0000 | [diff] [blame] | 816 | case ISD::FRAMEADDR: |
| 817 | case ISD::RETURNADDR: |
| 818 | // The only option for these nodes is to custom lower them. If the target |
| 819 | // does not custom lower them, then return zero. |
| 820 | Tmp1 = TLI.LowerOperation(Op, DAG); |
| 821 | if (Tmp1.Val) |
| 822 | Result = Tmp1; |
| 823 | else |
| 824 | Result = DAG.getConstant(0, TLI.getPointerTy()); |
| 825 | break; |
Anton Korobeynikov | 055c544 | 2007-08-29 23:18:48 +0000 | [diff] [blame] | 826 | case ISD::FRAME_TO_ARGS_OFFSET: { |
Anton Korobeynikov | 066f7b4 | 2007-08-29 19:28:29 +0000 | [diff] [blame] | 827 | MVT::ValueType VT = Node->getValueType(0); |
| 828 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 829 | default: assert(0 && "This action is not supported yet!"); |
| 830 | case TargetLowering::Custom: |
| 831 | Result = TLI.LowerOperation(Op, DAG); |
| 832 | if (Result.Val) break; |
| 833 | // Fall Thru |
| 834 | case TargetLowering::Legal: |
| 835 | Result = DAG.getConstant(0, VT); |
| 836 | break; |
| 837 | } |
Anton Korobeynikov | 055c544 | 2007-08-29 23:18:48 +0000 | [diff] [blame] | 838 | } |
Anton Korobeynikov | 066f7b4 | 2007-08-29 19:28:29 +0000 | [diff] [blame] | 839 | break; |
Jim Laskey | 2bc210d | 2007-02-22 15:37:19 +0000 | [diff] [blame] | 840 | case ISD::EXCEPTIONADDR: { |
| 841 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 842 | MVT::ValueType VT = Node->getValueType(0); |
| 843 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 844 | default: assert(0 && "This action is not supported yet!"); |
| 845 | case TargetLowering::Expand: { |
Jim Laskey | 8782d48 | 2007-02-28 20:43:58 +0000 | [diff] [blame] | 846 | unsigned Reg = TLI.getExceptionAddressRegister(); |
Jim Laskey | 2bc210d | 2007-02-22 15:37:19 +0000 | [diff] [blame] | 847 | Result = DAG.getCopyFromReg(Tmp1, Reg, VT).getValue(Op.ResNo); |
| 848 | } |
| 849 | break; |
| 850 | case TargetLowering::Custom: |
| 851 | Result = TLI.LowerOperation(Op, DAG); |
| 852 | if (Result.Val) break; |
| 853 | // Fall Thru |
Chris Lattner | eb7f34f | 2007-04-27 17:12:52 +0000 | [diff] [blame] | 854 | case TargetLowering::Legal: { |
| 855 | SDOperand Ops[] = { DAG.getConstant(0, VT), Tmp1 }; |
| 856 | Result = DAG.getNode(ISD::MERGE_VALUES, DAG.getVTList(VT, MVT::Other), |
| 857 | Ops, 2).getValue(Op.ResNo); |
Jim Laskey | 2bc210d | 2007-02-22 15:37:19 +0000 | [diff] [blame] | 858 | break; |
| 859 | } |
| 860 | } |
Chris Lattner | eb7f34f | 2007-04-27 17:12:52 +0000 | [diff] [blame] | 861 | } |
Jim Laskey | 2bc210d | 2007-02-22 15:37:19 +0000 | [diff] [blame] | 862 | break; |
Jim Laskey | 8782d48 | 2007-02-28 20:43:58 +0000 | [diff] [blame] | 863 | case ISD::EHSELECTION: { |
| 864 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 865 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 866 | MVT::ValueType VT = Node->getValueType(0); |
| 867 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 868 | default: assert(0 && "This action is not supported yet!"); |
| 869 | case TargetLowering::Expand: { |
| 870 | unsigned Reg = TLI.getExceptionSelectorRegister(); |
| 871 | Result = DAG.getCopyFromReg(Tmp2, Reg, VT).getValue(Op.ResNo); |
| 872 | } |
| 873 | break; |
| 874 | case TargetLowering::Custom: |
| 875 | Result = TLI.LowerOperation(Op, DAG); |
| 876 | if (Result.Val) break; |
| 877 | // Fall Thru |
Chris Lattner | eb7f34f | 2007-04-27 17:12:52 +0000 | [diff] [blame] | 878 | case TargetLowering::Legal: { |
| 879 | SDOperand Ops[] = { DAG.getConstant(0, VT), Tmp2 }; |
| 880 | Result = DAG.getNode(ISD::MERGE_VALUES, DAG.getVTList(VT, MVT::Other), |
| 881 | Ops, 2).getValue(Op.ResNo); |
Jim Laskey | 8782d48 | 2007-02-28 20:43:58 +0000 | [diff] [blame] | 882 | break; |
| 883 | } |
| 884 | } |
Chris Lattner | eb7f34f | 2007-04-27 17:12:52 +0000 | [diff] [blame] | 885 | } |
Jim Laskey | 8782d48 | 2007-02-28 20:43:58 +0000 | [diff] [blame] | 886 | break; |
Nick Lewycky | 6d4b711 | 2007-07-14 15:11:14 +0000 | [diff] [blame] | 887 | case ISD::EH_RETURN: { |
Anton Korobeynikov | 2365f51 | 2007-07-14 14:06:15 +0000 | [diff] [blame] | 888 | MVT::ValueType VT = Node->getValueType(0); |
| 889 | // The only "good" option for this node is to custom lower it. |
| 890 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 891 | default: assert(0 && "This action is not supported at all!"); |
| 892 | case TargetLowering::Custom: |
| 893 | Result = TLI.LowerOperation(Op, DAG); |
| 894 | if (Result.Val) break; |
| 895 | // Fall Thru |
| 896 | case TargetLowering::Legal: |
| 897 | // Target does not know, how to lower this, lower to noop |
| 898 | Result = LegalizeOp(Node->getOperand(0)); |
| 899 | break; |
| 900 | } |
Nick Lewycky | 6d4b711 | 2007-07-14 15:11:14 +0000 | [diff] [blame] | 901 | } |
Anton Korobeynikov | 2365f51 | 2007-07-14 14:06:15 +0000 | [diff] [blame] | 902 | break; |
Chris Lattner | 08951a3 | 2005-09-02 01:15:01 +0000 | [diff] [blame] | 903 | case ISD::AssertSext: |
| 904 | case ISD::AssertZext: |
| 905 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 906 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
Chris Lattner | 08951a3 | 2005-09-02 01:15:01 +0000 | [diff] [blame] | 907 | break; |
Chris Lattner | 308575b | 2005-11-20 22:56:56 +0000 | [diff] [blame] | 908 | case ISD::MERGE_VALUES: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 909 | // Legalize eliminates MERGE_VALUES nodes. |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 910 | Result = Node->getOperand(Op.ResNo); |
| 911 | break; |
Chris Lattner | 69a5215 | 2005-01-14 22:38:01 +0000 | [diff] [blame] | 912 | case ISD::CopyFromReg: |
| 913 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 914 | Result = Op.getValue(0); |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 915 | if (Node->getNumValues() == 2) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 916 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 917 | } else { |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 918 | assert(Node->getNumValues() == 3 && "Invalid copyfromreg!"); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 919 | if (Node->getNumOperands() == 3) { |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 920 | Tmp2 = LegalizeOp(Node->getOperand(2)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 921 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1),Tmp2); |
| 922 | } else { |
| 923 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
| 924 | } |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 925 | AddLegalizedOperand(Op.getValue(2), Result.getValue(2)); |
| 926 | } |
Chris Lattner | 13c184d | 2005-01-28 06:27:38 +0000 | [diff] [blame] | 927 | // Since CopyFromReg produces two values, make sure to remember that we |
| 928 | // legalized both of them. |
| 929 | AddLegalizedOperand(Op.getValue(0), Result); |
| 930 | AddLegalizedOperand(Op.getValue(1), Result.getValue(1)); |
| 931 | return Result.getValue(Op.ResNo); |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 932 | case ISD::UNDEF: { |
| 933 | MVT::ValueType VT = Op.getValueType(); |
| 934 | switch (TLI.getOperationAction(ISD::UNDEF, VT)) { |
Nate Begeman | ea19cd5 | 2005-04-02 00:41:14 +0000 | [diff] [blame] | 935 | default: assert(0 && "This action is not supported yet!"); |
| 936 | case TargetLowering::Expand: |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 937 | if (MVT::isInteger(VT)) |
| 938 | Result = DAG.getConstant(0, VT); |
| 939 | else if (MVT::isFloatingPoint(VT)) |
Dale Johannesen | f41db21 | 2007-09-26 17:26:49 +0000 | [diff] [blame] | 940 | Result = DAG.getConstantFP(APFloat(APInt(MVT::getSizeInBits(VT), 0)), |
| 941 | VT); |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 942 | else |
| 943 | assert(0 && "Unknown value type!"); |
| 944 | break; |
Nate Begeman | ea19cd5 | 2005-04-02 00:41:14 +0000 | [diff] [blame] | 945 | case TargetLowering::Legal: |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 946 | break; |
| 947 | } |
| 948 | break; |
| 949 | } |
Chris Lattner | d1f04d4 | 2006-03-24 02:26:29 +0000 | [diff] [blame] | 950 | |
Chris Lattner | 48b61a7 | 2006-03-28 00:40:33 +0000 | [diff] [blame] | 951 | case ISD::INTRINSIC_W_CHAIN: |
| 952 | case ISD::INTRINSIC_WO_CHAIN: |
| 953 | case ISD::INTRINSIC_VOID: { |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 954 | SmallVector<SDOperand, 8> Ops; |
Chris Lattner | d1f04d4 | 2006-03-24 02:26:29 +0000 | [diff] [blame] | 955 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) |
| 956 | Ops.push_back(LegalizeOp(Node->getOperand(i))); |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 957 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 10d7fa6 | 2006-03-26 09:12:51 +0000 | [diff] [blame] | 958 | |
| 959 | // Allow the target to custom lower its intrinsics if it wants to. |
Chris Lattner | 48b61a7 | 2006-03-28 00:40:33 +0000 | [diff] [blame] | 960 | if (TLI.getOperationAction(Node->getOpcode(), MVT::Other) == |
Chris Lattner | 10d7fa6 | 2006-03-26 09:12:51 +0000 | [diff] [blame] | 961 | TargetLowering::Custom) { |
| 962 | Tmp3 = TLI.LowerOperation(Result, DAG); |
| 963 | if (Tmp3.Val) Result = Tmp3; |
Chris Lattner | 13fc2f1 | 2006-03-27 20:28:29 +0000 | [diff] [blame] | 964 | } |
| 965 | |
| 966 | if (Result.Val->getNumValues() == 1) break; |
| 967 | |
| 968 | // Must have return value and chain result. |
| 969 | assert(Result.Val->getNumValues() == 2 && |
| 970 | "Cannot return more than two values!"); |
| 971 | |
| 972 | // Since loads produce two values, make sure to remember that we |
| 973 | // legalized both of them. |
| 974 | AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0)); |
| 975 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
| 976 | return Result.getValue(Op.ResNo); |
Chris Lattner | d1f04d4 | 2006-03-24 02:26:29 +0000 | [diff] [blame] | 977 | } |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 978 | |
| 979 | case ISD::LOCATION: |
| 980 | assert(Node->getNumOperands() == 5 && "Invalid LOCATION node!"); |
| 981 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the input chain. |
| 982 | |
| 983 | switch (TLI.getOperationAction(ISD::LOCATION, MVT::Other)) { |
| 984 | case TargetLowering::Promote: |
| 985 | default: assert(0 && "This action is not supported yet!"); |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 986 | case TargetLowering::Expand: { |
Jim Laskey | 44c3b9f | 2007-01-26 21:22:28 +0000 | [diff] [blame] | 987 | MachineModuleInfo *MMI = DAG.getMachineModuleInfo(); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 988 | bool useDEBUG_LOC = TLI.isOperationLegal(ISD::DEBUG_LOC, MVT::Other); |
Jim Laskey | 1ee2925 | 2007-01-26 14:34:52 +0000 | [diff] [blame] | 989 | bool useLABEL = TLI.isOperationLegal(ISD::LABEL, MVT::Other); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 990 | |
Jim Laskey | 44c3b9f | 2007-01-26 21:22:28 +0000 | [diff] [blame] | 991 | if (MMI && (useDEBUG_LOC || useLABEL)) { |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 992 | const std::string &FName = |
| 993 | cast<StringSDNode>(Node->getOperand(3))->getValue(); |
| 994 | const std::string &DirName = |
| 995 | cast<StringSDNode>(Node->getOperand(4))->getValue(); |
Jim Laskey | 44c3b9f | 2007-01-26 21:22:28 +0000 | [diff] [blame] | 996 | unsigned SrcFile = MMI->RecordSource(DirName, FName); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 997 | |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 998 | SmallVector<SDOperand, 8> Ops; |
Jim Laskey | e81aecb | 2005-12-21 20:51:37 +0000 | [diff] [blame] | 999 | Ops.push_back(Tmp1); // chain |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1000 | SDOperand LineOp = Node->getOperand(1); |
| 1001 | SDOperand ColOp = Node->getOperand(2); |
| 1002 | |
| 1003 | if (useDEBUG_LOC) { |
| 1004 | Ops.push_back(LineOp); // line # |
| 1005 | Ops.push_back(ColOp); // col # |
| 1006 | Ops.push_back(DAG.getConstant(SrcFile, MVT::i32)); // source file id |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 1007 | Result = DAG.getNode(ISD::DEBUG_LOC, MVT::Other, &Ops[0], Ops.size()); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1008 | } else { |
Jim Laskey | d0e58e3 | 2006-02-15 19:34:44 +0000 | [diff] [blame] | 1009 | unsigned Line = cast<ConstantSDNode>(LineOp)->getValue(); |
| 1010 | unsigned Col = cast<ConstantSDNode>(ColOp)->getValue(); |
Jim Laskey | 44c3b9f | 2007-01-26 21:22:28 +0000 | [diff] [blame] | 1011 | unsigned ID = MMI->RecordLabel(Line, Col, SrcFile); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1012 | Ops.push_back(DAG.getConstant(ID, MVT::i32)); |
Jim Laskey | 1ee2925 | 2007-01-26 14:34:52 +0000 | [diff] [blame] | 1013 | Result = DAG.getNode(ISD::LABEL, MVT::Other,&Ops[0],Ops.size()); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1014 | } |
Jim Laskey | e81aecb | 2005-12-21 20:51:37 +0000 | [diff] [blame] | 1015 | } else { |
| 1016 | Result = Tmp1; // chain |
| 1017 | } |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 1018 | break; |
Chris Lattner | e773673 | 2005-12-18 23:54:29 +0000 | [diff] [blame] | 1019 | } |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 1020 | case TargetLowering::Legal: |
Chris Lattner | 9ad17c9 | 2005-12-01 18:21:35 +0000 | [diff] [blame] | 1021 | if (Tmp1 != Node->getOperand(0) || |
| 1022 | getTypeAction(Node->getOperand(1).getValueType()) == Promote) { |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1023 | SmallVector<SDOperand, 8> Ops; |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 1024 | Ops.push_back(Tmp1); |
Chris Lattner | 9ad17c9 | 2005-12-01 18:21:35 +0000 | [diff] [blame] | 1025 | if (getTypeAction(Node->getOperand(1).getValueType()) == Legal) { |
| 1026 | Ops.push_back(Node->getOperand(1)); // line # must be legal. |
| 1027 | Ops.push_back(Node->getOperand(2)); // col # must be legal. |
| 1028 | } else { |
| 1029 | // Otherwise promote them. |
| 1030 | Ops.push_back(PromoteOp(Node->getOperand(1))); |
| 1031 | Ops.push_back(PromoteOp(Node->getOperand(2))); |
| 1032 | } |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 1033 | Ops.push_back(Node->getOperand(3)); // filename must be legal. |
| 1034 | Ops.push_back(Node->getOperand(4)); // working dir # must be legal. |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1035 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 1036 | } |
| 1037 | break; |
| 1038 | } |
| 1039 | break; |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 1040 | |
| 1041 | case ISD::DEBUG_LOC: |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1042 | assert(Node->getNumOperands() == 4 && "Invalid DEBUG_LOC node!"); |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 1043 | switch (TLI.getOperationAction(ISD::DEBUG_LOC, MVT::Other)) { |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 1044 | default: assert(0 && "This action is not supported yet!"); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1045 | case TargetLowering::Legal: |
| 1046 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1047 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the line #. |
| 1048 | Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the col #. |
| 1049 | Tmp4 = LegalizeOp(Node->getOperand(3)); // Legalize the source file id. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1050 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3, Tmp4); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1051 | break; |
| 1052 | } |
| 1053 | break; |
| 1054 | |
Jim Laskey | 1ee2925 | 2007-01-26 14:34:52 +0000 | [diff] [blame] | 1055 | case ISD::LABEL: |
| 1056 | assert(Node->getNumOperands() == 2 && "Invalid LABEL node!"); |
| 1057 | switch (TLI.getOperationAction(ISD::LABEL, MVT::Other)) { |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1058 | default: assert(0 && "This action is not supported yet!"); |
| 1059 | case TargetLowering::Legal: |
| 1060 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1061 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the label id. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1062 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 1063 | break; |
Chris Lattner | a9569f1 | 2007-03-03 19:21:38 +0000 | [diff] [blame] | 1064 | case TargetLowering::Expand: |
| 1065 | Result = LegalizeOp(Node->getOperand(0)); |
| 1066 | break; |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 1067 | } |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 1068 | break; |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 1069 | |
Scott Michel | c1513d2 | 2007-08-08 23:23:31 +0000 | [diff] [blame] | 1070 | case ISD::Constant: { |
| 1071 | ConstantSDNode *CN = cast<ConstantSDNode>(Node); |
| 1072 | unsigned opAction = |
| 1073 | TLI.getOperationAction(ISD::Constant, CN->getValueType(0)); |
| 1074 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1075 | // We know we don't need to expand constants here, constants only have one |
| 1076 | // value and we check that it is fine above. |
| 1077 | |
Scott Michel | c1513d2 | 2007-08-08 23:23:31 +0000 | [diff] [blame] | 1078 | if (opAction == TargetLowering::Custom) { |
| 1079 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 1080 | if (Tmp1.Val) |
| 1081 | Result = Tmp1; |
| 1082 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1083 | break; |
Scott Michel | c1513d2 | 2007-08-08 23:23:31 +0000 | [diff] [blame] | 1084 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1085 | case ISD::ConstantFP: { |
| 1086 | // Spill FP immediates to the constant pool if the target cannot directly |
| 1087 | // codegen them. Targets often have some immediate values that can be |
| 1088 | // efficiently generated into an FP register without a load. We explicitly |
| 1089 | // leave these constants as ConstantFP nodes for the target to deal with. |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1090 | ConstantFPSDNode *CFP = cast<ConstantFPSDNode>(Node); |
| 1091 | |
| 1092 | // Check to see if this FP immediate is already legal. |
| 1093 | bool isLegal = false; |
| 1094 | for (TargetLowering::legal_fpimm_iterator I = TLI.legal_fpimm_begin(), |
| 1095 | E = TLI.legal_fpimm_end(); I != E; ++I) |
| 1096 | if (CFP->isExactlyValue(*I)) { |
| 1097 | isLegal = true; |
| 1098 | break; |
| 1099 | } |
| 1100 | |
Chris Lattner | 3181a77 | 2006-01-29 06:26:56 +0000 | [diff] [blame] | 1101 | // If this is a legal constant, turn it into a TargetConstantFP node. |
| 1102 | if (isLegal) { |
Dale Johannesen | f04afdb | 2007-08-30 00:23:21 +0000 | [diff] [blame] | 1103 | Result = DAG.getTargetConstantFP(CFP->getValueAPF(), |
| 1104 | CFP->getValueType(0)); |
Chris Lattner | 3181a77 | 2006-01-29 06:26:56 +0000 | [diff] [blame] | 1105 | break; |
| 1106 | } |
| 1107 | |
| 1108 | switch (TLI.getOperationAction(ISD::ConstantFP, CFP->getValueType(0))) { |
| 1109 | default: assert(0 && "This action is not supported yet!"); |
| 1110 | case TargetLowering::Custom: |
| 1111 | Tmp3 = TLI.LowerOperation(Result, DAG); |
| 1112 | if (Tmp3.Val) { |
| 1113 | Result = Tmp3; |
| 1114 | break; |
| 1115 | } |
| 1116 | // FALLTHROUGH |
| 1117 | case TargetLowering::Expand: |
Evan Cheng | 279101e | 2006-12-12 22:19:28 +0000 | [diff] [blame] | 1118 | Result = ExpandConstantFP(CFP, true, DAG, TLI); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1119 | } |
| 1120 | break; |
| 1121 | } |
Chris Lattner | 040c11c | 2005-11-09 18:48:57 +0000 | [diff] [blame] | 1122 | case ISD::TokenFactor: |
| 1123 | if (Node->getNumOperands() == 2) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1124 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1125 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1126 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 1127 | } else if (Node->getNumOperands() == 3) { |
| 1128 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1129 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1130 | Tmp3 = LegalizeOp(Node->getOperand(2)); |
| 1131 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | 040c11c | 2005-11-09 18:48:57 +0000 | [diff] [blame] | 1132 | } else { |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1133 | SmallVector<SDOperand, 8> Ops; |
Chris Lattner | 040c11c | 2005-11-09 18:48:57 +0000 | [diff] [blame] | 1134 | // Legalize the operands. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1135 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) |
| 1136 | Ops.push_back(LegalizeOp(Node->getOperand(i))); |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1137 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | a385e9b | 2005-01-13 17:59:25 +0000 | [diff] [blame] | 1138 | } |
Chris Lattner | a385e9b | 2005-01-13 17:59:25 +0000 | [diff] [blame] | 1139 | break; |
Chris Lattner | fdfded5 | 2006-04-12 16:20:43 +0000 | [diff] [blame] | 1140 | |
| 1141 | case ISD::FORMAL_ARGUMENTS: |
Chris Lattner | f4ec817 | 2006-05-16 22:53:20 +0000 | [diff] [blame] | 1142 | case ISD::CALL: |
Chris Lattner | fdfded5 | 2006-04-12 16:20:43 +0000 | [diff] [blame] | 1143 | // The only option for this is to custom lower it. |
Chris Lattner | b248e16 | 2006-05-17 17:55:45 +0000 | [diff] [blame] | 1144 | Tmp3 = TLI.LowerOperation(Result.getValue(0), DAG); |
| 1145 | assert(Tmp3.Val && "Target didn't custom lower this node!"); |
| 1146 | assert(Tmp3.Val->getNumValues() == Result.Val->getNumValues() && |
| 1147 | "Lowering call/formal_arguments produced unexpected # results!"); |
Chris Lattner | e2e4173 | 2006-05-16 05:49:56 +0000 | [diff] [blame] | 1148 | |
Chris Lattner | f4ec817 | 2006-05-16 22:53:20 +0000 | [diff] [blame] | 1149 | // Since CALL/FORMAL_ARGUMENTS nodes produce multiple values, make sure to |
Chris Lattner | e2e4173 | 2006-05-16 05:49:56 +0000 | [diff] [blame] | 1150 | // 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] | 1151 | for (unsigned i = 0, e = Tmp3.Val->getNumValues(); i != e; ++i) { |
| 1152 | Tmp1 = LegalizeOp(Tmp3.getValue(i)); |
Chris Lattner | e2e4173 | 2006-05-16 05:49:56 +0000 | [diff] [blame] | 1153 | if (Op.ResNo == i) |
| 1154 | Tmp2 = Tmp1; |
| 1155 | AddLegalizedOperand(SDOperand(Node, i), Tmp1); |
| 1156 | } |
| 1157 | return Tmp2; |
Christopher Lamb | 557c363 | 2007-07-26 07:34:40 +0000 | [diff] [blame] | 1158 | case ISD::EXTRACT_SUBREG: { |
| 1159 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1160 | ConstantSDNode *idx = dyn_cast<ConstantSDNode>(Node->getOperand(1)); |
| 1161 | assert(idx && "Operand must be a constant"); |
| 1162 | Tmp2 = DAG.getTargetConstant(idx->getValue(), idx->getValueType(0)); |
| 1163 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 1164 | } |
| 1165 | break; |
| 1166 | case ISD::INSERT_SUBREG: { |
| 1167 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1168 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1169 | ConstantSDNode *idx = dyn_cast<ConstantSDNode>(Node->getOperand(2)); |
| 1170 | assert(idx && "Operand must be a constant"); |
| 1171 | Tmp3 = DAG.getTargetConstant(idx->getValue(), idx->getValueType(0)); |
| 1172 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
| 1173 | } |
| 1174 | break; |
Chris Lattner | b2827b0 | 2006-03-19 00:52:58 +0000 | [diff] [blame] | 1175 | case ISD::BUILD_VECTOR: |
| 1176 | switch (TLI.getOperationAction(ISD::BUILD_VECTOR, Node->getValueType(0))) { |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1177 | default: assert(0 && "This action is not supported yet!"); |
| 1178 | case TargetLowering::Custom: |
| 1179 | Tmp3 = TLI.LowerOperation(Result, DAG); |
| 1180 | if (Tmp3.Val) { |
| 1181 | Result = Tmp3; |
| 1182 | break; |
| 1183 | } |
| 1184 | // FALLTHROUGH |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 1185 | case TargetLowering::Expand: |
| 1186 | Result = ExpandBUILD_VECTOR(Result.Val); |
Chris Lattner | b2827b0 | 2006-03-19 00:52:58 +0000 | [diff] [blame] | 1187 | break; |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1188 | } |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1189 | break; |
| 1190 | case ISD::INSERT_VECTOR_ELT: |
| 1191 | Tmp1 = LegalizeOp(Node->getOperand(0)); // InVec |
| 1192 | Tmp2 = LegalizeOp(Node->getOperand(1)); // InVal |
| 1193 | Tmp3 = LegalizeOp(Node->getOperand(2)); // InEltNo |
| 1194 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
| 1195 | |
| 1196 | switch (TLI.getOperationAction(ISD::INSERT_VECTOR_ELT, |
| 1197 | Node->getValueType(0))) { |
| 1198 | default: assert(0 && "This action is not supported yet!"); |
| 1199 | case TargetLowering::Legal: |
| 1200 | break; |
| 1201 | case TargetLowering::Custom: |
| 1202 | Tmp3 = TLI.LowerOperation(Result, DAG); |
| 1203 | if (Tmp3.Val) { |
| 1204 | Result = Tmp3; |
| 1205 | break; |
| 1206 | } |
| 1207 | // FALLTHROUGH |
| 1208 | case TargetLowering::Expand: { |
Chris Lattner | 8d5a894 | 2006-04-17 19:21:01 +0000 | [diff] [blame] | 1209 | // If the insert index is a constant, codegen this as a scalar_to_vector, |
| 1210 | // then a shuffle that inserts it into the right position in the vector. |
| 1211 | if (ConstantSDNode *InsertPos = dyn_cast<ConstantSDNode>(Tmp3)) { |
| 1212 | SDOperand ScVec = DAG.getNode(ISD::SCALAR_TO_VECTOR, |
| 1213 | Tmp1.getValueType(), Tmp2); |
| 1214 | |
| 1215 | unsigned NumElts = MVT::getVectorNumElements(Tmp1.getValueType()); |
| 1216 | MVT::ValueType ShufMaskVT = MVT::getIntVectorWithNumElements(NumElts); |
Dan Gohman | 51eaa86 | 2007-06-14 22:58:02 +0000 | [diff] [blame] | 1217 | MVT::ValueType ShufMaskEltVT = MVT::getVectorElementType(ShufMaskVT); |
Chris Lattner | 8d5a894 | 2006-04-17 19:21:01 +0000 | [diff] [blame] | 1218 | |
| 1219 | // We generate a shuffle of InVec and ScVec, so the shuffle mask should |
| 1220 | // be 0,1,2,3,4,5... with the appropriate element replaced with elt 0 of |
| 1221 | // the RHS. |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 1222 | SmallVector<SDOperand, 8> ShufOps; |
Chris Lattner | 8d5a894 | 2006-04-17 19:21:01 +0000 | [diff] [blame] | 1223 | for (unsigned i = 0; i != NumElts; ++i) { |
| 1224 | if (i != InsertPos->getValue()) |
| 1225 | ShufOps.push_back(DAG.getConstant(i, ShufMaskEltVT)); |
| 1226 | else |
| 1227 | ShufOps.push_back(DAG.getConstant(NumElts, ShufMaskEltVT)); |
| 1228 | } |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 1229 | SDOperand ShufMask = DAG.getNode(ISD::BUILD_VECTOR, ShufMaskVT, |
| 1230 | &ShufOps[0], ShufOps.size()); |
Chris Lattner | 8d5a894 | 2006-04-17 19:21:01 +0000 | [diff] [blame] | 1231 | |
| 1232 | Result = DAG.getNode(ISD::VECTOR_SHUFFLE, Tmp1.getValueType(), |
| 1233 | Tmp1, ScVec, ShufMask); |
| 1234 | Result = LegalizeOp(Result); |
| 1235 | break; |
| 1236 | } |
| 1237 | |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1238 | // If the target doesn't support this, we have to spill the input vector |
| 1239 | // to a temporary stack slot, update the element, then reload it. This is |
| 1240 | // badness. We could also load the value into a vector register (either |
| 1241 | // with a "move to register" or "extload into register" instruction, then |
| 1242 | // permute it into place, if the idx is a constant and if the idx is |
| 1243 | // supported by the target. |
Evan Cheng | f6bf87f | 2006-04-08 01:46:37 +0000 | [diff] [blame] | 1244 | MVT::ValueType VT = Tmp1.getValueType(); |
| 1245 | MVT::ValueType EltVT = Tmp2.getValueType(); |
| 1246 | MVT::ValueType IdxVT = Tmp3.getValueType(); |
| 1247 | MVT::ValueType PtrVT = TLI.getPointerTy(); |
Chris Lattner | 85dd3be | 2007-10-15 17:48:57 +0000 | [diff] [blame] | 1248 | SDOperand StackPtr = DAG.CreateStackTemporary(VT); |
Evan Cheng | eb0b461 | 2006-03-31 01:27:51 +0000 | [diff] [blame] | 1249 | // Store the vector. |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 1250 | SDOperand Ch = DAG.getStore(DAG.getEntryNode(), Tmp1, StackPtr, NULL, 0); |
Evan Cheng | eb0b461 | 2006-03-31 01:27:51 +0000 | [diff] [blame] | 1251 | |
| 1252 | // Truncate or zero extend offset to target pointer type. |
Evan Cheng | f6bf87f | 2006-04-08 01:46:37 +0000 | [diff] [blame] | 1253 | unsigned CastOpc = (IdxVT > PtrVT) ? ISD::TRUNCATE : ISD::ZERO_EXTEND; |
| 1254 | Tmp3 = DAG.getNode(CastOpc, PtrVT, Tmp3); |
Evan Cheng | eb0b461 | 2006-03-31 01:27:51 +0000 | [diff] [blame] | 1255 | // Add the offset to the index. |
Evan Cheng | f6bf87f | 2006-04-08 01:46:37 +0000 | [diff] [blame] | 1256 | unsigned EltSize = MVT::getSizeInBits(EltVT)/8; |
| 1257 | Tmp3 = DAG.getNode(ISD::MUL, IdxVT, Tmp3,DAG.getConstant(EltSize, IdxVT)); |
| 1258 | SDOperand StackPtr2 = DAG.getNode(ISD::ADD, IdxVT, Tmp3, StackPtr); |
Evan Cheng | eb0b461 | 2006-03-31 01:27:51 +0000 | [diff] [blame] | 1259 | // Store the scalar value. |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 1260 | Ch = DAG.getStore(Ch, Tmp2, StackPtr2, NULL, 0); |
Evan Cheng | eb0b461 | 2006-03-31 01:27:51 +0000 | [diff] [blame] | 1261 | // Load the updated vector. |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1262 | Result = DAG.getLoad(VT, Ch, StackPtr, NULL, 0); |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1263 | break; |
| 1264 | } |
| 1265 | } |
| 1266 | break; |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 1267 | case ISD::SCALAR_TO_VECTOR: |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 1268 | if (!TLI.isTypeLegal(Node->getOperand(0).getValueType())) { |
| 1269 | Result = LegalizeOp(ExpandSCALAR_TO_VECTOR(Node)); |
| 1270 | break; |
| 1271 | } |
| 1272 | |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 1273 | Tmp1 = LegalizeOp(Node->getOperand(0)); // InVal |
| 1274 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 1275 | switch (TLI.getOperationAction(ISD::SCALAR_TO_VECTOR, |
| 1276 | Node->getValueType(0))) { |
| 1277 | default: assert(0 && "This action is not supported yet!"); |
| 1278 | case TargetLowering::Legal: |
| 1279 | break; |
Chris Lattner | 4d3abee | 2006-03-19 06:47:21 +0000 | [diff] [blame] | 1280 | case TargetLowering::Custom: |
| 1281 | Tmp3 = TLI.LowerOperation(Result, DAG); |
| 1282 | if (Tmp3.Val) { |
| 1283 | Result = Tmp3; |
| 1284 | break; |
| 1285 | } |
| 1286 | // FALLTHROUGH |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 1287 | case TargetLowering::Expand: |
| 1288 | Result = LegalizeOp(ExpandSCALAR_TO_VECTOR(Node)); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 1289 | break; |
| 1290 | } |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 1291 | break; |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 1292 | case ISD::VECTOR_SHUFFLE: |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 1293 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the input vectors, |
| 1294 | Tmp2 = LegalizeOp(Node->getOperand(1)); // but not the shuffle mask. |
| 1295 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
| 1296 | |
| 1297 | // Allow targets to custom lower the SHUFFLEs they support. |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 1298 | switch (TLI.getOperationAction(ISD::VECTOR_SHUFFLE,Result.getValueType())) { |
| 1299 | default: assert(0 && "Unknown operation action!"); |
| 1300 | case TargetLowering::Legal: |
| 1301 | assert(isShuffleLegal(Result.getValueType(), Node->getOperand(2)) && |
| 1302 | "vector shuffle should not be created if not legal!"); |
| 1303 | break; |
| 1304 | case TargetLowering::Custom: |
Evan Cheng | 18dd6d0 | 2006-04-05 06:07:11 +0000 | [diff] [blame] | 1305 | Tmp3 = TLI.LowerOperation(Result, DAG); |
| 1306 | if (Tmp3.Val) { |
| 1307 | Result = Tmp3; |
| 1308 | break; |
| 1309 | } |
| 1310 | // FALLTHROUGH |
| 1311 | case TargetLowering::Expand: { |
| 1312 | MVT::ValueType VT = Node->getValueType(0); |
Dan Gohman | 51eaa86 | 2007-06-14 22:58:02 +0000 | [diff] [blame] | 1313 | MVT::ValueType EltVT = MVT::getVectorElementType(VT); |
Evan Cheng | 18dd6d0 | 2006-04-05 06:07:11 +0000 | [diff] [blame] | 1314 | MVT::ValueType PtrVT = TLI.getPointerTy(); |
| 1315 | SDOperand Mask = Node->getOperand(2); |
| 1316 | unsigned NumElems = Mask.getNumOperands(); |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 1317 | SmallVector<SDOperand,8> Ops; |
Evan Cheng | 18dd6d0 | 2006-04-05 06:07:11 +0000 | [diff] [blame] | 1318 | for (unsigned i = 0; i != NumElems; ++i) { |
| 1319 | SDOperand Arg = Mask.getOperand(i); |
| 1320 | if (Arg.getOpcode() == ISD::UNDEF) { |
| 1321 | Ops.push_back(DAG.getNode(ISD::UNDEF, EltVT)); |
| 1322 | } else { |
| 1323 | assert(isa<ConstantSDNode>(Arg) && "Invalid VECTOR_SHUFFLE mask!"); |
| 1324 | unsigned Idx = cast<ConstantSDNode>(Arg)->getValue(); |
| 1325 | if (Idx < NumElems) |
| 1326 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, EltVT, Tmp1, |
| 1327 | DAG.getConstant(Idx, PtrVT))); |
| 1328 | else |
| 1329 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, EltVT, Tmp2, |
| 1330 | DAG.getConstant(Idx - NumElems, PtrVT))); |
| 1331 | } |
| 1332 | } |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 1333 | Result = DAG.getNode(ISD::BUILD_VECTOR, VT, &Ops[0], Ops.size()); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 1334 | break; |
Evan Cheng | 18dd6d0 | 2006-04-05 06:07:11 +0000 | [diff] [blame] | 1335 | } |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 1336 | case TargetLowering::Promote: { |
| 1337 | // Change base type to a different vector type. |
| 1338 | MVT::ValueType OVT = Node->getValueType(0); |
| 1339 | MVT::ValueType NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT); |
| 1340 | |
| 1341 | // Cast the two input vectors. |
| 1342 | Tmp1 = DAG.getNode(ISD::BIT_CONVERT, NVT, Tmp1); |
| 1343 | Tmp2 = DAG.getNode(ISD::BIT_CONVERT, NVT, Tmp2); |
| 1344 | |
| 1345 | // Convert the shuffle mask to the right # elements. |
| 1346 | Tmp3 = SDOperand(isShuffleLegal(OVT, Node->getOperand(2)), 0); |
| 1347 | assert(Tmp3.Val && "Shuffle not legal?"); |
| 1348 | Result = DAG.getNode(ISD::VECTOR_SHUFFLE, NVT, Tmp1, Tmp2, Tmp3); |
| 1349 | Result = DAG.getNode(ISD::BIT_CONVERT, OVT, Result); |
| 1350 | break; |
| 1351 | } |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 1352 | } |
| 1353 | break; |
Chris Lattner | 384504c | 2006-03-21 20:44:12 +0000 | [diff] [blame] | 1354 | |
| 1355 | case ISD::EXTRACT_VECTOR_ELT: |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 1356 | Tmp1 = Node->getOperand(0); |
Chris Lattner | 384504c | 2006-03-21 20:44:12 +0000 | [diff] [blame] | 1357 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1358 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 1359 | Result = ExpandEXTRACT_VECTOR_ELT(Result); |
Chris Lattner | 384504c | 2006-03-21 20:44:12 +0000 | [diff] [blame] | 1360 | break; |
| 1361 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 1362 | case ISD::EXTRACT_SUBVECTOR: |
| 1363 | Tmp1 = Node->getOperand(0); |
| 1364 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1365 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 1366 | Result = ExpandEXTRACT_SUBVECTOR(Result); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 1367 | break; |
| 1368 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1369 | case ISD::CALLSEQ_START: { |
| 1370 | SDNode *CallEnd = FindCallEndFromCallStart(Node); |
| 1371 | |
| 1372 | // Recursively Legalize all of the inputs of the call end that do not lead |
| 1373 | // to this call start. This ensures that any libcalls that need be inserted |
| 1374 | // are inserted *before* the CALLSEQ_START. |
Chris Lattner | 00755df | 2007-02-04 00:27:56 +0000 | [diff] [blame] | 1375 | {SmallPtrSet<SDNode*, 32> NodesLeadingTo; |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1376 | for (unsigned i = 0, e = CallEnd->getNumOperands(); i != e; ++i) |
Chris Lattner | c9cf4f1 | 2006-07-26 23:55:56 +0000 | [diff] [blame] | 1377 | LegalizeAllNodesNotLeadingTo(CallEnd->getOperand(i).Val, Node, |
| 1378 | NodesLeadingTo); |
| 1379 | } |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1380 | |
| 1381 | // Now that we legalized all of the inputs (which may have inserted |
| 1382 | // libcalls) create the new CALLSEQ_START node. |
| 1383 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1384 | |
| 1385 | // Merge in the last call, to ensure that this call start after the last |
| 1386 | // call ended. |
Chris Lattner | c5d7d7c | 2006-05-17 18:00:08 +0000 | [diff] [blame] | 1387 | if (LastCALLSEQ_END.getOpcode() != ISD::EntryToken) { |
Chris Lattner | b248e16 | 2006-05-17 17:55:45 +0000 | [diff] [blame] | 1388 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1389 | Tmp1 = LegalizeOp(Tmp1); |
| 1390 | } |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1391 | |
| 1392 | // Do not try to legalize the target-specific arguments (#1+). |
| 1393 | if (Tmp1 != Node->getOperand(0)) { |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1394 | SmallVector<SDOperand, 8> Ops(Node->op_begin(), Node->op_end()); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1395 | Ops[0] = Tmp1; |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1396 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1397 | } |
| 1398 | |
| 1399 | // Remember that the CALLSEQ_START is legalized. |
Chris Lattner | 4b653a0 | 2006-02-14 00:55:02 +0000 | [diff] [blame] | 1400 | AddLegalizedOperand(Op.getValue(0), Result); |
| 1401 | if (Node->getNumValues() == 2) // If this has a flag result, remember it. |
| 1402 | AddLegalizedOperand(Op.getValue(1), Result.getValue(1)); |
| 1403 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1404 | // Now that the callseq_start and all of the non-call nodes above this call |
| 1405 | // sequence have been legalized, legalize the call itself. During this |
| 1406 | // process, no libcalls can/will be inserted, guaranteeing that no calls |
| 1407 | // can overlap. |
| 1408 | assert(!IsLegalizingCall && "Inconsistent sequentialization of calls!"); |
| 1409 | SDOperand InCallSEQ = LastCALLSEQ_END; |
| 1410 | // Note that we are selecting this call! |
| 1411 | LastCALLSEQ_END = SDOperand(CallEnd, 0); |
| 1412 | IsLegalizingCall = true; |
| 1413 | |
| 1414 | // Legalize the call, starting from the CALLSEQ_END. |
| 1415 | LegalizeOp(LastCALLSEQ_END); |
| 1416 | assert(!IsLegalizingCall && "CALLSEQ_END should have cleared this!"); |
| 1417 | return Result; |
| 1418 | } |
Chris Lattner | 16cd04d | 2005-05-12 23:24:06 +0000 | [diff] [blame] | 1419 | case ISD::CALLSEQ_END: |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1420 | // If the CALLSEQ_START node hasn't been legalized first, legalize it. This |
| 1421 | // will cause this node to be legalized as well as handling libcalls right. |
| 1422 | if (LastCALLSEQ_END.Val != Node) { |
| 1423 | LegalizeOp(SDOperand(FindCallStartFromCallEnd(Node), 0)); |
Chris Lattner | 718071c | 2007-02-04 00:50:02 +0000 | [diff] [blame] | 1424 | DenseMap<SDOperand, SDOperand>::iterator I = LegalizedNodes.find(Op); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1425 | assert(I != LegalizedNodes.end() && |
| 1426 | "Legalizing the call start should have legalized this node!"); |
| 1427 | return I->second; |
| 1428 | } |
| 1429 | |
| 1430 | // Otherwise, the call start has been legalized and everything is going |
| 1431 | // according to plan. Just legalize ourselves normally here. |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1432 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | 70814bc | 2006-01-29 07:58:15 +0000 | [diff] [blame] | 1433 | // Do not try to legalize the target-specific arguments (#1+), except for |
| 1434 | // an optional flag input. |
| 1435 | if (Node->getOperand(Node->getNumOperands()-1).getValueType() != MVT::Flag){ |
| 1436 | if (Tmp1 != Node->getOperand(0)) { |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1437 | SmallVector<SDOperand, 8> Ops(Node->op_begin(), Node->op_end()); |
Chris Lattner | 70814bc | 2006-01-29 07:58:15 +0000 | [diff] [blame] | 1438 | Ops[0] = Tmp1; |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1439 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 70814bc | 2006-01-29 07:58:15 +0000 | [diff] [blame] | 1440 | } |
| 1441 | } else { |
| 1442 | Tmp2 = LegalizeOp(Node->getOperand(Node->getNumOperands()-1)); |
| 1443 | if (Tmp1 != Node->getOperand(0) || |
| 1444 | Tmp2 != Node->getOperand(Node->getNumOperands()-1)) { |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1445 | SmallVector<SDOperand, 8> Ops(Node->op_begin(), Node->op_end()); |
Chris Lattner | 70814bc | 2006-01-29 07:58:15 +0000 | [diff] [blame] | 1446 | Ops[0] = Tmp1; |
| 1447 | Ops.back() = Tmp2; |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1448 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 70814bc | 2006-01-29 07:58:15 +0000 | [diff] [blame] | 1449 | } |
Chris Lattner | 6a54289 | 2006-01-24 05:48:21 +0000 | [diff] [blame] | 1450 | } |
Chris Lattner | 4b653a0 | 2006-02-14 00:55:02 +0000 | [diff] [blame] | 1451 | assert(IsLegalizingCall && "Call sequence imbalance between start/end?"); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1452 | // This finishes up call legalization. |
| 1453 | IsLegalizingCall = false; |
Chris Lattner | 4b653a0 | 2006-02-14 00:55:02 +0000 | [diff] [blame] | 1454 | |
| 1455 | // If the CALLSEQ_END node has a flag, remember that we legalized it. |
| 1456 | AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0)); |
| 1457 | if (Node->getNumValues() == 2) |
| 1458 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
| 1459 | return Result.getValue(Op.ResNo); |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1460 | case ISD::DYNAMIC_STACKALLOC: { |
Evan Cheng | 61bbbab | 2007-08-16 23:50:06 +0000 | [diff] [blame] | 1461 | MVT::ValueType VT = Node->getValueType(0); |
Chris Lattner | fa404e8 | 2005-01-09 19:03:49 +0000 | [diff] [blame] | 1462 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1463 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the size. |
| 1464 | Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the alignment. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1465 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | fa404e8 | 2005-01-09 19:03:49 +0000 | [diff] [blame] | 1466 | |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1467 | Tmp1 = Result.getValue(0); |
Chris Lattner | 5f65229 | 2006-01-15 08:43:08 +0000 | [diff] [blame] | 1468 | Tmp2 = Result.getValue(1); |
Evan Cheng | 61bbbab | 2007-08-16 23:50:06 +0000 | [diff] [blame] | 1469 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1470 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1471 | case TargetLowering::Expand: { |
| 1472 | unsigned SPReg = TLI.getStackPointerRegisterToSaveRestore(); |
| 1473 | assert(SPReg && "Target cannot require DYNAMIC_STACKALLOC expansion and" |
| 1474 | " not tell us which reg is the stack pointer!"); |
| 1475 | SDOperand Chain = Tmp1.getOperand(0); |
| 1476 | SDOperand Size = Tmp2.getOperand(1); |
Evan Cheng | 61bbbab | 2007-08-16 23:50:06 +0000 | [diff] [blame] | 1477 | SDOperand SP = DAG.getCopyFromReg(Chain, SPReg, VT); |
| 1478 | Chain = SP.getValue(1); |
| 1479 | unsigned Align = cast<ConstantSDNode>(Tmp3)->getValue(); |
| 1480 | unsigned StackAlign = |
| 1481 | TLI.getTargetMachine().getFrameInfo()->getStackAlignment(); |
| 1482 | if (Align > StackAlign) |
Evan Cheng | 3e20bba | 2007-08-17 18:02:22 +0000 | [diff] [blame] | 1483 | SP = DAG.getNode(ISD::AND, VT, SP, |
| 1484 | DAG.getConstant(-(uint64_t)Align, VT)); |
Evan Cheng | 61bbbab | 2007-08-16 23:50:06 +0000 | [diff] [blame] | 1485 | Tmp1 = DAG.getNode(ISD::SUB, VT, SP, Size); // Value |
| 1486 | Tmp2 = DAG.getCopyToReg(Chain, SPReg, Tmp1); // Output chain |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1487 | Tmp1 = LegalizeOp(Tmp1); |
| 1488 | Tmp2 = LegalizeOp(Tmp2); |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1489 | break; |
| 1490 | } |
| 1491 | case TargetLowering::Custom: |
Chris Lattner | 5f65229 | 2006-01-15 08:43:08 +0000 | [diff] [blame] | 1492 | Tmp3 = TLI.LowerOperation(Tmp1, DAG); |
| 1493 | if (Tmp3.Val) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1494 | Tmp1 = LegalizeOp(Tmp3); |
| 1495 | Tmp2 = LegalizeOp(Tmp3.getValue(1)); |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1496 | } |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1497 | break; |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1498 | case TargetLowering::Legal: |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1499 | break; |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1500 | } |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1501 | // Since this op produce two values, make sure to remember that we |
| 1502 | // legalized both of them. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1503 | AddLegalizedOperand(SDOperand(Node, 0), Tmp1); |
| 1504 | AddLegalizedOperand(SDOperand(Node, 1), Tmp2); |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1505 | return Op.ResNo ? Tmp2 : Tmp1; |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1506 | } |
Chris Lattner | 25a022c | 2006-07-11 01:40:09 +0000 | [diff] [blame] | 1507 | case ISD::INLINEASM: { |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1508 | SmallVector<SDOperand, 8> Ops(Node->op_begin(), Node->op_end()); |
Chris Lattner | 25a022c | 2006-07-11 01:40:09 +0000 | [diff] [blame] | 1509 | bool Changed = false; |
| 1510 | // Legalize all of the operands of the inline asm, in case they are nodes |
| 1511 | // that need to be expanded or something. Note we skip the asm string and |
| 1512 | // all of the TargetConstant flags. |
| 1513 | SDOperand Op = LegalizeOp(Ops[0]); |
| 1514 | Changed = Op != Ops[0]; |
| 1515 | Ops[0] = Op; |
| 1516 | |
| 1517 | bool HasInFlag = Ops.back().getValueType() == MVT::Flag; |
| 1518 | for (unsigned i = 2, e = Ops.size()-HasInFlag; i < e; ) { |
| 1519 | unsigned NumVals = cast<ConstantSDNode>(Ops[i])->getValue() >> 3; |
| 1520 | for (++i; NumVals; ++i, --NumVals) { |
| 1521 | SDOperand Op = LegalizeOp(Ops[i]); |
| 1522 | if (Op != Ops[i]) { |
| 1523 | Changed = true; |
| 1524 | Ops[i] = Op; |
| 1525 | } |
| 1526 | } |
Chris Lattner | ce7518c | 2006-01-26 22:24:51 +0000 | [diff] [blame] | 1527 | } |
Chris Lattner | 25a022c | 2006-07-11 01:40:09 +0000 | [diff] [blame] | 1528 | |
| 1529 | if (HasInFlag) { |
| 1530 | Op = LegalizeOp(Ops.back()); |
| 1531 | Changed |= Op != Ops.back(); |
| 1532 | Ops.back() = Op; |
| 1533 | } |
| 1534 | |
| 1535 | if (Changed) |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1536 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | ce7518c | 2006-01-26 22:24:51 +0000 | [diff] [blame] | 1537 | |
| 1538 | // 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] | 1539 | AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0)); |
Chris Lattner | ce7518c | 2006-01-26 22:24:51 +0000 | [diff] [blame] | 1540 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
| 1541 | return Result.getValue(Op.ResNo); |
Chris Lattner | 25a022c | 2006-07-11 01:40:09 +0000 | [diff] [blame] | 1542 | } |
Chris Lattner | c7af179 | 2005-01-07 22:12:08 +0000 | [diff] [blame] | 1543 | case ISD::BR: |
| 1544 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1545 | // Ensure that libcalls are emitted before a branch. |
| 1546 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1547 | Tmp1 = LegalizeOp(Tmp1); |
| 1548 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 1549 | |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1550 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
Chris Lattner | c7af179 | 2005-01-07 22:12:08 +0000 | [diff] [blame] | 1551 | break; |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 1552 | case ISD::BRIND: |
| 1553 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1554 | // Ensure that libcalls are emitted before a branch. |
| 1555 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1556 | Tmp1 = LegalizeOp(Tmp1); |
| 1557 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 1558 | |
| 1559 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 1560 | default: assert(0 && "Indirect target must be legal type (pointer)!"); |
| 1561 | case Legal: |
| 1562 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the condition. |
| 1563 | break; |
| 1564 | } |
| 1565 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 1566 | break; |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 1567 | case ISD::BR_JT: |
| 1568 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1569 | // Ensure that libcalls are emitted before a branch. |
| 1570 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1571 | Tmp1 = LegalizeOp(Tmp1); |
| 1572 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 1573 | |
| 1574 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the jumptable node. |
| 1575 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
| 1576 | |
| 1577 | switch (TLI.getOperationAction(ISD::BR_JT, MVT::Other)) { |
| 1578 | default: assert(0 && "This action is not supported yet!"); |
| 1579 | case TargetLowering::Legal: break; |
| 1580 | case TargetLowering::Custom: |
| 1581 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 1582 | if (Tmp1.Val) Result = Tmp1; |
| 1583 | break; |
| 1584 | case TargetLowering::Expand: { |
| 1585 | SDOperand Chain = Result.getOperand(0); |
| 1586 | SDOperand Table = Result.getOperand(1); |
| 1587 | SDOperand Index = Result.getOperand(2); |
| 1588 | |
| 1589 | MVT::ValueType PTy = TLI.getPointerTy(); |
Jim Laskey | acd80ac | 2006-12-14 19:17:33 +0000 | [diff] [blame] | 1590 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1591 | unsigned EntrySize = MF.getJumpTableInfo()->getEntrySize(); |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 1592 | Index= DAG.getNode(ISD::MUL, PTy, Index, DAG.getConstant(EntrySize, PTy)); |
| 1593 | SDOperand Addr = DAG.getNode(ISD::ADD, PTy, Index, Table); |
Jim Laskey | acd80ac | 2006-12-14 19:17:33 +0000 | [diff] [blame] | 1594 | |
| 1595 | SDOperand LD; |
| 1596 | switch (EntrySize) { |
| 1597 | default: assert(0 && "Size of jump table not supported yet."); break; |
| 1598 | case 4: LD = DAG.getLoad(MVT::i32, Chain, Addr, NULL, 0); break; |
| 1599 | case 8: LD = DAG.getLoad(MVT::i64, Chain, Addr, NULL, 0); break; |
| 1600 | } |
| 1601 | |
| 1602 | if (TLI.getTargetMachine().getRelocationModel() == Reloc::PIC_) { |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 1603 | // For PIC, the sequence is: |
| 1604 | // BRIND(load(Jumptable + index) + RelocBase) |
| 1605 | // RelocBase is the JumpTable on PPC and X86, GOT on Alpha |
| 1606 | SDOperand Reloc; |
| 1607 | if (TLI.usesGlobalOffsetTable()) |
| 1608 | Reloc = DAG.getNode(ISD::GLOBAL_OFFSET_TABLE, PTy); |
| 1609 | else |
| 1610 | Reloc = Table; |
Evan Cheng | d063189 | 2006-10-31 02:31:00 +0000 | [diff] [blame] | 1611 | Addr = (PTy != MVT::i32) ? DAG.getNode(ISD::SIGN_EXTEND, PTy, LD) : LD; |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 1612 | Addr = DAG.getNode(ISD::ADD, PTy, Addr, Reloc); |
| 1613 | Result = DAG.getNode(ISD::BRIND, MVT::Other, LD.getValue(1), Addr); |
| 1614 | } else { |
| 1615 | Result = DAG.getNode(ISD::BRIND, MVT::Other, LD.getValue(1), LD); |
| 1616 | } |
| 1617 | } |
| 1618 | } |
| 1619 | break; |
Chris Lattner | c18ae4c | 2005-01-07 08:19:42 +0000 | [diff] [blame] | 1620 | case ISD::BRCOND: |
| 1621 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1622 | // Ensure that libcalls are emitted before a return. |
| 1623 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1624 | Tmp1 = LegalizeOp(Tmp1); |
| 1625 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 1626 | |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 1627 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 1628 | case Expand: assert(0 && "It's impossible to expand bools"); |
| 1629 | case Legal: |
| 1630 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the condition. |
| 1631 | break; |
| 1632 | case Promote: |
| 1633 | Tmp2 = PromoteOp(Node->getOperand(1)); // Promote the condition. |
Chris Lattner | f990817 | 2006-11-27 04:39:56 +0000 | [diff] [blame] | 1634 | |
| 1635 | // The top bits of the promoted condition are not necessarily zero, ensure |
| 1636 | // that the value is properly zero extended. |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1637 | if (!DAG.MaskedValueIsZero(Tmp2, |
Chris Lattner | f990817 | 2006-11-27 04:39:56 +0000 | [diff] [blame] | 1638 | MVT::getIntVTBitMask(Tmp2.getValueType())^1)) |
| 1639 | Tmp2 = DAG.getZeroExtendInReg(Tmp2, MVT::i1); |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 1640 | break; |
| 1641 | } |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 1642 | |
| 1643 | // Basic block destination (Op#2) is always legal. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1644 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 1645 | |
| 1646 | switch (TLI.getOperationAction(ISD::BRCOND, MVT::Other)) { |
| 1647 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 1648 | case TargetLowering::Legal: break; |
| 1649 | case TargetLowering::Custom: |
| 1650 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 1651 | if (Tmp1.Val) Result = Tmp1; |
| 1652 | break; |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 1653 | case TargetLowering::Expand: |
| 1654 | // Expand brcond's setcc into its constituent parts and create a BR_CC |
| 1655 | // Node. |
| 1656 | if (Tmp2.getOpcode() == ISD::SETCC) { |
| 1657 | Result = DAG.getNode(ISD::BR_CC, MVT::Other, Tmp1, Tmp2.getOperand(2), |
| 1658 | Tmp2.getOperand(0), Tmp2.getOperand(1), |
| 1659 | Node->getOperand(2)); |
| 1660 | } else { |
| 1661 | Result = DAG.getNode(ISD::BR_CC, MVT::Other, Tmp1, |
| 1662 | DAG.getCondCode(ISD::SETNE), Tmp2, |
| 1663 | DAG.getConstant(0, Tmp2.getValueType()), |
| 1664 | Node->getOperand(2)); |
| 1665 | } |
| 1666 | break; |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 1667 | } |
| 1668 | break; |
| 1669 | case ISD::BR_CC: |
| 1670 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1671 | // Ensure that libcalls are emitted before a branch. |
| 1672 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1673 | Tmp1 = LegalizeOp(Tmp1); |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 1674 | Tmp2 = Node->getOperand(2); // LHS |
| 1675 | Tmp3 = Node->getOperand(3); // RHS |
| 1676 | Tmp4 = Node->getOperand(1); // CC |
| 1677 | |
| 1678 | LegalizeSetCCOperands(Tmp2, Tmp3, Tmp4); |
Evan Cheng | 722cb36 | 2006-12-18 22:55:34 +0000 | [diff] [blame] | 1679 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 1680 | |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 1681 | // If we didn't get both a LHS and RHS back from LegalizeSetCCOperands, |
| 1682 | // the LHS is a legal SETCC itself. In this case, we need to compare |
| 1683 | // the result against zero to select between true and false values. |
| 1684 | if (Tmp3.Val == 0) { |
| 1685 | Tmp3 = DAG.getConstant(0, Tmp2.getValueType()); |
| 1686 | Tmp4 = DAG.getCondCode(ISD::SETNE); |
Chris Lattner | 181b7a3 | 2005-12-17 23:46:46 +0000 | [diff] [blame] | 1687 | } |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 1688 | |
| 1689 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp4, Tmp2, Tmp3, |
| 1690 | Node->getOperand(4)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 1691 | |
Chris Lattner | 181b7a3 | 2005-12-17 23:46:46 +0000 | [diff] [blame] | 1692 | switch (TLI.getOperationAction(ISD::BR_CC, Tmp3.getValueType())) { |
| 1693 | default: assert(0 && "Unexpected action for BR_CC!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 1694 | case TargetLowering::Legal: break; |
| 1695 | case TargetLowering::Custom: |
| 1696 | Tmp4 = TLI.LowerOperation(Result, DAG); |
| 1697 | if (Tmp4.Val) Result = Tmp4; |
Chris Lattner | 181b7a3 | 2005-12-17 23:46:46 +0000 | [diff] [blame] | 1698 | break; |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 1699 | } |
Chris Lattner | c18ae4c | 2005-01-07 08:19:42 +0000 | [diff] [blame] | 1700 | break; |
Evan Cheng | f3fd9fe | 2005-12-23 07:29:34 +0000 | [diff] [blame] | 1701 | case ISD::LOAD: { |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1702 | LoadSDNode *LD = cast<LoadSDNode>(Node); |
| 1703 | Tmp1 = LegalizeOp(LD->getChain()); // Legalize the chain. |
| 1704 | Tmp2 = LegalizeOp(LD->getBasePtr()); // Legalize the base pointer. |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 1705 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1706 | ISD::LoadExtType ExtType = LD->getExtensionType(); |
| 1707 | if (ExtType == ISD::NON_EXTLOAD) { |
| 1708 | MVT::ValueType VT = Node->getValueType(0); |
| 1709 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, LD->getOffset()); |
| 1710 | Tmp3 = Result.getValue(0); |
| 1711 | Tmp4 = Result.getValue(1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 1712 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1713 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 1714 | default: assert(0 && "This action is not supported yet!"); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 1715 | case TargetLowering::Legal: |
| 1716 | // If this is an unaligned load and the target doesn't support it, |
| 1717 | // expand it. |
| 1718 | if (!TLI.allowsUnalignedMemoryAccesses()) { |
| 1719 | unsigned ABIAlignment = TLI.getTargetData()-> |
| 1720 | getABITypeAlignment(MVT::getTypeForValueType(LD->getLoadedVT())); |
| 1721 | if (LD->getAlignment() < ABIAlignment){ |
| 1722 | Result = ExpandUnalignedLoad(cast<LoadSDNode>(Result.Val), DAG, |
| 1723 | TLI); |
| 1724 | Tmp3 = Result.getOperand(0); |
| 1725 | Tmp4 = Result.getOperand(1); |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 1726 | Tmp3 = LegalizeOp(Tmp3); |
| 1727 | Tmp4 = LegalizeOp(Tmp4); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 1728 | } |
| 1729 | } |
| 1730 | break; |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1731 | case TargetLowering::Custom: |
| 1732 | Tmp1 = TLI.LowerOperation(Tmp3, DAG); |
| 1733 | if (Tmp1.Val) { |
| 1734 | Tmp3 = LegalizeOp(Tmp1); |
| 1735 | Tmp4 = LegalizeOp(Tmp1.getValue(1)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 1736 | } |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1737 | break; |
| 1738 | case TargetLowering::Promote: { |
| 1739 | // Only promote a load of vector type to another. |
| 1740 | assert(MVT::isVector(VT) && "Cannot promote this load!"); |
| 1741 | // Change base type to a different vector type. |
| 1742 | MVT::ValueType NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), VT); |
| 1743 | |
| 1744 | Tmp1 = DAG.getLoad(NVT, Tmp1, Tmp2, LD->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 1745 | LD->getSrcValueOffset(), |
| 1746 | LD->isVolatile(), LD->getAlignment()); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1747 | Tmp3 = LegalizeOp(DAG.getNode(ISD::BIT_CONVERT, VT, Tmp1)); |
| 1748 | Tmp4 = LegalizeOp(Tmp1.getValue(1)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1749 | break; |
Andrew Lenharth | 9d416f7 | 2005-06-30 19:22:37 +0000 | [diff] [blame] | 1750 | } |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1751 | } |
| 1752 | // Since loads produce two values, make sure to remember that we |
| 1753 | // legalized both of them. |
| 1754 | AddLegalizedOperand(SDOperand(Node, 0), Tmp3); |
| 1755 | AddLegalizedOperand(SDOperand(Node, 1), Tmp4); |
| 1756 | return Op.ResNo ? Tmp4 : Tmp3; |
| 1757 | } else { |
Evan Cheng | 2e49f09 | 2006-10-11 07:10:22 +0000 | [diff] [blame] | 1758 | MVT::ValueType SrcVT = LD->getLoadedVT(); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1759 | switch (TLI.getLoadXAction(ExtType, SrcVT)) { |
| 1760 | default: assert(0 && "This action is not supported yet!"); |
| 1761 | case TargetLowering::Promote: |
| 1762 | assert(SrcVT == MVT::i1 && |
| 1763 | "Can only promote extending LOAD from i1 -> i8!"); |
| 1764 | Result = DAG.getExtLoad(ExtType, Node->getValueType(0), Tmp1, Tmp2, |
| 1765 | LD->getSrcValue(), LD->getSrcValueOffset(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 1766 | MVT::i8, LD->isVolatile(), LD->getAlignment()); |
Duncan Sands | f411b83 | 2007-10-17 13:49:58 +0000 | [diff] [blame] | 1767 | Tmp1 = Result.getValue(0); |
| 1768 | Tmp2 = Result.getValue(1); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1769 | break; |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1770 | case TargetLowering::Custom: |
| 1771 | isCustom = true; |
| 1772 | // FALLTHROUGH |
| 1773 | case TargetLowering::Legal: |
| 1774 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, LD->getOffset()); |
| 1775 | Tmp1 = Result.getValue(0); |
| 1776 | Tmp2 = Result.getValue(1); |
| 1777 | |
| 1778 | if (isCustom) { |
| 1779 | Tmp3 = TLI.LowerOperation(Result, DAG); |
| 1780 | if (Tmp3.Val) { |
| 1781 | Tmp1 = LegalizeOp(Tmp3); |
| 1782 | Tmp2 = LegalizeOp(Tmp3.getValue(1)); |
| 1783 | } |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 1784 | } else { |
| 1785 | // If this is an unaligned load and the target doesn't support it, |
| 1786 | // expand it. |
| 1787 | if (!TLI.allowsUnalignedMemoryAccesses()) { |
| 1788 | unsigned ABIAlignment = TLI.getTargetData()-> |
| 1789 | getABITypeAlignment(MVT::getTypeForValueType(LD->getLoadedVT())); |
| 1790 | if (LD->getAlignment() < ABIAlignment){ |
| 1791 | Result = ExpandUnalignedLoad(cast<LoadSDNode>(Result.Val), DAG, |
| 1792 | TLI); |
| 1793 | Tmp1 = Result.getOperand(0); |
| 1794 | Tmp2 = Result.getOperand(1); |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 1795 | Tmp1 = LegalizeOp(Tmp1); |
| 1796 | Tmp2 = LegalizeOp(Tmp2); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 1797 | } |
| 1798 | } |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1799 | } |
| 1800 | break; |
| 1801 | case TargetLowering::Expand: |
| 1802 | // f64 = EXTLOAD f32 should expand to LOAD, FP_EXTEND |
| 1803 | if (SrcVT == MVT::f32 && Node->getValueType(0) == MVT::f64) { |
| 1804 | SDOperand Load = DAG.getLoad(SrcVT, Tmp1, Tmp2, LD->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 1805 | LD->getSrcValueOffset(), |
| 1806 | LD->isVolatile(), LD->getAlignment()); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1807 | Result = DAG.getNode(ISD::FP_EXTEND, Node->getValueType(0), Load); |
| 1808 | Tmp1 = LegalizeOp(Result); // Relegalize new nodes. |
| 1809 | Tmp2 = LegalizeOp(Load.getValue(1)); |
| 1810 | break; |
| 1811 | } |
Chris Lattner | fea997a | 2007-02-01 04:55:59 +0000 | [diff] [blame] | 1812 | assert(ExtType != ISD::EXTLOAD &&"EXTLOAD should always be supported!"); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1813 | // Turn the unsupported load into an EXTLOAD followed by an explicit |
| 1814 | // zero/sign extend inreg. |
| 1815 | Result = DAG.getExtLoad(ISD::EXTLOAD, Node->getValueType(0), |
| 1816 | Tmp1, Tmp2, LD->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 1817 | LD->getSrcValueOffset(), SrcVT, |
| 1818 | LD->isVolatile(), LD->getAlignment()); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1819 | SDOperand ValRes; |
| 1820 | if (ExtType == ISD::SEXTLOAD) |
| 1821 | ValRes = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(), |
| 1822 | Result, DAG.getValueType(SrcVT)); |
| 1823 | else |
| 1824 | ValRes = DAG.getZeroExtendInReg(Result, SrcVT); |
| 1825 | Tmp1 = LegalizeOp(ValRes); // Relegalize new nodes. |
| 1826 | Tmp2 = LegalizeOp(Result.getValue(1)); // Relegalize new nodes. |
| 1827 | break; |
| 1828 | } |
| 1829 | // Since loads produce two values, make sure to remember that we legalized |
| 1830 | // both of them. |
| 1831 | AddLegalizedOperand(SDOperand(Node, 0), Tmp1); |
| 1832 | AddLegalizedOperand(SDOperand(Node, 1), Tmp2); |
| 1833 | return Op.ResNo ? Tmp2 : Tmp1; |
Chris Lattner | 01ff721 | 2005-04-10 22:54:25 +0000 | [diff] [blame] | 1834 | } |
Chris Lattner | 01ff721 | 2005-04-10 22:54:25 +0000 | [diff] [blame] | 1835 | } |
Nate Begeman | 5dc897b | 2005-10-19 00:06:56 +0000 | [diff] [blame] | 1836 | case ISD::EXTRACT_ELEMENT: { |
| 1837 | MVT::ValueType OpTy = Node->getOperand(0).getValueType(); |
| 1838 | switch (getTypeAction(OpTy)) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1839 | default: assert(0 && "EXTRACT_ELEMENT action for type unimplemented!"); |
Nate Begeman | 5dc897b | 2005-10-19 00:06:56 +0000 | [diff] [blame] | 1840 | case Legal: |
| 1841 | if (cast<ConstantSDNode>(Node->getOperand(1))->getValue()) { |
| 1842 | // 1 -> Hi |
| 1843 | Result = DAG.getNode(ISD::SRL, OpTy, Node->getOperand(0), |
| 1844 | DAG.getConstant(MVT::getSizeInBits(OpTy)/2, |
| 1845 | TLI.getShiftAmountTy())); |
| 1846 | Result = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0), Result); |
| 1847 | } else { |
| 1848 | // 0 -> Lo |
| 1849 | Result = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0), |
| 1850 | Node->getOperand(0)); |
| 1851 | } |
Nate Begeman | 5dc897b | 2005-10-19 00:06:56 +0000 | [diff] [blame] | 1852 | break; |
| 1853 | case Expand: |
| 1854 | // Get both the low and high parts. |
| 1855 | ExpandOp(Node->getOperand(0), Tmp1, Tmp2); |
| 1856 | if (cast<ConstantSDNode>(Node->getOperand(1))->getValue()) |
| 1857 | Result = Tmp2; // 1 -> Hi |
| 1858 | else |
| 1859 | Result = Tmp1; // 0 -> Lo |
| 1860 | break; |
| 1861 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1862 | break; |
Nate Begeman | 5dc897b | 2005-10-19 00:06:56 +0000 | [diff] [blame] | 1863 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1864 | |
| 1865 | case ISD::CopyToReg: |
| 1866 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 1867 | |
Chris Lattner | c9c60f6 | 2005-08-24 16:35:28 +0000 | [diff] [blame] | 1868 | assert(isTypeLegal(Node->getOperand(2).getValueType()) && |
Chris Lattner | d5d0f9b | 2005-08-16 21:55:35 +0000 | [diff] [blame] | 1869 | "Register type must be legal!"); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 1870 | // Legalize the incoming value (must be a legal type). |
Chris Lattner | d5d0f9b | 2005-08-16 21:55:35 +0000 | [diff] [blame] | 1871 | Tmp2 = LegalizeOp(Node->getOperand(2)); |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 1872 | if (Node->getNumValues() == 1) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1873 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1), Tmp2); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 1874 | } else { |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 1875 | assert(Node->getNumValues() == 2 && "Unknown CopyToReg"); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1876 | if (Node->getNumOperands() == 4) { |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 1877 | Tmp3 = LegalizeOp(Node->getOperand(3)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1878 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1), Tmp2, |
| 1879 | Tmp3); |
| 1880 | } else { |
| 1881 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1),Tmp2); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 1882 | } |
| 1883 | |
| 1884 | // Since this produces two values, make sure to remember that we legalized |
| 1885 | // both of them. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1886 | AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0)); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 1887 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1888 | return Result; |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 1889 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1890 | break; |
| 1891 | |
| 1892 | case ISD::RET: |
| 1893 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1894 | |
| 1895 | // Ensure that libcalls are emitted before a return. |
| 1896 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1897 | Tmp1 = LegalizeOp(Tmp1); |
| 1898 | LastCALLSEQ_END = DAG.getEntryNode(); |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 1899 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1900 | switch (Node->getNumOperands()) { |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 1901 | case 3: // ret val |
Evan Cheng | 98f8aeb | 2006-04-11 06:33:39 +0000 | [diff] [blame] | 1902 | Tmp2 = Node->getOperand(1); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 1903 | Tmp3 = Node->getOperand(2); // Signness |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 1904 | switch (getTypeAction(Tmp2.getValueType())) { |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1905 | case Legal: |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 1906 | Result = DAG.UpdateNodeOperands(Result, Tmp1, LegalizeOp(Tmp2), Tmp3); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1907 | break; |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 1908 | case Expand: |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 1909 | if (!MVT::isVector(Tmp2.getValueType())) { |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 1910 | SDOperand Lo, Hi; |
| 1911 | ExpandOp(Tmp2, Lo, Hi); |
Chris Lattner | edf2e8d | 2007-03-06 20:01:06 +0000 | [diff] [blame] | 1912 | |
| 1913 | // Big endian systems want the hi reg first. |
| 1914 | if (!TLI.isLittleEndian()) |
| 1915 | std::swap(Lo, Hi); |
| 1916 | |
Evan Cheng | 13acce3 | 2006-12-11 19:27:14 +0000 | [diff] [blame] | 1917 | if (Hi.Val) |
| 1918 | Result = DAG.getNode(ISD::RET, MVT::Other, Tmp1, Lo, Tmp3, Hi,Tmp3); |
| 1919 | else |
| 1920 | Result = DAG.getNode(ISD::RET, MVT::Other, Tmp1, Lo, Tmp3); |
Chris Lattner | f921a51 | 2006-08-21 20:24:53 +0000 | [diff] [blame] | 1921 | Result = LegalizeOp(Result); |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 1922 | } else { |
| 1923 | SDNode *InVal = Tmp2.Val; |
Dale Johannesen | e526962 | 2007-10-20 00:07:52 +0000 | [diff] [blame] | 1924 | int InIx = Tmp2.ResNo; |
| 1925 | unsigned NumElems = MVT::getVectorNumElements(InVal->getValueType(InIx)); |
| 1926 | MVT::ValueType EVT = MVT::getVectorElementType(InVal->getValueType(InIx)); |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 1927 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 1928 | // Figure out if there is a simple type corresponding to this Vector |
Reid Spencer | ac9dcb9 | 2007-02-15 03:39:18 +0000 | [diff] [blame] | 1929 | // type. If so, convert to the vector type. |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 1930 | MVT::ValueType TVT = MVT::getVectorType(EVT, NumElems); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 1931 | if (TLI.isTypeLegal(TVT)) { |
Reid Spencer | ac9dcb9 | 2007-02-15 03:39:18 +0000 | [diff] [blame] | 1932 | // Turn this into a return of the vector type. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 1933 | Tmp2 = LegalizeOp(Tmp2); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 1934 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 1935 | } else if (NumElems == 1) { |
| 1936 | // Turn this into a return of the scalar type. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 1937 | Tmp2 = ScalarizeVectorOp(Tmp2); |
| 1938 | Tmp2 = LegalizeOp(Tmp2); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 1939 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | b49e52c | 2006-04-11 02:00:08 +0000 | [diff] [blame] | 1940 | |
| 1941 | // FIXME: Returns of gcc generic vectors smaller than a legal type |
| 1942 | // should be returned in integer registers! |
| 1943 | |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 1944 | // The scalarized value type may not be legal, e.g. it might require |
| 1945 | // promotion or expansion. Relegalize the return. |
| 1946 | Result = LegalizeOp(Result); |
| 1947 | } else { |
Chris Lattner | b49e52c | 2006-04-11 02:00:08 +0000 | [diff] [blame] | 1948 | // FIXME: Returns of gcc generic vectors larger than a legal vector |
| 1949 | // type should be returned by reference! |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 1950 | SDOperand Lo, Hi; |
| 1951 | SplitVectorOp(Tmp2, Lo, Hi); |
Chris Lattner | fea997a | 2007-02-01 04:55:59 +0000 | [diff] [blame] | 1952 | Result = DAG.getNode(ISD::RET, MVT::Other, Tmp1, Lo, Tmp3, Hi,Tmp3); |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 1953 | Result = LegalizeOp(Result); |
| 1954 | } |
| 1955 | } |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 1956 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1957 | case Promote: |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 1958 | Tmp2 = PromoteOp(Node->getOperand(1)); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 1959 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1960 | Result = LegalizeOp(Result); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 1961 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1962 | } |
| 1963 | break; |
| 1964 | case 1: // ret void |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1965 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1966 | break; |
| 1967 | default: { // ret <values> |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1968 | SmallVector<SDOperand, 8> NewValues; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1969 | NewValues.push_back(Tmp1); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 1970 | for (unsigned i = 1, e = Node->getNumOperands(); i < e; i += 2) |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1971 | switch (getTypeAction(Node->getOperand(i).getValueType())) { |
| 1972 | case Legal: |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 1973 | NewValues.push_back(LegalizeOp(Node->getOperand(i))); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 1974 | NewValues.push_back(Node->getOperand(i+1)); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1975 | break; |
| 1976 | case Expand: { |
| 1977 | SDOperand Lo, Hi; |
Dan Gohman | 6595cb3 | 2007-06-27 16:08:04 +0000 | [diff] [blame] | 1978 | assert(!MVT::isExtendedVT(Node->getOperand(i).getValueType()) && |
Chris Lattner | b49e52c | 2006-04-11 02:00:08 +0000 | [diff] [blame] | 1979 | "FIXME: TODO: implement returning non-legal vector types!"); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1980 | ExpandOp(Node->getOperand(i), Lo, Hi); |
| 1981 | NewValues.push_back(Lo); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 1982 | NewValues.push_back(Node->getOperand(i+1)); |
Evan Cheng | 13acce3 | 2006-12-11 19:27:14 +0000 | [diff] [blame] | 1983 | if (Hi.Val) { |
| 1984 | NewValues.push_back(Hi); |
| 1985 | NewValues.push_back(Node->getOperand(i+1)); |
| 1986 | } |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 1987 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1988 | } |
| 1989 | case Promote: |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 1990 | assert(0 && "Can't promote multiple return value yet!"); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1991 | } |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1992 | |
| 1993 | if (NewValues.size() == Node->getNumOperands()) |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1994 | Result = DAG.UpdateNodeOperands(Result, &NewValues[0],NewValues.size()); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1995 | else |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1996 | Result = DAG.getNode(ISD::RET, MVT::Other, |
| 1997 | &NewValues[0], NewValues.size()); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1998 | break; |
| 1999 | } |
| 2000 | } |
Evan Cheng | 17c428e | 2006-01-06 00:41:43 +0000 | [diff] [blame] | 2001 | |
Chris Lattner | 6862dbc | 2006-01-29 21:02:23 +0000 | [diff] [blame] | 2002 | if (Result.getOpcode() == ISD::RET) { |
| 2003 | switch (TLI.getOperationAction(Result.getOpcode(), MVT::Other)) { |
| 2004 | default: assert(0 && "This action is not supported yet!"); |
| 2005 | case TargetLowering::Legal: break; |
| 2006 | case TargetLowering::Custom: |
| 2007 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2008 | if (Tmp1.Val) Result = Tmp1; |
| 2009 | break; |
| 2010 | } |
Evan Cheng | 17c428e | 2006-01-06 00:41:43 +0000 | [diff] [blame] | 2011 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2012 | break; |
Evan Cheng | f3fd9fe | 2005-12-23 07:29:34 +0000 | [diff] [blame] | 2013 | case ISD::STORE: { |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2014 | StoreSDNode *ST = cast<StoreSDNode>(Node); |
| 2015 | Tmp1 = LegalizeOp(ST->getChain()); // Legalize the chain. |
| 2016 | Tmp2 = LegalizeOp(ST->getBasePtr()); // Legalize the pointer. |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2017 | int SVOffset = ST->getSrcValueOffset(); |
| 2018 | unsigned Alignment = ST->getAlignment(); |
| 2019 | bool isVolatile = ST->isVolatile(); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2020 | |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2021 | if (!ST->isTruncatingStore()) { |
Chris Lattner | d93d46e | 2006-12-12 04:18:56 +0000 | [diff] [blame] | 2022 | // Turn 'store float 1.0, Ptr' -> 'store int 0x12345678, Ptr' |
| 2023 | // FIXME: We shouldn't do this for TargetConstantFP's. |
| 2024 | // FIXME: move this to the DAG Combiner! Note that we can't regress due |
| 2025 | // to phase ordering between legalized code and the dag combiner. This |
| 2026 | // probably means that we need to integrate dag combiner and legalizer |
| 2027 | // together. |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 2028 | // We generally can't do this one for long doubles. |
Chris Lattner | 2b4c279 | 2007-10-13 06:35:54 +0000 | [diff] [blame] | 2029 | if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(ST->getValue())) { |
Chris Lattner | 3cb9351 | 2007-10-15 05:46:06 +0000 | [diff] [blame] | 2030 | if (CFP->getValueType(0) == MVT::f32 && |
| 2031 | getTypeAction(MVT::i32) == Legal) { |
Dale Johannesen | 9d5f456 | 2007-09-12 03:30:33 +0000 | [diff] [blame] | 2032 | Tmp3 = DAG.getConstant((uint32_t)CFP->getValueAPF(). |
| 2033 | convertToAPInt().getZExtValue(), |
Dale Johannesen | 3f6eb74 | 2007-09-11 18:32:33 +0000 | [diff] [blame] | 2034 | MVT::i32); |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 2035 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
| 2036 | SVOffset, isVolatile, Alignment); |
| 2037 | break; |
| 2038 | } else if (CFP->getValueType(0) == MVT::f64) { |
Chris Lattner | 3cb9351 | 2007-10-15 05:46:06 +0000 | [diff] [blame] | 2039 | // If this target supports 64-bit registers, do a single 64-bit store. |
| 2040 | if (getTypeAction(MVT::i64) == Legal) { |
| 2041 | Tmp3 = DAG.getConstant(CFP->getValueAPF().convertToAPInt(). |
| 2042 | getZExtValue(), MVT::i64); |
| 2043 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
| 2044 | SVOffset, isVolatile, Alignment); |
| 2045 | break; |
| 2046 | } else if (getTypeAction(MVT::i32) == Legal) { |
| 2047 | // Otherwise, if the target supports 32-bit registers, use 2 32-bit |
| 2048 | // stores. If the target supports neither 32- nor 64-bits, this |
| 2049 | // xform is certainly not worth it. |
| 2050 | uint64_t IntVal =CFP->getValueAPF().convertToAPInt().getZExtValue(); |
| 2051 | SDOperand Lo = DAG.getConstant(uint32_t(IntVal), MVT::i32); |
| 2052 | SDOperand Hi = DAG.getConstant(uint32_t(IntVal >>32), MVT::i32); |
| 2053 | if (!TLI.isLittleEndian()) std::swap(Lo, Hi); |
| 2054 | |
| 2055 | Lo = DAG.getStore(Tmp1, Lo, Tmp2, ST->getSrcValue(), |
| 2056 | SVOffset, isVolatile, Alignment); |
| 2057 | Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2, |
| 2058 | getIntPtrConstant(4)); |
| 2059 | Hi = DAG.getStore(Tmp1, Hi, Tmp2, ST->getSrcValue(), SVOffset+4, |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 2060 | isVolatile, MinAlign(Alignment, 4U)); |
Chris Lattner | 3cb9351 | 2007-10-15 05:46:06 +0000 | [diff] [blame] | 2061 | |
| 2062 | Result = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo, Hi); |
| 2063 | break; |
| 2064 | } |
Chris Lattner | d93d46e | 2006-12-12 04:18:56 +0000 | [diff] [blame] | 2065 | } |
Chris Lattner | d93d46e | 2006-12-12 04:18:56 +0000 | [diff] [blame] | 2066 | } |
| 2067 | |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2068 | switch (getTypeAction(ST->getStoredVT())) { |
| 2069 | case Legal: { |
| 2070 | Tmp3 = LegalizeOp(ST->getValue()); |
| 2071 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp3, Tmp2, |
| 2072 | ST->getOffset()); |
Evan Cheng | f3fd9fe | 2005-12-23 07:29:34 +0000 | [diff] [blame] | 2073 | |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2074 | MVT::ValueType VT = Tmp3.getValueType(); |
| 2075 | switch (TLI.getOperationAction(ISD::STORE, VT)) { |
| 2076 | default: assert(0 && "This action is not supported yet!"); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2077 | case TargetLowering::Legal: |
| 2078 | // If this is an unaligned store and the target doesn't support it, |
| 2079 | // expand it. |
| 2080 | if (!TLI.allowsUnalignedMemoryAccesses()) { |
| 2081 | unsigned ABIAlignment = TLI.getTargetData()-> |
| 2082 | getABITypeAlignment(MVT::getTypeForValueType(ST->getStoredVT())); |
| 2083 | if (ST->getAlignment() < ABIAlignment) |
| 2084 | Result = ExpandUnalignedStore(cast<StoreSDNode>(Result.Val), DAG, |
| 2085 | TLI); |
| 2086 | } |
| 2087 | break; |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2088 | case TargetLowering::Custom: |
| 2089 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2090 | if (Tmp1.Val) Result = Tmp1; |
| 2091 | break; |
| 2092 | case TargetLowering::Promote: |
| 2093 | assert(MVT::isVector(VT) && "Unknown legal promote case!"); |
| 2094 | Tmp3 = DAG.getNode(ISD::BIT_CONVERT, |
| 2095 | TLI.getTypeToPromoteTo(ISD::STORE, VT), Tmp3); |
| 2096 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2097 | ST->getSrcValue(), SVOffset, isVolatile, |
| 2098 | Alignment); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2099 | break; |
| 2100 | } |
| 2101 | break; |
| 2102 | } |
| 2103 | case Promote: |
| 2104 | // Truncate the value and store the result. |
| 2105 | Tmp3 = PromoteOp(ST->getValue()); |
| 2106 | Result = DAG.getTruncStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2107 | SVOffset, ST->getStoredVT(), |
| 2108 | isVolatile, Alignment); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2109 | break; |
| 2110 | |
| 2111 | case Expand: |
| 2112 | unsigned IncrementSize = 0; |
| 2113 | SDOperand Lo, Hi; |
| 2114 | |
| 2115 | // If this is a vector type, then we have to calculate the increment as |
| 2116 | // the product of the element size in bytes, and the number of elements |
| 2117 | // in the high half of the vector. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2118 | if (MVT::isVector(ST->getValue().getValueType())) { |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2119 | SDNode *InVal = ST->getValue().Val; |
Dale Johannesen | e526962 | 2007-10-20 00:07:52 +0000 | [diff] [blame] | 2120 | int InIx = ST->getValue().ResNo; |
| 2121 | unsigned NumElems = MVT::getVectorNumElements(InVal->getValueType(InIx)); |
| 2122 | MVT::ValueType EVT = MVT::getVectorElementType(InVal->getValueType(InIx)); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2123 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2124 | // Figure out if there is a simple type corresponding to this Vector |
Reid Spencer | ac9dcb9 | 2007-02-15 03:39:18 +0000 | [diff] [blame] | 2125 | // type. If so, convert to the vector type. |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2126 | MVT::ValueType TVT = MVT::getVectorType(EVT, NumElems); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2127 | if (TLI.isTypeLegal(TVT)) { |
Reid Spencer | ac9dcb9 | 2007-02-15 03:39:18 +0000 | [diff] [blame] | 2128 | // Turn this into a normal store of the vector type. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2129 | Tmp3 = LegalizeOp(Node->getOperand(1)); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2130 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2131 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2132 | Result = LegalizeOp(Result); |
| 2133 | break; |
| 2134 | } else if (NumElems == 1) { |
| 2135 | // Turn this into a normal store of the scalar type. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2136 | Tmp3 = ScalarizeVectorOp(Node->getOperand(1)); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2137 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2138 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2139 | // The scalarized value type may not be legal, e.g. it might require |
| 2140 | // promotion or expansion. Relegalize the scalar store. |
| 2141 | Result = LegalizeOp(Result); |
| 2142 | break; |
| 2143 | } else { |
| 2144 | SplitVectorOp(Node->getOperand(1), Lo, Hi); |
| 2145 | IncrementSize = NumElems/2 * MVT::getSizeInBits(EVT)/8; |
| 2146 | } |
| 2147 | } else { |
| 2148 | ExpandOp(Node->getOperand(1), Lo, Hi); |
Evan Cheng | 7b2b5c8 | 2006-12-12 19:53:13 +0000 | [diff] [blame] | 2149 | IncrementSize = Hi.Val ? MVT::getSizeInBits(Hi.getValueType())/8 : 0; |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2150 | |
| 2151 | if (!TLI.isLittleEndian()) |
| 2152 | std::swap(Lo, Hi); |
| 2153 | } |
| 2154 | |
| 2155 | Lo = DAG.getStore(Tmp1, Lo, Tmp2, ST->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2156 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 7b2b5c8 | 2006-12-12 19:53:13 +0000 | [diff] [blame] | 2157 | |
| 2158 | if (Hi.Val == NULL) { |
| 2159 | // Must be int <-> float one-to-one expansion. |
| 2160 | Result = Lo; |
| 2161 | break; |
| 2162 | } |
| 2163 | |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2164 | Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2, |
| 2165 | getIntPtrConstant(IncrementSize)); |
| 2166 | assert(isTypeLegal(Tmp2.getValueType()) && |
| 2167 | "Pointers must be legal!"); |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2168 | SVOffset += IncrementSize; |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 2169 | Alignment = MinAlign(Alignment, IncrementSize); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2170 | Hi = DAG.getStore(Tmp1, Hi, Tmp2, ST->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2171 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2172 | Result = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo, Hi); |
| 2173 | break; |
| 2174 | } |
| 2175 | } else { |
| 2176 | // Truncating store |
| 2177 | assert(isTypeLegal(ST->getValue().getValueType()) && |
| 2178 | "Cannot handle illegal TRUNCSTORE yet!"); |
| 2179 | Tmp3 = LegalizeOp(ST->getValue()); |
| 2180 | |
| 2181 | // The only promote case we handle is TRUNCSTORE:i1 X into |
| 2182 | // -> TRUNCSTORE:i8 (and X, 1) |
| 2183 | if (ST->getStoredVT() == MVT::i1 && |
| 2184 | TLI.getStoreXAction(MVT::i1) == TargetLowering::Promote) { |
| 2185 | // Promote the bool to a mask then store. |
| 2186 | Tmp3 = DAG.getNode(ISD::AND, Tmp3.getValueType(), Tmp3, |
| 2187 | DAG.getConstant(1, Tmp3.getValueType())); |
| 2188 | Result = DAG.getTruncStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2189 | SVOffset, MVT::i8, |
| 2190 | isVolatile, Alignment); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2191 | } else if (Tmp1 != ST->getChain() || Tmp3 != ST->getValue() || |
| 2192 | Tmp2 != ST->getBasePtr()) { |
| 2193 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp3, Tmp2, |
| 2194 | ST->getOffset()); |
| 2195 | } |
| 2196 | |
| 2197 | MVT::ValueType StVT = cast<StoreSDNode>(Result.Val)->getStoredVT(); |
| 2198 | switch (TLI.getStoreXAction(StVT)) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2199 | default: assert(0 && "This action is not supported yet!"); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2200 | case TargetLowering::Legal: |
| 2201 | // If this is an unaligned store and the target doesn't support it, |
| 2202 | // expand it. |
| 2203 | if (!TLI.allowsUnalignedMemoryAccesses()) { |
| 2204 | unsigned ABIAlignment = TLI.getTargetData()-> |
| 2205 | getABITypeAlignment(MVT::getTypeForValueType(ST->getStoredVT())); |
| 2206 | if (ST->getAlignment() < ABIAlignment) |
| 2207 | Result = ExpandUnalignedStore(cast<StoreSDNode>(Result.Val), DAG, |
| 2208 | TLI); |
| 2209 | } |
| 2210 | break; |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2211 | case TargetLowering::Custom: |
| 2212 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2213 | if (Tmp1.Val) Result = Tmp1; |
| 2214 | break; |
Evan Cheng | f3fd9fe | 2005-12-23 07:29:34 +0000 | [diff] [blame] | 2215 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2216 | } |
| 2217 | break; |
Evan Cheng | f3fd9fe | 2005-12-23 07:29:34 +0000 | [diff] [blame] | 2218 | } |
Andrew Lenharth | 9576212 | 2005-03-31 21:24:06 +0000 | [diff] [blame] | 2219 | case ISD::PCMARKER: |
| 2220 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2221 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
Andrew Lenharth | 9576212 | 2005-03-31 21:24:06 +0000 | [diff] [blame] | 2222 | break; |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2223 | case ISD::STACKSAVE: |
| 2224 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2225 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 2226 | Tmp1 = Result.getValue(0); |
| 2227 | Tmp2 = Result.getValue(1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2228 | |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2229 | switch (TLI.getOperationAction(ISD::STACKSAVE, MVT::Other)) { |
| 2230 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2231 | case TargetLowering::Legal: break; |
| 2232 | case TargetLowering::Custom: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2233 | Tmp3 = TLI.LowerOperation(Result, DAG); |
| 2234 | if (Tmp3.Val) { |
| 2235 | Tmp1 = LegalizeOp(Tmp3); |
| 2236 | Tmp2 = LegalizeOp(Tmp3.getValue(1)); |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2237 | } |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2238 | break; |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2239 | case TargetLowering::Expand: |
Chris Lattner | 4f0d8e4 | 2006-01-13 17:48:44 +0000 | [diff] [blame] | 2240 | // Expand to CopyFromReg if the target set |
| 2241 | // StackPointerRegisterToSaveRestore. |
| 2242 | if (unsigned SP = TLI.getStackPointerRegisterToSaveRestore()) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2243 | Tmp1 = DAG.getCopyFromReg(Result.getOperand(0), SP, |
Chris Lattner | 4f0d8e4 | 2006-01-13 17:48:44 +0000 | [diff] [blame] | 2244 | Node->getValueType(0)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2245 | Tmp2 = Tmp1.getValue(1); |
Chris Lattner | 4f0d8e4 | 2006-01-13 17:48:44 +0000 | [diff] [blame] | 2246 | } else { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2247 | Tmp1 = DAG.getNode(ISD::UNDEF, Node->getValueType(0)); |
| 2248 | Tmp2 = Node->getOperand(0); |
Chris Lattner | 4f0d8e4 | 2006-01-13 17:48:44 +0000 | [diff] [blame] | 2249 | } |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2250 | break; |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2251 | } |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2252 | |
| 2253 | // Since stacksave produce two values, make sure to remember that we |
| 2254 | // legalized both of them. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2255 | AddLegalizedOperand(SDOperand(Node, 0), Tmp1); |
| 2256 | AddLegalizedOperand(SDOperand(Node, 1), Tmp2); |
| 2257 | return Op.ResNo ? Tmp2 : Tmp1; |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2258 | |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2259 | case ISD::STACKRESTORE: |
| 2260 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 2261 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2262 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2263 | |
| 2264 | switch (TLI.getOperationAction(ISD::STACKRESTORE, MVT::Other)) { |
| 2265 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2266 | case TargetLowering::Legal: break; |
| 2267 | case TargetLowering::Custom: |
| 2268 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2269 | if (Tmp1.Val) Result = Tmp1; |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2270 | break; |
| 2271 | case TargetLowering::Expand: |
Chris Lattner | 4f0d8e4 | 2006-01-13 17:48:44 +0000 | [diff] [blame] | 2272 | // Expand to CopyToReg if the target set |
| 2273 | // StackPointerRegisterToSaveRestore. |
| 2274 | if (unsigned SP = TLI.getStackPointerRegisterToSaveRestore()) { |
| 2275 | Result = DAG.getCopyToReg(Tmp1, SP, Tmp2); |
| 2276 | } else { |
| 2277 | Result = Tmp1; |
| 2278 | } |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2279 | break; |
| 2280 | } |
| 2281 | break; |
| 2282 | |
Andrew Lenharth | 51b8d54 | 2005-11-11 16:47:30 +0000 | [diff] [blame] | 2283 | case ISD::READCYCLECOUNTER: |
| 2284 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2285 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Evan Cheng | f0b3ba6 | 2006-11-29 08:26:18 +0000 | [diff] [blame] | 2286 | switch (TLI.getOperationAction(ISD::READCYCLECOUNTER, |
| 2287 | Node->getValueType(0))) { |
| 2288 | default: assert(0 && "This action is not supported yet!"); |
Evan Cheng | 6a16c5a | 2006-11-29 19:13:47 +0000 | [diff] [blame] | 2289 | case TargetLowering::Legal: |
| 2290 | Tmp1 = Result.getValue(0); |
| 2291 | Tmp2 = Result.getValue(1); |
| 2292 | break; |
Evan Cheng | f0b3ba6 | 2006-11-29 08:26:18 +0000 | [diff] [blame] | 2293 | case TargetLowering::Custom: |
| 2294 | Result = TLI.LowerOperation(Result, DAG); |
Evan Cheng | 6a16c5a | 2006-11-29 19:13:47 +0000 | [diff] [blame] | 2295 | Tmp1 = LegalizeOp(Result.getValue(0)); |
| 2296 | Tmp2 = LegalizeOp(Result.getValue(1)); |
Evan Cheng | f0b3ba6 | 2006-11-29 08:26:18 +0000 | [diff] [blame] | 2297 | break; |
| 2298 | } |
Andrew Lenharth | 49c709f | 2005-12-02 04:56:24 +0000 | [diff] [blame] | 2299 | |
| 2300 | // Since rdcc produce two values, make sure to remember that we legalized |
| 2301 | // both of them. |
Evan Cheng | 6a16c5a | 2006-11-29 19:13:47 +0000 | [diff] [blame] | 2302 | AddLegalizedOperand(SDOperand(Node, 0), Tmp1); |
| 2303 | AddLegalizedOperand(SDOperand(Node, 1), Tmp2); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2304 | return Result; |
Andrew Lenharth | f70e30b | 2005-11-20 21:32:07 +0000 | [diff] [blame] | 2305 | |
Chris Lattner | 2ee743f | 2005-01-14 22:08:15 +0000 | [diff] [blame] | 2306 | case ISD::SELECT: |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 2307 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 2308 | case Expand: assert(0 && "It's impossible to expand bools"); |
| 2309 | case Legal: |
| 2310 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the condition. |
| 2311 | break; |
| 2312 | case Promote: |
| 2313 | Tmp1 = PromoteOp(Node->getOperand(0)); // Promote the condition. |
Chris Lattner | b6c8060 | 2006-11-28 01:03:30 +0000 | [diff] [blame] | 2314 | // Make sure the condition is either zero or one. |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2315 | if (!DAG.MaskedValueIsZero(Tmp1, |
Chris Lattner | b6c8060 | 2006-11-28 01:03:30 +0000 | [diff] [blame] | 2316 | MVT::getIntVTBitMask(Tmp1.getValueType())^1)) |
| 2317 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, MVT::i1); |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 2318 | break; |
| 2319 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2320 | Tmp2 = LegalizeOp(Node->getOperand(1)); // TrueVal |
Chris Lattner | 2ee743f | 2005-01-14 22:08:15 +0000 | [diff] [blame] | 2321 | Tmp3 = LegalizeOp(Node->getOperand(2)); // FalseVal |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2322 | |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2323 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2324 | |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 2325 | switch (TLI.getOperationAction(ISD::SELECT, Tmp2.getValueType())) { |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2326 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2327 | case TargetLowering::Legal: break; |
| 2328 | case TargetLowering::Custom: { |
| 2329 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2330 | if (Tmp1.Val) Result = Tmp1; |
| 2331 | break; |
| 2332 | } |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 2333 | case TargetLowering::Expand: |
| 2334 | if (Tmp1.getOpcode() == ISD::SETCC) { |
| 2335 | Result = DAG.getSelectCC(Tmp1.getOperand(0), Tmp1.getOperand(1), |
| 2336 | Tmp2, Tmp3, |
| 2337 | cast<CondCodeSDNode>(Tmp1.getOperand(2))->get()); |
| 2338 | } else { |
| 2339 | Result = DAG.getSelectCC(Tmp1, |
| 2340 | DAG.getConstant(0, Tmp1.getValueType()), |
| 2341 | Tmp2, Tmp3, ISD::SETNE); |
| 2342 | } |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2343 | break; |
| 2344 | case TargetLowering::Promote: { |
| 2345 | MVT::ValueType NVT = |
| 2346 | TLI.getTypeToPromoteTo(ISD::SELECT, Tmp2.getValueType()); |
| 2347 | unsigned ExtOp, TruncOp; |
Evan Cheng | 41f6cbb | 2006-04-12 16:33:18 +0000 | [diff] [blame] | 2348 | if (MVT::isVector(Tmp2.getValueType())) { |
| 2349 | ExtOp = ISD::BIT_CONVERT; |
| 2350 | TruncOp = ISD::BIT_CONVERT; |
| 2351 | } else if (MVT::isInteger(Tmp2.getValueType())) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2352 | ExtOp = ISD::ANY_EXTEND; |
| 2353 | TruncOp = ISD::TRUNCATE; |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2354 | } else { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2355 | ExtOp = ISD::FP_EXTEND; |
| 2356 | TruncOp = ISD::FP_ROUND; |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2357 | } |
| 2358 | // Promote each of the values to the new type. |
| 2359 | Tmp2 = DAG.getNode(ExtOp, NVT, Tmp2); |
| 2360 | Tmp3 = DAG.getNode(ExtOp, NVT, Tmp3); |
| 2361 | // Perform the larger operation, then round down. |
| 2362 | Result = DAG.getNode(ISD::SELECT, NVT, Tmp1, Tmp2,Tmp3); |
| 2363 | Result = DAG.getNode(TruncOp, Node->getValueType(0), Result); |
| 2364 | break; |
| 2365 | } |
| 2366 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2367 | break; |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 2368 | case ISD::SELECT_CC: { |
| 2369 | Tmp1 = Node->getOperand(0); // LHS |
| 2370 | Tmp2 = Node->getOperand(1); // RHS |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 2371 | Tmp3 = LegalizeOp(Node->getOperand(2)); // True |
| 2372 | Tmp4 = LegalizeOp(Node->getOperand(3)); // False |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 2373 | SDOperand CC = Node->getOperand(4); |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 2374 | |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 2375 | LegalizeSetCCOperands(Tmp1, Tmp2, CC); |
| 2376 | |
| 2377 | // If we didn't get both a LHS and RHS back from LegalizeSetCCOperands, |
| 2378 | // the LHS is a legal SETCC itself. In this case, we need to compare |
| 2379 | // the result against zero to select between true and false values. |
| 2380 | if (Tmp2.Val == 0) { |
| 2381 | Tmp2 = DAG.getConstant(0, Tmp1.getValueType()); |
| 2382 | CC = DAG.getCondCode(ISD::SETNE); |
| 2383 | } |
| 2384 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3, Tmp4, CC); |
| 2385 | |
| 2386 | // Everything is legal, see if we should expand this op or something. |
| 2387 | switch (TLI.getOperationAction(ISD::SELECT_CC, Tmp3.getValueType())) { |
| 2388 | default: assert(0 && "This action is not supported yet!"); |
| 2389 | case TargetLowering::Legal: break; |
| 2390 | case TargetLowering::Custom: |
| 2391 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2392 | if (Tmp1.Val) Result = Tmp1; |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 2393 | break; |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 2394 | } |
| 2395 | break; |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 2396 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2397 | case ISD::SETCC: |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 2398 | Tmp1 = Node->getOperand(0); |
| 2399 | Tmp2 = Node->getOperand(1); |
| 2400 | Tmp3 = Node->getOperand(2); |
| 2401 | LegalizeSetCCOperands(Tmp1, Tmp2, Tmp3); |
| 2402 | |
| 2403 | // If we had to Expand the SetCC operands into a SELECT node, then it may |
| 2404 | // not always be possible to return a true LHS & RHS. In this case, just |
| 2405 | // return the value we legalized, returned in the LHS |
| 2406 | if (Tmp2.Val == 0) { |
| 2407 | Result = Tmp1; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2408 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2409 | } |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 2410 | |
Chris Lattner | 73e142f | 2006-01-30 22:43:50 +0000 | [diff] [blame] | 2411 | switch (TLI.getOperationAction(ISD::SETCC, Tmp1.getValueType())) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2412 | default: assert(0 && "Cannot handle this action for SETCC yet!"); |
| 2413 | case TargetLowering::Custom: |
| 2414 | isCustom = true; |
| 2415 | // FALLTHROUGH. |
| 2416 | case TargetLowering::Legal: |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 2417 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2418 | if (isCustom) { |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 2419 | Tmp4 = TLI.LowerOperation(Result, DAG); |
| 2420 | if (Tmp4.Val) Result = Tmp4; |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2421 | } |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 2422 | break; |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 2423 | case TargetLowering::Promote: { |
| 2424 | // First step, figure out the appropriate operation to use. |
| 2425 | // Allow SETCC to not be supported for all legal data types |
| 2426 | // Mostly this targets FP |
| 2427 | MVT::ValueType NewInTy = Node->getOperand(0).getValueType(); |
Chris Lattner | 00755df | 2007-02-04 00:27:56 +0000 | [diff] [blame] | 2428 | MVT::ValueType OldVT = NewInTy; OldVT = OldVT; |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 2429 | |
| 2430 | // Scan for the appropriate larger type to use. |
| 2431 | while (1) { |
| 2432 | NewInTy = (MVT::ValueType)(NewInTy+1); |
| 2433 | |
| 2434 | assert(MVT::isInteger(NewInTy) == MVT::isInteger(OldVT) && |
| 2435 | "Fell off of the edge of the integer world"); |
| 2436 | assert(MVT::isFloatingPoint(NewInTy) == MVT::isFloatingPoint(OldVT) && |
| 2437 | "Fell off of the edge of the floating point world"); |
| 2438 | |
| 2439 | // If the target supports SETCC of this type, use it. |
Chris Lattner | 1ccf26a | 2005-12-22 05:23:45 +0000 | [diff] [blame] | 2440 | if (TLI.isOperationLegal(ISD::SETCC, NewInTy)) |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 2441 | break; |
| 2442 | } |
| 2443 | if (MVT::isInteger(NewInTy)) |
| 2444 | assert(0 && "Cannot promote Legal Integer SETCC yet"); |
| 2445 | else { |
| 2446 | Tmp1 = DAG.getNode(ISD::FP_EXTEND, NewInTy, Tmp1); |
| 2447 | Tmp2 = DAG.getNode(ISD::FP_EXTEND, NewInTy, Tmp2); |
| 2448 | } |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2449 | Tmp1 = LegalizeOp(Tmp1); |
| 2450 | Tmp2 = LegalizeOp(Tmp2); |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 2451 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Evan Cheng | 433f8ac | 2006-01-17 19:47:13 +0000 | [diff] [blame] | 2452 | Result = LegalizeOp(Result); |
Andrew Lenharth | 5e3efbc | 2005-08-29 20:46:51 +0000 | [diff] [blame] | 2453 | break; |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 2454 | } |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 2455 | case TargetLowering::Expand: |
| 2456 | // Expand a setcc node into a select_cc of the same condition, lhs, and |
| 2457 | // rhs that selects between const 1 (true) and const 0 (false). |
| 2458 | MVT::ValueType VT = Node->getValueType(0); |
| 2459 | Result = DAG.getNode(ISD::SELECT_CC, VT, Tmp1, Tmp2, |
| 2460 | DAG.getConstant(1, VT), DAG.getConstant(0, VT), |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 2461 | Tmp3); |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 2462 | break; |
| 2463 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2464 | break; |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 2465 | case ISD::MEMSET: |
| 2466 | case ISD::MEMCPY: |
| 2467 | case ISD::MEMMOVE: { |
Chris Lattner | deb692e | 2005-02-01 18:38:28 +0000 | [diff] [blame] | 2468 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Chain |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 2469 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Pointer |
| 2470 | |
| 2471 | if (Node->getOpcode() == ISD::MEMSET) { // memset = ubyte |
| 2472 | switch (getTypeAction(Node->getOperand(2).getValueType())) { |
| 2473 | case Expand: assert(0 && "Cannot expand a byte!"); |
| 2474 | case Legal: |
Chris Lattner | deb692e | 2005-02-01 18:38:28 +0000 | [diff] [blame] | 2475 | Tmp3 = LegalizeOp(Node->getOperand(2)); |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 2476 | break; |
| 2477 | case Promote: |
Chris Lattner | deb692e | 2005-02-01 18:38:28 +0000 | [diff] [blame] | 2478 | Tmp3 = PromoteOp(Node->getOperand(2)); |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 2479 | break; |
| 2480 | } |
| 2481 | } else { |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2482 | Tmp3 = LegalizeOp(Node->getOperand(2)); // memcpy/move = pointer, |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 2483 | } |
Chris Lattner | 272455b | 2005-02-02 03:44:41 +0000 | [diff] [blame] | 2484 | |
| 2485 | SDOperand Tmp4; |
| 2486 | switch (getTypeAction(Node->getOperand(3).getValueType())) { |
Chris Lattner | 6814f15 | 2005-07-13 01:42:45 +0000 | [diff] [blame] | 2487 | case Expand: { |
| 2488 | // Length is too big, just take the lo-part of the length. |
| 2489 | SDOperand HiPart; |
Chris Lattner | fa9aa2b | 2006-11-07 04:11:44 +0000 | [diff] [blame] | 2490 | ExpandOp(Node->getOperand(3), Tmp4, HiPart); |
Chris Lattner | 6814f15 | 2005-07-13 01:42:45 +0000 | [diff] [blame] | 2491 | break; |
| 2492 | } |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 2493 | case Legal: |
| 2494 | Tmp4 = LegalizeOp(Node->getOperand(3)); |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 2495 | break; |
| 2496 | case Promote: |
| 2497 | Tmp4 = PromoteOp(Node->getOperand(3)); |
Chris Lattner | 272455b | 2005-02-02 03:44:41 +0000 | [diff] [blame] | 2498 | break; |
| 2499 | } |
| 2500 | |
| 2501 | SDOperand Tmp5; |
| 2502 | switch (getTypeAction(Node->getOperand(4).getValueType())) { // uint |
| 2503 | case Expand: assert(0 && "Cannot expand this yet!"); |
| 2504 | case Legal: |
| 2505 | Tmp5 = LegalizeOp(Node->getOperand(4)); |
| 2506 | break; |
| 2507 | case Promote: |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 2508 | Tmp5 = PromoteOp(Node->getOperand(4)); |
| 2509 | break; |
| 2510 | } |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2511 | |
Rafael Espindola | 5c0d6ed | 2007-10-19 10:41:11 +0000 | [diff] [blame] | 2512 | SDOperand Tmp6; |
| 2513 | switch (getTypeAction(Node->getOperand(5).getValueType())) { // bool |
| 2514 | case Expand: assert(0 && "Cannot expand this yet!"); |
| 2515 | case Legal: |
| 2516 | Tmp6 = LegalizeOp(Node->getOperand(5)); |
| 2517 | break; |
| 2518 | case Promote: |
| 2519 | Tmp6 = PromoteOp(Node->getOperand(5)); |
| 2520 | break; |
| 2521 | } |
| 2522 | |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2523 | switch (TLI.getOperationAction(Node->getOpcode(), MVT::Other)) { |
| 2524 | default: assert(0 && "This action not implemented for this operation!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2525 | case TargetLowering::Custom: |
| 2526 | isCustom = true; |
| 2527 | // FALLTHROUGH |
Rafael Espindola | 5c0d6ed | 2007-10-19 10:41:11 +0000 | [diff] [blame] | 2528 | case TargetLowering::Legal: { |
| 2529 | SDOperand Ops[] = { Tmp1, Tmp2, Tmp3, Tmp4, Tmp5, Tmp6 }; |
| 2530 | Result = DAG.UpdateNodeOperands(Result, Ops, 6); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2531 | if (isCustom) { |
| 2532 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2533 | if (Tmp1.Val) Result = Tmp1; |
| 2534 | } |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2535 | break; |
Rafael Espindola | 5c0d6ed | 2007-10-19 10:41:11 +0000 | [diff] [blame] | 2536 | } |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2537 | case TargetLowering::Expand: { |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 2538 | // Otherwise, the target does not support this operation. Lower the |
| 2539 | // operation to an explicit libcall as appropriate. |
| 2540 | MVT::ValueType IntPtr = TLI.getPointerTy(); |
Owen Anderson | a69571c | 2006-05-03 01:29:57 +0000 | [diff] [blame] | 2541 | const Type *IntPtrTy = TLI.getTargetData()->getIntPtrType(); |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 2542 | TargetLowering::ArgListTy Args; |
| 2543 | TargetLowering::ArgListEntry Entry; |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 2544 | |
Reid Spencer | 3bfbf4e | 2005-01-12 14:53:45 +0000 | [diff] [blame] | 2545 | const char *FnName = 0; |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 2546 | if (Node->getOpcode() == ISD::MEMSET) { |
Anton Korobeynikov | d0b82b3 | 2007-03-07 16:25:09 +0000 | [diff] [blame] | 2547 | Entry.Node = Tmp2; Entry.Ty = IntPtrTy; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 2548 | Args.push_back(Entry); |
Chris Lattner | dca7abe | 2006-02-20 06:38:35 +0000 | [diff] [blame] | 2549 | // Extend the (previously legalized) ubyte argument to be an int value |
| 2550 | // for the call. |
| 2551 | if (Tmp3.getValueType() > MVT::i32) |
| 2552 | Tmp3 = DAG.getNode(ISD::TRUNCATE, MVT::i32, Tmp3); |
| 2553 | else |
| 2554 | Tmp3 = DAG.getNode(ISD::ZERO_EXTEND, MVT::i32, Tmp3); |
Anton Korobeynikov | d0b82b3 | 2007-03-07 16:25:09 +0000 | [diff] [blame] | 2555 | Entry.Node = Tmp3; Entry.Ty = Type::Int32Ty; Entry.isSExt = true; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 2556 | Args.push_back(Entry); |
Anton Korobeynikov | d0b82b3 | 2007-03-07 16:25:09 +0000 | [diff] [blame] | 2557 | Entry.Node = Tmp4; Entry.Ty = IntPtrTy; Entry.isSExt = false; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 2558 | Args.push_back(Entry); |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 2559 | |
| 2560 | FnName = "memset"; |
| 2561 | } else if (Node->getOpcode() == ISD::MEMCPY || |
| 2562 | Node->getOpcode() == ISD::MEMMOVE) { |
Anton Korobeynikov | b25fe82 | 2007-02-01 08:39:52 +0000 | [diff] [blame] | 2563 | Entry.Ty = IntPtrTy; |
Reid Spencer | b47b25c | 2007-01-03 04:22:32 +0000 | [diff] [blame] | 2564 | Entry.Node = Tmp2; Args.push_back(Entry); |
| 2565 | Entry.Node = Tmp3; Args.push_back(Entry); |
| 2566 | Entry.Node = Tmp4; Args.push_back(Entry); |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 2567 | FnName = Node->getOpcode() == ISD::MEMMOVE ? "memmove" : "memcpy"; |
| 2568 | } else { |
| 2569 | assert(0 && "Unknown op!"); |
| 2570 | } |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 2571 | |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 2572 | std::pair<SDOperand,SDOperand> CallResult = |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 2573 | TLI.LowerCallTo(Tmp1, Type::VoidTy, false, false, CallingConv::C, false, |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 2574 | DAG.getExternalSymbol(FnName, IntPtr), Args, DAG); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2575 | Result = CallResult.second; |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2576 | break; |
| 2577 | } |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 2578 | } |
| 2579 | break; |
| 2580 | } |
Chris Lattner | 52d08bd | 2005-05-09 20:23:03 +0000 | [diff] [blame] | 2581 | |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 2582 | case ISD::SHL_PARTS: |
| 2583 | case ISD::SRA_PARTS: |
| 2584 | case ISD::SRL_PARTS: { |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 2585 | SmallVector<SDOperand, 8> Ops; |
Chris Lattner | 84f6788 | 2005-01-20 18:52:28 +0000 | [diff] [blame] | 2586 | bool Changed = false; |
| 2587 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) { |
| 2588 | Ops.push_back(LegalizeOp(Node->getOperand(i))); |
| 2589 | Changed |= Ops.back() != Node->getOperand(i); |
| 2590 | } |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2591 | if (Changed) |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 2592 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 2593 | |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 2594 | switch (TLI.getOperationAction(Node->getOpcode(), |
| 2595 | Node->getValueType(0))) { |
| 2596 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2597 | case TargetLowering::Legal: break; |
| 2598 | case TargetLowering::Custom: |
| 2599 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2600 | if (Tmp1.Val) { |
| 2601 | SDOperand Tmp2, RetVal(0, 0); |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 2602 | for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2603 | Tmp2 = LegalizeOp(Tmp1.getValue(i)); |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 2604 | AddLegalizedOperand(SDOperand(Node, i), Tmp2); |
| 2605 | if (i == Op.ResNo) |
Evan Cheng | 12f2274 | 2006-01-19 04:54:52 +0000 | [diff] [blame] | 2606 | RetVal = Tmp2; |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 2607 | } |
Chris Lattner | 269f8c0 | 2006-01-10 19:43:26 +0000 | [diff] [blame] | 2608 | assert(RetVal.Val && "Illegal result number"); |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 2609 | return RetVal; |
| 2610 | } |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 2611 | break; |
| 2612 | } |
| 2613 | |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 2614 | // Since these produce multiple values, make sure to remember that we |
| 2615 | // legalized all of them. |
| 2616 | for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) |
| 2617 | AddLegalizedOperand(SDOperand(Node, i), Result.getValue(i)); |
| 2618 | return Result.getValue(Op.ResNo); |
Chris Lattner | 84f6788 | 2005-01-20 18:52:28 +0000 | [diff] [blame] | 2619 | } |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 2620 | |
| 2621 | // Binary operators |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2622 | case ISD::ADD: |
| 2623 | case ISD::SUB: |
| 2624 | case ISD::MUL: |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 2625 | case ISD::MULHS: |
| 2626 | case ISD::MULHU: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2627 | case ISD::UDIV: |
| 2628 | case ISD::SDIV: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2629 | case ISD::AND: |
| 2630 | case ISD::OR: |
| 2631 | case ISD::XOR: |
Chris Lattner | 03c0cf8 | 2005-01-07 21:45:56 +0000 | [diff] [blame] | 2632 | case ISD::SHL: |
| 2633 | case ISD::SRL: |
| 2634 | case ISD::SRA: |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 2635 | case ISD::FADD: |
| 2636 | case ISD::FSUB: |
| 2637 | case ISD::FMUL: |
| 2638 | case ISD::FDIV: |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 2639 | case ISD::FPOW: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2640 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
Andrew Lenharth | f2eb139 | 2005-07-05 19:52:39 +0000 | [diff] [blame] | 2641 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 2642 | case Expand: assert(0 && "Not possible"); |
| 2643 | case Legal: |
| 2644 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the RHS. |
| 2645 | break; |
| 2646 | case Promote: |
| 2647 | Tmp2 = PromoteOp(Node->getOperand(1)); // Promote the RHS. |
| 2648 | break; |
| 2649 | } |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2650 | |
| 2651 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2652 | |
Andrew Lenharth | e8f65f1 | 2005-12-24 23:42:32 +0000 | [diff] [blame] | 2653 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
Chris Lattner | bc70cf8 | 2006-04-02 03:57:31 +0000 | [diff] [blame] | 2654 | default: assert(0 && "BinOp legalize operation not supported"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2655 | case TargetLowering::Legal: break; |
| 2656 | case TargetLowering::Custom: |
| 2657 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2658 | if (Tmp1.Val) Result = Tmp1; |
Andrew Lenharth | 57030e3 | 2005-12-25 01:07:37 +0000 | [diff] [blame] | 2659 | break; |
Chris Lattner | bc70cf8 | 2006-04-02 03:57:31 +0000 | [diff] [blame] | 2660 | case TargetLowering::Expand: { |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 2661 | MVT::ValueType VT = Op.getValueType(); |
| 2662 | |
| 2663 | // See if multiply or divide can be lowered using two-result operations. |
| 2664 | SDVTList VTs = DAG.getVTList(VT, VT); |
| 2665 | if (Node->getOpcode() == ISD::MUL) { |
| 2666 | // We just need the low half of the multiply; try both the signed |
| 2667 | // and unsigned forms. If the target supports both SMUL_LOHI and |
| 2668 | // UMUL_LOHI, form a preference by checking which forms of plain |
| 2669 | // MULH it supports. |
| 2670 | bool HasSMUL_LOHI = TLI.isOperationLegal(ISD::SMUL_LOHI, VT); |
| 2671 | bool HasUMUL_LOHI = TLI.isOperationLegal(ISD::UMUL_LOHI, VT); |
| 2672 | bool HasMULHS = TLI.isOperationLegal(ISD::MULHS, VT); |
| 2673 | bool HasMULHU = TLI.isOperationLegal(ISD::MULHU, VT); |
| 2674 | unsigned OpToUse = 0; |
| 2675 | if (HasSMUL_LOHI && !HasMULHS) { |
| 2676 | OpToUse = ISD::SMUL_LOHI; |
| 2677 | } else if (HasUMUL_LOHI && !HasMULHU) { |
| 2678 | OpToUse = ISD::UMUL_LOHI; |
| 2679 | } else if (HasSMUL_LOHI) { |
| 2680 | OpToUse = ISD::SMUL_LOHI; |
| 2681 | } else if (HasUMUL_LOHI) { |
| 2682 | OpToUse = ISD::UMUL_LOHI; |
| 2683 | } |
| 2684 | if (OpToUse) { |
| 2685 | Result = SDOperand(DAG.getNode(OpToUse, VTs, Tmp1, Tmp2).Val, 0); |
| 2686 | break; |
| 2687 | } |
| 2688 | } |
| 2689 | if (Node->getOpcode() == ISD::MULHS && |
| 2690 | TLI.isOperationLegal(ISD::SMUL_LOHI, VT)) { |
| 2691 | Result = SDOperand(DAG.getNode(ISD::SMUL_LOHI, VTs, Tmp1, Tmp2).Val, 1); |
| 2692 | break; |
| 2693 | } |
| 2694 | if (Node->getOpcode() == ISD::MULHU && |
| 2695 | TLI.isOperationLegal(ISD::UMUL_LOHI, VT)) { |
| 2696 | Result = SDOperand(DAG.getNode(ISD::UMUL_LOHI, VTs, Tmp1, Tmp2).Val, 1); |
| 2697 | break; |
| 2698 | } |
| 2699 | if (Node->getOpcode() == ISD::SDIV && |
| 2700 | TLI.isOperationLegal(ISD::SDIVREM, VT)) { |
| 2701 | Result = SDOperand(DAG.getNode(ISD::SDIVREM, VTs, Tmp1, Tmp2).Val, 0); |
| 2702 | break; |
| 2703 | } |
| 2704 | if (Node->getOpcode() == ISD::UDIV && |
| 2705 | TLI.isOperationLegal(ISD::UDIVREM, VT)) { |
| 2706 | Result = SDOperand(DAG.getNode(ISD::UDIVREM, VTs, Tmp1, Tmp2).Val, 0); |
| 2707 | break; |
| 2708 | } |
| 2709 | |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 2710 | // Check to see if we have a libcall for this operator. |
| 2711 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
| 2712 | bool isSigned = false; |
| 2713 | switch (Node->getOpcode()) { |
| 2714 | case ISD::UDIV: |
| 2715 | case ISD::SDIV: |
| 2716 | if (VT == MVT::i32) { |
| 2717 | LC = Node->getOpcode() == ISD::UDIV |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 2718 | ? RTLIB::UDIV_I32 : RTLIB::SDIV_I32; |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 2719 | isSigned = Node->getOpcode() == ISD::SDIV; |
| 2720 | } |
| 2721 | break; |
| 2722 | case ISD::FPOW: |
| 2723 | LC = VT == MVT::f32 ? RTLIB::POW_F32 : |
| 2724 | VT == MVT::f64 ? RTLIB::POW_F64 : |
| 2725 | VT == MVT::f80 ? RTLIB::POW_F80 : |
| 2726 | VT == MVT::ppcf128 ? RTLIB::POW_PPCF128 : |
| 2727 | RTLIB::UNKNOWN_LIBCALL; |
| 2728 | break; |
| 2729 | default: break; |
| 2730 | } |
| 2731 | if (LC != RTLIB::UNKNOWN_LIBCALL) { |
| 2732 | SDOperand Dummy; |
| 2733 | Result = ExpandLibCall(TLI.getLibcallName(LC), Node, isSigned, Dummy); |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 2734 | break; |
| 2735 | } |
| 2736 | |
Chris Lattner | bc70cf8 | 2006-04-02 03:57:31 +0000 | [diff] [blame] | 2737 | assert(MVT::isVector(Node->getValueType(0)) && |
| 2738 | "Cannot expand this binary operator!"); |
| 2739 | // Expand the operation into a bunch of nasty scalar code. |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 2740 | Result = LegalizeOp(UnrollVectorOp(Op)); |
Chris Lattner | bc70cf8 | 2006-04-02 03:57:31 +0000 | [diff] [blame] | 2741 | break; |
| 2742 | } |
Evan Cheng | cc98761 | 2006-04-12 21:20:24 +0000 | [diff] [blame] | 2743 | case TargetLowering::Promote: { |
| 2744 | switch (Node->getOpcode()) { |
| 2745 | default: assert(0 && "Do not know how to promote this BinOp!"); |
| 2746 | case ISD::AND: |
| 2747 | case ISD::OR: |
| 2748 | case ISD::XOR: { |
| 2749 | MVT::ValueType OVT = Node->getValueType(0); |
| 2750 | MVT::ValueType NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT); |
| 2751 | assert(MVT::isVector(OVT) && "Cannot promote this BinOp!"); |
| 2752 | // Bit convert each of the values to the new type. |
| 2753 | Tmp1 = DAG.getNode(ISD::BIT_CONVERT, NVT, Tmp1); |
| 2754 | Tmp2 = DAG.getNode(ISD::BIT_CONVERT, NVT, Tmp2); |
| 2755 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 2756 | // Bit convert the result back the original type. |
| 2757 | Result = DAG.getNode(ISD::BIT_CONVERT, OVT, Result); |
| 2758 | break; |
| 2759 | } |
| 2760 | } |
| 2761 | } |
Andrew Lenharth | e8f65f1 | 2005-12-24 23:42:32 +0000 | [diff] [blame] | 2762 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2763 | break; |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 2764 | |
Dan Gohman | e14ea86 | 2007-10-05 14:17:22 +0000 | [diff] [blame] | 2765 | case ISD::SMUL_LOHI: |
| 2766 | case ISD::UMUL_LOHI: |
| 2767 | case ISD::SDIVREM: |
| 2768 | case ISD::UDIVREM: |
| 2769 | // These nodes will only be produced by target-specific lowering, so |
| 2770 | // they shouldn't be here if they aren't legal. |
Duncan Sands | a7c97a7 | 2007-10-16 09:07:20 +0000 | [diff] [blame] | 2771 | assert(TLI.isOperationLegal(Node->getOpcode(), Node->getValueType(0)) && |
Dan Gohman | e14ea86 | 2007-10-05 14:17:22 +0000 | [diff] [blame] | 2772 | "This must be legal!"); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 2773 | |
| 2774 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
| 2775 | Tmp2 = LegalizeOp(Node->getOperand(1)); // RHS |
| 2776 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Dan Gohman | e14ea86 | 2007-10-05 14:17:22 +0000 | [diff] [blame] | 2777 | break; |
| 2778 | |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 2779 | case ISD::FCOPYSIGN: // FCOPYSIGN does not require LHS/RHS to match type! |
| 2780 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
| 2781 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 2782 | case Expand: assert(0 && "Not possible"); |
| 2783 | case Legal: |
| 2784 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the RHS. |
| 2785 | break; |
| 2786 | case Promote: |
| 2787 | Tmp2 = PromoteOp(Node->getOperand(1)); // Promote the RHS. |
| 2788 | break; |
| 2789 | } |
| 2790 | |
| 2791 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 2792 | |
| 2793 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 2794 | default: assert(0 && "Operation not supported"); |
| 2795 | case TargetLowering::Custom: |
| 2796 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2797 | if (Tmp1.Val) Result = Tmp1; |
Chris Lattner | 8f4191d | 2006-03-13 06:08:38 +0000 | [diff] [blame] | 2798 | break; |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 2799 | case TargetLowering::Legal: break; |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 2800 | case TargetLowering::Expand: { |
Evan Cheng | 636c753 | 2007-01-05 23:33:44 +0000 | [diff] [blame] | 2801 | // If this target supports fabs/fneg natively and select is cheap, |
| 2802 | // do this efficiently. |
| 2803 | if (!TLI.isSelectExpensive() && |
| 2804 | TLI.getOperationAction(ISD::FABS, Tmp1.getValueType()) == |
| 2805 | TargetLowering::Legal && |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 2806 | TLI.getOperationAction(ISD::FNEG, Tmp1.getValueType()) == |
Evan Cheng | 636c753 | 2007-01-05 23:33:44 +0000 | [diff] [blame] | 2807 | TargetLowering::Legal) { |
Chris Lattner | 8f4191d | 2006-03-13 06:08:38 +0000 | [diff] [blame] | 2808 | // Get the sign bit of the RHS. |
| 2809 | MVT::ValueType IVT = |
| 2810 | Tmp2.getValueType() == MVT::f32 ? MVT::i32 : MVT::i64; |
| 2811 | SDOperand SignBit = DAG.getNode(ISD::BIT_CONVERT, IVT, Tmp2); |
| 2812 | SignBit = DAG.getSetCC(TLI.getSetCCResultTy(), |
| 2813 | SignBit, DAG.getConstant(0, IVT), ISD::SETLT); |
| 2814 | // Get the absolute value of the result. |
| 2815 | SDOperand AbsVal = DAG.getNode(ISD::FABS, Tmp1.getValueType(), Tmp1); |
| 2816 | // Select between the nabs and abs value based on the sign bit of |
| 2817 | // the input. |
| 2818 | Result = DAG.getNode(ISD::SELECT, AbsVal.getValueType(), SignBit, |
| 2819 | DAG.getNode(ISD::FNEG, AbsVal.getValueType(), |
| 2820 | AbsVal), |
| 2821 | AbsVal); |
| 2822 | Result = LegalizeOp(Result); |
| 2823 | break; |
| 2824 | } |
| 2825 | |
| 2826 | // Otherwise, do bitwise ops! |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 2827 | MVT::ValueType NVT = |
| 2828 | Node->getValueType(0) == MVT::f32 ? MVT::i32 : MVT::i64; |
| 2829 | Result = ExpandFCOPYSIGNToBitwiseOps(Node, NVT, DAG, TLI); |
| 2830 | Result = DAG.getNode(ISD::BIT_CONVERT, Node->getValueType(0), Result); |
| 2831 | Result = LegalizeOp(Result); |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 2832 | break; |
| 2833 | } |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 2834 | } |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 2835 | break; |
| 2836 | |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 2837 | case ISD::ADDC: |
| 2838 | case ISD::SUBC: |
| 2839 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 2840 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 2841 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 2842 | // Since this produces two values, make sure to remember that we legalized |
| 2843 | // both of them. |
| 2844 | AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0)); |
| 2845 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
| 2846 | return Result; |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2847 | |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 2848 | case ISD::ADDE: |
| 2849 | case ISD::SUBE: |
| 2850 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 2851 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 2852 | Tmp3 = LegalizeOp(Node->getOperand(2)); |
| 2853 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
| 2854 | // Since this produces two values, make sure to remember that we legalized |
| 2855 | // both of them. |
| 2856 | AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0)); |
| 2857 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
| 2858 | return Result; |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 2859 | |
Nate Begeman | 419f8b6 | 2005-10-18 00:27:41 +0000 | [diff] [blame] | 2860 | case ISD::BUILD_PAIR: { |
| 2861 | MVT::ValueType PairTy = Node->getValueType(0); |
| 2862 | // TODO: handle the case where the Lo and Hi operands are not of legal type |
| 2863 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Lo |
| 2864 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Hi |
| 2865 | switch (TLI.getOperationAction(ISD::BUILD_PAIR, PairTy)) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2866 | case TargetLowering::Promote: |
| 2867 | case TargetLowering::Custom: |
| 2868 | assert(0 && "Cannot promote/custom this yet!"); |
Nate Begeman | 419f8b6 | 2005-10-18 00:27:41 +0000 | [diff] [blame] | 2869 | case TargetLowering::Legal: |
| 2870 | if (Tmp1 != Node->getOperand(0) || Tmp2 != Node->getOperand(1)) |
| 2871 | Result = DAG.getNode(ISD::BUILD_PAIR, PairTy, Tmp1, Tmp2); |
| 2872 | break; |
Nate Begeman | 419f8b6 | 2005-10-18 00:27:41 +0000 | [diff] [blame] | 2873 | case TargetLowering::Expand: |
| 2874 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, PairTy, Tmp1); |
| 2875 | Tmp2 = DAG.getNode(ISD::ANY_EXTEND, PairTy, Tmp2); |
| 2876 | Tmp2 = DAG.getNode(ISD::SHL, PairTy, Tmp2, |
| 2877 | DAG.getConstant(MVT::getSizeInBits(PairTy)/2, |
| 2878 | TLI.getShiftAmountTy())); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2879 | Result = DAG.getNode(ISD::OR, PairTy, Tmp1, Tmp2); |
Nate Begeman | 419f8b6 | 2005-10-18 00:27:41 +0000 | [diff] [blame] | 2880 | break; |
| 2881 | } |
| 2882 | break; |
| 2883 | } |
| 2884 | |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 2885 | case ISD::UREM: |
| 2886 | case ISD::SREM: |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 2887 | case ISD::FREM: |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 2888 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
| 2889 | Tmp2 = LegalizeOp(Node->getOperand(1)); // RHS |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2890 | |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 2891 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2892 | case TargetLowering::Promote: assert(0 && "Cannot promote this yet!"); |
| 2893 | case TargetLowering::Custom: |
| 2894 | isCustom = true; |
| 2895 | // FALLTHROUGH |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 2896 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2897 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2898 | if (isCustom) { |
| 2899 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2900 | if (Tmp1.Val) Result = Tmp1; |
| 2901 | } |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 2902 | break; |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 2903 | case TargetLowering::Expand: { |
Evan Cheng | 6b5578f | 2006-09-18 23:28:33 +0000 | [diff] [blame] | 2904 | unsigned DivOpc= (Node->getOpcode() == ISD::UREM) ? ISD::UDIV : ISD::SDIV; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 2905 | bool isSigned = DivOpc == ISD::SDIV; |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 2906 | MVT::ValueType VT = Node->getValueType(0); |
| 2907 | |
| 2908 | // See if remainder can be lowered using two-result operations. |
| 2909 | SDVTList VTs = DAG.getVTList(VT, VT); |
| 2910 | if (Node->getOpcode() == ISD::SREM && |
| 2911 | TLI.isOperationLegal(ISD::SDIVREM, VT)) { |
| 2912 | Result = SDOperand(DAG.getNode(ISD::SDIVREM, VTs, Tmp1, Tmp2).Val, 1); |
| 2913 | break; |
| 2914 | } |
| 2915 | if (Node->getOpcode() == ISD::UREM && |
| 2916 | TLI.isOperationLegal(ISD::UDIVREM, VT)) { |
| 2917 | Result = SDOperand(DAG.getNode(ISD::UDIVREM, VTs, Tmp1, Tmp2).Val, 1); |
| 2918 | break; |
| 2919 | } |
| 2920 | |
| 2921 | if (MVT::isInteger(VT)) { |
| 2922 | if (TLI.getOperationAction(DivOpc, VT) == |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 2923 | TargetLowering::Legal) { |
| 2924 | // X % Y -> X-X/Y*Y |
Evan Cheng | 6b5578f | 2006-09-18 23:28:33 +0000 | [diff] [blame] | 2925 | Result = DAG.getNode(DivOpc, VT, Tmp1, Tmp2); |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 2926 | Result = DAG.getNode(ISD::MUL, VT, Result, Tmp2); |
| 2927 | Result = DAG.getNode(ISD::SUB, VT, Tmp1, Result); |
| 2928 | } else { |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 2929 | assert(VT == MVT::i32 && |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 2930 | "Cannot expand this binary operator!"); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 2931 | RTLIB::Libcall LC = Node->getOpcode() == ISD::UREM |
| 2932 | ? RTLIB::UREM_I32 : RTLIB::SREM_I32; |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 2933 | SDOperand Dummy; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 2934 | Result = ExpandLibCall(TLI.getLibcallName(LC), Node, isSigned, Dummy); |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 2935 | } |
Chris Lattner | 4c64dd7 | 2005-08-03 20:31:37 +0000 | [diff] [blame] | 2936 | } else { |
| 2937 | // Floating point mod -> fmod libcall. |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 2938 | RTLIB::Libcall LC = VT == MVT::f32 |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 2939 | ? RTLIB::REM_F32 : RTLIB::REM_F64; |
Chris Lattner | 4c64dd7 | 2005-08-03 20:31:37 +0000 | [diff] [blame] | 2940 | SDOperand Dummy; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 2941 | Result = ExpandLibCall(TLI.getLibcallName(LC), Node, |
| 2942 | false/*sign irrelevant*/, Dummy); |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 2943 | } |
| 2944 | break; |
| 2945 | } |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 2946 | } |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 2947 | break; |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 2948 | case ISD::VAARG: { |
| 2949 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 2950 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. |
| 2951 | |
Chris Lattner | 5c62f33 | 2006-01-28 07:42:08 +0000 | [diff] [blame] | 2952 | MVT::ValueType VT = Node->getValueType(0); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 2953 | switch (TLI.getOperationAction(Node->getOpcode(), MVT::Other)) { |
| 2954 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2955 | case TargetLowering::Custom: |
| 2956 | isCustom = true; |
| 2957 | // FALLTHROUGH |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 2958 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2959 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
| 2960 | Result = Result.getValue(0); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2961 | Tmp1 = Result.getValue(1); |
| 2962 | |
| 2963 | if (isCustom) { |
| 2964 | Tmp2 = TLI.LowerOperation(Result, DAG); |
| 2965 | if (Tmp2.Val) { |
| 2966 | Result = LegalizeOp(Tmp2); |
| 2967 | Tmp1 = LegalizeOp(Tmp2.getValue(1)); |
| 2968 | } |
| 2969 | } |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 2970 | break; |
| 2971 | case TargetLowering::Expand: { |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2972 | SrcValueSDNode *SV = cast<SrcValueSDNode>(Node->getOperand(2)); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 2973 | SDOperand VAList = DAG.getLoad(TLI.getPointerTy(), Tmp1, Tmp2, |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2974 | SV->getValue(), SV->getOffset()); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 2975 | // Increment the pointer, VAList, to the next vaarg |
| 2976 | Tmp3 = DAG.getNode(ISD::ADD, TLI.getPointerTy(), VAList, |
| 2977 | DAG.getConstant(MVT::getSizeInBits(VT)/8, |
| 2978 | TLI.getPointerTy())); |
| 2979 | // Store the incremented VAList to the legalized pointer |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2980 | Tmp3 = DAG.getStore(VAList.getValue(1), Tmp3, Tmp2, SV->getValue(), |
| 2981 | SV->getOffset()); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 2982 | // Load the actual argument out of the pointer VAList |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2983 | Result = DAG.getLoad(VT, Tmp3, VAList, NULL, 0); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2984 | Tmp1 = LegalizeOp(Result.getValue(1)); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 2985 | Result = LegalizeOp(Result); |
| 2986 | break; |
| 2987 | } |
| 2988 | } |
| 2989 | // Since VAARG produces two values, make sure to remember that we |
| 2990 | // legalized both of them. |
| 2991 | AddLegalizedOperand(SDOperand(Node, 0), Result); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2992 | AddLegalizedOperand(SDOperand(Node, 1), Tmp1); |
| 2993 | return Op.ResNo ? Tmp1 : Result; |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 2994 | } |
| 2995 | |
| 2996 | case ISD::VACOPY: |
| 2997 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 2998 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the dest pointer. |
| 2999 | Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the source pointer. |
| 3000 | |
| 3001 | switch (TLI.getOperationAction(ISD::VACOPY, MVT::Other)) { |
| 3002 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3003 | case TargetLowering::Custom: |
| 3004 | isCustom = true; |
| 3005 | // FALLTHROUGH |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3006 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3007 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3, |
| 3008 | Node->getOperand(3), Node->getOperand(4)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3009 | if (isCustom) { |
| 3010 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 3011 | if (Tmp1.Val) Result = Tmp1; |
| 3012 | } |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3013 | break; |
| 3014 | case TargetLowering::Expand: |
| 3015 | // This defaults to loading a pointer from the input and storing it to the |
| 3016 | // output, returning the chain. |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 3017 | SrcValueSDNode *SVD = cast<SrcValueSDNode>(Node->getOperand(3)); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 3018 | SrcValueSDNode *SVS = cast<SrcValueSDNode>(Node->getOperand(4)); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 3019 | Tmp4 = DAG.getLoad(TLI.getPointerTy(), Tmp1, Tmp3, SVD->getValue(), |
| 3020 | SVD->getOffset()); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 3021 | Result = DAG.getStore(Tmp4.getValue(1), Tmp4, Tmp2, SVS->getValue(), |
| 3022 | SVS->getOffset()); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3023 | break; |
| 3024 | } |
| 3025 | break; |
| 3026 | |
| 3027 | case ISD::VAEND: |
| 3028 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 3029 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. |
| 3030 | |
| 3031 | switch (TLI.getOperationAction(ISD::VAEND, MVT::Other)) { |
| 3032 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3033 | case TargetLowering::Custom: |
| 3034 | isCustom = true; |
| 3035 | // FALLTHROUGH |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3036 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3037 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3038 | if (isCustom) { |
| 3039 | Tmp1 = TLI.LowerOperation(Tmp1, DAG); |
| 3040 | if (Tmp1.Val) Result = Tmp1; |
| 3041 | } |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3042 | break; |
| 3043 | case TargetLowering::Expand: |
| 3044 | Result = Tmp1; // Default to a no-op, return the chain |
| 3045 | break; |
| 3046 | } |
| 3047 | break; |
| 3048 | |
| 3049 | case ISD::VASTART: |
| 3050 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 3051 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. |
| 3052 | |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3053 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
| 3054 | |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3055 | switch (TLI.getOperationAction(ISD::VASTART, MVT::Other)) { |
| 3056 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3057 | case TargetLowering::Legal: break; |
| 3058 | case TargetLowering::Custom: |
| 3059 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 3060 | if (Tmp1.Val) Result = Tmp1; |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3061 | break; |
| 3062 | } |
| 3063 | break; |
| 3064 | |
Nate Begeman | 35ef913 | 2006-01-11 21:21:00 +0000 | [diff] [blame] | 3065 | case ISD::ROTL: |
| 3066 | case ISD::ROTR: |
| 3067 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
| 3068 | Tmp2 = LegalizeOp(Node->getOperand(1)); // RHS |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3069 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Scott Michel | c9dc114 | 2007-04-02 21:36:32 +0000 | [diff] [blame] | 3070 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 3071 | default: |
| 3072 | assert(0 && "ROTL/ROTR legalize operation not supported"); |
| 3073 | break; |
| 3074 | case TargetLowering::Legal: |
| 3075 | break; |
| 3076 | case TargetLowering::Custom: |
| 3077 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 3078 | if (Tmp1.Val) Result = Tmp1; |
| 3079 | break; |
| 3080 | case TargetLowering::Promote: |
| 3081 | assert(0 && "Do not know how to promote ROTL/ROTR"); |
| 3082 | break; |
| 3083 | case TargetLowering::Expand: |
| 3084 | assert(0 && "Do not know how to expand ROTL/ROTR"); |
| 3085 | break; |
| 3086 | } |
Nate Begeman | 35ef913 | 2006-01-11 21:21:00 +0000 | [diff] [blame] | 3087 | break; |
| 3088 | |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 3089 | case ISD::BSWAP: |
| 3090 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Op |
| 3091 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3092 | case TargetLowering::Custom: |
| 3093 | assert(0 && "Cannot custom legalize this yet!"); |
| 3094 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3095 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3096 | break; |
| 3097 | case TargetLowering::Promote: { |
| 3098 | MVT::ValueType OVT = Tmp1.getValueType(); |
| 3099 | MVT::ValueType NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT); |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 3100 | unsigned DiffBits = MVT::getSizeInBits(NVT) - MVT::getSizeInBits(OVT); |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 3101 | |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3102 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Tmp1); |
| 3103 | Tmp1 = DAG.getNode(ISD::BSWAP, NVT, Tmp1); |
| 3104 | Result = DAG.getNode(ISD::SRL, NVT, Tmp1, |
| 3105 | DAG.getConstant(DiffBits, TLI.getShiftAmountTy())); |
| 3106 | break; |
| 3107 | } |
| 3108 | case TargetLowering::Expand: |
| 3109 | Result = ExpandBSWAP(Tmp1); |
| 3110 | break; |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 3111 | } |
| 3112 | break; |
| 3113 | |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3114 | case ISD::CTPOP: |
| 3115 | case ISD::CTTZ: |
| 3116 | case ISD::CTLZ: |
| 3117 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Op |
| 3118 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
Scott Michel | 910b66d | 2007-07-30 21:00:31 +0000 | [diff] [blame] | 3119 | case TargetLowering::Custom: |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3120 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3121 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Scott Michel | 910b66d | 2007-07-30 21:00:31 +0000 | [diff] [blame] | 3122 | if (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0)) == |
Scott Michel | 335f4f7 | 2007-08-02 02:22:46 +0000 | [diff] [blame] | 3123 | TargetLowering::Custom) { |
| 3124 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 3125 | if (Tmp1.Val) { |
| 3126 | Result = Tmp1; |
| 3127 | } |
Scott Michel | 910b66d | 2007-07-30 21:00:31 +0000 | [diff] [blame] | 3128 | } |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3129 | break; |
| 3130 | case TargetLowering::Promote: { |
| 3131 | MVT::ValueType OVT = Tmp1.getValueType(); |
| 3132 | MVT::ValueType NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT); |
Chris Lattner | edb1add | 2005-05-11 04:51:16 +0000 | [diff] [blame] | 3133 | |
| 3134 | // Zero extend the argument. |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3135 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Tmp1); |
| 3136 | // Perform the larger operation, then subtract if needed. |
| 3137 | Tmp1 = DAG.getNode(Node->getOpcode(), Node->getValueType(0), Tmp1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3138 | switch (Node->getOpcode()) { |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3139 | case ISD::CTPOP: |
| 3140 | Result = Tmp1; |
| 3141 | break; |
| 3142 | case ISD::CTTZ: |
| 3143 | //if Tmp1 == sizeinbits(NVT) then Tmp1 = sizeinbits(Old VT) |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 3144 | Tmp2 = DAG.getSetCC(TLI.getSetCCResultTy(), Tmp1, |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 3145 | DAG.getConstant(MVT::getSizeInBits(NVT), NVT), |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 3146 | ISD::SETEQ); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 3147 | Result = DAG.getNode(ISD::SELECT, NVT, Tmp2, |
Scott Michel | 910b66d | 2007-07-30 21:00:31 +0000 | [diff] [blame] | 3148 | DAG.getConstant(MVT::getSizeInBits(OVT),NVT), Tmp1); |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3149 | break; |
| 3150 | case ISD::CTLZ: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3151 | // Tmp1 = Tmp1 - (sizeinbits(NVT) - sizeinbits(Old VT)) |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 3152 | Result = DAG.getNode(ISD::SUB, NVT, Tmp1, |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 3153 | DAG.getConstant(MVT::getSizeInBits(NVT) - |
| 3154 | MVT::getSizeInBits(OVT), NVT)); |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3155 | break; |
| 3156 | } |
| 3157 | break; |
| 3158 | } |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3159 | case TargetLowering::Expand: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3160 | Result = ExpandBitCount(Node->getOpcode(), Tmp1); |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3161 | break; |
| 3162 | } |
| 3163 | break; |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 3164 | |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3165 | // Unary operators |
| 3166 | case ISD::FABS: |
| 3167 | case ISD::FNEG: |
Chris Lattner | da6ba87 | 2005-04-28 21:44:33 +0000 | [diff] [blame] | 3168 | case ISD::FSQRT: |
| 3169 | case ISD::FSIN: |
| 3170 | case ISD::FCOS: |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3171 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 3172 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3173 | case TargetLowering::Promote: |
| 3174 | case TargetLowering::Custom: |
Evan Cheng | 59ad781 | 2006-01-31 18:14:25 +0000 | [diff] [blame] | 3175 | isCustom = true; |
| 3176 | // FALLTHROUGH |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3177 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3178 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Evan Cheng | 59ad781 | 2006-01-31 18:14:25 +0000 | [diff] [blame] | 3179 | if (isCustom) { |
| 3180 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 3181 | if (Tmp1.Val) Result = Tmp1; |
| 3182 | } |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3183 | break; |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3184 | case TargetLowering::Expand: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3185 | switch (Node->getOpcode()) { |
| 3186 | default: assert(0 && "Unreachable!"); |
| 3187 | case ISD::FNEG: |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3188 | // Expand Y = FNEG(X) -> Y = SUB -0.0, X |
| 3189 | Tmp2 = DAG.getConstantFP(-0.0, Node->getValueType(0)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3190 | Result = DAG.getNode(ISD::FSUB, Node->getValueType(0), Tmp2, Tmp1); |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 3191 | break; |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 3192 | case ISD::FABS: { |
Chris Lattner | 4af6e0d | 2005-04-02 05:26:37 +0000 | [diff] [blame] | 3193 | // Expand Y = FABS(X) -> Y = (X >u 0.0) ? X : fneg(X). |
| 3194 | MVT::ValueType VT = Node->getValueType(0); |
| 3195 | Tmp2 = DAG.getConstantFP(0.0, VT); |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 3196 | Tmp2 = DAG.getSetCC(TLI.getSetCCResultTy(), Tmp1, Tmp2, ISD::SETUGT); |
Chris Lattner | 4af6e0d | 2005-04-02 05:26:37 +0000 | [diff] [blame] | 3197 | Tmp3 = DAG.getNode(ISD::FNEG, VT, Tmp1); |
| 3198 | Result = DAG.getNode(ISD::SELECT, VT, Tmp2, Tmp1, Tmp3); |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 3199 | break; |
| 3200 | } |
| 3201 | case ISD::FSQRT: |
| 3202 | case ISD::FSIN: |
| 3203 | case ISD::FCOS: { |
| 3204 | MVT::ValueType VT = Node->getValueType(0); |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3205 | |
| 3206 | // Expand unsupported unary vector operators by unrolling them. |
| 3207 | if (MVT::isVector(VT)) { |
| 3208 | Result = LegalizeOp(UnrollVectorOp(Op)); |
| 3209 | break; |
| 3210 | } |
| 3211 | |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3212 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 3213 | switch(Node->getOpcode()) { |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3214 | case ISD::FSQRT: |
Dale Johannesen | 317096a | 2007-09-28 01:08:20 +0000 | [diff] [blame] | 3215 | LC = VT == MVT::f32 ? RTLIB::SQRT_F32 : |
Dale Johannesen | 161e897 | 2007-10-05 20:04:43 +0000 | [diff] [blame] | 3216 | VT == MVT::f64 ? RTLIB::SQRT_F64 : |
| 3217 | VT == MVT::f80 ? RTLIB::SQRT_F80 : |
| 3218 | VT == MVT::ppcf128 ? RTLIB::SQRT_PPCF128 : |
| 3219 | RTLIB::UNKNOWN_LIBCALL; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3220 | break; |
| 3221 | case ISD::FSIN: |
| 3222 | LC = VT == MVT::f32 ? RTLIB::SIN_F32 : RTLIB::SIN_F64; |
| 3223 | break; |
| 3224 | case ISD::FCOS: |
| 3225 | LC = VT == MVT::f32 ? RTLIB::COS_F32 : RTLIB::COS_F64; |
| 3226 | break; |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 3227 | default: assert(0 && "Unreachable!"); |
| 3228 | } |
Nate Begeman | 2ac4fc0 | 2005-08-04 21:43:28 +0000 | [diff] [blame] | 3229 | SDOperand Dummy; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3230 | Result = ExpandLibCall(TLI.getLibcallName(LC), Node, |
| 3231 | false/*sign irrelevant*/, Dummy); |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 3232 | break; |
| 3233 | } |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3234 | } |
| 3235 | break; |
| 3236 | } |
| 3237 | break; |
Chris Lattner | 6ddf8ed | 2006-09-09 06:03:30 +0000 | [diff] [blame] | 3238 | case ISD::FPOWI: { |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3239 | MVT::ValueType VT = Node->getValueType(0); |
| 3240 | |
| 3241 | // Expand unsupported unary vector operators by unrolling them. |
| 3242 | if (MVT::isVector(VT)) { |
| 3243 | Result = LegalizeOp(UnrollVectorOp(Op)); |
| 3244 | break; |
| 3245 | } |
| 3246 | |
| 3247 | // We always lower FPOWI into a libcall. No target support for it yet. |
Dale Johannesen | 317096a | 2007-09-28 01:08:20 +0000 | [diff] [blame] | 3248 | RTLIB::Libcall LC = |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3249 | VT == MVT::f32 ? RTLIB::POWI_F32 : |
| 3250 | VT == MVT::f64 ? RTLIB::POWI_F64 : |
| 3251 | VT == MVT::f80 ? RTLIB::POWI_F80 : |
| 3252 | VT == MVT::ppcf128 ? RTLIB::POWI_PPCF128 : |
Dale Johannesen | 161e897 | 2007-10-05 20:04:43 +0000 | [diff] [blame] | 3253 | RTLIB::UNKNOWN_LIBCALL; |
Chris Lattner | 6ddf8ed | 2006-09-09 06:03:30 +0000 | [diff] [blame] | 3254 | SDOperand Dummy; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3255 | Result = ExpandLibCall(TLI.getLibcallName(LC), Node, |
| 3256 | false/*sign irrelevant*/, Dummy); |
Chris Lattner | 6ddf8ed | 2006-09-09 06:03:30 +0000 | [diff] [blame] | 3257 | break; |
| 3258 | } |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 3259 | case ISD::BIT_CONVERT: |
Chris Lattner | 67993f7 | 2006-01-23 07:30:46 +0000 | [diff] [blame] | 3260 | if (!isTypeLegal(Node->getOperand(0).getValueType())) { |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 3261 | Result = ExpandBIT_CONVERT(Node->getValueType(0), Node->getOperand(0)); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3262 | } else if (MVT::isVector(Op.getOperand(0).getValueType())) { |
| 3263 | // The input has to be a vector type, we have to either scalarize it, pack |
| 3264 | // it, or convert it based on whether the input vector type is legal. |
| 3265 | SDNode *InVal = Node->getOperand(0).Val; |
Dale Johannesen | e526962 | 2007-10-20 00:07:52 +0000 | [diff] [blame] | 3266 | int InIx = Node->getOperand(0).ResNo; |
| 3267 | unsigned NumElems = MVT::getVectorNumElements(InVal->getValueType(InIx)); |
| 3268 | MVT::ValueType EVT = MVT::getVectorElementType(InVal->getValueType(InIx)); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3269 | |
| 3270 | // Figure out if there is a simple type corresponding to this Vector |
| 3271 | // type. If so, convert to the vector type. |
| 3272 | MVT::ValueType TVT = MVT::getVectorType(EVT, NumElems); |
| 3273 | if (TLI.isTypeLegal(TVT)) { |
Dan Gohman | 07a9676 | 2007-07-16 14:29:03 +0000 | [diff] [blame] | 3274 | // Turn this into a bit convert of the vector input. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3275 | Result = DAG.getNode(ISD::BIT_CONVERT, Node->getValueType(0), |
| 3276 | LegalizeOp(Node->getOperand(0))); |
| 3277 | break; |
| 3278 | } else if (NumElems == 1) { |
| 3279 | // Turn this into a bit convert of the scalar input. |
| 3280 | Result = DAG.getNode(ISD::BIT_CONVERT, Node->getValueType(0), |
| 3281 | ScalarizeVectorOp(Node->getOperand(0))); |
| 3282 | break; |
| 3283 | } else { |
| 3284 | // FIXME: UNIMP! Store then reload |
| 3285 | assert(0 && "Cast from unsupported vector type not implemented yet!"); |
| 3286 | } |
Chris Lattner | 67993f7 | 2006-01-23 07:30:46 +0000 | [diff] [blame] | 3287 | } else { |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 3288 | switch (TLI.getOperationAction(ISD::BIT_CONVERT, |
| 3289 | Node->getOperand(0).getValueType())) { |
| 3290 | default: assert(0 && "Unknown operation action!"); |
| 3291 | case TargetLowering::Expand: |
| 3292 | Result = ExpandBIT_CONVERT(Node->getValueType(0), Node->getOperand(0)); |
| 3293 | break; |
| 3294 | case TargetLowering::Legal: |
| 3295 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3296 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 3297 | break; |
| 3298 | } |
| 3299 | } |
| 3300 | break; |
Chris Lattner | d1f04d4 | 2006-03-24 02:26:29 +0000 | [diff] [blame] | 3301 | |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3302 | // Conversion operators. The source and destination have different types. |
Chris Lattner | ae0aacb | 2005-01-08 08:08:56 +0000 | [diff] [blame] | 3303 | case ISD::SINT_TO_FP: |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3304 | case ISD::UINT_TO_FP: { |
| 3305 | bool isSigned = Node->getOpcode() == ISD::SINT_TO_FP; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3306 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3307 | case Legal: |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 3308 | switch (TLI.getOperationAction(Node->getOpcode(), |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3309 | Node->getOperand(0).getValueType())) { |
| 3310 | default: assert(0 && "Unknown operation action!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3311 | case TargetLowering::Custom: |
| 3312 | isCustom = true; |
| 3313 | // FALLTHROUGH |
| 3314 | case TargetLowering::Legal: |
| 3315 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3316 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3317 | if (isCustom) { |
| 3318 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 3319 | if (Tmp1.Val) Result = Tmp1; |
| 3320 | } |
| 3321 | break; |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3322 | case TargetLowering::Expand: |
Jim Laskey | 6269ed1 | 2005-08-17 00:39:29 +0000 | [diff] [blame] | 3323 | Result = ExpandLegalINT_TO_FP(isSigned, |
| 3324 | LegalizeOp(Node->getOperand(0)), |
| 3325 | Node->getValueType(0)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3326 | break; |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3327 | case TargetLowering::Promote: |
| 3328 | Result = PromoteLegalINT_TO_FP(LegalizeOp(Node->getOperand(0)), |
| 3329 | Node->getValueType(0), |
| 3330 | isSigned); |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3331 | break; |
Andrew Lenharth | 5b5b8c2 | 2005-11-30 06:43:03 +0000 | [diff] [blame] | 3332 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3333 | break; |
Chris Lattner | b00a642 | 2005-01-07 22:37:48 +0000 | [diff] [blame] | 3334 | case Expand: |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3335 | Result = ExpandIntToFP(Node->getOpcode() == ISD::SINT_TO_FP, |
| 3336 | Node->getValueType(0), Node->getOperand(0)); |
| 3337 | break; |
| 3338 | case Promote: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3339 | Tmp1 = PromoteOp(Node->getOperand(0)); |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3340 | if (isSigned) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3341 | Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, Tmp1.getValueType(), |
| 3342 | Tmp1, DAG.getValueType(Node->getOperand(0).getValueType())); |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3343 | } else { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3344 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, |
| 3345 | Node->getOperand(0).getValueType()); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 3346 | } |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3347 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 3348 | Result = LegalizeOp(Result); // The 'op' is not necessarily legal! |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3349 | break; |
| 3350 | } |
| 3351 | break; |
| 3352 | } |
| 3353 | case ISD::TRUNCATE: |
| 3354 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3355 | case Legal: |
| 3356 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3357 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3358 | break; |
| 3359 | case Expand: |
| 3360 | ExpandOp(Node->getOperand(0), Tmp1, Tmp2); |
| 3361 | |
| 3362 | // Since the result is legal, we should just be able to truncate the low |
| 3363 | // part of the source. |
| 3364 | Result = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0), Tmp1); |
| 3365 | break; |
| 3366 | case Promote: |
| 3367 | Result = PromoteOp(Node->getOperand(0)); |
| 3368 | Result = DAG.getNode(ISD::TRUNCATE, Op.getValueType(), Result); |
| 3369 | break; |
| 3370 | } |
| 3371 | break; |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 3372 | |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3373 | case ISD::FP_TO_SINT: |
| 3374 | case ISD::FP_TO_UINT: |
| 3375 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3376 | case Legal: |
Chris Lattner | f1fa74e | 2005-07-30 00:04:12 +0000 | [diff] [blame] | 3377 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 3378 | |
Chris Lattner | 1618beb | 2005-07-29 00:11:56 +0000 | [diff] [blame] | 3379 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))){ |
| 3380 | default: assert(0 && "Unknown operation action!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3381 | case TargetLowering::Custom: |
| 3382 | isCustom = true; |
| 3383 | // FALLTHROUGH |
| 3384 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3385 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3386 | if (isCustom) { |
| 3387 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 3388 | if (Tmp1.Val) Result = Tmp1; |
| 3389 | } |
| 3390 | break; |
| 3391 | case TargetLowering::Promote: |
| 3392 | Result = PromoteLegalFP_TO_INT(Tmp1, Node->getValueType(0), |
| 3393 | Node->getOpcode() == ISD::FP_TO_SINT); |
| 3394 | break; |
Chris Lattner | 1618beb | 2005-07-29 00:11:56 +0000 | [diff] [blame] | 3395 | case TargetLowering::Expand: |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 3396 | if (Node->getOpcode() == ISD::FP_TO_UINT) { |
| 3397 | SDOperand True, False; |
| 3398 | MVT::ValueType VT = Node->getOperand(0).getValueType(); |
| 3399 | MVT::ValueType NVT = Node->getValueType(0); |
Dale Johannesen | f4d4832 | 2007-09-19 17:53:26 +0000 | [diff] [blame] | 3400 | unsigned ShiftAmt = MVT::getSizeInBits(NVT)-1; |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 3401 | const uint64_t zero[] = {0, 0}; |
| 3402 | APFloat apf = APFloat(APInt(MVT::getSizeInBits(VT), 2, zero)); |
| 3403 | uint64_t x = 1ULL << ShiftAmt; |
Neil Booth | ccf596a | 2007-10-07 11:45:55 +0000 | [diff] [blame] | 3404 | (void)apf.convertFromZeroExtendedInteger |
| 3405 | (&x, MVT::getSizeInBits(NVT), false, APFloat::rmNearestTiesToEven); |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 3406 | Tmp2 = DAG.getConstantFP(apf, VT); |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 3407 | Tmp3 = DAG.getSetCC(TLI.getSetCCResultTy(), |
| 3408 | Node->getOperand(0), Tmp2, ISD::SETLT); |
| 3409 | True = DAG.getNode(ISD::FP_TO_SINT, NVT, Node->getOperand(0)); |
| 3410 | False = DAG.getNode(ISD::FP_TO_SINT, NVT, |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 3411 | DAG.getNode(ISD::FSUB, VT, Node->getOperand(0), |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 3412 | Tmp2)); |
| 3413 | False = DAG.getNode(ISD::XOR, NVT, False, |
| 3414 | DAG.getConstant(1ULL << ShiftAmt, NVT)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3415 | Result = DAG.getNode(ISD::SELECT, NVT, Tmp3, True, False); |
| 3416 | break; |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 3417 | } else { |
| 3418 | assert(0 && "Do not know how to expand FP_TO_SINT yet!"); |
| 3419 | } |
| 3420 | break; |
Chris Lattner | 07dffd6 | 2005-08-26 00:14:16 +0000 | [diff] [blame] | 3421 | } |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3422 | break; |
Evan Cheng | 6af00d5 | 2006-12-13 01:57:55 +0000 | [diff] [blame] | 3423 | case Expand: { |
Evan Cheng | 6af00d5 | 2006-12-13 01:57:55 +0000 | [diff] [blame] | 3424 | MVT::ValueType VT = Op.getValueType(); |
Dale Johannesen | 6eaeff2 | 2007-10-10 01:01:31 +0000 | [diff] [blame] | 3425 | MVT::ValueType OVT = Node->getOperand(0).getValueType(); |
Dale Johannesen | fcf4d24 | 2007-10-11 23:32:15 +0000 | [diff] [blame] | 3426 | // Convert ppcf128 to i32 |
Dale Johannesen | 6eaeff2 | 2007-10-10 01:01:31 +0000 | [diff] [blame] | 3427 | if (OVT == MVT::ppcf128 && VT == MVT::i32) { |
Dale Johannesen | fcf4d24 | 2007-10-11 23:32:15 +0000 | [diff] [blame] | 3428 | if (Node->getOpcode()==ISD::FP_TO_SINT) |
| 3429 | Result = DAG.getNode(ISD::FP_TO_SINT, VT, |
Dale Johannesen | 6eaeff2 | 2007-10-10 01:01:31 +0000 | [diff] [blame] | 3430 | DAG.getNode(ISD::FP_ROUND, MVT::f64, |
| 3431 | (DAG.getNode(ISD::FP_ROUND_INREG, |
| 3432 | MVT::ppcf128, Node->getOperand(0), |
| 3433 | DAG.getValueType(MVT::f64))))); |
Dale Johannesen | fcf4d24 | 2007-10-11 23:32:15 +0000 | [diff] [blame] | 3434 | else { |
| 3435 | const uint64_t TwoE31[] = {0x41e0000000000000LL, 0}; |
| 3436 | APFloat apf = APFloat(APInt(128, 2, TwoE31)); |
| 3437 | Tmp2 = DAG.getConstantFP(apf, OVT); |
| 3438 | // X>=2^31 ? (int)(X-2^31)+0x80000000 : (int)X |
| 3439 | // FIXME: generated code sucks. |
| 3440 | Result = DAG.getNode(ISD::SELECT_CC, VT, Node->getOperand(0), Tmp2, |
| 3441 | DAG.getNode(ISD::ADD, MVT::i32, |
| 3442 | DAG.getNode(ISD::FP_TO_SINT, VT, |
| 3443 | DAG.getNode(ISD::FSUB, OVT, |
| 3444 | Node->getOperand(0), Tmp2)), |
| 3445 | DAG.getConstant(0x80000000, MVT::i32)), |
| 3446 | DAG.getNode(ISD::FP_TO_SINT, VT, |
| 3447 | Node->getOperand(0)), |
| 3448 | DAG.getCondCode(ISD::SETGE)); |
| 3449 | } |
Dale Johannesen | 6eaeff2 | 2007-10-10 01:01:31 +0000 | [diff] [blame] | 3450 | break; |
| 3451 | } |
Dale Johannesen | fcf4d24 | 2007-10-11 23:32:15 +0000 | [diff] [blame] | 3452 | // Convert f32 / f64 to i32 / i64. |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3453 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
Evan Cheng | 6af00d5 | 2006-12-13 01:57:55 +0000 | [diff] [blame] | 3454 | switch (Node->getOpcode()) { |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 3455 | case ISD::FP_TO_SINT: { |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 3456 | if (OVT == MVT::f32) |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3457 | LC = (VT == MVT::i32) |
| 3458 | ? RTLIB::FPTOSINT_F32_I32 : RTLIB::FPTOSINT_F32_I64; |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 3459 | else if (OVT == MVT::f64) |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3460 | LC = (VT == MVT::i32) |
| 3461 | ? RTLIB::FPTOSINT_F64_I32 : RTLIB::FPTOSINT_F64_I64; |
Dale Johannesen | 161e897 | 2007-10-05 20:04:43 +0000 | [diff] [blame] | 3462 | else if (OVT == MVT::f80) { |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 3463 | assert(VT == MVT::i64); |
Dale Johannesen | 161e897 | 2007-10-05 20:04:43 +0000 | [diff] [blame] | 3464 | LC = RTLIB::FPTOSINT_F80_I64; |
| 3465 | } |
| 3466 | else if (OVT == MVT::ppcf128) { |
| 3467 | assert(VT == MVT::i64); |
| 3468 | LC = RTLIB::FPTOSINT_PPCF128_I64; |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 3469 | } |
Evan Cheng | 6af00d5 | 2006-12-13 01:57:55 +0000 | [diff] [blame] | 3470 | break; |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 3471 | } |
| 3472 | case ISD::FP_TO_UINT: { |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 3473 | if (OVT == MVT::f32) |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3474 | LC = (VT == MVT::i32) |
| 3475 | ? RTLIB::FPTOUINT_F32_I32 : RTLIB::FPTOSINT_F32_I64; |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 3476 | else if (OVT == MVT::f64) |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3477 | LC = (VT == MVT::i32) |
| 3478 | ? RTLIB::FPTOUINT_F64_I32 : RTLIB::FPTOSINT_F64_I64; |
Dale Johannesen | 161e897 | 2007-10-05 20:04:43 +0000 | [diff] [blame] | 3479 | else if (OVT == MVT::f80) { |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 3480 | LC = (VT == MVT::i32) |
Dale Johannesen | 161e897 | 2007-10-05 20:04:43 +0000 | [diff] [blame] | 3481 | ? RTLIB::FPTOUINT_F80_I32 : RTLIB::FPTOUINT_F80_I64; |
| 3482 | } |
| 3483 | else if (OVT == MVT::ppcf128) { |
| 3484 | assert(VT == MVT::i64); |
| 3485 | LC = RTLIB::FPTOUINT_PPCF128_I64; |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 3486 | } |
Evan Cheng | 6af00d5 | 2006-12-13 01:57:55 +0000 | [diff] [blame] | 3487 | break; |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 3488 | } |
Evan Cheng | 6af00d5 | 2006-12-13 01:57:55 +0000 | [diff] [blame] | 3489 | default: assert(0 && "Unreachable!"); |
| 3490 | } |
| 3491 | SDOperand Dummy; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3492 | Result = ExpandLibCall(TLI.getLibcallName(LC), Node, |
| 3493 | false/*sign irrelevant*/, Dummy); |
Evan Cheng | 6af00d5 | 2006-12-13 01:57:55 +0000 | [diff] [blame] | 3494 | break; |
| 3495 | } |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3496 | case Promote: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3497 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 3498 | Result = DAG.UpdateNodeOperands(Result, LegalizeOp(Tmp1)); |
| 3499 | Result = LegalizeOp(Result); |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3500 | break; |
| 3501 | } |
| 3502 | break; |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 3503 | |
Dale Johannesen | ab081c7 | 2007-08-09 17:27:48 +0000 | [diff] [blame] | 3504 | case ISD::FP_EXTEND: |
Dale Johannesen | 5411a39 | 2007-08-09 01:04:01 +0000 | [diff] [blame] | 3505 | case ISD::FP_ROUND: { |
| 3506 | MVT::ValueType newVT = Op.getValueType(); |
| 3507 | MVT::ValueType oldVT = Op.getOperand(0).getValueType(); |
| 3508 | if (TLI.getConvertAction(oldVT, newVT) == TargetLowering::Expand) { |
Dale Johannesen | 638ccd5 | 2007-10-06 01:24:11 +0000 | [diff] [blame] | 3509 | if (Node->getOpcode() == ISD::FP_ROUND && oldVT == MVT::ppcf128) { |
| 3510 | SDOperand Lo, Hi; |
| 3511 | ExpandOp(Node->getOperand(0), Lo, Hi); |
| 3512 | if (newVT == MVT::f64) |
| 3513 | Result = Hi; |
| 3514 | else |
| 3515 | Result = DAG.getNode(ISD::FP_ROUND, newVT, Hi); |
| 3516 | break; |
Dale Johannesen | ab081c7 | 2007-08-09 17:27:48 +0000 | [diff] [blame] | 3517 | } else { |
Dale Johannesen | 638ccd5 | 2007-10-06 01:24:11 +0000 | [diff] [blame] | 3518 | // The only other way we can lower this is to turn it into a STORE, |
| 3519 | // LOAD pair, targetting a temporary location (a stack slot). |
| 3520 | |
| 3521 | // NOTE: there is a choice here between constantly creating new stack |
| 3522 | // slots and always reusing the same one. We currently always create |
| 3523 | // new ones, as reuse may inhibit scheduling. |
| 3524 | MVT::ValueType slotVT = |
| 3525 | (Node->getOpcode() == ISD::FP_EXTEND) ? oldVT : newVT; |
| 3526 | const Type *Ty = MVT::getTypeForValueType(slotVT); |
| 3527 | uint64_t TySize = TLI.getTargetData()->getTypeSize(Ty); |
| 3528 | unsigned Align = TLI.getTargetData()->getPrefTypeAlignment(Ty); |
| 3529 | MachineFunction &MF = DAG.getMachineFunction(); |
| 3530 | int SSFI = |
| 3531 | MF.getFrameInfo()->CreateStackObject(TySize, Align); |
| 3532 | SDOperand StackSlot = DAG.getFrameIndex(SSFI, TLI.getPointerTy()); |
| 3533 | if (Node->getOpcode() == ISD::FP_EXTEND) { |
| 3534 | Result = DAG.getStore(DAG.getEntryNode(), Node->getOperand(0), |
| 3535 | StackSlot, NULL, 0); |
| 3536 | Result = DAG.getExtLoad(ISD::EXTLOAD, newVT, |
| 3537 | Result, StackSlot, NULL, 0, oldVT); |
| 3538 | } else { |
| 3539 | Result = DAG.getTruncStore(DAG.getEntryNode(), Node->getOperand(0), |
| 3540 | StackSlot, NULL, 0, newVT); |
Duncan Sands | a7c97a7 | 2007-10-16 09:07:20 +0000 | [diff] [blame] | 3541 | Result = DAG.getLoad(newVT, Result, StackSlot, NULL, 0); |
Dale Johannesen | 638ccd5 | 2007-10-06 01:24:11 +0000 | [diff] [blame] | 3542 | } |
| 3543 | break; |
Dale Johannesen | ab081c7 | 2007-08-09 17:27:48 +0000 | [diff] [blame] | 3544 | } |
Dale Johannesen | 5411a39 | 2007-08-09 01:04:01 +0000 | [diff] [blame] | 3545 | } |
Dale Johannesen | 849f214 | 2007-07-03 00:53:03 +0000 | [diff] [blame] | 3546 | } |
| 3547 | // FALL THROUGH |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 3548 | case ISD::ANY_EXTEND: |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3549 | case ISD::ZERO_EXTEND: |
| 3550 | case ISD::SIGN_EXTEND: |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3551 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3552 | case Expand: assert(0 && "Shouldn't need to expand other operators here!"); |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3553 | case Legal: |
| 3554 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3555 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3556 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3557 | case Promote: |
| 3558 | switch (Node->getOpcode()) { |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 3559 | case ISD::ANY_EXTEND: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3560 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 3561 | Result = DAG.getNode(ISD::ANY_EXTEND, Op.getValueType(), Tmp1); |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 3562 | break; |
Chris Lattner | 1713e73 | 2005-01-16 00:38:00 +0000 | [diff] [blame] | 3563 | case ISD::ZERO_EXTEND: |
| 3564 | Result = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 3565 | Result = DAG.getNode(ISD::ANY_EXTEND, Op.getValueType(), Result); |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 3566 | Result = DAG.getZeroExtendInReg(Result, |
| 3567 | Node->getOperand(0).getValueType()); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3568 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3569 | case ISD::SIGN_EXTEND: |
Chris Lattner | 1713e73 | 2005-01-16 00:38:00 +0000 | [diff] [blame] | 3570 | Result = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 3571 | Result = DAG.getNode(ISD::ANY_EXTEND, Op.getValueType(), Result); |
Chris Lattner | 1713e73 | 2005-01-16 00:38:00 +0000 | [diff] [blame] | 3572 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(), |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 3573 | Result, |
| 3574 | DAG.getValueType(Node->getOperand(0).getValueType())); |
Chris Lattner | 1713e73 | 2005-01-16 00:38:00 +0000 | [diff] [blame] | 3575 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3576 | case ISD::FP_EXTEND: |
Chris Lattner | 1713e73 | 2005-01-16 00:38:00 +0000 | [diff] [blame] | 3577 | Result = PromoteOp(Node->getOperand(0)); |
| 3578 | if (Result.getValueType() != Op.getValueType()) |
| 3579 | // Dynamically dead while we have only 2 FP types. |
| 3580 | Result = DAG.getNode(ISD::FP_EXTEND, Op.getValueType(), Result); |
| 3581 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3582 | case ISD::FP_ROUND: |
Chris Lattner | f8161d8 | 2005-01-16 05:06:12 +0000 | [diff] [blame] | 3583 | Result = PromoteOp(Node->getOperand(0)); |
| 3584 | Result = DAG.getNode(Node->getOpcode(), Op.getValueType(), Result); |
| 3585 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3586 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3587 | } |
| 3588 | break; |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 3589 | case ISD::FP_ROUND_INREG: |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 3590 | case ISD::SIGN_EXTEND_INREG: { |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 3591 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 3592 | MVT::ValueType ExtraVT = cast<VTSDNode>(Node->getOperand(1))->getVT(); |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 3593 | |
| 3594 | // If this operation is not supported, convert it to a shl/shr or load/store |
| 3595 | // pair. |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 3596 | switch (TLI.getOperationAction(Node->getOpcode(), ExtraVT)) { |
| 3597 | default: assert(0 && "This action not supported for this op yet!"); |
| 3598 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3599 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 3600 | break; |
| 3601 | case TargetLowering::Expand: |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 3602 | // If this is an integer extend and shifts are supported, do that. |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 3603 | if (Node->getOpcode() == ISD::SIGN_EXTEND_INREG) { |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 3604 | // NOTE: we could fall back on load/store here too for targets without |
| 3605 | // SAR. However, it is doubtful that any exist. |
| 3606 | unsigned BitsDiff = MVT::getSizeInBits(Node->getValueType(0)) - |
| 3607 | MVT::getSizeInBits(ExtraVT); |
Chris Lattner | 27ff112 | 2005-01-22 00:31:52 +0000 | [diff] [blame] | 3608 | SDOperand ShiftCst = DAG.getConstant(BitsDiff, TLI.getShiftAmountTy()); |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 3609 | Result = DAG.getNode(ISD::SHL, Node->getValueType(0), |
| 3610 | Node->getOperand(0), ShiftCst); |
| 3611 | Result = DAG.getNode(ISD::SRA, Node->getValueType(0), |
| 3612 | Result, ShiftCst); |
| 3613 | } else if (Node->getOpcode() == ISD::FP_ROUND_INREG) { |
Jim Laskey | 2d84c4c | 2006-10-11 17:52:19 +0000 | [diff] [blame] | 3614 | // 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] | 3615 | // EXTLOAD pair, targetting a temporary location (a stack slot). |
| 3616 | |
| 3617 | // NOTE: there is a choice here between constantly creating new stack |
| 3618 | // slots and always reusing the same one. We currently always create |
| 3619 | // new ones, as reuse may inhibit scheduling. |
| 3620 | const Type *Ty = MVT::getTypeForValueType(ExtraVT); |
Chris Lattner | 44b2c50 | 2007-04-28 06:42:38 +0000 | [diff] [blame] | 3621 | uint64_t TySize = TLI.getTargetData()->getTypeSize(Ty); |
Chris Lattner | d2b7cec | 2007-02-14 05:52:17 +0000 | [diff] [blame] | 3622 | unsigned Align = TLI.getTargetData()->getPrefTypeAlignment(Ty); |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 3623 | MachineFunction &MF = DAG.getMachineFunction(); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 3624 | int SSFI = |
Chris Lattner | 44b2c50 | 2007-04-28 06:42:38 +0000 | [diff] [blame] | 3625 | MF.getFrameInfo()->CreateStackObject(TySize, Align); |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 3626 | SDOperand StackSlot = DAG.getFrameIndex(SSFI, TLI.getPointerTy()); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 3627 | Result = DAG.getTruncStore(DAG.getEntryNode(), Node->getOperand(0), |
| 3628 | StackSlot, NULL, 0, ExtraVT); |
Chris Lattner | 5f056bf | 2005-07-10 01:55:33 +0000 | [diff] [blame] | 3629 | Result = DAG.getExtLoad(ISD::EXTLOAD, Node->getValueType(0), |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 3630 | Result, StackSlot, NULL, 0, ExtraVT); |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 3631 | } else { |
| 3632 | assert(0 && "Unknown op"); |
| 3633 | } |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 3634 | break; |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 3635 | } |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 3636 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3637 | } |
Duncan Sands | 36397f5 | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 3638 | case ISD::TRAMPOLINE: { |
| 3639 | SDOperand Ops[6]; |
| 3640 | for (unsigned i = 0; i != 6; ++i) |
| 3641 | Ops[i] = LegalizeOp(Node->getOperand(i)); |
| 3642 | Result = DAG.UpdateNodeOperands(Result, Ops, 6); |
| 3643 | // The only option for this node is to custom lower it. |
| 3644 | Result = TLI.LowerOperation(Result, DAG); |
| 3645 | assert(Result.Val && "Should always custom lower!"); |
Duncan Sands | f7331b3 | 2007-09-11 14:10:23 +0000 | [diff] [blame] | 3646 | |
| 3647 | // Since trampoline produces two values, make sure to remember that we |
| 3648 | // legalized both of them. |
| 3649 | Tmp1 = LegalizeOp(Result.getValue(1)); |
| 3650 | Result = LegalizeOp(Result); |
| 3651 | AddLegalizedOperand(SDOperand(Node, 0), Result); |
| 3652 | AddLegalizedOperand(SDOperand(Node, 1), Tmp1); |
| 3653 | return Op.ResNo ? Tmp1 : Result; |
Duncan Sands | 36397f5 | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 3654 | } |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 3655 | } |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3656 | |
Chris Lattner | 4ddd283 | 2006-04-08 04:13:17 +0000 | [diff] [blame] | 3657 | assert(Result.getValueType() == Op.getValueType() && |
| 3658 | "Bad legalization!"); |
| 3659 | |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3660 | // Make sure that the generated code is itself legal. |
| 3661 | if (Result != Op) |
| 3662 | Result = LegalizeOp(Result); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3663 | |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 3664 | // Note that LegalizeOp may be reentered even from single-use nodes, which |
| 3665 | // means that we always must cache transformed nodes. |
| 3666 | AddLegalizedOperand(Op, Result); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3667 | return Result; |
| 3668 | } |
| 3669 | |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3670 | /// PromoteOp - Given an operation that produces a value in an invalid type, |
| 3671 | /// promote it to compute the value into a larger type. The produced value will |
| 3672 | /// have the correct bits for the low portion of the register, but no guarantee |
| 3673 | /// 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] | 3674 | SDOperand SelectionDAGLegalize::PromoteOp(SDOperand Op) { |
| 3675 | MVT::ValueType VT = Op.getValueType(); |
Chris Lattner | 71c42a0 | 2005-01-16 01:11:45 +0000 | [diff] [blame] | 3676 | MVT::ValueType NVT = TLI.getTypeToTransformTo(VT); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3677 | assert(getTypeAction(VT) == Promote && |
| 3678 | "Caller should expand or legalize operands that are not promotable!"); |
| 3679 | assert(NVT > VT && MVT::isInteger(NVT) == MVT::isInteger(VT) && |
| 3680 | "Cannot promote to smaller type!"); |
| 3681 | |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3682 | SDOperand Tmp1, Tmp2, Tmp3; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3683 | SDOperand Result; |
| 3684 | SDNode *Node = Op.Val; |
| 3685 | |
Chris Lattner | 40030bf | 2007-02-04 01:17:38 +0000 | [diff] [blame] | 3686 | DenseMap<SDOperand, SDOperand>::iterator I = PromotedNodes.find(Op); |
Chris Lattner | 6fdcb25 | 2005-09-02 20:32:45 +0000 | [diff] [blame] | 3687 | if (I != PromotedNodes.end()) return I->second; |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 3688 | |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3689 | switch (Node->getOpcode()) { |
Chris Lattner | d5d0f9b | 2005-08-16 21:55:35 +0000 | [diff] [blame] | 3690 | case ISD::CopyFromReg: |
| 3691 | assert(0 && "CopyFromReg must be legal!"); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3692 | default: |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 3693 | #ifndef NDEBUG |
Dan Gohman | 3983358 | 2007-06-04 16:17:33 +0000 | [diff] [blame] | 3694 | cerr << "NODE: "; Node->dump(&DAG); cerr << "\n"; |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 3695 | #endif |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3696 | assert(0 && "Do not know how to promote this operator!"); |
| 3697 | abort(); |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 3698 | case ISD::UNDEF: |
| 3699 | Result = DAG.getNode(ISD::UNDEF, NVT); |
| 3700 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3701 | case ISD::Constant: |
Chris Lattner | ec176e3 | 2005-08-30 16:56:19 +0000 | [diff] [blame] | 3702 | if (VT != MVT::i1) |
| 3703 | Result = DAG.getNode(ISD::SIGN_EXTEND, NVT, Op); |
| 3704 | else |
| 3705 | Result = DAG.getNode(ISD::ZERO_EXTEND, NVT, Op); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3706 | assert(isa<ConstantSDNode>(Result) && "Didn't constant fold zext?"); |
| 3707 | break; |
| 3708 | case ISD::ConstantFP: |
| 3709 | Result = DAG.getNode(ISD::FP_EXTEND, NVT, Op); |
| 3710 | assert(isa<ConstantFPSDNode>(Result) && "Didn't constant fold fp_extend?"); |
| 3711 | break; |
Chris Lattner | ef5cd1d | 2005-01-18 17:54:55 +0000 | [diff] [blame] | 3712 | |
Chris Lattner | 82fbfb6 | 2005-01-18 02:59:52 +0000 | [diff] [blame] | 3713 | case ISD::SETCC: |
Chris Lattner | c9c60f6 | 2005-08-24 16:35:28 +0000 | [diff] [blame] | 3714 | assert(isTypeLegal(TLI.getSetCCResultTy()) && "SetCC type is not legal??"); |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 3715 | Result = DAG.getNode(ISD::SETCC, TLI.getSetCCResultTy(),Node->getOperand(0), |
| 3716 | Node->getOperand(1), Node->getOperand(2)); |
Chris Lattner | 82fbfb6 | 2005-01-18 02:59:52 +0000 | [diff] [blame] | 3717 | break; |
Chris Lattner | fdfded5 | 2006-04-12 16:20:43 +0000 | [diff] [blame] | 3718 | |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3719 | case ISD::TRUNCATE: |
| 3720 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3721 | case Legal: |
| 3722 | Result = LegalizeOp(Node->getOperand(0)); |
| 3723 | assert(Result.getValueType() >= NVT && |
| 3724 | "This truncation doesn't make sense!"); |
| 3725 | if (Result.getValueType() > NVT) // Truncate to NVT instead of VT |
| 3726 | Result = DAG.getNode(ISD::TRUNCATE, NVT, Result); |
| 3727 | break; |
Chris Lattner | e76ad6d | 2005-01-28 22:52:50 +0000 | [diff] [blame] | 3728 | case Promote: |
| 3729 | // The truncation is not required, because we don't guarantee anything |
| 3730 | // about high bits anyway. |
| 3731 | Result = PromoteOp(Node->getOperand(0)); |
| 3732 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3733 | case Expand: |
Nate Begeman | 79e46ac | 2005-04-04 00:57:08 +0000 | [diff] [blame] | 3734 | ExpandOp(Node->getOperand(0), Tmp1, Tmp2); |
| 3735 | // Truncate the low part of the expanded value to the result type |
Chris Lattner | e21c305 | 2005-08-01 18:16:37 +0000 | [diff] [blame] | 3736 | Result = DAG.getNode(ISD::TRUNCATE, NVT, Tmp1); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3737 | } |
| 3738 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3739 | case ISD::SIGN_EXTEND: |
| 3740 | case ISD::ZERO_EXTEND: |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 3741 | case ISD::ANY_EXTEND: |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3742 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3743 | case Expand: assert(0 && "BUG: Smaller reg should have been promoted!"); |
| 3744 | case Legal: |
| 3745 | // 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] | 3746 | Result = DAG.getNode(Node->getOpcode(), NVT, Node->getOperand(0)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3747 | break; |
| 3748 | case Promote: |
| 3749 | // Promote the reg if it's smaller. |
| 3750 | Result = PromoteOp(Node->getOperand(0)); |
| 3751 | // The high bits are not guaranteed to be anything. Insert an extend. |
| 3752 | if (Node->getOpcode() == ISD::SIGN_EXTEND) |
Chris Lattner | 595dc54 | 2005-02-04 18:39:19 +0000 | [diff] [blame] | 3753 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Result, |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 3754 | DAG.getValueType(Node->getOperand(0).getValueType())); |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 3755 | else if (Node->getOpcode() == ISD::ZERO_EXTEND) |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 3756 | Result = DAG.getZeroExtendInReg(Result, |
| 3757 | Node->getOperand(0).getValueType()); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3758 | break; |
| 3759 | } |
| 3760 | break; |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 3761 | case ISD::BIT_CONVERT: |
| 3762 | Result = ExpandBIT_CONVERT(Node->getValueType(0), Node->getOperand(0)); |
| 3763 | Result = PromoteOp(Result); |
| 3764 | break; |
| 3765 | |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3766 | case ISD::FP_EXTEND: |
| 3767 | assert(0 && "Case not implemented. Dynamically dead with 2 FP types!"); |
| 3768 | case ISD::FP_ROUND: |
| 3769 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3770 | case Expand: assert(0 && "BUG: Cannot expand FP regs!"); |
| 3771 | case Promote: assert(0 && "Unreachable with 2 FP types!"); |
| 3772 | case Legal: |
| 3773 | // Input is legal? Do an FP_ROUND_INREG. |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3774 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Node->getOperand(0), |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 3775 | DAG.getValueType(VT)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3776 | break; |
| 3777 | } |
| 3778 | break; |
| 3779 | |
| 3780 | case ISD::SINT_TO_FP: |
| 3781 | case ISD::UINT_TO_FP: |
| 3782 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3783 | case Legal: |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 3784 | // No extra round required here. |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3785 | Result = DAG.getNode(Node->getOpcode(), NVT, Node->getOperand(0)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3786 | break; |
| 3787 | |
| 3788 | case Promote: |
| 3789 | Result = PromoteOp(Node->getOperand(0)); |
| 3790 | if (Node->getOpcode() == ISD::SINT_TO_FP) |
| 3791 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(), |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 3792 | Result, |
| 3793 | DAG.getValueType(Node->getOperand(0).getValueType())); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3794 | else |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 3795 | Result = DAG.getZeroExtendInReg(Result, |
| 3796 | Node->getOperand(0).getValueType()); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 3797 | // No extra round required here. |
| 3798 | Result = DAG.getNode(Node->getOpcode(), NVT, Result); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3799 | break; |
| 3800 | case Expand: |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 3801 | Result = ExpandIntToFP(Node->getOpcode() == ISD::SINT_TO_FP, NVT, |
| 3802 | Node->getOperand(0)); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 3803 | // Round if we cannot tolerate excess precision. |
| 3804 | if (NoExcessFPPrecision) |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 3805 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 3806 | DAG.getValueType(VT)); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 3807 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3808 | } |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3809 | break; |
| 3810 | |
Chris Lattner | 5e3c5b4 | 2005-12-09 17:32:47 +0000 | [diff] [blame] | 3811 | case ISD::SIGN_EXTEND_INREG: |
| 3812 | Result = PromoteOp(Node->getOperand(0)); |
| 3813 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Result, |
| 3814 | Node->getOperand(1)); |
| 3815 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3816 | case ISD::FP_TO_SINT: |
| 3817 | case ISD::FP_TO_UINT: |
| 3818 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3819 | case Legal: |
Evan Cheng | 0b1b9dc | 2006-12-16 02:10:30 +0000 | [diff] [blame] | 3820 | case Expand: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3821 | Tmp1 = Node->getOperand(0); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3822 | break; |
| 3823 | case Promote: |
| 3824 | // The input result is prerounded, so we don't have to do anything |
| 3825 | // special. |
| 3826 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 3827 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3828 | } |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 3829 | // If we're promoting a UINT to a larger size, check to see if the new node |
| 3830 | // will be legal. If it isn't, check to see if FP_TO_SINT is legal, since |
| 3831 | // we can use that instead. This allows us to generate better code for |
| 3832 | // FP_TO_UINT for small destination sizes on targets where FP_TO_UINT is not |
| 3833 | // legal, such as PowerPC. |
| 3834 | if (Node->getOpcode() == ISD::FP_TO_UINT && |
Chris Lattner | c9c60f6 | 2005-08-24 16:35:28 +0000 | [diff] [blame] | 3835 | !TLI.isOperationLegal(ISD::FP_TO_UINT, NVT) && |
Nate Begeman | b7f6ef1 | 2005-10-25 23:47:25 +0000 | [diff] [blame] | 3836 | (TLI.isOperationLegal(ISD::FP_TO_SINT, NVT) || |
| 3837 | TLI.getOperationAction(ISD::FP_TO_SINT, NVT)==TargetLowering::Custom)){ |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 3838 | Result = DAG.getNode(ISD::FP_TO_SINT, NVT, Tmp1); |
| 3839 | } else { |
| 3840 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1); |
| 3841 | } |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3842 | break; |
| 3843 | |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3844 | case ISD::FABS: |
| 3845 | case ISD::FNEG: |
| 3846 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 3847 | assert(Tmp1.getValueType() == NVT); |
| 3848 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1); |
| 3849 | // NOTE: we do not have to do any extra rounding here for |
| 3850 | // NoExcessFPPrecision, because we know the input will have the appropriate |
| 3851 | // precision, and these operations don't modify precision at all. |
| 3852 | break; |
| 3853 | |
Chris Lattner | da6ba87 | 2005-04-28 21:44:33 +0000 | [diff] [blame] | 3854 | case ISD::FSQRT: |
| 3855 | case ISD::FSIN: |
| 3856 | case ISD::FCOS: |
| 3857 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 3858 | assert(Tmp1.getValueType() == NVT); |
| 3859 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3860 | if (NoExcessFPPrecision) |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 3861 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 3862 | DAG.getValueType(VT)); |
Chris Lattner | da6ba87 | 2005-04-28 21:44:33 +0000 | [diff] [blame] | 3863 | break; |
| 3864 | |
Chris Lattner | 8b2d42c | 2007-03-03 23:43:21 +0000 | [diff] [blame] | 3865 | case ISD::FPOWI: { |
| 3866 | // Promote f32 powi to f64 powi. Note that this could insert a libcall |
| 3867 | // directly as well, which may be better. |
| 3868 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 3869 | assert(Tmp1.getValueType() == NVT); |
| 3870 | Result = DAG.getNode(ISD::FPOWI, NVT, Tmp1, Node->getOperand(1)); |
| 3871 | if (NoExcessFPPrecision) |
| 3872 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 3873 | DAG.getValueType(VT)); |
| 3874 | break; |
| 3875 | } |
| 3876 | |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3877 | case ISD::AND: |
| 3878 | case ISD::OR: |
| 3879 | case ISD::XOR: |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 3880 | case ISD::ADD: |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3881 | case ISD::SUB: |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 3882 | case ISD::MUL: |
| 3883 | // 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] | 3884 | // 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] | 3885 | // that too is okay if they are integer operations. |
| 3886 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 3887 | Tmp2 = PromoteOp(Node->getOperand(1)); |
| 3888 | assert(Tmp1.getValueType() == NVT && Tmp2.getValueType() == NVT); |
| 3889 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 3890 | break; |
| 3891 | case ISD::FADD: |
| 3892 | case ISD::FSUB: |
| 3893 | case ISD::FMUL: |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 3894 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 3895 | Tmp2 = PromoteOp(Node->getOperand(1)); |
| 3896 | assert(Tmp1.getValueType() == NVT && Tmp2.getValueType() == NVT); |
| 3897 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 3898 | |
| 3899 | // Floating point operations will give excess precision that we may not be |
| 3900 | // able to tolerate. If we DO allow excess precision, just leave it, |
| 3901 | // otherwise excise it. |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3902 | // FIXME: Why would we need to round FP ops more than integer ones? |
| 3903 | // 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] | 3904 | if (NoExcessFPPrecision) |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 3905 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 3906 | DAG.getValueType(VT)); |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 3907 | break; |
| 3908 | |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3909 | case ISD::SDIV: |
| 3910 | case ISD::SREM: |
| 3911 | // These operators require that their input be sign extended. |
| 3912 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 3913 | Tmp2 = PromoteOp(Node->getOperand(1)); |
| 3914 | if (MVT::isInteger(NVT)) { |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 3915 | Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp1, |
| 3916 | DAG.getValueType(VT)); |
| 3917 | Tmp2 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp2, |
| 3918 | DAG.getValueType(VT)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3919 | } |
| 3920 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 3921 | |
| 3922 | // Perform FP_ROUND: this is probably overly pessimistic. |
| 3923 | if (MVT::isFloatingPoint(NVT) && NoExcessFPPrecision) |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 3924 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 3925 | DAG.getValueType(VT)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3926 | break; |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 3927 | case ISD::FDIV: |
| 3928 | case ISD::FREM: |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 3929 | case ISD::FCOPYSIGN: |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 3930 | // These operators require that their input be fp extended. |
Nate Begeman | ec57fd9 | 2006-05-09 18:20:51 +0000 | [diff] [blame] | 3931 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3932 | case Legal: |
| 3933 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 3934 | break; |
| 3935 | case Promote: |
| 3936 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 3937 | break; |
| 3938 | case Expand: |
| 3939 | assert(0 && "not implemented"); |
| 3940 | } |
| 3941 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 3942 | case Legal: |
| 3943 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 3944 | break; |
| 3945 | case Promote: |
| 3946 | Tmp2 = PromoteOp(Node->getOperand(1)); |
| 3947 | break; |
| 3948 | case Expand: |
| 3949 | assert(0 && "not implemented"); |
| 3950 | } |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 3951 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 3952 | |
| 3953 | // Perform FP_ROUND: this is probably overly pessimistic. |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 3954 | if (NoExcessFPPrecision && Node->getOpcode() != ISD::FCOPYSIGN) |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 3955 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 3956 | DAG.getValueType(VT)); |
| 3957 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3958 | |
| 3959 | case ISD::UDIV: |
| 3960 | case ISD::UREM: |
| 3961 | // These operators require that their input be zero extended. |
| 3962 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 3963 | Tmp2 = PromoteOp(Node->getOperand(1)); |
| 3964 | assert(MVT::isInteger(NVT) && "Operators don't apply to FP!"); |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 3965 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, VT); |
| 3966 | Tmp2 = DAG.getZeroExtendInReg(Tmp2, VT); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3967 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 3968 | break; |
| 3969 | |
| 3970 | case ISD::SHL: |
| 3971 | Tmp1 = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3972 | Result = DAG.getNode(ISD::SHL, NVT, Tmp1, Node->getOperand(1)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3973 | break; |
| 3974 | case ISD::SRA: |
| 3975 | // The input value must be properly sign extended. |
| 3976 | Tmp1 = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 3977 | Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp1, |
| 3978 | DAG.getValueType(VT)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3979 | Result = DAG.getNode(ISD::SRA, NVT, Tmp1, Node->getOperand(1)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3980 | break; |
| 3981 | case ISD::SRL: |
| 3982 | // The input value must be properly zero extended. |
| 3983 | Tmp1 = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 3984 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, VT); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3985 | Result = DAG.getNode(ISD::SRL, NVT, Tmp1, Node->getOperand(1)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 3986 | break; |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 3987 | |
| 3988 | case ISD::VAARG: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3989 | Tmp1 = Node->getOperand(0); // Get the chain. |
| 3990 | Tmp2 = Node->getOperand(1); // Get the pointer. |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 3991 | if (TLI.getOperationAction(ISD::VAARG, VT) == TargetLowering::Custom) { |
| 3992 | Tmp3 = DAG.getVAArg(VT, Tmp1, Tmp2, Node->getOperand(2)); |
| 3993 | Result = TLI.CustomPromoteOperation(Tmp3, DAG); |
| 3994 | } else { |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 3995 | SrcValueSDNode *SV = cast<SrcValueSDNode>(Node->getOperand(2)); |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 3996 | SDOperand VAList = DAG.getLoad(TLI.getPointerTy(), Tmp1, Tmp2, |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 3997 | SV->getValue(), SV->getOffset()); |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 3998 | // Increment the pointer, VAList, to the next vaarg |
| 3999 | Tmp3 = DAG.getNode(ISD::ADD, TLI.getPointerTy(), VAList, |
| 4000 | DAG.getConstant(MVT::getSizeInBits(VT)/8, |
| 4001 | TLI.getPointerTy())); |
| 4002 | // Store the incremented VAList to the legalized pointer |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 4003 | Tmp3 = DAG.getStore(VAList.getValue(1), Tmp3, Tmp2, SV->getValue(), |
| 4004 | SV->getOffset()); |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 4005 | // Load the actual argument out of the pointer VAList |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 4006 | Result = DAG.getExtLoad(ISD::EXTLOAD, NVT, Tmp3, VAList, NULL, 0, VT); |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 4007 | } |
| 4008 | // Remember that we legalized the chain. |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4009 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1))); |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 4010 | break; |
| 4011 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 4012 | case ISD::LOAD: { |
| 4013 | LoadSDNode *LD = cast<LoadSDNode>(Node); |
Evan Cheng | 62f2a3c | 2006-10-10 07:51:21 +0000 | [diff] [blame] | 4014 | ISD::LoadExtType ExtType = ISD::isNON_EXTLoad(Node) |
| 4015 | ? ISD::EXTLOAD : LD->getExtensionType(); |
| 4016 | Result = DAG.getExtLoad(ExtType, NVT, |
| 4017 | LD->getChain(), LD->getBasePtr(), |
Chris Lattner | 55b5708 | 2006-10-10 18:54:19 +0000 | [diff] [blame] | 4018 | LD->getSrcValue(), LD->getSrcValueOffset(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 4019 | LD->getLoadedVT(), |
| 4020 | LD->isVolatile(), |
| 4021 | LD->getAlignment()); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4022 | // Remember that we legalized the chain. |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4023 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1))); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4024 | break; |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 4025 | } |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4026 | case ISD::SELECT: |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4027 | Tmp2 = PromoteOp(Node->getOperand(1)); // Legalize the op0 |
| 4028 | Tmp3 = PromoteOp(Node->getOperand(2)); // Legalize the op1 |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4029 | Result = DAG.getNode(ISD::SELECT, NVT, Node->getOperand(0), Tmp2, Tmp3); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4030 | break; |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 4031 | case ISD::SELECT_CC: |
| 4032 | Tmp2 = PromoteOp(Node->getOperand(2)); // True |
| 4033 | Tmp3 = PromoteOp(Node->getOperand(3)); // False |
| 4034 | Result = DAG.getNode(ISD::SELECT_CC, NVT, Node->getOperand(0), |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4035 | Node->getOperand(1), Tmp2, Tmp3, Node->getOperand(4)); |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 4036 | break; |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 4037 | case ISD::BSWAP: |
| 4038 | Tmp1 = Node->getOperand(0); |
| 4039 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Tmp1); |
| 4040 | Tmp1 = DAG.getNode(ISD::BSWAP, NVT, Tmp1); |
| 4041 | Result = DAG.getNode(ISD::SRL, NVT, Tmp1, |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 4042 | DAG.getConstant(MVT::getSizeInBits(NVT) - |
| 4043 | MVT::getSizeInBits(VT), |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 4044 | TLI.getShiftAmountTy())); |
| 4045 | break; |
Andrew Lenharth | fecf095 | 2005-05-04 19:11:05 +0000 | [diff] [blame] | 4046 | case ISD::CTPOP: |
| 4047 | case ISD::CTTZ: |
| 4048 | case ISD::CTLZ: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4049 | // Zero extend the argument |
| 4050 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Node->getOperand(0)); |
Andrew Lenharth | fecf095 | 2005-05-04 19:11:05 +0000 | [diff] [blame] | 4051 | // Perform the larger operation, then subtract if needed. |
| 4052 | Tmp1 = DAG.getNode(Node->getOpcode(), NVT, Tmp1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4053 | switch(Node->getOpcode()) { |
Andrew Lenharth | fecf095 | 2005-05-04 19:11:05 +0000 | [diff] [blame] | 4054 | case ISD::CTPOP: |
| 4055 | Result = Tmp1; |
| 4056 | break; |
| 4057 | case ISD::CTTZ: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4058 | // if Tmp1 == sizeinbits(NVT) then Tmp1 = sizeinbits(Old VT) |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 4059 | Tmp2 = DAG.getSetCC(TLI.getSetCCResultTy(), Tmp1, |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 4060 | DAG.getConstant(MVT::getSizeInBits(NVT), NVT), |
| 4061 | ISD::SETEQ); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 4062 | Result = DAG.getNode(ISD::SELECT, NVT, Tmp2, |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 4063 | DAG.getConstant(MVT::getSizeInBits(VT), NVT), Tmp1); |
Andrew Lenharth | fecf095 | 2005-05-04 19:11:05 +0000 | [diff] [blame] | 4064 | break; |
| 4065 | case ISD::CTLZ: |
| 4066 | //Tmp1 = Tmp1 - (sizeinbits(NVT) - sizeinbits(Old VT)) |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 4067 | Result = DAG.getNode(ISD::SUB, NVT, Tmp1, |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 4068 | DAG.getConstant(MVT::getSizeInBits(NVT) - |
| 4069 | MVT::getSizeInBits(VT), NVT)); |
Andrew Lenharth | fecf095 | 2005-05-04 19:11:05 +0000 | [diff] [blame] | 4070 | break; |
| 4071 | } |
| 4072 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4073 | case ISD::EXTRACT_SUBVECTOR: |
| 4074 | Result = PromoteOp(ExpandEXTRACT_SUBVECTOR(Op)); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 4075 | break; |
Chris Lattner | 4aab2f4 | 2006-04-02 05:06:04 +0000 | [diff] [blame] | 4076 | case ISD::EXTRACT_VECTOR_ELT: |
| 4077 | Result = PromoteOp(ExpandEXTRACT_VECTOR_ELT(Op)); |
| 4078 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4079 | } |
| 4080 | |
| 4081 | assert(Result.Val && "Didn't set a result!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4082 | |
| 4083 | // Make sure the result is itself legal. |
| 4084 | Result = LegalizeOp(Result); |
| 4085 | |
| 4086 | // Remember that we promoted this! |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4087 | AddPromotedOperand(Op, Result); |
| 4088 | return Result; |
| 4089 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 4090 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4091 | /// ExpandEXTRACT_VECTOR_ELT - Expand an EXTRACT_VECTOR_ELT operation into |
| 4092 | /// a legal EXTRACT_VECTOR_ELT operation, scalar code, or memory traffic, |
| 4093 | /// based on the vector type. The return type of this matches the element type |
| 4094 | /// of the vector, which may not be legal for the target. |
| 4095 | SDOperand SelectionDAGLegalize::ExpandEXTRACT_VECTOR_ELT(SDOperand Op) { |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4096 | // We know that operand #0 is the Vec vector. If the index is a constant |
| 4097 | // or if the invec is a supported hardware type, we can use it. Otherwise, |
| 4098 | // lower to a store then an indexed load. |
| 4099 | SDOperand Vec = Op.getOperand(0); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4100 | SDOperand Idx = Op.getOperand(1); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4101 | |
Dan Gohman | e40c7b0 | 2007-09-24 15:54:53 +0000 | [diff] [blame] | 4102 | MVT::ValueType TVT = Vec.getValueType(); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4103 | unsigned NumElems = MVT::getVectorNumElements(TVT); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4104 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4105 | switch (TLI.getOperationAction(ISD::EXTRACT_VECTOR_ELT, TVT)) { |
| 4106 | default: assert(0 && "This action is not supported yet!"); |
| 4107 | case TargetLowering::Custom: { |
| 4108 | Vec = LegalizeOp(Vec); |
| 4109 | Op = DAG.UpdateNodeOperands(Op, Vec, Idx); |
| 4110 | SDOperand Tmp3 = TLI.LowerOperation(Op, DAG); |
| 4111 | if (Tmp3.Val) |
| 4112 | return Tmp3; |
| 4113 | break; |
| 4114 | } |
| 4115 | case TargetLowering::Legal: |
| 4116 | if (isTypeLegal(TVT)) { |
| 4117 | Vec = LegalizeOp(Vec); |
| 4118 | Op = DAG.UpdateNodeOperands(Op, Vec, Idx); |
Christopher Lamb | 844228a | 2007-07-26 03:33:13 +0000 | [diff] [blame] | 4119 | return Op; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4120 | } |
| 4121 | break; |
| 4122 | case TargetLowering::Expand: |
| 4123 | break; |
| 4124 | } |
| 4125 | |
| 4126 | if (NumElems == 1) { |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4127 | // This must be an access of the only element. Return it. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4128 | Op = ScalarizeVectorOp(Vec); |
| 4129 | } else if (!TLI.isTypeLegal(TVT) && isa<ConstantSDNode>(Idx)) { |
| 4130 | ConstantSDNode *CIdx = cast<ConstantSDNode>(Idx); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4131 | SDOperand Lo, Hi; |
| 4132 | SplitVectorOp(Vec, Lo, Hi); |
| 4133 | if (CIdx->getValue() < NumElems/2) { |
| 4134 | Vec = Lo; |
| 4135 | } else { |
| 4136 | Vec = Hi; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4137 | Idx = DAG.getConstant(CIdx->getValue() - NumElems/2, |
| 4138 | Idx.getValueType()); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4139 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4140 | |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4141 | // It's now an extract from the appropriate high or low part. Recurse. |
| 4142 | Op = DAG.UpdateNodeOperands(Op, Vec, Idx); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4143 | Op = ExpandEXTRACT_VECTOR_ELT(Op); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4144 | } else { |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4145 | // Store the value to a temporary stack slot, then LOAD the scalar |
| 4146 | // element back out. |
Chris Lattner | 85dd3be | 2007-10-15 17:48:57 +0000 | [diff] [blame] | 4147 | SDOperand StackPtr = DAG.CreateStackTemporary(Vec.getValueType()); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4148 | SDOperand Ch = DAG.getStore(DAG.getEntryNode(), Vec, StackPtr, NULL, 0); |
| 4149 | |
| 4150 | // Add the offset to the index. |
| 4151 | unsigned EltSize = MVT::getSizeInBits(Op.getValueType())/8; |
| 4152 | Idx = DAG.getNode(ISD::MUL, Idx.getValueType(), Idx, |
| 4153 | DAG.getConstant(EltSize, Idx.getValueType())); |
Bill Wendling | 90bfc2d | 2007-10-18 08:32:37 +0000 | [diff] [blame] | 4154 | |
| 4155 | if (MVT::getSizeInBits(Idx.getValueType()) > |
| 4156 | MVT::getSizeInBits(TLI.getPointerTy())) |
Chris Lattner | f185e67 | 2007-10-19 16:47:35 +0000 | [diff] [blame] | 4157 | Idx = DAG.getNode(ISD::TRUNCATE, TLI.getPointerTy(), Idx); |
Bill Wendling | 90bfc2d | 2007-10-18 08:32:37 +0000 | [diff] [blame] | 4158 | else |
Chris Lattner | f185e67 | 2007-10-19 16:47:35 +0000 | [diff] [blame] | 4159 | Idx = DAG.getNode(ISD::ZERO_EXTEND, TLI.getPointerTy(), Idx); |
Bill Wendling | 90bfc2d | 2007-10-18 08:32:37 +0000 | [diff] [blame] | 4160 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4161 | StackPtr = DAG.getNode(ISD::ADD, Idx.getValueType(), Idx, StackPtr); |
| 4162 | |
| 4163 | Op = DAG.getLoad(Op.getValueType(), Ch, StackPtr, NULL, 0); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4164 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4165 | return Op; |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4166 | } |
| 4167 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4168 | /// ExpandEXTRACT_SUBVECTOR - Expand a EXTRACT_SUBVECTOR operation. For now |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 4169 | /// 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] | 4170 | SDOperand SelectionDAGLegalize::ExpandEXTRACT_SUBVECTOR(SDOperand Op) { |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 4171 | // We know that operand #0 is the Vec vector. For now we assume the index |
| 4172 | // is a constant and that the extracted result is a supported hardware type. |
| 4173 | SDOperand Vec = Op.getOperand(0); |
| 4174 | SDOperand Idx = LegalizeOp(Op.getOperand(1)); |
| 4175 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4176 | unsigned NumElems = MVT::getVectorNumElements(Vec.getValueType()); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 4177 | |
| 4178 | if (NumElems == MVT::getVectorNumElements(Op.getValueType())) { |
| 4179 | // This must be an access of the desired vector length. Return it. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4180 | return Vec; |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 4181 | } |
| 4182 | |
| 4183 | ConstantSDNode *CIdx = cast<ConstantSDNode>(Idx); |
| 4184 | SDOperand Lo, Hi; |
| 4185 | SplitVectorOp(Vec, Lo, Hi); |
| 4186 | if (CIdx->getValue() < NumElems/2) { |
| 4187 | Vec = Lo; |
| 4188 | } else { |
| 4189 | Vec = Hi; |
| 4190 | Idx = DAG.getConstant(CIdx->getValue() - NumElems/2, Idx.getValueType()); |
| 4191 | } |
| 4192 | |
| 4193 | // It's now an extract from the appropriate high or low part. Recurse. |
| 4194 | Op = DAG.UpdateNodeOperands(Op, Vec, Idx); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4195 | return ExpandEXTRACT_SUBVECTOR(Op); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 4196 | } |
| 4197 | |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 4198 | /// LegalizeSetCCOperands - Attempts to create a legal LHS and RHS for a SETCC |
| 4199 | /// with condition CC on the current target. This usually involves legalizing |
| 4200 | /// or promoting the arguments. In the case where LHS and RHS must be expanded, |
| 4201 | /// there may be no choice but to create a new SetCC node to represent the |
| 4202 | /// legalized value of setcc lhs, rhs. In this case, the value is returned in |
| 4203 | /// LHS, and the SDOperand returned in RHS has a nil SDNode value. |
| 4204 | void SelectionDAGLegalize::LegalizeSetCCOperands(SDOperand &LHS, |
| 4205 | SDOperand &RHS, |
| 4206 | SDOperand &CC) { |
Dale Johannesen | 638ccd5 | 2007-10-06 01:24:11 +0000 | [diff] [blame] | 4207 | SDOperand Tmp1, Tmp2, Tmp3, Result; |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 4208 | |
| 4209 | switch (getTypeAction(LHS.getValueType())) { |
| 4210 | case Legal: |
| 4211 | Tmp1 = LegalizeOp(LHS); // LHS |
| 4212 | Tmp2 = LegalizeOp(RHS); // RHS |
| 4213 | break; |
| 4214 | case Promote: |
| 4215 | Tmp1 = PromoteOp(LHS); // LHS |
| 4216 | Tmp2 = PromoteOp(RHS); // RHS |
| 4217 | |
| 4218 | // If this is an FP compare, the operands have already been extended. |
| 4219 | if (MVT::isInteger(LHS.getValueType())) { |
| 4220 | MVT::ValueType VT = LHS.getValueType(); |
| 4221 | MVT::ValueType NVT = TLI.getTypeToTransformTo(VT); |
| 4222 | |
| 4223 | // Otherwise, we have to insert explicit sign or zero extends. Note |
| 4224 | // that we could insert sign extends for ALL conditions, but zero extend |
| 4225 | // is cheaper on many machines (an AND instead of two shifts), so prefer |
| 4226 | // it. |
| 4227 | switch (cast<CondCodeSDNode>(CC)->get()) { |
| 4228 | default: assert(0 && "Unknown integer comparison!"); |
| 4229 | case ISD::SETEQ: |
| 4230 | case ISD::SETNE: |
| 4231 | case ISD::SETUGE: |
| 4232 | case ISD::SETUGT: |
| 4233 | case ISD::SETULE: |
| 4234 | case ISD::SETULT: |
| 4235 | // ALL of these operations will work if we either sign or zero extend |
| 4236 | // the operands (including the unsigned comparisons!). Zero extend is |
| 4237 | // usually a simpler/cheaper operation, so prefer it. |
| 4238 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, VT); |
| 4239 | Tmp2 = DAG.getZeroExtendInReg(Tmp2, VT); |
| 4240 | break; |
| 4241 | case ISD::SETGE: |
| 4242 | case ISD::SETGT: |
| 4243 | case ISD::SETLT: |
| 4244 | case ISD::SETLE: |
| 4245 | Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp1, |
| 4246 | DAG.getValueType(VT)); |
| 4247 | Tmp2 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp2, |
| 4248 | DAG.getValueType(VT)); |
| 4249 | break; |
| 4250 | } |
| 4251 | } |
| 4252 | break; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4253 | case Expand: { |
| 4254 | MVT::ValueType VT = LHS.getValueType(); |
| 4255 | if (VT == MVT::f32 || VT == MVT::f64) { |
| 4256 | // Expand into one or more soft-fp libcall(s). |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4257 | RTLIB::Libcall LC1, LC2 = RTLIB::UNKNOWN_LIBCALL; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4258 | switch (cast<CondCodeSDNode>(CC)->get()) { |
| 4259 | case ISD::SETEQ: |
| 4260 | case ISD::SETOEQ: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4261 | LC1 = (VT == MVT::f32) ? RTLIB::OEQ_F32 : RTLIB::OEQ_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4262 | break; |
| 4263 | case ISD::SETNE: |
| 4264 | case ISD::SETUNE: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4265 | LC1 = (VT == MVT::f32) ? RTLIB::UNE_F32 : RTLIB::UNE_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4266 | break; |
| 4267 | case ISD::SETGE: |
| 4268 | case ISD::SETOGE: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4269 | LC1 = (VT == MVT::f32) ? RTLIB::OGE_F32 : RTLIB::OGE_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4270 | break; |
| 4271 | case ISD::SETLT: |
| 4272 | case ISD::SETOLT: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4273 | LC1 = (VT == MVT::f32) ? RTLIB::OLT_F32 : RTLIB::OLT_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4274 | break; |
| 4275 | case ISD::SETLE: |
| 4276 | case ISD::SETOLE: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4277 | LC1 = (VT == MVT::f32) ? RTLIB::OLE_F32 : RTLIB::OLE_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4278 | break; |
| 4279 | case ISD::SETGT: |
| 4280 | case ISD::SETOGT: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4281 | LC1 = (VT == MVT::f32) ? RTLIB::OGT_F32 : RTLIB::OGT_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4282 | break; |
| 4283 | case ISD::SETUO: |
Evan Cheng | d385fd6 | 2007-01-31 09:29:11 +0000 | [diff] [blame] | 4284 | LC1 = (VT == MVT::f32) ? RTLIB::UO_F32 : RTLIB::UO_F64; |
| 4285 | break; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4286 | case ISD::SETO: |
Evan Cheng | 5efdecc | 2007-02-03 00:43:46 +0000 | [diff] [blame] | 4287 | LC1 = (VT == MVT::f32) ? RTLIB::O_F32 : RTLIB::O_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4288 | break; |
| 4289 | default: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4290 | LC1 = (VT == MVT::f32) ? RTLIB::UO_F32 : RTLIB::UO_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4291 | switch (cast<CondCodeSDNode>(CC)->get()) { |
| 4292 | case ISD::SETONE: |
| 4293 | // SETONE = SETOLT | SETOGT |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4294 | LC1 = (VT == MVT::f32) ? RTLIB::OLT_F32 : RTLIB::OLT_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4295 | // Fallthrough |
| 4296 | case ISD::SETUGT: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4297 | LC2 = (VT == MVT::f32) ? RTLIB::OGT_F32 : RTLIB::OGT_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4298 | break; |
| 4299 | case ISD::SETUGE: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4300 | LC2 = (VT == MVT::f32) ? RTLIB::OGE_F32 : RTLIB::OGE_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4301 | break; |
| 4302 | case ISD::SETULT: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4303 | LC2 = (VT == MVT::f32) ? RTLIB::OLT_F32 : RTLIB::OLT_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4304 | break; |
| 4305 | case ISD::SETULE: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4306 | LC2 = (VT == MVT::f32) ? RTLIB::OLE_F32 : RTLIB::OLE_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4307 | break; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4308 | case ISD::SETUEQ: |
| 4309 | LC2 = (VT == MVT::f32) ? RTLIB::OEQ_F32 : RTLIB::OEQ_F64; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4310 | break; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4311 | default: assert(0 && "Unsupported FP setcc!"); |
| 4312 | } |
| 4313 | } |
| 4314 | |
| 4315 | SDOperand Dummy; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4316 | Tmp1 = ExpandLibCall(TLI.getLibcallName(LC1), |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 4317 | DAG.getNode(ISD::MERGE_VALUES, VT, LHS, RHS).Val, |
Reid Spencer | b47b25c | 2007-01-03 04:22:32 +0000 | [diff] [blame] | 4318 | false /*sign irrelevant*/, Dummy); |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4319 | Tmp2 = DAG.getConstant(0, MVT::i32); |
Evan Cheng | d385fd6 | 2007-01-31 09:29:11 +0000 | [diff] [blame] | 4320 | CC = DAG.getCondCode(TLI.getCmpLibcallCC(LC1)); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4321 | if (LC2 != RTLIB::UNKNOWN_LIBCALL) { |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4322 | Tmp1 = DAG.getNode(ISD::SETCC, TLI.getSetCCResultTy(), Tmp1, Tmp2, CC); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4323 | LHS = ExpandLibCall(TLI.getLibcallName(LC2), |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 4324 | DAG.getNode(ISD::MERGE_VALUES, VT, LHS, RHS).Val, |
Reid Spencer | b47b25c | 2007-01-03 04:22:32 +0000 | [diff] [blame] | 4325 | false /*sign irrelevant*/, Dummy); |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4326 | Tmp2 = DAG.getNode(ISD::SETCC, TLI.getSetCCResultTy(), LHS, Tmp2, |
Evan Cheng | d385fd6 | 2007-01-31 09:29:11 +0000 | [diff] [blame] | 4327 | DAG.getCondCode(TLI.getCmpLibcallCC(LC2))); |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4328 | Tmp1 = DAG.getNode(ISD::OR, Tmp1.getValueType(), Tmp1, Tmp2); |
| 4329 | Tmp2 = SDOperand(); |
| 4330 | } |
| 4331 | LHS = Tmp1; |
| 4332 | RHS = Tmp2; |
| 4333 | return; |
| 4334 | } |
| 4335 | |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 4336 | SDOperand LHSLo, LHSHi, RHSLo, RHSHi; |
| 4337 | ExpandOp(LHS, LHSLo, LHSHi); |
Dale Johannesen | 638ccd5 | 2007-10-06 01:24:11 +0000 | [diff] [blame] | 4338 | ExpandOp(RHS, RHSLo, RHSHi); |
| 4339 | ISD::CondCode CCCode = cast<CondCodeSDNode>(CC)->get(); |
| 4340 | |
| 4341 | if (VT==MVT::ppcf128) { |
| 4342 | // FIXME: This generated code sucks. We want to generate |
| 4343 | // FCMP crN, hi1, hi2 |
| 4344 | // BNE crN, L: |
| 4345 | // FCMP crN, lo1, lo2 |
| 4346 | // The following can be improved, but not that much. |
| 4347 | Tmp1 = DAG.getSetCC(TLI.getSetCCResultTy(), LHSHi, RHSHi, ISD::SETEQ); |
| 4348 | Tmp2 = DAG.getSetCC(TLI.getSetCCResultTy(), LHSLo, RHSLo, CCCode); |
| 4349 | Tmp3 = DAG.getNode(ISD::AND, Tmp1.getValueType(), Tmp1, Tmp2); |
| 4350 | Tmp1 = DAG.getSetCC(TLI.getSetCCResultTy(), LHSHi, RHSHi, ISD::SETNE); |
| 4351 | Tmp2 = DAG.getSetCC(TLI.getSetCCResultTy(), LHSHi, RHSHi, CCCode); |
| 4352 | Tmp1 = DAG.getNode(ISD::AND, Tmp1.getValueType(), Tmp1, Tmp2); |
| 4353 | Tmp1 = DAG.getNode(ISD::OR, Tmp1.getValueType(), Tmp1, Tmp3); |
| 4354 | Tmp2 = SDOperand(); |
| 4355 | break; |
| 4356 | } |
| 4357 | |
| 4358 | switch (CCCode) { |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 4359 | case ISD::SETEQ: |
| 4360 | case ISD::SETNE: |
| 4361 | if (RHSLo == RHSHi) |
| 4362 | if (ConstantSDNode *RHSCST = dyn_cast<ConstantSDNode>(RHSLo)) |
| 4363 | if (RHSCST->isAllOnesValue()) { |
| 4364 | // Comparison to -1. |
| 4365 | Tmp1 = DAG.getNode(ISD::AND, LHSLo.getValueType(), LHSLo, LHSHi); |
| 4366 | Tmp2 = RHSLo; |
| 4367 | break; |
| 4368 | } |
| 4369 | |
| 4370 | Tmp1 = DAG.getNode(ISD::XOR, LHSLo.getValueType(), LHSLo, RHSLo); |
| 4371 | Tmp2 = DAG.getNode(ISD::XOR, LHSLo.getValueType(), LHSHi, RHSHi); |
| 4372 | Tmp1 = DAG.getNode(ISD::OR, Tmp1.getValueType(), Tmp1, Tmp2); |
| 4373 | Tmp2 = DAG.getConstant(0, Tmp1.getValueType()); |
| 4374 | break; |
| 4375 | default: |
| 4376 | // If this is a comparison of the sign bit, just look at the top part. |
| 4377 | // X > -1, x < 0 |
| 4378 | if (ConstantSDNode *CST = dyn_cast<ConstantSDNode>(RHS)) |
| 4379 | if ((cast<CondCodeSDNode>(CC)->get() == ISD::SETLT && |
| 4380 | CST->getValue() == 0) || // X < 0 |
| 4381 | (cast<CondCodeSDNode>(CC)->get() == ISD::SETGT && |
| 4382 | CST->isAllOnesValue())) { // X > -1 |
| 4383 | Tmp1 = LHSHi; |
| 4384 | Tmp2 = RHSHi; |
| 4385 | break; |
| 4386 | } |
| 4387 | |
| 4388 | // FIXME: This generated code sucks. |
| 4389 | ISD::CondCode LowCC; |
Evan Cheng | 2e67781 | 2007-02-08 22:16:19 +0000 | [diff] [blame] | 4390 | switch (CCCode) { |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 4391 | default: assert(0 && "Unknown integer setcc!"); |
| 4392 | case ISD::SETLT: |
| 4393 | case ISD::SETULT: LowCC = ISD::SETULT; break; |
| 4394 | case ISD::SETGT: |
| 4395 | case ISD::SETUGT: LowCC = ISD::SETUGT; break; |
| 4396 | case ISD::SETLE: |
| 4397 | case ISD::SETULE: LowCC = ISD::SETULE; break; |
| 4398 | case ISD::SETGE: |
| 4399 | case ISD::SETUGE: LowCC = ISD::SETUGE; break; |
| 4400 | } |
| 4401 | |
| 4402 | // Tmp1 = lo(op1) < lo(op2) // Always unsigned comparison |
| 4403 | // Tmp2 = hi(op1) < hi(op2) // Signedness depends on operands |
| 4404 | // dest = hi(op1) == hi(op2) ? Tmp1 : Tmp2; |
| 4405 | |
| 4406 | // NOTE: on targets without efficient SELECT of bools, we can always use |
| 4407 | // this identity: (B1 ? B2 : B3) --> (B1 & B2)|(!B1&B3) |
Evan Cheng | 2e67781 | 2007-02-08 22:16:19 +0000 | [diff] [blame] | 4408 | TargetLowering::DAGCombinerInfo DagCombineInfo(DAG, false, true, NULL); |
| 4409 | Tmp1 = TLI.SimplifySetCC(TLI.getSetCCResultTy(), LHSLo, RHSLo, LowCC, |
| 4410 | false, DagCombineInfo); |
| 4411 | if (!Tmp1.Val) |
| 4412 | Tmp1 = DAG.getSetCC(TLI.getSetCCResultTy(), LHSLo, RHSLo, LowCC); |
| 4413 | Tmp2 = TLI.SimplifySetCC(TLI.getSetCCResultTy(), LHSHi, RHSHi, |
| 4414 | CCCode, false, DagCombineInfo); |
| 4415 | if (!Tmp2.Val) |
Chris Lattner | 85dd3be | 2007-10-15 17:48:57 +0000 | [diff] [blame] | 4416 | Tmp2 = DAG.getNode(ISD::SETCC, TLI.getSetCCResultTy(), LHSHi, RHSHi,CC); |
Evan Cheng | 2e67781 | 2007-02-08 22:16:19 +0000 | [diff] [blame] | 4417 | |
| 4418 | ConstantSDNode *Tmp1C = dyn_cast<ConstantSDNode>(Tmp1.Val); |
| 4419 | ConstantSDNode *Tmp2C = dyn_cast<ConstantSDNode>(Tmp2.Val); |
| 4420 | if ((Tmp1C && Tmp1C->getValue() == 0) || |
| 4421 | (Tmp2C && Tmp2C->getValue() == 0 && |
| 4422 | (CCCode == ISD::SETLE || CCCode == ISD::SETGE || |
| 4423 | CCCode == ISD::SETUGE || CCCode == ISD::SETULE)) || |
| 4424 | (Tmp2C && Tmp2C->getValue() == 1 && |
| 4425 | (CCCode == ISD::SETLT || CCCode == ISD::SETGT || |
| 4426 | CCCode == ISD::SETUGT || CCCode == ISD::SETULT))) { |
| 4427 | // low part is known false, returns high part. |
| 4428 | // For LE / GE, if high part is known false, ignore the low part. |
| 4429 | // For LT / GT, if high part is known true, ignore the low part. |
| 4430 | Tmp1 = Tmp2; |
| 4431 | Tmp2 = SDOperand(); |
| 4432 | } else { |
| 4433 | Result = TLI.SimplifySetCC(TLI.getSetCCResultTy(), LHSHi, RHSHi, |
| 4434 | ISD::SETEQ, false, DagCombineInfo); |
| 4435 | if (!Result.Val) |
| 4436 | Result=DAG.getSetCC(TLI.getSetCCResultTy(), LHSHi, RHSHi, ISD::SETEQ); |
| 4437 | Result = LegalizeOp(DAG.getNode(ISD::SELECT, Tmp1.getValueType(), |
| 4438 | Result, Tmp1, Tmp2)); |
| 4439 | Tmp1 = Result; |
| 4440 | Tmp2 = SDOperand(); |
| 4441 | } |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 4442 | } |
| 4443 | } |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4444 | } |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 4445 | LHS = Tmp1; |
| 4446 | RHS = Tmp2; |
| 4447 | } |
| 4448 | |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 4449 | /// ExpandBIT_CONVERT - Expand a BIT_CONVERT node into a store/load combination. |
Chris Lattner | 232348d | 2005-12-23 00:52:30 +0000 | [diff] [blame] | 4450 | /// The resultant code need not be legal. Note that SrcOp is the input operand |
| 4451 | /// to the BIT_CONVERT, not the BIT_CONVERT node itself. |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 4452 | SDOperand SelectionDAGLegalize::ExpandBIT_CONVERT(MVT::ValueType DestVT, |
| 4453 | SDOperand SrcOp) { |
| 4454 | // Create the stack frame object. |
Chris Lattner | 85dd3be | 2007-10-15 17:48:57 +0000 | [diff] [blame] | 4455 | SDOperand FIPtr = DAG.CreateStackTemporary(DestVT); |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 4456 | |
| 4457 | // Emit a store to the stack slot. |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 4458 | SDOperand Store = DAG.getStore(DAG.getEntryNode(), SrcOp, FIPtr, NULL, 0); |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 4459 | // Result is a load from the stack slot. |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 4460 | return DAG.getLoad(DestVT, Store, FIPtr, NULL, 0); |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 4461 | } |
| 4462 | |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 4463 | SDOperand SelectionDAGLegalize::ExpandSCALAR_TO_VECTOR(SDNode *Node) { |
| 4464 | // Create a vector sized/aligned stack slot, store the value to element #0, |
| 4465 | // then load the whole vector back out. |
Chris Lattner | 85dd3be | 2007-10-15 17:48:57 +0000 | [diff] [blame] | 4466 | SDOperand StackPtr = DAG.CreateStackTemporary(Node->getValueType(0)); |
Evan Cheng | 786225a | 2006-10-05 23:01:46 +0000 | [diff] [blame] | 4467 | SDOperand Ch = DAG.getStore(DAG.getEntryNode(), Node->getOperand(0), StackPtr, |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 4468 | NULL, 0); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 4469 | return DAG.getLoad(Node->getValueType(0), Ch, StackPtr, NULL, 0); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 4470 | } |
| 4471 | |
| 4472 | |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4473 | /// ExpandBUILD_VECTOR - Expand a BUILD_VECTOR node on targets that don't |
Dan Gohman | 07a9676 | 2007-07-16 14:29:03 +0000 | [diff] [blame] | 4474 | /// support the operation, but do support the resultant vector type. |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4475 | SDOperand SelectionDAGLegalize::ExpandBUILD_VECTOR(SDNode *Node) { |
| 4476 | |
| 4477 | // 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] | 4478 | // 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] | 4479 | unsigned NumElems = Node->getNumOperands(); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4480 | bool isOnlyLowElement = true; |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 4481 | SDOperand SplatValue = Node->getOperand(0); |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 4482 | std::map<SDOperand, std::vector<unsigned> > Values; |
| 4483 | Values[SplatValue].push_back(0); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 4484 | bool isConstant = true; |
| 4485 | if (!isa<ConstantFPSDNode>(SplatValue) && !isa<ConstantSDNode>(SplatValue) && |
| 4486 | SplatValue.getOpcode() != ISD::UNDEF) |
| 4487 | isConstant = false; |
| 4488 | |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 4489 | for (unsigned i = 1; i < NumElems; ++i) { |
| 4490 | SDOperand V = Node->getOperand(i); |
Chris Lattner | 89a1b38 | 2006-04-19 23:17:50 +0000 | [diff] [blame] | 4491 | Values[V].push_back(i); |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 4492 | if (V.getOpcode() != ISD::UNDEF) |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4493 | isOnlyLowElement = false; |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 4494 | if (SplatValue != V) |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 4495 | SplatValue = SDOperand(0,0); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 4496 | |
| 4497 | // If this isn't a constant element or an undef, we can't use a constant |
| 4498 | // pool load. |
| 4499 | if (!isa<ConstantFPSDNode>(V) && !isa<ConstantSDNode>(V) && |
| 4500 | V.getOpcode() != ISD::UNDEF) |
| 4501 | isConstant = false; |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4502 | } |
| 4503 | |
| 4504 | if (isOnlyLowElement) { |
| 4505 | // If the low element is an undef too, then this whole things is an undef. |
| 4506 | if (Node->getOperand(0).getOpcode() == ISD::UNDEF) |
| 4507 | return DAG.getNode(ISD::UNDEF, Node->getValueType(0)); |
| 4508 | // Otherwise, turn this into a scalar_to_vector node. |
| 4509 | return DAG.getNode(ISD::SCALAR_TO_VECTOR, Node->getValueType(0), |
| 4510 | Node->getOperand(0)); |
| 4511 | } |
| 4512 | |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 4513 | // If all elements are constants, create a load from the constant pool. |
| 4514 | if (isConstant) { |
| 4515 | MVT::ValueType VT = Node->getValueType(0); |
| 4516 | const Type *OpNTy = |
| 4517 | MVT::getTypeForValueType(Node->getOperand(0).getValueType()); |
| 4518 | std::vector<Constant*> CV; |
| 4519 | for (unsigned i = 0, e = NumElems; i != e; ++i) { |
| 4520 | if (ConstantFPSDNode *V = |
| 4521 | dyn_cast<ConstantFPSDNode>(Node->getOperand(i))) { |
Dale Johannesen | f04afdb | 2007-08-30 00:23:21 +0000 | [diff] [blame] | 4522 | CV.push_back(ConstantFP::get(OpNTy, V->getValueAPF())); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 4523 | } else if (ConstantSDNode *V = |
| 4524 | dyn_cast<ConstantSDNode>(Node->getOperand(i))) { |
Reid Spencer | b83eb64 | 2006-10-20 07:07:24 +0000 | [diff] [blame] | 4525 | CV.push_back(ConstantInt::get(OpNTy, V->getValue())); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 4526 | } else { |
| 4527 | assert(Node->getOperand(i).getOpcode() == ISD::UNDEF); |
| 4528 | CV.push_back(UndefValue::get(OpNTy)); |
| 4529 | } |
| 4530 | } |
Reid Spencer | 9d6565a | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 4531 | Constant *CP = ConstantVector::get(CV); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 4532 | SDOperand CPIdx = DAG.getConstantPool(CP, TLI.getPointerTy()); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 4533 | return DAG.getLoad(VT, DAG.getEntryNode(), CPIdx, NULL, 0); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 4534 | } |
| 4535 | |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 4536 | if (SplatValue.Val) { // Splat of one value? |
| 4537 | // Build the shuffle constant vector: <0, 0, 0, 0> |
| 4538 | MVT::ValueType MaskVT = |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 4539 | MVT::getIntVectorWithNumElements(NumElems); |
Dan Gohman | 51eaa86 | 2007-06-14 22:58:02 +0000 | [diff] [blame] | 4540 | SDOperand Zero = DAG.getConstant(0, MVT::getVectorElementType(MaskVT)); |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 4541 | std::vector<SDOperand> ZeroVec(NumElems, Zero); |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 4542 | SDOperand SplatMask = DAG.getNode(ISD::BUILD_VECTOR, MaskVT, |
| 4543 | &ZeroVec[0], ZeroVec.size()); |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 4544 | |
| 4545 | // If the target supports VECTOR_SHUFFLE and this shuffle mask, use it. |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 4546 | if (isShuffleLegal(Node->getValueType(0), SplatMask)) { |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 4547 | // Get the splatted value into the low element of a vector register. |
| 4548 | SDOperand LowValVec = |
| 4549 | DAG.getNode(ISD::SCALAR_TO_VECTOR, Node->getValueType(0), SplatValue); |
| 4550 | |
| 4551 | // Return shuffle(LowValVec, undef, <0,0,0,0>) |
| 4552 | return DAG.getNode(ISD::VECTOR_SHUFFLE, Node->getValueType(0), LowValVec, |
| 4553 | DAG.getNode(ISD::UNDEF, Node->getValueType(0)), |
| 4554 | SplatMask); |
| 4555 | } |
| 4556 | } |
| 4557 | |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 4558 | // If there are only two unique elements, we may be able to turn this into a |
| 4559 | // vector shuffle. |
| 4560 | if (Values.size() == 2) { |
| 4561 | // Build the shuffle constant vector: e.g. <0, 4, 0, 4> |
| 4562 | MVT::ValueType MaskVT = |
| 4563 | MVT::getIntVectorWithNumElements(NumElems); |
| 4564 | std::vector<SDOperand> MaskVec(NumElems); |
| 4565 | unsigned i = 0; |
| 4566 | for (std::map<SDOperand,std::vector<unsigned> >::iterator I=Values.begin(), |
| 4567 | E = Values.end(); I != E; ++I) { |
| 4568 | for (std::vector<unsigned>::iterator II = I->second.begin(), |
| 4569 | EE = I->second.end(); II != EE; ++II) |
Dan Gohman | 51eaa86 | 2007-06-14 22:58:02 +0000 | [diff] [blame] | 4570 | MaskVec[*II] = DAG.getConstant(i, MVT::getVectorElementType(MaskVT)); |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 4571 | i += NumElems; |
| 4572 | } |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 4573 | SDOperand ShuffleMask = DAG.getNode(ISD::BUILD_VECTOR, MaskVT, |
| 4574 | &MaskVec[0], MaskVec.size()); |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 4575 | |
| 4576 | // If the target supports VECTOR_SHUFFLE and this shuffle mask, use it. |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 4577 | if (TLI.isOperationLegal(ISD::SCALAR_TO_VECTOR, Node->getValueType(0)) && |
| 4578 | isShuffleLegal(Node->getValueType(0), ShuffleMask)) { |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 4579 | SmallVector<SDOperand, 8> Ops; |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 4580 | for(std::map<SDOperand,std::vector<unsigned> >::iterator I=Values.begin(), |
| 4581 | E = Values.end(); I != E; ++I) { |
| 4582 | SDOperand Op = DAG.getNode(ISD::SCALAR_TO_VECTOR, Node->getValueType(0), |
| 4583 | I->first); |
| 4584 | Ops.push_back(Op); |
| 4585 | } |
| 4586 | Ops.push_back(ShuffleMask); |
| 4587 | |
| 4588 | // Return shuffle(LoValVec, HiValVec, <0,1,0,1>) |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 4589 | return DAG.getNode(ISD::VECTOR_SHUFFLE, Node->getValueType(0), |
| 4590 | &Ops[0], Ops.size()); |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 4591 | } |
| 4592 | } |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4593 | |
| 4594 | // Otherwise, we can't handle this case efficiently. Allocate a sufficiently |
| 4595 | // aligned object on the stack, store each element into it, then load |
| 4596 | // the result as a vector. |
| 4597 | MVT::ValueType VT = Node->getValueType(0); |
| 4598 | // Create the stack frame object. |
Chris Lattner | 85dd3be | 2007-10-15 17:48:57 +0000 | [diff] [blame] | 4599 | SDOperand FIPtr = DAG.CreateStackTemporary(VT); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4600 | |
| 4601 | // Emit a store of each element to the stack slot. |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 4602 | SmallVector<SDOperand, 8> Stores; |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4603 | unsigned TypeByteSize = |
| 4604 | MVT::getSizeInBits(Node->getOperand(0).getValueType())/8; |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4605 | // Store (in the right endianness) the elements to memory. |
| 4606 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) { |
| 4607 | // Ignore undef elements. |
| 4608 | if (Node->getOperand(i).getOpcode() == ISD::UNDEF) continue; |
| 4609 | |
Chris Lattner | 841c882 | 2006-03-22 01:46:54 +0000 | [diff] [blame] | 4610 | unsigned Offset = TypeByteSize*i; |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4611 | |
| 4612 | SDOperand Idx = DAG.getConstant(Offset, FIPtr.getValueType()); |
| 4613 | Idx = DAG.getNode(ISD::ADD, FIPtr.getValueType(), FIPtr, Idx); |
| 4614 | |
Evan Cheng | 786225a | 2006-10-05 23:01:46 +0000 | [diff] [blame] | 4615 | Stores.push_back(DAG.getStore(DAG.getEntryNode(), Node->getOperand(i), Idx, |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 4616 | NULL, 0)); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4617 | } |
| 4618 | |
| 4619 | SDOperand StoreChain; |
| 4620 | if (!Stores.empty()) // Not all undef elements? |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 4621 | StoreChain = DAG.getNode(ISD::TokenFactor, MVT::Other, |
| 4622 | &Stores[0], Stores.size()); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4623 | else |
| 4624 | StoreChain = DAG.getEntryNode(); |
| 4625 | |
| 4626 | // Result is a load from the stack slot. |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 4627 | return DAG.getLoad(VT, StoreChain, FIPtr, NULL, 0); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4628 | } |
| 4629 | |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 4630 | void SelectionDAGLegalize::ExpandShiftParts(unsigned NodeOp, |
| 4631 | SDOperand Op, SDOperand Amt, |
| 4632 | SDOperand &Lo, SDOperand &Hi) { |
| 4633 | // Expand the subcomponents. |
| 4634 | SDOperand LHSL, LHSH; |
| 4635 | ExpandOp(Op, LHSL, LHSH); |
| 4636 | |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 4637 | SDOperand Ops[] = { LHSL, LHSH, Amt }; |
Chris Lattner | f9f37fc | 2006-08-14 23:53:35 +0000 | [diff] [blame] | 4638 | MVT::ValueType VT = LHSL.getValueType(); |
| 4639 | Lo = DAG.getNode(NodeOp, DAG.getNodeValueTypes(VT, VT), 2, Ops, 3); |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 4640 | Hi = Lo.getValue(1); |
| 4641 | } |
| 4642 | |
| 4643 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 4644 | /// ExpandShift - Try to find a clever way to expand this shift operation out to |
| 4645 | /// smaller elements. If we can't find a way that is more efficient than a |
| 4646 | /// libcall on this target, return false. Otherwise, return true with the |
| 4647 | /// low-parts expanded into Lo and Hi. |
| 4648 | bool SelectionDAGLegalize::ExpandShift(unsigned Opc, SDOperand Op,SDOperand Amt, |
| 4649 | SDOperand &Lo, SDOperand &Hi) { |
| 4650 | assert((Opc == ISD::SHL || Opc == ISD::SRA || Opc == ISD::SRL) && |
| 4651 | "This is not a shift!"); |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 4652 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 4653 | MVT::ValueType NVT = TLI.getTypeToTransformTo(Op.getValueType()); |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 4654 | SDOperand ShAmt = LegalizeOp(Amt); |
| 4655 | MVT::ValueType ShTy = ShAmt.getValueType(); |
| 4656 | unsigned VTBits = MVT::getSizeInBits(Op.getValueType()); |
| 4657 | unsigned NVTBits = MVT::getSizeInBits(NVT); |
| 4658 | |
Chris Lattner | 7a3c855 | 2007-10-14 20:35:12 +0000 | [diff] [blame] | 4659 | // Handle the case when Amt is an immediate. |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 4660 | if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Amt.Val)) { |
| 4661 | unsigned Cst = CN->getValue(); |
| 4662 | // Expand the incoming operand to be shifted, so that we have its parts |
| 4663 | SDOperand InL, InH; |
| 4664 | ExpandOp(Op, InL, InH); |
| 4665 | switch(Opc) { |
| 4666 | case ISD::SHL: |
| 4667 | if (Cst > VTBits) { |
| 4668 | Lo = DAG.getConstant(0, NVT); |
| 4669 | Hi = DAG.getConstant(0, NVT); |
| 4670 | } else if (Cst > NVTBits) { |
| 4671 | Lo = DAG.getConstant(0, NVT); |
| 4672 | Hi = DAG.getNode(ISD::SHL, NVT, InL, DAG.getConstant(Cst-NVTBits,ShTy)); |
Chris Lattner | ee27f57 | 2005-04-11 20:08:52 +0000 | [diff] [blame] | 4673 | } else if (Cst == NVTBits) { |
| 4674 | Lo = DAG.getConstant(0, NVT); |
| 4675 | Hi = InL; |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 4676 | } else { |
| 4677 | Lo = DAG.getNode(ISD::SHL, NVT, InL, DAG.getConstant(Cst, ShTy)); |
| 4678 | Hi = DAG.getNode(ISD::OR, NVT, |
| 4679 | DAG.getNode(ISD::SHL, NVT, InH, DAG.getConstant(Cst, ShTy)), |
| 4680 | DAG.getNode(ISD::SRL, NVT, InL, DAG.getConstant(NVTBits-Cst, ShTy))); |
| 4681 | } |
| 4682 | return true; |
| 4683 | case ISD::SRL: |
| 4684 | if (Cst > VTBits) { |
| 4685 | Lo = DAG.getConstant(0, NVT); |
| 4686 | Hi = DAG.getConstant(0, NVT); |
| 4687 | } else if (Cst > NVTBits) { |
| 4688 | Lo = DAG.getNode(ISD::SRL, NVT, InH, DAG.getConstant(Cst-NVTBits,ShTy)); |
| 4689 | Hi = DAG.getConstant(0, NVT); |
Chris Lattner | ee27f57 | 2005-04-11 20:08:52 +0000 | [diff] [blame] | 4690 | } else if (Cst == NVTBits) { |
| 4691 | Lo = InH; |
| 4692 | Hi = DAG.getConstant(0, NVT); |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 4693 | } else { |
| 4694 | Lo = DAG.getNode(ISD::OR, NVT, |
| 4695 | DAG.getNode(ISD::SRL, NVT, InL, DAG.getConstant(Cst, ShTy)), |
| 4696 | DAG.getNode(ISD::SHL, NVT, InH, DAG.getConstant(NVTBits-Cst, ShTy))); |
| 4697 | Hi = DAG.getNode(ISD::SRL, NVT, InH, DAG.getConstant(Cst, ShTy)); |
| 4698 | } |
| 4699 | return true; |
| 4700 | case ISD::SRA: |
| 4701 | if (Cst > VTBits) { |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 4702 | Hi = Lo = DAG.getNode(ISD::SRA, NVT, InH, |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 4703 | DAG.getConstant(NVTBits-1, ShTy)); |
| 4704 | } else if (Cst > NVTBits) { |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 4705 | Lo = DAG.getNode(ISD::SRA, NVT, InH, |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 4706 | DAG.getConstant(Cst-NVTBits, ShTy)); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 4707 | Hi = DAG.getNode(ISD::SRA, NVT, InH, |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 4708 | DAG.getConstant(NVTBits-1, ShTy)); |
Chris Lattner | ee27f57 | 2005-04-11 20:08:52 +0000 | [diff] [blame] | 4709 | } else if (Cst == NVTBits) { |
| 4710 | Lo = InH; |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 4711 | Hi = DAG.getNode(ISD::SRA, NVT, InH, |
Chris Lattner | ee27f57 | 2005-04-11 20:08:52 +0000 | [diff] [blame] | 4712 | DAG.getConstant(NVTBits-1, ShTy)); |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 4713 | } else { |
| 4714 | Lo = DAG.getNode(ISD::OR, NVT, |
| 4715 | DAG.getNode(ISD::SRL, NVT, InL, DAG.getConstant(Cst, ShTy)), |
| 4716 | DAG.getNode(ISD::SHL, NVT, InH, DAG.getConstant(NVTBits-Cst, ShTy))); |
| 4717 | Hi = DAG.getNode(ISD::SRA, NVT, InH, DAG.getConstant(Cst, ShTy)); |
| 4718 | } |
| 4719 | return true; |
| 4720 | } |
| 4721 | } |
Chris Lattner | 0ea26ca | 2006-09-20 03:38:48 +0000 | [diff] [blame] | 4722 | |
| 4723 | // Okay, the shift amount isn't constant. However, if we can tell that it is |
| 4724 | // >= 32 or < 32, we can still simplify it, without knowing the actual value. |
| 4725 | uint64_t Mask = NVTBits, KnownZero, KnownOne; |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 4726 | DAG.ComputeMaskedBits(Amt, Mask, KnownZero, KnownOne); |
Chris Lattner | 0ea26ca | 2006-09-20 03:38:48 +0000 | [diff] [blame] | 4727 | |
| 4728 | // If we know that the high bit of the shift amount is one, then we can do |
| 4729 | // this as a couple of simple shifts. |
| 4730 | if (KnownOne & Mask) { |
| 4731 | // Mask out the high bit, which we know is set. |
| 4732 | Amt = DAG.getNode(ISD::AND, Amt.getValueType(), Amt, |
| 4733 | DAG.getConstant(NVTBits-1, Amt.getValueType())); |
| 4734 | |
| 4735 | // Expand the incoming operand to be shifted, so that we have its parts |
| 4736 | SDOperand InL, InH; |
| 4737 | ExpandOp(Op, InL, InH); |
| 4738 | switch(Opc) { |
| 4739 | case ISD::SHL: |
| 4740 | Lo = DAG.getConstant(0, NVT); // Low part is zero. |
| 4741 | Hi = DAG.getNode(ISD::SHL, NVT, InL, Amt); // High part from Lo part. |
| 4742 | return true; |
| 4743 | case ISD::SRL: |
| 4744 | Hi = DAG.getConstant(0, NVT); // Hi part is zero. |
| 4745 | Lo = DAG.getNode(ISD::SRL, NVT, InH, Amt); // Lo part from Hi part. |
| 4746 | return true; |
| 4747 | case ISD::SRA: |
| 4748 | Hi = DAG.getNode(ISD::SRA, NVT, InH, // Sign extend high part. |
| 4749 | DAG.getConstant(NVTBits-1, Amt.getValueType())); |
| 4750 | Lo = DAG.getNode(ISD::SRA, NVT, InH, Amt); // Lo part from Hi part. |
| 4751 | return true; |
| 4752 | } |
| 4753 | } |
| 4754 | |
| 4755 | // If we know that the high bit of the shift amount is zero, then we can do |
| 4756 | // this as a couple of simple shifts. |
| 4757 | if (KnownZero & Mask) { |
| 4758 | // Compute 32-amt. |
| 4759 | SDOperand Amt2 = DAG.getNode(ISD::SUB, Amt.getValueType(), |
| 4760 | DAG.getConstant(NVTBits, Amt.getValueType()), |
| 4761 | Amt); |
| 4762 | |
| 4763 | // Expand the incoming operand to be shifted, so that we have its parts |
| 4764 | SDOperand InL, InH; |
| 4765 | ExpandOp(Op, InL, InH); |
| 4766 | switch(Opc) { |
| 4767 | case ISD::SHL: |
| 4768 | Lo = DAG.getNode(ISD::SHL, NVT, InL, Amt); |
| 4769 | Hi = DAG.getNode(ISD::OR, NVT, |
| 4770 | DAG.getNode(ISD::SHL, NVT, InH, Amt), |
| 4771 | DAG.getNode(ISD::SRL, NVT, InL, Amt2)); |
| 4772 | return true; |
| 4773 | case ISD::SRL: |
| 4774 | Hi = DAG.getNode(ISD::SRL, NVT, InH, Amt); |
| 4775 | Lo = DAG.getNode(ISD::OR, NVT, |
| 4776 | DAG.getNode(ISD::SRL, NVT, InL, Amt), |
| 4777 | DAG.getNode(ISD::SHL, NVT, InH, Amt2)); |
| 4778 | return true; |
| 4779 | case ISD::SRA: |
| 4780 | Hi = DAG.getNode(ISD::SRA, NVT, InH, Amt); |
| 4781 | Lo = DAG.getNode(ISD::OR, NVT, |
| 4782 | DAG.getNode(ISD::SRL, NVT, InL, Amt), |
| 4783 | DAG.getNode(ISD::SHL, NVT, InH, Amt2)); |
| 4784 | return true; |
| 4785 | } |
| 4786 | } |
| 4787 | |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 4788 | return false; |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 4789 | } |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4790 | |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 4791 | |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4792 | // ExpandLibCall - Expand a node into a call to a libcall. If the result value |
| 4793 | // does not fit into a register, return the lo part and set the hi part to the |
| 4794 | // by-reg argument. If it does fit into a single register, return the result |
| 4795 | // and leave the Hi part unset. |
| 4796 | SDOperand SelectionDAGLegalize::ExpandLibCall(const char *Name, SDNode *Node, |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 4797 | bool isSigned, SDOperand &Hi) { |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 4798 | assert(!IsLegalizingCall && "Cannot overlap legalization of calls!"); |
| 4799 | // The input chain to this libcall is the entry node of the function. |
| 4800 | // Legalizing the call will automatically add the previous call to the |
| 4801 | // dependence. |
| 4802 | SDOperand InChain = DAG.getEntryNode(); |
| 4803 | |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4804 | TargetLowering::ArgListTy Args; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 4805 | TargetLowering::ArgListEntry Entry; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4806 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) { |
| 4807 | MVT::ValueType ArgVT = Node->getOperand(i).getValueType(); |
| 4808 | const Type *ArgTy = MVT::getTypeForValueType(ArgVT); |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 4809 | Entry.Node = Node->getOperand(i); Entry.Ty = ArgTy; |
Anton Korobeynikov | d0b82b3 | 2007-03-07 16:25:09 +0000 | [diff] [blame] | 4810 | Entry.isSExt = isSigned; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 4811 | Args.push_back(Entry); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4812 | } |
| 4813 | SDOperand Callee = DAG.getExternalSymbol(Name, TLI.getPointerTy()); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 4814 | |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 4815 | // Splice the libcall in wherever FindInputOutputChains tells us to. |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4816 | const Type *RetTy = MVT::getTypeForValueType(Node->getValueType(0)); |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 4817 | std::pair<SDOperand,SDOperand> CallInfo = |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 4818 | TLI.LowerCallTo(InChain, RetTy, isSigned, false, CallingConv::C, false, |
Chris Lattner | adf6a96 | 2005-05-13 18:50:42 +0000 | [diff] [blame] | 4819 | Callee, Args, DAG); |
Chris Lattner | b9fa3bc | 2005-05-12 04:49:08 +0000 | [diff] [blame] | 4820 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 4821 | // Legalize the call sequence, starting with the chain. This will advance |
| 4822 | // the LastCALLSEQ_END to the legalized version of the CALLSEQ_END node that |
| 4823 | // was added by LowerCallTo (guaranteeing proper serialization of calls). |
| 4824 | LegalizeOp(CallInfo.second); |
Chris Lattner | 99c25b8 | 2005-09-02 20:26:58 +0000 | [diff] [blame] | 4825 | SDOperand Result; |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 4826 | switch (getTypeAction(CallInfo.first.getValueType())) { |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4827 | default: assert(0 && "Unknown thing"); |
| 4828 | case Legal: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4829 | Result = CallInfo.first; |
Chris Lattner | 99c25b8 | 2005-09-02 20:26:58 +0000 | [diff] [blame] | 4830 | break; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4831 | case Expand: |
Chris Lattner | 99c25b8 | 2005-09-02 20:26:58 +0000 | [diff] [blame] | 4832 | ExpandOp(CallInfo.first, Result, Hi); |
Chris Lattner | 99c25b8 | 2005-09-02 20:26:58 +0000 | [diff] [blame] | 4833 | break; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4834 | } |
Chris Lattner | 99c25b8 | 2005-09-02 20:26:58 +0000 | [diff] [blame] | 4835 | return Result; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4836 | } |
| 4837 | |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 4838 | |
Evan Cheng | 4c6cfad | 2007-04-27 07:33:31 +0000 | [diff] [blame] | 4839 | /// ExpandIntToFP - Expand a [US]INT_TO_FP operation. |
| 4840 | /// |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4841 | SDOperand SelectionDAGLegalize:: |
| 4842 | ExpandIntToFP(bool isSigned, MVT::ValueType DestTy, SDOperand Source) { |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4843 | assert(getTypeAction(Source.getValueType()) == Expand && |
| 4844 | "This is not an expansion!"); |
| 4845 | assert(Source.getValueType() == MVT::i64 && "Only handle expand from i64!"); |
| 4846 | |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 4847 | if (!isSigned) { |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 4848 | assert(Source.getValueType() == MVT::i64 && |
| 4849 | "This only works for 64-bit -> FP"); |
| 4850 | // The 64-bit value loaded will be incorrectly if the 'sign bit' of the |
| 4851 | // incoming integer is set. To handle this, we dynamically test to see if |
| 4852 | // it is set, and, if so, add a fudge factor. |
| 4853 | SDOperand Lo, Hi; |
| 4854 | ExpandOp(Source, Lo, Hi); |
| 4855 | |
Chris Lattner | 66de05b | 2005-05-13 04:45:13 +0000 | [diff] [blame] | 4856 | // If this is unsigned, and not supported, first perform the conversion to |
| 4857 | // signed, then adjust the result if the sign bit is set. |
| 4858 | SDOperand SignedConv = ExpandIntToFP(true, DestTy, |
| 4859 | DAG.getNode(ISD::BUILD_PAIR, Source.getValueType(), Lo, Hi)); |
| 4860 | |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 4861 | SDOperand SignSet = DAG.getSetCC(TLI.getSetCCResultTy(), Hi, |
| 4862 | DAG.getConstant(0, Hi.getValueType()), |
| 4863 | ISD::SETLT); |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 4864 | SDOperand Zero = getIntPtrConstant(0), Four = getIntPtrConstant(4); |
| 4865 | SDOperand CstOffset = DAG.getNode(ISD::SELECT, Zero.getValueType(), |
| 4866 | SignSet, Four, Zero); |
Chris Lattner | 383203b | 2005-05-12 18:52:34 +0000 | [diff] [blame] | 4867 | uint64_t FF = 0x5f800000ULL; |
| 4868 | if (TLI.isLittleEndian()) FF <<= 32; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 4869 | static Constant *FudgeFactor = ConstantInt::get(Type::Int64Ty, FF); |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 4870 | |
Chris Lattner | 5839bf2 | 2005-08-26 17:15:30 +0000 | [diff] [blame] | 4871 | SDOperand CPIdx = DAG.getConstantPool(FudgeFactor, TLI.getPointerTy()); |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 4872 | CPIdx = DAG.getNode(ISD::ADD, TLI.getPointerTy(), CPIdx, CstOffset); |
| 4873 | SDOperand FudgeInReg; |
| 4874 | if (DestTy == MVT::f32) |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 4875 | FudgeInReg = DAG.getLoad(MVT::f32, DAG.getEntryNode(), CPIdx, NULL, 0); |
Dale Johannesen | 118cd9d | 2007-09-16 16:51:49 +0000 | [diff] [blame] | 4876 | else if (MVT::getSizeInBits(DestTy) > MVT::getSizeInBits(MVT::f32)) |
Evan Cheng | 4c6cfad | 2007-04-27 07:33:31 +0000 | [diff] [blame] | 4877 | // FIXME: Avoid the extend by construction the right constantpool? |
Dale Johannesen | 118cd9d | 2007-09-16 16:51:49 +0000 | [diff] [blame] | 4878 | FudgeInReg = DAG.getExtLoad(ISD::EXTLOAD, DestTy, DAG.getEntryNode(), |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 4879 | CPIdx, NULL, 0, MVT::f32); |
| 4880 | else |
| 4881 | assert(0 && "Unexpected conversion"); |
| 4882 | |
Evan Cheng | 4c6cfad | 2007-04-27 07:33:31 +0000 | [diff] [blame] | 4883 | MVT::ValueType SCVT = SignedConv.getValueType(); |
| 4884 | if (SCVT != DestTy) { |
| 4885 | // Destination type needs to be expanded as well. The FADD now we are |
| 4886 | // constructing will be expanded into a libcall. |
| 4887 | if (MVT::getSizeInBits(SCVT) != MVT::getSizeInBits(DestTy)) { |
| 4888 | assert(SCVT == MVT::i32 && DestTy == MVT::f64); |
| 4889 | SignedConv = DAG.getNode(ISD::BUILD_PAIR, MVT::i64, |
| 4890 | SignedConv, SignedConv.getValue(1)); |
| 4891 | } |
| 4892 | SignedConv = DAG.getNode(ISD::BIT_CONVERT, DestTy, SignedConv); |
| 4893 | } |
Chris Lattner | 473a990 | 2005-09-29 06:44:39 +0000 | [diff] [blame] | 4894 | return DAG.getNode(ISD::FADD, DestTy, SignedConv, FudgeInReg); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4895 | } |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 4896 | |
Chris Lattner | a88a260 | 2005-05-14 05:33:54 +0000 | [diff] [blame] | 4897 | // Check to see if the target has a custom way to lower this. If so, use it. |
| 4898 | switch (TLI.getOperationAction(ISD::SINT_TO_FP, Source.getValueType())) { |
| 4899 | default: assert(0 && "This action not implemented for this operation!"); |
| 4900 | case TargetLowering::Legal: |
| 4901 | case TargetLowering::Expand: |
| 4902 | break; // This case is handled below. |
Chris Lattner | 07dffd6 | 2005-08-26 00:14:16 +0000 | [diff] [blame] | 4903 | case TargetLowering::Custom: { |
| 4904 | SDOperand NV = TLI.LowerOperation(DAG.getNode(ISD::SINT_TO_FP, DestTy, |
| 4905 | Source), DAG); |
| 4906 | if (NV.Val) |
| 4907 | return LegalizeOp(NV); |
| 4908 | break; // The target decided this was legal after all |
| 4909 | } |
Chris Lattner | a88a260 | 2005-05-14 05:33:54 +0000 | [diff] [blame] | 4910 | } |
| 4911 | |
Chris Lattner | 13689e2 | 2005-05-12 07:00:44 +0000 | [diff] [blame] | 4912 | // Expand the source, then glue it back together for the call. We must expand |
| 4913 | // the source in case it is shared (this pass of legalize must traverse it). |
| 4914 | SDOperand SrcLo, SrcHi; |
| 4915 | ExpandOp(Source, SrcLo, SrcHi); |
| 4916 | Source = DAG.getNode(ISD::BUILD_PAIR, Source.getValueType(), SrcLo, SrcHi); |
| 4917 | |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4918 | RTLIB::Libcall LC; |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 4919 | if (DestTy == MVT::f32) |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4920 | LC = RTLIB::SINTTOFP_I64_F32; |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 4921 | else { |
| 4922 | assert(DestTy == MVT::f64 && "Unknown fp value type!"); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4923 | LC = RTLIB::SINTTOFP_I64_F64; |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 4924 | } |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 4925 | |
Evan Cheng | 4c6cfad | 2007-04-27 07:33:31 +0000 | [diff] [blame] | 4926 | 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] | 4927 | Source = DAG.getNode(ISD::SINT_TO_FP, DestTy, Source); |
| 4928 | SDOperand UnusedHiPart; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4929 | return ExpandLibCall(TLI.getLibcallName(LC), Source.Val, isSigned, |
| 4930 | UnusedHiPart); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4931 | } |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 4932 | |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 4933 | /// ExpandLegalINT_TO_FP - This function is responsible for legalizing a |
| 4934 | /// INT_TO_FP operation of the specified operand when the target requests that |
| 4935 | /// we expand it. At this point, we know that the result and operand types are |
| 4936 | /// legal for the target. |
| 4937 | SDOperand SelectionDAGLegalize::ExpandLegalINT_TO_FP(bool isSigned, |
| 4938 | SDOperand Op0, |
| 4939 | MVT::ValueType DestVT) { |
| 4940 | if (Op0.getValueType() == MVT::i32) { |
| 4941 | // simple 32-bit [signed|unsigned] integer to float/double expansion |
| 4942 | |
Chris Lattner | 58092e3 | 2007-01-20 22:35:55 +0000 | [diff] [blame] | 4943 | // get the stack frame index of a 8 byte buffer, pessimistically aligned |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 4944 | MachineFunction &MF = DAG.getMachineFunction(); |
Chris Lattner | 58092e3 | 2007-01-20 22:35:55 +0000 | [diff] [blame] | 4945 | const Type *F64Type = MVT::getTypeForValueType(MVT::f64); |
| 4946 | unsigned StackAlign = |
Chris Lattner | d2b7cec | 2007-02-14 05:52:17 +0000 | [diff] [blame] | 4947 | (unsigned)TLI.getTargetData()->getPrefTypeAlignment(F64Type); |
Chris Lattner | 58092e3 | 2007-01-20 22:35:55 +0000 | [diff] [blame] | 4948 | int SSFI = MF.getFrameInfo()->CreateStackObject(8, StackAlign); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 4949 | // get address of 8 byte buffer |
| 4950 | SDOperand StackSlot = DAG.getFrameIndex(SSFI, TLI.getPointerTy()); |
| 4951 | // word offset constant for Hi/Lo address computation |
| 4952 | SDOperand WordOff = DAG.getConstant(sizeof(int), TLI.getPointerTy()); |
| 4953 | // set up Hi and Lo (into buffer) address based on endian |
Chris Lattner | 408c428 | 2006-03-23 05:29:04 +0000 | [diff] [blame] | 4954 | SDOperand Hi = StackSlot; |
| 4955 | SDOperand Lo = DAG.getNode(ISD::ADD, TLI.getPointerTy(), StackSlot,WordOff); |
| 4956 | if (TLI.isLittleEndian()) |
| 4957 | std::swap(Hi, Lo); |
| 4958 | |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 4959 | // if signed map to unsigned space |
| 4960 | SDOperand Op0Mapped; |
| 4961 | if (isSigned) { |
| 4962 | // constant used to invert sign bit (signed to unsigned mapping) |
| 4963 | SDOperand SignBit = DAG.getConstant(0x80000000u, MVT::i32); |
| 4964 | Op0Mapped = DAG.getNode(ISD::XOR, MVT::i32, Op0, SignBit); |
| 4965 | } else { |
| 4966 | Op0Mapped = Op0; |
| 4967 | } |
| 4968 | // store the lo of the constructed double - based on integer input |
Evan Cheng | 786225a | 2006-10-05 23:01:46 +0000 | [diff] [blame] | 4969 | SDOperand Store1 = DAG.getStore(DAG.getEntryNode(), |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 4970 | Op0Mapped, Lo, NULL, 0); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 4971 | // initial hi portion of constructed double |
| 4972 | SDOperand InitialHi = DAG.getConstant(0x43300000u, MVT::i32); |
| 4973 | // store the hi of the constructed double - biased exponent |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 4974 | SDOperand Store2=DAG.getStore(Store1, InitialHi, Hi, NULL, 0); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 4975 | // load the constructed double |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 4976 | SDOperand Load = DAG.getLoad(MVT::f64, Store2, StackSlot, NULL, 0); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 4977 | // FP constant to bias correct the final result |
| 4978 | SDOperand Bias = DAG.getConstantFP(isSigned ? |
| 4979 | BitsToDouble(0x4330000080000000ULL) |
| 4980 | : BitsToDouble(0x4330000000000000ULL), |
| 4981 | MVT::f64); |
| 4982 | // subtract the bias |
| 4983 | SDOperand Sub = DAG.getNode(ISD::FSUB, MVT::f64, Load, Bias); |
| 4984 | // final result |
| 4985 | SDOperand Result; |
| 4986 | // handle final rounding |
| 4987 | if (DestVT == MVT::f64) { |
| 4988 | // do nothing |
| 4989 | Result = Sub; |
Dale Johannesen | 118cd9d | 2007-09-16 16:51:49 +0000 | [diff] [blame] | 4990 | } else if (MVT::getSizeInBits(DestVT) < MVT::getSizeInBits(MVT::f64)) { |
| 4991 | Result = DAG.getNode(ISD::FP_ROUND, DestVT, Sub); |
| 4992 | } else if (MVT::getSizeInBits(DestVT) > MVT::getSizeInBits(MVT::f64)) { |
| 4993 | Result = DAG.getNode(ISD::FP_EXTEND, DestVT, Sub); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 4994 | } |
| 4995 | return Result; |
| 4996 | } |
| 4997 | assert(!isSigned && "Legalize cannot Expand SINT_TO_FP for i64 yet"); |
| 4998 | SDOperand Tmp1 = DAG.getNode(ISD::SINT_TO_FP, DestVT, Op0); |
| 4999 | |
| 5000 | SDOperand SignSet = DAG.getSetCC(TLI.getSetCCResultTy(), Op0, |
| 5001 | DAG.getConstant(0, Op0.getValueType()), |
| 5002 | ISD::SETLT); |
| 5003 | SDOperand Zero = getIntPtrConstant(0), Four = getIntPtrConstant(4); |
| 5004 | SDOperand CstOffset = DAG.getNode(ISD::SELECT, Zero.getValueType(), |
| 5005 | SignSet, Four, Zero); |
| 5006 | |
| 5007 | // If the sign bit of the integer is set, the large number will be treated |
| 5008 | // as a negative number. To counteract this, the dynamic code adds an |
| 5009 | // offset depending on the data type. |
| 5010 | uint64_t FF; |
| 5011 | switch (Op0.getValueType()) { |
| 5012 | default: assert(0 && "Unsupported integer type!"); |
| 5013 | case MVT::i8 : FF = 0x43800000ULL; break; // 2^8 (as a float) |
| 5014 | case MVT::i16: FF = 0x47800000ULL; break; // 2^16 (as a float) |
| 5015 | case MVT::i32: FF = 0x4F800000ULL; break; // 2^32 (as a float) |
| 5016 | case MVT::i64: FF = 0x5F800000ULL; break; // 2^64 (as a float) |
| 5017 | } |
| 5018 | if (TLI.isLittleEndian()) FF <<= 32; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 5019 | static Constant *FudgeFactor = ConstantInt::get(Type::Int64Ty, FF); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5020 | |
| 5021 | SDOperand CPIdx = DAG.getConstantPool(FudgeFactor, TLI.getPointerTy()); |
| 5022 | CPIdx = DAG.getNode(ISD::ADD, TLI.getPointerTy(), CPIdx, CstOffset); |
| 5023 | SDOperand FudgeInReg; |
| 5024 | if (DestVT == MVT::f32) |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 5025 | FudgeInReg = DAG.getLoad(MVT::f32, DAG.getEntryNode(), CPIdx, NULL, 0); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5026 | else { |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 5027 | FudgeInReg = LegalizeOp(DAG.getExtLoad(ISD::EXTLOAD, DestVT, |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5028 | DAG.getEntryNode(), CPIdx, |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 5029 | NULL, 0, MVT::f32)); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5030 | } |
| 5031 | |
| 5032 | return DAG.getNode(ISD::FADD, DestVT, Tmp1, FudgeInReg); |
| 5033 | } |
| 5034 | |
| 5035 | /// PromoteLegalINT_TO_FP - This function is responsible for legalizing a |
| 5036 | /// *INT_TO_FP operation of the specified operand when the target requests that |
| 5037 | /// we promote it. At this point, we know that the result and operand types are |
| 5038 | /// legal for the target, and that there is a legal UINT_TO_FP or SINT_TO_FP |
| 5039 | /// operation that takes a larger input. |
| 5040 | SDOperand SelectionDAGLegalize::PromoteLegalINT_TO_FP(SDOperand LegalOp, |
| 5041 | MVT::ValueType DestVT, |
| 5042 | bool isSigned) { |
| 5043 | // First step, figure out the appropriate *INT_TO_FP operation to use. |
| 5044 | MVT::ValueType NewInTy = LegalOp.getValueType(); |
| 5045 | |
| 5046 | unsigned OpToUse = 0; |
| 5047 | |
| 5048 | // Scan for the appropriate larger type to use. |
| 5049 | while (1) { |
| 5050 | NewInTy = (MVT::ValueType)(NewInTy+1); |
| 5051 | assert(MVT::isInteger(NewInTy) && "Ran out of possibilities!"); |
| 5052 | |
| 5053 | // If the target supports SINT_TO_FP of this type, use it. |
| 5054 | switch (TLI.getOperationAction(ISD::SINT_TO_FP, NewInTy)) { |
| 5055 | default: break; |
| 5056 | case TargetLowering::Legal: |
| 5057 | if (!TLI.isTypeLegal(NewInTy)) |
| 5058 | break; // Can't use this datatype. |
| 5059 | // FALL THROUGH. |
| 5060 | case TargetLowering::Custom: |
| 5061 | OpToUse = ISD::SINT_TO_FP; |
| 5062 | break; |
| 5063 | } |
| 5064 | if (OpToUse) break; |
| 5065 | if (isSigned) continue; |
| 5066 | |
| 5067 | // If the target supports UINT_TO_FP of this type, use it. |
| 5068 | switch (TLI.getOperationAction(ISD::UINT_TO_FP, NewInTy)) { |
| 5069 | default: break; |
| 5070 | case TargetLowering::Legal: |
| 5071 | if (!TLI.isTypeLegal(NewInTy)) |
| 5072 | break; // Can't use this datatype. |
| 5073 | // FALL THROUGH. |
| 5074 | case TargetLowering::Custom: |
| 5075 | OpToUse = ISD::UINT_TO_FP; |
| 5076 | break; |
| 5077 | } |
| 5078 | if (OpToUse) break; |
| 5079 | |
| 5080 | // Otherwise, try a larger type. |
| 5081 | } |
| 5082 | |
| 5083 | // Okay, we found the operation and type to use. Zero extend our input to the |
| 5084 | // desired type then run the operation on it. |
| 5085 | return DAG.getNode(OpToUse, DestVT, |
| 5086 | DAG.getNode(isSigned ? ISD::SIGN_EXTEND : ISD::ZERO_EXTEND, |
| 5087 | NewInTy, LegalOp)); |
| 5088 | } |
| 5089 | |
| 5090 | /// PromoteLegalFP_TO_INT - This function is responsible for legalizing a |
| 5091 | /// FP_TO_*INT operation of the specified operand when the target requests that |
| 5092 | /// we promote it. At this point, we know that the result and operand types are |
| 5093 | /// legal for the target, and that there is a legal FP_TO_UINT or FP_TO_SINT |
| 5094 | /// operation that returns a larger result. |
| 5095 | SDOperand SelectionDAGLegalize::PromoteLegalFP_TO_INT(SDOperand LegalOp, |
| 5096 | MVT::ValueType DestVT, |
| 5097 | bool isSigned) { |
| 5098 | // First step, figure out the appropriate FP_TO*INT operation to use. |
| 5099 | MVT::ValueType NewOutTy = DestVT; |
| 5100 | |
| 5101 | unsigned OpToUse = 0; |
| 5102 | |
| 5103 | // Scan for the appropriate larger type to use. |
| 5104 | while (1) { |
| 5105 | NewOutTy = (MVT::ValueType)(NewOutTy+1); |
| 5106 | assert(MVT::isInteger(NewOutTy) && "Ran out of possibilities!"); |
| 5107 | |
| 5108 | // If the target supports FP_TO_SINT returning this type, use it. |
| 5109 | switch (TLI.getOperationAction(ISD::FP_TO_SINT, NewOutTy)) { |
| 5110 | default: break; |
| 5111 | case TargetLowering::Legal: |
| 5112 | if (!TLI.isTypeLegal(NewOutTy)) |
| 5113 | break; // Can't use this datatype. |
| 5114 | // FALL THROUGH. |
| 5115 | case TargetLowering::Custom: |
| 5116 | OpToUse = ISD::FP_TO_SINT; |
| 5117 | break; |
| 5118 | } |
| 5119 | if (OpToUse) break; |
| 5120 | |
| 5121 | // If the target supports FP_TO_UINT of this type, use it. |
| 5122 | switch (TLI.getOperationAction(ISD::FP_TO_UINT, NewOutTy)) { |
| 5123 | default: break; |
| 5124 | case TargetLowering::Legal: |
| 5125 | if (!TLI.isTypeLegal(NewOutTy)) |
| 5126 | break; // Can't use this datatype. |
| 5127 | // FALL THROUGH. |
| 5128 | case TargetLowering::Custom: |
| 5129 | OpToUse = ISD::FP_TO_UINT; |
| 5130 | break; |
| 5131 | } |
| 5132 | if (OpToUse) break; |
| 5133 | |
| 5134 | // Otherwise, try a larger type. |
| 5135 | } |
| 5136 | |
| 5137 | // Okay, we found the operation and type to use. Truncate the result of the |
| 5138 | // extended FP_TO_*INT operation to the desired size. |
| 5139 | return DAG.getNode(ISD::TRUNCATE, DestVT, |
| 5140 | DAG.getNode(OpToUse, NewOutTy, LegalOp)); |
| 5141 | } |
| 5142 | |
| 5143 | /// ExpandBSWAP - Open code the operations for BSWAP of the specified operation. |
| 5144 | /// |
| 5145 | SDOperand SelectionDAGLegalize::ExpandBSWAP(SDOperand Op) { |
| 5146 | MVT::ValueType VT = Op.getValueType(); |
| 5147 | MVT::ValueType SHVT = TLI.getShiftAmountTy(); |
| 5148 | SDOperand Tmp1, Tmp2, Tmp3, Tmp4, Tmp5, Tmp6, Tmp7, Tmp8; |
| 5149 | switch (VT) { |
| 5150 | default: assert(0 && "Unhandled Expand type in BSWAP!"); abort(); |
| 5151 | case MVT::i16: |
| 5152 | Tmp2 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(8, SHVT)); |
| 5153 | Tmp1 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(8, SHVT)); |
| 5154 | return DAG.getNode(ISD::OR, VT, Tmp1, Tmp2); |
| 5155 | case MVT::i32: |
| 5156 | Tmp4 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(24, SHVT)); |
| 5157 | Tmp3 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(8, SHVT)); |
| 5158 | Tmp2 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(8, SHVT)); |
| 5159 | Tmp1 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(24, SHVT)); |
| 5160 | Tmp3 = DAG.getNode(ISD::AND, VT, Tmp3, DAG.getConstant(0xFF0000, VT)); |
| 5161 | Tmp2 = DAG.getNode(ISD::AND, VT, Tmp2, DAG.getConstant(0xFF00, VT)); |
| 5162 | Tmp4 = DAG.getNode(ISD::OR, VT, Tmp4, Tmp3); |
| 5163 | Tmp2 = DAG.getNode(ISD::OR, VT, Tmp2, Tmp1); |
| 5164 | return DAG.getNode(ISD::OR, VT, Tmp4, Tmp2); |
| 5165 | case MVT::i64: |
| 5166 | Tmp8 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(56, SHVT)); |
| 5167 | Tmp7 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(40, SHVT)); |
| 5168 | Tmp6 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(24, SHVT)); |
| 5169 | Tmp5 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(8, SHVT)); |
| 5170 | Tmp4 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(8, SHVT)); |
| 5171 | Tmp3 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(24, SHVT)); |
| 5172 | Tmp2 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(40, SHVT)); |
| 5173 | Tmp1 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(56, SHVT)); |
| 5174 | Tmp7 = DAG.getNode(ISD::AND, VT, Tmp7, DAG.getConstant(255ULL<<48, VT)); |
| 5175 | Tmp6 = DAG.getNode(ISD::AND, VT, Tmp6, DAG.getConstant(255ULL<<40, VT)); |
| 5176 | Tmp5 = DAG.getNode(ISD::AND, VT, Tmp5, DAG.getConstant(255ULL<<32, VT)); |
| 5177 | Tmp4 = DAG.getNode(ISD::AND, VT, Tmp4, DAG.getConstant(255ULL<<24, VT)); |
| 5178 | Tmp3 = DAG.getNode(ISD::AND, VT, Tmp3, DAG.getConstant(255ULL<<16, VT)); |
| 5179 | Tmp2 = DAG.getNode(ISD::AND, VT, Tmp2, DAG.getConstant(255ULL<<8 , VT)); |
| 5180 | Tmp8 = DAG.getNode(ISD::OR, VT, Tmp8, Tmp7); |
| 5181 | Tmp6 = DAG.getNode(ISD::OR, VT, Tmp6, Tmp5); |
| 5182 | Tmp4 = DAG.getNode(ISD::OR, VT, Tmp4, Tmp3); |
| 5183 | Tmp2 = DAG.getNode(ISD::OR, VT, Tmp2, Tmp1); |
| 5184 | Tmp8 = DAG.getNode(ISD::OR, VT, Tmp8, Tmp6); |
| 5185 | Tmp4 = DAG.getNode(ISD::OR, VT, Tmp4, Tmp2); |
| 5186 | return DAG.getNode(ISD::OR, VT, Tmp8, Tmp4); |
| 5187 | } |
| 5188 | } |
| 5189 | |
| 5190 | /// ExpandBitCount - Expand the specified bitcount instruction into operations. |
| 5191 | /// |
| 5192 | SDOperand SelectionDAGLegalize::ExpandBitCount(unsigned Opc, SDOperand Op) { |
| 5193 | switch (Opc) { |
| 5194 | default: assert(0 && "Cannot expand this yet!"); |
| 5195 | case ISD::CTPOP: { |
| 5196 | static const uint64_t mask[6] = { |
| 5197 | 0x5555555555555555ULL, 0x3333333333333333ULL, |
| 5198 | 0x0F0F0F0F0F0F0F0FULL, 0x00FF00FF00FF00FFULL, |
| 5199 | 0x0000FFFF0000FFFFULL, 0x00000000FFFFFFFFULL |
| 5200 | }; |
| 5201 | MVT::ValueType VT = Op.getValueType(); |
| 5202 | MVT::ValueType ShVT = TLI.getShiftAmountTy(); |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 5203 | unsigned len = MVT::getSizeInBits(VT); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5204 | for (unsigned i = 0; (1U << i) <= (len / 2); ++i) { |
| 5205 | //x = (x & mask[i][len/8]) + (x >> (1 << i) & mask[i][len/8]) |
| 5206 | SDOperand Tmp2 = DAG.getConstant(mask[i], VT); |
| 5207 | SDOperand Tmp3 = DAG.getConstant(1ULL << i, ShVT); |
| 5208 | Op = DAG.getNode(ISD::ADD, VT, DAG.getNode(ISD::AND, VT, Op, Tmp2), |
| 5209 | DAG.getNode(ISD::AND, VT, |
| 5210 | DAG.getNode(ISD::SRL, VT, Op, Tmp3),Tmp2)); |
| 5211 | } |
| 5212 | return Op; |
| 5213 | } |
| 5214 | case ISD::CTLZ: { |
| 5215 | // for now, we do this: |
| 5216 | // x = x | (x >> 1); |
| 5217 | // x = x | (x >> 2); |
| 5218 | // ... |
| 5219 | // x = x | (x >>16); |
| 5220 | // x = x | (x >>32); // for 64-bit input |
| 5221 | // return popcount(~x); |
| 5222 | // |
| 5223 | // but see also: http://www.hackersdelight.org/HDcode/nlz.cc |
| 5224 | MVT::ValueType VT = Op.getValueType(); |
| 5225 | MVT::ValueType ShVT = TLI.getShiftAmountTy(); |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 5226 | unsigned len = MVT::getSizeInBits(VT); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5227 | for (unsigned i = 0; (1U << i) <= (len / 2); ++i) { |
| 5228 | SDOperand Tmp3 = DAG.getConstant(1ULL << i, ShVT); |
| 5229 | Op = DAG.getNode(ISD::OR, VT, Op, DAG.getNode(ISD::SRL, VT, Op, Tmp3)); |
| 5230 | } |
| 5231 | Op = DAG.getNode(ISD::XOR, VT, Op, DAG.getConstant(~0ULL, VT)); |
| 5232 | return DAG.getNode(ISD::CTPOP, VT, Op); |
| 5233 | } |
| 5234 | case ISD::CTTZ: { |
| 5235 | // for now, we use: { return popcount(~x & (x - 1)); } |
| 5236 | // unless the target has ctlz but not ctpop, in which case we use: |
| 5237 | // { return 32 - nlz(~x & (x-1)); } |
| 5238 | // see also http://www.hackersdelight.org/HDcode/ntz.cc |
| 5239 | MVT::ValueType VT = Op.getValueType(); |
| 5240 | SDOperand Tmp2 = DAG.getConstant(~0ULL, VT); |
| 5241 | SDOperand Tmp3 = DAG.getNode(ISD::AND, VT, |
| 5242 | DAG.getNode(ISD::XOR, VT, Op, Tmp2), |
| 5243 | DAG.getNode(ISD::SUB, VT, Op, DAG.getConstant(1, VT))); |
| 5244 | // If ISD::CTLZ is legal and CTPOP isn't, then do that instead. |
| 5245 | if (!TLI.isOperationLegal(ISD::CTPOP, VT) && |
| 5246 | TLI.isOperationLegal(ISD::CTLZ, VT)) |
| 5247 | return DAG.getNode(ISD::SUB, VT, |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 5248 | DAG.getConstant(MVT::getSizeInBits(VT), VT), |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5249 | DAG.getNode(ISD::CTLZ, VT, Tmp3)); |
| 5250 | return DAG.getNode(ISD::CTPOP, VT, Tmp3); |
| 5251 | } |
| 5252 | } |
| 5253 | } |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5254 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5255 | /// ExpandOp - Expand the specified SDOperand into its two component pieces |
| 5256 | /// Lo&Hi. Note that the Op MUST be an expanded type. As a result of this, the |
| 5257 | /// LegalizeNodes map is filled in for any results that are not expanded, the |
| 5258 | /// ExpandedNodes map is filled in for any results that are expanded, and the |
| 5259 | /// Lo/Hi values are returned. |
| 5260 | void SelectionDAGLegalize::ExpandOp(SDOperand Op, SDOperand &Lo, SDOperand &Hi){ |
| 5261 | MVT::ValueType VT = Op.getValueType(); |
Chris Lattner | 71c42a0 | 2005-01-16 01:11:45 +0000 | [diff] [blame] | 5262 | MVT::ValueType NVT = TLI.getTypeToTransformTo(VT); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5263 | SDNode *Node = Op.Val; |
| 5264 | assert(getTypeAction(VT) == Expand && "Not an expanded type!"); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 5265 | assert(((MVT::isInteger(NVT) && NVT < VT) || MVT::isFloatingPoint(VT) || |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5266 | MVT::isVector(VT)) && |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5267 | "Cannot expand to FP value or to larger int value!"); |
| 5268 | |
Chris Lattner | 6fdcb25 | 2005-09-02 20:32:45 +0000 | [diff] [blame] | 5269 | // See if we already expanded it. |
Chris Lattner | 40030bf | 2007-02-04 01:17:38 +0000 | [diff] [blame] | 5270 | DenseMap<SDOperand, std::pair<SDOperand, SDOperand> >::iterator I |
Chris Lattner | 6fdcb25 | 2005-09-02 20:32:45 +0000 | [diff] [blame] | 5271 | = ExpandedNodes.find(Op); |
| 5272 | if (I != ExpandedNodes.end()) { |
| 5273 | Lo = I->second.first; |
| 5274 | Hi = I->second.second; |
| 5275 | return; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5276 | } |
| 5277 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5278 | switch (Node->getOpcode()) { |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 5279 | case ISD::CopyFromReg: |
| 5280 | assert(0 && "CopyFromReg must be legal!"); |
Dale Johannesen | 6eaeff2 | 2007-10-10 01:01:31 +0000 | [diff] [blame] | 5281 | case ISD::FP_ROUND_INREG: |
| 5282 | if (VT == MVT::ppcf128 && |
| 5283 | TLI.getOperationAction(ISD::FP_ROUND_INREG, VT) == |
| 5284 | TargetLowering::Custom) { |
Dale Johannesen | fcf4d24 | 2007-10-11 23:32:15 +0000 | [diff] [blame] | 5285 | SDOperand SrcLo, SrcHi, Src; |
| 5286 | ExpandOp(Op.getOperand(0), SrcLo, SrcHi); |
| 5287 | Src = DAG.getNode(ISD::BUILD_PAIR, VT, SrcLo, SrcHi); |
| 5288 | SDOperand Result = TLI.LowerOperation( |
| 5289 | DAG.getNode(ISD::FP_ROUND_INREG, VT, Src, Op.getOperand(1)), DAG); |
Dale Johannesen | 6eaeff2 | 2007-10-10 01:01:31 +0000 | [diff] [blame] | 5290 | assert(Result.Val->getOpcode() == ISD::BUILD_PAIR); |
| 5291 | Lo = Result.Val->getOperand(0); |
| 5292 | Hi = Result.Val->getOperand(1); |
| 5293 | break; |
| 5294 | } |
| 5295 | // fall through |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 5296 | default: |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 5297 | #ifndef NDEBUG |
Dan Gohman | 3983358 | 2007-06-04 16:17:33 +0000 | [diff] [blame] | 5298 | cerr << "NODE: "; Node->dump(&DAG); cerr << "\n"; |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 5299 | #endif |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5300 | assert(0 && "Do not know how to expand this operator!"); |
| 5301 | abort(); |
Dale Johannesen | 25f1d08 | 2007-10-31 00:32:36 +0000 | [diff] [blame^] | 5302 | case ISD::EXTRACT_VECTOR_ELT: |
| 5303 | assert(VT==MVT::i64 && "Do not know how to expand this operator!"); |
| 5304 | // ExpandEXTRACT_VECTOR_ELT tolerates invalid result types. |
| 5305 | Lo = ExpandEXTRACT_VECTOR_ELT(Op); |
| 5306 | return ExpandOp(Lo, Lo, Hi); |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 5307 | case ISD::UNDEF: |
Evan Cheng | aa975c1 | 2006-12-16 02:20:50 +0000 | [diff] [blame] | 5308 | NVT = TLI.getTypeToExpandTo(VT); |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 5309 | Lo = DAG.getNode(ISD::UNDEF, NVT); |
| 5310 | Hi = DAG.getNode(ISD::UNDEF, NVT); |
| 5311 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5312 | case ISD::Constant: { |
| 5313 | uint64_t Cst = cast<ConstantSDNode>(Node)->getValue(); |
| 5314 | Lo = DAG.getConstant(Cst, NVT); |
| 5315 | Hi = DAG.getConstant(Cst >> MVT::getSizeInBits(NVT), NVT); |
| 5316 | break; |
| 5317 | } |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 5318 | case ISD::ConstantFP: { |
| 5319 | ConstantFPSDNode *CFP = cast<ConstantFPSDNode>(Node); |
Dale Johannesen | a471c2e | 2007-10-11 18:07:22 +0000 | [diff] [blame] | 5320 | if (CFP->getValueType(0) == MVT::ppcf128) { |
| 5321 | APInt api = CFP->getValueAPF().convertToAPInt(); |
| 5322 | Lo = DAG.getConstantFP(APFloat(APInt(64, 1, &api.getRawData()[1])), |
| 5323 | MVT::f64); |
| 5324 | Hi = DAG.getConstantFP(APFloat(APInt(64, 1, &api.getRawData()[0])), |
| 5325 | MVT::f64); |
| 5326 | break; |
| 5327 | } |
Evan Cheng | 279101e | 2006-12-12 22:19:28 +0000 | [diff] [blame] | 5328 | Lo = ExpandConstantFP(CFP, false, DAG, TLI); |
Evan Cheng | 9f87788 | 2006-12-13 20:57:08 +0000 | [diff] [blame] | 5329 | if (getTypeAction(Lo.getValueType()) == Expand) |
| 5330 | ExpandOp(Lo, Lo, Hi); |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 5331 | break; |
| 5332 | } |
Chris Lattner | d4e50bb | 2005-03-28 22:03:13 +0000 | [diff] [blame] | 5333 | case ISD::BUILD_PAIR: |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5334 | // Return the operands. |
| 5335 | Lo = Node->getOperand(0); |
| 5336 | Hi = Node->getOperand(1); |
Chris Lattner | d4e50bb | 2005-03-28 22:03:13 +0000 | [diff] [blame] | 5337 | break; |
Chris Lattner | 58f7963 | 2005-12-12 22:27:43 +0000 | [diff] [blame] | 5338 | |
| 5339 | case ISD::SIGN_EXTEND_INREG: |
| 5340 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Chris Lattner | 4bdd275 | 2006-10-06 17:34:12 +0000 | [diff] [blame] | 5341 | // sext_inreg the low part if needed. |
| 5342 | Lo = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Lo, Node->getOperand(1)); |
| 5343 | |
| 5344 | // The high part gets the sign extension from the lo-part. This handles |
| 5345 | // things like sextinreg V:i64 from i8. |
Chris Lattner | 58f7963 | 2005-12-12 22:27:43 +0000 | [diff] [blame] | 5346 | Hi = DAG.getNode(ISD::SRA, NVT, Lo, |
| 5347 | DAG.getConstant(MVT::getSizeInBits(NVT)-1, |
| 5348 | TLI.getShiftAmountTy())); |
Chris Lattner | 58f7963 | 2005-12-12 22:27:43 +0000 | [diff] [blame] | 5349 | break; |
Chris Lattner | d4e50bb | 2005-03-28 22:03:13 +0000 | [diff] [blame] | 5350 | |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 5351 | case ISD::BSWAP: { |
| 5352 | ExpandOp(Node->getOperand(0), Lo, Hi); |
| 5353 | SDOperand TempLo = DAG.getNode(ISD::BSWAP, NVT, Hi); |
| 5354 | Hi = DAG.getNode(ISD::BSWAP, NVT, Lo); |
| 5355 | Lo = TempLo; |
| 5356 | break; |
| 5357 | } |
| 5358 | |
Chris Lattner | edb1add | 2005-05-11 04:51:16 +0000 | [diff] [blame] | 5359 | case ISD::CTPOP: |
| 5360 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Chris Lattner | 9b583b4 | 2005-05-11 05:09:47 +0000 | [diff] [blame] | 5361 | Lo = DAG.getNode(ISD::ADD, NVT, // ctpop(HL) -> ctpop(H)+ctpop(L) |
| 5362 | DAG.getNode(ISD::CTPOP, NVT, Lo), |
| 5363 | DAG.getNode(ISD::CTPOP, NVT, Hi)); |
Chris Lattner | edb1add | 2005-05-11 04:51:16 +0000 | [diff] [blame] | 5364 | Hi = DAG.getConstant(0, NVT); |
| 5365 | break; |
| 5366 | |
Chris Lattner | 39a8f33 | 2005-05-12 19:05:01 +0000 | [diff] [blame] | 5367 | case ISD::CTLZ: { |
| 5368 | // ctlz (HL) -> ctlz(H) != 32 ? ctlz(H) : (ctlz(L)+32) |
Chris Lattner | 3becf20 | 2005-05-12 19:27:51 +0000 | [diff] [blame] | 5369 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Chris Lattner | 39a8f33 | 2005-05-12 19:05:01 +0000 | [diff] [blame] | 5370 | SDOperand BitsC = DAG.getConstant(MVT::getSizeInBits(NVT), NVT); |
| 5371 | SDOperand HLZ = DAG.getNode(ISD::CTLZ, NVT, Hi); |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 5372 | SDOperand TopNotZero = DAG.getSetCC(TLI.getSetCCResultTy(), HLZ, BitsC, |
| 5373 | ISD::SETNE); |
Chris Lattner | 39a8f33 | 2005-05-12 19:05:01 +0000 | [diff] [blame] | 5374 | SDOperand LowPart = DAG.getNode(ISD::CTLZ, NVT, Lo); |
| 5375 | LowPart = DAG.getNode(ISD::ADD, NVT, LowPart, BitsC); |
| 5376 | |
| 5377 | Lo = DAG.getNode(ISD::SELECT, NVT, TopNotZero, HLZ, LowPart); |
| 5378 | Hi = DAG.getConstant(0, NVT); |
| 5379 | break; |
| 5380 | } |
| 5381 | |
| 5382 | case ISD::CTTZ: { |
| 5383 | // cttz (HL) -> cttz(L) != 32 ? cttz(L) : (cttz(H)+32) |
Chris Lattner | 3becf20 | 2005-05-12 19:27:51 +0000 | [diff] [blame] | 5384 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Chris Lattner | 39a8f33 | 2005-05-12 19:05:01 +0000 | [diff] [blame] | 5385 | SDOperand BitsC = DAG.getConstant(MVT::getSizeInBits(NVT), NVT); |
| 5386 | SDOperand LTZ = DAG.getNode(ISD::CTTZ, NVT, Lo); |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 5387 | SDOperand BotNotZero = DAG.getSetCC(TLI.getSetCCResultTy(), LTZ, BitsC, |
| 5388 | ISD::SETNE); |
Chris Lattner | 39a8f33 | 2005-05-12 19:05:01 +0000 | [diff] [blame] | 5389 | SDOperand HiPart = DAG.getNode(ISD::CTTZ, NVT, Hi); |
| 5390 | HiPart = DAG.getNode(ISD::ADD, NVT, HiPart, BitsC); |
| 5391 | |
| 5392 | Lo = DAG.getNode(ISD::SELECT, NVT, BotNotZero, LTZ, HiPart); |
| 5393 | Hi = DAG.getConstant(0, NVT); |
| 5394 | break; |
| 5395 | } |
Chris Lattner | edb1add | 2005-05-11 04:51:16 +0000 | [diff] [blame] | 5396 | |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 5397 | case ISD::VAARG: { |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5398 | SDOperand Ch = Node->getOperand(0); // Legalize the chain. |
| 5399 | SDOperand Ptr = Node->getOperand(1); // Legalize the pointer. |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 5400 | Lo = DAG.getVAArg(NVT, Ch, Ptr, Node->getOperand(2)); |
| 5401 | Hi = DAG.getVAArg(NVT, Lo.getValue(1), Ptr, Node->getOperand(2)); |
| 5402 | |
| 5403 | // Remember that we legalized the chain. |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5404 | Hi = LegalizeOp(Hi); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 5405 | AddLegalizedOperand(Op.getValue(1), Hi.getValue(1)); |
| 5406 | if (!TLI.isLittleEndian()) |
| 5407 | std::swap(Lo, Hi); |
| 5408 | break; |
| 5409 | } |
| 5410 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5411 | case ISD::LOAD: { |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 5412 | LoadSDNode *LD = cast<LoadSDNode>(Node); |
| 5413 | SDOperand Ch = LD->getChain(); // Legalize the chain. |
| 5414 | SDOperand Ptr = LD->getBasePtr(); // Legalize the pointer. |
| 5415 | ISD::LoadExtType ExtType = LD->getExtensionType(); |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 5416 | int SVOffset = LD->getSrcValueOffset(); |
| 5417 | unsigned Alignment = LD->getAlignment(); |
| 5418 | bool isVolatile = LD->isVolatile(); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5419 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 5420 | if (ExtType == ISD::NON_EXTLOAD) { |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 5421 | Lo = DAG.getLoad(NVT, Ch, Ptr, LD->getSrcValue(), SVOffset, |
| 5422 | isVolatile, Alignment); |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 5423 | if (VT == MVT::f32 || VT == MVT::f64) { |
| 5424 | // f32->i32 or f64->i64 one to one expansion. |
| 5425 | // Remember that we legalized the chain. |
| 5426 | AddLegalizedOperand(SDOperand(Node, 1), LegalizeOp(Lo.getValue(1))); |
Evan Cheng | 9f87788 | 2006-12-13 20:57:08 +0000 | [diff] [blame] | 5427 | // Recursively expand the new load. |
| 5428 | if (getTypeAction(NVT) == Expand) |
| 5429 | ExpandOp(Lo, Lo, Hi); |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 5430 | break; |
| 5431 | } |
Chris Lattner | ec39a45 | 2005-01-19 18:02:17 +0000 | [diff] [blame] | 5432 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 5433 | // Increment the pointer to the other half. |
| 5434 | unsigned IncrementSize = MVT::getSizeInBits(Lo.getValueType())/8; |
| 5435 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
| 5436 | getIntPtrConstant(IncrementSize)); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5437 | SVOffset += IncrementSize; |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 5438 | Alignment = MinAlign(Alignment, IncrementSize); |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 5439 | Hi = DAG.getLoad(NVT, Ch, Ptr, LD->getSrcValue(), SVOffset, |
| 5440 | isVolatile, Alignment); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 5441 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 5442 | // Build a factor node to remember that this load is independent of the |
| 5443 | // other one. |
| 5444 | SDOperand TF = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1), |
| 5445 | Hi.getValue(1)); |
| 5446 | |
| 5447 | // Remember that we legalized the chain. |
| 5448 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(TF)); |
| 5449 | if (!TLI.isLittleEndian()) |
| 5450 | std::swap(Lo, Hi); |
| 5451 | } else { |
Evan Cheng | 2e49f09 | 2006-10-11 07:10:22 +0000 | [diff] [blame] | 5452 | MVT::ValueType EVT = LD->getLoadedVT(); |
Evan Cheng | 548f611 | 2006-12-13 03:19:57 +0000 | [diff] [blame] | 5453 | |
Dale Johannesen | b6210fc | 2007-10-19 20:29:00 +0000 | [diff] [blame] | 5454 | if ((VT == MVT::f64 && EVT == MVT::f32) || |
| 5455 | (VT == MVT::ppcf128 && (EVT==MVT::f64 || EVT==MVT::f32))) { |
Evan Cheng | 548f611 | 2006-12-13 03:19:57 +0000 | [diff] [blame] | 5456 | // f64 = EXTLOAD f32 should expand to LOAD, FP_EXTEND |
| 5457 | SDOperand Load = DAG.getLoad(EVT, Ch, Ptr, LD->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 5458 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 548f611 | 2006-12-13 03:19:57 +0000 | [diff] [blame] | 5459 | // Remember that we legalized the chain. |
| 5460 | AddLegalizedOperand(SDOperand(Node, 1), LegalizeOp(Load.getValue(1))); |
| 5461 | ExpandOp(DAG.getNode(ISD::FP_EXTEND, VT, Load), Lo, Hi); |
| 5462 | break; |
| 5463 | } |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 5464 | |
| 5465 | if (EVT == NVT) |
| 5466 | Lo = DAG.getLoad(NVT, Ch, Ptr, LD->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 5467 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 5468 | else |
| 5469 | Lo = DAG.getExtLoad(ExtType, NVT, Ch, Ptr, LD->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 5470 | SVOffset, EVT, isVolatile, |
| 5471 | Alignment); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 5472 | |
| 5473 | // Remember that we legalized the chain. |
| 5474 | AddLegalizedOperand(SDOperand(Node, 1), LegalizeOp(Lo.getValue(1))); |
| 5475 | |
| 5476 | if (ExtType == ISD::SEXTLOAD) { |
| 5477 | // The high part is obtained by SRA'ing all but one of the bits of the |
| 5478 | // lo part. |
| 5479 | unsigned LoSize = MVT::getSizeInBits(Lo.getValueType()); |
| 5480 | Hi = DAG.getNode(ISD::SRA, NVT, Lo, |
| 5481 | DAG.getConstant(LoSize-1, TLI.getShiftAmountTy())); |
| 5482 | } else if (ExtType == ISD::ZEXTLOAD) { |
| 5483 | // The high part is just a zero. |
| 5484 | Hi = DAG.getConstant(0, NVT); |
| 5485 | } else /* if (ExtType == ISD::EXTLOAD) */ { |
| 5486 | // The high part is undefined. |
| 5487 | Hi = DAG.getNode(ISD::UNDEF, NVT); |
| 5488 | } |
| 5489 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5490 | break; |
| 5491 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5492 | case ISD::AND: |
| 5493 | case ISD::OR: |
| 5494 | case ISD::XOR: { // Simple logical operators -> two trivial pieces. |
| 5495 | SDOperand LL, LH, RL, RH; |
| 5496 | ExpandOp(Node->getOperand(0), LL, LH); |
| 5497 | ExpandOp(Node->getOperand(1), RL, RH); |
| 5498 | Lo = DAG.getNode(Node->getOpcode(), NVT, LL, RL); |
| 5499 | Hi = DAG.getNode(Node->getOpcode(), NVT, LH, RH); |
| 5500 | break; |
| 5501 | } |
| 5502 | case ISD::SELECT: { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 5503 | SDOperand LL, LH, RL, RH; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5504 | ExpandOp(Node->getOperand(1), LL, LH); |
| 5505 | ExpandOp(Node->getOperand(2), RL, RH); |
Evan Cheng | 19103b1 | 2006-12-15 22:42:55 +0000 | [diff] [blame] | 5506 | if (getTypeAction(NVT) == Expand) |
| 5507 | NVT = TLI.getTypeToExpandTo(NVT); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 5508 | Lo = DAG.getNode(ISD::SELECT, NVT, Node->getOperand(0), LL, RL); |
Evan Cheng | 19103b1 | 2006-12-15 22:42:55 +0000 | [diff] [blame] | 5509 | if (VT != MVT::f32) |
| 5510 | Hi = DAG.getNode(ISD::SELECT, NVT, Node->getOperand(0), LH, RH); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5511 | break; |
| 5512 | } |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 5513 | case ISD::SELECT_CC: { |
| 5514 | SDOperand TL, TH, FL, FH; |
| 5515 | ExpandOp(Node->getOperand(2), TL, TH); |
| 5516 | ExpandOp(Node->getOperand(3), FL, FH); |
Evan Cheng | 19103b1 | 2006-12-15 22:42:55 +0000 | [diff] [blame] | 5517 | if (getTypeAction(NVT) == Expand) |
| 5518 | NVT = TLI.getTypeToExpandTo(NVT); |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 5519 | Lo = DAG.getNode(ISD::SELECT_CC, NVT, Node->getOperand(0), |
| 5520 | Node->getOperand(1), TL, FL, Node->getOperand(4)); |
Evan Cheng | 19103b1 | 2006-12-15 22:42:55 +0000 | [diff] [blame] | 5521 | if (VT != MVT::f32) |
| 5522 | Hi = DAG.getNode(ISD::SELECT_CC, NVT, Node->getOperand(0), |
| 5523 | Node->getOperand(1), TH, FH, Node->getOperand(4)); |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 5524 | break; |
| 5525 | } |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5526 | case ISD::ANY_EXTEND: |
| 5527 | // The low part is any extension of the input (which degenerates to a copy). |
| 5528 | Lo = DAG.getNode(ISD::ANY_EXTEND, NVT, Node->getOperand(0)); |
| 5529 | // The high part is undefined. |
| 5530 | Hi = DAG.getNode(ISD::UNDEF, NVT); |
| 5531 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5532 | case ISD::SIGN_EXTEND: { |
| 5533 | // The low part is just a sign extension of the input (which degenerates to |
| 5534 | // a copy). |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5535 | Lo = DAG.getNode(ISD::SIGN_EXTEND, NVT, Node->getOperand(0)); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 5536 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5537 | // The high part is obtained by SRA'ing all but one of the bits of the lo |
| 5538 | // part. |
Chris Lattner | 2dad454 | 2005-01-12 18:19:52 +0000 | [diff] [blame] | 5539 | unsigned LoSize = MVT::getSizeInBits(Lo.getValueType()); |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5540 | Hi = DAG.getNode(ISD::SRA, NVT, Lo, |
| 5541 | DAG.getConstant(LoSize-1, TLI.getShiftAmountTy())); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5542 | break; |
| 5543 | } |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5544 | case ISD::ZERO_EXTEND: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5545 | // The low part is just a zero extension of the input (which degenerates to |
| 5546 | // a copy). |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5547 | Lo = DAG.getNode(ISD::ZERO_EXTEND, NVT, Node->getOperand(0)); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 5548 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5549 | // The high part is just a zero. |
| 5550 | Hi = DAG.getConstant(0, NVT); |
| 5551 | break; |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 5552 | |
Chris Lattner | 4c948eb | 2007-02-13 23:55:16 +0000 | [diff] [blame] | 5553 | case ISD::TRUNCATE: { |
| 5554 | // The input value must be larger than this value. Expand *it*. |
| 5555 | SDOperand NewLo; |
| 5556 | ExpandOp(Node->getOperand(0), NewLo, Hi); |
| 5557 | |
| 5558 | // The low part is now either the right size, or it is closer. If not the |
| 5559 | // right size, make an illegal truncate so we recursively expand it. |
| 5560 | if (NewLo.getValueType() != Node->getValueType(0)) |
| 5561 | NewLo = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0), NewLo); |
| 5562 | ExpandOp(NewLo, Lo, Hi); |
| 5563 | break; |
| 5564 | } |
| 5565 | |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 5566 | case ISD::BIT_CONVERT: { |
Chris Lattner | f3f333d | 2006-09-09 00:20:27 +0000 | [diff] [blame] | 5567 | SDOperand Tmp; |
| 5568 | if (TLI.getOperationAction(ISD::BIT_CONVERT, VT) == TargetLowering::Custom){ |
| 5569 | // If the target wants to, allow it to lower this itself. |
| 5570 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 5571 | case Expand: assert(0 && "cannot expand FP!"); |
| 5572 | case Legal: Tmp = LegalizeOp(Node->getOperand(0)); break; |
| 5573 | case Promote: Tmp = PromoteOp (Node->getOperand(0)); break; |
| 5574 | } |
| 5575 | Tmp = TLI.LowerOperation(DAG.getNode(ISD::BIT_CONVERT, VT, Tmp), DAG); |
| 5576 | } |
| 5577 | |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 5578 | // f32 / f64 must be expanded to i32 / i64. |
Evan Cheng | 13acce3 | 2006-12-11 19:27:14 +0000 | [diff] [blame] | 5579 | if (VT == MVT::f32 || VT == MVT::f64) { |
| 5580 | Lo = DAG.getNode(ISD::BIT_CONVERT, NVT, Node->getOperand(0)); |
Evan Cheng | 19103b1 | 2006-12-15 22:42:55 +0000 | [diff] [blame] | 5581 | if (getTypeAction(NVT) == Expand) |
| 5582 | ExpandOp(Lo, Lo, Hi); |
Evan Cheng | 7b2b5c8 | 2006-12-12 19:53:13 +0000 | [diff] [blame] | 5583 | break; |
| 5584 | } |
| 5585 | |
| 5586 | // If source operand will be expanded to the same type as VT, i.e. |
| 5587 | // i64 <- f64, i32 <- f32, expand the source operand instead. |
| 5588 | MVT::ValueType VT0 = Node->getOperand(0).getValueType(); |
| 5589 | if (getTypeAction(VT0) == Expand && TLI.getTypeToTransformTo(VT0) == VT) { |
| 5590 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 5591 | break; |
| 5592 | } |
| 5593 | |
Chris Lattner | f3f333d | 2006-09-09 00:20:27 +0000 | [diff] [blame] | 5594 | // Turn this into a load/store pair by default. |
| 5595 | if (Tmp.Val == 0) |
Evan Cheng | 13acce3 | 2006-12-11 19:27:14 +0000 | [diff] [blame] | 5596 | Tmp = ExpandBIT_CONVERT(VT, Node->getOperand(0)); |
Chris Lattner | f3f333d | 2006-09-09 00:20:27 +0000 | [diff] [blame] | 5597 | |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 5598 | ExpandOp(Tmp, Lo, Hi); |
| 5599 | break; |
| 5600 | } |
Andrew Lenharth | f70e30b | 2005-11-20 21:32:07 +0000 | [diff] [blame] | 5601 | |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5602 | case ISD::READCYCLECOUNTER: |
Chris Lattner | 308575b | 2005-11-20 22:56:56 +0000 | [diff] [blame] | 5603 | assert(TLI.getOperationAction(ISD::READCYCLECOUNTER, VT) == |
| 5604 | TargetLowering::Custom && |
| 5605 | "Must custom expand ReadCycleCounter"); |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5606 | Lo = TLI.LowerOperation(Op, DAG); |
| 5607 | assert(Lo.Val && "Node must be custom expanded!"); |
| 5608 | Hi = Lo.getValue(1); |
Chris Lattner | 308575b | 2005-11-20 22:56:56 +0000 | [diff] [blame] | 5609 | AddLegalizedOperand(SDOperand(Node, 1), // Remember we legalized the chain. |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5610 | LegalizeOp(Lo.getValue(2))); |
Andrew Lenharth | f70e30b | 2005-11-20 21:32:07 +0000 | [diff] [blame] | 5611 | break; |
| 5612 | |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 5613 | // These operators cannot be expanded directly, emit them as calls to |
| 5614 | // library functions. |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5615 | case ISD::FP_TO_SINT: { |
Chris Lattner | 80a3e94 | 2005-07-29 00:33:32 +0000 | [diff] [blame] | 5616 | if (TLI.getOperationAction(ISD::FP_TO_SINT, VT) == TargetLowering::Custom) { |
Chris Lattner | f20d183 | 2005-07-30 01:40:57 +0000 | [diff] [blame] | 5617 | SDOperand Op; |
| 5618 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 5619 | case Expand: assert(0 && "cannot expand FP!"); |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5620 | case Legal: Op = LegalizeOp(Node->getOperand(0)); break; |
| 5621 | case Promote: Op = PromoteOp (Node->getOperand(0)); break; |
Chris Lattner | f20d183 | 2005-07-30 01:40:57 +0000 | [diff] [blame] | 5622 | } |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 5623 | |
Chris Lattner | f20d183 | 2005-07-30 01:40:57 +0000 | [diff] [blame] | 5624 | Op = TLI.LowerOperation(DAG.getNode(ISD::FP_TO_SINT, VT, Op), DAG); |
| 5625 | |
Chris Lattner | 80a3e94 | 2005-07-29 00:33:32 +0000 | [diff] [blame] | 5626 | // Now that the custom expander is done, expand the result, which is still |
| 5627 | // VT. |
Chris Lattner | 07dffd6 | 2005-08-26 00:14:16 +0000 | [diff] [blame] | 5628 | if (Op.Val) { |
| 5629 | ExpandOp(Op, Lo, Hi); |
| 5630 | break; |
| 5631 | } |
Chris Lattner | 80a3e94 | 2005-07-29 00:33:32 +0000 | [diff] [blame] | 5632 | } |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 5633 | |
Dale Johannesen | 161e897 | 2007-10-05 20:04:43 +0000 | [diff] [blame] | 5634 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 5635 | if (Node->getOperand(0).getValueType() == MVT::f32) |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5636 | LC = RTLIB::FPTOSINT_F32_I64; |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 5637 | else if (Node->getOperand(0).getValueType() == MVT::f64) |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5638 | LC = RTLIB::FPTOSINT_F64_I64; |
Dale Johannesen | 161e897 | 2007-10-05 20:04:43 +0000 | [diff] [blame] | 5639 | else if (Node->getOperand(0).getValueType() == MVT::f80) |
| 5640 | LC = RTLIB::FPTOSINT_F80_I64; |
| 5641 | else if (Node->getOperand(0).getValueType() == MVT::ppcf128) |
| 5642 | LC = RTLIB::FPTOSINT_PPCF128_I64; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5643 | Lo = ExpandLibCall(TLI.getLibcallName(LC), Node, |
| 5644 | false/*sign irrelevant*/, Hi); |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 5645 | break; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5646 | } |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 5647 | |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5648 | case ISD::FP_TO_UINT: { |
Chris Lattner | 80a3e94 | 2005-07-29 00:33:32 +0000 | [diff] [blame] | 5649 | if (TLI.getOperationAction(ISD::FP_TO_UINT, VT) == TargetLowering::Custom) { |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5650 | SDOperand Op; |
| 5651 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 5652 | case Expand: assert(0 && "cannot expand FP!"); |
| 5653 | case Legal: Op = LegalizeOp(Node->getOperand(0)); break; |
| 5654 | case Promote: Op = PromoteOp (Node->getOperand(0)); break; |
| 5655 | } |
| 5656 | |
| 5657 | Op = TLI.LowerOperation(DAG.getNode(ISD::FP_TO_UINT, VT, Op), DAG); |
| 5658 | |
| 5659 | // Now that the custom expander is done, expand the result. |
Chris Lattner | 07dffd6 | 2005-08-26 00:14:16 +0000 | [diff] [blame] | 5660 | if (Op.Val) { |
| 5661 | ExpandOp(Op, Lo, Hi); |
| 5662 | break; |
| 5663 | } |
Chris Lattner | 80a3e94 | 2005-07-29 00:33:32 +0000 | [diff] [blame] | 5664 | } |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 5665 | |
Evan Cheng | daccea18 | 2007-10-05 01:09:32 +0000 | [diff] [blame] | 5666 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 5667 | if (Node->getOperand(0).getValueType() == MVT::f32) |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5668 | LC = RTLIB::FPTOUINT_F32_I64; |
Dale Johannesen | 72292f0 | 2007-09-28 18:44:17 +0000 | [diff] [blame] | 5669 | else if (Node->getOperand(0).getValueType() == MVT::f64) |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5670 | LC = RTLIB::FPTOUINT_F64_I64; |
Dale Johannesen | 161e897 | 2007-10-05 20:04:43 +0000 | [diff] [blame] | 5671 | else if (Node->getOperand(0).getValueType() == MVT::f80) |
| 5672 | LC = RTLIB::FPTOUINT_F80_I64; |
| 5673 | else if (Node->getOperand(0).getValueType() == MVT::ppcf128) |
| 5674 | LC = RTLIB::FPTOUINT_PPCF128_I64; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5675 | Lo = ExpandLibCall(TLI.getLibcallName(LC), Node, |
| 5676 | false/*sign irrelevant*/, Hi); |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 5677 | break; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5678 | } |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 5679 | |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 5680 | case ISD::SHL: { |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 5681 | // If the target wants custom lowering, do so. |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 5682 | SDOperand ShiftAmt = LegalizeOp(Node->getOperand(1)); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 5683 | if (TLI.getOperationAction(ISD::SHL, VT) == TargetLowering::Custom) { |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5684 | SDOperand Op = DAG.getNode(ISD::SHL, VT, Node->getOperand(0), ShiftAmt); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 5685 | Op = TLI.LowerOperation(Op, DAG); |
| 5686 | if (Op.Val) { |
| 5687 | // Now that the custom expander is done, expand the result, which is |
| 5688 | // still VT. |
| 5689 | ExpandOp(Op, Lo, Hi); |
| 5690 | break; |
| 5691 | } |
| 5692 | } |
| 5693 | |
Chris Lattner | 79980b0 | 2006-09-13 03:50:39 +0000 | [diff] [blame] | 5694 | // If ADDC/ADDE are supported and if the shift amount is a constant 1, emit |
| 5695 | // this X << 1 as X+X. |
| 5696 | if (ConstantSDNode *ShAmt = dyn_cast<ConstantSDNode>(ShiftAmt)) { |
| 5697 | if (ShAmt->getValue() == 1 && TLI.isOperationLegal(ISD::ADDC, NVT) && |
| 5698 | TLI.isOperationLegal(ISD::ADDE, NVT)) { |
| 5699 | SDOperand LoOps[2], HiOps[3]; |
| 5700 | ExpandOp(Node->getOperand(0), LoOps[0], HiOps[0]); |
| 5701 | SDVTList VTList = DAG.getVTList(LoOps[0].getValueType(), MVT::Flag); |
| 5702 | LoOps[1] = LoOps[0]; |
| 5703 | Lo = DAG.getNode(ISD::ADDC, VTList, LoOps, 2); |
| 5704 | |
| 5705 | HiOps[1] = HiOps[0]; |
| 5706 | HiOps[2] = Lo.getValue(1); |
| 5707 | Hi = DAG.getNode(ISD::ADDE, VTList, HiOps, 3); |
| 5708 | break; |
| 5709 | } |
| 5710 | } |
| 5711 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5712 | // If we can emit an efficient shift operation, do so now. |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 5713 | if (ExpandShift(ISD::SHL, Node->getOperand(0), ShiftAmt, Lo, Hi)) |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5714 | break; |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 5715 | |
| 5716 | // If this target supports SHL_PARTS, use it. |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 5717 | TargetLowering::LegalizeAction Action = |
| 5718 | TLI.getOperationAction(ISD::SHL_PARTS, NVT); |
| 5719 | if ((Action == TargetLowering::Legal && TLI.isTypeLegal(NVT)) || |
| 5720 | Action == TargetLowering::Custom) { |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 5721 | ExpandShiftParts(ISD::SHL_PARTS, Node->getOperand(0), ShiftAmt, Lo, Hi); |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 5722 | break; |
| 5723 | } |
| 5724 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5725 | // Otherwise, emit a libcall. |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5726 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::SHL_I64), Node, |
| 5727 | false/*left shift=unsigned*/, Hi); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5728 | break; |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 5729 | } |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5730 | |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 5731 | case ISD::SRA: { |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 5732 | // If the target wants custom lowering, do so. |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 5733 | SDOperand ShiftAmt = LegalizeOp(Node->getOperand(1)); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 5734 | if (TLI.getOperationAction(ISD::SRA, VT) == TargetLowering::Custom) { |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5735 | SDOperand Op = DAG.getNode(ISD::SRA, VT, Node->getOperand(0), ShiftAmt); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 5736 | Op = TLI.LowerOperation(Op, DAG); |
| 5737 | if (Op.Val) { |
| 5738 | // Now that the custom expander is done, expand the result, which is |
| 5739 | // still VT. |
| 5740 | ExpandOp(Op, Lo, Hi); |
| 5741 | break; |
| 5742 | } |
| 5743 | } |
| 5744 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5745 | // If we can emit an efficient shift operation, do so now. |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 5746 | if (ExpandShift(ISD::SRA, Node->getOperand(0), ShiftAmt, Lo, Hi)) |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5747 | break; |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 5748 | |
| 5749 | // If this target supports SRA_PARTS, use it. |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 5750 | TargetLowering::LegalizeAction Action = |
| 5751 | TLI.getOperationAction(ISD::SRA_PARTS, NVT); |
| 5752 | if ((Action == TargetLowering::Legal && TLI.isTypeLegal(NVT)) || |
| 5753 | Action == TargetLowering::Custom) { |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 5754 | ExpandShiftParts(ISD::SRA_PARTS, Node->getOperand(0), ShiftAmt, Lo, Hi); |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 5755 | break; |
| 5756 | } |
| 5757 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5758 | // Otherwise, emit a libcall. |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5759 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::SRA_I64), Node, |
| 5760 | true/*ashr is signed*/, Hi); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5761 | break; |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 5762 | } |
| 5763 | |
| 5764 | case ISD::SRL: { |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 5765 | // If the target wants custom lowering, do so. |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 5766 | SDOperand ShiftAmt = LegalizeOp(Node->getOperand(1)); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 5767 | if (TLI.getOperationAction(ISD::SRL, VT) == TargetLowering::Custom) { |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5768 | SDOperand Op = DAG.getNode(ISD::SRL, VT, Node->getOperand(0), ShiftAmt); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 5769 | Op = TLI.LowerOperation(Op, DAG); |
| 5770 | if (Op.Val) { |
| 5771 | // Now that the custom expander is done, expand the result, which is |
| 5772 | // still VT. |
| 5773 | ExpandOp(Op, Lo, Hi); |
| 5774 | break; |
| 5775 | } |
| 5776 | } |
| 5777 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5778 | // If we can emit an efficient shift operation, do so now. |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 5779 | if (ExpandShift(ISD::SRL, Node->getOperand(0), ShiftAmt, Lo, Hi)) |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5780 | break; |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 5781 | |
| 5782 | // If this target supports SRL_PARTS, use it. |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 5783 | TargetLowering::LegalizeAction Action = |
| 5784 | TLI.getOperationAction(ISD::SRL_PARTS, NVT); |
| 5785 | if ((Action == TargetLowering::Legal && TLI.isTypeLegal(NVT)) || |
| 5786 | Action == TargetLowering::Custom) { |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 5787 | ExpandShiftParts(ISD::SRL_PARTS, Node->getOperand(0), ShiftAmt, Lo, Hi); |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 5788 | break; |
| 5789 | } |
| 5790 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5791 | // Otherwise, emit a libcall. |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5792 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::SRL_I64), Node, |
| 5793 | false/*lshr is unsigned*/, Hi); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5794 | break; |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 5795 | } |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5796 | |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 5797 | case ISD::ADD: |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5798 | case ISD::SUB: { |
| 5799 | // If the target wants to custom expand this, let them. |
| 5800 | if (TLI.getOperationAction(Node->getOpcode(), VT) == |
| 5801 | TargetLowering::Custom) { |
| 5802 | Op = TLI.LowerOperation(Op, DAG); |
| 5803 | if (Op.Val) { |
| 5804 | ExpandOp(Op, Lo, Hi); |
| 5805 | break; |
| 5806 | } |
| 5807 | } |
| 5808 | |
| 5809 | // Expand the subcomponents. |
| 5810 | SDOperand LHSL, LHSH, RHSL, RHSH; |
| 5811 | ExpandOp(Node->getOperand(0), LHSL, LHSH); |
| 5812 | ExpandOp(Node->getOperand(1), RHSL, RHSH); |
Chris Lattner | 79980b0 | 2006-09-13 03:50:39 +0000 | [diff] [blame] | 5813 | SDVTList VTList = DAG.getVTList(LHSL.getValueType(), MVT::Flag); |
| 5814 | SDOperand LoOps[2], HiOps[3]; |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 5815 | LoOps[0] = LHSL; |
| 5816 | LoOps[1] = RHSL; |
| 5817 | HiOps[0] = LHSH; |
| 5818 | HiOps[1] = RHSH; |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 5819 | if (Node->getOpcode() == ISD::ADD) { |
Chris Lattner | 79980b0 | 2006-09-13 03:50:39 +0000 | [diff] [blame] | 5820 | Lo = DAG.getNode(ISD::ADDC, VTList, LoOps, 2); |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 5821 | HiOps[2] = Lo.getValue(1); |
Chris Lattner | 79980b0 | 2006-09-13 03:50:39 +0000 | [diff] [blame] | 5822 | Hi = DAG.getNode(ISD::ADDE, VTList, HiOps, 3); |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 5823 | } else { |
Chris Lattner | 79980b0 | 2006-09-13 03:50:39 +0000 | [diff] [blame] | 5824 | Lo = DAG.getNode(ISD::SUBC, VTList, LoOps, 2); |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 5825 | HiOps[2] = Lo.getValue(1); |
Chris Lattner | 79980b0 | 2006-09-13 03:50:39 +0000 | [diff] [blame] | 5826 | Hi = DAG.getNode(ISD::SUBE, VTList, HiOps, 3); |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 5827 | } |
Chris Lattner | 84f6788 | 2005-01-20 18:52:28 +0000 | [diff] [blame] | 5828 | break; |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5829 | } |
Chris Lattner | b429f73 | 2007-05-17 18:15:41 +0000 | [diff] [blame] | 5830 | |
| 5831 | case ISD::ADDC: |
| 5832 | case ISD::SUBC: { |
| 5833 | // Expand the subcomponents. |
| 5834 | SDOperand LHSL, LHSH, RHSL, RHSH; |
| 5835 | ExpandOp(Node->getOperand(0), LHSL, LHSH); |
| 5836 | ExpandOp(Node->getOperand(1), RHSL, RHSH); |
| 5837 | SDVTList VTList = DAG.getVTList(LHSL.getValueType(), MVT::Flag); |
| 5838 | SDOperand LoOps[2] = { LHSL, RHSL }; |
| 5839 | SDOperand HiOps[3] = { LHSH, RHSH }; |
| 5840 | |
| 5841 | if (Node->getOpcode() == ISD::ADDC) { |
| 5842 | Lo = DAG.getNode(ISD::ADDC, VTList, LoOps, 2); |
| 5843 | HiOps[2] = Lo.getValue(1); |
| 5844 | Hi = DAG.getNode(ISD::ADDE, VTList, HiOps, 3); |
| 5845 | } else { |
| 5846 | Lo = DAG.getNode(ISD::SUBC, VTList, LoOps, 2); |
| 5847 | HiOps[2] = Lo.getValue(1); |
| 5848 | Hi = DAG.getNode(ISD::SUBE, VTList, HiOps, 3); |
| 5849 | } |
| 5850 | // Remember that we legalized the flag. |
| 5851 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Hi.getValue(1))); |
| 5852 | break; |
| 5853 | } |
| 5854 | case ISD::ADDE: |
| 5855 | case ISD::SUBE: { |
| 5856 | // Expand the subcomponents. |
| 5857 | SDOperand LHSL, LHSH, RHSL, RHSH; |
| 5858 | ExpandOp(Node->getOperand(0), LHSL, LHSH); |
| 5859 | ExpandOp(Node->getOperand(1), RHSL, RHSH); |
| 5860 | SDVTList VTList = DAG.getVTList(LHSL.getValueType(), MVT::Flag); |
| 5861 | SDOperand LoOps[3] = { LHSL, RHSL, Node->getOperand(2) }; |
| 5862 | SDOperand HiOps[3] = { LHSH, RHSH }; |
| 5863 | |
| 5864 | Lo = DAG.getNode(Node->getOpcode(), VTList, LoOps, 3); |
| 5865 | HiOps[2] = Lo.getValue(1); |
| 5866 | Hi = DAG.getNode(Node->getOpcode(), VTList, HiOps, 3); |
| 5867 | |
| 5868 | // Remember that we legalized the flag. |
| 5869 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Hi.getValue(1))); |
| 5870 | break; |
| 5871 | } |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 5872 | case ISD::MUL: { |
Chris Lattner | 7d7bffe | 2006-09-16 00:09:24 +0000 | [diff] [blame] | 5873 | // If the target wants to custom expand this, let them. |
| 5874 | if (TLI.getOperationAction(ISD::MUL, VT) == TargetLowering::Custom) { |
Chris Lattner | 8829dc8 | 2006-09-16 05:08:34 +0000 | [diff] [blame] | 5875 | SDOperand New = TLI.LowerOperation(Op, DAG); |
| 5876 | if (New.Val) { |
| 5877 | ExpandOp(New, Lo, Hi); |
Chris Lattner | 7d7bffe | 2006-09-16 00:09:24 +0000 | [diff] [blame] | 5878 | break; |
| 5879 | } |
| 5880 | } |
| 5881 | |
Evan Cheng | 3f4fd0f | 2006-09-01 18:17:58 +0000 | [diff] [blame] | 5882 | bool HasMULHS = TLI.isOperationLegal(ISD::MULHS, NVT); |
| 5883 | bool HasMULHU = TLI.isOperationLegal(ISD::MULHU, NVT); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 5884 | bool HasSMUL_LOHI = TLI.isOperationLegal(ISD::SMUL_LOHI, NVT); |
| 5885 | bool HasUMUL_LOHI = TLI.isOperationLegal(ISD::UMUL_LOHI, NVT); |
| 5886 | if (HasMULHU || HasMULHS || HasUMUL_LOHI || HasSMUL_LOHI) { |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 5887 | SDOperand LL, LH, RL, RH; |
| 5888 | ExpandOp(Node->getOperand(0), LL, LH); |
| 5889 | ExpandOp(Node->getOperand(1), RL, RH); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 5890 | unsigned BitSize = MVT::getSizeInBits(RH.getValueType()); |
| 5891 | unsigned LHSSB = DAG.ComputeNumSignBits(Op.getOperand(0)); |
| 5892 | unsigned RHSSB = DAG.ComputeNumSignBits(Op.getOperand(1)); |
| 5893 | // FIXME: generalize this to handle other bit sizes |
| 5894 | if (LHSSB == 32 && RHSSB == 32 && |
| 5895 | DAG.MaskedValueIsZero(Op.getOperand(0), 0xFFFFFFFF00000000ULL) && |
| 5896 | DAG.MaskedValueIsZero(Op.getOperand(1), 0xFFFFFFFF00000000ULL)) { |
| 5897 | // The inputs are both zero-extended. |
| 5898 | if (HasUMUL_LOHI) { |
| 5899 | // We can emit a umul_lohi. |
| 5900 | Lo = DAG.getNode(ISD::UMUL_LOHI, DAG.getVTList(NVT, NVT), LL, RL); |
| 5901 | Hi = SDOperand(Lo.Val, 1); |
| 5902 | break; |
| 5903 | } |
| 5904 | if (HasMULHU) { |
| 5905 | // We can emit a mulhu+mul. |
| 5906 | Lo = DAG.getNode(ISD::MUL, NVT, LL, RL); |
| 5907 | Hi = DAG.getNode(ISD::MULHU, NVT, LL, RL); |
| 5908 | break; |
| 5909 | } |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 5910 | } |
| 5911 | if (LHSSB > BitSize && RHSSB > BitSize) { |
| 5912 | // The input values are both sign-extended. |
| 5913 | if (HasSMUL_LOHI) { |
| 5914 | // We can emit a smul_lohi. |
| 5915 | Lo = DAG.getNode(ISD::SMUL_LOHI, DAG.getVTList(NVT, NVT), LL, RL); |
| 5916 | Hi = SDOperand(Lo.Val, 1); |
| 5917 | break; |
| 5918 | } |
| 5919 | if (HasMULHS) { |
| 5920 | // We can emit a mulhs+mul. |
| 5921 | Lo = DAG.getNode(ISD::MUL, NVT, LL, RL); |
| 5922 | Hi = DAG.getNode(ISD::MULHS, NVT, LL, RL); |
| 5923 | break; |
| 5924 | } |
| 5925 | } |
| 5926 | if (HasUMUL_LOHI) { |
| 5927 | // Lo,Hi = umul LHS, RHS. |
| 5928 | SDOperand UMulLOHI = DAG.getNode(ISD::UMUL_LOHI, |
| 5929 | DAG.getVTList(NVT, NVT), LL, RL); |
| 5930 | Lo = UMulLOHI; |
| 5931 | Hi = UMulLOHI.getValue(1); |
Nate Begeman | 56eb868 | 2005-08-30 02:44:00 +0000 | [diff] [blame] | 5932 | RH = DAG.getNode(ISD::MUL, NVT, LL, RH); |
| 5933 | LH = DAG.getNode(ISD::MUL, NVT, LH, RL); |
| 5934 | Hi = DAG.getNode(ISD::ADD, NVT, Hi, RH); |
| 5935 | Hi = DAG.getNode(ISD::ADD, NVT, Hi, LH); |
Chris Lattner | a89654b | 2006-09-16 00:21:44 +0000 | [diff] [blame] | 5936 | break; |
Nate Begeman | 56eb868 | 2005-08-30 02:44:00 +0000 | [diff] [blame] | 5937 | } |
Dale Johannesen | 8eadd5a | 2007-10-24 22:26:08 +0000 | [diff] [blame] | 5938 | if (HasMULHU) { |
| 5939 | Lo = DAG.getNode(ISD::MUL, NVT, LL, RL); |
| 5940 | Hi = DAG.getNode(ISD::MULHU, NVT, LL, RL); |
| 5941 | RH = DAG.getNode(ISD::MUL, NVT, LL, RH); |
| 5942 | LH = DAG.getNode(ISD::MUL, NVT, LH, RL); |
| 5943 | Hi = DAG.getNode(ISD::ADD, NVT, Hi, RH); |
| 5944 | Hi = DAG.getNode(ISD::ADD, NVT, Hi, LH); |
| 5945 | break; |
| 5946 | } |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 5947 | } |
Evan Cheng | 3f4fd0f | 2006-09-01 18:17:58 +0000 | [diff] [blame] | 5948 | |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 5949 | // If nothing else, we can make a libcall. |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5950 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::MUL_I64), Node, |
| 5951 | false/*sign irrelevant*/, Hi); |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 5952 | break; |
| 5953 | } |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5954 | case ISD::SDIV: |
| 5955 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::SDIV_I64), Node, true, Hi); |
| 5956 | break; |
| 5957 | case ISD::UDIV: |
| 5958 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::UDIV_I64), Node, true, Hi); |
| 5959 | break; |
| 5960 | case ISD::SREM: |
| 5961 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::SREM_I64), Node, true, Hi); |
| 5962 | break; |
| 5963 | case ISD::UREM: |
| 5964 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::UREM_I64), Node, true, Hi); |
| 5965 | break; |
Evan Cheng | 5c9ce18 | 2006-12-12 21:51:17 +0000 | [diff] [blame] | 5966 | |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 5967 | case ISD::FADD: |
Dale Johannesen | 161e897 | 2007-10-05 20:04:43 +0000 | [diff] [blame] | 5968 | Lo = ExpandLibCall(TLI.getLibcallName(VT == MVT::f32 ? RTLIB::ADD_F32 : |
| 5969 | VT == MVT::f64 ? RTLIB::ADD_F64 : |
| 5970 | VT == MVT::ppcf128 ? |
| 5971 | RTLIB::ADD_PPCF128 : |
| 5972 | RTLIB::UNKNOWN_LIBCALL), |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5973 | Node, false, Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 5974 | break; |
| 5975 | case ISD::FSUB: |
Dale Johannesen | 161e897 | 2007-10-05 20:04:43 +0000 | [diff] [blame] | 5976 | Lo = ExpandLibCall(TLI.getLibcallName(VT == MVT::f32 ? RTLIB::SUB_F32 : |
| 5977 | VT == MVT::f64 ? RTLIB::SUB_F64 : |
| 5978 | VT == MVT::ppcf128 ? |
| 5979 | RTLIB::SUB_PPCF128 : |
| 5980 | RTLIB::UNKNOWN_LIBCALL), |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5981 | Node, false, Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 5982 | break; |
| 5983 | case ISD::FMUL: |
Dale Johannesen | 161e897 | 2007-10-05 20:04:43 +0000 | [diff] [blame] | 5984 | Lo = ExpandLibCall(TLI.getLibcallName(VT == MVT::f32 ? RTLIB::MUL_F32 : |
| 5985 | VT == MVT::f64 ? RTLIB::MUL_F64 : |
| 5986 | VT == MVT::ppcf128 ? |
| 5987 | RTLIB::MUL_PPCF128 : |
| 5988 | RTLIB::UNKNOWN_LIBCALL), |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5989 | Node, false, Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 5990 | break; |
| 5991 | case ISD::FDIV: |
Dale Johannesen | 161e897 | 2007-10-05 20:04:43 +0000 | [diff] [blame] | 5992 | Lo = ExpandLibCall(TLI.getLibcallName(VT == MVT::f32 ? RTLIB::DIV_F32 : |
| 5993 | VT == MVT::f64 ? RTLIB::DIV_F64 : |
| 5994 | VT == MVT::ppcf128 ? |
| 5995 | RTLIB::DIV_PPCF128 : |
| 5996 | RTLIB::UNKNOWN_LIBCALL), |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5997 | Node, false, Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 5998 | break; |
| 5999 | case ISD::FP_EXTEND: |
Dale Johannesen | ca68aaa | 2007-10-12 01:37:08 +0000 | [diff] [blame] | 6000 | if (VT == MVT::ppcf128) { |
| 6001 | assert(Node->getOperand(0).getValueType()==MVT::f32 || |
| 6002 | Node->getOperand(0).getValueType()==MVT::f64); |
| 6003 | const uint64_t zero = 0; |
| 6004 | if (Node->getOperand(0).getValueType()==MVT::f32) |
| 6005 | Hi = DAG.getNode(ISD::FP_EXTEND, MVT::f64, Node->getOperand(0)); |
| 6006 | else |
| 6007 | Hi = Node->getOperand(0); |
| 6008 | Lo = DAG.getConstantFP(APFloat(APInt(64, 1, &zero)), MVT::f64); |
| 6009 | break; |
| 6010 | } |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6011 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::FPEXT_F32_F64), Node, true,Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 6012 | break; |
| 6013 | case ISD::FP_ROUND: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6014 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::FPROUND_F64_F32),Node,true,Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 6015 | break; |
Lauro Ramos Venancio | c90f089 | 2007-08-15 22:13:27 +0000 | [diff] [blame] | 6016 | case ISD::FPOWI: |
Dale Johannesen | 317096a | 2007-09-28 01:08:20 +0000 | [diff] [blame] | 6017 | Lo = ExpandLibCall(TLI.getLibcallName((VT == MVT::f32) ? RTLIB::POWI_F32 : |
| 6018 | (VT == MVT::f64) ? RTLIB::POWI_F64 : |
Dale Johannesen | 161e897 | 2007-10-05 20:04:43 +0000 | [diff] [blame] | 6019 | (VT == MVT::f80) ? RTLIB::POWI_F80 : |
| 6020 | (VT == MVT::ppcf128) ? |
| 6021 | RTLIB::POWI_PPCF128 : |
| 6022 | RTLIB::UNKNOWN_LIBCALL), |
Lauro Ramos Venancio | c90f089 | 2007-08-15 22:13:27 +0000 | [diff] [blame] | 6023 | Node, false, Hi); |
| 6024 | break; |
Evan Cheng | 98ff3b9 | 2006-12-13 02:38:13 +0000 | [diff] [blame] | 6025 | case ISD::FSQRT: |
| 6026 | case ISD::FSIN: |
| 6027 | case ISD::FCOS: { |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6028 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
Evan Cheng | 98ff3b9 | 2006-12-13 02:38:13 +0000 | [diff] [blame] | 6029 | switch(Node->getOpcode()) { |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6030 | case ISD::FSQRT: |
Dale Johannesen | 317096a | 2007-09-28 01:08:20 +0000 | [diff] [blame] | 6031 | LC = (VT == MVT::f32) ? RTLIB::SQRT_F32 : |
Dale Johannesen | 161e897 | 2007-10-05 20:04:43 +0000 | [diff] [blame] | 6032 | (VT == MVT::f64) ? RTLIB::SQRT_F64 : |
| 6033 | (VT == MVT::f80) ? RTLIB::SQRT_F80 : |
| 6034 | (VT == MVT::ppcf128) ? RTLIB::SQRT_PPCF128 : |
| 6035 | RTLIB::UNKNOWN_LIBCALL; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6036 | break; |
| 6037 | case ISD::FSIN: |
| 6038 | LC = (VT == MVT::f32) ? RTLIB::SIN_F32 : RTLIB::SIN_F64; |
| 6039 | break; |
| 6040 | case ISD::FCOS: |
| 6041 | LC = (VT == MVT::f32) ? RTLIB::COS_F32 : RTLIB::COS_F64; |
| 6042 | break; |
Evan Cheng | 98ff3b9 | 2006-12-13 02:38:13 +0000 | [diff] [blame] | 6043 | default: assert(0 && "Unreachable!"); |
| 6044 | } |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6045 | Lo = ExpandLibCall(TLI.getLibcallName(LC), Node, false, Hi); |
Evan Cheng | 98ff3b9 | 2006-12-13 02:38:13 +0000 | [diff] [blame] | 6046 | break; |
| 6047 | } |
Evan Cheng | 966bf24 | 2006-12-16 00:52:40 +0000 | [diff] [blame] | 6048 | case ISD::FABS: { |
Dale Johannesen | f646774 | 2007-10-12 19:02:17 +0000 | [diff] [blame] | 6049 | if (VT == MVT::ppcf128) { |
| 6050 | SDOperand Tmp; |
| 6051 | ExpandOp(Node->getOperand(0), Lo, Tmp); |
| 6052 | Hi = DAG.getNode(ISD::FABS, NVT, Tmp); |
| 6053 | // lo = hi==fabs(hi) ? lo : -lo; |
| 6054 | Lo = DAG.getNode(ISD::SELECT_CC, NVT, Hi, Tmp, |
| 6055 | Lo, DAG.getNode(ISD::FNEG, NVT, Lo), |
| 6056 | DAG.getCondCode(ISD::SETEQ)); |
| 6057 | break; |
| 6058 | } |
Evan Cheng | 966bf24 | 2006-12-16 00:52:40 +0000 | [diff] [blame] | 6059 | SDOperand Mask = (VT == MVT::f64) |
| 6060 | ? DAG.getConstantFP(BitsToDouble(~(1ULL << 63)), VT) |
| 6061 | : DAG.getConstantFP(BitsToFloat(~(1U << 31)), VT); |
| 6062 | Mask = DAG.getNode(ISD::BIT_CONVERT, NVT, Mask); |
| 6063 | Lo = DAG.getNode(ISD::BIT_CONVERT, NVT, Node->getOperand(0)); |
| 6064 | Lo = DAG.getNode(ISD::AND, NVT, Lo, Mask); |
| 6065 | if (getTypeAction(NVT) == Expand) |
| 6066 | ExpandOp(Lo, Lo, Hi); |
| 6067 | break; |
| 6068 | } |
| 6069 | case ISD::FNEG: { |
Dale Johannesen | f646774 | 2007-10-12 19:02:17 +0000 | [diff] [blame] | 6070 | if (VT == MVT::ppcf128) { |
| 6071 | ExpandOp(Node->getOperand(0), Lo, Hi); |
| 6072 | Lo = DAG.getNode(ISD::FNEG, MVT::f64, Lo); |
| 6073 | Hi = DAG.getNode(ISD::FNEG, MVT::f64, Hi); |
| 6074 | break; |
| 6075 | } |
Evan Cheng | 966bf24 | 2006-12-16 00:52:40 +0000 | [diff] [blame] | 6076 | SDOperand Mask = (VT == MVT::f64) |
| 6077 | ? DAG.getConstantFP(BitsToDouble(1ULL << 63), VT) |
| 6078 | : DAG.getConstantFP(BitsToFloat(1U << 31), VT); |
| 6079 | Mask = DAG.getNode(ISD::BIT_CONVERT, NVT, Mask); |
| 6080 | Lo = DAG.getNode(ISD::BIT_CONVERT, NVT, Node->getOperand(0)); |
| 6081 | Lo = DAG.getNode(ISD::XOR, NVT, Lo, Mask); |
| 6082 | if (getTypeAction(NVT) == Expand) |
| 6083 | ExpandOp(Lo, Lo, Hi); |
| 6084 | break; |
| 6085 | } |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 6086 | case ISD::FCOPYSIGN: { |
| 6087 | Lo = ExpandFCOPYSIGNToBitwiseOps(Node, NVT, DAG, TLI); |
| 6088 | if (getTypeAction(NVT) == Expand) |
| 6089 | ExpandOp(Lo, Lo, Hi); |
| 6090 | break; |
| 6091 | } |
Evan Cheng | 7df28dc | 2006-12-19 01:44:04 +0000 | [diff] [blame] | 6092 | case ISD::SINT_TO_FP: |
| 6093 | case ISD::UINT_TO_FP: { |
| 6094 | bool isSigned = Node->getOpcode() == ISD::SINT_TO_FP; |
| 6095 | MVT::ValueType SrcVT = Node->getOperand(0).getValueType(); |
Dale Johannesen | 6e63e09 | 2007-10-12 17:52:03 +0000 | [diff] [blame] | 6096 | if (VT == MVT::ppcf128 && SrcVT != MVT::i64) { |
Dale Johannesen | ca68aaa | 2007-10-12 01:37:08 +0000 | [diff] [blame] | 6097 | static uint64_t zero = 0; |
| 6098 | if (isSigned) { |
| 6099 | Hi = LegalizeOp(DAG.getNode(ISD::SINT_TO_FP, MVT::f64, |
| 6100 | Node->getOperand(0))); |
| 6101 | Lo = DAG.getConstantFP(APFloat(APInt(64, 1, &zero)), MVT::f64); |
| 6102 | } else { |
| 6103 | static uint64_t TwoE32[] = { 0x41f0000000000000LL, 0 }; |
| 6104 | Hi = LegalizeOp(DAG.getNode(ISD::SINT_TO_FP, MVT::f64, |
| 6105 | Node->getOperand(0))); |
| 6106 | Lo = DAG.getConstantFP(APFloat(APInt(64, 1, &zero)), MVT::f64); |
| 6107 | Hi = DAG.getNode(ISD::BUILD_PAIR, VT, Lo, Hi); |
Dale Johannesen | 6e63e09 | 2007-10-12 17:52:03 +0000 | [diff] [blame] | 6108 | // X>=0 ? {(f64)x, 0} : {(f64)x, 0} + 2^32 |
Dale Johannesen | ca68aaa | 2007-10-12 01:37:08 +0000 | [diff] [blame] | 6109 | ExpandOp(DAG.getNode(ISD::SELECT_CC, MVT::ppcf128, Node->getOperand(0), |
| 6110 | DAG.getConstant(0, MVT::i32), |
| 6111 | DAG.getNode(ISD::FADD, MVT::ppcf128, Hi, |
| 6112 | DAG.getConstantFP( |
| 6113 | APFloat(APInt(128, 2, TwoE32)), |
| 6114 | MVT::ppcf128)), |
| 6115 | Hi, |
| 6116 | DAG.getCondCode(ISD::SETLT)), |
| 6117 | Lo, Hi); |
| 6118 | } |
| 6119 | break; |
| 6120 | } |
Dale Johannesen | 6e63e09 | 2007-10-12 17:52:03 +0000 | [diff] [blame] | 6121 | if (VT == MVT::ppcf128 && SrcVT == MVT::i64 && !isSigned) { |
| 6122 | // si64->ppcf128 done by libcall, below |
| 6123 | static uint64_t TwoE64[] = { 0x43f0000000000000LL, 0 }; |
| 6124 | ExpandOp(DAG.getNode(ISD::SINT_TO_FP, MVT::ppcf128, Node->getOperand(0)), |
| 6125 | Lo, Hi); |
| 6126 | Hi = DAG.getNode(ISD::BUILD_PAIR, VT, Lo, Hi); |
| 6127 | // x>=0 ? (ppcf128)(i64)x : (ppcf128)(i64)x + 2^64 |
| 6128 | ExpandOp(DAG.getNode(ISD::SELECT_CC, MVT::ppcf128, Node->getOperand(0), |
| 6129 | DAG.getConstant(0, MVT::i64), |
| 6130 | DAG.getNode(ISD::FADD, MVT::ppcf128, Hi, |
| 6131 | DAG.getConstantFP( |
| 6132 | APFloat(APInt(128, 2, TwoE64)), |
| 6133 | MVT::ppcf128)), |
| 6134 | Hi, |
| 6135 | DAG.getCondCode(ISD::SETLT)), |
| 6136 | Lo, Hi); |
| 6137 | break; |
| 6138 | } |
Evan Cheng | 64f638d | 2007-09-27 07:35:39 +0000 | [diff] [blame] | 6139 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
Evan Cheng | 7df28dc | 2006-12-19 01:44:04 +0000 | [diff] [blame] | 6140 | if (Node->getOperand(0).getValueType() == MVT::i64) { |
| 6141 | if (VT == MVT::f32) |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6142 | LC = isSigned ? RTLIB::SINTTOFP_I64_F32 : RTLIB::UINTTOFP_I64_F32; |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 6143 | else if (VT == MVT::f64) |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6144 | LC = isSigned ? RTLIB::SINTTOFP_I64_F64 : RTLIB::UINTTOFP_I64_F64; |
Dale Johannesen | 161e897 | 2007-10-05 20:04:43 +0000 | [diff] [blame] | 6145 | else if (VT == MVT::f80) { |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 6146 | assert(isSigned); |
Dale Johannesen | 161e897 | 2007-10-05 20:04:43 +0000 | [diff] [blame] | 6147 | LC = RTLIB::SINTTOFP_I64_F80; |
| 6148 | } |
| 6149 | else if (VT == MVT::ppcf128) { |
| 6150 | assert(isSigned); |
| 6151 | LC = RTLIB::SINTTOFP_I64_PPCF128; |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 6152 | } |
Evan Cheng | 7df28dc | 2006-12-19 01:44:04 +0000 | [diff] [blame] | 6153 | } else { |
| 6154 | if (VT == MVT::f32) |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6155 | LC = isSigned ? RTLIB::SINTTOFP_I32_F32 : RTLIB::UINTTOFP_I32_F32; |
Evan Cheng | 7df28dc | 2006-12-19 01:44:04 +0000 | [diff] [blame] | 6156 | else |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6157 | LC = isSigned ? RTLIB::SINTTOFP_I32_F64 : RTLIB::UINTTOFP_I32_F64; |
Evan Cheng | 7df28dc | 2006-12-19 01:44:04 +0000 | [diff] [blame] | 6158 | } |
| 6159 | |
| 6160 | // Promote the operand if needed. |
| 6161 | if (getTypeAction(SrcVT) == Promote) { |
| 6162 | SDOperand Tmp = PromoteOp(Node->getOperand(0)); |
| 6163 | Tmp = isSigned |
| 6164 | ? DAG.getNode(ISD::SIGN_EXTEND_INREG, Tmp.getValueType(), Tmp, |
| 6165 | DAG.getValueType(SrcVT)) |
| 6166 | : DAG.getZeroExtendInReg(Tmp, SrcVT); |
| 6167 | Node = DAG.UpdateNodeOperands(Op, Tmp).Val; |
| 6168 | } |
Evan Cheng | 4c6cfad | 2007-04-27 07:33:31 +0000 | [diff] [blame] | 6169 | |
| 6170 | const char *LibCall = TLI.getLibcallName(LC); |
| 6171 | if (LibCall) |
| 6172 | Lo = ExpandLibCall(TLI.getLibcallName(LC), Node, isSigned, Hi); |
| 6173 | else { |
| 6174 | Lo = ExpandIntToFP(Node->getOpcode() == ISD::SINT_TO_FP, VT, |
| 6175 | Node->getOperand(0)); |
| 6176 | if (getTypeAction(Lo.getValueType()) == Expand) |
| 6177 | ExpandOp(Lo, Lo, Hi); |
| 6178 | } |
Evan Cheng | 7df28dc | 2006-12-19 01:44:04 +0000 | [diff] [blame] | 6179 | break; |
| 6180 | } |
Evan Cheng | 98ff3b9 | 2006-12-13 02:38:13 +0000 | [diff] [blame] | 6181 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6182 | |
Chris Lattner | 8339736 | 2005-12-21 18:02:52 +0000 | [diff] [blame] | 6183 | // Make sure the resultant values have been legalized themselves, unless this |
| 6184 | // is a type that requires multi-step expansion. |
| 6185 | if (getTypeAction(NVT) != Expand && NVT != MVT::isVoid) { |
| 6186 | Lo = LegalizeOp(Lo); |
Evan Cheng | 13acce3 | 2006-12-11 19:27:14 +0000 | [diff] [blame] | 6187 | if (Hi.Val) |
| 6188 | // Don't legalize the high part if it is expanded to a single node. |
| 6189 | Hi = LegalizeOp(Hi); |
Chris Lattner | 8339736 | 2005-12-21 18:02:52 +0000 | [diff] [blame] | 6190 | } |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 6191 | |
| 6192 | // Remember in a map if the values will be reused later. |
Chris Lattner | 40030bf | 2007-02-04 01:17:38 +0000 | [diff] [blame] | 6193 | 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] | 6194 | assert(isNew && "Value already expanded?!?"); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6195 | } |
| 6196 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6197 | /// SplitVectorOp - Given an operand of vector type, break it down into |
| 6198 | /// two smaller values, still of vector type. |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6199 | void SelectionDAGLegalize::SplitVectorOp(SDOperand Op, SDOperand &Lo, |
| 6200 | SDOperand &Hi) { |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6201 | assert(MVT::isVector(Op.getValueType()) && "Cannot split non-vector type!"); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6202 | SDNode *Node = Op.Val; |
Dan Gohman | e40c7b0 | 2007-09-24 15:54:53 +0000 | [diff] [blame] | 6203 | unsigned NumElements = MVT::getVectorNumElements(Op.getValueType()); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6204 | assert(NumElements > 1 && "Cannot split a single element vector!"); |
| 6205 | unsigned NewNumElts = NumElements/2; |
Dan Gohman | e40c7b0 | 2007-09-24 15:54:53 +0000 | [diff] [blame] | 6206 | MVT::ValueType NewEltVT = MVT::getVectorElementType(Op.getValueType()); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6207 | MVT::ValueType NewVT = MVT::getVectorType(NewEltVT, NewNumElts); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6208 | |
| 6209 | // See if we already split it. |
| 6210 | std::map<SDOperand, std::pair<SDOperand, SDOperand> >::iterator I |
| 6211 | = SplitNodes.find(Op); |
| 6212 | if (I != SplitNodes.end()) { |
| 6213 | Lo = I->second.first; |
| 6214 | Hi = I->second.second; |
| 6215 | return; |
| 6216 | } |
| 6217 | |
| 6218 | switch (Node->getOpcode()) { |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 6219 | default: |
| 6220 | #ifndef NDEBUG |
Dan Gohman | 3983358 | 2007-06-04 16:17:33 +0000 | [diff] [blame] | 6221 | Node->dump(&DAG); |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 6222 | #endif |
| 6223 | assert(0 && "Unhandled operation in SplitVectorOp!"); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6224 | case ISD::BUILD_PAIR: |
| 6225 | Lo = Node->getOperand(0); |
| 6226 | Hi = Node->getOperand(1); |
| 6227 | break; |
Dan Gohman | 9fe4662 | 2007-09-28 23:53:40 +0000 | [diff] [blame] | 6228 | case ISD::INSERT_VECTOR_ELT: { |
| 6229 | SplitVectorOp(Node->getOperand(0), Lo, Hi); |
| 6230 | unsigned Index = cast<ConstantSDNode>(Node->getOperand(2))->getValue(); |
| 6231 | SDOperand ScalarOp = Node->getOperand(1); |
| 6232 | if (Index < NewNumElts) |
| 6233 | Lo = DAG.getNode(ISD::INSERT_VECTOR_ELT, NewVT, Lo, ScalarOp, |
| 6234 | DAG.getConstant(Index, TLI.getPointerTy())); |
| 6235 | else |
| 6236 | Hi = DAG.getNode(ISD::INSERT_VECTOR_ELT, NewVT, Hi, ScalarOp, |
| 6237 | DAG.getConstant(Index - NewNumElts, TLI.getPointerTy())); |
| 6238 | break; |
| 6239 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6240 | case ISD::BUILD_VECTOR: { |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 6241 | SmallVector<SDOperand, 8> LoOps(Node->op_begin(), |
| 6242 | Node->op_begin()+NewNumElts); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6243 | Lo = DAG.getNode(ISD::BUILD_VECTOR, NewVT, &LoOps[0], LoOps.size()); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6244 | |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 6245 | SmallVector<SDOperand, 8> HiOps(Node->op_begin()+NewNumElts, |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6246 | Node->op_end()); |
| 6247 | Hi = DAG.getNode(ISD::BUILD_VECTOR, NewVT, &HiOps[0], HiOps.size()); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6248 | break; |
| 6249 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6250 | case ISD::CONCAT_VECTORS: { |
| 6251 | unsigned NewNumSubvectors = Node->getNumOperands() / 2; |
| 6252 | if (NewNumSubvectors == 1) { |
| 6253 | Lo = Node->getOperand(0); |
| 6254 | Hi = Node->getOperand(1); |
| 6255 | } else { |
| 6256 | SmallVector<SDOperand, 8> LoOps(Node->op_begin(), |
| 6257 | Node->op_begin()+NewNumSubvectors); |
| 6258 | Lo = DAG.getNode(ISD::CONCAT_VECTORS, NewVT, &LoOps[0], LoOps.size()); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 6259 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6260 | SmallVector<SDOperand, 8> HiOps(Node->op_begin()+NewNumSubvectors, |
| 6261 | Node->op_end()); |
| 6262 | Hi = DAG.getNode(ISD::CONCAT_VECTORS, NewVT, &HiOps[0], HiOps.size()); |
| 6263 | } |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 6264 | break; |
| 6265 | } |
Dan Gohman | c623096 | 2007-10-17 14:48:28 +0000 | [diff] [blame] | 6266 | case ISD::SELECT: { |
| 6267 | SDOperand Cond = Node->getOperand(0); |
| 6268 | |
| 6269 | SDOperand LL, LH, RL, RH; |
| 6270 | SplitVectorOp(Node->getOperand(1), LL, LH); |
| 6271 | SplitVectorOp(Node->getOperand(2), RL, RH); |
| 6272 | |
| 6273 | if (MVT::isVector(Cond.getValueType())) { |
| 6274 | // Handle a vector merge. |
| 6275 | SDOperand CL, CH; |
| 6276 | SplitVectorOp(Cond, CL, CH); |
| 6277 | Lo = DAG.getNode(Node->getOpcode(), NewVT, CL, LL, RL); |
| 6278 | Hi = DAG.getNode(Node->getOpcode(), NewVT, CH, LH, RH); |
| 6279 | } else { |
| 6280 | // Handle a simple select with vector operands. |
| 6281 | Lo = DAG.getNode(Node->getOpcode(), NewVT, Cond, LL, RL); |
| 6282 | Hi = DAG.getNode(Node->getOpcode(), NewVT, Cond, LH, RH); |
| 6283 | } |
| 6284 | break; |
| 6285 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6286 | case ISD::ADD: |
| 6287 | case ISD::SUB: |
| 6288 | case ISD::MUL: |
| 6289 | case ISD::FADD: |
| 6290 | case ISD::FSUB: |
| 6291 | case ISD::FMUL: |
| 6292 | case ISD::SDIV: |
| 6293 | case ISD::UDIV: |
| 6294 | case ISD::FDIV: |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 6295 | case ISD::FPOW: |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6296 | case ISD::AND: |
| 6297 | case ISD::OR: |
| 6298 | case ISD::XOR: { |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6299 | SDOperand LL, LH, RL, RH; |
| 6300 | SplitVectorOp(Node->getOperand(0), LL, LH); |
| 6301 | SplitVectorOp(Node->getOperand(1), RL, RH); |
| 6302 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6303 | Lo = DAG.getNode(Node->getOpcode(), NewVT, LL, RL); |
| 6304 | Hi = DAG.getNode(Node->getOpcode(), NewVT, LH, RH); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6305 | break; |
| 6306 | } |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 6307 | case ISD::FPOWI: { |
| 6308 | SDOperand L, H; |
| 6309 | SplitVectorOp(Node->getOperand(0), L, H); |
| 6310 | |
| 6311 | Lo = DAG.getNode(Node->getOpcode(), NewVT, L, Node->getOperand(1)); |
| 6312 | Hi = DAG.getNode(Node->getOpcode(), NewVT, H, Node->getOperand(1)); |
| 6313 | break; |
| 6314 | } |
| 6315 | case ISD::CTTZ: |
| 6316 | case ISD::CTLZ: |
| 6317 | case ISD::CTPOP: |
| 6318 | case ISD::FNEG: |
| 6319 | case ISD::FABS: |
| 6320 | case ISD::FSQRT: |
| 6321 | case ISD::FSIN: |
| 6322 | case ISD::FCOS: { |
| 6323 | SDOperand L, H; |
| 6324 | SplitVectorOp(Node->getOperand(0), L, H); |
| 6325 | |
| 6326 | Lo = DAG.getNode(Node->getOpcode(), NewVT, L); |
| 6327 | Hi = DAG.getNode(Node->getOpcode(), NewVT, H); |
| 6328 | break; |
| 6329 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6330 | case ISD::LOAD: { |
| 6331 | LoadSDNode *LD = cast<LoadSDNode>(Node); |
| 6332 | SDOperand Ch = LD->getChain(); |
| 6333 | SDOperand Ptr = LD->getBasePtr(); |
| 6334 | const Value *SV = LD->getSrcValue(); |
| 6335 | int SVOffset = LD->getSrcValueOffset(); |
| 6336 | unsigned Alignment = LD->getAlignment(); |
| 6337 | bool isVolatile = LD->isVolatile(); |
| 6338 | |
| 6339 | Lo = DAG.getLoad(NewVT, Ch, Ptr, SV, SVOffset, isVolatile, Alignment); |
| 6340 | unsigned IncrementSize = NewNumElts * MVT::getSizeInBits(NewEltVT)/8; |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6341 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
| 6342 | getIntPtrConstant(IncrementSize)); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6343 | SVOffset += IncrementSize; |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 6344 | Alignment = MinAlign(Alignment, IncrementSize); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6345 | Hi = DAG.getLoad(NewVT, Ch, Ptr, SV, SVOffset, isVolatile, Alignment); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6346 | |
| 6347 | // Build a factor node to remember that this load is independent of the |
| 6348 | // other one. |
| 6349 | SDOperand TF = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1), |
| 6350 | Hi.getValue(1)); |
| 6351 | |
| 6352 | // Remember that we legalized the chain. |
| 6353 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(TF)); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6354 | break; |
| 6355 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6356 | case ISD::BIT_CONVERT: { |
Chris Lattner | 7692eb4 | 2006-03-23 21:16:34 +0000 | [diff] [blame] | 6357 | // We know the result is a vector. The input may be either a vector or a |
| 6358 | // scalar value. |
Dan Gohman | 10a7aa6 | 2007-06-29 00:09:08 +0000 | [diff] [blame] | 6359 | SDOperand InOp = Node->getOperand(0); |
| 6360 | if (!MVT::isVector(InOp.getValueType()) || |
| 6361 | MVT::getVectorNumElements(InOp.getValueType()) == 1) { |
| 6362 | // The input is a scalar or single-element vector. |
| 6363 | // Lower to a store/load so that it can be split. |
| 6364 | // FIXME: this could be improved probably. |
Chris Lattner | 85dd3be | 2007-10-15 17:48:57 +0000 | [diff] [blame] | 6365 | SDOperand Ptr = DAG.CreateStackTemporary(InOp.getValueType()); |
Chris Lattner | 7692eb4 | 2006-03-23 21:16:34 +0000 | [diff] [blame] | 6366 | |
Evan Cheng | 786225a | 2006-10-05 23:01:46 +0000 | [diff] [blame] | 6367 | SDOperand St = DAG.getStore(DAG.getEntryNode(), |
Dan Gohman | 10a7aa6 | 2007-06-29 00:09:08 +0000 | [diff] [blame] | 6368 | InOp, Ptr, NULL, 0); |
| 6369 | InOp = DAG.getLoad(Op.getValueType(), St, Ptr, NULL, 0); |
Chris Lattner | 7692eb4 | 2006-03-23 21:16:34 +0000 | [diff] [blame] | 6370 | } |
Dan Gohman | 10a7aa6 | 2007-06-29 00:09:08 +0000 | [diff] [blame] | 6371 | // Split the vector and convert each of the pieces now. |
| 6372 | SplitVectorOp(InOp, Lo, Hi); |
| 6373 | Lo = DAG.getNode(ISD::BIT_CONVERT, NewVT, Lo); |
| 6374 | Hi = DAG.getNode(ISD::BIT_CONVERT, NewVT, Hi); |
| 6375 | break; |
Chris Lattner | 7692eb4 | 2006-03-23 21:16:34 +0000 | [diff] [blame] | 6376 | } |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6377 | } |
| 6378 | |
| 6379 | // Remember in a map if the values will be reused later. |
Chris Lattner | 40030bf | 2007-02-04 01:17:38 +0000 | [diff] [blame] | 6380 | bool isNew = |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6381 | SplitNodes.insert(std::make_pair(Op, std::make_pair(Lo, Hi))).second; |
Dan Gohman | 10a7aa6 | 2007-06-29 00:09:08 +0000 | [diff] [blame] | 6382 | assert(isNew && "Value already split?!?"); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6383 | } |
| 6384 | |
| 6385 | |
Dan Gohman | 89b20c0 | 2007-06-27 14:06:22 +0000 | [diff] [blame] | 6386 | /// ScalarizeVectorOp - Given an operand of single-element vector type |
| 6387 | /// (e.g. v1f32), convert it into the equivalent operation that returns a |
| 6388 | /// scalar (e.g. f32) value. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6389 | SDOperand SelectionDAGLegalize::ScalarizeVectorOp(SDOperand Op) { |
| 6390 | assert(MVT::isVector(Op.getValueType()) && |
| 6391 | "Bad ScalarizeVectorOp invocation!"); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6392 | SDNode *Node = Op.Val; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6393 | MVT::ValueType NewVT = MVT::getVectorElementType(Op.getValueType()); |
| 6394 | assert(MVT::getVectorNumElements(Op.getValueType()) == 1); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6395 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6396 | // See if we already scalarized it. |
| 6397 | std::map<SDOperand, SDOperand>::iterator I = ScalarizedNodes.find(Op); |
| 6398 | if (I != ScalarizedNodes.end()) return I->second; |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6399 | |
| 6400 | SDOperand Result; |
| 6401 | switch (Node->getOpcode()) { |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 6402 | default: |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 6403 | #ifndef NDEBUG |
Dan Gohman | 3983358 | 2007-06-04 16:17:33 +0000 | [diff] [blame] | 6404 | Node->dump(&DAG); cerr << "\n"; |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 6405 | #endif |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6406 | assert(0 && "Unknown vector operation in ScalarizeVectorOp!"); |
| 6407 | case ISD::ADD: |
| 6408 | case ISD::FADD: |
| 6409 | case ISD::SUB: |
| 6410 | case ISD::FSUB: |
| 6411 | case ISD::MUL: |
| 6412 | case ISD::FMUL: |
| 6413 | case ISD::SDIV: |
| 6414 | case ISD::UDIV: |
| 6415 | case ISD::FDIV: |
| 6416 | case ISD::SREM: |
| 6417 | case ISD::UREM: |
| 6418 | case ISD::FREM: |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 6419 | case ISD::FPOW: |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6420 | case ISD::AND: |
| 6421 | case ISD::OR: |
| 6422 | case ISD::XOR: |
| 6423 | Result = DAG.getNode(Node->getOpcode(), |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6424 | NewVT, |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6425 | ScalarizeVectorOp(Node->getOperand(0)), |
| 6426 | ScalarizeVectorOp(Node->getOperand(1))); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6427 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6428 | case ISD::FNEG: |
| 6429 | case ISD::FABS: |
| 6430 | case ISD::FSQRT: |
| 6431 | case ISD::FSIN: |
| 6432 | case ISD::FCOS: |
| 6433 | Result = DAG.getNode(Node->getOpcode(), |
| 6434 | NewVT, |
| 6435 | ScalarizeVectorOp(Node->getOperand(0))); |
| 6436 | break; |
Dan Gohman | 9e04c82 | 2007-10-12 14:13:46 +0000 | [diff] [blame] | 6437 | case ISD::FPOWI: |
| 6438 | Result = DAG.getNode(Node->getOpcode(), |
| 6439 | NewVT, |
| 6440 | ScalarizeVectorOp(Node->getOperand(0)), |
| 6441 | Node->getOperand(1)); |
| 6442 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6443 | case ISD::LOAD: { |
| 6444 | LoadSDNode *LD = cast<LoadSDNode>(Node); |
| 6445 | SDOperand Ch = LegalizeOp(LD->getChain()); // Legalize the chain. |
| 6446 | SDOperand Ptr = LegalizeOp(LD->getBasePtr()); // Legalize the pointer. |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6447 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6448 | const Value *SV = LD->getSrcValue(); |
| 6449 | int SVOffset = LD->getSrcValueOffset(); |
| 6450 | Result = DAG.getLoad(NewVT, Ch, Ptr, SV, SVOffset, |
| 6451 | LD->isVolatile(), LD->getAlignment()); |
| 6452 | |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6453 | // Remember that we legalized the chain. |
| 6454 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1))); |
| 6455 | break; |
| 6456 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6457 | case ISD::BUILD_VECTOR: |
| 6458 | Result = Node->getOperand(0); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6459 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6460 | case ISD::INSERT_VECTOR_ELT: |
| 6461 | // Returning the inserted scalar element. |
| 6462 | Result = Node->getOperand(1); |
| 6463 | break; |
| 6464 | case ISD::CONCAT_VECTORS: |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 6465 | assert(Node->getOperand(0).getValueType() == NewVT && |
| 6466 | "Concat of non-legal vectors not yet supported!"); |
| 6467 | Result = Node->getOperand(0); |
| 6468 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6469 | case ISD::VECTOR_SHUFFLE: { |
| 6470 | // Figure out if the scalar is the LHS or RHS and return it. |
| 6471 | SDOperand EltNum = Node->getOperand(2).getOperand(0); |
| 6472 | if (cast<ConstantSDNode>(EltNum)->getValue()) |
| 6473 | Result = ScalarizeVectorOp(Node->getOperand(1)); |
| 6474 | else |
| 6475 | Result = ScalarizeVectorOp(Node->getOperand(0)); |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 6476 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6477 | } |
| 6478 | case ISD::EXTRACT_SUBVECTOR: |
| 6479 | Result = Node->getOperand(0); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 6480 | assert(Result.getValueType() == NewVT); |
| 6481 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6482 | case ISD::BIT_CONVERT: |
| 6483 | Result = DAG.getNode(ISD::BIT_CONVERT, NewVT, Op.getOperand(0)); |
Chris Lattner | 5b2316e | 2006-03-28 20:24:43 +0000 | [diff] [blame] | 6484 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6485 | case ISD::SELECT: |
Chris Lattner | b22e35a | 2006-04-08 22:22:57 +0000 | [diff] [blame] | 6486 | Result = DAG.getNode(ISD::SELECT, NewVT, Op.getOperand(0), |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6487 | ScalarizeVectorOp(Op.getOperand(1)), |
| 6488 | ScalarizeVectorOp(Op.getOperand(2))); |
Chris Lattner | b22e35a | 2006-04-08 22:22:57 +0000 | [diff] [blame] | 6489 | break; |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6490 | } |
| 6491 | |
| 6492 | if (TLI.isTypeLegal(NewVT)) |
| 6493 | Result = LegalizeOp(Result); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6494 | bool isNew = ScalarizedNodes.insert(std::make_pair(Op, Result)).second; |
| 6495 | assert(isNew && "Value already scalarized?"); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6496 | return Result; |
| 6497 | } |
| 6498 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6499 | |
| 6500 | // SelectionDAG::Legalize - This is the entry point for the file. |
| 6501 | // |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 6502 | void SelectionDAG::Legalize() { |
Chris Lattner | 5e46a19 | 2006-04-02 03:07:27 +0000 | [diff] [blame] | 6503 | if (ViewLegalizeDAGs) viewGraph(); |
| 6504 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6505 | /// run - This is the main entry point to this class. |
| 6506 | /// |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 6507 | SelectionDAGLegalize(*this).LegalizeDAG(); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6508 | } |
| 6509 | |