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); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 304 | }; |
| 305 | } |
| 306 | |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 307 | /// isVectorShuffleLegal - Return true if a vector shuffle is legal with the |
| 308 | /// specified mask and type. Targets can specify exactly which masks they |
| 309 | /// support and the code generator is tasked with not creating illegal masks. |
| 310 | /// |
| 311 | /// Note that this will also return true for shuffles that are promoted to a |
| 312 | /// different type. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 313 | SDNode *SelectionDAGLegalize::isShuffleLegal(MVT VT, SDValue Mask) const { |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 314 | switch (TLI.getOperationAction(ISD::VECTOR_SHUFFLE, VT)) { |
| 315 | default: return 0; |
| 316 | case TargetLowering::Legal: |
| 317 | case TargetLowering::Custom: |
| 318 | break; |
| 319 | case TargetLowering::Promote: { |
| 320 | // If this is promoted to a different type, convert the shuffle mask and |
| 321 | // ask if it is legal in the promoted type! |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 322 | MVT NVT = TLI.getTypeToPromoteTo(ISD::VECTOR_SHUFFLE, VT); |
Duncan Sands | d038e04 | 2008-07-21 10:20:31 +0000 | [diff] [blame] | 323 | MVT EltVT = NVT.getVectorElementType(); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 324 | |
| 325 | // If we changed # elements, change the shuffle mask. |
| 326 | unsigned NumEltsGrowth = |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 327 | NVT.getVectorNumElements() / VT.getVectorNumElements(); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 328 | assert(NumEltsGrowth && "Cannot promote to vector type with fewer elts!"); |
| 329 | if (NumEltsGrowth > 1) { |
| 330 | // Renumber the elements. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 331 | SmallVector<SDValue, 8> Ops; |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 332 | for (unsigned i = 0, e = Mask.getNumOperands(); i != e; ++i) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 333 | SDValue InOp = Mask.getOperand(i); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 334 | for (unsigned j = 0; j != NumEltsGrowth; ++j) { |
| 335 | if (InOp.getOpcode() == ISD::UNDEF) |
Duncan Sands | d038e04 | 2008-07-21 10:20:31 +0000 | [diff] [blame] | 336 | Ops.push_back(DAG.getNode(ISD::UNDEF, EltVT)); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 337 | else { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 338 | unsigned InEltNo = cast<ConstantSDNode>(InOp)->getZExtValue(); |
Duncan Sands | d038e04 | 2008-07-21 10:20:31 +0000 | [diff] [blame] | 339 | Ops.push_back(DAG.getConstant(InEltNo*NumEltsGrowth+j, EltVT)); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 340 | } |
| 341 | } |
| 342 | } |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 343 | Mask = DAG.getNode(ISD::BUILD_VECTOR, NVT, &Ops[0], Ops.size()); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 344 | } |
| 345 | VT = NVT; |
| 346 | break; |
| 347 | } |
| 348 | } |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 349 | return TLI.isShuffleMaskLegal(Mask, VT) ? Mask.getNode() : 0; |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 350 | } |
| 351 | |
Duncan Sands | b6862bb | 2008-12-14 09:43:15 +0000 | [diff] [blame] | 352 | SelectionDAGLegalize::SelectionDAGLegalize(SelectionDAG &dag, bool types) |
| 353 | : TLI(dag.getTargetLoweringInfo()), DAG(dag), TypesNeedLegalizing(types), |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 354 | ValueTypeActions(TLI.getValueTypeActions()) { |
Nate Begeman | 6a64861 | 2005-11-29 05:45:29 +0000 | [diff] [blame] | 355 | assert(MVT::LAST_VALUETYPE <= 32 && |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 356 | "Too many value types for ValueTypeActions to hold!"); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 357 | } |
| 358 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 359 | void SelectionDAGLegalize::LegalizeDAG() { |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 360 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 361 | IsLegalizingCall = false; |
| 362 | |
Chris Lattner | ab510a7 | 2005-10-02 17:49:46 +0000 | [diff] [blame] | 363 | // The legalize process is inherently a bottom-up recursive process (users |
| 364 | // legalize their uses before themselves). Given infinite stack space, we |
| 365 | // could just start legalizing on the root and traverse the whole graph. In |
| 366 | // 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] | 367 | // blocks. To avoid this problem, compute an ordering of the nodes where each |
| 368 | // node is only legalized after all of its operands are legalized. |
Dan Gohman | f06c835 | 2008-09-30 18:30:35 +0000 | [diff] [blame] | 369 | DAG.AssignTopologicalOrder(); |
| 370 | for (SelectionDAG::allnodes_iterator I = DAG.allnodes_begin(), |
| 371 | E = prior(DAG.allnodes_end()); I != next(E); ++I) |
| 372 | HandleOp(SDValue(I, 0)); |
Chris Lattner | 32fca00 | 2005-10-06 01:20:27 +0000 | [diff] [blame] | 373 | |
| 374 | // Finally, it's possible the root changed. Get the new root. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 375 | SDValue OldRoot = DAG.getRoot(); |
Chris Lattner | 32fca00 | 2005-10-06 01:20:27 +0000 | [diff] [blame] | 376 | assert(LegalizedNodes.count(OldRoot) && "Root didn't get legalized?"); |
| 377 | DAG.setRoot(LegalizedNodes[OldRoot]); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 378 | |
| 379 | ExpandedNodes.clear(); |
| 380 | LegalizedNodes.clear(); |
Chris Lattner | 71c42a0 | 2005-01-16 01:11:45 +0000 | [diff] [blame] | 381 | PromotedNodes.clear(); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 382 | SplitNodes.clear(); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 383 | ScalarizedNodes.clear(); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 384 | WidenNodes.clear(); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 385 | |
| 386 | // Remove dead nodes now. |
Chris Lattner | 190a418 | 2006-08-04 17:45:20 +0000 | [diff] [blame] | 387 | DAG.RemoveDeadNodes(); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 388 | } |
| 389 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 390 | |
| 391 | /// FindCallEndFromCallStart - Given a chained node that is part of a call |
| 392 | /// sequence, find the CALLSEQ_END node that terminates the call sequence. |
| 393 | static SDNode *FindCallEndFromCallStart(SDNode *Node) { |
| 394 | if (Node->getOpcode() == ISD::CALLSEQ_END) |
| 395 | return Node; |
| 396 | if (Node->use_empty()) |
| 397 | return 0; // No CallSeqEnd |
| 398 | |
| 399 | // The chain is usually at the end. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 400 | SDValue TheChain(Node, Node->getNumValues()-1); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 401 | if (TheChain.getValueType() != MVT::Other) { |
| 402 | // Sometimes it's at the beginning. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 403 | TheChain = SDValue(Node, 0); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 404 | if (TheChain.getValueType() != MVT::Other) { |
| 405 | // Otherwise, hunt for it. |
| 406 | for (unsigned i = 1, e = Node->getNumValues(); i != e; ++i) |
| 407 | if (Node->getValueType(i) == MVT::Other) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 408 | TheChain = SDValue(Node, i); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 409 | break; |
| 410 | } |
| 411 | |
| 412 | // Otherwise, we walked into a node without a chain. |
| 413 | if (TheChain.getValueType() != MVT::Other) |
| 414 | return 0; |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | for (SDNode::use_iterator UI = Node->use_begin(), |
| 419 | E = Node->use_end(); UI != E; ++UI) { |
| 420 | |
| 421 | // Make sure to only follow users of our token chain. |
Dan Gohman | 8968450 | 2008-07-27 20:43:25 +0000 | [diff] [blame] | 422 | SDNode *User = *UI; |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 423 | for (unsigned i = 0, e = User->getNumOperands(); i != e; ++i) |
| 424 | if (User->getOperand(i) == TheChain) |
| 425 | if (SDNode *Result = FindCallEndFromCallStart(User)) |
| 426 | return Result; |
| 427 | } |
| 428 | return 0; |
| 429 | } |
| 430 | |
| 431 | /// FindCallStartFromCallEnd - Given a chained node that is part of a call |
| 432 | /// sequence, find the CALLSEQ_START node that initiates the call sequence. |
| 433 | static SDNode *FindCallStartFromCallEnd(SDNode *Node) { |
| 434 | assert(Node && "Didn't find callseq_start for a call??"); |
| 435 | if (Node->getOpcode() == ISD::CALLSEQ_START) return Node; |
| 436 | |
| 437 | assert(Node->getOperand(0).getValueType() == MVT::Other && |
| 438 | "Node doesn't have a token chain argument!"); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 439 | return FindCallStartFromCallEnd(Node->getOperand(0).getNode()); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | /// LegalizeAllNodesNotLeadingTo - Recursively walk the uses of N, looking to |
| 443 | /// see if any uses can reach Dest. If no dest operands can get to dest, |
| 444 | /// legalize them, legalize ourself, and return false, otherwise, return true. |
Chris Lattner | c9cf4f1 | 2006-07-26 23:55:56 +0000 | [diff] [blame] | 445 | /// |
| 446 | /// Keep track of the nodes we fine that actually do lead to Dest in |
| 447 | /// NodesLeadingTo. This avoids retraversing them exponential number of times. |
| 448 | /// |
| 449 | bool SelectionDAGLegalize::LegalizeAllNodesNotLeadingTo(SDNode *N, SDNode *Dest, |
Chris Lattner | 00755df | 2007-02-04 00:27:56 +0000 | [diff] [blame] | 450 | SmallPtrSet<SDNode*, 32> &NodesLeadingTo) { |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 451 | if (N == Dest) return true; // N certainly leads to Dest :) |
| 452 | |
Chris Lattner | c9cf4f1 | 2006-07-26 23:55:56 +0000 | [diff] [blame] | 453 | // If we've already processed this node and it does lead to Dest, there is no |
| 454 | // need to reprocess it. |
| 455 | if (NodesLeadingTo.count(N)) return true; |
| 456 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 457 | // If the first result of this node has been already legalized, then it cannot |
| 458 | // reach N. |
| 459 | switch (getTypeAction(N->getValueType(0))) { |
| 460 | case Legal: |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 461 | if (LegalizedNodes.count(SDValue(N, 0))) return false; |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 462 | break; |
| 463 | case Promote: |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 464 | if (PromotedNodes.count(SDValue(N, 0))) return false; |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 465 | break; |
| 466 | case Expand: |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 467 | if (ExpandedNodes.count(SDValue(N, 0))) return false; |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 468 | break; |
| 469 | } |
| 470 | |
| 471 | // Okay, this node has not already been legalized. Check and legalize all |
| 472 | // operands. If none lead to Dest, then we can legalize this node. |
| 473 | bool OperandsLeadToDest = false; |
| 474 | for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) |
| 475 | OperandsLeadToDest |= // If an operand leads to Dest, so do we. |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 476 | LegalizeAllNodesNotLeadingTo(N->getOperand(i).getNode(), Dest, NodesLeadingTo); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 477 | |
Chris Lattner | c9cf4f1 | 2006-07-26 23:55:56 +0000 | [diff] [blame] | 478 | if (OperandsLeadToDest) { |
| 479 | NodesLeadingTo.insert(N); |
| 480 | return true; |
| 481 | } |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 482 | |
| 483 | // Okay, this node looks safe, legalize it and return false. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 484 | HandleOp(SDValue(N, 0)); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 485 | return false; |
| 486 | } |
| 487 | |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 488 | /// HandleOp - Legalize, Promote, Widen, or Expand the specified operand as |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 489 | /// appropriate for its type. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 490 | void SelectionDAGLegalize::HandleOp(SDValue Op) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 491 | MVT VT = Op.getValueType(); |
Duncan Sands | b6862bb | 2008-12-14 09:43:15 +0000 | [diff] [blame] | 492 | // If the type legalizer was run then we should never see any illegal result |
| 493 | // 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] | 494 | // those) or for build vector used as a mask for a vector shuffle. |
| 495 | // FIXME: We can removed the BUILD_VECTOR case when we fix PR2957. |
Duncan Sands | b6862bb | 2008-12-14 09:43:15 +0000 | [diff] [blame] | 496 | assert((TypesNeedLegalizing || getTypeAction(VT) == Legal || |
Mon P Wang | 87c8a8f | 2008-12-18 20:03:17 +0000 | [diff] [blame] | 497 | Op.getOpcode() == ISD::TargetConstant || |
| 498 | Op.getOpcode() == ISD::BUILD_VECTOR) && |
Duncan Sands | b6862bb | 2008-12-14 09:43:15 +0000 | [diff] [blame] | 499 | "Illegal type introduced after type legalization?"); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 500 | switch (getTypeAction(VT)) { |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 501 | default: assert(0 && "Bad type action!"); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 502 | case Legal: (void)LegalizeOp(Op); break; |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 503 | case Promote: |
| 504 | if (!VT.isVector()) { |
| 505 | (void)PromoteOp(Op); |
| 506 | break; |
| 507 | } |
| 508 | else { |
| 509 | // See if we can widen otherwise use Expand to either scalarize or split |
| 510 | MVT WidenVT = TLI.getWidenVectorType(VT); |
| 511 | if (WidenVT != MVT::Other) { |
| 512 | (void) WidenVectorOp(Op, WidenVT); |
| 513 | break; |
| 514 | } |
| 515 | // else fall thru to expand since we can't widen the vector |
| 516 | } |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 517 | case Expand: |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 518 | if (!VT.isVector()) { |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 519 | // If this is an illegal scalar, expand it into its two component |
| 520 | // pieces. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 521 | SDValue X, Y; |
Chris Lattner | 09ec1b0 | 2007-08-25 01:00:22 +0000 | [diff] [blame] | 522 | if (Op.getOpcode() == ISD::TargetConstant) |
| 523 | break; // Allow illegal target nodes. |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 524 | ExpandOp(Op, X, Y); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 525 | } else if (VT.getVectorNumElements() == 1) { |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 526 | // If this is an illegal single element vector, convert it to a |
| 527 | // scalar operation. |
| 528 | (void)ScalarizeVectorOp(Op); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 529 | } else { |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 530 | // This is an illegal multiple element vector. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 531 | // Split it in half and legalize both parts. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 532 | SDValue X, Y; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 533 | SplitVectorOp(Op, X, Y); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 534 | } |
| 535 | break; |
| 536 | } |
| 537 | } |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 538 | |
Evan Cheng | 9f87788 | 2006-12-13 20:57:08 +0000 | [diff] [blame] | 539 | /// ExpandConstantFP - Expands the ConstantFP node to an integer constant or |
| 540 | /// a load from the constant pool. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 541 | static SDValue ExpandConstantFP(ConstantFPSDNode *CFP, bool UseCP, |
Dan Gohman | 0d137d7 | 2009-01-15 16:43:02 +0000 | [diff] [blame] | 542 | SelectionDAG &DAG, const TargetLowering &TLI) { |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 543 | bool Extend = false; |
| 544 | |
| 545 | // If a FP immediate is precise when represented as a float and if the |
| 546 | // target can do an extending load from float to double, we put it into |
| 547 | // 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] | 548 | // double. This shrinks FP constants and canonicalizes them for targets where |
| 549 | // an FP extending load is the same cost as a normal load (such as on the x87 |
| 550 | // fp stack or PPC FP unit). |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 551 | MVT VT = CFP->getValueType(0); |
Dan Gohman | 4fbd796 | 2008-09-12 18:08:03 +0000 | [diff] [blame] | 552 | ConstantFP *LLVMC = const_cast<ConstantFP*>(CFP->getConstantFPValue()); |
Evan Cheng | 9f87788 | 2006-12-13 20:57:08 +0000 | [diff] [blame] | 553 | if (!UseCP) { |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 554 | if (VT!=MVT::f64 && VT!=MVT::f32) |
| 555 | assert(0 && "Invalid type expansion"); |
Dale Johannesen | 7111b02 | 2008-10-09 18:53:47 +0000 | [diff] [blame] | 556 | return DAG.getConstant(LLVMC->getValueAPF().bitcastToAPInt(), |
Evan Cheng | ef12057 | 2008-03-04 08:05:30 +0000 | [diff] [blame] | 557 | (VT == MVT::f64) ? MVT::i64 : MVT::i32); |
Evan Cheng | 279101e | 2006-12-12 22:19:28 +0000 | [diff] [blame] | 558 | } |
| 559 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 560 | MVT OrigVT = VT; |
| 561 | MVT SVT = VT; |
Evan Cheng | ef12057 | 2008-03-04 08:05:30 +0000 | [diff] [blame] | 562 | while (SVT != MVT::f32) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 563 | SVT = (MVT::SimpleValueType)(SVT.getSimpleVT() - 1); |
Evan Cheng | ef12057 | 2008-03-04 08:05:30 +0000 | [diff] [blame] | 564 | if (CFP->isValueValidForType(SVT, CFP->getValueAPF()) && |
| 565 | // Only do this if the target has a native EXTLOAD instruction from |
| 566 | // smaller type. |
Evan Cheng | 0329466 | 2008-10-14 21:26:46 +0000 | [diff] [blame] | 567 | TLI.isLoadExtLegal(ISD::EXTLOAD, SVT) && |
Chris Lattner | aa2acbb | 2008-03-05 06:46:58 +0000 | [diff] [blame] | 568 | TLI.ShouldShrinkFPConstant(OrigVT)) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 569 | const Type *SType = SVT.getTypeForMVT(); |
Evan Cheng | ef12057 | 2008-03-04 08:05:30 +0000 | [diff] [blame] | 570 | LLVMC = cast<ConstantFP>(ConstantExpr::getFPTrunc(LLVMC, SType)); |
| 571 | VT = SVT; |
| 572 | Extend = true; |
| 573 | } |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 574 | } |
| 575 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 576 | SDValue CPIdx = DAG.getConstantPool(LLVMC, TLI.getPointerTy()); |
Dan Gohman | 50284d8 | 2008-09-16 22:05:41 +0000 | [diff] [blame] | 577 | unsigned Alignment = 1 << cast<ConstantPoolSDNode>(CPIdx)->getAlignment(); |
Evan Cheng | ef12057 | 2008-03-04 08:05:30 +0000 | [diff] [blame] | 578 | if (Extend) |
| 579 | return DAG.getExtLoad(ISD::EXTLOAD, OrigVT, DAG.getEntryNode(), |
Dan Gohman | 3069b87 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 580 | CPIdx, PseudoSourceValue::getConstantPool(), |
Dan Gohman | 50284d8 | 2008-09-16 22:05:41 +0000 | [diff] [blame] | 581 | 0, VT, false, Alignment); |
Evan Cheng | ef12057 | 2008-03-04 08:05:30 +0000 | [diff] [blame] | 582 | return DAG.getLoad(OrigVT, DAG.getEntryNode(), CPIdx, |
Dan Gohman | 50284d8 | 2008-09-16 22:05:41 +0000 | [diff] [blame] | 583 | PseudoSourceValue::getConstantPool(), 0, false, Alignment); |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 584 | } |
| 585 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 586 | |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 587 | /// ExpandFCOPYSIGNToBitwiseOps - Expands fcopysign to a series of bitwise |
| 588 | /// operations. |
| 589 | static |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 590 | SDValue ExpandFCOPYSIGNToBitwiseOps(SDNode *Node, MVT NVT, |
Dan Gohman | 0d137d7 | 2009-01-15 16:43:02 +0000 | [diff] [blame] | 591 | SelectionDAG &DAG, |
| 592 | const TargetLowering &TLI) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 593 | MVT VT = Node->getValueType(0); |
| 594 | MVT SrcVT = Node->getOperand(1).getValueType(); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 595 | assert((SrcVT == MVT::f32 || SrcVT == MVT::f64) && |
| 596 | "fcopysign expansion only supported for f32 and f64"); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 597 | MVT SrcNVT = (SrcVT == MVT::f64) ? MVT::i64 : MVT::i32; |
Evan Cheng | 068c5f4 | 2007-01-05 21:31:51 +0000 | [diff] [blame] | 598 | |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 599 | // First get the sign bit of second operand. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 600 | SDValue Mask1 = (SrcVT == MVT::f64) |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 601 | ? DAG.getConstantFP(BitsToDouble(1ULL << 63), SrcVT) |
| 602 | : DAG.getConstantFP(BitsToFloat(1U << 31), SrcVT); |
Evan Cheng | 068c5f4 | 2007-01-05 21:31:51 +0000 | [diff] [blame] | 603 | Mask1 = DAG.getNode(ISD::BIT_CONVERT, SrcNVT, Mask1); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 604 | SDValue SignBit= DAG.getNode(ISD::BIT_CONVERT, SrcNVT, Node->getOperand(1)); |
Evan Cheng | 068c5f4 | 2007-01-05 21:31:51 +0000 | [diff] [blame] | 605 | SignBit = DAG.getNode(ISD::AND, SrcNVT, SignBit, Mask1); |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 606 | // 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] | 607 | int SizeDiff = SrcNVT.getSizeInBits() - NVT.getSizeInBits(); |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 608 | if (SizeDiff > 0) { |
| 609 | SignBit = DAG.getNode(ISD::SRL, SrcNVT, SignBit, |
| 610 | DAG.getConstant(SizeDiff, TLI.getShiftAmountTy())); |
| 611 | SignBit = DAG.getNode(ISD::TRUNCATE, NVT, SignBit); |
Chris Lattner | c563e1d | 2008-07-10 23:46:13 +0000 | [diff] [blame] | 612 | } else if (SizeDiff < 0) { |
| 613 | SignBit = DAG.getNode(ISD::ZERO_EXTEND, NVT, SignBit); |
| 614 | SignBit = DAG.getNode(ISD::SHL, NVT, SignBit, |
| 615 | DAG.getConstant(-SizeDiff, TLI.getShiftAmountTy())); |
| 616 | } |
Evan Cheng | 068c5f4 | 2007-01-05 21:31:51 +0000 | [diff] [blame] | 617 | |
| 618 | // Clear the sign bit of first operand. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 619 | SDValue Mask2 = (VT == MVT::f64) |
Evan Cheng | 068c5f4 | 2007-01-05 21:31:51 +0000 | [diff] [blame] | 620 | ? DAG.getConstantFP(BitsToDouble(~(1ULL << 63)), VT) |
| 621 | : DAG.getConstantFP(BitsToFloat(~(1U << 31)), VT); |
| 622 | Mask2 = DAG.getNode(ISD::BIT_CONVERT, NVT, Mask2); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 623 | SDValue Result = DAG.getNode(ISD::BIT_CONVERT, NVT, Node->getOperand(0)); |
Evan Cheng | 068c5f4 | 2007-01-05 21:31:51 +0000 | [diff] [blame] | 624 | Result = DAG.getNode(ISD::AND, NVT, Result, Mask2); |
| 625 | |
| 626 | // Or the value with the sign bit. |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 627 | Result = DAG.getNode(ISD::OR, NVT, Result, SignBit); |
| 628 | return Result; |
| 629 | } |
| 630 | |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 631 | /// ExpandUnalignedStore - Expands an unaligned store to 2 half-size stores. |
| 632 | static |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 633 | SDValue ExpandUnalignedStore(StoreSDNode *ST, SelectionDAG &DAG, |
Dan Gohman | 0d137d7 | 2009-01-15 16:43:02 +0000 | [diff] [blame] | 634 | const TargetLowering &TLI) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 635 | SDValue Chain = ST->getChain(); |
| 636 | SDValue Ptr = ST->getBasePtr(); |
| 637 | SDValue Val = ST->getValue(); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 638 | MVT VT = Val.getValueType(); |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 639 | int Alignment = ST->getAlignment(); |
| 640 | int SVOffset = ST->getSrcValueOffset(); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 641 | if (ST->getMemoryVT().isFloatingPoint() || |
| 642 | ST->getMemoryVT().isVector()) { |
Duncan Sands | 05e11fa | 2008-12-12 21:47:02 +0000 | [diff] [blame] | 643 | MVT intVT = MVT::getIntegerVT(VT.getSizeInBits()); |
| 644 | if (TLI.isTypeLegal(intVT)) { |
| 645 | // Expand to a bitconvert of the value to the integer type of the |
| 646 | // same size, then a (misaligned) int store. |
| 647 | // FIXME: Does not handle truncating floating point stores! |
| 648 | SDValue Result = DAG.getNode(ISD::BIT_CONVERT, intVT, Val); |
| 649 | return DAG.getStore(Chain, Result, Ptr, ST->getSrcValue(), |
| 650 | SVOffset, ST->isVolatile(), Alignment); |
| 651 | } else { |
| 652 | // Do a (aligned) store to a stack slot, then copy from the stack slot |
| 653 | // to the final destination using (unaligned) integer loads and stores. |
| 654 | MVT StoredVT = ST->getMemoryVT(); |
| 655 | MVT RegVT = |
| 656 | TLI.getRegisterType(MVT::getIntegerVT(StoredVT.getSizeInBits())); |
| 657 | unsigned StoredBytes = StoredVT.getSizeInBits() / 8; |
| 658 | unsigned RegBytes = RegVT.getSizeInBits() / 8; |
| 659 | unsigned NumRegs = (StoredBytes + RegBytes - 1) / RegBytes; |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 660 | |
Duncan Sands | fd6673c | 2008-12-13 07:18:38 +0000 | [diff] [blame] | 661 | // Make sure the stack slot is also aligned for the register type. |
| 662 | SDValue StackPtr = DAG.CreateStackTemporary(StoredVT, RegVT); |
| 663 | |
| 664 | // Perform the original store, only redirected to the stack slot. |
Duncan Sands | 05e11fa | 2008-12-12 21:47:02 +0000 | [diff] [blame] | 665 | SDValue Store = DAG.getTruncStore(Chain, Val, StackPtr, NULL, 0,StoredVT); |
| 666 | SDValue Increment = DAG.getConstant(RegBytes, TLI.getPointerTy()); |
| 667 | SmallVector<SDValue, 8> Stores; |
| 668 | unsigned Offset = 0; |
| 669 | |
| 670 | // Do all but one copies using the full register width. |
| 671 | for (unsigned i = 1; i < NumRegs; i++) { |
| 672 | // Load one integer register's worth from the stack slot. |
| 673 | SDValue Load = DAG.getLoad(RegVT, Store, StackPtr, NULL, 0); |
| 674 | // Store it to the final location. Remember the store. |
| 675 | Stores.push_back(DAG.getStore(Load.getValue(1), Load, Ptr, |
| 676 | ST->getSrcValue(), SVOffset + Offset, |
| 677 | ST->isVolatile(), |
| 678 | MinAlign(ST->getAlignment(), Offset))); |
| 679 | // Increment the pointers. |
| 680 | Offset += RegBytes; |
| 681 | StackPtr = DAG.getNode(ISD::ADD, StackPtr.getValueType(), StackPtr, |
| 682 | Increment); |
| 683 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, Increment); |
| 684 | } |
| 685 | |
Duncan Sands | fd6673c | 2008-12-13 07:18:38 +0000 | [diff] [blame] | 686 | // The last store may be partial. Do a truncating store. On big-endian |
| 687 | // machines this requires an extending load from the stack slot to ensure |
| 688 | // that the bits are in the right place. |
| 689 | MVT MemVT = MVT::getIntegerVT(8 * (StoredBytes - Offset)); |
Duncan Sands | 05e11fa | 2008-12-12 21:47:02 +0000 | [diff] [blame] | 690 | |
Duncan Sands | fd6673c | 2008-12-13 07:18:38 +0000 | [diff] [blame] | 691 | // Load from the stack slot. |
| 692 | SDValue Load = DAG.getExtLoad(ISD::EXTLOAD, RegVT, Store, StackPtr, |
| 693 | NULL, 0, MemVT); |
| 694 | |
Duncan Sands | 05e11fa | 2008-12-12 21:47:02 +0000 | [diff] [blame] | 695 | Stores.push_back(DAG.getTruncStore(Load.getValue(1), Load, Ptr, |
| 696 | ST->getSrcValue(), SVOffset + Offset, |
Duncan Sands | fd6673c | 2008-12-13 07:18:38 +0000 | [diff] [blame] | 697 | MemVT, ST->isVolatile(), |
Duncan Sands | 05e11fa | 2008-12-12 21:47:02 +0000 | [diff] [blame] | 698 | MinAlign(ST->getAlignment(), Offset))); |
| 699 | // The order of the stores doesn't matter - say it with a TokenFactor. |
| 700 | return DAG.getNode(ISD::TokenFactor, MVT::Other, &Stores[0], |
| 701 | Stores.size()); |
| 702 | } |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 703 | } |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 704 | assert(ST->getMemoryVT().isInteger() && |
| 705 | !ST->getMemoryVT().isVector() && |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 706 | "Unaligned store of unknown type."); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 707 | // Get the half-size VT |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 708 | MVT NewStoredVT = |
| 709 | (MVT::SimpleValueType)(ST->getMemoryVT().getSimpleVT() - 1); |
| 710 | int NumBits = NewStoredVT.getSizeInBits(); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 711 | int IncrementSize = NumBits / 8; |
| 712 | |
| 713 | // Divide the stored value in two parts. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 714 | SDValue ShiftAmount = DAG.getConstant(NumBits, TLI.getShiftAmountTy()); |
| 715 | SDValue Lo = Val; |
| 716 | SDValue Hi = DAG.getNode(ISD::SRL, VT, Val, ShiftAmount); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 717 | |
| 718 | // Store the two parts |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 719 | SDValue Store1, Store2; |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 720 | Store1 = DAG.getTruncStore(Chain, TLI.isLittleEndian()?Lo:Hi, Ptr, |
| 721 | ST->getSrcValue(), SVOffset, NewStoredVT, |
| 722 | ST->isVolatile(), Alignment); |
| 723 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
| 724 | DAG.getConstant(IncrementSize, TLI.getPointerTy())); |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 725 | Alignment = MinAlign(Alignment, IncrementSize); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 726 | Store2 = DAG.getTruncStore(Chain, TLI.isLittleEndian()?Hi:Lo, Ptr, |
| 727 | ST->getSrcValue(), SVOffset + IncrementSize, |
| 728 | NewStoredVT, ST->isVolatile(), Alignment); |
| 729 | |
| 730 | return DAG.getNode(ISD::TokenFactor, MVT::Other, Store1, Store2); |
| 731 | } |
| 732 | |
| 733 | /// ExpandUnalignedLoad - Expands an unaligned load to 2 half-size loads. |
| 734 | static |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 735 | SDValue ExpandUnalignedLoad(LoadSDNode *LD, SelectionDAG &DAG, |
Dan Gohman | e9530ec | 2009-01-15 16:58:17 +0000 | [diff] [blame] | 736 | const TargetLowering &TLI) { |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 737 | int SVOffset = LD->getSrcValueOffset(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 738 | SDValue Chain = LD->getChain(); |
| 739 | SDValue Ptr = LD->getBasePtr(); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 740 | MVT VT = LD->getValueType(0); |
| 741 | MVT LoadedVT = LD->getMemoryVT(); |
| 742 | if (VT.isFloatingPoint() || VT.isVector()) { |
Duncan Sands | 05e11fa | 2008-12-12 21:47:02 +0000 | [diff] [blame] | 743 | MVT intVT = MVT::getIntegerVT(LoadedVT.getSizeInBits()); |
| 744 | if (TLI.isTypeLegal(intVT)) { |
| 745 | // Expand to a (misaligned) integer load of the same size, |
| 746 | // then bitconvert to floating point or vector. |
| 747 | SDValue newLoad = DAG.getLoad(intVT, Chain, Ptr, LD->getSrcValue(), |
| 748 | SVOffset, LD->isVolatile(), |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 749 | LD->getAlignment()); |
Duncan Sands | 05e11fa | 2008-12-12 21:47:02 +0000 | [diff] [blame] | 750 | SDValue Result = DAG.getNode(ISD::BIT_CONVERT, LoadedVT, newLoad); |
| 751 | if (VT.isFloatingPoint() && LoadedVT != VT) |
| 752 | Result = DAG.getNode(ISD::FP_EXTEND, VT, Result); |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 753 | |
Duncan Sands | 05e11fa | 2008-12-12 21:47:02 +0000 | [diff] [blame] | 754 | SDValue Ops[] = { Result, Chain }; |
| 755 | return DAG.getMergeValues(Ops, 2); |
| 756 | } else { |
| 757 | // Copy the value to a (aligned) stack slot using (unaligned) integer |
| 758 | // loads and stores, then do a (aligned) load from the stack slot. |
| 759 | MVT RegVT = TLI.getRegisterType(intVT); |
| 760 | unsigned LoadedBytes = LoadedVT.getSizeInBits() / 8; |
| 761 | unsigned RegBytes = RegVT.getSizeInBits() / 8; |
| 762 | unsigned NumRegs = (LoadedBytes + RegBytes - 1) / RegBytes; |
| 763 | |
Duncan Sands | fd6673c | 2008-12-13 07:18:38 +0000 | [diff] [blame] | 764 | // Make sure the stack slot is also aligned for the register type. |
| 765 | SDValue StackBase = DAG.CreateStackTemporary(LoadedVT, RegVT); |
| 766 | |
Duncan Sands | 05e11fa | 2008-12-12 21:47:02 +0000 | [diff] [blame] | 767 | SDValue Increment = DAG.getConstant(RegBytes, TLI.getPointerTy()); |
| 768 | SmallVector<SDValue, 8> Stores; |
| 769 | SDValue StackPtr = StackBase; |
| 770 | unsigned Offset = 0; |
| 771 | |
| 772 | // Do all but one copies using the full register width. |
| 773 | for (unsigned i = 1; i < NumRegs; i++) { |
| 774 | // Load one integer register's worth from the original location. |
| 775 | SDValue Load = DAG.getLoad(RegVT, Chain, Ptr, LD->getSrcValue(), |
| 776 | SVOffset + Offset, LD->isVolatile(), |
| 777 | MinAlign(LD->getAlignment(), Offset)); |
| 778 | // Follow the load with a store to the stack slot. Remember the store. |
| 779 | Stores.push_back(DAG.getStore(Load.getValue(1), Load, StackPtr, |
| 780 | NULL, 0)); |
| 781 | // Increment the pointers. |
| 782 | Offset += RegBytes; |
| 783 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, Increment); |
| 784 | StackPtr = DAG.getNode(ISD::ADD, StackPtr.getValueType(), StackPtr, |
| 785 | Increment); |
| 786 | } |
| 787 | |
| 788 | // The last copy may be partial. Do an extending load. |
Duncan Sands | fd6673c | 2008-12-13 07:18:38 +0000 | [diff] [blame] | 789 | MVT MemVT = MVT::getIntegerVT(8 * (LoadedBytes - Offset)); |
Duncan Sands | 05e11fa | 2008-12-12 21:47:02 +0000 | [diff] [blame] | 790 | SDValue Load = DAG.getExtLoad(ISD::EXTLOAD, RegVT, Chain, Ptr, |
| 791 | LD->getSrcValue(), SVOffset + Offset, |
Duncan Sands | fd6673c | 2008-12-13 07:18:38 +0000 | [diff] [blame] | 792 | MemVT, LD->isVolatile(), |
Duncan Sands | 05e11fa | 2008-12-12 21:47:02 +0000 | [diff] [blame] | 793 | MinAlign(LD->getAlignment(), Offset)); |
| 794 | // 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] | 795 | // On big-endian machines this requires a truncating store to ensure |
| 796 | // that the bits end up in the right place. |
| 797 | Stores.push_back(DAG.getTruncStore(Load.getValue(1), Load, StackPtr, |
| 798 | NULL, 0, MemVT)); |
Duncan Sands | 05e11fa | 2008-12-12 21:47:02 +0000 | [diff] [blame] | 799 | |
| 800 | // The order of the stores doesn't matter - say it with a TokenFactor. |
| 801 | SDValue TF = DAG.getNode(ISD::TokenFactor, MVT::Other, &Stores[0], |
| 802 | Stores.size()); |
| 803 | |
| 804 | // Finally, perform the original load only redirected to the stack slot. |
| 805 | Load = DAG.getExtLoad(LD->getExtensionType(), VT, TF, StackBase, |
| 806 | NULL, 0, LoadedVT); |
| 807 | |
| 808 | // Callers expect a MERGE_VALUES node. |
| 809 | SDValue Ops[] = { Load, TF }; |
| 810 | return DAG.getMergeValues(Ops, 2); |
| 811 | } |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 812 | } |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 813 | assert(LoadedVT.isInteger() && !LoadedVT.isVector() && |
Chris Lattner | e400af8 | 2007-11-19 21:38:03 +0000 | [diff] [blame] | 814 | "Unaligned load of unsupported type."); |
| 815 | |
Dale Johannesen | 8155d64 | 2008-02-27 22:36:00 +0000 | [diff] [blame] | 816 | // Compute the new VT that is half the size of the old one. This is an |
| 817 | // integer MVT. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 818 | unsigned NumBits = LoadedVT.getSizeInBits(); |
| 819 | MVT NewLoadedVT; |
| 820 | NewLoadedVT = MVT::getIntegerVT(NumBits/2); |
Chris Lattner | e400af8 | 2007-11-19 21:38:03 +0000 | [diff] [blame] | 821 | NumBits >>= 1; |
| 822 | |
| 823 | unsigned Alignment = LD->getAlignment(); |
| 824 | unsigned IncrementSize = NumBits / 8; |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 825 | ISD::LoadExtType HiExtType = LD->getExtensionType(); |
| 826 | |
| 827 | // If the original load is NON_EXTLOAD, the hi part load must be ZEXTLOAD. |
| 828 | if (HiExtType == ISD::NON_EXTLOAD) |
| 829 | HiExtType = ISD::ZEXTLOAD; |
| 830 | |
| 831 | // Load the value in two parts |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 832 | SDValue Lo, Hi; |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 833 | if (TLI.isLittleEndian()) { |
| 834 | Lo = DAG.getExtLoad(ISD::ZEXTLOAD, VT, Chain, Ptr, LD->getSrcValue(), |
| 835 | SVOffset, NewLoadedVT, LD->isVolatile(), Alignment); |
| 836 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
| 837 | DAG.getConstant(IncrementSize, TLI.getPointerTy())); |
| 838 | Hi = DAG.getExtLoad(HiExtType, VT, Chain, Ptr, LD->getSrcValue(), |
| 839 | SVOffset + IncrementSize, NewLoadedVT, LD->isVolatile(), |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 840 | MinAlign(Alignment, IncrementSize)); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 841 | } else { |
| 842 | Hi = DAG.getExtLoad(HiExtType, VT, Chain, Ptr, LD->getSrcValue(), SVOffset, |
| 843 | NewLoadedVT,LD->isVolatile(), Alignment); |
| 844 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
| 845 | DAG.getConstant(IncrementSize, TLI.getPointerTy())); |
| 846 | Lo = DAG.getExtLoad(ISD::ZEXTLOAD, VT, Chain, Ptr, LD->getSrcValue(), |
| 847 | SVOffset + IncrementSize, NewLoadedVT, LD->isVolatile(), |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 848 | MinAlign(Alignment, IncrementSize)); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | // aggregate the two parts |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 852 | SDValue ShiftAmount = DAG.getConstant(NumBits, TLI.getShiftAmountTy()); |
| 853 | SDValue Result = DAG.getNode(ISD::SHL, VT, Hi, ShiftAmount); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 854 | Result = DAG.getNode(ISD::OR, VT, Result, Lo); |
| 855 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 856 | SDValue TF = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1), |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 857 | Hi.getValue(1)); |
| 858 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 859 | SDValue Ops[] = { Result, TF }; |
Duncan Sands | 4bdcb61 | 2008-07-02 17:40:58 +0000 | [diff] [blame] | 860 | return DAG.getMergeValues(Ops, 2); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 861 | } |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 862 | |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 863 | /// UnrollVectorOp - We know that the given vector has a legal type, however |
| 864 | /// the operation it performs is not legal and is an operation that we have |
| 865 | /// no way of lowering. "Unroll" the vector, splitting out the scalars and |
| 866 | /// operating on each element individually. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 867 | SDValue SelectionDAGLegalize::UnrollVectorOp(SDValue Op) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 868 | MVT VT = Op.getValueType(); |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 869 | assert(isTypeLegal(VT) && |
| 870 | "Caller should expand or promote operands that are not legal!"); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 871 | assert(Op.getNode()->getNumValues() == 1 && |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 872 | "Can't unroll a vector with multiple results!"); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 873 | unsigned NE = VT.getVectorNumElements(); |
| 874 | MVT EltVT = VT.getVectorElementType(); |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 875 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 876 | SmallVector<SDValue, 8> Scalars; |
| 877 | SmallVector<SDValue, 4> Operands(Op.getNumOperands()); |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 878 | for (unsigned i = 0; i != NE; ++i) { |
| 879 | for (unsigned j = 0; j != Op.getNumOperands(); ++j) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 880 | SDValue Operand = Op.getOperand(j); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 881 | MVT OperandVT = Operand.getValueType(); |
| 882 | if (OperandVT.isVector()) { |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 883 | // A vector operand; extract a single element. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 884 | MVT OperandEltVT = OperandVT.getVectorElementType(); |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 885 | Operands[j] = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, |
| 886 | OperandEltVT, |
| 887 | Operand, |
| 888 | DAG.getConstant(i, MVT::i32)); |
| 889 | } else { |
| 890 | // A scalar operand; just use it as is. |
| 891 | Operands[j] = Operand; |
| 892 | } |
| 893 | } |
Mon P Wang | e9f1015 | 2008-12-09 05:46:39 +0000 | [diff] [blame] | 894 | |
| 895 | switch (Op.getOpcode()) { |
| 896 | default: |
| 897 | Scalars.push_back(DAG.getNode(Op.getOpcode(), EltVT, |
| 898 | &Operands[0], Operands.size())); |
| 899 | break; |
| 900 | case ISD::SHL: |
| 901 | case ISD::SRA: |
| 902 | case ISD::SRL: |
Duncan Sands | 92abc62 | 2009-01-31 15:50:11 +0000 | [diff] [blame] | 903 | case ISD::ROTL: |
| 904 | case ISD::ROTR: |
Mon P Wang | e9f1015 | 2008-12-09 05:46:39 +0000 | [diff] [blame] | 905 | Scalars.push_back(DAG.getNode(Op.getOpcode(), EltVT, Operands[0], |
Duncan Sands | 92abc62 | 2009-01-31 15:50:11 +0000 | [diff] [blame] | 906 | DAG.getShiftAmountOperand(Operands[1]))); |
Mon P Wang | e9f1015 | 2008-12-09 05:46:39 +0000 | [diff] [blame] | 907 | break; |
| 908 | } |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | return DAG.getNode(ISD::BUILD_VECTOR, VT, &Scalars[0], Scalars.size()); |
| 912 | } |
| 913 | |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 914 | /// GetFPLibCall - Return the right libcall for the given floating point type. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 915 | static RTLIB::Libcall GetFPLibCall(MVT VT, |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 916 | RTLIB::Libcall Call_F32, |
| 917 | RTLIB::Libcall Call_F64, |
| 918 | RTLIB::Libcall Call_F80, |
| 919 | RTLIB::Libcall Call_PPCF128) { |
| 920 | return |
| 921 | VT == MVT::f32 ? Call_F32 : |
| 922 | VT == MVT::f64 ? Call_F64 : |
| 923 | VT == MVT::f80 ? Call_F80 : |
| 924 | VT == MVT::ppcf128 ? Call_PPCF128 : |
| 925 | RTLIB::UNKNOWN_LIBCALL; |
| 926 | } |
| 927 | |
Nate Begeman | 6867991 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 928 | /// PerformInsertVectorEltInMemory - Some target cannot handle a variable |
| 929 | /// insertion index for the INSERT_VECTOR_ELT instruction. In this case, it |
| 930 | /// is necessary to spill the vector being inserted into to memory, perform |
| 931 | /// the insert there, and then read the result back. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 932 | SDValue SelectionDAGLegalize:: |
| 933 | PerformInsertVectorEltInMemory(SDValue Vec, SDValue Val, SDValue Idx) { |
| 934 | SDValue Tmp1 = Vec; |
| 935 | SDValue Tmp2 = Val; |
| 936 | SDValue Tmp3 = Idx; |
Nate Begeman | 6867991 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 937 | |
| 938 | // If the target doesn't support this, we have to spill the input vector |
| 939 | // to a temporary stack slot, update the element, then reload it. This is |
| 940 | // badness. We could also load the value into a vector register (either |
| 941 | // with a "move to register" or "extload into register" instruction, then |
| 942 | // permute it into place, if the idx is a constant and if the idx is |
| 943 | // supported by the target. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 944 | MVT VT = Tmp1.getValueType(); |
| 945 | MVT EltVT = VT.getVectorElementType(); |
| 946 | MVT IdxVT = Tmp3.getValueType(); |
| 947 | MVT PtrVT = TLI.getPointerTy(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 948 | SDValue StackPtr = DAG.CreateStackTemporary(VT); |
Nate Begeman | 6867991 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 949 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 950 | int SPFI = cast<FrameIndexSDNode>(StackPtr.getNode())->getIndex(); |
Nate Begeman | 6867991 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 951 | |
| 952 | // Store the vector. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 953 | SDValue Ch = DAG.getStore(DAG.getEntryNode(), Tmp1, StackPtr, |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 954 | PseudoSourceValue::getFixedStack(SPFI), 0); |
Nate Begeman | 6867991 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 955 | |
| 956 | // Truncate or zero extend offset to target pointer type. |
Duncan Sands | 8e4eb09 | 2008-06-08 20:54:56 +0000 | [diff] [blame] | 957 | unsigned CastOpc = IdxVT.bitsGT(PtrVT) ? ISD::TRUNCATE : ISD::ZERO_EXTEND; |
Nate Begeman | 6867991 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 958 | Tmp3 = DAG.getNode(CastOpc, PtrVT, Tmp3); |
| 959 | // Add the offset to the index. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 960 | unsigned EltSize = EltVT.getSizeInBits()/8; |
Nate Begeman | 6867991 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 961 | Tmp3 = DAG.getNode(ISD::MUL, IdxVT, Tmp3,DAG.getConstant(EltSize, IdxVT)); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 962 | SDValue StackPtr2 = DAG.getNode(ISD::ADD, IdxVT, Tmp3, StackPtr); |
Nate Begeman | 6867991 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 963 | // Store the scalar value. |
| 964 | Ch = DAG.getTruncStore(Ch, Tmp2, StackPtr2, |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 965 | PseudoSourceValue::getFixedStack(SPFI), 0, EltVT); |
Nate Begeman | 6867991 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 966 | // Load the updated vector. |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 967 | return DAG.getLoad(VT, Ch, StackPtr, |
| 968 | PseudoSourceValue::getFixedStack(SPFI), 0); |
Nate Begeman | 6867991 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 969 | } |
| 970 | |
Mon P Wang | e9f1015 | 2008-12-09 05:46:39 +0000 | [diff] [blame] | 971 | |
Dan Gohman | a346615 | 2007-07-13 20:14:11 +0000 | [diff] [blame] | 972 | /// LegalizeOp - We know that the specified value has a legal type, and |
| 973 | /// that its operands are legal. Now ensure that the operation itself |
| 974 | /// is legal, recursively ensuring that the operands' operations remain |
| 975 | /// legal. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 976 | SDValue SelectionDAGLegalize::LegalizeOp(SDValue Op) { |
Chris Lattner | 09ec1b0 | 2007-08-25 01:00:22 +0000 | [diff] [blame] | 977 | if (Op.getOpcode() == ISD::TargetConstant) // Allow illegal target nodes. |
| 978 | return Op; |
| 979 | |
Chris Lattner | c9c60f6 | 2005-08-24 16:35:28 +0000 | [diff] [blame] | 980 | assert(isTypeLegal(Op.getValueType()) && |
Chris Lattner | e3304a3 | 2005-01-08 20:35:13 +0000 | [diff] [blame] | 981 | "Caller should expand or promote operands that are not legal!"); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 982 | SDNode *Node = Op.getNode(); |
Dale Johannesen | 7d2ad62 | 2009-01-30 23:10:59 +0000 | [diff] [blame] | 983 | DebugLoc dl = Node->getDebugLoc(); |
Chris Lattner | e3304a3 | 2005-01-08 20:35:13 +0000 | [diff] [blame] | 984 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 985 | // If this operation defines any values that cannot be represented in a |
Chris Lattner | e3304a3 | 2005-01-08 20:35:13 +0000 | [diff] [blame] | 986 | // register on this target, make sure to expand or promote them. |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 987 | if (Node->getNumValues() > 1) { |
| 988 | for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 989 | if (getTypeAction(Node->getValueType(i)) != Legal) { |
| 990 | HandleOp(Op.getValue(i)); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 991 | assert(LegalizedNodes.count(Op) && |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 992 | "Handling didn't add legal operands!"); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 993 | return LegalizedNodes[Op]; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 994 | } |
| 995 | } |
| 996 | |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 997 | // Note that LegalizeOp may be reentered even from single-use nodes, which |
| 998 | // means that we always must cache transformed nodes. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 999 | DenseMap<SDValue, SDValue>::iterator I = LegalizedNodes.find(Op); |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 1000 | if (I != LegalizedNodes.end()) return I->second; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1001 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1002 | SDValue Tmp1, Tmp2, Tmp3, Tmp4; |
| 1003 | SDValue Result = Op; |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 1004 | bool isCustom = false; |
| 1005 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1006 | switch (Node->getOpcode()) { |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 1007 | case ISD::FrameIndex: |
| 1008 | case ISD::EntryToken: |
| 1009 | case ISD::Register: |
| 1010 | case ISD::BasicBlock: |
| 1011 | case ISD::TargetFrameIndex: |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 1012 | case ISD::TargetJumpTable: |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 1013 | case ISD::TargetConstant: |
Chris Lattner | 3181a77 | 2006-01-29 06:26:56 +0000 | [diff] [blame] | 1014 | case ISD::TargetConstantFP: |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 1015 | case ISD::TargetConstantPool: |
| 1016 | case ISD::TargetGlobalAddress: |
Lauro Ramos Venancio | b3a0417 | 2007-04-20 21:38:10 +0000 | [diff] [blame] | 1017 | case ISD::TargetGlobalTLSAddress: |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 1018 | case ISD::TargetExternalSymbol: |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 1019 | case ISD::VALUETYPE: |
| 1020 | case ISD::SRCVALUE: |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 1021 | case ISD::MEMOPERAND: |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 1022 | case ISD::CONDCODE: |
Duncan Sands | 276dcbd | 2008-03-21 09:14:45 +0000 | [diff] [blame] | 1023 | case ISD::ARG_FLAGS: |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 1024 | // Primitives must all be legal. |
Duncan Sands | a7c97a7 | 2007-10-16 09:07:20 +0000 | [diff] [blame] | 1025 | assert(TLI.isOperationLegal(Node->getOpcode(), Node->getValueType(0)) && |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 1026 | "This must be legal!"); |
| 1027 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1028 | default: |
Chris Lattner | d73cc5d | 2005-05-14 06:34:48 +0000 | [diff] [blame] | 1029 | if (Node->getOpcode() >= ISD::BUILTIN_OP_END) { |
| 1030 | // If this is a target node, legalize it by legalizing the operands then |
| 1031 | // passing it through. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1032 | SmallVector<SDValue, 8> Ops; |
Chris Lattner | c5d7d7c | 2006-05-17 18:00:08 +0000 | [diff] [blame] | 1033 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) |
Chris Lattner | d73cc5d | 2005-05-14 06:34:48 +0000 | [diff] [blame] | 1034 | Ops.push_back(LegalizeOp(Node->getOperand(i))); |
Chris Lattner | c5d7d7c | 2006-05-17 18:00:08 +0000 | [diff] [blame] | 1035 | |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1036 | Result = DAG.UpdateNodeOperands(Result.getValue(0), &Ops[0], Ops.size()); |
Chris Lattner | d73cc5d | 2005-05-14 06:34:48 +0000 | [diff] [blame] | 1037 | |
| 1038 | for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) |
| 1039 | AddLegalizedOperand(Op.getValue(i), Result.getValue(i)); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 1040 | return Result.getValue(Op.getResNo()); |
Chris Lattner | d73cc5d | 2005-05-14 06:34:48 +0000 | [diff] [blame] | 1041 | } |
| 1042 | // Otherwise this is an unhandled builtin node. splat. |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 1043 | #ifndef NDEBUG |
Dan Gohman | 3983358 | 2007-06-04 16:17:33 +0000 | [diff] [blame] | 1044 | cerr << "NODE: "; Node->dump(&DAG); cerr << "\n"; |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 1045 | #endif |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1046 | assert(0 && "Do not know how to legalize this operator!"); |
| 1047 | abort(); |
Lauro Ramos Venancio | 0d3b678 | 2007-04-20 23:02:39 +0000 | [diff] [blame] | 1048 | case ISD::GLOBAL_OFFSET_TABLE: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1049 | case ISD::GlobalAddress: |
Lauro Ramos Venancio | b3a0417 | 2007-04-20 21:38:10 +0000 | [diff] [blame] | 1050 | case ISD::GlobalTLSAddress: |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 1051 | case ISD::ExternalSymbol: |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 1052 | case ISD::ConstantPool: |
| 1053 | case ISD::JumpTable: // Nothing to do. |
Chris Lattner | 0c8fbe3 | 2005-11-17 06:41:44 +0000 | [diff] [blame] | 1054 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 1055 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 1056 | case TargetLowering::Custom: |
| 1057 | Tmp1 = TLI.LowerOperation(Op, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1058 | if (Tmp1.getNode()) Result = Tmp1; |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 1059 | // 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] | 1060 | case TargetLowering::Legal: |
Chris Lattner | 0c8fbe3 | 2005-11-17 06:41:44 +0000 | [diff] [blame] | 1061 | break; |
| 1062 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1063 | break; |
Nate Begeman | bcc5f36 | 2007-01-29 22:58:52 +0000 | [diff] [blame] | 1064 | case ISD::FRAMEADDR: |
| 1065 | case ISD::RETURNADDR: |
| 1066 | // The only option for these nodes is to custom lower them. If the target |
| 1067 | // does not custom lower them, then return zero. |
| 1068 | Tmp1 = TLI.LowerOperation(Op, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1069 | if (Tmp1.getNode()) |
Nate Begeman | bcc5f36 | 2007-01-29 22:58:52 +0000 | [diff] [blame] | 1070 | Result = Tmp1; |
| 1071 | else |
| 1072 | Result = DAG.getConstant(0, TLI.getPointerTy()); |
| 1073 | break; |
Anton Korobeynikov | 055c544 | 2007-08-29 23:18:48 +0000 | [diff] [blame] | 1074 | case ISD::FRAME_TO_ARGS_OFFSET: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1075 | MVT VT = Node->getValueType(0); |
Anton Korobeynikov | 066f7b4 | 2007-08-29 19:28:29 +0000 | [diff] [blame] | 1076 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 1077 | default: assert(0 && "This action is not supported yet!"); |
| 1078 | case TargetLowering::Custom: |
| 1079 | Result = TLI.LowerOperation(Op, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1080 | if (Result.getNode()) break; |
Anton Korobeynikov | 066f7b4 | 2007-08-29 19:28:29 +0000 | [diff] [blame] | 1081 | // Fall Thru |
| 1082 | case TargetLowering::Legal: |
| 1083 | Result = DAG.getConstant(0, VT); |
| 1084 | break; |
| 1085 | } |
Anton Korobeynikov | 055c544 | 2007-08-29 23:18:48 +0000 | [diff] [blame] | 1086 | } |
Anton Korobeynikov | 066f7b4 | 2007-08-29 19:28:29 +0000 | [diff] [blame] | 1087 | break; |
Jim Laskey | 2bc210d | 2007-02-22 15:37:19 +0000 | [diff] [blame] | 1088 | case ISD::EXCEPTIONADDR: { |
| 1089 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1090 | MVT VT = Node->getValueType(0); |
Jim Laskey | 2bc210d | 2007-02-22 15:37:19 +0000 | [diff] [blame] | 1091 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 1092 | default: assert(0 && "This action is not supported yet!"); |
| 1093 | case TargetLowering::Expand: { |
Jim Laskey | 8782d48 | 2007-02-28 20:43:58 +0000 | [diff] [blame] | 1094 | unsigned Reg = TLI.getExceptionAddressRegister(); |
Duncan Sands | b027fa0 | 2007-12-31 18:35:50 +0000 | [diff] [blame] | 1095 | Result = DAG.getCopyFromReg(Tmp1, Reg, VT); |
Jim Laskey | 2bc210d | 2007-02-22 15:37:19 +0000 | [diff] [blame] | 1096 | } |
| 1097 | break; |
| 1098 | case TargetLowering::Custom: |
| 1099 | Result = TLI.LowerOperation(Op, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1100 | if (Result.getNode()) break; |
Jim Laskey | 2bc210d | 2007-02-22 15:37:19 +0000 | [diff] [blame] | 1101 | // Fall Thru |
Chris Lattner | eb7f34f | 2007-04-27 17:12:52 +0000 | [diff] [blame] | 1102 | case TargetLowering::Legal: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1103 | SDValue Ops[] = { DAG.getConstant(0, VT), Tmp1 }; |
Duncan Sands | 4bdcb61 | 2008-07-02 17:40:58 +0000 | [diff] [blame] | 1104 | Result = DAG.getMergeValues(Ops, 2); |
Jim Laskey | 2bc210d | 2007-02-22 15:37:19 +0000 | [diff] [blame] | 1105 | break; |
| 1106 | } |
| 1107 | } |
Chris Lattner | eb7f34f | 2007-04-27 17:12:52 +0000 | [diff] [blame] | 1108 | } |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1109 | if (Result.getNode()->getNumValues() == 1) break; |
Duncan Sands | b027fa0 | 2007-12-31 18:35:50 +0000 | [diff] [blame] | 1110 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1111 | assert(Result.getNode()->getNumValues() == 2 && |
Duncan Sands | b027fa0 | 2007-12-31 18:35:50 +0000 | [diff] [blame] | 1112 | "Cannot return more than two values!"); |
| 1113 | |
| 1114 | // Since we produced two values, make sure to remember that we |
| 1115 | // legalized both of them. |
| 1116 | Tmp1 = LegalizeOp(Result); |
| 1117 | Tmp2 = LegalizeOp(Result.getValue(1)); |
| 1118 | AddLegalizedOperand(Op.getValue(0), Tmp1); |
| 1119 | AddLegalizedOperand(Op.getValue(1), Tmp2); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 1120 | return Op.getResNo() ? Tmp2 : Tmp1; |
Jim Laskey | 8782d48 | 2007-02-28 20:43:58 +0000 | [diff] [blame] | 1121 | case ISD::EHSELECTION: { |
| 1122 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1123 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1124 | MVT VT = Node->getValueType(0); |
Jim Laskey | 8782d48 | 2007-02-28 20:43:58 +0000 | [diff] [blame] | 1125 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 1126 | default: assert(0 && "This action is not supported yet!"); |
| 1127 | case TargetLowering::Expand: { |
| 1128 | unsigned Reg = TLI.getExceptionSelectorRegister(); |
Duncan Sands | b027fa0 | 2007-12-31 18:35:50 +0000 | [diff] [blame] | 1129 | Result = DAG.getCopyFromReg(Tmp2, Reg, VT); |
Jim Laskey | 8782d48 | 2007-02-28 20:43:58 +0000 | [diff] [blame] | 1130 | } |
| 1131 | break; |
| 1132 | case TargetLowering::Custom: |
| 1133 | Result = TLI.LowerOperation(Op, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1134 | if (Result.getNode()) break; |
Jim Laskey | 8782d48 | 2007-02-28 20:43:58 +0000 | [diff] [blame] | 1135 | // Fall Thru |
Chris Lattner | eb7f34f | 2007-04-27 17:12:52 +0000 | [diff] [blame] | 1136 | case TargetLowering::Legal: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1137 | SDValue Ops[] = { DAG.getConstant(0, VT), Tmp2 }; |
Duncan Sands | 4bdcb61 | 2008-07-02 17:40:58 +0000 | [diff] [blame] | 1138 | Result = DAG.getMergeValues(Ops, 2); |
Jim Laskey | 8782d48 | 2007-02-28 20:43:58 +0000 | [diff] [blame] | 1139 | break; |
| 1140 | } |
| 1141 | } |
Chris Lattner | eb7f34f | 2007-04-27 17:12:52 +0000 | [diff] [blame] | 1142 | } |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1143 | if (Result.getNode()->getNumValues() == 1) break; |
Duncan Sands | b027fa0 | 2007-12-31 18:35:50 +0000 | [diff] [blame] | 1144 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1145 | assert(Result.getNode()->getNumValues() == 2 && |
Duncan Sands | b027fa0 | 2007-12-31 18:35:50 +0000 | [diff] [blame] | 1146 | "Cannot return more than two values!"); |
| 1147 | |
| 1148 | // Since we produced two values, make sure to remember that we |
| 1149 | // legalized both of them. |
| 1150 | Tmp1 = LegalizeOp(Result); |
| 1151 | Tmp2 = LegalizeOp(Result.getValue(1)); |
| 1152 | AddLegalizedOperand(Op.getValue(0), Tmp1); |
| 1153 | AddLegalizedOperand(Op.getValue(1), Tmp2); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 1154 | return Op.getResNo() ? Tmp2 : Tmp1; |
Nick Lewycky | 6d4b711 | 2007-07-14 15:11:14 +0000 | [diff] [blame] | 1155 | case ISD::EH_RETURN: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1156 | MVT VT = Node->getValueType(0); |
Anton Korobeynikov | 2365f51 | 2007-07-14 14:06:15 +0000 | [diff] [blame] | 1157 | // The only "good" option for this node is to custom lower it. |
| 1158 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 1159 | default: assert(0 && "This action is not supported at all!"); |
| 1160 | case TargetLowering::Custom: |
| 1161 | Result = TLI.LowerOperation(Op, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1162 | if (Result.getNode()) break; |
Anton Korobeynikov | 2365f51 | 2007-07-14 14:06:15 +0000 | [diff] [blame] | 1163 | // Fall Thru |
| 1164 | case TargetLowering::Legal: |
| 1165 | // Target does not know, how to lower this, lower to noop |
| 1166 | Result = LegalizeOp(Node->getOperand(0)); |
| 1167 | break; |
| 1168 | } |
Nick Lewycky | 6d4b711 | 2007-07-14 15:11:14 +0000 | [diff] [blame] | 1169 | } |
Anton Korobeynikov | 2365f51 | 2007-07-14 14:06:15 +0000 | [diff] [blame] | 1170 | break; |
Chris Lattner | 08951a3 | 2005-09-02 01:15:01 +0000 | [diff] [blame] | 1171 | case ISD::AssertSext: |
| 1172 | case ISD::AssertZext: |
| 1173 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1174 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
Chris Lattner | 08951a3 | 2005-09-02 01:15:01 +0000 | [diff] [blame] | 1175 | break; |
Chris Lattner | 308575b | 2005-11-20 22:56:56 +0000 | [diff] [blame] | 1176 | case ISD::MERGE_VALUES: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1177 | // Legalize eliminates MERGE_VALUES nodes. |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 1178 | Result = Node->getOperand(Op.getResNo()); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 1179 | break; |
Chris Lattner | 69a5215 | 2005-01-14 22:38:01 +0000 | [diff] [blame] | 1180 | case ISD::CopyFromReg: |
| 1181 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 1182 | Result = Op.getValue(0); |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 1183 | if (Node->getNumValues() == 2) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1184 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 1185 | } else { |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 1186 | assert(Node->getNumValues() == 3 && "Invalid copyfromreg!"); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1187 | if (Node->getNumOperands() == 3) { |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 1188 | Tmp2 = LegalizeOp(Node->getOperand(2)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1189 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1),Tmp2); |
| 1190 | } else { |
| 1191 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
| 1192 | } |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 1193 | AddLegalizedOperand(Op.getValue(2), Result.getValue(2)); |
| 1194 | } |
Chris Lattner | 13c184d | 2005-01-28 06:27:38 +0000 | [diff] [blame] | 1195 | // Since CopyFromReg produces two values, make sure to remember that we |
| 1196 | // legalized both of them. |
| 1197 | AddLegalizedOperand(Op.getValue(0), Result); |
| 1198 | AddLegalizedOperand(Op.getValue(1), Result.getValue(1)); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 1199 | return Result.getValue(Op.getResNo()); |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 1200 | case ISD::UNDEF: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1201 | MVT VT = Op.getValueType(); |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 1202 | switch (TLI.getOperationAction(ISD::UNDEF, VT)) { |
Nate Begeman | ea19cd5 | 2005-04-02 00:41:14 +0000 | [diff] [blame] | 1203 | default: assert(0 && "This action is not supported yet!"); |
| 1204 | case TargetLowering::Expand: |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1205 | if (VT.isInteger()) |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 1206 | Result = DAG.getConstant(0, VT); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1207 | else if (VT.isFloatingPoint()) |
| 1208 | Result = DAG.getConstantFP(APFloat(APInt(VT.getSizeInBits(), 0)), |
Dale Johannesen | f41db21 | 2007-09-26 17:26:49 +0000 | [diff] [blame] | 1209 | VT); |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 1210 | else |
| 1211 | assert(0 && "Unknown value type!"); |
| 1212 | break; |
Nate Begeman | ea19cd5 | 2005-04-02 00:41:14 +0000 | [diff] [blame] | 1213 | case TargetLowering::Legal: |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 1214 | break; |
| 1215 | } |
| 1216 | break; |
| 1217 | } |
Chris Lattner | d1f04d4 | 2006-03-24 02:26:29 +0000 | [diff] [blame] | 1218 | |
Chris Lattner | 48b61a7 | 2006-03-28 00:40:33 +0000 | [diff] [blame] | 1219 | case ISD::INTRINSIC_W_CHAIN: |
| 1220 | case ISD::INTRINSIC_WO_CHAIN: |
| 1221 | case ISD::INTRINSIC_VOID: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1222 | SmallVector<SDValue, 8> Ops; |
Chris Lattner | d1f04d4 | 2006-03-24 02:26:29 +0000 | [diff] [blame] | 1223 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) |
| 1224 | Ops.push_back(LegalizeOp(Node->getOperand(i))); |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1225 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 10d7fa6 | 2006-03-26 09:12:51 +0000 | [diff] [blame] | 1226 | |
| 1227 | // Allow the target to custom lower its intrinsics if it wants to. |
Chris Lattner | 48b61a7 | 2006-03-28 00:40:33 +0000 | [diff] [blame] | 1228 | if (TLI.getOperationAction(Node->getOpcode(), MVT::Other) == |
Chris Lattner | 10d7fa6 | 2006-03-26 09:12:51 +0000 | [diff] [blame] | 1229 | TargetLowering::Custom) { |
| 1230 | Tmp3 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1231 | if (Tmp3.getNode()) Result = Tmp3; |
Chris Lattner | 13fc2f1 | 2006-03-27 20:28:29 +0000 | [diff] [blame] | 1232 | } |
| 1233 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1234 | if (Result.getNode()->getNumValues() == 1) break; |
Chris Lattner | 13fc2f1 | 2006-03-27 20:28:29 +0000 | [diff] [blame] | 1235 | |
| 1236 | // Must have return value and chain result. |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1237 | assert(Result.getNode()->getNumValues() == 2 && |
Chris Lattner | 13fc2f1 | 2006-03-27 20:28:29 +0000 | [diff] [blame] | 1238 | "Cannot return more than two values!"); |
| 1239 | |
| 1240 | // Since loads produce two values, make sure to remember that we |
| 1241 | // legalized both of them. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1242 | AddLegalizedOperand(SDValue(Node, 0), Result.getValue(0)); |
| 1243 | AddLegalizedOperand(SDValue(Node, 1), Result.getValue(1)); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 1244 | return Result.getValue(Op.getResNo()); |
Chris Lattner | d1f04d4 | 2006-03-24 02:26:29 +0000 | [diff] [blame] | 1245 | } |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 1246 | |
Dan Gohman | 7f46020 | 2008-06-30 20:59:49 +0000 | [diff] [blame] | 1247 | case ISD::DBG_STOPPOINT: |
| 1248 | assert(Node->getNumOperands() == 1 && "Invalid DBG_STOPPOINT node!"); |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 1249 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the input chain. |
| 1250 | |
Dan Gohman | 7f46020 | 2008-06-30 20:59:49 +0000 | [diff] [blame] | 1251 | switch (TLI.getOperationAction(ISD::DBG_STOPPOINT, MVT::Other)) { |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 1252 | case TargetLowering::Promote: |
| 1253 | default: assert(0 && "This action is not supported yet!"); |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 1254 | case TargetLowering::Expand: { |
Devang Patel | 83489bb | 2009-01-13 00:35:13 +0000 | [diff] [blame] | 1255 | DwarfWriter *DW = DAG.getDwarfWriter(); |
Dan Gohman | f560ffa | 2009-01-28 17:46:25 +0000 | [diff] [blame] | 1256 | bool useDEBUG_LOC = TLI.isOperationLegalOrCustom(ISD::DEBUG_LOC, |
| 1257 | MVT::Other); |
| 1258 | bool useLABEL = TLI.isOperationLegalOrCustom(ISD::DBG_LABEL, MVT::Other); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1259 | |
Dan Gohman | 7f46020 | 2008-06-30 20:59:49 +0000 | [diff] [blame] | 1260 | const DbgStopPointSDNode *DSP = cast<DbgStopPointSDNode>(Node); |
Devang Patel | 83489bb | 2009-01-13 00:35:13 +0000 | [diff] [blame] | 1261 | GlobalVariable *CU_GV = cast<GlobalVariable>(DSP->getCompileUnit()); |
| 1262 | if (DW && (useDEBUG_LOC || useLABEL) && !CU_GV->isDeclaration()) { |
| 1263 | DICompileUnit CU(cast<GlobalVariable>(DSP->getCompileUnit())); |
| 1264 | unsigned SrcFile = DW->RecordSource(CU.getDirectory(), |
| 1265 | CU.getFilename()); |
| 1266 | |
Dan Gohman | 7f46020 | 2008-06-30 20:59:49 +0000 | [diff] [blame] | 1267 | unsigned Line = DSP->getLine(); |
| 1268 | unsigned Col = DSP->getColumn(); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1269 | |
| 1270 | if (useDEBUG_LOC) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1271 | SDValue Ops[] = { Tmp1, DAG.getConstant(Line, MVT::i32), |
Evan Cheng | 71e8685 | 2008-07-08 20:06:39 +0000 | [diff] [blame] | 1272 | DAG.getConstant(Col, MVT::i32), |
| 1273 | DAG.getConstant(SrcFile, MVT::i32) }; |
| 1274 | Result = DAG.getNode(ISD::DEBUG_LOC, MVT::Other, Ops, 4); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1275 | } else { |
Devang Patel | 83489bb | 2009-01-13 00:35:13 +0000 | [diff] [blame] | 1276 | unsigned ID = DW->RecordSourceLine(Line, Col, SrcFile); |
Dan Gohman | 4406604 | 2008-07-01 00:05:16 +0000 | [diff] [blame] | 1277 | Result = DAG.getLabel(ISD::DBG_LABEL, Tmp1, ID); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1278 | } |
Jim Laskey | e81aecb | 2005-12-21 20:51:37 +0000 | [diff] [blame] | 1279 | } else { |
| 1280 | Result = Tmp1; // chain |
| 1281 | } |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 1282 | break; |
Chris Lattner | e773673 | 2005-12-18 23:54:29 +0000 | [diff] [blame] | 1283 | } |
Evan Cheng | 71e8685 | 2008-07-08 20:06:39 +0000 | [diff] [blame] | 1284 | case TargetLowering::Legal: { |
| 1285 | LegalizeAction Action = getTypeAction(Node->getOperand(1).getValueType()); |
| 1286 | if (Action == Legal && Tmp1 == Node->getOperand(0)) |
| 1287 | break; |
| 1288 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1289 | SmallVector<SDValue, 8> Ops; |
Evan Cheng | 71e8685 | 2008-07-08 20:06:39 +0000 | [diff] [blame] | 1290 | Ops.push_back(Tmp1); |
| 1291 | if (Action == Legal) { |
| 1292 | Ops.push_back(Node->getOperand(1)); // line # must be legal. |
| 1293 | Ops.push_back(Node->getOperand(2)); // col # must be legal. |
| 1294 | } else { |
| 1295 | // Otherwise promote them. |
| 1296 | Ops.push_back(PromoteOp(Node->getOperand(1))); |
| 1297 | Ops.push_back(PromoteOp(Node->getOperand(2))); |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 1298 | } |
Evan Cheng | 71e8685 | 2008-07-08 20:06:39 +0000 | [diff] [blame] | 1299 | Ops.push_back(Node->getOperand(3)); // filename must be legal. |
| 1300 | Ops.push_back(Node->getOperand(4)); // working dir # must be legal. |
| 1301 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 1302 | break; |
| 1303 | } |
Evan Cheng | 71e8685 | 2008-07-08 20:06:39 +0000 | [diff] [blame] | 1304 | } |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 1305 | break; |
Evan Cheng | a844bde | 2008-02-02 04:07:54 +0000 | [diff] [blame] | 1306 | |
| 1307 | case ISD::DECLARE: |
| 1308 | assert(Node->getNumOperands() == 3 && "Invalid DECLARE node!"); |
| 1309 | switch (TLI.getOperationAction(ISD::DECLARE, MVT::Other)) { |
| 1310 | default: assert(0 && "This action is not supported yet!"); |
| 1311 | case TargetLowering::Legal: |
| 1312 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1313 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the address. |
| 1314 | Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the variable. |
| 1315 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
| 1316 | break; |
Chris Lattner | e07415d | 2008-02-28 05:53:40 +0000 | [diff] [blame] | 1317 | case TargetLowering::Expand: |
| 1318 | Result = LegalizeOp(Node->getOperand(0)); |
| 1319 | break; |
Evan Cheng | a844bde | 2008-02-02 04:07:54 +0000 | [diff] [blame] | 1320 | } |
| 1321 | break; |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 1322 | |
| 1323 | case ISD::DEBUG_LOC: |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1324 | assert(Node->getNumOperands() == 4 && "Invalid DEBUG_LOC node!"); |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 1325 | switch (TLI.getOperationAction(ISD::DEBUG_LOC, MVT::Other)) { |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 1326 | default: assert(0 && "This action is not supported yet!"); |
Evan Cheng | 71e8685 | 2008-07-08 20:06:39 +0000 | [diff] [blame] | 1327 | case TargetLowering::Legal: { |
| 1328 | LegalizeAction Action = getTypeAction(Node->getOperand(1).getValueType()); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1329 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Evan Cheng | 71e8685 | 2008-07-08 20:06:39 +0000 | [diff] [blame] | 1330 | if (Action == Legal && Tmp1 == Node->getOperand(0)) |
| 1331 | break; |
| 1332 | if (Action == Legal) { |
| 1333 | Tmp2 = Node->getOperand(1); |
| 1334 | Tmp3 = Node->getOperand(2); |
| 1335 | Tmp4 = Node->getOperand(3); |
| 1336 | } else { |
| 1337 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the line #. |
| 1338 | Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the col #. |
| 1339 | Tmp4 = LegalizeOp(Node->getOperand(3)); // Legalize the source file id. |
| 1340 | } |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1341 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3, Tmp4); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1342 | break; |
| 1343 | } |
Evan Cheng | 71e8685 | 2008-07-08 20:06:39 +0000 | [diff] [blame] | 1344 | } |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1345 | break; |
| 1346 | |
Dan Gohman | 4406604 | 2008-07-01 00:05:16 +0000 | [diff] [blame] | 1347 | case ISD::DBG_LABEL: |
| 1348 | case ISD::EH_LABEL: |
| 1349 | assert(Node->getNumOperands() == 1 && "Invalid LABEL node!"); |
| 1350 | switch (TLI.getOperationAction(Node->getOpcode(), MVT::Other)) { |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1351 | default: assert(0 && "This action is not supported yet!"); |
| 1352 | case TargetLowering::Legal: |
| 1353 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Dan Gohman | 4406604 | 2008-07-01 00:05:16 +0000 | [diff] [blame] | 1354 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 1355 | break; |
Chris Lattner | a9569f1 | 2007-03-03 19:21:38 +0000 | [diff] [blame] | 1356 | case TargetLowering::Expand: |
| 1357 | Result = LegalizeOp(Node->getOperand(0)); |
| 1358 | break; |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 1359 | } |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 1360 | break; |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 1361 | |
Evan Cheng | 27b7db5 | 2008-03-08 00:58:38 +0000 | [diff] [blame] | 1362 | case ISD::PREFETCH: |
| 1363 | assert(Node->getNumOperands() == 4 && "Invalid Prefetch node!"); |
| 1364 | switch (TLI.getOperationAction(ISD::PREFETCH, MVT::Other)) { |
| 1365 | default: assert(0 && "This action is not supported yet!"); |
| 1366 | case TargetLowering::Legal: |
| 1367 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1368 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the address. |
| 1369 | Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the rw specifier. |
| 1370 | Tmp4 = LegalizeOp(Node->getOperand(3)); // Legalize locality specifier. |
| 1371 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3, Tmp4); |
| 1372 | break; |
| 1373 | case TargetLowering::Expand: |
| 1374 | // It's a noop. |
| 1375 | Result = LegalizeOp(Node->getOperand(0)); |
| 1376 | break; |
| 1377 | } |
| 1378 | break; |
| 1379 | |
Andrew Lenharth | 22c5c1b | 2008-02-16 01:24:58 +0000 | [diff] [blame] | 1380 | case ISD::MEMBARRIER: { |
| 1381 | assert(Node->getNumOperands() == 6 && "Invalid MemBarrier node!"); |
Andrew Lenharth | d497d9f | 2008-02-16 14:46:26 +0000 | [diff] [blame] | 1382 | switch (TLI.getOperationAction(ISD::MEMBARRIER, MVT::Other)) { |
| 1383 | default: assert(0 && "This action is not supported yet!"); |
| 1384 | case TargetLowering::Legal: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1385 | SDValue Ops[6]; |
Andrew Lenharth | d497d9f | 2008-02-16 14:46:26 +0000 | [diff] [blame] | 1386 | Ops[0] = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Duncan Sands | e90a615 | 2008-02-27 08:53:44 +0000 | [diff] [blame] | 1387 | for (int x = 1; x < 6; ++x) { |
| 1388 | Ops[x] = Node->getOperand(x); |
| 1389 | if (!isTypeLegal(Ops[x].getValueType())) |
| 1390 | Ops[x] = PromoteOp(Ops[x]); |
| 1391 | } |
Andrew Lenharth | d497d9f | 2008-02-16 14:46:26 +0000 | [diff] [blame] | 1392 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], 6); |
| 1393 | break; |
| 1394 | } |
| 1395 | case TargetLowering::Expand: |
| 1396 | //There is no libgcc call for this op |
| 1397 | Result = Node->getOperand(0); // Noop |
| 1398 | break; |
| 1399 | } |
Andrew Lenharth | 22c5c1b | 2008-02-16 01:24:58 +0000 | [diff] [blame] | 1400 | break; |
| 1401 | } |
| 1402 | |
Dan Gohman | 0b1d4a7 | 2008-12-23 21:37:04 +0000 | [diff] [blame] | 1403 | case ISD::ATOMIC_CMP_SWAP: { |
Mon P Wang | 63307c3 | 2008-05-05 19:05:59 +0000 | [diff] [blame] | 1404 | unsigned int num_operands = 4; |
| 1405 | assert(Node->getNumOperands() == num_operands && "Invalid Atomic node!"); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1406 | SDValue Ops[4]; |
Mon P Wang | 63307c3 | 2008-05-05 19:05:59 +0000 | [diff] [blame] | 1407 | for (unsigned int x = 0; x < num_operands; ++x) |
Andrew Lenharth | 26ed869 | 2008-03-01 21:52:34 +0000 | [diff] [blame] | 1408 | Ops[x] = LegalizeOp(Node->getOperand(x)); |
Mon P Wang | 63307c3 | 2008-05-05 19:05:59 +0000 | [diff] [blame] | 1409 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], num_operands); |
| 1410 | |
| 1411 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 1412 | default: assert(0 && "This action is not supported yet!"); |
| 1413 | case TargetLowering::Custom: |
| 1414 | Result = TLI.LowerOperation(Result, DAG); |
| 1415 | break; |
| 1416 | case TargetLowering::Legal: |
| 1417 | break; |
| 1418 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1419 | AddLegalizedOperand(SDValue(Node, 0), Result.getValue(0)); |
| 1420 | AddLegalizedOperand(SDValue(Node, 1), Result.getValue(1)); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 1421 | return Result.getValue(Op.getResNo()); |
Duncan Sands | 126d907 | 2008-07-04 11:47:58 +0000 | [diff] [blame] | 1422 | } |
Dan Gohman | 0b1d4a7 | 2008-12-23 21:37:04 +0000 | [diff] [blame] | 1423 | case ISD::ATOMIC_LOAD_ADD: |
| 1424 | case ISD::ATOMIC_LOAD_SUB: |
| 1425 | case ISD::ATOMIC_LOAD_AND: |
| 1426 | case ISD::ATOMIC_LOAD_OR: |
| 1427 | case ISD::ATOMIC_LOAD_XOR: |
| 1428 | case ISD::ATOMIC_LOAD_NAND: |
| 1429 | case ISD::ATOMIC_LOAD_MIN: |
| 1430 | case ISD::ATOMIC_LOAD_MAX: |
| 1431 | case ISD::ATOMIC_LOAD_UMIN: |
| 1432 | case ISD::ATOMIC_LOAD_UMAX: |
| 1433 | case ISD::ATOMIC_SWAP: { |
Mon P Wang | 63307c3 | 2008-05-05 19:05:59 +0000 | [diff] [blame] | 1434 | unsigned int num_operands = 3; |
| 1435 | assert(Node->getNumOperands() == num_operands && "Invalid Atomic node!"); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1436 | SDValue Ops[3]; |
Mon P Wang | 63307c3 | 2008-05-05 19:05:59 +0000 | [diff] [blame] | 1437 | for (unsigned int x = 0; x < num_operands; ++x) |
| 1438 | Ops[x] = LegalizeOp(Node->getOperand(x)); |
| 1439 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], num_operands); |
Duncan Sands | 126d907 | 2008-07-04 11:47:58 +0000 | [diff] [blame] | 1440 | |
Andrew Lenharth | 26ed869 | 2008-03-01 21:52:34 +0000 | [diff] [blame] | 1441 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 1442 | default: assert(0 && "This action is not supported yet!"); |
Andrew Lenharth | 26ed869 | 2008-03-01 21:52:34 +0000 | [diff] [blame] | 1443 | case TargetLowering::Custom: |
| 1444 | Result = TLI.LowerOperation(Result, DAG); |
| 1445 | break; |
| 1446 | case TargetLowering::Legal: |
Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 1447 | break; |
| 1448 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1449 | AddLegalizedOperand(SDValue(Node, 0), Result.getValue(0)); |
| 1450 | AddLegalizedOperand(SDValue(Node, 1), Result.getValue(1)); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 1451 | return Result.getValue(Op.getResNo()); |
Duncan Sands | 126d907 | 2008-07-04 11:47:58 +0000 | [diff] [blame] | 1452 | } |
Scott Michel | c1513d2 | 2007-08-08 23:23:31 +0000 | [diff] [blame] | 1453 | case ISD::Constant: { |
| 1454 | ConstantSDNode *CN = cast<ConstantSDNode>(Node); |
| 1455 | unsigned opAction = |
| 1456 | TLI.getOperationAction(ISD::Constant, CN->getValueType(0)); |
| 1457 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1458 | // We know we don't need to expand constants here, constants only have one |
| 1459 | // value and we check that it is fine above. |
| 1460 | |
Scott Michel | c1513d2 | 2007-08-08 23:23:31 +0000 | [diff] [blame] | 1461 | if (opAction == TargetLowering::Custom) { |
| 1462 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1463 | if (Tmp1.getNode()) |
Scott Michel | c1513d2 | 2007-08-08 23:23:31 +0000 | [diff] [blame] | 1464 | Result = Tmp1; |
| 1465 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1466 | break; |
Scott Michel | c1513d2 | 2007-08-08 23:23:31 +0000 | [diff] [blame] | 1467 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1468 | case ISD::ConstantFP: { |
| 1469 | // Spill FP immediates to the constant pool if the target cannot directly |
| 1470 | // codegen them. Targets often have some immediate values that can be |
| 1471 | // efficiently generated into an FP register without a load. We explicitly |
| 1472 | // leave these constants as ConstantFP nodes for the target to deal with. |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1473 | ConstantFPSDNode *CFP = cast<ConstantFPSDNode>(Node); |
| 1474 | |
Chris Lattner | 3181a77 | 2006-01-29 06:26:56 +0000 | [diff] [blame] | 1475 | switch (TLI.getOperationAction(ISD::ConstantFP, CFP->getValueType(0))) { |
| 1476 | default: assert(0 && "This action is not supported yet!"); |
Nate Begeman | e179584 | 2008-02-14 08:57:00 +0000 | [diff] [blame] | 1477 | case TargetLowering::Legal: |
| 1478 | break; |
Chris Lattner | 3181a77 | 2006-01-29 06:26:56 +0000 | [diff] [blame] | 1479 | case TargetLowering::Custom: |
| 1480 | Tmp3 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1481 | if (Tmp3.getNode()) { |
Chris Lattner | 3181a77 | 2006-01-29 06:26:56 +0000 | [diff] [blame] | 1482 | Result = Tmp3; |
| 1483 | break; |
| 1484 | } |
| 1485 | // FALLTHROUGH |
Nate Begeman | e179584 | 2008-02-14 08:57:00 +0000 | [diff] [blame] | 1486 | case TargetLowering::Expand: { |
| 1487 | // Check to see if this FP immediate is already legal. |
| 1488 | bool isLegal = false; |
| 1489 | for (TargetLowering::legal_fpimm_iterator I = TLI.legal_fpimm_begin(), |
| 1490 | E = TLI.legal_fpimm_end(); I != E; ++I) { |
| 1491 | if (CFP->isExactlyValue(*I)) { |
| 1492 | isLegal = true; |
| 1493 | break; |
| 1494 | } |
| 1495 | } |
| 1496 | // If this is a legal constant, turn it into a TargetConstantFP node. |
| 1497 | if (isLegal) |
| 1498 | break; |
Evan Cheng | 279101e | 2006-12-12 22:19:28 +0000 | [diff] [blame] | 1499 | Result = ExpandConstantFP(CFP, true, DAG, TLI); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1500 | } |
Nate Begeman | e179584 | 2008-02-14 08:57:00 +0000 | [diff] [blame] | 1501 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1502 | break; |
| 1503 | } |
Chris Lattner | 040c11c | 2005-11-09 18:48:57 +0000 | [diff] [blame] | 1504 | case ISD::TokenFactor: |
| 1505 | if (Node->getNumOperands() == 2) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1506 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1507 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1508 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 1509 | } else if (Node->getNumOperands() == 3) { |
| 1510 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1511 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1512 | Tmp3 = LegalizeOp(Node->getOperand(2)); |
| 1513 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | 040c11c | 2005-11-09 18:48:57 +0000 | [diff] [blame] | 1514 | } else { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1515 | SmallVector<SDValue, 8> Ops; |
Chris Lattner | 040c11c | 2005-11-09 18:48:57 +0000 | [diff] [blame] | 1516 | // Legalize the operands. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1517 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) |
| 1518 | Ops.push_back(LegalizeOp(Node->getOperand(i))); |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1519 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | a385e9b | 2005-01-13 17:59:25 +0000 | [diff] [blame] | 1520 | } |
Chris Lattner | a385e9b | 2005-01-13 17:59:25 +0000 | [diff] [blame] | 1521 | break; |
Chris Lattner | fdfded5 | 2006-04-12 16:20:43 +0000 | [diff] [blame] | 1522 | |
| 1523 | case ISD::FORMAL_ARGUMENTS: |
Chris Lattner | f4ec817 | 2006-05-16 22:53:20 +0000 | [diff] [blame] | 1524 | case ISD::CALL: |
Chris Lattner | fdfded5 | 2006-04-12 16:20:43 +0000 | [diff] [blame] | 1525 | // The only option for this is to custom lower it. |
Chris Lattner | b248e16 | 2006-05-17 17:55:45 +0000 | [diff] [blame] | 1526 | Tmp3 = TLI.LowerOperation(Result.getValue(0), DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1527 | assert(Tmp3.getNode() && "Target didn't custom lower this node!"); |
Dale Johannesen | 0ea0356 | 2008-03-05 19:14:03 +0000 | [diff] [blame] | 1528 | // A call within a calling sequence must be legalized to something |
| 1529 | // other than the normal CALLSEQ_END. Violating this gets Legalize |
| 1530 | // into an infinite loop. |
| 1531 | assert ((!IsLegalizingCall || |
| 1532 | Node->getOpcode() != ISD::CALL || |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1533 | Tmp3.getNode()->getOpcode() != ISD::CALLSEQ_END) && |
Dale Johannesen | 0ea0356 | 2008-03-05 19:14:03 +0000 | [diff] [blame] | 1534 | "Nested CALLSEQ_START..CALLSEQ_END not supported."); |
Bill Wendling | 0f8d9c0 | 2007-11-13 00:44:25 +0000 | [diff] [blame] | 1535 | |
| 1536 | // The number of incoming and outgoing values should match; unless the final |
| 1537 | // outgoing value is a flag. |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1538 | assert((Tmp3.getNode()->getNumValues() == Result.getNode()->getNumValues() || |
| 1539 | (Tmp3.getNode()->getNumValues() == Result.getNode()->getNumValues() + 1 && |
| 1540 | Tmp3.getNode()->getValueType(Tmp3.getNode()->getNumValues() - 1) == |
Bill Wendling | 0f8d9c0 | 2007-11-13 00:44:25 +0000 | [diff] [blame] | 1541 | MVT::Flag)) && |
Chris Lattner | b248e16 | 2006-05-17 17:55:45 +0000 | [diff] [blame] | 1542 | "Lowering call/formal_arguments produced unexpected # results!"); |
Chris Lattner | e2e4173 | 2006-05-16 05:49:56 +0000 | [diff] [blame] | 1543 | |
Chris Lattner | f4ec817 | 2006-05-16 22:53:20 +0000 | [diff] [blame] | 1544 | // Since CALL/FORMAL_ARGUMENTS nodes produce multiple values, make sure to |
Chris Lattner | e2e4173 | 2006-05-16 05:49:56 +0000 | [diff] [blame] | 1545 | // 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] | 1546 | for (unsigned i = 0, e = Tmp3.getNode()->getNumValues(); i != e; ++i) { |
| 1547 | if (Tmp3.getNode()->getValueType(i) == MVT::Flag) |
Bill Wendling | 0f8d9c0 | 2007-11-13 00:44:25 +0000 | [diff] [blame] | 1548 | continue; |
Chris Lattner | b248e16 | 2006-05-17 17:55:45 +0000 | [diff] [blame] | 1549 | Tmp1 = LegalizeOp(Tmp3.getValue(i)); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 1550 | if (Op.getResNo() == i) |
Chris Lattner | e2e4173 | 2006-05-16 05:49:56 +0000 | [diff] [blame] | 1551 | Tmp2 = Tmp1; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1552 | AddLegalizedOperand(SDValue(Node, i), Tmp1); |
Chris Lattner | e2e4173 | 2006-05-16 05:49:56 +0000 | [diff] [blame] | 1553 | } |
| 1554 | return Tmp2; |
Christopher Lamb | 557c363 | 2007-07-26 07:34:40 +0000 | [diff] [blame] | 1555 | case ISD::EXTRACT_SUBREG: { |
| 1556 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1557 | ConstantSDNode *idx = dyn_cast<ConstantSDNode>(Node->getOperand(1)); |
| 1558 | assert(idx && "Operand must be a constant"); |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1559 | Tmp2 = DAG.getTargetConstant(idx->getAPIntValue(), idx->getValueType(0)); |
Christopher Lamb | 557c363 | 2007-07-26 07:34:40 +0000 | [diff] [blame] | 1560 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 1561 | } |
| 1562 | break; |
| 1563 | case ISD::INSERT_SUBREG: { |
| 1564 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1565 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1566 | ConstantSDNode *idx = dyn_cast<ConstantSDNode>(Node->getOperand(2)); |
| 1567 | assert(idx && "Operand must be a constant"); |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1568 | Tmp3 = 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, Tmp3); |
| 1570 | } |
| 1571 | break; |
Chris Lattner | b2827b0 | 2006-03-19 00:52:58 +0000 | [diff] [blame] | 1572 | case ISD::BUILD_VECTOR: |
| 1573 | switch (TLI.getOperationAction(ISD::BUILD_VECTOR, Node->getValueType(0))) { |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1574 | default: assert(0 && "This action is not supported yet!"); |
| 1575 | case TargetLowering::Custom: |
| 1576 | Tmp3 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1577 | if (Tmp3.getNode()) { |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1578 | Result = Tmp3; |
| 1579 | break; |
| 1580 | } |
| 1581 | // FALLTHROUGH |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 1582 | case TargetLowering::Expand: |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1583 | Result = ExpandBUILD_VECTOR(Result.getNode()); |
Chris Lattner | b2827b0 | 2006-03-19 00:52:58 +0000 | [diff] [blame] | 1584 | break; |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1585 | } |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1586 | break; |
| 1587 | case ISD::INSERT_VECTOR_ELT: |
| 1588 | Tmp1 = LegalizeOp(Node->getOperand(0)); // InVec |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1589 | Tmp3 = LegalizeOp(Node->getOperand(2)); // InEltNo |
Nate Begeman | 0325d90 | 2008-02-13 06:43:04 +0000 | [diff] [blame] | 1590 | |
| 1591 | // The type of the value to insert may not be legal, even though the vector |
| 1592 | // type is legal. Legalize/Promote accordingly. We do not handle Expand |
| 1593 | // here. |
| 1594 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 1595 | default: assert(0 && "Cannot expand insert element operand"); |
| 1596 | case Legal: Tmp2 = LegalizeOp(Node->getOperand(1)); break; |
| 1597 | case Promote: Tmp2 = PromoteOp(Node->getOperand(1)); break; |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 1598 | case Expand: |
| 1599 | // FIXME: An alternative would be to check to see if the target is not |
| 1600 | // going to custom lower this operation, we could bitcast to half elt |
| 1601 | // width and perform two inserts at that width, if that is legal. |
| 1602 | Tmp2 = Node->getOperand(1); |
| 1603 | break; |
Nate Begeman | 0325d90 | 2008-02-13 06:43:04 +0000 | [diff] [blame] | 1604 | } |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1605 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
| 1606 | |
| 1607 | switch (TLI.getOperationAction(ISD::INSERT_VECTOR_ELT, |
| 1608 | Node->getValueType(0))) { |
| 1609 | default: assert(0 && "This action is not supported yet!"); |
| 1610 | case TargetLowering::Legal: |
| 1611 | break; |
| 1612 | case TargetLowering::Custom: |
Nate Begeman | 2281a99 | 2008-01-05 20:47:37 +0000 | [diff] [blame] | 1613 | Tmp4 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1614 | if (Tmp4.getNode()) { |
Nate Begeman | 2281a99 | 2008-01-05 20:47:37 +0000 | [diff] [blame] | 1615 | Result = Tmp4; |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1616 | break; |
| 1617 | } |
| 1618 | // FALLTHROUGH |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 1619 | case TargetLowering::Promote: |
| 1620 | // Fall thru for vector case |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1621 | case TargetLowering::Expand: { |
Chris Lattner | 8d5a894 | 2006-04-17 19:21:01 +0000 | [diff] [blame] | 1622 | // If the insert index is a constant, codegen this as a scalar_to_vector, |
| 1623 | // then a shuffle that inserts it into the right position in the vector. |
| 1624 | if (ConstantSDNode *InsertPos = dyn_cast<ConstantSDNode>(Tmp3)) { |
Nate Begeman | 0325d90 | 2008-02-13 06:43:04 +0000 | [diff] [blame] | 1625 | // SCALAR_TO_VECTOR requires that the type of the value being inserted |
| 1626 | // match the element type of the vector being created. |
| 1627 | if (Tmp2.getValueType() == |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1628 | Op.getValueType().getVectorElementType()) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1629 | SDValue ScVec = DAG.getNode(ISD::SCALAR_TO_VECTOR, |
Nate Begeman | 0325d90 | 2008-02-13 06:43:04 +0000 | [diff] [blame] | 1630 | Tmp1.getValueType(), Tmp2); |
| 1631 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1632 | unsigned NumElts = Tmp1.getValueType().getVectorNumElements(); |
| 1633 | MVT ShufMaskVT = |
| 1634 | MVT::getIntVectorWithNumElements(NumElts); |
| 1635 | MVT ShufMaskEltVT = ShufMaskVT.getVectorElementType(); |
Nate Begeman | 0325d90 | 2008-02-13 06:43:04 +0000 | [diff] [blame] | 1636 | |
| 1637 | // We generate a shuffle of InVec and ScVec, so the shuffle mask |
| 1638 | // should be 0,1,2,3,4,5... with the appropriate element replaced with |
| 1639 | // elt 0 of the RHS. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1640 | SmallVector<SDValue, 8> ShufOps; |
Nate Begeman | 0325d90 | 2008-02-13 06:43:04 +0000 | [diff] [blame] | 1641 | for (unsigned i = 0; i != NumElts; ++i) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1642 | if (i != InsertPos->getZExtValue()) |
Nate Begeman | 0325d90 | 2008-02-13 06:43:04 +0000 | [diff] [blame] | 1643 | ShufOps.push_back(DAG.getConstant(i, ShufMaskEltVT)); |
| 1644 | else |
| 1645 | ShufOps.push_back(DAG.getConstant(NumElts, ShufMaskEltVT)); |
| 1646 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1647 | SDValue ShufMask = DAG.getNode(ISD::BUILD_VECTOR, ShufMaskVT, |
Nate Begeman | 0325d90 | 2008-02-13 06:43:04 +0000 | [diff] [blame] | 1648 | &ShufOps[0], ShufOps.size()); |
| 1649 | |
| 1650 | Result = DAG.getNode(ISD::VECTOR_SHUFFLE, Tmp1.getValueType(), |
| 1651 | Tmp1, ScVec, ShufMask); |
| 1652 | Result = LegalizeOp(Result); |
| 1653 | break; |
Chris Lattner | 8d5a894 | 2006-04-17 19:21:01 +0000 | [diff] [blame] | 1654 | } |
Chris Lattner | 8d5a894 | 2006-04-17 19:21:01 +0000 | [diff] [blame] | 1655 | } |
Nate Begeman | 6867991 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 1656 | Result = PerformInsertVectorEltInMemory(Tmp1, Tmp2, Tmp3); |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1657 | break; |
| 1658 | } |
| 1659 | } |
| 1660 | break; |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 1661 | case ISD::SCALAR_TO_VECTOR: |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 1662 | if (!TLI.isTypeLegal(Node->getOperand(0).getValueType())) { |
| 1663 | Result = LegalizeOp(ExpandSCALAR_TO_VECTOR(Node)); |
| 1664 | break; |
| 1665 | } |
| 1666 | |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 1667 | Tmp1 = LegalizeOp(Node->getOperand(0)); // InVal |
| 1668 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 1669 | switch (TLI.getOperationAction(ISD::SCALAR_TO_VECTOR, |
| 1670 | Node->getValueType(0))) { |
| 1671 | default: assert(0 && "This action is not supported yet!"); |
| 1672 | case TargetLowering::Legal: |
| 1673 | break; |
Chris Lattner | 4d3abee | 2006-03-19 06:47:21 +0000 | [diff] [blame] | 1674 | case TargetLowering::Custom: |
| 1675 | Tmp3 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1676 | if (Tmp3.getNode()) { |
Chris Lattner | 4d3abee | 2006-03-19 06:47:21 +0000 | [diff] [blame] | 1677 | Result = Tmp3; |
| 1678 | break; |
| 1679 | } |
| 1680 | // FALLTHROUGH |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 1681 | case TargetLowering::Expand: |
| 1682 | Result = LegalizeOp(ExpandSCALAR_TO_VECTOR(Node)); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 1683 | break; |
| 1684 | } |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 1685 | break; |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 1686 | case ISD::VECTOR_SHUFFLE: |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 1687 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the input vectors, |
| 1688 | Tmp2 = LegalizeOp(Node->getOperand(1)); // but not the shuffle mask. |
| 1689 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
| 1690 | |
| 1691 | // Allow targets to custom lower the SHUFFLEs they support. |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 1692 | switch (TLI.getOperationAction(ISD::VECTOR_SHUFFLE,Result.getValueType())) { |
| 1693 | default: assert(0 && "Unknown operation action!"); |
| 1694 | case TargetLowering::Legal: |
| 1695 | assert(isShuffleLegal(Result.getValueType(), Node->getOperand(2)) && |
| 1696 | "vector shuffle should not be created if not legal!"); |
| 1697 | break; |
| 1698 | case TargetLowering::Custom: |
Evan Cheng | 18dd6d0 | 2006-04-05 06:07:11 +0000 | [diff] [blame] | 1699 | Tmp3 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1700 | if (Tmp3.getNode()) { |
Evan Cheng | 18dd6d0 | 2006-04-05 06:07:11 +0000 | [diff] [blame] | 1701 | Result = Tmp3; |
| 1702 | break; |
| 1703 | } |
| 1704 | // FALLTHROUGH |
| 1705 | case TargetLowering::Expand: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1706 | MVT VT = Node->getValueType(0); |
| 1707 | MVT EltVT = VT.getVectorElementType(); |
| 1708 | MVT PtrVT = TLI.getPointerTy(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1709 | SDValue Mask = Node->getOperand(2); |
Evan Cheng | 18dd6d0 | 2006-04-05 06:07:11 +0000 | [diff] [blame] | 1710 | unsigned NumElems = Mask.getNumOperands(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1711 | SmallVector<SDValue,8> Ops; |
Evan Cheng | 18dd6d0 | 2006-04-05 06:07:11 +0000 | [diff] [blame] | 1712 | for (unsigned i = 0; i != NumElems; ++i) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1713 | SDValue Arg = Mask.getOperand(i); |
Evan Cheng | 18dd6d0 | 2006-04-05 06:07:11 +0000 | [diff] [blame] | 1714 | if (Arg.getOpcode() == ISD::UNDEF) { |
| 1715 | Ops.push_back(DAG.getNode(ISD::UNDEF, EltVT)); |
| 1716 | } else { |
| 1717 | assert(isa<ConstantSDNode>(Arg) && "Invalid VECTOR_SHUFFLE mask!"); |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1718 | unsigned Idx = cast<ConstantSDNode>(Arg)->getZExtValue(); |
Evan Cheng | 18dd6d0 | 2006-04-05 06:07:11 +0000 | [diff] [blame] | 1719 | if (Idx < NumElems) |
| 1720 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, EltVT, Tmp1, |
| 1721 | DAG.getConstant(Idx, PtrVT))); |
| 1722 | else |
| 1723 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, EltVT, Tmp2, |
| 1724 | DAG.getConstant(Idx - NumElems, PtrVT))); |
| 1725 | } |
| 1726 | } |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 1727 | Result = DAG.getNode(ISD::BUILD_VECTOR, VT, &Ops[0], Ops.size()); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 1728 | break; |
Evan Cheng | 18dd6d0 | 2006-04-05 06:07:11 +0000 | [diff] [blame] | 1729 | } |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 1730 | case TargetLowering::Promote: { |
| 1731 | // Change base type to a different vector type. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1732 | MVT OVT = Node->getValueType(0); |
| 1733 | MVT NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 1734 | |
| 1735 | // Cast the two input vectors. |
| 1736 | Tmp1 = DAG.getNode(ISD::BIT_CONVERT, NVT, Tmp1); |
| 1737 | Tmp2 = DAG.getNode(ISD::BIT_CONVERT, NVT, Tmp2); |
| 1738 | |
| 1739 | // Convert the shuffle mask to the right # elements. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1740 | Tmp3 = SDValue(isShuffleLegal(OVT, Node->getOperand(2)), 0); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1741 | assert(Tmp3.getNode() && "Shuffle not legal?"); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 1742 | Result = DAG.getNode(ISD::VECTOR_SHUFFLE, NVT, Tmp1, Tmp2, Tmp3); |
| 1743 | Result = DAG.getNode(ISD::BIT_CONVERT, OVT, Result); |
| 1744 | break; |
| 1745 | } |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 1746 | } |
| 1747 | break; |
Chris Lattner | 384504c | 2006-03-21 20:44:12 +0000 | [diff] [blame] | 1748 | |
| 1749 | case ISD::EXTRACT_VECTOR_ELT: |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 1750 | Tmp1 = Node->getOperand(0); |
Chris Lattner | 384504c | 2006-03-21 20:44:12 +0000 | [diff] [blame] | 1751 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1752 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 1753 | Result = ExpandEXTRACT_VECTOR_ELT(Result); |
Chris Lattner | 384504c | 2006-03-21 20:44:12 +0000 | [diff] [blame] | 1754 | break; |
| 1755 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 1756 | case ISD::EXTRACT_SUBVECTOR: |
| 1757 | Tmp1 = Node->getOperand(0); |
| 1758 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1759 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 1760 | Result = ExpandEXTRACT_SUBVECTOR(Result); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 1761 | break; |
| 1762 | |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 1763 | case ISD::CONCAT_VECTORS: { |
| 1764 | // Use extract/insert/build vector for now. We might try to be |
| 1765 | // more clever later. |
| 1766 | MVT PtrVT = TLI.getPointerTy(); |
| 1767 | SmallVector<SDValue, 8> Ops; |
| 1768 | unsigned NumOperands = Node->getNumOperands(); |
| 1769 | for (unsigned i=0; i < NumOperands; ++i) { |
| 1770 | SDValue SubOp = Node->getOperand(i); |
| 1771 | MVT VVT = SubOp.getNode()->getValueType(0); |
| 1772 | MVT EltVT = VVT.getVectorElementType(); |
| 1773 | unsigned NumSubElem = VVT.getVectorNumElements(); |
| 1774 | for (unsigned j=0; j < NumSubElem; ++j) { |
| 1775 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, EltVT, SubOp, |
| 1776 | DAG.getConstant(j, PtrVT))); |
| 1777 | } |
| 1778 | } |
| 1779 | return LegalizeOp(DAG.getNode(ISD::BUILD_VECTOR, Node->getValueType(0), |
| 1780 | &Ops[0], Ops.size())); |
| 1781 | } |
| 1782 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1783 | case ISD::CALLSEQ_START: { |
| 1784 | SDNode *CallEnd = FindCallEndFromCallStart(Node); |
| 1785 | |
| 1786 | // Recursively Legalize all of the inputs of the call end that do not lead |
| 1787 | // to this call start. This ensures that any libcalls that need be inserted |
| 1788 | // are inserted *before* the CALLSEQ_START. |
Chris Lattner | 00755df | 2007-02-04 00:27:56 +0000 | [diff] [blame] | 1789 | {SmallPtrSet<SDNode*, 32> NodesLeadingTo; |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1790 | for (unsigned i = 0, e = CallEnd->getNumOperands(); i != e; ++i) |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1791 | LegalizeAllNodesNotLeadingTo(CallEnd->getOperand(i).getNode(), Node, |
Chris Lattner | c9cf4f1 | 2006-07-26 23:55:56 +0000 | [diff] [blame] | 1792 | NodesLeadingTo); |
| 1793 | } |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1794 | |
| 1795 | // Now that we legalized all of the inputs (which may have inserted |
| 1796 | // libcalls) create the new CALLSEQ_START node. |
| 1797 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1798 | |
| 1799 | // Merge in the last call, to ensure that this call start after the last |
| 1800 | // call ended. |
Chris Lattner | c5d7d7c | 2006-05-17 18:00:08 +0000 | [diff] [blame] | 1801 | if (LastCALLSEQ_END.getOpcode() != ISD::EntryToken) { |
Chris Lattner | b248e16 | 2006-05-17 17:55:45 +0000 | [diff] [blame] | 1802 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1803 | Tmp1 = LegalizeOp(Tmp1); |
| 1804 | } |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1805 | |
| 1806 | // Do not try to legalize the target-specific arguments (#1+). |
| 1807 | if (Tmp1 != Node->getOperand(0)) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1808 | SmallVector<SDValue, 8> Ops(Node->op_begin(), Node->op_end()); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1809 | Ops[0] = Tmp1; |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1810 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1811 | } |
| 1812 | |
| 1813 | // Remember that the CALLSEQ_START is legalized. |
Chris Lattner | 4b653a0 | 2006-02-14 00:55:02 +0000 | [diff] [blame] | 1814 | AddLegalizedOperand(Op.getValue(0), Result); |
| 1815 | if (Node->getNumValues() == 2) // If this has a flag result, remember it. |
| 1816 | AddLegalizedOperand(Op.getValue(1), Result.getValue(1)); |
| 1817 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1818 | // Now that the callseq_start and all of the non-call nodes above this call |
| 1819 | // sequence have been legalized, legalize the call itself. During this |
| 1820 | // process, no libcalls can/will be inserted, guaranteeing that no calls |
| 1821 | // can overlap. |
| 1822 | assert(!IsLegalizingCall && "Inconsistent sequentialization of calls!"); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1823 | // Note that we are selecting this call! |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1824 | LastCALLSEQ_END = SDValue(CallEnd, 0); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1825 | IsLegalizingCall = true; |
| 1826 | |
| 1827 | // Legalize the call, starting from the CALLSEQ_END. |
| 1828 | LegalizeOp(LastCALLSEQ_END); |
| 1829 | assert(!IsLegalizingCall && "CALLSEQ_END should have cleared this!"); |
| 1830 | return Result; |
| 1831 | } |
Chris Lattner | 16cd04d | 2005-05-12 23:24:06 +0000 | [diff] [blame] | 1832 | case ISD::CALLSEQ_END: |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1833 | // If the CALLSEQ_START node hasn't been legalized first, legalize it. This |
| 1834 | // 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] | 1835 | if (LastCALLSEQ_END.getNode() != Node) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1836 | LegalizeOp(SDValue(FindCallStartFromCallEnd(Node), 0)); |
| 1837 | DenseMap<SDValue, SDValue>::iterator I = LegalizedNodes.find(Op); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1838 | assert(I != LegalizedNodes.end() && |
| 1839 | "Legalizing the call start should have legalized this node!"); |
| 1840 | return I->second; |
| 1841 | } |
| 1842 | |
| 1843 | // Otherwise, the call start has been legalized and everything is going |
| 1844 | // according to plan. Just legalize ourselves normally here. |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1845 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | 70814bc | 2006-01-29 07:58:15 +0000 | [diff] [blame] | 1846 | // Do not try to legalize the target-specific arguments (#1+), except for |
| 1847 | // an optional flag input. |
| 1848 | if (Node->getOperand(Node->getNumOperands()-1).getValueType() != MVT::Flag){ |
| 1849 | if (Tmp1 != Node->getOperand(0)) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1850 | SmallVector<SDValue, 8> Ops(Node->op_begin(), Node->op_end()); |
Chris Lattner | 70814bc | 2006-01-29 07:58:15 +0000 | [diff] [blame] | 1851 | Ops[0] = Tmp1; |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1852 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 70814bc | 2006-01-29 07:58:15 +0000 | [diff] [blame] | 1853 | } |
| 1854 | } else { |
| 1855 | Tmp2 = LegalizeOp(Node->getOperand(Node->getNumOperands()-1)); |
| 1856 | if (Tmp1 != Node->getOperand(0) || |
| 1857 | Tmp2 != Node->getOperand(Node->getNumOperands()-1)) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1858 | SmallVector<SDValue, 8> Ops(Node->op_begin(), Node->op_end()); |
Chris Lattner | 70814bc | 2006-01-29 07:58:15 +0000 | [diff] [blame] | 1859 | Ops[0] = Tmp1; |
| 1860 | Ops.back() = Tmp2; |
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 | } |
Chris Lattner | 6a54289 | 2006-01-24 05:48:21 +0000 | [diff] [blame] | 1863 | } |
Chris Lattner | 4b653a0 | 2006-02-14 00:55:02 +0000 | [diff] [blame] | 1864 | assert(IsLegalizingCall && "Call sequence imbalance between start/end?"); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1865 | // This finishes up call legalization. |
| 1866 | IsLegalizingCall = false; |
Chris Lattner | 4b653a0 | 2006-02-14 00:55:02 +0000 | [diff] [blame] | 1867 | |
| 1868 | // 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] | 1869 | AddLegalizedOperand(SDValue(Node, 0), Result.getValue(0)); |
Chris Lattner | 4b653a0 | 2006-02-14 00:55:02 +0000 | [diff] [blame] | 1870 | if (Node->getNumValues() == 2) |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1871 | AddLegalizedOperand(SDValue(Node, 1), Result.getValue(1)); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 1872 | return Result.getValue(Op.getResNo()); |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1873 | case ISD::DYNAMIC_STACKALLOC: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1874 | MVT VT = Node->getValueType(0); |
Chris Lattner | fa404e8 | 2005-01-09 19:03:49 +0000 | [diff] [blame] | 1875 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1876 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the size. |
| 1877 | Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the alignment. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1878 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | fa404e8 | 2005-01-09 19:03:49 +0000 | [diff] [blame] | 1879 | |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1880 | Tmp1 = Result.getValue(0); |
Chris Lattner | 5f65229 | 2006-01-15 08:43:08 +0000 | [diff] [blame] | 1881 | Tmp2 = Result.getValue(1); |
Evan Cheng | 61bbbab | 2007-08-16 23:50:06 +0000 | [diff] [blame] | 1882 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1883 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1884 | case TargetLowering::Expand: { |
| 1885 | unsigned SPReg = TLI.getStackPointerRegisterToSaveRestore(); |
| 1886 | assert(SPReg && "Target cannot require DYNAMIC_STACKALLOC expansion and" |
| 1887 | " not tell us which reg is the stack pointer!"); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1888 | SDValue Chain = Tmp1.getOperand(0); |
Bill Wendling | 0f8d9c0 | 2007-11-13 00:44:25 +0000 | [diff] [blame] | 1889 | |
| 1890 | // Chain the dynamic stack allocation so that it doesn't modify the stack |
| 1891 | // pointer when other instructions are using the stack. |
Chris Lattner | e563bbc | 2008-10-11 22:08:30 +0000 | [diff] [blame] | 1892 | Chain = DAG.getCALLSEQ_START(Chain, DAG.getIntPtrConstant(0, true)); |
Bill Wendling | 0f8d9c0 | 2007-11-13 00:44:25 +0000 | [diff] [blame] | 1893 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1894 | SDValue Size = Tmp2.getOperand(1); |
| 1895 | SDValue SP = DAG.getCopyFromReg(Chain, SPReg, VT); |
Evan Cheng | 61bbbab | 2007-08-16 23:50:06 +0000 | [diff] [blame] | 1896 | Chain = SP.getValue(1); |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1897 | unsigned Align = cast<ConstantSDNode>(Tmp3)->getZExtValue(); |
Evan Cheng | 61bbbab | 2007-08-16 23:50:06 +0000 | [diff] [blame] | 1898 | unsigned StackAlign = |
| 1899 | TLI.getTargetMachine().getFrameInfo()->getStackAlignment(); |
| 1900 | if (Align > StackAlign) |
Evan Cheng | 3e20bba | 2007-08-17 18:02:22 +0000 | [diff] [blame] | 1901 | SP = DAG.getNode(ISD::AND, VT, SP, |
| 1902 | DAG.getConstant(-(uint64_t)Align, VT)); |
Evan Cheng | 61bbbab | 2007-08-16 23:50:06 +0000 | [diff] [blame] | 1903 | Tmp1 = DAG.getNode(ISD::SUB, VT, SP, Size); // Value |
Bill Wendling | 0f8d9c0 | 2007-11-13 00:44:25 +0000 | [diff] [blame] | 1904 | Chain = DAG.getCopyToReg(Chain, SPReg, Tmp1); // Output chain |
| 1905 | |
Chris Lattner | e563bbc | 2008-10-11 22:08:30 +0000 | [diff] [blame] | 1906 | Tmp2 = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(0, true), |
| 1907 | DAG.getIntPtrConstant(0, true), SDValue()); |
Bill Wendling | 0f8d9c0 | 2007-11-13 00:44:25 +0000 | [diff] [blame] | 1908 | |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1909 | Tmp1 = LegalizeOp(Tmp1); |
| 1910 | Tmp2 = LegalizeOp(Tmp2); |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1911 | break; |
| 1912 | } |
| 1913 | case TargetLowering::Custom: |
Chris Lattner | 5f65229 | 2006-01-15 08:43:08 +0000 | [diff] [blame] | 1914 | Tmp3 = TLI.LowerOperation(Tmp1, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1915 | if (Tmp3.getNode()) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1916 | Tmp1 = LegalizeOp(Tmp3); |
| 1917 | Tmp2 = LegalizeOp(Tmp3.getValue(1)); |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1918 | } |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1919 | break; |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1920 | case TargetLowering::Legal: |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1921 | break; |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1922 | } |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1923 | // Since this op produce two values, make sure to remember that we |
| 1924 | // legalized both of them. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1925 | AddLegalizedOperand(SDValue(Node, 0), Tmp1); |
| 1926 | AddLegalizedOperand(SDValue(Node, 1), Tmp2); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 1927 | return Op.getResNo() ? Tmp2 : Tmp1; |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1928 | } |
Chris Lattner | 25a022c | 2006-07-11 01:40:09 +0000 | [diff] [blame] | 1929 | case ISD::INLINEASM: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1930 | SmallVector<SDValue, 8> Ops(Node->op_begin(), Node->op_end()); |
Chris Lattner | 25a022c | 2006-07-11 01:40:09 +0000 | [diff] [blame] | 1931 | bool Changed = false; |
| 1932 | // Legalize all of the operands of the inline asm, in case they are nodes |
| 1933 | // that need to be expanded or something. Note we skip the asm string and |
| 1934 | // all of the TargetConstant flags. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1935 | SDValue Op = LegalizeOp(Ops[0]); |
Chris Lattner | 25a022c | 2006-07-11 01:40:09 +0000 | [diff] [blame] | 1936 | Changed = Op != Ops[0]; |
| 1937 | Ops[0] = Op; |
| 1938 | |
| 1939 | bool HasInFlag = Ops.back().getValueType() == MVT::Flag; |
| 1940 | for (unsigned i = 2, e = Ops.size()-HasInFlag; i < e; ) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1941 | unsigned NumVals = cast<ConstantSDNode>(Ops[i])->getZExtValue() >> 3; |
Chris Lattner | 25a022c | 2006-07-11 01:40:09 +0000 | [diff] [blame] | 1942 | for (++i; NumVals; ++i, --NumVals) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1943 | SDValue Op = LegalizeOp(Ops[i]); |
Chris Lattner | 25a022c | 2006-07-11 01:40:09 +0000 | [diff] [blame] | 1944 | if (Op != Ops[i]) { |
| 1945 | Changed = true; |
| 1946 | Ops[i] = Op; |
| 1947 | } |
| 1948 | } |
Chris Lattner | ce7518c | 2006-01-26 22:24:51 +0000 | [diff] [blame] | 1949 | } |
Chris Lattner | 25a022c | 2006-07-11 01:40:09 +0000 | [diff] [blame] | 1950 | |
| 1951 | if (HasInFlag) { |
| 1952 | Op = LegalizeOp(Ops.back()); |
| 1953 | Changed |= Op != Ops.back(); |
| 1954 | Ops.back() = Op; |
| 1955 | } |
| 1956 | |
| 1957 | if (Changed) |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1958 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | ce7518c | 2006-01-26 22:24:51 +0000 | [diff] [blame] | 1959 | |
| 1960 | // 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] | 1961 | AddLegalizedOperand(SDValue(Node, 0), Result.getValue(0)); |
| 1962 | AddLegalizedOperand(SDValue(Node, 1), Result.getValue(1)); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 1963 | return Result.getValue(Op.getResNo()); |
Chris Lattner | 25a022c | 2006-07-11 01:40:09 +0000 | [diff] [blame] | 1964 | } |
Chris Lattner | c7af179 | 2005-01-07 22:12:08 +0000 | [diff] [blame] | 1965 | case ISD::BR: |
| 1966 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1967 | // Ensure that libcalls are emitted before a branch. |
| 1968 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1969 | Tmp1 = LegalizeOp(Tmp1); |
| 1970 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 1971 | |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1972 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
Chris Lattner | c7af179 | 2005-01-07 22:12:08 +0000 | [diff] [blame] | 1973 | break; |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 1974 | case ISD::BRIND: |
| 1975 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 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 | |
| 1981 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 1982 | default: assert(0 && "Indirect target must be legal type (pointer)!"); |
| 1983 | case Legal: |
| 1984 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the condition. |
| 1985 | break; |
| 1986 | } |
| 1987 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 1988 | break; |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 1989 | case ISD::BR_JT: |
| 1990 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1991 | // Ensure that libcalls are emitted before a branch. |
| 1992 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1993 | Tmp1 = LegalizeOp(Tmp1); |
| 1994 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 1995 | |
| 1996 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the jumptable node. |
| 1997 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
| 1998 | |
| 1999 | switch (TLI.getOperationAction(ISD::BR_JT, MVT::Other)) { |
| 2000 | default: assert(0 && "This action is not supported yet!"); |
| 2001 | case TargetLowering::Legal: break; |
| 2002 | case TargetLowering::Custom: |
| 2003 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2004 | if (Tmp1.getNode()) Result = Tmp1; |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 2005 | break; |
| 2006 | case TargetLowering::Expand: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2007 | SDValue Chain = Result.getOperand(0); |
| 2008 | SDValue Table = Result.getOperand(1); |
| 2009 | SDValue Index = Result.getOperand(2); |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 2010 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2011 | MVT PTy = TLI.getPointerTy(); |
Jim Laskey | acd80ac | 2006-12-14 19:17:33 +0000 | [diff] [blame] | 2012 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2013 | unsigned EntrySize = MF.getJumpTableInfo()->getEntrySize(); |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 2014 | Index= DAG.getNode(ISD::MUL, PTy, Index, DAG.getConstant(EntrySize, PTy)); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2015 | SDValue Addr = DAG.getNode(ISD::ADD, PTy, Index, Table); |
Jim Laskey | acd80ac | 2006-12-14 19:17:33 +0000 | [diff] [blame] | 2016 | |
Duncan Sands | 712f7b3 | 2008-12-12 08:13:38 +0000 | [diff] [blame] | 2017 | MVT MemVT = MVT::getIntegerVT(EntrySize * 8); |
| 2018 | SDValue LD = DAG.getExtLoad(ISD::SEXTLOAD, PTy, Chain, Addr, |
| 2019 | PseudoSourceValue::getJumpTable(), 0, MemVT); |
Evan Cheng | cc41586 | 2007-11-09 01:32:10 +0000 | [diff] [blame] | 2020 | Addr = LD; |
Jim Laskey | acd80ac | 2006-12-14 19:17:33 +0000 | [diff] [blame] | 2021 | if (TLI.getTargetMachine().getRelocationModel() == Reloc::PIC_) { |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 2022 | // For PIC, the sequence is: |
| 2023 | // BRIND(load(Jumptable + index) + RelocBase) |
Evan Cheng | cc41586 | 2007-11-09 01:32:10 +0000 | [diff] [blame] | 2024 | // RelocBase can be JumpTable, GOT or some sort of global base. |
Evan Cheng | cc41586 | 2007-11-09 01:32:10 +0000 | [diff] [blame] | 2025 | Addr = DAG.getNode(ISD::ADD, PTy, Addr, |
| 2026 | TLI.getPICJumpTableRelocBase(Table, DAG)); |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 2027 | } |
Evan Cheng | cc41586 | 2007-11-09 01:32:10 +0000 | [diff] [blame] | 2028 | Result = DAG.getNode(ISD::BRIND, MVT::Other, LD.getValue(1), Addr); |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 2029 | } |
| 2030 | } |
| 2031 | break; |
Chris Lattner | c18ae4c | 2005-01-07 08:19:42 +0000 | [diff] [blame] | 2032 | case ISD::BRCOND: |
| 2033 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 2034 | // Ensure that libcalls are emitted before a return. |
| 2035 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 2036 | Tmp1 = LegalizeOp(Tmp1); |
| 2037 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 2038 | |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 2039 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 2040 | case Expand: assert(0 && "It's impossible to expand bools"); |
| 2041 | case Legal: |
| 2042 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the condition. |
| 2043 | break; |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 2044 | case Promote: { |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 2045 | Tmp2 = PromoteOp(Node->getOperand(1)); // Promote the condition. |
Chris Lattner | f990817 | 2006-11-27 04:39:56 +0000 | [diff] [blame] | 2046 | |
| 2047 | // The top bits of the promoted condition are not necessarily zero, ensure |
| 2048 | // that the value is properly zero extended. |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 2049 | unsigned BitWidth = Tmp2.getValueSizeInBits(); |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2050 | if (!DAG.MaskedValueIsZero(Tmp2, |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 2051 | APInt::getHighBitsSet(BitWidth, BitWidth-1))) |
Chris Lattner | f990817 | 2006-11-27 04:39:56 +0000 | [diff] [blame] | 2052 | Tmp2 = DAG.getZeroExtendInReg(Tmp2, MVT::i1); |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 2053 | break; |
| 2054 | } |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 2055 | } |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2056 | |
| 2057 | // Basic block destination (Op#2) is always legal. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2058 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 2059 | |
| 2060 | switch (TLI.getOperationAction(ISD::BRCOND, MVT::Other)) { |
| 2061 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2062 | case TargetLowering::Legal: break; |
| 2063 | case TargetLowering::Custom: |
| 2064 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2065 | if (Tmp1.getNode()) Result = Tmp1; |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2066 | break; |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 2067 | case TargetLowering::Expand: |
| 2068 | // Expand brcond's setcc into its constituent parts and create a BR_CC |
| 2069 | // Node. |
| 2070 | if (Tmp2.getOpcode() == ISD::SETCC) { |
| 2071 | Result = DAG.getNode(ISD::BR_CC, MVT::Other, Tmp1, Tmp2.getOperand(2), |
| 2072 | Tmp2.getOperand(0), Tmp2.getOperand(1), |
| 2073 | Node->getOperand(2)); |
| 2074 | } else { |
| 2075 | Result = DAG.getNode(ISD::BR_CC, MVT::Other, Tmp1, |
| 2076 | DAG.getCondCode(ISD::SETNE), Tmp2, |
| 2077 | DAG.getConstant(0, Tmp2.getValueType()), |
| 2078 | Node->getOperand(2)); |
| 2079 | } |
| 2080 | break; |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 2081 | } |
| 2082 | break; |
| 2083 | case ISD::BR_CC: |
| 2084 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 2085 | // Ensure that libcalls are emitted before a branch. |
| 2086 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 2087 | Tmp1 = LegalizeOp(Tmp1); |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 2088 | Tmp2 = Node->getOperand(2); // LHS |
| 2089 | Tmp3 = Node->getOperand(3); // RHS |
| 2090 | Tmp4 = Node->getOperand(1); // CC |
| 2091 | |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 2092 | LegalizeSetCC(TLI.getSetCCResultType(Tmp2.getValueType()), Tmp2, Tmp3,Tmp4); |
Evan Cheng | 722cb36 | 2006-12-18 22:55:34 +0000 | [diff] [blame] | 2093 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 2094 | |
Evan Cheng | 7f04268 | 2008-10-15 02:05:31 +0000 | [diff] [blame] | 2095 | // 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] | 2096 | // the LHS is a legal SETCC itself. In this case, we need to compare |
| 2097 | // the result against zero to select between true and false values. |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2098 | if (Tmp3.getNode() == 0) { |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 2099 | Tmp3 = DAG.getConstant(0, Tmp2.getValueType()); |
| 2100 | Tmp4 = DAG.getCondCode(ISD::SETNE); |
Chris Lattner | 181b7a3 | 2005-12-17 23:46:46 +0000 | [diff] [blame] | 2101 | } |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 2102 | |
| 2103 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp4, Tmp2, Tmp3, |
| 2104 | Node->getOperand(4)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2105 | |
Chris Lattner | 181b7a3 | 2005-12-17 23:46:46 +0000 | [diff] [blame] | 2106 | switch (TLI.getOperationAction(ISD::BR_CC, Tmp3.getValueType())) { |
| 2107 | default: assert(0 && "Unexpected action for BR_CC!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2108 | case TargetLowering::Legal: break; |
| 2109 | case TargetLowering::Custom: |
| 2110 | Tmp4 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2111 | if (Tmp4.getNode()) Result = Tmp4; |
Chris Lattner | 181b7a3 | 2005-12-17 23:46:46 +0000 | [diff] [blame] | 2112 | break; |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 2113 | } |
Chris Lattner | c18ae4c | 2005-01-07 08:19:42 +0000 | [diff] [blame] | 2114 | break; |
Evan Cheng | f3fd9fe | 2005-12-23 07:29:34 +0000 | [diff] [blame] | 2115 | case ISD::LOAD: { |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2116 | LoadSDNode *LD = cast<LoadSDNode>(Node); |
| 2117 | Tmp1 = LegalizeOp(LD->getChain()); // Legalize the chain. |
| 2118 | Tmp2 = LegalizeOp(LD->getBasePtr()); // Legalize the base pointer. |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 2119 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2120 | ISD::LoadExtType ExtType = LD->getExtensionType(); |
| 2121 | if (ExtType == ISD::NON_EXTLOAD) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2122 | MVT VT = Node->getValueType(0); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2123 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, LD->getOffset()); |
| 2124 | Tmp3 = Result.getValue(0); |
| 2125 | Tmp4 = Result.getValue(1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2126 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2127 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 2128 | default: assert(0 && "This action is not supported yet!"); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2129 | case TargetLowering::Legal: |
| 2130 | // If this is an unaligned load and the target doesn't support it, |
| 2131 | // expand it. |
| 2132 | if (!TLI.allowsUnalignedMemoryAccesses()) { |
| 2133 | unsigned ABIAlignment = TLI.getTargetData()-> |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2134 | getABITypeAlignment(LD->getMemoryVT().getTypeForMVT()); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2135 | if (LD->getAlignment() < ABIAlignment){ |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2136 | Result = ExpandUnalignedLoad(cast<LoadSDNode>(Result.getNode()), DAG, |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2137 | TLI); |
| 2138 | Tmp3 = Result.getOperand(0); |
| 2139 | Tmp4 = Result.getOperand(1); |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 2140 | Tmp3 = LegalizeOp(Tmp3); |
| 2141 | Tmp4 = LegalizeOp(Tmp4); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2142 | } |
| 2143 | } |
| 2144 | break; |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2145 | case TargetLowering::Custom: |
| 2146 | Tmp1 = TLI.LowerOperation(Tmp3, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2147 | if (Tmp1.getNode()) { |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2148 | Tmp3 = LegalizeOp(Tmp1); |
| 2149 | Tmp4 = LegalizeOp(Tmp1.getValue(1)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2150 | } |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2151 | break; |
| 2152 | case TargetLowering::Promote: { |
| 2153 | // Only promote a load of vector type to another. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2154 | assert(VT.isVector() && "Cannot promote this load!"); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2155 | // Change base type to a different vector type. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2156 | MVT NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), VT); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2157 | |
| 2158 | Tmp1 = DAG.getLoad(NVT, Tmp1, Tmp2, LD->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2159 | LD->getSrcValueOffset(), |
| 2160 | LD->isVolatile(), LD->getAlignment()); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2161 | Tmp3 = LegalizeOp(DAG.getNode(ISD::BIT_CONVERT, VT, Tmp1)); |
| 2162 | Tmp4 = LegalizeOp(Tmp1.getValue(1)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2163 | break; |
Andrew Lenharth | 9d416f7 | 2005-06-30 19:22:37 +0000 | [diff] [blame] | 2164 | } |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2165 | } |
| 2166 | // Since loads produce two values, make sure to remember that we |
| 2167 | // legalized both of them. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2168 | AddLegalizedOperand(SDValue(Node, 0), Tmp3); |
| 2169 | AddLegalizedOperand(SDValue(Node, 1), Tmp4); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 2170 | return Op.getResNo() ? Tmp4 : Tmp3; |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2171 | } else { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2172 | MVT SrcVT = LD->getMemoryVT(); |
| 2173 | unsigned SrcWidth = SrcVT.getSizeInBits(); |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2174 | int SVOffset = LD->getSrcValueOffset(); |
| 2175 | unsigned Alignment = LD->getAlignment(); |
| 2176 | bool isVolatile = LD->isVolatile(); |
| 2177 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2178 | if (SrcWidth != SrcVT.getStoreSizeInBits() && |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2179 | // Some targets pretend to have an i1 loading operation, and actually |
| 2180 | // load an i8. This trick is correct for ZEXTLOAD because the top 7 |
| 2181 | // bits are guaranteed to be zero; it helps the optimizers understand |
| 2182 | // that these bits are zero. It is also useful for EXTLOAD, since it |
| 2183 | // tells the optimizers that those bits are undefined. It would be |
| 2184 | // nice to have an effective generic way of getting these benefits... |
| 2185 | // Until such a way is found, don't insist on promoting i1 here. |
| 2186 | (SrcVT != MVT::i1 || |
Evan Cheng | 0329466 | 2008-10-14 21:26:46 +0000 | [diff] [blame] | 2187 | TLI.getLoadExtAction(ExtType, MVT::i1) == TargetLowering::Promote)) { |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2188 | // Promote to a byte-sized load if not loading an integral number of |
| 2189 | // bytes. For example, promote EXTLOAD:i20 -> EXTLOAD:i24. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2190 | unsigned NewWidth = SrcVT.getStoreSizeInBits(); |
| 2191 | MVT NVT = MVT::getIntegerVT(NewWidth); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2192 | SDValue Ch; |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2193 | |
| 2194 | // The extra bits are guaranteed to be zero, since we stored them that |
| 2195 | // way. A zext load from NVT thus automatically gives zext from SrcVT. |
| 2196 | |
| 2197 | ISD::LoadExtType NewExtType = |
| 2198 | ExtType == ISD::ZEXTLOAD ? ISD::ZEXTLOAD : ISD::EXTLOAD; |
| 2199 | |
| 2200 | Result = DAG.getExtLoad(NewExtType, Node->getValueType(0), |
| 2201 | Tmp1, Tmp2, LD->getSrcValue(), SVOffset, |
| 2202 | NVT, isVolatile, Alignment); |
| 2203 | |
| 2204 | Ch = Result.getValue(1); // The chain. |
| 2205 | |
| 2206 | if (ExtType == ISD::SEXTLOAD) |
| 2207 | // Having the top bits zero doesn't help when sign extending. |
| 2208 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(), |
| 2209 | Result, DAG.getValueType(SrcVT)); |
| 2210 | else if (ExtType == ISD::ZEXTLOAD || NVT == Result.getValueType()) |
| 2211 | // All the top bits are guaranteed to be zero - inform the optimizers. |
| 2212 | Result = DAG.getNode(ISD::AssertZext, Result.getValueType(), Result, |
| 2213 | DAG.getValueType(SrcVT)); |
| 2214 | |
| 2215 | Tmp1 = LegalizeOp(Result); |
| 2216 | Tmp2 = LegalizeOp(Ch); |
| 2217 | } else if (SrcWidth & (SrcWidth - 1)) { |
| 2218 | // 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] | 2219 | assert(SrcVT.isExtended() && !SrcVT.isVector() && |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2220 | "Unsupported extload!"); |
| 2221 | unsigned RoundWidth = 1 << Log2_32(SrcWidth); |
| 2222 | assert(RoundWidth < SrcWidth); |
| 2223 | unsigned ExtraWidth = SrcWidth - RoundWidth; |
| 2224 | assert(ExtraWidth < RoundWidth); |
| 2225 | assert(!(RoundWidth % 8) && !(ExtraWidth % 8) && |
| 2226 | "Load size not an integral number of bytes!"); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2227 | MVT RoundVT = MVT::getIntegerVT(RoundWidth); |
| 2228 | MVT ExtraVT = MVT::getIntegerVT(ExtraWidth); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2229 | SDValue Lo, Hi, Ch; |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2230 | unsigned IncrementSize; |
| 2231 | |
| 2232 | if (TLI.isLittleEndian()) { |
| 2233 | // EXTLOAD:i24 -> ZEXTLOAD:i16 | (shl EXTLOAD@+2:i8, 16) |
| 2234 | // Load the bottom RoundWidth bits. |
| 2235 | Lo = DAG.getExtLoad(ISD::ZEXTLOAD, Node->getValueType(0), Tmp1, Tmp2, |
| 2236 | LD->getSrcValue(), SVOffset, RoundVT, isVolatile, |
| 2237 | Alignment); |
| 2238 | |
| 2239 | // Load the remaining ExtraWidth bits. |
| 2240 | IncrementSize = RoundWidth / 8; |
| 2241 | Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2, |
| 2242 | DAG.getIntPtrConstant(IncrementSize)); |
| 2243 | Hi = DAG.getExtLoad(ExtType, Node->getValueType(0), Tmp1, Tmp2, |
| 2244 | LD->getSrcValue(), SVOffset + IncrementSize, |
| 2245 | ExtraVT, isVolatile, |
| 2246 | MinAlign(Alignment, IncrementSize)); |
| 2247 | |
| 2248 | // Build a factor node to remember that this load is independent of the |
| 2249 | // other one. |
| 2250 | Ch = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1), |
| 2251 | Hi.getValue(1)); |
| 2252 | |
| 2253 | // Move the top bits to the right place. |
| 2254 | Hi = DAG.getNode(ISD::SHL, Hi.getValueType(), Hi, |
| 2255 | DAG.getConstant(RoundWidth, TLI.getShiftAmountTy())); |
| 2256 | |
| 2257 | // Join the hi and lo parts. |
| 2258 | Result = DAG.getNode(ISD::OR, Node->getValueType(0), Lo, Hi); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2259 | } else { |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2260 | // Big endian - avoid unaligned loads. |
| 2261 | // EXTLOAD:i24 -> (shl EXTLOAD:i16, 8) | ZEXTLOAD@+2:i8 |
| 2262 | // Load the top RoundWidth bits. |
| 2263 | Hi = DAG.getExtLoad(ExtType, Node->getValueType(0), Tmp1, Tmp2, |
| 2264 | LD->getSrcValue(), SVOffset, RoundVT, isVolatile, |
| 2265 | Alignment); |
| 2266 | |
| 2267 | // Load the remaining ExtraWidth bits. |
| 2268 | IncrementSize = RoundWidth / 8; |
| 2269 | Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2, |
| 2270 | DAG.getIntPtrConstant(IncrementSize)); |
| 2271 | Lo = DAG.getExtLoad(ISD::ZEXTLOAD, Node->getValueType(0), Tmp1, Tmp2, |
| 2272 | LD->getSrcValue(), SVOffset + IncrementSize, |
| 2273 | ExtraVT, isVolatile, |
| 2274 | MinAlign(Alignment, IncrementSize)); |
| 2275 | |
| 2276 | // Build a factor node to remember that this load is independent of the |
| 2277 | // other one. |
| 2278 | Ch = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1), |
| 2279 | Hi.getValue(1)); |
| 2280 | |
| 2281 | // Move the top bits to the right place. |
| 2282 | Hi = DAG.getNode(ISD::SHL, Hi.getValueType(), Hi, |
| 2283 | DAG.getConstant(ExtraWidth, TLI.getShiftAmountTy())); |
| 2284 | |
| 2285 | // Join the hi and lo parts. |
| 2286 | Result = DAG.getNode(ISD::OR, Node->getValueType(0), Lo, Hi); |
| 2287 | } |
| 2288 | |
| 2289 | Tmp1 = LegalizeOp(Result); |
| 2290 | Tmp2 = LegalizeOp(Ch); |
| 2291 | } else { |
Evan Cheng | 0329466 | 2008-10-14 21:26:46 +0000 | [diff] [blame] | 2292 | switch (TLI.getLoadExtAction(ExtType, SrcVT)) { |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2293 | default: assert(0 && "This action is not supported yet!"); |
| 2294 | case TargetLowering::Custom: |
| 2295 | isCustom = true; |
| 2296 | // FALLTHROUGH |
| 2297 | case TargetLowering::Legal: |
| 2298 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, LD->getOffset()); |
| 2299 | Tmp1 = Result.getValue(0); |
| 2300 | Tmp2 = Result.getValue(1); |
| 2301 | |
| 2302 | if (isCustom) { |
| 2303 | Tmp3 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2304 | if (Tmp3.getNode()) { |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2305 | Tmp1 = LegalizeOp(Tmp3); |
| 2306 | Tmp2 = LegalizeOp(Tmp3.getValue(1)); |
| 2307 | } |
| 2308 | } else { |
| 2309 | // If this is an unaligned load and the target doesn't support it, |
| 2310 | // expand it. |
| 2311 | if (!TLI.allowsUnalignedMemoryAccesses()) { |
| 2312 | unsigned ABIAlignment = TLI.getTargetData()-> |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2313 | getABITypeAlignment(LD->getMemoryVT().getTypeForMVT()); |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2314 | if (LD->getAlignment() < ABIAlignment){ |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2315 | Result = ExpandUnalignedLoad(cast<LoadSDNode>(Result.getNode()), DAG, |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2316 | TLI); |
| 2317 | Tmp1 = Result.getOperand(0); |
| 2318 | Tmp2 = Result.getOperand(1); |
| 2319 | Tmp1 = LegalizeOp(Tmp1); |
| 2320 | Tmp2 = LegalizeOp(Tmp2); |
| 2321 | } |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2322 | } |
| 2323 | } |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2324 | break; |
| 2325 | case TargetLowering::Expand: |
| 2326 | // f64 = EXTLOAD f32 should expand to LOAD, FP_EXTEND |
| 2327 | if (SrcVT == MVT::f32 && Node->getValueType(0) == MVT::f64) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2328 | SDValue Load = DAG.getLoad(SrcVT, Tmp1, Tmp2, LD->getSrcValue(), |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2329 | LD->getSrcValueOffset(), |
| 2330 | LD->isVolatile(), LD->getAlignment()); |
| 2331 | Result = DAG.getNode(ISD::FP_EXTEND, Node->getValueType(0), Load); |
| 2332 | Tmp1 = LegalizeOp(Result); // Relegalize new nodes. |
| 2333 | Tmp2 = LegalizeOp(Load.getValue(1)); |
| 2334 | break; |
| 2335 | } |
| 2336 | assert(ExtType != ISD::EXTLOAD &&"EXTLOAD should always be supported!"); |
| 2337 | // Turn the unsupported load into an EXTLOAD followed by an explicit |
| 2338 | // zero/sign extend inreg. |
| 2339 | Result = DAG.getExtLoad(ISD::EXTLOAD, Node->getValueType(0), |
| 2340 | Tmp1, Tmp2, LD->getSrcValue(), |
| 2341 | LD->getSrcValueOffset(), SrcVT, |
| 2342 | LD->isVolatile(), LD->getAlignment()); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2343 | SDValue ValRes; |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2344 | if (ExtType == ISD::SEXTLOAD) |
| 2345 | ValRes = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(), |
| 2346 | Result, DAG.getValueType(SrcVT)); |
| 2347 | else |
| 2348 | ValRes = DAG.getZeroExtendInReg(Result, SrcVT); |
| 2349 | Tmp1 = LegalizeOp(ValRes); // Relegalize new nodes. |
| 2350 | Tmp2 = LegalizeOp(Result.getValue(1)); // Relegalize new nodes. |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2351 | break; |
| 2352 | } |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2353 | } |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2354 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2355 | // Since loads produce two values, make sure to remember that we legalized |
| 2356 | // both of them. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2357 | AddLegalizedOperand(SDValue(Node, 0), Tmp1); |
| 2358 | AddLegalizedOperand(SDValue(Node, 1), Tmp2); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 2359 | return Op.getResNo() ? Tmp2 : Tmp1; |
Chris Lattner | 01ff721 | 2005-04-10 22:54:25 +0000 | [diff] [blame] | 2360 | } |
Chris Lattner | 01ff721 | 2005-04-10 22:54:25 +0000 | [diff] [blame] | 2361 | } |
Nate Begeman | 5dc897b | 2005-10-19 00:06:56 +0000 | [diff] [blame] | 2362 | case ISD::EXTRACT_ELEMENT: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2363 | MVT OpTy = Node->getOperand(0).getValueType(); |
Nate Begeman | 5dc897b | 2005-10-19 00:06:56 +0000 | [diff] [blame] | 2364 | switch (getTypeAction(OpTy)) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2365 | default: assert(0 && "EXTRACT_ELEMENT action for type unimplemented!"); |
Nate Begeman | 5dc897b | 2005-10-19 00:06:56 +0000 | [diff] [blame] | 2366 | case Legal: |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2367 | if (cast<ConstantSDNode>(Node->getOperand(1))->getZExtValue()) { |
Nate Begeman | 5dc897b | 2005-10-19 00:06:56 +0000 | [diff] [blame] | 2368 | // 1 -> Hi |
| 2369 | Result = DAG.getNode(ISD::SRL, OpTy, Node->getOperand(0), |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2370 | DAG.getConstant(OpTy.getSizeInBits()/2, |
Nate Begeman | 5dc897b | 2005-10-19 00:06:56 +0000 | [diff] [blame] | 2371 | TLI.getShiftAmountTy())); |
| 2372 | Result = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0), Result); |
| 2373 | } else { |
| 2374 | // 0 -> Lo |
| 2375 | Result = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0), |
| 2376 | Node->getOperand(0)); |
| 2377 | } |
Nate Begeman | 5dc897b | 2005-10-19 00:06:56 +0000 | [diff] [blame] | 2378 | break; |
| 2379 | case Expand: |
| 2380 | // Get both the low and high parts. |
| 2381 | ExpandOp(Node->getOperand(0), Tmp1, Tmp2); |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2382 | if (cast<ConstantSDNode>(Node->getOperand(1))->getZExtValue()) |
Nate Begeman | 5dc897b | 2005-10-19 00:06:56 +0000 | [diff] [blame] | 2383 | Result = Tmp2; // 1 -> Hi |
| 2384 | else |
| 2385 | Result = Tmp1; // 0 -> Lo |
| 2386 | break; |
| 2387 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2388 | break; |
Nate Begeman | 5dc897b | 2005-10-19 00:06:56 +0000 | [diff] [blame] | 2389 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2390 | |
| 2391 | case ISD::CopyToReg: |
| 2392 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2393 | |
Chris Lattner | c9c60f6 | 2005-08-24 16:35:28 +0000 | [diff] [blame] | 2394 | assert(isTypeLegal(Node->getOperand(2).getValueType()) && |
Chris Lattner | d5d0f9b | 2005-08-16 21:55:35 +0000 | [diff] [blame] | 2395 | "Register type must be legal!"); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 2396 | // Legalize the incoming value (must be a legal type). |
Chris Lattner | d5d0f9b | 2005-08-16 21:55:35 +0000 | [diff] [blame] | 2397 | Tmp2 = LegalizeOp(Node->getOperand(2)); |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 2398 | if (Node->getNumValues() == 1) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2399 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1), Tmp2); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 2400 | } else { |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 2401 | assert(Node->getNumValues() == 2 && "Unknown CopyToReg"); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2402 | if (Node->getNumOperands() == 4) { |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 2403 | Tmp3 = LegalizeOp(Node->getOperand(3)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2404 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1), Tmp2, |
| 2405 | Tmp3); |
| 2406 | } else { |
| 2407 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1),Tmp2); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 2408 | } |
| 2409 | |
| 2410 | // Since this produces two values, make sure to remember that we legalized |
| 2411 | // both of them. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2412 | AddLegalizedOperand(SDValue(Node, 0), Result.getValue(0)); |
| 2413 | AddLegalizedOperand(SDValue(Node, 1), Result.getValue(1)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2414 | return Result; |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 2415 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2416 | break; |
| 2417 | |
| 2418 | case ISD::RET: |
| 2419 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 2420 | |
| 2421 | // Ensure that libcalls are emitted before a return. |
| 2422 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 2423 | Tmp1 = LegalizeOp(Tmp1); |
| 2424 | LastCALLSEQ_END = DAG.getEntryNode(); |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2425 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2426 | switch (Node->getNumOperands()) { |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 2427 | case 3: // ret val |
Evan Cheng | 98f8aeb | 2006-04-11 06:33:39 +0000 | [diff] [blame] | 2428 | Tmp2 = Node->getOperand(1); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 2429 | Tmp3 = Node->getOperand(2); // Signness |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2430 | switch (getTypeAction(Tmp2.getValueType())) { |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2431 | case Legal: |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 2432 | Result = DAG.UpdateNodeOperands(Result, Tmp1, LegalizeOp(Tmp2), Tmp3); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2433 | break; |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2434 | case Expand: |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2435 | if (!Tmp2.getValueType().isVector()) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2436 | SDValue Lo, Hi; |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2437 | ExpandOp(Tmp2, Lo, Hi); |
Chris Lattner | edf2e8d | 2007-03-06 20:01:06 +0000 | [diff] [blame] | 2438 | |
| 2439 | // Big endian systems want the hi reg first. |
Duncan Sands | 0753fc1 | 2008-02-11 10:37:04 +0000 | [diff] [blame] | 2440 | if (TLI.isBigEndian()) |
Chris Lattner | edf2e8d | 2007-03-06 20:01:06 +0000 | [diff] [blame] | 2441 | std::swap(Lo, Hi); |
| 2442 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2443 | if (Hi.getNode()) |
Evan Cheng | 13acce3 | 2006-12-11 19:27:14 +0000 | [diff] [blame] | 2444 | Result = DAG.getNode(ISD::RET, MVT::Other, Tmp1, Lo, Tmp3, Hi,Tmp3); |
| 2445 | else |
| 2446 | Result = DAG.getNode(ISD::RET, MVT::Other, Tmp1, Lo, Tmp3); |
Chris Lattner | f921a51 | 2006-08-21 20:24:53 +0000 | [diff] [blame] | 2447 | Result = LegalizeOp(Result); |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2448 | } else { |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2449 | SDNode *InVal = Tmp2.getNode(); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 2450 | int InIx = Tmp2.getResNo(); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2451 | unsigned NumElems = InVal->getValueType(InIx).getVectorNumElements(); |
| 2452 | MVT EVT = InVal->getValueType(InIx).getVectorElementType(); |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2453 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2454 | // Figure out if there is a simple type corresponding to this Vector |
Reid Spencer | ac9dcb9 | 2007-02-15 03:39:18 +0000 | [diff] [blame] | 2455 | // type. If so, convert to the vector type. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2456 | MVT TVT = MVT::getVectorVT(EVT, NumElems); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2457 | if (TLI.isTypeLegal(TVT)) { |
Reid Spencer | ac9dcb9 | 2007-02-15 03:39:18 +0000 | [diff] [blame] | 2458 | // Turn this into a return of the vector type. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2459 | Tmp2 = LegalizeOp(Tmp2); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 2460 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2461 | } else if (NumElems == 1) { |
| 2462 | // Turn this into a return of the scalar type. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2463 | Tmp2 = ScalarizeVectorOp(Tmp2); |
| 2464 | Tmp2 = LegalizeOp(Tmp2); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 2465 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | b49e52c | 2006-04-11 02:00:08 +0000 | [diff] [blame] | 2466 | |
| 2467 | // FIXME: Returns of gcc generic vectors smaller than a legal type |
| 2468 | // should be returned in integer registers! |
| 2469 | |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2470 | // The scalarized value type may not be legal, e.g. it might require |
| 2471 | // promotion or expansion. Relegalize the return. |
| 2472 | Result = LegalizeOp(Result); |
| 2473 | } else { |
Chris Lattner | b49e52c | 2006-04-11 02:00:08 +0000 | [diff] [blame] | 2474 | // FIXME: Returns of gcc generic vectors larger than a legal vector |
| 2475 | // type should be returned by reference! |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2476 | SDValue Lo, Hi; |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2477 | SplitVectorOp(Tmp2, Lo, Hi); |
Chris Lattner | fea997a | 2007-02-01 04:55:59 +0000 | [diff] [blame] | 2478 | Result = DAG.getNode(ISD::RET, MVT::Other, Tmp1, Lo, Tmp3, Hi,Tmp3); |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2479 | Result = LegalizeOp(Result); |
| 2480 | } |
| 2481 | } |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2482 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2483 | case Promote: |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 2484 | Tmp2 = PromoteOp(Node->getOperand(1)); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 2485 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2486 | Result = LegalizeOp(Result); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 2487 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2488 | } |
| 2489 | break; |
| 2490 | case 1: // ret void |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2491 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2492 | break; |
| 2493 | default: { // ret <values> |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2494 | SmallVector<SDValue, 8> NewValues; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2495 | NewValues.push_back(Tmp1); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 2496 | for (unsigned i = 1, e = Node->getNumOperands(); i < e; i += 2) |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2497 | switch (getTypeAction(Node->getOperand(i).getValueType())) { |
| 2498 | case Legal: |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 2499 | NewValues.push_back(LegalizeOp(Node->getOperand(i))); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 2500 | NewValues.push_back(Node->getOperand(i+1)); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2501 | break; |
| 2502 | case Expand: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2503 | SDValue Lo, Hi; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2504 | assert(!Node->getOperand(i).getValueType().isExtended() && |
Chris Lattner | b49e52c | 2006-04-11 02:00:08 +0000 | [diff] [blame] | 2505 | "FIXME: TODO: implement returning non-legal vector types!"); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2506 | ExpandOp(Node->getOperand(i), Lo, Hi); |
| 2507 | NewValues.push_back(Lo); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 2508 | NewValues.push_back(Node->getOperand(i+1)); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2509 | if (Hi.getNode()) { |
Evan Cheng | 13acce3 | 2006-12-11 19:27:14 +0000 | [diff] [blame] | 2510 | NewValues.push_back(Hi); |
| 2511 | NewValues.push_back(Node->getOperand(i+1)); |
| 2512 | } |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2513 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2514 | } |
| 2515 | case Promote: |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 2516 | assert(0 && "Can't promote multiple return value yet!"); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2517 | } |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2518 | |
| 2519 | if (NewValues.size() == Node->getNumOperands()) |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 2520 | Result = DAG.UpdateNodeOperands(Result, &NewValues[0],NewValues.size()); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2521 | else |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 2522 | Result = DAG.getNode(ISD::RET, MVT::Other, |
| 2523 | &NewValues[0], NewValues.size()); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2524 | break; |
| 2525 | } |
| 2526 | } |
Evan Cheng | 17c428e | 2006-01-06 00:41:43 +0000 | [diff] [blame] | 2527 | |
Chris Lattner | 6862dbc | 2006-01-29 21:02:23 +0000 | [diff] [blame] | 2528 | if (Result.getOpcode() == ISD::RET) { |
| 2529 | switch (TLI.getOperationAction(Result.getOpcode(), MVT::Other)) { |
| 2530 | default: assert(0 && "This action is not supported yet!"); |
| 2531 | case TargetLowering::Legal: break; |
| 2532 | case TargetLowering::Custom: |
| 2533 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2534 | if (Tmp1.getNode()) Result = Tmp1; |
Chris Lattner | 6862dbc | 2006-01-29 21:02:23 +0000 | [diff] [blame] | 2535 | break; |
| 2536 | } |
Evan Cheng | 17c428e | 2006-01-06 00:41:43 +0000 | [diff] [blame] | 2537 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2538 | break; |
Evan Cheng | f3fd9fe | 2005-12-23 07:29:34 +0000 | [diff] [blame] | 2539 | case ISD::STORE: { |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2540 | StoreSDNode *ST = cast<StoreSDNode>(Node); |
| 2541 | Tmp1 = LegalizeOp(ST->getChain()); // Legalize the chain. |
| 2542 | Tmp2 = LegalizeOp(ST->getBasePtr()); // Legalize the pointer. |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2543 | int SVOffset = ST->getSrcValueOffset(); |
| 2544 | unsigned Alignment = ST->getAlignment(); |
| 2545 | bool isVolatile = ST->isVolatile(); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2546 | |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2547 | if (!ST->isTruncatingStore()) { |
Chris Lattner | d93d46e | 2006-12-12 04:18:56 +0000 | [diff] [blame] | 2548 | // Turn 'store float 1.0, Ptr' -> 'store int 0x12345678, Ptr' |
| 2549 | // FIXME: We shouldn't do this for TargetConstantFP's. |
| 2550 | // FIXME: move this to the DAG Combiner! Note that we can't regress due |
| 2551 | // to phase ordering between legalized code and the dag combiner. This |
| 2552 | // probably means that we need to integrate dag combiner and legalizer |
| 2553 | // together. |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 2554 | // We generally can't do this one for long doubles. |
Chris Lattner | 2b4c279 | 2007-10-13 06:35:54 +0000 | [diff] [blame] | 2555 | if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(ST->getValue())) { |
Chris Lattner | 3cb9351 | 2007-10-15 05:46:06 +0000 | [diff] [blame] | 2556 | if (CFP->getValueType(0) == MVT::f32 && |
| 2557 | getTypeAction(MVT::i32) == Legal) { |
Dan Gohman | 6cf9b8a | 2008-03-11 00:11:06 +0000 | [diff] [blame] | 2558 | Tmp3 = DAG.getConstant(CFP->getValueAPF(). |
Dale Johannesen | 7111b02 | 2008-10-09 18:53:47 +0000 | [diff] [blame] | 2559 | bitcastToAPInt().zextOrTrunc(32), |
Dale Johannesen | 3f6eb74 | 2007-09-11 18:32:33 +0000 | [diff] [blame] | 2560 | MVT::i32); |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 2561 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
| 2562 | SVOffset, isVolatile, Alignment); |
| 2563 | break; |
| 2564 | } else if (CFP->getValueType(0) == MVT::f64) { |
Chris Lattner | 3cb9351 | 2007-10-15 05:46:06 +0000 | [diff] [blame] | 2565 | // If this target supports 64-bit registers, do a single 64-bit store. |
| 2566 | if (getTypeAction(MVT::i64) == Legal) { |
Dale Johannesen | 7111b02 | 2008-10-09 18:53:47 +0000 | [diff] [blame] | 2567 | Tmp3 = DAG.getConstant(CFP->getValueAPF().bitcastToAPInt(). |
Dan Gohman | 6cf9b8a | 2008-03-11 00:11:06 +0000 | [diff] [blame] | 2568 | zextOrTrunc(64), MVT::i64); |
Chris Lattner | 3cb9351 | 2007-10-15 05:46:06 +0000 | [diff] [blame] | 2569 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
| 2570 | SVOffset, isVolatile, Alignment); |
| 2571 | break; |
Duncan Sands | d4b9c17 | 2008-06-13 19:07:40 +0000 | [diff] [blame] | 2572 | } else if (getTypeAction(MVT::i32) == Legal && !ST->isVolatile()) { |
Chris Lattner | 3cb9351 | 2007-10-15 05:46:06 +0000 | [diff] [blame] | 2573 | // Otherwise, if the target supports 32-bit registers, use 2 32-bit |
| 2574 | // stores. If the target supports neither 32- nor 64-bits, this |
| 2575 | // xform is certainly not worth it. |
Dale Johannesen | 7111b02 | 2008-10-09 18:53:47 +0000 | [diff] [blame] | 2576 | const APInt &IntVal =CFP->getValueAPF().bitcastToAPInt(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2577 | SDValue Lo = DAG.getConstant(APInt(IntVal).trunc(32), MVT::i32); |
| 2578 | SDValue Hi = DAG.getConstant(IntVal.lshr(32).trunc(32), MVT::i32); |
Duncan Sands | 0753fc1 | 2008-02-11 10:37:04 +0000 | [diff] [blame] | 2579 | if (TLI.isBigEndian()) std::swap(Lo, Hi); |
Chris Lattner | 3cb9351 | 2007-10-15 05:46:06 +0000 | [diff] [blame] | 2580 | |
| 2581 | Lo = DAG.getStore(Tmp1, Lo, Tmp2, ST->getSrcValue(), |
| 2582 | SVOffset, isVolatile, Alignment); |
| 2583 | Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2, |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 2584 | DAG.getIntPtrConstant(4)); |
Chris Lattner | 3cb9351 | 2007-10-15 05:46:06 +0000 | [diff] [blame] | 2585 | Hi = DAG.getStore(Tmp1, Hi, Tmp2, ST->getSrcValue(), SVOffset+4, |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 2586 | isVolatile, MinAlign(Alignment, 4U)); |
Chris Lattner | 3cb9351 | 2007-10-15 05:46:06 +0000 | [diff] [blame] | 2587 | |
| 2588 | Result = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo, Hi); |
| 2589 | break; |
| 2590 | } |
Chris Lattner | d93d46e | 2006-12-12 04:18:56 +0000 | [diff] [blame] | 2591 | } |
Chris Lattner | d93d46e | 2006-12-12 04:18:56 +0000 | [diff] [blame] | 2592 | } |
| 2593 | |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 2594 | switch (getTypeAction(ST->getMemoryVT())) { |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2595 | case Legal: { |
| 2596 | Tmp3 = LegalizeOp(ST->getValue()); |
| 2597 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp3, Tmp2, |
| 2598 | ST->getOffset()); |
Evan Cheng | f3fd9fe | 2005-12-23 07:29:34 +0000 | [diff] [blame] | 2599 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2600 | MVT VT = Tmp3.getValueType(); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2601 | switch (TLI.getOperationAction(ISD::STORE, VT)) { |
| 2602 | default: assert(0 && "This action is not supported yet!"); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2603 | case TargetLowering::Legal: |
| 2604 | // If this is an unaligned store and the target doesn't support it, |
| 2605 | // expand it. |
| 2606 | if (!TLI.allowsUnalignedMemoryAccesses()) { |
| 2607 | unsigned ABIAlignment = TLI.getTargetData()-> |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2608 | getABITypeAlignment(ST->getMemoryVT().getTypeForMVT()); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2609 | if (ST->getAlignment() < ABIAlignment) |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2610 | Result = ExpandUnalignedStore(cast<StoreSDNode>(Result.getNode()), DAG, |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2611 | TLI); |
| 2612 | } |
| 2613 | break; |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2614 | case TargetLowering::Custom: |
| 2615 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2616 | if (Tmp1.getNode()) Result = Tmp1; |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2617 | break; |
| 2618 | case TargetLowering::Promote: |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2619 | assert(VT.isVector() && "Unknown legal promote case!"); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2620 | Tmp3 = DAG.getNode(ISD::BIT_CONVERT, |
| 2621 | TLI.getTypeToPromoteTo(ISD::STORE, VT), Tmp3); |
| 2622 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2623 | ST->getSrcValue(), SVOffset, isVolatile, |
| 2624 | Alignment); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2625 | break; |
| 2626 | } |
| 2627 | break; |
| 2628 | } |
| 2629 | case Promote: |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 2630 | if (!ST->getMemoryVT().isVector()) { |
| 2631 | // Truncate the value and store the result. |
| 2632 | Tmp3 = PromoteOp(ST->getValue()); |
| 2633 | Result = DAG.getTruncStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
| 2634 | SVOffset, ST->getMemoryVT(), |
| 2635 | isVolatile, Alignment); |
| 2636 | break; |
| 2637 | } |
| 2638 | // Fall thru to expand for vector |
| 2639 | case Expand: { |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2640 | unsigned IncrementSize = 0; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2641 | SDValue Lo, Hi; |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2642 | |
| 2643 | // If this is a vector type, then we have to calculate the increment as |
| 2644 | // the product of the element size in bytes, and the number of elements |
| 2645 | // in the high half of the vector. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2646 | if (ST->getValue().getValueType().isVector()) { |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2647 | SDNode *InVal = ST->getValue().getNode(); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 2648 | int InIx = ST->getValue().getResNo(); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2649 | MVT InVT = InVal->getValueType(InIx); |
| 2650 | unsigned NumElems = InVT.getVectorNumElements(); |
| 2651 | MVT EVT = InVT.getVectorElementType(); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2652 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2653 | // Figure out if there is a simple type corresponding to this Vector |
Reid Spencer | ac9dcb9 | 2007-02-15 03:39:18 +0000 | [diff] [blame] | 2654 | // type. If so, convert to the vector type. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2655 | MVT TVT = MVT::getVectorVT(EVT, NumElems); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2656 | if (TLI.isTypeLegal(TVT)) { |
Reid Spencer | ac9dcb9 | 2007-02-15 03:39:18 +0000 | [diff] [blame] | 2657 | // Turn this into a normal store of the vector type. |
Dan Gohman | 21be384 | 2008-02-15 18:11:59 +0000 | [diff] [blame] | 2658 | Tmp3 = LegalizeOp(ST->getValue()); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2659 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2660 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2661 | Result = LegalizeOp(Result); |
| 2662 | break; |
| 2663 | } else if (NumElems == 1) { |
| 2664 | // Turn this into a normal store of the scalar type. |
Dan Gohman | 21be384 | 2008-02-15 18:11:59 +0000 | [diff] [blame] | 2665 | Tmp3 = ScalarizeVectorOp(ST->getValue()); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2666 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2667 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2668 | // The scalarized value type may not be legal, e.g. it might require |
| 2669 | // promotion or expansion. Relegalize the scalar store. |
| 2670 | Result = LegalizeOp(Result); |
| 2671 | break; |
| 2672 | } else { |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 2673 | // Check if we have widen this node with another value |
| 2674 | std::map<SDValue, SDValue>::iterator I = |
| 2675 | WidenNodes.find(ST->getValue()); |
| 2676 | if (I != WidenNodes.end()) { |
| 2677 | Result = StoreWidenVectorOp(ST, Tmp1, Tmp2); |
| 2678 | break; |
| 2679 | } |
| 2680 | else { |
| 2681 | SplitVectorOp(ST->getValue(), Lo, Hi); |
| 2682 | IncrementSize = Lo.getNode()->getValueType(0).getVectorNumElements() * |
| 2683 | EVT.getSizeInBits()/8; |
| 2684 | } |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2685 | } |
| 2686 | } else { |
Dan Gohman | 21be384 | 2008-02-15 18:11:59 +0000 | [diff] [blame] | 2687 | ExpandOp(ST->getValue(), Lo, Hi); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2688 | IncrementSize = Hi.getNode() ? Hi.getValueType().getSizeInBits()/8 : 0; |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2689 | |
Richard Pennington | 4b052dc | 2008-09-25 16:15:10 +0000 | [diff] [blame] | 2690 | if (Hi.getNode() && TLI.isBigEndian()) |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2691 | std::swap(Lo, Hi); |
| 2692 | } |
| 2693 | |
| 2694 | Lo = DAG.getStore(Tmp1, Lo, Tmp2, ST->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2695 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 7b2b5c8 | 2006-12-12 19:53:13 +0000 | [diff] [blame] | 2696 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2697 | if (Hi.getNode() == NULL) { |
Evan Cheng | 7b2b5c8 | 2006-12-12 19:53:13 +0000 | [diff] [blame] | 2698 | // Must be int <-> float one-to-one expansion. |
| 2699 | Result = Lo; |
| 2700 | break; |
| 2701 | } |
| 2702 | |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2703 | Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2, |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 2704 | DAG.getIntPtrConstant(IncrementSize)); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2705 | assert(isTypeLegal(Tmp2.getValueType()) && |
| 2706 | "Pointers must be legal!"); |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2707 | SVOffset += IncrementSize; |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 2708 | Alignment = MinAlign(Alignment, IncrementSize); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2709 | Hi = DAG.getStore(Tmp1, Hi, Tmp2, ST->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2710 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2711 | Result = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo, Hi); |
| 2712 | break; |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 2713 | } // case Expand |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2714 | } |
| 2715 | } else { |
Chris Lattner | ddf8956 | 2008-01-17 19:59:44 +0000 | [diff] [blame] | 2716 | switch (getTypeAction(ST->getValue().getValueType())) { |
| 2717 | case Legal: |
| 2718 | Tmp3 = LegalizeOp(ST->getValue()); |
| 2719 | break; |
| 2720 | case Promote: |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 2721 | if (!ST->getValue().getValueType().isVector()) { |
| 2722 | // We can promote the value, the truncstore will still take care of it. |
| 2723 | Tmp3 = PromoteOp(ST->getValue()); |
| 2724 | break; |
| 2725 | } |
| 2726 | // Vector case falls through to expand |
Chris Lattner | ddf8956 | 2008-01-17 19:59:44 +0000 | [diff] [blame] | 2727 | case Expand: |
| 2728 | // Just store the low part. This may become a non-trunc store, so make |
| 2729 | // sure to use getTruncStore, not UpdateNodeOperands below. |
| 2730 | ExpandOp(ST->getValue(), Tmp3, Tmp4); |
| 2731 | return DAG.getTruncStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
| 2732 | SVOffset, MVT::i8, isVolatile, Alignment); |
| 2733 | } |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2734 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2735 | MVT StVT = ST->getMemoryVT(); |
| 2736 | unsigned StWidth = StVT.getSizeInBits(); |
Duncan Sands | 7e85720 | 2008-01-22 07:17:34 +0000 | [diff] [blame] | 2737 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2738 | if (StWidth != StVT.getStoreSizeInBits()) { |
Duncan Sands | 7e85720 | 2008-01-22 07:17:34 +0000 | [diff] [blame] | 2739 | // Promote to a byte-sized store with upper bits zero if not |
| 2740 | // storing an integral number of bytes. For example, promote |
| 2741 | // TRUNCSTORE:i1 X -> TRUNCSTORE:i8 (and X, 1) |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2742 | MVT NVT = MVT::getIntegerVT(StVT.getStoreSizeInBits()); |
Duncan Sands | 7e85720 | 2008-01-22 07:17:34 +0000 | [diff] [blame] | 2743 | Tmp3 = DAG.getZeroExtendInReg(Tmp3, StVT); |
| 2744 | Result = DAG.getTruncStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
| 2745 | SVOffset, NVT, isVolatile, Alignment); |
| 2746 | } else if (StWidth & (StWidth - 1)) { |
| 2747 | // 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] | 2748 | assert(StVT.isExtended() && !StVT.isVector() && |
Duncan Sands | 7e85720 | 2008-01-22 07:17:34 +0000 | [diff] [blame] | 2749 | "Unsupported truncstore!"); |
| 2750 | unsigned RoundWidth = 1 << Log2_32(StWidth); |
| 2751 | assert(RoundWidth < StWidth); |
| 2752 | unsigned ExtraWidth = StWidth - RoundWidth; |
| 2753 | assert(ExtraWidth < RoundWidth); |
| 2754 | assert(!(RoundWidth % 8) && !(ExtraWidth % 8) && |
| 2755 | "Store size not an integral number of bytes!"); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2756 | MVT RoundVT = MVT::getIntegerVT(RoundWidth); |
| 2757 | MVT ExtraVT = MVT::getIntegerVT(ExtraWidth); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2758 | SDValue Lo, Hi; |
Duncan Sands | 7e85720 | 2008-01-22 07:17:34 +0000 | [diff] [blame] | 2759 | unsigned IncrementSize; |
| 2760 | |
| 2761 | if (TLI.isLittleEndian()) { |
| 2762 | // TRUNCSTORE:i24 X -> TRUNCSTORE:i16 X, TRUNCSTORE@+2:i8 (srl X, 16) |
| 2763 | // Store the bottom RoundWidth bits. |
| 2764 | Lo = DAG.getTruncStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
| 2765 | SVOffset, RoundVT, |
| 2766 | isVolatile, Alignment); |
| 2767 | |
| 2768 | // Store the remaining ExtraWidth bits. |
| 2769 | IncrementSize = RoundWidth / 8; |
| 2770 | Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2, |
| 2771 | DAG.getIntPtrConstant(IncrementSize)); |
| 2772 | Hi = DAG.getNode(ISD::SRL, Tmp3.getValueType(), Tmp3, |
| 2773 | DAG.getConstant(RoundWidth, TLI.getShiftAmountTy())); |
| 2774 | Hi = DAG.getTruncStore(Tmp1, Hi, Tmp2, ST->getSrcValue(), |
| 2775 | SVOffset + IncrementSize, ExtraVT, isVolatile, |
| 2776 | MinAlign(Alignment, IncrementSize)); |
| 2777 | } else { |
| 2778 | // Big endian - avoid unaligned stores. |
| 2779 | // TRUNCSTORE:i24 X -> TRUNCSTORE:i16 (srl X, 8), TRUNCSTORE@+2:i8 X |
| 2780 | // Store the top RoundWidth bits. |
| 2781 | Hi = DAG.getNode(ISD::SRL, Tmp3.getValueType(), Tmp3, |
| 2782 | DAG.getConstant(ExtraWidth, TLI.getShiftAmountTy())); |
| 2783 | Hi = DAG.getTruncStore(Tmp1, Hi, Tmp2, ST->getSrcValue(), SVOffset, |
| 2784 | RoundVT, isVolatile, Alignment); |
| 2785 | |
| 2786 | // Store the remaining ExtraWidth bits. |
| 2787 | IncrementSize = RoundWidth / 8; |
| 2788 | Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2, |
| 2789 | DAG.getIntPtrConstant(IncrementSize)); |
| 2790 | Lo = DAG.getTruncStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
| 2791 | SVOffset + IncrementSize, ExtraVT, isVolatile, |
| 2792 | MinAlign(Alignment, IncrementSize)); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2793 | } |
Duncan Sands | 7e85720 | 2008-01-22 07:17:34 +0000 | [diff] [blame] | 2794 | |
| 2795 | // The order of the stores doesn't matter. |
| 2796 | Result = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo, Hi); |
| 2797 | } else { |
| 2798 | if (Tmp1 != ST->getChain() || Tmp3 != ST->getValue() || |
| 2799 | Tmp2 != ST->getBasePtr()) |
| 2800 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp3, Tmp2, |
| 2801 | ST->getOffset()); |
| 2802 | |
| 2803 | switch (TLI.getTruncStoreAction(ST->getValue().getValueType(), StVT)) { |
| 2804 | default: assert(0 && "This action is not supported yet!"); |
| 2805 | case TargetLowering::Legal: |
| 2806 | // If this is an unaligned store and the target doesn't support it, |
| 2807 | // expand it. |
| 2808 | if (!TLI.allowsUnalignedMemoryAccesses()) { |
| 2809 | unsigned ABIAlignment = TLI.getTargetData()-> |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2810 | getABITypeAlignment(ST->getMemoryVT().getTypeForMVT()); |
Duncan Sands | 7e85720 | 2008-01-22 07:17:34 +0000 | [diff] [blame] | 2811 | if (ST->getAlignment() < ABIAlignment) |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2812 | Result = ExpandUnalignedStore(cast<StoreSDNode>(Result.getNode()), DAG, |
Duncan Sands | 7e85720 | 2008-01-22 07:17:34 +0000 | [diff] [blame] | 2813 | TLI); |
| 2814 | } |
| 2815 | break; |
| 2816 | case TargetLowering::Custom: |
| 2817 | Result = TLI.LowerOperation(Result, DAG); |
| 2818 | break; |
| 2819 | case Expand: |
| 2820 | // TRUNCSTORE:i16 i32 -> STORE i16 |
| 2821 | assert(isTypeLegal(StVT) && "Do not know how to expand this store!"); |
| 2822 | Tmp3 = DAG.getNode(ISD::TRUNCATE, StVT, Tmp3); |
| 2823 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), SVOffset, |
| 2824 | isVolatile, Alignment); |
| 2825 | break; |
| 2826 | } |
Evan Cheng | f3fd9fe | 2005-12-23 07:29:34 +0000 | [diff] [blame] | 2827 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2828 | } |
| 2829 | break; |
Evan Cheng | f3fd9fe | 2005-12-23 07:29:34 +0000 | [diff] [blame] | 2830 | } |
Andrew Lenharth | 9576212 | 2005-03-31 21:24:06 +0000 | [diff] [blame] | 2831 | case ISD::PCMARKER: |
| 2832 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2833 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
Andrew Lenharth | 9576212 | 2005-03-31 21:24:06 +0000 | [diff] [blame] | 2834 | break; |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2835 | case ISD::STACKSAVE: |
| 2836 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2837 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 2838 | Tmp1 = Result.getValue(0); |
| 2839 | Tmp2 = Result.getValue(1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2840 | |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2841 | switch (TLI.getOperationAction(ISD::STACKSAVE, MVT::Other)) { |
| 2842 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2843 | case TargetLowering::Legal: break; |
| 2844 | case TargetLowering::Custom: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2845 | Tmp3 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2846 | if (Tmp3.getNode()) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2847 | Tmp1 = LegalizeOp(Tmp3); |
| 2848 | Tmp2 = LegalizeOp(Tmp3.getValue(1)); |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2849 | } |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2850 | break; |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2851 | case TargetLowering::Expand: |
Chris Lattner | 4f0d8e4 | 2006-01-13 17:48:44 +0000 | [diff] [blame] | 2852 | // Expand to CopyFromReg if the target set |
| 2853 | // StackPointerRegisterToSaveRestore. |
| 2854 | if (unsigned SP = TLI.getStackPointerRegisterToSaveRestore()) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2855 | Tmp1 = DAG.getCopyFromReg(Result.getOperand(0), SP, |
Chris Lattner | 4f0d8e4 | 2006-01-13 17:48:44 +0000 | [diff] [blame] | 2856 | Node->getValueType(0)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2857 | Tmp2 = Tmp1.getValue(1); |
Chris Lattner | 4f0d8e4 | 2006-01-13 17:48:44 +0000 | [diff] [blame] | 2858 | } else { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2859 | Tmp1 = DAG.getNode(ISD::UNDEF, Node->getValueType(0)); |
| 2860 | Tmp2 = Node->getOperand(0); |
Chris Lattner | 4f0d8e4 | 2006-01-13 17:48:44 +0000 | [diff] [blame] | 2861 | } |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2862 | break; |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2863 | } |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2864 | |
| 2865 | // Since stacksave produce two values, make sure to remember that we |
| 2866 | // legalized both of them. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2867 | AddLegalizedOperand(SDValue(Node, 0), Tmp1); |
| 2868 | AddLegalizedOperand(SDValue(Node, 1), Tmp2); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 2869 | return Op.getResNo() ? Tmp2 : Tmp1; |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2870 | |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2871 | case ISD::STACKRESTORE: |
| 2872 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 2873 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2874 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2875 | |
| 2876 | switch (TLI.getOperationAction(ISD::STACKRESTORE, MVT::Other)) { |
| 2877 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2878 | case TargetLowering::Legal: break; |
| 2879 | case TargetLowering::Custom: |
| 2880 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2881 | if (Tmp1.getNode()) Result = Tmp1; |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2882 | break; |
| 2883 | case TargetLowering::Expand: |
Chris Lattner | 4f0d8e4 | 2006-01-13 17:48:44 +0000 | [diff] [blame] | 2884 | // Expand to CopyToReg if the target set |
| 2885 | // StackPointerRegisterToSaveRestore. |
| 2886 | if (unsigned SP = TLI.getStackPointerRegisterToSaveRestore()) { |
| 2887 | Result = DAG.getCopyToReg(Tmp1, SP, Tmp2); |
| 2888 | } else { |
| 2889 | Result = Tmp1; |
| 2890 | } |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2891 | break; |
| 2892 | } |
| 2893 | break; |
| 2894 | |
Andrew Lenharth | 51b8d54 | 2005-11-11 16:47:30 +0000 | [diff] [blame] | 2895 | case ISD::READCYCLECOUNTER: |
| 2896 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2897 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Evan Cheng | f0b3ba6 | 2006-11-29 08:26:18 +0000 | [diff] [blame] | 2898 | switch (TLI.getOperationAction(ISD::READCYCLECOUNTER, |
| 2899 | Node->getValueType(0))) { |
| 2900 | default: assert(0 && "This action is not supported yet!"); |
Evan Cheng | 6a16c5a | 2006-11-29 19:13:47 +0000 | [diff] [blame] | 2901 | case TargetLowering::Legal: |
| 2902 | Tmp1 = Result.getValue(0); |
| 2903 | Tmp2 = Result.getValue(1); |
| 2904 | break; |
Evan Cheng | f0b3ba6 | 2006-11-29 08:26:18 +0000 | [diff] [blame] | 2905 | case TargetLowering::Custom: |
| 2906 | Result = TLI.LowerOperation(Result, DAG); |
Evan Cheng | 6a16c5a | 2006-11-29 19:13:47 +0000 | [diff] [blame] | 2907 | Tmp1 = LegalizeOp(Result.getValue(0)); |
| 2908 | Tmp2 = LegalizeOp(Result.getValue(1)); |
Evan Cheng | f0b3ba6 | 2006-11-29 08:26:18 +0000 | [diff] [blame] | 2909 | break; |
| 2910 | } |
Andrew Lenharth | 49c709f | 2005-12-02 04:56:24 +0000 | [diff] [blame] | 2911 | |
| 2912 | // Since rdcc produce two values, make sure to remember that we legalized |
| 2913 | // both of them. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2914 | AddLegalizedOperand(SDValue(Node, 0), Tmp1); |
| 2915 | AddLegalizedOperand(SDValue(Node, 1), Tmp2); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2916 | return Result; |
Andrew Lenharth | f70e30b | 2005-11-20 21:32:07 +0000 | [diff] [blame] | 2917 | |
Chris Lattner | 2ee743f | 2005-01-14 22:08:15 +0000 | [diff] [blame] | 2918 | case ISD::SELECT: |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 2919 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 2920 | case Expand: assert(0 && "It's impossible to expand bools"); |
| 2921 | case Legal: |
| 2922 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the condition. |
| 2923 | break; |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 2924 | case Promote: { |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 2925 | assert(!Node->getOperand(0).getValueType().isVector() && "not possible"); |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 2926 | Tmp1 = PromoteOp(Node->getOperand(0)); // Promote the condition. |
Chris Lattner | b6c8060 | 2006-11-28 01:03:30 +0000 | [diff] [blame] | 2927 | // Make sure the condition is either zero or one. |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 2928 | unsigned BitWidth = Tmp1.getValueSizeInBits(); |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2929 | if (!DAG.MaskedValueIsZero(Tmp1, |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 2930 | APInt::getHighBitsSet(BitWidth, BitWidth-1))) |
Chris Lattner | b6c8060 | 2006-11-28 01:03:30 +0000 | [diff] [blame] | 2931 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, MVT::i1); |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 2932 | break; |
| 2933 | } |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 2934 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2935 | Tmp2 = LegalizeOp(Node->getOperand(1)); // TrueVal |
Chris Lattner | 2ee743f | 2005-01-14 22:08:15 +0000 | [diff] [blame] | 2936 | Tmp3 = LegalizeOp(Node->getOperand(2)); // FalseVal |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2937 | |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2938 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2939 | |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 2940 | switch (TLI.getOperationAction(ISD::SELECT, Tmp2.getValueType())) { |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2941 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2942 | case TargetLowering::Legal: break; |
| 2943 | case TargetLowering::Custom: { |
| 2944 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2945 | if (Tmp1.getNode()) Result = Tmp1; |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2946 | break; |
| 2947 | } |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 2948 | case TargetLowering::Expand: |
| 2949 | if (Tmp1.getOpcode() == ISD::SETCC) { |
| 2950 | Result = DAG.getSelectCC(Tmp1.getOperand(0), Tmp1.getOperand(1), |
| 2951 | Tmp2, Tmp3, |
| 2952 | cast<CondCodeSDNode>(Tmp1.getOperand(2))->get()); |
| 2953 | } else { |
| 2954 | Result = DAG.getSelectCC(Tmp1, |
| 2955 | DAG.getConstant(0, Tmp1.getValueType()), |
| 2956 | Tmp2, Tmp3, ISD::SETNE); |
| 2957 | } |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2958 | break; |
| 2959 | case TargetLowering::Promote: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2960 | MVT NVT = |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2961 | TLI.getTypeToPromoteTo(ISD::SELECT, Tmp2.getValueType()); |
| 2962 | unsigned ExtOp, TruncOp; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2963 | if (Tmp2.getValueType().isVector()) { |
Evan Cheng | 41f6cbb | 2006-04-12 16:33:18 +0000 | [diff] [blame] | 2964 | ExtOp = ISD::BIT_CONVERT; |
| 2965 | TruncOp = ISD::BIT_CONVERT; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2966 | } else if (Tmp2.getValueType().isInteger()) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2967 | ExtOp = ISD::ANY_EXTEND; |
| 2968 | TruncOp = ISD::TRUNCATE; |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2969 | } else { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2970 | ExtOp = ISD::FP_EXTEND; |
| 2971 | TruncOp = ISD::FP_ROUND; |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2972 | } |
| 2973 | // Promote each of the values to the new type. |
| 2974 | Tmp2 = DAG.getNode(ExtOp, NVT, Tmp2); |
| 2975 | Tmp3 = DAG.getNode(ExtOp, NVT, Tmp3); |
| 2976 | // Perform the larger operation, then round down. |
| 2977 | Result = DAG.getNode(ISD::SELECT, NVT, Tmp1, Tmp2,Tmp3); |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 2978 | if (TruncOp != ISD::FP_ROUND) |
| 2979 | Result = DAG.getNode(TruncOp, Node->getValueType(0), Result); |
| 2980 | else |
| 2981 | Result = DAG.getNode(TruncOp, Node->getValueType(0), Result, |
| 2982 | DAG.getIntPtrConstant(0)); |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2983 | break; |
| 2984 | } |
| 2985 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2986 | break; |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 2987 | case ISD::SELECT_CC: { |
| 2988 | Tmp1 = Node->getOperand(0); // LHS |
| 2989 | Tmp2 = Node->getOperand(1); // RHS |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 2990 | Tmp3 = LegalizeOp(Node->getOperand(2)); // True |
| 2991 | Tmp4 = LegalizeOp(Node->getOperand(3)); // False |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2992 | SDValue CC = Node->getOperand(4); |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 2993 | |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 2994 | LegalizeSetCC(TLI.getSetCCResultType(Tmp1.getValueType()), Tmp1, Tmp2, CC); |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 2995 | |
Evan Cheng | 7f04268 | 2008-10-15 02:05:31 +0000 | [diff] [blame] | 2996 | // 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] | 2997 | // the LHS is a legal SETCC itself. In this case, we need to compare |
| 2998 | // the result against zero to select between true and false values. |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2999 | if (Tmp2.getNode() == 0) { |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 3000 | Tmp2 = DAG.getConstant(0, Tmp1.getValueType()); |
| 3001 | CC = DAG.getCondCode(ISD::SETNE); |
| 3002 | } |
| 3003 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3, Tmp4, CC); |
| 3004 | |
| 3005 | // Everything is legal, see if we should expand this op or something. |
| 3006 | switch (TLI.getOperationAction(ISD::SELECT_CC, Tmp3.getValueType())) { |
| 3007 | default: assert(0 && "This action is not supported yet!"); |
| 3008 | case TargetLowering::Legal: break; |
| 3009 | case TargetLowering::Custom: |
| 3010 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3011 | if (Tmp1.getNode()) Result = Tmp1; |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 3012 | break; |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 3013 | } |
| 3014 | break; |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 3015 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3016 | case ISD::SETCC: |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 3017 | Tmp1 = Node->getOperand(0); |
| 3018 | Tmp2 = Node->getOperand(1); |
| 3019 | Tmp3 = Node->getOperand(2); |
Evan Cheng | 7f04268 | 2008-10-15 02:05:31 +0000 | [diff] [blame] | 3020 | LegalizeSetCC(Node->getValueType(0), Tmp1, Tmp2, Tmp3); |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 3021 | |
| 3022 | // If we had to Expand the SetCC operands into a SELECT node, then it may |
| 3023 | // not always be possible to return a true LHS & RHS. In this case, just |
| 3024 | // return the value we legalized, returned in the LHS |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3025 | if (Tmp2.getNode() == 0) { |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 3026 | Result = Tmp1; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3027 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3028 | } |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 3029 | |
Chris Lattner | 73e142f | 2006-01-30 22:43:50 +0000 | [diff] [blame] | 3030 | switch (TLI.getOperationAction(ISD::SETCC, Tmp1.getValueType())) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3031 | default: assert(0 && "Cannot handle this action for SETCC yet!"); |
| 3032 | case TargetLowering::Custom: |
| 3033 | isCustom = true; |
| 3034 | // FALLTHROUGH. |
| 3035 | case TargetLowering::Legal: |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 3036 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3037 | if (isCustom) { |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 3038 | Tmp4 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3039 | if (Tmp4.getNode()) Result = Tmp4; |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3040 | } |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 3041 | break; |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 3042 | case TargetLowering::Promote: { |
| 3043 | // First step, figure out the appropriate operation to use. |
| 3044 | // Allow SETCC to not be supported for all legal data types |
| 3045 | // Mostly this targets FP |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3046 | MVT NewInTy = Node->getOperand(0).getValueType(); |
| 3047 | MVT OldVT = NewInTy; OldVT = OldVT; |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 3048 | |
| 3049 | // Scan for the appropriate larger type to use. |
| 3050 | while (1) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3051 | NewInTy = (MVT::SimpleValueType)(NewInTy.getSimpleVT()+1); |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 3052 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3053 | assert(NewInTy.isInteger() == OldVT.isInteger() && |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 3054 | "Fell off of the edge of the integer world"); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3055 | assert(NewInTy.isFloatingPoint() == OldVT.isFloatingPoint() && |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 3056 | "Fell off of the edge of the floating point world"); |
| 3057 | |
| 3058 | // If the target supports SETCC of this type, use it. |
Dan Gohman | f560ffa | 2009-01-28 17:46:25 +0000 | [diff] [blame] | 3059 | if (TLI.isOperationLegalOrCustom(ISD::SETCC, NewInTy)) |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 3060 | break; |
| 3061 | } |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3062 | if (NewInTy.isInteger()) |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 3063 | assert(0 && "Cannot promote Legal Integer SETCC yet"); |
| 3064 | else { |
| 3065 | Tmp1 = DAG.getNode(ISD::FP_EXTEND, NewInTy, Tmp1); |
| 3066 | Tmp2 = DAG.getNode(ISD::FP_EXTEND, NewInTy, Tmp2); |
| 3067 | } |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3068 | Tmp1 = LegalizeOp(Tmp1); |
| 3069 | Tmp2 = LegalizeOp(Tmp2); |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 3070 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Evan Cheng | 433f8ac | 2006-01-17 19:47:13 +0000 | [diff] [blame] | 3071 | Result = LegalizeOp(Result); |
Andrew Lenharth | 5e3efbc | 2005-08-29 20:46:51 +0000 | [diff] [blame] | 3072 | break; |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 3073 | } |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 3074 | case TargetLowering::Expand: |
| 3075 | // Expand a setcc node into a select_cc of the same condition, lhs, and |
| 3076 | // rhs that selects between const 1 (true) and const 0 (false). |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3077 | MVT VT = Node->getValueType(0); |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 3078 | Result = DAG.getNode(ISD::SELECT_CC, VT, Tmp1, Tmp2, |
| 3079 | DAG.getConstant(1, VT), DAG.getConstant(0, VT), |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 3080 | Tmp3); |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 3081 | break; |
| 3082 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3083 | break; |
Nate Begeman | b43e9c1 | 2008-05-12 19:40:03 +0000 | [diff] [blame] | 3084 | case ISD::VSETCC: { |
| 3085 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
| 3086 | Tmp2 = LegalizeOp(Node->getOperand(1)); // RHS |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3087 | SDValue CC = Node->getOperand(2); |
Nate Begeman | b43e9c1 | 2008-05-12 19:40:03 +0000 | [diff] [blame] | 3088 | |
| 3089 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, CC); |
| 3090 | |
| 3091 | // Everything is legal, see if we should expand this op or something. |
| 3092 | switch (TLI.getOperationAction(ISD::VSETCC, Tmp1.getValueType())) { |
| 3093 | default: assert(0 && "This action is not supported yet!"); |
| 3094 | case TargetLowering::Legal: break; |
| 3095 | case TargetLowering::Custom: |
| 3096 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3097 | if (Tmp1.getNode()) Result = Tmp1; |
Nate Begeman | b43e9c1 | 2008-05-12 19:40:03 +0000 | [diff] [blame] | 3098 | break; |
Mon P Wang | e1a0b2e | 2008-12-13 08:15:14 +0000 | [diff] [blame] | 3099 | case TargetLowering::Expand: { |
| 3100 | // Unroll into a nasty set of scalar code for now. |
| 3101 | MVT VT = Node->getValueType(0); |
| 3102 | unsigned NumElems = VT.getVectorNumElements(); |
| 3103 | MVT EltVT = VT.getVectorElementType(); |
| 3104 | MVT TmpEltVT = Tmp1.getValueType().getVectorElementType(); |
| 3105 | SmallVector<SDValue, 8> Ops(NumElems); |
| 3106 | for (unsigned i = 0; i < NumElems; ++i) { |
| 3107 | SDValue In1 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, TmpEltVT, |
| 3108 | Tmp1, DAG.getIntPtrConstant(i)); |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 3109 | Ops[i] = DAG.getNode(ISD::SETCC, TLI.getSetCCResultType(TmpEltVT), In1, |
Mon P Wang | 84aff84 | 2008-12-17 08:49:47 +0000 | [diff] [blame] | 3110 | DAG.getNode(ISD::EXTRACT_VECTOR_ELT, TmpEltVT, |
| 3111 | Tmp2, DAG.getIntPtrConstant(i)), |
| 3112 | CC); |
Duncan Sands | b0d5cdd | 2009-02-01 18:06:53 +0000 | [diff] [blame^] | 3113 | Ops[i] = DAG.getNode(ISD::SELECT, EltVT, Ops[i], DAG.getConstant( |
| 3114 | APInt::getAllOnesValue(EltVT.getSizeInBits()), |
| 3115 | EltVT), DAG.getConstant(0, EltVT)); |
Mon P Wang | e1a0b2e | 2008-12-13 08:15:14 +0000 | [diff] [blame] | 3116 | } |
| 3117 | Result = DAG.getNode(ISD::BUILD_VECTOR, VT, &Ops[0], NumElems); |
| 3118 | break; |
| 3119 | } |
Nate Begeman | b43e9c1 | 2008-05-12 19:40:03 +0000 | [diff] [blame] | 3120 | } |
| 3121 | break; |
| 3122 | } |
Chris Lattner | 52d08bd | 2005-05-09 20:23:03 +0000 | [diff] [blame] | 3123 | |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 3124 | case ISD::SHL_PARTS: |
| 3125 | case ISD::SRA_PARTS: |
| 3126 | case ISD::SRL_PARTS: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3127 | SmallVector<SDValue, 8> Ops; |
Chris Lattner | 84f6788 | 2005-01-20 18:52:28 +0000 | [diff] [blame] | 3128 | bool Changed = false; |
Duncan Sands | 92abc62 | 2009-01-31 15:50:11 +0000 | [diff] [blame] | 3129 | unsigned N = Node->getNumOperands(); |
| 3130 | for (unsigned i = 0; i + 1 < N; ++i) { |
Chris Lattner | 84f6788 | 2005-01-20 18:52:28 +0000 | [diff] [blame] | 3131 | Ops.push_back(LegalizeOp(Node->getOperand(i))); |
| 3132 | Changed |= Ops.back() != Node->getOperand(i); |
| 3133 | } |
Duncan Sands | 92abc62 | 2009-01-31 15:50:11 +0000 | [diff] [blame] | 3134 | Ops.push_back(LegalizeOp(DAG.getShiftAmountOperand(Node->getOperand(N-1)))); |
| 3135 | Changed |= Ops.back() != Node->getOperand(N-1); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3136 | if (Changed) |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 3137 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3138 | |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 3139 | switch (TLI.getOperationAction(Node->getOpcode(), |
| 3140 | Node->getValueType(0))) { |
| 3141 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3142 | case TargetLowering::Legal: break; |
| 3143 | case TargetLowering::Custom: |
| 3144 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3145 | if (Tmp1.getNode()) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3146 | SDValue Tmp2, RetVal(0, 0); |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 3147 | for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3148 | Tmp2 = LegalizeOp(Tmp1.getValue(i)); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3149 | AddLegalizedOperand(SDValue(Node, i), Tmp2); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 3150 | if (i == Op.getResNo()) |
Evan Cheng | 12f2274 | 2006-01-19 04:54:52 +0000 | [diff] [blame] | 3151 | RetVal = Tmp2; |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 3152 | } |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3153 | assert(RetVal.getNode() && "Illegal result number"); |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 3154 | return RetVal; |
| 3155 | } |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 3156 | break; |
| 3157 | } |
| 3158 | |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3159 | // Since these produce multiple values, make sure to remember that we |
| 3160 | // legalized all of them. |
| 3161 | for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3162 | AddLegalizedOperand(SDValue(Node, i), Result.getValue(i)); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 3163 | return Result.getValue(Op.getResNo()); |
Chris Lattner | 84f6788 | 2005-01-20 18:52:28 +0000 | [diff] [blame] | 3164 | } |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3165 | |
| 3166 | // Binary operators |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3167 | case ISD::ADD: |
| 3168 | case ISD::SUB: |
| 3169 | case ISD::MUL: |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 3170 | case ISD::MULHS: |
| 3171 | case ISD::MULHU: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3172 | case ISD::UDIV: |
| 3173 | case ISD::SDIV: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3174 | case ISD::AND: |
| 3175 | case ISD::OR: |
| 3176 | case ISD::XOR: |
Chris Lattner | 03c0cf8 | 2005-01-07 21:45:56 +0000 | [diff] [blame] | 3177 | case ISD::SHL: |
| 3178 | case ISD::SRL: |
| 3179 | case ISD::SRA: |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 3180 | case ISD::FADD: |
| 3181 | case ISD::FSUB: |
| 3182 | case ISD::FMUL: |
| 3183 | case ISD::FDIV: |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3184 | case ISD::FPOW: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3185 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
Duncan Sands | 92abc62 | 2009-01-31 15:50:11 +0000 | [diff] [blame] | 3186 | Tmp2 = LegalizeOp(Node->getOperand(1)); // RHS |
Nate Begeman | 5bc1ea0 | 2008-07-29 15:49:41 +0000 | [diff] [blame] | 3187 | |
| 3188 | if ((Node->getOpcode() == ISD::SHL || |
| 3189 | Node->getOpcode() == ISD::SRL || |
| 3190 | Node->getOpcode() == ISD::SRA) && |
Duncan Sands | 92abc62 | 2009-01-31 15:50:11 +0000 | [diff] [blame] | 3191 | !Node->getValueType(0).isVector()) |
| 3192 | Tmp2 = DAG.getShiftAmountOperand(Tmp2); |
| 3193 | |
| 3194 | switch (getTypeAction(Tmp2.getValueType())) { |
| 3195 | case Expand: assert(0 && "Not possible"); |
| 3196 | case Legal: |
| 3197 | Tmp2 = LegalizeOp(Tmp2); // Legalize the RHS. |
| 3198 | break; |
| 3199 | case Promote: |
| 3200 | Tmp2 = PromoteOp(Tmp2); // Promote the RHS. |
| 3201 | break; |
Mon P Wang | e1a0b2e | 2008-12-13 08:15:14 +0000 | [diff] [blame] | 3202 | } |
Nate Begeman | 5bc1ea0 | 2008-07-29 15:49:41 +0000 | [diff] [blame] | 3203 | |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3204 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Mon P Wang | aeb06d2 | 2008-11-10 04:46:22 +0000 | [diff] [blame] | 3205 | |
Andrew Lenharth | e8f65f1 | 2005-12-24 23:42:32 +0000 | [diff] [blame] | 3206 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
Chris Lattner | bc70cf8 | 2006-04-02 03:57:31 +0000 | [diff] [blame] | 3207 | default: assert(0 && "BinOp legalize operation not supported"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3208 | case TargetLowering::Legal: break; |
| 3209 | case TargetLowering::Custom: |
| 3210 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3211 | if (Tmp1.getNode()) { |
Nate Begeman | 5bc1ea0 | 2008-07-29 15:49:41 +0000 | [diff] [blame] | 3212 | Result = Tmp1; |
| 3213 | break; |
Nate Begeman | 24dc346 | 2008-07-29 19:07:27 +0000 | [diff] [blame] | 3214 | } |
Nate Begeman | 5bc1ea0 | 2008-07-29 15:49:41 +0000 | [diff] [blame] | 3215 | // Fall through if the custom lower can't deal with the operation |
Chris Lattner | bc70cf8 | 2006-04-02 03:57:31 +0000 | [diff] [blame] | 3216 | case TargetLowering::Expand: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3217 | MVT VT = Op.getValueType(); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 3218 | |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3219 | // See if multiply or divide can be lowered using two-result operations. |
| 3220 | SDVTList VTs = DAG.getVTList(VT, VT); |
| 3221 | if (Node->getOpcode() == ISD::MUL) { |
| 3222 | // We just need the low half of the multiply; try both the signed |
| 3223 | // and unsigned forms. If the target supports both SMUL_LOHI and |
| 3224 | // UMUL_LOHI, form a preference by checking which forms of plain |
| 3225 | // MULH it supports. |
Dan Gohman | f560ffa | 2009-01-28 17:46:25 +0000 | [diff] [blame] | 3226 | bool HasSMUL_LOHI = TLI.isOperationLegalOrCustom(ISD::SMUL_LOHI, VT); |
| 3227 | bool HasUMUL_LOHI = TLI.isOperationLegalOrCustom(ISD::UMUL_LOHI, VT); |
| 3228 | bool HasMULHS = TLI.isOperationLegalOrCustom(ISD::MULHS, VT); |
| 3229 | bool HasMULHU = TLI.isOperationLegalOrCustom(ISD::MULHU, VT); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3230 | unsigned OpToUse = 0; |
| 3231 | if (HasSMUL_LOHI && !HasMULHS) { |
| 3232 | OpToUse = ISD::SMUL_LOHI; |
| 3233 | } else if (HasUMUL_LOHI && !HasMULHU) { |
| 3234 | OpToUse = ISD::UMUL_LOHI; |
| 3235 | } else if (HasSMUL_LOHI) { |
| 3236 | OpToUse = ISD::SMUL_LOHI; |
| 3237 | } else if (HasUMUL_LOHI) { |
| 3238 | OpToUse = ISD::UMUL_LOHI; |
| 3239 | } |
| 3240 | if (OpToUse) { |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3241 | Result = SDValue(DAG.getNode(OpToUse, VTs, Tmp1, Tmp2).getNode(), 0); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3242 | break; |
| 3243 | } |
| 3244 | } |
| 3245 | if (Node->getOpcode() == ISD::MULHS && |
Dan Gohman | f560ffa | 2009-01-28 17:46:25 +0000 | [diff] [blame] | 3246 | TLI.isOperationLegalOrCustom(ISD::SMUL_LOHI, VT)) { |
Chris Lattner | 31d7161 | 2008-10-04 21:27:46 +0000 | [diff] [blame] | 3247 | Result = SDValue(DAG.getNode(ISD::SMUL_LOHI, VTs, Tmp1, Tmp2).getNode(), |
| 3248 | 1); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3249 | break; |
| 3250 | } |
| 3251 | if (Node->getOpcode() == ISD::MULHU && |
Dan Gohman | f560ffa | 2009-01-28 17:46:25 +0000 | [diff] [blame] | 3252 | TLI.isOperationLegalOrCustom(ISD::UMUL_LOHI, VT)) { |
Chris Lattner | 31d7161 | 2008-10-04 21:27:46 +0000 | [diff] [blame] | 3253 | Result = SDValue(DAG.getNode(ISD::UMUL_LOHI, VTs, Tmp1, Tmp2).getNode(), |
| 3254 | 1); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3255 | break; |
| 3256 | } |
| 3257 | if (Node->getOpcode() == ISD::SDIV && |
Dan Gohman | f560ffa | 2009-01-28 17:46:25 +0000 | [diff] [blame] | 3258 | TLI.isOperationLegalOrCustom(ISD::SDIVREM, VT)) { |
Chris Lattner | 31d7161 | 2008-10-04 21:27:46 +0000 | [diff] [blame] | 3259 | Result = SDValue(DAG.getNode(ISD::SDIVREM, VTs, Tmp1, Tmp2).getNode(), |
| 3260 | 0); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3261 | break; |
| 3262 | } |
| 3263 | if (Node->getOpcode() == ISD::UDIV && |
Dan Gohman | f560ffa | 2009-01-28 17:46:25 +0000 | [diff] [blame] | 3264 | TLI.isOperationLegalOrCustom(ISD::UDIVREM, VT)) { |
Chris Lattner | 31d7161 | 2008-10-04 21:27:46 +0000 | [diff] [blame] | 3265 | Result = SDValue(DAG.getNode(ISD::UDIVREM, VTs, Tmp1, Tmp2).getNode(), |
| 3266 | 0); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3267 | break; |
| 3268 | } |
Mon P Wang | 87c8a8f | 2008-12-18 20:03:17 +0000 | [diff] [blame] | 3269 | |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3270 | // Check to see if we have a libcall for this operator. |
| 3271 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
| 3272 | bool isSigned = false; |
| 3273 | switch (Node->getOpcode()) { |
| 3274 | case ISD::UDIV: |
| 3275 | case ISD::SDIV: |
| 3276 | if (VT == MVT::i32) { |
| 3277 | LC = Node->getOpcode() == ISD::UDIV |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 3278 | ? RTLIB::UDIV_I32 : RTLIB::SDIV_I32; |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3279 | isSigned = Node->getOpcode() == ISD::SDIV; |
| 3280 | } |
| 3281 | break; |
Chris Lattner | 31d7161 | 2008-10-04 21:27:46 +0000 | [diff] [blame] | 3282 | case ISD::MUL: |
| 3283 | if (VT == MVT::i32) |
| 3284 | LC = RTLIB::MUL_I32; |
Nate Begeman | 9b99485 | 2009-01-24 22:12:48 +0000 | [diff] [blame] | 3285 | else if (VT == MVT::i64) |
Scott Michel | 845145f | 2008-12-29 03:21:37 +0000 | [diff] [blame] | 3286 | LC = RTLIB::MUL_I64; |
Chris Lattner | 31d7161 | 2008-10-04 21:27:46 +0000 | [diff] [blame] | 3287 | break; |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3288 | case ISD::FPOW: |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 3289 | LC = GetFPLibCall(VT, RTLIB::POW_F32, RTLIB::POW_F64, RTLIB::POW_F80, |
| 3290 | RTLIB::POW_PPCF128); |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3291 | break; |
Scott Michel | d1e8d9c | 2009-01-21 04:58:48 +0000 | [diff] [blame] | 3292 | case ISD::FDIV: |
| 3293 | LC = GetFPLibCall(VT, RTLIB::DIV_F32, RTLIB::DIV_F64, RTLIB::DIV_F80, |
| 3294 | RTLIB::DIV_PPCF128); |
| 3295 | break; |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3296 | default: break; |
| 3297 | } |
| 3298 | if (LC != RTLIB::UNKNOWN_LIBCALL) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3299 | SDValue Dummy; |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 3300 | Result = ExpandLibCall(LC, Node, isSigned, Dummy); |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 3301 | break; |
| 3302 | } |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 3303 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3304 | assert(Node->getValueType(0).isVector() && |
Chris Lattner | bc70cf8 | 2006-04-02 03:57:31 +0000 | [diff] [blame] | 3305 | "Cannot expand this binary operator!"); |
| 3306 | // Expand the operation into a bunch of nasty scalar code. |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3307 | Result = LegalizeOp(UnrollVectorOp(Op)); |
Chris Lattner | bc70cf8 | 2006-04-02 03:57:31 +0000 | [diff] [blame] | 3308 | break; |
| 3309 | } |
Evan Cheng | cc98761 | 2006-04-12 21:20:24 +0000 | [diff] [blame] | 3310 | case TargetLowering::Promote: { |
| 3311 | switch (Node->getOpcode()) { |
| 3312 | default: assert(0 && "Do not know how to promote this BinOp!"); |
| 3313 | case ISD::AND: |
| 3314 | case ISD::OR: |
| 3315 | case ISD::XOR: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3316 | MVT OVT = Node->getValueType(0); |
| 3317 | MVT NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT); |
| 3318 | assert(OVT.isVector() && "Cannot promote this BinOp!"); |
Evan Cheng | cc98761 | 2006-04-12 21:20:24 +0000 | [diff] [blame] | 3319 | // Bit convert each of the values to the new type. |
| 3320 | Tmp1 = DAG.getNode(ISD::BIT_CONVERT, NVT, Tmp1); |
| 3321 | Tmp2 = DAG.getNode(ISD::BIT_CONVERT, NVT, Tmp2); |
| 3322 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 3323 | // Bit convert the result back the original type. |
| 3324 | Result = DAG.getNode(ISD::BIT_CONVERT, OVT, Result); |
| 3325 | break; |
| 3326 | } |
| 3327 | } |
| 3328 | } |
Andrew Lenharth | e8f65f1 | 2005-12-24 23:42:32 +0000 | [diff] [blame] | 3329 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3330 | break; |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 3331 | |
Dan Gohman | e14ea86 | 2007-10-05 14:17:22 +0000 | [diff] [blame] | 3332 | case ISD::SMUL_LOHI: |
| 3333 | case ISD::UMUL_LOHI: |
| 3334 | case ISD::SDIVREM: |
| 3335 | case ISD::UDIVREM: |
| 3336 | // These nodes will only be produced by target-specific lowering, so |
| 3337 | // they shouldn't be here if they aren't legal. |
Duncan Sands | a7c97a7 | 2007-10-16 09:07:20 +0000 | [diff] [blame] | 3338 | assert(TLI.isOperationLegal(Node->getOpcode(), Node->getValueType(0)) && |
Dan Gohman | e14ea86 | 2007-10-05 14:17:22 +0000 | [diff] [blame] | 3339 | "This must be legal!"); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3340 | |
| 3341 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
| 3342 | Tmp2 = LegalizeOp(Node->getOperand(1)); // RHS |
| 3343 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Dan Gohman | e14ea86 | 2007-10-05 14:17:22 +0000 | [diff] [blame] | 3344 | break; |
| 3345 | |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 3346 | case ISD::FCOPYSIGN: // FCOPYSIGN does not require LHS/RHS to match type! |
| 3347 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
| 3348 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 3349 | case Expand: assert(0 && "Not possible"); |
| 3350 | case Legal: |
| 3351 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the RHS. |
| 3352 | break; |
| 3353 | case Promote: |
| 3354 | Tmp2 = PromoteOp(Node->getOperand(1)); // Promote the RHS. |
| 3355 | break; |
| 3356 | } |
| 3357 | |
| 3358 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 3359 | |
| 3360 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 3361 | default: assert(0 && "Operation not supported"); |
| 3362 | case TargetLowering::Custom: |
| 3363 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3364 | if (Tmp1.getNode()) Result = Tmp1; |
Chris Lattner | 8f4191d | 2006-03-13 06:08:38 +0000 | [diff] [blame] | 3365 | break; |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 3366 | case TargetLowering::Legal: break; |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 3367 | case TargetLowering::Expand: { |
Evan Cheng | 636c753 | 2007-01-05 23:33:44 +0000 | [diff] [blame] | 3368 | // If this target supports fabs/fneg natively and select is cheap, |
| 3369 | // do this efficiently. |
| 3370 | if (!TLI.isSelectExpensive() && |
| 3371 | TLI.getOperationAction(ISD::FABS, Tmp1.getValueType()) == |
| 3372 | TargetLowering::Legal && |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 3373 | TLI.getOperationAction(ISD::FNEG, Tmp1.getValueType()) == |
Evan Cheng | 636c753 | 2007-01-05 23:33:44 +0000 | [diff] [blame] | 3374 | TargetLowering::Legal) { |
Chris Lattner | 8f4191d | 2006-03-13 06:08:38 +0000 | [diff] [blame] | 3375 | // Get the sign bit of the RHS. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3376 | MVT IVT = |
Chris Lattner | 8f4191d | 2006-03-13 06:08:38 +0000 | [diff] [blame] | 3377 | Tmp2.getValueType() == MVT::f32 ? MVT::i32 : MVT::i64; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3378 | SDValue SignBit = DAG.getNode(ISD::BIT_CONVERT, IVT, Tmp2); |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 3379 | SignBit = DAG.getSetCC(TLI.getSetCCResultType(IVT), |
Chris Lattner | 8f4191d | 2006-03-13 06:08:38 +0000 | [diff] [blame] | 3380 | SignBit, DAG.getConstant(0, IVT), ISD::SETLT); |
| 3381 | // Get the absolute value of the result. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3382 | SDValue AbsVal = DAG.getNode(ISD::FABS, Tmp1.getValueType(), Tmp1); |
Chris Lattner | 8f4191d | 2006-03-13 06:08:38 +0000 | [diff] [blame] | 3383 | // Select between the nabs and abs value based on the sign bit of |
| 3384 | // the input. |
| 3385 | Result = DAG.getNode(ISD::SELECT, AbsVal.getValueType(), SignBit, |
| 3386 | DAG.getNode(ISD::FNEG, AbsVal.getValueType(), |
| 3387 | AbsVal), |
| 3388 | AbsVal); |
| 3389 | Result = LegalizeOp(Result); |
| 3390 | break; |
| 3391 | } |
| 3392 | |
| 3393 | // Otherwise, do bitwise ops! |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3394 | MVT NVT = |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 3395 | Node->getValueType(0) == MVT::f32 ? MVT::i32 : MVT::i64; |
| 3396 | Result = ExpandFCOPYSIGNToBitwiseOps(Node, NVT, DAG, TLI); |
| 3397 | Result = DAG.getNode(ISD::BIT_CONVERT, Node->getValueType(0), Result); |
| 3398 | Result = LegalizeOp(Result); |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 3399 | break; |
| 3400 | } |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 3401 | } |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 3402 | break; |
| 3403 | |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 3404 | case ISD::ADDC: |
| 3405 | case ISD::SUBC: |
| 3406 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 3407 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 3408 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Sanjiv Gupta | d3f01aa | 2008-11-26 11:19:00 +0000 | [diff] [blame] | 3409 | Tmp3 = Result.getValue(0); |
| 3410 | Tmp4 = Result.getValue(1); |
| 3411 | |
| 3412 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 3413 | default: assert(0 && "This action is not supported yet!"); |
| 3414 | case TargetLowering::Legal: |
| 3415 | break; |
| 3416 | case TargetLowering::Custom: |
| 3417 | Tmp1 = TLI.LowerOperation(Tmp3, DAG); |
| 3418 | if (Tmp1.getNode() != NULL) { |
Sanjiv Gupta | 9b0f0b5 | 2008-11-27 05:58:04 +0000 | [diff] [blame] | 3419 | Tmp3 = LegalizeOp(Tmp1); |
Sanjiv Gupta | d3f01aa | 2008-11-26 11:19:00 +0000 | [diff] [blame] | 3420 | Tmp4 = LegalizeOp(Tmp1.getValue(1)); |
| 3421 | } |
| 3422 | break; |
| 3423 | } |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 3424 | // Since this produces two values, make sure to remember that we legalized |
| 3425 | // both of them. |
Sanjiv Gupta | d3f01aa | 2008-11-26 11:19:00 +0000 | [diff] [blame] | 3426 | AddLegalizedOperand(SDValue(Node, 0), Tmp3); |
| 3427 | AddLegalizedOperand(SDValue(Node, 1), Tmp4); |
| 3428 | return Op.getResNo() ? Tmp4 : Tmp3; |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 3429 | |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 3430 | case ISD::ADDE: |
| 3431 | case ISD::SUBE: |
| 3432 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 3433 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 3434 | Tmp3 = LegalizeOp(Node->getOperand(2)); |
| 3435 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Sanjiv Gupta | d3f01aa | 2008-11-26 11:19:00 +0000 | [diff] [blame] | 3436 | Tmp3 = Result.getValue(0); |
| 3437 | Tmp4 = Result.getValue(1); |
| 3438 | |
| 3439 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 3440 | default: assert(0 && "This action is not supported yet!"); |
| 3441 | case TargetLowering::Legal: |
| 3442 | break; |
| 3443 | case TargetLowering::Custom: |
| 3444 | Tmp1 = TLI.LowerOperation(Tmp3, DAG); |
| 3445 | if (Tmp1.getNode() != NULL) { |
Sanjiv Gupta | 9b0f0b5 | 2008-11-27 05:58:04 +0000 | [diff] [blame] | 3446 | Tmp3 = LegalizeOp(Tmp1); |
Sanjiv Gupta | d3f01aa | 2008-11-26 11:19:00 +0000 | [diff] [blame] | 3447 | Tmp4 = LegalizeOp(Tmp1.getValue(1)); |
| 3448 | } |
| 3449 | break; |
| 3450 | } |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 3451 | // Since this produces two values, make sure to remember that we legalized |
| 3452 | // both of them. |
Sanjiv Gupta | d3f01aa | 2008-11-26 11:19:00 +0000 | [diff] [blame] | 3453 | AddLegalizedOperand(SDValue(Node, 0), Tmp3); |
| 3454 | AddLegalizedOperand(SDValue(Node, 1), Tmp4); |
| 3455 | return Op.getResNo() ? Tmp4 : Tmp3; |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 3456 | |
Nate Begeman | 419f8b6 | 2005-10-18 00:27:41 +0000 | [diff] [blame] | 3457 | case ISD::BUILD_PAIR: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3458 | MVT PairTy = Node->getValueType(0); |
Nate Begeman | 419f8b6 | 2005-10-18 00:27:41 +0000 | [diff] [blame] | 3459 | // TODO: handle the case where the Lo and Hi operands are not of legal type |
| 3460 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Lo |
| 3461 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Hi |
| 3462 | switch (TLI.getOperationAction(ISD::BUILD_PAIR, PairTy)) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3463 | case TargetLowering::Promote: |
| 3464 | case TargetLowering::Custom: |
| 3465 | assert(0 && "Cannot promote/custom this yet!"); |
Nate Begeman | 419f8b6 | 2005-10-18 00:27:41 +0000 | [diff] [blame] | 3466 | case TargetLowering::Legal: |
| 3467 | if (Tmp1 != Node->getOperand(0) || Tmp2 != Node->getOperand(1)) |
| 3468 | Result = DAG.getNode(ISD::BUILD_PAIR, PairTy, Tmp1, Tmp2); |
| 3469 | break; |
Nate Begeman | 419f8b6 | 2005-10-18 00:27:41 +0000 | [diff] [blame] | 3470 | case TargetLowering::Expand: |
| 3471 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, PairTy, Tmp1); |
| 3472 | Tmp2 = DAG.getNode(ISD::ANY_EXTEND, PairTy, Tmp2); |
| 3473 | Tmp2 = DAG.getNode(ISD::SHL, PairTy, Tmp2, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3474 | DAG.getConstant(PairTy.getSizeInBits()/2, |
Nate Begeman | 419f8b6 | 2005-10-18 00:27:41 +0000 | [diff] [blame] | 3475 | TLI.getShiftAmountTy())); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3476 | Result = DAG.getNode(ISD::OR, PairTy, Tmp1, Tmp2); |
Nate Begeman | 419f8b6 | 2005-10-18 00:27:41 +0000 | [diff] [blame] | 3477 | break; |
| 3478 | } |
| 3479 | break; |
| 3480 | } |
| 3481 | |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 3482 | case ISD::UREM: |
| 3483 | case ISD::SREM: |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 3484 | case ISD::FREM: |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 3485 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
| 3486 | Tmp2 = LegalizeOp(Node->getOperand(1)); // RHS |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3487 | |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 3488 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3489 | case TargetLowering::Promote: assert(0 && "Cannot promote this yet!"); |
| 3490 | case TargetLowering::Custom: |
| 3491 | isCustom = true; |
| 3492 | // FALLTHROUGH |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 3493 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3494 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3495 | if (isCustom) { |
| 3496 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3497 | if (Tmp1.getNode()) Result = Tmp1; |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3498 | } |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 3499 | break; |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3500 | case TargetLowering::Expand: { |
Evan Cheng | 6b5578f | 2006-09-18 23:28:33 +0000 | [diff] [blame] | 3501 | unsigned DivOpc= (Node->getOpcode() == ISD::UREM) ? ISD::UDIV : ISD::SDIV; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 3502 | bool isSigned = DivOpc == ISD::SDIV; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3503 | MVT VT = Node->getValueType(0); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3504 | |
| 3505 | // See if remainder can be lowered using two-result operations. |
| 3506 | SDVTList VTs = DAG.getVTList(VT, VT); |
| 3507 | if (Node->getOpcode() == ISD::SREM && |
Dan Gohman | f560ffa | 2009-01-28 17:46:25 +0000 | [diff] [blame] | 3508 | TLI.isOperationLegalOrCustom(ISD::SDIVREM, VT)) { |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3509 | Result = SDValue(DAG.getNode(ISD::SDIVREM, VTs, Tmp1, Tmp2).getNode(), 1); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3510 | break; |
| 3511 | } |
| 3512 | if (Node->getOpcode() == ISD::UREM && |
Dan Gohman | f560ffa | 2009-01-28 17:46:25 +0000 | [diff] [blame] | 3513 | TLI.isOperationLegalOrCustom(ISD::UDIVREM, VT)) { |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3514 | Result = SDValue(DAG.getNode(ISD::UDIVREM, VTs, Tmp1, Tmp2).getNode(), 1); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3515 | break; |
| 3516 | } |
| 3517 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3518 | if (VT.isInteger()) { |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3519 | if (TLI.getOperationAction(DivOpc, VT) == |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 3520 | TargetLowering::Legal) { |
| 3521 | // X % Y -> X-X/Y*Y |
Evan Cheng | 6b5578f | 2006-09-18 23:28:33 +0000 | [diff] [blame] | 3522 | Result = DAG.getNode(DivOpc, VT, Tmp1, Tmp2); |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 3523 | Result = DAG.getNode(ISD::MUL, VT, Result, Tmp2); |
| 3524 | Result = DAG.getNode(ISD::SUB, VT, Tmp1, Result); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3525 | } else if (VT.isVector()) { |
Dan Gohman | 8017631 | 2007-11-05 23:35:22 +0000 | [diff] [blame] | 3526 | Result = LegalizeOp(UnrollVectorOp(Op)); |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 3527 | } else { |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3528 | assert(VT == MVT::i32 && |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 3529 | "Cannot expand this binary operator!"); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3530 | RTLIB::Libcall LC = Node->getOpcode() == ISD::UREM |
| 3531 | ? RTLIB::UREM_I32 : RTLIB::SREM_I32; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3532 | SDValue Dummy; |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 3533 | Result = ExpandLibCall(LC, Node, isSigned, Dummy); |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 3534 | } |
Dan Gohman | 0d97426 | 2007-11-06 22:11:54 +0000 | [diff] [blame] | 3535 | } else { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3536 | assert(VT.isFloatingPoint() && |
Dan Gohman | 0d97426 | 2007-11-06 22:11:54 +0000 | [diff] [blame] | 3537 | "remainder op must have integer or floating-point type"); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3538 | if (VT.isVector()) { |
Dan Gohman | 8017631 | 2007-11-05 23:35:22 +0000 | [diff] [blame] | 3539 | Result = LegalizeOp(UnrollVectorOp(Op)); |
| 3540 | } else { |
| 3541 | // Floating point mod -> fmod libcall. |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 3542 | RTLIB::Libcall LC = GetFPLibCall(VT, RTLIB::REM_F32, RTLIB::REM_F64, |
| 3543 | RTLIB::REM_F80, RTLIB::REM_PPCF128); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3544 | SDValue Dummy; |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 3545 | Result = ExpandLibCall(LC, Node, false/*sign irrelevant*/, Dummy); |
Dan Gohman | 8017631 | 2007-11-05 23:35:22 +0000 | [diff] [blame] | 3546 | } |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 3547 | } |
| 3548 | break; |
| 3549 | } |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3550 | } |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 3551 | break; |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3552 | case ISD::VAARG: { |
| 3553 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 3554 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. |
| 3555 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3556 | MVT VT = Node->getValueType(0); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3557 | switch (TLI.getOperationAction(Node->getOpcode(), MVT::Other)) { |
| 3558 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3559 | case TargetLowering::Custom: |
| 3560 | isCustom = true; |
| 3561 | // FALLTHROUGH |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3562 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3563 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
| 3564 | Result = Result.getValue(0); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3565 | Tmp1 = Result.getValue(1); |
| 3566 | |
| 3567 | if (isCustom) { |
| 3568 | Tmp2 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3569 | if (Tmp2.getNode()) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3570 | Result = LegalizeOp(Tmp2); |
| 3571 | Tmp1 = LegalizeOp(Tmp2.getValue(1)); |
| 3572 | } |
| 3573 | } |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3574 | break; |
| 3575 | case TargetLowering::Expand: { |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 3576 | const Value *V = cast<SrcValueSDNode>(Node->getOperand(2))->getValue(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3577 | SDValue VAList = DAG.getLoad(TLI.getPointerTy(), Tmp1, Tmp2, V, 0); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3578 | // Increment the pointer, VAList, to the next vaarg |
Duncan Sands | 5c58a31 | 2008-11-03 11:51:11 +0000 | [diff] [blame] | 3579 | Tmp3 = DAG.getNode(ISD::ADD, TLI.getPointerTy(), VAList, |
Duncan Sands | ceb4d1a | 2009-01-12 20:38:59 +0000 | [diff] [blame] | 3580 | DAG.getConstant(TLI.getTargetData()-> |
| 3581 | getTypePaddedSize(VT.getTypeForMVT()), |
| 3582 | TLI.getPointerTy())); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3583 | // Store the incremented VAList to the legalized pointer |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 3584 | Tmp3 = DAG.getStore(VAList.getValue(1), Tmp3, Tmp2, V, 0); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3585 | // Load the actual argument out of the pointer VAList |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 3586 | Result = DAG.getLoad(VT, Tmp3, VAList, NULL, 0); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3587 | Tmp1 = LegalizeOp(Result.getValue(1)); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3588 | Result = LegalizeOp(Result); |
| 3589 | break; |
| 3590 | } |
| 3591 | } |
| 3592 | // Since VAARG produces two values, make sure to remember that we |
| 3593 | // legalized both of them. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3594 | AddLegalizedOperand(SDValue(Node, 0), Result); |
| 3595 | AddLegalizedOperand(SDValue(Node, 1), Tmp1); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 3596 | return Op.getResNo() ? Tmp1 : Result; |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3597 | } |
| 3598 | |
| 3599 | case ISD::VACOPY: |
| 3600 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 3601 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the dest pointer. |
| 3602 | Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the source pointer. |
| 3603 | |
| 3604 | switch (TLI.getOperationAction(ISD::VACOPY, MVT::Other)) { |
| 3605 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3606 | case TargetLowering::Custom: |
| 3607 | isCustom = true; |
| 3608 | // FALLTHROUGH |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3609 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3610 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3, |
| 3611 | Node->getOperand(3), Node->getOperand(4)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3612 | if (isCustom) { |
| 3613 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3614 | if (Tmp1.getNode()) Result = Tmp1; |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3615 | } |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3616 | break; |
| 3617 | case TargetLowering::Expand: |
| 3618 | // This defaults to loading a pointer from the input and storing it to the |
| 3619 | // output, returning the chain. |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 3620 | const Value *VD = cast<SrcValueSDNode>(Node->getOperand(3))->getValue(); |
| 3621 | const Value *VS = cast<SrcValueSDNode>(Node->getOperand(4))->getValue(); |
Dan Gohman | 499c1bd | 2008-04-17 02:09:26 +0000 | [diff] [blame] | 3622 | Tmp4 = DAG.getLoad(TLI.getPointerTy(), Tmp1, Tmp3, VS, 0); |
| 3623 | Result = DAG.getStore(Tmp4.getValue(1), Tmp4, Tmp2, VD, 0); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3624 | break; |
| 3625 | } |
| 3626 | break; |
| 3627 | |
| 3628 | case ISD::VAEND: |
| 3629 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 3630 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. |
| 3631 | |
| 3632 | switch (TLI.getOperationAction(ISD::VAEND, MVT::Other)) { |
| 3633 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3634 | case TargetLowering::Custom: |
| 3635 | isCustom = true; |
| 3636 | // FALLTHROUGH |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3637 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3638 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3639 | if (isCustom) { |
| 3640 | Tmp1 = TLI.LowerOperation(Tmp1, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3641 | if (Tmp1.getNode()) Result = Tmp1; |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3642 | } |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3643 | break; |
| 3644 | case TargetLowering::Expand: |
| 3645 | Result = Tmp1; // Default to a no-op, return the chain |
| 3646 | break; |
| 3647 | } |
| 3648 | break; |
| 3649 | |
| 3650 | case ISD::VASTART: |
| 3651 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 3652 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. |
| 3653 | |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3654 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
| 3655 | |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3656 | switch (TLI.getOperationAction(ISD::VASTART, MVT::Other)) { |
| 3657 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3658 | case TargetLowering::Legal: break; |
| 3659 | case TargetLowering::Custom: |
| 3660 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3661 | if (Tmp1.getNode()) Result = Tmp1; |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3662 | break; |
| 3663 | } |
| 3664 | break; |
| 3665 | |
Nate Begeman | 35ef913 | 2006-01-11 21:21:00 +0000 | [diff] [blame] | 3666 | case ISD::ROTL: |
| 3667 | case ISD::ROTR: |
| 3668 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
Duncan Sands | 92abc62 | 2009-01-31 15:50:11 +0000 | [diff] [blame] | 3669 | Tmp2 = LegalizeOp(DAG.getShiftAmountOperand(Node->getOperand(1))); // RHS |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3670 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Scott Michel | c9dc114 | 2007-04-02 21:36:32 +0000 | [diff] [blame] | 3671 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 3672 | default: |
| 3673 | assert(0 && "ROTL/ROTR legalize operation not supported"); |
| 3674 | break; |
| 3675 | case TargetLowering::Legal: |
| 3676 | break; |
| 3677 | case TargetLowering::Custom: |
| 3678 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3679 | if (Tmp1.getNode()) Result = Tmp1; |
Scott Michel | c9dc114 | 2007-04-02 21:36:32 +0000 | [diff] [blame] | 3680 | break; |
| 3681 | case TargetLowering::Promote: |
| 3682 | assert(0 && "Do not know how to promote ROTL/ROTR"); |
| 3683 | break; |
| 3684 | case TargetLowering::Expand: |
| 3685 | assert(0 && "Do not know how to expand ROTL/ROTR"); |
| 3686 | break; |
| 3687 | } |
Nate Begeman | 35ef913 | 2006-01-11 21:21:00 +0000 | [diff] [blame] | 3688 | break; |
| 3689 | |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 3690 | case ISD::BSWAP: |
| 3691 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Op |
| 3692 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3693 | case TargetLowering::Custom: |
| 3694 | assert(0 && "Cannot custom legalize this yet!"); |
| 3695 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3696 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3697 | break; |
| 3698 | case TargetLowering::Promote: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3699 | MVT OVT = Tmp1.getValueType(); |
| 3700 | MVT NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT); |
| 3701 | unsigned DiffBits = NVT.getSizeInBits() - OVT.getSizeInBits(); |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 3702 | |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3703 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Tmp1); |
| 3704 | Tmp1 = DAG.getNode(ISD::BSWAP, NVT, Tmp1); |
| 3705 | Result = DAG.getNode(ISD::SRL, NVT, Tmp1, |
| 3706 | DAG.getConstant(DiffBits, TLI.getShiftAmountTy())); |
| 3707 | break; |
| 3708 | } |
| 3709 | case TargetLowering::Expand: |
| 3710 | Result = ExpandBSWAP(Tmp1); |
| 3711 | break; |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 3712 | } |
| 3713 | break; |
| 3714 | |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3715 | case ISD::CTPOP: |
| 3716 | case ISD::CTTZ: |
| 3717 | case ISD::CTLZ: |
| 3718 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Op |
| 3719 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
Scott Michel | 910b66d | 2007-07-30 21:00:31 +0000 | [diff] [blame] | 3720 | case TargetLowering::Custom: |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3721 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3722 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Scott Michel | 910b66d | 2007-07-30 21:00:31 +0000 | [diff] [blame] | 3723 | if (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0)) == |
Scott Michel | 335f4f7 | 2007-08-02 02:22:46 +0000 | [diff] [blame] | 3724 | TargetLowering::Custom) { |
| 3725 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3726 | if (Tmp1.getNode()) { |
Scott Michel | 335f4f7 | 2007-08-02 02:22:46 +0000 | [diff] [blame] | 3727 | Result = Tmp1; |
| 3728 | } |
Scott Michel | 910b66d | 2007-07-30 21:00:31 +0000 | [diff] [blame] | 3729 | } |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3730 | break; |
| 3731 | case TargetLowering::Promote: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3732 | MVT OVT = Tmp1.getValueType(); |
| 3733 | MVT NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT); |
Chris Lattner | edb1add | 2005-05-11 04:51:16 +0000 | [diff] [blame] | 3734 | |
| 3735 | // Zero extend the argument. |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3736 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Tmp1); |
| 3737 | // Perform the larger operation, then subtract if needed. |
| 3738 | Tmp1 = DAG.getNode(Node->getOpcode(), Node->getValueType(0), Tmp1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3739 | switch (Node->getOpcode()) { |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3740 | case ISD::CTPOP: |
| 3741 | Result = Tmp1; |
| 3742 | break; |
| 3743 | case ISD::CTTZ: |
| 3744 | //if Tmp1 == sizeinbits(NVT) then Tmp1 = sizeinbits(Old VT) |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 3745 | Tmp2 = DAG.getSetCC(TLI.getSetCCResultType(Tmp1.getValueType()), Tmp1, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3746 | DAG.getConstant(NVT.getSizeInBits(), NVT), |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 3747 | ISD::SETEQ); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 3748 | Result = DAG.getNode(ISD::SELECT, NVT, Tmp2, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3749 | DAG.getConstant(OVT.getSizeInBits(), NVT), Tmp1); |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3750 | break; |
| 3751 | case ISD::CTLZ: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3752 | // Tmp1 = Tmp1 - (sizeinbits(NVT) - sizeinbits(Old VT)) |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 3753 | Result = DAG.getNode(ISD::SUB, NVT, Tmp1, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3754 | DAG.getConstant(NVT.getSizeInBits() - |
| 3755 | OVT.getSizeInBits(), NVT)); |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3756 | break; |
| 3757 | } |
| 3758 | break; |
| 3759 | } |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3760 | case TargetLowering::Expand: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3761 | Result = ExpandBitCount(Node->getOpcode(), Tmp1); |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3762 | break; |
| 3763 | } |
| 3764 | break; |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 3765 | |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3766 | // Unary operators |
| 3767 | case ISD::FABS: |
| 3768 | case ISD::FNEG: |
Chris Lattner | da6ba87 | 2005-04-28 21:44:33 +0000 | [diff] [blame] | 3769 | case ISD::FSQRT: |
| 3770 | case ISD::FSIN: |
| 3771 | case ISD::FCOS: |
Dale Johannesen | 7794f2a | 2008-09-04 00:47:13 +0000 | [diff] [blame] | 3772 | case ISD::FLOG: |
| 3773 | case ISD::FLOG2: |
| 3774 | case ISD::FLOG10: |
| 3775 | case ISD::FEXP: |
| 3776 | case ISD::FEXP2: |
Dan Gohman | 509e84f | 2008-08-21 17:55:02 +0000 | [diff] [blame] | 3777 | case ISD::FTRUNC: |
| 3778 | case ISD::FFLOOR: |
| 3779 | case ISD::FCEIL: |
| 3780 | case ISD::FRINT: |
| 3781 | case ISD::FNEARBYINT: |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3782 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 3783 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3784 | case TargetLowering::Promote: |
| 3785 | case TargetLowering::Custom: |
Evan Cheng | 59ad781 | 2006-01-31 18:14:25 +0000 | [diff] [blame] | 3786 | isCustom = true; |
| 3787 | // FALLTHROUGH |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3788 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3789 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Evan Cheng | 59ad781 | 2006-01-31 18:14:25 +0000 | [diff] [blame] | 3790 | if (isCustom) { |
| 3791 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3792 | if (Tmp1.getNode()) Result = Tmp1; |
Evan Cheng | 59ad781 | 2006-01-31 18:14:25 +0000 | [diff] [blame] | 3793 | } |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3794 | break; |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3795 | case TargetLowering::Expand: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3796 | switch (Node->getOpcode()) { |
| 3797 | default: assert(0 && "Unreachable!"); |
| 3798 | case ISD::FNEG: |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3799 | // Expand Y = FNEG(X) -> Y = SUB -0.0, X |
| 3800 | Tmp2 = DAG.getConstantFP(-0.0, Node->getValueType(0)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3801 | Result = DAG.getNode(ISD::FSUB, Node->getValueType(0), Tmp2, Tmp1); |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 3802 | break; |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 3803 | case ISD::FABS: { |
Chris Lattner | 4af6e0d | 2005-04-02 05:26:37 +0000 | [diff] [blame] | 3804 | // Expand Y = FABS(X) -> Y = (X >u 0.0) ? X : fneg(X). |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3805 | MVT VT = Node->getValueType(0); |
Chris Lattner | 4af6e0d | 2005-04-02 05:26:37 +0000 | [diff] [blame] | 3806 | Tmp2 = DAG.getConstantFP(0.0, VT); |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 3807 | Tmp2 = DAG.getSetCC(TLI.getSetCCResultType(Tmp1.getValueType()), |
| 3808 | Tmp1, Tmp2, ISD::SETUGT); |
Chris Lattner | 4af6e0d | 2005-04-02 05:26:37 +0000 | [diff] [blame] | 3809 | Tmp3 = DAG.getNode(ISD::FNEG, VT, Tmp1); |
| 3810 | Result = DAG.getNode(ISD::SELECT, VT, Tmp2, Tmp1, Tmp3); |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 3811 | break; |
| 3812 | } |
Evan Cheng | 9d24ac5 | 2008-09-09 23:35:53 +0000 | [diff] [blame] | 3813 | case ISD::FSQRT: |
| 3814 | case ISD::FSIN: |
| 3815 | case ISD::FCOS: |
Dale Johannesen | 7794f2a | 2008-09-04 00:47:13 +0000 | [diff] [blame] | 3816 | case ISD::FLOG: |
| 3817 | case ISD::FLOG2: |
| 3818 | case ISD::FLOG10: |
| 3819 | case ISD::FEXP: |
| 3820 | case ISD::FEXP2: |
Dan Gohman | 2bb1e3e | 2008-08-21 18:38:14 +0000 | [diff] [blame] | 3821 | case ISD::FTRUNC: |
| 3822 | case ISD::FFLOOR: |
| 3823 | case ISD::FCEIL: |
| 3824 | case ISD::FRINT: |
Evan Cheng | 9d24ac5 | 2008-09-09 23:35:53 +0000 | [diff] [blame] | 3825 | case ISD::FNEARBYINT: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3826 | MVT VT = Node->getValueType(0); |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3827 | |
| 3828 | // Expand unsupported unary vector operators by unrolling them. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3829 | if (VT.isVector()) { |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3830 | Result = LegalizeOp(UnrollVectorOp(Op)); |
| 3831 | break; |
| 3832 | } |
| 3833 | |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3834 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 3835 | switch(Node->getOpcode()) { |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3836 | case ISD::FSQRT: |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 3837 | LC = GetFPLibCall(VT, RTLIB::SQRT_F32, RTLIB::SQRT_F64, |
| 3838 | RTLIB::SQRT_F80, RTLIB::SQRT_PPCF128); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3839 | break; |
| 3840 | case ISD::FSIN: |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 3841 | LC = GetFPLibCall(VT, RTLIB::SIN_F32, RTLIB::SIN_F64, |
| 3842 | RTLIB::SIN_F80, RTLIB::SIN_PPCF128); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3843 | break; |
| 3844 | case ISD::FCOS: |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 3845 | LC = GetFPLibCall(VT, RTLIB::COS_F32, RTLIB::COS_F64, |
| 3846 | RTLIB::COS_F80, RTLIB::COS_PPCF128); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3847 | break; |
Dale Johannesen | 7794f2a | 2008-09-04 00:47:13 +0000 | [diff] [blame] | 3848 | case ISD::FLOG: |
| 3849 | LC = GetFPLibCall(VT, RTLIB::LOG_F32, RTLIB::LOG_F64, |
| 3850 | RTLIB::LOG_F80, RTLIB::LOG_PPCF128); |
| 3851 | break; |
| 3852 | case ISD::FLOG2: |
| 3853 | LC = GetFPLibCall(VT, RTLIB::LOG2_F32, RTLIB::LOG2_F64, |
| 3854 | RTLIB::LOG2_F80, RTLIB::LOG2_PPCF128); |
| 3855 | break; |
| 3856 | case ISD::FLOG10: |
| 3857 | LC = GetFPLibCall(VT, RTLIB::LOG10_F32, RTLIB::LOG10_F64, |
| 3858 | RTLIB::LOG10_F80, RTLIB::LOG10_PPCF128); |
| 3859 | break; |
| 3860 | case ISD::FEXP: |
| 3861 | LC = GetFPLibCall(VT, RTLIB::EXP_F32, RTLIB::EXP_F64, |
| 3862 | RTLIB::EXP_F80, RTLIB::EXP_PPCF128); |
| 3863 | break; |
| 3864 | case ISD::FEXP2: |
| 3865 | LC = GetFPLibCall(VT, RTLIB::EXP2_F32, RTLIB::EXP2_F64, |
| 3866 | RTLIB::EXP2_F80, RTLIB::EXP2_PPCF128); |
| 3867 | break; |
Dan Gohman | 2bb1e3e | 2008-08-21 18:38:14 +0000 | [diff] [blame] | 3868 | case ISD::FTRUNC: |
| 3869 | LC = GetFPLibCall(VT, RTLIB::TRUNC_F32, RTLIB::TRUNC_F64, |
| 3870 | RTLIB::TRUNC_F80, RTLIB::TRUNC_PPCF128); |
| 3871 | break; |
| 3872 | case ISD::FFLOOR: |
| 3873 | LC = GetFPLibCall(VT, RTLIB::FLOOR_F32, RTLIB::FLOOR_F64, |
| 3874 | RTLIB::FLOOR_F80, RTLIB::FLOOR_PPCF128); |
| 3875 | break; |
| 3876 | case ISD::FCEIL: |
| 3877 | LC = GetFPLibCall(VT, RTLIB::CEIL_F32, RTLIB::CEIL_F64, |
| 3878 | RTLIB::CEIL_F80, RTLIB::CEIL_PPCF128); |
| 3879 | break; |
| 3880 | case ISD::FRINT: |
| 3881 | LC = GetFPLibCall(VT, RTLIB::RINT_F32, RTLIB::RINT_F64, |
| 3882 | RTLIB::RINT_F80, RTLIB::RINT_PPCF128); |
| 3883 | break; |
| 3884 | case ISD::FNEARBYINT: |
| 3885 | LC = GetFPLibCall(VT, RTLIB::NEARBYINT_F32, RTLIB::NEARBYINT_F64, |
| 3886 | RTLIB::NEARBYINT_F80, RTLIB::NEARBYINT_PPCF128); |
| 3887 | break; |
Evan Cheng | 9d24ac5 | 2008-09-09 23:35:53 +0000 | [diff] [blame] | 3888 | break; |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 3889 | default: assert(0 && "Unreachable!"); |
| 3890 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3891 | SDValue Dummy; |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 3892 | Result = ExpandLibCall(LC, Node, false/*sign irrelevant*/, Dummy); |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 3893 | break; |
| 3894 | } |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3895 | } |
| 3896 | break; |
| 3897 | } |
| 3898 | break; |
Chris Lattner | 6ddf8ed | 2006-09-09 06:03:30 +0000 | [diff] [blame] | 3899 | case ISD::FPOWI: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3900 | MVT VT = Node->getValueType(0); |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3901 | |
| 3902 | // Expand unsupported unary vector operators by unrolling them. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3903 | if (VT.isVector()) { |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3904 | Result = LegalizeOp(UnrollVectorOp(Op)); |
| 3905 | break; |
| 3906 | } |
| 3907 | |
| 3908 | // 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] | 3909 | RTLIB::Libcall LC = GetFPLibCall(VT, RTLIB::POWI_F32, RTLIB::POWI_F64, |
| 3910 | RTLIB::POWI_F80, RTLIB::POWI_PPCF128); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3911 | SDValue Dummy; |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 3912 | Result = ExpandLibCall(LC, Node, false/*sign irrelevant*/, Dummy); |
Chris Lattner | 6ddf8ed | 2006-09-09 06:03:30 +0000 | [diff] [blame] | 3913 | break; |
| 3914 | } |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 3915 | case ISD::BIT_CONVERT: |
Chris Lattner | 67993f7 | 2006-01-23 07:30:46 +0000 | [diff] [blame] | 3916 | if (!isTypeLegal(Node->getOperand(0).getValueType())) { |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 3917 | Result = EmitStackConvert(Node->getOperand(0), Node->getValueType(0), |
| 3918 | Node->getValueType(0)); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3919 | } else if (Op.getOperand(0).getValueType().isVector()) { |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3920 | // The input has to be a vector type, we have to either scalarize it, pack |
| 3921 | // 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] | 3922 | SDNode *InVal = Node->getOperand(0).getNode(); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 3923 | int InIx = Node->getOperand(0).getResNo(); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3924 | unsigned NumElems = InVal->getValueType(InIx).getVectorNumElements(); |
| 3925 | MVT EVT = InVal->getValueType(InIx).getVectorElementType(); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3926 | |
| 3927 | // Figure out if there is a simple type corresponding to this Vector |
| 3928 | // type. If so, convert to the vector type. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3929 | MVT TVT = MVT::getVectorVT(EVT, NumElems); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3930 | if (TLI.isTypeLegal(TVT)) { |
Dan Gohman | 07a9676 | 2007-07-16 14:29:03 +0000 | [diff] [blame] | 3931 | // Turn this into a bit convert of the vector input. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3932 | Result = DAG.getNode(ISD::BIT_CONVERT, Node->getValueType(0), |
| 3933 | LegalizeOp(Node->getOperand(0))); |
| 3934 | break; |
| 3935 | } else if (NumElems == 1) { |
| 3936 | // Turn this into a bit convert of the scalar input. |
| 3937 | Result = DAG.getNode(ISD::BIT_CONVERT, Node->getValueType(0), |
| 3938 | ScalarizeVectorOp(Node->getOperand(0))); |
| 3939 | break; |
| 3940 | } else { |
| 3941 | // FIXME: UNIMP! Store then reload |
| 3942 | assert(0 && "Cast from unsupported vector type not implemented yet!"); |
| 3943 | } |
Chris Lattner | 67993f7 | 2006-01-23 07:30:46 +0000 | [diff] [blame] | 3944 | } else { |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 3945 | switch (TLI.getOperationAction(ISD::BIT_CONVERT, |
| 3946 | Node->getOperand(0).getValueType())) { |
| 3947 | default: assert(0 && "Unknown operation action!"); |
| 3948 | case TargetLowering::Expand: |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 3949 | Result = EmitStackConvert(Node->getOperand(0), Node->getValueType(0), |
| 3950 | Node->getValueType(0)); |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 3951 | break; |
| 3952 | case TargetLowering::Legal: |
| 3953 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3954 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 3955 | break; |
| 3956 | } |
| 3957 | } |
| 3958 | break; |
Mon P Wang | 77cdf30 | 2008-11-10 20:54:11 +0000 | [diff] [blame] | 3959 | case ISD::CONVERT_RNDSAT: { |
| 3960 | ISD::CvtCode CvtCode = cast<CvtRndSatSDNode>(Node)->getCvtCode(); |
| 3961 | switch (CvtCode) { |
| 3962 | default: assert(0 && "Unknown cvt code!"); |
| 3963 | case ISD::CVT_SF: |
| 3964 | case ISD::CVT_UF: |
Mon P Wang | 77cdf30 | 2008-11-10 20:54:11 +0000 | [diff] [blame] | 3965 | case ISD::CVT_FF: |
Mon P Wang | 1cd46bb | 2008-12-09 07:27:39 +0000 | [diff] [blame] | 3966 | break; |
Mon P Wang | 77cdf30 | 2008-11-10 20:54:11 +0000 | [diff] [blame] | 3967 | case ISD::CVT_FS: |
| 3968 | case ISD::CVT_FU: |
| 3969 | case ISD::CVT_SS: |
| 3970 | case ISD::CVT_SU: |
| 3971 | case ISD::CVT_US: |
| 3972 | case ISD::CVT_UU: { |
| 3973 | SDValue DTyOp = Node->getOperand(1); |
| 3974 | SDValue STyOp = Node->getOperand(2); |
| 3975 | SDValue RndOp = Node->getOperand(3); |
| 3976 | SDValue SatOp = Node->getOperand(4); |
| 3977 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3978 | case Expand: assert(0 && "Shouldn't need to expand other operators here!"); |
| 3979 | case Legal: |
| 3980 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 3981 | Result = DAG.UpdateNodeOperands(Result, Tmp1, DTyOp, STyOp, |
| 3982 | RndOp, SatOp); |
| 3983 | if (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0)) == |
| 3984 | TargetLowering::Custom) { |
| 3985 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 3986 | if (Tmp1.getNode()) Result = Tmp1; |
| 3987 | } |
| 3988 | break; |
| 3989 | case Promote: |
| 3990 | Result = PromoteOp(Node->getOperand(0)); |
| 3991 | // For FP, make Op1 a i32 |
| 3992 | |
Mon P Wang | 1cd46bb | 2008-12-09 07:27:39 +0000 | [diff] [blame] | 3993 | Result = DAG.getConvertRndSat(Op.getValueType(), Result, |
Mon P Wang | 77cdf30 | 2008-11-10 20:54:11 +0000 | [diff] [blame] | 3994 | DTyOp, STyOp, RndOp, SatOp, CvtCode); |
| 3995 | break; |
| 3996 | } |
| 3997 | break; |
| 3998 | } |
| 3999 | } // end switch CvtCode |
| 4000 | break; |
| 4001 | } |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 4002 | // Conversion operators. The source and destination have different types. |
Chris Lattner | ae0aacb | 2005-01-08 08:08:56 +0000 | [diff] [blame] | 4003 | case ISD::SINT_TO_FP: |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 4004 | case ISD::UINT_TO_FP: { |
| 4005 | bool isSigned = Node->getOpcode() == ISD::SINT_TO_FP; |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 4006 | Result = LegalizeINT_TO_FP(Result, isSigned, |
| 4007 | Node->getValueType(0), Node->getOperand(0)); |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 4008 | break; |
| 4009 | } |
| 4010 | case ISD::TRUNCATE: |
| 4011 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 4012 | case Legal: |
| 4013 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Scott Michel | 546d7b5 | 2008-12-02 19:55:08 +0000 | [diff] [blame] | 4014 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 4015 | default: assert(0 && "Unknown TRUNCATE legalization operation action!"); |
| 4016 | case TargetLowering::Custom: |
Mon P Wang | f67303d | 2008-12-11 00:44:22 +0000 | [diff] [blame] | 4017 | isCustom = true; |
| 4018 | // FALLTHROUGH |
Scott Michel | 546d7b5 | 2008-12-02 19:55:08 +0000 | [diff] [blame] | 4019 | case TargetLowering::Legal: |
Mon P Wang | f67303d | 2008-12-11 00:44:22 +0000 | [diff] [blame] | 4020 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 4021 | if (isCustom) { |
| 4022 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 4023 | if (Tmp1.getNode()) Result = Tmp1; |
| 4024 | } |
| 4025 | break; |
Mon P Wang | 9e5ecb8 | 2008-12-12 01:25:51 +0000 | [diff] [blame] | 4026 | case TargetLowering::Expand: |
| 4027 | assert(Result.getValueType().isVector() && "must be vector type"); |
| 4028 | // Unroll the truncate. We should do better. |
| 4029 | Result = LegalizeOp(UnrollVectorOp(Result)); |
Tilmann Scheller | b0a5cdd | 2008-12-02 12:12:25 +0000 | [diff] [blame] | 4030 | } |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 4031 | break; |
| 4032 | case Expand: |
| 4033 | ExpandOp(Node->getOperand(0), Tmp1, Tmp2); |
| 4034 | |
| 4035 | // Since the result is legal, we should just be able to truncate the low |
| 4036 | // part of the source. |
| 4037 | Result = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0), Tmp1); |
| 4038 | break; |
| 4039 | case Promote: |
| 4040 | Result = PromoteOp(Node->getOperand(0)); |
| 4041 | Result = DAG.getNode(ISD::TRUNCATE, Op.getValueType(), Result); |
| 4042 | break; |
| 4043 | } |
| 4044 | break; |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 4045 | |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 4046 | case ISD::FP_TO_SINT: |
| 4047 | case ISD::FP_TO_UINT: |
| 4048 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 4049 | case Legal: |
Chris Lattner | f1fa74e | 2005-07-30 00:04:12 +0000 | [diff] [blame] | 4050 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 4051 | |
Chris Lattner | 1618beb | 2005-07-29 00:11:56 +0000 | [diff] [blame] | 4052 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))){ |
| 4053 | default: assert(0 && "Unknown operation action!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4054 | case TargetLowering::Custom: |
| 4055 | isCustom = true; |
| 4056 | // FALLTHROUGH |
| 4057 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 4058 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4059 | if (isCustom) { |
| 4060 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 4061 | if (Tmp1.getNode()) Result = Tmp1; |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4062 | } |
| 4063 | break; |
| 4064 | case TargetLowering::Promote: |
| 4065 | Result = PromoteLegalFP_TO_INT(Tmp1, Node->getValueType(0), |
| 4066 | Node->getOpcode() == ISD::FP_TO_SINT); |
| 4067 | break; |
Chris Lattner | 1618beb | 2005-07-29 00:11:56 +0000 | [diff] [blame] | 4068 | case TargetLowering::Expand: |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 4069 | if (Node->getOpcode() == ISD::FP_TO_UINT) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4070 | SDValue True, False; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4071 | MVT VT = Node->getOperand(0).getValueType(); |
| 4072 | MVT NVT = Node->getValueType(0); |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 4073 | const uint64_t zero[] = {0, 0}; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4074 | APFloat apf = APFloat(APInt(VT.getSizeInBits(), 2, zero)); |
| 4075 | APInt x = APInt::getSignBit(NVT.getSizeInBits()); |
Dan Gohman | c7773bf | 2008-02-29 01:44:25 +0000 | [diff] [blame] | 4076 | (void)apf.convertFromAPInt(x, false, APFloat::rmNearestTiesToEven); |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 4077 | Tmp2 = DAG.getConstantFP(apf, VT); |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 4078 | Tmp3 = DAG.getSetCC(TLI.getSetCCResultType(VT), Node->getOperand(0), |
| 4079 | Tmp2, ISD::SETLT); |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 4080 | True = DAG.getNode(ISD::FP_TO_SINT, NVT, Node->getOperand(0)); |
| 4081 | False = DAG.getNode(ISD::FP_TO_SINT, NVT, |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 4082 | DAG.getNode(ISD::FSUB, VT, Node->getOperand(0), |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 4083 | Tmp2)); |
| 4084 | False = DAG.getNode(ISD::XOR, NVT, False, |
Dan Gohman | c7773bf | 2008-02-29 01:44:25 +0000 | [diff] [blame] | 4085 | DAG.getConstant(x, NVT)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4086 | Result = DAG.getNode(ISD::SELECT, NVT, Tmp3, True, False); |
| 4087 | break; |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 4088 | } else { |
| 4089 | assert(0 && "Do not know how to expand FP_TO_SINT yet!"); |
| 4090 | } |
| 4091 | break; |
Chris Lattner | 07dffd6 | 2005-08-26 00:14:16 +0000 | [diff] [blame] | 4092 | } |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 4093 | break; |
Evan Cheng | 6af00d5 | 2006-12-13 01:57:55 +0000 | [diff] [blame] | 4094 | case Expand: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4095 | MVT VT = Op.getValueType(); |
| 4096 | MVT OVT = Node->getOperand(0).getValueType(); |
Dale Johannesen | fcf4d24 | 2007-10-11 23:32:15 +0000 | [diff] [blame] | 4097 | // Convert ppcf128 to i32 |
Dale Johannesen | 6eaeff2 | 2007-10-10 01:01:31 +0000 | [diff] [blame] | 4098 | if (OVT == MVT::ppcf128 && VT == MVT::i32) { |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4099 | if (Node->getOpcode() == ISD::FP_TO_SINT) { |
| 4100 | Result = DAG.getNode(ISD::FP_ROUND_INREG, MVT::ppcf128, |
| 4101 | Node->getOperand(0), DAG.getValueType(MVT::f64)); |
| 4102 | Result = DAG.getNode(ISD::FP_ROUND, MVT::f64, Result, |
| 4103 | DAG.getIntPtrConstant(1)); |
| 4104 | Result = DAG.getNode(ISD::FP_TO_SINT, VT, Result); |
| 4105 | } else { |
Dale Johannesen | fcf4d24 | 2007-10-11 23:32:15 +0000 | [diff] [blame] | 4106 | const uint64_t TwoE31[] = {0x41e0000000000000LL, 0}; |
| 4107 | APFloat apf = APFloat(APInt(128, 2, TwoE31)); |
| 4108 | Tmp2 = DAG.getConstantFP(apf, OVT); |
| 4109 | // X>=2^31 ? (int)(X-2^31)+0x80000000 : (int)X |
| 4110 | // FIXME: generated code sucks. |
| 4111 | Result = DAG.getNode(ISD::SELECT_CC, VT, Node->getOperand(0), Tmp2, |
| 4112 | DAG.getNode(ISD::ADD, MVT::i32, |
| 4113 | DAG.getNode(ISD::FP_TO_SINT, VT, |
| 4114 | DAG.getNode(ISD::FSUB, OVT, |
| 4115 | Node->getOperand(0), Tmp2)), |
| 4116 | DAG.getConstant(0x80000000, MVT::i32)), |
| 4117 | DAG.getNode(ISD::FP_TO_SINT, VT, |
| 4118 | Node->getOperand(0)), |
| 4119 | DAG.getCondCode(ISD::SETGE)); |
| 4120 | } |
Dale Johannesen | 6eaeff2 | 2007-10-10 01:01:31 +0000 | [diff] [blame] | 4121 | break; |
| 4122 | } |
Dan Gohman | a2e9485 | 2008-03-10 23:03:31 +0000 | [diff] [blame] | 4123 | // Convert f32 / f64 to i32 / i64 / i128. |
Duncan Sands | b2ff885 | 2008-07-17 02:36:29 +0000 | [diff] [blame] | 4124 | RTLIB::Libcall LC = (Node->getOpcode() == ISD::FP_TO_SINT) ? |
| 4125 | RTLIB::getFPTOSINT(OVT, VT) : RTLIB::getFPTOUINT(OVT, VT); |
| 4126 | assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unexpectd fp-to-int conversion!"); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4127 | SDValue Dummy; |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 4128 | Result = ExpandLibCall(LC, Node, false/*sign irrelevant*/, Dummy); |
Evan Cheng | 6af00d5 | 2006-12-13 01:57:55 +0000 | [diff] [blame] | 4129 | break; |
| 4130 | } |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 4131 | case Promote: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 4132 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4133 | Result = DAG.UpdateNodeOperands(Result, LegalizeOp(Tmp1)); |
| 4134 | Result = LegalizeOp(Result); |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 4135 | break; |
| 4136 | } |
| 4137 | break; |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 4138 | |
Chris Lattner | f2670a8 | 2008-01-16 06:57:07 +0000 | [diff] [blame] | 4139 | case ISD::FP_EXTEND: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4140 | MVT DstVT = Op.getValueType(); |
| 4141 | MVT SrcVT = Op.getOperand(0).getValueType(); |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4142 | if (TLI.getConvertAction(SrcVT, DstVT) == TargetLowering::Expand) { |
| 4143 | // The only other way we can lower this is to turn it into a STORE, |
| 4144 | // LOAD pair, targetting a temporary location (a stack slot). |
| 4145 | Result = EmitStackConvert(Node->getOperand(0), SrcVT, DstVT); |
| 4146 | break; |
Chris Lattner | f2670a8 | 2008-01-16 06:57:07 +0000 | [diff] [blame] | 4147 | } |
| 4148 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 4149 | case Expand: assert(0 && "Shouldn't need to expand other operators here!"); |
| 4150 | case Legal: |
| 4151 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 4152 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 4153 | break; |
| 4154 | case Promote: |
| 4155 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4156 | Result = DAG.getNode(ISD::FP_EXTEND, Op.getValueType(), Tmp1); |
| 4157 | break; |
| 4158 | } |
| 4159 | break; |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4160 | } |
Dale Johannesen | 5411a39 | 2007-08-09 01:04:01 +0000 | [diff] [blame] | 4161 | case ISD::FP_ROUND: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4162 | MVT DstVT = Op.getValueType(); |
| 4163 | MVT SrcVT = Op.getOperand(0).getValueType(); |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4164 | if (TLI.getConvertAction(SrcVT, DstVT) == TargetLowering::Expand) { |
| 4165 | if (SrcVT == MVT::ppcf128) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4166 | SDValue Lo; |
Dale Johannesen | 713ed3f | 2008-01-20 01:18:38 +0000 | [diff] [blame] | 4167 | ExpandOp(Node->getOperand(0), Lo, Result); |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4168 | // 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] | 4169 | if (DstVT!=MVT::f64) |
| 4170 | Result = DAG.getNode(ISD::FP_ROUND, DstVT, Result, Op.getOperand(1)); |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4171 | break; |
Dale Johannesen | 5411a39 | 2007-08-09 01:04:01 +0000 | [diff] [blame] | 4172 | } |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4173 | // The only other way we can lower this is to turn it into a STORE, |
| 4174 | // LOAD pair, targetting a temporary location (a stack slot). |
| 4175 | Result = EmitStackConvert(Node->getOperand(0), DstVT, DstVT); |
| 4176 | break; |
Dale Johannesen | 849f214 | 2007-07-03 00:53:03 +0000 | [diff] [blame] | 4177 | } |
Chris Lattner | f2670a8 | 2008-01-16 06:57:07 +0000 | [diff] [blame] | 4178 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 4179 | case Expand: assert(0 && "Shouldn't need to expand other operators here!"); |
| 4180 | case Legal: |
| 4181 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4182 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
Chris Lattner | f2670a8 | 2008-01-16 06:57:07 +0000 | [diff] [blame] | 4183 | break; |
| 4184 | case Promote: |
| 4185 | Tmp1 = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4186 | Result = DAG.getNode(ISD::FP_ROUND, Op.getValueType(), Tmp1, |
| 4187 | Node->getOperand(1)); |
Chris Lattner | f2670a8 | 2008-01-16 06:57:07 +0000 | [diff] [blame] | 4188 | break; |
| 4189 | } |
| 4190 | break; |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4191 | } |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 4192 | case ISD::ANY_EXTEND: |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 4193 | case ISD::ZERO_EXTEND: |
| 4194 | case ISD::SIGN_EXTEND: |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 4195 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4196 | case Expand: assert(0 && "Shouldn't need to expand other operators here!"); |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 4197 | case Legal: |
| 4198 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Scott Michel | 82747a5 | 2008-04-30 00:26:38 +0000 | [diff] [blame] | 4199 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Scott Michel | 0123b7d | 2008-02-15 23:05:48 +0000 | [diff] [blame] | 4200 | if (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0)) == |
| 4201 | TargetLowering::Custom) { |
Scott Michel | 82747a5 | 2008-04-30 00:26:38 +0000 | [diff] [blame] | 4202 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 4203 | if (Tmp1.getNode()) Result = Tmp1; |
Scott Michel | 0123b7d | 2008-02-15 23:05:48 +0000 | [diff] [blame] | 4204 | } |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 4205 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4206 | case Promote: |
| 4207 | switch (Node->getOpcode()) { |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 4208 | case ISD::ANY_EXTEND: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 4209 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4210 | Result = DAG.getNode(ISD::ANY_EXTEND, Op.getValueType(), Tmp1); |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 4211 | break; |
Chris Lattner | 1713e73 | 2005-01-16 00:38:00 +0000 | [diff] [blame] | 4212 | case ISD::ZERO_EXTEND: |
| 4213 | Result = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 4214 | Result = DAG.getNode(ISD::ANY_EXTEND, Op.getValueType(), Result); |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 4215 | Result = DAG.getZeroExtendInReg(Result, |
| 4216 | Node->getOperand(0).getValueType()); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4217 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4218 | case ISD::SIGN_EXTEND: |
Chris Lattner | 1713e73 | 2005-01-16 00:38:00 +0000 | [diff] [blame] | 4219 | Result = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 4220 | Result = DAG.getNode(ISD::ANY_EXTEND, Op.getValueType(), Result); |
Chris Lattner | 1713e73 | 2005-01-16 00:38:00 +0000 | [diff] [blame] | 4221 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(), |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 4222 | Result, |
| 4223 | DAG.getValueType(Node->getOperand(0).getValueType())); |
Chris Lattner | 1713e73 | 2005-01-16 00:38:00 +0000 | [diff] [blame] | 4224 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4225 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 4226 | } |
| 4227 | break; |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 4228 | case ISD::FP_ROUND_INREG: |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 4229 | case ISD::SIGN_EXTEND_INREG: { |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 4230 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4231 | MVT ExtraVT = cast<VTSDNode>(Node->getOperand(1))->getVT(); |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 4232 | |
| 4233 | // If this operation is not supported, convert it to a shl/shr or load/store |
| 4234 | // pair. |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 4235 | switch (TLI.getOperationAction(Node->getOpcode(), ExtraVT)) { |
| 4236 | default: assert(0 && "This action not supported for this op yet!"); |
| 4237 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 4238 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 4239 | break; |
| 4240 | case TargetLowering::Expand: |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 4241 | // If this is an integer extend and shifts are supported, do that. |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 4242 | if (Node->getOpcode() == ISD::SIGN_EXTEND_INREG) { |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 4243 | // NOTE: we could fall back on load/store here too for targets without |
| 4244 | // SAR. However, it is doubtful that any exist. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4245 | unsigned BitsDiff = Node->getValueType(0).getSizeInBits() - |
| 4246 | ExtraVT.getSizeInBits(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4247 | SDValue ShiftCst = DAG.getConstant(BitsDiff, TLI.getShiftAmountTy()); |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 4248 | Result = DAG.getNode(ISD::SHL, Node->getValueType(0), |
| 4249 | Node->getOperand(0), ShiftCst); |
| 4250 | Result = DAG.getNode(ISD::SRA, Node->getValueType(0), |
| 4251 | Result, ShiftCst); |
| 4252 | } else if (Node->getOpcode() == ISD::FP_ROUND_INREG) { |
Jim Laskey | 2d84c4c | 2006-10-11 17:52:19 +0000 | [diff] [blame] | 4253 | // 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] | 4254 | // EXTLOAD pair, targetting a temporary location (a stack slot). |
| 4255 | |
| 4256 | // NOTE: there is a choice here between constantly creating new stack |
| 4257 | // slots and always reusing the same one. We currently always create |
| 4258 | // new ones, as reuse may inhibit scheduling. |
Chris Lattner | a66bb39 | 2008-01-16 07:51:34 +0000 | [diff] [blame] | 4259 | Result = EmitStackConvert(Node->getOperand(0), ExtraVT, |
| 4260 | Node->getValueType(0)); |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 4261 | } else { |
| 4262 | assert(0 && "Unknown op"); |
| 4263 | } |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 4264 | break; |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 4265 | } |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 4266 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 4267 | } |
Duncan Sands | 36397f5 | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 4268 | case ISD::TRAMPOLINE: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4269 | SDValue Ops[6]; |
Duncan Sands | 36397f5 | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 4270 | for (unsigned i = 0; i != 6; ++i) |
| 4271 | Ops[i] = LegalizeOp(Node->getOperand(i)); |
| 4272 | Result = DAG.UpdateNodeOperands(Result, Ops, 6); |
| 4273 | // The only option for this node is to custom lower it. |
| 4274 | Result = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 4275 | assert(Result.getNode() && "Should always custom lower!"); |
Duncan Sands | f7331b3 | 2007-09-11 14:10:23 +0000 | [diff] [blame] | 4276 | |
| 4277 | // Since trampoline produces two values, make sure to remember that we |
| 4278 | // legalized both of them. |
| 4279 | Tmp1 = LegalizeOp(Result.getValue(1)); |
| 4280 | Result = LegalizeOp(Result); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4281 | AddLegalizedOperand(SDValue(Node, 0), Result); |
| 4282 | AddLegalizedOperand(SDValue(Node, 1), Tmp1); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 4283 | return Op.getResNo() ? Tmp1 : Result; |
Duncan Sands | 36397f5 | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 4284 | } |
Dan Gohman | 9c78a39 | 2008-05-14 00:43:10 +0000 | [diff] [blame] | 4285 | case ISD::FLT_ROUNDS_: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4286 | MVT VT = Node->getValueType(0); |
Anton Korobeynikov | 917c2a6 | 2007-11-15 23:25:33 +0000 | [diff] [blame] | 4287 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 4288 | default: assert(0 && "This action not supported for this op yet!"); |
| 4289 | case TargetLowering::Custom: |
| 4290 | Result = TLI.LowerOperation(Op, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 4291 | if (Result.getNode()) break; |
Anton Korobeynikov | 917c2a6 | 2007-11-15 23:25:33 +0000 | [diff] [blame] | 4292 | // Fall Thru |
| 4293 | case TargetLowering::Legal: |
| 4294 | // If this operation is not supported, lower it to constant 1 |
| 4295 | Result = DAG.getConstant(1, VT); |
| 4296 | break; |
| 4297 | } |
Dan Gohman | 9ab9ee8 | 2008-05-12 16:07:15 +0000 | [diff] [blame] | 4298 | break; |
Anton Korobeynikov | 917c2a6 | 2007-11-15 23:25:33 +0000 | [diff] [blame] | 4299 | } |
Chris Lattner | 41bab0b | 2008-01-15 21:58:08 +0000 | [diff] [blame] | 4300 | case ISD::TRAP: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4301 | MVT VT = Node->getValueType(0); |
Anton Korobeynikov | 66fac79 | 2008-01-15 07:02:33 +0000 | [diff] [blame] | 4302 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 4303 | default: assert(0 && "This action not supported for this op yet!"); |
Chris Lattner | 41bab0b | 2008-01-15 21:58:08 +0000 | [diff] [blame] | 4304 | case TargetLowering::Legal: |
| 4305 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 4306 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 4307 | break; |
Anton Korobeynikov | 66fac79 | 2008-01-15 07:02:33 +0000 | [diff] [blame] | 4308 | case TargetLowering::Custom: |
| 4309 | Result = TLI.LowerOperation(Op, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 4310 | if (Result.getNode()) break; |
Anton Korobeynikov | 66fac79 | 2008-01-15 07:02:33 +0000 | [diff] [blame] | 4311 | // Fall Thru |
Chris Lattner | 41bab0b | 2008-01-15 21:58:08 +0000 | [diff] [blame] | 4312 | case TargetLowering::Expand: |
Anton Korobeynikov | 66fac79 | 2008-01-15 07:02:33 +0000 | [diff] [blame] | 4313 | // If this operation is not supported, lower it to 'abort()' call |
Chris Lattner | 41bab0b | 2008-01-15 21:58:08 +0000 | [diff] [blame] | 4314 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Anton Korobeynikov | 66fac79 | 2008-01-15 07:02:33 +0000 | [diff] [blame] | 4315 | TargetLowering::ArgListTy Args; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4316 | std::pair<SDValue,SDValue> CallResult = |
Duncan Sands | 00fee65 | 2008-02-14 17:28:50 +0000 | [diff] [blame] | 4317 | TLI.LowerCallTo(Tmp1, Type::VoidTy, |
Dale Johannesen | 86098bd | 2008-09-26 19:31:26 +0000 | [diff] [blame] | 4318 | false, false, false, false, CallingConv::C, false, |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 4319 | DAG.getExternalSymbol("abort", TLI.getPointerTy()), |
Dale Johannesen | 7d2ad62 | 2009-01-30 23:10:59 +0000 | [diff] [blame] | 4320 | Args, DAG, dl); |
Anton Korobeynikov | 66fac79 | 2008-01-15 07:02:33 +0000 | [diff] [blame] | 4321 | Result = CallResult.second; |
| 4322 | break; |
| 4323 | } |
Chris Lattner | 41bab0b | 2008-01-15 21:58:08 +0000 | [diff] [blame] | 4324 | break; |
Anton Korobeynikov | 66fac79 | 2008-01-15 07:02:33 +0000 | [diff] [blame] | 4325 | } |
Bill Wendling | 8ac0d4b | 2008-11-22 00:22:52 +0000 | [diff] [blame] | 4326 | |
Bill Wendling | 74c3765 | 2008-12-09 22:08:41 +0000 | [diff] [blame] | 4327 | case ISD::SADDO: |
| 4328 | case ISD::SSUBO: { |
Bill Wendling | c0062fb | 2008-11-25 08:12:19 +0000 | [diff] [blame] | 4329 | MVT VT = Node->getValueType(0); |
| 4330 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 4331 | default: assert(0 && "This action not supported for this op yet!"); |
| 4332 | case TargetLowering::Custom: |
| 4333 | Result = TLI.LowerOperation(Op, DAG); |
| 4334 | if (Result.getNode()) break; |
| 4335 | // FALLTHROUGH |
| 4336 | case TargetLowering::Legal: { |
| 4337 | SDValue LHS = LegalizeOp(Node->getOperand(0)); |
| 4338 | SDValue RHS = LegalizeOp(Node->getOperand(1)); |
| 4339 | |
Bill Wendling | 74c3765 | 2008-12-09 22:08:41 +0000 | [diff] [blame] | 4340 | SDValue Sum = DAG.getNode(Node->getOpcode() == ISD::SADDO ? |
| 4341 | ISD::ADD : ISD::SUB, LHS.getValueType(), |
| 4342 | LHS, RHS); |
Bill Wendling | c0062fb | 2008-11-25 08:12:19 +0000 | [diff] [blame] | 4343 | MVT OType = Node->getValueType(1); |
| 4344 | |
Bill Wendling | a6af91a | 2008-11-25 08:19:22 +0000 | [diff] [blame] | 4345 | SDValue Zero = DAG.getConstant(0, LHS.getValueType()); |
Bill Wendling | c0062fb | 2008-11-25 08:12:19 +0000 | [diff] [blame] | 4346 | |
Bill Wendling | 740464e | 2008-11-25 19:40:17 +0000 | [diff] [blame] | 4347 | // LHSSign -> LHS >= 0 |
| 4348 | // RHSSign -> RHS >= 0 |
| 4349 | // SumSign -> Sum >= 0 |
| 4350 | // |
Bill Wendling | 74c3765 | 2008-12-09 22:08:41 +0000 | [diff] [blame] | 4351 | // Add: |
Bill Wendling | 740464e | 2008-11-25 19:40:17 +0000 | [diff] [blame] | 4352 | // Overflow -> (LHSSign == RHSSign) && (LHSSign != SumSign) |
Bill Wendling | 74c3765 | 2008-12-09 22:08:41 +0000 | [diff] [blame] | 4353 | // Sub: |
| 4354 | // Overflow -> (LHSSign != RHSSign) && (LHSSign != SumSign) |
Bill Wendling | 740464e | 2008-11-25 19:40:17 +0000 | [diff] [blame] | 4355 | // |
| 4356 | SDValue LHSSign = DAG.getSetCC(OType, LHS, Zero, ISD::SETGE); |
| 4357 | SDValue RHSSign = DAG.getSetCC(OType, RHS, Zero, ISD::SETGE); |
Bill Wendling | 74c3765 | 2008-12-09 22:08:41 +0000 | [diff] [blame] | 4358 | SDValue SignsMatch = DAG.getSetCC(OType, LHSSign, RHSSign, |
| 4359 | Node->getOpcode() == ISD::SADDO ? |
| 4360 | ISD::SETEQ : ISD::SETNE); |
Bill Wendling | c0062fb | 2008-11-25 08:12:19 +0000 | [diff] [blame] | 4361 | |
Bill Wendling | 740464e | 2008-11-25 19:40:17 +0000 | [diff] [blame] | 4362 | SDValue SumSign = DAG.getSetCC(OType, Sum, Zero, ISD::SETGE); |
| 4363 | SDValue SumSignNE = DAG.getSetCC(OType, LHSSign, SumSign, ISD::SETNE); |
Bill Wendling | c0062fb | 2008-11-25 08:12:19 +0000 | [diff] [blame] | 4364 | |
Bill Wendling | 74c3765 | 2008-12-09 22:08:41 +0000 | [diff] [blame] | 4365 | SDValue Cmp = DAG.getNode(ISD::AND, OType, SignsMatch, SumSignNE); |
Bill Wendling | c0062fb | 2008-11-25 08:12:19 +0000 | [diff] [blame] | 4366 | |
| 4367 | MVT ValueVTs[] = { LHS.getValueType(), OType }; |
| 4368 | SDValue Ops[] = { Sum, Cmp }; |
| 4369 | |
Duncan Sands | aaffa05 | 2008-12-01 11:41:29 +0000 | [diff] [blame] | 4370 | Result = DAG.getNode(ISD::MERGE_VALUES, DAG.getVTList(&ValueVTs[0], 2), |
| 4371 | &Ops[0], 2); |
Bill Wendling | c0062fb | 2008-11-25 08:12:19 +0000 | [diff] [blame] | 4372 | SDNode *RNode = Result.getNode(); |
| 4373 | DAG.ReplaceAllUsesOfValueWith(SDValue(Node, 0), SDValue(RNode, 0)); |
| 4374 | DAG.ReplaceAllUsesOfValueWith(SDValue(Node, 1), SDValue(RNode, 1)); |
| 4375 | break; |
| 4376 | } |
| 4377 | } |
| 4378 | |
| 4379 | break; |
| 4380 | } |
Bill Wendling | 74c3765 | 2008-12-09 22:08:41 +0000 | [diff] [blame] | 4381 | case ISD::UADDO: |
| 4382 | case ISD::USUBO: { |
Bill Wendling | 41ea7e7 | 2008-11-24 19:21:46 +0000 | [diff] [blame] | 4383 | MVT VT = Node->getValueType(0); |
| 4384 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 4385 | default: assert(0 && "This action not supported for this op yet!"); |
| 4386 | case TargetLowering::Custom: |
| 4387 | Result = TLI.LowerOperation(Op, DAG); |
| 4388 | if (Result.getNode()) break; |
| 4389 | // FALLTHROUGH |
| 4390 | case TargetLowering::Legal: { |
| 4391 | SDValue LHS = LegalizeOp(Node->getOperand(0)); |
| 4392 | SDValue RHS = LegalizeOp(Node->getOperand(1)); |
Bill Wendling | 8ac0d4b | 2008-11-22 00:22:52 +0000 | [diff] [blame] | 4393 | |
Bill Wendling | 74c3765 | 2008-12-09 22:08:41 +0000 | [diff] [blame] | 4394 | SDValue Sum = DAG.getNode(Node->getOpcode() == ISD::UADDO ? |
| 4395 | ISD::ADD : ISD::SUB, LHS.getValueType(), |
| 4396 | LHS, RHS); |
Bill Wendling | 41ea7e7 | 2008-11-24 19:21:46 +0000 | [diff] [blame] | 4397 | MVT OType = Node->getValueType(1); |
Bill Wendling | 74c3765 | 2008-12-09 22:08:41 +0000 | [diff] [blame] | 4398 | SDValue Cmp = DAG.getSetCC(OType, Sum, LHS, |
| 4399 | Node->getOpcode () == ISD::UADDO ? |
| 4400 | ISD::SETULT : ISD::SETUGT); |
Bill Wendling | 8ac0d4b | 2008-11-22 00:22:52 +0000 | [diff] [blame] | 4401 | |
Bill Wendling | 41ea7e7 | 2008-11-24 19:21:46 +0000 | [diff] [blame] | 4402 | MVT ValueVTs[] = { LHS.getValueType(), OType }; |
| 4403 | SDValue Ops[] = { Sum, Cmp }; |
Bill Wendling | 8ac0d4b | 2008-11-22 00:22:52 +0000 | [diff] [blame] | 4404 | |
Duncan Sands | aaffa05 | 2008-12-01 11:41:29 +0000 | [diff] [blame] | 4405 | Result = DAG.getNode(ISD::MERGE_VALUES, DAG.getVTList(&ValueVTs[0], 2), |
| 4406 | &Ops[0], 2); |
Bill Wendling | 41ea7e7 | 2008-11-24 19:21:46 +0000 | [diff] [blame] | 4407 | SDNode *RNode = Result.getNode(); |
| 4408 | DAG.ReplaceAllUsesOfValueWith(SDValue(Node, 0), SDValue(RNode, 0)); |
| 4409 | DAG.ReplaceAllUsesOfValueWith(SDValue(Node, 1), SDValue(RNode, 1)); |
| 4410 | break; |
| 4411 | } |
| 4412 | } |
| 4413 | |
Bill Wendling | 8ac0d4b | 2008-11-22 00:22:52 +0000 | [diff] [blame] | 4414 | break; |
| 4415 | } |
Bill Wendling | 74c3765 | 2008-12-09 22:08:41 +0000 | [diff] [blame] | 4416 | case ISD::SMULO: |
| 4417 | case ISD::UMULO: { |
| 4418 | MVT VT = Node->getValueType(0); |
| 4419 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 4420 | default: assert(0 && "This action is not supported at all!"); |
| 4421 | case TargetLowering::Custom: |
| 4422 | Result = TLI.LowerOperation(Op, DAG); |
| 4423 | if (Result.getNode()) break; |
| 4424 | // Fall Thru |
| 4425 | case TargetLowering::Legal: |
| 4426 | // FIXME: According to Hacker's Delight, this can be implemented in |
| 4427 | // target independent lowering, but it would be inefficient, since it |
Bill Wendling | bc5e15e | 2008-12-10 02:01:32 +0000 | [diff] [blame] | 4428 | // requires a division + a branch. |
Bill Wendling | 74c3765 | 2008-12-09 22:08:41 +0000 | [diff] [blame] | 4429 | assert(0 && "Target independent lowering is not supported for SMULO/UMULO!"); |
| 4430 | break; |
| 4431 | } |
| 4432 | break; |
| 4433 | } |
| 4434 | |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 4435 | } |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4436 | |
Chris Lattner | 4ddd283 | 2006-04-08 04:13:17 +0000 | [diff] [blame] | 4437 | assert(Result.getValueType() == Op.getValueType() && |
| 4438 | "Bad legalization!"); |
| 4439 | |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4440 | // Make sure that the generated code is itself legal. |
| 4441 | if (Result != Op) |
| 4442 | Result = LegalizeOp(Result); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 4443 | |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 4444 | // Note that LegalizeOp may be reentered even from single-use nodes, which |
| 4445 | // means that we always must cache transformed nodes. |
| 4446 | AddLegalizedOperand(Op, Result); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 4447 | return Result; |
| 4448 | } |
| 4449 | |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4450 | /// PromoteOp - Given an operation that produces a value in an invalid type, |
| 4451 | /// promote it to compute the value into a larger type. The produced value will |
| 4452 | /// have the correct bits for the low portion of the register, but no guarantee |
| 4453 | /// 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] | 4454 | SDValue SelectionDAGLegalize::PromoteOp(SDValue Op) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4455 | MVT VT = Op.getValueType(); |
| 4456 | MVT NVT = TLI.getTypeToTransformTo(VT); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4457 | assert(getTypeAction(VT) == Promote && |
| 4458 | "Caller should expand or legalize operands that are not promotable!"); |
Duncan Sands | 8e4eb09 | 2008-06-08 20:54:56 +0000 | [diff] [blame] | 4459 | assert(NVT.bitsGT(VT) && NVT.isInteger() == VT.isInteger() && |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4460 | "Cannot promote to smaller type!"); |
| 4461 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4462 | SDValue Tmp1, Tmp2, Tmp3; |
| 4463 | SDValue Result; |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 4464 | SDNode *Node = Op.getNode(); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4465 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4466 | DenseMap<SDValue, SDValue>::iterator I = PromotedNodes.find(Op); |
Chris Lattner | 6fdcb25 | 2005-09-02 20:32:45 +0000 | [diff] [blame] | 4467 | if (I != PromotedNodes.end()) return I->second; |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 4468 | |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4469 | switch (Node->getOpcode()) { |
Chris Lattner | d5d0f9b | 2005-08-16 21:55:35 +0000 | [diff] [blame] | 4470 | case ISD::CopyFromReg: |
| 4471 | assert(0 && "CopyFromReg must be legal!"); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4472 | default: |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 4473 | #ifndef NDEBUG |
Dan Gohman | 3983358 | 2007-06-04 16:17:33 +0000 | [diff] [blame] | 4474 | cerr << "NODE: "; Node->dump(&DAG); cerr << "\n"; |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 4475 | #endif |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4476 | assert(0 && "Do not know how to promote this operator!"); |
| 4477 | abort(); |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 4478 | case ISD::UNDEF: |
| 4479 | Result = DAG.getNode(ISD::UNDEF, NVT); |
| 4480 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4481 | case ISD::Constant: |
Chris Lattner | ec176e3 | 2005-08-30 16:56:19 +0000 | [diff] [blame] | 4482 | if (VT != MVT::i1) |
| 4483 | Result = DAG.getNode(ISD::SIGN_EXTEND, NVT, Op); |
| 4484 | else |
| 4485 | Result = DAG.getNode(ISD::ZERO_EXTEND, NVT, Op); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4486 | assert(isa<ConstantSDNode>(Result) && "Didn't constant fold zext?"); |
| 4487 | break; |
| 4488 | case ISD::ConstantFP: |
| 4489 | Result = DAG.getNode(ISD::FP_EXTEND, NVT, Op); |
| 4490 | assert(isa<ConstantFPSDNode>(Result) && "Didn't constant fold fp_extend?"); |
| 4491 | break; |
Chris Lattner | ef5cd1d | 2005-01-18 17:54:55 +0000 | [diff] [blame] | 4492 | |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 4493 | case ISD::SETCC: { |
| 4494 | MVT VT0 = Node->getOperand(0).getValueType(); |
| 4495 | assert(isTypeLegal(TLI.getSetCCResultType(VT0)) |
Nate Begeman | 5922f56 | 2008-03-14 00:53:31 +0000 | [diff] [blame] | 4496 | && "SetCC type is not legal??"); |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 4497 | Result = DAG.getNode(ISD::SETCC, TLI.getSetCCResultType(VT0), |
Nate Begeman | 5922f56 | 2008-03-14 00:53:31 +0000 | [diff] [blame] | 4498 | Node->getOperand(0), Node->getOperand(1), |
| 4499 | Node->getOperand(2)); |
Chris Lattner | 82fbfb6 | 2005-01-18 02:59:52 +0000 | [diff] [blame] | 4500 | break; |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 4501 | } |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4502 | case ISD::TRUNCATE: |
| 4503 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 4504 | case Legal: |
| 4505 | Result = LegalizeOp(Node->getOperand(0)); |
Duncan Sands | 8e4eb09 | 2008-06-08 20:54:56 +0000 | [diff] [blame] | 4506 | assert(Result.getValueType().bitsGE(NVT) && |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4507 | "This truncation doesn't make sense!"); |
Duncan Sands | 8e4eb09 | 2008-06-08 20:54:56 +0000 | [diff] [blame] | 4508 | if (Result.getValueType().bitsGT(NVT)) // Truncate to NVT instead of VT |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4509 | Result = DAG.getNode(ISD::TRUNCATE, NVT, Result); |
| 4510 | break; |
Chris Lattner | e76ad6d | 2005-01-28 22:52:50 +0000 | [diff] [blame] | 4511 | case Promote: |
| 4512 | // The truncation is not required, because we don't guarantee anything |
| 4513 | // about high bits anyway. |
| 4514 | Result = PromoteOp(Node->getOperand(0)); |
| 4515 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4516 | case Expand: |
Nate Begeman | 79e46ac | 2005-04-04 00:57:08 +0000 | [diff] [blame] | 4517 | ExpandOp(Node->getOperand(0), Tmp1, Tmp2); |
| 4518 | // Truncate the low part of the expanded value to the result type |
Chris Lattner | e21c305 | 2005-08-01 18:16:37 +0000 | [diff] [blame] | 4519 | Result = DAG.getNode(ISD::TRUNCATE, NVT, Tmp1); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4520 | } |
| 4521 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4522 | case ISD::SIGN_EXTEND: |
| 4523 | case ISD::ZERO_EXTEND: |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 4524 | case ISD::ANY_EXTEND: |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4525 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 4526 | case Expand: assert(0 && "BUG: Smaller reg should have been promoted!"); |
| 4527 | case Legal: |
| 4528 | // 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] | 4529 | Result = DAG.getNode(Node->getOpcode(), NVT, Node->getOperand(0)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4530 | break; |
| 4531 | case Promote: |
| 4532 | // Promote the reg if it's smaller. |
| 4533 | Result = PromoteOp(Node->getOperand(0)); |
| 4534 | // The high bits are not guaranteed to be anything. Insert an extend. |
| 4535 | if (Node->getOpcode() == ISD::SIGN_EXTEND) |
Chris Lattner | 595dc54 | 2005-02-04 18:39:19 +0000 | [diff] [blame] | 4536 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Result, |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 4537 | DAG.getValueType(Node->getOperand(0).getValueType())); |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 4538 | else if (Node->getOpcode() == ISD::ZERO_EXTEND) |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 4539 | Result = DAG.getZeroExtendInReg(Result, |
| 4540 | Node->getOperand(0).getValueType()); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4541 | break; |
| 4542 | } |
| 4543 | break; |
Mon P Wang | 77cdf30 | 2008-11-10 20:54:11 +0000 | [diff] [blame] | 4544 | case ISD::CONVERT_RNDSAT: { |
| 4545 | ISD::CvtCode CvtCode = cast<CvtRndSatSDNode>(Node)->getCvtCode(); |
| 4546 | assert ((CvtCode == ISD::CVT_SS || CvtCode == ISD::CVT_SU || |
| 4547 | CvtCode == ISD::CVT_US || CvtCode == ISD::CVT_UU || |
| 4548 | CvtCode == ISD::CVT_SF || CvtCode == ISD::CVT_UF) && |
| 4549 | "can only promote integers"); |
| 4550 | Result = DAG.getConvertRndSat(NVT, Node->getOperand(0), |
| 4551 | Node->getOperand(1), Node->getOperand(2), |
| 4552 | Node->getOperand(3), Node->getOperand(4), |
| 4553 | CvtCode); |
| 4554 | break; |
| 4555 | |
| 4556 | } |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 4557 | case ISD::BIT_CONVERT: |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 4558 | Result = EmitStackConvert(Node->getOperand(0), Node->getValueType(0), |
| 4559 | Node->getValueType(0)); |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 4560 | Result = PromoteOp(Result); |
| 4561 | break; |
| 4562 | |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4563 | case ISD::FP_EXTEND: |
| 4564 | assert(0 && "Case not implemented. Dynamically dead with 2 FP types!"); |
| 4565 | case ISD::FP_ROUND: |
| 4566 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 4567 | case Expand: assert(0 && "BUG: Cannot expand FP regs!"); |
| 4568 | case Promote: assert(0 && "Unreachable with 2 FP types!"); |
| 4569 | case Legal: |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4570 | if (Node->getConstantOperandVal(1) == 0) { |
| 4571 | // Input is legal? Do an FP_ROUND_INREG. |
| 4572 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Node->getOperand(0), |
| 4573 | DAG.getValueType(VT)); |
| 4574 | } else { |
| 4575 | // Just remove the truncate, it isn't affecting the value. |
| 4576 | Result = DAG.getNode(ISD::FP_ROUND, NVT, Node->getOperand(0), |
| 4577 | Node->getOperand(1)); |
| 4578 | } |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4579 | break; |
| 4580 | } |
| 4581 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4582 | case ISD::SINT_TO_FP: |
| 4583 | case ISD::UINT_TO_FP: |
| 4584 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 4585 | case Legal: |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4586 | // No extra round required here. |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4587 | Result = DAG.getNode(Node->getOpcode(), NVT, Node->getOperand(0)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4588 | break; |
| 4589 | |
| 4590 | case Promote: |
| 4591 | Result = PromoteOp(Node->getOperand(0)); |
| 4592 | if (Node->getOpcode() == ISD::SINT_TO_FP) |
| 4593 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(), |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 4594 | Result, |
| 4595 | DAG.getValueType(Node->getOperand(0).getValueType())); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4596 | else |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 4597 | Result = DAG.getZeroExtendInReg(Result, |
| 4598 | Node->getOperand(0).getValueType()); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4599 | // No extra round required here. |
| 4600 | Result = DAG.getNode(Node->getOpcode(), NVT, Result); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4601 | break; |
| 4602 | case Expand: |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4603 | Result = ExpandIntToFP(Node->getOpcode() == ISD::SINT_TO_FP, NVT, |
| 4604 | Node->getOperand(0)); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4605 | // Round if we cannot tolerate excess precision. |
| 4606 | if (NoExcessFPPrecision) |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 4607 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 4608 | DAG.getValueType(VT)); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4609 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4610 | } |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4611 | break; |
| 4612 | |
Chris Lattner | 5e3c5b4 | 2005-12-09 17:32:47 +0000 | [diff] [blame] | 4613 | case ISD::SIGN_EXTEND_INREG: |
| 4614 | Result = PromoteOp(Node->getOperand(0)); |
| 4615 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Result, |
| 4616 | Node->getOperand(1)); |
| 4617 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4618 | case ISD::FP_TO_SINT: |
| 4619 | case ISD::FP_TO_UINT: |
| 4620 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 4621 | case Legal: |
Evan Cheng | 0b1b9dc | 2006-12-16 02:10:30 +0000 | [diff] [blame] | 4622 | case Expand: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4623 | Tmp1 = Node->getOperand(0); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4624 | break; |
| 4625 | case Promote: |
| 4626 | // The input result is prerounded, so we don't have to do anything |
| 4627 | // special. |
| 4628 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4629 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4630 | } |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 4631 | // If we're promoting a UINT to a larger size, check to see if the new node |
| 4632 | // will be legal. If it isn't, check to see if FP_TO_SINT is legal, since |
| 4633 | // we can use that instead. This allows us to generate better code for |
| 4634 | // FP_TO_UINT for small destination sizes on targets where FP_TO_UINT is not |
| 4635 | // legal, such as PowerPC. |
| 4636 | if (Node->getOpcode() == ISD::FP_TO_UINT && |
Dan Gohman | f560ffa | 2009-01-28 17:46:25 +0000 | [diff] [blame] | 4637 | !TLI.isOperationLegalOrCustom(ISD::FP_TO_UINT, NVT) && |
| 4638 | (TLI.isOperationLegalOrCustom(ISD::FP_TO_SINT, NVT) || |
Nate Begeman | b7f6ef1 | 2005-10-25 23:47:25 +0000 | [diff] [blame] | 4639 | TLI.getOperationAction(ISD::FP_TO_SINT, NVT)==TargetLowering::Custom)){ |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 4640 | Result = DAG.getNode(ISD::FP_TO_SINT, NVT, Tmp1); |
| 4641 | } else { |
| 4642 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1); |
| 4643 | } |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4644 | break; |
| 4645 | |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 4646 | case ISD::FABS: |
| 4647 | case ISD::FNEG: |
| 4648 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4649 | assert(Tmp1.getValueType() == NVT); |
| 4650 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1); |
| 4651 | // NOTE: we do not have to do any extra rounding here for |
| 4652 | // NoExcessFPPrecision, because we know the input will have the appropriate |
| 4653 | // precision, and these operations don't modify precision at all. |
| 4654 | break; |
| 4655 | |
Dale Johannesen | 7794f2a | 2008-09-04 00:47:13 +0000 | [diff] [blame] | 4656 | case ISD::FLOG: |
| 4657 | case ISD::FLOG2: |
| 4658 | case ISD::FLOG10: |
| 4659 | case ISD::FEXP: |
| 4660 | case ISD::FEXP2: |
Chris Lattner | da6ba87 | 2005-04-28 21:44:33 +0000 | [diff] [blame] | 4661 | case ISD::FSQRT: |
| 4662 | case ISD::FSIN: |
| 4663 | case ISD::FCOS: |
Dan Gohman | 2bb1e3e | 2008-08-21 18:38:14 +0000 | [diff] [blame] | 4664 | case ISD::FTRUNC: |
| 4665 | case ISD::FFLOOR: |
| 4666 | case ISD::FCEIL: |
| 4667 | case ISD::FRINT: |
| 4668 | case ISD::FNEARBYINT: |
Chris Lattner | da6ba87 | 2005-04-28 21:44:33 +0000 | [diff] [blame] | 4669 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4670 | assert(Tmp1.getValueType() == NVT); |
| 4671 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4672 | if (NoExcessFPPrecision) |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 4673 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 4674 | DAG.getValueType(VT)); |
Chris Lattner | da6ba87 | 2005-04-28 21:44:33 +0000 | [diff] [blame] | 4675 | break; |
| 4676 | |
Evan Cheng | 9d24ac5 | 2008-09-09 23:35:53 +0000 | [diff] [blame] | 4677 | case ISD::FPOW: |
Chris Lattner | 8b2d42c | 2007-03-03 23:43:21 +0000 | [diff] [blame] | 4678 | case ISD::FPOWI: { |
Evan Cheng | 9d24ac5 | 2008-09-09 23:35:53 +0000 | [diff] [blame] | 4679 | // 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] | 4680 | // directly as well, which may be better. |
| 4681 | Tmp1 = PromoteOp(Node->getOperand(0)); |
Evan Cheng | 9d24ac5 | 2008-09-09 23:35:53 +0000 | [diff] [blame] | 4682 | Tmp2 = Node->getOperand(1); |
| 4683 | if (Node->getOpcode() == ISD::FPOW) |
| 4684 | Tmp2 = PromoteOp(Tmp2); |
Chris Lattner | 8b2d42c | 2007-03-03 23:43:21 +0000 | [diff] [blame] | 4685 | assert(Tmp1.getValueType() == NVT); |
Evan Cheng | 9d24ac5 | 2008-09-09 23:35:53 +0000 | [diff] [blame] | 4686 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
Chris Lattner | 8b2d42c | 2007-03-03 23:43:21 +0000 | [diff] [blame] | 4687 | if (NoExcessFPPrecision) |
| 4688 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 4689 | DAG.getValueType(VT)); |
| 4690 | break; |
| 4691 | } |
| 4692 | |
Dan Gohman | 0b1d4a7 | 2008-12-23 21:37:04 +0000 | [diff] [blame] | 4693 | case ISD::ATOMIC_CMP_SWAP: { |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 4694 | AtomicSDNode* AtomNode = cast<AtomicSDNode>(Node); |
Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 4695 | Tmp2 = PromoteOp(Node->getOperand(2)); |
| 4696 | Tmp3 = PromoteOp(Node->getOperand(3)); |
Dan Gohman | 0b1d4a7 | 2008-12-23 21:37:04 +0000 | [diff] [blame] | 4697 | Result = DAG.getAtomic(Node->getOpcode(), AtomNode->getMemoryVT(), |
| 4698 | AtomNode->getChain(), |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 4699 | AtomNode->getBasePtr(), Tmp2, Tmp3, |
Dan Gohman | fd4418f | 2008-06-25 16:07:49 +0000 | [diff] [blame] | 4700 | AtomNode->getSrcValue(), |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 4701 | AtomNode->getAlignment()); |
Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 4702 | // Remember that we legalized the chain. |
| 4703 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1))); |
| 4704 | break; |
| 4705 | } |
Dan Gohman | 0b1d4a7 | 2008-12-23 21:37:04 +0000 | [diff] [blame] | 4706 | case ISD::ATOMIC_LOAD_ADD: |
| 4707 | case ISD::ATOMIC_LOAD_SUB: |
| 4708 | case ISD::ATOMIC_LOAD_AND: |
| 4709 | case ISD::ATOMIC_LOAD_OR: |
| 4710 | case ISD::ATOMIC_LOAD_XOR: |
| 4711 | case ISD::ATOMIC_LOAD_NAND: |
| 4712 | case ISD::ATOMIC_LOAD_MIN: |
| 4713 | case ISD::ATOMIC_LOAD_MAX: |
| 4714 | case ISD::ATOMIC_LOAD_UMIN: |
| 4715 | case ISD::ATOMIC_LOAD_UMAX: |
| 4716 | case ISD::ATOMIC_SWAP: { |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 4717 | AtomicSDNode* AtomNode = cast<AtomicSDNode>(Node); |
Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 4718 | Tmp2 = PromoteOp(Node->getOperand(2)); |
Dan Gohman | 0b1d4a7 | 2008-12-23 21:37:04 +0000 | [diff] [blame] | 4719 | Result = DAG.getAtomic(Node->getOpcode(), AtomNode->getMemoryVT(), |
| 4720 | AtomNode->getChain(), |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 4721 | AtomNode->getBasePtr(), Tmp2, |
Dan Gohman | fd4418f | 2008-06-25 16:07:49 +0000 | [diff] [blame] | 4722 | AtomNode->getSrcValue(), |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 4723 | AtomNode->getAlignment()); |
Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 4724 | // Remember that we legalized the chain. |
| 4725 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1))); |
| 4726 | break; |
| 4727 | } |
| 4728 | |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4729 | case ISD::AND: |
| 4730 | case ISD::OR: |
| 4731 | case ISD::XOR: |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 4732 | case ISD::ADD: |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4733 | case ISD::SUB: |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 4734 | case ISD::MUL: |
| 4735 | // 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] | 4736 | // 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] | 4737 | // that too is okay if they are integer operations. |
| 4738 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4739 | Tmp2 = PromoteOp(Node->getOperand(1)); |
| 4740 | assert(Tmp1.getValueType() == NVT && Tmp2.getValueType() == NVT); |
| 4741 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 4742 | break; |
| 4743 | case ISD::FADD: |
| 4744 | case ISD::FSUB: |
| 4745 | case ISD::FMUL: |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 4746 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4747 | Tmp2 = PromoteOp(Node->getOperand(1)); |
| 4748 | assert(Tmp1.getValueType() == NVT && Tmp2.getValueType() == NVT); |
| 4749 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 4750 | |
| 4751 | // Floating point operations will give excess precision that we may not be |
| 4752 | // able to tolerate. If we DO allow excess precision, just leave it, |
| 4753 | // otherwise excise it. |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4754 | // FIXME: Why would we need to round FP ops more than integer ones? |
| 4755 | // 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] | 4756 | if (NoExcessFPPrecision) |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 4757 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 4758 | DAG.getValueType(VT)); |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 4759 | break; |
| 4760 | |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4761 | case ISD::SDIV: |
| 4762 | case ISD::SREM: |
| 4763 | // These operators require that their input be sign extended. |
| 4764 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4765 | Tmp2 = PromoteOp(Node->getOperand(1)); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4766 | if (NVT.isInteger()) { |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 4767 | Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp1, |
| 4768 | DAG.getValueType(VT)); |
| 4769 | Tmp2 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp2, |
| 4770 | DAG.getValueType(VT)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4771 | } |
| 4772 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 4773 | |
| 4774 | // Perform FP_ROUND: this is probably overly pessimistic. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4775 | if (NVT.isFloatingPoint() && NoExcessFPPrecision) |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 4776 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 4777 | DAG.getValueType(VT)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4778 | break; |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 4779 | case ISD::FDIV: |
| 4780 | case ISD::FREM: |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 4781 | case ISD::FCOPYSIGN: |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 4782 | // These operators require that their input be fp extended. |
Nate Begeman | ec57fd9 | 2006-05-09 18:20:51 +0000 | [diff] [blame] | 4783 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4784 | case Expand: assert(0 && "not implemented"); |
| 4785 | case Legal: Tmp1 = LegalizeOp(Node->getOperand(0)); break; |
| 4786 | case Promote: Tmp1 = PromoteOp(Node->getOperand(0)); break; |
Nate Begeman | ec57fd9 | 2006-05-09 18:20:51 +0000 | [diff] [blame] | 4787 | } |
| 4788 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4789 | case Expand: assert(0 && "not implemented"); |
| 4790 | case Legal: Tmp2 = LegalizeOp(Node->getOperand(1)); break; |
| 4791 | case Promote: Tmp2 = PromoteOp(Node->getOperand(1)); break; |
Nate Begeman | ec57fd9 | 2006-05-09 18:20:51 +0000 | [diff] [blame] | 4792 | } |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 4793 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 4794 | |
| 4795 | // Perform FP_ROUND: this is probably overly pessimistic. |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 4796 | if (NoExcessFPPrecision && Node->getOpcode() != ISD::FCOPYSIGN) |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 4797 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 4798 | DAG.getValueType(VT)); |
| 4799 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4800 | |
| 4801 | case ISD::UDIV: |
| 4802 | case ISD::UREM: |
| 4803 | // These operators require that their input be zero extended. |
| 4804 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4805 | Tmp2 = PromoteOp(Node->getOperand(1)); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4806 | assert(NVT.isInteger() && "Operators don't apply to FP!"); |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 4807 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, VT); |
| 4808 | Tmp2 = DAG.getZeroExtendInReg(Tmp2, VT); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4809 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 4810 | break; |
| 4811 | |
| 4812 | case ISD::SHL: |
| 4813 | Tmp1 = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4814 | Result = DAG.getNode(ISD::SHL, NVT, Tmp1, Node->getOperand(1)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4815 | break; |
| 4816 | case ISD::SRA: |
| 4817 | // The input value must be properly sign extended. |
| 4818 | Tmp1 = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 4819 | Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp1, |
| 4820 | DAG.getValueType(VT)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4821 | Result = DAG.getNode(ISD::SRA, NVT, Tmp1, Node->getOperand(1)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4822 | break; |
| 4823 | case ISD::SRL: |
| 4824 | // The input value must be properly zero extended. |
| 4825 | Tmp1 = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 4826 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, VT); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4827 | Result = DAG.getNode(ISD::SRL, NVT, Tmp1, Node->getOperand(1)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4828 | break; |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 4829 | |
| 4830 | case ISD::VAARG: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4831 | Tmp1 = Node->getOperand(0); // Get the chain. |
| 4832 | Tmp2 = Node->getOperand(1); // Get the pointer. |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 4833 | if (TLI.getOperationAction(ISD::VAARG, VT) == TargetLowering::Custom) { |
| 4834 | Tmp3 = DAG.getVAArg(VT, Tmp1, Tmp2, Node->getOperand(2)); |
Duncan Sands | 126d907 | 2008-07-04 11:47:58 +0000 | [diff] [blame] | 4835 | Result = TLI.LowerOperation(Tmp3, DAG); |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 4836 | } else { |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 4837 | const Value *V = cast<SrcValueSDNode>(Node->getOperand(2))->getValue(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4838 | SDValue VAList = DAG.getLoad(TLI.getPointerTy(), Tmp1, Tmp2, V, 0); |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 4839 | // Increment the pointer, VAList, to the next vaarg |
| 4840 | Tmp3 = DAG.getNode(ISD::ADD, TLI.getPointerTy(), VAList, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4841 | DAG.getConstant(VT.getSizeInBits()/8, |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 4842 | TLI.getPointerTy())); |
| 4843 | // Store the incremented VAList to the legalized pointer |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 4844 | Tmp3 = DAG.getStore(VAList.getValue(1), Tmp3, Tmp2, V, 0); |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 4845 | // Load the actual argument out of the pointer VAList |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 4846 | Result = DAG.getExtLoad(ISD::EXTLOAD, NVT, Tmp3, VAList, NULL, 0, VT); |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 4847 | } |
| 4848 | // Remember that we legalized the chain. |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4849 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1))); |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 4850 | break; |
| 4851 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 4852 | case ISD::LOAD: { |
| 4853 | LoadSDNode *LD = cast<LoadSDNode>(Node); |
Evan Cheng | 62f2a3c | 2006-10-10 07:51:21 +0000 | [diff] [blame] | 4854 | ISD::LoadExtType ExtType = ISD::isNON_EXTLoad(Node) |
| 4855 | ? ISD::EXTLOAD : LD->getExtensionType(); |
| 4856 | Result = DAG.getExtLoad(ExtType, NVT, |
| 4857 | LD->getChain(), LD->getBasePtr(), |
Chris Lattner | 55b5708 | 2006-10-10 18:54:19 +0000 | [diff] [blame] | 4858 | LD->getSrcValue(), LD->getSrcValueOffset(), |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 4859 | LD->getMemoryVT(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 4860 | LD->isVolatile(), |
| 4861 | LD->getAlignment()); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4862 | // Remember that we legalized the chain. |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4863 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1))); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4864 | break; |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 4865 | } |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 4866 | case ISD::SELECT: { |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4867 | Tmp2 = PromoteOp(Node->getOperand(1)); // Legalize the op0 |
| 4868 | Tmp3 = PromoteOp(Node->getOperand(2)); // Legalize the op1 |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 4869 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4870 | MVT VT2 = Tmp2.getValueType(); |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 4871 | assert(VT2 == Tmp3.getValueType() |
Scott Michel | ba12f57 | 2008-06-03 19:13:20 +0000 | [diff] [blame] | 4872 | && "PromoteOp SELECT: Operands 2 and 3 ValueTypes don't match"); |
| 4873 | // Ensure that the resulting node is at least the same size as the operands' |
| 4874 | // value types, because we cannot assume that TLI.getSetCCValueType() is |
| 4875 | // constant. |
| 4876 | Result = DAG.getNode(ISD::SELECT, VT2, Node->getOperand(0), Tmp2, Tmp3); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4877 | break; |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 4878 | } |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 4879 | case ISD::SELECT_CC: |
| 4880 | Tmp2 = PromoteOp(Node->getOperand(2)); // True |
| 4881 | Tmp3 = PromoteOp(Node->getOperand(3)); // False |
| 4882 | Result = DAG.getNode(ISD::SELECT_CC, NVT, Node->getOperand(0), |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4883 | Node->getOperand(1), Tmp2, Tmp3, Node->getOperand(4)); |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 4884 | break; |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 4885 | case ISD::BSWAP: |
| 4886 | Tmp1 = Node->getOperand(0); |
| 4887 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Tmp1); |
| 4888 | Tmp1 = DAG.getNode(ISD::BSWAP, NVT, Tmp1); |
| 4889 | Result = DAG.getNode(ISD::SRL, NVT, Tmp1, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4890 | DAG.getConstant(NVT.getSizeInBits() - |
| 4891 | VT.getSizeInBits(), |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 4892 | TLI.getShiftAmountTy())); |
| 4893 | break; |
Andrew Lenharth | fecf095 | 2005-05-04 19:11:05 +0000 | [diff] [blame] | 4894 | case ISD::CTPOP: |
| 4895 | case ISD::CTTZ: |
| 4896 | case ISD::CTLZ: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4897 | // Zero extend the argument |
| 4898 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Node->getOperand(0)); |
Andrew Lenharth | fecf095 | 2005-05-04 19:11:05 +0000 | [diff] [blame] | 4899 | // Perform the larger operation, then subtract if needed. |
| 4900 | Tmp1 = DAG.getNode(Node->getOpcode(), NVT, Tmp1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4901 | switch(Node->getOpcode()) { |
Andrew Lenharth | fecf095 | 2005-05-04 19:11:05 +0000 | [diff] [blame] | 4902 | case ISD::CTPOP: |
| 4903 | Result = Tmp1; |
| 4904 | break; |
| 4905 | case ISD::CTTZ: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4906 | // if Tmp1 == sizeinbits(NVT) then Tmp1 = sizeinbits(Old VT) |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 4907 | Tmp2 = DAG.getSetCC(TLI.getSetCCResultType(Tmp1.getValueType()), Tmp1, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4908 | DAG.getConstant(NVT.getSizeInBits(), NVT), |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 4909 | ISD::SETEQ); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 4910 | Result = DAG.getNode(ISD::SELECT, NVT, Tmp2, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4911 | DAG.getConstant(VT.getSizeInBits(), NVT), Tmp1); |
Andrew Lenharth | fecf095 | 2005-05-04 19:11:05 +0000 | [diff] [blame] | 4912 | break; |
| 4913 | case ISD::CTLZ: |
| 4914 | //Tmp1 = Tmp1 - (sizeinbits(NVT) - sizeinbits(Old VT)) |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 4915 | Result = DAG.getNode(ISD::SUB, NVT, Tmp1, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4916 | DAG.getConstant(NVT.getSizeInBits() - |
| 4917 | VT.getSizeInBits(), NVT)); |
Andrew Lenharth | fecf095 | 2005-05-04 19:11:05 +0000 | [diff] [blame] | 4918 | break; |
| 4919 | } |
| 4920 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4921 | case ISD::EXTRACT_SUBVECTOR: |
| 4922 | Result = PromoteOp(ExpandEXTRACT_SUBVECTOR(Op)); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 4923 | break; |
Chris Lattner | 4aab2f4 | 2006-04-02 05:06:04 +0000 | [diff] [blame] | 4924 | case ISD::EXTRACT_VECTOR_ELT: |
| 4925 | Result = PromoteOp(ExpandEXTRACT_VECTOR_ELT(Op)); |
| 4926 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4927 | } |
| 4928 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 4929 | assert(Result.getNode() && "Didn't set a result!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4930 | |
| 4931 | // Make sure the result is itself legal. |
| 4932 | Result = LegalizeOp(Result); |
| 4933 | |
| 4934 | // Remember that we promoted this! |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4935 | AddPromotedOperand(Op, Result); |
| 4936 | return Result; |
| 4937 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 4938 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4939 | /// ExpandEXTRACT_VECTOR_ELT - Expand an EXTRACT_VECTOR_ELT operation into |
| 4940 | /// a legal EXTRACT_VECTOR_ELT operation, scalar code, or memory traffic, |
| 4941 | /// based on the vector type. The return type of this matches the element type |
| 4942 | /// of the vector, which may not be legal for the target. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4943 | SDValue SelectionDAGLegalize::ExpandEXTRACT_VECTOR_ELT(SDValue Op) { |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4944 | // We know that operand #0 is the Vec vector. If the index is a constant |
| 4945 | // or if the invec is a supported hardware type, we can use it. Otherwise, |
| 4946 | // lower to a store then an indexed load. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4947 | SDValue Vec = Op.getOperand(0); |
| 4948 | SDValue Idx = Op.getOperand(1); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4949 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4950 | MVT TVT = Vec.getValueType(); |
| 4951 | unsigned NumElems = TVT.getVectorNumElements(); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4952 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4953 | switch (TLI.getOperationAction(ISD::EXTRACT_VECTOR_ELT, TVT)) { |
| 4954 | default: assert(0 && "This action is not supported yet!"); |
| 4955 | case TargetLowering::Custom: { |
| 4956 | Vec = LegalizeOp(Vec); |
| 4957 | Op = DAG.UpdateNodeOperands(Op, Vec, Idx); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4958 | SDValue Tmp3 = TLI.LowerOperation(Op, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 4959 | if (Tmp3.getNode()) |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4960 | return Tmp3; |
| 4961 | break; |
| 4962 | } |
| 4963 | case TargetLowering::Legal: |
| 4964 | if (isTypeLegal(TVT)) { |
| 4965 | Vec = LegalizeOp(Vec); |
| 4966 | Op = DAG.UpdateNodeOperands(Op, Vec, Idx); |
Christopher Lamb | 844228a | 2007-07-26 03:33:13 +0000 | [diff] [blame] | 4967 | return Op; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4968 | } |
| 4969 | break; |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 4970 | case TargetLowering::Promote: |
| 4971 | assert(TVT.isVector() && "not vector type"); |
| 4972 | // fall thru to expand since vectors are by default are promote |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4973 | case TargetLowering::Expand: |
| 4974 | break; |
| 4975 | } |
| 4976 | |
| 4977 | if (NumElems == 1) { |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4978 | // This must be an access of the only element. Return it. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4979 | Op = ScalarizeVectorOp(Vec); |
| 4980 | } else if (!TLI.isTypeLegal(TVT) && isa<ConstantSDNode>(Idx)) { |
Nate Begeman | 55030dc | 2008-01-29 02:24:00 +0000 | [diff] [blame] | 4981 | unsigned NumLoElts = 1 << Log2_32(NumElems-1); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4982 | ConstantSDNode *CIdx = cast<ConstantSDNode>(Idx); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4983 | SDValue Lo, Hi; |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4984 | SplitVectorOp(Vec, Lo, Hi); |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 4985 | if (CIdx->getZExtValue() < NumLoElts) { |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4986 | Vec = Lo; |
| 4987 | } else { |
| 4988 | Vec = Hi; |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 4989 | Idx = DAG.getConstant(CIdx->getZExtValue() - NumLoElts, |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4990 | Idx.getValueType()); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4991 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4992 | |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4993 | // It's now an extract from the appropriate high or low part. Recurse. |
| 4994 | Op = DAG.UpdateNodeOperands(Op, Vec, Idx); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4995 | Op = ExpandEXTRACT_VECTOR_ELT(Op); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4996 | } else { |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4997 | // Store the value to a temporary stack slot, then LOAD the scalar |
| 4998 | // element back out. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4999 | SDValue StackPtr = DAG.CreateStackTemporary(Vec.getValueType()); |
| 5000 | SDValue Ch = DAG.getStore(DAG.getEntryNode(), Vec, StackPtr, NULL, 0); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5001 | |
| 5002 | // Add the offset to the index. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5003 | unsigned EltSize = Op.getValueType().getSizeInBits()/8; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5004 | Idx = DAG.getNode(ISD::MUL, Idx.getValueType(), Idx, |
| 5005 | DAG.getConstant(EltSize, Idx.getValueType())); |
Bill Wendling | 90bfc2d | 2007-10-18 08:32:37 +0000 | [diff] [blame] | 5006 | |
Duncan Sands | 8e4eb09 | 2008-06-08 20:54:56 +0000 | [diff] [blame] | 5007 | if (Idx.getValueType().bitsGT(TLI.getPointerTy())) |
Chris Lattner | f185e67 | 2007-10-19 16:47:35 +0000 | [diff] [blame] | 5008 | Idx = DAG.getNode(ISD::TRUNCATE, TLI.getPointerTy(), Idx); |
Bill Wendling | 90bfc2d | 2007-10-18 08:32:37 +0000 | [diff] [blame] | 5009 | else |
Chris Lattner | f185e67 | 2007-10-19 16:47:35 +0000 | [diff] [blame] | 5010 | Idx = DAG.getNode(ISD::ZERO_EXTEND, TLI.getPointerTy(), Idx); |
Bill Wendling | 90bfc2d | 2007-10-18 08:32:37 +0000 | [diff] [blame] | 5011 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5012 | StackPtr = DAG.getNode(ISD::ADD, Idx.getValueType(), Idx, StackPtr); |
| 5013 | |
| 5014 | Op = DAG.getLoad(Op.getValueType(), Ch, StackPtr, NULL, 0); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 5015 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5016 | return Op; |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 5017 | } |
| 5018 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5019 | /// ExpandEXTRACT_SUBVECTOR - Expand a EXTRACT_SUBVECTOR operation. For now |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 5020 | /// 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] | 5021 | SDValue SelectionDAGLegalize::ExpandEXTRACT_SUBVECTOR(SDValue Op) { |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 5022 | // We know that operand #0 is the Vec vector. For now we assume the index |
| 5023 | // 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] | 5024 | SDValue Vec = Op.getOperand(0); |
| 5025 | SDValue Idx = LegalizeOp(Op.getOperand(1)); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 5026 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5027 | unsigned NumElems = Vec.getValueType().getVectorNumElements(); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 5028 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5029 | if (NumElems == Op.getValueType().getVectorNumElements()) { |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 5030 | // This must be an access of the desired vector length. Return it. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5031 | return Vec; |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 5032 | } |
| 5033 | |
| 5034 | ConstantSDNode *CIdx = cast<ConstantSDNode>(Idx); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5035 | SDValue Lo, Hi; |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 5036 | SplitVectorOp(Vec, Lo, Hi); |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 5037 | if (CIdx->getZExtValue() < NumElems/2) { |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 5038 | Vec = Lo; |
| 5039 | } else { |
| 5040 | Vec = Hi; |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 5041 | Idx = DAG.getConstant(CIdx->getZExtValue() - NumElems/2, |
| 5042 | Idx.getValueType()); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 5043 | } |
| 5044 | |
| 5045 | // It's now an extract from the appropriate high or low part. Recurse. |
| 5046 | Op = DAG.UpdateNodeOperands(Op, Vec, Idx); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5047 | return ExpandEXTRACT_SUBVECTOR(Op); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 5048 | } |
| 5049 | |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 5050 | /// LegalizeSetCCOperands - Attempts to create a legal LHS and RHS for a SETCC |
| 5051 | /// with condition CC on the current target. This usually involves legalizing |
| 5052 | /// or promoting the arguments. In the case where LHS and RHS must be expanded, |
| 5053 | /// there may be no choice but to create a new SetCC node to represent the |
| 5054 | /// 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] | 5055 | /// LHS, and the SDValue returned in RHS has a nil SDNode value. |
| 5056 | void SelectionDAGLegalize::LegalizeSetCCOperands(SDValue &LHS, |
| 5057 | SDValue &RHS, |
| 5058 | SDValue &CC) { |
| 5059 | SDValue Tmp1, Tmp2, Tmp3, Result; |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 5060 | |
| 5061 | switch (getTypeAction(LHS.getValueType())) { |
| 5062 | case Legal: |
| 5063 | Tmp1 = LegalizeOp(LHS); // LHS |
| 5064 | Tmp2 = LegalizeOp(RHS); // RHS |
| 5065 | break; |
| 5066 | case Promote: |
| 5067 | Tmp1 = PromoteOp(LHS); // LHS |
| 5068 | Tmp2 = PromoteOp(RHS); // RHS |
| 5069 | |
| 5070 | // If this is an FP compare, the operands have already been extended. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5071 | if (LHS.getValueType().isInteger()) { |
| 5072 | MVT VT = LHS.getValueType(); |
| 5073 | MVT NVT = TLI.getTypeToTransformTo(VT); |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 5074 | |
| 5075 | // Otherwise, we have to insert explicit sign or zero extends. Note |
| 5076 | // that we could insert sign extends for ALL conditions, but zero extend |
| 5077 | // is cheaper on many machines (an AND instead of two shifts), so prefer |
| 5078 | // it. |
| 5079 | switch (cast<CondCodeSDNode>(CC)->get()) { |
| 5080 | default: assert(0 && "Unknown integer comparison!"); |
| 5081 | case ISD::SETEQ: |
| 5082 | case ISD::SETNE: |
| 5083 | case ISD::SETUGE: |
| 5084 | case ISD::SETUGT: |
| 5085 | case ISD::SETULE: |
| 5086 | case ISD::SETULT: |
| 5087 | // ALL of these operations will work if we either sign or zero extend |
| 5088 | // the operands (including the unsigned comparisons!). Zero extend is |
| 5089 | // usually a simpler/cheaper operation, so prefer it. |
| 5090 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, VT); |
| 5091 | Tmp2 = DAG.getZeroExtendInReg(Tmp2, VT); |
| 5092 | break; |
| 5093 | case ISD::SETGE: |
| 5094 | case ISD::SETGT: |
| 5095 | case ISD::SETLT: |
| 5096 | case ISD::SETLE: |
| 5097 | Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp1, |
| 5098 | DAG.getValueType(VT)); |
| 5099 | Tmp2 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp2, |
| 5100 | DAG.getValueType(VT)); |
Evan Cheng | efa5339 | 2008-10-13 18:46:18 +0000 | [diff] [blame] | 5101 | Tmp1 = LegalizeOp(Tmp1); // Relegalize new nodes. |
| 5102 | Tmp2 = LegalizeOp(Tmp2); // Relegalize new nodes. |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 5103 | break; |
| 5104 | } |
| 5105 | } |
| 5106 | break; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5107 | case Expand: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5108 | MVT VT = LHS.getValueType(); |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5109 | if (VT == MVT::f32 || VT == MVT::f64) { |
| 5110 | // Expand into one or more soft-fp libcall(s). |
Evan Cheng | 6518c6e | 2008-07-01 21:35:46 +0000 | [diff] [blame] | 5111 | RTLIB::Libcall LC1 = RTLIB::UNKNOWN_LIBCALL, LC2 = RTLIB::UNKNOWN_LIBCALL; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5112 | switch (cast<CondCodeSDNode>(CC)->get()) { |
| 5113 | case ISD::SETEQ: |
| 5114 | case ISD::SETOEQ: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5115 | LC1 = (VT == MVT::f32) ? RTLIB::OEQ_F32 : RTLIB::OEQ_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5116 | break; |
| 5117 | case ISD::SETNE: |
| 5118 | case ISD::SETUNE: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5119 | LC1 = (VT == MVT::f32) ? RTLIB::UNE_F32 : RTLIB::UNE_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5120 | break; |
| 5121 | case ISD::SETGE: |
| 5122 | case ISD::SETOGE: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5123 | LC1 = (VT == MVT::f32) ? RTLIB::OGE_F32 : RTLIB::OGE_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5124 | break; |
| 5125 | case ISD::SETLT: |
| 5126 | case ISD::SETOLT: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5127 | LC1 = (VT == MVT::f32) ? RTLIB::OLT_F32 : RTLIB::OLT_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5128 | break; |
| 5129 | case ISD::SETLE: |
| 5130 | case ISD::SETOLE: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5131 | LC1 = (VT == MVT::f32) ? RTLIB::OLE_F32 : RTLIB::OLE_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5132 | break; |
| 5133 | case ISD::SETGT: |
| 5134 | case ISD::SETOGT: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5135 | LC1 = (VT == MVT::f32) ? RTLIB::OGT_F32 : RTLIB::OGT_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5136 | break; |
| 5137 | case ISD::SETUO: |
Evan Cheng | d385fd6 | 2007-01-31 09:29:11 +0000 | [diff] [blame] | 5138 | LC1 = (VT == MVT::f32) ? RTLIB::UO_F32 : RTLIB::UO_F64; |
| 5139 | break; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5140 | case ISD::SETO: |
Evan Cheng | 5efdecc | 2007-02-03 00:43:46 +0000 | [diff] [blame] | 5141 | LC1 = (VT == MVT::f32) ? RTLIB::O_F32 : RTLIB::O_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5142 | break; |
| 5143 | default: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5144 | LC1 = (VT == MVT::f32) ? RTLIB::UO_F32 : RTLIB::UO_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5145 | switch (cast<CondCodeSDNode>(CC)->get()) { |
| 5146 | case ISD::SETONE: |
| 5147 | // SETONE = SETOLT | SETOGT |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5148 | LC1 = (VT == MVT::f32) ? RTLIB::OLT_F32 : RTLIB::OLT_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5149 | // Fallthrough |
| 5150 | case ISD::SETUGT: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5151 | LC2 = (VT == MVT::f32) ? RTLIB::OGT_F32 : RTLIB::OGT_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5152 | break; |
| 5153 | case ISD::SETUGE: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5154 | LC2 = (VT == MVT::f32) ? RTLIB::OGE_F32 : RTLIB::OGE_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5155 | break; |
| 5156 | case ISD::SETULT: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5157 | LC2 = (VT == MVT::f32) ? RTLIB::OLT_F32 : RTLIB::OLT_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5158 | break; |
| 5159 | case ISD::SETULE: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5160 | LC2 = (VT == MVT::f32) ? RTLIB::OLE_F32 : RTLIB::OLE_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5161 | break; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5162 | case ISD::SETUEQ: |
| 5163 | LC2 = (VT == MVT::f32) ? RTLIB::OEQ_F32 : RTLIB::OEQ_F64; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5164 | break; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5165 | default: assert(0 && "Unsupported FP setcc!"); |
| 5166 | } |
| 5167 | } |
Duncan Sands | f951620 | 2008-06-30 10:19:09 +0000 | [diff] [blame] | 5168 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5169 | SDValue Dummy; |
| 5170 | SDValue Ops[2] = { LHS, RHS }; |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5171 | Tmp1 = ExpandLibCall(LC1, DAG.getMergeValues(Ops, 2).getNode(), |
Reid Spencer | b47b25c | 2007-01-03 04:22:32 +0000 | [diff] [blame] | 5172 | false /*sign irrelevant*/, Dummy); |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5173 | Tmp2 = DAG.getConstant(0, MVT::i32); |
Evan Cheng | d385fd6 | 2007-01-31 09:29:11 +0000 | [diff] [blame] | 5174 | CC = DAG.getCondCode(TLI.getCmpLibcallCC(LC1)); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5175 | if (LC2 != RTLIB::UNKNOWN_LIBCALL) { |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 5176 | Tmp1 = DAG.getNode(ISD::SETCC, |
| 5177 | TLI.getSetCCResultType(Tmp1.getValueType()), |
| 5178 | Tmp1, Tmp2, CC); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5179 | LHS = ExpandLibCall(LC2, DAG.getMergeValues(Ops, 2).getNode(), |
Reid Spencer | b47b25c | 2007-01-03 04:22:32 +0000 | [diff] [blame] | 5180 | false /*sign irrelevant*/, Dummy); |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 5181 | Tmp2 = DAG.getNode(ISD::SETCC, |
| 5182 | TLI.getSetCCResultType(LHS.getValueType()), LHS, |
| 5183 | Tmp2, DAG.getCondCode(TLI.getCmpLibcallCC(LC2))); |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5184 | Tmp1 = DAG.getNode(ISD::OR, Tmp1.getValueType(), Tmp1, Tmp2); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5185 | Tmp2 = SDValue(); |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5186 | } |
Evan Cheng | 21cacc4 | 2008-07-07 07:18:09 +0000 | [diff] [blame] | 5187 | LHS = LegalizeOp(Tmp1); |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5188 | RHS = Tmp2; |
| 5189 | return; |
| 5190 | } |
| 5191 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5192 | SDValue LHSLo, LHSHi, RHSLo, RHSHi; |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 5193 | ExpandOp(LHS, LHSLo, LHSHi); |
Dale Johannesen | 638ccd5 | 2007-10-06 01:24:11 +0000 | [diff] [blame] | 5194 | ExpandOp(RHS, RHSLo, RHSHi); |
| 5195 | ISD::CondCode CCCode = cast<CondCodeSDNode>(CC)->get(); |
| 5196 | |
| 5197 | if (VT==MVT::ppcf128) { |
| 5198 | // FIXME: This generated code sucks. We want to generate |
Dale Johannesen | e2f2083 | 2008-09-12 00:30:56 +0000 | [diff] [blame] | 5199 | // FCMPU crN, hi1, hi2 |
Dale Johannesen | 638ccd5 | 2007-10-06 01:24:11 +0000 | [diff] [blame] | 5200 | // BNE crN, L: |
Dale Johannesen | e2f2083 | 2008-09-12 00:30:56 +0000 | [diff] [blame] | 5201 | // FCMPU crN, lo1, lo2 |
Dale Johannesen | 638ccd5 | 2007-10-06 01:24:11 +0000 | [diff] [blame] | 5202 | // The following can be improved, but not that much. |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 5203 | Tmp1 = DAG.getSetCC(TLI.getSetCCResultType(LHSHi.getValueType()), |
| 5204 | LHSHi, RHSHi, ISD::SETOEQ); |
| 5205 | Tmp2 = DAG.getSetCC(TLI.getSetCCResultType(LHSLo.getValueType()), |
| 5206 | LHSLo, RHSLo, CCCode); |
Dale Johannesen | 638ccd5 | 2007-10-06 01:24:11 +0000 | [diff] [blame] | 5207 | Tmp3 = DAG.getNode(ISD::AND, Tmp1.getValueType(), Tmp1, Tmp2); |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 5208 | Tmp1 = DAG.getSetCC(TLI.getSetCCResultType(LHSHi.getValueType()), |
| 5209 | LHSHi, RHSHi, ISD::SETUNE); |
| 5210 | Tmp2 = DAG.getSetCC(TLI.getSetCCResultType(LHSHi.getValueType()), |
| 5211 | LHSHi, RHSHi, CCCode); |
Dale Johannesen | 638ccd5 | 2007-10-06 01:24:11 +0000 | [diff] [blame] | 5212 | Tmp1 = DAG.getNode(ISD::AND, Tmp1.getValueType(), Tmp1, Tmp2); |
| 5213 | Tmp1 = DAG.getNode(ISD::OR, Tmp1.getValueType(), Tmp1, Tmp3); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5214 | Tmp2 = SDValue(); |
Dale Johannesen | 638ccd5 | 2007-10-06 01:24:11 +0000 | [diff] [blame] | 5215 | break; |
| 5216 | } |
| 5217 | |
| 5218 | switch (CCCode) { |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 5219 | case ISD::SETEQ: |
| 5220 | case ISD::SETNE: |
| 5221 | if (RHSLo == RHSHi) |
| 5222 | if (ConstantSDNode *RHSCST = dyn_cast<ConstantSDNode>(RHSLo)) |
| 5223 | if (RHSCST->isAllOnesValue()) { |
| 5224 | // Comparison to -1. |
| 5225 | Tmp1 = DAG.getNode(ISD::AND, LHSLo.getValueType(), LHSLo, LHSHi); |
| 5226 | Tmp2 = RHSLo; |
| 5227 | break; |
| 5228 | } |
| 5229 | |
| 5230 | Tmp1 = DAG.getNode(ISD::XOR, LHSLo.getValueType(), LHSLo, RHSLo); |
| 5231 | Tmp2 = DAG.getNode(ISD::XOR, LHSLo.getValueType(), LHSHi, RHSHi); |
| 5232 | Tmp1 = DAG.getNode(ISD::OR, Tmp1.getValueType(), Tmp1, Tmp2); |
| 5233 | Tmp2 = DAG.getConstant(0, Tmp1.getValueType()); |
| 5234 | break; |
| 5235 | default: |
| 5236 | // If this is a comparison of the sign bit, just look at the top part. |
| 5237 | // X > -1, x < 0 |
| 5238 | if (ConstantSDNode *CST = dyn_cast<ConstantSDNode>(RHS)) |
| 5239 | if ((cast<CondCodeSDNode>(CC)->get() == ISD::SETLT && |
Dan Gohman | 002e5d0 | 2008-03-13 22:13:53 +0000 | [diff] [blame] | 5240 | CST->isNullValue()) || // X < 0 |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 5241 | (cast<CondCodeSDNode>(CC)->get() == ISD::SETGT && |
| 5242 | CST->isAllOnesValue())) { // X > -1 |
| 5243 | Tmp1 = LHSHi; |
| 5244 | Tmp2 = RHSHi; |
| 5245 | break; |
| 5246 | } |
| 5247 | |
| 5248 | // FIXME: This generated code sucks. |
| 5249 | ISD::CondCode LowCC; |
Evan Cheng | 2e67781 | 2007-02-08 22:16:19 +0000 | [diff] [blame] | 5250 | switch (CCCode) { |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 5251 | default: assert(0 && "Unknown integer setcc!"); |
| 5252 | case ISD::SETLT: |
| 5253 | case ISD::SETULT: LowCC = ISD::SETULT; break; |
| 5254 | case ISD::SETGT: |
| 5255 | case ISD::SETUGT: LowCC = ISD::SETUGT; break; |
| 5256 | case ISD::SETLE: |
| 5257 | case ISD::SETULE: LowCC = ISD::SETULE; break; |
| 5258 | case ISD::SETGE: |
| 5259 | case ISD::SETUGE: LowCC = ISD::SETUGE; break; |
| 5260 | } |
| 5261 | |
| 5262 | // Tmp1 = lo(op1) < lo(op2) // Always unsigned comparison |
| 5263 | // Tmp2 = hi(op1) < hi(op2) // Signedness depends on operands |
| 5264 | // dest = hi(op1) == hi(op2) ? Tmp1 : Tmp2; |
| 5265 | |
| 5266 | // NOTE: on targets without efficient SELECT of bools, we can always use |
| 5267 | // this identity: (B1 ? B2 : B3) --> (B1 & B2)|(!B1&B3) |
Evan Cheng | 2e67781 | 2007-02-08 22:16:19 +0000 | [diff] [blame] | 5268 | TargetLowering::DAGCombinerInfo DagCombineInfo(DAG, false, true, NULL); |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 5269 | Tmp1 = TLI.SimplifySetCC(TLI.getSetCCResultType(LHSLo.getValueType()), |
| 5270 | LHSLo, RHSLo, LowCC, false, DagCombineInfo); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5271 | if (!Tmp1.getNode()) |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 5272 | Tmp1 = DAG.getSetCC(TLI.getSetCCResultType(LHSLo.getValueType()), |
| 5273 | LHSLo, RHSLo, LowCC); |
| 5274 | Tmp2 = TLI.SimplifySetCC(TLI.getSetCCResultType(LHSHi.getValueType()), |
| 5275 | LHSHi, RHSHi, CCCode, false, DagCombineInfo); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5276 | if (!Tmp2.getNode()) |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 5277 | Tmp2 = DAG.getNode(ISD::SETCC, |
| 5278 | TLI.getSetCCResultType(LHSHi.getValueType()), |
| 5279 | LHSHi, RHSHi,CC); |
Evan Cheng | 2e67781 | 2007-02-08 22:16:19 +0000 | [diff] [blame] | 5280 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5281 | ConstantSDNode *Tmp1C = dyn_cast<ConstantSDNode>(Tmp1.getNode()); |
| 5282 | ConstantSDNode *Tmp2C = dyn_cast<ConstantSDNode>(Tmp2.getNode()); |
Dan Gohman | 002e5d0 | 2008-03-13 22:13:53 +0000 | [diff] [blame] | 5283 | if ((Tmp1C && Tmp1C->isNullValue()) || |
| 5284 | (Tmp2C && Tmp2C->isNullValue() && |
Evan Cheng | 2e67781 | 2007-02-08 22:16:19 +0000 | [diff] [blame] | 5285 | (CCCode == ISD::SETLE || CCCode == ISD::SETGE || |
| 5286 | CCCode == ISD::SETUGE || CCCode == ISD::SETULE)) || |
Dan Gohman | 002e5d0 | 2008-03-13 22:13:53 +0000 | [diff] [blame] | 5287 | (Tmp2C && Tmp2C->getAPIntValue() == 1 && |
Evan Cheng | 2e67781 | 2007-02-08 22:16:19 +0000 | [diff] [blame] | 5288 | (CCCode == ISD::SETLT || CCCode == ISD::SETGT || |
| 5289 | CCCode == ISD::SETUGT || CCCode == ISD::SETULT))) { |
| 5290 | // low part is known false, returns high part. |
| 5291 | // For LE / GE, if high part is known false, ignore the low part. |
| 5292 | // For LT / GT, if high part is known true, ignore the low part. |
| 5293 | Tmp1 = Tmp2; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5294 | Tmp2 = SDValue(); |
Evan Cheng | 2e67781 | 2007-02-08 22:16:19 +0000 | [diff] [blame] | 5295 | } else { |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 5296 | Result = TLI.SimplifySetCC(TLI.getSetCCResultType(LHSHi.getValueType()), |
| 5297 | LHSHi, RHSHi, ISD::SETEQ, false, |
| 5298 | DagCombineInfo); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5299 | if (!Result.getNode()) |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 5300 | Result=DAG.getSetCC(TLI.getSetCCResultType(LHSHi.getValueType()), |
| 5301 | LHSHi, RHSHi, ISD::SETEQ); |
Evan Cheng | 2e67781 | 2007-02-08 22:16:19 +0000 | [diff] [blame] | 5302 | Result = LegalizeOp(DAG.getNode(ISD::SELECT, Tmp1.getValueType(), |
| 5303 | Result, Tmp1, Tmp2)); |
| 5304 | Tmp1 = Result; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5305 | Tmp2 = SDValue(); |
Evan Cheng | 2e67781 | 2007-02-08 22:16:19 +0000 | [diff] [blame] | 5306 | } |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 5307 | } |
| 5308 | } |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 5309 | } |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 5310 | LHS = Tmp1; |
| 5311 | RHS = Tmp2; |
| 5312 | } |
| 5313 | |
Evan Cheng | 7f04268 | 2008-10-15 02:05:31 +0000 | [diff] [blame] | 5314 | /// LegalizeSetCCCondCode - Legalize a SETCC with given LHS and RHS and |
| 5315 | /// condition code CC on the current target. This routine assumes LHS and rHS |
| 5316 | /// have already been legalized by LegalizeSetCCOperands. It expands SETCC with |
| 5317 | /// illegal condition code into AND / OR of multiple SETCC values. |
| 5318 | void SelectionDAGLegalize::LegalizeSetCCCondCode(MVT VT, |
| 5319 | SDValue &LHS, SDValue &RHS, |
| 5320 | SDValue &CC) { |
| 5321 | MVT OpVT = LHS.getValueType(); |
| 5322 | ISD::CondCode CCCode = cast<CondCodeSDNode>(CC)->get(); |
| 5323 | switch (TLI.getCondCodeAction(CCCode, OpVT)) { |
| 5324 | default: assert(0 && "Unknown condition code action!"); |
| 5325 | case TargetLowering::Legal: |
| 5326 | // Nothing to do. |
| 5327 | break; |
| 5328 | case TargetLowering::Expand: { |
| 5329 | ISD::CondCode CC1 = ISD::SETCC_INVALID, CC2 = ISD::SETCC_INVALID; |
| 5330 | unsigned Opc = 0; |
| 5331 | switch (CCCode) { |
| 5332 | default: assert(0 && "Don't know how to expand this condition!"); abort(); |
Dan Gohman | e7d238e | 2008-10-21 03:12:54 +0000 | [diff] [blame] | 5333 | case ISD::SETOEQ: CC1 = ISD::SETEQ; CC2 = ISD::SETO; Opc = ISD::AND; break; |
| 5334 | case ISD::SETOGT: CC1 = ISD::SETGT; CC2 = ISD::SETO; Opc = ISD::AND; break; |
| 5335 | case ISD::SETOGE: CC1 = ISD::SETGE; CC2 = ISD::SETO; Opc = ISD::AND; break; |
| 5336 | case ISD::SETOLT: CC1 = ISD::SETLT; CC2 = ISD::SETO; Opc = ISD::AND; break; |
| 5337 | case ISD::SETOLE: CC1 = ISD::SETLE; CC2 = ISD::SETO; Opc = ISD::AND; break; |
| 5338 | case ISD::SETONE: CC1 = ISD::SETNE; CC2 = ISD::SETO; Opc = ISD::AND; break; |
| 5339 | case ISD::SETUEQ: CC1 = ISD::SETEQ; CC2 = ISD::SETUO; Opc = ISD::OR; break; |
| 5340 | case ISD::SETUGT: CC1 = ISD::SETGT; CC2 = ISD::SETUO; Opc = ISD::OR; break; |
| 5341 | case ISD::SETUGE: CC1 = ISD::SETGE; CC2 = ISD::SETUO; Opc = ISD::OR; break; |
| 5342 | case ISD::SETULT: CC1 = ISD::SETLT; CC2 = ISD::SETUO; Opc = ISD::OR; break; |
| 5343 | case ISD::SETULE: CC1 = ISD::SETLE; CC2 = ISD::SETUO; Opc = ISD::OR; break; |
| 5344 | 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] | 5345 | // FIXME: Implement more expansions. |
| 5346 | } |
| 5347 | |
| 5348 | SDValue SetCC1 = DAG.getSetCC(VT, LHS, RHS, CC1); |
| 5349 | SDValue SetCC2 = DAG.getSetCC(VT, LHS, RHS, CC2); |
| 5350 | LHS = DAG.getNode(Opc, VT, SetCC1, SetCC2); |
| 5351 | RHS = SDValue(); |
| 5352 | CC = SDValue(); |
| 5353 | break; |
| 5354 | } |
| 5355 | } |
| 5356 | } |
| 5357 | |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 5358 | /// EmitStackConvert - Emit a store/load combination to the stack. This stores |
| 5359 | /// SrcOp to a stack slot of type SlotVT, truncating it if needed. It then does |
| 5360 | /// a load from the stack slot to DestVT, extending it if needed. |
| 5361 | /// The resultant code need not be legal. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5362 | SDValue SelectionDAGLegalize::EmitStackConvert(SDValue SrcOp, |
| 5363 | MVT SlotVT, |
| 5364 | MVT DestVT) { |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 5365 | // Create the stack frame object. |
Mon P Wang | 364d73d | 2008-07-05 20:40:31 +0000 | [diff] [blame] | 5366 | unsigned SrcAlign = TLI.getTargetData()->getPrefTypeAlignment( |
| 5367 | SrcOp.getValueType().getTypeForMVT()); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5368 | SDValue FIPtr = DAG.CreateStackTemporary(SlotVT, SrcAlign); |
Mon P Wang | 364d73d | 2008-07-05 20:40:31 +0000 | [diff] [blame] | 5369 | |
Dan Gohman | bbbbb9c | 2008-02-11 18:58:42 +0000 | [diff] [blame] | 5370 | FrameIndexSDNode *StackPtrFI = cast<FrameIndexSDNode>(FIPtr); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5371 | int SPFI = StackPtrFI->getIndex(); |
Dan Gohman | 15b3830 | 2009-01-29 21:02:43 +0000 | [diff] [blame] | 5372 | const Value *SV = PseudoSourceValue::getFixedStack(SPFI); |
| 5373 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5374 | unsigned SrcSize = SrcOp.getValueType().getSizeInBits(); |
| 5375 | unsigned SlotSize = SlotVT.getSizeInBits(); |
| 5376 | unsigned DestSize = DestVT.getSizeInBits(); |
Mon P Wang | 364d73d | 2008-07-05 20:40:31 +0000 | [diff] [blame] | 5377 | unsigned DestAlign = TLI.getTargetData()->getPrefTypeAlignment( |
| 5378 | DestVT.getTypeForMVT()); |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 5379 | |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 5380 | // Emit a store to the stack slot. Use a truncstore if the input value is |
| 5381 | // later than DestVT. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5382 | SDValue Store; |
Mon P Wang | 364d73d | 2008-07-05 20:40:31 +0000 | [diff] [blame] | 5383 | |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 5384 | if (SrcSize > SlotSize) |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5385 | Store = DAG.getTruncStore(DAG.getEntryNode(), SrcOp, FIPtr, |
Dan Gohman | 15b3830 | 2009-01-29 21:02:43 +0000 | [diff] [blame] | 5386 | SV, 0, SlotVT, false, SrcAlign); |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 5387 | else { |
| 5388 | assert(SrcSize == SlotSize && "Invalid store"); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5389 | Store = DAG.getStore(DAG.getEntryNode(), SrcOp, FIPtr, |
Dan Gohman | 15b3830 | 2009-01-29 21:02:43 +0000 | [diff] [blame] | 5390 | SV, 0, false, SrcAlign); |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 5391 | } |
| 5392 | |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 5393 | // Result is a load from the stack slot. |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 5394 | if (SlotSize == DestSize) |
Dan Gohman | 15b3830 | 2009-01-29 21:02:43 +0000 | [diff] [blame] | 5395 | return DAG.getLoad(DestVT, Store, FIPtr, SV, 0, false, DestAlign); |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 5396 | |
| 5397 | assert(SlotSize < DestSize && "Unknown extension!"); |
Dan Gohman | 15b3830 | 2009-01-29 21:02:43 +0000 | [diff] [blame] | 5398 | return DAG.getExtLoad(ISD::EXTLOAD, DestVT, Store, FIPtr, SV, 0, SlotVT, |
Mon P Wang | 364d73d | 2008-07-05 20:40:31 +0000 | [diff] [blame] | 5399 | false, DestAlign); |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 5400 | } |
| 5401 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5402 | SDValue SelectionDAGLegalize::ExpandSCALAR_TO_VECTOR(SDNode *Node) { |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 5403 | // Create a vector sized/aligned stack slot, store the value to element #0, |
| 5404 | // then load the whole vector back out. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5405 | SDValue StackPtr = DAG.CreateStackTemporary(Node->getValueType(0)); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5406 | |
Dan Gohman | bbbbb9c | 2008-02-11 18:58:42 +0000 | [diff] [blame] | 5407 | FrameIndexSDNode *StackPtrFI = cast<FrameIndexSDNode>(StackPtr); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5408 | int SPFI = StackPtrFI->getIndex(); |
| 5409 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5410 | SDValue Ch = DAG.getStore(DAG.getEntryNode(), Node->getOperand(0), StackPtr, |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 5411 | PseudoSourceValue::getFixedStack(SPFI), 0); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5412 | return DAG.getLoad(Node->getValueType(0), Ch, StackPtr, |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 5413 | PseudoSourceValue::getFixedStack(SPFI), 0); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 5414 | } |
| 5415 | |
| 5416 | |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5417 | /// ExpandBUILD_VECTOR - Expand a BUILD_VECTOR node on targets that don't |
Dan Gohman | 07a9676 | 2007-07-16 14:29:03 +0000 | [diff] [blame] | 5418 | /// support the operation, but do support the resultant vector type. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5419 | SDValue SelectionDAGLegalize::ExpandBUILD_VECTOR(SDNode *Node) { |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5420 | |
| 5421 | // 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] | 5422 | // 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] | 5423 | unsigned NumElems = Node->getNumOperands(); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5424 | bool isOnlyLowElement = true; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5425 | SDValue SplatValue = Node->getOperand(0); |
Chris Lattner | f9d95c8 | 2008-03-09 00:29:42 +0000 | [diff] [blame] | 5426 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5427 | // 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] | 5428 | // and use a bitmask instead of a list of elements. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5429 | std::map<SDValue, std::vector<unsigned> > Values; |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 5430 | Values[SplatValue].push_back(0); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 5431 | bool isConstant = true; |
| 5432 | if (!isa<ConstantFPSDNode>(SplatValue) && !isa<ConstantSDNode>(SplatValue) && |
| 5433 | SplatValue.getOpcode() != ISD::UNDEF) |
| 5434 | isConstant = false; |
| 5435 | |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 5436 | for (unsigned i = 1; i < NumElems; ++i) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5437 | SDValue V = Node->getOperand(i); |
Chris Lattner | 89a1b38 | 2006-04-19 23:17:50 +0000 | [diff] [blame] | 5438 | Values[V].push_back(i); |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 5439 | if (V.getOpcode() != ISD::UNDEF) |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5440 | isOnlyLowElement = false; |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 5441 | if (SplatValue != V) |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5442 | SplatValue = SDValue(0,0); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 5443 | |
| 5444 | // If this isn't a constant element or an undef, we can't use a constant |
| 5445 | // pool load. |
| 5446 | if (!isa<ConstantFPSDNode>(V) && !isa<ConstantSDNode>(V) && |
| 5447 | V.getOpcode() != ISD::UNDEF) |
| 5448 | isConstant = false; |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5449 | } |
| 5450 | |
| 5451 | if (isOnlyLowElement) { |
| 5452 | // If the low element is an undef too, then this whole things is an undef. |
| 5453 | if (Node->getOperand(0).getOpcode() == ISD::UNDEF) |
| 5454 | return DAG.getNode(ISD::UNDEF, Node->getValueType(0)); |
| 5455 | // Otherwise, turn this into a scalar_to_vector node. |
| 5456 | return DAG.getNode(ISD::SCALAR_TO_VECTOR, Node->getValueType(0), |
| 5457 | Node->getOperand(0)); |
| 5458 | } |
| 5459 | |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 5460 | // If all elements are constants, create a load from the constant pool. |
| 5461 | if (isConstant) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5462 | MVT VT = Node->getValueType(0); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 5463 | std::vector<Constant*> CV; |
| 5464 | for (unsigned i = 0, e = NumElems; i != e; ++i) { |
| 5465 | if (ConstantFPSDNode *V = |
| 5466 | dyn_cast<ConstantFPSDNode>(Node->getOperand(i))) { |
Dan Gohman | 4fbd796 | 2008-09-12 18:08:03 +0000 | [diff] [blame] | 5467 | CV.push_back(const_cast<ConstantFP *>(V->getConstantFPValue())); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 5468 | } else if (ConstantSDNode *V = |
Chris Lattner | 02a260a | 2008-04-20 00:41:09 +0000 | [diff] [blame] | 5469 | dyn_cast<ConstantSDNode>(Node->getOperand(i))) { |
Dan Gohman | 4fbd796 | 2008-09-12 18:08:03 +0000 | [diff] [blame] | 5470 | CV.push_back(const_cast<ConstantInt *>(V->getConstantIntValue())); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 5471 | } else { |
| 5472 | assert(Node->getOperand(i).getOpcode() == ISD::UNDEF); |
Chris Lattner | 02a260a | 2008-04-20 00:41:09 +0000 | [diff] [blame] | 5473 | const Type *OpNTy = |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5474 | Node->getOperand(0).getValueType().getTypeForMVT(); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 5475 | CV.push_back(UndefValue::get(OpNTy)); |
| 5476 | } |
| 5477 | } |
Reid Spencer | 9d6565a | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 5478 | Constant *CP = ConstantVector::get(CV); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5479 | SDValue CPIdx = DAG.getConstantPool(CP, TLI.getPointerTy()); |
Dan Gohman | 50284d8 | 2008-09-16 22:05:41 +0000 | [diff] [blame] | 5480 | unsigned Alignment = 1 << cast<ConstantPoolSDNode>(CPIdx)->getAlignment(); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5481 | return DAG.getLoad(VT, DAG.getEntryNode(), CPIdx, |
Dan Gohman | 50284d8 | 2008-09-16 22:05:41 +0000 | [diff] [blame] | 5482 | PseudoSourceValue::getConstantPool(), 0, |
| 5483 | false, Alignment); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 5484 | } |
| 5485 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5486 | if (SplatValue.getNode()) { // Splat of one value? |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 5487 | // Build the shuffle constant vector: <0, 0, 0, 0> |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5488 | MVT MaskVT = MVT::getIntVectorWithNumElements(NumElems); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5489 | SDValue Zero = DAG.getConstant(0, MaskVT.getVectorElementType()); |
| 5490 | std::vector<SDValue> ZeroVec(NumElems, Zero); |
| 5491 | SDValue SplatMask = DAG.getNode(ISD::BUILD_VECTOR, MaskVT, |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 5492 | &ZeroVec[0], ZeroVec.size()); |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 5493 | |
| 5494 | // If the target supports VECTOR_SHUFFLE and this shuffle mask, use it. |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 5495 | if (isShuffleLegal(Node->getValueType(0), SplatMask)) { |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 5496 | // Get the splatted value into the low element of a vector register. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5497 | SDValue LowValVec = |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 5498 | DAG.getNode(ISD::SCALAR_TO_VECTOR, Node->getValueType(0), SplatValue); |
| 5499 | |
| 5500 | // Return shuffle(LowValVec, undef, <0,0,0,0>) |
| 5501 | return DAG.getNode(ISD::VECTOR_SHUFFLE, Node->getValueType(0), LowValVec, |
| 5502 | DAG.getNode(ISD::UNDEF, Node->getValueType(0)), |
| 5503 | SplatMask); |
| 5504 | } |
| 5505 | } |
| 5506 | |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 5507 | // If there are only two unique elements, we may be able to turn this into a |
| 5508 | // vector shuffle. |
| 5509 | if (Values.size() == 2) { |
Chris Lattner | f9d95c8 | 2008-03-09 00:29:42 +0000 | [diff] [blame] | 5510 | // Get the two values in deterministic order. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5511 | SDValue Val1 = Node->getOperand(1); |
| 5512 | SDValue Val2; |
| 5513 | std::map<SDValue, std::vector<unsigned> >::iterator MI = Values.begin(); |
Chris Lattner | f9d95c8 | 2008-03-09 00:29:42 +0000 | [diff] [blame] | 5514 | if (MI->first != Val1) |
| 5515 | Val2 = MI->first; |
| 5516 | else |
| 5517 | Val2 = (++MI)->first; |
| 5518 | |
| 5519 | // If Val1 is an undef, make sure end ends up as Val2, to ensure that our |
| 5520 | // vector shuffle has the undef vector on the RHS. |
| 5521 | if (Val1.getOpcode() == ISD::UNDEF) |
| 5522 | std::swap(Val1, Val2); |
| 5523 | |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 5524 | // Build the shuffle constant vector: e.g. <0, 4, 0, 4> |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5525 | MVT MaskVT = MVT::getIntVectorWithNumElements(NumElems); |
| 5526 | MVT MaskEltVT = MaskVT.getVectorElementType(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5527 | std::vector<SDValue> MaskVec(NumElems); |
Chris Lattner | f9d95c8 | 2008-03-09 00:29:42 +0000 | [diff] [blame] | 5528 | |
| 5529 | // Set elements of the shuffle mask for Val1. |
| 5530 | std::vector<unsigned> &Val1Elts = Values[Val1]; |
| 5531 | for (unsigned i = 0, e = Val1Elts.size(); i != e; ++i) |
| 5532 | MaskVec[Val1Elts[i]] = DAG.getConstant(0, MaskEltVT); |
| 5533 | |
| 5534 | // Set elements of the shuffle mask for Val2. |
| 5535 | std::vector<unsigned> &Val2Elts = Values[Val2]; |
| 5536 | for (unsigned i = 0, e = Val2Elts.size(); i != e; ++i) |
| 5537 | if (Val2.getOpcode() != ISD::UNDEF) |
| 5538 | MaskVec[Val2Elts[i]] = DAG.getConstant(NumElems, MaskEltVT); |
| 5539 | else |
| 5540 | MaskVec[Val2Elts[i]] = DAG.getNode(ISD::UNDEF, MaskEltVT); |
| 5541 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5542 | SDValue ShuffleMask = DAG.getNode(ISD::BUILD_VECTOR, MaskVT, |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 5543 | &MaskVec[0], MaskVec.size()); |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 5544 | |
Chris Lattner | f9d95c8 | 2008-03-09 00:29:42 +0000 | [diff] [blame] | 5545 | // If the target supports SCALAR_TO_VECTOR and this shuffle mask, use it. |
Dan Gohman | f560ffa | 2009-01-28 17:46:25 +0000 | [diff] [blame] | 5546 | if (TLI.isOperationLegalOrCustom(ISD::SCALAR_TO_VECTOR, |
| 5547 | Node->getValueType(0)) && |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 5548 | isShuffleLegal(Node->getValueType(0), ShuffleMask)) { |
Chris Lattner | f9d95c8 | 2008-03-09 00:29:42 +0000 | [diff] [blame] | 5549 | Val1 = DAG.getNode(ISD::SCALAR_TO_VECTOR, Node->getValueType(0), Val1); |
| 5550 | Val2 = DAG.getNode(ISD::SCALAR_TO_VECTOR, Node->getValueType(0), Val2); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5551 | SDValue Ops[] = { Val1, Val2, ShuffleMask }; |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 5552 | |
| 5553 | // Return shuffle(LoValVec, HiValVec, <0,1,0,1>) |
Chris Lattner | f9d95c8 | 2008-03-09 00:29:42 +0000 | [diff] [blame] | 5554 | return DAG.getNode(ISD::VECTOR_SHUFFLE, Node->getValueType(0), Ops, 3); |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 5555 | } |
| 5556 | } |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5557 | |
| 5558 | // Otherwise, we can't handle this case efficiently. Allocate a sufficiently |
| 5559 | // aligned object on the stack, store each element into it, then load |
| 5560 | // the result as a vector. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5561 | MVT VT = Node->getValueType(0); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5562 | // Create the stack frame object. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5563 | SDValue FIPtr = DAG.CreateStackTemporary(VT); |
Dan Gohman | 15b3830 | 2009-01-29 21:02:43 +0000 | [diff] [blame] | 5564 | int FI = cast<FrameIndexSDNode>(FIPtr.getNode())->getIndex(); |
| 5565 | const Value *SV = PseudoSourceValue::getFixedStack(FI); |
| 5566 | |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5567 | // Emit a store of each element to the stack slot. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5568 | SmallVector<SDValue, 8> Stores; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5569 | unsigned TypeByteSize = Node->getOperand(0).getValueType().getSizeInBits()/8; |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5570 | // Store (in the right endianness) the elements to memory. |
| 5571 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) { |
| 5572 | // Ignore undef elements. |
| 5573 | if (Node->getOperand(i).getOpcode() == ISD::UNDEF) continue; |
| 5574 | |
Chris Lattner | 841c882 | 2006-03-22 01:46:54 +0000 | [diff] [blame] | 5575 | unsigned Offset = TypeByteSize*i; |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5576 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5577 | SDValue Idx = DAG.getConstant(Offset, FIPtr.getValueType()); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5578 | Idx = DAG.getNode(ISD::ADD, FIPtr.getValueType(), FIPtr, Idx); |
| 5579 | |
Evan Cheng | 786225a | 2006-10-05 23:01:46 +0000 | [diff] [blame] | 5580 | Stores.push_back(DAG.getStore(DAG.getEntryNode(), Node->getOperand(i), Idx, |
Dan Gohman | 15b3830 | 2009-01-29 21:02:43 +0000 | [diff] [blame] | 5581 | SV, Offset)); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5582 | } |
| 5583 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5584 | SDValue StoreChain; |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5585 | if (!Stores.empty()) // Not all undef elements? |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 5586 | StoreChain = DAG.getNode(ISD::TokenFactor, MVT::Other, |
| 5587 | &Stores[0], Stores.size()); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5588 | else |
| 5589 | StoreChain = DAG.getEntryNode(); |
| 5590 | |
| 5591 | // Result is a load from the stack slot. |
Dan Gohman | 15b3830 | 2009-01-29 21:02:43 +0000 | [diff] [blame] | 5592 | return DAG.getLoad(VT, StoreChain, FIPtr, SV, 0); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5593 | } |
| 5594 | |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 5595 | void SelectionDAGLegalize::ExpandShiftParts(unsigned NodeOp, |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5596 | SDValue Op, SDValue Amt, |
| 5597 | SDValue &Lo, SDValue &Hi) { |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 5598 | // Expand the subcomponents. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5599 | SDValue LHSL, LHSH; |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 5600 | ExpandOp(Op, LHSL, LHSH); |
| 5601 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5602 | SDValue Ops[] = { LHSL, LHSH, Amt }; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5603 | MVT VT = LHSL.getValueType(); |
Chris Lattner | f9f37fc | 2006-08-14 23:53:35 +0000 | [diff] [blame] | 5604 | Lo = DAG.getNode(NodeOp, DAG.getNodeValueTypes(VT, VT), 2, Ops, 3); |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 5605 | Hi = Lo.getValue(1); |
| 5606 | } |
| 5607 | |
| 5608 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5609 | /// ExpandShift - Try to find a clever way to expand this shift operation out to |
| 5610 | /// smaller elements. If we can't find a way that is more efficient than a |
| 5611 | /// libcall on this target, return false. Otherwise, return true with the |
| 5612 | /// low-parts expanded into Lo and Hi. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5613 | bool SelectionDAGLegalize::ExpandShift(unsigned Opc, SDValue Op,SDValue Amt, |
| 5614 | SDValue &Lo, SDValue &Hi) { |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5615 | assert((Opc == ISD::SHL || Opc == ISD::SRA || Opc == ISD::SRL) && |
| 5616 | "This is not a shift!"); |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5617 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5618 | MVT NVT = TLI.getTypeToTransformTo(Op.getValueType()); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5619 | SDValue ShAmt = LegalizeOp(Amt); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5620 | MVT ShTy = ShAmt.getValueType(); |
| 5621 | unsigned ShBits = ShTy.getSizeInBits(); |
| 5622 | unsigned VTBits = Op.getValueType().getSizeInBits(); |
| 5623 | unsigned NVTBits = NVT.getSizeInBits(); |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5624 | |
Chris Lattner | 7a3c855 | 2007-10-14 20:35:12 +0000 | [diff] [blame] | 5625 | // Handle the case when Amt is an immediate. |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5626 | if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Amt.getNode())) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 5627 | unsigned Cst = CN->getZExtValue(); |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5628 | // 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] | 5629 | SDValue InL, InH; |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5630 | ExpandOp(Op, InL, InH); |
| 5631 | switch(Opc) { |
| 5632 | case ISD::SHL: |
| 5633 | if (Cst > VTBits) { |
| 5634 | Lo = DAG.getConstant(0, NVT); |
| 5635 | Hi = DAG.getConstant(0, NVT); |
| 5636 | } else if (Cst > NVTBits) { |
| 5637 | Lo = DAG.getConstant(0, NVT); |
| 5638 | Hi = DAG.getNode(ISD::SHL, NVT, InL, DAG.getConstant(Cst-NVTBits,ShTy)); |
Chris Lattner | ee27f57 | 2005-04-11 20:08:52 +0000 | [diff] [blame] | 5639 | } else if (Cst == NVTBits) { |
| 5640 | Lo = DAG.getConstant(0, NVT); |
| 5641 | Hi = InL; |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5642 | } else { |
| 5643 | Lo = DAG.getNode(ISD::SHL, NVT, InL, DAG.getConstant(Cst, ShTy)); |
| 5644 | Hi = DAG.getNode(ISD::OR, NVT, |
| 5645 | DAG.getNode(ISD::SHL, NVT, InH, DAG.getConstant(Cst, ShTy)), |
| 5646 | DAG.getNode(ISD::SRL, NVT, InL, DAG.getConstant(NVTBits-Cst, ShTy))); |
| 5647 | } |
| 5648 | return true; |
| 5649 | case ISD::SRL: |
| 5650 | if (Cst > VTBits) { |
| 5651 | Lo = DAG.getConstant(0, NVT); |
| 5652 | Hi = DAG.getConstant(0, NVT); |
| 5653 | } else if (Cst > NVTBits) { |
| 5654 | Lo = DAG.getNode(ISD::SRL, NVT, InH, DAG.getConstant(Cst-NVTBits,ShTy)); |
| 5655 | Hi = DAG.getConstant(0, NVT); |
Chris Lattner | ee27f57 | 2005-04-11 20:08:52 +0000 | [diff] [blame] | 5656 | } else if (Cst == NVTBits) { |
| 5657 | Lo = InH; |
| 5658 | Hi = DAG.getConstant(0, NVT); |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5659 | } else { |
| 5660 | Lo = DAG.getNode(ISD::OR, NVT, |
| 5661 | DAG.getNode(ISD::SRL, NVT, InL, DAG.getConstant(Cst, ShTy)), |
| 5662 | DAG.getNode(ISD::SHL, NVT, InH, DAG.getConstant(NVTBits-Cst, ShTy))); |
| 5663 | Hi = DAG.getNode(ISD::SRL, NVT, InH, DAG.getConstant(Cst, ShTy)); |
| 5664 | } |
| 5665 | return true; |
| 5666 | case ISD::SRA: |
| 5667 | if (Cst > VTBits) { |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 5668 | Hi = Lo = DAG.getNode(ISD::SRA, NVT, InH, |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5669 | DAG.getConstant(NVTBits-1, ShTy)); |
| 5670 | } else if (Cst > NVTBits) { |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 5671 | Lo = DAG.getNode(ISD::SRA, NVT, InH, |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5672 | DAG.getConstant(Cst-NVTBits, ShTy)); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 5673 | Hi = DAG.getNode(ISD::SRA, NVT, InH, |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5674 | DAG.getConstant(NVTBits-1, ShTy)); |
Chris Lattner | ee27f57 | 2005-04-11 20:08:52 +0000 | [diff] [blame] | 5675 | } else if (Cst == NVTBits) { |
| 5676 | Lo = InH; |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 5677 | Hi = DAG.getNode(ISD::SRA, NVT, InH, |
Chris Lattner | ee27f57 | 2005-04-11 20:08:52 +0000 | [diff] [blame] | 5678 | DAG.getConstant(NVTBits-1, ShTy)); |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5679 | } else { |
| 5680 | Lo = DAG.getNode(ISD::OR, NVT, |
| 5681 | DAG.getNode(ISD::SRL, NVT, InL, DAG.getConstant(Cst, ShTy)), |
| 5682 | DAG.getNode(ISD::SHL, NVT, InH, DAG.getConstant(NVTBits-Cst, ShTy))); |
| 5683 | Hi = DAG.getNode(ISD::SRA, NVT, InH, DAG.getConstant(Cst, ShTy)); |
| 5684 | } |
| 5685 | return true; |
| 5686 | } |
| 5687 | } |
Chris Lattner | 0ea26ca | 2006-09-20 03:38:48 +0000 | [diff] [blame] | 5688 | |
| 5689 | // Okay, the shift amount isn't constant. However, if we can tell that it is |
| 5690 | // >= 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] | 5691 | APInt Mask = APInt::getHighBitsSet(ShBits, ShBits - Log2_32(NVTBits)); |
| 5692 | APInt KnownZero, KnownOne; |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 5693 | DAG.ComputeMaskedBits(Amt, Mask, KnownZero, KnownOne); |
Chris Lattner | 0ea26ca | 2006-09-20 03:38:48 +0000 | [diff] [blame] | 5694 | |
Dan Gohman | 9e255b7 | 2008-02-22 01:12:31 +0000 | [diff] [blame] | 5695 | // If we know that if any of the high bits of the shift amount are one, then |
| 5696 | // we can do this as a couple of simple shifts. |
Dan Gohman | 91dc17b | 2008-02-20 16:57:27 +0000 | [diff] [blame] | 5697 | if (KnownOne.intersects(Mask)) { |
Chris Lattner | 0ea26ca | 2006-09-20 03:38:48 +0000 | [diff] [blame] | 5698 | // Mask out the high bit, which we know is set. |
| 5699 | Amt = DAG.getNode(ISD::AND, Amt.getValueType(), Amt, |
Dan Gohman | 91dc17b | 2008-02-20 16:57:27 +0000 | [diff] [blame] | 5700 | DAG.getConstant(~Mask, Amt.getValueType())); |
Chris Lattner | 0ea26ca | 2006-09-20 03:38:48 +0000 | [diff] [blame] | 5701 | |
| 5702 | // 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] | 5703 | SDValue InL, InH; |
Chris Lattner | 0ea26ca | 2006-09-20 03:38:48 +0000 | [diff] [blame] | 5704 | ExpandOp(Op, InL, InH); |
| 5705 | switch(Opc) { |
| 5706 | case ISD::SHL: |
| 5707 | Lo = DAG.getConstant(0, NVT); // Low part is zero. |
| 5708 | Hi = DAG.getNode(ISD::SHL, NVT, InL, Amt); // High part from Lo part. |
| 5709 | return true; |
| 5710 | case ISD::SRL: |
| 5711 | Hi = DAG.getConstant(0, NVT); // Hi part is zero. |
| 5712 | Lo = DAG.getNode(ISD::SRL, NVT, InH, Amt); // Lo part from Hi part. |
| 5713 | return true; |
| 5714 | case ISD::SRA: |
| 5715 | Hi = DAG.getNode(ISD::SRA, NVT, InH, // Sign extend high part. |
| 5716 | DAG.getConstant(NVTBits-1, Amt.getValueType())); |
| 5717 | Lo = DAG.getNode(ISD::SRA, NVT, InH, Amt); // Lo part from Hi part. |
| 5718 | return true; |
| 5719 | } |
| 5720 | } |
| 5721 | |
Dan Gohman | 9e255b7 | 2008-02-22 01:12:31 +0000 | [diff] [blame] | 5722 | // If we know that the high bits of the shift amount are all zero, then we can |
| 5723 | // do this as a couple of simple shifts. |
| 5724 | if ((KnownZero & Mask) == Mask) { |
Chris Lattner | 0ea26ca | 2006-09-20 03:38:48 +0000 | [diff] [blame] | 5725 | // Compute 32-amt. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5726 | SDValue Amt2 = DAG.getNode(ISD::SUB, Amt.getValueType(), |
Chris Lattner | 0ea26ca | 2006-09-20 03:38:48 +0000 | [diff] [blame] | 5727 | DAG.getConstant(NVTBits, Amt.getValueType()), |
| 5728 | Amt); |
| 5729 | |
| 5730 | // 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] | 5731 | SDValue InL, InH; |
Chris Lattner | 0ea26ca | 2006-09-20 03:38:48 +0000 | [diff] [blame] | 5732 | ExpandOp(Op, InL, InH); |
| 5733 | switch(Opc) { |
| 5734 | case ISD::SHL: |
| 5735 | Lo = DAG.getNode(ISD::SHL, NVT, InL, Amt); |
| 5736 | Hi = DAG.getNode(ISD::OR, NVT, |
| 5737 | DAG.getNode(ISD::SHL, NVT, InH, Amt), |
| 5738 | DAG.getNode(ISD::SRL, NVT, InL, Amt2)); |
| 5739 | return true; |
| 5740 | case ISD::SRL: |
| 5741 | Hi = DAG.getNode(ISD::SRL, NVT, InH, Amt); |
| 5742 | Lo = DAG.getNode(ISD::OR, NVT, |
| 5743 | DAG.getNode(ISD::SRL, NVT, InL, Amt), |
| 5744 | DAG.getNode(ISD::SHL, NVT, InH, Amt2)); |
| 5745 | return true; |
| 5746 | case ISD::SRA: |
| 5747 | Hi = DAG.getNode(ISD::SRA, NVT, InH, Amt); |
| 5748 | Lo = DAG.getNode(ISD::OR, NVT, |
| 5749 | DAG.getNode(ISD::SRL, NVT, InL, Amt), |
| 5750 | DAG.getNode(ISD::SHL, NVT, InH, Amt2)); |
| 5751 | return true; |
| 5752 | } |
| 5753 | } |
| 5754 | |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5755 | return false; |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5756 | } |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5757 | |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 5758 | |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5759 | // ExpandLibCall - Expand a node into a call to a libcall. If the result value |
| 5760 | // does not fit into a register, return the lo part and set the hi part to the |
| 5761 | // by-reg argument. If it does fit into a single register, return the result |
| 5762 | // and leave the Hi part unset. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5763 | SDValue SelectionDAGLegalize::ExpandLibCall(RTLIB::Libcall LC, SDNode *Node, |
| 5764 | bool isSigned, SDValue &Hi) { |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 5765 | assert(!IsLegalizingCall && "Cannot overlap legalization of calls!"); |
| 5766 | // The input chain to this libcall is the entry node of the function. |
| 5767 | // Legalizing the call will automatically add the previous call to the |
| 5768 | // dependence. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5769 | SDValue InChain = DAG.getEntryNode(); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 5770 | |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5771 | TargetLowering::ArgListTy Args; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 5772 | TargetLowering::ArgListEntry Entry; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5773 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5774 | MVT ArgVT = Node->getOperand(i).getValueType(); |
| 5775 | const Type *ArgTy = ArgVT.getTypeForMVT(); |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 5776 | Entry.Node = Node->getOperand(i); Entry.Ty = ArgTy; |
Anton Korobeynikov | d0b82b3 | 2007-03-07 16:25:09 +0000 | [diff] [blame] | 5777 | Entry.isSExt = isSigned; |
Duncan Sands | 00fee65 | 2008-02-14 17:28:50 +0000 | [diff] [blame] | 5778 | Entry.isZExt = !isSigned; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 5779 | Args.push_back(Entry); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5780 | } |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 5781 | SDValue Callee = DAG.getExternalSymbol(TLI.getLibcallName(LC), |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 5782 | TLI.getPointerTy()); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 5783 | |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 5784 | // Splice the libcall in wherever FindInputOutputChains tells us to. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5785 | const Type *RetTy = Node->getValueType(0).getTypeForMVT(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5786 | std::pair<SDValue,SDValue> CallInfo = |
Dale Johannesen | 86098bd | 2008-09-26 19:31:26 +0000 | [diff] [blame] | 5787 | TLI.LowerCallTo(InChain, RetTy, isSigned, !isSigned, false, false, |
Dale Johannesen | 7d2ad62 | 2009-01-30 23:10:59 +0000 | [diff] [blame] | 5788 | CallingConv::C, false, Callee, Args, DAG, |
| 5789 | Node->getDebugLoc()); |
Chris Lattner | b9fa3bc | 2005-05-12 04:49:08 +0000 | [diff] [blame] | 5790 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 5791 | // Legalize the call sequence, starting with the chain. This will advance |
| 5792 | // the LastCALLSEQ_END to the legalized version of the CALLSEQ_END node that |
| 5793 | // was added by LowerCallTo (guaranteeing proper serialization of calls). |
| 5794 | LegalizeOp(CallInfo.second); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5795 | SDValue Result; |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 5796 | switch (getTypeAction(CallInfo.first.getValueType())) { |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5797 | default: assert(0 && "Unknown thing"); |
| 5798 | case Legal: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 5799 | Result = CallInfo.first; |
Chris Lattner | 99c25b8 | 2005-09-02 20:26:58 +0000 | [diff] [blame] | 5800 | break; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5801 | case Expand: |
Chris Lattner | 99c25b8 | 2005-09-02 20:26:58 +0000 | [diff] [blame] | 5802 | ExpandOp(CallInfo.first, Result, Hi); |
Chris Lattner | 99c25b8 | 2005-09-02 20:26:58 +0000 | [diff] [blame] | 5803 | break; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5804 | } |
Chris Lattner | 99c25b8 | 2005-09-02 20:26:58 +0000 | [diff] [blame] | 5805 | return Result; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5806 | } |
| 5807 | |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 5808 | /// LegalizeINT_TO_FP - Legalize a [US]INT_TO_FP operation. |
| 5809 | /// |
| 5810 | SDValue SelectionDAGLegalize:: |
| 5811 | LegalizeINT_TO_FP(SDValue Result, bool isSigned, MVT DestTy, SDValue Op) { |
| 5812 | bool isCustom = false; |
| 5813 | SDValue Tmp1; |
| 5814 | switch (getTypeAction(Op.getValueType())) { |
| 5815 | case Legal: |
| 5816 | switch (TLI.getOperationAction(isSigned ? ISD::SINT_TO_FP : ISD::UINT_TO_FP, |
| 5817 | Op.getValueType())) { |
| 5818 | default: assert(0 && "Unknown operation action!"); |
| 5819 | case TargetLowering::Custom: |
| 5820 | isCustom = true; |
| 5821 | // FALLTHROUGH |
| 5822 | case TargetLowering::Legal: |
| 5823 | Tmp1 = LegalizeOp(Op); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5824 | if (Result.getNode()) |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 5825 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 5826 | else |
| 5827 | Result = DAG.getNode(isSigned ? ISD::SINT_TO_FP : ISD::UINT_TO_FP, |
| 5828 | DestTy, Tmp1); |
| 5829 | if (isCustom) { |
| 5830 | Tmp1 = TLI.LowerOperation(Result, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5831 | if (Tmp1.getNode()) Result = Tmp1; |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 5832 | } |
| 5833 | break; |
| 5834 | case TargetLowering::Expand: |
| 5835 | Result = ExpandLegalINT_TO_FP(isSigned, LegalizeOp(Op), DestTy); |
| 5836 | break; |
| 5837 | case TargetLowering::Promote: |
| 5838 | Result = PromoteLegalINT_TO_FP(LegalizeOp(Op), DestTy, isSigned); |
| 5839 | break; |
| 5840 | } |
| 5841 | break; |
| 5842 | case Expand: |
| 5843 | Result = ExpandIntToFP(isSigned, DestTy, Op); |
| 5844 | break; |
| 5845 | case Promote: |
| 5846 | Tmp1 = PromoteOp(Op); |
| 5847 | if (isSigned) { |
| 5848 | Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, Tmp1.getValueType(), |
| 5849 | Tmp1, DAG.getValueType(Op.getValueType())); |
| 5850 | } else { |
| 5851 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, |
| 5852 | Op.getValueType()); |
| 5853 | } |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5854 | if (Result.getNode()) |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 5855 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 5856 | else |
| 5857 | Result = DAG.getNode(isSigned ? ISD::SINT_TO_FP : ISD::UINT_TO_FP, |
| 5858 | DestTy, Tmp1); |
| 5859 | Result = LegalizeOp(Result); // The 'op' is not necessarily legal! |
| 5860 | break; |
| 5861 | } |
| 5862 | return Result; |
| 5863 | } |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 5864 | |
Evan Cheng | 4c6cfad | 2007-04-27 07:33:31 +0000 | [diff] [blame] | 5865 | /// ExpandIntToFP - Expand a [US]INT_TO_FP operation. |
| 5866 | /// |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5867 | SDValue SelectionDAGLegalize:: |
| 5868 | ExpandIntToFP(bool isSigned, MVT DestTy, SDValue Source) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5869 | MVT SourceVT = Source.getValueType(); |
Dan Gohman | 034f60e | 2008-03-11 01:59:03 +0000 | [diff] [blame] | 5870 | bool ExpandSource = getTypeAction(SourceVT) == Expand; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5871 | |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 5872 | // Expand unsupported int-to-fp vector casts by unrolling them. |
| 5873 | if (DestTy.isVector()) { |
| 5874 | if (!ExpandSource) |
| 5875 | return LegalizeOp(UnrollVectorOp(Source)); |
| 5876 | MVT DestEltTy = DestTy.getVectorElementType(); |
| 5877 | if (DestTy.getVectorNumElements() == 1) { |
| 5878 | SDValue Scalar = ScalarizeVectorOp(Source); |
| 5879 | SDValue Result = LegalizeINT_TO_FP(SDValue(), isSigned, |
| 5880 | DestEltTy, Scalar); |
| 5881 | return DAG.getNode(ISD::BUILD_VECTOR, DestTy, Result); |
| 5882 | } |
| 5883 | SDValue Lo, Hi; |
| 5884 | SplitVectorOp(Source, Lo, Hi); |
| 5885 | MVT SplitDestTy = MVT::getVectorVT(DestEltTy, |
| 5886 | DestTy.getVectorNumElements() / 2); |
| 5887 | SDValue LoResult = LegalizeINT_TO_FP(SDValue(), isSigned, SplitDestTy, Lo); |
| 5888 | SDValue HiResult = LegalizeINT_TO_FP(SDValue(), isSigned, SplitDestTy, Hi); |
Evan Cheng | efa5339 | 2008-10-13 18:46:18 +0000 | [diff] [blame] | 5889 | return LegalizeOp(DAG.getNode(ISD::CONCAT_VECTORS, DestTy, LoResult, |
| 5890 | HiResult)); |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 5891 | } |
| 5892 | |
Evan Cheng | 9845eb5 | 2008-04-01 02:18:22 +0000 | [diff] [blame] | 5893 | // Special case for i32 source to take advantage of UINTTOFP_I32_F32, etc. |
| 5894 | if (!isSigned && SourceVT != MVT::i32) { |
Dan Gohman | 34bc178 | 2008-03-05 02:07:31 +0000 | [diff] [blame] | 5895 | // 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] | 5896 | // incoming integer is set. To handle this, we dynamically test to see if |
| 5897 | // it is set, and, if so, add a fudge factor. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5898 | SDValue Hi; |
Dan Gohman | 034f60e | 2008-03-11 01:59:03 +0000 | [diff] [blame] | 5899 | if (ExpandSource) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5900 | SDValue Lo; |
Dan Gohman | 034f60e | 2008-03-11 01:59:03 +0000 | [diff] [blame] | 5901 | ExpandOp(Source, Lo, Hi); |
| 5902 | Source = DAG.getNode(ISD::BUILD_PAIR, SourceVT, Lo, Hi); |
| 5903 | } else { |
| 5904 | // The comparison for the sign bit will use the entire operand. |
| 5905 | Hi = Source; |
| 5906 | } |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 5907 | |
Dale Johannesen | 53997b0 | 2008-11-04 20:52:49 +0000 | [diff] [blame] | 5908 | // Check to see if the target has a custom way to lower this. If so, use |
| 5909 | // it. (Note we've already expanded the operand in this case.) |
Dale Johannesen | 1c15bf5 | 2008-10-21 20:50:01 +0000 | [diff] [blame] | 5910 | switch (TLI.getOperationAction(ISD::UINT_TO_FP, SourceVT)) { |
| 5911 | default: assert(0 && "This action not implemented for this operation!"); |
| 5912 | case TargetLowering::Legal: |
| 5913 | case TargetLowering::Expand: |
| 5914 | break; // This case is handled below. |
| 5915 | case TargetLowering::Custom: { |
| 5916 | SDValue NV = TLI.LowerOperation(DAG.getNode(ISD::UINT_TO_FP, DestTy, |
| 5917 | Source), DAG); |
| 5918 | if (NV.getNode()) |
| 5919 | return LegalizeOp(NV); |
| 5920 | break; // The target decided this was legal after all |
| 5921 | } |
| 5922 | } |
| 5923 | |
Chris Lattner | 66de05b | 2005-05-13 04:45:13 +0000 | [diff] [blame] | 5924 | // If this is unsigned, and not supported, first perform the conversion to |
| 5925 | // signed, then adjust the result if the sign bit is set. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5926 | SDValue SignedConv = ExpandIntToFP(true, DestTy, Source); |
Chris Lattner | 66de05b | 2005-05-13 04:45:13 +0000 | [diff] [blame] | 5927 | |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 5928 | SDValue SignSet = DAG.getSetCC(TLI.getSetCCResultType(Hi.getValueType()), |
| 5929 | Hi, DAG.getConstant(0, Hi.getValueType()), |
| 5930 | ISD::SETLT); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5931 | SDValue Zero = DAG.getIntPtrConstant(0), Four = DAG.getIntPtrConstant(4); |
| 5932 | SDValue CstOffset = DAG.getNode(ISD::SELECT, Zero.getValueType(), |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 5933 | SignSet, Four, Zero); |
Chris Lattner | 383203b | 2005-05-12 18:52:34 +0000 | [diff] [blame] | 5934 | uint64_t FF = 0x5f800000ULL; |
| 5935 | if (TLI.isLittleEndian()) FF <<= 32; |
Dan Gohman | 34bc178 | 2008-03-05 02:07:31 +0000 | [diff] [blame] | 5936 | static Constant *FudgeFactor = ConstantInt::get(Type::Int64Ty, FF); |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 5937 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5938 | SDValue CPIdx = DAG.getConstantPool(FudgeFactor, TLI.getPointerTy()); |
Dan Gohman | 50284d8 | 2008-09-16 22:05:41 +0000 | [diff] [blame] | 5939 | unsigned Alignment = 1 << cast<ConstantPoolSDNode>(CPIdx)->getAlignment(); |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 5940 | CPIdx = DAG.getNode(ISD::ADD, TLI.getPointerTy(), CPIdx, CstOffset); |
Dan Gohman | 87a0f10 | 2008-09-22 22:40:08 +0000 | [diff] [blame] | 5941 | Alignment = std::min(Alignment, 4u); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5942 | SDValue FudgeInReg; |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 5943 | if (DestTy == MVT::f32) |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5944 | FudgeInReg = DAG.getLoad(MVT::f32, DAG.getEntryNode(), CPIdx, |
Dan Gohman | 50284d8 | 2008-09-16 22:05:41 +0000 | [diff] [blame] | 5945 | PseudoSourceValue::getConstantPool(), 0, |
| 5946 | false, Alignment); |
Duncan Sands | 8e4eb09 | 2008-06-08 20:54:56 +0000 | [diff] [blame] | 5947 | else if (DestTy.bitsGT(MVT::f32)) |
Evan Cheng | 4c6cfad | 2007-04-27 07:33:31 +0000 | [diff] [blame] | 5948 | // FIXME: Avoid the extend by construction the right constantpool? |
Dale Johannesen | 118cd9d | 2007-09-16 16:51:49 +0000 | [diff] [blame] | 5949 | FudgeInReg = DAG.getExtLoad(ISD::EXTLOAD, DestTy, DAG.getEntryNode(), |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5950 | CPIdx, |
Dan Gohman | 3069b87 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 5951 | PseudoSourceValue::getConstantPool(), 0, |
Dan Gohman | 50284d8 | 2008-09-16 22:05:41 +0000 | [diff] [blame] | 5952 | MVT::f32, false, Alignment); |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 5953 | else |
| 5954 | assert(0 && "Unexpected conversion"); |
| 5955 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5956 | MVT SCVT = SignedConv.getValueType(); |
Evan Cheng | 4c6cfad | 2007-04-27 07:33:31 +0000 | [diff] [blame] | 5957 | if (SCVT != DestTy) { |
| 5958 | // Destination type needs to be expanded as well. The FADD now we are |
| 5959 | // constructing will be expanded into a libcall. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 5960 | if (SCVT.getSizeInBits() != DestTy.getSizeInBits()) { |
| 5961 | assert(SCVT.getSizeInBits() * 2 == DestTy.getSizeInBits()); |
Dan Gohman | d91446d | 2008-03-05 01:08:17 +0000 | [diff] [blame] | 5962 | SignedConv = DAG.getNode(ISD::BUILD_PAIR, DestTy, |
Evan Cheng | 4c6cfad | 2007-04-27 07:33:31 +0000 | [diff] [blame] | 5963 | SignedConv, SignedConv.getValue(1)); |
| 5964 | } |
| 5965 | SignedConv = DAG.getNode(ISD::BIT_CONVERT, DestTy, SignedConv); |
| 5966 | } |
Chris Lattner | 473a990 | 2005-09-29 06:44:39 +0000 | [diff] [blame] | 5967 | return DAG.getNode(ISD::FADD, DestTy, SignedConv, FudgeInReg); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5968 | } |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 5969 | |
Chris Lattner | a88a260 | 2005-05-14 05:33:54 +0000 | [diff] [blame] | 5970 | // 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] | 5971 | switch (TLI.getOperationAction(ISD::SINT_TO_FP, SourceVT)) { |
Chris Lattner | a88a260 | 2005-05-14 05:33:54 +0000 | [diff] [blame] | 5972 | default: assert(0 && "This action not implemented for this operation!"); |
| 5973 | case TargetLowering::Legal: |
| 5974 | case TargetLowering::Expand: |
| 5975 | break; // This case is handled below. |
Chris Lattner | 07dffd6 | 2005-08-26 00:14:16 +0000 | [diff] [blame] | 5976 | case TargetLowering::Custom: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5977 | SDValue NV = TLI.LowerOperation(DAG.getNode(ISD::SINT_TO_FP, DestTy, |
Chris Lattner | 07dffd6 | 2005-08-26 00:14:16 +0000 | [diff] [blame] | 5978 | Source), DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5979 | if (NV.getNode()) |
Chris Lattner | 07dffd6 | 2005-08-26 00:14:16 +0000 | [diff] [blame] | 5980 | return LegalizeOp(NV); |
| 5981 | break; // The target decided this was legal after all |
| 5982 | } |
Chris Lattner | a88a260 | 2005-05-14 05:33:54 +0000 | [diff] [blame] | 5983 | } |
| 5984 | |
Chris Lattner | 13689e2 | 2005-05-12 07:00:44 +0000 | [diff] [blame] | 5985 | // Expand the source, then glue it back together for the call. We must expand |
| 5986 | // 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] | 5987 | if (ExpandSource) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5988 | SDValue SrcLo, SrcHi; |
Dan Gohman | 034f60e | 2008-03-11 01:59:03 +0000 | [diff] [blame] | 5989 | ExpandOp(Source, SrcLo, SrcHi); |
| 5990 | Source = DAG.getNode(ISD::BUILD_PAIR, SourceVT, SrcLo, SrcHi); |
| 5991 | } |
Chris Lattner | 13689e2 | 2005-05-12 07:00:44 +0000 | [diff] [blame] | 5992 | |
Duncan Sands | b2ff885 | 2008-07-17 02:36:29 +0000 | [diff] [blame] | 5993 | RTLIB::Libcall LC = isSigned ? |
| 5994 | RTLIB::getSINTTOFP(SourceVT, DestTy) : |
| 5995 | RTLIB::getUINTTOFP(SourceVT, DestTy); |
| 5996 | assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unknown int value type"); |
| 5997 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 5998 | Source = DAG.getNode(ISD::SINT_TO_FP, DestTy, Source); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5999 | SDValue HiPart; |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6000 | SDValue Result = ExpandLibCall(LC, Source.getNode(), isSigned, HiPart); |
| 6001 | if (Result.getValueType() != DestTy && HiPart.getNode()) |
Dan Gohman | a2e9485 | 2008-03-10 23:03:31 +0000 | [diff] [blame] | 6002 | Result = DAG.getNode(ISD::BUILD_PAIR, DestTy, Result, HiPart); |
| 6003 | return Result; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 6004 | } |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 6005 | |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6006 | /// ExpandLegalINT_TO_FP - This function is responsible for legalizing a |
| 6007 | /// INT_TO_FP operation of the specified operand when the target requests that |
| 6008 | /// we expand it. At this point, we know that the result and operand types are |
| 6009 | /// legal for the target. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6010 | SDValue SelectionDAGLegalize::ExpandLegalINT_TO_FP(bool isSigned, |
| 6011 | SDValue Op0, |
| 6012 | MVT DestVT) { |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6013 | if (Op0.getValueType() == MVT::i32) { |
| 6014 | // simple 32-bit [signed|unsigned] integer to float/double expansion |
| 6015 | |
Chris Lattner | 23594d4 | 2008-01-16 07:03:22 +0000 | [diff] [blame] | 6016 | // Get the stack frame index of a 8 byte buffer. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6017 | SDValue StackSlot = DAG.CreateStackTemporary(MVT::f64); |
Chris Lattner | 23594d4 | 2008-01-16 07:03:22 +0000 | [diff] [blame] | 6018 | |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6019 | // word offset constant for Hi/Lo address computation |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6020 | SDValue WordOff = DAG.getConstant(sizeof(int), TLI.getPointerTy()); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6021 | // set up Hi and Lo (into buffer) address based on endian |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6022 | SDValue Hi = StackSlot; |
| 6023 | SDValue Lo = DAG.getNode(ISD::ADD, TLI.getPointerTy(), StackSlot,WordOff); |
Chris Lattner | 408c428 | 2006-03-23 05:29:04 +0000 | [diff] [blame] | 6024 | if (TLI.isLittleEndian()) |
| 6025 | std::swap(Hi, Lo); |
| 6026 | |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6027 | // if signed map to unsigned space |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6028 | SDValue Op0Mapped; |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6029 | if (isSigned) { |
| 6030 | // constant used to invert sign bit (signed to unsigned mapping) |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6031 | SDValue SignBit = DAG.getConstant(0x80000000u, MVT::i32); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6032 | Op0Mapped = DAG.getNode(ISD::XOR, MVT::i32, Op0, SignBit); |
| 6033 | } else { |
| 6034 | Op0Mapped = Op0; |
| 6035 | } |
| 6036 | // store the lo of the constructed double - based on integer input |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6037 | SDValue Store1 = DAG.getStore(DAG.getEntryNode(), |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 6038 | Op0Mapped, Lo, NULL, 0); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6039 | // initial hi portion of constructed double |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6040 | SDValue InitialHi = DAG.getConstant(0x43300000u, MVT::i32); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6041 | // store the hi of the constructed double - biased exponent |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6042 | SDValue Store2=DAG.getStore(Store1, InitialHi, Hi, NULL, 0); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6043 | // load the constructed double |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6044 | SDValue Load = DAG.getLoad(MVT::f64, Store2, StackSlot, NULL, 0); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6045 | // FP constant to bias correct the final result |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6046 | SDValue Bias = DAG.getConstantFP(isSigned ? |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6047 | BitsToDouble(0x4330000080000000ULL) |
| 6048 | : BitsToDouble(0x4330000000000000ULL), |
| 6049 | MVT::f64); |
| 6050 | // subtract the bias |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6051 | SDValue Sub = DAG.getNode(ISD::FSUB, MVT::f64, Load, Bias); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6052 | // final result |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6053 | SDValue Result; |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6054 | // handle final rounding |
| 6055 | if (DestVT == MVT::f64) { |
| 6056 | // do nothing |
| 6057 | Result = Sub; |
Duncan Sands | 8e4eb09 | 2008-06-08 20:54:56 +0000 | [diff] [blame] | 6058 | } else if (DestVT.bitsLT(MVT::f64)) { |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 6059 | Result = DAG.getNode(ISD::FP_ROUND, DestVT, Sub, |
| 6060 | DAG.getIntPtrConstant(0)); |
Duncan Sands | 8e4eb09 | 2008-06-08 20:54:56 +0000 | [diff] [blame] | 6061 | } else if (DestVT.bitsGT(MVT::f64)) { |
Dale Johannesen | 118cd9d | 2007-09-16 16:51:49 +0000 | [diff] [blame] | 6062 | Result = DAG.getNode(ISD::FP_EXTEND, DestVT, Sub); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6063 | } |
| 6064 | return Result; |
| 6065 | } |
| 6066 | assert(!isSigned && "Legalize cannot Expand SINT_TO_FP for i64 yet"); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6067 | SDValue Tmp1 = DAG.getNode(ISD::SINT_TO_FP, DestVT, Op0); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6068 | |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 6069 | SDValue SignSet = DAG.getSetCC(TLI.getSetCCResultType(Op0.getValueType()), |
| 6070 | Op0, DAG.getConstant(0, Op0.getValueType()), |
| 6071 | ISD::SETLT); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6072 | SDValue Zero = DAG.getIntPtrConstant(0), Four = DAG.getIntPtrConstant(4); |
| 6073 | SDValue CstOffset = DAG.getNode(ISD::SELECT, Zero.getValueType(), |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6074 | SignSet, Four, Zero); |
| 6075 | |
| 6076 | // If the sign bit of the integer is set, the large number will be treated |
| 6077 | // as a negative number. To counteract this, the dynamic code adds an |
| 6078 | // offset depending on the data type. |
| 6079 | uint64_t FF; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6080 | switch (Op0.getValueType().getSimpleVT()) { |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6081 | default: assert(0 && "Unsupported integer type!"); |
| 6082 | case MVT::i8 : FF = 0x43800000ULL; break; // 2^8 (as a float) |
| 6083 | case MVT::i16: FF = 0x47800000ULL; break; // 2^16 (as a float) |
| 6084 | case MVT::i32: FF = 0x4F800000ULL; break; // 2^32 (as a float) |
| 6085 | case MVT::i64: FF = 0x5F800000ULL; break; // 2^64 (as a float) |
| 6086 | } |
| 6087 | if (TLI.isLittleEndian()) FF <<= 32; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 6088 | static Constant *FudgeFactor = ConstantInt::get(Type::Int64Ty, FF); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6089 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6090 | SDValue CPIdx = DAG.getConstantPool(FudgeFactor, TLI.getPointerTy()); |
Dan Gohman | 50284d8 | 2008-09-16 22:05:41 +0000 | [diff] [blame] | 6091 | unsigned Alignment = 1 << cast<ConstantPoolSDNode>(CPIdx)->getAlignment(); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6092 | CPIdx = DAG.getNode(ISD::ADD, TLI.getPointerTy(), CPIdx, CstOffset); |
Dan Gohman | 87a0f10 | 2008-09-22 22:40:08 +0000 | [diff] [blame] | 6093 | Alignment = std::min(Alignment, 4u); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6094 | SDValue FudgeInReg; |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6095 | if (DestVT == MVT::f32) |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 6096 | FudgeInReg = DAG.getLoad(MVT::f32, DAG.getEntryNode(), CPIdx, |
Dan Gohman | 50284d8 | 2008-09-16 22:05:41 +0000 | [diff] [blame] | 6097 | PseudoSourceValue::getConstantPool(), 0, |
| 6098 | false, Alignment); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6099 | else { |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 6100 | FudgeInReg = |
| 6101 | LegalizeOp(DAG.getExtLoad(ISD::EXTLOAD, DestVT, |
| 6102 | DAG.getEntryNode(), CPIdx, |
Dan Gohman | 3069b87 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 6103 | PseudoSourceValue::getConstantPool(), 0, |
Dan Gohman | 50284d8 | 2008-09-16 22:05:41 +0000 | [diff] [blame] | 6104 | MVT::f32, false, Alignment)); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6105 | } |
| 6106 | |
| 6107 | return DAG.getNode(ISD::FADD, DestVT, Tmp1, FudgeInReg); |
| 6108 | } |
| 6109 | |
| 6110 | /// PromoteLegalINT_TO_FP - This function is responsible for legalizing a |
| 6111 | /// *INT_TO_FP operation of the specified operand when the target requests that |
| 6112 | /// we promote it. At this point, we know that the result and operand types are |
| 6113 | /// legal for the target, and that there is a legal UINT_TO_FP or SINT_TO_FP |
| 6114 | /// operation that takes a larger input. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6115 | SDValue SelectionDAGLegalize::PromoteLegalINT_TO_FP(SDValue LegalOp, |
| 6116 | MVT DestVT, |
| 6117 | bool isSigned) { |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6118 | // First step, figure out the appropriate *INT_TO_FP operation to use. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6119 | MVT NewInTy = LegalOp.getValueType(); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6120 | |
| 6121 | unsigned OpToUse = 0; |
| 6122 | |
| 6123 | // Scan for the appropriate larger type to use. |
| 6124 | while (1) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6125 | NewInTy = (MVT::SimpleValueType)(NewInTy.getSimpleVT()+1); |
| 6126 | assert(NewInTy.isInteger() && "Ran out of possibilities!"); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6127 | |
| 6128 | // If the target supports SINT_TO_FP of this type, use it. |
| 6129 | switch (TLI.getOperationAction(ISD::SINT_TO_FP, NewInTy)) { |
| 6130 | default: break; |
| 6131 | case TargetLowering::Legal: |
| 6132 | if (!TLI.isTypeLegal(NewInTy)) |
| 6133 | break; // Can't use this datatype. |
| 6134 | // FALL THROUGH. |
| 6135 | case TargetLowering::Custom: |
| 6136 | OpToUse = ISD::SINT_TO_FP; |
| 6137 | break; |
| 6138 | } |
| 6139 | if (OpToUse) break; |
| 6140 | if (isSigned) continue; |
| 6141 | |
| 6142 | // If the target supports UINT_TO_FP of this type, use it. |
| 6143 | switch (TLI.getOperationAction(ISD::UINT_TO_FP, NewInTy)) { |
| 6144 | default: break; |
| 6145 | case TargetLowering::Legal: |
| 6146 | if (!TLI.isTypeLegal(NewInTy)) |
| 6147 | break; // Can't use this datatype. |
| 6148 | // FALL THROUGH. |
| 6149 | case TargetLowering::Custom: |
| 6150 | OpToUse = ISD::UINT_TO_FP; |
| 6151 | break; |
| 6152 | } |
| 6153 | if (OpToUse) break; |
| 6154 | |
| 6155 | // Otherwise, try a larger type. |
| 6156 | } |
| 6157 | |
| 6158 | // Okay, we found the operation and type to use. Zero extend our input to the |
| 6159 | // desired type then run the operation on it. |
| 6160 | return DAG.getNode(OpToUse, DestVT, |
| 6161 | DAG.getNode(isSigned ? ISD::SIGN_EXTEND : ISD::ZERO_EXTEND, |
| 6162 | NewInTy, LegalOp)); |
| 6163 | } |
| 6164 | |
| 6165 | /// PromoteLegalFP_TO_INT - This function is responsible for legalizing a |
| 6166 | /// FP_TO_*INT operation of the specified operand when the target requests that |
| 6167 | /// we promote it. At this point, we know that the result and operand types are |
| 6168 | /// legal for the target, and that there is a legal FP_TO_UINT or FP_TO_SINT |
| 6169 | /// operation that returns a larger result. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6170 | SDValue SelectionDAGLegalize::PromoteLegalFP_TO_INT(SDValue LegalOp, |
| 6171 | MVT DestVT, |
| 6172 | bool isSigned) { |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6173 | // First step, figure out the appropriate FP_TO*INT operation to use. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6174 | MVT NewOutTy = DestVT; |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6175 | |
| 6176 | unsigned OpToUse = 0; |
| 6177 | |
| 6178 | // Scan for the appropriate larger type to use. |
| 6179 | while (1) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6180 | NewOutTy = (MVT::SimpleValueType)(NewOutTy.getSimpleVT()+1); |
| 6181 | assert(NewOutTy.isInteger() && "Ran out of possibilities!"); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6182 | |
| 6183 | // If the target supports FP_TO_SINT returning this type, use it. |
| 6184 | switch (TLI.getOperationAction(ISD::FP_TO_SINT, NewOutTy)) { |
| 6185 | default: break; |
| 6186 | case TargetLowering::Legal: |
| 6187 | if (!TLI.isTypeLegal(NewOutTy)) |
| 6188 | break; // Can't use this datatype. |
| 6189 | // FALL THROUGH. |
| 6190 | case TargetLowering::Custom: |
| 6191 | OpToUse = ISD::FP_TO_SINT; |
| 6192 | break; |
| 6193 | } |
| 6194 | if (OpToUse) break; |
| 6195 | |
| 6196 | // If the target supports FP_TO_UINT of this type, use it. |
| 6197 | switch (TLI.getOperationAction(ISD::FP_TO_UINT, NewOutTy)) { |
| 6198 | default: break; |
| 6199 | case TargetLowering::Legal: |
| 6200 | if (!TLI.isTypeLegal(NewOutTy)) |
| 6201 | break; // Can't use this datatype. |
| 6202 | // FALL THROUGH. |
| 6203 | case TargetLowering::Custom: |
| 6204 | OpToUse = ISD::FP_TO_UINT; |
| 6205 | break; |
| 6206 | } |
| 6207 | if (OpToUse) break; |
| 6208 | |
| 6209 | // Otherwise, try a larger type. |
| 6210 | } |
| 6211 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6212 | |
| 6213 | // Okay, we found the operation and type to use. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6214 | SDValue Operation = DAG.getNode(OpToUse, NewOutTy, LegalOp); |
Duncan Sands | 126d907 | 2008-07-04 11:47:58 +0000 | [diff] [blame] | 6215 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6216 | // If the operation produces an invalid type, it must be custom lowered. Use |
| 6217 | // the target lowering hooks to expand it. Just keep the low part of the |
| 6218 | // expanded operation, we know that we're truncating anyway. |
| 6219 | if (getTypeAction(NewOutTy) == Expand) { |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 6220 | SmallVector<SDValue, 2> Results; |
| 6221 | TLI.ReplaceNodeResults(Operation.getNode(), Results, DAG); |
| 6222 | assert(Results.size() == 1 && "Incorrect FP_TO_XINT lowering!"); |
| 6223 | Operation = Results[0]; |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6224 | } |
Duncan Sands | 126d907 | 2008-07-04 11:47:58 +0000 | [diff] [blame] | 6225 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6226 | // Truncate the result of the extended FP_TO_*INT operation to the desired |
| 6227 | // size. |
| 6228 | return DAG.getNode(ISD::TRUNCATE, DestVT, Operation); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6229 | } |
| 6230 | |
| 6231 | /// ExpandBSWAP - Open code the operations for BSWAP of the specified operation. |
| 6232 | /// |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6233 | SDValue SelectionDAGLegalize::ExpandBSWAP(SDValue Op) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6234 | MVT VT = Op.getValueType(); |
| 6235 | MVT SHVT = TLI.getShiftAmountTy(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6236 | SDValue Tmp1, Tmp2, Tmp3, Tmp4, Tmp5, Tmp6, Tmp7, Tmp8; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6237 | switch (VT.getSimpleVT()) { |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6238 | default: assert(0 && "Unhandled Expand type in BSWAP!"); abort(); |
| 6239 | case MVT::i16: |
| 6240 | Tmp2 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(8, SHVT)); |
| 6241 | Tmp1 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(8, SHVT)); |
| 6242 | return DAG.getNode(ISD::OR, VT, Tmp1, Tmp2); |
| 6243 | case MVT::i32: |
| 6244 | Tmp4 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(24, SHVT)); |
| 6245 | Tmp3 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(8, SHVT)); |
| 6246 | Tmp2 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(8, SHVT)); |
| 6247 | Tmp1 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(24, SHVT)); |
| 6248 | Tmp3 = DAG.getNode(ISD::AND, VT, Tmp3, DAG.getConstant(0xFF0000, VT)); |
| 6249 | Tmp2 = DAG.getNode(ISD::AND, VT, Tmp2, DAG.getConstant(0xFF00, VT)); |
| 6250 | Tmp4 = DAG.getNode(ISD::OR, VT, Tmp4, Tmp3); |
| 6251 | Tmp2 = DAG.getNode(ISD::OR, VT, Tmp2, Tmp1); |
| 6252 | return DAG.getNode(ISD::OR, VT, Tmp4, Tmp2); |
| 6253 | case MVT::i64: |
| 6254 | Tmp8 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(56, SHVT)); |
| 6255 | Tmp7 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(40, SHVT)); |
| 6256 | Tmp6 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(24, SHVT)); |
| 6257 | Tmp5 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(8, SHVT)); |
| 6258 | Tmp4 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(8, SHVT)); |
| 6259 | Tmp3 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(24, SHVT)); |
| 6260 | Tmp2 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(40, SHVT)); |
| 6261 | Tmp1 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(56, SHVT)); |
| 6262 | Tmp7 = DAG.getNode(ISD::AND, VT, Tmp7, DAG.getConstant(255ULL<<48, VT)); |
| 6263 | Tmp6 = DAG.getNode(ISD::AND, VT, Tmp6, DAG.getConstant(255ULL<<40, VT)); |
| 6264 | Tmp5 = DAG.getNode(ISD::AND, VT, Tmp5, DAG.getConstant(255ULL<<32, VT)); |
| 6265 | Tmp4 = DAG.getNode(ISD::AND, VT, Tmp4, DAG.getConstant(255ULL<<24, VT)); |
| 6266 | Tmp3 = DAG.getNode(ISD::AND, VT, Tmp3, DAG.getConstant(255ULL<<16, VT)); |
| 6267 | Tmp2 = DAG.getNode(ISD::AND, VT, Tmp2, DAG.getConstant(255ULL<<8 , VT)); |
| 6268 | Tmp8 = DAG.getNode(ISD::OR, VT, Tmp8, Tmp7); |
| 6269 | Tmp6 = DAG.getNode(ISD::OR, VT, Tmp6, Tmp5); |
| 6270 | Tmp4 = DAG.getNode(ISD::OR, VT, Tmp4, Tmp3); |
| 6271 | Tmp2 = DAG.getNode(ISD::OR, VT, Tmp2, Tmp1); |
| 6272 | Tmp8 = DAG.getNode(ISD::OR, VT, Tmp8, Tmp6); |
| 6273 | Tmp4 = DAG.getNode(ISD::OR, VT, Tmp4, Tmp2); |
| 6274 | return DAG.getNode(ISD::OR, VT, Tmp8, Tmp4); |
| 6275 | } |
| 6276 | } |
| 6277 | |
| 6278 | /// ExpandBitCount - Expand the specified bitcount instruction into operations. |
| 6279 | /// |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6280 | SDValue SelectionDAGLegalize::ExpandBitCount(unsigned Opc, SDValue Op) { |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6281 | switch (Opc) { |
| 6282 | default: assert(0 && "Cannot expand this yet!"); |
| 6283 | case ISD::CTPOP: { |
| 6284 | static const uint64_t mask[6] = { |
| 6285 | 0x5555555555555555ULL, 0x3333333333333333ULL, |
| 6286 | 0x0F0F0F0F0F0F0F0FULL, 0x00FF00FF00FF00FFULL, |
| 6287 | 0x0000FFFF0000FFFFULL, 0x00000000FFFFFFFFULL |
| 6288 | }; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6289 | MVT VT = Op.getValueType(); |
| 6290 | MVT ShVT = TLI.getShiftAmountTy(); |
| 6291 | unsigned len = VT.getSizeInBits(); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6292 | for (unsigned i = 0; (1U << i) <= (len / 2); ++i) { |
| 6293 | //x = (x & mask[i][len/8]) + (x >> (1 << i) & mask[i][len/8]) |
Duncan Sands | b0d5cdd | 2009-02-01 18:06:53 +0000 | [diff] [blame^] | 6294 | unsigned EltSize = VT.isVector() ? |
| 6295 | VT.getVectorElementType().getSizeInBits() : len; |
| 6296 | SDValue Tmp2 = DAG.getConstant(APInt(EltSize, mask[i]), VT); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 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 | } |
Bill Wendling | 7581bfa | 2009-01-30 23:03:19 +0000 | [diff] [blame] | 6321 | Op = DAG.getNOT(DebugLoc::getUnknownLoc(), 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(); |
Bill Wendling | 7581bfa | 2009-01-30 23:03:19 +0000 | [diff] [blame] | 6330 | SDValue Tmp3 = DAG.getNode(ISD::AND, VT, |
| 6331 | DAG.getNOT(DebugLoc::getUnknownLoc(), Op, VT), |
| 6332 | DAG.getNode(ISD::SUB, VT, Op, |
| 6333 | DAG.getConstant(1, VT))); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6334 | // If ISD::CTLZ is legal and CTPOP isn't, then do that instead. |
Dan Gohman | f560ffa | 2009-01-28 17:46:25 +0000 | [diff] [blame] | 6335 | if (!TLI.isOperationLegalOrCustom(ISD::CTPOP, VT) && |
| 6336 | TLI.isOperationLegalOrCustom(ISD::CTLZ, VT)) |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6337 | return DAG.getNode(ISD::SUB, VT, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6338 | DAG.getConstant(VT.getSizeInBits(), VT), |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 6339 | DAG.getNode(ISD::CTLZ, VT, Tmp3)); |
| 6340 | return DAG.getNode(ISD::CTPOP, VT, Tmp3); |
| 6341 | } |
| 6342 | } |
| 6343 | } |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6344 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6345 | /// ExpandOp - Expand the specified SDValue into its two component pieces |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6346 | /// 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] | 6347 | /// 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] | 6348 | /// ExpandedNodes map is filled in for any results that are expanded, and the |
| 6349 | /// Lo/Hi values are returned. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6350 | void SelectionDAGLegalize::ExpandOp(SDValue Op, SDValue &Lo, SDValue &Hi){ |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6351 | MVT VT = Op.getValueType(); |
| 6352 | MVT NVT = TLI.getTypeToTransformTo(VT); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6353 | SDNode *Node = Op.getNode(); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6354 | assert(getTypeAction(VT) == Expand && "Not an expanded type!"); |
Duncan Sands | 8e4eb09 | 2008-06-08 20:54:56 +0000 | [diff] [blame] | 6355 | assert(((NVT.isInteger() && NVT.bitsLT(VT)) || VT.isFloatingPoint() || |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6356 | VT.isVector()) && "Cannot expand to FP value or to larger int value!"); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6357 | |
Chris Lattner | 6fdcb25 | 2005-09-02 20:32:45 +0000 | [diff] [blame] | 6358 | // See if we already expanded it. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6359 | DenseMap<SDValue, std::pair<SDValue, SDValue> >::iterator I |
Chris Lattner | 6fdcb25 | 2005-09-02 20:32:45 +0000 | [diff] [blame] | 6360 | = ExpandedNodes.find(Op); |
| 6361 | if (I != ExpandedNodes.end()) { |
| 6362 | Lo = I->second.first; |
| 6363 | Hi = I->second.second; |
| 6364 | return; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6365 | } |
| 6366 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6367 | switch (Node->getOpcode()) { |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 6368 | case ISD::CopyFromReg: |
| 6369 | assert(0 && "CopyFromReg must be legal!"); |
Dale Johannesen | 6eaeff2 | 2007-10-10 01:01:31 +0000 | [diff] [blame] | 6370 | case ISD::FP_ROUND_INREG: |
| 6371 | if (VT == MVT::ppcf128 && |
| 6372 | TLI.getOperationAction(ISD::FP_ROUND_INREG, VT) == |
| 6373 | TargetLowering::Custom) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6374 | SDValue SrcLo, SrcHi, Src; |
Dale Johannesen | fcf4d24 | 2007-10-11 23:32:15 +0000 | [diff] [blame] | 6375 | ExpandOp(Op.getOperand(0), SrcLo, SrcHi); |
| 6376 | Src = DAG.getNode(ISD::BUILD_PAIR, VT, SrcLo, SrcHi); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6377 | SDValue Result = TLI.LowerOperation( |
Dale Johannesen | fcf4d24 | 2007-10-11 23:32:15 +0000 | [diff] [blame] | 6378 | DAG.getNode(ISD::FP_ROUND_INREG, VT, Src, Op.getOperand(1)), DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6379 | assert(Result.getNode()->getOpcode() == ISD::BUILD_PAIR); |
| 6380 | Lo = Result.getNode()->getOperand(0); |
| 6381 | Hi = Result.getNode()->getOperand(1); |
Dale Johannesen | 6eaeff2 | 2007-10-10 01:01:31 +0000 | [diff] [blame] | 6382 | break; |
| 6383 | } |
| 6384 | // fall through |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 6385 | default: |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 6386 | #ifndef NDEBUG |
Dan Gohman | 3983358 | 2007-06-04 16:17:33 +0000 | [diff] [blame] | 6387 | cerr << "NODE: "; Node->dump(&DAG); cerr << "\n"; |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 6388 | #endif |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6389 | assert(0 && "Do not know how to expand this operator!"); |
| 6390 | abort(); |
Dan Gohman | 1953ecb | 2008-02-27 01:52:30 +0000 | [diff] [blame] | 6391 | case ISD::EXTRACT_ELEMENT: |
| 6392 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 6393 | if (cast<ConstantSDNode>(Node->getOperand(1))->getZExtValue()) |
Dan Gohman | 1953ecb | 2008-02-27 01:52:30 +0000 | [diff] [blame] | 6394 | return ExpandOp(Hi, Lo, Hi); |
Dan Gohman | 18714ae | 2008-02-27 19:44:57 +0000 | [diff] [blame] | 6395 | return ExpandOp(Lo, Lo, Hi); |
Dale Johannesen | 25f1d08 | 2007-10-31 00:32:36 +0000 | [diff] [blame] | 6396 | case ISD::EXTRACT_VECTOR_ELT: |
Dale Johannesen | 25f1d08 | 2007-10-31 00:32:36 +0000 | [diff] [blame] | 6397 | // ExpandEXTRACT_VECTOR_ELT tolerates invalid result types. |
| 6398 | Lo = ExpandEXTRACT_VECTOR_ELT(Op); |
| 6399 | return ExpandOp(Lo, Lo, Hi); |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 6400 | case ISD::UNDEF: |
| 6401 | Lo = DAG.getNode(ISD::UNDEF, NVT); |
| 6402 | Hi = DAG.getNode(ISD::UNDEF, NVT); |
| 6403 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6404 | case ISD::Constant: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6405 | unsigned NVTBits = NVT.getSizeInBits(); |
Dan Gohman | 050f550 | 2008-03-03 22:20:46 +0000 | [diff] [blame] | 6406 | const APInt &Cst = cast<ConstantSDNode>(Node)->getAPIntValue(); |
| 6407 | Lo = DAG.getConstant(APInt(Cst).trunc(NVTBits), NVT); |
| 6408 | Hi = DAG.getConstant(Cst.lshr(NVTBits).trunc(NVTBits), NVT); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6409 | break; |
| 6410 | } |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 6411 | case ISD::ConstantFP: { |
| 6412 | ConstantFPSDNode *CFP = cast<ConstantFPSDNode>(Node); |
Dale Johannesen | a471c2e | 2007-10-11 18:07:22 +0000 | [diff] [blame] | 6413 | if (CFP->getValueType(0) == MVT::ppcf128) { |
Dale Johannesen | 7111b02 | 2008-10-09 18:53:47 +0000 | [diff] [blame] | 6414 | APInt api = CFP->getValueAPF().bitcastToAPInt(); |
Dale Johannesen | a471c2e | 2007-10-11 18:07:22 +0000 | [diff] [blame] | 6415 | Lo = DAG.getConstantFP(APFloat(APInt(64, 1, &api.getRawData()[1])), |
| 6416 | MVT::f64); |
| 6417 | Hi = DAG.getConstantFP(APFloat(APInt(64, 1, &api.getRawData()[0])), |
| 6418 | MVT::f64); |
| 6419 | break; |
| 6420 | } |
Evan Cheng | 279101e | 2006-12-12 22:19:28 +0000 | [diff] [blame] | 6421 | Lo = ExpandConstantFP(CFP, false, DAG, TLI); |
Evan Cheng | 9f87788 | 2006-12-13 20:57:08 +0000 | [diff] [blame] | 6422 | if (getTypeAction(Lo.getValueType()) == Expand) |
| 6423 | ExpandOp(Lo, Lo, Hi); |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 6424 | break; |
| 6425 | } |
Chris Lattner | d4e50bb | 2005-03-28 22:03:13 +0000 | [diff] [blame] | 6426 | case ISD::BUILD_PAIR: |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6427 | // Return the operands. |
| 6428 | Lo = Node->getOperand(0); |
| 6429 | Hi = Node->getOperand(1); |
Chris Lattner | d4e50bb | 2005-03-28 22:03:13 +0000 | [diff] [blame] | 6430 | break; |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6431 | |
| 6432 | case ISD::MERGE_VALUES: |
Chris Lattner | c58d558 | 2007-11-24 19:12:15 +0000 | [diff] [blame] | 6433 | if (Node->getNumValues() == 1) { |
| 6434 | ExpandOp(Op.getOperand(0), Lo, Hi); |
| 6435 | break; |
| 6436 | } |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6437 | // FIXME: For now only expand i64,chain = MERGE_VALUES (x, y) |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 6438 | assert(Op.getResNo() == 0 && Node->getNumValues() == 2 && |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6439 | Op.getValue(1).getValueType() == MVT::Other && |
| 6440 | "unhandled MERGE_VALUES"); |
| 6441 | ExpandOp(Op.getOperand(0), Lo, Hi); |
| 6442 | // Remember that we legalized the chain. |
| 6443 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Op.getOperand(1))); |
| 6444 | break; |
Chris Lattner | 58f7963 | 2005-12-12 22:27:43 +0000 | [diff] [blame] | 6445 | |
| 6446 | case ISD::SIGN_EXTEND_INREG: |
| 6447 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Chris Lattner | 4bdd275 | 2006-10-06 17:34:12 +0000 | [diff] [blame] | 6448 | // sext_inreg the low part if needed. |
| 6449 | Lo = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Lo, Node->getOperand(1)); |
| 6450 | |
| 6451 | // The high part gets the sign extension from the lo-part. This handles |
| 6452 | // things like sextinreg V:i64 from i8. |
Chris Lattner | 58f7963 | 2005-12-12 22:27:43 +0000 | [diff] [blame] | 6453 | Hi = DAG.getNode(ISD::SRA, NVT, Lo, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6454 | DAG.getConstant(NVT.getSizeInBits()-1, |
Chris Lattner | 58f7963 | 2005-12-12 22:27:43 +0000 | [diff] [blame] | 6455 | TLI.getShiftAmountTy())); |
Chris Lattner | 58f7963 | 2005-12-12 22:27:43 +0000 | [diff] [blame] | 6456 | break; |
Chris Lattner | d4e50bb | 2005-03-28 22:03:13 +0000 | [diff] [blame] | 6457 | |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 6458 | case ISD::BSWAP: { |
| 6459 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6460 | SDValue TempLo = DAG.getNode(ISD::BSWAP, NVT, Hi); |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 6461 | Hi = DAG.getNode(ISD::BSWAP, NVT, Lo); |
| 6462 | Lo = TempLo; |
| 6463 | break; |
| 6464 | } |
| 6465 | |
Chris Lattner | edb1add | 2005-05-11 04:51:16 +0000 | [diff] [blame] | 6466 | case ISD::CTPOP: |
| 6467 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Chris Lattner | 9b583b4 | 2005-05-11 05:09:47 +0000 | [diff] [blame] | 6468 | Lo = DAG.getNode(ISD::ADD, NVT, // ctpop(HL) -> ctpop(H)+ctpop(L) |
| 6469 | DAG.getNode(ISD::CTPOP, NVT, Lo), |
| 6470 | DAG.getNode(ISD::CTPOP, NVT, Hi)); |
Chris Lattner | edb1add | 2005-05-11 04:51:16 +0000 | [diff] [blame] | 6471 | Hi = DAG.getConstant(0, NVT); |
| 6472 | break; |
| 6473 | |
Chris Lattner | 39a8f33 | 2005-05-12 19:05:01 +0000 | [diff] [blame] | 6474 | case ISD::CTLZ: { |
| 6475 | // ctlz (HL) -> ctlz(H) != 32 ? ctlz(H) : (ctlz(L)+32) |
Chris Lattner | 3becf20 | 2005-05-12 19:27:51 +0000 | [diff] [blame] | 6476 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6477 | SDValue BitsC = DAG.getConstant(NVT.getSizeInBits(), NVT); |
| 6478 | SDValue HLZ = DAG.getNode(ISD::CTLZ, NVT, Hi); |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 6479 | SDValue TopNotZero = DAG.getSetCC(TLI.getSetCCResultType(NVT), HLZ, BitsC, |
| 6480 | ISD::SETNE); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6481 | SDValue LowPart = DAG.getNode(ISD::CTLZ, NVT, Lo); |
Chris Lattner | 39a8f33 | 2005-05-12 19:05:01 +0000 | [diff] [blame] | 6482 | LowPart = DAG.getNode(ISD::ADD, NVT, LowPart, BitsC); |
| 6483 | |
| 6484 | Lo = DAG.getNode(ISD::SELECT, NVT, TopNotZero, HLZ, LowPart); |
| 6485 | Hi = DAG.getConstant(0, NVT); |
| 6486 | break; |
| 6487 | } |
| 6488 | |
| 6489 | case ISD::CTTZ: { |
| 6490 | // cttz (HL) -> cttz(L) != 32 ? cttz(L) : (cttz(H)+32) |
Chris Lattner | 3becf20 | 2005-05-12 19:27:51 +0000 | [diff] [blame] | 6491 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6492 | SDValue BitsC = DAG.getConstant(NVT.getSizeInBits(), NVT); |
| 6493 | SDValue LTZ = DAG.getNode(ISD::CTTZ, NVT, Lo); |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 6494 | SDValue BotNotZero = DAG.getSetCC(TLI.getSetCCResultType(NVT), LTZ, BitsC, |
| 6495 | ISD::SETNE); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6496 | SDValue HiPart = DAG.getNode(ISD::CTTZ, NVT, Hi); |
Chris Lattner | 39a8f33 | 2005-05-12 19:05:01 +0000 | [diff] [blame] | 6497 | HiPart = DAG.getNode(ISD::ADD, NVT, HiPart, BitsC); |
| 6498 | |
| 6499 | Lo = DAG.getNode(ISD::SELECT, NVT, BotNotZero, LTZ, HiPart); |
| 6500 | Hi = DAG.getConstant(0, NVT); |
| 6501 | break; |
| 6502 | } |
Chris Lattner | edb1add | 2005-05-11 04:51:16 +0000 | [diff] [blame] | 6503 | |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 6504 | case ISD::VAARG: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6505 | SDValue Ch = Node->getOperand(0); // Legalize the chain. |
| 6506 | SDValue Ptr = Node->getOperand(1); // Legalize the pointer. |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 6507 | Lo = DAG.getVAArg(NVT, Ch, Ptr, Node->getOperand(2)); |
| 6508 | Hi = DAG.getVAArg(NVT, Lo.getValue(1), Ptr, Node->getOperand(2)); |
| 6509 | |
| 6510 | // Remember that we legalized the chain. |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6511 | Hi = LegalizeOp(Hi); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 6512 | AddLegalizedOperand(Op.getValue(1), Hi.getValue(1)); |
Duncan Sands | 0753fc1 | 2008-02-11 10:37:04 +0000 | [diff] [blame] | 6513 | if (TLI.isBigEndian()) |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 6514 | std::swap(Lo, Hi); |
| 6515 | break; |
| 6516 | } |
| 6517 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6518 | case ISD::LOAD: { |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6519 | LoadSDNode *LD = cast<LoadSDNode>(Node); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6520 | SDValue Ch = LD->getChain(); // Legalize the chain. |
| 6521 | SDValue Ptr = LD->getBasePtr(); // Legalize the pointer. |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6522 | ISD::LoadExtType ExtType = LD->getExtensionType(); |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 6523 | const Value *SV = LD->getSrcValue(); |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 6524 | int SVOffset = LD->getSrcValueOffset(); |
| 6525 | unsigned Alignment = LD->getAlignment(); |
| 6526 | bool isVolatile = LD->isVolatile(); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6527 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6528 | if (ExtType == ISD::NON_EXTLOAD) { |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 6529 | Lo = DAG.getLoad(NVT, Ch, Ptr, SV, SVOffset, |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 6530 | isVolatile, Alignment); |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 6531 | if (VT == MVT::f32 || VT == MVT::f64) { |
| 6532 | // f32->i32 or f64->i64 one to one expansion. |
| 6533 | // Remember that we legalized the chain. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6534 | AddLegalizedOperand(SDValue(Node, 1), LegalizeOp(Lo.getValue(1))); |
Evan Cheng | 9f87788 | 2006-12-13 20:57:08 +0000 | [diff] [blame] | 6535 | // Recursively expand the new load. |
| 6536 | if (getTypeAction(NVT) == Expand) |
| 6537 | ExpandOp(Lo, Lo, Hi); |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 6538 | break; |
| 6539 | } |
Chris Lattner | ec39a45 | 2005-01-19 18:02:17 +0000 | [diff] [blame] | 6540 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6541 | // Increment the pointer to the other half. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6542 | unsigned IncrementSize = Lo.getValueType().getSizeInBits()/8; |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6543 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 6544 | DAG.getIntPtrConstant(IncrementSize)); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6545 | SVOffset += IncrementSize; |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 6546 | Alignment = MinAlign(Alignment, IncrementSize); |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 6547 | Hi = DAG.getLoad(NVT, Ch, Ptr, SV, SVOffset, |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 6548 | isVolatile, Alignment); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 6549 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6550 | // Build a factor node to remember that this load is independent of the |
| 6551 | // other one. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6552 | SDValue TF = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1), |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6553 | Hi.getValue(1)); |
| 6554 | |
| 6555 | // Remember that we legalized the chain. |
| 6556 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(TF)); |
Duncan Sands | 0753fc1 | 2008-02-11 10:37:04 +0000 | [diff] [blame] | 6557 | if (TLI.isBigEndian()) |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6558 | std::swap(Lo, Hi); |
| 6559 | } else { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6560 | MVT EVT = LD->getMemoryVT(); |
Evan Cheng | 548f611 | 2006-12-13 03:19:57 +0000 | [diff] [blame] | 6561 | |
Dale Johannesen | b6210fc | 2007-10-19 20:29:00 +0000 | [diff] [blame] | 6562 | if ((VT == MVT::f64 && EVT == MVT::f32) || |
| 6563 | (VT == MVT::ppcf128 && (EVT==MVT::f64 || EVT==MVT::f32))) { |
Evan Cheng | 548f611 | 2006-12-13 03:19:57 +0000 | [diff] [blame] | 6564 | // f64 = EXTLOAD f32 should expand to LOAD, FP_EXTEND |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 6565 | SDValue Load = DAG.getLoad(EVT, Ch, Ptr, SV, |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 6566 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 548f611 | 2006-12-13 03:19:57 +0000 | [diff] [blame] | 6567 | // Remember that we legalized the chain. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6568 | AddLegalizedOperand(SDValue(Node, 1), LegalizeOp(Load.getValue(1))); |
Evan Cheng | 548f611 | 2006-12-13 03:19:57 +0000 | [diff] [blame] | 6569 | ExpandOp(DAG.getNode(ISD::FP_EXTEND, VT, Load), Lo, Hi); |
| 6570 | break; |
| 6571 | } |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6572 | |
| 6573 | if (EVT == NVT) |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 6574 | Lo = DAG.getLoad(NVT, Ch, Ptr, SV, |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 6575 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6576 | else |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 6577 | Lo = DAG.getExtLoad(ExtType, NVT, Ch, Ptr, SV, |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 6578 | SVOffset, EVT, isVolatile, |
| 6579 | Alignment); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6580 | |
| 6581 | // Remember that we legalized the chain. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6582 | AddLegalizedOperand(SDValue(Node, 1), LegalizeOp(Lo.getValue(1))); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6583 | |
| 6584 | if (ExtType == ISD::SEXTLOAD) { |
| 6585 | // The high part is obtained by SRA'ing all but one of the bits of the |
| 6586 | // lo part. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6587 | unsigned LoSize = Lo.getValueType().getSizeInBits(); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6588 | Hi = DAG.getNode(ISD::SRA, NVT, Lo, |
| 6589 | DAG.getConstant(LoSize-1, TLI.getShiftAmountTy())); |
| 6590 | } else if (ExtType == ISD::ZEXTLOAD) { |
| 6591 | // The high part is just a zero. |
| 6592 | Hi = DAG.getConstant(0, NVT); |
| 6593 | } else /* if (ExtType == ISD::EXTLOAD) */ { |
| 6594 | // The high part is undefined. |
| 6595 | Hi = DAG.getNode(ISD::UNDEF, NVT); |
| 6596 | } |
| 6597 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6598 | break; |
| 6599 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6600 | case ISD::AND: |
| 6601 | case ISD::OR: |
| 6602 | case ISD::XOR: { // Simple logical operators -> two trivial pieces. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6603 | SDValue LL, LH, RL, RH; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6604 | ExpandOp(Node->getOperand(0), LL, LH); |
| 6605 | ExpandOp(Node->getOperand(1), RL, RH); |
| 6606 | Lo = DAG.getNode(Node->getOpcode(), NVT, LL, RL); |
| 6607 | Hi = DAG.getNode(Node->getOpcode(), NVT, LH, RH); |
| 6608 | break; |
| 6609 | } |
| 6610 | case ISD::SELECT: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6611 | SDValue LL, LH, RL, RH; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6612 | ExpandOp(Node->getOperand(1), LL, LH); |
| 6613 | ExpandOp(Node->getOperand(2), RL, RH); |
Evan Cheng | 19103b1 | 2006-12-15 22:42:55 +0000 | [diff] [blame] | 6614 | if (getTypeAction(NVT) == Expand) |
| 6615 | NVT = TLI.getTypeToExpandTo(NVT); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 6616 | Lo = DAG.getNode(ISD::SELECT, NVT, Node->getOperand(0), LL, RL); |
Evan Cheng | 19103b1 | 2006-12-15 22:42:55 +0000 | [diff] [blame] | 6617 | if (VT != MVT::f32) |
| 6618 | Hi = DAG.getNode(ISD::SELECT, NVT, Node->getOperand(0), LH, RH); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6619 | break; |
| 6620 | } |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 6621 | case ISD::SELECT_CC: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6622 | SDValue TL, TH, FL, FH; |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 6623 | ExpandOp(Node->getOperand(2), TL, TH); |
| 6624 | ExpandOp(Node->getOperand(3), FL, FH); |
Evan Cheng | 19103b1 | 2006-12-15 22:42:55 +0000 | [diff] [blame] | 6625 | if (getTypeAction(NVT) == Expand) |
| 6626 | NVT = TLI.getTypeToExpandTo(NVT); |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 6627 | Lo = DAG.getNode(ISD::SELECT_CC, NVT, Node->getOperand(0), |
| 6628 | Node->getOperand(1), TL, FL, Node->getOperand(4)); |
Evan Cheng | 19103b1 | 2006-12-15 22:42:55 +0000 | [diff] [blame] | 6629 | if (VT != MVT::f32) |
| 6630 | Hi = DAG.getNode(ISD::SELECT_CC, NVT, Node->getOperand(0), |
| 6631 | Node->getOperand(1), TH, FH, Node->getOperand(4)); |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 6632 | break; |
| 6633 | } |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6634 | case ISD::ANY_EXTEND: |
| 6635 | // The low part is any extension of the input (which degenerates to a copy). |
| 6636 | Lo = DAG.getNode(ISD::ANY_EXTEND, NVT, Node->getOperand(0)); |
| 6637 | // The high part is undefined. |
| 6638 | Hi = DAG.getNode(ISD::UNDEF, NVT); |
| 6639 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6640 | case ISD::SIGN_EXTEND: { |
| 6641 | // The low part is just a sign extension of the input (which degenerates to |
| 6642 | // a copy). |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6643 | Lo = DAG.getNode(ISD::SIGN_EXTEND, NVT, Node->getOperand(0)); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 6644 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6645 | // The high part is obtained by SRA'ing all but one of the bits of the lo |
| 6646 | // part. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6647 | unsigned LoSize = Lo.getValueType().getSizeInBits(); |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6648 | Hi = DAG.getNode(ISD::SRA, NVT, Lo, |
| 6649 | DAG.getConstant(LoSize-1, TLI.getShiftAmountTy())); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6650 | break; |
| 6651 | } |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6652 | case ISD::ZERO_EXTEND: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6653 | // The low part is just a zero extension of the input (which degenerates to |
| 6654 | // a copy). |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6655 | Lo = DAG.getNode(ISD::ZERO_EXTEND, NVT, Node->getOperand(0)); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 6656 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6657 | // The high part is just a zero. |
| 6658 | Hi = DAG.getConstant(0, NVT); |
| 6659 | break; |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 6660 | |
Chris Lattner | 4c948eb | 2007-02-13 23:55:16 +0000 | [diff] [blame] | 6661 | case ISD::TRUNCATE: { |
| 6662 | // The input value must be larger than this value. Expand *it*. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6663 | SDValue NewLo; |
Chris Lattner | 4c948eb | 2007-02-13 23:55:16 +0000 | [diff] [blame] | 6664 | ExpandOp(Node->getOperand(0), NewLo, Hi); |
| 6665 | |
| 6666 | // The low part is now either the right size, or it is closer. If not the |
| 6667 | // right size, make an illegal truncate so we recursively expand it. |
| 6668 | if (NewLo.getValueType() != Node->getValueType(0)) |
| 6669 | NewLo = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0), NewLo); |
| 6670 | ExpandOp(NewLo, Lo, Hi); |
| 6671 | break; |
| 6672 | } |
| 6673 | |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 6674 | case ISD::BIT_CONVERT: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6675 | SDValue Tmp; |
Chris Lattner | f3f333d | 2006-09-09 00:20:27 +0000 | [diff] [blame] | 6676 | if (TLI.getOperationAction(ISD::BIT_CONVERT, VT) == TargetLowering::Custom){ |
| 6677 | // If the target wants to, allow it to lower this itself. |
| 6678 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 6679 | case Expand: assert(0 && "cannot expand FP!"); |
| 6680 | case Legal: Tmp = LegalizeOp(Node->getOperand(0)); break; |
| 6681 | case Promote: Tmp = PromoteOp (Node->getOperand(0)); break; |
| 6682 | } |
| 6683 | Tmp = TLI.LowerOperation(DAG.getNode(ISD::BIT_CONVERT, VT, Tmp), DAG); |
| 6684 | } |
| 6685 | |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 6686 | // f32 / f64 must be expanded to i32 / i64. |
Evan Cheng | 13acce3 | 2006-12-11 19:27:14 +0000 | [diff] [blame] | 6687 | if (VT == MVT::f32 || VT == MVT::f64) { |
| 6688 | Lo = DAG.getNode(ISD::BIT_CONVERT, NVT, Node->getOperand(0)); |
Evan Cheng | 19103b1 | 2006-12-15 22:42:55 +0000 | [diff] [blame] | 6689 | if (getTypeAction(NVT) == Expand) |
| 6690 | ExpandOp(Lo, Lo, Hi); |
Evan Cheng | 7b2b5c8 | 2006-12-12 19:53:13 +0000 | [diff] [blame] | 6691 | break; |
| 6692 | } |
| 6693 | |
| 6694 | // If source operand will be expanded to the same type as VT, i.e. |
| 6695 | // i64 <- f64, i32 <- f32, expand the source operand instead. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6696 | MVT VT0 = Node->getOperand(0).getValueType(); |
Evan Cheng | 7b2b5c8 | 2006-12-12 19:53:13 +0000 | [diff] [blame] | 6697 | if (getTypeAction(VT0) == Expand && TLI.getTypeToTransformTo(VT0) == VT) { |
| 6698 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 6699 | break; |
| 6700 | } |
| 6701 | |
Chris Lattner | f3f333d | 2006-09-09 00:20:27 +0000 | [diff] [blame] | 6702 | // Turn this into a load/store pair by default. |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6703 | if (Tmp.getNode() == 0) |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 6704 | Tmp = EmitStackConvert(Node->getOperand(0), VT, VT); |
Chris Lattner | f3f333d | 2006-09-09 00:20:27 +0000 | [diff] [blame] | 6705 | |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 6706 | ExpandOp(Tmp, Lo, Hi); |
| 6707 | break; |
| 6708 | } |
Andrew Lenharth | f70e30b | 2005-11-20 21:32:07 +0000 | [diff] [blame] | 6709 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6710 | case ISD::READCYCLECOUNTER: { |
Chris Lattner | 308575b | 2005-11-20 22:56:56 +0000 | [diff] [blame] | 6711 | assert(TLI.getOperationAction(ISD::READCYCLECOUNTER, VT) == |
| 6712 | TargetLowering::Custom && |
| 6713 | "Must custom expand ReadCycleCounter"); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6714 | SDValue Tmp = TLI.LowerOperation(Op, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6715 | assert(Tmp.getNode() && "Node must be custom expanded!"); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6716 | ExpandOp(Tmp.getValue(0), Lo, Hi); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6717 | AddLegalizedOperand(SDValue(Node, 1), // Remember we legalized the chain. |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6718 | LegalizeOp(Tmp.getValue(1))); |
Andrew Lenharth | f70e30b | 2005-11-20 21:32:07 +0000 | [diff] [blame] | 6719 | break; |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6720 | } |
Andrew Lenharth | f70e30b | 2005-11-20 21:32:07 +0000 | [diff] [blame] | 6721 | |
Dan Gohman | 0b1d4a7 | 2008-12-23 21:37:04 +0000 | [diff] [blame] | 6722 | case ISD::ATOMIC_CMP_SWAP: { |
Dale Johannesen | 1b54c7f | 2008-10-03 19:41:08 +0000 | [diff] [blame] | 6723 | // This operation does not need a loop. |
| 6724 | SDValue Tmp = TLI.LowerOperation(Op, DAG); |
| 6725 | assert(Tmp.getNode() && "Node must be custom expanded!"); |
| 6726 | ExpandOp(Tmp.getValue(0), Lo, Hi); |
| 6727 | AddLegalizedOperand(SDValue(Node, 1), // Remember we legalized the chain. |
| 6728 | LegalizeOp(Tmp.getValue(1))); |
| 6729 | break; |
| 6730 | } |
| 6731 | |
Dan Gohman | 0b1d4a7 | 2008-12-23 21:37:04 +0000 | [diff] [blame] | 6732 | case ISD::ATOMIC_LOAD_ADD: |
| 6733 | case ISD::ATOMIC_LOAD_SUB: |
| 6734 | case ISD::ATOMIC_LOAD_AND: |
| 6735 | case ISD::ATOMIC_LOAD_OR: |
| 6736 | case ISD::ATOMIC_LOAD_XOR: |
| 6737 | case ISD::ATOMIC_LOAD_NAND: |
| 6738 | case ISD::ATOMIC_SWAP: { |
Dale Johannesen | 1b54c7f | 2008-10-03 19:41:08 +0000 | [diff] [blame] | 6739 | // These operations require a loop to be generated. We can't do that yet, |
| 6740 | // so substitute a target-dependent pseudo and expand that later. |
Dale Johannesen | 48c1bc2 | 2008-10-02 18:53:47 +0000 | [diff] [blame] | 6741 | SDValue In2Lo, In2Hi, In2; |
| 6742 | ExpandOp(Op.getOperand(2), In2Lo, In2Hi); |
| 6743 | In2 = DAG.getNode(ISD::BUILD_PAIR, VT, In2Lo, In2Hi); |
Dale Johannesen | 1b54c7f | 2008-10-03 19:41:08 +0000 | [diff] [blame] | 6744 | AtomicSDNode* Anode = cast<AtomicSDNode>(Node); |
| 6745 | SDValue Replace = |
Dan Gohman | 0b1d4a7 | 2008-12-23 21:37:04 +0000 | [diff] [blame] | 6746 | DAG.getAtomic(Op.getOpcode(), Anode->getMemoryVT(), |
| 6747 | Op.getOperand(0), Op.getOperand(1), In2, |
Dale Johannesen | 1b54c7f | 2008-10-03 19:41:08 +0000 | [diff] [blame] | 6748 | Anode->getSrcValue(), Anode->getAlignment()); |
| 6749 | SDValue Result = TLI.LowerOperation(Replace, DAG); |
Dale Johannesen | 48c1bc2 | 2008-10-02 18:53:47 +0000 | [diff] [blame] | 6750 | ExpandOp(Result.getValue(0), Lo, Hi); |
| 6751 | // Remember that we legalized the chain. |
| 6752 | AddLegalizedOperand(SDValue(Node,1), LegalizeOp(Result.getValue(1))); |
Andrew Lenharth | d19189e | 2008-03-05 01:15:49 +0000 | [diff] [blame] | 6753 | break; |
| 6754 | } |
| 6755 | |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 6756 | // These operators cannot be expanded directly, emit them as calls to |
| 6757 | // library functions. |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6758 | case ISD::FP_TO_SINT: { |
Chris Lattner | 80a3e94 | 2005-07-29 00:33:32 +0000 | [diff] [blame] | 6759 | if (TLI.getOperationAction(ISD::FP_TO_SINT, VT) == TargetLowering::Custom) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6760 | SDValue Op; |
Chris Lattner | f20d183 | 2005-07-30 01:40:57 +0000 | [diff] [blame] | 6761 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 6762 | case Expand: assert(0 && "cannot expand FP!"); |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6763 | case Legal: Op = LegalizeOp(Node->getOperand(0)); break; |
| 6764 | case Promote: Op = PromoteOp (Node->getOperand(0)); break; |
Chris Lattner | f20d183 | 2005-07-30 01:40:57 +0000 | [diff] [blame] | 6765 | } |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 6766 | |
Chris Lattner | f20d183 | 2005-07-30 01:40:57 +0000 | [diff] [blame] | 6767 | Op = TLI.LowerOperation(DAG.getNode(ISD::FP_TO_SINT, VT, Op), DAG); |
| 6768 | |
Chris Lattner | 80a3e94 | 2005-07-29 00:33:32 +0000 | [diff] [blame] | 6769 | // Now that the custom expander is done, expand the result, which is still |
| 6770 | // VT. |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6771 | if (Op.getNode()) { |
Chris Lattner | 07dffd6 | 2005-08-26 00:14:16 +0000 | [diff] [blame] | 6772 | ExpandOp(Op, Lo, Hi); |
| 6773 | break; |
| 6774 | } |
Chris Lattner | 80a3e94 | 2005-07-29 00:33:32 +0000 | [diff] [blame] | 6775 | } |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 6776 | |
Duncan Sands | b2ff885 | 2008-07-17 02:36:29 +0000 | [diff] [blame] | 6777 | RTLIB::Libcall LC = RTLIB::getFPTOSINT(Node->getOperand(0).getValueType(), |
| 6778 | VT); |
| 6779 | assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unexpected uint-to-fp conversion!"); |
| 6780 | Lo = ExpandLibCall(LC, Node, false/*sign irrelevant*/, Hi); |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 6781 | break; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6782 | } |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 6783 | |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6784 | case ISD::FP_TO_UINT: { |
Chris Lattner | 80a3e94 | 2005-07-29 00:33:32 +0000 | [diff] [blame] | 6785 | if (TLI.getOperationAction(ISD::FP_TO_UINT, VT) == TargetLowering::Custom) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6786 | SDValue Op; |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6787 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 6788 | case Expand: assert(0 && "cannot expand FP!"); |
| 6789 | case Legal: Op = LegalizeOp(Node->getOperand(0)); break; |
| 6790 | case Promote: Op = PromoteOp (Node->getOperand(0)); break; |
| 6791 | } |
| 6792 | |
| 6793 | Op = TLI.LowerOperation(DAG.getNode(ISD::FP_TO_UINT, VT, Op), DAG); |
| 6794 | |
| 6795 | // Now that the custom expander is done, expand the result. |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6796 | if (Op.getNode()) { |
Chris Lattner | 07dffd6 | 2005-08-26 00:14:16 +0000 | [diff] [blame] | 6797 | ExpandOp(Op, Lo, Hi); |
| 6798 | break; |
| 6799 | } |
Chris Lattner | 80a3e94 | 2005-07-29 00:33:32 +0000 | [diff] [blame] | 6800 | } |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 6801 | |
Duncan Sands | b2ff885 | 2008-07-17 02:36:29 +0000 | [diff] [blame] | 6802 | RTLIB::Libcall LC = RTLIB::getFPTOUINT(Node->getOperand(0).getValueType(), |
| 6803 | VT); |
| 6804 | assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unexpected fp-to-uint conversion!"); |
| 6805 | Lo = ExpandLibCall(LC, Node, false/*sign irrelevant*/, Hi); |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 6806 | break; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6807 | } |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 6808 | |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 6809 | case ISD::SHL: { |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6810 | // If the target wants custom lowering, do so. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6811 | SDValue ShiftAmt = LegalizeOp(Node->getOperand(1)); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6812 | if (TLI.getOperationAction(ISD::SHL, VT) == TargetLowering::Custom) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6813 | SDValue Op = DAG.getNode(ISD::SHL, VT, Node->getOperand(0), ShiftAmt); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6814 | Op = TLI.LowerOperation(Op, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6815 | if (Op.getNode()) { |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6816 | // Now that the custom expander is done, expand the result, which is |
| 6817 | // still VT. |
| 6818 | ExpandOp(Op, Lo, Hi); |
| 6819 | break; |
| 6820 | } |
| 6821 | } |
| 6822 | |
Chris Lattner | 79980b0 | 2006-09-13 03:50:39 +0000 | [diff] [blame] | 6823 | // If ADDC/ADDE are supported and if the shift amount is a constant 1, emit |
| 6824 | // this X << 1 as X+X. |
| 6825 | if (ConstantSDNode *ShAmt = dyn_cast<ConstantSDNode>(ShiftAmt)) { |
Dan Gohman | f560ffa | 2009-01-28 17:46:25 +0000 | [diff] [blame] | 6826 | if (ShAmt->getAPIntValue() == 1 && |
| 6827 | TLI.isOperationLegalOrCustom(ISD::ADDC, NVT) && |
| 6828 | TLI.isOperationLegalOrCustom(ISD::ADDE, NVT)) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6829 | SDValue LoOps[2], HiOps[3]; |
Chris Lattner | 79980b0 | 2006-09-13 03:50:39 +0000 | [diff] [blame] | 6830 | ExpandOp(Node->getOperand(0), LoOps[0], HiOps[0]); |
| 6831 | SDVTList VTList = DAG.getVTList(LoOps[0].getValueType(), MVT::Flag); |
| 6832 | LoOps[1] = LoOps[0]; |
| 6833 | Lo = DAG.getNode(ISD::ADDC, VTList, LoOps, 2); |
| 6834 | |
| 6835 | HiOps[1] = HiOps[0]; |
| 6836 | HiOps[2] = Lo.getValue(1); |
| 6837 | Hi = DAG.getNode(ISD::ADDE, VTList, HiOps, 3); |
| 6838 | break; |
| 6839 | } |
| 6840 | } |
| 6841 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6842 | // If we can emit an efficient shift operation, do so now. |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 6843 | if (ExpandShift(ISD::SHL, Node->getOperand(0), ShiftAmt, Lo, Hi)) |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6844 | break; |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 6845 | |
| 6846 | // If this target supports SHL_PARTS, use it. |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 6847 | TargetLowering::LegalizeAction Action = |
| 6848 | TLI.getOperationAction(ISD::SHL_PARTS, NVT); |
| 6849 | if ((Action == TargetLowering::Legal && TLI.isTypeLegal(NVT)) || |
| 6850 | Action == TargetLowering::Custom) { |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 6851 | ExpandShiftParts(ISD::SHL_PARTS, Node->getOperand(0), ShiftAmt, Lo, Hi); |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 6852 | break; |
| 6853 | } |
| 6854 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6855 | // Otherwise, emit a libcall. |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 6856 | Lo = ExpandLibCall(RTLIB::SHL_I64, Node, false/*left shift=unsigned*/, Hi); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6857 | break; |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 6858 | } |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6859 | |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 6860 | case ISD::SRA: { |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6861 | // If the target wants custom lowering, do so. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6862 | SDValue ShiftAmt = LegalizeOp(Node->getOperand(1)); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6863 | if (TLI.getOperationAction(ISD::SRA, VT) == TargetLowering::Custom) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6864 | SDValue Op = DAG.getNode(ISD::SRA, VT, Node->getOperand(0), ShiftAmt); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6865 | Op = TLI.LowerOperation(Op, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6866 | if (Op.getNode()) { |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6867 | // Now that the custom expander is done, expand the result, which is |
| 6868 | // still VT. |
| 6869 | ExpandOp(Op, Lo, Hi); |
| 6870 | break; |
| 6871 | } |
| 6872 | } |
| 6873 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6874 | // If we can emit an efficient shift operation, do so now. |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 6875 | if (ExpandShift(ISD::SRA, Node->getOperand(0), ShiftAmt, Lo, Hi)) |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6876 | break; |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 6877 | |
| 6878 | // If this target supports SRA_PARTS, use it. |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 6879 | TargetLowering::LegalizeAction Action = |
| 6880 | TLI.getOperationAction(ISD::SRA_PARTS, NVT); |
| 6881 | if ((Action == TargetLowering::Legal && TLI.isTypeLegal(NVT)) || |
| 6882 | Action == TargetLowering::Custom) { |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 6883 | ExpandShiftParts(ISD::SRA_PARTS, Node->getOperand(0), ShiftAmt, Lo, Hi); |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 6884 | break; |
| 6885 | } |
| 6886 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6887 | // Otherwise, emit a libcall. |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 6888 | Lo = ExpandLibCall(RTLIB::SRA_I64, Node, true/*ashr is signed*/, Hi); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6889 | break; |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 6890 | } |
| 6891 | |
| 6892 | case ISD::SRL: { |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6893 | // If the target wants custom lowering, do so. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6894 | SDValue ShiftAmt = LegalizeOp(Node->getOperand(1)); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6895 | if (TLI.getOperationAction(ISD::SRL, VT) == TargetLowering::Custom) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6896 | SDValue Op = DAG.getNode(ISD::SRL, VT, Node->getOperand(0), ShiftAmt); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6897 | Op = TLI.LowerOperation(Op, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6898 | if (Op.getNode()) { |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6899 | // Now that the custom expander is done, expand the result, which is |
| 6900 | // still VT. |
| 6901 | ExpandOp(Op, Lo, Hi); |
| 6902 | break; |
| 6903 | } |
| 6904 | } |
| 6905 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6906 | // If we can emit an efficient shift operation, do so now. |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 6907 | if (ExpandShift(ISD::SRL, Node->getOperand(0), ShiftAmt, Lo, Hi)) |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6908 | break; |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 6909 | |
| 6910 | // If this target supports SRL_PARTS, use it. |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 6911 | TargetLowering::LegalizeAction Action = |
| 6912 | TLI.getOperationAction(ISD::SRL_PARTS, NVT); |
| 6913 | if ((Action == TargetLowering::Legal && TLI.isTypeLegal(NVT)) || |
| 6914 | Action == TargetLowering::Custom) { |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 6915 | ExpandShiftParts(ISD::SRL_PARTS, Node->getOperand(0), ShiftAmt, Lo, Hi); |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 6916 | break; |
| 6917 | } |
| 6918 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6919 | // Otherwise, emit a libcall. |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 6920 | Lo = ExpandLibCall(RTLIB::SRL_I64, Node, false/*lshr is unsigned*/, Hi); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6921 | break; |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 6922 | } |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6923 | |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 6924 | case ISD::ADD: |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6925 | case ISD::SUB: { |
| 6926 | // If the target wants to custom expand this, let them. |
| 6927 | if (TLI.getOperationAction(Node->getOpcode(), VT) == |
| 6928 | TargetLowering::Custom) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6929 | SDValue Result = TLI.LowerOperation(Op, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6930 | if (Result.getNode()) { |
Duncan Sands | 69bfb15 | 2008-06-22 09:42:16 +0000 | [diff] [blame] | 6931 | ExpandOp(Result, Lo, Hi); |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6932 | break; |
| 6933 | } |
| 6934 | } |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6935 | // Expand the subcomponents. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6936 | SDValue LHSL, LHSH, RHSL, RHSH; |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6937 | ExpandOp(Node->getOperand(0), LHSL, LHSH); |
| 6938 | ExpandOp(Node->getOperand(1), RHSL, RHSH); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6939 | SDValue LoOps[2], HiOps[3]; |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 6940 | LoOps[0] = LHSL; |
| 6941 | LoOps[1] = RHSL; |
| 6942 | HiOps[0] = LHSH; |
| 6943 | HiOps[1] = RHSH; |
Andrew Lenharth | 2163ca1 | 2008-10-07 18:27:23 +0000 | [diff] [blame] | 6944 | |
Andrew Lenharth | 5c9cc13 | 2008-10-07 17:03:15 +0000 | [diff] [blame] | 6945 | //cascaded check to see if any smaller size has a a carry flag. |
| 6946 | unsigned OpV = Node->getOpcode() == ISD::ADD ? ISD::ADDC : ISD::SUBC; |
| 6947 | bool hasCarry = false; |
Andrew Lenharth | 2163ca1 | 2008-10-07 18:27:23 +0000 | [diff] [blame] | 6948 | for (unsigned BitSize = NVT.getSizeInBits(); BitSize != 0; BitSize /= 2) { |
| 6949 | MVT AVT = MVT::getIntegerVT(BitSize); |
Dan Gohman | f560ffa | 2009-01-28 17:46:25 +0000 | [diff] [blame] | 6950 | if (TLI.isOperationLegalOrCustom(OpV, AVT)) { |
Andrew Lenharth | 2163ca1 | 2008-10-07 18:27:23 +0000 | [diff] [blame] | 6951 | hasCarry = true; |
| 6952 | break; |
| 6953 | } |
| 6954 | } |
| 6955 | |
Andrew Lenharth | 5c9cc13 | 2008-10-07 17:03:15 +0000 | [diff] [blame] | 6956 | if(hasCarry) { |
Evan Cheng | 637ed03 | 2008-12-12 18:49:09 +0000 | [diff] [blame] | 6957 | SDVTList VTList = DAG.getVTList(LHSL.getValueType(), MVT::Flag); |
Andrew Lenharth | 40d5139 | 2008-10-07 14:15:42 +0000 | [diff] [blame] | 6958 | if (Node->getOpcode() == ISD::ADD) { |
| 6959 | Lo = DAG.getNode(ISD::ADDC, VTList, LoOps, 2); |
| 6960 | HiOps[2] = Lo.getValue(1); |
| 6961 | Hi = DAG.getNode(ISD::ADDE, VTList, HiOps, 3); |
| 6962 | } else { |
| 6963 | Lo = DAG.getNode(ISD::SUBC, VTList, LoOps, 2); |
| 6964 | HiOps[2] = Lo.getValue(1); |
| 6965 | Hi = DAG.getNode(ISD::SUBE, VTList, HiOps, 3); |
| 6966 | } |
| 6967 | break; |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 6968 | } else { |
Andrew Lenharth | 40d5139 | 2008-10-07 14:15:42 +0000 | [diff] [blame] | 6969 | if (Node->getOpcode() == ISD::ADD) { |
Evan Cheng | 637ed03 | 2008-12-12 18:49:09 +0000 | [diff] [blame] | 6970 | Lo = DAG.getNode(ISD::ADD, NVT, LoOps, 2); |
| 6971 | Hi = DAG.getNode(ISD::ADD, NVT, HiOps, 2); |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 6972 | SDValue Cmp1 = DAG.getSetCC(TLI.getSetCCResultType(NVT), |
Andrew Lenharth | 5c9cc13 | 2008-10-07 17:03:15 +0000 | [diff] [blame] | 6973 | Lo, LoOps[0], ISD::SETULT); |
Andrew Lenharth | 40d5139 | 2008-10-07 14:15:42 +0000 | [diff] [blame] | 6974 | SDValue Carry1 = DAG.getNode(ISD::SELECT, NVT, Cmp1, |
| 6975 | DAG.getConstant(1, NVT), |
| 6976 | DAG.getConstant(0, NVT)); |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 6977 | SDValue Cmp2 = DAG.getSetCC(TLI.getSetCCResultType(NVT), |
Andrew Lenharth | 5c9cc13 | 2008-10-07 17:03:15 +0000 | [diff] [blame] | 6978 | Lo, LoOps[1], ISD::SETULT); |
Andrew Lenharth | 40d5139 | 2008-10-07 14:15:42 +0000 | [diff] [blame] | 6979 | SDValue Carry2 = DAG.getNode(ISD::SELECT, NVT, Cmp2, |
| 6980 | DAG.getConstant(1, NVT), |
| 6981 | Carry1); |
| 6982 | Hi = DAG.getNode(ISD::ADD, NVT, Hi, Carry2); |
| 6983 | } else { |
Evan Cheng | 637ed03 | 2008-12-12 18:49:09 +0000 | [diff] [blame] | 6984 | Lo = DAG.getNode(ISD::SUB, NVT, LoOps, 2); |
| 6985 | Hi = DAG.getNode(ISD::SUB, NVT, HiOps, 2); |
Andrew Lenharth | 40d5139 | 2008-10-07 14:15:42 +0000 | [diff] [blame] | 6986 | SDValue Cmp = DAG.getSetCC(NVT, LoOps[0], LoOps[1], ISD::SETULT); |
| 6987 | SDValue Borrow = DAG.getNode(ISD::SELECT, NVT, Cmp, |
| 6988 | DAG.getConstant(1, NVT), |
| 6989 | DAG.getConstant(0, NVT)); |
| 6990 | Hi = DAG.getNode(ISD::SUB, NVT, Hi, Borrow); |
| 6991 | } |
| 6992 | break; |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 6993 | } |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6994 | } |
Chris Lattner | b429f73 | 2007-05-17 18:15:41 +0000 | [diff] [blame] | 6995 | |
| 6996 | case ISD::ADDC: |
| 6997 | case ISD::SUBC: { |
| 6998 | // Expand the subcomponents. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6999 | SDValue LHSL, LHSH, RHSL, RHSH; |
Chris Lattner | b429f73 | 2007-05-17 18:15:41 +0000 | [diff] [blame] | 7000 | ExpandOp(Node->getOperand(0), LHSL, LHSH); |
| 7001 | ExpandOp(Node->getOperand(1), RHSL, RHSH); |
| 7002 | SDVTList VTList = DAG.getVTList(LHSL.getValueType(), MVT::Flag); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7003 | SDValue LoOps[2] = { LHSL, RHSL }; |
| 7004 | SDValue HiOps[3] = { LHSH, RHSH }; |
Chris Lattner | b429f73 | 2007-05-17 18:15:41 +0000 | [diff] [blame] | 7005 | |
| 7006 | if (Node->getOpcode() == ISD::ADDC) { |
| 7007 | Lo = DAG.getNode(ISD::ADDC, VTList, LoOps, 2); |
| 7008 | HiOps[2] = Lo.getValue(1); |
| 7009 | Hi = DAG.getNode(ISD::ADDE, VTList, HiOps, 3); |
| 7010 | } else { |
| 7011 | Lo = DAG.getNode(ISD::SUBC, VTList, LoOps, 2); |
| 7012 | HiOps[2] = Lo.getValue(1); |
| 7013 | Hi = DAG.getNode(ISD::SUBE, VTList, HiOps, 3); |
| 7014 | } |
| 7015 | // Remember that we legalized the flag. |
| 7016 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Hi.getValue(1))); |
| 7017 | break; |
| 7018 | } |
| 7019 | case ISD::ADDE: |
| 7020 | case ISD::SUBE: { |
| 7021 | // Expand the subcomponents. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7022 | SDValue LHSL, LHSH, RHSL, RHSH; |
Chris Lattner | b429f73 | 2007-05-17 18:15:41 +0000 | [diff] [blame] | 7023 | ExpandOp(Node->getOperand(0), LHSL, LHSH); |
| 7024 | ExpandOp(Node->getOperand(1), RHSL, RHSH); |
| 7025 | SDVTList VTList = DAG.getVTList(LHSL.getValueType(), MVT::Flag); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7026 | SDValue LoOps[3] = { LHSL, RHSL, Node->getOperand(2) }; |
| 7027 | SDValue HiOps[3] = { LHSH, RHSH }; |
Chris Lattner | b429f73 | 2007-05-17 18:15:41 +0000 | [diff] [blame] | 7028 | |
| 7029 | Lo = DAG.getNode(Node->getOpcode(), VTList, LoOps, 3); |
| 7030 | HiOps[2] = Lo.getValue(1); |
| 7031 | Hi = DAG.getNode(Node->getOpcode(), VTList, HiOps, 3); |
| 7032 | |
| 7033 | // Remember that we legalized the flag. |
| 7034 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Hi.getValue(1))); |
| 7035 | break; |
| 7036 | } |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 7037 | case ISD::MUL: { |
Chris Lattner | 7d7bffe | 2006-09-16 00:09:24 +0000 | [diff] [blame] | 7038 | // If the target wants to custom expand this, let them. |
| 7039 | if (TLI.getOperationAction(ISD::MUL, VT) == TargetLowering::Custom) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7040 | SDValue New = TLI.LowerOperation(Op, DAG); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 7041 | if (New.getNode()) { |
Chris Lattner | 8829dc8 | 2006-09-16 05:08:34 +0000 | [diff] [blame] | 7042 | ExpandOp(New, Lo, Hi); |
Chris Lattner | 7d7bffe | 2006-09-16 00:09:24 +0000 | [diff] [blame] | 7043 | break; |
| 7044 | } |
| 7045 | } |
| 7046 | |
Dan Gohman | f560ffa | 2009-01-28 17:46:25 +0000 | [diff] [blame] | 7047 | bool HasMULHS = TLI.isOperationLegalOrCustom(ISD::MULHS, NVT); |
| 7048 | bool HasMULHU = TLI.isOperationLegalOrCustom(ISD::MULHU, NVT); |
| 7049 | bool HasSMUL_LOHI = TLI.isOperationLegalOrCustom(ISD::SMUL_LOHI, NVT); |
| 7050 | bool HasUMUL_LOHI = TLI.isOperationLegalOrCustom(ISD::UMUL_LOHI, NVT); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 7051 | if (HasMULHU || HasMULHS || HasUMUL_LOHI || HasSMUL_LOHI) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7052 | SDValue LL, LH, RL, RH; |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 7053 | ExpandOp(Node->getOperand(0), LL, LH); |
| 7054 | ExpandOp(Node->getOperand(1), RL, RH); |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 7055 | unsigned OuterBitSize = Op.getValueSizeInBits(); |
| 7056 | unsigned InnerBitSize = RH.getValueSizeInBits(); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 7057 | unsigned LHSSB = DAG.ComputeNumSignBits(Op.getOperand(0)); |
| 7058 | unsigned RHSSB = DAG.ComputeNumSignBits(Op.getOperand(1)); |
Dan Gohman | 76c605b | 2008-03-10 20:42:19 +0000 | [diff] [blame] | 7059 | APInt HighMask = APInt::getHighBitsSet(OuterBitSize, InnerBitSize); |
| 7060 | if (DAG.MaskedValueIsZero(Node->getOperand(0), HighMask) && |
| 7061 | DAG.MaskedValueIsZero(Node->getOperand(1), HighMask)) { |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 7062 | // The inputs are both zero-extended. |
| 7063 | if (HasUMUL_LOHI) { |
| 7064 | // We can emit a umul_lohi. |
| 7065 | Lo = DAG.getNode(ISD::UMUL_LOHI, DAG.getVTList(NVT, NVT), LL, RL); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 7066 | Hi = SDValue(Lo.getNode(), 1); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 7067 | break; |
| 7068 | } |
| 7069 | if (HasMULHU) { |
| 7070 | // We can emit a mulhu+mul. |
| 7071 | Lo = DAG.getNode(ISD::MUL, NVT, LL, RL); |
| 7072 | Hi = DAG.getNode(ISD::MULHU, NVT, LL, RL); |
| 7073 | break; |
| 7074 | } |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 7075 | } |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 7076 | if (LHSSB > InnerBitSize && RHSSB > InnerBitSize) { |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 7077 | // The input values are both sign-extended. |
| 7078 | if (HasSMUL_LOHI) { |
| 7079 | // We can emit a smul_lohi. |
| 7080 | Lo = DAG.getNode(ISD::SMUL_LOHI, DAG.getVTList(NVT, NVT), LL, RL); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 7081 | Hi = SDValue(Lo.getNode(), 1); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 7082 | break; |
| 7083 | } |
| 7084 | if (HasMULHS) { |
| 7085 | // We can emit a mulhs+mul. |
| 7086 | Lo = DAG.getNode(ISD::MUL, NVT, LL, RL); |
| 7087 | Hi = DAG.getNode(ISD::MULHS, NVT, LL, RL); |
| 7088 | break; |
| 7089 | } |
| 7090 | } |
| 7091 | if (HasUMUL_LOHI) { |
| 7092 | // Lo,Hi = umul LHS, RHS. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7093 | SDValue UMulLOHI = DAG.getNode(ISD::UMUL_LOHI, |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 7094 | DAG.getVTList(NVT, NVT), LL, RL); |
| 7095 | Lo = UMulLOHI; |
| 7096 | Hi = UMulLOHI.getValue(1); |
Nate Begeman | 56eb868 | 2005-08-30 02:44:00 +0000 | [diff] [blame] | 7097 | RH = DAG.getNode(ISD::MUL, NVT, LL, RH); |
| 7098 | LH = DAG.getNode(ISD::MUL, NVT, LH, RL); |
| 7099 | Hi = DAG.getNode(ISD::ADD, NVT, Hi, RH); |
| 7100 | Hi = DAG.getNode(ISD::ADD, NVT, Hi, LH); |
Chris Lattner | a89654b | 2006-09-16 00:21:44 +0000 | [diff] [blame] | 7101 | break; |
Nate Begeman | 56eb868 | 2005-08-30 02:44:00 +0000 | [diff] [blame] | 7102 | } |
Dale Johannesen | 8eadd5a | 2007-10-24 22:26:08 +0000 | [diff] [blame] | 7103 | if (HasMULHU) { |
| 7104 | Lo = DAG.getNode(ISD::MUL, NVT, LL, RL); |
| 7105 | Hi = DAG.getNode(ISD::MULHU, NVT, LL, RL); |
| 7106 | RH = DAG.getNode(ISD::MUL, NVT, LL, RH); |
| 7107 | LH = DAG.getNode(ISD::MUL, NVT, LH, RL); |
| 7108 | Hi = DAG.getNode(ISD::ADD, NVT, Hi, RH); |
| 7109 | Hi = DAG.getNode(ISD::ADD, NVT, Hi, LH); |
| 7110 | break; |
| 7111 | } |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 7112 | } |
Evan Cheng | 3f4fd0f | 2006-09-01 18:17:58 +0000 | [diff] [blame] | 7113 | |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 7114 | // If nothing else, we can make a libcall. |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 7115 | Lo = ExpandLibCall(RTLIB::MUL_I64, Node, false/*sign irrelevant*/, Hi); |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 7116 | break; |
| 7117 | } |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 7118 | case ISD::SDIV: |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 7119 | Lo = ExpandLibCall(RTLIB::SDIV_I64, Node, true, Hi); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 7120 | break; |
| 7121 | case ISD::UDIV: |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 7122 | Lo = ExpandLibCall(RTLIB::UDIV_I64, Node, true, Hi); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 7123 | break; |
| 7124 | case ISD::SREM: |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 7125 | Lo = ExpandLibCall(RTLIB::SREM_I64, Node, true, Hi); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 7126 | break; |
| 7127 | case ISD::UREM: |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 7128 | Lo = ExpandLibCall(RTLIB::UREM_I64, Node, true, Hi); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 7129 | break; |
Evan Cheng | 5c9ce18 | 2006-12-12 21:51:17 +0000 | [diff] [blame] | 7130 | |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 7131 | case ISD::FADD: |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 7132 | Lo = ExpandLibCall(GetFPLibCall(VT, RTLIB::ADD_F32, |
| 7133 | RTLIB::ADD_F64, |
| 7134 | RTLIB::ADD_F80, |
| 7135 | RTLIB::ADD_PPCF128), |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 7136 | Node, false, Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 7137 | break; |
| 7138 | case ISD::FSUB: |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 7139 | Lo = ExpandLibCall(GetFPLibCall(VT, RTLIB::SUB_F32, |
| 7140 | RTLIB::SUB_F64, |
| 7141 | RTLIB::SUB_F80, |
| 7142 | RTLIB::SUB_PPCF128), |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 7143 | Node, false, Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 7144 | break; |
| 7145 | case ISD::FMUL: |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 7146 | Lo = ExpandLibCall(GetFPLibCall(VT, RTLIB::MUL_F32, |
| 7147 | RTLIB::MUL_F64, |
| 7148 | RTLIB::MUL_F80, |
| 7149 | RTLIB::MUL_PPCF128), |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 7150 | Node, false, Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 7151 | break; |
| 7152 | case ISD::FDIV: |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 7153 | Lo = ExpandLibCall(GetFPLibCall(VT, RTLIB::DIV_F32, |
| 7154 | RTLIB::DIV_F64, |
| 7155 | RTLIB::DIV_F80, |
| 7156 | RTLIB::DIV_PPCF128), |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 7157 | Node, false, Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 7158 | break; |
Duncan Sands | b2ff885 | 2008-07-17 02:36:29 +0000 | [diff] [blame] | 7159 | case ISD::FP_EXTEND: { |
Dale Johannesen | ca68aaa | 2007-10-12 01:37:08 +0000 | [diff] [blame] | 7160 | if (VT == MVT::ppcf128) { |
| 7161 | assert(Node->getOperand(0).getValueType()==MVT::f32 || |
| 7162 | Node->getOperand(0).getValueType()==MVT::f64); |
| 7163 | const uint64_t zero = 0; |
| 7164 | if (Node->getOperand(0).getValueType()==MVT::f32) |
| 7165 | Hi = DAG.getNode(ISD::FP_EXTEND, MVT::f64, Node->getOperand(0)); |
| 7166 | else |
| 7167 | Hi = Node->getOperand(0); |
| 7168 | Lo = DAG.getConstantFP(APFloat(APInt(64, 1, &zero)), MVT::f64); |
| 7169 | break; |
| 7170 | } |
Duncan Sands | b2ff885 | 2008-07-17 02:36:29 +0000 | [diff] [blame] | 7171 | RTLIB::Libcall LC = RTLIB::getFPEXT(Node->getOperand(0).getValueType(), VT); |
| 7172 | assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported FP_EXTEND!"); |
| 7173 | Lo = ExpandLibCall(LC, Node, true, Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 7174 | break; |
Duncan Sands | b2ff885 | 2008-07-17 02:36:29 +0000 | [diff] [blame] | 7175 | } |
| 7176 | case ISD::FP_ROUND: { |
| 7177 | RTLIB::Libcall LC = RTLIB::getFPROUND(Node->getOperand(0).getValueType(), |
| 7178 | VT); |
| 7179 | assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported FP_ROUND!"); |
| 7180 | Lo = ExpandLibCall(LC, Node, true, Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 7181 | break; |
Duncan Sands | b2ff885 | 2008-07-17 02:36:29 +0000 | [diff] [blame] | 7182 | } |
Evan Cheng | 4b88702 | 2008-09-09 23:02:14 +0000 | [diff] [blame] | 7183 | case ISD::FSQRT: |
| 7184 | case ISD::FSIN: |
| 7185 | case ISD::FCOS: |
Dale Johannesen | 7794f2a | 2008-09-04 00:47:13 +0000 | [diff] [blame] | 7186 | case ISD::FLOG: |
| 7187 | case ISD::FLOG2: |
| 7188 | case ISD::FLOG10: |
| 7189 | case ISD::FEXP: |
| 7190 | case ISD::FEXP2: |
Dan Gohman | 2bb1e3e | 2008-08-21 18:38:14 +0000 | [diff] [blame] | 7191 | case ISD::FTRUNC: |
| 7192 | case ISD::FFLOOR: |
| 7193 | case ISD::FCEIL: |
| 7194 | case ISD::FRINT: |
| 7195 | case ISD::FNEARBYINT: |
Evan Cheng | 9d24ac5 | 2008-09-09 23:35:53 +0000 | [diff] [blame] | 7196 | case ISD::FPOW: |
| 7197 | case ISD::FPOWI: { |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 7198 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
Evan Cheng | 98ff3b9 | 2006-12-13 02:38:13 +0000 | [diff] [blame] | 7199 | switch(Node->getOpcode()) { |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 7200 | case ISD::FSQRT: |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 7201 | LC = GetFPLibCall(VT, RTLIB::SQRT_F32, RTLIB::SQRT_F64, |
| 7202 | RTLIB::SQRT_F80, RTLIB::SQRT_PPCF128); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 7203 | break; |
| 7204 | case ISD::FSIN: |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 7205 | LC = GetFPLibCall(VT, RTLIB::SIN_F32, RTLIB::SIN_F64, |
| 7206 | RTLIB::SIN_F80, RTLIB::SIN_PPCF128); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 7207 | break; |
| 7208 | case ISD::FCOS: |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 7209 | LC = GetFPLibCall(VT, RTLIB::COS_F32, RTLIB::COS_F64, |
| 7210 | RTLIB::COS_F80, RTLIB::COS_PPCF128); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 7211 | break; |
Dale Johannesen | 7794f2a | 2008-09-04 00:47:13 +0000 | [diff] [blame] | 7212 | case ISD::FLOG: |
| 7213 | LC = GetFPLibCall(VT, RTLIB::LOG_F32, RTLIB::LOG_F64, |
| 7214 | RTLIB::LOG_F80, RTLIB::LOG_PPCF128); |
| 7215 | break; |
| 7216 | case ISD::FLOG2: |
| 7217 | LC = GetFPLibCall(VT, RTLIB::LOG2_F32, RTLIB::LOG2_F64, |
| 7218 | RTLIB::LOG2_F80, RTLIB::LOG2_PPCF128); |
| 7219 | break; |
| 7220 | case ISD::FLOG10: |
| 7221 | LC = GetFPLibCall(VT, RTLIB::LOG10_F32, RTLIB::LOG10_F64, |
| 7222 | RTLIB::LOG10_F80, RTLIB::LOG10_PPCF128); |
| 7223 | break; |
| 7224 | case ISD::FEXP: |
| 7225 | LC = GetFPLibCall(VT, RTLIB::EXP_F32, RTLIB::EXP_F64, |
| 7226 | RTLIB::EXP_F80, RTLIB::EXP_PPCF128); |
| 7227 | break; |
| 7228 | case ISD::FEXP2: |
| 7229 | LC = GetFPLibCall(VT, RTLIB::EXP2_F32, RTLIB::EXP2_F64, |
| 7230 | RTLIB::EXP2_F80, RTLIB::EXP2_PPCF128); |
| 7231 | break; |
Dan Gohman | 2bb1e3e | 2008-08-21 18:38:14 +0000 | [diff] [blame] | 7232 | case ISD::FTRUNC: |
| 7233 | LC = GetFPLibCall(VT, RTLIB::TRUNC_F32, RTLIB::TRUNC_F64, |
| 7234 | RTLIB::TRUNC_F80, RTLIB::TRUNC_PPCF128); |
| 7235 | break; |
| 7236 | case ISD::FFLOOR: |
| 7237 | LC = GetFPLibCall(VT, RTLIB::FLOOR_F32, RTLIB::FLOOR_F64, |
| 7238 | RTLIB::FLOOR_F80, RTLIB::FLOOR_PPCF128); |
| 7239 | break; |
| 7240 | case ISD::FCEIL: |
| 7241 | LC = GetFPLibCall(VT, RTLIB::CEIL_F32, RTLIB::CEIL_F64, |
| 7242 | RTLIB::CEIL_F80, RTLIB::CEIL_PPCF128); |
| 7243 | break; |
| 7244 | case ISD::FRINT: |
| 7245 | LC = GetFPLibCall(VT, RTLIB::RINT_F32, RTLIB::RINT_F64, |
| 7246 | RTLIB::RINT_F80, RTLIB::RINT_PPCF128); |
| 7247 | break; |
| 7248 | case ISD::FNEARBYINT: |
| 7249 | LC = GetFPLibCall(VT, RTLIB::NEARBYINT_F32, RTLIB::NEARBYINT_F64, |
| 7250 | RTLIB::NEARBYINT_F80, RTLIB::NEARBYINT_PPCF128); |
| 7251 | break; |
Evan Cheng | 4b88702 | 2008-09-09 23:02:14 +0000 | [diff] [blame] | 7252 | case ISD::FPOW: |
| 7253 | LC = GetFPLibCall(VT, RTLIB::POW_F32, RTLIB::POW_F64, RTLIB::POW_F80, |
| 7254 | RTLIB::POW_PPCF128); |
| 7255 | break; |
| 7256 | case ISD::FPOWI: |
| 7257 | LC = GetFPLibCall(VT, RTLIB::POWI_F32, RTLIB::POWI_F64, RTLIB::POWI_F80, |
| 7258 | RTLIB::POWI_PPCF128); |
| 7259 | break; |
Evan Cheng | 98ff3b9 | 2006-12-13 02:38:13 +0000 | [diff] [blame] | 7260 | default: assert(0 && "Unreachable!"); |
| 7261 | } |
Duncan Sands | 460a14e | 2008-04-12 17:14:18 +0000 | [diff] [blame] | 7262 | Lo = ExpandLibCall(LC, Node, false, Hi); |
Evan Cheng | 98ff3b9 | 2006-12-13 02:38:13 +0000 | [diff] [blame] | 7263 | break; |
| 7264 | } |
Evan Cheng | 966bf24 | 2006-12-16 00:52:40 +0000 | [diff] [blame] | 7265 | case ISD::FABS: { |
Dale Johannesen | f646774 | 2007-10-12 19:02:17 +0000 | [diff] [blame] | 7266 | if (VT == MVT::ppcf128) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7267 | SDValue Tmp; |
Dale Johannesen | f646774 | 2007-10-12 19:02:17 +0000 | [diff] [blame] | 7268 | ExpandOp(Node->getOperand(0), Lo, Tmp); |
| 7269 | Hi = DAG.getNode(ISD::FABS, NVT, Tmp); |
| 7270 | // lo = hi==fabs(hi) ? lo : -lo; |
| 7271 | Lo = DAG.getNode(ISD::SELECT_CC, NVT, Hi, Tmp, |
| 7272 | Lo, DAG.getNode(ISD::FNEG, NVT, Lo), |
| 7273 | DAG.getCondCode(ISD::SETEQ)); |
| 7274 | break; |
| 7275 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7276 | SDValue Mask = (VT == MVT::f64) |
Evan Cheng | 966bf24 | 2006-12-16 00:52:40 +0000 | [diff] [blame] | 7277 | ? DAG.getConstantFP(BitsToDouble(~(1ULL << 63)), VT) |
| 7278 | : DAG.getConstantFP(BitsToFloat(~(1U << 31)), VT); |
| 7279 | Mask = DAG.getNode(ISD::BIT_CONVERT, NVT, Mask); |
| 7280 | Lo = DAG.getNode(ISD::BIT_CONVERT, NVT, Node->getOperand(0)); |
| 7281 | Lo = DAG.getNode(ISD::AND, NVT, Lo, Mask); |
| 7282 | if (getTypeAction(NVT) == Expand) |
| 7283 | ExpandOp(Lo, Lo, Hi); |
| 7284 | break; |
| 7285 | } |
| 7286 | case ISD::FNEG: { |
Dale Johannesen | f646774 | 2007-10-12 19:02:17 +0000 | [diff] [blame] | 7287 | if (VT == MVT::ppcf128) { |
| 7288 | ExpandOp(Node->getOperand(0), Lo, Hi); |
| 7289 | Lo = DAG.getNode(ISD::FNEG, MVT::f64, Lo); |
| 7290 | Hi = DAG.getNode(ISD::FNEG, MVT::f64, Hi); |
| 7291 | break; |
| 7292 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7293 | SDValue Mask = (VT == MVT::f64) |
Evan Cheng | 966bf24 | 2006-12-16 00:52:40 +0000 | [diff] [blame] | 7294 | ? DAG.getConstantFP(BitsToDouble(1ULL << 63), VT) |
| 7295 | : DAG.getConstantFP(BitsToFloat(1U << 31), VT); |
| 7296 | Mask = DAG.getNode(ISD::BIT_CONVERT, NVT, Mask); |
| 7297 | Lo = DAG.getNode(ISD::BIT_CONVERT, NVT, Node->getOperand(0)); |
| 7298 | Lo = DAG.getNode(ISD::XOR, NVT, Lo, Mask); |
| 7299 | if (getTypeAction(NVT) == Expand) |
| 7300 | ExpandOp(Lo, Lo, Hi); |
| 7301 | break; |
| 7302 | } |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 7303 | case ISD::FCOPYSIGN: { |
| 7304 | Lo = ExpandFCOPYSIGNToBitwiseOps(Node, NVT, DAG, TLI); |
| 7305 | if (getTypeAction(NVT) == Expand) |
| 7306 | ExpandOp(Lo, Lo, Hi); |
| 7307 | break; |
| 7308 | } |
Evan Cheng | 7df28dc | 2006-12-19 01:44:04 +0000 | [diff] [blame] | 7309 | case ISD::SINT_TO_FP: |
| 7310 | case ISD::UINT_TO_FP: { |
| 7311 | bool isSigned = Node->getOpcode() == ISD::SINT_TO_FP; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 7312 | MVT SrcVT = Node->getOperand(0).getValueType(); |
Dale Johannesen | cf49819 | 2008-03-18 17:28:38 +0000 | [diff] [blame] | 7313 | |
| 7314 | // Promote the operand if needed. Do this before checking for |
| 7315 | // ppcf128 so conversions of i16 and i8 work. |
| 7316 | if (getTypeAction(SrcVT) == Promote) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7317 | SDValue Tmp = PromoteOp(Node->getOperand(0)); |
Dale Johannesen | cf49819 | 2008-03-18 17:28:38 +0000 | [diff] [blame] | 7318 | Tmp = isSigned |
| 7319 | ? DAG.getNode(ISD::SIGN_EXTEND_INREG, Tmp.getValueType(), Tmp, |
| 7320 | DAG.getValueType(SrcVT)) |
| 7321 | : DAG.getZeroExtendInReg(Tmp, SrcVT); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 7322 | Node = DAG.UpdateNodeOperands(Op, Tmp).getNode(); |
Dale Johannesen | cf49819 | 2008-03-18 17:28:38 +0000 | [diff] [blame] | 7323 | SrcVT = Node->getOperand(0).getValueType(); |
| 7324 | } |
| 7325 | |
Dan Gohman | a2e9485 | 2008-03-10 23:03:31 +0000 | [diff] [blame] | 7326 | if (VT == MVT::ppcf128 && SrcVT == MVT::i32) { |
Dan Gohman | f6283fd | 2008-02-25 21:39:34 +0000 | [diff] [blame] | 7327 | static const uint64_t zero = 0; |
Dale Johannesen | ca68aaa | 2007-10-12 01:37:08 +0000 | [diff] [blame] | 7328 | if (isSigned) { |
| 7329 | Hi = LegalizeOp(DAG.getNode(ISD::SINT_TO_FP, MVT::f64, |
| 7330 | Node->getOperand(0))); |
| 7331 | Lo = DAG.getConstantFP(APFloat(APInt(64, 1, &zero)), MVT::f64); |
| 7332 | } else { |
Dan Gohman | f6283fd | 2008-02-25 21:39:34 +0000 | [diff] [blame] | 7333 | static const uint64_t TwoE32[] = { 0x41f0000000000000LL, 0 }; |
Dale Johannesen | ca68aaa | 2007-10-12 01:37:08 +0000 | [diff] [blame] | 7334 | Hi = LegalizeOp(DAG.getNode(ISD::SINT_TO_FP, MVT::f64, |
| 7335 | Node->getOperand(0))); |
| 7336 | Lo = DAG.getConstantFP(APFloat(APInt(64, 1, &zero)), MVT::f64); |
| 7337 | Hi = DAG.getNode(ISD::BUILD_PAIR, VT, Lo, Hi); |
Dale Johannesen | 6e63e09 | 2007-10-12 17:52:03 +0000 | [diff] [blame] | 7338 | // X>=0 ? {(f64)x, 0} : {(f64)x, 0} + 2^32 |
Dale Johannesen | ca68aaa | 2007-10-12 01:37:08 +0000 | [diff] [blame] | 7339 | ExpandOp(DAG.getNode(ISD::SELECT_CC, MVT::ppcf128, Node->getOperand(0), |
| 7340 | DAG.getConstant(0, MVT::i32), |
| 7341 | DAG.getNode(ISD::FADD, MVT::ppcf128, Hi, |
| 7342 | DAG.getConstantFP( |
| 7343 | APFloat(APInt(128, 2, TwoE32)), |
| 7344 | MVT::ppcf128)), |
| 7345 | Hi, |
| 7346 | DAG.getCondCode(ISD::SETLT)), |
| 7347 | Lo, Hi); |
| 7348 | } |
| 7349 | break; |
| 7350 | } |
Dale Johannesen | 6e63e09 | 2007-10-12 17:52:03 +0000 | [diff] [blame] | 7351 | if (VT == MVT::ppcf128 && SrcVT == MVT::i64 && !isSigned) { |
| 7352 | // si64->ppcf128 done by libcall, below |
Dan Gohman | f6283fd | 2008-02-25 21:39:34 +0000 | [diff] [blame] | 7353 | static const uint64_t TwoE64[] = { 0x43f0000000000000LL, 0 }; |
Dale Johannesen | 6e63e09 | 2007-10-12 17:52:03 +0000 | [diff] [blame] | 7354 | ExpandOp(DAG.getNode(ISD::SINT_TO_FP, MVT::ppcf128, Node->getOperand(0)), |
| 7355 | Lo, Hi); |
| 7356 | Hi = DAG.getNode(ISD::BUILD_PAIR, VT, Lo, Hi); |
| 7357 | // x>=0 ? (ppcf128)(i64)x : (ppcf128)(i64)x + 2^64 |
| 7358 | ExpandOp(DAG.getNode(ISD::SELECT_CC, MVT::ppcf128, Node->getOperand(0), |
| 7359 | DAG.getConstant(0, MVT::i64), |
| 7360 | DAG.getNode(ISD::FADD, MVT::ppcf128, Hi, |
| 7361 | DAG.getConstantFP( |
| 7362 | APFloat(APInt(128, 2, TwoE64)), |
| 7363 | MVT::ppcf128)), |
| 7364 | Hi, |
| 7365 | DAG.getCondCode(ISD::SETLT)), |
| 7366 | Lo, Hi); |
| 7367 | break; |
| 7368 | } |
Evan Cheng | 7df28dc | 2006-12-19 01:44:04 +0000 | [diff] [blame] | 7369 | |
Dan Gohman | a2e9485 | 2008-03-10 23:03:31 +0000 | [diff] [blame] | 7370 | Lo = ExpandIntToFP(Node->getOpcode() == ISD::SINT_TO_FP, VT, |
| 7371 | Node->getOperand(0)); |
Evan Cheng | 110cf48 | 2008-04-01 01:50:16 +0000 | [diff] [blame] | 7372 | if (getTypeAction(Lo.getValueType()) == Expand) |
Evan Cheng | 6ad2f93 | 2008-04-01 01:51:26 +0000 | [diff] [blame] | 7373 | // float to i32 etc. can be 'expanded' to a single node. |
Evan Cheng | 110cf48 | 2008-04-01 01:50:16 +0000 | [diff] [blame] | 7374 | ExpandOp(Lo, Lo, Hi); |
Evan Cheng | 7df28dc | 2006-12-19 01:44:04 +0000 | [diff] [blame] | 7375 | break; |
| 7376 | } |
Evan Cheng | 98ff3b9 | 2006-12-13 02:38:13 +0000 | [diff] [blame] | 7377 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 7378 | |
Chris Lattner | 8339736 | 2005-12-21 18:02:52 +0000 | [diff] [blame] | 7379 | // Make sure the resultant values have been legalized themselves, unless this |
| 7380 | // is a type that requires multi-step expansion. |
| 7381 | if (getTypeAction(NVT) != Expand && NVT != MVT::isVoid) { |
| 7382 | Lo = LegalizeOp(Lo); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 7383 | if (Hi.getNode()) |
Evan Cheng | 13acce3 | 2006-12-11 19:27:14 +0000 | [diff] [blame] | 7384 | // Don't legalize the high part if it is expanded to a single node. |
| 7385 | Hi = LegalizeOp(Hi); |
Chris Lattner | 8339736 | 2005-12-21 18:02:52 +0000 | [diff] [blame] | 7386 | } |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 7387 | |
| 7388 | // Remember in a map if the values will be reused later. |
Dan Gohman | 6b345ee | 2008-07-07 17:46:23 +0000 | [diff] [blame] | 7389 | bool isNew = |
| 7390 | ExpandedNodes.insert(std::make_pair(Op, std::make_pair(Lo, Hi))).second; |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 7391 | assert(isNew && "Value already expanded?!?"); |
Evan Cheng | 24ac408 | 2008-11-24 07:09:49 +0000 | [diff] [blame] | 7392 | isNew = isNew; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 7393 | } |
| 7394 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7395 | /// SplitVectorOp - Given an operand of vector type, break it down into |
| 7396 | /// two smaller values, still of vector type. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7397 | void SelectionDAGLegalize::SplitVectorOp(SDValue Op, SDValue &Lo, |
| 7398 | SDValue &Hi) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 7399 | assert(Op.getValueType().isVector() && "Cannot split non-vector type!"); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 7400 | SDNode *Node = Op.getNode(); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 7401 | unsigned NumElements = Op.getValueType().getVectorNumElements(); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7402 | assert(NumElements > 1 && "Cannot split a single element vector!"); |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7403 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 7404 | MVT NewEltVT = Op.getValueType().getVectorElementType(); |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7405 | |
| 7406 | unsigned NewNumElts_Lo = 1 << Log2_32(NumElements-1); |
| 7407 | unsigned NewNumElts_Hi = NumElements - NewNumElts_Lo; |
| 7408 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 7409 | MVT NewVT_Lo = MVT::getVectorVT(NewEltVT, NewNumElts_Lo); |
| 7410 | MVT NewVT_Hi = MVT::getVectorVT(NewEltVT, NewNumElts_Hi); |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7411 | |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7412 | // See if we already split it. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7413 | std::map<SDValue, std::pair<SDValue, SDValue> >::iterator I |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7414 | = SplitNodes.find(Op); |
| 7415 | if (I != SplitNodes.end()) { |
| 7416 | Lo = I->second.first; |
| 7417 | Hi = I->second.second; |
| 7418 | return; |
| 7419 | } |
| 7420 | |
| 7421 | switch (Node->getOpcode()) { |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 7422 | default: |
| 7423 | #ifndef NDEBUG |
Dan Gohman | 3983358 | 2007-06-04 16:17:33 +0000 | [diff] [blame] | 7424 | Node->dump(&DAG); |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 7425 | #endif |
| 7426 | assert(0 && "Unhandled operation in SplitVectorOp!"); |
Chris Lattner | daf9bc8 | 2007-11-19 20:21:32 +0000 | [diff] [blame] | 7427 | case ISD::UNDEF: |
| 7428 | Lo = DAG.getNode(ISD::UNDEF, NewVT_Lo); |
| 7429 | Hi = DAG.getNode(ISD::UNDEF, NewVT_Hi); |
| 7430 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7431 | case ISD::BUILD_PAIR: |
| 7432 | Lo = Node->getOperand(0); |
| 7433 | Hi = Node->getOperand(1); |
| 7434 | break; |
Dan Gohman | 9fe4662 | 2007-09-28 23:53:40 +0000 | [diff] [blame] | 7435 | case ISD::INSERT_VECTOR_ELT: { |
Nate Begeman | 6867991 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 7436 | if (ConstantSDNode *Idx = dyn_cast<ConstantSDNode>(Node->getOperand(2))) { |
| 7437 | SplitVectorOp(Node->getOperand(0), Lo, Hi); |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 7438 | unsigned Index = Idx->getZExtValue(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7439 | SDValue ScalarOp = Node->getOperand(1); |
Nate Begeman | 6867991 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 7440 | if (Index < NewNumElts_Lo) |
| 7441 | Lo = DAG.getNode(ISD::INSERT_VECTOR_ELT, NewVT_Lo, Lo, ScalarOp, |
| 7442 | DAG.getIntPtrConstant(Index)); |
| 7443 | else |
| 7444 | Hi = DAG.getNode(ISD::INSERT_VECTOR_ELT, NewVT_Hi, Hi, ScalarOp, |
| 7445 | DAG.getIntPtrConstant(Index - NewNumElts_Lo)); |
| 7446 | break; |
| 7447 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7448 | SDValue Tmp = PerformInsertVectorEltInMemory(Node->getOperand(0), |
Nate Begeman | 6867991 | 2008-04-25 18:07:40 +0000 | [diff] [blame] | 7449 | Node->getOperand(1), |
| 7450 | Node->getOperand(2)); |
| 7451 | SplitVectorOp(Tmp, Lo, Hi); |
Dan Gohman | 9fe4662 | 2007-09-28 23:53:40 +0000 | [diff] [blame] | 7452 | break; |
| 7453 | } |
Chris Lattner | 6c9c680 | 2007-11-19 21:16:54 +0000 | [diff] [blame] | 7454 | case ISD::VECTOR_SHUFFLE: { |
| 7455 | // Build the low part. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7456 | SDValue Mask = Node->getOperand(2); |
| 7457 | SmallVector<SDValue, 8> Ops; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 7458 | MVT PtrVT = TLI.getPointerTy(); |
Chris Lattner | 6c9c680 | 2007-11-19 21:16:54 +0000 | [diff] [blame] | 7459 | |
| 7460 | // Insert all of the elements from the input that are needed. We use |
| 7461 | // buildvector of extractelement here because the input vectors will have |
| 7462 | // to be legalized, so this makes the code simpler. |
| 7463 | for (unsigned i = 0; i != NewNumElts_Lo; ++i) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7464 | SDValue IdxNode = Mask.getOperand(i); |
Nate Begeman | 5922f56 | 2008-03-14 00:53:31 +0000 | [diff] [blame] | 7465 | if (IdxNode.getOpcode() == ISD::UNDEF) { |
| 7466 | Ops.push_back(DAG.getNode(ISD::UNDEF, NewEltVT)); |
| 7467 | continue; |
| 7468 | } |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 7469 | unsigned Idx = cast<ConstantSDNode>(IdxNode)->getZExtValue(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7470 | SDValue InVec = Node->getOperand(0); |
Chris Lattner | 6c9c680 | 2007-11-19 21:16:54 +0000 | [diff] [blame] | 7471 | if (Idx >= NumElements) { |
| 7472 | InVec = Node->getOperand(1); |
| 7473 | Idx -= NumElements; |
| 7474 | } |
| 7475 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, NewEltVT, InVec, |
| 7476 | DAG.getConstant(Idx, PtrVT))); |
| 7477 | } |
| 7478 | Lo = DAG.getNode(ISD::BUILD_VECTOR, NewVT_Lo, &Ops[0], Ops.size()); |
| 7479 | Ops.clear(); |
| 7480 | |
| 7481 | for (unsigned i = NewNumElts_Lo; i != NumElements; ++i) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7482 | SDValue IdxNode = Mask.getOperand(i); |
Nate Begeman | 5922f56 | 2008-03-14 00:53:31 +0000 | [diff] [blame] | 7483 | if (IdxNode.getOpcode() == ISD::UNDEF) { |
| 7484 | Ops.push_back(DAG.getNode(ISD::UNDEF, NewEltVT)); |
| 7485 | continue; |
| 7486 | } |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 7487 | unsigned Idx = cast<ConstantSDNode>(IdxNode)->getZExtValue(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7488 | SDValue InVec = Node->getOperand(0); |
Chris Lattner | 6c9c680 | 2007-11-19 21:16:54 +0000 | [diff] [blame] | 7489 | if (Idx >= NumElements) { |
| 7490 | InVec = Node->getOperand(1); |
| 7491 | Idx -= NumElements; |
| 7492 | } |
| 7493 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, NewEltVT, InVec, |
| 7494 | DAG.getConstant(Idx, PtrVT))); |
| 7495 | } |
Mon P Wang | 92879f3 | 2008-07-25 01:30:26 +0000 | [diff] [blame] | 7496 | Hi = DAG.getNode(ISD::BUILD_VECTOR, NewVT_Hi, &Ops[0], Ops.size()); |
Chris Lattner | 6c9c680 | 2007-11-19 21:16:54 +0000 | [diff] [blame] | 7497 | break; |
| 7498 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7499 | case ISD::BUILD_VECTOR: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7500 | SmallVector<SDValue, 8> LoOps(Node->op_begin(), |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7501 | Node->op_begin()+NewNumElts_Lo); |
| 7502 | Lo = DAG.getNode(ISD::BUILD_VECTOR, NewVT_Lo, &LoOps[0], LoOps.size()); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7503 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7504 | SmallVector<SDValue, 8> HiOps(Node->op_begin()+NewNumElts_Lo, |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7505 | Node->op_end()); |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7506 | Hi = DAG.getNode(ISD::BUILD_VECTOR, NewVT_Hi, &HiOps[0], HiOps.size()); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7507 | break; |
| 7508 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7509 | case ISD::CONCAT_VECTORS: { |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7510 | // FIXME: Handle non-power-of-two vectors? |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7511 | unsigned NewNumSubvectors = Node->getNumOperands() / 2; |
| 7512 | if (NewNumSubvectors == 1) { |
| 7513 | Lo = Node->getOperand(0); |
| 7514 | Hi = Node->getOperand(1); |
| 7515 | } else { |
Mon P Wang | aeb06d2 | 2008-11-10 04:46:22 +0000 | [diff] [blame] | 7516 | SmallVector<SDValue, 8> LoOps(Node->op_begin(), |
| 7517 | Node->op_begin()+NewNumSubvectors); |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7518 | Lo = DAG.getNode(ISD::CONCAT_VECTORS, NewVT_Lo, &LoOps[0], LoOps.size()); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 7519 | |
Mon P Wang | aeb06d2 | 2008-11-10 04:46:22 +0000 | [diff] [blame] | 7520 | SmallVector<SDValue, 8> HiOps(Node->op_begin()+NewNumSubvectors, |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7521 | Node->op_end()); |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7522 | Hi = DAG.getNode(ISD::CONCAT_VECTORS, NewVT_Hi, &HiOps[0], HiOps.size()); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7523 | } |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 7524 | break; |
| 7525 | } |
Mon P Wang | aeb06d2 | 2008-11-10 04:46:22 +0000 | [diff] [blame] | 7526 | case ISD::EXTRACT_SUBVECTOR: { |
| 7527 | SDValue Vec = Op.getOperand(0); |
| 7528 | SDValue Idx = Op.getOperand(1); |
| 7529 | MVT IdxVT = Idx.getValueType(); |
| 7530 | |
| 7531 | Lo = DAG.getNode(ISD::EXTRACT_SUBVECTOR, NewVT_Lo, Vec, Idx); |
| 7532 | ConstantSDNode *CIdx = dyn_cast<ConstantSDNode>(Idx); |
| 7533 | if (CIdx) { |
| 7534 | Hi = DAG.getNode(ISD::EXTRACT_SUBVECTOR, NewVT_Hi, Vec, |
| 7535 | DAG.getConstant(CIdx->getZExtValue() + NewNumElts_Lo, |
| 7536 | IdxVT)); |
| 7537 | } else { |
| 7538 | Idx = DAG.getNode(ISD::ADD, IdxVT, Idx, |
| 7539 | DAG.getConstant(NewNumElts_Lo, IdxVT)); |
| 7540 | Hi = DAG.getNode(ISD::EXTRACT_SUBVECTOR, NewVT_Hi, Vec, Idx); |
| 7541 | } |
| 7542 | break; |
| 7543 | } |
Dan Gohman | c623096 | 2007-10-17 14:48:28 +0000 | [diff] [blame] | 7544 | case ISD::SELECT: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7545 | SDValue Cond = Node->getOperand(0); |
Dan Gohman | c623096 | 2007-10-17 14:48:28 +0000 | [diff] [blame] | 7546 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7547 | SDValue LL, LH, RL, RH; |
Dan Gohman | c623096 | 2007-10-17 14:48:28 +0000 | [diff] [blame] | 7548 | SplitVectorOp(Node->getOperand(1), LL, LH); |
| 7549 | SplitVectorOp(Node->getOperand(2), RL, RH); |
| 7550 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 7551 | if (Cond.getValueType().isVector()) { |
Dan Gohman | c623096 | 2007-10-17 14:48:28 +0000 | [diff] [blame] | 7552 | // Handle a vector merge. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7553 | SDValue CL, CH; |
Dan Gohman | c623096 | 2007-10-17 14:48:28 +0000 | [diff] [blame] | 7554 | SplitVectorOp(Cond, CL, CH); |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7555 | Lo = DAG.getNode(Node->getOpcode(), NewVT_Lo, CL, LL, RL); |
| 7556 | Hi = DAG.getNode(Node->getOpcode(), NewVT_Hi, CH, LH, RH); |
Dan Gohman | c623096 | 2007-10-17 14:48:28 +0000 | [diff] [blame] | 7557 | } else { |
| 7558 | // Handle a simple select with vector operands. |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7559 | Lo = DAG.getNode(Node->getOpcode(), NewVT_Lo, Cond, LL, RL); |
| 7560 | Hi = DAG.getNode(Node->getOpcode(), NewVT_Hi, Cond, LH, RH); |
Dan Gohman | c623096 | 2007-10-17 14:48:28 +0000 | [diff] [blame] | 7561 | } |
| 7562 | break; |
| 7563 | } |
Chris Lattner | 80c1a56 | 2008-06-30 02:43:01 +0000 | [diff] [blame] | 7564 | case ISD::SELECT_CC: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7565 | SDValue CondLHS = Node->getOperand(0); |
| 7566 | SDValue CondRHS = Node->getOperand(1); |
| 7567 | SDValue CondCode = Node->getOperand(4); |
Chris Lattner | 80c1a56 | 2008-06-30 02:43:01 +0000 | [diff] [blame] | 7568 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7569 | SDValue LL, LH, RL, RH; |
Chris Lattner | 80c1a56 | 2008-06-30 02:43:01 +0000 | [diff] [blame] | 7570 | SplitVectorOp(Node->getOperand(2), LL, LH); |
| 7571 | SplitVectorOp(Node->getOperand(3), RL, RH); |
| 7572 | |
| 7573 | // Handle a simple select with vector operands. |
| 7574 | Lo = DAG.getNode(ISD::SELECT_CC, NewVT_Lo, CondLHS, CondRHS, |
| 7575 | LL, RL, CondCode); |
| 7576 | Hi = DAG.getNode(ISD::SELECT_CC, NewVT_Hi, CondLHS, CondRHS, |
| 7577 | LH, RH, CondCode); |
| 7578 | break; |
| 7579 | } |
Nate Begeman | b43e9c1 | 2008-05-12 19:40:03 +0000 | [diff] [blame] | 7580 | case ISD::VSETCC: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7581 | SDValue LL, LH, RL, RH; |
Nate Begeman | b43e9c1 | 2008-05-12 19:40:03 +0000 | [diff] [blame] | 7582 | SplitVectorOp(Node->getOperand(0), LL, LH); |
| 7583 | SplitVectorOp(Node->getOperand(1), RL, RH); |
| 7584 | Lo = DAG.getNode(ISD::VSETCC, NewVT_Lo, LL, RL, Node->getOperand(2)); |
| 7585 | Hi = DAG.getNode(ISD::VSETCC, NewVT_Hi, LH, RH, Node->getOperand(2)); |
| 7586 | break; |
| 7587 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7588 | case ISD::ADD: |
| 7589 | case ISD::SUB: |
| 7590 | case ISD::MUL: |
| 7591 | case ISD::FADD: |
| 7592 | case ISD::FSUB: |
| 7593 | case ISD::FMUL: |
| 7594 | case ISD::SDIV: |
| 7595 | case ISD::UDIV: |
| 7596 | case ISD::FDIV: |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 7597 | case ISD::FPOW: |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7598 | case ISD::AND: |
| 7599 | case ISD::OR: |
Dan Gohman | 089617d | 2007-11-19 15:15:03 +0000 | [diff] [blame] | 7600 | case ISD::XOR: |
| 7601 | case ISD::UREM: |
| 7602 | case ISD::SREM: |
Mon P Wang | 87c8a8f | 2008-12-18 20:03:17 +0000 | [diff] [blame] | 7603 | case ISD::FREM: |
| 7604 | case ISD::SHL: |
| 7605 | case ISD::SRA: |
| 7606 | case ISD::SRL: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7607 | SDValue LL, LH, RL, RH; |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7608 | SplitVectorOp(Node->getOperand(0), LL, LH); |
| 7609 | SplitVectorOp(Node->getOperand(1), RL, RH); |
| 7610 | |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7611 | Lo = DAG.getNode(Node->getOpcode(), NewVT_Lo, LL, RL); |
| 7612 | Hi = DAG.getNode(Node->getOpcode(), NewVT_Hi, LH, RH); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7613 | break; |
| 7614 | } |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 7615 | case ISD::FP_ROUND: |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 7616 | case ISD::FPOWI: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7617 | SDValue L, H; |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 7618 | SplitVectorOp(Node->getOperand(0), L, H); |
| 7619 | |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7620 | Lo = DAG.getNode(Node->getOpcode(), NewVT_Lo, L, Node->getOperand(1)); |
| 7621 | Hi = DAG.getNode(Node->getOpcode(), NewVT_Hi, H, Node->getOperand(1)); |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 7622 | break; |
| 7623 | } |
| 7624 | case ISD::CTTZ: |
| 7625 | case ISD::CTLZ: |
| 7626 | case ISD::CTPOP: |
| 7627 | case ISD::FNEG: |
| 7628 | case ISD::FABS: |
| 7629 | case ISD::FSQRT: |
| 7630 | case ISD::FSIN: |
Nate Begeman | b348d18 | 2007-11-17 03:58:34 +0000 | [diff] [blame] | 7631 | case ISD::FCOS: |
Dale Johannesen | 7794f2a | 2008-09-04 00:47:13 +0000 | [diff] [blame] | 7632 | case ISD::FLOG: |
| 7633 | case ISD::FLOG2: |
| 7634 | case ISD::FLOG10: |
| 7635 | case ISD::FEXP: |
| 7636 | case ISD::FEXP2: |
Nate Begeman | b348d18 | 2007-11-17 03:58:34 +0000 | [diff] [blame] | 7637 | case ISD::FP_TO_SINT: |
| 7638 | case ISD::FP_TO_UINT: |
| 7639 | case ISD::SINT_TO_FP: |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 7640 | case ISD::UINT_TO_FP: |
| 7641 | case ISD::TRUNCATE: |
| 7642 | case ISD::ANY_EXTEND: |
| 7643 | case ISD::SIGN_EXTEND: |
| 7644 | case ISD::ZERO_EXTEND: |
| 7645 | case ISD::FP_EXTEND: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7646 | SDValue L, H; |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 7647 | SplitVectorOp(Node->getOperand(0), L, H); |
| 7648 | |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7649 | Lo = DAG.getNode(Node->getOpcode(), NewVT_Lo, L); |
| 7650 | Hi = DAG.getNode(Node->getOpcode(), NewVT_Hi, H); |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 7651 | break; |
| 7652 | } |
Mon P Wang | 77cdf30 | 2008-11-10 20:54:11 +0000 | [diff] [blame] | 7653 | case ISD::CONVERT_RNDSAT: { |
| 7654 | ISD::CvtCode CvtCode = cast<CvtRndSatSDNode>(Node)->getCvtCode(); |
| 7655 | SDValue L, H; |
| 7656 | SplitVectorOp(Node->getOperand(0), L, H); |
| 7657 | SDValue DTyOpL = DAG.getValueType(NewVT_Lo); |
| 7658 | SDValue DTyOpH = DAG.getValueType(NewVT_Hi); |
| 7659 | SDValue STyOpL = DAG.getValueType(L.getValueType()); |
| 7660 | SDValue STyOpH = DAG.getValueType(H.getValueType()); |
| 7661 | |
| 7662 | SDValue RndOp = Node->getOperand(3); |
| 7663 | SDValue SatOp = Node->getOperand(4); |
| 7664 | |
| 7665 | Lo = DAG.getConvertRndSat(NewVT_Lo, L, DTyOpL, STyOpL, |
| 7666 | RndOp, SatOp, CvtCode); |
| 7667 | Hi = DAG.getConvertRndSat(NewVT_Hi, H, DTyOpH, STyOpH, |
| 7668 | RndOp, SatOp, CvtCode); |
| 7669 | break; |
| 7670 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7671 | case ISD::LOAD: { |
| 7672 | LoadSDNode *LD = cast<LoadSDNode>(Node); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7673 | SDValue Ch = LD->getChain(); |
| 7674 | SDValue Ptr = LD->getBasePtr(); |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 7675 | ISD::LoadExtType ExtType = LD->getExtensionType(); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7676 | const Value *SV = LD->getSrcValue(); |
| 7677 | int SVOffset = LD->getSrcValueOffset(); |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 7678 | MVT MemoryVT = LD->getMemoryVT(); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7679 | unsigned Alignment = LD->getAlignment(); |
| 7680 | bool isVolatile = LD->isVolatile(); |
| 7681 | |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 7682 | assert(LD->isUnindexed() && "Indexed vector loads are not supported yet!"); |
| 7683 | SDValue Offset = DAG.getNode(ISD::UNDEF, Ptr.getValueType()); |
| 7684 | |
| 7685 | MVT MemNewEltVT = MemoryVT.getVectorElementType(); |
| 7686 | MVT MemNewVT_Lo = MVT::getVectorVT(MemNewEltVT, NewNumElts_Lo); |
| 7687 | MVT MemNewVT_Hi = MVT::getVectorVT(MemNewEltVT, NewNumElts_Hi); |
| 7688 | |
| 7689 | Lo = DAG.getLoad(ISD::UNINDEXED, ExtType, |
| 7690 | NewVT_Lo, Ch, Ptr, Offset, |
| 7691 | SV, SVOffset, MemNewVT_Lo, isVolatile, Alignment); |
| 7692 | unsigned IncrementSize = NewNumElts_Lo * MemNewEltVT.getSizeInBits()/8; |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7693 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 7694 | DAG.getIntPtrConstant(IncrementSize)); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7695 | SVOffset += IncrementSize; |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 7696 | Alignment = MinAlign(Alignment, IncrementSize); |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 7697 | Hi = DAG.getLoad(ISD::UNINDEXED, ExtType, |
| 7698 | NewVT_Hi, Ch, Ptr, Offset, |
| 7699 | SV, SVOffset, MemNewVT_Hi, isVolatile, Alignment); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7700 | |
| 7701 | // Build a factor node to remember that this load is independent of the |
| 7702 | // other one. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7703 | SDValue TF = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1), |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7704 | Hi.getValue(1)); |
| 7705 | |
| 7706 | // Remember that we legalized the chain. |
| 7707 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(TF)); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7708 | break; |
| 7709 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7710 | case ISD::BIT_CONVERT: { |
Chris Lattner | 7692eb4 | 2006-03-23 21:16:34 +0000 | [diff] [blame] | 7711 | // We know the result is a vector. The input may be either a vector or a |
| 7712 | // scalar value. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7713 | SDValue InOp = Node->getOperand(0); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 7714 | if (!InOp.getValueType().isVector() || |
| 7715 | InOp.getValueType().getVectorNumElements() == 1) { |
Dan Gohman | 10a7aa6 | 2007-06-29 00:09:08 +0000 | [diff] [blame] | 7716 | // The input is a scalar or single-element vector. |
| 7717 | // Lower to a store/load so that it can be split. |
| 7718 | // FIXME: this could be improved probably. |
Mon P Wang | 2920d2b | 2008-07-15 05:28:34 +0000 | [diff] [blame] | 7719 | unsigned LdAlign = TLI.getTargetData()->getPrefTypeAlignment( |
| 7720 | Op.getValueType().getTypeForMVT()); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7721 | SDValue Ptr = DAG.CreateStackTemporary(InOp.getValueType(), LdAlign); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 7722 | int FI = cast<FrameIndexSDNode>(Ptr.getNode())->getIndex(); |
Chris Lattner | 7692eb4 | 2006-03-23 21:16:34 +0000 | [diff] [blame] | 7723 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7724 | SDValue St = DAG.getStore(DAG.getEntryNode(), |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 7725 | InOp, Ptr, |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 7726 | PseudoSourceValue::getFixedStack(FI), 0); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 7727 | InOp = DAG.getLoad(Op.getValueType(), St, Ptr, |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 7728 | PseudoSourceValue::getFixedStack(FI), 0); |
Chris Lattner | 7692eb4 | 2006-03-23 21:16:34 +0000 | [diff] [blame] | 7729 | } |
Dan Gohman | 10a7aa6 | 2007-06-29 00:09:08 +0000 | [diff] [blame] | 7730 | // Split the vector and convert each of the pieces now. |
| 7731 | SplitVectorOp(InOp, Lo, Hi); |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7732 | Lo = DAG.getNode(ISD::BIT_CONVERT, NewVT_Lo, Lo); |
| 7733 | Hi = DAG.getNode(ISD::BIT_CONVERT, NewVT_Hi, Hi); |
Dan Gohman | 10a7aa6 | 2007-06-29 00:09:08 +0000 | [diff] [blame] | 7734 | break; |
Chris Lattner | 7692eb4 | 2006-03-23 21:16:34 +0000 | [diff] [blame] | 7735 | } |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7736 | } |
| 7737 | |
| 7738 | // Remember in a map if the values will be reused later. |
Chris Lattner | 40030bf | 2007-02-04 01:17:38 +0000 | [diff] [blame] | 7739 | bool isNew = |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7740 | SplitNodes.insert(std::make_pair(Op, std::make_pair(Lo, Hi))).second; |
Dan Gohman | 10a7aa6 | 2007-06-29 00:09:08 +0000 | [diff] [blame] | 7741 | assert(isNew && "Value already split?!?"); |
Evan Cheng | 24ac408 | 2008-11-24 07:09:49 +0000 | [diff] [blame] | 7742 | isNew = isNew; |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7743 | } |
| 7744 | |
| 7745 | |
Dan Gohman | 89b20c0 | 2007-06-27 14:06:22 +0000 | [diff] [blame] | 7746 | /// ScalarizeVectorOp - Given an operand of single-element vector type |
| 7747 | /// (e.g. v1f32), convert it into the equivalent operation that returns a |
| 7748 | /// scalar (e.g. f32) value. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7749 | SDValue SelectionDAGLegalize::ScalarizeVectorOp(SDValue Op) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 7750 | assert(Op.getValueType().isVector() && "Bad ScalarizeVectorOp invocation!"); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 7751 | SDNode *Node = Op.getNode(); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 7752 | MVT NewVT = Op.getValueType().getVectorElementType(); |
| 7753 | assert(Op.getValueType().getVectorNumElements() == 1); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7754 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7755 | // See if we already scalarized it. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7756 | std::map<SDValue, SDValue>::iterator I = ScalarizedNodes.find(Op); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7757 | if (I != ScalarizedNodes.end()) return I->second; |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7758 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7759 | SDValue Result; |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7760 | switch (Node->getOpcode()) { |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 7761 | default: |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 7762 | #ifndef NDEBUG |
Dan Gohman | 3983358 | 2007-06-04 16:17:33 +0000 | [diff] [blame] | 7763 | Node->dump(&DAG); cerr << "\n"; |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 7764 | #endif |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7765 | assert(0 && "Unknown vector operation in ScalarizeVectorOp!"); |
| 7766 | case ISD::ADD: |
| 7767 | case ISD::FADD: |
| 7768 | case ISD::SUB: |
| 7769 | case ISD::FSUB: |
| 7770 | case ISD::MUL: |
| 7771 | case ISD::FMUL: |
| 7772 | case ISD::SDIV: |
| 7773 | case ISD::UDIV: |
| 7774 | case ISD::FDIV: |
| 7775 | case ISD::SREM: |
| 7776 | case ISD::UREM: |
| 7777 | case ISD::FREM: |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 7778 | case ISD::FPOW: |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7779 | case ISD::AND: |
| 7780 | case ISD::OR: |
| 7781 | case ISD::XOR: |
| 7782 | Result = DAG.getNode(Node->getOpcode(), |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7783 | NewVT, |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7784 | ScalarizeVectorOp(Node->getOperand(0)), |
| 7785 | ScalarizeVectorOp(Node->getOperand(1))); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7786 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7787 | case ISD::FNEG: |
| 7788 | case ISD::FABS: |
| 7789 | case ISD::FSQRT: |
| 7790 | case ISD::FSIN: |
| 7791 | case ISD::FCOS: |
Dale Johannesen | 7794f2a | 2008-09-04 00:47:13 +0000 | [diff] [blame] | 7792 | case ISD::FLOG: |
| 7793 | case ISD::FLOG2: |
| 7794 | case ISD::FLOG10: |
| 7795 | case ISD::FEXP: |
| 7796 | case ISD::FEXP2: |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 7797 | case ISD::FP_TO_SINT: |
| 7798 | case ISD::FP_TO_UINT: |
| 7799 | case ISD::SINT_TO_FP: |
| 7800 | case ISD::UINT_TO_FP: |
| 7801 | case ISD::SIGN_EXTEND: |
| 7802 | case ISD::ZERO_EXTEND: |
| 7803 | case ISD::ANY_EXTEND: |
| 7804 | case ISD::TRUNCATE: |
| 7805 | case ISD::FP_EXTEND: |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7806 | Result = DAG.getNode(Node->getOpcode(), |
| 7807 | NewVT, |
| 7808 | ScalarizeVectorOp(Node->getOperand(0))); |
| 7809 | break; |
Mon P Wang | 77cdf30 | 2008-11-10 20:54:11 +0000 | [diff] [blame] | 7810 | case ISD::CONVERT_RNDSAT: { |
| 7811 | SDValue Op0 = ScalarizeVectorOp(Node->getOperand(0)); |
| 7812 | Result = DAG.getConvertRndSat(NewVT, Op0, |
| 7813 | DAG.getValueType(NewVT), |
| 7814 | DAG.getValueType(Op0.getValueType()), |
| 7815 | Node->getOperand(3), |
| 7816 | Node->getOperand(4), |
| 7817 | cast<CvtRndSatSDNode>(Node)->getCvtCode()); |
| 7818 | break; |
| 7819 | } |
Dan Gohman | 9e04c82 | 2007-10-12 14:13:46 +0000 | [diff] [blame] | 7820 | case ISD::FPOWI: |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 7821 | case ISD::FP_ROUND: |
Dan Gohman | 9e04c82 | 2007-10-12 14:13:46 +0000 | [diff] [blame] | 7822 | Result = DAG.getNode(Node->getOpcode(), |
| 7823 | NewVT, |
| 7824 | ScalarizeVectorOp(Node->getOperand(0)), |
| 7825 | Node->getOperand(1)); |
| 7826 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7827 | case ISD::LOAD: { |
| 7828 | LoadSDNode *LD = cast<LoadSDNode>(Node); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7829 | SDValue Ch = LegalizeOp(LD->getChain()); // Legalize the chain. |
| 7830 | SDValue Ptr = LegalizeOp(LD->getBasePtr()); // Legalize the pointer. |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 7831 | ISD::LoadExtType ExtType = LD->getExtensionType(); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7832 | const Value *SV = LD->getSrcValue(); |
| 7833 | int SVOffset = LD->getSrcValueOffset(); |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 7834 | MVT MemoryVT = LD->getMemoryVT(); |
| 7835 | unsigned Alignment = LD->getAlignment(); |
| 7836 | bool isVolatile = LD->isVolatile(); |
| 7837 | |
| 7838 | assert(LD->isUnindexed() && "Indexed vector loads are not supported yet!"); |
| 7839 | SDValue Offset = DAG.getNode(ISD::UNDEF, Ptr.getValueType()); |
| 7840 | |
| 7841 | Result = DAG.getLoad(ISD::UNINDEXED, ExtType, |
| 7842 | NewVT, Ch, Ptr, Offset, SV, SVOffset, |
| 7843 | MemoryVT.getVectorElementType(), |
| 7844 | isVolatile, Alignment); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7845 | |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7846 | // Remember that we legalized the chain. |
| 7847 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1))); |
| 7848 | break; |
| 7849 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7850 | case ISD::BUILD_VECTOR: |
| 7851 | Result = Node->getOperand(0); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7852 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7853 | case ISD::INSERT_VECTOR_ELT: |
| 7854 | // Returning the inserted scalar element. |
| 7855 | Result = Node->getOperand(1); |
| 7856 | break; |
| 7857 | case ISD::CONCAT_VECTORS: |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 7858 | assert(Node->getOperand(0).getValueType() == NewVT && |
| 7859 | "Concat of non-legal vectors not yet supported!"); |
| 7860 | Result = Node->getOperand(0); |
| 7861 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7862 | case ISD::VECTOR_SHUFFLE: { |
| 7863 | // 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] | 7864 | SDValue EltNum = Node->getOperand(2).getOperand(0); |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 7865 | if (cast<ConstantSDNode>(EltNum)->getZExtValue()) |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7866 | Result = ScalarizeVectorOp(Node->getOperand(1)); |
| 7867 | else |
| 7868 | Result = ScalarizeVectorOp(Node->getOperand(0)); |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 7869 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7870 | } |
| 7871 | case ISD::EXTRACT_SUBVECTOR: |
Mon P Wang | e0b436a | 2008-11-06 22:52:21 +0000 | [diff] [blame] | 7872 | Result = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, NewVT, Node->getOperand(0), |
Mon P Wang | aeb06d2 | 2008-11-10 04:46:22 +0000 | [diff] [blame] | 7873 | Node->getOperand(1)); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 7874 | break; |
Evan Cheng | 446efdd | 2008-05-16 17:19:05 +0000 | [diff] [blame] | 7875 | case ISD::BIT_CONVERT: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7876 | SDValue Op0 = Op.getOperand(0); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 7877 | if (Op0.getValueType().getVectorNumElements() == 1) |
Evan Cheng | 446efdd | 2008-05-16 17:19:05 +0000 | [diff] [blame] | 7878 | Op0 = ScalarizeVectorOp(Op0); |
| 7879 | Result = DAG.getNode(ISD::BIT_CONVERT, NewVT, Op0); |
Chris Lattner | 5b2316e | 2006-03-28 20:24:43 +0000 | [diff] [blame] | 7880 | break; |
Evan Cheng | 446efdd | 2008-05-16 17:19:05 +0000 | [diff] [blame] | 7881 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7882 | case ISD::SELECT: |
Chris Lattner | b22e35a | 2006-04-08 22:22:57 +0000 | [diff] [blame] | 7883 | Result = DAG.getNode(ISD::SELECT, NewVT, Op.getOperand(0), |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7884 | ScalarizeVectorOp(Op.getOperand(1)), |
| 7885 | ScalarizeVectorOp(Op.getOperand(2))); |
Chris Lattner | b22e35a | 2006-04-08 22:22:57 +0000 | [diff] [blame] | 7886 | break; |
Chris Lattner | 80c1a56 | 2008-06-30 02:43:01 +0000 | [diff] [blame] | 7887 | case ISD::SELECT_CC: |
| 7888 | Result = DAG.getNode(ISD::SELECT_CC, NewVT, Node->getOperand(0), |
| 7889 | Node->getOperand(1), |
| 7890 | ScalarizeVectorOp(Op.getOperand(2)), |
| 7891 | ScalarizeVectorOp(Op.getOperand(3)), |
| 7892 | Node->getOperand(4)); |
| 7893 | break; |
Nate Begeman | 0d1704b | 2008-05-12 23:09:43 +0000 | [diff] [blame] | 7894 | case ISD::VSETCC: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7895 | SDValue Op0 = ScalarizeVectorOp(Op.getOperand(0)); |
| 7896 | SDValue Op1 = ScalarizeVectorOp(Op.getOperand(1)); |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 7897 | Result = DAG.getNode(ISD::SETCC, TLI.getSetCCResultType(Op0.getValueType()), |
| 7898 | Op0, Op1, Op.getOperand(2)); |
Nate Begeman | 0d1704b | 2008-05-12 23:09:43 +0000 | [diff] [blame] | 7899 | Result = DAG.getNode(ISD::SELECT, NewVT, Result, |
| 7900 | DAG.getConstant(-1ULL, NewVT), |
| 7901 | DAG.getConstant(0ULL, NewVT)); |
| 7902 | break; |
| 7903 | } |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7904 | } |
| 7905 | |
| 7906 | if (TLI.isTypeLegal(NewVT)) |
| 7907 | Result = LegalizeOp(Result); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7908 | bool isNew = ScalarizedNodes.insert(std::make_pair(Op, Result)).second; |
| 7909 | assert(isNew && "Value already scalarized?"); |
Evan Cheng | 24ac408 | 2008-11-24 07:09:49 +0000 | [diff] [blame] | 7910 | isNew = isNew; |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7911 | return Result; |
| 7912 | } |
| 7913 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 7914 | |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 7915 | SDValue SelectionDAGLegalize::WidenVectorOp(SDValue Op, MVT WidenVT) { |
| 7916 | std::map<SDValue, SDValue>::iterator I = WidenNodes.find(Op); |
| 7917 | if (I != WidenNodes.end()) return I->second; |
| 7918 | |
| 7919 | MVT VT = Op.getValueType(); |
| 7920 | assert(VT.isVector() && "Cannot widen non-vector type!"); |
| 7921 | |
| 7922 | SDValue Result; |
| 7923 | SDNode *Node = Op.getNode(); |
| 7924 | MVT EVT = VT.getVectorElementType(); |
| 7925 | |
| 7926 | unsigned NumElts = VT.getVectorNumElements(); |
| 7927 | unsigned NewNumElts = WidenVT.getVectorNumElements(); |
| 7928 | assert(NewNumElts > NumElts && "Cannot widen to smaller type!"); |
| 7929 | assert(NewNumElts < 17); |
| 7930 | |
| 7931 | // When widen is called, it is assumed that it is more efficient to use a |
| 7932 | // wide type. The default action is to widen to operation to a wider legal |
| 7933 | // vector type and then do the operation if it is legal by calling LegalizeOp |
| 7934 | // again. If there is no vector equivalent, we will unroll the operation, do |
| 7935 | // it, and rebuild the vector. If most of the operations are vectorizible to |
| 7936 | // the legal type, the resulting code will be more efficient. If this is not |
| 7937 | // the case, the resulting code will preform badly as we end up generating |
| 7938 | // 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] | 7939 | // that is responsible for seeing this doesn't happen. |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 7940 | switch (Node->getOpcode()) { |
| 7941 | default: |
| 7942 | #ifndef NDEBUG |
| 7943 | Node->dump(&DAG); |
| 7944 | #endif |
| 7945 | assert(0 && "Unexpected operation in WidenVectorOp!"); |
| 7946 | break; |
| 7947 | case ISD::CopyFromReg: |
Mon P Wang | 49292f1 | 2008-11-15 06:05:52 +0000 | [diff] [blame] | 7948 | assert(0 && "CopyFromReg doesn't need widening!"); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 7949 | case ISD::Constant: |
| 7950 | case ISD::ConstantFP: |
| 7951 | // To build a vector of these elements, clients should call BuildVector |
| 7952 | // and with each element instead of creating a node with a vector type |
| 7953 | assert(0 && "Unexpected operation in WidenVectorOp!"); |
| 7954 | case ISD::VAARG: |
| 7955 | // Variable Arguments with vector types doesn't make any sense to me |
| 7956 | assert(0 && "Unexpected operation in WidenVectorOp!"); |
| 7957 | break; |
Mon P Wang | 49292f1 | 2008-11-15 06:05:52 +0000 | [diff] [blame] | 7958 | case ISD::UNDEF: |
| 7959 | Result = DAG.getNode(ISD::UNDEF, WidenVT); |
| 7960 | break; |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 7961 | case ISD::BUILD_VECTOR: { |
| 7962 | // Build a vector with undefined for the new nodes |
| 7963 | SDValueVector NewOps(Node->op_begin(), Node->op_end()); |
| 7964 | for (unsigned i = NumElts; i < NewNumElts; ++i) { |
| 7965 | NewOps.push_back(DAG.getNode(ISD::UNDEF,EVT)); |
| 7966 | } |
| 7967 | Result = DAG.getNode(ISD::BUILD_VECTOR, WidenVT, &NewOps[0], NewOps.size()); |
| 7968 | break; |
| 7969 | } |
| 7970 | case ISD::INSERT_VECTOR_ELT: { |
| 7971 | SDValue Tmp1 = WidenVectorOp(Node->getOperand(0), WidenVT); |
| 7972 | Result = DAG.getNode(ISD::INSERT_VECTOR_ELT, WidenVT, Tmp1, |
| 7973 | Node->getOperand(1), Node->getOperand(2)); |
| 7974 | break; |
| 7975 | } |
| 7976 | case ISD::VECTOR_SHUFFLE: { |
| 7977 | SDValue Tmp1 = WidenVectorOp(Node->getOperand(0), WidenVT); |
| 7978 | SDValue Tmp2 = WidenVectorOp(Node->getOperand(1), WidenVT); |
| 7979 | // VECTOR_SHUFFLE 3rd operand must be a constant build vector that is |
| 7980 | // used as permutation array. We build the vector here instead of widening |
| 7981 | // because we don't want to legalize and have it turned to something else. |
| 7982 | SDValue PermOp = Node->getOperand(2); |
| 7983 | SDValueVector NewOps; |
| 7984 | MVT PVT = PermOp.getValueType().getVectorElementType(); |
| 7985 | for (unsigned i = 0; i < NumElts; ++i) { |
| 7986 | if (PermOp.getOperand(i).getOpcode() == ISD::UNDEF) { |
| 7987 | NewOps.push_back(PermOp.getOperand(i)); |
| 7988 | } else { |
| 7989 | unsigned Idx = |
Mon P Wang | e1a0b2e | 2008-12-13 08:15:14 +0000 | [diff] [blame] | 7990 | cast<ConstantSDNode>(PermOp.getOperand(i))->getZExtValue(); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 7991 | if (Idx < NumElts) { |
| 7992 | NewOps.push_back(PermOp.getOperand(i)); |
| 7993 | } |
| 7994 | else { |
| 7995 | NewOps.push_back(DAG.getConstant(Idx + NewNumElts - NumElts, |
| 7996 | PermOp.getOperand(i).getValueType())); |
| 7997 | } |
| 7998 | } |
| 7999 | } |
| 8000 | for (unsigned i = NumElts; i < NewNumElts; ++i) { |
| 8001 | NewOps.push_back(DAG.getNode(ISD::UNDEF,PVT)); |
| 8002 | } |
| 8003 | |
| 8004 | SDValue Tmp3 = DAG.getNode(ISD::BUILD_VECTOR, |
| 8005 | MVT::getVectorVT(PVT, NewOps.size()), |
| 8006 | &NewOps[0], NewOps.size()); |
| 8007 | |
| 8008 | Result = DAG.getNode(ISD::VECTOR_SHUFFLE, WidenVT, Tmp1, Tmp2, Tmp3); |
| 8009 | break; |
| 8010 | } |
| 8011 | case ISD::LOAD: { |
| 8012 | // If the load widen returns true, we can use a single load for the |
| 8013 | // vector. Otherwise, it is returning a token factor for multiple |
| 8014 | // loads. |
| 8015 | SDValue TFOp; |
| 8016 | if (LoadWidenVectorOp(Result, TFOp, Op, WidenVT)) |
| 8017 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(TFOp.getValue(1))); |
| 8018 | else |
| 8019 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(TFOp.getValue(0))); |
| 8020 | break; |
| 8021 | } |
| 8022 | |
| 8023 | case ISD::BIT_CONVERT: { |
| 8024 | SDValue Tmp1 = Node->getOperand(0); |
| 8025 | // Converts between two different types so we need to determine |
| 8026 | // the correct widen type for the input operand. |
Mon P Wang | 87c8a8f | 2008-12-18 20:03:17 +0000 | [diff] [blame] | 8027 | MVT InVT = Tmp1.getValueType(); |
| 8028 | unsigned WidenSize = WidenVT.getSizeInBits(); |
| 8029 | if (InVT.isVector()) { |
| 8030 | MVT InEltVT = InVT.getVectorElementType(); |
| 8031 | unsigned InEltSize = InEltVT.getSizeInBits(); |
| 8032 | assert(WidenSize % InEltSize == 0 && |
| 8033 | "can not widen bit convert that are not multiple of element type"); |
| 8034 | MVT NewInWidenVT = MVT::getVectorVT(InEltVT, WidenSize / InEltSize); |
| 8035 | Tmp1 = WidenVectorOp(Tmp1, NewInWidenVT); |
| 8036 | assert(Tmp1.getValueType().getSizeInBits() == WidenVT.getSizeInBits()); |
| 8037 | Result = DAG.getNode(ISD::BIT_CONVERT, WidenVT, Tmp1); |
| 8038 | } else { |
| 8039 | // If the result size is a multiple of the input size, widen the input |
| 8040 | // and then convert. |
| 8041 | unsigned InSize = InVT.getSizeInBits(); |
| 8042 | assert(WidenSize % InSize == 0 && |
| 8043 | "can not widen bit convert that are not multiple of element type"); |
| 8044 | unsigned NewNumElts = WidenSize / InSize; |
| 8045 | SmallVector<SDValue, 16> Ops(NewNumElts); |
| 8046 | SDValue UndefVal = DAG.getNode(ISD::UNDEF, InVT); |
| 8047 | Ops[0] = Tmp1; |
| 8048 | for (unsigned i = 1; i < NewNumElts; ++i) |
| 8049 | Ops[i] = UndefVal; |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8050 | |
Mon P Wang | 87c8a8f | 2008-12-18 20:03:17 +0000 | [diff] [blame] | 8051 | MVT NewInVT = MVT::getVectorVT(InVT, NewNumElts); |
| 8052 | Result = DAG.getNode(ISD::BUILD_VECTOR, NewInVT, &Ops[0], NewNumElts); |
| 8053 | Result = DAG.getNode(ISD::BIT_CONVERT, WidenVT, Result); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8054 | } |
| 8055 | break; |
| 8056 | } |
| 8057 | |
| 8058 | case ISD::SINT_TO_FP: |
| 8059 | case ISD::UINT_TO_FP: |
| 8060 | case ISD::FP_TO_SINT: |
Mon P Wang | 87c8a8f | 2008-12-18 20:03:17 +0000 | [diff] [blame] | 8061 | case ISD::FP_TO_UINT: |
| 8062 | case ISD::FP_ROUND: { |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8063 | SDValue Tmp1 = Node->getOperand(0); |
| 8064 | // Converts between two different types so we need to determine |
| 8065 | // the correct widen type for the input operand. |
| 8066 | MVT TVT = Tmp1.getValueType(); |
| 8067 | assert(TVT.isVector() && "can not widen non vector type"); |
| 8068 | MVT TEVT = TVT.getVectorElementType(); |
| 8069 | MVT TWidenVT = MVT::getVectorVT(TEVT, NewNumElts); |
| 8070 | Tmp1 = WidenVectorOp(Tmp1, TWidenVT); |
| 8071 | assert(Tmp1.getValueType().getVectorNumElements() == NewNumElts); |
| 8072 | Result = DAG.getNode(Node->getOpcode(), WidenVT, Tmp1); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8073 | break; |
| 8074 | } |
| 8075 | |
| 8076 | case ISD::FP_EXTEND: |
| 8077 | assert(0 && "Case not implemented. Dynamically dead with 2 FP types!"); |
| 8078 | case ISD::TRUNCATE: |
| 8079 | case ISD::SIGN_EXTEND: |
| 8080 | case ISD::ZERO_EXTEND: |
| 8081 | case ISD::ANY_EXTEND: |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8082 | case ISD::SIGN_EXTEND_INREG: |
| 8083 | case ISD::FABS: |
| 8084 | case ISD::FNEG: |
| 8085 | case ISD::FSQRT: |
| 8086 | case ISD::FSIN: |
Mon P Wang | 49292f1 | 2008-11-15 06:05:52 +0000 | [diff] [blame] | 8087 | case ISD::FCOS: |
| 8088 | case ISD::CTPOP: |
| 8089 | case ISD::CTTZ: |
| 8090 | case ISD::CTLZ: { |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8091 | // Unary op widening |
Mon P Wang | 87c8a8f | 2008-12-18 20:03:17 +0000 | [diff] [blame] | 8092 | SDValue Tmp1; |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8093 | Tmp1 = WidenVectorOp(Node->getOperand(0), WidenVT); |
| 8094 | assert(Tmp1.getValueType() == WidenVT); |
| 8095 | Result = DAG.getNode(Node->getOpcode(), WidenVT, Tmp1); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8096 | break; |
| 8097 | } |
Mon P Wang | 77cdf30 | 2008-11-10 20:54:11 +0000 | [diff] [blame] | 8098 | case ISD::CONVERT_RNDSAT: { |
| 8099 | SDValue RndOp = Node->getOperand(3); |
| 8100 | SDValue SatOp = Node->getOperand(4); |
Mon P Wang | 77cdf30 | 2008-11-10 20:54:11 +0000 | [diff] [blame] | 8101 | SDValue SrcOp = Node->getOperand(0); |
| 8102 | |
| 8103 | // Converts between two different types so we need to determine |
| 8104 | // the correct widen type for the input operand. |
| 8105 | MVT SVT = SrcOp.getValueType(); |
| 8106 | assert(SVT.isVector() && "can not widen non vector type"); |
| 8107 | MVT SEVT = SVT.getVectorElementType(); |
| 8108 | MVT SWidenVT = MVT::getVectorVT(SEVT, NewNumElts); |
| 8109 | |
| 8110 | SrcOp = WidenVectorOp(SrcOp, SWidenVT); |
| 8111 | assert(SrcOp.getValueType() == WidenVT); |
| 8112 | SDValue DTyOp = DAG.getValueType(WidenVT); |
| 8113 | SDValue STyOp = DAG.getValueType(SrcOp.getValueType()); |
| 8114 | ISD::CvtCode CvtCode = cast<CvtRndSatSDNode>(Node)->getCvtCode(); |
| 8115 | |
| 8116 | Result = DAG.getConvertRndSat(WidenVT, SrcOp, DTyOp, STyOp, |
| 8117 | RndOp, SatOp, CvtCode); |
Mon P Wang | 77cdf30 | 2008-11-10 20:54:11 +0000 | [diff] [blame] | 8118 | break; |
| 8119 | } |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8120 | case ISD::FPOW: |
| 8121 | case ISD::FPOWI: |
| 8122 | case ISD::ADD: |
| 8123 | case ISD::SUB: |
| 8124 | case ISD::MUL: |
| 8125 | case ISD::MULHS: |
| 8126 | case ISD::MULHU: |
| 8127 | case ISD::AND: |
| 8128 | case ISD::OR: |
| 8129 | case ISD::XOR: |
| 8130 | case ISD::FADD: |
| 8131 | case ISD::FSUB: |
| 8132 | case ISD::FMUL: |
| 8133 | case ISD::SDIV: |
| 8134 | case ISD::SREM: |
| 8135 | case ISD::FDIV: |
| 8136 | case ISD::FREM: |
| 8137 | case ISD::FCOPYSIGN: |
| 8138 | case ISD::UDIV: |
| 8139 | case ISD::UREM: |
| 8140 | case ISD::BSWAP: { |
| 8141 | // Binary op widening |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8142 | SDValue Tmp1 = WidenVectorOp(Node->getOperand(0), WidenVT); |
| 8143 | SDValue Tmp2 = WidenVectorOp(Node->getOperand(1), WidenVT); |
| 8144 | assert(Tmp1.getValueType() == WidenVT && Tmp2.getValueType() == WidenVT); |
| 8145 | Result = DAG.getNode(Node->getOpcode(), WidenVT, Tmp1, Tmp2); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8146 | break; |
| 8147 | } |
| 8148 | |
| 8149 | case ISD::SHL: |
| 8150 | case ISD::SRA: |
| 8151 | case ISD::SRL: { |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8152 | SDValue Tmp1 = WidenVectorOp(Node->getOperand(0), WidenVT); |
| 8153 | assert(Tmp1.getValueType() == WidenVT); |
Mon P Wang | fb13f00 | 2008-12-02 07:35:08 +0000 | [diff] [blame] | 8154 | SDValue ShOp = Node->getOperand(1); |
| 8155 | MVT ShVT = ShOp.getValueType(); |
| 8156 | MVT NewShVT = MVT::getVectorVT(ShVT.getVectorElementType(), |
| 8157 | WidenVT.getVectorNumElements()); |
| 8158 | ShOp = WidenVectorOp(ShOp, NewShVT); |
| 8159 | assert(ShOp.getValueType() == NewShVT); |
| 8160 | Result = DAG.getNode(Node->getOpcode(), WidenVT, Tmp1, ShOp); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8161 | break; |
| 8162 | } |
Mon P Wang | fb13f00 | 2008-12-02 07:35:08 +0000 | [diff] [blame] | 8163 | |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8164 | case ISD::EXTRACT_VECTOR_ELT: { |
| 8165 | SDValue Tmp1 = WidenVectorOp(Node->getOperand(0), WidenVT); |
| 8166 | assert(Tmp1.getValueType() == WidenVT); |
| 8167 | Result = DAG.getNode(Node->getOpcode(), EVT, Tmp1, Node->getOperand(1)); |
| 8168 | break; |
| 8169 | } |
| 8170 | case ISD::CONCAT_VECTORS: { |
| 8171 | // We concurrently support only widen on a multiple of the incoming vector. |
| 8172 | // We could widen on a multiple of the incoming operand if necessary. |
| 8173 | unsigned NumConcat = NewNumElts / NumElts; |
| 8174 | assert(NewNumElts % NumElts == 0 && "Can widen only a multiple of vector"); |
Mon P Wang | fb13f00 | 2008-12-02 07:35:08 +0000 | [diff] [blame] | 8175 | SDValue UndefVal = DAG.getNode(ISD::UNDEF, VT); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8176 | SmallVector<SDValue, 8> MOps; |
| 8177 | MOps.push_back(Op); |
| 8178 | for (unsigned i = 1; i != NumConcat; ++i) { |
| 8179 | MOps.push_back(UndefVal); |
| 8180 | } |
| 8181 | Result = LegalizeOp(DAG.getNode(ISD::CONCAT_VECTORS, WidenVT, |
| 8182 | &MOps[0], MOps.size())); |
| 8183 | break; |
| 8184 | } |
| 8185 | case ISD::EXTRACT_SUBVECTOR: { |
Mon P Wang | 49292f1 | 2008-11-15 06:05:52 +0000 | [diff] [blame] | 8186 | SDValue Tmp1 = Node->getOperand(0); |
| 8187 | SDValue Idx = Node->getOperand(1); |
| 8188 | ConstantSDNode *CIdx = dyn_cast<ConstantSDNode>(Idx); |
| 8189 | if (CIdx && CIdx->getZExtValue() == 0) { |
| 8190 | // Since we are access the start of the vector, the incoming |
| 8191 | // vector type might be the proper. |
| 8192 | MVT Tmp1VT = Tmp1.getValueType(); |
| 8193 | if (Tmp1VT == WidenVT) |
| 8194 | return Tmp1; |
| 8195 | else { |
| 8196 | unsigned Tmp1VTNumElts = Tmp1VT.getVectorNumElements(); |
| 8197 | if (Tmp1VTNumElts < NewNumElts) |
| 8198 | Result = WidenVectorOp(Tmp1, WidenVT); |
| 8199 | else |
| 8200 | Result = DAG.getNode(ISD::EXTRACT_SUBVECTOR, WidenVT, Tmp1, Idx); |
| 8201 | } |
| 8202 | } else if (NewNumElts % NumElts == 0) { |
| 8203 | // Widen the extracted subvector. |
| 8204 | unsigned NumConcat = NewNumElts / NumElts; |
| 8205 | SDValue UndefVal = DAG.getNode(ISD::UNDEF, VT); |
| 8206 | SmallVector<SDValue, 8> MOps; |
| 8207 | MOps.push_back(Op); |
| 8208 | for (unsigned i = 1; i != NumConcat; ++i) { |
| 8209 | MOps.push_back(UndefVal); |
| 8210 | } |
| 8211 | Result = LegalizeOp(DAG.getNode(ISD::CONCAT_VECTORS, WidenVT, |
| 8212 | &MOps[0], MOps.size())); |
| 8213 | } else { |
| 8214 | assert(0 && "can not widen extract subvector"); |
| 8215 | // This could be implemented using insert and build vector but I would |
| 8216 | // like to see when this happens. |
| 8217 | } |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8218 | break; |
| 8219 | } |
| 8220 | |
| 8221 | case ISD::SELECT: { |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8222 | // Determine new condition widen type and widen |
| 8223 | SDValue Cond1 = Node->getOperand(0); |
| 8224 | MVT CondVT = Cond1.getValueType(); |
| 8225 | assert(CondVT.isVector() && "can not widen non vector type"); |
| 8226 | MVT CondEVT = CondVT.getVectorElementType(); |
| 8227 | MVT CondWidenVT = MVT::getVectorVT(CondEVT, NewNumElts); |
| 8228 | Cond1 = WidenVectorOp(Cond1, CondWidenVT); |
| 8229 | assert(Cond1.getValueType() == CondWidenVT && "Condition not widen"); |
| 8230 | |
| 8231 | SDValue Tmp1 = WidenVectorOp(Node->getOperand(1), WidenVT); |
| 8232 | SDValue Tmp2 = WidenVectorOp(Node->getOperand(2), WidenVT); |
| 8233 | assert(Tmp1.getValueType() == WidenVT && Tmp2.getValueType() == WidenVT); |
| 8234 | Result = DAG.getNode(Node->getOpcode(), WidenVT, Cond1, Tmp1, Tmp2); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8235 | break; |
| 8236 | } |
| 8237 | |
| 8238 | case ISD::SELECT_CC: { |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8239 | // Determine new condition widen type and widen |
| 8240 | SDValue Cond1 = Node->getOperand(0); |
| 8241 | SDValue Cond2 = Node->getOperand(1); |
| 8242 | MVT CondVT = Cond1.getValueType(); |
| 8243 | assert(CondVT.isVector() && "can not widen non vector type"); |
| 8244 | assert(CondVT == Cond2.getValueType() && "mismatch lhs/rhs"); |
| 8245 | MVT CondEVT = CondVT.getVectorElementType(); |
| 8246 | MVT CondWidenVT = MVT::getVectorVT(CondEVT, NewNumElts); |
| 8247 | Cond1 = WidenVectorOp(Cond1, CondWidenVT); |
| 8248 | Cond2 = WidenVectorOp(Cond2, CondWidenVT); |
| 8249 | assert(Cond1.getValueType() == CondWidenVT && |
| 8250 | Cond2.getValueType() == CondWidenVT && "condition not widen"); |
| 8251 | |
| 8252 | SDValue Tmp1 = WidenVectorOp(Node->getOperand(2), WidenVT); |
| 8253 | SDValue Tmp2 = WidenVectorOp(Node->getOperand(3), WidenVT); |
| 8254 | assert(Tmp1.getValueType() == WidenVT && Tmp2.getValueType() == WidenVT && |
| 8255 | "operands not widen"); |
| 8256 | Result = DAG.getNode(Node->getOpcode(), WidenVT, Cond1, Cond2, Tmp1, |
| 8257 | Tmp2, Node->getOperand(4)); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8258 | break; |
Mon P Wang | 2eb13c3 | 2008-10-30 18:21:52 +0000 | [diff] [blame] | 8259 | } |
| 8260 | case ISD::VSETCC: { |
| 8261 | // Determine widen for the operand |
| 8262 | SDValue Tmp1 = Node->getOperand(0); |
| 8263 | MVT TmpVT = Tmp1.getValueType(); |
| 8264 | assert(TmpVT.isVector() && "can not widen non vector type"); |
| 8265 | MVT TmpEVT = TmpVT.getVectorElementType(); |
| 8266 | MVT TmpWidenVT = MVT::getVectorVT(TmpEVT, NewNumElts); |
| 8267 | Tmp1 = WidenVectorOp(Tmp1, TmpWidenVT); |
| 8268 | SDValue Tmp2 = WidenVectorOp(Node->getOperand(1), TmpWidenVT); |
Mon P Wang | 87c8a8f | 2008-12-18 20:03:17 +0000 | [diff] [blame] | 8269 | Result = DAG.getNode(Node->getOpcode(), WidenVT, Tmp1, Tmp2, |
Mon P Wang | 2eb13c3 | 2008-10-30 18:21:52 +0000 | [diff] [blame] | 8270 | Node->getOperand(2)); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8271 | break; |
| 8272 | } |
Dan Gohman | 0b1d4a7 | 2008-12-23 21:37:04 +0000 | [diff] [blame] | 8273 | case ISD::ATOMIC_CMP_SWAP: |
| 8274 | case ISD::ATOMIC_LOAD_ADD: |
| 8275 | case ISD::ATOMIC_LOAD_SUB: |
| 8276 | case ISD::ATOMIC_LOAD_AND: |
| 8277 | case ISD::ATOMIC_LOAD_OR: |
| 8278 | case ISD::ATOMIC_LOAD_XOR: |
| 8279 | case ISD::ATOMIC_LOAD_NAND: |
| 8280 | case ISD::ATOMIC_LOAD_MIN: |
| 8281 | case ISD::ATOMIC_LOAD_MAX: |
| 8282 | case ISD::ATOMIC_LOAD_UMIN: |
| 8283 | case ISD::ATOMIC_LOAD_UMAX: |
| 8284 | case ISD::ATOMIC_SWAP: { |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8285 | // For now, we assume that using vectors for these operations don't make |
| 8286 | // much sense so we just split it. We return an empty result |
| 8287 | SDValue X, Y; |
| 8288 | SplitVectorOp(Op, X, Y); |
| 8289 | return Result; |
| 8290 | break; |
| 8291 | } |
| 8292 | |
| 8293 | } // end switch (Node->getOpcode()) |
| 8294 | |
| 8295 | assert(Result.getNode() && "Didn't set a result!"); |
| 8296 | if (Result != Op) |
| 8297 | Result = LegalizeOp(Result); |
| 8298 | |
Mon P Wang | f007a8b | 2008-11-06 05:31:54 +0000 | [diff] [blame] | 8299 | AddWidenedOperand(Op, Result); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8300 | return Result; |
| 8301 | } |
| 8302 | |
| 8303 | // Utility function to find a legal vector type and its associated element |
| 8304 | // type from a preferred width and whose vector type must be the same size |
| 8305 | // as the VVT. |
| 8306 | // TLI: Target lowering used to determine legal types |
| 8307 | // Width: Preferred width of element type |
| 8308 | // VVT: Vector value type whose size we must match. |
| 8309 | // Returns VecEVT and EVT - the vector type and its associated element type |
Dan Gohman | 0d137d7 | 2009-01-15 16:43:02 +0000 | [diff] [blame] | 8310 | static void FindWidenVecType(const TargetLowering &TLI, unsigned Width, MVT VVT, |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8311 | MVT& EVT, MVT& VecEVT) { |
| 8312 | // We start with the preferred width, make it a power of 2 and see if |
| 8313 | // we can find a vector type of that width. If not, we reduce it by |
| 8314 | // another power of 2. If we have widen the type, a vector of bytes should |
| 8315 | // always be legal. |
| 8316 | assert(TLI.isTypeLegal(VVT)); |
| 8317 | unsigned EWidth = Width + 1; |
| 8318 | do { |
| 8319 | assert(EWidth > 0); |
| 8320 | EWidth = (1 << Log2_32(EWidth-1)); |
| 8321 | EVT = MVT::getIntegerVT(EWidth); |
| 8322 | unsigned NumEVT = VVT.getSizeInBits()/EWidth; |
| 8323 | VecEVT = MVT::getVectorVT(EVT, NumEVT); |
| 8324 | } while (!TLI.isTypeLegal(VecEVT) || |
| 8325 | VVT.getSizeInBits() != VecEVT.getSizeInBits()); |
| 8326 | } |
| 8327 | |
| 8328 | SDValue SelectionDAGLegalize::genWidenVectorLoads(SDValueVector& LdChain, |
| 8329 | SDValue Chain, |
| 8330 | SDValue BasePtr, |
| 8331 | const Value *SV, |
| 8332 | int SVOffset, |
| 8333 | unsigned Alignment, |
| 8334 | bool isVolatile, |
| 8335 | unsigned LdWidth, |
| 8336 | MVT ResType) { |
| 8337 | // We assume that we have good rules to handle loading power of two loads so |
| 8338 | // we break down the operations to power of 2 loads. The strategy is to |
| 8339 | // load the largest power of 2 that we can easily transform to a legal vector |
| 8340 | // and then insert into that vector, and the cast the result into the legal |
| 8341 | // vector that we want. This avoids unnecessary stack converts. |
| 8342 | // TODO: If the Ldwidth is legal, alignment is the same as the LdWidth, and |
| 8343 | // the load is nonvolatile, we an use a wider load for the value. |
| 8344 | // Find a vector length we can load a large chunk |
| 8345 | MVT EVT, VecEVT; |
| 8346 | unsigned EVTWidth; |
| 8347 | FindWidenVecType(TLI, LdWidth, ResType, EVT, VecEVT); |
| 8348 | EVTWidth = EVT.getSizeInBits(); |
| 8349 | |
| 8350 | SDValue LdOp = DAG.getLoad(EVT, Chain, BasePtr, SV, SVOffset, |
| 8351 | isVolatile, Alignment); |
| 8352 | SDValue VecOp = DAG.getNode(ISD::SCALAR_TO_VECTOR, VecEVT, LdOp); |
| 8353 | LdChain.push_back(LdOp.getValue(1)); |
| 8354 | |
| 8355 | // Check if we can load the element with one instruction |
| 8356 | if (LdWidth == EVTWidth) { |
| 8357 | return DAG.getNode(ISD::BIT_CONVERT, ResType, VecOp); |
| 8358 | } |
| 8359 | |
| 8360 | // The vector element order is endianness dependent. |
| 8361 | unsigned Idx = 1; |
| 8362 | LdWidth -= EVTWidth; |
| 8363 | unsigned Offset = 0; |
| 8364 | |
| 8365 | while (LdWidth > 0) { |
| 8366 | unsigned Increment = EVTWidth / 8; |
| 8367 | Offset += Increment; |
| 8368 | BasePtr = DAG.getNode(ISD::ADD, BasePtr.getValueType(), BasePtr, |
| 8369 | DAG.getIntPtrConstant(Increment)); |
| 8370 | |
| 8371 | if (LdWidth < EVTWidth) { |
| 8372 | // Our current type we are using is too large, use a smaller size by |
| 8373 | // using a smaller power of 2 |
| 8374 | unsigned oEVTWidth = EVTWidth; |
| 8375 | FindWidenVecType(TLI, LdWidth, ResType, EVT, VecEVT); |
| 8376 | EVTWidth = EVT.getSizeInBits(); |
| 8377 | // Readjust position and vector position based on new load type |
Mon P Wang | 49292f1 | 2008-11-15 06:05:52 +0000 | [diff] [blame] | 8378 | Idx = Idx * (oEVTWidth/EVTWidth); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8379 | VecOp = DAG.getNode(ISD::BIT_CONVERT, VecEVT, VecOp); |
| 8380 | } |
| 8381 | |
| 8382 | SDValue LdOp = DAG.getLoad(EVT, Chain, BasePtr, SV, |
| 8383 | SVOffset+Offset, isVolatile, |
| 8384 | MinAlign(Alignment, Offset)); |
| 8385 | LdChain.push_back(LdOp.getValue(1)); |
| 8386 | VecOp = DAG.getNode(ISD::INSERT_VECTOR_ELT, VecEVT, VecOp, LdOp, |
| 8387 | DAG.getIntPtrConstant(Idx++)); |
| 8388 | |
| 8389 | LdWidth -= EVTWidth; |
| 8390 | } |
| 8391 | |
| 8392 | return DAG.getNode(ISD::BIT_CONVERT, ResType, VecOp); |
| 8393 | } |
| 8394 | |
| 8395 | bool SelectionDAGLegalize::LoadWidenVectorOp(SDValue& Result, |
| 8396 | SDValue& TFOp, |
| 8397 | SDValue Op, |
| 8398 | MVT NVT) { |
| 8399 | // TODO: Add support for ConcatVec and the ability to load many vector |
| 8400 | // types (e.g., v4i8). This will not work when a vector register |
| 8401 | // to memory mapping is strange (e.g., vector elements are not |
| 8402 | // stored in some sequential order). |
| 8403 | |
| 8404 | // It must be true that the widen vector type is bigger than where |
| 8405 | // we need to load from. |
| 8406 | LoadSDNode *LD = cast<LoadSDNode>(Op.getNode()); |
| 8407 | MVT LdVT = LD->getMemoryVT(); |
| 8408 | assert(LdVT.isVector() && NVT.isVector()); |
| 8409 | assert(LdVT.getVectorElementType() == NVT.getVectorElementType()); |
| 8410 | |
| 8411 | // Load information |
| 8412 | SDValue Chain = LD->getChain(); |
| 8413 | SDValue BasePtr = LD->getBasePtr(); |
| 8414 | int SVOffset = LD->getSrcValueOffset(); |
| 8415 | unsigned Alignment = LD->getAlignment(); |
| 8416 | bool isVolatile = LD->isVolatile(); |
| 8417 | const Value *SV = LD->getSrcValue(); |
| 8418 | unsigned int LdWidth = LdVT.getSizeInBits(); |
| 8419 | |
| 8420 | // Load value as a large register |
| 8421 | SDValueVector LdChain; |
| 8422 | Result = genWidenVectorLoads(LdChain, Chain, BasePtr, SV, SVOffset, |
| 8423 | Alignment, isVolatile, LdWidth, NVT); |
| 8424 | |
| 8425 | if (LdChain.size() == 1) { |
| 8426 | TFOp = LdChain[0]; |
| 8427 | return true; |
| 8428 | } |
| 8429 | else { |
| 8430 | TFOp=DAG.getNode(ISD::TokenFactor, MVT::Other, &LdChain[0], LdChain.size()); |
| 8431 | return false; |
| 8432 | } |
| 8433 | } |
| 8434 | |
| 8435 | |
| 8436 | void SelectionDAGLegalize::genWidenVectorStores(SDValueVector& StChain, |
| 8437 | SDValue Chain, |
| 8438 | SDValue BasePtr, |
| 8439 | const Value *SV, |
| 8440 | int SVOffset, |
| 8441 | unsigned Alignment, |
| 8442 | bool isVolatile, |
Mon P Wang | 49292f1 | 2008-11-15 06:05:52 +0000 | [diff] [blame] | 8443 | SDValue ValOp, |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8444 | unsigned StWidth) { |
| 8445 | // Breaks the stores into a series of power of 2 width stores. For any |
| 8446 | // width, we convert the vector to the vector of element size that we |
| 8447 | // want to store. This avoids requiring a stack convert. |
| 8448 | |
| 8449 | // Find a width of the element type we can store with |
| 8450 | MVT VVT = ValOp.getValueType(); |
| 8451 | MVT EVT, VecEVT; |
| 8452 | unsigned EVTWidth; |
| 8453 | FindWidenVecType(TLI, StWidth, VVT, EVT, VecEVT); |
| 8454 | EVTWidth = EVT.getSizeInBits(); |
| 8455 | |
| 8456 | SDValue VecOp = DAG.getNode(ISD::BIT_CONVERT, VecEVT, ValOp); |
| 8457 | SDValue EOp = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, EVT, VecOp, |
Mon P Wang | e0b436a | 2008-11-06 22:52:21 +0000 | [diff] [blame] | 8458 | DAG.getIntPtrConstant(0)); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8459 | SDValue StOp = DAG.getStore(Chain, EOp, BasePtr, SV, SVOffset, |
| 8460 | isVolatile, Alignment); |
| 8461 | StChain.push_back(StOp); |
| 8462 | |
| 8463 | // Check if we are done |
| 8464 | if (StWidth == EVTWidth) { |
| 8465 | return; |
| 8466 | } |
| 8467 | |
| 8468 | unsigned Idx = 1; |
| 8469 | StWidth -= EVTWidth; |
| 8470 | unsigned Offset = 0; |
| 8471 | |
| 8472 | while (StWidth > 0) { |
| 8473 | unsigned Increment = EVTWidth / 8; |
| 8474 | Offset += Increment; |
| 8475 | BasePtr = DAG.getNode(ISD::ADD, BasePtr.getValueType(), BasePtr, |
| 8476 | DAG.getIntPtrConstant(Increment)); |
| 8477 | |
| 8478 | if (StWidth < EVTWidth) { |
| 8479 | // Our current type we are using is too large, use a smaller size by |
| 8480 | // using a smaller power of 2 |
| 8481 | unsigned oEVTWidth = EVTWidth; |
| 8482 | FindWidenVecType(TLI, StWidth, VVT, EVT, VecEVT); |
| 8483 | EVTWidth = EVT.getSizeInBits(); |
| 8484 | // Readjust position and vector position based on new load type |
Mon P Wang | 49292f1 | 2008-11-15 06:05:52 +0000 | [diff] [blame] | 8485 | Idx = Idx * (oEVTWidth/EVTWidth); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8486 | VecOp = DAG.getNode(ISD::BIT_CONVERT, VecEVT, VecOp); |
| 8487 | } |
| 8488 | |
| 8489 | EOp = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, EVT, VecOp, |
Mon P Wang | 49292f1 | 2008-11-15 06:05:52 +0000 | [diff] [blame] | 8490 | DAG.getIntPtrConstant(Idx++)); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8491 | StChain.push_back(DAG.getStore(Chain, EOp, BasePtr, SV, |
| 8492 | SVOffset + Offset, isVolatile, |
| 8493 | MinAlign(Alignment, Offset))); |
| 8494 | StWidth -= EVTWidth; |
| 8495 | } |
| 8496 | } |
| 8497 | |
| 8498 | |
| 8499 | SDValue SelectionDAGLegalize::StoreWidenVectorOp(StoreSDNode *ST, |
| 8500 | SDValue Chain, |
| 8501 | SDValue BasePtr) { |
| 8502 | // TODO: It might be cleaner if we can use SplitVector and have more legal |
| 8503 | // vector types that can be stored into memory (e.g., v4xi8 can |
| 8504 | // be stored as a word). This will not work when a vector register |
| 8505 | // to memory mapping is strange (e.g., vector elements are not |
| 8506 | // stored in some sequential order). |
| 8507 | |
| 8508 | MVT StVT = ST->getMemoryVT(); |
| 8509 | SDValue ValOp = ST->getValue(); |
| 8510 | |
| 8511 | // Check if we have widen this node with another value |
| 8512 | std::map<SDValue, SDValue>::iterator I = WidenNodes.find(ValOp); |
| 8513 | if (I != WidenNodes.end()) |
| 8514 | ValOp = I->second; |
| 8515 | |
| 8516 | MVT VVT = ValOp.getValueType(); |
| 8517 | |
| 8518 | // It must be true that we the widen vector type is bigger than where |
| 8519 | // we need to store. |
| 8520 | assert(StVT.isVector() && VVT.isVector()); |
Dan Gohman | f83c81a | 2009-01-28 03:10:52 +0000 | [diff] [blame] | 8521 | assert(StVT.bitsLT(VVT)); |
Mon P Wang | 0c39719 | 2008-10-30 08:01:45 +0000 | [diff] [blame] | 8522 | assert(StVT.getVectorElementType() == VVT.getVectorElementType()); |
| 8523 | |
| 8524 | // Store value |
| 8525 | SDValueVector StChain; |
| 8526 | genWidenVectorStores(StChain, Chain, BasePtr, ST->getSrcValue(), |
| 8527 | ST->getSrcValueOffset(), ST->getAlignment(), |
| 8528 | ST->isVolatile(), ValOp, StVT.getSizeInBits()); |
| 8529 | if (StChain.size() == 1) |
| 8530 | return StChain[0]; |
| 8531 | else |
| 8532 | return DAG.getNode(ISD::TokenFactor, MVT::Other,&StChain[0],StChain.size()); |
| 8533 | } |
| 8534 | |
| 8535 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 8536 | // SelectionDAG::Legalize - This is the entry point for the file. |
| 8537 | // |
Duncan Sands | b6862bb | 2008-12-14 09:43:15 +0000 | [diff] [blame] | 8538 | void SelectionDAG::Legalize(bool TypesNeedLegalizing) { |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 8539 | /// run - This is the main entry point to this class. |
| 8540 | /// |
Duncan Sands | b6862bb | 2008-12-14 09:43:15 +0000 | [diff] [blame] | 8541 | SelectionDAGLegalize(*this, TypesNeedLegalizing).LegalizeDAG(); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 8542 | } |
| 8543 | |