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 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
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" |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/MachineModuleInfo.h" |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/PseudoSourceValue.h" |
Evan Cheng | 61bbbab | 2007-08-16 23:50:06 +0000 | [diff] [blame] | 20 | #include "llvm/Target/TargetFrameInfo.h" |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 21 | #include "llvm/Target/TargetLowering.h" |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 22 | #include "llvm/Target/TargetData.h" |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 23 | #include "llvm/Target/TargetMachine.h" |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 24 | #include "llvm/Target/TargetOptions.h" |
Chris Lattner | adf6a96 | 2005-05-13 18:50:42 +0000 | [diff] [blame] | 25 | #include "llvm/CallingConv.h" |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 26 | #include "llvm/Constants.h" |
Reid Spencer | c103057 | 2007-01-19 21:13:56 +0000 | [diff] [blame] | 27 | #include "llvm/DerivedTypes.h" |
Chris Lattner | 5e46a19 | 2006-04-02 03:07:27 +0000 | [diff] [blame] | 28 | #include "llvm/Support/CommandLine.h" |
Chris Lattner | a4f0b3a | 2006-08-27 12:54:02 +0000 | [diff] [blame] | 29 | #include "llvm/Support/Compiler.h" |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 30 | #include "llvm/Support/MathExtras.h" |
Chris Lattner | 7971514 | 2007-02-03 01:12:36 +0000 | [diff] [blame] | 31 | #include "llvm/ADT/DenseMap.h" |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 32 | #include "llvm/ADT/SmallVector.h" |
Chris Lattner | 00755df | 2007-02-04 00:27:56 +0000 | [diff] [blame] | 33 | #include "llvm/ADT/SmallPtrSet.h" |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 34 | #include <map> |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 35 | using namespace llvm; |
| 36 | |
Chris Lattner | 5e46a19 | 2006-04-02 03:07:27 +0000 | [diff] [blame] | 37 | #ifndef NDEBUG |
| 38 | static cl::opt<bool> |
| 39 | ViewLegalizeDAGs("view-legalize-dags", cl::Hidden, |
| 40 | cl::desc("Pop up a window to show dags before legalize")); |
| 41 | #else |
| 42 | static const bool ViewLegalizeDAGs = 0; |
| 43 | #endif |
| 44 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 45 | //===----------------------------------------------------------------------===// |
| 46 | /// SelectionDAGLegalize - This takes an arbitrary SelectionDAG as input and |
| 47 | /// hacks on it until the target machine can handle it. This involves |
| 48 | /// eliminating value sizes the machine cannot handle (promoting small sizes to |
| 49 | /// large sizes or splitting up large values into small values) as well as |
| 50 | /// eliminating operations the machine cannot handle. |
| 51 | /// |
| 52 | /// This code also does a small amount of optimization and recognition of idioms |
| 53 | /// as part of its processing. For example, if a target does not support a |
| 54 | /// 'setcc' instruction efficiently, but does support 'brcc' instruction, this |
| 55 | /// will attempt merge setcc and brc instructions into brcc's. |
| 56 | /// |
| 57 | namespace { |
Chris Lattner | 360e820 | 2006-06-28 21:58:30 +0000 | [diff] [blame] | 58 | class VISIBILITY_HIDDEN SelectionDAGLegalize { |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 59 | TargetLowering &TLI; |
| 60 | SelectionDAG &DAG; |
| 61 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 62 | // Libcall insertion helpers. |
| 63 | |
| 64 | /// LastCALLSEQ_END - This keeps track of the CALLSEQ_END node that has been |
| 65 | /// legalized. We use this to ensure that calls are properly serialized |
| 66 | /// against each other, including inserted libcalls. |
| 67 | SDOperand LastCALLSEQ_END; |
| 68 | |
| 69 | /// IsLegalizingCall - This member is used *only* for purposes of providing |
| 70 | /// helpful assertions that a libcall isn't created while another call is |
| 71 | /// being legalized (which could lead to non-serialized call sequences). |
| 72 | bool IsLegalizingCall; |
| 73 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 74 | enum LegalizeAction { |
Chris Lattner | 68a17fe | 2006-01-29 08:42:06 +0000 | [diff] [blame] | 75 | Legal, // The target natively supports this operation. |
| 76 | Promote, // This operation should be executed in a larger type. |
Chris Lattner | d74ea2b | 2006-05-24 17:04:05 +0000 | [diff] [blame] | 77 | Expand // Try to expand this to other ops, otherwise use a libcall. |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 78 | }; |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 79 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 80 | /// ValueTypeActions - This is a bitvector that contains two bits for each |
| 81 | /// value type, where the two bits correspond to the LegalizeAction enum. |
| 82 | /// This can be queried with "getTypeAction(VT)". |
Chris Lattner | 68a17fe | 2006-01-29 08:42:06 +0000 | [diff] [blame] | 83 | TargetLowering::ValueTypeActionImpl ValueTypeActions; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 84 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 85 | /// LegalizedNodes - For nodes that are of legal width, and that have more |
| 86 | /// than one use, this map indicates what regularized operand to use. This |
| 87 | /// allows us to avoid legalizing the same thing more than once. |
Chris Lattner | 718071c | 2007-02-04 00:50:02 +0000 | [diff] [blame] | 88 | DenseMap<SDOperand, SDOperand> LegalizedNodes; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 89 | |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 90 | /// PromotedNodes - For nodes that are below legal width, and that have more |
| 91 | /// than one use, this map indicates what promoted value to use. This allows |
| 92 | /// us to avoid promoting the same thing more than once. |
Chris Lattner | 40030bf | 2007-02-04 01:17:38 +0000 | [diff] [blame] | 93 | DenseMap<SDOperand, SDOperand> PromotedNodes; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 94 | |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 95 | /// ExpandedNodes - For nodes that need to be expanded this map indicates |
| 96 | /// which which operands are the expanded version of the input. This allows |
| 97 | /// us to avoid expanding the same node more than once. |
Chris Lattner | 40030bf | 2007-02-04 01:17:38 +0000 | [diff] [blame] | 98 | DenseMap<SDOperand, std::pair<SDOperand, SDOperand> > ExpandedNodes; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 99 | |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 100 | /// SplitNodes - For vector nodes that need to be split, this map indicates |
| 101 | /// which which operands are the split version of the input. This allows us |
| 102 | /// to avoid splitting the same node more than once. |
| 103 | std::map<SDOperand, std::pair<SDOperand, SDOperand> > SplitNodes; |
| 104 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 105 | /// ScalarizedNodes - For nodes that need to be converted from vector types to |
| 106 | /// scalar types, this contains the mapping of ones we have already |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 107 | /// processed to the result. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 108 | std::map<SDOperand, SDOperand> ScalarizedNodes; |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 109 | |
Chris Lattner | 8afc48e | 2005-01-07 22:28:47 +0000 | [diff] [blame] | 110 | void AddLegalizedOperand(SDOperand From, SDOperand To) { |
Chris Lattner | 69a889e | 2005-12-20 00:53:54 +0000 | [diff] [blame] | 111 | LegalizedNodes.insert(std::make_pair(From, To)); |
| 112 | // If someone requests legalization of the new node, return itself. |
| 113 | if (From != To) |
| 114 | LegalizedNodes.insert(std::make_pair(To, To)); |
Chris Lattner | 8afc48e | 2005-01-07 22:28:47 +0000 | [diff] [blame] | 115 | } |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 116 | void AddPromotedOperand(SDOperand From, SDOperand To) { |
Chris Lattner | 40030bf | 2007-02-04 01:17:38 +0000 | [diff] [blame] | 117 | bool isNew = PromotedNodes.insert(std::make_pair(From, To)); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 118 | assert(isNew && "Got into the map somehow?"); |
Chris Lattner | 69a889e | 2005-12-20 00:53:54 +0000 | [diff] [blame] | 119 | // If someone requests legalization of the new node, return itself. |
| 120 | LegalizedNodes.insert(std::make_pair(To, To)); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 121 | } |
Chris Lattner | 8afc48e | 2005-01-07 22:28:47 +0000 | [diff] [blame] | 122 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 123 | public: |
| 124 | |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 125 | SelectionDAGLegalize(SelectionDAG &DAG); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 126 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 127 | /// getTypeAction - Return how we should legalize values of this type, either |
| 128 | /// it is already legal or we need to expand it into multiple registers of |
| 129 | /// smaller integer type, or we need to promote it to a larger type. |
| 130 | LegalizeAction getTypeAction(MVT::ValueType VT) const { |
Chris Lattner | 68a17fe | 2006-01-29 08:42:06 +0000 | [diff] [blame] | 131 | return (LegalizeAction)ValueTypeActions.getTypeAction(VT); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | /// isTypeLegal - Return true if this type is legal on this target. |
| 135 | /// |
| 136 | bool isTypeLegal(MVT::ValueType VT) const { |
| 137 | return getTypeAction(VT) == Legal; |
| 138 | } |
| 139 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 140 | void LegalizeDAG(); |
| 141 | |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 142 | private: |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 143 | /// HandleOp - Legalize, Promote, or Expand the specified operand as |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 144 | /// appropriate for its type. |
| 145 | void HandleOp(SDOperand Op); |
| 146 | |
| 147 | /// LegalizeOp - We know that the specified value has a legal type. |
| 148 | /// Recursively ensure that the operands have legal types, then return the |
| 149 | /// result. |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 150 | SDOperand LegalizeOp(SDOperand O); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 151 | |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 152 | /// UnrollVectorOp - We know that the given vector has a legal type, however |
| 153 | /// the operation it performs is not legal and is an operation that we have |
| 154 | /// no way of lowering. "Unroll" the vector, splitting out the scalars and |
| 155 | /// operating on each element individually. |
| 156 | SDOperand UnrollVectorOp(SDOperand O); |
| 157 | |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 158 | /// PromoteOp - Given an operation that produces a value in an invalid type, |
| 159 | /// promote it to compute the value into a larger type. The produced value |
| 160 | /// will have the correct bits for the low portion of the register, but no |
| 161 | /// guarantee is made about the top bits: it may be zero, sign-extended, or |
| 162 | /// garbage. |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 163 | SDOperand PromoteOp(SDOperand O); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 164 | |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 165 | /// ExpandOp - Expand the specified SDOperand into its two component pieces |
| 166 | /// Lo&Hi. Note that the Op MUST be an expanded type. As a result of this, |
| 167 | /// the LegalizeNodes map is filled in for any results that are not expanded, |
| 168 | /// the ExpandedNodes map is filled in for any results that are expanded, and |
| 169 | /// the Lo/Hi values are returned. This applies to integer types and Vector |
| 170 | /// types. |
| 171 | void ExpandOp(SDOperand O, SDOperand &Lo, SDOperand &Hi); |
| 172 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 173 | /// SplitVectorOp - Given an operand of vector type, break it down into |
| 174 | /// two smaller values. |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 175 | void SplitVectorOp(SDOperand O, SDOperand &Lo, SDOperand &Hi); |
| 176 | |
Dan Gohman | 89b20c0 | 2007-06-27 14:06:22 +0000 | [diff] [blame] | 177 | /// ScalarizeVectorOp - Given an operand of single-element vector type |
| 178 | /// (e.g. v1f32), convert it into the equivalent operation that returns a |
| 179 | /// scalar (e.g. f32) value. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 180 | SDOperand ScalarizeVectorOp(SDOperand O); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 181 | |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 182 | /// isShuffleLegal - Return true if a vector shuffle is legal with the |
| 183 | /// specified mask and type. Targets can specify exactly which masks they |
| 184 | /// support and the code generator is tasked with not creating illegal masks. |
| 185 | /// |
| 186 | /// Note that this will also return true for shuffles that are promoted to a |
| 187 | /// different type. |
| 188 | /// |
| 189 | /// If this is a legal shuffle, this method returns the (possibly promoted) |
| 190 | /// build_vector Mask. If it's not a legal shuffle, it returns null. |
| 191 | SDNode *isShuffleLegal(MVT::ValueType VT, SDOperand Mask) const; |
| 192 | |
Chris Lattner | c9cf4f1 | 2006-07-26 23:55:56 +0000 | [diff] [blame] | 193 | bool LegalizeAllNodesNotLeadingTo(SDNode *N, SDNode *Dest, |
Chris Lattner | 00755df | 2007-02-04 00:27:56 +0000 | [diff] [blame] | 194 | SmallPtrSet<SDNode*, 32> &NodesLeadingTo); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 195 | |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 196 | void LegalizeSetCCOperands(SDOperand &LHS, SDOperand &RHS, SDOperand &CC); |
| 197 | |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 198 | SDOperand ExpandLibCall(const char *Name, SDNode *Node, bool isSigned, |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 199 | SDOperand &Hi); |
| 200 | SDOperand ExpandIntToFP(bool isSigned, MVT::ValueType DestTy, |
| 201 | SDOperand Source); |
Chris Lattner | cad063f | 2005-07-16 00:19:57 +0000 | [diff] [blame] | 202 | |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 203 | SDOperand EmitStackConvert(SDOperand SrcOp, MVT::ValueType SlotVT, |
| 204 | MVT::ValueType DestVT); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 205 | SDOperand ExpandBUILD_VECTOR(SDNode *Node); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 206 | SDOperand ExpandSCALAR_TO_VECTOR(SDNode *Node); |
Jim Laskey | 6269ed1 | 2005-08-17 00:39:29 +0000 | [diff] [blame] | 207 | SDOperand ExpandLegalINT_TO_FP(bool isSigned, |
| 208 | SDOperand LegalOp, |
| 209 | MVT::ValueType DestVT); |
Nate Begeman | 5a8441e | 2005-07-16 02:02:34 +0000 | [diff] [blame] | 210 | SDOperand PromoteLegalINT_TO_FP(SDOperand LegalOp, MVT::ValueType DestVT, |
| 211 | bool isSigned); |
Chris Lattner | 1618beb | 2005-07-29 00:11:56 +0000 | [diff] [blame] | 212 | SDOperand PromoteLegalFP_TO_INT(SDOperand LegalOp, MVT::ValueType DestVT, |
| 213 | bool isSigned); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 214 | |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 215 | SDOperand ExpandBSWAP(SDOperand Op); |
| 216 | SDOperand ExpandBitCount(unsigned Opc, SDOperand Op); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 217 | bool ExpandShift(unsigned Opc, SDOperand Op, SDOperand Amt, |
| 218 | SDOperand &Lo, SDOperand &Hi); |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 219 | void ExpandShiftParts(unsigned NodeOp, SDOperand Op, SDOperand Amt, |
| 220 | SDOperand &Lo, SDOperand &Hi); |
Chris Lattner | b9fa3bc | 2005-05-12 04:49:08 +0000 | [diff] [blame] | 221 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 222 | SDOperand ExpandEXTRACT_SUBVECTOR(SDOperand Op); |
Chris Lattner | 4aab2f4 | 2006-04-02 05:06:04 +0000 | [diff] [blame] | 223 | SDOperand ExpandEXTRACT_VECTOR_ELT(SDOperand Op); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 224 | }; |
| 225 | } |
| 226 | |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 227 | /// isVectorShuffleLegal - Return true if a vector shuffle is legal with the |
| 228 | /// specified mask and type. Targets can specify exactly which masks they |
| 229 | /// support and the code generator is tasked with not creating illegal masks. |
| 230 | /// |
| 231 | /// Note that this will also return true for shuffles that are promoted to a |
| 232 | /// different type. |
| 233 | SDNode *SelectionDAGLegalize::isShuffleLegal(MVT::ValueType VT, |
| 234 | SDOperand Mask) const { |
| 235 | switch (TLI.getOperationAction(ISD::VECTOR_SHUFFLE, VT)) { |
| 236 | default: return 0; |
| 237 | case TargetLowering::Legal: |
| 238 | case TargetLowering::Custom: |
| 239 | break; |
| 240 | case TargetLowering::Promote: { |
| 241 | // If this is promoted to a different type, convert the shuffle mask and |
| 242 | // ask if it is legal in the promoted type! |
| 243 | MVT::ValueType NVT = TLI.getTypeToPromoteTo(ISD::VECTOR_SHUFFLE, VT); |
| 244 | |
| 245 | // If we changed # elements, change the shuffle mask. |
| 246 | unsigned NumEltsGrowth = |
| 247 | MVT::getVectorNumElements(NVT) / MVT::getVectorNumElements(VT); |
| 248 | assert(NumEltsGrowth && "Cannot promote to vector type with fewer elts!"); |
| 249 | if (NumEltsGrowth > 1) { |
| 250 | // Renumber the elements. |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 251 | SmallVector<SDOperand, 8> Ops; |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 252 | for (unsigned i = 0, e = Mask.getNumOperands(); i != e; ++i) { |
| 253 | SDOperand InOp = Mask.getOperand(i); |
| 254 | for (unsigned j = 0; j != NumEltsGrowth; ++j) { |
| 255 | if (InOp.getOpcode() == ISD::UNDEF) |
| 256 | Ops.push_back(DAG.getNode(ISD::UNDEF, MVT::i32)); |
| 257 | else { |
| 258 | unsigned InEltNo = cast<ConstantSDNode>(InOp)->getValue(); |
| 259 | Ops.push_back(DAG.getConstant(InEltNo*NumEltsGrowth+j, MVT::i32)); |
| 260 | } |
| 261 | } |
| 262 | } |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 263 | Mask = DAG.getNode(ISD::BUILD_VECTOR, NVT, &Ops[0], Ops.size()); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 264 | } |
| 265 | VT = NVT; |
| 266 | break; |
| 267 | } |
| 268 | } |
| 269 | return TLI.isShuffleMaskLegal(Mask, VT) ? Mask.Val : 0; |
| 270 | } |
| 271 | |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 272 | SelectionDAGLegalize::SelectionDAGLegalize(SelectionDAG &dag) |
| 273 | : TLI(dag.getTargetLoweringInfo()), DAG(dag), |
| 274 | ValueTypeActions(TLI.getValueTypeActions()) { |
Nate Begeman | 6a64861 | 2005-11-29 05:45:29 +0000 | [diff] [blame] | 275 | assert(MVT::LAST_VALUETYPE <= 32 && |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 276 | "Too many value types for ValueTypeActions to hold!"); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 277 | } |
| 278 | |
Chris Lattner | e10e6f7 | 2007-06-18 21:28:10 +0000 | [diff] [blame] | 279 | /// ComputeTopDownOrdering - Compute a top-down ordering of the dag, where Order |
| 280 | /// contains all of a nodes operands before it contains the node. |
| 281 | static void ComputeTopDownOrdering(SelectionDAG &DAG, |
| 282 | SmallVector<SDNode*, 64> &Order) { |
| 283 | |
| 284 | DenseMap<SDNode*, unsigned> Visited; |
| 285 | std::vector<SDNode*> Worklist; |
| 286 | Worklist.reserve(128); |
Chris Lattner | 32fca00 | 2005-10-06 01:20:27 +0000 | [diff] [blame] | 287 | |
Chris Lattner | e10e6f7 | 2007-06-18 21:28:10 +0000 | [diff] [blame] | 288 | // Compute ordering from all of the leaves in the graphs, those (like the |
| 289 | // entry node) that have no operands. |
| 290 | for (SelectionDAG::allnodes_iterator I = DAG.allnodes_begin(), |
| 291 | E = DAG.allnodes_end(); I != E; ++I) { |
| 292 | if (I->getNumOperands() == 0) { |
| 293 | Visited[I] = 0 - 1U; |
| 294 | Worklist.push_back(I); |
| 295 | } |
Chris Lattner | 32fca00 | 2005-10-06 01:20:27 +0000 | [diff] [blame] | 296 | } |
| 297 | |
Chris Lattner | e10e6f7 | 2007-06-18 21:28:10 +0000 | [diff] [blame] | 298 | while (!Worklist.empty()) { |
| 299 | SDNode *N = Worklist.back(); |
| 300 | Worklist.pop_back(); |
| 301 | |
| 302 | if (++Visited[N] != N->getNumOperands()) |
| 303 | continue; // Haven't visited all operands yet |
| 304 | |
| 305 | Order.push_back(N); |
| 306 | |
| 307 | // Now that we have N in, add anything that uses it if all of their operands |
| 308 | // are now done. |
| 309 | for (SDNode::use_iterator UI = N->use_begin(), E = N->use_end(); |
| 310 | UI != E; ++UI) |
| 311 | Worklist.push_back(*UI); |
| 312 | } |
| 313 | |
| 314 | assert(Order.size() == Visited.size() && |
| 315 | Order.size() == |
| 316 | (unsigned)std::distance(DAG.allnodes_begin(), DAG.allnodes_end()) && |
| 317 | "Error: DAG is cyclic!"); |
Chris Lattner | 32fca00 | 2005-10-06 01:20:27 +0000 | [diff] [blame] | 318 | } |
| 319 | |
Chris Lattner | 1618beb | 2005-07-29 00:11:56 +0000 | [diff] [blame] | 320 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 321 | void SelectionDAGLegalize::LegalizeDAG() { |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 322 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 323 | IsLegalizingCall = false; |
| 324 | |
Chris Lattner | ab510a7 | 2005-10-02 17:49:46 +0000 | [diff] [blame] | 325 | // The legalize process is inherently a bottom-up recursive process (users |
| 326 | // legalize their uses before themselves). Given infinite stack space, we |
| 327 | // could just start legalizing on the root and traverse the whole graph. In |
| 328 | // 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] | 329 | // blocks. To avoid this problem, compute an ordering of the nodes where each |
| 330 | // node is only legalized after all of its operands are legalized. |
Chris Lattner | 0ed4417 | 2007-02-04 01:20:02 +0000 | [diff] [blame] | 331 | SmallVector<SDNode*, 64> Order; |
Chris Lattner | e10e6f7 | 2007-06-18 21:28:10 +0000 | [diff] [blame] | 332 | ComputeTopDownOrdering(DAG, Order); |
Chris Lattner | ab510a7 | 2005-10-02 17:49:46 +0000 | [diff] [blame] | 333 | |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 334 | for (unsigned i = 0, e = Order.size(); i != e; ++i) |
| 335 | HandleOp(SDOperand(Order[i], 0)); |
Chris Lattner | 32fca00 | 2005-10-06 01:20:27 +0000 | [diff] [blame] | 336 | |
| 337 | // Finally, it's possible the root changed. Get the new root. |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 338 | SDOperand OldRoot = DAG.getRoot(); |
Chris Lattner | 32fca00 | 2005-10-06 01:20:27 +0000 | [diff] [blame] | 339 | assert(LegalizedNodes.count(OldRoot) && "Root didn't get legalized?"); |
| 340 | DAG.setRoot(LegalizedNodes[OldRoot]); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 341 | |
| 342 | ExpandedNodes.clear(); |
| 343 | LegalizedNodes.clear(); |
Chris Lattner | 71c42a0 | 2005-01-16 01:11:45 +0000 | [diff] [blame] | 344 | PromotedNodes.clear(); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 345 | SplitNodes.clear(); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 346 | ScalarizedNodes.clear(); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 347 | |
| 348 | // Remove dead nodes now. |
Chris Lattner | 190a418 | 2006-08-04 17:45:20 +0000 | [diff] [blame] | 349 | DAG.RemoveDeadNodes(); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 350 | } |
| 351 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 352 | |
| 353 | /// FindCallEndFromCallStart - Given a chained node that is part of a call |
| 354 | /// sequence, find the CALLSEQ_END node that terminates the call sequence. |
| 355 | static SDNode *FindCallEndFromCallStart(SDNode *Node) { |
| 356 | if (Node->getOpcode() == ISD::CALLSEQ_END) |
| 357 | return Node; |
| 358 | if (Node->use_empty()) |
| 359 | return 0; // No CallSeqEnd |
| 360 | |
| 361 | // The chain is usually at the end. |
| 362 | SDOperand TheChain(Node, Node->getNumValues()-1); |
| 363 | if (TheChain.getValueType() != MVT::Other) { |
| 364 | // Sometimes it's at the beginning. |
| 365 | TheChain = SDOperand(Node, 0); |
| 366 | if (TheChain.getValueType() != MVT::Other) { |
| 367 | // Otherwise, hunt for it. |
| 368 | for (unsigned i = 1, e = Node->getNumValues(); i != e; ++i) |
| 369 | if (Node->getValueType(i) == MVT::Other) { |
| 370 | TheChain = SDOperand(Node, i); |
| 371 | break; |
| 372 | } |
| 373 | |
| 374 | // Otherwise, we walked into a node without a chain. |
| 375 | if (TheChain.getValueType() != MVT::Other) |
| 376 | return 0; |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | for (SDNode::use_iterator UI = Node->use_begin(), |
| 381 | E = Node->use_end(); UI != E; ++UI) { |
| 382 | |
| 383 | // Make sure to only follow users of our token chain. |
| 384 | SDNode *User = *UI; |
| 385 | for (unsigned i = 0, e = User->getNumOperands(); i != e; ++i) |
| 386 | if (User->getOperand(i) == TheChain) |
| 387 | if (SDNode *Result = FindCallEndFromCallStart(User)) |
| 388 | return Result; |
| 389 | } |
| 390 | return 0; |
| 391 | } |
| 392 | |
| 393 | /// FindCallStartFromCallEnd - Given a chained node that is part of a call |
| 394 | /// sequence, find the CALLSEQ_START node that initiates the call sequence. |
| 395 | static SDNode *FindCallStartFromCallEnd(SDNode *Node) { |
| 396 | assert(Node && "Didn't find callseq_start for a call??"); |
| 397 | if (Node->getOpcode() == ISD::CALLSEQ_START) return Node; |
| 398 | |
| 399 | assert(Node->getOperand(0).getValueType() == MVT::Other && |
| 400 | "Node doesn't have a token chain argument!"); |
| 401 | return FindCallStartFromCallEnd(Node->getOperand(0).Val); |
| 402 | } |
| 403 | |
| 404 | /// LegalizeAllNodesNotLeadingTo - Recursively walk the uses of N, looking to |
| 405 | /// see if any uses can reach Dest. If no dest operands can get to dest, |
| 406 | /// legalize them, legalize ourself, and return false, otherwise, return true. |
Chris Lattner | c9cf4f1 | 2006-07-26 23:55:56 +0000 | [diff] [blame] | 407 | /// |
| 408 | /// Keep track of the nodes we fine that actually do lead to Dest in |
| 409 | /// NodesLeadingTo. This avoids retraversing them exponential number of times. |
| 410 | /// |
| 411 | bool SelectionDAGLegalize::LegalizeAllNodesNotLeadingTo(SDNode *N, SDNode *Dest, |
Chris Lattner | 00755df | 2007-02-04 00:27:56 +0000 | [diff] [blame] | 412 | SmallPtrSet<SDNode*, 32> &NodesLeadingTo) { |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 413 | if (N == Dest) return true; // N certainly leads to Dest :) |
| 414 | |
Chris Lattner | c9cf4f1 | 2006-07-26 23:55:56 +0000 | [diff] [blame] | 415 | // If we've already processed this node and it does lead to Dest, there is no |
| 416 | // need to reprocess it. |
| 417 | if (NodesLeadingTo.count(N)) return true; |
| 418 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 419 | // If the first result of this node has been already legalized, then it cannot |
| 420 | // reach N. |
| 421 | switch (getTypeAction(N->getValueType(0))) { |
| 422 | case Legal: |
| 423 | if (LegalizedNodes.count(SDOperand(N, 0))) return false; |
| 424 | break; |
| 425 | case Promote: |
| 426 | if (PromotedNodes.count(SDOperand(N, 0))) return false; |
| 427 | break; |
| 428 | case Expand: |
| 429 | if (ExpandedNodes.count(SDOperand(N, 0))) return false; |
| 430 | break; |
| 431 | } |
| 432 | |
| 433 | // Okay, this node has not already been legalized. Check and legalize all |
| 434 | // operands. If none lead to Dest, then we can legalize this node. |
| 435 | bool OperandsLeadToDest = false; |
| 436 | for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) |
| 437 | OperandsLeadToDest |= // If an operand leads to Dest, so do we. |
Chris Lattner | c9cf4f1 | 2006-07-26 23:55:56 +0000 | [diff] [blame] | 438 | LegalizeAllNodesNotLeadingTo(N->getOperand(i).Val, Dest, NodesLeadingTo); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 439 | |
Chris Lattner | c9cf4f1 | 2006-07-26 23:55:56 +0000 | [diff] [blame] | 440 | if (OperandsLeadToDest) { |
| 441 | NodesLeadingTo.insert(N); |
| 442 | return true; |
| 443 | } |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 444 | |
| 445 | // Okay, this node looks safe, legalize it and return false. |
Chris Lattner | 80edfb3 | 2006-04-17 22:10:08 +0000 | [diff] [blame] | 446 | HandleOp(SDOperand(N, 0)); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 447 | return false; |
| 448 | } |
| 449 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 450 | /// HandleOp - Legalize, Promote, or Expand the specified operand as |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 451 | /// appropriate for its type. |
| 452 | void SelectionDAGLegalize::HandleOp(SDOperand Op) { |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 453 | MVT::ValueType VT = Op.getValueType(); |
| 454 | switch (getTypeAction(VT)) { |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 455 | default: assert(0 && "Bad type action!"); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 456 | case Legal: (void)LegalizeOp(Op); break; |
| 457 | case Promote: (void)PromoteOp(Op); break; |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 458 | case Expand: |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 459 | if (!MVT::isVector(VT)) { |
| 460 | // If this is an illegal scalar, expand it into its two component |
| 461 | // pieces. |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 462 | SDOperand X, Y; |
Chris Lattner | 09ec1b0 | 2007-08-25 01:00:22 +0000 | [diff] [blame] | 463 | if (Op.getOpcode() == ISD::TargetConstant) |
| 464 | break; // Allow illegal target nodes. |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 465 | ExpandOp(Op, X, Y); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 466 | } else if (MVT::getVectorNumElements(VT) == 1) { |
| 467 | // If this is an illegal single element vector, convert it to a |
| 468 | // scalar operation. |
| 469 | (void)ScalarizeVectorOp(Op); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 470 | } else { |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 471 | // Otherwise, this is an illegal multiple element vector. |
| 472 | // Split it in half and legalize both parts. |
| 473 | SDOperand X, Y; |
| 474 | SplitVectorOp(Op, X, Y); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 475 | } |
| 476 | break; |
| 477 | } |
| 478 | } |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 479 | |
Evan Cheng | 9f87788 | 2006-12-13 20:57:08 +0000 | [diff] [blame] | 480 | /// ExpandConstantFP - Expands the ConstantFP node to an integer constant or |
| 481 | /// a load from the constant pool. |
| 482 | static SDOperand ExpandConstantFP(ConstantFPSDNode *CFP, bool UseCP, |
Evan Cheng | 279101e | 2006-12-12 22:19:28 +0000 | [diff] [blame] | 483 | SelectionDAG &DAG, TargetLowering &TLI) { |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 484 | bool Extend = false; |
| 485 | |
| 486 | // If a FP immediate is precise when represented as a float and if the |
| 487 | // target can do an extending load from float to double, we put it into |
| 488 | // the constant pool as a float, even if it's is statically typed as a |
| 489 | // double. |
| 490 | MVT::ValueType VT = CFP->getValueType(0); |
| 491 | bool isDouble = VT == MVT::f64; |
Dale Johannesen | 118cd9d | 2007-09-16 16:51:49 +0000 | [diff] [blame] | 492 | ConstantFP *LLVMC = ConstantFP::get(MVT::getTypeForValueType(VT), |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 493 | CFP->getValueAPF()); |
Evan Cheng | 9f87788 | 2006-12-13 20:57:08 +0000 | [diff] [blame] | 494 | if (!UseCP) { |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 495 | if (VT!=MVT::f64 && VT!=MVT::f32) |
| 496 | assert(0 && "Invalid type expansion"); |
Dale Johannesen | 9d5f456 | 2007-09-12 03:30:33 +0000 | [diff] [blame] | 497 | return DAG.getConstant(LLVMC->getValueAPF().convertToAPInt().getZExtValue(), |
| 498 | isDouble ? MVT::i64 : MVT::i32); |
Evan Cheng | 279101e | 2006-12-12 22:19:28 +0000 | [diff] [blame] | 499 | } |
| 500 | |
Dale Johannesen | f04afdb | 2007-08-30 00:23:21 +0000 | [diff] [blame] | 501 | if (isDouble && CFP->isValueValidForType(MVT::f32, CFP->getValueAPF()) && |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 502 | // 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] | 503 | // Do not try to be clever about long doubles (so far) |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 504 | TLI.isLoadXLegal(ISD::EXTLOAD, MVT::f32)) { |
| 505 | LLVMC = cast<ConstantFP>(ConstantExpr::getFPTrunc(LLVMC,Type::FloatTy)); |
| 506 | VT = MVT::f32; |
| 507 | Extend = true; |
| 508 | } |
| 509 | |
| 510 | SDOperand CPIdx = DAG.getConstantPool(LLVMC, TLI.getPointerTy()); |
| 511 | if (Extend) { |
| 512 | return DAG.getExtLoad(ISD::EXTLOAD, MVT::f64, DAG.getEntryNode(), |
Dan Gohman | 3069b87 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 513 | CPIdx, PseudoSourceValue::getConstantPool(), |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 514 | 0, MVT::f32); |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 515 | } else { |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 516 | return DAG.getLoad(VT, DAG.getEntryNode(), CPIdx, |
Dan Gohman | 3069b87 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 517 | PseudoSourceValue::getConstantPool(), 0); |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 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(); |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 572 | if (MVT::isFloatingPoint(ST->getMemoryVT())) { |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 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 | } |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 587 | assert(MVT::isInteger(ST->getMemoryVT()) && |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 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 |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 590 | MVT::ValueType NewStoredVT = ST->getMemoryVT() - 1; |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 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); |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 622 | MVT::ValueType LoadedVT = LD->getMemoryVT(); |
Chris Lattner | e400af8 | 2007-11-19 21:38:03 +0000 | [diff] [blame] | 623 | if (MVT::isFloatingPoint(VT) && !MVT::isVector(VT)) { |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 624 | // Expand to a (misaligned) integer load of the same size, |
| 625 | // then bitconvert to floating point. |
| 626 | MVT::ValueType intVT; |
Chris Lattner | e400af8 | 2007-11-19 21:38:03 +0000 | [diff] [blame] | 627 | if (LoadedVT == MVT::f64) |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 628 | intVT = MVT::i64; |
Chris Lattner | e400af8 | 2007-11-19 21:38:03 +0000 | [diff] [blame] | 629 | else if (LoadedVT == MVT::f32) |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 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 | } |
Chris Lattner | e400af8 | 2007-11-19 21:38:03 +0000 | [diff] [blame] | 645 | assert((MVT::isInteger(LoadedVT) || MVT::isVector(LoadedVT)) && |
| 646 | "Unaligned load of unsupported type."); |
| 647 | |
| 648 | // Compute the new VT that is half the size of the old one. We either have an |
| 649 | // integer MVT or we have a vector MVT. |
| 650 | unsigned NumBits = MVT::getSizeInBits(LoadedVT); |
| 651 | MVT::ValueType NewLoadedVT; |
| 652 | if (!MVT::isVector(LoadedVT)) { |
| 653 | NewLoadedVT = MVT::getIntegerType(NumBits/2); |
| 654 | } else { |
| 655 | // FIXME: This is not right for <1 x anything> it is also not right for |
| 656 | // non-power-of-two vectors. |
| 657 | NewLoadedVT = MVT::getVectorType(MVT::getVectorElementType(LoadedVT), |
| 658 | MVT::getVectorNumElements(LoadedVT)/2); |
| 659 | } |
| 660 | NumBits >>= 1; |
| 661 | |
| 662 | unsigned Alignment = LD->getAlignment(); |
| 663 | unsigned IncrementSize = NumBits / 8; |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 664 | ISD::LoadExtType HiExtType = LD->getExtensionType(); |
| 665 | |
| 666 | // If the original load is NON_EXTLOAD, the hi part load must be ZEXTLOAD. |
| 667 | if (HiExtType == ISD::NON_EXTLOAD) |
| 668 | HiExtType = ISD::ZEXTLOAD; |
| 669 | |
| 670 | // Load the value in two parts |
| 671 | SDOperand Lo, Hi; |
| 672 | if (TLI.isLittleEndian()) { |
| 673 | Lo = DAG.getExtLoad(ISD::ZEXTLOAD, VT, Chain, Ptr, LD->getSrcValue(), |
| 674 | SVOffset, NewLoadedVT, LD->isVolatile(), Alignment); |
| 675 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
| 676 | DAG.getConstant(IncrementSize, TLI.getPointerTy())); |
| 677 | Hi = DAG.getExtLoad(HiExtType, VT, Chain, Ptr, LD->getSrcValue(), |
| 678 | SVOffset + IncrementSize, NewLoadedVT, LD->isVolatile(), |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 679 | MinAlign(Alignment, IncrementSize)); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 680 | } else { |
| 681 | Hi = DAG.getExtLoad(HiExtType, VT, Chain, Ptr, LD->getSrcValue(), SVOffset, |
| 682 | NewLoadedVT,LD->isVolatile(), Alignment); |
| 683 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
| 684 | DAG.getConstant(IncrementSize, TLI.getPointerTy())); |
| 685 | Lo = DAG.getExtLoad(ISD::ZEXTLOAD, VT, Chain, Ptr, LD->getSrcValue(), |
| 686 | SVOffset + IncrementSize, NewLoadedVT, LD->isVolatile(), |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 687 | MinAlign(Alignment, IncrementSize)); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | // aggregate the two parts |
| 691 | SDOperand ShiftAmount = DAG.getConstant(NumBits, TLI.getShiftAmountTy()); |
| 692 | SDOperand Result = DAG.getNode(ISD::SHL, VT, Hi, ShiftAmount); |
| 693 | Result = DAG.getNode(ISD::OR, VT, Result, Lo); |
| 694 | |
| 695 | SDOperand TF = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1), |
| 696 | Hi.getValue(1)); |
| 697 | |
| 698 | SDOperand Ops[] = { Result, TF }; |
| 699 | return DAG.getNode(ISD::MERGE_VALUES, DAG.getVTList(VT, MVT::Other), Ops, 2); |
| 700 | } |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 701 | |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 702 | /// UnrollVectorOp - We know that the given vector has a legal type, however |
| 703 | /// the operation it performs is not legal and is an operation that we have |
| 704 | /// no way of lowering. "Unroll" the vector, splitting out the scalars and |
| 705 | /// operating on each element individually. |
| 706 | SDOperand SelectionDAGLegalize::UnrollVectorOp(SDOperand Op) { |
| 707 | MVT::ValueType VT = Op.getValueType(); |
| 708 | assert(isTypeLegal(VT) && |
| 709 | "Caller should expand or promote operands that are not legal!"); |
| 710 | assert(Op.Val->getNumValues() == 1 && |
| 711 | "Can't unroll a vector with multiple results!"); |
| 712 | unsigned NE = MVT::getVectorNumElements(VT); |
| 713 | MVT::ValueType EltVT = MVT::getVectorElementType(VT); |
| 714 | |
| 715 | SmallVector<SDOperand, 8> Scalars; |
| 716 | SmallVector<SDOperand, 4> Operands(Op.getNumOperands()); |
| 717 | for (unsigned i = 0; i != NE; ++i) { |
| 718 | for (unsigned j = 0; j != Op.getNumOperands(); ++j) { |
| 719 | SDOperand Operand = Op.getOperand(j); |
| 720 | MVT::ValueType OperandVT = Operand.getValueType(); |
| 721 | if (MVT::isVector(OperandVT)) { |
| 722 | // A vector operand; extract a single element. |
| 723 | MVT::ValueType OperandEltVT = MVT::getVectorElementType(OperandVT); |
| 724 | Operands[j] = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, |
| 725 | OperandEltVT, |
| 726 | Operand, |
| 727 | DAG.getConstant(i, MVT::i32)); |
| 728 | } else { |
| 729 | // A scalar operand; just use it as is. |
| 730 | Operands[j] = Operand; |
| 731 | } |
| 732 | } |
| 733 | Scalars.push_back(DAG.getNode(Op.getOpcode(), EltVT, |
| 734 | &Operands[0], Operands.size())); |
| 735 | } |
| 736 | |
| 737 | return DAG.getNode(ISD::BUILD_VECTOR, VT, &Scalars[0], Scalars.size()); |
| 738 | } |
| 739 | |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 740 | /// GetFPLibCall - Return the right libcall for the given floating point type. |
| 741 | static RTLIB::Libcall GetFPLibCall(MVT::ValueType VT, |
| 742 | RTLIB::Libcall Call_F32, |
| 743 | RTLIB::Libcall Call_F64, |
| 744 | RTLIB::Libcall Call_F80, |
| 745 | RTLIB::Libcall Call_PPCF128) { |
| 746 | return |
| 747 | VT == MVT::f32 ? Call_F32 : |
| 748 | VT == MVT::f64 ? Call_F64 : |
| 749 | VT == MVT::f80 ? Call_F80 : |
| 750 | VT == MVT::ppcf128 ? Call_PPCF128 : |
| 751 | RTLIB::UNKNOWN_LIBCALL; |
| 752 | } |
| 753 | |
Dan Gohman | a346615 | 2007-07-13 20:14:11 +0000 | [diff] [blame] | 754 | /// LegalizeOp - We know that the specified value has a legal type, and |
| 755 | /// that its operands are legal. Now ensure that the operation itself |
| 756 | /// is legal, recursively ensuring that the operands' operations remain |
| 757 | /// legal. |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 758 | SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) { |
Chris Lattner | 09ec1b0 | 2007-08-25 01:00:22 +0000 | [diff] [blame] | 759 | if (Op.getOpcode() == ISD::TargetConstant) // Allow illegal target nodes. |
| 760 | return Op; |
| 761 | |
Chris Lattner | c9c60f6 | 2005-08-24 16:35:28 +0000 | [diff] [blame] | 762 | assert(isTypeLegal(Op.getValueType()) && |
Chris Lattner | e3304a3 | 2005-01-08 20:35:13 +0000 | [diff] [blame] | 763 | "Caller should expand or promote operands that are not legal!"); |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 764 | SDNode *Node = Op.Val; |
Chris Lattner | e3304a3 | 2005-01-08 20:35:13 +0000 | [diff] [blame] | 765 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 766 | // If this operation defines any values that cannot be represented in a |
Chris Lattner | e3304a3 | 2005-01-08 20:35:13 +0000 | [diff] [blame] | 767 | // register on this target, make sure to expand or promote them. |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 768 | if (Node->getNumValues() > 1) { |
| 769 | for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 770 | if (getTypeAction(Node->getValueType(i)) != Legal) { |
| 771 | HandleOp(Op.getValue(i)); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 772 | assert(LegalizedNodes.count(Op) && |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 773 | "Handling didn't add legal operands!"); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 774 | return LegalizedNodes[Op]; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 775 | } |
| 776 | } |
| 777 | |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 778 | // Note that LegalizeOp may be reentered even from single-use nodes, which |
| 779 | // means that we always must cache transformed nodes. |
Chris Lattner | 718071c | 2007-02-04 00:50:02 +0000 | [diff] [blame] | 780 | DenseMap<SDOperand, SDOperand>::iterator I = LegalizedNodes.find(Op); |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 781 | if (I != LegalizedNodes.end()) return I->second; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 782 | |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 783 | SDOperand Tmp1, Tmp2, Tmp3, Tmp4; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 784 | SDOperand Result = Op; |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 785 | bool isCustom = false; |
| 786 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 787 | switch (Node->getOpcode()) { |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 788 | case ISD::FrameIndex: |
| 789 | case ISD::EntryToken: |
| 790 | case ISD::Register: |
| 791 | case ISD::BasicBlock: |
| 792 | case ISD::TargetFrameIndex: |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 793 | case ISD::TargetJumpTable: |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 794 | case ISD::TargetConstant: |
Chris Lattner | 3181a77 | 2006-01-29 06:26:56 +0000 | [diff] [blame] | 795 | case ISD::TargetConstantFP: |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 796 | case ISD::TargetConstantPool: |
| 797 | case ISD::TargetGlobalAddress: |
Lauro Ramos Venancio | b3a0417 | 2007-04-20 21:38:10 +0000 | [diff] [blame] | 798 | case ISD::TargetGlobalTLSAddress: |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 799 | case ISD::TargetExternalSymbol: |
| 800 | case ISD::VALUETYPE: |
| 801 | case ISD::SRCVALUE: |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 802 | case ISD::MEMOPERAND: |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 803 | case ISD::STRING: |
| 804 | case ISD::CONDCODE: |
| 805 | // Primitives must all be legal. |
Duncan Sands | a7c97a7 | 2007-10-16 09:07:20 +0000 | [diff] [blame] | 806 | assert(TLI.isOperationLegal(Node->getOpcode(), Node->getValueType(0)) && |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 807 | "This must be legal!"); |
| 808 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 809 | default: |
Chris Lattner | d73cc5d | 2005-05-14 06:34:48 +0000 | [diff] [blame] | 810 | if (Node->getOpcode() >= ISD::BUILTIN_OP_END) { |
| 811 | // If this is a target node, legalize it by legalizing the operands then |
| 812 | // passing it through. |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 813 | SmallVector<SDOperand, 8> Ops; |
Chris Lattner | c5d7d7c | 2006-05-17 18:00:08 +0000 | [diff] [blame] | 814 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) |
Chris Lattner | d73cc5d | 2005-05-14 06:34:48 +0000 | [diff] [blame] | 815 | Ops.push_back(LegalizeOp(Node->getOperand(i))); |
Chris Lattner | c5d7d7c | 2006-05-17 18:00:08 +0000 | [diff] [blame] | 816 | |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 817 | Result = DAG.UpdateNodeOperands(Result.getValue(0), &Ops[0], Ops.size()); |
Chris Lattner | d73cc5d | 2005-05-14 06:34:48 +0000 | [diff] [blame] | 818 | |
| 819 | for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) |
| 820 | AddLegalizedOperand(Op.getValue(i), Result.getValue(i)); |
| 821 | return Result.getValue(Op.ResNo); |
| 822 | } |
| 823 | // Otherwise this is an unhandled builtin node. splat. |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 824 | #ifndef NDEBUG |
Dan Gohman | 3983358 | 2007-06-04 16:17:33 +0000 | [diff] [blame] | 825 | cerr << "NODE: "; Node->dump(&DAG); cerr << "\n"; |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 826 | #endif |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 827 | assert(0 && "Do not know how to legalize this operator!"); |
| 828 | abort(); |
Lauro Ramos Venancio | 0d3b678 | 2007-04-20 23:02:39 +0000 | [diff] [blame] | 829 | case ISD::GLOBAL_OFFSET_TABLE: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 830 | case ISD::GlobalAddress: |
Lauro Ramos Venancio | b3a0417 | 2007-04-20 21:38:10 +0000 | [diff] [blame] | 831 | case ISD::GlobalTLSAddress: |
Chris Lattner | 03c0cf8 | 2005-01-07 21:45:56 +0000 | [diff] [blame] | 832 | case ISD::ExternalSymbol: |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 833 | case ISD::ConstantPool: |
| 834 | case ISD::JumpTable: // Nothing to do. |
Chris Lattner | 0c8fbe3 | 2005-11-17 06:41:44 +0000 | [diff] [blame] | 835 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 836 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 837 | case TargetLowering::Custom: |
| 838 | Tmp1 = TLI.LowerOperation(Op, DAG); |
| 839 | if (Tmp1.Val) Result = Tmp1; |
| 840 | // 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] | 841 | case TargetLowering::Legal: |
Chris Lattner | 0c8fbe3 | 2005-11-17 06:41:44 +0000 | [diff] [blame] | 842 | break; |
| 843 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 844 | break; |
Nate Begeman | bcc5f36 | 2007-01-29 22:58:52 +0000 | [diff] [blame] | 845 | case ISD::FRAMEADDR: |
| 846 | case ISD::RETURNADDR: |
| 847 | // The only option for these nodes is to custom lower them. If the target |
| 848 | // does not custom lower them, then return zero. |
| 849 | Tmp1 = TLI.LowerOperation(Op, DAG); |
| 850 | if (Tmp1.Val) |
| 851 | Result = Tmp1; |
| 852 | else |
| 853 | Result = DAG.getConstant(0, TLI.getPointerTy()); |
| 854 | break; |
Anton Korobeynikov | 055c544 | 2007-08-29 23:18:48 +0000 | [diff] [blame] | 855 | case ISD::FRAME_TO_ARGS_OFFSET: { |
Anton Korobeynikov | 066f7b4 | 2007-08-29 19:28:29 +0000 | [diff] [blame] | 856 | MVT::ValueType VT = Node->getValueType(0); |
| 857 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 858 | default: assert(0 && "This action is not supported yet!"); |
| 859 | case TargetLowering::Custom: |
| 860 | Result = TLI.LowerOperation(Op, DAG); |
| 861 | if (Result.Val) break; |
| 862 | // Fall Thru |
| 863 | case TargetLowering::Legal: |
| 864 | Result = DAG.getConstant(0, VT); |
| 865 | break; |
| 866 | } |
Anton Korobeynikov | 055c544 | 2007-08-29 23:18:48 +0000 | [diff] [blame] | 867 | } |
Anton Korobeynikov | 066f7b4 | 2007-08-29 19:28:29 +0000 | [diff] [blame] | 868 | break; |
Jim Laskey | 2bc210d | 2007-02-22 15:37:19 +0000 | [diff] [blame] | 869 | case ISD::EXCEPTIONADDR: { |
| 870 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 871 | MVT::ValueType VT = Node->getValueType(0); |
| 872 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 873 | default: assert(0 && "This action is not supported yet!"); |
| 874 | case TargetLowering::Expand: { |
Jim Laskey | 8782d48 | 2007-02-28 20:43:58 +0000 | [diff] [blame] | 875 | unsigned Reg = TLI.getExceptionAddressRegister(); |
Duncan Sands | b027fa0 | 2007-12-31 18:35:50 +0000 | [diff] [blame] | 876 | Result = DAG.getCopyFromReg(Tmp1, Reg, VT); |
Jim Laskey | 2bc210d | 2007-02-22 15:37:19 +0000 | [diff] [blame] | 877 | } |
| 878 | break; |
| 879 | case TargetLowering::Custom: |
| 880 | Result = TLI.LowerOperation(Op, DAG); |
| 881 | if (Result.Val) break; |
| 882 | // Fall Thru |
Chris Lattner | eb7f34f | 2007-04-27 17:12:52 +0000 | [diff] [blame] | 883 | case TargetLowering::Legal: { |
| 884 | SDOperand Ops[] = { DAG.getConstant(0, VT), Tmp1 }; |
| 885 | Result = DAG.getNode(ISD::MERGE_VALUES, DAG.getVTList(VT, MVT::Other), |
Duncan Sands | b027fa0 | 2007-12-31 18:35:50 +0000 | [diff] [blame] | 886 | Ops, 2); |
Jim Laskey | 2bc210d | 2007-02-22 15:37:19 +0000 | [diff] [blame] | 887 | break; |
| 888 | } |
| 889 | } |
Chris Lattner | eb7f34f | 2007-04-27 17:12:52 +0000 | [diff] [blame] | 890 | } |
Duncan Sands | b027fa0 | 2007-12-31 18:35:50 +0000 | [diff] [blame] | 891 | if (Result.Val->getNumValues() == 1) break; |
| 892 | |
| 893 | assert(Result.Val->getNumValues() == 2 && |
| 894 | "Cannot return more than two values!"); |
| 895 | |
| 896 | // Since we produced two values, make sure to remember that we |
| 897 | // legalized both of them. |
| 898 | Tmp1 = LegalizeOp(Result); |
| 899 | Tmp2 = LegalizeOp(Result.getValue(1)); |
| 900 | AddLegalizedOperand(Op.getValue(0), Tmp1); |
| 901 | AddLegalizedOperand(Op.getValue(1), Tmp2); |
| 902 | return Op.ResNo ? Tmp2 : Tmp1; |
Jim Laskey | 8782d48 | 2007-02-28 20:43:58 +0000 | [diff] [blame] | 903 | case ISD::EHSELECTION: { |
| 904 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 905 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 906 | MVT::ValueType VT = Node->getValueType(0); |
| 907 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 908 | default: assert(0 && "This action is not supported yet!"); |
| 909 | case TargetLowering::Expand: { |
| 910 | unsigned Reg = TLI.getExceptionSelectorRegister(); |
Duncan Sands | b027fa0 | 2007-12-31 18:35:50 +0000 | [diff] [blame] | 911 | Result = DAG.getCopyFromReg(Tmp2, Reg, VT); |
Jim Laskey | 8782d48 | 2007-02-28 20:43:58 +0000 | [diff] [blame] | 912 | } |
| 913 | break; |
| 914 | case TargetLowering::Custom: |
| 915 | Result = TLI.LowerOperation(Op, DAG); |
| 916 | if (Result.Val) break; |
| 917 | // Fall Thru |
Chris Lattner | eb7f34f | 2007-04-27 17:12:52 +0000 | [diff] [blame] | 918 | case TargetLowering::Legal: { |
| 919 | SDOperand Ops[] = { DAG.getConstant(0, VT), Tmp2 }; |
| 920 | Result = DAG.getNode(ISD::MERGE_VALUES, DAG.getVTList(VT, MVT::Other), |
Duncan Sands | b027fa0 | 2007-12-31 18:35:50 +0000 | [diff] [blame] | 921 | Ops, 2); |
Jim Laskey | 8782d48 | 2007-02-28 20:43:58 +0000 | [diff] [blame] | 922 | break; |
| 923 | } |
| 924 | } |
Chris Lattner | eb7f34f | 2007-04-27 17:12:52 +0000 | [diff] [blame] | 925 | } |
Duncan Sands | b027fa0 | 2007-12-31 18:35:50 +0000 | [diff] [blame] | 926 | if (Result.Val->getNumValues() == 1) break; |
| 927 | |
| 928 | assert(Result.Val->getNumValues() == 2 && |
| 929 | "Cannot return more than two values!"); |
| 930 | |
| 931 | // Since we produced two values, make sure to remember that we |
| 932 | // legalized both of them. |
| 933 | Tmp1 = LegalizeOp(Result); |
| 934 | Tmp2 = LegalizeOp(Result.getValue(1)); |
| 935 | AddLegalizedOperand(Op.getValue(0), Tmp1); |
| 936 | AddLegalizedOperand(Op.getValue(1), Tmp2); |
| 937 | return Op.ResNo ? Tmp2 : Tmp1; |
Nick Lewycky | 6d4b711 | 2007-07-14 15:11:14 +0000 | [diff] [blame] | 938 | case ISD::EH_RETURN: { |
Anton Korobeynikov | 2365f51 | 2007-07-14 14:06:15 +0000 | [diff] [blame] | 939 | MVT::ValueType VT = Node->getValueType(0); |
| 940 | // The only "good" option for this node is to custom lower it. |
| 941 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 942 | default: assert(0 && "This action is not supported at all!"); |
| 943 | case TargetLowering::Custom: |
| 944 | Result = TLI.LowerOperation(Op, DAG); |
| 945 | if (Result.Val) break; |
| 946 | // Fall Thru |
| 947 | case TargetLowering::Legal: |
| 948 | // Target does not know, how to lower this, lower to noop |
| 949 | Result = LegalizeOp(Node->getOperand(0)); |
| 950 | break; |
| 951 | } |
Nick Lewycky | 6d4b711 | 2007-07-14 15:11:14 +0000 | [diff] [blame] | 952 | } |
Anton Korobeynikov | 2365f51 | 2007-07-14 14:06:15 +0000 | [diff] [blame] | 953 | break; |
Chris Lattner | 08951a3 | 2005-09-02 01:15:01 +0000 | [diff] [blame] | 954 | case ISD::AssertSext: |
| 955 | case ISD::AssertZext: |
| 956 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 957 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
Chris Lattner | 08951a3 | 2005-09-02 01:15:01 +0000 | [diff] [blame] | 958 | break; |
Chris Lattner | 308575b | 2005-11-20 22:56:56 +0000 | [diff] [blame] | 959 | case ISD::MERGE_VALUES: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 960 | // Legalize eliminates MERGE_VALUES nodes. |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 961 | Result = Node->getOperand(Op.ResNo); |
| 962 | break; |
Chris Lattner | 69a5215 | 2005-01-14 22:38:01 +0000 | [diff] [blame] | 963 | case ISD::CopyFromReg: |
| 964 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 965 | Result = Op.getValue(0); |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 966 | if (Node->getNumValues() == 2) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 967 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 968 | } else { |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 969 | assert(Node->getNumValues() == 3 && "Invalid copyfromreg!"); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 970 | if (Node->getNumOperands() == 3) { |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 971 | Tmp2 = LegalizeOp(Node->getOperand(2)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 972 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1),Tmp2); |
| 973 | } else { |
| 974 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
| 975 | } |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 976 | AddLegalizedOperand(Op.getValue(2), Result.getValue(2)); |
| 977 | } |
Chris Lattner | 13c184d | 2005-01-28 06:27:38 +0000 | [diff] [blame] | 978 | // Since CopyFromReg produces two values, make sure to remember that we |
| 979 | // legalized both of them. |
| 980 | AddLegalizedOperand(Op.getValue(0), Result); |
| 981 | AddLegalizedOperand(Op.getValue(1), Result.getValue(1)); |
| 982 | return Result.getValue(Op.ResNo); |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 983 | case ISD::UNDEF: { |
| 984 | MVT::ValueType VT = Op.getValueType(); |
| 985 | switch (TLI.getOperationAction(ISD::UNDEF, VT)) { |
Nate Begeman | ea19cd5 | 2005-04-02 00:41:14 +0000 | [diff] [blame] | 986 | default: assert(0 && "This action is not supported yet!"); |
| 987 | case TargetLowering::Expand: |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 988 | if (MVT::isInteger(VT)) |
| 989 | Result = DAG.getConstant(0, VT); |
| 990 | else if (MVT::isFloatingPoint(VT)) |
Dale Johannesen | f41db21 | 2007-09-26 17:26:49 +0000 | [diff] [blame] | 991 | Result = DAG.getConstantFP(APFloat(APInt(MVT::getSizeInBits(VT), 0)), |
| 992 | VT); |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 993 | else |
| 994 | assert(0 && "Unknown value type!"); |
| 995 | break; |
Nate Begeman | ea19cd5 | 2005-04-02 00:41:14 +0000 | [diff] [blame] | 996 | case TargetLowering::Legal: |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 997 | break; |
| 998 | } |
| 999 | break; |
| 1000 | } |
Chris Lattner | d1f04d4 | 2006-03-24 02:26:29 +0000 | [diff] [blame] | 1001 | |
Chris Lattner | 48b61a7 | 2006-03-28 00:40:33 +0000 | [diff] [blame] | 1002 | case ISD::INTRINSIC_W_CHAIN: |
| 1003 | case ISD::INTRINSIC_WO_CHAIN: |
| 1004 | case ISD::INTRINSIC_VOID: { |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1005 | SmallVector<SDOperand, 8> Ops; |
Chris Lattner | d1f04d4 | 2006-03-24 02:26:29 +0000 | [diff] [blame] | 1006 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) |
| 1007 | Ops.push_back(LegalizeOp(Node->getOperand(i))); |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1008 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 10d7fa6 | 2006-03-26 09:12:51 +0000 | [diff] [blame] | 1009 | |
| 1010 | // Allow the target to custom lower its intrinsics if it wants to. |
Chris Lattner | 48b61a7 | 2006-03-28 00:40:33 +0000 | [diff] [blame] | 1011 | if (TLI.getOperationAction(Node->getOpcode(), MVT::Other) == |
Chris Lattner | 10d7fa6 | 2006-03-26 09:12:51 +0000 | [diff] [blame] | 1012 | TargetLowering::Custom) { |
| 1013 | Tmp3 = TLI.LowerOperation(Result, DAG); |
| 1014 | if (Tmp3.Val) Result = Tmp3; |
Chris Lattner | 13fc2f1 | 2006-03-27 20:28:29 +0000 | [diff] [blame] | 1015 | } |
| 1016 | |
| 1017 | if (Result.Val->getNumValues() == 1) break; |
| 1018 | |
| 1019 | // Must have return value and chain result. |
| 1020 | assert(Result.Val->getNumValues() == 2 && |
| 1021 | "Cannot return more than two values!"); |
| 1022 | |
| 1023 | // Since loads produce two values, make sure to remember that we |
| 1024 | // legalized both of them. |
| 1025 | AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0)); |
| 1026 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
| 1027 | return Result.getValue(Op.ResNo); |
Chris Lattner | d1f04d4 | 2006-03-24 02:26:29 +0000 | [diff] [blame] | 1028 | } |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 1029 | |
| 1030 | case ISD::LOCATION: |
| 1031 | assert(Node->getNumOperands() == 5 && "Invalid LOCATION node!"); |
| 1032 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the input chain. |
| 1033 | |
| 1034 | switch (TLI.getOperationAction(ISD::LOCATION, MVT::Other)) { |
| 1035 | case TargetLowering::Promote: |
| 1036 | default: assert(0 && "This action is not supported yet!"); |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 1037 | case TargetLowering::Expand: { |
Jim Laskey | 44c3b9f | 2007-01-26 21:22:28 +0000 | [diff] [blame] | 1038 | MachineModuleInfo *MMI = DAG.getMachineModuleInfo(); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1039 | bool useDEBUG_LOC = TLI.isOperationLegal(ISD::DEBUG_LOC, MVT::Other); |
Jim Laskey | 1ee2925 | 2007-01-26 14:34:52 +0000 | [diff] [blame] | 1040 | bool useLABEL = TLI.isOperationLegal(ISD::LABEL, MVT::Other); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1041 | |
Jim Laskey | 44c3b9f | 2007-01-26 21:22:28 +0000 | [diff] [blame] | 1042 | if (MMI && (useDEBUG_LOC || useLABEL)) { |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1043 | const std::string &FName = |
| 1044 | cast<StringSDNode>(Node->getOperand(3))->getValue(); |
| 1045 | const std::string &DirName = |
| 1046 | cast<StringSDNode>(Node->getOperand(4))->getValue(); |
Jim Laskey | 44c3b9f | 2007-01-26 21:22:28 +0000 | [diff] [blame] | 1047 | unsigned SrcFile = MMI->RecordSource(DirName, FName); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1048 | |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 1049 | SmallVector<SDOperand, 8> Ops; |
Jim Laskey | e81aecb | 2005-12-21 20:51:37 +0000 | [diff] [blame] | 1050 | Ops.push_back(Tmp1); // chain |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1051 | SDOperand LineOp = Node->getOperand(1); |
| 1052 | SDOperand ColOp = Node->getOperand(2); |
| 1053 | |
| 1054 | if (useDEBUG_LOC) { |
| 1055 | Ops.push_back(LineOp); // line # |
| 1056 | Ops.push_back(ColOp); // col # |
| 1057 | Ops.push_back(DAG.getConstant(SrcFile, MVT::i32)); // source file id |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 1058 | Result = DAG.getNode(ISD::DEBUG_LOC, MVT::Other, &Ops[0], Ops.size()); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1059 | } else { |
Jim Laskey | d0e58e3 | 2006-02-15 19:34:44 +0000 | [diff] [blame] | 1060 | unsigned Line = cast<ConstantSDNode>(LineOp)->getValue(); |
| 1061 | unsigned Col = cast<ConstantSDNode>(ColOp)->getValue(); |
Evan Cheng | a647c92 | 2008-02-01 02:05:57 +0000 | [diff] [blame] | 1062 | unsigned ID = MMI->RecordSourceLine(Line, Col, SrcFile); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1063 | Ops.push_back(DAG.getConstant(ID, MVT::i32)); |
Evan Cheng | bb81d97 | 2008-01-31 09:59:15 +0000 | [diff] [blame] | 1064 | Ops.push_back(DAG.getConstant(0, MVT::i32)); // a debug label |
| 1065 | Result = DAG.getNode(ISD::LABEL, MVT::Other, &Ops[0], Ops.size()); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1066 | } |
Jim Laskey | e81aecb | 2005-12-21 20:51:37 +0000 | [diff] [blame] | 1067 | } else { |
| 1068 | Result = Tmp1; // chain |
| 1069 | } |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 1070 | break; |
Chris Lattner | e773673 | 2005-12-18 23:54:29 +0000 | [diff] [blame] | 1071 | } |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 1072 | case TargetLowering::Legal: |
Chris Lattner | 9ad17c9 | 2005-12-01 18:21:35 +0000 | [diff] [blame] | 1073 | if (Tmp1 != Node->getOperand(0) || |
| 1074 | getTypeAction(Node->getOperand(1).getValueType()) == Promote) { |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1075 | SmallVector<SDOperand, 8> Ops; |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 1076 | Ops.push_back(Tmp1); |
Chris Lattner | 9ad17c9 | 2005-12-01 18:21:35 +0000 | [diff] [blame] | 1077 | if (getTypeAction(Node->getOperand(1).getValueType()) == Legal) { |
| 1078 | Ops.push_back(Node->getOperand(1)); // line # must be legal. |
| 1079 | Ops.push_back(Node->getOperand(2)); // col # must be legal. |
| 1080 | } else { |
| 1081 | // Otherwise promote them. |
| 1082 | Ops.push_back(PromoteOp(Node->getOperand(1))); |
| 1083 | Ops.push_back(PromoteOp(Node->getOperand(2))); |
| 1084 | } |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 1085 | Ops.push_back(Node->getOperand(3)); // filename must be legal. |
| 1086 | Ops.push_back(Node->getOperand(4)); // working dir # must be legal. |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1087 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 1088 | } |
| 1089 | break; |
| 1090 | } |
| 1091 | break; |
Evan Cheng | a844bde | 2008-02-02 04:07:54 +0000 | [diff] [blame] | 1092 | |
| 1093 | case ISD::DECLARE: |
| 1094 | assert(Node->getNumOperands() == 3 && "Invalid DECLARE node!"); |
| 1095 | switch (TLI.getOperationAction(ISD::DECLARE, MVT::Other)) { |
| 1096 | default: assert(0 && "This action is not supported yet!"); |
| 1097 | case TargetLowering::Legal: |
| 1098 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1099 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the address. |
| 1100 | Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the variable. |
| 1101 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
| 1102 | break; |
| 1103 | } |
| 1104 | break; |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 1105 | |
| 1106 | case ISD::DEBUG_LOC: |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1107 | assert(Node->getNumOperands() == 4 && "Invalid DEBUG_LOC node!"); |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 1108 | switch (TLI.getOperationAction(ISD::DEBUG_LOC, MVT::Other)) { |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 1109 | default: assert(0 && "This action is not supported yet!"); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1110 | case TargetLowering::Legal: |
| 1111 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1112 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the line #. |
| 1113 | Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the col #. |
| 1114 | Tmp4 = LegalizeOp(Node->getOperand(3)); // Legalize the source file id. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1115 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3, Tmp4); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1116 | break; |
| 1117 | } |
| 1118 | break; |
| 1119 | |
Jim Laskey | 1ee2925 | 2007-01-26 14:34:52 +0000 | [diff] [blame] | 1120 | case ISD::LABEL: |
Evan Cheng | bb81d97 | 2008-01-31 09:59:15 +0000 | [diff] [blame] | 1121 | assert(Node->getNumOperands() == 3 && "Invalid LABEL node!"); |
Jim Laskey | 1ee2925 | 2007-01-26 14:34:52 +0000 | [diff] [blame] | 1122 | switch (TLI.getOperationAction(ISD::LABEL, MVT::Other)) { |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1123 | default: assert(0 && "This action is not supported yet!"); |
| 1124 | case TargetLowering::Legal: |
| 1125 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1126 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the label id. |
Evan Cheng | bb81d97 | 2008-01-31 09:59:15 +0000 | [diff] [blame] | 1127 | Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the "flavor" operand. |
| 1128 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 1129 | break; |
Chris Lattner | a9569f1 | 2007-03-03 19:21:38 +0000 | [diff] [blame] | 1130 | case TargetLowering::Expand: |
| 1131 | Result = LegalizeOp(Node->getOperand(0)); |
| 1132 | break; |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 1133 | } |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 1134 | break; |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 1135 | |
Andrew Lenharth | 22c5c1b | 2008-02-16 01:24:58 +0000 | [diff] [blame] | 1136 | case ISD::MEMBARRIER: { |
| 1137 | assert(Node->getNumOperands() == 6 && "Invalid MemBarrier node!"); |
Andrew Lenharth | d497d9f | 2008-02-16 14:46:26 +0000 | [diff] [blame] | 1138 | switch (TLI.getOperationAction(ISD::MEMBARRIER, MVT::Other)) { |
| 1139 | default: assert(0 && "This action is not supported yet!"); |
| 1140 | case TargetLowering::Legal: { |
| 1141 | SDOperand Ops[6]; |
| 1142 | Ops[0] = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1143 | for (int x = 1; x < 6; ++x) |
| 1144 | Ops[x] = PromoteOp(Node->getOperand(x)); |
| 1145 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], 6); |
| 1146 | break; |
| 1147 | } |
| 1148 | case TargetLowering::Expand: |
| 1149 | //There is no libgcc call for this op |
| 1150 | Result = Node->getOperand(0); // Noop |
| 1151 | break; |
| 1152 | } |
Andrew Lenharth | 22c5c1b | 2008-02-16 01:24:58 +0000 | [diff] [blame] | 1153 | break; |
| 1154 | } |
| 1155 | |
Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 1156 | case ISD::ATOMIC_LCS: |
| 1157 | case ISD::ATOMIC_LAS: |
| 1158 | case ISD::ATOMIC_SWAP: { |
| 1159 | assert(((Node->getNumOperands() == 4 && Node->getOpcode() == ISD::ATOMIC_LCS) || |
| 1160 | (Node->getNumOperands() == 3 && Node->getOpcode() == ISD::ATOMIC_LAS) || |
| 1161 | (Node->getNumOperands() == 3 && Node->getOpcode() == ISD::ATOMIC_SWAP)) && |
| 1162 | "Invalid MemBarrier node!"); |
| 1163 | int num = Node->getOpcode() == ISD::ATOMIC_LCS ? 4 : 3; |
| 1164 | MVT::ValueType VT = Node->getValueType(0); |
| 1165 | switch (TLI.getOperationAction(ISD::ATOMIC_LCS, VT)) { |
| 1166 | default: assert(0 && "This action is not supported yet!"); |
| 1167 | case TargetLowering::Legal: { |
| 1168 | SDOperand Ops[4]; |
| 1169 | for (int x = 0; x < num; ++x) |
| 1170 | Ops[x] = LegalizeOp(Node->getOperand(x)); |
| 1171 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], num); |
| 1172 | AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0)); |
| 1173 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
| 1174 | return Result.getValue(Op.ResNo); |
| 1175 | break; |
| 1176 | } |
| 1177 | } |
| 1178 | break; |
| 1179 | } |
| 1180 | |
Scott Michel | c1513d2 | 2007-08-08 23:23:31 +0000 | [diff] [blame] | 1181 | case ISD::Constant: { |
| 1182 | ConstantSDNode *CN = cast<ConstantSDNode>(Node); |
| 1183 | unsigned opAction = |
| 1184 | TLI.getOperationAction(ISD::Constant, CN->getValueType(0)); |
| 1185 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1186 | // We know we don't need to expand constants here, constants only have one |
| 1187 | // value and we check that it is fine above. |
| 1188 | |
Scott Michel | c1513d2 | 2007-08-08 23:23:31 +0000 | [diff] [blame] | 1189 | if (opAction == TargetLowering::Custom) { |
| 1190 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 1191 | if (Tmp1.Val) |
| 1192 | Result = Tmp1; |
| 1193 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1194 | break; |
Scott Michel | c1513d2 | 2007-08-08 23:23:31 +0000 | [diff] [blame] | 1195 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1196 | case ISD::ConstantFP: { |
| 1197 | // Spill FP immediates to the constant pool if the target cannot directly |
| 1198 | // codegen them. Targets often have some immediate values that can be |
| 1199 | // efficiently generated into an FP register without a load. We explicitly |
| 1200 | // leave these constants as ConstantFP nodes for the target to deal with. |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1201 | ConstantFPSDNode *CFP = cast<ConstantFPSDNode>(Node); |
| 1202 | |
Chris Lattner | 3181a77 | 2006-01-29 06:26:56 +0000 | [diff] [blame] | 1203 | switch (TLI.getOperationAction(ISD::ConstantFP, CFP->getValueType(0))) { |
| 1204 | default: assert(0 && "This action is not supported yet!"); |
Nate Begeman | e179584 | 2008-02-14 08:57:00 +0000 | [diff] [blame] | 1205 | case TargetLowering::Legal: |
| 1206 | break; |
Chris Lattner | 3181a77 | 2006-01-29 06:26:56 +0000 | [diff] [blame] | 1207 | case TargetLowering::Custom: |
| 1208 | Tmp3 = TLI.LowerOperation(Result, DAG); |
| 1209 | if (Tmp3.Val) { |
| 1210 | Result = Tmp3; |
| 1211 | break; |
| 1212 | } |
| 1213 | // FALLTHROUGH |
Nate Begeman | e179584 | 2008-02-14 08:57:00 +0000 | [diff] [blame] | 1214 | case TargetLowering::Expand: { |
| 1215 | // Check to see if this FP immediate is already legal. |
| 1216 | bool isLegal = false; |
| 1217 | for (TargetLowering::legal_fpimm_iterator I = TLI.legal_fpimm_begin(), |
| 1218 | E = TLI.legal_fpimm_end(); I != E; ++I) { |
| 1219 | if (CFP->isExactlyValue(*I)) { |
| 1220 | isLegal = true; |
| 1221 | break; |
| 1222 | } |
| 1223 | } |
| 1224 | // If this is a legal constant, turn it into a TargetConstantFP node. |
| 1225 | if (isLegal) |
| 1226 | break; |
Evan Cheng | 279101e | 2006-12-12 22:19:28 +0000 | [diff] [blame] | 1227 | Result = ExpandConstantFP(CFP, true, DAG, TLI); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1228 | } |
Nate Begeman | e179584 | 2008-02-14 08:57:00 +0000 | [diff] [blame] | 1229 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1230 | break; |
| 1231 | } |
Chris Lattner | 040c11c | 2005-11-09 18:48:57 +0000 | [diff] [blame] | 1232 | case ISD::TokenFactor: |
| 1233 | if (Node->getNumOperands() == 2) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1234 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1235 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1236 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 1237 | } else if (Node->getNumOperands() == 3) { |
| 1238 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1239 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1240 | Tmp3 = LegalizeOp(Node->getOperand(2)); |
| 1241 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | 040c11c | 2005-11-09 18:48:57 +0000 | [diff] [blame] | 1242 | } else { |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1243 | SmallVector<SDOperand, 8> Ops; |
Chris Lattner | 040c11c | 2005-11-09 18:48:57 +0000 | [diff] [blame] | 1244 | // Legalize the operands. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1245 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) |
| 1246 | Ops.push_back(LegalizeOp(Node->getOperand(i))); |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1247 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | a385e9b | 2005-01-13 17:59:25 +0000 | [diff] [blame] | 1248 | } |
Chris Lattner | a385e9b | 2005-01-13 17:59:25 +0000 | [diff] [blame] | 1249 | break; |
Chris Lattner | fdfded5 | 2006-04-12 16:20:43 +0000 | [diff] [blame] | 1250 | |
| 1251 | case ISD::FORMAL_ARGUMENTS: |
Chris Lattner | f4ec817 | 2006-05-16 22:53:20 +0000 | [diff] [blame] | 1252 | case ISD::CALL: |
Chris Lattner | fdfded5 | 2006-04-12 16:20:43 +0000 | [diff] [blame] | 1253 | // The only option for this is to custom lower it. |
Chris Lattner | b248e16 | 2006-05-17 17:55:45 +0000 | [diff] [blame] | 1254 | Tmp3 = TLI.LowerOperation(Result.getValue(0), DAG); |
| 1255 | assert(Tmp3.Val && "Target didn't custom lower this node!"); |
Bill Wendling | 0f8d9c0 | 2007-11-13 00:44:25 +0000 | [diff] [blame] | 1256 | |
| 1257 | // The number of incoming and outgoing values should match; unless the final |
| 1258 | // outgoing value is a flag. |
| 1259 | assert((Tmp3.Val->getNumValues() == Result.Val->getNumValues() || |
| 1260 | (Tmp3.Val->getNumValues() == Result.Val->getNumValues() + 1 && |
| 1261 | Tmp3.Val->getValueType(Tmp3.Val->getNumValues() - 1) == |
| 1262 | MVT::Flag)) && |
Chris Lattner | b248e16 | 2006-05-17 17:55:45 +0000 | [diff] [blame] | 1263 | "Lowering call/formal_arguments produced unexpected # results!"); |
Chris Lattner | e2e4173 | 2006-05-16 05:49:56 +0000 | [diff] [blame] | 1264 | |
Chris Lattner | f4ec817 | 2006-05-16 22:53:20 +0000 | [diff] [blame] | 1265 | // Since CALL/FORMAL_ARGUMENTS nodes produce multiple values, make sure to |
Chris Lattner | e2e4173 | 2006-05-16 05:49:56 +0000 | [diff] [blame] | 1266 | // 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] | 1267 | for (unsigned i = 0, e = Tmp3.Val->getNumValues(); i != e; ++i) { |
Bill Wendling | 0f8d9c0 | 2007-11-13 00:44:25 +0000 | [diff] [blame] | 1268 | if (Tmp3.Val->getValueType(i) == MVT::Flag) |
| 1269 | continue; |
Chris Lattner | b248e16 | 2006-05-17 17:55:45 +0000 | [diff] [blame] | 1270 | Tmp1 = LegalizeOp(Tmp3.getValue(i)); |
Chris Lattner | e2e4173 | 2006-05-16 05:49:56 +0000 | [diff] [blame] | 1271 | if (Op.ResNo == i) |
| 1272 | Tmp2 = Tmp1; |
| 1273 | AddLegalizedOperand(SDOperand(Node, i), Tmp1); |
| 1274 | } |
| 1275 | return Tmp2; |
Christopher Lamb | 557c363 | 2007-07-26 07:34:40 +0000 | [diff] [blame] | 1276 | case ISD::EXTRACT_SUBREG: { |
| 1277 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1278 | ConstantSDNode *idx = dyn_cast<ConstantSDNode>(Node->getOperand(1)); |
| 1279 | assert(idx && "Operand must be a constant"); |
| 1280 | Tmp2 = DAG.getTargetConstant(idx->getValue(), idx->getValueType(0)); |
| 1281 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 1282 | } |
| 1283 | break; |
| 1284 | case ISD::INSERT_SUBREG: { |
| 1285 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1286 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1287 | ConstantSDNode *idx = dyn_cast<ConstantSDNode>(Node->getOperand(2)); |
| 1288 | assert(idx && "Operand must be a constant"); |
| 1289 | Tmp3 = DAG.getTargetConstant(idx->getValue(), idx->getValueType(0)); |
| 1290 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
| 1291 | } |
| 1292 | break; |
Chris Lattner | b2827b0 | 2006-03-19 00:52:58 +0000 | [diff] [blame] | 1293 | case ISD::BUILD_VECTOR: |
| 1294 | switch (TLI.getOperationAction(ISD::BUILD_VECTOR, Node->getValueType(0))) { |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1295 | default: assert(0 && "This action is not supported yet!"); |
| 1296 | case TargetLowering::Custom: |
| 1297 | Tmp3 = TLI.LowerOperation(Result, DAG); |
| 1298 | if (Tmp3.Val) { |
| 1299 | Result = Tmp3; |
| 1300 | break; |
| 1301 | } |
| 1302 | // FALLTHROUGH |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 1303 | case TargetLowering::Expand: |
| 1304 | Result = ExpandBUILD_VECTOR(Result.Val); |
Chris Lattner | b2827b0 | 2006-03-19 00:52:58 +0000 | [diff] [blame] | 1305 | break; |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1306 | } |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1307 | break; |
| 1308 | case ISD::INSERT_VECTOR_ELT: |
| 1309 | Tmp1 = LegalizeOp(Node->getOperand(0)); // InVec |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1310 | Tmp3 = LegalizeOp(Node->getOperand(2)); // InEltNo |
Nate Begeman | 0325d90 | 2008-02-13 06:43:04 +0000 | [diff] [blame] | 1311 | |
| 1312 | // The type of the value to insert may not be legal, even though the vector |
| 1313 | // type is legal. Legalize/Promote accordingly. We do not handle Expand |
| 1314 | // here. |
| 1315 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 1316 | default: assert(0 && "Cannot expand insert element operand"); |
| 1317 | case Legal: Tmp2 = LegalizeOp(Node->getOperand(1)); break; |
| 1318 | case Promote: Tmp2 = PromoteOp(Node->getOperand(1)); break; |
| 1319 | } |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1320 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
| 1321 | |
| 1322 | switch (TLI.getOperationAction(ISD::INSERT_VECTOR_ELT, |
| 1323 | Node->getValueType(0))) { |
| 1324 | default: assert(0 && "This action is not supported yet!"); |
| 1325 | case TargetLowering::Legal: |
| 1326 | break; |
| 1327 | case TargetLowering::Custom: |
Nate Begeman | 2281a99 | 2008-01-05 20:47:37 +0000 | [diff] [blame] | 1328 | Tmp4 = TLI.LowerOperation(Result, DAG); |
| 1329 | if (Tmp4.Val) { |
| 1330 | Result = Tmp4; |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1331 | break; |
| 1332 | } |
| 1333 | // FALLTHROUGH |
| 1334 | case TargetLowering::Expand: { |
Chris Lattner | 8d5a894 | 2006-04-17 19:21:01 +0000 | [diff] [blame] | 1335 | // If the insert index is a constant, codegen this as a scalar_to_vector, |
| 1336 | // then a shuffle that inserts it into the right position in the vector. |
| 1337 | if (ConstantSDNode *InsertPos = dyn_cast<ConstantSDNode>(Tmp3)) { |
Nate Begeman | 0325d90 | 2008-02-13 06:43:04 +0000 | [diff] [blame] | 1338 | // SCALAR_TO_VECTOR requires that the type of the value being inserted |
| 1339 | // match the element type of the vector being created. |
| 1340 | if (Tmp2.getValueType() == |
| 1341 | MVT::getVectorElementType(Op.getValueType())) { |
| 1342 | SDOperand ScVec = DAG.getNode(ISD::SCALAR_TO_VECTOR, |
| 1343 | Tmp1.getValueType(), Tmp2); |
| 1344 | |
| 1345 | unsigned NumElts = MVT::getVectorNumElements(Tmp1.getValueType()); |
| 1346 | MVT::ValueType ShufMaskVT = MVT::getIntVectorWithNumElements(NumElts); |
| 1347 | MVT::ValueType ShufMaskEltVT = MVT::getVectorElementType(ShufMaskVT); |
| 1348 | |
| 1349 | // We generate a shuffle of InVec and ScVec, so the shuffle mask |
| 1350 | // should be 0,1,2,3,4,5... with the appropriate element replaced with |
| 1351 | // elt 0 of the RHS. |
| 1352 | SmallVector<SDOperand, 8> ShufOps; |
| 1353 | for (unsigned i = 0; i != NumElts; ++i) { |
| 1354 | if (i != InsertPos->getValue()) |
| 1355 | ShufOps.push_back(DAG.getConstant(i, ShufMaskEltVT)); |
| 1356 | else |
| 1357 | ShufOps.push_back(DAG.getConstant(NumElts, ShufMaskEltVT)); |
| 1358 | } |
| 1359 | SDOperand ShufMask = DAG.getNode(ISD::BUILD_VECTOR, ShufMaskVT, |
| 1360 | &ShufOps[0], ShufOps.size()); |
| 1361 | |
| 1362 | Result = DAG.getNode(ISD::VECTOR_SHUFFLE, Tmp1.getValueType(), |
| 1363 | Tmp1, ScVec, ShufMask); |
| 1364 | Result = LegalizeOp(Result); |
| 1365 | break; |
Chris Lattner | 8d5a894 | 2006-04-17 19:21:01 +0000 | [diff] [blame] | 1366 | } |
Chris Lattner | 8d5a894 | 2006-04-17 19:21:01 +0000 | [diff] [blame] | 1367 | } |
| 1368 | |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1369 | // If the target doesn't support this, we have to spill the input vector |
| 1370 | // to a temporary stack slot, update the element, then reload it. This is |
| 1371 | // badness. We could also load the value into a vector register (either |
| 1372 | // with a "move to register" or "extload into register" instruction, then |
| 1373 | // permute it into place, if the idx is a constant and if the idx is |
| 1374 | // supported by the target. |
Evan Cheng | f6bf87f | 2006-04-08 01:46:37 +0000 | [diff] [blame] | 1375 | MVT::ValueType VT = Tmp1.getValueType(); |
Nate Begeman | 0325d90 | 2008-02-13 06:43:04 +0000 | [diff] [blame] | 1376 | MVT::ValueType EltVT = MVT::getVectorElementType(VT); |
Evan Cheng | f6bf87f | 2006-04-08 01:46:37 +0000 | [diff] [blame] | 1377 | MVT::ValueType IdxVT = Tmp3.getValueType(); |
| 1378 | MVT::ValueType PtrVT = TLI.getPointerTy(); |
Chris Lattner | 85dd3be | 2007-10-15 17:48:57 +0000 | [diff] [blame] | 1379 | SDOperand StackPtr = DAG.CreateStackTemporary(VT); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 1380 | |
Dan Gohman | bbbbb9c | 2008-02-11 18:58:42 +0000 | [diff] [blame] | 1381 | FrameIndexSDNode *StackPtrFI = cast<FrameIndexSDNode>(StackPtr.Val); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 1382 | int SPFI = StackPtrFI->getIndex(); |
| 1383 | |
Evan Cheng | eb0b461 | 2006-03-31 01:27:51 +0000 | [diff] [blame] | 1384 | // Store the vector. |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 1385 | SDOperand Ch = DAG.getStore(DAG.getEntryNode(), Tmp1, StackPtr, |
Dan Gohman | 3069b87 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 1386 | PseudoSourceValue::getFixedStack(), |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 1387 | SPFI); |
Evan Cheng | eb0b461 | 2006-03-31 01:27:51 +0000 | [diff] [blame] | 1388 | |
| 1389 | // Truncate or zero extend offset to target pointer type. |
Evan Cheng | f6bf87f | 2006-04-08 01:46:37 +0000 | [diff] [blame] | 1390 | unsigned CastOpc = (IdxVT > PtrVT) ? ISD::TRUNCATE : ISD::ZERO_EXTEND; |
| 1391 | Tmp3 = DAG.getNode(CastOpc, PtrVT, Tmp3); |
Evan Cheng | eb0b461 | 2006-03-31 01:27:51 +0000 | [diff] [blame] | 1392 | // Add the offset to the index. |
Evan Cheng | f6bf87f | 2006-04-08 01:46:37 +0000 | [diff] [blame] | 1393 | unsigned EltSize = MVT::getSizeInBits(EltVT)/8; |
| 1394 | Tmp3 = DAG.getNode(ISD::MUL, IdxVT, Tmp3,DAG.getConstant(EltSize, IdxVT)); |
| 1395 | SDOperand StackPtr2 = DAG.getNode(ISD::ADD, IdxVT, Tmp3, StackPtr); |
Evan Cheng | eb0b461 | 2006-03-31 01:27:51 +0000 | [diff] [blame] | 1396 | // Store the scalar value. |
Nate Begeman | 0325d90 | 2008-02-13 06:43:04 +0000 | [diff] [blame] | 1397 | Ch = DAG.getTruncStore(Ch, Tmp2, StackPtr2, |
| 1398 | PseudoSourceValue::getFixedStack(), SPFI, EltVT); |
Evan Cheng | eb0b461 | 2006-03-31 01:27:51 +0000 | [diff] [blame] | 1399 | // Load the updated vector. |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 1400 | Result = DAG.getLoad(VT, Ch, StackPtr, |
Dan Gohman | 3069b87 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 1401 | PseudoSourceValue::getFixedStack(), SPFI); |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1402 | break; |
| 1403 | } |
| 1404 | } |
| 1405 | break; |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 1406 | case ISD::SCALAR_TO_VECTOR: |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 1407 | if (!TLI.isTypeLegal(Node->getOperand(0).getValueType())) { |
| 1408 | Result = LegalizeOp(ExpandSCALAR_TO_VECTOR(Node)); |
| 1409 | break; |
| 1410 | } |
| 1411 | |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 1412 | Tmp1 = LegalizeOp(Node->getOperand(0)); // InVal |
| 1413 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 1414 | switch (TLI.getOperationAction(ISD::SCALAR_TO_VECTOR, |
| 1415 | Node->getValueType(0))) { |
| 1416 | default: assert(0 && "This action is not supported yet!"); |
| 1417 | case TargetLowering::Legal: |
| 1418 | break; |
Chris Lattner | 4d3abee | 2006-03-19 06:47:21 +0000 | [diff] [blame] | 1419 | case TargetLowering::Custom: |
| 1420 | Tmp3 = TLI.LowerOperation(Result, DAG); |
| 1421 | if (Tmp3.Val) { |
| 1422 | Result = Tmp3; |
| 1423 | break; |
| 1424 | } |
| 1425 | // FALLTHROUGH |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 1426 | case TargetLowering::Expand: |
| 1427 | Result = LegalizeOp(ExpandSCALAR_TO_VECTOR(Node)); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 1428 | break; |
| 1429 | } |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 1430 | break; |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 1431 | case ISD::VECTOR_SHUFFLE: |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 1432 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the input vectors, |
| 1433 | Tmp2 = LegalizeOp(Node->getOperand(1)); // but not the shuffle mask. |
| 1434 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
| 1435 | |
| 1436 | // Allow targets to custom lower the SHUFFLEs they support. |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 1437 | switch (TLI.getOperationAction(ISD::VECTOR_SHUFFLE,Result.getValueType())) { |
| 1438 | default: assert(0 && "Unknown operation action!"); |
| 1439 | case TargetLowering::Legal: |
| 1440 | assert(isShuffleLegal(Result.getValueType(), Node->getOperand(2)) && |
| 1441 | "vector shuffle should not be created if not legal!"); |
| 1442 | break; |
| 1443 | case TargetLowering::Custom: |
Evan Cheng | 18dd6d0 | 2006-04-05 06:07:11 +0000 | [diff] [blame] | 1444 | Tmp3 = TLI.LowerOperation(Result, DAG); |
| 1445 | if (Tmp3.Val) { |
| 1446 | Result = Tmp3; |
| 1447 | break; |
| 1448 | } |
| 1449 | // FALLTHROUGH |
| 1450 | case TargetLowering::Expand: { |
| 1451 | MVT::ValueType VT = Node->getValueType(0); |
Dan Gohman | 51eaa86 | 2007-06-14 22:58:02 +0000 | [diff] [blame] | 1452 | MVT::ValueType EltVT = MVT::getVectorElementType(VT); |
Evan Cheng | 18dd6d0 | 2006-04-05 06:07:11 +0000 | [diff] [blame] | 1453 | MVT::ValueType PtrVT = TLI.getPointerTy(); |
| 1454 | SDOperand Mask = Node->getOperand(2); |
| 1455 | unsigned NumElems = Mask.getNumOperands(); |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 1456 | SmallVector<SDOperand,8> Ops; |
Evan Cheng | 18dd6d0 | 2006-04-05 06:07:11 +0000 | [diff] [blame] | 1457 | for (unsigned i = 0; i != NumElems; ++i) { |
| 1458 | SDOperand Arg = Mask.getOperand(i); |
| 1459 | if (Arg.getOpcode() == ISD::UNDEF) { |
| 1460 | Ops.push_back(DAG.getNode(ISD::UNDEF, EltVT)); |
| 1461 | } else { |
| 1462 | assert(isa<ConstantSDNode>(Arg) && "Invalid VECTOR_SHUFFLE mask!"); |
| 1463 | unsigned Idx = cast<ConstantSDNode>(Arg)->getValue(); |
| 1464 | if (Idx < NumElems) |
| 1465 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, EltVT, Tmp1, |
| 1466 | DAG.getConstant(Idx, PtrVT))); |
| 1467 | else |
| 1468 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, EltVT, Tmp2, |
| 1469 | DAG.getConstant(Idx - NumElems, PtrVT))); |
| 1470 | } |
| 1471 | } |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 1472 | Result = DAG.getNode(ISD::BUILD_VECTOR, VT, &Ops[0], Ops.size()); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 1473 | break; |
Evan Cheng | 18dd6d0 | 2006-04-05 06:07:11 +0000 | [diff] [blame] | 1474 | } |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 1475 | case TargetLowering::Promote: { |
| 1476 | // Change base type to a different vector type. |
| 1477 | MVT::ValueType OVT = Node->getValueType(0); |
| 1478 | MVT::ValueType NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT); |
| 1479 | |
| 1480 | // Cast the two input vectors. |
| 1481 | Tmp1 = DAG.getNode(ISD::BIT_CONVERT, NVT, Tmp1); |
| 1482 | Tmp2 = DAG.getNode(ISD::BIT_CONVERT, NVT, Tmp2); |
| 1483 | |
| 1484 | // Convert the shuffle mask to the right # elements. |
| 1485 | Tmp3 = SDOperand(isShuffleLegal(OVT, Node->getOperand(2)), 0); |
| 1486 | assert(Tmp3.Val && "Shuffle not legal?"); |
| 1487 | Result = DAG.getNode(ISD::VECTOR_SHUFFLE, NVT, Tmp1, Tmp2, Tmp3); |
| 1488 | Result = DAG.getNode(ISD::BIT_CONVERT, OVT, Result); |
| 1489 | break; |
| 1490 | } |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 1491 | } |
| 1492 | break; |
Chris Lattner | 384504c | 2006-03-21 20:44:12 +0000 | [diff] [blame] | 1493 | |
| 1494 | case ISD::EXTRACT_VECTOR_ELT: |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 1495 | Tmp1 = Node->getOperand(0); |
Chris Lattner | 384504c | 2006-03-21 20:44:12 +0000 | [diff] [blame] | 1496 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1497 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 1498 | Result = ExpandEXTRACT_VECTOR_ELT(Result); |
Chris Lattner | 384504c | 2006-03-21 20:44:12 +0000 | [diff] [blame] | 1499 | break; |
| 1500 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 1501 | case ISD::EXTRACT_SUBVECTOR: |
| 1502 | Tmp1 = Node->getOperand(0); |
| 1503 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1504 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 1505 | Result = ExpandEXTRACT_SUBVECTOR(Result); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 1506 | break; |
| 1507 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1508 | case ISD::CALLSEQ_START: { |
| 1509 | SDNode *CallEnd = FindCallEndFromCallStart(Node); |
| 1510 | |
| 1511 | // Recursively Legalize all of the inputs of the call end that do not lead |
| 1512 | // to this call start. This ensures that any libcalls that need be inserted |
| 1513 | // are inserted *before* the CALLSEQ_START. |
Chris Lattner | 00755df | 2007-02-04 00:27:56 +0000 | [diff] [blame] | 1514 | {SmallPtrSet<SDNode*, 32> NodesLeadingTo; |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1515 | for (unsigned i = 0, e = CallEnd->getNumOperands(); i != e; ++i) |
Chris Lattner | c9cf4f1 | 2006-07-26 23:55:56 +0000 | [diff] [blame] | 1516 | LegalizeAllNodesNotLeadingTo(CallEnd->getOperand(i).Val, Node, |
| 1517 | NodesLeadingTo); |
| 1518 | } |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1519 | |
| 1520 | // Now that we legalized all of the inputs (which may have inserted |
| 1521 | // libcalls) create the new CALLSEQ_START node. |
| 1522 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1523 | |
| 1524 | // Merge in the last call, to ensure that this call start after the last |
| 1525 | // call ended. |
Chris Lattner | c5d7d7c | 2006-05-17 18:00:08 +0000 | [diff] [blame] | 1526 | if (LastCALLSEQ_END.getOpcode() != ISD::EntryToken) { |
Chris Lattner | b248e16 | 2006-05-17 17:55:45 +0000 | [diff] [blame] | 1527 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1528 | Tmp1 = LegalizeOp(Tmp1); |
| 1529 | } |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1530 | |
| 1531 | // Do not try to legalize the target-specific arguments (#1+). |
| 1532 | if (Tmp1 != Node->getOperand(0)) { |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1533 | SmallVector<SDOperand, 8> Ops(Node->op_begin(), Node->op_end()); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1534 | Ops[0] = Tmp1; |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1535 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1536 | } |
| 1537 | |
| 1538 | // Remember that the CALLSEQ_START is legalized. |
Chris Lattner | 4b653a0 | 2006-02-14 00:55:02 +0000 | [diff] [blame] | 1539 | AddLegalizedOperand(Op.getValue(0), Result); |
| 1540 | if (Node->getNumValues() == 2) // If this has a flag result, remember it. |
| 1541 | AddLegalizedOperand(Op.getValue(1), Result.getValue(1)); |
| 1542 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1543 | // Now that the callseq_start and all of the non-call nodes above this call |
| 1544 | // sequence have been legalized, legalize the call itself. During this |
| 1545 | // process, no libcalls can/will be inserted, guaranteeing that no calls |
| 1546 | // can overlap. |
| 1547 | assert(!IsLegalizingCall && "Inconsistent sequentialization of calls!"); |
| 1548 | SDOperand InCallSEQ = LastCALLSEQ_END; |
| 1549 | // Note that we are selecting this call! |
| 1550 | LastCALLSEQ_END = SDOperand(CallEnd, 0); |
| 1551 | IsLegalizingCall = true; |
| 1552 | |
| 1553 | // Legalize the call, starting from the CALLSEQ_END. |
| 1554 | LegalizeOp(LastCALLSEQ_END); |
| 1555 | assert(!IsLegalizingCall && "CALLSEQ_END should have cleared this!"); |
| 1556 | return Result; |
| 1557 | } |
Chris Lattner | 16cd04d | 2005-05-12 23:24:06 +0000 | [diff] [blame] | 1558 | case ISD::CALLSEQ_END: |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1559 | // If the CALLSEQ_START node hasn't been legalized first, legalize it. This |
| 1560 | // will cause this node to be legalized as well as handling libcalls right. |
| 1561 | if (LastCALLSEQ_END.Val != Node) { |
| 1562 | LegalizeOp(SDOperand(FindCallStartFromCallEnd(Node), 0)); |
Chris Lattner | 718071c | 2007-02-04 00:50:02 +0000 | [diff] [blame] | 1563 | DenseMap<SDOperand, SDOperand>::iterator I = LegalizedNodes.find(Op); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1564 | assert(I != LegalizedNodes.end() && |
| 1565 | "Legalizing the call start should have legalized this node!"); |
| 1566 | return I->second; |
| 1567 | } |
| 1568 | |
| 1569 | // Otherwise, the call start has been legalized and everything is going |
| 1570 | // according to plan. Just legalize ourselves normally here. |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1571 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | 70814bc | 2006-01-29 07:58:15 +0000 | [diff] [blame] | 1572 | // Do not try to legalize the target-specific arguments (#1+), except for |
| 1573 | // an optional flag input. |
| 1574 | if (Node->getOperand(Node->getNumOperands()-1).getValueType() != MVT::Flag){ |
| 1575 | if (Tmp1 != Node->getOperand(0)) { |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1576 | SmallVector<SDOperand, 8> Ops(Node->op_begin(), Node->op_end()); |
Chris Lattner | 70814bc | 2006-01-29 07:58:15 +0000 | [diff] [blame] | 1577 | Ops[0] = Tmp1; |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1578 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 70814bc | 2006-01-29 07:58:15 +0000 | [diff] [blame] | 1579 | } |
| 1580 | } else { |
| 1581 | Tmp2 = LegalizeOp(Node->getOperand(Node->getNumOperands()-1)); |
| 1582 | if (Tmp1 != Node->getOperand(0) || |
| 1583 | Tmp2 != Node->getOperand(Node->getNumOperands()-1)) { |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1584 | SmallVector<SDOperand, 8> Ops(Node->op_begin(), Node->op_end()); |
Chris Lattner | 70814bc | 2006-01-29 07:58:15 +0000 | [diff] [blame] | 1585 | Ops[0] = Tmp1; |
| 1586 | Ops.back() = Tmp2; |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1587 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 70814bc | 2006-01-29 07:58:15 +0000 | [diff] [blame] | 1588 | } |
Chris Lattner | 6a54289 | 2006-01-24 05:48:21 +0000 | [diff] [blame] | 1589 | } |
Chris Lattner | 4b653a0 | 2006-02-14 00:55:02 +0000 | [diff] [blame] | 1590 | assert(IsLegalizingCall && "Call sequence imbalance between start/end?"); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1591 | // This finishes up call legalization. |
| 1592 | IsLegalizingCall = false; |
Chris Lattner | 4b653a0 | 2006-02-14 00:55:02 +0000 | [diff] [blame] | 1593 | |
| 1594 | // If the CALLSEQ_END node has a flag, remember that we legalized it. |
| 1595 | AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0)); |
| 1596 | if (Node->getNumValues() == 2) |
| 1597 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
| 1598 | return Result.getValue(Op.ResNo); |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1599 | case ISD::DYNAMIC_STACKALLOC: { |
Evan Cheng | 61bbbab | 2007-08-16 23:50:06 +0000 | [diff] [blame] | 1600 | MVT::ValueType VT = Node->getValueType(0); |
Chris Lattner | fa404e8 | 2005-01-09 19:03:49 +0000 | [diff] [blame] | 1601 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1602 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the size. |
| 1603 | Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the alignment. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1604 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | fa404e8 | 2005-01-09 19:03:49 +0000 | [diff] [blame] | 1605 | |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1606 | Tmp1 = Result.getValue(0); |
Chris Lattner | 5f65229 | 2006-01-15 08:43:08 +0000 | [diff] [blame] | 1607 | Tmp2 = Result.getValue(1); |
Evan Cheng | 61bbbab | 2007-08-16 23:50:06 +0000 | [diff] [blame] | 1608 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1609 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1610 | case TargetLowering::Expand: { |
| 1611 | unsigned SPReg = TLI.getStackPointerRegisterToSaveRestore(); |
| 1612 | assert(SPReg && "Target cannot require DYNAMIC_STACKALLOC expansion and" |
| 1613 | " not tell us which reg is the stack pointer!"); |
| 1614 | SDOperand Chain = Tmp1.getOperand(0); |
Bill Wendling | 0f8d9c0 | 2007-11-13 00:44:25 +0000 | [diff] [blame] | 1615 | |
| 1616 | // Chain the dynamic stack allocation so that it doesn't modify the stack |
| 1617 | // pointer when other instructions are using the stack. |
| 1618 | Chain = DAG.getCALLSEQ_START(Chain, |
| 1619 | DAG.getConstant(0, TLI.getPointerTy())); |
| 1620 | |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1621 | SDOperand Size = Tmp2.getOperand(1); |
Evan Cheng | 61bbbab | 2007-08-16 23:50:06 +0000 | [diff] [blame] | 1622 | SDOperand SP = DAG.getCopyFromReg(Chain, SPReg, VT); |
| 1623 | Chain = SP.getValue(1); |
| 1624 | unsigned Align = cast<ConstantSDNode>(Tmp3)->getValue(); |
| 1625 | unsigned StackAlign = |
| 1626 | TLI.getTargetMachine().getFrameInfo()->getStackAlignment(); |
| 1627 | if (Align > StackAlign) |
Evan Cheng | 3e20bba | 2007-08-17 18:02:22 +0000 | [diff] [blame] | 1628 | SP = DAG.getNode(ISD::AND, VT, SP, |
| 1629 | DAG.getConstant(-(uint64_t)Align, VT)); |
Evan Cheng | 61bbbab | 2007-08-16 23:50:06 +0000 | [diff] [blame] | 1630 | Tmp1 = DAG.getNode(ISD::SUB, VT, SP, Size); // Value |
Bill Wendling | 0f8d9c0 | 2007-11-13 00:44:25 +0000 | [diff] [blame] | 1631 | Chain = DAG.getCopyToReg(Chain, SPReg, Tmp1); // Output chain |
| 1632 | |
| 1633 | Tmp2 = |
| 1634 | DAG.getCALLSEQ_END(Chain, |
| 1635 | DAG.getConstant(0, TLI.getPointerTy()), |
| 1636 | DAG.getConstant(0, TLI.getPointerTy()), |
| 1637 | SDOperand()); |
| 1638 | |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1639 | Tmp1 = LegalizeOp(Tmp1); |
| 1640 | Tmp2 = LegalizeOp(Tmp2); |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1641 | break; |
| 1642 | } |
| 1643 | case TargetLowering::Custom: |
Chris Lattner | 5f65229 | 2006-01-15 08:43:08 +0000 | [diff] [blame] | 1644 | Tmp3 = TLI.LowerOperation(Tmp1, DAG); |
| 1645 | if (Tmp3.Val) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1646 | Tmp1 = LegalizeOp(Tmp3); |
| 1647 | Tmp2 = LegalizeOp(Tmp3.getValue(1)); |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1648 | } |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1649 | break; |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1650 | case TargetLowering::Legal: |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1651 | break; |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1652 | } |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1653 | // Since this op produce two values, make sure to remember that we |
| 1654 | // legalized both of them. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1655 | AddLegalizedOperand(SDOperand(Node, 0), Tmp1); |
| 1656 | AddLegalizedOperand(SDOperand(Node, 1), Tmp2); |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1657 | return Op.ResNo ? Tmp2 : Tmp1; |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1658 | } |
Chris Lattner | 25a022c | 2006-07-11 01:40:09 +0000 | [diff] [blame] | 1659 | case ISD::INLINEASM: { |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1660 | SmallVector<SDOperand, 8> Ops(Node->op_begin(), Node->op_end()); |
Chris Lattner | 25a022c | 2006-07-11 01:40:09 +0000 | [diff] [blame] | 1661 | bool Changed = false; |
| 1662 | // Legalize all of the operands of the inline asm, in case they are nodes |
| 1663 | // that need to be expanded or something. Note we skip the asm string and |
| 1664 | // all of the TargetConstant flags. |
| 1665 | SDOperand Op = LegalizeOp(Ops[0]); |
| 1666 | Changed = Op != Ops[0]; |
| 1667 | Ops[0] = Op; |
| 1668 | |
| 1669 | bool HasInFlag = Ops.back().getValueType() == MVT::Flag; |
| 1670 | for (unsigned i = 2, e = Ops.size()-HasInFlag; i < e; ) { |
| 1671 | unsigned NumVals = cast<ConstantSDNode>(Ops[i])->getValue() >> 3; |
| 1672 | for (++i; NumVals; ++i, --NumVals) { |
| 1673 | SDOperand Op = LegalizeOp(Ops[i]); |
| 1674 | if (Op != Ops[i]) { |
| 1675 | Changed = true; |
| 1676 | Ops[i] = Op; |
| 1677 | } |
| 1678 | } |
Chris Lattner | ce7518c | 2006-01-26 22:24:51 +0000 | [diff] [blame] | 1679 | } |
Chris Lattner | 25a022c | 2006-07-11 01:40:09 +0000 | [diff] [blame] | 1680 | |
| 1681 | if (HasInFlag) { |
| 1682 | Op = LegalizeOp(Ops.back()); |
| 1683 | Changed |= Op != Ops.back(); |
| 1684 | Ops.back() = Op; |
| 1685 | } |
| 1686 | |
| 1687 | if (Changed) |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1688 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | ce7518c | 2006-01-26 22:24:51 +0000 | [diff] [blame] | 1689 | |
| 1690 | // 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] | 1691 | AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0)); |
Chris Lattner | ce7518c | 2006-01-26 22:24:51 +0000 | [diff] [blame] | 1692 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
| 1693 | return Result.getValue(Op.ResNo); |
Chris Lattner | 25a022c | 2006-07-11 01:40:09 +0000 | [diff] [blame] | 1694 | } |
Chris Lattner | c7af179 | 2005-01-07 22:12:08 +0000 | [diff] [blame] | 1695 | case ISD::BR: |
| 1696 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1697 | // Ensure that libcalls are emitted before a branch. |
| 1698 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1699 | Tmp1 = LegalizeOp(Tmp1); |
| 1700 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 1701 | |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1702 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
Chris Lattner | c7af179 | 2005-01-07 22:12:08 +0000 | [diff] [blame] | 1703 | break; |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 1704 | case ISD::BRIND: |
| 1705 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1706 | // Ensure that libcalls are emitted before a branch. |
| 1707 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1708 | Tmp1 = LegalizeOp(Tmp1); |
| 1709 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 1710 | |
| 1711 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 1712 | default: assert(0 && "Indirect target must be legal type (pointer)!"); |
| 1713 | case Legal: |
| 1714 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the condition. |
| 1715 | break; |
| 1716 | } |
| 1717 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 1718 | break; |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 1719 | case ISD::BR_JT: |
| 1720 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1721 | // Ensure that libcalls are emitted before a branch. |
| 1722 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1723 | Tmp1 = LegalizeOp(Tmp1); |
| 1724 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 1725 | |
| 1726 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the jumptable node. |
| 1727 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
| 1728 | |
| 1729 | switch (TLI.getOperationAction(ISD::BR_JT, MVT::Other)) { |
| 1730 | default: assert(0 && "This action is not supported yet!"); |
| 1731 | case TargetLowering::Legal: break; |
| 1732 | case TargetLowering::Custom: |
| 1733 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 1734 | if (Tmp1.Val) Result = Tmp1; |
| 1735 | break; |
| 1736 | case TargetLowering::Expand: { |
| 1737 | SDOperand Chain = Result.getOperand(0); |
| 1738 | SDOperand Table = Result.getOperand(1); |
| 1739 | SDOperand Index = Result.getOperand(2); |
| 1740 | |
| 1741 | MVT::ValueType PTy = TLI.getPointerTy(); |
Jim Laskey | acd80ac | 2006-12-14 19:17:33 +0000 | [diff] [blame] | 1742 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1743 | unsigned EntrySize = MF.getJumpTableInfo()->getEntrySize(); |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 1744 | Index= DAG.getNode(ISD::MUL, PTy, Index, DAG.getConstant(EntrySize, PTy)); |
| 1745 | SDOperand Addr = DAG.getNode(ISD::ADD, PTy, Index, Table); |
Jim Laskey | acd80ac | 2006-12-14 19:17:33 +0000 | [diff] [blame] | 1746 | |
| 1747 | SDOperand LD; |
| 1748 | switch (EntrySize) { |
| 1749 | default: assert(0 && "Size of jump table not supported yet."); break; |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 1750 | case 4: LD = DAG.getLoad(MVT::i32, Chain, Addr, |
Dan Gohman | 3069b87 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 1751 | PseudoSourceValue::getJumpTable(), 0); break; |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 1752 | case 8: LD = DAG.getLoad(MVT::i64, Chain, Addr, |
Dan Gohman | 3069b87 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 1753 | PseudoSourceValue::getJumpTable(), 0); break; |
Jim Laskey | acd80ac | 2006-12-14 19:17:33 +0000 | [diff] [blame] | 1754 | } |
| 1755 | |
Evan Cheng | cc41586 | 2007-11-09 01:32:10 +0000 | [diff] [blame] | 1756 | Addr = LD; |
Jim Laskey | acd80ac | 2006-12-14 19:17:33 +0000 | [diff] [blame] | 1757 | if (TLI.getTargetMachine().getRelocationModel() == Reloc::PIC_) { |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 1758 | // For PIC, the sequence is: |
| 1759 | // BRIND(load(Jumptable + index) + RelocBase) |
Evan Cheng | cc41586 | 2007-11-09 01:32:10 +0000 | [diff] [blame] | 1760 | // RelocBase can be JumpTable, GOT or some sort of global base. |
| 1761 | if (PTy != MVT::i32) |
| 1762 | Addr = DAG.getNode(ISD::SIGN_EXTEND, PTy, Addr); |
| 1763 | Addr = DAG.getNode(ISD::ADD, PTy, Addr, |
| 1764 | TLI.getPICJumpTableRelocBase(Table, DAG)); |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 1765 | } |
Evan Cheng | cc41586 | 2007-11-09 01:32:10 +0000 | [diff] [blame] | 1766 | Result = DAG.getNode(ISD::BRIND, MVT::Other, LD.getValue(1), Addr); |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 1767 | } |
| 1768 | } |
| 1769 | break; |
Chris Lattner | c18ae4c | 2005-01-07 08:19:42 +0000 | [diff] [blame] | 1770 | case ISD::BRCOND: |
| 1771 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1772 | // Ensure that libcalls are emitted before a return. |
| 1773 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1774 | Tmp1 = LegalizeOp(Tmp1); |
| 1775 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 1776 | |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 1777 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 1778 | case Expand: assert(0 && "It's impossible to expand bools"); |
| 1779 | case Legal: |
| 1780 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the condition. |
| 1781 | break; |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 1782 | case Promote: { |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 1783 | Tmp2 = PromoteOp(Node->getOperand(1)); // Promote the condition. |
Chris Lattner | f990817 | 2006-11-27 04:39:56 +0000 | [diff] [blame] | 1784 | |
| 1785 | // The top bits of the promoted condition are not necessarily zero, ensure |
| 1786 | // that the value is properly zero extended. |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 1787 | unsigned BitWidth = Tmp2.getValueSizeInBits(); |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1788 | if (!DAG.MaskedValueIsZero(Tmp2, |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 1789 | APInt::getHighBitsSet(BitWidth, BitWidth-1))) |
Chris Lattner | f990817 | 2006-11-27 04:39:56 +0000 | [diff] [blame] | 1790 | Tmp2 = DAG.getZeroExtendInReg(Tmp2, MVT::i1); |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 1791 | break; |
| 1792 | } |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 1793 | } |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 1794 | |
| 1795 | // Basic block destination (Op#2) is always legal. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1796 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 1797 | |
| 1798 | switch (TLI.getOperationAction(ISD::BRCOND, MVT::Other)) { |
| 1799 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 1800 | case TargetLowering::Legal: break; |
| 1801 | case TargetLowering::Custom: |
| 1802 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 1803 | if (Tmp1.Val) Result = Tmp1; |
| 1804 | break; |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 1805 | case TargetLowering::Expand: |
| 1806 | // Expand brcond's setcc into its constituent parts and create a BR_CC |
| 1807 | // Node. |
| 1808 | if (Tmp2.getOpcode() == ISD::SETCC) { |
| 1809 | Result = DAG.getNode(ISD::BR_CC, MVT::Other, Tmp1, Tmp2.getOperand(2), |
| 1810 | Tmp2.getOperand(0), Tmp2.getOperand(1), |
| 1811 | Node->getOperand(2)); |
| 1812 | } else { |
| 1813 | Result = DAG.getNode(ISD::BR_CC, MVT::Other, Tmp1, |
| 1814 | DAG.getCondCode(ISD::SETNE), Tmp2, |
| 1815 | DAG.getConstant(0, Tmp2.getValueType()), |
| 1816 | Node->getOperand(2)); |
| 1817 | } |
| 1818 | break; |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 1819 | } |
| 1820 | break; |
| 1821 | case ISD::BR_CC: |
| 1822 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1823 | // Ensure that libcalls are emitted before a branch. |
| 1824 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1825 | Tmp1 = LegalizeOp(Tmp1); |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 1826 | Tmp2 = Node->getOperand(2); // LHS |
| 1827 | Tmp3 = Node->getOperand(3); // RHS |
| 1828 | Tmp4 = Node->getOperand(1); // CC |
| 1829 | |
| 1830 | LegalizeSetCCOperands(Tmp2, Tmp3, Tmp4); |
Evan Cheng | 722cb36 | 2006-12-18 22:55:34 +0000 | [diff] [blame] | 1831 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 1832 | |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 1833 | // If we didn't get both a LHS and RHS back from LegalizeSetCCOperands, |
| 1834 | // the LHS is a legal SETCC itself. In this case, we need to compare |
| 1835 | // the result against zero to select between true and false values. |
| 1836 | if (Tmp3.Val == 0) { |
| 1837 | Tmp3 = DAG.getConstant(0, Tmp2.getValueType()); |
| 1838 | Tmp4 = DAG.getCondCode(ISD::SETNE); |
Chris Lattner | 181b7a3 | 2005-12-17 23:46:46 +0000 | [diff] [blame] | 1839 | } |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 1840 | |
| 1841 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp4, Tmp2, Tmp3, |
| 1842 | Node->getOperand(4)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 1843 | |
Chris Lattner | 181b7a3 | 2005-12-17 23:46:46 +0000 | [diff] [blame] | 1844 | switch (TLI.getOperationAction(ISD::BR_CC, Tmp3.getValueType())) { |
| 1845 | default: assert(0 && "Unexpected action for BR_CC!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 1846 | case TargetLowering::Legal: break; |
| 1847 | case TargetLowering::Custom: |
| 1848 | Tmp4 = TLI.LowerOperation(Result, DAG); |
| 1849 | if (Tmp4.Val) Result = Tmp4; |
Chris Lattner | 181b7a3 | 2005-12-17 23:46:46 +0000 | [diff] [blame] | 1850 | break; |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 1851 | } |
Chris Lattner | c18ae4c | 2005-01-07 08:19:42 +0000 | [diff] [blame] | 1852 | break; |
Evan Cheng | f3fd9fe | 2005-12-23 07:29:34 +0000 | [diff] [blame] | 1853 | case ISD::LOAD: { |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1854 | LoadSDNode *LD = cast<LoadSDNode>(Node); |
| 1855 | Tmp1 = LegalizeOp(LD->getChain()); // Legalize the chain. |
| 1856 | Tmp2 = LegalizeOp(LD->getBasePtr()); // Legalize the base pointer. |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 1857 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1858 | ISD::LoadExtType ExtType = LD->getExtensionType(); |
| 1859 | if (ExtType == ISD::NON_EXTLOAD) { |
| 1860 | MVT::ValueType VT = Node->getValueType(0); |
| 1861 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, LD->getOffset()); |
| 1862 | Tmp3 = Result.getValue(0); |
| 1863 | Tmp4 = Result.getValue(1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 1864 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1865 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 1866 | default: assert(0 && "This action is not supported yet!"); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 1867 | case TargetLowering::Legal: |
| 1868 | // If this is an unaligned load and the target doesn't support it, |
| 1869 | // expand it. |
| 1870 | if (!TLI.allowsUnalignedMemoryAccesses()) { |
| 1871 | unsigned ABIAlignment = TLI.getTargetData()-> |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 1872 | getABITypeAlignment(MVT::getTypeForValueType(LD->getMemoryVT())); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 1873 | if (LD->getAlignment() < ABIAlignment){ |
| 1874 | Result = ExpandUnalignedLoad(cast<LoadSDNode>(Result.Val), DAG, |
| 1875 | TLI); |
| 1876 | Tmp3 = Result.getOperand(0); |
| 1877 | Tmp4 = Result.getOperand(1); |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 1878 | Tmp3 = LegalizeOp(Tmp3); |
| 1879 | Tmp4 = LegalizeOp(Tmp4); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 1880 | } |
| 1881 | } |
| 1882 | break; |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1883 | case TargetLowering::Custom: |
| 1884 | Tmp1 = TLI.LowerOperation(Tmp3, DAG); |
| 1885 | if (Tmp1.Val) { |
| 1886 | Tmp3 = LegalizeOp(Tmp1); |
| 1887 | Tmp4 = LegalizeOp(Tmp1.getValue(1)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 1888 | } |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1889 | break; |
| 1890 | case TargetLowering::Promote: { |
| 1891 | // Only promote a load of vector type to another. |
| 1892 | assert(MVT::isVector(VT) && "Cannot promote this load!"); |
| 1893 | // Change base type to a different vector type. |
| 1894 | MVT::ValueType NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), VT); |
| 1895 | |
| 1896 | Tmp1 = DAG.getLoad(NVT, Tmp1, Tmp2, LD->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 1897 | LD->getSrcValueOffset(), |
| 1898 | LD->isVolatile(), LD->getAlignment()); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1899 | Tmp3 = LegalizeOp(DAG.getNode(ISD::BIT_CONVERT, VT, Tmp1)); |
| 1900 | Tmp4 = LegalizeOp(Tmp1.getValue(1)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1901 | break; |
Andrew Lenharth | 9d416f7 | 2005-06-30 19:22:37 +0000 | [diff] [blame] | 1902 | } |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1903 | } |
| 1904 | // Since loads produce two values, make sure to remember that we |
| 1905 | // legalized both of them. |
| 1906 | AddLegalizedOperand(SDOperand(Node, 0), Tmp3); |
| 1907 | AddLegalizedOperand(SDOperand(Node, 1), Tmp4); |
| 1908 | return Op.ResNo ? Tmp4 : Tmp3; |
| 1909 | } else { |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 1910 | MVT::ValueType SrcVT = LD->getMemoryVT(); |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 1911 | unsigned SrcWidth = MVT::getSizeInBits(SrcVT); |
| 1912 | int SVOffset = LD->getSrcValueOffset(); |
| 1913 | unsigned Alignment = LD->getAlignment(); |
| 1914 | bool isVolatile = LD->isVolatile(); |
| 1915 | |
| 1916 | if (SrcWidth != MVT::getStoreSizeInBits(SrcVT) && |
| 1917 | // Some targets pretend to have an i1 loading operation, and actually |
| 1918 | // load an i8. This trick is correct for ZEXTLOAD because the top 7 |
| 1919 | // bits are guaranteed to be zero; it helps the optimizers understand |
| 1920 | // that these bits are zero. It is also useful for EXTLOAD, since it |
| 1921 | // tells the optimizers that those bits are undefined. It would be |
| 1922 | // nice to have an effective generic way of getting these benefits... |
| 1923 | // Until such a way is found, don't insist on promoting i1 here. |
| 1924 | (SrcVT != MVT::i1 || |
| 1925 | TLI.getLoadXAction(ExtType, MVT::i1) == TargetLowering::Promote)) { |
| 1926 | // Promote to a byte-sized load if not loading an integral number of |
| 1927 | // bytes. For example, promote EXTLOAD:i20 -> EXTLOAD:i24. |
| 1928 | unsigned NewWidth = MVT::getStoreSizeInBits(SrcVT); |
| 1929 | MVT::ValueType NVT = MVT::getIntegerType(NewWidth); |
| 1930 | SDOperand Ch; |
| 1931 | |
| 1932 | // The extra bits are guaranteed to be zero, since we stored them that |
| 1933 | // way. A zext load from NVT thus automatically gives zext from SrcVT. |
| 1934 | |
| 1935 | ISD::LoadExtType NewExtType = |
| 1936 | ExtType == ISD::ZEXTLOAD ? ISD::ZEXTLOAD : ISD::EXTLOAD; |
| 1937 | |
| 1938 | Result = DAG.getExtLoad(NewExtType, Node->getValueType(0), |
| 1939 | Tmp1, Tmp2, LD->getSrcValue(), SVOffset, |
| 1940 | NVT, isVolatile, Alignment); |
| 1941 | |
| 1942 | Ch = Result.getValue(1); // The chain. |
| 1943 | |
| 1944 | if (ExtType == ISD::SEXTLOAD) |
| 1945 | // Having the top bits zero doesn't help when sign extending. |
| 1946 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(), |
| 1947 | Result, DAG.getValueType(SrcVT)); |
| 1948 | else if (ExtType == ISD::ZEXTLOAD || NVT == Result.getValueType()) |
| 1949 | // All the top bits are guaranteed to be zero - inform the optimizers. |
| 1950 | Result = DAG.getNode(ISD::AssertZext, Result.getValueType(), Result, |
| 1951 | DAG.getValueType(SrcVT)); |
| 1952 | |
| 1953 | Tmp1 = LegalizeOp(Result); |
| 1954 | Tmp2 = LegalizeOp(Ch); |
| 1955 | } else if (SrcWidth & (SrcWidth - 1)) { |
| 1956 | // If not loading a power-of-2 number of bits, expand as two loads. |
| 1957 | assert(MVT::isExtendedVT(SrcVT) && !MVT::isVector(SrcVT) && |
| 1958 | "Unsupported extload!"); |
| 1959 | unsigned RoundWidth = 1 << Log2_32(SrcWidth); |
| 1960 | assert(RoundWidth < SrcWidth); |
| 1961 | unsigned ExtraWidth = SrcWidth - RoundWidth; |
| 1962 | assert(ExtraWidth < RoundWidth); |
| 1963 | assert(!(RoundWidth % 8) && !(ExtraWidth % 8) && |
| 1964 | "Load size not an integral number of bytes!"); |
| 1965 | MVT::ValueType RoundVT = MVT::getIntegerType(RoundWidth); |
| 1966 | MVT::ValueType ExtraVT = MVT::getIntegerType(ExtraWidth); |
| 1967 | SDOperand Lo, Hi, Ch; |
| 1968 | unsigned IncrementSize; |
| 1969 | |
| 1970 | if (TLI.isLittleEndian()) { |
| 1971 | // EXTLOAD:i24 -> ZEXTLOAD:i16 | (shl EXTLOAD@+2:i8, 16) |
| 1972 | // Load the bottom RoundWidth bits. |
| 1973 | Lo = DAG.getExtLoad(ISD::ZEXTLOAD, Node->getValueType(0), Tmp1, Tmp2, |
| 1974 | LD->getSrcValue(), SVOffset, RoundVT, isVolatile, |
| 1975 | Alignment); |
| 1976 | |
| 1977 | // Load the remaining ExtraWidth bits. |
| 1978 | IncrementSize = RoundWidth / 8; |
| 1979 | Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2, |
| 1980 | DAG.getIntPtrConstant(IncrementSize)); |
| 1981 | Hi = DAG.getExtLoad(ExtType, Node->getValueType(0), Tmp1, Tmp2, |
| 1982 | LD->getSrcValue(), SVOffset + IncrementSize, |
| 1983 | ExtraVT, isVolatile, |
| 1984 | MinAlign(Alignment, IncrementSize)); |
| 1985 | |
| 1986 | // Build a factor node to remember that this load is independent of the |
| 1987 | // other one. |
| 1988 | Ch = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1), |
| 1989 | Hi.getValue(1)); |
| 1990 | |
| 1991 | // Move the top bits to the right place. |
| 1992 | Hi = DAG.getNode(ISD::SHL, Hi.getValueType(), Hi, |
| 1993 | DAG.getConstant(RoundWidth, TLI.getShiftAmountTy())); |
| 1994 | |
| 1995 | // Join the hi and lo parts. |
| 1996 | Result = DAG.getNode(ISD::OR, Node->getValueType(0), Lo, Hi); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 1997 | } else { |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 1998 | // Big endian - avoid unaligned loads. |
| 1999 | // EXTLOAD:i24 -> (shl EXTLOAD:i16, 8) | ZEXTLOAD@+2:i8 |
| 2000 | // Load the top RoundWidth bits. |
| 2001 | Hi = DAG.getExtLoad(ExtType, Node->getValueType(0), Tmp1, Tmp2, |
| 2002 | LD->getSrcValue(), SVOffset, RoundVT, isVolatile, |
| 2003 | Alignment); |
| 2004 | |
| 2005 | // Load the remaining ExtraWidth bits. |
| 2006 | IncrementSize = RoundWidth / 8; |
| 2007 | Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2, |
| 2008 | DAG.getIntPtrConstant(IncrementSize)); |
| 2009 | Lo = DAG.getExtLoad(ISD::ZEXTLOAD, Node->getValueType(0), Tmp1, Tmp2, |
| 2010 | LD->getSrcValue(), SVOffset + IncrementSize, |
| 2011 | ExtraVT, isVolatile, |
| 2012 | MinAlign(Alignment, IncrementSize)); |
| 2013 | |
| 2014 | // Build a factor node to remember that this load is independent of the |
| 2015 | // other one. |
| 2016 | Ch = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1), |
| 2017 | Hi.getValue(1)); |
| 2018 | |
| 2019 | // Move the top bits to the right place. |
| 2020 | Hi = DAG.getNode(ISD::SHL, Hi.getValueType(), Hi, |
| 2021 | DAG.getConstant(ExtraWidth, TLI.getShiftAmountTy())); |
| 2022 | |
| 2023 | // Join the hi and lo parts. |
| 2024 | Result = DAG.getNode(ISD::OR, Node->getValueType(0), Lo, Hi); |
| 2025 | } |
| 2026 | |
| 2027 | Tmp1 = LegalizeOp(Result); |
| 2028 | Tmp2 = LegalizeOp(Ch); |
| 2029 | } else { |
| 2030 | switch (TLI.getLoadXAction(ExtType, SrcVT)) { |
| 2031 | default: assert(0 && "This action is not supported yet!"); |
| 2032 | case TargetLowering::Custom: |
| 2033 | isCustom = true; |
| 2034 | // FALLTHROUGH |
| 2035 | case TargetLowering::Legal: |
| 2036 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, LD->getOffset()); |
| 2037 | Tmp1 = Result.getValue(0); |
| 2038 | Tmp2 = Result.getValue(1); |
| 2039 | |
| 2040 | if (isCustom) { |
| 2041 | Tmp3 = TLI.LowerOperation(Result, DAG); |
| 2042 | if (Tmp3.Val) { |
| 2043 | Tmp1 = LegalizeOp(Tmp3); |
| 2044 | Tmp2 = LegalizeOp(Tmp3.getValue(1)); |
| 2045 | } |
| 2046 | } else { |
| 2047 | // If this is an unaligned load and the target doesn't support it, |
| 2048 | // expand it. |
| 2049 | if (!TLI.allowsUnalignedMemoryAccesses()) { |
| 2050 | unsigned ABIAlignment = TLI.getTargetData()-> |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 2051 | getABITypeAlignment(MVT::getTypeForValueType(LD->getMemoryVT())); |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2052 | if (LD->getAlignment() < ABIAlignment){ |
| 2053 | Result = ExpandUnalignedLoad(cast<LoadSDNode>(Result.Val), DAG, |
| 2054 | TLI); |
| 2055 | Tmp1 = Result.getOperand(0); |
| 2056 | Tmp2 = Result.getOperand(1); |
| 2057 | Tmp1 = LegalizeOp(Tmp1); |
| 2058 | Tmp2 = LegalizeOp(Tmp2); |
| 2059 | } |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2060 | } |
| 2061 | } |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2062 | break; |
| 2063 | case TargetLowering::Expand: |
| 2064 | // f64 = EXTLOAD f32 should expand to LOAD, FP_EXTEND |
| 2065 | if (SrcVT == MVT::f32 && Node->getValueType(0) == MVT::f64) { |
| 2066 | SDOperand Load = DAG.getLoad(SrcVT, Tmp1, Tmp2, LD->getSrcValue(), |
| 2067 | LD->getSrcValueOffset(), |
| 2068 | LD->isVolatile(), LD->getAlignment()); |
| 2069 | Result = DAG.getNode(ISD::FP_EXTEND, Node->getValueType(0), Load); |
| 2070 | Tmp1 = LegalizeOp(Result); // Relegalize new nodes. |
| 2071 | Tmp2 = LegalizeOp(Load.getValue(1)); |
| 2072 | break; |
| 2073 | } |
| 2074 | assert(ExtType != ISD::EXTLOAD &&"EXTLOAD should always be supported!"); |
| 2075 | // Turn the unsupported load into an EXTLOAD followed by an explicit |
| 2076 | // zero/sign extend inreg. |
| 2077 | Result = DAG.getExtLoad(ISD::EXTLOAD, Node->getValueType(0), |
| 2078 | Tmp1, Tmp2, LD->getSrcValue(), |
| 2079 | LD->getSrcValueOffset(), SrcVT, |
| 2080 | LD->isVolatile(), LD->getAlignment()); |
| 2081 | SDOperand ValRes; |
| 2082 | if (ExtType == ISD::SEXTLOAD) |
| 2083 | ValRes = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(), |
| 2084 | Result, DAG.getValueType(SrcVT)); |
| 2085 | else |
| 2086 | ValRes = DAG.getZeroExtendInReg(Result, SrcVT); |
| 2087 | Tmp1 = LegalizeOp(ValRes); // Relegalize new nodes. |
| 2088 | Tmp2 = LegalizeOp(Result.getValue(1)); // Relegalize new nodes. |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2089 | break; |
| 2090 | } |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2091 | } |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2092 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2093 | // Since loads produce two values, make sure to remember that we legalized |
| 2094 | // both of them. |
| 2095 | AddLegalizedOperand(SDOperand(Node, 0), Tmp1); |
| 2096 | AddLegalizedOperand(SDOperand(Node, 1), Tmp2); |
| 2097 | return Op.ResNo ? Tmp2 : Tmp1; |
Chris Lattner | 01ff721 | 2005-04-10 22:54:25 +0000 | [diff] [blame] | 2098 | } |
Chris Lattner | 01ff721 | 2005-04-10 22:54:25 +0000 | [diff] [blame] | 2099 | } |
Nate Begeman | 5dc897b | 2005-10-19 00:06:56 +0000 | [diff] [blame] | 2100 | case ISD::EXTRACT_ELEMENT: { |
| 2101 | MVT::ValueType OpTy = Node->getOperand(0).getValueType(); |
| 2102 | switch (getTypeAction(OpTy)) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2103 | default: assert(0 && "EXTRACT_ELEMENT action for type unimplemented!"); |
Nate Begeman | 5dc897b | 2005-10-19 00:06:56 +0000 | [diff] [blame] | 2104 | case Legal: |
| 2105 | if (cast<ConstantSDNode>(Node->getOperand(1))->getValue()) { |
| 2106 | // 1 -> Hi |
| 2107 | Result = DAG.getNode(ISD::SRL, OpTy, Node->getOperand(0), |
| 2108 | DAG.getConstant(MVT::getSizeInBits(OpTy)/2, |
| 2109 | TLI.getShiftAmountTy())); |
| 2110 | Result = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0), Result); |
| 2111 | } else { |
| 2112 | // 0 -> Lo |
| 2113 | Result = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0), |
| 2114 | Node->getOperand(0)); |
| 2115 | } |
Nate Begeman | 5dc897b | 2005-10-19 00:06:56 +0000 | [diff] [blame] | 2116 | break; |
| 2117 | case Expand: |
| 2118 | // Get both the low and high parts. |
| 2119 | ExpandOp(Node->getOperand(0), Tmp1, Tmp2); |
| 2120 | if (cast<ConstantSDNode>(Node->getOperand(1))->getValue()) |
| 2121 | Result = Tmp2; // 1 -> Hi |
| 2122 | else |
| 2123 | Result = Tmp1; // 0 -> Lo |
| 2124 | break; |
| 2125 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2126 | break; |
Nate Begeman | 5dc897b | 2005-10-19 00:06:56 +0000 | [diff] [blame] | 2127 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2128 | |
| 2129 | case ISD::CopyToReg: |
| 2130 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2131 | |
Chris Lattner | c9c60f6 | 2005-08-24 16:35:28 +0000 | [diff] [blame] | 2132 | assert(isTypeLegal(Node->getOperand(2).getValueType()) && |
Chris Lattner | d5d0f9b | 2005-08-16 21:55:35 +0000 | [diff] [blame] | 2133 | "Register type must be legal!"); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 2134 | // Legalize the incoming value (must be a legal type). |
Chris Lattner | d5d0f9b | 2005-08-16 21:55:35 +0000 | [diff] [blame] | 2135 | Tmp2 = LegalizeOp(Node->getOperand(2)); |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 2136 | if (Node->getNumValues() == 1) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2137 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1), Tmp2); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 2138 | } else { |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 2139 | assert(Node->getNumValues() == 2 && "Unknown CopyToReg"); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2140 | if (Node->getNumOperands() == 4) { |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 2141 | Tmp3 = LegalizeOp(Node->getOperand(3)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2142 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1), Tmp2, |
| 2143 | Tmp3); |
| 2144 | } else { |
| 2145 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1),Tmp2); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 2146 | } |
| 2147 | |
| 2148 | // Since this produces two values, make sure to remember that we legalized |
| 2149 | // both of them. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2150 | AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0)); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 2151 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2152 | return Result; |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 2153 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2154 | break; |
| 2155 | |
| 2156 | case ISD::RET: |
| 2157 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 2158 | |
| 2159 | // Ensure that libcalls are emitted before a return. |
| 2160 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 2161 | Tmp1 = LegalizeOp(Tmp1); |
| 2162 | LastCALLSEQ_END = DAG.getEntryNode(); |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2163 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2164 | switch (Node->getNumOperands()) { |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 2165 | case 3: // ret val |
Evan Cheng | 98f8aeb | 2006-04-11 06:33:39 +0000 | [diff] [blame] | 2166 | Tmp2 = Node->getOperand(1); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 2167 | Tmp3 = Node->getOperand(2); // Signness |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2168 | switch (getTypeAction(Tmp2.getValueType())) { |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2169 | case Legal: |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 2170 | Result = DAG.UpdateNodeOperands(Result, Tmp1, LegalizeOp(Tmp2), Tmp3); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2171 | break; |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2172 | case Expand: |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2173 | if (!MVT::isVector(Tmp2.getValueType())) { |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2174 | SDOperand Lo, Hi; |
| 2175 | ExpandOp(Tmp2, Lo, Hi); |
Chris Lattner | edf2e8d | 2007-03-06 20:01:06 +0000 | [diff] [blame] | 2176 | |
| 2177 | // Big endian systems want the hi reg first. |
Duncan Sands | 0753fc1 | 2008-02-11 10:37:04 +0000 | [diff] [blame] | 2178 | if (TLI.isBigEndian()) |
Chris Lattner | edf2e8d | 2007-03-06 20:01:06 +0000 | [diff] [blame] | 2179 | std::swap(Lo, Hi); |
| 2180 | |
Evan Cheng | 13acce3 | 2006-12-11 19:27:14 +0000 | [diff] [blame] | 2181 | if (Hi.Val) |
| 2182 | Result = DAG.getNode(ISD::RET, MVT::Other, Tmp1, Lo, Tmp3, Hi,Tmp3); |
| 2183 | else |
| 2184 | Result = DAG.getNode(ISD::RET, MVT::Other, Tmp1, Lo, Tmp3); |
Chris Lattner | f921a51 | 2006-08-21 20:24:53 +0000 | [diff] [blame] | 2185 | Result = LegalizeOp(Result); |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2186 | } else { |
| 2187 | SDNode *InVal = Tmp2.Val; |
Dale Johannesen | e526962 | 2007-10-20 00:07:52 +0000 | [diff] [blame] | 2188 | int InIx = Tmp2.ResNo; |
| 2189 | unsigned NumElems = MVT::getVectorNumElements(InVal->getValueType(InIx)); |
| 2190 | MVT::ValueType EVT = MVT::getVectorElementType(InVal->getValueType(InIx)); |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2191 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2192 | // Figure out if there is a simple type corresponding to this Vector |
Reid Spencer | ac9dcb9 | 2007-02-15 03:39:18 +0000 | [diff] [blame] | 2193 | // type. If so, convert to the vector type. |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2194 | MVT::ValueType TVT = MVT::getVectorType(EVT, NumElems); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2195 | if (TLI.isTypeLegal(TVT)) { |
Reid Spencer | ac9dcb9 | 2007-02-15 03:39:18 +0000 | [diff] [blame] | 2196 | // Turn this into a return of the vector type. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2197 | Tmp2 = LegalizeOp(Tmp2); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 2198 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2199 | } else if (NumElems == 1) { |
| 2200 | // Turn this into a return of the scalar type. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2201 | Tmp2 = ScalarizeVectorOp(Tmp2); |
| 2202 | Tmp2 = LegalizeOp(Tmp2); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 2203 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | b49e52c | 2006-04-11 02:00:08 +0000 | [diff] [blame] | 2204 | |
| 2205 | // FIXME: Returns of gcc generic vectors smaller than a legal type |
| 2206 | // should be returned in integer registers! |
| 2207 | |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2208 | // The scalarized value type may not be legal, e.g. it might require |
| 2209 | // promotion or expansion. Relegalize the return. |
| 2210 | Result = LegalizeOp(Result); |
| 2211 | } else { |
Chris Lattner | b49e52c | 2006-04-11 02:00:08 +0000 | [diff] [blame] | 2212 | // FIXME: Returns of gcc generic vectors larger than a legal vector |
| 2213 | // type should be returned by reference! |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2214 | SDOperand Lo, Hi; |
| 2215 | SplitVectorOp(Tmp2, Lo, Hi); |
Chris Lattner | fea997a | 2007-02-01 04:55:59 +0000 | [diff] [blame] | 2216 | Result = DAG.getNode(ISD::RET, MVT::Other, Tmp1, Lo, Tmp3, Hi,Tmp3); |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2217 | Result = LegalizeOp(Result); |
| 2218 | } |
| 2219 | } |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2220 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2221 | case Promote: |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 2222 | Tmp2 = PromoteOp(Node->getOperand(1)); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 2223 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2224 | Result = LegalizeOp(Result); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 2225 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2226 | } |
| 2227 | break; |
| 2228 | case 1: // ret void |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2229 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2230 | break; |
| 2231 | default: { // ret <values> |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 2232 | SmallVector<SDOperand, 8> NewValues; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2233 | NewValues.push_back(Tmp1); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 2234 | for (unsigned i = 1, e = Node->getNumOperands(); i < e; i += 2) |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2235 | switch (getTypeAction(Node->getOperand(i).getValueType())) { |
| 2236 | case Legal: |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 2237 | NewValues.push_back(LegalizeOp(Node->getOperand(i))); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 2238 | NewValues.push_back(Node->getOperand(i+1)); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2239 | break; |
| 2240 | case Expand: { |
| 2241 | SDOperand Lo, Hi; |
Dan Gohman | 6595cb3 | 2007-06-27 16:08:04 +0000 | [diff] [blame] | 2242 | assert(!MVT::isExtendedVT(Node->getOperand(i).getValueType()) && |
Chris Lattner | b49e52c | 2006-04-11 02:00:08 +0000 | [diff] [blame] | 2243 | "FIXME: TODO: implement returning non-legal vector types!"); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2244 | ExpandOp(Node->getOperand(i), Lo, Hi); |
| 2245 | NewValues.push_back(Lo); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 2246 | NewValues.push_back(Node->getOperand(i+1)); |
Evan Cheng | 13acce3 | 2006-12-11 19:27:14 +0000 | [diff] [blame] | 2247 | if (Hi.Val) { |
| 2248 | NewValues.push_back(Hi); |
| 2249 | NewValues.push_back(Node->getOperand(i+1)); |
| 2250 | } |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2251 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2252 | } |
| 2253 | case Promote: |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 2254 | assert(0 && "Can't promote multiple return value yet!"); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2255 | } |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2256 | |
| 2257 | if (NewValues.size() == Node->getNumOperands()) |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 2258 | Result = DAG.UpdateNodeOperands(Result, &NewValues[0],NewValues.size()); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2259 | else |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 2260 | Result = DAG.getNode(ISD::RET, MVT::Other, |
| 2261 | &NewValues[0], NewValues.size()); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2262 | break; |
| 2263 | } |
| 2264 | } |
Evan Cheng | 17c428e | 2006-01-06 00:41:43 +0000 | [diff] [blame] | 2265 | |
Chris Lattner | 6862dbc | 2006-01-29 21:02:23 +0000 | [diff] [blame] | 2266 | if (Result.getOpcode() == ISD::RET) { |
| 2267 | switch (TLI.getOperationAction(Result.getOpcode(), MVT::Other)) { |
| 2268 | default: assert(0 && "This action is not supported yet!"); |
| 2269 | case TargetLowering::Legal: break; |
| 2270 | case TargetLowering::Custom: |
| 2271 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2272 | if (Tmp1.Val) Result = Tmp1; |
| 2273 | break; |
| 2274 | } |
Evan Cheng | 17c428e | 2006-01-06 00:41:43 +0000 | [diff] [blame] | 2275 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2276 | break; |
Evan Cheng | f3fd9fe | 2005-12-23 07:29:34 +0000 | [diff] [blame] | 2277 | case ISD::STORE: { |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2278 | StoreSDNode *ST = cast<StoreSDNode>(Node); |
| 2279 | Tmp1 = LegalizeOp(ST->getChain()); // Legalize the chain. |
| 2280 | Tmp2 = LegalizeOp(ST->getBasePtr()); // Legalize the pointer. |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2281 | int SVOffset = ST->getSrcValueOffset(); |
| 2282 | unsigned Alignment = ST->getAlignment(); |
| 2283 | bool isVolatile = ST->isVolatile(); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2284 | |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2285 | if (!ST->isTruncatingStore()) { |
Chris Lattner | d93d46e | 2006-12-12 04:18:56 +0000 | [diff] [blame] | 2286 | // Turn 'store float 1.0, Ptr' -> 'store int 0x12345678, Ptr' |
| 2287 | // FIXME: We shouldn't do this for TargetConstantFP's. |
| 2288 | // FIXME: move this to the DAG Combiner! Note that we can't regress due |
| 2289 | // to phase ordering between legalized code and the dag combiner. This |
| 2290 | // probably means that we need to integrate dag combiner and legalizer |
| 2291 | // together. |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 2292 | // We generally can't do this one for long doubles. |
Chris Lattner | 2b4c279 | 2007-10-13 06:35:54 +0000 | [diff] [blame] | 2293 | if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(ST->getValue())) { |
Chris Lattner | 3cb9351 | 2007-10-15 05:46:06 +0000 | [diff] [blame] | 2294 | if (CFP->getValueType(0) == MVT::f32 && |
| 2295 | getTypeAction(MVT::i32) == Legal) { |
Dale Johannesen | 9d5f456 | 2007-09-12 03:30:33 +0000 | [diff] [blame] | 2296 | Tmp3 = DAG.getConstant((uint32_t)CFP->getValueAPF(). |
| 2297 | convertToAPInt().getZExtValue(), |
Dale Johannesen | 3f6eb74 | 2007-09-11 18:32:33 +0000 | [diff] [blame] | 2298 | MVT::i32); |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 2299 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
| 2300 | SVOffset, isVolatile, Alignment); |
| 2301 | break; |
| 2302 | } else if (CFP->getValueType(0) == MVT::f64) { |
Chris Lattner | 3cb9351 | 2007-10-15 05:46:06 +0000 | [diff] [blame] | 2303 | // If this target supports 64-bit registers, do a single 64-bit store. |
| 2304 | if (getTypeAction(MVT::i64) == Legal) { |
| 2305 | Tmp3 = DAG.getConstant(CFP->getValueAPF().convertToAPInt(). |
| 2306 | getZExtValue(), MVT::i64); |
| 2307 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
| 2308 | SVOffset, isVolatile, Alignment); |
| 2309 | break; |
| 2310 | } else if (getTypeAction(MVT::i32) == Legal) { |
| 2311 | // Otherwise, if the target supports 32-bit registers, use 2 32-bit |
| 2312 | // stores. If the target supports neither 32- nor 64-bits, this |
| 2313 | // xform is certainly not worth it. |
| 2314 | uint64_t IntVal =CFP->getValueAPF().convertToAPInt().getZExtValue(); |
| 2315 | SDOperand Lo = DAG.getConstant(uint32_t(IntVal), MVT::i32); |
| 2316 | SDOperand Hi = DAG.getConstant(uint32_t(IntVal >>32), MVT::i32); |
Duncan Sands | 0753fc1 | 2008-02-11 10:37:04 +0000 | [diff] [blame] | 2317 | if (TLI.isBigEndian()) std::swap(Lo, Hi); |
Chris Lattner | 3cb9351 | 2007-10-15 05:46:06 +0000 | [diff] [blame] | 2318 | |
| 2319 | Lo = DAG.getStore(Tmp1, Lo, Tmp2, ST->getSrcValue(), |
| 2320 | SVOffset, isVolatile, Alignment); |
| 2321 | Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2, |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 2322 | DAG.getIntPtrConstant(4)); |
Chris Lattner | 3cb9351 | 2007-10-15 05:46:06 +0000 | [diff] [blame] | 2323 | Hi = DAG.getStore(Tmp1, Hi, Tmp2, ST->getSrcValue(), SVOffset+4, |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 2324 | isVolatile, MinAlign(Alignment, 4U)); |
Chris Lattner | 3cb9351 | 2007-10-15 05:46:06 +0000 | [diff] [blame] | 2325 | |
| 2326 | Result = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo, Hi); |
| 2327 | break; |
| 2328 | } |
Chris Lattner | d93d46e | 2006-12-12 04:18:56 +0000 | [diff] [blame] | 2329 | } |
Chris Lattner | d93d46e | 2006-12-12 04:18:56 +0000 | [diff] [blame] | 2330 | } |
| 2331 | |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 2332 | switch (getTypeAction(ST->getMemoryVT())) { |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2333 | case Legal: { |
| 2334 | Tmp3 = LegalizeOp(ST->getValue()); |
| 2335 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp3, Tmp2, |
| 2336 | ST->getOffset()); |
Evan Cheng | f3fd9fe | 2005-12-23 07:29:34 +0000 | [diff] [blame] | 2337 | |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2338 | MVT::ValueType VT = Tmp3.getValueType(); |
| 2339 | switch (TLI.getOperationAction(ISD::STORE, VT)) { |
| 2340 | default: assert(0 && "This action is not supported yet!"); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2341 | case TargetLowering::Legal: |
| 2342 | // If this is an unaligned store and the target doesn't support it, |
| 2343 | // expand it. |
| 2344 | if (!TLI.allowsUnalignedMemoryAccesses()) { |
| 2345 | unsigned ABIAlignment = TLI.getTargetData()-> |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 2346 | getABITypeAlignment(MVT::getTypeForValueType(ST->getMemoryVT())); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2347 | if (ST->getAlignment() < ABIAlignment) |
| 2348 | Result = ExpandUnalignedStore(cast<StoreSDNode>(Result.Val), DAG, |
| 2349 | TLI); |
| 2350 | } |
| 2351 | break; |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2352 | case TargetLowering::Custom: |
| 2353 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2354 | if (Tmp1.Val) Result = Tmp1; |
| 2355 | break; |
| 2356 | case TargetLowering::Promote: |
| 2357 | assert(MVT::isVector(VT) && "Unknown legal promote case!"); |
| 2358 | Tmp3 = DAG.getNode(ISD::BIT_CONVERT, |
| 2359 | TLI.getTypeToPromoteTo(ISD::STORE, VT), Tmp3); |
| 2360 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2361 | ST->getSrcValue(), SVOffset, isVolatile, |
| 2362 | Alignment); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2363 | break; |
| 2364 | } |
| 2365 | break; |
| 2366 | } |
| 2367 | case Promote: |
| 2368 | // Truncate the value and store the result. |
| 2369 | Tmp3 = PromoteOp(ST->getValue()); |
| 2370 | Result = DAG.getTruncStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 2371 | SVOffset, ST->getMemoryVT(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2372 | isVolatile, Alignment); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2373 | break; |
| 2374 | |
| 2375 | case Expand: |
| 2376 | unsigned IncrementSize = 0; |
| 2377 | SDOperand Lo, Hi; |
| 2378 | |
| 2379 | // If this is a vector type, then we have to calculate the increment as |
| 2380 | // the product of the element size in bytes, and the number of elements |
| 2381 | // in the high half of the vector. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2382 | if (MVT::isVector(ST->getValue().getValueType())) { |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2383 | SDNode *InVal = ST->getValue().Val; |
Dale Johannesen | e526962 | 2007-10-20 00:07:52 +0000 | [diff] [blame] | 2384 | int InIx = ST->getValue().ResNo; |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 2385 | MVT::ValueType InVT = InVal->getValueType(InIx); |
| 2386 | unsigned NumElems = MVT::getVectorNumElements(InVT); |
| 2387 | MVT::ValueType EVT = MVT::getVectorElementType(InVT); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2388 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2389 | // Figure out if there is a simple type corresponding to this Vector |
Reid Spencer | ac9dcb9 | 2007-02-15 03:39:18 +0000 | [diff] [blame] | 2390 | // type. If so, convert to the vector type. |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2391 | MVT::ValueType TVT = MVT::getVectorType(EVT, NumElems); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2392 | if (TLI.isTypeLegal(TVT)) { |
Reid Spencer | ac9dcb9 | 2007-02-15 03:39:18 +0000 | [diff] [blame] | 2393 | // Turn this into a normal store of the vector type. |
Dan Gohman | 21be384 | 2008-02-15 18:11:59 +0000 | [diff] [blame] | 2394 | Tmp3 = LegalizeOp(ST->getValue()); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2395 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2396 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2397 | Result = LegalizeOp(Result); |
| 2398 | break; |
| 2399 | } else if (NumElems == 1) { |
| 2400 | // Turn this into a normal store of the scalar type. |
Dan Gohman | 21be384 | 2008-02-15 18:11:59 +0000 | [diff] [blame] | 2401 | Tmp3 = ScalarizeVectorOp(ST->getValue()); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2402 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2403 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2404 | // The scalarized value type may not be legal, e.g. it might require |
| 2405 | // promotion or expansion. Relegalize the scalar store. |
| 2406 | Result = LegalizeOp(Result); |
| 2407 | break; |
| 2408 | } else { |
Dan Gohman | 21be384 | 2008-02-15 18:11:59 +0000 | [diff] [blame] | 2409 | SplitVectorOp(ST->getValue(), Lo, Hi); |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 2410 | IncrementSize = MVT::getVectorNumElements(Lo.Val->getValueType(0)) * |
| 2411 | MVT::getSizeInBits(EVT)/8; |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2412 | } |
| 2413 | } else { |
Dan Gohman | 21be384 | 2008-02-15 18:11:59 +0000 | [diff] [blame] | 2414 | ExpandOp(ST->getValue(), Lo, Hi); |
Evan Cheng | 7b2b5c8 | 2006-12-12 19:53:13 +0000 | [diff] [blame] | 2415 | IncrementSize = Hi.Val ? MVT::getSizeInBits(Hi.getValueType())/8 : 0; |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2416 | |
Duncan Sands | 0753fc1 | 2008-02-11 10:37:04 +0000 | [diff] [blame] | 2417 | if (TLI.isBigEndian()) |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2418 | std::swap(Lo, Hi); |
| 2419 | } |
| 2420 | |
| 2421 | Lo = DAG.getStore(Tmp1, Lo, Tmp2, ST->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2422 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 7b2b5c8 | 2006-12-12 19:53:13 +0000 | [diff] [blame] | 2423 | |
| 2424 | if (Hi.Val == NULL) { |
| 2425 | // Must be int <-> float one-to-one expansion. |
| 2426 | Result = Lo; |
| 2427 | break; |
| 2428 | } |
| 2429 | |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2430 | Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2, |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 2431 | DAG.getIntPtrConstant(IncrementSize)); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2432 | assert(isTypeLegal(Tmp2.getValueType()) && |
| 2433 | "Pointers must be legal!"); |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2434 | SVOffset += IncrementSize; |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 2435 | Alignment = MinAlign(Alignment, IncrementSize); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2436 | Hi = DAG.getStore(Tmp1, Hi, Tmp2, ST->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2437 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2438 | Result = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo, Hi); |
| 2439 | break; |
| 2440 | } |
| 2441 | } else { |
Chris Lattner | ddf8956 | 2008-01-17 19:59:44 +0000 | [diff] [blame] | 2442 | switch (getTypeAction(ST->getValue().getValueType())) { |
| 2443 | case Legal: |
| 2444 | Tmp3 = LegalizeOp(ST->getValue()); |
| 2445 | break; |
| 2446 | case Promote: |
| 2447 | // We can promote the value, the truncstore will still take care of it. |
| 2448 | Tmp3 = PromoteOp(ST->getValue()); |
| 2449 | break; |
| 2450 | case Expand: |
| 2451 | // Just store the low part. This may become a non-trunc store, so make |
| 2452 | // sure to use getTruncStore, not UpdateNodeOperands below. |
| 2453 | ExpandOp(ST->getValue(), Tmp3, Tmp4); |
| 2454 | return DAG.getTruncStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
| 2455 | SVOffset, MVT::i8, isVolatile, Alignment); |
| 2456 | } |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2457 | |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 2458 | MVT::ValueType StVT = ST->getMemoryVT(); |
Duncan Sands | 7e85720 | 2008-01-22 07:17:34 +0000 | [diff] [blame] | 2459 | unsigned StWidth = MVT::getSizeInBits(StVT); |
| 2460 | |
| 2461 | if (StWidth != MVT::getStoreSizeInBits(StVT)) { |
| 2462 | // Promote to a byte-sized store with upper bits zero if not |
| 2463 | // storing an integral number of bytes. For example, promote |
| 2464 | // TRUNCSTORE:i1 X -> TRUNCSTORE:i8 (and X, 1) |
| 2465 | MVT::ValueType NVT = MVT::getIntegerType(MVT::getStoreSizeInBits(StVT)); |
| 2466 | Tmp3 = DAG.getZeroExtendInReg(Tmp3, StVT); |
| 2467 | Result = DAG.getTruncStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
| 2468 | SVOffset, NVT, isVolatile, Alignment); |
| 2469 | } else if (StWidth & (StWidth - 1)) { |
| 2470 | // If not storing a power-of-2 number of bits, expand as two stores. |
| 2471 | assert(MVT::isExtendedVT(StVT) && !MVT::isVector(StVT) && |
| 2472 | "Unsupported truncstore!"); |
| 2473 | unsigned RoundWidth = 1 << Log2_32(StWidth); |
| 2474 | assert(RoundWidth < StWidth); |
| 2475 | unsigned ExtraWidth = StWidth - RoundWidth; |
| 2476 | assert(ExtraWidth < RoundWidth); |
| 2477 | assert(!(RoundWidth % 8) && !(ExtraWidth % 8) && |
| 2478 | "Store size not an integral number of bytes!"); |
| 2479 | MVT::ValueType RoundVT = MVT::getIntegerType(RoundWidth); |
| 2480 | MVT::ValueType ExtraVT = MVT::getIntegerType(ExtraWidth); |
| 2481 | SDOperand Lo, Hi; |
| 2482 | unsigned IncrementSize; |
| 2483 | |
| 2484 | if (TLI.isLittleEndian()) { |
| 2485 | // TRUNCSTORE:i24 X -> TRUNCSTORE:i16 X, TRUNCSTORE@+2:i8 (srl X, 16) |
| 2486 | // Store the bottom RoundWidth bits. |
| 2487 | Lo = DAG.getTruncStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
| 2488 | SVOffset, RoundVT, |
| 2489 | isVolatile, Alignment); |
| 2490 | |
| 2491 | // Store the remaining ExtraWidth bits. |
| 2492 | IncrementSize = RoundWidth / 8; |
| 2493 | Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2, |
| 2494 | DAG.getIntPtrConstant(IncrementSize)); |
| 2495 | Hi = DAG.getNode(ISD::SRL, Tmp3.getValueType(), Tmp3, |
| 2496 | DAG.getConstant(RoundWidth, TLI.getShiftAmountTy())); |
| 2497 | Hi = DAG.getTruncStore(Tmp1, Hi, Tmp2, ST->getSrcValue(), |
| 2498 | SVOffset + IncrementSize, ExtraVT, isVolatile, |
| 2499 | MinAlign(Alignment, IncrementSize)); |
| 2500 | } else { |
| 2501 | // Big endian - avoid unaligned stores. |
| 2502 | // TRUNCSTORE:i24 X -> TRUNCSTORE:i16 (srl X, 8), TRUNCSTORE@+2:i8 X |
| 2503 | // Store the top RoundWidth bits. |
| 2504 | Hi = DAG.getNode(ISD::SRL, Tmp3.getValueType(), Tmp3, |
| 2505 | DAG.getConstant(ExtraWidth, TLI.getShiftAmountTy())); |
| 2506 | Hi = DAG.getTruncStore(Tmp1, Hi, Tmp2, ST->getSrcValue(), SVOffset, |
| 2507 | RoundVT, isVolatile, Alignment); |
| 2508 | |
| 2509 | // Store the remaining ExtraWidth bits. |
| 2510 | IncrementSize = RoundWidth / 8; |
| 2511 | Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2, |
| 2512 | DAG.getIntPtrConstant(IncrementSize)); |
| 2513 | Lo = DAG.getTruncStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
| 2514 | SVOffset + IncrementSize, ExtraVT, isVolatile, |
| 2515 | MinAlign(Alignment, IncrementSize)); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2516 | } |
Duncan Sands | 7e85720 | 2008-01-22 07:17:34 +0000 | [diff] [blame] | 2517 | |
| 2518 | // The order of the stores doesn't matter. |
| 2519 | Result = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo, Hi); |
| 2520 | } else { |
| 2521 | if (Tmp1 != ST->getChain() || Tmp3 != ST->getValue() || |
| 2522 | Tmp2 != ST->getBasePtr()) |
| 2523 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp3, Tmp2, |
| 2524 | ST->getOffset()); |
| 2525 | |
| 2526 | switch (TLI.getTruncStoreAction(ST->getValue().getValueType(), StVT)) { |
| 2527 | default: assert(0 && "This action is not supported yet!"); |
| 2528 | case TargetLowering::Legal: |
| 2529 | // If this is an unaligned store and the target doesn't support it, |
| 2530 | // expand it. |
| 2531 | if (!TLI.allowsUnalignedMemoryAccesses()) { |
| 2532 | unsigned ABIAlignment = TLI.getTargetData()-> |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 2533 | getABITypeAlignment(MVT::getTypeForValueType(ST->getMemoryVT())); |
Duncan Sands | 7e85720 | 2008-01-22 07:17:34 +0000 | [diff] [blame] | 2534 | if (ST->getAlignment() < ABIAlignment) |
| 2535 | Result = ExpandUnalignedStore(cast<StoreSDNode>(Result.Val), DAG, |
| 2536 | TLI); |
| 2537 | } |
| 2538 | break; |
| 2539 | case TargetLowering::Custom: |
| 2540 | Result = TLI.LowerOperation(Result, DAG); |
| 2541 | break; |
| 2542 | case Expand: |
| 2543 | // TRUNCSTORE:i16 i32 -> STORE i16 |
| 2544 | assert(isTypeLegal(StVT) && "Do not know how to expand this store!"); |
| 2545 | Tmp3 = DAG.getNode(ISD::TRUNCATE, StVT, Tmp3); |
| 2546 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), SVOffset, |
| 2547 | isVolatile, Alignment); |
| 2548 | break; |
| 2549 | } |
Evan Cheng | f3fd9fe | 2005-12-23 07:29:34 +0000 | [diff] [blame] | 2550 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2551 | } |
| 2552 | break; |
Evan Cheng | f3fd9fe | 2005-12-23 07:29:34 +0000 | [diff] [blame] | 2553 | } |
Andrew Lenharth | 9576212 | 2005-03-31 21:24:06 +0000 | [diff] [blame] | 2554 | case ISD::PCMARKER: |
| 2555 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2556 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
Andrew Lenharth | 9576212 | 2005-03-31 21:24:06 +0000 | [diff] [blame] | 2557 | break; |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2558 | case ISD::STACKSAVE: |
| 2559 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2560 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 2561 | Tmp1 = Result.getValue(0); |
| 2562 | Tmp2 = Result.getValue(1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2563 | |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2564 | switch (TLI.getOperationAction(ISD::STACKSAVE, MVT::Other)) { |
| 2565 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2566 | case TargetLowering::Legal: break; |
| 2567 | case TargetLowering::Custom: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2568 | Tmp3 = TLI.LowerOperation(Result, DAG); |
| 2569 | if (Tmp3.Val) { |
| 2570 | Tmp1 = LegalizeOp(Tmp3); |
| 2571 | Tmp2 = LegalizeOp(Tmp3.getValue(1)); |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2572 | } |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2573 | break; |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2574 | case TargetLowering::Expand: |
Chris Lattner | 4f0d8e4 | 2006-01-13 17:48:44 +0000 | [diff] [blame] | 2575 | // Expand to CopyFromReg if the target set |
| 2576 | // StackPointerRegisterToSaveRestore. |
| 2577 | if (unsigned SP = TLI.getStackPointerRegisterToSaveRestore()) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2578 | Tmp1 = DAG.getCopyFromReg(Result.getOperand(0), SP, |
Chris Lattner | 4f0d8e4 | 2006-01-13 17:48:44 +0000 | [diff] [blame] | 2579 | Node->getValueType(0)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2580 | Tmp2 = Tmp1.getValue(1); |
Chris Lattner | 4f0d8e4 | 2006-01-13 17:48:44 +0000 | [diff] [blame] | 2581 | } else { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2582 | Tmp1 = DAG.getNode(ISD::UNDEF, Node->getValueType(0)); |
| 2583 | Tmp2 = Node->getOperand(0); |
Chris Lattner | 4f0d8e4 | 2006-01-13 17:48:44 +0000 | [diff] [blame] | 2584 | } |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2585 | break; |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2586 | } |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2587 | |
| 2588 | // Since stacksave produce two values, make sure to remember that we |
| 2589 | // legalized both of them. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2590 | AddLegalizedOperand(SDOperand(Node, 0), Tmp1); |
| 2591 | AddLegalizedOperand(SDOperand(Node, 1), Tmp2); |
| 2592 | return Op.ResNo ? Tmp2 : Tmp1; |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2593 | |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2594 | case ISD::STACKRESTORE: |
| 2595 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 2596 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2597 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2598 | |
| 2599 | switch (TLI.getOperationAction(ISD::STACKRESTORE, MVT::Other)) { |
| 2600 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2601 | case TargetLowering::Legal: break; |
| 2602 | case TargetLowering::Custom: |
| 2603 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2604 | if (Tmp1.Val) Result = Tmp1; |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2605 | break; |
| 2606 | case TargetLowering::Expand: |
Chris Lattner | 4f0d8e4 | 2006-01-13 17:48:44 +0000 | [diff] [blame] | 2607 | // Expand to CopyToReg if the target set |
| 2608 | // StackPointerRegisterToSaveRestore. |
| 2609 | if (unsigned SP = TLI.getStackPointerRegisterToSaveRestore()) { |
| 2610 | Result = DAG.getCopyToReg(Tmp1, SP, Tmp2); |
| 2611 | } else { |
| 2612 | Result = Tmp1; |
| 2613 | } |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2614 | break; |
| 2615 | } |
| 2616 | break; |
| 2617 | |
Andrew Lenharth | 51b8d54 | 2005-11-11 16:47:30 +0000 | [diff] [blame] | 2618 | case ISD::READCYCLECOUNTER: |
| 2619 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2620 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Evan Cheng | f0b3ba6 | 2006-11-29 08:26:18 +0000 | [diff] [blame] | 2621 | switch (TLI.getOperationAction(ISD::READCYCLECOUNTER, |
| 2622 | Node->getValueType(0))) { |
| 2623 | default: assert(0 && "This action is not supported yet!"); |
Evan Cheng | 6a16c5a | 2006-11-29 19:13:47 +0000 | [diff] [blame] | 2624 | case TargetLowering::Legal: |
| 2625 | Tmp1 = Result.getValue(0); |
| 2626 | Tmp2 = Result.getValue(1); |
| 2627 | break; |
Evan Cheng | f0b3ba6 | 2006-11-29 08:26:18 +0000 | [diff] [blame] | 2628 | case TargetLowering::Custom: |
| 2629 | Result = TLI.LowerOperation(Result, DAG); |
Evan Cheng | 6a16c5a | 2006-11-29 19:13:47 +0000 | [diff] [blame] | 2630 | Tmp1 = LegalizeOp(Result.getValue(0)); |
| 2631 | Tmp2 = LegalizeOp(Result.getValue(1)); |
Evan Cheng | f0b3ba6 | 2006-11-29 08:26:18 +0000 | [diff] [blame] | 2632 | break; |
| 2633 | } |
Andrew Lenharth | 49c709f | 2005-12-02 04:56:24 +0000 | [diff] [blame] | 2634 | |
| 2635 | // Since rdcc produce two values, make sure to remember that we legalized |
| 2636 | // both of them. |
Evan Cheng | 6a16c5a | 2006-11-29 19:13:47 +0000 | [diff] [blame] | 2637 | AddLegalizedOperand(SDOperand(Node, 0), Tmp1); |
| 2638 | AddLegalizedOperand(SDOperand(Node, 1), Tmp2); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2639 | return Result; |
Andrew Lenharth | f70e30b | 2005-11-20 21:32:07 +0000 | [diff] [blame] | 2640 | |
Chris Lattner | 2ee743f | 2005-01-14 22:08:15 +0000 | [diff] [blame] | 2641 | case ISD::SELECT: |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 2642 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 2643 | case Expand: assert(0 && "It's impossible to expand bools"); |
| 2644 | case Legal: |
| 2645 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the condition. |
| 2646 | break; |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 2647 | case Promote: { |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 2648 | Tmp1 = PromoteOp(Node->getOperand(0)); // Promote the condition. |
Chris Lattner | b6c8060 | 2006-11-28 01:03:30 +0000 | [diff] [blame] | 2649 | // Make sure the condition is either zero or one. |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 2650 | unsigned BitWidth = Tmp1.getValueSizeInBits(); |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2651 | if (!DAG.MaskedValueIsZero(Tmp1, |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 2652 | APInt::getHighBitsSet(BitWidth, BitWidth-1))) |
Chris Lattner | b6c8060 | 2006-11-28 01:03:30 +0000 | [diff] [blame] | 2653 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, MVT::i1); |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 2654 | break; |
| 2655 | } |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 2656 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2657 | Tmp2 = LegalizeOp(Node->getOperand(1)); // TrueVal |
Chris Lattner | 2ee743f | 2005-01-14 22:08:15 +0000 | [diff] [blame] | 2658 | Tmp3 = LegalizeOp(Node->getOperand(2)); // FalseVal |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2659 | |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2660 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2661 | |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 2662 | switch (TLI.getOperationAction(ISD::SELECT, Tmp2.getValueType())) { |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2663 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2664 | case TargetLowering::Legal: break; |
| 2665 | case TargetLowering::Custom: { |
| 2666 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2667 | if (Tmp1.Val) Result = Tmp1; |
| 2668 | break; |
| 2669 | } |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 2670 | case TargetLowering::Expand: |
| 2671 | if (Tmp1.getOpcode() == ISD::SETCC) { |
| 2672 | Result = DAG.getSelectCC(Tmp1.getOperand(0), Tmp1.getOperand(1), |
| 2673 | Tmp2, Tmp3, |
| 2674 | cast<CondCodeSDNode>(Tmp1.getOperand(2))->get()); |
| 2675 | } else { |
| 2676 | Result = DAG.getSelectCC(Tmp1, |
| 2677 | DAG.getConstant(0, Tmp1.getValueType()), |
| 2678 | Tmp2, Tmp3, ISD::SETNE); |
| 2679 | } |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2680 | break; |
| 2681 | case TargetLowering::Promote: { |
| 2682 | MVT::ValueType NVT = |
| 2683 | TLI.getTypeToPromoteTo(ISD::SELECT, Tmp2.getValueType()); |
| 2684 | unsigned ExtOp, TruncOp; |
Evan Cheng | 41f6cbb | 2006-04-12 16:33:18 +0000 | [diff] [blame] | 2685 | if (MVT::isVector(Tmp2.getValueType())) { |
| 2686 | ExtOp = ISD::BIT_CONVERT; |
| 2687 | TruncOp = ISD::BIT_CONVERT; |
| 2688 | } else if (MVT::isInteger(Tmp2.getValueType())) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2689 | ExtOp = ISD::ANY_EXTEND; |
| 2690 | TruncOp = ISD::TRUNCATE; |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2691 | } else { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2692 | ExtOp = ISD::FP_EXTEND; |
| 2693 | TruncOp = ISD::FP_ROUND; |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2694 | } |
| 2695 | // Promote each of the values to the new type. |
| 2696 | Tmp2 = DAG.getNode(ExtOp, NVT, Tmp2); |
| 2697 | Tmp3 = DAG.getNode(ExtOp, NVT, Tmp3); |
| 2698 | // Perform the larger operation, then round down. |
| 2699 | Result = DAG.getNode(ISD::SELECT, NVT, Tmp1, Tmp2,Tmp3); |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 2700 | if (TruncOp != ISD::FP_ROUND) |
| 2701 | Result = DAG.getNode(TruncOp, Node->getValueType(0), Result); |
| 2702 | else |
| 2703 | Result = DAG.getNode(TruncOp, Node->getValueType(0), Result, |
| 2704 | DAG.getIntPtrConstant(0)); |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2705 | break; |
| 2706 | } |
| 2707 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2708 | break; |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 2709 | case ISD::SELECT_CC: { |
| 2710 | Tmp1 = Node->getOperand(0); // LHS |
| 2711 | Tmp2 = Node->getOperand(1); // RHS |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 2712 | Tmp3 = LegalizeOp(Node->getOperand(2)); // True |
| 2713 | Tmp4 = LegalizeOp(Node->getOperand(3)); // False |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 2714 | SDOperand CC = Node->getOperand(4); |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 2715 | |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 2716 | LegalizeSetCCOperands(Tmp1, Tmp2, CC); |
| 2717 | |
| 2718 | // If we didn't get both a LHS and RHS back from LegalizeSetCCOperands, |
| 2719 | // the LHS is a legal SETCC itself. In this case, we need to compare |
| 2720 | // the result against zero to select between true and false values. |
| 2721 | if (Tmp2.Val == 0) { |
| 2722 | Tmp2 = DAG.getConstant(0, Tmp1.getValueType()); |
| 2723 | CC = DAG.getCondCode(ISD::SETNE); |
| 2724 | } |
| 2725 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3, Tmp4, CC); |
| 2726 | |
| 2727 | // Everything is legal, see if we should expand this op or something. |
| 2728 | switch (TLI.getOperationAction(ISD::SELECT_CC, Tmp3.getValueType())) { |
| 2729 | default: assert(0 && "This action is not supported yet!"); |
| 2730 | case TargetLowering::Legal: break; |
| 2731 | case TargetLowering::Custom: |
| 2732 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2733 | if (Tmp1.Val) Result = Tmp1; |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 2734 | break; |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 2735 | } |
| 2736 | break; |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 2737 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2738 | case ISD::SETCC: |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 2739 | Tmp1 = Node->getOperand(0); |
| 2740 | Tmp2 = Node->getOperand(1); |
| 2741 | Tmp3 = Node->getOperand(2); |
| 2742 | LegalizeSetCCOperands(Tmp1, Tmp2, Tmp3); |
| 2743 | |
| 2744 | // If we had to Expand the SetCC operands into a SELECT node, then it may |
| 2745 | // not always be possible to return a true LHS & RHS. In this case, just |
| 2746 | // return the value we legalized, returned in the LHS |
| 2747 | if (Tmp2.Val == 0) { |
| 2748 | Result = Tmp1; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2749 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2750 | } |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 2751 | |
Chris Lattner | 73e142f | 2006-01-30 22:43:50 +0000 | [diff] [blame] | 2752 | switch (TLI.getOperationAction(ISD::SETCC, Tmp1.getValueType())) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2753 | default: assert(0 && "Cannot handle this action for SETCC yet!"); |
| 2754 | case TargetLowering::Custom: |
| 2755 | isCustom = true; |
| 2756 | // FALLTHROUGH. |
| 2757 | case TargetLowering::Legal: |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 2758 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2759 | if (isCustom) { |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 2760 | Tmp4 = TLI.LowerOperation(Result, DAG); |
| 2761 | if (Tmp4.Val) Result = Tmp4; |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2762 | } |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 2763 | break; |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 2764 | case TargetLowering::Promote: { |
| 2765 | // First step, figure out the appropriate operation to use. |
| 2766 | // Allow SETCC to not be supported for all legal data types |
| 2767 | // Mostly this targets FP |
| 2768 | MVT::ValueType NewInTy = Node->getOperand(0).getValueType(); |
Chris Lattner | 00755df | 2007-02-04 00:27:56 +0000 | [diff] [blame] | 2769 | MVT::ValueType OldVT = NewInTy; OldVT = OldVT; |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 2770 | |
| 2771 | // Scan for the appropriate larger type to use. |
| 2772 | while (1) { |
| 2773 | NewInTy = (MVT::ValueType)(NewInTy+1); |
| 2774 | |
| 2775 | assert(MVT::isInteger(NewInTy) == MVT::isInteger(OldVT) && |
| 2776 | "Fell off of the edge of the integer world"); |
| 2777 | assert(MVT::isFloatingPoint(NewInTy) == MVT::isFloatingPoint(OldVT) && |
| 2778 | "Fell off of the edge of the floating point world"); |
| 2779 | |
| 2780 | // If the target supports SETCC of this type, use it. |
Chris Lattner | 1ccf26a | 2005-12-22 05:23:45 +0000 | [diff] [blame] | 2781 | if (TLI.isOperationLegal(ISD::SETCC, NewInTy)) |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 2782 | break; |
| 2783 | } |
| 2784 | if (MVT::isInteger(NewInTy)) |
| 2785 | assert(0 && "Cannot promote Legal Integer SETCC yet"); |
| 2786 | else { |
| 2787 | Tmp1 = DAG.getNode(ISD::FP_EXTEND, NewInTy, Tmp1); |
| 2788 | Tmp2 = DAG.getNode(ISD::FP_EXTEND, NewInTy, Tmp2); |
| 2789 | } |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2790 | Tmp1 = LegalizeOp(Tmp1); |
| 2791 | Tmp2 = LegalizeOp(Tmp2); |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 2792 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Evan Cheng | 433f8ac | 2006-01-17 19:47:13 +0000 | [diff] [blame] | 2793 | Result = LegalizeOp(Result); |
Andrew Lenharth | 5e3efbc | 2005-08-29 20:46:51 +0000 | [diff] [blame] | 2794 | break; |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 2795 | } |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 2796 | case TargetLowering::Expand: |
| 2797 | // Expand a setcc node into a select_cc of the same condition, lhs, and |
| 2798 | // rhs that selects between const 1 (true) and const 0 (false). |
| 2799 | MVT::ValueType VT = Node->getValueType(0); |
| 2800 | Result = DAG.getNode(ISD::SELECT_CC, VT, Tmp1, Tmp2, |
| 2801 | DAG.getConstant(1, VT), DAG.getConstant(0, VT), |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 2802 | Tmp3); |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 2803 | break; |
| 2804 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2805 | break; |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 2806 | case ISD::MEMSET: |
| 2807 | case ISD::MEMCPY: |
| 2808 | case ISD::MEMMOVE: { |
Chris Lattner | deb692e | 2005-02-01 18:38:28 +0000 | [diff] [blame] | 2809 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Chain |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 2810 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Pointer |
| 2811 | |
| 2812 | if (Node->getOpcode() == ISD::MEMSET) { // memset = ubyte |
| 2813 | switch (getTypeAction(Node->getOperand(2).getValueType())) { |
| 2814 | case Expand: assert(0 && "Cannot expand a byte!"); |
| 2815 | case Legal: |
Chris Lattner | deb692e | 2005-02-01 18:38:28 +0000 | [diff] [blame] | 2816 | Tmp3 = LegalizeOp(Node->getOperand(2)); |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 2817 | break; |
| 2818 | case Promote: |
Chris Lattner | deb692e | 2005-02-01 18:38:28 +0000 | [diff] [blame] | 2819 | Tmp3 = PromoteOp(Node->getOperand(2)); |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 2820 | break; |
| 2821 | } |
| 2822 | } else { |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2823 | Tmp3 = LegalizeOp(Node->getOperand(2)); // memcpy/move = pointer, |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 2824 | } |
Chris Lattner | 272455b | 2005-02-02 03:44:41 +0000 | [diff] [blame] | 2825 | |
| 2826 | SDOperand Tmp4; |
| 2827 | switch (getTypeAction(Node->getOperand(3).getValueType())) { |
Chris Lattner | 6814f15 | 2005-07-13 01:42:45 +0000 | [diff] [blame] | 2828 | case Expand: { |
| 2829 | // Length is too big, just take the lo-part of the length. |
| 2830 | SDOperand HiPart; |
Chris Lattner | fa9aa2b | 2006-11-07 04:11:44 +0000 | [diff] [blame] | 2831 | ExpandOp(Node->getOperand(3), Tmp4, HiPart); |
Chris Lattner | 6814f15 | 2005-07-13 01:42:45 +0000 | [diff] [blame] | 2832 | break; |
| 2833 | } |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 2834 | case Legal: |
| 2835 | Tmp4 = LegalizeOp(Node->getOperand(3)); |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 2836 | break; |
| 2837 | case Promote: |
| 2838 | Tmp4 = PromoteOp(Node->getOperand(3)); |
Chris Lattner | 272455b | 2005-02-02 03:44:41 +0000 | [diff] [blame] | 2839 | break; |
| 2840 | } |
| 2841 | |
| 2842 | SDOperand Tmp5; |
| 2843 | switch (getTypeAction(Node->getOperand(4).getValueType())) { // uint |
| 2844 | case Expand: assert(0 && "Cannot expand this yet!"); |
| 2845 | case Legal: |
| 2846 | Tmp5 = LegalizeOp(Node->getOperand(4)); |
| 2847 | break; |
| 2848 | case Promote: |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 2849 | Tmp5 = PromoteOp(Node->getOperand(4)); |
| 2850 | break; |
| 2851 | } |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2852 | |
Rafael Espindola | 5c0d6ed | 2007-10-19 10:41:11 +0000 | [diff] [blame] | 2853 | SDOperand Tmp6; |
| 2854 | switch (getTypeAction(Node->getOperand(5).getValueType())) { // bool |
| 2855 | case Expand: assert(0 && "Cannot expand this yet!"); |
| 2856 | case Legal: |
| 2857 | Tmp6 = LegalizeOp(Node->getOperand(5)); |
| 2858 | break; |
| 2859 | case Promote: |
| 2860 | Tmp6 = PromoteOp(Node->getOperand(5)); |
| 2861 | break; |
| 2862 | } |
| 2863 | |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2864 | switch (TLI.getOperationAction(Node->getOpcode(), MVT::Other)) { |
| 2865 | default: assert(0 && "This action not implemented for this operation!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2866 | case TargetLowering::Custom: |
| 2867 | isCustom = true; |
| 2868 | // FALLTHROUGH |
Rafael Espindola | 5c0d6ed | 2007-10-19 10:41:11 +0000 | [diff] [blame] | 2869 | case TargetLowering::Legal: { |
| 2870 | SDOperand Ops[] = { Tmp1, Tmp2, Tmp3, Tmp4, Tmp5, Tmp6 }; |
| 2871 | Result = DAG.UpdateNodeOperands(Result, Ops, 6); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2872 | if (isCustom) { |
| 2873 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2874 | if (Tmp1.Val) Result = Tmp1; |
| 2875 | } |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2876 | break; |
Rafael Espindola | 5c0d6ed | 2007-10-19 10:41:11 +0000 | [diff] [blame] | 2877 | } |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2878 | case TargetLowering::Expand: { |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 2879 | // Otherwise, the target does not support this operation. Lower the |
| 2880 | // operation to an explicit libcall as appropriate. |
| 2881 | MVT::ValueType IntPtr = TLI.getPointerTy(); |
Owen Anderson | a69571c | 2006-05-03 01:29:57 +0000 | [diff] [blame] | 2882 | const Type *IntPtrTy = TLI.getTargetData()->getIntPtrType(); |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 2883 | TargetLowering::ArgListTy Args; |
| 2884 | TargetLowering::ArgListEntry Entry; |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 2885 | |
Reid Spencer | 3bfbf4e | 2005-01-12 14:53:45 +0000 | [diff] [blame] | 2886 | const char *FnName = 0; |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 2887 | if (Node->getOpcode() == ISD::MEMSET) { |
Anton Korobeynikov | d0b82b3 | 2007-03-07 16:25:09 +0000 | [diff] [blame] | 2888 | Entry.Node = Tmp2; Entry.Ty = IntPtrTy; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 2889 | Args.push_back(Entry); |
Chris Lattner | dca7abe | 2006-02-20 06:38:35 +0000 | [diff] [blame] | 2890 | // Extend the (previously legalized) ubyte argument to be an int value |
| 2891 | // for the call. |
| 2892 | if (Tmp3.getValueType() > MVT::i32) |
| 2893 | Tmp3 = DAG.getNode(ISD::TRUNCATE, MVT::i32, Tmp3); |
| 2894 | else |
| 2895 | Tmp3 = DAG.getNode(ISD::ZERO_EXTEND, MVT::i32, Tmp3); |
Anton Korobeynikov | d0b82b3 | 2007-03-07 16:25:09 +0000 | [diff] [blame] | 2896 | Entry.Node = Tmp3; Entry.Ty = Type::Int32Ty; Entry.isSExt = true; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 2897 | Args.push_back(Entry); |
Anton Korobeynikov | d0b82b3 | 2007-03-07 16:25:09 +0000 | [diff] [blame] | 2898 | Entry.Node = Tmp4; Entry.Ty = IntPtrTy; Entry.isSExt = false; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 2899 | Args.push_back(Entry); |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 2900 | |
| 2901 | FnName = "memset"; |
| 2902 | } else if (Node->getOpcode() == ISD::MEMCPY || |
| 2903 | Node->getOpcode() == ISD::MEMMOVE) { |
Anton Korobeynikov | b25fe82 | 2007-02-01 08:39:52 +0000 | [diff] [blame] | 2904 | Entry.Ty = IntPtrTy; |
Reid Spencer | b47b25c | 2007-01-03 04:22:32 +0000 | [diff] [blame] | 2905 | Entry.Node = Tmp2; Args.push_back(Entry); |
| 2906 | Entry.Node = Tmp3; Args.push_back(Entry); |
| 2907 | Entry.Node = Tmp4; Args.push_back(Entry); |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 2908 | FnName = Node->getOpcode() == ISD::MEMMOVE ? "memmove" : "memcpy"; |
| 2909 | } else { |
| 2910 | assert(0 && "Unknown op!"); |
| 2911 | } |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 2912 | |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 2913 | std::pair<SDOperand,SDOperand> CallResult = |
Duncan Sands | 00fee65 | 2008-02-14 17:28:50 +0000 | [diff] [blame] | 2914 | TLI.LowerCallTo(Tmp1, Type::VoidTy, |
| 2915 | false, false, false, CallingConv::C, false, |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 2916 | DAG.getExternalSymbol(FnName, IntPtr), Args, DAG); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2917 | Result = CallResult.second; |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2918 | break; |
| 2919 | } |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 2920 | } |
| 2921 | break; |
| 2922 | } |
Chris Lattner | 52d08bd | 2005-05-09 20:23:03 +0000 | [diff] [blame] | 2923 | |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 2924 | case ISD::SHL_PARTS: |
| 2925 | case ISD::SRA_PARTS: |
| 2926 | case ISD::SRL_PARTS: { |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 2927 | SmallVector<SDOperand, 8> Ops; |
Chris Lattner | 84f6788 | 2005-01-20 18:52:28 +0000 | [diff] [blame] | 2928 | bool Changed = false; |
| 2929 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) { |
| 2930 | Ops.push_back(LegalizeOp(Node->getOperand(i))); |
| 2931 | Changed |= Ops.back() != Node->getOperand(i); |
| 2932 | } |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2933 | if (Changed) |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 2934 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 2935 | |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 2936 | switch (TLI.getOperationAction(Node->getOpcode(), |
| 2937 | Node->getValueType(0))) { |
| 2938 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2939 | case TargetLowering::Legal: break; |
| 2940 | case TargetLowering::Custom: |
| 2941 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2942 | if (Tmp1.Val) { |
| 2943 | SDOperand Tmp2, RetVal(0, 0); |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 2944 | for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2945 | Tmp2 = LegalizeOp(Tmp1.getValue(i)); |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 2946 | AddLegalizedOperand(SDOperand(Node, i), Tmp2); |
| 2947 | if (i == Op.ResNo) |
Evan Cheng | 12f2274 | 2006-01-19 04:54:52 +0000 | [diff] [blame] | 2948 | RetVal = Tmp2; |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 2949 | } |
Chris Lattner | 269f8c0 | 2006-01-10 19:43:26 +0000 | [diff] [blame] | 2950 | assert(RetVal.Val && "Illegal result number"); |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 2951 | return RetVal; |
| 2952 | } |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 2953 | break; |
| 2954 | } |
| 2955 | |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 2956 | // Since these produce multiple values, make sure to remember that we |
| 2957 | // legalized all of them. |
| 2958 | for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) |
| 2959 | AddLegalizedOperand(SDOperand(Node, i), Result.getValue(i)); |
| 2960 | return Result.getValue(Op.ResNo); |
Chris Lattner | 84f6788 | 2005-01-20 18:52:28 +0000 | [diff] [blame] | 2961 | } |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 2962 | |
| 2963 | // Binary operators |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2964 | case ISD::ADD: |
| 2965 | case ISD::SUB: |
| 2966 | case ISD::MUL: |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 2967 | case ISD::MULHS: |
| 2968 | case ISD::MULHU: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2969 | case ISD::UDIV: |
| 2970 | case ISD::SDIV: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2971 | case ISD::AND: |
| 2972 | case ISD::OR: |
| 2973 | case ISD::XOR: |
Chris Lattner | 03c0cf8 | 2005-01-07 21:45:56 +0000 | [diff] [blame] | 2974 | case ISD::SHL: |
| 2975 | case ISD::SRL: |
| 2976 | case ISD::SRA: |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 2977 | case ISD::FADD: |
| 2978 | case ISD::FSUB: |
| 2979 | case ISD::FMUL: |
| 2980 | case ISD::FDIV: |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 2981 | case ISD::FPOW: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2982 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
Andrew Lenharth | f2eb139 | 2005-07-05 19:52:39 +0000 | [diff] [blame] | 2983 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 2984 | case Expand: assert(0 && "Not possible"); |
| 2985 | case Legal: |
| 2986 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the RHS. |
| 2987 | break; |
| 2988 | case Promote: |
| 2989 | Tmp2 = PromoteOp(Node->getOperand(1)); // Promote the RHS. |
| 2990 | break; |
| 2991 | } |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2992 | |
| 2993 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2994 | |
Andrew Lenharth | e8f65f1 | 2005-12-24 23:42:32 +0000 | [diff] [blame] | 2995 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
Chris Lattner | bc70cf8 | 2006-04-02 03:57:31 +0000 | [diff] [blame] | 2996 | default: assert(0 && "BinOp legalize operation not supported"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2997 | case TargetLowering::Legal: break; |
| 2998 | case TargetLowering::Custom: |
| 2999 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 3000 | if (Tmp1.Val) Result = Tmp1; |
Andrew Lenharth | 57030e3 | 2005-12-25 01:07:37 +0000 | [diff] [blame] | 3001 | break; |
Chris Lattner | bc70cf8 | 2006-04-02 03:57:31 +0000 | [diff] [blame] | 3002 | case TargetLowering::Expand: { |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3003 | MVT::ValueType VT = Op.getValueType(); |
| 3004 | |
| 3005 | // See if multiply or divide can be lowered using two-result operations. |
| 3006 | SDVTList VTs = DAG.getVTList(VT, VT); |
| 3007 | if (Node->getOpcode() == ISD::MUL) { |
| 3008 | // We just need the low half of the multiply; try both the signed |
| 3009 | // and unsigned forms. If the target supports both SMUL_LOHI and |
| 3010 | // UMUL_LOHI, form a preference by checking which forms of plain |
| 3011 | // MULH it supports. |
| 3012 | bool HasSMUL_LOHI = TLI.isOperationLegal(ISD::SMUL_LOHI, VT); |
| 3013 | bool HasUMUL_LOHI = TLI.isOperationLegal(ISD::UMUL_LOHI, VT); |
| 3014 | bool HasMULHS = TLI.isOperationLegal(ISD::MULHS, VT); |
| 3015 | bool HasMULHU = TLI.isOperationLegal(ISD::MULHU, VT); |
| 3016 | unsigned OpToUse = 0; |
| 3017 | if (HasSMUL_LOHI && !HasMULHS) { |
| 3018 | OpToUse = ISD::SMUL_LOHI; |
| 3019 | } else if (HasUMUL_LOHI && !HasMULHU) { |
| 3020 | OpToUse = ISD::UMUL_LOHI; |
| 3021 | } else if (HasSMUL_LOHI) { |
| 3022 | OpToUse = ISD::SMUL_LOHI; |
| 3023 | } else if (HasUMUL_LOHI) { |
| 3024 | OpToUse = ISD::UMUL_LOHI; |
| 3025 | } |
| 3026 | if (OpToUse) { |
| 3027 | Result = SDOperand(DAG.getNode(OpToUse, VTs, Tmp1, Tmp2).Val, 0); |
| 3028 | break; |
| 3029 | } |
| 3030 | } |
| 3031 | if (Node->getOpcode() == ISD::MULHS && |
| 3032 | TLI.isOperationLegal(ISD::SMUL_LOHI, VT)) { |
| 3033 | Result = SDOperand(DAG.getNode(ISD::SMUL_LOHI, VTs, Tmp1, Tmp2).Val, 1); |
| 3034 | break; |
| 3035 | } |
| 3036 | if (Node->getOpcode() == ISD::MULHU && |
| 3037 | TLI.isOperationLegal(ISD::UMUL_LOHI, VT)) { |
| 3038 | Result = SDOperand(DAG.getNode(ISD::UMUL_LOHI, VTs, Tmp1, Tmp2).Val, 1); |
| 3039 | break; |
| 3040 | } |
| 3041 | if (Node->getOpcode() == ISD::SDIV && |
| 3042 | TLI.isOperationLegal(ISD::SDIVREM, VT)) { |
| 3043 | Result = SDOperand(DAG.getNode(ISD::SDIVREM, VTs, Tmp1, Tmp2).Val, 0); |
| 3044 | break; |
| 3045 | } |
| 3046 | if (Node->getOpcode() == ISD::UDIV && |
| 3047 | TLI.isOperationLegal(ISD::UDIVREM, VT)) { |
| 3048 | Result = SDOperand(DAG.getNode(ISD::UDIVREM, VTs, Tmp1, Tmp2).Val, 0); |
| 3049 | break; |
| 3050 | } |
| 3051 | |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3052 | // Check to see if we have a libcall for this operator. |
| 3053 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
| 3054 | bool isSigned = false; |
| 3055 | switch (Node->getOpcode()) { |
| 3056 | case ISD::UDIV: |
| 3057 | case ISD::SDIV: |
| 3058 | if (VT == MVT::i32) { |
| 3059 | LC = Node->getOpcode() == ISD::UDIV |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3060 | ? RTLIB::UDIV_I32 : RTLIB::SDIV_I32; |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3061 | isSigned = Node->getOpcode() == ISD::SDIV; |
| 3062 | } |
| 3063 | break; |
| 3064 | case ISD::FPOW: |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 3065 | LC = GetFPLibCall(VT, RTLIB::POW_F32, RTLIB::POW_F64, RTLIB::POW_F80, |
| 3066 | RTLIB::POW_PPCF128); |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3067 | break; |
| 3068 | default: break; |
| 3069 | } |
| 3070 | if (LC != RTLIB::UNKNOWN_LIBCALL) { |
| 3071 | SDOperand Dummy; |
| 3072 | Result = ExpandLibCall(TLI.getLibcallName(LC), Node, isSigned, Dummy); |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 3073 | break; |
| 3074 | } |
| 3075 | |
Chris Lattner | bc70cf8 | 2006-04-02 03:57:31 +0000 | [diff] [blame] | 3076 | assert(MVT::isVector(Node->getValueType(0)) && |
| 3077 | "Cannot expand this binary operator!"); |
| 3078 | // Expand the operation into a bunch of nasty scalar code. |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3079 | Result = LegalizeOp(UnrollVectorOp(Op)); |
Chris Lattner | bc70cf8 | 2006-04-02 03:57:31 +0000 | [diff] [blame] | 3080 | break; |
| 3081 | } |
Evan Cheng | cc98761 | 2006-04-12 21:20:24 +0000 | [diff] [blame] | 3082 | case TargetLowering::Promote: { |
| 3083 | switch (Node->getOpcode()) { |
| 3084 | default: assert(0 && "Do not know how to promote this BinOp!"); |
| 3085 | case ISD::AND: |
| 3086 | case ISD::OR: |
| 3087 | case ISD::XOR: { |
| 3088 | MVT::ValueType OVT = Node->getValueType(0); |
| 3089 | MVT::ValueType NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT); |
| 3090 | assert(MVT::isVector(OVT) && "Cannot promote this BinOp!"); |
| 3091 | // Bit convert each of the values to the new type. |
| 3092 | Tmp1 = DAG.getNode(ISD::BIT_CONVERT, NVT, Tmp1); |
| 3093 | Tmp2 = DAG.getNode(ISD::BIT_CONVERT, NVT, Tmp2); |
| 3094 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 3095 | // Bit convert the result back the original type. |
| 3096 | Result = DAG.getNode(ISD::BIT_CONVERT, OVT, Result); |
| 3097 | break; |
| 3098 | } |
| 3099 | } |
| 3100 | } |
Andrew Lenharth | e8f65f1 | 2005-12-24 23:42:32 +0000 | [diff] [blame] | 3101 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3102 | break; |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 3103 | |
Dan Gohman | e14ea86 | 2007-10-05 14:17:22 +0000 | [diff] [blame] | 3104 | case ISD::SMUL_LOHI: |
| 3105 | case ISD::UMUL_LOHI: |
| 3106 | case ISD::SDIVREM: |
| 3107 | case ISD::UDIVREM: |
| 3108 | // These nodes will only be produced by target-specific lowering, so |
| 3109 | // they shouldn't be here if they aren't legal. |
Duncan Sands | a7c97a7 | 2007-10-16 09:07:20 +0000 | [diff] [blame] | 3110 | assert(TLI.isOperationLegal(Node->getOpcode(), Node->getValueType(0)) && |
Dan Gohman | e14ea86 | 2007-10-05 14:17:22 +0000 | [diff] [blame] | 3111 | "This must be legal!"); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3112 | |
| 3113 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
| 3114 | Tmp2 = LegalizeOp(Node->getOperand(1)); // RHS |
| 3115 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Dan Gohman | e14ea86 | 2007-10-05 14:17:22 +0000 | [diff] [blame] | 3116 | break; |
| 3117 | |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 3118 | case ISD::FCOPYSIGN: // FCOPYSIGN does not require LHS/RHS to match type! |
| 3119 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
| 3120 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 3121 | case Expand: assert(0 && "Not possible"); |
| 3122 | case Legal: |
| 3123 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the RHS. |
| 3124 | break; |
| 3125 | case Promote: |
| 3126 | Tmp2 = PromoteOp(Node->getOperand(1)); // Promote the RHS. |
| 3127 | break; |
| 3128 | } |
| 3129 | |
| 3130 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 3131 | |
| 3132 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 3133 | default: assert(0 && "Operation not supported"); |
| 3134 | case TargetLowering::Custom: |
| 3135 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 3136 | if (Tmp1.Val) Result = Tmp1; |
Chris Lattner | 8f4191d | 2006-03-13 06:08:38 +0000 | [diff] [blame] | 3137 | break; |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 3138 | case TargetLowering::Legal: break; |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 3139 | case TargetLowering::Expand: { |
Evan Cheng | 636c753 | 2007-01-05 23:33:44 +0000 | [diff] [blame] | 3140 | // If this target supports fabs/fneg natively and select is cheap, |
| 3141 | // do this efficiently. |
| 3142 | if (!TLI.isSelectExpensive() && |
| 3143 | TLI.getOperationAction(ISD::FABS, Tmp1.getValueType()) == |
| 3144 | TargetLowering::Legal && |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 3145 | TLI.getOperationAction(ISD::FNEG, Tmp1.getValueType()) == |
Evan Cheng | 636c753 | 2007-01-05 23:33:44 +0000 | [diff] [blame] | 3146 | TargetLowering::Legal) { |
Chris Lattner | 8f4191d | 2006-03-13 06:08:38 +0000 | [diff] [blame] | 3147 | // Get the sign bit of the RHS. |
| 3148 | MVT::ValueType IVT = |
| 3149 | Tmp2.getValueType() == MVT::f32 ? MVT::i32 : MVT::i64; |
| 3150 | SDOperand SignBit = DAG.getNode(ISD::BIT_CONVERT, IVT, Tmp2); |
| 3151 | SignBit = DAG.getSetCC(TLI.getSetCCResultTy(), |
| 3152 | SignBit, DAG.getConstant(0, IVT), ISD::SETLT); |
| 3153 | // Get the absolute value of the result. |
| 3154 | SDOperand AbsVal = DAG.getNode(ISD::FABS, Tmp1.getValueType(), Tmp1); |
| 3155 | // Select between the nabs and abs value based on the sign bit of |
| 3156 | // the input. |
| 3157 | Result = DAG.getNode(ISD::SELECT, AbsVal.getValueType(), SignBit, |
| 3158 | DAG.getNode(ISD::FNEG, AbsVal.getValueType(), |
| 3159 | AbsVal), |
| 3160 | AbsVal); |
| 3161 | Result = LegalizeOp(Result); |
| 3162 | break; |
| 3163 | } |
| 3164 | |
| 3165 | // Otherwise, do bitwise ops! |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 3166 | MVT::ValueType NVT = |
| 3167 | Node->getValueType(0) == MVT::f32 ? MVT::i32 : MVT::i64; |
| 3168 | Result = ExpandFCOPYSIGNToBitwiseOps(Node, NVT, DAG, TLI); |
| 3169 | Result = DAG.getNode(ISD::BIT_CONVERT, Node->getValueType(0), Result); |
| 3170 | Result = LegalizeOp(Result); |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 3171 | break; |
| 3172 | } |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 3173 | } |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 3174 | break; |
| 3175 | |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 3176 | case ISD::ADDC: |
| 3177 | case ISD::SUBC: |
| 3178 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 3179 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 3180 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 3181 | // Since this produces two values, make sure to remember that we legalized |
| 3182 | // both of them. |
| 3183 | AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0)); |
| 3184 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
| 3185 | return Result; |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 3186 | |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 3187 | case ISD::ADDE: |
| 3188 | case ISD::SUBE: |
| 3189 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 3190 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 3191 | Tmp3 = LegalizeOp(Node->getOperand(2)); |
| 3192 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
| 3193 | // Since this produces two values, make sure to remember that we legalized |
| 3194 | // both of them. |
| 3195 | AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0)); |
| 3196 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
| 3197 | return Result; |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 3198 | |
Nate Begeman | 419f8b6 | 2005-10-18 00:27:41 +0000 | [diff] [blame] | 3199 | case ISD::BUILD_PAIR: { |
| 3200 | MVT::ValueType PairTy = Node->getValueType(0); |
| 3201 | // TODO: handle the case where the Lo and Hi operands are not of legal type |
| 3202 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Lo |
| 3203 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Hi |
| 3204 | switch (TLI.getOperationAction(ISD::BUILD_PAIR, PairTy)) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3205 | case TargetLowering::Promote: |
| 3206 | case TargetLowering::Custom: |
| 3207 | assert(0 && "Cannot promote/custom this yet!"); |
Nate Begeman | 419f8b6 | 2005-10-18 00:27:41 +0000 | [diff] [blame] | 3208 | case TargetLowering::Legal: |
| 3209 | if (Tmp1 != Node->getOperand(0) || Tmp2 != Node->getOperand(1)) |
| 3210 | Result = DAG.getNode(ISD::BUILD_PAIR, PairTy, Tmp1, Tmp2); |
| 3211 | break; |
Nate Begeman | 419f8b6 | 2005-10-18 00:27:41 +0000 | [diff] [blame] | 3212 | case TargetLowering::Expand: |
| 3213 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, PairTy, Tmp1); |
| 3214 | Tmp2 = DAG.getNode(ISD::ANY_EXTEND, PairTy, Tmp2); |
| 3215 | Tmp2 = DAG.getNode(ISD::SHL, PairTy, Tmp2, |
| 3216 | DAG.getConstant(MVT::getSizeInBits(PairTy)/2, |
| 3217 | TLI.getShiftAmountTy())); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3218 | Result = DAG.getNode(ISD::OR, PairTy, Tmp1, Tmp2); |
Nate Begeman | 419f8b6 | 2005-10-18 00:27:41 +0000 | [diff] [blame] | 3219 | break; |
| 3220 | } |
| 3221 | break; |
| 3222 | } |
| 3223 | |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 3224 | case ISD::UREM: |
| 3225 | case ISD::SREM: |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 3226 | case ISD::FREM: |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 3227 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
| 3228 | Tmp2 = LegalizeOp(Node->getOperand(1)); // RHS |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3229 | |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 3230 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3231 | case TargetLowering::Promote: assert(0 && "Cannot promote this yet!"); |
| 3232 | case TargetLowering::Custom: |
| 3233 | isCustom = true; |
| 3234 | // FALLTHROUGH |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 3235 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3236 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3237 | if (isCustom) { |
| 3238 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 3239 | if (Tmp1.Val) Result = Tmp1; |
| 3240 | } |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 3241 | break; |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3242 | case TargetLowering::Expand: { |
Evan Cheng | 6b5578f | 2006-09-18 23:28:33 +0000 | [diff] [blame] | 3243 | unsigned DivOpc= (Node->getOpcode() == ISD::UREM) ? ISD::UDIV : ISD::SDIV; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 3244 | bool isSigned = DivOpc == ISD::SDIV; |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3245 | MVT::ValueType VT = Node->getValueType(0); |
| 3246 | |
| 3247 | // See if remainder can be lowered using two-result operations. |
| 3248 | SDVTList VTs = DAG.getVTList(VT, VT); |
| 3249 | if (Node->getOpcode() == ISD::SREM && |
| 3250 | TLI.isOperationLegal(ISD::SDIVREM, VT)) { |
| 3251 | Result = SDOperand(DAG.getNode(ISD::SDIVREM, VTs, Tmp1, Tmp2).Val, 1); |
| 3252 | break; |
| 3253 | } |
| 3254 | if (Node->getOpcode() == ISD::UREM && |
| 3255 | TLI.isOperationLegal(ISD::UDIVREM, VT)) { |
| 3256 | Result = SDOperand(DAG.getNode(ISD::UDIVREM, VTs, Tmp1, Tmp2).Val, 1); |
| 3257 | break; |
| 3258 | } |
| 3259 | |
| 3260 | if (MVT::isInteger(VT)) { |
| 3261 | if (TLI.getOperationAction(DivOpc, VT) == |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 3262 | TargetLowering::Legal) { |
| 3263 | // X % Y -> X-X/Y*Y |
Evan Cheng | 6b5578f | 2006-09-18 23:28:33 +0000 | [diff] [blame] | 3264 | Result = DAG.getNode(DivOpc, VT, Tmp1, Tmp2); |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 3265 | Result = DAG.getNode(ISD::MUL, VT, Result, Tmp2); |
| 3266 | Result = DAG.getNode(ISD::SUB, VT, Tmp1, Result); |
Dan Gohman | 8017631 | 2007-11-05 23:35:22 +0000 | [diff] [blame] | 3267 | } else if (MVT::isVector(VT)) { |
| 3268 | Result = LegalizeOp(UnrollVectorOp(Op)); |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 3269 | } else { |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3270 | assert(VT == MVT::i32 && |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 3271 | "Cannot expand this binary operator!"); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3272 | RTLIB::Libcall LC = Node->getOpcode() == ISD::UREM |
| 3273 | ? RTLIB::UREM_I32 : RTLIB::SREM_I32; |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 3274 | SDOperand Dummy; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3275 | Result = ExpandLibCall(TLI.getLibcallName(LC), Node, isSigned, Dummy); |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 3276 | } |
Dan Gohman | 0d97426 | 2007-11-06 22:11:54 +0000 | [diff] [blame] | 3277 | } else { |
| 3278 | assert(MVT::isFloatingPoint(VT) && |
| 3279 | "remainder op must have integer or floating-point type"); |
Dan Gohman | 8017631 | 2007-11-05 23:35:22 +0000 | [diff] [blame] | 3280 | if (MVT::isVector(VT)) { |
| 3281 | Result = LegalizeOp(UnrollVectorOp(Op)); |
| 3282 | } else { |
| 3283 | // Floating point mod -> fmod libcall. |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 3284 | RTLIB::Libcall LC = GetFPLibCall(VT, RTLIB::REM_F32, RTLIB::REM_F64, |
| 3285 | RTLIB::REM_F80, RTLIB::REM_PPCF128); |
Dan Gohman | 8017631 | 2007-11-05 23:35:22 +0000 | [diff] [blame] | 3286 | SDOperand Dummy; |
| 3287 | Result = ExpandLibCall(TLI.getLibcallName(LC), Node, |
| 3288 | false/*sign irrelevant*/, Dummy); |
| 3289 | } |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 3290 | } |
| 3291 | break; |
| 3292 | } |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3293 | } |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 3294 | break; |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3295 | case ISD::VAARG: { |
| 3296 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 3297 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. |
| 3298 | |
Chris Lattner | 5c62f33 | 2006-01-28 07:42:08 +0000 | [diff] [blame] | 3299 | MVT::ValueType VT = Node->getValueType(0); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3300 | switch (TLI.getOperationAction(Node->getOpcode(), MVT::Other)) { |
| 3301 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3302 | case TargetLowering::Custom: |
| 3303 | isCustom = true; |
| 3304 | // FALLTHROUGH |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3305 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3306 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
| 3307 | Result = Result.getValue(0); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3308 | Tmp1 = Result.getValue(1); |
| 3309 | |
| 3310 | if (isCustom) { |
| 3311 | Tmp2 = TLI.LowerOperation(Result, DAG); |
| 3312 | if (Tmp2.Val) { |
| 3313 | Result = LegalizeOp(Tmp2); |
| 3314 | Tmp1 = LegalizeOp(Tmp2.getValue(1)); |
| 3315 | } |
| 3316 | } |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3317 | break; |
| 3318 | case TargetLowering::Expand: { |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 3319 | const Value *V = cast<SrcValueSDNode>(Node->getOperand(2))->getValue(); |
| 3320 | SDOperand VAList = DAG.getLoad(TLI.getPointerTy(), Tmp1, Tmp2, V, 0); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3321 | // Increment the pointer, VAList, to the next vaarg |
| 3322 | Tmp3 = DAG.getNode(ISD::ADD, TLI.getPointerTy(), VAList, |
| 3323 | DAG.getConstant(MVT::getSizeInBits(VT)/8, |
| 3324 | TLI.getPointerTy())); |
| 3325 | // Store the incremented VAList to the legalized pointer |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 3326 | Tmp3 = DAG.getStore(VAList.getValue(1), Tmp3, Tmp2, V, 0); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3327 | // Load the actual argument out of the pointer VAList |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 3328 | Result = DAG.getLoad(VT, Tmp3, VAList, NULL, 0); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3329 | Tmp1 = LegalizeOp(Result.getValue(1)); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3330 | Result = LegalizeOp(Result); |
| 3331 | break; |
| 3332 | } |
| 3333 | } |
| 3334 | // Since VAARG produces two values, make sure to remember that we |
| 3335 | // legalized both of them. |
| 3336 | AddLegalizedOperand(SDOperand(Node, 0), Result); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3337 | AddLegalizedOperand(SDOperand(Node, 1), Tmp1); |
| 3338 | return Op.ResNo ? Tmp1 : Result; |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3339 | } |
| 3340 | |
| 3341 | case ISD::VACOPY: |
| 3342 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 3343 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the dest pointer. |
| 3344 | Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the source pointer. |
| 3345 | |
| 3346 | switch (TLI.getOperationAction(ISD::VACOPY, MVT::Other)) { |
| 3347 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3348 | case TargetLowering::Custom: |
| 3349 | isCustom = true; |
| 3350 | // FALLTHROUGH |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3351 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3352 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3, |
| 3353 | Node->getOperand(3), Node->getOperand(4)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3354 | if (isCustom) { |
| 3355 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 3356 | if (Tmp1.Val) Result = Tmp1; |
| 3357 | } |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3358 | break; |
| 3359 | case TargetLowering::Expand: |
| 3360 | // This defaults to loading a pointer from the input and storing it to the |
| 3361 | // output, returning the chain. |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 3362 | const Value *VD = cast<SrcValueSDNode>(Node->getOperand(3))->getValue(); |
| 3363 | const Value *VS = cast<SrcValueSDNode>(Node->getOperand(4))->getValue(); |
| 3364 | Tmp4 = DAG.getLoad(TLI.getPointerTy(), Tmp1, Tmp3, VD, 0); |
| 3365 | Result = DAG.getStore(Tmp4.getValue(1), Tmp4, Tmp2, VS, 0); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3366 | break; |
| 3367 | } |
| 3368 | break; |
| 3369 | |
| 3370 | case ISD::VAEND: |
| 3371 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 3372 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. |
| 3373 | |
| 3374 | switch (TLI.getOperationAction(ISD::VAEND, MVT::Other)) { |
| 3375 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3376 | case TargetLowering::Custom: |
| 3377 | isCustom = true; |
| 3378 | // FALLTHROUGH |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3379 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3380 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3381 | if (isCustom) { |
| 3382 | Tmp1 = TLI.LowerOperation(Tmp1, DAG); |
| 3383 | if (Tmp1.Val) Result = Tmp1; |
| 3384 | } |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3385 | break; |
| 3386 | case TargetLowering::Expand: |
| 3387 | Result = Tmp1; // Default to a no-op, return the chain |
| 3388 | break; |
| 3389 | } |
| 3390 | break; |
| 3391 | |
| 3392 | case ISD::VASTART: |
| 3393 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 3394 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. |
| 3395 | |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3396 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
| 3397 | |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3398 | switch (TLI.getOperationAction(ISD::VASTART, MVT::Other)) { |
| 3399 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3400 | case TargetLowering::Legal: break; |
| 3401 | case TargetLowering::Custom: |
| 3402 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 3403 | if (Tmp1.Val) Result = Tmp1; |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3404 | break; |
| 3405 | } |
| 3406 | break; |
| 3407 | |
Nate Begeman | 35ef913 | 2006-01-11 21:21:00 +0000 | [diff] [blame] | 3408 | case ISD::ROTL: |
| 3409 | case ISD::ROTR: |
| 3410 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
| 3411 | Tmp2 = LegalizeOp(Node->getOperand(1)); // RHS |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3412 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Scott Michel | c9dc114 | 2007-04-02 21:36:32 +0000 | [diff] [blame] | 3413 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 3414 | default: |
| 3415 | assert(0 && "ROTL/ROTR legalize operation not supported"); |
| 3416 | break; |
| 3417 | case TargetLowering::Legal: |
| 3418 | break; |
| 3419 | case TargetLowering::Custom: |
| 3420 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 3421 | if (Tmp1.Val) Result = Tmp1; |
| 3422 | break; |
| 3423 | case TargetLowering::Promote: |
| 3424 | assert(0 && "Do not know how to promote ROTL/ROTR"); |
| 3425 | break; |
| 3426 | case TargetLowering::Expand: |
| 3427 | assert(0 && "Do not know how to expand ROTL/ROTR"); |
| 3428 | break; |
| 3429 | } |
Nate Begeman | 35ef913 | 2006-01-11 21:21:00 +0000 | [diff] [blame] | 3430 | break; |
| 3431 | |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 3432 | case ISD::BSWAP: |
| 3433 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Op |
| 3434 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3435 | case TargetLowering::Custom: |
| 3436 | assert(0 && "Cannot custom legalize this yet!"); |
| 3437 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3438 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3439 | break; |
| 3440 | case TargetLowering::Promote: { |
| 3441 | MVT::ValueType OVT = Tmp1.getValueType(); |
| 3442 | MVT::ValueType NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT); |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 3443 | unsigned DiffBits = MVT::getSizeInBits(NVT) - MVT::getSizeInBits(OVT); |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 3444 | |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3445 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Tmp1); |
| 3446 | Tmp1 = DAG.getNode(ISD::BSWAP, NVT, Tmp1); |
| 3447 | Result = DAG.getNode(ISD::SRL, NVT, Tmp1, |
| 3448 | DAG.getConstant(DiffBits, TLI.getShiftAmountTy())); |
| 3449 | break; |
| 3450 | } |
| 3451 | case TargetLowering::Expand: |
| 3452 | Result = ExpandBSWAP(Tmp1); |
| 3453 | break; |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 3454 | } |
| 3455 | break; |
| 3456 | |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3457 | case ISD::CTPOP: |
| 3458 | case ISD::CTTZ: |
| 3459 | case ISD::CTLZ: |
| 3460 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Op |
| 3461 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
Scott Michel | 910b66d | 2007-07-30 21:00:31 +0000 | [diff] [blame] | 3462 | case TargetLowering::Custom: |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3463 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3464 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Scott Michel | 910b66d | 2007-07-30 21:00:31 +0000 | [diff] [blame] | 3465 | if (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0)) == |
Scott Michel | 335f4f7 | 2007-08-02 02:22:46 +0000 | [diff] [blame] | 3466 | TargetLowering::Custom) { |
| 3467 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 3468 | if (Tmp1.Val) { |
| 3469 | Result = Tmp1; |
| 3470 | } |
Scott Michel | 910b66d | 2007-07-30 21:00:31 +0000 | [diff] [blame] | 3471 | } |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3472 | break; |
| 3473 | case TargetLowering::Promote: { |
| 3474 | MVT::ValueType OVT = Tmp1.getValueType(); |
| 3475 | MVT::ValueType NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT); |
Chris Lattner | edb1add | 2005-05-11 04:51:16 +0000 | [diff] [blame] | 3476 | |
| 3477 | // Zero extend the argument. |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3478 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Tmp1); |
| 3479 | // Perform the larger operation, then subtract if needed. |
| 3480 | Tmp1 = DAG.getNode(Node->getOpcode(), Node->getValueType(0), Tmp1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3481 | switch (Node->getOpcode()) { |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3482 | case ISD::CTPOP: |
| 3483 | Result = Tmp1; |
| 3484 | break; |
| 3485 | case ISD::CTTZ: |
| 3486 | //if Tmp1 == sizeinbits(NVT) then Tmp1 = sizeinbits(Old VT) |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 3487 | Tmp2 = DAG.getSetCC(TLI.getSetCCResultTy(), Tmp1, |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 3488 | DAG.getConstant(MVT::getSizeInBits(NVT), NVT), |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 3489 | ISD::SETEQ); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 3490 | Result = DAG.getNode(ISD::SELECT, NVT, Tmp2, |
Scott Michel | 910b66d | 2007-07-30 21:00:31 +0000 | [diff] [blame] | 3491 | DAG.getConstant(MVT::getSizeInBits(OVT),NVT), Tmp1); |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3492 | break; |
| 3493 | case ISD::CTLZ: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3494 | // Tmp1 = Tmp1 - (sizeinbits(NVT) - sizeinbits(Old VT)) |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 3495 | Result = DAG.getNode(ISD::SUB, NVT, Tmp1, |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 3496 | DAG.getConstant(MVT::getSizeInBits(NVT) - |
| 3497 | MVT::getSizeInBits(OVT), NVT)); |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3498 | break; |
| 3499 | } |
| 3500 | break; |
| 3501 | } |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3502 | case TargetLowering::Expand: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3503 | Result = ExpandBitCount(Node->getOpcode(), Tmp1); |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3504 | break; |
| 3505 | } |
| 3506 | break; |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 3507 | |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3508 | // Unary operators |
| 3509 | case ISD::FABS: |
| 3510 | case ISD::FNEG: |
Chris Lattner | da6ba87 | 2005-04-28 21:44:33 +0000 | [diff] [blame] | 3511 | case ISD::FSQRT: |
| 3512 | case ISD::FSIN: |
| 3513 | case ISD::FCOS: |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3514 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 3515 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3516 | case TargetLowering::Promote: |
| 3517 | case TargetLowering::Custom: |
Evan Cheng | 59ad781 | 2006-01-31 18:14:25 +0000 | [diff] [blame] | 3518 | isCustom = true; |
| 3519 | // FALLTHROUGH |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3520 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3521 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Evan Cheng | 59ad781 | 2006-01-31 18:14:25 +0000 | [diff] [blame] | 3522 | if (isCustom) { |
| 3523 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 3524 | if (Tmp1.Val) Result = Tmp1; |
| 3525 | } |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3526 | break; |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3527 | case TargetLowering::Expand: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3528 | switch (Node->getOpcode()) { |
| 3529 | default: assert(0 && "Unreachable!"); |
| 3530 | case ISD::FNEG: |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3531 | // Expand Y = FNEG(X) -> Y = SUB -0.0, X |
| 3532 | Tmp2 = DAG.getConstantFP(-0.0, Node->getValueType(0)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3533 | Result = DAG.getNode(ISD::FSUB, Node->getValueType(0), Tmp2, Tmp1); |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 3534 | break; |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 3535 | case ISD::FABS: { |
Chris Lattner | 4af6e0d | 2005-04-02 05:26:37 +0000 | [diff] [blame] | 3536 | // Expand Y = FABS(X) -> Y = (X >u 0.0) ? X : fneg(X). |
| 3537 | MVT::ValueType VT = Node->getValueType(0); |
| 3538 | Tmp2 = DAG.getConstantFP(0.0, VT); |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 3539 | Tmp2 = DAG.getSetCC(TLI.getSetCCResultTy(), Tmp1, Tmp2, ISD::SETUGT); |
Chris Lattner | 4af6e0d | 2005-04-02 05:26:37 +0000 | [diff] [blame] | 3540 | Tmp3 = DAG.getNode(ISD::FNEG, VT, Tmp1); |
| 3541 | Result = DAG.getNode(ISD::SELECT, VT, Tmp2, Tmp1, Tmp3); |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 3542 | break; |
| 3543 | } |
| 3544 | case ISD::FSQRT: |
| 3545 | case ISD::FSIN: |
| 3546 | case ISD::FCOS: { |
| 3547 | MVT::ValueType VT = Node->getValueType(0); |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3548 | |
| 3549 | // Expand unsupported unary vector operators by unrolling them. |
| 3550 | if (MVT::isVector(VT)) { |
| 3551 | Result = LegalizeOp(UnrollVectorOp(Op)); |
| 3552 | break; |
| 3553 | } |
| 3554 | |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3555 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 3556 | switch(Node->getOpcode()) { |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3557 | case ISD::FSQRT: |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 3558 | LC = GetFPLibCall(VT, RTLIB::SQRT_F32, RTLIB::SQRT_F64, |
| 3559 | RTLIB::SQRT_F80, RTLIB::SQRT_PPCF128); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3560 | break; |
| 3561 | case ISD::FSIN: |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 3562 | LC = GetFPLibCall(VT, RTLIB::SIN_F32, RTLIB::SIN_F64, |
| 3563 | RTLIB::SIN_F80, RTLIB::SIN_PPCF128); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3564 | break; |
| 3565 | case ISD::FCOS: |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 3566 | LC = GetFPLibCall(VT, RTLIB::COS_F32, RTLIB::COS_F64, |
| 3567 | RTLIB::COS_F80, RTLIB::COS_PPCF128); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3568 | break; |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 3569 | default: assert(0 && "Unreachable!"); |
| 3570 | } |
Nate Begeman | 2ac4fc0 | 2005-08-04 21:43:28 +0000 | [diff] [blame] | 3571 | SDOperand Dummy; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3572 | Result = ExpandLibCall(TLI.getLibcallName(LC), Node, |
| 3573 | false/*sign irrelevant*/, Dummy); |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 3574 | break; |
| 3575 | } |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3576 | } |
| 3577 | break; |
| 3578 | } |
| 3579 | break; |
Chris Lattner | 6ddf8ed | 2006-09-09 06:03:30 +0000 | [diff] [blame] | 3580 | case ISD::FPOWI: { |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3581 | MVT::ValueType VT = Node->getValueType(0); |
| 3582 | |
| 3583 | // Expand unsupported unary vector operators by unrolling them. |
| 3584 | if (MVT::isVector(VT)) { |
| 3585 | Result = LegalizeOp(UnrollVectorOp(Op)); |
| 3586 | break; |
| 3587 | } |
| 3588 | |
| 3589 | // We always lower FPOWI into a libcall. No target support for it yet. |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 3590 | RTLIB::Libcall LC = GetFPLibCall(VT, RTLIB::POWI_F32, RTLIB::POWI_F64, |
| 3591 | RTLIB::POWI_F80, RTLIB::POWI_PPCF128); |
Chris Lattner | 6ddf8ed | 2006-09-09 06:03:30 +0000 | [diff] [blame] | 3592 | SDOperand Dummy; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3593 | Result = ExpandLibCall(TLI.getLibcallName(LC), Node, |
| 3594 | false/*sign irrelevant*/, Dummy); |
Chris Lattner | 6ddf8ed | 2006-09-09 06:03:30 +0000 | [diff] [blame] | 3595 | break; |
| 3596 | } |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 3597 | case ISD::BIT_CONVERT: |
Chris Lattner | 67993f7 | 2006-01-23 07:30:46 +0000 | [diff] [blame] | 3598 | if (!isTypeLegal(Node->getOperand(0).getValueType())) { |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 3599 | Result = EmitStackConvert(Node->getOperand(0), Node->getValueType(0), |
| 3600 | Node->getValueType(0)); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3601 | } else if (MVT::isVector(Op.getOperand(0).getValueType())) { |
| 3602 | // The input has to be a vector type, we have to either scalarize it, pack |
| 3603 | // it, or convert it based on whether the input vector type is legal. |
| 3604 | SDNode *InVal = Node->getOperand(0).Val; |
Dale Johannesen | e526962 | 2007-10-20 00:07:52 +0000 | [diff] [blame] | 3605 | int InIx = Node->getOperand(0).ResNo; |
| 3606 | unsigned NumElems = MVT::getVectorNumElements(InVal->getValueType(InIx)); |
| 3607 | MVT::ValueType EVT = MVT::getVectorElementType(InVal->getValueType(InIx)); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3608 | |
| 3609 | // Figure out if there is a simple type corresponding to this Vector |
| 3610 | // type. If so, convert to the vector type. |
| 3611 | MVT::ValueType TVT = MVT::getVectorType(EVT, NumElems); |
| 3612 | if (TLI.isTypeLegal(TVT)) { |
Dan Gohman | 07a9676 | 2007-07-16 14:29:03 +0000 | [diff] [blame] | 3613 | // Turn this into a bit convert of the vector input. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3614 | Result = DAG.getNode(ISD::BIT_CONVERT, Node->getValueType(0), |
| 3615 | LegalizeOp(Node->getOperand(0))); |
| 3616 | break; |
| 3617 | } else if (NumElems == 1) { |
| 3618 | // Turn this into a bit convert of the scalar input. |
| 3619 | Result = DAG.getNode(ISD::BIT_CONVERT, Node->getValueType(0), |
| 3620 | ScalarizeVectorOp(Node->getOperand(0))); |
| 3621 | break; |
| 3622 | } else { |
| 3623 | // FIXME: UNIMP! Store then reload |
| 3624 | assert(0 && "Cast from unsupported vector type not implemented yet!"); |
| 3625 | } |
Chris Lattner | 67993f7 | 2006-01-23 07:30:46 +0000 | [diff] [blame] | 3626 | } else { |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 3627 | switch (TLI.getOperationAction(ISD::BIT_CONVERT, |
| 3628 | Node->getOperand(0).getValueType())) { |
| 3629 | default: assert(0 && "Unknown operation action!"); |
| 3630 | case TargetLowering::Expand: |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 3631 | Result = EmitStackConvert(Node->getOperand(0), Node->getValueType(0), |
| 3632 | Node->getValueType(0)); |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 3633 | break; |
| 3634 | case TargetLowering::Legal: |
| 3635 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3636 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 3637 | break; |
| 3638 | } |
| 3639 | } |
| 3640 | break; |
Chris Lattner | d1f04d4 | 2006-03-24 02:26:29 +0000 | [diff] [blame] | 3641 | |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3642 | // Conversion operators. The source and destination have different types. |
Chris Lattner | ae0aacb | 2005-01-08 08:08:56 +0000 | [diff] [blame] | 3643 | case ISD::SINT_TO_FP: |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3644 | case ISD::UINT_TO_FP: { |
| 3645 | bool isSigned = Node->getOpcode() == ISD::SINT_TO_FP; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3646 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3647 | case Legal: |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 3648 | switch (TLI.getOperationAction(Node->getOpcode(), |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3649 | Node->getOperand(0).getValueType())) { |
| 3650 | default: assert(0 && "Unknown operation action!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3651 | case TargetLowering::Custom: |
| 3652 | isCustom = true; |
| 3653 | // FALLTHROUGH |
| 3654 | case TargetLowering::Legal: |
| 3655 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3656 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3657 | if (isCustom) { |
| 3658 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 3659 | if (Tmp1.Val) Result = Tmp1; |
| 3660 | } |
| 3661 | break; |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3662 | case TargetLowering::Expand: |
Jim Laskey | 6269ed1 | 2005-08-17 00:39:29 +0000 | [diff] [blame] | 3663 | Result = ExpandLegalINT_TO_FP(isSigned, |
| 3664 | LegalizeOp(Node->getOperand(0)), |
| 3665 | Node->getValueType(0)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3666 | break; |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3667 | case TargetLowering::Promote: |
| 3668 | Result = PromoteLegalINT_TO_FP(LegalizeOp(Node->getOperand(0)), |
| 3669 | Node->getValueType(0), |
| 3670 | isSigned); |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3671 | break; |
Andrew Lenharth | 5b5b8c2 | 2005-11-30 06:43:03 +0000 | [diff] [blame] | 3672 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3673 | break; |
Chris Lattner | b00a642 | 2005-01-07 22:37:48 +0000 | [diff] [blame] | 3674 | case Expand: |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3675 | Result = ExpandIntToFP(Node->getOpcode() == ISD::SINT_TO_FP, |
| 3676 | Node->getValueType(0), Node->getOperand(0)); |
| 3677 | break; |
| 3678 | case Promote: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3679 | Tmp1 = PromoteOp(Node->getOperand(0)); |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3680 | if (isSigned) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3681 | Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, Tmp1.getValueType(), |
| 3682 | Tmp1, DAG.getValueType(Node->getOperand(0).getValueType())); |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3683 | } else { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3684 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, |
| 3685 | Node->getOperand(0).getValueType()); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 3686 | } |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3687 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 3688 | Result = LegalizeOp(Result); // The 'op' is not necessarily legal! |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3689 | break; |
| 3690 | } |
| 3691 | break; |
| 3692 | } |
| 3693 | case ISD::TRUNCATE: |
| 3694 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3695 | case Legal: |
| 3696 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3697 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3698 | break; |
| 3699 | case Expand: |
| 3700 | ExpandOp(Node->getOperand(0), Tmp1, Tmp2); |
| 3701 | |
| 3702 | // Since the result is legal, we should just be able to truncate the low |
| 3703 | // part of the source. |
| 3704 | Result = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0), Tmp1); |
| 3705 | break; |
| 3706 | case Promote: |
| 3707 | Result = PromoteOp(Node->getOperand(0)); |
| 3708 | Result = DAG.getNode(ISD::TRUNCATE, Op.getValueType(), Result); |
| 3709 | break; |
| 3710 | } |
| 3711 | break; |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 3712 | |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3713 | case ISD::FP_TO_SINT: |
| 3714 | case ISD::FP_TO_UINT: |
| 3715 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3716 | case Legal: |
Chris Lattner | f1fa74e | 2005-07-30 00:04:12 +0000 | [diff] [blame] | 3717 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 3718 | |
Chris Lattner | 1618beb | 2005-07-29 00:11:56 +0000 | [diff] [blame] | 3719 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))){ |
| 3720 | default: assert(0 && "Unknown operation action!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3721 | case TargetLowering::Custom: |
| 3722 | isCustom = true; |
| 3723 | // FALLTHROUGH |
| 3724 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3725 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3726 | if (isCustom) { |
| 3727 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 3728 | if (Tmp1.Val) Result = Tmp1; |
| 3729 | } |
| 3730 | break; |
| 3731 | case TargetLowering::Promote: |
| 3732 | Result = PromoteLegalFP_TO_INT(Tmp1, Node->getValueType(0), |
| 3733 | Node->getOpcode() == ISD::FP_TO_SINT); |
| 3734 | break; |
Chris Lattner | 1618beb | 2005-07-29 00:11:56 +0000 | [diff] [blame] | 3735 | case TargetLowering::Expand: |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 3736 | if (Node->getOpcode() == ISD::FP_TO_UINT) { |
| 3737 | SDOperand True, False; |
| 3738 | MVT::ValueType VT = Node->getOperand(0).getValueType(); |
| 3739 | MVT::ValueType NVT = Node->getValueType(0); |
Dale Johannesen | f4d4832 | 2007-09-19 17:53:26 +0000 | [diff] [blame] | 3740 | unsigned ShiftAmt = MVT::getSizeInBits(NVT)-1; |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 3741 | const uint64_t zero[] = {0, 0}; |
| 3742 | APFloat apf = APFloat(APInt(MVT::getSizeInBits(VT), 2, zero)); |
| 3743 | uint64_t x = 1ULL << ShiftAmt; |
Neil Booth | ccf596a | 2007-10-07 11:45:55 +0000 | [diff] [blame] | 3744 | (void)apf.convertFromZeroExtendedInteger |
| 3745 | (&x, MVT::getSizeInBits(NVT), false, APFloat::rmNearestTiesToEven); |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 3746 | Tmp2 = DAG.getConstantFP(apf, VT); |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 3747 | Tmp3 = DAG.getSetCC(TLI.getSetCCResultTy(), |
| 3748 | Node->getOperand(0), Tmp2, ISD::SETLT); |
| 3749 | True = DAG.getNode(ISD::FP_TO_SINT, NVT, Node->getOperand(0)); |
| 3750 | False = DAG.getNode(ISD::FP_TO_SINT, NVT, |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 3751 | DAG.getNode(ISD::FSUB, VT, Node->getOperand(0), |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 3752 | Tmp2)); |
| 3753 | False = DAG.getNode(ISD::XOR, NVT, False, |
| 3754 | DAG.getConstant(1ULL << ShiftAmt, NVT)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3755 | Result = DAG.getNode(ISD::SELECT, NVT, Tmp3, True, False); |
| 3756 | break; |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 3757 | } else { |
| 3758 | assert(0 && "Do not know how to expand FP_TO_SINT yet!"); |
| 3759 | } |
| 3760 | break; |
Chris Lattner | 07dffd6 | 2005-08-26 00:14:16 +0000 | [diff] [blame] | 3761 | } |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3762 | break; |
Evan Cheng | 6af00d5 | 2006-12-13 01:57:55 +0000 | [diff] [blame] | 3763 | case Expand: { |
Evan Cheng | 6af00d5 | 2006-12-13 01:57:55 +0000 | [diff] [blame] | 3764 | MVT::ValueType VT = Op.getValueType(); |
Dale Johannesen | 6eaeff2 | 2007-10-10 01:01:31 +0000 | [diff] [blame] | 3765 | MVT::ValueType OVT = Node->getOperand(0).getValueType(); |
Dale Johannesen | fcf4d24 | 2007-10-11 23:32:15 +0000 | [diff] [blame] | 3766 | // Convert ppcf128 to i32 |
Dale Johannesen | 6eaeff2 | 2007-10-10 01:01:31 +0000 | [diff] [blame] | 3767 | if (OVT == MVT::ppcf128 && VT == MVT::i32) { |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 3768 | if (Node->getOpcode() == ISD::FP_TO_SINT) { |
| 3769 | Result = DAG.getNode(ISD::FP_ROUND_INREG, MVT::ppcf128, |
| 3770 | Node->getOperand(0), DAG.getValueType(MVT::f64)); |
| 3771 | Result = DAG.getNode(ISD::FP_ROUND, MVT::f64, Result, |
| 3772 | DAG.getIntPtrConstant(1)); |
| 3773 | Result = DAG.getNode(ISD::FP_TO_SINT, VT, Result); |
| 3774 | } else { |
Dale Johannesen | fcf4d24 | 2007-10-11 23:32:15 +0000 | [diff] [blame] | 3775 | const uint64_t TwoE31[] = {0x41e0000000000000LL, 0}; |
| 3776 | APFloat apf = APFloat(APInt(128, 2, TwoE31)); |
| 3777 | Tmp2 = DAG.getConstantFP(apf, OVT); |
| 3778 | // X>=2^31 ? (int)(X-2^31)+0x80000000 : (int)X |
| 3779 | // FIXME: generated code sucks. |
| 3780 | Result = DAG.getNode(ISD::SELECT_CC, VT, Node->getOperand(0), Tmp2, |
| 3781 | DAG.getNode(ISD::ADD, MVT::i32, |
| 3782 | DAG.getNode(ISD::FP_TO_SINT, VT, |
| 3783 | DAG.getNode(ISD::FSUB, OVT, |
| 3784 | Node->getOperand(0), Tmp2)), |
| 3785 | DAG.getConstant(0x80000000, MVT::i32)), |
| 3786 | DAG.getNode(ISD::FP_TO_SINT, VT, |
| 3787 | Node->getOperand(0)), |
| 3788 | DAG.getCondCode(ISD::SETGE)); |
| 3789 | } |
Dale Johannesen | 6eaeff2 | 2007-10-10 01:01:31 +0000 | [diff] [blame] | 3790 | break; |
| 3791 | } |
Dale Johannesen | fcf4d24 | 2007-10-11 23:32:15 +0000 | [diff] [blame] | 3792 | // Convert f32 / f64 to i32 / i64. |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3793 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
Evan Cheng | 6af00d5 | 2006-12-13 01:57:55 +0000 | [diff] [blame] | 3794 | switch (Node->getOpcode()) { |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 3795 | case ISD::FP_TO_SINT: { |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 3796 | if (OVT == MVT::f32) |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3797 | LC = (VT == MVT::i32) |
| 3798 | ? RTLIB::FPTOSINT_F32_I32 : RTLIB::FPTOSINT_F32_I64; |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 3799 | else if (OVT == MVT::f64) |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3800 | LC = (VT == MVT::i32) |
| 3801 | ? RTLIB::FPTOSINT_F64_I32 : RTLIB::FPTOSINT_F64_I64; |
Dale Johannesen | 161e897 | 2007-10-05 20:04:43 +0000 | [diff] [blame] | 3802 | else if (OVT == MVT::f80) { |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 3803 | assert(VT == MVT::i64); |
Dale Johannesen | 161e897 | 2007-10-05 20:04:43 +0000 | [diff] [blame] | 3804 | LC = RTLIB::FPTOSINT_F80_I64; |
| 3805 | } |
| 3806 | else if (OVT == MVT::ppcf128) { |
| 3807 | assert(VT == MVT::i64); |
| 3808 | LC = RTLIB::FPTOSINT_PPCF128_I64; |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 3809 | } |
Evan Cheng | 6af00d5 | 2006-12-13 01:57:55 +0000 | [diff] [blame] | 3810 | break; |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 3811 | } |
| 3812 | case ISD::FP_TO_UINT: { |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 3813 | if (OVT == MVT::f32) |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3814 | LC = (VT == MVT::i32) |
| 3815 | ? RTLIB::FPTOUINT_F32_I32 : RTLIB::FPTOSINT_F32_I64; |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 3816 | else if (OVT == MVT::f64) |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3817 | LC = (VT == MVT::i32) |
| 3818 | ? RTLIB::FPTOUINT_F64_I32 : RTLIB::FPTOSINT_F64_I64; |
Dale Johannesen | 161e897 | 2007-10-05 20:04:43 +0000 | [diff] [blame] | 3819 | else if (OVT == MVT::f80) { |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 3820 | LC = (VT == MVT::i32) |
Dale Johannesen | 161e897 | 2007-10-05 20:04:43 +0000 | [diff] [blame] | 3821 | ? RTLIB::FPTOUINT_F80_I32 : RTLIB::FPTOUINT_F80_I64; |
| 3822 | } |
| 3823 | else if (OVT == MVT::ppcf128) { |
| 3824 | assert(VT == MVT::i64); |
| 3825 | LC = RTLIB::FPTOUINT_PPCF128_I64; |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 3826 | } |
Evan Cheng | 6af00d5 | 2006-12-13 01:57:55 +0000 | [diff] [blame] | 3827 | break; |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 3828 | } |
Evan Cheng | 6af00d5 | 2006-12-13 01:57:55 +0000 | [diff] [blame] | 3829 | default: assert(0 && "Unreachable!"); |
| 3830 | } |
| 3831 | SDOperand Dummy; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3832 | Result = ExpandLibCall(TLI.getLibcallName(LC), Node, |
| 3833 | false/*sign irrelevant*/, Dummy); |
Evan Cheng | 6af00d5 | 2006-12-13 01:57:55 +0000 | [diff] [blame] | 3834 | break; |
| 3835 | } |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3836 | case Promote: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3837 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 3838 | Result = DAG.UpdateNodeOperands(Result, LegalizeOp(Tmp1)); |
| 3839 | Result = LegalizeOp(Result); |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3840 | break; |
| 3841 | } |
| 3842 | break; |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 3843 | |
Chris Lattner | f2670a8 | 2008-01-16 06:57:07 +0000 | [diff] [blame] | 3844 | case ISD::FP_EXTEND: { |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 3845 | MVT::ValueType DstVT = Op.getValueType(); |
| 3846 | MVT::ValueType SrcVT = Op.getOperand(0).getValueType(); |
| 3847 | if (TLI.getConvertAction(SrcVT, DstVT) == TargetLowering::Expand) { |
| 3848 | // The only other way we can lower this is to turn it into a STORE, |
| 3849 | // LOAD pair, targetting a temporary location (a stack slot). |
| 3850 | Result = EmitStackConvert(Node->getOperand(0), SrcVT, DstVT); |
| 3851 | break; |
Chris Lattner | f2670a8 | 2008-01-16 06:57:07 +0000 | [diff] [blame] | 3852 | } |
| 3853 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3854 | case Expand: assert(0 && "Shouldn't need to expand other operators here!"); |
| 3855 | case Legal: |
| 3856 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 3857 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 3858 | break; |
| 3859 | case Promote: |
| 3860 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 3861 | Result = DAG.getNode(ISD::FP_EXTEND, Op.getValueType(), Tmp1); |
| 3862 | break; |
| 3863 | } |
| 3864 | break; |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 3865 | } |
Dale Johannesen | 5411a39 | 2007-08-09 01:04:01 +0000 | [diff] [blame] | 3866 | case ISD::FP_ROUND: { |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 3867 | MVT::ValueType DstVT = Op.getValueType(); |
| 3868 | MVT::ValueType SrcVT = Op.getOperand(0).getValueType(); |
| 3869 | if (TLI.getConvertAction(SrcVT, DstVT) == TargetLowering::Expand) { |
| 3870 | if (SrcVT == MVT::ppcf128) { |
Dale Johannesen | 713ed3f | 2008-01-20 01:18:38 +0000 | [diff] [blame] | 3871 | SDOperand Lo; |
| 3872 | ExpandOp(Node->getOperand(0), Lo, Result); |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 3873 | // Round it the rest of the way (e.g. to f32) if needed. |
Dale Johannesen | 713ed3f | 2008-01-20 01:18:38 +0000 | [diff] [blame] | 3874 | if (DstVT!=MVT::f64) |
| 3875 | Result = DAG.getNode(ISD::FP_ROUND, DstVT, Result, Op.getOperand(1)); |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 3876 | break; |
Dale Johannesen | 5411a39 | 2007-08-09 01:04:01 +0000 | [diff] [blame] | 3877 | } |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 3878 | // The only other way we can lower this is to turn it into a STORE, |
| 3879 | // LOAD pair, targetting a temporary location (a stack slot). |
| 3880 | Result = EmitStackConvert(Node->getOperand(0), DstVT, DstVT); |
| 3881 | break; |
Dale Johannesen | 849f214 | 2007-07-03 00:53:03 +0000 | [diff] [blame] | 3882 | } |
Chris Lattner | f2670a8 | 2008-01-16 06:57:07 +0000 | [diff] [blame] | 3883 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3884 | case Expand: assert(0 && "Shouldn't need to expand other operators here!"); |
| 3885 | case Legal: |
| 3886 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 3887 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
Chris Lattner | f2670a8 | 2008-01-16 06:57:07 +0000 | [diff] [blame] | 3888 | break; |
| 3889 | case Promote: |
| 3890 | Tmp1 = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 3891 | Result = DAG.getNode(ISD::FP_ROUND, Op.getValueType(), Tmp1, |
| 3892 | Node->getOperand(1)); |
Chris Lattner | f2670a8 | 2008-01-16 06:57:07 +0000 | [diff] [blame] | 3893 | break; |
| 3894 | } |
| 3895 | break; |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 3896 | } |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 3897 | case ISD::ANY_EXTEND: |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3898 | case ISD::ZERO_EXTEND: |
| 3899 | case ISD::SIGN_EXTEND: |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3900 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3901 | case Expand: assert(0 && "Shouldn't need to expand other operators here!"); |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3902 | case Legal: |
| 3903 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Scott Michel | 0123b7d | 2008-02-15 23:05:48 +0000 | [diff] [blame] | 3904 | if (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0)) == |
| 3905 | TargetLowering::Custom) { |
| 3906 | Tmp2 = TLI.LowerOperation(Result, DAG); |
| 3907 | if (Tmp2.Val) { |
| 3908 | Tmp1 = Tmp2; |
| 3909 | } |
| 3910 | } |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3911 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3912 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3913 | case Promote: |
| 3914 | switch (Node->getOpcode()) { |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 3915 | case ISD::ANY_EXTEND: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3916 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 3917 | Result = DAG.getNode(ISD::ANY_EXTEND, Op.getValueType(), Tmp1); |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 3918 | break; |
Chris Lattner | 1713e73 | 2005-01-16 00:38:00 +0000 | [diff] [blame] | 3919 | case ISD::ZERO_EXTEND: |
| 3920 | Result = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 3921 | Result = DAG.getNode(ISD::ANY_EXTEND, Op.getValueType(), Result); |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 3922 | Result = DAG.getZeroExtendInReg(Result, |
| 3923 | Node->getOperand(0).getValueType()); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3924 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3925 | case ISD::SIGN_EXTEND: |
Chris Lattner | 1713e73 | 2005-01-16 00:38:00 +0000 | [diff] [blame] | 3926 | Result = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 3927 | Result = DAG.getNode(ISD::ANY_EXTEND, Op.getValueType(), Result); |
Chris Lattner | 1713e73 | 2005-01-16 00:38:00 +0000 | [diff] [blame] | 3928 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(), |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 3929 | Result, |
| 3930 | DAG.getValueType(Node->getOperand(0).getValueType())); |
Chris Lattner | 1713e73 | 2005-01-16 00:38:00 +0000 | [diff] [blame] | 3931 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3932 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3933 | } |
| 3934 | break; |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 3935 | case ISD::FP_ROUND_INREG: |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 3936 | case ISD::SIGN_EXTEND_INREG: { |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 3937 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 3938 | MVT::ValueType ExtraVT = cast<VTSDNode>(Node->getOperand(1))->getVT(); |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 3939 | |
| 3940 | // If this operation is not supported, convert it to a shl/shr or load/store |
| 3941 | // pair. |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 3942 | switch (TLI.getOperationAction(Node->getOpcode(), ExtraVT)) { |
| 3943 | default: assert(0 && "This action not supported for this op yet!"); |
| 3944 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3945 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 3946 | break; |
| 3947 | case TargetLowering::Expand: |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 3948 | // If this is an integer extend and shifts are supported, do that. |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 3949 | if (Node->getOpcode() == ISD::SIGN_EXTEND_INREG) { |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 3950 | // NOTE: we could fall back on load/store here too for targets without |
| 3951 | // SAR. However, it is doubtful that any exist. |
| 3952 | unsigned BitsDiff = MVT::getSizeInBits(Node->getValueType(0)) - |
| 3953 | MVT::getSizeInBits(ExtraVT); |
Chris Lattner | 27ff112 | 2005-01-22 00:31:52 +0000 | [diff] [blame] | 3954 | SDOperand ShiftCst = DAG.getConstant(BitsDiff, TLI.getShiftAmountTy()); |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 3955 | Result = DAG.getNode(ISD::SHL, Node->getValueType(0), |
| 3956 | Node->getOperand(0), ShiftCst); |
| 3957 | Result = DAG.getNode(ISD::SRA, Node->getValueType(0), |
| 3958 | Result, ShiftCst); |
| 3959 | } else if (Node->getOpcode() == ISD::FP_ROUND_INREG) { |
Jim Laskey | 2d84c4c | 2006-10-11 17:52:19 +0000 | [diff] [blame] | 3960 | // 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] | 3961 | // EXTLOAD pair, targetting a temporary location (a stack slot). |
| 3962 | |
| 3963 | // NOTE: there is a choice here between constantly creating new stack |
| 3964 | // slots and always reusing the same one. We currently always create |
| 3965 | // new ones, as reuse may inhibit scheduling. |
Chris Lattner | a66bb39 | 2008-01-16 07:51:34 +0000 | [diff] [blame] | 3966 | Result = EmitStackConvert(Node->getOperand(0), ExtraVT, |
| 3967 | Node->getValueType(0)); |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 3968 | } else { |
| 3969 | assert(0 && "Unknown op"); |
| 3970 | } |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 3971 | break; |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 3972 | } |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 3973 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3974 | } |
Duncan Sands | 36397f5 | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 3975 | case ISD::TRAMPOLINE: { |
| 3976 | SDOperand Ops[6]; |
| 3977 | for (unsigned i = 0; i != 6; ++i) |
| 3978 | Ops[i] = LegalizeOp(Node->getOperand(i)); |
| 3979 | Result = DAG.UpdateNodeOperands(Result, Ops, 6); |
| 3980 | // The only option for this node is to custom lower it. |
| 3981 | Result = TLI.LowerOperation(Result, DAG); |
| 3982 | assert(Result.Val && "Should always custom lower!"); |
Duncan Sands | f7331b3 | 2007-09-11 14:10:23 +0000 | [diff] [blame] | 3983 | |
| 3984 | // Since trampoline produces two values, make sure to remember that we |
| 3985 | // legalized both of them. |
| 3986 | Tmp1 = LegalizeOp(Result.getValue(1)); |
| 3987 | Result = LegalizeOp(Result); |
| 3988 | AddLegalizedOperand(SDOperand(Node, 0), Result); |
| 3989 | AddLegalizedOperand(SDOperand(Node, 1), Tmp1); |
| 3990 | return Op.ResNo ? Tmp1 : Result; |
Duncan Sands | 36397f5 | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 3991 | } |
Dan Gohman | 1a02486 | 2008-01-31 00:41:03 +0000 | [diff] [blame] | 3992 | case ISD::FLT_ROUNDS_: { |
Anton Korobeynikov | 917c2a6 | 2007-11-15 23:25:33 +0000 | [diff] [blame] | 3993 | MVT::ValueType VT = Node->getValueType(0); |
| 3994 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 3995 | default: assert(0 && "This action not supported for this op yet!"); |
| 3996 | case TargetLowering::Custom: |
| 3997 | Result = TLI.LowerOperation(Op, DAG); |
| 3998 | if (Result.Val) break; |
| 3999 | // Fall Thru |
| 4000 | case TargetLowering::Legal: |
| 4001 | // If this operation is not supported, lower it to constant 1 |
| 4002 | Result = DAG.getConstant(1, VT); |
| 4003 | break; |
| 4004 | } |
| 4005 | } |
Chris Lattner | 41bab0b | 2008-01-15 21:58:08 +0000 | [diff] [blame] | 4006 | case ISD::TRAP: { |
Anton Korobeynikov | 66fac79 | 2008-01-15 07:02:33 +0000 | [diff] [blame] | 4007 | MVT::ValueType VT = Node->getValueType(0); |
| 4008 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 4009 | default: assert(0 && "This action not supported for this op yet!"); |
Chris Lattner | 41bab0b | 2008-01-15 21:58:08 +0000 | [diff] [blame] | 4010 | case TargetLowering::Legal: |
| 4011 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 4012 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 4013 | break; |
Anton Korobeynikov | 66fac79 | 2008-01-15 07:02:33 +0000 | [diff] [blame] | 4014 | case TargetLowering::Custom: |
| 4015 | Result = TLI.LowerOperation(Op, DAG); |
| 4016 | if (Result.Val) break; |
| 4017 | // Fall Thru |
Chris Lattner | 41bab0b | 2008-01-15 21:58:08 +0000 | [diff] [blame] | 4018 | case TargetLowering::Expand: |
Anton Korobeynikov | 66fac79 | 2008-01-15 07:02:33 +0000 | [diff] [blame] | 4019 | // If this operation is not supported, lower it to 'abort()' call |
Chris Lattner | 41bab0b | 2008-01-15 21:58:08 +0000 | [diff] [blame] | 4020 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Anton Korobeynikov | 66fac79 | 2008-01-15 07:02:33 +0000 | [diff] [blame] | 4021 | TargetLowering::ArgListTy Args; |
| 4022 | std::pair<SDOperand,SDOperand> CallResult = |
Duncan Sands | 00fee65 | 2008-02-14 17:28:50 +0000 | [diff] [blame] | 4023 | TLI.LowerCallTo(Tmp1, Type::VoidTy, |
| 4024 | false, false, false, CallingConv::C, false, |
Chris Lattner | 034f12e | 2008-01-15 22:09:33 +0000 | [diff] [blame] | 4025 | DAG.getExternalSymbol("abort", TLI.getPointerTy()), |
| 4026 | Args, DAG); |
Anton Korobeynikov | 66fac79 | 2008-01-15 07:02:33 +0000 | [diff] [blame] | 4027 | Result = CallResult.second; |
| 4028 | break; |
| 4029 | } |
Chris Lattner | 41bab0b | 2008-01-15 21:58:08 +0000 | [diff] [blame] | 4030 | break; |
Anton Korobeynikov | 66fac79 | 2008-01-15 07:02:33 +0000 | [diff] [blame] | 4031 | } |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 4032 | } |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4033 | |
Chris Lattner | 4ddd283 | 2006-04-08 04:13:17 +0000 | [diff] [blame] | 4034 | assert(Result.getValueType() == Op.getValueType() && |
| 4035 | "Bad legalization!"); |
| 4036 | |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4037 | // Make sure that the generated code is itself legal. |
| 4038 | if (Result != Op) |
| 4039 | Result = LegalizeOp(Result); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 4040 | |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 4041 | // Note that LegalizeOp may be reentered even from single-use nodes, which |
| 4042 | // means that we always must cache transformed nodes. |
| 4043 | AddLegalizedOperand(Op, Result); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 4044 | return Result; |
| 4045 | } |
| 4046 | |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4047 | /// PromoteOp - Given an operation that produces a value in an invalid type, |
| 4048 | /// promote it to compute the value into a larger type. The produced value will |
| 4049 | /// have the correct bits for the low portion of the register, but no guarantee |
| 4050 | /// 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] | 4051 | SDOperand SelectionDAGLegalize::PromoteOp(SDOperand Op) { |
| 4052 | MVT::ValueType VT = Op.getValueType(); |
Chris Lattner | 71c42a0 | 2005-01-16 01:11:45 +0000 | [diff] [blame] | 4053 | MVT::ValueType NVT = TLI.getTypeToTransformTo(VT); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4054 | assert(getTypeAction(VT) == Promote && |
| 4055 | "Caller should expand or legalize operands that are not promotable!"); |
| 4056 | assert(NVT > VT && MVT::isInteger(NVT) == MVT::isInteger(VT) && |
| 4057 | "Cannot promote to smaller type!"); |
| 4058 | |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4059 | SDOperand Tmp1, Tmp2, Tmp3; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4060 | SDOperand Result; |
| 4061 | SDNode *Node = Op.Val; |
| 4062 | |
Chris Lattner | 40030bf | 2007-02-04 01:17:38 +0000 | [diff] [blame] | 4063 | DenseMap<SDOperand, SDOperand>::iterator I = PromotedNodes.find(Op); |
Chris Lattner | 6fdcb25 | 2005-09-02 20:32:45 +0000 | [diff] [blame] | 4064 | if (I != PromotedNodes.end()) return I->second; |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 4065 | |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4066 | switch (Node->getOpcode()) { |
Chris Lattner | d5d0f9b | 2005-08-16 21:55:35 +0000 | [diff] [blame] | 4067 | case ISD::CopyFromReg: |
| 4068 | assert(0 && "CopyFromReg must be legal!"); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4069 | default: |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 4070 | #ifndef NDEBUG |
Dan Gohman | 3983358 | 2007-06-04 16:17:33 +0000 | [diff] [blame] | 4071 | cerr << "NODE: "; Node->dump(&DAG); cerr << "\n"; |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 4072 | #endif |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4073 | assert(0 && "Do not know how to promote this operator!"); |
| 4074 | abort(); |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 4075 | case ISD::UNDEF: |
| 4076 | Result = DAG.getNode(ISD::UNDEF, NVT); |
| 4077 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4078 | case ISD::Constant: |
Chris Lattner | ec176e3 | 2005-08-30 16:56:19 +0000 | [diff] [blame] | 4079 | if (VT != MVT::i1) |
| 4080 | Result = DAG.getNode(ISD::SIGN_EXTEND, NVT, Op); |
| 4081 | else |
| 4082 | Result = DAG.getNode(ISD::ZERO_EXTEND, NVT, Op); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4083 | assert(isa<ConstantSDNode>(Result) && "Didn't constant fold zext?"); |
| 4084 | break; |
| 4085 | case ISD::ConstantFP: |
| 4086 | Result = DAG.getNode(ISD::FP_EXTEND, NVT, Op); |
| 4087 | assert(isa<ConstantFPSDNode>(Result) && "Didn't constant fold fp_extend?"); |
| 4088 | break; |
Chris Lattner | ef5cd1d | 2005-01-18 17:54:55 +0000 | [diff] [blame] | 4089 | |
Chris Lattner | 82fbfb6 | 2005-01-18 02:59:52 +0000 | [diff] [blame] | 4090 | case ISD::SETCC: |
Chris Lattner | c9c60f6 | 2005-08-24 16:35:28 +0000 | [diff] [blame] | 4091 | assert(isTypeLegal(TLI.getSetCCResultTy()) && "SetCC type is not legal??"); |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 4092 | Result = DAG.getNode(ISD::SETCC, TLI.getSetCCResultTy(),Node->getOperand(0), |
| 4093 | Node->getOperand(1), Node->getOperand(2)); |
Chris Lattner | 82fbfb6 | 2005-01-18 02:59:52 +0000 | [diff] [blame] | 4094 | break; |
Chris Lattner | fdfded5 | 2006-04-12 16:20:43 +0000 | [diff] [blame] | 4095 | |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4096 | case ISD::TRUNCATE: |
| 4097 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 4098 | case Legal: |
| 4099 | Result = LegalizeOp(Node->getOperand(0)); |
| 4100 | assert(Result.getValueType() >= NVT && |
| 4101 | "This truncation doesn't make sense!"); |
| 4102 | if (Result.getValueType() > NVT) // Truncate to NVT instead of VT |
| 4103 | Result = DAG.getNode(ISD::TRUNCATE, NVT, Result); |
| 4104 | break; |
Chris Lattner | e76ad6d | 2005-01-28 22:52:50 +0000 | [diff] [blame] | 4105 | case Promote: |
| 4106 | // The truncation is not required, because we don't guarantee anything |
| 4107 | // about high bits anyway. |
| 4108 | Result = PromoteOp(Node->getOperand(0)); |
| 4109 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4110 | case Expand: |
Nate Begeman | 79e46ac | 2005-04-04 00:57:08 +0000 | [diff] [blame] | 4111 | ExpandOp(Node->getOperand(0), Tmp1, Tmp2); |
| 4112 | // Truncate the low part of the expanded value to the result type |
Chris Lattner | e21c305 | 2005-08-01 18:16:37 +0000 | [diff] [blame] | 4113 | Result = DAG.getNode(ISD::TRUNCATE, NVT, Tmp1); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4114 | } |
| 4115 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4116 | case ISD::SIGN_EXTEND: |
| 4117 | case ISD::ZERO_EXTEND: |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 4118 | case ISD::ANY_EXTEND: |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4119 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 4120 | case Expand: assert(0 && "BUG: Smaller reg should have been promoted!"); |
| 4121 | case Legal: |
| 4122 | // 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] | 4123 | Result = DAG.getNode(Node->getOpcode(), NVT, Node->getOperand(0)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4124 | break; |
| 4125 | case Promote: |
| 4126 | // Promote the reg if it's smaller. |
| 4127 | Result = PromoteOp(Node->getOperand(0)); |
| 4128 | // The high bits are not guaranteed to be anything. Insert an extend. |
| 4129 | if (Node->getOpcode() == ISD::SIGN_EXTEND) |
Chris Lattner | 595dc54 | 2005-02-04 18:39:19 +0000 | [diff] [blame] | 4130 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Result, |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 4131 | DAG.getValueType(Node->getOperand(0).getValueType())); |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 4132 | else if (Node->getOpcode() == ISD::ZERO_EXTEND) |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 4133 | Result = DAG.getZeroExtendInReg(Result, |
| 4134 | Node->getOperand(0).getValueType()); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4135 | break; |
| 4136 | } |
| 4137 | break; |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 4138 | case ISD::BIT_CONVERT: |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 4139 | Result = EmitStackConvert(Node->getOperand(0), Node->getValueType(0), |
| 4140 | Node->getValueType(0)); |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 4141 | Result = PromoteOp(Result); |
| 4142 | break; |
| 4143 | |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4144 | case ISD::FP_EXTEND: |
| 4145 | assert(0 && "Case not implemented. Dynamically dead with 2 FP types!"); |
| 4146 | case ISD::FP_ROUND: |
| 4147 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 4148 | case Expand: assert(0 && "BUG: Cannot expand FP regs!"); |
| 4149 | case Promote: assert(0 && "Unreachable with 2 FP types!"); |
| 4150 | case Legal: |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4151 | if (Node->getConstantOperandVal(1) == 0) { |
| 4152 | // Input is legal? Do an FP_ROUND_INREG. |
| 4153 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Node->getOperand(0), |
| 4154 | DAG.getValueType(VT)); |
| 4155 | } else { |
| 4156 | // Just remove the truncate, it isn't affecting the value. |
| 4157 | Result = DAG.getNode(ISD::FP_ROUND, NVT, Node->getOperand(0), |
| 4158 | Node->getOperand(1)); |
| 4159 | } |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4160 | break; |
| 4161 | } |
| 4162 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4163 | case ISD::SINT_TO_FP: |
| 4164 | case ISD::UINT_TO_FP: |
| 4165 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 4166 | case Legal: |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4167 | // No extra round required here. |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4168 | Result = DAG.getNode(Node->getOpcode(), NVT, Node->getOperand(0)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4169 | break; |
| 4170 | |
| 4171 | case Promote: |
| 4172 | Result = PromoteOp(Node->getOperand(0)); |
| 4173 | if (Node->getOpcode() == ISD::SINT_TO_FP) |
| 4174 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(), |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 4175 | Result, |
| 4176 | DAG.getValueType(Node->getOperand(0).getValueType())); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4177 | else |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 4178 | Result = DAG.getZeroExtendInReg(Result, |
| 4179 | Node->getOperand(0).getValueType()); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4180 | // No extra round required here. |
| 4181 | Result = DAG.getNode(Node->getOpcode(), NVT, Result); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4182 | break; |
| 4183 | case Expand: |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4184 | Result = ExpandIntToFP(Node->getOpcode() == ISD::SINT_TO_FP, NVT, |
| 4185 | Node->getOperand(0)); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4186 | // Round if we cannot tolerate excess precision. |
| 4187 | if (NoExcessFPPrecision) |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 4188 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 4189 | DAG.getValueType(VT)); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4190 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4191 | } |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4192 | break; |
| 4193 | |
Chris Lattner | 5e3c5b4 | 2005-12-09 17:32:47 +0000 | [diff] [blame] | 4194 | case ISD::SIGN_EXTEND_INREG: |
| 4195 | Result = PromoteOp(Node->getOperand(0)); |
| 4196 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Result, |
| 4197 | Node->getOperand(1)); |
| 4198 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4199 | case ISD::FP_TO_SINT: |
| 4200 | case ISD::FP_TO_UINT: |
| 4201 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 4202 | case Legal: |
Evan Cheng | 0b1b9dc | 2006-12-16 02:10:30 +0000 | [diff] [blame] | 4203 | case Expand: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4204 | Tmp1 = Node->getOperand(0); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4205 | break; |
| 4206 | case Promote: |
| 4207 | // The input result is prerounded, so we don't have to do anything |
| 4208 | // special. |
| 4209 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4210 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4211 | } |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 4212 | // If we're promoting a UINT to a larger size, check to see if the new node |
| 4213 | // will be legal. If it isn't, check to see if FP_TO_SINT is legal, since |
| 4214 | // we can use that instead. This allows us to generate better code for |
| 4215 | // FP_TO_UINT for small destination sizes on targets where FP_TO_UINT is not |
| 4216 | // legal, such as PowerPC. |
| 4217 | if (Node->getOpcode() == ISD::FP_TO_UINT && |
Chris Lattner | c9c60f6 | 2005-08-24 16:35:28 +0000 | [diff] [blame] | 4218 | !TLI.isOperationLegal(ISD::FP_TO_UINT, NVT) && |
Nate Begeman | b7f6ef1 | 2005-10-25 23:47:25 +0000 | [diff] [blame] | 4219 | (TLI.isOperationLegal(ISD::FP_TO_SINT, NVT) || |
| 4220 | TLI.getOperationAction(ISD::FP_TO_SINT, NVT)==TargetLowering::Custom)){ |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 4221 | Result = DAG.getNode(ISD::FP_TO_SINT, NVT, Tmp1); |
| 4222 | } else { |
| 4223 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1); |
| 4224 | } |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4225 | break; |
| 4226 | |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 4227 | case ISD::FABS: |
| 4228 | case ISD::FNEG: |
| 4229 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4230 | assert(Tmp1.getValueType() == NVT); |
| 4231 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1); |
| 4232 | // NOTE: we do not have to do any extra rounding here for |
| 4233 | // NoExcessFPPrecision, because we know the input will have the appropriate |
| 4234 | // precision, and these operations don't modify precision at all. |
| 4235 | break; |
| 4236 | |
Chris Lattner | da6ba87 | 2005-04-28 21:44:33 +0000 | [diff] [blame] | 4237 | case ISD::FSQRT: |
| 4238 | case ISD::FSIN: |
| 4239 | case ISD::FCOS: |
| 4240 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4241 | assert(Tmp1.getValueType() == NVT); |
| 4242 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4243 | if (NoExcessFPPrecision) |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 4244 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 4245 | DAG.getValueType(VT)); |
Chris Lattner | da6ba87 | 2005-04-28 21:44:33 +0000 | [diff] [blame] | 4246 | break; |
| 4247 | |
Chris Lattner | 8b2d42c | 2007-03-03 23:43:21 +0000 | [diff] [blame] | 4248 | case ISD::FPOWI: { |
| 4249 | // Promote f32 powi to f64 powi. Note that this could insert a libcall |
| 4250 | // directly as well, which may be better. |
| 4251 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4252 | assert(Tmp1.getValueType() == NVT); |
| 4253 | Result = DAG.getNode(ISD::FPOWI, NVT, Tmp1, Node->getOperand(1)); |
| 4254 | if (NoExcessFPPrecision) |
| 4255 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 4256 | DAG.getValueType(VT)); |
| 4257 | break; |
| 4258 | } |
| 4259 | |
Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 4260 | case ISD::ATOMIC_LCS: { |
| 4261 | Tmp2 = PromoteOp(Node->getOperand(2)); |
| 4262 | Tmp3 = PromoteOp(Node->getOperand(3)); |
| 4263 | Result = DAG.getAtomic(Node->getOpcode(), Node->getOperand(0), |
| 4264 | Node->getOperand(1), Tmp2, Tmp3, |
| 4265 | cast<AtomicSDNode>(Node)->getVT()); |
| 4266 | // Remember that we legalized the chain. |
| 4267 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1))); |
| 4268 | break; |
| 4269 | } |
| 4270 | case ISD::ATOMIC_LAS: |
| 4271 | case ISD::ATOMIC_SWAP: { |
| 4272 | Tmp2 = PromoteOp(Node->getOperand(2)); |
| 4273 | Result = DAG.getAtomic(Node->getOpcode(), Node->getOperand(0), |
| 4274 | Node->getOperand(1), Tmp2, |
| 4275 | cast<AtomicSDNode>(Node)->getVT()); |
| 4276 | // Remember that we legalized the chain. |
| 4277 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1))); |
| 4278 | break; |
| 4279 | } |
| 4280 | |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4281 | case ISD::AND: |
| 4282 | case ISD::OR: |
| 4283 | case ISD::XOR: |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 4284 | case ISD::ADD: |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4285 | case ISD::SUB: |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 4286 | case ISD::MUL: |
| 4287 | // 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] | 4288 | // 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] | 4289 | // that too is okay if they are integer operations. |
| 4290 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4291 | Tmp2 = PromoteOp(Node->getOperand(1)); |
| 4292 | assert(Tmp1.getValueType() == NVT && Tmp2.getValueType() == NVT); |
| 4293 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 4294 | break; |
| 4295 | case ISD::FADD: |
| 4296 | case ISD::FSUB: |
| 4297 | case ISD::FMUL: |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 4298 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4299 | Tmp2 = PromoteOp(Node->getOperand(1)); |
| 4300 | assert(Tmp1.getValueType() == NVT && Tmp2.getValueType() == NVT); |
| 4301 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 4302 | |
| 4303 | // Floating point operations will give excess precision that we may not be |
| 4304 | // able to tolerate. If we DO allow excess precision, just leave it, |
| 4305 | // otherwise excise it. |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4306 | // FIXME: Why would we need to round FP ops more than integer ones? |
| 4307 | // 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] | 4308 | if (NoExcessFPPrecision) |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 4309 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 4310 | DAG.getValueType(VT)); |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 4311 | break; |
| 4312 | |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4313 | case ISD::SDIV: |
| 4314 | case ISD::SREM: |
| 4315 | // These operators require that their input be sign extended. |
| 4316 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4317 | Tmp2 = PromoteOp(Node->getOperand(1)); |
| 4318 | if (MVT::isInteger(NVT)) { |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 4319 | Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp1, |
| 4320 | DAG.getValueType(VT)); |
| 4321 | Tmp2 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp2, |
| 4322 | DAG.getValueType(VT)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4323 | } |
| 4324 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 4325 | |
| 4326 | // Perform FP_ROUND: this is probably overly pessimistic. |
| 4327 | if (MVT::isFloatingPoint(NVT) && NoExcessFPPrecision) |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 4328 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 4329 | DAG.getValueType(VT)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4330 | break; |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 4331 | case ISD::FDIV: |
| 4332 | case ISD::FREM: |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 4333 | case ISD::FCOPYSIGN: |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 4334 | // These operators require that their input be fp extended. |
Nate Begeman | ec57fd9 | 2006-05-09 18:20:51 +0000 | [diff] [blame] | 4335 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4336 | case Expand: assert(0 && "not implemented"); |
| 4337 | case Legal: Tmp1 = LegalizeOp(Node->getOperand(0)); break; |
| 4338 | case Promote: Tmp1 = PromoteOp(Node->getOperand(0)); break; |
Nate Begeman | ec57fd9 | 2006-05-09 18:20:51 +0000 | [diff] [blame] | 4339 | } |
| 4340 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4341 | case Expand: assert(0 && "not implemented"); |
| 4342 | case Legal: Tmp2 = LegalizeOp(Node->getOperand(1)); break; |
| 4343 | case Promote: Tmp2 = PromoteOp(Node->getOperand(1)); break; |
Nate Begeman | ec57fd9 | 2006-05-09 18:20:51 +0000 | [diff] [blame] | 4344 | } |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 4345 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 4346 | |
| 4347 | // Perform FP_ROUND: this is probably overly pessimistic. |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 4348 | if (NoExcessFPPrecision && Node->getOpcode() != ISD::FCOPYSIGN) |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 4349 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 4350 | DAG.getValueType(VT)); |
| 4351 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4352 | |
| 4353 | case ISD::UDIV: |
| 4354 | case ISD::UREM: |
| 4355 | // These operators require that their input be zero extended. |
| 4356 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4357 | Tmp2 = PromoteOp(Node->getOperand(1)); |
| 4358 | assert(MVT::isInteger(NVT) && "Operators don't apply to FP!"); |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 4359 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, VT); |
| 4360 | Tmp2 = DAG.getZeroExtendInReg(Tmp2, VT); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4361 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 4362 | break; |
| 4363 | |
| 4364 | case ISD::SHL: |
| 4365 | Tmp1 = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4366 | Result = DAG.getNode(ISD::SHL, NVT, Tmp1, Node->getOperand(1)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4367 | break; |
| 4368 | case ISD::SRA: |
| 4369 | // The input value must be properly sign extended. |
| 4370 | Tmp1 = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 4371 | Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp1, |
| 4372 | DAG.getValueType(VT)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4373 | Result = DAG.getNode(ISD::SRA, NVT, Tmp1, Node->getOperand(1)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4374 | break; |
| 4375 | case ISD::SRL: |
| 4376 | // The input value must be properly zero extended. |
| 4377 | Tmp1 = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 4378 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, VT); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4379 | Result = DAG.getNode(ISD::SRL, NVT, Tmp1, Node->getOperand(1)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4380 | break; |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 4381 | |
| 4382 | case ISD::VAARG: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4383 | Tmp1 = Node->getOperand(0); // Get the chain. |
| 4384 | Tmp2 = Node->getOperand(1); // Get the pointer. |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 4385 | if (TLI.getOperationAction(ISD::VAARG, VT) == TargetLowering::Custom) { |
| 4386 | Tmp3 = DAG.getVAArg(VT, Tmp1, Tmp2, Node->getOperand(2)); |
| 4387 | Result = TLI.CustomPromoteOperation(Tmp3, DAG); |
| 4388 | } else { |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 4389 | const Value *V = cast<SrcValueSDNode>(Node->getOperand(2))->getValue(); |
| 4390 | SDOperand VAList = DAG.getLoad(TLI.getPointerTy(), Tmp1, Tmp2, V, 0); |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 4391 | // Increment the pointer, VAList, to the next vaarg |
| 4392 | Tmp3 = DAG.getNode(ISD::ADD, TLI.getPointerTy(), VAList, |
| 4393 | DAG.getConstant(MVT::getSizeInBits(VT)/8, |
| 4394 | TLI.getPointerTy())); |
| 4395 | // Store the incremented VAList to the legalized pointer |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 4396 | Tmp3 = DAG.getStore(VAList.getValue(1), Tmp3, Tmp2, V, 0); |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 4397 | // Load the actual argument out of the pointer VAList |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 4398 | Result = DAG.getExtLoad(ISD::EXTLOAD, NVT, Tmp3, VAList, NULL, 0, VT); |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 4399 | } |
| 4400 | // Remember that we legalized the chain. |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4401 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1))); |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 4402 | break; |
| 4403 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 4404 | case ISD::LOAD: { |
| 4405 | LoadSDNode *LD = cast<LoadSDNode>(Node); |
Evan Cheng | 62f2a3c | 2006-10-10 07:51:21 +0000 | [diff] [blame] | 4406 | ISD::LoadExtType ExtType = ISD::isNON_EXTLoad(Node) |
| 4407 | ? ISD::EXTLOAD : LD->getExtensionType(); |
| 4408 | Result = DAG.getExtLoad(ExtType, NVT, |
| 4409 | LD->getChain(), LD->getBasePtr(), |
Chris Lattner | 55b5708 | 2006-10-10 18:54:19 +0000 | [diff] [blame] | 4410 | LD->getSrcValue(), LD->getSrcValueOffset(), |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 4411 | LD->getMemoryVT(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 4412 | LD->isVolatile(), |
| 4413 | LD->getAlignment()); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4414 | // Remember that we legalized the chain. |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4415 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1))); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4416 | break; |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 4417 | } |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4418 | case ISD::SELECT: |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4419 | Tmp2 = PromoteOp(Node->getOperand(1)); // Legalize the op0 |
| 4420 | Tmp3 = PromoteOp(Node->getOperand(2)); // Legalize the op1 |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4421 | Result = DAG.getNode(ISD::SELECT, NVT, Node->getOperand(0), Tmp2, Tmp3); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4422 | break; |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 4423 | case ISD::SELECT_CC: |
| 4424 | Tmp2 = PromoteOp(Node->getOperand(2)); // True |
| 4425 | Tmp3 = PromoteOp(Node->getOperand(3)); // False |
| 4426 | Result = DAG.getNode(ISD::SELECT_CC, NVT, Node->getOperand(0), |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4427 | Node->getOperand(1), Tmp2, Tmp3, Node->getOperand(4)); |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 4428 | break; |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 4429 | case ISD::BSWAP: |
| 4430 | Tmp1 = Node->getOperand(0); |
| 4431 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Tmp1); |
| 4432 | Tmp1 = DAG.getNode(ISD::BSWAP, NVT, Tmp1); |
| 4433 | Result = DAG.getNode(ISD::SRL, NVT, Tmp1, |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 4434 | DAG.getConstant(MVT::getSizeInBits(NVT) - |
| 4435 | MVT::getSizeInBits(VT), |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 4436 | TLI.getShiftAmountTy())); |
| 4437 | break; |
Andrew Lenharth | fecf095 | 2005-05-04 19:11:05 +0000 | [diff] [blame] | 4438 | case ISD::CTPOP: |
| 4439 | case ISD::CTTZ: |
| 4440 | case ISD::CTLZ: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4441 | // Zero extend the argument |
| 4442 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Node->getOperand(0)); |
Andrew Lenharth | fecf095 | 2005-05-04 19:11:05 +0000 | [diff] [blame] | 4443 | // Perform the larger operation, then subtract if needed. |
| 4444 | Tmp1 = DAG.getNode(Node->getOpcode(), NVT, Tmp1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4445 | switch(Node->getOpcode()) { |
Andrew Lenharth | fecf095 | 2005-05-04 19:11:05 +0000 | [diff] [blame] | 4446 | case ISD::CTPOP: |
| 4447 | Result = Tmp1; |
| 4448 | break; |
| 4449 | case ISD::CTTZ: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4450 | // if Tmp1 == sizeinbits(NVT) then Tmp1 = sizeinbits(Old VT) |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 4451 | Tmp2 = DAG.getSetCC(TLI.getSetCCResultTy(), Tmp1, |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 4452 | DAG.getConstant(MVT::getSizeInBits(NVT), NVT), |
| 4453 | ISD::SETEQ); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 4454 | Result = DAG.getNode(ISD::SELECT, NVT, Tmp2, |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 4455 | DAG.getConstant(MVT::getSizeInBits(VT), NVT), Tmp1); |
Andrew Lenharth | fecf095 | 2005-05-04 19:11:05 +0000 | [diff] [blame] | 4456 | break; |
| 4457 | case ISD::CTLZ: |
| 4458 | //Tmp1 = Tmp1 - (sizeinbits(NVT) - sizeinbits(Old VT)) |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 4459 | Result = DAG.getNode(ISD::SUB, NVT, Tmp1, |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 4460 | DAG.getConstant(MVT::getSizeInBits(NVT) - |
| 4461 | MVT::getSizeInBits(VT), NVT)); |
Andrew Lenharth | fecf095 | 2005-05-04 19:11:05 +0000 | [diff] [blame] | 4462 | break; |
| 4463 | } |
| 4464 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4465 | case ISD::EXTRACT_SUBVECTOR: |
| 4466 | Result = PromoteOp(ExpandEXTRACT_SUBVECTOR(Op)); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 4467 | break; |
Chris Lattner | 4aab2f4 | 2006-04-02 05:06:04 +0000 | [diff] [blame] | 4468 | case ISD::EXTRACT_VECTOR_ELT: |
| 4469 | Result = PromoteOp(ExpandEXTRACT_VECTOR_ELT(Op)); |
| 4470 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4471 | } |
| 4472 | |
| 4473 | assert(Result.Val && "Didn't set a result!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4474 | |
| 4475 | // Make sure the result is itself legal. |
| 4476 | Result = LegalizeOp(Result); |
| 4477 | |
| 4478 | // Remember that we promoted this! |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4479 | AddPromotedOperand(Op, Result); |
| 4480 | return Result; |
| 4481 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 4482 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4483 | /// ExpandEXTRACT_VECTOR_ELT - Expand an EXTRACT_VECTOR_ELT operation into |
| 4484 | /// a legal EXTRACT_VECTOR_ELT operation, scalar code, or memory traffic, |
| 4485 | /// based on the vector type. The return type of this matches the element type |
| 4486 | /// of the vector, which may not be legal for the target. |
| 4487 | SDOperand SelectionDAGLegalize::ExpandEXTRACT_VECTOR_ELT(SDOperand Op) { |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4488 | // We know that operand #0 is the Vec vector. If the index is a constant |
| 4489 | // or if the invec is a supported hardware type, we can use it. Otherwise, |
| 4490 | // lower to a store then an indexed load. |
| 4491 | SDOperand Vec = Op.getOperand(0); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4492 | SDOperand Idx = Op.getOperand(1); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4493 | |
Dan Gohman | e40c7b0 | 2007-09-24 15:54:53 +0000 | [diff] [blame] | 4494 | MVT::ValueType TVT = Vec.getValueType(); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4495 | unsigned NumElems = MVT::getVectorNumElements(TVT); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4496 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4497 | switch (TLI.getOperationAction(ISD::EXTRACT_VECTOR_ELT, TVT)) { |
| 4498 | default: assert(0 && "This action is not supported yet!"); |
| 4499 | case TargetLowering::Custom: { |
| 4500 | Vec = LegalizeOp(Vec); |
| 4501 | Op = DAG.UpdateNodeOperands(Op, Vec, Idx); |
| 4502 | SDOperand Tmp3 = TLI.LowerOperation(Op, DAG); |
| 4503 | if (Tmp3.Val) |
| 4504 | return Tmp3; |
| 4505 | break; |
| 4506 | } |
| 4507 | case TargetLowering::Legal: |
| 4508 | if (isTypeLegal(TVT)) { |
| 4509 | Vec = LegalizeOp(Vec); |
| 4510 | Op = DAG.UpdateNodeOperands(Op, Vec, Idx); |
Christopher Lamb | 844228a | 2007-07-26 03:33:13 +0000 | [diff] [blame] | 4511 | return Op; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4512 | } |
| 4513 | break; |
| 4514 | case TargetLowering::Expand: |
| 4515 | break; |
| 4516 | } |
| 4517 | |
| 4518 | if (NumElems == 1) { |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4519 | // This must be an access of the only element. Return it. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4520 | Op = ScalarizeVectorOp(Vec); |
| 4521 | } else if (!TLI.isTypeLegal(TVT) && isa<ConstantSDNode>(Idx)) { |
Nate Begeman | 55030dc | 2008-01-29 02:24:00 +0000 | [diff] [blame] | 4522 | unsigned NumLoElts = 1 << Log2_32(NumElems-1); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4523 | ConstantSDNode *CIdx = cast<ConstantSDNode>(Idx); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4524 | SDOperand Lo, Hi; |
| 4525 | SplitVectorOp(Vec, Lo, Hi); |
Nate Begeman | 55030dc | 2008-01-29 02:24:00 +0000 | [diff] [blame] | 4526 | if (CIdx->getValue() < NumLoElts) { |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4527 | Vec = Lo; |
| 4528 | } else { |
| 4529 | Vec = Hi; |
Nate Begeman | 55030dc | 2008-01-29 02:24:00 +0000 | [diff] [blame] | 4530 | Idx = DAG.getConstant(CIdx->getValue() - NumLoElts, |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4531 | Idx.getValueType()); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4532 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4533 | |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4534 | // It's now an extract from the appropriate high or low part. Recurse. |
| 4535 | Op = DAG.UpdateNodeOperands(Op, Vec, Idx); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4536 | Op = ExpandEXTRACT_VECTOR_ELT(Op); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4537 | } else { |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4538 | // Store the value to a temporary stack slot, then LOAD the scalar |
| 4539 | // element back out. |
Chris Lattner | 85dd3be | 2007-10-15 17:48:57 +0000 | [diff] [blame] | 4540 | SDOperand StackPtr = DAG.CreateStackTemporary(Vec.getValueType()); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4541 | SDOperand Ch = DAG.getStore(DAG.getEntryNode(), Vec, StackPtr, NULL, 0); |
| 4542 | |
| 4543 | // Add the offset to the index. |
| 4544 | unsigned EltSize = MVT::getSizeInBits(Op.getValueType())/8; |
| 4545 | Idx = DAG.getNode(ISD::MUL, Idx.getValueType(), Idx, |
| 4546 | DAG.getConstant(EltSize, Idx.getValueType())); |
Bill Wendling | 90bfc2d | 2007-10-18 08:32:37 +0000 | [diff] [blame] | 4547 | |
| 4548 | if (MVT::getSizeInBits(Idx.getValueType()) > |
| 4549 | MVT::getSizeInBits(TLI.getPointerTy())) |
Chris Lattner | f185e67 | 2007-10-19 16:47:35 +0000 | [diff] [blame] | 4550 | Idx = DAG.getNode(ISD::TRUNCATE, TLI.getPointerTy(), Idx); |
Bill Wendling | 90bfc2d | 2007-10-18 08:32:37 +0000 | [diff] [blame] | 4551 | else |
Chris Lattner | f185e67 | 2007-10-19 16:47:35 +0000 | [diff] [blame] | 4552 | Idx = DAG.getNode(ISD::ZERO_EXTEND, TLI.getPointerTy(), Idx); |
Bill Wendling | 90bfc2d | 2007-10-18 08:32:37 +0000 | [diff] [blame] | 4553 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4554 | StackPtr = DAG.getNode(ISD::ADD, Idx.getValueType(), Idx, StackPtr); |
| 4555 | |
| 4556 | Op = DAG.getLoad(Op.getValueType(), Ch, StackPtr, NULL, 0); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4557 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4558 | return Op; |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4559 | } |
| 4560 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4561 | /// ExpandEXTRACT_SUBVECTOR - Expand a EXTRACT_SUBVECTOR operation. For now |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 4562 | /// 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] | 4563 | SDOperand SelectionDAGLegalize::ExpandEXTRACT_SUBVECTOR(SDOperand Op) { |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 4564 | // We know that operand #0 is the Vec vector. For now we assume the index |
| 4565 | // is a constant and that the extracted result is a supported hardware type. |
| 4566 | SDOperand Vec = Op.getOperand(0); |
| 4567 | SDOperand Idx = LegalizeOp(Op.getOperand(1)); |
| 4568 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4569 | unsigned NumElems = MVT::getVectorNumElements(Vec.getValueType()); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 4570 | |
| 4571 | if (NumElems == MVT::getVectorNumElements(Op.getValueType())) { |
| 4572 | // This must be an access of the desired vector length. Return it. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4573 | return Vec; |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 4574 | } |
| 4575 | |
| 4576 | ConstantSDNode *CIdx = cast<ConstantSDNode>(Idx); |
| 4577 | SDOperand Lo, Hi; |
| 4578 | SplitVectorOp(Vec, Lo, Hi); |
| 4579 | if (CIdx->getValue() < NumElems/2) { |
| 4580 | Vec = Lo; |
| 4581 | } else { |
| 4582 | Vec = Hi; |
| 4583 | Idx = DAG.getConstant(CIdx->getValue() - NumElems/2, Idx.getValueType()); |
| 4584 | } |
| 4585 | |
| 4586 | // It's now an extract from the appropriate high or low part. Recurse. |
| 4587 | Op = DAG.UpdateNodeOperands(Op, Vec, Idx); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4588 | return ExpandEXTRACT_SUBVECTOR(Op); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 4589 | } |
| 4590 | |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 4591 | /// LegalizeSetCCOperands - Attempts to create a legal LHS and RHS for a SETCC |
| 4592 | /// with condition CC on the current target. This usually involves legalizing |
| 4593 | /// or promoting the arguments. In the case where LHS and RHS must be expanded, |
| 4594 | /// there may be no choice but to create a new SetCC node to represent the |
| 4595 | /// legalized value of setcc lhs, rhs. In this case, the value is returned in |
| 4596 | /// LHS, and the SDOperand returned in RHS has a nil SDNode value. |
| 4597 | void SelectionDAGLegalize::LegalizeSetCCOperands(SDOperand &LHS, |
| 4598 | SDOperand &RHS, |
| 4599 | SDOperand &CC) { |
Dale Johannesen | 638ccd5 | 2007-10-06 01:24:11 +0000 | [diff] [blame] | 4600 | SDOperand Tmp1, Tmp2, Tmp3, Result; |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 4601 | |
| 4602 | switch (getTypeAction(LHS.getValueType())) { |
| 4603 | case Legal: |
| 4604 | Tmp1 = LegalizeOp(LHS); // LHS |
| 4605 | Tmp2 = LegalizeOp(RHS); // RHS |
| 4606 | break; |
| 4607 | case Promote: |
| 4608 | Tmp1 = PromoteOp(LHS); // LHS |
| 4609 | Tmp2 = PromoteOp(RHS); // RHS |
| 4610 | |
| 4611 | // If this is an FP compare, the operands have already been extended. |
| 4612 | if (MVT::isInteger(LHS.getValueType())) { |
| 4613 | MVT::ValueType VT = LHS.getValueType(); |
| 4614 | MVT::ValueType NVT = TLI.getTypeToTransformTo(VT); |
| 4615 | |
| 4616 | // Otherwise, we have to insert explicit sign or zero extends. Note |
| 4617 | // that we could insert sign extends for ALL conditions, but zero extend |
| 4618 | // is cheaper on many machines (an AND instead of two shifts), so prefer |
| 4619 | // it. |
| 4620 | switch (cast<CondCodeSDNode>(CC)->get()) { |
| 4621 | default: assert(0 && "Unknown integer comparison!"); |
| 4622 | case ISD::SETEQ: |
| 4623 | case ISD::SETNE: |
| 4624 | case ISD::SETUGE: |
| 4625 | case ISD::SETUGT: |
| 4626 | case ISD::SETULE: |
| 4627 | case ISD::SETULT: |
| 4628 | // ALL of these operations will work if we either sign or zero extend |
| 4629 | // the operands (including the unsigned comparisons!). Zero extend is |
| 4630 | // usually a simpler/cheaper operation, so prefer it. |
| 4631 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, VT); |
| 4632 | Tmp2 = DAG.getZeroExtendInReg(Tmp2, VT); |
| 4633 | break; |
| 4634 | case ISD::SETGE: |
| 4635 | case ISD::SETGT: |
| 4636 | case ISD::SETLT: |
| 4637 | case ISD::SETLE: |
| 4638 | Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp1, |
| 4639 | DAG.getValueType(VT)); |
| 4640 | Tmp2 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp2, |
| 4641 | DAG.getValueType(VT)); |
| 4642 | break; |
| 4643 | } |
| 4644 | } |
| 4645 | break; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4646 | case Expand: { |
| 4647 | MVT::ValueType VT = LHS.getValueType(); |
| 4648 | if (VT == MVT::f32 || VT == MVT::f64) { |
| 4649 | // Expand into one or more soft-fp libcall(s). |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4650 | RTLIB::Libcall LC1, LC2 = RTLIB::UNKNOWN_LIBCALL; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4651 | switch (cast<CondCodeSDNode>(CC)->get()) { |
| 4652 | case ISD::SETEQ: |
| 4653 | case ISD::SETOEQ: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4654 | LC1 = (VT == MVT::f32) ? RTLIB::OEQ_F32 : RTLIB::OEQ_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4655 | break; |
| 4656 | case ISD::SETNE: |
| 4657 | case ISD::SETUNE: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4658 | LC1 = (VT == MVT::f32) ? RTLIB::UNE_F32 : RTLIB::UNE_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4659 | break; |
| 4660 | case ISD::SETGE: |
| 4661 | case ISD::SETOGE: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4662 | LC1 = (VT == MVT::f32) ? RTLIB::OGE_F32 : RTLIB::OGE_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4663 | break; |
| 4664 | case ISD::SETLT: |
| 4665 | case ISD::SETOLT: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4666 | LC1 = (VT == MVT::f32) ? RTLIB::OLT_F32 : RTLIB::OLT_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4667 | break; |
| 4668 | case ISD::SETLE: |
| 4669 | case ISD::SETOLE: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4670 | LC1 = (VT == MVT::f32) ? RTLIB::OLE_F32 : RTLIB::OLE_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4671 | break; |
| 4672 | case ISD::SETGT: |
| 4673 | case ISD::SETOGT: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4674 | LC1 = (VT == MVT::f32) ? RTLIB::OGT_F32 : RTLIB::OGT_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4675 | break; |
| 4676 | case ISD::SETUO: |
Evan Cheng | d385fd6 | 2007-01-31 09:29:11 +0000 | [diff] [blame] | 4677 | LC1 = (VT == MVT::f32) ? RTLIB::UO_F32 : RTLIB::UO_F64; |
| 4678 | break; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4679 | case ISD::SETO: |
Evan Cheng | 5efdecc | 2007-02-03 00:43:46 +0000 | [diff] [blame] | 4680 | LC1 = (VT == MVT::f32) ? RTLIB::O_F32 : RTLIB::O_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4681 | break; |
| 4682 | default: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4683 | LC1 = (VT == MVT::f32) ? RTLIB::UO_F32 : RTLIB::UO_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4684 | switch (cast<CondCodeSDNode>(CC)->get()) { |
| 4685 | case ISD::SETONE: |
| 4686 | // SETONE = SETOLT | SETOGT |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4687 | LC1 = (VT == MVT::f32) ? RTLIB::OLT_F32 : RTLIB::OLT_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4688 | // Fallthrough |
| 4689 | case ISD::SETUGT: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4690 | LC2 = (VT == MVT::f32) ? RTLIB::OGT_F32 : RTLIB::OGT_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4691 | break; |
| 4692 | case ISD::SETUGE: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4693 | LC2 = (VT == MVT::f32) ? RTLIB::OGE_F32 : RTLIB::OGE_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4694 | break; |
| 4695 | case ISD::SETULT: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4696 | LC2 = (VT == MVT::f32) ? RTLIB::OLT_F32 : RTLIB::OLT_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4697 | break; |
| 4698 | case ISD::SETULE: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4699 | LC2 = (VT == MVT::f32) ? RTLIB::OLE_F32 : RTLIB::OLE_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4700 | break; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4701 | case ISD::SETUEQ: |
| 4702 | LC2 = (VT == MVT::f32) ? RTLIB::OEQ_F32 : RTLIB::OEQ_F64; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4703 | break; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4704 | default: assert(0 && "Unsupported FP setcc!"); |
| 4705 | } |
| 4706 | } |
| 4707 | |
| 4708 | SDOperand Dummy; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4709 | Tmp1 = ExpandLibCall(TLI.getLibcallName(LC1), |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 4710 | DAG.getNode(ISD::MERGE_VALUES, VT, LHS, RHS).Val, |
Reid Spencer | b47b25c | 2007-01-03 04:22:32 +0000 | [diff] [blame] | 4711 | false /*sign irrelevant*/, Dummy); |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4712 | Tmp2 = DAG.getConstant(0, MVT::i32); |
Evan Cheng | d385fd6 | 2007-01-31 09:29:11 +0000 | [diff] [blame] | 4713 | CC = DAG.getCondCode(TLI.getCmpLibcallCC(LC1)); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4714 | if (LC2 != RTLIB::UNKNOWN_LIBCALL) { |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4715 | Tmp1 = DAG.getNode(ISD::SETCC, TLI.getSetCCResultTy(), Tmp1, Tmp2, CC); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4716 | LHS = ExpandLibCall(TLI.getLibcallName(LC2), |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 4717 | DAG.getNode(ISD::MERGE_VALUES, VT, LHS, RHS).Val, |
Reid Spencer | b47b25c | 2007-01-03 04:22:32 +0000 | [diff] [blame] | 4718 | false /*sign irrelevant*/, Dummy); |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4719 | Tmp2 = DAG.getNode(ISD::SETCC, TLI.getSetCCResultTy(), LHS, Tmp2, |
Evan Cheng | d385fd6 | 2007-01-31 09:29:11 +0000 | [diff] [blame] | 4720 | DAG.getCondCode(TLI.getCmpLibcallCC(LC2))); |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4721 | Tmp1 = DAG.getNode(ISD::OR, Tmp1.getValueType(), Tmp1, Tmp2); |
| 4722 | Tmp2 = SDOperand(); |
| 4723 | } |
| 4724 | LHS = Tmp1; |
| 4725 | RHS = Tmp2; |
| 4726 | return; |
| 4727 | } |
| 4728 | |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 4729 | SDOperand LHSLo, LHSHi, RHSLo, RHSHi; |
| 4730 | ExpandOp(LHS, LHSLo, LHSHi); |
Dale Johannesen | 638ccd5 | 2007-10-06 01:24:11 +0000 | [diff] [blame] | 4731 | ExpandOp(RHS, RHSLo, RHSHi); |
| 4732 | ISD::CondCode CCCode = cast<CondCodeSDNode>(CC)->get(); |
| 4733 | |
| 4734 | if (VT==MVT::ppcf128) { |
| 4735 | // FIXME: This generated code sucks. We want to generate |
| 4736 | // FCMP crN, hi1, hi2 |
| 4737 | // BNE crN, L: |
| 4738 | // FCMP crN, lo1, lo2 |
| 4739 | // The following can be improved, but not that much. |
| 4740 | Tmp1 = DAG.getSetCC(TLI.getSetCCResultTy(), LHSHi, RHSHi, ISD::SETEQ); |
| 4741 | Tmp2 = DAG.getSetCC(TLI.getSetCCResultTy(), LHSLo, RHSLo, CCCode); |
| 4742 | Tmp3 = DAG.getNode(ISD::AND, Tmp1.getValueType(), Tmp1, Tmp2); |
| 4743 | Tmp1 = DAG.getSetCC(TLI.getSetCCResultTy(), LHSHi, RHSHi, ISD::SETNE); |
| 4744 | Tmp2 = DAG.getSetCC(TLI.getSetCCResultTy(), LHSHi, RHSHi, CCCode); |
| 4745 | Tmp1 = DAG.getNode(ISD::AND, Tmp1.getValueType(), Tmp1, Tmp2); |
| 4746 | Tmp1 = DAG.getNode(ISD::OR, Tmp1.getValueType(), Tmp1, Tmp3); |
| 4747 | Tmp2 = SDOperand(); |
| 4748 | break; |
| 4749 | } |
| 4750 | |
| 4751 | switch (CCCode) { |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 4752 | case ISD::SETEQ: |
| 4753 | case ISD::SETNE: |
| 4754 | if (RHSLo == RHSHi) |
| 4755 | if (ConstantSDNode *RHSCST = dyn_cast<ConstantSDNode>(RHSLo)) |
| 4756 | if (RHSCST->isAllOnesValue()) { |
| 4757 | // Comparison to -1. |
| 4758 | Tmp1 = DAG.getNode(ISD::AND, LHSLo.getValueType(), LHSLo, LHSHi); |
| 4759 | Tmp2 = RHSLo; |
| 4760 | break; |
| 4761 | } |
| 4762 | |
| 4763 | Tmp1 = DAG.getNode(ISD::XOR, LHSLo.getValueType(), LHSLo, RHSLo); |
| 4764 | Tmp2 = DAG.getNode(ISD::XOR, LHSLo.getValueType(), LHSHi, RHSHi); |
| 4765 | Tmp1 = DAG.getNode(ISD::OR, Tmp1.getValueType(), Tmp1, Tmp2); |
| 4766 | Tmp2 = DAG.getConstant(0, Tmp1.getValueType()); |
| 4767 | break; |
| 4768 | default: |
| 4769 | // If this is a comparison of the sign bit, just look at the top part. |
| 4770 | // X > -1, x < 0 |
| 4771 | if (ConstantSDNode *CST = dyn_cast<ConstantSDNode>(RHS)) |
| 4772 | if ((cast<CondCodeSDNode>(CC)->get() == ISD::SETLT && |
| 4773 | CST->getValue() == 0) || // X < 0 |
| 4774 | (cast<CondCodeSDNode>(CC)->get() == ISD::SETGT && |
| 4775 | CST->isAllOnesValue())) { // X > -1 |
| 4776 | Tmp1 = LHSHi; |
| 4777 | Tmp2 = RHSHi; |
| 4778 | break; |
| 4779 | } |
| 4780 | |
| 4781 | // FIXME: This generated code sucks. |
| 4782 | ISD::CondCode LowCC; |
Evan Cheng | 2e67781 | 2007-02-08 22:16:19 +0000 | [diff] [blame] | 4783 | switch (CCCode) { |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 4784 | default: assert(0 && "Unknown integer setcc!"); |
| 4785 | case ISD::SETLT: |
| 4786 | case ISD::SETULT: LowCC = ISD::SETULT; break; |
| 4787 | case ISD::SETGT: |
| 4788 | case ISD::SETUGT: LowCC = ISD::SETUGT; break; |
| 4789 | case ISD::SETLE: |
| 4790 | case ISD::SETULE: LowCC = ISD::SETULE; break; |
| 4791 | case ISD::SETGE: |
| 4792 | case ISD::SETUGE: LowCC = ISD::SETUGE; break; |
| 4793 | } |
| 4794 | |
| 4795 | // Tmp1 = lo(op1) < lo(op2) // Always unsigned comparison |
| 4796 | // Tmp2 = hi(op1) < hi(op2) // Signedness depends on operands |
| 4797 | // dest = hi(op1) == hi(op2) ? Tmp1 : Tmp2; |
| 4798 | |
| 4799 | // NOTE: on targets without efficient SELECT of bools, we can always use |
| 4800 | // this identity: (B1 ? B2 : B3) --> (B1 & B2)|(!B1&B3) |
Evan Cheng | 2e67781 | 2007-02-08 22:16:19 +0000 | [diff] [blame] | 4801 | TargetLowering::DAGCombinerInfo DagCombineInfo(DAG, false, true, NULL); |
| 4802 | Tmp1 = TLI.SimplifySetCC(TLI.getSetCCResultTy(), LHSLo, RHSLo, LowCC, |
| 4803 | false, DagCombineInfo); |
| 4804 | if (!Tmp1.Val) |
| 4805 | Tmp1 = DAG.getSetCC(TLI.getSetCCResultTy(), LHSLo, RHSLo, LowCC); |
| 4806 | Tmp2 = TLI.SimplifySetCC(TLI.getSetCCResultTy(), LHSHi, RHSHi, |
| 4807 | CCCode, false, DagCombineInfo); |
| 4808 | if (!Tmp2.Val) |
Chris Lattner | 85dd3be | 2007-10-15 17:48:57 +0000 | [diff] [blame] | 4809 | Tmp2 = DAG.getNode(ISD::SETCC, TLI.getSetCCResultTy(), LHSHi, RHSHi,CC); |
Evan Cheng | 2e67781 | 2007-02-08 22:16:19 +0000 | [diff] [blame] | 4810 | |
| 4811 | ConstantSDNode *Tmp1C = dyn_cast<ConstantSDNode>(Tmp1.Val); |
| 4812 | ConstantSDNode *Tmp2C = dyn_cast<ConstantSDNode>(Tmp2.Val); |
| 4813 | if ((Tmp1C && Tmp1C->getValue() == 0) || |
| 4814 | (Tmp2C && Tmp2C->getValue() == 0 && |
| 4815 | (CCCode == ISD::SETLE || CCCode == ISD::SETGE || |
| 4816 | CCCode == ISD::SETUGE || CCCode == ISD::SETULE)) || |
| 4817 | (Tmp2C && Tmp2C->getValue() == 1 && |
| 4818 | (CCCode == ISD::SETLT || CCCode == ISD::SETGT || |
| 4819 | CCCode == ISD::SETUGT || CCCode == ISD::SETULT))) { |
| 4820 | // low part is known false, returns high part. |
| 4821 | // For LE / GE, if high part is known false, ignore the low part. |
| 4822 | // For LT / GT, if high part is known true, ignore the low part. |
| 4823 | Tmp1 = Tmp2; |
| 4824 | Tmp2 = SDOperand(); |
| 4825 | } else { |
| 4826 | Result = TLI.SimplifySetCC(TLI.getSetCCResultTy(), LHSHi, RHSHi, |
| 4827 | ISD::SETEQ, false, DagCombineInfo); |
| 4828 | if (!Result.Val) |
| 4829 | Result=DAG.getSetCC(TLI.getSetCCResultTy(), LHSHi, RHSHi, ISD::SETEQ); |
| 4830 | Result = LegalizeOp(DAG.getNode(ISD::SELECT, Tmp1.getValueType(), |
| 4831 | Result, Tmp1, Tmp2)); |
| 4832 | Tmp1 = Result; |
| 4833 | Tmp2 = SDOperand(); |
| 4834 | } |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 4835 | } |
| 4836 | } |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4837 | } |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 4838 | LHS = Tmp1; |
| 4839 | RHS = Tmp2; |
| 4840 | } |
| 4841 | |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 4842 | /// EmitStackConvert - Emit a store/load combination to the stack. This stores |
| 4843 | /// SrcOp to a stack slot of type SlotVT, truncating it if needed. It then does |
| 4844 | /// a load from the stack slot to DestVT, extending it if needed. |
| 4845 | /// The resultant code need not be legal. |
| 4846 | SDOperand SelectionDAGLegalize::EmitStackConvert(SDOperand SrcOp, |
| 4847 | MVT::ValueType SlotVT, |
| 4848 | MVT::ValueType DestVT) { |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 4849 | // Create the stack frame object. |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 4850 | SDOperand FIPtr = DAG.CreateStackTemporary(SlotVT); |
| 4851 | |
Dan Gohman | bbbbb9c | 2008-02-11 18:58:42 +0000 | [diff] [blame] | 4852 | FrameIndexSDNode *StackPtrFI = cast<FrameIndexSDNode>(FIPtr); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 4853 | int SPFI = StackPtrFI->getIndex(); |
| 4854 | |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 4855 | unsigned SrcSize = MVT::getSizeInBits(SrcOp.getValueType()); |
| 4856 | unsigned SlotSize = MVT::getSizeInBits(SlotVT); |
| 4857 | unsigned DestSize = MVT::getSizeInBits(DestVT); |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 4858 | |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 4859 | // Emit a store to the stack slot. Use a truncstore if the input value is |
| 4860 | // later than DestVT. |
| 4861 | SDOperand Store; |
| 4862 | if (SrcSize > SlotSize) |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 4863 | Store = DAG.getTruncStore(DAG.getEntryNode(), SrcOp, FIPtr, |
Dan Gohman | 3069b87 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 4864 | PseudoSourceValue::getFixedStack(), |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 4865 | SPFI, SlotVT); |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 4866 | else { |
| 4867 | assert(SrcSize == SlotSize && "Invalid store"); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 4868 | Store = DAG.getStore(DAG.getEntryNode(), SrcOp, FIPtr, |
Dan Gohman | 3069b87 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 4869 | PseudoSourceValue::getFixedStack(), |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 4870 | SPFI, SlotVT); |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 4871 | } |
| 4872 | |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 4873 | // Result is a load from the stack slot. |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 4874 | if (SlotSize == DestSize) |
| 4875 | return DAG.getLoad(DestVT, Store, FIPtr, NULL, 0); |
| 4876 | |
| 4877 | assert(SlotSize < DestSize && "Unknown extension!"); |
| 4878 | return DAG.getExtLoad(ISD::EXTLOAD, DestVT, Store, FIPtr, NULL, 0, SlotVT); |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 4879 | } |
| 4880 | |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 4881 | SDOperand SelectionDAGLegalize::ExpandSCALAR_TO_VECTOR(SDNode *Node) { |
| 4882 | // Create a vector sized/aligned stack slot, store the value to element #0, |
| 4883 | // then load the whole vector back out. |
Chris Lattner | 85dd3be | 2007-10-15 17:48:57 +0000 | [diff] [blame] | 4884 | SDOperand StackPtr = DAG.CreateStackTemporary(Node->getValueType(0)); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 4885 | |
Dan Gohman | bbbbb9c | 2008-02-11 18:58:42 +0000 | [diff] [blame] | 4886 | FrameIndexSDNode *StackPtrFI = cast<FrameIndexSDNode>(StackPtr); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 4887 | int SPFI = StackPtrFI->getIndex(); |
| 4888 | |
Evan Cheng | 786225a | 2006-10-05 23:01:46 +0000 | [diff] [blame] | 4889 | SDOperand Ch = DAG.getStore(DAG.getEntryNode(), Node->getOperand(0), StackPtr, |
Dan Gohman | 3069b87 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 4890 | PseudoSourceValue::getFixedStack(), SPFI); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 4891 | return DAG.getLoad(Node->getValueType(0), Ch, StackPtr, |
Dan Gohman | 3069b87 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 4892 | PseudoSourceValue::getFixedStack(), SPFI); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 4893 | } |
| 4894 | |
| 4895 | |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4896 | /// ExpandBUILD_VECTOR - Expand a BUILD_VECTOR node on targets that don't |
Dan Gohman | 07a9676 | 2007-07-16 14:29:03 +0000 | [diff] [blame] | 4897 | /// support the operation, but do support the resultant vector type. |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4898 | SDOperand SelectionDAGLegalize::ExpandBUILD_VECTOR(SDNode *Node) { |
| 4899 | |
| 4900 | // 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] | 4901 | // 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] | 4902 | unsigned NumElems = Node->getNumOperands(); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4903 | bool isOnlyLowElement = true; |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 4904 | SDOperand SplatValue = Node->getOperand(0); |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 4905 | std::map<SDOperand, std::vector<unsigned> > Values; |
| 4906 | Values[SplatValue].push_back(0); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 4907 | bool isConstant = true; |
| 4908 | if (!isa<ConstantFPSDNode>(SplatValue) && !isa<ConstantSDNode>(SplatValue) && |
| 4909 | SplatValue.getOpcode() != ISD::UNDEF) |
| 4910 | isConstant = false; |
| 4911 | |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 4912 | for (unsigned i = 1; i < NumElems; ++i) { |
| 4913 | SDOperand V = Node->getOperand(i); |
Chris Lattner | 89a1b38 | 2006-04-19 23:17:50 +0000 | [diff] [blame] | 4914 | Values[V].push_back(i); |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 4915 | if (V.getOpcode() != ISD::UNDEF) |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4916 | isOnlyLowElement = false; |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 4917 | if (SplatValue != V) |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 4918 | SplatValue = SDOperand(0,0); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 4919 | |
| 4920 | // If this isn't a constant element or an undef, we can't use a constant |
| 4921 | // pool load. |
| 4922 | if (!isa<ConstantFPSDNode>(V) && !isa<ConstantSDNode>(V) && |
| 4923 | V.getOpcode() != ISD::UNDEF) |
| 4924 | isConstant = false; |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4925 | } |
| 4926 | |
| 4927 | if (isOnlyLowElement) { |
| 4928 | // If the low element is an undef too, then this whole things is an undef. |
| 4929 | if (Node->getOperand(0).getOpcode() == ISD::UNDEF) |
| 4930 | return DAG.getNode(ISD::UNDEF, Node->getValueType(0)); |
| 4931 | // Otherwise, turn this into a scalar_to_vector node. |
| 4932 | return DAG.getNode(ISD::SCALAR_TO_VECTOR, Node->getValueType(0), |
| 4933 | Node->getOperand(0)); |
| 4934 | } |
| 4935 | |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 4936 | // If all elements are constants, create a load from the constant pool. |
| 4937 | if (isConstant) { |
| 4938 | MVT::ValueType VT = Node->getValueType(0); |
| 4939 | const Type *OpNTy = |
| 4940 | MVT::getTypeForValueType(Node->getOperand(0).getValueType()); |
| 4941 | std::vector<Constant*> CV; |
| 4942 | for (unsigned i = 0, e = NumElems; i != e; ++i) { |
| 4943 | if (ConstantFPSDNode *V = |
| 4944 | dyn_cast<ConstantFPSDNode>(Node->getOperand(i))) { |
Dale Johannesen | f04afdb | 2007-08-30 00:23:21 +0000 | [diff] [blame] | 4945 | CV.push_back(ConstantFP::get(OpNTy, V->getValueAPF())); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 4946 | } else if (ConstantSDNode *V = |
| 4947 | dyn_cast<ConstantSDNode>(Node->getOperand(i))) { |
Reid Spencer | b83eb64 | 2006-10-20 07:07:24 +0000 | [diff] [blame] | 4948 | CV.push_back(ConstantInt::get(OpNTy, V->getValue())); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 4949 | } else { |
| 4950 | assert(Node->getOperand(i).getOpcode() == ISD::UNDEF); |
| 4951 | CV.push_back(UndefValue::get(OpNTy)); |
| 4952 | } |
| 4953 | } |
Reid Spencer | 9d6565a | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 4954 | Constant *CP = ConstantVector::get(CV); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 4955 | SDOperand CPIdx = DAG.getConstantPool(CP, TLI.getPointerTy()); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 4956 | return DAG.getLoad(VT, DAG.getEntryNode(), CPIdx, |
Dan Gohman | 3069b87 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 4957 | PseudoSourceValue::getConstantPool(), 0); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 4958 | } |
| 4959 | |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 4960 | if (SplatValue.Val) { // Splat of one value? |
| 4961 | // Build the shuffle constant vector: <0, 0, 0, 0> |
| 4962 | MVT::ValueType MaskVT = |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 4963 | MVT::getIntVectorWithNumElements(NumElems); |
Dan Gohman | 51eaa86 | 2007-06-14 22:58:02 +0000 | [diff] [blame] | 4964 | SDOperand Zero = DAG.getConstant(0, MVT::getVectorElementType(MaskVT)); |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 4965 | std::vector<SDOperand> ZeroVec(NumElems, Zero); |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 4966 | SDOperand SplatMask = DAG.getNode(ISD::BUILD_VECTOR, MaskVT, |
| 4967 | &ZeroVec[0], ZeroVec.size()); |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 4968 | |
| 4969 | // If the target supports VECTOR_SHUFFLE and this shuffle mask, use it. |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 4970 | if (isShuffleLegal(Node->getValueType(0), SplatMask)) { |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 4971 | // Get the splatted value into the low element of a vector register. |
| 4972 | SDOperand LowValVec = |
| 4973 | DAG.getNode(ISD::SCALAR_TO_VECTOR, Node->getValueType(0), SplatValue); |
| 4974 | |
| 4975 | // Return shuffle(LowValVec, undef, <0,0,0,0>) |
| 4976 | return DAG.getNode(ISD::VECTOR_SHUFFLE, Node->getValueType(0), LowValVec, |
| 4977 | DAG.getNode(ISD::UNDEF, Node->getValueType(0)), |
| 4978 | SplatMask); |
| 4979 | } |
| 4980 | } |
| 4981 | |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 4982 | // If there are only two unique elements, we may be able to turn this into a |
| 4983 | // vector shuffle. |
| 4984 | if (Values.size() == 2) { |
| 4985 | // Build the shuffle constant vector: e.g. <0, 4, 0, 4> |
| 4986 | MVT::ValueType MaskVT = |
| 4987 | MVT::getIntVectorWithNumElements(NumElems); |
| 4988 | std::vector<SDOperand> MaskVec(NumElems); |
| 4989 | unsigned i = 0; |
| 4990 | for (std::map<SDOperand,std::vector<unsigned> >::iterator I=Values.begin(), |
| 4991 | E = Values.end(); I != E; ++I) { |
| 4992 | for (std::vector<unsigned>::iterator II = I->second.begin(), |
| 4993 | EE = I->second.end(); II != EE; ++II) |
Dan Gohman | 51eaa86 | 2007-06-14 22:58:02 +0000 | [diff] [blame] | 4994 | MaskVec[*II] = DAG.getConstant(i, MVT::getVectorElementType(MaskVT)); |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 4995 | i += NumElems; |
| 4996 | } |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 4997 | SDOperand ShuffleMask = DAG.getNode(ISD::BUILD_VECTOR, MaskVT, |
| 4998 | &MaskVec[0], MaskVec.size()); |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 4999 | |
| 5000 | // If the target supports VECTOR_SHUFFLE and this shuffle mask, use it. |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 5001 | if (TLI.isOperationLegal(ISD::SCALAR_TO_VECTOR, Node->getValueType(0)) && |
| 5002 | isShuffleLegal(Node->getValueType(0), ShuffleMask)) { |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 5003 | SmallVector<SDOperand, 8> Ops; |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 5004 | for(std::map<SDOperand,std::vector<unsigned> >::iterator I=Values.begin(), |
| 5005 | E = Values.end(); I != E; ++I) { |
| 5006 | SDOperand Op = DAG.getNode(ISD::SCALAR_TO_VECTOR, Node->getValueType(0), |
| 5007 | I->first); |
| 5008 | Ops.push_back(Op); |
| 5009 | } |
| 5010 | Ops.push_back(ShuffleMask); |
| 5011 | |
| 5012 | // Return shuffle(LoValVec, HiValVec, <0,1,0,1>) |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 5013 | return DAG.getNode(ISD::VECTOR_SHUFFLE, Node->getValueType(0), |
| 5014 | &Ops[0], Ops.size()); |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 5015 | } |
| 5016 | } |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5017 | |
| 5018 | // Otherwise, we can't handle this case efficiently. Allocate a sufficiently |
| 5019 | // aligned object on the stack, store each element into it, then load |
| 5020 | // the result as a vector. |
| 5021 | MVT::ValueType VT = Node->getValueType(0); |
| 5022 | // Create the stack frame object. |
Chris Lattner | 85dd3be | 2007-10-15 17:48:57 +0000 | [diff] [blame] | 5023 | SDOperand FIPtr = DAG.CreateStackTemporary(VT); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5024 | |
| 5025 | // Emit a store of each element to the stack slot. |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 5026 | SmallVector<SDOperand, 8> Stores; |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5027 | unsigned TypeByteSize = |
| 5028 | MVT::getSizeInBits(Node->getOperand(0).getValueType())/8; |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5029 | // Store (in the right endianness) the elements to memory. |
| 5030 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) { |
| 5031 | // Ignore undef elements. |
| 5032 | if (Node->getOperand(i).getOpcode() == ISD::UNDEF) continue; |
| 5033 | |
Chris Lattner | 841c882 | 2006-03-22 01:46:54 +0000 | [diff] [blame] | 5034 | unsigned Offset = TypeByteSize*i; |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5035 | |
| 5036 | SDOperand Idx = DAG.getConstant(Offset, FIPtr.getValueType()); |
| 5037 | Idx = DAG.getNode(ISD::ADD, FIPtr.getValueType(), FIPtr, Idx); |
| 5038 | |
Evan Cheng | 786225a | 2006-10-05 23:01:46 +0000 | [diff] [blame] | 5039 | Stores.push_back(DAG.getStore(DAG.getEntryNode(), Node->getOperand(i), Idx, |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 5040 | NULL, 0)); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5041 | } |
| 5042 | |
| 5043 | SDOperand StoreChain; |
| 5044 | if (!Stores.empty()) // Not all undef elements? |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 5045 | StoreChain = DAG.getNode(ISD::TokenFactor, MVT::Other, |
| 5046 | &Stores[0], Stores.size()); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5047 | else |
| 5048 | StoreChain = DAG.getEntryNode(); |
| 5049 | |
| 5050 | // Result is a load from the stack slot. |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 5051 | return DAG.getLoad(VT, StoreChain, FIPtr, NULL, 0); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5052 | } |
| 5053 | |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 5054 | void SelectionDAGLegalize::ExpandShiftParts(unsigned NodeOp, |
| 5055 | SDOperand Op, SDOperand Amt, |
| 5056 | SDOperand &Lo, SDOperand &Hi) { |
| 5057 | // Expand the subcomponents. |
| 5058 | SDOperand LHSL, LHSH; |
| 5059 | ExpandOp(Op, LHSL, LHSH); |
| 5060 | |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 5061 | SDOperand Ops[] = { LHSL, LHSH, Amt }; |
Chris Lattner | f9f37fc | 2006-08-14 23:53:35 +0000 | [diff] [blame] | 5062 | MVT::ValueType VT = LHSL.getValueType(); |
| 5063 | Lo = DAG.getNode(NodeOp, DAG.getNodeValueTypes(VT, VT), 2, Ops, 3); |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 5064 | Hi = Lo.getValue(1); |
| 5065 | } |
| 5066 | |
| 5067 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5068 | /// ExpandShift - Try to find a clever way to expand this shift operation out to |
| 5069 | /// smaller elements. If we can't find a way that is more efficient than a |
| 5070 | /// libcall on this target, return false. Otherwise, return true with the |
| 5071 | /// low-parts expanded into Lo and Hi. |
| 5072 | bool SelectionDAGLegalize::ExpandShift(unsigned Opc, SDOperand Op,SDOperand Amt, |
| 5073 | SDOperand &Lo, SDOperand &Hi) { |
| 5074 | assert((Opc == ISD::SHL || Opc == ISD::SRA || Opc == ISD::SRL) && |
| 5075 | "This is not a shift!"); |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5076 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5077 | MVT::ValueType NVT = TLI.getTypeToTransformTo(Op.getValueType()); |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5078 | SDOperand ShAmt = LegalizeOp(Amt); |
| 5079 | MVT::ValueType ShTy = ShAmt.getValueType(); |
Dan Gohman | 91dc17b | 2008-02-20 16:57:27 +0000 | [diff] [blame] | 5080 | unsigned ShBits = MVT::getSizeInBits(ShTy); |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5081 | unsigned VTBits = MVT::getSizeInBits(Op.getValueType()); |
| 5082 | unsigned NVTBits = MVT::getSizeInBits(NVT); |
| 5083 | |
Chris Lattner | 7a3c855 | 2007-10-14 20:35:12 +0000 | [diff] [blame] | 5084 | // Handle the case when Amt is an immediate. |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5085 | if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Amt.Val)) { |
| 5086 | unsigned Cst = CN->getValue(); |
| 5087 | // Expand the incoming operand to be shifted, so that we have its parts |
| 5088 | SDOperand InL, InH; |
| 5089 | ExpandOp(Op, InL, InH); |
| 5090 | switch(Opc) { |
| 5091 | case ISD::SHL: |
| 5092 | if (Cst > VTBits) { |
| 5093 | Lo = DAG.getConstant(0, NVT); |
| 5094 | Hi = DAG.getConstant(0, NVT); |
| 5095 | } else if (Cst > NVTBits) { |
| 5096 | Lo = DAG.getConstant(0, NVT); |
| 5097 | Hi = DAG.getNode(ISD::SHL, NVT, InL, DAG.getConstant(Cst-NVTBits,ShTy)); |
Chris Lattner | ee27f57 | 2005-04-11 20:08:52 +0000 | [diff] [blame] | 5098 | } else if (Cst == NVTBits) { |
| 5099 | Lo = DAG.getConstant(0, NVT); |
| 5100 | Hi = InL; |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5101 | } else { |
| 5102 | Lo = DAG.getNode(ISD::SHL, NVT, InL, DAG.getConstant(Cst, ShTy)); |
| 5103 | Hi = DAG.getNode(ISD::OR, NVT, |
| 5104 | DAG.getNode(ISD::SHL, NVT, InH, DAG.getConstant(Cst, ShTy)), |
| 5105 | DAG.getNode(ISD::SRL, NVT, InL, DAG.getConstant(NVTBits-Cst, ShTy))); |
| 5106 | } |
| 5107 | return true; |
| 5108 | case ISD::SRL: |
| 5109 | if (Cst > VTBits) { |
| 5110 | Lo = DAG.getConstant(0, NVT); |
| 5111 | Hi = DAG.getConstant(0, NVT); |
| 5112 | } else if (Cst > NVTBits) { |
| 5113 | Lo = DAG.getNode(ISD::SRL, NVT, InH, DAG.getConstant(Cst-NVTBits,ShTy)); |
| 5114 | Hi = DAG.getConstant(0, NVT); |
Chris Lattner | ee27f57 | 2005-04-11 20:08:52 +0000 | [diff] [blame] | 5115 | } else if (Cst == NVTBits) { |
| 5116 | Lo = InH; |
| 5117 | Hi = DAG.getConstant(0, NVT); |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5118 | } else { |
| 5119 | Lo = DAG.getNode(ISD::OR, NVT, |
| 5120 | DAG.getNode(ISD::SRL, NVT, InL, DAG.getConstant(Cst, ShTy)), |
| 5121 | DAG.getNode(ISD::SHL, NVT, InH, DAG.getConstant(NVTBits-Cst, ShTy))); |
| 5122 | Hi = DAG.getNode(ISD::SRL, NVT, InH, DAG.getConstant(Cst, ShTy)); |
| 5123 | } |
| 5124 | return true; |
| 5125 | case ISD::SRA: |
| 5126 | if (Cst > VTBits) { |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 5127 | Hi = Lo = DAG.getNode(ISD::SRA, NVT, InH, |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5128 | DAG.getConstant(NVTBits-1, ShTy)); |
| 5129 | } else if (Cst > NVTBits) { |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 5130 | Lo = DAG.getNode(ISD::SRA, NVT, InH, |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5131 | DAG.getConstant(Cst-NVTBits, ShTy)); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 5132 | Hi = DAG.getNode(ISD::SRA, NVT, InH, |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5133 | DAG.getConstant(NVTBits-1, ShTy)); |
Chris Lattner | ee27f57 | 2005-04-11 20:08:52 +0000 | [diff] [blame] | 5134 | } else if (Cst == NVTBits) { |
| 5135 | Lo = InH; |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 5136 | Hi = DAG.getNode(ISD::SRA, NVT, InH, |
Chris Lattner | ee27f57 | 2005-04-11 20:08:52 +0000 | [diff] [blame] | 5137 | DAG.getConstant(NVTBits-1, ShTy)); |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5138 | } else { |
| 5139 | Lo = DAG.getNode(ISD::OR, NVT, |
| 5140 | DAG.getNode(ISD::SRL, NVT, InL, DAG.getConstant(Cst, ShTy)), |
| 5141 | DAG.getNode(ISD::SHL, NVT, InH, DAG.getConstant(NVTBits-Cst, ShTy))); |
| 5142 | Hi = DAG.getNode(ISD::SRA, NVT, InH, DAG.getConstant(Cst, ShTy)); |
| 5143 | } |
| 5144 | return true; |
| 5145 | } |
| 5146 | } |
Chris Lattner | 0ea26ca | 2006-09-20 03:38:48 +0000 | [diff] [blame] | 5147 | |
| 5148 | // Okay, the shift amount isn't constant. However, if we can tell that it is |
| 5149 | // >= 32 or < 32, we can still simplify it, without knowing the actual value. |
Dan Gohman | 91dc17b | 2008-02-20 16:57:27 +0000 | [diff] [blame] | 5150 | APInt Mask = APInt::getHighBitsSet(ShBits, ShBits - Log2_32(NVTBits)); |
| 5151 | APInt KnownZero, KnownOne; |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 5152 | DAG.ComputeMaskedBits(Amt, Mask, KnownZero, KnownOne); |
Chris Lattner | 0ea26ca | 2006-09-20 03:38:48 +0000 | [diff] [blame] | 5153 | |
Dan Gohman | 9e255b7 | 2008-02-22 01:12:31 +0000 | [diff] [blame] | 5154 | // If we know that if any of the high bits of the shift amount are one, then |
| 5155 | // we can do this as a couple of simple shifts. |
Dan Gohman | 91dc17b | 2008-02-20 16:57:27 +0000 | [diff] [blame] | 5156 | if (KnownOne.intersects(Mask)) { |
Chris Lattner | 0ea26ca | 2006-09-20 03:38:48 +0000 | [diff] [blame] | 5157 | // Mask out the high bit, which we know is set. |
| 5158 | Amt = DAG.getNode(ISD::AND, Amt.getValueType(), Amt, |
Dan Gohman | 91dc17b | 2008-02-20 16:57:27 +0000 | [diff] [blame] | 5159 | DAG.getConstant(~Mask, Amt.getValueType())); |
Chris Lattner | 0ea26ca | 2006-09-20 03:38:48 +0000 | [diff] [blame] | 5160 | |
| 5161 | // Expand the incoming operand to be shifted, so that we have its parts |
| 5162 | SDOperand InL, InH; |
| 5163 | ExpandOp(Op, InL, InH); |
| 5164 | switch(Opc) { |
| 5165 | case ISD::SHL: |
| 5166 | Lo = DAG.getConstant(0, NVT); // Low part is zero. |
| 5167 | Hi = DAG.getNode(ISD::SHL, NVT, InL, Amt); // High part from Lo part. |
| 5168 | return true; |
| 5169 | case ISD::SRL: |
| 5170 | Hi = DAG.getConstant(0, NVT); // Hi part is zero. |
| 5171 | Lo = DAG.getNode(ISD::SRL, NVT, InH, Amt); // Lo part from Hi part. |
| 5172 | return true; |
| 5173 | case ISD::SRA: |
| 5174 | Hi = DAG.getNode(ISD::SRA, NVT, InH, // Sign extend high part. |
| 5175 | DAG.getConstant(NVTBits-1, Amt.getValueType())); |
| 5176 | Lo = DAG.getNode(ISD::SRA, NVT, InH, Amt); // Lo part from Hi part. |
| 5177 | return true; |
| 5178 | } |
| 5179 | } |
| 5180 | |
Dan Gohman | 9e255b7 | 2008-02-22 01:12:31 +0000 | [diff] [blame] | 5181 | // If we know that the high bits of the shift amount are all zero, then we can |
| 5182 | // do this as a couple of simple shifts. |
| 5183 | if ((KnownZero & Mask) == Mask) { |
Chris Lattner | 0ea26ca | 2006-09-20 03:38:48 +0000 | [diff] [blame] | 5184 | // Compute 32-amt. |
| 5185 | SDOperand Amt2 = DAG.getNode(ISD::SUB, Amt.getValueType(), |
| 5186 | DAG.getConstant(NVTBits, Amt.getValueType()), |
| 5187 | Amt); |
| 5188 | |
| 5189 | // Expand the incoming operand to be shifted, so that we have its parts |
| 5190 | SDOperand InL, InH; |
| 5191 | ExpandOp(Op, InL, InH); |
| 5192 | switch(Opc) { |
| 5193 | case ISD::SHL: |
| 5194 | Lo = DAG.getNode(ISD::SHL, NVT, InL, Amt); |
| 5195 | Hi = DAG.getNode(ISD::OR, NVT, |
| 5196 | DAG.getNode(ISD::SHL, NVT, InH, Amt), |
| 5197 | DAG.getNode(ISD::SRL, NVT, InL, Amt2)); |
| 5198 | return true; |
| 5199 | case ISD::SRL: |
| 5200 | Hi = DAG.getNode(ISD::SRL, NVT, InH, Amt); |
| 5201 | Lo = DAG.getNode(ISD::OR, NVT, |
| 5202 | DAG.getNode(ISD::SRL, NVT, InL, Amt), |
| 5203 | DAG.getNode(ISD::SHL, NVT, InH, Amt2)); |
| 5204 | return true; |
| 5205 | case ISD::SRA: |
| 5206 | Hi = DAG.getNode(ISD::SRA, NVT, InH, Amt); |
| 5207 | Lo = DAG.getNode(ISD::OR, NVT, |
| 5208 | DAG.getNode(ISD::SRL, NVT, InL, Amt), |
| 5209 | DAG.getNode(ISD::SHL, NVT, InH, Amt2)); |
| 5210 | return true; |
| 5211 | } |
| 5212 | } |
| 5213 | |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5214 | return false; |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5215 | } |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5216 | |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 5217 | |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5218 | // ExpandLibCall - Expand a node into a call to a libcall. If the result value |
| 5219 | // does not fit into a register, return the lo part and set the hi part to the |
| 5220 | // by-reg argument. If it does fit into a single register, return the result |
| 5221 | // and leave the Hi part unset. |
| 5222 | SDOperand SelectionDAGLegalize::ExpandLibCall(const char *Name, SDNode *Node, |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 5223 | bool isSigned, SDOperand &Hi) { |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 5224 | assert(!IsLegalizingCall && "Cannot overlap legalization of calls!"); |
| 5225 | // The input chain to this libcall is the entry node of the function. |
| 5226 | // Legalizing the call will automatically add the previous call to the |
| 5227 | // dependence. |
| 5228 | SDOperand InChain = DAG.getEntryNode(); |
| 5229 | |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5230 | TargetLowering::ArgListTy Args; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 5231 | TargetLowering::ArgListEntry Entry; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5232 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) { |
| 5233 | MVT::ValueType ArgVT = Node->getOperand(i).getValueType(); |
| 5234 | const Type *ArgTy = MVT::getTypeForValueType(ArgVT); |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 5235 | Entry.Node = Node->getOperand(i); Entry.Ty = ArgTy; |
Anton Korobeynikov | d0b82b3 | 2007-03-07 16:25:09 +0000 | [diff] [blame] | 5236 | Entry.isSExt = isSigned; |
Duncan Sands | 00fee65 | 2008-02-14 17:28:50 +0000 | [diff] [blame] | 5237 | Entry.isZExt = !isSigned; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 5238 | Args.push_back(Entry); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5239 | } |
| 5240 | SDOperand Callee = DAG.getExternalSymbol(Name, TLI.getPointerTy()); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 5241 | |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 5242 | // Splice the libcall in wherever FindInputOutputChains tells us to. |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5243 | const Type *RetTy = MVT::getTypeForValueType(Node->getValueType(0)); |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 5244 | std::pair<SDOperand,SDOperand> CallInfo = |
Duncan Sands | 00fee65 | 2008-02-14 17:28:50 +0000 | [diff] [blame] | 5245 | TLI.LowerCallTo(InChain, RetTy, isSigned, !isSigned, false, CallingConv::C, |
| 5246 | false, Callee, Args, DAG); |
Chris Lattner | b9fa3bc | 2005-05-12 04:49:08 +0000 | [diff] [blame] | 5247 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 5248 | // Legalize the call sequence, starting with the chain. This will advance |
| 5249 | // the LastCALLSEQ_END to the legalized version of the CALLSEQ_END node that |
| 5250 | // was added by LowerCallTo (guaranteeing proper serialization of calls). |
| 5251 | LegalizeOp(CallInfo.second); |
Chris Lattner | 99c25b8 | 2005-09-02 20:26:58 +0000 | [diff] [blame] | 5252 | SDOperand Result; |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 5253 | switch (getTypeAction(CallInfo.first.getValueType())) { |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5254 | default: assert(0 && "Unknown thing"); |
| 5255 | case Legal: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 5256 | Result = CallInfo.first; |
Chris Lattner | 99c25b8 | 2005-09-02 20:26:58 +0000 | [diff] [blame] | 5257 | break; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5258 | case Expand: |
Chris Lattner | 99c25b8 | 2005-09-02 20:26:58 +0000 | [diff] [blame] | 5259 | ExpandOp(CallInfo.first, Result, Hi); |
Chris Lattner | 99c25b8 | 2005-09-02 20:26:58 +0000 | [diff] [blame] | 5260 | break; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5261 | } |
Chris Lattner | 99c25b8 | 2005-09-02 20:26:58 +0000 | [diff] [blame] | 5262 | return Result; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5263 | } |
| 5264 | |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 5265 | |
Evan Cheng | 4c6cfad | 2007-04-27 07:33:31 +0000 | [diff] [blame] | 5266 | /// ExpandIntToFP - Expand a [US]INT_TO_FP operation. |
| 5267 | /// |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5268 | SDOperand SelectionDAGLegalize:: |
| 5269 | ExpandIntToFP(bool isSigned, MVT::ValueType DestTy, SDOperand Source) { |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5270 | assert(getTypeAction(Source.getValueType()) == Expand && |
| 5271 | "This is not an expansion!"); |
| 5272 | assert(Source.getValueType() == MVT::i64 && "Only handle expand from i64!"); |
| 5273 | |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 5274 | if (!isSigned) { |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 5275 | assert(Source.getValueType() == MVT::i64 && |
| 5276 | "This only works for 64-bit -> FP"); |
| 5277 | // The 64-bit value loaded will be incorrectly if the 'sign bit' of the |
| 5278 | // incoming integer is set. To handle this, we dynamically test to see if |
| 5279 | // it is set, and, if so, add a fudge factor. |
| 5280 | SDOperand Lo, Hi; |
| 5281 | ExpandOp(Source, Lo, Hi); |
| 5282 | |
Chris Lattner | 66de05b | 2005-05-13 04:45:13 +0000 | [diff] [blame] | 5283 | // If this is unsigned, and not supported, first perform the conversion to |
| 5284 | // signed, then adjust the result if the sign bit is set. |
| 5285 | SDOperand SignedConv = ExpandIntToFP(true, DestTy, |
| 5286 | DAG.getNode(ISD::BUILD_PAIR, Source.getValueType(), Lo, Hi)); |
| 5287 | |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 5288 | SDOperand SignSet = DAG.getSetCC(TLI.getSetCCResultTy(), Hi, |
| 5289 | DAG.getConstant(0, Hi.getValueType()), |
| 5290 | ISD::SETLT); |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 5291 | SDOperand Zero = DAG.getIntPtrConstant(0), Four = DAG.getIntPtrConstant(4); |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 5292 | SDOperand CstOffset = DAG.getNode(ISD::SELECT, Zero.getValueType(), |
| 5293 | SignSet, Four, Zero); |
Chris Lattner | 383203b | 2005-05-12 18:52:34 +0000 | [diff] [blame] | 5294 | uint64_t FF = 0x5f800000ULL; |
| 5295 | if (TLI.isLittleEndian()) FF <<= 32; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 5296 | static Constant *FudgeFactor = ConstantInt::get(Type::Int64Ty, FF); |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 5297 | |
Chris Lattner | 5839bf2 | 2005-08-26 17:15:30 +0000 | [diff] [blame] | 5298 | SDOperand CPIdx = DAG.getConstantPool(FudgeFactor, TLI.getPointerTy()); |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 5299 | CPIdx = DAG.getNode(ISD::ADD, TLI.getPointerTy(), CPIdx, CstOffset); |
| 5300 | SDOperand FudgeInReg; |
| 5301 | if (DestTy == MVT::f32) |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5302 | FudgeInReg = DAG.getLoad(MVT::f32, DAG.getEntryNode(), CPIdx, |
Dan Gohman | 3069b87 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 5303 | PseudoSourceValue::getConstantPool(), 0); |
Dale Johannesen | 118cd9d | 2007-09-16 16:51:49 +0000 | [diff] [blame] | 5304 | else if (MVT::getSizeInBits(DestTy) > MVT::getSizeInBits(MVT::f32)) |
Evan Cheng | 4c6cfad | 2007-04-27 07:33:31 +0000 | [diff] [blame] | 5305 | // FIXME: Avoid the extend by construction the right constantpool? |
Dale Johannesen | 118cd9d | 2007-09-16 16:51:49 +0000 | [diff] [blame] | 5306 | FudgeInReg = DAG.getExtLoad(ISD::EXTLOAD, DestTy, DAG.getEntryNode(), |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5307 | CPIdx, |
Dan Gohman | 3069b87 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 5308 | PseudoSourceValue::getConstantPool(), 0, |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5309 | MVT::f32); |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 5310 | else |
| 5311 | assert(0 && "Unexpected conversion"); |
| 5312 | |
Evan Cheng | 4c6cfad | 2007-04-27 07:33:31 +0000 | [diff] [blame] | 5313 | MVT::ValueType SCVT = SignedConv.getValueType(); |
| 5314 | if (SCVT != DestTy) { |
| 5315 | // Destination type needs to be expanded as well. The FADD now we are |
| 5316 | // constructing will be expanded into a libcall. |
| 5317 | if (MVT::getSizeInBits(SCVT) != MVT::getSizeInBits(DestTy)) { |
| 5318 | assert(SCVT == MVT::i32 && DestTy == MVT::f64); |
| 5319 | SignedConv = DAG.getNode(ISD::BUILD_PAIR, MVT::i64, |
| 5320 | SignedConv, SignedConv.getValue(1)); |
| 5321 | } |
| 5322 | SignedConv = DAG.getNode(ISD::BIT_CONVERT, DestTy, SignedConv); |
| 5323 | } |
Chris Lattner | 473a990 | 2005-09-29 06:44:39 +0000 | [diff] [blame] | 5324 | return DAG.getNode(ISD::FADD, DestTy, SignedConv, FudgeInReg); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5325 | } |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 5326 | |
Chris Lattner | a88a260 | 2005-05-14 05:33:54 +0000 | [diff] [blame] | 5327 | // Check to see if the target has a custom way to lower this. If so, use it. |
| 5328 | switch (TLI.getOperationAction(ISD::SINT_TO_FP, Source.getValueType())) { |
| 5329 | default: assert(0 && "This action not implemented for this operation!"); |
| 5330 | case TargetLowering::Legal: |
| 5331 | case TargetLowering::Expand: |
| 5332 | break; // This case is handled below. |
Chris Lattner | 07dffd6 | 2005-08-26 00:14:16 +0000 | [diff] [blame] | 5333 | case TargetLowering::Custom: { |
| 5334 | SDOperand NV = TLI.LowerOperation(DAG.getNode(ISD::SINT_TO_FP, DestTy, |
| 5335 | Source), DAG); |
| 5336 | if (NV.Val) |
| 5337 | return LegalizeOp(NV); |
| 5338 | break; // The target decided this was legal after all |
| 5339 | } |
Chris Lattner | a88a260 | 2005-05-14 05:33:54 +0000 | [diff] [blame] | 5340 | } |
| 5341 | |
Chris Lattner | 13689e2 | 2005-05-12 07:00:44 +0000 | [diff] [blame] | 5342 | // Expand the source, then glue it back together for the call. We must expand |
| 5343 | // the source in case it is shared (this pass of legalize must traverse it). |
| 5344 | SDOperand SrcLo, SrcHi; |
| 5345 | ExpandOp(Source, SrcLo, SrcHi); |
| 5346 | Source = DAG.getNode(ISD::BUILD_PAIR, Source.getValueType(), SrcLo, SrcHi); |
| 5347 | |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5348 | RTLIB::Libcall LC; |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 5349 | if (DestTy == MVT::f32) |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5350 | LC = RTLIB::SINTTOFP_I64_F32; |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 5351 | else { |
| 5352 | assert(DestTy == MVT::f64 && "Unknown fp value type!"); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5353 | LC = RTLIB::SINTTOFP_I64_F64; |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 5354 | } |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 5355 | |
Evan Cheng | 4c6cfad | 2007-04-27 07:33:31 +0000 | [diff] [blame] | 5356 | 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] | 5357 | Source = DAG.getNode(ISD::SINT_TO_FP, DestTy, Source); |
| 5358 | SDOperand UnusedHiPart; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5359 | return ExpandLibCall(TLI.getLibcallName(LC), Source.Val, isSigned, |
| 5360 | UnusedHiPart); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5361 | } |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 5362 | |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5363 | /// ExpandLegalINT_TO_FP - This function is responsible for legalizing a |
| 5364 | /// INT_TO_FP operation of the specified operand when the target requests that |
| 5365 | /// we expand it. At this point, we know that the result and operand types are |
| 5366 | /// legal for the target. |
| 5367 | SDOperand SelectionDAGLegalize::ExpandLegalINT_TO_FP(bool isSigned, |
| 5368 | SDOperand Op0, |
| 5369 | MVT::ValueType DestVT) { |
| 5370 | if (Op0.getValueType() == MVT::i32) { |
| 5371 | // simple 32-bit [signed|unsigned] integer to float/double expansion |
| 5372 | |
Chris Lattner | 23594d4 | 2008-01-16 07:03:22 +0000 | [diff] [blame] | 5373 | // Get the stack frame index of a 8 byte buffer. |
| 5374 | SDOperand StackSlot = DAG.CreateStackTemporary(MVT::f64); |
| 5375 | |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5376 | // word offset constant for Hi/Lo address computation |
| 5377 | SDOperand WordOff = DAG.getConstant(sizeof(int), TLI.getPointerTy()); |
| 5378 | // set up Hi and Lo (into buffer) address based on endian |
Chris Lattner | 408c428 | 2006-03-23 05:29:04 +0000 | [diff] [blame] | 5379 | SDOperand Hi = StackSlot; |
| 5380 | SDOperand Lo = DAG.getNode(ISD::ADD, TLI.getPointerTy(), StackSlot,WordOff); |
| 5381 | if (TLI.isLittleEndian()) |
| 5382 | std::swap(Hi, Lo); |
| 5383 | |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5384 | // if signed map to unsigned space |
| 5385 | SDOperand Op0Mapped; |
| 5386 | if (isSigned) { |
| 5387 | // constant used to invert sign bit (signed to unsigned mapping) |
| 5388 | SDOperand SignBit = DAG.getConstant(0x80000000u, MVT::i32); |
| 5389 | Op0Mapped = DAG.getNode(ISD::XOR, MVT::i32, Op0, SignBit); |
| 5390 | } else { |
| 5391 | Op0Mapped = Op0; |
| 5392 | } |
| 5393 | // store the lo of the constructed double - based on integer input |
Evan Cheng | 786225a | 2006-10-05 23:01:46 +0000 | [diff] [blame] | 5394 | SDOperand Store1 = DAG.getStore(DAG.getEntryNode(), |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 5395 | Op0Mapped, Lo, NULL, 0); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5396 | // initial hi portion of constructed double |
| 5397 | SDOperand InitialHi = DAG.getConstant(0x43300000u, MVT::i32); |
| 5398 | // store the hi of the constructed double - biased exponent |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 5399 | SDOperand Store2=DAG.getStore(Store1, InitialHi, Hi, NULL, 0); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5400 | // load the constructed double |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 5401 | SDOperand Load = DAG.getLoad(MVT::f64, Store2, StackSlot, NULL, 0); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5402 | // FP constant to bias correct the final result |
| 5403 | SDOperand Bias = DAG.getConstantFP(isSigned ? |
| 5404 | BitsToDouble(0x4330000080000000ULL) |
| 5405 | : BitsToDouble(0x4330000000000000ULL), |
| 5406 | MVT::f64); |
| 5407 | // subtract the bias |
| 5408 | SDOperand Sub = DAG.getNode(ISD::FSUB, MVT::f64, Load, Bias); |
| 5409 | // final result |
| 5410 | SDOperand Result; |
| 5411 | // handle final rounding |
| 5412 | if (DestVT == MVT::f64) { |
| 5413 | // do nothing |
| 5414 | Result = Sub; |
Dale Johannesen | 118cd9d | 2007-09-16 16:51:49 +0000 | [diff] [blame] | 5415 | } else if (MVT::getSizeInBits(DestVT) < MVT::getSizeInBits(MVT::f64)) { |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 5416 | Result = DAG.getNode(ISD::FP_ROUND, DestVT, Sub, |
| 5417 | DAG.getIntPtrConstant(0)); |
Dale Johannesen | 118cd9d | 2007-09-16 16:51:49 +0000 | [diff] [blame] | 5418 | } else if (MVT::getSizeInBits(DestVT) > MVT::getSizeInBits(MVT::f64)) { |
| 5419 | Result = DAG.getNode(ISD::FP_EXTEND, DestVT, Sub); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5420 | } |
| 5421 | return Result; |
| 5422 | } |
| 5423 | assert(!isSigned && "Legalize cannot Expand SINT_TO_FP for i64 yet"); |
| 5424 | SDOperand Tmp1 = DAG.getNode(ISD::SINT_TO_FP, DestVT, Op0); |
| 5425 | |
| 5426 | SDOperand SignSet = DAG.getSetCC(TLI.getSetCCResultTy(), Op0, |
| 5427 | DAG.getConstant(0, Op0.getValueType()), |
| 5428 | ISD::SETLT); |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 5429 | SDOperand Zero = DAG.getIntPtrConstant(0), Four = DAG.getIntPtrConstant(4); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5430 | SDOperand CstOffset = DAG.getNode(ISD::SELECT, Zero.getValueType(), |
| 5431 | SignSet, Four, Zero); |
| 5432 | |
| 5433 | // If the sign bit of the integer is set, the large number will be treated |
| 5434 | // as a negative number. To counteract this, the dynamic code adds an |
| 5435 | // offset depending on the data type. |
| 5436 | uint64_t FF; |
| 5437 | switch (Op0.getValueType()) { |
| 5438 | default: assert(0 && "Unsupported integer type!"); |
| 5439 | case MVT::i8 : FF = 0x43800000ULL; break; // 2^8 (as a float) |
| 5440 | case MVT::i16: FF = 0x47800000ULL; break; // 2^16 (as a float) |
| 5441 | case MVT::i32: FF = 0x4F800000ULL; break; // 2^32 (as a float) |
| 5442 | case MVT::i64: FF = 0x5F800000ULL; break; // 2^64 (as a float) |
| 5443 | } |
| 5444 | if (TLI.isLittleEndian()) FF <<= 32; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 5445 | static Constant *FudgeFactor = ConstantInt::get(Type::Int64Ty, FF); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5446 | |
| 5447 | SDOperand CPIdx = DAG.getConstantPool(FudgeFactor, TLI.getPointerTy()); |
| 5448 | CPIdx = DAG.getNode(ISD::ADD, TLI.getPointerTy(), CPIdx, CstOffset); |
| 5449 | SDOperand FudgeInReg; |
| 5450 | if (DestVT == MVT::f32) |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5451 | FudgeInReg = DAG.getLoad(MVT::f32, DAG.getEntryNode(), CPIdx, |
Dan Gohman | 3069b87 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 5452 | PseudoSourceValue::getConstantPool(), 0); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5453 | else { |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5454 | FudgeInReg = |
| 5455 | LegalizeOp(DAG.getExtLoad(ISD::EXTLOAD, DestVT, |
| 5456 | DAG.getEntryNode(), CPIdx, |
Dan Gohman | 3069b87 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 5457 | PseudoSourceValue::getConstantPool(), 0, |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5458 | MVT::f32)); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5459 | } |
| 5460 | |
| 5461 | return DAG.getNode(ISD::FADD, DestVT, Tmp1, FudgeInReg); |
| 5462 | } |
| 5463 | |
| 5464 | /// PromoteLegalINT_TO_FP - This function is responsible for legalizing a |
| 5465 | /// *INT_TO_FP operation of the specified operand when the target requests that |
| 5466 | /// we promote it. At this point, we know that the result and operand types are |
| 5467 | /// legal for the target, and that there is a legal UINT_TO_FP or SINT_TO_FP |
| 5468 | /// operation that takes a larger input. |
| 5469 | SDOperand SelectionDAGLegalize::PromoteLegalINT_TO_FP(SDOperand LegalOp, |
| 5470 | MVT::ValueType DestVT, |
| 5471 | bool isSigned) { |
| 5472 | // First step, figure out the appropriate *INT_TO_FP operation to use. |
| 5473 | MVT::ValueType NewInTy = LegalOp.getValueType(); |
| 5474 | |
| 5475 | unsigned OpToUse = 0; |
| 5476 | |
| 5477 | // Scan for the appropriate larger type to use. |
| 5478 | while (1) { |
| 5479 | NewInTy = (MVT::ValueType)(NewInTy+1); |
| 5480 | assert(MVT::isInteger(NewInTy) && "Ran out of possibilities!"); |
| 5481 | |
| 5482 | // If the target supports SINT_TO_FP of this type, use it. |
| 5483 | switch (TLI.getOperationAction(ISD::SINT_TO_FP, NewInTy)) { |
| 5484 | default: break; |
| 5485 | case TargetLowering::Legal: |
| 5486 | if (!TLI.isTypeLegal(NewInTy)) |
| 5487 | break; // Can't use this datatype. |
| 5488 | // FALL THROUGH. |
| 5489 | case TargetLowering::Custom: |
| 5490 | OpToUse = ISD::SINT_TO_FP; |
| 5491 | break; |
| 5492 | } |
| 5493 | if (OpToUse) break; |
| 5494 | if (isSigned) continue; |
| 5495 | |
| 5496 | // If the target supports UINT_TO_FP of this type, use it. |
| 5497 | switch (TLI.getOperationAction(ISD::UINT_TO_FP, NewInTy)) { |
| 5498 | default: break; |
| 5499 | case TargetLowering::Legal: |
| 5500 | if (!TLI.isTypeLegal(NewInTy)) |
| 5501 | break; // Can't use this datatype. |
| 5502 | // FALL THROUGH. |
| 5503 | case TargetLowering::Custom: |
| 5504 | OpToUse = ISD::UINT_TO_FP; |
| 5505 | break; |
| 5506 | } |
| 5507 | if (OpToUse) break; |
| 5508 | |
| 5509 | // Otherwise, try a larger type. |
| 5510 | } |
| 5511 | |
| 5512 | // Okay, we found the operation and type to use. Zero extend our input to the |
| 5513 | // desired type then run the operation on it. |
| 5514 | return DAG.getNode(OpToUse, DestVT, |
| 5515 | DAG.getNode(isSigned ? ISD::SIGN_EXTEND : ISD::ZERO_EXTEND, |
| 5516 | NewInTy, LegalOp)); |
| 5517 | } |
| 5518 | |
| 5519 | /// PromoteLegalFP_TO_INT - This function is responsible for legalizing a |
| 5520 | /// FP_TO_*INT operation of the specified operand when the target requests that |
| 5521 | /// we promote it. At this point, we know that the result and operand types are |
| 5522 | /// legal for the target, and that there is a legal FP_TO_UINT or FP_TO_SINT |
| 5523 | /// operation that returns a larger result. |
| 5524 | SDOperand SelectionDAGLegalize::PromoteLegalFP_TO_INT(SDOperand LegalOp, |
| 5525 | MVT::ValueType DestVT, |
| 5526 | bool isSigned) { |
| 5527 | // First step, figure out the appropriate FP_TO*INT operation to use. |
| 5528 | MVT::ValueType NewOutTy = DestVT; |
| 5529 | |
| 5530 | unsigned OpToUse = 0; |
| 5531 | |
| 5532 | // Scan for the appropriate larger type to use. |
| 5533 | while (1) { |
| 5534 | NewOutTy = (MVT::ValueType)(NewOutTy+1); |
| 5535 | assert(MVT::isInteger(NewOutTy) && "Ran out of possibilities!"); |
| 5536 | |
| 5537 | // If the target supports FP_TO_SINT returning this type, use it. |
| 5538 | switch (TLI.getOperationAction(ISD::FP_TO_SINT, NewOutTy)) { |
| 5539 | default: break; |
| 5540 | case TargetLowering::Legal: |
| 5541 | if (!TLI.isTypeLegal(NewOutTy)) |
| 5542 | break; // Can't use this datatype. |
| 5543 | // FALL THROUGH. |
| 5544 | case TargetLowering::Custom: |
| 5545 | OpToUse = ISD::FP_TO_SINT; |
| 5546 | break; |
| 5547 | } |
| 5548 | if (OpToUse) break; |
| 5549 | |
| 5550 | // If the target supports FP_TO_UINT of this type, use it. |
| 5551 | switch (TLI.getOperationAction(ISD::FP_TO_UINT, NewOutTy)) { |
| 5552 | default: break; |
| 5553 | case TargetLowering::Legal: |
| 5554 | if (!TLI.isTypeLegal(NewOutTy)) |
| 5555 | break; // Can't use this datatype. |
| 5556 | // FALL THROUGH. |
| 5557 | case TargetLowering::Custom: |
| 5558 | OpToUse = ISD::FP_TO_UINT; |
| 5559 | break; |
| 5560 | } |
| 5561 | if (OpToUse) break; |
| 5562 | |
| 5563 | // Otherwise, try a larger type. |
| 5564 | } |
| 5565 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 5566 | |
| 5567 | // Okay, we found the operation and type to use. |
| 5568 | SDOperand Operation = DAG.getNode(OpToUse, NewOutTy, LegalOp); |
| 5569 | |
| 5570 | // If the operation produces an invalid type, it must be custom lowered. Use |
| 5571 | // the target lowering hooks to expand it. Just keep the low part of the |
| 5572 | // expanded operation, we know that we're truncating anyway. |
| 5573 | if (getTypeAction(NewOutTy) == Expand) { |
| 5574 | Operation = SDOperand(TLI.ExpandOperationResult(Operation.Val, DAG), 0); |
| 5575 | assert(Operation.Val && "Didn't return anything"); |
| 5576 | } |
| 5577 | |
| 5578 | // Truncate the result of the extended FP_TO_*INT operation to the desired |
| 5579 | // size. |
| 5580 | return DAG.getNode(ISD::TRUNCATE, DestVT, Operation); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5581 | } |
| 5582 | |
| 5583 | /// ExpandBSWAP - Open code the operations for BSWAP of the specified operation. |
| 5584 | /// |
| 5585 | SDOperand SelectionDAGLegalize::ExpandBSWAP(SDOperand Op) { |
| 5586 | MVT::ValueType VT = Op.getValueType(); |
| 5587 | MVT::ValueType SHVT = TLI.getShiftAmountTy(); |
| 5588 | SDOperand Tmp1, Tmp2, Tmp3, Tmp4, Tmp5, Tmp6, Tmp7, Tmp8; |
| 5589 | switch (VT) { |
| 5590 | default: assert(0 && "Unhandled Expand type in BSWAP!"); abort(); |
| 5591 | case MVT::i16: |
| 5592 | Tmp2 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(8, SHVT)); |
| 5593 | Tmp1 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(8, SHVT)); |
| 5594 | return DAG.getNode(ISD::OR, VT, Tmp1, Tmp2); |
| 5595 | case MVT::i32: |
| 5596 | Tmp4 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(24, SHVT)); |
| 5597 | Tmp3 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(8, SHVT)); |
| 5598 | Tmp2 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(8, SHVT)); |
| 5599 | Tmp1 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(24, SHVT)); |
| 5600 | Tmp3 = DAG.getNode(ISD::AND, VT, Tmp3, DAG.getConstant(0xFF0000, VT)); |
| 5601 | Tmp2 = DAG.getNode(ISD::AND, VT, Tmp2, DAG.getConstant(0xFF00, VT)); |
| 5602 | Tmp4 = DAG.getNode(ISD::OR, VT, Tmp4, Tmp3); |
| 5603 | Tmp2 = DAG.getNode(ISD::OR, VT, Tmp2, Tmp1); |
| 5604 | return DAG.getNode(ISD::OR, VT, Tmp4, Tmp2); |
| 5605 | case MVT::i64: |
| 5606 | Tmp8 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(56, SHVT)); |
| 5607 | Tmp7 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(40, SHVT)); |
| 5608 | Tmp6 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(24, SHVT)); |
| 5609 | Tmp5 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(8, SHVT)); |
| 5610 | Tmp4 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(8, SHVT)); |
| 5611 | Tmp3 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(24, SHVT)); |
| 5612 | Tmp2 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(40, SHVT)); |
| 5613 | Tmp1 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(56, SHVT)); |
| 5614 | Tmp7 = DAG.getNode(ISD::AND, VT, Tmp7, DAG.getConstant(255ULL<<48, VT)); |
| 5615 | Tmp6 = DAG.getNode(ISD::AND, VT, Tmp6, DAG.getConstant(255ULL<<40, VT)); |
| 5616 | Tmp5 = DAG.getNode(ISD::AND, VT, Tmp5, DAG.getConstant(255ULL<<32, VT)); |
| 5617 | Tmp4 = DAG.getNode(ISD::AND, VT, Tmp4, DAG.getConstant(255ULL<<24, VT)); |
| 5618 | Tmp3 = DAG.getNode(ISD::AND, VT, Tmp3, DAG.getConstant(255ULL<<16, VT)); |
| 5619 | Tmp2 = DAG.getNode(ISD::AND, VT, Tmp2, DAG.getConstant(255ULL<<8 , VT)); |
| 5620 | Tmp8 = DAG.getNode(ISD::OR, VT, Tmp8, Tmp7); |
| 5621 | Tmp6 = DAG.getNode(ISD::OR, VT, Tmp6, Tmp5); |
| 5622 | Tmp4 = DAG.getNode(ISD::OR, VT, Tmp4, Tmp3); |
| 5623 | Tmp2 = DAG.getNode(ISD::OR, VT, Tmp2, Tmp1); |
| 5624 | Tmp8 = DAG.getNode(ISD::OR, VT, Tmp8, Tmp6); |
| 5625 | Tmp4 = DAG.getNode(ISD::OR, VT, Tmp4, Tmp2); |
| 5626 | return DAG.getNode(ISD::OR, VT, Tmp8, Tmp4); |
| 5627 | } |
| 5628 | } |
| 5629 | |
| 5630 | /// ExpandBitCount - Expand the specified bitcount instruction into operations. |
| 5631 | /// |
| 5632 | SDOperand SelectionDAGLegalize::ExpandBitCount(unsigned Opc, SDOperand Op) { |
| 5633 | switch (Opc) { |
| 5634 | default: assert(0 && "Cannot expand this yet!"); |
| 5635 | case ISD::CTPOP: { |
| 5636 | static const uint64_t mask[6] = { |
| 5637 | 0x5555555555555555ULL, 0x3333333333333333ULL, |
| 5638 | 0x0F0F0F0F0F0F0F0FULL, 0x00FF00FF00FF00FFULL, |
| 5639 | 0x0000FFFF0000FFFFULL, 0x00000000FFFFFFFFULL |
| 5640 | }; |
| 5641 | MVT::ValueType VT = Op.getValueType(); |
| 5642 | MVT::ValueType ShVT = TLI.getShiftAmountTy(); |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 5643 | unsigned len = MVT::getSizeInBits(VT); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5644 | for (unsigned i = 0; (1U << i) <= (len / 2); ++i) { |
| 5645 | //x = (x & mask[i][len/8]) + (x >> (1 << i) & mask[i][len/8]) |
| 5646 | SDOperand Tmp2 = DAG.getConstant(mask[i], VT); |
| 5647 | SDOperand Tmp3 = DAG.getConstant(1ULL << i, ShVT); |
| 5648 | Op = DAG.getNode(ISD::ADD, VT, DAG.getNode(ISD::AND, VT, Op, Tmp2), |
| 5649 | DAG.getNode(ISD::AND, VT, |
| 5650 | DAG.getNode(ISD::SRL, VT, Op, Tmp3),Tmp2)); |
| 5651 | } |
| 5652 | return Op; |
| 5653 | } |
| 5654 | case ISD::CTLZ: { |
| 5655 | // for now, we do this: |
| 5656 | // x = x | (x >> 1); |
| 5657 | // x = x | (x >> 2); |
| 5658 | // ... |
| 5659 | // x = x | (x >>16); |
| 5660 | // x = x | (x >>32); // for 64-bit input |
| 5661 | // return popcount(~x); |
| 5662 | // |
| 5663 | // but see also: http://www.hackersdelight.org/HDcode/nlz.cc |
| 5664 | MVT::ValueType VT = Op.getValueType(); |
| 5665 | MVT::ValueType ShVT = TLI.getShiftAmountTy(); |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 5666 | unsigned len = MVT::getSizeInBits(VT); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5667 | for (unsigned i = 0; (1U << i) <= (len / 2); ++i) { |
| 5668 | SDOperand Tmp3 = DAG.getConstant(1ULL << i, ShVT); |
| 5669 | Op = DAG.getNode(ISD::OR, VT, Op, DAG.getNode(ISD::SRL, VT, Op, Tmp3)); |
| 5670 | } |
| 5671 | Op = DAG.getNode(ISD::XOR, VT, Op, DAG.getConstant(~0ULL, VT)); |
| 5672 | return DAG.getNode(ISD::CTPOP, VT, Op); |
| 5673 | } |
| 5674 | case ISD::CTTZ: { |
| 5675 | // for now, we use: { return popcount(~x & (x - 1)); } |
| 5676 | // unless the target has ctlz but not ctpop, in which case we use: |
| 5677 | // { return 32 - nlz(~x & (x-1)); } |
| 5678 | // see also http://www.hackersdelight.org/HDcode/ntz.cc |
| 5679 | MVT::ValueType VT = Op.getValueType(); |
| 5680 | SDOperand Tmp2 = DAG.getConstant(~0ULL, VT); |
| 5681 | SDOperand Tmp3 = DAG.getNode(ISD::AND, VT, |
| 5682 | DAG.getNode(ISD::XOR, VT, Op, Tmp2), |
| 5683 | DAG.getNode(ISD::SUB, VT, Op, DAG.getConstant(1, VT))); |
| 5684 | // If ISD::CTLZ is legal and CTPOP isn't, then do that instead. |
| 5685 | if (!TLI.isOperationLegal(ISD::CTPOP, VT) && |
| 5686 | TLI.isOperationLegal(ISD::CTLZ, VT)) |
| 5687 | return DAG.getNode(ISD::SUB, VT, |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 5688 | DAG.getConstant(MVT::getSizeInBits(VT), VT), |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5689 | DAG.getNode(ISD::CTLZ, VT, Tmp3)); |
| 5690 | return DAG.getNode(ISD::CTPOP, VT, Tmp3); |
| 5691 | } |
| 5692 | } |
| 5693 | } |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5694 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5695 | /// ExpandOp - Expand the specified SDOperand into its two component pieces |
| 5696 | /// Lo&Hi. Note that the Op MUST be an expanded type. As a result of this, the |
| 5697 | /// LegalizeNodes map is filled in for any results that are not expanded, the |
| 5698 | /// ExpandedNodes map is filled in for any results that are expanded, and the |
| 5699 | /// Lo/Hi values are returned. |
| 5700 | void SelectionDAGLegalize::ExpandOp(SDOperand Op, SDOperand &Lo, SDOperand &Hi){ |
| 5701 | MVT::ValueType VT = Op.getValueType(); |
Chris Lattner | 71c42a0 | 2005-01-16 01:11:45 +0000 | [diff] [blame] | 5702 | MVT::ValueType NVT = TLI.getTypeToTransformTo(VT); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5703 | SDNode *Node = Op.Val; |
| 5704 | assert(getTypeAction(VT) == Expand && "Not an expanded type!"); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 5705 | assert(((MVT::isInteger(NVT) && NVT < VT) || MVT::isFloatingPoint(VT) || |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5706 | MVT::isVector(VT)) && |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5707 | "Cannot expand to FP value or to larger int value!"); |
| 5708 | |
Chris Lattner | 6fdcb25 | 2005-09-02 20:32:45 +0000 | [diff] [blame] | 5709 | // See if we already expanded it. |
Chris Lattner | 40030bf | 2007-02-04 01:17:38 +0000 | [diff] [blame] | 5710 | DenseMap<SDOperand, std::pair<SDOperand, SDOperand> >::iterator I |
Chris Lattner | 6fdcb25 | 2005-09-02 20:32:45 +0000 | [diff] [blame] | 5711 | = ExpandedNodes.find(Op); |
| 5712 | if (I != ExpandedNodes.end()) { |
| 5713 | Lo = I->second.first; |
| 5714 | Hi = I->second.second; |
| 5715 | return; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5716 | } |
| 5717 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5718 | switch (Node->getOpcode()) { |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 5719 | case ISD::CopyFromReg: |
| 5720 | assert(0 && "CopyFromReg must be legal!"); |
Dale Johannesen | 6eaeff2 | 2007-10-10 01:01:31 +0000 | [diff] [blame] | 5721 | case ISD::FP_ROUND_INREG: |
| 5722 | if (VT == MVT::ppcf128 && |
| 5723 | TLI.getOperationAction(ISD::FP_ROUND_INREG, VT) == |
| 5724 | TargetLowering::Custom) { |
Dale Johannesen | fcf4d24 | 2007-10-11 23:32:15 +0000 | [diff] [blame] | 5725 | SDOperand SrcLo, SrcHi, Src; |
| 5726 | ExpandOp(Op.getOperand(0), SrcLo, SrcHi); |
| 5727 | Src = DAG.getNode(ISD::BUILD_PAIR, VT, SrcLo, SrcHi); |
| 5728 | SDOperand Result = TLI.LowerOperation( |
| 5729 | DAG.getNode(ISD::FP_ROUND_INREG, VT, Src, Op.getOperand(1)), DAG); |
Dale Johannesen | 6eaeff2 | 2007-10-10 01:01:31 +0000 | [diff] [blame] | 5730 | assert(Result.Val->getOpcode() == ISD::BUILD_PAIR); |
| 5731 | Lo = Result.Val->getOperand(0); |
| 5732 | Hi = Result.Val->getOperand(1); |
| 5733 | break; |
| 5734 | } |
| 5735 | // fall through |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 5736 | default: |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 5737 | #ifndef NDEBUG |
Dan Gohman | 3983358 | 2007-06-04 16:17:33 +0000 | [diff] [blame] | 5738 | cerr << "NODE: "; Node->dump(&DAG); cerr << "\n"; |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 5739 | #endif |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5740 | assert(0 && "Do not know how to expand this operator!"); |
| 5741 | abort(); |
Dan Gohman | 1953ecb | 2008-02-27 01:52:30 +0000 | [diff] [blame^] | 5742 | case ISD::EXTRACT_ELEMENT: |
| 5743 | ExpandOp(Node->getOperand(0), Lo, Hi); |
| 5744 | if (cast<ConstantSDNode>(Node->getOperand(1))->getValue()) |
| 5745 | return ExpandOp(Hi, Lo, Hi); |
| 5746 | else |
| 5747 | return ExpandOp(Lo, Lo, Hi); |
Dale Johannesen | 25f1d08 | 2007-10-31 00:32:36 +0000 | [diff] [blame] | 5748 | case ISD::EXTRACT_VECTOR_ELT: |
| 5749 | assert(VT==MVT::i64 && "Do not know how to expand this operator!"); |
| 5750 | // ExpandEXTRACT_VECTOR_ELT tolerates invalid result types. |
| 5751 | Lo = ExpandEXTRACT_VECTOR_ELT(Op); |
| 5752 | return ExpandOp(Lo, Lo, Hi); |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 5753 | case ISD::UNDEF: |
Evan Cheng | aa975c1 | 2006-12-16 02:20:50 +0000 | [diff] [blame] | 5754 | NVT = TLI.getTypeToExpandTo(VT); |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 5755 | Lo = DAG.getNode(ISD::UNDEF, NVT); |
| 5756 | Hi = DAG.getNode(ISD::UNDEF, NVT); |
| 5757 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5758 | case ISD::Constant: { |
| 5759 | uint64_t Cst = cast<ConstantSDNode>(Node)->getValue(); |
| 5760 | Lo = DAG.getConstant(Cst, NVT); |
| 5761 | Hi = DAG.getConstant(Cst >> MVT::getSizeInBits(NVT), NVT); |
| 5762 | break; |
| 5763 | } |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 5764 | case ISD::ConstantFP: { |
| 5765 | ConstantFPSDNode *CFP = cast<ConstantFPSDNode>(Node); |
Dale Johannesen | a471c2e | 2007-10-11 18:07:22 +0000 | [diff] [blame] | 5766 | if (CFP->getValueType(0) == MVT::ppcf128) { |
| 5767 | APInt api = CFP->getValueAPF().convertToAPInt(); |
| 5768 | Lo = DAG.getConstantFP(APFloat(APInt(64, 1, &api.getRawData()[1])), |
| 5769 | MVT::f64); |
| 5770 | Hi = DAG.getConstantFP(APFloat(APInt(64, 1, &api.getRawData()[0])), |
| 5771 | MVT::f64); |
| 5772 | break; |
| 5773 | } |
Evan Cheng | 279101e | 2006-12-12 22:19:28 +0000 | [diff] [blame] | 5774 | Lo = ExpandConstantFP(CFP, false, DAG, TLI); |
Evan Cheng | 9f87788 | 2006-12-13 20:57:08 +0000 | [diff] [blame] | 5775 | if (getTypeAction(Lo.getValueType()) == Expand) |
| 5776 | ExpandOp(Lo, Lo, Hi); |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 5777 | break; |
| 5778 | } |
Chris Lattner | d4e50bb | 2005-03-28 22:03:13 +0000 | [diff] [blame] | 5779 | case ISD::BUILD_PAIR: |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5780 | // Return the operands. |
| 5781 | Lo = Node->getOperand(0); |
| 5782 | Hi = Node->getOperand(1); |
Chris Lattner | d4e50bb | 2005-03-28 22:03:13 +0000 | [diff] [blame] | 5783 | break; |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 5784 | |
| 5785 | case ISD::MERGE_VALUES: |
Chris Lattner | c58d558 | 2007-11-24 19:12:15 +0000 | [diff] [blame] | 5786 | if (Node->getNumValues() == 1) { |
| 5787 | ExpandOp(Op.getOperand(0), Lo, Hi); |
| 5788 | break; |
| 5789 | } |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 5790 | // FIXME: For now only expand i64,chain = MERGE_VALUES (x, y) |
| 5791 | assert(Op.ResNo == 0 && Node->getNumValues() == 2 && |
| 5792 | Op.getValue(1).getValueType() == MVT::Other && |
| 5793 | "unhandled MERGE_VALUES"); |
| 5794 | ExpandOp(Op.getOperand(0), Lo, Hi); |
| 5795 | // Remember that we legalized the chain. |
| 5796 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Op.getOperand(1))); |
| 5797 | break; |
Chris Lattner | 58f7963 | 2005-12-12 22:27:43 +0000 | [diff] [blame] | 5798 | |
| 5799 | case ISD::SIGN_EXTEND_INREG: |
| 5800 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Chris Lattner | 4bdd275 | 2006-10-06 17:34:12 +0000 | [diff] [blame] | 5801 | // sext_inreg the low part if needed. |
| 5802 | Lo = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Lo, Node->getOperand(1)); |
| 5803 | |
| 5804 | // The high part gets the sign extension from the lo-part. This handles |
| 5805 | // things like sextinreg V:i64 from i8. |
Chris Lattner | 58f7963 | 2005-12-12 22:27:43 +0000 | [diff] [blame] | 5806 | Hi = DAG.getNode(ISD::SRA, NVT, Lo, |
| 5807 | DAG.getConstant(MVT::getSizeInBits(NVT)-1, |
| 5808 | TLI.getShiftAmountTy())); |
Chris Lattner | 58f7963 | 2005-12-12 22:27:43 +0000 | [diff] [blame] | 5809 | break; |
Chris Lattner | d4e50bb | 2005-03-28 22:03:13 +0000 | [diff] [blame] | 5810 | |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 5811 | case ISD::BSWAP: { |
| 5812 | ExpandOp(Node->getOperand(0), Lo, Hi); |
| 5813 | SDOperand TempLo = DAG.getNode(ISD::BSWAP, NVT, Hi); |
| 5814 | Hi = DAG.getNode(ISD::BSWAP, NVT, Lo); |
| 5815 | Lo = TempLo; |
| 5816 | break; |
| 5817 | } |
| 5818 | |
Chris Lattner | edb1add | 2005-05-11 04:51:16 +0000 | [diff] [blame] | 5819 | case ISD::CTPOP: |
| 5820 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Chris Lattner | 9b583b4 | 2005-05-11 05:09:47 +0000 | [diff] [blame] | 5821 | Lo = DAG.getNode(ISD::ADD, NVT, // ctpop(HL) -> ctpop(H)+ctpop(L) |
| 5822 | DAG.getNode(ISD::CTPOP, NVT, Lo), |
| 5823 | DAG.getNode(ISD::CTPOP, NVT, Hi)); |
Chris Lattner | edb1add | 2005-05-11 04:51:16 +0000 | [diff] [blame] | 5824 | Hi = DAG.getConstant(0, NVT); |
| 5825 | break; |
| 5826 | |
Chris Lattner | 39a8f33 | 2005-05-12 19:05:01 +0000 | [diff] [blame] | 5827 | case ISD::CTLZ: { |
| 5828 | // ctlz (HL) -> ctlz(H) != 32 ? ctlz(H) : (ctlz(L)+32) |
Chris Lattner | 3becf20 | 2005-05-12 19:27:51 +0000 | [diff] [blame] | 5829 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Chris Lattner | 39a8f33 | 2005-05-12 19:05:01 +0000 | [diff] [blame] | 5830 | SDOperand BitsC = DAG.getConstant(MVT::getSizeInBits(NVT), NVT); |
| 5831 | SDOperand HLZ = DAG.getNode(ISD::CTLZ, NVT, Hi); |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 5832 | SDOperand TopNotZero = DAG.getSetCC(TLI.getSetCCResultTy(), HLZ, BitsC, |
| 5833 | ISD::SETNE); |
Chris Lattner | 39a8f33 | 2005-05-12 19:05:01 +0000 | [diff] [blame] | 5834 | SDOperand LowPart = DAG.getNode(ISD::CTLZ, NVT, Lo); |
| 5835 | LowPart = DAG.getNode(ISD::ADD, NVT, LowPart, BitsC); |
| 5836 | |
| 5837 | Lo = DAG.getNode(ISD::SELECT, NVT, TopNotZero, HLZ, LowPart); |
| 5838 | Hi = DAG.getConstant(0, NVT); |
| 5839 | break; |
| 5840 | } |
| 5841 | |
| 5842 | case ISD::CTTZ: { |
| 5843 | // cttz (HL) -> cttz(L) != 32 ? cttz(L) : (cttz(H)+32) |
Chris Lattner | 3becf20 | 2005-05-12 19:27:51 +0000 | [diff] [blame] | 5844 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Chris Lattner | 39a8f33 | 2005-05-12 19:05:01 +0000 | [diff] [blame] | 5845 | SDOperand BitsC = DAG.getConstant(MVT::getSizeInBits(NVT), NVT); |
| 5846 | SDOperand LTZ = DAG.getNode(ISD::CTTZ, NVT, Lo); |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 5847 | SDOperand BotNotZero = DAG.getSetCC(TLI.getSetCCResultTy(), LTZ, BitsC, |
| 5848 | ISD::SETNE); |
Chris Lattner | 39a8f33 | 2005-05-12 19:05:01 +0000 | [diff] [blame] | 5849 | SDOperand HiPart = DAG.getNode(ISD::CTTZ, NVT, Hi); |
| 5850 | HiPart = DAG.getNode(ISD::ADD, NVT, HiPart, BitsC); |
| 5851 | |
| 5852 | Lo = DAG.getNode(ISD::SELECT, NVT, BotNotZero, LTZ, HiPart); |
| 5853 | Hi = DAG.getConstant(0, NVT); |
| 5854 | break; |
| 5855 | } |
Chris Lattner | edb1add | 2005-05-11 04:51:16 +0000 | [diff] [blame] | 5856 | |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 5857 | case ISD::VAARG: { |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5858 | SDOperand Ch = Node->getOperand(0); // Legalize the chain. |
| 5859 | SDOperand Ptr = Node->getOperand(1); // Legalize the pointer. |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 5860 | Lo = DAG.getVAArg(NVT, Ch, Ptr, Node->getOperand(2)); |
| 5861 | Hi = DAG.getVAArg(NVT, Lo.getValue(1), Ptr, Node->getOperand(2)); |
| 5862 | |
| 5863 | // Remember that we legalized the chain. |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5864 | Hi = LegalizeOp(Hi); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 5865 | AddLegalizedOperand(Op.getValue(1), Hi.getValue(1)); |
Duncan Sands | 0753fc1 | 2008-02-11 10:37:04 +0000 | [diff] [blame] | 5866 | if (TLI.isBigEndian()) |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 5867 | std::swap(Lo, Hi); |
| 5868 | break; |
| 5869 | } |
| 5870 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5871 | case ISD::LOAD: { |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 5872 | LoadSDNode *LD = cast<LoadSDNode>(Node); |
| 5873 | SDOperand Ch = LD->getChain(); // Legalize the chain. |
| 5874 | SDOperand Ptr = LD->getBasePtr(); // Legalize the pointer. |
| 5875 | ISD::LoadExtType ExtType = LD->getExtensionType(); |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 5876 | int SVOffset = LD->getSrcValueOffset(); |
| 5877 | unsigned Alignment = LD->getAlignment(); |
| 5878 | bool isVolatile = LD->isVolatile(); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5879 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 5880 | if (ExtType == ISD::NON_EXTLOAD) { |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 5881 | Lo = DAG.getLoad(NVT, Ch, Ptr, LD->getSrcValue(), SVOffset, |
| 5882 | isVolatile, Alignment); |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 5883 | if (VT == MVT::f32 || VT == MVT::f64) { |
| 5884 | // f32->i32 or f64->i64 one to one expansion. |
| 5885 | // Remember that we legalized the chain. |
| 5886 | AddLegalizedOperand(SDOperand(Node, 1), LegalizeOp(Lo.getValue(1))); |
Evan Cheng | 9f87788 | 2006-12-13 20:57:08 +0000 | [diff] [blame] | 5887 | // Recursively expand the new load. |
| 5888 | if (getTypeAction(NVT) == Expand) |
| 5889 | ExpandOp(Lo, Lo, Hi); |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 5890 | break; |
| 5891 | } |
Chris Lattner | ec39a45 | 2005-01-19 18:02:17 +0000 | [diff] [blame] | 5892 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 5893 | // Increment the pointer to the other half. |
| 5894 | unsigned IncrementSize = MVT::getSizeInBits(Lo.getValueType())/8; |
| 5895 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 5896 | DAG.getIntPtrConstant(IncrementSize)); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5897 | SVOffset += IncrementSize; |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 5898 | Alignment = MinAlign(Alignment, IncrementSize); |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 5899 | Hi = DAG.getLoad(NVT, Ch, Ptr, LD->getSrcValue(), SVOffset, |
| 5900 | isVolatile, Alignment); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 5901 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 5902 | // Build a factor node to remember that this load is independent of the |
| 5903 | // other one. |
| 5904 | SDOperand TF = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1), |
| 5905 | Hi.getValue(1)); |
| 5906 | |
| 5907 | // Remember that we legalized the chain. |
| 5908 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(TF)); |
Duncan Sands | 0753fc1 | 2008-02-11 10:37:04 +0000 | [diff] [blame] | 5909 | if (TLI.isBigEndian()) |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 5910 | std::swap(Lo, Hi); |
| 5911 | } else { |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 5912 | MVT::ValueType EVT = LD->getMemoryVT(); |
Evan Cheng | 548f611 | 2006-12-13 03:19:57 +0000 | [diff] [blame] | 5913 | |
Dale Johannesen | b6210fc | 2007-10-19 20:29:00 +0000 | [diff] [blame] | 5914 | if ((VT == MVT::f64 && EVT == MVT::f32) || |
| 5915 | (VT == MVT::ppcf128 && (EVT==MVT::f64 || EVT==MVT::f32))) { |
Evan Cheng | 548f611 | 2006-12-13 03:19:57 +0000 | [diff] [blame] | 5916 | // f64 = EXTLOAD f32 should expand to LOAD, FP_EXTEND |
| 5917 | SDOperand Load = DAG.getLoad(EVT, Ch, Ptr, LD->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 5918 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 548f611 | 2006-12-13 03:19:57 +0000 | [diff] [blame] | 5919 | // Remember that we legalized the chain. |
| 5920 | AddLegalizedOperand(SDOperand(Node, 1), LegalizeOp(Load.getValue(1))); |
| 5921 | ExpandOp(DAG.getNode(ISD::FP_EXTEND, VT, Load), Lo, Hi); |
| 5922 | break; |
| 5923 | } |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 5924 | |
| 5925 | if (EVT == NVT) |
| 5926 | Lo = DAG.getLoad(NVT, Ch, Ptr, LD->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 5927 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 5928 | else |
| 5929 | Lo = DAG.getExtLoad(ExtType, NVT, Ch, Ptr, LD->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 5930 | SVOffset, EVT, isVolatile, |
| 5931 | Alignment); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 5932 | |
| 5933 | // Remember that we legalized the chain. |
| 5934 | AddLegalizedOperand(SDOperand(Node, 1), LegalizeOp(Lo.getValue(1))); |
| 5935 | |
| 5936 | if (ExtType == ISD::SEXTLOAD) { |
| 5937 | // The high part is obtained by SRA'ing all but one of the bits of the |
| 5938 | // lo part. |
| 5939 | unsigned LoSize = MVT::getSizeInBits(Lo.getValueType()); |
| 5940 | Hi = DAG.getNode(ISD::SRA, NVT, Lo, |
| 5941 | DAG.getConstant(LoSize-1, TLI.getShiftAmountTy())); |
| 5942 | } else if (ExtType == ISD::ZEXTLOAD) { |
| 5943 | // The high part is just a zero. |
| 5944 | Hi = DAG.getConstant(0, NVT); |
| 5945 | } else /* if (ExtType == ISD::EXTLOAD) */ { |
| 5946 | // The high part is undefined. |
| 5947 | Hi = DAG.getNode(ISD::UNDEF, NVT); |
| 5948 | } |
| 5949 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5950 | break; |
| 5951 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5952 | case ISD::AND: |
| 5953 | case ISD::OR: |
| 5954 | case ISD::XOR: { // Simple logical operators -> two trivial pieces. |
| 5955 | SDOperand LL, LH, RL, RH; |
| 5956 | ExpandOp(Node->getOperand(0), LL, LH); |
| 5957 | ExpandOp(Node->getOperand(1), RL, RH); |
| 5958 | Lo = DAG.getNode(Node->getOpcode(), NVT, LL, RL); |
| 5959 | Hi = DAG.getNode(Node->getOpcode(), NVT, LH, RH); |
| 5960 | break; |
| 5961 | } |
| 5962 | case ISD::SELECT: { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 5963 | SDOperand LL, LH, RL, RH; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5964 | ExpandOp(Node->getOperand(1), LL, LH); |
| 5965 | ExpandOp(Node->getOperand(2), RL, RH); |
Evan Cheng | 19103b1 | 2006-12-15 22:42:55 +0000 | [diff] [blame] | 5966 | if (getTypeAction(NVT) == Expand) |
| 5967 | NVT = TLI.getTypeToExpandTo(NVT); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 5968 | Lo = DAG.getNode(ISD::SELECT, NVT, Node->getOperand(0), LL, RL); |
Evan Cheng | 19103b1 | 2006-12-15 22:42:55 +0000 | [diff] [blame] | 5969 | if (VT != MVT::f32) |
| 5970 | Hi = DAG.getNode(ISD::SELECT, NVT, Node->getOperand(0), LH, RH); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5971 | break; |
| 5972 | } |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 5973 | case ISD::SELECT_CC: { |
| 5974 | SDOperand TL, TH, FL, FH; |
| 5975 | ExpandOp(Node->getOperand(2), TL, TH); |
| 5976 | ExpandOp(Node->getOperand(3), FL, FH); |
Evan Cheng | 19103b1 | 2006-12-15 22:42:55 +0000 | [diff] [blame] | 5977 | if (getTypeAction(NVT) == Expand) |
| 5978 | NVT = TLI.getTypeToExpandTo(NVT); |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 5979 | Lo = DAG.getNode(ISD::SELECT_CC, NVT, Node->getOperand(0), |
| 5980 | Node->getOperand(1), TL, FL, Node->getOperand(4)); |
Evan Cheng | 19103b1 | 2006-12-15 22:42:55 +0000 | [diff] [blame] | 5981 | if (VT != MVT::f32) |
| 5982 | Hi = DAG.getNode(ISD::SELECT_CC, NVT, Node->getOperand(0), |
| 5983 | Node->getOperand(1), TH, FH, Node->getOperand(4)); |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 5984 | break; |
| 5985 | } |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5986 | case ISD::ANY_EXTEND: |
| 5987 | // The low part is any extension of the input (which degenerates to a copy). |
| 5988 | Lo = DAG.getNode(ISD::ANY_EXTEND, NVT, Node->getOperand(0)); |
| 5989 | // The high part is undefined. |
| 5990 | Hi = DAG.getNode(ISD::UNDEF, NVT); |
| 5991 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5992 | case ISD::SIGN_EXTEND: { |
| 5993 | // The low part is just a sign extension of the input (which degenerates to |
| 5994 | // a copy). |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5995 | Lo = DAG.getNode(ISD::SIGN_EXTEND, NVT, Node->getOperand(0)); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 5996 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5997 | // The high part is obtained by SRA'ing all but one of the bits of the lo |
| 5998 | // part. |
Chris Lattner | 2dad454 | 2005-01-12 18:19:52 +0000 | [diff] [blame] | 5999 | unsigned LoSize = MVT::getSizeInBits(Lo.getValueType()); |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6000 | Hi = DAG.getNode(ISD::SRA, NVT, Lo, |
| 6001 | DAG.getConstant(LoSize-1, TLI.getShiftAmountTy())); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6002 | break; |
| 6003 | } |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6004 | case ISD::ZERO_EXTEND: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6005 | // The low part is just a zero extension of the input (which degenerates to |
| 6006 | // a copy). |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6007 | Lo = DAG.getNode(ISD::ZERO_EXTEND, NVT, Node->getOperand(0)); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 6008 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6009 | // The high part is just a zero. |
| 6010 | Hi = DAG.getConstant(0, NVT); |
| 6011 | break; |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 6012 | |
Chris Lattner | 4c948eb | 2007-02-13 23:55:16 +0000 | [diff] [blame] | 6013 | case ISD::TRUNCATE: { |
| 6014 | // The input value must be larger than this value. Expand *it*. |
| 6015 | SDOperand NewLo; |
| 6016 | ExpandOp(Node->getOperand(0), NewLo, Hi); |
| 6017 | |
| 6018 | // The low part is now either the right size, or it is closer. If not the |
| 6019 | // right size, make an illegal truncate so we recursively expand it. |
| 6020 | if (NewLo.getValueType() != Node->getValueType(0)) |
| 6021 | NewLo = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0), NewLo); |
| 6022 | ExpandOp(NewLo, Lo, Hi); |
| 6023 | break; |
| 6024 | } |
| 6025 | |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 6026 | case ISD::BIT_CONVERT: { |
Chris Lattner | f3f333d | 2006-09-09 00:20:27 +0000 | [diff] [blame] | 6027 | SDOperand Tmp; |
| 6028 | if (TLI.getOperationAction(ISD::BIT_CONVERT, VT) == TargetLowering::Custom){ |
| 6029 | // If the target wants to, allow it to lower this itself. |
| 6030 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 6031 | case Expand: assert(0 && "cannot expand FP!"); |
| 6032 | case Legal: Tmp = LegalizeOp(Node->getOperand(0)); break; |
| 6033 | case Promote: Tmp = PromoteOp (Node->getOperand(0)); break; |
| 6034 | } |
| 6035 | Tmp = TLI.LowerOperation(DAG.getNode(ISD::BIT_CONVERT, VT, Tmp), DAG); |
| 6036 | } |
| 6037 | |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 6038 | // f32 / f64 must be expanded to i32 / i64. |
Evan Cheng | 13acce3 | 2006-12-11 19:27:14 +0000 | [diff] [blame] | 6039 | if (VT == MVT::f32 || VT == MVT::f64) { |
| 6040 | Lo = DAG.getNode(ISD::BIT_CONVERT, NVT, Node->getOperand(0)); |
Evan Cheng | 19103b1 | 2006-12-15 22:42:55 +0000 | [diff] [blame] | 6041 | if (getTypeAction(NVT) == Expand) |
| 6042 | ExpandOp(Lo, Lo, Hi); |
Evan Cheng | 7b2b5c8 | 2006-12-12 19:53:13 +0000 | [diff] [blame] | 6043 | break; |
| 6044 | } |
| 6045 | |
| 6046 | // If source operand will be expanded to the same type as VT, i.e. |
| 6047 | // i64 <- f64, i32 <- f32, expand the source operand instead. |
| 6048 | MVT::ValueType VT0 = Node->getOperand(0).getValueType(); |
| 6049 | if (getTypeAction(VT0) == Expand && TLI.getTypeToTransformTo(VT0) == VT) { |
| 6050 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 6051 | break; |
| 6052 | } |
| 6053 | |
Chris Lattner | f3f333d | 2006-09-09 00:20:27 +0000 | [diff] [blame] | 6054 | // Turn this into a load/store pair by default. |
| 6055 | if (Tmp.Val == 0) |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 6056 | Tmp = EmitStackConvert(Node->getOperand(0), VT, VT); |
Chris Lattner | f3f333d | 2006-09-09 00:20:27 +0000 | [diff] [blame] | 6057 | |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 6058 | ExpandOp(Tmp, Lo, Hi); |
| 6059 | break; |
| 6060 | } |
Andrew Lenharth | f70e30b | 2005-11-20 21:32:07 +0000 | [diff] [blame] | 6061 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6062 | case ISD::READCYCLECOUNTER: { |
Chris Lattner | 308575b | 2005-11-20 22:56:56 +0000 | [diff] [blame] | 6063 | assert(TLI.getOperationAction(ISD::READCYCLECOUNTER, VT) == |
| 6064 | TargetLowering::Custom && |
| 6065 | "Must custom expand ReadCycleCounter"); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6066 | SDOperand Tmp = TLI.LowerOperation(Op, DAG); |
| 6067 | assert(Tmp.Val && "Node must be custom expanded!"); |
| 6068 | ExpandOp(Tmp.getValue(0), Lo, Hi); |
Chris Lattner | 308575b | 2005-11-20 22:56:56 +0000 | [diff] [blame] | 6069 | AddLegalizedOperand(SDOperand(Node, 1), // Remember we legalized the chain. |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6070 | LegalizeOp(Tmp.getValue(1))); |
Andrew Lenharth | f70e30b | 2005-11-20 21:32:07 +0000 | [diff] [blame] | 6071 | break; |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6072 | } |
Andrew Lenharth | f70e30b | 2005-11-20 21:32:07 +0000 | [diff] [blame] | 6073 | |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 6074 | // These operators cannot be expanded directly, emit them as calls to |
| 6075 | // library functions. |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6076 | case ISD::FP_TO_SINT: { |
Chris Lattner | 80a3e94 | 2005-07-29 00:33:32 +0000 | [diff] [blame] | 6077 | if (TLI.getOperationAction(ISD::FP_TO_SINT, VT) == TargetLowering::Custom) { |
Chris Lattner | f20d183 | 2005-07-30 01:40:57 +0000 | [diff] [blame] | 6078 | SDOperand Op; |
| 6079 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 6080 | case Expand: assert(0 && "cannot expand FP!"); |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6081 | case Legal: Op = LegalizeOp(Node->getOperand(0)); break; |
| 6082 | case Promote: Op = PromoteOp (Node->getOperand(0)); break; |
Chris Lattner | f20d183 | 2005-07-30 01:40:57 +0000 | [diff] [blame] | 6083 | } |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 6084 | |
Chris Lattner | f20d183 | 2005-07-30 01:40:57 +0000 | [diff] [blame] | 6085 | Op = TLI.LowerOperation(DAG.getNode(ISD::FP_TO_SINT, VT, Op), DAG); |
| 6086 | |
Chris Lattner | 80a3e94 | 2005-07-29 00:33:32 +0000 | [diff] [blame] | 6087 | // Now that the custom expander is done, expand the result, which is still |
| 6088 | // VT. |
Chris Lattner | 07dffd6 | 2005-08-26 00:14:16 +0000 | [diff] [blame] | 6089 | if (Op.Val) { |
| 6090 | ExpandOp(Op, Lo, Hi); |
| 6091 | break; |
| 6092 | } |
Chris Lattner | 80a3e94 | 2005-07-29 00:33:32 +0000 | [diff] [blame] | 6093 | } |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 6094 | |
Dale Johannesen | 161e897 | 2007-10-05 20:04:43 +0000 | [diff] [blame] | 6095 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 6096 | if (Node->getOperand(0).getValueType() == MVT::f32) |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6097 | LC = RTLIB::FPTOSINT_F32_I64; |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 6098 | else if (Node->getOperand(0).getValueType() == MVT::f64) |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6099 | LC = RTLIB::FPTOSINT_F64_I64; |
Dale Johannesen | 161e897 | 2007-10-05 20:04:43 +0000 | [diff] [blame] | 6100 | else if (Node->getOperand(0).getValueType() == MVT::f80) |
| 6101 | LC = RTLIB::FPTOSINT_F80_I64; |
| 6102 | else if (Node->getOperand(0).getValueType() == MVT::ppcf128) |
| 6103 | LC = RTLIB::FPTOSINT_PPCF128_I64; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6104 | Lo = ExpandLibCall(TLI.getLibcallName(LC), Node, |
| 6105 | false/*sign irrelevant*/, Hi); |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 6106 | break; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6107 | } |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 6108 | |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6109 | case ISD::FP_TO_UINT: { |
Chris Lattner | 80a3e94 | 2005-07-29 00:33:32 +0000 | [diff] [blame] | 6110 | if (TLI.getOperationAction(ISD::FP_TO_UINT, VT) == TargetLowering::Custom) { |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6111 | SDOperand Op; |
| 6112 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 6113 | case Expand: assert(0 && "cannot expand FP!"); |
| 6114 | case Legal: Op = LegalizeOp(Node->getOperand(0)); break; |
| 6115 | case Promote: Op = PromoteOp (Node->getOperand(0)); break; |
| 6116 | } |
| 6117 | |
| 6118 | Op = TLI.LowerOperation(DAG.getNode(ISD::FP_TO_UINT, VT, Op), DAG); |
| 6119 | |
| 6120 | // Now that the custom expander is done, expand the result. |
Chris Lattner | 07dffd6 | 2005-08-26 00:14:16 +0000 | [diff] [blame] | 6121 | if (Op.Val) { |
| 6122 | ExpandOp(Op, Lo, Hi); |
| 6123 | break; |
| 6124 | } |
Chris Lattner | 80a3e94 | 2005-07-29 00:33:32 +0000 | [diff] [blame] | 6125 | } |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 6126 | |
Evan Cheng | daccea18 | 2007-10-05 01:09:32 +0000 | [diff] [blame] | 6127 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 6128 | if (Node->getOperand(0).getValueType() == MVT::f32) |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6129 | LC = RTLIB::FPTOUINT_F32_I64; |
Dale Johannesen | 72292f0 | 2007-09-28 18:44:17 +0000 | [diff] [blame] | 6130 | else if (Node->getOperand(0).getValueType() == MVT::f64) |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6131 | LC = RTLIB::FPTOUINT_F64_I64; |
Dale Johannesen | 161e897 | 2007-10-05 20:04:43 +0000 | [diff] [blame] | 6132 | else if (Node->getOperand(0).getValueType() == MVT::f80) |
| 6133 | LC = RTLIB::FPTOUINT_F80_I64; |
| 6134 | else if (Node->getOperand(0).getValueType() == MVT::ppcf128) |
| 6135 | LC = RTLIB::FPTOUINT_PPCF128_I64; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6136 | Lo = ExpandLibCall(TLI.getLibcallName(LC), Node, |
| 6137 | false/*sign irrelevant*/, Hi); |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 6138 | break; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6139 | } |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 6140 | |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 6141 | case ISD::SHL: { |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6142 | // If the target wants custom lowering, do so. |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 6143 | SDOperand ShiftAmt = LegalizeOp(Node->getOperand(1)); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6144 | if (TLI.getOperationAction(ISD::SHL, VT) == TargetLowering::Custom) { |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6145 | SDOperand Op = DAG.getNode(ISD::SHL, VT, Node->getOperand(0), ShiftAmt); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6146 | Op = TLI.LowerOperation(Op, DAG); |
| 6147 | if (Op.Val) { |
| 6148 | // Now that the custom expander is done, expand the result, which is |
| 6149 | // still VT. |
| 6150 | ExpandOp(Op, Lo, Hi); |
| 6151 | break; |
| 6152 | } |
| 6153 | } |
| 6154 | |
Chris Lattner | 79980b0 | 2006-09-13 03:50:39 +0000 | [diff] [blame] | 6155 | // If ADDC/ADDE are supported and if the shift amount is a constant 1, emit |
| 6156 | // this X << 1 as X+X. |
| 6157 | if (ConstantSDNode *ShAmt = dyn_cast<ConstantSDNode>(ShiftAmt)) { |
| 6158 | if (ShAmt->getValue() == 1 && TLI.isOperationLegal(ISD::ADDC, NVT) && |
| 6159 | TLI.isOperationLegal(ISD::ADDE, NVT)) { |
| 6160 | SDOperand LoOps[2], HiOps[3]; |
| 6161 | ExpandOp(Node->getOperand(0), LoOps[0], HiOps[0]); |
| 6162 | SDVTList VTList = DAG.getVTList(LoOps[0].getValueType(), MVT::Flag); |
| 6163 | LoOps[1] = LoOps[0]; |
| 6164 | Lo = DAG.getNode(ISD::ADDC, VTList, LoOps, 2); |
| 6165 | |
| 6166 | HiOps[1] = HiOps[0]; |
| 6167 | HiOps[2] = Lo.getValue(1); |
| 6168 | Hi = DAG.getNode(ISD::ADDE, VTList, HiOps, 3); |
| 6169 | break; |
| 6170 | } |
| 6171 | } |
| 6172 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6173 | // If we can emit an efficient shift operation, do so now. |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 6174 | if (ExpandShift(ISD::SHL, Node->getOperand(0), ShiftAmt, Lo, Hi)) |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6175 | break; |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 6176 | |
| 6177 | // If this target supports SHL_PARTS, use it. |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 6178 | TargetLowering::LegalizeAction Action = |
| 6179 | TLI.getOperationAction(ISD::SHL_PARTS, NVT); |
| 6180 | if ((Action == TargetLowering::Legal && TLI.isTypeLegal(NVT)) || |
| 6181 | Action == TargetLowering::Custom) { |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 6182 | ExpandShiftParts(ISD::SHL_PARTS, Node->getOperand(0), ShiftAmt, Lo, Hi); |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 6183 | break; |
| 6184 | } |
| 6185 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6186 | // Otherwise, emit a libcall. |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6187 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::SHL_I64), Node, |
| 6188 | false/*left shift=unsigned*/, Hi); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6189 | break; |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 6190 | } |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6191 | |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 6192 | case ISD::SRA: { |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6193 | // If the target wants custom lowering, do so. |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 6194 | SDOperand ShiftAmt = LegalizeOp(Node->getOperand(1)); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6195 | if (TLI.getOperationAction(ISD::SRA, VT) == TargetLowering::Custom) { |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6196 | SDOperand Op = DAG.getNode(ISD::SRA, VT, Node->getOperand(0), ShiftAmt); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6197 | Op = TLI.LowerOperation(Op, DAG); |
| 6198 | if (Op.Val) { |
| 6199 | // Now that the custom expander is done, expand the result, which is |
| 6200 | // still VT. |
| 6201 | ExpandOp(Op, Lo, Hi); |
| 6202 | break; |
| 6203 | } |
| 6204 | } |
| 6205 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6206 | // If we can emit an efficient shift operation, do so now. |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 6207 | if (ExpandShift(ISD::SRA, Node->getOperand(0), ShiftAmt, Lo, Hi)) |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6208 | break; |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 6209 | |
| 6210 | // If this target supports SRA_PARTS, use it. |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 6211 | TargetLowering::LegalizeAction Action = |
| 6212 | TLI.getOperationAction(ISD::SRA_PARTS, NVT); |
| 6213 | if ((Action == TargetLowering::Legal && TLI.isTypeLegal(NVT)) || |
| 6214 | Action == TargetLowering::Custom) { |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 6215 | ExpandShiftParts(ISD::SRA_PARTS, Node->getOperand(0), ShiftAmt, Lo, Hi); |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 6216 | break; |
| 6217 | } |
| 6218 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6219 | // Otherwise, emit a libcall. |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6220 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::SRA_I64), Node, |
| 6221 | true/*ashr is signed*/, Hi); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6222 | break; |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 6223 | } |
| 6224 | |
| 6225 | case ISD::SRL: { |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6226 | // If the target wants custom lowering, do so. |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 6227 | SDOperand ShiftAmt = LegalizeOp(Node->getOperand(1)); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6228 | if (TLI.getOperationAction(ISD::SRL, VT) == TargetLowering::Custom) { |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6229 | SDOperand Op = DAG.getNode(ISD::SRL, VT, Node->getOperand(0), ShiftAmt); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6230 | Op = TLI.LowerOperation(Op, DAG); |
| 6231 | if (Op.Val) { |
| 6232 | // Now that the custom expander is done, expand the result, which is |
| 6233 | // still VT. |
| 6234 | ExpandOp(Op, Lo, Hi); |
| 6235 | break; |
| 6236 | } |
| 6237 | } |
| 6238 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6239 | // If we can emit an efficient shift operation, do so now. |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 6240 | if (ExpandShift(ISD::SRL, Node->getOperand(0), ShiftAmt, Lo, Hi)) |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6241 | break; |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 6242 | |
| 6243 | // If this target supports SRL_PARTS, use it. |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 6244 | TargetLowering::LegalizeAction Action = |
| 6245 | TLI.getOperationAction(ISD::SRL_PARTS, NVT); |
| 6246 | if ((Action == TargetLowering::Legal && TLI.isTypeLegal(NVT)) || |
| 6247 | Action == TargetLowering::Custom) { |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 6248 | ExpandShiftParts(ISD::SRL_PARTS, Node->getOperand(0), ShiftAmt, Lo, Hi); |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 6249 | break; |
| 6250 | } |
| 6251 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6252 | // Otherwise, emit a libcall. |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6253 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::SRL_I64), Node, |
| 6254 | false/*lshr is unsigned*/, Hi); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6255 | break; |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 6256 | } |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6257 | |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 6258 | case ISD::ADD: |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6259 | case ISD::SUB: { |
| 6260 | // If the target wants to custom expand this, let them. |
| 6261 | if (TLI.getOperationAction(Node->getOpcode(), VT) == |
| 6262 | TargetLowering::Custom) { |
| 6263 | Op = TLI.LowerOperation(Op, DAG); |
| 6264 | if (Op.Val) { |
| 6265 | ExpandOp(Op, Lo, Hi); |
| 6266 | break; |
| 6267 | } |
| 6268 | } |
| 6269 | |
| 6270 | // Expand the subcomponents. |
| 6271 | SDOperand LHSL, LHSH, RHSL, RHSH; |
| 6272 | ExpandOp(Node->getOperand(0), LHSL, LHSH); |
| 6273 | ExpandOp(Node->getOperand(1), RHSL, RHSH); |
Chris Lattner | 79980b0 | 2006-09-13 03:50:39 +0000 | [diff] [blame] | 6274 | SDVTList VTList = DAG.getVTList(LHSL.getValueType(), MVT::Flag); |
| 6275 | SDOperand LoOps[2], HiOps[3]; |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 6276 | LoOps[0] = LHSL; |
| 6277 | LoOps[1] = RHSL; |
| 6278 | HiOps[0] = LHSH; |
| 6279 | HiOps[1] = RHSH; |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 6280 | if (Node->getOpcode() == ISD::ADD) { |
Chris Lattner | 79980b0 | 2006-09-13 03:50:39 +0000 | [diff] [blame] | 6281 | Lo = DAG.getNode(ISD::ADDC, VTList, LoOps, 2); |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 6282 | HiOps[2] = Lo.getValue(1); |
Chris Lattner | 79980b0 | 2006-09-13 03:50:39 +0000 | [diff] [blame] | 6283 | Hi = DAG.getNode(ISD::ADDE, VTList, HiOps, 3); |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 6284 | } else { |
Chris Lattner | 79980b0 | 2006-09-13 03:50:39 +0000 | [diff] [blame] | 6285 | Lo = DAG.getNode(ISD::SUBC, VTList, LoOps, 2); |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 6286 | HiOps[2] = Lo.getValue(1); |
Chris Lattner | 79980b0 | 2006-09-13 03:50:39 +0000 | [diff] [blame] | 6287 | Hi = DAG.getNode(ISD::SUBE, VTList, HiOps, 3); |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 6288 | } |
Chris Lattner | 84f6788 | 2005-01-20 18:52:28 +0000 | [diff] [blame] | 6289 | break; |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6290 | } |
Chris Lattner | b429f73 | 2007-05-17 18:15:41 +0000 | [diff] [blame] | 6291 | |
| 6292 | case ISD::ADDC: |
| 6293 | case ISD::SUBC: { |
| 6294 | // Expand the subcomponents. |
| 6295 | SDOperand LHSL, LHSH, RHSL, RHSH; |
| 6296 | ExpandOp(Node->getOperand(0), LHSL, LHSH); |
| 6297 | ExpandOp(Node->getOperand(1), RHSL, RHSH); |
| 6298 | SDVTList VTList = DAG.getVTList(LHSL.getValueType(), MVT::Flag); |
| 6299 | SDOperand LoOps[2] = { LHSL, RHSL }; |
| 6300 | SDOperand HiOps[3] = { LHSH, RHSH }; |
| 6301 | |
| 6302 | if (Node->getOpcode() == ISD::ADDC) { |
| 6303 | Lo = DAG.getNode(ISD::ADDC, VTList, LoOps, 2); |
| 6304 | HiOps[2] = Lo.getValue(1); |
| 6305 | Hi = DAG.getNode(ISD::ADDE, VTList, HiOps, 3); |
| 6306 | } else { |
| 6307 | Lo = DAG.getNode(ISD::SUBC, VTList, LoOps, 2); |
| 6308 | HiOps[2] = Lo.getValue(1); |
| 6309 | Hi = DAG.getNode(ISD::SUBE, VTList, HiOps, 3); |
| 6310 | } |
| 6311 | // Remember that we legalized the flag. |
| 6312 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Hi.getValue(1))); |
| 6313 | break; |
| 6314 | } |
| 6315 | case ISD::ADDE: |
| 6316 | case ISD::SUBE: { |
| 6317 | // Expand the subcomponents. |
| 6318 | SDOperand LHSL, LHSH, RHSL, RHSH; |
| 6319 | ExpandOp(Node->getOperand(0), LHSL, LHSH); |
| 6320 | ExpandOp(Node->getOperand(1), RHSL, RHSH); |
| 6321 | SDVTList VTList = DAG.getVTList(LHSL.getValueType(), MVT::Flag); |
| 6322 | SDOperand LoOps[3] = { LHSL, RHSL, Node->getOperand(2) }; |
| 6323 | SDOperand HiOps[3] = { LHSH, RHSH }; |
| 6324 | |
| 6325 | Lo = DAG.getNode(Node->getOpcode(), VTList, LoOps, 3); |
| 6326 | HiOps[2] = Lo.getValue(1); |
| 6327 | Hi = DAG.getNode(Node->getOpcode(), VTList, HiOps, 3); |
| 6328 | |
| 6329 | // Remember that we legalized the flag. |
| 6330 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Hi.getValue(1))); |
| 6331 | break; |
| 6332 | } |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 6333 | case ISD::MUL: { |
Chris Lattner | 7d7bffe | 2006-09-16 00:09:24 +0000 | [diff] [blame] | 6334 | // If the target wants to custom expand this, let them. |
| 6335 | if (TLI.getOperationAction(ISD::MUL, VT) == TargetLowering::Custom) { |
Chris Lattner | 8829dc8 | 2006-09-16 05:08:34 +0000 | [diff] [blame] | 6336 | SDOperand New = TLI.LowerOperation(Op, DAG); |
| 6337 | if (New.Val) { |
| 6338 | ExpandOp(New, Lo, Hi); |
Chris Lattner | 7d7bffe | 2006-09-16 00:09:24 +0000 | [diff] [blame] | 6339 | break; |
| 6340 | } |
| 6341 | } |
| 6342 | |
Evan Cheng | 3f4fd0f | 2006-09-01 18:17:58 +0000 | [diff] [blame] | 6343 | bool HasMULHS = TLI.isOperationLegal(ISD::MULHS, NVT); |
| 6344 | bool HasMULHU = TLI.isOperationLegal(ISD::MULHU, NVT); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 6345 | bool HasSMUL_LOHI = TLI.isOperationLegal(ISD::SMUL_LOHI, NVT); |
| 6346 | bool HasUMUL_LOHI = TLI.isOperationLegal(ISD::UMUL_LOHI, NVT); |
| 6347 | if (HasMULHU || HasMULHS || HasUMUL_LOHI || HasSMUL_LOHI) { |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 6348 | SDOperand LL, LH, RL, RH; |
| 6349 | ExpandOp(Node->getOperand(0), LL, LH); |
| 6350 | ExpandOp(Node->getOperand(1), RL, RH); |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 6351 | unsigned OuterBitSize = Op.getValueSizeInBits(); |
| 6352 | unsigned InnerBitSize = RH.getValueSizeInBits(); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 6353 | unsigned LHSSB = DAG.ComputeNumSignBits(Op.getOperand(0)); |
| 6354 | unsigned RHSSB = DAG.ComputeNumSignBits(Op.getOperand(1)); |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 6355 | if (DAG.MaskedValueIsZero(Op.getOperand(0), |
| 6356 | APInt::getHighBitsSet(OuterBitSize, LHSSB)) && |
| 6357 | DAG.MaskedValueIsZero(Op.getOperand(1), |
| 6358 | APInt::getHighBitsSet(OuterBitSize, RHSSB))) { |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 6359 | // The inputs are both zero-extended. |
| 6360 | if (HasUMUL_LOHI) { |
| 6361 | // We can emit a umul_lohi. |
| 6362 | Lo = DAG.getNode(ISD::UMUL_LOHI, DAG.getVTList(NVT, NVT), LL, RL); |
| 6363 | Hi = SDOperand(Lo.Val, 1); |
| 6364 | break; |
| 6365 | } |
| 6366 | if (HasMULHU) { |
| 6367 | // We can emit a mulhu+mul. |
| 6368 | Lo = DAG.getNode(ISD::MUL, NVT, LL, RL); |
| 6369 | Hi = DAG.getNode(ISD::MULHU, NVT, LL, RL); |
| 6370 | break; |
| 6371 | } |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 6372 | } |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 6373 | if (LHSSB > InnerBitSize && RHSSB > InnerBitSize) { |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 6374 | // The input values are both sign-extended. |
| 6375 | if (HasSMUL_LOHI) { |
| 6376 | // We can emit a smul_lohi. |
| 6377 | Lo = DAG.getNode(ISD::SMUL_LOHI, DAG.getVTList(NVT, NVT), LL, RL); |
| 6378 | Hi = SDOperand(Lo.Val, 1); |
| 6379 | break; |
| 6380 | } |
| 6381 | if (HasMULHS) { |
| 6382 | // We can emit a mulhs+mul. |
| 6383 | Lo = DAG.getNode(ISD::MUL, NVT, LL, RL); |
| 6384 | Hi = DAG.getNode(ISD::MULHS, NVT, LL, RL); |
| 6385 | break; |
| 6386 | } |
| 6387 | } |
| 6388 | if (HasUMUL_LOHI) { |
| 6389 | // Lo,Hi = umul LHS, RHS. |
| 6390 | SDOperand UMulLOHI = DAG.getNode(ISD::UMUL_LOHI, |
| 6391 | DAG.getVTList(NVT, NVT), LL, RL); |
| 6392 | Lo = UMulLOHI; |
| 6393 | Hi = UMulLOHI.getValue(1); |
Nate Begeman | 56eb868 | 2005-08-30 02:44:00 +0000 | [diff] [blame] | 6394 | RH = DAG.getNode(ISD::MUL, NVT, LL, RH); |
| 6395 | LH = DAG.getNode(ISD::MUL, NVT, LH, RL); |
| 6396 | Hi = DAG.getNode(ISD::ADD, NVT, Hi, RH); |
| 6397 | Hi = DAG.getNode(ISD::ADD, NVT, Hi, LH); |
Chris Lattner | a89654b | 2006-09-16 00:21:44 +0000 | [diff] [blame] | 6398 | break; |
Nate Begeman | 56eb868 | 2005-08-30 02:44:00 +0000 | [diff] [blame] | 6399 | } |
Dale Johannesen | 8eadd5a | 2007-10-24 22:26:08 +0000 | [diff] [blame] | 6400 | if (HasMULHU) { |
| 6401 | Lo = DAG.getNode(ISD::MUL, NVT, LL, RL); |
| 6402 | Hi = DAG.getNode(ISD::MULHU, NVT, LL, RL); |
| 6403 | RH = DAG.getNode(ISD::MUL, NVT, LL, RH); |
| 6404 | LH = DAG.getNode(ISD::MUL, NVT, LH, RL); |
| 6405 | Hi = DAG.getNode(ISD::ADD, NVT, Hi, RH); |
| 6406 | Hi = DAG.getNode(ISD::ADD, NVT, Hi, LH); |
| 6407 | break; |
| 6408 | } |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 6409 | } |
Evan Cheng | 3f4fd0f | 2006-09-01 18:17:58 +0000 | [diff] [blame] | 6410 | |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 6411 | // If nothing else, we can make a libcall. |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6412 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::MUL_I64), Node, |
| 6413 | false/*sign irrelevant*/, Hi); |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 6414 | break; |
| 6415 | } |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6416 | case ISD::SDIV: |
| 6417 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::SDIV_I64), Node, true, Hi); |
| 6418 | break; |
| 6419 | case ISD::UDIV: |
| 6420 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::UDIV_I64), Node, true, Hi); |
| 6421 | break; |
| 6422 | case ISD::SREM: |
| 6423 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::SREM_I64), Node, true, Hi); |
| 6424 | break; |
| 6425 | case ISD::UREM: |
| 6426 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::UREM_I64), Node, true, Hi); |
| 6427 | break; |
Evan Cheng | 5c9ce18 | 2006-12-12 21:51:17 +0000 | [diff] [blame] | 6428 | |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 6429 | case ISD::FADD: |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 6430 | Lo = ExpandLibCall(TLI.getLibcallName(GetFPLibCall(VT, RTLIB::ADD_F32, |
| 6431 | RTLIB::ADD_F64, |
| 6432 | RTLIB::ADD_F80, |
| 6433 | RTLIB::ADD_PPCF128)), |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6434 | Node, false, Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 6435 | break; |
| 6436 | case ISD::FSUB: |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 6437 | Lo = ExpandLibCall(TLI.getLibcallName(GetFPLibCall(VT, RTLIB::SUB_F32, |
| 6438 | RTLIB::SUB_F64, |
| 6439 | RTLIB::SUB_F80, |
| 6440 | RTLIB::SUB_PPCF128)), |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6441 | Node, false, Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 6442 | break; |
| 6443 | case ISD::FMUL: |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 6444 | Lo = ExpandLibCall(TLI.getLibcallName(GetFPLibCall(VT, RTLIB::MUL_F32, |
| 6445 | RTLIB::MUL_F64, |
| 6446 | RTLIB::MUL_F80, |
| 6447 | RTLIB::MUL_PPCF128)), |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6448 | Node, false, Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 6449 | break; |
| 6450 | case ISD::FDIV: |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 6451 | Lo = ExpandLibCall(TLI.getLibcallName(GetFPLibCall(VT, RTLIB::DIV_F32, |
| 6452 | RTLIB::DIV_F64, |
| 6453 | RTLIB::DIV_F80, |
| 6454 | RTLIB::DIV_PPCF128)), |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6455 | Node, false, Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 6456 | break; |
| 6457 | case ISD::FP_EXTEND: |
Dale Johannesen | ca68aaa | 2007-10-12 01:37:08 +0000 | [diff] [blame] | 6458 | if (VT == MVT::ppcf128) { |
| 6459 | assert(Node->getOperand(0).getValueType()==MVT::f32 || |
| 6460 | Node->getOperand(0).getValueType()==MVT::f64); |
| 6461 | const uint64_t zero = 0; |
| 6462 | if (Node->getOperand(0).getValueType()==MVT::f32) |
| 6463 | Hi = DAG.getNode(ISD::FP_EXTEND, MVT::f64, Node->getOperand(0)); |
| 6464 | else |
| 6465 | Hi = Node->getOperand(0); |
| 6466 | Lo = DAG.getConstantFP(APFloat(APInt(64, 1, &zero)), MVT::f64); |
| 6467 | break; |
| 6468 | } |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6469 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::FPEXT_F32_F64), Node, true,Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 6470 | break; |
| 6471 | case ISD::FP_ROUND: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6472 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::FPROUND_F64_F32),Node,true,Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 6473 | break; |
Lauro Ramos Venancio | c90f089 | 2007-08-15 22:13:27 +0000 | [diff] [blame] | 6474 | case ISD::FPOWI: |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 6475 | Lo = ExpandLibCall(TLI.getLibcallName(GetFPLibCall(VT, RTLIB::POWI_F32, |
| 6476 | RTLIB::POWI_F64, |
| 6477 | RTLIB::POWI_F80, |
| 6478 | RTLIB::POWI_PPCF128)), |
Lauro Ramos Venancio | c90f089 | 2007-08-15 22:13:27 +0000 | [diff] [blame] | 6479 | Node, false, Hi); |
| 6480 | break; |
Evan Cheng | 98ff3b9 | 2006-12-13 02:38:13 +0000 | [diff] [blame] | 6481 | case ISD::FSQRT: |
| 6482 | case ISD::FSIN: |
| 6483 | case ISD::FCOS: { |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6484 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
Evan Cheng | 98ff3b9 | 2006-12-13 02:38:13 +0000 | [diff] [blame] | 6485 | switch(Node->getOpcode()) { |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6486 | case ISD::FSQRT: |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 6487 | LC = GetFPLibCall(VT, RTLIB::SQRT_F32, RTLIB::SQRT_F64, |
| 6488 | RTLIB::SQRT_F80, RTLIB::SQRT_PPCF128); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6489 | break; |
| 6490 | case ISD::FSIN: |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 6491 | LC = GetFPLibCall(VT, RTLIB::SIN_F32, RTLIB::SIN_F64, |
| 6492 | RTLIB::SIN_F80, RTLIB::SIN_PPCF128); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6493 | break; |
| 6494 | case ISD::FCOS: |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 6495 | LC = GetFPLibCall(VT, RTLIB::COS_F32, RTLIB::COS_F64, |
| 6496 | RTLIB::COS_F80, RTLIB::COS_PPCF128); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6497 | break; |
Evan Cheng | 98ff3b9 | 2006-12-13 02:38:13 +0000 | [diff] [blame] | 6498 | default: assert(0 && "Unreachable!"); |
| 6499 | } |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6500 | Lo = ExpandLibCall(TLI.getLibcallName(LC), Node, false, Hi); |
Evan Cheng | 98ff3b9 | 2006-12-13 02:38:13 +0000 | [diff] [blame] | 6501 | break; |
| 6502 | } |
Evan Cheng | 966bf24 | 2006-12-16 00:52:40 +0000 | [diff] [blame] | 6503 | case ISD::FABS: { |
Dale Johannesen | f646774 | 2007-10-12 19:02:17 +0000 | [diff] [blame] | 6504 | if (VT == MVT::ppcf128) { |
| 6505 | SDOperand Tmp; |
| 6506 | ExpandOp(Node->getOperand(0), Lo, Tmp); |
| 6507 | Hi = DAG.getNode(ISD::FABS, NVT, Tmp); |
| 6508 | // lo = hi==fabs(hi) ? lo : -lo; |
| 6509 | Lo = DAG.getNode(ISD::SELECT_CC, NVT, Hi, Tmp, |
| 6510 | Lo, DAG.getNode(ISD::FNEG, NVT, Lo), |
| 6511 | DAG.getCondCode(ISD::SETEQ)); |
| 6512 | break; |
| 6513 | } |
Evan Cheng | 966bf24 | 2006-12-16 00:52:40 +0000 | [diff] [blame] | 6514 | SDOperand Mask = (VT == MVT::f64) |
| 6515 | ? DAG.getConstantFP(BitsToDouble(~(1ULL << 63)), VT) |
| 6516 | : DAG.getConstantFP(BitsToFloat(~(1U << 31)), VT); |
| 6517 | Mask = DAG.getNode(ISD::BIT_CONVERT, NVT, Mask); |
| 6518 | Lo = DAG.getNode(ISD::BIT_CONVERT, NVT, Node->getOperand(0)); |
| 6519 | Lo = DAG.getNode(ISD::AND, NVT, Lo, Mask); |
| 6520 | if (getTypeAction(NVT) == Expand) |
| 6521 | ExpandOp(Lo, Lo, Hi); |
| 6522 | break; |
| 6523 | } |
| 6524 | case ISD::FNEG: { |
Dale Johannesen | f646774 | 2007-10-12 19:02:17 +0000 | [diff] [blame] | 6525 | if (VT == MVT::ppcf128) { |
| 6526 | ExpandOp(Node->getOperand(0), Lo, Hi); |
| 6527 | Lo = DAG.getNode(ISD::FNEG, MVT::f64, Lo); |
| 6528 | Hi = DAG.getNode(ISD::FNEG, MVT::f64, Hi); |
| 6529 | break; |
| 6530 | } |
Evan Cheng | 966bf24 | 2006-12-16 00:52:40 +0000 | [diff] [blame] | 6531 | SDOperand Mask = (VT == MVT::f64) |
| 6532 | ? DAG.getConstantFP(BitsToDouble(1ULL << 63), VT) |
| 6533 | : DAG.getConstantFP(BitsToFloat(1U << 31), VT); |
| 6534 | Mask = DAG.getNode(ISD::BIT_CONVERT, NVT, Mask); |
| 6535 | Lo = DAG.getNode(ISD::BIT_CONVERT, NVT, Node->getOperand(0)); |
| 6536 | Lo = DAG.getNode(ISD::XOR, NVT, Lo, Mask); |
| 6537 | if (getTypeAction(NVT) == Expand) |
| 6538 | ExpandOp(Lo, Lo, Hi); |
| 6539 | break; |
| 6540 | } |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 6541 | case ISD::FCOPYSIGN: { |
| 6542 | Lo = ExpandFCOPYSIGNToBitwiseOps(Node, NVT, DAG, TLI); |
| 6543 | if (getTypeAction(NVT) == Expand) |
| 6544 | ExpandOp(Lo, Lo, Hi); |
| 6545 | break; |
| 6546 | } |
Evan Cheng | 7df28dc | 2006-12-19 01:44:04 +0000 | [diff] [blame] | 6547 | case ISD::SINT_TO_FP: |
| 6548 | case ISD::UINT_TO_FP: { |
| 6549 | bool isSigned = Node->getOpcode() == ISD::SINT_TO_FP; |
| 6550 | MVT::ValueType SrcVT = Node->getOperand(0).getValueType(); |
Dale Johannesen | 6e63e09 | 2007-10-12 17:52:03 +0000 | [diff] [blame] | 6551 | if (VT == MVT::ppcf128 && SrcVT != MVT::i64) { |
Dan Gohman | f6283fd | 2008-02-25 21:39:34 +0000 | [diff] [blame] | 6552 | static const uint64_t zero = 0; |
Dale Johannesen | ca68aaa | 2007-10-12 01:37:08 +0000 | [diff] [blame] | 6553 | if (isSigned) { |
| 6554 | Hi = LegalizeOp(DAG.getNode(ISD::SINT_TO_FP, MVT::f64, |
| 6555 | Node->getOperand(0))); |
| 6556 | Lo = DAG.getConstantFP(APFloat(APInt(64, 1, &zero)), MVT::f64); |
| 6557 | } else { |
Dan Gohman | f6283fd | 2008-02-25 21:39:34 +0000 | [diff] [blame] | 6558 | static const uint64_t TwoE32[] = { 0x41f0000000000000LL, 0 }; |
Dale Johannesen | ca68aaa | 2007-10-12 01:37:08 +0000 | [diff] [blame] | 6559 | Hi = LegalizeOp(DAG.getNode(ISD::SINT_TO_FP, MVT::f64, |
| 6560 | Node->getOperand(0))); |
| 6561 | Lo = DAG.getConstantFP(APFloat(APInt(64, 1, &zero)), MVT::f64); |
| 6562 | Hi = DAG.getNode(ISD::BUILD_PAIR, VT, Lo, Hi); |
Dale Johannesen | 6e63e09 | 2007-10-12 17:52:03 +0000 | [diff] [blame] | 6563 | // X>=0 ? {(f64)x, 0} : {(f64)x, 0} + 2^32 |
Dale Johannesen | ca68aaa | 2007-10-12 01:37:08 +0000 | [diff] [blame] | 6564 | ExpandOp(DAG.getNode(ISD::SELECT_CC, MVT::ppcf128, Node->getOperand(0), |
| 6565 | DAG.getConstant(0, MVT::i32), |
| 6566 | DAG.getNode(ISD::FADD, MVT::ppcf128, Hi, |
| 6567 | DAG.getConstantFP( |
| 6568 | APFloat(APInt(128, 2, TwoE32)), |
| 6569 | MVT::ppcf128)), |
| 6570 | Hi, |
| 6571 | DAG.getCondCode(ISD::SETLT)), |
| 6572 | Lo, Hi); |
| 6573 | } |
| 6574 | break; |
| 6575 | } |
Dale Johannesen | 6e63e09 | 2007-10-12 17:52:03 +0000 | [diff] [blame] | 6576 | if (VT == MVT::ppcf128 && SrcVT == MVT::i64 && !isSigned) { |
| 6577 | // si64->ppcf128 done by libcall, below |
Dan Gohman | f6283fd | 2008-02-25 21:39:34 +0000 | [diff] [blame] | 6578 | static const uint64_t TwoE64[] = { 0x43f0000000000000LL, 0 }; |
Dale Johannesen | 6e63e09 | 2007-10-12 17:52:03 +0000 | [diff] [blame] | 6579 | ExpandOp(DAG.getNode(ISD::SINT_TO_FP, MVT::ppcf128, Node->getOperand(0)), |
| 6580 | Lo, Hi); |
| 6581 | Hi = DAG.getNode(ISD::BUILD_PAIR, VT, Lo, Hi); |
| 6582 | // x>=0 ? (ppcf128)(i64)x : (ppcf128)(i64)x + 2^64 |
| 6583 | ExpandOp(DAG.getNode(ISD::SELECT_CC, MVT::ppcf128, Node->getOperand(0), |
| 6584 | DAG.getConstant(0, MVT::i64), |
| 6585 | DAG.getNode(ISD::FADD, MVT::ppcf128, Hi, |
| 6586 | DAG.getConstantFP( |
| 6587 | APFloat(APInt(128, 2, TwoE64)), |
| 6588 | MVT::ppcf128)), |
| 6589 | Hi, |
| 6590 | DAG.getCondCode(ISD::SETLT)), |
| 6591 | Lo, Hi); |
| 6592 | break; |
| 6593 | } |
Evan Cheng | 64f638d | 2007-09-27 07:35:39 +0000 | [diff] [blame] | 6594 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
Evan Cheng | 7df28dc | 2006-12-19 01:44:04 +0000 | [diff] [blame] | 6595 | if (Node->getOperand(0).getValueType() == MVT::i64) { |
| 6596 | if (VT == MVT::f32) |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6597 | LC = isSigned ? RTLIB::SINTTOFP_I64_F32 : RTLIB::UINTTOFP_I64_F32; |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 6598 | else if (VT == MVT::f64) |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6599 | LC = isSigned ? RTLIB::SINTTOFP_I64_F64 : RTLIB::UINTTOFP_I64_F64; |
Dale Johannesen | 161e897 | 2007-10-05 20:04:43 +0000 | [diff] [blame] | 6600 | else if (VT == MVT::f80) { |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 6601 | assert(isSigned); |
Dale Johannesen | 161e897 | 2007-10-05 20:04:43 +0000 | [diff] [blame] | 6602 | LC = RTLIB::SINTTOFP_I64_F80; |
| 6603 | } |
| 6604 | else if (VT == MVT::ppcf128) { |
| 6605 | assert(isSigned); |
| 6606 | LC = RTLIB::SINTTOFP_I64_PPCF128; |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 6607 | } |
Evan Cheng | 7df28dc | 2006-12-19 01:44:04 +0000 | [diff] [blame] | 6608 | } else { |
| 6609 | if (VT == MVT::f32) |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6610 | LC = isSigned ? RTLIB::SINTTOFP_I32_F32 : RTLIB::UINTTOFP_I32_F32; |
Evan Cheng | 7df28dc | 2006-12-19 01:44:04 +0000 | [diff] [blame] | 6611 | else |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6612 | LC = isSigned ? RTLIB::SINTTOFP_I32_F64 : RTLIB::UINTTOFP_I32_F64; |
Evan Cheng | 7df28dc | 2006-12-19 01:44:04 +0000 | [diff] [blame] | 6613 | } |
| 6614 | |
| 6615 | // Promote the operand if needed. |
| 6616 | if (getTypeAction(SrcVT) == Promote) { |
| 6617 | SDOperand Tmp = PromoteOp(Node->getOperand(0)); |
| 6618 | Tmp = isSigned |
| 6619 | ? DAG.getNode(ISD::SIGN_EXTEND_INREG, Tmp.getValueType(), Tmp, |
| 6620 | DAG.getValueType(SrcVT)) |
| 6621 | : DAG.getZeroExtendInReg(Tmp, SrcVT); |
| 6622 | Node = DAG.UpdateNodeOperands(Op, Tmp).Val; |
| 6623 | } |
Evan Cheng | 4c6cfad | 2007-04-27 07:33:31 +0000 | [diff] [blame] | 6624 | |
| 6625 | const char *LibCall = TLI.getLibcallName(LC); |
| 6626 | if (LibCall) |
| 6627 | Lo = ExpandLibCall(TLI.getLibcallName(LC), Node, isSigned, Hi); |
| 6628 | else { |
| 6629 | Lo = ExpandIntToFP(Node->getOpcode() == ISD::SINT_TO_FP, VT, |
| 6630 | Node->getOperand(0)); |
| 6631 | if (getTypeAction(Lo.getValueType()) == Expand) |
| 6632 | ExpandOp(Lo, Lo, Hi); |
| 6633 | } |
Evan Cheng | 7df28dc | 2006-12-19 01:44:04 +0000 | [diff] [blame] | 6634 | break; |
| 6635 | } |
Evan Cheng | 98ff3b9 | 2006-12-13 02:38:13 +0000 | [diff] [blame] | 6636 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6637 | |
Chris Lattner | 8339736 | 2005-12-21 18:02:52 +0000 | [diff] [blame] | 6638 | // Make sure the resultant values have been legalized themselves, unless this |
| 6639 | // is a type that requires multi-step expansion. |
| 6640 | if (getTypeAction(NVT) != Expand && NVT != MVT::isVoid) { |
| 6641 | Lo = LegalizeOp(Lo); |
Evan Cheng | 13acce3 | 2006-12-11 19:27:14 +0000 | [diff] [blame] | 6642 | if (Hi.Val) |
| 6643 | // Don't legalize the high part if it is expanded to a single node. |
| 6644 | Hi = LegalizeOp(Hi); |
Chris Lattner | 8339736 | 2005-12-21 18:02:52 +0000 | [diff] [blame] | 6645 | } |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 6646 | |
| 6647 | // Remember in a map if the values will be reused later. |
Chris Lattner | 40030bf | 2007-02-04 01:17:38 +0000 | [diff] [blame] | 6648 | 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] | 6649 | assert(isNew && "Value already expanded?!?"); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6650 | } |
| 6651 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6652 | /// SplitVectorOp - Given an operand of vector type, break it down into |
| 6653 | /// two smaller values, still of vector type. |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6654 | void SelectionDAGLegalize::SplitVectorOp(SDOperand Op, SDOperand &Lo, |
| 6655 | SDOperand &Hi) { |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6656 | assert(MVT::isVector(Op.getValueType()) && "Cannot split non-vector type!"); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6657 | SDNode *Node = Op.Val; |
Dan Gohman | e40c7b0 | 2007-09-24 15:54:53 +0000 | [diff] [blame] | 6658 | unsigned NumElements = MVT::getVectorNumElements(Op.getValueType()); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6659 | assert(NumElements > 1 && "Cannot split a single element vector!"); |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 6660 | |
Dan Gohman | e40c7b0 | 2007-09-24 15:54:53 +0000 | [diff] [blame] | 6661 | MVT::ValueType NewEltVT = MVT::getVectorElementType(Op.getValueType()); |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 6662 | |
| 6663 | unsigned NewNumElts_Lo = 1 << Log2_32(NumElements-1); |
| 6664 | unsigned NewNumElts_Hi = NumElements - NewNumElts_Lo; |
| 6665 | |
| 6666 | MVT::ValueType NewVT_Lo = MVT::getVectorType(NewEltVT, NewNumElts_Lo); |
| 6667 | MVT::ValueType NewVT_Hi = MVT::getVectorType(NewEltVT, NewNumElts_Hi); |
| 6668 | |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6669 | // See if we already split it. |
| 6670 | std::map<SDOperand, std::pair<SDOperand, SDOperand> >::iterator I |
| 6671 | = SplitNodes.find(Op); |
| 6672 | if (I != SplitNodes.end()) { |
| 6673 | Lo = I->second.first; |
| 6674 | Hi = I->second.second; |
| 6675 | return; |
| 6676 | } |
| 6677 | |
| 6678 | switch (Node->getOpcode()) { |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 6679 | default: |
| 6680 | #ifndef NDEBUG |
Dan Gohman | 3983358 | 2007-06-04 16:17:33 +0000 | [diff] [blame] | 6681 | Node->dump(&DAG); |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 6682 | #endif |
| 6683 | assert(0 && "Unhandled operation in SplitVectorOp!"); |
Chris Lattner | daf9bc8 | 2007-11-19 20:21:32 +0000 | [diff] [blame] | 6684 | case ISD::UNDEF: |
| 6685 | Lo = DAG.getNode(ISD::UNDEF, NewVT_Lo); |
| 6686 | Hi = DAG.getNode(ISD::UNDEF, NewVT_Hi); |
| 6687 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6688 | case ISD::BUILD_PAIR: |
| 6689 | Lo = Node->getOperand(0); |
| 6690 | Hi = Node->getOperand(1); |
| 6691 | break; |
Dan Gohman | 9fe4662 | 2007-09-28 23:53:40 +0000 | [diff] [blame] | 6692 | case ISD::INSERT_VECTOR_ELT: { |
| 6693 | SplitVectorOp(Node->getOperand(0), Lo, Hi); |
| 6694 | unsigned Index = cast<ConstantSDNode>(Node->getOperand(2))->getValue(); |
| 6695 | SDOperand ScalarOp = Node->getOperand(1); |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 6696 | if (Index < NewNumElts_Lo) |
| 6697 | Lo = DAG.getNode(ISD::INSERT_VECTOR_ELT, NewVT_Lo, Lo, ScalarOp, |
Dan Gohman | 9fe4662 | 2007-09-28 23:53:40 +0000 | [diff] [blame] | 6698 | DAG.getConstant(Index, TLI.getPointerTy())); |
| 6699 | else |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 6700 | Hi = DAG.getNode(ISD::INSERT_VECTOR_ELT, NewVT_Hi, Hi, ScalarOp, |
| 6701 | DAG.getConstant(Index - NewNumElts_Lo, |
| 6702 | TLI.getPointerTy())); |
Dan Gohman | 9fe4662 | 2007-09-28 23:53:40 +0000 | [diff] [blame] | 6703 | break; |
| 6704 | } |
Chris Lattner | 6c9c680 | 2007-11-19 21:16:54 +0000 | [diff] [blame] | 6705 | case ISD::VECTOR_SHUFFLE: { |
| 6706 | // Build the low part. |
| 6707 | SDOperand Mask = Node->getOperand(2); |
| 6708 | SmallVector<SDOperand, 8> Ops; |
| 6709 | MVT::ValueType PtrVT = TLI.getPointerTy(); |
| 6710 | |
| 6711 | // Insert all of the elements from the input that are needed. We use |
| 6712 | // buildvector of extractelement here because the input vectors will have |
| 6713 | // to be legalized, so this makes the code simpler. |
| 6714 | for (unsigned i = 0; i != NewNumElts_Lo; ++i) { |
| 6715 | unsigned Idx = cast<ConstantSDNode>(Mask.getOperand(i))->getValue(); |
| 6716 | SDOperand InVec = Node->getOperand(0); |
| 6717 | if (Idx >= NumElements) { |
| 6718 | InVec = Node->getOperand(1); |
| 6719 | Idx -= NumElements; |
| 6720 | } |
| 6721 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, NewEltVT, InVec, |
| 6722 | DAG.getConstant(Idx, PtrVT))); |
| 6723 | } |
| 6724 | Lo = DAG.getNode(ISD::BUILD_VECTOR, NewVT_Lo, &Ops[0], Ops.size()); |
| 6725 | Ops.clear(); |
| 6726 | |
| 6727 | for (unsigned i = NewNumElts_Lo; i != NumElements; ++i) { |
| 6728 | unsigned Idx = cast<ConstantSDNode>(Mask.getOperand(i))->getValue(); |
| 6729 | SDOperand InVec = Node->getOperand(0); |
| 6730 | if (Idx >= NumElements) { |
| 6731 | InVec = Node->getOperand(1); |
| 6732 | Idx -= NumElements; |
| 6733 | } |
| 6734 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, NewEltVT, InVec, |
| 6735 | DAG.getConstant(Idx, PtrVT))); |
| 6736 | } |
| 6737 | Hi = DAG.getNode(ISD::BUILD_VECTOR, NewVT_Lo, &Ops[0], Ops.size()); |
| 6738 | break; |
| 6739 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6740 | case ISD::BUILD_VECTOR: { |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 6741 | SmallVector<SDOperand, 8> LoOps(Node->op_begin(), |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 6742 | Node->op_begin()+NewNumElts_Lo); |
| 6743 | Lo = DAG.getNode(ISD::BUILD_VECTOR, NewVT_Lo, &LoOps[0], LoOps.size()); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6744 | |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 6745 | SmallVector<SDOperand, 8> HiOps(Node->op_begin()+NewNumElts_Lo, |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6746 | Node->op_end()); |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 6747 | Hi = DAG.getNode(ISD::BUILD_VECTOR, NewVT_Hi, &HiOps[0], HiOps.size()); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6748 | break; |
| 6749 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6750 | case ISD::CONCAT_VECTORS: { |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 6751 | // FIXME: Handle non-power-of-two vectors? |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6752 | unsigned NewNumSubvectors = Node->getNumOperands() / 2; |
| 6753 | if (NewNumSubvectors == 1) { |
| 6754 | Lo = Node->getOperand(0); |
| 6755 | Hi = Node->getOperand(1); |
| 6756 | } else { |
| 6757 | SmallVector<SDOperand, 8> LoOps(Node->op_begin(), |
| 6758 | Node->op_begin()+NewNumSubvectors); |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 6759 | Lo = DAG.getNode(ISD::CONCAT_VECTORS, NewVT_Lo, &LoOps[0], LoOps.size()); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 6760 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6761 | SmallVector<SDOperand, 8> HiOps(Node->op_begin()+NewNumSubvectors, |
| 6762 | Node->op_end()); |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 6763 | Hi = DAG.getNode(ISD::CONCAT_VECTORS, NewVT_Hi, &HiOps[0], HiOps.size()); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6764 | } |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 6765 | break; |
| 6766 | } |
Dan Gohman | c623096 | 2007-10-17 14:48:28 +0000 | [diff] [blame] | 6767 | case ISD::SELECT: { |
| 6768 | SDOperand Cond = Node->getOperand(0); |
| 6769 | |
| 6770 | SDOperand LL, LH, RL, RH; |
| 6771 | SplitVectorOp(Node->getOperand(1), LL, LH); |
| 6772 | SplitVectorOp(Node->getOperand(2), RL, RH); |
| 6773 | |
| 6774 | if (MVT::isVector(Cond.getValueType())) { |
| 6775 | // Handle a vector merge. |
| 6776 | SDOperand CL, CH; |
| 6777 | SplitVectorOp(Cond, CL, CH); |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 6778 | Lo = DAG.getNode(Node->getOpcode(), NewVT_Lo, CL, LL, RL); |
| 6779 | Hi = DAG.getNode(Node->getOpcode(), NewVT_Hi, CH, LH, RH); |
Dan Gohman | c623096 | 2007-10-17 14:48:28 +0000 | [diff] [blame] | 6780 | } else { |
| 6781 | // Handle a simple select with vector operands. |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 6782 | Lo = DAG.getNode(Node->getOpcode(), NewVT_Lo, Cond, LL, RL); |
| 6783 | Hi = DAG.getNode(Node->getOpcode(), NewVT_Hi, Cond, LH, RH); |
Dan Gohman | c623096 | 2007-10-17 14:48:28 +0000 | [diff] [blame] | 6784 | } |
| 6785 | break; |
| 6786 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6787 | case ISD::ADD: |
| 6788 | case ISD::SUB: |
| 6789 | case ISD::MUL: |
| 6790 | case ISD::FADD: |
| 6791 | case ISD::FSUB: |
| 6792 | case ISD::FMUL: |
| 6793 | case ISD::SDIV: |
| 6794 | case ISD::UDIV: |
| 6795 | case ISD::FDIV: |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 6796 | case ISD::FPOW: |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6797 | case ISD::AND: |
| 6798 | case ISD::OR: |
Dan Gohman | 089617d | 2007-11-19 15:15:03 +0000 | [diff] [blame] | 6799 | case ISD::XOR: |
| 6800 | case ISD::UREM: |
| 6801 | case ISD::SREM: |
| 6802 | case ISD::FREM: { |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6803 | SDOperand LL, LH, RL, RH; |
| 6804 | SplitVectorOp(Node->getOperand(0), LL, LH); |
| 6805 | SplitVectorOp(Node->getOperand(1), RL, RH); |
| 6806 | |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 6807 | Lo = DAG.getNode(Node->getOpcode(), NewVT_Lo, LL, RL); |
| 6808 | Hi = DAG.getNode(Node->getOpcode(), NewVT_Hi, LH, RH); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6809 | break; |
| 6810 | } |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 6811 | case ISD::FPOWI: { |
| 6812 | SDOperand L, H; |
| 6813 | SplitVectorOp(Node->getOperand(0), L, H); |
| 6814 | |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 6815 | Lo = DAG.getNode(Node->getOpcode(), NewVT_Lo, L, Node->getOperand(1)); |
| 6816 | Hi = DAG.getNode(Node->getOpcode(), NewVT_Hi, H, Node->getOperand(1)); |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 6817 | break; |
| 6818 | } |
| 6819 | case ISD::CTTZ: |
| 6820 | case ISD::CTLZ: |
| 6821 | case ISD::CTPOP: |
| 6822 | case ISD::FNEG: |
| 6823 | case ISD::FABS: |
| 6824 | case ISD::FSQRT: |
| 6825 | case ISD::FSIN: |
Nate Begeman | b348d18 | 2007-11-17 03:58:34 +0000 | [diff] [blame] | 6826 | case ISD::FCOS: |
| 6827 | case ISD::FP_TO_SINT: |
| 6828 | case ISD::FP_TO_UINT: |
| 6829 | case ISD::SINT_TO_FP: |
| 6830 | case ISD::UINT_TO_FP: { |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 6831 | SDOperand L, H; |
| 6832 | SplitVectorOp(Node->getOperand(0), L, H); |
| 6833 | |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 6834 | Lo = DAG.getNode(Node->getOpcode(), NewVT_Lo, L); |
| 6835 | Hi = DAG.getNode(Node->getOpcode(), NewVT_Hi, H); |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 6836 | break; |
| 6837 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6838 | case ISD::LOAD: { |
| 6839 | LoadSDNode *LD = cast<LoadSDNode>(Node); |
| 6840 | SDOperand Ch = LD->getChain(); |
| 6841 | SDOperand Ptr = LD->getBasePtr(); |
| 6842 | const Value *SV = LD->getSrcValue(); |
| 6843 | int SVOffset = LD->getSrcValueOffset(); |
| 6844 | unsigned Alignment = LD->getAlignment(); |
| 6845 | bool isVolatile = LD->isVolatile(); |
| 6846 | |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 6847 | Lo = DAG.getLoad(NewVT_Lo, Ch, Ptr, SV, SVOffset, isVolatile, Alignment); |
| 6848 | unsigned IncrementSize = NewNumElts_Lo * MVT::getSizeInBits(NewEltVT)/8; |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6849 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 6850 | DAG.getIntPtrConstant(IncrementSize)); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6851 | SVOffset += IncrementSize; |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 6852 | Alignment = MinAlign(Alignment, IncrementSize); |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 6853 | Hi = DAG.getLoad(NewVT_Hi, Ch, Ptr, SV, SVOffset, isVolatile, Alignment); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6854 | |
| 6855 | // Build a factor node to remember that this load is independent of the |
| 6856 | // other one. |
| 6857 | SDOperand TF = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1), |
| 6858 | Hi.getValue(1)); |
| 6859 | |
| 6860 | // Remember that we legalized the chain. |
| 6861 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(TF)); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6862 | break; |
| 6863 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6864 | case ISD::BIT_CONVERT: { |
Chris Lattner | 7692eb4 | 2006-03-23 21:16:34 +0000 | [diff] [blame] | 6865 | // We know the result is a vector. The input may be either a vector or a |
| 6866 | // scalar value. |
Dan Gohman | 10a7aa6 | 2007-06-29 00:09:08 +0000 | [diff] [blame] | 6867 | SDOperand InOp = Node->getOperand(0); |
| 6868 | if (!MVT::isVector(InOp.getValueType()) || |
| 6869 | MVT::getVectorNumElements(InOp.getValueType()) == 1) { |
| 6870 | // The input is a scalar or single-element vector. |
| 6871 | // Lower to a store/load so that it can be split. |
| 6872 | // FIXME: this could be improved probably. |
Chris Lattner | 85dd3be | 2007-10-15 17:48:57 +0000 | [diff] [blame] | 6873 | SDOperand Ptr = DAG.CreateStackTemporary(InOp.getValueType()); |
Dan Gohman | bbbbb9c | 2008-02-11 18:58:42 +0000 | [diff] [blame] | 6874 | FrameIndexSDNode *FI = cast<FrameIndexSDNode>(Ptr.Val); |
Chris Lattner | 7692eb4 | 2006-03-23 21:16:34 +0000 | [diff] [blame] | 6875 | |
Evan Cheng | 786225a | 2006-10-05 23:01:46 +0000 | [diff] [blame] | 6876 | SDOperand St = DAG.getStore(DAG.getEntryNode(), |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 6877 | InOp, Ptr, |
Dan Gohman | 3069b87 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 6878 | PseudoSourceValue::getFixedStack(), |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 6879 | FI->getIndex()); |
| 6880 | InOp = DAG.getLoad(Op.getValueType(), St, Ptr, |
Dan Gohman | 3069b87 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 6881 | PseudoSourceValue::getFixedStack(), |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 6882 | FI->getIndex()); |
Chris Lattner | 7692eb4 | 2006-03-23 21:16:34 +0000 | [diff] [blame] | 6883 | } |
Dan Gohman | 10a7aa6 | 2007-06-29 00:09:08 +0000 | [diff] [blame] | 6884 | // Split the vector and convert each of the pieces now. |
| 6885 | SplitVectorOp(InOp, Lo, Hi); |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 6886 | Lo = DAG.getNode(ISD::BIT_CONVERT, NewVT_Lo, Lo); |
| 6887 | Hi = DAG.getNode(ISD::BIT_CONVERT, NewVT_Hi, Hi); |
Dan Gohman | 10a7aa6 | 2007-06-29 00:09:08 +0000 | [diff] [blame] | 6888 | break; |
Chris Lattner | 7692eb4 | 2006-03-23 21:16:34 +0000 | [diff] [blame] | 6889 | } |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6890 | } |
| 6891 | |
| 6892 | // Remember in a map if the values will be reused later. |
Chris Lattner | 40030bf | 2007-02-04 01:17:38 +0000 | [diff] [blame] | 6893 | bool isNew = |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6894 | SplitNodes.insert(std::make_pair(Op, std::make_pair(Lo, Hi))).second; |
Dan Gohman | 10a7aa6 | 2007-06-29 00:09:08 +0000 | [diff] [blame] | 6895 | assert(isNew && "Value already split?!?"); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6896 | } |
| 6897 | |
| 6898 | |
Dan Gohman | 89b20c0 | 2007-06-27 14:06:22 +0000 | [diff] [blame] | 6899 | /// ScalarizeVectorOp - Given an operand of single-element vector type |
| 6900 | /// (e.g. v1f32), convert it into the equivalent operation that returns a |
| 6901 | /// scalar (e.g. f32) value. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6902 | SDOperand SelectionDAGLegalize::ScalarizeVectorOp(SDOperand Op) { |
| 6903 | assert(MVT::isVector(Op.getValueType()) && |
| 6904 | "Bad ScalarizeVectorOp invocation!"); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6905 | SDNode *Node = Op.Val; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6906 | MVT::ValueType NewVT = MVT::getVectorElementType(Op.getValueType()); |
| 6907 | assert(MVT::getVectorNumElements(Op.getValueType()) == 1); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6908 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6909 | // See if we already scalarized it. |
| 6910 | std::map<SDOperand, SDOperand>::iterator I = ScalarizedNodes.find(Op); |
| 6911 | if (I != ScalarizedNodes.end()) return I->second; |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6912 | |
| 6913 | SDOperand Result; |
| 6914 | switch (Node->getOpcode()) { |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 6915 | default: |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 6916 | #ifndef NDEBUG |
Dan Gohman | 3983358 | 2007-06-04 16:17:33 +0000 | [diff] [blame] | 6917 | Node->dump(&DAG); cerr << "\n"; |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 6918 | #endif |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6919 | assert(0 && "Unknown vector operation in ScalarizeVectorOp!"); |
| 6920 | case ISD::ADD: |
| 6921 | case ISD::FADD: |
| 6922 | case ISD::SUB: |
| 6923 | case ISD::FSUB: |
| 6924 | case ISD::MUL: |
| 6925 | case ISD::FMUL: |
| 6926 | case ISD::SDIV: |
| 6927 | case ISD::UDIV: |
| 6928 | case ISD::FDIV: |
| 6929 | case ISD::SREM: |
| 6930 | case ISD::UREM: |
| 6931 | case ISD::FREM: |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 6932 | case ISD::FPOW: |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6933 | case ISD::AND: |
| 6934 | case ISD::OR: |
| 6935 | case ISD::XOR: |
| 6936 | Result = DAG.getNode(Node->getOpcode(), |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6937 | NewVT, |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6938 | ScalarizeVectorOp(Node->getOperand(0)), |
| 6939 | ScalarizeVectorOp(Node->getOperand(1))); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6940 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6941 | case ISD::FNEG: |
| 6942 | case ISD::FABS: |
| 6943 | case ISD::FSQRT: |
| 6944 | case ISD::FSIN: |
| 6945 | case ISD::FCOS: |
| 6946 | Result = DAG.getNode(Node->getOpcode(), |
| 6947 | NewVT, |
| 6948 | ScalarizeVectorOp(Node->getOperand(0))); |
| 6949 | break; |
Dan Gohman | 9e04c82 | 2007-10-12 14:13:46 +0000 | [diff] [blame] | 6950 | case ISD::FPOWI: |
| 6951 | Result = DAG.getNode(Node->getOpcode(), |
| 6952 | NewVT, |
| 6953 | ScalarizeVectorOp(Node->getOperand(0)), |
| 6954 | Node->getOperand(1)); |
| 6955 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6956 | case ISD::LOAD: { |
| 6957 | LoadSDNode *LD = cast<LoadSDNode>(Node); |
| 6958 | SDOperand Ch = LegalizeOp(LD->getChain()); // Legalize the chain. |
| 6959 | SDOperand Ptr = LegalizeOp(LD->getBasePtr()); // Legalize the pointer. |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6960 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6961 | const Value *SV = LD->getSrcValue(); |
| 6962 | int SVOffset = LD->getSrcValueOffset(); |
| 6963 | Result = DAG.getLoad(NewVT, Ch, Ptr, SV, SVOffset, |
| 6964 | LD->isVolatile(), LD->getAlignment()); |
| 6965 | |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6966 | // Remember that we legalized the chain. |
| 6967 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1))); |
| 6968 | break; |
| 6969 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6970 | case ISD::BUILD_VECTOR: |
| 6971 | Result = Node->getOperand(0); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6972 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6973 | case ISD::INSERT_VECTOR_ELT: |
| 6974 | // Returning the inserted scalar element. |
| 6975 | Result = Node->getOperand(1); |
| 6976 | break; |
| 6977 | case ISD::CONCAT_VECTORS: |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 6978 | assert(Node->getOperand(0).getValueType() == NewVT && |
| 6979 | "Concat of non-legal vectors not yet supported!"); |
| 6980 | Result = Node->getOperand(0); |
| 6981 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6982 | case ISD::VECTOR_SHUFFLE: { |
| 6983 | // Figure out if the scalar is the LHS or RHS and return it. |
| 6984 | SDOperand EltNum = Node->getOperand(2).getOperand(0); |
| 6985 | if (cast<ConstantSDNode>(EltNum)->getValue()) |
| 6986 | Result = ScalarizeVectorOp(Node->getOperand(1)); |
| 6987 | else |
| 6988 | Result = ScalarizeVectorOp(Node->getOperand(0)); |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 6989 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6990 | } |
| 6991 | case ISD::EXTRACT_SUBVECTOR: |
| 6992 | Result = Node->getOperand(0); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 6993 | assert(Result.getValueType() == NewVT); |
| 6994 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6995 | case ISD::BIT_CONVERT: |
| 6996 | Result = DAG.getNode(ISD::BIT_CONVERT, NewVT, Op.getOperand(0)); |
Chris Lattner | 5b2316e | 2006-03-28 20:24:43 +0000 | [diff] [blame] | 6997 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6998 | case ISD::SELECT: |
Chris Lattner | b22e35a | 2006-04-08 22:22:57 +0000 | [diff] [blame] | 6999 | Result = DAG.getNode(ISD::SELECT, NewVT, Op.getOperand(0), |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7000 | ScalarizeVectorOp(Op.getOperand(1)), |
| 7001 | ScalarizeVectorOp(Op.getOperand(2))); |
Chris Lattner | b22e35a | 2006-04-08 22:22:57 +0000 | [diff] [blame] | 7002 | break; |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7003 | } |
| 7004 | |
| 7005 | if (TLI.isTypeLegal(NewVT)) |
| 7006 | Result = LegalizeOp(Result); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7007 | bool isNew = ScalarizedNodes.insert(std::make_pair(Op, Result)).second; |
| 7008 | assert(isNew && "Value already scalarized?"); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7009 | return Result; |
| 7010 | } |
| 7011 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 7012 | |
| 7013 | // SelectionDAG::Legalize - This is the entry point for the file. |
| 7014 | // |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 7015 | void SelectionDAG::Legalize() { |
Chris Lattner | 5e46a19 | 2006-04-02 03:07:27 +0000 | [diff] [blame] | 7016 | if (ViewLegalizeDAGs) viewGraph(); |
| 7017 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 7018 | /// run - This is the main entry point to this class. |
| 7019 | /// |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 7020 | SelectionDAGLegalize(*this).LegalizeDAG(); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 7021 | } |
| 7022 | |