Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1 | //===-- LegalizeDAG.cpp - Implement SelectionDAG::Legalize ----------------===// |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2 | // |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 7 | // |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the SelectionDAG::Legalize method. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "llvm/CodeGen/SelectionDAG.h" |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 15 | #include "llvm/CodeGen/MachineFunction.h" |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 16 | #include "llvm/CodeGen/MachineFrameInfo.h" |
Jim Laskey | acd80ac | 2006-12-14 19:17:33 +0000 | [diff] [blame] | 17 | #include "llvm/CodeGen/MachineJumpTableInfo.h" |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/MachineModuleInfo.h" |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/PseudoSourceValue.h" |
Evan Cheng | 61bbbab | 2007-08-16 23:50:06 +0000 | [diff] [blame] | 20 | #include "llvm/Target/TargetFrameInfo.h" |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 21 | #include "llvm/Target/TargetLowering.h" |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 22 | #include "llvm/Target/TargetData.h" |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 23 | #include "llvm/Target/TargetMachine.h" |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 24 | #include "llvm/Target/TargetOptions.h" |
Chris Lattner | adf6a96 | 2005-05-13 18:50:42 +0000 | [diff] [blame] | 25 | #include "llvm/CallingConv.h" |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 26 | #include "llvm/Constants.h" |
Reid Spencer | c103057 | 2007-01-19 21:13:56 +0000 | [diff] [blame] | 27 | #include "llvm/DerivedTypes.h" |
Chris Lattner | 5e46a19 | 2006-04-02 03:07:27 +0000 | [diff] [blame] | 28 | #include "llvm/Support/CommandLine.h" |
Chris Lattner | a4f0b3a | 2006-08-27 12:54:02 +0000 | [diff] [blame] | 29 | #include "llvm/Support/Compiler.h" |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 30 | #include "llvm/Support/MathExtras.h" |
Chris Lattner | 7971514 | 2007-02-03 01:12:36 +0000 | [diff] [blame] | 31 | #include "llvm/ADT/DenseMap.h" |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 32 | #include "llvm/ADT/SmallVector.h" |
Chris Lattner | 00755df | 2007-02-04 00:27:56 +0000 | [diff] [blame] | 33 | #include "llvm/ADT/SmallPtrSet.h" |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 34 | #include <map> |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 35 | using namespace llvm; |
| 36 | |
Chris Lattner | 5e46a19 | 2006-04-02 03:07:27 +0000 | [diff] [blame] | 37 | #ifndef NDEBUG |
| 38 | static cl::opt<bool> |
| 39 | ViewLegalizeDAGs("view-legalize-dags", cl::Hidden, |
| 40 | cl::desc("Pop up a window to show dags before legalize")); |
| 41 | #else |
| 42 | static const bool ViewLegalizeDAGs = 0; |
| 43 | #endif |
| 44 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 45 | //===----------------------------------------------------------------------===// |
| 46 | /// SelectionDAGLegalize - This takes an arbitrary SelectionDAG as input and |
| 47 | /// hacks on it until the target machine can handle it. This involves |
| 48 | /// eliminating value sizes the machine cannot handle (promoting small sizes to |
| 49 | /// large sizes or splitting up large values into small values) as well as |
| 50 | /// eliminating operations the machine cannot handle. |
| 51 | /// |
| 52 | /// This code also does a small amount of optimization and recognition of idioms |
| 53 | /// as part of its processing. For example, if a target does not support a |
| 54 | /// 'setcc' instruction efficiently, but does support 'brcc' instruction, this |
| 55 | /// will attempt merge setcc and brc instructions into brcc's. |
| 56 | /// |
| 57 | namespace { |
Chris Lattner | 360e820 | 2006-06-28 21:58:30 +0000 | [diff] [blame] | 58 | class VISIBILITY_HIDDEN SelectionDAGLegalize { |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 59 | TargetLowering &TLI; |
| 60 | SelectionDAG &DAG; |
| 61 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 62 | // Libcall insertion helpers. |
| 63 | |
| 64 | /// LastCALLSEQ_END - This keeps track of the CALLSEQ_END node that has been |
| 65 | /// legalized. We use this to ensure that calls are properly serialized |
| 66 | /// against each other, including inserted libcalls. |
| 67 | SDOperand LastCALLSEQ_END; |
| 68 | |
| 69 | /// IsLegalizingCall - This member is used *only* for purposes of providing |
| 70 | /// helpful assertions that a libcall isn't created while another call is |
| 71 | /// being legalized (which could lead to non-serialized call sequences). |
| 72 | bool IsLegalizingCall; |
| 73 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 74 | enum LegalizeAction { |
Chris Lattner | 68a17fe | 2006-01-29 08:42:06 +0000 | [diff] [blame] | 75 | Legal, // The target natively supports this operation. |
| 76 | Promote, // This operation should be executed in a larger type. |
Chris Lattner | d74ea2b | 2006-05-24 17:04:05 +0000 | [diff] [blame] | 77 | Expand // Try to expand this to other ops, otherwise use a libcall. |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 78 | }; |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 79 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 80 | /// ValueTypeActions - This is a bitvector that contains two bits for each |
| 81 | /// value type, where the two bits correspond to the LegalizeAction enum. |
| 82 | /// This can be queried with "getTypeAction(VT)". |
Chris Lattner | 68a17fe | 2006-01-29 08:42:06 +0000 | [diff] [blame] | 83 | TargetLowering::ValueTypeActionImpl ValueTypeActions; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 84 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 85 | /// LegalizedNodes - For nodes that are of legal width, and that have more |
| 86 | /// than one use, this map indicates what regularized operand to use. This |
| 87 | /// allows us to avoid legalizing the same thing more than once. |
Roman Levenstein | dc1adac | 2008-04-07 10:06:32 +0000 | [diff] [blame] | 88 | DenseMap<SDOperandImpl, SDOperand> LegalizedNodes; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 89 | |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 90 | /// PromotedNodes - For nodes that are below legal width, and that have more |
| 91 | /// than one use, this map indicates what promoted value to use. This allows |
| 92 | /// us to avoid promoting the same thing more than once. |
Roman Levenstein | dc1adac | 2008-04-07 10:06:32 +0000 | [diff] [blame] | 93 | DenseMap<SDOperandImpl, SDOperand> PromotedNodes; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 94 | |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 95 | /// ExpandedNodes - For nodes that need to be expanded this map indicates |
| 96 | /// which which operands are the expanded version of the input. This allows |
| 97 | /// us to avoid expanding the same node more than once. |
Roman Levenstein | dc1adac | 2008-04-07 10:06:32 +0000 | [diff] [blame] | 98 | DenseMap<SDOperandImpl, std::pair<SDOperand, SDOperand> > ExpandedNodes; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 99 | |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 100 | /// SplitNodes - For vector nodes that need to be split, this map indicates |
| 101 | /// which which operands are the split version of the input. This allows us |
| 102 | /// to avoid splitting the same node more than once. |
| 103 | std::map<SDOperand, std::pair<SDOperand, SDOperand> > SplitNodes; |
| 104 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 105 | /// ScalarizedNodes - For nodes that need to be converted from vector types to |
| 106 | /// scalar types, this contains the mapping of ones we have already |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 107 | /// processed to the result. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 108 | std::map<SDOperand, SDOperand> ScalarizedNodes; |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 109 | |
Chris Lattner | 8afc48e | 2005-01-07 22:28:47 +0000 | [diff] [blame] | 110 | void AddLegalizedOperand(SDOperand From, SDOperand To) { |
Chris Lattner | 69a889e | 2005-12-20 00:53:54 +0000 | [diff] [blame] | 111 | LegalizedNodes.insert(std::make_pair(From, To)); |
| 112 | // If someone requests legalization of the new node, return itself. |
| 113 | if (From != To) |
| 114 | LegalizedNodes.insert(std::make_pair(To, To)); |
Chris Lattner | 8afc48e | 2005-01-07 22:28:47 +0000 | [diff] [blame] | 115 | } |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 116 | void AddPromotedOperand(SDOperand From, SDOperand To) { |
Chris Lattner | 40030bf | 2007-02-04 01:17:38 +0000 | [diff] [blame] | 117 | bool isNew = PromotedNodes.insert(std::make_pair(From, To)); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 118 | assert(isNew && "Got into the map somehow?"); |
Chris Lattner | 69a889e | 2005-12-20 00:53:54 +0000 | [diff] [blame] | 119 | // If someone requests legalization of the new node, return itself. |
| 120 | LegalizedNodes.insert(std::make_pair(To, To)); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 121 | } |
Chris Lattner | 8afc48e | 2005-01-07 22:28:47 +0000 | [diff] [blame] | 122 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 123 | public: |
| 124 | |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 125 | SelectionDAGLegalize(SelectionDAG &DAG); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 126 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 127 | /// getTypeAction - Return how we should legalize values of this type, either |
| 128 | /// it is already legal or we need to expand it into multiple registers of |
| 129 | /// smaller integer type, or we need to promote it to a larger type. |
| 130 | LegalizeAction getTypeAction(MVT::ValueType VT) const { |
Chris Lattner | 68a17fe | 2006-01-29 08:42:06 +0000 | [diff] [blame] | 131 | return (LegalizeAction)ValueTypeActions.getTypeAction(VT); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | /// isTypeLegal - Return true if this type is legal on this target. |
| 135 | /// |
| 136 | bool isTypeLegal(MVT::ValueType VT) const { |
| 137 | return getTypeAction(VT) == Legal; |
| 138 | } |
| 139 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 140 | void LegalizeDAG(); |
| 141 | |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 142 | private: |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 143 | /// HandleOp - Legalize, Promote, or Expand the specified operand as |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 144 | /// appropriate for its type. |
| 145 | void HandleOp(SDOperand Op); |
| 146 | |
| 147 | /// LegalizeOp - We know that the specified value has a legal type. |
| 148 | /// Recursively ensure that the operands have legal types, then return the |
| 149 | /// result. |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 150 | SDOperand LegalizeOp(SDOperand O); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 151 | |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 152 | /// UnrollVectorOp - We know that the given vector has a legal type, however |
| 153 | /// the operation it performs is not legal and is an operation that we have |
| 154 | /// no way of lowering. "Unroll" the vector, splitting out the scalars and |
| 155 | /// operating on each element individually. |
| 156 | SDOperand UnrollVectorOp(SDOperand O); |
| 157 | |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 158 | /// PromoteOp - Given an operation that produces a value in an invalid type, |
| 159 | /// promote it to compute the value into a larger type. The produced value |
| 160 | /// will have the correct bits for the low portion of the register, but no |
| 161 | /// guarantee is made about the top bits: it may be zero, sign-extended, or |
| 162 | /// garbage. |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 163 | SDOperand PromoteOp(SDOperand O); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 164 | |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 165 | /// ExpandOp - Expand the specified SDOperand into its two component pieces |
| 166 | /// Lo&Hi. Note that the Op MUST be an expanded type. As a result of this, |
| 167 | /// the LegalizeNodes map is filled in for any results that are not expanded, |
| 168 | /// the ExpandedNodes map is filled in for any results that are expanded, and |
| 169 | /// the Lo/Hi values are returned. This applies to integer types and Vector |
| 170 | /// types. |
| 171 | void ExpandOp(SDOperand O, SDOperand &Lo, SDOperand &Hi); |
| 172 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 173 | /// SplitVectorOp - Given an operand of vector type, break it down into |
| 174 | /// two smaller values. |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 175 | void SplitVectorOp(SDOperand O, SDOperand &Lo, SDOperand &Hi); |
| 176 | |
Dan Gohman | 89b20c0 | 2007-06-27 14:06:22 +0000 | [diff] [blame] | 177 | /// ScalarizeVectorOp - Given an operand of single-element vector type |
| 178 | /// (e.g. v1f32), convert it into the equivalent operation that returns a |
| 179 | /// scalar (e.g. f32) value. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 180 | SDOperand ScalarizeVectorOp(SDOperand O); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 181 | |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 182 | /// isShuffleLegal - Return true if a vector shuffle is legal with the |
| 183 | /// specified mask and type. Targets can specify exactly which masks they |
| 184 | /// support and the code generator is tasked with not creating illegal masks. |
| 185 | /// |
| 186 | /// Note that this will also return true for shuffles that are promoted to a |
| 187 | /// different type. |
| 188 | /// |
| 189 | /// If this is a legal shuffle, this method returns the (possibly promoted) |
| 190 | /// build_vector Mask. If it's not a legal shuffle, it returns null. |
| 191 | SDNode *isShuffleLegal(MVT::ValueType VT, SDOperand Mask) const; |
| 192 | |
Chris Lattner | c9cf4f1 | 2006-07-26 23:55:56 +0000 | [diff] [blame] | 193 | bool LegalizeAllNodesNotLeadingTo(SDNode *N, SDNode *Dest, |
Chris Lattner | 00755df | 2007-02-04 00:27:56 +0000 | [diff] [blame] | 194 | SmallPtrSet<SDNode*, 32> &NodesLeadingTo); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 195 | |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 196 | void LegalizeSetCCOperands(SDOperand &LHS, SDOperand &RHS, SDOperand &CC); |
| 197 | |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 198 | SDOperand ExpandLibCall(const char *Name, SDNode *Node, bool isSigned, |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 199 | SDOperand &Hi); |
| 200 | SDOperand ExpandIntToFP(bool isSigned, MVT::ValueType DestTy, |
| 201 | SDOperand Source); |
Chris Lattner | cad063f | 2005-07-16 00:19:57 +0000 | [diff] [blame] | 202 | |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 203 | SDOperand EmitStackConvert(SDOperand SrcOp, MVT::ValueType SlotVT, |
| 204 | MVT::ValueType DestVT); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 205 | SDOperand ExpandBUILD_VECTOR(SDNode *Node); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 206 | SDOperand ExpandSCALAR_TO_VECTOR(SDNode *Node); |
Jim Laskey | 6269ed1 | 2005-08-17 00:39:29 +0000 | [diff] [blame] | 207 | SDOperand ExpandLegalINT_TO_FP(bool isSigned, |
| 208 | SDOperand LegalOp, |
| 209 | MVT::ValueType DestVT); |
Nate Begeman | 5a8441e | 2005-07-16 02:02:34 +0000 | [diff] [blame] | 210 | SDOperand PromoteLegalINT_TO_FP(SDOperand LegalOp, MVT::ValueType DestVT, |
| 211 | bool isSigned); |
Chris Lattner | 1618beb | 2005-07-29 00:11:56 +0000 | [diff] [blame] | 212 | SDOperand PromoteLegalFP_TO_INT(SDOperand LegalOp, MVT::ValueType DestVT, |
| 213 | bool isSigned); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 214 | |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 215 | SDOperand ExpandBSWAP(SDOperand Op); |
| 216 | SDOperand ExpandBitCount(unsigned Opc, SDOperand Op); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 217 | bool ExpandShift(unsigned Opc, SDOperand Op, SDOperand Amt, |
| 218 | SDOperand &Lo, SDOperand &Hi); |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 219 | void ExpandShiftParts(unsigned NodeOp, SDOperand Op, SDOperand Amt, |
| 220 | SDOperand &Lo, SDOperand &Hi); |
Chris Lattner | b9fa3bc | 2005-05-12 04:49:08 +0000 | [diff] [blame] | 221 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 222 | SDOperand ExpandEXTRACT_SUBVECTOR(SDOperand Op); |
Chris Lattner | 4aab2f4 | 2006-04-02 05:06:04 +0000 | [diff] [blame] | 223 | SDOperand ExpandEXTRACT_VECTOR_ELT(SDOperand Op); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 224 | }; |
| 225 | } |
| 226 | |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 227 | /// isVectorShuffleLegal - Return true if a vector shuffle is legal with the |
| 228 | /// specified mask and type. Targets can specify exactly which masks they |
| 229 | /// support and the code generator is tasked with not creating illegal masks. |
| 230 | /// |
| 231 | /// Note that this will also return true for shuffles that are promoted to a |
| 232 | /// different type. |
| 233 | SDNode *SelectionDAGLegalize::isShuffleLegal(MVT::ValueType VT, |
| 234 | SDOperand Mask) const { |
| 235 | switch (TLI.getOperationAction(ISD::VECTOR_SHUFFLE, VT)) { |
| 236 | default: return 0; |
| 237 | case TargetLowering::Legal: |
| 238 | case TargetLowering::Custom: |
| 239 | break; |
| 240 | case TargetLowering::Promote: { |
| 241 | // If this is promoted to a different type, convert the shuffle mask and |
| 242 | // ask if it is legal in the promoted type! |
| 243 | MVT::ValueType NVT = TLI.getTypeToPromoteTo(ISD::VECTOR_SHUFFLE, VT); |
| 244 | |
| 245 | // If we changed # elements, change the shuffle mask. |
| 246 | unsigned NumEltsGrowth = |
| 247 | MVT::getVectorNumElements(NVT) / MVT::getVectorNumElements(VT); |
| 248 | assert(NumEltsGrowth && "Cannot promote to vector type with fewer elts!"); |
| 249 | if (NumEltsGrowth > 1) { |
| 250 | // Renumber the elements. |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 251 | SmallVector<SDOperand, 8> Ops; |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 252 | for (unsigned i = 0, e = Mask.getNumOperands(); i != e; ++i) { |
| 253 | SDOperand InOp = Mask.getOperand(i); |
| 254 | for (unsigned j = 0; j != NumEltsGrowth; ++j) { |
| 255 | if (InOp.getOpcode() == ISD::UNDEF) |
| 256 | Ops.push_back(DAG.getNode(ISD::UNDEF, MVT::i32)); |
| 257 | else { |
| 258 | unsigned InEltNo = cast<ConstantSDNode>(InOp)->getValue(); |
| 259 | Ops.push_back(DAG.getConstant(InEltNo*NumEltsGrowth+j, MVT::i32)); |
| 260 | } |
| 261 | } |
| 262 | } |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 263 | Mask = DAG.getNode(ISD::BUILD_VECTOR, NVT, &Ops[0], Ops.size()); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 264 | } |
| 265 | VT = NVT; |
| 266 | break; |
| 267 | } |
| 268 | } |
| 269 | return TLI.isShuffleMaskLegal(Mask, VT) ? Mask.Val : 0; |
| 270 | } |
| 271 | |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 272 | SelectionDAGLegalize::SelectionDAGLegalize(SelectionDAG &dag) |
| 273 | : TLI(dag.getTargetLoweringInfo()), DAG(dag), |
| 274 | ValueTypeActions(TLI.getValueTypeActions()) { |
Nate Begeman | 6a64861 | 2005-11-29 05:45:29 +0000 | [diff] [blame] | 275 | assert(MVT::LAST_VALUETYPE <= 32 && |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 276 | "Too many value types for ValueTypeActions to hold!"); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 277 | } |
| 278 | |
Chris Lattner | e10e6f7 | 2007-06-18 21:28:10 +0000 | [diff] [blame] | 279 | /// ComputeTopDownOrdering - Compute a top-down ordering of the dag, where Order |
| 280 | /// contains all of a nodes operands before it contains the node. |
| 281 | static void ComputeTopDownOrdering(SelectionDAG &DAG, |
| 282 | SmallVector<SDNode*, 64> &Order) { |
| 283 | |
| 284 | DenseMap<SDNode*, unsigned> Visited; |
| 285 | std::vector<SDNode*> Worklist; |
| 286 | Worklist.reserve(128); |
Chris Lattner | 32fca00 | 2005-10-06 01:20:27 +0000 | [diff] [blame] | 287 | |
Chris Lattner | e10e6f7 | 2007-06-18 21:28:10 +0000 | [diff] [blame] | 288 | // Compute ordering from all of the leaves in the graphs, those (like the |
| 289 | // entry node) that have no operands. |
| 290 | for (SelectionDAG::allnodes_iterator I = DAG.allnodes_begin(), |
| 291 | E = DAG.allnodes_end(); I != E; ++I) { |
| 292 | if (I->getNumOperands() == 0) { |
| 293 | Visited[I] = 0 - 1U; |
| 294 | Worklist.push_back(I); |
| 295 | } |
Chris Lattner | 32fca00 | 2005-10-06 01:20:27 +0000 | [diff] [blame] | 296 | } |
| 297 | |
Chris Lattner | e10e6f7 | 2007-06-18 21:28:10 +0000 | [diff] [blame] | 298 | while (!Worklist.empty()) { |
| 299 | SDNode *N = Worklist.back(); |
| 300 | Worklist.pop_back(); |
| 301 | |
| 302 | if (++Visited[N] != N->getNumOperands()) |
| 303 | continue; // Haven't visited all operands yet |
| 304 | |
| 305 | Order.push_back(N); |
| 306 | |
| 307 | // Now that we have N in, add anything that uses it if all of their operands |
| 308 | // are now done. |
| 309 | for (SDNode::use_iterator UI = N->use_begin(), E = N->use_end(); |
| 310 | UI != E; ++UI) |
Roman Levenstein | dc1adac | 2008-04-07 10:06:32 +0000 | [diff] [blame] | 311 | Worklist.push_back(UI->getUser()); |
Chris Lattner | e10e6f7 | 2007-06-18 21:28:10 +0000 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | assert(Order.size() == Visited.size() && |
| 315 | Order.size() == |
| 316 | (unsigned)std::distance(DAG.allnodes_begin(), DAG.allnodes_end()) && |
| 317 | "Error: DAG is cyclic!"); |
Chris Lattner | 32fca00 | 2005-10-06 01:20:27 +0000 | [diff] [blame] | 318 | } |
| 319 | |
Chris Lattner | 1618beb | 2005-07-29 00:11:56 +0000 | [diff] [blame] | 320 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 321 | void SelectionDAGLegalize::LegalizeDAG() { |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 322 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 323 | IsLegalizingCall = false; |
| 324 | |
Chris Lattner | ab510a7 | 2005-10-02 17:49:46 +0000 | [diff] [blame] | 325 | // The legalize process is inherently a bottom-up recursive process (users |
| 326 | // legalize their uses before themselves). Given infinite stack space, we |
| 327 | // could just start legalizing on the root and traverse the whole graph. In |
| 328 | // practice however, this causes us to run out of stack space on large basic |
Chris Lattner | 32fca00 | 2005-10-06 01:20:27 +0000 | [diff] [blame] | 329 | // blocks. To avoid this problem, compute an ordering of the nodes where each |
| 330 | // node is only legalized after all of its operands are legalized. |
Chris Lattner | 0ed4417 | 2007-02-04 01:20:02 +0000 | [diff] [blame] | 331 | SmallVector<SDNode*, 64> Order; |
Chris Lattner | e10e6f7 | 2007-06-18 21:28:10 +0000 | [diff] [blame] | 332 | ComputeTopDownOrdering(DAG, Order); |
Chris Lattner | ab510a7 | 2005-10-02 17:49:46 +0000 | [diff] [blame] | 333 | |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 334 | for (unsigned i = 0, e = Order.size(); i != e; ++i) |
| 335 | HandleOp(SDOperand(Order[i], 0)); |
Chris Lattner | 32fca00 | 2005-10-06 01:20:27 +0000 | [diff] [blame] | 336 | |
| 337 | // Finally, it's possible the root changed. Get the new root. |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 338 | SDOperand OldRoot = DAG.getRoot(); |
Chris Lattner | 32fca00 | 2005-10-06 01:20:27 +0000 | [diff] [blame] | 339 | assert(LegalizedNodes.count(OldRoot) && "Root didn't get legalized?"); |
| 340 | DAG.setRoot(LegalizedNodes[OldRoot]); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 341 | |
| 342 | ExpandedNodes.clear(); |
| 343 | LegalizedNodes.clear(); |
Chris Lattner | 71c42a0 | 2005-01-16 01:11:45 +0000 | [diff] [blame] | 344 | PromotedNodes.clear(); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 345 | SplitNodes.clear(); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 346 | ScalarizedNodes.clear(); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 347 | |
| 348 | // Remove dead nodes now. |
Chris Lattner | 190a418 | 2006-08-04 17:45:20 +0000 | [diff] [blame] | 349 | DAG.RemoveDeadNodes(); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 350 | } |
| 351 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 352 | |
| 353 | /// FindCallEndFromCallStart - Given a chained node that is part of a call |
| 354 | /// sequence, find the CALLSEQ_END node that terminates the call sequence. |
| 355 | static SDNode *FindCallEndFromCallStart(SDNode *Node) { |
| 356 | if (Node->getOpcode() == ISD::CALLSEQ_END) |
| 357 | return Node; |
| 358 | if (Node->use_empty()) |
| 359 | return 0; // No CallSeqEnd |
| 360 | |
| 361 | // The chain is usually at the end. |
| 362 | SDOperand TheChain(Node, Node->getNumValues()-1); |
| 363 | if (TheChain.getValueType() != MVT::Other) { |
| 364 | // Sometimes it's at the beginning. |
| 365 | TheChain = SDOperand(Node, 0); |
| 366 | if (TheChain.getValueType() != MVT::Other) { |
| 367 | // Otherwise, hunt for it. |
| 368 | for (unsigned i = 1, e = Node->getNumValues(); i != e; ++i) |
| 369 | if (Node->getValueType(i) == MVT::Other) { |
| 370 | TheChain = SDOperand(Node, i); |
| 371 | break; |
| 372 | } |
| 373 | |
| 374 | // Otherwise, we walked into a node without a chain. |
| 375 | if (TheChain.getValueType() != MVT::Other) |
| 376 | return 0; |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | for (SDNode::use_iterator UI = Node->use_begin(), |
| 381 | E = Node->use_end(); UI != E; ++UI) { |
| 382 | |
| 383 | // Make sure to only follow users of our token chain. |
Roman Levenstein | dc1adac | 2008-04-07 10:06:32 +0000 | [diff] [blame] | 384 | SDNode *User = UI->getUser(); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 385 | for (unsigned i = 0, e = User->getNumOperands(); i != e; ++i) |
| 386 | if (User->getOperand(i) == TheChain) |
| 387 | if (SDNode *Result = FindCallEndFromCallStart(User)) |
| 388 | return Result; |
| 389 | } |
| 390 | return 0; |
| 391 | } |
| 392 | |
| 393 | /// FindCallStartFromCallEnd - Given a chained node that is part of a call |
| 394 | /// sequence, find the CALLSEQ_START node that initiates the call sequence. |
| 395 | static SDNode *FindCallStartFromCallEnd(SDNode *Node) { |
| 396 | assert(Node && "Didn't find callseq_start for a call??"); |
| 397 | if (Node->getOpcode() == ISD::CALLSEQ_START) return Node; |
| 398 | |
| 399 | assert(Node->getOperand(0).getValueType() == MVT::Other && |
| 400 | "Node doesn't have a token chain argument!"); |
| 401 | return FindCallStartFromCallEnd(Node->getOperand(0).Val); |
| 402 | } |
| 403 | |
| 404 | /// LegalizeAllNodesNotLeadingTo - Recursively walk the uses of N, looking to |
| 405 | /// see if any uses can reach Dest. If no dest operands can get to dest, |
| 406 | /// legalize them, legalize ourself, and return false, otherwise, return true. |
Chris Lattner | c9cf4f1 | 2006-07-26 23:55:56 +0000 | [diff] [blame] | 407 | /// |
| 408 | /// Keep track of the nodes we fine that actually do lead to Dest in |
| 409 | /// NodesLeadingTo. This avoids retraversing them exponential number of times. |
| 410 | /// |
| 411 | bool SelectionDAGLegalize::LegalizeAllNodesNotLeadingTo(SDNode *N, SDNode *Dest, |
Chris Lattner | 00755df | 2007-02-04 00:27:56 +0000 | [diff] [blame] | 412 | SmallPtrSet<SDNode*, 32> &NodesLeadingTo) { |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 413 | if (N == Dest) return true; // N certainly leads to Dest :) |
| 414 | |
Chris Lattner | c9cf4f1 | 2006-07-26 23:55:56 +0000 | [diff] [blame] | 415 | // If we've already processed this node and it does lead to Dest, there is no |
| 416 | // need to reprocess it. |
| 417 | if (NodesLeadingTo.count(N)) return true; |
| 418 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 419 | // If the first result of this node has been already legalized, then it cannot |
| 420 | // reach N. |
| 421 | switch (getTypeAction(N->getValueType(0))) { |
| 422 | case Legal: |
| 423 | if (LegalizedNodes.count(SDOperand(N, 0))) return false; |
| 424 | break; |
| 425 | case Promote: |
| 426 | if (PromotedNodes.count(SDOperand(N, 0))) return false; |
| 427 | break; |
| 428 | case Expand: |
| 429 | if (ExpandedNodes.count(SDOperand(N, 0))) return false; |
| 430 | break; |
| 431 | } |
| 432 | |
| 433 | // Okay, this node has not already been legalized. Check and legalize all |
| 434 | // operands. If none lead to Dest, then we can legalize this node. |
| 435 | bool OperandsLeadToDest = false; |
| 436 | for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) |
| 437 | OperandsLeadToDest |= // If an operand leads to Dest, so do we. |
Chris Lattner | c9cf4f1 | 2006-07-26 23:55:56 +0000 | [diff] [blame] | 438 | LegalizeAllNodesNotLeadingTo(N->getOperand(i).Val, Dest, NodesLeadingTo); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 439 | |
Chris Lattner | c9cf4f1 | 2006-07-26 23:55:56 +0000 | [diff] [blame] | 440 | if (OperandsLeadToDest) { |
| 441 | NodesLeadingTo.insert(N); |
| 442 | return true; |
| 443 | } |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 444 | |
| 445 | // Okay, this node looks safe, legalize it and return false. |
Chris Lattner | 80edfb3 | 2006-04-17 22:10:08 +0000 | [diff] [blame] | 446 | HandleOp(SDOperand(N, 0)); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 447 | return false; |
| 448 | } |
| 449 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 450 | /// HandleOp - Legalize, Promote, or Expand the specified operand as |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 451 | /// appropriate for its type. |
| 452 | void SelectionDAGLegalize::HandleOp(SDOperand Op) { |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 453 | MVT::ValueType VT = Op.getValueType(); |
| 454 | switch (getTypeAction(VT)) { |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 455 | default: assert(0 && "Bad type action!"); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 456 | case Legal: (void)LegalizeOp(Op); break; |
| 457 | case Promote: (void)PromoteOp(Op); break; |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 458 | case Expand: |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 459 | if (!MVT::isVector(VT)) { |
| 460 | // If this is an illegal scalar, expand it into its two component |
| 461 | // pieces. |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 462 | SDOperand X, Y; |
Chris Lattner | 09ec1b0 | 2007-08-25 01:00:22 +0000 | [diff] [blame] | 463 | if (Op.getOpcode() == ISD::TargetConstant) |
| 464 | break; // Allow illegal target nodes. |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 465 | ExpandOp(Op, X, Y); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 466 | } else if (MVT::getVectorNumElements(VT) == 1) { |
| 467 | // If this is an illegal single element vector, convert it to a |
| 468 | // scalar operation. |
| 469 | (void)ScalarizeVectorOp(Op); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 470 | } else { |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 471 | // Otherwise, this is an illegal multiple element vector. |
| 472 | // Split it in half and legalize both parts. |
| 473 | SDOperand X, Y; |
| 474 | SplitVectorOp(Op, X, Y); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 475 | } |
| 476 | break; |
| 477 | } |
| 478 | } |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 479 | |
Evan Cheng | 9f87788 | 2006-12-13 20:57:08 +0000 | [diff] [blame] | 480 | /// ExpandConstantFP - Expands the ConstantFP node to an integer constant or |
| 481 | /// a load from the constant pool. |
| 482 | static SDOperand ExpandConstantFP(ConstantFPSDNode *CFP, bool UseCP, |
Evan Cheng | 279101e | 2006-12-12 22:19:28 +0000 | [diff] [blame] | 483 | SelectionDAG &DAG, TargetLowering &TLI) { |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 484 | bool Extend = false; |
| 485 | |
| 486 | // If a FP immediate is precise when represented as a float and if the |
| 487 | // target can do an extending load from float to double, we put it into |
| 488 | // the constant pool as a float, even if it's is statically typed as a |
Chris Lattner | aa2acbb | 2008-03-05 06:46:58 +0000 | [diff] [blame] | 489 | // double. This shrinks FP constants and canonicalizes them for targets where |
| 490 | // an FP extending load is the same cost as a normal load (such as on the x87 |
| 491 | // fp stack or PPC FP unit). |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 492 | MVT::ValueType VT = CFP->getValueType(0); |
Dale Johannesen | 118cd9d | 2007-09-16 16:51:49 +0000 | [diff] [blame] | 493 | ConstantFP *LLVMC = ConstantFP::get(MVT::getTypeForValueType(VT), |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 494 | CFP->getValueAPF()); |
Evan Cheng | 9f87788 | 2006-12-13 20:57:08 +0000 | [diff] [blame] | 495 | if (!UseCP) { |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 496 | if (VT!=MVT::f64 && VT!=MVT::f32) |
| 497 | assert(0 && "Invalid type expansion"); |
Dan Gohman | 6cf9b8a | 2008-03-11 00:11:06 +0000 | [diff] [blame] | 498 | return DAG.getConstant(LLVMC->getValueAPF().convertToAPInt(), |
Evan Cheng | ef12057 | 2008-03-04 08:05:30 +0000 | [diff] [blame] | 499 | (VT == MVT::f64) ? MVT::i64 : MVT::i32); |
Evan Cheng | 279101e | 2006-12-12 22:19:28 +0000 | [diff] [blame] | 500 | } |
| 501 | |
Evan Cheng | ef12057 | 2008-03-04 08:05:30 +0000 | [diff] [blame] | 502 | MVT::ValueType OrigVT = VT; |
| 503 | MVT::ValueType SVT = VT; |
| 504 | while (SVT != MVT::f32) { |
| 505 | SVT = (unsigned)SVT - 1; |
| 506 | if (CFP->isValueValidForType(SVT, CFP->getValueAPF()) && |
| 507 | // Only do this if the target has a native EXTLOAD instruction from |
| 508 | // smaller type. |
Evan Cheng | 6fd599f | 2008-03-05 01:30:59 +0000 | [diff] [blame] | 509 | TLI.isLoadXLegal(ISD::EXTLOAD, SVT) && |
Chris Lattner | aa2acbb | 2008-03-05 06:46:58 +0000 | [diff] [blame] | 510 | TLI.ShouldShrinkFPConstant(OrigVT)) { |
Evan Cheng | ef12057 | 2008-03-04 08:05:30 +0000 | [diff] [blame] | 511 | const Type *SType = MVT::getTypeForValueType(SVT); |
| 512 | LLVMC = cast<ConstantFP>(ConstantExpr::getFPTrunc(LLVMC, SType)); |
| 513 | VT = SVT; |
| 514 | Extend = true; |
| 515 | } |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | SDOperand CPIdx = DAG.getConstantPool(LLVMC, TLI.getPointerTy()); |
Evan Cheng | ef12057 | 2008-03-04 08:05:30 +0000 | [diff] [blame] | 519 | if (Extend) |
| 520 | return DAG.getExtLoad(ISD::EXTLOAD, OrigVT, DAG.getEntryNode(), |
Dan Gohman | 3069b87 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 521 | CPIdx, PseudoSourceValue::getConstantPool(), |
Evan Cheng | ef12057 | 2008-03-04 08:05:30 +0000 | [diff] [blame] | 522 | 0, VT); |
| 523 | return DAG.getLoad(OrigVT, DAG.getEntryNode(), CPIdx, |
| 524 | PseudoSourceValue::getConstantPool(), 0); |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 525 | } |
| 526 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 527 | |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 528 | /// ExpandFCOPYSIGNToBitwiseOps - Expands fcopysign to a series of bitwise |
| 529 | /// operations. |
| 530 | static |
| 531 | SDOperand ExpandFCOPYSIGNToBitwiseOps(SDNode *Node, MVT::ValueType NVT, |
| 532 | SelectionDAG &DAG, TargetLowering &TLI) { |
Evan Cheng | 068c5f4 | 2007-01-05 21:31:51 +0000 | [diff] [blame] | 533 | MVT::ValueType VT = Node->getValueType(0); |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 534 | MVT::ValueType SrcVT = Node->getOperand(1).getValueType(); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 535 | assert((SrcVT == MVT::f32 || SrcVT == MVT::f64) && |
| 536 | "fcopysign expansion only supported for f32 and f64"); |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 537 | MVT::ValueType SrcNVT = (SrcVT == MVT::f64) ? MVT::i64 : MVT::i32; |
Evan Cheng | 068c5f4 | 2007-01-05 21:31:51 +0000 | [diff] [blame] | 538 | |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 539 | // First get the sign bit of second operand. |
Evan Cheng | 068c5f4 | 2007-01-05 21:31:51 +0000 | [diff] [blame] | 540 | SDOperand Mask1 = (SrcVT == MVT::f64) |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 541 | ? DAG.getConstantFP(BitsToDouble(1ULL << 63), SrcVT) |
| 542 | : DAG.getConstantFP(BitsToFloat(1U << 31), SrcVT); |
Evan Cheng | 068c5f4 | 2007-01-05 21:31:51 +0000 | [diff] [blame] | 543 | Mask1 = DAG.getNode(ISD::BIT_CONVERT, SrcNVT, Mask1); |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 544 | SDOperand SignBit= DAG.getNode(ISD::BIT_CONVERT, SrcNVT, Node->getOperand(1)); |
Evan Cheng | 068c5f4 | 2007-01-05 21:31:51 +0000 | [diff] [blame] | 545 | SignBit = DAG.getNode(ISD::AND, SrcNVT, SignBit, Mask1); |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 546 | // Shift right or sign-extend it if the two operands have different types. |
| 547 | int SizeDiff = MVT::getSizeInBits(SrcNVT) - MVT::getSizeInBits(NVT); |
| 548 | if (SizeDiff > 0) { |
| 549 | SignBit = DAG.getNode(ISD::SRL, SrcNVT, SignBit, |
| 550 | DAG.getConstant(SizeDiff, TLI.getShiftAmountTy())); |
| 551 | SignBit = DAG.getNode(ISD::TRUNCATE, NVT, SignBit); |
| 552 | } else if (SizeDiff < 0) |
| 553 | SignBit = DAG.getNode(ISD::SIGN_EXTEND, NVT, SignBit); |
Evan Cheng | 068c5f4 | 2007-01-05 21:31:51 +0000 | [diff] [blame] | 554 | |
| 555 | // Clear the sign bit of first operand. |
| 556 | SDOperand Mask2 = (VT == MVT::f64) |
| 557 | ? DAG.getConstantFP(BitsToDouble(~(1ULL << 63)), VT) |
| 558 | : DAG.getConstantFP(BitsToFloat(~(1U << 31)), VT); |
| 559 | Mask2 = DAG.getNode(ISD::BIT_CONVERT, NVT, Mask2); |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 560 | SDOperand Result = DAG.getNode(ISD::BIT_CONVERT, NVT, Node->getOperand(0)); |
Evan Cheng | 068c5f4 | 2007-01-05 21:31:51 +0000 | [diff] [blame] | 561 | Result = DAG.getNode(ISD::AND, NVT, Result, Mask2); |
| 562 | |
| 563 | // Or the value with the sign bit. |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 564 | Result = DAG.getNode(ISD::OR, NVT, Result, SignBit); |
| 565 | return Result; |
| 566 | } |
| 567 | |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 568 | /// ExpandUnalignedStore - Expands an unaligned store to 2 half-size stores. |
| 569 | static |
| 570 | SDOperand ExpandUnalignedStore(StoreSDNode *ST, SelectionDAG &DAG, |
| 571 | TargetLowering &TLI) { |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 572 | SDOperand Chain = ST->getChain(); |
| 573 | SDOperand Ptr = ST->getBasePtr(); |
| 574 | SDOperand Val = ST->getValue(); |
| 575 | MVT::ValueType VT = Val.getValueType(); |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 576 | int Alignment = ST->getAlignment(); |
| 577 | int SVOffset = ST->getSrcValueOffset(); |
Dale Johannesen | 8155d64 | 2008-02-27 22:36:00 +0000 | [diff] [blame] | 578 | if (MVT::isFloatingPoint(ST->getMemoryVT()) || |
| 579 | MVT::isVector(ST->getMemoryVT())) { |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 580 | // Expand to a bitconvert of the value to the integer type of the |
| 581 | // same size, then a (misaligned) int store. |
| 582 | MVT::ValueType intVT; |
Dale Johannesen | 3c8b59c | 2008-03-01 03:40:57 +0000 | [diff] [blame] | 583 | if (MVT::is128BitVector(VT) || VT == MVT::ppcf128 || VT == MVT::f128) |
Dale Johannesen | 8155d64 | 2008-02-27 22:36:00 +0000 | [diff] [blame] | 584 | intVT = MVT::i128; |
Dale Johannesen | 3c8b59c | 2008-03-01 03:40:57 +0000 | [diff] [blame] | 585 | else if (MVT::is64BitVector(VT) || VT==MVT::f64) |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 586 | intVT = MVT::i64; |
| 587 | else if (VT==MVT::f32) |
| 588 | intVT = MVT::i32; |
| 589 | else |
Dale Johannesen | cd9f174 | 2008-02-28 18:36:51 +0000 | [diff] [blame] | 590 | assert(0 && "Unaligned store of unsupported type"); |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 591 | |
| 592 | SDOperand Result = DAG.getNode(ISD::BIT_CONVERT, intVT, Val); |
| 593 | return DAG.getStore(Chain, Result, Ptr, ST->getSrcValue(), |
| 594 | SVOffset, ST->isVolatile(), Alignment); |
| 595 | } |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 596 | assert(MVT::isInteger(ST->getMemoryVT()) && |
Dale Johannesen | 8155d64 | 2008-02-27 22:36:00 +0000 | [diff] [blame] | 597 | !MVT::isVector(ST->getMemoryVT()) && |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 598 | "Unaligned store of unknown type."); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 599 | // Get the half-size VT |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 600 | MVT::ValueType NewStoredVT = ST->getMemoryVT() - 1; |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 601 | int NumBits = MVT::getSizeInBits(NewStoredVT); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 602 | int IncrementSize = NumBits / 8; |
| 603 | |
| 604 | // Divide the stored value in two parts. |
| 605 | SDOperand ShiftAmount = DAG.getConstant(NumBits, TLI.getShiftAmountTy()); |
| 606 | SDOperand Lo = Val; |
| 607 | SDOperand Hi = DAG.getNode(ISD::SRL, VT, Val, ShiftAmount); |
| 608 | |
| 609 | // Store the two parts |
| 610 | SDOperand Store1, Store2; |
| 611 | Store1 = DAG.getTruncStore(Chain, TLI.isLittleEndian()?Lo:Hi, Ptr, |
| 612 | ST->getSrcValue(), SVOffset, NewStoredVT, |
| 613 | ST->isVolatile(), Alignment); |
| 614 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
| 615 | DAG.getConstant(IncrementSize, TLI.getPointerTy())); |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 616 | Alignment = MinAlign(Alignment, IncrementSize); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 617 | Store2 = DAG.getTruncStore(Chain, TLI.isLittleEndian()?Hi:Lo, Ptr, |
| 618 | ST->getSrcValue(), SVOffset + IncrementSize, |
| 619 | NewStoredVT, ST->isVolatile(), Alignment); |
| 620 | |
| 621 | return DAG.getNode(ISD::TokenFactor, MVT::Other, Store1, Store2); |
| 622 | } |
| 623 | |
| 624 | /// ExpandUnalignedLoad - Expands an unaligned load to 2 half-size loads. |
| 625 | static |
| 626 | SDOperand ExpandUnalignedLoad(LoadSDNode *LD, SelectionDAG &DAG, |
| 627 | TargetLowering &TLI) { |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 628 | int SVOffset = LD->getSrcValueOffset(); |
| 629 | SDOperand Chain = LD->getChain(); |
| 630 | SDOperand Ptr = LD->getBasePtr(); |
| 631 | MVT::ValueType VT = LD->getValueType(0); |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 632 | MVT::ValueType LoadedVT = LD->getMemoryVT(); |
Dale Johannesen | 8155d64 | 2008-02-27 22:36:00 +0000 | [diff] [blame] | 633 | if (MVT::isFloatingPoint(VT) || MVT::isVector(VT)) { |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 634 | // Expand to a (misaligned) integer load of the same size, |
Dale Johannesen | 8155d64 | 2008-02-27 22:36:00 +0000 | [diff] [blame] | 635 | // then bitconvert to floating point or vector. |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 636 | MVT::ValueType intVT; |
Dale Johannesen | 3c8b59c | 2008-03-01 03:40:57 +0000 | [diff] [blame] | 637 | if (MVT::is128BitVector(LoadedVT) || |
| 638 | LoadedVT == MVT::ppcf128 || LoadedVT == MVT::f128) |
Dale Johannesen | 8155d64 | 2008-02-27 22:36:00 +0000 | [diff] [blame] | 639 | intVT = MVT::i128; |
Dale Johannesen | 3c8b59c | 2008-03-01 03:40:57 +0000 | [diff] [blame] | 640 | else if (MVT::is64BitVector(LoadedVT) || LoadedVT == MVT::f64) |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 641 | intVT = MVT::i64; |
Chris Lattner | e400af8 | 2007-11-19 21:38:03 +0000 | [diff] [blame] | 642 | else if (LoadedVT == MVT::f32) |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 643 | intVT = MVT::i32; |
| 644 | else |
Dale Johannesen | 8155d64 | 2008-02-27 22:36:00 +0000 | [diff] [blame] | 645 | assert(0 && "Unaligned load of unsupported type"); |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 646 | |
| 647 | SDOperand newLoad = DAG.getLoad(intVT, Chain, Ptr, LD->getSrcValue(), |
| 648 | SVOffset, LD->isVolatile(), |
| 649 | LD->getAlignment()); |
| 650 | SDOperand Result = DAG.getNode(ISD::BIT_CONVERT, LoadedVT, newLoad); |
Dale Johannesen | 8155d64 | 2008-02-27 22:36:00 +0000 | [diff] [blame] | 651 | if (MVT::isFloatingPoint(VT) && LoadedVT != VT) |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 652 | Result = DAG.getNode(ISD::FP_EXTEND, VT, Result); |
| 653 | |
| 654 | SDOperand Ops[] = { Result, Chain }; |
| 655 | return DAG.getNode(ISD::MERGE_VALUES, DAG.getVTList(VT, MVT::Other), |
| 656 | Ops, 2); |
| 657 | } |
Dale Johannesen | 8155d64 | 2008-02-27 22:36:00 +0000 | [diff] [blame] | 658 | assert(MVT::isInteger(LoadedVT) && !MVT::isVector(LoadedVT) && |
Chris Lattner | e400af8 | 2007-11-19 21:38:03 +0000 | [diff] [blame] | 659 | "Unaligned load of unsupported type."); |
| 660 | |
Dale Johannesen | 8155d64 | 2008-02-27 22:36:00 +0000 | [diff] [blame] | 661 | // Compute the new VT that is half the size of the old one. This is an |
| 662 | // integer MVT. |
Chris Lattner | e400af8 | 2007-11-19 21:38:03 +0000 | [diff] [blame] | 663 | unsigned NumBits = MVT::getSizeInBits(LoadedVT); |
| 664 | MVT::ValueType NewLoadedVT; |
Dale Johannesen | 8155d64 | 2008-02-27 22:36:00 +0000 | [diff] [blame] | 665 | NewLoadedVT = MVT::getIntegerType(NumBits/2); |
Chris Lattner | e400af8 | 2007-11-19 21:38:03 +0000 | [diff] [blame] | 666 | NumBits >>= 1; |
| 667 | |
| 668 | unsigned Alignment = LD->getAlignment(); |
| 669 | unsigned IncrementSize = NumBits / 8; |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 670 | ISD::LoadExtType HiExtType = LD->getExtensionType(); |
| 671 | |
| 672 | // If the original load is NON_EXTLOAD, the hi part load must be ZEXTLOAD. |
| 673 | if (HiExtType == ISD::NON_EXTLOAD) |
| 674 | HiExtType = ISD::ZEXTLOAD; |
| 675 | |
| 676 | // Load the value in two parts |
| 677 | SDOperand Lo, Hi; |
| 678 | if (TLI.isLittleEndian()) { |
| 679 | Lo = DAG.getExtLoad(ISD::ZEXTLOAD, VT, Chain, Ptr, LD->getSrcValue(), |
| 680 | SVOffset, NewLoadedVT, LD->isVolatile(), Alignment); |
| 681 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
| 682 | DAG.getConstant(IncrementSize, TLI.getPointerTy())); |
| 683 | Hi = DAG.getExtLoad(HiExtType, VT, Chain, Ptr, LD->getSrcValue(), |
| 684 | SVOffset + IncrementSize, NewLoadedVT, LD->isVolatile(), |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 685 | MinAlign(Alignment, IncrementSize)); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 686 | } else { |
| 687 | Hi = DAG.getExtLoad(HiExtType, VT, Chain, Ptr, LD->getSrcValue(), SVOffset, |
| 688 | NewLoadedVT,LD->isVolatile(), Alignment); |
| 689 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
| 690 | DAG.getConstant(IncrementSize, TLI.getPointerTy())); |
| 691 | Lo = DAG.getExtLoad(ISD::ZEXTLOAD, VT, Chain, Ptr, LD->getSrcValue(), |
| 692 | SVOffset + IncrementSize, NewLoadedVT, LD->isVolatile(), |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 693 | MinAlign(Alignment, IncrementSize)); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | // aggregate the two parts |
| 697 | SDOperand ShiftAmount = DAG.getConstant(NumBits, TLI.getShiftAmountTy()); |
| 698 | SDOperand Result = DAG.getNode(ISD::SHL, VT, Hi, ShiftAmount); |
| 699 | Result = DAG.getNode(ISD::OR, VT, Result, Lo); |
| 700 | |
| 701 | SDOperand TF = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1), |
| 702 | Hi.getValue(1)); |
| 703 | |
| 704 | SDOperand Ops[] = { Result, TF }; |
| 705 | return DAG.getNode(ISD::MERGE_VALUES, DAG.getVTList(VT, MVT::Other), Ops, 2); |
| 706 | } |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 707 | |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 708 | /// UnrollVectorOp - We know that the given vector has a legal type, however |
| 709 | /// the operation it performs is not legal and is an operation that we have |
| 710 | /// no way of lowering. "Unroll" the vector, splitting out the scalars and |
| 711 | /// operating on each element individually. |
| 712 | SDOperand SelectionDAGLegalize::UnrollVectorOp(SDOperand Op) { |
| 713 | MVT::ValueType VT = Op.getValueType(); |
| 714 | assert(isTypeLegal(VT) && |
| 715 | "Caller should expand or promote operands that are not legal!"); |
| 716 | assert(Op.Val->getNumValues() == 1 && |
| 717 | "Can't unroll a vector with multiple results!"); |
| 718 | unsigned NE = MVT::getVectorNumElements(VT); |
| 719 | MVT::ValueType EltVT = MVT::getVectorElementType(VT); |
| 720 | |
| 721 | SmallVector<SDOperand, 8> Scalars; |
| 722 | SmallVector<SDOperand, 4> Operands(Op.getNumOperands()); |
| 723 | for (unsigned i = 0; i != NE; ++i) { |
| 724 | for (unsigned j = 0; j != Op.getNumOperands(); ++j) { |
| 725 | SDOperand Operand = Op.getOperand(j); |
| 726 | MVT::ValueType OperandVT = Operand.getValueType(); |
| 727 | if (MVT::isVector(OperandVT)) { |
| 728 | // A vector operand; extract a single element. |
| 729 | MVT::ValueType OperandEltVT = MVT::getVectorElementType(OperandVT); |
| 730 | Operands[j] = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, |
| 731 | OperandEltVT, |
| 732 | Operand, |
| 733 | DAG.getConstant(i, MVT::i32)); |
| 734 | } else { |
| 735 | // A scalar operand; just use it as is. |
| 736 | Operands[j] = Operand; |
| 737 | } |
| 738 | } |
| 739 | Scalars.push_back(DAG.getNode(Op.getOpcode(), EltVT, |
| 740 | &Operands[0], Operands.size())); |
| 741 | } |
| 742 | |
| 743 | return DAG.getNode(ISD::BUILD_VECTOR, VT, &Scalars[0], Scalars.size()); |
| 744 | } |
| 745 | |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 746 | /// GetFPLibCall - Return the right libcall for the given floating point type. |
| 747 | static RTLIB::Libcall GetFPLibCall(MVT::ValueType VT, |
| 748 | RTLIB::Libcall Call_F32, |
| 749 | RTLIB::Libcall Call_F64, |
| 750 | RTLIB::Libcall Call_F80, |
| 751 | RTLIB::Libcall Call_PPCF128) { |
| 752 | return |
| 753 | VT == MVT::f32 ? Call_F32 : |
| 754 | VT == MVT::f64 ? Call_F64 : |
| 755 | VT == MVT::f80 ? Call_F80 : |
| 756 | VT == MVT::ppcf128 ? Call_PPCF128 : |
| 757 | RTLIB::UNKNOWN_LIBCALL; |
| 758 | } |
| 759 | |
Dan Gohman | a346615 | 2007-07-13 20:14:11 +0000 | [diff] [blame] | 760 | /// LegalizeOp - We know that the specified value has a legal type, and |
| 761 | /// that its operands are legal. Now ensure that the operation itself |
| 762 | /// is legal, recursively ensuring that the operands' operations remain |
| 763 | /// legal. |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 764 | SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) { |
Chris Lattner | 09ec1b0 | 2007-08-25 01:00:22 +0000 | [diff] [blame] | 765 | if (Op.getOpcode() == ISD::TargetConstant) // Allow illegal target nodes. |
| 766 | return Op; |
| 767 | |
Chris Lattner | c9c60f6 | 2005-08-24 16:35:28 +0000 | [diff] [blame] | 768 | assert(isTypeLegal(Op.getValueType()) && |
Chris Lattner | e3304a3 | 2005-01-08 20:35:13 +0000 | [diff] [blame] | 769 | "Caller should expand or promote operands that are not legal!"); |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 770 | SDNode *Node = Op.Val; |
Chris Lattner | e3304a3 | 2005-01-08 20:35:13 +0000 | [diff] [blame] | 771 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 772 | // If this operation defines any values that cannot be represented in a |
Chris Lattner | e3304a3 | 2005-01-08 20:35:13 +0000 | [diff] [blame] | 773 | // register on this target, make sure to expand or promote them. |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 774 | if (Node->getNumValues() > 1) { |
| 775 | for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 776 | if (getTypeAction(Node->getValueType(i)) != Legal) { |
| 777 | HandleOp(Op.getValue(i)); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 778 | assert(LegalizedNodes.count(Op) && |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 779 | "Handling didn't add legal operands!"); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 780 | return LegalizedNodes[Op]; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 781 | } |
| 782 | } |
| 783 | |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 784 | // Note that LegalizeOp may be reentered even from single-use nodes, which |
| 785 | // means that we always must cache transformed nodes. |
Roman Levenstein | dc1adac | 2008-04-07 10:06:32 +0000 | [diff] [blame] | 786 | DenseMap<SDOperandImpl, SDOperand>::iterator I = LegalizedNodes.find(Op); |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 787 | if (I != LegalizedNodes.end()) return I->second; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 788 | |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 789 | SDOperand Tmp1, Tmp2, Tmp3, Tmp4; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 790 | SDOperand Result = Op; |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 791 | bool isCustom = false; |
| 792 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 793 | switch (Node->getOpcode()) { |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 794 | case ISD::FrameIndex: |
| 795 | case ISD::EntryToken: |
| 796 | case ISD::Register: |
| 797 | case ISD::BasicBlock: |
| 798 | case ISD::TargetFrameIndex: |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 799 | case ISD::TargetJumpTable: |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 800 | case ISD::TargetConstant: |
Chris Lattner | 3181a77 | 2006-01-29 06:26:56 +0000 | [diff] [blame] | 801 | case ISD::TargetConstantFP: |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 802 | case ISD::TargetConstantPool: |
| 803 | case ISD::TargetGlobalAddress: |
Lauro Ramos Venancio | b3a0417 | 2007-04-20 21:38:10 +0000 | [diff] [blame] | 804 | case ISD::TargetGlobalTLSAddress: |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 805 | case ISD::TargetExternalSymbol: |
| 806 | case ISD::VALUETYPE: |
| 807 | case ISD::SRCVALUE: |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 808 | case ISD::MEMOPERAND: |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 809 | case ISD::STRING: |
| 810 | case ISD::CONDCODE: |
Duncan Sands | 276dcbd | 2008-03-21 09:14:45 +0000 | [diff] [blame] | 811 | case ISD::ARG_FLAGS: |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 812 | // Primitives must all be legal. |
Duncan Sands | a7c97a7 | 2007-10-16 09:07:20 +0000 | [diff] [blame] | 813 | assert(TLI.isOperationLegal(Node->getOpcode(), Node->getValueType(0)) && |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 814 | "This must be legal!"); |
| 815 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 816 | default: |
Chris Lattner | d73cc5d | 2005-05-14 06:34:48 +0000 | [diff] [blame] | 817 | if (Node->getOpcode() >= ISD::BUILTIN_OP_END) { |
| 818 | // If this is a target node, legalize it by legalizing the operands then |
| 819 | // passing it through. |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 820 | SmallVector<SDOperand, 8> Ops; |
Chris Lattner | c5d7d7c | 2006-05-17 18:00:08 +0000 | [diff] [blame] | 821 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) |
Chris Lattner | d73cc5d | 2005-05-14 06:34:48 +0000 | [diff] [blame] | 822 | Ops.push_back(LegalizeOp(Node->getOperand(i))); |
Chris Lattner | c5d7d7c | 2006-05-17 18:00:08 +0000 | [diff] [blame] | 823 | |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 824 | Result = DAG.UpdateNodeOperands(Result.getValue(0), &Ops[0], Ops.size()); |
Chris Lattner | d73cc5d | 2005-05-14 06:34:48 +0000 | [diff] [blame] | 825 | |
| 826 | for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) |
| 827 | AddLegalizedOperand(Op.getValue(i), Result.getValue(i)); |
| 828 | return Result.getValue(Op.ResNo); |
| 829 | } |
| 830 | // Otherwise this is an unhandled builtin node. splat. |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 831 | #ifndef NDEBUG |
Dan Gohman | 3983358 | 2007-06-04 16:17:33 +0000 | [diff] [blame] | 832 | cerr << "NODE: "; Node->dump(&DAG); cerr << "\n"; |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 833 | #endif |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 834 | assert(0 && "Do not know how to legalize this operator!"); |
| 835 | abort(); |
Lauro Ramos Venancio | 0d3b678 | 2007-04-20 23:02:39 +0000 | [diff] [blame] | 836 | case ISD::GLOBAL_OFFSET_TABLE: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 837 | case ISD::GlobalAddress: |
Lauro Ramos Venancio | b3a0417 | 2007-04-20 21:38:10 +0000 | [diff] [blame] | 838 | case ISD::GlobalTLSAddress: |
Chris Lattner | 03c0cf8 | 2005-01-07 21:45:56 +0000 | [diff] [blame] | 839 | case ISD::ExternalSymbol: |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 840 | case ISD::ConstantPool: |
| 841 | case ISD::JumpTable: // Nothing to do. |
Chris Lattner | 0c8fbe3 | 2005-11-17 06:41:44 +0000 | [diff] [blame] | 842 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 843 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 948c1b1 | 2006-01-28 08:31:04 +0000 | [diff] [blame] | 844 | case TargetLowering::Custom: |
| 845 | Tmp1 = TLI.LowerOperation(Op, DAG); |
| 846 | if (Tmp1.Val) Result = Tmp1; |
| 847 | // 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] | 848 | case TargetLowering::Legal: |
Chris Lattner | 0c8fbe3 | 2005-11-17 06:41:44 +0000 | [diff] [blame] | 849 | break; |
| 850 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 851 | break; |
Nate Begeman | bcc5f36 | 2007-01-29 22:58:52 +0000 | [diff] [blame] | 852 | case ISD::FRAMEADDR: |
| 853 | case ISD::RETURNADDR: |
| 854 | // The only option for these nodes is to custom lower them. If the target |
| 855 | // does not custom lower them, then return zero. |
| 856 | Tmp1 = TLI.LowerOperation(Op, DAG); |
| 857 | if (Tmp1.Val) |
| 858 | Result = Tmp1; |
| 859 | else |
| 860 | Result = DAG.getConstant(0, TLI.getPointerTy()); |
| 861 | break; |
Anton Korobeynikov | 055c544 | 2007-08-29 23:18:48 +0000 | [diff] [blame] | 862 | case ISD::FRAME_TO_ARGS_OFFSET: { |
Anton Korobeynikov | 066f7b4 | 2007-08-29 19:28:29 +0000 | [diff] [blame] | 863 | MVT::ValueType VT = Node->getValueType(0); |
| 864 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 865 | default: assert(0 && "This action is not supported yet!"); |
| 866 | case TargetLowering::Custom: |
| 867 | Result = TLI.LowerOperation(Op, DAG); |
| 868 | if (Result.Val) break; |
| 869 | // Fall Thru |
| 870 | case TargetLowering::Legal: |
| 871 | Result = DAG.getConstant(0, VT); |
| 872 | break; |
| 873 | } |
Anton Korobeynikov | 055c544 | 2007-08-29 23:18:48 +0000 | [diff] [blame] | 874 | } |
Anton Korobeynikov | 066f7b4 | 2007-08-29 19:28:29 +0000 | [diff] [blame] | 875 | break; |
Jim Laskey | 2bc210d | 2007-02-22 15:37:19 +0000 | [diff] [blame] | 876 | case ISD::EXCEPTIONADDR: { |
| 877 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 878 | MVT::ValueType VT = Node->getValueType(0); |
| 879 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 880 | default: assert(0 && "This action is not supported yet!"); |
| 881 | case TargetLowering::Expand: { |
Jim Laskey | 8782d48 | 2007-02-28 20:43:58 +0000 | [diff] [blame] | 882 | unsigned Reg = TLI.getExceptionAddressRegister(); |
Duncan Sands | b027fa0 | 2007-12-31 18:35:50 +0000 | [diff] [blame] | 883 | Result = DAG.getCopyFromReg(Tmp1, Reg, VT); |
Jim Laskey | 2bc210d | 2007-02-22 15:37:19 +0000 | [diff] [blame] | 884 | } |
| 885 | break; |
| 886 | case TargetLowering::Custom: |
| 887 | Result = TLI.LowerOperation(Op, DAG); |
| 888 | if (Result.Val) break; |
| 889 | // Fall Thru |
Chris Lattner | eb7f34f | 2007-04-27 17:12:52 +0000 | [diff] [blame] | 890 | case TargetLowering::Legal: { |
| 891 | SDOperand Ops[] = { DAG.getConstant(0, VT), Tmp1 }; |
| 892 | Result = DAG.getNode(ISD::MERGE_VALUES, DAG.getVTList(VT, MVT::Other), |
Duncan Sands | b027fa0 | 2007-12-31 18:35:50 +0000 | [diff] [blame] | 893 | Ops, 2); |
Jim Laskey | 2bc210d | 2007-02-22 15:37:19 +0000 | [diff] [blame] | 894 | break; |
| 895 | } |
| 896 | } |
Chris Lattner | eb7f34f | 2007-04-27 17:12:52 +0000 | [diff] [blame] | 897 | } |
Duncan Sands | b027fa0 | 2007-12-31 18:35:50 +0000 | [diff] [blame] | 898 | if (Result.Val->getNumValues() == 1) break; |
| 899 | |
| 900 | assert(Result.Val->getNumValues() == 2 && |
| 901 | "Cannot return more than two values!"); |
| 902 | |
| 903 | // Since we produced two values, make sure to remember that we |
| 904 | // legalized both of them. |
| 905 | Tmp1 = LegalizeOp(Result); |
| 906 | Tmp2 = LegalizeOp(Result.getValue(1)); |
| 907 | AddLegalizedOperand(Op.getValue(0), Tmp1); |
| 908 | AddLegalizedOperand(Op.getValue(1), Tmp2); |
| 909 | return Op.ResNo ? Tmp2 : Tmp1; |
Jim Laskey | 8782d48 | 2007-02-28 20:43:58 +0000 | [diff] [blame] | 910 | case ISD::EHSELECTION: { |
| 911 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 912 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 913 | MVT::ValueType VT = Node->getValueType(0); |
| 914 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 915 | default: assert(0 && "This action is not supported yet!"); |
| 916 | case TargetLowering::Expand: { |
| 917 | unsigned Reg = TLI.getExceptionSelectorRegister(); |
Duncan Sands | b027fa0 | 2007-12-31 18:35:50 +0000 | [diff] [blame] | 918 | Result = DAG.getCopyFromReg(Tmp2, Reg, VT); |
Jim Laskey | 8782d48 | 2007-02-28 20:43:58 +0000 | [diff] [blame] | 919 | } |
| 920 | break; |
| 921 | case TargetLowering::Custom: |
| 922 | Result = TLI.LowerOperation(Op, DAG); |
| 923 | if (Result.Val) break; |
| 924 | // Fall Thru |
Chris Lattner | eb7f34f | 2007-04-27 17:12:52 +0000 | [diff] [blame] | 925 | case TargetLowering::Legal: { |
| 926 | SDOperand Ops[] = { DAG.getConstant(0, VT), Tmp2 }; |
| 927 | Result = DAG.getNode(ISD::MERGE_VALUES, DAG.getVTList(VT, MVT::Other), |
Duncan Sands | b027fa0 | 2007-12-31 18:35:50 +0000 | [diff] [blame] | 928 | Ops, 2); |
Jim Laskey | 8782d48 | 2007-02-28 20:43:58 +0000 | [diff] [blame] | 929 | break; |
| 930 | } |
| 931 | } |
Chris Lattner | eb7f34f | 2007-04-27 17:12:52 +0000 | [diff] [blame] | 932 | } |
Duncan Sands | b027fa0 | 2007-12-31 18:35:50 +0000 | [diff] [blame] | 933 | if (Result.Val->getNumValues() == 1) break; |
| 934 | |
| 935 | assert(Result.Val->getNumValues() == 2 && |
| 936 | "Cannot return more than two values!"); |
| 937 | |
| 938 | // Since we produced two values, make sure to remember that we |
| 939 | // legalized both of them. |
| 940 | Tmp1 = LegalizeOp(Result); |
| 941 | Tmp2 = LegalizeOp(Result.getValue(1)); |
| 942 | AddLegalizedOperand(Op.getValue(0), Tmp1); |
| 943 | AddLegalizedOperand(Op.getValue(1), Tmp2); |
| 944 | return Op.ResNo ? Tmp2 : Tmp1; |
Nick Lewycky | 6d4b711 | 2007-07-14 15:11:14 +0000 | [diff] [blame] | 945 | case ISD::EH_RETURN: { |
Anton Korobeynikov | 2365f51 | 2007-07-14 14:06:15 +0000 | [diff] [blame] | 946 | MVT::ValueType VT = Node->getValueType(0); |
| 947 | // The only "good" option for this node is to custom lower it. |
| 948 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 949 | default: assert(0 && "This action is not supported at all!"); |
| 950 | case TargetLowering::Custom: |
| 951 | Result = TLI.LowerOperation(Op, DAG); |
| 952 | if (Result.Val) break; |
| 953 | // Fall Thru |
| 954 | case TargetLowering::Legal: |
| 955 | // Target does not know, how to lower this, lower to noop |
| 956 | Result = LegalizeOp(Node->getOperand(0)); |
| 957 | break; |
| 958 | } |
Nick Lewycky | 6d4b711 | 2007-07-14 15:11:14 +0000 | [diff] [blame] | 959 | } |
Anton Korobeynikov | 2365f51 | 2007-07-14 14:06:15 +0000 | [diff] [blame] | 960 | break; |
Chris Lattner | 08951a3 | 2005-09-02 01:15:01 +0000 | [diff] [blame] | 961 | case ISD::AssertSext: |
| 962 | case ISD::AssertZext: |
| 963 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 964 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
Chris Lattner | 08951a3 | 2005-09-02 01:15:01 +0000 | [diff] [blame] | 965 | break; |
Chris Lattner | 308575b | 2005-11-20 22:56:56 +0000 | [diff] [blame] | 966 | case ISD::MERGE_VALUES: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 967 | // Legalize eliminates MERGE_VALUES nodes. |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 968 | Result = Node->getOperand(Op.ResNo); |
| 969 | break; |
Chris Lattner | 69a5215 | 2005-01-14 22:38:01 +0000 | [diff] [blame] | 970 | case ISD::CopyFromReg: |
| 971 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 972 | Result = Op.getValue(0); |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 973 | if (Node->getNumValues() == 2) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 974 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 975 | } else { |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 976 | assert(Node->getNumValues() == 3 && "Invalid copyfromreg!"); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 977 | if (Node->getNumOperands() == 3) { |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 978 | Tmp2 = LegalizeOp(Node->getOperand(2)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 979 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1),Tmp2); |
| 980 | } else { |
| 981 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
| 982 | } |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 983 | AddLegalizedOperand(Op.getValue(2), Result.getValue(2)); |
| 984 | } |
Chris Lattner | 13c184d | 2005-01-28 06:27:38 +0000 | [diff] [blame] | 985 | // Since CopyFromReg produces two values, make sure to remember that we |
| 986 | // legalized both of them. |
| 987 | AddLegalizedOperand(Op.getValue(0), Result); |
| 988 | AddLegalizedOperand(Op.getValue(1), Result.getValue(1)); |
| 989 | return Result.getValue(Op.ResNo); |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 990 | case ISD::UNDEF: { |
| 991 | MVT::ValueType VT = Op.getValueType(); |
| 992 | switch (TLI.getOperationAction(ISD::UNDEF, VT)) { |
Nate Begeman | ea19cd5 | 2005-04-02 00:41:14 +0000 | [diff] [blame] | 993 | default: assert(0 && "This action is not supported yet!"); |
| 994 | case TargetLowering::Expand: |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 995 | if (MVT::isInteger(VT)) |
| 996 | Result = DAG.getConstant(0, VT); |
| 997 | else if (MVT::isFloatingPoint(VT)) |
Dale Johannesen | f41db21 | 2007-09-26 17:26:49 +0000 | [diff] [blame] | 998 | Result = DAG.getConstantFP(APFloat(APInt(MVT::getSizeInBits(VT), 0)), |
| 999 | VT); |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 1000 | else |
| 1001 | assert(0 && "Unknown value type!"); |
| 1002 | break; |
Nate Begeman | ea19cd5 | 2005-04-02 00:41:14 +0000 | [diff] [blame] | 1003 | case TargetLowering::Legal: |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 1004 | break; |
| 1005 | } |
| 1006 | break; |
| 1007 | } |
Chris Lattner | d1f04d4 | 2006-03-24 02:26:29 +0000 | [diff] [blame] | 1008 | |
Chris Lattner | 48b61a7 | 2006-03-28 00:40:33 +0000 | [diff] [blame] | 1009 | case ISD::INTRINSIC_W_CHAIN: |
| 1010 | case ISD::INTRINSIC_WO_CHAIN: |
| 1011 | case ISD::INTRINSIC_VOID: { |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1012 | SmallVector<SDOperand, 8> Ops; |
Chris Lattner | d1f04d4 | 2006-03-24 02:26:29 +0000 | [diff] [blame] | 1013 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) |
| 1014 | Ops.push_back(LegalizeOp(Node->getOperand(i))); |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1015 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 10d7fa6 | 2006-03-26 09:12:51 +0000 | [diff] [blame] | 1016 | |
| 1017 | // Allow the target to custom lower its intrinsics if it wants to. |
Chris Lattner | 48b61a7 | 2006-03-28 00:40:33 +0000 | [diff] [blame] | 1018 | if (TLI.getOperationAction(Node->getOpcode(), MVT::Other) == |
Chris Lattner | 10d7fa6 | 2006-03-26 09:12:51 +0000 | [diff] [blame] | 1019 | TargetLowering::Custom) { |
| 1020 | Tmp3 = TLI.LowerOperation(Result, DAG); |
| 1021 | if (Tmp3.Val) Result = Tmp3; |
Chris Lattner | 13fc2f1 | 2006-03-27 20:28:29 +0000 | [diff] [blame] | 1022 | } |
| 1023 | |
| 1024 | if (Result.Val->getNumValues() == 1) break; |
| 1025 | |
| 1026 | // Must have return value and chain result. |
| 1027 | assert(Result.Val->getNumValues() == 2 && |
| 1028 | "Cannot return more than two values!"); |
| 1029 | |
| 1030 | // Since loads produce two values, make sure to remember that we |
| 1031 | // legalized both of them. |
| 1032 | AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0)); |
| 1033 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
| 1034 | return Result.getValue(Op.ResNo); |
Chris Lattner | d1f04d4 | 2006-03-24 02:26:29 +0000 | [diff] [blame] | 1035 | } |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 1036 | |
| 1037 | case ISD::LOCATION: |
| 1038 | assert(Node->getNumOperands() == 5 && "Invalid LOCATION node!"); |
| 1039 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the input chain. |
| 1040 | |
| 1041 | switch (TLI.getOperationAction(ISD::LOCATION, MVT::Other)) { |
| 1042 | case TargetLowering::Promote: |
| 1043 | default: assert(0 && "This action is not supported yet!"); |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 1044 | case TargetLowering::Expand: { |
Jim Laskey | 44c3b9f | 2007-01-26 21:22:28 +0000 | [diff] [blame] | 1045 | MachineModuleInfo *MMI = DAG.getMachineModuleInfo(); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1046 | bool useDEBUG_LOC = TLI.isOperationLegal(ISD::DEBUG_LOC, MVT::Other); |
Jim Laskey | 1ee2925 | 2007-01-26 14:34:52 +0000 | [diff] [blame] | 1047 | bool useLABEL = TLI.isOperationLegal(ISD::LABEL, MVT::Other); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1048 | |
Jim Laskey | 44c3b9f | 2007-01-26 21:22:28 +0000 | [diff] [blame] | 1049 | if (MMI && (useDEBUG_LOC || useLABEL)) { |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1050 | const std::string &FName = |
| 1051 | cast<StringSDNode>(Node->getOperand(3))->getValue(); |
| 1052 | const std::string &DirName = |
| 1053 | cast<StringSDNode>(Node->getOperand(4))->getValue(); |
Jim Laskey | 44c3b9f | 2007-01-26 21:22:28 +0000 | [diff] [blame] | 1054 | unsigned SrcFile = MMI->RecordSource(DirName, FName); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1055 | |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 1056 | SmallVector<SDOperand, 8> Ops; |
Jim Laskey | e81aecb | 2005-12-21 20:51:37 +0000 | [diff] [blame] | 1057 | Ops.push_back(Tmp1); // chain |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1058 | SDOperand LineOp = Node->getOperand(1); |
| 1059 | SDOperand ColOp = Node->getOperand(2); |
| 1060 | |
| 1061 | if (useDEBUG_LOC) { |
| 1062 | Ops.push_back(LineOp); // line # |
| 1063 | Ops.push_back(ColOp); // col # |
| 1064 | Ops.push_back(DAG.getConstant(SrcFile, MVT::i32)); // source file id |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 1065 | Result = DAG.getNode(ISD::DEBUG_LOC, MVT::Other, &Ops[0], Ops.size()); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1066 | } else { |
Jim Laskey | d0e58e3 | 2006-02-15 19:34:44 +0000 | [diff] [blame] | 1067 | unsigned Line = cast<ConstantSDNode>(LineOp)->getValue(); |
| 1068 | unsigned Col = cast<ConstantSDNode>(ColOp)->getValue(); |
Evan Cheng | a647c92 | 2008-02-01 02:05:57 +0000 | [diff] [blame] | 1069 | unsigned ID = MMI->RecordSourceLine(Line, Col, SrcFile); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1070 | Ops.push_back(DAG.getConstant(ID, MVT::i32)); |
Evan Cheng | bb81d97 | 2008-01-31 09:59:15 +0000 | [diff] [blame] | 1071 | Ops.push_back(DAG.getConstant(0, MVT::i32)); // a debug label |
| 1072 | Result = DAG.getNode(ISD::LABEL, MVT::Other, &Ops[0], Ops.size()); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1073 | } |
Jim Laskey | e81aecb | 2005-12-21 20:51:37 +0000 | [diff] [blame] | 1074 | } else { |
| 1075 | Result = Tmp1; // chain |
| 1076 | } |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 1077 | break; |
Chris Lattner | e773673 | 2005-12-18 23:54:29 +0000 | [diff] [blame] | 1078 | } |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 1079 | case TargetLowering::Legal: |
Chris Lattner | 9ad17c9 | 2005-12-01 18:21:35 +0000 | [diff] [blame] | 1080 | if (Tmp1 != Node->getOperand(0) || |
| 1081 | getTypeAction(Node->getOperand(1).getValueType()) == Promote) { |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1082 | SmallVector<SDOperand, 8> Ops; |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 1083 | Ops.push_back(Tmp1); |
Chris Lattner | 9ad17c9 | 2005-12-01 18:21:35 +0000 | [diff] [blame] | 1084 | if (getTypeAction(Node->getOperand(1).getValueType()) == Legal) { |
| 1085 | Ops.push_back(Node->getOperand(1)); // line # must be legal. |
| 1086 | Ops.push_back(Node->getOperand(2)); // col # must be legal. |
| 1087 | } else { |
| 1088 | // Otherwise promote them. |
| 1089 | Ops.push_back(PromoteOp(Node->getOperand(1))); |
| 1090 | Ops.push_back(PromoteOp(Node->getOperand(2))); |
| 1091 | } |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 1092 | Ops.push_back(Node->getOperand(3)); // filename must be legal. |
| 1093 | Ops.push_back(Node->getOperand(4)); // working dir # must be legal. |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1094 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 1095 | } |
| 1096 | break; |
| 1097 | } |
| 1098 | break; |
Evan Cheng | a844bde | 2008-02-02 04:07:54 +0000 | [diff] [blame] | 1099 | |
| 1100 | case ISD::DECLARE: |
| 1101 | assert(Node->getNumOperands() == 3 && "Invalid DECLARE node!"); |
| 1102 | switch (TLI.getOperationAction(ISD::DECLARE, MVT::Other)) { |
| 1103 | default: assert(0 && "This action is not supported yet!"); |
| 1104 | case TargetLowering::Legal: |
| 1105 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1106 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the address. |
| 1107 | Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the variable. |
| 1108 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
| 1109 | break; |
Chris Lattner | e07415d | 2008-02-28 05:53:40 +0000 | [diff] [blame] | 1110 | case TargetLowering::Expand: |
| 1111 | Result = LegalizeOp(Node->getOperand(0)); |
| 1112 | break; |
Evan Cheng | a844bde | 2008-02-02 04:07:54 +0000 | [diff] [blame] | 1113 | } |
| 1114 | break; |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 1115 | |
| 1116 | case ISD::DEBUG_LOC: |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1117 | assert(Node->getNumOperands() == 4 && "Invalid DEBUG_LOC node!"); |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 1118 | switch (TLI.getOperationAction(ISD::DEBUG_LOC, MVT::Other)) { |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 1119 | default: assert(0 && "This action is not supported yet!"); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1120 | case TargetLowering::Legal: |
| 1121 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1122 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the line #. |
| 1123 | Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the col #. |
| 1124 | Tmp4 = LegalizeOp(Node->getOperand(3)); // Legalize the source file id. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1125 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3, Tmp4); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1126 | break; |
| 1127 | } |
| 1128 | break; |
| 1129 | |
Jim Laskey | 1ee2925 | 2007-01-26 14:34:52 +0000 | [diff] [blame] | 1130 | case ISD::LABEL: |
Evan Cheng | bb81d97 | 2008-01-31 09:59:15 +0000 | [diff] [blame] | 1131 | assert(Node->getNumOperands() == 3 && "Invalid LABEL node!"); |
Jim Laskey | 1ee2925 | 2007-01-26 14:34:52 +0000 | [diff] [blame] | 1132 | switch (TLI.getOperationAction(ISD::LABEL, MVT::Other)) { |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 1133 | default: assert(0 && "This action is not supported yet!"); |
| 1134 | case TargetLowering::Legal: |
| 1135 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1136 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the label id. |
Evan Cheng | bb81d97 | 2008-01-31 09:59:15 +0000 | [diff] [blame] | 1137 | Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the "flavor" operand. |
| 1138 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 1139 | break; |
Chris Lattner | a9569f1 | 2007-03-03 19:21:38 +0000 | [diff] [blame] | 1140 | case TargetLowering::Expand: |
| 1141 | Result = LegalizeOp(Node->getOperand(0)); |
| 1142 | break; |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 1143 | } |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 1144 | break; |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 1145 | |
Evan Cheng | 27b7db5 | 2008-03-08 00:58:38 +0000 | [diff] [blame] | 1146 | case ISD::PREFETCH: |
| 1147 | assert(Node->getNumOperands() == 4 && "Invalid Prefetch node!"); |
| 1148 | switch (TLI.getOperationAction(ISD::PREFETCH, MVT::Other)) { |
| 1149 | default: assert(0 && "This action is not supported yet!"); |
| 1150 | case TargetLowering::Legal: |
| 1151 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1152 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the address. |
| 1153 | Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the rw specifier. |
| 1154 | Tmp4 = LegalizeOp(Node->getOperand(3)); // Legalize locality specifier. |
| 1155 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3, Tmp4); |
| 1156 | break; |
| 1157 | case TargetLowering::Expand: |
| 1158 | // It's a noop. |
| 1159 | Result = LegalizeOp(Node->getOperand(0)); |
| 1160 | break; |
| 1161 | } |
| 1162 | break; |
| 1163 | |
Andrew Lenharth | 22c5c1b | 2008-02-16 01:24:58 +0000 | [diff] [blame] | 1164 | case ISD::MEMBARRIER: { |
| 1165 | assert(Node->getNumOperands() == 6 && "Invalid MemBarrier node!"); |
Andrew Lenharth | d497d9f | 2008-02-16 14:46:26 +0000 | [diff] [blame] | 1166 | switch (TLI.getOperationAction(ISD::MEMBARRIER, MVT::Other)) { |
| 1167 | default: assert(0 && "This action is not supported yet!"); |
| 1168 | case TargetLowering::Legal: { |
| 1169 | SDOperand Ops[6]; |
| 1170 | Ops[0] = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Duncan Sands | e90a615 | 2008-02-27 08:53:44 +0000 | [diff] [blame] | 1171 | for (int x = 1; x < 6; ++x) { |
| 1172 | Ops[x] = Node->getOperand(x); |
| 1173 | if (!isTypeLegal(Ops[x].getValueType())) |
| 1174 | Ops[x] = PromoteOp(Ops[x]); |
| 1175 | } |
Andrew Lenharth | d497d9f | 2008-02-16 14:46:26 +0000 | [diff] [blame] | 1176 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], 6); |
| 1177 | break; |
| 1178 | } |
| 1179 | case TargetLowering::Expand: |
| 1180 | //There is no libgcc call for this op |
| 1181 | Result = Node->getOperand(0); // Noop |
| 1182 | break; |
| 1183 | } |
Andrew Lenharth | 22c5c1b | 2008-02-16 01:24:58 +0000 | [diff] [blame] | 1184 | break; |
| 1185 | } |
| 1186 | |
Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 1187 | case ISD::ATOMIC_LCS: |
| 1188 | case ISD::ATOMIC_LAS: |
| 1189 | case ISD::ATOMIC_SWAP: { |
| 1190 | assert(((Node->getNumOperands() == 4 && Node->getOpcode() == ISD::ATOMIC_LCS) || |
| 1191 | (Node->getNumOperands() == 3 && Node->getOpcode() == ISD::ATOMIC_LAS) || |
| 1192 | (Node->getNumOperands() == 3 && Node->getOpcode() == ISD::ATOMIC_SWAP)) && |
Andrew Lenharth | 26ed869 | 2008-03-01 21:52:34 +0000 | [diff] [blame] | 1193 | "Invalid Atomic node!"); |
Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 1194 | int num = Node->getOpcode() == ISD::ATOMIC_LCS ? 4 : 3; |
Andrew Lenharth | 26ed869 | 2008-03-01 21:52:34 +0000 | [diff] [blame] | 1195 | SDOperand Ops[4]; |
| 1196 | for (int x = 0; x < num; ++x) |
| 1197 | Ops[x] = LegalizeOp(Node->getOperand(x)); |
| 1198 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], num); |
| 1199 | |
| 1200 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 1201 | default: assert(0 && "This action is not supported yet!"); |
Andrew Lenharth | 26ed869 | 2008-03-01 21:52:34 +0000 | [diff] [blame] | 1202 | case TargetLowering::Custom: |
| 1203 | Result = TLI.LowerOperation(Result, DAG); |
| 1204 | break; |
| 1205 | case TargetLowering::Legal: |
Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 1206 | break; |
| 1207 | } |
Andrew Lenharth | 26ed869 | 2008-03-01 21:52:34 +0000 | [diff] [blame] | 1208 | AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0)); |
| 1209 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
| 1210 | return Result.getValue(Op.ResNo); |
Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 1211 | } |
| 1212 | |
Scott Michel | c1513d2 | 2007-08-08 23:23:31 +0000 | [diff] [blame] | 1213 | case ISD::Constant: { |
| 1214 | ConstantSDNode *CN = cast<ConstantSDNode>(Node); |
| 1215 | unsigned opAction = |
| 1216 | TLI.getOperationAction(ISD::Constant, CN->getValueType(0)); |
| 1217 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1218 | // We know we don't need to expand constants here, constants only have one |
| 1219 | // value and we check that it is fine above. |
| 1220 | |
Scott Michel | c1513d2 | 2007-08-08 23:23:31 +0000 | [diff] [blame] | 1221 | if (opAction == TargetLowering::Custom) { |
| 1222 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 1223 | if (Tmp1.Val) |
| 1224 | Result = Tmp1; |
| 1225 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1226 | break; |
Scott Michel | c1513d2 | 2007-08-08 23:23:31 +0000 | [diff] [blame] | 1227 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1228 | case ISD::ConstantFP: { |
| 1229 | // Spill FP immediates to the constant pool if the target cannot directly |
| 1230 | // codegen them. Targets often have some immediate values that can be |
| 1231 | // efficiently generated into an FP register without a load. We explicitly |
| 1232 | // leave these constants as ConstantFP nodes for the target to deal with. |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1233 | ConstantFPSDNode *CFP = cast<ConstantFPSDNode>(Node); |
| 1234 | |
Chris Lattner | 3181a77 | 2006-01-29 06:26:56 +0000 | [diff] [blame] | 1235 | switch (TLI.getOperationAction(ISD::ConstantFP, CFP->getValueType(0))) { |
| 1236 | default: assert(0 && "This action is not supported yet!"); |
Nate Begeman | e179584 | 2008-02-14 08:57:00 +0000 | [diff] [blame] | 1237 | case TargetLowering::Legal: |
| 1238 | break; |
Chris Lattner | 3181a77 | 2006-01-29 06:26:56 +0000 | [diff] [blame] | 1239 | case TargetLowering::Custom: |
| 1240 | Tmp3 = TLI.LowerOperation(Result, DAG); |
| 1241 | if (Tmp3.Val) { |
| 1242 | Result = Tmp3; |
| 1243 | break; |
| 1244 | } |
| 1245 | // FALLTHROUGH |
Nate Begeman | e179584 | 2008-02-14 08:57:00 +0000 | [diff] [blame] | 1246 | case TargetLowering::Expand: { |
| 1247 | // Check to see if this FP immediate is already legal. |
| 1248 | bool isLegal = false; |
| 1249 | for (TargetLowering::legal_fpimm_iterator I = TLI.legal_fpimm_begin(), |
| 1250 | E = TLI.legal_fpimm_end(); I != E; ++I) { |
| 1251 | if (CFP->isExactlyValue(*I)) { |
| 1252 | isLegal = true; |
| 1253 | break; |
| 1254 | } |
| 1255 | } |
| 1256 | // If this is a legal constant, turn it into a TargetConstantFP node. |
| 1257 | if (isLegal) |
| 1258 | break; |
Evan Cheng | 279101e | 2006-12-12 22:19:28 +0000 | [diff] [blame] | 1259 | Result = ExpandConstantFP(CFP, true, DAG, TLI); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1260 | } |
Nate Begeman | e179584 | 2008-02-14 08:57:00 +0000 | [diff] [blame] | 1261 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1262 | break; |
| 1263 | } |
Chris Lattner | 040c11c | 2005-11-09 18:48:57 +0000 | [diff] [blame] | 1264 | case ISD::TokenFactor: |
| 1265 | if (Node->getNumOperands() == 2) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1266 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1267 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1268 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 1269 | } else if (Node->getNumOperands() == 3) { |
| 1270 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1271 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1272 | Tmp3 = LegalizeOp(Node->getOperand(2)); |
| 1273 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | 040c11c | 2005-11-09 18:48:57 +0000 | [diff] [blame] | 1274 | } else { |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1275 | SmallVector<SDOperand, 8> Ops; |
Chris Lattner | 040c11c | 2005-11-09 18:48:57 +0000 | [diff] [blame] | 1276 | // Legalize the operands. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1277 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) |
| 1278 | Ops.push_back(LegalizeOp(Node->getOperand(i))); |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1279 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | a385e9b | 2005-01-13 17:59:25 +0000 | [diff] [blame] | 1280 | } |
Chris Lattner | a385e9b | 2005-01-13 17:59:25 +0000 | [diff] [blame] | 1281 | break; |
Chris Lattner | fdfded5 | 2006-04-12 16:20:43 +0000 | [diff] [blame] | 1282 | |
| 1283 | case ISD::FORMAL_ARGUMENTS: |
Chris Lattner | f4ec817 | 2006-05-16 22:53:20 +0000 | [diff] [blame] | 1284 | case ISD::CALL: |
Chris Lattner | fdfded5 | 2006-04-12 16:20:43 +0000 | [diff] [blame] | 1285 | // The only option for this is to custom lower it. |
Chris Lattner | b248e16 | 2006-05-17 17:55:45 +0000 | [diff] [blame] | 1286 | Tmp3 = TLI.LowerOperation(Result.getValue(0), DAG); |
| 1287 | assert(Tmp3.Val && "Target didn't custom lower this node!"); |
Dale Johannesen | 0ea0356 | 2008-03-05 19:14:03 +0000 | [diff] [blame] | 1288 | // A call within a calling sequence must be legalized to something |
| 1289 | // other than the normal CALLSEQ_END. Violating this gets Legalize |
| 1290 | // into an infinite loop. |
| 1291 | assert ((!IsLegalizingCall || |
| 1292 | Node->getOpcode() != ISD::CALL || |
| 1293 | Tmp3.Val->getOpcode() != ISD::CALLSEQ_END) && |
| 1294 | "Nested CALLSEQ_START..CALLSEQ_END not supported."); |
Bill Wendling | 0f8d9c0 | 2007-11-13 00:44:25 +0000 | [diff] [blame] | 1295 | |
| 1296 | // The number of incoming and outgoing values should match; unless the final |
| 1297 | // outgoing value is a flag. |
| 1298 | assert((Tmp3.Val->getNumValues() == Result.Val->getNumValues() || |
| 1299 | (Tmp3.Val->getNumValues() == Result.Val->getNumValues() + 1 && |
| 1300 | Tmp3.Val->getValueType(Tmp3.Val->getNumValues() - 1) == |
| 1301 | MVT::Flag)) && |
Chris Lattner | b248e16 | 2006-05-17 17:55:45 +0000 | [diff] [blame] | 1302 | "Lowering call/formal_arguments produced unexpected # results!"); |
Chris Lattner | e2e4173 | 2006-05-16 05:49:56 +0000 | [diff] [blame] | 1303 | |
Chris Lattner | f4ec817 | 2006-05-16 22:53:20 +0000 | [diff] [blame] | 1304 | // Since CALL/FORMAL_ARGUMENTS nodes produce multiple values, make sure to |
Chris Lattner | e2e4173 | 2006-05-16 05:49:56 +0000 | [diff] [blame] | 1305 | // remember that we legalized all of them, so it doesn't get relegalized. |
Chris Lattner | b248e16 | 2006-05-17 17:55:45 +0000 | [diff] [blame] | 1306 | for (unsigned i = 0, e = Tmp3.Val->getNumValues(); i != e; ++i) { |
Bill Wendling | 0f8d9c0 | 2007-11-13 00:44:25 +0000 | [diff] [blame] | 1307 | if (Tmp3.Val->getValueType(i) == MVT::Flag) |
| 1308 | continue; |
Chris Lattner | b248e16 | 2006-05-17 17:55:45 +0000 | [diff] [blame] | 1309 | Tmp1 = LegalizeOp(Tmp3.getValue(i)); |
Chris Lattner | e2e4173 | 2006-05-16 05:49:56 +0000 | [diff] [blame] | 1310 | if (Op.ResNo == i) |
| 1311 | Tmp2 = Tmp1; |
| 1312 | AddLegalizedOperand(SDOperand(Node, i), Tmp1); |
| 1313 | } |
| 1314 | return Tmp2; |
Christopher Lamb | 557c363 | 2007-07-26 07:34:40 +0000 | [diff] [blame] | 1315 | case ISD::EXTRACT_SUBREG: { |
| 1316 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1317 | ConstantSDNode *idx = dyn_cast<ConstantSDNode>(Node->getOperand(1)); |
| 1318 | assert(idx && "Operand must be a constant"); |
| 1319 | Tmp2 = DAG.getTargetConstant(idx->getValue(), idx->getValueType(0)); |
| 1320 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 1321 | } |
| 1322 | break; |
| 1323 | case ISD::INSERT_SUBREG: { |
| 1324 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1325 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1326 | ConstantSDNode *idx = dyn_cast<ConstantSDNode>(Node->getOperand(2)); |
| 1327 | assert(idx && "Operand must be a constant"); |
| 1328 | Tmp3 = DAG.getTargetConstant(idx->getValue(), idx->getValueType(0)); |
| 1329 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
| 1330 | } |
| 1331 | break; |
Chris Lattner | b2827b0 | 2006-03-19 00:52:58 +0000 | [diff] [blame] | 1332 | case ISD::BUILD_VECTOR: |
| 1333 | switch (TLI.getOperationAction(ISD::BUILD_VECTOR, Node->getValueType(0))) { |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1334 | default: assert(0 && "This action is not supported yet!"); |
| 1335 | case TargetLowering::Custom: |
| 1336 | Tmp3 = TLI.LowerOperation(Result, DAG); |
| 1337 | if (Tmp3.Val) { |
| 1338 | Result = Tmp3; |
| 1339 | break; |
| 1340 | } |
| 1341 | // FALLTHROUGH |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 1342 | case TargetLowering::Expand: |
| 1343 | Result = ExpandBUILD_VECTOR(Result.Val); |
Chris Lattner | b2827b0 | 2006-03-19 00:52:58 +0000 | [diff] [blame] | 1344 | break; |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1345 | } |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1346 | break; |
| 1347 | case ISD::INSERT_VECTOR_ELT: |
| 1348 | Tmp1 = LegalizeOp(Node->getOperand(0)); // InVec |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1349 | Tmp3 = LegalizeOp(Node->getOperand(2)); // InEltNo |
Nate Begeman | 0325d90 | 2008-02-13 06:43:04 +0000 | [diff] [blame] | 1350 | |
| 1351 | // The type of the value to insert may not be legal, even though the vector |
| 1352 | // type is legal. Legalize/Promote accordingly. We do not handle Expand |
| 1353 | // here. |
| 1354 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 1355 | default: assert(0 && "Cannot expand insert element operand"); |
| 1356 | case Legal: Tmp2 = LegalizeOp(Node->getOperand(1)); break; |
| 1357 | case Promote: Tmp2 = PromoteOp(Node->getOperand(1)); break; |
| 1358 | } |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1359 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
| 1360 | |
| 1361 | switch (TLI.getOperationAction(ISD::INSERT_VECTOR_ELT, |
| 1362 | Node->getValueType(0))) { |
| 1363 | default: assert(0 && "This action is not supported yet!"); |
| 1364 | case TargetLowering::Legal: |
| 1365 | break; |
| 1366 | case TargetLowering::Custom: |
Nate Begeman | 2281a99 | 2008-01-05 20:47:37 +0000 | [diff] [blame] | 1367 | Tmp4 = TLI.LowerOperation(Result, DAG); |
| 1368 | if (Tmp4.Val) { |
| 1369 | Result = Tmp4; |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1370 | break; |
| 1371 | } |
| 1372 | // FALLTHROUGH |
| 1373 | case TargetLowering::Expand: { |
Chris Lattner | 8d5a894 | 2006-04-17 19:21:01 +0000 | [diff] [blame] | 1374 | // If the insert index is a constant, codegen this as a scalar_to_vector, |
| 1375 | // then a shuffle that inserts it into the right position in the vector. |
| 1376 | if (ConstantSDNode *InsertPos = dyn_cast<ConstantSDNode>(Tmp3)) { |
Nate Begeman | 0325d90 | 2008-02-13 06:43:04 +0000 | [diff] [blame] | 1377 | // SCALAR_TO_VECTOR requires that the type of the value being inserted |
| 1378 | // match the element type of the vector being created. |
| 1379 | if (Tmp2.getValueType() == |
| 1380 | MVT::getVectorElementType(Op.getValueType())) { |
| 1381 | SDOperand ScVec = DAG.getNode(ISD::SCALAR_TO_VECTOR, |
| 1382 | Tmp1.getValueType(), Tmp2); |
| 1383 | |
| 1384 | unsigned NumElts = MVT::getVectorNumElements(Tmp1.getValueType()); |
| 1385 | MVT::ValueType ShufMaskVT = MVT::getIntVectorWithNumElements(NumElts); |
| 1386 | MVT::ValueType ShufMaskEltVT = MVT::getVectorElementType(ShufMaskVT); |
| 1387 | |
| 1388 | // We generate a shuffle of InVec and ScVec, so the shuffle mask |
| 1389 | // should be 0,1,2,3,4,5... with the appropriate element replaced with |
| 1390 | // elt 0 of the RHS. |
| 1391 | SmallVector<SDOperand, 8> ShufOps; |
| 1392 | for (unsigned i = 0; i != NumElts; ++i) { |
| 1393 | if (i != InsertPos->getValue()) |
| 1394 | ShufOps.push_back(DAG.getConstant(i, ShufMaskEltVT)); |
| 1395 | else |
| 1396 | ShufOps.push_back(DAG.getConstant(NumElts, ShufMaskEltVT)); |
| 1397 | } |
| 1398 | SDOperand ShufMask = DAG.getNode(ISD::BUILD_VECTOR, ShufMaskVT, |
| 1399 | &ShufOps[0], ShufOps.size()); |
| 1400 | |
| 1401 | Result = DAG.getNode(ISD::VECTOR_SHUFFLE, Tmp1.getValueType(), |
| 1402 | Tmp1, ScVec, ShufMask); |
| 1403 | Result = LegalizeOp(Result); |
| 1404 | break; |
Chris Lattner | 8d5a894 | 2006-04-17 19:21:01 +0000 | [diff] [blame] | 1405 | } |
Chris Lattner | 8d5a894 | 2006-04-17 19:21:01 +0000 | [diff] [blame] | 1406 | } |
| 1407 | |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1408 | // If the target doesn't support this, we have to spill the input vector |
| 1409 | // to a temporary stack slot, update the element, then reload it. This is |
| 1410 | // badness. We could also load the value into a vector register (either |
| 1411 | // with a "move to register" or "extload into register" instruction, then |
| 1412 | // permute it into place, if the idx is a constant and if the idx is |
| 1413 | // supported by the target. |
Evan Cheng | f6bf87f | 2006-04-08 01:46:37 +0000 | [diff] [blame] | 1414 | MVT::ValueType VT = Tmp1.getValueType(); |
Nate Begeman | 0325d90 | 2008-02-13 06:43:04 +0000 | [diff] [blame] | 1415 | MVT::ValueType EltVT = MVT::getVectorElementType(VT); |
Evan Cheng | f6bf87f | 2006-04-08 01:46:37 +0000 | [diff] [blame] | 1416 | MVT::ValueType IdxVT = Tmp3.getValueType(); |
| 1417 | MVT::ValueType PtrVT = TLI.getPointerTy(); |
Chris Lattner | 85dd3be | 2007-10-15 17:48:57 +0000 | [diff] [blame] | 1418 | SDOperand StackPtr = DAG.CreateStackTemporary(VT); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 1419 | |
Dan Gohman | bbbbb9c | 2008-02-11 18:58:42 +0000 | [diff] [blame] | 1420 | FrameIndexSDNode *StackPtrFI = cast<FrameIndexSDNode>(StackPtr.Val); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 1421 | int SPFI = StackPtrFI->getIndex(); |
| 1422 | |
Evan Cheng | eb0b461 | 2006-03-31 01:27:51 +0000 | [diff] [blame] | 1423 | // Store the vector. |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 1424 | SDOperand Ch = DAG.getStore(DAG.getEntryNode(), Tmp1, StackPtr, |
Dan Gohman | 3069b87 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 1425 | PseudoSourceValue::getFixedStack(), |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 1426 | SPFI); |
Evan Cheng | eb0b461 | 2006-03-31 01:27:51 +0000 | [diff] [blame] | 1427 | |
| 1428 | // Truncate or zero extend offset to target pointer type. |
Evan Cheng | f6bf87f | 2006-04-08 01:46:37 +0000 | [diff] [blame] | 1429 | unsigned CastOpc = (IdxVT > PtrVT) ? ISD::TRUNCATE : ISD::ZERO_EXTEND; |
| 1430 | Tmp3 = DAG.getNode(CastOpc, PtrVT, Tmp3); |
Evan Cheng | eb0b461 | 2006-03-31 01:27:51 +0000 | [diff] [blame] | 1431 | // Add the offset to the index. |
Evan Cheng | f6bf87f | 2006-04-08 01:46:37 +0000 | [diff] [blame] | 1432 | unsigned EltSize = MVT::getSizeInBits(EltVT)/8; |
| 1433 | Tmp3 = DAG.getNode(ISD::MUL, IdxVT, Tmp3,DAG.getConstant(EltSize, IdxVT)); |
| 1434 | SDOperand StackPtr2 = DAG.getNode(ISD::ADD, IdxVT, Tmp3, StackPtr); |
Evan Cheng | eb0b461 | 2006-03-31 01:27:51 +0000 | [diff] [blame] | 1435 | // Store the scalar value. |
Nate Begeman | 0325d90 | 2008-02-13 06:43:04 +0000 | [diff] [blame] | 1436 | Ch = DAG.getTruncStore(Ch, Tmp2, StackPtr2, |
| 1437 | PseudoSourceValue::getFixedStack(), SPFI, EltVT); |
Evan Cheng | eb0b461 | 2006-03-31 01:27:51 +0000 | [diff] [blame] | 1438 | // Load the updated vector. |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 1439 | Result = DAG.getLoad(VT, Ch, StackPtr, |
Dan Gohman | 3069b87 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 1440 | PseudoSourceValue::getFixedStack(), SPFI); |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 1441 | break; |
| 1442 | } |
| 1443 | } |
| 1444 | break; |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 1445 | case ISD::SCALAR_TO_VECTOR: |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 1446 | if (!TLI.isTypeLegal(Node->getOperand(0).getValueType())) { |
| 1447 | Result = LegalizeOp(ExpandSCALAR_TO_VECTOR(Node)); |
| 1448 | break; |
| 1449 | } |
| 1450 | |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 1451 | Tmp1 = LegalizeOp(Node->getOperand(0)); // InVal |
| 1452 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 1453 | switch (TLI.getOperationAction(ISD::SCALAR_TO_VECTOR, |
| 1454 | Node->getValueType(0))) { |
| 1455 | default: assert(0 && "This action is not supported yet!"); |
| 1456 | case TargetLowering::Legal: |
| 1457 | break; |
Chris Lattner | 4d3abee | 2006-03-19 06:47:21 +0000 | [diff] [blame] | 1458 | case TargetLowering::Custom: |
| 1459 | Tmp3 = TLI.LowerOperation(Result, DAG); |
| 1460 | if (Tmp3.Val) { |
| 1461 | Result = Tmp3; |
| 1462 | break; |
| 1463 | } |
| 1464 | // FALLTHROUGH |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 1465 | case TargetLowering::Expand: |
| 1466 | Result = LegalizeOp(ExpandSCALAR_TO_VECTOR(Node)); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 1467 | break; |
| 1468 | } |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 1469 | break; |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 1470 | case ISD::VECTOR_SHUFFLE: |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 1471 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the input vectors, |
| 1472 | Tmp2 = LegalizeOp(Node->getOperand(1)); // but not the shuffle mask. |
| 1473 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
| 1474 | |
| 1475 | // Allow targets to custom lower the SHUFFLEs they support. |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 1476 | switch (TLI.getOperationAction(ISD::VECTOR_SHUFFLE,Result.getValueType())) { |
| 1477 | default: assert(0 && "Unknown operation action!"); |
| 1478 | case TargetLowering::Legal: |
| 1479 | assert(isShuffleLegal(Result.getValueType(), Node->getOperand(2)) && |
| 1480 | "vector shuffle should not be created if not legal!"); |
| 1481 | break; |
| 1482 | case TargetLowering::Custom: |
Evan Cheng | 18dd6d0 | 2006-04-05 06:07:11 +0000 | [diff] [blame] | 1483 | Tmp3 = TLI.LowerOperation(Result, DAG); |
| 1484 | if (Tmp3.Val) { |
| 1485 | Result = Tmp3; |
| 1486 | break; |
| 1487 | } |
| 1488 | // FALLTHROUGH |
| 1489 | case TargetLowering::Expand: { |
| 1490 | MVT::ValueType VT = Node->getValueType(0); |
Dan Gohman | 51eaa86 | 2007-06-14 22:58:02 +0000 | [diff] [blame] | 1491 | MVT::ValueType EltVT = MVT::getVectorElementType(VT); |
Evan Cheng | 18dd6d0 | 2006-04-05 06:07:11 +0000 | [diff] [blame] | 1492 | MVT::ValueType PtrVT = TLI.getPointerTy(); |
| 1493 | SDOperand Mask = Node->getOperand(2); |
| 1494 | unsigned NumElems = Mask.getNumOperands(); |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 1495 | SmallVector<SDOperand,8> Ops; |
Evan Cheng | 18dd6d0 | 2006-04-05 06:07:11 +0000 | [diff] [blame] | 1496 | for (unsigned i = 0; i != NumElems; ++i) { |
| 1497 | SDOperand Arg = Mask.getOperand(i); |
| 1498 | if (Arg.getOpcode() == ISD::UNDEF) { |
| 1499 | Ops.push_back(DAG.getNode(ISD::UNDEF, EltVT)); |
| 1500 | } else { |
| 1501 | assert(isa<ConstantSDNode>(Arg) && "Invalid VECTOR_SHUFFLE mask!"); |
| 1502 | unsigned Idx = cast<ConstantSDNode>(Arg)->getValue(); |
| 1503 | if (Idx < NumElems) |
| 1504 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, EltVT, Tmp1, |
| 1505 | DAG.getConstant(Idx, PtrVT))); |
| 1506 | else |
| 1507 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, EltVT, Tmp2, |
| 1508 | DAG.getConstant(Idx - NumElems, PtrVT))); |
| 1509 | } |
| 1510 | } |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 1511 | Result = DAG.getNode(ISD::BUILD_VECTOR, VT, &Ops[0], Ops.size()); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 1512 | break; |
Evan Cheng | 18dd6d0 | 2006-04-05 06:07:11 +0000 | [diff] [blame] | 1513 | } |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 1514 | case TargetLowering::Promote: { |
| 1515 | // Change base type to a different vector type. |
| 1516 | MVT::ValueType OVT = Node->getValueType(0); |
| 1517 | MVT::ValueType NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT); |
| 1518 | |
| 1519 | // Cast the two input vectors. |
| 1520 | Tmp1 = DAG.getNode(ISD::BIT_CONVERT, NVT, Tmp1); |
| 1521 | Tmp2 = DAG.getNode(ISD::BIT_CONVERT, NVT, Tmp2); |
| 1522 | |
| 1523 | // Convert the shuffle mask to the right # elements. |
| 1524 | Tmp3 = SDOperand(isShuffleLegal(OVT, Node->getOperand(2)), 0); |
| 1525 | assert(Tmp3.Val && "Shuffle not legal?"); |
| 1526 | Result = DAG.getNode(ISD::VECTOR_SHUFFLE, NVT, Tmp1, Tmp2, Tmp3); |
| 1527 | Result = DAG.getNode(ISD::BIT_CONVERT, OVT, Result); |
| 1528 | break; |
| 1529 | } |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 1530 | } |
| 1531 | break; |
Chris Lattner | 384504c | 2006-03-21 20:44:12 +0000 | [diff] [blame] | 1532 | |
| 1533 | case ISD::EXTRACT_VECTOR_ELT: |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 1534 | Tmp1 = Node->getOperand(0); |
Chris Lattner | 384504c | 2006-03-21 20:44:12 +0000 | [diff] [blame] | 1535 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1536 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 1537 | Result = ExpandEXTRACT_VECTOR_ELT(Result); |
Chris Lattner | 384504c | 2006-03-21 20:44:12 +0000 | [diff] [blame] | 1538 | break; |
| 1539 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 1540 | case ISD::EXTRACT_SUBVECTOR: |
| 1541 | Tmp1 = Node->getOperand(0); |
| 1542 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1543 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 1544 | Result = ExpandEXTRACT_SUBVECTOR(Result); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 1545 | break; |
| 1546 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1547 | case ISD::CALLSEQ_START: { |
| 1548 | SDNode *CallEnd = FindCallEndFromCallStart(Node); |
| 1549 | |
| 1550 | // Recursively Legalize all of the inputs of the call end that do not lead |
| 1551 | // to this call start. This ensures that any libcalls that need be inserted |
| 1552 | // are inserted *before* the CALLSEQ_START. |
Chris Lattner | 00755df | 2007-02-04 00:27:56 +0000 | [diff] [blame] | 1553 | {SmallPtrSet<SDNode*, 32> NodesLeadingTo; |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1554 | for (unsigned i = 0, e = CallEnd->getNumOperands(); i != e; ++i) |
Chris Lattner | c9cf4f1 | 2006-07-26 23:55:56 +0000 | [diff] [blame] | 1555 | LegalizeAllNodesNotLeadingTo(CallEnd->getOperand(i).Val, Node, |
| 1556 | NodesLeadingTo); |
| 1557 | } |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1558 | |
| 1559 | // Now that we legalized all of the inputs (which may have inserted |
| 1560 | // libcalls) create the new CALLSEQ_START node. |
| 1561 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1562 | |
| 1563 | // Merge in the last call, to ensure that this call start after the last |
| 1564 | // call ended. |
Chris Lattner | c5d7d7c | 2006-05-17 18:00:08 +0000 | [diff] [blame] | 1565 | if (LastCALLSEQ_END.getOpcode() != ISD::EntryToken) { |
Chris Lattner | b248e16 | 2006-05-17 17:55:45 +0000 | [diff] [blame] | 1566 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1567 | Tmp1 = LegalizeOp(Tmp1); |
| 1568 | } |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1569 | |
| 1570 | // Do not try to legalize the target-specific arguments (#1+). |
| 1571 | if (Tmp1 != Node->getOperand(0)) { |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1572 | SmallVector<SDOperand, 8> Ops(Node->op_begin(), Node->op_end()); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1573 | Ops[0] = Tmp1; |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1574 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1575 | } |
| 1576 | |
| 1577 | // Remember that the CALLSEQ_START is legalized. |
Chris Lattner | 4b653a0 | 2006-02-14 00:55:02 +0000 | [diff] [blame] | 1578 | AddLegalizedOperand(Op.getValue(0), Result); |
| 1579 | if (Node->getNumValues() == 2) // If this has a flag result, remember it. |
| 1580 | AddLegalizedOperand(Op.getValue(1), Result.getValue(1)); |
| 1581 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1582 | // Now that the callseq_start and all of the non-call nodes above this call |
| 1583 | // sequence have been legalized, legalize the call itself. During this |
| 1584 | // process, no libcalls can/will be inserted, guaranteeing that no calls |
| 1585 | // can overlap. |
| 1586 | assert(!IsLegalizingCall && "Inconsistent sequentialization of calls!"); |
| 1587 | SDOperand InCallSEQ = LastCALLSEQ_END; |
| 1588 | // Note that we are selecting this call! |
| 1589 | LastCALLSEQ_END = SDOperand(CallEnd, 0); |
| 1590 | IsLegalizingCall = true; |
| 1591 | |
| 1592 | // Legalize the call, starting from the CALLSEQ_END. |
| 1593 | LegalizeOp(LastCALLSEQ_END); |
| 1594 | assert(!IsLegalizingCall && "CALLSEQ_END should have cleared this!"); |
| 1595 | return Result; |
| 1596 | } |
Chris Lattner | 16cd04d | 2005-05-12 23:24:06 +0000 | [diff] [blame] | 1597 | case ISD::CALLSEQ_END: |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1598 | // If the CALLSEQ_START node hasn't been legalized first, legalize it. This |
| 1599 | // will cause this node to be legalized as well as handling libcalls right. |
| 1600 | if (LastCALLSEQ_END.Val != Node) { |
| 1601 | LegalizeOp(SDOperand(FindCallStartFromCallEnd(Node), 0)); |
Roman Levenstein | dc1adac | 2008-04-07 10:06:32 +0000 | [diff] [blame] | 1602 | DenseMap<SDOperandImpl, SDOperand>::iterator I = LegalizedNodes.find(Op); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1603 | assert(I != LegalizedNodes.end() && |
| 1604 | "Legalizing the call start should have legalized this node!"); |
| 1605 | return I->second; |
| 1606 | } |
| 1607 | |
| 1608 | // Otherwise, the call start has been legalized and everything is going |
| 1609 | // according to plan. Just legalize ourselves normally here. |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1610 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | 70814bc | 2006-01-29 07:58:15 +0000 | [diff] [blame] | 1611 | // Do not try to legalize the target-specific arguments (#1+), except for |
| 1612 | // an optional flag input. |
| 1613 | if (Node->getOperand(Node->getNumOperands()-1).getValueType() != MVT::Flag){ |
| 1614 | if (Tmp1 != Node->getOperand(0)) { |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1615 | SmallVector<SDOperand, 8> Ops(Node->op_begin(), Node->op_end()); |
Chris Lattner | 70814bc | 2006-01-29 07:58:15 +0000 | [diff] [blame] | 1616 | Ops[0] = Tmp1; |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1617 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 70814bc | 2006-01-29 07:58:15 +0000 | [diff] [blame] | 1618 | } |
| 1619 | } else { |
| 1620 | Tmp2 = LegalizeOp(Node->getOperand(Node->getNumOperands()-1)); |
| 1621 | if (Tmp1 != Node->getOperand(0) || |
| 1622 | Tmp2 != Node->getOperand(Node->getNumOperands()-1)) { |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1623 | SmallVector<SDOperand, 8> Ops(Node->op_begin(), Node->op_end()); |
Chris Lattner | 70814bc | 2006-01-29 07:58:15 +0000 | [diff] [blame] | 1624 | Ops[0] = Tmp1; |
| 1625 | Ops.back() = Tmp2; |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1626 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 70814bc | 2006-01-29 07:58:15 +0000 | [diff] [blame] | 1627 | } |
Chris Lattner | 6a54289 | 2006-01-24 05:48:21 +0000 | [diff] [blame] | 1628 | } |
Chris Lattner | 4b653a0 | 2006-02-14 00:55:02 +0000 | [diff] [blame] | 1629 | assert(IsLegalizingCall && "Call sequence imbalance between start/end?"); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1630 | // This finishes up call legalization. |
| 1631 | IsLegalizingCall = false; |
Chris Lattner | 4b653a0 | 2006-02-14 00:55:02 +0000 | [diff] [blame] | 1632 | |
| 1633 | // If the CALLSEQ_END node has a flag, remember that we legalized it. |
| 1634 | AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0)); |
| 1635 | if (Node->getNumValues() == 2) |
| 1636 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
| 1637 | return Result.getValue(Op.ResNo); |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1638 | case ISD::DYNAMIC_STACKALLOC: { |
Evan Cheng | 61bbbab | 2007-08-16 23:50:06 +0000 | [diff] [blame] | 1639 | MVT::ValueType VT = Node->getValueType(0); |
Chris Lattner | fa404e8 | 2005-01-09 19:03:49 +0000 | [diff] [blame] | 1640 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1641 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the size. |
| 1642 | Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the alignment. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1643 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | fa404e8 | 2005-01-09 19:03:49 +0000 | [diff] [blame] | 1644 | |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1645 | Tmp1 = Result.getValue(0); |
Chris Lattner | 5f65229 | 2006-01-15 08:43:08 +0000 | [diff] [blame] | 1646 | Tmp2 = Result.getValue(1); |
Evan Cheng | 61bbbab | 2007-08-16 23:50:06 +0000 | [diff] [blame] | 1647 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1648 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1649 | case TargetLowering::Expand: { |
| 1650 | unsigned SPReg = TLI.getStackPointerRegisterToSaveRestore(); |
| 1651 | assert(SPReg && "Target cannot require DYNAMIC_STACKALLOC expansion and" |
| 1652 | " not tell us which reg is the stack pointer!"); |
| 1653 | SDOperand Chain = Tmp1.getOperand(0); |
Bill Wendling | 0f8d9c0 | 2007-11-13 00:44:25 +0000 | [diff] [blame] | 1654 | |
| 1655 | // Chain the dynamic stack allocation so that it doesn't modify the stack |
| 1656 | // pointer when other instructions are using the stack. |
| 1657 | Chain = DAG.getCALLSEQ_START(Chain, |
| 1658 | DAG.getConstant(0, TLI.getPointerTy())); |
| 1659 | |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1660 | SDOperand Size = Tmp2.getOperand(1); |
Evan Cheng | 61bbbab | 2007-08-16 23:50:06 +0000 | [diff] [blame] | 1661 | SDOperand SP = DAG.getCopyFromReg(Chain, SPReg, VT); |
| 1662 | Chain = SP.getValue(1); |
| 1663 | unsigned Align = cast<ConstantSDNode>(Tmp3)->getValue(); |
| 1664 | unsigned StackAlign = |
| 1665 | TLI.getTargetMachine().getFrameInfo()->getStackAlignment(); |
| 1666 | if (Align > StackAlign) |
Evan Cheng | 3e20bba | 2007-08-17 18:02:22 +0000 | [diff] [blame] | 1667 | SP = DAG.getNode(ISD::AND, VT, SP, |
| 1668 | DAG.getConstant(-(uint64_t)Align, VT)); |
Evan Cheng | 61bbbab | 2007-08-16 23:50:06 +0000 | [diff] [blame] | 1669 | Tmp1 = DAG.getNode(ISD::SUB, VT, SP, Size); // Value |
Bill Wendling | 0f8d9c0 | 2007-11-13 00:44:25 +0000 | [diff] [blame] | 1670 | Chain = DAG.getCopyToReg(Chain, SPReg, Tmp1); // Output chain |
| 1671 | |
| 1672 | Tmp2 = |
| 1673 | DAG.getCALLSEQ_END(Chain, |
| 1674 | DAG.getConstant(0, TLI.getPointerTy()), |
| 1675 | DAG.getConstant(0, TLI.getPointerTy()), |
| 1676 | SDOperand()); |
| 1677 | |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1678 | Tmp1 = LegalizeOp(Tmp1); |
| 1679 | Tmp2 = LegalizeOp(Tmp2); |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1680 | break; |
| 1681 | } |
| 1682 | case TargetLowering::Custom: |
Chris Lattner | 5f65229 | 2006-01-15 08:43:08 +0000 | [diff] [blame] | 1683 | Tmp3 = TLI.LowerOperation(Tmp1, DAG); |
| 1684 | if (Tmp3.Val) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1685 | Tmp1 = LegalizeOp(Tmp3); |
| 1686 | Tmp2 = LegalizeOp(Tmp3.getValue(1)); |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1687 | } |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1688 | break; |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1689 | case TargetLowering::Legal: |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1690 | break; |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1691 | } |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1692 | // Since this op produce two values, make sure to remember that we |
| 1693 | // legalized both of them. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1694 | AddLegalizedOperand(SDOperand(Node, 0), Tmp1); |
| 1695 | AddLegalizedOperand(SDOperand(Node, 1), Tmp2); |
Chris Lattner | 903d278 | 2006-01-15 08:54:32 +0000 | [diff] [blame] | 1696 | return Op.ResNo ? Tmp2 : Tmp1; |
Evan Cheng | a7dce3c | 2006-01-11 22:14:47 +0000 | [diff] [blame] | 1697 | } |
Chris Lattner | 25a022c | 2006-07-11 01:40:09 +0000 | [diff] [blame] | 1698 | case ISD::INLINEASM: { |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1699 | SmallVector<SDOperand, 8> Ops(Node->op_begin(), Node->op_end()); |
Chris Lattner | 25a022c | 2006-07-11 01:40:09 +0000 | [diff] [blame] | 1700 | bool Changed = false; |
| 1701 | // Legalize all of the operands of the inline asm, in case they are nodes |
| 1702 | // that need to be expanded or something. Note we skip the asm string and |
| 1703 | // all of the TargetConstant flags. |
| 1704 | SDOperand Op = LegalizeOp(Ops[0]); |
| 1705 | Changed = Op != Ops[0]; |
| 1706 | Ops[0] = Op; |
| 1707 | |
| 1708 | bool HasInFlag = Ops.back().getValueType() == MVT::Flag; |
| 1709 | for (unsigned i = 2, e = Ops.size()-HasInFlag; i < e; ) { |
| 1710 | unsigned NumVals = cast<ConstantSDNode>(Ops[i])->getValue() >> 3; |
| 1711 | for (++i; NumVals; ++i, --NumVals) { |
| 1712 | SDOperand Op = LegalizeOp(Ops[i]); |
| 1713 | if (Op != Ops[i]) { |
| 1714 | Changed = true; |
| 1715 | Ops[i] = Op; |
| 1716 | } |
| 1717 | } |
Chris Lattner | ce7518c | 2006-01-26 22:24:51 +0000 | [diff] [blame] | 1718 | } |
Chris Lattner | 25a022c | 2006-07-11 01:40:09 +0000 | [diff] [blame] | 1719 | |
| 1720 | if (HasInFlag) { |
| 1721 | Op = LegalizeOp(Ops.back()); |
| 1722 | Changed |= Op != Ops.back(); |
| 1723 | Ops.back() = Op; |
| 1724 | } |
| 1725 | |
| 1726 | if (Changed) |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 1727 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | ce7518c | 2006-01-26 22:24:51 +0000 | [diff] [blame] | 1728 | |
| 1729 | // INLINE asm returns a chain and flag, make sure to add both to the map. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1730 | AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0)); |
Chris Lattner | ce7518c | 2006-01-26 22:24:51 +0000 | [diff] [blame] | 1731 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
| 1732 | return Result.getValue(Op.ResNo); |
Chris Lattner | 25a022c | 2006-07-11 01:40:09 +0000 | [diff] [blame] | 1733 | } |
Chris Lattner | c7af179 | 2005-01-07 22:12:08 +0000 | [diff] [blame] | 1734 | case ISD::BR: |
| 1735 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1736 | // Ensure that libcalls are emitted before a branch. |
| 1737 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1738 | Tmp1 = LegalizeOp(Tmp1); |
| 1739 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 1740 | |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1741 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
Chris Lattner | c7af179 | 2005-01-07 22:12:08 +0000 | [diff] [blame] | 1742 | break; |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 1743 | case ISD::BRIND: |
| 1744 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1745 | // Ensure that libcalls are emitted before a branch. |
| 1746 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1747 | Tmp1 = LegalizeOp(Tmp1); |
| 1748 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 1749 | |
| 1750 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 1751 | default: assert(0 && "Indirect target must be legal type (pointer)!"); |
| 1752 | case Legal: |
| 1753 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the condition. |
| 1754 | break; |
| 1755 | } |
| 1756 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 1757 | break; |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 1758 | case ISD::BR_JT: |
| 1759 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1760 | // Ensure that libcalls are emitted before a branch. |
| 1761 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1762 | Tmp1 = LegalizeOp(Tmp1); |
| 1763 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 1764 | |
| 1765 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the jumptable node. |
| 1766 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
| 1767 | |
| 1768 | switch (TLI.getOperationAction(ISD::BR_JT, MVT::Other)) { |
| 1769 | default: assert(0 && "This action is not supported yet!"); |
| 1770 | case TargetLowering::Legal: break; |
| 1771 | case TargetLowering::Custom: |
| 1772 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 1773 | if (Tmp1.Val) Result = Tmp1; |
| 1774 | break; |
| 1775 | case TargetLowering::Expand: { |
| 1776 | SDOperand Chain = Result.getOperand(0); |
| 1777 | SDOperand Table = Result.getOperand(1); |
| 1778 | SDOperand Index = Result.getOperand(2); |
| 1779 | |
| 1780 | MVT::ValueType PTy = TLI.getPointerTy(); |
Jim Laskey | acd80ac | 2006-12-14 19:17:33 +0000 | [diff] [blame] | 1781 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1782 | unsigned EntrySize = MF.getJumpTableInfo()->getEntrySize(); |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 1783 | Index= DAG.getNode(ISD::MUL, PTy, Index, DAG.getConstant(EntrySize, PTy)); |
| 1784 | SDOperand Addr = DAG.getNode(ISD::ADD, PTy, Index, Table); |
Jim Laskey | acd80ac | 2006-12-14 19:17:33 +0000 | [diff] [blame] | 1785 | |
| 1786 | SDOperand LD; |
| 1787 | switch (EntrySize) { |
| 1788 | default: assert(0 && "Size of jump table not supported yet."); break; |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 1789 | case 4: LD = DAG.getLoad(MVT::i32, Chain, Addr, |
Dan Gohman | 3069b87 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 1790 | PseudoSourceValue::getJumpTable(), 0); break; |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 1791 | case 8: LD = DAG.getLoad(MVT::i64, Chain, Addr, |
Dan Gohman | 3069b87 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 1792 | PseudoSourceValue::getJumpTable(), 0); break; |
Jim Laskey | acd80ac | 2006-12-14 19:17:33 +0000 | [diff] [blame] | 1793 | } |
| 1794 | |
Evan Cheng | cc41586 | 2007-11-09 01:32:10 +0000 | [diff] [blame] | 1795 | Addr = LD; |
Jim Laskey | acd80ac | 2006-12-14 19:17:33 +0000 | [diff] [blame] | 1796 | if (TLI.getTargetMachine().getRelocationModel() == Reloc::PIC_) { |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 1797 | // For PIC, the sequence is: |
| 1798 | // BRIND(load(Jumptable + index) + RelocBase) |
Evan Cheng | cc41586 | 2007-11-09 01:32:10 +0000 | [diff] [blame] | 1799 | // RelocBase can be JumpTable, GOT or some sort of global base. |
| 1800 | if (PTy != MVT::i32) |
| 1801 | Addr = DAG.getNode(ISD::SIGN_EXTEND, PTy, Addr); |
| 1802 | Addr = DAG.getNode(ISD::ADD, PTy, Addr, |
| 1803 | TLI.getPICJumpTableRelocBase(Table, DAG)); |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 1804 | } |
Evan Cheng | cc41586 | 2007-11-09 01:32:10 +0000 | [diff] [blame] | 1805 | Result = DAG.getNode(ISD::BRIND, MVT::Other, LD.getValue(1), Addr); |
Evan Cheng | 3d4ce11 | 2006-10-30 08:00:44 +0000 | [diff] [blame] | 1806 | } |
| 1807 | } |
| 1808 | break; |
Chris Lattner | c18ae4c | 2005-01-07 08:19:42 +0000 | [diff] [blame] | 1809 | case ISD::BRCOND: |
| 1810 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1811 | // Ensure that libcalls are emitted before a return. |
| 1812 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1813 | Tmp1 = LegalizeOp(Tmp1); |
| 1814 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 1815 | |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 1816 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 1817 | case Expand: assert(0 && "It's impossible to expand bools"); |
| 1818 | case Legal: |
| 1819 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the condition. |
| 1820 | break; |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 1821 | case Promote: { |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 1822 | Tmp2 = PromoteOp(Node->getOperand(1)); // Promote the condition. |
Chris Lattner | f990817 | 2006-11-27 04:39:56 +0000 | [diff] [blame] | 1823 | |
| 1824 | // The top bits of the promoted condition are not necessarily zero, ensure |
| 1825 | // that the value is properly zero extended. |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 1826 | unsigned BitWidth = Tmp2.getValueSizeInBits(); |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1827 | if (!DAG.MaskedValueIsZero(Tmp2, |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 1828 | APInt::getHighBitsSet(BitWidth, BitWidth-1))) |
Chris Lattner | f990817 | 2006-11-27 04:39:56 +0000 | [diff] [blame] | 1829 | Tmp2 = DAG.getZeroExtendInReg(Tmp2, MVT::i1); |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 1830 | break; |
| 1831 | } |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 1832 | } |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 1833 | |
| 1834 | // Basic block destination (Op#2) is always legal. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1835 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 1836 | |
| 1837 | switch (TLI.getOperationAction(ISD::BRCOND, MVT::Other)) { |
| 1838 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 1839 | case TargetLowering::Legal: break; |
| 1840 | case TargetLowering::Custom: |
| 1841 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 1842 | if (Tmp1.Val) Result = Tmp1; |
| 1843 | break; |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 1844 | case TargetLowering::Expand: |
| 1845 | // Expand brcond's setcc into its constituent parts and create a BR_CC |
| 1846 | // Node. |
| 1847 | if (Tmp2.getOpcode() == ISD::SETCC) { |
| 1848 | Result = DAG.getNode(ISD::BR_CC, MVT::Other, Tmp1, Tmp2.getOperand(2), |
| 1849 | Tmp2.getOperand(0), Tmp2.getOperand(1), |
| 1850 | Node->getOperand(2)); |
| 1851 | } else { |
| 1852 | Result = DAG.getNode(ISD::BR_CC, MVT::Other, Tmp1, |
| 1853 | DAG.getCondCode(ISD::SETNE), Tmp2, |
| 1854 | DAG.getConstant(0, Tmp2.getValueType()), |
| 1855 | Node->getOperand(2)); |
| 1856 | } |
| 1857 | break; |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 1858 | } |
| 1859 | break; |
| 1860 | case ISD::BR_CC: |
| 1861 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 1862 | // Ensure that libcalls are emitted before a branch. |
| 1863 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 1864 | Tmp1 = LegalizeOp(Tmp1); |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 1865 | Tmp2 = Node->getOperand(2); // LHS |
| 1866 | Tmp3 = Node->getOperand(3); // RHS |
| 1867 | Tmp4 = Node->getOperand(1); // CC |
| 1868 | |
| 1869 | LegalizeSetCCOperands(Tmp2, Tmp3, Tmp4); |
Evan Cheng | 722cb36 | 2006-12-18 22:55:34 +0000 | [diff] [blame] | 1870 | LastCALLSEQ_END = DAG.getEntryNode(); |
| 1871 | |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 1872 | // If we didn't get both a LHS and RHS back from LegalizeSetCCOperands, |
| 1873 | // the LHS is a legal SETCC itself. In this case, we need to compare |
| 1874 | // the result against zero to select between true and false values. |
| 1875 | if (Tmp3.Val == 0) { |
| 1876 | Tmp3 = DAG.getConstant(0, Tmp2.getValueType()); |
| 1877 | Tmp4 = DAG.getCondCode(ISD::SETNE); |
Chris Lattner | 181b7a3 | 2005-12-17 23:46:46 +0000 | [diff] [blame] | 1878 | } |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 1879 | |
| 1880 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp4, Tmp2, Tmp3, |
| 1881 | Node->getOperand(4)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 1882 | |
Chris Lattner | 181b7a3 | 2005-12-17 23:46:46 +0000 | [diff] [blame] | 1883 | switch (TLI.getOperationAction(ISD::BR_CC, Tmp3.getValueType())) { |
| 1884 | default: assert(0 && "Unexpected action for BR_CC!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 1885 | case TargetLowering::Legal: break; |
| 1886 | case TargetLowering::Custom: |
| 1887 | Tmp4 = TLI.LowerOperation(Result, DAG); |
| 1888 | if (Tmp4.Val) Result = Tmp4; |
Chris Lattner | 181b7a3 | 2005-12-17 23:46:46 +0000 | [diff] [blame] | 1889 | break; |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 1890 | } |
Chris Lattner | c18ae4c | 2005-01-07 08:19:42 +0000 | [diff] [blame] | 1891 | break; |
Evan Cheng | f3fd9fe | 2005-12-23 07:29:34 +0000 | [diff] [blame] | 1892 | case ISD::LOAD: { |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1893 | LoadSDNode *LD = cast<LoadSDNode>(Node); |
| 1894 | Tmp1 = LegalizeOp(LD->getChain()); // Legalize the chain. |
| 1895 | Tmp2 = LegalizeOp(LD->getBasePtr()); // Legalize the base pointer. |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 1896 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1897 | ISD::LoadExtType ExtType = LD->getExtensionType(); |
| 1898 | if (ExtType == ISD::NON_EXTLOAD) { |
| 1899 | MVT::ValueType VT = Node->getValueType(0); |
| 1900 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, LD->getOffset()); |
| 1901 | Tmp3 = Result.getValue(0); |
| 1902 | Tmp4 = Result.getValue(1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 1903 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1904 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 1905 | default: assert(0 && "This action is not supported yet!"); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 1906 | case TargetLowering::Legal: |
| 1907 | // If this is an unaligned load and the target doesn't support it, |
| 1908 | // expand it. |
| 1909 | if (!TLI.allowsUnalignedMemoryAccesses()) { |
| 1910 | unsigned ABIAlignment = TLI.getTargetData()-> |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 1911 | getABITypeAlignment(MVT::getTypeForValueType(LD->getMemoryVT())); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 1912 | if (LD->getAlignment() < ABIAlignment){ |
| 1913 | Result = ExpandUnalignedLoad(cast<LoadSDNode>(Result.Val), DAG, |
| 1914 | TLI); |
| 1915 | Tmp3 = Result.getOperand(0); |
| 1916 | Tmp4 = Result.getOperand(1); |
Dale Johannesen | 907f28c | 2007-09-08 19:29:23 +0000 | [diff] [blame] | 1917 | Tmp3 = LegalizeOp(Tmp3); |
| 1918 | Tmp4 = LegalizeOp(Tmp4); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 1919 | } |
| 1920 | } |
| 1921 | break; |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1922 | case TargetLowering::Custom: |
| 1923 | Tmp1 = TLI.LowerOperation(Tmp3, DAG); |
| 1924 | if (Tmp1.Val) { |
| 1925 | Tmp3 = LegalizeOp(Tmp1); |
| 1926 | Tmp4 = LegalizeOp(Tmp1.getValue(1)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 1927 | } |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1928 | break; |
| 1929 | case TargetLowering::Promote: { |
| 1930 | // Only promote a load of vector type to another. |
| 1931 | assert(MVT::isVector(VT) && "Cannot promote this load!"); |
| 1932 | // Change base type to a different vector type. |
| 1933 | MVT::ValueType NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), VT); |
| 1934 | |
| 1935 | Tmp1 = DAG.getLoad(NVT, Tmp1, Tmp2, LD->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 1936 | LD->getSrcValueOffset(), |
| 1937 | LD->isVolatile(), LD->getAlignment()); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1938 | Tmp3 = LegalizeOp(DAG.getNode(ISD::BIT_CONVERT, VT, Tmp1)); |
| 1939 | Tmp4 = LegalizeOp(Tmp1.getValue(1)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 1940 | break; |
Andrew Lenharth | 9d416f7 | 2005-06-30 19:22:37 +0000 | [diff] [blame] | 1941 | } |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 1942 | } |
| 1943 | // Since loads produce two values, make sure to remember that we |
| 1944 | // legalized both of them. |
| 1945 | AddLegalizedOperand(SDOperand(Node, 0), Tmp3); |
| 1946 | AddLegalizedOperand(SDOperand(Node, 1), Tmp4); |
| 1947 | return Op.ResNo ? Tmp4 : Tmp3; |
| 1948 | } else { |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 1949 | MVT::ValueType SrcVT = LD->getMemoryVT(); |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 1950 | unsigned SrcWidth = MVT::getSizeInBits(SrcVT); |
| 1951 | int SVOffset = LD->getSrcValueOffset(); |
| 1952 | unsigned Alignment = LD->getAlignment(); |
| 1953 | bool isVolatile = LD->isVolatile(); |
| 1954 | |
| 1955 | if (SrcWidth != MVT::getStoreSizeInBits(SrcVT) && |
| 1956 | // Some targets pretend to have an i1 loading operation, and actually |
| 1957 | // load an i8. This trick is correct for ZEXTLOAD because the top 7 |
| 1958 | // bits are guaranteed to be zero; it helps the optimizers understand |
| 1959 | // that these bits are zero. It is also useful for EXTLOAD, since it |
| 1960 | // tells the optimizers that those bits are undefined. It would be |
| 1961 | // nice to have an effective generic way of getting these benefits... |
| 1962 | // Until such a way is found, don't insist on promoting i1 here. |
| 1963 | (SrcVT != MVT::i1 || |
| 1964 | TLI.getLoadXAction(ExtType, MVT::i1) == TargetLowering::Promote)) { |
| 1965 | // Promote to a byte-sized load if not loading an integral number of |
| 1966 | // bytes. For example, promote EXTLOAD:i20 -> EXTLOAD:i24. |
| 1967 | unsigned NewWidth = MVT::getStoreSizeInBits(SrcVT); |
| 1968 | MVT::ValueType NVT = MVT::getIntegerType(NewWidth); |
| 1969 | SDOperand Ch; |
| 1970 | |
| 1971 | // The extra bits are guaranteed to be zero, since we stored them that |
| 1972 | // way. A zext load from NVT thus automatically gives zext from SrcVT. |
| 1973 | |
| 1974 | ISD::LoadExtType NewExtType = |
| 1975 | ExtType == ISD::ZEXTLOAD ? ISD::ZEXTLOAD : ISD::EXTLOAD; |
| 1976 | |
| 1977 | Result = DAG.getExtLoad(NewExtType, Node->getValueType(0), |
| 1978 | Tmp1, Tmp2, LD->getSrcValue(), SVOffset, |
| 1979 | NVT, isVolatile, Alignment); |
| 1980 | |
| 1981 | Ch = Result.getValue(1); // The chain. |
| 1982 | |
| 1983 | if (ExtType == ISD::SEXTLOAD) |
| 1984 | // Having the top bits zero doesn't help when sign extending. |
| 1985 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(), |
| 1986 | Result, DAG.getValueType(SrcVT)); |
| 1987 | else if (ExtType == ISD::ZEXTLOAD || NVT == Result.getValueType()) |
| 1988 | // All the top bits are guaranteed to be zero - inform the optimizers. |
| 1989 | Result = DAG.getNode(ISD::AssertZext, Result.getValueType(), Result, |
| 1990 | DAG.getValueType(SrcVT)); |
| 1991 | |
| 1992 | Tmp1 = LegalizeOp(Result); |
| 1993 | Tmp2 = LegalizeOp(Ch); |
| 1994 | } else if (SrcWidth & (SrcWidth - 1)) { |
| 1995 | // If not loading a power-of-2 number of bits, expand as two loads. |
| 1996 | assert(MVT::isExtendedVT(SrcVT) && !MVT::isVector(SrcVT) && |
| 1997 | "Unsupported extload!"); |
| 1998 | unsigned RoundWidth = 1 << Log2_32(SrcWidth); |
| 1999 | assert(RoundWidth < SrcWidth); |
| 2000 | unsigned ExtraWidth = SrcWidth - RoundWidth; |
| 2001 | assert(ExtraWidth < RoundWidth); |
| 2002 | assert(!(RoundWidth % 8) && !(ExtraWidth % 8) && |
| 2003 | "Load size not an integral number of bytes!"); |
| 2004 | MVT::ValueType RoundVT = MVT::getIntegerType(RoundWidth); |
| 2005 | MVT::ValueType ExtraVT = MVT::getIntegerType(ExtraWidth); |
| 2006 | SDOperand Lo, Hi, Ch; |
| 2007 | unsigned IncrementSize; |
| 2008 | |
| 2009 | if (TLI.isLittleEndian()) { |
| 2010 | // EXTLOAD:i24 -> ZEXTLOAD:i16 | (shl EXTLOAD@+2:i8, 16) |
| 2011 | // Load the bottom RoundWidth bits. |
| 2012 | Lo = DAG.getExtLoad(ISD::ZEXTLOAD, Node->getValueType(0), Tmp1, Tmp2, |
| 2013 | LD->getSrcValue(), SVOffset, RoundVT, isVolatile, |
| 2014 | Alignment); |
| 2015 | |
| 2016 | // Load the remaining ExtraWidth bits. |
| 2017 | IncrementSize = RoundWidth / 8; |
| 2018 | Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2, |
| 2019 | DAG.getIntPtrConstant(IncrementSize)); |
| 2020 | Hi = DAG.getExtLoad(ExtType, Node->getValueType(0), Tmp1, Tmp2, |
| 2021 | LD->getSrcValue(), SVOffset + IncrementSize, |
| 2022 | ExtraVT, isVolatile, |
| 2023 | MinAlign(Alignment, IncrementSize)); |
| 2024 | |
| 2025 | // Build a factor node to remember that this load is independent of the |
| 2026 | // other one. |
| 2027 | Ch = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1), |
| 2028 | Hi.getValue(1)); |
| 2029 | |
| 2030 | // Move the top bits to the right place. |
| 2031 | Hi = DAG.getNode(ISD::SHL, Hi.getValueType(), Hi, |
| 2032 | DAG.getConstant(RoundWidth, TLI.getShiftAmountTy())); |
| 2033 | |
| 2034 | // Join the hi and lo parts. |
| 2035 | Result = DAG.getNode(ISD::OR, Node->getValueType(0), Lo, Hi); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2036 | } else { |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2037 | // Big endian - avoid unaligned loads. |
| 2038 | // EXTLOAD:i24 -> (shl EXTLOAD:i16, 8) | ZEXTLOAD@+2:i8 |
| 2039 | // Load the top RoundWidth bits. |
| 2040 | Hi = DAG.getExtLoad(ExtType, Node->getValueType(0), Tmp1, Tmp2, |
| 2041 | LD->getSrcValue(), SVOffset, RoundVT, isVolatile, |
| 2042 | Alignment); |
| 2043 | |
| 2044 | // Load the remaining ExtraWidth bits. |
| 2045 | IncrementSize = RoundWidth / 8; |
| 2046 | Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2, |
| 2047 | DAG.getIntPtrConstant(IncrementSize)); |
| 2048 | Lo = DAG.getExtLoad(ISD::ZEXTLOAD, Node->getValueType(0), Tmp1, Tmp2, |
| 2049 | LD->getSrcValue(), SVOffset + IncrementSize, |
| 2050 | ExtraVT, isVolatile, |
| 2051 | MinAlign(Alignment, IncrementSize)); |
| 2052 | |
| 2053 | // Build a factor node to remember that this load is independent of the |
| 2054 | // other one. |
| 2055 | Ch = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1), |
| 2056 | Hi.getValue(1)); |
| 2057 | |
| 2058 | // Move the top bits to the right place. |
| 2059 | Hi = DAG.getNode(ISD::SHL, Hi.getValueType(), Hi, |
| 2060 | DAG.getConstant(ExtraWidth, TLI.getShiftAmountTy())); |
| 2061 | |
| 2062 | // Join the hi and lo parts. |
| 2063 | Result = DAG.getNode(ISD::OR, Node->getValueType(0), Lo, Hi); |
| 2064 | } |
| 2065 | |
| 2066 | Tmp1 = LegalizeOp(Result); |
| 2067 | Tmp2 = LegalizeOp(Ch); |
| 2068 | } else { |
| 2069 | switch (TLI.getLoadXAction(ExtType, SrcVT)) { |
| 2070 | default: assert(0 && "This action is not supported yet!"); |
| 2071 | case TargetLowering::Custom: |
| 2072 | isCustom = true; |
| 2073 | // FALLTHROUGH |
| 2074 | case TargetLowering::Legal: |
| 2075 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, LD->getOffset()); |
| 2076 | Tmp1 = Result.getValue(0); |
| 2077 | Tmp2 = Result.getValue(1); |
| 2078 | |
| 2079 | if (isCustom) { |
| 2080 | Tmp3 = TLI.LowerOperation(Result, DAG); |
| 2081 | if (Tmp3.Val) { |
| 2082 | Tmp1 = LegalizeOp(Tmp3); |
| 2083 | Tmp2 = LegalizeOp(Tmp3.getValue(1)); |
| 2084 | } |
| 2085 | } else { |
| 2086 | // If this is an unaligned load and the target doesn't support it, |
| 2087 | // expand it. |
| 2088 | if (!TLI.allowsUnalignedMemoryAccesses()) { |
| 2089 | unsigned ABIAlignment = TLI.getTargetData()-> |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 2090 | getABITypeAlignment(MVT::getTypeForValueType(LD->getMemoryVT())); |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2091 | if (LD->getAlignment() < ABIAlignment){ |
| 2092 | Result = ExpandUnalignedLoad(cast<LoadSDNode>(Result.Val), DAG, |
| 2093 | TLI); |
| 2094 | Tmp1 = Result.getOperand(0); |
| 2095 | Tmp2 = Result.getOperand(1); |
| 2096 | Tmp1 = LegalizeOp(Tmp1); |
| 2097 | Tmp2 = LegalizeOp(Tmp2); |
| 2098 | } |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2099 | } |
| 2100 | } |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2101 | break; |
| 2102 | case TargetLowering::Expand: |
| 2103 | // f64 = EXTLOAD f32 should expand to LOAD, FP_EXTEND |
| 2104 | if (SrcVT == MVT::f32 && Node->getValueType(0) == MVT::f64) { |
| 2105 | SDOperand Load = DAG.getLoad(SrcVT, Tmp1, Tmp2, LD->getSrcValue(), |
| 2106 | LD->getSrcValueOffset(), |
| 2107 | LD->isVolatile(), LD->getAlignment()); |
| 2108 | Result = DAG.getNode(ISD::FP_EXTEND, Node->getValueType(0), Load); |
| 2109 | Tmp1 = LegalizeOp(Result); // Relegalize new nodes. |
| 2110 | Tmp2 = LegalizeOp(Load.getValue(1)); |
| 2111 | break; |
| 2112 | } |
| 2113 | assert(ExtType != ISD::EXTLOAD &&"EXTLOAD should always be supported!"); |
| 2114 | // Turn the unsupported load into an EXTLOAD followed by an explicit |
| 2115 | // zero/sign extend inreg. |
| 2116 | Result = DAG.getExtLoad(ISD::EXTLOAD, Node->getValueType(0), |
| 2117 | Tmp1, Tmp2, LD->getSrcValue(), |
| 2118 | LD->getSrcValueOffset(), SrcVT, |
| 2119 | LD->isVolatile(), LD->getAlignment()); |
| 2120 | SDOperand ValRes; |
| 2121 | if (ExtType == ISD::SEXTLOAD) |
| 2122 | ValRes = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(), |
| 2123 | Result, DAG.getValueType(SrcVT)); |
| 2124 | else |
| 2125 | ValRes = DAG.getZeroExtendInReg(Result, SrcVT); |
| 2126 | Tmp1 = LegalizeOp(ValRes); // Relegalize new nodes. |
| 2127 | Tmp2 = LegalizeOp(Result.getValue(1)); // Relegalize new nodes. |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2128 | break; |
| 2129 | } |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2130 | } |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 2131 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2132 | // Since loads produce two values, make sure to remember that we legalized |
| 2133 | // both of them. |
| 2134 | AddLegalizedOperand(SDOperand(Node, 0), Tmp1); |
| 2135 | AddLegalizedOperand(SDOperand(Node, 1), Tmp2); |
| 2136 | return Op.ResNo ? Tmp2 : Tmp1; |
Chris Lattner | 01ff721 | 2005-04-10 22:54:25 +0000 | [diff] [blame] | 2137 | } |
Chris Lattner | 01ff721 | 2005-04-10 22:54:25 +0000 | [diff] [blame] | 2138 | } |
Nate Begeman | 5dc897b | 2005-10-19 00:06:56 +0000 | [diff] [blame] | 2139 | case ISD::EXTRACT_ELEMENT: { |
| 2140 | MVT::ValueType OpTy = Node->getOperand(0).getValueType(); |
| 2141 | switch (getTypeAction(OpTy)) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2142 | default: assert(0 && "EXTRACT_ELEMENT action for type unimplemented!"); |
Nate Begeman | 5dc897b | 2005-10-19 00:06:56 +0000 | [diff] [blame] | 2143 | case Legal: |
| 2144 | if (cast<ConstantSDNode>(Node->getOperand(1))->getValue()) { |
| 2145 | // 1 -> Hi |
| 2146 | Result = DAG.getNode(ISD::SRL, OpTy, Node->getOperand(0), |
| 2147 | DAG.getConstant(MVT::getSizeInBits(OpTy)/2, |
| 2148 | TLI.getShiftAmountTy())); |
| 2149 | Result = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0), Result); |
| 2150 | } else { |
| 2151 | // 0 -> Lo |
| 2152 | Result = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0), |
| 2153 | Node->getOperand(0)); |
| 2154 | } |
Nate Begeman | 5dc897b | 2005-10-19 00:06:56 +0000 | [diff] [blame] | 2155 | break; |
| 2156 | case Expand: |
| 2157 | // Get both the low and high parts. |
| 2158 | ExpandOp(Node->getOperand(0), Tmp1, Tmp2); |
| 2159 | if (cast<ConstantSDNode>(Node->getOperand(1))->getValue()) |
| 2160 | Result = Tmp2; // 1 -> Hi |
| 2161 | else |
| 2162 | Result = Tmp1; // 0 -> Lo |
| 2163 | break; |
| 2164 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2165 | break; |
Nate Begeman | 5dc897b | 2005-10-19 00:06:56 +0000 | [diff] [blame] | 2166 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2167 | |
| 2168 | case ISD::CopyToReg: |
| 2169 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2170 | |
Chris Lattner | c9c60f6 | 2005-08-24 16:35:28 +0000 | [diff] [blame] | 2171 | assert(isTypeLegal(Node->getOperand(2).getValueType()) && |
Chris Lattner | d5d0f9b | 2005-08-16 21:55:35 +0000 | [diff] [blame] | 2172 | "Register type must be legal!"); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 2173 | // Legalize the incoming value (must be a legal type). |
Chris Lattner | d5d0f9b | 2005-08-16 21:55:35 +0000 | [diff] [blame] | 2174 | Tmp2 = LegalizeOp(Node->getOperand(2)); |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 2175 | if (Node->getNumValues() == 1) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2176 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1), Tmp2); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 2177 | } else { |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 2178 | assert(Node->getNumValues() == 2 && "Unknown CopyToReg"); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2179 | if (Node->getNumOperands() == 4) { |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 2180 | Tmp3 = LegalizeOp(Node->getOperand(3)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2181 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1), Tmp2, |
| 2182 | Tmp3); |
| 2183 | } else { |
| 2184 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1),Tmp2); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 2185 | } |
| 2186 | |
| 2187 | // Since this produces two values, make sure to remember that we legalized |
| 2188 | // both of them. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2189 | AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0)); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 2190 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2191 | return Result; |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 2192 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2193 | break; |
| 2194 | |
| 2195 | case ISD::RET: |
| 2196 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 2197 | |
| 2198 | // Ensure that libcalls are emitted before a return. |
| 2199 | Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); |
| 2200 | Tmp1 = LegalizeOp(Tmp1); |
| 2201 | LastCALLSEQ_END = DAG.getEntryNode(); |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2202 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2203 | switch (Node->getNumOperands()) { |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 2204 | case 3: // ret val |
Evan Cheng | 98f8aeb | 2006-04-11 06:33:39 +0000 | [diff] [blame] | 2205 | Tmp2 = Node->getOperand(1); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 2206 | Tmp3 = Node->getOperand(2); // Signness |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2207 | switch (getTypeAction(Tmp2.getValueType())) { |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2208 | case Legal: |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 2209 | Result = DAG.UpdateNodeOperands(Result, Tmp1, LegalizeOp(Tmp2), Tmp3); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2210 | break; |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2211 | case Expand: |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2212 | if (!MVT::isVector(Tmp2.getValueType())) { |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2213 | SDOperand Lo, Hi; |
| 2214 | ExpandOp(Tmp2, Lo, Hi); |
Chris Lattner | edf2e8d | 2007-03-06 20:01:06 +0000 | [diff] [blame] | 2215 | |
| 2216 | // Big endian systems want the hi reg first. |
Duncan Sands | 0753fc1 | 2008-02-11 10:37:04 +0000 | [diff] [blame] | 2217 | if (TLI.isBigEndian()) |
Chris Lattner | edf2e8d | 2007-03-06 20:01:06 +0000 | [diff] [blame] | 2218 | std::swap(Lo, Hi); |
| 2219 | |
Evan Cheng | 13acce3 | 2006-12-11 19:27:14 +0000 | [diff] [blame] | 2220 | if (Hi.Val) |
| 2221 | Result = DAG.getNode(ISD::RET, MVT::Other, Tmp1, Lo, Tmp3, Hi,Tmp3); |
| 2222 | else |
| 2223 | Result = DAG.getNode(ISD::RET, MVT::Other, Tmp1, Lo, Tmp3); |
Chris Lattner | f921a51 | 2006-08-21 20:24:53 +0000 | [diff] [blame] | 2224 | Result = LegalizeOp(Result); |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2225 | } else { |
| 2226 | SDNode *InVal = Tmp2.Val; |
Dale Johannesen | e526962 | 2007-10-20 00:07:52 +0000 | [diff] [blame] | 2227 | int InIx = Tmp2.ResNo; |
| 2228 | unsigned NumElems = MVT::getVectorNumElements(InVal->getValueType(InIx)); |
| 2229 | MVT::ValueType EVT = MVT::getVectorElementType(InVal->getValueType(InIx)); |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2230 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2231 | // Figure out if there is a simple type corresponding to this Vector |
Reid Spencer | ac9dcb9 | 2007-02-15 03:39:18 +0000 | [diff] [blame] | 2232 | // type. If so, convert to the vector type. |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2233 | MVT::ValueType TVT = MVT::getVectorType(EVT, NumElems); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2234 | if (TLI.isTypeLegal(TVT)) { |
Reid Spencer | ac9dcb9 | 2007-02-15 03:39:18 +0000 | [diff] [blame] | 2235 | // Turn this into a return of the vector type. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2236 | Tmp2 = LegalizeOp(Tmp2); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 2237 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2238 | } else if (NumElems == 1) { |
| 2239 | // Turn this into a return of the scalar type. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2240 | Tmp2 = ScalarizeVectorOp(Tmp2); |
| 2241 | Tmp2 = LegalizeOp(Tmp2); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 2242 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | b49e52c | 2006-04-11 02:00:08 +0000 | [diff] [blame] | 2243 | |
| 2244 | // FIXME: Returns of gcc generic vectors smaller than a legal type |
| 2245 | // should be returned in integer registers! |
| 2246 | |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2247 | // The scalarized value type may not be legal, e.g. it might require |
| 2248 | // promotion or expansion. Relegalize the return. |
| 2249 | Result = LegalizeOp(Result); |
| 2250 | } else { |
Chris Lattner | b49e52c | 2006-04-11 02:00:08 +0000 | [diff] [blame] | 2251 | // FIXME: Returns of gcc generic vectors larger than a legal vector |
| 2252 | // type should be returned by reference! |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2253 | SDOperand Lo, Hi; |
| 2254 | SplitVectorOp(Tmp2, Lo, Hi); |
Chris Lattner | fea997a | 2007-02-01 04:55:59 +0000 | [diff] [blame] | 2255 | Result = DAG.getNode(ISD::RET, MVT::Other, Tmp1, Lo, Tmp3, Hi,Tmp3); |
Chris Lattner | f87324e | 2006-04-11 01:31:51 +0000 | [diff] [blame] | 2256 | Result = LegalizeOp(Result); |
| 2257 | } |
| 2258 | } |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2259 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2260 | case Promote: |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 2261 | Tmp2 = PromoteOp(Node->getOperand(1)); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 2262 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2263 | Result = LegalizeOp(Result); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 2264 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2265 | } |
| 2266 | break; |
| 2267 | case 1: // ret void |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2268 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2269 | break; |
| 2270 | default: { // ret <values> |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 2271 | SmallVector<SDOperand, 8> NewValues; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2272 | NewValues.push_back(Tmp1); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 2273 | for (unsigned i = 1, e = Node->getNumOperands(); i < e; i += 2) |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2274 | switch (getTypeAction(Node->getOperand(i).getValueType())) { |
| 2275 | case Legal: |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 2276 | NewValues.push_back(LegalizeOp(Node->getOperand(i))); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 2277 | NewValues.push_back(Node->getOperand(i+1)); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2278 | break; |
| 2279 | case Expand: { |
| 2280 | SDOperand Lo, Hi; |
Dan Gohman | 6595cb3 | 2007-06-27 16:08:04 +0000 | [diff] [blame] | 2281 | assert(!MVT::isExtendedVT(Node->getOperand(i).getValueType()) && |
Chris Lattner | b49e52c | 2006-04-11 02:00:08 +0000 | [diff] [blame] | 2282 | "FIXME: TODO: implement returning non-legal vector types!"); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2283 | ExpandOp(Node->getOperand(i), Lo, Hi); |
| 2284 | NewValues.push_back(Lo); |
Evan Cheng | 8e7d056 | 2006-05-26 23:09:09 +0000 | [diff] [blame] | 2285 | NewValues.push_back(Node->getOperand(i+1)); |
Evan Cheng | 13acce3 | 2006-12-11 19:27:14 +0000 | [diff] [blame] | 2286 | if (Hi.Val) { |
| 2287 | NewValues.push_back(Hi); |
| 2288 | NewValues.push_back(Node->getOperand(i+1)); |
| 2289 | } |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2290 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2291 | } |
| 2292 | case Promote: |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 2293 | assert(0 && "Can't promote multiple return value yet!"); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2294 | } |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2295 | |
| 2296 | if (NewValues.size() == Node->getNumOperands()) |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 2297 | Result = DAG.UpdateNodeOperands(Result, &NewValues[0],NewValues.size()); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2298 | else |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 2299 | Result = DAG.getNode(ISD::RET, MVT::Other, |
| 2300 | &NewValues[0], NewValues.size()); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2301 | break; |
| 2302 | } |
| 2303 | } |
Evan Cheng | 17c428e | 2006-01-06 00:41:43 +0000 | [diff] [blame] | 2304 | |
Chris Lattner | 6862dbc | 2006-01-29 21:02:23 +0000 | [diff] [blame] | 2305 | if (Result.getOpcode() == ISD::RET) { |
| 2306 | switch (TLI.getOperationAction(Result.getOpcode(), MVT::Other)) { |
| 2307 | default: assert(0 && "This action is not supported yet!"); |
| 2308 | case TargetLowering::Legal: break; |
| 2309 | case TargetLowering::Custom: |
| 2310 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2311 | if (Tmp1.Val) Result = Tmp1; |
| 2312 | break; |
| 2313 | } |
Evan Cheng | 17c428e | 2006-01-06 00:41:43 +0000 | [diff] [blame] | 2314 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2315 | break; |
Evan Cheng | f3fd9fe | 2005-12-23 07:29:34 +0000 | [diff] [blame] | 2316 | case ISD::STORE: { |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2317 | StoreSDNode *ST = cast<StoreSDNode>(Node); |
| 2318 | Tmp1 = LegalizeOp(ST->getChain()); // Legalize the chain. |
| 2319 | Tmp2 = LegalizeOp(ST->getBasePtr()); // Legalize the pointer. |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2320 | int SVOffset = ST->getSrcValueOffset(); |
| 2321 | unsigned Alignment = ST->getAlignment(); |
| 2322 | bool isVolatile = ST->isVolatile(); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2323 | |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2324 | if (!ST->isTruncatingStore()) { |
Chris Lattner | d93d46e | 2006-12-12 04:18:56 +0000 | [diff] [blame] | 2325 | // Turn 'store float 1.0, Ptr' -> 'store int 0x12345678, Ptr' |
| 2326 | // FIXME: We shouldn't do this for TargetConstantFP's. |
| 2327 | // FIXME: move this to the DAG Combiner! Note that we can't regress due |
| 2328 | // to phase ordering between legalized code and the dag combiner. This |
| 2329 | // probably means that we need to integrate dag combiner and legalizer |
| 2330 | // together. |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 2331 | // We generally can't do this one for long doubles. |
Chris Lattner | 2b4c279 | 2007-10-13 06:35:54 +0000 | [diff] [blame] | 2332 | if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(ST->getValue())) { |
Chris Lattner | 3cb9351 | 2007-10-15 05:46:06 +0000 | [diff] [blame] | 2333 | if (CFP->getValueType(0) == MVT::f32 && |
| 2334 | getTypeAction(MVT::i32) == Legal) { |
Dan Gohman | 6cf9b8a | 2008-03-11 00:11:06 +0000 | [diff] [blame] | 2335 | Tmp3 = DAG.getConstant(CFP->getValueAPF(). |
| 2336 | convertToAPInt().zextOrTrunc(32), |
Dale Johannesen | 3f6eb74 | 2007-09-11 18:32:33 +0000 | [diff] [blame] | 2337 | MVT::i32); |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 2338 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
| 2339 | SVOffset, isVolatile, Alignment); |
| 2340 | break; |
| 2341 | } else if (CFP->getValueType(0) == MVT::f64) { |
Chris Lattner | 3cb9351 | 2007-10-15 05:46:06 +0000 | [diff] [blame] | 2342 | // If this target supports 64-bit registers, do a single 64-bit store. |
| 2343 | if (getTypeAction(MVT::i64) == Legal) { |
| 2344 | Tmp3 = DAG.getConstant(CFP->getValueAPF().convertToAPInt(). |
Dan Gohman | 6cf9b8a | 2008-03-11 00:11:06 +0000 | [diff] [blame] | 2345 | zextOrTrunc(64), MVT::i64); |
Chris Lattner | 3cb9351 | 2007-10-15 05:46:06 +0000 | [diff] [blame] | 2346 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
| 2347 | SVOffset, isVolatile, Alignment); |
| 2348 | break; |
| 2349 | } else if (getTypeAction(MVT::i32) == Legal) { |
| 2350 | // Otherwise, if the target supports 32-bit registers, use 2 32-bit |
| 2351 | // stores. If the target supports neither 32- nor 64-bits, this |
| 2352 | // xform is certainly not worth it. |
Dan Gohman | 6cf9b8a | 2008-03-11 00:11:06 +0000 | [diff] [blame] | 2353 | const APInt &IntVal =CFP->getValueAPF().convertToAPInt(); |
| 2354 | SDOperand Lo = DAG.getConstant(APInt(IntVal).trunc(32), MVT::i32); |
| 2355 | SDOperand Hi = DAG.getConstant(IntVal.lshr(32).trunc(32), MVT::i32); |
Duncan Sands | 0753fc1 | 2008-02-11 10:37:04 +0000 | [diff] [blame] | 2356 | if (TLI.isBigEndian()) std::swap(Lo, Hi); |
Chris Lattner | 3cb9351 | 2007-10-15 05:46:06 +0000 | [diff] [blame] | 2357 | |
| 2358 | Lo = DAG.getStore(Tmp1, Lo, Tmp2, ST->getSrcValue(), |
| 2359 | SVOffset, isVolatile, Alignment); |
| 2360 | Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2, |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 2361 | DAG.getIntPtrConstant(4)); |
Chris Lattner | 3cb9351 | 2007-10-15 05:46:06 +0000 | [diff] [blame] | 2362 | Hi = DAG.getStore(Tmp1, Hi, Tmp2, ST->getSrcValue(), SVOffset+4, |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 2363 | isVolatile, MinAlign(Alignment, 4U)); |
Chris Lattner | 3cb9351 | 2007-10-15 05:46:06 +0000 | [diff] [blame] | 2364 | |
| 2365 | Result = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo, Hi); |
| 2366 | break; |
| 2367 | } |
Chris Lattner | d93d46e | 2006-12-12 04:18:56 +0000 | [diff] [blame] | 2368 | } |
Chris Lattner | d93d46e | 2006-12-12 04:18:56 +0000 | [diff] [blame] | 2369 | } |
| 2370 | |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 2371 | switch (getTypeAction(ST->getMemoryVT())) { |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2372 | case Legal: { |
| 2373 | Tmp3 = LegalizeOp(ST->getValue()); |
| 2374 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp3, Tmp2, |
| 2375 | ST->getOffset()); |
Evan Cheng | f3fd9fe | 2005-12-23 07:29:34 +0000 | [diff] [blame] | 2376 | |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2377 | MVT::ValueType VT = Tmp3.getValueType(); |
| 2378 | switch (TLI.getOperationAction(ISD::STORE, VT)) { |
| 2379 | default: assert(0 && "This action is not supported yet!"); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2380 | case TargetLowering::Legal: |
| 2381 | // If this is an unaligned store and the target doesn't support it, |
| 2382 | // expand it. |
| 2383 | if (!TLI.allowsUnalignedMemoryAccesses()) { |
| 2384 | unsigned ABIAlignment = TLI.getTargetData()-> |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 2385 | getABITypeAlignment(MVT::getTypeForValueType(ST->getMemoryVT())); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2386 | if (ST->getAlignment() < ABIAlignment) |
| 2387 | Result = ExpandUnalignedStore(cast<StoreSDNode>(Result.Val), DAG, |
| 2388 | TLI); |
| 2389 | } |
| 2390 | break; |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2391 | case TargetLowering::Custom: |
| 2392 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2393 | if (Tmp1.Val) Result = Tmp1; |
| 2394 | break; |
| 2395 | case TargetLowering::Promote: |
| 2396 | assert(MVT::isVector(VT) && "Unknown legal promote case!"); |
| 2397 | Tmp3 = DAG.getNode(ISD::BIT_CONVERT, |
| 2398 | TLI.getTypeToPromoteTo(ISD::STORE, VT), Tmp3); |
| 2399 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2400 | ST->getSrcValue(), SVOffset, isVolatile, |
| 2401 | Alignment); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2402 | break; |
| 2403 | } |
| 2404 | break; |
| 2405 | } |
| 2406 | case Promote: |
| 2407 | // Truncate the value and store the result. |
| 2408 | Tmp3 = PromoteOp(ST->getValue()); |
| 2409 | Result = DAG.getTruncStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 2410 | SVOffset, ST->getMemoryVT(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2411 | isVolatile, Alignment); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2412 | break; |
| 2413 | |
| 2414 | case Expand: |
| 2415 | unsigned IncrementSize = 0; |
| 2416 | SDOperand Lo, Hi; |
| 2417 | |
| 2418 | // If this is a vector type, then we have to calculate the increment as |
| 2419 | // the product of the element size in bytes, and the number of elements |
| 2420 | // in the high half of the vector. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2421 | if (MVT::isVector(ST->getValue().getValueType())) { |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2422 | SDNode *InVal = ST->getValue().Val; |
Dale Johannesen | e526962 | 2007-10-20 00:07:52 +0000 | [diff] [blame] | 2423 | int InIx = ST->getValue().ResNo; |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 2424 | MVT::ValueType InVT = InVal->getValueType(InIx); |
| 2425 | unsigned NumElems = MVT::getVectorNumElements(InVT); |
| 2426 | MVT::ValueType EVT = MVT::getVectorElementType(InVT); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2427 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2428 | // Figure out if there is a simple type corresponding to this Vector |
Reid Spencer | ac9dcb9 | 2007-02-15 03:39:18 +0000 | [diff] [blame] | 2429 | // type. If so, convert to the vector type. |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2430 | MVT::ValueType TVT = MVT::getVectorType(EVT, NumElems); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2431 | if (TLI.isTypeLegal(TVT)) { |
Reid Spencer | ac9dcb9 | 2007-02-15 03:39:18 +0000 | [diff] [blame] | 2432 | // Turn this into a normal store of the vector type. |
Dan Gohman | 21be384 | 2008-02-15 18:11:59 +0000 | [diff] [blame] | 2433 | Tmp3 = LegalizeOp(ST->getValue()); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2434 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2435 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2436 | Result = LegalizeOp(Result); |
| 2437 | break; |
| 2438 | } else if (NumElems == 1) { |
| 2439 | // Turn this into a normal store of the scalar type. |
Dan Gohman | 21be384 | 2008-02-15 18:11:59 +0000 | [diff] [blame] | 2440 | Tmp3 = ScalarizeVectorOp(ST->getValue()); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2441 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2442 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2443 | // The scalarized value type may not be legal, e.g. it might require |
| 2444 | // promotion or expansion. Relegalize the scalar store. |
| 2445 | Result = LegalizeOp(Result); |
| 2446 | break; |
| 2447 | } else { |
Dan Gohman | 21be384 | 2008-02-15 18:11:59 +0000 | [diff] [blame] | 2448 | SplitVectorOp(ST->getValue(), Lo, Hi); |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 2449 | IncrementSize = MVT::getVectorNumElements(Lo.Val->getValueType(0)) * |
| 2450 | MVT::getSizeInBits(EVT)/8; |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2451 | } |
| 2452 | } else { |
Dan Gohman | 21be384 | 2008-02-15 18:11:59 +0000 | [diff] [blame] | 2453 | ExpandOp(ST->getValue(), Lo, Hi); |
Evan Cheng | 7b2b5c8 | 2006-12-12 19:53:13 +0000 | [diff] [blame] | 2454 | IncrementSize = Hi.Val ? MVT::getSizeInBits(Hi.getValueType())/8 : 0; |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2455 | |
Duncan Sands | 0753fc1 | 2008-02-11 10:37:04 +0000 | [diff] [blame] | 2456 | if (TLI.isBigEndian()) |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2457 | std::swap(Lo, Hi); |
| 2458 | } |
| 2459 | |
| 2460 | Lo = DAG.getStore(Tmp1, Lo, Tmp2, ST->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2461 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 7b2b5c8 | 2006-12-12 19:53:13 +0000 | [diff] [blame] | 2462 | |
| 2463 | if (Hi.Val == NULL) { |
| 2464 | // Must be int <-> float one-to-one expansion. |
| 2465 | Result = Lo; |
| 2466 | break; |
| 2467 | } |
| 2468 | |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2469 | Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2, |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 2470 | DAG.getIntPtrConstant(IncrementSize)); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2471 | assert(isTypeLegal(Tmp2.getValueType()) && |
| 2472 | "Pointers must be legal!"); |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2473 | SVOffset += IncrementSize; |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 2474 | Alignment = MinAlign(Alignment, IncrementSize); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2475 | Hi = DAG.getStore(Tmp1, Hi, Tmp2, ST->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 2476 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2477 | Result = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo, Hi); |
| 2478 | break; |
| 2479 | } |
| 2480 | } else { |
Chris Lattner | ddf8956 | 2008-01-17 19:59:44 +0000 | [diff] [blame] | 2481 | switch (getTypeAction(ST->getValue().getValueType())) { |
| 2482 | case Legal: |
| 2483 | Tmp3 = LegalizeOp(ST->getValue()); |
| 2484 | break; |
| 2485 | case Promote: |
| 2486 | // We can promote the value, the truncstore will still take care of it. |
| 2487 | Tmp3 = PromoteOp(ST->getValue()); |
| 2488 | break; |
| 2489 | case Expand: |
| 2490 | // Just store the low part. This may become a non-trunc store, so make |
| 2491 | // sure to use getTruncStore, not UpdateNodeOperands below. |
| 2492 | ExpandOp(ST->getValue(), Tmp3, Tmp4); |
| 2493 | return DAG.getTruncStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
| 2494 | SVOffset, MVT::i8, isVolatile, Alignment); |
| 2495 | } |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 2496 | |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 2497 | MVT::ValueType StVT = ST->getMemoryVT(); |
Duncan Sands | 7e85720 | 2008-01-22 07:17:34 +0000 | [diff] [blame] | 2498 | unsigned StWidth = MVT::getSizeInBits(StVT); |
| 2499 | |
| 2500 | if (StWidth != MVT::getStoreSizeInBits(StVT)) { |
| 2501 | // Promote to a byte-sized store with upper bits zero if not |
| 2502 | // storing an integral number of bytes. For example, promote |
| 2503 | // TRUNCSTORE:i1 X -> TRUNCSTORE:i8 (and X, 1) |
| 2504 | MVT::ValueType NVT = MVT::getIntegerType(MVT::getStoreSizeInBits(StVT)); |
| 2505 | Tmp3 = DAG.getZeroExtendInReg(Tmp3, StVT); |
| 2506 | Result = DAG.getTruncStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
| 2507 | SVOffset, NVT, isVolatile, Alignment); |
| 2508 | } else if (StWidth & (StWidth - 1)) { |
| 2509 | // If not storing a power-of-2 number of bits, expand as two stores. |
| 2510 | assert(MVT::isExtendedVT(StVT) && !MVT::isVector(StVT) && |
| 2511 | "Unsupported truncstore!"); |
| 2512 | unsigned RoundWidth = 1 << Log2_32(StWidth); |
| 2513 | assert(RoundWidth < StWidth); |
| 2514 | unsigned ExtraWidth = StWidth - RoundWidth; |
| 2515 | assert(ExtraWidth < RoundWidth); |
| 2516 | assert(!(RoundWidth % 8) && !(ExtraWidth % 8) && |
| 2517 | "Store size not an integral number of bytes!"); |
| 2518 | MVT::ValueType RoundVT = MVT::getIntegerType(RoundWidth); |
| 2519 | MVT::ValueType ExtraVT = MVT::getIntegerType(ExtraWidth); |
| 2520 | SDOperand Lo, Hi; |
| 2521 | unsigned IncrementSize; |
| 2522 | |
| 2523 | if (TLI.isLittleEndian()) { |
| 2524 | // TRUNCSTORE:i24 X -> TRUNCSTORE:i16 X, TRUNCSTORE@+2:i8 (srl X, 16) |
| 2525 | // Store the bottom RoundWidth bits. |
| 2526 | Lo = DAG.getTruncStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
| 2527 | SVOffset, RoundVT, |
| 2528 | isVolatile, Alignment); |
| 2529 | |
| 2530 | // Store the remaining ExtraWidth bits. |
| 2531 | IncrementSize = RoundWidth / 8; |
| 2532 | Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2, |
| 2533 | DAG.getIntPtrConstant(IncrementSize)); |
| 2534 | Hi = DAG.getNode(ISD::SRL, Tmp3.getValueType(), Tmp3, |
| 2535 | DAG.getConstant(RoundWidth, TLI.getShiftAmountTy())); |
| 2536 | Hi = DAG.getTruncStore(Tmp1, Hi, Tmp2, ST->getSrcValue(), |
| 2537 | SVOffset + IncrementSize, ExtraVT, isVolatile, |
| 2538 | MinAlign(Alignment, IncrementSize)); |
| 2539 | } else { |
| 2540 | // Big endian - avoid unaligned stores. |
| 2541 | // TRUNCSTORE:i24 X -> TRUNCSTORE:i16 (srl X, 8), TRUNCSTORE@+2:i8 X |
| 2542 | // Store the top RoundWidth bits. |
| 2543 | Hi = DAG.getNode(ISD::SRL, Tmp3.getValueType(), Tmp3, |
| 2544 | DAG.getConstant(ExtraWidth, TLI.getShiftAmountTy())); |
| 2545 | Hi = DAG.getTruncStore(Tmp1, Hi, Tmp2, ST->getSrcValue(), SVOffset, |
| 2546 | RoundVT, isVolatile, Alignment); |
| 2547 | |
| 2548 | // Store the remaining ExtraWidth bits. |
| 2549 | IncrementSize = RoundWidth / 8; |
| 2550 | Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2, |
| 2551 | DAG.getIntPtrConstant(IncrementSize)); |
| 2552 | Lo = DAG.getTruncStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), |
| 2553 | SVOffset + IncrementSize, ExtraVT, isVolatile, |
| 2554 | MinAlign(Alignment, IncrementSize)); |
Lauro Ramos Venancio | f3c13c8 | 2007-08-01 19:34:21 +0000 | [diff] [blame] | 2555 | } |
Duncan Sands | 7e85720 | 2008-01-22 07:17:34 +0000 | [diff] [blame] | 2556 | |
| 2557 | // The order of the stores doesn't matter. |
| 2558 | Result = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo, Hi); |
| 2559 | } else { |
| 2560 | if (Tmp1 != ST->getChain() || Tmp3 != ST->getValue() || |
| 2561 | Tmp2 != ST->getBasePtr()) |
| 2562 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp3, Tmp2, |
| 2563 | ST->getOffset()); |
| 2564 | |
| 2565 | switch (TLI.getTruncStoreAction(ST->getValue().getValueType(), StVT)) { |
| 2566 | default: assert(0 && "This action is not supported yet!"); |
| 2567 | case TargetLowering::Legal: |
| 2568 | // If this is an unaligned store and the target doesn't support it, |
| 2569 | // expand it. |
| 2570 | if (!TLI.allowsUnalignedMemoryAccesses()) { |
| 2571 | unsigned ABIAlignment = TLI.getTargetData()-> |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 2572 | getABITypeAlignment(MVT::getTypeForValueType(ST->getMemoryVT())); |
Duncan Sands | 7e85720 | 2008-01-22 07:17:34 +0000 | [diff] [blame] | 2573 | if (ST->getAlignment() < ABIAlignment) |
| 2574 | Result = ExpandUnalignedStore(cast<StoreSDNode>(Result.Val), DAG, |
| 2575 | TLI); |
| 2576 | } |
| 2577 | break; |
| 2578 | case TargetLowering::Custom: |
| 2579 | Result = TLI.LowerOperation(Result, DAG); |
| 2580 | break; |
| 2581 | case Expand: |
| 2582 | // TRUNCSTORE:i16 i32 -> STORE i16 |
| 2583 | assert(isTypeLegal(StVT) && "Do not know how to expand this store!"); |
| 2584 | Tmp3 = DAG.getNode(ISD::TRUNCATE, StVT, Tmp3); |
| 2585 | Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), SVOffset, |
| 2586 | isVolatile, Alignment); |
| 2587 | break; |
| 2588 | } |
Evan Cheng | f3fd9fe | 2005-12-23 07:29:34 +0000 | [diff] [blame] | 2589 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2590 | } |
| 2591 | break; |
Evan Cheng | f3fd9fe | 2005-12-23 07:29:34 +0000 | [diff] [blame] | 2592 | } |
Andrew Lenharth | 9576212 | 2005-03-31 21:24:06 +0000 | [diff] [blame] | 2593 | case ISD::PCMARKER: |
| 2594 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2595 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
Andrew Lenharth | 9576212 | 2005-03-31 21:24:06 +0000 | [diff] [blame] | 2596 | break; |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2597 | case ISD::STACKSAVE: |
| 2598 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2599 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 2600 | Tmp1 = Result.getValue(0); |
| 2601 | Tmp2 = Result.getValue(1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2602 | |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2603 | switch (TLI.getOperationAction(ISD::STACKSAVE, MVT::Other)) { |
| 2604 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2605 | case TargetLowering::Legal: break; |
| 2606 | case TargetLowering::Custom: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2607 | Tmp3 = TLI.LowerOperation(Result, DAG); |
| 2608 | if (Tmp3.Val) { |
| 2609 | Tmp1 = LegalizeOp(Tmp3); |
| 2610 | Tmp2 = LegalizeOp(Tmp3.getValue(1)); |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2611 | } |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2612 | break; |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2613 | case TargetLowering::Expand: |
Chris Lattner | 4f0d8e4 | 2006-01-13 17:48:44 +0000 | [diff] [blame] | 2614 | // Expand to CopyFromReg if the target set |
| 2615 | // StackPointerRegisterToSaveRestore. |
| 2616 | if (unsigned SP = TLI.getStackPointerRegisterToSaveRestore()) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2617 | Tmp1 = DAG.getCopyFromReg(Result.getOperand(0), SP, |
Chris Lattner | 4f0d8e4 | 2006-01-13 17:48:44 +0000 | [diff] [blame] | 2618 | Node->getValueType(0)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2619 | Tmp2 = Tmp1.getValue(1); |
Chris Lattner | 4f0d8e4 | 2006-01-13 17:48:44 +0000 | [diff] [blame] | 2620 | } else { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2621 | Tmp1 = DAG.getNode(ISD::UNDEF, Node->getValueType(0)); |
| 2622 | Tmp2 = Node->getOperand(0); |
Chris Lattner | 4f0d8e4 | 2006-01-13 17:48:44 +0000 | [diff] [blame] | 2623 | } |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2624 | break; |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2625 | } |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2626 | |
| 2627 | // Since stacksave produce two values, make sure to remember that we |
| 2628 | // legalized both of them. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2629 | AddLegalizedOperand(SDOperand(Node, 0), Tmp1); |
| 2630 | AddLegalizedOperand(SDOperand(Node, 1), Tmp2); |
| 2631 | return Op.ResNo ? Tmp2 : Tmp1; |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2632 | |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2633 | case ISD::STACKRESTORE: |
| 2634 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 2635 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2636 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2637 | |
| 2638 | switch (TLI.getOperationAction(ISD::STACKRESTORE, MVT::Other)) { |
| 2639 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2640 | case TargetLowering::Legal: break; |
| 2641 | case TargetLowering::Custom: |
| 2642 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2643 | if (Tmp1.Val) Result = Tmp1; |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2644 | break; |
| 2645 | case TargetLowering::Expand: |
Chris Lattner | 4f0d8e4 | 2006-01-13 17:48:44 +0000 | [diff] [blame] | 2646 | // Expand to CopyToReg if the target set |
| 2647 | // StackPointerRegisterToSaveRestore. |
| 2648 | if (unsigned SP = TLI.getStackPointerRegisterToSaveRestore()) { |
| 2649 | Result = DAG.getCopyToReg(Tmp1, SP, Tmp2); |
| 2650 | } else { |
| 2651 | Result = Tmp1; |
| 2652 | } |
Chris Lattner | 140d53c | 2006-01-13 02:50:02 +0000 | [diff] [blame] | 2653 | break; |
| 2654 | } |
| 2655 | break; |
| 2656 | |
Andrew Lenharth | 51b8d54 | 2005-11-11 16:47:30 +0000 | [diff] [blame] | 2657 | case ISD::READCYCLECOUNTER: |
| 2658 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2659 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Evan Cheng | f0b3ba6 | 2006-11-29 08:26:18 +0000 | [diff] [blame] | 2660 | switch (TLI.getOperationAction(ISD::READCYCLECOUNTER, |
| 2661 | Node->getValueType(0))) { |
| 2662 | default: assert(0 && "This action is not supported yet!"); |
Evan Cheng | 6a16c5a | 2006-11-29 19:13:47 +0000 | [diff] [blame] | 2663 | case TargetLowering::Legal: |
| 2664 | Tmp1 = Result.getValue(0); |
| 2665 | Tmp2 = Result.getValue(1); |
| 2666 | break; |
Evan Cheng | f0b3ba6 | 2006-11-29 08:26:18 +0000 | [diff] [blame] | 2667 | case TargetLowering::Custom: |
| 2668 | Result = TLI.LowerOperation(Result, DAG); |
Evan Cheng | 6a16c5a | 2006-11-29 19:13:47 +0000 | [diff] [blame] | 2669 | Tmp1 = LegalizeOp(Result.getValue(0)); |
| 2670 | Tmp2 = LegalizeOp(Result.getValue(1)); |
Evan Cheng | f0b3ba6 | 2006-11-29 08:26:18 +0000 | [diff] [blame] | 2671 | break; |
| 2672 | } |
Andrew Lenharth | 49c709f | 2005-12-02 04:56:24 +0000 | [diff] [blame] | 2673 | |
| 2674 | // Since rdcc produce two values, make sure to remember that we legalized |
| 2675 | // both of them. |
Evan Cheng | 6a16c5a | 2006-11-29 19:13:47 +0000 | [diff] [blame] | 2676 | AddLegalizedOperand(SDOperand(Node, 0), Tmp1); |
| 2677 | AddLegalizedOperand(SDOperand(Node, 1), Tmp2); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2678 | return Result; |
Andrew Lenharth | f70e30b | 2005-11-20 21:32:07 +0000 | [diff] [blame] | 2679 | |
Chris Lattner | 2ee743f | 2005-01-14 22:08:15 +0000 | [diff] [blame] | 2680 | case ISD::SELECT: |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 2681 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 2682 | case Expand: assert(0 && "It's impossible to expand bools"); |
| 2683 | case Legal: |
| 2684 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the condition. |
| 2685 | break; |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 2686 | case Promote: { |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 2687 | Tmp1 = PromoteOp(Node->getOperand(0)); // Promote the condition. |
Chris Lattner | b6c8060 | 2006-11-28 01:03:30 +0000 | [diff] [blame] | 2688 | // Make sure the condition is either zero or one. |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 2689 | unsigned BitWidth = Tmp1.getValueSizeInBits(); |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2690 | if (!DAG.MaskedValueIsZero(Tmp1, |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 2691 | APInt::getHighBitsSet(BitWidth, BitWidth-1))) |
Chris Lattner | b6c8060 | 2006-11-28 01:03:30 +0000 | [diff] [blame] | 2692 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, MVT::i1); |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 2693 | break; |
| 2694 | } |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 2695 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2696 | Tmp2 = LegalizeOp(Node->getOperand(1)); // TrueVal |
Chris Lattner | 2ee743f | 2005-01-14 22:08:15 +0000 | [diff] [blame] | 2697 | Tmp3 = LegalizeOp(Node->getOperand(2)); // FalseVal |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2698 | |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2699 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2700 | |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 2701 | switch (TLI.getOperationAction(ISD::SELECT, Tmp2.getValueType())) { |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2702 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2703 | case TargetLowering::Legal: break; |
| 2704 | case TargetLowering::Custom: { |
| 2705 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2706 | if (Tmp1.Val) Result = Tmp1; |
| 2707 | break; |
| 2708 | } |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 2709 | case TargetLowering::Expand: |
| 2710 | if (Tmp1.getOpcode() == ISD::SETCC) { |
| 2711 | Result = DAG.getSelectCC(Tmp1.getOperand(0), Tmp1.getOperand(1), |
| 2712 | Tmp2, Tmp3, |
| 2713 | cast<CondCodeSDNode>(Tmp1.getOperand(2))->get()); |
| 2714 | } else { |
| 2715 | Result = DAG.getSelectCC(Tmp1, |
| 2716 | DAG.getConstant(0, Tmp1.getValueType()), |
| 2717 | Tmp2, Tmp3, ISD::SETNE); |
| 2718 | } |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2719 | break; |
| 2720 | case TargetLowering::Promote: { |
| 2721 | MVT::ValueType NVT = |
| 2722 | TLI.getTypeToPromoteTo(ISD::SELECT, Tmp2.getValueType()); |
| 2723 | unsigned ExtOp, TruncOp; |
Evan Cheng | 41f6cbb | 2006-04-12 16:33:18 +0000 | [diff] [blame] | 2724 | if (MVT::isVector(Tmp2.getValueType())) { |
| 2725 | ExtOp = ISD::BIT_CONVERT; |
| 2726 | TruncOp = ISD::BIT_CONVERT; |
| 2727 | } else if (MVT::isInteger(Tmp2.getValueType())) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2728 | ExtOp = ISD::ANY_EXTEND; |
| 2729 | TruncOp = ISD::TRUNCATE; |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2730 | } else { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2731 | ExtOp = ISD::FP_EXTEND; |
| 2732 | TruncOp = ISD::FP_ROUND; |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2733 | } |
| 2734 | // Promote each of the values to the new type. |
| 2735 | Tmp2 = DAG.getNode(ExtOp, NVT, Tmp2); |
| 2736 | Tmp3 = DAG.getNode(ExtOp, NVT, Tmp3); |
| 2737 | // Perform the larger operation, then round down. |
| 2738 | Result = DAG.getNode(ISD::SELECT, NVT, Tmp1, Tmp2,Tmp3); |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 2739 | if (TruncOp != ISD::FP_ROUND) |
| 2740 | Result = DAG.getNode(TruncOp, Node->getValueType(0), Result); |
| 2741 | else |
| 2742 | Result = DAG.getNode(TruncOp, Node->getValueType(0), Result, |
| 2743 | DAG.getIntPtrConstant(0)); |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2744 | break; |
| 2745 | } |
| 2746 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2747 | break; |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 2748 | case ISD::SELECT_CC: { |
| 2749 | Tmp1 = Node->getOperand(0); // LHS |
| 2750 | Tmp2 = Node->getOperand(1); // RHS |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 2751 | Tmp3 = LegalizeOp(Node->getOperand(2)); // True |
| 2752 | Tmp4 = LegalizeOp(Node->getOperand(3)); // False |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 2753 | SDOperand CC = Node->getOperand(4); |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 2754 | |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 2755 | LegalizeSetCCOperands(Tmp1, Tmp2, CC); |
| 2756 | |
| 2757 | // If we didn't get both a LHS and RHS back from LegalizeSetCCOperands, |
| 2758 | // the LHS is a legal SETCC itself. In this case, we need to compare |
| 2759 | // the result against zero to select between true and false values. |
| 2760 | if (Tmp2.Val == 0) { |
| 2761 | Tmp2 = DAG.getConstant(0, Tmp1.getValueType()); |
| 2762 | CC = DAG.getCondCode(ISD::SETNE); |
| 2763 | } |
| 2764 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3, Tmp4, CC); |
| 2765 | |
| 2766 | // Everything is legal, see if we should expand this op or something. |
| 2767 | switch (TLI.getOperationAction(ISD::SELECT_CC, Tmp3.getValueType())) { |
| 2768 | default: assert(0 && "This action is not supported yet!"); |
| 2769 | case TargetLowering::Legal: break; |
| 2770 | case TargetLowering::Custom: |
| 2771 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2772 | if (Tmp1.Val) Result = Tmp1; |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 2773 | break; |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 2774 | } |
| 2775 | break; |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 2776 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2777 | case ISD::SETCC: |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 2778 | Tmp1 = Node->getOperand(0); |
| 2779 | Tmp2 = Node->getOperand(1); |
| 2780 | Tmp3 = Node->getOperand(2); |
| 2781 | LegalizeSetCCOperands(Tmp1, Tmp2, Tmp3); |
| 2782 | |
| 2783 | // If we had to Expand the SetCC operands into a SELECT node, then it may |
| 2784 | // not always be possible to return a true LHS & RHS. In this case, just |
| 2785 | // return the value we legalized, returned in the LHS |
| 2786 | if (Tmp2.Val == 0) { |
| 2787 | Result = Tmp1; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2788 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2789 | } |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 2790 | |
Chris Lattner | 73e142f | 2006-01-30 22:43:50 +0000 | [diff] [blame] | 2791 | switch (TLI.getOperationAction(ISD::SETCC, Tmp1.getValueType())) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2792 | default: assert(0 && "Cannot handle this action for SETCC yet!"); |
| 2793 | case TargetLowering::Custom: |
| 2794 | isCustom = true; |
| 2795 | // FALLTHROUGH. |
| 2796 | case TargetLowering::Legal: |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 2797 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2798 | if (isCustom) { |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 2799 | Tmp4 = TLI.LowerOperation(Result, DAG); |
| 2800 | if (Tmp4.Val) Result = Tmp4; |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2801 | } |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 2802 | break; |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 2803 | case TargetLowering::Promote: { |
| 2804 | // First step, figure out the appropriate operation to use. |
| 2805 | // Allow SETCC to not be supported for all legal data types |
| 2806 | // Mostly this targets FP |
| 2807 | MVT::ValueType NewInTy = Node->getOperand(0).getValueType(); |
Chris Lattner | 00755df | 2007-02-04 00:27:56 +0000 | [diff] [blame] | 2808 | MVT::ValueType OldVT = NewInTy; OldVT = OldVT; |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 2809 | |
| 2810 | // Scan for the appropriate larger type to use. |
| 2811 | while (1) { |
| 2812 | NewInTy = (MVT::ValueType)(NewInTy+1); |
| 2813 | |
| 2814 | assert(MVT::isInteger(NewInTy) == MVT::isInteger(OldVT) && |
| 2815 | "Fell off of the edge of the integer world"); |
| 2816 | assert(MVT::isFloatingPoint(NewInTy) == MVT::isFloatingPoint(OldVT) && |
| 2817 | "Fell off of the edge of the floating point world"); |
| 2818 | |
| 2819 | // If the target supports SETCC of this type, use it. |
Chris Lattner | 1ccf26a | 2005-12-22 05:23:45 +0000 | [diff] [blame] | 2820 | if (TLI.isOperationLegal(ISD::SETCC, NewInTy)) |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 2821 | break; |
| 2822 | } |
| 2823 | if (MVT::isInteger(NewInTy)) |
| 2824 | assert(0 && "Cannot promote Legal Integer SETCC yet"); |
| 2825 | else { |
| 2826 | Tmp1 = DAG.getNode(ISD::FP_EXTEND, NewInTy, Tmp1); |
| 2827 | Tmp2 = DAG.getNode(ISD::FP_EXTEND, NewInTy, Tmp2); |
| 2828 | } |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2829 | Tmp1 = LegalizeOp(Tmp1); |
| 2830 | Tmp2 = LegalizeOp(Tmp2); |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 2831 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
Evan Cheng | 433f8ac | 2006-01-17 19:47:13 +0000 | [diff] [blame] | 2832 | Result = LegalizeOp(Result); |
Andrew Lenharth | 5e3efbc | 2005-08-29 20:46:51 +0000 | [diff] [blame] | 2833 | break; |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 2834 | } |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 2835 | case TargetLowering::Expand: |
| 2836 | // Expand a setcc node into a select_cc of the same condition, lhs, and |
| 2837 | // rhs that selects between const 1 (true) and const 0 (false). |
| 2838 | MVT::ValueType VT = Node->getValueType(0); |
| 2839 | Result = DAG.getNode(ISD::SELECT_CC, VT, Tmp1, Tmp2, |
| 2840 | DAG.getConstant(1, VT), DAG.getConstant(0, VT), |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 2841 | Tmp3); |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 2842 | break; |
| 2843 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2844 | break; |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 2845 | case ISD::MEMSET: |
| 2846 | case ISD::MEMCPY: |
| 2847 | case ISD::MEMMOVE: { |
Chris Lattner | deb692e | 2005-02-01 18:38:28 +0000 | [diff] [blame] | 2848 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Chain |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 2849 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Pointer |
| 2850 | |
| 2851 | if (Node->getOpcode() == ISD::MEMSET) { // memset = ubyte |
| 2852 | switch (getTypeAction(Node->getOperand(2).getValueType())) { |
| 2853 | case Expand: assert(0 && "Cannot expand a byte!"); |
| 2854 | case Legal: |
Chris Lattner | deb692e | 2005-02-01 18:38:28 +0000 | [diff] [blame] | 2855 | Tmp3 = LegalizeOp(Node->getOperand(2)); |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 2856 | break; |
| 2857 | case Promote: |
Chris Lattner | deb692e | 2005-02-01 18:38:28 +0000 | [diff] [blame] | 2858 | Tmp3 = PromoteOp(Node->getOperand(2)); |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 2859 | break; |
| 2860 | } |
| 2861 | } else { |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2862 | Tmp3 = LegalizeOp(Node->getOperand(2)); // memcpy/move = pointer, |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 2863 | } |
Chris Lattner | 272455b | 2005-02-02 03:44:41 +0000 | [diff] [blame] | 2864 | |
| 2865 | SDOperand Tmp4; |
| 2866 | switch (getTypeAction(Node->getOperand(3).getValueType())) { |
Chris Lattner | 6814f15 | 2005-07-13 01:42:45 +0000 | [diff] [blame] | 2867 | case Expand: { |
| 2868 | // Length is too big, just take the lo-part of the length. |
| 2869 | SDOperand HiPart; |
Chris Lattner | fa9aa2b | 2006-11-07 04:11:44 +0000 | [diff] [blame] | 2870 | ExpandOp(Node->getOperand(3), Tmp4, HiPart); |
Chris Lattner | 6814f15 | 2005-07-13 01:42:45 +0000 | [diff] [blame] | 2871 | break; |
| 2872 | } |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 2873 | case Legal: |
| 2874 | Tmp4 = LegalizeOp(Node->getOperand(3)); |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 2875 | break; |
| 2876 | case Promote: |
| 2877 | Tmp4 = PromoteOp(Node->getOperand(3)); |
Chris Lattner | 272455b | 2005-02-02 03:44:41 +0000 | [diff] [blame] | 2878 | break; |
| 2879 | } |
| 2880 | |
| 2881 | SDOperand Tmp5; |
| 2882 | switch (getTypeAction(Node->getOperand(4).getValueType())) { // uint |
| 2883 | case Expand: assert(0 && "Cannot expand this yet!"); |
| 2884 | case Legal: |
| 2885 | Tmp5 = LegalizeOp(Node->getOperand(4)); |
| 2886 | break; |
| 2887 | case Promote: |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 2888 | Tmp5 = PromoteOp(Node->getOperand(4)); |
| 2889 | break; |
| 2890 | } |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2891 | |
Rafael Espindola | 5c0d6ed | 2007-10-19 10:41:11 +0000 | [diff] [blame] | 2892 | SDOperand Tmp6; |
| 2893 | switch (getTypeAction(Node->getOperand(5).getValueType())) { // bool |
| 2894 | case Expand: assert(0 && "Cannot expand this yet!"); |
| 2895 | case Legal: |
| 2896 | Tmp6 = LegalizeOp(Node->getOperand(5)); |
| 2897 | break; |
| 2898 | case Promote: |
| 2899 | Tmp6 = PromoteOp(Node->getOperand(5)); |
| 2900 | break; |
| 2901 | } |
| 2902 | |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2903 | switch (TLI.getOperationAction(Node->getOpcode(), MVT::Other)) { |
| 2904 | default: assert(0 && "This action not implemented for this operation!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2905 | case TargetLowering::Custom: |
| 2906 | isCustom = true; |
| 2907 | // FALLTHROUGH |
Rafael Espindola | 5c0d6ed | 2007-10-19 10:41:11 +0000 | [diff] [blame] | 2908 | case TargetLowering::Legal: { |
| 2909 | SDOperand Ops[] = { Tmp1, Tmp2, Tmp3, Tmp4, Tmp5, Tmp6 }; |
| 2910 | Result = DAG.UpdateNodeOperands(Result, Ops, 6); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2911 | if (isCustom) { |
| 2912 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2913 | if (Tmp1.Val) Result = Tmp1; |
| 2914 | } |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2915 | break; |
Rafael Espindola | 5c0d6ed | 2007-10-19 10:41:11 +0000 | [diff] [blame] | 2916 | } |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2917 | case TargetLowering::Expand: { |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 2918 | // Otherwise, the target does not support this operation. Lower the |
| 2919 | // operation to an explicit libcall as appropriate. |
| 2920 | MVT::ValueType IntPtr = TLI.getPointerTy(); |
Owen Anderson | a69571c | 2006-05-03 01:29:57 +0000 | [diff] [blame] | 2921 | const Type *IntPtrTy = TLI.getTargetData()->getIntPtrType(); |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 2922 | TargetLowering::ArgListTy Args; |
| 2923 | TargetLowering::ArgListEntry Entry; |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 2924 | |
Reid Spencer | 3bfbf4e | 2005-01-12 14:53:45 +0000 | [diff] [blame] | 2925 | const char *FnName = 0; |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 2926 | if (Node->getOpcode() == ISD::MEMSET) { |
Anton Korobeynikov | d0b82b3 | 2007-03-07 16:25:09 +0000 | [diff] [blame] | 2927 | Entry.Node = Tmp2; Entry.Ty = IntPtrTy; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 2928 | Args.push_back(Entry); |
Chris Lattner | dca7abe | 2006-02-20 06:38:35 +0000 | [diff] [blame] | 2929 | // Extend the (previously legalized) ubyte argument to be an int value |
| 2930 | // for the call. |
| 2931 | if (Tmp3.getValueType() > MVT::i32) |
| 2932 | Tmp3 = DAG.getNode(ISD::TRUNCATE, MVT::i32, Tmp3); |
| 2933 | else |
| 2934 | Tmp3 = DAG.getNode(ISD::ZERO_EXTEND, MVT::i32, Tmp3); |
Anton Korobeynikov | d0b82b3 | 2007-03-07 16:25:09 +0000 | [diff] [blame] | 2935 | Entry.Node = Tmp3; Entry.Ty = Type::Int32Ty; Entry.isSExt = true; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 2936 | Args.push_back(Entry); |
Anton Korobeynikov | d0b82b3 | 2007-03-07 16:25:09 +0000 | [diff] [blame] | 2937 | Entry.Node = Tmp4; Entry.Ty = IntPtrTy; Entry.isSExt = false; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 2938 | Args.push_back(Entry); |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 2939 | |
| 2940 | FnName = "memset"; |
| 2941 | } else if (Node->getOpcode() == ISD::MEMCPY || |
| 2942 | Node->getOpcode() == ISD::MEMMOVE) { |
Anton Korobeynikov | b25fe82 | 2007-02-01 08:39:52 +0000 | [diff] [blame] | 2943 | Entry.Ty = IntPtrTy; |
Reid Spencer | b47b25c | 2007-01-03 04:22:32 +0000 | [diff] [blame] | 2944 | Entry.Node = Tmp2; Args.push_back(Entry); |
| 2945 | Entry.Node = Tmp3; Args.push_back(Entry); |
| 2946 | Entry.Node = Tmp4; Args.push_back(Entry); |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 2947 | FnName = Node->getOpcode() == ISD::MEMMOVE ? "memmove" : "memcpy"; |
| 2948 | } else { |
| 2949 | assert(0 && "Unknown op!"); |
| 2950 | } |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 2951 | |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 2952 | std::pair<SDOperand,SDOperand> CallResult = |
Duncan Sands | 00fee65 | 2008-02-14 17:28:50 +0000 | [diff] [blame] | 2953 | TLI.LowerCallTo(Tmp1, Type::VoidTy, |
| 2954 | false, false, false, CallingConv::C, false, |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 2955 | DAG.getExternalSymbol(FnName, IntPtr), Args, DAG); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2956 | Result = CallResult.second; |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2957 | break; |
| 2958 | } |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 2959 | } |
| 2960 | break; |
| 2961 | } |
Chris Lattner | 52d08bd | 2005-05-09 20:23:03 +0000 | [diff] [blame] | 2962 | |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 2963 | case ISD::SHL_PARTS: |
| 2964 | case ISD::SRA_PARTS: |
| 2965 | case ISD::SRL_PARTS: { |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 2966 | SmallVector<SDOperand, 8> Ops; |
Chris Lattner | 84f6788 | 2005-01-20 18:52:28 +0000 | [diff] [blame] | 2967 | bool Changed = false; |
| 2968 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) { |
| 2969 | Ops.push_back(LegalizeOp(Node->getOperand(i))); |
| 2970 | Changed |= Ops.back() != Node->getOperand(i); |
| 2971 | } |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 2972 | if (Changed) |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 2973 | Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 2974 | |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 2975 | switch (TLI.getOperationAction(Node->getOpcode(), |
| 2976 | Node->getValueType(0))) { |
| 2977 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2978 | case TargetLowering::Legal: break; |
| 2979 | case TargetLowering::Custom: |
| 2980 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 2981 | if (Tmp1.Val) { |
| 2982 | SDOperand Tmp2, RetVal(0, 0); |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 2983 | for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 2984 | Tmp2 = LegalizeOp(Tmp1.getValue(i)); |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 2985 | AddLegalizedOperand(SDOperand(Node, i), Tmp2); |
| 2986 | if (i == Op.ResNo) |
Evan Cheng | 12f2274 | 2006-01-19 04:54:52 +0000 | [diff] [blame] | 2987 | RetVal = Tmp2; |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 2988 | } |
Chris Lattner | 269f8c0 | 2006-01-10 19:43:26 +0000 | [diff] [blame] | 2989 | assert(RetVal.Val && "Illegal result number"); |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 2990 | return RetVal; |
| 2991 | } |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 2992 | break; |
| 2993 | } |
| 2994 | |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 2995 | // Since these produce multiple values, make sure to remember that we |
| 2996 | // legalized all of them. |
| 2997 | for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) |
| 2998 | AddLegalizedOperand(SDOperand(Node, i), Result.getValue(i)); |
| 2999 | return Result.getValue(Op.ResNo); |
Chris Lattner | 84f6788 | 2005-01-20 18:52:28 +0000 | [diff] [blame] | 3000 | } |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3001 | |
| 3002 | // Binary operators |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3003 | case ISD::ADD: |
| 3004 | case ISD::SUB: |
| 3005 | case ISD::MUL: |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 3006 | case ISD::MULHS: |
| 3007 | case ISD::MULHU: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3008 | case ISD::UDIV: |
| 3009 | case ISD::SDIV: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3010 | case ISD::AND: |
| 3011 | case ISD::OR: |
| 3012 | case ISD::XOR: |
Chris Lattner | 03c0cf8 | 2005-01-07 21:45:56 +0000 | [diff] [blame] | 3013 | case ISD::SHL: |
| 3014 | case ISD::SRL: |
| 3015 | case ISD::SRA: |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 3016 | case ISD::FADD: |
| 3017 | case ISD::FSUB: |
| 3018 | case ISD::FMUL: |
| 3019 | case ISD::FDIV: |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3020 | case ISD::FPOW: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3021 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
Andrew Lenharth | f2eb139 | 2005-07-05 19:52:39 +0000 | [diff] [blame] | 3022 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 3023 | case Expand: assert(0 && "Not possible"); |
| 3024 | case Legal: |
| 3025 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the RHS. |
| 3026 | break; |
| 3027 | case Promote: |
| 3028 | Tmp2 = PromoteOp(Node->getOperand(1)); // Promote the RHS. |
| 3029 | break; |
| 3030 | } |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3031 | |
| 3032 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3033 | |
Andrew Lenharth | e8f65f1 | 2005-12-24 23:42:32 +0000 | [diff] [blame] | 3034 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
Chris Lattner | bc70cf8 | 2006-04-02 03:57:31 +0000 | [diff] [blame] | 3035 | default: assert(0 && "BinOp legalize operation not supported"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3036 | case TargetLowering::Legal: break; |
| 3037 | case TargetLowering::Custom: |
| 3038 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 3039 | if (Tmp1.Val) Result = Tmp1; |
Andrew Lenharth | 57030e3 | 2005-12-25 01:07:37 +0000 | [diff] [blame] | 3040 | break; |
Chris Lattner | bc70cf8 | 2006-04-02 03:57:31 +0000 | [diff] [blame] | 3041 | case TargetLowering::Expand: { |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3042 | MVT::ValueType VT = Op.getValueType(); |
| 3043 | |
| 3044 | // See if multiply or divide can be lowered using two-result operations. |
| 3045 | SDVTList VTs = DAG.getVTList(VT, VT); |
| 3046 | if (Node->getOpcode() == ISD::MUL) { |
| 3047 | // We just need the low half of the multiply; try both the signed |
| 3048 | // and unsigned forms. If the target supports both SMUL_LOHI and |
| 3049 | // UMUL_LOHI, form a preference by checking which forms of plain |
| 3050 | // MULH it supports. |
| 3051 | bool HasSMUL_LOHI = TLI.isOperationLegal(ISD::SMUL_LOHI, VT); |
| 3052 | bool HasUMUL_LOHI = TLI.isOperationLegal(ISD::UMUL_LOHI, VT); |
| 3053 | bool HasMULHS = TLI.isOperationLegal(ISD::MULHS, VT); |
| 3054 | bool HasMULHU = TLI.isOperationLegal(ISD::MULHU, VT); |
| 3055 | unsigned OpToUse = 0; |
| 3056 | if (HasSMUL_LOHI && !HasMULHS) { |
| 3057 | OpToUse = ISD::SMUL_LOHI; |
| 3058 | } else if (HasUMUL_LOHI && !HasMULHU) { |
| 3059 | OpToUse = ISD::UMUL_LOHI; |
| 3060 | } else if (HasSMUL_LOHI) { |
| 3061 | OpToUse = ISD::SMUL_LOHI; |
| 3062 | } else if (HasUMUL_LOHI) { |
| 3063 | OpToUse = ISD::UMUL_LOHI; |
| 3064 | } |
| 3065 | if (OpToUse) { |
| 3066 | Result = SDOperand(DAG.getNode(OpToUse, VTs, Tmp1, Tmp2).Val, 0); |
| 3067 | break; |
| 3068 | } |
| 3069 | } |
| 3070 | if (Node->getOpcode() == ISD::MULHS && |
| 3071 | TLI.isOperationLegal(ISD::SMUL_LOHI, VT)) { |
| 3072 | Result = SDOperand(DAG.getNode(ISD::SMUL_LOHI, VTs, Tmp1, Tmp2).Val, 1); |
| 3073 | break; |
| 3074 | } |
| 3075 | if (Node->getOpcode() == ISD::MULHU && |
| 3076 | TLI.isOperationLegal(ISD::UMUL_LOHI, VT)) { |
| 3077 | Result = SDOperand(DAG.getNode(ISD::UMUL_LOHI, VTs, Tmp1, Tmp2).Val, 1); |
| 3078 | break; |
| 3079 | } |
| 3080 | if (Node->getOpcode() == ISD::SDIV && |
| 3081 | TLI.isOperationLegal(ISD::SDIVREM, VT)) { |
| 3082 | Result = SDOperand(DAG.getNode(ISD::SDIVREM, VTs, Tmp1, Tmp2).Val, 0); |
| 3083 | break; |
| 3084 | } |
| 3085 | if (Node->getOpcode() == ISD::UDIV && |
| 3086 | TLI.isOperationLegal(ISD::UDIVREM, VT)) { |
| 3087 | Result = SDOperand(DAG.getNode(ISD::UDIVREM, VTs, Tmp1, Tmp2).Val, 0); |
| 3088 | break; |
| 3089 | } |
| 3090 | |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3091 | // Check to see if we have a libcall for this operator. |
| 3092 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
| 3093 | bool isSigned = false; |
| 3094 | switch (Node->getOpcode()) { |
| 3095 | case ISD::UDIV: |
| 3096 | case ISD::SDIV: |
| 3097 | if (VT == MVT::i32) { |
| 3098 | LC = Node->getOpcode() == ISD::UDIV |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3099 | ? RTLIB::UDIV_I32 : RTLIB::SDIV_I32; |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3100 | isSigned = Node->getOpcode() == ISD::SDIV; |
| 3101 | } |
| 3102 | break; |
| 3103 | case ISD::FPOW: |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 3104 | LC = GetFPLibCall(VT, RTLIB::POW_F32, RTLIB::POW_F64, RTLIB::POW_F80, |
| 3105 | RTLIB::POW_PPCF128); |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3106 | break; |
| 3107 | default: break; |
| 3108 | } |
| 3109 | if (LC != RTLIB::UNKNOWN_LIBCALL) { |
| 3110 | SDOperand Dummy; |
| 3111 | Result = ExpandLibCall(TLI.getLibcallName(LC), Node, isSigned, Dummy); |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 3112 | break; |
| 3113 | } |
| 3114 | |
Chris Lattner | bc70cf8 | 2006-04-02 03:57:31 +0000 | [diff] [blame] | 3115 | assert(MVT::isVector(Node->getValueType(0)) && |
| 3116 | "Cannot expand this binary operator!"); |
| 3117 | // Expand the operation into a bunch of nasty scalar code. |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3118 | Result = LegalizeOp(UnrollVectorOp(Op)); |
Chris Lattner | bc70cf8 | 2006-04-02 03:57:31 +0000 | [diff] [blame] | 3119 | break; |
| 3120 | } |
Evan Cheng | cc98761 | 2006-04-12 21:20:24 +0000 | [diff] [blame] | 3121 | case TargetLowering::Promote: { |
| 3122 | switch (Node->getOpcode()) { |
| 3123 | default: assert(0 && "Do not know how to promote this BinOp!"); |
| 3124 | case ISD::AND: |
| 3125 | case ISD::OR: |
| 3126 | case ISD::XOR: { |
| 3127 | MVT::ValueType OVT = Node->getValueType(0); |
| 3128 | MVT::ValueType NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT); |
| 3129 | assert(MVT::isVector(OVT) && "Cannot promote this BinOp!"); |
| 3130 | // Bit convert each of the values to the new type. |
| 3131 | Tmp1 = DAG.getNode(ISD::BIT_CONVERT, NVT, Tmp1); |
| 3132 | Tmp2 = DAG.getNode(ISD::BIT_CONVERT, NVT, Tmp2); |
| 3133 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 3134 | // Bit convert the result back the original type. |
| 3135 | Result = DAG.getNode(ISD::BIT_CONVERT, OVT, Result); |
| 3136 | break; |
| 3137 | } |
| 3138 | } |
| 3139 | } |
Andrew Lenharth | e8f65f1 | 2005-12-24 23:42:32 +0000 | [diff] [blame] | 3140 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3141 | break; |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 3142 | |
Dan Gohman | e14ea86 | 2007-10-05 14:17:22 +0000 | [diff] [blame] | 3143 | case ISD::SMUL_LOHI: |
| 3144 | case ISD::UMUL_LOHI: |
| 3145 | case ISD::SDIVREM: |
| 3146 | case ISD::UDIVREM: |
| 3147 | // These nodes will only be produced by target-specific lowering, so |
| 3148 | // they shouldn't be here if they aren't legal. |
Duncan Sands | a7c97a7 | 2007-10-16 09:07:20 +0000 | [diff] [blame] | 3149 | assert(TLI.isOperationLegal(Node->getOpcode(), Node->getValueType(0)) && |
Dan Gohman | e14ea86 | 2007-10-05 14:17:22 +0000 | [diff] [blame] | 3150 | "This must be legal!"); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3151 | |
| 3152 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
| 3153 | Tmp2 = LegalizeOp(Node->getOperand(1)); // RHS |
| 3154 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Dan Gohman | e14ea86 | 2007-10-05 14:17:22 +0000 | [diff] [blame] | 3155 | break; |
| 3156 | |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 3157 | case ISD::FCOPYSIGN: // FCOPYSIGN does not require LHS/RHS to match type! |
| 3158 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
| 3159 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 3160 | case Expand: assert(0 && "Not possible"); |
| 3161 | case Legal: |
| 3162 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the RHS. |
| 3163 | break; |
| 3164 | case Promote: |
| 3165 | Tmp2 = PromoteOp(Node->getOperand(1)); // Promote the RHS. |
| 3166 | break; |
| 3167 | } |
| 3168 | |
| 3169 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 3170 | |
| 3171 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 3172 | default: assert(0 && "Operation not supported"); |
| 3173 | case TargetLowering::Custom: |
| 3174 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 3175 | if (Tmp1.Val) Result = Tmp1; |
Chris Lattner | 8f4191d | 2006-03-13 06:08:38 +0000 | [diff] [blame] | 3176 | break; |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 3177 | case TargetLowering::Legal: break; |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 3178 | case TargetLowering::Expand: { |
Evan Cheng | 636c753 | 2007-01-05 23:33:44 +0000 | [diff] [blame] | 3179 | // If this target supports fabs/fneg natively and select is cheap, |
| 3180 | // do this efficiently. |
| 3181 | if (!TLI.isSelectExpensive() && |
| 3182 | TLI.getOperationAction(ISD::FABS, Tmp1.getValueType()) == |
| 3183 | TargetLowering::Legal && |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 3184 | TLI.getOperationAction(ISD::FNEG, Tmp1.getValueType()) == |
Evan Cheng | 636c753 | 2007-01-05 23:33:44 +0000 | [diff] [blame] | 3185 | TargetLowering::Legal) { |
Chris Lattner | 8f4191d | 2006-03-13 06:08:38 +0000 | [diff] [blame] | 3186 | // Get the sign bit of the RHS. |
| 3187 | MVT::ValueType IVT = |
| 3188 | Tmp2.getValueType() == MVT::f32 ? MVT::i32 : MVT::i64; |
| 3189 | SDOperand SignBit = DAG.getNode(ISD::BIT_CONVERT, IVT, Tmp2); |
Scott Michel | 5b8f82e | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 3190 | SignBit = DAG.getSetCC(TLI.getSetCCResultType(SignBit), |
Chris Lattner | 8f4191d | 2006-03-13 06:08:38 +0000 | [diff] [blame] | 3191 | SignBit, DAG.getConstant(0, IVT), ISD::SETLT); |
| 3192 | // Get the absolute value of the result. |
| 3193 | SDOperand AbsVal = DAG.getNode(ISD::FABS, Tmp1.getValueType(), Tmp1); |
| 3194 | // Select between the nabs and abs value based on the sign bit of |
| 3195 | // the input. |
| 3196 | Result = DAG.getNode(ISD::SELECT, AbsVal.getValueType(), SignBit, |
| 3197 | DAG.getNode(ISD::FNEG, AbsVal.getValueType(), |
| 3198 | AbsVal), |
| 3199 | AbsVal); |
| 3200 | Result = LegalizeOp(Result); |
| 3201 | break; |
| 3202 | } |
| 3203 | |
| 3204 | // Otherwise, do bitwise ops! |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 3205 | MVT::ValueType NVT = |
| 3206 | Node->getValueType(0) == MVT::f32 ? MVT::i32 : MVT::i64; |
| 3207 | Result = ExpandFCOPYSIGNToBitwiseOps(Node, NVT, DAG, TLI); |
| 3208 | Result = DAG.getNode(ISD::BIT_CONVERT, Node->getValueType(0), Result); |
| 3209 | Result = LegalizeOp(Result); |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 3210 | break; |
| 3211 | } |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 3212 | } |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 3213 | break; |
| 3214 | |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 3215 | case ISD::ADDC: |
| 3216 | case ISD::SUBC: |
| 3217 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 3218 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 3219 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
| 3220 | // Since this produces two values, make sure to remember that we legalized |
| 3221 | // both of them. |
| 3222 | AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0)); |
| 3223 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
| 3224 | return Result; |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 3225 | |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 3226 | case ISD::ADDE: |
| 3227 | case ISD::SUBE: |
| 3228 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 3229 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 3230 | Tmp3 = LegalizeOp(Node->getOperand(2)); |
| 3231 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); |
| 3232 | // Since this produces two values, make sure to remember that we legalized |
| 3233 | // both of them. |
| 3234 | AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0)); |
| 3235 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
| 3236 | return Result; |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 3237 | |
Nate Begeman | 419f8b6 | 2005-10-18 00:27:41 +0000 | [diff] [blame] | 3238 | case ISD::BUILD_PAIR: { |
| 3239 | MVT::ValueType PairTy = Node->getValueType(0); |
| 3240 | // TODO: handle the case where the Lo and Hi operands are not of legal type |
| 3241 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Lo |
| 3242 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Hi |
| 3243 | switch (TLI.getOperationAction(ISD::BUILD_PAIR, PairTy)) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3244 | case TargetLowering::Promote: |
| 3245 | case TargetLowering::Custom: |
| 3246 | assert(0 && "Cannot promote/custom this yet!"); |
Nate Begeman | 419f8b6 | 2005-10-18 00:27:41 +0000 | [diff] [blame] | 3247 | case TargetLowering::Legal: |
| 3248 | if (Tmp1 != Node->getOperand(0) || Tmp2 != Node->getOperand(1)) |
| 3249 | Result = DAG.getNode(ISD::BUILD_PAIR, PairTy, Tmp1, Tmp2); |
| 3250 | break; |
Nate Begeman | 419f8b6 | 2005-10-18 00:27:41 +0000 | [diff] [blame] | 3251 | case TargetLowering::Expand: |
| 3252 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, PairTy, Tmp1); |
| 3253 | Tmp2 = DAG.getNode(ISD::ANY_EXTEND, PairTy, Tmp2); |
| 3254 | Tmp2 = DAG.getNode(ISD::SHL, PairTy, Tmp2, |
| 3255 | DAG.getConstant(MVT::getSizeInBits(PairTy)/2, |
| 3256 | TLI.getShiftAmountTy())); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3257 | Result = DAG.getNode(ISD::OR, PairTy, Tmp1, Tmp2); |
Nate Begeman | 419f8b6 | 2005-10-18 00:27:41 +0000 | [diff] [blame] | 3258 | break; |
| 3259 | } |
| 3260 | break; |
| 3261 | } |
| 3262 | |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 3263 | case ISD::UREM: |
| 3264 | case ISD::SREM: |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 3265 | case ISD::FREM: |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 3266 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
| 3267 | Tmp2 = LegalizeOp(Node->getOperand(1)); // RHS |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3268 | |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 3269 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3270 | case TargetLowering::Promote: assert(0 && "Cannot promote this yet!"); |
| 3271 | case TargetLowering::Custom: |
| 3272 | isCustom = true; |
| 3273 | // FALLTHROUGH |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 3274 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3275 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3276 | if (isCustom) { |
| 3277 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 3278 | if (Tmp1.Val) Result = Tmp1; |
| 3279 | } |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 3280 | break; |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3281 | case TargetLowering::Expand: { |
Evan Cheng | 6b5578f | 2006-09-18 23:28:33 +0000 | [diff] [blame] | 3282 | unsigned DivOpc= (Node->getOpcode() == ISD::UREM) ? ISD::UDIV : ISD::SDIV; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 3283 | bool isSigned = DivOpc == ISD::SDIV; |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3284 | MVT::ValueType VT = Node->getValueType(0); |
| 3285 | |
| 3286 | // See if remainder can be lowered using two-result operations. |
| 3287 | SDVTList VTs = DAG.getVTList(VT, VT); |
| 3288 | if (Node->getOpcode() == ISD::SREM && |
| 3289 | TLI.isOperationLegal(ISD::SDIVREM, VT)) { |
| 3290 | Result = SDOperand(DAG.getNode(ISD::SDIVREM, VTs, Tmp1, Tmp2).Val, 1); |
| 3291 | break; |
| 3292 | } |
| 3293 | if (Node->getOpcode() == ISD::UREM && |
| 3294 | TLI.isOperationLegal(ISD::UDIVREM, VT)) { |
| 3295 | Result = SDOperand(DAG.getNode(ISD::UDIVREM, VTs, Tmp1, Tmp2).Val, 1); |
| 3296 | break; |
| 3297 | } |
| 3298 | |
| 3299 | if (MVT::isInteger(VT)) { |
| 3300 | if (TLI.getOperationAction(DivOpc, VT) == |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 3301 | TargetLowering::Legal) { |
| 3302 | // X % Y -> X-X/Y*Y |
Evan Cheng | 6b5578f | 2006-09-18 23:28:33 +0000 | [diff] [blame] | 3303 | Result = DAG.getNode(DivOpc, VT, Tmp1, Tmp2); |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 3304 | Result = DAG.getNode(ISD::MUL, VT, Result, Tmp2); |
| 3305 | Result = DAG.getNode(ISD::SUB, VT, Tmp1, Result); |
Dan Gohman | 8017631 | 2007-11-05 23:35:22 +0000 | [diff] [blame] | 3306 | } else if (MVT::isVector(VT)) { |
| 3307 | Result = LegalizeOp(UnrollVectorOp(Op)); |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 3308 | } else { |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3309 | assert(VT == MVT::i32 && |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 3310 | "Cannot expand this binary operator!"); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3311 | RTLIB::Libcall LC = Node->getOpcode() == ISD::UREM |
| 3312 | ? RTLIB::UREM_I32 : RTLIB::SREM_I32; |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 3313 | SDOperand Dummy; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3314 | Result = ExpandLibCall(TLI.getLibcallName(LC), Node, isSigned, Dummy); |
Evan Cheng | 52cc1ea | 2006-09-18 21:49:04 +0000 | [diff] [blame] | 3315 | } |
Dan Gohman | 0d97426 | 2007-11-06 22:11:54 +0000 | [diff] [blame] | 3316 | } else { |
| 3317 | assert(MVT::isFloatingPoint(VT) && |
| 3318 | "remainder op must have integer or floating-point type"); |
Dan Gohman | 8017631 | 2007-11-05 23:35:22 +0000 | [diff] [blame] | 3319 | if (MVT::isVector(VT)) { |
| 3320 | Result = LegalizeOp(UnrollVectorOp(Op)); |
| 3321 | } else { |
| 3322 | // Floating point mod -> fmod libcall. |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 3323 | RTLIB::Libcall LC = GetFPLibCall(VT, RTLIB::REM_F32, RTLIB::REM_F64, |
| 3324 | RTLIB::REM_F80, RTLIB::REM_PPCF128); |
Dan Gohman | 8017631 | 2007-11-05 23:35:22 +0000 | [diff] [blame] | 3325 | SDOperand Dummy; |
| 3326 | Result = ExpandLibCall(TLI.getLibcallName(LC), Node, |
| 3327 | false/*sign irrelevant*/, Dummy); |
| 3328 | } |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 3329 | } |
| 3330 | break; |
| 3331 | } |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 3332 | } |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 3333 | break; |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3334 | case ISD::VAARG: { |
| 3335 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 3336 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. |
| 3337 | |
Chris Lattner | 5c62f33 | 2006-01-28 07:42:08 +0000 | [diff] [blame] | 3338 | MVT::ValueType VT = Node->getValueType(0); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3339 | switch (TLI.getOperationAction(Node->getOpcode(), MVT::Other)) { |
| 3340 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3341 | case TargetLowering::Custom: |
| 3342 | isCustom = true; |
| 3343 | // FALLTHROUGH |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3344 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3345 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
| 3346 | Result = Result.getValue(0); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3347 | Tmp1 = Result.getValue(1); |
| 3348 | |
| 3349 | if (isCustom) { |
| 3350 | Tmp2 = TLI.LowerOperation(Result, DAG); |
| 3351 | if (Tmp2.Val) { |
| 3352 | Result = LegalizeOp(Tmp2); |
| 3353 | Tmp1 = LegalizeOp(Tmp2.getValue(1)); |
| 3354 | } |
| 3355 | } |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3356 | break; |
| 3357 | case TargetLowering::Expand: { |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 3358 | const Value *V = cast<SrcValueSDNode>(Node->getOperand(2))->getValue(); |
| 3359 | SDOperand VAList = DAG.getLoad(TLI.getPointerTy(), Tmp1, Tmp2, V, 0); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3360 | // Increment the pointer, VAList, to the next vaarg |
| 3361 | Tmp3 = DAG.getNode(ISD::ADD, TLI.getPointerTy(), VAList, |
| 3362 | DAG.getConstant(MVT::getSizeInBits(VT)/8, |
| 3363 | TLI.getPointerTy())); |
| 3364 | // Store the incremented VAList to the legalized pointer |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 3365 | Tmp3 = DAG.getStore(VAList.getValue(1), Tmp3, Tmp2, V, 0); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3366 | // Load the actual argument out of the pointer VAList |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 3367 | Result = DAG.getLoad(VT, Tmp3, VAList, NULL, 0); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3368 | Tmp1 = LegalizeOp(Result.getValue(1)); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3369 | Result = LegalizeOp(Result); |
| 3370 | break; |
| 3371 | } |
| 3372 | } |
| 3373 | // Since VAARG produces two values, make sure to remember that we |
| 3374 | // legalized both of them. |
| 3375 | AddLegalizedOperand(SDOperand(Node, 0), Result); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3376 | AddLegalizedOperand(SDOperand(Node, 1), Tmp1); |
| 3377 | return Op.ResNo ? Tmp1 : Result; |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3378 | } |
| 3379 | |
| 3380 | case ISD::VACOPY: |
| 3381 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 3382 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the dest pointer. |
| 3383 | Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the source pointer. |
| 3384 | |
| 3385 | switch (TLI.getOperationAction(ISD::VACOPY, MVT::Other)) { |
| 3386 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3387 | case TargetLowering::Custom: |
| 3388 | isCustom = true; |
| 3389 | // FALLTHROUGH |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3390 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3391 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3, |
| 3392 | Node->getOperand(3), Node->getOperand(4)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3393 | if (isCustom) { |
| 3394 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 3395 | if (Tmp1.Val) Result = Tmp1; |
| 3396 | } |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3397 | break; |
| 3398 | case TargetLowering::Expand: |
| 3399 | // This defaults to loading a pointer from the input and storing it to the |
| 3400 | // output, returning the chain. |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 3401 | const Value *VD = cast<SrcValueSDNode>(Node->getOperand(3))->getValue(); |
| 3402 | const Value *VS = cast<SrcValueSDNode>(Node->getOperand(4))->getValue(); |
| 3403 | Tmp4 = DAG.getLoad(TLI.getPointerTy(), Tmp1, Tmp3, VD, 0); |
| 3404 | Result = DAG.getStore(Tmp4.getValue(1), Tmp4, Tmp2, VS, 0); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3405 | break; |
| 3406 | } |
| 3407 | break; |
| 3408 | |
| 3409 | case ISD::VAEND: |
| 3410 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 3411 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. |
| 3412 | |
| 3413 | switch (TLI.getOperationAction(ISD::VAEND, MVT::Other)) { |
| 3414 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3415 | case TargetLowering::Custom: |
| 3416 | isCustom = true; |
| 3417 | // FALLTHROUGH |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3418 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3419 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3420 | if (isCustom) { |
| 3421 | Tmp1 = TLI.LowerOperation(Tmp1, DAG); |
| 3422 | if (Tmp1.Val) Result = Tmp1; |
| 3423 | } |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3424 | break; |
| 3425 | case TargetLowering::Expand: |
| 3426 | Result = Tmp1; // Default to a no-op, return the chain |
| 3427 | break; |
| 3428 | } |
| 3429 | break; |
| 3430 | |
| 3431 | case ISD::VASTART: |
| 3432 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 3433 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. |
| 3434 | |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3435 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); |
| 3436 | |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3437 | switch (TLI.getOperationAction(ISD::VASTART, MVT::Other)) { |
| 3438 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3439 | case TargetLowering::Legal: break; |
| 3440 | case TargetLowering::Custom: |
| 3441 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 3442 | if (Tmp1.Val) Result = Tmp1; |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 3443 | break; |
| 3444 | } |
| 3445 | break; |
| 3446 | |
Nate Begeman | 35ef913 | 2006-01-11 21:21:00 +0000 | [diff] [blame] | 3447 | case ISD::ROTL: |
| 3448 | case ISD::ROTR: |
| 3449 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
| 3450 | Tmp2 = LegalizeOp(Node->getOperand(1)); // RHS |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3451 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); |
Scott Michel | c9dc114 | 2007-04-02 21:36:32 +0000 | [diff] [blame] | 3452 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 3453 | default: |
| 3454 | assert(0 && "ROTL/ROTR legalize operation not supported"); |
| 3455 | break; |
| 3456 | case TargetLowering::Legal: |
| 3457 | break; |
| 3458 | case TargetLowering::Custom: |
| 3459 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 3460 | if (Tmp1.Val) Result = Tmp1; |
| 3461 | break; |
| 3462 | case TargetLowering::Promote: |
| 3463 | assert(0 && "Do not know how to promote ROTL/ROTR"); |
| 3464 | break; |
| 3465 | case TargetLowering::Expand: |
| 3466 | assert(0 && "Do not know how to expand ROTL/ROTR"); |
| 3467 | break; |
| 3468 | } |
Nate Begeman | 35ef913 | 2006-01-11 21:21:00 +0000 | [diff] [blame] | 3469 | break; |
| 3470 | |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 3471 | case ISD::BSWAP: |
| 3472 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Op |
| 3473 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3474 | case TargetLowering::Custom: |
| 3475 | assert(0 && "Cannot custom legalize this yet!"); |
| 3476 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3477 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3478 | break; |
| 3479 | case TargetLowering::Promote: { |
| 3480 | MVT::ValueType OVT = Tmp1.getValueType(); |
| 3481 | MVT::ValueType NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT); |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 3482 | unsigned DiffBits = MVT::getSizeInBits(NVT) - MVT::getSizeInBits(OVT); |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 3483 | |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3484 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Tmp1); |
| 3485 | Tmp1 = DAG.getNode(ISD::BSWAP, NVT, Tmp1); |
| 3486 | Result = DAG.getNode(ISD::SRL, NVT, Tmp1, |
| 3487 | DAG.getConstant(DiffBits, TLI.getShiftAmountTy())); |
| 3488 | break; |
| 3489 | } |
| 3490 | case TargetLowering::Expand: |
| 3491 | Result = ExpandBSWAP(Tmp1); |
| 3492 | break; |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 3493 | } |
| 3494 | break; |
| 3495 | |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3496 | case ISD::CTPOP: |
| 3497 | case ISD::CTTZ: |
| 3498 | case ISD::CTLZ: |
| 3499 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Op |
| 3500 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
Scott Michel | 910b66d | 2007-07-30 21:00:31 +0000 | [diff] [blame] | 3501 | case TargetLowering::Custom: |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3502 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3503 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Scott Michel | 910b66d | 2007-07-30 21:00:31 +0000 | [diff] [blame] | 3504 | if (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0)) == |
Scott Michel | 335f4f7 | 2007-08-02 02:22:46 +0000 | [diff] [blame] | 3505 | TargetLowering::Custom) { |
| 3506 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 3507 | if (Tmp1.Val) { |
| 3508 | Result = Tmp1; |
| 3509 | } |
Scott Michel | 910b66d | 2007-07-30 21:00:31 +0000 | [diff] [blame] | 3510 | } |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3511 | break; |
| 3512 | case TargetLowering::Promote: { |
| 3513 | MVT::ValueType OVT = Tmp1.getValueType(); |
| 3514 | MVT::ValueType NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT); |
Chris Lattner | edb1add | 2005-05-11 04:51:16 +0000 | [diff] [blame] | 3515 | |
| 3516 | // Zero extend the argument. |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3517 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Tmp1); |
| 3518 | // Perform the larger operation, then subtract if needed. |
| 3519 | Tmp1 = DAG.getNode(Node->getOpcode(), Node->getValueType(0), Tmp1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3520 | switch (Node->getOpcode()) { |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3521 | case ISD::CTPOP: |
| 3522 | Result = Tmp1; |
| 3523 | break; |
| 3524 | case ISD::CTTZ: |
| 3525 | //if Tmp1 == sizeinbits(NVT) then Tmp1 = sizeinbits(Old VT) |
Scott Michel | 5b8f82e | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 3526 | Tmp2 = DAG.getSetCC(TLI.getSetCCResultType(Tmp1), Tmp1, |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 3527 | DAG.getConstant(MVT::getSizeInBits(NVT), NVT), |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 3528 | ISD::SETEQ); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 3529 | Result = DAG.getNode(ISD::SELECT, NVT, Tmp2, |
Scott Michel | 910b66d | 2007-07-30 21:00:31 +0000 | [diff] [blame] | 3530 | DAG.getConstant(MVT::getSizeInBits(OVT),NVT), Tmp1); |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3531 | break; |
| 3532 | case ISD::CTLZ: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3533 | // Tmp1 = Tmp1 - (sizeinbits(NVT) - sizeinbits(Old VT)) |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 3534 | Result = DAG.getNode(ISD::SUB, NVT, Tmp1, |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 3535 | DAG.getConstant(MVT::getSizeInBits(NVT) - |
| 3536 | MVT::getSizeInBits(OVT), NVT)); |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3537 | break; |
| 3538 | } |
| 3539 | break; |
| 3540 | } |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3541 | case TargetLowering::Expand: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3542 | Result = ExpandBitCount(Node->getOpcode(), Tmp1); |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 3543 | break; |
| 3544 | } |
| 3545 | break; |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 3546 | |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3547 | // Unary operators |
| 3548 | case ISD::FABS: |
| 3549 | case ISD::FNEG: |
Chris Lattner | da6ba87 | 2005-04-28 21:44:33 +0000 | [diff] [blame] | 3550 | case ISD::FSQRT: |
| 3551 | case ISD::FSIN: |
| 3552 | case ISD::FCOS: |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3553 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 3554 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3555 | case TargetLowering::Promote: |
| 3556 | case TargetLowering::Custom: |
Evan Cheng | 59ad781 | 2006-01-31 18:14:25 +0000 | [diff] [blame] | 3557 | isCustom = true; |
| 3558 | // FALLTHROUGH |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3559 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3560 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Evan Cheng | 59ad781 | 2006-01-31 18:14:25 +0000 | [diff] [blame] | 3561 | if (isCustom) { |
| 3562 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 3563 | if (Tmp1.Val) Result = Tmp1; |
| 3564 | } |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3565 | break; |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3566 | case TargetLowering::Expand: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3567 | switch (Node->getOpcode()) { |
| 3568 | default: assert(0 && "Unreachable!"); |
| 3569 | case ISD::FNEG: |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3570 | // Expand Y = FNEG(X) -> Y = SUB -0.0, X |
| 3571 | Tmp2 = DAG.getConstantFP(-0.0, Node->getValueType(0)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3572 | Result = DAG.getNode(ISD::FSUB, Node->getValueType(0), Tmp2, Tmp1); |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 3573 | break; |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 3574 | case ISD::FABS: { |
Chris Lattner | 4af6e0d | 2005-04-02 05:26:37 +0000 | [diff] [blame] | 3575 | // Expand Y = FABS(X) -> Y = (X >u 0.0) ? X : fneg(X). |
| 3576 | MVT::ValueType VT = Node->getValueType(0); |
| 3577 | Tmp2 = DAG.getConstantFP(0.0, VT); |
Scott Michel | 5b8f82e | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 3578 | Tmp2 = DAG.getSetCC(TLI.getSetCCResultType(Tmp1), Tmp1, Tmp2, |
Nate Begeman | 5922f56 | 2008-03-14 00:53:31 +0000 | [diff] [blame] | 3579 | ISD::SETUGT); |
Chris Lattner | 4af6e0d | 2005-04-02 05:26:37 +0000 | [diff] [blame] | 3580 | Tmp3 = DAG.getNode(ISD::FNEG, VT, Tmp1); |
| 3581 | Result = DAG.getNode(ISD::SELECT, VT, Tmp2, Tmp1, Tmp3); |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 3582 | break; |
| 3583 | } |
| 3584 | case ISD::FSQRT: |
| 3585 | case ISD::FSIN: |
| 3586 | case ISD::FCOS: { |
| 3587 | MVT::ValueType VT = Node->getValueType(0); |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3588 | |
| 3589 | // Expand unsupported unary vector operators by unrolling them. |
| 3590 | if (MVT::isVector(VT)) { |
| 3591 | Result = LegalizeOp(UnrollVectorOp(Op)); |
| 3592 | break; |
| 3593 | } |
| 3594 | |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3595 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 3596 | switch(Node->getOpcode()) { |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3597 | case ISD::FSQRT: |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 3598 | LC = GetFPLibCall(VT, RTLIB::SQRT_F32, RTLIB::SQRT_F64, |
| 3599 | RTLIB::SQRT_F80, RTLIB::SQRT_PPCF128); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3600 | break; |
| 3601 | case ISD::FSIN: |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 3602 | LC = GetFPLibCall(VT, RTLIB::SIN_F32, RTLIB::SIN_F64, |
| 3603 | RTLIB::SIN_F80, RTLIB::SIN_PPCF128); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3604 | break; |
| 3605 | case ISD::FCOS: |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 3606 | LC = GetFPLibCall(VT, RTLIB::COS_F32, RTLIB::COS_F64, |
| 3607 | RTLIB::COS_F80, RTLIB::COS_PPCF128); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3608 | break; |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 3609 | default: assert(0 && "Unreachable!"); |
| 3610 | } |
Nate Begeman | 2ac4fc0 | 2005-08-04 21:43:28 +0000 | [diff] [blame] | 3611 | SDOperand Dummy; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3612 | Result = ExpandLibCall(TLI.getLibcallName(LC), Node, |
| 3613 | false/*sign irrelevant*/, Dummy); |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 3614 | break; |
| 3615 | } |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3616 | } |
| 3617 | break; |
| 3618 | } |
| 3619 | break; |
Chris Lattner | 6ddf8ed | 2006-09-09 06:03:30 +0000 | [diff] [blame] | 3620 | case ISD::FPOWI: { |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 3621 | MVT::ValueType VT = Node->getValueType(0); |
| 3622 | |
| 3623 | // Expand unsupported unary vector operators by unrolling them. |
| 3624 | if (MVT::isVector(VT)) { |
| 3625 | Result = LegalizeOp(UnrollVectorOp(Op)); |
| 3626 | break; |
| 3627 | } |
| 3628 | |
| 3629 | // 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] | 3630 | RTLIB::Libcall LC = GetFPLibCall(VT, RTLIB::POWI_F32, RTLIB::POWI_F64, |
| 3631 | RTLIB::POWI_F80, RTLIB::POWI_PPCF128); |
Chris Lattner | 6ddf8ed | 2006-09-09 06:03:30 +0000 | [diff] [blame] | 3632 | SDOperand Dummy; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3633 | Result = ExpandLibCall(TLI.getLibcallName(LC), Node, |
| 3634 | false/*sign irrelevant*/, Dummy); |
Chris Lattner | 6ddf8ed | 2006-09-09 06:03:30 +0000 | [diff] [blame] | 3635 | break; |
| 3636 | } |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 3637 | case ISD::BIT_CONVERT: |
Chris Lattner | 67993f7 | 2006-01-23 07:30:46 +0000 | [diff] [blame] | 3638 | if (!isTypeLegal(Node->getOperand(0).getValueType())) { |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 3639 | Result = EmitStackConvert(Node->getOperand(0), Node->getValueType(0), |
| 3640 | Node->getValueType(0)); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3641 | } else if (MVT::isVector(Op.getOperand(0).getValueType())) { |
| 3642 | // The input has to be a vector type, we have to either scalarize it, pack |
| 3643 | // it, or convert it based on whether the input vector type is legal. |
| 3644 | SDNode *InVal = Node->getOperand(0).Val; |
Dale Johannesen | e526962 | 2007-10-20 00:07:52 +0000 | [diff] [blame] | 3645 | int InIx = Node->getOperand(0).ResNo; |
| 3646 | unsigned NumElems = MVT::getVectorNumElements(InVal->getValueType(InIx)); |
| 3647 | MVT::ValueType EVT = MVT::getVectorElementType(InVal->getValueType(InIx)); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3648 | |
| 3649 | // Figure out if there is a simple type corresponding to this Vector |
| 3650 | // type. If so, convert to the vector type. |
| 3651 | MVT::ValueType TVT = MVT::getVectorType(EVT, NumElems); |
| 3652 | if (TLI.isTypeLegal(TVT)) { |
Dan Gohman | 07a9676 | 2007-07-16 14:29:03 +0000 | [diff] [blame] | 3653 | // Turn this into a bit convert of the vector input. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3654 | Result = DAG.getNode(ISD::BIT_CONVERT, Node->getValueType(0), |
| 3655 | LegalizeOp(Node->getOperand(0))); |
| 3656 | break; |
| 3657 | } else if (NumElems == 1) { |
| 3658 | // Turn this into a bit convert of the scalar input. |
| 3659 | Result = DAG.getNode(ISD::BIT_CONVERT, Node->getValueType(0), |
| 3660 | ScalarizeVectorOp(Node->getOperand(0))); |
| 3661 | break; |
| 3662 | } else { |
| 3663 | // FIXME: UNIMP! Store then reload |
| 3664 | assert(0 && "Cast from unsupported vector type not implemented yet!"); |
| 3665 | } |
Chris Lattner | 67993f7 | 2006-01-23 07:30:46 +0000 | [diff] [blame] | 3666 | } else { |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 3667 | switch (TLI.getOperationAction(ISD::BIT_CONVERT, |
| 3668 | Node->getOperand(0).getValueType())) { |
| 3669 | default: assert(0 && "Unknown operation action!"); |
| 3670 | case TargetLowering::Expand: |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 3671 | Result = EmitStackConvert(Node->getOperand(0), Node->getValueType(0), |
| 3672 | Node->getValueType(0)); |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 3673 | break; |
| 3674 | case TargetLowering::Legal: |
| 3675 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3676 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 3677 | break; |
| 3678 | } |
| 3679 | } |
| 3680 | break; |
Chris Lattner | d1f04d4 | 2006-03-24 02:26:29 +0000 | [diff] [blame] | 3681 | |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 3682 | // Conversion operators. The source and destination have different types. |
Chris Lattner | ae0aacb | 2005-01-08 08:08:56 +0000 | [diff] [blame] | 3683 | case ISD::SINT_TO_FP: |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3684 | case ISD::UINT_TO_FP: { |
| 3685 | bool isSigned = Node->getOpcode() == ISD::SINT_TO_FP; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3686 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3687 | case Legal: |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 3688 | switch (TLI.getOperationAction(Node->getOpcode(), |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3689 | Node->getOperand(0).getValueType())) { |
| 3690 | default: assert(0 && "Unknown operation action!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3691 | case TargetLowering::Custom: |
| 3692 | isCustom = true; |
| 3693 | // FALLTHROUGH |
| 3694 | case TargetLowering::Legal: |
| 3695 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
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 | if (isCustom) { |
| 3698 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 3699 | if (Tmp1.Val) Result = Tmp1; |
| 3700 | } |
| 3701 | break; |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3702 | case TargetLowering::Expand: |
Jim Laskey | 6269ed1 | 2005-08-17 00:39:29 +0000 | [diff] [blame] | 3703 | Result = ExpandLegalINT_TO_FP(isSigned, |
| 3704 | LegalizeOp(Node->getOperand(0)), |
| 3705 | Node->getValueType(0)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3706 | break; |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3707 | case TargetLowering::Promote: |
| 3708 | Result = PromoteLegalINT_TO_FP(LegalizeOp(Node->getOperand(0)), |
| 3709 | Node->getValueType(0), |
| 3710 | isSigned); |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3711 | break; |
Andrew Lenharth | 5b5b8c2 | 2005-11-30 06:43:03 +0000 | [diff] [blame] | 3712 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3713 | break; |
Chris Lattner | b00a642 | 2005-01-07 22:37:48 +0000 | [diff] [blame] | 3714 | case Expand: |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3715 | Result = ExpandIntToFP(Node->getOpcode() == ISD::SINT_TO_FP, |
| 3716 | Node->getValueType(0), Node->getOperand(0)); |
| 3717 | break; |
| 3718 | case Promote: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3719 | Tmp1 = PromoteOp(Node->getOperand(0)); |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3720 | if (isSigned) { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3721 | Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, Tmp1.getValueType(), |
| 3722 | Tmp1, DAG.getValueType(Node->getOperand(0).getValueType())); |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3723 | } else { |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3724 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, |
| 3725 | Node->getOperand(0).getValueType()); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 3726 | } |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3727 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 3728 | Result = LegalizeOp(Result); // The 'op' is not necessarily legal! |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3729 | break; |
| 3730 | } |
| 3731 | break; |
| 3732 | } |
| 3733 | case ISD::TRUNCATE: |
| 3734 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3735 | case Legal: |
| 3736 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3737 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3738 | break; |
| 3739 | case Expand: |
| 3740 | ExpandOp(Node->getOperand(0), Tmp1, Tmp2); |
| 3741 | |
| 3742 | // Since the result is legal, we should just be able to truncate the low |
| 3743 | // part of the source. |
| 3744 | Result = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0), Tmp1); |
| 3745 | break; |
| 3746 | case Promote: |
| 3747 | Result = PromoteOp(Node->getOperand(0)); |
| 3748 | Result = DAG.getNode(ISD::TRUNCATE, Op.getValueType(), Result); |
| 3749 | break; |
| 3750 | } |
| 3751 | break; |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 3752 | |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3753 | case ISD::FP_TO_SINT: |
| 3754 | case ISD::FP_TO_UINT: |
| 3755 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3756 | case Legal: |
Chris Lattner | f1fa74e | 2005-07-30 00:04:12 +0000 | [diff] [blame] | 3757 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 3758 | |
Chris Lattner | 1618beb | 2005-07-29 00:11:56 +0000 | [diff] [blame] | 3759 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))){ |
| 3760 | default: assert(0 && "Unknown operation action!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3761 | case TargetLowering::Custom: |
| 3762 | isCustom = true; |
| 3763 | // FALLTHROUGH |
| 3764 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3765 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3766 | if (isCustom) { |
| 3767 | Tmp1 = TLI.LowerOperation(Result, DAG); |
| 3768 | if (Tmp1.Val) Result = Tmp1; |
| 3769 | } |
| 3770 | break; |
| 3771 | case TargetLowering::Promote: |
| 3772 | Result = PromoteLegalFP_TO_INT(Tmp1, Node->getValueType(0), |
| 3773 | Node->getOpcode() == ISD::FP_TO_SINT); |
| 3774 | break; |
Chris Lattner | 1618beb | 2005-07-29 00:11:56 +0000 | [diff] [blame] | 3775 | case TargetLowering::Expand: |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 3776 | if (Node->getOpcode() == ISD::FP_TO_UINT) { |
| 3777 | SDOperand True, False; |
| 3778 | MVT::ValueType VT = Node->getOperand(0).getValueType(); |
| 3779 | MVT::ValueType NVT = Node->getValueType(0); |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 3780 | const uint64_t zero[] = {0, 0}; |
| 3781 | APFloat apf = APFloat(APInt(MVT::getSizeInBits(VT), 2, zero)); |
Dan Gohman | c7773bf | 2008-02-29 01:44:25 +0000 | [diff] [blame] | 3782 | APInt x = APInt::getSignBit(MVT::getSizeInBits(NVT)); |
| 3783 | (void)apf.convertFromAPInt(x, false, APFloat::rmNearestTiesToEven); |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 3784 | Tmp2 = DAG.getConstantFP(apf, VT); |
Scott Michel | 5b8f82e | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 3785 | Tmp3 = DAG.getSetCC(TLI.getSetCCResultType(Node->getOperand(0)), |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 3786 | Node->getOperand(0), Tmp2, ISD::SETLT); |
| 3787 | True = DAG.getNode(ISD::FP_TO_SINT, NVT, Node->getOperand(0)); |
| 3788 | False = DAG.getNode(ISD::FP_TO_SINT, NVT, |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 3789 | DAG.getNode(ISD::FSUB, VT, Node->getOperand(0), |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 3790 | Tmp2)); |
| 3791 | False = DAG.getNode(ISD::XOR, NVT, False, |
Dan Gohman | c7773bf | 2008-02-29 01:44:25 +0000 | [diff] [blame] | 3792 | DAG.getConstant(x, NVT)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3793 | Result = DAG.getNode(ISD::SELECT, NVT, Tmp3, True, False); |
| 3794 | break; |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 3795 | } else { |
| 3796 | assert(0 && "Do not know how to expand FP_TO_SINT yet!"); |
| 3797 | } |
| 3798 | break; |
Chris Lattner | 07dffd6 | 2005-08-26 00:14:16 +0000 | [diff] [blame] | 3799 | } |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3800 | break; |
Evan Cheng | 6af00d5 | 2006-12-13 01:57:55 +0000 | [diff] [blame] | 3801 | case Expand: { |
Evan Cheng | 6af00d5 | 2006-12-13 01:57:55 +0000 | [diff] [blame] | 3802 | MVT::ValueType VT = Op.getValueType(); |
Dale Johannesen | 6eaeff2 | 2007-10-10 01:01:31 +0000 | [diff] [blame] | 3803 | MVT::ValueType OVT = Node->getOperand(0).getValueType(); |
Dale Johannesen | fcf4d24 | 2007-10-11 23:32:15 +0000 | [diff] [blame] | 3804 | // Convert ppcf128 to i32 |
Dale Johannesen | 6eaeff2 | 2007-10-10 01:01:31 +0000 | [diff] [blame] | 3805 | if (OVT == MVT::ppcf128 && VT == MVT::i32) { |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 3806 | if (Node->getOpcode() == ISD::FP_TO_SINT) { |
| 3807 | Result = DAG.getNode(ISD::FP_ROUND_INREG, MVT::ppcf128, |
| 3808 | Node->getOperand(0), DAG.getValueType(MVT::f64)); |
| 3809 | Result = DAG.getNode(ISD::FP_ROUND, MVT::f64, Result, |
| 3810 | DAG.getIntPtrConstant(1)); |
| 3811 | Result = DAG.getNode(ISD::FP_TO_SINT, VT, Result); |
| 3812 | } else { |
Dale Johannesen | fcf4d24 | 2007-10-11 23:32:15 +0000 | [diff] [blame] | 3813 | const uint64_t TwoE31[] = {0x41e0000000000000LL, 0}; |
| 3814 | APFloat apf = APFloat(APInt(128, 2, TwoE31)); |
| 3815 | Tmp2 = DAG.getConstantFP(apf, OVT); |
| 3816 | // X>=2^31 ? (int)(X-2^31)+0x80000000 : (int)X |
| 3817 | // FIXME: generated code sucks. |
| 3818 | Result = DAG.getNode(ISD::SELECT_CC, VT, Node->getOperand(0), Tmp2, |
| 3819 | DAG.getNode(ISD::ADD, MVT::i32, |
| 3820 | DAG.getNode(ISD::FP_TO_SINT, VT, |
| 3821 | DAG.getNode(ISD::FSUB, OVT, |
| 3822 | Node->getOperand(0), Tmp2)), |
| 3823 | DAG.getConstant(0x80000000, MVT::i32)), |
| 3824 | DAG.getNode(ISD::FP_TO_SINT, VT, |
| 3825 | Node->getOperand(0)), |
| 3826 | DAG.getCondCode(ISD::SETGE)); |
| 3827 | } |
Dale Johannesen | 6eaeff2 | 2007-10-10 01:01:31 +0000 | [diff] [blame] | 3828 | break; |
| 3829 | } |
Dan Gohman | a2e9485 | 2008-03-10 23:03:31 +0000 | [diff] [blame] | 3830 | // Convert f32 / f64 to i32 / i64 / i128. |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3831 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
Evan Cheng | 6af00d5 | 2006-12-13 01:57:55 +0000 | [diff] [blame] | 3832 | switch (Node->getOpcode()) { |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 3833 | case ISD::FP_TO_SINT: { |
Dan Gohman | a2e9485 | 2008-03-10 23:03:31 +0000 | [diff] [blame] | 3834 | if (VT == MVT::i32) { |
| 3835 | if (OVT == MVT::f32) |
| 3836 | LC = RTLIB::FPTOSINT_F32_I32; |
| 3837 | else if (OVT == MVT::f64) |
| 3838 | LC = RTLIB::FPTOSINT_F64_I32; |
| 3839 | else |
| 3840 | assert(0 && "Unexpected i32-to-fp conversion!"); |
| 3841 | } else if (VT == MVT::i64) { |
| 3842 | if (OVT == MVT::f32) |
| 3843 | LC = RTLIB::FPTOSINT_F32_I64; |
| 3844 | else if (OVT == MVT::f64) |
| 3845 | LC = RTLIB::FPTOSINT_F64_I64; |
| 3846 | else if (OVT == MVT::f80) |
| 3847 | LC = RTLIB::FPTOSINT_F80_I64; |
| 3848 | else if (OVT == MVT::ppcf128) |
| 3849 | LC = RTLIB::FPTOSINT_PPCF128_I64; |
| 3850 | else |
| 3851 | assert(0 && "Unexpected i64-to-fp conversion!"); |
| 3852 | } else if (VT == MVT::i128) { |
| 3853 | if (OVT == MVT::f32) |
| 3854 | LC = RTLIB::FPTOSINT_F32_I128; |
| 3855 | else if (OVT == MVT::f64) |
| 3856 | LC = RTLIB::FPTOSINT_F64_I128; |
| 3857 | else if (OVT == MVT::f80) |
| 3858 | LC = RTLIB::FPTOSINT_F80_I128; |
| 3859 | else if (OVT == MVT::ppcf128) |
| 3860 | LC = RTLIB::FPTOSINT_PPCF128_I128; |
| 3861 | else |
| 3862 | assert(0 && "Unexpected i128-to-fp conversion!"); |
| 3863 | } else { |
| 3864 | assert(0 && "Unexpectd int-to-fp conversion!"); |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 3865 | } |
Evan Cheng | 6af00d5 | 2006-12-13 01:57:55 +0000 | [diff] [blame] | 3866 | break; |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 3867 | } |
| 3868 | case ISD::FP_TO_UINT: { |
Dan Gohman | a2e9485 | 2008-03-10 23:03:31 +0000 | [diff] [blame] | 3869 | if (VT == MVT::i32) { |
| 3870 | if (OVT == MVT::f32) |
| 3871 | LC = RTLIB::FPTOUINT_F32_I32; |
| 3872 | else if (OVT == MVT::f64) |
| 3873 | LC = RTLIB::FPTOUINT_F64_I32; |
| 3874 | else if (OVT == MVT::f80) |
| 3875 | LC = RTLIB::FPTOUINT_F80_I32; |
| 3876 | else |
| 3877 | assert(0 && "Unexpected i32-to-fp conversion!"); |
| 3878 | } else if (VT == MVT::i64) { |
| 3879 | if (OVT == MVT::f32) |
| 3880 | LC = RTLIB::FPTOUINT_F32_I64; |
| 3881 | else if (OVT == MVT::f64) |
| 3882 | LC = RTLIB::FPTOUINT_F64_I64; |
| 3883 | else if (OVT == MVT::f80) |
| 3884 | LC = RTLIB::FPTOUINT_F80_I64; |
| 3885 | else if (OVT == MVT::ppcf128) |
| 3886 | LC = RTLIB::FPTOUINT_PPCF128_I64; |
| 3887 | else |
| 3888 | assert(0 && "Unexpected i64-to-fp conversion!"); |
| 3889 | } else if (VT == MVT::i128) { |
| 3890 | if (OVT == MVT::f32) |
| 3891 | LC = RTLIB::FPTOUINT_F32_I128; |
| 3892 | else if (OVT == MVT::f64) |
| 3893 | LC = RTLIB::FPTOUINT_F64_I128; |
| 3894 | else if (OVT == MVT::f80) |
| 3895 | LC = RTLIB::FPTOUINT_F80_I128; |
| 3896 | else if (OVT == MVT::ppcf128) |
| 3897 | LC = RTLIB::FPTOUINT_PPCF128_I128; |
| 3898 | else |
| 3899 | assert(0 && "Unexpected i128-to-fp conversion!"); |
| 3900 | } else { |
| 3901 | assert(0 && "Unexpectd int-to-fp conversion!"); |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 3902 | } |
Evan Cheng | 6af00d5 | 2006-12-13 01:57:55 +0000 | [diff] [blame] | 3903 | break; |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 3904 | } |
Evan Cheng | 6af00d5 | 2006-12-13 01:57:55 +0000 | [diff] [blame] | 3905 | default: assert(0 && "Unreachable!"); |
| 3906 | } |
| 3907 | SDOperand Dummy; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 3908 | Result = ExpandLibCall(TLI.getLibcallName(LC), Node, |
| 3909 | false/*sign irrelevant*/, Dummy); |
Evan Cheng | 6af00d5 | 2006-12-13 01:57:55 +0000 | [diff] [blame] | 3910 | break; |
| 3911 | } |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3912 | case Promote: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3913 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 3914 | Result = DAG.UpdateNodeOperands(Result, LegalizeOp(Tmp1)); |
| 3915 | Result = LegalizeOp(Result); |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3916 | break; |
| 3917 | } |
| 3918 | break; |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 3919 | |
Chris Lattner | f2670a8 | 2008-01-16 06:57:07 +0000 | [diff] [blame] | 3920 | case ISD::FP_EXTEND: { |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 3921 | MVT::ValueType DstVT = Op.getValueType(); |
| 3922 | MVT::ValueType SrcVT = Op.getOperand(0).getValueType(); |
| 3923 | if (TLI.getConvertAction(SrcVT, DstVT) == TargetLowering::Expand) { |
| 3924 | // The only other way we can lower this is to turn it into a STORE, |
| 3925 | // LOAD pair, targetting a temporary location (a stack slot). |
| 3926 | Result = EmitStackConvert(Node->getOperand(0), SrcVT, DstVT); |
| 3927 | break; |
Chris Lattner | f2670a8 | 2008-01-16 06:57:07 +0000 | [diff] [blame] | 3928 | } |
| 3929 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3930 | case Expand: assert(0 && "Shouldn't need to expand other operators here!"); |
| 3931 | case Legal: |
| 3932 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 3933 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 3934 | break; |
| 3935 | case Promote: |
| 3936 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 3937 | Result = DAG.getNode(ISD::FP_EXTEND, Op.getValueType(), Tmp1); |
| 3938 | break; |
| 3939 | } |
| 3940 | break; |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 3941 | } |
Dale Johannesen | 5411a39 | 2007-08-09 01:04:01 +0000 | [diff] [blame] | 3942 | case ISD::FP_ROUND: { |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 3943 | MVT::ValueType DstVT = Op.getValueType(); |
| 3944 | MVT::ValueType SrcVT = Op.getOperand(0).getValueType(); |
| 3945 | if (TLI.getConvertAction(SrcVT, DstVT) == TargetLowering::Expand) { |
| 3946 | if (SrcVT == MVT::ppcf128) { |
Dale Johannesen | 713ed3f | 2008-01-20 01:18:38 +0000 | [diff] [blame] | 3947 | SDOperand Lo; |
| 3948 | ExpandOp(Node->getOperand(0), Lo, Result); |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 3949 | // 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] | 3950 | if (DstVT!=MVT::f64) |
| 3951 | Result = DAG.getNode(ISD::FP_ROUND, DstVT, Result, Op.getOperand(1)); |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 3952 | break; |
Dale Johannesen | 5411a39 | 2007-08-09 01:04:01 +0000 | [diff] [blame] | 3953 | } |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 3954 | // The only other way we can lower this is to turn it into a STORE, |
| 3955 | // LOAD pair, targetting a temporary location (a stack slot). |
| 3956 | Result = EmitStackConvert(Node->getOperand(0), DstVT, DstVT); |
| 3957 | break; |
Dale Johannesen | 849f214 | 2007-07-03 00:53:03 +0000 | [diff] [blame] | 3958 | } |
Chris Lattner | f2670a8 | 2008-01-16 06:57:07 +0000 | [diff] [blame] | 3959 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3960 | case Expand: assert(0 && "Shouldn't need to expand other operators here!"); |
| 3961 | case Legal: |
| 3962 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 3963 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
Chris Lattner | f2670a8 | 2008-01-16 06:57:07 +0000 | [diff] [blame] | 3964 | break; |
| 3965 | case Promote: |
| 3966 | Tmp1 = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 3967 | Result = DAG.getNode(ISD::FP_ROUND, Op.getValueType(), Tmp1, |
| 3968 | Node->getOperand(1)); |
Chris Lattner | f2670a8 | 2008-01-16 06:57:07 +0000 | [diff] [blame] | 3969 | break; |
| 3970 | } |
| 3971 | break; |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 3972 | } |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 3973 | case ISD::ANY_EXTEND: |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3974 | case ISD::ZERO_EXTEND: |
| 3975 | case ISD::SIGN_EXTEND: |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3976 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 3977 | case Expand: assert(0 && "Shouldn't need to expand other operators here!"); |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3978 | case Legal: |
| 3979 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Scott Michel | 0123b7d | 2008-02-15 23:05:48 +0000 | [diff] [blame] | 3980 | if (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0)) == |
| 3981 | TargetLowering::Custom) { |
| 3982 | Tmp2 = TLI.LowerOperation(Result, DAG); |
| 3983 | if (Tmp2.Val) { |
| 3984 | Tmp1 = Tmp2; |
| 3985 | } |
| 3986 | } |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3987 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 3988 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 3989 | case Promote: |
| 3990 | switch (Node->getOpcode()) { |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 3991 | case ISD::ANY_EXTEND: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 3992 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 3993 | Result = DAG.getNode(ISD::ANY_EXTEND, Op.getValueType(), Tmp1); |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 3994 | break; |
Chris Lattner | 1713e73 | 2005-01-16 00:38:00 +0000 | [diff] [blame] | 3995 | case ISD::ZERO_EXTEND: |
| 3996 | Result = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 3997 | Result = DAG.getNode(ISD::ANY_EXTEND, Op.getValueType(), Result); |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 3998 | Result = DAG.getZeroExtendInReg(Result, |
| 3999 | Node->getOperand(0).getValueType()); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4000 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4001 | case ISD::SIGN_EXTEND: |
Chris Lattner | 1713e73 | 2005-01-16 00:38:00 +0000 | [diff] [blame] | 4002 | Result = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 4003 | Result = DAG.getNode(ISD::ANY_EXTEND, Op.getValueType(), Result); |
Chris Lattner | 1713e73 | 2005-01-16 00:38:00 +0000 | [diff] [blame] | 4004 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(), |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 4005 | Result, |
| 4006 | DAG.getValueType(Node->getOperand(0).getValueType())); |
Chris Lattner | 1713e73 | 2005-01-16 00:38:00 +0000 | [diff] [blame] | 4007 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4008 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 4009 | } |
| 4010 | break; |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 4011 | case ISD::FP_ROUND_INREG: |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 4012 | case ISD::SIGN_EXTEND_INREG: { |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 4013 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 4014 | MVT::ValueType ExtraVT = cast<VTSDNode>(Node->getOperand(1))->getVT(); |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 4015 | |
| 4016 | // If this operation is not supported, convert it to a shl/shr or load/store |
| 4017 | // pair. |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 4018 | switch (TLI.getOperationAction(Node->getOpcode(), ExtraVT)) { |
| 4019 | default: assert(0 && "This action not supported for this op yet!"); |
| 4020 | case TargetLowering::Legal: |
Chris Lattner | c52ad4f | 2006-01-28 10:58:55 +0000 | [diff] [blame] | 4021 | Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 4022 | break; |
| 4023 | case TargetLowering::Expand: |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 4024 | // If this is an integer extend and shifts are supported, do that. |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 4025 | if (Node->getOpcode() == ISD::SIGN_EXTEND_INREG) { |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 4026 | // NOTE: we could fall back on load/store here too for targets without |
| 4027 | // SAR. However, it is doubtful that any exist. |
| 4028 | unsigned BitsDiff = MVT::getSizeInBits(Node->getValueType(0)) - |
| 4029 | MVT::getSizeInBits(ExtraVT); |
Chris Lattner | 27ff112 | 2005-01-22 00:31:52 +0000 | [diff] [blame] | 4030 | SDOperand ShiftCst = DAG.getConstant(BitsDiff, TLI.getShiftAmountTy()); |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 4031 | Result = DAG.getNode(ISD::SHL, Node->getValueType(0), |
| 4032 | Node->getOperand(0), ShiftCst); |
| 4033 | Result = DAG.getNode(ISD::SRA, Node->getValueType(0), |
| 4034 | Result, ShiftCst); |
| 4035 | } else if (Node->getOpcode() == ISD::FP_ROUND_INREG) { |
Jim Laskey | 2d84c4c | 2006-10-11 17:52:19 +0000 | [diff] [blame] | 4036 | // 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] | 4037 | // EXTLOAD pair, targetting a temporary location (a stack slot). |
| 4038 | |
| 4039 | // NOTE: there is a choice here between constantly creating new stack |
| 4040 | // slots and always reusing the same one. We currently always create |
| 4041 | // new ones, as reuse may inhibit scheduling. |
Chris Lattner | a66bb39 | 2008-01-16 07:51:34 +0000 | [diff] [blame] | 4042 | Result = EmitStackConvert(Node->getOperand(0), ExtraVT, |
| 4043 | Node->getValueType(0)); |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 4044 | } else { |
| 4045 | assert(0 && "Unknown op"); |
| 4046 | } |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 4047 | break; |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 4048 | } |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 4049 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 4050 | } |
Duncan Sands | 36397f5 | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 4051 | case ISD::TRAMPOLINE: { |
| 4052 | SDOperand Ops[6]; |
| 4053 | for (unsigned i = 0; i != 6; ++i) |
| 4054 | Ops[i] = LegalizeOp(Node->getOperand(i)); |
| 4055 | Result = DAG.UpdateNodeOperands(Result, Ops, 6); |
| 4056 | // The only option for this node is to custom lower it. |
| 4057 | Result = TLI.LowerOperation(Result, DAG); |
| 4058 | assert(Result.Val && "Should always custom lower!"); |
Duncan Sands | f7331b3 | 2007-09-11 14:10:23 +0000 | [diff] [blame] | 4059 | |
| 4060 | // Since trampoline produces two values, make sure to remember that we |
| 4061 | // legalized both of them. |
| 4062 | Tmp1 = LegalizeOp(Result.getValue(1)); |
| 4063 | Result = LegalizeOp(Result); |
| 4064 | AddLegalizedOperand(SDOperand(Node, 0), Result); |
| 4065 | AddLegalizedOperand(SDOperand(Node, 1), Tmp1); |
| 4066 | return Op.ResNo ? Tmp1 : Result; |
Duncan Sands | 36397f5 | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 4067 | } |
Dan Gohman | 1a02486 | 2008-01-31 00:41:03 +0000 | [diff] [blame] | 4068 | case ISD::FLT_ROUNDS_: { |
Anton Korobeynikov | 917c2a6 | 2007-11-15 23:25:33 +0000 | [diff] [blame] | 4069 | MVT::ValueType VT = Node->getValueType(0); |
| 4070 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 4071 | default: assert(0 && "This action not supported for this op yet!"); |
| 4072 | case TargetLowering::Custom: |
| 4073 | Result = TLI.LowerOperation(Op, DAG); |
| 4074 | if (Result.Val) break; |
| 4075 | // Fall Thru |
| 4076 | case TargetLowering::Legal: |
| 4077 | // If this operation is not supported, lower it to constant 1 |
| 4078 | Result = DAG.getConstant(1, VT); |
| 4079 | break; |
| 4080 | } |
| 4081 | } |
Chris Lattner | 41bab0b | 2008-01-15 21:58:08 +0000 | [diff] [blame] | 4082 | case ISD::TRAP: { |
Anton Korobeynikov | 66fac79 | 2008-01-15 07:02:33 +0000 | [diff] [blame] | 4083 | MVT::ValueType VT = Node->getValueType(0); |
| 4084 | switch (TLI.getOperationAction(Node->getOpcode(), VT)) { |
| 4085 | default: assert(0 && "This action not supported for this op yet!"); |
Chris Lattner | 41bab0b | 2008-01-15 21:58:08 +0000 | [diff] [blame] | 4086 | case TargetLowering::Legal: |
| 4087 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 4088 | Result = DAG.UpdateNodeOperands(Result, Tmp1); |
| 4089 | break; |
Anton Korobeynikov | 66fac79 | 2008-01-15 07:02:33 +0000 | [diff] [blame] | 4090 | case TargetLowering::Custom: |
| 4091 | Result = TLI.LowerOperation(Op, DAG); |
| 4092 | if (Result.Val) break; |
| 4093 | // Fall Thru |
Chris Lattner | 41bab0b | 2008-01-15 21:58:08 +0000 | [diff] [blame] | 4094 | case TargetLowering::Expand: |
Anton Korobeynikov | 66fac79 | 2008-01-15 07:02:33 +0000 | [diff] [blame] | 4095 | // If this operation is not supported, lower it to 'abort()' call |
Chris Lattner | 41bab0b | 2008-01-15 21:58:08 +0000 | [diff] [blame] | 4096 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Anton Korobeynikov | 66fac79 | 2008-01-15 07:02:33 +0000 | [diff] [blame] | 4097 | TargetLowering::ArgListTy Args; |
| 4098 | std::pair<SDOperand,SDOperand> CallResult = |
Duncan Sands | 00fee65 | 2008-02-14 17:28:50 +0000 | [diff] [blame] | 4099 | TLI.LowerCallTo(Tmp1, Type::VoidTy, |
| 4100 | false, false, false, CallingConv::C, false, |
Chris Lattner | 034f12e | 2008-01-15 22:09:33 +0000 | [diff] [blame] | 4101 | DAG.getExternalSymbol("abort", TLI.getPointerTy()), |
| 4102 | Args, DAG); |
Anton Korobeynikov | 66fac79 | 2008-01-15 07:02:33 +0000 | [diff] [blame] | 4103 | Result = CallResult.second; |
| 4104 | break; |
| 4105 | } |
Chris Lattner | 41bab0b | 2008-01-15 21:58:08 +0000 | [diff] [blame] | 4106 | break; |
Anton Korobeynikov | 66fac79 | 2008-01-15 07:02:33 +0000 | [diff] [blame] | 4107 | } |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 4108 | } |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4109 | |
Chris Lattner | 4ddd283 | 2006-04-08 04:13:17 +0000 | [diff] [blame] | 4110 | assert(Result.getValueType() == Op.getValueType() && |
| 4111 | "Bad legalization!"); |
| 4112 | |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4113 | // Make sure that the generated code is itself legal. |
| 4114 | if (Result != Op) |
| 4115 | Result = LegalizeOp(Result); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 4116 | |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 4117 | // Note that LegalizeOp may be reentered even from single-use nodes, which |
| 4118 | // means that we always must cache transformed nodes. |
| 4119 | AddLegalizedOperand(Op, Result); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 4120 | return Result; |
| 4121 | } |
| 4122 | |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4123 | /// PromoteOp - Given an operation that produces a value in an invalid type, |
| 4124 | /// promote it to compute the value into a larger type. The produced value will |
| 4125 | /// have the correct bits for the low portion of the register, but no guarantee |
| 4126 | /// is made about the top bits: it may be zero, sign-extended, or garbage. |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4127 | SDOperand SelectionDAGLegalize::PromoteOp(SDOperand Op) { |
| 4128 | MVT::ValueType VT = Op.getValueType(); |
Chris Lattner | 71c42a0 | 2005-01-16 01:11:45 +0000 | [diff] [blame] | 4129 | MVT::ValueType NVT = TLI.getTypeToTransformTo(VT); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4130 | assert(getTypeAction(VT) == Promote && |
| 4131 | "Caller should expand or legalize operands that are not promotable!"); |
| 4132 | assert(NVT > VT && MVT::isInteger(NVT) == MVT::isInteger(VT) && |
| 4133 | "Cannot promote to smaller type!"); |
| 4134 | |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4135 | SDOperand Tmp1, Tmp2, Tmp3; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4136 | SDOperand Result; |
| 4137 | SDNode *Node = Op.Val; |
| 4138 | |
Roman Levenstein | dc1adac | 2008-04-07 10:06:32 +0000 | [diff] [blame] | 4139 | DenseMap<SDOperandImpl, SDOperand>::iterator I = PromotedNodes.find(Op); |
Chris Lattner | 6fdcb25 | 2005-09-02 20:32:45 +0000 | [diff] [blame] | 4140 | if (I != PromotedNodes.end()) return I->second; |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 4141 | |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4142 | switch (Node->getOpcode()) { |
Chris Lattner | d5d0f9b | 2005-08-16 21:55:35 +0000 | [diff] [blame] | 4143 | case ISD::CopyFromReg: |
| 4144 | assert(0 && "CopyFromReg must be legal!"); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4145 | default: |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 4146 | #ifndef NDEBUG |
Dan Gohman | 3983358 | 2007-06-04 16:17:33 +0000 | [diff] [blame] | 4147 | cerr << "NODE: "; Node->dump(&DAG); cerr << "\n"; |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 4148 | #endif |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4149 | assert(0 && "Do not know how to promote this operator!"); |
| 4150 | abort(); |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 4151 | case ISD::UNDEF: |
| 4152 | Result = DAG.getNode(ISD::UNDEF, NVT); |
| 4153 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4154 | case ISD::Constant: |
Chris Lattner | ec176e3 | 2005-08-30 16:56:19 +0000 | [diff] [blame] | 4155 | if (VT != MVT::i1) |
| 4156 | Result = DAG.getNode(ISD::SIGN_EXTEND, NVT, Op); |
| 4157 | else |
| 4158 | Result = DAG.getNode(ISD::ZERO_EXTEND, NVT, Op); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4159 | assert(isa<ConstantSDNode>(Result) && "Didn't constant fold zext?"); |
| 4160 | break; |
| 4161 | case ISD::ConstantFP: |
| 4162 | Result = DAG.getNode(ISD::FP_EXTEND, NVT, Op); |
| 4163 | assert(isa<ConstantFPSDNode>(Result) && "Didn't constant fold fp_extend?"); |
| 4164 | break; |
Chris Lattner | ef5cd1d | 2005-01-18 17:54:55 +0000 | [diff] [blame] | 4165 | |
Chris Lattner | 82fbfb6 | 2005-01-18 02:59:52 +0000 | [diff] [blame] | 4166 | case ISD::SETCC: |
Scott Michel | 5b8f82e | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 4167 | assert(isTypeLegal(TLI.getSetCCResultType(Node->getOperand(0))) |
Nate Begeman | 5922f56 | 2008-03-14 00:53:31 +0000 | [diff] [blame] | 4168 | && "SetCC type is not legal??"); |
Scott Michel | 5b8f82e | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 4169 | Result = DAG.getNode(ISD::SETCC, |
Nate Begeman | 5922f56 | 2008-03-14 00:53:31 +0000 | [diff] [blame] | 4170 | TLI.getSetCCResultType(Node->getOperand(0)), |
| 4171 | Node->getOperand(0), Node->getOperand(1), |
| 4172 | Node->getOperand(2)); |
Chris Lattner | 82fbfb6 | 2005-01-18 02:59:52 +0000 | [diff] [blame] | 4173 | break; |
Chris Lattner | fdfded5 | 2006-04-12 16:20:43 +0000 | [diff] [blame] | 4174 | |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4175 | case ISD::TRUNCATE: |
| 4176 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 4177 | case Legal: |
| 4178 | Result = LegalizeOp(Node->getOperand(0)); |
| 4179 | assert(Result.getValueType() >= NVT && |
| 4180 | "This truncation doesn't make sense!"); |
| 4181 | if (Result.getValueType() > NVT) // Truncate to NVT instead of VT |
| 4182 | Result = DAG.getNode(ISD::TRUNCATE, NVT, Result); |
| 4183 | break; |
Chris Lattner | e76ad6d | 2005-01-28 22:52:50 +0000 | [diff] [blame] | 4184 | case Promote: |
| 4185 | // The truncation is not required, because we don't guarantee anything |
| 4186 | // about high bits anyway. |
| 4187 | Result = PromoteOp(Node->getOperand(0)); |
| 4188 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4189 | case Expand: |
Nate Begeman | 79e46ac | 2005-04-04 00:57:08 +0000 | [diff] [blame] | 4190 | ExpandOp(Node->getOperand(0), Tmp1, Tmp2); |
| 4191 | // Truncate the low part of the expanded value to the result type |
Chris Lattner | e21c305 | 2005-08-01 18:16:37 +0000 | [diff] [blame] | 4192 | Result = DAG.getNode(ISD::TRUNCATE, NVT, Tmp1); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4193 | } |
| 4194 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4195 | case ISD::SIGN_EXTEND: |
| 4196 | case ISD::ZERO_EXTEND: |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 4197 | case ISD::ANY_EXTEND: |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4198 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 4199 | case Expand: assert(0 && "BUG: Smaller reg should have been promoted!"); |
| 4200 | case Legal: |
| 4201 | // 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] | 4202 | Result = DAG.getNode(Node->getOpcode(), NVT, Node->getOperand(0)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4203 | break; |
| 4204 | case Promote: |
| 4205 | // Promote the reg if it's smaller. |
| 4206 | Result = PromoteOp(Node->getOperand(0)); |
| 4207 | // The high bits are not guaranteed to be anything. Insert an extend. |
| 4208 | if (Node->getOpcode() == ISD::SIGN_EXTEND) |
Chris Lattner | 595dc54 | 2005-02-04 18:39:19 +0000 | [diff] [blame] | 4209 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Result, |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 4210 | DAG.getValueType(Node->getOperand(0).getValueType())); |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 4211 | else if (Node->getOpcode() == ISD::ZERO_EXTEND) |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 4212 | Result = DAG.getZeroExtendInReg(Result, |
| 4213 | Node->getOperand(0).getValueType()); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4214 | break; |
| 4215 | } |
| 4216 | break; |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 4217 | case ISD::BIT_CONVERT: |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 4218 | Result = EmitStackConvert(Node->getOperand(0), Node->getValueType(0), |
| 4219 | Node->getValueType(0)); |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 4220 | Result = PromoteOp(Result); |
| 4221 | break; |
| 4222 | |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4223 | case ISD::FP_EXTEND: |
| 4224 | assert(0 && "Case not implemented. Dynamically dead with 2 FP types!"); |
| 4225 | case ISD::FP_ROUND: |
| 4226 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 4227 | case Expand: assert(0 && "BUG: Cannot expand FP regs!"); |
| 4228 | case Promote: assert(0 && "Unreachable with 2 FP types!"); |
| 4229 | case Legal: |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4230 | if (Node->getConstantOperandVal(1) == 0) { |
| 4231 | // Input is legal? Do an FP_ROUND_INREG. |
| 4232 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Node->getOperand(0), |
| 4233 | DAG.getValueType(VT)); |
| 4234 | } else { |
| 4235 | // Just remove the truncate, it isn't affecting the value. |
| 4236 | Result = DAG.getNode(ISD::FP_ROUND, NVT, Node->getOperand(0), |
| 4237 | Node->getOperand(1)); |
| 4238 | } |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4239 | break; |
| 4240 | } |
| 4241 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4242 | case ISD::SINT_TO_FP: |
| 4243 | case ISD::UINT_TO_FP: |
| 4244 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 4245 | case Legal: |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4246 | // No extra round required here. |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4247 | Result = DAG.getNode(Node->getOpcode(), NVT, Node->getOperand(0)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4248 | break; |
| 4249 | |
| 4250 | case Promote: |
| 4251 | Result = PromoteOp(Node->getOperand(0)); |
| 4252 | if (Node->getOpcode() == ISD::SINT_TO_FP) |
| 4253 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(), |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 4254 | Result, |
| 4255 | DAG.getValueType(Node->getOperand(0).getValueType())); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4256 | else |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 4257 | Result = DAG.getZeroExtendInReg(Result, |
| 4258 | Node->getOperand(0).getValueType()); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4259 | // No extra round required here. |
| 4260 | Result = DAG.getNode(Node->getOpcode(), NVT, Result); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4261 | break; |
| 4262 | case Expand: |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4263 | Result = ExpandIntToFP(Node->getOpcode() == ISD::SINT_TO_FP, NVT, |
| 4264 | Node->getOperand(0)); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4265 | // Round if we cannot tolerate excess precision. |
| 4266 | if (NoExcessFPPrecision) |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 4267 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 4268 | DAG.getValueType(VT)); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 4269 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4270 | } |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4271 | break; |
| 4272 | |
Chris Lattner | 5e3c5b4 | 2005-12-09 17:32:47 +0000 | [diff] [blame] | 4273 | case ISD::SIGN_EXTEND_INREG: |
| 4274 | Result = PromoteOp(Node->getOperand(0)); |
| 4275 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Result, |
| 4276 | Node->getOperand(1)); |
| 4277 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4278 | case ISD::FP_TO_SINT: |
| 4279 | case ISD::FP_TO_UINT: |
| 4280 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 4281 | case Legal: |
Evan Cheng | 0b1b9dc | 2006-12-16 02:10:30 +0000 | [diff] [blame] | 4282 | case Expand: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4283 | Tmp1 = Node->getOperand(0); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4284 | break; |
| 4285 | case Promote: |
| 4286 | // The input result is prerounded, so we don't have to do anything |
| 4287 | // special. |
| 4288 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4289 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4290 | } |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 4291 | // If we're promoting a UINT to a larger size, check to see if the new node |
| 4292 | // will be legal. If it isn't, check to see if FP_TO_SINT is legal, since |
| 4293 | // we can use that instead. This allows us to generate better code for |
| 4294 | // FP_TO_UINT for small destination sizes on targets where FP_TO_UINT is not |
| 4295 | // legal, such as PowerPC. |
| 4296 | if (Node->getOpcode() == ISD::FP_TO_UINT && |
Chris Lattner | c9c60f6 | 2005-08-24 16:35:28 +0000 | [diff] [blame] | 4297 | !TLI.isOperationLegal(ISD::FP_TO_UINT, NVT) && |
Nate Begeman | b7f6ef1 | 2005-10-25 23:47:25 +0000 | [diff] [blame] | 4298 | (TLI.isOperationLegal(ISD::FP_TO_SINT, NVT) || |
| 4299 | TLI.getOperationAction(ISD::FP_TO_SINT, NVT)==TargetLowering::Custom)){ |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 4300 | Result = DAG.getNode(ISD::FP_TO_SINT, NVT, Tmp1); |
| 4301 | } else { |
| 4302 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1); |
| 4303 | } |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4304 | break; |
| 4305 | |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 4306 | case ISD::FABS: |
| 4307 | case ISD::FNEG: |
| 4308 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4309 | assert(Tmp1.getValueType() == NVT); |
| 4310 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1); |
| 4311 | // NOTE: we do not have to do any extra rounding here for |
| 4312 | // NoExcessFPPrecision, because we know the input will have the appropriate |
| 4313 | // precision, and these operations don't modify precision at all. |
| 4314 | break; |
| 4315 | |
Chris Lattner | da6ba87 | 2005-04-28 21:44:33 +0000 | [diff] [blame] | 4316 | case ISD::FSQRT: |
| 4317 | case ISD::FSIN: |
| 4318 | case ISD::FCOS: |
| 4319 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4320 | assert(Tmp1.getValueType() == NVT); |
| 4321 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4322 | if (NoExcessFPPrecision) |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 4323 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 4324 | DAG.getValueType(VT)); |
Chris Lattner | da6ba87 | 2005-04-28 21:44:33 +0000 | [diff] [blame] | 4325 | break; |
| 4326 | |
Chris Lattner | 8b2d42c | 2007-03-03 23:43:21 +0000 | [diff] [blame] | 4327 | case ISD::FPOWI: { |
| 4328 | // Promote f32 powi to f64 powi. Note that this could insert a libcall |
| 4329 | // directly as well, which may be better. |
| 4330 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4331 | assert(Tmp1.getValueType() == NVT); |
| 4332 | Result = DAG.getNode(ISD::FPOWI, NVT, Tmp1, Node->getOperand(1)); |
| 4333 | if (NoExcessFPPrecision) |
| 4334 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 4335 | DAG.getValueType(VT)); |
| 4336 | break; |
| 4337 | } |
| 4338 | |
Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 4339 | case ISD::ATOMIC_LCS: { |
| 4340 | Tmp2 = PromoteOp(Node->getOperand(2)); |
| 4341 | Tmp3 = PromoteOp(Node->getOperand(3)); |
| 4342 | Result = DAG.getAtomic(Node->getOpcode(), Node->getOperand(0), |
| 4343 | Node->getOperand(1), Tmp2, Tmp3, |
| 4344 | cast<AtomicSDNode>(Node)->getVT()); |
| 4345 | // Remember that we legalized the chain. |
| 4346 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1))); |
| 4347 | break; |
| 4348 | } |
| 4349 | case ISD::ATOMIC_LAS: |
| 4350 | case ISD::ATOMIC_SWAP: { |
| 4351 | Tmp2 = PromoteOp(Node->getOperand(2)); |
| 4352 | Result = DAG.getAtomic(Node->getOpcode(), Node->getOperand(0), |
| 4353 | Node->getOperand(1), Tmp2, |
| 4354 | cast<AtomicSDNode>(Node)->getVT()); |
| 4355 | // Remember that we legalized the chain. |
| 4356 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1))); |
| 4357 | break; |
| 4358 | } |
| 4359 | |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4360 | case ISD::AND: |
| 4361 | case ISD::OR: |
| 4362 | case ISD::XOR: |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 4363 | case ISD::ADD: |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4364 | case ISD::SUB: |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 4365 | case ISD::MUL: |
| 4366 | // 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] | 4367 | // 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] | 4368 | // that too is okay if they are integer operations. |
| 4369 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4370 | Tmp2 = PromoteOp(Node->getOperand(1)); |
| 4371 | assert(Tmp1.getValueType() == NVT && Tmp2.getValueType() == NVT); |
| 4372 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 4373 | break; |
| 4374 | case ISD::FADD: |
| 4375 | case ISD::FSUB: |
| 4376 | case ISD::FMUL: |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 4377 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4378 | Tmp2 = PromoteOp(Node->getOperand(1)); |
| 4379 | assert(Tmp1.getValueType() == NVT && Tmp2.getValueType() == NVT); |
| 4380 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 4381 | |
| 4382 | // Floating point operations will give excess precision that we may not be |
| 4383 | // able to tolerate. If we DO allow excess precision, just leave it, |
| 4384 | // otherwise excise it. |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4385 | // FIXME: Why would we need to round FP ops more than integer ones? |
| 4386 | // 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] | 4387 | if (NoExcessFPPrecision) |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 4388 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 4389 | DAG.getValueType(VT)); |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 4390 | break; |
| 4391 | |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4392 | case ISD::SDIV: |
| 4393 | case ISD::SREM: |
| 4394 | // These operators require that their input be sign extended. |
| 4395 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4396 | Tmp2 = PromoteOp(Node->getOperand(1)); |
| 4397 | if (MVT::isInteger(NVT)) { |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 4398 | Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp1, |
| 4399 | DAG.getValueType(VT)); |
| 4400 | Tmp2 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp2, |
| 4401 | DAG.getValueType(VT)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4402 | } |
| 4403 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 4404 | |
| 4405 | // Perform FP_ROUND: this is probably overly pessimistic. |
| 4406 | if (MVT::isFloatingPoint(NVT) && NoExcessFPPrecision) |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 4407 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 4408 | DAG.getValueType(VT)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4409 | break; |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 4410 | case ISD::FDIV: |
| 4411 | case ISD::FREM: |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 4412 | case ISD::FCOPYSIGN: |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 4413 | // These operators require that their input be fp extended. |
Nate Begeman | ec57fd9 | 2006-05-09 18:20:51 +0000 | [diff] [blame] | 4414 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4415 | case Expand: assert(0 && "not implemented"); |
| 4416 | case Legal: Tmp1 = LegalizeOp(Node->getOperand(0)); break; |
| 4417 | case Promote: Tmp1 = PromoteOp(Node->getOperand(0)); break; |
Nate Begeman | ec57fd9 | 2006-05-09 18:20:51 +0000 | [diff] [blame] | 4418 | } |
| 4419 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 4420 | case Expand: assert(0 && "not implemented"); |
| 4421 | case Legal: Tmp2 = LegalizeOp(Node->getOperand(1)); break; |
| 4422 | case Promote: Tmp2 = PromoteOp(Node->getOperand(1)); break; |
Nate Begeman | ec57fd9 | 2006-05-09 18:20:51 +0000 | [diff] [blame] | 4423 | } |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 4424 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 4425 | |
| 4426 | // Perform FP_ROUND: this is probably overly pessimistic. |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 4427 | if (NoExcessFPPrecision && Node->getOpcode() != ISD::FCOPYSIGN) |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 4428 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 4429 | DAG.getValueType(VT)); |
| 4430 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4431 | |
| 4432 | case ISD::UDIV: |
| 4433 | case ISD::UREM: |
| 4434 | // These operators require that their input be zero extended. |
| 4435 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 4436 | Tmp2 = PromoteOp(Node->getOperand(1)); |
| 4437 | assert(MVT::isInteger(NVT) && "Operators don't apply to FP!"); |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 4438 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, VT); |
| 4439 | Tmp2 = DAG.getZeroExtendInReg(Tmp2, VT); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4440 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 4441 | break; |
| 4442 | |
| 4443 | case ISD::SHL: |
| 4444 | Tmp1 = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4445 | Result = DAG.getNode(ISD::SHL, NVT, Tmp1, Node->getOperand(1)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4446 | break; |
| 4447 | case ISD::SRA: |
| 4448 | // The input value must be properly sign extended. |
| 4449 | Tmp1 = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 4450 | Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp1, |
| 4451 | DAG.getValueType(VT)); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4452 | Result = DAG.getNode(ISD::SRA, NVT, Tmp1, Node->getOperand(1)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4453 | break; |
| 4454 | case ISD::SRL: |
| 4455 | // The input value must be properly zero extended. |
| 4456 | Tmp1 = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 4457 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, VT); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4458 | Result = DAG.getNode(ISD::SRL, NVT, Tmp1, Node->getOperand(1)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 4459 | break; |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 4460 | |
| 4461 | case ISD::VAARG: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4462 | Tmp1 = Node->getOperand(0); // Get the chain. |
| 4463 | Tmp2 = Node->getOperand(1); // Get the pointer. |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 4464 | if (TLI.getOperationAction(ISD::VAARG, VT) == TargetLowering::Custom) { |
| 4465 | Tmp3 = DAG.getVAArg(VT, Tmp1, Tmp2, Node->getOperand(2)); |
| 4466 | Result = TLI.CustomPromoteOperation(Tmp3, DAG); |
| 4467 | } else { |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 4468 | const Value *V = cast<SrcValueSDNode>(Node->getOperand(2))->getValue(); |
| 4469 | SDOperand VAList = DAG.getLoad(TLI.getPointerTy(), Tmp1, Tmp2, V, 0); |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 4470 | // Increment the pointer, VAList, to the next vaarg |
| 4471 | Tmp3 = DAG.getNode(ISD::ADD, TLI.getPointerTy(), VAList, |
| 4472 | DAG.getConstant(MVT::getSizeInBits(VT)/8, |
| 4473 | TLI.getPointerTy())); |
| 4474 | // Store the incremented VAList to the legalized pointer |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 4475 | Tmp3 = DAG.getStore(VAList.getValue(1), Tmp3, Tmp2, V, 0); |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 4476 | // Load the actual argument out of the pointer VAList |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 4477 | Result = DAG.getExtLoad(ISD::EXTLOAD, NVT, Tmp3, VAList, NULL, 0, VT); |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 4478 | } |
| 4479 | // Remember that we legalized the chain. |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4480 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1))); |
Nate Begeman | 0aed784 | 2006-01-28 03:14:31 +0000 | [diff] [blame] | 4481 | break; |
| 4482 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 4483 | case ISD::LOAD: { |
| 4484 | LoadSDNode *LD = cast<LoadSDNode>(Node); |
Evan Cheng | 62f2a3c | 2006-10-10 07:51:21 +0000 | [diff] [blame] | 4485 | ISD::LoadExtType ExtType = ISD::isNON_EXTLoad(Node) |
| 4486 | ? ISD::EXTLOAD : LD->getExtensionType(); |
| 4487 | Result = DAG.getExtLoad(ExtType, NVT, |
| 4488 | LD->getChain(), LD->getBasePtr(), |
Chris Lattner | 55b5708 | 2006-10-10 18:54:19 +0000 | [diff] [blame] | 4489 | LD->getSrcValue(), LD->getSrcValueOffset(), |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 4490 | LD->getMemoryVT(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 4491 | LD->isVolatile(), |
| 4492 | LD->getAlignment()); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4493 | // Remember that we legalized the chain. |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4494 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1))); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4495 | break; |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 4496 | } |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4497 | case ISD::SELECT: |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4498 | Tmp2 = PromoteOp(Node->getOperand(1)); // Legalize the op0 |
| 4499 | Tmp3 = PromoteOp(Node->getOperand(2)); // Legalize the op1 |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4500 | Result = DAG.getNode(ISD::SELECT, NVT, Node->getOperand(0), Tmp2, Tmp3); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4501 | break; |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 4502 | case ISD::SELECT_CC: |
| 4503 | Tmp2 = PromoteOp(Node->getOperand(2)); // True |
| 4504 | Tmp3 = PromoteOp(Node->getOperand(3)); // False |
| 4505 | Result = DAG.getNode(ISD::SELECT_CC, NVT, Node->getOperand(0), |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4506 | Node->getOperand(1), Tmp2, Tmp3, Node->getOperand(4)); |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 4507 | break; |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 4508 | case ISD::BSWAP: |
| 4509 | Tmp1 = Node->getOperand(0); |
| 4510 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Tmp1); |
| 4511 | Tmp1 = DAG.getNode(ISD::BSWAP, NVT, Tmp1); |
| 4512 | Result = DAG.getNode(ISD::SRL, NVT, Tmp1, |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 4513 | DAG.getConstant(MVT::getSizeInBits(NVT) - |
| 4514 | MVT::getSizeInBits(VT), |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 4515 | TLI.getShiftAmountTy())); |
| 4516 | break; |
Andrew Lenharth | fecf095 | 2005-05-04 19:11:05 +0000 | [diff] [blame] | 4517 | case ISD::CTPOP: |
| 4518 | case ISD::CTTZ: |
| 4519 | case ISD::CTLZ: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4520 | // Zero extend the argument |
| 4521 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Node->getOperand(0)); |
Andrew Lenharth | fecf095 | 2005-05-04 19:11:05 +0000 | [diff] [blame] | 4522 | // Perform the larger operation, then subtract if needed. |
| 4523 | Tmp1 = DAG.getNode(Node->getOpcode(), NVT, Tmp1); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4524 | switch(Node->getOpcode()) { |
Andrew Lenharth | fecf095 | 2005-05-04 19:11:05 +0000 | [diff] [blame] | 4525 | case ISD::CTPOP: |
| 4526 | Result = Tmp1; |
| 4527 | break; |
| 4528 | case ISD::CTTZ: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4529 | // if Tmp1 == sizeinbits(NVT) then Tmp1 = sizeinbits(Old VT) |
Scott Michel | 5b8f82e | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 4530 | Tmp2 = DAG.getSetCC(TLI.getSetCCResultType(Tmp1), Tmp1, |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 4531 | DAG.getConstant(MVT::getSizeInBits(NVT), NVT), |
| 4532 | ISD::SETEQ); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 4533 | Result = DAG.getNode(ISD::SELECT, NVT, Tmp2, |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 4534 | DAG.getConstant(MVT::getSizeInBits(VT), NVT), Tmp1); |
Andrew Lenharth | fecf095 | 2005-05-04 19:11:05 +0000 | [diff] [blame] | 4535 | break; |
| 4536 | case ISD::CTLZ: |
| 4537 | //Tmp1 = Tmp1 - (sizeinbits(NVT) - sizeinbits(Old VT)) |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 4538 | Result = DAG.getNode(ISD::SUB, NVT, Tmp1, |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 4539 | DAG.getConstant(MVT::getSizeInBits(NVT) - |
| 4540 | MVT::getSizeInBits(VT), NVT)); |
Andrew Lenharth | fecf095 | 2005-05-04 19:11:05 +0000 | [diff] [blame] | 4541 | break; |
| 4542 | } |
| 4543 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4544 | case ISD::EXTRACT_SUBVECTOR: |
| 4545 | Result = PromoteOp(ExpandEXTRACT_SUBVECTOR(Op)); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 4546 | break; |
Chris Lattner | 4aab2f4 | 2006-04-02 05:06:04 +0000 | [diff] [blame] | 4547 | case ISD::EXTRACT_VECTOR_ELT: |
| 4548 | Result = PromoteOp(ExpandEXTRACT_VECTOR_ELT(Op)); |
| 4549 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4550 | } |
| 4551 | |
| 4552 | assert(Result.Val && "Didn't set a result!"); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 4553 | |
| 4554 | // Make sure the result is itself legal. |
| 4555 | Result = LegalizeOp(Result); |
| 4556 | |
| 4557 | // Remember that we promoted this! |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 4558 | AddPromotedOperand(Op, Result); |
| 4559 | return Result; |
| 4560 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 4561 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4562 | /// ExpandEXTRACT_VECTOR_ELT - Expand an EXTRACT_VECTOR_ELT operation into |
| 4563 | /// a legal EXTRACT_VECTOR_ELT operation, scalar code, or memory traffic, |
| 4564 | /// based on the vector type. The return type of this matches the element type |
| 4565 | /// of the vector, which may not be legal for the target. |
| 4566 | SDOperand SelectionDAGLegalize::ExpandEXTRACT_VECTOR_ELT(SDOperand Op) { |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4567 | // We know that operand #0 is the Vec vector. If the index is a constant |
| 4568 | // or if the invec is a supported hardware type, we can use it. Otherwise, |
| 4569 | // lower to a store then an indexed load. |
| 4570 | SDOperand Vec = Op.getOperand(0); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4571 | SDOperand Idx = Op.getOperand(1); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4572 | |
Dan Gohman | e40c7b0 | 2007-09-24 15:54:53 +0000 | [diff] [blame] | 4573 | MVT::ValueType TVT = Vec.getValueType(); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4574 | unsigned NumElems = MVT::getVectorNumElements(TVT); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4575 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4576 | switch (TLI.getOperationAction(ISD::EXTRACT_VECTOR_ELT, TVT)) { |
| 4577 | default: assert(0 && "This action is not supported yet!"); |
| 4578 | case TargetLowering::Custom: { |
| 4579 | Vec = LegalizeOp(Vec); |
| 4580 | Op = DAG.UpdateNodeOperands(Op, Vec, Idx); |
| 4581 | SDOperand Tmp3 = TLI.LowerOperation(Op, DAG); |
| 4582 | if (Tmp3.Val) |
| 4583 | return Tmp3; |
| 4584 | break; |
| 4585 | } |
| 4586 | case TargetLowering::Legal: |
| 4587 | if (isTypeLegal(TVT)) { |
| 4588 | Vec = LegalizeOp(Vec); |
| 4589 | Op = DAG.UpdateNodeOperands(Op, Vec, Idx); |
Christopher Lamb | 844228a | 2007-07-26 03:33:13 +0000 | [diff] [blame] | 4590 | return Op; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4591 | } |
| 4592 | break; |
| 4593 | case TargetLowering::Expand: |
| 4594 | break; |
| 4595 | } |
| 4596 | |
| 4597 | if (NumElems == 1) { |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4598 | // This must be an access of the only element. Return it. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4599 | Op = ScalarizeVectorOp(Vec); |
| 4600 | } else if (!TLI.isTypeLegal(TVT) && isa<ConstantSDNode>(Idx)) { |
Nate Begeman | 55030dc | 2008-01-29 02:24:00 +0000 | [diff] [blame] | 4601 | unsigned NumLoElts = 1 << Log2_32(NumElems-1); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4602 | ConstantSDNode *CIdx = cast<ConstantSDNode>(Idx); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4603 | SDOperand Lo, Hi; |
| 4604 | SplitVectorOp(Vec, Lo, Hi); |
Nate Begeman | 55030dc | 2008-01-29 02:24:00 +0000 | [diff] [blame] | 4605 | if (CIdx->getValue() < NumLoElts) { |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4606 | Vec = Lo; |
| 4607 | } else { |
| 4608 | Vec = Hi; |
Nate Begeman | 55030dc | 2008-01-29 02:24:00 +0000 | [diff] [blame] | 4609 | Idx = DAG.getConstant(CIdx->getValue() - NumLoElts, |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4610 | Idx.getValueType()); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4611 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4612 | |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4613 | // It's now an extract from the appropriate high or low part. Recurse. |
| 4614 | Op = DAG.UpdateNodeOperands(Op, Vec, Idx); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4615 | Op = ExpandEXTRACT_VECTOR_ELT(Op); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4616 | } else { |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4617 | // Store the value to a temporary stack slot, then LOAD the scalar |
| 4618 | // element back out. |
Chris Lattner | 85dd3be | 2007-10-15 17:48:57 +0000 | [diff] [blame] | 4619 | SDOperand StackPtr = DAG.CreateStackTemporary(Vec.getValueType()); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4620 | SDOperand Ch = DAG.getStore(DAG.getEntryNode(), Vec, StackPtr, NULL, 0); |
| 4621 | |
| 4622 | // Add the offset to the index. |
| 4623 | unsigned EltSize = MVT::getSizeInBits(Op.getValueType())/8; |
| 4624 | Idx = DAG.getNode(ISD::MUL, Idx.getValueType(), Idx, |
| 4625 | DAG.getConstant(EltSize, Idx.getValueType())); |
Bill Wendling | 90bfc2d | 2007-10-18 08:32:37 +0000 | [diff] [blame] | 4626 | |
| 4627 | if (MVT::getSizeInBits(Idx.getValueType()) > |
| 4628 | MVT::getSizeInBits(TLI.getPointerTy())) |
Chris Lattner | f185e67 | 2007-10-19 16:47:35 +0000 | [diff] [blame] | 4629 | Idx = DAG.getNode(ISD::TRUNCATE, TLI.getPointerTy(), Idx); |
Bill Wendling | 90bfc2d | 2007-10-18 08:32:37 +0000 | [diff] [blame] | 4630 | else |
Chris Lattner | f185e67 | 2007-10-19 16:47:35 +0000 | [diff] [blame] | 4631 | Idx = DAG.getNode(ISD::ZERO_EXTEND, TLI.getPointerTy(), Idx); |
Bill Wendling | 90bfc2d | 2007-10-18 08:32:37 +0000 | [diff] [blame] | 4632 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4633 | StackPtr = DAG.getNode(ISD::ADD, Idx.getValueType(), Idx, StackPtr); |
| 4634 | |
| 4635 | Op = DAG.getLoad(Op.getValueType(), Ch, StackPtr, NULL, 0); |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4636 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4637 | return Op; |
Chris Lattner | 1597221 | 2006-03-31 17:55:51 +0000 | [diff] [blame] | 4638 | } |
| 4639 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4640 | /// ExpandEXTRACT_SUBVECTOR - Expand a EXTRACT_SUBVECTOR operation. For now |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 4641 | /// we assume the operation can be split if it is not already legal. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4642 | SDOperand SelectionDAGLegalize::ExpandEXTRACT_SUBVECTOR(SDOperand Op) { |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 4643 | // We know that operand #0 is the Vec vector. For now we assume the index |
| 4644 | // is a constant and that the extracted result is a supported hardware type. |
| 4645 | SDOperand Vec = Op.getOperand(0); |
| 4646 | SDOperand Idx = LegalizeOp(Op.getOperand(1)); |
| 4647 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4648 | unsigned NumElems = MVT::getVectorNumElements(Vec.getValueType()); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 4649 | |
| 4650 | if (NumElems == MVT::getVectorNumElements(Op.getValueType())) { |
| 4651 | // This must be an access of the desired vector length. Return it. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4652 | return Vec; |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 4653 | } |
| 4654 | |
| 4655 | ConstantSDNode *CIdx = cast<ConstantSDNode>(Idx); |
| 4656 | SDOperand Lo, Hi; |
| 4657 | SplitVectorOp(Vec, Lo, Hi); |
| 4658 | if (CIdx->getValue() < NumElems/2) { |
| 4659 | Vec = Lo; |
| 4660 | } else { |
| 4661 | Vec = Hi; |
| 4662 | Idx = DAG.getConstant(CIdx->getValue() - NumElems/2, Idx.getValueType()); |
| 4663 | } |
| 4664 | |
| 4665 | // It's now an extract from the appropriate high or low part. Recurse. |
| 4666 | Op = DAG.UpdateNodeOperands(Op, Vec, Idx); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 4667 | return ExpandEXTRACT_SUBVECTOR(Op); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 4668 | } |
| 4669 | |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 4670 | /// LegalizeSetCCOperands - Attempts to create a legal LHS and RHS for a SETCC |
| 4671 | /// with condition CC on the current target. This usually involves legalizing |
| 4672 | /// or promoting the arguments. In the case where LHS and RHS must be expanded, |
| 4673 | /// there may be no choice but to create a new SetCC node to represent the |
| 4674 | /// legalized value of setcc lhs, rhs. In this case, the value is returned in |
| 4675 | /// LHS, and the SDOperand returned in RHS has a nil SDNode value. |
| 4676 | void SelectionDAGLegalize::LegalizeSetCCOperands(SDOperand &LHS, |
| 4677 | SDOperand &RHS, |
| 4678 | SDOperand &CC) { |
Dale Johannesen | 638ccd5 | 2007-10-06 01:24:11 +0000 | [diff] [blame] | 4679 | SDOperand Tmp1, Tmp2, Tmp3, Result; |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 4680 | |
| 4681 | switch (getTypeAction(LHS.getValueType())) { |
| 4682 | case Legal: |
| 4683 | Tmp1 = LegalizeOp(LHS); // LHS |
| 4684 | Tmp2 = LegalizeOp(RHS); // RHS |
| 4685 | break; |
| 4686 | case Promote: |
| 4687 | Tmp1 = PromoteOp(LHS); // LHS |
| 4688 | Tmp2 = PromoteOp(RHS); // RHS |
| 4689 | |
| 4690 | // If this is an FP compare, the operands have already been extended. |
| 4691 | if (MVT::isInteger(LHS.getValueType())) { |
| 4692 | MVT::ValueType VT = LHS.getValueType(); |
| 4693 | MVT::ValueType NVT = TLI.getTypeToTransformTo(VT); |
| 4694 | |
| 4695 | // Otherwise, we have to insert explicit sign or zero extends. Note |
| 4696 | // that we could insert sign extends for ALL conditions, but zero extend |
| 4697 | // is cheaper on many machines (an AND instead of two shifts), so prefer |
| 4698 | // it. |
| 4699 | switch (cast<CondCodeSDNode>(CC)->get()) { |
| 4700 | default: assert(0 && "Unknown integer comparison!"); |
| 4701 | case ISD::SETEQ: |
| 4702 | case ISD::SETNE: |
| 4703 | case ISD::SETUGE: |
| 4704 | case ISD::SETUGT: |
| 4705 | case ISD::SETULE: |
| 4706 | case ISD::SETULT: |
| 4707 | // ALL of these operations will work if we either sign or zero extend |
| 4708 | // the operands (including the unsigned comparisons!). Zero extend is |
| 4709 | // usually a simpler/cheaper operation, so prefer it. |
| 4710 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, VT); |
| 4711 | Tmp2 = DAG.getZeroExtendInReg(Tmp2, VT); |
| 4712 | break; |
| 4713 | case ISD::SETGE: |
| 4714 | case ISD::SETGT: |
| 4715 | case ISD::SETLT: |
| 4716 | case ISD::SETLE: |
| 4717 | Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp1, |
| 4718 | DAG.getValueType(VT)); |
| 4719 | Tmp2 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp2, |
| 4720 | DAG.getValueType(VT)); |
| 4721 | break; |
| 4722 | } |
| 4723 | } |
| 4724 | break; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4725 | case Expand: { |
| 4726 | MVT::ValueType VT = LHS.getValueType(); |
| 4727 | if (VT == MVT::f32 || VT == MVT::f64) { |
| 4728 | // Expand into one or more soft-fp libcall(s). |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4729 | RTLIB::Libcall LC1, LC2 = RTLIB::UNKNOWN_LIBCALL; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4730 | switch (cast<CondCodeSDNode>(CC)->get()) { |
| 4731 | case ISD::SETEQ: |
| 4732 | case ISD::SETOEQ: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4733 | LC1 = (VT == MVT::f32) ? RTLIB::OEQ_F32 : RTLIB::OEQ_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4734 | break; |
| 4735 | case ISD::SETNE: |
| 4736 | case ISD::SETUNE: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4737 | LC1 = (VT == MVT::f32) ? RTLIB::UNE_F32 : RTLIB::UNE_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4738 | break; |
| 4739 | case ISD::SETGE: |
| 4740 | case ISD::SETOGE: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4741 | LC1 = (VT == MVT::f32) ? RTLIB::OGE_F32 : RTLIB::OGE_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4742 | break; |
| 4743 | case ISD::SETLT: |
| 4744 | case ISD::SETOLT: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4745 | LC1 = (VT == MVT::f32) ? RTLIB::OLT_F32 : RTLIB::OLT_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4746 | break; |
| 4747 | case ISD::SETLE: |
| 4748 | case ISD::SETOLE: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4749 | LC1 = (VT == MVT::f32) ? RTLIB::OLE_F32 : RTLIB::OLE_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4750 | break; |
| 4751 | case ISD::SETGT: |
| 4752 | case ISD::SETOGT: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4753 | LC1 = (VT == MVT::f32) ? RTLIB::OGT_F32 : RTLIB::OGT_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4754 | break; |
| 4755 | case ISD::SETUO: |
Evan Cheng | d385fd6 | 2007-01-31 09:29:11 +0000 | [diff] [blame] | 4756 | LC1 = (VT == MVT::f32) ? RTLIB::UO_F32 : RTLIB::UO_F64; |
| 4757 | break; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4758 | case ISD::SETO: |
Evan Cheng | 5efdecc | 2007-02-03 00:43:46 +0000 | [diff] [blame] | 4759 | LC1 = (VT == MVT::f32) ? RTLIB::O_F32 : RTLIB::O_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4760 | break; |
| 4761 | default: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4762 | LC1 = (VT == MVT::f32) ? RTLIB::UO_F32 : RTLIB::UO_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4763 | switch (cast<CondCodeSDNode>(CC)->get()) { |
| 4764 | case ISD::SETONE: |
| 4765 | // SETONE = SETOLT | SETOGT |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4766 | LC1 = (VT == MVT::f32) ? RTLIB::OLT_F32 : RTLIB::OLT_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4767 | // Fallthrough |
| 4768 | case ISD::SETUGT: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4769 | LC2 = (VT == MVT::f32) ? RTLIB::OGT_F32 : RTLIB::OGT_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4770 | break; |
| 4771 | case ISD::SETUGE: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4772 | LC2 = (VT == MVT::f32) ? RTLIB::OGE_F32 : RTLIB::OGE_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4773 | break; |
| 4774 | case ISD::SETULT: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4775 | LC2 = (VT == MVT::f32) ? RTLIB::OLT_F32 : RTLIB::OLT_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4776 | break; |
| 4777 | case ISD::SETULE: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4778 | LC2 = (VT == MVT::f32) ? RTLIB::OLE_F32 : RTLIB::OLE_F64; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4779 | break; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4780 | case ISD::SETUEQ: |
| 4781 | LC2 = (VT == MVT::f32) ? RTLIB::OEQ_F32 : RTLIB::OEQ_F64; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4782 | break; |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4783 | default: assert(0 && "Unsupported FP setcc!"); |
| 4784 | } |
| 4785 | } |
| 4786 | |
| 4787 | SDOperand Dummy; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4788 | Tmp1 = ExpandLibCall(TLI.getLibcallName(LC1), |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 4789 | DAG.getNode(ISD::MERGE_VALUES, VT, LHS, RHS).Val, |
Reid Spencer | b47b25c | 2007-01-03 04:22:32 +0000 | [diff] [blame] | 4790 | false /*sign irrelevant*/, Dummy); |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4791 | Tmp2 = DAG.getConstant(0, MVT::i32); |
Evan Cheng | d385fd6 | 2007-01-31 09:29:11 +0000 | [diff] [blame] | 4792 | CC = DAG.getCondCode(TLI.getCmpLibcallCC(LC1)); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4793 | if (LC2 != RTLIB::UNKNOWN_LIBCALL) { |
Scott Michel | 5b8f82e | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 4794 | Tmp1 = DAG.getNode(ISD::SETCC, TLI.getSetCCResultType(Tmp1), Tmp1, Tmp2, |
Nate Begeman | 5922f56 | 2008-03-14 00:53:31 +0000 | [diff] [blame] | 4795 | CC); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 4796 | LHS = ExpandLibCall(TLI.getLibcallName(LC2), |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 4797 | DAG.getNode(ISD::MERGE_VALUES, VT, LHS, RHS).Val, |
Reid Spencer | b47b25c | 2007-01-03 04:22:32 +0000 | [diff] [blame] | 4798 | false /*sign irrelevant*/, Dummy); |
Scott Michel | 5b8f82e | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 4799 | Tmp2 = DAG.getNode(ISD::SETCC, TLI.getSetCCResultType(LHS), LHS, Tmp2, |
Evan Cheng | d385fd6 | 2007-01-31 09:29:11 +0000 | [diff] [blame] | 4800 | DAG.getCondCode(TLI.getCmpLibcallCC(LC2))); |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4801 | Tmp1 = DAG.getNode(ISD::OR, Tmp1.getValueType(), Tmp1, Tmp2); |
| 4802 | Tmp2 = SDOperand(); |
| 4803 | } |
| 4804 | LHS = Tmp1; |
| 4805 | RHS = Tmp2; |
| 4806 | return; |
| 4807 | } |
| 4808 | |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 4809 | SDOperand LHSLo, LHSHi, RHSLo, RHSHi; |
| 4810 | ExpandOp(LHS, LHSLo, LHSHi); |
Dale Johannesen | 638ccd5 | 2007-10-06 01:24:11 +0000 | [diff] [blame] | 4811 | ExpandOp(RHS, RHSLo, RHSHi); |
| 4812 | ISD::CondCode CCCode = cast<CondCodeSDNode>(CC)->get(); |
| 4813 | |
| 4814 | if (VT==MVT::ppcf128) { |
| 4815 | // FIXME: This generated code sucks. We want to generate |
| 4816 | // FCMP crN, hi1, hi2 |
| 4817 | // BNE crN, L: |
| 4818 | // FCMP crN, lo1, lo2 |
| 4819 | // The following can be improved, but not that much. |
Scott Michel | 5b8f82e | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 4820 | Tmp1 = DAG.getSetCC(TLI.getSetCCResultType(LHSHi), LHSHi, RHSHi, ISD::SETEQ); |
| 4821 | Tmp2 = DAG.getSetCC(TLI.getSetCCResultType(LHSLo), LHSLo, RHSLo, CCCode); |
Dale Johannesen | 638ccd5 | 2007-10-06 01:24:11 +0000 | [diff] [blame] | 4822 | Tmp3 = DAG.getNode(ISD::AND, Tmp1.getValueType(), Tmp1, Tmp2); |
Scott Michel | 5b8f82e | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 4823 | Tmp1 = DAG.getSetCC(TLI.getSetCCResultType(LHSHi), LHSHi, RHSHi, ISD::SETNE); |
| 4824 | Tmp2 = DAG.getSetCC(TLI.getSetCCResultType(LHSHi), LHSHi, RHSHi, CCCode); |
Dale Johannesen | 638ccd5 | 2007-10-06 01:24:11 +0000 | [diff] [blame] | 4825 | Tmp1 = DAG.getNode(ISD::AND, Tmp1.getValueType(), Tmp1, Tmp2); |
| 4826 | Tmp1 = DAG.getNode(ISD::OR, Tmp1.getValueType(), Tmp1, Tmp3); |
| 4827 | Tmp2 = SDOperand(); |
| 4828 | break; |
| 4829 | } |
| 4830 | |
| 4831 | switch (CCCode) { |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 4832 | case ISD::SETEQ: |
| 4833 | case ISD::SETNE: |
| 4834 | if (RHSLo == RHSHi) |
| 4835 | if (ConstantSDNode *RHSCST = dyn_cast<ConstantSDNode>(RHSLo)) |
| 4836 | if (RHSCST->isAllOnesValue()) { |
| 4837 | // Comparison to -1. |
| 4838 | Tmp1 = DAG.getNode(ISD::AND, LHSLo.getValueType(), LHSLo, LHSHi); |
| 4839 | Tmp2 = RHSLo; |
| 4840 | break; |
| 4841 | } |
| 4842 | |
| 4843 | Tmp1 = DAG.getNode(ISD::XOR, LHSLo.getValueType(), LHSLo, RHSLo); |
| 4844 | Tmp2 = DAG.getNode(ISD::XOR, LHSLo.getValueType(), LHSHi, RHSHi); |
| 4845 | Tmp1 = DAG.getNode(ISD::OR, Tmp1.getValueType(), Tmp1, Tmp2); |
| 4846 | Tmp2 = DAG.getConstant(0, Tmp1.getValueType()); |
| 4847 | break; |
| 4848 | default: |
| 4849 | // If this is a comparison of the sign bit, just look at the top part. |
| 4850 | // X > -1, x < 0 |
| 4851 | if (ConstantSDNode *CST = dyn_cast<ConstantSDNode>(RHS)) |
| 4852 | if ((cast<CondCodeSDNode>(CC)->get() == ISD::SETLT && |
Dan Gohman | 002e5d0 | 2008-03-13 22:13:53 +0000 | [diff] [blame] | 4853 | CST->isNullValue()) || // X < 0 |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 4854 | (cast<CondCodeSDNode>(CC)->get() == ISD::SETGT && |
| 4855 | CST->isAllOnesValue())) { // X > -1 |
| 4856 | Tmp1 = LHSHi; |
| 4857 | Tmp2 = RHSHi; |
| 4858 | break; |
| 4859 | } |
| 4860 | |
| 4861 | // FIXME: This generated code sucks. |
| 4862 | ISD::CondCode LowCC; |
Evan Cheng | 2e67781 | 2007-02-08 22:16:19 +0000 | [diff] [blame] | 4863 | switch (CCCode) { |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 4864 | default: assert(0 && "Unknown integer setcc!"); |
| 4865 | case ISD::SETLT: |
| 4866 | case ISD::SETULT: LowCC = ISD::SETULT; break; |
| 4867 | case ISD::SETGT: |
| 4868 | case ISD::SETUGT: LowCC = ISD::SETUGT; break; |
| 4869 | case ISD::SETLE: |
| 4870 | case ISD::SETULE: LowCC = ISD::SETULE; break; |
| 4871 | case ISD::SETGE: |
| 4872 | case ISD::SETUGE: LowCC = ISD::SETUGE; break; |
| 4873 | } |
| 4874 | |
| 4875 | // Tmp1 = lo(op1) < lo(op2) // Always unsigned comparison |
| 4876 | // Tmp2 = hi(op1) < hi(op2) // Signedness depends on operands |
| 4877 | // dest = hi(op1) == hi(op2) ? Tmp1 : Tmp2; |
| 4878 | |
| 4879 | // NOTE: on targets without efficient SELECT of bools, we can always use |
| 4880 | // this identity: (B1 ? B2 : B3) --> (B1 & B2)|(!B1&B3) |
Evan Cheng | 2e67781 | 2007-02-08 22:16:19 +0000 | [diff] [blame] | 4881 | TargetLowering::DAGCombinerInfo DagCombineInfo(DAG, false, true, NULL); |
Scott Michel | 5b8f82e | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 4882 | Tmp1 = TLI.SimplifySetCC(TLI.getSetCCResultType(LHSLo), LHSLo, RHSLo, |
Nate Begeman | 5922f56 | 2008-03-14 00:53:31 +0000 | [diff] [blame] | 4883 | LowCC, false, DagCombineInfo); |
Evan Cheng | 2e67781 | 2007-02-08 22:16:19 +0000 | [diff] [blame] | 4884 | if (!Tmp1.Val) |
Scott Michel | 5b8f82e | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 4885 | Tmp1 = DAG.getSetCC(TLI.getSetCCResultType(LHSLo), LHSLo, RHSLo, LowCC); |
| 4886 | Tmp2 = TLI.SimplifySetCC(TLI.getSetCCResultType(LHSHi), LHSHi, RHSHi, |
Evan Cheng | 2e67781 | 2007-02-08 22:16:19 +0000 | [diff] [blame] | 4887 | CCCode, false, DagCombineInfo); |
| 4888 | if (!Tmp2.Val) |
Scott Michel | 5b8f82e | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 4889 | Tmp2 = DAG.getNode(ISD::SETCC, TLI.getSetCCResultType(LHSHi), LHSHi, |
Nate Begeman | 5922f56 | 2008-03-14 00:53:31 +0000 | [diff] [blame] | 4890 | RHSHi,CC); |
Evan Cheng | 2e67781 | 2007-02-08 22:16:19 +0000 | [diff] [blame] | 4891 | |
| 4892 | ConstantSDNode *Tmp1C = dyn_cast<ConstantSDNode>(Tmp1.Val); |
| 4893 | ConstantSDNode *Tmp2C = dyn_cast<ConstantSDNode>(Tmp2.Val); |
Dan Gohman | 002e5d0 | 2008-03-13 22:13:53 +0000 | [diff] [blame] | 4894 | if ((Tmp1C && Tmp1C->isNullValue()) || |
| 4895 | (Tmp2C && Tmp2C->isNullValue() && |
Evan Cheng | 2e67781 | 2007-02-08 22:16:19 +0000 | [diff] [blame] | 4896 | (CCCode == ISD::SETLE || CCCode == ISD::SETGE || |
| 4897 | CCCode == ISD::SETUGE || CCCode == ISD::SETULE)) || |
Dan Gohman | 002e5d0 | 2008-03-13 22:13:53 +0000 | [diff] [blame] | 4898 | (Tmp2C && Tmp2C->getAPIntValue() == 1 && |
Evan Cheng | 2e67781 | 2007-02-08 22:16:19 +0000 | [diff] [blame] | 4899 | (CCCode == ISD::SETLT || CCCode == ISD::SETGT || |
| 4900 | CCCode == ISD::SETUGT || CCCode == ISD::SETULT))) { |
| 4901 | // low part is known false, returns high part. |
| 4902 | // For LE / GE, if high part is known false, ignore the low part. |
| 4903 | // For LT / GT, if high part is known true, ignore the low part. |
| 4904 | Tmp1 = Tmp2; |
| 4905 | Tmp2 = SDOperand(); |
| 4906 | } else { |
Scott Michel | 5b8f82e | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 4907 | Result = TLI.SimplifySetCC(TLI.getSetCCResultType(LHSHi), LHSHi, RHSHi, |
Evan Cheng | 2e67781 | 2007-02-08 22:16:19 +0000 | [diff] [blame] | 4908 | ISD::SETEQ, false, DagCombineInfo); |
| 4909 | if (!Result.Val) |
Scott Michel | 5b8f82e | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 4910 | Result=DAG.getSetCC(TLI.getSetCCResultType(LHSHi), LHSHi, RHSHi, |
Nate Begeman | 5922f56 | 2008-03-14 00:53:31 +0000 | [diff] [blame] | 4911 | ISD::SETEQ); |
Evan Cheng | 2e67781 | 2007-02-08 22:16:19 +0000 | [diff] [blame] | 4912 | Result = LegalizeOp(DAG.getNode(ISD::SELECT, Tmp1.getValueType(), |
| 4913 | Result, Tmp1, Tmp2)); |
| 4914 | Tmp1 = Result; |
| 4915 | Tmp2 = SDOperand(); |
| 4916 | } |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 4917 | } |
| 4918 | } |
Evan Cheng | 2b49c50 | 2006-12-15 02:59:56 +0000 | [diff] [blame] | 4919 | } |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 4920 | LHS = Tmp1; |
| 4921 | RHS = Tmp2; |
| 4922 | } |
| 4923 | |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 4924 | /// EmitStackConvert - Emit a store/load combination to the stack. This stores |
| 4925 | /// SrcOp to a stack slot of type SlotVT, truncating it if needed. It then does |
| 4926 | /// a load from the stack slot to DestVT, extending it if needed. |
| 4927 | /// The resultant code need not be legal. |
| 4928 | SDOperand SelectionDAGLegalize::EmitStackConvert(SDOperand SrcOp, |
| 4929 | MVT::ValueType SlotVT, |
| 4930 | MVT::ValueType DestVT) { |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 4931 | // Create the stack frame object. |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 4932 | SDOperand FIPtr = DAG.CreateStackTemporary(SlotVT); |
| 4933 | |
Dan Gohman | bbbbb9c | 2008-02-11 18:58:42 +0000 | [diff] [blame] | 4934 | FrameIndexSDNode *StackPtrFI = cast<FrameIndexSDNode>(FIPtr); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 4935 | int SPFI = StackPtrFI->getIndex(); |
| 4936 | |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 4937 | unsigned SrcSize = MVT::getSizeInBits(SrcOp.getValueType()); |
| 4938 | unsigned SlotSize = MVT::getSizeInBits(SlotVT); |
| 4939 | unsigned DestSize = MVT::getSizeInBits(DestVT); |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 4940 | |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 4941 | // Emit a store to the stack slot. Use a truncstore if the input value is |
| 4942 | // later than DestVT. |
| 4943 | SDOperand Store; |
| 4944 | if (SrcSize > SlotSize) |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 4945 | Store = DAG.getTruncStore(DAG.getEntryNode(), SrcOp, FIPtr, |
Dan Gohman | 3069b87 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 4946 | PseudoSourceValue::getFixedStack(), |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 4947 | SPFI, SlotVT); |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 4948 | else { |
| 4949 | assert(SrcSize == SlotSize && "Invalid store"); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 4950 | Store = DAG.getStore(DAG.getEntryNode(), SrcOp, FIPtr, |
Dan Gohman | 3069b87 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 4951 | PseudoSourceValue::getFixedStack(), |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 4952 | SPFI, SlotVT); |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 4953 | } |
| 4954 | |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 4955 | // Result is a load from the stack slot. |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 4956 | if (SlotSize == DestSize) |
| 4957 | return DAG.getLoad(DestVT, Store, FIPtr, NULL, 0); |
| 4958 | |
| 4959 | assert(SlotSize < DestSize && "Unknown extension!"); |
| 4960 | return DAG.getExtLoad(ISD::EXTLOAD, DestVT, Store, FIPtr, NULL, 0, SlotVT); |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 4961 | } |
| 4962 | |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 4963 | SDOperand SelectionDAGLegalize::ExpandSCALAR_TO_VECTOR(SDNode *Node) { |
| 4964 | // Create a vector sized/aligned stack slot, store the value to element #0, |
| 4965 | // then load the whole vector back out. |
Chris Lattner | 85dd3be | 2007-10-15 17:48:57 +0000 | [diff] [blame] | 4966 | SDOperand StackPtr = DAG.CreateStackTemporary(Node->getValueType(0)); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 4967 | |
Dan Gohman | bbbbb9c | 2008-02-11 18:58:42 +0000 | [diff] [blame] | 4968 | FrameIndexSDNode *StackPtrFI = cast<FrameIndexSDNode>(StackPtr); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 4969 | int SPFI = StackPtrFI->getIndex(); |
| 4970 | |
Evan Cheng | 786225a | 2006-10-05 23:01:46 +0000 | [diff] [blame] | 4971 | SDOperand Ch = DAG.getStore(DAG.getEntryNode(), Node->getOperand(0), StackPtr, |
Dan Gohman | 3069b87 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 4972 | PseudoSourceValue::getFixedStack(), SPFI); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 4973 | return DAG.getLoad(Node->getValueType(0), Ch, StackPtr, |
Dan Gohman | 3069b87 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 4974 | PseudoSourceValue::getFixedStack(), SPFI); |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 4975 | } |
| 4976 | |
| 4977 | |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4978 | /// ExpandBUILD_VECTOR - Expand a BUILD_VECTOR node on targets that don't |
Dan Gohman | 07a9676 | 2007-07-16 14:29:03 +0000 | [diff] [blame] | 4979 | /// support the operation, but do support the resultant vector type. |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4980 | SDOperand SelectionDAGLegalize::ExpandBUILD_VECTOR(SDNode *Node) { |
| 4981 | |
| 4982 | // 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] | 4983 | // 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] | 4984 | unsigned NumElems = Node->getNumOperands(); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 4985 | bool isOnlyLowElement = true; |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 4986 | SDOperand SplatValue = Node->getOperand(0); |
Chris Lattner | f9d95c8 | 2008-03-09 00:29:42 +0000 | [diff] [blame] | 4987 | |
| 4988 | // FIXME: it would be far nicer to change this into map<SDOperand,uint64_t> |
| 4989 | // and use a bitmask instead of a list of elements. |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 4990 | std::map<SDOperand, std::vector<unsigned> > Values; |
| 4991 | Values[SplatValue].push_back(0); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 4992 | bool isConstant = true; |
| 4993 | if (!isa<ConstantFPSDNode>(SplatValue) && !isa<ConstantSDNode>(SplatValue) && |
| 4994 | SplatValue.getOpcode() != ISD::UNDEF) |
| 4995 | isConstant = false; |
| 4996 | |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 4997 | for (unsigned i = 1; i < NumElems; ++i) { |
| 4998 | SDOperand V = Node->getOperand(i); |
Chris Lattner | 89a1b38 | 2006-04-19 23:17:50 +0000 | [diff] [blame] | 4999 | Values[V].push_back(i); |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 5000 | if (V.getOpcode() != ISD::UNDEF) |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5001 | isOnlyLowElement = false; |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 5002 | if (SplatValue != V) |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 5003 | SplatValue = SDOperand(0,0); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 5004 | |
| 5005 | // If this isn't a constant element or an undef, we can't use a constant |
| 5006 | // pool load. |
| 5007 | if (!isa<ConstantFPSDNode>(V) && !isa<ConstantSDNode>(V) && |
| 5008 | V.getOpcode() != ISD::UNDEF) |
| 5009 | isConstant = false; |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5010 | } |
| 5011 | |
| 5012 | if (isOnlyLowElement) { |
| 5013 | // If the low element is an undef too, then this whole things is an undef. |
| 5014 | if (Node->getOperand(0).getOpcode() == ISD::UNDEF) |
| 5015 | return DAG.getNode(ISD::UNDEF, Node->getValueType(0)); |
| 5016 | // Otherwise, turn this into a scalar_to_vector node. |
| 5017 | return DAG.getNode(ISD::SCALAR_TO_VECTOR, Node->getValueType(0), |
| 5018 | Node->getOperand(0)); |
| 5019 | } |
| 5020 | |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 5021 | // If all elements are constants, create a load from the constant pool. |
| 5022 | if (isConstant) { |
| 5023 | MVT::ValueType VT = Node->getValueType(0); |
| 5024 | const Type *OpNTy = |
| 5025 | MVT::getTypeForValueType(Node->getOperand(0).getValueType()); |
| 5026 | std::vector<Constant*> CV; |
| 5027 | for (unsigned i = 0, e = NumElems; i != e; ++i) { |
| 5028 | if (ConstantFPSDNode *V = |
| 5029 | dyn_cast<ConstantFPSDNode>(Node->getOperand(i))) { |
Dale Johannesen | f04afdb | 2007-08-30 00:23:21 +0000 | [diff] [blame] | 5030 | CV.push_back(ConstantFP::get(OpNTy, V->getValueAPF())); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 5031 | } else if (ConstantSDNode *V = |
| 5032 | dyn_cast<ConstantSDNode>(Node->getOperand(i))) { |
Reid Spencer | b83eb64 | 2006-10-20 07:07:24 +0000 | [diff] [blame] | 5033 | CV.push_back(ConstantInt::get(OpNTy, V->getValue())); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 5034 | } else { |
| 5035 | assert(Node->getOperand(i).getOpcode() == ISD::UNDEF); |
| 5036 | CV.push_back(UndefValue::get(OpNTy)); |
| 5037 | } |
| 5038 | } |
Reid Spencer | 9d6565a | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 5039 | Constant *CP = ConstantVector::get(CV); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 5040 | SDOperand CPIdx = DAG.getConstantPool(CP, TLI.getPointerTy()); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5041 | return DAG.getLoad(VT, DAG.getEntryNode(), CPIdx, |
Dan Gohman | 3069b87 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 5042 | PseudoSourceValue::getConstantPool(), 0); |
Chris Lattner | 2eb8653 | 2006-03-24 07:29:17 +0000 | [diff] [blame] | 5043 | } |
| 5044 | |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 5045 | if (SplatValue.Val) { // Splat of one value? |
| 5046 | // Build the shuffle constant vector: <0, 0, 0, 0> |
| 5047 | MVT::ValueType MaskVT = |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 5048 | MVT::getIntVectorWithNumElements(NumElems); |
Dan Gohman | 51eaa86 | 2007-06-14 22:58:02 +0000 | [diff] [blame] | 5049 | SDOperand Zero = DAG.getConstant(0, MVT::getVectorElementType(MaskVT)); |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 5050 | std::vector<SDOperand> ZeroVec(NumElems, Zero); |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 5051 | SDOperand SplatMask = DAG.getNode(ISD::BUILD_VECTOR, MaskVT, |
| 5052 | &ZeroVec[0], ZeroVec.size()); |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 5053 | |
| 5054 | // If the target supports VECTOR_SHUFFLE and this shuffle mask, use it. |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 5055 | if (isShuffleLegal(Node->getValueType(0), SplatMask)) { |
Chris Lattner | 87100e0 | 2006-03-20 01:52:29 +0000 | [diff] [blame] | 5056 | // Get the splatted value into the low element of a vector register. |
| 5057 | SDOperand LowValVec = |
| 5058 | DAG.getNode(ISD::SCALAR_TO_VECTOR, Node->getValueType(0), SplatValue); |
| 5059 | |
| 5060 | // Return shuffle(LowValVec, undef, <0,0,0,0>) |
| 5061 | return DAG.getNode(ISD::VECTOR_SHUFFLE, Node->getValueType(0), LowValVec, |
| 5062 | DAG.getNode(ISD::UNDEF, Node->getValueType(0)), |
| 5063 | SplatMask); |
| 5064 | } |
| 5065 | } |
| 5066 | |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 5067 | // If there are only two unique elements, we may be able to turn this into a |
| 5068 | // vector shuffle. |
| 5069 | if (Values.size() == 2) { |
Chris Lattner | f9d95c8 | 2008-03-09 00:29:42 +0000 | [diff] [blame] | 5070 | // Get the two values in deterministic order. |
| 5071 | SDOperand Val1 = Node->getOperand(1); |
| 5072 | SDOperand Val2; |
| 5073 | std::map<SDOperand, std::vector<unsigned> >::iterator MI = Values.begin(); |
| 5074 | if (MI->first != Val1) |
| 5075 | Val2 = MI->first; |
| 5076 | else |
| 5077 | Val2 = (++MI)->first; |
| 5078 | |
| 5079 | // If Val1 is an undef, make sure end ends up as Val2, to ensure that our |
| 5080 | // vector shuffle has the undef vector on the RHS. |
| 5081 | if (Val1.getOpcode() == ISD::UNDEF) |
| 5082 | std::swap(Val1, Val2); |
| 5083 | |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 5084 | // Build the shuffle constant vector: e.g. <0, 4, 0, 4> |
Chris Lattner | f9d95c8 | 2008-03-09 00:29:42 +0000 | [diff] [blame] | 5085 | MVT::ValueType MaskVT = MVT::getIntVectorWithNumElements(NumElems); |
| 5086 | MVT::ValueType MaskEltVT = MVT::getVectorElementType(MaskVT); |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 5087 | std::vector<SDOperand> MaskVec(NumElems); |
Chris Lattner | f9d95c8 | 2008-03-09 00:29:42 +0000 | [diff] [blame] | 5088 | |
| 5089 | // Set elements of the shuffle mask for Val1. |
| 5090 | std::vector<unsigned> &Val1Elts = Values[Val1]; |
| 5091 | for (unsigned i = 0, e = Val1Elts.size(); i != e; ++i) |
| 5092 | MaskVec[Val1Elts[i]] = DAG.getConstant(0, MaskEltVT); |
| 5093 | |
| 5094 | // Set elements of the shuffle mask for Val2. |
| 5095 | std::vector<unsigned> &Val2Elts = Values[Val2]; |
| 5096 | for (unsigned i = 0, e = Val2Elts.size(); i != e; ++i) |
| 5097 | if (Val2.getOpcode() != ISD::UNDEF) |
| 5098 | MaskVec[Val2Elts[i]] = DAG.getConstant(NumElems, MaskEltVT); |
| 5099 | else |
| 5100 | MaskVec[Val2Elts[i]] = DAG.getNode(ISD::UNDEF, MaskEltVT); |
| 5101 | |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 5102 | SDOperand ShuffleMask = DAG.getNode(ISD::BUILD_VECTOR, MaskVT, |
| 5103 | &MaskVec[0], MaskVec.size()); |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 5104 | |
Chris Lattner | f9d95c8 | 2008-03-09 00:29:42 +0000 | [diff] [blame] | 5105 | // If the target supports SCALAR_TO_VECTOR and this shuffle mask, use it. |
Chris Lattner | 4352cc9 | 2006-04-04 17:23:26 +0000 | [diff] [blame] | 5106 | if (TLI.isOperationLegal(ISD::SCALAR_TO_VECTOR, Node->getValueType(0)) && |
| 5107 | isShuffleLegal(Node->getValueType(0), ShuffleMask)) { |
Chris Lattner | f9d95c8 | 2008-03-09 00:29:42 +0000 | [diff] [blame] | 5108 | Val1 = DAG.getNode(ISD::SCALAR_TO_VECTOR, Node->getValueType(0), Val1); |
| 5109 | Val2 = DAG.getNode(ISD::SCALAR_TO_VECTOR, Node->getValueType(0), Val2); |
| 5110 | SDOperand Ops[] = { Val1, Val2, ShuffleMask }; |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 5111 | |
| 5112 | // Return shuffle(LoValVec, HiValVec, <0,1,0,1>) |
Chris Lattner | f9d95c8 | 2008-03-09 00:29:42 +0000 | [diff] [blame] | 5113 | return DAG.getNode(ISD::VECTOR_SHUFFLE, Node->getValueType(0), Ops, 3); |
Evan Cheng | 033e681 | 2006-03-24 01:17:21 +0000 | [diff] [blame] | 5114 | } |
| 5115 | } |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5116 | |
| 5117 | // Otherwise, we can't handle this case efficiently. Allocate a sufficiently |
| 5118 | // aligned object on the stack, store each element into it, then load |
| 5119 | // the result as a vector. |
| 5120 | MVT::ValueType VT = Node->getValueType(0); |
| 5121 | // Create the stack frame object. |
Chris Lattner | 85dd3be | 2007-10-15 17:48:57 +0000 | [diff] [blame] | 5122 | SDOperand FIPtr = DAG.CreateStackTemporary(VT); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5123 | |
| 5124 | // Emit a store of each element to the stack slot. |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 5125 | SmallVector<SDOperand, 8> Stores; |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5126 | unsigned TypeByteSize = |
| 5127 | MVT::getSizeInBits(Node->getOperand(0).getValueType())/8; |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5128 | // Store (in the right endianness) the elements to memory. |
| 5129 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) { |
| 5130 | // Ignore undef elements. |
| 5131 | if (Node->getOperand(i).getOpcode() == ISD::UNDEF) continue; |
| 5132 | |
Chris Lattner | 841c882 | 2006-03-22 01:46:54 +0000 | [diff] [blame] | 5133 | unsigned Offset = TypeByteSize*i; |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5134 | |
| 5135 | SDOperand Idx = DAG.getConstant(Offset, FIPtr.getValueType()); |
| 5136 | Idx = DAG.getNode(ISD::ADD, FIPtr.getValueType(), FIPtr, Idx); |
| 5137 | |
Evan Cheng | 786225a | 2006-10-05 23:01:46 +0000 | [diff] [blame] | 5138 | Stores.push_back(DAG.getStore(DAG.getEntryNode(), Node->getOperand(i), Idx, |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 5139 | NULL, 0)); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5140 | } |
| 5141 | |
| 5142 | SDOperand StoreChain; |
| 5143 | if (!Stores.empty()) // Not all undef elements? |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 5144 | StoreChain = DAG.getNode(ISD::TokenFactor, MVT::Other, |
| 5145 | &Stores[0], Stores.size()); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5146 | else |
| 5147 | StoreChain = DAG.getEntryNode(); |
| 5148 | |
| 5149 | // Result is a load from the stack slot. |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 5150 | return DAG.getLoad(VT, StoreChain, FIPtr, NULL, 0); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 5151 | } |
| 5152 | |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 5153 | void SelectionDAGLegalize::ExpandShiftParts(unsigned NodeOp, |
| 5154 | SDOperand Op, SDOperand Amt, |
| 5155 | SDOperand &Lo, SDOperand &Hi) { |
| 5156 | // Expand the subcomponents. |
| 5157 | SDOperand LHSL, LHSH; |
| 5158 | ExpandOp(Op, LHSL, LHSH); |
| 5159 | |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 5160 | SDOperand Ops[] = { LHSL, LHSH, Amt }; |
Chris Lattner | f9f37fc | 2006-08-14 23:53:35 +0000 | [diff] [blame] | 5161 | MVT::ValueType VT = LHSL.getValueType(); |
| 5162 | Lo = DAG.getNode(NodeOp, DAG.getNodeValueTypes(VT, VT), 2, Ops, 3); |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 5163 | Hi = Lo.getValue(1); |
| 5164 | } |
| 5165 | |
| 5166 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5167 | /// ExpandShift - Try to find a clever way to expand this shift operation out to |
| 5168 | /// smaller elements. If we can't find a way that is more efficient than a |
| 5169 | /// libcall on this target, return false. Otherwise, return true with the |
| 5170 | /// low-parts expanded into Lo and Hi. |
| 5171 | bool SelectionDAGLegalize::ExpandShift(unsigned Opc, SDOperand Op,SDOperand Amt, |
| 5172 | SDOperand &Lo, SDOperand &Hi) { |
| 5173 | assert((Opc == ISD::SHL || Opc == ISD::SRA || Opc == ISD::SRL) && |
| 5174 | "This is not a shift!"); |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5175 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5176 | MVT::ValueType NVT = TLI.getTypeToTransformTo(Op.getValueType()); |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5177 | SDOperand ShAmt = LegalizeOp(Amt); |
| 5178 | MVT::ValueType ShTy = ShAmt.getValueType(); |
Dan Gohman | 91dc17b | 2008-02-20 16:57:27 +0000 | [diff] [blame] | 5179 | unsigned ShBits = MVT::getSizeInBits(ShTy); |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5180 | unsigned VTBits = MVT::getSizeInBits(Op.getValueType()); |
| 5181 | unsigned NVTBits = MVT::getSizeInBits(NVT); |
| 5182 | |
Chris Lattner | 7a3c855 | 2007-10-14 20:35:12 +0000 | [diff] [blame] | 5183 | // Handle the case when Amt is an immediate. |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5184 | if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Amt.Val)) { |
| 5185 | unsigned Cst = CN->getValue(); |
| 5186 | // Expand the incoming operand to be shifted, so that we have its parts |
| 5187 | SDOperand InL, InH; |
| 5188 | ExpandOp(Op, InL, InH); |
| 5189 | switch(Opc) { |
| 5190 | case ISD::SHL: |
| 5191 | if (Cst > VTBits) { |
| 5192 | Lo = DAG.getConstant(0, NVT); |
| 5193 | Hi = DAG.getConstant(0, NVT); |
| 5194 | } else if (Cst > NVTBits) { |
| 5195 | Lo = DAG.getConstant(0, NVT); |
| 5196 | Hi = DAG.getNode(ISD::SHL, NVT, InL, DAG.getConstant(Cst-NVTBits,ShTy)); |
Chris Lattner | ee27f57 | 2005-04-11 20:08:52 +0000 | [diff] [blame] | 5197 | } else if (Cst == NVTBits) { |
| 5198 | Lo = DAG.getConstant(0, NVT); |
| 5199 | Hi = InL; |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5200 | } else { |
| 5201 | Lo = DAG.getNode(ISD::SHL, NVT, InL, DAG.getConstant(Cst, ShTy)); |
| 5202 | Hi = DAG.getNode(ISD::OR, NVT, |
| 5203 | DAG.getNode(ISD::SHL, NVT, InH, DAG.getConstant(Cst, ShTy)), |
| 5204 | DAG.getNode(ISD::SRL, NVT, InL, DAG.getConstant(NVTBits-Cst, ShTy))); |
| 5205 | } |
| 5206 | return true; |
| 5207 | case ISD::SRL: |
| 5208 | if (Cst > VTBits) { |
| 5209 | Lo = DAG.getConstant(0, NVT); |
| 5210 | Hi = DAG.getConstant(0, NVT); |
| 5211 | } else if (Cst > NVTBits) { |
| 5212 | Lo = DAG.getNode(ISD::SRL, NVT, InH, DAG.getConstant(Cst-NVTBits,ShTy)); |
| 5213 | Hi = DAG.getConstant(0, NVT); |
Chris Lattner | ee27f57 | 2005-04-11 20:08:52 +0000 | [diff] [blame] | 5214 | } else if (Cst == NVTBits) { |
| 5215 | Lo = InH; |
| 5216 | Hi = DAG.getConstant(0, NVT); |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5217 | } else { |
| 5218 | Lo = DAG.getNode(ISD::OR, NVT, |
| 5219 | DAG.getNode(ISD::SRL, NVT, InL, DAG.getConstant(Cst, ShTy)), |
| 5220 | DAG.getNode(ISD::SHL, NVT, InH, DAG.getConstant(NVTBits-Cst, ShTy))); |
| 5221 | Hi = DAG.getNode(ISD::SRL, NVT, InH, DAG.getConstant(Cst, ShTy)); |
| 5222 | } |
| 5223 | return true; |
| 5224 | case ISD::SRA: |
| 5225 | if (Cst > VTBits) { |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 5226 | Hi = Lo = DAG.getNode(ISD::SRA, NVT, InH, |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5227 | DAG.getConstant(NVTBits-1, ShTy)); |
| 5228 | } else if (Cst > NVTBits) { |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 5229 | Lo = DAG.getNode(ISD::SRA, NVT, InH, |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5230 | DAG.getConstant(Cst-NVTBits, ShTy)); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 5231 | Hi = DAG.getNode(ISD::SRA, NVT, InH, |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5232 | DAG.getConstant(NVTBits-1, ShTy)); |
Chris Lattner | ee27f57 | 2005-04-11 20:08:52 +0000 | [diff] [blame] | 5233 | } else if (Cst == NVTBits) { |
| 5234 | Lo = InH; |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 5235 | Hi = DAG.getNode(ISD::SRA, NVT, InH, |
Chris Lattner | ee27f57 | 2005-04-11 20:08:52 +0000 | [diff] [blame] | 5236 | DAG.getConstant(NVTBits-1, ShTy)); |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5237 | } else { |
| 5238 | Lo = DAG.getNode(ISD::OR, NVT, |
| 5239 | DAG.getNode(ISD::SRL, NVT, InL, DAG.getConstant(Cst, ShTy)), |
| 5240 | DAG.getNode(ISD::SHL, NVT, InH, DAG.getConstant(NVTBits-Cst, ShTy))); |
| 5241 | Hi = DAG.getNode(ISD::SRA, NVT, InH, DAG.getConstant(Cst, ShTy)); |
| 5242 | } |
| 5243 | return true; |
| 5244 | } |
| 5245 | } |
Chris Lattner | 0ea26ca | 2006-09-20 03:38:48 +0000 | [diff] [blame] | 5246 | |
| 5247 | // Okay, the shift amount isn't constant. However, if we can tell that it is |
| 5248 | // >= 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] | 5249 | APInt Mask = APInt::getHighBitsSet(ShBits, ShBits - Log2_32(NVTBits)); |
| 5250 | APInt KnownZero, KnownOne; |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 5251 | DAG.ComputeMaskedBits(Amt, Mask, KnownZero, KnownOne); |
Chris Lattner | 0ea26ca | 2006-09-20 03:38:48 +0000 | [diff] [blame] | 5252 | |
Dan Gohman | 9e255b7 | 2008-02-22 01:12:31 +0000 | [diff] [blame] | 5253 | // If we know that if any of the high bits of the shift amount are one, then |
| 5254 | // we can do this as a couple of simple shifts. |
Dan Gohman | 91dc17b | 2008-02-20 16:57:27 +0000 | [diff] [blame] | 5255 | if (KnownOne.intersects(Mask)) { |
Chris Lattner | 0ea26ca | 2006-09-20 03:38:48 +0000 | [diff] [blame] | 5256 | // Mask out the high bit, which we know is set. |
| 5257 | Amt = DAG.getNode(ISD::AND, Amt.getValueType(), Amt, |
Dan Gohman | 91dc17b | 2008-02-20 16:57:27 +0000 | [diff] [blame] | 5258 | DAG.getConstant(~Mask, Amt.getValueType())); |
Chris Lattner | 0ea26ca | 2006-09-20 03:38:48 +0000 | [diff] [blame] | 5259 | |
| 5260 | // Expand the incoming operand to be shifted, so that we have its parts |
| 5261 | SDOperand InL, InH; |
| 5262 | ExpandOp(Op, InL, InH); |
| 5263 | switch(Opc) { |
| 5264 | case ISD::SHL: |
| 5265 | Lo = DAG.getConstant(0, NVT); // Low part is zero. |
| 5266 | Hi = DAG.getNode(ISD::SHL, NVT, InL, Amt); // High part from Lo part. |
| 5267 | return true; |
| 5268 | case ISD::SRL: |
| 5269 | Hi = DAG.getConstant(0, NVT); // Hi part is zero. |
| 5270 | Lo = DAG.getNode(ISD::SRL, NVT, InH, Amt); // Lo part from Hi part. |
| 5271 | return true; |
| 5272 | case ISD::SRA: |
| 5273 | Hi = DAG.getNode(ISD::SRA, NVT, InH, // Sign extend high part. |
| 5274 | DAG.getConstant(NVTBits-1, Amt.getValueType())); |
| 5275 | Lo = DAG.getNode(ISD::SRA, NVT, InH, Amt); // Lo part from Hi part. |
| 5276 | return true; |
| 5277 | } |
| 5278 | } |
| 5279 | |
Dan Gohman | 9e255b7 | 2008-02-22 01:12:31 +0000 | [diff] [blame] | 5280 | // If we know that the high bits of the shift amount are all zero, then we can |
| 5281 | // do this as a couple of simple shifts. |
| 5282 | if ((KnownZero & Mask) == Mask) { |
Chris Lattner | 0ea26ca | 2006-09-20 03:38:48 +0000 | [diff] [blame] | 5283 | // Compute 32-amt. |
| 5284 | SDOperand Amt2 = DAG.getNode(ISD::SUB, Amt.getValueType(), |
| 5285 | DAG.getConstant(NVTBits, Amt.getValueType()), |
| 5286 | Amt); |
| 5287 | |
| 5288 | // Expand the incoming operand to be shifted, so that we have its parts |
| 5289 | SDOperand InL, InH; |
| 5290 | ExpandOp(Op, InL, InH); |
| 5291 | switch(Opc) { |
| 5292 | case ISD::SHL: |
| 5293 | Lo = DAG.getNode(ISD::SHL, NVT, InL, Amt); |
| 5294 | Hi = DAG.getNode(ISD::OR, NVT, |
| 5295 | DAG.getNode(ISD::SHL, NVT, InH, Amt), |
| 5296 | DAG.getNode(ISD::SRL, NVT, InL, Amt2)); |
| 5297 | return true; |
| 5298 | case ISD::SRL: |
| 5299 | Hi = DAG.getNode(ISD::SRL, NVT, InH, Amt); |
| 5300 | Lo = DAG.getNode(ISD::OR, NVT, |
| 5301 | DAG.getNode(ISD::SRL, NVT, InL, Amt), |
| 5302 | DAG.getNode(ISD::SHL, NVT, InH, Amt2)); |
| 5303 | return true; |
| 5304 | case ISD::SRA: |
| 5305 | Hi = DAG.getNode(ISD::SRA, NVT, InH, Amt); |
| 5306 | Lo = DAG.getNode(ISD::OR, NVT, |
| 5307 | DAG.getNode(ISD::SRL, NVT, InL, Amt), |
| 5308 | DAG.getNode(ISD::SHL, NVT, InH, Amt2)); |
| 5309 | return true; |
| 5310 | } |
| 5311 | } |
| 5312 | |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 5313 | return false; |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5314 | } |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5315 | |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 5316 | |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5317 | // ExpandLibCall - Expand a node into a call to a libcall. If the result value |
| 5318 | // does not fit into a register, return the lo part and set the hi part to the |
| 5319 | // by-reg argument. If it does fit into a single register, return the result |
| 5320 | // and leave the Hi part unset. |
| 5321 | SDOperand SelectionDAGLegalize::ExpandLibCall(const char *Name, SDNode *Node, |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 5322 | bool isSigned, SDOperand &Hi) { |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 5323 | assert(!IsLegalizingCall && "Cannot overlap legalization of calls!"); |
| 5324 | // The input chain to this libcall is the entry node of the function. |
| 5325 | // Legalizing the call will automatically add the previous call to the |
| 5326 | // dependence. |
| 5327 | SDOperand InChain = DAG.getEntryNode(); |
| 5328 | |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5329 | TargetLowering::ArgListTy Args; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 5330 | TargetLowering::ArgListEntry Entry; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5331 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) { |
| 5332 | MVT::ValueType ArgVT = Node->getOperand(i).getValueType(); |
| 5333 | const Type *ArgTy = MVT::getTypeForValueType(ArgVT); |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 5334 | Entry.Node = Node->getOperand(i); Entry.Ty = ArgTy; |
Anton Korobeynikov | d0b82b3 | 2007-03-07 16:25:09 +0000 | [diff] [blame] | 5335 | Entry.isSExt = isSigned; |
Duncan Sands | 00fee65 | 2008-02-14 17:28:50 +0000 | [diff] [blame] | 5336 | Entry.isZExt = !isSigned; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 5337 | Args.push_back(Entry); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5338 | } |
| 5339 | SDOperand Callee = DAG.getExternalSymbol(Name, TLI.getPointerTy()); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 5340 | |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 5341 | // Splice the libcall in wherever FindInputOutputChains tells us to. |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5342 | const Type *RetTy = MVT::getTypeForValueType(Node->getValueType(0)); |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 5343 | std::pair<SDOperand,SDOperand> CallInfo = |
Duncan Sands | 00fee65 | 2008-02-14 17:28:50 +0000 | [diff] [blame] | 5344 | TLI.LowerCallTo(InChain, RetTy, isSigned, !isSigned, false, CallingConv::C, |
| 5345 | false, Callee, Args, DAG); |
Chris Lattner | b9fa3bc | 2005-05-12 04:49:08 +0000 | [diff] [blame] | 5346 | |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 5347 | // Legalize the call sequence, starting with the chain. This will advance |
| 5348 | // the LastCALLSEQ_END to the legalized version of the CALLSEQ_END node that |
| 5349 | // was added by LowerCallTo (guaranteeing proper serialization of calls). |
| 5350 | LegalizeOp(CallInfo.second); |
Chris Lattner | 99c25b8 | 2005-09-02 20:26:58 +0000 | [diff] [blame] | 5351 | SDOperand Result; |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 5352 | switch (getTypeAction(CallInfo.first.getValueType())) { |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5353 | default: assert(0 && "Unknown thing"); |
| 5354 | case Legal: |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 5355 | Result = CallInfo.first; |
Chris Lattner | 99c25b8 | 2005-09-02 20:26:58 +0000 | [diff] [blame] | 5356 | break; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5357 | case Expand: |
Chris Lattner | 99c25b8 | 2005-09-02 20:26:58 +0000 | [diff] [blame] | 5358 | ExpandOp(CallInfo.first, Result, Hi); |
Chris Lattner | 99c25b8 | 2005-09-02 20:26:58 +0000 | [diff] [blame] | 5359 | break; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5360 | } |
Chris Lattner | 99c25b8 | 2005-09-02 20:26:58 +0000 | [diff] [blame] | 5361 | return Result; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5362 | } |
| 5363 | |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 5364 | |
Evan Cheng | 4c6cfad | 2007-04-27 07:33:31 +0000 | [diff] [blame] | 5365 | /// ExpandIntToFP - Expand a [US]INT_TO_FP operation. |
| 5366 | /// |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5367 | SDOperand SelectionDAGLegalize:: |
| 5368 | ExpandIntToFP(bool isSigned, MVT::ValueType DestTy, SDOperand Source) { |
Dan Gohman | d91446d | 2008-03-05 01:08:17 +0000 | [diff] [blame] | 5369 | MVT::ValueType SourceVT = Source.getValueType(); |
Dan Gohman | 034f60e | 2008-03-11 01:59:03 +0000 | [diff] [blame] | 5370 | bool ExpandSource = getTypeAction(SourceVT) == Expand; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5371 | |
Evan Cheng | 9845eb5 | 2008-04-01 02:18:22 +0000 | [diff] [blame] | 5372 | // Special case for i32 source to take advantage of UINTTOFP_I32_F32, etc. |
| 5373 | if (!isSigned && SourceVT != MVT::i32) { |
Dan Gohman | 34bc178 | 2008-03-05 02:07:31 +0000 | [diff] [blame] | 5374 | // 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] | 5375 | // incoming integer is set. To handle this, we dynamically test to see if |
| 5376 | // it is set, and, if so, add a fudge factor. |
Dan Gohman | 034f60e | 2008-03-11 01:59:03 +0000 | [diff] [blame] | 5377 | SDOperand Hi; |
| 5378 | if (ExpandSource) { |
| 5379 | SDOperand Lo; |
| 5380 | ExpandOp(Source, Lo, Hi); |
| 5381 | Source = DAG.getNode(ISD::BUILD_PAIR, SourceVT, Lo, Hi); |
| 5382 | } else { |
| 5383 | // The comparison for the sign bit will use the entire operand. |
| 5384 | Hi = Source; |
| 5385 | } |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 5386 | |
Chris Lattner | 66de05b | 2005-05-13 04:45:13 +0000 | [diff] [blame] | 5387 | // If this is unsigned, and not supported, first perform the conversion to |
| 5388 | // signed, then adjust the result if the sign bit is set. |
Dan Gohman | 034f60e | 2008-03-11 01:59:03 +0000 | [diff] [blame] | 5389 | SDOperand SignedConv = ExpandIntToFP(true, DestTy, Source); |
Chris Lattner | 66de05b | 2005-05-13 04:45:13 +0000 | [diff] [blame] | 5390 | |
Scott Michel | 5b8f82e | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 5391 | SDOperand SignSet = DAG.getSetCC(TLI.getSetCCResultType(Hi), Hi, |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 5392 | DAG.getConstant(0, Hi.getValueType()), |
| 5393 | ISD::SETLT); |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 5394 | SDOperand Zero = DAG.getIntPtrConstant(0), Four = DAG.getIntPtrConstant(4); |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 5395 | SDOperand CstOffset = DAG.getNode(ISD::SELECT, Zero.getValueType(), |
| 5396 | SignSet, Four, Zero); |
Chris Lattner | 383203b | 2005-05-12 18:52:34 +0000 | [diff] [blame] | 5397 | uint64_t FF = 0x5f800000ULL; |
| 5398 | if (TLI.isLittleEndian()) FF <<= 32; |
Dan Gohman | 34bc178 | 2008-03-05 02:07:31 +0000 | [diff] [blame] | 5399 | static Constant *FudgeFactor = ConstantInt::get(Type::Int64Ty, FF); |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 5400 | |
Chris Lattner | 5839bf2 | 2005-08-26 17:15:30 +0000 | [diff] [blame] | 5401 | SDOperand CPIdx = DAG.getConstantPool(FudgeFactor, TLI.getPointerTy()); |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 5402 | CPIdx = DAG.getNode(ISD::ADD, TLI.getPointerTy(), CPIdx, CstOffset); |
| 5403 | SDOperand FudgeInReg; |
| 5404 | if (DestTy == MVT::f32) |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5405 | FudgeInReg = DAG.getLoad(MVT::f32, DAG.getEntryNode(), CPIdx, |
Dan Gohman | 3069b87 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 5406 | PseudoSourceValue::getConstantPool(), 0); |
Dale Johannesen | 118cd9d | 2007-09-16 16:51:49 +0000 | [diff] [blame] | 5407 | else if (MVT::getSizeInBits(DestTy) > MVT::getSizeInBits(MVT::f32)) |
Evan Cheng | 4c6cfad | 2007-04-27 07:33:31 +0000 | [diff] [blame] | 5408 | // FIXME: Avoid the extend by construction the right constantpool? |
Dale Johannesen | 118cd9d | 2007-09-16 16:51:49 +0000 | [diff] [blame] | 5409 | FudgeInReg = DAG.getExtLoad(ISD::EXTLOAD, DestTy, DAG.getEntryNode(), |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5410 | CPIdx, |
Dan Gohman | 3069b87 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 5411 | PseudoSourceValue::getConstantPool(), 0, |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5412 | MVT::f32); |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 5413 | else |
| 5414 | assert(0 && "Unexpected conversion"); |
| 5415 | |
Evan Cheng | 4c6cfad | 2007-04-27 07:33:31 +0000 | [diff] [blame] | 5416 | MVT::ValueType SCVT = SignedConv.getValueType(); |
| 5417 | if (SCVT != DestTy) { |
| 5418 | // Destination type needs to be expanded as well. The FADD now we are |
| 5419 | // constructing will be expanded into a libcall. |
| 5420 | if (MVT::getSizeInBits(SCVT) != MVT::getSizeInBits(DestTy)) { |
Dan Gohman | d91446d | 2008-03-05 01:08:17 +0000 | [diff] [blame] | 5421 | assert(MVT::getSizeInBits(SCVT) * 2 == MVT::getSizeInBits(DestTy)); |
| 5422 | SignedConv = DAG.getNode(ISD::BUILD_PAIR, DestTy, |
Evan Cheng | 4c6cfad | 2007-04-27 07:33:31 +0000 | [diff] [blame] | 5423 | SignedConv, SignedConv.getValue(1)); |
| 5424 | } |
| 5425 | SignedConv = DAG.getNode(ISD::BIT_CONVERT, DestTy, SignedConv); |
| 5426 | } |
Chris Lattner | 473a990 | 2005-09-29 06:44:39 +0000 | [diff] [blame] | 5427 | return DAG.getNode(ISD::FADD, DestTy, SignedConv, FudgeInReg); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5428 | } |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 5429 | |
Chris Lattner | a88a260 | 2005-05-14 05:33:54 +0000 | [diff] [blame] | 5430 | // 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] | 5431 | switch (TLI.getOperationAction(ISD::SINT_TO_FP, SourceVT)) { |
Chris Lattner | a88a260 | 2005-05-14 05:33:54 +0000 | [diff] [blame] | 5432 | default: assert(0 && "This action not implemented for this operation!"); |
| 5433 | case TargetLowering::Legal: |
| 5434 | case TargetLowering::Expand: |
| 5435 | break; // This case is handled below. |
Chris Lattner | 07dffd6 | 2005-08-26 00:14:16 +0000 | [diff] [blame] | 5436 | case TargetLowering::Custom: { |
| 5437 | SDOperand NV = TLI.LowerOperation(DAG.getNode(ISD::SINT_TO_FP, DestTy, |
| 5438 | Source), DAG); |
| 5439 | if (NV.Val) |
| 5440 | return LegalizeOp(NV); |
| 5441 | break; // The target decided this was legal after all |
| 5442 | } |
Chris Lattner | a88a260 | 2005-05-14 05:33:54 +0000 | [diff] [blame] | 5443 | } |
| 5444 | |
Chris Lattner | 13689e2 | 2005-05-12 07:00:44 +0000 | [diff] [blame] | 5445 | // Expand the source, then glue it back together for the call. We must expand |
| 5446 | // 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] | 5447 | if (ExpandSource) { |
| 5448 | SDOperand SrcLo, SrcHi; |
| 5449 | ExpandOp(Source, SrcLo, SrcHi); |
| 5450 | Source = DAG.getNode(ISD::BUILD_PAIR, SourceVT, SrcLo, SrcHi); |
| 5451 | } |
Chris Lattner | 13689e2 | 2005-05-12 07:00:44 +0000 | [diff] [blame] | 5452 | |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 5453 | RTLIB::Libcall LC; |
Evan Cheng | 110cf48 | 2008-04-01 01:50:16 +0000 | [diff] [blame] | 5454 | if (SourceVT == MVT::i32) { |
| 5455 | if (DestTy == MVT::f32) |
Evan Cheng | db45d1c | 2008-04-01 02:00:09 +0000 | [diff] [blame] | 5456 | LC = isSigned ? RTLIB::SINTTOFP_I32_F32 : RTLIB::UINTTOFP_I32_F32; |
Evan Cheng | 110cf48 | 2008-04-01 01:50:16 +0000 | [diff] [blame] | 5457 | else { |
| 5458 | assert(DestTy == MVT::f64 && "Unknown fp value type!"); |
| 5459 | LC = isSigned ? RTLIB::SINTTOFP_I32_F64 : RTLIB::UINTTOFP_I32_F64; |
| 5460 | } |
| 5461 | } else if (SourceVT == MVT::i64) { |
Dan Gohman | d91446d | 2008-03-05 01:08:17 +0000 | [diff] [blame] | 5462 | if (DestTy == MVT::f32) |
| 5463 | LC = RTLIB::SINTTOFP_I64_F32; |
Dan Gohman | 034f60e | 2008-03-11 01:59:03 +0000 | [diff] [blame] | 5464 | else if (DestTy == MVT::f64) |
Dan Gohman | d91446d | 2008-03-05 01:08:17 +0000 | [diff] [blame] | 5465 | LC = RTLIB::SINTTOFP_I64_F64; |
Dan Gohman | 034f60e | 2008-03-11 01:59:03 +0000 | [diff] [blame] | 5466 | else if (DestTy == MVT::f80) |
| 5467 | LC = RTLIB::SINTTOFP_I64_F80; |
| 5468 | else { |
| 5469 | assert(DestTy == MVT::ppcf128 && "Unknown fp value type!"); |
| 5470 | LC = RTLIB::SINTTOFP_I64_PPCF128; |
Dan Gohman | d91446d | 2008-03-05 01:08:17 +0000 | [diff] [blame] | 5471 | } |
| 5472 | } else if (SourceVT == MVT::i128) { |
| 5473 | if (DestTy == MVT::f32) |
| 5474 | LC = RTLIB::SINTTOFP_I128_F32; |
| 5475 | else if (DestTy == MVT::f64) |
| 5476 | LC = RTLIB::SINTTOFP_I128_F64; |
| 5477 | else if (DestTy == MVT::f80) |
| 5478 | LC = RTLIB::SINTTOFP_I128_F80; |
| 5479 | else { |
| 5480 | assert(DestTy == MVT::ppcf128 && "Unknown fp value type!"); |
| 5481 | LC = RTLIB::SINTTOFP_I128_PPCF128; |
| 5482 | } |
| 5483 | } else { |
| 5484 | assert(0 && "Unknown int value type"); |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 5485 | } |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 5486 | |
Evan Cheng | 4c6cfad | 2007-04-27 07:33:31 +0000 | [diff] [blame] | 5487 | assert(TLI.getLibcallName(LC) && "Don't know how to expand this SINT_TO_FP!"); |
Chris Lattner | 6831a81 | 2006-02-13 09:18:02 +0000 | [diff] [blame] | 5488 | Source = DAG.getNode(ISD::SINT_TO_FP, DestTy, Source); |
Dan Gohman | a2e9485 | 2008-03-10 23:03:31 +0000 | [diff] [blame] | 5489 | SDOperand HiPart; |
| 5490 | SDOperand Result = ExpandLibCall(TLI.getLibcallName(LC), Source.Val, isSigned, |
| 5491 | HiPart); |
Evan Cheng | 110cf48 | 2008-04-01 01:50:16 +0000 | [diff] [blame] | 5492 | if (Result.getValueType() != DestTy && HiPart.Val) |
Dan Gohman | a2e9485 | 2008-03-10 23:03:31 +0000 | [diff] [blame] | 5493 | Result = DAG.getNode(ISD::BUILD_PAIR, DestTy, Result, HiPart); |
| 5494 | return Result; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 5495 | } |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 5496 | |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5497 | /// ExpandLegalINT_TO_FP - This function is responsible for legalizing a |
| 5498 | /// INT_TO_FP operation of the specified operand when the target requests that |
| 5499 | /// we expand it. At this point, we know that the result and operand types are |
| 5500 | /// legal for the target. |
| 5501 | SDOperand SelectionDAGLegalize::ExpandLegalINT_TO_FP(bool isSigned, |
| 5502 | SDOperand Op0, |
| 5503 | MVT::ValueType DestVT) { |
| 5504 | if (Op0.getValueType() == MVT::i32) { |
| 5505 | // simple 32-bit [signed|unsigned] integer to float/double expansion |
| 5506 | |
Chris Lattner | 23594d4 | 2008-01-16 07:03:22 +0000 | [diff] [blame] | 5507 | // Get the stack frame index of a 8 byte buffer. |
| 5508 | SDOperand StackSlot = DAG.CreateStackTemporary(MVT::f64); |
| 5509 | |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5510 | // word offset constant for Hi/Lo address computation |
| 5511 | SDOperand WordOff = DAG.getConstant(sizeof(int), TLI.getPointerTy()); |
| 5512 | // set up Hi and Lo (into buffer) address based on endian |
Chris Lattner | 408c428 | 2006-03-23 05:29:04 +0000 | [diff] [blame] | 5513 | SDOperand Hi = StackSlot; |
| 5514 | SDOperand Lo = DAG.getNode(ISD::ADD, TLI.getPointerTy(), StackSlot,WordOff); |
| 5515 | if (TLI.isLittleEndian()) |
| 5516 | std::swap(Hi, Lo); |
| 5517 | |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5518 | // if signed map to unsigned space |
| 5519 | SDOperand Op0Mapped; |
| 5520 | if (isSigned) { |
| 5521 | // constant used to invert sign bit (signed to unsigned mapping) |
| 5522 | SDOperand SignBit = DAG.getConstant(0x80000000u, MVT::i32); |
| 5523 | Op0Mapped = DAG.getNode(ISD::XOR, MVT::i32, Op0, SignBit); |
| 5524 | } else { |
| 5525 | Op0Mapped = Op0; |
| 5526 | } |
| 5527 | // store the lo of the constructed double - based on integer input |
Evan Cheng | 786225a | 2006-10-05 23:01:46 +0000 | [diff] [blame] | 5528 | SDOperand Store1 = DAG.getStore(DAG.getEntryNode(), |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 5529 | Op0Mapped, Lo, NULL, 0); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5530 | // initial hi portion of constructed double |
| 5531 | SDOperand InitialHi = DAG.getConstant(0x43300000u, MVT::i32); |
| 5532 | // store the hi of the constructed double - biased exponent |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 5533 | SDOperand Store2=DAG.getStore(Store1, InitialHi, Hi, NULL, 0); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5534 | // load the constructed double |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 5535 | SDOperand Load = DAG.getLoad(MVT::f64, Store2, StackSlot, NULL, 0); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5536 | // FP constant to bias correct the final result |
| 5537 | SDOperand Bias = DAG.getConstantFP(isSigned ? |
| 5538 | BitsToDouble(0x4330000080000000ULL) |
| 5539 | : BitsToDouble(0x4330000000000000ULL), |
| 5540 | MVT::f64); |
| 5541 | // subtract the bias |
| 5542 | SDOperand Sub = DAG.getNode(ISD::FSUB, MVT::f64, Load, Bias); |
| 5543 | // final result |
| 5544 | SDOperand Result; |
| 5545 | // handle final rounding |
| 5546 | if (DestVT == MVT::f64) { |
| 5547 | // do nothing |
| 5548 | Result = Sub; |
Dale Johannesen | 118cd9d | 2007-09-16 16:51:49 +0000 | [diff] [blame] | 5549 | } else if (MVT::getSizeInBits(DestVT) < MVT::getSizeInBits(MVT::f64)) { |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 5550 | Result = DAG.getNode(ISD::FP_ROUND, DestVT, Sub, |
| 5551 | DAG.getIntPtrConstant(0)); |
Dale Johannesen | 118cd9d | 2007-09-16 16:51:49 +0000 | [diff] [blame] | 5552 | } else if (MVT::getSizeInBits(DestVT) > MVT::getSizeInBits(MVT::f64)) { |
| 5553 | Result = DAG.getNode(ISD::FP_EXTEND, DestVT, Sub); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5554 | } |
| 5555 | return Result; |
| 5556 | } |
| 5557 | assert(!isSigned && "Legalize cannot Expand SINT_TO_FP for i64 yet"); |
| 5558 | SDOperand Tmp1 = DAG.getNode(ISD::SINT_TO_FP, DestVT, Op0); |
| 5559 | |
Scott Michel | 5b8f82e | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 5560 | SDOperand SignSet = DAG.getSetCC(TLI.getSetCCResultType(Op0), Op0, |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5561 | DAG.getConstant(0, Op0.getValueType()), |
| 5562 | ISD::SETLT); |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 5563 | SDOperand Zero = DAG.getIntPtrConstant(0), Four = DAG.getIntPtrConstant(4); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5564 | SDOperand CstOffset = DAG.getNode(ISD::SELECT, Zero.getValueType(), |
| 5565 | SignSet, Four, Zero); |
| 5566 | |
| 5567 | // If the sign bit of the integer is set, the large number will be treated |
| 5568 | // as a negative number. To counteract this, the dynamic code adds an |
| 5569 | // offset depending on the data type. |
| 5570 | uint64_t FF; |
| 5571 | switch (Op0.getValueType()) { |
| 5572 | default: assert(0 && "Unsupported integer type!"); |
| 5573 | case MVT::i8 : FF = 0x43800000ULL; break; // 2^8 (as a float) |
| 5574 | case MVT::i16: FF = 0x47800000ULL; break; // 2^16 (as a float) |
| 5575 | case MVT::i32: FF = 0x4F800000ULL; break; // 2^32 (as a float) |
| 5576 | case MVT::i64: FF = 0x5F800000ULL; break; // 2^64 (as a float) |
| 5577 | } |
| 5578 | if (TLI.isLittleEndian()) FF <<= 32; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 5579 | static Constant *FudgeFactor = ConstantInt::get(Type::Int64Ty, FF); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5580 | |
| 5581 | SDOperand CPIdx = DAG.getConstantPool(FudgeFactor, TLI.getPointerTy()); |
| 5582 | CPIdx = DAG.getNode(ISD::ADD, TLI.getPointerTy(), CPIdx, CstOffset); |
| 5583 | SDOperand FudgeInReg; |
| 5584 | if (DestVT == MVT::f32) |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5585 | FudgeInReg = DAG.getLoad(MVT::f32, DAG.getEntryNode(), CPIdx, |
Dan Gohman | 3069b87 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 5586 | PseudoSourceValue::getConstantPool(), 0); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5587 | else { |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5588 | FudgeInReg = |
| 5589 | LegalizeOp(DAG.getExtLoad(ISD::EXTLOAD, DestVT, |
| 5590 | DAG.getEntryNode(), CPIdx, |
Dan Gohman | 3069b87 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 5591 | PseudoSourceValue::getConstantPool(), 0, |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 5592 | MVT::f32)); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5593 | } |
| 5594 | |
| 5595 | return DAG.getNode(ISD::FADD, DestVT, Tmp1, FudgeInReg); |
| 5596 | } |
| 5597 | |
| 5598 | /// PromoteLegalINT_TO_FP - This function is responsible for legalizing a |
| 5599 | /// *INT_TO_FP operation of the specified operand when the target requests that |
| 5600 | /// we promote it. At this point, we know that the result and operand types are |
| 5601 | /// legal for the target, and that there is a legal UINT_TO_FP or SINT_TO_FP |
| 5602 | /// operation that takes a larger input. |
| 5603 | SDOperand SelectionDAGLegalize::PromoteLegalINT_TO_FP(SDOperand LegalOp, |
| 5604 | MVT::ValueType DestVT, |
| 5605 | bool isSigned) { |
| 5606 | // First step, figure out the appropriate *INT_TO_FP operation to use. |
| 5607 | MVT::ValueType NewInTy = LegalOp.getValueType(); |
| 5608 | |
| 5609 | unsigned OpToUse = 0; |
| 5610 | |
| 5611 | // Scan for the appropriate larger type to use. |
| 5612 | while (1) { |
| 5613 | NewInTy = (MVT::ValueType)(NewInTy+1); |
| 5614 | assert(MVT::isInteger(NewInTy) && "Ran out of possibilities!"); |
| 5615 | |
| 5616 | // If the target supports SINT_TO_FP of this type, use it. |
| 5617 | switch (TLI.getOperationAction(ISD::SINT_TO_FP, NewInTy)) { |
| 5618 | default: break; |
| 5619 | case TargetLowering::Legal: |
| 5620 | if (!TLI.isTypeLegal(NewInTy)) |
| 5621 | break; // Can't use this datatype. |
| 5622 | // FALL THROUGH. |
| 5623 | case TargetLowering::Custom: |
| 5624 | OpToUse = ISD::SINT_TO_FP; |
| 5625 | break; |
| 5626 | } |
| 5627 | if (OpToUse) break; |
| 5628 | if (isSigned) continue; |
| 5629 | |
| 5630 | // If the target supports UINT_TO_FP of this type, use it. |
| 5631 | switch (TLI.getOperationAction(ISD::UINT_TO_FP, NewInTy)) { |
| 5632 | default: break; |
| 5633 | case TargetLowering::Legal: |
| 5634 | if (!TLI.isTypeLegal(NewInTy)) |
| 5635 | break; // Can't use this datatype. |
| 5636 | // FALL THROUGH. |
| 5637 | case TargetLowering::Custom: |
| 5638 | OpToUse = ISD::UINT_TO_FP; |
| 5639 | break; |
| 5640 | } |
| 5641 | if (OpToUse) break; |
| 5642 | |
| 5643 | // Otherwise, try a larger type. |
| 5644 | } |
| 5645 | |
| 5646 | // Okay, we found the operation and type to use. Zero extend our input to the |
| 5647 | // desired type then run the operation on it. |
| 5648 | return DAG.getNode(OpToUse, DestVT, |
| 5649 | DAG.getNode(isSigned ? ISD::SIGN_EXTEND : ISD::ZERO_EXTEND, |
| 5650 | NewInTy, LegalOp)); |
| 5651 | } |
| 5652 | |
| 5653 | /// PromoteLegalFP_TO_INT - This function is responsible for legalizing a |
| 5654 | /// FP_TO_*INT operation of the specified operand when the target requests that |
| 5655 | /// we promote it. At this point, we know that the result and operand types are |
| 5656 | /// legal for the target, and that there is a legal FP_TO_UINT or FP_TO_SINT |
| 5657 | /// operation that returns a larger result. |
| 5658 | SDOperand SelectionDAGLegalize::PromoteLegalFP_TO_INT(SDOperand LegalOp, |
| 5659 | MVT::ValueType DestVT, |
| 5660 | bool isSigned) { |
| 5661 | // First step, figure out the appropriate FP_TO*INT operation to use. |
| 5662 | MVT::ValueType NewOutTy = DestVT; |
| 5663 | |
| 5664 | unsigned OpToUse = 0; |
| 5665 | |
| 5666 | // Scan for the appropriate larger type to use. |
| 5667 | while (1) { |
| 5668 | NewOutTy = (MVT::ValueType)(NewOutTy+1); |
| 5669 | assert(MVT::isInteger(NewOutTy) && "Ran out of possibilities!"); |
| 5670 | |
| 5671 | // If the target supports FP_TO_SINT returning this type, use it. |
| 5672 | switch (TLI.getOperationAction(ISD::FP_TO_SINT, NewOutTy)) { |
| 5673 | default: break; |
| 5674 | case TargetLowering::Legal: |
| 5675 | if (!TLI.isTypeLegal(NewOutTy)) |
| 5676 | break; // Can't use this datatype. |
| 5677 | // FALL THROUGH. |
| 5678 | case TargetLowering::Custom: |
| 5679 | OpToUse = ISD::FP_TO_SINT; |
| 5680 | break; |
| 5681 | } |
| 5682 | if (OpToUse) break; |
| 5683 | |
| 5684 | // If the target supports FP_TO_UINT of this type, use it. |
| 5685 | switch (TLI.getOperationAction(ISD::FP_TO_UINT, NewOutTy)) { |
| 5686 | default: break; |
| 5687 | case TargetLowering::Legal: |
| 5688 | if (!TLI.isTypeLegal(NewOutTy)) |
| 5689 | break; // Can't use this datatype. |
| 5690 | // FALL THROUGH. |
| 5691 | case TargetLowering::Custom: |
| 5692 | OpToUse = ISD::FP_TO_UINT; |
| 5693 | break; |
| 5694 | } |
| 5695 | if (OpToUse) break; |
| 5696 | |
| 5697 | // Otherwise, try a larger type. |
| 5698 | } |
| 5699 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 5700 | |
| 5701 | // Okay, we found the operation and type to use. |
| 5702 | SDOperand Operation = DAG.getNode(OpToUse, NewOutTy, LegalOp); |
| 5703 | |
| 5704 | // If the operation produces an invalid type, it must be custom lowered. Use |
| 5705 | // the target lowering hooks to expand it. Just keep the low part of the |
| 5706 | // expanded operation, we know that we're truncating anyway. |
| 5707 | if (getTypeAction(NewOutTy) == Expand) { |
| 5708 | Operation = SDOperand(TLI.ExpandOperationResult(Operation.Val, DAG), 0); |
| 5709 | assert(Operation.Val && "Didn't return anything"); |
| 5710 | } |
| 5711 | |
| 5712 | // Truncate the result of the extended FP_TO_*INT operation to the desired |
| 5713 | // size. |
| 5714 | return DAG.getNode(ISD::TRUNCATE, DestVT, Operation); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5715 | } |
| 5716 | |
| 5717 | /// ExpandBSWAP - Open code the operations for BSWAP of the specified operation. |
| 5718 | /// |
| 5719 | SDOperand SelectionDAGLegalize::ExpandBSWAP(SDOperand Op) { |
| 5720 | MVT::ValueType VT = Op.getValueType(); |
| 5721 | MVT::ValueType SHVT = TLI.getShiftAmountTy(); |
| 5722 | SDOperand Tmp1, Tmp2, Tmp3, Tmp4, Tmp5, Tmp6, Tmp7, Tmp8; |
| 5723 | switch (VT) { |
| 5724 | default: assert(0 && "Unhandled Expand type in BSWAP!"); abort(); |
| 5725 | case MVT::i16: |
| 5726 | Tmp2 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(8, SHVT)); |
| 5727 | Tmp1 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(8, SHVT)); |
| 5728 | return DAG.getNode(ISD::OR, VT, Tmp1, Tmp2); |
| 5729 | case MVT::i32: |
| 5730 | Tmp4 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(24, SHVT)); |
| 5731 | Tmp3 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(8, SHVT)); |
| 5732 | Tmp2 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(8, SHVT)); |
| 5733 | Tmp1 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(24, SHVT)); |
| 5734 | Tmp3 = DAG.getNode(ISD::AND, VT, Tmp3, DAG.getConstant(0xFF0000, VT)); |
| 5735 | Tmp2 = DAG.getNode(ISD::AND, VT, Tmp2, DAG.getConstant(0xFF00, VT)); |
| 5736 | Tmp4 = DAG.getNode(ISD::OR, VT, Tmp4, Tmp3); |
| 5737 | Tmp2 = DAG.getNode(ISD::OR, VT, Tmp2, Tmp1); |
| 5738 | return DAG.getNode(ISD::OR, VT, Tmp4, Tmp2); |
| 5739 | case MVT::i64: |
| 5740 | Tmp8 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(56, SHVT)); |
| 5741 | Tmp7 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(40, SHVT)); |
| 5742 | Tmp6 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(24, SHVT)); |
| 5743 | Tmp5 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(8, SHVT)); |
| 5744 | Tmp4 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(8, SHVT)); |
| 5745 | Tmp3 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(24, SHVT)); |
| 5746 | Tmp2 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(40, SHVT)); |
| 5747 | Tmp1 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(56, SHVT)); |
| 5748 | Tmp7 = DAG.getNode(ISD::AND, VT, Tmp7, DAG.getConstant(255ULL<<48, VT)); |
| 5749 | Tmp6 = DAG.getNode(ISD::AND, VT, Tmp6, DAG.getConstant(255ULL<<40, VT)); |
| 5750 | Tmp5 = DAG.getNode(ISD::AND, VT, Tmp5, DAG.getConstant(255ULL<<32, VT)); |
| 5751 | Tmp4 = DAG.getNode(ISD::AND, VT, Tmp4, DAG.getConstant(255ULL<<24, VT)); |
| 5752 | Tmp3 = DAG.getNode(ISD::AND, VT, Tmp3, DAG.getConstant(255ULL<<16, VT)); |
| 5753 | Tmp2 = DAG.getNode(ISD::AND, VT, Tmp2, DAG.getConstant(255ULL<<8 , VT)); |
| 5754 | Tmp8 = DAG.getNode(ISD::OR, VT, Tmp8, Tmp7); |
| 5755 | Tmp6 = DAG.getNode(ISD::OR, VT, Tmp6, Tmp5); |
| 5756 | Tmp4 = DAG.getNode(ISD::OR, VT, Tmp4, Tmp3); |
| 5757 | Tmp2 = DAG.getNode(ISD::OR, VT, Tmp2, Tmp1); |
| 5758 | Tmp8 = DAG.getNode(ISD::OR, VT, Tmp8, Tmp6); |
| 5759 | Tmp4 = DAG.getNode(ISD::OR, VT, Tmp4, Tmp2); |
| 5760 | return DAG.getNode(ISD::OR, VT, Tmp8, Tmp4); |
| 5761 | } |
| 5762 | } |
| 5763 | |
| 5764 | /// ExpandBitCount - Expand the specified bitcount instruction into operations. |
| 5765 | /// |
| 5766 | SDOperand SelectionDAGLegalize::ExpandBitCount(unsigned Opc, SDOperand Op) { |
| 5767 | switch (Opc) { |
| 5768 | default: assert(0 && "Cannot expand this yet!"); |
| 5769 | case ISD::CTPOP: { |
| 5770 | static const uint64_t mask[6] = { |
| 5771 | 0x5555555555555555ULL, 0x3333333333333333ULL, |
| 5772 | 0x0F0F0F0F0F0F0F0FULL, 0x00FF00FF00FF00FFULL, |
| 5773 | 0x0000FFFF0000FFFFULL, 0x00000000FFFFFFFFULL |
| 5774 | }; |
| 5775 | MVT::ValueType VT = Op.getValueType(); |
| 5776 | MVT::ValueType ShVT = TLI.getShiftAmountTy(); |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 5777 | unsigned len = MVT::getSizeInBits(VT); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5778 | for (unsigned i = 0; (1U << i) <= (len / 2); ++i) { |
| 5779 | //x = (x & mask[i][len/8]) + (x >> (1 << i) & mask[i][len/8]) |
| 5780 | SDOperand Tmp2 = DAG.getConstant(mask[i], VT); |
| 5781 | SDOperand Tmp3 = DAG.getConstant(1ULL << i, ShVT); |
| 5782 | Op = DAG.getNode(ISD::ADD, VT, DAG.getNode(ISD::AND, VT, Op, Tmp2), |
| 5783 | DAG.getNode(ISD::AND, VT, |
| 5784 | DAG.getNode(ISD::SRL, VT, Op, Tmp3),Tmp2)); |
| 5785 | } |
| 5786 | return Op; |
| 5787 | } |
| 5788 | case ISD::CTLZ: { |
| 5789 | // for now, we do this: |
| 5790 | // x = x | (x >> 1); |
| 5791 | // x = x | (x >> 2); |
| 5792 | // ... |
| 5793 | // x = x | (x >>16); |
| 5794 | // x = x | (x >>32); // for 64-bit input |
| 5795 | // return popcount(~x); |
| 5796 | // |
| 5797 | // but see also: http://www.hackersdelight.org/HDcode/nlz.cc |
| 5798 | MVT::ValueType VT = Op.getValueType(); |
| 5799 | MVT::ValueType ShVT = TLI.getShiftAmountTy(); |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 5800 | unsigned len = MVT::getSizeInBits(VT); |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5801 | for (unsigned i = 0; (1U << i) <= (len / 2); ++i) { |
| 5802 | SDOperand Tmp3 = DAG.getConstant(1ULL << i, ShVT); |
| 5803 | Op = DAG.getNode(ISD::OR, VT, Op, DAG.getNode(ISD::SRL, VT, Op, Tmp3)); |
| 5804 | } |
| 5805 | Op = DAG.getNode(ISD::XOR, VT, Op, DAG.getConstant(~0ULL, VT)); |
| 5806 | return DAG.getNode(ISD::CTPOP, VT, Op); |
| 5807 | } |
| 5808 | case ISD::CTTZ: { |
| 5809 | // for now, we use: { return popcount(~x & (x - 1)); } |
| 5810 | // unless the target has ctlz but not ctpop, in which case we use: |
| 5811 | // { return 32 - nlz(~x & (x-1)); } |
| 5812 | // see also http://www.hackersdelight.org/HDcode/ntz.cc |
| 5813 | MVT::ValueType VT = Op.getValueType(); |
| 5814 | SDOperand Tmp2 = DAG.getConstant(~0ULL, VT); |
| 5815 | SDOperand Tmp3 = DAG.getNode(ISD::AND, VT, |
| 5816 | DAG.getNode(ISD::XOR, VT, Op, Tmp2), |
| 5817 | DAG.getNode(ISD::SUB, VT, Op, DAG.getConstant(1, VT))); |
| 5818 | // If ISD::CTLZ is legal and CTPOP isn't, then do that instead. |
| 5819 | if (!TLI.isOperationLegal(ISD::CTPOP, VT) && |
| 5820 | TLI.isOperationLegal(ISD::CTLZ, VT)) |
| 5821 | return DAG.getNode(ISD::SUB, VT, |
Dan Gohman | b55757e | 2007-05-18 17:52:13 +0000 | [diff] [blame] | 5822 | DAG.getConstant(MVT::getSizeInBits(VT), VT), |
Chris Lattner | 22cde6a | 2006-01-28 08:25:58 +0000 | [diff] [blame] | 5823 | DAG.getNode(ISD::CTLZ, VT, Tmp3)); |
| 5824 | return DAG.getNode(ISD::CTPOP, VT, Tmp3); |
| 5825 | } |
| 5826 | } |
| 5827 | } |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 5828 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5829 | /// ExpandOp - Expand the specified SDOperand into its two component pieces |
| 5830 | /// Lo&Hi. Note that the Op MUST be an expanded type. As a result of this, the |
| 5831 | /// LegalizeNodes map is filled in for any results that are not expanded, the |
| 5832 | /// ExpandedNodes map is filled in for any results that are expanded, and the |
| 5833 | /// Lo/Hi values are returned. |
| 5834 | void SelectionDAGLegalize::ExpandOp(SDOperand Op, SDOperand &Lo, SDOperand &Hi){ |
| 5835 | MVT::ValueType VT = Op.getValueType(); |
Chris Lattner | 71c42a0 | 2005-01-16 01:11:45 +0000 | [diff] [blame] | 5836 | MVT::ValueType NVT = TLI.getTypeToTransformTo(VT); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5837 | SDNode *Node = Op.Val; |
| 5838 | assert(getTypeAction(VT) == Expand && "Not an expanded type!"); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 5839 | assert(((MVT::isInteger(NVT) && NVT < VT) || MVT::isFloatingPoint(VT) || |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 5840 | MVT::isVector(VT)) && |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5841 | "Cannot expand to FP value or to larger int value!"); |
| 5842 | |
Chris Lattner | 6fdcb25 | 2005-09-02 20:32:45 +0000 | [diff] [blame] | 5843 | // See if we already expanded it. |
Roman Levenstein | dc1adac | 2008-04-07 10:06:32 +0000 | [diff] [blame] | 5844 | DenseMap<SDOperandImpl, std::pair<SDOperand, SDOperand> >::iterator I |
Chris Lattner | 6fdcb25 | 2005-09-02 20:32:45 +0000 | [diff] [blame] | 5845 | = ExpandedNodes.find(Op); |
| 5846 | if (I != ExpandedNodes.end()) { |
| 5847 | Lo = I->second.first; |
| 5848 | Hi = I->second.second; |
| 5849 | return; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5850 | } |
| 5851 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5852 | switch (Node->getOpcode()) { |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 5853 | case ISD::CopyFromReg: |
| 5854 | assert(0 && "CopyFromReg must be legal!"); |
Dale Johannesen | 6eaeff2 | 2007-10-10 01:01:31 +0000 | [diff] [blame] | 5855 | case ISD::FP_ROUND_INREG: |
| 5856 | if (VT == MVT::ppcf128 && |
| 5857 | TLI.getOperationAction(ISD::FP_ROUND_INREG, VT) == |
| 5858 | TargetLowering::Custom) { |
Dale Johannesen | fcf4d24 | 2007-10-11 23:32:15 +0000 | [diff] [blame] | 5859 | SDOperand SrcLo, SrcHi, Src; |
| 5860 | ExpandOp(Op.getOperand(0), SrcLo, SrcHi); |
| 5861 | Src = DAG.getNode(ISD::BUILD_PAIR, VT, SrcLo, SrcHi); |
| 5862 | SDOperand Result = TLI.LowerOperation( |
| 5863 | DAG.getNode(ISD::FP_ROUND_INREG, VT, Src, Op.getOperand(1)), DAG); |
Dale Johannesen | 6eaeff2 | 2007-10-10 01:01:31 +0000 | [diff] [blame] | 5864 | assert(Result.Val->getOpcode() == ISD::BUILD_PAIR); |
| 5865 | Lo = Result.Val->getOperand(0); |
| 5866 | Hi = Result.Val->getOperand(1); |
| 5867 | break; |
| 5868 | } |
| 5869 | // fall through |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 5870 | default: |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 5871 | #ifndef NDEBUG |
Dan Gohman | 3983358 | 2007-06-04 16:17:33 +0000 | [diff] [blame] | 5872 | cerr << "NODE: "; Node->dump(&DAG); cerr << "\n"; |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 5873 | #endif |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5874 | assert(0 && "Do not know how to expand this operator!"); |
| 5875 | abort(); |
Dan Gohman | 1953ecb | 2008-02-27 01:52:30 +0000 | [diff] [blame] | 5876 | case ISD::EXTRACT_ELEMENT: |
| 5877 | ExpandOp(Node->getOperand(0), Lo, Hi); |
| 5878 | if (cast<ConstantSDNode>(Node->getOperand(1))->getValue()) |
| 5879 | return ExpandOp(Hi, Lo, Hi); |
Dan Gohman | 18714ae | 2008-02-27 19:44:57 +0000 | [diff] [blame] | 5880 | return ExpandOp(Lo, Lo, Hi); |
Dale Johannesen | 25f1d08 | 2007-10-31 00:32:36 +0000 | [diff] [blame] | 5881 | case ISD::EXTRACT_VECTOR_ELT: |
| 5882 | assert(VT==MVT::i64 && "Do not know how to expand this operator!"); |
| 5883 | // ExpandEXTRACT_VECTOR_ELT tolerates invalid result types. |
| 5884 | Lo = ExpandEXTRACT_VECTOR_ELT(Op); |
| 5885 | return ExpandOp(Lo, Lo, Hi); |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 5886 | case ISD::UNDEF: |
Evan Cheng | aa975c1 | 2006-12-16 02:20:50 +0000 | [diff] [blame] | 5887 | NVT = TLI.getTypeToExpandTo(VT); |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 5888 | Lo = DAG.getNode(ISD::UNDEF, NVT); |
| 5889 | Hi = DAG.getNode(ISD::UNDEF, NVT); |
| 5890 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5891 | case ISD::Constant: { |
Dan Gohman | 050f550 | 2008-03-03 22:20:46 +0000 | [diff] [blame] | 5892 | unsigned NVTBits = MVT::getSizeInBits(NVT); |
| 5893 | const APInt &Cst = cast<ConstantSDNode>(Node)->getAPIntValue(); |
| 5894 | Lo = DAG.getConstant(APInt(Cst).trunc(NVTBits), NVT); |
| 5895 | Hi = DAG.getConstant(Cst.lshr(NVTBits).trunc(NVTBits), NVT); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 5896 | break; |
| 5897 | } |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 5898 | case ISD::ConstantFP: { |
| 5899 | ConstantFPSDNode *CFP = cast<ConstantFPSDNode>(Node); |
Dale Johannesen | a471c2e | 2007-10-11 18:07:22 +0000 | [diff] [blame] | 5900 | if (CFP->getValueType(0) == MVT::ppcf128) { |
| 5901 | APInt api = CFP->getValueAPF().convertToAPInt(); |
| 5902 | Lo = DAG.getConstantFP(APFloat(APInt(64, 1, &api.getRawData()[1])), |
| 5903 | MVT::f64); |
| 5904 | Hi = DAG.getConstantFP(APFloat(APInt(64, 1, &api.getRawData()[0])), |
| 5905 | MVT::f64); |
| 5906 | break; |
| 5907 | } |
Evan Cheng | 279101e | 2006-12-12 22:19:28 +0000 | [diff] [blame] | 5908 | Lo = ExpandConstantFP(CFP, false, DAG, TLI); |
Evan Cheng | 9f87788 | 2006-12-13 20:57:08 +0000 | [diff] [blame] | 5909 | if (getTypeAction(Lo.getValueType()) == Expand) |
| 5910 | ExpandOp(Lo, Lo, Hi); |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 5911 | break; |
| 5912 | } |
Chris Lattner | d4e50bb | 2005-03-28 22:03:13 +0000 | [diff] [blame] | 5913 | case ISD::BUILD_PAIR: |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5914 | // Return the operands. |
| 5915 | Lo = Node->getOperand(0); |
| 5916 | Hi = Node->getOperand(1); |
Chris Lattner | d4e50bb | 2005-03-28 22:03:13 +0000 | [diff] [blame] | 5917 | break; |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 5918 | |
| 5919 | case ISD::MERGE_VALUES: |
Chris Lattner | c58d558 | 2007-11-24 19:12:15 +0000 | [diff] [blame] | 5920 | if (Node->getNumValues() == 1) { |
| 5921 | ExpandOp(Op.getOperand(0), Lo, Hi); |
| 5922 | break; |
| 5923 | } |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 5924 | // FIXME: For now only expand i64,chain = MERGE_VALUES (x, y) |
| 5925 | assert(Op.ResNo == 0 && Node->getNumValues() == 2 && |
| 5926 | Op.getValue(1).getValueType() == MVT::Other && |
| 5927 | "unhandled MERGE_VALUES"); |
| 5928 | ExpandOp(Op.getOperand(0), Lo, Hi); |
| 5929 | // Remember that we legalized the chain. |
| 5930 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Op.getOperand(1))); |
| 5931 | break; |
Chris Lattner | 58f7963 | 2005-12-12 22:27:43 +0000 | [diff] [blame] | 5932 | |
| 5933 | case ISD::SIGN_EXTEND_INREG: |
| 5934 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Chris Lattner | 4bdd275 | 2006-10-06 17:34:12 +0000 | [diff] [blame] | 5935 | // sext_inreg the low part if needed. |
| 5936 | Lo = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Lo, Node->getOperand(1)); |
| 5937 | |
| 5938 | // The high part gets the sign extension from the lo-part. This handles |
| 5939 | // things like sextinreg V:i64 from i8. |
Chris Lattner | 58f7963 | 2005-12-12 22:27:43 +0000 | [diff] [blame] | 5940 | Hi = DAG.getNode(ISD::SRA, NVT, Lo, |
| 5941 | DAG.getConstant(MVT::getSizeInBits(NVT)-1, |
| 5942 | TLI.getShiftAmountTy())); |
Chris Lattner | 58f7963 | 2005-12-12 22:27:43 +0000 | [diff] [blame] | 5943 | break; |
Chris Lattner | d4e50bb | 2005-03-28 22:03:13 +0000 | [diff] [blame] | 5944 | |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 5945 | case ISD::BSWAP: { |
| 5946 | ExpandOp(Node->getOperand(0), Lo, Hi); |
| 5947 | SDOperand TempLo = DAG.getNode(ISD::BSWAP, NVT, Hi); |
| 5948 | Hi = DAG.getNode(ISD::BSWAP, NVT, Lo); |
| 5949 | Lo = TempLo; |
| 5950 | break; |
| 5951 | } |
| 5952 | |
Chris Lattner | edb1add | 2005-05-11 04:51:16 +0000 | [diff] [blame] | 5953 | case ISD::CTPOP: |
| 5954 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Chris Lattner | 9b583b4 | 2005-05-11 05:09:47 +0000 | [diff] [blame] | 5955 | Lo = DAG.getNode(ISD::ADD, NVT, // ctpop(HL) -> ctpop(H)+ctpop(L) |
| 5956 | DAG.getNode(ISD::CTPOP, NVT, Lo), |
| 5957 | DAG.getNode(ISD::CTPOP, NVT, Hi)); |
Chris Lattner | edb1add | 2005-05-11 04:51:16 +0000 | [diff] [blame] | 5958 | Hi = DAG.getConstant(0, NVT); |
| 5959 | break; |
| 5960 | |
Chris Lattner | 39a8f33 | 2005-05-12 19:05:01 +0000 | [diff] [blame] | 5961 | case ISD::CTLZ: { |
| 5962 | // ctlz (HL) -> ctlz(H) != 32 ? ctlz(H) : (ctlz(L)+32) |
Chris Lattner | 3becf20 | 2005-05-12 19:27:51 +0000 | [diff] [blame] | 5963 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Chris Lattner | 39a8f33 | 2005-05-12 19:05:01 +0000 | [diff] [blame] | 5964 | SDOperand BitsC = DAG.getConstant(MVT::getSizeInBits(NVT), NVT); |
| 5965 | SDOperand HLZ = DAG.getNode(ISD::CTLZ, NVT, Hi); |
Scott Michel | 5b8f82e | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 5966 | SDOperand TopNotZero = DAG.getSetCC(TLI.getSetCCResultType(HLZ), HLZ, BitsC, |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 5967 | ISD::SETNE); |
Chris Lattner | 39a8f33 | 2005-05-12 19:05:01 +0000 | [diff] [blame] | 5968 | SDOperand LowPart = DAG.getNode(ISD::CTLZ, NVT, Lo); |
| 5969 | LowPart = DAG.getNode(ISD::ADD, NVT, LowPart, BitsC); |
| 5970 | |
| 5971 | Lo = DAG.getNode(ISD::SELECT, NVT, TopNotZero, HLZ, LowPart); |
| 5972 | Hi = DAG.getConstant(0, NVT); |
| 5973 | break; |
| 5974 | } |
| 5975 | |
| 5976 | case ISD::CTTZ: { |
| 5977 | // cttz (HL) -> cttz(L) != 32 ? cttz(L) : (cttz(H)+32) |
Chris Lattner | 3becf20 | 2005-05-12 19:27:51 +0000 | [diff] [blame] | 5978 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Chris Lattner | 39a8f33 | 2005-05-12 19:05:01 +0000 | [diff] [blame] | 5979 | SDOperand BitsC = DAG.getConstant(MVT::getSizeInBits(NVT), NVT); |
| 5980 | SDOperand LTZ = DAG.getNode(ISD::CTTZ, NVT, Lo); |
Scott Michel | 5b8f82e | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 5981 | SDOperand BotNotZero = DAG.getSetCC(TLI.getSetCCResultType(LTZ), LTZ, BitsC, |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 5982 | ISD::SETNE); |
Chris Lattner | 39a8f33 | 2005-05-12 19:05:01 +0000 | [diff] [blame] | 5983 | SDOperand HiPart = DAG.getNode(ISD::CTTZ, NVT, Hi); |
| 5984 | HiPart = DAG.getNode(ISD::ADD, NVT, HiPart, BitsC); |
| 5985 | |
| 5986 | Lo = DAG.getNode(ISD::SELECT, NVT, BotNotZero, LTZ, HiPart); |
| 5987 | Hi = DAG.getConstant(0, NVT); |
| 5988 | break; |
| 5989 | } |
Chris Lattner | edb1add | 2005-05-11 04:51:16 +0000 | [diff] [blame] | 5990 | |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 5991 | case ISD::VAARG: { |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5992 | SDOperand Ch = Node->getOperand(0); // Legalize the chain. |
| 5993 | SDOperand Ptr = Node->getOperand(1); // Legalize the pointer. |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 5994 | Lo = DAG.getVAArg(NVT, Ch, Ptr, Node->getOperand(2)); |
| 5995 | Hi = DAG.getVAArg(NVT, Lo.getValue(1), Ptr, Node->getOperand(2)); |
| 5996 | |
| 5997 | // Remember that we legalized the chain. |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 5998 | Hi = LegalizeOp(Hi); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 5999 | AddLegalizedOperand(Op.getValue(1), Hi.getValue(1)); |
Duncan Sands | 0753fc1 | 2008-02-11 10:37:04 +0000 | [diff] [blame] | 6000 | if (TLI.isBigEndian()) |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 6001 | std::swap(Lo, Hi); |
| 6002 | break; |
| 6003 | } |
| 6004 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6005 | case ISD::LOAD: { |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6006 | LoadSDNode *LD = cast<LoadSDNode>(Node); |
| 6007 | SDOperand Ch = LD->getChain(); // Legalize the chain. |
| 6008 | SDOperand Ptr = LD->getBasePtr(); // Legalize the pointer. |
| 6009 | ISD::LoadExtType ExtType = LD->getExtensionType(); |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 6010 | int SVOffset = LD->getSrcValueOffset(); |
| 6011 | unsigned Alignment = LD->getAlignment(); |
| 6012 | bool isVolatile = LD->isVolatile(); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6013 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6014 | if (ExtType == ISD::NON_EXTLOAD) { |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 6015 | Lo = DAG.getLoad(NVT, Ch, Ptr, LD->getSrcValue(), SVOffset, |
| 6016 | isVolatile, Alignment); |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 6017 | if (VT == MVT::f32 || VT == MVT::f64) { |
| 6018 | // f32->i32 or f64->i64 one to one expansion. |
| 6019 | // Remember that we legalized the chain. |
| 6020 | AddLegalizedOperand(SDOperand(Node, 1), LegalizeOp(Lo.getValue(1))); |
Evan Cheng | 9f87788 | 2006-12-13 20:57:08 +0000 | [diff] [blame] | 6021 | // Recursively expand the new load. |
| 6022 | if (getTypeAction(NVT) == Expand) |
| 6023 | ExpandOp(Lo, Lo, Hi); |
Evan Cheng | 0049521 | 2006-12-12 21:32:44 +0000 | [diff] [blame] | 6024 | break; |
| 6025 | } |
Chris Lattner | ec39a45 | 2005-01-19 18:02:17 +0000 | [diff] [blame] | 6026 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6027 | // Increment the pointer to the other half. |
| 6028 | unsigned IncrementSize = MVT::getSizeInBits(Lo.getValueType())/8; |
| 6029 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 6030 | DAG.getIntPtrConstant(IncrementSize)); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6031 | SVOffset += IncrementSize; |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 6032 | Alignment = MinAlign(Alignment, IncrementSize); |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 6033 | Hi = DAG.getLoad(NVT, Ch, Ptr, LD->getSrcValue(), SVOffset, |
| 6034 | isVolatile, Alignment); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 6035 | |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6036 | // Build a factor node to remember that this load is independent of the |
| 6037 | // other one. |
| 6038 | SDOperand TF = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1), |
| 6039 | Hi.getValue(1)); |
| 6040 | |
| 6041 | // Remember that we legalized the chain. |
| 6042 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(TF)); |
Duncan Sands | 0753fc1 | 2008-02-11 10:37:04 +0000 | [diff] [blame] | 6043 | if (TLI.isBigEndian()) |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6044 | std::swap(Lo, Hi); |
| 6045 | } else { |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 6046 | MVT::ValueType EVT = LD->getMemoryVT(); |
Evan Cheng | 548f611 | 2006-12-13 03:19:57 +0000 | [diff] [blame] | 6047 | |
Dale Johannesen | b6210fc | 2007-10-19 20:29:00 +0000 | [diff] [blame] | 6048 | if ((VT == MVT::f64 && EVT == MVT::f32) || |
| 6049 | (VT == MVT::ppcf128 && (EVT==MVT::f64 || EVT==MVT::f32))) { |
Evan Cheng | 548f611 | 2006-12-13 03:19:57 +0000 | [diff] [blame] | 6050 | // f64 = EXTLOAD f32 should expand to LOAD, FP_EXTEND |
| 6051 | SDOperand Load = DAG.getLoad(EVT, Ch, Ptr, LD->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 6052 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 548f611 | 2006-12-13 03:19:57 +0000 | [diff] [blame] | 6053 | // Remember that we legalized the chain. |
| 6054 | AddLegalizedOperand(SDOperand(Node, 1), LegalizeOp(Load.getValue(1))); |
| 6055 | ExpandOp(DAG.getNode(ISD::FP_EXTEND, VT, Load), Lo, Hi); |
| 6056 | break; |
| 6057 | } |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6058 | |
| 6059 | if (EVT == NVT) |
| 6060 | Lo = DAG.getLoad(NVT, Ch, Ptr, LD->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 6061 | SVOffset, isVolatile, Alignment); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6062 | else |
| 6063 | Lo = DAG.getExtLoad(ExtType, NVT, Ch, Ptr, LD->getSrcValue(), |
Dan Gohman | d6fd1bc | 2007-07-09 22:18:38 +0000 | [diff] [blame] | 6064 | SVOffset, EVT, isVolatile, |
| 6065 | Alignment); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 6066 | |
| 6067 | // Remember that we legalized the chain. |
| 6068 | AddLegalizedOperand(SDOperand(Node, 1), LegalizeOp(Lo.getValue(1))); |
| 6069 | |
| 6070 | if (ExtType == ISD::SEXTLOAD) { |
| 6071 | // The high part is obtained by SRA'ing all but one of the bits of the |
| 6072 | // lo part. |
| 6073 | unsigned LoSize = MVT::getSizeInBits(Lo.getValueType()); |
| 6074 | Hi = DAG.getNode(ISD::SRA, NVT, Lo, |
| 6075 | DAG.getConstant(LoSize-1, TLI.getShiftAmountTy())); |
| 6076 | } else if (ExtType == ISD::ZEXTLOAD) { |
| 6077 | // The high part is just a zero. |
| 6078 | Hi = DAG.getConstant(0, NVT); |
| 6079 | } else /* if (ExtType == ISD::EXTLOAD) */ { |
| 6080 | // The high part is undefined. |
| 6081 | Hi = DAG.getNode(ISD::UNDEF, NVT); |
| 6082 | } |
| 6083 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6084 | break; |
| 6085 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6086 | case ISD::AND: |
| 6087 | case ISD::OR: |
| 6088 | case ISD::XOR: { // Simple logical operators -> two trivial pieces. |
| 6089 | SDOperand LL, LH, RL, RH; |
| 6090 | ExpandOp(Node->getOperand(0), LL, LH); |
| 6091 | ExpandOp(Node->getOperand(1), RL, RH); |
| 6092 | Lo = DAG.getNode(Node->getOpcode(), NVT, LL, RL); |
| 6093 | Hi = DAG.getNode(Node->getOpcode(), NVT, LH, RH); |
| 6094 | break; |
| 6095 | } |
| 6096 | case ISD::SELECT: { |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 6097 | SDOperand LL, LH, RL, RH; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6098 | ExpandOp(Node->getOperand(1), LL, LH); |
| 6099 | ExpandOp(Node->getOperand(2), RL, RH); |
Evan Cheng | 19103b1 | 2006-12-15 22:42:55 +0000 | [diff] [blame] | 6100 | if (getTypeAction(NVT) == Expand) |
| 6101 | NVT = TLI.getTypeToExpandTo(NVT); |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 6102 | Lo = DAG.getNode(ISD::SELECT, NVT, Node->getOperand(0), LL, RL); |
Evan Cheng | 19103b1 | 2006-12-15 22:42:55 +0000 | [diff] [blame] | 6103 | if (VT != MVT::f32) |
| 6104 | Hi = DAG.getNode(ISD::SELECT, NVT, Node->getOperand(0), LH, RH); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6105 | break; |
| 6106 | } |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 6107 | case ISD::SELECT_CC: { |
| 6108 | SDOperand TL, TH, FL, FH; |
| 6109 | ExpandOp(Node->getOperand(2), TL, TH); |
| 6110 | ExpandOp(Node->getOperand(3), FL, FH); |
Evan Cheng | 19103b1 | 2006-12-15 22:42:55 +0000 | [diff] [blame] | 6111 | if (getTypeAction(NVT) == Expand) |
| 6112 | NVT = TLI.getTypeToExpandTo(NVT); |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 6113 | Lo = DAG.getNode(ISD::SELECT_CC, NVT, Node->getOperand(0), |
| 6114 | Node->getOperand(1), TL, FL, Node->getOperand(4)); |
Evan Cheng | 19103b1 | 2006-12-15 22:42:55 +0000 | [diff] [blame] | 6115 | if (VT != MVT::f32) |
| 6116 | Hi = DAG.getNode(ISD::SELECT_CC, NVT, Node->getOperand(0), |
| 6117 | Node->getOperand(1), TH, FH, Node->getOperand(4)); |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 6118 | break; |
| 6119 | } |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6120 | case ISD::ANY_EXTEND: |
| 6121 | // The low part is any extension of the input (which degenerates to a copy). |
| 6122 | Lo = DAG.getNode(ISD::ANY_EXTEND, NVT, Node->getOperand(0)); |
| 6123 | // The high part is undefined. |
| 6124 | Hi = DAG.getNode(ISD::UNDEF, NVT); |
| 6125 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6126 | case ISD::SIGN_EXTEND: { |
| 6127 | // The low part is just a sign extension of the input (which degenerates to |
| 6128 | // a copy). |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6129 | Lo = DAG.getNode(ISD::SIGN_EXTEND, NVT, Node->getOperand(0)); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 6130 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6131 | // The high part is obtained by SRA'ing all but one of the bits of the lo |
| 6132 | // part. |
Chris Lattner | 2dad454 | 2005-01-12 18:19:52 +0000 | [diff] [blame] | 6133 | unsigned LoSize = MVT::getSizeInBits(Lo.getValueType()); |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6134 | Hi = DAG.getNode(ISD::SRA, NVT, Lo, |
| 6135 | DAG.getConstant(LoSize-1, TLI.getShiftAmountTy())); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6136 | break; |
| 6137 | } |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6138 | case ISD::ZERO_EXTEND: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6139 | // The low part is just a zero extension of the input (which degenerates to |
| 6140 | // a copy). |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6141 | Lo = DAG.getNode(ISD::ZERO_EXTEND, NVT, Node->getOperand(0)); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 6142 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6143 | // The high part is just a zero. |
| 6144 | Hi = DAG.getConstant(0, NVT); |
| 6145 | break; |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 6146 | |
Chris Lattner | 4c948eb | 2007-02-13 23:55:16 +0000 | [diff] [blame] | 6147 | case ISD::TRUNCATE: { |
| 6148 | // The input value must be larger than this value. Expand *it*. |
| 6149 | SDOperand NewLo; |
| 6150 | ExpandOp(Node->getOperand(0), NewLo, Hi); |
| 6151 | |
| 6152 | // The low part is now either the right size, or it is closer. If not the |
| 6153 | // right size, make an illegal truncate so we recursively expand it. |
| 6154 | if (NewLo.getValueType() != Node->getValueType(0)) |
| 6155 | NewLo = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0), NewLo); |
| 6156 | ExpandOp(NewLo, Lo, Hi); |
| 6157 | break; |
| 6158 | } |
| 6159 | |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 6160 | case ISD::BIT_CONVERT: { |
Chris Lattner | f3f333d | 2006-09-09 00:20:27 +0000 | [diff] [blame] | 6161 | SDOperand Tmp; |
| 6162 | if (TLI.getOperationAction(ISD::BIT_CONVERT, VT) == TargetLowering::Custom){ |
| 6163 | // If the target wants to, allow it to lower this itself. |
| 6164 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 6165 | case Expand: assert(0 && "cannot expand FP!"); |
| 6166 | case Legal: Tmp = LegalizeOp(Node->getOperand(0)); break; |
| 6167 | case Promote: Tmp = PromoteOp (Node->getOperand(0)); break; |
| 6168 | } |
| 6169 | Tmp = TLI.LowerOperation(DAG.getNode(ISD::BIT_CONVERT, VT, Tmp), DAG); |
| 6170 | } |
| 6171 | |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 6172 | // f32 / f64 must be expanded to i32 / i64. |
Evan Cheng | 13acce3 | 2006-12-11 19:27:14 +0000 | [diff] [blame] | 6173 | if (VT == MVT::f32 || VT == MVT::f64) { |
| 6174 | Lo = DAG.getNode(ISD::BIT_CONVERT, NVT, Node->getOperand(0)); |
Evan Cheng | 19103b1 | 2006-12-15 22:42:55 +0000 | [diff] [blame] | 6175 | if (getTypeAction(NVT) == Expand) |
| 6176 | ExpandOp(Lo, Lo, Hi); |
Evan Cheng | 7b2b5c8 | 2006-12-12 19:53:13 +0000 | [diff] [blame] | 6177 | break; |
| 6178 | } |
| 6179 | |
| 6180 | // If source operand will be expanded to the same type as VT, i.e. |
| 6181 | // i64 <- f64, i32 <- f32, expand the source operand instead. |
| 6182 | MVT::ValueType VT0 = Node->getOperand(0).getValueType(); |
| 6183 | if (getTypeAction(VT0) == Expand && TLI.getTypeToTransformTo(VT0) == VT) { |
| 6184 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 6185 | break; |
| 6186 | } |
| 6187 | |
Chris Lattner | f3f333d | 2006-09-09 00:20:27 +0000 | [diff] [blame] | 6188 | // Turn this into a load/store pair by default. |
| 6189 | if (Tmp.Val == 0) |
Chris Lattner | 1401d15 | 2008-01-16 07:45:30 +0000 | [diff] [blame] | 6190 | Tmp = EmitStackConvert(Node->getOperand(0), VT, VT); |
Chris Lattner | f3f333d | 2006-09-09 00:20:27 +0000 | [diff] [blame] | 6191 | |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 6192 | ExpandOp(Tmp, Lo, Hi); |
| 6193 | break; |
| 6194 | } |
Andrew Lenharth | f70e30b | 2005-11-20 21:32:07 +0000 | [diff] [blame] | 6195 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6196 | case ISD::READCYCLECOUNTER: { |
Chris Lattner | 308575b | 2005-11-20 22:56:56 +0000 | [diff] [blame] | 6197 | assert(TLI.getOperationAction(ISD::READCYCLECOUNTER, VT) == |
| 6198 | TargetLowering::Custom && |
| 6199 | "Must custom expand ReadCycleCounter"); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6200 | SDOperand Tmp = TLI.LowerOperation(Op, DAG); |
| 6201 | assert(Tmp.Val && "Node must be custom expanded!"); |
| 6202 | ExpandOp(Tmp.getValue(0), Lo, Hi); |
Chris Lattner | 308575b | 2005-11-20 22:56:56 +0000 | [diff] [blame] | 6203 | AddLegalizedOperand(SDOperand(Node, 1), // Remember we legalized the chain. |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6204 | LegalizeOp(Tmp.getValue(1))); |
Andrew Lenharth | f70e30b | 2005-11-20 21:32:07 +0000 | [diff] [blame] | 6205 | break; |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6206 | } |
Andrew Lenharth | f70e30b | 2005-11-20 21:32:07 +0000 | [diff] [blame] | 6207 | |
Andrew Lenharth | d19189e | 2008-03-05 01:15:49 +0000 | [diff] [blame] | 6208 | case ISD::ATOMIC_LCS: { |
| 6209 | SDOperand Tmp = TLI.LowerOperation(Op, DAG); |
| 6210 | assert(Tmp.Val && "Node must be custom expanded!"); |
| 6211 | ExpandOp(Tmp.getValue(0), Lo, Hi); |
| 6212 | AddLegalizedOperand(SDOperand(Node, 1), // Remember we legalized the chain. |
| 6213 | LegalizeOp(Tmp.getValue(1))); |
| 6214 | break; |
| 6215 | } |
| 6216 | |
| 6217 | |
| 6218 | |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 6219 | // These operators cannot be expanded directly, emit them as calls to |
| 6220 | // library functions. |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6221 | case ISD::FP_TO_SINT: { |
Chris Lattner | 80a3e94 | 2005-07-29 00:33:32 +0000 | [diff] [blame] | 6222 | if (TLI.getOperationAction(ISD::FP_TO_SINT, VT) == TargetLowering::Custom) { |
Chris Lattner | f20d183 | 2005-07-30 01:40:57 +0000 | [diff] [blame] | 6223 | SDOperand Op; |
| 6224 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 6225 | case Expand: assert(0 && "cannot expand FP!"); |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6226 | case Legal: Op = LegalizeOp(Node->getOperand(0)); break; |
| 6227 | case Promote: Op = PromoteOp (Node->getOperand(0)); break; |
Chris Lattner | f20d183 | 2005-07-30 01:40:57 +0000 | [diff] [blame] | 6228 | } |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 6229 | |
Chris Lattner | f20d183 | 2005-07-30 01:40:57 +0000 | [diff] [blame] | 6230 | Op = TLI.LowerOperation(DAG.getNode(ISD::FP_TO_SINT, VT, Op), DAG); |
| 6231 | |
Chris Lattner | 80a3e94 | 2005-07-29 00:33:32 +0000 | [diff] [blame] | 6232 | // Now that the custom expander is done, expand the result, which is still |
| 6233 | // VT. |
Chris Lattner | 07dffd6 | 2005-08-26 00:14:16 +0000 | [diff] [blame] | 6234 | if (Op.Val) { |
| 6235 | ExpandOp(Op, Lo, Hi); |
| 6236 | break; |
| 6237 | } |
Chris Lattner | 80a3e94 | 2005-07-29 00:33:32 +0000 | [diff] [blame] | 6238 | } |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 6239 | |
Dale Johannesen | 161e897 | 2007-10-05 20:04:43 +0000 | [diff] [blame] | 6240 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
Dan Gohman | a2e9485 | 2008-03-10 23:03:31 +0000 | [diff] [blame] | 6241 | if (VT == MVT::i64) { |
| 6242 | if (Node->getOperand(0).getValueType() == MVT::f32) |
| 6243 | LC = RTLIB::FPTOSINT_F32_I64; |
| 6244 | else if (Node->getOperand(0).getValueType() == MVT::f64) |
| 6245 | LC = RTLIB::FPTOSINT_F64_I64; |
| 6246 | else if (Node->getOperand(0).getValueType() == MVT::f80) |
| 6247 | LC = RTLIB::FPTOSINT_F80_I64; |
| 6248 | else if (Node->getOperand(0).getValueType() == MVT::ppcf128) |
| 6249 | LC = RTLIB::FPTOSINT_PPCF128_I64; |
| 6250 | Lo = ExpandLibCall(TLI.getLibcallName(LC), Node, |
| 6251 | false/*sign irrelevant*/, Hi); |
| 6252 | } else if (VT == MVT::i128) { |
| 6253 | if (Node->getOperand(0).getValueType() == MVT::f32) |
| 6254 | LC = RTLIB::FPTOSINT_F32_I128; |
| 6255 | else if (Node->getOperand(0).getValueType() == MVT::f64) |
| 6256 | LC = RTLIB::FPTOSINT_F64_I128; |
| 6257 | else if (Node->getOperand(0).getValueType() == MVT::f80) |
| 6258 | LC = RTLIB::FPTOSINT_F80_I128; |
| 6259 | else if (Node->getOperand(0).getValueType() == MVT::ppcf128) |
| 6260 | LC = RTLIB::FPTOSINT_PPCF128_I128; |
| 6261 | Lo = ExpandLibCall(TLI.getLibcallName(LC), Node, |
| 6262 | false/*sign irrelevant*/, Hi); |
| 6263 | } else { |
| 6264 | assert(0 && "Unexpected uint-to-fp conversion!"); |
| 6265 | } |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 6266 | break; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6267 | } |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 6268 | |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6269 | case ISD::FP_TO_UINT: { |
Chris Lattner | 80a3e94 | 2005-07-29 00:33:32 +0000 | [diff] [blame] | 6270 | if (TLI.getOperationAction(ISD::FP_TO_UINT, VT) == TargetLowering::Custom) { |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6271 | SDOperand Op; |
| 6272 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 6273 | case Expand: assert(0 && "cannot expand FP!"); |
| 6274 | case Legal: Op = LegalizeOp(Node->getOperand(0)); break; |
| 6275 | case Promote: Op = PromoteOp (Node->getOperand(0)); break; |
| 6276 | } |
| 6277 | |
| 6278 | Op = TLI.LowerOperation(DAG.getNode(ISD::FP_TO_UINT, VT, Op), DAG); |
| 6279 | |
| 6280 | // Now that the custom expander is done, expand the result. |
Chris Lattner | 07dffd6 | 2005-08-26 00:14:16 +0000 | [diff] [blame] | 6281 | if (Op.Val) { |
| 6282 | ExpandOp(Op, Lo, Hi); |
| 6283 | break; |
| 6284 | } |
Chris Lattner | 80a3e94 | 2005-07-29 00:33:32 +0000 | [diff] [blame] | 6285 | } |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 6286 | |
Evan Cheng | daccea18 | 2007-10-05 01:09:32 +0000 | [diff] [blame] | 6287 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
Dan Gohman | a2e9485 | 2008-03-10 23:03:31 +0000 | [diff] [blame] | 6288 | if (VT == MVT::i64) { |
| 6289 | if (Node->getOperand(0).getValueType() == MVT::f32) |
| 6290 | LC = RTLIB::FPTOUINT_F32_I64; |
| 6291 | else if (Node->getOperand(0).getValueType() == MVT::f64) |
| 6292 | LC = RTLIB::FPTOUINT_F64_I64; |
| 6293 | else if (Node->getOperand(0).getValueType() == MVT::f80) |
| 6294 | LC = RTLIB::FPTOUINT_F80_I64; |
| 6295 | else if (Node->getOperand(0).getValueType() == MVT::ppcf128) |
| 6296 | LC = RTLIB::FPTOUINT_PPCF128_I64; |
| 6297 | Lo = ExpandLibCall(TLI.getLibcallName(LC), Node, |
| 6298 | false/*sign irrelevant*/, Hi); |
| 6299 | } else if (VT == MVT::i128) { |
| 6300 | if (Node->getOperand(0).getValueType() == MVT::f32) |
| 6301 | LC = RTLIB::FPTOUINT_F32_I128; |
| 6302 | else if (Node->getOperand(0).getValueType() == MVT::f64) |
| 6303 | LC = RTLIB::FPTOUINT_F64_I128; |
| 6304 | else if (Node->getOperand(0).getValueType() == MVT::f80) |
| 6305 | LC = RTLIB::FPTOUINT_F80_I128; |
| 6306 | else if (Node->getOperand(0).getValueType() == MVT::ppcf128) |
| 6307 | LC = RTLIB::FPTOUINT_PPCF128_I128; |
| 6308 | Lo = ExpandLibCall(TLI.getLibcallName(LC), Node, |
| 6309 | false/*sign irrelevant*/, Hi); |
| 6310 | } else { |
| 6311 | assert(0 && "Unexpected uint-to-fp conversion!"); |
| 6312 | } |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 6313 | break; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6314 | } |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 6315 | |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 6316 | case ISD::SHL: { |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6317 | // If the target wants custom lowering, do so. |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 6318 | SDOperand ShiftAmt = LegalizeOp(Node->getOperand(1)); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6319 | if (TLI.getOperationAction(ISD::SHL, VT) == TargetLowering::Custom) { |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6320 | SDOperand Op = DAG.getNode(ISD::SHL, VT, Node->getOperand(0), ShiftAmt); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6321 | Op = TLI.LowerOperation(Op, DAG); |
| 6322 | if (Op.Val) { |
| 6323 | // Now that the custom expander is done, expand the result, which is |
| 6324 | // still VT. |
| 6325 | ExpandOp(Op, Lo, Hi); |
| 6326 | break; |
| 6327 | } |
| 6328 | } |
| 6329 | |
Chris Lattner | 79980b0 | 2006-09-13 03:50:39 +0000 | [diff] [blame] | 6330 | // If ADDC/ADDE are supported and if the shift amount is a constant 1, emit |
| 6331 | // this X << 1 as X+X. |
| 6332 | if (ConstantSDNode *ShAmt = dyn_cast<ConstantSDNode>(ShiftAmt)) { |
Dan Gohman | 002e5d0 | 2008-03-13 22:13:53 +0000 | [diff] [blame] | 6333 | if (ShAmt->getAPIntValue() == 1 && TLI.isOperationLegal(ISD::ADDC, NVT) && |
Chris Lattner | 79980b0 | 2006-09-13 03:50:39 +0000 | [diff] [blame] | 6334 | TLI.isOperationLegal(ISD::ADDE, NVT)) { |
| 6335 | SDOperand LoOps[2], HiOps[3]; |
| 6336 | ExpandOp(Node->getOperand(0), LoOps[0], HiOps[0]); |
| 6337 | SDVTList VTList = DAG.getVTList(LoOps[0].getValueType(), MVT::Flag); |
| 6338 | LoOps[1] = LoOps[0]; |
| 6339 | Lo = DAG.getNode(ISD::ADDC, VTList, LoOps, 2); |
| 6340 | |
| 6341 | HiOps[1] = HiOps[0]; |
| 6342 | HiOps[2] = Lo.getValue(1); |
| 6343 | Hi = DAG.getNode(ISD::ADDE, VTList, HiOps, 3); |
| 6344 | break; |
| 6345 | } |
| 6346 | } |
| 6347 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6348 | // If we can emit an efficient shift operation, do so now. |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 6349 | if (ExpandShift(ISD::SHL, Node->getOperand(0), ShiftAmt, Lo, Hi)) |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6350 | break; |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 6351 | |
| 6352 | // If this target supports SHL_PARTS, use it. |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 6353 | TargetLowering::LegalizeAction Action = |
| 6354 | TLI.getOperationAction(ISD::SHL_PARTS, NVT); |
| 6355 | if ((Action == TargetLowering::Legal && TLI.isTypeLegal(NVT)) || |
| 6356 | Action == TargetLowering::Custom) { |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 6357 | ExpandShiftParts(ISD::SHL_PARTS, Node->getOperand(0), ShiftAmt, Lo, Hi); |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 6358 | break; |
| 6359 | } |
| 6360 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6361 | // Otherwise, emit a libcall. |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6362 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::SHL_I64), Node, |
| 6363 | false/*left shift=unsigned*/, Hi); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6364 | break; |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 6365 | } |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6366 | |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 6367 | case ISD::SRA: { |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6368 | // If the target wants custom lowering, do so. |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 6369 | SDOperand ShiftAmt = LegalizeOp(Node->getOperand(1)); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6370 | if (TLI.getOperationAction(ISD::SRA, VT) == TargetLowering::Custom) { |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6371 | SDOperand Op = DAG.getNode(ISD::SRA, VT, Node->getOperand(0), ShiftAmt); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6372 | Op = TLI.LowerOperation(Op, DAG); |
| 6373 | if (Op.Val) { |
| 6374 | // Now that the custom expander is done, expand the result, which is |
| 6375 | // still VT. |
| 6376 | ExpandOp(Op, Lo, Hi); |
| 6377 | break; |
| 6378 | } |
| 6379 | } |
| 6380 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6381 | // If we can emit an efficient shift operation, do so now. |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 6382 | if (ExpandShift(ISD::SRA, Node->getOperand(0), ShiftAmt, Lo, Hi)) |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6383 | break; |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 6384 | |
| 6385 | // If this target supports SRA_PARTS, use it. |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 6386 | TargetLowering::LegalizeAction Action = |
| 6387 | TLI.getOperationAction(ISD::SRA_PARTS, NVT); |
| 6388 | if ((Action == TargetLowering::Legal && TLI.isTypeLegal(NVT)) || |
| 6389 | Action == TargetLowering::Custom) { |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 6390 | ExpandShiftParts(ISD::SRA_PARTS, Node->getOperand(0), ShiftAmt, Lo, Hi); |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 6391 | break; |
| 6392 | } |
| 6393 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6394 | // Otherwise, emit a libcall. |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6395 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::SRA_I64), Node, |
| 6396 | true/*ashr is signed*/, Hi); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6397 | break; |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 6398 | } |
| 6399 | |
| 6400 | case ISD::SRL: { |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6401 | // If the target wants custom lowering, do so. |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 6402 | SDOperand ShiftAmt = LegalizeOp(Node->getOperand(1)); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6403 | if (TLI.getOperationAction(ISD::SRL, VT) == TargetLowering::Custom) { |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6404 | SDOperand Op = DAG.getNode(ISD::SRL, VT, Node->getOperand(0), ShiftAmt); |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 6405 | Op = TLI.LowerOperation(Op, DAG); |
| 6406 | if (Op.Val) { |
| 6407 | // Now that the custom expander is done, expand the result, which is |
| 6408 | // still VT. |
| 6409 | ExpandOp(Op, Lo, Hi); |
| 6410 | break; |
| 6411 | } |
| 6412 | } |
| 6413 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6414 | // If we can emit an efficient shift operation, do so now. |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 6415 | if (ExpandShift(ISD::SRL, Node->getOperand(0), ShiftAmt, Lo, Hi)) |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6416 | break; |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 6417 | |
| 6418 | // If this target supports SRL_PARTS, use it. |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 6419 | TargetLowering::LegalizeAction Action = |
| 6420 | TLI.getOperationAction(ISD::SRL_PARTS, NVT); |
| 6421 | if ((Action == TargetLowering::Legal && TLI.isTypeLegal(NVT)) || |
| 6422 | Action == TargetLowering::Custom) { |
Chris Lattner | 348e93c | 2006-01-21 04:27:00 +0000 | [diff] [blame] | 6423 | ExpandShiftParts(ISD::SRL_PARTS, Node->getOperand(0), ShiftAmt, Lo, Hi); |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 6424 | break; |
| 6425 | } |
| 6426 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6427 | // Otherwise, emit a libcall. |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6428 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::SRL_I64), Node, |
| 6429 | false/*lshr is unsigned*/, Hi); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6430 | break; |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 6431 | } |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 6432 | |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 6433 | case ISD::ADD: |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6434 | case ISD::SUB: { |
| 6435 | // If the target wants to custom expand this, let them. |
| 6436 | if (TLI.getOperationAction(Node->getOpcode(), VT) == |
| 6437 | TargetLowering::Custom) { |
| 6438 | Op = TLI.LowerOperation(Op, DAG); |
| 6439 | if (Op.Val) { |
| 6440 | ExpandOp(Op, Lo, Hi); |
| 6441 | break; |
| 6442 | } |
| 6443 | } |
| 6444 | |
| 6445 | // Expand the subcomponents. |
| 6446 | SDOperand LHSL, LHSH, RHSL, RHSH; |
| 6447 | ExpandOp(Node->getOperand(0), LHSL, LHSH); |
| 6448 | ExpandOp(Node->getOperand(1), RHSL, RHSH); |
Chris Lattner | 79980b0 | 2006-09-13 03:50:39 +0000 | [diff] [blame] | 6449 | SDVTList VTList = DAG.getVTList(LHSL.getValueType(), MVT::Flag); |
| 6450 | SDOperand LoOps[2], HiOps[3]; |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 6451 | LoOps[0] = LHSL; |
| 6452 | LoOps[1] = RHSL; |
| 6453 | HiOps[0] = LHSH; |
| 6454 | HiOps[1] = RHSH; |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 6455 | if (Node->getOpcode() == ISD::ADD) { |
Chris Lattner | 79980b0 | 2006-09-13 03:50:39 +0000 | [diff] [blame] | 6456 | Lo = DAG.getNode(ISD::ADDC, VTList, LoOps, 2); |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 6457 | HiOps[2] = Lo.getValue(1); |
Chris Lattner | 79980b0 | 2006-09-13 03:50:39 +0000 | [diff] [blame] | 6458 | Hi = DAG.getNode(ISD::ADDE, VTList, HiOps, 3); |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 6459 | } else { |
Chris Lattner | 79980b0 | 2006-09-13 03:50:39 +0000 | [diff] [blame] | 6460 | Lo = DAG.getNode(ISD::SUBC, VTList, LoOps, 2); |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 6461 | HiOps[2] = Lo.getValue(1); |
Chris Lattner | 79980b0 | 2006-09-13 03:50:39 +0000 | [diff] [blame] | 6462 | Hi = DAG.getNode(ISD::SUBE, VTList, HiOps, 3); |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 6463 | } |
Chris Lattner | 84f6788 | 2005-01-20 18:52:28 +0000 | [diff] [blame] | 6464 | break; |
Chris Lattner | 8137c9e | 2006-01-28 05:07:51 +0000 | [diff] [blame] | 6465 | } |
Chris Lattner | b429f73 | 2007-05-17 18:15:41 +0000 | [diff] [blame] | 6466 | |
| 6467 | case ISD::ADDC: |
| 6468 | case ISD::SUBC: { |
| 6469 | // Expand the subcomponents. |
| 6470 | SDOperand LHSL, LHSH, RHSL, RHSH; |
| 6471 | ExpandOp(Node->getOperand(0), LHSL, LHSH); |
| 6472 | ExpandOp(Node->getOperand(1), RHSL, RHSH); |
| 6473 | SDVTList VTList = DAG.getVTList(LHSL.getValueType(), MVT::Flag); |
| 6474 | SDOperand LoOps[2] = { LHSL, RHSL }; |
| 6475 | SDOperand HiOps[3] = { LHSH, RHSH }; |
| 6476 | |
| 6477 | if (Node->getOpcode() == ISD::ADDC) { |
| 6478 | Lo = DAG.getNode(ISD::ADDC, VTList, LoOps, 2); |
| 6479 | HiOps[2] = Lo.getValue(1); |
| 6480 | Hi = DAG.getNode(ISD::ADDE, VTList, HiOps, 3); |
| 6481 | } else { |
| 6482 | Lo = DAG.getNode(ISD::SUBC, VTList, LoOps, 2); |
| 6483 | HiOps[2] = Lo.getValue(1); |
| 6484 | Hi = DAG.getNode(ISD::SUBE, VTList, HiOps, 3); |
| 6485 | } |
| 6486 | // Remember that we legalized the flag. |
| 6487 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Hi.getValue(1))); |
| 6488 | break; |
| 6489 | } |
| 6490 | case ISD::ADDE: |
| 6491 | case ISD::SUBE: { |
| 6492 | // Expand the subcomponents. |
| 6493 | SDOperand LHSL, LHSH, RHSL, RHSH; |
| 6494 | ExpandOp(Node->getOperand(0), LHSL, LHSH); |
| 6495 | ExpandOp(Node->getOperand(1), RHSL, RHSH); |
| 6496 | SDVTList VTList = DAG.getVTList(LHSL.getValueType(), MVT::Flag); |
| 6497 | SDOperand LoOps[3] = { LHSL, RHSL, Node->getOperand(2) }; |
| 6498 | SDOperand HiOps[3] = { LHSH, RHSH }; |
| 6499 | |
| 6500 | Lo = DAG.getNode(Node->getOpcode(), VTList, LoOps, 3); |
| 6501 | HiOps[2] = Lo.getValue(1); |
| 6502 | Hi = DAG.getNode(Node->getOpcode(), VTList, HiOps, 3); |
| 6503 | |
| 6504 | // Remember that we legalized the flag. |
| 6505 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Hi.getValue(1))); |
| 6506 | break; |
| 6507 | } |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 6508 | case ISD::MUL: { |
Chris Lattner | 7d7bffe | 2006-09-16 00:09:24 +0000 | [diff] [blame] | 6509 | // If the target wants to custom expand this, let them. |
| 6510 | if (TLI.getOperationAction(ISD::MUL, VT) == TargetLowering::Custom) { |
Chris Lattner | 8829dc8 | 2006-09-16 05:08:34 +0000 | [diff] [blame] | 6511 | SDOperand New = TLI.LowerOperation(Op, DAG); |
| 6512 | if (New.Val) { |
| 6513 | ExpandOp(New, Lo, Hi); |
Chris Lattner | 7d7bffe | 2006-09-16 00:09:24 +0000 | [diff] [blame] | 6514 | break; |
| 6515 | } |
| 6516 | } |
| 6517 | |
Evan Cheng | 3f4fd0f | 2006-09-01 18:17:58 +0000 | [diff] [blame] | 6518 | bool HasMULHS = TLI.isOperationLegal(ISD::MULHS, NVT); |
| 6519 | bool HasMULHU = TLI.isOperationLegal(ISD::MULHU, NVT); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 6520 | bool HasSMUL_LOHI = TLI.isOperationLegal(ISD::SMUL_LOHI, NVT); |
| 6521 | bool HasUMUL_LOHI = TLI.isOperationLegal(ISD::UMUL_LOHI, NVT); |
| 6522 | if (HasMULHU || HasMULHS || HasUMUL_LOHI || HasSMUL_LOHI) { |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 6523 | SDOperand LL, LH, RL, RH; |
| 6524 | ExpandOp(Node->getOperand(0), LL, LH); |
| 6525 | ExpandOp(Node->getOperand(1), RL, RH); |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 6526 | unsigned OuterBitSize = Op.getValueSizeInBits(); |
| 6527 | unsigned InnerBitSize = RH.getValueSizeInBits(); |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 6528 | unsigned LHSSB = DAG.ComputeNumSignBits(Op.getOperand(0)); |
| 6529 | unsigned RHSSB = DAG.ComputeNumSignBits(Op.getOperand(1)); |
Dan Gohman | 76c605b | 2008-03-10 20:42:19 +0000 | [diff] [blame] | 6530 | APInt HighMask = APInt::getHighBitsSet(OuterBitSize, InnerBitSize); |
| 6531 | if (DAG.MaskedValueIsZero(Node->getOperand(0), HighMask) && |
| 6532 | DAG.MaskedValueIsZero(Node->getOperand(1), HighMask)) { |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 6533 | // The inputs are both zero-extended. |
| 6534 | if (HasUMUL_LOHI) { |
| 6535 | // We can emit a umul_lohi. |
| 6536 | Lo = DAG.getNode(ISD::UMUL_LOHI, DAG.getVTList(NVT, NVT), LL, RL); |
| 6537 | Hi = SDOperand(Lo.Val, 1); |
| 6538 | break; |
| 6539 | } |
| 6540 | if (HasMULHU) { |
| 6541 | // We can emit a mulhu+mul. |
| 6542 | Lo = DAG.getNode(ISD::MUL, NVT, LL, RL); |
| 6543 | Hi = DAG.getNode(ISD::MULHU, NVT, LL, RL); |
| 6544 | break; |
| 6545 | } |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 6546 | } |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 6547 | if (LHSSB > InnerBitSize && RHSSB > InnerBitSize) { |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 6548 | // The input values are both sign-extended. |
| 6549 | if (HasSMUL_LOHI) { |
| 6550 | // We can emit a smul_lohi. |
| 6551 | Lo = DAG.getNode(ISD::SMUL_LOHI, DAG.getVTList(NVT, NVT), LL, RL); |
| 6552 | Hi = SDOperand(Lo.Val, 1); |
| 6553 | break; |
| 6554 | } |
| 6555 | if (HasMULHS) { |
| 6556 | // We can emit a mulhs+mul. |
| 6557 | Lo = DAG.getNode(ISD::MUL, NVT, LL, RL); |
| 6558 | Hi = DAG.getNode(ISD::MULHS, NVT, LL, RL); |
| 6559 | break; |
| 6560 | } |
| 6561 | } |
| 6562 | if (HasUMUL_LOHI) { |
| 6563 | // Lo,Hi = umul LHS, RHS. |
| 6564 | SDOperand UMulLOHI = DAG.getNode(ISD::UMUL_LOHI, |
| 6565 | DAG.getVTList(NVT, NVT), LL, RL); |
| 6566 | Lo = UMulLOHI; |
| 6567 | Hi = UMulLOHI.getValue(1); |
Nate Begeman | 56eb868 | 2005-08-30 02:44:00 +0000 | [diff] [blame] | 6568 | RH = DAG.getNode(ISD::MUL, NVT, LL, RH); |
| 6569 | LH = DAG.getNode(ISD::MUL, NVT, LH, RL); |
| 6570 | Hi = DAG.getNode(ISD::ADD, NVT, Hi, RH); |
| 6571 | Hi = DAG.getNode(ISD::ADD, NVT, Hi, LH); |
Chris Lattner | a89654b | 2006-09-16 00:21:44 +0000 | [diff] [blame] | 6572 | break; |
Nate Begeman | 56eb868 | 2005-08-30 02:44:00 +0000 | [diff] [blame] | 6573 | } |
Dale Johannesen | 8eadd5a | 2007-10-24 22:26:08 +0000 | [diff] [blame] | 6574 | if (HasMULHU) { |
| 6575 | Lo = DAG.getNode(ISD::MUL, NVT, LL, RL); |
| 6576 | Hi = DAG.getNode(ISD::MULHU, NVT, LL, RL); |
| 6577 | RH = DAG.getNode(ISD::MUL, NVT, LL, RH); |
| 6578 | LH = DAG.getNode(ISD::MUL, NVT, LH, RL); |
| 6579 | Hi = DAG.getNode(ISD::ADD, NVT, Hi, RH); |
| 6580 | Hi = DAG.getNode(ISD::ADD, NVT, Hi, LH); |
| 6581 | break; |
| 6582 | } |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 6583 | } |
Evan Cheng | 3f4fd0f | 2006-09-01 18:17:58 +0000 | [diff] [blame] | 6584 | |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 6585 | // If nothing else, we can make a libcall. |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6586 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::MUL_I64), Node, |
| 6587 | false/*sign irrelevant*/, Hi); |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 6588 | break; |
| 6589 | } |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6590 | case ISD::SDIV: |
| 6591 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::SDIV_I64), Node, true, Hi); |
| 6592 | break; |
| 6593 | case ISD::UDIV: |
| 6594 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::UDIV_I64), Node, true, Hi); |
| 6595 | break; |
| 6596 | case ISD::SREM: |
| 6597 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::SREM_I64), Node, true, Hi); |
| 6598 | break; |
| 6599 | case ISD::UREM: |
| 6600 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::UREM_I64), Node, true, Hi); |
| 6601 | break; |
Evan Cheng | 5c9ce18 | 2006-12-12 21:51:17 +0000 | [diff] [blame] | 6602 | |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 6603 | case ISD::FADD: |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 6604 | Lo = ExpandLibCall(TLI.getLibcallName(GetFPLibCall(VT, RTLIB::ADD_F32, |
| 6605 | RTLIB::ADD_F64, |
| 6606 | RTLIB::ADD_F80, |
| 6607 | RTLIB::ADD_PPCF128)), |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6608 | Node, false, Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 6609 | break; |
| 6610 | case ISD::FSUB: |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 6611 | Lo = ExpandLibCall(TLI.getLibcallName(GetFPLibCall(VT, RTLIB::SUB_F32, |
| 6612 | RTLIB::SUB_F64, |
| 6613 | RTLIB::SUB_F80, |
| 6614 | RTLIB::SUB_PPCF128)), |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6615 | Node, false, Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 6616 | break; |
| 6617 | case ISD::FMUL: |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 6618 | Lo = ExpandLibCall(TLI.getLibcallName(GetFPLibCall(VT, RTLIB::MUL_F32, |
| 6619 | RTLIB::MUL_F64, |
| 6620 | RTLIB::MUL_F80, |
| 6621 | RTLIB::MUL_PPCF128)), |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6622 | Node, false, Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 6623 | break; |
| 6624 | case ISD::FDIV: |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 6625 | Lo = ExpandLibCall(TLI.getLibcallName(GetFPLibCall(VT, RTLIB::DIV_F32, |
| 6626 | RTLIB::DIV_F64, |
| 6627 | RTLIB::DIV_F80, |
| 6628 | RTLIB::DIV_PPCF128)), |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6629 | Node, false, Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 6630 | break; |
| 6631 | case ISD::FP_EXTEND: |
Dale Johannesen | ca68aaa | 2007-10-12 01:37:08 +0000 | [diff] [blame] | 6632 | if (VT == MVT::ppcf128) { |
| 6633 | assert(Node->getOperand(0).getValueType()==MVT::f32 || |
| 6634 | Node->getOperand(0).getValueType()==MVT::f64); |
| 6635 | const uint64_t zero = 0; |
| 6636 | if (Node->getOperand(0).getValueType()==MVT::f32) |
| 6637 | Hi = DAG.getNode(ISD::FP_EXTEND, MVT::f64, Node->getOperand(0)); |
| 6638 | else |
| 6639 | Hi = Node->getOperand(0); |
| 6640 | Lo = DAG.getConstantFP(APFloat(APInt(64, 1, &zero)), MVT::f64); |
| 6641 | break; |
| 6642 | } |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6643 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::FPEXT_F32_F64), Node, true,Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 6644 | break; |
| 6645 | case ISD::FP_ROUND: |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6646 | Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::FPROUND_F64_F32),Node,true,Hi); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 6647 | break; |
Lauro Ramos Venancio | c90f089 | 2007-08-15 22:13:27 +0000 | [diff] [blame] | 6648 | case ISD::FPOWI: |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 6649 | Lo = ExpandLibCall(TLI.getLibcallName(GetFPLibCall(VT, RTLIB::POWI_F32, |
| 6650 | RTLIB::POWI_F64, |
| 6651 | RTLIB::POWI_F80, |
| 6652 | RTLIB::POWI_PPCF128)), |
Lauro Ramos Venancio | c90f089 | 2007-08-15 22:13:27 +0000 | [diff] [blame] | 6653 | Node, false, Hi); |
| 6654 | break; |
Evan Cheng | 98ff3b9 | 2006-12-13 02:38:13 +0000 | [diff] [blame] | 6655 | case ISD::FSQRT: |
| 6656 | case ISD::FSIN: |
| 6657 | case ISD::FCOS: { |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6658 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
Evan Cheng | 98ff3b9 | 2006-12-13 02:38:13 +0000 | [diff] [blame] | 6659 | switch(Node->getOpcode()) { |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6660 | case ISD::FSQRT: |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 6661 | LC = GetFPLibCall(VT, RTLIB::SQRT_F32, RTLIB::SQRT_F64, |
| 6662 | RTLIB::SQRT_F80, RTLIB::SQRT_PPCF128); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6663 | break; |
| 6664 | case ISD::FSIN: |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 6665 | LC = GetFPLibCall(VT, RTLIB::SIN_F32, RTLIB::SIN_F64, |
| 6666 | RTLIB::SIN_F80, RTLIB::SIN_PPCF128); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6667 | break; |
| 6668 | case ISD::FCOS: |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 6669 | LC = GetFPLibCall(VT, RTLIB::COS_F32, RTLIB::COS_F64, |
| 6670 | RTLIB::COS_F80, RTLIB::COS_PPCF128); |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6671 | break; |
Evan Cheng | 98ff3b9 | 2006-12-13 02:38:13 +0000 | [diff] [blame] | 6672 | default: assert(0 && "Unreachable!"); |
| 6673 | } |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 6674 | Lo = ExpandLibCall(TLI.getLibcallName(LC), Node, false, Hi); |
Evan Cheng | 98ff3b9 | 2006-12-13 02:38:13 +0000 | [diff] [blame] | 6675 | break; |
| 6676 | } |
Evan Cheng | 966bf24 | 2006-12-16 00:52:40 +0000 | [diff] [blame] | 6677 | case ISD::FABS: { |
Dale Johannesen | f646774 | 2007-10-12 19:02:17 +0000 | [diff] [blame] | 6678 | if (VT == MVT::ppcf128) { |
| 6679 | SDOperand Tmp; |
| 6680 | ExpandOp(Node->getOperand(0), Lo, Tmp); |
| 6681 | Hi = DAG.getNode(ISD::FABS, NVT, Tmp); |
| 6682 | // lo = hi==fabs(hi) ? lo : -lo; |
| 6683 | Lo = DAG.getNode(ISD::SELECT_CC, NVT, Hi, Tmp, |
| 6684 | Lo, DAG.getNode(ISD::FNEG, NVT, Lo), |
| 6685 | DAG.getCondCode(ISD::SETEQ)); |
| 6686 | break; |
| 6687 | } |
Evan Cheng | 966bf24 | 2006-12-16 00:52:40 +0000 | [diff] [blame] | 6688 | SDOperand Mask = (VT == MVT::f64) |
| 6689 | ? DAG.getConstantFP(BitsToDouble(~(1ULL << 63)), VT) |
| 6690 | : DAG.getConstantFP(BitsToFloat(~(1U << 31)), VT); |
| 6691 | Mask = DAG.getNode(ISD::BIT_CONVERT, NVT, Mask); |
| 6692 | Lo = DAG.getNode(ISD::BIT_CONVERT, NVT, Node->getOperand(0)); |
| 6693 | Lo = DAG.getNode(ISD::AND, NVT, Lo, Mask); |
| 6694 | if (getTypeAction(NVT) == Expand) |
| 6695 | ExpandOp(Lo, Lo, Hi); |
| 6696 | break; |
| 6697 | } |
| 6698 | case ISD::FNEG: { |
Dale Johannesen | f646774 | 2007-10-12 19:02:17 +0000 | [diff] [blame] | 6699 | if (VT == MVT::ppcf128) { |
| 6700 | ExpandOp(Node->getOperand(0), Lo, Hi); |
| 6701 | Lo = DAG.getNode(ISD::FNEG, MVT::f64, Lo); |
| 6702 | Hi = DAG.getNode(ISD::FNEG, MVT::f64, Hi); |
| 6703 | break; |
| 6704 | } |
Evan Cheng | 966bf24 | 2006-12-16 00:52:40 +0000 | [diff] [blame] | 6705 | SDOperand Mask = (VT == MVT::f64) |
| 6706 | ? DAG.getConstantFP(BitsToDouble(1ULL << 63), VT) |
| 6707 | : DAG.getConstantFP(BitsToFloat(1U << 31), VT); |
| 6708 | Mask = DAG.getNode(ISD::BIT_CONVERT, NVT, Mask); |
| 6709 | Lo = DAG.getNode(ISD::BIT_CONVERT, NVT, Node->getOperand(0)); |
| 6710 | Lo = DAG.getNode(ISD::XOR, NVT, Lo, Mask); |
| 6711 | if (getTypeAction(NVT) == Expand) |
| 6712 | ExpandOp(Lo, Lo, Hi); |
| 6713 | break; |
| 6714 | } |
Evan Cheng | 912095b | 2007-01-04 21:56:39 +0000 | [diff] [blame] | 6715 | case ISD::FCOPYSIGN: { |
| 6716 | Lo = ExpandFCOPYSIGNToBitwiseOps(Node, NVT, DAG, TLI); |
| 6717 | if (getTypeAction(NVT) == Expand) |
| 6718 | ExpandOp(Lo, Lo, Hi); |
| 6719 | break; |
| 6720 | } |
Evan Cheng | 7df28dc | 2006-12-19 01:44:04 +0000 | [diff] [blame] | 6721 | case ISD::SINT_TO_FP: |
| 6722 | case ISD::UINT_TO_FP: { |
| 6723 | bool isSigned = Node->getOpcode() == ISD::SINT_TO_FP; |
| 6724 | MVT::ValueType SrcVT = Node->getOperand(0).getValueType(); |
Dale Johannesen | cf49819 | 2008-03-18 17:28:38 +0000 | [diff] [blame] | 6725 | |
| 6726 | // Promote the operand if needed. Do this before checking for |
| 6727 | // ppcf128 so conversions of i16 and i8 work. |
| 6728 | if (getTypeAction(SrcVT) == Promote) { |
| 6729 | SDOperand Tmp = PromoteOp(Node->getOperand(0)); |
| 6730 | Tmp = isSigned |
| 6731 | ? DAG.getNode(ISD::SIGN_EXTEND_INREG, Tmp.getValueType(), Tmp, |
| 6732 | DAG.getValueType(SrcVT)) |
| 6733 | : DAG.getZeroExtendInReg(Tmp, SrcVT); |
| 6734 | Node = DAG.UpdateNodeOperands(Op, Tmp).Val; |
| 6735 | SrcVT = Node->getOperand(0).getValueType(); |
| 6736 | } |
| 6737 | |
Dan Gohman | a2e9485 | 2008-03-10 23:03:31 +0000 | [diff] [blame] | 6738 | if (VT == MVT::ppcf128 && SrcVT == MVT::i32) { |
Dan Gohman | f6283fd | 2008-02-25 21:39:34 +0000 | [diff] [blame] | 6739 | static const uint64_t zero = 0; |
Dale Johannesen | ca68aaa | 2007-10-12 01:37:08 +0000 | [diff] [blame] | 6740 | if (isSigned) { |
| 6741 | Hi = LegalizeOp(DAG.getNode(ISD::SINT_TO_FP, MVT::f64, |
| 6742 | Node->getOperand(0))); |
| 6743 | Lo = DAG.getConstantFP(APFloat(APInt(64, 1, &zero)), MVT::f64); |
| 6744 | } else { |
Dan Gohman | f6283fd | 2008-02-25 21:39:34 +0000 | [diff] [blame] | 6745 | static const uint64_t TwoE32[] = { 0x41f0000000000000LL, 0 }; |
Dale Johannesen | ca68aaa | 2007-10-12 01:37:08 +0000 | [diff] [blame] | 6746 | Hi = LegalizeOp(DAG.getNode(ISD::SINT_TO_FP, MVT::f64, |
| 6747 | Node->getOperand(0))); |
| 6748 | Lo = DAG.getConstantFP(APFloat(APInt(64, 1, &zero)), MVT::f64); |
| 6749 | Hi = DAG.getNode(ISD::BUILD_PAIR, VT, Lo, Hi); |
Dale Johannesen | 6e63e09 | 2007-10-12 17:52:03 +0000 | [diff] [blame] | 6750 | // X>=0 ? {(f64)x, 0} : {(f64)x, 0} + 2^32 |
Dale Johannesen | ca68aaa | 2007-10-12 01:37:08 +0000 | [diff] [blame] | 6751 | ExpandOp(DAG.getNode(ISD::SELECT_CC, MVT::ppcf128, Node->getOperand(0), |
| 6752 | DAG.getConstant(0, MVT::i32), |
| 6753 | DAG.getNode(ISD::FADD, MVT::ppcf128, Hi, |
| 6754 | DAG.getConstantFP( |
| 6755 | APFloat(APInt(128, 2, TwoE32)), |
| 6756 | MVT::ppcf128)), |
| 6757 | Hi, |
| 6758 | DAG.getCondCode(ISD::SETLT)), |
| 6759 | Lo, Hi); |
| 6760 | } |
| 6761 | break; |
| 6762 | } |
Dale Johannesen | 6e63e09 | 2007-10-12 17:52:03 +0000 | [diff] [blame] | 6763 | if (VT == MVT::ppcf128 && SrcVT == MVT::i64 && !isSigned) { |
| 6764 | // si64->ppcf128 done by libcall, below |
Dan Gohman | f6283fd | 2008-02-25 21:39:34 +0000 | [diff] [blame] | 6765 | static const uint64_t TwoE64[] = { 0x43f0000000000000LL, 0 }; |
Dale Johannesen | 6e63e09 | 2007-10-12 17:52:03 +0000 | [diff] [blame] | 6766 | ExpandOp(DAG.getNode(ISD::SINT_TO_FP, MVT::ppcf128, Node->getOperand(0)), |
| 6767 | Lo, Hi); |
| 6768 | Hi = DAG.getNode(ISD::BUILD_PAIR, VT, Lo, Hi); |
| 6769 | // x>=0 ? (ppcf128)(i64)x : (ppcf128)(i64)x + 2^64 |
| 6770 | ExpandOp(DAG.getNode(ISD::SELECT_CC, MVT::ppcf128, Node->getOperand(0), |
| 6771 | DAG.getConstant(0, MVT::i64), |
| 6772 | DAG.getNode(ISD::FADD, MVT::ppcf128, Hi, |
| 6773 | DAG.getConstantFP( |
| 6774 | APFloat(APInt(128, 2, TwoE64)), |
| 6775 | MVT::ppcf128)), |
| 6776 | Hi, |
| 6777 | DAG.getCondCode(ISD::SETLT)), |
| 6778 | Lo, Hi); |
| 6779 | break; |
| 6780 | } |
Evan Cheng | 7df28dc | 2006-12-19 01:44:04 +0000 | [diff] [blame] | 6781 | |
Dan Gohman | a2e9485 | 2008-03-10 23:03:31 +0000 | [diff] [blame] | 6782 | Lo = ExpandIntToFP(Node->getOpcode() == ISD::SINT_TO_FP, VT, |
| 6783 | Node->getOperand(0)); |
Evan Cheng | 110cf48 | 2008-04-01 01:50:16 +0000 | [diff] [blame] | 6784 | if (getTypeAction(Lo.getValueType()) == Expand) |
Evan Cheng | 6ad2f93 | 2008-04-01 01:51:26 +0000 | [diff] [blame] | 6785 | // float to i32 etc. can be 'expanded' to a single node. |
Evan Cheng | 110cf48 | 2008-04-01 01:50:16 +0000 | [diff] [blame] | 6786 | ExpandOp(Lo, Lo, Hi); |
Evan Cheng | 7df28dc | 2006-12-19 01:44:04 +0000 | [diff] [blame] | 6787 | break; |
| 6788 | } |
Evan Cheng | 98ff3b9 | 2006-12-13 02:38:13 +0000 | [diff] [blame] | 6789 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6790 | |
Chris Lattner | 8339736 | 2005-12-21 18:02:52 +0000 | [diff] [blame] | 6791 | // Make sure the resultant values have been legalized themselves, unless this |
| 6792 | // is a type that requires multi-step expansion. |
| 6793 | if (getTypeAction(NVT) != Expand && NVT != MVT::isVoid) { |
| 6794 | Lo = LegalizeOp(Lo); |
Evan Cheng | 13acce3 | 2006-12-11 19:27:14 +0000 | [diff] [blame] | 6795 | if (Hi.Val) |
| 6796 | // Don't legalize the high part if it is expanded to a single node. |
| 6797 | Hi = LegalizeOp(Hi); |
Chris Lattner | 8339736 | 2005-12-21 18:02:52 +0000 | [diff] [blame] | 6798 | } |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 6799 | |
| 6800 | // Remember in a map if the values will be reused later. |
Chris Lattner | 40030bf | 2007-02-04 01:17:38 +0000 | [diff] [blame] | 6801 | bool isNew = ExpandedNodes.insert(std::make_pair(Op, std::make_pair(Lo, Hi))); |
Evan Cheng | 05a2d56 | 2006-01-09 18:31:59 +0000 | [diff] [blame] | 6802 | assert(isNew && "Value already expanded?!?"); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 6803 | } |
| 6804 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6805 | /// SplitVectorOp - Given an operand of vector type, break it down into |
| 6806 | /// two smaller values, still of vector type. |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6807 | void SelectionDAGLegalize::SplitVectorOp(SDOperand Op, SDOperand &Lo, |
| 6808 | SDOperand &Hi) { |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6809 | assert(MVT::isVector(Op.getValueType()) && "Cannot split non-vector type!"); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6810 | SDNode *Node = Op.Val; |
Dan Gohman | e40c7b0 | 2007-09-24 15:54:53 +0000 | [diff] [blame] | 6811 | unsigned NumElements = MVT::getVectorNumElements(Op.getValueType()); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6812 | assert(NumElements > 1 && "Cannot split a single element vector!"); |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 6813 | |
Dan Gohman | e40c7b0 | 2007-09-24 15:54:53 +0000 | [diff] [blame] | 6814 | MVT::ValueType NewEltVT = MVT::getVectorElementType(Op.getValueType()); |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 6815 | |
| 6816 | unsigned NewNumElts_Lo = 1 << Log2_32(NumElements-1); |
| 6817 | unsigned NewNumElts_Hi = NumElements - NewNumElts_Lo; |
| 6818 | |
| 6819 | MVT::ValueType NewVT_Lo = MVT::getVectorType(NewEltVT, NewNumElts_Lo); |
| 6820 | MVT::ValueType NewVT_Hi = MVT::getVectorType(NewEltVT, NewNumElts_Hi); |
| 6821 | |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6822 | // See if we already split it. |
| 6823 | std::map<SDOperand, std::pair<SDOperand, SDOperand> >::iterator I |
| 6824 | = SplitNodes.find(Op); |
| 6825 | if (I != SplitNodes.end()) { |
| 6826 | Lo = I->second.first; |
| 6827 | Hi = I->second.second; |
| 6828 | return; |
| 6829 | } |
| 6830 | |
| 6831 | switch (Node->getOpcode()) { |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 6832 | default: |
| 6833 | #ifndef NDEBUG |
Dan Gohman | 3983358 | 2007-06-04 16:17:33 +0000 | [diff] [blame] | 6834 | Node->dump(&DAG); |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 6835 | #endif |
| 6836 | assert(0 && "Unhandled operation in SplitVectorOp!"); |
Chris Lattner | daf9bc8 | 2007-11-19 20:21:32 +0000 | [diff] [blame] | 6837 | case ISD::UNDEF: |
| 6838 | Lo = DAG.getNode(ISD::UNDEF, NewVT_Lo); |
| 6839 | Hi = DAG.getNode(ISD::UNDEF, NewVT_Hi); |
| 6840 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6841 | case ISD::BUILD_PAIR: |
| 6842 | Lo = Node->getOperand(0); |
| 6843 | Hi = Node->getOperand(1); |
| 6844 | break; |
Dan Gohman | 9fe4662 | 2007-09-28 23:53:40 +0000 | [diff] [blame] | 6845 | case ISD::INSERT_VECTOR_ELT: { |
| 6846 | SplitVectorOp(Node->getOperand(0), Lo, Hi); |
| 6847 | unsigned Index = cast<ConstantSDNode>(Node->getOperand(2))->getValue(); |
| 6848 | SDOperand ScalarOp = Node->getOperand(1); |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 6849 | if (Index < NewNumElts_Lo) |
| 6850 | Lo = DAG.getNode(ISD::INSERT_VECTOR_ELT, NewVT_Lo, Lo, ScalarOp, |
Nate Begeman | 5922f56 | 2008-03-14 00:53:31 +0000 | [diff] [blame] | 6851 | DAG.getIntPtrConstant(Index)); |
Dan Gohman | 9fe4662 | 2007-09-28 23:53:40 +0000 | [diff] [blame] | 6852 | else |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 6853 | Hi = DAG.getNode(ISD::INSERT_VECTOR_ELT, NewVT_Hi, Hi, ScalarOp, |
Nate Begeman | 5922f56 | 2008-03-14 00:53:31 +0000 | [diff] [blame] | 6854 | DAG.getIntPtrConstant(Index - NewNumElts_Lo)); |
Dan Gohman | 9fe4662 | 2007-09-28 23:53:40 +0000 | [diff] [blame] | 6855 | break; |
| 6856 | } |
Chris Lattner | 6c9c680 | 2007-11-19 21:16:54 +0000 | [diff] [blame] | 6857 | case ISD::VECTOR_SHUFFLE: { |
| 6858 | // Build the low part. |
| 6859 | SDOperand Mask = Node->getOperand(2); |
| 6860 | SmallVector<SDOperand, 8> Ops; |
| 6861 | MVT::ValueType PtrVT = TLI.getPointerTy(); |
| 6862 | |
| 6863 | // Insert all of the elements from the input that are needed. We use |
| 6864 | // buildvector of extractelement here because the input vectors will have |
| 6865 | // to be legalized, so this makes the code simpler. |
| 6866 | for (unsigned i = 0; i != NewNumElts_Lo; ++i) { |
Nate Begeman | 5922f56 | 2008-03-14 00:53:31 +0000 | [diff] [blame] | 6867 | SDOperand IdxNode = Mask.getOperand(i); |
| 6868 | if (IdxNode.getOpcode() == ISD::UNDEF) { |
| 6869 | Ops.push_back(DAG.getNode(ISD::UNDEF, NewEltVT)); |
| 6870 | continue; |
| 6871 | } |
| 6872 | unsigned Idx = cast<ConstantSDNode>(IdxNode)->getValue(); |
Chris Lattner | 6c9c680 | 2007-11-19 21:16:54 +0000 | [diff] [blame] | 6873 | SDOperand InVec = Node->getOperand(0); |
| 6874 | if (Idx >= NumElements) { |
| 6875 | InVec = Node->getOperand(1); |
| 6876 | Idx -= NumElements; |
| 6877 | } |
| 6878 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, NewEltVT, InVec, |
| 6879 | DAG.getConstant(Idx, PtrVT))); |
| 6880 | } |
| 6881 | Lo = DAG.getNode(ISD::BUILD_VECTOR, NewVT_Lo, &Ops[0], Ops.size()); |
| 6882 | Ops.clear(); |
| 6883 | |
| 6884 | for (unsigned i = NewNumElts_Lo; i != NumElements; ++i) { |
Nate Begeman | 5922f56 | 2008-03-14 00:53:31 +0000 | [diff] [blame] | 6885 | SDOperand IdxNode = Mask.getOperand(i); |
| 6886 | if (IdxNode.getOpcode() == ISD::UNDEF) { |
| 6887 | Ops.push_back(DAG.getNode(ISD::UNDEF, NewEltVT)); |
| 6888 | continue; |
| 6889 | } |
| 6890 | unsigned Idx = cast<ConstantSDNode>(IdxNode)->getValue(); |
Chris Lattner | 6c9c680 | 2007-11-19 21:16:54 +0000 | [diff] [blame] | 6891 | SDOperand InVec = Node->getOperand(0); |
| 6892 | if (Idx >= NumElements) { |
| 6893 | InVec = Node->getOperand(1); |
| 6894 | Idx -= NumElements; |
| 6895 | } |
| 6896 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, NewEltVT, InVec, |
| 6897 | DAG.getConstant(Idx, PtrVT))); |
| 6898 | } |
| 6899 | Hi = DAG.getNode(ISD::BUILD_VECTOR, NewVT_Lo, &Ops[0], Ops.size()); |
| 6900 | break; |
| 6901 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6902 | case ISD::BUILD_VECTOR: { |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 6903 | SmallVector<SDOperand, 8> LoOps(Node->op_begin(), |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 6904 | Node->op_begin()+NewNumElts_Lo); |
| 6905 | Lo = DAG.getNode(ISD::BUILD_VECTOR, NewVT_Lo, &LoOps[0], LoOps.size()); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6906 | |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 6907 | SmallVector<SDOperand, 8> HiOps(Node->op_begin()+NewNumElts_Lo, |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6908 | Node->op_end()); |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 6909 | Hi = DAG.getNode(ISD::BUILD_VECTOR, NewVT_Hi, &HiOps[0], HiOps.size()); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6910 | break; |
| 6911 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6912 | case ISD::CONCAT_VECTORS: { |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 6913 | // FIXME: Handle non-power-of-two vectors? |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6914 | unsigned NewNumSubvectors = Node->getNumOperands() / 2; |
| 6915 | if (NewNumSubvectors == 1) { |
| 6916 | Lo = Node->getOperand(0); |
| 6917 | Hi = Node->getOperand(1); |
| 6918 | } else { |
| 6919 | SmallVector<SDOperand, 8> LoOps(Node->op_begin(), |
| 6920 | Node->op_begin()+NewNumSubvectors); |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 6921 | Lo = DAG.getNode(ISD::CONCAT_VECTORS, NewVT_Lo, &LoOps[0], LoOps.size()); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 6922 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6923 | SmallVector<SDOperand, 8> HiOps(Node->op_begin()+NewNumSubvectors, |
| 6924 | Node->op_end()); |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 6925 | Hi = DAG.getNode(ISD::CONCAT_VECTORS, NewVT_Hi, &HiOps[0], HiOps.size()); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6926 | } |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 6927 | break; |
| 6928 | } |
Dan Gohman | c623096 | 2007-10-17 14:48:28 +0000 | [diff] [blame] | 6929 | case ISD::SELECT: { |
| 6930 | SDOperand Cond = Node->getOperand(0); |
| 6931 | |
| 6932 | SDOperand LL, LH, RL, RH; |
| 6933 | SplitVectorOp(Node->getOperand(1), LL, LH); |
| 6934 | SplitVectorOp(Node->getOperand(2), RL, RH); |
| 6935 | |
| 6936 | if (MVT::isVector(Cond.getValueType())) { |
| 6937 | // Handle a vector merge. |
| 6938 | SDOperand CL, CH; |
| 6939 | SplitVectorOp(Cond, CL, CH); |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 6940 | Lo = DAG.getNode(Node->getOpcode(), NewVT_Lo, CL, LL, RL); |
| 6941 | Hi = DAG.getNode(Node->getOpcode(), NewVT_Hi, CH, LH, RH); |
Dan Gohman | c623096 | 2007-10-17 14:48:28 +0000 | [diff] [blame] | 6942 | } else { |
| 6943 | // Handle a simple select with vector operands. |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 6944 | Lo = DAG.getNode(Node->getOpcode(), NewVT_Lo, Cond, LL, RL); |
| 6945 | Hi = DAG.getNode(Node->getOpcode(), NewVT_Hi, Cond, LH, RH); |
Dan Gohman | c623096 | 2007-10-17 14:48:28 +0000 | [diff] [blame] | 6946 | } |
| 6947 | break; |
| 6948 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6949 | case ISD::ADD: |
| 6950 | case ISD::SUB: |
| 6951 | case ISD::MUL: |
| 6952 | case ISD::FADD: |
| 6953 | case ISD::FSUB: |
| 6954 | case ISD::FMUL: |
| 6955 | case ISD::SDIV: |
| 6956 | case ISD::UDIV: |
| 6957 | case ISD::FDIV: |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 6958 | case ISD::FPOW: |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 6959 | case ISD::AND: |
| 6960 | case ISD::OR: |
Dan Gohman | 089617d | 2007-11-19 15:15:03 +0000 | [diff] [blame] | 6961 | case ISD::XOR: |
| 6962 | case ISD::UREM: |
| 6963 | case ISD::SREM: |
| 6964 | case ISD::FREM: { |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6965 | SDOperand LL, LH, RL, RH; |
| 6966 | SplitVectorOp(Node->getOperand(0), LL, LH); |
| 6967 | SplitVectorOp(Node->getOperand(1), RL, RH); |
| 6968 | |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 6969 | Lo = DAG.getNode(Node->getOpcode(), NewVT_Lo, LL, RL); |
| 6970 | Hi = DAG.getNode(Node->getOpcode(), NewVT_Hi, LH, RH); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 6971 | break; |
| 6972 | } |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 6973 | case ISD::FPOWI: { |
| 6974 | SDOperand L, H; |
| 6975 | SplitVectorOp(Node->getOperand(0), L, H); |
| 6976 | |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 6977 | Lo = DAG.getNode(Node->getOpcode(), NewVT_Lo, L, Node->getOperand(1)); |
| 6978 | Hi = DAG.getNode(Node->getOpcode(), NewVT_Hi, H, Node->getOperand(1)); |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 6979 | break; |
| 6980 | } |
| 6981 | case ISD::CTTZ: |
| 6982 | case ISD::CTLZ: |
| 6983 | case ISD::CTPOP: |
| 6984 | case ISD::FNEG: |
| 6985 | case ISD::FABS: |
| 6986 | case ISD::FSQRT: |
| 6987 | case ISD::FSIN: |
Nate Begeman | b348d18 | 2007-11-17 03:58:34 +0000 | [diff] [blame] | 6988 | case ISD::FCOS: |
| 6989 | case ISD::FP_TO_SINT: |
| 6990 | case ISD::FP_TO_UINT: |
| 6991 | case ISD::SINT_TO_FP: |
| 6992 | case ISD::UINT_TO_FP: { |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 6993 | SDOperand L, H; |
| 6994 | SplitVectorOp(Node->getOperand(0), L, H); |
| 6995 | |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 6996 | Lo = DAG.getNode(Node->getOpcode(), NewVT_Lo, L); |
| 6997 | Hi = DAG.getNode(Node->getOpcode(), NewVT_Hi, H); |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 6998 | break; |
| 6999 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7000 | case ISD::LOAD: { |
| 7001 | LoadSDNode *LD = cast<LoadSDNode>(Node); |
| 7002 | SDOperand Ch = LD->getChain(); |
| 7003 | SDOperand Ptr = LD->getBasePtr(); |
| 7004 | const Value *SV = LD->getSrcValue(); |
| 7005 | int SVOffset = LD->getSrcValueOffset(); |
| 7006 | unsigned Alignment = LD->getAlignment(); |
| 7007 | bool isVolatile = LD->isVolatile(); |
| 7008 | |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7009 | Lo = DAG.getLoad(NewVT_Lo, Ch, Ptr, SV, SVOffset, isVolatile, Alignment); |
| 7010 | unsigned IncrementSize = NewNumElts_Lo * MVT::getSizeInBits(NewEltVT)/8; |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7011 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 7012 | DAG.getIntPtrConstant(IncrementSize)); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7013 | SVOffset += IncrementSize; |
Duncan Sands | dc84650 | 2007-10-28 12:59:45 +0000 | [diff] [blame] | 7014 | Alignment = MinAlign(Alignment, IncrementSize); |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7015 | Hi = DAG.getLoad(NewVT_Hi, Ch, Ptr, SV, SVOffset, isVolatile, Alignment); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7016 | |
| 7017 | // Build a factor node to remember that this load is independent of the |
| 7018 | // other one. |
| 7019 | SDOperand TF = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1), |
| 7020 | Hi.getValue(1)); |
| 7021 | |
| 7022 | // Remember that we legalized the chain. |
| 7023 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(TF)); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7024 | break; |
| 7025 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7026 | case ISD::BIT_CONVERT: { |
Chris Lattner | 7692eb4 | 2006-03-23 21:16:34 +0000 | [diff] [blame] | 7027 | // We know the result is a vector. The input may be either a vector or a |
| 7028 | // scalar value. |
Dan Gohman | 10a7aa6 | 2007-06-29 00:09:08 +0000 | [diff] [blame] | 7029 | SDOperand InOp = Node->getOperand(0); |
| 7030 | if (!MVT::isVector(InOp.getValueType()) || |
| 7031 | MVT::getVectorNumElements(InOp.getValueType()) == 1) { |
| 7032 | // The input is a scalar or single-element vector. |
| 7033 | // Lower to a store/load so that it can be split. |
| 7034 | // FIXME: this could be improved probably. |
Chris Lattner | 85dd3be | 2007-10-15 17:48:57 +0000 | [diff] [blame] | 7035 | SDOperand Ptr = DAG.CreateStackTemporary(InOp.getValueType()); |
Dan Gohman | bbbbb9c | 2008-02-11 18:58:42 +0000 | [diff] [blame] | 7036 | FrameIndexSDNode *FI = cast<FrameIndexSDNode>(Ptr.Val); |
Chris Lattner | 7692eb4 | 2006-03-23 21:16:34 +0000 | [diff] [blame] | 7037 | |
Evan Cheng | 786225a | 2006-10-05 23:01:46 +0000 | [diff] [blame] | 7038 | SDOperand St = DAG.getStore(DAG.getEntryNode(), |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 7039 | InOp, Ptr, |
Dan Gohman | 3069b87 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 7040 | PseudoSourceValue::getFixedStack(), |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 7041 | FI->getIndex()); |
| 7042 | InOp = DAG.getLoad(Op.getValueType(), St, Ptr, |
Dan Gohman | 3069b87 | 2008-02-07 18:41:25 +0000 | [diff] [blame] | 7043 | PseudoSourceValue::getFixedStack(), |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 7044 | FI->getIndex()); |
Chris Lattner | 7692eb4 | 2006-03-23 21:16:34 +0000 | [diff] [blame] | 7045 | } |
Dan Gohman | 10a7aa6 | 2007-06-29 00:09:08 +0000 | [diff] [blame] | 7046 | // Split the vector and convert each of the pieces now. |
| 7047 | SplitVectorOp(InOp, Lo, Hi); |
Nate Begeman | 5db1afb | 2007-11-15 21:15:26 +0000 | [diff] [blame] | 7048 | Lo = DAG.getNode(ISD::BIT_CONVERT, NewVT_Lo, Lo); |
| 7049 | Hi = DAG.getNode(ISD::BIT_CONVERT, NewVT_Hi, Hi); |
Dan Gohman | 10a7aa6 | 2007-06-29 00:09:08 +0000 | [diff] [blame] | 7050 | break; |
Chris Lattner | 7692eb4 | 2006-03-23 21:16:34 +0000 | [diff] [blame] | 7051 | } |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7052 | } |
| 7053 | |
| 7054 | // Remember in a map if the values will be reused later. |
Chris Lattner | 40030bf | 2007-02-04 01:17:38 +0000 | [diff] [blame] | 7055 | bool isNew = |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7056 | SplitNodes.insert(std::make_pair(Op, std::make_pair(Lo, Hi))).second; |
Dan Gohman | 10a7aa6 | 2007-06-29 00:09:08 +0000 | [diff] [blame] | 7057 | assert(isNew && "Value already split?!?"); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7058 | } |
| 7059 | |
| 7060 | |
Dan Gohman | 89b20c0 | 2007-06-27 14:06:22 +0000 | [diff] [blame] | 7061 | /// ScalarizeVectorOp - Given an operand of single-element vector type |
| 7062 | /// (e.g. v1f32), convert it into the equivalent operation that returns a |
| 7063 | /// scalar (e.g. f32) value. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7064 | SDOperand SelectionDAGLegalize::ScalarizeVectorOp(SDOperand Op) { |
| 7065 | assert(MVT::isVector(Op.getValueType()) && |
| 7066 | "Bad ScalarizeVectorOp invocation!"); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7067 | SDNode *Node = Op.Val; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7068 | MVT::ValueType NewVT = MVT::getVectorElementType(Op.getValueType()); |
| 7069 | assert(MVT::getVectorNumElements(Op.getValueType()) == 1); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7070 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7071 | // See if we already scalarized it. |
| 7072 | std::map<SDOperand, SDOperand>::iterator I = ScalarizedNodes.find(Op); |
| 7073 | if (I != ScalarizedNodes.end()) return I->second; |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7074 | |
| 7075 | SDOperand Result; |
| 7076 | switch (Node->getOpcode()) { |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 7077 | default: |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 7078 | #ifndef NDEBUG |
Dan Gohman | 3983358 | 2007-06-04 16:17:33 +0000 | [diff] [blame] | 7079 | Node->dump(&DAG); cerr << "\n"; |
Jim Laskey | e37fe9b | 2006-07-11 17:58:07 +0000 | [diff] [blame] | 7080 | #endif |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7081 | assert(0 && "Unknown vector operation in ScalarizeVectorOp!"); |
| 7082 | case ISD::ADD: |
| 7083 | case ISD::FADD: |
| 7084 | case ISD::SUB: |
| 7085 | case ISD::FSUB: |
| 7086 | case ISD::MUL: |
| 7087 | case ISD::FMUL: |
| 7088 | case ISD::SDIV: |
| 7089 | case ISD::UDIV: |
| 7090 | case ISD::FDIV: |
| 7091 | case ISD::SREM: |
| 7092 | case ISD::UREM: |
| 7093 | case ISD::FREM: |
Dan Gohman | 8266952 | 2007-10-11 23:57:53 +0000 | [diff] [blame] | 7094 | case ISD::FPOW: |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7095 | case ISD::AND: |
| 7096 | case ISD::OR: |
| 7097 | case ISD::XOR: |
| 7098 | Result = DAG.getNode(Node->getOpcode(), |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7099 | NewVT, |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7100 | ScalarizeVectorOp(Node->getOperand(0)), |
| 7101 | ScalarizeVectorOp(Node->getOperand(1))); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7102 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7103 | case ISD::FNEG: |
| 7104 | case ISD::FABS: |
| 7105 | case ISD::FSQRT: |
| 7106 | case ISD::FSIN: |
| 7107 | case ISD::FCOS: |
| 7108 | Result = DAG.getNode(Node->getOpcode(), |
| 7109 | NewVT, |
| 7110 | ScalarizeVectorOp(Node->getOperand(0))); |
| 7111 | break; |
Dan Gohman | 9e04c82 | 2007-10-12 14:13:46 +0000 | [diff] [blame] | 7112 | case ISD::FPOWI: |
| 7113 | Result = DAG.getNode(Node->getOpcode(), |
| 7114 | NewVT, |
| 7115 | ScalarizeVectorOp(Node->getOperand(0)), |
| 7116 | Node->getOperand(1)); |
| 7117 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7118 | case ISD::LOAD: { |
| 7119 | LoadSDNode *LD = cast<LoadSDNode>(Node); |
| 7120 | SDOperand Ch = LegalizeOp(LD->getChain()); // Legalize the chain. |
| 7121 | SDOperand Ptr = LegalizeOp(LD->getBasePtr()); // Legalize the pointer. |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7122 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7123 | const Value *SV = LD->getSrcValue(); |
| 7124 | int SVOffset = LD->getSrcValueOffset(); |
| 7125 | Result = DAG.getLoad(NewVT, Ch, Ptr, SV, SVOffset, |
| 7126 | LD->isVolatile(), LD->getAlignment()); |
| 7127 | |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7128 | // Remember that we legalized the chain. |
| 7129 | AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1))); |
| 7130 | break; |
| 7131 | } |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7132 | case ISD::BUILD_VECTOR: |
| 7133 | Result = Node->getOperand(0); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7134 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7135 | case ISD::INSERT_VECTOR_ELT: |
| 7136 | // Returning the inserted scalar element. |
| 7137 | Result = Node->getOperand(1); |
| 7138 | break; |
| 7139 | case ISD::CONCAT_VECTORS: |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 7140 | assert(Node->getOperand(0).getValueType() == NewVT && |
| 7141 | "Concat of non-legal vectors not yet supported!"); |
| 7142 | Result = Node->getOperand(0); |
| 7143 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7144 | case ISD::VECTOR_SHUFFLE: { |
| 7145 | // Figure out if the scalar is the LHS or RHS and return it. |
| 7146 | SDOperand EltNum = Node->getOperand(2).getOperand(0); |
| 7147 | if (cast<ConstantSDNode>(EltNum)->getValue()) |
| 7148 | Result = ScalarizeVectorOp(Node->getOperand(1)); |
| 7149 | else |
| 7150 | Result = ScalarizeVectorOp(Node->getOperand(0)); |
Chris Lattner | 2332b9f | 2006-03-19 01:17:20 +0000 | [diff] [blame] | 7151 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7152 | } |
| 7153 | case ISD::EXTRACT_SUBVECTOR: |
| 7154 | Result = Node->getOperand(0); |
Dan Gohman | 6595635 | 2007-06-13 15:12:02 +0000 | [diff] [blame] | 7155 | assert(Result.getValueType() == NewVT); |
| 7156 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7157 | case ISD::BIT_CONVERT: |
| 7158 | Result = DAG.getNode(ISD::BIT_CONVERT, NewVT, Op.getOperand(0)); |
Chris Lattner | 5b2316e | 2006-03-28 20:24:43 +0000 | [diff] [blame] | 7159 | break; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7160 | case ISD::SELECT: |
Chris Lattner | b22e35a | 2006-04-08 22:22:57 +0000 | [diff] [blame] | 7161 | Result = DAG.getNode(ISD::SELECT, NewVT, Op.getOperand(0), |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7162 | ScalarizeVectorOp(Op.getOperand(1)), |
| 7163 | ScalarizeVectorOp(Op.getOperand(2))); |
Chris Lattner | b22e35a | 2006-04-08 22:22:57 +0000 | [diff] [blame] | 7164 | break; |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7165 | } |
| 7166 | |
| 7167 | if (TLI.isTypeLegal(NewVT)) |
| 7168 | Result = LegalizeOp(Result); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 7169 | bool isNew = ScalarizedNodes.insert(std::make_pair(Op, Result)).second; |
| 7170 | assert(isNew && "Value already scalarized?"); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 7171 | return Result; |
| 7172 | } |
| 7173 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 7174 | |
| 7175 | // SelectionDAG::Legalize - This is the entry point for the file. |
| 7176 | // |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 7177 | void SelectionDAG::Legalize() { |
Chris Lattner | 5e46a19 | 2006-04-02 03:07:27 +0000 | [diff] [blame] | 7178 | if (ViewLegalizeDAGs) viewGraph(); |
| 7179 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 7180 | /// run - This is the main entry point to this class. |
| 7181 | /// |
Chris Lattner | 456a93a | 2006-01-28 07:39:30 +0000 | [diff] [blame] | 7182 | SelectionDAGLegalize(*this).LegalizeDAG(); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 7183 | } |
| 7184 | |