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" |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 25 | #include "llvm/Target/TargetSubtarget.h" |
Chris Lattner | adf6a96 | 2005-05-13 18:50:42 +0000 | [diff] [blame] | 26 | #include "llvm/CallingConv.h" |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 27 | #include "llvm/Constants.h" |
Reid Spencer | c103057 | 2007-01-19 21:13:56 +0000 | [diff] [blame] | 28 | #include "llvm/DerivedTypes.h" |
Chris Lattner | 5e46a19 | 2006-04-02 03:07:27 +0000 | [diff] [blame] | 29 | #include "llvm/Support/CommandLine.h" |
Chris Lattner | a4f0b3a | 2006-08-27 12:54:02 +0000 | [diff] [blame] | 30 | #include "llvm/Support/Compiler.h" |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 31 | #include "llvm/Support/MathExtras.h" |
Chris Lattner | 7971514 | 2007-02-03 01:12:36 +0000 | [diff] [blame] | 32 | #include "llvm/ADT/DenseMap.h" |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 33 | #include "llvm/ADT/SmallVector.h" |
Chris Lattner | 00755df | 2007-02-04 00:27:56 +0000 | [diff] [blame] | 34 | #include "llvm/ADT/SmallPtrSet.h" |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 35 | #include <map> |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 36 | using namespace llvm; |
| 37 | |
| 38 | //===----------------------------------------------------------------------===// |
| 39 | /// SelectionDAGLegalize - This takes an arbitrary SelectionDAG as input and |
| 40 | /// hacks on it until the target machine can handle it. This involves |
| 41 | /// eliminating value sizes the machine cannot handle (promoting small sizes to |
| 42 | /// large sizes or splitting up large values into small values) as well as |
| 43 | /// eliminating operations the machine cannot handle. |
| 44 | /// |
| 45 | /// This code also does a small amount of optimization and recognition of idioms |
| 46 | /// as part of its processing. For example, if a target does not support a |
| 47 | /// 'setcc' instruction efficiently, but does support 'brcc' instruction, this |
| 48 | /// will attempt merge setcc and brc instructions into brcc's. |
| 49 | /// |
| 50 | namespace { |
Chris Lattner | 360e820 | 2006-06-28 21:58:30 +0000 | [diff] [blame] | 51 | class VISIBILITY_HIDDEN SelectionDAGLegalize { |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 52 | TargetLowering &TLI; |
| 53 | SelectionDAG &DAG; |
| 54 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 55 | // Libcall insertion helpers. |
| 56 | |
| 57 | /// LastCALLSEQ_END - This keeps track of the CALLSEQ_END node that has been |
| 58 | /// legalized. We use this to ensure that calls are properly serialized |
| 59 | /// against each other, including inserted libcalls. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 60 | SDValue LastCALLSEQ_END; |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 61 | |
| 62 | /// IsLegalizingCall - This member is used *only* for purposes of providing |
| 63 | /// helpful assertions that a libcall isn't created while another call is |
| 64 | /// being legalized (which could lead to non-serialized call sequences). |
| 65 | bool IsLegalizingCall; |
| 66 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 67 | enum LegalizeAction { |
Chris Lattner | 68a17fe | 2006-01-29 08:42:06 +0000 | [diff] [blame] | 68 | Legal, // The target natively supports this operation. |
| 69 | Promote, // This operation should be executed in a larger type. |
Chris Lattner | d74ea2b | 2006-05-24 17:04:05 +0000 | [diff] [blame] | 70 | Expand // Try to expand this to other ops, otherwise use a libcall. |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 71 | }; |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 72 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 73 | /// ValueTypeActions - This is a bitvector that contains two bits for each |
| 74 | /// value type, where the two bits correspond to the LegalizeAction enum. |
| 75 | /// This can be queried with "getTypeAction(VT)". |
Chris Lattner | 68a17fe | 2006-01-29 08:42:06 +0000 | [diff] [blame] | 76 | TargetLowering::ValueTypeActionImpl ValueTypeActions; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 77 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 78 | /// LegalizedNodes - For nodes that are of legal width, and that have more |
| 79 | /// than one use, this map indicates what regularized operand to use. This |
| 80 | /// allows us to avoid legalizing the same thing more than once. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 81 | DenseMap<SDValue, SDValue> LegalizedNodes; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 82 | |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 83 | /// PromotedNodes - For nodes that are below legal width, and that have more |
| 84 | /// than one use, this map indicates what promoted value to use. This allows |
| 85 | /// us to avoid promoting the same thing more than once. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 86 | DenseMap<SDValue, SDValue> PromotedNodes; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 87 | |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 88 | /// ExpandedNodes - For nodes that need to be expanded this map indicates |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 89 | /// which operands are the expanded version of the input. This allows |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 90 | /// us to avoid expanding the same node more than once. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 91 | DenseMap<SDValue, std::pair<SDValue, SDValue> > ExpandedNodes; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 92 | |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 93 | /// SplitNodes - For vector nodes that need to be split, this map indicates |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 94 | /// which operands are the split version of the input. This allows us |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 95 | /// to avoid splitting the same node more than once. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 96 | std::map<SDValue, std::pair<SDValue, SDValue> > SplitNodes; |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 97 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 98 | /// ScalarizedNodes - For nodes that need to be converted from vector types to |
| 99 | /// scalar types, this contains the mapping of ones we have already |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 100 | /// processed to the result. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 101 | std::map<SDValue, SDValue> ScalarizedNodes; |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 102 | |
Mon P Wang | f007a8b | 2008-11-06 05:31:54 +0000 | [diff] [blame] | 103 | /// WidenNodes - For nodes that need to be widened from one vector type to |
| 104 | /// another, this contains the mapping of those that we have already widen. |
| 105 | /// This allows us to avoid widening more than once. |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 106 | std::map<SDValue, SDValue> WidenNodes; |
| 107 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 108 | void AddLegalizedOperand(SDValue From, SDValue To) { |
Chris Lattner | 69a889e | 2005-12-20 00:53:54 +0000 | [diff] [blame] | 109 | LegalizedNodes.insert(std::make_pair(From, To)); |
| 110 | // If someone requests legalization of the new node, return itself. |
| 111 | if (From != To) |
| 112 | LegalizedNodes.insert(std::make_pair(To, To)); |
Chris Lattner | 8afc48e | 2005-01-07 22:28:47 +0000 | [diff] [blame] | 113 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 114 | void AddPromotedOperand(SDValue From, SDValue To) { |
Dan Gohman | 6b345ee | 2008-07-07 17:46:23 +0000 | [diff] [blame] | 115 | bool isNew = PromotedNodes.insert(std::make_pair(From, To)).second; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 116 | assert(isNew && "Got into the map somehow?"); |
Evan Cheng | 24ac408 | 2008-11-24 07:09:49 +0000 | [diff] [blame] | 117 | isNew = isNew; |
Chris Lattner | 69a889e | 2005-12-20 00:53:54 +0000 | [diff] [blame] | 118 | // If someone requests legalization of the new node, return itself. |
| 119 | LegalizedNodes.insert(std::make_pair(To, To)); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 120 | } |
Mon P Wang | f007a8b | 2008-11-06 05:31:54 +0000 | [diff] [blame] | 121 | void AddWidenedOperand(SDValue From, SDValue To) { |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 122 | bool isNew = WidenNodes.insert(std::make_pair(From, To)).second; |
| 123 | assert(isNew && "Got into the map somehow?"); |
Evan Cheng | 24ac408 | 2008-11-24 07:09:49 +0000 | [diff] [blame] | 124 | isNew = isNew; |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 125 | // If someone requests legalization of the new node, return itself. |
| 126 | LegalizedNodes.insert(std::make_pair(To, To)); |
| 127 | } |
Chris Lattner | 8afc48e | 2005-01-07 22:28:47 +0000 | [diff] [blame] | 128 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 129 | public: |
Dan Gohman | 1002c02 | 2008-07-07 18:00:37 +0000 | [diff] [blame] | 130 | explicit SelectionDAGLegalize(SelectionDAG &DAG); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 131 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 132 | /// getTypeAction - Return how we should legalize values of this type, either |
| 133 | /// it is already legal or we need to expand it into multiple registers of |
| 134 | /// smaller integer type, or we need to promote it to a larger type. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 135 | LegalizeAction getTypeAction(MVT VT) const { |
Chris Lattner | 68a17fe | 2006-01-29 08:42:06 +0000 | [diff] [blame] | 136 | return (LegalizeAction)ValueTypeActions.getTypeAction(VT); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | /// isTypeLegal - Return true if this type is legal on this target. |
| 140 | /// |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 141 | bool isTypeLegal(MVT VT) const { |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 142 | return getTypeAction(VT) == Legal; |
| 143 | } |
| 144 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 145 | void LegalizeDAG(); |
| 146 | |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 147 | private: |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 148 | /// HandleOp - Legalize, Promote, or Expand the specified operand as |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 149 | /// appropriate for its type. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 150 | void HandleOp(SDValue Op); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 151 | |
| 152 | /// LegalizeOp - We know that the specified value has a legal type. |
| 153 | /// Recursively ensure that the operands have legal types, then return the |
| 154 | /// result. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 155 | SDValue LegalizeOp(SDValue O); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 156 | |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 157 | /// UnrollVectorOp - We know that the given vector has a legal type, however |
| 158 | /// the operation it performs is not legal and is an operation that we have |
| 159 | /// no way of lowering. "Unroll" the vector, splitting out the scalars and |
| 160 | /// operating on each element individually. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 161 | SDValue UnrollVectorOp(SDValue O); |
Nate Begeman | 6867991 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 162 | |
| 163 | /// PerformInsertVectorEltInMemory - Some target cannot handle a variable |
| 164 | /// insertion index for the INSERT_VECTOR_ELT instruction. In this case, it |
| 165 | /// is necessary to spill the vector being inserted into to memory, perform |
| 166 | /// the insert there, and then read the result back. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 167 | SDValue PerformInsertVectorEltInMemory(SDValue Vec, SDValue Val, |
| 168 | SDValue Idx); |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 169 | |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 170 | /// PromoteOp - Given an operation that produces a value in an invalid type, |
| 171 | /// promote it to compute the value into a larger type. The produced value |
| 172 | /// will have the correct bits for the low portion of the register, but no |
| 173 | /// guarantee is made about the top bits: it may be zero, sign-extended, or |
| 174 | /// garbage. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 175 | SDValue PromoteOp(SDValue O); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 176 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 177 | /// ExpandOp - Expand the specified SDValue into its two component pieces |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 178 | /// Lo&Hi. Note that the Op MUST be an expanded type. As a result of this, |
Dan Gohman | 929d3eb | 2008-10-01 15:07:49 +0000 | [diff] [blame] | 179 | /// the LegalizedNodes map is filled in for any results that are not expanded, |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 180 | /// the ExpandedNodes map is filled in for any results that are expanded, and |
| 181 | /// the Lo/Hi values are returned. This applies to integer types and Vector |
| 182 | /// types. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 183 | void ExpandOp(SDValue O, SDValue &Lo, SDValue &Hi); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 184 | |
Mon P Wang | f007a8b | 2008-11-06 05:31:54 +0000 | [diff] [blame] | 185 | /// WidenVectorOp - Widen a vector operation to a wider type given by WidenVT |
| 186 | /// (e.g., v3i32 to v4i32). The produced value will have the correct value |
| 187 | /// for the existing elements but no guarantee is made about the new elements |
| 188 | /// at the end of the vector: it may be zero, ones, or garbage. This is useful |
| 189 | /// when we have an instruction operating on an illegal vector type and we |
| 190 | /// want to widen it to do the computation on a legal wider vector type. |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 191 | SDValue WidenVectorOp(SDValue Op, MVT WidenVT); |
| 192 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 193 | /// SplitVectorOp - Given an operand of vector type, break it down into |
| 194 | /// two smaller values. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 195 | void SplitVectorOp(SDValue O, SDValue &Lo, SDValue &Hi); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 196 | |
Dan Gohman | 89b20c0 | 2007-06-27 14:06:22 +0000 | [diff] [blame] | 197 | /// ScalarizeVectorOp - Given an operand of single-element vector type |
| 198 | /// (e.g. v1f32), convert it into the equivalent operation that returns a |
| 199 | /// scalar (e.g. f32) value. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 200 | SDValue ScalarizeVectorOp(SDValue O); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 201 | |
Mon P Wang | f007a8b | 2008-11-06 05:31:54 +0000 | [diff] [blame] | 202 | /// Useful 16 element vector type that is used to pass operands for widening. |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 203 | typedef SmallVector<SDValue, 16> SDValueVector; |
| 204 | |
| 205 | /// LoadWidenVectorOp - Load a vector for a wider type. Returns true if |
| 206 | /// the LdChain contains a single load and false if it contains a token |
| 207 | /// factor for multiple loads. It takes |
| 208 | /// Result: location to return the result |
| 209 | /// LdChain: location to return the load chain |
| 210 | /// Op: load operation to widen |
| 211 | /// NVT: widen vector result type we want for the load |
| 212 | bool LoadWidenVectorOp(SDValue& Result, SDValue& LdChain, |
| 213 | SDValue Op, MVT NVT); |
| 214 | |
| 215 | /// Helper genWidenVectorLoads - Helper function to generate a set of |
| 216 | /// loads to load a vector with a resulting wider type. It takes |
| 217 | /// LdChain: list of chains for the load we have generated |
| 218 | /// Chain: incoming chain for the ld vector |
| 219 | /// BasePtr: base pointer to load from |
| 220 | /// SV: memory disambiguation source value |
| 221 | /// SVOffset: memory disambiugation offset |
| 222 | /// Alignment: alignment of the memory |
| 223 | /// isVolatile: volatile load |
| 224 | /// LdWidth: width of memory that we want to load |
| 225 | /// ResType: the wider result result type for the resulting loaded vector |
| 226 | SDValue genWidenVectorLoads(SDValueVector& LdChain, SDValue Chain, |
| 227 | SDValue BasePtr, const Value *SV, |
| 228 | int SVOffset, unsigned Alignment, |
| 229 | bool isVolatile, unsigned LdWidth, |
| 230 | MVT ResType); |
| 231 | |
| 232 | /// StoreWidenVectorOp - Stores a widen vector into non widen memory |
| 233 | /// location. It takes |
| 234 | /// ST: store node that we want to replace |
| 235 | /// Chain: incoming store chain |
| 236 | /// BasePtr: base address of where we want to store into |
| 237 | SDValue StoreWidenVectorOp(StoreSDNode *ST, SDValue Chain, |
| 238 | SDValue BasePtr); |
| 239 | |
| 240 | /// Helper genWidenVectorStores - Helper function to generate a set of |
| 241 | /// stores to store a widen vector into non widen memory |
| 242 | // It takes |
| 243 | // StChain: list of chains for the stores we have generated |
| 244 | // Chain: incoming chain for the ld vector |
| 245 | // BasePtr: base pointer to load from |
| 246 | // SV: memory disambiguation source value |
| 247 | // SVOffset: memory disambiugation offset |
| 248 | // Alignment: alignment of the memory |
| 249 | // isVolatile: volatile lod |
| 250 | // ValOp: value to store |
| 251 | // StWidth: width of memory that we want to store |
| 252 | void genWidenVectorStores(SDValueVector& StChain, SDValue Chain, |
| 253 | SDValue BasePtr, const Value *SV, |
| 254 | int SVOffset, unsigned Alignment, |
| 255 | bool isVolatile, SDValue ValOp, |
| 256 | unsigned StWidth); |
| 257 | |
Duncan Sands | d038e04 | 2008-07-21 10:20:31 +0000 | [diff] [blame] | 258 | /// isShuffleLegal - Return non-null if a vector shuffle is legal with the |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 259 | /// specified mask and type. Targets can specify exactly which masks they |
| 260 | /// support and the code generator is tasked with not creating illegal masks. |
| 261 | /// |
| 262 | /// Note that this will also return true for shuffles that are promoted to a |
| 263 | /// different type. |
| 264 | /// |
| 265 | /// If this is a legal shuffle, this method returns the (possibly promoted) |
| 266 | /// build_vector Mask. If it's not a legal shuffle, it returns null. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 267 | SDNode *isShuffleLegal(MVT VT, SDValue Mask) const; |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 268 | |
Chris Lattner | c9cf4f1 | 2006-07-26 23:55:56 +0000 | [diff] [blame] | 269 | bool LegalizeAllNodesNotLeadingTo(SDNode *N, SDNode *Dest, |
Chris Lattner | 00755df | 2007-02-04 00:27:56 +0000 | [diff] [blame] | 270 | SmallPtrSet<SDNode*, 32> &NodesLeadingTo); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 271 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 272 | void LegalizeSetCCOperands(SDValue &LHS, SDValue &RHS, SDValue &CC); |
Evan Cheng | 7f04268 | 2008-10-15 02:05:31 +0000 | [diff] [blame] | 273 | void LegalizeSetCCCondCode(MVT VT, SDValue &LHS, SDValue &RHS, SDValue &CC); |
| 274 | void LegalizeSetCC(MVT VT, SDValue &LHS, SDValue &RHS, SDValue &CC) { |
| 275 | LegalizeSetCCOperands(LHS, RHS, CC); |
| 276 | LegalizeSetCCCondCode(VT, LHS, RHS, CC); |
| 277 | } |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 278 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 279 | SDValue ExpandLibCall(RTLIB::Libcall LC, SDNode *Node, bool isSigned, |
| 280 | SDValue &Hi); |
| 281 | SDValue ExpandIntToFP(bool isSigned, MVT DestTy, SDValue Source); |
Chris Lattner | cad063f | 2005-07-16 00:19:57 +0000 | [diff] [blame] | 282 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 283 | SDValue EmitStackConvert(SDValue SrcOp, MVT SlotVT, MVT DestVT); |
| 284 | SDValue ExpandBUILD_VECTOR(SDNode *Node); |
| 285 | SDValue ExpandSCALAR_TO_VECTOR(SDNode *Node); |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 286 | SDValue LegalizeINT_TO_FP(SDValue Result, bool isSigned, MVT DestTy, SDValue Op); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 287 | SDValue ExpandLegalINT_TO_FP(bool isSigned, SDValue LegalOp, MVT DestVT); |
| 288 | SDValue PromoteLegalINT_TO_FP(SDValue LegalOp, MVT DestVT, bool isSigned); |
| 289 | SDValue PromoteLegalFP_TO_INT(SDValue LegalOp, MVT DestVT, bool isSigned); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 290 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 291 | SDValue ExpandBSWAP(SDValue Op); |
| 292 | SDValue ExpandBitCount(unsigned Opc, SDValue Op); |
| 293 | bool ExpandShift(unsigned Opc, SDValue Op, SDValue Amt, |
| 294 | SDValue &Lo, SDValue &Hi); |
| 295 | void ExpandShiftParts(unsigned NodeOp, SDValue Op, SDValue Amt, |
| 296 | SDValue &Lo, SDValue &Hi); |
Chris Lattner | b9fa3bc | 2005-05-12 04:49:08 +0000 | [diff] [blame] | 297 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 298 | SDValue ExpandEXTRACT_SUBVECTOR(SDValue Op); |
| 299 | SDValue ExpandEXTRACT_VECTOR_ELT(SDValue Op); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 300 | }; |
| 301 | } |
| 302 | |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 303 | /// isVectorShuffleLegal - Return true if a vector shuffle is legal with the |
| 304 | /// specified mask and type. Targets can specify exactly which masks they |
| 305 | /// support and the code generator is tasked with not creating illegal masks. |
| 306 | /// |
| 307 | /// Note that this will also return true for shuffles that are promoted to a |
| 308 | /// different type. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 309 | SDNode *SelectionDAGLegalize::isShuffleLegal(MVT VT, SDValue Mask) const { |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 310 | switch (TLI.getOperationAction(ISD::VECTOR_SHUFFLE, VT)) { |
| 311 | default: return 0; |
| 312 | case TargetLowering::Legal: |
| 313 | case TargetLowering::Custom: |
| 314 | break; |
| 315 | case TargetLowering::Promote: { |
| 316 | // If this is promoted to a different type, convert the shuffle mask and |
| 317 | // ask if it is legal in the promoted type! |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 318 | MVT NVT = TLI.getTypeToPromoteTo(ISD::VECTOR_SHUFFLE, VT); |
Duncan Sands | d038e04 | 2008-07-21 10:20:31 +0000 | [diff] [blame] | 319 | MVT EltVT = NVT.getVectorElementType(); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 320 | |
| 321 | // If we changed # elements, change the shuffle mask. |
| 322 | unsigned NumEltsGrowth = |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 323 | NVT.getVectorNumElements() / VT.getVectorNumElements(); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 324 | assert(NumEltsGrowth && "Cannot promote to vector type with fewer elts!"); |
| 325 | if (NumEltsGrowth > 1) { |
| 326 | // Renumber the elements. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 327 | SmallVector<SDValue, 8> Ops; |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 328 | for (unsigned i = 0, e = Mask.getNumOperands(); i != e; ++i) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 329 | SDValue InOp = Mask.getOperand(i); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 330 | for (unsigned j = 0; j != NumEltsGrowth; ++j) { |
| 331 | if (InOp.getOpcode() == ISD::UNDEF) |
Duncan Sands | d038e04 | 2008-07-21 10:20:31 +0000 | [diff] [blame] | 332 | Ops.push_back(DAG.getNode(ISD::UNDEF, EltVT)); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 333 | else { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 334 | unsigned InEltNo = cast<ConstantSDNode>(InOp)->getZExtValue(); |
Duncan Sands | d038e04 | 2008-07-21 10:20:31 +0000 | [diff] [blame] | 335 | Ops.push_back(DAG.getConstant(InEltNo*NumEltsGrowth+j, EltVT)); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 336 | } |
| 337 | } |
| 338 | } |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 339 | Mask = DAG.getNode(ISD::BUILD_VECTOR, NVT, &Ops[0], Ops.size()); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 340 | } |
| 341 | VT = NVT; |
| 342 | break; |
| 343 | } |
| 344 | } |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 345 | return TLI.isShuffleMaskLegal(Mask, VT) ? Mask.getNode() : 0; |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 346 | } |
| 347 | |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 348 | SelectionDAGLegalize::SelectionDAGLegalize(SelectionDAG &dag) |
| 349 | : TLI(dag.getTargetLoweringInfo()), DAG(dag), |
| 350 | ValueTypeActions(TLI.getValueTypeActions()) { |
Nate Begeman | 6a64861 | 2005-11-29 05:45:29 +0000 | [diff] [blame] | 351 | assert(MVT::LAST_VALUETYPE <= 32 && |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 352 | "Too many value types for ValueTypeActions to hold!"); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 353 | } |
| 354 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 355 | void SelectionDAGLegalize::LegalizeDAG() { |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 356 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 357 | IsLegalizingCall = false; |
| 358 | |
Chris Lattner | ab510a7 | 2005-10-02 17:49:46 +0000 | [diff] [blame] | 359 | // The legalize process is inherently a bottom-up recursive process (users |
| 360 | // legalize their uses before themselves). Given infinite stack space, we |
| 361 | // could just start legalizing on the root and traverse the whole graph. In |
| 362 | // 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] | 363 | // blocks. To avoid this problem, compute an ordering of the nodes where each |
| 364 | // node is only legalized after all of its operands are legalized. |
Dan Gohman | f06c835 | 2008-09-30 18:30:35 +0000 | [diff] [blame] | 365 | DAG.AssignTopologicalOrder(); |
| 366 | for (SelectionDAG::allnodes_iterator I = DAG.allnodes_begin(), |
| 367 | E = prior(DAG.allnodes_end()); I != next(E); ++I) |
| 368 | HandleOp(SDValue(I, 0)); |
Chris Lattner | 32fca00 | 2005-10-06 01:20:27 +0000 | [diff] [blame] | 369 | |
| 370 | // Finally, it's possible the root changed. Get the new root. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 371 | SDValue OldRoot = DAG.getRoot(); |
Chris Lattner | 32fca00 | 2005-10-06 01:20:27 +0000 | [diff] [blame] | 372 | assert(LegalizedNodes.count(OldRoot) && "Root didn't get legalized?"); |
| 373 | DAG.setRoot(LegalizedNodes[OldRoot]); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 374 | |
| 375 | ExpandedNodes.clear(); |
| 376 | LegalizedNodes.clear(); |
Chris Lattner | 71c42a0 | 2005-01-16 01:11:45 +0000 | [diff] [blame] | 377 | PromotedNodes.clear(); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 378 | SplitNodes.clear(); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 379 | ScalarizedNodes.clear(); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 380 | WidenNodes.clear(); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 381 | |
| 382 | // Remove dead nodes now. |
Chris Lattner | 190a418 | 2006-08-04 17:45:20 +0000 | [diff] [blame] | 383 | DAG.RemoveDeadNodes(); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 384 | } |
| 385 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 386 | |
| 387 | /// FindCallEndFromCallStart - Given a chained node that is part of a call |
| 388 | /// sequence, find the CALLSEQ_END node that terminates the call sequence. |
| 389 | static SDNode *FindCallEndFromCallStart(SDNode *Node) { |
| 390 | if (Node->getOpcode() == ISD::CALLSEQ_END) |
| 391 | return Node; |
| 392 | if (Node->use_empty()) |
| 393 | return 0; // No CallSeqEnd |
| 394 | |
| 395 | // The chain is usually at the end. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 396 | SDValue TheChain(Node, Node->getNumValues()-1); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 397 | if (TheChain.getValueType() != MVT::Other) { |
| 398 | // Sometimes it's at the beginning. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 399 | TheChain = SDValue(Node, 0); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 400 | if (TheChain.getValueType() != MVT::Other) { |
| 401 | // Otherwise, hunt for it. |
| 402 | for (unsigned i = 1, e = Node->getNumValues(); i != e; ++i) |
| 403 | if (Node->getValueType(i) == MVT::Other) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 404 | TheChain = SDValue(Node, i); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 405 | break; |
| 406 | } |
| 407 | |
| 408 | // Otherwise, we walked into a node without a chain. |
| 409 | if (TheChain.getValueType() != MVT::Other) |
| 410 | return 0; |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | for (SDNode::use_iterator UI = Node->use_begin(), |
| 415 | E = Node->use_end(); UI != E; ++UI) { |
| 416 | |
| 417 | // Make sure to only follow users of our token chain. |
Dan Gohman | 8968450 | 2008-07-27 20:43:25 +0000 | [diff] [blame] | 418 | SDNode *User = *UI; |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 419 | for (unsigned i = 0, e = User->getNumOperands(); i != e; ++i) |
| 420 | if (User->getOperand(i) == TheChain) |
| 421 | if (SDNode *Result = FindCallEndFromCallStart(User)) |
| 422 | return Result; |
| 423 | } |
| 424 | return 0; |
| 425 | } |
| 426 | |
| 427 | /// FindCallStartFromCallEnd - Given a chained node that is part of a call |
| 428 | /// sequence, find the CALLSEQ_START node that initiates the call sequence. |
| 429 | static SDNode *FindCallStartFromCallEnd(SDNode *Node) { |
| 430 | assert(Node && "Didn't find callseq_start for a call??"); |
| 431 | if (Node->getOpcode() == ISD::CALLSEQ_START) return Node; |
| 432 | |
| 433 | assert(Node->getOperand(0).getValueType() == MVT::Other && |
| 434 | "Node doesn't have a token chain argument!"); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 435 | return FindCallStartFromCallEnd(Node->getOperand(0).getNode()); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | /// LegalizeAllNodesNotLeadingTo - Recursively walk the uses of N, looking to |
| 439 | /// see if any uses can reach Dest. If no dest operands can get to dest, |
| 440 | /// legalize them, legalize ourself, and return false, otherwise, return true. |
Chris Lattner | c9cf4f1 | 2006-07-26 23:55:56 +0000 | [diff] [blame] | 441 | /// |
| 442 | /// Keep track of the nodes we fine that actually do lead to Dest in |
| 443 | /// NodesLeadingTo. This avoids retraversing them exponential number of times. |
| 444 | /// |
| 445 | bool SelectionDAGLegalize::LegalizeAllNodesNotLeadingTo(SDNode *N, SDNode *Dest, |
Chris Lattner | 00755df | 2007-02-04 00:27:56 +0000 | [diff] [blame] | 446 | SmallPtrSet<SDNode*, 32> &NodesLeadingTo) { |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 447 | if (N == Dest) return true; // N certainly leads to Dest :) |
| 448 | |
Chris Lattner | c9cf4f1 | 2006-07-26 23:55:56 +0000 | [diff] [blame] | 449 | // If we've already processed this node and it does lead to Dest, there is no |
| 450 | // need to reprocess it. |
| 451 | if (NodesLeadingTo.count(N)) return true; |
| 452 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 453 | // If the first result of this node has been already legalized, then it cannot |
| 454 | // reach N. |
| 455 | switch (getTypeAction(N->getValueType(0))) { |
| 456 | case Legal: |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 457 | if (LegalizedNodes.count(SDValue(N, 0))) return false; |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 458 | break; |
| 459 | case Promote: |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 460 | if (PromotedNodes.count(SDValue(N, 0))) return false; |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 461 | break; |
| 462 | case Expand: |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 463 | if (ExpandedNodes.count(SDValue(N, 0))) return false; |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 464 | break; |
| 465 | } |
| 466 | |
| 467 | // Okay, this node has not already been legalized. Check and legalize all |
| 468 | // operands. If none lead to Dest, then we can legalize this node. |
| 469 | bool OperandsLeadToDest = false; |
| 470 | for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) |
| 471 | OperandsLeadToDest |= // If an operand leads to Dest, so do we. |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 472 | LegalizeAllNodesNotLeadingTo(N->getOperand(i).getNode(), Dest, NodesLeadingTo); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 473 | |
Chris Lattner | c9cf4f1 | 2006-07-26 23:55:56 +0000 | [diff] [blame] | 474 | if (OperandsLeadToDest) { |
| 475 | NodesLeadingTo.insert(N); |
| 476 | return true; |
| 477 | } |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 478 | |
| 479 | // Okay, this node looks safe, legalize it and return false. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 480 | HandleOp(SDValue(N, 0)); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 481 | return false; |
| 482 | } |
| 483 | |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 484 | /// HandleOp - Legalize, Promote, Widen, or Expand the specified operand as |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 485 | /// appropriate for its type. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 486 | void SelectionDAGLegalize::HandleOp(SDValue Op) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 487 | MVT VT = Op.getValueType(); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 488 | switch (getTypeAction(VT)) { |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 489 | default: assert(0 && "Bad type action!"); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 490 | case Legal: (void)LegalizeOp(Op); break; |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 491 | case Promote: |
| 492 | if (!VT.isVector()) { |
| 493 | (void)PromoteOp(Op); |
| 494 | break; |
| 495 | } |
| 496 | else { |
| 497 | // See if we can widen otherwise use Expand to either scalarize or split |
| 498 | MVT WidenVT = TLI.getWidenVectorType(VT); |
| 499 | if (WidenVT != MVT::Other) { |
| 500 | (void) WidenVectorOp(Op, WidenVT); |
| 501 | break; |
| 502 | } |
| 503 | // else fall thru to expand since we can't widen the vector |
| 504 | } |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 505 | case Expand: |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 506 | if (!VT.isVector()) { |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 507 | // If this is an illegal scalar, expand it into its two component |
| 508 | // pieces. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 509 | SDValue X, Y; |
Chris Lattner | 09ec1b0 | 2007-08-25 01:00:22 +0000 | [diff] [blame] | 510 | if (Op.getOpcode() == ISD::TargetConstant) |
| 511 | break; // Allow illegal target nodes. |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 512 | ExpandOp(Op, X, Y); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 513 | } else if (VT.getVectorNumElements() == 1) { |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 514 | // If this is an illegal single element vector, convert it to a |
| 515 | // scalar operation. |
| 516 | (void)ScalarizeVectorOp(Op); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 517 | } else { |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 518 | // This is an illegal multiple element vector. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 519 | // Split it in half and legalize both parts. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 520 | SDValue X, Y; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 521 | SplitVectorOp(Op, X, Y); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 522 | } |
| 523 | break; |
| 524 | } |
| 525 | } |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 526 | |
Evan Cheng | 9f87788 | 2006-12-13 20:57:08 +0000 | [diff] [blame] | 527 | /// ExpandConstantFP - Expands the ConstantFP node to an integer constant or |
| 528 | /// a load from the constant pool. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 529 | static SDValue ExpandConstantFP(ConstantFPSDNode *CFP, bool UseCP, |
Evan Cheng | 279101e | 2006-12-12 22:19:28 +0000 | [diff] [blame] | 530 | SelectionDAG &DAG, TargetLowering &TLI) { |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 531 | bool Extend = false; |
| 532 | |
| 533 | // If a FP immediate is precise when represented as a float and if the |
| 534 | // target can do an extending load from float to double, we put it into |
| 535 | // the constant pool as a float, even if it's is statically typed as a |
Chris Lattner | aa2acbb | 2008-03-05 06:46:58 +0000 | [diff] [blame] | 536 | // double. This shrinks FP constants and canonicalizes them for targets where |
| 537 | // an FP extending load is the same cost as a normal load (such as on the x87 |
| 538 | // fp stack or PPC FP unit). |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 539 | MVT VT = CFP->getValueType(0); |
Dan Gohman | 4fbd796 | 2008-09-12 18:08:03 +0000 | [diff] [blame] | 540 | ConstantFP *LLVMC = const_cast<ConstantFP*>(CFP->getConstantFPValue()); |
Evan Cheng | 9f87788 | 2006-12-13 20:57:08 +0000 | [diff] [blame] | 541 | if (!UseCP) { |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 542 | if (VT!=MVT::f64 && VT!=MVT::f32) |
| 543 | assert(0 && "Invalid type expansion"); |
Dale Johannesen | 7111b02 | 2008-10-09 18:53:47 +0000 | [diff] [blame] | 544 | return DAG.getConstant(LLVMC->getValueAPF().bitcastToAPInt(), |
Evan Cheng | ef12057 | 2008-03-04 08:05:30 +0000 | [diff] [blame] | 545 | (VT == MVT::f64) ? MVT::i64 : MVT::i32); |
Evan Cheng | 279101e | 2006-12-12 22:19:28 +0000 | [diff] [blame] | 546 | } |
| 547 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 548 | MVT OrigVT = VT; |
| 549 | MVT SVT = VT; |
Evan Cheng | ef12057 | 2008-03-04 08:05:30 +0000 | [diff] [blame] | 550 | while (SVT != MVT::f32) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 551 | SVT = (MVT::SimpleValueType)(SVT.getSimpleVT() - 1); |
Evan Cheng | ef12057 | 2008-03-04 08:05:30 +0000 | [diff] [blame] | 552 | if (CFP->isValueValidForType(SVT, CFP->getValueAPF()) && |
| 553 | // Only do this if the target has a native EXTLOAD instruction from |
| 554 | // smaller type. |
Evan Cheng | 0329466 | 2008-10-14 21:26:46 +0000 | [diff] [blame] | 555 | TLI.isLoadExtLegal(ISD::EXTLOAD, SVT) && |
Chris Lattner | aa2acbb | 2008-03-05 06:46:58 +0000 | [diff] [blame] | 556 | TLI.ShouldShrinkFPConstant(OrigVT)) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 557 | const Type *SType = SVT.getTypeForMVT(); |
Evan Cheng | ef12057 | 2008-03-04 08:05:30 +0000 | [diff] [blame] | 558 | LLVMC = cast<ConstantFP>(ConstantExpr::getFPTrunc(LLVMC, SType)); |
| 559 | VT = SVT; |
| 560 | Extend = true; |
| 561 | } |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 562 | } |
| 563 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 564 | SDValue CPIdx = DAG.getConstantPool(LLVMC, TLI.getPointerTy()); |
Dan Gohman | 50284d8 | 2008-09-16 22:05:41 +0000 | [diff] [blame] | 565 | unsigned Alignment = 1 << cast<ConstantPoolSDNode>(CPIdx)->getAlignment(); |
Evan Cheng | ef12057 | 2008-03-04 08:05:30 +0000 | [diff] [blame] | 566 | if (Extend) |
| 567 | return DAG.getExtLoad(ISD::EXTLOAD, OrigVT, DAG.getEntryNode(), |
Dan Gohman | 3069b87 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 568 | CPIdx, PseudoSourceValue::getConstantPool(), |
Dan Gohman | 50284d8 | 2008-09-16 22:05:41 +0000 | [diff] [blame] | 569 | 0, VT, false, Alignment); |
Evan Cheng | ef12057 | 2008-03-04 08:05:30 +0000 | [diff] [blame] | 570 | return DAG.getLoad(OrigVT, DAG.getEntryNode(), CPIdx, |
Dan Gohman | 50284d8 | 2008-09-16 22:05:41 +0000 | [diff] [blame] | 571 | PseudoSourceValue::getConstantPool(), 0, false, Alignment); |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 572 | } |
| 573 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 574 | |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 575 | /// ExpandFCOPYSIGNToBitwiseOps - Expands fcopysign to a series of bitwise |
| 576 | /// operations. |
| 577 | static |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 578 | SDValue ExpandFCOPYSIGNToBitwiseOps(SDNode *Node, MVT NVT, |
| 579 | SelectionDAG &DAG, TargetLowering &TLI) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 580 | MVT VT = Node->getValueType(0); |
| 581 | MVT SrcVT = Node->getOperand(1).getValueType(); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 582 | assert((SrcVT == MVT::f32 || SrcVT == MVT::f64) && |
| 583 | "fcopysign expansion only supported for f32 and f64"); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 584 | MVT SrcNVT = (SrcVT == MVT::f64) ? MVT::i64 : MVT::i32; |
Evan Cheng | 068c5f4 | 2007-01-05 21:31:51 +0000 | [diff] [blame] | 585 | |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 586 | // First get the sign bit of second operand. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 587 | SDValue Mask1 = (SrcVT == MVT::f64) |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 588 | ? DAG.getConstantFP(BitsToDouble(1ULL << 63), SrcVT) |
| 589 | : DAG.getConstantFP(BitsToFloat(1U << 31), SrcVT); |
Evan Cheng | 068c5f4 | 2007-01-05 21:31:51 +0000 | [diff] [blame] | 590 | Mask1 = DAG.getNode(ISD::BIT_CONVERT, SrcNVT, Mask1); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 591 | SDValue SignBit= DAG.getNode(ISD::BIT_CONVERT, SrcNVT, Node->getOperand(1)); |
Evan Cheng | 068c5f4 | 2007-01-05 21:31:51 +0000 | [diff] [blame] | 592 | SignBit = DAG.getNode(ISD::AND, SrcNVT, SignBit, Mask1); |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 593 | // Shift right or sign-extend it if the two operands have different types. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 594 | int SizeDiff = SrcNVT.getSizeInBits() - NVT.getSizeInBits(); |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 595 | if (SizeDiff > 0) { |
| 596 | SignBit = DAG.getNode(ISD::SRL, SrcNVT, SignBit, |
| 597 | DAG.getConstant(SizeDiff, TLI.getShiftAmountTy())); |
| 598 | SignBit = DAG.getNode(ISD::TRUNCATE, NVT, SignBit); |
Chris Lattner | c563e1d | 2008-07-10 23:46:13 +0000 | [diff] [blame] | 599 | } else if (SizeDiff < 0) { |
| 600 | SignBit = DAG.getNode(ISD::ZERO_EXTEND, NVT, SignBit); |
| 601 | SignBit = DAG.getNode(ISD::SHL, NVT, SignBit, |
| 602 | DAG.getConstant(-SizeDiff, TLI.getShiftAmountTy())); |
| 603 | } |
Evan Cheng | 068c5f4 | 2007-01-05 21:31:51 +0000 | [diff] [blame] | 604 | |
| 605 | // Clear the sign bit of first operand. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 606 | SDValue Mask2 = (VT == MVT::f64) |
Evan Cheng | 068c5f4 | 2007-01-05 21:31:51 +0000 | [diff] [blame] | 607 | ? DAG.getConstantFP(BitsToDouble(~(1ULL << 63)), VT) |
| 608 | : DAG.getConstantFP(BitsToFloat(~(1U << 31)), VT); |
| 609 | Mask2 = DAG.getNode(ISD::BIT_CONVERT, NVT, Mask2); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 610 | SDValue Result = DAG.getNode(ISD::BIT_CONVERT, NVT, Node->getOperand(0)); |
Evan Cheng | 068c5f4 | 2007-01-05 21:31:51 +0000 | [diff] [blame] | 611 | Result = DAG.getNode(ISD::AND, NVT, Result, Mask2); |
| 612 | |
| 613 | // Or the value with the sign bit. |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 614 | Result = DAG.getNode(ISD::OR, NVT, Result, SignBit); |
| 615 | return Result; |
| 616 | } |
| 617 | |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 618 | /// ExpandUnalignedStore - Expands an unaligned store to 2 half-size stores. |
| 619 | static |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 620 | SDValue ExpandUnalignedStore(StoreSDNode *ST, SelectionDAG &DAG, |
| 621 | TargetLowering &TLI) { |
| 622 | SDValue Chain = ST->getChain(); |
| 623 | SDValue Ptr = ST->getBasePtr(); |
| 624 | SDValue Val = ST->getValue(); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 625 | MVT VT = Val.getValueType(); |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 626 | int Alignment = ST->getAlignment(); |
| 627 | int SVOffset = ST->getSrcValueOffset(); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 628 | if (ST->getMemoryVT().isFloatingPoint() || |
| 629 | ST->getMemoryVT().isVector()) { |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 630 | // Expand to a bitconvert of the value to the integer type of the |
| 631 | // same size, then a (misaligned) int store. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 632 | MVT intVT; |
| 633 | if (VT.is128BitVector() || VT == MVT::ppcf128 || VT == MVT::f128) |
Dale Johannesen | 8155d64 | 2008-02-27 22:36:00 +0000 | [diff] [blame] | 634 | intVT = MVT::i128; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 635 | else if (VT.is64BitVector() || VT==MVT::f64) |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 636 | intVT = MVT::i64; |
| 637 | else if (VT==MVT::f32) |
| 638 | intVT = MVT::i32; |
| 639 | else |
Dale Johannesen | cd9f174 | 2008-02-28 18:36:51 +0000 | [diff] [blame] | 640 | assert(0 && "Unaligned store of unsupported type"); |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 641 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 642 | SDValue Result = DAG.getNode(ISD::BIT_CONVERT, intVT, Val); |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 643 | return DAG.getStore(Chain, Result, Ptr, ST->getSrcValue(), |
| 644 | SVOffset, ST->isVolatile(), Alignment); |
| 645 | } |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 646 | assert(ST->getMemoryVT().isInteger() && |
| 647 | !ST->getMemoryVT().isVector() && |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 648 | "Unaligned store of unknown type."); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 649 | // Get the half-size VT |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 650 | MVT NewStoredVT = |
| 651 | (MVT::SimpleValueType)(ST->getMemoryVT().getSimpleVT() - 1); |
| 652 | int NumBits = NewStoredVT.getSizeInBits(); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 653 | int IncrementSize = NumBits / 8; |
| 654 | |
| 655 | // Divide the stored value in two parts. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 656 | SDValue ShiftAmount = DAG.getConstant(NumBits, TLI.getShiftAmountTy()); |
| 657 | SDValue Lo = Val; |
| 658 | SDValue Hi = DAG.getNode(ISD::SRL, VT, Val, ShiftAmount); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 659 | |
| 660 | // Store the two parts |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 661 | SDValue Store1, Store2; |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 662 | Store1 = DAG.getTruncStore(Chain, TLI.isLittleEndian()?Lo:Hi, Ptr, |
| 663 | ST->getSrcValue(), SVOffset, NewStoredVT, |
| 664 | ST->isVolatile(), Alignment); |
| 665 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
| 666 | DAG.getConstant(IncrementSize, TLI.getPointerTy())); |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 667 | Alignment = MinAlign(Alignment, IncrementSize); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 668 | Store2 = DAG.getTruncStore(Chain, TLI.isLittleEndian()?Hi:Lo, Ptr, |
| 669 | ST->getSrcValue(), SVOffset + IncrementSize, |
| 670 | NewStoredVT, ST->isVolatile(), Alignment); |
| 671 | |
| 672 | return DAG.getNode(ISD::TokenFactor, MVT::Other, Store1, Store2); |
| 673 | } |
| 674 | |
| 675 | /// ExpandUnalignedLoad - Expands an unaligned load to 2 half-size loads. |
| 676 | static |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 677 | SDValue ExpandUnalignedLoad(LoadSDNode *LD, SelectionDAG &DAG, |
| 678 | TargetLowering &TLI) { |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 679 | int SVOffset = LD->getSrcValueOffset(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 680 | SDValue Chain = LD->getChain(); |
| 681 | SDValue Ptr = LD->getBasePtr(); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 682 | MVT VT = LD->getValueType(0); |
| 683 | MVT LoadedVT = LD->getMemoryVT(); |
| 684 | if (VT.isFloatingPoint() || VT.isVector()) { |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 685 | // Expand to a (misaligned) integer load of the same size, |
Dale Johannesen | 8155d64 | 2008-02-27 22:36:00 +0000 | [diff] [blame] | 686 | // then bitconvert to floating point or vector. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 687 | MVT intVT; |
| 688 | if (LoadedVT.is128BitVector() || |
Dale Johannesen | 3c8b59c | 2008-03-01 03:40:57 +0000 | [diff] [blame] | 689 | LoadedVT == MVT::ppcf128 || LoadedVT == MVT::f128) |
Dale Johannesen | 8155d64 | 2008-02-27 22:36:00 +0000 | [diff] [blame] | 690 | intVT = MVT::i128; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 691 | else if (LoadedVT.is64BitVector() || LoadedVT == MVT::f64) |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 692 | intVT = MVT::i64; |
Chris Lattner | e400af8 | 2007-11-19 21:38:03 +0000 | [diff] [blame] | 693 | else if (LoadedVT == MVT::f32) |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 694 | intVT = MVT::i32; |
| 695 | else |
Dale Johannesen | 8155d64 | 2008-02-27 22:36:00 +0000 | [diff] [blame] | 696 | assert(0 && "Unaligned load of unsupported type"); |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 697 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 698 | SDValue newLoad = DAG.getLoad(intVT, Chain, Ptr, LD->getSrcValue(), |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 699 | SVOffset, LD->isVolatile(), |
| 700 | LD->getAlignment()); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 701 | SDValue Result = DAG.getNode(ISD::BIT_CONVERT, LoadedVT, newLoad); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 702 | if (VT.isFloatingPoint() && LoadedVT != VT) |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 703 | Result = DAG.getNode(ISD::FP_EXTEND, VT, Result); |
| 704 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 705 | SDValue Ops[] = { Result, Chain }; |
Duncan Sands | 4bdcb61 | 2008-07-02 17:40:58 +0000 | [diff] [blame] | 706 | return DAG.getMergeValues(Ops, 2); |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 707 | } |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 708 | assert(LoadedVT.isInteger() && !LoadedVT.isVector() && |
Chris Lattner | e400af8 | 2007-11-19 21:38:03 +0000 | [diff] [blame] | 709 | "Unaligned load of unsupported type."); |
| 710 | |
Dale Johannesen | 8155d64 | 2008-02-27 22:36:00 +0000 | [diff] [blame] | 711 | // Compute the new VT that is half the size of the old one. This is an |
| 712 | // integer MVT. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 713 | unsigned NumBits = LoadedVT.getSizeInBits(); |
| 714 | MVT NewLoadedVT; |
| 715 | NewLoadedVT = MVT::getIntegerVT(NumBits/2); |
Chris Lattner | e400af8 | 2007-11-19 21:38:03 +0000 | [diff] [blame] | 716 | NumBits >>= 1; |
| 717 | |
| 718 | unsigned Alignment = LD->getAlignment(); |
| 719 | unsigned IncrementSize = NumBits / 8; |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 720 | ISD::LoadExtType HiExtType = LD->getExtensionType(); |
| 721 | |
| 722 | // If the original load is NON_EXTLOAD, the hi part load must be ZEXTLOAD. |
| 723 | if (HiExtType == ISD::NON_EXTLOAD) |
| 724 | HiExtType = ISD::ZEXTLOAD; |
| 725 | |
| 726 | // Load the value in two parts |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 727 | SDValue Lo, Hi; |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 728 | if (TLI.isLittleEndian()) { |
| 729 | Lo = DAG.getExtLoad(ISD::ZEXTLOAD, VT, Chain, Ptr, LD->getSrcValue(), |
| 730 | SVOffset, NewLoadedVT, LD->isVolatile(), Alignment); |
| 731 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
| 732 | DAG.getConstant(IncrementSize, TLI.getPointerTy())); |
| 733 | Hi = DAG.getExtLoad(HiExtType, VT, Chain, Ptr, LD->getSrcValue(), |
| 734 | SVOffset + IncrementSize, NewLoadedVT, LD->isVolatile(), |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 735 | MinAlign(Alignment, IncrementSize)); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 736 | } else { |
| 737 | Hi = DAG.getExtLoad(HiExtType, VT, Chain, Ptr, LD->getSrcValue(), SVOffset, |
| 738 | NewLoadedVT,LD->isVolatile(), Alignment); |
| 739 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
| 740 | DAG.getConstant(IncrementSize, TLI.getPointerTy())); |
| 741 | Lo = DAG.getExtLoad(ISD::ZEXTLOAD, VT, Chain, Ptr, LD->getSrcValue(), |
| 742 | SVOffset + IncrementSize, NewLoadedVT, LD->isVolatile(), |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 743 | MinAlign(Alignment, IncrementSize)); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | // aggregate the two parts |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 747 | SDValue ShiftAmount = DAG.getConstant(NumBits, TLI.getShiftAmountTy()); |
| 748 | SDValue Result = DAG.getNode(ISD::SHL, VT, Hi, ShiftAmount); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 749 | Result = DAG.getNode(ISD::OR, VT, Result, Lo); |
| 750 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 751 | SDValue TF = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1), |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 752 | Hi.getValue(1)); |
| 753 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 754 | SDValue Ops[] = { Result, TF }; |
Duncan Sands | 4bdcb61 | 2008-07-02 17:40:58 +0000 | [diff] [blame] | 755 | return DAG.getMergeValues(Ops, 2); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 756 | } |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 757 | |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 758 | /// UnrollVectorOp - We know that the given vector has a legal type, however |
| 759 | /// the operation it performs is not legal and is an operation that we have |
| 760 | /// no way of lowering. "Unroll" the vector, splitting out the scalars and |
| 761 | /// operating on each element individually. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 762 | SDValue SelectionDAGLegalize::UnrollVectorOp(SDValue Op) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 763 | MVT VT = Op.getValueType(); |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 764 | assert(isTypeLegal(VT) && |
| 765 | "Caller should expand or promote operands that are not legal!"); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 766 | assert(Op.getNode()->getNumValues() == 1 && |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 767 | "Can't unroll a vector with multiple results!"); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 768 | unsigned NE = VT.getVectorNumElements(); |
| 769 | MVT EltVT = VT.getVectorElementType(); |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 770 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 771 | SmallVector<SDValue, 8> Scalars; |
| 772 | SmallVector<SDValue, 4> Operands(Op.getNumOperands()); |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 773 | for (unsigned i = 0; i != NE; ++i) { |
| 774 | for (unsigned j = 0; j != Op.getNumOperands(); ++j) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 775 | SDValue Operand = Op.getOperand(j); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 776 | MVT OperandVT = Operand.getValueType(); |
| 777 | if (OperandVT.isVector()) { |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 778 | // A vector operand; extract a single element. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 779 | MVT OperandEltVT = OperandVT.getVectorElementType(); |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 780 | Operands[j] = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, |
| 781 | OperandEltVT, |
| 782 | Operand, |
| 783 | DAG.getConstant(i, MVT::i32)); |
| 784 | } else { |
| 785 | // A scalar operand; just use it as is. |
| 786 | Operands[j] = Operand; |
| 787 | } |
| 788 | } |
| 789 | Scalars.push_back(DAG.getNode(Op.getOpcode(), EltVT, |
| 790 | &Operands[0], Operands.size())); |
| 791 | } |
| 792 | |
| 793 | return DAG.getNode(ISD::BUILD_VECTOR, VT, &Scalars[0], Scalars.size()); |
| 794 | } |
| 795 | |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 796 | /// GetFPLibCall - Return the right libcall for the given floating point type. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 797 | static RTLIB::Libcall GetFPLibCall(MVT VT, |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 798 | RTLIB::Libcall Call_F32, |
| 799 | RTLIB::Libcall Call_F64, |
| 800 | RTLIB::Libcall Call_F80, |
| 801 | RTLIB::Libcall Call_PPCF128) { |
| 802 | return |
| 803 | VT == MVT::f32 ? Call_F32 : |
| 804 | VT == MVT::f64 ? Call_F64 : |
| 805 | VT == MVT::f80 ? Call_F80 : |
| 806 | VT == MVT::ppcf128 ? Call_PPCF128 : |
| 807 | RTLIB::UNKNOWN_LIBCALL; |
| 808 | } |
| 809 | |
Nate Begeman | 6867991 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 810 | /// PerformInsertVectorEltInMemory - Some target cannot handle a variable |
| 811 | /// insertion index for the INSERT_VECTOR_ELT instruction. In this case, it |
| 812 | /// is necessary to spill the vector being inserted into to memory, perform |
| 813 | /// the insert there, and then read the result back. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 814 | SDValue SelectionDAGLegalize:: |
| 815 | PerformInsertVectorEltInMemory(SDValue Vec, SDValue Val, SDValue Idx) { |
| 816 | SDValue Tmp1 = Vec; |
| 817 | SDValue Tmp2 = Val; |
| 818 | SDValue Tmp3 = Idx; |
Nate Begeman | 6867991 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 819 | |
| 820 | // If the target doesn't support this, we have to spill the input vector |
| 821 | // to a temporary stack slot, update the element, then reload it. This is |
| 822 | // badness. We could also load the value into a vector register (either |
| 823 | // with a "move to register" or "extload into register" instruction, then |
| 824 | // permute it into place, if the idx is a constant and if the idx is |
| 825 | // supported by the target. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 826 | MVT VT = Tmp1.getValueType(); |
| 827 | MVT EltVT = VT.getVectorElementType(); |
| 828 | MVT IdxVT = Tmp3.getValueType(); |
| 829 | MVT PtrVT = TLI.getPointerTy(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 830 | SDValue StackPtr = DAG.CreateStackTemporary(VT); |
Nate Begeman | 6867991 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 831 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 832 | int SPFI = cast<FrameIndexSDNode>(StackPtr.getNode())->getIndex(); |
Nate Begeman | 6867991 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 833 | |
| 834 | // Store the vector. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 835 | SDValue Ch = DAG.getStore(DAG.getEntryNode(), Tmp1, StackPtr, |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 836 | PseudoSourceValue::getFixedStack(SPFI), 0); |
Nate Begeman | 6867991 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 837 | |
| 838 | // Truncate or zero extend offset to target pointer type. |
Duncan Sands | 8e4eb09 | 2008-06-08 20:54:56 +0000 | [diff] [blame] | 839 | unsigned CastOpc = IdxVT.bitsGT(PtrVT) ? ISD::TRUNCATE : ISD::ZERO_EXTEND; |
Nate Begeman | 6867991 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 840 | Tmp3 = DAG.getNode(CastOpc, PtrVT, Tmp3); |
| 841 | // Add the offset to the index. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 842 | unsigned EltSize = EltVT.getSizeInBits()/8; |
Nate Begeman | 6867991 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 843 | Tmp3 = DAG.getNode(ISD::MUL, IdxVT, Tmp3,DAG.getConstant(EltSize, IdxVT)); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 844 | SDValue StackPtr2 = DAG.getNode(ISD::ADD, IdxVT, Tmp3, StackPtr); |
Nate Begeman | 6867991 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 845 | // Store the scalar value. |
| 846 | Ch = DAG.getTruncStore(Ch, Tmp2, StackPtr2, |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 847 | PseudoSourceValue::getFixedStack(SPFI), 0, EltVT); |
Nate Begeman | 6867991 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 848 | // Load the updated vector. |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 849 | return DAG.getLoad(VT, Ch, StackPtr, |
| 850 | PseudoSourceValue::getFixedStack(SPFI), 0); |
Nate Begeman | 6867991 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 851 | } |
| 852 | |
Dan Gohman | a346615 | 2007-07-13 20:14:11 +0000 | [diff] [blame] | 853 | /// LegalizeOp - We know that the specified value has a legal type, and |
| 854 | /// that its operands are legal. Now ensure that the operation itself |
| 855 | /// is legal, recursively ensuring that the operands' operations remain |
| 856 | /// legal. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 857 | SDValue SelectionDAGLegalize::LegalizeOp(SDValue Op) { |
Chris Lattner | 09ec1b0 | 2007-08-25 01:00:22 +0000 | [diff] [blame] | 858 | if (Op.getOpcode() == ISD::TargetConstant) // Allow illegal target nodes. |
| 859 | return Op; |
| 860 | |
Chris Lattner | c9c60f6 | 2005-08-24 16:35:28 +0000 | [diff] [blame] | 861 | assert(isTypeLegal(Op.getValueType()) && |
Chris Lattner | e3304a3 | 2005-01-08 20:35:13 +0000 | [diff] [blame] | 862 | "Caller should expand or promote operands that are not legal!"); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 863 | SDNode *Node = Op.getNode(); |
Chris Lattner | e3304a3 | 2005-01-08 20:35:13 +0000 | [diff] [blame] | 864 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 865 | // If this operation defines any values that cannot be represented in a |
Chris Lattner | e3304a3 | 2005-01-08 20:35:13 +0000 | [diff] [blame] | 866 | // register on this target, make sure to expand or promote them. |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 867 | if (Node->getNumValues() > 1) { |
| 868 | for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 869 | if (getTypeAction(Node->getValueType(i)) != Legal) { |
| 870 | HandleOp(Op.getValue(i)); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 871 | assert(LegalizedNodes.count(Op) && |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 872 | "Handling didn't add legal operands!"); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 873 | return LegalizedNodes[Op]; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 874 | } |
| 875 | } |
| 876 | |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 877 | // Note that LegalizeOp may be reentered even from single-use nodes, which |
| 878 | // means that we always must cache transformed nodes. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 879 | DenseMap<SDValue, SDValue>::iterator I = LegalizedNodes.find(Op); |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 880 | if (I != LegalizedNodes.end()) return I->second; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 881 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 882 | SDValue Tmp1, Tmp2, Tmp3, Tmp4; |
| 883 | SDValue Result = Op; |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 884 | bool isCustom = false; |
| 885 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 886 | switch (Node->getOpcode()) { |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 887 | case ISD::FrameIndex: |
| 888 | case ISD::EntryToken: |
| 889 | case ISD::Register: |
| 890 | case ISD::BasicBlock: |
| 891 | case ISD::TargetFrameIndex: |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 892 | case ISD::TargetJumpTable: |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 893 | case ISD::TargetConstant: |
Chris Lattner | 3181a77 | 2006-01-29 06:26:56 +0000 | [diff] [blame] | 894 | case ISD::TargetConstantFP: |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 895 | case ISD::TargetConstantPool: |
| 896 | case ISD::TargetGlobalAddress: |
Lauro Ramos Venancio | b3a0417 | 2007-04-20 21:38:10 +0000 | [diff] [blame] | 897 | case ISD::TargetGlobalTLSAddress: |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 898 | case ISD::TargetExternalSymbol: |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 899 | case ISD::VALUETYPE: |
| 900 | case ISD::SRCVALUE: |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 901 | case ISD::MEMOPERAND: |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 902 | case ISD::CONDCODE: |
Duncan Sands | 276dcbd | 2008-03-21 09:14:45 +0000 | [diff] [blame] | 903 | case ISD::ARG_FLAGS: |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 904 | // Primitives must all be legal. |
Duncan Sands | a7c97a7 | 2007-10-16 09:07:20 +0000 | [diff] [blame] | 905 | assert(TLI.isOperationLegal(Node->getOpcode(), Node->getValueType(0)) && |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 906 | "This must be legal!"); |
| 907 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 908 | default: |
Chris Lattner | d73cc5d | 2005-05-14 06:34:48 +0000 | [diff] [blame] | 909 | if (Node->getOpcode() >= ISD::BUILTIN_OP_END) { |
| 910 | // If this is a target node, legalize it by legalizing the operands then |
| 911 | // passing it through. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 912 | SmallVector<SDValue, 8> Ops; |
Chris Lattner | c5d7d7c | 2006-05-17 18:00:08 +0000 | [diff] [blame] | 913 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) |
Chris Lattner | d73cc5d | 2005-05-14 06:34:48 +0000 | [diff] [blame] | 914 | Ops.push_back(LegalizeOp(Node->getOperand(i))); |
Chris Lattner | c5d7d7c | 2006-05-17 18:00:08 +0000 | [diff] [blame] | 915 | |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 916 | Result = DAG.UpdateNodeOperands(Result.getValue(0), &Ops[0], Ops.size()); |
Chris Lattner | d73cc5d | 2005-05-14 06:34:48 +0000 | [diff] [blame] | 917 | |
| 918 | for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) |
| 919 | AddLegalizedOperand(Op.getValue(i), Result.getValue(i)); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 920 | return Result.getValue(Op.getResNo()); |
Chris Lattner | d73cc5d | 2005-05-14 06:34:48 +0000 | [diff] [blame] | 921 | } |
| 922 | // Otherwise this is an unhandled builtin node. splat. |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 923 | #ifndef NDEBUG |
Dan Gohman | 3983358 | 2007-06-04 16:17:33 +0000 | [diff] [blame] | 924 | cerr << "NODE: "; Node->dump(&DAG); cerr << "\n"; |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 925 | #endif |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 926 | assert(0 && "Do not know how to legalize this operator!"); |
| 927 | abort(); |
Lauro Ramos Venancio | 0d3b678 | 2007-04-20 23:02:39 +0000 | [diff] [blame] | 928 | case ISD::GLOBAL_OFFSET_TABLE: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 929 | case ISD::GlobalAddress: |
Lauro Ramos Venancio | b3a0417 | 2007-04-20 21:38:10 +0000 | [diff] [blame] | 930 | case ISD::GlobalTLSAddress: |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 931 | case ISD::ExternalSymbol: |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 932 | case ISD::ConstantPool: |
| 933 | case ISD::JumpTable: // Nothing to do. |
Chris Lattner | 0c8fbe3 | 2005-11-17 06:41:44 +0000 | [diff] [blame] | 934 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 935 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 936 | case TargetLowering::Custom: |
| 937 | Tmp1 = TLI.LowerOperation(Op, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 938 | if (Tmp1.getNode()) Result = Tmp1; |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 939 | // 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] | 940 | case TargetLowering::Legal: |
Chris Lattner | 0c8fbe3 | 2005-11-17 06:41:44 +0000 | [diff] [blame] | 941 | break; |
| 942 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 943 | break; |
Nate Begeman | bcc5f36 | 2007-01-29 22:58:52 +0000 | [diff] [blame] | 944 | case ISD::FRAMEADDR: |
| 945 | case ISD::RETURNADDR: |
| 946 | // The only option for these nodes is to custom lower them. If the target |
| 947 | // does not custom lower them, then return zero. |
| 948 | Tmp1 = TLI.LowerOperation(Op, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 949 | if (Tmp1.getNode()) |
Nate Begeman | bcc5f36 | 2007-01-29 22:58:52 +0000 | [diff] [blame] | 950 | Result = Tmp1; |
| 951 | else |
| 952 | Result = DAG.getConstant(0, TLI.getPointerTy()); |
| 953 | break; |
Anton Korobeynikov | 055c544 | 2007-08-29 23:18:48 +0000 | [diff] [blame] | 954 | case ISD::FRAME_TO_ARGS_OFFSET: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 955 | MVT VT = Node->getValueType(0); |
Anton Korobeynikov | 066f7b4 | 2007-08-29 19:28:29 +0000 | [diff] [blame] | 956 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 957 | default: assert(0 && "This action is not supported yet!"); |
| 958 | case TargetLowering::Custom: |
| 959 | Result = TLI.LowerOperation(Op, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 960 | if (Result.getNode()) break; |
Anton Korobeynikov | 066f7b4 | 2007-08-29 19:28:29 +0000 | [diff] [blame] | 961 | // Fall Thru |
| 962 | case TargetLowering::Legal: |
| 963 | Result = DAG.getConstant(0, VT); |
| 964 | break; |
| 965 | } |
Anton Korobeynikov | 055c544 | 2007-08-29 23:18:48 +0000 | [diff] [blame] | 966 | } |
Anton Korobeynikov | 066f7b4 | 2007-08-29 19:28:29 +0000 | [diff] [blame] | 967 | break; |
Jim Laskey | 2bc210d | 2007-02-22 15:37:19 +0000 | [diff] [blame] | 968 | case ISD::EXCEPTIONADDR: { |
| 969 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 970 | MVT VT = Node->getValueType(0); |
Jim Laskey | 2bc210d | 2007-02-22 15:37:19 +0000 | [diff] [blame] | 971 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 972 | default: assert(0 && "This action is not supported yet!"); |
| 973 | case TargetLowering::Expand: { |
Jim Laskey | 8782d48 | 2007-02-28 20:43:58 +0000 | [diff] [blame] | 974 | unsigned Reg = TLI.getExceptionAddressRegister(); |
Duncan Sands | b027fa0 | 2007-12-31 18:35:50 +0000 | [diff] [blame] | 975 | Result = DAG.getCopyFromReg(Tmp1, Reg, VT); |
Jim Laskey | 2bc210d | 2007-02-22 15:37:19 +0000 | [diff] [blame] | 976 | } |
| 977 | break; |
| 978 | case TargetLowering::Custom: |
| 979 | Result = TLI.LowerOperation(Op, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 980 | if (Result.getNode()) break; |
Jim Laskey | 2bc210d | 2007-02-22 15:37:19 +0000 | [diff] [blame] | 981 | // Fall Thru |
Chris Lattner | eb7f34f | 2007-04-27 17:12:52 +0000 | [diff] [blame] | 982 | case TargetLowering::Legal: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 983 | SDValue Ops[] = { DAG.getConstant(0, VT), Tmp1 }; |
Duncan Sands | 4bdcb61 | 2008-07-02 17:40:58 +0000 | [diff] [blame] | 984 | Result = DAG.getMergeValues(Ops, 2); |
Jim Laskey | 2bc210d | 2007-02-22 15:37:19 +0000 | [diff] [blame] | 985 | break; |
| 986 | } |
| 987 | } |
Chris Lattner | eb7f34f | 2007-04-27 17:12:52 +0000 | [diff] [blame] | 988 | } |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 989 | if (Result.getNode()->getNumValues() == 1) break; |
Duncan Sands | b027fa0 | 2007-12-31 18:35:50 +0000 | [diff] [blame] | 990 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 991 | assert(Result.getNode()->getNumValues() == 2 && |
Duncan Sands | b027fa0 | 2007-12-31 18:35:50 +0000 | [diff] [blame] | 992 | "Cannot return more than two values!"); |
| 993 | |
| 994 | // Since we produced two values, make sure to remember that we |
| 995 | // legalized both of them. |
| 996 | Tmp1 = LegalizeOp(Result); |
| 997 | Tmp2 = LegalizeOp(Result.getValue(1)); |
| 998 | AddLegalizedOperand(Op.getValue(0), Tmp1); |
| 999 | AddLegalizedOperand(Op.getValue(1), Tmp2); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 1000 | return Op.getResNo() ? Tmp2 : Tmp1; |
Jim Laskey | 8782d48 | 2007-02-28 20:43:58 +0000 | [diff] [blame] | 1001 | case ISD::EHSELECTION: { |
| 1002 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1003 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1004 | MVT VT = Node->getValueType(0); |
Jim Laskey | 8782d48 | 2007-02-28 20:43:58 +0000 | [diff] [blame] | 1005 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 1006 | default: assert(0 && "This action is not supported yet!"); |
| 1007 | case TargetLowering::Expand: { |
| 1008 | unsigned Reg = TLI.getExceptionSelectorRegister(); |
Duncan Sands | b027fa0 | 2007-12-31 18:35:50 +0000 | [diff] [blame] | 1009 | Result = DAG.getCopyFromReg(Tmp2, Reg, VT); |
Jim Laskey | 8782d48 | 2007-02-28 20:43:58 +0000 | [diff] [blame] | 1010 | } |
| 1011 | break; |
| 1012 | case TargetLowering::Custom: |
| 1013 | Result = TLI.LowerOperation(Op, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1014 | if (Result.getNode()) break; |
Jim Laskey | 8782d48 | 2007-02-28 20:43:58 +0000 | [diff] [blame] | 1015 | // Fall Thru |
Chris Lattner | eb7f34f | 2007-04-27 17:12:52 +0000 | [diff] [blame] | 1016 | case TargetLowering::Legal: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1017 | SDValue Ops[] = { DAG.getConstant(0, VT), Tmp2 }; |
Duncan Sands | 4bdcb61 | 2008-07-02 17:40:58 +0000 | [diff] [blame] | 1018 | Result = DAG.getMergeValues(Ops, 2); |
Jim Laskey | 8782d48 | 2007-02-28 20:43:58 +0000 | [diff] [blame] | 1019 | break; |
| 1020 | } |
| 1021 | } |
Chris Lattner | eb7f34f | 2007-04-27 17:12:52 +0000 | [diff] [blame] | 1022 | } |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1023 | if (Result.getNode()->getNumValues() == 1) break; |
Duncan Sands | b027fa0 | 2007-12-31 18:35:50 +0000 | [diff] [blame] | 1024 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1025 | assert(Result.getNode()->getNumValues() == 2 && |
Duncan Sands | b027fa0 | 2007-12-31 18:35:50 +0000 | [diff] [blame] | 1026 | "Cannot return more than two values!"); |
| 1027 | |
| 1028 | // Since we produced two values, make sure to remember that we |
| 1029 | // legalized both of them. |
| 1030 | Tmp1 = LegalizeOp(Result); |
| 1031 | Tmp2 = LegalizeOp(Result.getValue(1)); |
| 1032 | AddLegalizedOperand(Op.getValue(0), Tmp1); |
| 1033 | AddLegalizedOperand(Op.getValue(1), Tmp2); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 1034 | return Op.getResNo() ? Tmp2 : Tmp1; |
Nick Lewycky | 6d4b711 | 2007-07-14 15:11:14 +0000 | [diff] [blame] | 1035 | case ISD::EH_RETURN: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1036 | MVT VT = Node->getValueType(0); |
Anton Korobeynikov | 2365f51 | 2007-07-14 14:06:15 +0000 | [diff] [blame] | 1037 | // The only "good" option for this node is to custom lower it. |
| 1038 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 1039 | default: assert(0 && "This action is not supported at all!"); |
| 1040 | case TargetLowering::Custom: |
| 1041 | Result = TLI.LowerOperation(Op, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1042 | if (Result.getNode()) break; |
Anton Korobeynikov | 2365f51 | 2007-07-14 14:06:15 +0000 | [diff] [blame] | 1043 | // Fall Thru |
| 1044 | case TargetLowering::Legal: |
| 1045 | // Target does not know, how to lower this, lower to noop |
| 1046 | Result = LegalizeOp(Node->getOperand(0)); |
| 1047 | break; |
| 1048 | } |
Nick Lewycky | 6d4b711 | 2007-07-14 15:11:14 +0000 | [diff] [blame] | 1049 | } |
Anton Korobeynikov | 2365f51 | 2007-07-14 14:06:15 +0000 | [diff] [blame] | 1050 | break; |
Chris Lattner | 08951a3 | 2005-09-02 01:15:01 +0000 | [diff] [blame] | 1051 | case ISD::AssertSext: |
| 1052 | case ISD::AssertZext: |
| 1053 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1054 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
Chris Lattner | 08951a3 | 2005-09-02 01:15:01 +0000 | [diff] [blame] | 1055 | break; |
Chris Lattner | 308575b | 2005-11-20 22:56:56 +0000 | [diff] [blame] | 1056 | case ISD::MERGE_VALUES: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1057 | // Legalize eliminates MERGE_VALUES nodes. |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 1058 | Result = Node->getOperand(Op.getResNo()); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 1059 | break; |
Chris Lattner | 69a5215 | 2005-01-14 22:38:01 +0000 | [diff] [blame] | 1060 | case ISD::CopyFromReg: |
| 1061 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 1062 | Result = Op.getValue(0); |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 1063 | if (Node->getNumValues() == 2) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1064 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 1065 | } else { |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 1066 | assert(Node->getNumValues() == 3 && "Invalid copyfromreg!"); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1067 | if (Node->getNumOperands() == 3) { |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 1068 | Tmp2 = LegalizeOp(Node->getOperand(2)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1069 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1),Tmp2); |
| 1070 | } else { |
| 1071 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
| 1072 | } |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 1073 | AddLegalizedOperand(Op.getValue(2), Result.getValue(2)); |
| 1074 | } |
Chris Lattner | 13c184d | 2005-01-28 06:27:38 +0000 | [diff] [blame] | 1075 | // Since CopyFromReg produces two values, make sure to remember that we |
| 1076 | // legalized both of them. |
| 1077 | AddLegalizedOperand(Op.getValue(0), Result); |
| 1078 | AddLegalizedOperand(Op.getValue(1), Result.getValue(1)); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 1079 | return Result.getValue(Op.getResNo()); |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 1080 | case ISD::UNDEF: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1081 | MVT VT = Op.getValueType(); |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 1082 | switch (TLI.getOperationAction(ISD::UNDEF, VT)) { |
Nate Begeman | ea19cd5 | 2005-04-02 00:41:14 +0000 | [diff] [blame] | 1083 | default: assert(0 && "This action is not supported yet!"); |
| 1084 | case TargetLowering::Expand: |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1085 | if (VT.isInteger()) |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 1086 | Result = DAG.getConstant(0, VT); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1087 | else if (VT.isFloatingPoint()) |
| 1088 | Result = DAG.getConstantFP(APFloat(APInt(VT.getSizeInBits(), 0)), |
Dale Johannesen | f41db21 | 2007-09-26 17:26:49 +0000 | [diff] [blame] | 1089 | VT); |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 1090 | else |
| 1091 | assert(0 && "Unknown value type!"); |
| 1092 | break; |
Nate Begeman | ea19cd5 | 2005-04-02 00:41:14 +0000 | [diff] [blame] | 1093 | case TargetLowering::Legal: |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 1094 | break; |
| 1095 | } |
| 1096 | break; |
| 1097 | } |
Chris Lattner | d1f04d4 | 2006-03-24 02:26:29 +0000 | [diff] [blame] | 1098 | |
Chris Lattner | 48b61a7 | 2006-03-28 00:40:33 +0000 | [diff] [blame] | 1099 | case ISD::INTRINSIC_W_CHAIN: |
| 1100 | case ISD::INTRINSIC_WO_CHAIN: |
| 1101 | case ISD::INTRINSIC_VOID: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1102 | SmallVector<SDValue, 8> Ops; |
Chris Lattner | d1f04d4 | 2006-03-24 02:26:29 +0000 | [diff] [blame] | 1103 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) |
| 1104 | Ops.push_back(LegalizeOp(Node->getOperand(i))); |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1105 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 10d7fa6 | 2006-03-26 09:12:51 +0000 | [diff] [blame] | 1106 | |
| 1107 | // Allow the target to custom lower its intrinsics if it wants to. |
Chris Lattner | 48b61a7 | 2006-03-28 00:40:33 +0000 | [diff] [blame] | 1108 | if (TLI.getOperationAction(Node->getOpcode(), MVT::Other) == |
Chris Lattner | 10d7fa6 | 2006-03-26 09:12:51 +0000 | [diff] [blame] | 1109 | TargetLowering::Custom) { |
| 1110 | Tmp3 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1111 | if (Tmp3.getNode()) Result = Tmp3; |
Chris Lattner | 13fc2f1 | 2006-03-27 20:28:29 +0000 | [diff] [blame] | 1112 | } |
| 1113 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1114 | if (Result.getNode()->getNumValues() == 1) break; |
Chris Lattner | 13fc2f1 | 2006-03-27 20:28:29 +0000 | [diff] [blame] | 1115 | |
| 1116 | // Must have return value and chain result. |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1117 | assert(Result.getNode()->getNumValues() == 2 && |
Chris Lattner | 13fc2f1 | 2006-03-27 20:28:29 +0000 | [diff] [blame] | 1118 | "Cannot return more than two values!"); |
| 1119 | |
| 1120 | // Since loads produce two values, make sure to remember that we |
| 1121 | // legalized both of them. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1122 | AddLegalizedOperand(SDValue(Node, 0), Result.getValue(0)); |
| 1123 | AddLegalizedOperand(SDValue(Node, 1), Result.getValue(1)); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 1124 | return Result.getValue(Op.getResNo()); |
Chris Lattner | d1f04d4 | 2006-03-24 02:26:29 +0000 | [diff] [blame] | 1125 | } |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 1126 | |
Dan Gohman | 7f46020 | 2008-06-30 20:59:49 +0000 | [diff] [blame] | 1127 | case ISD::DBG_STOPPOINT: |
| 1128 | assert(Node->getNumOperands() == 1 && "Invalid DBG_STOPPOINT node!"); |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 1129 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the input chain. |
| 1130 | |
Dan Gohman | 7f46020 | 2008-06-30 20:59:49 +0000 | [diff] [blame] | 1131 | switch (TLI.getOperationAction(ISD::DBG_STOPPOINT, MVT::Other)) { |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 1132 | case TargetLowering::Promote: |
| 1133 | default: assert(0 && "This action is not supported yet!"); |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 1134 | case TargetLowering::Expand: { |
Jim Laskey | 44c3b9f | 2007-01-26 21:22:28 +0000 | [diff] [blame] | 1135 | MachineModuleInfo *MMI = DAG.getMachineModuleInfo(); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1136 | bool useDEBUG_LOC = TLI.isOperationLegal(ISD::DEBUG_LOC, MVT::Other); |
Dan Gohman | 4406604 | 2008-07-01 00:05:16 +0000 | [diff] [blame] | 1137 | bool useLABEL = TLI.isOperationLegal(ISD::DBG_LABEL, MVT::Other); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1138 | |
Dan Gohman | 7f46020 | 2008-06-30 20:59:49 +0000 | [diff] [blame] | 1139 | const DbgStopPointSDNode *DSP = cast<DbgStopPointSDNode>(Node); |
Jim Laskey | 44c3b9f | 2007-01-26 21:22:28 +0000 | [diff] [blame] | 1140 | if (MMI && (useDEBUG_LOC || useLABEL)) { |
Dan Gohman | 7f46020 | 2008-06-30 20:59:49 +0000 | [diff] [blame] | 1141 | const CompileUnitDesc *CompileUnit = DSP->getCompileUnit(); |
| 1142 | unsigned SrcFile = MMI->RecordSource(CompileUnit); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1143 | |
Dan Gohman | 7f46020 | 2008-06-30 20:59:49 +0000 | [diff] [blame] | 1144 | unsigned Line = DSP->getLine(); |
| 1145 | unsigned Col = DSP->getColumn(); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1146 | |
| 1147 | if (useDEBUG_LOC) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1148 | SDValue Ops[] = { Tmp1, DAG.getConstant(Line, MVT::i32), |
Evan Cheng | 71e8685 | 2008-07-08 20:06:39 +0000 | [diff] [blame] | 1149 | DAG.getConstant(Col, MVT::i32), |
| 1150 | DAG.getConstant(SrcFile, MVT::i32) }; |
| 1151 | Result = DAG.getNode(ISD::DEBUG_LOC, MVT::Other, Ops, 4); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1152 | } else { |
Evan Cheng | a647c92 | 2008-02-01 02:05:57 +0000 | [diff] [blame] | 1153 | unsigned ID = MMI->RecordSourceLine(Line, Col, SrcFile); |
Dan Gohman | 4406604 | 2008-07-01 00:05:16 +0000 | [diff] [blame] | 1154 | Result = DAG.getLabel(ISD::DBG_LABEL, Tmp1, ID); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1155 | } |
Jim Laskey | e81aecb | 2005-12-21 20:51:37 +0000 | [diff] [blame] | 1156 | } else { |
| 1157 | Result = Tmp1; // chain |
| 1158 | } |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 1159 | break; |
Chris Lattner | e773673 | 2005-12-18 23:54:29 +0000 | [diff] [blame] | 1160 | } |
Evan Cheng | 71e8685 | 2008-07-08 20:06:39 +0000 | [diff] [blame] | 1161 | case TargetLowering::Legal: { |
| 1162 | LegalizeAction Action = getTypeAction(Node->getOperand(1).getValueType()); |
| 1163 | if (Action == Legal && Tmp1 == Node->getOperand(0)) |
| 1164 | break; |
| 1165 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1166 | SmallVector<SDValue, 8> Ops; |
Evan Cheng | 71e8685 | 2008-07-08 20:06:39 +0000 | [diff] [blame] | 1167 | Ops.push_back(Tmp1); |
| 1168 | if (Action == Legal) { |
| 1169 | Ops.push_back(Node->getOperand(1)); // line # must be legal. |
| 1170 | Ops.push_back(Node->getOperand(2)); // col # must be legal. |
| 1171 | } else { |
| 1172 | // Otherwise promote them. |
| 1173 | Ops.push_back(PromoteOp(Node->getOperand(1))); |
| 1174 | Ops.push_back(PromoteOp(Node->getOperand(2))); |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 1175 | } |
Evan Cheng | 71e8685 | 2008-07-08 20:06:39 +0000 | [diff] [blame] | 1176 | Ops.push_back(Node->getOperand(3)); // filename must be legal. |
| 1177 | Ops.push_back(Node->getOperand(4)); // working dir # must be legal. |
| 1178 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 1179 | break; |
| 1180 | } |
Evan Cheng | 71e8685 | 2008-07-08 20:06:39 +0000 | [diff] [blame] | 1181 | } |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 1182 | break; |
Evan Cheng | a844bde | 2008-02-02 04:07:54 +0000 | [diff] [blame] | 1183 | |
| 1184 | case ISD::DECLARE: |
| 1185 | assert(Node->getNumOperands() == 3 && "Invalid DECLARE node!"); |
| 1186 | switch (TLI.getOperationAction(ISD::DECLARE, MVT::Other)) { |
| 1187 | default: assert(0 && "This action is not supported yet!"); |
| 1188 | case TargetLowering::Legal: |
| 1189 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1190 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the address. |
| 1191 | Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the variable. |
| 1192 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
| 1193 | break; |
Chris Lattner | e07415d | 2008-02-28 05:53:40 +0000 | [diff] [blame] | 1194 | case TargetLowering::Expand: |
| 1195 | Result = LegalizeOp(Node->getOperand(0)); |
| 1196 | break; |
Evan Cheng | a844bde | 2008-02-02 04:07:54 +0000 | [diff] [blame] | 1197 | } |
| 1198 | break; |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 1199 | |
| 1200 | case ISD::DEBUG_LOC: |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1201 | assert(Node->getNumOperands() == 4 && "Invalid DEBUG_LOC node!"); |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 1202 | switch (TLI.getOperationAction(ISD::DEBUG_LOC, MVT::Other)) { |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 1203 | default: assert(0 && "This action is not supported yet!"); |
Evan Cheng | 71e8685 | 2008-07-08 20:06:39 +0000 | [diff] [blame] | 1204 | case TargetLowering::Legal: { |
| 1205 | LegalizeAction Action = getTypeAction(Node->getOperand(1).getValueType()); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1206 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Evan Cheng | 71e8685 | 2008-07-08 20:06:39 +0000 | [diff] [blame] | 1207 | if (Action == Legal && Tmp1 == Node->getOperand(0)) |
| 1208 | break; |
| 1209 | if (Action == Legal) { |
| 1210 | Tmp2 = Node->getOperand(1); |
| 1211 | Tmp3 = Node->getOperand(2); |
| 1212 | Tmp4 = Node->getOperand(3); |
| 1213 | } else { |
| 1214 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the line #. |
| 1215 | Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the col #. |
| 1216 | Tmp4 = LegalizeOp(Node->getOperand(3)); // Legalize the source file id. |
| 1217 | } |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1218 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3, Tmp4); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1219 | break; |
| 1220 | } |
Evan Cheng | 71e8685 | 2008-07-08 20:06:39 +0000 | [diff] [blame] | 1221 | } |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1222 | break; |
| 1223 | |
Dan Gohman | 4406604 | 2008-07-01 00:05:16 +0000 | [diff] [blame] | 1224 | case ISD::DBG_LABEL: |
| 1225 | case ISD::EH_LABEL: |
| 1226 | assert(Node->getNumOperands() == 1 && "Invalid LABEL node!"); |
| 1227 | switch (TLI.getOperationAction(Node->getOpcode(), MVT::Other)) { |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1228 | default: assert(0 && "This action is not supported yet!"); |
| 1229 | case TargetLowering::Legal: |
| 1230 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Dan Gohman | 4406604 | 2008-07-01 00:05:16 +0000 | [diff] [blame] | 1231 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 1232 | break; |
Chris Lattner | a9569f1 | 2007-03-03 19:21:38 +0000 | [diff] [blame] | 1233 | case TargetLowering::Expand: |
| 1234 | Result = LegalizeOp(Node->getOperand(0)); |
| 1235 | break; |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 1236 | } |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 1237 | break; |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 1238 | |
Evan Cheng | 27b7db5 | 2008-03-08 00:58:38 +0000 | [diff] [blame] | 1239 | case ISD::PREFETCH: |
| 1240 | assert(Node->getNumOperands() == 4 && "Invalid Prefetch node!"); |
| 1241 | switch (TLI.getOperationAction(ISD::PREFETCH, MVT::Other)) { |
| 1242 | default: assert(0 && "This action is not supported yet!"); |
| 1243 | case TargetLowering::Legal: |
| 1244 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1245 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the address. |
| 1246 | Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the rw specifier. |
| 1247 | Tmp4 = LegalizeOp(Node->getOperand(3)); // Legalize locality specifier. |
| 1248 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3, Tmp4); |
| 1249 | break; |
| 1250 | case TargetLowering::Expand: |
| 1251 | // It's a noop. |
| 1252 | Result = LegalizeOp(Node->getOperand(0)); |
| 1253 | break; |
| 1254 | } |
| 1255 | break; |
| 1256 | |
Andrew Lenharth | 22c5c1b | 2008-02-16 01:24:58 +0000 | [diff] [blame] | 1257 | case ISD::MEMBARRIER: { |
| 1258 | assert(Node->getNumOperands() == 6 && "Invalid MemBarrier node!"); |
Andrew Lenharth | d497d9f | 2008-02-16 14:46:26 +0000 | [diff] [blame] | 1259 | switch (TLI.getOperationAction(ISD::MEMBARRIER, MVT::Other)) { |
| 1260 | default: assert(0 && "This action is not supported yet!"); |
| 1261 | case TargetLowering::Legal: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1262 | SDValue Ops[6]; |
Andrew Lenharth | d497d9f | 2008-02-16 14:46:26 +0000 | [diff] [blame] | 1263 | Ops[0] = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Duncan Sands | e90a615 | 2008-02-27 08:53:44 +0000 | [diff] [blame] | 1264 | for (int x = 1; x < 6; ++x) { |
| 1265 | Ops[x] = Node->getOperand(x); |
| 1266 | if (!isTypeLegal(Ops[x].getValueType())) |
| 1267 | Ops[x] = PromoteOp(Ops[x]); |
| 1268 | } |
Andrew Lenharth | d497d9f | 2008-02-16 14:46:26 +0000 | [diff] [blame] | 1269 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], 6); |
| 1270 | break; |
| 1271 | } |
| 1272 | case TargetLowering::Expand: |
| 1273 | //There is no libgcc call for this op |
| 1274 | Result = Node->getOperand(0); // Noop |
| 1275 | break; |
| 1276 | } |
Andrew Lenharth | 22c5c1b | 2008-02-16 01:24:58 +0000 | [diff] [blame] | 1277 | break; |
| 1278 | } |
| 1279 | |
Dale Johannesen | e00a8a2 | 2008-08-28 02:44:49 +0000 | [diff] [blame] | 1280 | case ISD::ATOMIC_CMP_SWAP_8: |
| 1281 | case ISD::ATOMIC_CMP_SWAP_16: |
| 1282 | case ISD::ATOMIC_CMP_SWAP_32: |
| 1283 | case ISD::ATOMIC_CMP_SWAP_64: { |
Mon P Wang | 63307c3 | 2008-05-05 19:05:59 +0000 | [diff] [blame] | 1284 | unsigned int num_operands = 4; |
| 1285 | assert(Node->getNumOperands() == num_operands && "Invalid Atomic node!"); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1286 | SDValue Ops[4]; |
Mon P Wang | 63307c3 | 2008-05-05 19:05:59 +0000 | [diff] [blame] | 1287 | for (unsigned int x = 0; x < num_operands; ++x) |
Andrew Lenharth | 26ed869 | 2008-03-01 21:52:34 +0000 | [diff] [blame] | 1288 | Ops[x] = LegalizeOp(Node->getOperand(x)); |
Mon P Wang | 63307c3 | 2008-05-05 19:05:59 +0000 | [diff] [blame] | 1289 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], num_operands); |
| 1290 | |
| 1291 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 1292 | default: assert(0 && "This action is not supported yet!"); |
| 1293 | case TargetLowering::Custom: |
| 1294 | Result = TLI.LowerOperation(Result, DAG); |
| 1295 | break; |
| 1296 | case TargetLowering::Legal: |
| 1297 | break; |
| 1298 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1299 | AddLegalizedOperand(SDValue(Node, 0), Result.getValue(0)); |
| 1300 | AddLegalizedOperand(SDValue(Node, 1), Result.getValue(1)); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 1301 | return Result.getValue(Op.getResNo()); |
Duncan Sands | 126d907 | 2008-07-04 11:47:58 +0000 | [diff] [blame] | 1302 | } |
Dale Johannesen | e00a8a2 | 2008-08-28 02:44:49 +0000 | [diff] [blame] | 1303 | case ISD::ATOMIC_LOAD_ADD_8: |
| 1304 | case ISD::ATOMIC_LOAD_SUB_8: |
| 1305 | case ISD::ATOMIC_LOAD_AND_8: |
| 1306 | case ISD::ATOMIC_LOAD_OR_8: |
| 1307 | case ISD::ATOMIC_LOAD_XOR_8: |
| 1308 | case ISD::ATOMIC_LOAD_NAND_8: |
| 1309 | case ISD::ATOMIC_LOAD_MIN_8: |
| 1310 | case ISD::ATOMIC_LOAD_MAX_8: |
| 1311 | case ISD::ATOMIC_LOAD_UMIN_8: |
| 1312 | case ISD::ATOMIC_LOAD_UMAX_8: |
| 1313 | case ISD::ATOMIC_SWAP_8: |
| 1314 | case ISD::ATOMIC_LOAD_ADD_16: |
| 1315 | case ISD::ATOMIC_LOAD_SUB_16: |
| 1316 | case ISD::ATOMIC_LOAD_AND_16: |
| 1317 | case ISD::ATOMIC_LOAD_OR_16: |
| 1318 | case ISD::ATOMIC_LOAD_XOR_16: |
| 1319 | case ISD::ATOMIC_LOAD_NAND_16: |
| 1320 | case ISD::ATOMIC_LOAD_MIN_16: |
| 1321 | case ISD::ATOMIC_LOAD_MAX_16: |
| 1322 | case ISD::ATOMIC_LOAD_UMIN_16: |
| 1323 | case ISD::ATOMIC_LOAD_UMAX_16: |
| 1324 | case ISD::ATOMIC_SWAP_16: |
| 1325 | case ISD::ATOMIC_LOAD_ADD_32: |
| 1326 | case ISD::ATOMIC_LOAD_SUB_32: |
| 1327 | case ISD::ATOMIC_LOAD_AND_32: |
| 1328 | case ISD::ATOMIC_LOAD_OR_32: |
| 1329 | case ISD::ATOMIC_LOAD_XOR_32: |
| 1330 | case ISD::ATOMIC_LOAD_NAND_32: |
| 1331 | case ISD::ATOMIC_LOAD_MIN_32: |
| 1332 | case ISD::ATOMIC_LOAD_MAX_32: |
| 1333 | case ISD::ATOMIC_LOAD_UMIN_32: |
| 1334 | case ISD::ATOMIC_LOAD_UMAX_32: |
| 1335 | case ISD::ATOMIC_SWAP_32: |
| 1336 | case ISD::ATOMIC_LOAD_ADD_64: |
| 1337 | case ISD::ATOMIC_LOAD_SUB_64: |
| 1338 | case ISD::ATOMIC_LOAD_AND_64: |
| 1339 | case ISD::ATOMIC_LOAD_OR_64: |
| 1340 | case ISD::ATOMIC_LOAD_XOR_64: |
| 1341 | case ISD::ATOMIC_LOAD_NAND_64: |
| 1342 | case ISD::ATOMIC_LOAD_MIN_64: |
| 1343 | case ISD::ATOMIC_LOAD_MAX_64: |
| 1344 | case ISD::ATOMIC_LOAD_UMIN_64: |
| 1345 | case ISD::ATOMIC_LOAD_UMAX_64: |
| 1346 | case ISD::ATOMIC_SWAP_64: { |
Mon P Wang | 63307c3 | 2008-05-05 19:05:59 +0000 | [diff] [blame] | 1347 | unsigned int num_operands = 3; |
| 1348 | assert(Node->getNumOperands() == num_operands && "Invalid Atomic node!"); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1349 | SDValue Ops[3]; |
Mon P Wang | 63307c3 | 2008-05-05 19:05:59 +0000 | [diff] [blame] | 1350 | for (unsigned int x = 0; x < num_operands; ++x) |
| 1351 | Ops[x] = LegalizeOp(Node->getOperand(x)); |
| 1352 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], num_operands); |
Duncan Sands | 126d907 | 2008-07-04 11:47:58 +0000 | [diff] [blame] | 1353 | |
Andrew Lenharth | 26ed869 | 2008-03-01 21:52:34 +0000 | [diff] [blame] | 1354 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 1355 | default: assert(0 && "This action is not supported yet!"); |
Andrew Lenharth | 26ed869 | 2008-03-01 21:52:34 +0000 | [diff] [blame] | 1356 | case TargetLowering::Custom: |
| 1357 | Result = TLI.LowerOperation(Result, DAG); |
| 1358 | break; |
| 1359 | case TargetLowering::Legal: |
Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 1360 | break; |
| 1361 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1362 | AddLegalizedOperand(SDValue(Node, 0), Result.getValue(0)); |
| 1363 | AddLegalizedOperand(SDValue(Node, 1), Result.getValue(1)); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 1364 | return Result.getValue(Op.getResNo()); |
Duncan Sands | 126d907 | 2008-07-04 11:47:58 +0000 | [diff] [blame] | 1365 | } |
Scott Michel | c1513d2 | 2007-08-08 23:23:31 +0000 | [diff] [blame] | 1366 | case ISD::Constant: { |
| 1367 | ConstantSDNode *CN = cast<ConstantSDNode>(Node); |
| 1368 | unsigned opAction = |
| 1369 | TLI.getOperationAction(ISD::Constant, CN->getValueType(0)); |
| 1370 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1371 | // We know we don't need to expand constants here, constants only have one |
| 1372 | // value and we check that it is fine above. |
| 1373 | |
Scott Michel | c1513d2 | 2007-08-08 23:23:31 +0000 | [diff] [blame] | 1374 | if (opAction == TargetLowering::Custom) { |
| 1375 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1376 | if (Tmp1.getNode()) |
Scott Michel | c1513d2 | 2007-08-08 23:23:31 +0000 | [diff] [blame] | 1377 | Result = Tmp1; |
| 1378 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1379 | break; |
Scott Michel | c1513d2 | 2007-08-08 23:23:31 +0000 | [diff] [blame] | 1380 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1381 | case ISD::ConstantFP: { |
| 1382 | // Spill FP immediates to the constant pool if the target cannot directly |
| 1383 | // codegen them. Targets often have some immediate values that can be |
| 1384 | // efficiently generated into an FP register without a load. We explicitly |
| 1385 | // leave these constants as ConstantFP nodes for the target to deal with. |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1386 | ConstantFPSDNode *CFP = cast<ConstantFPSDNode>(Node); |
| 1387 | |
Chris Lattner | 3181a77 | 2006-01-29 06:26:56 +0000 | [diff] [blame] | 1388 | switch (TLI.getOperationAction(ISD::ConstantFP, CFP->getValueType(0))) { |
| 1389 | default: assert(0 && "This action is not supported yet!"); |
Nate Begeman | e179584 | 2008-02-14 08:57:00 +0000 | [diff] [blame] | 1390 | case TargetLowering::Legal: |
| 1391 | break; |
Chris Lattner | 3181a77 | 2006-01-29 06:26:56 +0000 | [diff] [blame] | 1392 | case TargetLowering::Custom: |
| 1393 | Tmp3 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1394 | if (Tmp3.getNode()) { |
Chris Lattner | 3181a77 | 2006-01-29 06:26:56 +0000 | [diff] [blame] | 1395 | Result = Tmp3; |
| 1396 | break; |
| 1397 | } |
| 1398 | // FALLTHROUGH |
Nate Begeman | e179584 | 2008-02-14 08:57:00 +0000 | [diff] [blame] | 1399 | case TargetLowering::Expand: { |
| 1400 | // Check to see if this FP immediate is already legal. |
| 1401 | bool isLegal = false; |
| 1402 | for (TargetLowering::legal_fpimm_iterator I = TLI.legal_fpimm_begin(), |
| 1403 | E = TLI.legal_fpimm_end(); I != E; ++I) { |
| 1404 | if (CFP->isExactlyValue(*I)) { |
| 1405 | isLegal = true; |
| 1406 | break; |
| 1407 | } |
| 1408 | } |
| 1409 | // If this is a legal constant, turn it into a TargetConstantFP node. |
| 1410 | if (isLegal) |
| 1411 | break; |
Evan Cheng | 279101e | 2006-12-12 22:19:28 +0000 | [diff] [blame] | 1412 | Result = ExpandConstantFP(CFP, true, DAG, TLI); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1413 | } |
Nate Begeman | e179584 | 2008-02-14 08:57:00 +0000 | [diff] [blame] | 1414 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1415 | break; |
| 1416 | } |
Chris Lattner | 040c11c | 2005-11-09 18:48:57 +0000 | [diff] [blame] | 1417 | case ISD::TokenFactor: |
| 1418 | if (Node->getNumOperands() == 2) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1419 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1420 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1421 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 1422 | } else if (Node->getNumOperands() == 3) { |
| 1423 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1424 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1425 | Tmp3 = LegalizeOp(Node->getOperand(2)); |
| 1426 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | 040c11c | 2005-11-09 18:48:57 +0000 | [diff] [blame] | 1427 | } else { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1428 | SmallVector<SDValue, 8> Ops; |
Chris Lattner | 040c11c | 2005-11-09 18:48:57 +0000 | [diff] [blame] | 1429 | // Legalize the operands. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1430 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) |
| 1431 | Ops.push_back(LegalizeOp(Node->getOperand(i))); |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1432 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | a385e9b | 2005-01-13 17:59:25 +0000 | [diff] [blame] | 1433 | } |
Chris Lattner | a385e9b | 2005-01-13 17:59:25 +0000 | [diff] [blame] | 1434 | break; |
Chris Lattner | fdfded5 | 2006-04-12 16:20:43 +0000 | [diff] [blame] | 1435 | |
| 1436 | case ISD::FORMAL_ARGUMENTS: |
Chris Lattner | f4ec817 | 2006-05-16 22:53:20 +0000 | [diff] [blame] | 1437 | case ISD::CALL: |
Chris Lattner | fdfded5 | 2006-04-12 16:20:43 +0000 | [diff] [blame] | 1438 | // The only option for this is to custom lower it. |
Chris Lattner | b248e16 | 2006-05-17 17:55:45 +0000 | [diff] [blame] | 1439 | Tmp3 = TLI.LowerOperation(Result.getValue(0), DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1440 | assert(Tmp3.getNode() && "Target didn't custom lower this node!"); |
Dale Johannesen | 0ea0356 | 2008-03-05 19:14:03 +0000 | [diff] [blame] | 1441 | // A call within a calling sequence must be legalized to something |
| 1442 | // other than the normal CALLSEQ_END. Violating this gets Legalize |
| 1443 | // into an infinite loop. |
| 1444 | assert ((!IsLegalizingCall || |
| 1445 | Node->getOpcode() != ISD::CALL || |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1446 | Tmp3.getNode()->getOpcode() != ISD::CALLSEQ_END) && |
Dale Johannesen | 0ea0356 | 2008-03-05 19:14:03 +0000 | [diff] [blame] | 1447 | "Nested CALLSEQ_START..CALLSEQ_END not supported."); |
Bill Wendling | 0f8d9c0 | 2007-11-13 00:44:25 +0000 | [diff] [blame] | 1448 | |
| 1449 | // The number of incoming and outgoing values should match; unless the final |
| 1450 | // outgoing value is a flag. |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1451 | assert((Tmp3.getNode()->getNumValues() == Result.getNode()->getNumValues() || |
| 1452 | (Tmp3.getNode()->getNumValues() == Result.getNode()->getNumValues() + 1 && |
| 1453 | Tmp3.getNode()->getValueType(Tmp3.getNode()->getNumValues() - 1) == |
Bill Wendling | 0f8d9c0 | 2007-11-13 00:44:25 +0000 | [diff] [blame] | 1454 | MVT::Flag)) && |
Chris Lattner | b248e16 | 2006-05-17 17:55:45 +0000 | [diff] [blame] | 1455 | "Lowering call/formal_arguments produced unexpected # results!"); |
Chris Lattner | e2e4173 | 2006-05-16 05:49:56 +0000 | [diff] [blame] | 1456 | |
Chris Lattner | f4ec817 | 2006-05-16 22:53:20 +0000 | [diff] [blame] | 1457 | // Since CALL/FORMAL_ARGUMENTS nodes produce multiple values, make sure to |
Chris Lattner | e2e4173 | 2006-05-16 05:49:56 +0000 | [diff] [blame] | 1458 | // remember that we legalized all of them, so it doesn't get relegalized. |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1459 | for (unsigned i = 0, e = Tmp3.getNode()->getNumValues(); i != e; ++i) { |
| 1460 | if (Tmp3.getNode()->getValueType(i) == MVT::Flag) |
Bill Wendling | 0f8d9c0 | 2007-11-13 00:44:25 +0000 | [diff] [blame] | 1461 | continue; |
Chris Lattner | b248e16 | 2006-05-17 17:55:45 +0000 | [diff] [blame] | 1462 | Tmp1 = LegalizeOp(Tmp3.getValue(i)); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 1463 | if (Op.getResNo() == i) |
Chris Lattner | e2e4173 | 2006-05-16 05:49:56 +0000 | [diff] [blame] | 1464 | Tmp2 = Tmp1; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1465 | AddLegalizedOperand(SDValue(Node, i), Tmp1); |
Chris Lattner | e2e4173 | 2006-05-16 05:49:56 +0000 | [diff] [blame] | 1466 | } |
| 1467 | return Tmp2; |
Christopher Lamb | 557c363 | 2007-07-26 07:34:40 +0000 | [diff] [blame] | 1468 | case ISD::EXTRACT_SUBREG: { |
| 1469 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1470 | ConstantSDNode *idx = dyn_cast<ConstantSDNode>(Node->getOperand(1)); |
| 1471 | assert(idx && "Operand must be a constant"); |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1472 | Tmp2 = DAG.getTargetConstant(idx->getAPIntValue(), idx->getValueType(0)); |
Christopher Lamb | 557c363 | 2007-07-26 07:34:40 +0000 | [diff] [blame] | 1473 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 1474 | } |
| 1475 | break; |
| 1476 | case ISD::INSERT_SUBREG: { |
| 1477 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1478 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1479 | ConstantSDNode *idx = dyn_cast<ConstantSDNode>(Node->getOperand(2)); |
| 1480 | assert(idx && "Operand must be a constant"); |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1481 | Tmp3 = DAG.getTargetConstant(idx->getAPIntValue(), idx->getValueType(0)); |
Christopher Lamb | 557c363 | 2007-07-26 07:34:40 +0000 | [diff] [blame] | 1482 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
| 1483 | } |
| 1484 | break; |
Chris Lattner | b2827b0 | 2006-03-19 00:52:58 +0000 | [diff] [blame] | 1485 | case ISD::BUILD_VECTOR: |
| 1486 | switch (TLI.getOperationAction(ISD::BUILD_VECTOR, Node->getValueType(0))) { |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1487 | default: assert(0 && "This action is not supported yet!"); |
| 1488 | case TargetLowering::Custom: |
| 1489 | Tmp3 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1490 | if (Tmp3.getNode()) { |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1491 | Result = Tmp3; |
| 1492 | break; |
| 1493 | } |
| 1494 | // FALLTHROUGH |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 1495 | case TargetLowering::Expand: |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1496 | Result = ExpandBUILD_VECTOR(Result.getNode()); |
Chris Lattner | b2827b0 | 2006-03-19 00:52:58 +0000 | [diff] [blame] | 1497 | break; |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1498 | } |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1499 | break; |
| 1500 | case ISD::INSERT_VECTOR_ELT: |
| 1501 | Tmp1 = LegalizeOp(Node->getOperand(0)); // InVec |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1502 | Tmp3 = LegalizeOp(Node->getOperand(2)); // InEltNo |
Nate Begeman | 0325d90 | 2008-02-13 06:43:04 +0000 | [diff] [blame] | 1503 | |
| 1504 | // The type of the value to insert may not be legal, even though the vector |
| 1505 | // type is legal. Legalize/Promote accordingly. We do not handle Expand |
| 1506 | // here. |
| 1507 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 1508 | default: assert(0 && "Cannot expand insert element operand"); |
| 1509 | case Legal: Tmp2 = LegalizeOp(Node->getOperand(1)); break; |
| 1510 | case Promote: Tmp2 = PromoteOp(Node->getOperand(1)); break; |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 1511 | case Expand: |
| 1512 | // FIXME: An alternative would be to check to see if the target is not |
| 1513 | // going to custom lower this operation, we could bitcast to half elt |
| 1514 | // width and perform two inserts at that width, if that is legal. |
| 1515 | Tmp2 = Node->getOperand(1); |
| 1516 | break; |
Nate Begeman | 0325d90 | 2008-02-13 06:43:04 +0000 | [diff] [blame] | 1517 | } |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1518 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
| 1519 | |
| 1520 | switch (TLI.getOperationAction(ISD::INSERT_VECTOR_ELT, |
| 1521 | Node->getValueType(0))) { |
| 1522 | default: assert(0 && "This action is not supported yet!"); |
| 1523 | case TargetLowering::Legal: |
| 1524 | break; |
| 1525 | case TargetLowering::Custom: |
Nate Begeman | 2281a99 | 2008-01-05 20:47:37 +0000 | [diff] [blame] | 1526 | Tmp4 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1527 | if (Tmp4.getNode()) { |
Nate Begeman | 2281a99 | 2008-01-05 20:47:37 +0000 | [diff] [blame] | 1528 | Result = Tmp4; |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1529 | break; |
| 1530 | } |
| 1531 | // FALLTHROUGH |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 1532 | case TargetLowering::Promote: |
| 1533 | // Fall thru for vector case |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1534 | case TargetLowering::Expand: { |
Chris Lattner | 8d5a894 | 2006-04-17 19:21:01 +0000 | [diff] [blame] | 1535 | // If the insert index is a constant, codegen this as a scalar_to_vector, |
| 1536 | // then a shuffle that inserts it into the right position in the vector. |
| 1537 | if (ConstantSDNode *InsertPos = dyn_cast<ConstantSDNode>(Tmp3)) { |
Nate Begeman | 0325d90 | 2008-02-13 06:43:04 +0000 | [diff] [blame] | 1538 | // SCALAR_TO_VECTOR requires that the type of the value being inserted |
| 1539 | // match the element type of the vector being created. |
| 1540 | if (Tmp2.getValueType() == |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1541 | Op.getValueType().getVectorElementType()) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1542 | SDValue ScVec = DAG.getNode(ISD::SCALAR_TO_VECTOR, |
Nate Begeman | 0325d90 | 2008-02-13 06:43:04 +0000 | [diff] [blame] | 1543 | Tmp1.getValueType(), Tmp2); |
| 1544 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1545 | unsigned NumElts = Tmp1.getValueType().getVectorNumElements(); |
| 1546 | MVT ShufMaskVT = |
| 1547 | MVT::getIntVectorWithNumElements(NumElts); |
| 1548 | MVT ShufMaskEltVT = ShufMaskVT.getVectorElementType(); |
Nate Begeman | 0325d90 | 2008-02-13 06:43:04 +0000 | [diff] [blame] | 1549 | |
| 1550 | // We generate a shuffle of InVec and ScVec, so the shuffle mask |
| 1551 | // should be 0,1,2,3,4,5... with the appropriate element replaced with |
| 1552 | // elt 0 of the RHS. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1553 | SmallVector<SDValue, 8> ShufOps; |
Nate Begeman | 0325d90 | 2008-02-13 06:43:04 +0000 | [diff] [blame] | 1554 | for (unsigned i = 0; i != NumElts; ++i) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1555 | if (i != InsertPos->getZExtValue()) |
Nate Begeman | 0325d90 | 2008-02-13 06:43:04 +0000 | [diff] [blame] | 1556 | ShufOps.push_back(DAG.getConstant(i, ShufMaskEltVT)); |
| 1557 | else |
| 1558 | ShufOps.push_back(DAG.getConstant(NumElts, ShufMaskEltVT)); |
| 1559 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1560 | SDValue ShufMask = DAG.getNode(ISD::BUILD_VECTOR, ShufMaskVT, |
Nate Begeman | 0325d90 | 2008-02-13 06:43:04 +0000 | [diff] [blame] | 1561 | &ShufOps[0], ShufOps.size()); |
| 1562 | |
| 1563 | Result = DAG.getNode(ISD::VECTOR_SHUFFLE, Tmp1.getValueType(), |
| 1564 | Tmp1, ScVec, ShufMask); |
| 1565 | Result = LegalizeOp(Result); |
| 1566 | break; |
Chris Lattner | 8d5a894 | 2006-04-17 19:21:01 +0000 | [diff] [blame] | 1567 | } |
Chris Lattner | 8d5a894 | 2006-04-17 19:21:01 +0000 | [diff] [blame] | 1568 | } |
Nate Begeman | 6867991 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 1569 | Result = PerformInsertVectorEltInMemory(Tmp1, Tmp2, Tmp3); |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1570 | break; |
| 1571 | } |
| 1572 | } |
| 1573 | break; |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 1574 | case ISD::SCALAR_TO_VECTOR: |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 1575 | if (!TLI.isTypeLegal(Node->getOperand(0).getValueType())) { |
| 1576 | Result = LegalizeOp(ExpandSCALAR_TO_VECTOR(Node)); |
| 1577 | break; |
| 1578 | } |
| 1579 | |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 1580 | Tmp1 = LegalizeOp(Node->getOperand(0)); // InVal |
| 1581 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 1582 | switch (TLI.getOperationAction(ISD::SCALAR_TO_VECTOR, |
| 1583 | Node->getValueType(0))) { |
| 1584 | default: assert(0 && "This action is not supported yet!"); |
| 1585 | case TargetLowering::Legal: |
| 1586 | break; |
Chris Lattner | 4d3abee | 2006-03-19 06:47:21 +0000 | [diff] [blame] | 1587 | case TargetLowering::Custom: |
| 1588 | Tmp3 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1589 | if (Tmp3.getNode()) { |
Chris Lattner | 4d3abee | 2006-03-19 06:47:21 +0000 | [diff] [blame] | 1590 | Result = Tmp3; |
| 1591 | break; |
| 1592 | } |
| 1593 | // FALLTHROUGH |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 1594 | case TargetLowering::Expand: |
| 1595 | Result = LegalizeOp(ExpandSCALAR_TO_VECTOR(Node)); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 1596 | break; |
| 1597 | } |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 1598 | break; |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 1599 | case ISD::VECTOR_SHUFFLE: |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 1600 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the input vectors, |
| 1601 | Tmp2 = LegalizeOp(Node->getOperand(1)); // but not the shuffle mask. |
| 1602 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
| 1603 | |
| 1604 | // Allow targets to custom lower the SHUFFLEs they support. |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 1605 | switch (TLI.getOperationAction(ISD::VECTOR_SHUFFLE,Result.getValueType())) { |
| 1606 | default: assert(0 && "Unknown operation action!"); |
| 1607 | case TargetLowering::Legal: |
| 1608 | assert(isShuffleLegal(Result.getValueType(), Node->getOperand(2)) && |
| 1609 | "vector shuffle should not be created if not legal!"); |
| 1610 | break; |
| 1611 | case TargetLowering::Custom: |
Evan Cheng | 18dd6d0 | 2006-04-05 06:07:11 +0000 | [diff] [blame] | 1612 | Tmp3 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1613 | if (Tmp3.getNode()) { |
Evan Cheng | 18dd6d0 | 2006-04-05 06:07:11 +0000 | [diff] [blame] | 1614 | Result = Tmp3; |
| 1615 | break; |
| 1616 | } |
| 1617 | // FALLTHROUGH |
| 1618 | case TargetLowering::Expand: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1619 | MVT VT = Node->getValueType(0); |
| 1620 | MVT EltVT = VT.getVectorElementType(); |
| 1621 | MVT PtrVT = TLI.getPointerTy(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1622 | SDValue Mask = Node->getOperand(2); |
Evan Cheng | 18dd6d0 | 2006-04-05 06:07:11 +0000 | [diff] [blame] | 1623 | unsigned NumElems = Mask.getNumOperands(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1624 | SmallVector<SDValue,8> Ops; |
Evan Cheng | 18dd6d0 | 2006-04-05 06:07:11 +0000 | [diff] [blame] | 1625 | for (unsigned i = 0; i != NumElems; ++i) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1626 | SDValue Arg = Mask.getOperand(i); |
Evan Cheng | 18dd6d0 | 2006-04-05 06:07:11 +0000 | [diff] [blame] | 1627 | if (Arg.getOpcode() == ISD::UNDEF) { |
| 1628 | Ops.push_back(DAG.getNode(ISD::UNDEF, EltVT)); |
| 1629 | } else { |
| 1630 | assert(isa<ConstantSDNode>(Arg) && "Invalid VECTOR_SHUFFLE mask!"); |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1631 | unsigned Idx = cast<ConstantSDNode>(Arg)->getZExtValue(); |
Evan Cheng | 18dd6d0 | 2006-04-05 06:07:11 +0000 | [diff] [blame] | 1632 | if (Idx < NumElems) |
| 1633 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, EltVT, Tmp1, |
| 1634 | DAG.getConstant(Idx, PtrVT))); |
| 1635 | else |
| 1636 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, EltVT, Tmp2, |
| 1637 | DAG.getConstant(Idx - NumElems, PtrVT))); |
| 1638 | } |
| 1639 | } |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 1640 | Result = DAG.getNode(ISD::BUILD_VECTOR, VT, &Ops[0], Ops.size()); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 1641 | break; |
Evan Cheng | 18dd6d0 | 2006-04-05 06:07:11 +0000 | [diff] [blame] | 1642 | } |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 1643 | case TargetLowering::Promote: { |
| 1644 | // Change base type to a different vector type. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1645 | MVT OVT = Node->getValueType(0); |
| 1646 | MVT NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 1647 | |
| 1648 | // Cast the two input vectors. |
| 1649 | Tmp1 = DAG.getNode(ISD::BIT_CONVERT, NVT, Tmp1); |
| 1650 | Tmp2 = DAG.getNode(ISD::BIT_CONVERT, NVT, Tmp2); |
| 1651 | |
| 1652 | // Convert the shuffle mask to the right # elements. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1653 | Tmp3 = SDValue(isShuffleLegal(OVT, Node->getOperand(2)), 0); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1654 | assert(Tmp3.getNode() && "Shuffle not legal?"); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 1655 | Result = DAG.getNode(ISD::VECTOR_SHUFFLE, NVT, Tmp1, Tmp2, Tmp3); |
| 1656 | Result = DAG.getNode(ISD::BIT_CONVERT, OVT, Result); |
| 1657 | break; |
| 1658 | } |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 1659 | } |
| 1660 | break; |
Chris Lattner | 384504c | 2006-03-21 20:44:12 +0000 | [diff] [blame] | 1661 | |
| 1662 | case ISD::EXTRACT_VECTOR_ELT: |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 1663 | Tmp1 = Node->getOperand(0); |
Chris Lattner | 384504c | 2006-03-21 20:44:12 +0000 | [diff] [blame] | 1664 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1665 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 1666 | Result = ExpandEXTRACT_VECTOR_ELT(Result); |
Chris Lattner | 384504c | 2006-03-21 20:44:12 +0000 | [diff] [blame] | 1667 | break; |
| 1668 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 1669 | case ISD::EXTRACT_SUBVECTOR: |
| 1670 | Tmp1 = Node->getOperand(0); |
| 1671 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1672 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 1673 | Result = ExpandEXTRACT_SUBVECTOR(Result); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 1674 | break; |
| 1675 | |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 1676 | case ISD::CONCAT_VECTORS: { |
| 1677 | // Use extract/insert/build vector for now. We might try to be |
| 1678 | // more clever later. |
| 1679 | MVT PtrVT = TLI.getPointerTy(); |
| 1680 | SmallVector<SDValue, 8> Ops; |
| 1681 | unsigned NumOperands = Node->getNumOperands(); |
| 1682 | for (unsigned i=0; i < NumOperands; ++i) { |
| 1683 | SDValue SubOp = Node->getOperand(i); |
| 1684 | MVT VVT = SubOp.getNode()->getValueType(0); |
| 1685 | MVT EltVT = VVT.getVectorElementType(); |
| 1686 | unsigned NumSubElem = VVT.getVectorNumElements(); |
| 1687 | for (unsigned j=0; j < NumSubElem; ++j) { |
| 1688 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, EltVT, SubOp, |
| 1689 | DAG.getConstant(j, PtrVT))); |
| 1690 | } |
| 1691 | } |
| 1692 | return LegalizeOp(DAG.getNode(ISD::BUILD_VECTOR, Node->getValueType(0), |
| 1693 | &Ops[0], Ops.size())); |
| 1694 | } |
| 1695 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1696 | case ISD::CALLSEQ_START: { |
| 1697 | SDNode *CallEnd = FindCallEndFromCallStart(Node); |
| 1698 | |
| 1699 | // Recursively Legalize all of the inputs of the call end that do not lead |
| 1700 | // to this call start. This ensures that any libcalls that need be inserted |
| 1701 | // are inserted *before* the CALLSEQ_START. |
Chris Lattner | 00755df | 2007-02-04 00:27:56 +0000 | [diff] [blame] | 1702 | {SmallPtrSet<SDNode*, 32> NodesLeadingTo; |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1703 | for (unsigned i = 0, e = CallEnd->getNumOperands(); i != e; ++i) |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1704 | LegalizeAllNodesNotLeadingTo(CallEnd->getOperand(i).getNode(), Node, |
Chris Lattner | c9cf4f1 | 2006-07-26 23:55:56 +0000 | [diff] [blame] | 1705 | NodesLeadingTo); |
| 1706 | } |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1707 | |
| 1708 | // Now that we legalized all of the inputs (which may have inserted |
| 1709 | // libcalls) create the new CALLSEQ_START node. |
| 1710 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1711 | |
| 1712 | // Merge in the last call, to ensure that this call start after the last |
| 1713 | // call ended. |
Chris Lattner | c5d7d7c | 2006-05-17 18:00:08 +0000 | [diff] [blame] | 1714 | if (LastCALLSEQ_END.getOpcode() != ISD::EntryToken) { |
Chris Lattner | b248e16 | 2006-05-17 17:55:45 +0000 | [diff] [blame] | 1715 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1716 | Tmp1 = LegalizeOp(Tmp1); |
| 1717 | } |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1718 | |
| 1719 | // Do not try to legalize the target-specific arguments (#1+). |
| 1720 | if (Tmp1 != Node->getOperand(0)) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1721 | SmallVector<SDValue, 8> Ops(Node->op_begin(), Node->op_end()); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1722 | Ops[0] = Tmp1; |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1723 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1724 | } |
| 1725 | |
| 1726 | // Remember that the CALLSEQ_START is legalized. |
Chris Lattner | 4b653a0 | 2006-02-14 00:55:02 +0000 | [diff] [blame] | 1727 | AddLegalizedOperand(Op.getValue(0), Result); |
| 1728 | if (Node->getNumValues() == 2) // If this has a flag result, remember it. |
| 1729 | AddLegalizedOperand(Op.getValue(1), Result.getValue(1)); |
| 1730 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1731 | // Now that the callseq_start and all of the non-call nodes above this call |
| 1732 | // sequence have been legalized, legalize the call itself. During this |
| 1733 | // process, no libcalls can/will be inserted, guaranteeing that no calls |
| 1734 | // can overlap. |
| 1735 | assert(!IsLegalizingCall && "Inconsistent sequentialization of calls!"); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1736 | // Note that we are selecting this call! |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1737 | LastCALLSEQ_END = SDValue(CallEnd, 0); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1738 | IsLegalizingCall = true; |
| 1739 | |
| 1740 | // Legalize the call, starting from the CALLSEQ_END. |
| 1741 | LegalizeOp(LastCALLSEQ_END); |
| 1742 | assert(!IsLegalizingCall && "CALLSEQ_END should have cleared this!"); |
| 1743 | return Result; |
| 1744 | } |
Chris Lattner | 16cd04d | 2005-05-12 23:24:06 +0000 | [diff] [blame] | 1745 | case ISD::CALLSEQ_END: |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1746 | // If the CALLSEQ_START node hasn't been legalized first, legalize it. This |
| 1747 | // will cause this node to be legalized as well as handling libcalls right. |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1748 | if (LastCALLSEQ_END.getNode() != Node) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1749 | LegalizeOp(SDValue(FindCallStartFromCallEnd(Node), 0)); |
| 1750 | DenseMap<SDValue, SDValue>::iterator I = LegalizedNodes.find(Op); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1751 | assert(I != LegalizedNodes.end() && |
| 1752 | "Legalizing the call start should have legalized this node!"); |
| 1753 | return I->second; |
| 1754 | } |
| 1755 | |
| 1756 | // Otherwise, the call start has been legalized and everything is going |
| 1757 | // according to plan. Just legalize ourselves normally here. |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1758 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | 70814bc | 2006-01-29 07:58:15 +0000 | [diff] [blame] | 1759 | // Do not try to legalize the target-specific arguments (#1+), except for |
| 1760 | // an optional flag input. |
| 1761 | if (Node->getOperand(Node->getNumOperands()-1).getValueType() != MVT::Flag){ |
| 1762 | if (Tmp1 != Node->getOperand(0)) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1763 | SmallVector<SDValue, 8> Ops(Node->op_begin(), Node->op_end()); |
Chris Lattner | 70814bc | 2006-01-29 07:58:15 +0000 | [diff] [blame] | 1764 | Ops[0] = Tmp1; |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1765 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 70814bc | 2006-01-29 07:58:15 +0000 | [diff] [blame] | 1766 | } |
| 1767 | } else { |
| 1768 | Tmp2 = LegalizeOp(Node->getOperand(Node->getNumOperands()-1)); |
| 1769 | if (Tmp1 != Node->getOperand(0) || |
| 1770 | Tmp2 != Node->getOperand(Node->getNumOperands()-1)) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1771 | SmallVector<SDValue, 8> Ops(Node->op_begin(), Node->op_end()); |
Chris Lattner | 70814bc | 2006-01-29 07:58:15 +0000 | [diff] [blame] | 1772 | Ops[0] = Tmp1; |
| 1773 | Ops.back() = Tmp2; |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1774 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 70814bc | 2006-01-29 07:58:15 +0000 | [diff] [blame] | 1775 | } |
Chris Lattner | 6a54289 | 2006-01-24 05:48:21 +0000 | [diff] [blame] | 1776 | } |
Chris Lattner | 4b653a0 | 2006-02-14 00:55:02 +0000 | [diff] [blame] | 1777 | assert(IsLegalizingCall && "Call sequence imbalance between start/end?"); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1778 | // This finishes up call legalization. |
| 1779 | IsLegalizingCall = false; |
Chris Lattner | 4b653a0 | 2006-02-14 00:55:02 +0000 | [diff] [blame] | 1780 | |
| 1781 | // If the CALLSEQ_END node has a flag, remember that we legalized it. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1782 | AddLegalizedOperand(SDValue(Node, 0), Result.getValue(0)); |
Chris Lattner | 4b653a0 | 2006-02-14 00:55:02 +0000 | [diff] [blame] | 1783 | if (Node->getNumValues() == 2) |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1784 | AddLegalizedOperand(SDValue(Node, 1), Result.getValue(1)); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 1785 | return Result.getValue(Op.getResNo()); |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1786 | case ISD::DYNAMIC_STACKALLOC: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1787 | MVT VT = Node->getValueType(0); |
Chris Lattner | fa404e8 | 2005-01-09 19:03:49 +0000 | [diff] [blame] | 1788 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1789 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the size. |
| 1790 | Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the alignment. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1791 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | fa404e8 | 2005-01-09 19:03:49 +0000 | [diff] [blame] | 1792 | |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1793 | Tmp1 = Result.getValue(0); |
Chris Lattner | 5f65229 | 2006-01-15 08:43:08 +0000 | [diff] [blame] | 1794 | Tmp2 = Result.getValue(1); |
Evan Cheng | 61bbbab | 2007-08-16 23:50:06 +0000 | [diff] [blame] | 1795 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1796 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1797 | case TargetLowering::Expand: { |
| 1798 | unsigned SPReg = TLI.getStackPointerRegisterToSaveRestore(); |
| 1799 | assert(SPReg && "Target cannot require DYNAMIC_STACKALLOC expansion and" |
| 1800 | " not tell us which reg is the stack pointer!"); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1801 | SDValue Chain = Tmp1.getOperand(0); |
Bill Wendling | 0f8d9c0 | 2007-11-13 00:44:25 +0000 | [diff] [blame] | 1802 | |
| 1803 | // Chain the dynamic stack allocation so that it doesn't modify the stack |
| 1804 | // pointer when other instructions are using the stack. |
Chris Lattner | e563bbc | 2008-10-11 22:08:30 +0000 | [diff] [blame] | 1805 | Chain = DAG.getCALLSEQ_START(Chain, DAG.getIntPtrConstant(0, true)); |
Bill Wendling | 0f8d9c0 | 2007-11-13 00:44:25 +0000 | [diff] [blame] | 1806 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1807 | SDValue Size = Tmp2.getOperand(1); |
| 1808 | SDValue SP = DAG.getCopyFromReg(Chain, SPReg, VT); |
Evan Cheng | 61bbbab | 2007-08-16 23:50:06 +0000 | [diff] [blame] | 1809 | Chain = SP.getValue(1); |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1810 | unsigned Align = cast<ConstantSDNode>(Tmp3)->getZExtValue(); |
Evan Cheng | 61bbbab | 2007-08-16 23:50:06 +0000 | [diff] [blame] | 1811 | unsigned StackAlign = |
| 1812 | TLI.getTargetMachine().getFrameInfo()->getStackAlignment(); |
| 1813 | if (Align > StackAlign) |
Evan Cheng | 3e20bba | 2007-08-17 18:02:22 +0000 | [diff] [blame] | 1814 | SP = DAG.getNode(ISD::AND, VT, SP, |
| 1815 | DAG.getConstant(-(uint64_t)Align, VT)); |
Evan Cheng | 61bbbab | 2007-08-16 23:50:06 +0000 | [diff] [blame] | 1816 | Tmp1 = DAG.getNode(ISD::SUB, VT, SP, Size); // Value |
Bill Wendling | 0f8d9c0 | 2007-11-13 00:44:25 +0000 | [diff] [blame] | 1817 | Chain = DAG.getCopyToReg(Chain, SPReg, Tmp1); // Output chain |
| 1818 | |
Chris Lattner | e563bbc | 2008-10-11 22:08:30 +0000 | [diff] [blame] | 1819 | Tmp2 = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(0, true), |
| 1820 | DAG.getIntPtrConstant(0, true), SDValue()); |
Bill Wendling | 0f8d9c0 | 2007-11-13 00:44:25 +0000 | [diff] [blame] | 1821 | |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1822 | Tmp1 = LegalizeOp(Tmp1); |
| 1823 | Tmp2 = LegalizeOp(Tmp2); |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1824 | break; |
| 1825 | } |
| 1826 | case TargetLowering::Custom: |
Chris Lattner | 5f65229 | 2006-01-15 08:43:08 +0000 | [diff] [blame] | 1827 | Tmp3 = TLI.LowerOperation(Tmp1, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1828 | if (Tmp3.getNode()) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1829 | Tmp1 = LegalizeOp(Tmp3); |
| 1830 | Tmp2 = LegalizeOp(Tmp3.getValue(1)); |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1831 | } |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1832 | break; |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1833 | case TargetLowering::Legal: |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1834 | break; |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1835 | } |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1836 | // Since this op produce two values, make sure to remember that we |
| 1837 | // legalized both of them. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1838 | AddLegalizedOperand(SDValue(Node, 0), Tmp1); |
| 1839 | AddLegalizedOperand(SDValue(Node, 1), Tmp2); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 1840 | return Op.getResNo() ? Tmp2 : Tmp1; |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1841 | } |
Chris Lattner | 25a022c | 2006-07-11 01:40:09 +0000 | [diff] [blame] | 1842 | case ISD::INLINEASM: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1843 | SmallVector<SDValue, 8> Ops(Node->op_begin(), Node->op_end()); |
Chris Lattner | 25a022c | 2006-07-11 01:40:09 +0000 | [diff] [blame] | 1844 | bool Changed = false; |
| 1845 | // Legalize all of the operands of the inline asm, in case they are nodes |
| 1846 | // that need to be expanded or something. Note we skip the asm string and |
| 1847 | // all of the TargetConstant flags. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1848 | SDValue Op = LegalizeOp(Ops[0]); |
Chris Lattner | 25a022c | 2006-07-11 01:40:09 +0000 | [diff] [blame] | 1849 | Changed = Op != Ops[0]; |
| 1850 | Ops[0] = Op; |
| 1851 | |
| 1852 | bool HasInFlag = Ops.back().getValueType() == MVT::Flag; |
| 1853 | for (unsigned i = 2, e = Ops.size()-HasInFlag; i < e; ) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1854 | unsigned NumVals = cast<ConstantSDNode>(Ops[i])->getZExtValue() >> 3; |
Chris Lattner | 25a022c | 2006-07-11 01:40:09 +0000 | [diff] [blame] | 1855 | for (++i; NumVals; ++i, --NumVals) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1856 | SDValue Op = LegalizeOp(Ops[i]); |
Chris Lattner | 25a022c | 2006-07-11 01:40:09 +0000 | [diff] [blame] | 1857 | if (Op != Ops[i]) { |
| 1858 | Changed = true; |
| 1859 | Ops[i] = Op; |
| 1860 | } |
| 1861 | } |
Chris Lattner | ce7518c | 2006-01-26 22:24:51 +0000 | [diff] [blame] | 1862 | } |
Chris Lattner | 25a022c | 2006-07-11 01:40:09 +0000 | [diff] [blame] | 1863 | |
| 1864 | if (HasInFlag) { |
| 1865 | Op = LegalizeOp(Ops.back()); |
| 1866 | Changed |= Op != Ops.back(); |
| 1867 | Ops.back() = Op; |
| 1868 | } |
| 1869 | |
| 1870 | if (Changed) |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1871 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | ce7518c | 2006-01-26 22:24:51 +0000 | [diff] [blame] | 1872 | |
| 1873 | // INLINE asm returns a chain and flag, make sure to add both to the map. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1874 | AddLegalizedOperand(SDValue(Node, 0), Result.getValue(0)); |
| 1875 | AddLegalizedOperand(SDValue(Node, 1), Result.getValue(1)); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 1876 | return Result.getValue(Op.getResNo()); |
Chris Lattner | 25a022c | 2006-07-11 01:40:09 +0000 | [diff] [blame] | 1877 | } |
Chris Lattner | c7af179 | 2005-01-07 22:12:08 +0000 | [diff] [blame] | 1878 | case ISD::BR: |
| 1879 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1880 | // Ensure that libcalls are emitted before a branch. |
| 1881 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1882 | Tmp1 = LegalizeOp(Tmp1); |
| 1883 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 1884 | |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1885 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
Chris Lattner | c7af179 | 2005-01-07 22:12:08 +0000 | [diff] [blame] | 1886 | break; |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 1887 | case ISD::BRIND: |
| 1888 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1889 | // Ensure that libcalls are emitted before a branch. |
| 1890 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1891 | Tmp1 = LegalizeOp(Tmp1); |
| 1892 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 1893 | |
| 1894 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 1895 | default: assert(0 && "Indirect target must be legal type (pointer)!"); |
| 1896 | case Legal: |
| 1897 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the condition. |
| 1898 | break; |
| 1899 | } |
| 1900 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 1901 | break; |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 1902 | case ISD::BR_JT: |
| 1903 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1904 | // Ensure that libcalls are emitted before a branch. |
| 1905 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1906 | Tmp1 = LegalizeOp(Tmp1); |
| 1907 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 1908 | |
| 1909 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the jumptable node. |
| 1910 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
| 1911 | |
| 1912 | switch (TLI.getOperationAction(ISD::BR_JT, MVT::Other)) { |
| 1913 | default: assert(0 && "This action is not supported yet!"); |
| 1914 | case TargetLowering::Legal: break; |
| 1915 | case TargetLowering::Custom: |
| 1916 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1917 | if (Tmp1.getNode()) Result = Tmp1; |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 1918 | break; |
| 1919 | case TargetLowering::Expand: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1920 | SDValue Chain = Result.getOperand(0); |
| 1921 | SDValue Table = Result.getOperand(1); |
| 1922 | SDValue Index = Result.getOperand(2); |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 1923 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1924 | MVT PTy = TLI.getPointerTy(); |
Jim Laskey | acd80ac | 2006-12-14 19:17:33 +0000 | [diff] [blame] | 1925 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1926 | unsigned EntrySize = MF.getJumpTableInfo()->getEntrySize(); |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 1927 | Index= DAG.getNode(ISD::MUL, PTy, Index, DAG.getConstant(EntrySize, PTy)); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1928 | SDValue Addr = DAG.getNode(ISD::ADD, PTy, Index, Table); |
Jim Laskey | acd80ac | 2006-12-14 19:17:33 +0000 | [diff] [blame] | 1929 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1930 | SDValue LD; |
Jim Laskey | acd80ac | 2006-12-14 19:17:33 +0000 | [diff] [blame] | 1931 | switch (EntrySize) { |
| 1932 | default: assert(0 && "Size of jump table not supported yet."); break; |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 1933 | case 4: LD = DAG.getLoad(MVT::i32, Chain, Addr, |
Dan Gohman | 3069b87 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 1934 | PseudoSourceValue::getJumpTable(), 0); break; |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 1935 | case 8: LD = DAG.getLoad(MVT::i64, Chain, Addr, |
Dan Gohman | 3069b87 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 1936 | PseudoSourceValue::getJumpTable(), 0); break; |
Jim Laskey | acd80ac | 2006-12-14 19:17:33 +0000 | [diff] [blame] | 1937 | } |
| 1938 | |
Evan Cheng | cc41586 | 2007-11-09 01:32:10 +0000 | [diff] [blame] | 1939 | Addr = LD; |
Jim Laskey | acd80ac | 2006-12-14 19:17:33 +0000 | [diff] [blame] | 1940 | if (TLI.getTargetMachine().getRelocationModel() == Reloc::PIC_) { |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 1941 | // For PIC, the sequence is: |
| 1942 | // BRIND(load(Jumptable + index) + RelocBase) |
Evan Cheng | cc41586 | 2007-11-09 01:32:10 +0000 | [diff] [blame] | 1943 | // RelocBase can be JumpTable, GOT or some sort of global base. |
| 1944 | if (PTy != MVT::i32) |
| 1945 | Addr = DAG.getNode(ISD::SIGN_EXTEND, PTy, Addr); |
| 1946 | Addr = DAG.getNode(ISD::ADD, PTy, Addr, |
| 1947 | TLI.getPICJumpTableRelocBase(Table, DAG)); |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 1948 | } |
Evan Cheng | cc41586 | 2007-11-09 01:32:10 +0000 | [diff] [blame] | 1949 | Result = DAG.getNode(ISD::BRIND, MVT::Other, LD.getValue(1), Addr); |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 1950 | } |
| 1951 | } |
| 1952 | break; |
Chris Lattner | c18ae4c | 2005-01-07 08:19:42 +0000 | [diff] [blame] | 1953 | case ISD::BRCOND: |
| 1954 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1955 | // Ensure that libcalls are emitted before a return. |
| 1956 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1957 | Tmp1 = LegalizeOp(Tmp1); |
| 1958 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 1959 | |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 1960 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 1961 | case Expand: assert(0 && "It's impossible to expand bools"); |
| 1962 | case Legal: |
| 1963 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the condition. |
| 1964 | break; |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 1965 | case Promote: { |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 1966 | Tmp2 = PromoteOp(Node->getOperand(1)); // Promote the condition. |
Chris Lattner | f990817 | 2006-11-27 04:39:56 +0000 | [diff] [blame] | 1967 | |
| 1968 | // The top bits of the promoted condition are not necessarily zero, ensure |
| 1969 | // that the value is properly zero extended. |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 1970 | unsigned BitWidth = Tmp2.getValueSizeInBits(); |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1971 | if (!DAG.MaskedValueIsZero(Tmp2, |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 1972 | APInt::getHighBitsSet(BitWidth, BitWidth-1))) |
Chris Lattner | f990817 | 2006-11-27 04:39:56 +0000 | [diff] [blame] | 1973 | Tmp2 = DAG.getZeroExtendInReg(Tmp2, MVT::i1); |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 1974 | break; |
| 1975 | } |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 1976 | } |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 1977 | |
| 1978 | // Basic block destination (Op#2) is always legal. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1979 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 1980 | |
| 1981 | switch (TLI.getOperationAction(ISD::BRCOND, MVT::Other)) { |
| 1982 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 1983 | case TargetLowering::Legal: break; |
| 1984 | case TargetLowering::Custom: |
| 1985 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1986 | if (Tmp1.getNode()) Result = Tmp1; |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 1987 | break; |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 1988 | case TargetLowering::Expand: |
| 1989 | // Expand brcond's setcc into its constituent parts and create a BR_CC |
| 1990 | // Node. |
| 1991 | if (Tmp2.getOpcode() == ISD::SETCC) { |
| 1992 | Result = DAG.getNode(ISD::BR_CC, MVT::Other, Tmp1, Tmp2.getOperand(2), |
| 1993 | Tmp2.getOperand(0), Tmp2.getOperand(1), |
| 1994 | Node->getOperand(2)); |
| 1995 | } else { |
| 1996 | Result = DAG.getNode(ISD::BR_CC, MVT::Other, Tmp1, |
| 1997 | DAG.getCondCode(ISD::SETNE), Tmp2, |
| 1998 | DAG.getConstant(0, Tmp2.getValueType()), |
| 1999 | Node->getOperand(2)); |
| 2000 | } |
| 2001 | break; |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 2002 | } |
| 2003 | break; |
| 2004 | case ISD::BR_CC: |
| 2005 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 2006 | // Ensure that libcalls are emitted before a branch. |
| 2007 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 2008 | Tmp1 = LegalizeOp(Tmp1); |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 2009 | Tmp2 = Node->getOperand(2); // LHS |
| 2010 | Tmp3 = Node->getOperand(3); // RHS |
| 2011 | Tmp4 = Node->getOperand(1); // CC |
| 2012 | |
Dale Johannesen | 53e4e44 | 2008-11-07 22:54:33 +0000 | [diff] [blame] | 2013 | LegalizeSetCC(TLI.getSetCCResultType(Tmp2), Tmp2, Tmp3, Tmp4); |
Evan Cheng | 722cb36 | 2006-12-18 22:55:34 +0000 | [diff] [blame] | 2014 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 2015 | |
Evan Cheng | 7f04268 | 2008-10-15 02:05:31 +0000 | [diff] [blame] | 2016 | // If we didn't get both a LHS and RHS back from LegalizeSetCC, |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 2017 | // the LHS is a legal SETCC itself. In this case, we need to compare |
| 2018 | // the result against zero to select between true and false values. |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2019 | if (Tmp3.getNode() == 0) { |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 2020 | Tmp3 = DAG.getConstant(0, Tmp2.getValueType()); |
| 2021 | Tmp4 = DAG.getCondCode(ISD::SETNE); |
Chris Lattner | 181b7a3 | 2005-12-17 23:46:46 +0000 | [diff] [blame] | 2022 | } |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 2023 | |
| 2024 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp4, Tmp2, Tmp3, |
| 2025 | Node->getOperand(4)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2026 | |
Chris Lattner | 181b7a3 | 2005-12-17 23:46:46 +0000 | [diff] [blame] | 2027 | switch (TLI.getOperationAction(ISD::BR_CC, Tmp3.getValueType())) { |
| 2028 | default: assert(0 && "Unexpected action for BR_CC!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2029 | case TargetLowering::Legal: break; |
| 2030 | case TargetLowering::Custom: |
| 2031 | Tmp4 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2032 | if (Tmp4.getNode()) Result = Tmp4; |
Chris Lattner | 181b7a3 | 2005-12-17 23:46:46 +0000 | [diff] [blame] | 2033 | break; |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 2034 | } |
Chris Lattner | c18ae4c | 2005-01-07 08:19:42 +0000 | [diff] [blame] | 2035 | break; |
Evan Cheng | f3fd9fe | 2005-12-23 07:29:34 +0000 | [diff] [blame] | 2036 | case ISD::LOAD: { |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2037 | LoadSDNode *LD = cast<LoadSDNode>(Node); |
| 2038 | Tmp1 = LegalizeOp(LD->getChain()); // Legalize the chain. |
| 2039 | Tmp2 = LegalizeOp(LD->getBasePtr()); // Legalize the base pointer. |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 2040 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2041 | ISD::LoadExtType ExtType = LD->getExtensionType(); |
| 2042 | if (ExtType == ISD::NON_EXTLOAD) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2043 | MVT VT = Node->getValueType(0); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2044 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, LD->getOffset()); |
| 2045 | Tmp3 = Result.getValue(0); |
| 2046 | Tmp4 = Result.getValue(1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2047 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2048 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 2049 | default: assert(0 && "This action is not supported yet!"); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2050 | case TargetLowering::Legal: |
| 2051 | // If this is an unaligned load and the target doesn't support it, |
| 2052 | // expand it. |
| 2053 | if (!TLI.allowsUnalignedMemoryAccesses()) { |
| 2054 | unsigned ABIAlignment = TLI.getTargetData()-> |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2055 | getABITypeAlignment(LD->getMemoryVT().getTypeForMVT()); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2056 | if (LD->getAlignment() < ABIAlignment){ |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2057 | Result = ExpandUnalignedLoad(cast<LoadSDNode>(Result.getNode()), DAG, |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2058 | TLI); |
| 2059 | Tmp3 = Result.getOperand(0); |
| 2060 | Tmp4 = Result.getOperand(1); |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 2061 | Tmp3 = LegalizeOp(Tmp3); |
| 2062 | Tmp4 = LegalizeOp(Tmp4); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2063 | } |
| 2064 | } |
| 2065 | break; |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2066 | case TargetLowering::Custom: |
| 2067 | Tmp1 = TLI.LowerOperation(Tmp3, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2068 | if (Tmp1.getNode()) { |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2069 | Tmp3 = LegalizeOp(Tmp1); |
| 2070 | Tmp4 = LegalizeOp(Tmp1.getValue(1)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2071 | } |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2072 | break; |
| 2073 | case TargetLowering::Promote: { |
| 2074 | // Only promote a load of vector type to another. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2075 | assert(VT.isVector() && "Cannot promote this load!"); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2076 | // Change base type to a different vector type. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2077 | MVT NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), VT); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2078 | |
| 2079 | Tmp1 = DAG.getLoad(NVT, Tmp1, Tmp2, LD->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2080 | LD->getSrcValueOffset(), |
| 2081 | LD->isVolatile(), LD->getAlignment()); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2082 | Tmp3 = LegalizeOp(DAG.getNode(ISD::BIT_CONVERT, VT, Tmp1)); |
| 2083 | Tmp4 = LegalizeOp(Tmp1.getValue(1)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2084 | break; |
Andrew Lenharth | 9d416f7 | 2005-06-30 19:22:37 +0000 | [diff] [blame] | 2085 | } |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2086 | } |
| 2087 | // Since loads produce two values, make sure to remember that we |
| 2088 | // legalized both of them. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2089 | AddLegalizedOperand(SDValue(Node, 0), Tmp3); |
| 2090 | AddLegalizedOperand(SDValue(Node, 1), Tmp4); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 2091 | return Op.getResNo() ? Tmp4 : Tmp3; |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2092 | } else { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2093 | MVT SrcVT = LD->getMemoryVT(); |
| 2094 | unsigned SrcWidth = SrcVT.getSizeInBits(); |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2095 | int SVOffset = LD->getSrcValueOffset(); |
| 2096 | unsigned Alignment = LD->getAlignment(); |
| 2097 | bool isVolatile = LD->isVolatile(); |
| 2098 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2099 | if (SrcWidth != SrcVT.getStoreSizeInBits() && |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2100 | // Some targets pretend to have an i1 loading operation, and actually |
| 2101 | // load an i8. This trick is correct for ZEXTLOAD because the top 7 |
| 2102 | // bits are guaranteed to be zero; it helps the optimizers understand |
| 2103 | // that these bits are zero. It is also useful for EXTLOAD, since it |
| 2104 | // tells the optimizers that those bits are undefined. It would be |
| 2105 | // nice to have an effective generic way of getting these benefits... |
| 2106 | // Until such a way is found, don't insist on promoting i1 here. |
| 2107 | (SrcVT != MVT::i1 || |
Evan Cheng | 0329466 | 2008-10-14 21:26:46 +0000 | [diff] [blame] | 2108 | TLI.getLoadExtAction(ExtType, MVT::i1) == TargetLowering::Promote)) { |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2109 | // Promote to a byte-sized load if not loading an integral number of |
| 2110 | // bytes. For example, promote EXTLOAD:i20 -> EXTLOAD:i24. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2111 | unsigned NewWidth = SrcVT.getStoreSizeInBits(); |
| 2112 | MVT NVT = MVT::getIntegerVT(NewWidth); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2113 | SDValue Ch; |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2114 | |
| 2115 | // The extra bits are guaranteed to be zero, since we stored them that |
| 2116 | // way. A zext load from NVT thus automatically gives zext from SrcVT. |
| 2117 | |
| 2118 | ISD::LoadExtType NewExtType = |
| 2119 | ExtType == ISD::ZEXTLOAD ? ISD::ZEXTLOAD : ISD::EXTLOAD; |
| 2120 | |
| 2121 | Result = DAG.getExtLoad(NewExtType, Node->getValueType(0), |
| 2122 | Tmp1, Tmp2, LD->getSrcValue(), SVOffset, |
| 2123 | NVT, isVolatile, Alignment); |
| 2124 | |
| 2125 | Ch = Result.getValue(1); // The chain. |
| 2126 | |
| 2127 | if (ExtType == ISD::SEXTLOAD) |
| 2128 | // Having the top bits zero doesn't help when sign extending. |
| 2129 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(), |
| 2130 | Result, DAG.getValueType(SrcVT)); |
| 2131 | else if (ExtType == ISD::ZEXTLOAD || NVT == Result.getValueType()) |
| 2132 | // All the top bits are guaranteed to be zero - inform the optimizers. |
| 2133 | Result = DAG.getNode(ISD::AssertZext, Result.getValueType(), Result, |
| 2134 | DAG.getValueType(SrcVT)); |
| 2135 | |
| 2136 | Tmp1 = LegalizeOp(Result); |
| 2137 | Tmp2 = LegalizeOp(Ch); |
| 2138 | } else if (SrcWidth & (SrcWidth - 1)) { |
| 2139 | // If not loading a power-of-2 number of bits, expand as two loads. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2140 | assert(SrcVT.isExtended() && !SrcVT.isVector() && |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2141 | "Unsupported extload!"); |
| 2142 | unsigned RoundWidth = 1 << Log2_32(SrcWidth); |
| 2143 | assert(RoundWidth < SrcWidth); |
| 2144 | unsigned ExtraWidth = SrcWidth - RoundWidth; |
| 2145 | assert(ExtraWidth < RoundWidth); |
| 2146 | assert(!(RoundWidth % 8) && !(ExtraWidth % 8) && |
| 2147 | "Load size not an integral number of bytes!"); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2148 | MVT RoundVT = MVT::getIntegerVT(RoundWidth); |
| 2149 | MVT ExtraVT = MVT::getIntegerVT(ExtraWidth); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2150 | SDValue Lo, Hi, Ch; |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2151 | unsigned IncrementSize; |
| 2152 | |
| 2153 | if (TLI.isLittleEndian()) { |
| 2154 | // EXTLOAD:i24 -> ZEXTLOAD:i16 | (shl EXTLOAD@+2:i8, 16) |
| 2155 | // Load the bottom RoundWidth bits. |
| 2156 | Lo = DAG.getExtLoad(ISD::ZEXTLOAD, Node->getValueType(0), Tmp1, Tmp2, |
| 2157 | LD->getSrcValue(), SVOffset, RoundVT, isVolatile, |
| 2158 | Alignment); |
| 2159 | |
| 2160 | // Load the remaining ExtraWidth bits. |
| 2161 | IncrementSize = RoundWidth / 8; |
| 2162 | Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2, |
| 2163 | DAG.getIntPtrConstant(IncrementSize)); |
| 2164 | Hi = DAG.getExtLoad(ExtType, Node->getValueType(0), Tmp1, Tmp2, |
| 2165 | LD->getSrcValue(), SVOffset + IncrementSize, |
| 2166 | ExtraVT, isVolatile, |
| 2167 | MinAlign(Alignment, IncrementSize)); |
| 2168 | |
| 2169 | // Build a factor node to remember that this load is independent of the |
| 2170 | // other one. |
| 2171 | Ch = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1), |
| 2172 | Hi.getValue(1)); |
| 2173 | |
| 2174 | // Move the top bits to the right place. |
| 2175 | Hi = DAG.getNode(ISD::SHL, Hi.getValueType(), Hi, |
| 2176 | DAG.getConstant(RoundWidth, TLI.getShiftAmountTy())); |
| 2177 | |
| 2178 | // Join the hi and lo parts. |
| 2179 | Result = DAG.getNode(ISD::OR, Node->getValueType(0), Lo, Hi); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2180 | } else { |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2181 | // Big endian - avoid unaligned loads. |
| 2182 | // EXTLOAD:i24 -> (shl EXTLOAD:i16, 8) | ZEXTLOAD@+2:i8 |
| 2183 | // Load the top RoundWidth bits. |
| 2184 | Hi = DAG.getExtLoad(ExtType, Node->getValueType(0), Tmp1, Tmp2, |
| 2185 | LD->getSrcValue(), SVOffset, RoundVT, isVolatile, |
| 2186 | Alignment); |
| 2187 | |
| 2188 | // Load the remaining ExtraWidth bits. |
| 2189 | IncrementSize = RoundWidth / 8; |
| 2190 | Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2, |
| 2191 | DAG.getIntPtrConstant(IncrementSize)); |
| 2192 | Lo = DAG.getExtLoad(ISD::ZEXTLOAD, Node->getValueType(0), Tmp1, Tmp2, |
| 2193 | LD->getSrcValue(), SVOffset + IncrementSize, |
| 2194 | ExtraVT, isVolatile, |
| 2195 | MinAlign(Alignment, IncrementSize)); |
| 2196 | |
| 2197 | // Build a factor node to remember that this load is independent of the |
| 2198 | // other one. |
| 2199 | Ch = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1), |
| 2200 | Hi.getValue(1)); |
| 2201 | |
| 2202 | // Move the top bits to the right place. |
| 2203 | Hi = DAG.getNode(ISD::SHL, Hi.getValueType(), Hi, |
| 2204 | DAG.getConstant(ExtraWidth, TLI.getShiftAmountTy())); |
| 2205 | |
| 2206 | // Join the hi and lo parts. |
| 2207 | Result = DAG.getNode(ISD::OR, Node->getValueType(0), Lo, Hi); |
| 2208 | } |
| 2209 | |
| 2210 | Tmp1 = LegalizeOp(Result); |
| 2211 | Tmp2 = LegalizeOp(Ch); |
| 2212 | } else { |
Evan Cheng | 0329466 | 2008-10-14 21:26:46 +0000 | [diff] [blame] | 2213 | switch (TLI.getLoadExtAction(ExtType, SrcVT)) { |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2214 | default: assert(0 && "This action is not supported yet!"); |
| 2215 | case TargetLowering::Custom: |
| 2216 | isCustom = true; |
| 2217 | // FALLTHROUGH |
| 2218 | case TargetLowering::Legal: |
| 2219 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, LD->getOffset()); |
| 2220 | Tmp1 = Result.getValue(0); |
| 2221 | Tmp2 = Result.getValue(1); |
| 2222 | |
| 2223 | if (isCustom) { |
| 2224 | Tmp3 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2225 | if (Tmp3.getNode()) { |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2226 | Tmp1 = LegalizeOp(Tmp3); |
| 2227 | Tmp2 = LegalizeOp(Tmp3.getValue(1)); |
| 2228 | } |
| 2229 | } else { |
| 2230 | // If this is an unaligned load and the target doesn't support it, |
| 2231 | // expand it. |
| 2232 | if (!TLI.allowsUnalignedMemoryAccesses()) { |
| 2233 | unsigned ABIAlignment = TLI.getTargetData()-> |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2234 | getABITypeAlignment(LD->getMemoryVT().getTypeForMVT()); |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2235 | if (LD->getAlignment() < ABIAlignment){ |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2236 | Result = ExpandUnalignedLoad(cast<LoadSDNode>(Result.getNode()), DAG, |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2237 | TLI); |
| 2238 | Tmp1 = Result.getOperand(0); |
| 2239 | Tmp2 = Result.getOperand(1); |
| 2240 | Tmp1 = LegalizeOp(Tmp1); |
| 2241 | Tmp2 = LegalizeOp(Tmp2); |
| 2242 | } |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2243 | } |
| 2244 | } |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2245 | break; |
| 2246 | case TargetLowering::Expand: |
| 2247 | // f64 = EXTLOAD f32 should expand to LOAD, FP_EXTEND |
| 2248 | if (SrcVT == MVT::f32 && Node->getValueType(0) == MVT::f64) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2249 | SDValue Load = DAG.getLoad(SrcVT, Tmp1, Tmp2, LD->getSrcValue(), |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2250 | LD->getSrcValueOffset(), |
| 2251 | LD->isVolatile(), LD->getAlignment()); |
| 2252 | Result = DAG.getNode(ISD::FP_EXTEND, Node->getValueType(0), Load); |
| 2253 | Tmp1 = LegalizeOp(Result); // Relegalize new nodes. |
| 2254 | Tmp2 = LegalizeOp(Load.getValue(1)); |
| 2255 | break; |
| 2256 | } |
| 2257 | assert(ExtType != ISD::EXTLOAD &&"EXTLOAD should always be supported!"); |
| 2258 | // Turn the unsupported load into an EXTLOAD followed by an explicit |
| 2259 | // zero/sign extend inreg. |
| 2260 | Result = DAG.getExtLoad(ISD::EXTLOAD, Node->getValueType(0), |
| 2261 | Tmp1, Tmp2, LD->getSrcValue(), |
| 2262 | LD->getSrcValueOffset(), SrcVT, |
| 2263 | LD->isVolatile(), LD->getAlignment()); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2264 | SDValue ValRes; |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2265 | if (ExtType == ISD::SEXTLOAD) |
| 2266 | ValRes = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(), |
| 2267 | Result, DAG.getValueType(SrcVT)); |
| 2268 | else |
| 2269 | ValRes = DAG.getZeroExtendInReg(Result, SrcVT); |
| 2270 | Tmp1 = LegalizeOp(ValRes); // Relegalize new nodes. |
| 2271 | Tmp2 = LegalizeOp(Result.getValue(1)); // Relegalize new nodes. |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2272 | break; |
| 2273 | } |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2274 | } |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2275 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2276 | // Since loads produce two values, make sure to remember that we legalized |
| 2277 | // both of them. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2278 | AddLegalizedOperand(SDValue(Node, 0), Tmp1); |
| 2279 | AddLegalizedOperand(SDValue(Node, 1), Tmp2); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 2280 | return Op.getResNo() ? Tmp2 : Tmp1; |
Chris Lattner | 01ff721 | 2005-04-10 22:54:25 +0000 | [diff] [blame] | 2281 | } |
Chris Lattner | 01ff721 | 2005-04-10 22:54:25 +0000 | [diff] [blame] | 2282 | } |
Nate Begeman | 5dc897b | 2005-10-19 00:06:56 +0000 | [diff] [blame] | 2283 | case ISD::EXTRACT_ELEMENT: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2284 | MVT OpTy = Node->getOperand(0).getValueType(); |
Nate Begeman | 5dc897b | 2005-10-19 00:06:56 +0000 | [diff] [blame] | 2285 | switch (getTypeAction(OpTy)) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2286 | default: assert(0 && "EXTRACT_ELEMENT action for type unimplemented!"); |
Nate Begeman | 5dc897b | 2005-10-19 00:06:56 +0000 | [diff] [blame] | 2287 | case Legal: |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2288 | if (cast<ConstantSDNode>(Node->getOperand(1))->getZExtValue()) { |
Nate Begeman | 5dc897b | 2005-10-19 00:06:56 +0000 | [diff] [blame] | 2289 | // 1 -> Hi |
| 2290 | Result = DAG.getNode(ISD::SRL, OpTy, Node->getOperand(0), |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2291 | DAG.getConstant(OpTy.getSizeInBits()/2, |
Nate Begeman | 5dc897b | 2005-10-19 00:06:56 +0000 | [diff] [blame] | 2292 | TLI.getShiftAmountTy())); |
| 2293 | Result = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0), Result); |
| 2294 | } else { |
| 2295 | // 0 -> Lo |
| 2296 | Result = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0), |
| 2297 | Node->getOperand(0)); |
| 2298 | } |
Nate Begeman | 5dc897b | 2005-10-19 00:06:56 +0000 | [diff] [blame] | 2299 | break; |
| 2300 | case Expand: |
| 2301 | // Get both the low and high parts. |
| 2302 | ExpandOp(Node->getOperand(0), Tmp1, Tmp2); |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2303 | if (cast<ConstantSDNode>(Node->getOperand(1))->getZExtValue()) |
Nate Begeman | 5dc897b | 2005-10-19 00:06:56 +0000 | [diff] [blame] | 2304 | Result = Tmp2; // 1 -> Hi |
| 2305 | else |
| 2306 | Result = Tmp1; // 0 -> Lo |
| 2307 | break; |
| 2308 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2309 | break; |
Nate Begeman | 5dc897b | 2005-10-19 00:06:56 +0000 | [diff] [blame] | 2310 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2311 | |
| 2312 | case ISD::CopyToReg: |
| 2313 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2314 | |
Chris Lattner | c9c60f6 | 2005-08-24 16:35:28 +0000 | [diff] [blame] | 2315 | assert(isTypeLegal(Node->getOperand(2).getValueType()) && |
Chris Lattner | d5d0f9b | 2005-08-16 21:55:35 +0000 | [diff] [blame] | 2316 | "Register type must be legal!"); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 2317 | // Legalize the incoming value (must be a legal type). |
Chris Lattner | d5d0f9b | 2005-08-16 21:55:35 +0000 | [diff] [blame] | 2318 | Tmp2 = LegalizeOp(Node->getOperand(2)); |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 2319 | if (Node->getNumValues() == 1) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2320 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1), Tmp2); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 2321 | } else { |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 2322 | assert(Node->getNumValues() == 2 && "Unknown CopyToReg"); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2323 | if (Node->getNumOperands() == 4) { |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 2324 | Tmp3 = LegalizeOp(Node->getOperand(3)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2325 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1), Tmp2, |
| 2326 | Tmp3); |
| 2327 | } else { |
| 2328 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1),Tmp2); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 2329 | } |
| 2330 | |
| 2331 | // Since this produces two values, make sure to remember that we legalized |
| 2332 | // both of them. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2333 | AddLegalizedOperand(SDValue(Node, 0), Result.getValue(0)); |
| 2334 | AddLegalizedOperand(SDValue(Node, 1), Result.getValue(1)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2335 | return Result; |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 2336 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2337 | break; |
| 2338 | |
| 2339 | case ISD::RET: |
| 2340 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 2341 | |
| 2342 | // Ensure that libcalls are emitted before a return. |
| 2343 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 2344 | Tmp1 = LegalizeOp(Tmp1); |
| 2345 | LastCALLSEQ_END = DAG.getEntryNode(); |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2346 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2347 | switch (Node->getNumOperands()) { |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 2348 | case 3: // ret val |
Evan Cheng | 98f8aeb | 2006-04-11 06:33:39 +0000 | [diff] [blame] | 2349 | Tmp2 = Node->getOperand(1); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 2350 | Tmp3 = Node->getOperand(2); // Signness |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2351 | switch (getTypeAction(Tmp2.getValueType())) { |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2352 | case Legal: |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 2353 | Result = DAG.UpdateNodeOperands(Result, Tmp1, LegalizeOp(Tmp2), Tmp3); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2354 | break; |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2355 | case Expand: |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2356 | if (!Tmp2.getValueType().isVector()) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2357 | SDValue Lo, Hi; |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2358 | ExpandOp(Tmp2, Lo, Hi); |
Chris Lattner | edf2e8d | 2007-03-06 20:01:06 +0000 | [diff] [blame] | 2359 | |
| 2360 | // Big endian systems want the hi reg first. |
Duncan Sands | 0753fc1 | 2008-02-11 10:37:04 +0000 | [diff] [blame] | 2361 | if (TLI.isBigEndian()) |
Chris Lattner | edf2e8d | 2007-03-06 20:01:06 +0000 | [diff] [blame] | 2362 | std::swap(Lo, Hi); |
| 2363 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2364 | if (Hi.getNode()) |
Evan Cheng | 13acce3 | 2006-12-11 19:27:14 +0000 | [diff] [blame] | 2365 | Result = DAG.getNode(ISD::RET, MVT::Other, Tmp1, Lo, Tmp3, Hi,Tmp3); |
| 2366 | else |
| 2367 | Result = DAG.getNode(ISD::RET, MVT::Other, Tmp1, Lo, Tmp3); |
Chris Lattner | f921a51 | 2006-08-21 20:24:53 +0000 | [diff] [blame] | 2368 | Result = LegalizeOp(Result); |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2369 | } else { |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2370 | SDNode *InVal = Tmp2.getNode(); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 2371 | int InIx = Tmp2.getResNo(); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2372 | unsigned NumElems = InVal->getValueType(InIx).getVectorNumElements(); |
| 2373 | MVT EVT = InVal->getValueType(InIx).getVectorElementType(); |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2374 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2375 | // Figure out if there is a simple type corresponding to this Vector |
Reid Spencer | ac9dcb9 | 2007-02-15 03:39:18 +0000 | [diff] [blame] | 2376 | // type. If so, convert to the vector type. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2377 | MVT TVT = MVT::getVectorVT(EVT, NumElems); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2378 | if (TLI.isTypeLegal(TVT)) { |
Reid Spencer | ac9dcb9 | 2007-02-15 03:39:18 +0000 | [diff] [blame] | 2379 | // Turn this into a return of the vector type. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2380 | Tmp2 = LegalizeOp(Tmp2); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 2381 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2382 | } else if (NumElems == 1) { |
| 2383 | // Turn this into a return of the scalar type. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2384 | Tmp2 = ScalarizeVectorOp(Tmp2); |
| 2385 | Tmp2 = LegalizeOp(Tmp2); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 2386 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | b49e52c | 2006-04-11 02:00:08 +0000 | [diff] [blame] | 2387 | |
| 2388 | // FIXME: Returns of gcc generic vectors smaller than a legal type |
| 2389 | // should be returned in integer registers! |
| 2390 | |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2391 | // The scalarized value type may not be legal, e.g. it might require |
| 2392 | // promotion or expansion. Relegalize the return. |
| 2393 | Result = LegalizeOp(Result); |
| 2394 | } else { |
Chris Lattner | b49e52c | 2006-04-11 02:00:08 +0000 | [diff] [blame] | 2395 | // FIXME: Returns of gcc generic vectors larger than a legal vector |
| 2396 | // type should be returned by reference! |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2397 | SDValue Lo, Hi; |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2398 | SplitVectorOp(Tmp2, Lo, Hi); |
Chris Lattner | fea997a | 2007-02-01 04:55:59 +0000 | [diff] [blame] | 2399 | Result = DAG.getNode(ISD::RET, MVT::Other, Tmp1, Lo, Tmp3, Hi,Tmp3); |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2400 | Result = LegalizeOp(Result); |
| 2401 | } |
| 2402 | } |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2403 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2404 | case Promote: |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 2405 | Tmp2 = PromoteOp(Node->getOperand(1)); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 2406 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2407 | Result = LegalizeOp(Result); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 2408 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2409 | } |
| 2410 | break; |
| 2411 | case 1: // ret void |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2412 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2413 | break; |
| 2414 | default: { // ret <values> |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2415 | SmallVector<SDValue, 8> NewValues; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2416 | NewValues.push_back(Tmp1); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 2417 | for (unsigned i = 1, e = Node->getNumOperands(); i < e; i += 2) |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2418 | switch (getTypeAction(Node->getOperand(i).getValueType())) { |
| 2419 | case Legal: |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 2420 | NewValues.push_back(LegalizeOp(Node->getOperand(i))); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 2421 | NewValues.push_back(Node->getOperand(i+1)); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2422 | break; |
| 2423 | case Expand: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2424 | SDValue Lo, Hi; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2425 | assert(!Node->getOperand(i).getValueType().isExtended() && |
Chris Lattner | b49e52c | 2006-04-11 02:00:08 +0000 | [diff] [blame] | 2426 | "FIXME: TODO: implement returning non-legal vector types!"); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2427 | ExpandOp(Node->getOperand(i), Lo, Hi); |
| 2428 | NewValues.push_back(Lo); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 2429 | NewValues.push_back(Node->getOperand(i+1)); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2430 | if (Hi.getNode()) { |
Evan Cheng | 13acce3 | 2006-12-11 19:27:14 +0000 | [diff] [blame] | 2431 | NewValues.push_back(Hi); |
| 2432 | NewValues.push_back(Node->getOperand(i+1)); |
| 2433 | } |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2434 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2435 | } |
| 2436 | case Promote: |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 2437 | assert(0 && "Can't promote multiple return value yet!"); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2438 | } |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2439 | |
| 2440 | if (NewValues.size() == Node->getNumOperands()) |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 2441 | Result = DAG.UpdateNodeOperands(Result, &NewValues[0],NewValues.size()); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2442 | else |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 2443 | Result = DAG.getNode(ISD::RET, MVT::Other, |
| 2444 | &NewValues[0], NewValues.size()); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2445 | break; |
| 2446 | } |
| 2447 | } |
Evan Cheng | 17c428e | 2006-01-06 00:41:43 +0000 | [diff] [blame] | 2448 | |
Chris Lattner | 6862dbc | 2006-01-29 21:02:23 +0000 | [diff] [blame] | 2449 | if (Result.getOpcode() == ISD::RET) { |
| 2450 | switch (TLI.getOperationAction(Result.getOpcode(), MVT::Other)) { |
| 2451 | default: assert(0 && "This action is not supported yet!"); |
| 2452 | case TargetLowering::Legal: break; |
| 2453 | case TargetLowering::Custom: |
| 2454 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2455 | if (Tmp1.getNode()) Result = Tmp1; |
Chris Lattner | 6862dbc | 2006-01-29 21:02:23 +0000 | [diff] [blame] | 2456 | break; |
| 2457 | } |
Evan Cheng | 17c428e | 2006-01-06 00:41:43 +0000 | [diff] [blame] | 2458 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2459 | break; |
Evan Cheng | f3fd9fe | 2005-12-23 07:29:34 +0000 | [diff] [blame] | 2460 | case ISD::STORE: { |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2461 | StoreSDNode *ST = cast<StoreSDNode>(Node); |
| 2462 | Tmp1 = LegalizeOp(ST->getChain()); // Legalize the chain. |
| 2463 | Tmp2 = LegalizeOp(ST->getBasePtr()); // Legalize the pointer. |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2464 | int SVOffset = ST->getSrcValueOffset(); |
| 2465 | unsigned Alignment = ST->getAlignment(); |
| 2466 | bool isVolatile = ST->isVolatile(); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2467 | |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2468 | if (!ST->isTruncatingStore()) { |
Chris Lattner | d93d46e | 2006-12-12 04:18:56 +0000 | [diff] [blame] | 2469 | // Turn 'store float 1.0, Ptr' -> 'store int 0x12345678, Ptr' |
| 2470 | // FIXME: We shouldn't do this for TargetConstantFP's. |
| 2471 | // FIXME: move this to the DAG Combiner! Note that we can't regress due |
| 2472 | // to phase ordering between legalized code and the dag combiner. This |
| 2473 | // probably means that we need to integrate dag combiner and legalizer |
| 2474 | // together. |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 2475 | // We generally can't do this one for long doubles. |
Chris Lattner | 2b4c279 | 2007-10-13 06:35:54 +0000 | [diff] [blame] | 2476 | if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(ST->getValue())) { |
Chris Lattner | 3cb9351 | 2007-10-15 05:46:06 +0000 | [diff] [blame] | 2477 | if (CFP->getValueType(0) == MVT::f32 && |
| 2478 | getTypeAction(MVT::i32) == Legal) { |
Dan Gohman | 6cf9b8a | 2008-03-11 00:11:06 +0000 | [diff] [blame] | 2479 | Tmp3 = DAG.getConstant(CFP->getValueAPF(). |
Dale Johannesen | 7111b02 | 2008-10-09 18:53:47 +0000 | [diff] [blame] | 2480 | bitcastToAPInt().zextOrTrunc(32), |
Dale Johannesen | 3f6eb74 | 2007-09-11 18:32:33 +0000 | [diff] [blame] | 2481 | MVT::i32); |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 2482 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
| 2483 | SVOffset, isVolatile, Alignment); |
| 2484 | break; |
| 2485 | } else if (CFP->getValueType(0) == MVT::f64) { |
Chris Lattner | 3cb9351 | 2007-10-15 05:46:06 +0000 | [diff] [blame] | 2486 | // If this target supports 64-bit registers, do a single 64-bit store. |
| 2487 | if (getTypeAction(MVT::i64) == Legal) { |
Dale Johannesen | 7111b02 | 2008-10-09 18:53:47 +0000 | [diff] [blame] | 2488 | Tmp3 = DAG.getConstant(CFP->getValueAPF().bitcastToAPInt(). |
Dan Gohman | 6cf9b8a | 2008-03-11 00:11:06 +0000 | [diff] [blame] | 2489 | zextOrTrunc(64), MVT::i64); |
Chris Lattner | 3cb9351 | 2007-10-15 05:46:06 +0000 | [diff] [blame] | 2490 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
| 2491 | SVOffset, isVolatile, Alignment); |
| 2492 | break; |
Duncan Sands | d4b9c17 | 2008-06-13 19:07:40 +0000 | [diff] [blame] | 2493 | } else if (getTypeAction(MVT::i32) == Legal && !ST->isVolatile()) { |
Chris Lattner | 3cb9351 | 2007-10-15 05:46:06 +0000 | [diff] [blame] | 2494 | // Otherwise, if the target supports 32-bit registers, use 2 32-bit |
| 2495 | // stores. If the target supports neither 32- nor 64-bits, this |
| 2496 | // xform is certainly not worth it. |
Dale Johannesen | 7111b02 | 2008-10-09 18:53:47 +0000 | [diff] [blame] | 2497 | const APInt &IntVal =CFP->getValueAPF().bitcastToAPInt(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2498 | SDValue Lo = DAG.getConstant(APInt(IntVal).trunc(32), MVT::i32); |
| 2499 | SDValue Hi = DAG.getConstant(IntVal.lshr(32).trunc(32), MVT::i32); |
Duncan Sands | 0753fc1 | 2008-02-11 10:37:04 +0000 | [diff] [blame] | 2500 | if (TLI.isBigEndian()) std::swap(Lo, Hi); |
Chris Lattner | 3cb9351 | 2007-10-15 05:46:06 +0000 | [diff] [blame] | 2501 | |
| 2502 | Lo = DAG.getStore(Tmp1, Lo, Tmp2, ST->getSrcValue(), |
| 2503 | SVOffset, isVolatile, Alignment); |
| 2504 | Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2, |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 2505 | DAG.getIntPtrConstant(4)); |
Chris Lattner | 3cb9351 | 2007-10-15 05:46:06 +0000 | [diff] [blame] | 2506 | Hi = DAG.getStore(Tmp1, Hi, Tmp2, ST->getSrcValue(), SVOffset+4, |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 2507 | isVolatile, MinAlign(Alignment, 4U)); |
Chris Lattner | 3cb9351 | 2007-10-15 05:46:06 +0000 | [diff] [blame] | 2508 | |
| 2509 | Result = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo, Hi); |
| 2510 | break; |
| 2511 | } |
Chris Lattner | d93d46e | 2006-12-12 04:18:56 +0000 | [diff] [blame] | 2512 | } |
Chris Lattner | d93d46e | 2006-12-12 04:18:56 +0000 | [diff] [blame] | 2513 | } |
| 2514 | |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 2515 | switch (getTypeAction(ST->getMemoryVT())) { |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2516 | case Legal: { |
| 2517 | Tmp3 = LegalizeOp(ST->getValue()); |
| 2518 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp3, Tmp2, |
| 2519 | ST->getOffset()); |
Evan Cheng | f3fd9fe | 2005-12-23 07:29:34 +0000 | [diff] [blame] | 2520 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2521 | MVT VT = Tmp3.getValueType(); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2522 | switch (TLI.getOperationAction(ISD::STORE, VT)) { |
| 2523 | default: assert(0 && "This action is not supported yet!"); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2524 | case TargetLowering::Legal: |
| 2525 | // If this is an unaligned store and the target doesn't support it, |
| 2526 | // expand it. |
| 2527 | if (!TLI.allowsUnalignedMemoryAccesses()) { |
| 2528 | unsigned ABIAlignment = TLI.getTargetData()-> |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2529 | getABITypeAlignment(ST->getMemoryVT().getTypeForMVT()); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2530 | if (ST->getAlignment() < ABIAlignment) |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2531 | Result = ExpandUnalignedStore(cast<StoreSDNode>(Result.getNode()), DAG, |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2532 | TLI); |
| 2533 | } |
| 2534 | break; |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2535 | case TargetLowering::Custom: |
| 2536 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2537 | if (Tmp1.getNode()) Result = Tmp1; |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2538 | break; |
| 2539 | case TargetLowering::Promote: |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2540 | assert(VT.isVector() && "Unknown legal promote case!"); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2541 | Tmp3 = DAG.getNode(ISD::BIT_CONVERT, |
| 2542 | TLI.getTypeToPromoteTo(ISD::STORE, VT), Tmp3); |
| 2543 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2544 | ST->getSrcValue(), SVOffset, isVolatile, |
| 2545 | Alignment); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2546 | break; |
| 2547 | } |
| 2548 | break; |
| 2549 | } |
| 2550 | case Promote: |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 2551 | if (!ST->getMemoryVT().isVector()) { |
| 2552 | // Truncate the value and store the result. |
| 2553 | Tmp3 = PromoteOp(ST->getValue()); |
| 2554 | Result = DAG.getTruncStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
| 2555 | SVOffset, ST->getMemoryVT(), |
| 2556 | isVolatile, Alignment); |
| 2557 | break; |
| 2558 | } |
| 2559 | // Fall thru to expand for vector |
| 2560 | case Expand: { |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2561 | unsigned IncrementSize = 0; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2562 | SDValue Lo, Hi; |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2563 | |
| 2564 | // If this is a vector type, then we have to calculate the increment as |
| 2565 | // the product of the element size in bytes, and the number of elements |
| 2566 | // in the high half of the vector. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2567 | if (ST->getValue().getValueType().isVector()) { |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2568 | SDNode *InVal = ST->getValue().getNode(); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 2569 | int InIx = ST->getValue().getResNo(); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2570 | MVT InVT = InVal->getValueType(InIx); |
| 2571 | unsigned NumElems = InVT.getVectorNumElements(); |
| 2572 | MVT EVT = InVT.getVectorElementType(); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2573 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2574 | // Figure out if there is a simple type corresponding to this Vector |
Reid Spencer | ac9dcb9 | 2007-02-15 03:39:18 +0000 | [diff] [blame] | 2575 | // type. If so, convert to the vector type. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2576 | MVT TVT = MVT::getVectorVT(EVT, NumElems); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2577 | if (TLI.isTypeLegal(TVT)) { |
Reid Spencer | ac9dcb9 | 2007-02-15 03:39:18 +0000 | [diff] [blame] | 2578 | // Turn this into a normal store of the vector type. |
Dan Gohman | 21be384 | 2008-02-15 18:11:59 +0000 | [diff] [blame] | 2579 | Tmp3 = LegalizeOp(ST->getValue()); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2580 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2581 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2582 | Result = LegalizeOp(Result); |
| 2583 | break; |
| 2584 | } else if (NumElems == 1) { |
| 2585 | // Turn this into a normal store of the scalar type. |
Dan Gohman | 21be384 | 2008-02-15 18:11:59 +0000 | [diff] [blame] | 2586 | Tmp3 = ScalarizeVectorOp(ST->getValue()); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2587 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2588 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2589 | // The scalarized value type may not be legal, e.g. it might require |
| 2590 | // promotion or expansion. Relegalize the scalar store. |
| 2591 | Result = LegalizeOp(Result); |
| 2592 | break; |
| 2593 | } else { |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 2594 | // Check if we have widen this node with another value |
| 2595 | std::map<SDValue, SDValue>::iterator I = |
| 2596 | WidenNodes.find(ST->getValue()); |
| 2597 | if (I != WidenNodes.end()) { |
| 2598 | Result = StoreWidenVectorOp(ST, Tmp1, Tmp2); |
| 2599 | break; |
| 2600 | } |
| 2601 | else { |
| 2602 | SplitVectorOp(ST->getValue(), Lo, Hi); |
| 2603 | IncrementSize = Lo.getNode()->getValueType(0).getVectorNumElements() * |
| 2604 | EVT.getSizeInBits()/8; |
| 2605 | } |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2606 | } |
| 2607 | } else { |
Dan Gohman | 21be384 | 2008-02-15 18:11:59 +0000 | [diff] [blame] | 2608 | ExpandOp(ST->getValue(), Lo, Hi); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2609 | IncrementSize = Hi.getNode() ? Hi.getValueType().getSizeInBits()/8 : 0; |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2610 | |
Richard Pennington | 4b052dc | 2008-09-25 16:15:10 +0000 | [diff] [blame] | 2611 | if (Hi.getNode() && TLI.isBigEndian()) |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2612 | std::swap(Lo, Hi); |
| 2613 | } |
| 2614 | |
| 2615 | Lo = DAG.getStore(Tmp1, Lo, Tmp2, ST->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2616 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 7b2b5c8 | 2006-12-12 19:53:13 +0000 | [diff] [blame] | 2617 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2618 | if (Hi.getNode() == NULL) { |
Evan Cheng | 7b2b5c8 | 2006-12-12 19:53:13 +0000 | [diff] [blame] | 2619 | // Must be int <-> float one-to-one expansion. |
| 2620 | Result = Lo; |
| 2621 | break; |
| 2622 | } |
| 2623 | |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2624 | Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2, |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 2625 | DAG.getIntPtrConstant(IncrementSize)); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2626 | assert(isTypeLegal(Tmp2.getValueType()) && |
| 2627 | "Pointers must be legal!"); |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2628 | SVOffset += IncrementSize; |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 2629 | Alignment = MinAlign(Alignment, IncrementSize); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2630 | Hi = DAG.getStore(Tmp1, Hi, Tmp2, ST->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2631 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2632 | Result = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo, Hi); |
| 2633 | break; |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 2634 | } // case Expand |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2635 | } |
| 2636 | } else { |
Chris Lattner | ddf8956 | 2008-01-17 19:59:44 +0000 | [diff] [blame] | 2637 | switch (getTypeAction(ST->getValue().getValueType())) { |
| 2638 | case Legal: |
| 2639 | Tmp3 = LegalizeOp(ST->getValue()); |
| 2640 | break; |
| 2641 | case Promote: |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 2642 | if (!ST->getValue().getValueType().isVector()) { |
| 2643 | // We can promote the value, the truncstore will still take care of it. |
| 2644 | Tmp3 = PromoteOp(ST->getValue()); |
| 2645 | break; |
| 2646 | } |
| 2647 | // Vector case falls through to expand |
Chris Lattner | ddf8956 | 2008-01-17 19:59:44 +0000 | [diff] [blame] | 2648 | case Expand: |
| 2649 | // Just store the low part. This may become a non-trunc store, so make |
| 2650 | // sure to use getTruncStore, not UpdateNodeOperands below. |
| 2651 | ExpandOp(ST->getValue(), Tmp3, Tmp4); |
| 2652 | return DAG.getTruncStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
| 2653 | SVOffset, MVT::i8, isVolatile, Alignment); |
| 2654 | } |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2655 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2656 | MVT StVT = ST->getMemoryVT(); |
| 2657 | unsigned StWidth = StVT.getSizeInBits(); |
Duncan Sands | 7e85720 | 2008-01-22 07:17:34 +0000 | [diff] [blame] | 2658 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2659 | if (StWidth != StVT.getStoreSizeInBits()) { |
Duncan Sands | 7e85720 | 2008-01-22 07:17:34 +0000 | [diff] [blame] | 2660 | // Promote to a byte-sized store with upper bits zero if not |
| 2661 | // storing an integral number of bytes. For example, promote |
| 2662 | // TRUNCSTORE:i1 X -> TRUNCSTORE:i8 (and X, 1) |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2663 | MVT NVT = MVT::getIntegerVT(StVT.getStoreSizeInBits()); |
Duncan Sands | 7e85720 | 2008-01-22 07:17:34 +0000 | [diff] [blame] | 2664 | Tmp3 = DAG.getZeroExtendInReg(Tmp3, StVT); |
| 2665 | Result = DAG.getTruncStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
| 2666 | SVOffset, NVT, isVolatile, Alignment); |
| 2667 | } else if (StWidth & (StWidth - 1)) { |
| 2668 | // If not storing a power-of-2 number of bits, expand as two stores. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2669 | assert(StVT.isExtended() && !StVT.isVector() && |
Duncan Sands | 7e85720 | 2008-01-22 07:17:34 +0000 | [diff] [blame] | 2670 | "Unsupported truncstore!"); |
| 2671 | unsigned RoundWidth = 1 << Log2_32(StWidth); |
| 2672 | assert(RoundWidth < StWidth); |
| 2673 | unsigned ExtraWidth = StWidth - RoundWidth; |
| 2674 | assert(ExtraWidth < RoundWidth); |
| 2675 | assert(!(RoundWidth % 8) && !(ExtraWidth % 8) && |
| 2676 | "Store size not an integral number of bytes!"); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2677 | MVT RoundVT = MVT::getIntegerVT(RoundWidth); |
| 2678 | MVT ExtraVT = MVT::getIntegerVT(ExtraWidth); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2679 | SDValue Lo, Hi; |
Duncan Sands | 7e85720 | 2008-01-22 07:17:34 +0000 | [diff] [blame] | 2680 | unsigned IncrementSize; |
| 2681 | |
| 2682 | if (TLI.isLittleEndian()) { |
| 2683 | // TRUNCSTORE:i24 X -> TRUNCSTORE:i16 X, TRUNCSTORE@+2:i8 (srl X, 16) |
| 2684 | // Store the bottom RoundWidth bits. |
| 2685 | Lo = DAG.getTruncStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
| 2686 | SVOffset, RoundVT, |
| 2687 | isVolatile, Alignment); |
| 2688 | |
| 2689 | // Store the remaining ExtraWidth bits. |
| 2690 | IncrementSize = RoundWidth / 8; |
| 2691 | Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2, |
| 2692 | DAG.getIntPtrConstant(IncrementSize)); |
| 2693 | Hi = DAG.getNode(ISD::SRL, Tmp3.getValueType(), Tmp3, |
| 2694 | DAG.getConstant(RoundWidth, TLI.getShiftAmountTy())); |
| 2695 | Hi = DAG.getTruncStore(Tmp1, Hi, Tmp2, ST->getSrcValue(), |
| 2696 | SVOffset + IncrementSize, ExtraVT, isVolatile, |
| 2697 | MinAlign(Alignment, IncrementSize)); |
| 2698 | } else { |
| 2699 | // Big endian - avoid unaligned stores. |
| 2700 | // TRUNCSTORE:i24 X -> TRUNCSTORE:i16 (srl X, 8), TRUNCSTORE@+2:i8 X |
| 2701 | // Store the top RoundWidth bits. |
| 2702 | Hi = DAG.getNode(ISD::SRL, Tmp3.getValueType(), Tmp3, |
| 2703 | DAG.getConstant(ExtraWidth, TLI.getShiftAmountTy())); |
| 2704 | Hi = DAG.getTruncStore(Tmp1, Hi, Tmp2, ST->getSrcValue(), SVOffset, |
| 2705 | RoundVT, isVolatile, Alignment); |
| 2706 | |
| 2707 | // Store the remaining ExtraWidth bits. |
| 2708 | IncrementSize = RoundWidth / 8; |
| 2709 | Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2, |
| 2710 | DAG.getIntPtrConstant(IncrementSize)); |
| 2711 | Lo = DAG.getTruncStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
| 2712 | SVOffset + IncrementSize, ExtraVT, isVolatile, |
| 2713 | MinAlign(Alignment, IncrementSize)); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2714 | } |
Duncan Sands | 7e85720 | 2008-01-22 07:17:34 +0000 | [diff] [blame] | 2715 | |
| 2716 | // The order of the stores doesn't matter. |
| 2717 | Result = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo, Hi); |
| 2718 | } else { |
| 2719 | if (Tmp1 != ST->getChain() || Tmp3 != ST->getValue() || |
| 2720 | Tmp2 != ST->getBasePtr()) |
| 2721 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp3, Tmp2, |
| 2722 | ST->getOffset()); |
| 2723 | |
| 2724 | switch (TLI.getTruncStoreAction(ST->getValue().getValueType(), StVT)) { |
| 2725 | default: assert(0 && "This action is not supported yet!"); |
| 2726 | case TargetLowering::Legal: |
| 2727 | // If this is an unaligned store and the target doesn't support it, |
| 2728 | // expand it. |
| 2729 | if (!TLI.allowsUnalignedMemoryAccesses()) { |
| 2730 | unsigned ABIAlignment = TLI.getTargetData()-> |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2731 | getABITypeAlignment(ST->getMemoryVT().getTypeForMVT()); |
Duncan Sands | 7e85720 | 2008-01-22 07:17:34 +0000 | [diff] [blame] | 2732 | if (ST->getAlignment() < ABIAlignment) |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2733 | Result = ExpandUnalignedStore(cast<StoreSDNode>(Result.getNode()), DAG, |
Duncan Sands | 7e85720 | 2008-01-22 07:17:34 +0000 | [diff] [blame] | 2734 | TLI); |
| 2735 | } |
| 2736 | break; |
| 2737 | case TargetLowering::Custom: |
| 2738 | Result = TLI.LowerOperation(Result, DAG); |
| 2739 | break; |
| 2740 | case Expand: |
| 2741 | // TRUNCSTORE:i16 i32 -> STORE i16 |
| 2742 | assert(isTypeLegal(StVT) && "Do not know how to expand this store!"); |
| 2743 | Tmp3 = DAG.getNode(ISD::TRUNCATE, StVT, Tmp3); |
| 2744 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), SVOffset, |
| 2745 | isVolatile, Alignment); |
| 2746 | break; |
| 2747 | } |
Evan Cheng | f3fd9fe | 2005-12-23 07:29:34 +0000 | [diff] [blame] | 2748 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2749 | } |
| 2750 | break; |
Evan Cheng | f3fd9fe | 2005-12-23 07:29:34 +0000 | [diff] [blame] | 2751 | } |
Andrew Lenharth | 9576212 | 2005-03-31 21:24:06 +0000 | [diff] [blame] | 2752 | case ISD::PCMARKER: |
| 2753 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2754 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
Andrew Lenharth | 9576212 | 2005-03-31 21:24:06 +0000 | [diff] [blame] | 2755 | break; |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2756 | case ISD::STACKSAVE: |
| 2757 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2758 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 2759 | Tmp1 = Result.getValue(0); |
| 2760 | Tmp2 = Result.getValue(1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2761 | |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2762 | switch (TLI.getOperationAction(ISD::STACKSAVE, MVT::Other)) { |
| 2763 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2764 | case TargetLowering::Legal: break; |
| 2765 | case TargetLowering::Custom: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2766 | Tmp3 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2767 | if (Tmp3.getNode()) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2768 | Tmp1 = LegalizeOp(Tmp3); |
| 2769 | Tmp2 = LegalizeOp(Tmp3.getValue(1)); |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2770 | } |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2771 | break; |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2772 | case TargetLowering::Expand: |
Chris Lattner | 4f0d8e4 | 2006-01-13 17:48:44 +0000 | [diff] [blame] | 2773 | // Expand to CopyFromReg if the target set |
| 2774 | // StackPointerRegisterToSaveRestore. |
| 2775 | if (unsigned SP = TLI.getStackPointerRegisterToSaveRestore()) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2776 | Tmp1 = DAG.getCopyFromReg(Result.getOperand(0), SP, |
Chris Lattner | 4f0d8e4 | 2006-01-13 17:48:44 +0000 | [diff] [blame] | 2777 | Node->getValueType(0)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2778 | Tmp2 = Tmp1.getValue(1); |
Chris Lattner | 4f0d8e4 | 2006-01-13 17:48:44 +0000 | [diff] [blame] | 2779 | } else { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2780 | Tmp1 = DAG.getNode(ISD::UNDEF, Node->getValueType(0)); |
| 2781 | Tmp2 = Node->getOperand(0); |
Chris Lattner | 4f0d8e4 | 2006-01-13 17:48:44 +0000 | [diff] [blame] | 2782 | } |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2783 | break; |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2784 | } |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2785 | |
| 2786 | // Since stacksave produce two values, make sure to remember that we |
| 2787 | // legalized both of them. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2788 | AddLegalizedOperand(SDValue(Node, 0), Tmp1); |
| 2789 | AddLegalizedOperand(SDValue(Node, 1), Tmp2); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 2790 | return Op.getResNo() ? Tmp2 : Tmp1; |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2791 | |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2792 | case ISD::STACKRESTORE: |
| 2793 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 2794 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2795 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2796 | |
| 2797 | switch (TLI.getOperationAction(ISD::STACKRESTORE, MVT::Other)) { |
| 2798 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2799 | case TargetLowering::Legal: break; |
| 2800 | case TargetLowering::Custom: |
| 2801 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2802 | if (Tmp1.getNode()) Result = Tmp1; |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2803 | break; |
| 2804 | case TargetLowering::Expand: |
Chris Lattner | 4f0d8e4 | 2006-01-13 17:48:44 +0000 | [diff] [blame] | 2805 | // Expand to CopyToReg if the target set |
| 2806 | // StackPointerRegisterToSaveRestore. |
| 2807 | if (unsigned SP = TLI.getStackPointerRegisterToSaveRestore()) { |
| 2808 | Result = DAG.getCopyToReg(Tmp1, SP, Tmp2); |
| 2809 | } else { |
| 2810 | Result = Tmp1; |
| 2811 | } |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2812 | break; |
| 2813 | } |
| 2814 | break; |
| 2815 | |
Andrew Lenharth | 51b8d54 | 2005-11-11 16:47:30 +0000 | [diff] [blame] | 2816 | case ISD::READCYCLECOUNTER: |
| 2817 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2818 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Evan Cheng | f0b3ba6 | 2006-11-29 08:26:18 +0000 | [diff] [blame] | 2819 | switch (TLI.getOperationAction(ISD::READCYCLECOUNTER, |
| 2820 | Node->getValueType(0))) { |
| 2821 | default: assert(0 && "This action is not supported yet!"); |
Evan Cheng | 6a16c5a | 2006-11-29 19:13:47 +0000 | [diff] [blame] | 2822 | case TargetLowering::Legal: |
| 2823 | Tmp1 = Result.getValue(0); |
| 2824 | Tmp2 = Result.getValue(1); |
| 2825 | break; |
Evan Cheng | f0b3ba6 | 2006-11-29 08:26:18 +0000 | [diff] [blame] | 2826 | case TargetLowering::Custom: |
| 2827 | Result = TLI.LowerOperation(Result, DAG); |
Evan Cheng | 6a16c5a | 2006-11-29 19:13:47 +0000 | [diff] [blame] | 2828 | Tmp1 = LegalizeOp(Result.getValue(0)); |
| 2829 | Tmp2 = LegalizeOp(Result.getValue(1)); |
Evan Cheng | f0b3ba6 | 2006-11-29 08:26:18 +0000 | [diff] [blame] | 2830 | break; |
| 2831 | } |
Andrew Lenharth | 49c709f | 2005-12-02 04:56:24 +0000 | [diff] [blame] | 2832 | |
| 2833 | // Since rdcc produce two values, make sure to remember that we legalized |
| 2834 | // both of them. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2835 | AddLegalizedOperand(SDValue(Node, 0), Tmp1); |
| 2836 | AddLegalizedOperand(SDValue(Node, 1), Tmp2); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2837 | return Result; |
Andrew Lenharth | f70e30b | 2005-11-20 21:32:07 +0000 | [diff] [blame] | 2838 | |
Chris Lattner | 2ee743f | 2005-01-14 22:08:15 +0000 | [diff] [blame] | 2839 | case ISD::SELECT: |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 2840 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 2841 | case Expand: assert(0 && "It's impossible to expand bools"); |
| 2842 | case Legal: |
| 2843 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the condition. |
| 2844 | break; |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 2845 | case Promote: { |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 2846 | assert(!Node->getOperand(0).getValueType().isVector() && "not possible"); |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 2847 | Tmp1 = PromoteOp(Node->getOperand(0)); // Promote the condition. |
Chris Lattner | b6c8060 | 2006-11-28 01:03:30 +0000 | [diff] [blame] | 2848 | // Make sure the condition is either zero or one. |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 2849 | unsigned BitWidth = Tmp1.getValueSizeInBits(); |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2850 | if (!DAG.MaskedValueIsZero(Tmp1, |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 2851 | APInt::getHighBitsSet(BitWidth, BitWidth-1))) |
Chris Lattner | b6c8060 | 2006-11-28 01:03:30 +0000 | [diff] [blame] | 2852 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, MVT::i1); |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 2853 | break; |
| 2854 | } |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 2855 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2856 | Tmp2 = LegalizeOp(Node->getOperand(1)); // TrueVal |
Chris Lattner | 2ee743f | 2005-01-14 22:08:15 +0000 | [diff] [blame] | 2857 | Tmp3 = LegalizeOp(Node->getOperand(2)); // FalseVal |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2858 | |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2859 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2860 | |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 2861 | switch (TLI.getOperationAction(ISD::SELECT, Tmp2.getValueType())) { |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2862 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2863 | case TargetLowering::Legal: break; |
| 2864 | case TargetLowering::Custom: { |
| 2865 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2866 | if (Tmp1.getNode()) Result = Tmp1; |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2867 | break; |
| 2868 | } |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 2869 | case TargetLowering::Expand: |
| 2870 | if (Tmp1.getOpcode() == ISD::SETCC) { |
| 2871 | Result = DAG.getSelectCC(Tmp1.getOperand(0), Tmp1.getOperand(1), |
| 2872 | Tmp2, Tmp3, |
| 2873 | cast<CondCodeSDNode>(Tmp1.getOperand(2))->get()); |
| 2874 | } else { |
| 2875 | Result = DAG.getSelectCC(Tmp1, |
| 2876 | DAG.getConstant(0, Tmp1.getValueType()), |
| 2877 | Tmp2, Tmp3, ISD::SETNE); |
| 2878 | } |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2879 | break; |
| 2880 | case TargetLowering::Promote: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2881 | MVT NVT = |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2882 | TLI.getTypeToPromoteTo(ISD::SELECT, Tmp2.getValueType()); |
| 2883 | unsigned ExtOp, TruncOp; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2884 | if (Tmp2.getValueType().isVector()) { |
Evan Cheng | 41f6cbb | 2006-04-12 16:33:18 +0000 | [diff] [blame] | 2885 | ExtOp = ISD::BIT_CONVERT; |
| 2886 | TruncOp = ISD::BIT_CONVERT; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2887 | } else if (Tmp2.getValueType().isInteger()) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2888 | ExtOp = ISD::ANY_EXTEND; |
| 2889 | TruncOp = ISD::TRUNCATE; |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2890 | } else { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2891 | ExtOp = ISD::FP_EXTEND; |
| 2892 | TruncOp = ISD::FP_ROUND; |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2893 | } |
| 2894 | // Promote each of the values to the new type. |
| 2895 | Tmp2 = DAG.getNode(ExtOp, NVT, Tmp2); |
| 2896 | Tmp3 = DAG.getNode(ExtOp, NVT, Tmp3); |
| 2897 | // Perform the larger operation, then round down. |
| 2898 | Result = DAG.getNode(ISD::SELECT, NVT, Tmp1, Tmp2,Tmp3); |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 2899 | if (TruncOp != ISD::FP_ROUND) |
| 2900 | Result = DAG.getNode(TruncOp, Node->getValueType(0), Result); |
| 2901 | else |
| 2902 | Result = DAG.getNode(TruncOp, Node->getValueType(0), Result, |
| 2903 | DAG.getIntPtrConstant(0)); |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2904 | break; |
| 2905 | } |
| 2906 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2907 | break; |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 2908 | case ISD::SELECT_CC: { |
| 2909 | Tmp1 = Node->getOperand(0); // LHS |
| 2910 | Tmp2 = Node->getOperand(1); // RHS |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 2911 | Tmp3 = LegalizeOp(Node->getOperand(2)); // True |
| 2912 | Tmp4 = LegalizeOp(Node->getOperand(3)); // False |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2913 | SDValue CC = Node->getOperand(4); |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 2914 | |
Dale Johannesen | 53e4e44 | 2008-11-07 22:54:33 +0000 | [diff] [blame] | 2915 | LegalizeSetCC(TLI.getSetCCResultType(Tmp1), Tmp1, Tmp2, CC); |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 2916 | |
Evan Cheng | 7f04268 | 2008-10-15 02:05:31 +0000 | [diff] [blame] | 2917 | // If we didn't get both a LHS and RHS back from LegalizeSetCC, |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 2918 | // the LHS is a legal SETCC itself. In this case, we need to compare |
| 2919 | // the result against zero to select between true and false values. |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2920 | if (Tmp2.getNode() == 0) { |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 2921 | Tmp2 = DAG.getConstant(0, Tmp1.getValueType()); |
| 2922 | CC = DAG.getCondCode(ISD::SETNE); |
| 2923 | } |
| 2924 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3, Tmp4, CC); |
| 2925 | |
| 2926 | // Everything is legal, see if we should expand this op or something. |
| 2927 | switch (TLI.getOperationAction(ISD::SELECT_CC, Tmp3.getValueType())) { |
| 2928 | default: assert(0 && "This action is not supported yet!"); |
| 2929 | case TargetLowering::Legal: break; |
| 2930 | case TargetLowering::Custom: |
| 2931 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2932 | if (Tmp1.getNode()) Result = Tmp1; |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 2933 | break; |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 2934 | } |
| 2935 | break; |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 2936 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2937 | case ISD::SETCC: |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 2938 | Tmp1 = Node->getOperand(0); |
| 2939 | Tmp2 = Node->getOperand(1); |
| 2940 | Tmp3 = Node->getOperand(2); |
Evan Cheng | 7f04268 | 2008-10-15 02:05:31 +0000 | [diff] [blame] | 2941 | LegalizeSetCC(Node->getValueType(0), Tmp1, Tmp2, Tmp3); |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 2942 | |
| 2943 | // If we had to Expand the SetCC operands into a SELECT node, then it may |
| 2944 | // not always be possible to return a true LHS & RHS. In this case, just |
| 2945 | // return the value we legalized, returned in the LHS |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2946 | if (Tmp2.getNode() == 0) { |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 2947 | Result = Tmp1; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2948 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2949 | } |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 2950 | |
Chris Lattner | 73e142f | 2006-01-30 22:43:50 +0000 | [diff] [blame] | 2951 | switch (TLI.getOperationAction(ISD::SETCC, Tmp1.getValueType())) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2952 | default: assert(0 && "Cannot handle this action for SETCC yet!"); |
| 2953 | case TargetLowering::Custom: |
| 2954 | isCustom = true; |
| 2955 | // FALLTHROUGH. |
| 2956 | case TargetLowering::Legal: |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 2957 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2958 | if (isCustom) { |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 2959 | Tmp4 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2960 | if (Tmp4.getNode()) Result = Tmp4; |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2961 | } |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 2962 | break; |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 2963 | case TargetLowering::Promote: { |
| 2964 | // First step, figure out the appropriate operation to use. |
| 2965 | // Allow SETCC to not be supported for all legal data types |
| 2966 | // Mostly this targets FP |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2967 | MVT NewInTy = Node->getOperand(0).getValueType(); |
| 2968 | MVT OldVT = NewInTy; OldVT = OldVT; |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 2969 | |
| 2970 | // Scan for the appropriate larger type to use. |
| 2971 | while (1) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2972 | NewInTy = (MVT::SimpleValueType)(NewInTy.getSimpleVT()+1); |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 2973 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2974 | assert(NewInTy.isInteger() == OldVT.isInteger() && |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 2975 | "Fell off of the edge of the integer world"); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2976 | assert(NewInTy.isFloatingPoint() == OldVT.isFloatingPoint() && |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 2977 | "Fell off of the edge of the floating point world"); |
| 2978 | |
| 2979 | // If the target supports SETCC of this type, use it. |
Chris Lattner | 1ccf26a | 2005-12-22 05:23:45 +0000 | [diff] [blame] | 2980 | if (TLI.isOperationLegal(ISD::SETCC, NewInTy)) |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 2981 | break; |
| 2982 | } |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2983 | if (NewInTy.isInteger()) |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 2984 | assert(0 && "Cannot promote Legal Integer SETCC yet"); |
| 2985 | else { |
| 2986 | Tmp1 = DAG.getNode(ISD::FP_EXTEND, NewInTy, Tmp1); |
| 2987 | Tmp2 = DAG.getNode(ISD::FP_EXTEND, NewInTy, Tmp2); |
| 2988 | } |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2989 | Tmp1 = LegalizeOp(Tmp1); |
| 2990 | Tmp2 = LegalizeOp(Tmp2); |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 2991 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Evan Cheng | 433f8ac | 2006-01-17 19:47:13 +0000 | [diff] [blame] | 2992 | Result = LegalizeOp(Result); |
Andrew Lenharth | 5e3efbc | 2005-08-29 20:46:51 +0000 | [diff] [blame] | 2993 | break; |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 2994 | } |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 2995 | case TargetLowering::Expand: |
| 2996 | // Expand a setcc node into a select_cc of the same condition, lhs, and |
| 2997 | // rhs that selects between const 1 (true) and const 0 (false). |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2998 | MVT VT = Node->getValueType(0); |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 2999 | Result = DAG.getNode(ISD::SELECT_CC, VT, Tmp1, Tmp2, |
| 3000 | DAG.getConstant(1, VT), DAG.getConstant(0, VT), |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 3001 | Tmp3); |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 3002 | break; |
| 3003 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3004 | break; |
Nate Begeman | b43e9c1 | 2008-05-12 19:40:03 +0000 | [diff] [blame] | 3005 | case ISD::VSETCC: { |
| 3006 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
| 3007 | Tmp2 = LegalizeOp(Node->getOperand(1)); // RHS |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3008 | SDValue CC = Node->getOperand(2); |
Nate Begeman | b43e9c1 | 2008-05-12 19:40:03 +0000 | [diff] [blame] | 3009 | |
| 3010 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, CC); |
| 3011 | |
| 3012 | // Everything is legal, see if we should expand this op or something. |
| 3013 | switch (TLI.getOperationAction(ISD::VSETCC, Tmp1.getValueType())) { |
| 3014 | default: assert(0 && "This action is not supported yet!"); |
| 3015 | case TargetLowering::Legal: break; |
| 3016 | case TargetLowering::Custom: |
| 3017 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3018 | if (Tmp1.getNode()) Result = Tmp1; |
Nate Begeman | b43e9c1 | 2008-05-12 19:40:03 +0000 | [diff] [blame] | 3019 | break; |
| 3020 | } |
| 3021 | break; |
| 3022 | } |
Chris Lattner | 52d08bd | 2005-05-09 20:23:03 +0000 | [diff] [blame] | 3023 | |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 3024 | case ISD::SHL_PARTS: |
| 3025 | case ISD::SRA_PARTS: |
| 3026 | case ISD::SRL_PARTS: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3027 | SmallVector<SDValue, 8> Ops; |
Chris Lattner | 84f6788 | 2005-01-20 18:52:28 +0000 | [diff] [blame] | 3028 | bool Changed = false; |
| 3029 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) { |
| 3030 | Ops.push_back(LegalizeOp(Node->getOperand(i))); |
| 3031 | Changed |= Ops.back() != Node->getOperand(i); |
| 3032 | } |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3033 | if (Changed) |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 3034 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3035 | |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 3036 | switch (TLI.getOperationAction(Node->getOpcode(), |
| 3037 | Node->getValueType(0))) { |
| 3038 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3039 | case TargetLowering::Legal: break; |
| 3040 | case TargetLowering::Custom: |
| 3041 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3042 | if (Tmp1.getNode()) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3043 | SDValue Tmp2, RetVal(0, 0); |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 3044 | for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3045 | Tmp2 = LegalizeOp(Tmp1.getValue(i)); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3046 | AddLegalizedOperand(SDValue(Node, i), Tmp2); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 3047 | if (i == Op.getResNo()) |
Evan Cheng | 12f2274 | 2006-01-19 04:54:52 +0000 | [diff] [blame] | 3048 | RetVal = Tmp2; |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 3049 | } |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3050 | assert(RetVal.getNode() && "Illegal result number"); |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 3051 | return RetVal; |
| 3052 | } |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 3053 | break; |
| 3054 | } |
| 3055 | |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3056 | // Since these produce multiple values, make sure to remember that we |
| 3057 | // legalized all of them. |
| 3058 | for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3059 | AddLegalizedOperand(SDValue(Node, i), Result.getValue(i)); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 3060 | return Result.getValue(Op.getResNo()); |
Chris Lattner | 84f6788 | 2005-01-20 18:52:28 +0000 | [diff] [blame] | 3061 | } |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3062 | |
| 3063 | // Binary operators |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3064 | case ISD::ADD: |
| 3065 | case ISD::SUB: |
| 3066 | case ISD::MUL: |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 3067 | case ISD::MULHS: |
| 3068 | case ISD::MULHU: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3069 | case ISD::UDIV: |
| 3070 | case ISD::SDIV: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3071 | case ISD::AND: |
| 3072 | case ISD::OR: |
| 3073 | case ISD::XOR: |
Chris Lattner | 03c0cf8 | 2005-01-07 21:45:56 +0000 | [diff] [blame] | 3074 | case ISD::SHL: |
| 3075 | case ISD::SRL: |
| 3076 | case ISD::SRA: |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 3077 | case ISD::FADD: |
| 3078 | case ISD::FSUB: |
| 3079 | case ISD::FMUL: |
| 3080 | case ISD::FDIV: |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3081 | case ISD::FPOW: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3082 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
Andrew Lenharth | f2eb139 | 2005-07-05 19:52:39 +0000 | [diff] [blame] | 3083 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 3084 | case Expand: assert(0 && "Not possible"); |
| 3085 | case Legal: |
| 3086 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the RHS. |
| 3087 | break; |
| 3088 | case Promote: |
| 3089 | Tmp2 = PromoteOp(Node->getOperand(1)); // Promote the RHS. |
| 3090 | break; |
| 3091 | } |
Nate Begeman | 5bc1ea0 | 2008-07-29 15:49:41 +0000 | [diff] [blame] | 3092 | |
| 3093 | if ((Node->getOpcode() == ISD::SHL || |
| 3094 | Node->getOpcode() == ISD::SRL || |
| 3095 | Node->getOpcode() == ISD::SRA) && |
| 3096 | !Node->getValueType(0).isVector()) { |
| 3097 | if (TLI.getShiftAmountTy().bitsLT(Tmp2.getValueType())) |
| 3098 | Tmp2 = DAG.getNode(ISD::TRUNCATE, TLI.getShiftAmountTy(), Tmp2); |
| 3099 | else if (TLI.getShiftAmountTy().bitsGT(Tmp2.getValueType())) |
| 3100 | Tmp2 = DAG.getNode(ISD::ANY_EXTEND, TLI.getShiftAmountTy(), Tmp2); |
| 3101 | } |
| 3102 | |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3103 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Mon P Wang | aeb06d2 | 2008-11-10 04:46:22 +0000 | [diff] [blame] | 3104 | |
Andrew Lenharth | e8f65f1 | 2005-12-24 23:42:32 +0000 | [diff] [blame] | 3105 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
Chris Lattner | bc70cf8 | 2006-04-02 03:57:31 +0000 | [diff] [blame] | 3106 | default: assert(0 && "BinOp legalize operation not supported"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3107 | case TargetLowering::Legal: break; |
| 3108 | case TargetLowering::Custom: |
| 3109 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3110 | if (Tmp1.getNode()) { |
Nate Begeman | 5bc1ea0 | 2008-07-29 15:49:41 +0000 | [diff] [blame] | 3111 | Result = Tmp1; |
| 3112 | break; |
Nate Begeman | 24dc346 | 2008-07-29 19:07:27 +0000 | [diff] [blame] | 3113 | } |
Nate Begeman | 5bc1ea0 | 2008-07-29 15:49:41 +0000 | [diff] [blame] | 3114 | // Fall through if the custom lower can't deal with the operation |
Chris Lattner | bc70cf8 | 2006-04-02 03:57:31 +0000 | [diff] [blame] | 3115 | case TargetLowering::Expand: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3116 | MVT VT = Op.getValueType(); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 3117 | |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3118 | // See if multiply or divide can be lowered using two-result operations. |
| 3119 | SDVTList VTs = DAG.getVTList(VT, VT); |
| 3120 | if (Node->getOpcode() == ISD::MUL) { |
| 3121 | // We just need the low half of the multiply; try both the signed |
| 3122 | // and unsigned forms. If the target supports both SMUL_LOHI and |
| 3123 | // UMUL_LOHI, form a preference by checking which forms of plain |
| 3124 | // MULH it supports. |
| 3125 | bool HasSMUL_LOHI = TLI.isOperationLegal(ISD::SMUL_LOHI, VT); |
| 3126 | bool HasUMUL_LOHI = TLI.isOperationLegal(ISD::UMUL_LOHI, VT); |
| 3127 | bool HasMULHS = TLI.isOperationLegal(ISD::MULHS, VT); |
| 3128 | bool HasMULHU = TLI.isOperationLegal(ISD::MULHU, VT); |
| 3129 | unsigned OpToUse = 0; |
| 3130 | if (HasSMUL_LOHI && !HasMULHS) { |
| 3131 | OpToUse = ISD::SMUL_LOHI; |
| 3132 | } else if (HasUMUL_LOHI && !HasMULHU) { |
| 3133 | OpToUse = ISD::UMUL_LOHI; |
| 3134 | } else if (HasSMUL_LOHI) { |
| 3135 | OpToUse = ISD::SMUL_LOHI; |
| 3136 | } else if (HasUMUL_LOHI) { |
| 3137 | OpToUse = ISD::UMUL_LOHI; |
| 3138 | } |
| 3139 | if (OpToUse) { |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3140 | Result = SDValue(DAG.getNode(OpToUse, VTs, Tmp1, Tmp2).getNode(), 0); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3141 | break; |
| 3142 | } |
| 3143 | } |
| 3144 | if (Node->getOpcode() == ISD::MULHS && |
| 3145 | TLI.isOperationLegal(ISD::SMUL_LOHI, VT)) { |
Chris Lattner | 31d7161 | 2008-10-04 21:27:46 +0000 | [diff] [blame] | 3146 | Result = SDValue(DAG.getNode(ISD::SMUL_LOHI, VTs, Tmp1, Tmp2).getNode(), |
| 3147 | 1); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3148 | break; |
| 3149 | } |
| 3150 | if (Node->getOpcode() == ISD::MULHU && |
| 3151 | TLI.isOperationLegal(ISD::UMUL_LOHI, VT)) { |
Chris Lattner | 31d7161 | 2008-10-04 21:27:46 +0000 | [diff] [blame] | 3152 | Result = SDValue(DAG.getNode(ISD::UMUL_LOHI, VTs, Tmp1, Tmp2).getNode(), |
| 3153 | 1); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3154 | break; |
| 3155 | } |
| 3156 | if (Node->getOpcode() == ISD::SDIV && |
| 3157 | TLI.isOperationLegal(ISD::SDIVREM, VT)) { |
Chris Lattner | 31d7161 | 2008-10-04 21:27:46 +0000 | [diff] [blame] | 3158 | Result = SDValue(DAG.getNode(ISD::SDIVREM, VTs, Tmp1, Tmp2).getNode(), |
| 3159 | 0); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3160 | break; |
| 3161 | } |
| 3162 | if (Node->getOpcode() == ISD::UDIV && |
| 3163 | TLI.isOperationLegal(ISD::UDIVREM, VT)) { |
Chris Lattner | 31d7161 | 2008-10-04 21:27:46 +0000 | [diff] [blame] | 3164 | Result = SDValue(DAG.getNode(ISD::UDIVREM, VTs, Tmp1, Tmp2).getNode(), |
| 3165 | 0); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3166 | break; |
| 3167 | } |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 3168 | |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3169 | // Check to see if we have a libcall for this operator. |
| 3170 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
| 3171 | bool isSigned = false; |
| 3172 | switch (Node->getOpcode()) { |
| 3173 | case ISD::UDIV: |
| 3174 | case ISD::SDIV: |
| 3175 | if (VT == MVT::i32) { |
| 3176 | LC = Node->getOpcode() == ISD::UDIV |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 3177 | ? RTLIB::UDIV_I32 : RTLIB::SDIV_I32; |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3178 | isSigned = Node->getOpcode() == ISD::SDIV; |
| 3179 | } |
| 3180 | break; |
Chris Lattner | 31d7161 | 2008-10-04 21:27:46 +0000 | [diff] [blame] | 3181 | case ISD::MUL: |
| 3182 | if (VT == MVT::i32) |
| 3183 | LC = RTLIB::MUL_I32; |
| 3184 | break; |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3185 | case ISD::FPOW: |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 3186 | LC = GetFPLibCall(VT, RTLIB::POW_F32, RTLIB::POW_F64, RTLIB::POW_F80, |
| 3187 | RTLIB::POW_PPCF128); |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3188 | break; |
| 3189 | default: break; |
| 3190 | } |
| 3191 | if (LC != RTLIB::UNKNOWN_LIBCALL) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3192 | SDValue Dummy; |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 3193 | Result = ExpandLibCall(LC, Node, isSigned, Dummy); |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 3194 | break; |
| 3195 | } |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 3196 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3197 | assert(Node->getValueType(0).isVector() && |
Chris Lattner | bc70cf8 | 2006-04-02 03:57:31 +0000 | [diff] [blame] | 3198 | "Cannot expand this binary operator!"); |
| 3199 | // Expand the operation into a bunch of nasty scalar code. |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3200 | Result = LegalizeOp(UnrollVectorOp(Op)); |
Chris Lattner | bc70cf8 | 2006-04-02 03:57:31 +0000 | [diff] [blame] | 3201 | break; |
| 3202 | } |
Evan Cheng | cc98761 | 2006-04-12 21:20:24 +0000 | [diff] [blame] | 3203 | case TargetLowering::Promote: { |
| 3204 | switch (Node->getOpcode()) { |
| 3205 | default: assert(0 && "Do not know how to promote this BinOp!"); |
| 3206 | case ISD::AND: |
| 3207 | case ISD::OR: |
| 3208 | case ISD::XOR: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3209 | MVT OVT = Node->getValueType(0); |
| 3210 | MVT NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT); |
| 3211 | assert(OVT.isVector() && "Cannot promote this BinOp!"); |
Evan Cheng | cc98761 | 2006-04-12 21:20:24 +0000 | [diff] [blame] | 3212 | // Bit convert each of the values to the new type. |
| 3213 | Tmp1 = DAG.getNode(ISD::BIT_CONVERT, NVT, Tmp1); |
| 3214 | Tmp2 = DAG.getNode(ISD::BIT_CONVERT, NVT, Tmp2); |
| 3215 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 3216 | // Bit convert the result back the original type. |
| 3217 | Result = DAG.getNode(ISD::BIT_CONVERT, OVT, Result); |
| 3218 | break; |
| 3219 | } |
| 3220 | } |
| 3221 | } |
Andrew Lenharth | e8f65f1 | 2005-12-24 23:42:32 +0000 | [diff] [blame] | 3222 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3223 | break; |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 3224 | |
Dan Gohman | e14ea86 | 2007-10-05 14:17:22 +0000 | [diff] [blame] | 3225 | case ISD::SMUL_LOHI: |
| 3226 | case ISD::UMUL_LOHI: |
| 3227 | case ISD::SDIVREM: |
| 3228 | case ISD::UDIVREM: |
| 3229 | // These nodes will only be produced by target-specific lowering, so |
| 3230 | // they shouldn't be here if they aren't legal. |
Duncan Sands | a7c97a7 | 2007-10-16 09:07:20 +0000 | [diff] [blame] | 3231 | assert(TLI.isOperationLegal(Node->getOpcode(), Node->getValueType(0)) && |
Dan Gohman | e14ea86 | 2007-10-05 14:17:22 +0000 | [diff] [blame] | 3232 | "This must be legal!"); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3233 | |
| 3234 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
| 3235 | Tmp2 = LegalizeOp(Node->getOperand(1)); // RHS |
| 3236 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Dan Gohman | e14ea86 | 2007-10-05 14:17:22 +0000 | [diff] [blame] | 3237 | break; |
| 3238 | |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 3239 | case ISD::FCOPYSIGN: // FCOPYSIGN does not require LHS/RHS to match type! |
| 3240 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
| 3241 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 3242 | case Expand: assert(0 && "Not possible"); |
| 3243 | case Legal: |
| 3244 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the RHS. |
| 3245 | break; |
| 3246 | case Promote: |
| 3247 | Tmp2 = PromoteOp(Node->getOperand(1)); // Promote the RHS. |
| 3248 | break; |
| 3249 | } |
| 3250 | |
| 3251 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 3252 | |
| 3253 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 3254 | default: assert(0 && "Operation not supported"); |
| 3255 | case TargetLowering::Custom: |
| 3256 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3257 | if (Tmp1.getNode()) Result = Tmp1; |
Chris Lattner | 8f4191d | 2006-03-13 06:08:38 +0000 | [diff] [blame] | 3258 | break; |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 3259 | case TargetLowering::Legal: break; |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 3260 | case TargetLowering::Expand: { |
Evan Cheng | 636c753 | 2007-01-05 23:33:44 +0000 | [diff] [blame] | 3261 | // If this target supports fabs/fneg natively and select is cheap, |
| 3262 | // do this efficiently. |
| 3263 | if (!TLI.isSelectExpensive() && |
| 3264 | TLI.getOperationAction(ISD::FABS, Tmp1.getValueType()) == |
| 3265 | TargetLowering::Legal && |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 3266 | TLI.getOperationAction(ISD::FNEG, Tmp1.getValueType()) == |
Evan Cheng | 636c753 | 2007-01-05 23:33:44 +0000 | [diff] [blame] | 3267 | TargetLowering::Legal) { |
Chris Lattner | 8f4191d | 2006-03-13 06:08:38 +0000 | [diff] [blame] | 3268 | // Get the sign bit of the RHS. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3269 | MVT IVT = |
Chris Lattner | 8f4191d | 2006-03-13 06:08:38 +0000 | [diff] [blame] | 3270 | Tmp2.getValueType() == MVT::f32 ? MVT::i32 : MVT::i64; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3271 | SDValue SignBit = DAG.getNode(ISD::BIT_CONVERT, IVT, Tmp2); |
Scott Michel | 5b8f82e | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 3272 | SignBit = DAG.getSetCC(TLI.getSetCCResultType(SignBit), |
Chris Lattner | 8f4191d | 2006-03-13 06:08:38 +0000 | [diff] [blame] | 3273 | SignBit, DAG.getConstant(0, IVT), ISD::SETLT); |
| 3274 | // Get the absolute value of the result. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3275 | SDValue AbsVal = DAG.getNode(ISD::FABS, Tmp1.getValueType(), Tmp1); |
Chris Lattner | 8f4191d | 2006-03-13 06:08:38 +0000 | [diff] [blame] | 3276 | // Select between the nabs and abs value based on the sign bit of |
| 3277 | // the input. |
| 3278 | Result = DAG.getNode(ISD::SELECT, AbsVal.getValueType(), SignBit, |
| 3279 | DAG.getNode(ISD::FNEG, AbsVal.getValueType(), |
| 3280 | AbsVal), |
| 3281 | AbsVal); |
| 3282 | Result = LegalizeOp(Result); |
| 3283 | break; |
| 3284 | } |
| 3285 | |
| 3286 | // Otherwise, do bitwise ops! |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3287 | MVT NVT = |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 3288 | Node->getValueType(0) == MVT::f32 ? MVT::i32 : MVT::i64; |
| 3289 | Result = ExpandFCOPYSIGNToBitwiseOps(Node, NVT, DAG, TLI); |
| 3290 | Result = DAG.getNode(ISD::BIT_CONVERT, Node->getValueType(0), Result); |
| 3291 | Result = LegalizeOp(Result); |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 3292 | break; |
| 3293 | } |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 3294 | } |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 3295 | break; |
| 3296 | |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 3297 | case ISD::ADDC: |
| 3298 | case ISD::SUBC: |
| 3299 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 3300 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 3301 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Sanjiv Gupta | d3f01aa | 2008-11-26 11:19:00 +0000 | [diff] [blame] | 3302 | Tmp3 = Result.getValue(0); |
| 3303 | Tmp4 = Result.getValue(1); |
| 3304 | |
| 3305 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 3306 | default: assert(0 && "This action is not supported yet!"); |
| 3307 | case TargetLowering::Legal: |
| 3308 | break; |
| 3309 | case TargetLowering::Custom: |
| 3310 | Tmp1 = TLI.LowerOperation(Tmp3, DAG); |
| 3311 | if (Tmp1.getNode() != NULL) { |
Sanjiv Gupta | 9b0f0b5 | 2008-11-27 05:58:04 +0000 | [diff] [blame] | 3312 | Tmp3 = LegalizeOp(Tmp1); |
Sanjiv Gupta | d3f01aa | 2008-11-26 11:19:00 +0000 | [diff] [blame] | 3313 | Tmp4 = LegalizeOp(Tmp1.getValue(1)); |
| 3314 | } |
| 3315 | break; |
| 3316 | } |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 3317 | // Since this produces two values, make sure to remember that we legalized |
| 3318 | // both of them. |
Sanjiv Gupta | d3f01aa | 2008-11-26 11:19:00 +0000 | [diff] [blame] | 3319 | AddLegalizedOperand(SDValue(Node, 0), Tmp3); |
| 3320 | AddLegalizedOperand(SDValue(Node, 1), Tmp4); |
| 3321 | return Op.getResNo() ? Tmp4 : Tmp3; |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 3322 | |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 3323 | case ISD::ADDE: |
| 3324 | case ISD::SUBE: |
| 3325 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 3326 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 3327 | Tmp3 = LegalizeOp(Node->getOperand(2)); |
| 3328 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Sanjiv Gupta | d3f01aa | 2008-11-26 11:19:00 +0000 | [diff] [blame] | 3329 | Tmp3 = Result.getValue(0); |
| 3330 | Tmp4 = Result.getValue(1); |
| 3331 | |
| 3332 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 3333 | default: assert(0 && "This action is not supported yet!"); |
| 3334 | case TargetLowering::Legal: |
| 3335 | break; |
| 3336 | case TargetLowering::Custom: |
| 3337 | Tmp1 = TLI.LowerOperation(Tmp3, DAG); |
| 3338 | if (Tmp1.getNode() != NULL) { |
Sanjiv Gupta | 9b0f0b5 | 2008-11-27 05:58:04 +0000 | [diff] [blame] | 3339 | Tmp3 = LegalizeOp(Tmp1); |
Sanjiv Gupta | d3f01aa | 2008-11-26 11:19:00 +0000 | [diff] [blame] | 3340 | Tmp4 = LegalizeOp(Tmp1.getValue(1)); |
| 3341 | } |
| 3342 | break; |
| 3343 | } |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 3344 | // Since this produces two values, make sure to remember that we legalized |
| 3345 | // both of them. |
Sanjiv Gupta | d3f01aa | 2008-11-26 11:19:00 +0000 | [diff] [blame] | 3346 | AddLegalizedOperand(SDValue(Node, 0), Tmp3); |
| 3347 | AddLegalizedOperand(SDValue(Node, 1), Tmp4); |
| 3348 | return Op.getResNo() ? Tmp4 : Tmp3; |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 3349 | |
Nate Begeman | 419f8b6 | 2005-10-18 00:27:41 +0000 | [diff] [blame] | 3350 | case ISD::BUILD_PAIR: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3351 | MVT PairTy = Node->getValueType(0); |
Nate Begeman | 419f8b6 | 2005-10-18 00:27:41 +0000 | [diff] [blame] | 3352 | // TODO: handle the case where the Lo and Hi operands are not of legal type |
| 3353 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Lo |
| 3354 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Hi |
| 3355 | switch (TLI.getOperationAction(ISD::BUILD_PAIR, PairTy)) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3356 | case TargetLowering::Promote: |
| 3357 | case TargetLowering::Custom: |
| 3358 | assert(0 && "Cannot promote/custom this yet!"); |
Nate Begeman | 419f8b6 | 2005-10-18 00:27:41 +0000 | [diff] [blame] | 3359 | case TargetLowering::Legal: |
| 3360 | if (Tmp1 != Node->getOperand(0) || Tmp2 != Node->getOperand(1)) |
| 3361 | Result = DAG.getNode(ISD::BUILD_PAIR, PairTy, Tmp1, Tmp2); |
| 3362 | break; |
Nate Begeman | 419f8b6 | 2005-10-18 00:27:41 +0000 | [diff] [blame] | 3363 | case TargetLowering::Expand: |
| 3364 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, PairTy, Tmp1); |
| 3365 | Tmp2 = DAG.getNode(ISD::ANY_EXTEND, PairTy, Tmp2); |
| 3366 | Tmp2 = DAG.getNode(ISD::SHL, PairTy, Tmp2, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3367 | DAG.getConstant(PairTy.getSizeInBits()/2, |
Nate Begeman | 419f8b6 | 2005-10-18 00:27:41 +0000 | [diff] [blame] | 3368 | TLI.getShiftAmountTy())); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3369 | Result = DAG.getNode(ISD::OR, PairTy, Tmp1, Tmp2); |
Nate Begeman | 419f8b6 | 2005-10-18 00:27:41 +0000 | [diff] [blame] | 3370 | break; |
| 3371 | } |
| 3372 | break; |
| 3373 | } |
| 3374 | |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 3375 | case ISD::UREM: |
| 3376 | case ISD::SREM: |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 3377 | case ISD::FREM: |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 3378 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
| 3379 | Tmp2 = LegalizeOp(Node->getOperand(1)); // RHS |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3380 | |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 3381 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3382 | case TargetLowering::Promote: assert(0 && "Cannot promote this yet!"); |
| 3383 | case TargetLowering::Custom: |
| 3384 | isCustom = true; |
| 3385 | // FALLTHROUGH |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 3386 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3387 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3388 | if (isCustom) { |
| 3389 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3390 | if (Tmp1.getNode()) Result = Tmp1; |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3391 | } |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 3392 | break; |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3393 | case TargetLowering::Expand: { |
Evan Cheng | 6b5578f | 2006-09-18 23:28:33 +0000 | [diff] [blame] | 3394 | unsigned DivOpc= (Node->getOpcode() == ISD::UREM) ? ISD::UDIV : ISD::SDIV; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 3395 | bool isSigned = DivOpc == ISD::SDIV; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3396 | MVT VT = Node->getValueType(0); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3397 | |
| 3398 | // See if remainder can be lowered using two-result operations. |
| 3399 | SDVTList VTs = DAG.getVTList(VT, VT); |
| 3400 | if (Node->getOpcode() == ISD::SREM && |
| 3401 | TLI.isOperationLegal(ISD::SDIVREM, VT)) { |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3402 | Result = SDValue(DAG.getNode(ISD::SDIVREM, VTs, Tmp1, Tmp2).getNode(), 1); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3403 | break; |
| 3404 | } |
| 3405 | if (Node->getOpcode() == ISD::UREM && |
| 3406 | TLI.isOperationLegal(ISD::UDIVREM, VT)) { |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3407 | Result = SDValue(DAG.getNode(ISD::UDIVREM, VTs, Tmp1, Tmp2).getNode(), 1); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3408 | break; |
| 3409 | } |
| 3410 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3411 | if (VT.isInteger()) { |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3412 | if (TLI.getOperationAction(DivOpc, VT) == |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 3413 | TargetLowering::Legal) { |
| 3414 | // X % Y -> X-X/Y*Y |
Evan Cheng | 6b5578f | 2006-09-18 23:28:33 +0000 | [diff] [blame] | 3415 | Result = DAG.getNode(DivOpc, VT, Tmp1, Tmp2); |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 3416 | Result = DAG.getNode(ISD::MUL, VT, Result, Tmp2); |
| 3417 | Result = DAG.getNode(ISD::SUB, VT, Tmp1, Result); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3418 | } else if (VT.isVector()) { |
Dan Gohman | 8017631 | 2007-11-05 23:35:22 +0000 | [diff] [blame] | 3419 | Result = LegalizeOp(UnrollVectorOp(Op)); |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 3420 | } else { |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3421 | assert(VT == MVT::i32 && |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 3422 | "Cannot expand this binary operator!"); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3423 | RTLIB::Libcall LC = Node->getOpcode() == ISD::UREM |
| 3424 | ? RTLIB::UREM_I32 : RTLIB::SREM_I32; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3425 | SDValue Dummy; |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 3426 | Result = ExpandLibCall(LC, Node, isSigned, Dummy); |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 3427 | } |
Dan Gohman | 0d97426 | 2007-11-06 22:11:54 +0000 | [diff] [blame] | 3428 | } else { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3429 | assert(VT.isFloatingPoint() && |
Dan Gohman | 0d97426 | 2007-11-06 22:11:54 +0000 | [diff] [blame] | 3430 | "remainder op must have integer or floating-point type"); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3431 | if (VT.isVector()) { |
Dan Gohman | 8017631 | 2007-11-05 23:35:22 +0000 | [diff] [blame] | 3432 | Result = LegalizeOp(UnrollVectorOp(Op)); |
| 3433 | } else { |
| 3434 | // Floating point mod -> fmod libcall. |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 3435 | RTLIB::Libcall LC = GetFPLibCall(VT, RTLIB::REM_F32, RTLIB::REM_F64, |
| 3436 | RTLIB::REM_F80, RTLIB::REM_PPCF128); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3437 | SDValue Dummy; |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 3438 | Result = ExpandLibCall(LC, Node, false/*sign irrelevant*/, Dummy); |
Dan Gohman | 8017631 | 2007-11-05 23:35:22 +0000 | [diff] [blame] | 3439 | } |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 3440 | } |
| 3441 | break; |
| 3442 | } |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3443 | } |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 3444 | break; |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3445 | case ISD::VAARG: { |
| 3446 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 3447 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. |
| 3448 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3449 | MVT VT = Node->getValueType(0); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3450 | switch (TLI.getOperationAction(Node->getOpcode(), MVT::Other)) { |
| 3451 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3452 | case TargetLowering::Custom: |
| 3453 | isCustom = true; |
| 3454 | // FALLTHROUGH |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3455 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3456 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
| 3457 | Result = Result.getValue(0); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3458 | Tmp1 = Result.getValue(1); |
| 3459 | |
| 3460 | if (isCustom) { |
| 3461 | Tmp2 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3462 | if (Tmp2.getNode()) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3463 | Result = LegalizeOp(Tmp2); |
| 3464 | Tmp1 = LegalizeOp(Tmp2.getValue(1)); |
| 3465 | } |
| 3466 | } |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3467 | break; |
| 3468 | case TargetLowering::Expand: { |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 3469 | const Value *V = cast<SrcValueSDNode>(Node->getOperand(2))->getValue(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3470 | SDValue VAList = DAG.getLoad(TLI.getPointerTy(), Tmp1, Tmp2, V, 0); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3471 | // Increment the pointer, VAList, to the next vaarg |
Duncan Sands | 5c58a31 | 2008-11-03 11:51:11 +0000 | [diff] [blame] | 3472 | Tmp3 = DAG.getNode(ISD::ADD, TLI.getPointerTy(), VAList, |
| 3473 | DAG.getConstant(TLI.getTargetData()->getABITypeSize(VT.getTypeForMVT()), |
| 3474 | TLI.getPointerTy())); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3475 | // Store the incremented VAList to the legalized pointer |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 3476 | Tmp3 = DAG.getStore(VAList.getValue(1), Tmp3, Tmp2, V, 0); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3477 | // Load the actual argument out of the pointer VAList |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 3478 | Result = DAG.getLoad(VT, Tmp3, VAList, NULL, 0); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3479 | Tmp1 = LegalizeOp(Result.getValue(1)); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3480 | Result = LegalizeOp(Result); |
| 3481 | break; |
| 3482 | } |
| 3483 | } |
| 3484 | // Since VAARG produces two values, make sure to remember that we |
| 3485 | // legalized both of them. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3486 | AddLegalizedOperand(SDValue(Node, 0), Result); |
| 3487 | AddLegalizedOperand(SDValue(Node, 1), Tmp1); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 3488 | return Op.getResNo() ? Tmp1 : Result; |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3489 | } |
| 3490 | |
| 3491 | case ISD::VACOPY: |
| 3492 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 3493 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the dest pointer. |
| 3494 | Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the source pointer. |
| 3495 | |
| 3496 | switch (TLI.getOperationAction(ISD::VACOPY, MVT::Other)) { |
| 3497 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3498 | case TargetLowering::Custom: |
| 3499 | isCustom = true; |
| 3500 | // FALLTHROUGH |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3501 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3502 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3, |
| 3503 | Node->getOperand(3), Node->getOperand(4)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3504 | if (isCustom) { |
| 3505 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3506 | if (Tmp1.getNode()) Result = Tmp1; |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3507 | } |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3508 | break; |
| 3509 | case TargetLowering::Expand: |
| 3510 | // This defaults to loading a pointer from the input and storing it to the |
| 3511 | // output, returning the chain. |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 3512 | const Value *VD = cast<SrcValueSDNode>(Node->getOperand(3))->getValue(); |
| 3513 | const Value *VS = cast<SrcValueSDNode>(Node->getOperand(4))->getValue(); |
Dan Gohman | 499c1bd | 2008-04-17 02:09:26 +0000 | [diff] [blame] | 3514 | Tmp4 = DAG.getLoad(TLI.getPointerTy(), Tmp1, Tmp3, VS, 0); |
| 3515 | Result = DAG.getStore(Tmp4.getValue(1), Tmp4, Tmp2, VD, 0); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3516 | break; |
| 3517 | } |
| 3518 | break; |
| 3519 | |
| 3520 | case ISD::VAEND: |
| 3521 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 3522 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. |
| 3523 | |
| 3524 | switch (TLI.getOperationAction(ISD::VAEND, MVT::Other)) { |
| 3525 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3526 | case TargetLowering::Custom: |
| 3527 | isCustom = true; |
| 3528 | // FALLTHROUGH |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3529 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3530 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3531 | if (isCustom) { |
| 3532 | Tmp1 = TLI.LowerOperation(Tmp1, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3533 | if (Tmp1.getNode()) Result = Tmp1; |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3534 | } |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3535 | break; |
| 3536 | case TargetLowering::Expand: |
| 3537 | Result = Tmp1; // Default to a no-op, return the chain |
| 3538 | break; |
| 3539 | } |
| 3540 | break; |
| 3541 | |
| 3542 | case ISD::VASTART: |
| 3543 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 3544 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. |
| 3545 | |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3546 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
| 3547 | |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3548 | switch (TLI.getOperationAction(ISD::VASTART, MVT::Other)) { |
| 3549 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3550 | case TargetLowering::Legal: break; |
| 3551 | case TargetLowering::Custom: |
| 3552 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3553 | if (Tmp1.getNode()) Result = Tmp1; |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3554 | break; |
| 3555 | } |
| 3556 | break; |
| 3557 | |
Nate Begeman | 35ef913 | 2006-01-11 21:21:00 +0000 | [diff] [blame] | 3558 | case ISD::ROTL: |
| 3559 | case ISD::ROTR: |
| 3560 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
| 3561 | Tmp2 = LegalizeOp(Node->getOperand(1)); // RHS |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3562 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Scott Michel | c9dc114 | 2007-04-02 21:36:32 +0000 | [diff] [blame] | 3563 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 3564 | default: |
| 3565 | assert(0 && "ROTL/ROTR legalize operation not supported"); |
| 3566 | break; |
| 3567 | case TargetLowering::Legal: |
| 3568 | break; |
| 3569 | case TargetLowering::Custom: |
| 3570 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3571 | if (Tmp1.getNode()) Result = Tmp1; |
Scott Michel | c9dc114 | 2007-04-02 21:36:32 +0000 | [diff] [blame] | 3572 | break; |
| 3573 | case TargetLowering::Promote: |
| 3574 | assert(0 && "Do not know how to promote ROTL/ROTR"); |
| 3575 | break; |
| 3576 | case TargetLowering::Expand: |
| 3577 | assert(0 && "Do not know how to expand ROTL/ROTR"); |
| 3578 | break; |
| 3579 | } |
Nate Begeman | 35ef913 | 2006-01-11 21:21:00 +0000 | [diff] [blame] | 3580 | break; |
| 3581 | |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 3582 | case ISD::BSWAP: |
| 3583 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Op |
| 3584 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3585 | case TargetLowering::Custom: |
| 3586 | assert(0 && "Cannot custom legalize this yet!"); |
| 3587 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3588 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3589 | break; |
| 3590 | case TargetLowering::Promote: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3591 | MVT OVT = Tmp1.getValueType(); |
| 3592 | MVT NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT); |
| 3593 | unsigned DiffBits = NVT.getSizeInBits() - OVT.getSizeInBits(); |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 3594 | |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3595 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Tmp1); |
| 3596 | Tmp1 = DAG.getNode(ISD::BSWAP, NVT, Tmp1); |
| 3597 | Result = DAG.getNode(ISD::SRL, NVT, Tmp1, |
| 3598 | DAG.getConstant(DiffBits, TLI.getShiftAmountTy())); |
| 3599 | break; |
| 3600 | } |
| 3601 | case TargetLowering::Expand: |
| 3602 | Result = ExpandBSWAP(Tmp1); |
| 3603 | break; |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 3604 | } |
| 3605 | break; |
| 3606 | |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3607 | case ISD::CTPOP: |
| 3608 | case ISD::CTTZ: |
| 3609 | case ISD::CTLZ: |
| 3610 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Op |
| 3611 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
Scott Michel | 910b66d | 2007-07-30 21:00:31 +0000 | [diff] [blame] | 3612 | case TargetLowering::Custom: |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3613 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3614 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Scott Michel | 910b66d | 2007-07-30 21:00:31 +0000 | [diff] [blame] | 3615 | if (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0)) == |
Scott Michel | 335f4f7 | 2007-08-02 02:22:46 +0000 | [diff] [blame] | 3616 | TargetLowering::Custom) { |
| 3617 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3618 | if (Tmp1.getNode()) { |
Scott Michel | 335f4f7 | 2007-08-02 02:22:46 +0000 | [diff] [blame] | 3619 | Result = Tmp1; |
| 3620 | } |
Scott Michel | 910b66d | 2007-07-30 21:00:31 +0000 | [diff] [blame] | 3621 | } |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3622 | break; |
| 3623 | case TargetLowering::Promote: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3624 | MVT OVT = Tmp1.getValueType(); |
| 3625 | MVT NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT); |
Chris Lattner | edb1add | 2005-05-11 04:51:16 +0000 | [diff] [blame] | 3626 | |
| 3627 | // Zero extend the argument. |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3628 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Tmp1); |
| 3629 | // Perform the larger operation, then subtract if needed. |
| 3630 | Tmp1 = DAG.getNode(Node->getOpcode(), Node->getValueType(0), Tmp1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3631 | switch (Node->getOpcode()) { |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3632 | case ISD::CTPOP: |
| 3633 | Result = Tmp1; |
| 3634 | break; |
| 3635 | case ISD::CTTZ: |
| 3636 | //if Tmp1 == sizeinbits(NVT) then Tmp1 = sizeinbits(Old VT) |
Scott Michel | 5b8f82e | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 3637 | Tmp2 = DAG.getSetCC(TLI.getSetCCResultType(Tmp1), Tmp1, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3638 | DAG.getConstant(NVT.getSizeInBits(), NVT), |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 3639 | ISD::SETEQ); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 3640 | Result = DAG.getNode(ISD::SELECT, NVT, Tmp2, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3641 | DAG.getConstant(OVT.getSizeInBits(), NVT), Tmp1); |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3642 | break; |
| 3643 | case ISD::CTLZ: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3644 | // Tmp1 = Tmp1 - (sizeinbits(NVT) - sizeinbits(Old VT)) |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 3645 | Result = DAG.getNode(ISD::SUB, NVT, Tmp1, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3646 | DAG.getConstant(NVT.getSizeInBits() - |
| 3647 | OVT.getSizeInBits(), NVT)); |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3648 | break; |
| 3649 | } |
| 3650 | break; |
| 3651 | } |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3652 | case TargetLowering::Expand: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3653 | Result = ExpandBitCount(Node->getOpcode(), Tmp1); |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3654 | break; |
| 3655 | } |
| 3656 | break; |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 3657 | |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3658 | // Unary operators |
| 3659 | case ISD::FABS: |
| 3660 | case ISD::FNEG: |
Chris Lattner | da6ba87 | 2005-04-28 21:44:33 +0000 | [diff] [blame] | 3661 | case ISD::FSQRT: |
| 3662 | case ISD::FSIN: |
| 3663 | case ISD::FCOS: |
Dale Johannesen | 7794f2a | 2008-09-04 00:47:13 +0000 | [diff] [blame] | 3664 | case ISD::FLOG: |
| 3665 | case ISD::FLOG2: |
| 3666 | case ISD::FLOG10: |
| 3667 | case ISD::FEXP: |
| 3668 | case ISD::FEXP2: |
Dan Gohman | 509e84f | 2008-08-21 17:55:02 +0000 | [diff] [blame] | 3669 | case ISD::FTRUNC: |
| 3670 | case ISD::FFLOOR: |
| 3671 | case ISD::FCEIL: |
| 3672 | case ISD::FRINT: |
| 3673 | case ISD::FNEARBYINT: |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3674 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 3675 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3676 | case TargetLowering::Promote: |
| 3677 | case TargetLowering::Custom: |
Evan Cheng | 59ad781 | 2006-01-31 18:14:25 +0000 | [diff] [blame] | 3678 | isCustom = true; |
| 3679 | // FALLTHROUGH |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3680 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3681 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Evan Cheng | 59ad781 | 2006-01-31 18:14:25 +0000 | [diff] [blame] | 3682 | if (isCustom) { |
| 3683 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3684 | if (Tmp1.getNode()) Result = Tmp1; |
Evan Cheng | 59ad781 | 2006-01-31 18:14:25 +0000 | [diff] [blame] | 3685 | } |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3686 | break; |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3687 | case TargetLowering::Expand: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3688 | switch (Node->getOpcode()) { |
| 3689 | default: assert(0 && "Unreachable!"); |
| 3690 | case ISD::FNEG: |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3691 | // Expand Y = FNEG(X) -> Y = SUB -0.0, X |
| 3692 | Tmp2 = DAG.getConstantFP(-0.0, Node->getValueType(0)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3693 | Result = DAG.getNode(ISD::FSUB, Node->getValueType(0), Tmp2, Tmp1); |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 3694 | break; |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 3695 | case ISD::FABS: { |
Chris Lattner | 4af6e0d | 2005-04-02 05:26:37 +0000 | [diff] [blame] | 3696 | // Expand Y = FABS(X) -> Y = (X >u 0.0) ? X : fneg(X). |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3697 | MVT VT = Node->getValueType(0); |
Chris Lattner | 4af6e0d | 2005-04-02 05:26:37 +0000 | [diff] [blame] | 3698 | Tmp2 = DAG.getConstantFP(0.0, VT); |
Scott Michel | 5b8f82e | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 3699 | Tmp2 = DAG.getSetCC(TLI.getSetCCResultType(Tmp1), Tmp1, Tmp2, |
Nate Begeman | 5922f56 | 2008-03-14 00:53:31 +0000 | [diff] [blame] | 3700 | ISD::SETUGT); |
Chris Lattner | 4af6e0d | 2005-04-02 05:26:37 +0000 | [diff] [blame] | 3701 | Tmp3 = DAG.getNode(ISD::FNEG, VT, Tmp1); |
| 3702 | Result = DAG.getNode(ISD::SELECT, VT, Tmp2, Tmp1, Tmp3); |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 3703 | break; |
| 3704 | } |
Evan Cheng | 9d24ac5 | 2008-09-09 23:35:53 +0000 | [diff] [blame] | 3705 | case ISD::FSQRT: |
| 3706 | case ISD::FSIN: |
| 3707 | case ISD::FCOS: |
Dale Johannesen | 7794f2a | 2008-09-04 00:47:13 +0000 | [diff] [blame] | 3708 | case ISD::FLOG: |
| 3709 | case ISD::FLOG2: |
| 3710 | case ISD::FLOG10: |
| 3711 | case ISD::FEXP: |
| 3712 | case ISD::FEXP2: |
Dan Gohman | 2bb1e3e | 2008-08-21 18:38:14 +0000 | [diff] [blame] | 3713 | case ISD::FTRUNC: |
| 3714 | case ISD::FFLOOR: |
| 3715 | case ISD::FCEIL: |
| 3716 | case ISD::FRINT: |
Evan Cheng | 9d24ac5 | 2008-09-09 23:35:53 +0000 | [diff] [blame] | 3717 | case ISD::FNEARBYINT: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3718 | MVT VT = Node->getValueType(0); |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3719 | |
| 3720 | // Expand unsupported unary vector operators by unrolling them. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3721 | if (VT.isVector()) { |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3722 | Result = LegalizeOp(UnrollVectorOp(Op)); |
| 3723 | break; |
| 3724 | } |
| 3725 | |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3726 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 3727 | switch(Node->getOpcode()) { |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3728 | case ISD::FSQRT: |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 3729 | LC = GetFPLibCall(VT, RTLIB::SQRT_F32, RTLIB::SQRT_F64, |
| 3730 | RTLIB::SQRT_F80, RTLIB::SQRT_PPCF128); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3731 | break; |
| 3732 | case ISD::FSIN: |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 3733 | LC = GetFPLibCall(VT, RTLIB::SIN_F32, RTLIB::SIN_F64, |
| 3734 | RTLIB::SIN_F80, RTLIB::SIN_PPCF128); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3735 | break; |
| 3736 | case ISD::FCOS: |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 3737 | LC = GetFPLibCall(VT, RTLIB::COS_F32, RTLIB::COS_F64, |
| 3738 | RTLIB::COS_F80, RTLIB::COS_PPCF128); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3739 | break; |
Dale Johannesen | 7794f2a | 2008-09-04 00:47:13 +0000 | [diff] [blame] | 3740 | case ISD::FLOG: |
| 3741 | LC = GetFPLibCall(VT, RTLIB::LOG_F32, RTLIB::LOG_F64, |
| 3742 | RTLIB::LOG_F80, RTLIB::LOG_PPCF128); |
| 3743 | break; |
| 3744 | case ISD::FLOG2: |
| 3745 | LC = GetFPLibCall(VT, RTLIB::LOG2_F32, RTLIB::LOG2_F64, |
| 3746 | RTLIB::LOG2_F80, RTLIB::LOG2_PPCF128); |
| 3747 | break; |
| 3748 | case ISD::FLOG10: |
| 3749 | LC = GetFPLibCall(VT, RTLIB::LOG10_F32, RTLIB::LOG10_F64, |
| 3750 | RTLIB::LOG10_F80, RTLIB::LOG10_PPCF128); |
| 3751 | break; |
| 3752 | case ISD::FEXP: |
| 3753 | LC = GetFPLibCall(VT, RTLIB::EXP_F32, RTLIB::EXP_F64, |
| 3754 | RTLIB::EXP_F80, RTLIB::EXP_PPCF128); |
| 3755 | break; |
| 3756 | case ISD::FEXP2: |
| 3757 | LC = GetFPLibCall(VT, RTLIB::EXP2_F32, RTLIB::EXP2_F64, |
| 3758 | RTLIB::EXP2_F80, RTLIB::EXP2_PPCF128); |
| 3759 | break; |
Dan Gohman | 2bb1e3e | 2008-08-21 18:38:14 +0000 | [diff] [blame] | 3760 | case ISD::FTRUNC: |
| 3761 | LC = GetFPLibCall(VT, RTLIB::TRUNC_F32, RTLIB::TRUNC_F64, |
| 3762 | RTLIB::TRUNC_F80, RTLIB::TRUNC_PPCF128); |
| 3763 | break; |
| 3764 | case ISD::FFLOOR: |
| 3765 | LC = GetFPLibCall(VT, RTLIB::FLOOR_F32, RTLIB::FLOOR_F64, |
| 3766 | RTLIB::FLOOR_F80, RTLIB::FLOOR_PPCF128); |
| 3767 | break; |
| 3768 | case ISD::FCEIL: |
| 3769 | LC = GetFPLibCall(VT, RTLIB::CEIL_F32, RTLIB::CEIL_F64, |
| 3770 | RTLIB::CEIL_F80, RTLIB::CEIL_PPCF128); |
| 3771 | break; |
| 3772 | case ISD::FRINT: |
| 3773 | LC = GetFPLibCall(VT, RTLIB::RINT_F32, RTLIB::RINT_F64, |
| 3774 | RTLIB::RINT_F80, RTLIB::RINT_PPCF128); |
| 3775 | break; |
| 3776 | case ISD::FNEARBYINT: |
| 3777 | LC = GetFPLibCall(VT, RTLIB::NEARBYINT_F32, RTLIB::NEARBYINT_F64, |
| 3778 | RTLIB::NEARBYINT_F80, RTLIB::NEARBYINT_PPCF128); |
| 3779 | break; |
Evan Cheng | 9d24ac5 | 2008-09-09 23:35:53 +0000 | [diff] [blame] | 3780 | break; |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 3781 | default: assert(0 && "Unreachable!"); |
| 3782 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3783 | SDValue Dummy; |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 3784 | Result = ExpandLibCall(LC, Node, false/*sign irrelevant*/, Dummy); |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 3785 | break; |
| 3786 | } |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3787 | } |
| 3788 | break; |
| 3789 | } |
| 3790 | break; |
Chris Lattner | 6ddf8ed | 2006-09-09 06:03:30 +0000 | [diff] [blame] | 3791 | case ISD::FPOWI: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3792 | MVT VT = Node->getValueType(0); |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3793 | |
| 3794 | // Expand unsupported unary vector operators by unrolling them. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3795 | if (VT.isVector()) { |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3796 | Result = LegalizeOp(UnrollVectorOp(Op)); |
| 3797 | break; |
| 3798 | } |
| 3799 | |
| 3800 | // 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] | 3801 | RTLIB::Libcall LC = GetFPLibCall(VT, RTLIB::POWI_F32, RTLIB::POWI_F64, |
| 3802 | RTLIB::POWI_F80, RTLIB::POWI_PPCF128); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3803 | SDValue Dummy; |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 3804 | Result = ExpandLibCall(LC, Node, false/*sign irrelevant*/, Dummy); |
Chris Lattner | 6ddf8ed | 2006-09-09 06:03:30 +0000 | [diff] [blame] | 3805 | break; |
| 3806 | } |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 3807 | case ISD::BIT_CONVERT: |
Chris Lattner | 67993f7 | 2006-01-23 07:30:46 +0000 | [diff] [blame] | 3808 | if (!isTypeLegal(Node->getOperand(0).getValueType())) { |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 3809 | Result = EmitStackConvert(Node->getOperand(0), Node->getValueType(0), |
| 3810 | Node->getValueType(0)); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3811 | } else if (Op.getOperand(0).getValueType().isVector()) { |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3812 | // The input has to be a vector type, we have to either scalarize it, pack |
| 3813 | // it, or convert it based on whether the input vector type is legal. |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3814 | SDNode *InVal = Node->getOperand(0).getNode(); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 3815 | int InIx = Node->getOperand(0).getResNo(); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3816 | unsigned NumElems = InVal->getValueType(InIx).getVectorNumElements(); |
| 3817 | MVT EVT = InVal->getValueType(InIx).getVectorElementType(); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3818 | |
| 3819 | // Figure out if there is a simple type corresponding to this Vector |
| 3820 | // type. If so, convert to the vector type. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3821 | MVT TVT = MVT::getVectorVT(EVT, NumElems); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3822 | if (TLI.isTypeLegal(TVT)) { |
Dan Gohman | 07a9676 | 2007-07-16 14:29:03 +0000 | [diff] [blame] | 3823 | // Turn this into a bit convert of the vector input. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3824 | Result = DAG.getNode(ISD::BIT_CONVERT, Node->getValueType(0), |
| 3825 | LegalizeOp(Node->getOperand(0))); |
| 3826 | break; |
| 3827 | } else if (NumElems == 1) { |
| 3828 | // Turn this into a bit convert of the scalar input. |
| 3829 | Result = DAG.getNode(ISD::BIT_CONVERT, Node->getValueType(0), |
| 3830 | ScalarizeVectorOp(Node->getOperand(0))); |
| 3831 | break; |
| 3832 | } else { |
| 3833 | // FIXME: UNIMP! Store then reload |
| 3834 | assert(0 && "Cast from unsupported vector type not implemented yet!"); |
| 3835 | } |
Chris Lattner | 67993f7 | 2006-01-23 07:30:46 +0000 | [diff] [blame] | 3836 | } else { |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 3837 | switch (TLI.getOperationAction(ISD::BIT_CONVERT, |
| 3838 | Node->getOperand(0).getValueType())) { |
| 3839 | default: assert(0 && "Unknown operation action!"); |
| 3840 | case TargetLowering::Expand: |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 3841 | Result = EmitStackConvert(Node->getOperand(0), Node->getValueType(0), |
| 3842 | Node->getValueType(0)); |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 3843 | break; |
| 3844 | case TargetLowering::Legal: |
| 3845 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3846 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 3847 | break; |
| 3848 | } |
| 3849 | } |
| 3850 | break; |
Mon P Wang | 77cdf30 | 2008-11-10 20:54:11 +0000 | [diff] [blame] | 3851 | case ISD::CONVERT_RNDSAT: { |
| 3852 | ISD::CvtCode CvtCode = cast<CvtRndSatSDNode>(Node)->getCvtCode(); |
| 3853 | switch (CvtCode) { |
| 3854 | default: assert(0 && "Unknown cvt code!"); |
| 3855 | case ISD::CVT_SF: |
| 3856 | case ISD::CVT_UF: |
| 3857 | break; |
| 3858 | case ISD::CVT_FF: |
| 3859 | case ISD::CVT_FS: |
| 3860 | case ISD::CVT_FU: |
| 3861 | case ISD::CVT_SS: |
| 3862 | case ISD::CVT_SU: |
| 3863 | case ISD::CVT_US: |
| 3864 | case ISD::CVT_UU: { |
| 3865 | SDValue DTyOp = Node->getOperand(1); |
| 3866 | SDValue STyOp = Node->getOperand(2); |
| 3867 | SDValue RndOp = Node->getOperand(3); |
| 3868 | SDValue SatOp = Node->getOperand(4); |
| 3869 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3870 | case Expand: assert(0 && "Shouldn't need to expand other operators here!"); |
| 3871 | case Legal: |
| 3872 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 3873 | Result = DAG.UpdateNodeOperands(Result, Tmp1, DTyOp, STyOp, |
| 3874 | RndOp, SatOp); |
| 3875 | if (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0)) == |
| 3876 | TargetLowering::Custom) { |
| 3877 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 3878 | if (Tmp1.getNode()) Result = Tmp1; |
| 3879 | } |
| 3880 | break; |
| 3881 | case Promote: |
| 3882 | Result = PromoteOp(Node->getOperand(0)); |
| 3883 | // For FP, make Op1 a i32 |
| 3884 | |
| 3885 | Result = DAG.getConvertRndSat(Result.getValueType(), Result, |
| 3886 | DTyOp, STyOp, RndOp, SatOp, CvtCode); |
| 3887 | break; |
| 3888 | } |
| 3889 | break; |
| 3890 | } |
| 3891 | } // end switch CvtCode |
| 3892 | break; |
| 3893 | } |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3894 | // Conversion operators. The source and destination have different types. |
Chris Lattner | ae0aacb | 2005-01-08 08:08:56 +0000 | [diff] [blame] | 3895 | case ISD::SINT_TO_FP: |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3896 | case ISD::UINT_TO_FP: { |
| 3897 | bool isSigned = Node->getOpcode() == ISD::SINT_TO_FP; |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 3898 | Result = LegalizeINT_TO_FP(Result, isSigned, |
| 3899 | Node->getValueType(0), Node->getOperand(0)); |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3900 | break; |
| 3901 | } |
| 3902 | case ISD::TRUNCATE: |
| 3903 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3904 | case Legal: |
| 3905 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3906 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3907 | break; |
| 3908 | case Expand: |
| 3909 | ExpandOp(Node->getOperand(0), Tmp1, Tmp2); |
| 3910 | |
| 3911 | // Since the result is legal, we should just be able to truncate the low |
| 3912 | // part of the source. |
| 3913 | Result = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0), Tmp1); |
| 3914 | break; |
| 3915 | case Promote: |
| 3916 | Result = PromoteOp(Node->getOperand(0)); |
| 3917 | Result = DAG.getNode(ISD::TRUNCATE, Op.getValueType(), Result); |
| 3918 | break; |
| 3919 | } |
| 3920 | break; |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 3921 | |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3922 | case ISD::FP_TO_SINT: |
| 3923 | case ISD::FP_TO_UINT: |
| 3924 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3925 | case Legal: |
Chris Lattner | f1fa74e | 2005-07-30 00:04:12 +0000 | [diff] [blame] | 3926 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 3927 | |
Chris Lattner | 1618beb | 2005-07-29 00:11:56 +0000 | [diff] [blame] | 3928 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))){ |
| 3929 | default: assert(0 && "Unknown operation action!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3930 | case TargetLowering::Custom: |
| 3931 | isCustom = true; |
| 3932 | // FALLTHROUGH |
| 3933 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3934 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3935 | if (isCustom) { |
| 3936 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3937 | if (Tmp1.getNode()) Result = Tmp1; |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3938 | } |
| 3939 | break; |
| 3940 | case TargetLowering::Promote: |
| 3941 | Result = PromoteLegalFP_TO_INT(Tmp1, Node->getValueType(0), |
| 3942 | Node->getOpcode() == ISD::FP_TO_SINT); |
| 3943 | break; |
Chris Lattner | 1618beb | 2005-07-29 00:11:56 +0000 | [diff] [blame] | 3944 | case TargetLowering::Expand: |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 3945 | if (Node->getOpcode() == ISD::FP_TO_UINT) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3946 | SDValue True, False; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3947 | MVT VT = Node->getOperand(0).getValueType(); |
| 3948 | MVT NVT = Node->getValueType(0); |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 3949 | const uint64_t zero[] = {0, 0}; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3950 | APFloat apf = APFloat(APInt(VT.getSizeInBits(), 2, zero)); |
| 3951 | APInt x = APInt::getSignBit(NVT.getSizeInBits()); |
Dan Gohman | c7773bf | 2008-02-29 01:44:25 +0000 | [diff] [blame] | 3952 | (void)apf.convertFromAPInt(x, false, APFloat::rmNearestTiesToEven); |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 3953 | Tmp2 = DAG.getConstantFP(apf, VT); |
Scott Michel | 5b8f82e | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 3954 | Tmp3 = DAG.getSetCC(TLI.getSetCCResultType(Node->getOperand(0)), |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 3955 | Node->getOperand(0), Tmp2, ISD::SETLT); |
| 3956 | True = DAG.getNode(ISD::FP_TO_SINT, NVT, Node->getOperand(0)); |
| 3957 | False = DAG.getNode(ISD::FP_TO_SINT, NVT, |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 3958 | DAG.getNode(ISD::FSUB, VT, Node->getOperand(0), |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 3959 | Tmp2)); |
| 3960 | False = DAG.getNode(ISD::XOR, NVT, False, |
Dan Gohman | c7773bf | 2008-02-29 01:44:25 +0000 | [diff] [blame] | 3961 | DAG.getConstant(x, NVT)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3962 | Result = DAG.getNode(ISD::SELECT, NVT, Tmp3, True, False); |
| 3963 | break; |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 3964 | } else { |
| 3965 | assert(0 && "Do not know how to expand FP_TO_SINT yet!"); |
| 3966 | } |
| 3967 | break; |
Chris Lattner | 07dffd6 | 2005-08-26 00:14:16 +0000 | [diff] [blame] | 3968 | } |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3969 | break; |
Evan Cheng | 6af00d5 | 2006-12-13 01:57:55 +0000 | [diff] [blame] | 3970 | case Expand: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3971 | MVT VT = Op.getValueType(); |
| 3972 | MVT OVT = Node->getOperand(0).getValueType(); |
Dale Johannesen | fcf4d24 | 2007-10-11 23:32:15 +0000 | [diff] [blame] | 3973 | // Convert ppcf128 to i32 |
Dale Johannesen | 6eaeff2 | 2007-10-10 01:01:31 +0000 | [diff] [blame] | 3974 | if (OVT == MVT::ppcf128 && VT == MVT::i32) { |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 3975 | if (Node->getOpcode() == ISD::FP_TO_SINT) { |
| 3976 | Result = DAG.getNode(ISD::FP_ROUND_INREG, MVT::ppcf128, |
| 3977 | Node->getOperand(0), DAG.getValueType(MVT::f64)); |
| 3978 | Result = DAG.getNode(ISD::FP_ROUND, MVT::f64, Result, |
| 3979 | DAG.getIntPtrConstant(1)); |
| 3980 | Result = DAG.getNode(ISD::FP_TO_SINT, VT, Result); |
| 3981 | } else { |
Dale Johannesen | fcf4d24 | 2007-10-11 23:32:15 +0000 | [diff] [blame] | 3982 | const uint64_t TwoE31[] = {0x41e0000000000000LL, 0}; |
| 3983 | APFloat apf = APFloat(APInt(128, 2, TwoE31)); |
| 3984 | Tmp2 = DAG.getConstantFP(apf, OVT); |
| 3985 | // X>=2^31 ? (int)(X-2^31)+0x80000000 : (int)X |
| 3986 | // FIXME: generated code sucks. |
| 3987 | Result = DAG.getNode(ISD::SELECT_CC, VT, Node->getOperand(0), Tmp2, |
| 3988 | DAG.getNode(ISD::ADD, MVT::i32, |
| 3989 | DAG.getNode(ISD::FP_TO_SINT, VT, |
| 3990 | DAG.getNode(ISD::FSUB, OVT, |
| 3991 | Node->getOperand(0), Tmp2)), |
| 3992 | DAG.getConstant(0x80000000, MVT::i32)), |
| 3993 | DAG.getNode(ISD::FP_TO_SINT, VT, |
| 3994 | Node->getOperand(0)), |
| 3995 | DAG.getCondCode(ISD::SETGE)); |
| 3996 | } |
Dale Johannesen | 6eaeff2 | 2007-10-10 01:01:31 +0000 | [diff] [blame] | 3997 | break; |
| 3998 | } |
Dan Gohman | a2e9485 | 2008-03-10 23:03:31 +0000 | [diff] [blame] | 3999 | // Convert f32 / f64 to i32 / i64 / i128. |
Duncan Sands | b2ff885 | 2008-07-17 02:36:29 +0000 | [diff] [blame] | 4000 | RTLIB::Libcall LC = (Node->getOpcode() == ISD::FP_TO_SINT) ? |
| 4001 | RTLIB::getFPTOSINT(OVT, VT) : RTLIB::getFPTOUINT(OVT, VT); |
| 4002 | assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unexpectd fp-to-int conversion!"); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4003 | SDValue Dummy; |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 4004 | Result = ExpandLibCall(LC, Node, false/*sign irrelevant*/, Dummy); |
Evan Cheng | 6af00d5 | 2006-12-13 01:57:55 +0000 | [diff] [blame] | 4005 | break; |
| 4006 | } |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 4007 | case Promote: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 4008 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4009 | Result = DAG.UpdateNodeOperands(Result, LegalizeOp(Tmp1)); |
| 4010 | Result = LegalizeOp(Result); |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 4011 | break; |
| 4012 | } |
| 4013 | break; |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 4014 | |
Chris Lattner | f2670a8 | 2008-01-16 06:57:07 +0000 | [diff] [blame] | 4015 | case ISD::FP_EXTEND: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4016 | MVT DstVT = Op.getValueType(); |
| 4017 | MVT SrcVT = Op.getOperand(0).getValueType(); |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4018 | if (TLI.getConvertAction(SrcVT, DstVT) == TargetLowering::Expand) { |
| 4019 | // The only other way we can lower this is to turn it into a STORE, |
| 4020 | // LOAD pair, targetting a temporary location (a stack slot). |
| 4021 | Result = EmitStackConvert(Node->getOperand(0), SrcVT, DstVT); |
| 4022 | break; |
Chris Lattner | f2670a8 | 2008-01-16 06:57:07 +0000 | [diff] [blame] | 4023 | } |
| 4024 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 4025 | case Expand: assert(0 && "Shouldn't need to expand other operators here!"); |
| 4026 | case Legal: |
| 4027 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 4028 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 4029 | break; |
| 4030 | case Promote: |
| 4031 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4032 | Result = DAG.getNode(ISD::FP_EXTEND, Op.getValueType(), Tmp1); |
| 4033 | break; |
| 4034 | } |
| 4035 | break; |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4036 | } |
Dale Johannesen | 5411a39 | 2007-08-09 01:04:01 +0000 | [diff] [blame] | 4037 | case ISD::FP_ROUND: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4038 | MVT DstVT = Op.getValueType(); |
| 4039 | MVT SrcVT = Op.getOperand(0).getValueType(); |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4040 | if (TLI.getConvertAction(SrcVT, DstVT) == TargetLowering::Expand) { |
| 4041 | if (SrcVT == MVT::ppcf128) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4042 | SDValue Lo; |
Dale Johannesen | 713ed3f | 2008-01-20 01:18:38 +0000 | [diff] [blame] | 4043 | ExpandOp(Node->getOperand(0), Lo, Result); |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4044 | // 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] | 4045 | if (DstVT!=MVT::f64) |
| 4046 | Result = DAG.getNode(ISD::FP_ROUND, DstVT, Result, Op.getOperand(1)); |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4047 | break; |
Dale Johannesen | 5411a39 | 2007-08-09 01:04:01 +0000 | [diff] [blame] | 4048 | } |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4049 | // The only other way we can lower this is to turn it into a STORE, |
| 4050 | // LOAD pair, targetting a temporary location (a stack slot). |
| 4051 | Result = EmitStackConvert(Node->getOperand(0), DstVT, DstVT); |
| 4052 | break; |
Dale Johannesen | 849f214 | 2007-07-03 00:53:03 +0000 | [diff] [blame] | 4053 | } |
Chris Lattner | f2670a8 | 2008-01-16 06:57:07 +0000 | [diff] [blame] | 4054 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 4055 | case Expand: assert(0 && "Shouldn't need to expand other operators here!"); |
| 4056 | case Legal: |
| 4057 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4058 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
Chris Lattner | f2670a8 | 2008-01-16 06:57:07 +0000 | [diff] [blame] | 4059 | break; |
| 4060 | case Promote: |
| 4061 | Tmp1 = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4062 | Result = DAG.getNode(ISD::FP_ROUND, Op.getValueType(), Tmp1, |
| 4063 | Node->getOperand(1)); |
Chris Lattner | f2670a8 | 2008-01-16 06:57:07 +0000 | [diff] [blame] | 4064 | break; |
| 4065 | } |
| 4066 | break; |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4067 | } |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 4068 | case ISD::ANY_EXTEND: |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 4069 | case ISD::ZERO_EXTEND: |
| 4070 | case ISD::SIGN_EXTEND: |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 4071 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4072 | case Expand: assert(0 && "Shouldn't need to expand other operators here!"); |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 4073 | case Legal: |
| 4074 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Scott Michel | 82747a5 | 2008-04-30 00:26:38 +0000 | [diff] [blame] | 4075 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Scott Michel | 0123b7d | 2008-02-15 23:05:48 +0000 | [diff] [blame] | 4076 | if (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0)) == |
| 4077 | TargetLowering::Custom) { |
Scott Michel | 82747a5 | 2008-04-30 00:26:38 +0000 | [diff] [blame] | 4078 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 4079 | if (Tmp1.getNode()) Result = Tmp1; |
Scott Michel | 0123b7d | 2008-02-15 23:05:48 +0000 | [diff] [blame] | 4080 | } |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 4081 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4082 | case Promote: |
| 4083 | switch (Node->getOpcode()) { |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 4084 | case ISD::ANY_EXTEND: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 4085 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4086 | Result = DAG.getNode(ISD::ANY_EXTEND, Op.getValueType(), Tmp1); |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 4087 | break; |
Chris Lattner | 1713e73 | 2005-01-16 00:38:00 +0000 | [diff] [blame] | 4088 | case ISD::ZERO_EXTEND: |
| 4089 | Result = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 4090 | Result = DAG.getNode(ISD::ANY_EXTEND, Op.getValueType(), Result); |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 4091 | Result = DAG.getZeroExtendInReg(Result, |
| 4092 | Node->getOperand(0).getValueType()); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4093 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4094 | case ISD::SIGN_EXTEND: |
Chris Lattner | 1713e73 | 2005-01-16 00:38:00 +0000 | [diff] [blame] | 4095 | Result = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 4096 | Result = DAG.getNode(ISD::ANY_EXTEND, Op.getValueType(), Result); |
Chris Lattner | 1713e73 | 2005-01-16 00:38:00 +0000 | [diff] [blame] | 4097 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(), |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 4098 | Result, |
| 4099 | DAG.getValueType(Node->getOperand(0).getValueType())); |
Chris Lattner | 1713e73 | 2005-01-16 00:38:00 +0000 | [diff] [blame] | 4100 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4101 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 4102 | } |
| 4103 | break; |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 4104 | case ISD::FP_ROUND_INREG: |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 4105 | case ISD::SIGN_EXTEND_INREG: { |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 4106 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4107 | MVT ExtraVT = cast<VTSDNode>(Node->getOperand(1))->getVT(); |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 4108 | |
| 4109 | // If this operation is not supported, convert it to a shl/shr or load/store |
| 4110 | // pair. |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 4111 | switch (TLI.getOperationAction(Node->getOpcode(), ExtraVT)) { |
| 4112 | default: assert(0 && "This action not supported for this op yet!"); |
| 4113 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 4114 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 4115 | break; |
| 4116 | case TargetLowering::Expand: |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 4117 | // If this is an integer extend and shifts are supported, do that. |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 4118 | if (Node->getOpcode() == ISD::SIGN_EXTEND_INREG) { |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 4119 | // NOTE: we could fall back on load/store here too for targets without |
| 4120 | // SAR. However, it is doubtful that any exist. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4121 | unsigned BitsDiff = Node->getValueType(0).getSizeInBits() - |
| 4122 | ExtraVT.getSizeInBits(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4123 | SDValue ShiftCst = DAG.getConstant(BitsDiff, TLI.getShiftAmountTy()); |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 4124 | Result = DAG.getNode(ISD::SHL, Node->getValueType(0), |
| 4125 | Node->getOperand(0), ShiftCst); |
| 4126 | Result = DAG.getNode(ISD::SRA, Node->getValueType(0), |
| 4127 | Result, ShiftCst); |
| 4128 | } else if (Node->getOpcode() == ISD::FP_ROUND_INREG) { |
Jim Laskey | 2d84c4c | 2006-10-11 17:52:19 +0000 | [diff] [blame] | 4129 | // 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] | 4130 | // EXTLOAD pair, targetting a temporary location (a stack slot). |
| 4131 | |
| 4132 | // NOTE: there is a choice here between constantly creating new stack |
| 4133 | // slots and always reusing the same one. We currently always create |
| 4134 | // new ones, as reuse may inhibit scheduling. |
Chris Lattner | a66bb39 | 2008-01-16 07:51:34 +0000 | [diff] [blame] | 4135 | Result = EmitStackConvert(Node->getOperand(0), ExtraVT, |
| 4136 | Node->getValueType(0)); |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 4137 | } else { |
| 4138 | assert(0 && "Unknown op"); |
| 4139 | } |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 4140 | break; |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 4141 | } |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 4142 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 4143 | } |
Duncan Sands | 36397f5 | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 4144 | case ISD::TRAMPOLINE: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4145 | SDValue Ops[6]; |
Duncan Sands | 36397f5 | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 4146 | for (unsigned i = 0; i != 6; ++i) |
| 4147 | Ops[i] = LegalizeOp(Node->getOperand(i)); |
| 4148 | Result = DAG.UpdateNodeOperands(Result, Ops, 6); |
| 4149 | // The only option for this node is to custom lower it. |
| 4150 | Result = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 4151 | assert(Result.getNode() && "Should always custom lower!"); |
Duncan Sands | f7331b3 | 2007-09-11 14:10:23 +0000 | [diff] [blame] | 4152 | |
| 4153 | // Since trampoline produces two values, make sure to remember that we |
| 4154 | // legalized both of them. |
| 4155 | Tmp1 = LegalizeOp(Result.getValue(1)); |
| 4156 | Result = LegalizeOp(Result); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4157 | AddLegalizedOperand(SDValue(Node, 0), Result); |
| 4158 | AddLegalizedOperand(SDValue(Node, 1), Tmp1); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 4159 | return Op.getResNo() ? Tmp1 : Result; |
Duncan Sands | 36397f5 | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 4160 | } |
Dan Gohman | 9c78a39 | 2008-05-14 00:43:10 +0000 | [diff] [blame] | 4161 | case ISD::FLT_ROUNDS_: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4162 | MVT VT = Node->getValueType(0); |
Anton Korobeynikov | 917c2a6 | 2007-11-15 23:25:33 +0000 | [diff] [blame] | 4163 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 4164 | default: assert(0 && "This action not supported for this op yet!"); |
| 4165 | case TargetLowering::Custom: |
| 4166 | Result = TLI.LowerOperation(Op, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 4167 | if (Result.getNode()) break; |
Anton Korobeynikov | 917c2a6 | 2007-11-15 23:25:33 +0000 | [diff] [blame] | 4168 | // Fall Thru |
| 4169 | case TargetLowering::Legal: |
| 4170 | // If this operation is not supported, lower it to constant 1 |
| 4171 | Result = DAG.getConstant(1, VT); |
| 4172 | break; |
| 4173 | } |
Dan Gohman | 9ab9ee8 | 2008-05-12 16:07:15 +0000 | [diff] [blame] | 4174 | break; |
Anton Korobeynikov | 917c2a6 | 2007-11-15 23:25:33 +0000 | [diff] [blame] | 4175 | } |
Chris Lattner | 41bab0b | 2008-01-15 21:58:08 +0000 | [diff] [blame] | 4176 | case ISD::TRAP: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4177 | MVT VT = Node->getValueType(0); |
Anton Korobeynikov | 66fac79 | 2008-01-15 07:02:33 +0000 | [diff] [blame] | 4178 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 4179 | default: assert(0 && "This action not supported for this op yet!"); |
Chris Lattner | 41bab0b | 2008-01-15 21:58:08 +0000 | [diff] [blame] | 4180 | case TargetLowering::Legal: |
| 4181 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 4182 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 4183 | break; |
Anton Korobeynikov | 66fac79 | 2008-01-15 07:02:33 +0000 | [diff] [blame] | 4184 | case TargetLowering::Custom: |
| 4185 | Result = TLI.LowerOperation(Op, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 4186 | if (Result.getNode()) break; |
Anton Korobeynikov | 66fac79 | 2008-01-15 07:02:33 +0000 | [diff] [blame] | 4187 | // Fall Thru |
Chris Lattner | 41bab0b | 2008-01-15 21:58:08 +0000 | [diff] [blame] | 4188 | case TargetLowering::Expand: |
Anton Korobeynikov | 66fac79 | 2008-01-15 07:02:33 +0000 | [diff] [blame] | 4189 | // If this operation is not supported, lower it to 'abort()' call |
Chris Lattner | 41bab0b | 2008-01-15 21:58:08 +0000 | [diff] [blame] | 4190 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Anton Korobeynikov | 66fac79 | 2008-01-15 07:02:33 +0000 | [diff] [blame] | 4191 | TargetLowering::ArgListTy Args; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4192 | std::pair<SDValue,SDValue> CallResult = |
Duncan Sands | 00fee65 | 2008-02-14 17:28:50 +0000 | [diff] [blame] | 4193 | TLI.LowerCallTo(Tmp1, Type::VoidTy, |
Dale Johannesen | 86098bd | 2008-09-26 19:31:26 +0000 | [diff] [blame] | 4194 | false, false, false, false, CallingConv::C, false, |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 4195 | DAG.getExternalSymbol("abort", TLI.getPointerTy()), |
Chris Lattner | 034f12e | 2008-01-15 22:09:33 +0000 | [diff] [blame] | 4196 | Args, DAG); |
Anton Korobeynikov | 66fac79 | 2008-01-15 07:02:33 +0000 | [diff] [blame] | 4197 | Result = CallResult.second; |
| 4198 | break; |
| 4199 | } |
Chris Lattner | 41bab0b | 2008-01-15 21:58:08 +0000 | [diff] [blame] | 4200 | break; |
Anton Korobeynikov | 66fac79 | 2008-01-15 07:02:33 +0000 | [diff] [blame] | 4201 | } |
Bill Wendling | 8ac0d4b | 2008-11-22 00:22:52 +0000 | [diff] [blame] | 4202 | |
Bill Wendling | c0062fb | 2008-11-25 08:12:19 +0000 | [diff] [blame] | 4203 | case ISD::SADDO: { |
| 4204 | MVT VT = Node->getValueType(0); |
| 4205 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 4206 | default: assert(0 && "This action not supported for this op yet!"); |
| 4207 | case TargetLowering::Custom: |
| 4208 | Result = TLI.LowerOperation(Op, DAG); |
| 4209 | if (Result.getNode()) break; |
| 4210 | // FALLTHROUGH |
| 4211 | case TargetLowering::Legal: { |
| 4212 | SDValue LHS = LegalizeOp(Node->getOperand(0)); |
| 4213 | SDValue RHS = LegalizeOp(Node->getOperand(1)); |
| 4214 | |
| 4215 | SDValue Sum = DAG.getNode(ISD::ADD, LHS.getValueType(), LHS, RHS); |
Bill Wendling | c0062fb | 2008-11-25 08:12:19 +0000 | [diff] [blame] | 4216 | MVT OType = Node->getValueType(1); |
| 4217 | |
Bill Wendling | a6af91a | 2008-11-25 08:19:22 +0000 | [diff] [blame] | 4218 | SDValue Zero = DAG.getConstant(0, LHS.getValueType()); |
Bill Wendling | c0062fb | 2008-11-25 08:12:19 +0000 | [diff] [blame] | 4219 | |
Bill Wendling | 740464e | 2008-11-25 19:40:17 +0000 | [diff] [blame] | 4220 | // LHSSign -> LHS >= 0 |
| 4221 | // RHSSign -> RHS >= 0 |
| 4222 | // SumSign -> Sum >= 0 |
| 4223 | // |
| 4224 | // Overflow -> (LHSSign == RHSSign) && (LHSSign != SumSign) |
| 4225 | // |
| 4226 | SDValue LHSSign = DAG.getSetCC(OType, LHS, Zero, ISD::SETGE); |
| 4227 | SDValue RHSSign = DAG.getSetCC(OType, RHS, Zero, ISD::SETGE); |
| 4228 | SDValue SignsEq = DAG.getSetCC(OType, LHSSign, RHSSign, ISD::SETEQ); |
Bill Wendling | c0062fb | 2008-11-25 08:12:19 +0000 | [diff] [blame] | 4229 | |
Bill Wendling | 740464e | 2008-11-25 19:40:17 +0000 | [diff] [blame] | 4230 | SDValue SumSign = DAG.getSetCC(OType, Sum, Zero, ISD::SETGE); |
| 4231 | SDValue SumSignNE = DAG.getSetCC(OType, LHSSign, SumSign, ISD::SETNE); |
Bill Wendling | c0062fb | 2008-11-25 08:12:19 +0000 | [diff] [blame] | 4232 | |
Bill Wendling | 740464e | 2008-11-25 19:40:17 +0000 | [diff] [blame] | 4233 | SDValue Cmp = DAG.getNode(ISD::AND, OType, SignsEq, SumSignNE); |
Bill Wendling | c0062fb | 2008-11-25 08:12:19 +0000 | [diff] [blame] | 4234 | |
| 4235 | MVT ValueVTs[] = { LHS.getValueType(), OType }; |
| 4236 | SDValue Ops[] = { Sum, Cmp }; |
| 4237 | |
Duncan Sands | aaffa05 | 2008-12-01 11:41:29 +0000 | [diff] [blame] | 4238 | Result = DAG.getNode(ISD::MERGE_VALUES, DAG.getVTList(&ValueVTs[0], 2), |
| 4239 | &Ops[0], 2); |
Bill Wendling | c0062fb | 2008-11-25 08:12:19 +0000 | [diff] [blame] | 4240 | SDNode *RNode = Result.getNode(); |
| 4241 | DAG.ReplaceAllUsesOfValueWith(SDValue(Node, 0), SDValue(RNode, 0)); |
| 4242 | DAG.ReplaceAllUsesOfValueWith(SDValue(Node, 1), SDValue(RNode, 1)); |
| 4243 | break; |
| 4244 | } |
| 4245 | } |
| 4246 | |
| 4247 | break; |
| 4248 | } |
Bill Wendling | def2739 | 2008-11-24 01:38:29 +0000 | [diff] [blame] | 4249 | case ISD::UADDO: { |
Bill Wendling | 41ea7e7 | 2008-11-24 19:21:46 +0000 | [diff] [blame] | 4250 | MVT VT = Node->getValueType(0); |
| 4251 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 4252 | default: assert(0 && "This action not supported for this op yet!"); |
| 4253 | case TargetLowering::Custom: |
| 4254 | Result = TLI.LowerOperation(Op, DAG); |
| 4255 | if (Result.getNode()) break; |
| 4256 | // FALLTHROUGH |
| 4257 | case TargetLowering::Legal: { |
| 4258 | SDValue LHS = LegalizeOp(Node->getOperand(0)); |
| 4259 | SDValue RHS = LegalizeOp(Node->getOperand(1)); |
Bill Wendling | 8ac0d4b | 2008-11-22 00:22:52 +0000 | [diff] [blame] | 4260 | |
Bill Wendling | 41ea7e7 | 2008-11-24 19:21:46 +0000 | [diff] [blame] | 4261 | SDValue Sum = DAG.getNode(ISD::ADD, LHS.getValueType(), LHS, RHS); |
| 4262 | MVT OType = Node->getValueType(1); |
Bill Wendling | c0062fb | 2008-11-25 08:12:19 +0000 | [diff] [blame] | 4263 | SDValue Cmp = DAG.getSetCC(OType, Sum, LHS, ISD::SETULT); |
Bill Wendling | 8ac0d4b | 2008-11-22 00:22:52 +0000 | [diff] [blame] | 4264 | |
Bill Wendling | 41ea7e7 | 2008-11-24 19:21:46 +0000 | [diff] [blame] | 4265 | MVT ValueVTs[] = { LHS.getValueType(), OType }; |
| 4266 | SDValue Ops[] = { Sum, Cmp }; |
Bill Wendling | 8ac0d4b | 2008-11-22 00:22:52 +0000 | [diff] [blame] | 4267 | |
Duncan Sands | aaffa05 | 2008-12-01 11:41:29 +0000 | [diff] [blame] | 4268 | Result = DAG.getNode(ISD::MERGE_VALUES, DAG.getVTList(&ValueVTs[0], 2), |
| 4269 | &Ops[0], 2); |
Bill Wendling | 41ea7e7 | 2008-11-24 19:21:46 +0000 | [diff] [blame] | 4270 | SDNode *RNode = Result.getNode(); |
| 4271 | DAG.ReplaceAllUsesOfValueWith(SDValue(Node, 0), SDValue(RNode, 0)); |
| 4272 | DAG.ReplaceAllUsesOfValueWith(SDValue(Node, 1), SDValue(RNode, 1)); |
| 4273 | break; |
| 4274 | } |
| 4275 | } |
| 4276 | |
Bill Wendling | 8ac0d4b | 2008-11-22 00:22:52 +0000 | [diff] [blame] | 4277 | break; |
| 4278 | } |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 4279 | } |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4280 | |
Chris Lattner | 4ddd283 | 2006-04-08 04:13:17 +0000 | [diff] [blame] | 4281 | assert(Result.getValueType() == Op.getValueType() && |
| 4282 | "Bad legalization!"); |
| 4283 | |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4284 | // Make sure that the generated code is itself legal. |
| 4285 | if (Result != Op) |
| 4286 | Result = LegalizeOp(Result); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 4287 | |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 4288 | // Note that LegalizeOp may be reentered even from single-use nodes, which |
| 4289 | // means that we always must cache transformed nodes. |
| 4290 | AddLegalizedOperand(Op, Result); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 4291 | return Result; |
| 4292 | } |
| 4293 | |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4294 | /// PromoteOp - Given an operation that produces a value in an invalid type, |
| 4295 | /// promote it to compute the value into a larger type. The produced value will |
| 4296 | /// have the correct bits for the low portion of the register, but no guarantee |
| 4297 | /// is made about the top bits: it may be zero, sign-extended, or garbage. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4298 | SDValue SelectionDAGLegalize::PromoteOp(SDValue Op) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4299 | MVT VT = Op.getValueType(); |
| 4300 | MVT NVT = TLI.getTypeToTransformTo(VT); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4301 | assert(getTypeAction(VT) == Promote && |
| 4302 | "Caller should expand or legalize operands that are not promotable!"); |
Duncan Sands | 8e4eb09 | 2008-06-08 20:54:56 +0000 | [diff] [blame] | 4303 | assert(NVT.bitsGT(VT) && NVT.isInteger() == VT.isInteger() && |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4304 | "Cannot promote to smaller type!"); |
| 4305 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4306 | SDValue Tmp1, Tmp2, Tmp3; |
| 4307 | SDValue Result; |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 4308 | SDNode *Node = Op.getNode(); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4309 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4310 | DenseMap<SDValue, SDValue>::iterator I = PromotedNodes.find(Op); |
Chris Lattner | 6fdcb25 | 2005-09-02 20:32:45 +0000 | [diff] [blame] | 4311 | if (I != PromotedNodes.end()) return I->second; |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 4312 | |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4313 | switch (Node->getOpcode()) { |
Chris Lattner | d5d0f9b | 2005-08-16 21:55:35 +0000 | [diff] [blame] | 4314 | case ISD::CopyFromReg: |
| 4315 | assert(0 && "CopyFromReg must be legal!"); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4316 | default: |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 4317 | #ifndef NDEBUG |
Dan Gohman | 3983358 | 2007-06-04 16:17:33 +0000 | [diff] [blame] | 4318 | cerr << "NODE: "; Node->dump(&DAG); cerr << "\n"; |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 4319 | #endif |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4320 | assert(0 && "Do not know how to promote this operator!"); |
| 4321 | abort(); |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 4322 | case ISD::UNDEF: |
| 4323 | Result = DAG.getNode(ISD::UNDEF, NVT); |
| 4324 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4325 | case ISD::Constant: |
Chris Lattner | ec176e3 | 2005-08-30 16:56:19 +0000 | [diff] [blame] | 4326 | if (VT != MVT::i1) |
| 4327 | Result = DAG.getNode(ISD::SIGN_EXTEND, NVT, Op); |
| 4328 | else |
| 4329 | Result = DAG.getNode(ISD::ZERO_EXTEND, NVT, Op); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4330 | assert(isa<ConstantSDNode>(Result) && "Didn't constant fold zext?"); |
| 4331 | break; |
| 4332 | case ISD::ConstantFP: |
| 4333 | Result = DAG.getNode(ISD::FP_EXTEND, NVT, Op); |
| 4334 | assert(isa<ConstantFPSDNode>(Result) && "Didn't constant fold fp_extend?"); |
| 4335 | break; |
Chris Lattner | ef5cd1d | 2005-01-18 17:54:55 +0000 | [diff] [blame] | 4336 | |
Chris Lattner | 82fbfb6 | 2005-01-18 02:59:52 +0000 | [diff] [blame] | 4337 | case ISD::SETCC: |
Scott Michel | 5b8f82e | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 4338 | assert(isTypeLegal(TLI.getSetCCResultType(Node->getOperand(0))) |
Nate Begeman | 5922f56 | 2008-03-14 00:53:31 +0000 | [diff] [blame] | 4339 | && "SetCC type is not legal??"); |
Scott Michel | 5b8f82e | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 4340 | Result = DAG.getNode(ISD::SETCC, |
Nate Begeman | 5922f56 | 2008-03-14 00:53:31 +0000 | [diff] [blame] | 4341 | TLI.getSetCCResultType(Node->getOperand(0)), |
| 4342 | Node->getOperand(0), Node->getOperand(1), |
| 4343 | Node->getOperand(2)); |
Chris Lattner | 82fbfb6 | 2005-01-18 02:59:52 +0000 | [diff] [blame] | 4344 | break; |
Chris Lattner | fdfded5 | 2006-04-12 16:20:43 +0000 | [diff] [blame] | 4345 | |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4346 | case ISD::TRUNCATE: |
| 4347 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 4348 | case Legal: |
| 4349 | Result = LegalizeOp(Node->getOperand(0)); |
Duncan Sands | 8e4eb09 | 2008-06-08 20:54:56 +0000 | [diff] [blame] | 4350 | assert(Result.getValueType().bitsGE(NVT) && |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4351 | "This truncation doesn't make sense!"); |
Duncan Sands | 8e4eb09 | 2008-06-08 20:54:56 +0000 | [diff] [blame] | 4352 | if (Result.getValueType().bitsGT(NVT)) // Truncate to NVT instead of VT |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4353 | Result = DAG.getNode(ISD::TRUNCATE, NVT, Result); |
| 4354 | break; |
Chris Lattner | e76ad6d | 2005-01-28 22:52:50 +0000 | [diff] [blame] | 4355 | case Promote: |
| 4356 | // The truncation is not required, because we don't guarantee anything |
| 4357 | // about high bits anyway. |
| 4358 | Result = PromoteOp(Node->getOperand(0)); |
| 4359 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4360 | case Expand: |
Nate Begeman | 79e46ac | 2005-04-04 00:57:08 +0000 | [diff] [blame] | 4361 | ExpandOp(Node->getOperand(0), Tmp1, Tmp2); |
| 4362 | // Truncate the low part of the expanded value to the result type |
Chris Lattner | e21c305 | 2005-08-01 18:16:37 +0000 | [diff] [blame] | 4363 | Result = DAG.getNode(ISD::TRUNCATE, NVT, Tmp1); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4364 | } |
| 4365 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4366 | case ISD::SIGN_EXTEND: |
| 4367 | case ISD::ZERO_EXTEND: |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 4368 | case ISD::ANY_EXTEND: |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4369 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 4370 | case Expand: assert(0 && "BUG: Smaller reg should have been promoted!"); |
| 4371 | case Legal: |
| 4372 | // 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] | 4373 | Result = DAG.getNode(Node->getOpcode(), NVT, Node->getOperand(0)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4374 | break; |
| 4375 | case Promote: |
| 4376 | // Promote the reg if it's smaller. |
| 4377 | Result = PromoteOp(Node->getOperand(0)); |
| 4378 | // The high bits are not guaranteed to be anything. Insert an extend. |
| 4379 | if (Node->getOpcode() == ISD::SIGN_EXTEND) |
Chris Lattner | 595dc54 | 2005-02-04 18:39:19 +0000 | [diff] [blame] | 4380 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Result, |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 4381 | DAG.getValueType(Node->getOperand(0).getValueType())); |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 4382 | else if (Node->getOpcode() == ISD::ZERO_EXTEND) |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 4383 | Result = DAG.getZeroExtendInReg(Result, |
| 4384 | Node->getOperand(0).getValueType()); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4385 | break; |
| 4386 | } |
| 4387 | break; |
Mon P Wang | 77cdf30 | 2008-11-10 20:54:11 +0000 | [diff] [blame] | 4388 | case ISD::CONVERT_RNDSAT: { |
| 4389 | ISD::CvtCode CvtCode = cast<CvtRndSatSDNode>(Node)->getCvtCode(); |
| 4390 | assert ((CvtCode == ISD::CVT_SS || CvtCode == ISD::CVT_SU || |
| 4391 | CvtCode == ISD::CVT_US || CvtCode == ISD::CVT_UU || |
| 4392 | CvtCode == ISD::CVT_SF || CvtCode == ISD::CVT_UF) && |
| 4393 | "can only promote integers"); |
| 4394 | Result = DAG.getConvertRndSat(NVT, Node->getOperand(0), |
| 4395 | Node->getOperand(1), Node->getOperand(2), |
| 4396 | Node->getOperand(3), Node->getOperand(4), |
| 4397 | CvtCode); |
| 4398 | break; |
| 4399 | |
| 4400 | } |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 4401 | case ISD::BIT_CONVERT: |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 4402 | Result = EmitStackConvert(Node->getOperand(0), Node->getValueType(0), |
| 4403 | Node->getValueType(0)); |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 4404 | Result = PromoteOp(Result); |
| 4405 | break; |
| 4406 | |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4407 | case ISD::FP_EXTEND: |
| 4408 | assert(0 && "Case not implemented. Dynamically dead with 2 FP types!"); |
| 4409 | case ISD::FP_ROUND: |
| 4410 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 4411 | case Expand: assert(0 && "BUG: Cannot expand FP regs!"); |
| 4412 | case Promote: assert(0 && "Unreachable with 2 FP types!"); |
| 4413 | case Legal: |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4414 | if (Node->getConstantOperandVal(1) == 0) { |
| 4415 | // Input is legal? Do an FP_ROUND_INREG. |
| 4416 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Node->getOperand(0), |
| 4417 | DAG.getValueType(VT)); |
| 4418 | } else { |
| 4419 | // Just remove the truncate, it isn't affecting the value. |
| 4420 | Result = DAG.getNode(ISD::FP_ROUND, NVT, Node->getOperand(0), |
| 4421 | Node->getOperand(1)); |
| 4422 | } |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4423 | break; |
| 4424 | } |
| 4425 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4426 | case ISD::SINT_TO_FP: |
| 4427 | case ISD::UINT_TO_FP: |
| 4428 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 4429 | case Legal: |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4430 | // No extra round required here. |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4431 | Result = DAG.getNode(Node->getOpcode(), NVT, Node->getOperand(0)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4432 | break; |
| 4433 | |
| 4434 | case Promote: |
| 4435 | Result = PromoteOp(Node->getOperand(0)); |
| 4436 | if (Node->getOpcode() == ISD::SINT_TO_FP) |
| 4437 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(), |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 4438 | Result, |
| 4439 | DAG.getValueType(Node->getOperand(0).getValueType())); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4440 | else |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 4441 | Result = DAG.getZeroExtendInReg(Result, |
| 4442 | Node->getOperand(0).getValueType()); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4443 | // No extra round required here. |
| 4444 | Result = DAG.getNode(Node->getOpcode(), NVT, Result); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4445 | break; |
| 4446 | case Expand: |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4447 | Result = ExpandIntToFP(Node->getOpcode() == ISD::SINT_TO_FP, NVT, |
| 4448 | Node->getOperand(0)); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4449 | // Round if we cannot tolerate excess precision. |
| 4450 | if (NoExcessFPPrecision) |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 4451 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 4452 | DAG.getValueType(VT)); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4453 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4454 | } |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4455 | break; |
| 4456 | |
Chris Lattner | 5e3c5b4 | 2005-12-09 17:32:47 +0000 | [diff] [blame] | 4457 | case ISD::SIGN_EXTEND_INREG: |
| 4458 | Result = PromoteOp(Node->getOperand(0)); |
| 4459 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Result, |
| 4460 | Node->getOperand(1)); |
| 4461 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4462 | case ISD::FP_TO_SINT: |
| 4463 | case ISD::FP_TO_UINT: |
| 4464 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 4465 | case Legal: |
Evan Cheng | 0b1b9dc | 2006-12-16 02:10:30 +0000 | [diff] [blame] | 4466 | case Expand: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4467 | Tmp1 = Node->getOperand(0); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4468 | break; |
| 4469 | case Promote: |
| 4470 | // The input result is prerounded, so we don't have to do anything |
| 4471 | // special. |
| 4472 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4473 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4474 | } |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 4475 | // If we're promoting a UINT to a larger size, check to see if the new node |
| 4476 | // will be legal. If it isn't, check to see if FP_TO_SINT is legal, since |
| 4477 | // we can use that instead. This allows us to generate better code for |
| 4478 | // FP_TO_UINT for small destination sizes on targets where FP_TO_UINT is not |
| 4479 | // legal, such as PowerPC. |
| 4480 | if (Node->getOpcode() == ISD::FP_TO_UINT && |
Chris Lattner | c9c60f6 | 2005-08-24 16:35:28 +0000 | [diff] [blame] | 4481 | !TLI.isOperationLegal(ISD::FP_TO_UINT, NVT) && |
Nate Begeman | b7f6ef1 | 2005-10-25 23:47:25 +0000 | [diff] [blame] | 4482 | (TLI.isOperationLegal(ISD::FP_TO_SINT, NVT) || |
| 4483 | TLI.getOperationAction(ISD::FP_TO_SINT, NVT)==TargetLowering::Custom)){ |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 4484 | Result = DAG.getNode(ISD::FP_TO_SINT, NVT, Tmp1); |
| 4485 | } else { |
| 4486 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1); |
| 4487 | } |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4488 | break; |
| 4489 | |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 4490 | case ISD::FABS: |
| 4491 | case ISD::FNEG: |
| 4492 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4493 | assert(Tmp1.getValueType() == NVT); |
| 4494 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1); |
| 4495 | // NOTE: we do not have to do any extra rounding here for |
| 4496 | // NoExcessFPPrecision, because we know the input will have the appropriate |
| 4497 | // precision, and these operations don't modify precision at all. |
| 4498 | break; |
| 4499 | |
Dale Johannesen | 7794f2a | 2008-09-04 00:47:13 +0000 | [diff] [blame] | 4500 | case ISD::FLOG: |
| 4501 | case ISD::FLOG2: |
| 4502 | case ISD::FLOG10: |
| 4503 | case ISD::FEXP: |
| 4504 | case ISD::FEXP2: |
Chris Lattner | da6ba87 | 2005-04-28 21:44:33 +0000 | [diff] [blame] | 4505 | case ISD::FSQRT: |
| 4506 | case ISD::FSIN: |
| 4507 | case ISD::FCOS: |
Dan Gohman | 2bb1e3e | 2008-08-21 18:38:14 +0000 | [diff] [blame] | 4508 | case ISD::FTRUNC: |
| 4509 | case ISD::FFLOOR: |
| 4510 | case ISD::FCEIL: |
| 4511 | case ISD::FRINT: |
| 4512 | case ISD::FNEARBYINT: |
Chris Lattner | da6ba87 | 2005-04-28 21:44:33 +0000 | [diff] [blame] | 4513 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4514 | assert(Tmp1.getValueType() == NVT); |
| 4515 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4516 | if (NoExcessFPPrecision) |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 4517 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 4518 | DAG.getValueType(VT)); |
Chris Lattner | da6ba87 | 2005-04-28 21:44:33 +0000 | [diff] [blame] | 4519 | break; |
| 4520 | |
Evan Cheng | 9d24ac5 | 2008-09-09 23:35:53 +0000 | [diff] [blame] | 4521 | case ISD::FPOW: |
Chris Lattner | 8b2d42c | 2007-03-03 23:43:21 +0000 | [diff] [blame] | 4522 | case ISD::FPOWI: { |
Evan Cheng | 9d24ac5 | 2008-09-09 23:35:53 +0000 | [diff] [blame] | 4523 | // Promote f32 pow(i) to f64 pow(i). Note that this could insert a libcall |
Chris Lattner | 8b2d42c | 2007-03-03 23:43:21 +0000 | [diff] [blame] | 4524 | // directly as well, which may be better. |
| 4525 | Tmp1 = PromoteOp(Node->getOperand(0)); |
Evan Cheng | 9d24ac5 | 2008-09-09 23:35:53 +0000 | [diff] [blame] | 4526 | Tmp2 = Node->getOperand(1); |
| 4527 | if (Node->getOpcode() == ISD::FPOW) |
| 4528 | Tmp2 = PromoteOp(Tmp2); |
Chris Lattner | 8b2d42c | 2007-03-03 23:43:21 +0000 | [diff] [blame] | 4529 | assert(Tmp1.getValueType() == NVT); |
Evan Cheng | 9d24ac5 | 2008-09-09 23:35:53 +0000 | [diff] [blame] | 4530 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
Chris Lattner | 8b2d42c | 2007-03-03 23:43:21 +0000 | [diff] [blame] | 4531 | if (NoExcessFPPrecision) |
| 4532 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 4533 | DAG.getValueType(VT)); |
| 4534 | break; |
| 4535 | } |
| 4536 | |
Dale Johannesen | e00a8a2 | 2008-08-28 02:44:49 +0000 | [diff] [blame] | 4537 | case ISD::ATOMIC_CMP_SWAP_8: |
| 4538 | case ISD::ATOMIC_CMP_SWAP_16: |
| 4539 | case ISD::ATOMIC_CMP_SWAP_32: |
| 4540 | case ISD::ATOMIC_CMP_SWAP_64: { |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 4541 | AtomicSDNode* AtomNode = cast<AtomicSDNode>(Node); |
Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 4542 | Tmp2 = PromoteOp(Node->getOperand(2)); |
| 4543 | Tmp3 = PromoteOp(Node->getOperand(3)); |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 4544 | Result = DAG.getAtomic(Node->getOpcode(), AtomNode->getChain(), |
| 4545 | AtomNode->getBasePtr(), Tmp2, Tmp3, |
Dan Gohman | fd4418f | 2008-06-25 16:07:49 +0000 | [diff] [blame] | 4546 | AtomNode->getSrcValue(), |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 4547 | AtomNode->getAlignment()); |
Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 4548 | // Remember that we legalized the chain. |
| 4549 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1))); |
| 4550 | break; |
| 4551 | } |
Dale Johannesen | e00a8a2 | 2008-08-28 02:44:49 +0000 | [diff] [blame] | 4552 | case ISD::ATOMIC_LOAD_ADD_8: |
| 4553 | case ISD::ATOMIC_LOAD_SUB_8: |
| 4554 | case ISD::ATOMIC_LOAD_AND_8: |
| 4555 | case ISD::ATOMIC_LOAD_OR_8: |
| 4556 | case ISD::ATOMIC_LOAD_XOR_8: |
| 4557 | case ISD::ATOMIC_LOAD_NAND_8: |
| 4558 | case ISD::ATOMIC_LOAD_MIN_8: |
| 4559 | case ISD::ATOMIC_LOAD_MAX_8: |
| 4560 | case ISD::ATOMIC_LOAD_UMIN_8: |
| 4561 | case ISD::ATOMIC_LOAD_UMAX_8: |
| 4562 | case ISD::ATOMIC_SWAP_8: |
| 4563 | case ISD::ATOMIC_LOAD_ADD_16: |
| 4564 | case ISD::ATOMIC_LOAD_SUB_16: |
| 4565 | case ISD::ATOMIC_LOAD_AND_16: |
| 4566 | case ISD::ATOMIC_LOAD_OR_16: |
| 4567 | case ISD::ATOMIC_LOAD_XOR_16: |
| 4568 | case ISD::ATOMIC_LOAD_NAND_16: |
| 4569 | case ISD::ATOMIC_LOAD_MIN_16: |
| 4570 | case ISD::ATOMIC_LOAD_MAX_16: |
| 4571 | case ISD::ATOMIC_LOAD_UMIN_16: |
| 4572 | case ISD::ATOMIC_LOAD_UMAX_16: |
| 4573 | case ISD::ATOMIC_SWAP_16: |
| 4574 | case ISD::ATOMIC_LOAD_ADD_32: |
| 4575 | case ISD::ATOMIC_LOAD_SUB_32: |
| 4576 | case ISD::ATOMIC_LOAD_AND_32: |
| 4577 | case ISD::ATOMIC_LOAD_OR_32: |
| 4578 | case ISD::ATOMIC_LOAD_XOR_32: |
| 4579 | case ISD::ATOMIC_LOAD_NAND_32: |
| 4580 | case ISD::ATOMIC_LOAD_MIN_32: |
| 4581 | case ISD::ATOMIC_LOAD_MAX_32: |
| 4582 | case ISD::ATOMIC_LOAD_UMIN_32: |
| 4583 | case ISD::ATOMIC_LOAD_UMAX_32: |
| 4584 | case ISD::ATOMIC_SWAP_32: |
| 4585 | case ISD::ATOMIC_LOAD_ADD_64: |
| 4586 | case ISD::ATOMIC_LOAD_SUB_64: |
| 4587 | case ISD::ATOMIC_LOAD_AND_64: |
| 4588 | case ISD::ATOMIC_LOAD_OR_64: |
| 4589 | case ISD::ATOMIC_LOAD_XOR_64: |
| 4590 | case ISD::ATOMIC_LOAD_NAND_64: |
| 4591 | case ISD::ATOMIC_LOAD_MIN_64: |
| 4592 | case ISD::ATOMIC_LOAD_MAX_64: |
| 4593 | case ISD::ATOMIC_LOAD_UMIN_64: |
| 4594 | case ISD::ATOMIC_LOAD_UMAX_64: |
| 4595 | case ISD::ATOMIC_SWAP_64: { |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 4596 | AtomicSDNode* AtomNode = cast<AtomicSDNode>(Node); |
Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 4597 | Tmp2 = PromoteOp(Node->getOperand(2)); |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 4598 | Result = DAG.getAtomic(Node->getOpcode(), AtomNode->getChain(), |
| 4599 | AtomNode->getBasePtr(), Tmp2, |
Dan Gohman | fd4418f | 2008-06-25 16:07:49 +0000 | [diff] [blame] | 4600 | AtomNode->getSrcValue(), |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 4601 | AtomNode->getAlignment()); |
Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 4602 | // Remember that we legalized the chain. |
| 4603 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1))); |
| 4604 | break; |
| 4605 | } |
| 4606 | |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4607 | case ISD::AND: |
| 4608 | case ISD::OR: |
| 4609 | case ISD::XOR: |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 4610 | case ISD::ADD: |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4611 | case ISD::SUB: |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 4612 | case ISD::MUL: |
| 4613 | // 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] | 4614 | // 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] | 4615 | // that too is okay if they are integer operations. |
| 4616 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4617 | Tmp2 = PromoteOp(Node->getOperand(1)); |
| 4618 | assert(Tmp1.getValueType() == NVT && Tmp2.getValueType() == NVT); |
| 4619 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 4620 | break; |
| 4621 | case ISD::FADD: |
| 4622 | case ISD::FSUB: |
| 4623 | case ISD::FMUL: |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 4624 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4625 | Tmp2 = PromoteOp(Node->getOperand(1)); |
| 4626 | assert(Tmp1.getValueType() == NVT && Tmp2.getValueType() == NVT); |
| 4627 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 4628 | |
| 4629 | // Floating point operations will give excess precision that we may not be |
| 4630 | // able to tolerate. If we DO allow excess precision, just leave it, |
| 4631 | // otherwise excise it. |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4632 | // FIXME: Why would we need to round FP ops more than integer ones? |
| 4633 | // 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] | 4634 | if (NoExcessFPPrecision) |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 4635 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 4636 | DAG.getValueType(VT)); |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 4637 | break; |
| 4638 | |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4639 | case ISD::SDIV: |
| 4640 | case ISD::SREM: |
| 4641 | // These operators require that their input be sign extended. |
| 4642 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4643 | Tmp2 = PromoteOp(Node->getOperand(1)); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4644 | if (NVT.isInteger()) { |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 4645 | Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp1, |
| 4646 | DAG.getValueType(VT)); |
| 4647 | Tmp2 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp2, |
| 4648 | DAG.getValueType(VT)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4649 | } |
| 4650 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 4651 | |
| 4652 | // Perform FP_ROUND: this is probably overly pessimistic. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4653 | if (NVT.isFloatingPoint() && NoExcessFPPrecision) |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 4654 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 4655 | DAG.getValueType(VT)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4656 | break; |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 4657 | case ISD::FDIV: |
| 4658 | case ISD::FREM: |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 4659 | case ISD::FCOPYSIGN: |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 4660 | // These operators require that their input be fp extended. |
Nate Begeman | ec57fd9 | 2006-05-09 18:20:51 +0000 | [diff] [blame] | 4661 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4662 | case Expand: assert(0 && "not implemented"); |
| 4663 | case Legal: Tmp1 = LegalizeOp(Node->getOperand(0)); break; |
| 4664 | case Promote: Tmp1 = PromoteOp(Node->getOperand(0)); break; |
Nate Begeman | ec57fd9 | 2006-05-09 18:20:51 +0000 | [diff] [blame] | 4665 | } |
| 4666 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4667 | case Expand: assert(0 && "not implemented"); |
| 4668 | case Legal: Tmp2 = LegalizeOp(Node->getOperand(1)); break; |
| 4669 | case Promote: Tmp2 = PromoteOp(Node->getOperand(1)); break; |
Nate Begeman | ec57fd9 | 2006-05-09 18:20:51 +0000 | [diff] [blame] | 4670 | } |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 4671 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 4672 | |
| 4673 | // Perform FP_ROUND: this is probably overly pessimistic. |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 4674 | if (NoExcessFPPrecision && Node->getOpcode() != ISD::FCOPYSIGN) |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 4675 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 4676 | DAG.getValueType(VT)); |
| 4677 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4678 | |
| 4679 | case ISD::UDIV: |
| 4680 | case ISD::UREM: |
| 4681 | // These operators require that their input be zero extended. |
| 4682 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4683 | Tmp2 = PromoteOp(Node->getOperand(1)); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4684 | assert(NVT.isInteger() && "Operators don't apply to FP!"); |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 4685 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, VT); |
| 4686 | Tmp2 = DAG.getZeroExtendInReg(Tmp2, VT); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4687 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 4688 | break; |
| 4689 | |
| 4690 | case ISD::SHL: |
| 4691 | Tmp1 = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4692 | Result = DAG.getNode(ISD::SHL, NVT, Tmp1, Node->getOperand(1)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4693 | break; |
| 4694 | case ISD::SRA: |
| 4695 | // The input value must be properly sign extended. |
| 4696 | Tmp1 = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 4697 | Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp1, |
| 4698 | DAG.getValueType(VT)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4699 | Result = DAG.getNode(ISD::SRA, NVT, Tmp1, Node->getOperand(1)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4700 | break; |
| 4701 | case ISD::SRL: |
| 4702 | // The input value must be properly zero extended. |
| 4703 | Tmp1 = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 4704 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, VT); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4705 | Result = DAG.getNode(ISD::SRL, NVT, Tmp1, Node->getOperand(1)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4706 | break; |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 4707 | |
| 4708 | case ISD::VAARG: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4709 | Tmp1 = Node->getOperand(0); // Get the chain. |
| 4710 | Tmp2 = Node->getOperand(1); // Get the pointer. |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 4711 | if (TLI.getOperationAction(ISD::VAARG, VT) == TargetLowering::Custom) { |
| 4712 | Tmp3 = DAG.getVAArg(VT, Tmp1, Tmp2, Node->getOperand(2)); |
Duncan Sands | 126d907 | 2008-07-04 11:47:58 +0000 | [diff] [blame] | 4713 | Result = TLI.LowerOperation(Tmp3, DAG); |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 4714 | } else { |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 4715 | const Value *V = cast<SrcValueSDNode>(Node->getOperand(2))->getValue(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4716 | SDValue VAList = DAG.getLoad(TLI.getPointerTy(), Tmp1, Tmp2, V, 0); |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 4717 | // Increment the pointer, VAList, to the next vaarg |
| 4718 | Tmp3 = DAG.getNode(ISD::ADD, TLI.getPointerTy(), VAList, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4719 | DAG.getConstant(VT.getSizeInBits()/8, |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 4720 | TLI.getPointerTy())); |
| 4721 | // Store the incremented VAList to the legalized pointer |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 4722 | Tmp3 = DAG.getStore(VAList.getValue(1), Tmp3, Tmp2, V, 0); |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 4723 | // Load the actual argument out of the pointer VAList |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 4724 | Result = DAG.getExtLoad(ISD::EXTLOAD, NVT, Tmp3, VAList, NULL, 0, VT); |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 4725 | } |
| 4726 | // Remember that we legalized the chain. |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4727 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1))); |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 4728 | break; |
| 4729 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 4730 | case ISD::LOAD: { |
| 4731 | LoadSDNode *LD = cast<LoadSDNode>(Node); |
Evan Cheng | 62f2a3c | 2006-10-10 07:51:21 +0000 | [diff] [blame] | 4732 | ISD::LoadExtType ExtType = ISD::isNON_EXTLoad(Node) |
| 4733 | ? ISD::EXTLOAD : LD->getExtensionType(); |
| 4734 | Result = DAG.getExtLoad(ExtType, NVT, |
| 4735 | LD->getChain(), LD->getBasePtr(), |
Chris Lattner | 55b5708 | 2006-10-10 18:54:19 +0000 | [diff] [blame] | 4736 | LD->getSrcValue(), LD->getSrcValueOffset(), |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 4737 | LD->getMemoryVT(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 4738 | LD->isVolatile(), |
| 4739 | LD->getAlignment()); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4740 | // Remember that we legalized the chain. |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4741 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1))); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4742 | break; |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 4743 | } |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 4744 | case ISD::SELECT: { |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4745 | Tmp2 = PromoteOp(Node->getOperand(1)); // Legalize the op0 |
| 4746 | Tmp3 = PromoteOp(Node->getOperand(2)); // Legalize the op1 |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 4747 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4748 | MVT VT2 = Tmp2.getValueType(); |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 4749 | assert(VT2 == Tmp3.getValueType() |
Scott Michel | ba12f57 | 2008-06-03 19:13:20 +0000 | [diff] [blame] | 4750 | && "PromoteOp SELECT: Operands 2 and 3 ValueTypes don't match"); |
| 4751 | // Ensure that the resulting node is at least the same size as the operands' |
| 4752 | // value types, because we cannot assume that TLI.getSetCCValueType() is |
| 4753 | // constant. |
| 4754 | Result = DAG.getNode(ISD::SELECT, VT2, Node->getOperand(0), Tmp2, Tmp3); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4755 | break; |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 4756 | } |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 4757 | case ISD::SELECT_CC: |
| 4758 | Tmp2 = PromoteOp(Node->getOperand(2)); // True |
| 4759 | Tmp3 = PromoteOp(Node->getOperand(3)); // False |
| 4760 | Result = DAG.getNode(ISD::SELECT_CC, NVT, Node->getOperand(0), |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4761 | Node->getOperand(1), Tmp2, Tmp3, Node->getOperand(4)); |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 4762 | break; |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 4763 | case ISD::BSWAP: |
| 4764 | Tmp1 = Node->getOperand(0); |
| 4765 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Tmp1); |
| 4766 | Tmp1 = DAG.getNode(ISD::BSWAP, NVT, Tmp1); |
| 4767 | Result = DAG.getNode(ISD::SRL, NVT, Tmp1, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4768 | DAG.getConstant(NVT.getSizeInBits() - |
| 4769 | VT.getSizeInBits(), |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 4770 | TLI.getShiftAmountTy())); |
| 4771 | break; |
Andrew Lenharth | fecf095 | 2005-05-04 19:11:05 +0000 | [diff] [blame] | 4772 | case ISD::CTPOP: |
| 4773 | case ISD::CTTZ: |
| 4774 | case ISD::CTLZ: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4775 | // Zero extend the argument |
| 4776 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Node->getOperand(0)); |
Andrew Lenharth | fecf095 | 2005-05-04 19:11:05 +0000 | [diff] [blame] | 4777 | // Perform the larger operation, then subtract if needed. |
| 4778 | Tmp1 = DAG.getNode(Node->getOpcode(), NVT, Tmp1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4779 | switch(Node->getOpcode()) { |
Andrew Lenharth | fecf095 | 2005-05-04 19:11:05 +0000 | [diff] [blame] | 4780 | case ISD::CTPOP: |
| 4781 | Result = Tmp1; |
| 4782 | break; |
| 4783 | case ISD::CTTZ: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4784 | // if Tmp1 == sizeinbits(NVT) then Tmp1 = sizeinbits(Old VT) |
Scott Michel | 5b8f82e | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 4785 | Tmp2 = DAG.getSetCC(TLI.getSetCCResultType(Tmp1), Tmp1, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4786 | DAG.getConstant(NVT.getSizeInBits(), NVT), |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 4787 | ISD::SETEQ); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 4788 | Result = DAG.getNode(ISD::SELECT, NVT, Tmp2, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4789 | DAG.getConstant(VT.getSizeInBits(), NVT), Tmp1); |
Andrew Lenharth | fecf095 | 2005-05-04 19:11:05 +0000 | [diff] [blame] | 4790 | break; |
| 4791 | case ISD::CTLZ: |
| 4792 | //Tmp1 = Tmp1 - (sizeinbits(NVT) - sizeinbits(Old VT)) |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 4793 | Result = DAG.getNode(ISD::SUB, NVT, Tmp1, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4794 | DAG.getConstant(NVT.getSizeInBits() - |
| 4795 | VT.getSizeInBits(), NVT)); |
Andrew Lenharth | fecf095 | 2005-05-04 19:11:05 +0000 | [diff] [blame] | 4796 | break; |
| 4797 | } |
| 4798 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4799 | case ISD::EXTRACT_SUBVECTOR: |
| 4800 | Result = PromoteOp(ExpandEXTRACT_SUBVECTOR(Op)); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 4801 | break; |
Chris Lattner | 4aab2f4 | 2006-04-02 05:06:04 +0000 | [diff] [blame] | 4802 | case ISD::EXTRACT_VECTOR_ELT: |
| 4803 | Result = PromoteOp(ExpandEXTRACT_VECTOR_ELT(Op)); |
| 4804 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4805 | } |
| 4806 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 4807 | assert(Result.getNode() && "Didn't set a result!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4808 | |
| 4809 | // Make sure the result is itself legal. |
| 4810 | Result = LegalizeOp(Result); |
| 4811 | |
| 4812 | // Remember that we promoted this! |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4813 | AddPromotedOperand(Op, Result); |
| 4814 | return Result; |
| 4815 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 4816 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4817 | /// ExpandEXTRACT_VECTOR_ELT - Expand an EXTRACT_VECTOR_ELT operation into |
| 4818 | /// a legal EXTRACT_VECTOR_ELT operation, scalar code, or memory traffic, |
| 4819 | /// based on the vector type. The return type of this matches the element type |
| 4820 | /// of the vector, which may not be legal for the target. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4821 | SDValue SelectionDAGLegalize::ExpandEXTRACT_VECTOR_ELT(SDValue Op) { |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4822 | // We know that operand #0 is the Vec vector. If the index is a constant |
| 4823 | // or if the invec is a supported hardware type, we can use it. Otherwise, |
| 4824 | // lower to a store then an indexed load. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4825 | SDValue Vec = Op.getOperand(0); |
| 4826 | SDValue Idx = Op.getOperand(1); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4827 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4828 | MVT TVT = Vec.getValueType(); |
| 4829 | unsigned NumElems = TVT.getVectorNumElements(); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4830 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4831 | switch (TLI.getOperationAction(ISD::EXTRACT_VECTOR_ELT, TVT)) { |
| 4832 | default: assert(0 && "This action is not supported yet!"); |
| 4833 | case TargetLowering::Custom: { |
| 4834 | Vec = LegalizeOp(Vec); |
| 4835 | Op = DAG.UpdateNodeOperands(Op, Vec, Idx); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4836 | SDValue Tmp3 = TLI.LowerOperation(Op, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 4837 | if (Tmp3.getNode()) |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4838 | return Tmp3; |
| 4839 | break; |
| 4840 | } |
| 4841 | case TargetLowering::Legal: |
| 4842 | if (isTypeLegal(TVT)) { |
| 4843 | Vec = LegalizeOp(Vec); |
| 4844 | Op = DAG.UpdateNodeOperands(Op, Vec, Idx); |
Christopher Lamb | 844228a | 2007-07-26 03:33:13 +0000 | [diff] [blame] | 4845 | return Op; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4846 | } |
| 4847 | break; |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 4848 | case TargetLowering::Promote: |
| 4849 | assert(TVT.isVector() && "not vector type"); |
| 4850 | // fall thru to expand since vectors are by default are promote |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4851 | case TargetLowering::Expand: |
| 4852 | break; |
| 4853 | } |
| 4854 | |
| 4855 | if (NumElems == 1) { |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4856 | // This must be an access of the only element. Return it. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4857 | Op = ScalarizeVectorOp(Vec); |
| 4858 | } else if (!TLI.isTypeLegal(TVT) && isa<ConstantSDNode>(Idx)) { |
Nate Begeman | 55030dc | 2008-01-29 02:24:00 +0000 | [diff] [blame] | 4859 | unsigned NumLoElts = 1 << Log2_32(NumElems-1); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4860 | ConstantSDNode *CIdx = cast<ConstantSDNode>(Idx); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4861 | SDValue Lo, Hi; |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4862 | SplitVectorOp(Vec, Lo, Hi); |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 4863 | if (CIdx->getZExtValue() < NumLoElts) { |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4864 | Vec = Lo; |
| 4865 | } else { |
| 4866 | Vec = Hi; |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 4867 | Idx = DAG.getConstant(CIdx->getZExtValue() - NumLoElts, |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4868 | Idx.getValueType()); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4869 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4870 | |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4871 | // It's now an extract from the appropriate high or low part. Recurse. |
| 4872 | Op = DAG.UpdateNodeOperands(Op, Vec, Idx); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4873 | Op = ExpandEXTRACT_VECTOR_ELT(Op); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4874 | } else { |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4875 | // Store the value to a temporary stack slot, then LOAD the scalar |
| 4876 | // element back out. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4877 | SDValue StackPtr = DAG.CreateStackTemporary(Vec.getValueType()); |
| 4878 | SDValue Ch = DAG.getStore(DAG.getEntryNode(), Vec, StackPtr, NULL, 0); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4879 | |
| 4880 | // Add the offset to the index. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4881 | unsigned EltSize = Op.getValueType().getSizeInBits()/8; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4882 | Idx = DAG.getNode(ISD::MUL, Idx.getValueType(), Idx, |
| 4883 | DAG.getConstant(EltSize, Idx.getValueType())); |
Bill Wendling | 90bfc2d | 2007-10-18 08:32:37 +0000 | [diff] [blame] | 4884 | |
Duncan Sands | 8e4eb09 | 2008-06-08 20:54:56 +0000 | [diff] [blame] | 4885 | if (Idx.getValueType().bitsGT(TLI.getPointerTy())) |
Chris Lattner | f185e67 | 2007-10-19 16:47:35 +0000 | [diff] [blame] | 4886 | Idx = DAG.getNode(ISD::TRUNCATE, TLI.getPointerTy(), Idx); |
Bill Wendling | 90bfc2d | 2007-10-18 08:32:37 +0000 | [diff] [blame] | 4887 | else |
Chris Lattner | f185e67 | 2007-10-19 16:47:35 +0000 | [diff] [blame] | 4888 | Idx = DAG.getNode(ISD::ZERO_EXTEND, TLI.getPointerTy(), Idx); |
Bill Wendling | 90bfc2d | 2007-10-18 08:32:37 +0000 | [diff] [blame] | 4889 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4890 | StackPtr = DAG.getNode(ISD::ADD, Idx.getValueType(), Idx, StackPtr); |
| 4891 | |
| 4892 | Op = DAG.getLoad(Op.getValueType(), Ch, StackPtr, NULL, 0); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4893 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4894 | return Op; |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4895 | } |
| 4896 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4897 | /// ExpandEXTRACT_SUBVECTOR - Expand a EXTRACT_SUBVECTOR operation. For now |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 4898 | /// we assume the operation can be split if it is not already legal. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4899 | SDValue SelectionDAGLegalize::ExpandEXTRACT_SUBVECTOR(SDValue Op) { |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 4900 | // We know that operand #0 is the Vec vector. For now we assume the index |
| 4901 | // is a constant and that the extracted result is a supported hardware type. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4902 | SDValue Vec = Op.getOperand(0); |
| 4903 | SDValue Idx = LegalizeOp(Op.getOperand(1)); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 4904 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4905 | unsigned NumElems = Vec.getValueType().getVectorNumElements(); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 4906 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4907 | if (NumElems == Op.getValueType().getVectorNumElements()) { |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 4908 | // This must be an access of the desired vector length. Return it. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4909 | return Vec; |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 4910 | } |
| 4911 | |
| 4912 | ConstantSDNode *CIdx = cast<ConstantSDNode>(Idx); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4913 | SDValue Lo, Hi; |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 4914 | SplitVectorOp(Vec, Lo, Hi); |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 4915 | if (CIdx->getZExtValue() < NumElems/2) { |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 4916 | Vec = Lo; |
| 4917 | } else { |
| 4918 | Vec = Hi; |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 4919 | Idx = DAG.getConstant(CIdx->getZExtValue() - NumElems/2, |
| 4920 | Idx.getValueType()); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 4921 | } |
| 4922 | |
| 4923 | // It's now an extract from the appropriate high or low part. Recurse. |
| 4924 | Op = DAG.UpdateNodeOperands(Op, Vec, Idx); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4925 | return ExpandEXTRACT_SUBVECTOR(Op); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 4926 | } |
| 4927 | |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 4928 | /// LegalizeSetCCOperands - Attempts to create a legal LHS and RHS for a SETCC |
| 4929 | /// with condition CC on the current target. This usually involves legalizing |
| 4930 | /// or promoting the arguments. In the case where LHS and RHS must be expanded, |
| 4931 | /// there may be no choice but to create a new SetCC node to represent the |
| 4932 | /// legalized value of setcc lhs, rhs. In this case, the value is returned in |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4933 | /// LHS, and the SDValue returned in RHS has a nil SDNode value. |
| 4934 | void SelectionDAGLegalize::LegalizeSetCCOperands(SDValue &LHS, |
| 4935 | SDValue &RHS, |
| 4936 | SDValue &CC) { |
| 4937 | SDValue Tmp1, Tmp2, Tmp3, Result; |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 4938 | |
| 4939 | switch (getTypeAction(LHS.getValueType())) { |
| 4940 | case Legal: |
| 4941 | Tmp1 = LegalizeOp(LHS); // LHS |
| 4942 | Tmp2 = LegalizeOp(RHS); // RHS |
| 4943 | break; |
| 4944 | case Promote: |
| 4945 | Tmp1 = PromoteOp(LHS); // LHS |
| 4946 | Tmp2 = PromoteOp(RHS); // RHS |
| 4947 | |
| 4948 | // If this is an FP compare, the operands have already been extended. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4949 | if (LHS.getValueType().isInteger()) { |
| 4950 | MVT VT = LHS.getValueType(); |
| 4951 | MVT NVT = TLI.getTypeToTransformTo(VT); |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 4952 | |
| 4953 | // Otherwise, we have to insert explicit sign or zero extends. Note |
| 4954 | // that we could insert sign extends for ALL conditions, but zero extend |
| 4955 | // is cheaper on many machines (an AND instead of two shifts), so prefer |
| 4956 | // it. |
| 4957 | switch (cast<CondCodeSDNode>(CC)->get()) { |
| 4958 | default: assert(0 && "Unknown integer comparison!"); |
| 4959 | case ISD::SETEQ: |
| 4960 | case ISD::SETNE: |
| 4961 | case ISD::SETUGE: |
| 4962 | case ISD::SETUGT: |
| 4963 | case ISD::SETULE: |
| 4964 | case ISD::SETULT: |
| 4965 | // ALL of these operations will work if we either sign or zero extend |
| 4966 | // the operands (including the unsigned comparisons!). Zero extend is |
| 4967 | // usually a simpler/cheaper operation, so prefer it. |
| 4968 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, VT); |
| 4969 | Tmp2 = DAG.getZeroExtendInReg(Tmp2, VT); |
| 4970 | break; |
| 4971 | case ISD::SETGE: |
| 4972 | case ISD::SETGT: |
| 4973 | case ISD::SETLT: |
| 4974 | case ISD::SETLE: |
| 4975 | Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp1, |
| 4976 | DAG.getValueType(VT)); |
| 4977 | Tmp2 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp2, |
| 4978 | DAG.getValueType(VT)); |
Evan Cheng | efa5339 | 2008-10-13 18:46:18 +0000 | [diff] [blame] | 4979 | Tmp1 = LegalizeOp(Tmp1); // Relegalize new nodes. |
| 4980 | Tmp2 = LegalizeOp(Tmp2); // Relegalize new nodes. |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 4981 | break; |
| 4982 | } |
| 4983 | } |
| 4984 | break; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4985 | case Expand: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4986 | MVT VT = LHS.getValueType(); |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4987 | if (VT == MVT::f32 || VT == MVT::f64) { |
| 4988 | // Expand into one or more soft-fp libcall(s). |
Evan Cheng | 6518c6e | 2008-07-01 21:35:46 +0000 | [diff] [blame] | 4989 | RTLIB::Libcall LC1 = RTLIB::UNKNOWN_LIBCALL, LC2 = RTLIB::UNKNOWN_LIBCALL; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4990 | switch (cast<CondCodeSDNode>(CC)->get()) { |
| 4991 | case ISD::SETEQ: |
| 4992 | case ISD::SETOEQ: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4993 | LC1 = (VT == MVT::f32) ? RTLIB::OEQ_F32 : RTLIB::OEQ_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4994 | break; |
| 4995 | case ISD::SETNE: |
| 4996 | case ISD::SETUNE: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4997 | LC1 = (VT == MVT::f32) ? RTLIB::UNE_F32 : RTLIB::UNE_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4998 | break; |
| 4999 | case ISD::SETGE: |
| 5000 | case ISD::SETOGE: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5001 | LC1 = (VT == MVT::f32) ? RTLIB::OGE_F32 : RTLIB::OGE_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5002 | break; |
| 5003 | case ISD::SETLT: |
| 5004 | case ISD::SETOLT: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5005 | LC1 = (VT == MVT::f32) ? RTLIB::OLT_F32 : RTLIB::OLT_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5006 | break; |
| 5007 | case ISD::SETLE: |
| 5008 | case ISD::SETOLE: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5009 | LC1 = (VT == MVT::f32) ? RTLIB::OLE_F32 : RTLIB::OLE_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5010 | break; |
| 5011 | case ISD::SETGT: |
| 5012 | case ISD::SETOGT: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5013 | LC1 = (VT == MVT::f32) ? RTLIB::OGT_F32 : RTLIB::OGT_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5014 | break; |
| 5015 | case ISD::SETUO: |
Evan Cheng | d385fd6 | 2007-01-31 09:29:11 +0000 | [diff] [blame] | 5016 | LC1 = (VT == MVT::f32) ? RTLIB::UO_F32 : RTLIB::UO_F64; |
| 5017 | break; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5018 | case ISD::SETO: |
Evan Cheng | 5efdecc | 2007-02-03 00:43:46 +0000 | [diff] [blame] | 5019 | LC1 = (VT == MVT::f32) ? RTLIB::O_F32 : RTLIB::O_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5020 | break; |
| 5021 | default: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5022 | LC1 = (VT == MVT::f32) ? RTLIB::UO_F32 : RTLIB::UO_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5023 | switch (cast<CondCodeSDNode>(CC)->get()) { |
| 5024 | case ISD::SETONE: |
| 5025 | // SETONE = SETOLT | SETOGT |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5026 | LC1 = (VT == MVT::f32) ? RTLIB::OLT_F32 : RTLIB::OLT_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5027 | // Fallthrough |
| 5028 | case ISD::SETUGT: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5029 | LC2 = (VT == MVT::f32) ? RTLIB::OGT_F32 : RTLIB::OGT_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5030 | break; |
| 5031 | case ISD::SETUGE: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5032 | LC2 = (VT == MVT::f32) ? RTLIB::OGE_F32 : RTLIB::OGE_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5033 | break; |
| 5034 | case ISD::SETULT: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5035 | LC2 = (VT == MVT::f32) ? RTLIB::OLT_F32 : RTLIB::OLT_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5036 | break; |
| 5037 | case ISD::SETULE: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5038 | LC2 = (VT == MVT::f32) ? RTLIB::OLE_F32 : RTLIB::OLE_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5039 | break; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5040 | case ISD::SETUEQ: |
| 5041 | LC2 = (VT == MVT::f32) ? RTLIB::OEQ_F32 : RTLIB::OEQ_F64; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5042 | break; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5043 | default: assert(0 && "Unsupported FP setcc!"); |
| 5044 | } |
| 5045 | } |
Duncan Sands | f951620 | 2008-06-30 10:19:09 +0000 | [diff] [blame] | 5046 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5047 | SDValue Dummy; |
| 5048 | SDValue Ops[2] = { LHS, RHS }; |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5049 | Tmp1 = ExpandLibCall(LC1, DAG.getMergeValues(Ops, 2).getNode(), |
Reid Spencer | b47b25c | 2007-01-03 04:22:32 +0000 | [diff] [blame] | 5050 | false /*sign irrelevant*/, Dummy); |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5051 | Tmp2 = DAG.getConstant(0, MVT::i32); |
Evan Cheng | d385fd6 | 2007-01-31 09:29:11 +0000 | [diff] [blame] | 5052 | CC = DAG.getCondCode(TLI.getCmpLibcallCC(LC1)); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5053 | if (LC2 != RTLIB::UNKNOWN_LIBCALL) { |
Scott Michel | 5b8f82e | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 5054 | Tmp1 = DAG.getNode(ISD::SETCC, TLI.getSetCCResultType(Tmp1), Tmp1, Tmp2, |
Nate Begeman | 5922f56 | 2008-03-14 00:53:31 +0000 | [diff] [blame] | 5055 | CC); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5056 | LHS = ExpandLibCall(LC2, DAG.getMergeValues(Ops, 2).getNode(), |
Reid Spencer | b47b25c | 2007-01-03 04:22:32 +0000 | [diff] [blame] | 5057 | false /*sign irrelevant*/, Dummy); |
Scott Michel | 5b8f82e | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 5058 | Tmp2 = DAG.getNode(ISD::SETCC, TLI.getSetCCResultType(LHS), LHS, Tmp2, |
Evan Cheng | d385fd6 | 2007-01-31 09:29:11 +0000 | [diff] [blame] | 5059 | DAG.getCondCode(TLI.getCmpLibcallCC(LC2))); |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5060 | Tmp1 = DAG.getNode(ISD::OR, Tmp1.getValueType(), Tmp1, Tmp2); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5061 | Tmp2 = SDValue(); |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5062 | } |
Evan Cheng | 21cacc4 | 2008-07-07 07:18:09 +0000 | [diff] [blame] | 5063 | LHS = LegalizeOp(Tmp1); |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5064 | RHS = Tmp2; |
| 5065 | return; |
| 5066 | } |
| 5067 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5068 | SDValue LHSLo, LHSHi, RHSLo, RHSHi; |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 5069 | ExpandOp(LHS, LHSLo, LHSHi); |
Dale Johannesen | 638ccd5 | 2007-10-06 01:24:11 +0000 | [diff] [blame] | 5070 | ExpandOp(RHS, RHSLo, RHSHi); |
| 5071 | ISD::CondCode CCCode = cast<CondCodeSDNode>(CC)->get(); |
| 5072 | |
| 5073 | if (VT==MVT::ppcf128) { |
| 5074 | // FIXME: This generated code sucks. We want to generate |
Dale Johannesen | e2f2083 | 2008-09-12 00:30:56 +0000 | [diff] [blame] | 5075 | // FCMPU crN, hi1, hi2 |
Dale Johannesen | 638ccd5 | 2007-10-06 01:24:11 +0000 | [diff] [blame] | 5076 | // BNE crN, L: |
Dale Johannesen | e2f2083 | 2008-09-12 00:30:56 +0000 | [diff] [blame] | 5077 | // FCMPU crN, lo1, lo2 |
Dale Johannesen | 638ccd5 | 2007-10-06 01:24:11 +0000 | [diff] [blame] | 5078 | // The following can be improved, but not that much. |
Dale Johannesen | e2f2083 | 2008-09-12 00:30:56 +0000 | [diff] [blame] | 5079 | Tmp1 = DAG.getSetCC(TLI.getSetCCResultType(LHSHi), LHSHi, RHSHi, |
| 5080 | ISD::SETOEQ); |
Scott Michel | 5b8f82e | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 5081 | Tmp2 = DAG.getSetCC(TLI.getSetCCResultType(LHSLo), LHSLo, RHSLo, CCCode); |
Dale Johannesen | 638ccd5 | 2007-10-06 01:24:11 +0000 | [diff] [blame] | 5082 | Tmp3 = DAG.getNode(ISD::AND, Tmp1.getValueType(), Tmp1, Tmp2); |
Dale Johannesen | e2f2083 | 2008-09-12 00:30:56 +0000 | [diff] [blame] | 5083 | Tmp1 = DAG.getSetCC(TLI.getSetCCResultType(LHSHi), LHSHi, RHSHi, |
| 5084 | ISD::SETUNE); |
Scott Michel | 5b8f82e | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 5085 | Tmp2 = DAG.getSetCC(TLI.getSetCCResultType(LHSHi), LHSHi, RHSHi, CCCode); |
Dale Johannesen | 638ccd5 | 2007-10-06 01:24:11 +0000 | [diff] [blame] | 5086 | Tmp1 = DAG.getNode(ISD::AND, Tmp1.getValueType(), Tmp1, Tmp2); |
| 5087 | Tmp1 = DAG.getNode(ISD::OR, Tmp1.getValueType(), Tmp1, Tmp3); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5088 | Tmp2 = SDValue(); |
Dale Johannesen | 638ccd5 | 2007-10-06 01:24:11 +0000 | [diff] [blame] | 5089 | break; |
| 5090 | } |
| 5091 | |
| 5092 | switch (CCCode) { |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 5093 | case ISD::SETEQ: |
| 5094 | case ISD::SETNE: |
| 5095 | if (RHSLo == RHSHi) |
| 5096 | if (ConstantSDNode *RHSCST = dyn_cast<ConstantSDNode>(RHSLo)) |
| 5097 | if (RHSCST->isAllOnesValue()) { |
| 5098 | // Comparison to -1. |
| 5099 | Tmp1 = DAG.getNode(ISD::AND, LHSLo.getValueType(), LHSLo, LHSHi); |
| 5100 | Tmp2 = RHSLo; |
| 5101 | break; |
| 5102 | } |
| 5103 | |
| 5104 | Tmp1 = DAG.getNode(ISD::XOR, LHSLo.getValueType(), LHSLo, RHSLo); |
| 5105 | Tmp2 = DAG.getNode(ISD::XOR, LHSLo.getValueType(), LHSHi, RHSHi); |
| 5106 | Tmp1 = DAG.getNode(ISD::OR, Tmp1.getValueType(), Tmp1, Tmp2); |
| 5107 | Tmp2 = DAG.getConstant(0, Tmp1.getValueType()); |
| 5108 | break; |
| 5109 | default: |
| 5110 | // If this is a comparison of the sign bit, just look at the top part. |
| 5111 | // X > -1, x < 0 |
| 5112 | if (ConstantSDNode *CST = dyn_cast<ConstantSDNode>(RHS)) |
| 5113 | if ((cast<CondCodeSDNode>(CC)->get() == ISD::SETLT && |
Dan Gohman | 002e5d0 | 2008-03-13 22:13:53 +0000 | [diff] [blame] | 5114 | CST->isNullValue()) || // X < 0 |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 5115 | (cast<CondCodeSDNode>(CC)->get() == ISD::SETGT && |
| 5116 | CST->isAllOnesValue())) { // X > -1 |
| 5117 | Tmp1 = LHSHi; |
| 5118 | Tmp2 = RHSHi; |
| 5119 | break; |
| 5120 | } |
| 5121 | |
| 5122 | // FIXME: This generated code sucks. |
| 5123 | ISD::CondCode LowCC; |
Evan Cheng | 2e67781 | 2007-02-08 22:16:19 +0000 | [diff] [blame] | 5124 | switch (CCCode) { |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 5125 | default: assert(0 && "Unknown integer setcc!"); |
| 5126 | case ISD::SETLT: |
| 5127 | case ISD::SETULT: LowCC = ISD::SETULT; break; |
| 5128 | case ISD::SETGT: |
| 5129 | case ISD::SETUGT: LowCC = ISD::SETUGT; break; |
| 5130 | case ISD::SETLE: |
| 5131 | case ISD::SETULE: LowCC = ISD::SETULE; break; |
| 5132 | case ISD::SETGE: |
| 5133 | case ISD::SETUGE: LowCC = ISD::SETUGE; break; |
| 5134 | } |
| 5135 | |
| 5136 | // Tmp1 = lo(op1) < lo(op2) // Always unsigned comparison |
| 5137 | // Tmp2 = hi(op1) < hi(op2) // Signedness depends on operands |
| 5138 | // dest = hi(op1) == hi(op2) ? Tmp1 : Tmp2; |
| 5139 | |
| 5140 | // NOTE: on targets without efficient SELECT of bools, we can always use |
| 5141 | // this identity: (B1 ? B2 : B3) --> (B1 & B2)|(!B1&B3) |
Evan Cheng | 2e67781 | 2007-02-08 22:16:19 +0000 | [diff] [blame] | 5142 | TargetLowering::DAGCombinerInfo DagCombineInfo(DAG, false, true, NULL); |
Scott Michel | 5b8f82e | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 5143 | Tmp1 = TLI.SimplifySetCC(TLI.getSetCCResultType(LHSLo), LHSLo, RHSLo, |
Nate Begeman | 5922f56 | 2008-03-14 00:53:31 +0000 | [diff] [blame] | 5144 | LowCC, false, DagCombineInfo); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5145 | if (!Tmp1.getNode()) |
Scott Michel | 5b8f82e | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 5146 | Tmp1 = DAG.getSetCC(TLI.getSetCCResultType(LHSLo), LHSLo, RHSLo, LowCC); |
| 5147 | Tmp2 = TLI.SimplifySetCC(TLI.getSetCCResultType(LHSHi), LHSHi, RHSHi, |
Evan Cheng | 2e67781 | 2007-02-08 22:16:19 +0000 | [diff] [blame] | 5148 | CCCode, false, DagCombineInfo); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5149 | if (!Tmp2.getNode()) |
Scott Michel | 5b8f82e | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 5150 | Tmp2 = DAG.getNode(ISD::SETCC, TLI.getSetCCResultType(LHSHi), LHSHi, |
Nate Begeman | 5922f56 | 2008-03-14 00:53:31 +0000 | [diff] [blame] | 5151 | RHSHi,CC); |
Evan Cheng | 2e67781 | 2007-02-08 22:16:19 +0000 | [diff] [blame] | 5152 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5153 | ConstantSDNode *Tmp1C = dyn_cast<ConstantSDNode>(Tmp1.getNode()); |
| 5154 | ConstantSDNode *Tmp2C = dyn_cast<ConstantSDNode>(Tmp2.getNode()); |
Dan Gohman | 002e5d0 | 2008-03-13 22:13:53 +0000 | [diff] [blame] | 5155 | if ((Tmp1C && Tmp1C->isNullValue()) || |
| 5156 | (Tmp2C && Tmp2C->isNullValue() && |
Evan Cheng | 2e67781 | 2007-02-08 22:16:19 +0000 | [diff] [blame] | 5157 | (CCCode == ISD::SETLE || CCCode == ISD::SETGE || |
| 5158 | CCCode == ISD::SETUGE || CCCode == ISD::SETULE)) || |
Dan Gohman | 002e5d0 | 2008-03-13 22:13:53 +0000 | [diff] [blame] | 5159 | (Tmp2C && Tmp2C->getAPIntValue() == 1 && |
Evan Cheng | 2e67781 | 2007-02-08 22:16:19 +0000 | [diff] [blame] | 5160 | (CCCode == ISD::SETLT || CCCode == ISD::SETGT || |
| 5161 | CCCode == ISD::SETUGT || CCCode == ISD::SETULT))) { |
| 5162 | // low part is known false, returns high part. |
| 5163 | // For LE / GE, if high part is known false, ignore the low part. |
| 5164 | // For LT / GT, if high part is known true, ignore the low part. |
| 5165 | Tmp1 = Tmp2; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5166 | Tmp2 = SDValue(); |
Evan Cheng | 2e67781 | 2007-02-08 22:16:19 +0000 | [diff] [blame] | 5167 | } else { |
Scott Michel | 5b8f82e | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 5168 | Result = TLI.SimplifySetCC(TLI.getSetCCResultType(LHSHi), LHSHi, RHSHi, |
Evan Cheng | 2e67781 | 2007-02-08 22:16:19 +0000 | [diff] [blame] | 5169 | ISD::SETEQ, false, DagCombineInfo); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5170 | if (!Result.getNode()) |
Scott Michel | 5b8f82e | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 5171 | Result=DAG.getSetCC(TLI.getSetCCResultType(LHSHi), LHSHi, RHSHi, |
Nate Begeman | 5922f56 | 2008-03-14 00:53:31 +0000 | [diff] [blame] | 5172 | ISD::SETEQ); |
Evan Cheng | 2e67781 | 2007-02-08 22:16:19 +0000 | [diff] [blame] | 5173 | Result = LegalizeOp(DAG.getNode(ISD::SELECT, Tmp1.getValueType(), |
| 5174 | Result, Tmp1, Tmp2)); |
| 5175 | Tmp1 = Result; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5176 | Tmp2 = SDValue(); |
Evan Cheng | 2e67781 | 2007-02-08 22:16:19 +0000 | [diff] [blame] | 5177 | } |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 5178 | } |
| 5179 | } |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5180 | } |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 5181 | LHS = Tmp1; |
| 5182 | RHS = Tmp2; |
| 5183 | } |
| 5184 | |
Evan Cheng | 7f04268 | 2008-10-15 02:05:31 +0000 | [diff] [blame] | 5185 | /// LegalizeSetCCCondCode - Legalize a SETCC with given LHS and RHS and |
| 5186 | /// condition code CC on the current target. This routine assumes LHS and rHS |
| 5187 | /// have already been legalized by LegalizeSetCCOperands. It expands SETCC with |
| 5188 | /// illegal condition code into AND / OR of multiple SETCC values. |
| 5189 | void SelectionDAGLegalize::LegalizeSetCCCondCode(MVT VT, |
| 5190 | SDValue &LHS, SDValue &RHS, |
| 5191 | SDValue &CC) { |
| 5192 | MVT OpVT = LHS.getValueType(); |
| 5193 | ISD::CondCode CCCode = cast<CondCodeSDNode>(CC)->get(); |
| 5194 | switch (TLI.getCondCodeAction(CCCode, OpVT)) { |
| 5195 | default: assert(0 && "Unknown condition code action!"); |
| 5196 | case TargetLowering::Legal: |
| 5197 | // Nothing to do. |
| 5198 | break; |
| 5199 | case TargetLowering::Expand: { |
| 5200 | ISD::CondCode CC1 = ISD::SETCC_INVALID, CC2 = ISD::SETCC_INVALID; |
| 5201 | unsigned Opc = 0; |
| 5202 | switch (CCCode) { |
| 5203 | default: assert(0 && "Don't know how to expand this condition!"); abort(); |
Dan Gohman | e7d238e | 2008-10-21 03:12:54 +0000 | [diff] [blame] | 5204 | case ISD::SETOEQ: CC1 = ISD::SETEQ; CC2 = ISD::SETO; Opc = ISD::AND; break; |
| 5205 | case ISD::SETOGT: CC1 = ISD::SETGT; CC2 = ISD::SETO; Opc = ISD::AND; break; |
| 5206 | case ISD::SETOGE: CC1 = ISD::SETGE; CC2 = ISD::SETO; Opc = ISD::AND; break; |
| 5207 | case ISD::SETOLT: CC1 = ISD::SETLT; CC2 = ISD::SETO; Opc = ISD::AND; break; |
| 5208 | case ISD::SETOLE: CC1 = ISD::SETLE; CC2 = ISD::SETO; Opc = ISD::AND; break; |
| 5209 | case ISD::SETONE: CC1 = ISD::SETNE; CC2 = ISD::SETO; Opc = ISD::AND; break; |
| 5210 | case ISD::SETUEQ: CC1 = ISD::SETEQ; CC2 = ISD::SETUO; Opc = ISD::OR; break; |
| 5211 | case ISD::SETUGT: CC1 = ISD::SETGT; CC2 = ISD::SETUO; Opc = ISD::OR; break; |
| 5212 | case ISD::SETUGE: CC1 = ISD::SETGE; CC2 = ISD::SETUO; Opc = ISD::OR; break; |
| 5213 | case ISD::SETULT: CC1 = ISD::SETLT; CC2 = ISD::SETUO; Opc = ISD::OR; break; |
| 5214 | case ISD::SETULE: CC1 = ISD::SETLE; CC2 = ISD::SETUO; Opc = ISD::OR; break; |
| 5215 | case ISD::SETUNE: CC1 = ISD::SETNE; CC2 = ISD::SETUO; Opc = ISD::OR; break; |
Evan Cheng | 7f04268 | 2008-10-15 02:05:31 +0000 | [diff] [blame] | 5216 | // FIXME: Implement more expansions. |
| 5217 | } |
| 5218 | |
| 5219 | SDValue SetCC1 = DAG.getSetCC(VT, LHS, RHS, CC1); |
| 5220 | SDValue SetCC2 = DAG.getSetCC(VT, LHS, RHS, CC2); |
| 5221 | LHS = DAG.getNode(Opc, VT, SetCC1, SetCC2); |
| 5222 | RHS = SDValue(); |
| 5223 | CC = SDValue(); |
| 5224 | break; |
| 5225 | } |
| 5226 | } |
| 5227 | } |
| 5228 | |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 5229 | /// EmitStackConvert - Emit a store/load combination to the stack. This stores |
| 5230 | /// SrcOp to a stack slot of type SlotVT, truncating it if needed. It then does |
| 5231 | /// a load from the stack slot to DestVT, extending it if needed. |
| 5232 | /// The resultant code need not be legal. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5233 | SDValue SelectionDAGLegalize::EmitStackConvert(SDValue SrcOp, |
| 5234 | MVT SlotVT, |
| 5235 | MVT DestVT) { |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 5236 | // Create the stack frame object. |
Mon P Wang | 364d73d | 2008-07-05 20:40:31 +0000 | [diff] [blame] | 5237 | unsigned SrcAlign = TLI.getTargetData()->getPrefTypeAlignment( |
| 5238 | SrcOp.getValueType().getTypeForMVT()); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5239 | SDValue FIPtr = DAG.CreateStackTemporary(SlotVT, SrcAlign); |
Mon P Wang | 364d73d | 2008-07-05 20:40:31 +0000 | [diff] [blame] | 5240 | |
Dan Gohman | bbbbb9c | 2008-02-11 18:58:42 +0000 | [diff] [blame] | 5241 | FrameIndexSDNode *StackPtrFI = cast<FrameIndexSDNode>(FIPtr); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5242 | int SPFI = StackPtrFI->getIndex(); |
Mon P Wang | 364d73d | 2008-07-05 20:40:31 +0000 | [diff] [blame] | 5243 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5244 | unsigned SrcSize = SrcOp.getValueType().getSizeInBits(); |
| 5245 | unsigned SlotSize = SlotVT.getSizeInBits(); |
| 5246 | unsigned DestSize = DestVT.getSizeInBits(); |
Mon P Wang | 364d73d | 2008-07-05 20:40:31 +0000 | [diff] [blame] | 5247 | unsigned DestAlign = TLI.getTargetData()->getPrefTypeAlignment( |
| 5248 | DestVT.getTypeForMVT()); |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 5249 | |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 5250 | // Emit a store to the stack slot. Use a truncstore if the input value is |
| 5251 | // later than DestVT. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5252 | SDValue Store; |
Mon P Wang | 364d73d | 2008-07-05 20:40:31 +0000 | [diff] [blame] | 5253 | |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 5254 | if (SrcSize > SlotSize) |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5255 | Store = DAG.getTruncStore(DAG.getEntryNode(), SrcOp, FIPtr, |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 5256 | PseudoSourceValue::getFixedStack(SPFI), 0, |
| 5257 | SlotVT, false, SrcAlign); |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 5258 | else { |
| 5259 | assert(SrcSize == SlotSize && "Invalid store"); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5260 | Store = DAG.getStore(DAG.getEntryNode(), SrcOp, FIPtr, |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 5261 | PseudoSourceValue::getFixedStack(SPFI), 0, |
Mon P Wang | 364d73d | 2008-07-05 20:40:31 +0000 | [diff] [blame] | 5262 | false, SrcAlign); |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 5263 | } |
| 5264 | |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 5265 | // Result is a load from the stack slot. |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 5266 | if (SlotSize == DestSize) |
Mon P Wang | 364d73d | 2008-07-05 20:40:31 +0000 | [diff] [blame] | 5267 | return DAG.getLoad(DestVT, Store, FIPtr, NULL, 0, false, DestAlign); |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 5268 | |
| 5269 | assert(SlotSize < DestSize && "Unknown extension!"); |
Mon P Wang | 364d73d | 2008-07-05 20:40:31 +0000 | [diff] [blame] | 5270 | return DAG.getExtLoad(ISD::EXTLOAD, DestVT, Store, FIPtr, NULL, 0, SlotVT, |
| 5271 | false, DestAlign); |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 5272 | } |
| 5273 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5274 | SDValue SelectionDAGLegalize::ExpandSCALAR_TO_VECTOR(SDNode *Node) { |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 5275 | // Create a vector sized/aligned stack slot, store the value to element #0, |
| 5276 | // then load the whole vector back out. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5277 | SDValue StackPtr = DAG.CreateStackTemporary(Node->getValueType(0)); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5278 | |
Dan Gohman | bbbbb9c | 2008-02-11 18:58:42 +0000 | [diff] [blame] | 5279 | FrameIndexSDNode *StackPtrFI = cast<FrameIndexSDNode>(StackPtr); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5280 | int SPFI = StackPtrFI->getIndex(); |
| 5281 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5282 | SDValue Ch = DAG.getStore(DAG.getEntryNode(), Node->getOperand(0), StackPtr, |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 5283 | PseudoSourceValue::getFixedStack(SPFI), 0); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5284 | return DAG.getLoad(Node->getValueType(0), Ch, StackPtr, |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 5285 | PseudoSourceValue::getFixedStack(SPFI), 0); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 5286 | } |
| 5287 | |
| 5288 | |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5289 | /// ExpandBUILD_VECTOR - Expand a BUILD_VECTOR node on targets that don't |
Dan Gohman | 07a9676 | 2007-07-16 14:29:03 +0000 | [diff] [blame] | 5290 | /// support the operation, but do support the resultant vector type. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5291 | SDValue SelectionDAGLegalize::ExpandBUILD_VECTOR(SDNode *Node) { |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5292 | |
| 5293 | // 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] | 5294 | // 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] | 5295 | unsigned NumElems = Node->getNumOperands(); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5296 | bool isOnlyLowElement = true; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5297 | SDValue SplatValue = Node->getOperand(0); |
Chris Lattner | f9d95c8 | 2008-03-09 00:29:42 +0000 | [diff] [blame] | 5298 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5299 | // FIXME: it would be far nicer to change this into map<SDValue,uint64_t> |
Chris Lattner | f9d95c8 | 2008-03-09 00:29:42 +0000 | [diff] [blame] | 5300 | // and use a bitmask instead of a list of elements. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5301 | std::map<SDValue, std::vector<unsigned> > Values; |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 5302 | Values[SplatValue].push_back(0); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 5303 | bool isConstant = true; |
| 5304 | if (!isa<ConstantFPSDNode>(SplatValue) && !isa<ConstantSDNode>(SplatValue) && |
| 5305 | SplatValue.getOpcode() != ISD::UNDEF) |
| 5306 | isConstant = false; |
| 5307 | |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 5308 | for (unsigned i = 1; i < NumElems; ++i) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5309 | SDValue V = Node->getOperand(i); |
Chris Lattner | 89a1b38 | 2006-04-19 23:17:50 +0000 | [diff] [blame] | 5310 | Values[V].push_back(i); |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 5311 | if (V.getOpcode() != ISD::UNDEF) |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5312 | isOnlyLowElement = false; |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 5313 | if (SplatValue != V) |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5314 | SplatValue = SDValue(0,0); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 5315 | |
| 5316 | // If this isn't a constant element or an undef, we can't use a constant |
| 5317 | // pool load. |
| 5318 | if (!isa<ConstantFPSDNode>(V) && !isa<ConstantSDNode>(V) && |
| 5319 | V.getOpcode() != ISD::UNDEF) |
| 5320 | isConstant = false; |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5321 | } |
| 5322 | |
| 5323 | if (isOnlyLowElement) { |
| 5324 | // If the low element is an undef too, then this whole things is an undef. |
| 5325 | if (Node->getOperand(0).getOpcode() == ISD::UNDEF) |
| 5326 | return DAG.getNode(ISD::UNDEF, Node->getValueType(0)); |
| 5327 | // Otherwise, turn this into a scalar_to_vector node. |
| 5328 | return DAG.getNode(ISD::SCALAR_TO_VECTOR, Node->getValueType(0), |
| 5329 | Node->getOperand(0)); |
| 5330 | } |
| 5331 | |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 5332 | // If all elements are constants, create a load from the constant pool. |
| 5333 | if (isConstant) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5334 | MVT VT = Node->getValueType(0); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 5335 | std::vector<Constant*> CV; |
| 5336 | for (unsigned i = 0, e = NumElems; i != e; ++i) { |
| 5337 | if (ConstantFPSDNode *V = |
| 5338 | dyn_cast<ConstantFPSDNode>(Node->getOperand(i))) { |
Dan Gohman | 4fbd796 | 2008-09-12 18:08:03 +0000 | [diff] [blame] | 5339 | CV.push_back(const_cast<ConstantFP *>(V->getConstantFPValue())); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 5340 | } else if (ConstantSDNode *V = |
Chris Lattner | 02a260a | 2008-04-20 00:41:09 +0000 | [diff] [blame] | 5341 | dyn_cast<ConstantSDNode>(Node->getOperand(i))) { |
Dan Gohman | 4fbd796 | 2008-09-12 18:08:03 +0000 | [diff] [blame] | 5342 | CV.push_back(const_cast<ConstantInt *>(V->getConstantIntValue())); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 5343 | } else { |
| 5344 | assert(Node->getOperand(i).getOpcode() == ISD::UNDEF); |
Chris Lattner | 02a260a | 2008-04-20 00:41:09 +0000 | [diff] [blame] | 5345 | const Type *OpNTy = |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5346 | Node->getOperand(0).getValueType().getTypeForMVT(); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 5347 | CV.push_back(UndefValue::get(OpNTy)); |
| 5348 | } |
| 5349 | } |
Reid Spencer | 9d6565a | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 5350 | Constant *CP = ConstantVector::get(CV); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5351 | SDValue CPIdx = DAG.getConstantPool(CP, TLI.getPointerTy()); |
Dan Gohman | 50284d8 | 2008-09-16 22:05:41 +0000 | [diff] [blame] | 5352 | unsigned Alignment = 1 << cast<ConstantPoolSDNode>(CPIdx)->getAlignment(); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5353 | return DAG.getLoad(VT, DAG.getEntryNode(), CPIdx, |
Dan Gohman | 50284d8 | 2008-09-16 22:05:41 +0000 | [diff] [blame] | 5354 | PseudoSourceValue::getConstantPool(), 0, |
| 5355 | false, Alignment); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 5356 | } |
| 5357 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5358 | if (SplatValue.getNode()) { // Splat of one value? |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 5359 | // Build the shuffle constant vector: <0, 0, 0, 0> |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5360 | MVT MaskVT = MVT::getIntVectorWithNumElements(NumElems); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5361 | SDValue Zero = DAG.getConstant(0, MaskVT.getVectorElementType()); |
| 5362 | std::vector<SDValue> ZeroVec(NumElems, Zero); |
| 5363 | SDValue SplatMask = DAG.getNode(ISD::BUILD_VECTOR, MaskVT, |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 5364 | &ZeroVec[0], ZeroVec.size()); |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 5365 | |
| 5366 | // If the target supports VECTOR_SHUFFLE and this shuffle mask, use it. |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 5367 | if (isShuffleLegal(Node->getValueType(0), SplatMask)) { |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 5368 | // Get the splatted value into the low element of a vector register. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5369 | SDValue LowValVec = |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 5370 | DAG.getNode(ISD::SCALAR_TO_VECTOR, Node->getValueType(0), SplatValue); |
| 5371 | |
| 5372 | // Return shuffle(LowValVec, undef, <0,0,0,0>) |
| 5373 | return DAG.getNode(ISD::VECTOR_SHUFFLE, Node->getValueType(0), LowValVec, |
| 5374 | DAG.getNode(ISD::UNDEF, Node->getValueType(0)), |
| 5375 | SplatMask); |
| 5376 | } |
| 5377 | } |
| 5378 | |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 5379 | // If there are only two unique elements, we may be able to turn this into a |
| 5380 | // vector shuffle. |
| 5381 | if (Values.size() == 2) { |
Chris Lattner | f9d95c8 | 2008-03-09 00:29:42 +0000 | [diff] [blame] | 5382 | // Get the two values in deterministic order. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5383 | SDValue Val1 = Node->getOperand(1); |
| 5384 | SDValue Val2; |
| 5385 | std::map<SDValue, std::vector<unsigned> >::iterator MI = Values.begin(); |
Chris Lattner | f9d95c8 | 2008-03-09 00:29:42 +0000 | [diff] [blame] | 5386 | if (MI->first != Val1) |
| 5387 | Val2 = MI->first; |
| 5388 | else |
| 5389 | Val2 = (++MI)->first; |
| 5390 | |
| 5391 | // If Val1 is an undef, make sure end ends up as Val2, to ensure that our |
| 5392 | // vector shuffle has the undef vector on the RHS. |
| 5393 | if (Val1.getOpcode() == ISD::UNDEF) |
| 5394 | std::swap(Val1, Val2); |
| 5395 | |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 5396 | // Build the shuffle constant vector: e.g. <0, 4, 0, 4> |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5397 | MVT MaskVT = MVT::getIntVectorWithNumElements(NumElems); |
| 5398 | MVT MaskEltVT = MaskVT.getVectorElementType(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5399 | std::vector<SDValue> MaskVec(NumElems); |
Chris Lattner | f9d95c8 | 2008-03-09 00:29:42 +0000 | [diff] [blame] | 5400 | |
| 5401 | // Set elements of the shuffle mask for Val1. |
| 5402 | std::vector<unsigned> &Val1Elts = Values[Val1]; |
| 5403 | for (unsigned i = 0, e = Val1Elts.size(); i != e; ++i) |
| 5404 | MaskVec[Val1Elts[i]] = DAG.getConstant(0, MaskEltVT); |
| 5405 | |
| 5406 | // Set elements of the shuffle mask for Val2. |
| 5407 | std::vector<unsigned> &Val2Elts = Values[Val2]; |
| 5408 | for (unsigned i = 0, e = Val2Elts.size(); i != e; ++i) |
| 5409 | if (Val2.getOpcode() != ISD::UNDEF) |
| 5410 | MaskVec[Val2Elts[i]] = DAG.getConstant(NumElems, MaskEltVT); |
| 5411 | else |
| 5412 | MaskVec[Val2Elts[i]] = DAG.getNode(ISD::UNDEF, MaskEltVT); |
| 5413 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5414 | SDValue ShuffleMask = DAG.getNode(ISD::BUILD_VECTOR, MaskVT, |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 5415 | &MaskVec[0], MaskVec.size()); |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 5416 | |
Chris Lattner | f9d95c8 | 2008-03-09 00:29:42 +0000 | [diff] [blame] | 5417 | // If the target supports SCALAR_TO_VECTOR and this shuffle mask, use it. |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 5418 | if (TLI.isOperationLegal(ISD::SCALAR_TO_VECTOR, Node->getValueType(0)) && |
| 5419 | isShuffleLegal(Node->getValueType(0), ShuffleMask)) { |
Chris Lattner | f9d95c8 | 2008-03-09 00:29:42 +0000 | [diff] [blame] | 5420 | Val1 = DAG.getNode(ISD::SCALAR_TO_VECTOR, Node->getValueType(0), Val1); |
| 5421 | Val2 = DAG.getNode(ISD::SCALAR_TO_VECTOR, Node->getValueType(0), Val2); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5422 | SDValue Ops[] = { Val1, Val2, ShuffleMask }; |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 5423 | |
| 5424 | // Return shuffle(LoValVec, HiValVec, <0,1,0,1>) |
Chris Lattner | f9d95c8 | 2008-03-09 00:29:42 +0000 | [diff] [blame] | 5425 | return DAG.getNode(ISD::VECTOR_SHUFFLE, Node->getValueType(0), Ops, 3); |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 5426 | } |
| 5427 | } |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5428 | |
| 5429 | // Otherwise, we can't handle this case efficiently. Allocate a sufficiently |
| 5430 | // aligned object on the stack, store each element into it, then load |
| 5431 | // the result as a vector. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5432 | MVT VT = Node->getValueType(0); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5433 | // Create the stack frame object. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5434 | SDValue FIPtr = DAG.CreateStackTemporary(VT); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5435 | |
| 5436 | // Emit a store of each element to the stack slot. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5437 | SmallVector<SDValue, 8> Stores; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5438 | unsigned TypeByteSize = Node->getOperand(0).getValueType().getSizeInBits()/8; |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5439 | // Store (in the right endianness) the elements to memory. |
| 5440 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) { |
| 5441 | // Ignore undef elements. |
| 5442 | if (Node->getOperand(i).getOpcode() == ISD::UNDEF) continue; |
| 5443 | |
Chris Lattner | 841c882 | 2006-03-22 01:46:54 +0000 | [diff] [blame] | 5444 | unsigned Offset = TypeByteSize*i; |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5445 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5446 | SDValue Idx = DAG.getConstant(Offset, FIPtr.getValueType()); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5447 | Idx = DAG.getNode(ISD::ADD, FIPtr.getValueType(), FIPtr, Idx); |
| 5448 | |
Evan Cheng | 786225a | 2006-10-05 23:01:46 +0000 | [diff] [blame] | 5449 | Stores.push_back(DAG.getStore(DAG.getEntryNode(), Node->getOperand(i), Idx, |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 5450 | NULL, 0)); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5451 | } |
| 5452 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5453 | SDValue StoreChain; |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5454 | if (!Stores.empty()) // Not all undef elements? |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 5455 | StoreChain = DAG.getNode(ISD::TokenFactor, MVT::Other, |
| 5456 | &Stores[0], Stores.size()); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5457 | else |
| 5458 | StoreChain = DAG.getEntryNode(); |
| 5459 | |
| 5460 | // Result is a load from the stack slot. |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 5461 | return DAG.getLoad(VT, StoreChain, FIPtr, NULL, 0); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5462 | } |
| 5463 | |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 5464 | void SelectionDAGLegalize::ExpandShiftParts(unsigned NodeOp, |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5465 | SDValue Op, SDValue Amt, |
| 5466 | SDValue &Lo, SDValue &Hi) { |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 5467 | // Expand the subcomponents. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5468 | SDValue LHSL, LHSH; |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 5469 | ExpandOp(Op, LHSL, LHSH); |
| 5470 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5471 | SDValue Ops[] = { LHSL, LHSH, Amt }; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5472 | MVT VT = LHSL.getValueType(); |
Chris Lattner | f9f37fc | 2006-08-14 23:53:35 +0000 | [diff] [blame] | 5473 | Lo = DAG.getNode(NodeOp, DAG.getNodeValueTypes(VT, VT), 2, Ops, 3); |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 5474 | Hi = Lo.getValue(1); |
| 5475 | } |
| 5476 | |
| 5477 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5478 | /// ExpandShift - Try to find a clever way to expand this shift operation out to |
| 5479 | /// smaller elements. If we can't find a way that is more efficient than a |
| 5480 | /// libcall on this target, return false. Otherwise, return true with the |
| 5481 | /// low-parts expanded into Lo and Hi. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5482 | bool SelectionDAGLegalize::ExpandShift(unsigned Opc, SDValue Op,SDValue Amt, |
| 5483 | SDValue &Lo, SDValue &Hi) { |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5484 | assert((Opc == ISD::SHL || Opc == ISD::SRA || Opc == ISD::SRL) && |
| 5485 | "This is not a shift!"); |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5486 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5487 | MVT NVT = TLI.getTypeToTransformTo(Op.getValueType()); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5488 | SDValue ShAmt = LegalizeOp(Amt); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5489 | MVT ShTy = ShAmt.getValueType(); |
| 5490 | unsigned ShBits = ShTy.getSizeInBits(); |
| 5491 | unsigned VTBits = Op.getValueType().getSizeInBits(); |
| 5492 | unsigned NVTBits = NVT.getSizeInBits(); |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5493 | |
Chris Lattner | 7a3c855 | 2007-10-14 20:35:12 +0000 | [diff] [blame] | 5494 | // Handle the case when Amt is an immediate. |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5495 | if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Amt.getNode())) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 5496 | unsigned Cst = CN->getZExtValue(); |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5497 | // Expand the incoming operand to be shifted, so that we have its parts |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5498 | SDValue InL, InH; |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5499 | ExpandOp(Op, InL, InH); |
| 5500 | switch(Opc) { |
| 5501 | case ISD::SHL: |
| 5502 | if (Cst > VTBits) { |
| 5503 | Lo = DAG.getConstant(0, NVT); |
| 5504 | Hi = DAG.getConstant(0, NVT); |
| 5505 | } else if (Cst > NVTBits) { |
| 5506 | Lo = DAG.getConstant(0, NVT); |
| 5507 | Hi = DAG.getNode(ISD::SHL, NVT, InL, DAG.getConstant(Cst-NVTBits,ShTy)); |
Chris Lattner | ee27f57 | 2005-04-11 20:08:52 +0000 | [diff] [blame] | 5508 | } else if (Cst == NVTBits) { |
| 5509 | Lo = DAG.getConstant(0, NVT); |
| 5510 | Hi = InL; |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5511 | } else { |
| 5512 | Lo = DAG.getNode(ISD::SHL, NVT, InL, DAG.getConstant(Cst, ShTy)); |
| 5513 | Hi = DAG.getNode(ISD::OR, NVT, |
| 5514 | DAG.getNode(ISD::SHL, NVT, InH, DAG.getConstant(Cst, ShTy)), |
| 5515 | DAG.getNode(ISD::SRL, NVT, InL, DAG.getConstant(NVTBits-Cst, ShTy))); |
| 5516 | } |
| 5517 | return true; |
| 5518 | case ISD::SRL: |
| 5519 | if (Cst > VTBits) { |
| 5520 | Lo = DAG.getConstant(0, NVT); |
| 5521 | Hi = DAG.getConstant(0, NVT); |
| 5522 | } else if (Cst > NVTBits) { |
| 5523 | Lo = DAG.getNode(ISD::SRL, NVT, InH, DAG.getConstant(Cst-NVTBits,ShTy)); |
| 5524 | Hi = DAG.getConstant(0, NVT); |
Chris Lattner | ee27f57 | 2005-04-11 20:08:52 +0000 | [diff] [blame] | 5525 | } else if (Cst == NVTBits) { |
| 5526 | Lo = InH; |
| 5527 | Hi = DAG.getConstant(0, NVT); |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5528 | } else { |
| 5529 | Lo = DAG.getNode(ISD::OR, NVT, |
| 5530 | DAG.getNode(ISD::SRL, NVT, InL, DAG.getConstant(Cst, ShTy)), |
| 5531 | DAG.getNode(ISD::SHL, NVT, InH, DAG.getConstant(NVTBits-Cst, ShTy))); |
| 5532 | Hi = DAG.getNode(ISD::SRL, NVT, InH, DAG.getConstant(Cst, ShTy)); |
| 5533 | } |
| 5534 | return true; |
| 5535 | case ISD::SRA: |
| 5536 | if (Cst > VTBits) { |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 5537 | Hi = Lo = DAG.getNode(ISD::SRA, NVT, InH, |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5538 | DAG.getConstant(NVTBits-1, ShTy)); |
| 5539 | } else if (Cst > NVTBits) { |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 5540 | Lo = DAG.getNode(ISD::SRA, NVT, InH, |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5541 | DAG.getConstant(Cst-NVTBits, ShTy)); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 5542 | Hi = DAG.getNode(ISD::SRA, NVT, InH, |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5543 | DAG.getConstant(NVTBits-1, ShTy)); |
Chris Lattner | ee27f57 | 2005-04-11 20:08:52 +0000 | [diff] [blame] | 5544 | } else if (Cst == NVTBits) { |
| 5545 | Lo = InH; |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 5546 | Hi = DAG.getNode(ISD::SRA, NVT, InH, |
Chris Lattner | ee27f57 | 2005-04-11 20:08:52 +0000 | [diff] [blame] | 5547 | DAG.getConstant(NVTBits-1, ShTy)); |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5548 | } else { |
| 5549 | Lo = DAG.getNode(ISD::OR, NVT, |
| 5550 | DAG.getNode(ISD::SRL, NVT, InL, DAG.getConstant(Cst, ShTy)), |
| 5551 | DAG.getNode(ISD::SHL, NVT, InH, DAG.getConstant(NVTBits-Cst, ShTy))); |
| 5552 | Hi = DAG.getNode(ISD::SRA, NVT, InH, DAG.getConstant(Cst, ShTy)); |
| 5553 | } |
| 5554 | return true; |
| 5555 | } |
| 5556 | } |
Chris Lattner | 0ea26ca | 2006-09-20 03:38:48 +0000 | [diff] [blame] | 5557 | |
| 5558 | // Okay, the shift amount isn't constant. However, if we can tell that it is |
| 5559 | // >= 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] | 5560 | APInt Mask = APInt::getHighBitsSet(ShBits, ShBits - Log2_32(NVTBits)); |
| 5561 | APInt KnownZero, KnownOne; |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 5562 | DAG.ComputeMaskedBits(Amt, Mask, KnownZero, KnownOne); |
Chris Lattner | 0ea26ca | 2006-09-20 03:38:48 +0000 | [diff] [blame] | 5563 | |
Dan Gohman | 9e255b7 | 2008-02-22 01:12:31 +0000 | [diff] [blame] | 5564 | // If we know that if any of the high bits of the shift amount are one, then |
| 5565 | // we can do this as a couple of simple shifts. |
Dan Gohman | 91dc17b | 2008-02-20 16:57:27 +0000 | [diff] [blame] | 5566 | if (KnownOne.intersects(Mask)) { |
Chris Lattner | 0ea26ca | 2006-09-20 03:38:48 +0000 | [diff] [blame] | 5567 | // Mask out the high bit, which we know is set. |
| 5568 | Amt = DAG.getNode(ISD::AND, Amt.getValueType(), Amt, |
Dan Gohman | 91dc17b | 2008-02-20 16:57:27 +0000 | [diff] [blame] | 5569 | DAG.getConstant(~Mask, Amt.getValueType())); |
Chris Lattner | 0ea26ca | 2006-09-20 03:38:48 +0000 | [diff] [blame] | 5570 | |
| 5571 | // Expand the incoming operand to be shifted, so that we have its parts |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5572 | SDValue InL, InH; |
Chris Lattner | 0ea26ca | 2006-09-20 03:38:48 +0000 | [diff] [blame] | 5573 | ExpandOp(Op, InL, InH); |
| 5574 | switch(Opc) { |
| 5575 | case ISD::SHL: |
| 5576 | Lo = DAG.getConstant(0, NVT); // Low part is zero. |
| 5577 | Hi = DAG.getNode(ISD::SHL, NVT, InL, Amt); // High part from Lo part. |
| 5578 | return true; |
| 5579 | case ISD::SRL: |
| 5580 | Hi = DAG.getConstant(0, NVT); // Hi part is zero. |
| 5581 | Lo = DAG.getNode(ISD::SRL, NVT, InH, Amt); // Lo part from Hi part. |
| 5582 | return true; |
| 5583 | case ISD::SRA: |
| 5584 | Hi = DAG.getNode(ISD::SRA, NVT, InH, // Sign extend high part. |
| 5585 | DAG.getConstant(NVTBits-1, Amt.getValueType())); |
| 5586 | Lo = DAG.getNode(ISD::SRA, NVT, InH, Amt); // Lo part from Hi part. |
| 5587 | return true; |
| 5588 | } |
| 5589 | } |
| 5590 | |
Dan Gohman | 9e255b7 | 2008-02-22 01:12:31 +0000 | [diff] [blame] | 5591 | // If we know that the high bits of the shift amount are all zero, then we can |
| 5592 | // do this as a couple of simple shifts. |
| 5593 | if ((KnownZero & Mask) == Mask) { |
Chris Lattner | 0ea26ca | 2006-09-20 03:38:48 +0000 | [diff] [blame] | 5594 | // Compute 32-amt. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5595 | SDValue Amt2 = DAG.getNode(ISD::SUB, Amt.getValueType(), |
Chris Lattner | 0ea26ca | 2006-09-20 03:38:48 +0000 | [diff] [blame] | 5596 | DAG.getConstant(NVTBits, Amt.getValueType()), |
| 5597 | Amt); |
| 5598 | |
| 5599 | // Expand the incoming operand to be shifted, so that we have its parts |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5600 | SDValue InL, InH; |
Chris Lattner | 0ea26ca | 2006-09-20 03:38:48 +0000 | [diff] [blame] | 5601 | ExpandOp(Op, InL, InH); |
| 5602 | switch(Opc) { |
| 5603 | case ISD::SHL: |
| 5604 | Lo = DAG.getNode(ISD::SHL, NVT, InL, Amt); |
| 5605 | Hi = DAG.getNode(ISD::OR, NVT, |
| 5606 | DAG.getNode(ISD::SHL, NVT, InH, Amt), |
| 5607 | DAG.getNode(ISD::SRL, NVT, InL, Amt2)); |
| 5608 | return true; |
| 5609 | case ISD::SRL: |
| 5610 | Hi = DAG.getNode(ISD::SRL, NVT, InH, Amt); |
| 5611 | Lo = DAG.getNode(ISD::OR, NVT, |
| 5612 | DAG.getNode(ISD::SRL, NVT, InL, Amt), |
| 5613 | DAG.getNode(ISD::SHL, NVT, InH, Amt2)); |
| 5614 | return true; |
| 5615 | case ISD::SRA: |
| 5616 | Hi = DAG.getNode(ISD::SRA, NVT, InH, Amt); |
| 5617 | Lo = DAG.getNode(ISD::OR, NVT, |
| 5618 | DAG.getNode(ISD::SRL, NVT, InL, Amt), |
| 5619 | DAG.getNode(ISD::SHL, NVT, InH, Amt2)); |
| 5620 | return true; |
| 5621 | } |
| 5622 | } |
| 5623 | |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5624 | return false; |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5625 | } |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5626 | |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 5627 | |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5628 | // ExpandLibCall - Expand a node into a call to a libcall. If the result value |
| 5629 | // does not fit into a register, return the lo part and set the hi part to the |
| 5630 | // by-reg argument. If it does fit into a single register, return the result |
| 5631 | // and leave the Hi part unset. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5632 | SDValue SelectionDAGLegalize::ExpandLibCall(RTLIB::Libcall LC, SDNode *Node, |
| 5633 | bool isSigned, SDValue &Hi) { |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 5634 | assert(!IsLegalizingCall && "Cannot overlap legalization of calls!"); |
| 5635 | // The input chain to this libcall is the entry node of the function. |
| 5636 | // Legalizing the call will automatically add the previous call to the |
| 5637 | // dependence. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5638 | SDValue InChain = DAG.getEntryNode(); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 5639 | |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5640 | TargetLowering::ArgListTy Args; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 5641 | TargetLowering::ArgListEntry Entry; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5642 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5643 | MVT ArgVT = Node->getOperand(i).getValueType(); |
| 5644 | const Type *ArgTy = ArgVT.getTypeForMVT(); |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 5645 | Entry.Node = Node->getOperand(i); Entry.Ty = ArgTy; |
Anton Korobeynikov | d0b82b3 | 2007-03-07 16:25:09 +0000 | [diff] [blame] | 5646 | Entry.isSExt = isSigned; |
Duncan Sands | 00fee65 | 2008-02-14 17:28:50 +0000 | [diff] [blame] | 5647 | Entry.isZExt = !isSigned; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 5648 | Args.push_back(Entry); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5649 | } |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 5650 | SDValue Callee = DAG.getExternalSymbol(TLI.getLibcallName(LC), |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 5651 | TLI.getPointerTy()); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 5652 | |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 5653 | // Splice the libcall in wherever FindInputOutputChains tells us to. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5654 | const Type *RetTy = Node->getValueType(0).getTypeForMVT(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5655 | std::pair<SDValue,SDValue> CallInfo = |
Dale Johannesen | 86098bd | 2008-09-26 19:31:26 +0000 | [diff] [blame] | 5656 | TLI.LowerCallTo(InChain, RetTy, isSigned, !isSigned, false, false, |
| 5657 | CallingConv::C, false, Callee, Args, DAG); |
Chris Lattner | b9fa3bc | 2005-05-12 04:49:08 +0000 | [diff] [blame] | 5658 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 5659 | // Legalize the call sequence, starting with the chain. This will advance |
| 5660 | // the LastCALLSEQ_END to the legalized version of the CALLSEQ_END node that |
| 5661 | // was added by LowerCallTo (guaranteeing proper serialization of calls). |
| 5662 | LegalizeOp(CallInfo.second); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5663 | SDValue Result; |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 5664 | switch (getTypeAction(CallInfo.first.getValueType())) { |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5665 | default: assert(0 && "Unknown thing"); |
| 5666 | case Legal: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 5667 | Result = CallInfo.first; |
Chris Lattner | 99c25b8 | 2005-09-02 20:26:58 +0000 | [diff] [blame] | 5668 | break; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5669 | case Expand: |
Chris Lattner | 99c25b8 | 2005-09-02 20:26:58 +0000 | [diff] [blame] | 5670 | ExpandOp(CallInfo.first, Result, Hi); |
Chris Lattner | 99c25b8 | 2005-09-02 20:26:58 +0000 | [diff] [blame] | 5671 | break; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5672 | } |
Chris Lattner | 99c25b8 | 2005-09-02 20:26:58 +0000 | [diff] [blame] | 5673 | return Result; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5674 | } |
| 5675 | |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 5676 | /// LegalizeINT_TO_FP - Legalize a [US]INT_TO_FP operation. |
| 5677 | /// |
| 5678 | SDValue SelectionDAGLegalize:: |
| 5679 | LegalizeINT_TO_FP(SDValue Result, bool isSigned, MVT DestTy, SDValue Op) { |
| 5680 | bool isCustom = false; |
| 5681 | SDValue Tmp1; |
| 5682 | switch (getTypeAction(Op.getValueType())) { |
| 5683 | case Legal: |
| 5684 | switch (TLI.getOperationAction(isSigned ? ISD::SINT_TO_FP : ISD::UINT_TO_FP, |
| 5685 | Op.getValueType())) { |
| 5686 | default: assert(0 && "Unknown operation action!"); |
| 5687 | case TargetLowering::Custom: |
| 5688 | isCustom = true; |
| 5689 | // FALLTHROUGH |
| 5690 | case TargetLowering::Legal: |
| 5691 | Tmp1 = LegalizeOp(Op); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5692 | if (Result.getNode()) |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 5693 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 5694 | else |
| 5695 | Result = DAG.getNode(isSigned ? ISD::SINT_TO_FP : ISD::UINT_TO_FP, |
| 5696 | DestTy, Tmp1); |
| 5697 | if (isCustom) { |
| 5698 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5699 | if (Tmp1.getNode()) Result = Tmp1; |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 5700 | } |
| 5701 | break; |
| 5702 | case TargetLowering::Expand: |
| 5703 | Result = ExpandLegalINT_TO_FP(isSigned, LegalizeOp(Op), DestTy); |
| 5704 | break; |
| 5705 | case TargetLowering::Promote: |
| 5706 | Result = PromoteLegalINT_TO_FP(LegalizeOp(Op), DestTy, isSigned); |
| 5707 | break; |
| 5708 | } |
| 5709 | break; |
| 5710 | case Expand: |
| 5711 | Result = ExpandIntToFP(isSigned, DestTy, Op); |
| 5712 | break; |
| 5713 | case Promote: |
| 5714 | Tmp1 = PromoteOp(Op); |
| 5715 | if (isSigned) { |
| 5716 | Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, Tmp1.getValueType(), |
| 5717 | Tmp1, DAG.getValueType(Op.getValueType())); |
| 5718 | } else { |
| 5719 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, |
| 5720 | Op.getValueType()); |
| 5721 | } |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5722 | if (Result.getNode()) |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 5723 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 5724 | else |
| 5725 | Result = DAG.getNode(isSigned ? ISD::SINT_TO_FP : ISD::UINT_TO_FP, |
| 5726 | DestTy, Tmp1); |
| 5727 | Result = LegalizeOp(Result); // The 'op' is not necessarily legal! |
| 5728 | break; |
| 5729 | } |
| 5730 | return Result; |
| 5731 | } |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 5732 | |
Evan Cheng | 4c6cfad | 2007-04-27 07:33:31 +0000 | [diff] [blame] | 5733 | /// ExpandIntToFP - Expand a [US]INT_TO_FP operation. |
| 5734 | /// |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5735 | SDValue SelectionDAGLegalize:: |
| 5736 | ExpandIntToFP(bool isSigned, MVT DestTy, SDValue Source) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5737 | MVT SourceVT = Source.getValueType(); |
Dan Gohman | 034f60e | 2008-03-11 01:59:03 +0000 | [diff] [blame] | 5738 | bool ExpandSource = getTypeAction(SourceVT) == Expand; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5739 | |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 5740 | // Expand unsupported int-to-fp vector casts by unrolling them. |
| 5741 | if (DestTy.isVector()) { |
| 5742 | if (!ExpandSource) |
| 5743 | return LegalizeOp(UnrollVectorOp(Source)); |
| 5744 | MVT DestEltTy = DestTy.getVectorElementType(); |
| 5745 | if (DestTy.getVectorNumElements() == 1) { |
| 5746 | SDValue Scalar = ScalarizeVectorOp(Source); |
| 5747 | SDValue Result = LegalizeINT_TO_FP(SDValue(), isSigned, |
| 5748 | DestEltTy, Scalar); |
| 5749 | return DAG.getNode(ISD::BUILD_VECTOR, DestTy, Result); |
| 5750 | } |
| 5751 | SDValue Lo, Hi; |
| 5752 | SplitVectorOp(Source, Lo, Hi); |
| 5753 | MVT SplitDestTy = MVT::getVectorVT(DestEltTy, |
| 5754 | DestTy.getVectorNumElements() / 2); |
| 5755 | SDValue LoResult = LegalizeINT_TO_FP(SDValue(), isSigned, SplitDestTy, Lo); |
| 5756 | SDValue HiResult = LegalizeINT_TO_FP(SDValue(), isSigned, SplitDestTy, Hi); |
Evan Cheng | efa5339 | 2008-10-13 18:46:18 +0000 | [diff] [blame] | 5757 | return LegalizeOp(DAG.getNode(ISD::CONCAT_VECTORS, DestTy, LoResult, |
| 5758 | HiResult)); |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 5759 | } |
| 5760 | |
Evan Cheng | 9845eb5 | 2008-04-01 02:18:22 +0000 | [diff] [blame] | 5761 | // Special case for i32 source to take advantage of UINTTOFP_I32_F32, etc. |
| 5762 | if (!isSigned && SourceVT != MVT::i32) { |
Dan Gohman | 34bc178 | 2008-03-05 02:07:31 +0000 | [diff] [blame] | 5763 | // The integer value loaded will be incorrectly if the 'sign bit' of the |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 5764 | // incoming integer is set. To handle this, we dynamically test to see if |
| 5765 | // it is set, and, if so, add a fudge factor. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5766 | SDValue Hi; |
Dan Gohman | 034f60e | 2008-03-11 01:59:03 +0000 | [diff] [blame] | 5767 | if (ExpandSource) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5768 | SDValue Lo; |
Dan Gohman | 034f60e | 2008-03-11 01:59:03 +0000 | [diff] [blame] | 5769 | ExpandOp(Source, Lo, Hi); |
| 5770 | Source = DAG.getNode(ISD::BUILD_PAIR, SourceVT, Lo, Hi); |
| 5771 | } else { |
| 5772 | // The comparison for the sign bit will use the entire operand. |
| 5773 | Hi = Source; |
| 5774 | } |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 5775 | |
Dale Johannesen | 53997b0 | 2008-11-04 20:52:49 +0000 | [diff] [blame] | 5776 | // Check to see if the target has a custom way to lower this. If so, use |
| 5777 | // it. (Note we've already expanded the operand in this case.) |
Dale Johannesen | 1c15bf5 | 2008-10-21 20:50:01 +0000 | [diff] [blame] | 5778 | switch (TLI.getOperationAction(ISD::UINT_TO_FP, SourceVT)) { |
| 5779 | default: assert(0 && "This action not implemented for this operation!"); |
| 5780 | case TargetLowering::Legal: |
| 5781 | case TargetLowering::Expand: |
| 5782 | break; // This case is handled below. |
| 5783 | case TargetLowering::Custom: { |
| 5784 | SDValue NV = TLI.LowerOperation(DAG.getNode(ISD::UINT_TO_FP, DestTy, |
| 5785 | Source), DAG); |
| 5786 | if (NV.getNode()) |
| 5787 | return LegalizeOp(NV); |
| 5788 | break; // The target decided this was legal after all |
| 5789 | } |
| 5790 | } |
| 5791 | |
Chris Lattner | 66de05b | 2005-05-13 04:45:13 +0000 | [diff] [blame] | 5792 | // If this is unsigned, and not supported, first perform the conversion to |
| 5793 | // signed, then adjust the result if the sign bit is set. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5794 | SDValue SignedConv = ExpandIntToFP(true, DestTy, Source); |
Chris Lattner | 66de05b | 2005-05-13 04:45:13 +0000 | [diff] [blame] | 5795 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5796 | SDValue SignSet = DAG.getSetCC(TLI.getSetCCResultType(Hi), Hi, |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 5797 | DAG.getConstant(0, Hi.getValueType()), |
| 5798 | ISD::SETLT); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5799 | SDValue Zero = DAG.getIntPtrConstant(0), Four = DAG.getIntPtrConstant(4); |
| 5800 | SDValue CstOffset = DAG.getNode(ISD::SELECT, Zero.getValueType(), |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 5801 | SignSet, Four, Zero); |
Chris Lattner | 383203b | 2005-05-12 18:52:34 +0000 | [diff] [blame] | 5802 | uint64_t FF = 0x5f800000ULL; |
| 5803 | if (TLI.isLittleEndian()) FF <<= 32; |
Dan Gohman | 34bc178 | 2008-03-05 02:07:31 +0000 | [diff] [blame] | 5804 | static Constant *FudgeFactor = ConstantInt::get(Type::Int64Ty, FF); |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 5805 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5806 | SDValue CPIdx = DAG.getConstantPool(FudgeFactor, TLI.getPointerTy()); |
Dan Gohman | 50284d8 | 2008-09-16 22:05:41 +0000 | [diff] [blame] | 5807 | unsigned Alignment = 1 << cast<ConstantPoolSDNode>(CPIdx)->getAlignment(); |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 5808 | CPIdx = DAG.getNode(ISD::ADD, TLI.getPointerTy(), CPIdx, CstOffset); |
Dan Gohman | 87a0f10 | 2008-09-22 22:40:08 +0000 | [diff] [blame] | 5809 | Alignment = std::min(Alignment, 4u); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5810 | SDValue FudgeInReg; |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 5811 | if (DestTy == MVT::f32) |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5812 | FudgeInReg = DAG.getLoad(MVT::f32, DAG.getEntryNode(), CPIdx, |
Dan Gohman | 50284d8 | 2008-09-16 22:05:41 +0000 | [diff] [blame] | 5813 | PseudoSourceValue::getConstantPool(), 0, |
| 5814 | false, Alignment); |
Duncan Sands | 8e4eb09 | 2008-06-08 20:54:56 +0000 | [diff] [blame] | 5815 | else if (DestTy.bitsGT(MVT::f32)) |
Evan Cheng | 4c6cfad | 2007-04-27 07:33:31 +0000 | [diff] [blame] | 5816 | // FIXME: Avoid the extend by construction the right constantpool? |
Dale Johannesen | 118cd9d | 2007-09-16 16:51:49 +0000 | [diff] [blame] | 5817 | FudgeInReg = DAG.getExtLoad(ISD::EXTLOAD, DestTy, DAG.getEntryNode(), |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5818 | CPIdx, |
Dan Gohman | 3069b87 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 5819 | PseudoSourceValue::getConstantPool(), 0, |
Dan Gohman | 50284d8 | 2008-09-16 22:05:41 +0000 | [diff] [blame] | 5820 | MVT::f32, false, Alignment); |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 5821 | else |
| 5822 | assert(0 && "Unexpected conversion"); |
| 5823 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5824 | MVT SCVT = SignedConv.getValueType(); |
Evan Cheng | 4c6cfad | 2007-04-27 07:33:31 +0000 | [diff] [blame] | 5825 | if (SCVT != DestTy) { |
| 5826 | // Destination type needs to be expanded as well. The FADD now we are |
| 5827 | // constructing will be expanded into a libcall. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5828 | if (SCVT.getSizeInBits() != DestTy.getSizeInBits()) { |
| 5829 | assert(SCVT.getSizeInBits() * 2 == DestTy.getSizeInBits()); |
Dan Gohman | d91446d | 2008-03-05 01:08:17 +0000 | [diff] [blame] | 5830 | SignedConv = DAG.getNode(ISD::BUILD_PAIR, DestTy, |
Evan Cheng | 4c6cfad | 2007-04-27 07:33:31 +0000 | [diff] [blame] | 5831 | SignedConv, SignedConv.getValue(1)); |
| 5832 | } |
| 5833 | SignedConv = DAG.getNode(ISD::BIT_CONVERT, DestTy, SignedConv); |
| 5834 | } |
Chris Lattner | 473a990 | 2005-09-29 06:44:39 +0000 | [diff] [blame] | 5835 | return DAG.getNode(ISD::FADD, DestTy, SignedConv, FudgeInReg); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5836 | } |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 5837 | |
Chris Lattner | a88a260 | 2005-05-14 05:33:54 +0000 | [diff] [blame] | 5838 | // Check to see if the target has a custom way to lower this. If so, use it. |
Dan Gohman | d91446d | 2008-03-05 01:08:17 +0000 | [diff] [blame] | 5839 | switch (TLI.getOperationAction(ISD::SINT_TO_FP, SourceVT)) { |
Chris Lattner | a88a260 | 2005-05-14 05:33:54 +0000 | [diff] [blame] | 5840 | default: assert(0 && "This action not implemented for this operation!"); |
| 5841 | case TargetLowering::Legal: |
| 5842 | case TargetLowering::Expand: |
| 5843 | break; // This case is handled below. |
Chris Lattner | 07dffd6 | 2005-08-26 00:14:16 +0000 | [diff] [blame] | 5844 | case TargetLowering::Custom: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5845 | SDValue NV = TLI.LowerOperation(DAG.getNode(ISD::SINT_TO_FP, DestTy, |
Chris Lattner | 07dffd6 | 2005-08-26 00:14:16 +0000 | [diff] [blame] | 5846 | Source), DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5847 | if (NV.getNode()) |
Chris Lattner | 07dffd6 | 2005-08-26 00:14:16 +0000 | [diff] [blame] | 5848 | return LegalizeOp(NV); |
| 5849 | break; // The target decided this was legal after all |
| 5850 | } |
Chris Lattner | a88a260 | 2005-05-14 05:33:54 +0000 | [diff] [blame] | 5851 | } |
| 5852 | |
Chris Lattner | 13689e2 | 2005-05-12 07:00:44 +0000 | [diff] [blame] | 5853 | // Expand the source, then glue it back together for the call. We must expand |
| 5854 | // the source in case it is shared (this pass of legalize must traverse it). |
Dan Gohman | 034f60e | 2008-03-11 01:59:03 +0000 | [diff] [blame] | 5855 | if (ExpandSource) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5856 | SDValue SrcLo, SrcHi; |
Dan Gohman | 034f60e | 2008-03-11 01:59:03 +0000 | [diff] [blame] | 5857 | ExpandOp(Source, SrcLo, SrcHi); |
| 5858 | Source = DAG.getNode(ISD::BUILD_PAIR, SourceVT, SrcLo, SrcHi); |
| 5859 | } |
Chris Lattner | 13689e2 | 2005-05-12 07:00:44 +0000 | [diff] [blame] | 5860 | |
Duncan Sands | b2ff885 | 2008-07-17 02:36:29 +0000 | [diff] [blame] | 5861 | RTLIB::Libcall LC = isSigned ? |
| 5862 | RTLIB::getSINTTOFP(SourceVT, DestTy) : |
| 5863 | RTLIB::getUINTTOFP(SourceVT, DestTy); |
| 5864 | assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unknown int value type"); |
| 5865 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 5866 | Source = DAG.getNode(ISD::SINT_TO_FP, DestTy, Source); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5867 | SDValue HiPart; |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5868 | SDValue Result = ExpandLibCall(LC, Source.getNode(), isSigned, HiPart); |
| 5869 | if (Result.getValueType() != DestTy && HiPart.getNode()) |
Dan Gohman | a2e9485 | 2008-03-10 23:03:31 +0000 | [diff] [blame] | 5870 | Result = DAG.getNode(ISD::BUILD_PAIR, DestTy, Result, HiPart); |
| 5871 | return Result; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5872 | } |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 5873 | |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5874 | /// ExpandLegalINT_TO_FP - This function is responsible for legalizing a |
| 5875 | /// INT_TO_FP operation of the specified operand when the target requests that |
| 5876 | /// we expand it. At this point, we know that the result and operand types are |
| 5877 | /// legal for the target. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5878 | SDValue SelectionDAGLegalize::ExpandLegalINT_TO_FP(bool isSigned, |
| 5879 | SDValue Op0, |
| 5880 | MVT DestVT) { |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5881 | if (Op0.getValueType() == MVT::i32) { |
| 5882 | // simple 32-bit [signed|unsigned] integer to float/double expansion |
| 5883 | |
Chris Lattner | 23594d4 | 2008-01-16 07:03:22 +0000 | [diff] [blame] | 5884 | // Get the stack frame index of a 8 byte buffer. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5885 | SDValue StackSlot = DAG.CreateStackTemporary(MVT::f64); |
Chris Lattner | 23594d4 | 2008-01-16 07:03:22 +0000 | [diff] [blame] | 5886 | |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5887 | // word offset constant for Hi/Lo address computation |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5888 | SDValue WordOff = DAG.getConstant(sizeof(int), TLI.getPointerTy()); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5889 | // set up Hi and Lo (into buffer) address based on endian |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5890 | SDValue Hi = StackSlot; |
| 5891 | SDValue Lo = DAG.getNode(ISD::ADD, TLI.getPointerTy(), StackSlot,WordOff); |
Chris Lattner | 408c428 | 2006-03-23 05:29:04 +0000 | [diff] [blame] | 5892 | if (TLI.isLittleEndian()) |
| 5893 | std::swap(Hi, Lo); |
| 5894 | |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5895 | // if signed map to unsigned space |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5896 | SDValue Op0Mapped; |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5897 | if (isSigned) { |
| 5898 | // constant used to invert sign bit (signed to unsigned mapping) |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5899 | SDValue SignBit = DAG.getConstant(0x80000000u, MVT::i32); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5900 | Op0Mapped = DAG.getNode(ISD::XOR, MVT::i32, Op0, SignBit); |
| 5901 | } else { |
| 5902 | Op0Mapped = Op0; |
| 5903 | } |
| 5904 | // store the lo of the constructed double - based on integer input |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5905 | SDValue Store1 = DAG.getStore(DAG.getEntryNode(), |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 5906 | Op0Mapped, Lo, NULL, 0); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5907 | // initial hi portion of constructed double |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5908 | SDValue InitialHi = DAG.getConstant(0x43300000u, MVT::i32); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5909 | // store the hi of the constructed double - biased exponent |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5910 | SDValue Store2=DAG.getStore(Store1, InitialHi, Hi, NULL, 0); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5911 | // load the constructed double |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5912 | SDValue Load = DAG.getLoad(MVT::f64, Store2, StackSlot, NULL, 0); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5913 | // FP constant to bias correct the final result |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5914 | SDValue Bias = DAG.getConstantFP(isSigned ? |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5915 | BitsToDouble(0x4330000080000000ULL) |
| 5916 | : BitsToDouble(0x4330000000000000ULL), |
| 5917 | MVT::f64); |
| 5918 | // subtract the bias |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5919 | SDValue Sub = DAG.getNode(ISD::FSUB, MVT::f64, Load, Bias); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5920 | // final result |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5921 | SDValue Result; |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5922 | // handle final rounding |
| 5923 | if (DestVT == MVT::f64) { |
| 5924 | // do nothing |
| 5925 | Result = Sub; |
Duncan Sands | 8e4eb09 | 2008-06-08 20:54:56 +0000 | [diff] [blame] | 5926 | } else if (DestVT.bitsLT(MVT::f64)) { |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 5927 | Result = DAG.getNode(ISD::FP_ROUND, DestVT, Sub, |
| 5928 | DAG.getIntPtrConstant(0)); |
Duncan Sands | 8e4eb09 | 2008-06-08 20:54:56 +0000 | [diff] [blame] | 5929 | } else if (DestVT.bitsGT(MVT::f64)) { |
Dale Johannesen | 118cd9d | 2007-09-16 16:51:49 +0000 | [diff] [blame] | 5930 | Result = DAG.getNode(ISD::FP_EXTEND, DestVT, Sub); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5931 | } |
| 5932 | return Result; |
| 5933 | } |
| 5934 | assert(!isSigned && "Legalize cannot Expand SINT_TO_FP for i64 yet"); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5935 | SDValue Tmp1 = DAG.getNode(ISD::SINT_TO_FP, DestVT, Op0); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5936 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5937 | SDValue SignSet = DAG.getSetCC(TLI.getSetCCResultType(Op0), Op0, |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5938 | DAG.getConstant(0, Op0.getValueType()), |
| 5939 | ISD::SETLT); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5940 | SDValue Zero = DAG.getIntPtrConstant(0), Four = DAG.getIntPtrConstant(4); |
| 5941 | SDValue CstOffset = DAG.getNode(ISD::SELECT, Zero.getValueType(), |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5942 | SignSet, Four, Zero); |
| 5943 | |
| 5944 | // If the sign bit of the integer is set, the large number will be treated |
| 5945 | // as a negative number. To counteract this, the dynamic code adds an |
| 5946 | // offset depending on the data type. |
| 5947 | uint64_t FF; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5948 | switch (Op0.getValueType().getSimpleVT()) { |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5949 | default: assert(0 && "Unsupported integer type!"); |
| 5950 | case MVT::i8 : FF = 0x43800000ULL; break; // 2^8 (as a float) |
| 5951 | case MVT::i16: FF = 0x47800000ULL; break; // 2^16 (as a float) |
| 5952 | case MVT::i32: FF = 0x4F800000ULL; break; // 2^32 (as a float) |
| 5953 | case MVT::i64: FF = 0x5F800000ULL; break; // 2^64 (as a float) |
| 5954 | } |
| 5955 | if (TLI.isLittleEndian()) FF <<= 32; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 5956 | static Constant *FudgeFactor = ConstantInt::get(Type::Int64Ty, FF); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5957 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5958 | SDValue CPIdx = DAG.getConstantPool(FudgeFactor, TLI.getPointerTy()); |
Dan Gohman | 50284d8 | 2008-09-16 22:05:41 +0000 | [diff] [blame] | 5959 | unsigned Alignment = 1 << cast<ConstantPoolSDNode>(CPIdx)->getAlignment(); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5960 | CPIdx = DAG.getNode(ISD::ADD, TLI.getPointerTy(), CPIdx, CstOffset); |
Dan Gohman | 87a0f10 | 2008-09-22 22:40:08 +0000 | [diff] [blame] | 5961 | Alignment = std::min(Alignment, 4u); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5962 | SDValue FudgeInReg; |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5963 | if (DestVT == MVT::f32) |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5964 | FudgeInReg = DAG.getLoad(MVT::f32, DAG.getEntryNode(), CPIdx, |
Dan Gohman | 50284d8 | 2008-09-16 22:05:41 +0000 | [diff] [blame] | 5965 | PseudoSourceValue::getConstantPool(), 0, |
| 5966 | false, Alignment); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5967 | else { |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5968 | FudgeInReg = |
| 5969 | LegalizeOp(DAG.getExtLoad(ISD::EXTLOAD, DestVT, |
| 5970 | DAG.getEntryNode(), CPIdx, |
Dan Gohman | 3069b87 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 5971 | PseudoSourceValue::getConstantPool(), 0, |
Dan Gohman | 50284d8 | 2008-09-16 22:05:41 +0000 | [diff] [blame] | 5972 | MVT::f32, false, Alignment)); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5973 | } |
| 5974 | |
| 5975 | return DAG.getNode(ISD::FADD, DestVT, Tmp1, FudgeInReg); |
| 5976 | } |
| 5977 | |
| 5978 | /// PromoteLegalINT_TO_FP - This function is responsible for legalizing a |
| 5979 | /// *INT_TO_FP operation of the specified operand when the target requests that |
| 5980 | /// we promote it. At this point, we know that the result and operand types are |
| 5981 | /// legal for the target, and that there is a legal UINT_TO_FP or SINT_TO_FP |
| 5982 | /// operation that takes a larger input. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5983 | SDValue SelectionDAGLegalize::PromoteLegalINT_TO_FP(SDValue LegalOp, |
| 5984 | MVT DestVT, |
| 5985 | bool isSigned) { |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5986 | // First step, figure out the appropriate *INT_TO_FP operation to use. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5987 | MVT NewInTy = LegalOp.getValueType(); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5988 | |
| 5989 | unsigned OpToUse = 0; |
| 5990 | |
| 5991 | // Scan for the appropriate larger type to use. |
| 5992 | while (1) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5993 | NewInTy = (MVT::SimpleValueType)(NewInTy.getSimpleVT()+1); |
| 5994 | assert(NewInTy.isInteger() && "Ran out of possibilities!"); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5995 | |
| 5996 | // If the target supports SINT_TO_FP of this type, use it. |
| 5997 | switch (TLI.getOperationAction(ISD::SINT_TO_FP, NewInTy)) { |
| 5998 | default: break; |
| 5999 | case TargetLowering::Legal: |
| 6000 | if (!TLI.isTypeLegal(NewInTy)) |
| 6001 | break; // Can't use this datatype. |
| 6002 | // FALL THROUGH. |
| 6003 | case TargetLowering::Custom: |
| 6004 | OpToUse = ISD::SINT_TO_FP; |
| 6005 | break; |
| 6006 | } |
| 6007 | if (OpToUse) break; |
| 6008 | if (isSigned) continue; |
| 6009 | |
| 6010 | // If the target supports UINT_TO_FP of this type, use it. |
| 6011 | switch (TLI.getOperationAction(ISD::UINT_TO_FP, NewInTy)) { |
| 6012 | default: break; |
| 6013 | case TargetLowering::Legal: |
| 6014 | if (!TLI.isTypeLegal(NewInTy)) |
| 6015 | break; // Can't use this datatype. |
| 6016 | // FALL THROUGH. |
| 6017 | case TargetLowering::Custom: |
| 6018 | OpToUse = ISD::UINT_TO_FP; |
| 6019 | break; |
| 6020 | } |
| 6021 | if (OpToUse) break; |
| 6022 | |
| 6023 | // Otherwise, try a larger type. |
| 6024 | } |
| 6025 | |
| 6026 | // Okay, we found the operation and type to use. Zero extend our input to the |
| 6027 | // desired type then run the operation on it. |
| 6028 | return DAG.getNode(OpToUse, DestVT, |
| 6029 | DAG.getNode(isSigned ? ISD::SIGN_EXTEND : ISD::ZERO_EXTEND, |
| 6030 | NewInTy, LegalOp)); |
| 6031 | } |
| 6032 | |
| 6033 | /// PromoteLegalFP_TO_INT - This function is responsible for legalizing a |
| 6034 | /// FP_TO_*INT operation of the specified operand when the target requests that |
| 6035 | /// we promote it. At this point, we know that the result and operand types are |
| 6036 | /// legal for the target, and that there is a legal FP_TO_UINT or FP_TO_SINT |
| 6037 | /// operation that returns a larger result. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6038 | SDValue SelectionDAGLegalize::PromoteLegalFP_TO_INT(SDValue LegalOp, |
| 6039 | MVT DestVT, |
| 6040 | bool isSigned) { |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6041 | // First step, figure out the appropriate FP_TO*INT operation to use. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6042 | MVT NewOutTy = DestVT; |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6043 | |
| 6044 | unsigned OpToUse = 0; |
| 6045 | |
| 6046 | // Scan for the appropriate larger type to use. |
| 6047 | while (1) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6048 | NewOutTy = (MVT::SimpleValueType)(NewOutTy.getSimpleVT()+1); |
| 6049 | assert(NewOutTy.isInteger() && "Ran out of possibilities!"); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6050 | |
| 6051 | // If the target supports FP_TO_SINT returning this type, use it. |
| 6052 | switch (TLI.getOperationAction(ISD::FP_TO_SINT, NewOutTy)) { |
| 6053 | default: break; |
| 6054 | case TargetLowering::Legal: |
| 6055 | if (!TLI.isTypeLegal(NewOutTy)) |
| 6056 | break; // Can't use this datatype. |
| 6057 | // FALL THROUGH. |
| 6058 | case TargetLowering::Custom: |
| 6059 | OpToUse = ISD::FP_TO_SINT; |
| 6060 | break; |
| 6061 | } |
| 6062 | if (OpToUse) break; |
| 6063 | |
| 6064 | // If the target supports FP_TO_UINT of this type, use it. |
| 6065 | switch (TLI.getOperationAction(ISD::FP_TO_UINT, NewOutTy)) { |
| 6066 | default: break; |
| 6067 | case TargetLowering::Legal: |
| 6068 | if (!TLI.isTypeLegal(NewOutTy)) |
| 6069 | break; // Can't use this datatype. |
| 6070 | // FALL THROUGH. |
| 6071 | case TargetLowering::Custom: |
| 6072 | OpToUse = ISD::FP_TO_UINT; |
| 6073 | break; |
| 6074 | } |
| 6075 | if (OpToUse) break; |
| 6076 | |
| 6077 | // Otherwise, try a larger type. |
| 6078 | } |
| 6079 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6080 | |
| 6081 | // Okay, we found the operation and type to use. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6082 | SDValue Operation = DAG.getNode(OpToUse, NewOutTy, LegalOp); |
Duncan Sands | 126d907 | 2008-07-04 11:47:58 +0000 | [diff] [blame] | 6083 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6084 | // If the operation produces an invalid type, it must be custom lowered. Use |
| 6085 | // the target lowering hooks to expand it. Just keep the low part of the |
| 6086 | // expanded operation, we know that we're truncating anyway. |
| 6087 | if (getTypeAction(NewOutTy) == Expand) { |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 6088 | SmallVector<SDValue, 2> Results; |
| 6089 | TLI.ReplaceNodeResults(Operation.getNode(), Results, DAG); |
| 6090 | assert(Results.size() == 1 && "Incorrect FP_TO_XINT lowering!"); |
| 6091 | Operation = Results[0]; |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6092 | } |
Duncan Sands | 126d907 | 2008-07-04 11:47:58 +0000 | [diff] [blame] | 6093 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6094 | // Truncate the result of the extended FP_TO_*INT operation to the desired |
| 6095 | // size. |
| 6096 | return DAG.getNode(ISD::TRUNCATE, DestVT, Operation); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6097 | } |
| 6098 | |
| 6099 | /// ExpandBSWAP - Open code the operations for BSWAP of the specified operation. |
| 6100 | /// |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6101 | SDValue SelectionDAGLegalize::ExpandBSWAP(SDValue Op) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6102 | MVT VT = Op.getValueType(); |
| 6103 | MVT SHVT = TLI.getShiftAmountTy(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6104 | SDValue Tmp1, Tmp2, Tmp3, Tmp4, Tmp5, Tmp6, Tmp7, Tmp8; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6105 | switch (VT.getSimpleVT()) { |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6106 | default: assert(0 && "Unhandled Expand type in BSWAP!"); abort(); |
| 6107 | case MVT::i16: |
| 6108 | Tmp2 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(8, SHVT)); |
| 6109 | Tmp1 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(8, SHVT)); |
| 6110 | return DAG.getNode(ISD::OR, VT, Tmp1, Tmp2); |
| 6111 | case MVT::i32: |
| 6112 | Tmp4 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(24, SHVT)); |
| 6113 | Tmp3 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(8, SHVT)); |
| 6114 | Tmp2 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(8, SHVT)); |
| 6115 | Tmp1 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(24, SHVT)); |
| 6116 | Tmp3 = DAG.getNode(ISD::AND, VT, Tmp3, DAG.getConstant(0xFF0000, VT)); |
| 6117 | Tmp2 = DAG.getNode(ISD::AND, VT, Tmp2, DAG.getConstant(0xFF00, VT)); |
| 6118 | Tmp4 = DAG.getNode(ISD::OR, VT, Tmp4, Tmp3); |
| 6119 | Tmp2 = DAG.getNode(ISD::OR, VT, Tmp2, Tmp1); |
| 6120 | return DAG.getNode(ISD::OR, VT, Tmp4, Tmp2); |
| 6121 | case MVT::i64: |
| 6122 | Tmp8 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(56, SHVT)); |
| 6123 | Tmp7 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(40, SHVT)); |
| 6124 | Tmp6 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(24, SHVT)); |
| 6125 | Tmp5 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(8, SHVT)); |
| 6126 | Tmp4 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(8, SHVT)); |
| 6127 | Tmp3 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(24, SHVT)); |
| 6128 | Tmp2 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(40, SHVT)); |
| 6129 | Tmp1 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(56, SHVT)); |
| 6130 | Tmp7 = DAG.getNode(ISD::AND, VT, Tmp7, DAG.getConstant(255ULL<<48, VT)); |
| 6131 | Tmp6 = DAG.getNode(ISD::AND, VT, Tmp6, DAG.getConstant(255ULL<<40, VT)); |
| 6132 | Tmp5 = DAG.getNode(ISD::AND, VT, Tmp5, DAG.getConstant(255ULL<<32, VT)); |
| 6133 | Tmp4 = DAG.getNode(ISD::AND, VT, Tmp4, DAG.getConstant(255ULL<<24, VT)); |
| 6134 | Tmp3 = DAG.getNode(ISD::AND, VT, Tmp3, DAG.getConstant(255ULL<<16, VT)); |
| 6135 | Tmp2 = DAG.getNode(ISD::AND, VT, Tmp2, DAG.getConstant(255ULL<<8 , VT)); |
| 6136 | Tmp8 = DAG.getNode(ISD::OR, VT, Tmp8, Tmp7); |
| 6137 | Tmp6 = DAG.getNode(ISD::OR, VT, Tmp6, Tmp5); |
| 6138 | Tmp4 = DAG.getNode(ISD::OR, VT, Tmp4, Tmp3); |
| 6139 | Tmp2 = DAG.getNode(ISD::OR, VT, Tmp2, Tmp1); |
| 6140 | Tmp8 = DAG.getNode(ISD::OR, VT, Tmp8, Tmp6); |
| 6141 | Tmp4 = DAG.getNode(ISD::OR, VT, Tmp4, Tmp2); |
| 6142 | return DAG.getNode(ISD::OR, VT, Tmp8, Tmp4); |
| 6143 | } |
| 6144 | } |
| 6145 | |
| 6146 | /// ExpandBitCount - Expand the specified bitcount instruction into operations. |
| 6147 | /// |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6148 | SDValue SelectionDAGLegalize::ExpandBitCount(unsigned Opc, SDValue Op) { |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6149 | switch (Opc) { |
| 6150 | default: assert(0 && "Cannot expand this yet!"); |
| 6151 | case ISD::CTPOP: { |
| 6152 | static const uint64_t mask[6] = { |
| 6153 | 0x5555555555555555ULL, 0x3333333333333333ULL, |
| 6154 | 0x0F0F0F0F0F0F0F0FULL, 0x00FF00FF00FF00FFULL, |
| 6155 | 0x0000FFFF0000FFFFULL, 0x00000000FFFFFFFFULL |
| 6156 | }; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6157 | MVT VT = Op.getValueType(); |
| 6158 | MVT ShVT = TLI.getShiftAmountTy(); |
| 6159 | unsigned len = VT.getSizeInBits(); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6160 | for (unsigned i = 0; (1U << i) <= (len / 2); ++i) { |
| 6161 | //x = (x & mask[i][len/8]) + (x >> (1 << i) & mask[i][len/8]) |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6162 | SDValue Tmp2 = DAG.getConstant(mask[i], VT); |
| 6163 | SDValue Tmp3 = DAG.getConstant(1ULL << i, ShVT); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6164 | Op = DAG.getNode(ISD::ADD, VT, DAG.getNode(ISD::AND, VT, Op, Tmp2), |
| 6165 | DAG.getNode(ISD::AND, VT, |
| 6166 | DAG.getNode(ISD::SRL, VT, Op, Tmp3),Tmp2)); |
| 6167 | } |
| 6168 | return Op; |
| 6169 | } |
| 6170 | case ISD::CTLZ: { |
| 6171 | // for now, we do this: |
| 6172 | // x = x | (x >> 1); |
| 6173 | // x = x | (x >> 2); |
| 6174 | // ... |
| 6175 | // x = x | (x >>16); |
| 6176 | // x = x | (x >>32); // for 64-bit input |
| 6177 | // return popcount(~x); |
| 6178 | // |
| 6179 | // but see also: http://www.hackersdelight.org/HDcode/nlz.cc |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6180 | MVT VT = Op.getValueType(); |
| 6181 | MVT ShVT = TLI.getShiftAmountTy(); |
| 6182 | unsigned len = VT.getSizeInBits(); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6183 | for (unsigned i = 0; (1U << i) <= (len / 2); ++i) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6184 | SDValue Tmp3 = DAG.getConstant(1ULL << i, ShVT); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6185 | Op = DAG.getNode(ISD::OR, VT, Op, DAG.getNode(ISD::SRL, VT, Op, Tmp3)); |
| 6186 | } |
| 6187 | Op = DAG.getNode(ISD::XOR, VT, Op, DAG.getConstant(~0ULL, VT)); |
| 6188 | return DAG.getNode(ISD::CTPOP, VT, Op); |
| 6189 | } |
| 6190 | case ISD::CTTZ: { |
| 6191 | // for now, we use: { return popcount(~x & (x - 1)); } |
| 6192 | // unless the target has ctlz but not ctpop, in which case we use: |
| 6193 | // { return 32 - nlz(~x & (x-1)); } |
| 6194 | // see also http://www.hackersdelight.org/HDcode/ntz.cc |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6195 | MVT VT = Op.getValueType(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6196 | SDValue Tmp2 = DAG.getConstant(~0ULL, VT); |
| 6197 | SDValue Tmp3 = DAG.getNode(ISD::AND, VT, |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6198 | DAG.getNode(ISD::XOR, VT, Op, Tmp2), |
| 6199 | DAG.getNode(ISD::SUB, VT, Op, DAG.getConstant(1, VT))); |
| 6200 | // If ISD::CTLZ is legal and CTPOP isn't, then do that instead. |
| 6201 | if (!TLI.isOperationLegal(ISD::CTPOP, VT) && |
| 6202 | TLI.isOperationLegal(ISD::CTLZ, VT)) |
| 6203 | return DAG.getNode(ISD::SUB, VT, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6204 | DAG.getConstant(VT.getSizeInBits(), VT), |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6205 | DAG.getNode(ISD::CTLZ, VT, Tmp3)); |
| 6206 | return DAG.getNode(ISD::CTPOP, VT, Tmp3); |
| 6207 | } |
| 6208 | } |
| 6209 | } |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6210 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6211 | /// ExpandOp - Expand the specified SDValue into its two component pieces |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6212 | /// Lo&Hi. Note that the Op MUST be an expanded type. As a result of this, the |
Dan Gohman | 929d3eb | 2008-10-01 15:07:49 +0000 | [diff] [blame] | 6213 | /// LegalizedNodes map is filled in for any results that are not expanded, the |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6214 | /// ExpandedNodes map is filled in for any results that are expanded, and the |
| 6215 | /// Lo/Hi values are returned. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6216 | void SelectionDAGLegalize::ExpandOp(SDValue Op, SDValue &Lo, SDValue &Hi){ |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6217 | MVT VT = Op.getValueType(); |
| 6218 | MVT NVT = TLI.getTypeToTransformTo(VT); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6219 | SDNode *Node = Op.getNode(); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6220 | assert(getTypeAction(VT) == Expand && "Not an expanded type!"); |
Duncan Sands | 8e4eb09 | 2008-06-08 20:54:56 +0000 | [diff] [blame] | 6221 | assert(((NVT.isInteger() && NVT.bitsLT(VT)) || VT.isFloatingPoint() || |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6222 | VT.isVector()) && "Cannot expand to FP value or to larger int value!"); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6223 | |
Chris Lattner | 6fdcb25 | 2005-09-02 20:32:45 +0000 | [diff] [blame] | 6224 | // See if we already expanded it. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6225 | DenseMap<SDValue, std::pair<SDValue, SDValue> >::iterator I |
Chris Lattner | 6fdcb25 | 2005-09-02 20:32:45 +0000 | [diff] [blame] | 6226 | = ExpandedNodes.find(Op); |
| 6227 | if (I != ExpandedNodes.end()) { |
| 6228 | Lo = I->second.first; |
| 6229 | Hi = I->second.second; |
| 6230 | return; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6231 | } |
| 6232 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6233 | switch (Node->getOpcode()) { |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 6234 | case ISD::CopyFromReg: |
| 6235 | assert(0 && "CopyFromReg must be legal!"); |
Dale Johannesen | 6eaeff2 | 2007-10-10 01:01:31 +0000 | [diff] [blame] | 6236 | case ISD::FP_ROUND_INREG: |
| 6237 | if (VT == MVT::ppcf128 && |
| 6238 | TLI.getOperationAction(ISD::FP_ROUND_INREG, VT) == |
| 6239 | TargetLowering::Custom) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6240 | SDValue SrcLo, SrcHi, Src; |
Dale Johannesen | fcf4d24 | 2007-10-11 23:32:15 +0000 | [diff] [blame] | 6241 | ExpandOp(Op.getOperand(0), SrcLo, SrcHi); |
| 6242 | Src = DAG.getNode(ISD::BUILD_PAIR, VT, SrcLo, SrcHi); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6243 | SDValue Result = TLI.LowerOperation( |
Dale Johannesen | fcf4d24 | 2007-10-11 23:32:15 +0000 | [diff] [blame] | 6244 | DAG.getNode(ISD::FP_ROUND_INREG, VT, Src, Op.getOperand(1)), DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6245 | assert(Result.getNode()->getOpcode() == ISD::BUILD_PAIR); |
| 6246 | Lo = Result.getNode()->getOperand(0); |
| 6247 | Hi = Result.getNode()->getOperand(1); |
Dale Johannesen | 6eaeff2 | 2007-10-10 01:01:31 +0000 | [diff] [blame] | 6248 | break; |
| 6249 | } |
| 6250 | // fall through |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 6251 | default: |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 6252 | #ifndef NDEBUG |
Dan Gohman | 3983358 | 2007-06-04 16:17:33 +0000 | [diff] [blame] | 6253 | cerr << "NODE: "; Node->dump(&DAG); cerr << "\n"; |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 6254 | #endif |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6255 | assert(0 && "Do not know how to expand this operator!"); |
| 6256 | abort(); |
Dan Gohman | 1953ecb | 2008-02-27 01:52:30 +0000 | [diff] [blame] | 6257 | case ISD::EXTRACT_ELEMENT: |
| 6258 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 6259 | if (cast<ConstantSDNode>(Node->getOperand(1))->getZExtValue()) |
Dan Gohman | 1953ecb | 2008-02-27 01:52:30 +0000 | [diff] [blame] | 6260 | return ExpandOp(Hi, Lo, Hi); |
Dan Gohman | 18714ae | 2008-02-27 19:44:57 +0000 | [diff] [blame] | 6261 | return ExpandOp(Lo, Lo, Hi); |
Dale Johannesen | 25f1d08 | 2007-10-31 00:32:36 +0000 | [diff] [blame] | 6262 | case ISD::EXTRACT_VECTOR_ELT: |
Dale Johannesen | 25f1d08 | 2007-10-31 00:32:36 +0000 | [diff] [blame] | 6263 | // ExpandEXTRACT_VECTOR_ELT tolerates invalid result types. |
| 6264 | Lo = ExpandEXTRACT_VECTOR_ELT(Op); |
| 6265 | return ExpandOp(Lo, Lo, Hi); |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 6266 | case ISD::UNDEF: |
| 6267 | Lo = DAG.getNode(ISD::UNDEF, NVT); |
| 6268 | Hi = DAG.getNode(ISD::UNDEF, NVT); |
| 6269 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6270 | case ISD::Constant: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6271 | unsigned NVTBits = NVT.getSizeInBits(); |
Dan Gohman | 050f550 | 2008-03-03 22:20:46 +0000 | [diff] [blame] | 6272 | const APInt &Cst = cast<ConstantSDNode>(Node)->getAPIntValue(); |
| 6273 | Lo = DAG.getConstant(APInt(Cst).trunc(NVTBits), NVT); |
| 6274 | Hi = DAG.getConstant(Cst.lshr(NVTBits).trunc(NVTBits), NVT); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6275 | break; |
| 6276 | } |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 6277 | case ISD::ConstantFP: { |
| 6278 | ConstantFPSDNode *CFP = cast<ConstantFPSDNode>(Node); |
Dale Johannesen | a471c2e | 2007-10-11 18:07:22 +0000 | [diff] [blame] | 6279 | if (CFP->getValueType(0) == MVT::ppcf128) { |
Dale Johannesen | 7111b02 | 2008-10-09 18:53:47 +0000 | [diff] [blame] | 6280 | APInt api = CFP->getValueAPF().bitcastToAPInt(); |
Dale Johannesen | a471c2e | 2007-10-11 18:07:22 +0000 | [diff] [blame] | 6281 | Lo = DAG.getConstantFP(APFloat(APInt(64, 1, &api.getRawData()[1])), |
| 6282 | MVT::f64); |
| 6283 | Hi = DAG.getConstantFP(APFloat(APInt(64, 1, &api.getRawData()[0])), |
| 6284 | MVT::f64); |
| 6285 | break; |
| 6286 | } |
Evan Cheng | 279101e | 2006-12-12 22:19:28 +0000 | [diff] [blame] | 6287 | Lo = ExpandConstantFP(CFP, false, DAG, TLI); |
Evan Cheng | 9f87788 | 2006-12-13 20:57:08 +0000 | [diff] [blame] | 6288 | if (getTypeAction(Lo.getValueType()) == Expand) |
| 6289 | ExpandOp(Lo, Lo, Hi); |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 6290 | break; |
| 6291 | } |
Chris Lattner | d4e50bb | 2005-03-28 22:03:13 +0000 | [diff] [blame] | 6292 | case ISD::BUILD_PAIR: |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6293 | // Return the operands. |
| 6294 | Lo = Node->getOperand(0); |
| 6295 | Hi = Node->getOperand(1); |
Chris Lattner | d4e50bb | 2005-03-28 22:03:13 +0000 | [diff] [blame] | 6296 | break; |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6297 | |
| 6298 | case ISD::MERGE_VALUES: |
Chris Lattner | c58d558 | 2007-11-24 19:12:15 +0000 | [diff] [blame] | 6299 | if (Node->getNumValues() == 1) { |
| 6300 | ExpandOp(Op.getOperand(0), Lo, Hi); |
| 6301 | break; |
| 6302 | } |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6303 | // FIXME: For now only expand i64,chain = MERGE_VALUES (x, y) |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 6304 | assert(Op.getResNo() == 0 && Node->getNumValues() == 2 && |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6305 | Op.getValue(1).getValueType() == MVT::Other && |
| 6306 | "unhandled MERGE_VALUES"); |
| 6307 | ExpandOp(Op.getOperand(0), Lo, Hi); |
| 6308 | // Remember that we legalized the chain. |
| 6309 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Op.getOperand(1))); |
| 6310 | break; |
Chris Lattner | 58f7963 | 2005-12-12 22:27:43 +0000 | [diff] [blame] | 6311 | |
| 6312 | case ISD::SIGN_EXTEND_INREG: |
| 6313 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Chris Lattner | 4bdd275 | 2006-10-06 17:34:12 +0000 | [diff] [blame] | 6314 | // sext_inreg the low part if needed. |
| 6315 | Lo = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Lo, Node->getOperand(1)); |
| 6316 | |
| 6317 | // The high part gets the sign extension from the lo-part. This handles |
| 6318 | // things like sextinreg V:i64 from i8. |
Chris Lattner | 58f7963 | 2005-12-12 22:27:43 +0000 | [diff] [blame] | 6319 | Hi = DAG.getNode(ISD::SRA, NVT, Lo, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6320 | DAG.getConstant(NVT.getSizeInBits()-1, |
Chris Lattner | 58f7963 | 2005-12-12 22:27:43 +0000 | [diff] [blame] | 6321 | TLI.getShiftAmountTy())); |
Chris Lattner | 58f7963 | 2005-12-12 22:27:43 +0000 | [diff] [blame] | 6322 | break; |
Chris Lattner | d4e50bb | 2005-03-28 22:03:13 +0000 | [diff] [blame] | 6323 | |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 6324 | case ISD::BSWAP: { |
| 6325 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6326 | SDValue TempLo = DAG.getNode(ISD::BSWAP, NVT, Hi); |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 6327 | Hi = DAG.getNode(ISD::BSWAP, NVT, Lo); |
| 6328 | Lo = TempLo; |
| 6329 | break; |
| 6330 | } |
| 6331 | |
Chris Lattner | edb1add | 2005-05-11 04:51:16 +0000 | [diff] [blame] | 6332 | case ISD::CTPOP: |
| 6333 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Chris Lattner | 9b583b4 | 2005-05-11 05:09:47 +0000 | [diff] [blame] | 6334 | Lo = DAG.getNode(ISD::ADD, NVT, // ctpop(HL) -> ctpop(H)+ctpop(L) |
| 6335 | DAG.getNode(ISD::CTPOP, NVT, Lo), |
| 6336 | DAG.getNode(ISD::CTPOP, NVT, Hi)); |
Chris Lattner | edb1add | 2005-05-11 04:51:16 +0000 | [diff] [blame] | 6337 | Hi = DAG.getConstant(0, NVT); |
| 6338 | break; |
| 6339 | |
Chris Lattner | 39a8f33 | 2005-05-12 19:05:01 +0000 | [diff] [blame] | 6340 | case ISD::CTLZ: { |
| 6341 | // ctlz (HL) -> ctlz(H) != 32 ? ctlz(H) : (ctlz(L)+32) |
Chris Lattner | 3becf20 | 2005-05-12 19:27:51 +0000 | [diff] [blame] | 6342 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6343 | SDValue BitsC = DAG.getConstant(NVT.getSizeInBits(), NVT); |
| 6344 | SDValue HLZ = DAG.getNode(ISD::CTLZ, NVT, Hi); |
| 6345 | SDValue TopNotZero = DAG.getSetCC(TLI.getSetCCResultType(HLZ), HLZ, BitsC, |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 6346 | ISD::SETNE); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6347 | SDValue LowPart = DAG.getNode(ISD::CTLZ, NVT, Lo); |
Chris Lattner | 39a8f33 | 2005-05-12 19:05:01 +0000 | [diff] [blame] | 6348 | LowPart = DAG.getNode(ISD::ADD, NVT, LowPart, BitsC); |
| 6349 | |
| 6350 | Lo = DAG.getNode(ISD::SELECT, NVT, TopNotZero, HLZ, LowPart); |
| 6351 | Hi = DAG.getConstant(0, NVT); |
| 6352 | break; |
| 6353 | } |
| 6354 | |
| 6355 | case ISD::CTTZ: { |
| 6356 | // cttz (HL) -> cttz(L) != 32 ? cttz(L) : (cttz(H)+32) |
Chris Lattner | 3becf20 | 2005-05-12 19:27:51 +0000 | [diff] [blame] | 6357 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6358 | SDValue BitsC = DAG.getConstant(NVT.getSizeInBits(), NVT); |
| 6359 | SDValue LTZ = DAG.getNode(ISD::CTTZ, NVT, Lo); |
| 6360 | SDValue BotNotZero = DAG.getSetCC(TLI.getSetCCResultType(LTZ), LTZ, BitsC, |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 6361 | ISD::SETNE); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6362 | SDValue HiPart = DAG.getNode(ISD::CTTZ, NVT, Hi); |
Chris Lattner | 39a8f33 | 2005-05-12 19:05:01 +0000 | [diff] [blame] | 6363 | HiPart = DAG.getNode(ISD::ADD, NVT, HiPart, BitsC); |
| 6364 | |
| 6365 | Lo = DAG.getNode(ISD::SELECT, NVT, BotNotZero, LTZ, HiPart); |
| 6366 | Hi = DAG.getConstant(0, NVT); |
| 6367 | break; |
| 6368 | } |
Chris Lattner | edb1add | 2005-05-11 04:51:16 +0000 | [diff] [blame] | 6369 | |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 6370 | case ISD::VAARG: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6371 | SDValue Ch = Node->getOperand(0); // Legalize the chain. |
| 6372 | SDValue Ptr = Node->getOperand(1); // Legalize the pointer. |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 6373 | Lo = DAG.getVAArg(NVT, Ch, Ptr, Node->getOperand(2)); |
| 6374 | Hi = DAG.getVAArg(NVT, Lo.getValue(1), Ptr, Node->getOperand(2)); |
| 6375 | |
| 6376 | // Remember that we legalized the chain. |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6377 | Hi = LegalizeOp(Hi); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 6378 | AddLegalizedOperand(Op.getValue(1), Hi.getValue(1)); |
Duncan Sands | 0753fc1 | 2008-02-11 10:37:04 +0000 | [diff] [blame] | 6379 | if (TLI.isBigEndian()) |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 6380 | std::swap(Lo, Hi); |
| 6381 | break; |
| 6382 | } |
| 6383 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6384 | case ISD::LOAD: { |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6385 | LoadSDNode *LD = cast<LoadSDNode>(Node); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6386 | SDValue Ch = LD->getChain(); // Legalize the chain. |
| 6387 | SDValue Ptr = LD->getBasePtr(); // Legalize the pointer. |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6388 | ISD::LoadExtType ExtType = LD->getExtensionType(); |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 6389 | const Value *SV = LD->getSrcValue(); |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 6390 | int SVOffset = LD->getSrcValueOffset(); |
| 6391 | unsigned Alignment = LD->getAlignment(); |
| 6392 | bool isVolatile = LD->isVolatile(); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6393 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6394 | if (ExtType == ISD::NON_EXTLOAD) { |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 6395 | Lo = DAG.getLoad(NVT, Ch, Ptr, SV, SVOffset, |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 6396 | isVolatile, Alignment); |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 6397 | if (VT == MVT::f32 || VT == MVT::f64) { |
| 6398 | // f32->i32 or f64->i64 one to one expansion. |
| 6399 | // Remember that we legalized the chain. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6400 | AddLegalizedOperand(SDValue(Node, 1), LegalizeOp(Lo.getValue(1))); |
Evan Cheng | 9f87788 | 2006-12-13 20:57:08 +0000 | [diff] [blame] | 6401 | // Recursively expand the new load. |
| 6402 | if (getTypeAction(NVT) == Expand) |
| 6403 | ExpandOp(Lo, Lo, Hi); |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 6404 | break; |
| 6405 | } |
Chris Lattner | ec39a45 | 2005-01-19 18:02:17 +0000 | [diff] [blame] | 6406 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6407 | // Increment the pointer to the other half. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6408 | unsigned IncrementSize = Lo.getValueType().getSizeInBits()/8; |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6409 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 6410 | DAG.getIntPtrConstant(IncrementSize)); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6411 | SVOffset += IncrementSize; |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 6412 | Alignment = MinAlign(Alignment, IncrementSize); |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 6413 | Hi = DAG.getLoad(NVT, Ch, Ptr, SV, SVOffset, |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 6414 | isVolatile, Alignment); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 6415 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6416 | // Build a factor node to remember that this load is independent of the |
| 6417 | // other one. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6418 | SDValue TF = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1), |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6419 | Hi.getValue(1)); |
| 6420 | |
| 6421 | // Remember that we legalized the chain. |
| 6422 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(TF)); |
Duncan Sands | 0753fc1 | 2008-02-11 10:37:04 +0000 | [diff] [blame] | 6423 | if (TLI.isBigEndian()) |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6424 | std::swap(Lo, Hi); |
| 6425 | } else { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6426 | MVT EVT = LD->getMemoryVT(); |
Evan Cheng | 548f611 | 2006-12-13 03:19:57 +0000 | [diff] [blame] | 6427 | |
Dale Johannesen | b6210fc | 2007-10-19 20:29:00 +0000 | [diff] [blame] | 6428 | if ((VT == MVT::f64 && EVT == MVT::f32) || |
| 6429 | (VT == MVT::ppcf128 && (EVT==MVT::f64 || EVT==MVT::f32))) { |
Evan Cheng | 548f611 | 2006-12-13 03:19:57 +0000 | [diff] [blame] | 6430 | // f64 = EXTLOAD f32 should expand to LOAD, FP_EXTEND |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 6431 | SDValue Load = DAG.getLoad(EVT, Ch, Ptr, SV, |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 6432 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 548f611 | 2006-12-13 03:19:57 +0000 | [diff] [blame] | 6433 | // Remember that we legalized the chain. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6434 | AddLegalizedOperand(SDValue(Node, 1), LegalizeOp(Load.getValue(1))); |
Evan Cheng | 548f611 | 2006-12-13 03:19:57 +0000 | [diff] [blame] | 6435 | ExpandOp(DAG.getNode(ISD::FP_EXTEND, VT, Load), Lo, Hi); |
| 6436 | break; |
| 6437 | } |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6438 | |
| 6439 | if (EVT == NVT) |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 6440 | Lo = DAG.getLoad(NVT, Ch, Ptr, SV, |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 6441 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6442 | else |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 6443 | Lo = DAG.getExtLoad(ExtType, NVT, Ch, Ptr, SV, |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 6444 | SVOffset, EVT, isVolatile, |
| 6445 | Alignment); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6446 | |
| 6447 | // Remember that we legalized the chain. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6448 | AddLegalizedOperand(SDValue(Node, 1), LegalizeOp(Lo.getValue(1))); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6449 | |
| 6450 | if (ExtType == ISD::SEXTLOAD) { |
| 6451 | // The high part is obtained by SRA'ing all but one of the bits of the |
| 6452 | // lo part. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6453 | unsigned LoSize = Lo.getValueType().getSizeInBits(); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6454 | Hi = DAG.getNode(ISD::SRA, NVT, Lo, |
| 6455 | DAG.getConstant(LoSize-1, TLI.getShiftAmountTy())); |
| 6456 | } else if (ExtType == ISD::ZEXTLOAD) { |
| 6457 | // The high part is just a zero. |
| 6458 | Hi = DAG.getConstant(0, NVT); |
| 6459 | } else /* if (ExtType == ISD::EXTLOAD) */ { |
| 6460 | // The high part is undefined. |
| 6461 | Hi = DAG.getNode(ISD::UNDEF, NVT); |
| 6462 | } |
| 6463 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6464 | break; |
| 6465 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6466 | case ISD::AND: |
| 6467 | case ISD::OR: |
| 6468 | case ISD::XOR: { // Simple logical operators -> two trivial pieces. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6469 | SDValue LL, LH, RL, RH; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6470 | ExpandOp(Node->getOperand(0), LL, LH); |
| 6471 | ExpandOp(Node->getOperand(1), RL, RH); |
| 6472 | Lo = DAG.getNode(Node->getOpcode(), NVT, LL, RL); |
| 6473 | Hi = DAG.getNode(Node->getOpcode(), NVT, LH, RH); |
| 6474 | break; |
| 6475 | } |
| 6476 | case ISD::SELECT: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6477 | SDValue LL, LH, RL, RH; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6478 | ExpandOp(Node->getOperand(1), LL, LH); |
| 6479 | ExpandOp(Node->getOperand(2), RL, RH); |
Evan Cheng | 19103b1 | 2006-12-15 22:42:55 +0000 | [diff] [blame] | 6480 | if (getTypeAction(NVT) == Expand) |
| 6481 | NVT = TLI.getTypeToExpandTo(NVT); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 6482 | Lo = DAG.getNode(ISD::SELECT, NVT, Node->getOperand(0), LL, RL); |
Evan Cheng | 19103b1 | 2006-12-15 22:42:55 +0000 | [diff] [blame] | 6483 | if (VT != MVT::f32) |
| 6484 | Hi = DAG.getNode(ISD::SELECT, NVT, Node->getOperand(0), LH, RH); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6485 | break; |
| 6486 | } |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 6487 | case ISD::SELECT_CC: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6488 | SDValue TL, TH, FL, FH; |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 6489 | ExpandOp(Node->getOperand(2), TL, TH); |
| 6490 | ExpandOp(Node->getOperand(3), FL, FH); |
Evan Cheng | 19103b1 | 2006-12-15 22:42:55 +0000 | [diff] [blame] | 6491 | if (getTypeAction(NVT) == Expand) |
| 6492 | NVT = TLI.getTypeToExpandTo(NVT); |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 6493 | Lo = DAG.getNode(ISD::SELECT_CC, NVT, Node->getOperand(0), |
| 6494 | Node->getOperand(1), TL, FL, Node->getOperand(4)); |
Evan Cheng | 19103b1 | 2006-12-15 22:42:55 +0000 | [diff] [blame] | 6495 | if (VT != MVT::f32) |
| 6496 | Hi = DAG.getNode(ISD::SELECT_CC, NVT, Node->getOperand(0), |
| 6497 | Node->getOperand(1), TH, FH, Node->getOperand(4)); |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 6498 | break; |
| 6499 | } |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6500 | case ISD::ANY_EXTEND: |
| 6501 | // The low part is any extension of the input (which degenerates to a copy). |
| 6502 | Lo = DAG.getNode(ISD::ANY_EXTEND, NVT, Node->getOperand(0)); |
| 6503 | // The high part is undefined. |
| 6504 | Hi = DAG.getNode(ISD::UNDEF, NVT); |
| 6505 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6506 | case ISD::SIGN_EXTEND: { |
| 6507 | // The low part is just a sign extension of the input (which degenerates to |
| 6508 | // a copy). |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6509 | Lo = DAG.getNode(ISD::SIGN_EXTEND, NVT, Node->getOperand(0)); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 6510 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6511 | // The high part is obtained by SRA'ing all but one of the bits of the lo |
| 6512 | // part. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6513 | unsigned LoSize = Lo.getValueType().getSizeInBits(); |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6514 | Hi = DAG.getNode(ISD::SRA, NVT, Lo, |
| 6515 | DAG.getConstant(LoSize-1, TLI.getShiftAmountTy())); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6516 | break; |
| 6517 | } |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6518 | case ISD::ZERO_EXTEND: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6519 | // The low part is just a zero extension of the input (which degenerates to |
| 6520 | // a copy). |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6521 | Lo = DAG.getNode(ISD::ZERO_EXTEND, NVT, Node->getOperand(0)); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 6522 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6523 | // The high part is just a zero. |
| 6524 | Hi = DAG.getConstant(0, NVT); |
| 6525 | break; |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 6526 | |
Chris Lattner | 4c948eb | 2007-02-13 23:55:16 +0000 | [diff] [blame] | 6527 | case ISD::TRUNCATE: { |
| 6528 | // The input value must be larger than this value. Expand *it*. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6529 | SDValue NewLo; |
Chris Lattner | 4c948eb | 2007-02-13 23:55:16 +0000 | [diff] [blame] | 6530 | ExpandOp(Node->getOperand(0), NewLo, Hi); |
| 6531 | |
| 6532 | // The low part is now either the right size, or it is closer. If not the |
| 6533 | // right size, make an illegal truncate so we recursively expand it. |
| 6534 | if (NewLo.getValueType() != Node->getValueType(0)) |
| 6535 | NewLo = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0), NewLo); |
| 6536 | ExpandOp(NewLo, Lo, Hi); |
| 6537 | break; |
| 6538 | } |
| 6539 | |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 6540 | case ISD::BIT_CONVERT: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6541 | SDValue Tmp; |
Chris Lattner | f3f333d | 2006-09-09 00:20:27 +0000 | [diff] [blame] | 6542 | if (TLI.getOperationAction(ISD::BIT_CONVERT, VT) == TargetLowering::Custom){ |
| 6543 | // If the target wants to, allow it to lower this itself. |
| 6544 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 6545 | case Expand: assert(0 && "cannot expand FP!"); |
| 6546 | case Legal: Tmp = LegalizeOp(Node->getOperand(0)); break; |
| 6547 | case Promote: Tmp = PromoteOp (Node->getOperand(0)); break; |
| 6548 | } |
| 6549 | Tmp = TLI.LowerOperation(DAG.getNode(ISD::BIT_CONVERT, VT, Tmp), DAG); |
| 6550 | } |
| 6551 | |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 6552 | // f32 / f64 must be expanded to i32 / i64. |
Evan Cheng | 13acce3 | 2006-12-11 19:27:14 +0000 | [diff] [blame] | 6553 | if (VT == MVT::f32 || VT == MVT::f64) { |
| 6554 | Lo = DAG.getNode(ISD::BIT_CONVERT, NVT, Node->getOperand(0)); |
Evan Cheng | 19103b1 | 2006-12-15 22:42:55 +0000 | [diff] [blame] | 6555 | if (getTypeAction(NVT) == Expand) |
| 6556 | ExpandOp(Lo, Lo, Hi); |
Evan Cheng | 7b2b5c8 | 2006-12-12 19:53:13 +0000 | [diff] [blame] | 6557 | break; |
| 6558 | } |
| 6559 | |
| 6560 | // If source operand will be expanded to the same type as VT, i.e. |
| 6561 | // i64 <- f64, i32 <- f32, expand the source operand instead. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6562 | MVT VT0 = Node->getOperand(0).getValueType(); |
Evan Cheng | 7b2b5c8 | 2006-12-12 19:53:13 +0000 | [diff] [blame] | 6563 | if (getTypeAction(VT0) == Expand && TLI.getTypeToTransformTo(VT0) == VT) { |
| 6564 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 6565 | break; |
| 6566 | } |
| 6567 | |
Chris Lattner | f3f333d | 2006-09-09 00:20:27 +0000 | [diff] [blame] | 6568 | // Turn this into a load/store pair by default. |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6569 | if (Tmp.getNode() == 0) |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 6570 | Tmp = EmitStackConvert(Node->getOperand(0), VT, VT); |
Chris Lattner | f3f333d | 2006-09-09 00:20:27 +0000 | [diff] [blame] | 6571 | |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 6572 | ExpandOp(Tmp, Lo, Hi); |
| 6573 | break; |
| 6574 | } |
Andrew Lenharth | f70e30b | 2005-11-20 21:32:07 +0000 | [diff] [blame] | 6575 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6576 | case ISD::READCYCLECOUNTER: { |
Chris Lattner | 308575b | 2005-11-20 22:56:56 +0000 | [diff] [blame] | 6577 | assert(TLI.getOperationAction(ISD::READCYCLECOUNTER, VT) == |
| 6578 | TargetLowering::Custom && |
| 6579 | "Must custom expand ReadCycleCounter"); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6580 | SDValue Tmp = TLI.LowerOperation(Op, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6581 | assert(Tmp.getNode() && "Node must be custom expanded!"); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6582 | ExpandOp(Tmp.getValue(0), Lo, Hi); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6583 | AddLegalizedOperand(SDValue(Node, 1), // Remember we legalized the chain. |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6584 | LegalizeOp(Tmp.getValue(1))); |
Andrew Lenharth | f70e30b | 2005-11-20 21:32:07 +0000 | [diff] [blame] | 6585 | break; |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6586 | } |
Andrew Lenharth | f70e30b | 2005-11-20 21:32:07 +0000 | [diff] [blame] | 6587 | |
Dale Johannesen | 1b54c7f | 2008-10-03 19:41:08 +0000 | [diff] [blame] | 6588 | case ISD::ATOMIC_CMP_SWAP_64: { |
| 6589 | // This operation does not need a loop. |
| 6590 | SDValue Tmp = TLI.LowerOperation(Op, DAG); |
| 6591 | assert(Tmp.getNode() && "Node must be custom expanded!"); |
| 6592 | ExpandOp(Tmp.getValue(0), Lo, Hi); |
| 6593 | AddLegalizedOperand(SDValue(Node, 1), // Remember we legalized the chain. |
| 6594 | LegalizeOp(Tmp.getValue(1))); |
| 6595 | break; |
| 6596 | } |
| 6597 | |
Dale Johannesen | 48c1bc2 | 2008-10-02 18:53:47 +0000 | [diff] [blame] | 6598 | case ISD::ATOMIC_LOAD_ADD_64: |
| 6599 | case ISD::ATOMIC_LOAD_SUB_64: |
| 6600 | case ISD::ATOMIC_LOAD_AND_64: |
| 6601 | case ISD::ATOMIC_LOAD_OR_64: |
| 6602 | case ISD::ATOMIC_LOAD_XOR_64: |
| 6603 | case ISD::ATOMIC_LOAD_NAND_64: |
Dale Johannesen | 1b54c7f | 2008-10-03 19:41:08 +0000 | [diff] [blame] | 6604 | case ISD::ATOMIC_SWAP_64: { |
| 6605 | // These operations require a loop to be generated. We can't do that yet, |
| 6606 | // so substitute a target-dependent pseudo and expand that later. |
Dale Johannesen | 48c1bc2 | 2008-10-02 18:53:47 +0000 | [diff] [blame] | 6607 | SDValue In2Lo, In2Hi, In2; |
| 6608 | ExpandOp(Op.getOperand(2), In2Lo, In2Hi); |
| 6609 | In2 = DAG.getNode(ISD::BUILD_PAIR, VT, In2Lo, In2Hi); |
Dale Johannesen | 1b54c7f | 2008-10-03 19:41:08 +0000 | [diff] [blame] | 6610 | AtomicSDNode* Anode = cast<AtomicSDNode>(Node); |
| 6611 | SDValue Replace = |
| 6612 | DAG.getAtomic(Op.getOpcode(), Op.getOperand(0), Op.getOperand(1), In2, |
| 6613 | Anode->getSrcValue(), Anode->getAlignment()); |
| 6614 | SDValue Result = TLI.LowerOperation(Replace, DAG); |
Dale Johannesen | 48c1bc2 | 2008-10-02 18:53:47 +0000 | [diff] [blame] | 6615 | ExpandOp(Result.getValue(0), Lo, Hi); |
| 6616 | // Remember that we legalized the chain. |
| 6617 | AddLegalizedOperand(SDValue(Node,1), LegalizeOp(Result.getValue(1))); |
Andrew Lenharth | d19189e | 2008-03-05 01:15:49 +0000 | [diff] [blame] | 6618 | break; |
| 6619 | } |
| 6620 | |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 6621 | // These operators cannot be expanded directly, emit them as calls to |
| 6622 | // library functions. |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6623 | case ISD::FP_TO_SINT: { |
Chris Lattner | 80a3e94 | 2005-07-29 00:33:32 +0000 | [diff] [blame] | 6624 | if (TLI.getOperationAction(ISD::FP_TO_SINT, VT) == TargetLowering::Custom) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6625 | SDValue Op; |
Chris Lattner | f20d183 | 2005-07-30 01:40:57 +0000 | [diff] [blame] | 6626 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 6627 | case Expand: assert(0 && "cannot expand FP!"); |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6628 | case Legal: Op = LegalizeOp(Node->getOperand(0)); break; |
| 6629 | case Promote: Op = PromoteOp (Node->getOperand(0)); break; |
Chris Lattner | f20d183 | 2005-07-30 01:40:57 +0000 | [diff] [blame] | 6630 | } |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 6631 | |
Chris Lattner | f20d183 | 2005-07-30 01:40:57 +0000 | [diff] [blame] | 6632 | Op = TLI.LowerOperation(DAG.getNode(ISD::FP_TO_SINT, VT, Op), DAG); |
| 6633 | |
Chris Lattner | 80a3e94 | 2005-07-29 00:33:32 +0000 | [diff] [blame] | 6634 | // Now that the custom expander is done, expand the result, which is still |
| 6635 | // VT. |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6636 | if (Op.getNode()) { |
Chris Lattner | 07dffd6 | 2005-08-26 00:14:16 +0000 | [diff] [blame] | 6637 | ExpandOp(Op, Lo, Hi); |
| 6638 | break; |
| 6639 | } |
Chris Lattner | 80a3e94 | 2005-07-29 00:33:32 +0000 | [diff] [blame] | 6640 | } |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 6641 | |
Duncan Sands | b2ff885 | 2008-07-17 02:36:29 +0000 | [diff] [blame] | 6642 | RTLIB::Libcall LC = RTLIB::getFPTOSINT(Node->getOperand(0).getValueType(), |
| 6643 | VT); |
| 6644 | assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unexpected uint-to-fp conversion!"); |
| 6645 | Lo = ExpandLibCall(LC, Node, false/*sign irrelevant*/, Hi); |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 6646 | break; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6647 | } |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 6648 | |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6649 | case ISD::FP_TO_UINT: { |
Chris Lattner | 80a3e94 | 2005-07-29 00:33:32 +0000 | [diff] [blame] | 6650 | if (TLI.getOperationAction(ISD::FP_TO_UINT, VT) == TargetLowering::Custom) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6651 | SDValue Op; |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6652 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 6653 | case Expand: assert(0 && "cannot expand FP!"); |
| 6654 | case Legal: Op = LegalizeOp(Node->getOperand(0)); break; |
| 6655 | case Promote: Op = PromoteOp (Node->getOperand(0)); break; |
| 6656 | } |
| 6657 | |
| 6658 | Op = TLI.LowerOperation(DAG.getNode(ISD::FP_TO_UINT, VT, Op), DAG); |
| 6659 | |
| 6660 | // Now that the custom expander is done, expand the result. |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6661 | if (Op.getNode()) { |
Chris Lattner | 07dffd6 | 2005-08-26 00:14:16 +0000 | [diff] [blame] | 6662 | ExpandOp(Op, Lo, Hi); |
| 6663 | break; |
| 6664 | } |
Chris Lattner | 80a3e94 | 2005-07-29 00:33:32 +0000 | [diff] [blame] | 6665 | } |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 6666 | |
Duncan Sands | b2ff885 | 2008-07-17 02:36:29 +0000 | [diff] [blame] | 6667 | RTLIB::Libcall LC = RTLIB::getFPTOUINT(Node->getOperand(0).getValueType(), |
| 6668 | VT); |
| 6669 | assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unexpected fp-to-uint conversion!"); |
| 6670 | Lo = ExpandLibCall(LC, Node, false/*sign irrelevant*/, Hi); |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 6671 | break; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6672 | } |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 6673 | |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 6674 | case ISD::SHL: { |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6675 | // If the target wants custom lowering, do so. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6676 | SDValue ShiftAmt = LegalizeOp(Node->getOperand(1)); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6677 | if (TLI.getOperationAction(ISD::SHL, VT) == TargetLowering::Custom) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6678 | SDValue Op = DAG.getNode(ISD::SHL, VT, Node->getOperand(0), ShiftAmt); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6679 | Op = TLI.LowerOperation(Op, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6680 | if (Op.getNode()) { |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6681 | // Now that the custom expander is done, expand the result, which is |
| 6682 | // still VT. |
| 6683 | ExpandOp(Op, Lo, Hi); |
| 6684 | break; |
| 6685 | } |
| 6686 | } |
| 6687 | |
Chris Lattner | 79980b0 | 2006-09-13 03:50:39 +0000 | [diff] [blame] | 6688 | // If ADDC/ADDE are supported and if the shift amount is a constant 1, emit |
| 6689 | // this X << 1 as X+X. |
| 6690 | if (ConstantSDNode *ShAmt = dyn_cast<ConstantSDNode>(ShiftAmt)) { |
Dan Gohman | 002e5d0 | 2008-03-13 22:13:53 +0000 | [diff] [blame] | 6691 | if (ShAmt->getAPIntValue() == 1 && TLI.isOperationLegal(ISD::ADDC, NVT) && |
Chris Lattner | 79980b0 | 2006-09-13 03:50:39 +0000 | [diff] [blame] | 6692 | TLI.isOperationLegal(ISD::ADDE, NVT)) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6693 | SDValue LoOps[2], HiOps[3]; |
Chris Lattner | 79980b0 | 2006-09-13 03:50:39 +0000 | [diff] [blame] | 6694 | ExpandOp(Node->getOperand(0), LoOps[0], HiOps[0]); |
| 6695 | SDVTList VTList = DAG.getVTList(LoOps[0].getValueType(), MVT::Flag); |
| 6696 | LoOps[1] = LoOps[0]; |
| 6697 | Lo = DAG.getNode(ISD::ADDC, VTList, LoOps, 2); |
| 6698 | |
| 6699 | HiOps[1] = HiOps[0]; |
| 6700 | HiOps[2] = Lo.getValue(1); |
| 6701 | Hi = DAG.getNode(ISD::ADDE, VTList, HiOps, 3); |
| 6702 | break; |
| 6703 | } |
| 6704 | } |
| 6705 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6706 | // If we can emit an efficient shift operation, do so now. |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 6707 | if (ExpandShift(ISD::SHL, Node->getOperand(0), ShiftAmt, Lo, Hi)) |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6708 | break; |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 6709 | |
| 6710 | // If this target supports SHL_PARTS, use it. |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 6711 | TargetLowering::LegalizeAction Action = |
| 6712 | TLI.getOperationAction(ISD::SHL_PARTS, NVT); |
| 6713 | if ((Action == TargetLowering::Legal && TLI.isTypeLegal(NVT)) || |
| 6714 | Action == TargetLowering::Custom) { |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 6715 | ExpandShiftParts(ISD::SHL_PARTS, Node->getOperand(0), ShiftAmt, Lo, Hi); |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 6716 | break; |
| 6717 | } |
| 6718 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6719 | // Otherwise, emit a libcall. |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 6720 | Lo = ExpandLibCall(RTLIB::SHL_I64, Node, false/*left shift=unsigned*/, Hi); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6721 | break; |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 6722 | } |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6723 | |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 6724 | case ISD::SRA: { |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6725 | // If the target wants custom lowering, do so. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6726 | SDValue ShiftAmt = LegalizeOp(Node->getOperand(1)); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6727 | if (TLI.getOperationAction(ISD::SRA, VT) == TargetLowering::Custom) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6728 | SDValue Op = DAG.getNode(ISD::SRA, VT, Node->getOperand(0), ShiftAmt); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6729 | Op = TLI.LowerOperation(Op, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6730 | if (Op.getNode()) { |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6731 | // Now that the custom expander is done, expand the result, which is |
| 6732 | // still VT. |
| 6733 | ExpandOp(Op, Lo, Hi); |
| 6734 | break; |
| 6735 | } |
| 6736 | } |
| 6737 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6738 | // If we can emit an efficient shift operation, do so now. |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 6739 | if (ExpandShift(ISD::SRA, Node->getOperand(0), ShiftAmt, Lo, Hi)) |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6740 | break; |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 6741 | |
| 6742 | // If this target supports SRA_PARTS, use it. |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 6743 | TargetLowering::LegalizeAction Action = |
| 6744 | TLI.getOperationAction(ISD::SRA_PARTS, NVT); |
| 6745 | if ((Action == TargetLowering::Legal && TLI.isTypeLegal(NVT)) || |
| 6746 | Action == TargetLowering::Custom) { |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 6747 | ExpandShiftParts(ISD::SRA_PARTS, Node->getOperand(0), ShiftAmt, Lo, Hi); |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 6748 | break; |
| 6749 | } |
| 6750 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6751 | // Otherwise, emit a libcall. |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 6752 | Lo = ExpandLibCall(RTLIB::SRA_I64, Node, true/*ashr is signed*/, Hi); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6753 | break; |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 6754 | } |
| 6755 | |
| 6756 | case ISD::SRL: { |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6757 | // If the target wants custom lowering, do so. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6758 | SDValue ShiftAmt = LegalizeOp(Node->getOperand(1)); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6759 | if (TLI.getOperationAction(ISD::SRL, VT) == TargetLowering::Custom) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6760 | SDValue Op = DAG.getNode(ISD::SRL, VT, Node->getOperand(0), ShiftAmt); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6761 | Op = TLI.LowerOperation(Op, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6762 | if (Op.getNode()) { |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6763 | // Now that the custom expander is done, expand the result, which is |
| 6764 | // still VT. |
| 6765 | ExpandOp(Op, Lo, Hi); |
| 6766 | break; |
| 6767 | } |
| 6768 | } |
| 6769 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6770 | // If we can emit an efficient shift operation, do so now. |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 6771 | if (ExpandShift(ISD::SRL, Node->getOperand(0), ShiftAmt, Lo, Hi)) |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6772 | break; |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 6773 | |
| 6774 | // If this target supports SRL_PARTS, use it. |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 6775 | TargetLowering::LegalizeAction Action = |
| 6776 | TLI.getOperationAction(ISD::SRL_PARTS, NVT); |
| 6777 | if ((Action == TargetLowering::Legal && TLI.isTypeLegal(NVT)) || |
| 6778 | Action == TargetLowering::Custom) { |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 6779 | ExpandShiftParts(ISD::SRL_PARTS, Node->getOperand(0), ShiftAmt, Lo, Hi); |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 6780 | break; |
| 6781 | } |
| 6782 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6783 | // Otherwise, emit a libcall. |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 6784 | Lo = ExpandLibCall(RTLIB::SRL_I64, Node, false/*lshr is unsigned*/, Hi); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6785 | break; |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 6786 | } |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6787 | |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 6788 | case ISD::ADD: |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6789 | case ISD::SUB: { |
| 6790 | // If the target wants to custom expand this, let them. |
| 6791 | if (TLI.getOperationAction(Node->getOpcode(), VT) == |
| 6792 | TargetLowering::Custom) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6793 | SDValue Result = TLI.LowerOperation(Op, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6794 | if (Result.getNode()) { |
Duncan Sands | 69bfb15 | 2008-06-22 09:42:16 +0000 | [diff] [blame] | 6795 | ExpandOp(Result, Lo, Hi); |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6796 | break; |
| 6797 | } |
| 6798 | } |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6799 | // Expand the subcomponents. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6800 | SDValue LHSL, LHSH, RHSL, RHSH; |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6801 | ExpandOp(Node->getOperand(0), LHSL, LHSH); |
| 6802 | ExpandOp(Node->getOperand(1), RHSL, RHSH); |
Chris Lattner | 79980b0 | 2006-09-13 03:50:39 +0000 | [diff] [blame] | 6803 | SDVTList VTList = DAG.getVTList(LHSL.getValueType(), MVT::Flag); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6804 | SDValue LoOps[2], HiOps[3]; |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 6805 | LoOps[0] = LHSL; |
| 6806 | LoOps[1] = RHSL; |
| 6807 | HiOps[0] = LHSH; |
| 6808 | HiOps[1] = RHSH; |
Andrew Lenharth | 2163ca1 | 2008-10-07 18:27:23 +0000 | [diff] [blame] | 6809 | |
Andrew Lenharth | 5c9cc13 | 2008-10-07 17:03:15 +0000 | [diff] [blame] | 6810 | //cascaded check to see if any smaller size has a a carry flag. |
| 6811 | unsigned OpV = Node->getOpcode() == ISD::ADD ? ISD::ADDC : ISD::SUBC; |
| 6812 | bool hasCarry = false; |
Andrew Lenharth | 2163ca1 | 2008-10-07 18:27:23 +0000 | [diff] [blame] | 6813 | for (unsigned BitSize = NVT.getSizeInBits(); BitSize != 0; BitSize /= 2) { |
| 6814 | MVT AVT = MVT::getIntegerVT(BitSize); |
| 6815 | if (TLI.isOperationLegal(OpV, AVT)) { |
| 6816 | hasCarry = true; |
| 6817 | break; |
| 6818 | } |
| 6819 | } |
| 6820 | |
Andrew Lenharth | 5c9cc13 | 2008-10-07 17:03:15 +0000 | [diff] [blame] | 6821 | if(hasCarry) { |
Andrew Lenharth | 40d5139 | 2008-10-07 14:15:42 +0000 | [diff] [blame] | 6822 | if (Node->getOpcode() == ISD::ADD) { |
| 6823 | Lo = DAG.getNode(ISD::ADDC, VTList, LoOps, 2); |
| 6824 | HiOps[2] = Lo.getValue(1); |
| 6825 | Hi = DAG.getNode(ISD::ADDE, VTList, HiOps, 3); |
| 6826 | } else { |
| 6827 | Lo = DAG.getNode(ISD::SUBC, VTList, LoOps, 2); |
| 6828 | HiOps[2] = Lo.getValue(1); |
| 6829 | Hi = DAG.getNode(ISD::SUBE, VTList, HiOps, 3); |
| 6830 | } |
| 6831 | break; |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 6832 | } else { |
Andrew Lenharth | 40d5139 | 2008-10-07 14:15:42 +0000 | [diff] [blame] | 6833 | if (Node->getOpcode() == ISD::ADD) { |
| 6834 | Lo = DAG.getNode(ISD::ADD, VTList, LoOps, 2); |
| 6835 | Hi = DAG.getNode(ISD::ADD, VTList, HiOps, 2); |
Andrew Lenharth | 5c9cc13 | 2008-10-07 17:03:15 +0000 | [diff] [blame] | 6836 | SDValue Cmp1 = DAG.getSetCC(TLI.getSetCCResultType(Lo), |
| 6837 | Lo, LoOps[0], ISD::SETULT); |
Andrew Lenharth | 40d5139 | 2008-10-07 14:15:42 +0000 | [diff] [blame] | 6838 | SDValue Carry1 = DAG.getNode(ISD::SELECT, NVT, Cmp1, |
| 6839 | DAG.getConstant(1, NVT), |
| 6840 | DAG.getConstant(0, NVT)); |
Andrew Lenharth | 5c9cc13 | 2008-10-07 17:03:15 +0000 | [diff] [blame] | 6841 | SDValue Cmp2 = DAG.getSetCC(TLI.getSetCCResultType(Lo), |
| 6842 | Lo, LoOps[1], ISD::SETULT); |
Andrew Lenharth | 40d5139 | 2008-10-07 14:15:42 +0000 | [diff] [blame] | 6843 | SDValue Carry2 = DAG.getNode(ISD::SELECT, NVT, Cmp2, |
| 6844 | DAG.getConstant(1, NVT), |
| 6845 | Carry1); |
| 6846 | Hi = DAG.getNode(ISD::ADD, NVT, Hi, Carry2); |
| 6847 | } else { |
| 6848 | Lo = DAG.getNode(ISD::SUB, VTList, LoOps, 2); |
| 6849 | Hi = DAG.getNode(ISD::SUB, VTList, HiOps, 2); |
| 6850 | SDValue Cmp = DAG.getSetCC(NVT, LoOps[0], LoOps[1], ISD::SETULT); |
| 6851 | SDValue Borrow = DAG.getNode(ISD::SELECT, NVT, Cmp, |
| 6852 | DAG.getConstant(1, NVT), |
| 6853 | DAG.getConstant(0, NVT)); |
| 6854 | Hi = DAG.getNode(ISD::SUB, NVT, Hi, Borrow); |
| 6855 | } |
| 6856 | break; |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 6857 | } |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6858 | } |
Chris Lattner | b429f73 | 2007-05-17 18:15:41 +0000 | [diff] [blame] | 6859 | |
| 6860 | case ISD::ADDC: |
| 6861 | case ISD::SUBC: { |
| 6862 | // Expand the subcomponents. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6863 | SDValue LHSL, LHSH, RHSL, RHSH; |
Chris Lattner | b429f73 | 2007-05-17 18:15:41 +0000 | [diff] [blame] | 6864 | ExpandOp(Node->getOperand(0), LHSL, LHSH); |
| 6865 | ExpandOp(Node->getOperand(1), RHSL, RHSH); |
| 6866 | SDVTList VTList = DAG.getVTList(LHSL.getValueType(), MVT::Flag); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6867 | SDValue LoOps[2] = { LHSL, RHSL }; |
| 6868 | SDValue HiOps[3] = { LHSH, RHSH }; |
Chris Lattner | b429f73 | 2007-05-17 18:15:41 +0000 | [diff] [blame] | 6869 | |
| 6870 | if (Node->getOpcode() == ISD::ADDC) { |
| 6871 | Lo = DAG.getNode(ISD::ADDC, VTList, LoOps, 2); |
| 6872 | HiOps[2] = Lo.getValue(1); |
| 6873 | Hi = DAG.getNode(ISD::ADDE, VTList, HiOps, 3); |
| 6874 | } else { |
| 6875 | Lo = DAG.getNode(ISD::SUBC, VTList, LoOps, 2); |
| 6876 | HiOps[2] = Lo.getValue(1); |
| 6877 | Hi = DAG.getNode(ISD::SUBE, VTList, HiOps, 3); |
| 6878 | } |
| 6879 | // Remember that we legalized the flag. |
| 6880 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Hi.getValue(1))); |
| 6881 | break; |
| 6882 | } |
| 6883 | case ISD::ADDE: |
| 6884 | case ISD::SUBE: { |
| 6885 | // Expand the subcomponents. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6886 | SDValue LHSL, LHSH, RHSL, RHSH; |
Chris Lattner | b429f73 | 2007-05-17 18:15:41 +0000 | [diff] [blame] | 6887 | ExpandOp(Node->getOperand(0), LHSL, LHSH); |
| 6888 | ExpandOp(Node->getOperand(1), RHSL, RHSH); |
| 6889 | SDVTList VTList = DAG.getVTList(LHSL.getValueType(), MVT::Flag); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6890 | SDValue LoOps[3] = { LHSL, RHSL, Node->getOperand(2) }; |
| 6891 | SDValue HiOps[3] = { LHSH, RHSH }; |
Chris Lattner | b429f73 | 2007-05-17 18:15:41 +0000 | [diff] [blame] | 6892 | |
| 6893 | Lo = DAG.getNode(Node->getOpcode(), VTList, LoOps, 3); |
| 6894 | HiOps[2] = Lo.getValue(1); |
| 6895 | Hi = DAG.getNode(Node->getOpcode(), VTList, HiOps, 3); |
| 6896 | |
| 6897 | // Remember that we legalized the flag. |
| 6898 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Hi.getValue(1))); |
| 6899 | break; |
| 6900 | } |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 6901 | case ISD::MUL: { |
Chris Lattner | 7d7bffe | 2006-09-16 00:09:24 +0000 | [diff] [blame] | 6902 | // If the target wants to custom expand this, let them. |
| 6903 | if (TLI.getOperationAction(ISD::MUL, VT) == TargetLowering::Custom) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6904 | SDValue New = TLI.LowerOperation(Op, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6905 | if (New.getNode()) { |
Chris Lattner | 8829dc8 | 2006-09-16 05:08:34 +0000 | [diff] [blame] | 6906 | ExpandOp(New, Lo, Hi); |
Chris Lattner | 7d7bffe | 2006-09-16 00:09:24 +0000 | [diff] [blame] | 6907 | break; |
| 6908 | } |
| 6909 | } |
| 6910 | |
Evan Cheng | 3f4fd0f | 2006-09-01 18:17:58 +0000 | [diff] [blame] | 6911 | bool HasMULHS = TLI.isOperationLegal(ISD::MULHS, NVT); |
| 6912 | bool HasMULHU = TLI.isOperationLegal(ISD::MULHU, NVT); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 6913 | bool HasSMUL_LOHI = TLI.isOperationLegal(ISD::SMUL_LOHI, NVT); |
| 6914 | bool HasUMUL_LOHI = TLI.isOperationLegal(ISD::UMUL_LOHI, NVT); |
| 6915 | if (HasMULHU || HasMULHS || HasUMUL_LOHI || HasSMUL_LOHI) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6916 | SDValue LL, LH, RL, RH; |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 6917 | ExpandOp(Node->getOperand(0), LL, LH); |
| 6918 | ExpandOp(Node->getOperand(1), RL, RH); |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 6919 | unsigned OuterBitSize = Op.getValueSizeInBits(); |
| 6920 | unsigned InnerBitSize = RH.getValueSizeInBits(); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 6921 | unsigned LHSSB = DAG.ComputeNumSignBits(Op.getOperand(0)); |
| 6922 | unsigned RHSSB = DAG.ComputeNumSignBits(Op.getOperand(1)); |
Dan Gohman | 76c605b | 2008-03-10 20:42:19 +0000 | [diff] [blame] | 6923 | APInt HighMask = APInt::getHighBitsSet(OuterBitSize, InnerBitSize); |
| 6924 | if (DAG.MaskedValueIsZero(Node->getOperand(0), HighMask) && |
| 6925 | DAG.MaskedValueIsZero(Node->getOperand(1), HighMask)) { |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 6926 | // The inputs are both zero-extended. |
| 6927 | if (HasUMUL_LOHI) { |
| 6928 | // We can emit a umul_lohi. |
| 6929 | Lo = DAG.getNode(ISD::UMUL_LOHI, DAG.getVTList(NVT, NVT), LL, RL); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6930 | Hi = SDValue(Lo.getNode(), 1); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 6931 | break; |
| 6932 | } |
| 6933 | if (HasMULHU) { |
| 6934 | // We can emit a mulhu+mul. |
| 6935 | Lo = DAG.getNode(ISD::MUL, NVT, LL, RL); |
| 6936 | Hi = DAG.getNode(ISD::MULHU, NVT, LL, RL); |
| 6937 | break; |
| 6938 | } |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 6939 | } |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 6940 | if (LHSSB > InnerBitSize && RHSSB > InnerBitSize) { |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 6941 | // The input values are both sign-extended. |
| 6942 | if (HasSMUL_LOHI) { |
| 6943 | // We can emit a smul_lohi. |
| 6944 | Lo = DAG.getNode(ISD::SMUL_LOHI, DAG.getVTList(NVT, NVT), LL, RL); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6945 | Hi = SDValue(Lo.getNode(), 1); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 6946 | break; |
| 6947 | } |
| 6948 | if (HasMULHS) { |
| 6949 | // We can emit a mulhs+mul. |
| 6950 | Lo = DAG.getNode(ISD::MUL, NVT, LL, RL); |
| 6951 | Hi = DAG.getNode(ISD::MULHS, NVT, LL, RL); |
| 6952 | break; |
| 6953 | } |
| 6954 | } |
| 6955 | if (HasUMUL_LOHI) { |
| 6956 | // Lo,Hi = umul LHS, RHS. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6957 | SDValue UMulLOHI = DAG.getNode(ISD::UMUL_LOHI, |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 6958 | DAG.getVTList(NVT, NVT), LL, RL); |
| 6959 | Lo = UMulLOHI; |
| 6960 | Hi = UMulLOHI.getValue(1); |
Nate Begeman | 56eb868 | 2005-08-30 02:44:00 +0000 | [diff] [blame] | 6961 | RH = DAG.getNode(ISD::MUL, NVT, LL, RH); |
| 6962 | LH = DAG.getNode(ISD::MUL, NVT, LH, RL); |
| 6963 | Hi = DAG.getNode(ISD::ADD, NVT, Hi, RH); |
| 6964 | Hi = DAG.getNode(ISD::ADD, NVT, Hi, LH); |
Chris Lattner | a89654b | 2006-09-16 00:21:44 +0000 | [diff] [blame] | 6965 | break; |
Nate Begeman | 56eb868 | 2005-08-30 02:44:00 +0000 | [diff] [blame] | 6966 | } |
Dale Johannesen | 8eadd5a | 2007-10-24 22:26:08 +0000 | [diff] [blame] | 6967 | if (HasMULHU) { |
| 6968 | Lo = DAG.getNode(ISD::MUL, NVT, LL, RL); |
| 6969 | Hi = DAG.getNode(ISD::MULHU, NVT, LL, RL); |
| 6970 | RH = DAG.getNode(ISD::MUL, NVT, LL, RH); |
| 6971 | LH = DAG.getNode(ISD::MUL, NVT, LH, RL); |
| 6972 | Hi = DAG.getNode(ISD::ADD, NVT, Hi, RH); |
| 6973 | Hi = DAG.getNode(ISD::ADD, NVT, Hi, LH); |
| 6974 | break; |
| 6975 | } |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 6976 | } |
Evan Cheng | 3f4fd0f | 2006-09-01 18:17:58 +0000 | [diff] [blame] | 6977 | |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 6978 | // If nothing else, we can make a libcall. |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 6979 | Lo = ExpandLibCall(RTLIB::MUL_I64, Node, false/*sign irrelevant*/, Hi); |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 6980 | break; |
| 6981 | } |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6982 | case ISD::SDIV: |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 6983 | Lo = ExpandLibCall(RTLIB::SDIV_I64, Node, true, Hi); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6984 | break; |
| 6985 | case ISD::UDIV: |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 6986 | Lo = ExpandLibCall(RTLIB::UDIV_I64, Node, true, Hi); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6987 | break; |
| 6988 | case ISD::SREM: |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 6989 | Lo = ExpandLibCall(RTLIB::SREM_I64, Node, true, Hi); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6990 | break; |
| 6991 | case ISD::UREM: |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 6992 | Lo = ExpandLibCall(RTLIB::UREM_I64, Node, true, Hi); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6993 | break; |
Evan Cheng | 5c9ce18 | 2006-12-12 21:51:17 +0000 | [diff] [blame] | 6994 | |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 6995 | case ISD::FADD: |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 6996 | Lo = ExpandLibCall(GetFPLibCall(VT, RTLIB::ADD_F32, |
| 6997 | RTLIB::ADD_F64, |
| 6998 | RTLIB::ADD_F80, |
| 6999 | RTLIB::ADD_PPCF128), |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 7000 | Node, false, Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 7001 | break; |
| 7002 | case ISD::FSUB: |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 7003 | Lo = ExpandLibCall(GetFPLibCall(VT, RTLIB::SUB_F32, |
| 7004 | RTLIB::SUB_F64, |
| 7005 | RTLIB::SUB_F80, |
| 7006 | RTLIB::SUB_PPCF128), |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 7007 | Node, false, Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 7008 | break; |
| 7009 | case ISD::FMUL: |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 7010 | Lo = ExpandLibCall(GetFPLibCall(VT, RTLIB::MUL_F32, |
| 7011 | RTLIB::MUL_F64, |
| 7012 | RTLIB::MUL_F80, |
| 7013 | RTLIB::MUL_PPCF128), |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 7014 | Node, false, Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 7015 | break; |
| 7016 | case ISD::FDIV: |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 7017 | Lo = ExpandLibCall(GetFPLibCall(VT, RTLIB::DIV_F32, |
| 7018 | RTLIB::DIV_F64, |
| 7019 | RTLIB::DIV_F80, |
| 7020 | RTLIB::DIV_PPCF128), |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 7021 | Node, false, Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 7022 | break; |
Duncan Sands | b2ff885 | 2008-07-17 02:36:29 +0000 | [diff] [blame] | 7023 | case ISD::FP_EXTEND: { |
Dale Johannesen | ca68aaa | 2007-10-12 01:37:08 +0000 | [diff] [blame] | 7024 | if (VT == MVT::ppcf128) { |
| 7025 | assert(Node->getOperand(0).getValueType()==MVT::f32 || |
| 7026 | Node->getOperand(0).getValueType()==MVT::f64); |
| 7027 | const uint64_t zero = 0; |
| 7028 | if (Node->getOperand(0).getValueType()==MVT::f32) |
| 7029 | Hi = DAG.getNode(ISD::FP_EXTEND, MVT::f64, Node->getOperand(0)); |
| 7030 | else |
| 7031 | Hi = Node->getOperand(0); |
| 7032 | Lo = DAG.getConstantFP(APFloat(APInt(64, 1, &zero)), MVT::f64); |
| 7033 | break; |
| 7034 | } |
Duncan Sands | b2ff885 | 2008-07-17 02:36:29 +0000 | [diff] [blame] | 7035 | RTLIB::Libcall LC = RTLIB::getFPEXT(Node->getOperand(0).getValueType(), VT); |
| 7036 | assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported FP_EXTEND!"); |
| 7037 | Lo = ExpandLibCall(LC, Node, true, Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 7038 | break; |
Duncan Sands | b2ff885 | 2008-07-17 02:36:29 +0000 | [diff] [blame] | 7039 | } |
| 7040 | case ISD::FP_ROUND: { |
| 7041 | RTLIB::Libcall LC = RTLIB::getFPROUND(Node->getOperand(0).getValueType(), |
| 7042 | VT); |
| 7043 | assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported FP_ROUND!"); |
| 7044 | Lo = ExpandLibCall(LC, Node, true, Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 7045 | break; |
Duncan Sands | b2ff885 | 2008-07-17 02:36:29 +0000 | [diff] [blame] | 7046 | } |
Evan Cheng | 4b88702 | 2008-09-09 23:02:14 +0000 | [diff] [blame] | 7047 | case ISD::FSQRT: |
| 7048 | case ISD::FSIN: |
| 7049 | case ISD::FCOS: |
Dale Johannesen | 7794f2a | 2008-09-04 00:47:13 +0000 | [diff] [blame] | 7050 | case ISD::FLOG: |
| 7051 | case ISD::FLOG2: |
| 7052 | case ISD::FLOG10: |
| 7053 | case ISD::FEXP: |
| 7054 | case ISD::FEXP2: |
Dan Gohman | 2bb1e3e | 2008-08-21 18:38:14 +0000 | [diff] [blame] | 7055 | case ISD::FTRUNC: |
| 7056 | case ISD::FFLOOR: |
| 7057 | case ISD::FCEIL: |
| 7058 | case ISD::FRINT: |
| 7059 | case ISD::FNEARBYINT: |
Evan Cheng | 9d24ac5 | 2008-09-09 23:35:53 +0000 | [diff] [blame] | 7060 | case ISD::FPOW: |
| 7061 | case ISD::FPOWI: { |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 7062 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
Evan Cheng | 98ff3b9 | 2006-12-13 02:38:13 +0000 | [diff] [blame] | 7063 | switch(Node->getOpcode()) { |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 7064 | case ISD::FSQRT: |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 7065 | LC = GetFPLibCall(VT, RTLIB::SQRT_F32, RTLIB::SQRT_F64, |
| 7066 | RTLIB::SQRT_F80, RTLIB::SQRT_PPCF128); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 7067 | break; |
| 7068 | case ISD::FSIN: |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 7069 | LC = GetFPLibCall(VT, RTLIB::SIN_F32, RTLIB::SIN_F64, |
| 7070 | RTLIB::SIN_F80, RTLIB::SIN_PPCF128); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 7071 | break; |
| 7072 | case ISD::FCOS: |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 7073 | LC = GetFPLibCall(VT, RTLIB::COS_F32, RTLIB::COS_F64, |
| 7074 | RTLIB::COS_F80, RTLIB::COS_PPCF128); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 7075 | break; |
Dale Johannesen | 7794f2a | 2008-09-04 00:47:13 +0000 | [diff] [blame] | 7076 | case ISD::FLOG: |
| 7077 | LC = GetFPLibCall(VT, RTLIB::LOG_F32, RTLIB::LOG_F64, |
| 7078 | RTLIB::LOG_F80, RTLIB::LOG_PPCF128); |
| 7079 | break; |
| 7080 | case ISD::FLOG2: |
| 7081 | LC = GetFPLibCall(VT, RTLIB::LOG2_F32, RTLIB::LOG2_F64, |
| 7082 | RTLIB::LOG2_F80, RTLIB::LOG2_PPCF128); |
| 7083 | break; |
| 7084 | case ISD::FLOG10: |
| 7085 | LC = GetFPLibCall(VT, RTLIB::LOG10_F32, RTLIB::LOG10_F64, |
| 7086 | RTLIB::LOG10_F80, RTLIB::LOG10_PPCF128); |
| 7087 | break; |
| 7088 | case ISD::FEXP: |
| 7089 | LC = GetFPLibCall(VT, RTLIB::EXP_F32, RTLIB::EXP_F64, |
| 7090 | RTLIB::EXP_F80, RTLIB::EXP_PPCF128); |
| 7091 | break; |
| 7092 | case ISD::FEXP2: |
| 7093 | LC = GetFPLibCall(VT, RTLIB::EXP2_F32, RTLIB::EXP2_F64, |
| 7094 | RTLIB::EXP2_F80, RTLIB::EXP2_PPCF128); |
| 7095 | break; |
Dan Gohman | 2bb1e3e | 2008-08-21 18:38:14 +0000 | [diff] [blame] | 7096 | case ISD::FTRUNC: |
| 7097 | LC = GetFPLibCall(VT, RTLIB::TRUNC_F32, RTLIB::TRUNC_F64, |
| 7098 | RTLIB::TRUNC_F80, RTLIB::TRUNC_PPCF128); |
| 7099 | break; |
| 7100 | case ISD::FFLOOR: |
| 7101 | LC = GetFPLibCall(VT, RTLIB::FLOOR_F32, RTLIB::FLOOR_F64, |
| 7102 | RTLIB::FLOOR_F80, RTLIB::FLOOR_PPCF128); |
| 7103 | break; |
| 7104 | case ISD::FCEIL: |
| 7105 | LC = GetFPLibCall(VT, RTLIB::CEIL_F32, RTLIB::CEIL_F64, |
| 7106 | RTLIB::CEIL_F80, RTLIB::CEIL_PPCF128); |
| 7107 | break; |
| 7108 | case ISD::FRINT: |
| 7109 | LC = GetFPLibCall(VT, RTLIB::RINT_F32, RTLIB::RINT_F64, |
| 7110 | RTLIB::RINT_F80, RTLIB::RINT_PPCF128); |
| 7111 | break; |
| 7112 | case ISD::FNEARBYINT: |
| 7113 | LC = GetFPLibCall(VT, RTLIB::NEARBYINT_F32, RTLIB::NEARBYINT_F64, |
| 7114 | RTLIB::NEARBYINT_F80, RTLIB::NEARBYINT_PPCF128); |
| 7115 | break; |
Evan Cheng | 4b88702 | 2008-09-09 23:02:14 +0000 | [diff] [blame] | 7116 | case ISD::FPOW: |
| 7117 | LC = GetFPLibCall(VT, RTLIB::POW_F32, RTLIB::POW_F64, RTLIB::POW_F80, |
| 7118 | RTLIB::POW_PPCF128); |
| 7119 | break; |
| 7120 | case ISD::FPOWI: |
| 7121 | LC = GetFPLibCall(VT, RTLIB::POWI_F32, RTLIB::POWI_F64, RTLIB::POWI_F80, |
| 7122 | RTLIB::POWI_PPCF128); |
| 7123 | break; |
Evan Cheng | 98ff3b9 | 2006-12-13 02:38:13 +0000 | [diff] [blame] | 7124 | default: assert(0 && "Unreachable!"); |
| 7125 | } |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 7126 | Lo = ExpandLibCall(LC, Node, false, Hi); |
Evan Cheng | 98ff3b9 | 2006-12-13 02:38:13 +0000 | [diff] [blame] | 7127 | break; |
| 7128 | } |
Evan Cheng | 966bf24 | 2006-12-16 00:52:40 +0000 | [diff] [blame] | 7129 | case ISD::FABS: { |
Dale Johannesen | f646774 | 2007-10-12 19:02:17 +0000 | [diff] [blame] | 7130 | if (VT == MVT::ppcf128) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7131 | SDValue Tmp; |
Dale Johannesen | f646774 | 2007-10-12 19:02:17 +0000 | [diff] [blame] | 7132 | ExpandOp(Node->getOperand(0), Lo, Tmp); |
| 7133 | Hi = DAG.getNode(ISD::FABS, NVT, Tmp); |
| 7134 | // lo = hi==fabs(hi) ? lo : -lo; |
| 7135 | Lo = DAG.getNode(ISD::SELECT_CC, NVT, Hi, Tmp, |
| 7136 | Lo, DAG.getNode(ISD::FNEG, NVT, Lo), |
| 7137 | DAG.getCondCode(ISD::SETEQ)); |
| 7138 | break; |
| 7139 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7140 | SDValue Mask = (VT == MVT::f64) |
Evan Cheng | 966bf24 | 2006-12-16 00:52:40 +0000 | [diff] [blame] | 7141 | ? DAG.getConstantFP(BitsToDouble(~(1ULL << 63)), VT) |
| 7142 | : DAG.getConstantFP(BitsToFloat(~(1U << 31)), VT); |
| 7143 | Mask = DAG.getNode(ISD::BIT_CONVERT, NVT, Mask); |
| 7144 | Lo = DAG.getNode(ISD::BIT_CONVERT, NVT, Node->getOperand(0)); |
| 7145 | Lo = DAG.getNode(ISD::AND, NVT, Lo, Mask); |
| 7146 | if (getTypeAction(NVT) == Expand) |
| 7147 | ExpandOp(Lo, Lo, Hi); |
| 7148 | break; |
| 7149 | } |
| 7150 | case ISD::FNEG: { |
Dale Johannesen | f646774 | 2007-10-12 19:02:17 +0000 | [diff] [blame] | 7151 | if (VT == MVT::ppcf128) { |
| 7152 | ExpandOp(Node->getOperand(0), Lo, Hi); |
| 7153 | Lo = DAG.getNode(ISD::FNEG, MVT::f64, Lo); |
| 7154 | Hi = DAG.getNode(ISD::FNEG, MVT::f64, Hi); |
| 7155 | break; |
| 7156 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7157 | SDValue Mask = (VT == MVT::f64) |
Evan Cheng | 966bf24 | 2006-12-16 00:52:40 +0000 | [diff] [blame] | 7158 | ? DAG.getConstantFP(BitsToDouble(1ULL << 63), VT) |
| 7159 | : DAG.getConstantFP(BitsToFloat(1U << 31), VT); |
| 7160 | Mask = DAG.getNode(ISD::BIT_CONVERT, NVT, Mask); |
| 7161 | Lo = DAG.getNode(ISD::BIT_CONVERT, NVT, Node->getOperand(0)); |
| 7162 | Lo = DAG.getNode(ISD::XOR, NVT, Lo, Mask); |
| 7163 | if (getTypeAction(NVT) == Expand) |
| 7164 | ExpandOp(Lo, Lo, Hi); |
| 7165 | break; |
| 7166 | } |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 7167 | case ISD::FCOPYSIGN: { |
| 7168 | Lo = ExpandFCOPYSIGNToBitwiseOps(Node, NVT, DAG, TLI); |
| 7169 | if (getTypeAction(NVT) == Expand) |
| 7170 | ExpandOp(Lo, Lo, Hi); |
| 7171 | break; |
| 7172 | } |
Evan Cheng | 7df28dc | 2006-12-19 01:44:04 +0000 | [diff] [blame] | 7173 | case ISD::SINT_TO_FP: |
| 7174 | case ISD::UINT_TO_FP: { |
| 7175 | bool isSigned = Node->getOpcode() == ISD::SINT_TO_FP; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 7176 | MVT SrcVT = Node->getOperand(0).getValueType(); |
Dale Johannesen | cf49819 | 2008-03-18 17:28:38 +0000 | [diff] [blame] | 7177 | |
| 7178 | // Promote the operand if needed. Do this before checking for |
| 7179 | // ppcf128 so conversions of i16 and i8 work. |
| 7180 | if (getTypeAction(SrcVT) == Promote) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7181 | SDValue Tmp = PromoteOp(Node->getOperand(0)); |
Dale Johannesen | cf49819 | 2008-03-18 17:28:38 +0000 | [diff] [blame] | 7182 | Tmp = isSigned |
| 7183 | ? DAG.getNode(ISD::SIGN_EXTEND_INREG, Tmp.getValueType(), Tmp, |
| 7184 | DAG.getValueType(SrcVT)) |
| 7185 | : DAG.getZeroExtendInReg(Tmp, SrcVT); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 7186 | Node = DAG.UpdateNodeOperands(Op, Tmp).getNode(); |
Dale Johannesen | cf49819 | 2008-03-18 17:28:38 +0000 | [diff] [blame] | 7187 | SrcVT = Node->getOperand(0).getValueType(); |
| 7188 | } |
| 7189 | |
Dan Gohman | a2e9485 | 2008-03-10 23:03:31 +0000 | [diff] [blame] | 7190 | if (VT == MVT::ppcf128 && SrcVT == MVT::i32) { |
Dan Gohman | f6283fd | 2008-02-25 21:39:34 +0000 | [diff] [blame] | 7191 | static const uint64_t zero = 0; |
Dale Johannesen | ca68aaa | 2007-10-12 01:37:08 +0000 | [diff] [blame] | 7192 | if (isSigned) { |
| 7193 | Hi = LegalizeOp(DAG.getNode(ISD::SINT_TO_FP, MVT::f64, |
| 7194 | Node->getOperand(0))); |
| 7195 | Lo = DAG.getConstantFP(APFloat(APInt(64, 1, &zero)), MVT::f64); |
| 7196 | } else { |
Dan Gohman | f6283fd | 2008-02-25 21:39:34 +0000 | [diff] [blame] | 7197 | static const uint64_t TwoE32[] = { 0x41f0000000000000LL, 0 }; |
Dale Johannesen | ca68aaa | 2007-10-12 01:37:08 +0000 | [diff] [blame] | 7198 | Hi = LegalizeOp(DAG.getNode(ISD::SINT_TO_FP, MVT::f64, |
| 7199 | Node->getOperand(0))); |
| 7200 | Lo = DAG.getConstantFP(APFloat(APInt(64, 1, &zero)), MVT::f64); |
| 7201 | Hi = DAG.getNode(ISD::BUILD_PAIR, VT, Lo, Hi); |
Dale Johannesen | 6e63e09 | 2007-10-12 17:52:03 +0000 | [diff] [blame] | 7202 | // X>=0 ? {(f64)x, 0} : {(f64)x, 0} + 2^32 |
Dale Johannesen | ca68aaa | 2007-10-12 01:37:08 +0000 | [diff] [blame] | 7203 | ExpandOp(DAG.getNode(ISD::SELECT_CC, MVT::ppcf128, Node->getOperand(0), |
| 7204 | DAG.getConstant(0, MVT::i32), |
| 7205 | DAG.getNode(ISD::FADD, MVT::ppcf128, Hi, |
| 7206 | DAG.getConstantFP( |
| 7207 | APFloat(APInt(128, 2, TwoE32)), |
| 7208 | MVT::ppcf128)), |
| 7209 | Hi, |
| 7210 | DAG.getCondCode(ISD::SETLT)), |
| 7211 | Lo, Hi); |
| 7212 | } |
| 7213 | break; |
| 7214 | } |
Dale Johannesen | 6e63e09 | 2007-10-12 17:52:03 +0000 | [diff] [blame] | 7215 | if (VT == MVT::ppcf128 && SrcVT == MVT::i64 && !isSigned) { |
| 7216 | // si64->ppcf128 done by libcall, below |
Dan Gohman | f6283fd | 2008-02-25 21:39:34 +0000 | [diff] [blame] | 7217 | static const uint64_t TwoE64[] = { 0x43f0000000000000LL, 0 }; |
Dale Johannesen | 6e63e09 | 2007-10-12 17:52:03 +0000 | [diff] [blame] | 7218 | ExpandOp(DAG.getNode(ISD::SINT_TO_FP, MVT::ppcf128, Node->getOperand(0)), |
| 7219 | Lo, Hi); |
| 7220 | Hi = DAG.getNode(ISD::BUILD_PAIR, VT, Lo, Hi); |
| 7221 | // x>=0 ? (ppcf128)(i64)x : (ppcf128)(i64)x + 2^64 |
| 7222 | ExpandOp(DAG.getNode(ISD::SELECT_CC, MVT::ppcf128, Node->getOperand(0), |
| 7223 | DAG.getConstant(0, MVT::i64), |
| 7224 | DAG.getNode(ISD::FADD, MVT::ppcf128, Hi, |
| 7225 | DAG.getConstantFP( |
| 7226 | APFloat(APInt(128, 2, TwoE64)), |
| 7227 | MVT::ppcf128)), |
| 7228 | Hi, |
| 7229 | DAG.getCondCode(ISD::SETLT)), |
| 7230 | Lo, Hi); |
| 7231 | break; |
| 7232 | } |
Evan Cheng | 7df28dc | 2006-12-19 01:44:04 +0000 | [diff] [blame] | 7233 | |
Dan Gohman | a2e9485 | 2008-03-10 23:03:31 +0000 | [diff] [blame] | 7234 | Lo = ExpandIntToFP(Node->getOpcode() == ISD::SINT_TO_FP, VT, |
| 7235 | Node->getOperand(0)); |
Evan Cheng | 110cf48 | 2008-04-01 01:50:16 +0000 | [diff] [blame] | 7236 | if (getTypeAction(Lo.getValueType()) == Expand) |
Evan Cheng | 6ad2f93 | 2008-04-01 01:51:26 +0000 | [diff] [blame] | 7237 | // float to i32 etc. can be 'expanded' to a single node. |
Evan Cheng | 110cf48 | 2008-04-01 01:50:16 +0000 | [diff] [blame] | 7238 | ExpandOp(Lo, Lo, Hi); |
Evan Cheng | 7df28dc | 2006-12-19 01:44:04 +0000 | [diff] [blame] | 7239 | break; |
| 7240 | } |
Evan Cheng | 98ff3b9 | 2006-12-13 02:38:13 +0000 | [diff] [blame] | 7241 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 7242 | |
Chris Lattner | 8339736 | 2005-12-21 18:02:52 +0000 | [diff] [blame] | 7243 | // Make sure the resultant values have been legalized themselves, unless this |
| 7244 | // is a type that requires multi-step expansion. |
| 7245 | if (getTypeAction(NVT) != Expand && NVT != MVT::isVoid) { |
| 7246 | Lo = LegalizeOp(Lo); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 7247 | if (Hi.getNode()) |
Evan Cheng | 13acce3 | 2006-12-11 19:27:14 +0000 | [diff] [blame] | 7248 | // Don't legalize the high part if it is expanded to a single node. |
| 7249 | Hi = LegalizeOp(Hi); |
Chris Lattner | 8339736 | 2005-12-21 18:02:52 +0000 | [diff] [blame] | 7250 | } |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 7251 | |
| 7252 | // Remember in a map if the values will be reused later. |
Dan Gohman | 6b345ee | 2008-07-07 17:46:23 +0000 | [diff] [blame] | 7253 | bool isNew = |
| 7254 | ExpandedNodes.insert(std::make_pair(Op, std::make_pair(Lo, Hi))).second; |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 7255 | assert(isNew && "Value already expanded?!?"); |
Evan Cheng | 24ac408 | 2008-11-24 07:09:49 +0000 | [diff] [blame] | 7256 | isNew = isNew; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 7257 | } |
| 7258 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7259 | /// SplitVectorOp - Given an operand of vector type, break it down into |
| 7260 | /// two smaller values, still of vector type. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7261 | void SelectionDAGLegalize::SplitVectorOp(SDValue Op, SDValue &Lo, |
| 7262 | SDValue &Hi) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 7263 | assert(Op.getValueType().isVector() && "Cannot split non-vector type!"); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 7264 | SDNode *Node = Op.getNode(); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 7265 | unsigned NumElements = Op.getValueType().getVectorNumElements(); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7266 | assert(NumElements > 1 && "Cannot split a single element vector!"); |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7267 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 7268 | MVT NewEltVT = Op.getValueType().getVectorElementType(); |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7269 | |
| 7270 | unsigned NewNumElts_Lo = 1 << Log2_32(NumElements-1); |
| 7271 | unsigned NewNumElts_Hi = NumElements - NewNumElts_Lo; |
| 7272 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 7273 | MVT NewVT_Lo = MVT::getVectorVT(NewEltVT, NewNumElts_Lo); |
| 7274 | MVT NewVT_Hi = MVT::getVectorVT(NewEltVT, NewNumElts_Hi); |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7275 | |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7276 | // See if we already split it. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7277 | std::map<SDValue, std::pair<SDValue, SDValue> >::iterator I |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7278 | = SplitNodes.find(Op); |
| 7279 | if (I != SplitNodes.end()) { |
| 7280 | Lo = I->second.first; |
| 7281 | Hi = I->second.second; |
| 7282 | return; |
| 7283 | } |
| 7284 | |
| 7285 | switch (Node->getOpcode()) { |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 7286 | default: |
| 7287 | #ifndef NDEBUG |
Dan Gohman | 3983358 | 2007-06-04 16:17:33 +0000 | [diff] [blame] | 7288 | Node->dump(&DAG); |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 7289 | #endif |
| 7290 | assert(0 && "Unhandled operation in SplitVectorOp!"); |
Chris Lattner | daf9bc8 | 2007-11-19 20:21:32 +0000 | [diff] [blame] | 7291 | case ISD::UNDEF: |
| 7292 | Lo = DAG.getNode(ISD::UNDEF, NewVT_Lo); |
| 7293 | Hi = DAG.getNode(ISD::UNDEF, NewVT_Hi); |
| 7294 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7295 | case ISD::BUILD_PAIR: |
| 7296 | Lo = Node->getOperand(0); |
| 7297 | Hi = Node->getOperand(1); |
| 7298 | break; |
Dan Gohman | 9fe4662 | 2007-09-28 23:53:40 +0000 | [diff] [blame] | 7299 | case ISD::INSERT_VECTOR_ELT: { |
Nate Begeman | 6867991 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 7300 | if (ConstantSDNode *Idx = dyn_cast<ConstantSDNode>(Node->getOperand(2))) { |
| 7301 | SplitVectorOp(Node->getOperand(0), Lo, Hi); |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 7302 | unsigned Index = Idx->getZExtValue(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7303 | SDValue ScalarOp = Node->getOperand(1); |
Nate Begeman | 6867991 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 7304 | if (Index < NewNumElts_Lo) |
| 7305 | Lo = DAG.getNode(ISD::INSERT_VECTOR_ELT, NewVT_Lo, Lo, ScalarOp, |
| 7306 | DAG.getIntPtrConstant(Index)); |
| 7307 | else |
| 7308 | Hi = DAG.getNode(ISD::INSERT_VECTOR_ELT, NewVT_Hi, Hi, ScalarOp, |
| 7309 | DAG.getIntPtrConstant(Index - NewNumElts_Lo)); |
| 7310 | break; |
| 7311 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7312 | SDValue Tmp = PerformInsertVectorEltInMemory(Node->getOperand(0), |
Nate Begeman | 6867991 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 7313 | Node->getOperand(1), |
| 7314 | Node->getOperand(2)); |
| 7315 | SplitVectorOp(Tmp, Lo, Hi); |
Dan Gohman | 9fe4662 | 2007-09-28 23:53:40 +0000 | [diff] [blame] | 7316 | break; |
| 7317 | } |
Chris Lattner | 6c9c680 | 2007-11-19 21:16:54 +0000 | [diff] [blame] | 7318 | case ISD::VECTOR_SHUFFLE: { |
| 7319 | // Build the low part. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7320 | SDValue Mask = Node->getOperand(2); |
| 7321 | SmallVector<SDValue, 8> Ops; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 7322 | MVT PtrVT = TLI.getPointerTy(); |
Chris Lattner | 6c9c680 | 2007-11-19 21:16:54 +0000 | [diff] [blame] | 7323 | |
| 7324 | // Insert all of the elements from the input that are needed. We use |
| 7325 | // buildvector of extractelement here because the input vectors will have |
| 7326 | // to be legalized, so this makes the code simpler. |
| 7327 | for (unsigned i = 0; i != NewNumElts_Lo; ++i) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7328 | SDValue IdxNode = Mask.getOperand(i); |
Nate Begeman | 5922f56 | 2008-03-14 00:53:31 +0000 | [diff] [blame] | 7329 | if (IdxNode.getOpcode() == ISD::UNDEF) { |
| 7330 | Ops.push_back(DAG.getNode(ISD::UNDEF, NewEltVT)); |
| 7331 | continue; |
| 7332 | } |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 7333 | unsigned Idx = cast<ConstantSDNode>(IdxNode)->getZExtValue(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7334 | SDValue InVec = Node->getOperand(0); |
Chris Lattner | 6c9c680 | 2007-11-19 21:16:54 +0000 | [diff] [blame] | 7335 | if (Idx >= NumElements) { |
| 7336 | InVec = Node->getOperand(1); |
| 7337 | Idx -= NumElements; |
| 7338 | } |
| 7339 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, NewEltVT, InVec, |
| 7340 | DAG.getConstant(Idx, PtrVT))); |
| 7341 | } |
| 7342 | Lo = DAG.getNode(ISD::BUILD_VECTOR, NewVT_Lo, &Ops[0], Ops.size()); |
| 7343 | Ops.clear(); |
| 7344 | |
| 7345 | for (unsigned i = NewNumElts_Lo; i != NumElements; ++i) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7346 | SDValue IdxNode = Mask.getOperand(i); |
Nate Begeman | 5922f56 | 2008-03-14 00:53:31 +0000 | [diff] [blame] | 7347 | if (IdxNode.getOpcode() == ISD::UNDEF) { |
| 7348 | Ops.push_back(DAG.getNode(ISD::UNDEF, NewEltVT)); |
| 7349 | continue; |
| 7350 | } |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 7351 | unsigned Idx = cast<ConstantSDNode>(IdxNode)->getZExtValue(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7352 | SDValue InVec = Node->getOperand(0); |
Chris Lattner | 6c9c680 | 2007-11-19 21:16:54 +0000 | [diff] [blame] | 7353 | if (Idx >= NumElements) { |
| 7354 | InVec = Node->getOperand(1); |
| 7355 | Idx -= NumElements; |
| 7356 | } |
| 7357 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, NewEltVT, InVec, |
| 7358 | DAG.getConstant(Idx, PtrVT))); |
| 7359 | } |
Mon P Wang | 92879f3 | 2008-07-25 01:30:26 +0000 | [diff] [blame] | 7360 | Hi = DAG.getNode(ISD::BUILD_VECTOR, NewVT_Hi, &Ops[0], Ops.size()); |
Chris Lattner | 6c9c680 | 2007-11-19 21:16:54 +0000 | [diff] [blame] | 7361 | break; |
| 7362 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7363 | case ISD::BUILD_VECTOR: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7364 | SmallVector<SDValue, 8> LoOps(Node->op_begin(), |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7365 | Node->op_begin()+NewNumElts_Lo); |
| 7366 | Lo = DAG.getNode(ISD::BUILD_VECTOR, NewVT_Lo, &LoOps[0], LoOps.size()); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7367 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7368 | SmallVector<SDValue, 8> HiOps(Node->op_begin()+NewNumElts_Lo, |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7369 | Node->op_end()); |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7370 | Hi = DAG.getNode(ISD::BUILD_VECTOR, NewVT_Hi, &HiOps[0], HiOps.size()); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7371 | break; |
| 7372 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7373 | case ISD::CONCAT_VECTORS: { |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7374 | // FIXME: Handle non-power-of-two vectors? |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7375 | unsigned NewNumSubvectors = Node->getNumOperands() / 2; |
| 7376 | if (NewNumSubvectors == 1) { |
| 7377 | Lo = Node->getOperand(0); |
| 7378 | Hi = Node->getOperand(1); |
| 7379 | } else { |
Mon P Wang | aeb06d2 | 2008-11-10 04:46:22 +0000 | [diff] [blame] | 7380 | SmallVector<SDValue, 8> LoOps(Node->op_begin(), |
| 7381 | Node->op_begin()+NewNumSubvectors); |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7382 | Lo = DAG.getNode(ISD::CONCAT_VECTORS, NewVT_Lo, &LoOps[0], LoOps.size()); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 7383 | |
Mon P Wang | aeb06d2 | 2008-11-10 04:46:22 +0000 | [diff] [blame] | 7384 | SmallVector<SDValue, 8> HiOps(Node->op_begin()+NewNumSubvectors, |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7385 | Node->op_end()); |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7386 | Hi = DAG.getNode(ISD::CONCAT_VECTORS, NewVT_Hi, &HiOps[0], HiOps.size()); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7387 | } |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 7388 | break; |
| 7389 | } |
Mon P Wang | aeb06d2 | 2008-11-10 04:46:22 +0000 | [diff] [blame] | 7390 | case ISD::EXTRACT_SUBVECTOR: { |
| 7391 | SDValue Vec = Op.getOperand(0); |
| 7392 | SDValue Idx = Op.getOperand(1); |
| 7393 | MVT IdxVT = Idx.getValueType(); |
| 7394 | |
| 7395 | Lo = DAG.getNode(ISD::EXTRACT_SUBVECTOR, NewVT_Lo, Vec, Idx); |
| 7396 | ConstantSDNode *CIdx = dyn_cast<ConstantSDNode>(Idx); |
| 7397 | if (CIdx) { |
| 7398 | Hi = DAG.getNode(ISD::EXTRACT_SUBVECTOR, NewVT_Hi, Vec, |
| 7399 | DAG.getConstant(CIdx->getZExtValue() + NewNumElts_Lo, |
| 7400 | IdxVT)); |
| 7401 | } else { |
| 7402 | Idx = DAG.getNode(ISD::ADD, IdxVT, Idx, |
| 7403 | DAG.getConstant(NewNumElts_Lo, IdxVT)); |
| 7404 | Hi = DAG.getNode(ISD::EXTRACT_SUBVECTOR, NewVT_Hi, Vec, Idx); |
| 7405 | } |
| 7406 | break; |
| 7407 | } |
Dan Gohman | c623096 | 2007-10-17 14:48:28 +0000 | [diff] [blame] | 7408 | case ISD::SELECT: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7409 | SDValue Cond = Node->getOperand(0); |
Dan Gohman | c623096 | 2007-10-17 14:48:28 +0000 | [diff] [blame] | 7410 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7411 | SDValue LL, LH, RL, RH; |
Dan Gohman | c623096 | 2007-10-17 14:48:28 +0000 | [diff] [blame] | 7412 | SplitVectorOp(Node->getOperand(1), LL, LH); |
| 7413 | SplitVectorOp(Node->getOperand(2), RL, RH); |
| 7414 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 7415 | if (Cond.getValueType().isVector()) { |
Dan Gohman | c623096 | 2007-10-17 14:48:28 +0000 | [diff] [blame] | 7416 | // Handle a vector merge. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7417 | SDValue CL, CH; |
Dan Gohman | c623096 | 2007-10-17 14:48:28 +0000 | [diff] [blame] | 7418 | SplitVectorOp(Cond, CL, CH); |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7419 | Lo = DAG.getNode(Node->getOpcode(), NewVT_Lo, CL, LL, RL); |
| 7420 | Hi = DAG.getNode(Node->getOpcode(), NewVT_Hi, CH, LH, RH); |
Dan Gohman | c623096 | 2007-10-17 14:48:28 +0000 | [diff] [blame] | 7421 | } else { |
| 7422 | // Handle a simple select with vector operands. |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7423 | Lo = DAG.getNode(Node->getOpcode(), NewVT_Lo, Cond, LL, RL); |
| 7424 | Hi = DAG.getNode(Node->getOpcode(), NewVT_Hi, Cond, LH, RH); |
Dan Gohman | c623096 | 2007-10-17 14:48:28 +0000 | [diff] [blame] | 7425 | } |
| 7426 | break; |
| 7427 | } |
Chris Lattner | 80c1a56 | 2008-06-30 02:43:01 +0000 | [diff] [blame] | 7428 | case ISD::SELECT_CC: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7429 | SDValue CondLHS = Node->getOperand(0); |
| 7430 | SDValue CondRHS = Node->getOperand(1); |
| 7431 | SDValue CondCode = Node->getOperand(4); |
Chris Lattner | 80c1a56 | 2008-06-30 02:43:01 +0000 | [diff] [blame] | 7432 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7433 | SDValue LL, LH, RL, RH; |
Chris Lattner | 80c1a56 | 2008-06-30 02:43:01 +0000 | [diff] [blame] | 7434 | SplitVectorOp(Node->getOperand(2), LL, LH); |
| 7435 | SplitVectorOp(Node->getOperand(3), RL, RH); |
| 7436 | |
| 7437 | // Handle a simple select with vector operands. |
| 7438 | Lo = DAG.getNode(ISD::SELECT_CC, NewVT_Lo, CondLHS, CondRHS, |
| 7439 | LL, RL, CondCode); |
| 7440 | Hi = DAG.getNode(ISD::SELECT_CC, NewVT_Hi, CondLHS, CondRHS, |
| 7441 | LH, RH, CondCode); |
| 7442 | break; |
| 7443 | } |
Nate Begeman | b43e9c1 | 2008-05-12 19:40:03 +0000 | [diff] [blame] | 7444 | case ISD::VSETCC: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7445 | SDValue LL, LH, RL, RH; |
Nate Begeman | b43e9c1 | 2008-05-12 19:40:03 +0000 | [diff] [blame] | 7446 | SplitVectorOp(Node->getOperand(0), LL, LH); |
| 7447 | SplitVectorOp(Node->getOperand(1), RL, RH); |
| 7448 | Lo = DAG.getNode(ISD::VSETCC, NewVT_Lo, LL, RL, Node->getOperand(2)); |
| 7449 | Hi = DAG.getNode(ISD::VSETCC, NewVT_Hi, LH, RH, Node->getOperand(2)); |
| 7450 | break; |
| 7451 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7452 | case ISD::ADD: |
| 7453 | case ISD::SUB: |
| 7454 | case ISD::MUL: |
| 7455 | case ISD::FADD: |
| 7456 | case ISD::FSUB: |
| 7457 | case ISD::FMUL: |
| 7458 | case ISD::SDIV: |
| 7459 | case ISD::UDIV: |
| 7460 | case ISD::FDIV: |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 7461 | case ISD::FPOW: |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7462 | case ISD::AND: |
| 7463 | case ISD::OR: |
Dan Gohman | 089617d | 2007-11-19 15:15:03 +0000 | [diff] [blame] | 7464 | case ISD::XOR: |
| 7465 | case ISD::UREM: |
| 7466 | case ISD::SREM: |
| 7467 | case ISD::FREM: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7468 | SDValue LL, LH, RL, RH; |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7469 | SplitVectorOp(Node->getOperand(0), LL, LH); |
| 7470 | SplitVectorOp(Node->getOperand(1), RL, RH); |
| 7471 | |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7472 | Lo = DAG.getNode(Node->getOpcode(), NewVT_Lo, LL, RL); |
| 7473 | Hi = DAG.getNode(Node->getOpcode(), NewVT_Hi, LH, RH); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7474 | break; |
| 7475 | } |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 7476 | case ISD::FP_ROUND: |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 7477 | case ISD::FPOWI: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7478 | SDValue L, H; |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 7479 | SplitVectorOp(Node->getOperand(0), L, H); |
| 7480 | |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7481 | Lo = DAG.getNode(Node->getOpcode(), NewVT_Lo, L, Node->getOperand(1)); |
| 7482 | Hi = DAG.getNode(Node->getOpcode(), NewVT_Hi, H, Node->getOperand(1)); |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 7483 | break; |
| 7484 | } |
| 7485 | case ISD::CTTZ: |
| 7486 | case ISD::CTLZ: |
| 7487 | case ISD::CTPOP: |
| 7488 | case ISD::FNEG: |
| 7489 | case ISD::FABS: |
| 7490 | case ISD::FSQRT: |
| 7491 | case ISD::FSIN: |
Nate Begeman | b348d18 | 2007-11-17 03:58:34 +0000 | [diff] [blame] | 7492 | case ISD::FCOS: |
Dale Johannesen | 7794f2a | 2008-09-04 00:47:13 +0000 | [diff] [blame] | 7493 | case ISD::FLOG: |
| 7494 | case ISD::FLOG2: |
| 7495 | case ISD::FLOG10: |
| 7496 | case ISD::FEXP: |
| 7497 | case ISD::FEXP2: |
Nate Begeman | b348d18 | 2007-11-17 03:58:34 +0000 | [diff] [blame] | 7498 | case ISD::FP_TO_SINT: |
| 7499 | case ISD::FP_TO_UINT: |
| 7500 | case ISD::SINT_TO_FP: |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 7501 | case ISD::UINT_TO_FP: |
| 7502 | case ISD::TRUNCATE: |
| 7503 | case ISD::ANY_EXTEND: |
| 7504 | case ISD::SIGN_EXTEND: |
| 7505 | case ISD::ZERO_EXTEND: |
| 7506 | case ISD::FP_EXTEND: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7507 | SDValue L, H; |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 7508 | SplitVectorOp(Node->getOperand(0), L, H); |
| 7509 | |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7510 | Lo = DAG.getNode(Node->getOpcode(), NewVT_Lo, L); |
| 7511 | Hi = DAG.getNode(Node->getOpcode(), NewVT_Hi, H); |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 7512 | break; |
| 7513 | } |
Mon P Wang | 77cdf30 | 2008-11-10 20:54:11 +0000 | [diff] [blame] | 7514 | case ISD::CONVERT_RNDSAT: { |
| 7515 | ISD::CvtCode CvtCode = cast<CvtRndSatSDNode>(Node)->getCvtCode(); |
| 7516 | SDValue L, H; |
| 7517 | SplitVectorOp(Node->getOperand(0), L, H); |
| 7518 | SDValue DTyOpL = DAG.getValueType(NewVT_Lo); |
| 7519 | SDValue DTyOpH = DAG.getValueType(NewVT_Hi); |
| 7520 | SDValue STyOpL = DAG.getValueType(L.getValueType()); |
| 7521 | SDValue STyOpH = DAG.getValueType(H.getValueType()); |
| 7522 | |
| 7523 | SDValue RndOp = Node->getOperand(3); |
| 7524 | SDValue SatOp = Node->getOperand(4); |
| 7525 | |
| 7526 | Lo = DAG.getConvertRndSat(NewVT_Lo, L, DTyOpL, STyOpL, |
| 7527 | RndOp, SatOp, CvtCode); |
| 7528 | Hi = DAG.getConvertRndSat(NewVT_Hi, H, DTyOpH, STyOpH, |
| 7529 | RndOp, SatOp, CvtCode); |
| 7530 | break; |
| 7531 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7532 | case ISD::LOAD: { |
| 7533 | LoadSDNode *LD = cast<LoadSDNode>(Node); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7534 | SDValue Ch = LD->getChain(); |
| 7535 | SDValue Ptr = LD->getBasePtr(); |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 7536 | ISD::LoadExtType ExtType = LD->getExtensionType(); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7537 | const Value *SV = LD->getSrcValue(); |
| 7538 | int SVOffset = LD->getSrcValueOffset(); |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 7539 | MVT MemoryVT = LD->getMemoryVT(); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7540 | unsigned Alignment = LD->getAlignment(); |
| 7541 | bool isVolatile = LD->isVolatile(); |
| 7542 | |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 7543 | assert(LD->isUnindexed() && "Indexed vector loads are not supported yet!"); |
| 7544 | SDValue Offset = DAG.getNode(ISD::UNDEF, Ptr.getValueType()); |
| 7545 | |
| 7546 | MVT MemNewEltVT = MemoryVT.getVectorElementType(); |
| 7547 | MVT MemNewVT_Lo = MVT::getVectorVT(MemNewEltVT, NewNumElts_Lo); |
| 7548 | MVT MemNewVT_Hi = MVT::getVectorVT(MemNewEltVT, NewNumElts_Hi); |
| 7549 | |
| 7550 | Lo = DAG.getLoad(ISD::UNINDEXED, ExtType, |
| 7551 | NewVT_Lo, Ch, Ptr, Offset, |
| 7552 | SV, SVOffset, MemNewVT_Lo, isVolatile, Alignment); |
| 7553 | unsigned IncrementSize = NewNumElts_Lo * MemNewEltVT.getSizeInBits()/8; |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7554 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 7555 | DAG.getIntPtrConstant(IncrementSize)); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7556 | SVOffset += IncrementSize; |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 7557 | Alignment = MinAlign(Alignment, IncrementSize); |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 7558 | Hi = DAG.getLoad(ISD::UNINDEXED, ExtType, |
| 7559 | NewVT_Hi, Ch, Ptr, Offset, |
| 7560 | SV, SVOffset, MemNewVT_Hi, isVolatile, Alignment); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7561 | |
| 7562 | // Build a factor node to remember that this load is independent of the |
| 7563 | // other one. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7564 | SDValue TF = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1), |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7565 | Hi.getValue(1)); |
| 7566 | |
| 7567 | // Remember that we legalized the chain. |
| 7568 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(TF)); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7569 | break; |
| 7570 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7571 | case ISD::BIT_CONVERT: { |
Chris Lattner | 7692eb4 | 2006-03-23 21:16:34 +0000 | [diff] [blame] | 7572 | // We know the result is a vector. The input may be either a vector or a |
| 7573 | // scalar value. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7574 | SDValue InOp = Node->getOperand(0); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 7575 | if (!InOp.getValueType().isVector() || |
| 7576 | InOp.getValueType().getVectorNumElements() == 1) { |
Dan Gohman | 10a7aa6 | 2007-06-29 00:09:08 +0000 | [diff] [blame] | 7577 | // The input is a scalar or single-element vector. |
| 7578 | // Lower to a store/load so that it can be split. |
| 7579 | // FIXME: this could be improved probably. |
Mon P Wang | 2920d2b | 2008-07-15 05:28:34 +0000 | [diff] [blame] | 7580 | unsigned LdAlign = TLI.getTargetData()->getPrefTypeAlignment( |
| 7581 | Op.getValueType().getTypeForMVT()); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7582 | SDValue Ptr = DAG.CreateStackTemporary(InOp.getValueType(), LdAlign); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 7583 | int FI = cast<FrameIndexSDNode>(Ptr.getNode())->getIndex(); |
Chris Lattner | 7692eb4 | 2006-03-23 21:16:34 +0000 | [diff] [blame] | 7584 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7585 | SDValue St = DAG.getStore(DAG.getEntryNode(), |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 7586 | InOp, Ptr, |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 7587 | PseudoSourceValue::getFixedStack(FI), 0); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 7588 | InOp = DAG.getLoad(Op.getValueType(), St, Ptr, |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 7589 | PseudoSourceValue::getFixedStack(FI), 0); |
Chris Lattner | 7692eb4 | 2006-03-23 21:16:34 +0000 | [diff] [blame] | 7590 | } |
Dan Gohman | 10a7aa6 | 2007-06-29 00:09:08 +0000 | [diff] [blame] | 7591 | // Split the vector and convert each of the pieces now. |
| 7592 | SplitVectorOp(InOp, Lo, Hi); |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7593 | Lo = DAG.getNode(ISD::BIT_CONVERT, NewVT_Lo, Lo); |
| 7594 | Hi = DAG.getNode(ISD::BIT_CONVERT, NewVT_Hi, Hi); |
Dan Gohman | 10a7aa6 | 2007-06-29 00:09:08 +0000 | [diff] [blame] | 7595 | break; |
Chris Lattner | 7692eb4 | 2006-03-23 21:16:34 +0000 | [diff] [blame] | 7596 | } |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7597 | } |
| 7598 | |
| 7599 | // Remember in a map if the values will be reused later. |
Chris Lattner | 40030bf | 2007-02-04 01:17:38 +0000 | [diff] [blame] | 7600 | bool isNew = |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7601 | SplitNodes.insert(std::make_pair(Op, std::make_pair(Lo, Hi))).second; |
Dan Gohman | 10a7aa6 | 2007-06-29 00:09:08 +0000 | [diff] [blame] | 7602 | assert(isNew && "Value already split?!?"); |
Evan Cheng | 24ac408 | 2008-11-24 07:09:49 +0000 | [diff] [blame] | 7603 | isNew = isNew; |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7604 | } |
| 7605 | |
| 7606 | |
Dan Gohman | 89b20c0 | 2007-06-27 14:06:22 +0000 | [diff] [blame] | 7607 | /// ScalarizeVectorOp - Given an operand of single-element vector type |
| 7608 | /// (e.g. v1f32), convert it into the equivalent operation that returns a |
| 7609 | /// scalar (e.g. f32) value. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7610 | SDValue SelectionDAGLegalize::ScalarizeVectorOp(SDValue Op) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 7611 | assert(Op.getValueType().isVector() && "Bad ScalarizeVectorOp invocation!"); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 7612 | SDNode *Node = Op.getNode(); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 7613 | MVT NewVT = Op.getValueType().getVectorElementType(); |
| 7614 | assert(Op.getValueType().getVectorNumElements() == 1); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7615 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7616 | // See if we already scalarized it. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7617 | std::map<SDValue, SDValue>::iterator I = ScalarizedNodes.find(Op); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7618 | if (I != ScalarizedNodes.end()) return I->second; |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7619 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7620 | SDValue Result; |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7621 | switch (Node->getOpcode()) { |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 7622 | default: |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 7623 | #ifndef NDEBUG |
Dan Gohman | 3983358 | 2007-06-04 16:17:33 +0000 | [diff] [blame] | 7624 | Node->dump(&DAG); cerr << "\n"; |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 7625 | #endif |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7626 | assert(0 && "Unknown vector operation in ScalarizeVectorOp!"); |
| 7627 | case ISD::ADD: |
| 7628 | case ISD::FADD: |
| 7629 | case ISD::SUB: |
| 7630 | case ISD::FSUB: |
| 7631 | case ISD::MUL: |
| 7632 | case ISD::FMUL: |
| 7633 | case ISD::SDIV: |
| 7634 | case ISD::UDIV: |
| 7635 | case ISD::FDIV: |
| 7636 | case ISD::SREM: |
| 7637 | case ISD::UREM: |
| 7638 | case ISD::FREM: |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 7639 | case ISD::FPOW: |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7640 | case ISD::AND: |
| 7641 | case ISD::OR: |
| 7642 | case ISD::XOR: |
| 7643 | Result = DAG.getNode(Node->getOpcode(), |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7644 | NewVT, |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7645 | ScalarizeVectorOp(Node->getOperand(0)), |
| 7646 | ScalarizeVectorOp(Node->getOperand(1))); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7647 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7648 | case ISD::FNEG: |
| 7649 | case ISD::FABS: |
| 7650 | case ISD::FSQRT: |
| 7651 | case ISD::FSIN: |
| 7652 | case ISD::FCOS: |
Dale Johannesen | 7794f2a | 2008-09-04 00:47:13 +0000 | [diff] [blame] | 7653 | case ISD::FLOG: |
| 7654 | case ISD::FLOG2: |
| 7655 | case ISD::FLOG10: |
| 7656 | case ISD::FEXP: |
| 7657 | case ISD::FEXP2: |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 7658 | case ISD::FP_TO_SINT: |
| 7659 | case ISD::FP_TO_UINT: |
| 7660 | case ISD::SINT_TO_FP: |
| 7661 | case ISD::UINT_TO_FP: |
| 7662 | case ISD::SIGN_EXTEND: |
| 7663 | case ISD::ZERO_EXTEND: |
| 7664 | case ISD::ANY_EXTEND: |
| 7665 | case ISD::TRUNCATE: |
| 7666 | case ISD::FP_EXTEND: |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7667 | Result = DAG.getNode(Node->getOpcode(), |
| 7668 | NewVT, |
| 7669 | ScalarizeVectorOp(Node->getOperand(0))); |
| 7670 | break; |
Mon P Wang | 77cdf30 | 2008-11-10 20:54:11 +0000 | [diff] [blame] | 7671 | case ISD::CONVERT_RNDSAT: { |
| 7672 | SDValue Op0 = ScalarizeVectorOp(Node->getOperand(0)); |
| 7673 | Result = DAG.getConvertRndSat(NewVT, Op0, |
| 7674 | DAG.getValueType(NewVT), |
| 7675 | DAG.getValueType(Op0.getValueType()), |
| 7676 | Node->getOperand(3), |
| 7677 | Node->getOperand(4), |
| 7678 | cast<CvtRndSatSDNode>(Node)->getCvtCode()); |
| 7679 | break; |
| 7680 | } |
Dan Gohman | 9e04c82 | 2007-10-12 14:13:46 +0000 | [diff] [blame] | 7681 | case ISD::FPOWI: |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 7682 | case ISD::FP_ROUND: |
Dan Gohman | 9e04c82 | 2007-10-12 14:13:46 +0000 | [diff] [blame] | 7683 | Result = DAG.getNode(Node->getOpcode(), |
| 7684 | NewVT, |
| 7685 | ScalarizeVectorOp(Node->getOperand(0)), |
| 7686 | Node->getOperand(1)); |
| 7687 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7688 | case ISD::LOAD: { |
| 7689 | LoadSDNode *LD = cast<LoadSDNode>(Node); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7690 | SDValue Ch = LegalizeOp(LD->getChain()); // Legalize the chain. |
| 7691 | SDValue Ptr = LegalizeOp(LD->getBasePtr()); // Legalize the pointer. |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 7692 | ISD::LoadExtType ExtType = LD->getExtensionType(); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7693 | const Value *SV = LD->getSrcValue(); |
| 7694 | int SVOffset = LD->getSrcValueOffset(); |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 7695 | MVT MemoryVT = LD->getMemoryVT(); |
| 7696 | unsigned Alignment = LD->getAlignment(); |
| 7697 | bool isVolatile = LD->isVolatile(); |
| 7698 | |
| 7699 | assert(LD->isUnindexed() && "Indexed vector loads are not supported yet!"); |
| 7700 | SDValue Offset = DAG.getNode(ISD::UNDEF, Ptr.getValueType()); |
| 7701 | |
| 7702 | Result = DAG.getLoad(ISD::UNINDEXED, ExtType, |
| 7703 | NewVT, Ch, Ptr, Offset, SV, SVOffset, |
| 7704 | MemoryVT.getVectorElementType(), |
| 7705 | isVolatile, Alignment); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7706 | |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7707 | // Remember that we legalized the chain. |
| 7708 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1))); |
| 7709 | break; |
| 7710 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7711 | case ISD::BUILD_VECTOR: |
| 7712 | Result = Node->getOperand(0); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7713 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7714 | case ISD::INSERT_VECTOR_ELT: |
| 7715 | // Returning the inserted scalar element. |
| 7716 | Result = Node->getOperand(1); |
| 7717 | break; |
| 7718 | case ISD::CONCAT_VECTORS: |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 7719 | assert(Node->getOperand(0).getValueType() == NewVT && |
| 7720 | "Concat of non-legal vectors not yet supported!"); |
| 7721 | Result = Node->getOperand(0); |
| 7722 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7723 | case ISD::VECTOR_SHUFFLE: { |
| 7724 | // Figure out if the scalar is the LHS or RHS and return it. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7725 | SDValue EltNum = Node->getOperand(2).getOperand(0); |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 7726 | if (cast<ConstantSDNode>(EltNum)->getZExtValue()) |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7727 | Result = ScalarizeVectorOp(Node->getOperand(1)); |
| 7728 | else |
| 7729 | Result = ScalarizeVectorOp(Node->getOperand(0)); |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 7730 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7731 | } |
| 7732 | case ISD::EXTRACT_SUBVECTOR: |
Mon P Wang | e0b436a | 2008-11-06 22:52:21 +0000 | [diff] [blame] | 7733 | Result = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, NewVT, Node->getOperand(0), |
Mon P Wang | aeb06d2 | 2008-11-10 04:46:22 +0000 | [diff] [blame] | 7734 | Node->getOperand(1)); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 7735 | break; |
Evan Cheng | 446efdd | 2008-05-16 17:19:05 +0000 | [diff] [blame] | 7736 | case ISD::BIT_CONVERT: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7737 | SDValue Op0 = Op.getOperand(0); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 7738 | if (Op0.getValueType().getVectorNumElements() == 1) |
Evan Cheng | 446efdd | 2008-05-16 17:19:05 +0000 | [diff] [blame] | 7739 | Op0 = ScalarizeVectorOp(Op0); |
| 7740 | Result = DAG.getNode(ISD::BIT_CONVERT, NewVT, Op0); |
Chris Lattner | 5b2316e | 2006-03-28 20:24:43 +0000 | [diff] [blame] | 7741 | break; |
Evan Cheng | 446efdd | 2008-05-16 17:19:05 +0000 | [diff] [blame] | 7742 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7743 | case ISD::SELECT: |
Chris Lattner | b22e35a | 2006-04-08 22:22:57 +0000 | [diff] [blame] | 7744 | Result = DAG.getNode(ISD::SELECT, NewVT, Op.getOperand(0), |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7745 | ScalarizeVectorOp(Op.getOperand(1)), |
| 7746 | ScalarizeVectorOp(Op.getOperand(2))); |
Chris Lattner | b22e35a | 2006-04-08 22:22:57 +0000 | [diff] [blame] | 7747 | break; |
Chris Lattner | 80c1a56 | 2008-06-30 02:43:01 +0000 | [diff] [blame] | 7748 | case ISD::SELECT_CC: |
| 7749 | Result = DAG.getNode(ISD::SELECT_CC, NewVT, Node->getOperand(0), |
| 7750 | Node->getOperand(1), |
| 7751 | ScalarizeVectorOp(Op.getOperand(2)), |
| 7752 | ScalarizeVectorOp(Op.getOperand(3)), |
| 7753 | Node->getOperand(4)); |
| 7754 | break; |
Nate Begeman | 0d1704b | 2008-05-12 23:09:43 +0000 | [diff] [blame] | 7755 | case ISD::VSETCC: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7756 | SDValue Op0 = ScalarizeVectorOp(Op.getOperand(0)); |
| 7757 | SDValue Op1 = ScalarizeVectorOp(Op.getOperand(1)); |
Nate Begeman | 0d1704b | 2008-05-12 23:09:43 +0000 | [diff] [blame] | 7758 | Result = DAG.getNode(ISD::SETCC, TLI.getSetCCResultType(Op0), Op0, Op1, |
| 7759 | Op.getOperand(2)); |
| 7760 | Result = DAG.getNode(ISD::SELECT, NewVT, Result, |
| 7761 | DAG.getConstant(-1ULL, NewVT), |
| 7762 | DAG.getConstant(0ULL, NewVT)); |
| 7763 | break; |
| 7764 | } |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7765 | } |
| 7766 | |
| 7767 | if (TLI.isTypeLegal(NewVT)) |
| 7768 | Result = LegalizeOp(Result); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7769 | bool isNew = ScalarizedNodes.insert(std::make_pair(Op, Result)).second; |
| 7770 | assert(isNew && "Value already scalarized?"); |
Evan Cheng | 24ac408 | 2008-11-24 07:09:49 +0000 | [diff] [blame] | 7771 | isNew = isNew; |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7772 | return Result; |
| 7773 | } |
| 7774 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 7775 | |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 7776 | SDValue SelectionDAGLegalize::WidenVectorOp(SDValue Op, MVT WidenVT) { |
| 7777 | std::map<SDValue, SDValue>::iterator I = WidenNodes.find(Op); |
| 7778 | if (I != WidenNodes.end()) return I->second; |
| 7779 | |
| 7780 | MVT VT = Op.getValueType(); |
| 7781 | assert(VT.isVector() && "Cannot widen non-vector type!"); |
| 7782 | |
| 7783 | SDValue Result; |
| 7784 | SDNode *Node = Op.getNode(); |
| 7785 | MVT EVT = VT.getVectorElementType(); |
| 7786 | |
| 7787 | unsigned NumElts = VT.getVectorNumElements(); |
| 7788 | unsigned NewNumElts = WidenVT.getVectorNumElements(); |
| 7789 | assert(NewNumElts > NumElts && "Cannot widen to smaller type!"); |
| 7790 | assert(NewNumElts < 17); |
| 7791 | |
| 7792 | // When widen is called, it is assumed that it is more efficient to use a |
| 7793 | // wide type. The default action is to widen to operation to a wider legal |
| 7794 | // vector type and then do the operation if it is legal by calling LegalizeOp |
| 7795 | // again. If there is no vector equivalent, we will unroll the operation, do |
| 7796 | // it, and rebuild the vector. If most of the operations are vectorizible to |
| 7797 | // the legal type, the resulting code will be more efficient. If this is not |
| 7798 | // the case, the resulting code will preform badly as we end up generating |
| 7799 | // code to pack/unpack the results. It is the function that calls widen |
Mon P Wang | f007a8b | 2008-11-06 05:31:54 +0000 | [diff] [blame] | 7800 | // that is responsible for seeing this doesn't happen. |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 7801 | switch (Node->getOpcode()) { |
| 7802 | default: |
| 7803 | #ifndef NDEBUG |
| 7804 | Node->dump(&DAG); |
| 7805 | #endif |
| 7806 | assert(0 && "Unexpected operation in WidenVectorOp!"); |
| 7807 | break; |
| 7808 | case ISD::CopyFromReg: |
Mon P Wang | 49292f1 | 2008-11-15 06:05:52 +0000 | [diff] [blame] | 7809 | assert(0 && "CopyFromReg doesn't need widening!"); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 7810 | case ISD::Constant: |
| 7811 | case ISD::ConstantFP: |
| 7812 | // To build a vector of these elements, clients should call BuildVector |
| 7813 | // and with each element instead of creating a node with a vector type |
| 7814 | assert(0 && "Unexpected operation in WidenVectorOp!"); |
| 7815 | case ISD::VAARG: |
| 7816 | // Variable Arguments with vector types doesn't make any sense to me |
| 7817 | assert(0 && "Unexpected operation in WidenVectorOp!"); |
| 7818 | break; |
Mon P Wang | 49292f1 | 2008-11-15 06:05:52 +0000 | [diff] [blame] | 7819 | case ISD::UNDEF: |
| 7820 | Result = DAG.getNode(ISD::UNDEF, WidenVT); |
| 7821 | break; |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 7822 | case ISD::BUILD_VECTOR: { |
| 7823 | // Build a vector with undefined for the new nodes |
| 7824 | SDValueVector NewOps(Node->op_begin(), Node->op_end()); |
| 7825 | for (unsigned i = NumElts; i < NewNumElts; ++i) { |
| 7826 | NewOps.push_back(DAG.getNode(ISD::UNDEF,EVT)); |
| 7827 | } |
| 7828 | Result = DAG.getNode(ISD::BUILD_VECTOR, WidenVT, &NewOps[0], NewOps.size()); |
| 7829 | break; |
| 7830 | } |
| 7831 | case ISD::INSERT_VECTOR_ELT: { |
| 7832 | SDValue Tmp1 = WidenVectorOp(Node->getOperand(0), WidenVT); |
| 7833 | Result = DAG.getNode(ISD::INSERT_VECTOR_ELT, WidenVT, Tmp1, |
| 7834 | Node->getOperand(1), Node->getOperand(2)); |
| 7835 | break; |
| 7836 | } |
| 7837 | case ISD::VECTOR_SHUFFLE: { |
| 7838 | SDValue Tmp1 = WidenVectorOp(Node->getOperand(0), WidenVT); |
| 7839 | SDValue Tmp2 = WidenVectorOp(Node->getOperand(1), WidenVT); |
| 7840 | // VECTOR_SHUFFLE 3rd operand must be a constant build vector that is |
| 7841 | // used as permutation array. We build the vector here instead of widening |
| 7842 | // because we don't want to legalize and have it turned to something else. |
| 7843 | SDValue PermOp = Node->getOperand(2); |
| 7844 | SDValueVector NewOps; |
| 7845 | MVT PVT = PermOp.getValueType().getVectorElementType(); |
| 7846 | for (unsigned i = 0; i < NumElts; ++i) { |
| 7847 | if (PermOp.getOperand(i).getOpcode() == ISD::UNDEF) { |
| 7848 | NewOps.push_back(PermOp.getOperand(i)); |
| 7849 | } else { |
| 7850 | unsigned Idx = |
| 7851 | cast<ConstantSDNode>(PermOp.getOperand(i))->getZExtValue(); |
| 7852 | if (Idx < NumElts) { |
| 7853 | NewOps.push_back(PermOp.getOperand(i)); |
| 7854 | } |
| 7855 | else { |
| 7856 | NewOps.push_back(DAG.getConstant(Idx + NewNumElts - NumElts, |
| 7857 | PermOp.getOperand(i).getValueType())); |
| 7858 | } |
| 7859 | } |
| 7860 | } |
| 7861 | for (unsigned i = NumElts; i < NewNumElts; ++i) { |
| 7862 | NewOps.push_back(DAG.getNode(ISD::UNDEF,PVT)); |
| 7863 | } |
| 7864 | |
| 7865 | SDValue Tmp3 = DAG.getNode(ISD::BUILD_VECTOR, |
| 7866 | MVT::getVectorVT(PVT, NewOps.size()), |
| 7867 | &NewOps[0], NewOps.size()); |
| 7868 | |
| 7869 | Result = DAG.getNode(ISD::VECTOR_SHUFFLE, WidenVT, Tmp1, Tmp2, Tmp3); |
| 7870 | break; |
| 7871 | } |
| 7872 | case ISD::LOAD: { |
| 7873 | // If the load widen returns true, we can use a single load for the |
| 7874 | // vector. Otherwise, it is returning a token factor for multiple |
| 7875 | // loads. |
| 7876 | SDValue TFOp; |
| 7877 | if (LoadWidenVectorOp(Result, TFOp, Op, WidenVT)) |
| 7878 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(TFOp.getValue(1))); |
| 7879 | else |
| 7880 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(TFOp.getValue(0))); |
| 7881 | break; |
| 7882 | } |
| 7883 | |
| 7884 | case ISD::BIT_CONVERT: { |
| 7885 | SDValue Tmp1 = Node->getOperand(0); |
| 7886 | // Converts between two different types so we need to determine |
| 7887 | // the correct widen type for the input operand. |
| 7888 | MVT TVT = Tmp1.getValueType(); |
| 7889 | assert(TVT.isVector() && "can not widen non vector type"); |
| 7890 | MVT TEVT = TVT.getVectorElementType(); |
| 7891 | assert(WidenVT.getSizeInBits() % EVT.getSizeInBits() == 0 && |
| 7892 | "can not widen bit bit convert that are not multiple of element type"); |
| 7893 | MVT TWidenVT = MVT::getVectorVT(TEVT, |
| 7894 | WidenVT.getSizeInBits()/EVT.getSizeInBits()); |
| 7895 | Tmp1 = WidenVectorOp(Tmp1, TWidenVT); |
| 7896 | assert(Tmp1.getValueType().getSizeInBits() == WidenVT.getSizeInBits()); |
| 7897 | Result = DAG.getNode(Node->getOpcode(), WidenVT, Tmp1); |
| 7898 | |
| 7899 | TargetLowering::LegalizeAction action = |
| 7900 | TLI.getOperationAction(Node->getOpcode(), WidenVT); |
| 7901 | switch (action) { |
| 7902 | default: assert(0 && "action not supported"); |
| 7903 | case TargetLowering::Legal: |
| 7904 | break; |
| 7905 | case TargetLowering::Promote: |
| 7906 | // We defer the promotion to when we legalize the op |
| 7907 | break; |
| 7908 | case TargetLowering::Expand: |
| 7909 | // Expand the operation into a bunch of nasty scalar code. |
| 7910 | Result = LegalizeOp(UnrollVectorOp(Result)); |
| 7911 | break; |
| 7912 | } |
| 7913 | break; |
| 7914 | } |
| 7915 | |
| 7916 | case ISD::SINT_TO_FP: |
| 7917 | case ISD::UINT_TO_FP: |
| 7918 | case ISD::FP_TO_SINT: |
| 7919 | case ISD::FP_TO_UINT: { |
| 7920 | SDValue Tmp1 = Node->getOperand(0); |
| 7921 | // Converts between two different types so we need to determine |
| 7922 | // the correct widen type for the input operand. |
| 7923 | MVT TVT = Tmp1.getValueType(); |
| 7924 | assert(TVT.isVector() && "can not widen non vector type"); |
| 7925 | MVT TEVT = TVT.getVectorElementType(); |
| 7926 | MVT TWidenVT = MVT::getVectorVT(TEVT, NewNumElts); |
| 7927 | Tmp1 = WidenVectorOp(Tmp1, TWidenVT); |
| 7928 | assert(Tmp1.getValueType().getVectorNumElements() == NewNumElts); |
| 7929 | Result = DAG.getNode(Node->getOpcode(), WidenVT, Tmp1); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 7930 | break; |
| 7931 | } |
| 7932 | |
| 7933 | case ISD::FP_EXTEND: |
| 7934 | assert(0 && "Case not implemented. Dynamically dead with 2 FP types!"); |
| 7935 | case ISD::TRUNCATE: |
| 7936 | case ISD::SIGN_EXTEND: |
| 7937 | case ISD::ZERO_EXTEND: |
| 7938 | case ISD::ANY_EXTEND: |
| 7939 | case ISD::FP_ROUND: |
| 7940 | case ISD::SIGN_EXTEND_INREG: |
| 7941 | case ISD::FABS: |
| 7942 | case ISD::FNEG: |
| 7943 | case ISD::FSQRT: |
| 7944 | case ISD::FSIN: |
Mon P Wang | 49292f1 | 2008-11-15 06:05:52 +0000 | [diff] [blame] | 7945 | case ISD::FCOS: |
| 7946 | case ISD::CTPOP: |
| 7947 | case ISD::CTTZ: |
| 7948 | case ISD::CTLZ: { |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 7949 | // Unary op widening |
| 7950 | SDValue Tmp1; |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 7951 | Tmp1 = WidenVectorOp(Node->getOperand(0), WidenVT); |
| 7952 | assert(Tmp1.getValueType() == WidenVT); |
| 7953 | Result = DAG.getNode(Node->getOpcode(), WidenVT, Tmp1); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 7954 | break; |
| 7955 | } |
Mon P Wang | 77cdf30 | 2008-11-10 20:54:11 +0000 | [diff] [blame] | 7956 | case ISD::CONVERT_RNDSAT: { |
| 7957 | SDValue RndOp = Node->getOperand(3); |
| 7958 | SDValue SatOp = Node->getOperand(4); |
Mon P Wang | 77cdf30 | 2008-11-10 20:54:11 +0000 | [diff] [blame] | 7959 | SDValue SrcOp = Node->getOperand(0); |
| 7960 | |
| 7961 | // Converts between two different types so we need to determine |
| 7962 | // the correct widen type for the input operand. |
| 7963 | MVT SVT = SrcOp.getValueType(); |
| 7964 | assert(SVT.isVector() && "can not widen non vector type"); |
| 7965 | MVT SEVT = SVT.getVectorElementType(); |
| 7966 | MVT SWidenVT = MVT::getVectorVT(SEVT, NewNumElts); |
| 7967 | |
| 7968 | SrcOp = WidenVectorOp(SrcOp, SWidenVT); |
| 7969 | assert(SrcOp.getValueType() == WidenVT); |
| 7970 | SDValue DTyOp = DAG.getValueType(WidenVT); |
| 7971 | SDValue STyOp = DAG.getValueType(SrcOp.getValueType()); |
| 7972 | ISD::CvtCode CvtCode = cast<CvtRndSatSDNode>(Node)->getCvtCode(); |
| 7973 | |
| 7974 | Result = DAG.getConvertRndSat(WidenVT, SrcOp, DTyOp, STyOp, |
| 7975 | RndOp, SatOp, CvtCode); |
Mon P Wang | 77cdf30 | 2008-11-10 20:54:11 +0000 | [diff] [blame] | 7976 | break; |
| 7977 | } |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 7978 | case ISD::FPOW: |
| 7979 | case ISD::FPOWI: |
| 7980 | case ISD::ADD: |
| 7981 | case ISD::SUB: |
| 7982 | case ISD::MUL: |
| 7983 | case ISD::MULHS: |
| 7984 | case ISD::MULHU: |
| 7985 | case ISD::AND: |
| 7986 | case ISD::OR: |
| 7987 | case ISD::XOR: |
| 7988 | case ISD::FADD: |
| 7989 | case ISD::FSUB: |
| 7990 | case ISD::FMUL: |
| 7991 | case ISD::SDIV: |
| 7992 | case ISD::SREM: |
| 7993 | case ISD::FDIV: |
| 7994 | case ISD::FREM: |
| 7995 | case ISD::FCOPYSIGN: |
| 7996 | case ISD::UDIV: |
| 7997 | case ISD::UREM: |
| 7998 | case ISD::BSWAP: { |
| 7999 | // Binary op widening |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8000 | SDValue Tmp1 = WidenVectorOp(Node->getOperand(0), WidenVT); |
| 8001 | SDValue Tmp2 = WidenVectorOp(Node->getOperand(1), WidenVT); |
| 8002 | assert(Tmp1.getValueType() == WidenVT && Tmp2.getValueType() == WidenVT); |
| 8003 | Result = DAG.getNode(Node->getOpcode(), WidenVT, Tmp1, Tmp2); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8004 | break; |
| 8005 | } |
| 8006 | |
| 8007 | case ISD::SHL: |
| 8008 | case ISD::SRA: |
| 8009 | case ISD::SRL: { |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8010 | SDValue Tmp1 = WidenVectorOp(Node->getOperand(0), WidenVT); |
| 8011 | assert(Tmp1.getValueType() == WidenVT); |
Mon P Wang | fb13f00 | 2008-12-02 07:35:08 +0000 | [diff] [blame^] | 8012 | SDValue ShOp = Node->getOperand(1); |
| 8013 | MVT ShVT = ShOp.getValueType(); |
| 8014 | MVT NewShVT = MVT::getVectorVT(ShVT.getVectorElementType(), |
| 8015 | WidenVT.getVectorNumElements()); |
| 8016 | ShOp = WidenVectorOp(ShOp, NewShVT); |
| 8017 | assert(ShOp.getValueType() == NewShVT); |
| 8018 | Result = DAG.getNode(Node->getOpcode(), WidenVT, Tmp1, ShOp); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8019 | break; |
| 8020 | } |
Mon P Wang | fb13f00 | 2008-12-02 07:35:08 +0000 | [diff] [blame^] | 8021 | |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8022 | case ISD::EXTRACT_VECTOR_ELT: { |
| 8023 | SDValue Tmp1 = WidenVectorOp(Node->getOperand(0), WidenVT); |
| 8024 | assert(Tmp1.getValueType() == WidenVT); |
| 8025 | Result = DAG.getNode(Node->getOpcode(), EVT, Tmp1, Node->getOperand(1)); |
| 8026 | break; |
| 8027 | } |
| 8028 | case ISD::CONCAT_VECTORS: { |
| 8029 | // We concurrently support only widen on a multiple of the incoming vector. |
| 8030 | // We could widen on a multiple of the incoming operand if necessary. |
| 8031 | unsigned NumConcat = NewNumElts / NumElts; |
| 8032 | assert(NewNumElts % NumElts == 0 && "Can widen only a multiple of vector"); |
Mon P Wang | fb13f00 | 2008-12-02 07:35:08 +0000 | [diff] [blame^] | 8033 | SDValue UndefVal = DAG.getNode(ISD::UNDEF, VT); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8034 | SmallVector<SDValue, 8> MOps; |
| 8035 | MOps.push_back(Op); |
| 8036 | for (unsigned i = 1; i != NumConcat; ++i) { |
| 8037 | MOps.push_back(UndefVal); |
| 8038 | } |
| 8039 | Result = LegalizeOp(DAG.getNode(ISD::CONCAT_VECTORS, WidenVT, |
| 8040 | &MOps[0], MOps.size())); |
| 8041 | break; |
| 8042 | } |
| 8043 | case ISD::EXTRACT_SUBVECTOR: { |
Mon P Wang | 49292f1 | 2008-11-15 06:05:52 +0000 | [diff] [blame] | 8044 | SDValue Tmp1 = Node->getOperand(0); |
| 8045 | SDValue Idx = Node->getOperand(1); |
| 8046 | ConstantSDNode *CIdx = dyn_cast<ConstantSDNode>(Idx); |
| 8047 | if (CIdx && CIdx->getZExtValue() == 0) { |
| 8048 | // Since we are access the start of the vector, the incoming |
| 8049 | // vector type might be the proper. |
| 8050 | MVT Tmp1VT = Tmp1.getValueType(); |
| 8051 | if (Tmp1VT == WidenVT) |
| 8052 | return Tmp1; |
| 8053 | else { |
| 8054 | unsigned Tmp1VTNumElts = Tmp1VT.getVectorNumElements(); |
| 8055 | if (Tmp1VTNumElts < NewNumElts) |
| 8056 | Result = WidenVectorOp(Tmp1, WidenVT); |
| 8057 | else |
| 8058 | Result = DAG.getNode(ISD::EXTRACT_SUBVECTOR, WidenVT, Tmp1, Idx); |
| 8059 | } |
| 8060 | } else if (NewNumElts % NumElts == 0) { |
| 8061 | // Widen the extracted subvector. |
| 8062 | unsigned NumConcat = NewNumElts / NumElts; |
| 8063 | SDValue UndefVal = DAG.getNode(ISD::UNDEF, VT); |
| 8064 | SmallVector<SDValue, 8> MOps; |
| 8065 | MOps.push_back(Op); |
| 8066 | for (unsigned i = 1; i != NumConcat; ++i) { |
| 8067 | MOps.push_back(UndefVal); |
| 8068 | } |
| 8069 | Result = LegalizeOp(DAG.getNode(ISD::CONCAT_VECTORS, WidenVT, |
| 8070 | &MOps[0], MOps.size())); |
| 8071 | } else { |
| 8072 | assert(0 && "can not widen extract subvector"); |
| 8073 | // This could be implemented using insert and build vector but I would |
| 8074 | // like to see when this happens. |
| 8075 | } |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8076 | break; |
| 8077 | } |
| 8078 | |
| 8079 | case ISD::SELECT: { |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8080 | // Determine new condition widen type and widen |
| 8081 | SDValue Cond1 = Node->getOperand(0); |
| 8082 | MVT CondVT = Cond1.getValueType(); |
| 8083 | assert(CondVT.isVector() && "can not widen non vector type"); |
| 8084 | MVT CondEVT = CondVT.getVectorElementType(); |
| 8085 | MVT CondWidenVT = MVT::getVectorVT(CondEVT, NewNumElts); |
| 8086 | Cond1 = WidenVectorOp(Cond1, CondWidenVT); |
| 8087 | assert(Cond1.getValueType() == CondWidenVT && "Condition not widen"); |
| 8088 | |
| 8089 | SDValue Tmp1 = WidenVectorOp(Node->getOperand(1), WidenVT); |
| 8090 | SDValue Tmp2 = WidenVectorOp(Node->getOperand(2), WidenVT); |
| 8091 | assert(Tmp1.getValueType() == WidenVT && Tmp2.getValueType() == WidenVT); |
| 8092 | Result = DAG.getNode(Node->getOpcode(), WidenVT, Cond1, Tmp1, Tmp2); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8093 | break; |
| 8094 | } |
| 8095 | |
| 8096 | case ISD::SELECT_CC: { |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8097 | // Determine new condition widen type and widen |
| 8098 | SDValue Cond1 = Node->getOperand(0); |
| 8099 | SDValue Cond2 = Node->getOperand(1); |
| 8100 | MVT CondVT = Cond1.getValueType(); |
| 8101 | assert(CondVT.isVector() && "can not widen non vector type"); |
| 8102 | assert(CondVT == Cond2.getValueType() && "mismatch lhs/rhs"); |
| 8103 | MVT CondEVT = CondVT.getVectorElementType(); |
| 8104 | MVT CondWidenVT = MVT::getVectorVT(CondEVT, NewNumElts); |
| 8105 | Cond1 = WidenVectorOp(Cond1, CondWidenVT); |
| 8106 | Cond2 = WidenVectorOp(Cond2, CondWidenVT); |
| 8107 | assert(Cond1.getValueType() == CondWidenVT && |
| 8108 | Cond2.getValueType() == CondWidenVT && "condition not widen"); |
| 8109 | |
| 8110 | SDValue Tmp1 = WidenVectorOp(Node->getOperand(2), WidenVT); |
| 8111 | SDValue Tmp2 = WidenVectorOp(Node->getOperand(3), WidenVT); |
| 8112 | assert(Tmp1.getValueType() == WidenVT && Tmp2.getValueType() == WidenVT && |
| 8113 | "operands not widen"); |
| 8114 | Result = DAG.getNode(Node->getOpcode(), WidenVT, Cond1, Cond2, Tmp1, |
| 8115 | Tmp2, Node->getOperand(4)); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8116 | break; |
Mon P Wang | 2eb13c3 | 2008-10-30 18:21:52 +0000 | [diff] [blame] | 8117 | } |
| 8118 | case ISD::VSETCC: { |
| 8119 | // Determine widen for the operand |
| 8120 | SDValue Tmp1 = Node->getOperand(0); |
| 8121 | MVT TmpVT = Tmp1.getValueType(); |
| 8122 | assert(TmpVT.isVector() && "can not widen non vector type"); |
| 8123 | MVT TmpEVT = TmpVT.getVectorElementType(); |
| 8124 | MVT TmpWidenVT = MVT::getVectorVT(TmpEVT, NewNumElts); |
| 8125 | Tmp1 = WidenVectorOp(Tmp1, TmpWidenVT); |
| 8126 | SDValue Tmp2 = WidenVectorOp(Node->getOperand(1), TmpWidenVT); |
| 8127 | Result = DAG.getNode(Node->getOpcode(), WidenVT, Tmp1, Tmp2, |
| 8128 | Node->getOperand(2)); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8129 | break; |
| 8130 | } |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8131 | case ISD::ATOMIC_CMP_SWAP_8: |
| 8132 | case ISD::ATOMIC_CMP_SWAP_16: |
| 8133 | case ISD::ATOMIC_CMP_SWAP_32: |
| 8134 | case ISD::ATOMIC_CMP_SWAP_64: |
| 8135 | case ISD::ATOMIC_LOAD_ADD_8: |
| 8136 | case ISD::ATOMIC_LOAD_SUB_8: |
| 8137 | case ISD::ATOMIC_LOAD_AND_8: |
| 8138 | case ISD::ATOMIC_LOAD_OR_8: |
| 8139 | case ISD::ATOMIC_LOAD_XOR_8: |
| 8140 | case ISD::ATOMIC_LOAD_NAND_8: |
| 8141 | case ISD::ATOMIC_LOAD_MIN_8: |
| 8142 | case ISD::ATOMIC_LOAD_MAX_8: |
| 8143 | case ISD::ATOMIC_LOAD_UMIN_8: |
| 8144 | case ISD::ATOMIC_LOAD_UMAX_8: |
| 8145 | case ISD::ATOMIC_SWAP_8: |
| 8146 | case ISD::ATOMIC_LOAD_ADD_16: |
| 8147 | case ISD::ATOMIC_LOAD_SUB_16: |
| 8148 | case ISD::ATOMIC_LOAD_AND_16: |
| 8149 | case ISD::ATOMIC_LOAD_OR_16: |
| 8150 | case ISD::ATOMIC_LOAD_XOR_16: |
| 8151 | case ISD::ATOMIC_LOAD_NAND_16: |
| 8152 | case ISD::ATOMIC_LOAD_MIN_16: |
| 8153 | case ISD::ATOMIC_LOAD_MAX_16: |
| 8154 | case ISD::ATOMIC_LOAD_UMIN_16: |
| 8155 | case ISD::ATOMIC_LOAD_UMAX_16: |
| 8156 | case ISD::ATOMIC_SWAP_16: |
| 8157 | case ISD::ATOMIC_LOAD_ADD_32: |
| 8158 | case ISD::ATOMIC_LOAD_SUB_32: |
| 8159 | case ISD::ATOMIC_LOAD_AND_32: |
| 8160 | case ISD::ATOMIC_LOAD_OR_32: |
| 8161 | case ISD::ATOMIC_LOAD_XOR_32: |
| 8162 | case ISD::ATOMIC_LOAD_NAND_32: |
| 8163 | case ISD::ATOMIC_LOAD_MIN_32: |
| 8164 | case ISD::ATOMIC_LOAD_MAX_32: |
| 8165 | case ISD::ATOMIC_LOAD_UMIN_32: |
| 8166 | case ISD::ATOMIC_LOAD_UMAX_32: |
| 8167 | case ISD::ATOMIC_SWAP_32: |
| 8168 | case ISD::ATOMIC_LOAD_ADD_64: |
| 8169 | case ISD::ATOMIC_LOAD_SUB_64: |
| 8170 | case ISD::ATOMIC_LOAD_AND_64: |
| 8171 | case ISD::ATOMIC_LOAD_OR_64: |
| 8172 | case ISD::ATOMIC_LOAD_XOR_64: |
| 8173 | case ISD::ATOMIC_LOAD_NAND_64: |
| 8174 | case ISD::ATOMIC_LOAD_MIN_64: |
| 8175 | case ISD::ATOMIC_LOAD_MAX_64: |
| 8176 | case ISD::ATOMIC_LOAD_UMIN_64: |
| 8177 | case ISD::ATOMIC_LOAD_UMAX_64: |
| 8178 | case ISD::ATOMIC_SWAP_64: { |
| 8179 | // For now, we assume that using vectors for these operations don't make |
| 8180 | // much sense so we just split it. We return an empty result |
| 8181 | SDValue X, Y; |
| 8182 | SplitVectorOp(Op, X, Y); |
| 8183 | return Result; |
| 8184 | break; |
| 8185 | } |
| 8186 | |
| 8187 | } // end switch (Node->getOpcode()) |
| 8188 | |
| 8189 | assert(Result.getNode() && "Didn't set a result!"); |
| 8190 | if (Result != Op) |
| 8191 | Result = LegalizeOp(Result); |
| 8192 | |
Mon P Wang | f007a8b | 2008-11-06 05:31:54 +0000 | [diff] [blame] | 8193 | AddWidenedOperand(Op, Result); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8194 | return Result; |
| 8195 | } |
| 8196 | |
| 8197 | // Utility function to find a legal vector type and its associated element |
| 8198 | // type from a preferred width and whose vector type must be the same size |
| 8199 | // as the VVT. |
| 8200 | // TLI: Target lowering used to determine legal types |
| 8201 | // Width: Preferred width of element type |
| 8202 | // VVT: Vector value type whose size we must match. |
| 8203 | // Returns VecEVT and EVT - the vector type and its associated element type |
| 8204 | static void FindWidenVecType(TargetLowering &TLI, unsigned Width, MVT VVT, |
| 8205 | MVT& EVT, MVT& VecEVT) { |
| 8206 | // We start with the preferred width, make it a power of 2 and see if |
| 8207 | // we can find a vector type of that width. If not, we reduce it by |
| 8208 | // another power of 2. If we have widen the type, a vector of bytes should |
| 8209 | // always be legal. |
| 8210 | assert(TLI.isTypeLegal(VVT)); |
| 8211 | unsigned EWidth = Width + 1; |
| 8212 | do { |
| 8213 | assert(EWidth > 0); |
| 8214 | EWidth = (1 << Log2_32(EWidth-1)); |
| 8215 | EVT = MVT::getIntegerVT(EWidth); |
| 8216 | unsigned NumEVT = VVT.getSizeInBits()/EWidth; |
| 8217 | VecEVT = MVT::getVectorVT(EVT, NumEVT); |
| 8218 | } while (!TLI.isTypeLegal(VecEVT) || |
| 8219 | VVT.getSizeInBits() != VecEVT.getSizeInBits()); |
| 8220 | } |
| 8221 | |
| 8222 | SDValue SelectionDAGLegalize::genWidenVectorLoads(SDValueVector& LdChain, |
| 8223 | SDValue Chain, |
| 8224 | SDValue BasePtr, |
| 8225 | const Value *SV, |
| 8226 | int SVOffset, |
| 8227 | unsigned Alignment, |
| 8228 | bool isVolatile, |
| 8229 | unsigned LdWidth, |
| 8230 | MVT ResType) { |
| 8231 | // We assume that we have good rules to handle loading power of two loads so |
| 8232 | // we break down the operations to power of 2 loads. The strategy is to |
| 8233 | // load the largest power of 2 that we can easily transform to a legal vector |
| 8234 | // and then insert into that vector, and the cast the result into the legal |
| 8235 | // vector that we want. This avoids unnecessary stack converts. |
| 8236 | // TODO: If the Ldwidth is legal, alignment is the same as the LdWidth, and |
| 8237 | // the load is nonvolatile, we an use a wider load for the value. |
| 8238 | // Find a vector length we can load a large chunk |
| 8239 | MVT EVT, VecEVT; |
| 8240 | unsigned EVTWidth; |
| 8241 | FindWidenVecType(TLI, LdWidth, ResType, EVT, VecEVT); |
| 8242 | EVTWidth = EVT.getSizeInBits(); |
| 8243 | |
| 8244 | SDValue LdOp = DAG.getLoad(EVT, Chain, BasePtr, SV, SVOffset, |
| 8245 | isVolatile, Alignment); |
| 8246 | SDValue VecOp = DAG.getNode(ISD::SCALAR_TO_VECTOR, VecEVT, LdOp); |
| 8247 | LdChain.push_back(LdOp.getValue(1)); |
| 8248 | |
| 8249 | // Check if we can load the element with one instruction |
| 8250 | if (LdWidth == EVTWidth) { |
| 8251 | return DAG.getNode(ISD::BIT_CONVERT, ResType, VecOp); |
| 8252 | } |
| 8253 | |
| 8254 | // The vector element order is endianness dependent. |
| 8255 | unsigned Idx = 1; |
| 8256 | LdWidth -= EVTWidth; |
| 8257 | unsigned Offset = 0; |
| 8258 | |
| 8259 | while (LdWidth > 0) { |
| 8260 | unsigned Increment = EVTWidth / 8; |
| 8261 | Offset += Increment; |
| 8262 | BasePtr = DAG.getNode(ISD::ADD, BasePtr.getValueType(), BasePtr, |
| 8263 | DAG.getIntPtrConstant(Increment)); |
| 8264 | |
| 8265 | if (LdWidth < EVTWidth) { |
| 8266 | // Our current type we are using is too large, use a smaller size by |
| 8267 | // using a smaller power of 2 |
| 8268 | unsigned oEVTWidth = EVTWidth; |
| 8269 | FindWidenVecType(TLI, LdWidth, ResType, EVT, VecEVT); |
| 8270 | EVTWidth = EVT.getSizeInBits(); |
| 8271 | // Readjust position and vector position based on new load type |
Mon P Wang | 49292f1 | 2008-11-15 06:05:52 +0000 | [diff] [blame] | 8272 | Idx = Idx * (oEVTWidth/EVTWidth); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8273 | VecOp = DAG.getNode(ISD::BIT_CONVERT, VecEVT, VecOp); |
| 8274 | } |
| 8275 | |
| 8276 | SDValue LdOp = DAG.getLoad(EVT, Chain, BasePtr, SV, |
| 8277 | SVOffset+Offset, isVolatile, |
| 8278 | MinAlign(Alignment, Offset)); |
| 8279 | LdChain.push_back(LdOp.getValue(1)); |
| 8280 | VecOp = DAG.getNode(ISD::INSERT_VECTOR_ELT, VecEVT, VecOp, LdOp, |
| 8281 | DAG.getIntPtrConstant(Idx++)); |
| 8282 | |
| 8283 | LdWidth -= EVTWidth; |
| 8284 | } |
| 8285 | |
| 8286 | return DAG.getNode(ISD::BIT_CONVERT, ResType, VecOp); |
| 8287 | } |
| 8288 | |
| 8289 | bool SelectionDAGLegalize::LoadWidenVectorOp(SDValue& Result, |
| 8290 | SDValue& TFOp, |
| 8291 | SDValue Op, |
| 8292 | MVT NVT) { |
| 8293 | // TODO: Add support for ConcatVec and the ability to load many vector |
| 8294 | // types (e.g., v4i8). This will not work when a vector register |
| 8295 | // to memory mapping is strange (e.g., vector elements are not |
| 8296 | // stored in some sequential order). |
| 8297 | |
| 8298 | // It must be true that the widen vector type is bigger than where |
| 8299 | // we need to load from. |
| 8300 | LoadSDNode *LD = cast<LoadSDNode>(Op.getNode()); |
| 8301 | MVT LdVT = LD->getMemoryVT(); |
| 8302 | assert(LdVT.isVector() && NVT.isVector()); |
| 8303 | assert(LdVT.getVectorElementType() == NVT.getVectorElementType()); |
| 8304 | |
| 8305 | // Load information |
| 8306 | SDValue Chain = LD->getChain(); |
| 8307 | SDValue BasePtr = LD->getBasePtr(); |
| 8308 | int SVOffset = LD->getSrcValueOffset(); |
| 8309 | unsigned Alignment = LD->getAlignment(); |
| 8310 | bool isVolatile = LD->isVolatile(); |
| 8311 | const Value *SV = LD->getSrcValue(); |
| 8312 | unsigned int LdWidth = LdVT.getSizeInBits(); |
| 8313 | |
| 8314 | // Load value as a large register |
| 8315 | SDValueVector LdChain; |
| 8316 | Result = genWidenVectorLoads(LdChain, Chain, BasePtr, SV, SVOffset, |
| 8317 | Alignment, isVolatile, LdWidth, NVT); |
| 8318 | |
| 8319 | if (LdChain.size() == 1) { |
| 8320 | TFOp = LdChain[0]; |
| 8321 | return true; |
| 8322 | } |
| 8323 | else { |
| 8324 | TFOp=DAG.getNode(ISD::TokenFactor, MVT::Other, &LdChain[0], LdChain.size()); |
| 8325 | return false; |
| 8326 | } |
| 8327 | } |
| 8328 | |
| 8329 | |
| 8330 | void SelectionDAGLegalize::genWidenVectorStores(SDValueVector& StChain, |
| 8331 | SDValue Chain, |
| 8332 | SDValue BasePtr, |
| 8333 | const Value *SV, |
| 8334 | int SVOffset, |
| 8335 | unsigned Alignment, |
| 8336 | bool isVolatile, |
Mon P Wang | 49292f1 | 2008-11-15 06:05:52 +0000 | [diff] [blame] | 8337 | SDValue ValOp, |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8338 | unsigned StWidth) { |
| 8339 | // Breaks the stores into a series of power of 2 width stores. For any |
| 8340 | // width, we convert the vector to the vector of element size that we |
| 8341 | // want to store. This avoids requiring a stack convert. |
| 8342 | |
| 8343 | // Find a width of the element type we can store with |
| 8344 | MVT VVT = ValOp.getValueType(); |
| 8345 | MVT EVT, VecEVT; |
| 8346 | unsigned EVTWidth; |
| 8347 | FindWidenVecType(TLI, StWidth, VVT, EVT, VecEVT); |
| 8348 | EVTWidth = EVT.getSizeInBits(); |
| 8349 | |
| 8350 | SDValue VecOp = DAG.getNode(ISD::BIT_CONVERT, VecEVT, ValOp); |
| 8351 | SDValue EOp = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, EVT, VecOp, |
Mon P Wang | e0b436a | 2008-11-06 22:52:21 +0000 | [diff] [blame] | 8352 | DAG.getIntPtrConstant(0)); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8353 | SDValue StOp = DAG.getStore(Chain, EOp, BasePtr, SV, SVOffset, |
| 8354 | isVolatile, Alignment); |
| 8355 | StChain.push_back(StOp); |
| 8356 | |
| 8357 | // Check if we are done |
| 8358 | if (StWidth == EVTWidth) { |
| 8359 | return; |
| 8360 | } |
| 8361 | |
| 8362 | unsigned Idx = 1; |
| 8363 | StWidth -= EVTWidth; |
| 8364 | unsigned Offset = 0; |
| 8365 | |
| 8366 | while (StWidth > 0) { |
| 8367 | unsigned Increment = EVTWidth / 8; |
| 8368 | Offset += Increment; |
| 8369 | BasePtr = DAG.getNode(ISD::ADD, BasePtr.getValueType(), BasePtr, |
| 8370 | DAG.getIntPtrConstant(Increment)); |
| 8371 | |
| 8372 | if (StWidth < EVTWidth) { |
| 8373 | // Our current type we are using is too large, use a smaller size by |
| 8374 | // using a smaller power of 2 |
| 8375 | unsigned oEVTWidth = EVTWidth; |
| 8376 | FindWidenVecType(TLI, StWidth, VVT, EVT, VecEVT); |
| 8377 | EVTWidth = EVT.getSizeInBits(); |
| 8378 | // Readjust position and vector position based on new load type |
Mon P Wang | 49292f1 | 2008-11-15 06:05:52 +0000 | [diff] [blame] | 8379 | Idx = Idx * (oEVTWidth/EVTWidth); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8380 | VecOp = DAG.getNode(ISD::BIT_CONVERT, VecEVT, VecOp); |
| 8381 | } |
| 8382 | |
| 8383 | EOp = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, EVT, VecOp, |
Mon P Wang | 49292f1 | 2008-11-15 06:05:52 +0000 | [diff] [blame] | 8384 | DAG.getIntPtrConstant(Idx++)); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8385 | StChain.push_back(DAG.getStore(Chain, EOp, BasePtr, SV, |
| 8386 | SVOffset + Offset, isVolatile, |
| 8387 | MinAlign(Alignment, Offset))); |
| 8388 | StWidth -= EVTWidth; |
| 8389 | } |
| 8390 | } |
| 8391 | |
| 8392 | |
| 8393 | SDValue SelectionDAGLegalize::StoreWidenVectorOp(StoreSDNode *ST, |
| 8394 | SDValue Chain, |
| 8395 | SDValue BasePtr) { |
| 8396 | // TODO: It might be cleaner if we can use SplitVector and have more legal |
| 8397 | // vector types that can be stored into memory (e.g., v4xi8 can |
| 8398 | // be stored as a word). This will not work when a vector register |
| 8399 | // to memory mapping is strange (e.g., vector elements are not |
| 8400 | // stored in some sequential order). |
| 8401 | |
| 8402 | MVT StVT = ST->getMemoryVT(); |
| 8403 | SDValue ValOp = ST->getValue(); |
| 8404 | |
| 8405 | // Check if we have widen this node with another value |
| 8406 | std::map<SDValue, SDValue>::iterator I = WidenNodes.find(ValOp); |
| 8407 | if (I != WidenNodes.end()) |
| 8408 | ValOp = I->second; |
| 8409 | |
| 8410 | MVT VVT = ValOp.getValueType(); |
| 8411 | |
| 8412 | // It must be true that we the widen vector type is bigger than where |
| 8413 | // we need to store. |
| 8414 | assert(StVT.isVector() && VVT.isVector()); |
| 8415 | assert(StVT.getSizeInBits() < VVT.getSizeInBits()); |
| 8416 | assert(StVT.getVectorElementType() == VVT.getVectorElementType()); |
| 8417 | |
| 8418 | // Store value |
| 8419 | SDValueVector StChain; |
| 8420 | genWidenVectorStores(StChain, Chain, BasePtr, ST->getSrcValue(), |
| 8421 | ST->getSrcValueOffset(), ST->getAlignment(), |
| 8422 | ST->isVolatile(), ValOp, StVT.getSizeInBits()); |
| 8423 | if (StChain.size() == 1) |
| 8424 | return StChain[0]; |
| 8425 | else |
| 8426 | return DAG.getNode(ISD::TokenFactor, MVT::Other,&StChain[0],StChain.size()); |
| 8427 | } |
| 8428 | |
| 8429 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 8430 | // SelectionDAG::Legalize - This is the entry point for the file. |
| 8431 | // |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 8432 | void SelectionDAG::Legalize() { |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 8433 | /// run - This is the main entry point to this class. |
| 8434 | /// |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 8435 | SelectionDAGLegalize(*this).LegalizeDAG(); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 8436 | } |
| 8437 | |