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" |
Devang Patel | 83489bb | 2009-01-13 00:35:13 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/DwarfWriter.h" |
| 20 | #include "llvm/Analysis/DebugInfo.h" |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/PseudoSourceValue.h" |
Evan Cheng | 61bbbab | 2007-08-16 23:50:06 +0000 | [diff] [blame] | 22 | #include "llvm/Target/TargetFrameInfo.h" |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 23 | #include "llvm/Target/TargetLowering.h" |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 24 | #include "llvm/Target/TargetData.h" |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 25 | #include "llvm/Target/TargetMachine.h" |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 26 | #include "llvm/Target/TargetOptions.h" |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 27 | #include "llvm/Target/TargetSubtarget.h" |
Chris Lattner | adf6a96 | 2005-05-13 18:50:42 +0000 | [diff] [blame] | 28 | #include "llvm/CallingConv.h" |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 29 | #include "llvm/Constants.h" |
Reid Spencer | c103057 | 2007-01-19 21:13:56 +0000 | [diff] [blame] | 30 | #include "llvm/DerivedTypes.h" |
Devang Patel | 83489bb | 2009-01-13 00:35:13 +0000 | [diff] [blame] | 31 | #include "llvm/GlobalVariable.h" |
Chris Lattner | 5e46a19 | 2006-04-02 03:07:27 +0000 | [diff] [blame] | 32 | #include "llvm/Support/CommandLine.h" |
Chris Lattner | a4f0b3a | 2006-08-27 12:54:02 +0000 | [diff] [blame] | 33 | #include "llvm/Support/Compiler.h" |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 34 | #include "llvm/Support/MathExtras.h" |
Chris Lattner | 7971514 | 2007-02-03 01:12:36 +0000 | [diff] [blame] | 35 | #include "llvm/ADT/DenseMap.h" |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 36 | #include "llvm/ADT/SmallVector.h" |
Chris Lattner | 00755df | 2007-02-04 00:27:56 +0000 | [diff] [blame] | 37 | #include "llvm/ADT/SmallPtrSet.h" |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 38 | #include <map> |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 39 | using namespace llvm; |
| 40 | |
| 41 | //===----------------------------------------------------------------------===// |
| 42 | /// SelectionDAGLegalize - This takes an arbitrary SelectionDAG as input and |
| 43 | /// hacks on it until the target machine can handle it. This involves |
| 44 | /// eliminating value sizes the machine cannot handle (promoting small sizes to |
| 45 | /// large sizes or splitting up large values into small values) as well as |
| 46 | /// eliminating operations the machine cannot handle. |
| 47 | /// |
| 48 | /// This code also does a small amount of optimization and recognition of idioms |
| 49 | /// as part of its processing. For example, if a target does not support a |
| 50 | /// 'setcc' instruction efficiently, but does support 'brcc' instruction, this |
| 51 | /// will attempt merge setcc and brc instructions into brcc's. |
| 52 | /// |
| 53 | namespace { |
Chris Lattner | 360e820 | 2006-06-28 21:58:30 +0000 | [diff] [blame] | 54 | class VISIBILITY_HIDDEN SelectionDAGLegalize { |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 55 | TargetLowering &TLI; |
| 56 | SelectionDAG &DAG; |
Duncan Sands | b6862bb | 2008-12-14 09:43:15 +0000 | [diff] [blame] | 57 | bool TypesNeedLegalizing; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 58 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 59 | // Libcall insertion helpers. |
| 60 | |
| 61 | /// LastCALLSEQ_END - This keeps track of the CALLSEQ_END node that has been |
| 62 | /// legalized. We use this to ensure that calls are properly serialized |
| 63 | /// against each other, including inserted libcalls. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 64 | SDValue LastCALLSEQ_END; |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 65 | |
| 66 | /// IsLegalizingCall - This member is used *only* for purposes of providing |
| 67 | /// helpful assertions that a libcall isn't created while another call is |
| 68 | /// being legalized (which could lead to non-serialized call sequences). |
| 69 | bool IsLegalizingCall; |
| 70 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 71 | enum LegalizeAction { |
Chris Lattner | 68a17fe | 2006-01-29 08:42:06 +0000 | [diff] [blame] | 72 | Legal, // The target natively supports this operation. |
| 73 | Promote, // This operation should be executed in a larger type. |
Chris Lattner | d74ea2b | 2006-05-24 17:04:05 +0000 | [diff] [blame] | 74 | Expand // Try to expand this to other ops, otherwise use a libcall. |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 75 | }; |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 76 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 77 | /// ValueTypeActions - This is a bitvector that contains two bits for each |
| 78 | /// value type, where the two bits correspond to the LegalizeAction enum. |
| 79 | /// This can be queried with "getTypeAction(VT)". |
Chris Lattner | 68a17fe | 2006-01-29 08:42:06 +0000 | [diff] [blame] | 80 | TargetLowering::ValueTypeActionImpl ValueTypeActions; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 81 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 82 | /// LegalizedNodes - For nodes that are of legal width, and that have more |
| 83 | /// than one use, this map indicates what regularized operand to use. This |
| 84 | /// allows us to avoid legalizing the same thing more than once. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 85 | DenseMap<SDValue, SDValue> LegalizedNodes; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 86 | |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 87 | /// PromotedNodes - For nodes that are below legal width, and that have more |
| 88 | /// than one use, this map indicates what promoted value to use. This allows |
| 89 | /// us to avoid promoting the same thing more than once. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 90 | DenseMap<SDValue, SDValue> PromotedNodes; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 91 | |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 92 | /// ExpandedNodes - For nodes that need to be expanded this map indicates |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 93 | /// which operands are the expanded version of the input. This allows |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 94 | /// us to avoid expanding the same node more than once. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 95 | DenseMap<SDValue, std::pair<SDValue, SDValue> > ExpandedNodes; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 96 | |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 97 | /// 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] | 98 | /// which operands are the split version of the input. This allows us |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 99 | /// to avoid splitting the same node more than once. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 100 | std::map<SDValue, std::pair<SDValue, SDValue> > SplitNodes; |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 101 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 102 | /// ScalarizedNodes - For nodes that need to be converted from vector types to |
| 103 | /// scalar types, this contains the mapping of ones we have already |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 104 | /// processed to the result. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 105 | std::map<SDValue, SDValue> ScalarizedNodes; |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 106 | |
Mon P Wang | f007a8b | 2008-11-06 05:31:54 +0000 | [diff] [blame] | 107 | /// WidenNodes - For nodes that need to be widened from one vector type to |
| 108 | /// another, this contains the mapping of those that we have already widen. |
| 109 | /// This allows us to avoid widening more than once. |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 110 | std::map<SDValue, SDValue> WidenNodes; |
| 111 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 112 | void AddLegalizedOperand(SDValue From, SDValue To) { |
Chris Lattner | 69a889e | 2005-12-20 00:53:54 +0000 | [diff] [blame] | 113 | LegalizedNodes.insert(std::make_pair(From, To)); |
| 114 | // If someone requests legalization of the new node, return itself. |
| 115 | if (From != To) |
| 116 | LegalizedNodes.insert(std::make_pair(To, To)); |
Chris Lattner | 8afc48e | 2005-01-07 22:28:47 +0000 | [diff] [blame] | 117 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 118 | void AddPromotedOperand(SDValue From, SDValue To) { |
Dan Gohman | 6b345ee | 2008-07-07 17:46:23 +0000 | [diff] [blame] | 119 | bool isNew = PromotedNodes.insert(std::make_pair(From, To)).second; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 120 | assert(isNew && "Got into the map somehow?"); |
Evan Cheng | 24ac408 | 2008-11-24 07:09:49 +0000 | [diff] [blame] | 121 | isNew = isNew; |
Chris Lattner | 69a889e | 2005-12-20 00:53:54 +0000 | [diff] [blame] | 122 | // If someone requests legalization of the new node, return itself. |
| 123 | LegalizedNodes.insert(std::make_pair(To, To)); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 124 | } |
Mon P Wang | f007a8b | 2008-11-06 05:31:54 +0000 | [diff] [blame] | 125 | void AddWidenedOperand(SDValue From, SDValue To) { |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 126 | bool isNew = WidenNodes.insert(std::make_pair(From, To)).second; |
| 127 | assert(isNew && "Got into the map somehow?"); |
Evan Cheng | 24ac408 | 2008-11-24 07:09:49 +0000 | [diff] [blame] | 128 | isNew = isNew; |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 129 | // If someone requests legalization of the new node, return itself. |
| 130 | LegalizedNodes.insert(std::make_pair(To, To)); |
| 131 | } |
Chris Lattner | 8afc48e | 2005-01-07 22:28:47 +0000 | [diff] [blame] | 132 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 133 | public: |
Duncan Sands | b6862bb | 2008-12-14 09:43:15 +0000 | [diff] [blame] | 134 | explicit SelectionDAGLegalize(SelectionDAG &DAG, bool TypesNeedLegalizing); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 135 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 136 | /// getTypeAction - Return how we should legalize values of this type, either |
| 137 | /// it is already legal or we need to expand it into multiple registers of |
| 138 | /// 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] | 139 | LegalizeAction getTypeAction(MVT VT) const { |
Chris Lattner | 68a17fe | 2006-01-29 08:42:06 +0000 | [diff] [blame] | 140 | return (LegalizeAction)ValueTypeActions.getTypeAction(VT); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | /// isTypeLegal - Return true if this type is legal on this target. |
| 144 | /// |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 145 | bool isTypeLegal(MVT VT) const { |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 146 | return getTypeAction(VT) == Legal; |
| 147 | } |
| 148 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 149 | void LegalizeDAG(); |
| 150 | |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 151 | private: |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 152 | /// HandleOp - Legalize, Promote, or Expand the specified operand as |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 153 | /// appropriate for its type. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 154 | void HandleOp(SDValue Op); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 155 | |
| 156 | /// LegalizeOp - We know that the specified value has a legal type. |
| 157 | /// Recursively ensure that the operands have legal types, then return the |
| 158 | /// result. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 159 | SDValue LegalizeOp(SDValue O); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 160 | |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 161 | /// UnrollVectorOp - We know that the given vector has a legal type, however |
| 162 | /// the operation it performs is not legal and is an operation that we have |
| 163 | /// no way of lowering. "Unroll" the vector, splitting out the scalars and |
| 164 | /// operating on each element individually. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 165 | SDValue UnrollVectorOp(SDValue O); |
Nate Begeman | 6867991 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 166 | |
| 167 | /// PerformInsertVectorEltInMemory - Some target cannot handle a variable |
| 168 | /// insertion index for the INSERT_VECTOR_ELT instruction. In this case, it |
| 169 | /// is necessary to spill the vector being inserted into to memory, perform |
| 170 | /// the insert there, and then read the result back. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 171 | SDValue PerformInsertVectorEltInMemory(SDValue Vec, SDValue Val, |
| 172 | SDValue Idx); |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 173 | |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 174 | /// PromoteOp - Given an operation that produces a value in an invalid type, |
| 175 | /// promote it to compute the value into a larger type. The produced value |
| 176 | /// will have the correct bits for the low portion of the register, but no |
| 177 | /// guarantee is made about the top bits: it may be zero, sign-extended, or |
| 178 | /// garbage. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 179 | SDValue PromoteOp(SDValue O); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 180 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 181 | /// ExpandOp - Expand the specified SDValue into its two component pieces |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 182 | /// 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] | 183 | /// 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] | 184 | /// the ExpandedNodes map is filled in for any results that are expanded, and |
| 185 | /// the Lo/Hi values are returned. This applies to integer types and Vector |
| 186 | /// types. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 187 | void ExpandOp(SDValue O, SDValue &Lo, SDValue &Hi); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 188 | |
Mon P Wang | f007a8b | 2008-11-06 05:31:54 +0000 | [diff] [blame] | 189 | /// WidenVectorOp - Widen a vector operation to a wider type given by WidenVT |
| 190 | /// (e.g., v3i32 to v4i32). The produced value will have the correct value |
| 191 | /// for the existing elements but no guarantee is made about the new elements |
| 192 | /// at the end of the vector: it may be zero, ones, or garbage. This is useful |
| 193 | /// when we have an instruction operating on an illegal vector type and we |
| 194 | /// 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] | 195 | SDValue WidenVectorOp(SDValue Op, MVT WidenVT); |
| 196 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 197 | /// SplitVectorOp - Given an operand of vector type, break it down into |
| 198 | /// two smaller values. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 199 | void SplitVectorOp(SDValue O, SDValue &Lo, SDValue &Hi); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 200 | |
Dan Gohman | 89b20c0 | 2007-06-27 14:06:22 +0000 | [diff] [blame] | 201 | /// ScalarizeVectorOp - Given an operand of single-element vector type |
| 202 | /// (e.g. v1f32), convert it into the equivalent operation that returns a |
| 203 | /// scalar (e.g. f32) value. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 204 | SDValue ScalarizeVectorOp(SDValue O); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 205 | |
Mon P Wang | f007a8b | 2008-11-06 05:31:54 +0000 | [diff] [blame] | 206 | /// 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] | 207 | typedef SmallVector<SDValue, 16> SDValueVector; |
| 208 | |
| 209 | /// LoadWidenVectorOp - Load a vector for a wider type. Returns true if |
| 210 | /// the LdChain contains a single load and false if it contains a token |
| 211 | /// factor for multiple loads. It takes |
| 212 | /// Result: location to return the result |
| 213 | /// LdChain: location to return the load chain |
| 214 | /// Op: load operation to widen |
| 215 | /// NVT: widen vector result type we want for the load |
| 216 | bool LoadWidenVectorOp(SDValue& Result, SDValue& LdChain, |
| 217 | SDValue Op, MVT NVT); |
| 218 | |
| 219 | /// Helper genWidenVectorLoads - Helper function to generate a set of |
| 220 | /// loads to load a vector with a resulting wider type. It takes |
| 221 | /// LdChain: list of chains for the load we have generated |
| 222 | /// Chain: incoming chain for the ld vector |
| 223 | /// BasePtr: base pointer to load from |
| 224 | /// SV: memory disambiguation source value |
| 225 | /// SVOffset: memory disambiugation offset |
| 226 | /// Alignment: alignment of the memory |
| 227 | /// isVolatile: volatile load |
| 228 | /// LdWidth: width of memory that we want to load |
| 229 | /// ResType: the wider result result type for the resulting loaded vector |
| 230 | SDValue genWidenVectorLoads(SDValueVector& LdChain, SDValue Chain, |
| 231 | SDValue BasePtr, const Value *SV, |
| 232 | int SVOffset, unsigned Alignment, |
| 233 | bool isVolatile, unsigned LdWidth, |
| 234 | MVT ResType); |
| 235 | |
| 236 | /// StoreWidenVectorOp - Stores a widen vector into non widen memory |
| 237 | /// location. It takes |
| 238 | /// ST: store node that we want to replace |
| 239 | /// Chain: incoming store chain |
| 240 | /// BasePtr: base address of where we want to store into |
| 241 | SDValue StoreWidenVectorOp(StoreSDNode *ST, SDValue Chain, |
| 242 | SDValue BasePtr); |
| 243 | |
| 244 | /// Helper genWidenVectorStores - Helper function to generate a set of |
| 245 | /// stores to store a widen vector into non widen memory |
| 246 | // It takes |
| 247 | // StChain: list of chains for the stores we have generated |
| 248 | // Chain: incoming chain for the ld vector |
| 249 | // BasePtr: base pointer to load from |
| 250 | // SV: memory disambiguation source value |
| 251 | // SVOffset: memory disambiugation offset |
| 252 | // Alignment: alignment of the memory |
| 253 | // isVolatile: volatile lod |
| 254 | // ValOp: value to store |
| 255 | // StWidth: width of memory that we want to store |
| 256 | void genWidenVectorStores(SDValueVector& StChain, SDValue Chain, |
| 257 | SDValue BasePtr, const Value *SV, |
| 258 | int SVOffset, unsigned Alignment, |
| 259 | bool isVolatile, SDValue ValOp, |
| 260 | unsigned StWidth); |
| 261 | |
Duncan Sands | d038e04 | 2008-07-21 10:20:31 +0000 | [diff] [blame] | 262 | /// isShuffleLegal - Return non-null if a vector shuffle is legal with the |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 263 | /// specified mask and type. Targets can specify exactly which masks they |
| 264 | /// support and the code generator is tasked with not creating illegal masks. |
| 265 | /// |
| 266 | /// Note that this will also return true for shuffles that are promoted to a |
| 267 | /// different type. |
| 268 | /// |
| 269 | /// If this is a legal shuffle, this method returns the (possibly promoted) |
| 270 | /// 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] | 271 | SDNode *isShuffleLegal(MVT VT, SDValue Mask) const; |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 272 | |
Chris Lattner | c9cf4f1 | 2006-07-26 23:55:56 +0000 | [diff] [blame] | 273 | bool LegalizeAllNodesNotLeadingTo(SDNode *N, SDNode *Dest, |
Chris Lattner | 00755df | 2007-02-04 00:27:56 +0000 | [diff] [blame] | 274 | SmallPtrSet<SDNode*, 32> &NodesLeadingTo); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 275 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 276 | void LegalizeSetCCOperands(SDValue &LHS, SDValue &RHS, SDValue &CC); |
Evan Cheng | 7f04268 | 2008-10-15 02:05:31 +0000 | [diff] [blame] | 277 | void LegalizeSetCCCondCode(MVT VT, SDValue &LHS, SDValue &RHS, SDValue &CC); |
| 278 | void LegalizeSetCC(MVT VT, SDValue &LHS, SDValue &RHS, SDValue &CC) { |
| 279 | LegalizeSetCCOperands(LHS, RHS, CC); |
| 280 | LegalizeSetCCCondCode(VT, LHS, RHS, CC); |
| 281 | } |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 282 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 283 | SDValue ExpandLibCall(RTLIB::Libcall LC, SDNode *Node, bool isSigned, |
| 284 | SDValue &Hi); |
| 285 | SDValue ExpandIntToFP(bool isSigned, MVT DestTy, SDValue Source); |
Chris Lattner | cad063f | 2005-07-16 00:19:57 +0000 | [diff] [blame] | 286 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 287 | SDValue EmitStackConvert(SDValue SrcOp, MVT SlotVT, MVT DestVT); |
| 288 | SDValue ExpandBUILD_VECTOR(SDNode *Node); |
| 289 | SDValue ExpandSCALAR_TO_VECTOR(SDNode *Node); |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 290 | SDValue LegalizeINT_TO_FP(SDValue Result, bool isSigned, MVT DestTy, SDValue Op); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 291 | SDValue ExpandLegalINT_TO_FP(bool isSigned, SDValue LegalOp, MVT DestVT); |
| 292 | SDValue PromoteLegalINT_TO_FP(SDValue LegalOp, MVT DestVT, bool isSigned); |
| 293 | SDValue PromoteLegalFP_TO_INT(SDValue LegalOp, MVT DestVT, bool isSigned); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 294 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 295 | SDValue ExpandBSWAP(SDValue Op); |
| 296 | SDValue ExpandBitCount(unsigned Opc, SDValue Op); |
| 297 | bool ExpandShift(unsigned Opc, SDValue Op, SDValue Amt, |
| 298 | SDValue &Lo, SDValue &Hi); |
| 299 | void ExpandShiftParts(unsigned NodeOp, SDValue Op, SDValue Amt, |
| 300 | SDValue &Lo, SDValue &Hi); |
Chris Lattner | b9fa3bc | 2005-05-12 04:49:08 +0000 | [diff] [blame] | 301 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 302 | SDValue ExpandEXTRACT_SUBVECTOR(SDValue Op); |
| 303 | SDValue ExpandEXTRACT_VECTOR_ELT(SDValue Op); |
Mon P Wang | e9f1015 | 2008-12-09 05:46:39 +0000 | [diff] [blame] | 304 | |
| 305 | // Returns the legalized (truncated or extended) shift amount. |
| 306 | SDValue LegalizeShiftAmount(SDValue ShiftAmt); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 307 | }; |
| 308 | } |
| 309 | |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 310 | /// isVectorShuffleLegal - Return true if a vector shuffle is legal with the |
| 311 | /// specified mask and type. Targets can specify exactly which masks they |
| 312 | /// support and the code generator is tasked with not creating illegal masks. |
| 313 | /// |
| 314 | /// Note that this will also return true for shuffles that are promoted to a |
| 315 | /// different type. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 316 | SDNode *SelectionDAGLegalize::isShuffleLegal(MVT VT, SDValue Mask) const { |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 317 | switch (TLI.getOperationAction(ISD::VECTOR_SHUFFLE, VT)) { |
| 318 | default: return 0; |
| 319 | case TargetLowering::Legal: |
| 320 | case TargetLowering::Custom: |
| 321 | break; |
| 322 | case TargetLowering::Promote: { |
| 323 | // If this is promoted to a different type, convert the shuffle mask and |
| 324 | // ask if it is legal in the promoted type! |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 325 | MVT NVT = TLI.getTypeToPromoteTo(ISD::VECTOR_SHUFFLE, VT); |
Duncan Sands | d038e04 | 2008-07-21 10:20:31 +0000 | [diff] [blame] | 326 | MVT EltVT = NVT.getVectorElementType(); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 327 | |
| 328 | // If we changed # elements, change the shuffle mask. |
| 329 | unsigned NumEltsGrowth = |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 330 | NVT.getVectorNumElements() / VT.getVectorNumElements(); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 331 | assert(NumEltsGrowth && "Cannot promote to vector type with fewer elts!"); |
| 332 | if (NumEltsGrowth > 1) { |
| 333 | // Renumber the elements. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 334 | SmallVector<SDValue, 8> Ops; |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 335 | for (unsigned i = 0, e = Mask.getNumOperands(); i != e; ++i) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 336 | SDValue InOp = Mask.getOperand(i); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 337 | for (unsigned j = 0; j != NumEltsGrowth; ++j) { |
| 338 | if (InOp.getOpcode() == ISD::UNDEF) |
Duncan Sands | d038e04 | 2008-07-21 10:20:31 +0000 | [diff] [blame] | 339 | Ops.push_back(DAG.getNode(ISD::UNDEF, EltVT)); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 340 | else { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 341 | unsigned InEltNo = cast<ConstantSDNode>(InOp)->getZExtValue(); |
Duncan Sands | d038e04 | 2008-07-21 10:20:31 +0000 | [diff] [blame] | 342 | Ops.push_back(DAG.getConstant(InEltNo*NumEltsGrowth+j, EltVT)); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 343 | } |
| 344 | } |
| 345 | } |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 346 | Mask = DAG.getNode(ISD::BUILD_VECTOR, NVT, &Ops[0], Ops.size()); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 347 | } |
| 348 | VT = NVT; |
| 349 | break; |
| 350 | } |
| 351 | } |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 352 | return TLI.isShuffleMaskLegal(Mask, VT) ? Mask.getNode() : 0; |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 353 | } |
| 354 | |
Duncan Sands | b6862bb | 2008-12-14 09:43:15 +0000 | [diff] [blame] | 355 | SelectionDAGLegalize::SelectionDAGLegalize(SelectionDAG &dag, bool types) |
| 356 | : TLI(dag.getTargetLoweringInfo()), DAG(dag), TypesNeedLegalizing(types), |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 357 | ValueTypeActions(TLI.getValueTypeActions()) { |
Nate Begeman | 6a64861 | 2005-11-29 05:45:29 +0000 | [diff] [blame] | 358 | assert(MVT::LAST_VALUETYPE <= 32 && |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 359 | "Too many value types for ValueTypeActions to hold!"); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 360 | } |
| 361 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 362 | void SelectionDAGLegalize::LegalizeDAG() { |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 363 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 364 | IsLegalizingCall = false; |
| 365 | |
Chris Lattner | ab510a7 | 2005-10-02 17:49:46 +0000 | [diff] [blame] | 366 | // The legalize process is inherently a bottom-up recursive process (users |
| 367 | // legalize their uses before themselves). Given infinite stack space, we |
| 368 | // could just start legalizing on the root and traverse the whole graph. In |
| 369 | // 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] | 370 | // blocks. To avoid this problem, compute an ordering of the nodes where each |
| 371 | // node is only legalized after all of its operands are legalized. |
Dan Gohman | f06c835 | 2008-09-30 18:30:35 +0000 | [diff] [blame] | 372 | DAG.AssignTopologicalOrder(); |
| 373 | for (SelectionDAG::allnodes_iterator I = DAG.allnodes_begin(), |
| 374 | E = prior(DAG.allnodes_end()); I != next(E); ++I) |
| 375 | HandleOp(SDValue(I, 0)); |
Chris Lattner | 32fca00 | 2005-10-06 01:20:27 +0000 | [diff] [blame] | 376 | |
| 377 | // Finally, it's possible the root changed. Get the new root. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 378 | SDValue OldRoot = DAG.getRoot(); |
Chris Lattner | 32fca00 | 2005-10-06 01:20:27 +0000 | [diff] [blame] | 379 | assert(LegalizedNodes.count(OldRoot) && "Root didn't get legalized?"); |
| 380 | DAG.setRoot(LegalizedNodes[OldRoot]); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 381 | |
| 382 | ExpandedNodes.clear(); |
| 383 | LegalizedNodes.clear(); |
Chris Lattner | 71c42a0 | 2005-01-16 01:11:45 +0000 | [diff] [blame] | 384 | PromotedNodes.clear(); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 385 | SplitNodes.clear(); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 386 | ScalarizedNodes.clear(); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 387 | WidenNodes.clear(); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 388 | |
| 389 | // Remove dead nodes now. |
Chris Lattner | 190a418 | 2006-08-04 17:45:20 +0000 | [diff] [blame] | 390 | DAG.RemoveDeadNodes(); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 391 | } |
| 392 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 393 | |
| 394 | /// FindCallEndFromCallStart - Given a chained node that is part of a call |
| 395 | /// sequence, find the CALLSEQ_END node that terminates the call sequence. |
| 396 | static SDNode *FindCallEndFromCallStart(SDNode *Node) { |
| 397 | if (Node->getOpcode() == ISD::CALLSEQ_END) |
| 398 | return Node; |
| 399 | if (Node->use_empty()) |
| 400 | return 0; // No CallSeqEnd |
| 401 | |
| 402 | // The chain is usually at the end. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 403 | SDValue TheChain(Node, Node->getNumValues()-1); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 404 | if (TheChain.getValueType() != MVT::Other) { |
| 405 | // Sometimes it's at the beginning. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 406 | TheChain = SDValue(Node, 0); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 407 | if (TheChain.getValueType() != MVT::Other) { |
| 408 | // Otherwise, hunt for it. |
| 409 | for (unsigned i = 1, e = Node->getNumValues(); i != e; ++i) |
| 410 | if (Node->getValueType(i) == MVT::Other) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 411 | TheChain = SDValue(Node, i); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 412 | break; |
| 413 | } |
| 414 | |
| 415 | // Otherwise, we walked into a node without a chain. |
| 416 | if (TheChain.getValueType() != MVT::Other) |
| 417 | return 0; |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | for (SDNode::use_iterator UI = Node->use_begin(), |
| 422 | E = Node->use_end(); UI != E; ++UI) { |
| 423 | |
| 424 | // Make sure to only follow users of our token chain. |
Dan Gohman | 8968450 | 2008-07-27 20:43:25 +0000 | [diff] [blame] | 425 | SDNode *User = *UI; |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 426 | for (unsigned i = 0, e = User->getNumOperands(); i != e; ++i) |
| 427 | if (User->getOperand(i) == TheChain) |
| 428 | if (SDNode *Result = FindCallEndFromCallStart(User)) |
| 429 | return Result; |
| 430 | } |
| 431 | return 0; |
| 432 | } |
| 433 | |
| 434 | /// FindCallStartFromCallEnd - Given a chained node that is part of a call |
| 435 | /// sequence, find the CALLSEQ_START node that initiates the call sequence. |
| 436 | static SDNode *FindCallStartFromCallEnd(SDNode *Node) { |
| 437 | assert(Node && "Didn't find callseq_start for a call??"); |
| 438 | if (Node->getOpcode() == ISD::CALLSEQ_START) return Node; |
| 439 | |
| 440 | assert(Node->getOperand(0).getValueType() == MVT::Other && |
| 441 | "Node doesn't have a token chain argument!"); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 442 | return FindCallStartFromCallEnd(Node->getOperand(0).getNode()); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | /// LegalizeAllNodesNotLeadingTo - Recursively walk the uses of N, looking to |
| 446 | /// see if any uses can reach Dest. If no dest operands can get to dest, |
| 447 | /// legalize them, legalize ourself, and return false, otherwise, return true. |
Chris Lattner | c9cf4f1 | 2006-07-26 23:55:56 +0000 | [diff] [blame] | 448 | /// |
| 449 | /// Keep track of the nodes we fine that actually do lead to Dest in |
| 450 | /// NodesLeadingTo. This avoids retraversing them exponential number of times. |
| 451 | /// |
| 452 | bool SelectionDAGLegalize::LegalizeAllNodesNotLeadingTo(SDNode *N, SDNode *Dest, |
Chris Lattner | 00755df | 2007-02-04 00:27:56 +0000 | [diff] [blame] | 453 | SmallPtrSet<SDNode*, 32> &NodesLeadingTo) { |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 454 | if (N == Dest) return true; // N certainly leads to Dest :) |
| 455 | |
Chris Lattner | c9cf4f1 | 2006-07-26 23:55:56 +0000 | [diff] [blame] | 456 | // If we've already processed this node and it does lead to Dest, there is no |
| 457 | // need to reprocess it. |
| 458 | if (NodesLeadingTo.count(N)) return true; |
| 459 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 460 | // If the first result of this node has been already legalized, then it cannot |
| 461 | // reach N. |
| 462 | switch (getTypeAction(N->getValueType(0))) { |
| 463 | case Legal: |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 464 | if (LegalizedNodes.count(SDValue(N, 0))) return false; |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 465 | break; |
| 466 | case Promote: |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 467 | if (PromotedNodes.count(SDValue(N, 0))) return false; |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 468 | break; |
| 469 | case Expand: |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 470 | if (ExpandedNodes.count(SDValue(N, 0))) return false; |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 471 | break; |
| 472 | } |
| 473 | |
| 474 | // Okay, this node has not already been legalized. Check and legalize all |
| 475 | // operands. If none lead to Dest, then we can legalize this node. |
| 476 | bool OperandsLeadToDest = false; |
| 477 | for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) |
| 478 | OperandsLeadToDest |= // If an operand leads to Dest, so do we. |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 479 | LegalizeAllNodesNotLeadingTo(N->getOperand(i).getNode(), Dest, NodesLeadingTo); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 480 | |
Chris Lattner | c9cf4f1 | 2006-07-26 23:55:56 +0000 | [diff] [blame] | 481 | if (OperandsLeadToDest) { |
| 482 | NodesLeadingTo.insert(N); |
| 483 | return true; |
| 484 | } |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 485 | |
| 486 | // Okay, this node looks safe, legalize it and return false. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 487 | HandleOp(SDValue(N, 0)); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 488 | return false; |
| 489 | } |
| 490 | |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 491 | /// HandleOp - Legalize, Promote, Widen, or Expand the specified operand as |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 492 | /// appropriate for its type. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 493 | void SelectionDAGLegalize::HandleOp(SDValue Op) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 494 | MVT VT = Op.getValueType(); |
Duncan Sands | b6862bb | 2008-12-14 09:43:15 +0000 | [diff] [blame] | 495 | // If the type legalizer was run then we should never see any illegal result |
| 496 | // types here except for target constants (the type legalizer does not touch |
Mon P Wang | 87c8a8f | 2008-12-18 20:03:17 +0000 | [diff] [blame] | 497 | // those) or for build vector used as a mask for a vector shuffle. |
| 498 | // FIXME: We can removed the BUILD_VECTOR case when we fix PR2957. |
Duncan Sands | b6862bb | 2008-12-14 09:43:15 +0000 | [diff] [blame] | 499 | assert((TypesNeedLegalizing || getTypeAction(VT) == Legal || |
Mon P Wang | 87c8a8f | 2008-12-18 20:03:17 +0000 | [diff] [blame] | 500 | Op.getOpcode() == ISD::TargetConstant || |
| 501 | Op.getOpcode() == ISD::BUILD_VECTOR) && |
Duncan Sands | b6862bb | 2008-12-14 09:43:15 +0000 | [diff] [blame] | 502 | "Illegal type introduced after type legalization?"); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 503 | switch (getTypeAction(VT)) { |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 504 | default: assert(0 && "Bad type action!"); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 505 | case Legal: (void)LegalizeOp(Op); break; |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 506 | case Promote: |
| 507 | if (!VT.isVector()) { |
| 508 | (void)PromoteOp(Op); |
| 509 | break; |
| 510 | } |
| 511 | else { |
| 512 | // See if we can widen otherwise use Expand to either scalarize or split |
| 513 | MVT WidenVT = TLI.getWidenVectorType(VT); |
| 514 | if (WidenVT != MVT::Other) { |
| 515 | (void) WidenVectorOp(Op, WidenVT); |
| 516 | break; |
| 517 | } |
| 518 | // else fall thru to expand since we can't widen the vector |
| 519 | } |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 520 | case Expand: |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 521 | if (!VT.isVector()) { |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 522 | // If this is an illegal scalar, expand it into its two component |
| 523 | // pieces. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 524 | SDValue X, Y; |
Chris Lattner | 09ec1b0 | 2007-08-25 01:00:22 +0000 | [diff] [blame] | 525 | if (Op.getOpcode() == ISD::TargetConstant) |
| 526 | break; // Allow illegal target nodes. |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 527 | ExpandOp(Op, X, Y); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 528 | } else if (VT.getVectorNumElements() == 1) { |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 529 | // If this is an illegal single element vector, convert it to a |
| 530 | // scalar operation. |
| 531 | (void)ScalarizeVectorOp(Op); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 532 | } else { |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 533 | // This is an illegal multiple element vector. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 534 | // Split it in half and legalize both parts. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 535 | SDValue X, Y; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 536 | SplitVectorOp(Op, X, Y); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 537 | } |
| 538 | break; |
| 539 | } |
| 540 | } |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 541 | |
Evan Cheng | 9f87788 | 2006-12-13 20:57:08 +0000 | [diff] [blame] | 542 | /// ExpandConstantFP - Expands the ConstantFP node to an integer constant or |
| 543 | /// a load from the constant pool. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 544 | static SDValue ExpandConstantFP(ConstantFPSDNode *CFP, bool UseCP, |
Dan Gohman | 0d137d7 | 2009-01-15 16:43:02 +0000 | [diff] [blame] | 545 | SelectionDAG &DAG, const TargetLowering &TLI) { |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 546 | bool Extend = false; |
| 547 | |
| 548 | // If a FP immediate is precise when represented as a float and if the |
| 549 | // target can do an extending load from float to double, we put it into |
| 550 | // 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] | 551 | // double. This shrinks FP constants and canonicalizes them for targets where |
| 552 | // an FP extending load is the same cost as a normal load (such as on the x87 |
| 553 | // fp stack or PPC FP unit). |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 554 | MVT VT = CFP->getValueType(0); |
Dan Gohman | 4fbd796 | 2008-09-12 18:08:03 +0000 | [diff] [blame] | 555 | ConstantFP *LLVMC = const_cast<ConstantFP*>(CFP->getConstantFPValue()); |
Evan Cheng | 9f87788 | 2006-12-13 20:57:08 +0000 | [diff] [blame] | 556 | if (!UseCP) { |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 557 | if (VT!=MVT::f64 && VT!=MVT::f32) |
| 558 | assert(0 && "Invalid type expansion"); |
Dale Johannesen | 7111b02 | 2008-10-09 18:53:47 +0000 | [diff] [blame] | 559 | return DAG.getConstant(LLVMC->getValueAPF().bitcastToAPInt(), |
Evan Cheng | ef12057 | 2008-03-04 08:05:30 +0000 | [diff] [blame] | 560 | (VT == MVT::f64) ? MVT::i64 : MVT::i32); |
Evan Cheng | 279101e | 2006-12-12 22:19:28 +0000 | [diff] [blame] | 561 | } |
| 562 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 563 | MVT OrigVT = VT; |
| 564 | MVT SVT = VT; |
Evan Cheng | ef12057 | 2008-03-04 08:05:30 +0000 | [diff] [blame] | 565 | while (SVT != MVT::f32) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 566 | SVT = (MVT::SimpleValueType)(SVT.getSimpleVT() - 1); |
Evan Cheng | ef12057 | 2008-03-04 08:05:30 +0000 | [diff] [blame] | 567 | if (CFP->isValueValidForType(SVT, CFP->getValueAPF()) && |
| 568 | // Only do this if the target has a native EXTLOAD instruction from |
| 569 | // smaller type. |
Evan Cheng | 0329466 | 2008-10-14 21:26:46 +0000 | [diff] [blame] | 570 | TLI.isLoadExtLegal(ISD::EXTLOAD, SVT) && |
Chris Lattner | aa2acbb | 2008-03-05 06:46:58 +0000 | [diff] [blame] | 571 | TLI.ShouldShrinkFPConstant(OrigVT)) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 572 | const Type *SType = SVT.getTypeForMVT(); |
Evan Cheng | ef12057 | 2008-03-04 08:05:30 +0000 | [diff] [blame] | 573 | LLVMC = cast<ConstantFP>(ConstantExpr::getFPTrunc(LLVMC, SType)); |
| 574 | VT = SVT; |
| 575 | Extend = true; |
| 576 | } |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 577 | } |
| 578 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 579 | SDValue CPIdx = DAG.getConstantPool(LLVMC, TLI.getPointerTy()); |
Dan Gohman | 50284d8 | 2008-09-16 22:05:41 +0000 | [diff] [blame] | 580 | unsigned Alignment = 1 << cast<ConstantPoolSDNode>(CPIdx)->getAlignment(); |
Evan Cheng | ef12057 | 2008-03-04 08:05:30 +0000 | [diff] [blame] | 581 | if (Extend) |
| 582 | return DAG.getExtLoad(ISD::EXTLOAD, OrigVT, DAG.getEntryNode(), |
Dan Gohman | 3069b87 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 583 | CPIdx, PseudoSourceValue::getConstantPool(), |
Dan Gohman | 50284d8 | 2008-09-16 22:05:41 +0000 | [diff] [blame] | 584 | 0, VT, false, Alignment); |
Evan Cheng | ef12057 | 2008-03-04 08:05:30 +0000 | [diff] [blame] | 585 | return DAG.getLoad(OrigVT, DAG.getEntryNode(), CPIdx, |
Dan Gohman | 50284d8 | 2008-09-16 22:05:41 +0000 | [diff] [blame] | 586 | PseudoSourceValue::getConstantPool(), 0, false, Alignment); |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 587 | } |
| 588 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 589 | |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 590 | /// ExpandFCOPYSIGNToBitwiseOps - Expands fcopysign to a series of bitwise |
| 591 | /// operations. |
| 592 | static |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 593 | SDValue ExpandFCOPYSIGNToBitwiseOps(SDNode *Node, MVT NVT, |
Dan Gohman | 0d137d7 | 2009-01-15 16:43:02 +0000 | [diff] [blame] | 594 | SelectionDAG &DAG, |
| 595 | const TargetLowering &TLI) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 596 | MVT VT = Node->getValueType(0); |
| 597 | MVT SrcVT = Node->getOperand(1).getValueType(); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 598 | assert((SrcVT == MVT::f32 || SrcVT == MVT::f64) && |
| 599 | "fcopysign expansion only supported for f32 and f64"); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 600 | MVT SrcNVT = (SrcVT == MVT::f64) ? MVT::i64 : MVT::i32; |
Evan Cheng | 068c5f4 | 2007-01-05 21:31:51 +0000 | [diff] [blame] | 601 | |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 602 | // First get the sign bit of second operand. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 603 | SDValue Mask1 = (SrcVT == MVT::f64) |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 604 | ? DAG.getConstantFP(BitsToDouble(1ULL << 63), SrcVT) |
| 605 | : DAG.getConstantFP(BitsToFloat(1U << 31), SrcVT); |
Evan Cheng | 068c5f4 | 2007-01-05 21:31:51 +0000 | [diff] [blame] | 606 | Mask1 = DAG.getNode(ISD::BIT_CONVERT, SrcNVT, Mask1); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 607 | SDValue SignBit= DAG.getNode(ISD::BIT_CONVERT, SrcNVT, Node->getOperand(1)); |
Evan Cheng | 068c5f4 | 2007-01-05 21:31:51 +0000 | [diff] [blame] | 608 | SignBit = DAG.getNode(ISD::AND, SrcNVT, SignBit, Mask1); |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 609 | // 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] | 610 | int SizeDiff = SrcNVT.getSizeInBits() - NVT.getSizeInBits(); |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 611 | if (SizeDiff > 0) { |
| 612 | SignBit = DAG.getNode(ISD::SRL, SrcNVT, SignBit, |
| 613 | DAG.getConstant(SizeDiff, TLI.getShiftAmountTy())); |
| 614 | SignBit = DAG.getNode(ISD::TRUNCATE, NVT, SignBit); |
Chris Lattner | c563e1d | 2008-07-10 23:46:13 +0000 | [diff] [blame] | 615 | } else if (SizeDiff < 0) { |
| 616 | SignBit = DAG.getNode(ISD::ZERO_EXTEND, NVT, SignBit); |
| 617 | SignBit = DAG.getNode(ISD::SHL, NVT, SignBit, |
| 618 | DAG.getConstant(-SizeDiff, TLI.getShiftAmountTy())); |
| 619 | } |
Evan Cheng | 068c5f4 | 2007-01-05 21:31:51 +0000 | [diff] [blame] | 620 | |
| 621 | // Clear the sign bit of first operand. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 622 | SDValue Mask2 = (VT == MVT::f64) |
Evan Cheng | 068c5f4 | 2007-01-05 21:31:51 +0000 | [diff] [blame] | 623 | ? DAG.getConstantFP(BitsToDouble(~(1ULL << 63)), VT) |
| 624 | : DAG.getConstantFP(BitsToFloat(~(1U << 31)), VT); |
| 625 | Mask2 = DAG.getNode(ISD::BIT_CONVERT, NVT, Mask2); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 626 | SDValue Result = DAG.getNode(ISD::BIT_CONVERT, NVT, Node->getOperand(0)); |
Evan Cheng | 068c5f4 | 2007-01-05 21:31:51 +0000 | [diff] [blame] | 627 | Result = DAG.getNode(ISD::AND, NVT, Result, Mask2); |
| 628 | |
| 629 | // Or the value with the sign bit. |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 630 | Result = DAG.getNode(ISD::OR, NVT, Result, SignBit); |
| 631 | return Result; |
| 632 | } |
| 633 | |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 634 | /// ExpandUnalignedStore - Expands an unaligned store to 2 half-size stores. |
| 635 | static |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 636 | SDValue ExpandUnalignedStore(StoreSDNode *ST, SelectionDAG &DAG, |
Dan Gohman | 0d137d7 | 2009-01-15 16:43:02 +0000 | [diff] [blame] | 637 | const TargetLowering &TLI) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 638 | SDValue Chain = ST->getChain(); |
| 639 | SDValue Ptr = ST->getBasePtr(); |
| 640 | SDValue Val = ST->getValue(); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 641 | MVT VT = Val.getValueType(); |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 642 | int Alignment = ST->getAlignment(); |
| 643 | int SVOffset = ST->getSrcValueOffset(); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 644 | if (ST->getMemoryVT().isFloatingPoint() || |
| 645 | ST->getMemoryVT().isVector()) { |
Duncan Sands | 05e11fa | 2008-12-12 21:47:02 +0000 | [diff] [blame] | 646 | MVT intVT = MVT::getIntegerVT(VT.getSizeInBits()); |
| 647 | if (TLI.isTypeLegal(intVT)) { |
| 648 | // Expand to a bitconvert of the value to the integer type of the |
| 649 | // same size, then a (misaligned) int store. |
| 650 | // FIXME: Does not handle truncating floating point stores! |
| 651 | SDValue Result = DAG.getNode(ISD::BIT_CONVERT, intVT, Val); |
| 652 | return DAG.getStore(Chain, Result, Ptr, ST->getSrcValue(), |
| 653 | SVOffset, ST->isVolatile(), Alignment); |
| 654 | } else { |
| 655 | // Do a (aligned) store to a stack slot, then copy from the stack slot |
| 656 | // to the final destination using (unaligned) integer loads and stores. |
| 657 | MVT StoredVT = ST->getMemoryVT(); |
| 658 | MVT RegVT = |
| 659 | TLI.getRegisterType(MVT::getIntegerVT(StoredVT.getSizeInBits())); |
| 660 | unsigned StoredBytes = StoredVT.getSizeInBits() / 8; |
| 661 | unsigned RegBytes = RegVT.getSizeInBits() / 8; |
| 662 | unsigned NumRegs = (StoredBytes + RegBytes - 1) / RegBytes; |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 663 | |
Duncan Sands | fd6673c | 2008-12-13 07:18:38 +0000 | [diff] [blame] | 664 | // Make sure the stack slot is also aligned for the register type. |
| 665 | SDValue StackPtr = DAG.CreateStackTemporary(StoredVT, RegVT); |
| 666 | |
| 667 | // Perform the original store, only redirected to the stack slot. |
Duncan Sands | 05e11fa | 2008-12-12 21:47:02 +0000 | [diff] [blame] | 668 | SDValue Store = DAG.getTruncStore(Chain, Val, StackPtr, NULL, 0,StoredVT); |
| 669 | SDValue Increment = DAG.getConstant(RegBytes, TLI.getPointerTy()); |
| 670 | SmallVector<SDValue, 8> Stores; |
| 671 | unsigned Offset = 0; |
| 672 | |
| 673 | // Do all but one copies using the full register width. |
| 674 | for (unsigned i = 1; i < NumRegs; i++) { |
| 675 | // Load one integer register's worth from the stack slot. |
| 676 | SDValue Load = DAG.getLoad(RegVT, Store, StackPtr, NULL, 0); |
| 677 | // Store it to the final location. Remember the store. |
| 678 | Stores.push_back(DAG.getStore(Load.getValue(1), Load, Ptr, |
| 679 | ST->getSrcValue(), SVOffset + Offset, |
| 680 | ST->isVolatile(), |
| 681 | MinAlign(ST->getAlignment(), Offset))); |
| 682 | // Increment the pointers. |
| 683 | Offset += RegBytes; |
| 684 | StackPtr = DAG.getNode(ISD::ADD, StackPtr.getValueType(), StackPtr, |
| 685 | Increment); |
| 686 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, Increment); |
| 687 | } |
| 688 | |
Duncan Sands | fd6673c | 2008-12-13 07:18:38 +0000 | [diff] [blame] | 689 | // The last store may be partial. Do a truncating store. On big-endian |
| 690 | // machines this requires an extending load from the stack slot to ensure |
| 691 | // that the bits are in the right place. |
| 692 | MVT MemVT = MVT::getIntegerVT(8 * (StoredBytes - Offset)); |
Duncan Sands | 05e11fa | 2008-12-12 21:47:02 +0000 | [diff] [blame] | 693 | |
Duncan Sands | fd6673c | 2008-12-13 07:18:38 +0000 | [diff] [blame] | 694 | // Load from the stack slot. |
| 695 | SDValue Load = DAG.getExtLoad(ISD::EXTLOAD, RegVT, Store, StackPtr, |
| 696 | NULL, 0, MemVT); |
| 697 | |
Duncan Sands | 05e11fa | 2008-12-12 21:47:02 +0000 | [diff] [blame] | 698 | Stores.push_back(DAG.getTruncStore(Load.getValue(1), Load, Ptr, |
| 699 | ST->getSrcValue(), SVOffset + Offset, |
Duncan Sands | fd6673c | 2008-12-13 07:18:38 +0000 | [diff] [blame] | 700 | MemVT, ST->isVolatile(), |
Duncan Sands | 05e11fa | 2008-12-12 21:47:02 +0000 | [diff] [blame] | 701 | MinAlign(ST->getAlignment(), Offset))); |
| 702 | // The order of the stores doesn't matter - say it with a TokenFactor. |
| 703 | return DAG.getNode(ISD::TokenFactor, MVT::Other, &Stores[0], |
| 704 | Stores.size()); |
| 705 | } |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 706 | } |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 707 | assert(ST->getMemoryVT().isInteger() && |
| 708 | !ST->getMemoryVT().isVector() && |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 709 | "Unaligned store of unknown type."); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 710 | // Get the half-size VT |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 711 | MVT NewStoredVT = |
| 712 | (MVT::SimpleValueType)(ST->getMemoryVT().getSimpleVT() - 1); |
| 713 | int NumBits = NewStoredVT.getSizeInBits(); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 714 | int IncrementSize = NumBits / 8; |
| 715 | |
| 716 | // Divide the stored value in two parts. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 717 | SDValue ShiftAmount = DAG.getConstant(NumBits, TLI.getShiftAmountTy()); |
| 718 | SDValue Lo = Val; |
| 719 | SDValue Hi = DAG.getNode(ISD::SRL, VT, Val, ShiftAmount); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 720 | |
| 721 | // Store the two parts |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 722 | SDValue Store1, Store2; |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 723 | Store1 = DAG.getTruncStore(Chain, TLI.isLittleEndian()?Lo:Hi, Ptr, |
| 724 | ST->getSrcValue(), SVOffset, NewStoredVT, |
| 725 | ST->isVolatile(), Alignment); |
| 726 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
| 727 | DAG.getConstant(IncrementSize, TLI.getPointerTy())); |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 728 | Alignment = MinAlign(Alignment, IncrementSize); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 729 | Store2 = DAG.getTruncStore(Chain, TLI.isLittleEndian()?Hi:Lo, Ptr, |
| 730 | ST->getSrcValue(), SVOffset + IncrementSize, |
| 731 | NewStoredVT, ST->isVolatile(), Alignment); |
| 732 | |
| 733 | return DAG.getNode(ISD::TokenFactor, MVT::Other, Store1, Store2); |
| 734 | } |
| 735 | |
| 736 | /// ExpandUnalignedLoad - Expands an unaligned load to 2 half-size loads. |
| 737 | static |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 738 | SDValue ExpandUnalignedLoad(LoadSDNode *LD, SelectionDAG &DAG, |
Dan Gohman | e9530ec | 2009-01-15 16:58:17 +0000 | [diff] [blame] | 739 | const TargetLowering &TLI) { |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 740 | int SVOffset = LD->getSrcValueOffset(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 741 | SDValue Chain = LD->getChain(); |
| 742 | SDValue Ptr = LD->getBasePtr(); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 743 | MVT VT = LD->getValueType(0); |
| 744 | MVT LoadedVT = LD->getMemoryVT(); |
| 745 | if (VT.isFloatingPoint() || VT.isVector()) { |
Duncan Sands | 05e11fa | 2008-12-12 21:47:02 +0000 | [diff] [blame] | 746 | MVT intVT = MVT::getIntegerVT(LoadedVT.getSizeInBits()); |
| 747 | if (TLI.isTypeLegal(intVT)) { |
| 748 | // Expand to a (misaligned) integer load of the same size, |
| 749 | // then bitconvert to floating point or vector. |
| 750 | SDValue newLoad = DAG.getLoad(intVT, Chain, Ptr, LD->getSrcValue(), |
| 751 | SVOffset, LD->isVolatile(), |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 752 | LD->getAlignment()); |
Duncan Sands | 05e11fa | 2008-12-12 21:47:02 +0000 | [diff] [blame] | 753 | SDValue Result = DAG.getNode(ISD::BIT_CONVERT, LoadedVT, newLoad); |
| 754 | if (VT.isFloatingPoint() && LoadedVT != VT) |
| 755 | Result = DAG.getNode(ISD::FP_EXTEND, VT, Result); |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 756 | |
Duncan Sands | 05e11fa | 2008-12-12 21:47:02 +0000 | [diff] [blame] | 757 | SDValue Ops[] = { Result, Chain }; |
| 758 | return DAG.getMergeValues(Ops, 2); |
| 759 | } else { |
| 760 | // Copy the value to a (aligned) stack slot using (unaligned) integer |
| 761 | // loads and stores, then do a (aligned) load from the stack slot. |
| 762 | MVT RegVT = TLI.getRegisterType(intVT); |
| 763 | unsigned LoadedBytes = LoadedVT.getSizeInBits() / 8; |
| 764 | unsigned RegBytes = RegVT.getSizeInBits() / 8; |
| 765 | unsigned NumRegs = (LoadedBytes + RegBytes - 1) / RegBytes; |
| 766 | |
Duncan Sands | fd6673c | 2008-12-13 07:18:38 +0000 | [diff] [blame] | 767 | // Make sure the stack slot is also aligned for the register type. |
| 768 | SDValue StackBase = DAG.CreateStackTemporary(LoadedVT, RegVT); |
| 769 | |
Duncan Sands | 05e11fa | 2008-12-12 21:47:02 +0000 | [diff] [blame] | 770 | SDValue Increment = DAG.getConstant(RegBytes, TLI.getPointerTy()); |
| 771 | SmallVector<SDValue, 8> Stores; |
| 772 | SDValue StackPtr = StackBase; |
| 773 | unsigned Offset = 0; |
| 774 | |
| 775 | // Do all but one copies using the full register width. |
| 776 | for (unsigned i = 1; i < NumRegs; i++) { |
| 777 | // Load one integer register's worth from the original location. |
| 778 | SDValue Load = DAG.getLoad(RegVT, Chain, Ptr, LD->getSrcValue(), |
| 779 | SVOffset + Offset, LD->isVolatile(), |
| 780 | MinAlign(LD->getAlignment(), Offset)); |
| 781 | // Follow the load with a store to the stack slot. Remember the store. |
| 782 | Stores.push_back(DAG.getStore(Load.getValue(1), Load, StackPtr, |
| 783 | NULL, 0)); |
| 784 | // Increment the pointers. |
| 785 | Offset += RegBytes; |
| 786 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, Increment); |
| 787 | StackPtr = DAG.getNode(ISD::ADD, StackPtr.getValueType(), StackPtr, |
| 788 | Increment); |
| 789 | } |
| 790 | |
| 791 | // The last copy may be partial. Do an extending load. |
Duncan Sands | fd6673c | 2008-12-13 07:18:38 +0000 | [diff] [blame] | 792 | MVT MemVT = MVT::getIntegerVT(8 * (LoadedBytes - Offset)); |
Duncan Sands | 05e11fa | 2008-12-12 21:47:02 +0000 | [diff] [blame] | 793 | SDValue Load = DAG.getExtLoad(ISD::EXTLOAD, RegVT, Chain, Ptr, |
| 794 | LD->getSrcValue(), SVOffset + Offset, |
Duncan Sands | fd6673c | 2008-12-13 07:18:38 +0000 | [diff] [blame] | 795 | MemVT, LD->isVolatile(), |
Duncan Sands | 05e11fa | 2008-12-12 21:47:02 +0000 | [diff] [blame] | 796 | MinAlign(LD->getAlignment(), Offset)); |
| 797 | // Follow the load with a store to the stack slot. Remember the store. |
Duncan Sands | fd6673c | 2008-12-13 07:18:38 +0000 | [diff] [blame] | 798 | // On big-endian machines this requires a truncating store to ensure |
| 799 | // that the bits end up in the right place. |
| 800 | Stores.push_back(DAG.getTruncStore(Load.getValue(1), Load, StackPtr, |
| 801 | NULL, 0, MemVT)); |
Duncan Sands | 05e11fa | 2008-12-12 21:47:02 +0000 | [diff] [blame] | 802 | |
| 803 | // The order of the stores doesn't matter - say it with a TokenFactor. |
| 804 | SDValue TF = DAG.getNode(ISD::TokenFactor, MVT::Other, &Stores[0], |
| 805 | Stores.size()); |
| 806 | |
| 807 | // Finally, perform the original load only redirected to the stack slot. |
| 808 | Load = DAG.getExtLoad(LD->getExtensionType(), VT, TF, StackBase, |
| 809 | NULL, 0, LoadedVT); |
| 810 | |
| 811 | // Callers expect a MERGE_VALUES node. |
| 812 | SDValue Ops[] = { Load, TF }; |
| 813 | return DAG.getMergeValues(Ops, 2); |
| 814 | } |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 815 | } |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 816 | assert(LoadedVT.isInteger() && !LoadedVT.isVector() && |
Chris Lattner | e400af8 | 2007-11-19 21:38:03 +0000 | [diff] [blame] | 817 | "Unaligned load of unsupported type."); |
| 818 | |
Dale Johannesen | 8155d64 | 2008-02-27 22:36:00 +0000 | [diff] [blame] | 819 | // Compute the new VT that is half the size of the old one. This is an |
| 820 | // integer MVT. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 821 | unsigned NumBits = LoadedVT.getSizeInBits(); |
| 822 | MVT NewLoadedVT; |
| 823 | NewLoadedVT = MVT::getIntegerVT(NumBits/2); |
Chris Lattner | e400af8 | 2007-11-19 21:38:03 +0000 | [diff] [blame] | 824 | NumBits >>= 1; |
| 825 | |
| 826 | unsigned Alignment = LD->getAlignment(); |
| 827 | unsigned IncrementSize = NumBits / 8; |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 828 | ISD::LoadExtType HiExtType = LD->getExtensionType(); |
| 829 | |
| 830 | // If the original load is NON_EXTLOAD, the hi part load must be ZEXTLOAD. |
| 831 | if (HiExtType == ISD::NON_EXTLOAD) |
| 832 | HiExtType = ISD::ZEXTLOAD; |
| 833 | |
| 834 | // Load the value in two parts |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 835 | SDValue Lo, Hi; |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 836 | if (TLI.isLittleEndian()) { |
| 837 | Lo = DAG.getExtLoad(ISD::ZEXTLOAD, VT, Chain, Ptr, LD->getSrcValue(), |
| 838 | SVOffset, NewLoadedVT, LD->isVolatile(), Alignment); |
| 839 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
| 840 | DAG.getConstant(IncrementSize, TLI.getPointerTy())); |
| 841 | Hi = DAG.getExtLoad(HiExtType, VT, Chain, Ptr, LD->getSrcValue(), |
| 842 | SVOffset + IncrementSize, NewLoadedVT, LD->isVolatile(), |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 843 | MinAlign(Alignment, IncrementSize)); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 844 | } else { |
| 845 | Hi = DAG.getExtLoad(HiExtType, VT, Chain, Ptr, LD->getSrcValue(), SVOffset, |
| 846 | NewLoadedVT,LD->isVolatile(), Alignment); |
| 847 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
| 848 | DAG.getConstant(IncrementSize, TLI.getPointerTy())); |
| 849 | Lo = DAG.getExtLoad(ISD::ZEXTLOAD, VT, Chain, Ptr, LD->getSrcValue(), |
| 850 | SVOffset + IncrementSize, NewLoadedVT, LD->isVolatile(), |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 851 | MinAlign(Alignment, IncrementSize)); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | // aggregate the two parts |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 855 | SDValue ShiftAmount = DAG.getConstant(NumBits, TLI.getShiftAmountTy()); |
| 856 | SDValue Result = DAG.getNode(ISD::SHL, VT, Hi, ShiftAmount); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 857 | Result = DAG.getNode(ISD::OR, VT, Result, Lo); |
| 858 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 859 | SDValue TF = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1), |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 860 | Hi.getValue(1)); |
| 861 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 862 | SDValue Ops[] = { Result, TF }; |
Duncan Sands | 4bdcb61 | 2008-07-02 17:40:58 +0000 | [diff] [blame] | 863 | return DAG.getMergeValues(Ops, 2); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 864 | } |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 865 | |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 866 | /// UnrollVectorOp - We know that the given vector has a legal type, however |
| 867 | /// the operation it performs is not legal and is an operation that we have |
| 868 | /// no way of lowering. "Unroll" the vector, splitting out the scalars and |
| 869 | /// operating on each element individually. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 870 | SDValue SelectionDAGLegalize::UnrollVectorOp(SDValue Op) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 871 | MVT VT = Op.getValueType(); |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 872 | assert(isTypeLegal(VT) && |
| 873 | "Caller should expand or promote operands that are not legal!"); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 874 | assert(Op.getNode()->getNumValues() == 1 && |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 875 | "Can't unroll a vector with multiple results!"); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 876 | unsigned NE = VT.getVectorNumElements(); |
| 877 | MVT EltVT = VT.getVectorElementType(); |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 878 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 879 | SmallVector<SDValue, 8> Scalars; |
| 880 | SmallVector<SDValue, 4> Operands(Op.getNumOperands()); |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 881 | for (unsigned i = 0; i != NE; ++i) { |
| 882 | for (unsigned j = 0; j != Op.getNumOperands(); ++j) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 883 | SDValue Operand = Op.getOperand(j); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 884 | MVT OperandVT = Operand.getValueType(); |
| 885 | if (OperandVT.isVector()) { |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 886 | // A vector operand; extract a single element. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 887 | MVT OperandEltVT = OperandVT.getVectorElementType(); |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 888 | Operands[j] = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, |
| 889 | OperandEltVT, |
| 890 | Operand, |
| 891 | DAG.getConstant(i, MVT::i32)); |
| 892 | } else { |
| 893 | // A scalar operand; just use it as is. |
| 894 | Operands[j] = Operand; |
| 895 | } |
| 896 | } |
Mon P Wang | e9f1015 | 2008-12-09 05:46:39 +0000 | [diff] [blame] | 897 | |
| 898 | switch (Op.getOpcode()) { |
| 899 | default: |
| 900 | Scalars.push_back(DAG.getNode(Op.getOpcode(), EltVT, |
| 901 | &Operands[0], Operands.size())); |
| 902 | break; |
| 903 | case ISD::SHL: |
| 904 | case ISD::SRA: |
| 905 | case ISD::SRL: |
| 906 | Scalars.push_back(DAG.getNode(Op.getOpcode(), EltVT, Operands[0], |
| 907 | LegalizeShiftAmount(Operands[1]))); |
| 908 | break; |
| 909 | } |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 910 | } |
| 911 | |
| 912 | return DAG.getNode(ISD::BUILD_VECTOR, VT, &Scalars[0], Scalars.size()); |
| 913 | } |
| 914 | |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 915 | /// GetFPLibCall - Return the right libcall for the given floating point type. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 916 | static RTLIB::Libcall GetFPLibCall(MVT VT, |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 917 | RTLIB::Libcall Call_F32, |
| 918 | RTLIB::Libcall Call_F64, |
| 919 | RTLIB::Libcall Call_F80, |
| 920 | RTLIB::Libcall Call_PPCF128) { |
| 921 | return |
| 922 | VT == MVT::f32 ? Call_F32 : |
| 923 | VT == MVT::f64 ? Call_F64 : |
| 924 | VT == MVT::f80 ? Call_F80 : |
| 925 | VT == MVT::ppcf128 ? Call_PPCF128 : |
| 926 | RTLIB::UNKNOWN_LIBCALL; |
| 927 | } |
| 928 | |
Nate Begeman | 6867991 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 929 | /// PerformInsertVectorEltInMemory - Some target cannot handle a variable |
| 930 | /// insertion index for the INSERT_VECTOR_ELT instruction. In this case, it |
| 931 | /// is necessary to spill the vector being inserted into to memory, perform |
| 932 | /// the insert there, and then read the result back. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 933 | SDValue SelectionDAGLegalize:: |
| 934 | PerformInsertVectorEltInMemory(SDValue Vec, SDValue Val, SDValue Idx) { |
| 935 | SDValue Tmp1 = Vec; |
| 936 | SDValue Tmp2 = Val; |
| 937 | SDValue Tmp3 = Idx; |
Nate Begeman | 6867991 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 938 | |
| 939 | // If the target doesn't support this, we have to spill the input vector |
| 940 | // to a temporary stack slot, update the element, then reload it. This is |
| 941 | // badness. We could also load the value into a vector register (either |
| 942 | // with a "move to register" or "extload into register" instruction, then |
| 943 | // permute it into place, if the idx is a constant and if the idx is |
| 944 | // supported by the target. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 945 | MVT VT = Tmp1.getValueType(); |
| 946 | MVT EltVT = VT.getVectorElementType(); |
| 947 | MVT IdxVT = Tmp3.getValueType(); |
| 948 | MVT PtrVT = TLI.getPointerTy(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 949 | SDValue StackPtr = DAG.CreateStackTemporary(VT); |
Nate Begeman | 6867991 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 950 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 951 | int SPFI = cast<FrameIndexSDNode>(StackPtr.getNode())->getIndex(); |
Nate Begeman | 6867991 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 952 | |
| 953 | // Store the vector. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 954 | SDValue Ch = DAG.getStore(DAG.getEntryNode(), Tmp1, StackPtr, |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 955 | PseudoSourceValue::getFixedStack(SPFI), 0); |
Nate Begeman | 6867991 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 956 | |
| 957 | // Truncate or zero extend offset to target pointer type. |
Duncan Sands | 8e4eb09 | 2008-06-08 20:54:56 +0000 | [diff] [blame] | 958 | unsigned CastOpc = IdxVT.bitsGT(PtrVT) ? ISD::TRUNCATE : ISD::ZERO_EXTEND; |
Nate Begeman | 6867991 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 959 | Tmp3 = DAG.getNode(CastOpc, PtrVT, Tmp3); |
| 960 | // Add the offset to the index. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 961 | unsigned EltSize = EltVT.getSizeInBits()/8; |
Nate Begeman | 6867991 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 962 | Tmp3 = DAG.getNode(ISD::MUL, IdxVT, Tmp3,DAG.getConstant(EltSize, IdxVT)); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 963 | SDValue StackPtr2 = DAG.getNode(ISD::ADD, IdxVT, Tmp3, StackPtr); |
Nate Begeman | 6867991 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 964 | // Store the scalar value. |
| 965 | Ch = DAG.getTruncStore(Ch, Tmp2, StackPtr2, |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 966 | PseudoSourceValue::getFixedStack(SPFI), 0, EltVT); |
Nate Begeman | 6867991 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 967 | // Load the updated vector. |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 968 | return DAG.getLoad(VT, Ch, StackPtr, |
| 969 | PseudoSourceValue::getFixedStack(SPFI), 0); |
Nate Begeman | 6867991 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 970 | } |
| 971 | |
Mon P Wang | e9f1015 | 2008-12-09 05:46:39 +0000 | [diff] [blame] | 972 | SDValue SelectionDAGLegalize::LegalizeShiftAmount(SDValue ShiftAmt) { |
| 973 | if (TLI.getShiftAmountTy().bitsLT(ShiftAmt.getValueType())) |
| 974 | return DAG.getNode(ISD::TRUNCATE, TLI.getShiftAmountTy(), ShiftAmt); |
| 975 | |
| 976 | if (TLI.getShiftAmountTy().bitsGT(ShiftAmt.getValueType())) |
| 977 | return DAG.getNode(ISD::ANY_EXTEND, TLI.getShiftAmountTy(), ShiftAmt); |
| 978 | |
| 979 | return ShiftAmt; |
| 980 | } |
| 981 | |
| 982 | |
Dan Gohman | a346615 | 2007-07-13 20:14:11 +0000 | [diff] [blame] | 983 | /// LegalizeOp - We know that the specified value has a legal type, and |
| 984 | /// that its operands are legal. Now ensure that the operation itself |
| 985 | /// is legal, recursively ensuring that the operands' operations remain |
| 986 | /// legal. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 987 | SDValue SelectionDAGLegalize::LegalizeOp(SDValue Op) { |
Chris Lattner | 09ec1b0 | 2007-08-25 01:00:22 +0000 | [diff] [blame] | 988 | if (Op.getOpcode() == ISD::TargetConstant) // Allow illegal target nodes. |
| 989 | return Op; |
| 990 | |
Chris Lattner | c9c60f6 | 2005-08-24 16:35:28 +0000 | [diff] [blame] | 991 | assert(isTypeLegal(Op.getValueType()) && |
Chris Lattner | e3304a3 | 2005-01-08 20:35:13 +0000 | [diff] [blame] | 992 | "Caller should expand or promote operands that are not legal!"); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 993 | SDNode *Node = Op.getNode(); |
Chris Lattner | e3304a3 | 2005-01-08 20:35:13 +0000 | [diff] [blame] | 994 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 995 | // If this operation defines any values that cannot be represented in a |
Chris Lattner | e3304a3 | 2005-01-08 20:35:13 +0000 | [diff] [blame] | 996 | // register on this target, make sure to expand or promote them. |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 997 | if (Node->getNumValues() > 1) { |
| 998 | for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 999 | if (getTypeAction(Node->getValueType(i)) != Legal) { |
| 1000 | HandleOp(Op.getValue(i)); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1001 | assert(LegalizedNodes.count(Op) && |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 1002 | "Handling didn't add legal operands!"); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 1003 | return LegalizedNodes[Op]; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1004 | } |
| 1005 | } |
| 1006 | |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 1007 | // Note that LegalizeOp may be reentered even from single-use nodes, which |
| 1008 | // means that we always must cache transformed nodes. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1009 | DenseMap<SDValue, SDValue>::iterator I = LegalizedNodes.find(Op); |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 1010 | if (I != LegalizedNodes.end()) return I->second; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1011 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1012 | SDValue Tmp1, Tmp2, Tmp3, Tmp4; |
| 1013 | SDValue Result = Op; |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 1014 | bool isCustom = false; |
| 1015 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1016 | switch (Node->getOpcode()) { |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 1017 | case ISD::FrameIndex: |
| 1018 | case ISD::EntryToken: |
| 1019 | case ISD::Register: |
| 1020 | case ISD::BasicBlock: |
| 1021 | case ISD::TargetFrameIndex: |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 1022 | case ISD::TargetJumpTable: |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 1023 | case ISD::TargetConstant: |
Chris Lattner | 3181a77 | 2006-01-29 06:26:56 +0000 | [diff] [blame] | 1024 | case ISD::TargetConstantFP: |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 1025 | case ISD::TargetConstantPool: |
| 1026 | case ISD::TargetGlobalAddress: |
Lauro Ramos Venancio | b3a0417 | 2007-04-20 21:38:10 +0000 | [diff] [blame] | 1027 | case ISD::TargetGlobalTLSAddress: |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 1028 | case ISD::TargetExternalSymbol: |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 1029 | case ISD::VALUETYPE: |
| 1030 | case ISD::SRCVALUE: |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 1031 | case ISD::MEMOPERAND: |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 1032 | case ISD::CONDCODE: |
Duncan Sands | 276dcbd | 2008-03-21 09:14:45 +0000 | [diff] [blame] | 1033 | case ISD::ARG_FLAGS: |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 1034 | // Primitives must all be legal. |
Duncan Sands | a7c97a7 | 2007-10-16 09:07:20 +0000 | [diff] [blame] | 1035 | assert(TLI.isOperationLegal(Node->getOpcode(), Node->getValueType(0)) && |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 1036 | "This must be legal!"); |
| 1037 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1038 | default: |
Chris Lattner | d73cc5d | 2005-05-14 06:34:48 +0000 | [diff] [blame] | 1039 | if (Node->getOpcode() >= ISD::BUILTIN_OP_END) { |
| 1040 | // If this is a target node, legalize it by legalizing the operands then |
| 1041 | // passing it through. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1042 | SmallVector<SDValue, 8> Ops; |
Chris Lattner | c5d7d7c | 2006-05-17 18:00:08 +0000 | [diff] [blame] | 1043 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) |
Chris Lattner | d73cc5d | 2005-05-14 06:34:48 +0000 | [diff] [blame] | 1044 | Ops.push_back(LegalizeOp(Node->getOperand(i))); |
Chris Lattner | c5d7d7c | 2006-05-17 18:00:08 +0000 | [diff] [blame] | 1045 | |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1046 | Result = DAG.UpdateNodeOperands(Result.getValue(0), &Ops[0], Ops.size()); |
Chris Lattner | d73cc5d | 2005-05-14 06:34:48 +0000 | [diff] [blame] | 1047 | |
| 1048 | for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) |
| 1049 | AddLegalizedOperand(Op.getValue(i), Result.getValue(i)); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 1050 | return Result.getValue(Op.getResNo()); |
Chris Lattner | d73cc5d | 2005-05-14 06:34:48 +0000 | [diff] [blame] | 1051 | } |
| 1052 | // Otherwise this is an unhandled builtin node. splat. |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 1053 | #ifndef NDEBUG |
Dan Gohman | 3983358 | 2007-06-04 16:17:33 +0000 | [diff] [blame] | 1054 | cerr << "NODE: "; Node->dump(&DAG); cerr << "\n"; |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 1055 | #endif |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1056 | assert(0 && "Do not know how to legalize this operator!"); |
| 1057 | abort(); |
Lauro Ramos Venancio | 0d3b678 | 2007-04-20 23:02:39 +0000 | [diff] [blame] | 1058 | case ISD::GLOBAL_OFFSET_TABLE: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1059 | case ISD::GlobalAddress: |
Lauro Ramos Venancio | b3a0417 | 2007-04-20 21:38:10 +0000 | [diff] [blame] | 1060 | case ISD::GlobalTLSAddress: |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 1061 | case ISD::ExternalSymbol: |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 1062 | case ISD::ConstantPool: |
| 1063 | case ISD::JumpTable: // Nothing to do. |
Chris Lattner | 0c8fbe3 | 2005-11-17 06:41:44 +0000 | [diff] [blame] | 1064 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 1065 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 1066 | case TargetLowering::Custom: |
| 1067 | Tmp1 = TLI.LowerOperation(Op, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1068 | if (Tmp1.getNode()) Result = Tmp1; |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 1069 | // 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] | 1070 | case TargetLowering::Legal: |
Chris Lattner | 0c8fbe3 | 2005-11-17 06:41:44 +0000 | [diff] [blame] | 1071 | break; |
| 1072 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1073 | break; |
Nate Begeman | bcc5f36 | 2007-01-29 22:58:52 +0000 | [diff] [blame] | 1074 | case ISD::FRAMEADDR: |
| 1075 | case ISD::RETURNADDR: |
| 1076 | // The only option for these nodes is to custom lower them. If the target |
| 1077 | // does not custom lower them, then return zero. |
| 1078 | Tmp1 = TLI.LowerOperation(Op, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1079 | if (Tmp1.getNode()) |
Nate Begeman | bcc5f36 | 2007-01-29 22:58:52 +0000 | [diff] [blame] | 1080 | Result = Tmp1; |
| 1081 | else |
| 1082 | Result = DAG.getConstant(0, TLI.getPointerTy()); |
| 1083 | break; |
Anton Korobeynikov | 055c544 | 2007-08-29 23:18:48 +0000 | [diff] [blame] | 1084 | case ISD::FRAME_TO_ARGS_OFFSET: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1085 | MVT VT = Node->getValueType(0); |
Anton Korobeynikov | 066f7b4 | 2007-08-29 19:28:29 +0000 | [diff] [blame] | 1086 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 1087 | default: assert(0 && "This action is not supported yet!"); |
| 1088 | case TargetLowering::Custom: |
| 1089 | Result = TLI.LowerOperation(Op, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1090 | if (Result.getNode()) break; |
Anton Korobeynikov | 066f7b4 | 2007-08-29 19:28:29 +0000 | [diff] [blame] | 1091 | // Fall Thru |
| 1092 | case TargetLowering::Legal: |
| 1093 | Result = DAG.getConstant(0, VT); |
| 1094 | break; |
| 1095 | } |
Anton Korobeynikov | 055c544 | 2007-08-29 23:18:48 +0000 | [diff] [blame] | 1096 | } |
Anton Korobeynikov | 066f7b4 | 2007-08-29 19:28:29 +0000 | [diff] [blame] | 1097 | break; |
Jim Laskey | 2bc210d | 2007-02-22 15:37:19 +0000 | [diff] [blame] | 1098 | case ISD::EXCEPTIONADDR: { |
| 1099 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1100 | MVT VT = Node->getValueType(0); |
Jim Laskey | 2bc210d | 2007-02-22 15:37:19 +0000 | [diff] [blame] | 1101 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 1102 | default: assert(0 && "This action is not supported yet!"); |
| 1103 | case TargetLowering::Expand: { |
Jim Laskey | 8782d48 | 2007-02-28 20:43:58 +0000 | [diff] [blame] | 1104 | unsigned Reg = TLI.getExceptionAddressRegister(); |
Duncan Sands | b027fa0 | 2007-12-31 18:35:50 +0000 | [diff] [blame] | 1105 | Result = DAG.getCopyFromReg(Tmp1, Reg, VT); |
Jim Laskey | 2bc210d | 2007-02-22 15:37:19 +0000 | [diff] [blame] | 1106 | } |
| 1107 | break; |
| 1108 | case TargetLowering::Custom: |
| 1109 | Result = TLI.LowerOperation(Op, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1110 | if (Result.getNode()) break; |
Jim Laskey | 2bc210d | 2007-02-22 15:37:19 +0000 | [diff] [blame] | 1111 | // Fall Thru |
Chris Lattner | eb7f34f | 2007-04-27 17:12:52 +0000 | [diff] [blame] | 1112 | case TargetLowering::Legal: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1113 | SDValue Ops[] = { DAG.getConstant(0, VT), Tmp1 }; |
Duncan Sands | 4bdcb61 | 2008-07-02 17:40:58 +0000 | [diff] [blame] | 1114 | Result = DAG.getMergeValues(Ops, 2); |
Jim Laskey | 2bc210d | 2007-02-22 15:37:19 +0000 | [diff] [blame] | 1115 | break; |
| 1116 | } |
| 1117 | } |
Chris Lattner | eb7f34f | 2007-04-27 17:12:52 +0000 | [diff] [blame] | 1118 | } |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1119 | if (Result.getNode()->getNumValues() == 1) break; |
Duncan Sands | b027fa0 | 2007-12-31 18:35:50 +0000 | [diff] [blame] | 1120 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1121 | assert(Result.getNode()->getNumValues() == 2 && |
Duncan Sands | b027fa0 | 2007-12-31 18:35:50 +0000 | [diff] [blame] | 1122 | "Cannot return more than two values!"); |
| 1123 | |
| 1124 | // Since we produced two values, make sure to remember that we |
| 1125 | // legalized both of them. |
| 1126 | Tmp1 = LegalizeOp(Result); |
| 1127 | Tmp2 = LegalizeOp(Result.getValue(1)); |
| 1128 | AddLegalizedOperand(Op.getValue(0), Tmp1); |
| 1129 | AddLegalizedOperand(Op.getValue(1), Tmp2); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 1130 | return Op.getResNo() ? Tmp2 : Tmp1; |
Jim Laskey | 8782d48 | 2007-02-28 20:43:58 +0000 | [diff] [blame] | 1131 | case ISD::EHSELECTION: { |
| 1132 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1133 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1134 | MVT VT = Node->getValueType(0); |
Jim Laskey | 8782d48 | 2007-02-28 20:43:58 +0000 | [diff] [blame] | 1135 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 1136 | default: assert(0 && "This action is not supported yet!"); |
| 1137 | case TargetLowering::Expand: { |
| 1138 | unsigned Reg = TLI.getExceptionSelectorRegister(); |
Duncan Sands | b027fa0 | 2007-12-31 18:35:50 +0000 | [diff] [blame] | 1139 | Result = DAG.getCopyFromReg(Tmp2, Reg, VT); |
Jim Laskey | 8782d48 | 2007-02-28 20:43:58 +0000 | [diff] [blame] | 1140 | } |
| 1141 | break; |
| 1142 | case TargetLowering::Custom: |
| 1143 | Result = TLI.LowerOperation(Op, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1144 | if (Result.getNode()) break; |
Jim Laskey | 8782d48 | 2007-02-28 20:43:58 +0000 | [diff] [blame] | 1145 | // Fall Thru |
Chris Lattner | eb7f34f | 2007-04-27 17:12:52 +0000 | [diff] [blame] | 1146 | case TargetLowering::Legal: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1147 | SDValue Ops[] = { DAG.getConstant(0, VT), Tmp2 }; |
Duncan Sands | 4bdcb61 | 2008-07-02 17:40:58 +0000 | [diff] [blame] | 1148 | Result = DAG.getMergeValues(Ops, 2); |
Jim Laskey | 8782d48 | 2007-02-28 20:43:58 +0000 | [diff] [blame] | 1149 | break; |
| 1150 | } |
| 1151 | } |
Chris Lattner | eb7f34f | 2007-04-27 17:12:52 +0000 | [diff] [blame] | 1152 | } |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1153 | if (Result.getNode()->getNumValues() == 1) break; |
Duncan Sands | b027fa0 | 2007-12-31 18:35:50 +0000 | [diff] [blame] | 1154 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1155 | assert(Result.getNode()->getNumValues() == 2 && |
Duncan Sands | b027fa0 | 2007-12-31 18:35:50 +0000 | [diff] [blame] | 1156 | "Cannot return more than two values!"); |
| 1157 | |
| 1158 | // Since we produced two values, make sure to remember that we |
| 1159 | // legalized both of them. |
| 1160 | Tmp1 = LegalizeOp(Result); |
| 1161 | Tmp2 = LegalizeOp(Result.getValue(1)); |
| 1162 | AddLegalizedOperand(Op.getValue(0), Tmp1); |
| 1163 | AddLegalizedOperand(Op.getValue(1), Tmp2); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 1164 | return Op.getResNo() ? Tmp2 : Tmp1; |
Nick Lewycky | 6d4b711 | 2007-07-14 15:11:14 +0000 | [diff] [blame] | 1165 | case ISD::EH_RETURN: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1166 | MVT VT = Node->getValueType(0); |
Anton Korobeynikov | 2365f51 | 2007-07-14 14:06:15 +0000 | [diff] [blame] | 1167 | // The only "good" option for this node is to custom lower it. |
| 1168 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 1169 | default: assert(0 && "This action is not supported at all!"); |
| 1170 | case TargetLowering::Custom: |
| 1171 | Result = TLI.LowerOperation(Op, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1172 | if (Result.getNode()) break; |
Anton Korobeynikov | 2365f51 | 2007-07-14 14:06:15 +0000 | [diff] [blame] | 1173 | // Fall Thru |
| 1174 | case TargetLowering::Legal: |
| 1175 | // Target does not know, how to lower this, lower to noop |
| 1176 | Result = LegalizeOp(Node->getOperand(0)); |
| 1177 | break; |
| 1178 | } |
Nick Lewycky | 6d4b711 | 2007-07-14 15:11:14 +0000 | [diff] [blame] | 1179 | } |
Anton Korobeynikov | 2365f51 | 2007-07-14 14:06:15 +0000 | [diff] [blame] | 1180 | break; |
Chris Lattner | 08951a3 | 2005-09-02 01:15:01 +0000 | [diff] [blame] | 1181 | case ISD::AssertSext: |
| 1182 | case ISD::AssertZext: |
| 1183 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1184 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
Chris Lattner | 08951a3 | 2005-09-02 01:15:01 +0000 | [diff] [blame] | 1185 | break; |
Chris Lattner | 308575b | 2005-11-20 22:56:56 +0000 | [diff] [blame] | 1186 | case ISD::MERGE_VALUES: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1187 | // Legalize eliminates MERGE_VALUES nodes. |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 1188 | Result = Node->getOperand(Op.getResNo()); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 1189 | break; |
Chris Lattner | 69a5215 | 2005-01-14 22:38:01 +0000 | [diff] [blame] | 1190 | case ISD::CopyFromReg: |
| 1191 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 1192 | Result = Op.getValue(0); |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 1193 | if (Node->getNumValues() == 2) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1194 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 1195 | } else { |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 1196 | assert(Node->getNumValues() == 3 && "Invalid copyfromreg!"); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1197 | if (Node->getNumOperands() == 3) { |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 1198 | Tmp2 = LegalizeOp(Node->getOperand(2)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1199 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1),Tmp2); |
| 1200 | } else { |
| 1201 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
| 1202 | } |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 1203 | AddLegalizedOperand(Op.getValue(2), Result.getValue(2)); |
| 1204 | } |
Chris Lattner | 13c184d | 2005-01-28 06:27:38 +0000 | [diff] [blame] | 1205 | // Since CopyFromReg produces two values, make sure to remember that we |
| 1206 | // legalized both of them. |
| 1207 | AddLegalizedOperand(Op.getValue(0), Result); |
| 1208 | AddLegalizedOperand(Op.getValue(1), Result.getValue(1)); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 1209 | return Result.getValue(Op.getResNo()); |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 1210 | case ISD::UNDEF: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1211 | MVT VT = Op.getValueType(); |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 1212 | switch (TLI.getOperationAction(ISD::UNDEF, VT)) { |
Nate Begeman | ea19cd5 | 2005-04-02 00:41:14 +0000 | [diff] [blame] | 1213 | default: assert(0 && "This action is not supported yet!"); |
| 1214 | case TargetLowering::Expand: |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1215 | if (VT.isInteger()) |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 1216 | Result = DAG.getConstant(0, VT); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1217 | else if (VT.isFloatingPoint()) |
| 1218 | Result = DAG.getConstantFP(APFloat(APInt(VT.getSizeInBits(), 0)), |
Dale Johannesen | f41db21 | 2007-09-26 17:26:49 +0000 | [diff] [blame] | 1219 | VT); |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 1220 | else |
| 1221 | assert(0 && "Unknown value type!"); |
| 1222 | break; |
Nate Begeman | ea19cd5 | 2005-04-02 00:41:14 +0000 | [diff] [blame] | 1223 | case TargetLowering::Legal: |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 1224 | break; |
| 1225 | } |
| 1226 | break; |
| 1227 | } |
Chris Lattner | d1f04d4 | 2006-03-24 02:26:29 +0000 | [diff] [blame] | 1228 | |
Chris Lattner | 48b61a7 | 2006-03-28 00:40:33 +0000 | [diff] [blame] | 1229 | case ISD::INTRINSIC_W_CHAIN: |
| 1230 | case ISD::INTRINSIC_WO_CHAIN: |
| 1231 | case ISD::INTRINSIC_VOID: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1232 | SmallVector<SDValue, 8> Ops; |
Chris Lattner | d1f04d4 | 2006-03-24 02:26:29 +0000 | [diff] [blame] | 1233 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) |
| 1234 | Ops.push_back(LegalizeOp(Node->getOperand(i))); |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1235 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 10d7fa6 | 2006-03-26 09:12:51 +0000 | [diff] [blame] | 1236 | |
| 1237 | // Allow the target to custom lower its intrinsics if it wants to. |
Chris Lattner | 48b61a7 | 2006-03-28 00:40:33 +0000 | [diff] [blame] | 1238 | if (TLI.getOperationAction(Node->getOpcode(), MVT::Other) == |
Chris Lattner | 10d7fa6 | 2006-03-26 09:12:51 +0000 | [diff] [blame] | 1239 | TargetLowering::Custom) { |
| 1240 | Tmp3 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1241 | if (Tmp3.getNode()) Result = Tmp3; |
Chris Lattner | 13fc2f1 | 2006-03-27 20:28:29 +0000 | [diff] [blame] | 1242 | } |
| 1243 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1244 | if (Result.getNode()->getNumValues() == 1) break; |
Chris Lattner | 13fc2f1 | 2006-03-27 20:28:29 +0000 | [diff] [blame] | 1245 | |
| 1246 | // Must have return value and chain result. |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1247 | assert(Result.getNode()->getNumValues() == 2 && |
Chris Lattner | 13fc2f1 | 2006-03-27 20:28:29 +0000 | [diff] [blame] | 1248 | "Cannot return more than two values!"); |
| 1249 | |
| 1250 | // Since loads produce two values, make sure to remember that we |
| 1251 | // legalized both of them. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1252 | AddLegalizedOperand(SDValue(Node, 0), Result.getValue(0)); |
| 1253 | AddLegalizedOperand(SDValue(Node, 1), Result.getValue(1)); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 1254 | return Result.getValue(Op.getResNo()); |
Chris Lattner | d1f04d4 | 2006-03-24 02:26:29 +0000 | [diff] [blame] | 1255 | } |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 1256 | |
Dan Gohman | 7f46020 | 2008-06-30 20:59:49 +0000 | [diff] [blame] | 1257 | case ISD::DBG_STOPPOINT: |
| 1258 | assert(Node->getNumOperands() == 1 && "Invalid DBG_STOPPOINT node!"); |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 1259 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the input chain. |
| 1260 | |
Dan Gohman | 7f46020 | 2008-06-30 20:59:49 +0000 | [diff] [blame] | 1261 | switch (TLI.getOperationAction(ISD::DBG_STOPPOINT, MVT::Other)) { |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 1262 | case TargetLowering::Promote: |
| 1263 | default: assert(0 && "This action is not supported yet!"); |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 1264 | case TargetLowering::Expand: { |
Devang Patel | 83489bb | 2009-01-13 00:35:13 +0000 | [diff] [blame] | 1265 | DwarfWriter *DW = DAG.getDwarfWriter(); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1266 | bool useDEBUG_LOC = TLI.isOperationLegal(ISD::DEBUG_LOC, MVT::Other); |
Dan Gohman | 4406604 | 2008-07-01 00:05:16 +0000 | [diff] [blame] | 1267 | bool useLABEL = TLI.isOperationLegal(ISD::DBG_LABEL, MVT::Other); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1268 | |
Dan Gohman | 7f46020 | 2008-06-30 20:59:49 +0000 | [diff] [blame] | 1269 | const DbgStopPointSDNode *DSP = cast<DbgStopPointSDNode>(Node); |
Devang Patel | 83489bb | 2009-01-13 00:35:13 +0000 | [diff] [blame] | 1270 | GlobalVariable *CU_GV = cast<GlobalVariable>(DSP->getCompileUnit()); |
| 1271 | if (DW && (useDEBUG_LOC || useLABEL) && !CU_GV->isDeclaration()) { |
| 1272 | DICompileUnit CU(cast<GlobalVariable>(DSP->getCompileUnit())); |
| 1273 | unsigned SrcFile = DW->RecordSource(CU.getDirectory(), |
| 1274 | CU.getFilename()); |
| 1275 | |
Dan Gohman | 7f46020 | 2008-06-30 20:59:49 +0000 | [diff] [blame] | 1276 | unsigned Line = DSP->getLine(); |
| 1277 | unsigned Col = DSP->getColumn(); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1278 | |
| 1279 | if (useDEBUG_LOC) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1280 | SDValue Ops[] = { Tmp1, DAG.getConstant(Line, MVT::i32), |
Evan Cheng | 71e8685 | 2008-07-08 20:06:39 +0000 | [diff] [blame] | 1281 | DAG.getConstant(Col, MVT::i32), |
| 1282 | DAG.getConstant(SrcFile, MVT::i32) }; |
| 1283 | Result = DAG.getNode(ISD::DEBUG_LOC, MVT::Other, Ops, 4); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1284 | } else { |
Devang Patel | 83489bb | 2009-01-13 00:35:13 +0000 | [diff] [blame] | 1285 | unsigned ID = DW->RecordSourceLine(Line, Col, SrcFile); |
Dan Gohman | 4406604 | 2008-07-01 00:05:16 +0000 | [diff] [blame] | 1286 | Result = DAG.getLabel(ISD::DBG_LABEL, Tmp1, ID); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1287 | } |
Jim Laskey | e81aecb | 2005-12-21 20:51:37 +0000 | [diff] [blame] | 1288 | } else { |
| 1289 | Result = Tmp1; // chain |
| 1290 | } |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 1291 | break; |
Chris Lattner | e773673 | 2005-12-18 23:54:29 +0000 | [diff] [blame] | 1292 | } |
Evan Cheng | 71e8685 | 2008-07-08 20:06:39 +0000 | [diff] [blame] | 1293 | case TargetLowering::Legal: { |
| 1294 | LegalizeAction Action = getTypeAction(Node->getOperand(1).getValueType()); |
| 1295 | if (Action == Legal && Tmp1 == Node->getOperand(0)) |
| 1296 | break; |
| 1297 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1298 | SmallVector<SDValue, 8> Ops; |
Evan Cheng | 71e8685 | 2008-07-08 20:06:39 +0000 | [diff] [blame] | 1299 | Ops.push_back(Tmp1); |
| 1300 | if (Action == Legal) { |
| 1301 | Ops.push_back(Node->getOperand(1)); // line # must be legal. |
| 1302 | Ops.push_back(Node->getOperand(2)); // col # must be legal. |
| 1303 | } else { |
| 1304 | // Otherwise promote them. |
| 1305 | Ops.push_back(PromoteOp(Node->getOperand(1))); |
| 1306 | Ops.push_back(PromoteOp(Node->getOperand(2))); |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 1307 | } |
Evan Cheng | 71e8685 | 2008-07-08 20:06:39 +0000 | [diff] [blame] | 1308 | Ops.push_back(Node->getOperand(3)); // filename must be legal. |
| 1309 | Ops.push_back(Node->getOperand(4)); // working dir # must be legal. |
| 1310 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 1311 | break; |
| 1312 | } |
Evan Cheng | 71e8685 | 2008-07-08 20:06:39 +0000 | [diff] [blame] | 1313 | } |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 1314 | break; |
Evan Cheng | a844bde | 2008-02-02 04:07:54 +0000 | [diff] [blame] | 1315 | |
| 1316 | case ISD::DECLARE: |
| 1317 | assert(Node->getNumOperands() == 3 && "Invalid DECLARE node!"); |
| 1318 | switch (TLI.getOperationAction(ISD::DECLARE, MVT::Other)) { |
| 1319 | default: assert(0 && "This action is not supported yet!"); |
| 1320 | case TargetLowering::Legal: |
| 1321 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1322 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the address. |
| 1323 | Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the variable. |
| 1324 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
| 1325 | break; |
Chris Lattner | e07415d | 2008-02-28 05:53:40 +0000 | [diff] [blame] | 1326 | case TargetLowering::Expand: |
| 1327 | Result = LegalizeOp(Node->getOperand(0)); |
| 1328 | break; |
Evan Cheng | a844bde | 2008-02-02 04:07:54 +0000 | [diff] [blame] | 1329 | } |
| 1330 | break; |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 1331 | |
| 1332 | case ISD::DEBUG_LOC: |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1333 | assert(Node->getNumOperands() == 4 && "Invalid DEBUG_LOC node!"); |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 1334 | switch (TLI.getOperationAction(ISD::DEBUG_LOC, MVT::Other)) { |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 1335 | default: assert(0 && "This action is not supported yet!"); |
Evan Cheng | 71e8685 | 2008-07-08 20:06:39 +0000 | [diff] [blame] | 1336 | case TargetLowering::Legal: { |
| 1337 | LegalizeAction Action = getTypeAction(Node->getOperand(1).getValueType()); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1338 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Evan Cheng | 71e8685 | 2008-07-08 20:06:39 +0000 | [diff] [blame] | 1339 | if (Action == Legal && Tmp1 == Node->getOperand(0)) |
| 1340 | break; |
| 1341 | if (Action == Legal) { |
| 1342 | Tmp2 = Node->getOperand(1); |
| 1343 | Tmp3 = Node->getOperand(2); |
| 1344 | Tmp4 = Node->getOperand(3); |
| 1345 | } else { |
| 1346 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the line #. |
| 1347 | Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the col #. |
| 1348 | Tmp4 = LegalizeOp(Node->getOperand(3)); // Legalize the source file id. |
| 1349 | } |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1350 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3, Tmp4); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1351 | break; |
| 1352 | } |
Evan Cheng | 71e8685 | 2008-07-08 20:06:39 +0000 | [diff] [blame] | 1353 | } |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1354 | break; |
| 1355 | |
Dan Gohman | 4406604 | 2008-07-01 00:05:16 +0000 | [diff] [blame] | 1356 | case ISD::DBG_LABEL: |
| 1357 | case ISD::EH_LABEL: |
| 1358 | assert(Node->getNumOperands() == 1 && "Invalid LABEL node!"); |
| 1359 | switch (TLI.getOperationAction(Node->getOpcode(), MVT::Other)) { |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1360 | default: assert(0 && "This action is not supported yet!"); |
| 1361 | case TargetLowering::Legal: |
| 1362 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Dan Gohman | 4406604 | 2008-07-01 00:05:16 +0000 | [diff] [blame] | 1363 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 1364 | break; |
Chris Lattner | a9569f1 | 2007-03-03 19:21:38 +0000 | [diff] [blame] | 1365 | case TargetLowering::Expand: |
| 1366 | Result = LegalizeOp(Node->getOperand(0)); |
| 1367 | break; |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 1368 | } |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 1369 | break; |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 1370 | |
Evan Cheng | 27b7db5 | 2008-03-08 00:58:38 +0000 | [diff] [blame] | 1371 | case ISD::PREFETCH: |
| 1372 | assert(Node->getNumOperands() == 4 && "Invalid Prefetch node!"); |
| 1373 | switch (TLI.getOperationAction(ISD::PREFETCH, MVT::Other)) { |
| 1374 | default: assert(0 && "This action is not supported yet!"); |
| 1375 | case TargetLowering::Legal: |
| 1376 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1377 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the address. |
| 1378 | Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the rw specifier. |
| 1379 | Tmp4 = LegalizeOp(Node->getOperand(3)); // Legalize locality specifier. |
| 1380 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3, Tmp4); |
| 1381 | break; |
| 1382 | case TargetLowering::Expand: |
| 1383 | // It's a noop. |
| 1384 | Result = LegalizeOp(Node->getOperand(0)); |
| 1385 | break; |
| 1386 | } |
| 1387 | break; |
| 1388 | |
Andrew Lenharth | 22c5c1b | 2008-02-16 01:24:58 +0000 | [diff] [blame] | 1389 | case ISD::MEMBARRIER: { |
| 1390 | assert(Node->getNumOperands() == 6 && "Invalid MemBarrier node!"); |
Andrew Lenharth | d497d9f | 2008-02-16 14:46:26 +0000 | [diff] [blame] | 1391 | switch (TLI.getOperationAction(ISD::MEMBARRIER, MVT::Other)) { |
| 1392 | default: assert(0 && "This action is not supported yet!"); |
| 1393 | case TargetLowering::Legal: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1394 | SDValue Ops[6]; |
Andrew Lenharth | d497d9f | 2008-02-16 14:46:26 +0000 | [diff] [blame] | 1395 | Ops[0] = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Duncan Sands | e90a615 | 2008-02-27 08:53:44 +0000 | [diff] [blame] | 1396 | for (int x = 1; x < 6; ++x) { |
| 1397 | Ops[x] = Node->getOperand(x); |
| 1398 | if (!isTypeLegal(Ops[x].getValueType())) |
| 1399 | Ops[x] = PromoteOp(Ops[x]); |
| 1400 | } |
Andrew Lenharth | d497d9f | 2008-02-16 14:46:26 +0000 | [diff] [blame] | 1401 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], 6); |
| 1402 | break; |
| 1403 | } |
| 1404 | case TargetLowering::Expand: |
| 1405 | //There is no libgcc call for this op |
| 1406 | Result = Node->getOperand(0); // Noop |
| 1407 | break; |
| 1408 | } |
Andrew Lenharth | 22c5c1b | 2008-02-16 01:24:58 +0000 | [diff] [blame] | 1409 | break; |
| 1410 | } |
| 1411 | |
Dan Gohman | 0b1d4a7 | 2008-12-23 21:37:04 +0000 | [diff] [blame] | 1412 | case ISD::ATOMIC_CMP_SWAP: { |
Mon P Wang | 63307c3 | 2008-05-05 19:05:59 +0000 | [diff] [blame] | 1413 | unsigned int num_operands = 4; |
| 1414 | assert(Node->getNumOperands() == num_operands && "Invalid Atomic node!"); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1415 | SDValue Ops[4]; |
Mon P Wang | 63307c3 | 2008-05-05 19:05:59 +0000 | [diff] [blame] | 1416 | for (unsigned int x = 0; x < num_operands; ++x) |
Andrew Lenharth | 26ed869 | 2008-03-01 21:52:34 +0000 | [diff] [blame] | 1417 | Ops[x] = LegalizeOp(Node->getOperand(x)); |
Mon P Wang | 63307c3 | 2008-05-05 19:05:59 +0000 | [diff] [blame] | 1418 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], num_operands); |
| 1419 | |
| 1420 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 1421 | default: assert(0 && "This action is not supported yet!"); |
| 1422 | case TargetLowering::Custom: |
| 1423 | Result = TLI.LowerOperation(Result, DAG); |
| 1424 | break; |
| 1425 | case TargetLowering::Legal: |
| 1426 | break; |
| 1427 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1428 | AddLegalizedOperand(SDValue(Node, 0), Result.getValue(0)); |
| 1429 | AddLegalizedOperand(SDValue(Node, 1), Result.getValue(1)); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 1430 | return Result.getValue(Op.getResNo()); |
Duncan Sands | 126d907 | 2008-07-04 11:47:58 +0000 | [diff] [blame] | 1431 | } |
Dan Gohman | 0b1d4a7 | 2008-12-23 21:37:04 +0000 | [diff] [blame] | 1432 | case ISD::ATOMIC_LOAD_ADD: |
| 1433 | case ISD::ATOMIC_LOAD_SUB: |
| 1434 | case ISD::ATOMIC_LOAD_AND: |
| 1435 | case ISD::ATOMIC_LOAD_OR: |
| 1436 | case ISD::ATOMIC_LOAD_XOR: |
| 1437 | case ISD::ATOMIC_LOAD_NAND: |
| 1438 | case ISD::ATOMIC_LOAD_MIN: |
| 1439 | case ISD::ATOMIC_LOAD_MAX: |
| 1440 | case ISD::ATOMIC_LOAD_UMIN: |
| 1441 | case ISD::ATOMIC_LOAD_UMAX: |
| 1442 | case ISD::ATOMIC_SWAP: { |
Mon P Wang | 63307c3 | 2008-05-05 19:05:59 +0000 | [diff] [blame] | 1443 | unsigned int num_operands = 3; |
| 1444 | assert(Node->getNumOperands() == num_operands && "Invalid Atomic node!"); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1445 | SDValue Ops[3]; |
Mon P Wang | 63307c3 | 2008-05-05 19:05:59 +0000 | [diff] [blame] | 1446 | for (unsigned int x = 0; x < num_operands; ++x) |
| 1447 | Ops[x] = LegalizeOp(Node->getOperand(x)); |
| 1448 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], num_operands); |
Duncan Sands | 126d907 | 2008-07-04 11:47:58 +0000 | [diff] [blame] | 1449 | |
Andrew Lenharth | 26ed869 | 2008-03-01 21:52:34 +0000 | [diff] [blame] | 1450 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 1451 | default: assert(0 && "This action is not supported yet!"); |
Andrew Lenharth | 26ed869 | 2008-03-01 21:52:34 +0000 | [diff] [blame] | 1452 | case TargetLowering::Custom: |
| 1453 | Result = TLI.LowerOperation(Result, DAG); |
| 1454 | break; |
| 1455 | case TargetLowering::Legal: |
Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 1456 | break; |
| 1457 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1458 | AddLegalizedOperand(SDValue(Node, 0), Result.getValue(0)); |
| 1459 | AddLegalizedOperand(SDValue(Node, 1), Result.getValue(1)); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 1460 | return Result.getValue(Op.getResNo()); |
Duncan Sands | 126d907 | 2008-07-04 11:47:58 +0000 | [diff] [blame] | 1461 | } |
Scott Michel | c1513d2 | 2007-08-08 23:23:31 +0000 | [diff] [blame] | 1462 | case ISD::Constant: { |
| 1463 | ConstantSDNode *CN = cast<ConstantSDNode>(Node); |
| 1464 | unsigned opAction = |
| 1465 | TLI.getOperationAction(ISD::Constant, CN->getValueType(0)); |
| 1466 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1467 | // We know we don't need to expand constants here, constants only have one |
| 1468 | // value and we check that it is fine above. |
| 1469 | |
Scott Michel | c1513d2 | 2007-08-08 23:23:31 +0000 | [diff] [blame] | 1470 | if (opAction == TargetLowering::Custom) { |
| 1471 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1472 | if (Tmp1.getNode()) |
Scott Michel | c1513d2 | 2007-08-08 23:23:31 +0000 | [diff] [blame] | 1473 | Result = Tmp1; |
| 1474 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1475 | break; |
Scott Michel | c1513d2 | 2007-08-08 23:23:31 +0000 | [diff] [blame] | 1476 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1477 | case ISD::ConstantFP: { |
| 1478 | // Spill FP immediates to the constant pool if the target cannot directly |
| 1479 | // codegen them. Targets often have some immediate values that can be |
| 1480 | // efficiently generated into an FP register without a load. We explicitly |
| 1481 | // leave these constants as ConstantFP nodes for the target to deal with. |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1482 | ConstantFPSDNode *CFP = cast<ConstantFPSDNode>(Node); |
| 1483 | |
Chris Lattner | 3181a77 | 2006-01-29 06:26:56 +0000 | [diff] [blame] | 1484 | switch (TLI.getOperationAction(ISD::ConstantFP, CFP->getValueType(0))) { |
| 1485 | default: assert(0 && "This action is not supported yet!"); |
Nate Begeman | e179584 | 2008-02-14 08:57:00 +0000 | [diff] [blame] | 1486 | case TargetLowering::Legal: |
| 1487 | break; |
Chris Lattner | 3181a77 | 2006-01-29 06:26:56 +0000 | [diff] [blame] | 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 | 3181a77 | 2006-01-29 06:26:56 +0000 | [diff] [blame] | 1491 | Result = Tmp3; |
| 1492 | break; |
| 1493 | } |
| 1494 | // FALLTHROUGH |
Nate Begeman | e179584 | 2008-02-14 08:57:00 +0000 | [diff] [blame] | 1495 | case TargetLowering::Expand: { |
| 1496 | // Check to see if this FP immediate is already legal. |
| 1497 | bool isLegal = false; |
| 1498 | for (TargetLowering::legal_fpimm_iterator I = TLI.legal_fpimm_begin(), |
| 1499 | E = TLI.legal_fpimm_end(); I != E; ++I) { |
| 1500 | if (CFP->isExactlyValue(*I)) { |
| 1501 | isLegal = true; |
| 1502 | break; |
| 1503 | } |
| 1504 | } |
| 1505 | // If this is a legal constant, turn it into a TargetConstantFP node. |
| 1506 | if (isLegal) |
| 1507 | break; |
Evan Cheng | 279101e | 2006-12-12 22:19:28 +0000 | [diff] [blame] | 1508 | Result = ExpandConstantFP(CFP, true, DAG, TLI); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1509 | } |
Nate Begeman | e179584 | 2008-02-14 08:57:00 +0000 | [diff] [blame] | 1510 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1511 | break; |
| 1512 | } |
Chris Lattner | 040c11c | 2005-11-09 18:48:57 +0000 | [diff] [blame] | 1513 | case ISD::TokenFactor: |
| 1514 | if (Node->getNumOperands() == 2) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1515 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1516 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1517 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 1518 | } else if (Node->getNumOperands() == 3) { |
| 1519 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1520 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1521 | Tmp3 = LegalizeOp(Node->getOperand(2)); |
| 1522 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | 040c11c | 2005-11-09 18:48:57 +0000 | [diff] [blame] | 1523 | } else { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1524 | SmallVector<SDValue, 8> Ops; |
Chris Lattner | 040c11c | 2005-11-09 18:48:57 +0000 | [diff] [blame] | 1525 | // Legalize the operands. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1526 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) |
| 1527 | Ops.push_back(LegalizeOp(Node->getOperand(i))); |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1528 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | a385e9b | 2005-01-13 17:59:25 +0000 | [diff] [blame] | 1529 | } |
Chris Lattner | a385e9b | 2005-01-13 17:59:25 +0000 | [diff] [blame] | 1530 | break; |
Chris Lattner | fdfded5 | 2006-04-12 16:20:43 +0000 | [diff] [blame] | 1531 | |
| 1532 | case ISD::FORMAL_ARGUMENTS: |
Chris Lattner | f4ec817 | 2006-05-16 22:53:20 +0000 | [diff] [blame] | 1533 | case ISD::CALL: |
Chris Lattner | fdfded5 | 2006-04-12 16:20:43 +0000 | [diff] [blame] | 1534 | // The only option for this is to custom lower it. |
Chris Lattner | b248e16 | 2006-05-17 17:55:45 +0000 | [diff] [blame] | 1535 | Tmp3 = TLI.LowerOperation(Result.getValue(0), DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1536 | assert(Tmp3.getNode() && "Target didn't custom lower this node!"); |
Dale Johannesen | 0ea0356 | 2008-03-05 19:14:03 +0000 | [diff] [blame] | 1537 | // A call within a calling sequence must be legalized to something |
| 1538 | // other than the normal CALLSEQ_END. Violating this gets Legalize |
| 1539 | // into an infinite loop. |
| 1540 | assert ((!IsLegalizingCall || |
| 1541 | Node->getOpcode() != ISD::CALL || |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1542 | Tmp3.getNode()->getOpcode() != ISD::CALLSEQ_END) && |
Dale Johannesen | 0ea0356 | 2008-03-05 19:14:03 +0000 | [diff] [blame] | 1543 | "Nested CALLSEQ_START..CALLSEQ_END not supported."); |
Bill Wendling | 0f8d9c0 | 2007-11-13 00:44:25 +0000 | [diff] [blame] | 1544 | |
| 1545 | // The number of incoming and outgoing values should match; unless the final |
| 1546 | // outgoing value is a flag. |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1547 | assert((Tmp3.getNode()->getNumValues() == Result.getNode()->getNumValues() || |
| 1548 | (Tmp3.getNode()->getNumValues() == Result.getNode()->getNumValues() + 1 && |
| 1549 | Tmp3.getNode()->getValueType(Tmp3.getNode()->getNumValues() - 1) == |
Bill Wendling | 0f8d9c0 | 2007-11-13 00:44:25 +0000 | [diff] [blame] | 1550 | MVT::Flag)) && |
Chris Lattner | b248e16 | 2006-05-17 17:55:45 +0000 | [diff] [blame] | 1551 | "Lowering call/formal_arguments produced unexpected # results!"); |
Chris Lattner | e2e4173 | 2006-05-16 05:49:56 +0000 | [diff] [blame] | 1552 | |
Chris Lattner | f4ec817 | 2006-05-16 22:53:20 +0000 | [diff] [blame] | 1553 | // Since CALL/FORMAL_ARGUMENTS nodes produce multiple values, make sure to |
Chris Lattner | e2e4173 | 2006-05-16 05:49:56 +0000 | [diff] [blame] | 1554 | // 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] | 1555 | for (unsigned i = 0, e = Tmp3.getNode()->getNumValues(); i != e; ++i) { |
| 1556 | if (Tmp3.getNode()->getValueType(i) == MVT::Flag) |
Bill Wendling | 0f8d9c0 | 2007-11-13 00:44:25 +0000 | [diff] [blame] | 1557 | continue; |
Chris Lattner | b248e16 | 2006-05-17 17:55:45 +0000 | [diff] [blame] | 1558 | Tmp1 = LegalizeOp(Tmp3.getValue(i)); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 1559 | if (Op.getResNo() == i) |
Chris Lattner | e2e4173 | 2006-05-16 05:49:56 +0000 | [diff] [blame] | 1560 | Tmp2 = Tmp1; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1561 | AddLegalizedOperand(SDValue(Node, i), Tmp1); |
Chris Lattner | e2e4173 | 2006-05-16 05:49:56 +0000 | [diff] [blame] | 1562 | } |
| 1563 | return Tmp2; |
Christopher Lamb | 557c363 | 2007-07-26 07:34:40 +0000 | [diff] [blame] | 1564 | case ISD::EXTRACT_SUBREG: { |
| 1565 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1566 | ConstantSDNode *idx = dyn_cast<ConstantSDNode>(Node->getOperand(1)); |
| 1567 | assert(idx && "Operand must be a constant"); |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1568 | Tmp2 = DAG.getTargetConstant(idx->getAPIntValue(), idx->getValueType(0)); |
Christopher Lamb | 557c363 | 2007-07-26 07:34:40 +0000 | [diff] [blame] | 1569 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 1570 | } |
| 1571 | break; |
| 1572 | case ISD::INSERT_SUBREG: { |
| 1573 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1574 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1575 | ConstantSDNode *idx = dyn_cast<ConstantSDNode>(Node->getOperand(2)); |
| 1576 | assert(idx && "Operand must be a constant"); |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1577 | Tmp3 = DAG.getTargetConstant(idx->getAPIntValue(), idx->getValueType(0)); |
Christopher Lamb | 557c363 | 2007-07-26 07:34:40 +0000 | [diff] [blame] | 1578 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
| 1579 | } |
| 1580 | break; |
Chris Lattner | b2827b0 | 2006-03-19 00:52:58 +0000 | [diff] [blame] | 1581 | case ISD::BUILD_VECTOR: |
| 1582 | switch (TLI.getOperationAction(ISD::BUILD_VECTOR, Node->getValueType(0))) { |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1583 | default: assert(0 && "This action is not supported yet!"); |
| 1584 | case TargetLowering::Custom: |
| 1585 | Tmp3 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1586 | if (Tmp3.getNode()) { |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1587 | Result = Tmp3; |
| 1588 | break; |
| 1589 | } |
| 1590 | // FALLTHROUGH |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 1591 | case TargetLowering::Expand: |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1592 | Result = ExpandBUILD_VECTOR(Result.getNode()); |
Chris Lattner | b2827b0 | 2006-03-19 00:52:58 +0000 | [diff] [blame] | 1593 | break; |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1594 | } |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1595 | break; |
| 1596 | case ISD::INSERT_VECTOR_ELT: |
| 1597 | Tmp1 = LegalizeOp(Node->getOperand(0)); // InVec |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1598 | Tmp3 = LegalizeOp(Node->getOperand(2)); // InEltNo |
Nate Begeman | 0325d90 | 2008-02-13 06:43:04 +0000 | [diff] [blame] | 1599 | |
| 1600 | // The type of the value to insert may not be legal, even though the vector |
| 1601 | // type is legal. Legalize/Promote accordingly. We do not handle Expand |
| 1602 | // here. |
| 1603 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 1604 | default: assert(0 && "Cannot expand insert element operand"); |
| 1605 | case Legal: Tmp2 = LegalizeOp(Node->getOperand(1)); break; |
| 1606 | case Promote: Tmp2 = PromoteOp(Node->getOperand(1)); break; |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 1607 | case Expand: |
| 1608 | // FIXME: An alternative would be to check to see if the target is not |
| 1609 | // going to custom lower this operation, we could bitcast to half elt |
| 1610 | // width and perform two inserts at that width, if that is legal. |
| 1611 | Tmp2 = Node->getOperand(1); |
| 1612 | break; |
Nate Begeman | 0325d90 | 2008-02-13 06:43:04 +0000 | [diff] [blame] | 1613 | } |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1614 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
| 1615 | |
| 1616 | switch (TLI.getOperationAction(ISD::INSERT_VECTOR_ELT, |
| 1617 | Node->getValueType(0))) { |
| 1618 | default: assert(0 && "This action is not supported yet!"); |
| 1619 | case TargetLowering::Legal: |
| 1620 | break; |
| 1621 | case TargetLowering::Custom: |
Nate Begeman | 2281a99 | 2008-01-05 20:47:37 +0000 | [diff] [blame] | 1622 | Tmp4 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1623 | if (Tmp4.getNode()) { |
Nate Begeman | 2281a99 | 2008-01-05 20:47:37 +0000 | [diff] [blame] | 1624 | Result = Tmp4; |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1625 | break; |
| 1626 | } |
| 1627 | // FALLTHROUGH |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 1628 | case TargetLowering::Promote: |
| 1629 | // Fall thru for vector case |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1630 | case TargetLowering::Expand: { |
Chris Lattner | 8d5a894 | 2006-04-17 19:21:01 +0000 | [diff] [blame] | 1631 | // If the insert index is a constant, codegen this as a scalar_to_vector, |
| 1632 | // then a shuffle that inserts it into the right position in the vector. |
| 1633 | if (ConstantSDNode *InsertPos = dyn_cast<ConstantSDNode>(Tmp3)) { |
Nate Begeman | 0325d90 | 2008-02-13 06:43:04 +0000 | [diff] [blame] | 1634 | // SCALAR_TO_VECTOR requires that the type of the value being inserted |
| 1635 | // match the element type of the vector being created. |
| 1636 | if (Tmp2.getValueType() == |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1637 | Op.getValueType().getVectorElementType()) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1638 | SDValue ScVec = DAG.getNode(ISD::SCALAR_TO_VECTOR, |
Nate Begeman | 0325d90 | 2008-02-13 06:43:04 +0000 | [diff] [blame] | 1639 | Tmp1.getValueType(), Tmp2); |
| 1640 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1641 | unsigned NumElts = Tmp1.getValueType().getVectorNumElements(); |
| 1642 | MVT ShufMaskVT = |
| 1643 | MVT::getIntVectorWithNumElements(NumElts); |
| 1644 | MVT ShufMaskEltVT = ShufMaskVT.getVectorElementType(); |
Nate Begeman | 0325d90 | 2008-02-13 06:43:04 +0000 | [diff] [blame] | 1645 | |
| 1646 | // We generate a shuffle of InVec and ScVec, so the shuffle mask |
| 1647 | // should be 0,1,2,3,4,5... with the appropriate element replaced with |
| 1648 | // elt 0 of the RHS. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1649 | SmallVector<SDValue, 8> ShufOps; |
Nate Begeman | 0325d90 | 2008-02-13 06:43:04 +0000 | [diff] [blame] | 1650 | for (unsigned i = 0; i != NumElts; ++i) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1651 | if (i != InsertPos->getZExtValue()) |
Nate Begeman | 0325d90 | 2008-02-13 06:43:04 +0000 | [diff] [blame] | 1652 | ShufOps.push_back(DAG.getConstant(i, ShufMaskEltVT)); |
| 1653 | else |
| 1654 | ShufOps.push_back(DAG.getConstant(NumElts, ShufMaskEltVT)); |
| 1655 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1656 | SDValue ShufMask = DAG.getNode(ISD::BUILD_VECTOR, ShufMaskVT, |
Nate Begeman | 0325d90 | 2008-02-13 06:43:04 +0000 | [diff] [blame] | 1657 | &ShufOps[0], ShufOps.size()); |
| 1658 | |
| 1659 | Result = DAG.getNode(ISD::VECTOR_SHUFFLE, Tmp1.getValueType(), |
| 1660 | Tmp1, ScVec, ShufMask); |
| 1661 | Result = LegalizeOp(Result); |
| 1662 | break; |
Chris Lattner | 8d5a894 | 2006-04-17 19:21:01 +0000 | [diff] [blame] | 1663 | } |
Chris Lattner | 8d5a894 | 2006-04-17 19:21:01 +0000 | [diff] [blame] | 1664 | } |
Nate Begeman | 6867991 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 1665 | Result = PerformInsertVectorEltInMemory(Tmp1, Tmp2, Tmp3); |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1666 | break; |
| 1667 | } |
| 1668 | } |
| 1669 | break; |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 1670 | case ISD::SCALAR_TO_VECTOR: |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 1671 | if (!TLI.isTypeLegal(Node->getOperand(0).getValueType())) { |
| 1672 | Result = LegalizeOp(ExpandSCALAR_TO_VECTOR(Node)); |
| 1673 | break; |
| 1674 | } |
| 1675 | |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 1676 | Tmp1 = LegalizeOp(Node->getOperand(0)); // InVal |
| 1677 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 1678 | switch (TLI.getOperationAction(ISD::SCALAR_TO_VECTOR, |
| 1679 | Node->getValueType(0))) { |
| 1680 | default: assert(0 && "This action is not supported yet!"); |
| 1681 | case TargetLowering::Legal: |
| 1682 | break; |
Chris Lattner | 4d3abee | 2006-03-19 06:47:21 +0000 | [diff] [blame] | 1683 | case TargetLowering::Custom: |
| 1684 | Tmp3 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1685 | if (Tmp3.getNode()) { |
Chris Lattner | 4d3abee | 2006-03-19 06:47:21 +0000 | [diff] [blame] | 1686 | Result = Tmp3; |
| 1687 | break; |
| 1688 | } |
| 1689 | // FALLTHROUGH |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 1690 | case TargetLowering::Expand: |
| 1691 | Result = LegalizeOp(ExpandSCALAR_TO_VECTOR(Node)); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 1692 | break; |
| 1693 | } |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 1694 | break; |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 1695 | case ISD::VECTOR_SHUFFLE: |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 1696 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the input vectors, |
| 1697 | Tmp2 = LegalizeOp(Node->getOperand(1)); // but not the shuffle mask. |
| 1698 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
| 1699 | |
| 1700 | // Allow targets to custom lower the SHUFFLEs they support. |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 1701 | switch (TLI.getOperationAction(ISD::VECTOR_SHUFFLE,Result.getValueType())) { |
| 1702 | default: assert(0 && "Unknown operation action!"); |
| 1703 | case TargetLowering::Legal: |
| 1704 | assert(isShuffleLegal(Result.getValueType(), Node->getOperand(2)) && |
| 1705 | "vector shuffle should not be created if not legal!"); |
| 1706 | break; |
| 1707 | case TargetLowering::Custom: |
Evan Cheng | 18dd6d0 | 2006-04-05 06:07:11 +0000 | [diff] [blame] | 1708 | Tmp3 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1709 | if (Tmp3.getNode()) { |
Evan Cheng | 18dd6d0 | 2006-04-05 06:07:11 +0000 | [diff] [blame] | 1710 | Result = Tmp3; |
| 1711 | break; |
| 1712 | } |
| 1713 | // FALLTHROUGH |
| 1714 | case TargetLowering::Expand: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1715 | MVT VT = Node->getValueType(0); |
| 1716 | MVT EltVT = VT.getVectorElementType(); |
| 1717 | MVT PtrVT = TLI.getPointerTy(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1718 | SDValue Mask = Node->getOperand(2); |
Evan Cheng | 18dd6d0 | 2006-04-05 06:07:11 +0000 | [diff] [blame] | 1719 | unsigned NumElems = Mask.getNumOperands(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1720 | SmallVector<SDValue,8> Ops; |
Evan Cheng | 18dd6d0 | 2006-04-05 06:07:11 +0000 | [diff] [blame] | 1721 | for (unsigned i = 0; i != NumElems; ++i) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1722 | SDValue Arg = Mask.getOperand(i); |
Evan Cheng | 18dd6d0 | 2006-04-05 06:07:11 +0000 | [diff] [blame] | 1723 | if (Arg.getOpcode() == ISD::UNDEF) { |
| 1724 | Ops.push_back(DAG.getNode(ISD::UNDEF, EltVT)); |
| 1725 | } else { |
| 1726 | assert(isa<ConstantSDNode>(Arg) && "Invalid VECTOR_SHUFFLE mask!"); |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1727 | unsigned Idx = cast<ConstantSDNode>(Arg)->getZExtValue(); |
Evan Cheng | 18dd6d0 | 2006-04-05 06:07:11 +0000 | [diff] [blame] | 1728 | if (Idx < NumElems) |
| 1729 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, EltVT, Tmp1, |
| 1730 | DAG.getConstant(Idx, PtrVT))); |
| 1731 | else |
| 1732 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, EltVT, Tmp2, |
| 1733 | DAG.getConstant(Idx - NumElems, PtrVT))); |
| 1734 | } |
| 1735 | } |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 1736 | Result = DAG.getNode(ISD::BUILD_VECTOR, VT, &Ops[0], Ops.size()); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 1737 | break; |
Evan Cheng | 18dd6d0 | 2006-04-05 06:07:11 +0000 | [diff] [blame] | 1738 | } |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 1739 | case TargetLowering::Promote: { |
| 1740 | // Change base type to a different vector type. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1741 | MVT OVT = Node->getValueType(0); |
| 1742 | MVT NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 1743 | |
| 1744 | // Cast the two input vectors. |
| 1745 | Tmp1 = DAG.getNode(ISD::BIT_CONVERT, NVT, Tmp1); |
| 1746 | Tmp2 = DAG.getNode(ISD::BIT_CONVERT, NVT, Tmp2); |
| 1747 | |
| 1748 | // Convert the shuffle mask to the right # elements. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1749 | Tmp3 = SDValue(isShuffleLegal(OVT, Node->getOperand(2)), 0); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1750 | assert(Tmp3.getNode() && "Shuffle not legal?"); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 1751 | Result = DAG.getNode(ISD::VECTOR_SHUFFLE, NVT, Tmp1, Tmp2, Tmp3); |
| 1752 | Result = DAG.getNode(ISD::BIT_CONVERT, OVT, Result); |
| 1753 | break; |
| 1754 | } |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 1755 | } |
| 1756 | break; |
Chris Lattner | 384504c | 2006-03-21 20:44:12 +0000 | [diff] [blame] | 1757 | |
| 1758 | case ISD::EXTRACT_VECTOR_ELT: |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 1759 | Tmp1 = Node->getOperand(0); |
Chris Lattner | 384504c | 2006-03-21 20:44:12 +0000 | [diff] [blame] | 1760 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1761 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 1762 | Result = ExpandEXTRACT_VECTOR_ELT(Result); |
Chris Lattner | 384504c | 2006-03-21 20:44:12 +0000 | [diff] [blame] | 1763 | break; |
| 1764 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 1765 | case ISD::EXTRACT_SUBVECTOR: |
| 1766 | Tmp1 = Node->getOperand(0); |
| 1767 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1768 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 1769 | Result = ExpandEXTRACT_SUBVECTOR(Result); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 1770 | break; |
| 1771 | |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 1772 | case ISD::CONCAT_VECTORS: { |
| 1773 | // Use extract/insert/build vector for now. We might try to be |
| 1774 | // more clever later. |
| 1775 | MVT PtrVT = TLI.getPointerTy(); |
| 1776 | SmallVector<SDValue, 8> Ops; |
| 1777 | unsigned NumOperands = Node->getNumOperands(); |
| 1778 | for (unsigned i=0; i < NumOperands; ++i) { |
| 1779 | SDValue SubOp = Node->getOperand(i); |
| 1780 | MVT VVT = SubOp.getNode()->getValueType(0); |
| 1781 | MVT EltVT = VVT.getVectorElementType(); |
| 1782 | unsigned NumSubElem = VVT.getVectorNumElements(); |
| 1783 | for (unsigned j=0; j < NumSubElem; ++j) { |
| 1784 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, EltVT, SubOp, |
| 1785 | DAG.getConstant(j, PtrVT))); |
| 1786 | } |
| 1787 | } |
| 1788 | return LegalizeOp(DAG.getNode(ISD::BUILD_VECTOR, Node->getValueType(0), |
| 1789 | &Ops[0], Ops.size())); |
| 1790 | } |
| 1791 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1792 | case ISD::CALLSEQ_START: { |
| 1793 | SDNode *CallEnd = FindCallEndFromCallStart(Node); |
| 1794 | |
| 1795 | // Recursively Legalize all of the inputs of the call end that do not lead |
| 1796 | // to this call start. This ensures that any libcalls that need be inserted |
| 1797 | // are inserted *before* the CALLSEQ_START. |
Chris Lattner | 00755df | 2007-02-04 00:27:56 +0000 | [diff] [blame] | 1798 | {SmallPtrSet<SDNode*, 32> NodesLeadingTo; |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1799 | for (unsigned i = 0, e = CallEnd->getNumOperands(); i != e; ++i) |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1800 | LegalizeAllNodesNotLeadingTo(CallEnd->getOperand(i).getNode(), Node, |
Chris Lattner | c9cf4f1 | 2006-07-26 23:55:56 +0000 | [diff] [blame] | 1801 | NodesLeadingTo); |
| 1802 | } |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1803 | |
| 1804 | // Now that we legalized all of the inputs (which may have inserted |
| 1805 | // libcalls) create the new CALLSEQ_START node. |
| 1806 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1807 | |
| 1808 | // Merge in the last call, to ensure that this call start after the last |
| 1809 | // call ended. |
Chris Lattner | c5d7d7c | 2006-05-17 18:00:08 +0000 | [diff] [blame] | 1810 | if (LastCALLSEQ_END.getOpcode() != ISD::EntryToken) { |
Chris Lattner | b248e16 | 2006-05-17 17:55:45 +0000 | [diff] [blame] | 1811 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1812 | Tmp1 = LegalizeOp(Tmp1); |
| 1813 | } |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1814 | |
| 1815 | // Do not try to legalize the target-specific arguments (#1+). |
| 1816 | if (Tmp1 != Node->getOperand(0)) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1817 | SmallVector<SDValue, 8> Ops(Node->op_begin(), Node->op_end()); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1818 | Ops[0] = Tmp1; |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1819 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1820 | } |
| 1821 | |
| 1822 | // Remember that the CALLSEQ_START is legalized. |
Chris Lattner | 4b653a0 | 2006-02-14 00:55:02 +0000 | [diff] [blame] | 1823 | AddLegalizedOperand(Op.getValue(0), Result); |
| 1824 | if (Node->getNumValues() == 2) // If this has a flag result, remember it. |
| 1825 | AddLegalizedOperand(Op.getValue(1), Result.getValue(1)); |
| 1826 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1827 | // Now that the callseq_start and all of the non-call nodes above this call |
| 1828 | // sequence have been legalized, legalize the call itself. During this |
| 1829 | // process, no libcalls can/will be inserted, guaranteeing that no calls |
| 1830 | // can overlap. |
| 1831 | assert(!IsLegalizingCall && "Inconsistent sequentialization of calls!"); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1832 | // Note that we are selecting this call! |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1833 | LastCALLSEQ_END = SDValue(CallEnd, 0); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1834 | IsLegalizingCall = true; |
| 1835 | |
| 1836 | // Legalize the call, starting from the CALLSEQ_END. |
| 1837 | LegalizeOp(LastCALLSEQ_END); |
| 1838 | assert(!IsLegalizingCall && "CALLSEQ_END should have cleared this!"); |
| 1839 | return Result; |
| 1840 | } |
Chris Lattner | 16cd04d | 2005-05-12 23:24:06 +0000 | [diff] [blame] | 1841 | case ISD::CALLSEQ_END: |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1842 | // If the CALLSEQ_START node hasn't been legalized first, legalize it. This |
| 1843 | // 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] | 1844 | if (LastCALLSEQ_END.getNode() != Node) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1845 | LegalizeOp(SDValue(FindCallStartFromCallEnd(Node), 0)); |
| 1846 | DenseMap<SDValue, SDValue>::iterator I = LegalizedNodes.find(Op); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1847 | assert(I != LegalizedNodes.end() && |
| 1848 | "Legalizing the call start should have legalized this node!"); |
| 1849 | return I->second; |
| 1850 | } |
| 1851 | |
| 1852 | // Otherwise, the call start has been legalized and everything is going |
| 1853 | // according to plan. Just legalize ourselves normally here. |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1854 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | 70814bc | 2006-01-29 07:58:15 +0000 | [diff] [blame] | 1855 | // Do not try to legalize the target-specific arguments (#1+), except for |
| 1856 | // an optional flag input. |
| 1857 | if (Node->getOperand(Node->getNumOperands()-1).getValueType() != MVT::Flag){ |
| 1858 | if (Tmp1 != Node->getOperand(0)) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1859 | SmallVector<SDValue, 8> Ops(Node->op_begin(), Node->op_end()); |
Chris Lattner | 70814bc | 2006-01-29 07:58:15 +0000 | [diff] [blame] | 1860 | Ops[0] = Tmp1; |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1861 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 70814bc | 2006-01-29 07:58:15 +0000 | [diff] [blame] | 1862 | } |
| 1863 | } else { |
| 1864 | Tmp2 = LegalizeOp(Node->getOperand(Node->getNumOperands()-1)); |
| 1865 | if (Tmp1 != Node->getOperand(0) || |
| 1866 | Tmp2 != Node->getOperand(Node->getNumOperands()-1)) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1867 | SmallVector<SDValue, 8> Ops(Node->op_begin(), Node->op_end()); |
Chris Lattner | 70814bc | 2006-01-29 07:58:15 +0000 | [diff] [blame] | 1868 | Ops[0] = Tmp1; |
| 1869 | Ops.back() = Tmp2; |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1870 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 70814bc | 2006-01-29 07:58:15 +0000 | [diff] [blame] | 1871 | } |
Chris Lattner | 6a54289 | 2006-01-24 05:48:21 +0000 | [diff] [blame] | 1872 | } |
Chris Lattner | 4b653a0 | 2006-02-14 00:55:02 +0000 | [diff] [blame] | 1873 | assert(IsLegalizingCall && "Call sequence imbalance between start/end?"); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1874 | // This finishes up call legalization. |
| 1875 | IsLegalizingCall = false; |
Chris Lattner | 4b653a0 | 2006-02-14 00:55:02 +0000 | [diff] [blame] | 1876 | |
| 1877 | // 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] | 1878 | AddLegalizedOperand(SDValue(Node, 0), Result.getValue(0)); |
Chris Lattner | 4b653a0 | 2006-02-14 00:55:02 +0000 | [diff] [blame] | 1879 | if (Node->getNumValues() == 2) |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1880 | AddLegalizedOperand(SDValue(Node, 1), Result.getValue(1)); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 1881 | return Result.getValue(Op.getResNo()); |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1882 | case ISD::DYNAMIC_STACKALLOC: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1883 | MVT VT = Node->getValueType(0); |
Chris Lattner | fa404e8 | 2005-01-09 19:03:49 +0000 | [diff] [blame] | 1884 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1885 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the size. |
| 1886 | Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the alignment. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1887 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | fa404e8 | 2005-01-09 19:03:49 +0000 | [diff] [blame] | 1888 | |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1889 | Tmp1 = Result.getValue(0); |
Chris Lattner | 5f65229 | 2006-01-15 08:43:08 +0000 | [diff] [blame] | 1890 | Tmp2 = Result.getValue(1); |
Evan Cheng | 61bbbab | 2007-08-16 23:50:06 +0000 | [diff] [blame] | 1891 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1892 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1893 | case TargetLowering::Expand: { |
| 1894 | unsigned SPReg = TLI.getStackPointerRegisterToSaveRestore(); |
| 1895 | assert(SPReg && "Target cannot require DYNAMIC_STACKALLOC expansion and" |
| 1896 | " not tell us which reg is the stack pointer!"); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1897 | SDValue Chain = Tmp1.getOperand(0); |
Bill Wendling | 0f8d9c0 | 2007-11-13 00:44:25 +0000 | [diff] [blame] | 1898 | |
| 1899 | // Chain the dynamic stack allocation so that it doesn't modify the stack |
| 1900 | // pointer when other instructions are using the stack. |
Chris Lattner | e563bbc | 2008-10-11 22:08:30 +0000 | [diff] [blame] | 1901 | Chain = DAG.getCALLSEQ_START(Chain, DAG.getIntPtrConstant(0, true)); |
Bill Wendling | 0f8d9c0 | 2007-11-13 00:44:25 +0000 | [diff] [blame] | 1902 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1903 | SDValue Size = Tmp2.getOperand(1); |
| 1904 | SDValue SP = DAG.getCopyFromReg(Chain, SPReg, VT); |
Evan Cheng | 61bbbab | 2007-08-16 23:50:06 +0000 | [diff] [blame] | 1905 | Chain = SP.getValue(1); |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1906 | unsigned Align = cast<ConstantSDNode>(Tmp3)->getZExtValue(); |
Evan Cheng | 61bbbab | 2007-08-16 23:50:06 +0000 | [diff] [blame] | 1907 | unsigned StackAlign = |
| 1908 | TLI.getTargetMachine().getFrameInfo()->getStackAlignment(); |
| 1909 | if (Align > StackAlign) |
Evan Cheng | 3e20bba | 2007-08-17 18:02:22 +0000 | [diff] [blame] | 1910 | SP = DAG.getNode(ISD::AND, VT, SP, |
| 1911 | DAG.getConstant(-(uint64_t)Align, VT)); |
Evan Cheng | 61bbbab | 2007-08-16 23:50:06 +0000 | [diff] [blame] | 1912 | Tmp1 = DAG.getNode(ISD::SUB, VT, SP, Size); // Value |
Bill Wendling | 0f8d9c0 | 2007-11-13 00:44:25 +0000 | [diff] [blame] | 1913 | Chain = DAG.getCopyToReg(Chain, SPReg, Tmp1); // Output chain |
| 1914 | |
Chris Lattner | e563bbc | 2008-10-11 22:08:30 +0000 | [diff] [blame] | 1915 | Tmp2 = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(0, true), |
| 1916 | DAG.getIntPtrConstant(0, true), SDValue()); |
Bill Wendling | 0f8d9c0 | 2007-11-13 00:44:25 +0000 | [diff] [blame] | 1917 | |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1918 | Tmp1 = LegalizeOp(Tmp1); |
| 1919 | Tmp2 = LegalizeOp(Tmp2); |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1920 | break; |
| 1921 | } |
| 1922 | case TargetLowering::Custom: |
Chris Lattner | 5f65229 | 2006-01-15 08:43:08 +0000 | [diff] [blame] | 1923 | Tmp3 = TLI.LowerOperation(Tmp1, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1924 | if (Tmp3.getNode()) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1925 | Tmp1 = LegalizeOp(Tmp3); |
| 1926 | Tmp2 = LegalizeOp(Tmp3.getValue(1)); |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1927 | } |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1928 | break; |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1929 | case TargetLowering::Legal: |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1930 | break; |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1931 | } |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1932 | // Since this op produce two values, make sure to remember that we |
| 1933 | // legalized both of them. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1934 | AddLegalizedOperand(SDValue(Node, 0), Tmp1); |
| 1935 | AddLegalizedOperand(SDValue(Node, 1), Tmp2); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 1936 | return Op.getResNo() ? Tmp2 : Tmp1; |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1937 | } |
Chris Lattner | 25a022c | 2006-07-11 01:40:09 +0000 | [diff] [blame] | 1938 | case ISD::INLINEASM: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1939 | SmallVector<SDValue, 8> Ops(Node->op_begin(), Node->op_end()); |
Chris Lattner | 25a022c | 2006-07-11 01:40:09 +0000 | [diff] [blame] | 1940 | bool Changed = false; |
| 1941 | // Legalize all of the operands of the inline asm, in case they are nodes |
| 1942 | // that need to be expanded or something. Note we skip the asm string and |
| 1943 | // all of the TargetConstant flags. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1944 | SDValue Op = LegalizeOp(Ops[0]); |
Chris Lattner | 25a022c | 2006-07-11 01:40:09 +0000 | [diff] [blame] | 1945 | Changed = Op != Ops[0]; |
| 1946 | Ops[0] = Op; |
| 1947 | |
| 1948 | bool HasInFlag = Ops.back().getValueType() == MVT::Flag; |
| 1949 | for (unsigned i = 2, e = Ops.size()-HasInFlag; i < e; ) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1950 | unsigned NumVals = cast<ConstantSDNode>(Ops[i])->getZExtValue() >> 3; |
Chris Lattner | 25a022c | 2006-07-11 01:40:09 +0000 | [diff] [blame] | 1951 | for (++i; NumVals; ++i, --NumVals) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1952 | SDValue Op = LegalizeOp(Ops[i]); |
Chris Lattner | 25a022c | 2006-07-11 01:40:09 +0000 | [diff] [blame] | 1953 | if (Op != Ops[i]) { |
| 1954 | Changed = true; |
| 1955 | Ops[i] = Op; |
| 1956 | } |
| 1957 | } |
Chris Lattner | ce7518c | 2006-01-26 22:24:51 +0000 | [diff] [blame] | 1958 | } |
Chris Lattner | 25a022c | 2006-07-11 01:40:09 +0000 | [diff] [blame] | 1959 | |
| 1960 | if (HasInFlag) { |
| 1961 | Op = LegalizeOp(Ops.back()); |
| 1962 | Changed |= Op != Ops.back(); |
| 1963 | Ops.back() = Op; |
| 1964 | } |
| 1965 | |
| 1966 | if (Changed) |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1967 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | ce7518c | 2006-01-26 22:24:51 +0000 | [diff] [blame] | 1968 | |
| 1969 | // 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] | 1970 | AddLegalizedOperand(SDValue(Node, 0), Result.getValue(0)); |
| 1971 | AddLegalizedOperand(SDValue(Node, 1), Result.getValue(1)); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 1972 | return Result.getValue(Op.getResNo()); |
Chris Lattner | 25a022c | 2006-07-11 01:40:09 +0000 | [diff] [blame] | 1973 | } |
Chris Lattner | c7af179 | 2005-01-07 22:12:08 +0000 | [diff] [blame] | 1974 | case ISD::BR: |
| 1975 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1976 | // Ensure that libcalls are emitted before a branch. |
| 1977 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1978 | Tmp1 = LegalizeOp(Tmp1); |
| 1979 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 1980 | |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1981 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
Chris Lattner | c7af179 | 2005-01-07 22:12:08 +0000 | [diff] [blame] | 1982 | break; |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 1983 | case ISD::BRIND: |
| 1984 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1985 | // Ensure that libcalls are emitted before a branch. |
| 1986 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1987 | Tmp1 = LegalizeOp(Tmp1); |
| 1988 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 1989 | |
| 1990 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 1991 | default: assert(0 && "Indirect target must be legal type (pointer)!"); |
| 1992 | case Legal: |
| 1993 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the condition. |
| 1994 | break; |
| 1995 | } |
| 1996 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 1997 | break; |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 1998 | case ISD::BR_JT: |
| 1999 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 2000 | // Ensure that libcalls are emitted before a branch. |
| 2001 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 2002 | Tmp1 = LegalizeOp(Tmp1); |
| 2003 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 2004 | |
| 2005 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the jumptable node. |
| 2006 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
| 2007 | |
| 2008 | switch (TLI.getOperationAction(ISD::BR_JT, MVT::Other)) { |
| 2009 | default: assert(0 && "This action is not supported yet!"); |
| 2010 | case TargetLowering::Legal: break; |
| 2011 | case TargetLowering::Custom: |
| 2012 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2013 | if (Tmp1.getNode()) Result = Tmp1; |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 2014 | break; |
| 2015 | case TargetLowering::Expand: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2016 | SDValue Chain = Result.getOperand(0); |
| 2017 | SDValue Table = Result.getOperand(1); |
| 2018 | SDValue Index = Result.getOperand(2); |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 2019 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2020 | MVT PTy = TLI.getPointerTy(); |
Jim Laskey | acd80ac | 2006-12-14 19:17:33 +0000 | [diff] [blame] | 2021 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2022 | unsigned EntrySize = MF.getJumpTableInfo()->getEntrySize(); |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 2023 | Index= DAG.getNode(ISD::MUL, PTy, Index, DAG.getConstant(EntrySize, PTy)); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2024 | SDValue Addr = DAG.getNode(ISD::ADD, PTy, Index, Table); |
Jim Laskey | acd80ac | 2006-12-14 19:17:33 +0000 | [diff] [blame] | 2025 | |
Duncan Sands | 712f7b3 | 2008-12-12 08:13:38 +0000 | [diff] [blame] | 2026 | MVT MemVT = MVT::getIntegerVT(EntrySize * 8); |
| 2027 | SDValue LD = DAG.getExtLoad(ISD::SEXTLOAD, PTy, Chain, Addr, |
| 2028 | PseudoSourceValue::getJumpTable(), 0, MemVT); |
Evan Cheng | cc41586 | 2007-11-09 01:32:10 +0000 | [diff] [blame] | 2029 | Addr = LD; |
Jim Laskey | acd80ac | 2006-12-14 19:17:33 +0000 | [diff] [blame] | 2030 | if (TLI.getTargetMachine().getRelocationModel() == Reloc::PIC_) { |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 2031 | // For PIC, the sequence is: |
| 2032 | // BRIND(load(Jumptable + index) + RelocBase) |
Evan Cheng | cc41586 | 2007-11-09 01:32:10 +0000 | [diff] [blame] | 2033 | // RelocBase can be JumpTable, GOT or some sort of global base. |
Evan Cheng | cc41586 | 2007-11-09 01:32:10 +0000 | [diff] [blame] | 2034 | Addr = DAG.getNode(ISD::ADD, PTy, Addr, |
| 2035 | TLI.getPICJumpTableRelocBase(Table, DAG)); |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 2036 | } |
Evan Cheng | cc41586 | 2007-11-09 01:32:10 +0000 | [diff] [blame] | 2037 | Result = DAG.getNode(ISD::BRIND, MVT::Other, LD.getValue(1), Addr); |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 2038 | } |
| 2039 | } |
| 2040 | break; |
Chris Lattner | c18ae4c | 2005-01-07 08:19:42 +0000 | [diff] [blame] | 2041 | case ISD::BRCOND: |
| 2042 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 2043 | // Ensure that libcalls are emitted before a return. |
| 2044 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 2045 | Tmp1 = LegalizeOp(Tmp1); |
| 2046 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 2047 | |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 2048 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 2049 | case Expand: assert(0 && "It's impossible to expand bools"); |
| 2050 | case Legal: |
| 2051 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the condition. |
| 2052 | break; |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 2053 | case Promote: { |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 2054 | Tmp2 = PromoteOp(Node->getOperand(1)); // Promote the condition. |
Chris Lattner | f990817 | 2006-11-27 04:39:56 +0000 | [diff] [blame] | 2055 | |
| 2056 | // The top bits of the promoted condition are not necessarily zero, ensure |
| 2057 | // that the value is properly zero extended. |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 2058 | unsigned BitWidth = Tmp2.getValueSizeInBits(); |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2059 | if (!DAG.MaskedValueIsZero(Tmp2, |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 2060 | APInt::getHighBitsSet(BitWidth, BitWidth-1))) |
Chris Lattner | f990817 | 2006-11-27 04:39:56 +0000 | [diff] [blame] | 2061 | Tmp2 = DAG.getZeroExtendInReg(Tmp2, MVT::i1); |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 2062 | break; |
| 2063 | } |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 2064 | } |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2065 | |
| 2066 | // Basic block destination (Op#2) is always legal. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2067 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 2068 | |
| 2069 | switch (TLI.getOperationAction(ISD::BRCOND, MVT::Other)) { |
| 2070 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2071 | case TargetLowering::Legal: break; |
| 2072 | case TargetLowering::Custom: |
| 2073 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2074 | if (Tmp1.getNode()) Result = Tmp1; |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2075 | break; |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 2076 | case TargetLowering::Expand: |
| 2077 | // Expand brcond's setcc into its constituent parts and create a BR_CC |
| 2078 | // Node. |
| 2079 | if (Tmp2.getOpcode() == ISD::SETCC) { |
| 2080 | Result = DAG.getNode(ISD::BR_CC, MVT::Other, Tmp1, Tmp2.getOperand(2), |
| 2081 | Tmp2.getOperand(0), Tmp2.getOperand(1), |
| 2082 | Node->getOperand(2)); |
| 2083 | } else { |
| 2084 | Result = DAG.getNode(ISD::BR_CC, MVT::Other, Tmp1, |
| 2085 | DAG.getCondCode(ISD::SETNE), Tmp2, |
| 2086 | DAG.getConstant(0, Tmp2.getValueType()), |
| 2087 | Node->getOperand(2)); |
| 2088 | } |
| 2089 | break; |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 2090 | } |
| 2091 | break; |
| 2092 | case ISD::BR_CC: |
| 2093 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 2094 | // Ensure that libcalls are emitted before a branch. |
| 2095 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 2096 | Tmp1 = LegalizeOp(Tmp1); |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 2097 | Tmp2 = Node->getOperand(2); // LHS |
| 2098 | Tmp3 = Node->getOperand(3); // RHS |
| 2099 | Tmp4 = Node->getOperand(1); // CC |
| 2100 | |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 2101 | LegalizeSetCC(TLI.getSetCCResultType(Tmp2.getValueType()), Tmp2, Tmp3,Tmp4); |
Evan Cheng | 722cb36 | 2006-12-18 22:55:34 +0000 | [diff] [blame] | 2102 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 2103 | |
Evan Cheng | 7f04268 | 2008-10-15 02:05:31 +0000 | [diff] [blame] | 2104 | // 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] | 2105 | // the LHS is a legal SETCC itself. In this case, we need to compare |
| 2106 | // the result against zero to select between true and false values. |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2107 | if (Tmp3.getNode() == 0) { |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 2108 | Tmp3 = DAG.getConstant(0, Tmp2.getValueType()); |
| 2109 | Tmp4 = DAG.getCondCode(ISD::SETNE); |
Chris Lattner | 181b7a3 | 2005-12-17 23:46:46 +0000 | [diff] [blame] | 2110 | } |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 2111 | |
| 2112 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp4, Tmp2, Tmp3, |
| 2113 | Node->getOperand(4)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2114 | |
Chris Lattner | 181b7a3 | 2005-12-17 23:46:46 +0000 | [diff] [blame] | 2115 | switch (TLI.getOperationAction(ISD::BR_CC, Tmp3.getValueType())) { |
| 2116 | default: assert(0 && "Unexpected action for BR_CC!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2117 | case TargetLowering::Legal: break; |
| 2118 | case TargetLowering::Custom: |
| 2119 | Tmp4 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2120 | if (Tmp4.getNode()) Result = Tmp4; |
Chris Lattner | 181b7a3 | 2005-12-17 23:46:46 +0000 | [diff] [blame] | 2121 | break; |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 2122 | } |
Chris Lattner | c18ae4c | 2005-01-07 08:19:42 +0000 | [diff] [blame] | 2123 | break; |
Evan Cheng | f3fd9fe | 2005-12-23 07:29:34 +0000 | [diff] [blame] | 2124 | case ISD::LOAD: { |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2125 | LoadSDNode *LD = cast<LoadSDNode>(Node); |
| 2126 | Tmp1 = LegalizeOp(LD->getChain()); // Legalize the chain. |
| 2127 | Tmp2 = LegalizeOp(LD->getBasePtr()); // Legalize the base pointer. |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 2128 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2129 | ISD::LoadExtType ExtType = LD->getExtensionType(); |
| 2130 | if (ExtType == ISD::NON_EXTLOAD) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2131 | MVT VT = Node->getValueType(0); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2132 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, LD->getOffset()); |
| 2133 | Tmp3 = Result.getValue(0); |
| 2134 | Tmp4 = Result.getValue(1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2135 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2136 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 2137 | default: assert(0 && "This action is not supported yet!"); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2138 | case TargetLowering::Legal: |
| 2139 | // If this is an unaligned load and the target doesn't support it, |
| 2140 | // expand it. |
| 2141 | if (!TLI.allowsUnalignedMemoryAccesses()) { |
| 2142 | unsigned ABIAlignment = TLI.getTargetData()-> |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2143 | getABITypeAlignment(LD->getMemoryVT().getTypeForMVT()); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2144 | if (LD->getAlignment() < ABIAlignment){ |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2145 | Result = ExpandUnalignedLoad(cast<LoadSDNode>(Result.getNode()), DAG, |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2146 | TLI); |
| 2147 | Tmp3 = Result.getOperand(0); |
| 2148 | Tmp4 = Result.getOperand(1); |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 2149 | Tmp3 = LegalizeOp(Tmp3); |
| 2150 | Tmp4 = LegalizeOp(Tmp4); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2151 | } |
| 2152 | } |
| 2153 | break; |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2154 | case TargetLowering::Custom: |
| 2155 | Tmp1 = TLI.LowerOperation(Tmp3, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2156 | if (Tmp1.getNode()) { |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2157 | Tmp3 = LegalizeOp(Tmp1); |
| 2158 | Tmp4 = LegalizeOp(Tmp1.getValue(1)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2159 | } |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2160 | break; |
| 2161 | case TargetLowering::Promote: { |
| 2162 | // Only promote a load of vector type to another. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2163 | assert(VT.isVector() && "Cannot promote this load!"); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2164 | // Change base type to a different vector type. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2165 | MVT NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), VT); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2166 | |
| 2167 | Tmp1 = DAG.getLoad(NVT, Tmp1, Tmp2, LD->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2168 | LD->getSrcValueOffset(), |
| 2169 | LD->isVolatile(), LD->getAlignment()); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2170 | Tmp3 = LegalizeOp(DAG.getNode(ISD::BIT_CONVERT, VT, Tmp1)); |
| 2171 | Tmp4 = LegalizeOp(Tmp1.getValue(1)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2172 | break; |
Andrew Lenharth | 9d416f7 | 2005-06-30 19:22:37 +0000 | [diff] [blame] | 2173 | } |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2174 | } |
| 2175 | // Since loads produce two values, make sure to remember that we |
| 2176 | // legalized both of them. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2177 | AddLegalizedOperand(SDValue(Node, 0), Tmp3); |
| 2178 | AddLegalizedOperand(SDValue(Node, 1), Tmp4); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 2179 | return Op.getResNo() ? Tmp4 : Tmp3; |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2180 | } else { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2181 | MVT SrcVT = LD->getMemoryVT(); |
| 2182 | unsigned SrcWidth = SrcVT.getSizeInBits(); |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2183 | int SVOffset = LD->getSrcValueOffset(); |
| 2184 | unsigned Alignment = LD->getAlignment(); |
| 2185 | bool isVolatile = LD->isVolatile(); |
| 2186 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2187 | if (SrcWidth != SrcVT.getStoreSizeInBits() && |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2188 | // Some targets pretend to have an i1 loading operation, and actually |
| 2189 | // load an i8. This trick is correct for ZEXTLOAD because the top 7 |
| 2190 | // bits are guaranteed to be zero; it helps the optimizers understand |
| 2191 | // that these bits are zero. It is also useful for EXTLOAD, since it |
| 2192 | // tells the optimizers that those bits are undefined. It would be |
| 2193 | // nice to have an effective generic way of getting these benefits... |
| 2194 | // Until such a way is found, don't insist on promoting i1 here. |
| 2195 | (SrcVT != MVT::i1 || |
Evan Cheng | 0329466 | 2008-10-14 21:26:46 +0000 | [diff] [blame] | 2196 | TLI.getLoadExtAction(ExtType, MVT::i1) == TargetLowering::Promote)) { |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2197 | // Promote to a byte-sized load if not loading an integral number of |
| 2198 | // bytes. For example, promote EXTLOAD:i20 -> EXTLOAD:i24. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2199 | unsigned NewWidth = SrcVT.getStoreSizeInBits(); |
| 2200 | MVT NVT = MVT::getIntegerVT(NewWidth); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2201 | SDValue Ch; |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2202 | |
| 2203 | // The extra bits are guaranteed to be zero, since we stored them that |
| 2204 | // way. A zext load from NVT thus automatically gives zext from SrcVT. |
| 2205 | |
| 2206 | ISD::LoadExtType NewExtType = |
| 2207 | ExtType == ISD::ZEXTLOAD ? ISD::ZEXTLOAD : ISD::EXTLOAD; |
| 2208 | |
| 2209 | Result = DAG.getExtLoad(NewExtType, Node->getValueType(0), |
| 2210 | Tmp1, Tmp2, LD->getSrcValue(), SVOffset, |
| 2211 | NVT, isVolatile, Alignment); |
| 2212 | |
| 2213 | Ch = Result.getValue(1); // The chain. |
| 2214 | |
| 2215 | if (ExtType == ISD::SEXTLOAD) |
| 2216 | // Having the top bits zero doesn't help when sign extending. |
| 2217 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(), |
| 2218 | Result, DAG.getValueType(SrcVT)); |
| 2219 | else if (ExtType == ISD::ZEXTLOAD || NVT == Result.getValueType()) |
| 2220 | // All the top bits are guaranteed to be zero - inform the optimizers. |
| 2221 | Result = DAG.getNode(ISD::AssertZext, Result.getValueType(), Result, |
| 2222 | DAG.getValueType(SrcVT)); |
| 2223 | |
| 2224 | Tmp1 = LegalizeOp(Result); |
| 2225 | Tmp2 = LegalizeOp(Ch); |
| 2226 | } else if (SrcWidth & (SrcWidth - 1)) { |
| 2227 | // 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] | 2228 | assert(SrcVT.isExtended() && !SrcVT.isVector() && |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2229 | "Unsupported extload!"); |
| 2230 | unsigned RoundWidth = 1 << Log2_32(SrcWidth); |
| 2231 | assert(RoundWidth < SrcWidth); |
| 2232 | unsigned ExtraWidth = SrcWidth - RoundWidth; |
| 2233 | assert(ExtraWidth < RoundWidth); |
| 2234 | assert(!(RoundWidth % 8) && !(ExtraWidth % 8) && |
| 2235 | "Load size not an integral number of bytes!"); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2236 | MVT RoundVT = MVT::getIntegerVT(RoundWidth); |
| 2237 | MVT ExtraVT = MVT::getIntegerVT(ExtraWidth); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2238 | SDValue Lo, Hi, Ch; |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2239 | unsigned IncrementSize; |
| 2240 | |
| 2241 | if (TLI.isLittleEndian()) { |
| 2242 | // EXTLOAD:i24 -> ZEXTLOAD:i16 | (shl EXTLOAD@+2:i8, 16) |
| 2243 | // Load the bottom RoundWidth bits. |
| 2244 | Lo = DAG.getExtLoad(ISD::ZEXTLOAD, Node->getValueType(0), Tmp1, Tmp2, |
| 2245 | LD->getSrcValue(), SVOffset, RoundVT, isVolatile, |
| 2246 | Alignment); |
| 2247 | |
| 2248 | // Load the remaining ExtraWidth bits. |
| 2249 | IncrementSize = RoundWidth / 8; |
| 2250 | Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2, |
| 2251 | DAG.getIntPtrConstant(IncrementSize)); |
| 2252 | Hi = DAG.getExtLoad(ExtType, Node->getValueType(0), Tmp1, Tmp2, |
| 2253 | LD->getSrcValue(), SVOffset + IncrementSize, |
| 2254 | ExtraVT, isVolatile, |
| 2255 | MinAlign(Alignment, IncrementSize)); |
| 2256 | |
| 2257 | // Build a factor node to remember that this load is independent of the |
| 2258 | // other one. |
| 2259 | Ch = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1), |
| 2260 | Hi.getValue(1)); |
| 2261 | |
| 2262 | // Move the top bits to the right place. |
| 2263 | Hi = DAG.getNode(ISD::SHL, Hi.getValueType(), Hi, |
| 2264 | DAG.getConstant(RoundWidth, TLI.getShiftAmountTy())); |
| 2265 | |
| 2266 | // Join the hi and lo parts. |
| 2267 | Result = DAG.getNode(ISD::OR, Node->getValueType(0), Lo, Hi); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2268 | } else { |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2269 | // Big endian - avoid unaligned loads. |
| 2270 | // EXTLOAD:i24 -> (shl EXTLOAD:i16, 8) | ZEXTLOAD@+2:i8 |
| 2271 | // Load the top RoundWidth bits. |
| 2272 | Hi = DAG.getExtLoad(ExtType, Node->getValueType(0), Tmp1, Tmp2, |
| 2273 | LD->getSrcValue(), SVOffset, RoundVT, isVolatile, |
| 2274 | Alignment); |
| 2275 | |
| 2276 | // Load the remaining ExtraWidth bits. |
| 2277 | IncrementSize = RoundWidth / 8; |
| 2278 | Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2, |
| 2279 | DAG.getIntPtrConstant(IncrementSize)); |
| 2280 | Lo = DAG.getExtLoad(ISD::ZEXTLOAD, Node->getValueType(0), Tmp1, Tmp2, |
| 2281 | LD->getSrcValue(), SVOffset + IncrementSize, |
| 2282 | ExtraVT, isVolatile, |
| 2283 | MinAlign(Alignment, IncrementSize)); |
| 2284 | |
| 2285 | // Build a factor node to remember that this load is independent of the |
| 2286 | // other one. |
| 2287 | Ch = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1), |
| 2288 | Hi.getValue(1)); |
| 2289 | |
| 2290 | // Move the top bits to the right place. |
| 2291 | Hi = DAG.getNode(ISD::SHL, Hi.getValueType(), Hi, |
| 2292 | DAG.getConstant(ExtraWidth, TLI.getShiftAmountTy())); |
| 2293 | |
| 2294 | // Join the hi and lo parts. |
| 2295 | Result = DAG.getNode(ISD::OR, Node->getValueType(0), Lo, Hi); |
| 2296 | } |
| 2297 | |
| 2298 | Tmp1 = LegalizeOp(Result); |
| 2299 | Tmp2 = LegalizeOp(Ch); |
| 2300 | } else { |
Evan Cheng | 0329466 | 2008-10-14 21:26:46 +0000 | [diff] [blame] | 2301 | switch (TLI.getLoadExtAction(ExtType, SrcVT)) { |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2302 | default: assert(0 && "This action is not supported yet!"); |
| 2303 | case TargetLowering::Custom: |
| 2304 | isCustom = true; |
| 2305 | // FALLTHROUGH |
| 2306 | case TargetLowering::Legal: |
| 2307 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, LD->getOffset()); |
| 2308 | Tmp1 = Result.getValue(0); |
| 2309 | Tmp2 = Result.getValue(1); |
| 2310 | |
| 2311 | if (isCustom) { |
| 2312 | Tmp3 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2313 | if (Tmp3.getNode()) { |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2314 | Tmp1 = LegalizeOp(Tmp3); |
| 2315 | Tmp2 = LegalizeOp(Tmp3.getValue(1)); |
| 2316 | } |
| 2317 | } else { |
| 2318 | // If this is an unaligned load and the target doesn't support it, |
| 2319 | // expand it. |
| 2320 | if (!TLI.allowsUnalignedMemoryAccesses()) { |
| 2321 | unsigned ABIAlignment = TLI.getTargetData()-> |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2322 | getABITypeAlignment(LD->getMemoryVT().getTypeForMVT()); |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2323 | if (LD->getAlignment() < ABIAlignment){ |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2324 | Result = ExpandUnalignedLoad(cast<LoadSDNode>(Result.getNode()), DAG, |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2325 | TLI); |
| 2326 | Tmp1 = Result.getOperand(0); |
| 2327 | Tmp2 = Result.getOperand(1); |
| 2328 | Tmp1 = LegalizeOp(Tmp1); |
| 2329 | Tmp2 = LegalizeOp(Tmp2); |
| 2330 | } |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2331 | } |
| 2332 | } |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2333 | break; |
| 2334 | case TargetLowering::Expand: |
| 2335 | // f64 = EXTLOAD f32 should expand to LOAD, FP_EXTEND |
| 2336 | if (SrcVT == MVT::f32 && Node->getValueType(0) == MVT::f64) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2337 | SDValue Load = DAG.getLoad(SrcVT, Tmp1, Tmp2, LD->getSrcValue(), |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2338 | LD->getSrcValueOffset(), |
| 2339 | LD->isVolatile(), LD->getAlignment()); |
| 2340 | Result = DAG.getNode(ISD::FP_EXTEND, Node->getValueType(0), Load); |
| 2341 | Tmp1 = LegalizeOp(Result); // Relegalize new nodes. |
| 2342 | Tmp2 = LegalizeOp(Load.getValue(1)); |
| 2343 | break; |
| 2344 | } |
| 2345 | assert(ExtType != ISD::EXTLOAD &&"EXTLOAD should always be supported!"); |
| 2346 | // Turn the unsupported load into an EXTLOAD followed by an explicit |
| 2347 | // zero/sign extend inreg. |
| 2348 | Result = DAG.getExtLoad(ISD::EXTLOAD, Node->getValueType(0), |
| 2349 | Tmp1, Tmp2, LD->getSrcValue(), |
| 2350 | LD->getSrcValueOffset(), SrcVT, |
| 2351 | LD->isVolatile(), LD->getAlignment()); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2352 | SDValue ValRes; |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2353 | if (ExtType == ISD::SEXTLOAD) |
| 2354 | ValRes = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(), |
| 2355 | Result, DAG.getValueType(SrcVT)); |
| 2356 | else |
| 2357 | ValRes = DAG.getZeroExtendInReg(Result, SrcVT); |
| 2358 | Tmp1 = LegalizeOp(ValRes); // Relegalize new nodes. |
| 2359 | Tmp2 = LegalizeOp(Result.getValue(1)); // Relegalize new nodes. |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2360 | break; |
| 2361 | } |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2362 | } |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2363 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2364 | // Since loads produce two values, make sure to remember that we legalized |
| 2365 | // both of them. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2366 | AddLegalizedOperand(SDValue(Node, 0), Tmp1); |
| 2367 | AddLegalizedOperand(SDValue(Node, 1), Tmp2); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 2368 | return Op.getResNo() ? Tmp2 : Tmp1; |
Chris Lattner | 01ff721 | 2005-04-10 22:54:25 +0000 | [diff] [blame] | 2369 | } |
Chris Lattner | 01ff721 | 2005-04-10 22:54:25 +0000 | [diff] [blame] | 2370 | } |
Nate Begeman | 5dc897b | 2005-10-19 00:06:56 +0000 | [diff] [blame] | 2371 | case ISD::EXTRACT_ELEMENT: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2372 | MVT OpTy = Node->getOperand(0).getValueType(); |
Nate Begeman | 5dc897b | 2005-10-19 00:06:56 +0000 | [diff] [blame] | 2373 | switch (getTypeAction(OpTy)) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2374 | default: assert(0 && "EXTRACT_ELEMENT action for type unimplemented!"); |
Nate Begeman | 5dc897b | 2005-10-19 00:06:56 +0000 | [diff] [blame] | 2375 | case Legal: |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2376 | if (cast<ConstantSDNode>(Node->getOperand(1))->getZExtValue()) { |
Nate Begeman | 5dc897b | 2005-10-19 00:06:56 +0000 | [diff] [blame] | 2377 | // 1 -> Hi |
| 2378 | Result = DAG.getNode(ISD::SRL, OpTy, Node->getOperand(0), |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2379 | DAG.getConstant(OpTy.getSizeInBits()/2, |
Nate Begeman | 5dc897b | 2005-10-19 00:06:56 +0000 | [diff] [blame] | 2380 | TLI.getShiftAmountTy())); |
| 2381 | Result = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0), Result); |
| 2382 | } else { |
| 2383 | // 0 -> Lo |
| 2384 | Result = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0), |
| 2385 | Node->getOperand(0)); |
| 2386 | } |
Nate Begeman | 5dc897b | 2005-10-19 00:06:56 +0000 | [diff] [blame] | 2387 | break; |
| 2388 | case Expand: |
| 2389 | // Get both the low and high parts. |
| 2390 | ExpandOp(Node->getOperand(0), Tmp1, Tmp2); |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2391 | if (cast<ConstantSDNode>(Node->getOperand(1))->getZExtValue()) |
Nate Begeman | 5dc897b | 2005-10-19 00:06:56 +0000 | [diff] [blame] | 2392 | Result = Tmp2; // 1 -> Hi |
| 2393 | else |
| 2394 | Result = Tmp1; // 0 -> Lo |
| 2395 | break; |
| 2396 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2397 | break; |
Nate Begeman | 5dc897b | 2005-10-19 00:06:56 +0000 | [diff] [blame] | 2398 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2399 | |
| 2400 | case ISD::CopyToReg: |
| 2401 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2402 | |
Chris Lattner | c9c60f6 | 2005-08-24 16:35:28 +0000 | [diff] [blame] | 2403 | assert(isTypeLegal(Node->getOperand(2).getValueType()) && |
Chris Lattner | d5d0f9b | 2005-08-16 21:55:35 +0000 | [diff] [blame] | 2404 | "Register type must be legal!"); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 2405 | // Legalize the incoming value (must be a legal type). |
Chris Lattner | d5d0f9b | 2005-08-16 21:55:35 +0000 | [diff] [blame] | 2406 | Tmp2 = LegalizeOp(Node->getOperand(2)); |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 2407 | if (Node->getNumValues() == 1) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2408 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1), Tmp2); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 2409 | } else { |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 2410 | assert(Node->getNumValues() == 2 && "Unknown CopyToReg"); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2411 | if (Node->getNumOperands() == 4) { |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 2412 | Tmp3 = LegalizeOp(Node->getOperand(3)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2413 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1), Tmp2, |
| 2414 | Tmp3); |
| 2415 | } else { |
| 2416 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1),Tmp2); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 2417 | } |
| 2418 | |
| 2419 | // Since this produces two values, make sure to remember that we legalized |
| 2420 | // both of them. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2421 | AddLegalizedOperand(SDValue(Node, 0), Result.getValue(0)); |
| 2422 | AddLegalizedOperand(SDValue(Node, 1), Result.getValue(1)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2423 | return Result; |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 2424 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2425 | break; |
| 2426 | |
| 2427 | case ISD::RET: |
| 2428 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 2429 | |
| 2430 | // Ensure that libcalls are emitted before a return. |
| 2431 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 2432 | Tmp1 = LegalizeOp(Tmp1); |
| 2433 | LastCALLSEQ_END = DAG.getEntryNode(); |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2434 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2435 | switch (Node->getNumOperands()) { |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 2436 | case 3: // ret val |
Evan Cheng | 98f8aeb | 2006-04-11 06:33:39 +0000 | [diff] [blame] | 2437 | Tmp2 = Node->getOperand(1); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 2438 | Tmp3 = Node->getOperand(2); // Signness |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2439 | switch (getTypeAction(Tmp2.getValueType())) { |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2440 | case Legal: |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 2441 | Result = DAG.UpdateNodeOperands(Result, Tmp1, LegalizeOp(Tmp2), Tmp3); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2442 | break; |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2443 | case Expand: |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2444 | if (!Tmp2.getValueType().isVector()) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2445 | SDValue Lo, Hi; |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2446 | ExpandOp(Tmp2, Lo, Hi); |
Chris Lattner | edf2e8d | 2007-03-06 20:01:06 +0000 | [diff] [blame] | 2447 | |
| 2448 | // Big endian systems want the hi reg first. |
Duncan Sands | 0753fc1 | 2008-02-11 10:37:04 +0000 | [diff] [blame] | 2449 | if (TLI.isBigEndian()) |
Chris Lattner | edf2e8d | 2007-03-06 20:01:06 +0000 | [diff] [blame] | 2450 | std::swap(Lo, Hi); |
| 2451 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2452 | if (Hi.getNode()) |
Evan Cheng | 13acce3 | 2006-12-11 19:27:14 +0000 | [diff] [blame] | 2453 | Result = DAG.getNode(ISD::RET, MVT::Other, Tmp1, Lo, Tmp3, Hi,Tmp3); |
| 2454 | else |
| 2455 | Result = DAG.getNode(ISD::RET, MVT::Other, Tmp1, Lo, Tmp3); |
Chris Lattner | f921a51 | 2006-08-21 20:24:53 +0000 | [diff] [blame] | 2456 | Result = LegalizeOp(Result); |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2457 | } else { |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2458 | SDNode *InVal = Tmp2.getNode(); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 2459 | int InIx = Tmp2.getResNo(); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2460 | unsigned NumElems = InVal->getValueType(InIx).getVectorNumElements(); |
| 2461 | MVT EVT = InVal->getValueType(InIx).getVectorElementType(); |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2462 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2463 | // Figure out if there is a simple type corresponding to this Vector |
Reid Spencer | ac9dcb9 | 2007-02-15 03:39:18 +0000 | [diff] [blame] | 2464 | // type. If so, convert to the vector type. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2465 | MVT TVT = MVT::getVectorVT(EVT, NumElems); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2466 | if (TLI.isTypeLegal(TVT)) { |
Reid Spencer | ac9dcb9 | 2007-02-15 03:39:18 +0000 | [diff] [blame] | 2467 | // Turn this into a return of the vector type. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2468 | Tmp2 = LegalizeOp(Tmp2); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 2469 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2470 | } else if (NumElems == 1) { |
| 2471 | // Turn this into a return of the scalar type. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2472 | Tmp2 = ScalarizeVectorOp(Tmp2); |
| 2473 | Tmp2 = LegalizeOp(Tmp2); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 2474 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | b49e52c | 2006-04-11 02:00:08 +0000 | [diff] [blame] | 2475 | |
| 2476 | // FIXME: Returns of gcc generic vectors smaller than a legal type |
| 2477 | // should be returned in integer registers! |
| 2478 | |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2479 | // The scalarized value type may not be legal, e.g. it might require |
| 2480 | // promotion or expansion. Relegalize the return. |
| 2481 | Result = LegalizeOp(Result); |
| 2482 | } else { |
Chris Lattner | b49e52c | 2006-04-11 02:00:08 +0000 | [diff] [blame] | 2483 | // FIXME: Returns of gcc generic vectors larger than a legal vector |
| 2484 | // type should be returned by reference! |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2485 | SDValue Lo, Hi; |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2486 | SplitVectorOp(Tmp2, Lo, Hi); |
Chris Lattner | fea997a | 2007-02-01 04:55:59 +0000 | [diff] [blame] | 2487 | Result = DAG.getNode(ISD::RET, MVT::Other, Tmp1, Lo, Tmp3, Hi,Tmp3); |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2488 | Result = LegalizeOp(Result); |
| 2489 | } |
| 2490 | } |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2491 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2492 | case Promote: |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 2493 | Tmp2 = PromoteOp(Node->getOperand(1)); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 2494 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2495 | Result = LegalizeOp(Result); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 2496 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2497 | } |
| 2498 | break; |
| 2499 | case 1: // ret void |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2500 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2501 | break; |
| 2502 | default: { // ret <values> |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2503 | SmallVector<SDValue, 8> NewValues; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2504 | NewValues.push_back(Tmp1); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 2505 | for (unsigned i = 1, e = Node->getNumOperands(); i < e; i += 2) |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2506 | switch (getTypeAction(Node->getOperand(i).getValueType())) { |
| 2507 | case Legal: |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 2508 | NewValues.push_back(LegalizeOp(Node->getOperand(i))); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 2509 | NewValues.push_back(Node->getOperand(i+1)); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2510 | break; |
| 2511 | case Expand: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2512 | SDValue Lo, Hi; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2513 | assert(!Node->getOperand(i).getValueType().isExtended() && |
Chris Lattner | b49e52c | 2006-04-11 02:00:08 +0000 | [diff] [blame] | 2514 | "FIXME: TODO: implement returning non-legal vector types!"); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2515 | ExpandOp(Node->getOperand(i), Lo, Hi); |
| 2516 | NewValues.push_back(Lo); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 2517 | NewValues.push_back(Node->getOperand(i+1)); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2518 | if (Hi.getNode()) { |
Evan Cheng | 13acce3 | 2006-12-11 19:27:14 +0000 | [diff] [blame] | 2519 | NewValues.push_back(Hi); |
| 2520 | NewValues.push_back(Node->getOperand(i+1)); |
| 2521 | } |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2522 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2523 | } |
| 2524 | case Promote: |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 2525 | assert(0 && "Can't promote multiple return value yet!"); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2526 | } |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2527 | |
| 2528 | if (NewValues.size() == Node->getNumOperands()) |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 2529 | Result = DAG.UpdateNodeOperands(Result, &NewValues[0],NewValues.size()); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2530 | else |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 2531 | Result = DAG.getNode(ISD::RET, MVT::Other, |
| 2532 | &NewValues[0], NewValues.size()); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2533 | break; |
| 2534 | } |
| 2535 | } |
Evan Cheng | 17c428e | 2006-01-06 00:41:43 +0000 | [diff] [blame] | 2536 | |
Chris Lattner | 6862dbc | 2006-01-29 21:02:23 +0000 | [diff] [blame] | 2537 | if (Result.getOpcode() == ISD::RET) { |
| 2538 | switch (TLI.getOperationAction(Result.getOpcode(), MVT::Other)) { |
| 2539 | default: assert(0 && "This action is not supported yet!"); |
| 2540 | case TargetLowering::Legal: break; |
| 2541 | case TargetLowering::Custom: |
| 2542 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2543 | if (Tmp1.getNode()) Result = Tmp1; |
Chris Lattner | 6862dbc | 2006-01-29 21:02:23 +0000 | [diff] [blame] | 2544 | break; |
| 2545 | } |
Evan Cheng | 17c428e | 2006-01-06 00:41:43 +0000 | [diff] [blame] | 2546 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2547 | break; |
Evan Cheng | f3fd9fe | 2005-12-23 07:29:34 +0000 | [diff] [blame] | 2548 | case ISD::STORE: { |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2549 | StoreSDNode *ST = cast<StoreSDNode>(Node); |
| 2550 | Tmp1 = LegalizeOp(ST->getChain()); // Legalize the chain. |
| 2551 | Tmp2 = LegalizeOp(ST->getBasePtr()); // Legalize the pointer. |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2552 | int SVOffset = ST->getSrcValueOffset(); |
| 2553 | unsigned Alignment = ST->getAlignment(); |
| 2554 | bool isVolatile = ST->isVolatile(); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2555 | |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2556 | if (!ST->isTruncatingStore()) { |
Chris Lattner | d93d46e | 2006-12-12 04:18:56 +0000 | [diff] [blame] | 2557 | // Turn 'store float 1.0, Ptr' -> 'store int 0x12345678, Ptr' |
| 2558 | // FIXME: We shouldn't do this for TargetConstantFP's. |
| 2559 | // FIXME: move this to the DAG Combiner! Note that we can't regress due |
| 2560 | // to phase ordering between legalized code and the dag combiner. This |
| 2561 | // probably means that we need to integrate dag combiner and legalizer |
| 2562 | // together. |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 2563 | // We generally can't do this one for long doubles. |
Chris Lattner | 2b4c279 | 2007-10-13 06:35:54 +0000 | [diff] [blame] | 2564 | if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(ST->getValue())) { |
Chris Lattner | 3cb9351 | 2007-10-15 05:46:06 +0000 | [diff] [blame] | 2565 | if (CFP->getValueType(0) == MVT::f32 && |
| 2566 | getTypeAction(MVT::i32) == Legal) { |
Dan Gohman | 6cf9b8a | 2008-03-11 00:11:06 +0000 | [diff] [blame] | 2567 | Tmp3 = DAG.getConstant(CFP->getValueAPF(). |
Dale Johannesen | 7111b02 | 2008-10-09 18:53:47 +0000 | [diff] [blame] | 2568 | bitcastToAPInt().zextOrTrunc(32), |
Dale Johannesen | 3f6eb74 | 2007-09-11 18:32:33 +0000 | [diff] [blame] | 2569 | MVT::i32); |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 2570 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
| 2571 | SVOffset, isVolatile, Alignment); |
| 2572 | break; |
| 2573 | } else if (CFP->getValueType(0) == MVT::f64) { |
Chris Lattner | 3cb9351 | 2007-10-15 05:46:06 +0000 | [diff] [blame] | 2574 | // If this target supports 64-bit registers, do a single 64-bit store. |
| 2575 | if (getTypeAction(MVT::i64) == Legal) { |
Dale Johannesen | 7111b02 | 2008-10-09 18:53:47 +0000 | [diff] [blame] | 2576 | Tmp3 = DAG.getConstant(CFP->getValueAPF().bitcastToAPInt(). |
Dan Gohman | 6cf9b8a | 2008-03-11 00:11:06 +0000 | [diff] [blame] | 2577 | zextOrTrunc(64), MVT::i64); |
Chris Lattner | 3cb9351 | 2007-10-15 05:46:06 +0000 | [diff] [blame] | 2578 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
| 2579 | SVOffset, isVolatile, Alignment); |
| 2580 | break; |
Duncan Sands | d4b9c17 | 2008-06-13 19:07:40 +0000 | [diff] [blame] | 2581 | } else if (getTypeAction(MVT::i32) == Legal && !ST->isVolatile()) { |
Chris Lattner | 3cb9351 | 2007-10-15 05:46:06 +0000 | [diff] [blame] | 2582 | // Otherwise, if the target supports 32-bit registers, use 2 32-bit |
| 2583 | // stores. If the target supports neither 32- nor 64-bits, this |
| 2584 | // xform is certainly not worth it. |
Dale Johannesen | 7111b02 | 2008-10-09 18:53:47 +0000 | [diff] [blame] | 2585 | const APInt &IntVal =CFP->getValueAPF().bitcastToAPInt(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2586 | SDValue Lo = DAG.getConstant(APInt(IntVal).trunc(32), MVT::i32); |
| 2587 | SDValue Hi = DAG.getConstant(IntVal.lshr(32).trunc(32), MVT::i32); |
Duncan Sands | 0753fc1 | 2008-02-11 10:37:04 +0000 | [diff] [blame] | 2588 | if (TLI.isBigEndian()) std::swap(Lo, Hi); |
Chris Lattner | 3cb9351 | 2007-10-15 05:46:06 +0000 | [diff] [blame] | 2589 | |
| 2590 | Lo = DAG.getStore(Tmp1, Lo, Tmp2, ST->getSrcValue(), |
| 2591 | SVOffset, isVolatile, Alignment); |
| 2592 | Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2, |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 2593 | DAG.getIntPtrConstant(4)); |
Chris Lattner | 3cb9351 | 2007-10-15 05:46:06 +0000 | [diff] [blame] | 2594 | Hi = DAG.getStore(Tmp1, Hi, Tmp2, ST->getSrcValue(), SVOffset+4, |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 2595 | isVolatile, MinAlign(Alignment, 4U)); |
Chris Lattner | 3cb9351 | 2007-10-15 05:46:06 +0000 | [diff] [blame] | 2596 | |
| 2597 | Result = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo, Hi); |
| 2598 | break; |
| 2599 | } |
Chris Lattner | d93d46e | 2006-12-12 04:18:56 +0000 | [diff] [blame] | 2600 | } |
Chris Lattner | d93d46e | 2006-12-12 04:18:56 +0000 | [diff] [blame] | 2601 | } |
| 2602 | |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 2603 | switch (getTypeAction(ST->getMemoryVT())) { |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2604 | case Legal: { |
| 2605 | Tmp3 = LegalizeOp(ST->getValue()); |
| 2606 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp3, Tmp2, |
| 2607 | ST->getOffset()); |
Evan Cheng | f3fd9fe | 2005-12-23 07:29:34 +0000 | [diff] [blame] | 2608 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2609 | MVT VT = Tmp3.getValueType(); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2610 | switch (TLI.getOperationAction(ISD::STORE, VT)) { |
| 2611 | default: assert(0 && "This action is not supported yet!"); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2612 | case TargetLowering::Legal: |
| 2613 | // If this is an unaligned store and the target doesn't support it, |
| 2614 | // expand it. |
| 2615 | if (!TLI.allowsUnalignedMemoryAccesses()) { |
| 2616 | unsigned ABIAlignment = TLI.getTargetData()-> |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2617 | getABITypeAlignment(ST->getMemoryVT().getTypeForMVT()); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2618 | if (ST->getAlignment() < ABIAlignment) |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2619 | Result = ExpandUnalignedStore(cast<StoreSDNode>(Result.getNode()), DAG, |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2620 | TLI); |
| 2621 | } |
| 2622 | break; |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2623 | case TargetLowering::Custom: |
| 2624 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2625 | if (Tmp1.getNode()) Result = Tmp1; |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2626 | break; |
| 2627 | case TargetLowering::Promote: |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2628 | assert(VT.isVector() && "Unknown legal promote case!"); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2629 | Tmp3 = DAG.getNode(ISD::BIT_CONVERT, |
| 2630 | TLI.getTypeToPromoteTo(ISD::STORE, VT), Tmp3); |
| 2631 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2632 | ST->getSrcValue(), SVOffset, isVolatile, |
| 2633 | Alignment); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2634 | break; |
| 2635 | } |
| 2636 | break; |
| 2637 | } |
| 2638 | case Promote: |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 2639 | if (!ST->getMemoryVT().isVector()) { |
| 2640 | // Truncate the value and store the result. |
| 2641 | Tmp3 = PromoteOp(ST->getValue()); |
| 2642 | Result = DAG.getTruncStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
| 2643 | SVOffset, ST->getMemoryVT(), |
| 2644 | isVolatile, Alignment); |
| 2645 | break; |
| 2646 | } |
| 2647 | // Fall thru to expand for vector |
| 2648 | case Expand: { |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2649 | unsigned IncrementSize = 0; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2650 | SDValue Lo, Hi; |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2651 | |
| 2652 | // If this is a vector type, then we have to calculate the increment as |
| 2653 | // the product of the element size in bytes, and the number of elements |
| 2654 | // in the high half of the vector. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2655 | if (ST->getValue().getValueType().isVector()) { |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2656 | SDNode *InVal = ST->getValue().getNode(); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 2657 | int InIx = ST->getValue().getResNo(); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2658 | MVT InVT = InVal->getValueType(InIx); |
| 2659 | unsigned NumElems = InVT.getVectorNumElements(); |
| 2660 | MVT EVT = InVT.getVectorElementType(); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2661 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2662 | // Figure out if there is a simple type corresponding to this Vector |
Reid Spencer | ac9dcb9 | 2007-02-15 03:39:18 +0000 | [diff] [blame] | 2663 | // type. If so, convert to the vector type. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2664 | MVT TVT = MVT::getVectorVT(EVT, NumElems); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2665 | if (TLI.isTypeLegal(TVT)) { |
Reid Spencer | ac9dcb9 | 2007-02-15 03:39:18 +0000 | [diff] [blame] | 2666 | // Turn this into a normal store of the vector type. |
Dan Gohman | 21be384 | 2008-02-15 18:11:59 +0000 | [diff] [blame] | 2667 | Tmp3 = LegalizeOp(ST->getValue()); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2668 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2669 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2670 | Result = LegalizeOp(Result); |
| 2671 | break; |
| 2672 | } else if (NumElems == 1) { |
| 2673 | // Turn this into a normal store of the scalar type. |
Dan Gohman | 21be384 | 2008-02-15 18:11:59 +0000 | [diff] [blame] | 2674 | Tmp3 = ScalarizeVectorOp(ST->getValue()); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2675 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2676 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2677 | // The scalarized value type may not be legal, e.g. it might require |
| 2678 | // promotion or expansion. Relegalize the scalar store. |
| 2679 | Result = LegalizeOp(Result); |
| 2680 | break; |
| 2681 | } else { |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 2682 | // Check if we have widen this node with another value |
| 2683 | std::map<SDValue, SDValue>::iterator I = |
| 2684 | WidenNodes.find(ST->getValue()); |
| 2685 | if (I != WidenNodes.end()) { |
| 2686 | Result = StoreWidenVectorOp(ST, Tmp1, Tmp2); |
| 2687 | break; |
| 2688 | } |
| 2689 | else { |
| 2690 | SplitVectorOp(ST->getValue(), Lo, Hi); |
| 2691 | IncrementSize = Lo.getNode()->getValueType(0).getVectorNumElements() * |
| 2692 | EVT.getSizeInBits()/8; |
| 2693 | } |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2694 | } |
| 2695 | } else { |
Dan Gohman | 21be384 | 2008-02-15 18:11:59 +0000 | [diff] [blame] | 2696 | ExpandOp(ST->getValue(), Lo, Hi); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2697 | IncrementSize = Hi.getNode() ? Hi.getValueType().getSizeInBits()/8 : 0; |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2698 | |
Richard Pennington | 4b052dc | 2008-09-25 16:15:10 +0000 | [diff] [blame] | 2699 | if (Hi.getNode() && TLI.isBigEndian()) |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2700 | std::swap(Lo, Hi); |
| 2701 | } |
| 2702 | |
| 2703 | Lo = DAG.getStore(Tmp1, Lo, Tmp2, ST->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2704 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 7b2b5c8 | 2006-12-12 19:53:13 +0000 | [diff] [blame] | 2705 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2706 | if (Hi.getNode() == NULL) { |
Evan Cheng | 7b2b5c8 | 2006-12-12 19:53:13 +0000 | [diff] [blame] | 2707 | // Must be int <-> float one-to-one expansion. |
| 2708 | Result = Lo; |
| 2709 | break; |
| 2710 | } |
| 2711 | |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2712 | Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2, |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 2713 | DAG.getIntPtrConstant(IncrementSize)); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2714 | assert(isTypeLegal(Tmp2.getValueType()) && |
| 2715 | "Pointers must be legal!"); |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2716 | SVOffset += IncrementSize; |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 2717 | Alignment = MinAlign(Alignment, IncrementSize); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2718 | Hi = DAG.getStore(Tmp1, Hi, Tmp2, ST->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2719 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2720 | Result = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo, Hi); |
| 2721 | break; |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 2722 | } // case Expand |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2723 | } |
| 2724 | } else { |
Chris Lattner | ddf8956 | 2008-01-17 19:59:44 +0000 | [diff] [blame] | 2725 | switch (getTypeAction(ST->getValue().getValueType())) { |
| 2726 | case Legal: |
| 2727 | Tmp3 = LegalizeOp(ST->getValue()); |
| 2728 | break; |
| 2729 | case Promote: |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 2730 | if (!ST->getValue().getValueType().isVector()) { |
| 2731 | // We can promote the value, the truncstore will still take care of it. |
| 2732 | Tmp3 = PromoteOp(ST->getValue()); |
| 2733 | break; |
| 2734 | } |
| 2735 | // Vector case falls through to expand |
Chris Lattner | ddf8956 | 2008-01-17 19:59:44 +0000 | [diff] [blame] | 2736 | case Expand: |
| 2737 | // Just store the low part. This may become a non-trunc store, so make |
| 2738 | // sure to use getTruncStore, not UpdateNodeOperands below. |
| 2739 | ExpandOp(ST->getValue(), Tmp3, Tmp4); |
| 2740 | return DAG.getTruncStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
| 2741 | SVOffset, MVT::i8, isVolatile, Alignment); |
| 2742 | } |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2743 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2744 | MVT StVT = ST->getMemoryVT(); |
| 2745 | unsigned StWidth = StVT.getSizeInBits(); |
Duncan Sands | 7e85720 | 2008-01-22 07:17:34 +0000 | [diff] [blame] | 2746 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2747 | if (StWidth != StVT.getStoreSizeInBits()) { |
Duncan Sands | 7e85720 | 2008-01-22 07:17:34 +0000 | [diff] [blame] | 2748 | // Promote to a byte-sized store with upper bits zero if not |
| 2749 | // storing an integral number of bytes. For example, promote |
| 2750 | // TRUNCSTORE:i1 X -> TRUNCSTORE:i8 (and X, 1) |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2751 | MVT NVT = MVT::getIntegerVT(StVT.getStoreSizeInBits()); |
Duncan Sands | 7e85720 | 2008-01-22 07:17:34 +0000 | [diff] [blame] | 2752 | Tmp3 = DAG.getZeroExtendInReg(Tmp3, StVT); |
| 2753 | Result = DAG.getTruncStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
| 2754 | SVOffset, NVT, isVolatile, Alignment); |
| 2755 | } else if (StWidth & (StWidth - 1)) { |
| 2756 | // 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] | 2757 | assert(StVT.isExtended() && !StVT.isVector() && |
Duncan Sands | 7e85720 | 2008-01-22 07:17:34 +0000 | [diff] [blame] | 2758 | "Unsupported truncstore!"); |
| 2759 | unsigned RoundWidth = 1 << Log2_32(StWidth); |
| 2760 | assert(RoundWidth < StWidth); |
| 2761 | unsigned ExtraWidth = StWidth - RoundWidth; |
| 2762 | assert(ExtraWidth < RoundWidth); |
| 2763 | assert(!(RoundWidth % 8) && !(ExtraWidth % 8) && |
| 2764 | "Store size not an integral number of bytes!"); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2765 | MVT RoundVT = MVT::getIntegerVT(RoundWidth); |
| 2766 | MVT ExtraVT = MVT::getIntegerVT(ExtraWidth); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2767 | SDValue Lo, Hi; |
Duncan Sands | 7e85720 | 2008-01-22 07:17:34 +0000 | [diff] [blame] | 2768 | unsigned IncrementSize; |
| 2769 | |
| 2770 | if (TLI.isLittleEndian()) { |
| 2771 | // TRUNCSTORE:i24 X -> TRUNCSTORE:i16 X, TRUNCSTORE@+2:i8 (srl X, 16) |
| 2772 | // Store the bottom RoundWidth bits. |
| 2773 | Lo = DAG.getTruncStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
| 2774 | SVOffset, RoundVT, |
| 2775 | isVolatile, Alignment); |
| 2776 | |
| 2777 | // Store the remaining ExtraWidth bits. |
| 2778 | IncrementSize = RoundWidth / 8; |
| 2779 | Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2, |
| 2780 | DAG.getIntPtrConstant(IncrementSize)); |
| 2781 | Hi = DAG.getNode(ISD::SRL, Tmp3.getValueType(), Tmp3, |
| 2782 | DAG.getConstant(RoundWidth, TLI.getShiftAmountTy())); |
| 2783 | Hi = DAG.getTruncStore(Tmp1, Hi, Tmp2, ST->getSrcValue(), |
| 2784 | SVOffset + IncrementSize, ExtraVT, isVolatile, |
| 2785 | MinAlign(Alignment, IncrementSize)); |
| 2786 | } else { |
| 2787 | // Big endian - avoid unaligned stores. |
| 2788 | // TRUNCSTORE:i24 X -> TRUNCSTORE:i16 (srl X, 8), TRUNCSTORE@+2:i8 X |
| 2789 | // Store the top RoundWidth bits. |
| 2790 | Hi = DAG.getNode(ISD::SRL, Tmp3.getValueType(), Tmp3, |
| 2791 | DAG.getConstant(ExtraWidth, TLI.getShiftAmountTy())); |
| 2792 | Hi = DAG.getTruncStore(Tmp1, Hi, Tmp2, ST->getSrcValue(), SVOffset, |
| 2793 | RoundVT, isVolatile, Alignment); |
| 2794 | |
| 2795 | // Store the remaining ExtraWidth bits. |
| 2796 | IncrementSize = RoundWidth / 8; |
| 2797 | Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2, |
| 2798 | DAG.getIntPtrConstant(IncrementSize)); |
| 2799 | Lo = DAG.getTruncStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
| 2800 | SVOffset + IncrementSize, ExtraVT, isVolatile, |
| 2801 | MinAlign(Alignment, IncrementSize)); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2802 | } |
Duncan Sands | 7e85720 | 2008-01-22 07:17:34 +0000 | [diff] [blame] | 2803 | |
| 2804 | // The order of the stores doesn't matter. |
| 2805 | Result = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo, Hi); |
| 2806 | } else { |
| 2807 | if (Tmp1 != ST->getChain() || Tmp3 != ST->getValue() || |
| 2808 | Tmp2 != ST->getBasePtr()) |
| 2809 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp3, Tmp2, |
| 2810 | ST->getOffset()); |
| 2811 | |
| 2812 | switch (TLI.getTruncStoreAction(ST->getValue().getValueType(), StVT)) { |
| 2813 | default: assert(0 && "This action is not supported yet!"); |
| 2814 | case TargetLowering::Legal: |
| 2815 | // If this is an unaligned store and the target doesn't support it, |
| 2816 | // expand it. |
| 2817 | if (!TLI.allowsUnalignedMemoryAccesses()) { |
| 2818 | unsigned ABIAlignment = TLI.getTargetData()-> |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2819 | getABITypeAlignment(ST->getMemoryVT().getTypeForMVT()); |
Duncan Sands | 7e85720 | 2008-01-22 07:17:34 +0000 | [diff] [blame] | 2820 | if (ST->getAlignment() < ABIAlignment) |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2821 | Result = ExpandUnalignedStore(cast<StoreSDNode>(Result.getNode()), DAG, |
Duncan Sands | 7e85720 | 2008-01-22 07:17:34 +0000 | [diff] [blame] | 2822 | TLI); |
| 2823 | } |
| 2824 | break; |
| 2825 | case TargetLowering::Custom: |
| 2826 | Result = TLI.LowerOperation(Result, DAG); |
| 2827 | break; |
| 2828 | case Expand: |
| 2829 | // TRUNCSTORE:i16 i32 -> STORE i16 |
| 2830 | assert(isTypeLegal(StVT) && "Do not know how to expand this store!"); |
| 2831 | Tmp3 = DAG.getNode(ISD::TRUNCATE, StVT, Tmp3); |
| 2832 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), SVOffset, |
| 2833 | isVolatile, Alignment); |
| 2834 | break; |
| 2835 | } |
Evan Cheng | f3fd9fe | 2005-12-23 07:29:34 +0000 | [diff] [blame] | 2836 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2837 | } |
| 2838 | break; |
Evan Cheng | f3fd9fe | 2005-12-23 07:29:34 +0000 | [diff] [blame] | 2839 | } |
Andrew Lenharth | 9576212 | 2005-03-31 21:24:06 +0000 | [diff] [blame] | 2840 | case ISD::PCMARKER: |
| 2841 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2842 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
Andrew Lenharth | 9576212 | 2005-03-31 21:24:06 +0000 | [diff] [blame] | 2843 | break; |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2844 | case ISD::STACKSAVE: |
| 2845 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2846 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 2847 | Tmp1 = Result.getValue(0); |
| 2848 | Tmp2 = Result.getValue(1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2849 | |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2850 | switch (TLI.getOperationAction(ISD::STACKSAVE, MVT::Other)) { |
| 2851 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2852 | case TargetLowering::Legal: break; |
| 2853 | case TargetLowering::Custom: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2854 | Tmp3 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2855 | if (Tmp3.getNode()) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2856 | Tmp1 = LegalizeOp(Tmp3); |
| 2857 | Tmp2 = LegalizeOp(Tmp3.getValue(1)); |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2858 | } |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2859 | break; |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2860 | case TargetLowering::Expand: |
Chris Lattner | 4f0d8e4 | 2006-01-13 17:48:44 +0000 | [diff] [blame] | 2861 | // Expand to CopyFromReg if the target set |
| 2862 | // StackPointerRegisterToSaveRestore. |
| 2863 | if (unsigned SP = TLI.getStackPointerRegisterToSaveRestore()) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2864 | Tmp1 = DAG.getCopyFromReg(Result.getOperand(0), SP, |
Chris Lattner | 4f0d8e4 | 2006-01-13 17:48:44 +0000 | [diff] [blame] | 2865 | Node->getValueType(0)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2866 | Tmp2 = Tmp1.getValue(1); |
Chris Lattner | 4f0d8e4 | 2006-01-13 17:48:44 +0000 | [diff] [blame] | 2867 | } else { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2868 | Tmp1 = DAG.getNode(ISD::UNDEF, Node->getValueType(0)); |
| 2869 | Tmp2 = Node->getOperand(0); |
Chris Lattner | 4f0d8e4 | 2006-01-13 17:48:44 +0000 | [diff] [blame] | 2870 | } |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2871 | break; |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2872 | } |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2873 | |
| 2874 | // Since stacksave produce two values, make sure to remember that we |
| 2875 | // legalized both of them. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2876 | AddLegalizedOperand(SDValue(Node, 0), Tmp1); |
| 2877 | AddLegalizedOperand(SDValue(Node, 1), Tmp2); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 2878 | return Op.getResNo() ? Tmp2 : Tmp1; |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2879 | |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2880 | case ISD::STACKRESTORE: |
| 2881 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 2882 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2883 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2884 | |
| 2885 | switch (TLI.getOperationAction(ISD::STACKRESTORE, MVT::Other)) { |
| 2886 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2887 | case TargetLowering::Legal: break; |
| 2888 | case TargetLowering::Custom: |
| 2889 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2890 | if (Tmp1.getNode()) Result = Tmp1; |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2891 | break; |
| 2892 | case TargetLowering::Expand: |
Chris Lattner | 4f0d8e4 | 2006-01-13 17:48:44 +0000 | [diff] [blame] | 2893 | // Expand to CopyToReg if the target set |
| 2894 | // StackPointerRegisterToSaveRestore. |
| 2895 | if (unsigned SP = TLI.getStackPointerRegisterToSaveRestore()) { |
| 2896 | Result = DAG.getCopyToReg(Tmp1, SP, Tmp2); |
| 2897 | } else { |
| 2898 | Result = Tmp1; |
| 2899 | } |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2900 | break; |
| 2901 | } |
| 2902 | break; |
| 2903 | |
Andrew Lenharth | 51b8d54 | 2005-11-11 16:47:30 +0000 | [diff] [blame] | 2904 | case ISD::READCYCLECOUNTER: |
| 2905 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2906 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Evan Cheng | f0b3ba6 | 2006-11-29 08:26:18 +0000 | [diff] [blame] | 2907 | switch (TLI.getOperationAction(ISD::READCYCLECOUNTER, |
| 2908 | Node->getValueType(0))) { |
| 2909 | default: assert(0 && "This action is not supported yet!"); |
Evan Cheng | 6a16c5a | 2006-11-29 19:13:47 +0000 | [diff] [blame] | 2910 | case TargetLowering::Legal: |
| 2911 | Tmp1 = Result.getValue(0); |
| 2912 | Tmp2 = Result.getValue(1); |
| 2913 | break; |
Evan Cheng | f0b3ba6 | 2006-11-29 08:26:18 +0000 | [diff] [blame] | 2914 | case TargetLowering::Custom: |
| 2915 | Result = TLI.LowerOperation(Result, DAG); |
Evan Cheng | 6a16c5a | 2006-11-29 19:13:47 +0000 | [diff] [blame] | 2916 | Tmp1 = LegalizeOp(Result.getValue(0)); |
| 2917 | Tmp2 = LegalizeOp(Result.getValue(1)); |
Evan Cheng | f0b3ba6 | 2006-11-29 08:26:18 +0000 | [diff] [blame] | 2918 | break; |
| 2919 | } |
Andrew Lenharth | 49c709f | 2005-12-02 04:56:24 +0000 | [diff] [blame] | 2920 | |
| 2921 | // Since rdcc produce two values, make sure to remember that we legalized |
| 2922 | // both of them. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2923 | AddLegalizedOperand(SDValue(Node, 0), Tmp1); |
| 2924 | AddLegalizedOperand(SDValue(Node, 1), Tmp2); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2925 | return Result; |
Andrew Lenharth | f70e30b | 2005-11-20 21:32:07 +0000 | [diff] [blame] | 2926 | |
Chris Lattner | 2ee743f | 2005-01-14 22:08:15 +0000 | [diff] [blame] | 2927 | case ISD::SELECT: |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 2928 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 2929 | case Expand: assert(0 && "It's impossible to expand bools"); |
| 2930 | case Legal: |
| 2931 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the condition. |
| 2932 | break; |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 2933 | case Promote: { |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 2934 | assert(!Node->getOperand(0).getValueType().isVector() && "not possible"); |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 2935 | Tmp1 = PromoteOp(Node->getOperand(0)); // Promote the condition. |
Chris Lattner | b6c8060 | 2006-11-28 01:03:30 +0000 | [diff] [blame] | 2936 | // Make sure the condition is either zero or one. |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 2937 | unsigned BitWidth = Tmp1.getValueSizeInBits(); |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2938 | if (!DAG.MaskedValueIsZero(Tmp1, |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 2939 | APInt::getHighBitsSet(BitWidth, BitWidth-1))) |
Chris Lattner | b6c8060 | 2006-11-28 01:03:30 +0000 | [diff] [blame] | 2940 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, MVT::i1); |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 2941 | break; |
| 2942 | } |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 2943 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2944 | Tmp2 = LegalizeOp(Node->getOperand(1)); // TrueVal |
Chris Lattner | 2ee743f | 2005-01-14 22:08:15 +0000 | [diff] [blame] | 2945 | Tmp3 = LegalizeOp(Node->getOperand(2)); // FalseVal |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2946 | |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2947 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2948 | |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 2949 | switch (TLI.getOperationAction(ISD::SELECT, Tmp2.getValueType())) { |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2950 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2951 | case TargetLowering::Legal: break; |
| 2952 | case TargetLowering::Custom: { |
| 2953 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2954 | if (Tmp1.getNode()) Result = Tmp1; |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2955 | break; |
| 2956 | } |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 2957 | case TargetLowering::Expand: |
| 2958 | if (Tmp1.getOpcode() == ISD::SETCC) { |
| 2959 | Result = DAG.getSelectCC(Tmp1.getOperand(0), Tmp1.getOperand(1), |
| 2960 | Tmp2, Tmp3, |
| 2961 | cast<CondCodeSDNode>(Tmp1.getOperand(2))->get()); |
| 2962 | } else { |
| 2963 | Result = DAG.getSelectCC(Tmp1, |
| 2964 | DAG.getConstant(0, Tmp1.getValueType()), |
| 2965 | Tmp2, Tmp3, ISD::SETNE); |
| 2966 | } |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2967 | break; |
| 2968 | case TargetLowering::Promote: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2969 | MVT NVT = |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2970 | TLI.getTypeToPromoteTo(ISD::SELECT, Tmp2.getValueType()); |
| 2971 | unsigned ExtOp, TruncOp; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2972 | if (Tmp2.getValueType().isVector()) { |
Evan Cheng | 41f6cbb | 2006-04-12 16:33:18 +0000 | [diff] [blame] | 2973 | ExtOp = ISD::BIT_CONVERT; |
| 2974 | TruncOp = ISD::BIT_CONVERT; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2975 | } else if (Tmp2.getValueType().isInteger()) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2976 | ExtOp = ISD::ANY_EXTEND; |
| 2977 | TruncOp = ISD::TRUNCATE; |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2978 | } else { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2979 | ExtOp = ISD::FP_EXTEND; |
| 2980 | TruncOp = ISD::FP_ROUND; |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2981 | } |
| 2982 | // Promote each of the values to the new type. |
| 2983 | Tmp2 = DAG.getNode(ExtOp, NVT, Tmp2); |
| 2984 | Tmp3 = DAG.getNode(ExtOp, NVT, Tmp3); |
| 2985 | // Perform the larger operation, then round down. |
| 2986 | Result = DAG.getNode(ISD::SELECT, NVT, Tmp1, Tmp2,Tmp3); |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 2987 | if (TruncOp != ISD::FP_ROUND) |
| 2988 | Result = DAG.getNode(TruncOp, Node->getValueType(0), Result); |
| 2989 | else |
| 2990 | Result = DAG.getNode(TruncOp, Node->getValueType(0), Result, |
| 2991 | DAG.getIntPtrConstant(0)); |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2992 | break; |
| 2993 | } |
| 2994 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2995 | break; |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 2996 | case ISD::SELECT_CC: { |
| 2997 | Tmp1 = Node->getOperand(0); // LHS |
| 2998 | Tmp2 = Node->getOperand(1); // RHS |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 2999 | Tmp3 = LegalizeOp(Node->getOperand(2)); // True |
| 3000 | Tmp4 = LegalizeOp(Node->getOperand(3)); // False |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3001 | SDValue CC = Node->getOperand(4); |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 3002 | |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 3003 | LegalizeSetCC(TLI.getSetCCResultType(Tmp1.getValueType()), Tmp1, Tmp2, CC); |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 3004 | |
Evan Cheng | 7f04268 | 2008-10-15 02:05:31 +0000 | [diff] [blame] | 3005 | // 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] | 3006 | // the LHS is a legal SETCC itself. In this case, we need to compare |
| 3007 | // the result against zero to select between true and false values. |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3008 | if (Tmp2.getNode() == 0) { |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 3009 | Tmp2 = DAG.getConstant(0, Tmp1.getValueType()); |
| 3010 | CC = DAG.getCondCode(ISD::SETNE); |
| 3011 | } |
| 3012 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3, Tmp4, CC); |
| 3013 | |
| 3014 | // Everything is legal, see if we should expand this op or something. |
| 3015 | switch (TLI.getOperationAction(ISD::SELECT_CC, Tmp3.getValueType())) { |
| 3016 | default: assert(0 && "This action is not supported yet!"); |
| 3017 | case TargetLowering::Legal: break; |
| 3018 | case TargetLowering::Custom: |
| 3019 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3020 | if (Tmp1.getNode()) Result = Tmp1; |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 3021 | break; |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 3022 | } |
| 3023 | break; |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 3024 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3025 | case ISD::SETCC: |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 3026 | Tmp1 = Node->getOperand(0); |
| 3027 | Tmp2 = Node->getOperand(1); |
| 3028 | Tmp3 = Node->getOperand(2); |
Evan Cheng | 7f04268 | 2008-10-15 02:05:31 +0000 | [diff] [blame] | 3029 | LegalizeSetCC(Node->getValueType(0), Tmp1, Tmp2, Tmp3); |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 3030 | |
| 3031 | // If we had to Expand the SetCC operands into a SELECT node, then it may |
| 3032 | // not always be possible to return a true LHS & RHS. In this case, just |
| 3033 | // return the value we legalized, returned in the LHS |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3034 | if (Tmp2.getNode() == 0) { |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 3035 | Result = Tmp1; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3036 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3037 | } |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 3038 | |
Chris Lattner | 73e142f | 2006-01-30 22:43:50 +0000 | [diff] [blame] | 3039 | switch (TLI.getOperationAction(ISD::SETCC, Tmp1.getValueType())) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3040 | default: assert(0 && "Cannot handle this action for SETCC yet!"); |
| 3041 | case TargetLowering::Custom: |
| 3042 | isCustom = true; |
| 3043 | // FALLTHROUGH. |
| 3044 | case TargetLowering::Legal: |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 3045 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3046 | if (isCustom) { |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 3047 | Tmp4 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3048 | if (Tmp4.getNode()) Result = Tmp4; |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3049 | } |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 3050 | break; |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 3051 | case TargetLowering::Promote: { |
| 3052 | // First step, figure out the appropriate operation to use. |
| 3053 | // Allow SETCC to not be supported for all legal data types |
| 3054 | // Mostly this targets FP |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3055 | MVT NewInTy = Node->getOperand(0).getValueType(); |
| 3056 | MVT OldVT = NewInTy; OldVT = OldVT; |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 3057 | |
| 3058 | // Scan for the appropriate larger type to use. |
| 3059 | while (1) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3060 | NewInTy = (MVT::SimpleValueType)(NewInTy.getSimpleVT()+1); |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 3061 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3062 | assert(NewInTy.isInteger() == OldVT.isInteger() && |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 3063 | "Fell off of the edge of the integer world"); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3064 | assert(NewInTy.isFloatingPoint() == OldVT.isFloatingPoint() && |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 3065 | "Fell off of the edge of the floating point world"); |
| 3066 | |
| 3067 | // If the target supports SETCC of this type, use it. |
Chris Lattner | 1ccf26a | 2005-12-22 05:23:45 +0000 | [diff] [blame] | 3068 | if (TLI.isOperationLegal(ISD::SETCC, NewInTy)) |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 3069 | break; |
| 3070 | } |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3071 | if (NewInTy.isInteger()) |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 3072 | assert(0 && "Cannot promote Legal Integer SETCC yet"); |
| 3073 | else { |
| 3074 | Tmp1 = DAG.getNode(ISD::FP_EXTEND, NewInTy, Tmp1); |
| 3075 | Tmp2 = DAG.getNode(ISD::FP_EXTEND, NewInTy, Tmp2); |
| 3076 | } |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3077 | Tmp1 = LegalizeOp(Tmp1); |
| 3078 | Tmp2 = LegalizeOp(Tmp2); |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 3079 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Evan Cheng | 433f8ac | 2006-01-17 19:47:13 +0000 | [diff] [blame] | 3080 | Result = LegalizeOp(Result); |
Andrew Lenharth | 5e3efbc | 2005-08-29 20:46:51 +0000 | [diff] [blame] | 3081 | break; |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 3082 | } |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 3083 | case TargetLowering::Expand: |
| 3084 | // Expand a setcc node into a select_cc of the same condition, lhs, and |
| 3085 | // rhs that selects between const 1 (true) and const 0 (false). |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3086 | MVT VT = Node->getValueType(0); |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 3087 | Result = DAG.getNode(ISD::SELECT_CC, VT, Tmp1, Tmp2, |
| 3088 | DAG.getConstant(1, VT), DAG.getConstant(0, VT), |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 3089 | Tmp3); |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 3090 | break; |
| 3091 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3092 | break; |
Nate Begeman | b43e9c1 | 2008-05-12 19:40:03 +0000 | [diff] [blame] | 3093 | case ISD::VSETCC: { |
| 3094 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
| 3095 | Tmp2 = LegalizeOp(Node->getOperand(1)); // RHS |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3096 | SDValue CC = Node->getOperand(2); |
Nate Begeman | b43e9c1 | 2008-05-12 19:40:03 +0000 | [diff] [blame] | 3097 | |
| 3098 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, CC); |
| 3099 | |
| 3100 | // Everything is legal, see if we should expand this op or something. |
| 3101 | switch (TLI.getOperationAction(ISD::VSETCC, Tmp1.getValueType())) { |
| 3102 | default: assert(0 && "This action is not supported yet!"); |
| 3103 | case TargetLowering::Legal: break; |
| 3104 | case TargetLowering::Custom: |
| 3105 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3106 | if (Tmp1.getNode()) Result = Tmp1; |
Nate Begeman | b43e9c1 | 2008-05-12 19:40:03 +0000 | [diff] [blame] | 3107 | break; |
Mon P Wang | e1a0b2e | 2008-12-13 08:15:14 +0000 | [diff] [blame] | 3108 | case TargetLowering::Expand: { |
| 3109 | // Unroll into a nasty set of scalar code for now. |
| 3110 | MVT VT = Node->getValueType(0); |
| 3111 | unsigned NumElems = VT.getVectorNumElements(); |
| 3112 | MVT EltVT = VT.getVectorElementType(); |
| 3113 | MVT TmpEltVT = Tmp1.getValueType().getVectorElementType(); |
| 3114 | SmallVector<SDValue, 8> Ops(NumElems); |
| 3115 | for (unsigned i = 0; i < NumElems; ++i) { |
| 3116 | SDValue In1 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, TmpEltVT, |
| 3117 | Tmp1, DAG.getIntPtrConstant(i)); |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 3118 | Ops[i] = DAG.getNode(ISD::SETCC, TLI.getSetCCResultType(TmpEltVT), In1, |
Mon P Wang | 84aff84 | 2008-12-17 08:49:47 +0000 | [diff] [blame] | 3119 | DAG.getNode(ISD::EXTRACT_VECTOR_ELT, TmpEltVT, |
| 3120 | Tmp2, DAG.getIntPtrConstant(i)), |
| 3121 | CC); |
| 3122 | Ops[i] = DAG.getNode(ISD::SELECT, EltVT, Ops[i], |
| 3123 | DAG.getConstant(EltVT.getIntegerVTBitMask(),EltVT), |
| 3124 | DAG.getConstant(0, EltVT)); |
Mon P Wang | e1a0b2e | 2008-12-13 08:15:14 +0000 | [diff] [blame] | 3125 | } |
| 3126 | Result = DAG.getNode(ISD::BUILD_VECTOR, VT, &Ops[0], NumElems); |
| 3127 | break; |
| 3128 | } |
Nate Begeman | b43e9c1 | 2008-05-12 19:40:03 +0000 | [diff] [blame] | 3129 | } |
| 3130 | break; |
| 3131 | } |
Chris Lattner | 52d08bd | 2005-05-09 20:23:03 +0000 | [diff] [blame] | 3132 | |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 3133 | case ISD::SHL_PARTS: |
| 3134 | case ISD::SRA_PARTS: |
| 3135 | case ISD::SRL_PARTS: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3136 | SmallVector<SDValue, 8> Ops; |
Chris Lattner | 84f6788 | 2005-01-20 18:52:28 +0000 | [diff] [blame] | 3137 | bool Changed = false; |
| 3138 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) { |
| 3139 | Ops.push_back(LegalizeOp(Node->getOperand(i))); |
| 3140 | Changed |= Ops.back() != Node->getOperand(i); |
| 3141 | } |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3142 | if (Changed) |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 3143 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3144 | |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 3145 | switch (TLI.getOperationAction(Node->getOpcode(), |
| 3146 | Node->getValueType(0))) { |
| 3147 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3148 | case TargetLowering::Legal: break; |
| 3149 | case TargetLowering::Custom: |
| 3150 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3151 | if (Tmp1.getNode()) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3152 | SDValue Tmp2, RetVal(0, 0); |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 3153 | for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3154 | Tmp2 = LegalizeOp(Tmp1.getValue(i)); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3155 | AddLegalizedOperand(SDValue(Node, i), Tmp2); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 3156 | if (i == Op.getResNo()) |
Evan Cheng | 12f2274 | 2006-01-19 04:54:52 +0000 | [diff] [blame] | 3157 | RetVal = Tmp2; |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 3158 | } |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3159 | assert(RetVal.getNode() && "Illegal result number"); |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 3160 | return RetVal; |
| 3161 | } |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 3162 | break; |
| 3163 | } |
| 3164 | |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3165 | // Since these produce multiple values, make sure to remember that we |
| 3166 | // legalized all of them. |
| 3167 | for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3168 | AddLegalizedOperand(SDValue(Node, i), Result.getValue(i)); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 3169 | return Result.getValue(Op.getResNo()); |
Chris Lattner | 84f6788 | 2005-01-20 18:52:28 +0000 | [diff] [blame] | 3170 | } |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3171 | |
| 3172 | // Binary operators |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3173 | case ISD::ADD: |
| 3174 | case ISD::SUB: |
| 3175 | case ISD::MUL: |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 3176 | case ISD::MULHS: |
| 3177 | case ISD::MULHU: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3178 | case ISD::UDIV: |
| 3179 | case ISD::SDIV: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3180 | case ISD::AND: |
| 3181 | case ISD::OR: |
| 3182 | case ISD::XOR: |
Chris Lattner | 03c0cf8 | 2005-01-07 21:45:56 +0000 | [diff] [blame] | 3183 | case ISD::SHL: |
| 3184 | case ISD::SRL: |
| 3185 | case ISD::SRA: |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 3186 | case ISD::FADD: |
| 3187 | case ISD::FSUB: |
| 3188 | case ISD::FMUL: |
| 3189 | case ISD::FDIV: |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3190 | case ISD::FPOW: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3191 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
Andrew Lenharth | f2eb139 | 2005-07-05 19:52:39 +0000 | [diff] [blame] | 3192 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 3193 | case Expand: assert(0 && "Not possible"); |
| 3194 | case Legal: |
| 3195 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the RHS. |
| 3196 | break; |
| 3197 | case Promote: |
| 3198 | Tmp2 = PromoteOp(Node->getOperand(1)); // Promote the RHS. |
| 3199 | break; |
| 3200 | } |
Nate Begeman | 5bc1ea0 | 2008-07-29 15:49:41 +0000 | [diff] [blame] | 3201 | |
| 3202 | if ((Node->getOpcode() == ISD::SHL || |
| 3203 | Node->getOpcode() == ISD::SRL || |
| 3204 | Node->getOpcode() == ISD::SRA) && |
| 3205 | !Node->getValueType(0).isVector()) { |
Mon P Wang | e9f1015 | 2008-12-09 05:46:39 +0000 | [diff] [blame] | 3206 | Tmp2 = LegalizeShiftAmount(Tmp2); |
Mon P Wang | e1a0b2e | 2008-12-13 08:15:14 +0000 | [diff] [blame] | 3207 | } |
Nate Begeman | 5bc1ea0 | 2008-07-29 15:49:41 +0000 | [diff] [blame] | 3208 | |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3209 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Mon P Wang | aeb06d2 | 2008-11-10 04:46:22 +0000 | [diff] [blame] | 3210 | |
Andrew Lenharth | e8f65f1 | 2005-12-24 23:42:32 +0000 | [diff] [blame] | 3211 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
Chris Lattner | bc70cf8 | 2006-04-02 03:57:31 +0000 | [diff] [blame] | 3212 | default: assert(0 && "BinOp legalize operation not supported"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3213 | case TargetLowering::Legal: break; |
| 3214 | case TargetLowering::Custom: |
| 3215 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3216 | if (Tmp1.getNode()) { |
Nate Begeman | 5bc1ea0 | 2008-07-29 15:49:41 +0000 | [diff] [blame] | 3217 | Result = Tmp1; |
| 3218 | break; |
Nate Begeman | 24dc346 | 2008-07-29 19:07:27 +0000 | [diff] [blame] | 3219 | } |
Nate Begeman | 5bc1ea0 | 2008-07-29 15:49:41 +0000 | [diff] [blame] | 3220 | // Fall through if the custom lower can't deal with the operation |
Chris Lattner | bc70cf8 | 2006-04-02 03:57:31 +0000 | [diff] [blame] | 3221 | case TargetLowering::Expand: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3222 | MVT VT = Op.getValueType(); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 3223 | |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3224 | // See if multiply or divide can be lowered using two-result operations. |
| 3225 | SDVTList VTs = DAG.getVTList(VT, VT); |
| 3226 | if (Node->getOpcode() == ISD::MUL) { |
| 3227 | // We just need the low half of the multiply; try both the signed |
| 3228 | // and unsigned forms. If the target supports both SMUL_LOHI and |
| 3229 | // UMUL_LOHI, form a preference by checking which forms of plain |
| 3230 | // MULH it supports. |
| 3231 | bool HasSMUL_LOHI = TLI.isOperationLegal(ISD::SMUL_LOHI, VT); |
| 3232 | bool HasUMUL_LOHI = TLI.isOperationLegal(ISD::UMUL_LOHI, VT); |
| 3233 | bool HasMULHS = TLI.isOperationLegal(ISD::MULHS, VT); |
| 3234 | bool HasMULHU = TLI.isOperationLegal(ISD::MULHU, VT); |
| 3235 | unsigned OpToUse = 0; |
| 3236 | if (HasSMUL_LOHI && !HasMULHS) { |
| 3237 | OpToUse = ISD::SMUL_LOHI; |
| 3238 | } else if (HasUMUL_LOHI && !HasMULHU) { |
| 3239 | OpToUse = ISD::UMUL_LOHI; |
| 3240 | } else if (HasSMUL_LOHI) { |
| 3241 | OpToUse = ISD::SMUL_LOHI; |
| 3242 | } else if (HasUMUL_LOHI) { |
| 3243 | OpToUse = ISD::UMUL_LOHI; |
| 3244 | } |
| 3245 | if (OpToUse) { |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3246 | Result = SDValue(DAG.getNode(OpToUse, VTs, Tmp1, Tmp2).getNode(), 0); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3247 | break; |
| 3248 | } |
| 3249 | } |
| 3250 | if (Node->getOpcode() == ISD::MULHS && |
| 3251 | TLI.isOperationLegal(ISD::SMUL_LOHI, VT)) { |
Chris Lattner | 31d7161 | 2008-10-04 21:27:46 +0000 | [diff] [blame] | 3252 | Result = SDValue(DAG.getNode(ISD::SMUL_LOHI, VTs, Tmp1, Tmp2).getNode(), |
| 3253 | 1); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3254 | break; |
| 3255 | } |
| 3256 | if (Node->getOpcode() == ISD::MULHU && |
| 3257 | TLI.isOperationLegal(ISD::UMUL_LOHI, VT)) { |
Chris Lattner | 31d7161 | 2008-10-04 21:27:46 +0000 | [diff] [blame] | 3258 | Result = SDValue(DAG.getNode(ISD::UMUL_LOHI, VTs, Tmp1, Tmp2).getNode(), |
| 3259 | 1); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3260 | break; |
| 3261 | } |
| 3262 | if (Node->getOpcode() == ISD::SDIV && |
| 3263 | TLI.isOperationLegal(ISD::SDIVREM, VT)) { |
Chris Lattner | 31d7161 | 2008-10-04 21:27:46 +0000 | [diff] [blame] | 3264 | Result = SDValue(DAG.getNode(ISD::SDIVREM, VTs, Tmp1, Tmp2).getNode(), |
| 3265 | 0); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3266 | break; |
| 3267 | } |
| 3268 | if (Node->getOpcode() == ISD::UDIV && |
| 3269 | TLI.isOperationLegal(ISD::UDIVREM, VT)) { |
Chris Lattner | 31d7161 | 2008-10-04 21:27:46 +0000 | [diff] [blame] | 3270 | Result = SDValue(DAG.getNode(ISD::UDIVREM, VTs, Tmp1, Tmp2).getNode(), |
| 3271 | 0); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3272 | break; |
| 3273 | } |
Mon P Wang | 87c8a8f | 2008-12-18 20:03:17 +0000 | [diff] [blame] | 3274 | |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3275 | // Check to see if we have a libcall for this operator. |
| 3276 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
| 3277 | bool isSigned = false; |
| 3278 | switch (Node->getOpcode()) { |
| 3279 | case ISD::UDIV: |
| 3280 | case ISD::SDIV: |
| 3281 | if (VT == MVT::i32) { |
| 3282 | LC = Node->getOpcode() == ISD::UDIV |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 3283 | ? RTLIB::UDIV_I32 : RTLIB::SDIV_I32; |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3284 | isSigned = Node->getOpcode() == ISD::SDIV; |
| 3285 | } |
| 3286 | break; |
Chris Lattner | 31d7161 | 2008-10-04 21:27:46 +0000 | [diff] [blame] | 3287 | case ISD::MUL: |
| 3288 | if (VT == MVT::i32) |
| 3289 | LC = RTLIB::MUL_I32; |
Nate Begeman | 9b99485 | 2009-01-24 22:12:48 +0000 | [diff] [blame] | 3290 | else if (VT == MVT::i64) |
Scott Michel | 845145f | 2008-12-29 03:21:37 +0000 | [diff] [blame] | 3291 | LC = RTLIB::MUL_I64; |
Chris Lattner | 31d7161 | 2008-10-04 21:27:46 +0000 | [diff] [blame] | 3292 | break; |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3293 | case ISD::FPOW: |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 3294 | LC = GetFPLibCall(VT, RTLIB::POW_F32, RTLIB::POW_F64, RTLIB::POW_F80, |
| 3295 | RTLIB::POW_PPCF128); |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3296 | break; |
Scott Michel | d1e8d9c | 2009-01-21 04:58:48 +0000 | [diff] [blame] | 3297 | case ISD::FDIV: |
| 3298 | LC = GetFPLibCall(VT, RTLIB::DIV_F32, RTLIB::DIV_F64, RTLIB::DIV_F80, |
| 3299 | RTLIB::DIV_PPCF128); |
| 3300 | break; |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3301 | default: break; |
| 3302 | } |
| 3303 | if (LC != RTLIB::UNKNOWN_LIBCALL) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3304 | SDValue Dummy; |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 3305 | Result = ExpandLibCall(LC, Node, isSigned, Dummy); |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 3306 | break; |
| 3307 | } |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 3308 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3309 | assert(Node->getValueType(0).isVector() && |
Chris Lattner | bc70cf8 | 2006-04-02 03:57:31 +0000 | [diff] [blame] | 3310 | "Cannot expand this binary operator!"); |
| 3311 | // Expand the operation into a bunch of nasty scalar code. |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3312 | Result = LegalizeOp(UnrollVectorOp(Op)); |
Chris Lattner | bc70cf8 | 2006-04-02 03:57:31 +0000 | [diff] [blame] | 3313 | break; |
| 3314 | } |
Evan Cheng | cc98761 | 2006-04-12 21:20:24 +0000 | [diff] [blame] | 3315 | case TargetLowering::Promote: { |
| 3316 | switch (Node->getOpcode()) { |
| 3317 | default: assert(0 && "Do not know how to promote this BinOp!"); |
| 3318 | case ISD::AND: |
| 3319 | case ISD::OR: |
| 3320 | case ISD::XOR: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3321 | MVT OVT = Node->getValueType(0); |
| 3322 | MVT NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT); |
| 3323 | assert(OVT.isVector() && "Cannot promote this BinOp!"); |
Evan Cheng | cc98761 | 2006-04-12 21:20:24 +0000 | [diff] [blame] | 3324 | // Bit convert each of the values to the new type. |
| 3325 | Tmp1 = DAG.getNode(ISD::BIT_CONVERT, NVT, Tmp1); |
| 3326 | Tmp2 = DAG.getNode(ISD::BIT_CONVERT, NVT, Tmp2); |
| 3327 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 3328 | // Bit convert the result back the original type. |
| 3329 | Result = DAG.getNode(ISD::BIT_CONVERT, OVT, Result); |
| 3330 | break; |
| 3331 | } |
| 3332 | } |
| 3333 | } |
Andrew Lenharth | e8f65f1 | 2005-12-24 23:42:32 +0000 | [diff] [blame] | 3334 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3335 | break; |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 3336 | |
Dan Gohman | e14ea86 | 2007-10-05 14:17:22 +0000 | [diff] [blame] | 3337 | case ISD::SMUL_LOHI: |
| 3338 | case ISD::UMUL_LOHI: |
| 3339 | case ISD::SDIVREM: |
| 3340 | case ISD::UDIVREM: |
| 3341 | // These nodes will only be produced by target-specific lowering, so |
| 3342 | // they shouldn't be here if they aren't legal. |
Duncan Sands | a7c97a7 | 2007-10-16 09:07:20 +0000 | [diff] [blame] | 3343 | assert(TLI.isOperationLegal(Node->getOpcode(), Node->getValueType(0)) && |
Dan Gohman | e14ea86 | 2007-10-05 14:17:22 +0000 | [diff] [blame] | 3344 | "This must be legal!"); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3345 | |
| 3346 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
| 3347 | Tmp2 = LegalizeOp(Node->getOperand(1)); // RHS |
| 3348 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Dan Gohman | e14ea86 | 2007-10-05 14:17:22 +0000 | [diff] [blame] | 3349 | break; |
| 3350 | |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 3351 | case ISD::FCOPYSIGN: // FCOPYSIGN does not require LHS/RHS to match type! |
| 3352 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
| 3353 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 3354 | case Expand: assert(0 && "Not possible"); |
| 3355 | case Legal: |
| 3356 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the RHS. |
| 3357 | break; |
| 3358 | case Promote: |
| 3359 | Tmp2 = PromoteOp(Node->getOperand(1)); // Promote the RHS. |
| 3360 | break; |
| 3361 | } |
| 3362 | |
| 3363 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 3364 | |
| 3365 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 3366 | default: assert(0 && "Operation not supported"); |
| 3367 | case TargetLowering::Custom: |
| 3368 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3369 | if (Tmp1.getNode()) Result = Tmp1; |
Chris Lattner | 8f4191d | 2006-03-13 06:08:38 +0000 | [diff] [blame] | 3370 | break; |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 3371 | case TargetLowering::Legal: break; |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 3372 | case TargetLowering::Expand: { |
Evan Cheng | 636c753 | 2007-01-05 23:33:44 +0000 | [diff] [blame] | 3373 | // If this target supports fabs/fneg natively and select is cheap, |
| 3374 | // do this efficiently. |
| 3375 | if (!TLI.isSelectExpensive() && |
| 3376 | TLI.getOperationAction(ISD::FABS, Tmp1.getValueType()) == |
| 3377 | TargetLowering::Legal && |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 3378 | TLI.getOperationAction(ISD::FNEG, Tmp1.getValueType()) == |
Evan Cheng | 636c753 | 2007-01-05 23:33:44 +0000 | [diff] [blame] | 3379 | TargetLowering::Legal) { |
Chris Lattner | 8f4191d | 2006-03-13 06:08:38 +0000 | [diff] [blame] | 3380 | // Get the sign bit of the RHS. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3381 | MVT IVT = |
Chris Lattner | 8f4191d | 2006-03-13 06:08:38 +0000 | [diff] [blame] | 3382 | Tmp2.getValueType() == MVT::f32 ? MVT::i32 : MVT::i64; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3383 | SDValue SignBit = DAG.getNode(ISD::BIT_CONVERT, IVT, Tmp2); |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 3384 | SignBit = DAG.getSetCC(TLI.getSetCCResultType(IVT), |
Chris Lattner | 8f4191d | 2006-03-13 06:08:38 +0000 | [diff] [blame] | 3385 | SignBit, DAG.getConstant(0, IVT), ISD::SETLT); |
| 3386 | // Get the absolute value of the result. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3387 | SDValue AbsVal = DAG.getNode(ISD::FABS, Tmp1.getValueType(), Tmp1); |
Chris Lattner | 8f4191d | 2006-03-13 06:08:38 +0000 | [diff] [blame] | 3388 | // Select between the nabs and abs value based on the sign bit of |
| 3389 | // the input. |
| 3390 | Result = DAG.getNode(ISD::SELECT, AbsVal.getValueType(), SignBit, |
| 3391 | DAG.getNode(ISD::FNEG, AbsVal.getValueType(), |
| 3392 | AbsVal), |
| 3393 | AbsVal); |
| 3394 | Result = LegalizeOp(Result); |
| 3395 | break; |
| 3396 | } |
| 3397 | |
| 3398 | // Otherwise, do bitwise ops! |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3399 | MVT NVT = |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 3400 | Node->getValueType(0) == MVT::f32 ? MVT::i32 : MVT::i64; |
| 3401 | Result = ExpandFCOPYSIGNToBitwiseOps(Node, NVT, DAG, TLI); |
| 3402 | Result = DAG.getNode(ISD::BIT_CONVERT, Node->getValueType(0), Result); |
| 3403 | Result = LegalizeOp(Result); |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 3404 | break; |
| 3405 | } |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 3406 | } |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 3407 | break; |
| 3408 | |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 3409 | case ISD::ADDC: |
| 3410 | case ISD::SUBC: |
| 3411 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 3412 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 3413 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Sanjiv Gupta | d3f01aa | 2008-11-26 11:19:00 +0000 | [diff] [blame] | 3414 | Tmp3 = Result.getValue(0); |
| 3415 | Tmp4 = Result.getValue(1); |
| 3416 | |
| 3417 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 3418 | default: assert(0 && "This action is not supported yet!"); |
| 3419 | case TargetLowering::Legal: |
| 3420 | break; |
| 3421 | case TargetLowering::Custom: |
| 3422 | Tmp1 = TLI.LowerOperation(Tmp3, DAG); |
| 3423 | if (Tmp1.getNode() != NULL) { |
Sanjiv Gupta | 9b0f0b5 | 2008-11-27 05:58:04 +0000 | [diff] [blame] | 3424 | Tmp3 = LegalizeOp(Tmp1); |
Sanjiv Gupta | d3f01aa | 2008-11-26 11:19:00 +0000 | [diff] [blame] | 3425 | Tmp4 = LegalizeOp(Tmp1.getValue(1)); |
| 3426 | } |
| 3427 | break; |
| 3428 | } |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 3429 | // Since this produces two values, make sure to remember that we legalized |
| 3430 | // both of them. |
Sanjiv Gupta | d3f01aa | 2008-11-26 11:19:00 +0000 | [diff] [blame] | 3431 | AddLegalizedOperand(SDValue(Node, 0), Tmp3); |
| 3432 | AddLegalizedOperand(SDValue(Node, 1), Tmp4); |
| 3433 | return Op.getResNo() ? Tmp4 : Tmp3; |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 3434 | |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 3435 | case ISD::ADDE: |
| 3436 | case ISD::SUBE: |
| 3437 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 3438 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 3439 | Tmp3 = LegalizeOp(Node->getOperand(2)); |
| 3440 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Sanjiv Gupta | d3f01aa | 2008-11-26 11:19:00 +0000 | [diff] [blame] | 3441 | Tmp3 = Result.getValue(0); |
| 3442 | Tmp4 = Result.getValue(1); |
| 3443 | |
| 3444 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 3445 | default: assert(0 && "This action is not supported yet!"); |
| 3446 | case TargetLowering::Legal: |
| 3447 | break; |
| 3448 | case TargetLowering::Custom: |
| 3449 | Tmp1 = TLI.LowerOperation(Tmp3, DAG); |
| 3450 | if (Tmp1.getNode() != NULL) { |
Sanjiv Gupta | 9b0f0b5 | 2008-11-27 05:58:04 +0000 | [diff] [blame] | 3451 | Tmp3 = LegalizeOp(Tmp1); |
Sanjiv Gupta | d3f01aa | 2008-11-26 11:19:00 +0000 | [diff] [blame] | 3452 | Tmp4 = LegalizeOp(Tmp1.getValue(1)); |
| 3453 | } |
| 3454 | break; |
| 3455 | } |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 3456 | // Since this produces two values, make sure to remember that we legalized |
| 3457 | // both of them. |
Sanjiv Gupta | d3f01aa | 2008-11-26 11:19:00 +0000 | [diff] [blame] | 3458 | AddLegalizedOperand(SDValue(Node, 0), Tmp3); |
| 3459 | AddLegalizedOperand(SDValue(Node, 1), Tmp4); |
| 3460 | return Op.getResNo() ? Tmp4 : Tmp3; |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 3461 | |
Nate Begeman | 419f8b6 | 2005-10-18 00:27:41 +0000 | [diff] [blame] | 3462 | case ISD::BUILD_PAIR: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3463 | MVT PairTy = Node->getValueType(0); |
Nate Begeman | 419f8b6 | 2005-10-18 00:27:41 +0000 | [diff] [blame] | 3464 | // TODO: handle the case where the Lo and Hi operands are not of legal type |
| 3465 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Lo |
| 3466 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Hi |
| 3467 | switch (TLI.getOperationAction(ISD::BUILD_PAIR, PairTy)) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3468 | case TargetLowering::Promote: |
| 3469 | case TargetLowering::Custom: |
| 3470 | assert(0 && "Cannot promote/custom this yet!"); |
Nate Begeman | 419f8b6 | 2005-10-18 00:27:41 +0000 | [diff] [blame] | 3471 | case TargetLowering::Legal: |
| 3472 | if (Tmp1 != Node->getOperand(0) || Tmp2 != Node->getOperand(1)) |
| 3473 | Result = DAG.getNode(ISD::BUILD_PAIR, PairTy, Tmp1, Tmp2); |
| 3474 | break; |
Nate Begeman | 419f8b6 | 2005-10-18 00:27:41 +0000 | [diff] [blame] | 3475 | case TargetLowering::Expand: |
| 3476 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, PairTy, Tmp1); |
| 3477 | Tmp2 = DAG.getNode(ISD::ANY_EXTEND, PairTy, Tmp2); |
| 3478 | Tmp2 = DAG.getNode(ISD::SHL, PairTy, Tmp2, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3479 | DAG.getConstant(PairTy.getSizeInBits()/2, |
Nate Begeman | 419f8b6 | 2005-10-18 00:27:41 +0000 | [diff] [blame] | 3480 | TLI.getShiftAmountTy())); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3481 | Result = DAG.getNode(ISD::OR, PairTy, Tmp1, Tmp2); |
Nate Begeman | 419f8b6 | 2005-10-18 00:27:41 +0000 | [diff] [blame] | 3482 | break; |
| 3483 | } |
| 3484 | break; |
| 3485 | } |
| 3486 | |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 3487 | case ISD::UREM: |
| 3488 | case ISD::SREM: |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 3489 | case ISD::FREM: |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 3490 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
| 3491 | Tmp2 = LegalizeOp(Node->getOperand(1)); // RHS |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3492 | |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 3493 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3494 | case TargetLowering::Promote: assert(0 && "Cannot promote this yet!"); |
| 3495 | case TargetLowering::Custom: |
| 3496 | isCustom = true; |
| 3497 | // FALLTHROUGH |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 3498 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3499 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3500 | if (isCustom) { |
| 3501 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3502 | if (Tmp1.getNode()) Result = Tmp1; |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3503 | } |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 3504 | break; |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3505 | case TargetLowering::Expand: { |
Evan Cheng | 6b5578f | 2006-09-18 23:28:33 +0000 | [diff] [blame] | 3506 | unsigned DivOpc= (Node->getOpcode() == ISD::UREM) ? ISD::UDIV : ISD::SDIV; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 3507 | bool isSigned = DivOpc == ISD::SDIV; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3508 | MVT VT = Node->getValueType(0); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3509 | |
| 3510 | // See if remainder can be lowered using two-result operations. |
| 3511 | SDVTList VTs = DAG.getVTList(VT, VT); |
| 3512 | if (Node->getOpcode() == ISD::SREM && |
| 3513 | TLI.isOperationLegal(ISD::SDIVREM, VT)) { |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3514 | Result = SDValue(DAG.getNode(ISD::SDIVREM, VTs, Tmp1, Tmp2).getNode(), 1); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3515 | break; |
| 3516 | } |
| 3517 | if (Node->getOpcode() == ISD::UREM && |
| 3518 | TLI.isOperationLegal(ISD::UDIVREM, VT)) { |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3519 | Result = SDValue(DAG.getNode(ISD::UDIVREM, VTs, Tmp1, Tmp2).getNode(), 1); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3520 | break; |
| 3521 | } |
| 3522 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3523 | if (VT.isInteger()) { |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3524 | if (TLI.getOperationAction(DivOpc, VT) == |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 3525 | TargetLowering::Legal) { |
| 3526 | // X % Y -> X-X/Y*Y |
Evan Cheng | 6b5578f | 2006-09-18 23:28:33 +0000 | [diff] [blame] | 3527 | Result = DAG.getNode(DivOpc, VT, Tmp1, Tmp2); |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 3528 | Result = DAG.getNode(ISD::MUL, VT, Result, Tmp2); |
| 3529 | Result = DAG.getNode(ISD::SUB, VT, Tmp1, Result); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3530 | } else if (VT.isVector()) { |
Dan Gohman | 8017631 | 2007-11-05 23:35:22 +0000 | [diff] [blame] | 3531 | Result = LegalizeOp(UnrollVectorOp(Op)); |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 3532 | } else { |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3533 | assert(VT == MVT::i32 && |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 3534 | "Cannot expand this binary operator!"); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3535 | RTLIB::Libcall LC = Node->getOpcode() == ISD::UREM |
| 3536 | ? RTLIB::UREM_I32 : RTLIB::SREM_I32; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3537 | SDValue Dummy; |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 3538 | Result = ExpandLibCall(LC, Node, isSigned, Dummy); |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 3539 | } |
Dan Gohman | 0d97426 | 2007-11-06 22:11:54 +0000 | [diff] [blame] | 3540 | } else { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3541 | assert(VT.isFloatingPoint() && |
Dan Gohman | 0d97426 | 2007-11-06 22:11:54 +0000 | [diff] [blame] | 3542 | "remainder op must have integer or floating-point type"); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3543 | if (VT.isVector()) { |
Dan Gohman | 8017631 | 2007-11-05 23:35:22 +0000 | [diff] [blame] | 3544 | Result = LegalizeOp(UnrollVectorOp(Op)); |
| 3545 | } else { |
| 3546 | // Floating point mod -> fmod libcall. |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 3547 | RTLIB::Libcall LC = GetFPLibCall(VT, RTLIB::REM_F32, RTLIB::REM_F64, |
| 3548 | RTLIB::REM_F80, RTLIB::REM_PPCF128); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3549 | SDValue Dummy; |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 3550 | Result = ExpandLibCall(LC, Node, false/*sign irrelevant*/, Dummy); |
Dan Gohman | 8017631 | 2007-11-05 23:35:22 +0000 | [diff] [blame] | 3551 | } |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 3552 | } |
| 3553 | break; |
| 3554 | } |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3555 | } |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 3556 | break; |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3557 | case ISD::VAARG: { |
| 3558 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 3559 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. |
| 3560 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3561 | MVT VT = Node->getValueType(0); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3562 | switch (TLI.getOperationAction(Node->getOpcode(), MVT::Other)) { |
| 3563 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3564 | case TargetLowering::Custom: |
| 3565 | isCustom = true; |
| 3566 | // FALLTHROUGH |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3567 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3568 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
| 3569 | Result = Result.getValue(0); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3570 | Tmp1 = Result.getValue(1); |
| 3571 | |
| 3572 | if (isCustom) { |
| 3573 | Tmp2 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3574 | if (Tmp2.getNode()) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3575 | Result = LegalizeOp(Tmp2); |
| 3576 | Tmp1 = LegalizeOp(Tmp2.getValue(1)); |
| 3577 | } |
| 3578 | } |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3579 | break; |
| 3580 | case TargetLowering::Expand: { |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 3581 | const Value *V = cast<SrcValueSDNode>(Node->getOperand(2))->getValue(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3582 | SDValue VAList = DAG.getLoad(TLI.getPointerTy(), Tmp1, Tmp2, V, 0); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3583 | // Increment the pointer, VAList, to the next vaarg |
Duncan Sands | 5c58a31 | 2008-11-03 11:51:11 +0000 | [diff] [blame] | 3584 | Tmp3 = DAG.getNode(ISD::ADD, TLI.getPointerTy(), VAList, |
Duncan Sands | ceb4d1a | 2009-01-12 20:38:59 +0000 | [diff] [blame] | 3585 | DAG.getConstant(TLI.getTargetData()-> |
| 3586 | getTypePaddedSize(VT.getTypeForMVT()), |
| 3587 | TLI.getPointerTy())); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3588 | // Store the incremented VAList to the legalized pointer |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 3589 | Tmp3 = DAG.getStore(VAList.getValue(1), Tmp3, Tmp2, V, 0); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3590 | // Load the actual argument out of the pointer VAList |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 3591 | Result = DAG.getLoad(VT, Tmp3, VAList, NULL, 0); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3592 | Tmp1 = LegalizeOp(Result.getValue(1)); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3593 | Result = LegalizeOp(Result); |
| 3594 | break; |
| 3595 | } |
| 3596 | } |
| 3597 | // Since VAARG produces two values, make sure to remember that we |
| 3598 | // legalized both of them. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3599 | AddLegalizedOperand(SDValue(Node, 0), Result); |
| 3600 | AddLegalizedOperand(SDValue(Node, 1), Tmp1); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 3601 | return Op.getResNo() ? Tmp1 : Result; |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3602 | } |
| 3603 | |
| 3604 | case ISD::VACOPY: |
| 3605 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 3606 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the dest pointer. |
| 3607 | Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the source pointer. |
| 3608 | |
| 3609 | switch (TLI.getOperationAction(ISD::VACOPY, MVT::Other)) { |
| 3610 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3611 | case TargetLowering::Custom: |
| 3612 | isCustom = true; |
| 3613 | // FALLTHROUGH |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3614 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3615 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3, |
| 3616 | Node->getOperand(3), Node->getOperand(4)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3617 | if (isCustom) { |
| 3618 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3619 | if (Tmp1.getNode()) Result = Tmp1; |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3620 | } |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3621 | break; |
| 3622 | case TargetLowering::Expand: |
| 3623 | // This defaults to loading a pointer from the input and storing it to the |
| 3624 | // output, returning the chain. |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 3625 | const Value *VD = cast<SrcValueSDNode>(Node->getOperand(3))->getValue(); |
| 3626 | const Value *VS = cast<SrcValueSDNode>(Node->getOperand(4))->getValue(); |
Dan Gohman | 499c1bd | 2008-04-17 02:09:26 +0000 | [diff] [blame] | 3627 | Tmp4 = DAG.getLoad(TLI.getPointerTy(), Tmp1, Tmp3, VS, 0); |
| 3628 | Result = DAG.getStore(Tmp4.getValue(1), Tmp4, Tmp2, VD, 0); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3629 | break; |
| 3630 | } |
| 3631 | break; |
| 3632 | |
| 3633 | case ISD::VAEND: |
| 3634 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 3635 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. |
| 3636 | |
| 3637 | switch (TLI.getOperationAction(ISD::VAEND, MVT::Other)) { |
| 3638 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3639 | case TargetLowering::Custom: |
| 3640 | isCustom = true; |
| 3641 | // FALLTHROUGH |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3642 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3643 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3644 | if (isCustom) { |
| 3645 | Tmp1 = TLI.LowerOperation(Tmp1, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3646 | if (Tmp1.getNode()) Result = Tmp1; |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3647 | } |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3648 | break; |
| 3649 | case TargetLowering::Expand: |
| 3650 | Result = Tmp1; // Default to a no-op, return the chain |
| 3651 | break; |
| 3652 | } |
| 3653 | break; |
| 3654 | |
| 3655 | case ISD::VASTART: |
| 3656 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 3657 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. |
| 3658 | |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3659 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
| 3660 | |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3661 | switch (TLI.getOperationAction(ISD::VASTART, MVT::Other)) { |
| 3662 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3663 | case TargetLowering::Legal: break; |
| 3664 | case TargetLowering::Custom: |
| 3665 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3666 | if (Tmp1.getNode()) Result = Tmp1; |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3667 | break; |
| 3668 | } |
| 3669 | break; |
| 3670 | |
Nate Begeman | 35ef913 | 2006-01-11 21:21:00 +0000 | [diff] [blame] | 3671 | case ISD::ROTL: |
| 3672 | case ISD::ROTR: |
| 3673 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
| 3674 | Tmp2 = LegalizeOp(Node->getOperand(1)); // RHS |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3675 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Scott Michel | c9dc114 | 2007-04-02 21:36:32 +0000 | [diff] [blame] | 3676 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 3677 | default: |
| 3678 | assert(0 && "ROTL/ROTR legalize operation not supported"); |
| 3679 | break; |
| 3680 | case TargetLowering::Legal: |
| 3681 | break; |
| 3682 | case TargetLowering::Custom: |
| 3683 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3684 | if (Tmp1.getNode()) Result = Tmp1; |
Scott Michel | c9dc114 | 2007-04-02 21:36:32 +0000 | [diff] [blame] | 3685 | break; |
| 3686 | case TargetLowering::Promote: |
| 3687 | assert(0 && "Do not know how to promote ROTL/ROTR"); |
| 3688 | break; |
| 3689 | case TargetLowering::Expand: |
| 3690 | assert(0 && "Do not know how to expand ROTL/ROTR"); |
| 3691 | break; |
| 3692 | } |
Nate Begeman | 35ef913 | 2006-01-11 21:21:00 +0000 | [diff] [blame] | 3693 | break; |
| 3694 | |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 3695 | case ISD::BSWAP: |
| 3696 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Op |
| 3697 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3698 | case TargetLowering::Custom: |
| 3699 | assert(0 && "Cannot custom legalize this yet!"); |
| 3700 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3701 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3702 | break; |
| 3703 | case TargetLowering::Promote: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3704 | MVT OVT = Tmp1.getValueType(); |
| 3705 | MVT NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT); |
| 3706 | unsigned DiffBits = NVT.getSizeInBits() - OVT.getSizeInBits(); |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 3707 | |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3708 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Tmp1); |
| 3709 | Tmp1 = DAG.getNode(ISD::BSWAP, NVT, Tmp1); |
| 3710 | Result = DAG.getNode(ISD::SRL, NVT, Tmp1, |
| 3711 | DAG.getConstant(DiffBits, TLI.getShiftAmountTy())); |
| 3712 | break; |
| 3713 | } |
| 3714 | case TargetLowering::Expand: |
| 3715 | Result = ExpandBSWAP(Tmp1); |
| 3716 | break; |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 3717 | } |
| 3718 | break; |
| 3719 | |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3720 | case ISD::CTPOP: |
| 3721 | case ISD::CTTZ: |
| 3722 | case ISD::CTLZ: |
| 3723 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Op |
| 3724 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
Scott Michel | 910b66d | 2007-07-30 21:00:31 +0000 | [diff] [blame] | 3725 | case TargetLowering::Custom: |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3726 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3727 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Scott Michel | 910b66d | 2007-07-30 21:00:31 +0000 | [diff] [blame] | 3728 | if (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0)) == |
Scott Michel | 335f4f7 | 2007-08-02 02:22:46 +0000 | [diff] [blame] | 3729 | TargetLowering::Custom) { |
| 3730 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3731 | if (Tmp1.getNode()) { |
Scott Michel | 335f4f7 | 2007-08-02 02:22:46 +0000 | [diff] [blame] | 3732 | Result = Tmp1; |
| 3733 | } |
Scott Michel | 910b66d | 2007-07-30 21:00:31 +0000 | [diff] [blame] | 3734 | } |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3735 | break; |
| 3736 | case TargetLowering::Promote: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3737 | MVT OVT = Tmp1.getValueType(); |
| 3738 | MVT NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT); |
Chris Lattner | edb1add | 2005-05-11 04:51:16 +0000 | [diff] [blame] | 3739 | |
| 3740 | // Zero extend the argument. |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3741 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Tmp1); |
| 3742 | // Perform the larger operation, then subtract if needed. |
| 3743 | Tmp1 = DAG.getNode(Node->getOpcode(), Node->getValueType(0), Tmp1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3744 | switch (Node->getOpcode()) { |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3745 | case ISD::CTPOP: |
| 3746 | Result = Tmp1; |
| 3747 | break; |
| 3748 | case ISD::CTTZ: |
| 3749 | //if Tmp1 == sizeinbits(NVT) then Tmp1 = sizeinbits(Old VT) |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 3750 | Tmp2 = DAG.getSetCC(TLI.getSetCCResultType(Tmp1.getValueType()), Tmp1, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3751 | DAG.getConstant(NVT.getSizeInBits(), NVT), |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 3752 | ISD::SETEQ); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 3753 | Result = DAG.getNode(ISD::SELECT, NVT, Tmp2, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3754 | DAG.getConstant(OVT.getSizeInBits(), NVT), Tmp1); |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3755 | break; |
| 3756 | case ISD::CTLZ: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3757 | // Tmp1 = Tmp1 - (sizeinbits(NVT) - sizeinbits(Old VT)) |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 3758 | Result = DAG.getNode(ISD::SUB, NVT, Tmp1, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3759 | DAG.getConstant(NVT.getSizeInBits() - |
| 3760 | OVT.getSizeInBits(), NVT)); |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3761 | break; |
| 3762 | } |
| 3763 | break; |
| 3764 | } |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3765 | case TargetLowering::Expand: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3766 | Result = ExpandBitCount(Node->getOpcode(), Tmp1); |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3767 | break; |
| 3768 | } |
| 3769 | break; |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 3770 | |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3771 | // Unary operators |
| 3772 | case ISD::FABS: |
| 3773 | case ISD::FNEG: |
Chris Lattner | da6ba87 | 2005-04-28 21:44:33 +0000 | [diff] [blame] | 3774 | case ISD::FSQRT: |
| 3775 | case ISD::FSIN: |
| 3776 | case ISD::FCOS: |
Dale Johannesen | 7794f2a | 2008-09-04 00:47:13 +0000 | [diff] [blame] | 3777 | case ISD::FLOG: |
| 3778 | case ISD::FLOG2: |
| 3779 | case ISD::FLOG10: |
| 3780 | case ISD::FEXP: |
| 3781 | case ISD::FEXP2: |
Dan Gohman | 509e84f | 2008-08-21 17:55:02 +0000 | [diff] [blame] | 3782 | case ISD::FTRUNC: |
| 3783 | case ISD::FFLOOR: |
| 3784 | case ISD::FCEIL: |
| 3785 | case ISD::FRINT: |
| 3786 | case ISD::FNEARBYINT: |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3787 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 3788 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3789 | case TargetLowering::Promote: |
| 3790 | case TargetLowering::Custom: |
Evan Cheng | 59ad781 | 2006-01-31 18:14:25 +0000 | [diff] [blame] | 3791 | isCustom = true; |
| 3792 | // FALLTHROUGH |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3793 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3794 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Evan Cheng | 59ad781 | 2006-01-31 18:14:25 +0000 | [diff] [blame] | 3795 | if (isCustom) { |
| 3796 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3797 | if (Tmp1.getNode()) Result = Tmp1; |
Evan Cheng | 59ad781 | 2006-01-31 18:14:25 +0000 | [diff] [blame] | 3798 | } |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3799 | break; |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3800 | case TargetLowering::Expand: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3801 | switch (Node->getOpcode()) { |
| 3802 | default: assert(0 && "Unreachable!"); |
| 3803 | case ISD::FNEG: |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3804 | // Expand Y = FNEG(X) -> Y = SUB -0.0, X |
| 3805 | Tmp2 = DAG.getConstantFP(-0.0, Node->getValueType(0)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3806 | Result = DAG.getNode(ISD::FSUB, Node->getValueType(0), Tmp2, Tmp1); |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 3807 | break; |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 3808 | case ISD::FABS: { |
Chris Lattner | 4af6e0d | 2005-04-02 05:26:37 +0000 | [diff] [blame] | 3809 | // Expand Y = FABS(X) -> Y = (X >u 0.0) ? X : fneg(X). |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3810 | MVT VT = Node->getValueType(0); |
Chris Lattner | 4af6e0d | 2005-04-02 05:26:37 +0000 | [diff] [blame] | 3811 | Tmp2 = DAG.getConstantFP(0.0, VT); |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 3812 | Tmp2 = DAG.getSetCC(TLI.getSetCCResultType(Tmp1.getValueType()), |
| 3813 | Tmp1, Tmp2, ISD::SETUGT); |
Chris Lattner | 4af6e0d | 2005-04-02 05:26:37 +0000 | [diff] [blame] | 3814 | Tmp3 = DAG.getNode(ISD::FNEG, VT, Tmp1); |
| 3815 | Result = DAG.getNode(ISD::SELECT, VT, Tmp2, Tmp1, Tmp3); |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 3816 | break; |
| 3817 | } |
Evan Cheng | 9d24ac5 | 2008-09-09 23:35:53 +0000 | [diff] [blame] | 3818 | case ISD::FSQRT: |
| 3819 | case ISD::FSIN: |
| 3820 | case ISD::FCOS: |
Dale Johannesen | 7794f2a | 2008-09-04 00:47:13 +0000 | [diff] [blame] | 3821 | case ISD::FLOG: |
| 3822 | case ISD::FLOG2: |
| 3823 | case ISD::FLOG10: |
| 3824 | case ISD::FEXP: |
| 3825 | case ISD::FEXP2: |
Dan Gohman | 2bb1e3e | 2008-08-21 18:38:14 +0000 | [diff] [blame] | 3826 | case ISD::FTRUNC: |
| 3827 | case ISD::FFLOOR: |
| 3828 | case ISD::FCEIL: |
| 3829 | case ISD::FRINT: |
Evan Cheng | 9d24ac5 | 2008-09-09 23:35:53 +0000 | [diff] [blame] | 3830 | case ISD::FNEARBYINT: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3831 | MVT VT = Node->getValueType(0); |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3832 | |
| 3833 | // Expand unsupported unary vector operators by unrolling them. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3834 | if (VT.isVector()) { |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3835 | Result = LegalizeOp(UnrollVectorOp(Op)); |
| 3836 | break; |
| 3837 | } |
| 3838 | |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3839 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 3840 | switch(Node->getOpcode()) { |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3841 | case ISD::FSQRT: |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 3842 | LC = GetFPLibCall(VT, RTLIB::SQRT_F32, RTLIB::SQRT_F64, |
| 3843 | RTLIB::SQRT_F80, RTLIB::SQRT_PPCF128); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3844 | break; |
| 3845 | case ISD::FSIN: |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 3846 | LC = GetFPLibCall(VT, RTLIB::SIN_F32, RTLIB::SIN_F64, |
| 3847 | RTLIB::SIN_F80, RTLIB::SIN_PPCF128); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3848 | break; |
| 3849 | case ISD::FCOS: |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 3850 | LC = GetFPLibCall(VT, RTLIB::COS_F32, RTLIB::COS_F64, |
| 3851 | RTLIB::COS_F80, RTLIB::COS_PPCF128); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3852 | break; |
Dale Johannesen | 7794f2a | 2008-09-04 00:47:13 +0000 | [diff] [blame] | 3853 | case ISD::FLOG: |
| 3854 | LC = GetFPLibCall(VT, RTLIB::LOG_F32, RTLIB::LOG_F64, |
| 3855 | RTLIB::LOG_F80, RTLIB::LOG_PPCF128); |
| 3856 | break; |
| 3857 | case ISD::FLOG2: |
| 3858 | LC = GetFPLibCall(VT, RTLIB::LOG2_F32, RTLIB::LOG2_F64, |
| 3859 | RTLIB::LOG2_F80, RTLIB::LOG2_PPCF128); |
| 3860 | break; |
| 3861 | case ISD::FLOG10: |
| 3862 | LC = GetFPLibCall(VT, RTLIB::LOG10_F32, RTLIB::LOG10_F64, |
| 3863 | RTLIB::LOG10_F80, RTLIB::LOG10_PPCF128); |
| 3864 | break; |
| 3865 | case ISD::FEXP: |
| 3866 | LC = GetFPLibCall(VT, RTLIB::EXP_F32, RTLIB::EXP_F64, |
| 3867 | RTLIB::EXP_F80, RTLIB::EXP_PPCF128); |
| 3868 | break; |
| 3869 | case ISD::FEXP2: |
| 3870 | LC = GetFPLibCall(VT, RTLIB::EXP2_F32, RTLIB::EXP2_F64, |
| 3871 | RTLIB::EXP2_F80, RTLIB::EXP2_PPCF128); |
| 3872 | break; |
Dan Gohman | 2bb1e3e | 2008-08-21 18:38:14 +0000 | [diff] [blame] | 3873 | case ISD::FTRUNC: |
| 3874 | LC = GetFPLibCall(VT, RTLIB::TRUNC_F32, RTLIB::TRUNC_F64, |
| 3875 | RTLIB::TRUNC_F80, RTLIB::TRUNC_PPCF128); |
| 3876 | break; |
| 3877 | case ISD::FFLOOR: |
| 3878 | LC = GetFPLibCall(VT, RTLIB::FLOOR_F32, RTLIB::FLOOR_F64, |
| 3879 | RTLIB::FLOOR_F80, RTLIB::FLOOR_PPCF128); |
| 3880 | break; |
| 3881 | case ISD::FCEIL: |
| 3882 | LC = GetFPLibCall(VT, RTLIB::CEIL_F32, RTLIB::CEIL_F64, |
| 3883 | RTLIB::CEIL_F80, RTLIB::CEIL_PPCF128); |
| 3884 | break; |
| 3885 | case ISD::FRINT: |
| 3886 | LC = GetFPLibCall(VT, RTLIB::RINT_F32, RTLIB::RINT_F64, |
| 3887 | RTLIB::RINT_F80, RTLIB::RINT_PPCF128); |
| 3888 | break; |
| 3889 | case ISD::FNEARBYINT: |
| 3890 | LC = GetFPLibCall(VT, RTLIB::NEARBYINT_F32, RTLIB::NEARBYINT_F64, |
| 3891 | RTLIB::NEARBYINT_F80, RTLIB::NEARBYINT_PPCF128); |
| 3892 | break; |
Evan Cheng | 9d24ac5 | 2008-09-09 23:35:53 +0000 | [diff] [blame] | 3893 | break; |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 3894 | default: assert(0 && "Unreachable!"); |
| 3895 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3896 | SDValue Dummy; |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 3897 | Result = ExpandLibCall(LC, Node, false/*sign irrelevant*/, Dummy); |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 3898 | break; |
| 3899 | } |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3900 | } |
| 3901 | break; |
| 3902 | } |
| 3903 | break; |
Chris Lattner | 6ddf8ed | 2006-09-09 06:03:30 +0000 | [diff] [blame] | 3904 | case ISD::FPOWI: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3905 | MVT VT = Node->getValueType(0); |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3906 | |
| 3907 | // Expand unsupported unary vector operators by unrolling them. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3908 | if (VT.isVector()) { |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3909 | Result = LegalizeOp(UnrollVectorOp(Op)); |
| 3910 | break; |
| 3911 | } |
| 3912 | |
| 3913 | // 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] | 3914 | RTLIB::Libcall LC = GetFPLibCall(VT, RTLIB::POWI_F32, RTLIB::POWI_F64, |
| 3915 | RTLIB::POWI_F80, RTLIB::POWI_PPCF128); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3916 | SDValue Dummy; |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 3917 | Result = ExpandLibCall(LC, Node, false/*sign irrelevant*/, Dummy); |
Chris Lattner | 6ddf8ed | 2006-09-09 06:03:30 +0000 | [diff] [blame] | 3918 | break; |
| 3919 | } |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 3920 | case ISD::BIT_CONVERT: |
Chris Lattner | 67993f7 | 2006-01-23 07:30:46 +0000 | [diff] [blame] | 3921 | if (!isTypeLegal(Node->getOperand(0).getValueType())) { |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 3922 | Result = EmitStackConvert(Node->getOperand(0), Node->getValueType(0), |
| 3923 | Node->getValueType(0)); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3924 | } else if (Op.getOperand(0).getValueType().isVector()) { |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3925 | // The input has to be a vector type, we have to either scalarize it, pack |
| 3926 | // 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] | 3927 | SDNode *InVal = Node->getOperand(0).getNode(); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 3928 | int InIx = Node->getOperand(0).getResNo(); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3929 | unsigned NumElems = InVal->getValueType(InIx).getVectorNumElements(); |
| 3930 | MVT EVT = InVal->getValueType(InIx).getVectorElementType(); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3931 | |
| 3932 | // Figure out if there is a simple type corresponding to this Vector |
| 3933 | // type. If so, convert to the vector type. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3934 | MVT TVT = MVT::getVectorVT(EVT, NumElems); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3935 | if (TLI.isTypeLegal(TVT)) { |
Dan Gohman | 07a9676 | 2007-07-16 14:29:03 +0000 | [diff] [blame] | 3936 | // Turn this into a bit convert of the vector input. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3937 | Result = DAG.getNode(ISD::BIT_CONVERT, Node->getValueType(0), |
| 3938 | LegalizeOp(Node->getOperand(0))); |
| 3939 | break; |
| 3940 | } else if (NumElems == 1) { |
| 3941 | // Turn this into a bit convert of the scalar input. |
| 3942 | Result = DAG.getNode(ISD::BIT_CONVERT, Node->getValueType(0), |
| 3943 | ScalarizeVectorOp(Node->getOperand(0))); |
| 3944 | break; |
| 3945 | } else { |
| 3946 | // FIXME: UNIMP! Store then reload |
| 3947 | assert(0 && "Cast from unsupported vector type not implemented yet!"); |
| 3948 | } |
Chris Lattner | 67993f7 | 2006-01-23 07:30:46 +0000 | [diff] [blame] | 3949 | } else { |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 3950 | switch (TLI.getOperationAction(ISD::BIT_CONVERT, |
| 3951 | Node->getOperand(0).getValueType())) { |
| 3952 | default: assert(0 && "Unknown operation action!"); |
| 3953 | case TargetLowering::Expand: |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 3954 | Result = EmitStackConvert(Node->getOperand(0), Node->getValueType(0), |
| 3955 | Node->getValueType(0)); |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 3956 | break; |
| 3957 | case TargetLowering::Legal: |
| 3958 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3959 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 3960 | break; |
| 3961 | } |
| 3962 | } |
| 3963 | break; |
Mon P Wang | 77cdf30 | 2008-11-10 20:54:11 +0000 | [diff] [blame] | 3964 | case ISD::CONVERT_RNDSAT: { |
| 3965 | ISD::CvtCode CvtCode = cast<CvtRndSatSDNode>(Node)->getCvtCode(); |
| 3966 | switch (CvtCode) { |
| 3967 | default: assert(0 && "Unknown cvt code!"); |
| 3968 | case ISD::CVT_SF: |
| 3969 | case ISD::CVT_UF: |
Mon P Wang | 77cdf30 | 2008-11-10 20:54:11 +0000 | [diff] [blame] | 3970 | case ISD::CVT_FF: |
Mon P Wang | 1cd46bb | 2008-12-09 07:27:39 +0000 | [diff] [blame] | 3971 | break; |
Mon P Wang | 77cdf30 | 2008-11-10 20:54:11 +0000 | [diff] [blame] | 3972 | case ISD::CVT_FS: |
| 3973 | case ISD::CVT_FU: |
| 3974 | case ISD::CVT_SS: |
| 3975 | case ISD::CVT_SU: |
| 3976 | case ISD::CVT_US: |
| 3977 | case ISD::CVT_UU: { |
| 3978 | SDValue DTyOp = Node->getOperand(1); |
| 3979 | SDValue STyOp = Node->getOperand(2); |
| 3980 | SDValue RndOp = Node->getOperand(3); |
| 3981 | SDValue SatOp = Node->getOperand(4); |
| 3982 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3983 | case Expand: assert(0 && "Shouldn't need to expand other operators here!"); |
| 3984 | case Legal: |
| 3985 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 3986 | Result = DAG.UpdateNodeOperands(Result, Tmp1, DTyOp, STyOp, |
| 3987 | RndOp, SatOp); |
| 3988 | if (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0)) == |
| 3989 | TargetLowering::Custom) { |
| 3990 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 3991 | if (Tmp1.getNode()) Result = Tmp1; |
| 3992 | } |
| 3993 | break; |
| 3994 | case Promote: |
| 3995 | Result = PromoteOp(Node->getOperand(0)); |
| 3996 | // For FP, make Op1 a i32 |
| 3997 | |
Mon P Wang | 1cd46bb | 2008-12-09 07:27:39 +0000 | [diff] [blame] | 3998 | Result = DAG.getConvertRndSat(Op.getValueType(), Result, |
Mon P Wang | 77cdf30 | 2008-11-10 20:54:11 +0000 | [diff] [blame] | 3999 | DTyOp, STyOp, RndOp, SatOp, CvtCode); |
| 4000 | break; |
| 4001 | } |
| 4002 | break; |
| 4003 | } |
| 4004 | } // end switch CvtCode |
| 4005 | break; |
| 4006 | } |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 4007 | // Conversion operators. The source and destination have different types. |
Chris Lattner | ae0aacb | 2005-01-08 08:08:56 +0000 | [diff] [blame] | 4008 | case ISD::SINT_TO_FP: |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 4009 | case ISD::UINT_TO_FP: { |
| 4010 | bool isSigned = Node->getOpcode() == ISD::SINT_TO_FP; |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 4011 | Result = LegalizeINT_TO_FP(Result, isSigned, |
| 4012 | Node->getValueType(0), Node->getOperand(0)); |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 4013 | break; |
| 4014 | } |
| 4015 | case ISD::TRUNCATE: |
| 4016 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 4017 | case Legal: |
| 4018 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Scott Michel | 546d7b5 | 2008-12-02 19:55:08 +0000 | [diff] [blame] | 4019 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 4020 | default: assert(0 && "Unknown TRUNCATE legalization operation action!"); |
| 4021 | case TargetLowering::Custom: |
Mon P Wang | f67303d | 2008-12-11 00:44:22 +0000 | [diff] [blame] | 4022 | isCustom = true; |
| 4023 | // FALLTHROUGH |
Scott Michel | 546d7b5 | 2008-12-02 19:55:08 +0000 | [diff] [blame] | 4024 | case TargetLowering::Legal: |
Mon P Wang | f67303d | 2008-12-11 00:44:22 +0000 | [diff] [blame] | 4025 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 4026 | if (isCustom) { |
| 4027 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 4028 | if (Tmp1.getNode()) Result = Tmp1; |
| 4029 | } |
| 4030 | break; |
Mon P Wang | 9e5ecb8 | 2008-12-12 01:25:51 +0000 | [diff] [blame] | 4031 | case TargetLowering::Expand: |
| 4032 | assert(Result.getValueType().isVector() && "must be vector type"); |
| 4033 | // Unroll the truncate. We should do better. |
| 4034 | Result = LegalizeOp(UnrollVectorOp(Result)); |
Tilmann Scheller | b0a5cdd | 2008-12-02 12:12:25 +0000 | [diff] [blame] | 4035 | } |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 4036 | break; |
| 4037 | case Expand: |
| 4038 | ExpandOp(Node->getOperand(0), Tmp1, Tmp2); |
| 4039 | |
| 4040 | // Since the result is legal, we should just be able to truncate the low |
| 4041 | // part of the source. |
| 4042 | Result = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0), Tmp1); |
| 4043 | break; |
| 4044 | case Promote: |
| 4045 | Result = PromoteOp(Node->getOperand(0)); |
| 4046 | Result = DAG.getNode(ISD::TRUNCATE, Op.getValueType(), Result); |
| 4047 | break; |
| 4048 | } |
| 4049 | break; |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 4050 | |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 4051 | case ISD::FP_TO_SINT: |
| 4052 | case ISD::FP_TO_UINT: |
| 4053 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 4054 | case Legal: |
Chris Lattner | f1fa74e | 2005-07-30 00:04:12 +0000 | [diff] [blame] | 4055 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 4056 | |
Chris Lattner | 1618beb | 2005-07-29 00:11:56 +0000 | [diff] [blame] | 4057 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))){ |
| 4058 | default: assert(0 && "Unknown operation action!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4059 | case TargetLowering::Custom: |
| 4060 | isCustom = true; |
| 4061 | // FALLTHROUGH |
| 4062 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 4063 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4064 | if (isCustom) { |
| 4065 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 4066 | if (Tmp1.getNode()) Result = Tmp1; |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4067 | } |
| 4068 | break; |
| 4069 | case TargetLowering::Promote: |
| 4070 | Result = PromoteLegalFP_TO_INT(Tmp1, Node->getValueType(0), |
| 4071 | Node->getOpcode() == ISD::FP_TO_SINT); |
| 4072 | break; |
Chris Lattner | 1618beb | 2005-07-29 00:11:56 +0000 | [diff] [blame] | 4073 | case TargetLowering::Expand: |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 4074 | if (Node->getOpcode() == ISD::FP_TO_UINT) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4075 | SDValue True, False; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4076 | MVT VT = Node->getOperand(0).getValueType(); |
| 4077 | MVT NVT = Node->getValueType(0); |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 4078 | const uint64_t zero[] = {0, 0}; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4079 | APFloat apf = APFloat(APInt(VT.getSizeInBits(), 2, zero)); |
| 4080 | APInt x = APInt::getSignBit(NVT.getSizeInBits()); |
Dan Gohman | c7773bf | 2008-02-29 01:44:25 +0000 | [diff] [blame] | 4081 | (void)apf.convertFromAPInt(x, false, APFloat::rmNearestTiesToEven); |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 4082 | Tmp2 = DAG.getConstantFP(apf, VT); |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 4083 | Tmp3 = DAG.getSetCC(TLI.getSetCCResultType(VT), Node->getOperand(0), |
| 4084 | Tmp2, ISD::SETLT); |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 4085 | True = DAG.getNode(ISD::FP_TO_SINT, NVT, Node->getOperand(0)); |
| 4086 | False = DAG.getNode(ISD::FP_TO_SINT, NVT, |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 4087 | DAG.getNode(ISD::FSUB, VT, Node->getOperand(0), |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 4088 | Tmp2)); |
| 4089 | False = DAG.getNode(ISD::XOR, NVT, False, |
Dan Gohman | c7773bf | 2008-02-29 01:44:25 +0000 | [diff] [blame] | 4090 | DAG.getConstant(x, NVT)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4091 | Result = DAG.getNode(ISD::SELECT, NVT, Tmp3, True, False); |
| 4092 | break; |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 4093 | } else { |
| 4094 | assert(0 && "Do not know how to expand FP_TO_SINT yet!"); |
| 4095 | } |
| 4096 | break; |
Chris Lattner | 07dffd6 | 2005-08-26 00:14:16 +0000 | [diff] [blame] | 4097 | } |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 4098 | break; |
Evan Cheng | 6af00d5 | 2006-12-13 01:57:55 +0000 | [diff] [blame] | 4099 | case Expand: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4100 | MVT VT = Op.getValueType(); |
| 4101 | MVT OVT = Node->getOperand(0).getValueType(); |
Dale Johannesen | fcf4d24 | 2007-10-11 23:32:15 +0000 | [diff] [blame] | 4102 | // Convert ppcf128 to i32 |
Dale Johannesen | 6eaeff2 | 2007-10-10 01:01:31 +0000 | [diff] [blame] | 4103 | if (OVT == MVT::ppcf128 && VT == MVT::i32) { |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4104 | if (Node->getOpcode() == ISD::FP_TO_SINT) { |
| 4105 | Result = DAG.getNode(ISD::FP_ROUND_INREG, MVT::ppcf128, |
| 4106 | Node->getOperand(0), DAG.getValueType(MVT::f64)); |
| 4107 | Result = DAG.getNode(ISD::FP_ROUND, MVT::f64, Result, |
| 4108 | DAG.getIntPtrConstant(1)); |
| 4109 | Result = DAG.getNode(ISD::FP_TO_SINT, VT, Result); |
| 4110 | } else { |
Dale Johannesen | fcf4d24 | 2007-10-11 23:32:15 +0000 | [diff] [blame] | 4111 | const uint64_t TwoE31[] = {0x41e0000000000000LL, 0}; |
| 4112 | APFloat apf = APFloat(APInt(128, 2, TwoE31)); |
| 4113 | Tmp2 = DAG.getConstantFP(apf, OVT); |
| 4114 | // X>=2^31 ? (int)(X-2^31)+0x80000000 : (int)X |
| 4115 | // FIXME: generated code sucks. |
| 4116 | Result = DAG.getNode(ISD::SELECT_CC, VT, Node->getOperand(0), Tmp2, |
| 4117 | DAG.getNode(ISD::ADD, MVT::i32, |
| 4118 | DAG.getNode(ISD::FP_TO_SINT, VT, |
| 4119 | DAG.getNode(ISD::FSUB, OVT, |
| 4120 | Node->getOperand(0), Tmp2)), |
| 4121 | DAG.getConstant(0x80000000, MVT::i32)), |
| 4122 | DAG.getNode(ISD::FP_TO_SINT, VT, |
| 4123 | Node->getOperand(0)), |
| 4124 | DAG.getCondCode(ISD::SETGE)); |
| 4125 | } |
Dale Johannesen | 6eaeff2 | 2007-10-10 01:01:31 +0000 | [diff] [blame] | 4126 | break; |
| 4127 | } |
Dan Gohman | a2e9485 | 2008-03-10 23:03:31 +0000 | [diff] [blame] | 4128 | // Convert f32 / f64 to i32 / i64 / i128. |
Duncan Sands | b2ff885 | 2008-07-17 02:36:29 +0000 | [diff] [blame] | 4129 | RTLIB::Libcall LC = (Node->getOpcode() == ISD::FP_TO_SINT) ? |
| 4130 | RTLIB::getFPTOSINT(OVT, VT) : RTLIB::getFPTOUINT(OVT, VT); |
| 4131 | assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unexpectd fp-to-int conversion!"); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4132 | SDValue Dummy; |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 4133 | Result = ExpandLibCall(LC, Node, false/*sign irrelevant*/, Dummy); |
Evan Cheng | 6af00d5 | 2006-12-13 01:57:55 +0000 | [diff] [blame] | 4134 | break; |
| 4135 | } |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 4136 | case Promote: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 4137 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4138 | Result = DAG.UpdateNodeOperands(Result, LegalizeOp(Tmp1)); |
| 4139 | Result = LegalizeOp(Result); |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 4140 | break; |
| 4141 | } |
| 4142 | break; |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 4143 | |
Chris Lattner | f2670a8 | 2008-01-16 06:57:07 +0000 | [diff] [blame] | 4144 | case ISD::FP_EXTEND: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4145 | MVT DstVT = Op.getValueType(); |
| 4146 | MVT SrcVT = Op.getOperand(0).getValueType(); |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4147 | if (TLI.getConvertAction(SrcVT, DstVT) == TargetLowering::Expand) { |
| 4148 | // The only other way we can lower this is to turn it into a STORE, |
| 4149 | // LOAD pair, targetting a temporary location (a stack slot). |
| 4150 | Result = EmitStackConvert(Node->getOperand(0), SrcVT, DstVT); |
| 4151 | break; |
Chris Lattner | f2670a8 | 2008-01-16 06:57:07 +0000 | [diff] [blame] | 4152 | } |
| 4153 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 4154 | case Expand: assert(0 && "Shouldn't need to expand other operators here!"); |
| 4155 | case Legal: |
| 4156 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 4157 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 4158 | break; |
| 4159 | case Promote: |
| 4160 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4161 | Result = DAG.getNode(ISD::FP_EXTEND, Op.getValueType(), Tmp1); |
| 4162 | break; |
| 4163 | } |
| 4164 | break; |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4165 | } |
Dale Johannesen | 5411a39 | 2007-08-09 01:04:01 +0000 | [diff] [blame] | 4166 | case ISD::FP_ROUND: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4167 | MVT DstVT = Op.getValueType(); |
| 4168 | MVT SrcVT = Op.getOperand(0).getValueType(); |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4169 | if (TLI.getConvertAction(SrcVT, DstVT) == TargetLowering::Expand) { |
| 4170 | if (SrcVT == MVT::ppcf128) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4171 | SDValue Lo; |
Dale Johannesen | 713ed3f | 2008-01-20 01:18:38 +0000 | [diff] [blame] | 4172 | ExpandOp(Node->getOperand(0), Lo, Result); |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4173 | // 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] | 4174 | if (DstVT!=MVT::f64) |
| 4175 | Result = DAG.getNode(ISD::FP_ROUND, DstVT, Result, Op.getOperand(1)); |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4176 | break; |
Dale Johannesen | 5411a39 | 2007-08-09 01:04:01 +0000 | [diff] [blame] | 4177 | } |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4178 | // The only other way we can lower this is to turn it into a STORE, |
| 4179 | // LOAD pair, targetting a temporary location (a stack slot). |
| 4180 | Result = EmitStackConvert(Node->getOperand(0), DstVT, DstVT); |
| 4181 | break; |
Dale Johannesen | 849f214 | 2007-07-03 00:53:03 +0000 | [diff] [blame] | 4182 | } |
Chris Lattner | f2670a8 | 2008-01-16 06:57:07 +0000 | [diff] [blame] | 4183 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 4184 | case Expand: assert(0 && "Shouldn't need to expand other operators here!"); |
| 4185 | case Legal: |
| 4186 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4187 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
Chris Lattner | f2670a8 | 2008-01-16 06:57:07 +0000 | [diff] [blame] | 4188 | break; |
| 4189 | case Promote: |
| 4190 | Tmp1 = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4191 | Result = DAG.getNode(ISD::FP_ROUND, Op.getValueType(), Tmp1, |
| 4192 | Node->getOperand(1)); |
Chris Lattner | f2670a8 | 2008-01-16 06:57:07 +0000 | [diff] [blame] | 4193 | break; |
| 4194 | } |
| 4195 | break; |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4196 | } |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 4197 | case ISD::ANY_EXTEND: |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 4198 | case ISD::ZERO_EXTEND: |
| 4199 | case ISD::SIGN_EXTEND: |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 4200 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4201 | case Expand: assert(0 && "Shouldn't need to expand other operators here!"); |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 4202 | case Legal: |
| 4203 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Scott Michel | 82747a5 | 2008-04-30 00:26:38 +0000 | [diff] [blame] | 4204 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Scott Michel | 0123b7d | 2008-02-15 23:05:48 +0000 | [diff] [blame] | 4205 | if (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0)) == |
| 4206 | TargetLowering::Custom) { |
Scott Michel | 82747a5 | 2008-04-30 00:26:38 +0000 | [diff] [blame] | 4207 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 4208 | if (Tmp1.getNode()) Result = Tmp1; |
Scott Michel | 0123b7d | 2008-02-15 23:05:48 +0000 | [diff] [blame] | 4209 | } |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 4210 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4211 | case Promote: |
| 4212 | switch (Node->getOpcode()) { |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 4213 | case ISD::ANY_EXTEND: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 4214 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4215 | Result = DAG.getNode(ISD::ANY_EXTEND, Op.getValueType(), Tmp1); |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 4216 | break; |
Chris Lattner | 1713e73 | 2005-01-16 00:38:00 +0000 | [diff] [blame] | 4217 | case ISD::ZERO_EXTEND: |
| 4218 | Result = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 4219 | Result = DAG.getNode(ISD::ANY_EXTEND, Op.getValueType(), Result); |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 4220 | Result = DAG.getZeroExtendInReg(Result, |
| 4221 | Node->getOperand(0).getValueType()); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4222 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4223 | case ISD::SIGN_EXTEND: |
Chris Lattner | 1713e73 | 2005-01-16 00:38:00 +0000 | [diff] [blame] | 4224 | Result = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 4225 | Result = DAG.getNode(ISD::ANY_EXTEND, Op.getValueType(), Result); |
Chris Lattner | 1713e73 | 2005-01-16 00:38:00 +0000 | [diff] [blame] | 4226 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(), |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 4227 | Result, |
| 4228 | DAG.getValueType(Node->getOperand(0).getValueType())); |
Chris Lattner | 1713e73 | 2005-01-16 00:38:00 +0000 | [diff] [blame] | 4229 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4230 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 4231 | } |
| 4232 | break; |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 4233 | case ISD::FP_ROUND_INREG: |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 4234 | case ISD::SIGN_EXTEND_INREG: { |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 4235 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4236 | MVT ExtraVT = cast<VTSDNode>(Node->getOperand(1))->getVT(); |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 4237 | |
| 4238 | // If this operation is not supported, convert it to a shl/shr or load/store |
| 4239 | // pair. |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 4240 | switch (TLI.getOperationAction(Node->getOpcode(), ExtraVT)) { |
| 4241 | default: assert(0 && "This action not supported for this op yet!"); |
| 4242 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 4243 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 4244 | break; |
| 4245 | case TargetLowering::Expand: |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 4246 | // If this is an integer extend and shifts are supported, do that. |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 4247 | if (Node->getOpcode() == ISD::SIGN_EXTEND_INREG) { |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 4248 | // NOTE: we could fall back on load/store here too for targets without |
| 4249 | // SAR. However, it is doubtful that any exist. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4250 | unsigned BitsDiff = Node->getValueType(0).getSizeInBits() - |
| 4251 | ExtraVT.getSizeInBits(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4252 | SDValue ShiftCst = DAG.getConstant(BitsDiff, TLI.getShiftAmountTy()); |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 4253 | Result = DAG.getNode(ISD::SHL, Node->getValueType(0), |
| 4254 | Node->getOperand(0), ShiftCst); |
| 4255 | Result = DAG.getNode(ISD::SRA, Node->getValueType(0), |
| 4256 | Result, ShiftCst); |
| 4257 | } else if (Node->getOpcode() == ISD::FP_ROUND_INREG) { |
Jim Laskey | 2d84c4c | 2006-10-11 17:52:19 +0000 | [diff] [blame] | 4258 | // 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] | 4259 | // EXTLOAD pair, targetting a temporary location (a stack slot). |
| 4260 | |
| 4261 | // NOTE: there is a choice here between constantly creating new stack |
| 4262 | // slots and always reusing the same one. We currently always create |
| 4263 | // new ones, as reuse may inhibit scheduling. |
Chris Lattner | a66bb39 | 2008-01-16 07:51:34 +0000 | [diff] [blame] | 4264 | Result = EmitStackConvert(Node->getOperand(0), ExtraVT, |
| 4265 | Node->getValueType(0)); |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 4266 | } else { |
| 4267 | assert(0 && "Unknown op"); |
| 4268 | } |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 4269 | break; |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 4270 | } |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 4271 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 4272 | } |
Duncan Sands | 36397f5 | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 4273 | case ISD::TRAMPOLINE: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4274 | SDValue Ops[6]; |
Duncan Sands | 36397f5 | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 4275 | for (unsigned i = 0; i != 6; ++i) |
| 4276 | Ops[i] = LegalizeOp(Node->getOperand(i)); |
| 4277 | Result = DAG.UpdateNodeOperands(Result, Ops, 6); |
| 4278 | // The only option for this node is to custom lower it. |
| 4279 | Result = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 4280 | assert(Result.getNode() && "Should always custom lower!"); |
Duncan Sands | f7331b3 | 2007-09-11 14:10:23 +0000 | [diff] [blame] | 4281 | |
| 4282 | // Since trampoline produces two values, make sure to remember that we |
| 4283 | // legalized both of them. |
| 4284 | Tmp1 = LegalizeOp(Result.getValue(1)); |
| 4285 | Result = LegalizeOp(Result); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4286 | AddLegalizedOperand(SDValue(Node, 0), Result); |
| 4287 | AddLegalizedOperand(SDValue(Node, 1), Tmp1); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 4288 | return Op.getResNo() ? Tmp1 : Result; |
Duncan Sands | 36397f5 | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 4289 | } |
Dan Gohman | 9c78a39 | 2008-05-14 00:43:10 +0000 | [diff] [blame] | 4290 | case ISD::FLT_ROUNDS_: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4291 | MVT VT = Node->getValueType(0); |
Anton Korobeynikov | 917c2a6 | 2007-11-15 23:25:33 +0000 | [diff] [blame] | 4292 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 4293 | default: assert(0 && "This action not supported for this op yet!"); |
| 4294 | case TargetLowering::Custom: |
| 4295 | Result = TLI.LowerOperation(Op, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 4296 | if (Result.getNode()) break; |
Anton Korobeynikov | 917c2a6 | 2007-11-15 23:25:33 +0000 | [diff] [blame] | 4297 | // Fall Thru |
| 4298 | case TargetLowering::Legal: |
| 4299 | // If this operation is not supported, lower it to constant 1 |
| 4300 | Result = DAG.getConstant(1, VT); |
| 4301 | break; |
| 4302 | } |
Dan Gohman | 9ab9ee8 | 2008-05-12 16:07:15 +0000 | [diff] [blame] | 4303 | break; |
Anton Korobeynikov | 917c2a6 | 2007-11-15 23:25:33 +0000 | [diff] [blame] | 4304 | } |
Chris Lattner | 41bab0b | 2008-01-15 21:58:08 +0000 | [diff] [blame] | 4305 | case ISD::TRAP: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4306 | MVT VT = Node->getValueType(0); |
Anton Korobeynikov | 66fac79 | 2008-01-15 07:02:33 +0000 | [diff] [blame] | 4307 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 4308 | default: assert(0 && "This action not supported for this op yet!"); |
Chris Lattner | 41bab0b | 2008-01-15 21:58:08 +0000 | [diff] [blame] | 4309 | case TargetLowering::Legal: |
| 4310 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 4311 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 4312 | break; |
Anton Korobeynikov | 66fac79 | 2008-01-15 07:02:33 +0000 | [diff] [blame] | 4313 | case TargetLowering::Custom: |
| 4314 | Result = TLI.LowerOperation(Op, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 4315 | if (Result.getNode()) break; |
Anton Korobeynikov | 66fac79 | 2008-01-15 07:02:33 +0000 | [diff] [blame] | 4316 | // Fall Thru |
Chris Lattner | 41bab0b | 2008-01-15 21:58:08 +0000 | [diff] [blame] | 4317 | case TargetLowering::Expand: |
Anton Korobeynikov | 66fac79 | 2008-01-15 07:02:33 +0000 | [diff] [blame] | 4318 | // If this operation is not supported, lower it to 'abort()' call |
Chris Lattner | 41bab0b | 2008-01-15 21:58:08 +0000 | [diff] [blame] | 4319 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Anton Korobeynikov | 66fac79 | 2008-01-15 07:02:33 +0000 | [diff] [blame] | 4320 | TargetLowering::ArgListTy Args; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4321 | std::pair<SDValue,SDValue> CallResult = |
Duncan Sands | 00fee65 | 2008-02-14 17:28:50 +0000 | [diff] [blame] | 4322 | TLI.LowerCallTo(Tmp1, Type::VoidTy, |
Dale Johannesen | 86098bd | 2008-09-26 19:31:26 +0000 | [diff] [blame] | 4323 | false, false, false, false, CallingConv::C, false, |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 4324 | DAG.getExternalSymbol("abort", TLI.getPointerTy()), |
Chris Lattner | 034f12e | 2008-01-15 22:09:33 +0000 | [diff] [blame] | 4325 | Args, DAG); |
Anton Korobeynikov | 66fac79 | 2008-01-15 07:02:33 +0000 | [diff] [blame] | 4326 | Result = CallResult.second; |
| 4327 | break; |
| 4328 | } |
Chris Lattner | 41bab0b | 2008-01-15 21:58:08 +0000 | [diff] [blame] | 4329 | break; |
Anton Korobeynikov | 66fac79 | 2008-01-15 07:02:33 +0000 | [diff] [blame] | 4330 | } |
Bill Wendling | 8ac0d4b | 2008-11-22 00:22:52 +0000 | [diff] [blame] | 4331 | |
Bill Wendling | 74c3765 | 2008-12-09 22:08:41 +0000 | [diff] [blame] | 4332 | case ISD::SADDO: |
| 4333 | case ISD::SSUBO: { |
Bill Wendling | c0062fb | 2008-11-25 08:12:19 +0000 | [diff] [blame] | 4334 | MVT VT = Node->getValueType(0); |
| 4335 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 4336 | default: assert(0 && "This action not supported for this op yet!"); |
| 4337 | case TargetLowering::Custom: |
| 4338 | Result = TLI.LowerOperation(Op, DAG); |
| 4339 | if (Result.getNode()) break; |
| 4340 | // FALLTHROUGH |
| 4341 | case TargetLowering::Legal: { |
| 4342 | SDValue LHS = LegalizeOp(Node->getOperand(0)); |
| 4343 | SDValue RHS = LegalizeOp(Node->getOperand(1)); |
| 4344 | |
Bill Wendling | 74c3765 | 2008-12-09 22:08:41 +0000 | [diff] [blame] | 4345 | SDValue Sum = DAG.getNode(Node->getOpcode() == ISD::SADDO ? |
| 4346 | ISD::ADD : ISD::SUB, LHS.getValueType(), |
| 4347 | LHS, RHS); |
Bill Wendling | c0062fb | 2008-11-25 08:12:19 +0000 | [diff] [blame] | 4348 | MVT OType = Node->getValueType(1); |
| 4349 | |
Bill Wendling | a6af91a | 2008-11-25 08:19:22 +0000 | [diff] [blame] | 4350 | SDValue Zero = DAG.getConstant(0, LHS.getValueType()); |
Bill Wendling | c0062fb | 2008-11-25 08:12:19 +0000 | [diff] [blame] | 4351 | |
Bill Wendling | 740464e | 2008-11-25 19:40:17 +0000 | [diff] [blame] | 4352 | // LHSSign -> LHS >= 0 |
| 4353 | // RHSSign -> RHS >= 0 |
| 4354 | // SumSign -> Sum >= 0 |
| 4355 | // |
Bill Wendling | 74c3765 | 2008-12-09 22:08:41 +0000 | [diff] [blame] | 4356 | // Add: |
Bill Wendling | 740464e | 2008-11-25 19:40:17 +0000 | [diff] [blame] | 4357 | // Overflow -> (LHSSign == RHSSign) && (LHSSign != SumSign) |
Bill Wendling | 74c3765 | 2008-12-09 22:08:41 +0000 | [diff] [blame] | 4358 | // Sub: |
| 4359 | // Overflow -> (LHSSign != RHSSign) && (LHSSign != SumSign) |
Bill Wendling | 740464e | 2008-11-25 19:40:17 +0000 | [diff] [blame] | 4360 | // |
| 4361 | SDValue LHSSign = DAG.getSetCC(OType, LHS, Zero, ISD::SETGE); |
| 4362 | SDValue RHSSign = DAG.getSetCC(OType, RHS, Zero, ISD::SETGE); |
Bill Wendling | 74c3765 | 2008-12-09 22:08:41 +0000 | [diff] [blame] | 4363 | SDValue SignsMatch = DAG.getSetCC(OType, LHSSign, RHSSign, |
| 4364 | Node->getOpcode() == ISD::SADDO ? |
| 4365 | ISD::SETEQ : ISD::SETNE); |
Bill Wendling | c0062fb | 2008-11-25 08:12:19 +0000 | [diff] [blame] | 4366 | |
Bill Wendling | 740464e | 2008-11-25 19:40:17 +0000 | [diff] [blame] | 4367 | SDValue SumSign = DAG.getSetCC(OType, Sum, Zero, ISD::SETGE); |
| 4368 | SDValue SumSignNE = DAG.getSetCC(OType, LHSSign, SumSign, ISD::SETNE); |
Bill Wendling | c0062fb | 2008-11-25 08:12:19 +0000 | [diff] [blame] | 4369 | |
Bill Wendling | 74c3765 | 2008-12-09 22:08:41 +0000 | [diff] [blame] | 4370 | SDValue Cmp = DAG.getNode(ISD::AND, OType, SignsMatch, SumSignNE); |
Bill Wendling | c0062fb | 2008-11-25 08:12:19 +0000 | [diff] [blame] | 4371 | |
| 4372 | MVT ValueVTs[] = { LHS.getValueType(), OType }; |
| 4373 | SDValue Ops[] = { Sum, Cmp }; |
| 4374 | |
Duncan Sands | aaffa05 | 2008-12-01 11:41:29 +0000 | [diff] [blame] | 4375 | Result = DAG.getNode(ISD::MERGE_VALUES, DAG.getVTList(&ValueVTs[0], 2), |
| 4376 | &Ops[0], 2); |
Bill Wendling | c0062fb | 2008-11-25 08:12:19 +0000 | [diff] [blame] | 4377 | SDNode *RNode = Result.getNode(); |
| 4378 | DAG.ReplaceAllUsesOfValueWith(SDValue(Node, 0), SDValue(RNode, 0)); |
| 4379 | DAG.ReplaceAllUsesOfValueWith(SDValue(Node, 1), SDValue(RNode, 1)); |
| 4380 | break; |
| 4381 | } |
| 4382 | } |
| 4383 | |
| 4384 | break; |
| 4385 | } |
Bill Wendling | 74c3765 | 2008-12-09 22:08:41 +0000 | [diff] [blame] | 4386 | case ISD::UADDO: |
| 4387 | case ISD::USUBO: { |
Bill Wendling | 41ea7e7 | 2008-11-24 19:21:46 +0000 | [diff] [blame] | 4388 | MVT VT = Node->getValueType(0); |
| 4389 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 4390 | default: assert(0 && "This action not supported for this op yet!"); |
| 4391 | case TargetLowering::Custom: |
| 4392 | Result = TLI.LowerOperation(Op, DAG); |
| 4393 | if (Result.getNode()) break; |
| 4394 | // FALLTHROUGH |
| 4395 | case TargetLowering::Legal: { |
| 4396 | SDValue LHS = LegalizeOp(Node->getOperand(0)); |
| 4397 | SDValue RHS = LegalizeOp(Node->getOperand(1)); |
Bill Wendling | 8ac0d4b | 2008-11-22 00:22:52 +0000 | [diff] [blame] | 4398 | |
Bill Wendling | 74c3765 | 2008-12-09 22:08:41 +0000 | [diff] [blame] | 4399 | SDValue Sum = DAG.getNode(Node->getOpcode() == ISD::UADDO ? |
| 4400 | ISD::ADD : ISD::SUB, LHS.getValueType(), |
| 4401 | LHS, RHS); |
Bill Wendling | 41ea7e7 | 2008-11-24 19:21:46 +0000 | [diff] [blame] | 4402 | MVT OType = Node->getValueType(1); |
Bill Wendling | 74c3765 | 2008-12-09 22:08:41 +0000 | [diff] [blame] | 4403 | SDValue Cmp = DAG.getSetCC(OType, Sum, LHS, |
| 4404 | Node->getOpcode () == ISD::UADDO ? |
| 4405 | ISD::SETULT : ISD::SETUGT); |
Bill Wendling | 8ac0d4b | 2008-11-22 00:22:52 +0000 | [diff] [blame] | 4406 | |
Bill Wendling | 41ea7e7 | 2008-11-24 19:21:46 +0000 | [diff] [blame] | 4407 | MVT ValueVTs[] = { LHS.getValueType(), OType }; |
| 4408 | SDValue Ops[] = { Sum, Cmp }; |
Bill Wendling | 8ac0d4b | 2008-11-22 00:22:52 +0000 | [diff] [blame] | 4409 | |
Duncan Sands | aaffa05 | 2008-12-01 11:41:29 +0000 | [diff] [blame] | 4410 | Result = DAG.getNode(ISD::MERGE_VALUES, DAG.getVTList(&ValueVTs[0], 2), |
| 4411 | &Ops[0], 2); |
Bill Wendling | 41ea7e7 | 2008-11-24 19:21:46 +0000 | [diff] [blame] | 4412 | SDNode *RNode = Result.getNode(); |
| 4413 | DAG.ReplaceAllUsesOfValueWith(SDValue(Node, 0), SDValue(RNode, 0)); |
| 4414 | DAG.ReplaceAllUsesOfValueWith(SDValue(Node, 1), SDValue(RNode, 1)); |
| 4415 | break; |
| 4416 | } |
| 4417 | } |
| 4418 | |
Bill Wendling | 8ac0d4b | 2008-11-22 00:22:52 +0000 | [diff] [blame] | 4419 | break; |
| 4420 | } |
Bill Wendling | 74c3765 | 2008-12-09 22:08:41 +0000 | [diff] [blame] | 4421 | case ISD::SMULO: |
| 4422 | case ISD::UMULO: { |
| 4423 | MVT VT = Node->getValueType(0); |
| 4424 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 4425 | default: assert(0 && "This action is not supported at all!"); |
| 4426 | case TargetLowering::Custom: |
| 4427 | Result = TLI.LowerOperation(Op, DAG); |
| 4428 | if (Result.getNode()) break; |
| 4429 | // Fall Thru |
| 4430 | case TargetLowering::Legal: |
| 4431 | // FIXME: According to Hacker's Delight, this can be implemented in |
| 4432 | // target independent lowering, but it would be inefficient, since it |
Bill Wendling | bc5e15e | 2008-12-10 02:01:32 +0000 | [diff] [blame] | 4433 | // requires a division + a branch. |
Bill Wendling | 74c3765 | 2008-12-09 22:08:41 +0000 | [diff] [blame] | 4434 | assert(0 && "Target independent lowering is not supported for SMULO/UMULO!"); |
| 4435 | break; |
| 4436 | } |
| 4437 | break; |
| 4438 | } |
| 4439 | |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 4440 | } |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4441 | |
Chris Lattner | 4ddd283 | 2006-04-08 04:13:17 +0000 | [diff] [blame] | 4442 | assert(Result.getValueType() == Op.getValueType() && |
| 4443 | "Bad legalization!"); |
| 4444 | |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4445 | // Make sure that the generated code is itself legal. |
| 4446 | if (Result != Op) |
| 4447 | Result = LegalizeOp(Result); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 4448 | |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 4449 | // Note that LegalizeOp may be reentered even from single-use nodes, which |
| 4450 | // means that we always must cache transformed nodes. |
| 4451 | AddLegalizedOperand(Op, Result); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 4452 | return Result; |
| 4453 | } |
| 4454 | |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4455 | /// PromoteOp - Given an operation that produces a value in an invalid type, |
| 4456 | /// promote it to compute the value into a larger type. The produced value will |
| 4457 | /// have the correct bits for the low portion of the register, but no guarantee |
| 4458 | /// 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] | 4459 | SDValue SelectionDAGLegalize::PromoteOp(SDValue Op) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4460 | MVT VT = Op.getValueType(); |
| 4461 | MVT NVT = TLI.getTypeToTransformTo(VT); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4462 | assert(getTypeAction(VT) == Promote && |
| 4463 | "Caller should expand or legalize operands that are not promotable!"); |
Duncan Sands | 8e4eb09 | 2008-06-08 20:54:56 +0000 | [diff] [blame] | 4464 | assert(NVT.bitsGT(VT) && NVT.isInteger() == VT.isInteger() && |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4465 | "Cannot promote to smaller type!"); |
| 4466 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4467 | SDValue Tmp1, Tmp2, Tmp3; |
| 4468 | SDValue Result; |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 4469 | SDNode *Node = Op.getNode(); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4470 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4471 | DenseMap<SDValue, SDValue>::iterator I = PromotedNodes.find(Op); |
Chris Lattner | 6fdcb25 | 2005-09-02 20:32:45 +0000 | [diff] [blame] | 4472 | if (I != PromotedNodes.end()) return I->second; |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 4473 | |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4474 | switch (Node->getOpcode()) { |
Chris Lattner | d5d0f9b | 2005-08-16 21:55:35 +0000 | [diff] [blame] | 4475 | case ISD::CopyFromReg: |
| 4476 | assert(0 && "CopyFromReg must be legal!"); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4477 | default: |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 4478 | #ifndef NDEBUG |
Dan Gohman | 3983358 | 2007-06-04 16:17:33 +0000 | [diff] [blame] | 4479 | cerr << "NODE: "; Node->dump(&DAG); cerr << "\n"; |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 4480 | #endif |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4481 | assert(0 && "Do not know how to promote this operator!"); |
| 4482 | abort(); |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 4483 | case ISD::UNDEF: |
| 4484 | Result = DAG.getNode(ISD::UNDEF, NVT); |
| 4485 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4486 | case ISD::Constant: |
Chris Lattner | ec176e3 | 2005-08-30 16:56:19 +0000 | [diff] [blame] | 4487 | if (VT != MVT::i1) |
| 4488 | Result = DAG.getNode(ISD::SIGN_EXTEND, NVT, Op); |
| 4489 | else |
| 4490 | Result = DAG.getNode(ISD::ZERO_EXTEND, NVT, Op); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4491 | assert(isa<ConstantSDNode>(Result) && "Didn't constant fold zext?"); |
| 4492 | break; |
| 4493 | case ISD::ConstantFP: |
| 4494 | Result = DAG.getNode(ISD::FP_EXTEND, NVT, Op); |
| 4495 | assert(isa<ConstantFPSDNode>(Result) && "Didn't constant fold fp_extend?"); |
| 4496 | break; |
Chris Lattner | ef5cd1d | 2005-01-18 17:54:55 +0000 | [diff] [blame] | 4497 | |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 4498 | case ISD::SETCC: { |
| 4499 | MVT VT0 = Node->getOperand(0).getValueType(); |
| 4500 | assert(isTypeLegal(TLI.getSetCCResultType(VT0)) |
Nate Begeman | 5922f56 | 2008-03-14 00:53:31 +0000 | [diff] [blame] | 4501 | && "SetCC type is not legal??"); |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 4502 | Result = DAG.getNode(ISD::SETCC, TLI.getSetCCResultType(VT0), |
Nate Begeman | 5922f56 | 2008-03-14 00:53:31 +0000 | [diff] [blame] | 4503 | Node->getOperand(0), Node->getOperand(1), |
| 4504 | Node->getOperand(2)); |
Chris Lattner | 82fbfb6 | 2005-01-18 02:59:52 +0000 | [diff] [blame] | 4505 | break; |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 4506 | } |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4507 | case ISD::TRUNCATE: |
| 4508 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 4509 | case Legal: |
| 4510 | Result = LegalizeOp(Node->getOperand(0)); |
Duncan Sands | 8e4eb09 | 2008-06-08 20:54:56 +0000 | [diff] [blame] | 4511 | assert(Result.getValueType().bitsGE(NVT) && |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4512 | "This truncation doesn't make sense!"); |
Duncan Sands | 8e4eb09 | 2008-06-08 20:54:56 +0000 | [diff] [blame] | 4513 | if (Result.getValueType().bitsGT(NVT)) // Truncate to NVT instead of VT |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4514 | Result = DAG.getNode(ISD::TRUNCATE, NVT, Result); |
| 4515 | break; |
Chris Lattner | e76ad6d | 2005-01-28 22:52:50 +0000 | [diff] [blame] | 4516 | case Promote: |
| 4517 | // The truncation is not required, because we don't guarantee anything |
| 4518 | // about high bits anyway. |
| 4519 | Result = PromoteOp(Node->getOperand(0)); |
| 4520 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4521 | case Expand: |
Nate Begeman | 79e46ac | 2005-04-04 00:57:08 +0000 | [diff] [blame] | 4522 | ExpandOp(Node->getOperand(0), Tmp1, Tmp2); |
| 4523 | // Truncate the low part of the expanded value to the result type |
Chris Lattner | e21c305 | 2005-08-01 18:16:37 +0000 | [diff] [blame] | 4524 | Result = DAG.getNode(ISD::TRUNCATE, NVT, Tmp1); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4525 | } |
| 4526 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4527 | case ISD::SIGN_EXTEND: |
| 4528 | case ISD::ZERO_EXTEND: |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 4529 | case ISD::ANY_EXTEND: |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4530 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 4531 | case Expand: assert(0 && "BUG: Smaller reg should have been promoted!"); |
| 4532 | case Legal: |
| 4533 | // 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] | 4534 | Result = DAG.getNode(Node->getOpcode(), NVT, Node->getOperand(0)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4535 | break; |
| 4536 | case Promote: |
| 4537 | // Promote the reg if it's smaller. |
| 4538 | Result = PromoteOp(Node->getOperand(0)); |
| 4539 | // The high bits are not guaranteed to be anything. Insert an extend. |
| 4540 | if (Node->getOpcode() == ISD::SIGN_EXTEND) |
Chris Lattner | 595dc54 | 2005-02-04 18:39:19 +0000 | [diff] [blame] | 4541 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Result, |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 4542 | DAG.getValueType(Node->getOperand(0).getValueType())); |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 4543 | else if (Node->getOpcode() == ISD::ZERO_EXTEND) |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 4544 | Result = DAG.getZeroExtendInReg(Result, |
| 4545 | Node->getOperand(0).getValueType()); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4546 | break; |
| 4547 | } |
| 4548 | break; |
Mon P Wang | 77cdf30 | 2008-11-10 20:54:11 +0000 | [diff] [blame] | 4549 | case ISD::CONVERT_RNDSAT: { |
| 4550 | ISD::CvtCode CvtCode = cast<CvtRndSatSDNode>(Node)->getCvtCode(); |
| 4551 | assert ((CvtCode == ISD::CVT_SS || CvtCode == ISD::CVT_SU || |
| 4552 | CvtCode == ISD::CVT_US || CvtCode == ISD::CVT_UU || |
| 4553 | CvtCode == ISD::CVT_SF || CvtCode == ISD::CVT_UF) && |
| 4554 | "can only promote integers"); |
| 4555 | Result = DAG.getConvertRndSat(NVT, Node->getOperand(0), |
| 4556 | Node->getOperand(1), Node->getOperand(2), |
| 4557 | Node->getOperand(3), Node->getOperand(4), |
| 4558 | CvtCode); |
| 4559 | break; |
| 4560 | |
| 4561 | } |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 4562 | case ISD::BIT_CONVERT: |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 4563 | Result = EmitStackConvert(Node->getOperand(0), Node->getValueType(0), |
| 4564 | Node->getValueType(0)); |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 4565 | Result = PromoteOp(Result); |
| 4566 | break; |
| 4567 | |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4568 | case ISD::FP_EXTEND: |
| 4569 | assert(0 && "Case not implemented. Dynamically dead with 2 FP types!"); |
| 4570 | case ISD::FP_ROUND: |
| 4571 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 4572 | case Expand: assert(0 && "BUG: Cannot expand FP regs!"); |
| 4573 | case Promote: assert(0 && "Unreachable with 2 FP types!"); |
| 4574 | case Legal: |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4575 | if (Node->getConstantOperandVal(1) == 0) { |
| 4576 | // Input is legal? Do an FP_ROUND_INREG. |
| 4577 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Node->getOperand(0), |
| 4578 | DAG.getValueType(VT)); |
| 4579 | } else { |
| 4580 | // Just remove the truncate, it isn't affecting the value. |
| 4581 | Result = DAG.getNode(ISD::FP_ROUND, NVT, Node->getOperand(0), |
| 4582 | Node->getOperand(1)); |
| 4583 | } |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4584 | break; |
| 4585 | } |
| 4586 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4587 | case ISD::SINT_TO_FP: |
| 4588 | case ISD::UINT_TO_FP: |
| 4589 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 4590 | case Legal: |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4591 | // No extra round required here. |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4592 | Result = DAG.getNode(Node->getOpcode(), NVT, Node->getOperand(0)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4593 | break; |
| 4594 | |
| 4595 | case Promote: |
| 4596 | Result = PromoteOp(Node->getOperand(0)); |
| 4597 | if (Node->getOpcode() == ISD::SINT_TO_FP) |
| 4598 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(), |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 4599 | Result, |
| 4600 | DAG.getValueType(Node->getOperand(0).getValueType())); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4601 | else |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 4602 | Result = DAG.getZeroExtendInReg(Result, |
| 4603 | Node->getOperand(0).getValueType()); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4604 | // No extra round required here. |
| 4605 | Result = DAG.getNode(Node->getOpcode(), NVT, Result); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4606 | break; |
| 4607 | case Expand: |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4608 | Result = ExpandIntToFP(Node->getOpcode() == ISD::SINT_TO_FP, NVT, |
| 4609 | Node->getOperand(0)); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4610 | // Round if we cannot tolerate excess precision. |
| 4611 | if (NoExcessFPPrecision) |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 4612 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 4613 | DAG.getValueType(VT)); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4614 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4615 | } |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4616 | break; |
| 4617 | |
Chris Lattner | 5e3c5b4 | 2005-12-09 17:32:47 +0000 | [diff] [blame] | 4618 | case ISD::SIGN_EXTEND_INREG: |
| 4619 | Result = PromoteOp(Node->getOperand(0)); |
| 4620 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Result, |
| 4621 | Node->getOperand(1)); |
| 4622 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4623 | case ISD::FP_TO_SINT: |
| 4624 | case ISD::FP_TO_UINT: |
| 4625 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 4626 | case Legal: |
Evan Cheng | 0b1b9dc | 2006-12-16 02:10:30 +0000 | [diff] [blame] | 4627 | case Expand: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4628 | Tmp1 = Node->getOperand(0); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4629 | break; |
| 4630 | case Promote: |
| 4631 | // The input result is prerounded, so we don't have to do anything |
| 4632 | // special. |
| 4633 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4634 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4635 | } |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 4636 | // If we're promoting a UINT to a larger size, check to see if the new node |
| 4637 | // will be legal. If it isn't, check to see if FP_TO_SINT is legal, since |
| 4638 | // we can use that instead. This allows us to generate better code for |
| 4639 | // FP_TO_UINT for small destination sizes on targets where FP_TO_UINT is not |
| 4640 | // legal, such as PowerPC. |
| 4641 | if (Node->getOpcode() == ISD::FP_TO_UINT && |
Chris Lattner | c9c60f6 | 2005-08-24 16:35:28 +0000 | [diff] [blame] | 4642 | !TLI.isOperationLegal(ISD::FP_TO_UINT, NVT) && |
Nate Begeman | b7f6ef1 | 2005-10-25 23:47:25 +0000 | [diff] [blame] | 4643 | (TLI.isOperationLegal(ISD::FP_TO_SINT, NVT) || |
| 4644 | TLI.getOperationAction(ISD::FP_TO_SINT, NVT)==TargetLowering::Custom)){ |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 4645 | Result = DAG.getNode(ISD::FP_TO_SINT, NVT, Tmp1); |
| 4646 | } else { |
| 4647 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1); |
| 4648 | } |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4649 | break; |
| 4650 | |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 4651 | case ISD::FABS: |
| 4652 | case ISD::FNEG: |
| 4653 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4654 | assert(Tmp1.getValueType() == NVT); |
| 4655 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1); |
| 4656 | // NOTE: we do not have to do any extra rounding here for |
| 4657 | // NoExcessFPPrecision, because we know the input will have the appropriate |
| 4658 | // precision, and these operations don't modify precision at all. |
| 4659 | break; |
| 4660 | |
Dale Johannesen | 7794f2a | 2008-09-04 00:47:13 +0000 | [diff] [blame] | 4661 | case ISD::FLOG: |
| 4662 | case ISD::FLOG2: |
| 4663 | case ISD::FLOG10: |
| 4664 | case ISD::FEXP: |
| 4665 | case ISD::FEXP2: |
Chris Lattner | da6ba87 | 2005-04-28 21:44:33 +0000 | [diff] [blame] | 4666 | case ISD::FSQRT: |
| 4667 | case ISD::FSIN: |
| 4668 | case ISD::FCOS: |
Dan Gohman | 2bb1e3e | 2008-08-21 18:38:14 +0000 | [diff] [blame] | 4669 | case ISD::FTRUNC: |
| 4670 | case ISD::FFLOOR: |
| 4671 | case ISD::FCEIL: |
| 4672 | case ISD::FRINT: |
| 4673 | case ISD::FNEARBYINT: |
Chris Lattner | da6ba87 | 2005-04-28 21:44:33 +0000 | [diff] [blame] | 4674 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4675 | assert(Tmp1.getValueType() == NVT); |
| 4676 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4677 | if (NoExcessFPPrecision) |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 4678 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 4679 | DAG.getValueType(VT)); |
Chris Lattner | da6ba87 | 2005-04-28 21:44:33 +0000 | [diff] [blame] | 4680 | break; |
| 4681 | |
Evan Cheng | 9d24ac5 | 2008-09-09 23:35:53 +0000 | [diff] [blame] | 4682 | case ISD::FPOW: |
Chris Lattner | 8b2d42c | 2007-03-03 23:43:21 +0000 | [diff] [blame] | 4683 | case ISD::FPOWI: { |
Evan Cheng | 9d24ac5 | 2008-09-09 23:35:53 +0000 | [diff] [blame] | 4684 | // 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] | 4685 | // directly as well, which may be better. |
| 4686 | Tmp1 = PromoteOp(Node->getOperand(0)); |
Evan Cheng | 9d24ac5 | 2008-09-09 23:35:53 +0000 | [diff] [blame] | 4687 | Tmp2 = Node->getOperand(1); |
| 4688 | if (Node->getOpcode() == ISD::FPOW) |
| 4689 | Tmp2 = PromoteOp(Tmp2); |
Chris Lattner | 8b2d42c | 2007-03-03 23:43:21 +0000 | [diff] [blame] | 4690 | assert(Tmp1.getValueType() == NVT); |
Evan Cheng | 9d24ac5 | 2008-09-09 23:35:53 +0000 | [diff] [blame] | 4691 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
Chris Lattner | 8b2d42c | 2007-03-03 23:43:21 +0000 | [diff] [blame] | 4692 | if (NoExcessFPPrecision) |
| 4693 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 4694 | DAG.getValueType(VT)); |
| 4695 | break; |
| 4696 | } |
| 4697 | |
Dan Gohman | 0b1d4a7 | 2008-12-23 21:37:04 +0000 | [diff] [blame] | 4698 | case ISD::ATOMIC_CMP_SWAP: { |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 4699 | AtomicSDNode* AtomNode = cast<AtomicSDNode>(Node); |
Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 4700 | Tmp2 = PromoteOp(Node->getOperand(2)); |
| 4701 | Tmp3 = PromoteOp(Node->getOperand(3)); |
Dan Gohman | 0b1d4a7 | 2008-12-23 21:37:04 +0000 | [diff] [blame] | 4702 | Result = DAG.getAtomic(Node->getOpcode(), AtomNode->getMemoryVT(), |
| 4703 | AtomNode->getChain(), |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 4704 | AtomNode->getBasePtr(), Tmp2, Tmp3, |
Dan Gohman | fd4418f | 2008-06-25 16:07:49 +0000 | [diff] [blame] | 4705 | AtomNode->getSrcValue(), |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 4706 | AtomNode->getAlignment()); |
Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 4707 | // Remember that we legalized the chain. |
| 4708 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1))); |
| 4709 | break; |
| 4710 | } |
Dan Gohman | 0b1d4a7 | 2008-12-23 21:37:04 +0000 | [diff] [blame] | 4711 | case ISD::ATOMIC_LOAD_ADD: |
| 4712 | case ISD::ATOMIC_LOAD_SUB: |
| 4713 | case ISD::ATOMIC_LOAD_AND: |
| 4714 | case ISD::ATOMIC_LOAD_OR: |
| 4715 | case ISD::ATOMIC_LOAD_XOR: |
| 4716 | case ISD::ATOMIC_LOAD_NAND: |
| 4717 | case ISD::ATOMIC_LOAD_MIN: |
| 4718 | case ISD::ATOMIC_LOAD_MAX: |
| 4719 | case ISD::ATOMIC_LOAD_UMIN: |
| 4720 | case ISD::ATOMIC_LOAD_UMAX: |
| 4721 | case ISD::ATOMIC_SWAP: { |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 4722 | AtomicSDNode* AtomNode = cast<AtomicSDNode>(Node); |
Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 4723 | Tmp2 = PromoteOp(Node->getOperand(2)); |
Dan Gohman | 0b1d4a7 | 2008-12-23 21:37:04 +0000 | [diff] [blame] | 4724 | Result = DAG.getAtomic(Node->getOpcode(), AtomNode->getMemoryVT(), |
| 4725 | AtomNode->getChain(), |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 4726 | AtomNode->getBasePtr(), Tmp2, |
Dan Gohman | fd4418f | 2008-06-25 16:07:49 +0000 | [diff] [blame] | 4727 | AtomNode->getSrcValue(), |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 4728 | AtomNode->getAlignment()); |
Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 4729 | // Remember that we legalized the chain. |
| 4730 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1))); |
| 4731 | break; |
| 4732 | } |
| 4733 | |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4734 | case ISD::AND: |
| 4735 | case ISD::OR: |
| 4736 | case ISD::XOR: |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 4737 | case ISD::ADD: |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4738 | case ISD::SUB: |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 4739 | case ISD::MUL: |
| 4740 | // 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] | 4741 | // 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] | 4742 | // that too is okay if they are integer operations. |
| 4743 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4744 | Tmp2 = PromoteOp(Node->getOperand(1)); |
| 4745 | assert(Tmp1.getValueType() == NVT && Tmp2.getValueType() == NVT); |
| 4746 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 4747 | break; |
| 4748 | case ISD::FADD: |
| 4749 | case ISD::FSUB: |
| 4750 | case ISD::FMUL: |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 4751 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4752 | Tmp2 = PromoteOp(Node->getOperand(1)); |
| 4753 | assert(Tmp1.getValueType() == NVT && Tmp2.getValueType() == NVT); |
| 4754 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 4755 | |
| 4756 | // Floating point operations will give excess precision that we may not be |
| 4757 | // able to tolerate. If we DO allow excess precision, just leave it, |
| 4758 | // otherwise excise it. |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4759 | // FIXME: Why would we need to round FP ops more than integer ones? |
| 4760 | // 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] | 4761 | if (NoExcessFPPrecision) |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 4762 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 4763 | DAG.getValueType(VT)); |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 4764 | break; |
| 4765 | |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4766 | case ISD::SDIV: |
| 4767 | case ISD::SREM: |
| 4768 | // These operators require that their input be sign extended. |
| 4769 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4770 | Tmp2 = PromoteOp(Node->getOperand(1)); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4771 | if (NVT.isInteger()) { |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 4772 | Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp1, |
| 4773 | DAG.getValueType(VT)); |
| 4774 | Tmp2 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp2, |
| 4775 | DAG.getValueType(VT)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4776 | } |
| 4777 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 4778 | |
| 4779 | // Perform FP_ROUND: this is probably overly pessimistic. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4780 | if (NVT.isFloatingPoint() && NoExcessFPPrecision) |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 4781 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 4782 | DAG.getValueType(VT)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4783 | break; |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 4784 | case ISD::FDIV: |
| 4785 | case ISD::FREM: |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 4786 | case ISD::FCOPYSIGN: |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 4787 | // These operators require that their input be fp extended. |
Nate Begeman | ec57fd9 | 2006-05-09 18:20:51 +0000 | [diff] [blame] | 4788 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4789 | case Expand: assert(0 && "not implemented"); |
| 4790 | case Legal: Tmp1 = LegalizeOp(Node->getOperand(0)); break; |
| 4791 | case Promote: Tmp1 = PromoteOp(Node->getOperand(0)); break; |
Nate Begeman | ec57fd9 | 2006-05-09 18:20:51 +0000 | [diff] [blame] | 4792 | } |
| 4793 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4794 | case Expand: assert(0 && "not implemented"); |
| 4795 | case Legal: Tmp2 = LegalizeOp(Node->getOperand(1)); break; |
| 4796 | case Promote: Tmp2 = PromoteOp(Node->getOperand(1)); break; |
Nate Begeman | ec57fd9 | 2006-05-09 18:20:51 +0000 | [diff] [blame] | 4797 | } |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 4798 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 4799 | |
| 4800 | // Perform FP_ROUND: this is probably overly pessimistic. |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 4801 | if (NoExcessFPPrecision && Node->getOpcode() != ISD::FCOPYSIGN) |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 4802 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 4803 | DAG.getValueType(VT)); |
| 4804 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4805 | |
| 4806 | case ISD::UDIV: |
| 4807 | case ISD::UREM: |
| 4808 | // These operators require that their input be zero extended. |
| 4809 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4810 | Tmp2 = PromoteOp(Node->getOperand(1)); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4811 | assert(NVT.isInteger() && "Operators don't apply to FP!"); |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 4812 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, VT); |
| 4813 | Tmp2 = DAG.getZeroExtendInReg(Tmp2, VT); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4814 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 4815 | break; |
| 4816 | |
| 4817 | case ISD::SHL: |
| 4818 | Tmp1 = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4819 | Result = DAG.getNode(ISD::SHL, NVT, Tmp1, Node->getOperand(1)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4820 | break; |
| 4821 | case ISD::SRA: |
| 4822 | // The input value must be properly sign extended. |
| 4823 | Tmp1 = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 4824 | Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp1, |
| 4825 | DAG.getValueType(VT)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4826 | Result = DAG.getNode(ISD::SRA, NVT, Tmp1, Node->getOperand(1)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4827 | break; |
| 4828 | case ISD::SRL: |
| 4829 | // The input value must be properly zero extended. |
| 4830 | Tmp1 = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 4831 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, VT); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4832 | Result = DAG.getNode(ISD::SRL, NVT, Tmp1, Node->getOperand(1)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4833 | break; |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 4834 | |
| 4835 | case ISD::VAARG: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4836 | Tmp1 = Node->getOperand(0); // Get the chain. |
| 4837 | Tmp2 = Node->getOperand(1); // Get the pointer. |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 4838 | if (TLI.getOperationAction(ISD::VAARG, VT) == TargetLowering::Custom) { |
| 4839 | Tmp3 = DAG.getVAArg(VT, Tmp1, Tmp2, Node->getOperand(2)); |
Duncan Sands | 126d907 | 2008-07-04 11:47:58 +0000 | [diff] [blame] | 4840 | Result = TLI.LowerOperation(Tmp3, DAG); |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 4841 | } else { |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 4842 | const Value *V = cast<SrcValueSDNode>(Node->getOperand(2))->getValue(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4843 | SDValue VAList = DAG.getLoad(TLI.getPointerTy(), Tmp1, Tmp2, V, 0); |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 4844 | // Increment the pointer, VAList, to the next vaarg |
| 4845 | Tmp3 = DAG.getNode(ISD::ADD, TLI.getPointerTy(), VAList, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4846 | DAG.getConstant(VT.getSizeInBits()/8, |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 4847 | TLI.getPointerTy())); |
| 4848 | // Store the incremented VAList to the legalized pointer |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 4849 | Tmp3 = DAG.getStore(VAList.getValue(1), Tmp3, Tmp2, V, 0); |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 4850 | // Load the actual argument out of the pointer VAList |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 4851 | Result = DAG.getExtLoad(ISD::EXTLOAD, NVT, Tmp3, VAList, NULL, 0, VT); |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 4852 | } |
| 4853 | // Remember that we legalized the chain. |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4854 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1))); |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 4855 | break; |
| 4856 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 4857 | case ISD::LOAD: { |
| 4858 | LoadSDNode *LD = cast<LoadSDNode>(Node); |
Evan Cheng | 62f2a3c | 2006-10-10 07:51:21 +0000 | [diff] [blame] | 4859 | ISD::LoadExtType ExtType = ISD::isNON_EXTLoad(Node) |
| 4860 | ? ISD::EXTLOAD : LD->getExtensionType(); |
| 4861 | Result = DAG.getExtLoad(ExtType, NVT, |
| 4862 | LD->getChain(), LD->getBasePtr(), |
Chris Lattner | 55b5708 | 2006-10-10 18:54:19 +0000 | [diff] [blame] | 4863 | LD->getSrcValue(), LD->getSrcValueOffset(), |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 4864 | LD->getMemoryVT(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 4865 | LD->isVolatile(), |
| 4866 | LD->getAlignment()); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4867 | // Remember that we legalized the chain. |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4868 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1))); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4869 | break; |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 4870 | } |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 4871 | case ISD::SELECT: { |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4872 | Tmp2 = PromoteOp(Node->getOperand(1)); // Legalize the op0 |
| 4873 | Tmp3 = PromoteOp(Node->getOperand(2)); // Legalize the op1 |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 4874 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4875 | MVT VT2 = Tmp2.getValueType(); |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 4876 | assert(VT2 == Tmp3.getValueType() |
Scott Michel | ba12f57 | 2008-06-03 19:13:20 +0000 | [diff] [blame] | 4877 | && "PromoteOp SELECT: Operands 2 and 3 ValueTypes don't match"); |
| 4878 | // Ensure that the resulting node is at least the same size as the operands' |
| 4879 | // value types, because we cannot assume that TLI.getSetCCValueType() is |
| 4880 | // constant. |
| 4881 | Result = DAG.getNode(ISD::SELECT, VT2, Node->getOperand(0), Tmp2, Tmp3); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4882 | break; |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 4883 | } |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 4884 | case ISD::SELECT_CC: |
| 4885 | Tmp2 = PromoteOp(Node->getOperand(2)); // True |
| 4886 | Tmp3 = PromoteOp(Node->getOperand(3)); // False |
| 4887 | Result = DAG.getNode(ISD::SELECT_CC, NVT, Node->getOperand(0), |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4888 | Node->getOperand(1), Tmp2, Tmp3, Node->getOperand(4)); |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 4889 | break; |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 4890 | case ISD::BSWAP: |
| 4891 | Tmp1 = Node->getOperand(0); |
| 4892 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Tmp1); |
| 4893 | Tmp1 = DAG.getNode(ISD::BSWAP, NVT, Tmp1); |
| 4894 | Result = DAG.getNode(ISD::SRL, NVT, Tmp1, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4895 | DAG.getConstant(NVT.getSizeInBits() - |
| 4896 | VT.getSizeInBits(), |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 4897 | TLI.getShiftAmountTy())); |
| 4898 | break; |
Andrew Lenharth | fecf095 | 2005-05-04 19:11:05 +0000 | [diff] [blame] | 4899 | case ISD::CTPOP: |
| 4900 | case ISD::CTTZ: |
| 4901 | case ISD::CTLZ: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4902 | // Zero extend the argument |
| 4903 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Node->getOperand(0)); |
Andrew Lenharth | fecf095 | 2005-05-04 19:11:05 +0000 | [diff] [blame] | 4904 | // Perform the larger operation, then subtract if needed. |
| 4905 | Tmp1 = DAG.getNode(Node->getOpcode(), NVT, Tmp1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4906 | switch(Node->getOpcode()) { |
Andrew Lenharth | fecf095 | 2005-05-04 19:11:05 +0000 | [diff] [blame] | 4907 | case ISD::CTPOP: |
| 4908 | Result = Tmp1; |
| 4909 | break; |
| 4910 | case ISD::CTTZ: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4911 | // if Tmp1 == sizeinbits(NVT) then Tmp1 = sizeinbits(Old VT) |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 4912 | Tmp2 = DAG.getSetCC(TLI.getSetCCResultType(Tmp1.getValueType()), Tmp1, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4913 | DAG.getConstant(NVT.getSizeInBits(), NVT), |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 4914 | ISD::SETEQ); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 4915 | Result = DAG.getNode(ISD::SELECT, NVT, Tmp2, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4916 | DAG.getConstant(VT.getSizeInBits(), NVT), Tmp1); |
Andrew Lenharth | fecf095 | 2005-05-04 19:11:05 +0000 | [diff] [blame] | 4917 | break; |
| 4918 | case ISD::CTLZ: |
| 4919 | //Tmp1 = Tmp1 - (sizeinbits(NVT) - sizeinbits(Old VT)) |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 4920 | Result = DAG.getNode(ISD::SUB, NVT, Tmp1, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4921 | DAG.getConstant(NVT.getSizeInBits() - |
| 4922 | VT.getSizeInBits(), NVT)); |
Andrew Lenharth | fecf095 | 2005-05-04 19:11:05 +0000 | [diff] [blame] | 4923 | break; |
| 4924 | } |
| 4925 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4926 | case ISD::EXTRACT_SUBVECTOR: |
| 4927 | Result = PromoteOp(ExpandEXTRACT_SUBVECTOR(Op)); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 4928 | break; |
Chris Lattner | 4aab2f4 | 2006-04-02 05:06:04 +0000 | [diff] [blame] | 4929 | case ISD::EXTRACT_VECTOR_ELT: |
| 4930 | Result = PromoteOp(ExpandEXTRACT_VECTOR_ELT(Op)); |
| 4931 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4932 | } |
| 4933 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 4934 | assert(Result.getNode() && "Didn't set a result!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4935 | |
| 4936 | // Make sure the result is itself legal. |
| 4937 | Result = LegalizeOp(Result); |
| 4938 | |
| 4939 | // Remember that we promoted this! |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4940 | AddPromotedOperand(Op, Result); |
| 4941 | return Result; |
| 4942 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 4943 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4944 | /// ExpandEXTRACT_VECTOR_ELT - Expand an EXTRACT_VECTOR_ELT operation into |
| 4945 | /// a legal EXTRACT_VECTOR_ELT operation, scalar code, or memory traffic, |
| 4946 | /// based on the vector type. The return type of this matches the element type |
| 4947 | /// of the vector, which may not be legal for the target. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4948 | SDValue SelectionDAGLegalize::ExpandEXTRACT_VECTOR_ELT(SDValue Op) { |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4949 | // We know that operand #0 is the Vec vector. If the index is a constant |
| 4950 | // or if the invec is a supported hardware type, we can use it. Otherwise, |
| 4951 | // lower to a store then an indexed load. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4952 | SDValue Vec = Op.getOperand(0); |
| 4953 | SDValue Idx = Op.getOperand(1); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4954 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4955 | MVT TVT = Vec.getValueType(); |
| 4956 | unsigned NumElems = TVT.getVectorNumElements(); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4957 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4958 | switch (TLI.getOperationAction(ISD::EXTRACT_VECTOR_ELT, TVT)) { |
| 4959 | default: assert(0 && "This action is not supported yet!"); |
| 4960 | case TargetLowering::Custom: { |
| 4961 | Vec = LegalizeOp(Vec); |
| 4962 | Op = DAG.UpdateNodeOperands(Op, Vec, Idx); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4963 | SDValue Tmp3 = TLI.LowerOperation(Op, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 4964 | if (Tmp3.getNode()) |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4965 | return Tmp3; |
| 4966 | break; |
| 4967 | } |
| 4968 | case TargetLowering::Legal: |
| 4969 | if (isTypeLegal(TVT)) { |
| 4970 | Vec = LegalizeOp(Vec); |
| 4971 | Op = DAG.UpdateNodeOperands(Op, Vec, Idx); |
Christopher Lamb | 844228a | 2007-07-26 03:33:13 +0000 | [diff] [blame] | 4972 | return Op; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4973 | } |
| 4974 | break; |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 4975 | case TargetLowering::Promote: |
| 4976 | assert(TVT.isVector() && "not vector type"); |
| 4977 | // fall thru to expand since vectors are by default are promote |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4978 | case TargetLowering::Expand: |
| 4979 | break; |
| 4980 | } |
| 4981 | |
| 4982 | if (NumElems == 1) { |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4983 | // This must be an access of the only element. Return it. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4984 | Op = ScalarizeVectorOp(Vec); |
| 4985 | } else if (!TLI.isTypeLegal(TVT) && isa<ConstantSDNode>(Idx)) { |
Nate Begeman | 55030dc | 2008-01-29 02:24:00 +0000 | [diff] [blame] | 4986 | unsigned NumLoElts = 1 << Log2_32(NumElems-1); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4987 | ConstantSDNode *CIdx = cast<ConstantSDNode>(Idx); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4988 | SDValue Lo, Hi; |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4989 | SplitVectorOp(Vec, Lo, Hi); |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 4990 | if (CIdx->getZExtValue() < NumLoElts) { |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4991 | Vec = Lo; |
| 4992 | } else { |
| 4993 | Vec = Hi; |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 4994 | Idx = DAG.getConstant(CIdx->getZExtValue() - NumLoElts, |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4995 | Idx.getValueType()); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4996 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4997 | |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4998 | // It's now an extract from the appropriate high or low part. Recurse. |
| 4999 | Op = DAG.UpdateNodeOperands(Op, Vec, Idx); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5000 | Op = ExpandEXTRACT_VECTOR_ELT(Op); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 5001 | } else { |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5002 | // Store the value to a temporary stack slot, then LOAD the scalar |
| 5003 | // element back out. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5004 | SDValue StackPtr = DAG.CreateStackTemporary(Vec.getValueType()); |
| 5005 | SDValue Ch = DAG.getStore(DAG.getEntryNode(), Vec, StackPtr, NULL, 0); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5006 | |
| 5007 | // Add the offset to the index. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5008 | unsigned EltSize = Op.getValueType().getSizeInBits()/8; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5009 | Idx = DAG.getNode(ISD::MUL, Idx.getValueType(), Idx, |
| 5010 | DAG.getConstant(EltSize, Idx.getValueType())); |
Bill Wendling | 90bfc2d | 2007-10-18 08:32:37 +0000 | [diff] [blame] | 5011 | |
Duncan Sands | 8e4eb09 | 2008-06-08 20:54:56 +0000 | [diff] [blame] | 5012 | if (Idx.getValueType().bitsGT(TLI.getPointerTy())) |
Chris Lattner | f185e67 | 2007-10-19 16:47:35 +0000 | [diff] [blame] | 5013 | Idx = DAG.getNode(ISD::TRUNCATE, TLI.getPointerTy(), Idx); |
Bill Wendling | 90bfc2d | 2007-10-18 08:32:37 +0000 | [diff] [blame] | 5014 | else |
Chris Lattner | f185e67 | 2007-10-19 16:47:35 +0000 | [diff] [blame] | 5015 | Idx = DAG.getNode(ISD::ZERO_EXTEND, TLI.getPointerTy(), Idx); |
Bill Wendling | 90bfc2d | 2007-10-18 08:32:37 +0000 | [diff] [blame] | 5016 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5017 | StackPtr = DAG.getNode(ISD::ADD, Idx.getValueType(), Idx, StackPtr); |
| 5018 | |
| 5019 | Op = DAG.getLoad(Op.getValueType(), Ch, StackPtr, NULL, 0); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 5020 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5021 | return Op; |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 5022 | } |
| 5023 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5024 | /// ExpandEXTRACT_SUBVECTOR - Expand a EXTRACT_SUBVECTOR operation. For now |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 5025 | /// 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] | 5026 | SDValue SelectionDAGLegalize::ExpandEXTRACT_SUBVECTOR(SDValue Op) { |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 5027 | // We know that operand #0 is the Vec vector. For now we assume the index |
| 5028 | // 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] | 5029 | SDValue Vec = Op.getOperand(0); |
| 5030 | SDValue Idx = LegalizeOp(Op.getOperand(1)); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 5031 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5032 | unsigned NumElems = Vec.getValueType().getVectorNumElements(); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 5033 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5034 | if (NumElems == Op.getValueType().getVectorNumElements()) { |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 5035 | // This must be an access of the desired vector length. Return it. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5036 | return Vec; |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 5037 | } |
| 5038 | |
| 5039 | ConstantSDNode *CIdx = cast<ConstantSDNode>(Idx); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5040 | SDValue Lo, Hi; |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 5041 | SplitVectorOp(Vec, Lo, Hi); |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 5042 | if (CIdx->getZExtValue() < NumElems/2) { |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 5043 | Vec = Lo; |
| 5044 | } else { |
| 5045 | Vec = Hi; |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 5046 | Idx = DAG.getConstant(CIdx->getZExtValue() - NumElems/2, |
| 5047 | Idx.getValueType()); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 5048 | } |
| 5049 | |
| 5050 | // It's now an extract from the appropriate high or low part. Recurse. |
| 5051 | Op = DAG.UpdateNodeOperands(Op, Vec, Idx); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5052 | return ExpandEXTRACT_SUBVECTOR(Op); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 5053 | } |
| 5054 | |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 5055 | /// LegalizeSetCCOperands - Attempts to create a legal LHS and RHS for a SETCC |
| 5056 | /// with condition CC on the current target. This usually involves legalizing |
| 5057 | /// or promoting the arguments. In the case where LHS and RHS must be expanded, |
| 5058 | /// there may be no choice but to create a new SetCC node to represent the |
| 5059 | /// 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] | 5060 | /// LHS, and the SDValue returned in RHS has a nil SDNode value. |
| 5061 | void SelectionDAGLegalize::LegalizeSetCCOperands(SDValue &LHS, |
| 5062 | SDValue &RHS, |
| 5063 | SDValue &CC) { |
| 5064 | SDValue Tmp1, Tmp2, Tmp3, Result; |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 5065 | |
| 5066 | switch (getTypeAction(LHS.getValueType())) { |
| 5067 | case Legal: |
| 5068 | Tmp1 = LegalizeOp(LHS); // LHS |
| 5069 | Tmp2 = LegalizeOp(RHS); // RHS |
| 5070 | break; |
| 5071 | case Promote: |
| 5072 | Tmp1 = PromoteOp(LHS); // LHS |
| 5073 | Tmp2 = PromoteOp(RHS); // RHS |
| 5074 | |
| 5075 | // If this is an FP compare, the operands have already been extended. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5076 | if (LHS.getValueType().isInteger()) { |
| 5077 | MVT VT = LHS.getValueType(); |
| 5078 | MVT NVT = TLI.getTypeToTransformTo(VT); |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 5079 | |
| 5080 | // Otherwise, we have to insert explicit sign or zero extends. Note |
| 5081 | // that we could insert sign extends for ALL conditions, but zero extend |
| 5082 | // is cheaper on many machines (an AND instead of two shifts), so prefer |
| 5083 | // it. |
| 5084 | switch (cast<CondCodeSDNode>(CC)->get()) { |
| 5085 | default: assert(0 && "Unknown integer comparison!"); |
| 5086 | case ISD::SETEQ: |
| 5087 | case ISD::SETNE: |
| 5088 | case ISD::SETUGE: |
| 5089 | case ISD::SETUGT: |
| 5090 | case ISD::SETULE: |
| 5091 | case ISD::SETULT: |
| 5092 | // ALL of these operations will work if we either sign or zero extend |
| 5093 | // the operands (including the unsigned comparisons!). Zero extend is |
| 5094 | // usually a simpler/cheaper operation, so prefer it. |
| 5095 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, VT); |
| 5096 | Tmp2 = DAG.getZeroExtendInReg(Tmp2, VT); |
| 5097 | break; |
| 5098 | case ISD::SETGE: |
| 5099 | case ISD::SETGT: |
| 5100 | case ISD::SETLT: |
| 5101 | case ISD::SETLE: |
| 5102 | Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp1, |
| 5103 | DAG.getValueType(VT)); |
| 5104 | Tmp2 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp2, |
| 5105 | DAG.getValueType(VT)); |
Evan Cheng | efa5339 | 2008-10-13 18:46:18 +0000 | [diff] [blame] | 5106 | Tmp1 = LegalizeOp(Tmp1); // Relegalize new nodes. |
| 5107 | Tmp2 = LegalizeOp(Tmp2); // Relegalize new nodes. |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 5108 | break; |
| 5109 | } |
| 5110 | } |
| 5111 | break; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5112 | case Expand: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5113 | MVT VT = LHS.getValueType(); |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5114 | if (VT == MVT::f32 || VT == MVT::f64) { |
| 5115 | // Expand into one or more soft-fp libcall(s). |
Evan Cheng | 6518c6e | 2008-07-01 21:35:46 +0000 | [diff] [blame] | 5116 | RTLIB::Libcall LC1 = RTLIB::UNKNOWN_LIBCALL, LC2 = RTLIB::UNKNOWN_LIBCALL; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5117 | switch (cast<CondCodeSDNode>(CC)->get()) { |
| 5118 | case ISD::SETEQ: |
| 5119 | case ISD::SETOEQ: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5120 | LC1 = (VT == MVT::f32) ? RTLIB::OEQ_F32 : RTLIB::OEQ_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5121 | break; |
| 5122 | case ISD::SETNE: |
| 5123 | case ISD::SETUNE: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5124 | LC1 = (VT == MVT::f32) ? RTLIB::UNE_F32 : RTLIB::UNE_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5125 | break; |
| 5126 | case ISD::SETGE: |
| 5127 | case ISD::SETOGE: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5128 | LC1 = (VT == MVT::f32) ? RTLIB::OGE_F32 : RTLIB::OGE_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5129 | break; |
| 5130 | case ISD::SETLT: |
| 5131 | case ISD::SETOLT: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5132 | LC1 = (VT == MVT::f32) ? RTLIB::OLT_F32 : RTLIB::OLT_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5133 | break; |
| 5134 | case ISD::SETLE: |
| 5135 | case ISD::SETOLE: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5136 | LC1 = (VT == MVT::f32) ? RTLIB::OLE_F32 : RTLIB::OLE_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5137 | break; |
| 5138 | case ISD::SETGT: |
| 5139 | case ISD::SETOGT: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5140 | LC1 = (VT == MVT::f32) ? RTLIB::OGT_F32 : RTLIB::OGT_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5141 | break; |
| 5142 | case ISD::SETUO: |
Evan Cheng | d385fd6 | 2007-01-31 09:29:11 +0000 | [diff] [blame] | 5143 | LC1 = (VT == MVT::f32) ? RTLIB::UO_F32 : RTLIB::UO_F64; |
| 5144 | break; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5145 | case ISD::SETO: |
Evan Cheng | 5efdecc | 2007-02-03 00:43:46 +0000 | [diff] [blame] | 5146 | LC1 = (VT == MVT::f32) ? RTLIB::O_F32 : RTLIB::O_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5147 | break; |
| 5148 | default: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5149 | LC1 = (VT == MVT::f32) ? RTLIB::UO_F32 : RTLIB::UO_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5150 | switch (cast<CondCodeSDNode>(CC)->get()) { |
| 5151 | case ISD::SETONE: |
| 5152 | // SETONE = SETOLT | SETOGT |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5153 | LC1 = (VT == MVT::f32) ? RTLIB::OLT_F32 : RTLIB::OLT_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5154 | // Fallthrough |
| 5155 | case ISD::SETUGT: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5156 | LC2 = (VT == MVT::f32) ? RTLIB::OGT_F32 : RTLIB::OGT_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5157 | break; |
| 5158 | case ISD::SETUGE: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5159 | LC2 = (VT == MVT::f32) ? RTLIB::OGE_F32 : RTLIB::OGE_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5160 | break; |
| 5161 | case ISD::SETULT: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5162 | LC2 = (VT == MVT::f32) ? RTLIB::OLT_F32 : RTLIB::OLT_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5163 | break; |
| 5164 | case ISD::SETULE: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5165 | LC2 = (VT == MVT::f32) ? RTLIB::OLE_F32 : RTLIB::OLE_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5166 | break; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5167 | case ISD::SETUEQ: |
| 5168 | LC2 = (VT == MVT::f32) ? RTLIB::OEQ_F32 : RTLIB::OEQ_F64; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5169 | break; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5170 | default: assert(0 && "Unsupported FP setcc!"); |
| 5171 | } |
| 5172 | } |
Duncan Sands | f951620 | 2008-06-30 10:19:09 +0000 | [diff] [blame] | 5173 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5174 | SDValue Dummy; |
| 5175 | SDValue Ops[2] = { LHS, RHS }; |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5176 | Tmp1 = ExpandLibCall(LC1, DAG.getMergeValues(Ops, 2).getNode(), |
Reid Spencer | b47b25c | 2007-01-03 04:22:32 +0000 | [diff] [blame] | 5177 | false /*sign irrelevant*/, Dummy); |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5178 | Tmp2 = DAG.getConstant(0, MVT::i32); |
Evan Cheng | d385fd6 | 2007-01-31 09:29:11 +0000 | [diff] [blame] | 5179 | CC = DAG.getCondCode(TLI.getCmpLibcallCC(LC1)); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5180 | if (LC2 != RTLIB::UNKNOWN_LIBCALL) { |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 5181 | Tmp1 = DAG.getNode(ISD::SETCC, |
| 5182 | TLI.getSetCCResultType(Tmp1.getValueType()), |
| 5183 | Tmp1, Tmp2, CC); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5184 | LHS = ExpandLibCall(LC2, DAG.getMergeValues(Ops, 2).getNode(), |
Reid Spencer | b47b25c | 2007-01-03 04:22:32 +0000 | [diff] [blame] | 5185 | false /*sign irrelevant*/, Dummy); |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 5186 | Tmp2 = DAG.getNode(ISD::SETCC, |
| 5187 | TLI.getSetCCResultType(LHS.getValueType()), LHS, |
| 5188 | Tmp2, DAG.getCondCode(TLI.getCmpLibcallCC(LC2))); |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5189 | Tmp1 = DAG.getNode(ISD::OR, Tmp1.getValueType(), Tmp1, Tmp2); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5190 | Tmp2 = SDValue(); |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5191 | } |
Evan Cheng | 21cacc4 | 2008-07-07 07:18:09 +0000 | [diff] [blame] | 5192 | LHS = LegalizeOp(Tmp1); |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5193 | RHS = Tmp2; |
| 5194 | return; |
| 5195 | } |
| 5196 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5197 | SDValue LHSLo, LHSHi, RHSLo, RHSHi; |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 5198 | ExpandOp(LHS, LHSLo, LHSHi); |
Dale Johannesen | 638ccd5 | 2007-10-06 01:24:11 +0000 | [diff] [blame] | 5199 | ExpandOp(RHS, RHSLo, RHSHi); |
| 5200 | ISD::CondCode CCCode = cast<CondCodeSDNode>(CC)->get(); |
| 5201 | |
| 5202 | if (VT==MVT::ppcf128) { |
| 5203 | // FIXME: This generated code sucks. We want to generate |
Dale Johannesen | e2f2083 | 2008-09-12 00:30:56 +0000 | [diff] [blame] | 5204 | // FCMPU crN, hi1, hi2 |
Dale Johannesen | 638ccd5 | 2007-10-06 01:24:11 +0000 | [diff] [blame] | 5205 | // BNE crN, L: |
Dale Johannesen | e2f2083 | 2008-09-12 00:30:56 +0000 | [diff] [blame] | 5206 | // FCMPU crN, lo1, lo2 |
Dale Johannesen | 638ccd5 | 2007-10-06 01:24:11 +0000 | [diff] [blame] | 5207 | // The following can be improved, but not that much. |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 5208 | Tmp1 = DAG.getSetCC(TLI.getSetCCResultType(LHSHi.getValueType()), |
| 5209 | LHSHi, RHSHi, ISD::SETOEQ); |
| 5210 | Tmp2 = DAG.getSetCC(TLI.getSetCCResultType(LHSLo.getValueType()), |
| 5211 | LHSLo, RHSLo, CCCode); |
Dale Johannesen | 638ccd5 | 2007-10-06 01:24:11 +0000 | [diff] [blame] | 5212 | Tmp3 = DAG.getNode(ISD::AND, Tmp1.getValueType(), Tmp1, Tmp2); |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 5213 | Tmp1 = DAG.getSetCC(TLI.getSetCCResultType(LHSHi.getValueType()), |
| 5214 | LHSHi, RHSHi, ISD::SETUNE); |
| 5215 | Tmp2 = DAG.getSetCC(TLI.getSetCCResultType(LHSHi.getValueType()), |
| 5216 | LHSHi, RHSHi, CCCode); |
Dale Johannesen | 638ccd5 | 2007-10-06 01:24:11 +0000 | [diff] [blame] | 5217 | Tmp1 = DAG.getNode(ISD::AND, Tmp1.getValueType(), Tmp1, Tmp2); |
| 5218 | Tmp1 = DAG.getNode(ISD::OR, Tmp1.getValueType(), Tmp1, Tmp3); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5219 | Tmp2 = SDValue(); |
Dale Johannesen | 638ccd5 | 2007-10-06 01:24:11 +0000 | [diff] [blame] | 5220 | break; |
| 5221 | } |
| 5222 | |
| 5223 | switch (CCCode) { |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 5224 | case ISD::SETEQ: |
| 5225 | case ISD::SETNE: |
| 5226 | if (RHSLo == RHSHi) |
| 5227 | if (ConstantSDNode *RHSCST = dyn_cast<ConstantSDNode>(RHSLo)) |
| 5228 | if (RHSCST->isAllOnesValue()) { |
| 5229 | // Comparison to -1. |
| 5230 | Tmp1 = DAG.getNode(ISD::AND, LHSLo.getValueType(), LHSLo, LHSHi); |
| 5231 | Tmp2 = RHSLo; |
| 5232 | break; |
| 5233 | } |
| 5234 | |
| 5235 | Tmp1 = DAG.getNode(ISD::XOR, LHSLo.getValueType(), LHSLo, RHSLo); |
| 5236 | Tmp2 = DAG.getNode(ISD::XOR, LHSLo.getValueType(), LHSHi, RHSHi); |
| 5237 | Tmp1 = DAG.getNode(ISD::OR, Tmp1.getValueType(), Tmp1, Tmp2); |
| 5238 | Tmp2 = DAG.getConstant(0, Tmp1.getValueType()); |
| 5239 | break; |
| 5240 | default: |
| 5241 | // If this is a comparison of the sign bit, just look at the top part. |
| 5242 | // X > -1, x < 0 |
| 5243 | if (ConstantSDNode *CST = dyn_cast<ConstantSDNode>(RHS)) |
| 5244 | if ((cast<CondCodeSDNode>(CC)->get() == ISD::SETLT && |
Dan Gohman | 002e5d0 | 2008-03-13 22:13:53 +0000 | [diff] [blame] | 5245 | CST->isNullValue()) || // X < 0 |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 5246 | (cast<CondCodeSDNode>(CC)->get() == ISD::SETGT && |
| 5247 | CST->isAllOnesValue())) { // X > -1 |
| 5248 | Tmp1 = LHSHi; |
| 5249 | Tmp2 = RHSHi; |
| 5250 | break; |
| 5251 | } |
| 5252 | |
| 5253 | // FIXME: This generated code sucks. |
| 5254 | ISD::CondCode LowCC; |
Evan Cheng | 2e67781 | 2007-02-08 22:16:19 +0000 | [diff] [blame] | 5255 | switch (CCCode) { |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 5256 | default: assert(0 && "Unknown integer setcc!"); |
| 5257 | case ISD::SETLT: |
| 5258 | case ISD::SETULT: LowCC = ISD::SETULT; break; |
| 5259 | case ISD::SETGT: |
| 5260 | case ISD::SETUGT: LowCC = ISD::SETUGT; break; |
| 5261 | case ISD::SETLE: |
| 5262 | case ISD::SETULE: LowCC = ISD::SETULE; break; |
| 5263 | case ISD::SETGE: |
| 5264 | case ISD::SETUGE: LowCC = ISD::SETUGE; break; |
| 5265 | } |
| 5266 | |
| 5267 | // Tmp1 = lo(op1) < lo(op2) // Always unsigned comparison |
| 5268 | // Tmp2 = hi(op1) < hi(op2) // Signedness depends on operands |
| 5269 | // dest = hi(op1) == hi(op2) ? Tmp1 : Tmp2; |
| 5270 | |
| 5271 | // NOTE: on targets without efficient SELECT of bools, we can always use |
| 5272 | // this identity: (B1 ? B2 : B3) --> (B1 & B2)|(!B1&B3) |
Evan Cheng | 2e67781 | 2007-02-08 22:16:19 +0000 | [diff] [blame] | 5273 | TargetLowering::DAGCombinerInfo DagCombineInfo(DAG, false, true, NULL); |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 5274 | Tmp1 = TLI.SimplifySetCC(TLI.getSetCCResultType(LHSLo.getValueType()), |
| 5275 | LHSLo, RHSLo, LowCC, false, DagCombineInfo); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5276 | if (!Tmp1.getNode()) |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 5277 | Tmp1 = DAG.getSetCC(TLI.getSetCCResultType(LHSLo.getValueType()), |
| 5278 | LHSLo, RHSLo, LowCC); |
| 5279 | Tmp2 = TLI.SimplifySetCC(TLI.getSetCCResultType(LHSHi.getValueType()), |
| 5280 | LHSHi, RHSHi, CCCode, false, DagCombineInfo); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5281 | if (!Tmp2.getNode()) |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 5282 | Tmp2 = DAG.getNode(ISD::SETCC, |
| 5283 | TLI.getSetCCResultType(LHSHi.getValueType()), |
| 5284 | LHSHi, RHSHi,CC); |
Evan Cheng | 2e67781 | 2007-02-08 22:16:19 +0000 | [diff] [blame] | 5285 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5286 | ConstantSDNode *Tmp1C = dyn_cast<ConstantSDNode>(Tmp1.getNode()); |
| 5287 | ConstantSDNode *Tmp2C = dyn_cast<ConstantSDNode>(Tmp2.getNode()); |
Dan Gohman | 002e5d0 | 2008-03-13 22:13:53 +0000 | [diff] [blame] | 5288 | if ((Tmp1C && Tmp1C->isNullValue()) || |
| 5289 | (Tmp2C && Tmp2C->isNullValue() && |
Evan Cheng | 2e67781 | 2007-02-08 22:16:19 +0000 | [diff] [blame] | 5290 | (CCCode == ISD::SETLE || CCCode == ISD::SETGE || |
| 5291 | CCCode == ISD::SETUGE || CCCode == ISD::SETULE)) || |
Dan Gohman | 002e5d0 | 2008-03-13 22:13:53 +0000 | [diff] [blame] | 5292 | (Tmp2C && Tmp2C->getAPIntValue() == 1 && |
Evan Cheng | 2e67781 | 2007-02-08 22:16:19 +0000 | [diff] [blame] | 5293 | (CCCode == ISD::SETLT || CCCode == ISD::SETGT || |
| 5294 | CCCode == ISD::SETUGT || CCCode == ISD::SETULT))) { |
| 5295 | // low part is known false, returns high part. |
| 5296 | // For LE / GE, if high part is known false, ignore the low part. |
| 5297 | // For LT / GT, if high part is known true, ignore the low part. |
| 5298 | Tmp1 = Tmp2; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5299 | Tmp2 = SDValue(); |
Evan Cheng | 2e67781 | 2007-02-08 22:16:19 +0000 | [diff] [blame] | 5300 | } else { |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 5301 | Result = TLI.SimplifySetCC(TLI.getSetCCResultType(LHSHi.getValueType()), |
| 5302 | LHSHi, RHSHi, ISD::SETEQ, false, |
| 5303 | DagCombineInfo); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5304 | if (!Result.getNode()) |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 5305 | Result=DAG.getSetCC(TLI.getSetCCResultType(LHSHi.getValueType()), |
| 5306 | LHSHi, RHSHi, ISD::SETEQ); |
Evan Cheng | 2e67781 | 2007-02-08 22:16:19 +0000 | [diff] [blame] | 5307 | Result = LegalizeOp(DAG.getNode(ISD::SELECT, Tmp1.getValueType(), |
| 5308 | Result, Tmp1, Tmp2)); |
| 5309 | Tmp1 = Result; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5310 | Tmp2 = SDValue(); |
Evan Cheng | 2e67781 | 2007-02-08 22:16:19 +0000 | [diff] [blame] | 5311 | } |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 5312 | } |
| 5313 | } |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5314 | } |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 5315 | LHS = Tmp1; |
| 5316 | RHS = Tmp2; |
| 5317 | } |
| 5318 | |
Evan Cheng | 7f04268 | 2008-10-15 02:05:31 +0000 | [diff] [blame] | 5319 | /// LegalizeSetCCCondCode - Legalize a SETCC with given LHS and RHS and |
| 5320 | /// condition code CC on the current target. This routine assumes LHS and rHS |
| 5321 | /// have already been legalized by LegalizeSetCCOperands. It expands SETCC with |
| 5322 | /// illegal condition code into AND / OR of multiple SETCC values. |
| 5323 | void SelectionDAGLegalize::LegalizeSetCCCondCode(MVT VT, |
| 5324 | SDValue &LHS, SDValue &RHS, |
| 5325 | SDValue &CC) { |
| 5326 | MVT OpVT = LHS.getValueType(); |
| 5327 | ISD::CondCode CCCode = cast<CondCodeSDNode>(CC)->get(); |
| 5328 | switch (TLI.getCondCodeAction(CCCode, OpVT)) { |
| 5329 | default: assert(0 && "Unknown condition code action!"); |
| 5330 | case TargetLowering::Legal: |
| 5331 | // Nothing to do. |
| 5332 | break; |
| 5333 | case TargetLowering::Expand: { |
| 5334 | ISD::CondCode CC1 = ISD::SETCC_INVALID, CC2 = ISD::SETCC_INVALID; |
| 5335 | unsigned Opc = 0; |
| 5336 | switch (CCCode) { |
| 5337 | default: assert(0 && "Don't know how to expand this condition!"); abort(); |
Dan Gohman | e7d238e | 2008-10-21 03:12:54 +0000 | [diff] [blame] | 5338 | case ISD::SETOEQ: CC1 = ISD::SETEQ; CC2 = ISD::SETO; Opc = ISD::AND; break; |
| 5339 | case ISD::SETOGT: CC1 = ISD::SETGT; CC2 = ISD::SETO; Opc = ISD::AND; break; |
| 5340 | case ISD::SETOGE: CC1 = ISD::SETGE; CC2 = ISD::SETO; Opc = ISD::AND; break; |
| 5341 | case ISD::SETOLT: CC1 = ISD::SETLT; CC2 = ISD::SETO; Opc = ISD::AND; break; |
| 5342 | case ISD::SETOLE: CC1 = ISD::SETLE; CC2 = ISD::SETO; Opc = ISD::AND; break; |
| 5343 | case ISD::SETONE: CC1 = ISD::SETNE; CC2 = ISD::SETO; Opc = ISD::AND; break; |
| 5344 | case ISD::SETUEQ: CC1 = ISD::SETEQ; CC2 = ISD::SETUO; Opc = ISD::OR; break; |
| 5345 | case ISD::SETUGT: CC1 = ISD::SETGT; CC2 = ISD::SETUO; Opc = ISD::OR; break; |
| 5346 | case ISD::SETUGE: CC1 = ISD::SETGE; CC2 = ISD::SETUO; Opc = ISD::OR; break; |
| 5347 | case ISD::SETULT: CC1 = ISD::SETLT; CC2 = ISD::SETUO; Opc = ISD::OR; break; |
| 5348 | case ISD::SETULE: CC1 = ISD::SETLE; CC2 = ISD::SETUO; Opc = ISD::OR; break; |
| 5349 | 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] | 5350 | // FIXME: Implement more expansions. |
| 5351 | } |
| 5352 | |
| 5353 | SDValue SetCC1 = DAG.getSetCC(VT, LHS, RHS, CC1); |
| 5354 | SDValue SetCC2 = DAG.getSetCC(VT, LHS, RHS, CC2); |
| 5355 | LHS = DAG.getNode(Opc, VT, SetCC1, SetCC2); |
| 5356 | RHS = SDValue(); |
| 5357 | CC = SDValue(); |
| 5358 | break; |
| 5359 | } |
| 5360 | } |
| 5361 | } |
| 5362 | |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 5363 | /// EmitStackConvert - Emit a store/load combination to the stack. This stores |
| 5364 | /// SrcOp to a stack slot of type SlotVT, truncating it if needed. It then does |
| 5365 | /// a load from the stack slot to DestVT, extending it if needed. |
| 5366 | /// The resultant code need not be legal. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5367 | SDValue SelectionDAGLegalize::EmitStackConvert(SDValue SrcOp, |
| 5368 | MVT SlotVT, |
| 5369 | MVT DestVT) { |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 5370 | // Create the stack frame object. |
Mon P Wang | 364d73d | 2008-07-05 20:40:31 +0000 | [diff] [blame] | 5371 | unsigned SrcAlign = TLI.getTargetData()->getPrefTypeAlignment( |
| 5372 | SrcOp.getValueType().getTypeForMVT()); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5373 | SDValue FIPtr = DAG.CreateStackTemporary(SlotVT, SrcAlign); |
Mon P Wang | 364d73d | 2008-07-05 20:40:31 +0000 | [diff] [blame] | 5374 | |
Dan Gohman | bbbbb9c | 2008-02-11 18:58:42 +0000 | [diff] [blame] | 5375 | FrameIndexSDNode *StackPtrFI = cast<FrameIndexSDNode>(FIPtr); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5376 | int SPFI = StackPtrFI->getIndex(); |
Mon P Wang | 364d73d | 2008-07-05 20:40:31 +0000 | [diff] [blame] | 5377 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5378 | unsigned SrcSize = SrcOp.getValueType().getSizeInBits(); |
| 5379 | unsigned SlotSize = SlotVT.getSizeInBits(); |
| 5380 | unsigned DestSize = DestVT.getSizeInBits(); |
Mon P Wang | 364d73d | 2008-07-05 20:40:31 +0000 | [diff] [blame] | 5381 | unsigned DestAlign = TLI.getTargetData()->getPrefTypeAlignment( |
| 5382 | DestVT.getTypeForMVT()); |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 5383 | |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 5384 | // Emit a store to the stack slot. Use a truncstore if the input value is |
| 5385 | // later than DestVT. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5386 | SDValue Store; |
Mon P Wang | 364d73d | 2008-07-05 20:40:31 +0000 | [diff] [blame] | 5387 | |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 5388 | if (SrcSize > SlotSize) |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5389 | Store = DAG.getTruncStore(DAG.getEntryNode(), SrcOp, FIPtr, |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 5390 | PseudoSourceValue::getFixedStack(SPFI), 0, |
| 5391 | SlotVT, false, SrcAlign); |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 5392 | else { |
| 5393 | assert(SrcSize == SlotSize && "Invalid store"); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5394 | Store = DAG.getStore(DAG.getEntryNode(), SrcOp, FIPtr, |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 5395 | PseudoSourceValue::getFixedStack(SPFI), 0, |
Mon P Wang | 364d73d | 2008-07-05 20:40:31 +0000 | [diff] [blame] | 5396 | false, SrcAlign); |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 5397 | } |
| 5398 | |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 5399 | // Result is a load from the stack slot. |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 5400 | if (SlotSize == DestSize) |
Mon P Wang | 364d73d | 2008-07-05 20:40:31 +0000 | [diff] [blame] | 5401 | return DAG.getLoad(DestVT, Store, FIPtr, NULL, 0, false, DestAlign); |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 5402 | |
| 5403 | assert(SlotSize < DestSize && "Unknown extension!"); |
Mon P Wang | 364d73d | 2008-07-05 20:40:31 +0000 | [diff] [blame] | 5404 | return DAG.getExtLoad(ISD::EXTLOAD, DestVT, Store, FIPtr, NULL, 0, SlotVT, |
| 5405 | false, DestAlign); |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 5406 | } |
| 5407 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5408 | SDValue SelectionDAGLegalize::ExpandSCALAR_TO_VECTOR(SDNode *Node) { |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 5409 | // Create a vector sized/aligned stack slot, store the value to element #0, |
| 5410 | // then load the whole vector back out. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5411 | SDValue StackPtr = DAG.CreateStackTemporary(Node->getValueType(0)); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5412 | |
Dan Gohman | bbbbb9c | 2008-02-11 18:58:42 +0000 | [diff] [blame] | 5413 | FrameIndexSDNode *StackPtrFI = cast<FrameIndexSDNode>(StackPtr); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5414 | int SPFI = StackPtrFI->getIndex(); |
| 5415 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5416 | SDValue Ch = DAG.getStore(DAG.getEntryNode(), Node->getOperand(0), StackPtr, |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 5417 | PseudoSourceValue::getFixedStack(SPFI), 0); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5418 | return DAG.getLoad(Node->getValueType(0), Ch, StackPtr, |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 5419 | PseudoSourceValue::getFixedStack(SPFI), 0); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 5420 | } |
| 5421 | |
| 5422 | |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5423 | /// ExpandBUILD_VECTOR - Expand a BUILD_VECTOR node on targets that don't |
Dan Gohman | 07a9676 | 2007-07-16 14:29:03 +0000 | [diff] [blame] | 5424 | /// support the operation, but do support the resultant vector type. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5425 | SDValue SelectionDAGLegalize::ExpandBUILD_VECTOR(SDNode *Node) { |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5426 | |
| 5427 | // 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] | 5428 | // 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] | 5429 | unsigned NumElems = Node->getNumOperands(); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5430 | bool isOnlyLowElement = true; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5431 | SDValue SplatValue = Node->getOperand(0); |
Chris Lattner | f9d95c8 | 2008-03-09 00:29:42 +0000 | [diff] [blame] | 5432 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5433 | // 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] | 5434 | // and use a bitmask instead of a list of elements. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5435 | std::map<SDValue, std::vector<unsigned> > Values; |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 5436 | Values[SplatValue].push_back(0); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 5437 | bool isConstant = true; |
| 5438 | if (!isa<ConstantFPSDNode>(SplatValue) && !isa<ConstantSDNode>(SplatValue) && |
| 5439 | SplatValue.getOpcode() != ISD::UNDEF) |
| 5440 | isConstant = false; |
| 5441 | |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 5442 | for (unsigned i = 1; i < NumElems; ++i) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5443 | SDValue V = Node->getOperand(i); |
Chris Lattner | 89a1b38 | 2006-04-19 23:17:50 +0000 | [diff] [blame] | 5444 | Values[V].push_back(i); |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 5445 | if (V.getOpcode() != ISD::UNDEF) |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5446 | isOnlyLowElement = false; |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 5447 | if (SplatValue != V) |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5448 | SplatValue = SDValue(0,0); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 5449 | |
| 5450 | // If this isn't a constant element or an undef, we can't use a constant |
| 5451 | // pool load. |
| 5452 | if (!isa<ConstantFPSDNode>(V) && !isa<ConstantSDNode>(V) && |
| 5453 | V.getOpcode() != ISD::UNDEF) |
| 5454 | isConstant = false; |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5455 | } |
| 5456 | |
| 5457 | if (isOnlyLowElement) { |
| 5458 | // If the low element is an undef too, then this whole things is an undef. |
| 5459 | if (Node->getOperand(0).getOpcode() == ISD::UNDEF) |
| 5460 | return DAG.getNode(ISD::UNDEF, Node->getValueType(0)); |
| 5461 | // Otherwise, turn this into a scalar_to_vector node. |
| 5462 | return DAG.getNode(ISD::SCALAR_TO_VECTOR, Node->getValueType(0), |
| 5463 | Node->getOperand(0)); |
| 5464 | } |
| 5465 | |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 5466 | // If all elements are constants, create a load from the constant pool. |
| 5467 | if (isConstant) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5468 | MVT VT = Node->getValueType(0); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 5469 | std::vector<Constant*> CV; |
| 5470 | for (unsigned i = 0, e = NumElems; i != e; ++i) { |
| 5471 | if (ConstantFPSDNode *V = |
| 5472 | dyn_cast<ConstantFPSDNode>(Node->getOperand(i))) { |
Dan Gohman | 4fbd796 | 2008-09-12 18:08:03 +0000 | [diff] [blame] | 5473 | CV.push_back(const_cast<ConstantFP *>(V->getConstantFPValue())); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 5474 | } else if (ConstantSDNode *V = |
Chris Lattner | 02a260a | 2008-04-20 00:41:09 +0000 | [diff] [blame] | 5475 | dyn_cast<ConstantSDNode>(Node->getOperand(i))) { |
Dan Gohman | 4fbd796 | 2008-09-12 18:08:03 +0000 | [diff] [blame] | 5476 | CV.push_back(const_cast<ConstantInt *>(V->getConstantIntValue())); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 5477 | } else { |
| 5478 | assert(Node->getOperand(i).getOpcode() == ISD::UNDEF); |
Chris Lattner | 02a260a | 2008-04-20 00:41:09 +0000 | [diff] [blame] | 5479 | const Type *OpNTy = |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5480 | Node->getOperand(0).getValueType().getTypeForMVT(); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 5481 | CV.push_back(UndefValue::get(OpNTy)); |
| 5482 | } |
| 5483 | } |
Reid Spencer | 9d6565a | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 5484 | Constant *CP = ConstantVector::get(CV); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5485 | SDValue CPIdx = DAG.getConstantPool(CP, TLI.getPointerTy()); |
Dan Gohman | 50284d8 | 2008-09-16 22:05:41 +0000 | [diff] [blame] | 5486 | unsigned Alignment = 1 << cast<ConstantPoolSDNode>(CPIdx)->getAlignment(); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5487 | return DAG.getLoad(VT, DAG.getEntryNode(), CPIdx, |
Dan Gohman | 50284d8 | 2008-09-16 22:05:41 +0000 | [diff] [blame] | 5488 | PseudoSourceValue::getConstantPool(), 0, |
| 5489 | false, Alignment); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 5490 | } |
| 5491 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5492 | if (SplatValue.getNode()) { // Splat of one value? |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 5493 | // Build the shuffle constant vector: <0, 0, 0, 0> |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5494 | MVT MaskVT = MVT::getIntVectorWithNumElements(NumElems); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5495 | SDValue Zero = DAG.getConstant(0, MaskVT.getVectorElementType()); |
| 5496 | std::vector<SDValue> ZeroVec(NumElems, Zero); |
| 5497 | SDValue SplatMask = DAG.getNode(ISD::BUILD_VECTOR, MaskVT, |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 5498 | &ZeroVec[0], ZeroVec.size()); |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 5499 | |
| 5500 | // If the target supports VECTOR_SHUFFLE and this shuffle mask, use it. |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 5501 | if (isShuffleLegal(Node->getValueType(0), SplatMask)) { |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 5502 | // Get the splatted value into the low element of a vector register. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5503 | SDValue LowValVec = |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 5504 | DAG.getNode(ISD::SCALAR_TO_VECTOR, Node->getValueType(0), SplatValue); |
| 5505 | |
| 5506 | // Return shuffle(LowValVec, undef, <0,0,0,0>) |
| 5507 | return DAG.getNode(ISD::VECTOR_SHUFFLE, Node->getValueType(0), LowValVec, |
| 5508 | DAG.getNode(ISD::UNDEF, Node->getValueType(0)), |
| 5509 | SplatMask); |
| 5510 | } |
| 5511 | } |
| 5512 | |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 5513 | // If there are only two unique elements, we may be able to turn this into a |
| 5514 | // vector shuffle. |
| 5515 | if (Values.size() == 2) { |
Chris Lattner | f9d95c8 | 2008-03-09 00:29:42 +0000 | [diff] [blame] | 5516 | // Get the two values in deterministic order. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5517 | SDValue Val1 = Node->getOperand(1); |
| 5518 | SDValue Val2; |
| 5519 | std::map<SDValue, std::vector<unsigned> >::iterator MI = Values.begin(); |
Chris Lattner | f9d95c8 | 2008-03-09 00:29:42 +0000 | [diff] [blame] | 5520 | if (MI->first != Val1) |
| 5521 | Val2 = MI->first; |
| 5522 | else |
| 5523 | Val2 = (++MI)->first; |
| 5524 | |
| 5525 | // If Val1 is an undef, make sure end ends up as Val2, to ensure that our |
| 5526 | // vector shuffle has the undef vector on the RHS. |
| 5527 | if (Val1.getOpcode() == ISD::UNDEF) |
| 5528 | std::swap(Val1, Val2); |
| 5529 | |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 5530 | // Build the shuffle constant vector: e.g. <0, 4, 0, 4> |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5531 | MVT MaskVT = MVT::getIntVectorWithNumElements(NumElems); |
| 5532 | MVT MaskEltVT = MaskVT.getVectorElementType(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5533 | std::vector<SDValue> MaskVec(NumElems); |
Chris Lattner | f9d95c8 | 2008-03-09 00:29:42 +0000 | [diff] [blame] | 5534 | |
| 5535 | // Set elements of the shuffle mask for Val1. |
| 5536 | std::vector<unsigned> &Val1Elts = Values[Val1]; |
| 5537 | for (unsigned i = 0, e = Val1Elts.size(); i != e; ++i) |
| 5538 | MaskVec[Val1Elts[i]] = DAG.getConstant(0, MaskEltVT); |
| 5539 | |
| 5540 | // Set elements of the shuffle mask for Val2. |
| 5541 | std::vector<unsigned> &Val2Elts = Values[Val2]; |
| 5542 | for (unsigned i = 0, e = Val2Elts.size(); i != e; ++i) |
| 5543 | if (Val2.getOpcode() != ISD::UNDEF) |
| 5544 | MaskVec[Val2Elts[i]] = DAG.getConstant(NumElems, MaskEltVT); |
| 5545 | else |
| 5546 | MaskVec[Val2Elts[i]] = DAG.getNode(ISD::UNDEF, MaskEltVT); |
| 5547 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5548 | SDValue ShuffleMask = DAG.getNode(ISD::BUILD_VECTOR, MaskVT, |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 5549 | &MaskVec[0], MaskVec.size()); |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 5550 | |
Chris Lattner | f9d95c8 | 2008-03-09 00:29:42 +0000 | [diff] [blame] | 5551 | // 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] | 5552 | if (TLI.isOperationLegal(ISD::SCALAR_TO_VECTOR, Node->getValueType(0)) && |
| 5553 | isShuffleLegal(Node->getValueType(0), ShuffleMask)) { |
Chris Lattner | f9d95c8 | 2008-03-09 00:29:42 +0000 | [diff] [blame] | 5554 | Val1 = DAG.getNode(ISD::SCALAR_TO_VECTOR, Node->getValueType(0), Val1); |
| 5555 | Val2 = DAG.getNode(ISD::SCALAR_TO_VECTOR, Node->getValueType(0), Val2); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5556 | SDValue Ops[] = { Val1, Val2, ShuffleMask }; |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 5557 | |
| 5558 | // Return shuffle(LoValVec, HiValVec, <0,1,0,1>) |
Chris Lattner | f9d95c8 | 2008-03-09 00:29:42 +0000 | [diff] [blame] | 5559 | return DAG.getNode(ISD::VECTOR_SHUFFLE, Node->getValueType(0), Ops, 3); |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 5560 | } |
| 5561 | } |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5562 | |
| 5563 | // Otherwise, we can't handle this case efficiently. Allocate a sufficiently |
| 5564 | // aligned object on the stack, store each element into it, then load |
| 5565 | // the result as a vector. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5566 | MVT VT = Node->getValueType(0); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5567 | // Create the stack frame object. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5568 | SDValue FIPtr = DAG.CreateStackTemporary(VT); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5569 | |
| 5570 | // Emit a store of each element to the stack slot. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5571 | SmallVector<SDValue, 8> Stores; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5572 | unsigned TypeByteSize = Node->getOperand(0).getValueType().getSizeInBits()/8; |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5573 | // Store (in the right endianness) the elements to memory. |
| 5574 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) { |
| 5575 | // Ignore undef elements. |
| 5576 | if (Node->getOperand(i).getOpcode() == ISD::UNDEF) continue; |
| 5577 | |
Chris Lattner | 841c882 | 2006-03-22 01:46:54 +0000 | [diff] [blame] | 5578 | unsigned Offset = TypeByteSize*i; |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5579 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5580 | SDValue Idx = DAG.getConstant(Offset, FIPtr.getValueType()); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5581 | Idx = DAG.getNode(ISD::ADD, FIPtr.getValueType(), FIPtr, Idx); |
| 5582 | |
Evan Cheng | 786225a | 2006-10-05 23:01:46 +0000 | [diff] [blame] | 5583 | Stores.push_back(DAG.getStore(DAG.getEntryNode(), Node->getOperand(i), Idx, |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 5584 | NULL, 0)); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5585 | } |
| 5586 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5587 | SDValue StoreChain; |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5588 | if (!Stores.empty()) // Not all undef elements? |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 5589 | StoreChain = DAG.getNode(ISD::TokenFactor, MVT::Other, |
| 5590 | &Stores[0], Stores.size()); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5591 | else |
| 5592 | StoreChain = DAG.getEntryNode(); |
| 5593 | |
| 5594 | // Result is a load from the stack slot. |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 5595 | return DAG.getLoad(VT, StoreChain, FIPtr, NULL, 0); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5596 | } |
| 5597 | |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 5598 | void SelectionDAGLegalize::ExpandShiftParts(unsigned NodeOp, |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5599 | SDValue Op, SDValue Amt, |
| 5600 | SDValue &Lo, SDValue &Hi) { |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 5601 | // Expand the subcomponents. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5602 | SDValue LHSL, LHSH; |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 5603 | ExpandOp(Op, LHSL, LHSH); |
| 5604 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5605 | SDValue Ops[] = { LHSL, LHSH, Amt }; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5606 | MVT VT = LHSL.getValueType(); |
Chris Lattner | f9f37fc | 2006-08-14 23:53:35 +0000 | [diff] [blame] | 5607 | Lo = DAG.getNode(NodeOp, DAG.getNodeValueTypes(VT, VT), 2, Ops, 3); |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 5608 | Hi = Lo.getValue(1); |
| 5609 | } |
| 5610 | |
| 5611 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5612 | /// ExpandShift - Try to find a clever way to expand this shift operation out to |
| 5613 | /// smaller elements. If we can't find a way that is more efficient than a |
| 5614 | /// libcall on this target, return false. Otherwise, return true with the |
| 5615 | /// low-parts expanded into Lo and Hi. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5616 | bool SelectionDAGLegalize::ExpandShift(unsigned Opc, SDValue Op,SDValue Amt, |
| 5617 | SDValue &Lo, SDValue &Hi) { |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5618 | assert((Opc == ISD::SHL || Opc == ISD::SRA || Opc == ISD::SRL) && |
| 5619 | "This is not a shift!"); |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5620 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5621 | MVT NVT = TLI.getTypeToTransformTo(Op.getValueType()); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5622 | SDValue ShAmt = LegalizeOp(Amt); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5623 | MVT ShTy = ShAmt.getValueType(); |
| 5624 | unsigned ShBits = ShTy.getSizeInBits(); |
| 5625 | unsigned VTBits = Op.getValueType().getSizeInBits(); |
| 5626 | unsigned NVTBits = NVT.getSizeInBits(); |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5627 | |
Chris Lattner | 7a3c855 | 2007-10-14 20:35:12 +0000 | [diff] [blame] | 5628 | // Handle the case when Amt is an immediate. |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5629 | if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Amt.getNode())) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 5630 | unsigned Cst = CN->getZExtValue(); |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5631 | // 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] | 5632 | SDValue InL, InH; |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5633 | ExpandOp(Op, InL, InH); |
| 5634 | switch(Opc) { |
| 5635 | case ISD::SHL: |
| 5636 | if (Cst > VTBits) { |
| 5637 | Lo = DAG.getConstant(0, NVT); |
| 5638 | Hi = DAG.getConstant(0, NVT); |
| 5639 | } else if (Cst > NVTBits) { |
| 5640 | Lo = DAG.getConstant(0, NVT); |
| 5641 | Hi = DAG.getNode(ISD::SHL, NVT, InL, DAG.getConstant(Cst-NVTBits,ShTy)); |
Chris Lattner | ee27f57 | 2005-04-11 20:08:52 +0000 | [diff] [blame] | 5642 | } else if (Cst == NVTBits) { |
| 5643 | Lo = DAG.getConstant(0, NVT); |
| 5644 | Hi = InL; |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5645 | } else { |
| 5646 | Lo = DAG.getNode(ISD::SHL, NVT, InL, DAG.getConstant(Cst, ShTy)); |
| 5647 | Hi = DAG.getNode(ISD::OR, NVT, |
| 5648 | DAG.getNode(ISD::SHL, NVT, InH, DAG.getConstant(Cst, ShTy)), |
| 5649 | DAG.getNode(ISD::SRL, NVT, InL, DAG.getConstant(NVTBits-Cst, ShTy))); |
| 5650 | } |
| 5651 | return true; |
| 5652 | case ISD::SRL: |
| 5653 | if (Cst > VTBits) { |
| 5654 | Lo = DAG.getConstant(0, NVT); |
| 5655 | Hi = DAG.getConstant(0, NVT); |
| 5656 | } else if (Cst > NVTBits) { |
| 5657 | Lo = DAG.getNode(ISD::SRL, NVT, InH, DAG.getConstant(Cst-NVTBits,ShTy)); |
| 5658 | Hi = DAG.getConstant(0, NVT); |
Chris Lattner | ee27f57 | 2005-04-11 20:08:52 +0000 | [diff] [blame] | 5659 | } else if (Cst == NVTBits) { |
| 5660 | Lo = InH; |
| 5661 | Hi = DAG.getConstant(0, NVT); |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5662 | } else { |
| 5663 | Lo = DAG.getNode(ISD::OR, NVT, |
| 5664 | DAG.getNode(ISD::SRL, NVT, InL, DAG.getConstant(Cst, ShTy)), |
| 5665 | DAG.getNode(ISD::SHL, NVT, InH, DAG.getConstant(NVTBits-Cst, ShTy))); |
| 5666 | Hi = DAG.getNode(ISD::SRL, NVT, InH, DAG.getConstant(Cst, ShTy)); |
| 5667 | } |
| 5668 | return true; |
| 5669 | case ISD::SRA: |
| 5670 | if (Cst > VTBits) { |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 5671 | Hi = Lo = DAG.getNode(ISD::SRA, NVT, InH, |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5672 | DAG.getConstant(NVTBits-1, ShTy)); |
| 5673 | } else if (Cst > NVTBits) { |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 5674 | Lo = DAG.getNode(ISD::SRA, NVT, InH, |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5675 | DAG.getConstant(Cst-NVTBits, ShTy)); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 5676 | Hi = DAG.getNode(ISD::SRA, NVT, InH, |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5677 | DAG.getConstant(NVTBits-1, ShTy)); |
Chris Lattner | ee27f57 | 2005-04-11 20:08:52 +0000 | [diff] [blame] | 5678 | } else if (Cst == NVTBits) { |
| 5679 | Lo = InH; |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 5680 | Hi = DAG.getNode(ISD::SRA, NVT, InH, |
Chris Lattner | ee27f57 | 2005-04-11 20:08:52 +0000 | [diff] [blame] | 5681 | DAG.getConstant(NVTBits-1, ShTy)); |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5682 | } else { |
| 5683 | Lo = DAG.getNode(ISD::OR, NVT, |
| 5684 | DAG.getNode(ISD::SRL, NVT, InL, DAG.getConstant(Cst, ShTy)), |
| 5685 | DAG.getNode(ISD::SHL, NVT, InH, DAG.getConstant(NVTBits-Cst, ShTy))); |
| 5686 | Hi = DAG.getNode(ISD::SRA, NVT, InH, DAG.getConstant(Cst, ShTy)); |
| 5687 | } |
| 5688 | return true; |
| 5689 | } |
| 5690 | } |
Chris Lattner | 0ea26ca | 2006-09-20 03:38:48 +0000 | [diff] [blame] | 5691 | |
| 5692 | // Okay, the shift amount isn't constant. However, if we can tell that it is |
| 5693 | // >= 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] | 5694 | APInt Mask = APInt::getHighBitsSet(ShBits, ShBits - Log2_32(NVTBits)); |
| 5695 | APInt KnownZero, KnownOne; |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 5696 | DAG.ComputeMaskedBits(Amt, Mask, KnownZero, KnownOne); |
Chris Lattner | 0ea26ca | 2006-09-20 03:38:48 +0000 | [diff] [blame] | 5697 | |
Dan Gohman | 9e255b7 | 2008-02-22 01:12:31 +0000 | [diff] [blame] | 5698 | // If we know that if any of the high bits of the shift amount are one, then |
| 5699 | // we can do this as a couple of simple shifts. |
Dan Gohman | 91dc17b | 2008-02-20 16:57:27 +0000 | [diff] [blame] | 5700 | if (KnownOne.intersects(Mask)) { |
Chris Lattner | 0ea26ca | 2006-09-20 03:38:48 +0000 | [diff] [blame] | 5701 | // Mask out the high bit, which we know is set. |
| 5702 | Amt = DAG.getNode(ISD::AND, Amt.getValueType(), Amt, |
Dan Gohman | 91dc17b | 2008-02-20 16:57:27 +0000 | [diff] [blame] | 5703 | DAG.getConstant(~Mask, Amt.getValueType())); |
Chris Lattner | 0ea26ca | 2006-09-20 03:38:48 +0000 | [diff] [blame] | 5704 | |
| 5705 | // 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] | 5706 | SDValue InL, InH; |
Chris Lattner | 0ea26ca | 2006-09-20 03:38:48 +0000 | [diff] [blame] | 5707 | ExpandOp(Op, InL, InH); |
| 5708 | switch(Opc) { |
| 5709 | case ISD::SHL: |
| 5710 | Lo = DAG.getConstant(0, NVT); // Low part is zero. |
| 5711 | Hi = DAG.getNode(ISD::SHL, NVT, InL, Amt); // High part from Lo part. |
| 5712 | return true; |
| 5713 | case ISD::SRL: |
| 5714 | Hi = DAG.getConstant(0, NVT); // Hi part is zero. |
| 5715 | Lo = DAG.getNode(ISD::SRL, NVT, InH, Amt); // Lo part from Hi part. |
| 5716 | return true; |
| 5717 | case ISD::SRA: |
| 5718 | Hi = DAG.getNode(ISD::SRA, NVT, InH, // Sign extend high part. |
| 5719 | DAG.getConstant(NVTBits-1, Amt.getValueType())); |
| 5720 | Lo = DAG.getNode(ISD::SRA, NVT, InH, Amt); // Lo part from Hi part. |
| 5721 | return true; |
| 5722 | } |
| 5723 | } |
| 5724 | |
Dan Gohman | 9e255b7 | 2008-02-22 01:12:31 +0000 | [diff] [blame] | 5725 | // If we know that the high bits of the shift amount are all zero, then we can |
| 5726 | // do this as a couple of simple shifts. |
| 5727 | if ((KnownZero & Mask) == Mask) { |
Chris Lattner | 0ea26ca | 2006-09-20 03:38:48 +0000 | [diff] [blame] | 5728 | // Compute 32-amt. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5729 | SDValue Amt2 = DAG.getNode(ISD::SUB, Amt.getValueType(), |
Chris Lattner | 0ea26ca | 2006-09-20 03:38:48 +0000 | [diff] [blame] | 5730 | DAG.getConstant(NVTBits, Amt.getValueType()), |
| 5731 | Amt); |
| 5732 | |
| 5733 | // 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] | 5734 | SDValue InL, InH; |
Chris Lattner | 0ea26ca | 2006-09-20 03:38:48 +0000 | [diff] [blame] | 5735 | ExpandOp(Op, InL, InH); |
| 5736 | switch(Opc) { |
| 5737 | case ISD::SHL: |
| 5738 | Lo = DAG.getNode(ISD::SHL, NVT, InL, Amt); |
| 5739 | Hi = DAG.getNode(ISD::OR, NVT, |
| 5740 | DAG.getNode(ISD::SHL, NVT, InH, Amt), |
| 5741 | DAG.getNode(ISD::SRL, NVT, InL, Amt2)); |
| 5742 | return true; |
| 5743 | case ISD::SRL: |
| 5744 | Hi = DAG.getNode(ISD::SRL, NVT, InH, Amt); |
| 5745 | Lo = DAG.getNode(ISD::OR, NVT, |
| 5746 | DAG.getNode(ISD::SRL, NVT, InL, Amt), |
| 5747 | DAG.getNode(ISD::SHL, NVT, InH, Amt2)); |
| 5748 | return true; |
| 5749 | case ISD::SRA: |
| 5750 | Hi = DAG.getNode(ISD::SRA, NVT, InH, Amt); |
| 5751 | Lo = DAG.getNode(ISD::OR, NVT, |
| 5752 | DAG.getNode(ISD::SRL, NVT, InL, Amt), |
| 5753 | DAG.getNode(ISD::SHL, NVT, InH, Amt2)); |
| 5754 | return true; |
| 5755 | } |
| 5756 | } |
| 5757 | |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5758 | return false; |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5759 | } |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5760 | |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 5761 | |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5762 | // ExpandLibCall - Expand a node into a call to a libcall. If the result value |
| 5763 | // does not fit into a register, return the lo part and set the hi part to the |
| 5764 | // by-reg argument. If it does fit into a single register, return the result |
| 5765 | // and leave the Hi part unset. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5766 | SDValue SelectionDAGLegalize::ExpandLibCall(RTLIB::Libcall LC, SDNode *Node, |
| 5767 | bool isSigned, SDValue &Hi) { |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 5768 | assert(!IsLegalizingCall && "Cannot overlap legalization of calls!"); |
| 5769 | // The input chain to this libcall is the entry node of the function. |
| 5770 | // Legalizing the call will automatically add the previous call to the |
| 5771 | // dependence. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5772 | SDValue InChain = DAG.getEntryNode(); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 5773 | |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5774 | TargetLowering::ArgListTy Args; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 5775 | TargetLowering::ArgListEntry Entry; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5776 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5777 | MVT ArgVT = Node->getOperand(i).getValueType(); |
| 5778 | const Type *ArgTy = ArgVT.getTypeForMVT(); |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 5779 | Entry.Node = Node->getOperand(i); Entry.Ty = ArgTy; |
Anton Korobeynikov | d0b82b3 | 2007-03-07 16:25:09 +0000 | [diff] [blame] | 5780 | Entry.isSExt = isSigned; |
Duncan Sands | 00fee65 | 2008-02-14 17:28:50 +0000 | [diff] [blame] | 5781 | Entry.isZExt = !isSigned; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 5782 | Args.push_back(Entry); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5783 | } |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 5784 | SDValue Callee = DAG.getExternalSymbol(TLI.getLibcallName(LC), |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 5785 | TLI.getPointerTy()); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 5786 | |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 5787 | // Splice the libcall in wherever FindInputOutputChains tells us to. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5788 | const Type *RetTy = Node->getValueType(0).getTypeForMVT(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5789 | std::pair<SDValue,SDValue> CallInfo = |
Dale Johannesen | 86098bd | 2008-09-26 19:31:26 +0000 | [diff] [blame] | 5790 | TLI.LowerCallTo(InChain, RetTy, isSigned, !isSigned, false, false, |
| 5791 | CallingConv::C, false, Callee, Args, DAG); |
Chris Lattner | b9fa3bc | 2005-05-12 04:49:08 +0000 | [diff] [blame] | 5792 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 5793 | // Legalize the call sequence, starting with the chain. This will advance |
| 5794 | // the LastCALLSEQ_END to the legalized version of the CALLSEQ_END node that |
| 5795 | // was added by LowerCallTo (guaranteeing proper serialization of calls). |
| 5796 | LegalizeOp(CallInfo.second); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5797 | SDValue Result; |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 5798 | switch (getTypeAction(CallInfo.first.getValueType())) { |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5799 | default: assert(0 && "Unknown thing"); |
| 5800 | case Legal: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 5801 | Result = CallInfo.first; |
Chris Lattner | 99c25b8 | 2005-09-02 20:26:58 +0000 | [diff] [blame] | 5802 | break; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5803 | case Expand: |
Chris Lattner | 99c25b8 | 2005-09-02 20:26:58 +0000 | [diff] [blame] | 5804 | ExpandOp(CallInfo.first, Result, Hi); |
Chris Lattner | 99c25b8 | 2005-09-02 20:26:58 +0000 | [diff] [blame] | 5805 | break; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5806 | } |
Chris Lattner | 99c25b8 | 2005-09-02 20:26:58 +0000 | [diff] [blame] | 5807 | return Result; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5808 | } |
| 5809 | |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 5810 | /// LegalizeINT_TO_FP - Legalize a [US]INT_TO_FP operation. |
| 5811 | /// |
| 5812 | SDValue SelectionDAGLegalize:: |
| 5813 | LegalizeINT_TO_FP(SDValue Result, bool isSigned, MVT DestTy, SDValue Op) { |
| 5814 | bool isCustom = false; |
| 5815 | SDValue Tmp1; |
| 5816 | switch (getTypeAction(Op.getValueType())) { |
| 5817 | case Legal: |
| 5818 | switch (TLI.getOperationAction(isSigned ? ISD::SINT_TO_FP : ISD::UINT_TO_FP, |
| 5819 | Op.getValueType())) { |
| 5820 | default: assert(0 && "Unknown operation action!"); |
| 5821 | case TargetLowering::Custom: |
| 5822 | isCustom = true; |
| 5823 | // FALLTHROUGH |
| 5824 | case TargetLowering::Legal: |
| 5825 | Tmp1 = LegalizeOp(Op); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5826 | if (Result.getNode()) |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 5827 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 5828 | else |
| 5829 | Result = DAG.getNode(isSigned ? ISD::SINT_TO_FP : ISD::UINT_TO_FP, |
| 5830 | DestTy, Tmp1); |
| 5831 | if (isCustom) { |
| 5832 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5833 | if (Tmp1.getNode()) Result = Tmp1; |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 5834 | } |
| 5835 | break; |
| 5836 | case TargetLowering::Expand: |
| 5837 | Result = ExpandLegalINT_TO_FP(isSigned, LegalizeOp(Op), DestTy); |
| 5838 | break; |
| 5839 | case TargetLowering::Promote: |
| 5840 | Result = PromoteLegalINT_TO_FP(LegalizeOp(Op), DestTy, isSigned); |
| 5841 | break; |
| 5842 | } |
| 5843 | break; |
| 5844 | case Expand: |
| 5845 | Result = ExpandIntToFP(isSigned, DestTy, Op); |
| 5846 | break; |
| 5847 | case Promote: |
| 5848 | Tmp1 = PromoteOp(Op); |
| 5849 | if (isSigned) { |
| 5850 | Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, Tmp1.getValueType(), |
| 5851 | Tmp1, DAG.getValueType(Op.getValueType())); |
| 5852 | } else { |
| 5853 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, |
| 5854 | Op.getValueType()); |
| 5855 | } |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5856 | if (Result.getNode()) |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 5857 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 5858 | else |
| 5859 | Result = DAG.getNode(isSigned ? ISD::SINT_TO_FP : ISD::UINT_TO_FP, |
| 5860 | DestTy, Tmp1); |
| 5861 | Result = LegalizeOp(Result); // The 'op' is not necessarily legal! |
| 5862 | break; |
| 5863 | } |
| 5864 | return Result; |
| 5865 | } |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 5866 | |
Evan Cheng | 4c6cfad | 2007-04-27 07:33:31 +0000 | [diff] [blame] | 5867 | /// ExpandIntToFP - Expand a [US]INT_TO_FP operation. |
| 5868 | /// |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5869 | SDValue SelectionDAGLegalize:: |
| 5870 | ExpandIntToFP(bool isSigned, MVT DestTy, SDValue Source) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5871 | MVT SourceVT = Source.getValueType(); |
Dan Gohman | 034f60e | 2008-03-11 01:59:03 +0000 | [diff] [blame] | 5872 | bool ExpandSource = getTypeAction(SourceVT) == Expand; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5873 | |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 5874 | // Expand unsupported int-to-fp vector casts by unrolling them. |
| 5875 | if (DestTy.isVector()) { |
| 5876 | if (!ExpandSource) |
| 5877 | return LegalizeOp(UnrollVectorOp(Source)); |
| 5878 | MVT DestEltTy = DestTy.getVectorElementType(); |
| 5879 | if (DestTy.getVectorNumElements() == 1) { |
| 5880 | SDValue Scalar = ScalarizeVectorOp(Source); |
| 5881 | SDValue Result = LegalizeINT_TO_FP(SDValue(), isSigned, |
| 5882 | DestEltTy, Scalar); |
| 5883 | return DAG.getNode(ISD::BUILD_VECTOR, DestTy, Result); |
| 5884 | } |
| 5885 | SDValue Lo, Hi; |
| 5886 | SplitVectorOp(Source, Lo, Hi); |
| 5887 | MVT SplitDestTy = MVT::getVectorVT(DestEltTy, |
| 5888 | DestTy.getVectorNumElements() / 2); |
| 5889 | SDValue LoResult = LegalizeINT_TO_FP(SDValue(), isSigned, SplitDestTy, Lo); |
| 5890 | SDValue HiResult = LegalizeINT_TO_FP(SDValue(), isSigned, SplitDestTy, Hi); |
Evan Cheng | efa5339 | 2008-10-13 18:46:18 +0000 | [diff] [blame] | 5891 | return LegalizeOp(DAG.getNode(ISD::CONCAT_VECTORS, DestTy, LoResult, |
| 5892 | HiResult)); |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 5893 | } |
| 5894 | |
Evan Cheng | 9845eb5 | 2008-04-01 02:18:22 +0000 | [diff] [blame] | 5895 | // Special case for i32 source to take advantage of UINTTOFP_I32_F32, etc. |
| 5896 | if (!isSigned && SourceVT != MVT::i32) { |
Dan Gohman | 34bc178 | 2008-03-05 02:07:31 +0000 | [diff] [blame] | 5897 | // 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] | 5898 | // incoming integer is set. To handle this, we dynamically test to see if |
| 5899 | // it is set, and, if so, add a fudge factor. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5900 | SDValue Hi; |
Dan Gohman | 034f60e | 2008-03-11 01:59:03 +0000 | [diff] [blame] | 5901 | if (ExpandSource) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5902 | SDValue Lo; |
Dan Gohman | 034f60e | 2008-03-11 01:59:03 +0000 | [diff] [blame] | 5903 | ExpandOp(Source, Lo, Hi); |
| 5904 | Source = DAG.getNode(ISD::BUILD_PAIR, SourceVT, Lo, Hi); |
| 5905 | } else { |
| 5906 | // The comparison for the sign bit will use the entire operand. |
| 5907 | Hi = Source; |
| 5908 | } |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 5909 | |
Dale Johannesen | 53997b0 | 2008-11-04 20:52:49 +0000 | [diff] [blame] | 5910 | // Check to see if the target has a custom way to lower this. If so, use |
| 5911 | // it. (Note we've already expanded the operand in this case.) |
Dale Johannesen | 1c15bf5 | 2008-10-21 20:50:01 +0000 | [diff] [blame] | 5912 | switch (TLI.getOperationAction(ISD::UINT_TO_FP, SourceVT)) { |
| 5913 | default: assert(0 && "This action not implemented for this operation!"); |
| 5914 | case TargetLowering::Legal: |
| 5915 | case TargetLowering::Expand: |
| 5916 | break; // This case is handled below. |
| 5917 | case TargetLowering::Custom: { |
| 5918 | SDValue NV = TLI.LowerOperation(DAG.getNode(ISD::UINT_TO_FP, DestTy, |
| 5919 | Source), DAG); |
| 5920 | if (NV.getNode()) |
| 5921 | return LegalizeOp(NV); |
| 5922 | break; // The target decided this was legal after all |
| 5923 | } |
| 5924 | } |
| 5925 | |
Chris Lattner | 66de05b | 2005-05-13 04:45:13 +0000 | [diff] [blame] | 5926 | // If this is unsigned, and not supported, first perform the conversion to |
| 5927 | // signed, then adjust the result if the sign bit is set. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5928 | SDValue SignedConv = ExpandIntToFP(true, DestTy, Source); |
Chris Lattner | 66de05b | 2005-05-13 04:45:13 +0000 | [diff] [blame] | 5929 | |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 5930 | SDValue SignSet = DAG.getSetCC(TLI.getSetCCResultType(Hi.getValueType()), |
| 5931 | Hi, DAG.getConstant(0, Hi.getValueType()), |
| 5932 | ISD::SETLT); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5933 | SDValue Zero = DAG.getIntPtrConstant(0), Four = DAG.getIntPtrConstant(4); |
| 5934 | SDValue CstOffset = DAG.getNode(ISD::SELECT, Zero.getValueType(), |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 5935 | SignSet, Four, Zero); |
Chris Lattner | 383203b | 2005-05-12 18:52:34 +0000 | [diff] [blame] | 5936 | uint64_t FF = 0x5f800000ULL; |
| 5937 | if (TLI.isLittleEndian()) FF <<= 32; |
Dan Gohman | 34bc178 | 2008-03-05 02:07:31 +0000 | [diff] [blame] | 5938 | static Constant *FudgeFactor = ConstantInt::get(Type::Int64Ty, FF); |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 5939 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5940 | SDValue CPIdx = DAG.getConstantPool(FudgeFactor, TLI.getPointerTy()); |
Dan Gohman | 50284d8 | 2008-09-16 22:05:41 +0000 | [diff] [blame] | 5941 | unsigned Alignment = 1 << cast<ConstantPoolSDNode>(CPIdx)->getAlignment(); |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 5942 | CPIdx = DAG.getNode(ISD::ADD, TLI.getPointerTy(), CPIdx, CstOffset); |
Dan Gohman | 87a0f10 | 2008-09-22 22:40:08 +0000 | [diff] [blame] | 5943 | Alignment = std::min(Alignment, 4u); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5944 | SDValue FudgeInReg; |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 5945 | if (DestTy == MVT::f32) |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5946 | FudgeInReg = DAG.getLoad(MVT::f32, DAG.getEntryNode(), CPIdx, |
Dan Gohman | 50284d8 | 2008-09-16 22:05:41 +0000 | [diff] [blame] | 5947 | PseudoSourceValue::getConstantPool(), 0, |
| 5948 | false, Alignment); |
Duncan Sands | 8e4eb09 | 2008-06-08 20:54:56 +0000 | [diff] [blame] | 5949 | else if (DestTy.bitsGT(MVT::f32)) |
Evan Cheng | 4c6cfad | 2007-04-27 07:33:31 +0000 | [diff] [blame] | 5950 | // FIXME: Avoid the extend by construction the right constantpool? |
Dale Johannesen | 118cd9d | 2007-09-16 16:51:49 +0000 | [diff] [blame] | 5951 | FudgeInReg = DAG.getExtLoad(ISD::EXTLOAD, DestTy, DAG.getEntryNode(), |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5952 | CPIdx, |
Dan Gohman | 3069b87 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 5953 | PseudoSourceValue::getConstantPool(), 0, |
Dan Gohman | 50284d8 | 2008-09-16 22:05:41 +0000 | [diff] [blame] | 5954 | MVT::f32, false, Alignment); |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 5955 | else |
| 5956 | assert(0 && "Unexpected conversion"); |
| 5957 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5958 | MVT SCVT = SignedConv.getValueType(); |
Evan Cheng | 4c6cfad | 2007-04-27 07:33:31 +0000 | [diff] [blame] | 5959 | if (SCVT != DestTy) { |
| 5960 | // Destination type needs to be expanded as well. The FADD now we are |
| 5961 | // constructing will be expanded into a libcall. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5962 | if (SCVT.getSizeInBits() != DestTy.getSizeInBits()) { |
| 5963 | assert(SCVT.getSizeInBits() * 2 == DestTy.getSizeInBits()); |
Dan Gohman | d91446d | 2008-03-05 01:08:17 +0000 | [diff] [blame] | 5964 | SignedConv = DAG.getNode(ISD::BUILD_PAIR, DestTy, |
Evan Cheng | 4c6cfad | 2007-04-27 07:33:31 +0000 | [diff] [blame] | 5965 | SignedConv, SignedConv.getValue(1)); |
| 5966 | } |
| 5967 | SignedConv = DAG.getNode(ISD::BIT_CONVERT, DestTy, SignedConv); |
| 5968 | } |
Chris Lattner | 473a990 | 2005-09-29 06:44:39 +0000 | [diff] [blame] | 5969 | return DAG.getNode(ISD::FADD, DestTy, SignedConv, FudgeInReg); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5970 | } |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 5971 | |
Chris Lattner | a88a260 | 2005-05-14 05:33:54 +0000 | [diff] [blame] | 5972 | // 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] | 5973 | switch (TLI.getOperationAction(ISD::SINT_TO_FP, SourceVT)) { |
Chris Lattner | a88a260 | 2005-05-14 05:33:54 +0000 | [diff] [blame] | 5974 | default: assert(0 && "This action not implemented for this operation!"); |
| 5975 | case TargetLowering::Legal: |
| 5976 | case TargetLowering::Expand: |
| 5977 | break; // This case is handled below. |
Chris Lattner | 07dffd6 | 2005-08-26 00:14:16 +0000 | [diff] [blame] | 5978 | case TargetLowering::Custom: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5979 | SDValue NV = TLI.LowerOperation(DAG.getNode(ISD::SINT_TO_FP, DestTy, |
Chris Lattner | 07dffd6 | 2005-08-26 00:14:16 +0000 | [diff] [blame] | 5980 | Source), DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5981 | if (NV.getNode()) |
Chris Lattner | 07dffd6 | 2005-08-26 00:14:16 +0000 | [diff] [blame] | 5982 | return LegalizeOp(NV); |
| 5983 | break; // The target decided this was legal after all |
| 5984 | } |
Chris Lattner | a88a260 | 2005-05-14 05:33:54 +0000 | [diff] [blame] | 5985 | } |
| 5986 | |
Chris Lattner | 13689e2 | 2005-05-12 07:00:44 +0000 | [diff] [blame] | 5987 | // Expand the source, then glue it back together for the call. We must expand |
| 5988 | // 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] | 5989 | if (ExpandSource) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5990 | SDValue SrcLo, SrcHi; |
Dan Gohman | 034f60e | 2008-03-11 01:59:03 +0000 | [diff] [blame] | 5991 | ExpandOp(Source, SrcLo, SrcHi); |
| 5992 | Source = DAG.getNode(ISD::BUILD_PAIR, SourceVT, SrcLo, SrcHi); |
| 5993 | } |
Chris Lattner | 13689e2 | 2005-05-12 07:00:44 +0000 | [diff] [blame] | 5994 | |
Duncan Sands | b2ff885 | 2008-07-17 02:36:29 +0000 | [diff] [blame] | 5995 | RTLIB::Libcall LC = isSigned ? |
| 5996 | RTLIB::getSINTTOFP(SourceVT, DestTy) : |
| 5997 | RTLIB::getUINTTOFP(SourceVT, DestTy); |
| 5998 | assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unknown int value type"); |
| 5999 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 6000 | Source = DAG.getNode(ISD::SINT_TO_FP, DestTy, Source); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6001 | SDValue HiPart; |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6002 | SDValue Result = ExpandLibCall(LC, Source.getNode(), isSigned, HiPart); |
| 6003 | if (Result.getValueType() != DestTy && HiPart.getNode()) |
Dan Gohman | a2e9485 | 2008-03-10 23:03:31 +0000 | [diff] [blame] | 6004 | Result = DAG.getNode(ISD::BUILD_PAIR, DestTy, Result, HiPart); |
| 6005 | return Result; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 6006 | } |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 6007 | |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6008 | /// ExpandLegalINT_TO_FP - This function is responsible for legalizing a |
| 6009 | /// INT_TO_FP operation of the specified operand when the target requests that |
| 6010 | /// we expand it. At this point, we know that the result and operand types are |
| 6011 | /// legal for the target. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6012 | SDValue SelectionDAGLegalize::ExpandLegalINT_TO_FP(bool isSigned, |
| 6013 | SDValue Op0, |
| 6014 | MVT DestVT) { |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6015 | if (Op0.getValueType() == MVT::i32) { |
| 6016 | // simple 32-bit [signed|unsigned] integer to float/double expansion |
| 6017 | |
Chris Lattner | 23594d4 | 2008-01-16 07:03:22 +0000 | [diff] [blame] | 6018 | // Get the stack frame index of a 8 byte buffer. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6019 | SDValue StackSlot = DAG.CreateStackTemporary(MVT::f64); |
Chris Lattner | 23594d4 | 2008-01-16 07:03:22 +0000 | [diff] [blame] | 6020 | |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6021 | // word offset constant for Hi/Lo address computation |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6022 | SDValue WordOff = DAG.getConstant(sizeof(int), TLI.getPointerTy()); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6023 | // set up Hi and Lo (into buffer) address based on endian |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6024 | SDValue Hi = StackSlot; |
| 6025 | SDValue Lo = DAG.getNode(ISD::ADD, TLI.getPointerTy(), StackSlot,WordOff); |
Chris Lattner | 408c428 | 2006-03-23 05:29:04 +0000 | [diff] [blame] | 6026 | if (TLI.isLittleEndian()) |
| 6027 | std::swap(Hi, Lo); |
| 6028 | |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6029 | // if signed map to unsigned space |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6030 | SDValue Op0Mapped; |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6031 | if (isSigned) { |
| 6032 | // constant used to invert sign bit (signed to unsigned mapping) |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6033 | SDValue SignBit = DAG.getConstant(0x80000000u, MVT::i32); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6034 | Op0Mapped = DAG.getNode(ISD::XOR, MVT::i32, Op0, SignBit); |
| 6035 | } else { |
| 6036 | Op0Mapped = Op0; |
| 6037 | } |
| 6038 | // store the lo of the constructed double - based on integer input |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6039 | SDValue Store1 = DAG.getStore(DAG.getEntryNode(), |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 6040 | Op0Mapped, Lo, NULL, 0); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6041 | // initial hi portion of constructed double |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6042 | SDValue InitialHi = DAG.getConstant(0x43300000u, MVT::i32); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6043 | // store the hi of the constructed double - biased exponent |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6044 | SDValue Store2=DAG.getStore(Store1, InitialHi, Hi, NULL, 0); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6045 | // load the constructed double |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6046 | SDValue Load = DAG.getLoad(MVT::f64, Store2, StackSlot, NULL, 0); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6047 | // FP constant to bias correct the final result |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6048 | SDValue Bias = DAG.getConstantFP(isSigned ? |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6049 | BitsToDouble(0x4330000080000000ULL) |
| 6050 | : BitsToDouble(0x4330000000000000ULL), |
| 6051 | MVT::f64); |
| 6052 | // subtract the bias |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6053 | SDValue Sub = DAG.getNode(ISD::FSUB, MVT::f64, Load, Bias); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6054 | // final result |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6055 | SDValue Result; |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6056 | // handle final rounding |
| 6057 | if (DestVT == MVT::f64) { |
| 6058 | // do nothing |
| 6059 | Result = Sub; |
Duncan Sands | 8e4eb09 | 2008-06-08 20:54:56 +0000 | [diff] [blame] | 6060 | } else if (DestVT.bitsLT(MVT::f64)) { |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 6061 | Result = DAG.getNode(ISD::FP_ROUND, DestVT, Sub, |
| 6062 | DAG.getIntPtrConstant(0)); |
Duncan Sands | 8e4eb09 | 2008-06-08 20:54:56 +0000 | [diff] [blame] | 6063 | } else if (DestVT.bitsGT(MVT::f64)) { |
Dale Johannesen | 118cd9d | 2007-09-16 16:51:49 +0000 | [diff] [blame] | 6064 | Result = DAG.getNode(ISD::FP_EXTEND, DestVT, Sub); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6065 | } |
| 6066 | return Result; |
| 6067 | } |
| 6068 | assert(!isSigned && "Legalize cannot Expand SINT_TO_FP for i64 yet"); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6069 | SDValue Tmp1 = DAG.getNode(ISD::SINT_TO_FP, DestVT, Op0); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6070 | |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 6071 | SDValue SignSet = DAG.getSetCC(TLI.getSetCCResultType(Op0.getValueType()), |
| 6072 | Op0, DAG.getConstant(0, Op0.getValueType()), |
| 6073 | ISD::SETLT); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6074 | SDValue Zero = DAG.getIntPtrConstant(0), Four = DAG.getIntPtrConstant(4); |
| 6075 | SDValue CstOffset = DAG.getNode(ISD::SELECT, Zero.getValueType(), |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6076 | SignSet, Four, Zero); |
| 6077 | |
| 6078 | // If the sign bit of the integer is set, the large number will be treated |
| 6079 | // as a negative number. To counteract this, the dynamic code adds an |
| 6080 | // offset depending on the data type. |
| 6081 | uint64_t FF; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6082 | switch (Op0.getValueType().getSimpleVT()) { |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6083 | default: assert(0 && "Unsupported integer type!"); |
| 6084 | case MVT::i8 : FF = 0x43800000ULL; break; // 2^8 (as a float) |
| 6085 | case MVT::i16: FF = 0x47800000ULL; break; // 2^16 (as a float) |
| 6086 | case MVT::i32: FF = 0x4F800000ULL; break; // 2^32 (as a float) |
| 6087 | case MVT::i64: FF = 0x5F800000ULL; break; // 2^64 (as a float) |
| 6088 | } |
| 6089 | if (TLI.isLittleEndian()) FF <<= 32; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 6090 | static Constant *FudgeFactor = ConstantInt::get(Type::Int64Ty, FF); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6091 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6092 | SDValue CPIdx = DAG.getConstantPool(FudgeFactor, TLI.getPointerTy()); |
Dan Gohman | 50284d8 | 2008-09-16 22:05:41 +0000 | [diff] [blame] | 6093 | unsigned Alignment = 1 << cast<ConstantPoolSDNode>(CPIdx)->getAlignment(); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6094 | CPIdx = DAG.getNode(ISD::ADD, TLI.getPointerTy(), CPIdx, CstOffset); |
Dan Gohman | 87a0f10 | 2008-09-22 22:40:08 +0000 | [diff] [blame] | 6095 | Alignment = std::min(Alignment, 4u); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6096 | SDValue FudgeInReg; |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6097 | if (DestVT == MVT::f32) |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 6098 | FudgeInReg = DAG.getLoad(MVT::f32, DAG.getEntryNode(), CPIdx, |
Dan Gohman | 50284d8 | 2008-09-16 22:05:41 +0000 | [diff] [blame] | 6099 | PseudoSourceValue::getConstantPool(), 0, |
| 6100 | false, Alignment); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6101 | else { |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 6102 | FudgeInReg = |
| 6103 | LegalizeOp(DAG.getExtLoad(ISD::EXTLOAD, DestVT, |
| 6104 | DAG.getEntryNode(), CPIdx, |
Dan Gohman | 3069b87 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 6105 | PseudoSourceValue::getConstantPool(), 0, |
Dan Gohman | 50284d8 | 2008-09-16 22:05:41 +0000 | [diff] [blame] | 6106 | MVT::f32, false, Alignment)); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6107 | } |
| 6108 | |
| 6109 | return DAG.getNode(ISD::FADD, DestVT, Tmp1, FudgeInReg); |
| 6110 | } |
| 6111 | |
| 6112 | /// PromoteLegalINT_TO_FP - This function is responsible for legalizing a |
| 6113 | /// *INT_TO_FP operation of the specified operand when the target requests that |
| 6114 | /// we promote it. At this point, we know that the result and operand types are |
| 6115 | /// legal for the target, and that there is a legal UINT_TO_FP or SINT_TO_FP |
| 6116 | /// operation that takes a larger input. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6117 | SDValue SelectionDAGLegalize::PromoteLegalINT_TO_FP(SDValue LegalOp, |
| 6118 | MVT DestVT, |
| 6119 | bool isSigned) { |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6120 | // First step, figure out the appropriate *INT_TO_FP operation to use. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6121 | MVT NewInTy = LegalOp.getValueType(); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6122 | |
| 6123 | unsigned OpToUse = 0; |
| 6124 | |
| 6125 | // Scan for the appropriate larger type to use. |
| 6126 | while (1) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6127 | NewInTy = (MVT::SimpleValueType)(NewInTy.getSimpleVT()+1); |
| 6128 | assert(NewInTy.isInteger() && "Ran out of possibilities!"); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6129 | |
| 6130 | // If the target supports SINT_TO_FP of this type, use it. |
| 6131 | switch (TLI.getOperationAction(ISD::SINT_TO_FP, NewInTy)) { |
| 6132 | default: break; |
| 6133 | case TargetLowering::Legal: |
| 6134 | if (!TLI.isTypeLegal(NewInTy)) |
| 6135 | break; // Can't use this datatype. |
| 6136 | // FALL THROUGH. |
| 6137 | case TargetLowering::Custom: |
| 6138 | OpToUse = ISD::SINT_TO_FP; |
| 6139 | break; |
| 6140 | } |
| 6141 | if (OpToUse) break; |
| 6142 | if (isSigned) continue; |
| 6143 | |
| 6144 | // If the target supports UINT_TO_FP of this type, use it. |
| 6145 | switch (TLI.getOperationAction(ISD::UINT_TO_FP, NewInTy)) { |
| 6146 | default: break; |
| 6147 | case TargetLowering::Legal: |
| 6148 | if (!TLI.isTypeLegal(NewInTy)) |
| 6149 | break; // Can't use this datatype. |
| 6150 | // FALL THROUGH. |
| 6151 | case TargetLowering::Custom: |
| 6152 | OpToUse = ISD::UINT_TO_FP; |
| 6153 | break; |
| 6154 | } |
| 6155 | if (OpToUse) break; |
| 6156 | |
| 6157 | // Otherwise, try a larger type. |
| 6158 | } |
| 6159 | |
| 6160 | // Okay, we found the operation and type to use. Zero extend our input to the |
| 6161 | // desired type then run the operation on it. |
| 6162 | return DAG.getNode(OpToUse, DestVT, |
| 6163 | DAG.getNode(isSigned ? ISD::SIGN_EXTEND : ISD::ZERO_EXTEND, |
| 6164 | NewInTy, LegalOp)); |
| 6165 | } |
| 6166 | |
| 6167 | /// PromoteLegalFP_TO_INT - This function is responsible for legalizing a |
| 6168 | /// FP_TO_*INT operation of the specified operand when the target requests that |
| 6169 | /// we promote it. At this point, we know that the result and operand types are |
| 6170 | /// legal for the target, and that there is a legal FP_TO_UINT or FP_TO_SINT |
| 6171 | /// operation that returns a larger result. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6172 | SDValue SelectionDAGLegalize::PromoteLegalFP_TO_INT(SDValue LegalOp, |
| 6173 | MVT DestVT, |
| 6174 | bool isSigned) { |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6175 | // First step, figure out the appropriate FP_TO*INT operation to use. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6176 | MVT NewOutTy = DestVT; |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6177 | |
| 6178 | unsigned OpToUse = 0; |
| 6179 | |
| 6180 | // Scan for the appropriate larger type to use. |
| 6181 | while (1) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6182 | NewOutTy = (MVT::SimpleValueType)(NewOutTy.getSimpleVT()+1); |
| 6183 | assert(NewOutTy.isInteger() && "Ran out of possibilities!"); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6184 | |
| 6185 | // If the target supports FP_TO_SINT returning this type, use it. |
| 6186 | switch (TLI.getOperationAction(ISD::FP_TO_SINT, NewOutTy)) { |
| 6187 | default: break; |
| 6188 | case TargetLowering::Legal: |
| 6189 | if (!TLI.isTypeLegal(NewOutTy)) |
| 6190 | break; // Can't use this datatype. |
| 6191 | // FALL THROUGH. |
| 6192 | case TargetLowering::Custom: |
| 6193 | OpToUse = ISD::FP_TO_SINT; |
| 6194 | break; |
| 6195 | } |
| 6196 | if (OpToUse) break; |
| 6197 | |
| 6198 | // If the target supports FP_TO_UINT of this type, use it. |
| 6199 | switch (TLI.getOperationAction(ISD::FP_TO_UINT, NewOutTy)) { |
| 6200 | default: break; |
| 6201 | case TargetLowering::Legal: |
| 6202 | if (!TLI.isTypeLegal(NewOutTy)) |
| 6203 | break; // Can't use this datatype. |
| 6204 | // FALL THROUGH. |
| 6205 | case TargetLowering::Custom: |
| 6206 | OpToUse = ISD::FP_TO_UINT; |
| 6207 | break; |
| 6208 | } |
| 6209 | if (OpToUse) break; |
| 6210 | |
| 6211 | // Otherwise, try a larger type. |
| 6212 | } |
| 6213 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6214 | |
| 6215 | // Okay, we found the operation and type to use. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6216 | SDValue Operation = DAG.getNode(OpToUse, NewOutTy, LegalOp); |
Duncan Sands | 126d907 | 2008-07-04 11:47:58 +0000 | [diff] [blame] | 6217 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6218 | // If the operation produces an invalid type, it must be custom lowered. Use |
| 6219 | // the target lowering hooks to expand it. Just keep the low part of the |
| 6220 | // expanded operation, we know that we're truncating anyway. |
| 6221 | if (getTypeAction(NewOutTy) == Expand) { |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 6222 | SmallVector<SDValue, 2> Results; |
| 6223 | TLI.ReplaceNodeResults(Operation.getNode(), Results, DAG); |
| 6224 | assert(Results.size() == 1 && "Incorrect FP_TO_XINT lowering!"); |
| 6225 | Operation = Results[0]; |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6226 | } |
Duncan Sands | 126d907 | 2008-07-04 11:47:58 +0000 | [diff] [blame] | 6227 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6228 | // Truncate the result of the extended FP_TO_*INT operation to the desired |
| 6229 | // size. |
| 6230 | return DAG.getNode(ISD::TRUNCATE, DestVT, Operation); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6231 | } |
| 6232 | |
| 6233 | /// ExpandBSWAP - Open code the operations for BSWAP of the specified operation. |
| 6234 | /// |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6235 | SDValue SelectionDAGLegalize::ExpandBSWAP(SDValue Op) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6236 | MVT VT = Op.getValueType(); |
| 6237 | MVT SHVT = TLI.getShiftAmountTy(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6238 | SDValue Tmp1, Tmp2, Tmp3, Tmp4, Tmp5, Tmp6, Tmp7, Tmp8; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6239 | switch (VT.getSimpleVT()) { |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6240 | default: assert(0 && "Unhandled Expand type in BSWAP!"); abort(); |
| 6241 | case MVT::i16: |
| 6242 | Tmp2 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(8, SHVT)); |
| 6243 | Tmp1 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(8, SHVT)); |
| 6244 | return DAG.getNode(ISD::OR, VT, Tmp1, Tmp2); |
| 6245 | case MVT::i32: |
| 6246 | Tmp4 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(24, SHVT)); |
| 6247 | Tmp3 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(8, SHVT)); |
| 6248 | Tmp2 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(8, SHVT)); |
| 6249 | Tmp1 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(24, SHVT)); |
| 6250 | Tmp3 = DAG.getNode(ISD::AND, VT, Tmp3, DAG.getConstant(0xFF0000, VT)); |
| 6251 | Tmp2 = DAG.getNode(ISD::AND, VT, Tmp2, DAG.getConstant(0xFF00, VT)); |
| 6252 | Tmp4 = DAG.getNode(ISD::OR, VT, Tmp4, Tmp3); |
| 6253 | Tmp2 = DAG.getNode(ISD::OR, VT, Tmp2, Tmp1); |
| 6254 | return DAG.getNode(ISD::OR, VT, Tmp4, Tmp2); |
| 6255 | case MVT::i64: |
| 6256 | Tmp8 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(56, SHVT)); |
| 6257 | Tmp7 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(40, SHVT)); |
| 6258 | Tmp6 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(24, SHVT)); |
| 6259 | Tmp5 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(8, SHVT)); |
| 6260 | Tmp4 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(8, SHVT)); |
| 6261 | Tmp3 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(24, SHVT)); |
| 6262 | Tmp2 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(40, SHVT)); |
| 6263 | Tmp1 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(56, SHVT)); |
| 6264 | Tmp7 = DAG.getNode(ISD::AND, VT, Tmp7, DAG.getConstant(255ULL<<48, VT)); |
| 6265 | Tmp6 = DAG.getNode(ISD::AND, VT, Tmp6, DAG.getConstant(255ULL<<40, VT)); |
| 6266 | Tmp5 = DAG.getNode(ISD::AND, VT, Tmp5, DAG.getConstant(255ULL<<32, VT)); |
| 6267 | Tmp4 = DAG.getNode(ISD::AND, VT, Tmp4, DAG.getConstant(255ULL<<24, VT)); |
| 6268 | Tmp3 = DAG.getNode(ISD::AND, VT, Tmp3, DAG.getConstant(255ULL<<16, VT)); |
| 6269 | Tmp2 = DAG.getNode(ISD::AND, VT, Tmp2, DAG.getConstant(255ULL<<8 , VT)); |
| 6270 | Tmp8 = DAG.getNode(ISD::OR, VT, Tmp8, Tmp7); |
| 6271 | Tmp6 = DAG.getNode(ISD::OR, VT, Tmp6, Tmp5); |
| 6272 | Tmp4 = DAG.getNode(ISD::OR, VT, Tmp4, Tmp3); |
| 6273 | Tmp2 = DAG.getNode(ISD::OR, VT, Tmp2, Tmp1); |
| 6274 | Tmp8 = DAG.getNode(ISD::OR, VT, Tmp8, Tmp6); |
| 6275 | Tmp4 = DAG.getNode(ISD::OR, VT, Tmp4, Tmp2); |
| 6276 | return DAG.getNode(ISD::OR, VT, Tmp8, Tmp4); |
| 6277 | } |
| 6278 | } |
| 6279 | |
| 6280 | /// ExpandBitCount - Expand the specified bitcount instruction into operations. |
| 6281 | /// |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6282 | SDValue SelectionDAGLegalize::ExpandBitCount(unsigned Opc, SDValue Op) { |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6283 | switch (Opc) { |
| 6284 | default: assert(0 && "Cannot expand this yet!"); |
| 6285 | case ISD::CTPOP: { |
| 6286 | static const uint64_t mask[6] = { |
| 6287 | 0x5555555555555555ULL, 0x3333333333333333ULL, |
| 6288 | 0x0F0F0F0F0F0F0F0FULL, 0x00FF00FF00FF00FFULL, |
| 6289 | 0x0000FFFF0000FFFFULL, 0x00000000FFFFFFFFULL |
| 6290 | }; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6291 | MVT VT = Op.getValueType(); |
| 6292 | MVT ShVT = TLI.getShiftAmountTy(); |
| 6293 | unsigned len = VT.getSizeInBits(); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6294 | for (unsigned i = 0; (1U << i) <= (len / 2); ++i) { |
| 6295 | //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] | 6296 | SDValue Tmp2 = DAG.getConstant(mask[i], VT); |
| 6297 | SDValue Tmp3 = DAG.getConstant(1ULL << i, ShVT); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6298 | Op = DAG.getNode(ISD::ADD, VT, DAG.getNode(ISD::AND, VT, Op, Tmp2), |
| 6299 | DAG.getNode(ISD::AND, VT, |
| 6300 | DAG.getNode(ISD::SRL, VT, Op, Tmp3),Tmp2)); |
| 6301 | } |
| 6302 | return Op; |
| 6303 | } |
| 6304 | case ISD::CTLZ: { |
| 6305 | // for now, we do this: |
| 6306 | // x = x | (x >> 1); |
| 6307 | // x = x | (x >> 2); |
| 6308 | // ... |
| 6309 | // x = x | (x >>16); |
| 6310 | // x = x | (x >>32); // for 64-bit input |
| 6311 | // return popcount(~x); |
| 6312 | // |
| 6313 | // but see also: http://www.hackersdelight.org/HDcode/nlz.cc |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6314 | MVT VT = Op.getValueType(); |
| 6315 | MVT ShVT = TLI.getShiftAmountTy(); |
| 6316 | unsigned len = VT.getSizeInBits(); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6317 | for (unsigned i = 0; (1U << i) <= (len / 2); ++i) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6318 | SDValue Tmp3 = DAG.getConstant(1ULL << i, ShVT); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6319 | Op = DAG.getNode(ISD::OR, VT, Op, DAG.getNode(ISD::SRL, VT, Op, Tmp3)); |
| 6320 | } |
Bob Wilson | 4c24546 | 2009-01-22 17:39:32 +0000 | [diff] [blame] | 6321 | Op = DAG.getNOT(Op, VT); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6322 | return DAG.getNode(ISD::CTPOP, VT, Op); |
| 6323 | } |
| 6324 | case ISD::CTTZ: { |
| 6325 | // for now, we use: { return popcount(~x & (x - 1)); } |
| 6326 | // unless the target has ctlz but not ctpop, in which case we use: |
| 6327 | // { return 32 - nlz(~x & (x-1)); } |
| 6328 | // see also http://www.hackersdelight.org/HDcode/ntz.cc |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6329 | MVT VT = Op.getValueType(); |
Bob Wilson | 4c24546 | 2009-01-22 17:39:32 +0000 | [diff] [blame] | 6330 | SDValue Tmp3 = DAG.getNode(ISD::AND, VT, DAG.getNOT(Op, VT), |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6331 | DAG.getNode(ISD::SUB, VT, Op, DAG.getConstant(1, VT))); |
| 6332 | // If ISD::CTLZ is legal and CTPOP isn't, then do that instead. |
| 6333 | if (!TLI.isOperationLegal(ISD::CTPOP, VT) && |
| 6334 | TLI.isOperationLegal(ISD::CTLZ, VT)) |
| 6335 | return DAG.getNode(ISD::SUB, VT, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6336 | DAG.getConstant(VT.getSizeInBits(), VT), |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6337 | DAG.getNode(ISD::CTLZ, VT, Tmp3)); |
| 6338 | return DAG.getNode(ISD::CTPOP, VT, Tmp3); |
| 6339 | } |
| 6340 | } |
| 6341 | } |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6342 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6343 | /// ExpandOp - Expand the specified SDValue into its two component pieces |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6344 | /// 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] | 6345 | /// 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] | 6346 | /// ExpandedNodes map is filled in for any results that are expanded, and the |
| 6347 | /// Lo/Hi values are returned. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6348 | void SelectionDAGLegalize::ExpandOp(SDValue Op, SDValue &Lo, SDValue &Hi){ |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6349 | MVT VT = Op.getValueType(); |
| 6350 | MVT NVT = TLI.getTypeToTransformTo(VT); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6351 | SDNode *Node = Op.getNode(); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6352 | assert(getTypeAction(VT) == Expand && "Not an expanded type!"); |
Duncan Sands | 8e4eb09 | 2008-06-08 20:54:56 +0000 | [diff] [blame] | 6353 | assert(((NVT.isInteger() && NVT.bitsLT(VT)) || VT.isFloatingPoint() || |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6354 | VT.isVector()) && "Cannot expand to FP value or to larger int value!"); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6355 | |
Chris Lattner | 6fdcb25 | 2005-09-02 20:32:45 +0000 | [diff] [blame] | 6356 | // See if we already expanded it. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6357 | DenseMap<SDValue, std::pair<SDValue, SDValue> >::iterator I |
Chris Lattner | 6fdcb25 | 2005-09-02 20:32:45 +0000 | [diff] [blame] | 6358 | = ExpandedNodes.find(Op); |
| 6359 | if (I != ExpandedNodes.end()) { |
| 6360 | Lo = I->second.first; |
| 6361 | Hi = I->second.second; |
| 6362 | return; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6363 | } |
| 6364 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6365 | switch (Node->getOpcode()) { |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 6366 | case ISD::CopyFromReg: |
| 6367 | assert(0 && "CopyFromReg must be legal!"); |
Dale Johannesen | 6eaeff2 | 2007-10-10 01:01:31 +0000 | [diff] [blame] | 6368 | case ISD::FP_ROUND_INREG: |
| 6369 | if (VT == MVT::ppcf128 && |
| 6370 | TLI.getOperationAction(ISD::FP_ROUND_INREG, VT) == |
| 6371 | TargetLowering::Custom) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6372 | SDValue SrcLo, SrcHi, Src; |
Dale Johannesen | fcf4d24 | 2007-10-11 23:32:15 +0000 | [diff] [blame] | 6373 | ExpandOp(Op.getOperand(0), SrcLo, SrcHi); |
| 6374 | Src = DAG.getNode(ISD::BUILD_PAIR, VT, SrcLo, SrcHi); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6375 | SDValue Result = TLI.LowerOperation( |
Dale Johannesen | fcf4d24 | 2007-10-11 23:32:15 +0000 | [diff] [blame] | 6376 | DAG.getNode(ISD::FP_ROUND_INREG, VT, Src, Op.getOperand(1)), DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6377 | assert(Result.getNode()->getOpcode() == ISD::BUILD_PAIR); |
| 6378 | Lo = Result.getNode()->getOperand(0); |
| 6379 | Hi = Result.getNode()->getOperand(1); |
Dale Johannesen | 6eaeff2 | 2007-10-10 01:01:31 +0000 | [diff] [blame] | 6380 | break; |
| 6381 | } |
| 6382 | // fall through |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 6383 | default: |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 6384 | #ifndef NDEBUG |
Dan Gohman | 3983358 | 2007-06-04 16:17:33 +0000 | [diff] [blame] | 6385 | cerr << "NODE: "; Node->dump(&DAG); cerr << "\n"; |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 6386 | #endif |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6387 | assert(0 && "Do not know how to expand this operator!"); |
| 6388 | abort(); |
Dan Gohman | 1953ecb | 2008-02-27 01:52:30 +0000 | [diff] [blame] | 6389 | case ISD::EXTRACT_ELEMENT: |
| 6390 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 6391 | if (cast<ConstantSDNode>(Node->getOperand(1))->getZExtValue()) |
Dan Gohman | 1953ecb | 2008-02-27 01:52:30 +0000 | [diff] [blame] | 6392 | return ExpandOp(Hi, Lo, Hi); |
Dan Gohman | 18714ae | 2008-02-27 19:44:57 +0000 | [diff] [blame] | 6393 | return ExpandOp(Lo, Lo, Hi); |
Dale Johannesen | 25f1d08 | 2007-10-31 00:32:36 +0000 | [diff] [blame] | 6394 | case ISD::EXTRACT_VECTOR_ELT: |
Dale Johannesen | 25f1d08 | 2007-10-31 00:32:36 +0000 | [diff] [blame] | 6395 | // ExpandEXTRACT_VECTOR_ELT tolerates invalid result types. |
| 6396 | Lo = ExpandEXTRACT_VECTOR_ELT(Op); |
| 6397 | return ExpandOp(Lo, Lo, Hi); |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 6398 | case ISD::UNDEF: |
| 6399 | Lo = DAG.getNode(ISD::UNDEF, NVT); |
| 6400 | Hi = DAG.getNode(ISD::UNDEF, NVT); |
| 6401 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6402 | case ISD::Constant: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6403 | unsigned NVTBits = NVT.getSizeInBits(); |
Dan Gohman | 050f550 | 2008-03-03 22:20:46 +0000 | [diff] [blame] | 6404 | const APInt &Cst = cast<ConstantSDNode>(Node)->getAPIntValue(); |
| 6405 | Lo = DAG.getConstant(APInt(Cst).trunc(NVTBits), NVT); |
| 6406 | Hi = DAG.getConstant(Cst.lshr(NVTBits).trunc(NVTBits), NVT); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6407 | break; |
| 6408 | } |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 6409 | case ISD::ConstantFP: { |
| 6410 | ConstantFPSDNode *CFP = cast<ConstantFPSDNode>(Node); |
Dale Johannesen | a471c2e | 2007-10-11 18:07:22 +0000 | [diff] [blame] | 6411 | if (CFP->getValueType(0) == MVT::ppcf128) { |
Dale Johannesen | 7111b02 | 2008-10-09 18:53:47 +0000 | [diff] [blame] | 6412 | APInt api = CFP->getValueAPF().bitcastToAPInt(); |
Dale Johannesen | a471c2e | 2007-10-11 18:07:22 +0000 | [diff] [blame] | 6413 | Lo = DAG.getConstantFP(APFloat(APInt(64, 1, &api.getRawData()[1])), |
| 6414 | MVT::f64); |
| 6415 | Hi = DAG.getConstantFP(APFloat(APInt(64, 1, &api.getRawData()[0])), |
| 6416 | MVT::f64); |
| 6417 | break; |
| 6418 | } |
Evan Cheng | 279101e | 2006-12-12 22:19:28 +0000 | [diff] [blame] | 6419 | Lo = ExpandConstantFP(CFP, false, DAG, TLI); |
Evan Cheng | 9f87788 | 2006-12-13 20:57:08 +0000 | [diff] [blame] | 6420 | if (getTypeAction(Lo.getValueType()) == Expand) |
| 6421 | ExpandOp(Lo, Lo, Hi); |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 6422 | break; |
| 6423 | } |
Chris Lattner | d4e50bb | 2005-03-28 22:03:13 +0000 | [diff] [blame] | 6424 | case ISD::BUILD_PAIR: |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6425 | // Return the operands. |
| 6426 | Lo = Node->getOperand(0); |
| 6427 | Hi = Node->getOperand(1); |
Chris Lattner | d4e50bb | 2005-03-28 22:03:13 +0000 | [diff] [blame] | 6428 | break; |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6429 | |
| 6430 | case ISD::MERGE_VALUES: |
Chris Lattner | c58d558 | 2007-11-24 19:12:15 +0000 | [diff] [blame] | 6431 | if (Node->getNumValues() == 1) { |
| 6432 | ExpandOp(Op.getOperand(0), Lo, Hi); |
| 6433 | break; |
| 6434 | } |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6435 | // FIXME: For now only expand i64,chain = MERGE_VALUES (x, y) |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 6436 | assert(Op.getResNo() == 0 && Node->getNumValues() == 2 && |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6437 | Op.getValue(1).getValueType() == MVT::Other && |
| 6438 | "unhandled MERGE_VALUES"); |
| 6439 | ExpandOp(Op.getOperand(0), Lo, Hi); |
| 6440 | // Remember that we legalized the chain. |
| 6441 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Op.getOperand(1))); |
| 6442 | break; |
Chris Lattner | 58f7963 | 2005-12-12 22:27:43 +0000 | [diff] [blame] | 6443 | |
| 6444 | case ISD::SIGN_EXTEND_INREG: |
| 6445 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Chris Lattner | 4bdd275 | 2006-10-06 17:34:12 +0000 | [diff] [blame] | 6446 | // sext_inreg the low part if needed. |
| 6447 | Lo = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Lo, Node->getOperand(1)); |
| 6448 | |
| 6449 | // The high part gets the sign extension from the lo-part. This handles |
| 6450 | // things like sextinreg V:i64 from i8. |
Chris Lattner | 58f7963 | 2005-12-12 22:27:43 +0000 | [diff] [blame] | 6451 | Hi = DAG.getNode(ISD::SRA, NVT, Lo, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6452 | DAG.getConstant(NVT.getSizeInBits()-1, |
Chris Lattner | 58f7963 | 2005-12-12 22:27:43 +0000 | [diff] [blame] | 6453 | TLI.getShiftAmountTy())); |
Chris Lattner | 58f7963 | 2005-12-12 22:27:43 +0000 | [diff] [blame] | 6454 | break; |
Chris Lattner | d4e50bb | 2005-03-28 22:03:13 +0000 | [diff] [blame] | 6455 | |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 6456 | case ISD::BSWAP: { |
| 6457 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6458 | SDValue TempLo = DAG.getNode(ISD::BSWAP, NVT, Hi); |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 6459 | Hi = DAG.getNode(ISD::BSWAP, NVT, Lo); |
| 6460 | Lo = TempLo; |
| 6461 | break; |
| 6462 | } |
| 6463 | |
Chris Lattner | edb1add | 2005-05-11 04:51:16 +0000 | [diff] [blame] | 6464 | case ISD::CTPOP: |
| 6465 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Chris Lattner | 9b583b4 | 2005-05-11 05:09:47 +0000 | [diff] [blame] | 6466 | Lo = DAG.getNode(ISD::ADD, NVT, // ctpop(HL) -> ctpop(H)+ctpop(L) |
| 6467 | DAG.getNode(ISD::CTPOP, NVT, Lo), |
| 6468 | DAG.getNode(ISD::CTPOP, NVT, Hi)); |
Chris Lattner | edb1add | 2005-05-11 04:51:16 +0000 | [diff] [blame] | 6469 | Hi = DAG.getConstant(0, NVT); |
| 6470 | break; |
| 6471 | |
Chris Lattner | 39a8f33 | 2005-05-12 19:05:01 +0000 | [diff] [blame] | 6472 | case ISD::CTLZ: { |
| 6473 | // ctlz (HL) -> ctlz(H) != 32 ? ctlz(H) : (ctlz(L)+32) |
Chris Lattner | 3becf20 | 2005-05-12 19:27:51 +0000 | [diff] [blame] | 6474 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6475 | SDValue BitsC = DAG.getConstant(NVT.getSizeInBits(), NVT); |
| 6476 | SDValue HLZ = DAG.getNode(ISD::CTLZ, NVT, Hi); |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 6477 | SDValue TopNotZero = DAG.getSetCC(TLI.getSetCCResultType(NVT), HLZ, BitsC, |
| 6478 | ISD::SETNE); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6479 | SDValue LowPart = DAG.getNode(ISD::CTLZ, NVT, Lo); |
Chris Lattner | 39a8f33 | 2005-05-12 19:05:01 +0000 | [diff] [blame] | 6480 | LowPart = DAG.getNode(ISD::ADD, NVT, LowPart, BitsC); |
| 6481 | |
| 6482 | Lo = DAG.getNode(ISD::SELECT, NVT, TopNotZero, HLZ, LowPart); |
| 6483 | Hi = DAG.getConstant(0, NVT); |
| 6484 | break; |
| 6485 | } |
| 6486 | |
| 6487 | case ISD::CTTZ: { |
| 6488 | // cttz (HL) -> cttz(L) != 32 ? cttz(L) : (cttz(H)+32) |
Chris Lattner | 3becf20 | 2005-05-12 19:27:51 +0000 | [diff] [blame] | 6489 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6490 | SDValue BitsC = DAG.getConstant(NVT.getSizeInBits(), NVT); |
| 6491 | SDValue LTZ = DAG.getNode(ISD::CTTZ, NVT, Lo); |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 6492 | SDValue BotNotZero = DAG.getSetCC(TLI.getSetCCResultType(NVT), LTZ, BitsC, |
| 6493 | ISD::SETNE); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6494 | SDValue HiPart = DAG.getNode(ISD::CTTZ, NVT, Hi); |
Chris Lattner | 39a8f33 | 2005-05-12 19:05:01 +0000 | [diff] [blame] | 6495 | HiPart = DAG.getNode(ISD::ADD, NVT, HiPart, BitsC); |
| 6496 | |
| 6497 | Lo = DAG.getNode(ISD::SELECT, NVT, BotNotZero, LTZ, HiPart); |
| 6498 | Hi = DAG.getConstant(0, NVT); |
| 6499 | break; |
| 6500 | } |
Chris Lattner | edb1add | 2005-05-11 04:51:16 +0000 | [diff] [blame] | 6501 | |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 6502 | case ISD::VAARG: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6503 | SDValue Ch = Node->getOperand(0); // Legalize the chain. |
| 6504 | SDValue Ptr = Node->getOperand(1); // Legalize the pointer. |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 6505 | Lo = DAG.getVAArg(NVT, Ch, Ptr, Node->getOperand(2)); |
| 6506 | Hi = DAG.getVAArg(NVT, Lo.getValue(1), Ptr, Node->getOperand(2)); |
| 6507 | |
| 6508 | // Remember that we legalized the chain. |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6509 | Hi = LegalizeOp(Hi); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 6510 | AddLegalizedOperand(Op.getValue(1), Hi.getValue(1)); |
Duncan Sands | 0753fc1 | 2008-02-11 10:37:04 +0000 | [diff] [blame] | 6511 | if (TLI.isBigEndian()) |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 6512 | std::swap(Lo, Hi); |
| 6513 | break; |
| 6514 | } |
| 6515 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6516 | case ISD::LOAD: { |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6517 | LoadSDNode *LD = cast<LoadSDNode>(Node); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6518 | SDValue Ch = LD->getChain(); // Legalize the chain. |
| 6519 | SDValue Ptr = LD->getBasePtr(); // Legalize the pointer. |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6520 | ISD::LoadExtType ExtType = LD->getExtensionType(); |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 6521 | const Value *SV = LD->getSrcValue(); |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 6522 | int SVOffset = LD->getSrcValueOffset(); |
| 6523 | unsigned Alignment = LD->getAlignment(); |
| 6524 | bool isVolatile = LD->isVolatile(); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6525 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6526 | if (ExtType == ISD::NON_EXTLOAD) { |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 6527 | Lo = DAG.getLoad(NVT, Ch, Ptr, SV, SVOffset, |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 6528 | isVolatile, Alignment); |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 6529 | if (VT == MVT::f32 || VT == MVT::f64) { |
| 6530 | // f32->i32 or f64->i64 one to one expansion. |
| 6531 | // Remember that we legalized the chain. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6532 | AddLegalizedOperand(SDValue(Node, 1), LegalizeOp(Lo.getValue(1))); |
Evan Cheng | 9f87788 | 2006-12-13 20:57:08 +0000 | [diff] [blame] | 6533 | // Recursively expand the new load. |
| 6534 | if (getTypeAction(NVT) == Expand) |
| 6535 | ExpandOp(Lo, Lo, Hi); |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 6536 | break; |
| 6537 | } |
Chris Lattner | ec39a45 | 2005-01-19 18:02:17 +0000 | [diff] [blame] | 6538 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6539 | // Increment the pointer to the other half. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6540 | unsigned IncrementSize = Lo.getValueType().getSizeInBits()/8; |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6541 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 6542 | DAG.getIntPtrConstant(IncrementSize)); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6543 | SVOffset += IncrementSize; |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 6544 | Alignment = MinAlign(Alignment, IncrementSize); |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 6545 | Hi = DAG.getLoad(NVT, Ch, Ptr, SV, SVOffset, |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 6546 | isVolatile, Alignment); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 6547 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6548 | // Build a factor node to remember that this load is independent of the |
| 6549 | // other one. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6550 | SDValue TF = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1), |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6551 | Hi.getValue(1)); |
| 6552 | |
| 6553 | // Remember that we legalized the chain. |
| 6554 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(TF)); |
Duncan Sands | 0753fc1 | 2008-02-11 10:37:04 +0000 | [diff] [blame] | 6555 | if (TLI.isBigEndian()) |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6556 | std::swap(Lo, Hi); |
| 6557 | } else { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6558 | MVT EVT = LD->getMemoryVT(); |
Evan Cheng | 548f611 | 2006-12-13 03:19:57 +0000 | [diff] [blame] | 6559 | |
Dale Johannesen | b6210fc | 2007-10-19 20:29:00 +0000 | [diff] [blame] | 6560 | if ((VT == MVT::f64 && EVT == MVT::f32) || |
| 6561 | (VT == MVT::ppcf128 && (EVT==MVT::f64 || EVT==MVT::f32))) { |
Evan Cheng | 548f611 | 2006-12-13 03:19:57 +0000 | [diff] [blame] | 6562 | // f64 = EXTLOAD f32 should expand to LOAD, FP_EXTEND |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 6563 | SDValue Load = DAG.getLoad(EVT, Ch, Ptr, SV, |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 6564 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 548f611 | 2006-12-13 03:19:57 +0000 | [diff] [blame] | 6565 | // Remember that we legalized the chain. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6566 | AddLegalizedOperand(SDValue(Node, 1), LegalizeOp(Load.getValue(1))); |
Evan Cheng | 548f611 | 2006-12-13 03:19:57 +0000 | [diff] [blame] | 6567 | ExpandOp(DAG.getNode(ISD::FP_EXTEND, VT, Load), Lo, Hi); |
| 6568 | break; |
| 6569 | } |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6570 | |
| 6571 | if (EVT == NVT) |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 6572 | Lo = DAG.getLoad(NVT, Ch, Ptr, SV, |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 6573 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6574 | else |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 6575 | Lo = DAG.getExtLoad(ExtType, NVT, Ch, Ptr, SV, |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 6576 | SVOffset, EVT, isVolatile, |
| 6577 | Alignment); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6578 | |
| 6579 | // Remember that we legalized the chain. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6580 | AddLegalizedOperand(SDValue(Node, 1), LegalizeOp(Lo.getValue(1))); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6581 | |
| 6582 | if (ExtType == ISD::SEXTLOAD) { |
| 6583 | // The high part is obtained by SRA'ing all but one of the bits of the |
| 6584 | // lo part. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6585 | unsigned LoSize = Lo.getValueType().getSizeInBits(); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6586 | Hi = DAG.getNode(ISD::SRA, NVT, Lo, |
| 6587 | DAG.getConstant(LoSize-1, TLI.getShiftAmountTy())); |
| 6588 | } else if (ExtType == ISD::ZEXTLOAD) { |
| 6589 | // The high part is just a zero. |
| 6590 | Hi = DAG.getConstant(0, NVT); |
| 6591 | } else /* if (ExtType == ISD::EXTLOAD) */ { |
| 6592 | // The high part is undefined. |
| 6593 | Hi = DAG.getNode(ISD::UNDEF, NVT); |
| 6594 | } |
| 6595 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6596 | break; |
| 6597 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6598 | case ISD::AND: |
| 6599 | case ISD::OR: |
| 6600 | case ISD::XOR: { // Simple logical operators -> two trivial pieces. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6601 | SDValue LL, LH, RL, RH; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6602 | ExpandOp(Node->getOperand(0), LL, LH); |
| 6603 | ExpandOp(Node->getOperand(1), RL, RH); |
| 6604 | Lo = DAG.getNode(Node->getOpcode(), NVT, LL, RL); |
| 6605 | Hi = DAG.getNode(Node->getOpcode(), NVT, LH, RH); |
| 6606 | break; |
| 6607 | } |
| 6608 | case ISD::SELECT: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6609 | SDValue LL, LH, RL, RH; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6610 | ExpandOp(Node->getOperand(1), LL, LH); |
| 6611 | ExpandOp(Node->getOperand(2), RL, RH); |
Evan Cheng | 19103b1 | 2006-12-15 22:42:55 +0000 | [diff] [blame] | 6612 | if (getTypeAction(NVT) == Expand) |
| 6613 | NVT = TLI.getTypeToExpandTo(NVT); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 6614 | Lo = DAG.getNode(ISD::SELECT, NVT, Node->getOperand(0), LL, RL); |
Evan Cheng | 19103b1 | 2006-12-15 22:42:55 +0000 | [diff] [blame] | 6615 | if (VT != MVT::f32) |
| 6616 | Hi = DAG.getNode(ISD::SELECT, NVT, Node->getOperand(0), LH, RH); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6617 | break; |
| 6618 | } |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 6619 | case ISD::SELECT_CC: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6620 | SDValue TL, TH, FL, FH; |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 6621 | ExpandOp(Node->getOperand(2), TL, TH); |
| 6622 | ExpandOp(Node->getOperand(3), FL, FH); |
Evan Cheng | 19103b1 | 2006-12-15 22:42:55 +0000 | [diff] [blame] | 6623 | if (getTypeAction(NVT) == Expand) |
| 6624 | NVT = TLI.getTypeToExpandTo(NVT); |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 6625 | Lo = DAG.getNode(ISD::SELECT_CC, NVT, Node->getOperand(0), |
| 6626 | Node->getOperand(1), TL, FL, Node->getOperand(4)); |
Evan Cheng | 19103b1 | 2006-12-15 22:42:55 +0000 | [diff] [blame] | 6627 | if (VT != MVT::f32) |
| 6628 | Hi = DAG.getNode(ISD::SELECT_CC, NVT, Node->getOperand(0), |
| 6629 | Node->getOperand(1), TH, FH, Node->getOperand(4)); |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 6630 | break; |
| 6631 | } |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6632 | case ISD::ANY_EXTEND: |
| 6633 | // The low part is any extension of the input (which degenerates to a copy). |
| 6634 | Lo = DAG.getNode(ISD::ANY_EXTEND, NVT, Node->getOperand(0)); |
| 6635 | // The high part is undefined. |
| 6636 | Hi = DAG.getNode(ISD::UNDEF, NVT); |
| 6637 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6638 | case ISD::SIGN_EXTEND: { |
| 6639 | // The low part is just a sign extension of the input (which degenerates to |
| 6640 | // a copy). |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6641 | Lo = DAG.getNode(ISD::SIGN_EXTEND, NVT, Node->getOperand(0)); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 6642 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6643 | // The high part is obtained by SRA'ing all but one of the bits of the lo |
| 6644 | // part. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6645 | unsigned LoSize = Lo.getValueType().getSizeInBits(); |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6646 | Hi = DAG.getNode(ISD::SRA, NVT, Lo, |
| 6647 | DAG.getConstant(LoSize-1, TLI.getShiftAmountTy())); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6648 | break; |
| 6649 | } |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6650 | case ISD::ZERO_EXTEND: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6651 | // The low part is just a zero extension of the input (which degenerates to |
| 6652 | // a copy). |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6653 | Lo = DAG.getNode(ISD::ZERO_EXTEND, NVT, Node->getOperand(0)); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 6654 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6655 | // The high part is just a zero. |
| 6656 | Hi = DAG.getConstant(0, NVT); |
| 6657 | break; |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 6658 | |
Chris Lattner | 4c948eb | 2007-02-13 23:55:16 +0000 | [diff] [blame] | 6659 | case ISD::TRUNCATE: { |
| 6660 | // The input value must be larger than this value. Expand *it*. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6661 | SDValue NewLo; |
Chris Lattner | 4c948eb | 2007-02-13 23:55:16 +0000 | [diff] [blame] | 6662 | ExpandOp(Node->getOperand(0), NewLo, Hi); |
| 6663 | |
| 6664 | // The low part is now either the right size, or it is closer. If not the |
| 6665 | // right size, make an illegal truncate so we recursively expand it. |
| 6666 | if (NewLo.getValueType() != Node->getValueType(0)) |
| 6667 | NewLo = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0), NewLo); |
| 6668 | ExpandOp(NewLo, Lo, Hi); |
| 6669 | break; |
| 6670 | } |
| 6671 | |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 6672 | case ISD::BIT_CONVERT: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6673 | SDValue Tmp; |
Chris Lattner | f3f333d | 2006-09-09 00:20:27 +0000 | [diff] [blame] | 6674 | if (TLI.getOperationAction(ISD::BIT_CONVERT, VT) == TargetLowering::Custom){ |
| 6675 | // If the target wants to, allow it to lower this itself. |
| 6676 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 6677 | case Expand: assert(0 && "cannot expand FP!"); |
| 6678 | case Legal: Tmp = LegalizeOp(Node->getOperand(0)); break; |
| 6679 | case Promote: Tmp = PromoteOp (Node->getOperand(0)); break; |
| 6680 | } |
| 6681 | Tmp = TLI.LowerOperation(DAG.getNode(ISD::BIT_CONVERT, VT, Tmp), DAG); |
| 6682 | } |
| 6683 | |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 6684 | // f32 / f64 must be expanded to i32 / i64. |
Evan Cheng | 13acce3 | 2006-12-11 19:27:14 +0000 | [diff] [blame] | 6685 | if (VT == MVT::f32 || VT == MVT::f64) { |
| 6686 | Lo = DAG.getNode(ISD::BIT_CONVERT, NVT, Node->getOperand(0)); |
Evan Cheng | 19103b1 | 2006-12-15 22:42:55 +0000 | [diff] [blame] | 6687 | if (getTypeAction(NVT) == Expand) |
| 6688 | ExpandOp(Lo, Lo, Hi); |
Evan Cheng | 7b2b5c8 | 2006-12-12 19:53:13 +0000 | [diff] [blame] | 6689 | break; |
| 6690 | } |
| 6691 | |
| 6692 | // If source operand will be expanded to the same type as VT, i.e. |
| 6693 | // i64 <- f64, i32 <- f32, expand the source operand instead. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6694 | MVT VT0 = Node->getOperand(0).getValueType(); |
Evan Cheng | 7b2b5c8 | 2006-12-12 19:53:13 +0000 | [diff] [blame] | 6695 | if (getTypeAction(VT0) == Expand && TLI.getTypeToTransformTo(VT0) == VT) { |
| 6696 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 6697 | break; |
| 6698 | } |
| 6699 | |
Chris Lattner | f3f333d | 2006-09-09 00:20:27 +0000 | [diff] [blame] | 6700 | // Turn this into a load/store pair by default. |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6701 | if (Tmp.getNode() == 0) |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 6702 | Tmp = EmitStackConvert(Node->getOperand(0), VT, VT); |
Chris Lattner | f3f333d | 2006-09-09 00:20:27 +0000 | [diff] [blame] | 6703 | |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 6704 | ExpandOp(Tmp, Lo, Hi); |
| 6705 | break; |
| 6706 | } |
Andrew Lenharth | f70e30b | 2005-11-20 21:32:07 +0000 | [diff] [blame] | 6707 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6708 | case ISD::READCYCLECOUNTER: { |
Chris Lattner | 308575b | 2005-11-20 22:56:56 +0000 | [diff] [blame] | 6709 | assert(TLI.getOperationAction(ISD::READCYCLECOUNTER, VT) == |
| 6710 | TargetLowering::Custom && |
| 6711 | "Must custom expand ReadCycleCounter"); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6712 | SDValue Tmp = TLI.LowerOperation(Op, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6713 | assert(Tmp.getNode() && "Node must be custom expanded!"); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6714 | ExpandOp(Tmp.getValue(0), Lo, Hi); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6715 | AddLegalizedOperand(SDValue(Node, 1), // Remember we legalized the chain. |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6716 | LegalizeOp(Tmp.getValue(1))); |
Andrew Lenharth | f70e30b | 2005-11-20 21:32:07 +0000 | [diff] [blame] | 6717 | break; |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6718 | } |
Andrew Lenharth | f70e30b | 2005-11-20 21:32:07 +0000 | [diff] [blame] | 6719 | |
Dan Gohman | 0b1d4a7 | 2008-12-23 21:37:04 +0000 | [diff] [blame] | 6720 | case ISD::ATOMIC_CMP_SWAP: { |
Dale Johannesen | 1b54c7f | 2008-10-03 19:41:08 +0000 | [diff] [blame] | 6721 | // This operation does not need a loop. |
| 6722 | SDValue Tmp = TLI.LowerOperation(Op, DAG); |
| 6723 | assert(Tmp.getNode() && "Node must be custom expanded!"); |
| 6724 | ExpandOp(Tmp.getValue(0), Lo, Hi); |
| 6725 | AddLegalizedOperand(SDValue(Node, 1), // Remember we legalized the chain. |
| 6726 | LegalizeOp(Tmp.getValue(1))); |
| 6727 | break; |
| 6728 | } |
| 6729 | |
Dan Gohman | 0b1d4a7 | 2008-12-23 21:37:04 +0000 | [diff] [blame] | 6730 | case ISD::ATOMIC_LOAD_ADD: |
| 6731 | case ISD::ATOMIC_LOAD_SUB: |
| 6732 | case ISD::ATOMIC_LOAD_AND: |
| 6733 | case ISD::ATOMIC_LOAD_OR: |
| 6734 | case ISD::ATOMIC_LOAD_XOR: |
| 6735 | case ISD::ATOMIC_LOAD_NAND: |
| 6736 | case ISD::ATOMIC_SWAP: { |
Dale Johannesen | 1b54c7f | 2008-10-03 19:41:08 +0000 | [diff] [blame] | 6737 | // These operations require a loop to be generated. We can't do that yet, |
| 6738 | // so substitute a target-dependent pseudo and expand that later. |
Dale Johannesen | 48c1bc2 | 2008-10-02 18:53:47 +0000 | [diff] [blame] | 6739 | SDValue In2Lo, In2Hi, In2; |
| 6740 | ExpandOp(Op.getOperand(2), In2Lo, In2Hi); |
| 6741 | In2 = DAG.getNode(ISD::BUILD_PAIR, VT, In2Lo, In2Hi); |
Dale Johannesen | 1b54c7f | 2008-10-03 19:41:08 +0000 | [diff] [blame] | 6742 | AtomicSDNode* Anode = cast<AtomicSDNode>(Node); |
| 6743 | SDValue Replace = |
Dan Gohman | 0b1d4a7 | 2008-12-23 21:37:04 +0000 | [diff] [blame] | 6744 | DAG.getAtomic(Op.getOpcode(), Anode->getMemoryVT(), |
| 6745 | Op.getOperand(0), Op.getOperand(1), In2, |
Dale Johannesen | 1b54c7f | 2008-10-03 19:41:08 +0000 | [diff] [blame] | 6746 | Anode->getSrcValue(), Anode->getAlignment()); |
| 6747 | SDValue Result = TLI.LowerOperation(Replace, DAG); |
Dale Johannesen | 48c1bc2 | 2008-10-02 18:53:47 +0000 | [diff] [blame] | 6748 | ExpandOp(Result.getValue(0), Lo, Hi); |
| 6749 | // Remember that we legalized the chain. |
| 6750 | AddLegalizedOperand(SDValue(Node,1), LegalizeOp(Result.getValue(1))); |
Andrew Lenharth | d19189e | 2008-03-05 01:15:49 +0000 | [diff] [blame] | 6751 | break; |
| 6752 | } |
| 6753 | |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 6754 | // These operators cannot be expanded directly, emit them as calls to |
| 6755 | // library functions. |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6756 | case ISD::FP_TO_SINT: { |
Chris Lattner | 80a3e94 | 2005-07-29 00:33:32 +0000 | [diff] [blame] | 6757 | if (TLI.getOperationAction(ISD::FP_TO_SINT, VT) == TargetLowering::Custom) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6758 | SDValue Op; |
Chris Lattner | f20d183 | 2005-07-30 01:40:57 +0000 | [diff] [blame] | 6759 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 6760 | case Expand: assert(0 && "cannot expand FP!"); |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6761 | case Legal: Op = LegalizeOp(Node->getOperand(0)); break; |
| 6762 | case Promote: Op = PromoteOp (Node->getOperand(0)); break; |
Chris Lattner | f20d183 | 2005-07-30 01:40:57 +0000 | [diff] [blame] | 6763 | } |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 6764 | |
Chris Lattner | f20d183 | 2005-07-30 01:40:57 +0000 | [diff] [blame] | 6765 | Op = TLI.LowerOperation(DAG.getNode(ISD::FP_TO_SINT, VT, Op), DAG); |
| 6766 | |
Chris Lattner | 80a3e94 | 2005-07-29 00:33:32 +0000 | [diff] [blame] | 6767 | // Now that the custom expander is done, expand the result, which is still |
| 6768 | // VT. |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6769 | if (Op.getNode()) { |
Chris Lattner | 07dffd6 | 2005-08-26 00:14:16 +0000 | [diff] [blame] | 6770 | ExpandOp(Op, Lo, Hi); |
| 6771 | break; |
| 6772 | } |
Chris Lattner | 80a3e94 | 2005-07-29 00:33:32 +0000 | [diff] [blame] | 6773 | } |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 6774 | |
Duncan Sands | b2ff885 | 2008-07-17 02:36:29 +0000 | [diff] [blame] | 6775 | RTLIB::Libcall LC = RTLIB::getFPTOSINT(Node->getOperand(0).getValueType(), |
| 6776 | VT); |
| 6777 | assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unexpected uint-to-fp conversion!"); |
| 6778 | Lo = ExpandLibCall(LC, Node, false/*sign irrelevant*/, Hi); |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 6779 | break; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6780 | } |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 6781 | |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6782 | case ISD::FP_TO_UINT: { |
Chris Lattner | 80a3e94 | 2005-07-29 00:33:32 +0000 | [diff] [blame] | 6783 | if (TLI.getOperationAction(ISD::FP_TO_UINT, VT) == TargetLowering::Custom) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6784 | SDValue Op; |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6785 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 6786 | case Expand: assert(0 && "cannot expand FP!"); |
| 6787 | case Legal: Op = LegalizeOp(Node->getOperand(0)); break; |
| 6788 | case Promote: Op = PromoteOp (Node->getOperand(0)); break; |
| 6789 | } |
| 6790 | |
| 6791 | Op = TLI.LowerOperation(DAG.getNode(ISD::FP_TO_UINT, VT, Op), DAG); |
| 6792 | |
| 6793 | // Now that the custom expander is done, expand the result. |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6794 | if (Op.getNode()) { |
Chris Lattner | 07dffd6 | 2005-08-26 00:14:16 +0000 | [diff] [blame] | 6795 | ExpandOp(Op, Lo, Hi); |
| 6796 | break; |
| 6797 | } |
Chris Lattner | 80a3e94 | 2005-07-29 00:33:32 +0000 | [diff] [blame] | 6798 | } |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 6799 | |
Duncan Sands | b2ff885 | 2008-07-17 02:36:29 +0000 | [diff] [blame] | 6800 | RTLIB::Libcall LC = RTLIB::getFPTOUINT(Node->getOperand(0).getValueType(), |
| 6801 | VT); |
| 6802 | assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unexpected fp-to-uint conversion!"); |
| 6803 | Lo = ExpandLibCall(LC, Node, false/*sign irrelevant*/, Hi); |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 6804 | break; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6805 | } |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 6806 | |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 6807 | case ISD::SHL: { |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6808 | // If the target wants custom lowering, do so. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6809 | SDValue ShiftAmt = LegalizeOp(Node->getOperand(1)); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6810 | if (TLI.getOperationAction(ISD::SHL, VT) == TargetLowering::Custom) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6811 | SDValue Op = DAG.getNode(ISD::SHL, VT, Node->getOperand(0), ShiftAmt); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6812 | Op = TLI.LowerOperation(Op, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6813 | if (Op.getNode()) { |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6814 | // Now that the custom expander is done, expand the result, which is |
| 6815 | // still VT. |
| 6816 | ExpandOp(Op, Lo, Hi); |
| 6817 | break; |
| 6818 | } |
| 6819 | } |
| 6820 | |
Chris Lattner | 79980b0 | 2006-09-13 03:50:39 +0000 | [diff] [blame] | 6821 | // If ADDC/ADDE are supported and if the shift amount is a constant 1, emit |
| 6822 | // this X << 1 as X+X. |
| 6823 | if (ConstantSDNode *ShAmt = dyn_cast<ConstantSDNode>(ShiftAmt)) { |
Dan Gohman | 002e5d0 | 2008-03-13 22:13:53 +0000 | [diff] [blame] | 6824 | if (ShAmt->getAPIntValue() == 1 && TLI.isOperationLegal(ISD::ADDC, NVT) && |
Chris Lattner | 79980b0 | 2006-09-13 03:50:39 +0000 | [diff] [blame] | 6825 | TLI.isOperationLegal(ISD::ADDE, NVT)) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6826 | SDValue LoOps[2], HiOps[3]; |
Chris Lattner | 79980b0 | 2006-09-13 03:50:39 +0000 | [diff] [blame] | 6827 | ExpandOp(Node->getOperand(0), LoOps[0], HiOps[0]); |
| 6828 | SDVTList VTList = DAG.getVTList(LoOps[0].getValueType(), MVT::Flag); |
| 6829 | LoOps[1] = LoOps[0]; |
| 6830 | Lo = DAG.getNode(ISD::ADDC, VTList, LoOps, 2); |
| 6831 | |
| 6832 | HiOps[1] = HiOps[0]; |
| 6833 | HiOps[2] = Lo.getValue(1); |
| 6834 | Hi = DAG.getNode(ISD::ADDE, VTList, HiOps, 3); |
| 6835 | break; |
| 6836 | } |
| 6837 | } |
| 6838 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6839 | // If we can emit an efficient shift operation, do so now. |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 6840 | if (ExpandShift(ISD::SHL, Node->getOperand(0), ShiftAmt, Lo, Hi)) |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6841 | break; |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 6842 | |
| 6843 | // If this target supports SHL_PARTS, use it. |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 6844 | TargetLowering::LegalizeAction Action = |
| 6845 | TLI.getOperationAction(ISD::SHL_PARTS, NVT); |
| 6846 | if ((Action == TargetLowering::Legal && TLI.isTypeLegal(NVT)) || |
| 6847 | Action == TargetLowering::Custom) { |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 6848 | ExpandShiftParts(ISD::SHL_PARTS, Node->getOperand(0), ShiftAmt, Lo, Hi); |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 6849 | break; |
| 6850 | } |
| 6851 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6852 | // Otherwise, emit a libcall. |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 6853 | Lo = ExpandLibCall(RTLIB::SHL_I64, Node, false/*left shift=unsigned*/, Hi); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6854 | break; |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 6855 | } |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6856 | |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 6857 | case ISD::SRA: { |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6858 | // If the target wants custom lowering, do so. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6859 | SDValue ShiftAmt = LegalizeOp(Node->getOperand(1)); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6860 | if (TLI.getOperationAction(ISD::SRA, VT) == TargetLowering::Custom) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6861 | SDValue Op = DAG.getNode(ISD::SRA, VT, Node->getOperand(0), ShiftAmt); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6862 | Op = TLI.LowerOperation(Op, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6863 | if (Op.getNode()) { |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6864 | // Now that the custom expander is done, expand the result, which is |
| 6865 | // still VT. |
| 6866 | ExpandOp(Op, Lo, Hi); |
| 6867 | break; |
| 6868 | } |
| 6869 | } |
| 6870 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6871 | // If we can emit an efficient shift operation, do so now. |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 6872 | if (ExpandShift(ISD::SRA, Node->getOperand(0), ShiftAmt, Lo, Hi)) |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6873 | break; |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 6874 | |
| 6875 | // If this target supports SRA_PARTS, use it. |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 6876 | TargetLowering::LegalizeAction Action = |
| 6877 | TLI.getOperationAction(ISD::SRA_PARTS, NVT); |
| 6878 | if ((Action == TargetLowering::Legal && TLI.isTypeLegal(NVT)) || |
| 6879 | Action == TargetLowering::Custom) { |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 6880 | ExpandShiftParts(ISD::SRA_PARTS, Node->getOperand(0), ShiftAmt, Lo, Hi); |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 6881 | break; |
| 6882 | } |
| 6883 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6884 | // Otherwise, emit a libcall. |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 6885 | Lo = ExpandLibCall(RTLIB::SRA_I64, Node, true/*ashr is signed*/, Hi); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6886 | break; |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 6887 | } |
| 6888 | |
| 6889 | case ISD::SRL: { |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6890 | // If the target wants custom lowering, do so. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6891 | SDValue ShiftAmt = LegalizeOp(Node->getOperand(1)); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6892 | if (TLI.getOperationAction(ISD::SRL, VT) == TargetLowering::Custom) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6893 | SDValue Op = DAG.getNode(ISD::SRL, VT, Node->getOperand(0), ShiftAmt); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6894 | Op = TLI.LowerOperation(Op, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6895 | if (Op.getNode()) { |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6896 | // Now that the custom expander is done, expand the result, which is |
| 6897 | // still VT. |
| 6898 | ExpandOp(Op, Lo, Hi); |
| 6899 | break; |
| 6900 | } |
| 6901 | } |
| 6902 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6903 | // If we can emit an efficient shift operation, do so now. |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 6904 | if (ExpandShift(ISD::SRL, Node->getOperand(0), ShiftAmt, Lo, Hi)) |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6905 | break; |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 6906 | |
| 6907 | // If this target supports SRL_PARTS, use it. |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 6908 | TargetLowering::LegalizeAction Action = |
| 6909 | TLI.getOperationAction(ISD::SRL_PARTS, NVT); |
| 6910 | if ((Action == TargetLowering::Legal && TLI.isTypeLegal(NVT)) || |
| 6911 | Action == TargetLowering::Custom) { |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 6912 | ExpandShiftParts(ISD::SRL_PARTS, Node->getOperand(0), ShiftAmt, Lo, Hi); |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 6913 | break; |
| 6914 | } |
| 6915 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6916 | // Otherwise, emit a libcall. |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 6917 | Lo = ExpandLibCall(RTLIB::SRL_I64, Node, false/*lshr is unsigned*/, Hi); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6918 | break; |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 6919 | } |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6920 | |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 6921 | case ISD::ADD: |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6922 | case ISD::SUB: { |
| 6923 | // If the target wants to custom expand this, let them. |
| 6924 | if (TLI.getOperationAction(Node->getOpcode(), VT) == |
| 6925 | TargetLowering::Custom) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6926 | SDValue Result = TLI.LowerOperation(Op, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6927 | if (Result.getNode()) { |
Duncan Sands | 69bfb15 | 2008-06-22 09:42:16 +0000 | [diff] [blame] | 6928 | ExpandOp(Result, Lo, Hi); |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6929 | break; |
| 6930 | } |
| 6931 | } |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6932 | // Expand the subcomponents. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6933 | SDValue LHSL, LHSH, RHSL, RHSH; |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6934 | ExpandOp(Node->getOperand(0), LHSL, LHSH); |
| 6935 | ExpandOp(Node->getOperand(1), RHSL, RHSH); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6936 | SDValue LoOps[2], HiOps[3]; |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 6937 | LoOps[0] = LHSL; |
| 6938 | LoOps[1] = RHSL; |
| 6939 | HiOps[0] = LHSH; |
| 6940 | HiOps[1] = RHSH; |
Andrew Lenharth | 2163ca1 | 2008-10-07 18:27:23 +0000 | [diff] [blame] | 6941 | |
Andrew Lenharth | 5c9cc13 | 2008-10-07 17:03:15 +0000 | [diff] [blame] | 6942 | //cascaded check to see if any smaller size has a a carry flag. |
| 6943 | unsigned OpV = Node->getOpcode() == ISD::ADD ? ISD::ADDC : ISD::SUBC; |
| 6944 | bool hasCarry = false; |
Andrew Lenharth | 2163ca1 | 2008-10-07 18:27:23 +0000 | [diff] [blame] | 6945 | for (unsigned BitSize = NVT.getSizeInBits(); BitSize != 0; BitSize /= 2) { |
| 6946 | MVT AVT = MVT::getIntegerVT(BitSize); |
| 6947 | if (TLI.isOperationLegal(OpV, AVT)) { |
| 6948 | hasCarry = true; |
| 6949 | break; |
| 6950 | } |
| 6951 | } |
| 6952 | |
Andrew Lenharth | 5c9cc13 | 2008-10-07 17:03:15 +0000 | [diff] [blame] | 6953 | if(hasCarry) { |
Evan Cheng | 637ed03 | 2008-12-12 18:49:09 +0000 | [diff] [blame] | 6954 | SDVTList VTList = DAG.getVTList(LHSL.getValueType(), MVT::Flag); |
Andrew Lenharth | 40d5139 | 2008-10-07 14:15:42 +0000 | [diff] [blame] | 6955 | if (Node->getOpcode() == ISD::ADD) { |
| 6956 | Lo = DAG.getNode(ISD::ADDC, VTList, LoOps, 2); |
| 6957 | HiOps[2] = Lo.getValue(1); |
| 6958 | Hi = DAG.getNode(ISD::ADDE, VTList, HiOps, 3); |
| 6959 | } else { |
| 6960 | Lo = DAG.getNode(ISD::SUBC, VTList, LoOps, 2); |
| 6961 | HiOps[2] = Lo.getValue(1); |
| 6962 | Hi = DAG.getNode(ISD::SUBE, VTList, HiOps, 3); |
| 6963 | } |
| 6964 | break; |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 6965 | } else { |
Andrew Lenharth | 40d5139 | 2008-10-07 14:15:42 +0000 | [diff] [blame] | 6966 | if (Node->getOpcode() == ISD::ADD) { |
Evan Cheng | 637ed03 | 2008-12-12 18:49:09 +0000 | [diff] [blame] | 6967 | Lo = DAG.getNode(ISD::ADD, NVT, LoOps, 2); |
| 6968 | Hi = DAG.getNode(ISD::ADD, NVT, HiOps, 2); |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 6969 | SDValue Cmp1 = DAG.getSetCC(TLI.getSetCCResultType(NVT), |
Andrew Lenharth | 5c9cc13 | 2008-10-07 17:03:15 +0000 | [diff] [blame] | 6970 | Lo, LoOps[0], ISD::SETULT); |
Andrew Lenharth | 40d5139 | 2008-10-07 14:15:42 +0000 | [diff] [blame] | 6971 | SDValue Carry1 = DAG.getNode(ISD::SELECT, NVT, Cmp1, |
| 6972 | DAG.getConstant(1, NVT), |
| 6973 | DAG.getConstant(0, NVT)); |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 6974 | SDValue Cmp2 = DAG.getSetCC(TLI.getSetCCResultType(NVT), |
Andrew Lenharth | 5c9cc13 | 2008-10-07 17:03:15 +0000 | [diff] [blame] | 6975 | Lo, LoOps[1], ISD::SETULT); |
Andrew Lenharth | 40d5139 | 2008-10-07 14:15:42 +0000 | [diff] [blame] | 6976 | SDValue Carry2 = DAG.getNode(ISD::SELECT, NVT, Cmp2, |
| 6977 | DAG.getConstant(1, NVT), |
| 6978 | Carry1); |
| 6979 | Hi = DAG.getNode(ISD::ADD, NVT, Hi, Carry2); |
| 6980 | } else { |
Evan Cheng | 637ed03 | 2008-12-12 18:49:09 +0000 | [diff] [blame] | 6981 | Lo = DAG.getNode(ISD::SUB, NVT, LoOps, 2); |
| 6982 | Hi = DAG.getNode(ISD::SUB, NVT, HiOps, 2); |
Andrew Lenharth | 40d5139 | 2008-10-07 14:15:42 +0000 | [diff] [blame] | 6983 | SDValue Cmp = DAG.getSetCC(NVT, LoOps[0], LoOps[1], ISD::SETULT); |
| 6984 | SDValue Borrow = DAG.getNode(ISD::SELECT, NVT, Cmp, |
| 6985 | DAG.getConstant(1, NVT), |
| 6986 | DAG.getConstant(0, NVT)); |
| 6987 | Hi = DAG.getNode(ISD::SUB, NVT, Hi, Borrow); |
| 6988 | } |
| 6989 | break; |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 6990 | } |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6991 | } |
Chris Lattner | b429f73 | 2007-05-17 18:15:41 +0000 | [diff] [blame] | 6992 | |
| 6993 | case ISD::ADDC: |
| 6994 | case ISD::SUBC: { |
| 6995 | // Expand the subcomponents. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6996 | SDValue LHSL, LHSH, RHSL, RHSH; |
Chris Lattner | b429f73 | 2007-05-17 18:15:41 +0000 | [diff] [blame] | 6997 | ExpandOp(Node->getOperand(0), LHSL, LHSH); |
| 6998 | ExpandOp(Node->getOperand(1), RHSL, RHSH); |
| 6999 | SDVTList VTList = DAG.getVTList(LHSL.getValueType(), MVT::Flag); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7000 | SDValue LoOps[2] = { LHSL, RHSL }; |
| 7001 | SDValue HiOps[3] = { LHSH, RHSH }; |
Chris Lattner | b429f73 | 2007-05-17 18:15:41 +0000 | [diff] [blame] | 7002 | |
| 7003 | if (Node->getOpcode() == ISD::ADDC) { |
| 7004 | Lo = DAG.getNode(ISD::ADDC, VTList, LoOps, 2); |
| 7005 | HiOps[2] = Lo.getValue(1); |
| 7006 | Hi = DAG.getNode(ISD::ADDE, VTList, HiOps, 3); |
| 7007 | } else { |
| 7008 | Lo = DAG.getNode(ISD::SUBC, VTList, LoOps, 2); |
| 7009 | HiOps[2] = Lo.getValue(1); |
| 7010 | Hi = DAG.getNode(ISD::SUBE, VTList, HiOps, 3); |
| 7011 | } |
| 7012 | // Remember that we legalized the flag. |
| 7013 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Hi.getValue(1))); |
| 7014 | break; |
| 7015 | } |
| 7016 | case ISD::ADDE: |
| 7017 | case ISD::SUBE: { |
| 7018 | // Expand the subcomponents. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7019 | SDValue LHSL, LHSH, RHSL, RHSH; |
Chris Lattner | b429f73 | 2007-05-17 18:15:41 +0000 | [diff] [blame] | 7020 | ExpandOp(Node->getOperand(0), LHSL, LHSH); |
| 7021 | ExpandOp(Node->getOperand(1), RHSL, RHSH); |
| 7022 | SDVTList VTList = DAG.getVTList(LHSL.getValueType(), MVT::Flag); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7023 | SDValue LoOps[3] = { LHSL, RHSL, Node->getOperand(2) }; |
| 7024 | SDValue HiOps[3] = { LHSH, RHSH }; |
Chris Lattner | b429f73 | 2007-05-17 18:15:41 +0000 | [diff] [blame] | 7025 | |
| 7026 | Lo = DAG.getNode(Node->getOpcode(), VTList, LoOps, 3); |
| 7027 | HiOps[2] = Lo.getValue(1); |
| 7028 | Hi = DAG.getNode(Node->getOpcode(), VTList, HiOps, 3); |
| 7029 | |
| 7030 | // Remember that we legalized the flag. |
| 7031 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Hi.getValue(1))); |
| 7032 | break; |
| 7033 | } |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 7034 | case ISD::MUL: { |
Chris Lattner | 7d7bffe | 2006-09-16 00:09:24 +0000 | [diff] [blame] | 7035 | // If the target wants to custom expand this, let them. |
| 7036 | if (TLI.getOperationAction(ISD::MUL, VT) == TargetLowering::Custom) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7037 | SDValue New = TLI.LowerOperation(Op, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 7038 | if (New.getNode()) { |
Chris Lattner | 8829dc8 | 2006-09-16 05:08:34 +0000 | [diff] [blame] | 7039 | ExpandOp(New, Lo, Hi); |
Chris Lattner | 7d7bffe | 2006-09-16 00:09:24 +0000 | [diff] [blame] | 7040 | break; |
| 7041 | } |
| 7042 | } |
| 7043 | |
Evan Cheng | 3f4fd0f | 2006-09-01 18:17:58 +0000 | [diff] [blame] | 7044 | bool HasMULHS = TLI.isOperationLegal(ISD::MULHS, NVT); |
| 7045 | bool HasMULHU = TLI.isOperationLegal(ISD::MULHU, NVT); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 7046 | bool HasSMUL_LOHI = TLI.isOperationLegal(ISD::SMUL_LOHI, NVT); |
| 7047 | bool HasUMUL_LOHI = TLI.isOperationLegal(ISD::UMUL_LOHI, NVT); |
| 7048 | if (HasMULHU || HasMULHS || HasUMUL_LOHI || HasSMUL_LOHI) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7049 | SDValue LL, LH, RL, RH; |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 7050 | ExpandOp(Node->getOperand(0), LL, LH); |
| 7051 | ExpandOp(Node->getOperand(1), RL, RH); |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 7052 | unsigned OuterBitSize = Op.getValueSizeInBits(); |
| 7053 | unsigned InnerBitSize = RH.getValueSizeInBits(); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 7054 | unsigned LHSSB = DAG.ComputeNumSignBits(Op.getOperand(0)); |
| 7055 | unsigned RHSSB = DAG.ComputeNumSignBits(Op.getOperand(1)); |
Dan Gohman | 76c605b | 2008-03-10 20:42:19 +0000 | [diff] [blame] | 7056 | APInt HighMask = APInt::getHighBitsSet(OuterBitSize, InnerBitSize); |
| 7057 | if (DAG.MaskedValueIsZero(Node->getOperand(0), HighMask) && |
| 7058 | DAG.MaskedValueIsZero(Node->getOperand(1), HighMask)) { |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 7059 | // The inputs are both zero-extended. |
| 7060 | if (HasUMUL_LOHI) { |
| 7061 | // We can emit a umul_lohi. |
| 7062 | Lo = DAG.getNode(ISD::UMUL_LOHI, DAG.getVTList(NVT, NVT), LL, RL); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 7063 | Hi = SDValue(Lo.getNode(), 1); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 7064 | break; |
| 7065 | } |
| 7066 | if (HasMULHU) { |
| 7067 | // We can emit a mulhu+mul. |
| 7068 | Lo = DAG.getNode(ISD::MUL, NVT, LL, RL); |
| 7069 | Hi = DAG.getNode(ISD::MULHU, NVT, LL, RL); |
| 7070 | break; |
| 7071 | } |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 7072 | } |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 7073 | if (LHSSB > InnerBitSize && RHSSB > InnerBitSize) { |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 7074 | // The input values are both sign-extended. |
| 7075 | if (HasSMUL_LOHI) { |
| 7076 | // We can emit a smul_lohi. |
| 7077 | Lo = DAG.getNode(ISD::SMUL_LOHI, DAG.getVTList(NVT, NVT), LL, RL); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 7078 | Hi = SDValue(Lo.getNode(), 1); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 7079 | break; |
| 7080 | } |
| 7081 | if (HasMULHS) { |
| 7082 | // We can emit a mulhs+mul. |
| 7083 | Lo = DAG.getNode(ISD::MUL, NVT, LL, RL); |
| 7084 | Hi = DAG.getNode(ISD::MULHS, NVT, LL, RL); |
| 7085 | break; |
| 7086 | } |
| 7087 | } |
| 7088 | if (HasUMUL_LOHI) { |
| 7089 | // Lo,Hi = umul LHS, RHS. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7090 | SDValue UMulLOHI = DAG.getNode(ISD::UMUL_LOHI, |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 7091 | DAG.getVTList(NVT, NVT), LL, RL); |
| 7092 | Lo = UMulLOHI; |
| 7093 | Hi = UMulLOHI.getValue(1); |
Nate Begeman | 56eb868 | 2005-08-30 02:44:00 +0000 | [diff] [blame] | 7094 | RH = DAG.getNode(ISD::MUL, NVT, LL, RH); |
| 7095 | LH = DAG.getNode(ISD::MUL, NVT, LH, RL); |
| 7096 | Hi = DAG.getNode(ISD::ADD, NVT, Hi, RH); |
| 7097 | Hi = DAG.getNode(ISD::ADD, NVT, Hi, LH); |
Chris Lattner | a89654b | 2006-09-16 00:21:44 +0000 | [diff] [blame] | 7098 | break; |
Nate Begeman | 56eb868 | 2005-08-30 02:44:00 +0000 | [diff] [blame] | 7099 | } |
Dale Johannesen | 8eadd5a | 2007-10-24 22:26:08 +0000 | [diff] [blame] | 7100 | if (HasMULHU) { |
| 7101 | Lo = DAG.getNode(ISD::MUL, NVT, LL, RL); |
| 7102 | Hi = DAG.getNode(ISD::MULHU, NVT, LL, RL); |
| 7103 | RH = DAG.getNode(ISD::MUL, NVT, LL, RH); |
| 7104 | LH = DAG.getNode(ISD::MUL, NVT, LH, RL); |
| 7105 | Hi = DAG.getNode(ISD::ADD, NVT, Hi, RH); |
| 7106 | Hi = DAG.getNode(ISD::ADD, NVT, Hi, LH); |
| 7107 | break; |
| 7108 | } |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 7109 | } |
Evan Cheng | 3f4fd0f | 2006-09-01 18:17:58 +0000 | [diff] [blame] | 7110 | |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 7111 | // If nothing else, we can make a libcall. |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 7112 | Lo = ExpandLibCall(RTLIB::MUL_I64, Node, false/*sign irrelevant*/, Hi); |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 7113 | break; |
| 7114 | } |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 7115 | case ISD::SDIV: |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 7116 | Lo = ExpandLibCall(RTLIB::SDIV_I64, Node, true, Hi); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 7117 | break; |
| 7118 | case ISD::UDIV: |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 7119 | Lo = ExpandLibCall(RTLIB::UDIV_I64, Node, true, Hi); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 7120 | break; |
| 7121 | case ISD::SREM: |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 7122 | Lo = ExpandLibCall(RTLIB::SREM_I64, Node, true, Hi); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 7123 | break; |
| 7124 | case ISD::UREM: |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 7125 | Lo = ExpandLibCall(RTLIB::UREM_I64, Node, true, Hi); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 7126 | break; |
Evan Cheng | 5c9ce18 | 2006-12-12 21:51:17 +0000 | [diff] [blame] | 7127 | |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 7128 | case ISD::FADD: |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 7129 | Lo = ExpandLibCall(GetFPLibCall(VT, RTLIB::ADD_F32, |
| 7130 | RTLIB::ADD_F64, |
| 7131 | RTLIB::ADD_F80, |
| 7132 | RTLIB::ADD_PPCF128), |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 7133 | Node, false, Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 7134 | break; |
| 7135 | case ISD::FSUB: |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 7136 | Lo = ExpandLibCall(GetFPLibCall(VT, RTLIB::SUB_F32, |
| 7137 | RTLIB::SUB_F64, |
| 7138 | RTLIB::SUB_F80, |
| 7139 | RTLIB::SUB_PPCF128), |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 7140 | Node, false, Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 7141 | break; |
| 7142 | case ISD::FMUL: |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 7143 | Lo = ExpandLibCall(GetFPLibCall(VT, RTLIB::MUL_F32, |
| 7144 | RTLIB::MUL_F64, |
| 7145 | RTLIB::MUL_F80, |
| 7146 | RTLIB::MUL_PPCF128), |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 7147 | Node, false, Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 7148 | break; |
| 7149 | case ISD::FDIV: |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 7150 | Lo = ExpandLibCall(GetFPLibCall(VT, RTLIB::DIV_F32, |
| 7151 | RTLIB::DIV_F64, |
| 7152 | RTLIB::DIV_F80, |
| 7153 | RTLIB::DIV_PPCF128), |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 7154 | Node, false, Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 7155 | break; |
Duncan Sands | b2ff885 | 2008-07-17 02:36:29 +0000 | [diff] [blame] | 7156 | case ISD::FP_EXTEND: { |
Dale Johannesen | ca68aaa | 2007-10-12 01:37:08 +0000 | [diff] [blame] | 7157 | if (VT == MVT::ppcf128) { |
| 7158 | assert(Node->getOperand(0).getValueType()==MVT::f32 || |
| 7159 | Node->getOperand(0).getValueType()==MVT::f64); |
| 7160 | const uint64_t zero = 0; |
| 7161 | if (Node->getOperand(0).getValueType()==MVT::f32) |
| 7162 | Hi = DAG.getNode(ISD::FP_EXTEND, MVT::f64, Node->getOperand(0)); |
| 7163 | else |
| 7164 | Hi = Node->getOperand(0); |
| 7165 | Lo = DAG.getConstantFP(APFloat(APInt(64, 1, &zero)), MVT::f64); |
| 7166 | break; |
| 7167 | } |
Duncan Sands | b2ff885 | 2008-07-17 02:36:29 +0000 | [diff] [blame] | 7168 | RTLIB::Libcall LC = RTLIB::getFPEXT(Node->getOperand(0).getValueType(), VT); |
| 7169 | assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported FP_EXTEND!"); |
| 7170 | Lo = ExpandLibCall(LC, Node, true, Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 7171 | break; |
Duncan Sands | b2ff885 | 2008-07-17 02:36:29 +0000 | [diff] [blame] | 7172 | } |
| 7173 | case ISD::FP_ROUND: { |
| 7174 | RTLIB::Libcall LC = RTLIB::getFPROUND(Node->getOperand(0).getValueType(), |
| 7175 | VT); |
| 7176 | assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported FP_ROUND!"); |
| 7177 | Lo = ExpandLibCall(LC, Node, true, Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 7178 | break; |
Duncan Sands | b2ff885 | 2008-07-17 02:36:29 +0000 | [diff] [blame] | 7179 | } |
Evan Cheng | 4b88702 | 2008-09-09 23:02:14 +0000 | [diff] [blame] | 7180 | case ISD::FSQRT: |
| 7181 | case ISD::FSIN: |
| 7182 | case ISD::FCOS: |
Dale Johannesen | 7794f2a | 2008-09-04 00:47:13 +0000 | [diff] [blame] | 7183 | case ISD::FLOG: |
| 7184 | case ISD::FLOG2: |
| 7185 | case ISD::FLOG10: |
| 7186 | case ISD::FEXP: |
| 7187 | case ISD::FEXP2: |
Dan Gohman | 2bb1e3e | 2008-08-21 18:38:14 +0000 | [diff] [blame] | 7188 | case ISD::FTRUNC: |
| 7189 | case ISD::FFLOOR: |
| 7190 | case ISD::FCEIL: |
| 7191 | case ISD::FRINT: |
| 7192 | case ISD::FNEARBYINT: |
Evan Cheng | 9d24ac5 | 2008-09-09 23:35:53 +0000 | [diff] [blame] | 7193 | case ISD::FPOW: |
| 7194 | case ISD::FPOWI: { |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 7195 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
Evan Cheng | 98ff3b9 | 2006-12-13 02:38:13 +0000 | [diff] [blame] | 7196 | switch(Node->getOpcode()) { |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 7197 | case ISD::FSQRT: |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 7198 | LC = GetFPLibCall(VT, RTLIB::SQRT_F32, RTLIB::SQRT_F64, |
| 7199 | RTLIB::SQRT_F80, RTLIB::SQRT_PPCF128); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 7200 | break; |
| 7201 | case ISD::FSIN: |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 7202 | LC = GetFPLibCall(VT, RTLIB::SIN_F32, RTLIB::SIN_F64, |
| 7203 | RTLIB::SIN_F80, RTLIB::SIN_PPCF128); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 7204 | break; |
| 7205 | case ISD::FCOS: |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 7206 | LC = GetFPLibCall(VT, RTLIB::COS_F32, RTLIB::COS_F64, |
| 7207 | RTLIB::COS_F80, RTLIB::COS_PPCF128); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 7208 | break; |
Dale Johannesen | 7794f2a | 2008-09-04 00:47:13 +0000 | [diff] [blame] | 7209 | case ISD::FLOG: |
| 7210 | LC = GetFPLibCall(VT, RTLIB::LOG_F32, RTLIB::LOG_F64, |
| 7211 | RTLIB::LOG_F80, RTLIB::LOG_PPCF128); |
| 7212 | break; |
| 7213 | case ISD::FLOG2: |
| 7214 | LC = GetFPLibCall(VT, RTLIB::LOG2_F32, RTLIB::LOG2_F64, |
| 7215 | RTLIB::LOG2_F80, RTLIB::LOG2_PPCF128); |
| 7216 | break; |
| 7217 | case ISD::FLOG10: |
| 7218 | LC = GetFPLibCall(VT, RTLIB::LOG10_F32, RTLIB::LOG10_F64, |
| 7219 | RTLIB::LOG10_F80, RTLIB::LOG10_PPCF128); |
| 7220 | break; |
| 7221 | case ISD::FEXP: |
| 7222 | LC = GetFPLibCall(VT, RTLIB::EXP_F32, RTLIB::EXP_F64, |
| 7223 | RTLIB::EXP_F80, RTLIB::EXP_PPCF128); |
| 7224 | break; |
| 7225 | case ISD::FEXP2: |
| 7226 | LC = GetFPLibCall(VT, RTLIB::EXP2_F32, RTLIB::EXP2_F64, |
| 7227 | RTLIB::EXP2_F80, RTLIB::EXP2_PPCF128); |
| 7228 | break; |
Dan Gohman | 2bb1e3e | 2008-08-21 18:38:14 +0000 | [diff] [blame] | 7229 | case ISD::FTRUNC: |
| 7230 | LC = GetFPLibCall(VT, RTLIB::TRUNC_F32, RTLIB::TRUNC_F64, |
| 7231 | RTLIB::TRUNC_F80, RTLIB::TRUNC_PPCF128); |
| 7232 | break; |
| 7233 | case ISD::FFLOOR: |
| 7234 | LC = GetFPLibCall(VT, RTLIB::FLOOR_F32, RTLIB::FLOOR_F64, |
| 7235 | RTLIB::FLOOR_F80, RTLIB::FLOOR_PPCF128); |
| 7236 | break; |
| 7237 | case ISD::FCEIL: |
| 7238 | LC = GetFPLibCall(VT, RTLIB::CEIL_F32, RTLIB::CEIL_F64, |
| 7239 | RTLIB::CEIL_F80, RTLIB::CEIL_PPCF128); |
| 7240 | break; |
| 7241 | case ISD::FRINT: |
| 7242 | LC = GetFPLibCall(VT, RTLIB::RINT_F32, RTLIB::RINT_F64, |
| 7243 | RTLIB::RINT_F80, RTLIB::RINT_PPCF128); |
| 7244 | break; |
| 7245 | case ISD::FNEARBYINT: |
| 7246 | LC = GetFPLibCall(VT, RTLIB::NEARBYINT_F32, RTLIB::NEARBYINT_F64, |
| 7247 | RTLIB::NEARBYINT_F80, RTLIB::NEARBYINT_PPCF128); |
| 7248 | break; |
Evan Cheng | 4b88702 | 2008-09-09 23:02:14 +0000 | [diff] [blame] | 7249 | case ISD::FPOW: |
| 7250 | LC = GetFPLibCall(VT, RTLIB::POW_F32, RTLIB::POW_F64, RTLIB::POW_F80, |
| 7251 | RTLIB::POW_PPCF128); |
| 7252 | break; |
| 7253 | case ISD::FPOWI: |
| 7254 | LC = GetFPLibCall(VT, RTLIB::POWI_F32, RTLIB::POWI_F64, RTLIB::POWI_F80, |
| 7255 | RTLIB::POWI_PPCF128); |
| 7256 | break; |
Evan Cheng | 98ff3b9 | 2006-12-13 02:38:13 +0000 | [diff] [blame] | 7257 | default: assert(0 && "Unreachable!"); |
| 7258 | } |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 7259 | Lo = ExpandLibCall(LC, Node, false, Hi); |
Evan Cheng | 98ff3b9 | 2006-12-13 02:38:13 +0000 | [diff] [blame] | 7260 | break; |
| 7261 | } |
Evan Cheng | 966bf24 | 2006-12-16 00:52:40 +0000 | [diff] [blame] | 7262 | case ISD::FABS: { |
Dale Johannesen | f646774 | 2007-10-12 19:02:17 +0000 | [diff] [blame] | 7263 | if (VT == MVT::ppcf128) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7264 | SDValue Tmp; |
Dale Johannesen | f646774 | 2007-10-12 19:02:17 +0000 | [diff] [blame] | 7265 | ExpandOp(Node->getOperand(0), Lo, Tmp); |
| 7266 | Hi = DAG.getNode(ISD::FABS, NVT, Tmp); |
| 7267 | // lo = hi==fabs(hi) ? lo : -lo; |
| 7268 | Lo = DAG.getNode(ISD::SELECT_CC, NVT, Hi, Tmp, |
| 7269 | Lo, DAG.getNode(ISD::FNEG, NVT, Lo), |
| 7270 | DAG.getCondCode(ISD::SETEQ)); |
| 7271 | break; |
| 7272 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7273 | SDValue Mask = (VT == MVT::f64) |
Evan Cheng | 966bf24 | 2006-12-16 00:52:40 +0000 | [diff] [blame] | 7274 | ? DAG.getConstantFP(BitsToDouble(~(1ULL << 63)), VT) |
| 7275 | : DAG.getConstantFP(BitsToFloat(~(1U << 31)), VT); |
| 7276 | Mask = DAG.getNode(ISD::BIT_CONVERT, NVT, Mask); |
| 7277 | Lo = DAG.getNode(ISD::BIT_CONVERT, NVT, Node->getOperand(0)); |
| 7278 | Lo = DAG.getNode(ISD::AND, NVT, Lo, Mask); |
| 7279 | if (getTypeAction(NVT) == Expand) |
| 7280 | ExpandOp(Lo, Lo, Hi); |
| 7281 | break; |
| 7282 | } |
| 7283 | case ISD::FNEG: { |
Dale Johannesen | f646774 | 2007-10-12 19:02:17 +0000 | [diff] [blame] | 7284 | if (VT == MVT::ppcf128) { |
| 7285 | ExpandOp(Node->getOperand(0), Lo, Hi); |
| 7286 | Lo = DAG.getNode(ISD::FNEG, MVT::f64, Lo); |
| 7287 | Hi = DAG.getNode(ISD::FNEG, MVT::f64, Hi); |
| 7288 | break; |
| 7289 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7290 | SDValue Mask = (VT == MVT::f64) |
Evan Cheng | 966bf24 | 2006-12-16 00:52:40 +0000 | [diff] [blame] | 7291 | ? DAG.getConstantFP(BitsToDouble(1ULL << 63), VT) |
| 7292 | : DAG.getConstantFP(BitsToFloat(1U << 31), VT); |
| 7293 | Mask = DAG.getNode(ISD::BIT_CONVERT, NVT, Mask); |
| 7294 | Lo = DAG.getNode(ISD::BIT_CONVERT, NVT, Node->getOperand(0)); |
| 7295 | Lo = DAG.getNode(ISD::XOR, NVT, Lo, Mask); |
| 7296 | if (getTypeAction(NVT) == Expand) |
| 7297 | ExpandOp(Lo, Lo, Hi); |
| 7298 | break; |
| 7299 | } |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 7300 | case ISD::FCOPYSIGN: { |
| 7301 | Lo = ExpandFCOPYSIGNToBitwiseOps(Node, NVT, DAG, TLI); |
| 7302 | if (getTypeAction(NVT) == Expand) |
| 7303 | ExpandOp(Lo, Lo, Hi); |
| 7304 | break; |
| 7305 | } |
Evan Cheng | 7df28dc | 2006-12-19 01:44:04 +0000 | [diff] [blame] | 7306 | case ISD::SINT_TO_FP: |
| 7307 | case ISD::UINT_TO_FP: { |
| 7308 | bool isSigned = Node->getOpcode() == ISD::SINT_TO_FP; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 7309 | MVT SrcVT = Node->getOperand(0).getValueType(); |
Dale Johannesen | cf49819 | 2008-03-18 17:28:38 +0000 | [diff] [blame] | 7310 | |
| 7311 | // Promote the operand if needed. Do this before checking for |
| 7312 | // ppcf128 so conversions of i16 and i8 work. |
| 7313 | if (getTypeAction(SrcVT) == Promote) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7314 | SDValue Tmp = PromoteOp(Node->getOperand(0)); |
Dale Johannesen | cf49819 | 2008-03-18 17:28:38 +0000 | [diff] [blame] | 7315 | Tmp = isSigned |
| 7316 | ? DAG.getNode(ISD::SIGN_EXTEND_INREG, Tmp.getValueType(), Tmp, |
| 7317 | DAG.getValueType(SrcVT)) |
| 7318 | : DAG.getZeroExtendInReg(Tmp, SrcVT); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 7319 | Node = DAG.UpdateNodeOperands(Op, Tmp).getNode(); |
Dale Johannesen | cf49819 | 2008-03-18 17:28:38 +0000 | [diff] [blame] | 7320 | SrcVT = Node->getOperand(0).getValueType(); |
| 7321 | } |
| 7322 | |
Dan Gohman | a2e9485 | 2008-03-10 23:03:31 +0000 | [diff] [blame] | 7323 | if (VT == MVT::ppcf128 && SrcVT == MVT::i32) { |
Dan Gohman | f6283fd | 2008-02-25 21:39:34 +0000 | [diff] [blame] | 7324 | static const uint64_t zero = 0; |
Dale Johannesen | ca68aaa | 2007-10-12 01:37:08 +0000 | [diff] [blame] | 7325 | if (isSigned) { |
| 7326 | Hi = LegalizeOp(DAG.getNode(ISD::SINT_TO_FP, MVT::f64, |
| 7327 | Node->getOperand(0))); |
| 7328 | Lo = DAG.getConstantFP(APFloat(APInt(64, 1, &zero)), MVT::f64); |
| 7329 | } else { |
Dan Gohman | f6283fd | 2008-02-25 21:39:34 +0000 | [diff] [blame] | 7330 | static const uint64_t TwoE32[] = { 0x41f0000000000000LL, 0 }; |
Dale Johannesen | ca68aaa | 2007-10-12 01:37:08 +0000 | [diff] [blame] | 7331 | Hi = LegalizeOp(DAG.getNode(ISD::SINT_TO_FP, MVT::f64, |
| 7332 | Node->getOperand(0))); |
| 7333 | Lo = DAG.getConstantFP(APFloat(APInt(64, 1, &zero)), MVT::f64); |
| 7334 | Hi = DAG.getNode(ISD::BUILD_PAIR, VT, Lo, Hi); |
Dale Johannesen | 6e63e09 | 2007-10-12 17:52:03 +0000 | [diff] [blame] | 7335 | // X>=0 ? {(f64)x, 0} : {(f64)x, 0} + 2^32 |
Dale Johannesen | ca68aaa | 2007-10-12 01:37:08 +0000 | [diff] [blame] | 7336 | ExpandOp(DAG.getNode(ISD::SELECT_CC, MVT::ppcf128, Node->getOperand(0), |
| 7337 | DAG.getConstant(0, MVT::i32), |
| 7338 | DAG.getNode(ISD::FADD, MVT::ppcf128, Hi, |
| 7339 | DAG.getConstantFP( |
| 7340 | APFloat(APInt(128, 2, TwoE32)), |
| 7341 | MVT::ppcf128)), |
| 7342 | Hi, |
| 7343 | DAG.getCondCode(ISD::SETLT)), |
| 7344 | Lo, Hi); |
| 7345 | } |
| 7346 | break; |
| 7347 | } |
Dale Johannesen | 6e63e09 | 2007-10-12 17:52:03 +0000 | [diff] [blame] | 7348 | if (VT == MVT::ppcf128 && SrcVT == MVT::i64 && !isSigned) { |
| 7349 | // si64->ppcf128 done by libcall, below |
Dan Gohman | f6283fd | 2008-02-25 21:39:34 +0000 | [diff] [blame] | 7350 | static const uint64_t TwoE64[] = { 0x43f0000000000000LL, 0 }; |
Dale Johannesen | 6e63e09 | 2007-10-12 17:52:03 +0000 | [diff] [blame] | 7351 | ExpandOp(DAG.getNode(ISD::SINT_TO_FP, MVT::ppcf128, Node->getOperand(0)), |
| 7352 | Lo, Hi); |
| 7353 | Hi = DAG.getNode(ISD::BUILD_PAIR, VT, Lo, Hi); |
| 7354 | // x>=0 ? (ppcf128)(i64)x : (ppcf128)(i64)x + 2^64 |
| 7355 | ExpandOp(DAG.getNode(ISD::SELECT_CC, MVT::ppcf128, Node->getOperand(0), |
| 7356 | DAG.getConstant(0, MVT::i64), |
| 7357 | DAG.getNode(ISD::FADD, MVT::ppcf128, Hi, |
| 7358 | DAG.getConstantFP( |
| 7359 | APFloat(APInt(128, 2, TwoE64)), |
| 7360 | MVT::ppcf128)), |
| 7361 | Hi, |
| 7362 | DAG.getCondCode(ISD::SETLT)), |
| 7363 | Lo, Hi); |
| 7364 | break; |
| 7365 | } |
Evan Cheng | 7df28dc | 2006-12-19 01:44:04 +0000 | [diff] [blame] | 7366 | |
Dan Gohman | a2e9485 | 2008-03-10 23:03:31 +0000 | [diff] [blame] | 7367 | Lo = ExpandIntToFP(Node->getOpcode() == ISD::SINT_TO_FP, VT, |
| 7368 | Node->getOperand(0)); |
Evan Cheng | 110cf48 | 2008-04-01 01:50:16 +0000 | [diff] [blame] | 7369 | if (getTypeAction(Lo.getValueType()) == Expand) |
Evan Cheng | 6ad2f93 | 2008-04-01 01:51:26 +0000 | [diff] [blame] | 7370 | // float to i32 etc. can be 'expanded' to a single node. |
Evan Cheng | 110cf48 | 2008-04-01 01:50:16 +0000 | [diff] [blame] | 7371 | ExpandOp(Lo, Lo, Hi); |
Evan Cheng | 7df28dc | 2006-12-19 01:44:04 +0000 | [diff] [blame] | 7372 | break; |
| 7373 | } |
Evan Cheng | 98ff3b9 | 2006-12-13 02:38:13 +0000 | [diff] [blame] | 7374 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 7375 | |
Chris Lattner | 8339736 | 2005-12-21 18:02:52 +0000 | [diff] [blame] | 7376 | // Make sure the resultant values have been legalized themselves, unless this |
| 7377 | // is a type that requires multi-step expansion. |
| 7378 | if (getTypeAction(NVT) != Expand && NVT != MVT::isVoid) { |
| 7379 | Lo = LegalizeOp(Lo); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 7380 | if (Hi.getNode()) |
Evan Cheng | 13acce3 | 2006-12-11 19:27:14 +0000 | [diff] [blame] | 7381 | // Don't legalize the high part if it is expanded to a single node. |
| 7382 | Hi = LegalizeOp(Hi); |
Chris Lattner | 8339736 | 2005-12-21 18:02:52 +0000 | [diff] [blame] | 7383 | } |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 7384 | |
| 7385 | // Remember in a map if the values will be reused later. |
Dan Gohman | 6b345ee | 2008-07-07 17:46:23 +0000 | [diff] [blame] | 7386 | bool isNew = |
| 7387 | ExpandedNodes.insert(std::make_pair(Op, std::make_pair(Lo, Hi))).second; |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 7388 | assert(isNew && "Value already expanded?!?"); |
Evan Cheng | 24ac408 | 2008-11-24 07:09:49 +0000 | [diff] [blame] | 7389 | isNew = isNew; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 7390 | } |
| 7391 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7392 | /// SplitVectorOp - Given an operand of vector type, break it down into |
| 7393 | /// two smaller values, still of vector type. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7394 | void SelectionDAGLegalize::SplitVectorOp(SDValue Op, SDValue &Lo, |
| 7395 | SDValue &Hi) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 7396 | assert(Op.getValueType().isVector() && "Cannot split non-vector type!"); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 7397 | SDNode *Node = Op.getNode(); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 7398 | unsigned NumElements = Op.getValueType().getVectorNumElements(); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7399 | assert(NumElements > 1 && "Cannot split a single element vector!"); |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7400 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 7401 | MVT NewEltVT = Op.getValueType().getVectorElementType(); |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7402 | |
| 7403 | unsigned NewNumElts_Lo = 1 << Log2_32(NumElements-1); |
| 7404 | unsigned NewNumElts_Hi = NumElements - NewNumElts_Lo; |
| 7405 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 7406 | MVT NewVT_Lo = MVT::getVectorVT(NewEltVT, NewNumElts_Lo); |
| 7407 | MVT NewVT_Hi = MVT::getVectorVT(NewEltVT, NewNumElts_Hi); |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7408 | |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7409 | // See if we already split it. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7410 | std::map<SDValue, std::pair<SDValue, SDValue> >::iterator I |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7411 | = SplitNodes.find(Op); |
| 7412 | if (I != SplitNodes.end()) { |
| 7413 | Lo = I->second.first; |
| 7414 | Hi = I->second.second; |
| 7415 | return; |
| 7416 | } |
| 7417 | |
| 7418 | switch (Node->getOpcode()) { |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 7419 | default: |
| 7420 | #ifndef NDEBUG |
Dan Gohman | 3983358 | 2007-06-04 16:17:33 +0000 | [diff] [blame] | 7421 | Node->dump(&DAG); |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 7422 | #endif |
| 7423 | assert(0 && "Unhandled operation in SplitVectorOp!"); |
Chris Lattner | daf9bc8 | 2007-11-19 20:21:32 +0000 | [diff] [blame] | 7424 | case ISD::UNDEF: |
| 7425 | Lo = DAG.getNode(ISD::UNDEF, NewVT_Lo); |
| 7426 | Hi = DAG.getNode(ISD::UNDEF, NewVT_Hi); |
| 7427 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7428 | case ISD::BUILD_PAIR: |
| 7429 | Lo = Node->getOperand(0); |
| 7430 | Hi = Node->getOperand(1); |
| 7431 | break; |
Dan Gohman | 9fe4662 | 2007-09-28 23:53:40 +0000 | [diff] [blame] | 7432 | case ISD::INSERT_VECTOR_ELT: { |
Nate Begeman | 6867991 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 7433 | if (ConstantSDNode *Idx = dyn_cast<ConstantSDNode>(Node->getOperand(2))) { |
| 7434 | SplitVectorOp(Node->getOperand(0), Lo, Hi); |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 7435 | unsigned Index = Idx->getZExtValue(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7436 | SDValue ScalarOp = Node->getOperand(1); |
Nate Begeman | 6867991 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 7437 | if (Index < NewNumElts_Lo) |
| 7438 | Lo = DAG.getNode(ISD::INSERT_VECTOR_ELT, NewVT_Lo, Lo, ScalarOp, |
| 7439 | DAG.getIntPtrConstant(Index)); |
| 7440 | else |
| 7441 | Hi = DAG.getNode(ISD::INSERT_VECTOR_ELT, NewVT_Hi, Hi, ScalarOp, |
| 7442 | DAG.getIntPtrConstant(Index - NewNumElts_Lo)); |
| 7443 | break; |
| 7444 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7445 | SDValue Tmp = PerformInsertVectorEltInMemory(Node->getOperand(0), |
Nate Begeman | 6867991 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 7446 | Node->getOperand(1), |
| 7447 | Node->getOperand(2)); |
| 7448 | SplitVectorOp(Tmp, Lo, Hi); |
Dan Gohman | 9fe4662 | 2007-09-28 23:53:40 +0000 | [diff] [blame] | 7449 | break; |
| 7450 | } |
Chris Lattner | 6c9c680 | 2007-11-19 21:16:54 +0000 | [diff] [blame] | 7451 | case ISD::VECTOR_SHUFFLE: { |
| 7452 | // Build the low part. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7453 | SDValue Mask = Node->getOperand(2); |
| 7454 | SmallVector<SDValue, 8> Ops; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 7455 | MVT PtrVT = TLI.getPointerTy(); |
Chris Lattner | 6c9c680 | 2007-11-19 21:16:54 +0000 | [diff] [blame] | 7456 | |
| 7457 | // Insert all of the elements from the input that are needed. We use |
| 7458 | // buildvector of extractelement here because the input vectors will have |
| 7459 | // to be legalized, so this makes the code simpler. |
| 7460 | for (unsigned i = 0; i != NewNumElts_Lo; ++i) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7461 | SDValue IdxNode = Mask.getOperand(i); |
Nate Begeman | 5922f56 | 2008-03-14 00:53:31 +0000 | [diff] [blame] | 7462 | if (IdxNode.getOpcode() == ISD::UNDEF) { |
| 7463 | Ops.push_back(DAG.getNode(ISD::UNDEF, NewEltVT)); |
| 7464 | continue; |
| 7465 | } |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 7466 | unsigned Idx = cast<ConstantSDNode>(IdxNode)->getZExtValue(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7467 | SDValue InVec = Node->getOperand(0); |
Chris Lattner | 6c9c680 | 2007-11-19 21:16:54 +0000 | [diff] [blame] | 7468 | if (Idx >= NumElements) { |
| 7469 | InVec = Node->getOperand(1); |
| 7470 | Idx -= NumElements; |
| 7471 | } |
| 7472 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, NewEltVT, InVec, |
| 7473 | DAG.getConstant(Idx, PtrVT))); |
| 7474 | } |
| 7475 | Lo = DAG.getNode(ISD::BUILD_VECTOR, NewVT_Lo, &Ops[0], Ops.size()); |
| 7476 | Ops.clear(); |
| 7477 | |
| 7478 | for (unsigned i = NewNumElts_Lo; i != NumElements; ++i) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7479 | SDValue IdxNode = Mask.getOperand(i); |
Nate Begeman | 5922f56 | 2008-03-14 00:53:31 +0000 | [diff] [blame] | 7480 | if (IdxNode.getOpcode() == ISD::UNDEF) { |
| 7481 | Ops.push_back(DAG.getNode(ISD::UNDEF, NewEltVT)); |
| 7482 | continue; |
| 7483 | } |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 7484 | unsigned Idx = cast<ConstantSDNode>(IdxNode)->getZExtValue(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7485 | SDValue InVec = Node->getOperand(0); |
Chris Lattner | 6c9c680 | 2007-11-19 21:16:54 +0000 | [diff] [blame] | 7486 | if (Idx >= NumElements) { |
| 7487 | InVec = Node->getOperand(1); |
| 7488 | Idx -= NumElements; |
| 7489 | } |
| 7490 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, NewEltVT, InVec, |
| 7491 | DAG.getConstant(Idx, PtrVT))); |
| 7492 | } |
Mon P Wang | 92879f3 | 2008-07-25 01:30:26 +0000 | [diff] [blame] | 7493 | Hi = DAG.getNode(ISD::BUILD_VECTOR, NewVT_Hi, &Ops[0], Ops.size()); |
Chris Lattner | 6c9c680 | 2007-11-19 21:16:54 +0000 | [diff] [blame] | 7494 | break; |
| 7495 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7496 | case ISD::BUILD_VECTOR: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7497 | SmallVector<SDValue, 8> LoOps(Node->op_begin(), |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7498 | Node->op_begin()+NewNumElts_Lo); |
| 7499 | Lo = DAG.getNode(ISD::BUILD_VECTOR, NewVT_Lo, &LoOps[0], LoOps.size()); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7500 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7501 | SmallVector<SDValue, 8> HiOps(Node->op_begin()+NewNumElts_Lo, |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7502 | Node->op_end()); |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7503 | Hi = DAG.getNode(ISD::BUILD_VECTOR, NewVT_Hi, &HiOps[0], HiOps.size()); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7504 | break; |
| 7505 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7506 | case ISD::CONCAT_VECTORS: { |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7507 | // FIXME: Handle non-power-of-two vectors? |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7508 | unsigned NewNumSubvectors = Node->getNumOperands() / 2; |
| 7509 | if (NewNumSubvectors == 1) { |
| 7510 | Lo = Node->getOperand(0); |
| 7511 | Hi = Node->getOperand(1); |
| 7512 | } else { |
Mon P Wang | aeb06d2 | 2008-11-10 04:46:22 +0000 | [diff] [blame] | 7513 | SmallVector<SDValue, 8> LoOps(Node->op_begin(), |
| 7514 | Node->op_begin()+NewNumSubvectors); |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7515 | Lo = DAG.getNode(ISD::CONCAT_VECTORS, NewVT_Lo, &LoOps[0], LoOps.size()); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 7516 | |
Mon P Wang | aeb06d2 | 2008-11-10 04:46:22 +0000 | [diff] [blame] | 7517 | SmallVector<SDValue, 8> HiOps(Node->op_begin()+NewNumSubvectors, |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7518 | Node->op_end()); |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7519 | Hi = DAG.getNode(ISD::CONCAT_VECTORS, NewVT_Hi, &HiOps[0], HiOps.size()); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7520 | } |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 7521 | break; |
| 7522 | } |
Mon P Wang | aeb06d2 | 2008-11-10 04:46:22 +0000 | [diff] [blame] | 7523 | case ISD::EXTRACT_SUBVECTOR: { |
| 7524 | SDValue Vec = Op.getOperand(0); |
| 7525 | SDValue Idx = Op.getOperand(1); |
| 7526 | MVT IdxVT = Idx.getValueType(); |
| 7527 | |
| 7528 | Lo = DAG.getNode(ISD::EXTRACT_SUBVECTOR, NewVT_Lo, Vec, Idx); |
| 7529 | ConstantSDNode *CIdx = dyn_cast<ConstantSDNode>(Idx); |
| 7530 | if (CIdx) { |
| 7531 | Hi = DAG.getNode(ISD::EXTRACT_SUBVECTOR, NewVT_Hi, Vec, |
| 7532 | DAG.getConstant(CIdx->getZExtValue() + NewNumElts_Lo, |
| 7533 | IdxVT)); |
| 7534 | } else { |
| 7535 | Idx = DAG.getNode(ISD::ADD, IdxVT, Idx, |
| 7536 | DAG.getConstant(NewNumElts_Lo, IdxVT)); |
| 7537 | Hi = DAG.getNode(ISD::EXTRACT_SUBVECTOR, NewVT_Hi, Vec, Idx); |
| 7538 | } |
| 7539 | break; |
| 7540 | } |
Dan Gohman | c623096 | 2007-10-17 14:48:28 +0000 | [diff] [blame] | 7541 | case ISD::SELECT: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7542 | SDValue Cond = Node->getOperand(0); |
Dan Gohman | c623096 | 2007-10-17 14:48:28 +0000 | [diff] [blame] | 7543 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7544 | SDValue LL, LH, RL, RH; |
Dan Gohman | c623096 | 2007-10-17 14:48:28 +0000 | [diff] [blame] | 7545 | SplitVectorOp(Node->getOperand(1), LL, LH); |
| 7546 | SplitVectorOp(Node->getOperand(2), RL, RH); |
| 7547 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 7548 | if (Cond.getValueType().isVector()) { |
Dan Gohman | c623096 | 2007-10-17 14:48:28 +0000 | [diff] [blame] | 7549 | // Handle a vector merge. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7550 | SDValue CL, CH; |
Dan Gohman | c623096 | 2007-10-17 14:48:28 +0000 | [diff] [blame] | 7551 | SplitVectorOp(Cond, CL, CH); |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7552 | Lo = DAG.getNode(Node->getOpcode(), NewVT_Lo, CL, LL, RL); |
| 7553 | Hi = DAG.getNode(Node->getOpcode(), NewVT_Hi, CH, LH, RH); |
Dan Gohman | c623096 | 2007-10-17 14:48:28 +0000 | [diff] [blame] | 7554 | } else { |
| 7555 | // Handle a simple select with vector operands. |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7556 | Lo = DAG.getNode(Node->getOpcode(), NewVT_Lo, Cond, LL, RL); |
| 7557 | Hi = DAG.getNode(Node->getOpcode(), NewVT_Hi, Cond, LH, RH); |
Dan Gohman | c623096 | 2007-10-17 14:48:28 +0000 | [diff] [blame] | 7558 | } |
| 7559 | break; |
| 7560 | } |
Chris Lattner | 80c1a56 | 2008-06-30 02:43:01 +0000 | [diff] [blame] | 7561 | case ISD::SELECT_CC: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7562 | SDValue CondLHS = Node->getOperand(0); |
| 7563 | SDValue CondRHS = Node->getOperand(1); |
| 7564 | SDValue CondCode = Node->getOperand(4); |
Chris Lattner | 80c1a56 | 2008-06-30 02:43:01 +0000 | [diff] [blame] | 7565 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7566 | SDValue LL, LH, RL, RH; |
Chris Lattner | 80c1a56 | 2008-06-30 02:43:01 +0000 | [diff] [blame] | 7567 | SplitVectorOp(Node->getOperand(2), LL, LH); |
| 7568 | SplitVectorOp(Node->getOperand(3), RL, RH); |
| 7569 | |
| 7570 | // Handle a simple select with vector operands. |
| 7571 | Lo = DAG.getNode(ISD::SELECT_CC, NewVT_Lo, CondLHS, CondRHS, |
| 7572 | LL, RL, CondCode); |
| 7573 | Hi = DAG.getNode(ISD::SELECT_CC, NewVT_Hi, CondLHS, CondRHS, |
| 7574 | LH, RH, CondCode); |
| 7575 | break; |
| 7576 | } |
Nate Begeman | b43e9c1 | 2008-05-12 19:40:03 +0000 | [diff] [blame] | 7577 | case ISD::VSETCC: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7578 | SDValue LL, LH, RL, RH; |
Nate Begeman | b43e9c1 | 2008-05-12 19:40:03 +0000 | [diff] [blame] | 7579 | SplitVectorOp(Node->getOperand(0), LL, LH); |
| 7580 | SplitVectorOp(Node->getOperand(1), RL, RH); |
| 7581 | Lo = DAG.getNode(ISD::VSETCC, NewVT_Lo, LL, RL, Node->getOperand(2)); |
| 7582 | Hi = DAG.getNode(ISD::VSETCC, NewVT_Hi, LH, RH, Node->getOperand(2)); |
| 7583 | break; |
| 7584 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7585 | case ISD::ADD: |
| 7586 | case ISD::SUB: |
| 7587 | case ISD::MUL: |
| 7588 | case ISD::FADD: |
| 7589 | case ISD::FSUB: |
| 7590 | case ISD::FMUL: |
| 7591 | case ISD::SDIV: |
| 7592 | case ISD::UDIV: |
| 7593 | case ISD::FDIV: |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 7594 | case ISD::FPOW: |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7595 | case ISD::AND: |
| 7596 | case ISD::OR: |
Dan Gohman | 089617d | 2007-11-19 15:15:03 +0000 | [diff] [blame] | 7597 | case ISD::XOR: |
| 7598 | case ISD::UREM: |
| 7599 | case ISD::SREM: |
Mon P Wang | 87c8a8f | 2008-12-18 20:03:17 +0000 | [diff] [blame] | 7600 | case ISD::FREM: |
| 7601 | case ISD::SHL: |
| 7602 | case ISD::SRA: |
| 7603 | case ISD::SRL: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7604 | SDValue LL, LH, RL, RH; |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7605 | SplitVectorOp(Node->getOperand(0), LL, LH); |
| 7606 | SplitVectorOp(Node->getOperand(1), RL, RH); |
| 7607 | |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7608 | Lo = DAG.getNode(Node->getOpcode(), NewVT_Lo, LL, RL); |
| 7609 | Hi = DAG.getNode(Node->getOpcode(), NewVT_Hi, LH, RH); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7610 | break; |
| 7611 | } |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 7612 | case ISD::FP_ROUND: |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 7613 | case ISD::FPOWI: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7614 | SDValue L, H; |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 7615 | SplitVectorOp(Node->getOperand(0), L, H); |
| 7616 | |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7617 | Lo = DAG.getNode(Node->getOpcode(), NewVT_Lo, L, Node->getOperand(1)); |
| 7618 | Hi = DAG.getNode(Node->getOpcode(), NewVT_Hi, H, Node->getOperand(1)); |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 7619 | break; |
| 7620 | } |
| 7621 | case ISD::CTTZ: |
| 7622 | case ISD::CTLZ: |
| 7623 | case ISD::CTPOP: |
| 7624 | case ISD::FNEG: |
| 7625 | case ISD::FABS: |
| 7626 | case ISD::FSQRT: |
| 7627 | case ISD::FSIN: |
Nate Begeman | b348d18 | 2007-11-17 03:58:34 +0000 | [diff] [blame] | 7628 | case ISD::FCOS: |
Dale Johannesen | 7794f2a | 2008-09-04 00:47:13 +0000 | [diff] [blame] | 7629 | case ISD::FLOG: |
| 7630 | case ISD::FLOG2: |
| 7631 | case ISD::FLOG10: |
| 7632 | case ISD::FEXP: |
| 7633 | case ISD::FEXP2: |
Nate Begeman | b348d18 | 2007-11-17 03:58:34 +0000 | [diff] [blame] | 7634 | case ISD::FP_TO_SINT: |
| 7635 | case ISD::FP_TO_UINT: |
| 7636 | case ISD::SINT_TO_FP: |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 7637 | case ISD::UINT_TO_FP: |
| 7638 | case ISD::TRUNCATE: |
| 7639 | case ISD::ANY_EXTEND: |
| 7640 | case ISD::SIGN_EXTEND: |
| 7641 | case ISD::ZERO_EXTEND: |
| 7642 | case ISD::FP_EXTEND: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7643 | SDValue L, H; |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 7644 | SplitVectorOp(Node->getOperand(0), L, H); |
| 7645 | |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7646 | Lo = DAG.getNode(Node->getOpcode(), NewVT_Lo, L); |
| 7647 | Hi = DAG.getNode(Node->getOpcode(), NewVT_Hi, H); |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 7648 | break; |
| 7649 | } |
Mon P Wang | 77cdf30 | 2008-11-10 20:54:11 +0000 | [diff] [blame] | 7650 | case ISD::CONVERT_RNDSAT: { |
| 7651 | ISD::CvtCode CvtCode = cast<CvtRndSatSDNode>(Node)->getCvtCode(); |
| 7652 | SDValue L, H; |
| 7653 | SplitVectorOp(Node->getOperand(0), L, H); |
| 7654 | SDValue DTyOpL = DAG.getValueType(NewVT_Lo); |
| 7655 | SDValue DTyOpH = DAG.getValueType(NewVT_Hi); |
| 7656 | SDValue STyOpL = DAG.getValueType(L.getValueType()); |
| 7657 | SDValue STyOpH = DAG.getValueType(H.getValueType()); |
| 7658 | |
| 7659 | SDValue RndOp = Node->getOperand(3); |
| 7660 | SDValue SatOp = Node->getOperand(4); |
| 7661 | |
| 7662 | Lo = DAG.getConvertRndSat(NewVT_Lo, L, DTyOpL, STyOpL, |
| 7663 | RndOp, SatOp, CvtCode); |
| 7664 | Hi = DAG.getConvertRndSat(NewVT_Hi, H, DTyOpH, STyOpH, |
| 7665 | RndOp, SatOp, CvtCode); |
| 7666 | break; |
| 7667 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7668 | case ISD::LOAD: { |
| 7669 | LoadSDNode *LD = cast<LoadSDNode>(Node); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7670 | SDValue Ch = LD->getChain(); |
| 7671 | SDValue Ptr = LD->getBasePtr(); |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 7672 | ISD::LoadExtType ExtType = LD->getExtensionType(); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7673 | const Value *SV = LD->getSrcValue(); |
| 7674 | int SVOffset = LD->getSrcValueOffset(); |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 7675 | MVT MemoryVT = LD->getMemoryVT(); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7676 | unsigned Alignment = LD->getAlignment(); |
| 7677 | bool isVolatile = LD->isVolatile(); |
| 7678 | |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 7679 | assert(LD->isUnindexed() && "Indexed vector loads are not supported yet!"); |
| 7680 | SDValue Offset = DAG.getNode(ISD::UNDEF, Ptr.getValueType()); |
| 7681 | |
| 7682 | MVT MemNewEltVT = MemoryVT.getVectorElementType(); |
| 7683 | MVT MemNewVT_Lo = MVT::getVectorVT(MemNewEltVT, NewNumElts_Lo); |
| 7684 | MVT MemNewVT_Hi = MVT::getVectorVT(MemNewEltVT, NewNumElts_Hi); |
| 7685 | |
| 7686 | Lo = DAG.getLoad(ISD::UNINDEXED, ExtType, |
| 7687 | NewVT_Lo, Ch, Ptr, Offset, |
| 7688 | SV, SVOffset, MemNewVT_Lo, isVolatile, Alignment); |
| 7689 | unsigned IncrementSize = NewNumElts_Lo * MemNewEltVT.getSizeInBits()/8; |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7690 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 7691 | DAG.getIntPtrConstant(IncrementSize)); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7692 | SVOffset += IncrementSize; |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 7693 | Alignment = MinAlign(Alignment, IncrementSize); |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 7694 | Hi = DAG.getLoad(ISD::UNINDEXED, ExtType, |
| 7695 | NewVT_Hi, Ch, Ptr, Offset, |
| 7696 | SV, SVOffset, MemNewVT_Hi, isVolatile, Alignment); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7697 | |
| 7698 | // Build a factor node to remember that this load is independent of the |
| 7699 | // other one. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7700 | SDValue TF = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1), |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7701 | Hi.getValue(1)); |
| 7702 | |
| 7703 | // Remember that we legalized the chain. |
| 7704 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(TF)); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7705 | break; |
| 7706 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7707 | case ISD::BIT_CONVERT: { |
Chris Lattner | 7692eb4 | 2006-03-23 21:16:34 +0000 | [diff] [blame] | 7708 | // We know the result is a vector. The input may be either a vector or a |
| 7709 | // scalar value. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7710 | SDValue InOp = Node->getOperand(0); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 7711 | if (!InOp.getValueType().isVector() || |
| 7712 | InOp.getValueType().getVectorNumElements() == 1) { |
Dan Gohman | 10a7aa6 | 2007-06-29 00:09:08 +0000 | [diff] [blame] | 7713 | // The input is a scalar or single-element vector. |
| 7714 | // Lower to a store/load so that it can be split. |
| 7715 | // FIXME: this could be improved probably. |
Mon P Wang | 2920d2b | 2008-07-15 05:28:34 +0000 | [diff] [blame] | 7716 | unsigned LdAlign = TLI.getTargetData()->getPrefTypeAlignment( |
| 7717 | Op.getValueType().getTypeForMVT()); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7718 | SDValue Ptr = DAG.CreateStackTemporary(InOp.getValueType(), LdAlign); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 7719 | int FI = cast<FrameIndexSDNode>(Ptr.getNode())->getIndex(); |
Chris Lattner | 7692eb4 | 2006-03-23 21:16:34 +0000 | [diff] [blame] | 7720 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7721 | SDValue St = DAG.getStore(DAG.getEntryNode(), |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 7722 | InOp, Ptr, |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 7723 | PseudoSourceValue::getFixedStack(FI), 0); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 7724 | InOp = DAG.getLoad(Op.getValueType(), St, Ptr, |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 7725 | PseudoSourceValue::getFixedStack(FI), 0); |
Chris Lattner | 7692eb4 | 2006-03-23 21:16:34 +0000 | [diff] [blame] | 7726 | } |
Dan Gohman | 10a7aa6 | 2007-06-29 00:09:08 +0000 | [diff] [blame] | 7727 | // Split the vector and convert each of the pieces now. |
| 7728 | SplitVectorOp(InOp, Lo, Hi); |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7729 | Lo = DAG.getNode(ISD::BIT_CONVERT, NewVT_Lo, Lo); |
| 7730 | Hi = DAG.getNode(ISD::BIT_CONVERT, NewVT_Hi, Hi); |
Dan Gohman | 10a7aa6 | 2007-06-29 00:09:08 +0000 | [diff] [blame] | 7731 | break; |
Chris Lattner | 7692eb4 | 2006-03-23 21:16:34 +0000 | [diff] [blame] | 7732 | } |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7733 | } |
| 7734 | |
| 7735 | // Remember in a map if the values will be reused later. |
Chris Lattner | 40030bf | 2007-02-04 01:17:38 +0000 | [diff] [blame] | 7736 | bool isNew = |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7737 | SplitNodes.insert(std::make_pair(Op, std::make_pair(Lo, Hi))).second; |
Dan Gohman | 10a7aa6 | 2007-06-29 00:09:08 +0000 | [diff] [blame] | 7738 | assert(isNew && "Value already split?!?"); |
Evan Cheng | 24ac408 | 2008-11-24 07:09:49 +0000 | [diff] [blame] | 7739 | isNew = isNew; |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7740 | } |
| 7741 | |
| 7742 | |
Dan Gohman | 89b20c0 | 2007-06-27 14:06:22 +0000 | [diff] [blame] | 7743 | /// ScalarizeVectorOp - Given an operand of single-element vector type |
| 7744 | /// (e.g. v1f32), convert it into the equivalent operation that returns a |
| 7745 | /// scalar (e.g. f32) value. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7746 | SDValue SelectionDAGLegalize::ScalarizeVectorOp(SDValue Op) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 7747 | assert(Op.getValueType().isVector() && "Bad ScalarizeVectorOp invocation!"); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 7748 | SDNode *Node = Op.getNode(); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 7749 | MVT NewVT = Op.getValueType().getVectorElementType(); |
| 7750 | assert(Op.getValueType().getVectorNumElements() == 1); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7751 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7752 | // See if we already scalarized it. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7753 | std::map<SDValue, SDValue>::iterator I = ScalarizedNodes.find(Op); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7754 | if (I != ScalarizedNodes.end()) return I->second; |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7755 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7756 | SDValue Result; |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7757 | switch (Node->getOpcode()) { |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 7758 | default: |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 7759 | #ifndef NDEBUG |
Dan Gohman | 3983358 | 2007-06-04 16:17:33 +0000 | [diff] [blame] | 7760 | Node->dump(&DAG); cerr << "\n"; |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 7761 | #endif |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7762 | assert(0 && "Unknown vector operation in ScalarizeVectorOp!"); |
| 7763 | case ISD::ADD: |
| 7764 | case ISD::FADD: |
| 7765 | case ISD::SUB: |
| 7766 | case ISD::FSUB: |
| 7767 | case ISD::MUL: |
| 7768 | case ISD::FMUL: |
| 7769 | case ISD::SDIV: |
| 7770 | case ISD::UDIV: |
| 7771 | case ISD::FDIV: |
| 7772 | case ISD::SREM: |
| 7773 | case ISD::UREM: |
| 7774 | case ISD::FREM: |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 7775 | case ISD::FPOW: |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7776 | case ISD::AND: |
| 7777 | case ISD::OR: |
| 7778 | case ISD::XOR: |
| 7779 | Result = DAG.getNode(Node->getOpcode(), |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7780 | NewVT, |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7781 | ScalarizeVectorOp(Node->getOperand(0)), |
| 7782 | ScalarizeVectorOp(Node->getOperand(1))); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7783 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7784 | case ISD::FNEG: |
| 7785 | case ISD::FABS: |
| 7786 | case ISD::FSQRT: |
| 7787 | case ISD::FSIN: |
| 7788 | case ISD::FCOS: |
Dale Johannesen | 7794f2a | 2008-09-04 00:47:13 +0000 | [diff] [blame] | 7789 | case ISD::FLOG: |
| 7790 | case ISD::FLOG2: |
| 7791 | case ISD::FLOG10: |
| 7792 | case ISD::FEXP: |
| 7793 | case ISD::FEXP2: |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 7794 | case ISD::FP_TO_SINT: |
| 7795 | case ISD::FP_TO_UINT: |
| 7796 | case ISD::SINT_TO_FP: |
| 7797 | case ISD::UINT_TO_FP: |
| 7798 | case ISD::SIGN_EXTEND: |
| 7799 | case ISD::ZERO_EXTEND: |
| 7800 | case ISD::ANY_EXTEND: |
| 7801 | case ISD::TRUNCATE: |
| 7802 | case ISD::FP_EXTEND: |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7803 | Result = DAG.getNode(Node->getOpcode(), |
| 7804 | NewVT, |
| 7805 | ScalarizeVectorOp(Node->getOperand(0))); |
| 7806 | break; |
Mon P Wang | 77cdf30 | 2008-11-10 20:54:11 +0000 | [diff] [blame] | 7807 | case ISD::CONVERT_RNDSAT: { |
| 7808 | SDValue Op0 = ScalarizeVectorOp(Node->getOperand(0)); |
| 7809 | Result = DAG.getConvertRndSat(NewVT, Op0, |
| 7810 | DAG.getValueType(NewVT), |
| 7811 | DAG.getValueType(Op0.getValueType()), |
| 7812 | Node->getOperand(3), |
| 7813 | Node->getOperand(4), |
| 7814 | cast<CvtRndSatSDNode>(Node)->getCvtCode()); |
| 7815 | break; |
| 7816 | } |
Dan Gohman | 9e04c82 | 2007-10-12 14:13:46 +0000 | [diff] [blame] | 7817 | case ISD::FPOWI: |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 7818 | case ISD::FP_ROUND: |
Dan Gohman | 9e04c82 | 2007-10-12 14:13:46 +0000 | [diff] [blame] | 7819 | Result = DAG.getNode(Node->getOpcode(), |
| 7820 | NewVT, |
| 7821 | ScalarizeVectorOp(Node->getOperand(0)), |
| 7822 | Node->getOperand(1)); |
| 7823 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7824 | case ISD::LOAD: { |
| 7825 | LoadSDNode *LD = cast<LoadSDNode>(Node); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7826 | SDValue Ch = LegalizeOp(LD->getChain()); // Legalize the chain. |
| 7827 | SDValue Ptr = LegalizeOp(LD->getBasePtr()); // Legalize the pointer. |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 7828 | ISD::LoadExtType ExtType = LD->getExtensionType(); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7829 | const Value *SV = LD->getSrcValue(); |
| 7830 | int SVOffset = LD->getSrcValueOffset(); |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 7831 | MVT MemoryVT = LD->getMemoryVT(); |
| 7832 | unsigned Alignment = LD->getAlignment(); |
| 7833 | bool isVolatile = LD->isVolatile(); |
| 7834 | |
| 7835 | assert(LD->isUnindexed() && "Indexed vector loads are not supported yet!"); |
| 7836 | SDValue Offset = DAG.getNode(ISD::UNDEF, Ptr.getValueType()); |
| 7837 | |
| 7838 | Result = DAG.getLoad(ISD::UNINDEXED, ExtType, |
| 7839 | NewVT, Ch, Ptr, Offset, SV, SVOffset, |
| 7840 | MemoryVT.getVectorElementType(), |
| 7841 | isVolatile, Alignment); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7842 | |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7843 | // Remember that we legalized the chain. |
| 7844 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1))); |
| 7845 | break; |
| 7846 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7847 | case ISD::BUILD_VECTOR: |
| 7848 | Result = Node->getOperand(0); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7849 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7850 | case ISD::INSERT_VECTOR_ELT: |
| 7851 | // Returning the inserted scalar element. |
| 7852 | Result = Node->getOperand(1); |
| 7853 | break; |
| 7854 | case ISD::CONCAT_VECTORS: |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 7855 | assert(Node->getOperand(0).getValueType() == NewVT && |
| 7856 | "Concat of non-legal vectors not yet supported!"); |
| 7857 | Result = Node->getOperand(0); |
| 7858 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7859 | case ISD::VECTOR_SHUFFLE: { |
| 7860 | // 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] | 7861 | SDValue EltNum = Node->getOperand(2).getOperand(0); |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 7862 | if (cast<ConstantSDNode>(EltNum)->getZExtValue()) |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7863 | Result = ScalarizeVectorOp(Node->getOperand(1)); |
| 7864 | else |
| 7865 | Result = ScalarizeVectorOp(Node->getOperand(0)); |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 7866 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7867 | } |
| 7868 | case ISD::EXTRACT_SUBVECTOR: |
Mon P Wang | e0b436a | 2008-11-06 22:52:21 +0000 | [diff] [blame] | 7869 | Result = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, NewVT, Node->getOperand(0), |
Mon P Wang | aeb06d2 | 2008-11-10 04:46:22 +0000 | [diff] [blame] | 7870 | Node->getOperand(1)); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 7871 | break; |
Evan Cheng | 446efdd | 2008-05-16 17:19:05 +0000 | [diff] [blame] | 7872 | case ISD::BIT_CONVERT: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7873 | SDValue Op0 = Op.getOperand(0); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 7874 | if (Op0.getValueType().getVectorNumElements() == 1) |
Evan Cheng | 446efdd | 2008-05-16 17:19:05 +0000 | [diff] [blame] | 7875 | Op0 = ScalarizeVectorOp(Op0); |
| 7876 | Result = DAG.getNode(ISD::BIT_CONVERT, NewVT, Op0); |
Chris Lattner | 5b2316e | 2006-03-28 20:24:43 +0000 | [diff] [blame] | 7877 | break; |
Evan Cheng | 446efdd | 2008-05-16 17:19:05 +0000 | [diff] [blame] | 7878 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7879 | case ISD::SELECT: |
Chris Lattner | b22e35a | 2006-04-08 22:22:57 +0000 | [diff] [blame] | 7880 | Result = DAG.getNode(ISD::SELECT, NewVT, Op.getOperand(0), |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7881 | ScalarizeVectorOp(Op.getOperand(1)), |
| 7882 | ScalarizeVectorOp(Op.getOperand(2))); |
Chris Lattner | b22e35a | 2006-04-08 22:22:57 +0000 | [diff] [blame] | 7883 | break; |
Chris Lattner | 80c1a56 | 2008-06-30 02:43:01 +0000 | [diff] [blame] | 7884 | case ISD::SELECT_CC: |
| 7885 | Result = DAG.getNode(ISD::SELECT_CC, NewVT, Node->getOperand(0), |
| 7886 | Node->getOperand(1), |
| 7887 | ScalarizeVectorOp(Op.getOperand(2)), |
| 7888 | ScalarizeVectorOp(Op.getOperand(3)), |
| 7889 | Node->getOperand(4)); |
| 7890 | break; |
Nate Begeman | 0d1704b | 2008-05-12 23:09:43 +0000 | [diff] [blame] | 7891 | case ISD::VSETCC: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7892 | SDValue Op0 = ScalarizeVectorOp(Op.getOperand(0)); |
| 7893 | SDValue Op1 = ScalarizeVectorOp(Op.getOperand(1)); |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 7894 | Result = DAG.getNode(ISD::SETCC, TLI.getSetCCResultType(Op0.getValueType()), |
| 7895 | Op0, Op1, Op.getOperand(2)); |
Nate Begeman | 0d1704b | 2008-05-12 23:09:43 +0000 | [diff] [blame] | 7896 | Result = DAG.getNode(ISD::SELECT, NewVT, Result, |
| 7897 | DAG.getConstant(-1ULL, NewVT), |
| 7898 | DAG.getConstant(0ULL, NewVT)); |
| 7899 | break; |
| 7900 | } |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7901 | } |
| 7902 | |
| 7903 | if (TLI.isTypeLegal(NewVT)) |
| 7904 | Result = LegalizeOp(Result); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7905 | bool isNew = ScalarizedNodes.insert(std::make_pair(Op, Result)).second; |
| 7906 | assert(isNew && "Value already scalarized?"); |
Evan Cheng | 24ac408 | 2008-11-24 07:09:49 +0000 | [diff] [blame] | 7907 | isNew = isNew; |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7908 | return Result; |
| 7909 | } |
| 7910 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 7911 | |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 7912 | SDValue SelectionDAGLegalize::WidenVectorOp(SDValue Op, MVT WidenVT) { |
| 7913 | std::map<SDValue, SDValue>::iterator I = WidenNodes.find(Op); |
| 7914 | if (I != WidenNodes.end()) return I->second; |
| 7915 | |
| 7916 | MVT VT = Op.getValueType(); |
| 7917 | assert(VT.isVector() && "Cannot widen non-vector type!"); |
| 7918 | |
| 7919 | SDValue Result; |
| 7920 | SDNode *Node = Op.getNode(); |
| 7921 | MVT EVT = VT.getVectorElementType(); |
| 7922 | |
| 7923 | unsigned NumElts = VT.getVectorNumElements(); |
| 7924 | unsigned NewNumElts = WidenVT.getVectorNumElements(); |
| 7925 | assert(NewNumElts > NumElts && "Cannot widen to smaller type!"); |
| 7926 | assert(NewNumElts < 17); |
| 7927 | |
| 7928 | // When widen is called, it is assumed that it is more efficient to use a |
| 7929 | // wide type. The default action is to widen to operation to a wider legal |
| 7930 | // vector type and then do the operation if it is legal by calling LegalizeOp |
| 7931 | // again. If there is no vector equivalent, we will unroll the operation, do |
| 7932 | // it, and rebuild the vector. If most of the operations are vectorizible to |
| 7933 | // the legal type, the resulting code will be more efficient. If this is not |
| 7934 | // the case, the resulting code will preform badly as we end up generating |
| 7935 | // 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] | 7936 | // that is responsible for seeing this doesn't happen. |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 7937 | switch (Node->getOpcode()) { |
| 7938 | default: |
| 7939 | #ifndef NDEBUG |
| 7940 | Node->dump(&DAG); |
| 7941 | #endif |
| 7942 | assert(0 && "Unexpected operation in WidenVectorOp!"); |
| 7943 | break; |
| 7944 | case ISD::CopyFromReg: |
Mon P Wang | 49292f1 | 2008-11-15 06:05:52 +0000 | [diff] [blame] | 7945 | assert(0 && "CopyFromReg doesn't need widening!"); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 7946 | case ISD::Constant: |
| 7947 | case ISD::ConstantFP: |
| 7948 | // To build a vector of these elements, clients should call BuildVector |
| 7949 | // and with each element instead of creating a node with a vector type |
| 7950 | assert(0 && "Unexpected operation in WidenVectorOp!"); |
| 7951 | case ISD::VAARG: |
| 7952 | // Variable Arguments with vector types doesn't make any sense to me |
| 7953 | assert(0 && "Unexpected operation in WidenVectorOp!"); |
| 7954 | break; |
Mon P Wang | 49292f1 | 2008-11-15 06:05:52 +0000 | [diff] [blame] | 7955 | case ISD::UNDEF: |
| 7956 | Result = DAG.getNode(ISD::UNDEF, WidenVT); |
| 7957 | break; |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 7958 | case ISD::BUILD_VECTOR: { |
| 7959 | // Build a vector with undefined for the new nodes |
| 7960 | SDValueVector NewOps(Node->op_begin(), Node->op_end()); |
| 7961 | for (unsigned i = NumElts; i < NewNumElts; ++i) { |
| 7962 | NewOps.push_back(DAG.getNode(ISD::UNDEF,EVT)); |
| 7963 | } |
| 7964 | Result = DAG.getNode(ISD::BUILD_VECTOR, WidenVT, &NewOps[0], NewOps.size()); |
| 7965 | break; |
| 7966 | } |
| 7967 | case ISD::INSERT_VECTOR_ELT: { |
| 7968 | SDValue Tmp1 = WidenVectorOp(Node->getOperand(0), WidenVT); |
| 7969 | Result = DAG.getNode(ISD::INSERT_VECTOR_ELT, WidenVT, Tmp1, |
| 7970 | Node->getOperand(1), Node->getOperand(2)); |
| 7971 | break; |
| 7972 | } |
| 7973 | case ISD::VECTOR_SHUFFLE: { |
| 7974 | SDValue Tmp1 = WidenVectorOp(Node->getOperand(0), WidenVT); |
| 7975 | SDValue Tmp2 = WidenVectorOp(Node->getOperand(1), WidenVT); |
| 7976 | // VECTOR_SHUFFLE 3rd operand must be a constant build vector that is |
| 7977 | // used as permutation array. We build the vector here instead of widening |
| 7978 | // because we don't want to legalize and have it turned to something else. |
| 7979 | SDValue PermOp = Node->getOperand(2); |
| 7980 | SDValueVector NewOps; |
| 7981 | MVT PVT = PermOp.getValueType().getVectorElementType(); |
| 7982 | for (unsigned i = 0; i < NumElts; ++i) { |
| 7983 | if (PermOp.getOperand(i).getOpcode() == ISD::UNDEF) { |
| 7984 | NewOps.push_back(PermOp.getOperand(i)); |
| 7985 | } else { |
| 7986 | unsigned Idx = |
Mon P Wang | e1a0b2e | 2008-12-13 08:15:14 +0000 | [diff] [blame] | 7987 | cast<ConstantSDNode>(PermOp.getOperand(i))->getZExtValue(); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 7988 | if (Idx < NumElts) { |
| 7989 | NewOps.push_back(PermOp.getOperand(i)); |
| 7990 | } |
| 7991 | else { |
| 7992 | NewOps.push_back(DAG.getConstant(Idx + NewNumElts - NumElts, |
| 7993 | PermOp.getOperand(i).getValueType())); |
| 7994 | } |
| 7995 | } |
| 7996 | } |
| 7997 | for (unsigned i = NumElts; i < NewNumElts; ++i) { |
| 7998 | NewOps.push_back(DAG.getNode(ISD::UNDEF,PVT)); |
| 7999 | } |
| 8000 | |
| 8001 | SDValue Tmp3 = DAG.getNode(ISD::BUILD_VECTOR, |
| 8002 | MVT::getVectorVT(PVT, NewOps.size()), |
| 8003 | &NewOps[0], NewOps.size()); |
| 8004 | |
| 8005 | Result = DAG.getNode(ISD::VECTOR_SHUFFLE, WidenVT, Tmp1, Tmp2, Tmp3); |
| 8006 | break; |
| 8007 | } |
| 8008 | case ISD::LOAD: { |
| 8009 | // If the load widen returns true, we can use a single load for the |
| 8010 | // vector. Otherwise, it is returning a token factor for multiple |
| 8011 | // loads. |
| 8012 | SDValue TFOp; |
| 8013 | if (LoadWidenVectorOp(Result, TFOp, Op, WidenVT)) |
| 8014 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(TFOp.getValue(1))); |
| 8015 | else |
| 8016 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(TFOp.getValue(0))); |
| 8017 | break; |
| 8018 | } |
| 8019 | |
| 8020 | case ISD::BIT_CONVERT: { |
| 8021 | SDValue Tmp1 = Node->getOperand(0); |
| 8022 | // Converts between two different types so we need to determine |
| 8023 | // the correct widen type for the input operand. |
Mon P Wang | 87c8a8f | 2008-12-18 20:03:17 +0000 | [diff] [blame] | 8024 | MVT InVT = Tmp1.getValueType(); |
| 8025 | unsigned WidenSize = WidenVT.getSizeInBits(); |
| 8026 | if (InVT.isVector()) { |
| 8027 | MVT InEltVT = InVT.getVectorElementType(); |
| 8028 | unsigned InEltSize = InEltVT.getSizeInBits(); |
| 8029 | assert(WidenSize % InEltSize == 0 && |
| 8030 | "can not widen bit convert that are not multiple of element type"); |
| 8031 | MVT NewInWidenVT = MVT::getVectorVT(InEltVT, WidenSize / InEltSize); |
| 8032 | Tmp1 = WidenVectorOp(Tmp1, NewInWidenVT); |
| 8033 | assert(Tmp1.getValueType().getSizeInBits() == WidenVT.getSizeInBits()); |
| 8034 | Result = DAG.getNode(ISD::BIT_CONVERT, WidenVT, Tmp1); |
| 8035 | } else { |
| 8036 | // If the result size is a multiple of the input size, widen the input |
| 8037 | // and then convert. |
| 8038 | unsigned InSize = InVT.getSizeInBits(); |
| 8039 | assert(WidenSize % InSize == 0 && |
| 8040 | "can not widen bit convert that are not multiple of element type"); |
| 8041 | unsigned NewNumElts = WidenSize / InSize; |
| 8042 | SmallVector<SDValue, 16> Ops(NewNumElts); |
| 8043 | SDValue UndefVal = DAG.getNode(ISD::UNDEF, InVT); |
| 8044 | Ops[0] = Tmp1; |
| 8045 | for (unsigned i = 1; i < NewNumElts; ++i) |
| 8046 | Ops[i] = UndefVal; |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8047 | |
Mon P Wang | 87c8a8f | 2008-12-18 20:03:17 +0000 | [diff] [blame] | 8048 | MVT NewInVT = MVT::getVectorVT(InVT, NewNumElts); |
| 8049 | Result = DAG.getNode(ISD::BUILD_VECTOR, NewInVT, &Ops[0], NewNumElts); |
| 8050 | Result = DAG.getNode(ISD::BIT_CONVERT, WidenVT, Result); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8051 | } |
| 8052 | break; |
| 8053 | } |
| 8054 | |
| 8055 | case ISD::SINT_TO_FP: |
| 8056 | case ISD::UINT_TO_FP: |
| 8057 | case ISD::FP_TO_SINT: |
Mon P Wang | 87c8a8f | 2008-12-18 20:03:17 +0000 | [diff] [blame] | 8058 | case ISD::FP_TO_UINT: |
| 8059 | case ISD::FP_ROUND: { |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8060 | SDValue Tmp1 = Node->getOperand(0); |
| 8061 | // Converts between two different types so we need to determine |
| 8062 | // the correct widen type for the input operand. |
| 8063 | MVT TVT = Tmp1.getValueType(); |
| 8064 | assert(TVT.isVector() && "can not widen non vector type"); |
| 8065 | MVT TEVT = TVT.getVectorElementType(); |
| 8066 | MVT TWidenVT = MVT::getVectorVT(TEVT, NewNumElts); |
| 8067 | Tmp1 = WidenVectorOp(Tmp1, TWidenVT); |
| 8068 | assert(Tmp1.getValueType().getVectorNumElements() == NewNumElts); |
| 8069 | Result = DAG.getNode(Node->getOpcode(), WidenVT, Tmp1); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8070 | break; |
| 8071 | } |
| 8072 | |
| 8073 | case ISD::FP_EXTEND: |
| 8074 | assert(0 && "Case not implemented. Dynamically dead with 2 FP types!"); |
| 8075 | case ISD::TRUNCATE: |
| 8076 | case ISD::SIGN_EXTEND: |
| 8077 | case ISD::ZERO_EXTEND: |
| 8078 | case ISD::ANY_EXTEND: |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8079 | case ISD::SIGN_EXTEND_INREG: |
| 8080 | case ISD::FABS: |
| 8081 | case ISD::FNEG: |
| 8082 | case ISD::FSQRT: |
| 8083 | case ISD::FSIN: |
Mon P Wang | 49292f1 | 2008-11-15 06:05:52 +0000 | [diff] [blame] | 8084 | case ISD::FCOS: |
| 8085 | case ISD::CTPOP: |
| 8086 | case ISD::CTTZ: |
| 8087 | case ISD::CTLZ: { |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8088 | // Unary op widening |
Mon P Wang | 87c8a8f | 2008-12-18 20:03:17 +0000 | [diff] [blame] | 8089 | SDValue Tmp1; |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8090 | Tmp1 = WidenVectorOp(Node->getOperand(0), WidenVT); |
| 8091 | assert(Tmp1.getValueType() == WidenVT); |
| 8092 | Result = DAG.getNode(Node->getOpcode(), WidenVT, Tmp1); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8093 | break; |
| 8094 | } |
Mon P Wang | 77cdf30 | 2008-11-10 20:54:11 +0000 | [diff] [blame] | 8095 | case ISD::CONVERT_RNDSAT: { |
| 8096 | SDValue RndOp = Node->getOperand(3); |
| 8097 | SDValue SatOp = Node->getOperand(4); |
Mon P Wang | 77cdf30 | 2008-11-10 20:54:11 +0000 | [diff] [blame] | 8098 | SDValue SrcOp = Node->getOperand(0); |
| 8099 | |
| 8100 | // Converts between two different types so we need to determine |
| 8101 | // the correct widen type for the input operand. |
| 8102 | MVT SVT = SrcOp.getValueType(); |
| 8103 | assert(SVT.isVector() && "can not widen non vector type"); |
| 8104 | MVT SEVT = SVT.getVectorElementType(); |
| 8105 | MVT SWidenVT = MVT::getVectorVT(SEVT, NewNumElts); |
| 8106 | |
| 8107 | SrcOp = WidenVectorOp(SrcOp, SWidenVT); |
| 8108 | assert(SrcOp.getValueType() == WidenVT); |
| 8109 | SDValue DTyOp = DAG.getValueType(WidenVT); |
| 8110 | SDValue STyOp = DAG.getValueType(SrcOp.getValueType()); |
| 8111 | ISD::CvtCode CvtCode = cast<CvtRndSatSDNode>(Node)->getCvtCode(); |
| 8112 | |
| 8113 | Result = DAG.getConvertRndSat(WidenVT, SrcOp, DTyOp, STyOp, |
| 8114 | RndOp, SatOp, CvtCode); |
Mon P Wang | 77cdf30 | 2008-11-10 20:54:11 +0000 | [diff] [blame] | 8115 | break; |
| 8116 | } |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8117 | case ISD::FPOW: |
| 8118 | case ISD::FPOWI: |
| 8119 | case ISD::ADD: |
| 8120 | case ISD::SUB: |
| 8121 | case ISD::MUL: |
| 8122 | case ISD::MULHS: |
| 8123 | case ISD::MULHU: |
| 8124 | case ISD::AND: |
| 8125 | case ISD::OR: |
| 8126 | case ISD::XOR: |
| 8127 | case ISD::FADD: |
| 8128 | case ISD::FSUB: |
| 8129 | case ISD::FMUL: |
| 8130 | case ISD::SDIV: |
| 8131 | case ISD::SREM: |
| 8132 | case ISD::FDIV: |
| 8133 | case ISD::FREM: |
| 8134 | case ISD::FCOPYSIGN: |
| 8135 | case ISD::UDIV: |
| 8136 | case ISD::UREM: |
| 8137 | case ISD::BSWAP: { |
| 8138 | // Binary op widening |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8139 | SDValue Tmp1 = WidenVectorOp(Node->getOperand(0), WidenVT); |
| 8140 | SDValue Tmp2 = WidenVectorOp(Node->getOperand(1), WidenVT); |
| 8141 | assert(Tmp1.getValueType() == WidenVT && Tmp2.getValueType() == WidenVT); |
| 8142 | Result = DAG.getNode(Node->getOpcode(), WidenVT, Tmp1, Tmp2); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8143 | break; |
| 8144 | } |
| 8145 | |
| 8146 | case ISD::SHL: |
| 8147 | case ISD::SRA: |
| 8148 | case ISD::SRL: { |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8149 | SDValue Tmp1 = WidenVectorOp(Node->getOperand(0), WidenVT); |
| 8150 | assert(Tmp1.getValueType() == WidenVT); |
Mon P Wang | fb13f00 | 2008-12-02 07:35:08 +0000 | [diff] [blame] | 8151 | SDValue ShOp = Node->getOperand(1); |
| 8152 | MVT ShVT = ShOp.getValueType(); |
| 8153 | MVT NewShVT = MVT::getVectorVT(ShVT.getVectorElementType(), |
| 8154 | WidenVT.getVectorNumElements()); |
| 8155 | ShOp = WidenVectorOp(ShOp, NewShVT); |
| 8156 | assert(ShOp.getValueType() == NewShVT); |
| 8157 | Result = DAG.getNode(Node->getOpcode(), WidenVT, Tmp1, ShOp); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8158 | break; |
| 8159 | } |
Mon P Wang | fb13f00 | 2008-12-02 07:35:08 +0000 | [diff] [blame] | 8160 | |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8161 | case ISD::EXTRACT_VECTOR_ELT: { |
| 8162 | SDValue Tmp1 = WidenVectorOp(Node->getOperand(0), WidenVT); |
| 8163 | assert(Tmp1.getValueType() == WidenVT); |
| 8164 | Result = DAG.getNode(Node->getOpcode(), EVT, Tmp1, Node->getOperand(1)); |
| 8165 | break; |
| 8166 | } |
| 8167 | case ISD::CONCAT_VECTORS: { |
| 8168 | // We concurrently support only widen on a multiple of the incoming vector. |
| 8169 | // We could widen on a multiple of the incoming operand if necessary. |
| 8170 | unsigned NumConcat = NewNumElts / NumElts; |
| 8171 | assert(NewNumElts % NumElts == 0 && "Can widen only a multiple of vector"); |
Mon P Wang | fb13f00 | 2008-12-02 07:35:08 +0000 | [diff] [blame] | 8172 | SDValue UndefVal = DAG.getNode(ISD::UNDEF, VT); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8173 | SmallVector<SDValue, 8> MOps; |
| 8174 | MOps.push_back(Op); |
| 8175 | for (unsigned i = 1; i != NumConcat; ++i) { |
| 8176 | MOps.push_back(UndefVal); |
| 8177 | } |
| 8178 | Result = LegalizeOp(DAG.getNode(ISD::CONCAT_VECTORS, WidenVT, |
| 8179 | &MOps[0], MOps.size())); |
| 8180 | break; |
| 8181 | } |
| 8182 | case ISD::EXTRACT_SUBVECTOR: { |
Mon P Wang | 49292f1 | 2008-11-15 06:05:52 +0000 | [diff] [blame] | 8183 | SDValue Tmp1 = Node->getOperand(0); |
| 8184 | SDValue Idx = Node->getOperand(1); |
| 8185 | ConstantSDNode *CIdx = dyn_cast<ConstantSDNode>(Idx); |
| 8186 | if (CIdx && CIdx->getZExtValue() == 0) { |
| 8187 | // Since we are access the start of the vector, the incoming |
| 8188 | // vector type might be the proper. |
| 8189 | MVT Tmp1VT = Tmp1.getValueType(); |
| 8190 | if (Tmp1VT == WidenVT) |
| 8191 | return Tmp1; |
| 8192 | else { |
| 8193 | unsigned Tmp1VTNumElts = Tmp1VT.getVectorNumElements(); |
| 8194 | if (Tmp1VTNumElts < NewNumElts) |
| 8195 | Result = WidenVectorOp(Tmp1, WidenVT); |
| 8196 | else |
| 8197 | Result = DAG.getNode(ISD::EXTRACT_SUBVECTOR, WidenVT, Tmp1, Idx); |
| 8198 | } |
| 8199 | } else if (NewNumElts % NumElts == 0) { |
| 8200 | // Widen the extracted subvector. |
| 8201 | unsigned NumConcat = NewNumElts / NumElts; |
| 8202 | SDValue UndefVal = DAG.getNode(ISD::UNDEF, VT); |
| 8203 | SmallVector<SDValue, 8> MOps; |
| 8204 | MOps.push_back(Op); |
| 8205 | for (unsigned i = 1; i != NumConcat; ++i) { |
| 8206 | MOps.push_back(UndefVal); |
| 8207 | } |
| 8208 | Result = LegalizeOp(DAG.getNode(ISD::CONCAT_VECTORS, WidenVT, |
| 8209 | &MOps[0], MOps.size())); |
| 8210 | } else { |
| 8211 | assert(0 && "can not widen extract subvector"); |
| 8212 | // This could be implemented using insert and build vector but I would |
| 8213 | // like to see when this happens. |
| 8214 | } |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8215 | break; |
| 8216 | } |
| 8217 | |
| 8218 | case ISD::SELECT: { |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8219 | // Determine new condition widen type and widen |
| 8220 | SDValue Cond1 = Node->getOperand(0); |
| 8221 | MVT CondVT = Cond1.getValueType(); |
| 8222 | assert(CondVT.isVector() && "can not widen non vector type"); |
| 8223 | MVT CondEVT = CondVT.getVectorElementType(); |
| 8224 | MVT CondWidenVT = MVT::getVectorVT(CondEVT, NewNumElts); |
| 8225 | Cond1 = WidenVectorOp(Cond1, CondWidenVT); |
| 8226 | assert(Cond1.getValueType() == CondWidenVT && "Condition not widen"); |
| 8227 | |
| 8228 | SDValue Tmp1 = WidenVectorOp(Node->getOperand(1), WidenVT); |
| 8229 | SDValue Tmp2 = WidenVectorOp(Node->getOperand(2), WidenVT); |
| 8230 | assert(Tmp1.getValueType() == WidenVT && Tmp2.getValueType() == WidenVT); |
| 8231 | Result = DAG.getNode(Node->getOpcode(), WidenVT, Cond1, Tmp1, Tmp2); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8232 | break; |
| 8233 | } |
| 8234 | |
| 8235 | case ISD::SELECT_CC: { |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8236 | // Determine new condition widen type and widen |
| 8237 | SDValue Cond1 = Node->getOperand(0); |
| 8238 | SDValue Cond2 = Node->getOperand(1); |
| 8239 | MVT CondVT = Cond1.getValueType(); |
| 8240 | assert(CondVT.isVector() && "can not widen non vector type"); |
| 8241 | assert(CondVT == Cond2.getValueType() && "mismatch lhs/rhs"); |
| 8242 | MVT CondEVT = CondVT.getVectorElementType(); |
| 8243 | MVT CondWidenVT = MVT::getVectorVT(CondEVT, NewNumElts); |
| 8244 | Cond1 = WidenVectorOp(Cond1, CondWidenVT); |
| 8245 | Cond2 = WidenVectorOp(Cond2, CondWidenVT); |
| 8246 | assert(Cond1.getValueType() == CondWidenVT && |
| 8247 | Cond2.getValueType() == CondWidenVT && "condition not widen"); |
| 8248 | |
| 8249 | SDValue Tmp1 = WidenVectorOp(Node->getOperand(2), WidenVT); |
| 8250 | SDValue Tmp2 = WidenVectorOp(Node->getOperand(3), WidenVT); |
| 8251 | assert(Tmp1.getValueType() == WidenVT && Tmp2.getValueType() == WidenVT && |
| 8252 | "operands not widen"); |
| 8253 | Result = DAG.getNode(Node->getOpcode(), WidenVT, Cond1, Cond2, Tmp1, |
| 8254 | Tmp2, Node->getOperand(4)); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8255 | break; |
Mon P Wang | 2eb13c3 | 2008-10-30 18:21:52 +0000 | [diff] [blame] | 8256 | } |
| 8257 | case ISD::VSETCC: { |
| 8258 | // Determine widen for the operand |
| 8259 | SDValue Tmp1 = Node->getOperand(0); |
| 8260 | MVT TmpVT = Tmp1.getValueType(); |
| 8261 | assert(TmpVT.isVector() && "can not widen non vector type"); |
| 8262 | MVT TmpEVT = TmpVT.getVectorElementType(); |
| 8263 | MVT TmpWidenVT = MVT::getVectorVT(TmpEVT, NewNumElts); |
| 8264 | Tmp1 = WidenVectorOp(Tmp1, TmpWidenVT); |
| 8265 | SDValue Tmp2 = WidenVectorOp(Node->getOperand(1), TmpWidenVT); |
Mon P Wang | 87c8a8f | 2008-12-18 20:03:17 +0000 | [diff] [blame] | 8266 | Result = DAG.getNode(Node->getOpcode(), WidenVT, Tmp1, Tmp2, |
Mon P Wang | 2eb13c3 | 2008-10-30 18:21:52 +0000 | [diff] [blame] | 8267 | Node->getOperand(2)); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8268 | break; |
| 8269 | } |
Dan Gohman | 0b1d4a7 | 2008-12-23 21:37:04 +0000 | [diff] [blame] | 8270 | case ISD::ATOMIC_CMP_SWAP: |
| 8271 | case ISD::ATOMIC_LOAD_ADD: |
| 8272 | case ISD::ATOMIC_LOAD_SUB: |
| 8273 | case ISD::ATOMIC_LOAD_AND: |
| 8274 | case ISD::ATOMIC_LOAD_OR: |
| 8275 | case ISD::ATOMIC_LOAD_XOR: |
| 8276 | case ISD::ATOMIC_LOAD_NAND: |
| 8277 | case ISD::ATOMIC_LOAD_MIN: |
| 8278 | case ISD::ATOMIC_LOAD_MAX: |
| 8279 | case ISD::ATOMIC_LOAD_UMIN: |
| 8280 | case ISD::ATOMIC_LOAD_UMAX: |
| 8281 | case ISD::ATOMIC_SWAP: { |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8282 | // For now, we assume that using vectors for these operations don't make |
| 8283 | // much sense so we just split it. We return an empty result |
| 8284 | SDValue X, Y; |
| 8285 | SplitVectorOp(Op, X, Y); |
| 8286 | return Result; |
| 8287 | break; |
| 8288 | } |
| 8289 | |
| 8290 | } // end switch (Node->getOpcode()) |
| 8291 | |
| 8292 | assert(Result.getNode() && "Didn't set a result!"); |
| 8293 | if (Result != Op) |
| 8294 | Result = LegalizeOp(Result); |
| 8295 | |
Mon P Wang | f007a8b | 2008-11-06 05:31:54 +0000 | [diff] [blame] | 8296 | AddWidenedOperand(Op, Result); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8297 | return Result; |
| 8298 | } |
| 8299 | |
| 8300 | // Utility function to find a legal vector type and its associated element |
| 8301 | // type from a preferred width and whose vector type must be the same size |
| 8302 | // as the VVT. |
| 8303 | // TLI: Target lowering used to determine legal types |
| 8304 | // Width: Preferred width of element type |
| 8305 | // VVT: Vector value type whose size we must match. |
| 8306 | // Returns VecEVT and EVT - the vector type and its associated element type |
Dan Gohman | 0d137d7 | 2009-01-15 16:43:02 +0000 | [diff] [blame] | 8307 | static void FindWidenVecType(const TargetLowering &TLI, unsigned Width, MVT VVT, |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8308 | MVT& EVT, MVT& VecEVT) { |
| 8309 | // We start with the preferred width, make it a power of 2 and see if |
| 8310 | // we can find a vector type of that width. If not, we reduce it by |
| 8311 | // another power of 2. If we have widen the type, a vector of bytes should |
| 8312 | // always be legal. |
| 8313 | assert(TLI.isTypeLegal(VVT)); |
| 8314 | unsigned EWidth = Width + 1; |
| 8315 | do { |
| 8316 | assert(EWidth > 0); |
| 8317 | EWidth = (1 << Log2_32(EWidth-1)); |
| 8318 | EVT = MVT::getIntegerVT(EWidth); |
| 8319 | unsigned NumEVT = VVT.getSizeInBits()/EWidth; |
| 8320 | VecEVT = MVT::getVectorVT(EVT, NumEVT); |
| 8321 | } while (!TLI.isTypeLegal(VecEVT) || |
| 8322 | VVT.getSizeInBits() != VecEVT.getSizeInBits()); |
| 8323 | } |
| 8324 | |
| 8325 | SDValue SelectionDAGLegalize::genWidenVectorLoads(SDValueVector& LdChain, |
| 8326 | SDValue Chain, |
| 8327 | SDValue BasePtr, |
| 8328 | const Value *SV, |
| 8329 | int SVOffset, |
| 8330 | unsigned Alignment, |
| 8331 | bool isVolatile, |
| 8332 | unsigned LdWidth, |
| 8333 | MVT ResType) { |
| 8334 | // We assume that we have good rules to handle loading power of two loads so |
| 8335 | // we break down the operations to power of 2 loads. The strategy is to |
| 8336 | // load the largest power of 2 that we can easily transform to a legal vector |
| 8337 | // and then insert into that vector, and the cast the result into the legal |
| 8338 | // vector that we want. This avoids unnecessary stack converts. |
| 8339 | // TODO: If the Ldwidth is legal, alignment is the same as the LdWidth, and |
| 8340 | // the load is nonvolatile, we an use a wider load for the value. |
| 8341 | // Find a vector length we can load a large chunk |
| 8342 | MVT EVT, VecEVT; |
| 8343 | unsigned EVTWidth; |
| 8344 | FindWidenVecType(TLI, LdWidth, ResType, EVT, VecEVT); |
| 8345 | EVTWidth = EVT.getSizeInBits(); |
| 8346 | |
| 8347 | SDValue LdOp = DAG.getLoad(EVT, Chain, BasePtr, SV, SVOffset, |
| 8348 | isVolatile, Alignment); |
| 8349 | SDValue VecOp = DAG.getNode(ISD::SCALAR_TO_VECTOR, VecEVT, LdOp); |
| 8350 | LdChain.push_back(LdOp.getValue(1)); |
| 8351 | |
| 8352 | // Check if we can load the element with one instruction |
| 8353 | if (LdWidth == EVTWidth) { |
| 8354 | return DAG.getNode(ISD::BIT_CONVERT, ResType, VecOp); |
| 8355 | } |
| 8356 | |
| 8357 | // The vector element order is endianness dependent. |
| 8358 | unsigned Idx = 1; |
| 8359 | LdWidth -= EVTWidth; |
| 8360 | unsigned Offset = 0; |
| 8361 | |
| 8362 | while (LdWidth > 0) { |
| 8363 | unsigned Increment = EVTWidth / 8; |
| 8364 | Offset += Increment; |
| 8365 | BasePtr = DAG.getNode(ISD::ADD, BasePtr.getValueType(), BasePtr, |
| 8366 | DAG.getIntPtrConstant(Increment)); |
| 8367 | |
| 8368 | if (LdWidth < EVTWidth) { |
| 8369 | // Our current type we are using is too large, use a smaller size by |
| 8370 | // using a smaller power of 2 |
| 8371 | unsigned oEVTWidth = EVTWidth; |
| 8372 | FindWidenVecType(TLI, LdWidth, ResType, EVT, VecEVT); |
| 8373 | EVTWidth = EVT.getSizeInBits(); |
| 8374 | // Readjust position and vector position based on new load type |
Mon P Wang | 49292f1 | 2008-11-15 06:05:52 +0000 | [diff] [blame] | 8375 | Idx = Idx * (oEVTWidth/EVTWidth); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8376 | VecOp = DAG.getNode(ISD::BIT_CONVERT, VecEVT, VecOp); |
| 8377 | } |
| 8378 | |
| 8379 | SDValue LdOp = DAG.getLoad(EVT, Chain, BasePtr, SV, |
| 8380 | SVOffset+Offset, isVolatile, |
| 8381 | MinAlign(Alignment, Offset)); |
| 8382 | LdChain.push_back(LdOp.getValue(1)); |
| 8383 | VecOp = DAG.getNode(ISD::INSERT_VECTOR_ELT, VecEVT, VecOp, LdOp, |
| 8384 | DAG.getIntPtrConstant(Idx++)); |
| 8385 | |
| 8386 | LdWidth -= EVTWidth; |
| 8387 | } |
| 8388 | |
| 8389 | return DAG.getNode(ISD::BIT_CONVERT, ResType, VecOp); |
| 8390 | } |
| 8391 | |
| 8392 | bool SelectionDAGLegalize::LoadWidenVectorOp(SDValue& Result, |
| 8393 | SDValue& TFOp, |
| 8394 | SDValue Op, |
| 8395 | MVT NVT) { |
| 8396 | // TODO: Add support for ConcatVec and the ability to load many vector |
| 8397 | // types (e.g., v4i8). This will not work when a vector register |
| 8398 | // to memory mapping is strange (e.g., vector elements are not |
| 8399 | // stored in some sequential order). |
| 8400 | |
| 8401 | // It must be true that the widen vector type is bigger than where |
| 8402 | // we need to load from. |
| 8403 | LoadSDNode *LD = cast<LoadSDNode>(Op.getNode()); |
| 8404 | MVT LdVT = LD->getMemoryVT(); |
| 8405 | assert(LdVT.isVector() && NVT.isVector()); |
| 8406 | assert(LdVT.getVectorElementType() == NVT.getVectorElementType()); |
| 8407 | |
| 8408 | // Load information |
| 8409 | SDValue Chain = LD->getChain(); |
| 8410 | SDValue BasePtr = LD->getBasePtr(); |
| 8411 | int SVOffset = LD->getSrcValueOffset(); |
| 8412 | unsigned Alignment = LD->getAlignment(); |
| 8413 | bool isVolatile = LD->isVolatile(); |
| 8414 | const Value *SV = LD->getSrcValue(); |
| 8415 | unsigned int LdWidth = LdVT.getSizeInBits(); |
| 8416 | |
| 8417 | // Load value as a large register |
| 8418 | SDValueVector LdChain; |
| 8419 | Result = genWidenVectorLoads(LdChain, Chain, BasePtr, SV, SVOffset, |
| 8420 | Alignment, isVolatile, LdWidth, NVT); |
| 8421 | |
| 8422 | if (LdChain.size() == 1) { |
| 8423 | TFOp = LdChain[0]; |
| 8424 | return true; |
| 8425 | } |
| 8426 | else { |
| 8427 | TFOp=DAG.getNode(ISD::TokenFactor, MVT::Other, &LdChain[0], LdChain.size()); |
| 8428 | return false; |
| 8429 | } |
| 8430 | } |
| 8431 | |
| 8432 | |
| 8433 | void SelectionDAGLegalize::genWidenVectorStores(SDValueVector& StChain, |
| 8434 | SDValue Chain, |
| 8435 | SDValue BasePtr, |
| 8436 | const Value *SV, |
| 8437 | int SVOffset, |
| 8438 | unsigned Alignment, |
| 8439 | bool isVolatile, |
Mon P Wang | 49292f1 | 2008-11-15 06:05:52 +0000 | [diff] [blame] | 8440 | SDValue ValOp, |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8441 | unsigned StWidth) { |
| 8442 | // Breaks the stores into a series of power of 2 width stores. For any |
| 8443 | // width, we convert the vector to the vector of element size that we |
| 8444 | // want to store. This avoids requiring a stack convert. |
| 8445 | |
| 8446 | // Find a width of the element type we can store with |
| 8447 | MVT VVT = ValOp.getValueType(); |
| 8448 | MVT EVT, VecEVT; |
| 8449 | unsigned EVTWidth; |
| 8450 | FindWidenVecType(TLI, StWidth, VVT, EVT, VecEVT); |
| 8451 | EVTWidth = EVT.getSizeInBits(); |
| 8452 | |
| 8453 | SDValue VecOp = DAG.getNode(ISD::BIT_CONVERT, VecEVT, ValOp); |
| 8454 | SDValue EOp = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, EVT, VecOp, |
Mon P Wang | e0b436a | 2008-11-06 22:52:21 +0000 | [diff] [blame] | 8455 | DAG.getIntPtrConstant(0)); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8456 | SDValue StOp = DAG.getStore(Chain, EOp, BasePtr, SV, SVOffset, |
| 8457 | isVolatile, Alignment); |
| 8458 | StChain.push_back(StOp); |
| 8459 | |
| 8460 | // Check if we are done |
| 8461 | if (StWidth == EVTWidth) { |
| 8462 | return; |
| 8463 | } |
| 8464 | |
| 8465 | unsigned Idx = 1; |
| 8466 | StWidth -= EVTWidth; |
| 8467 | unsigned Offset = 0; |
| 8468 | |
| 8469 | while (StWidth > 0) { |
| 8470 | unsigned Increment = EVTWidth / 8; |
| 8471 | Offset += Increment; |
| 8472 | BasePtr = DAG.getNode(ISD::ADD, BasePtr.getValueType(), BasePtr, |
| 8473 | DAG.getIntPtrConstant(Increment)); |
| 8474 | |
| 8475 | if (StWidth < EVTWidth) { |
| 8476 | // Our current type we are using is too large, use a smaller size by |
| 8477 | // using a smaller power of 2 |
| 8478 | unsigned oEVTWidth = EVTWidth; |
| 8479 | FindWidenVecType(TLI, StWidth, VVT, EVT, VecEVT); |
| 8480 | EVTWidth = EVT.getSizeInBits(); |
| 8481 | // Readjust position and vector position based on new load type |
Mon P Wang | 49292f1 | 2008-11-15 06:05:52 +0000 | [diff] [blame] | 8482 | Idx = Idx * (oEVTWidth/EVTWidth); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8483 | VecOp = DAG.getNode(ISD::BIT_CONVERT, VecEVT, VecOp); |
| 8484 | } |
| 8485 | |
| 8486 | EOp = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, EVT, VecOp, |
Mon P Wang | 49292f1 | 2008-11-15 06:05:52 +0000 | [diff] [blame] | 8487 | DAG.getIntPtrConstant(Idx++)); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8488 | StChain.push_back(DAG.getStore(Chain, EOp, BasePtr, SV, |
| 8489 | SVOffset + Offset, isVolatile, |
| 8490 | MinAlign(Alignment, Offset))); |
| 8491 | StWidth -= EVTWidth; |
| 8492 | } |
| 8493 | } |
| 8494 | |
| 8495 | |
| 8496 | SDValue SelectionDAGLegalize::StoreWidenVectorOp(StoreSDNode *ST, |
| 8497 | SDValue Chain, |
| 8498 | SDValue BasePtr) { |
| 8499 | // TODO: It might be cleaner if we can use SplitVector and have more legal |
| 8500 | // vector types that can be stored into memory (e.g., v4xi8 can |
| 8501 | // be stored as a word). This will not work when a vector register |
| 8502 | // to memory mapping is strange (e.g., vector elements are not |
| 8503 | // stored in some sequential order). |
| 8504 | |
| 8505 | MVT StVT = ST->getMemoryVT(); |
| 8506 | SDValue ValOp = ST->getValue(); |
| 8507 | |
| 8508 | // Check if we have widen this node with another value |
| 8509 | std::map<SDValue, SDValue>::iterator I = WidenNodes.find(ValOp); |
| 8510 | if (I != WidenNodes.end()) |
| 8511 | ValOp = I->second; |
| 8512 | |
| 8513 | MVT VVT = ValOp.getValueType(); |
| 8514 | |
| 8515 | // It must be true that we the widen vector type is bigger than where |
| 8516 | // we need to store. |
| 8517 | assert(StVT.isVector() && VVT.isVector()); |
| 8518 | assert(StVT.getSizeInBits() < VVT.getSizeInBits()); |
| 8519 | assert(StVT.getVectorElementType() == VVT.getVectorElementType()); |
| 8520 | |
| 8521 | // Store value |
| 8522 | SDValueVector StChain; |
| 8523 | genWidenVectorStores(StChain, Chain, BasePtr, ST->getSrcValue(), |
| 8524 | ST->getSrcValueOffset(), ST->getAlignment(), |
| 8525 | ST->isVolatile(), ValOp, StVT.getSizeInBits()); |
| 8526 | if (StChain.size() == 1) |
| 8527 | return StChain[0]; |
| 8528 | else |
| 8529 | return DAG.getNode(ISD::TokenFactor, MVT::Other,&StChain[0],StChain.size()); |
| 8530 | } |
| 8531 | |
| 8532 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 8533 | // SelectionDAG::Legalize - This is the entry point for the file. |
| 8534 | // |
Duncan Sands | b6862bb | 2008-12-14 09:43:15 +0000 | [diff] [blame] | 8535 | void SelectionDAG::Legalize(bool TypesNeedLegalizing) { |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 8536 | /// run - This is the main entry point to this class. |
| 8537 | /// |
Duncan Sands | b6862bb | 2008-12-14 09:43:15 +0000 | [diff] [blame] | 8538 | SelectionDAGLegalize(*this, TypesNeedLegalizing).LegalizeDAG(); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 8539 | } |
| 8540 | |