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 | // |
| 5 | // This file was developed by the LLVM research group and is distributed under |
| 6 | // the University of Illinois Open Source 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 | 02659d2 | 2005-08-17 17:42:52 +0000 | [diff] [blame] | 17 | #include "llvm/Support/MathExtras.h" |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 18 | #include "llvm/Target/TargetLowering.h" |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 19 | #include "llvm/Target/TargetData.h" |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 20 | #include "llvm/Target/TargetOptions.h" |
Chris Lattner | adf6a96 | 2005-05-13 18:50:42 +0000 | [diff] [blame] | 21 | #include "llvm/CallingConv.h" |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 22 | #include "llvm/Constants.h" |
| 23 | #include <iostream> |
Chris Lattner | 82299e7 | 2005-08-05 18:10:27 +0000 | [diff] [blame] | 24 | #include <set> |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 25 | using namespace llvm; |
| 26 | |
| 27 | //===----------------------------------------------------------------------===// |
| 28 | /// SelectionDAGLegalize - This takes an arbitrary SelectionDAG as input and |
| 29 | /// hacks on it until the target machine can handle it. This involves |
| 30 | /// eliminating value sizes the machine cannot handle (promoting small sizes to |
| 31 | /// large sizes or splitting up large values into small values) as well as |
| 32 | /// eliminating operations the machine cannot handle. |
| 33 | /// |
| 34 | /// This code also does a small amount of optimization and recognition of idioms |
| 35 | /// as part of its processing. For example, if a target does not support a |
| 36 | /// 'setcc' instruction efficiently, but does support 'brcc' instruction, this |
| 37 | /// will attempt merge setcc and brc instructions into brcc's. |
| 38 | /// |
| 39 | namespace { |
| 40 | class SelectionDAGLegalize { |
| 41 | TargetLowering &TLI; |
| 42 | SelectionDAG &DAG; |
| 43 | |
| 44 | /// LegalizeAction - This enum indicates what action we should take for each |
| 45 | /// value type the can occur in the program. |
| 46 | enum LegalizeAction { |
| 47 | Legal, // The target natively supports this value type. |
| 48 | Promote, // This should be promoted to the next larger type. |
| 49 | Expand, // This integer type should be broken into smaller pieces. |
| 50 | }; |
| 51 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 52 | /// ValueTypeActions - This is a bitvector that contains two bits for each |
| 53 | /// value type, where the two bits correspond to the LegalizeAction enum. |
| 54 | /// This can be queried with "getTypeAction(VT)". |
Nate Begeman | 6a64861 | 2005-11-29 05:45:29 +0000 | [diff] [blame] | 55 | unsigned long long ValueTypeActions; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 56 | |
| 57 | /// NeedsAnotherIteration - This is set when we expand a large integer |
| 58 | /// operation into smaller integer operations, but the smaller operations are |
| 59 | /// not set. This occurs only rarely in practice, for targets that don't have |
| 60 | /// 32-bit or larger integer registers. |
| 61 | bool NeedsAnotherIteration; |
| 62 | |
| 63 | /// LegalizedNodes - For nodes that are of legal width, and that have more |
| 64 | /// than one use, this map indicates what regularized operand to use. This |
| 65 | /// allows us to avoid legalizing the same thing more than once. |
| 66 | std::map<SDOperand, SDOperand> LegalizedNodes; |
| 67 | |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 68 | /// PromotedNodes - For nodes that are below legal width, and that have more |
| 69 | /// than one use, this map indicates what promoted value to use. This allows |
| 70 | /// us to avoid promoting the same thing more than once. |
| 71 | std::map<SDOperand, SDOperand> PromotedNodes; |
| 72 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 73 | /// ExpandedNodes - For nodes that need to be expanded, and which have more |
| 74 | /// than one use, this map indicates which which operands are the expanded |
| 75 | /// version of the input. This allows us to avoid expanding the same node |
| 76 | /// more than once. |
| 77 | std::map<SDOperand, std::pair<SDOperand, SDOperand> > ExpandedNodes; |
| 78 | |
Chris Lattner | 8afc48e | 2005-01-07 22:28:47 +0000 | [diff] [blame] | 79 | void AddLegalizedOperand(SDOperand From, SDOperand To) { |
Chris Lattner | 69a889e | 2005-12-20 00:53:54 +0000 | [diff] [blame] | 80 | LegalizedNodes.insert(std::make_pair(From, To)); |
| 81 | // If someone requests legalization of the new node, return itself. |
| 82 | if (From != To) |
| 83 | LegalizedNodes.insert(std::make_pair(To, To)); |
Chris Lattner | 8afc48e | 2005-01-07 22:28:47 +0000 | [diff] [blame] | 84 | } |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 85 | void AddPromotedOperand(SDOperand From, SDOperand To) { |
| 86 | bool isNew = PromotedNodes.insert(std::make_pair(From, To)).second; |
| 87 | assert(isNew && "Got into the map somehow?"); |
Chris Lattner | 69a889e | 2005-12-20 00:53:54 +0000 | [diff] [blame] | 88 | // If someone requests legalization of the new node, return itself. |
| 89 | LegalizedNodes.insert(std::make_pair(To, To)); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 90 | } |
Chris Lattner | 8afc48e | 2005-01-07 22:28:47 +0000 | [diff] [blame] | 91 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 92 | public: |
| 93 | |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 94 | SelectionDAGLegalize(SelectionDAG &DAG); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 95 | |
| 96 | /// Run - While there is still lowering to do, perform a pass over the DAG. |
| 97 | /// Most regularization can be done in a single pass, but targets that require |
| 98 | /// large values to be split into registers multiple times (e.g. i64 -> 4x |
| 99 | /// i16) require iteration for these values (the first iteration will demote |
| 100 | /// to i32, the second will demote to i16). |
| 101 | void Run() { |
| 102 | do { |
| 103 | NeedsAnotherIteration = false; |
| 104 | LegalizeDAG(); |
| 105 | } while (NeedsAnotherIteration); |
| 106 | } |
| 107 | |
| 108 | /// getTypeAction - Return how we should legalize values of this type, either |
| 109 | /// it is already legal or we need to expand it into multiple registers of |
| 110 | /// smaller integer type, or we need to promote it to a larger type. |
| 111 | LegalizeAction getTypeAction(MVT::ValueType VT) const { |
| 112 | return (LegalizeAction)((ValueTypeActions >> (2*VT)) & 3); |
| 113 | } |
| 114 | |
| 115 | /// isTypeLegal - Return true if this type is legal on this target. |
| 116 | /// |
| 117 | bool isTypeLegal(MVT::ValueType VT) const { |
| 118 | return getTypeAction(VT) == Legal; |
| 119 | } |
| 120 | |
| 121 | private: |
| 122 | void LegalizeDAG(); |
| 123 | |
| 124 | SDOperand LegalizeOp(SDOperand O); |
| 125 | void ExpandOp(SDOperand O, SDOperand &Lo, SDOperand &Hi); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 126 | SDOperand PromoteOp(SDOperand O); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 127 | |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 128 | SDOperand ExpandLibCall(const char *Name, SDNode *Node, |
| 129 | SDOperand &Hi); |
| 130 | SDOperand ExpandIntToFP(bool isSigned, MVT::ValueType DestTy, |
| 131 | SDOperand Source); |
Chris Lattner | cad063f | 2005-07-16 00:19:57 +0000 | [diff] [blame] | 132 | |
Jim Laskey | 6269ed1 | 2005-08-17 00:39:29 +0000 | [diff] [blame] | 133 | SDOperand ExpandLegalINT_TO_FP(bool isSigned, |
| 134 | SDOperand LegalOp, |
| 135 | MVT::ValueType DestVT); |
Nate Begeman | 5a8441e | 2005-07-16 02:02:34 +0000 | [diff] [blame] | 136 | SDOperand PromoteLegalINT_TO_FP(SDOperand LegalOp, MVT::ValueType DestVT, |
| 137 | bool isSigned); |
Chris Lattner | 1618beb | 2005-07-29 00:11:56 +0000 | [diff] [blame] | 138 | SDOperand PromoteLegalFP_TO_INT(SDOperand LegalOp, MVT::ValueType DestVT, |
| 139 | bool isSigned); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 140 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 141 | bool ExpandShift(unsigned Opc, SDOperand Op, SDOperand Amt, |
| 142 | SDOperand &Lo, SDOperand &Hi); |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 143 | void ExpandShiftParts(unsigned NodeOp, SDOperand Op, SDOperand Amt, |
| 144 | SDOperand &Lo, SDOperand &Hi); |
| 145 | void ExpandByParts(unsigned NodeOp, SDOperand LHS, SDOperand RHS, |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 146 | SDOperand &Lo, SDOperand &Hi); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 147 | |
Chris Lattner | b9fa3bc | 2005-05-12 04:49:08 +0000 | [diff] [blame] | 148 | void SpliceCallInto(const SDOperand &CallResult, SDNode *OutChain); |
| 149 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 150 | SDOperand getIntPtrConstant(uint64_t Val) { |
| 151 | return DAG.getConstant(Val, TLI.getPointerTy()); |
| 152 | } |
| 153 | }; |
| 154 | } |
| 155 | |
Chris Lattner | b89175f | 2005-11-19 05:51:46 +0000 | [diff] [blame] | 156 | static unsigned getScalarizedOpcode(unsigned VecOp, MVT::ValueType VT) { |
Nate Begeman | 5fbb5d2 | 2005-11-19 00:36:38 +0000 | [diff] [blame] | 157 | switch (VecOp) { |
| 158 | default: assert(0 && "Don't know how to scalarize this opcode!"); |
Nate Begeman | 5fbb5d2 | 2005-11-19 00:36:38 +0000 | [diff] [blame] | 159 | case ISD::VADD: return MVT::isInteger(VT) ? ISD::ADD : ISD::FADD; |
| 160 | case ISD::VSUB: return MVT::isInteger(VT) ? ISD::SUB : ISD::FSUB; |
| 161 | case ISD::VMUL: return MVT::isInteger(VT) ? ISD::MUL : ISD::FMUL; |
| 162 | } |
| 163 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 164 | |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 165 | SelectionDAGLegalize::SelectionDAGLegalize(SelectionDAG &dag) |
| 166 | : TLI(dag.getTargetLoweringInfo()), DAG(dag), |
| 167 | ValueTypeActions(TLI.getValueTypeActions()) { |
Nate Begeman | 6a64861 | 2005-11-29 05:45:29 +0000 | [diff] [blame] | 168 | assert(MVT::LAST_VALUETYPE <= 32 && |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 169 | "Too many value types for ValueTypeActions to hold!"); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 170 | } |
| 171 | |
Jim Laskey | 6269ed1 | 2005-08-17 00:39:29 +0000 | [diff] [blame] | 172 | /// ExpandLegalINT_TO_FP - This function is responsible for legalizing a |
| 173 | /// INT_TO_FP operation of the specified operand when the target requests that |
Chris Lattner | cad063f | 2005-07-16 00:19:57 +0000 | [diff] [blame] | 174 | /// we expand it. At this point, we know that the result and operand types are |
| 175 | /// legal for the target. |
Jim Laskey | 6269ed1 | 2005-08-17 00:39:29 +0000 | [diff] [blame] | 176 | SDOperand SelectionDAGLegalize::ExpandLegalINT_TO_FP(bool isSigned, |
| 177 | SDOperand Op0, |
| 178 | MVT::ValueType DestVT) { |
| 179 | if (Op0.getValueType() == MVT::i32) { |
| 180 | // simple 32-bit [signed|unsigned] integer to float/double expansion |
| 181 | |
| 182 | // get the stack frame index of a 8 byte buffer |
| 183 | MachineFunction &MF = DAG.getMachineFunction(); |
| 184 | int SSFI = MF.getFrameInfo()->CreateStackObject(8, 8); |
| 185 | // get address of 8 byte buffer |
| 186 | SDOperand StackSlot = DAG.getFrameIndex(SSFI, TLI.getPointerTy()); |
| 187 | // word offset constant for Hi/Lo address computation |
| 188 | SDOperand WordOff = DAG.getConstant(sizeof(int), TLI.getPointerTy()); |
| 189 | // set up Hi and Lo (into buffer) address based on endian |
| 190 | SDOperand Hi, Lo; |
| 191 | if (TLI.isLittleEndian()) { |
| 192 | Hi = DAG.getNode(ISD::ADD, TLI.getPointerTy(), StackSlot, WordOff); |
| 193 | Lo = StackSlot; |
| 194 | } else { |
| 195 | Hi = StackSlot; |
| 196 | Lo = DAG.getNode(ISD::ADD, TLI.getPointerTy(), StackSlot, WordOff); |
| 197 | } |
| 198 | // if signed map to unsigned space |
| 199 | SDOperand Op0Mapped; |
| 200 | if (isSigned) { |
| 201 | // constant used to invert sign bit (signed to unsigned mapping) |
| 202 | SDOperand SignBit = DAG.getConstant(0x80000000u, MVT::i32); |
| 203 | Op0Mapped = DAG.getNode(ISD::XOR, MVT::i32, Op0, SignBit); |
| 204 | } else { |
| 205 | Op0Mapped = Op0; |
| 206 | } |
| 207 | // store the lo of the constructed double - based on integer input |
| 208 | SDOperand Store1 = DAG.getNode(ISD::STORE, MVT::Other, DAG.getEntryNode(), |
| 209 | Op0Mapped, Lo, DAG.getSrcValue(NULL)); |
| 210 | // initial hi portion of constructed double |
| 211 | SDOperand InitialHi = DAG.getConstant(0x43300000u, MVT::i32); |
| 212 | // store the hi of the constructed double - biased exponent |
| 213 | SDOperand Store2 = DAG.getNode(ISD::STORE, MVT::Other, Store1, |
| 214 | InitialHi, Hi, DAG.getSrcValue(NULL)); |
| 215 | // load the constructed double |
| 216 | SDOperand Load = DAG.getLoad(MVT::f64, Store2, StackSlot, |
| 217 | DAG.getSrcValue(NULL)); |
| 218 | // FP constant to bias correct the final result |
Jim Laskey | 02659d2 | 2005-08-17 17:42:52 +0000 | [diff] [blame] | 219 | SDOperand Bias = DAG.getConstantFP(isSigned ? |
| 220 | BitsToDouble(0x4330000080000000ULL) |
| 221 | : BitsToDouble(0x4330000000000000ULL), |
Jim Laskey | 6269ed1 | 2005-08-17 00:39:29 +0000 | [diff] [blame] | 222 | MVT::f64); |
| 223 | // subtract the bias |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 224 | SDOperand Sub = DAG.getNode(ISD::FSUB, MVT::f64, Load, Bias); |
Jim Laskey | 6269ed1 | 2005-08-17 00:39:29 +0000 | [diff] [blame] | 225 | // final result |
| 226 | SDOperand Result; |
| 227 | // handle final rounding |
| 228 | if (DestVT == MVT::f64) { |
| 229 | // do nothing |
| 230 | Result = Sub; |
| 231 | } else { |
| 232 | // if f32 then cast to f32 |
| 233 | Result = DAG.getNode(ISD::FP_ROUND, MVT::f32, Sub); |
| 234 | } |
Chris Lattner | 69a889e | 2005-12-20 00:53:54 +0000 | [diff] [blame] | 235 | return LegalizeOp(Result); |
Jim Laskey | 6269ed1 | 2005-08-17 00:39:29 +0000 | [diff] [blame] | 236 | } |
| 237 | assert(!isSigned && "Legalize cannot Expand SINT_TO_FP for i64 yet"); |
Chris Lattner | cad063f | 2005-07-16 00:19:57 +0000 | [diff] [blame] | 238 | SDOperand Tmp1 = DAG.getNode(ISD::SINT_TO_FP, DestVT, Op0); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 239 | |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 240 | SDOperand SignSet = DAG.getSetCC(TLI.getSetCCResultTy(), Op0, |
| 241 | DAG.getConstant(0, Op0.getValueType()), |
| 242 | ISD::SETLT); |
Chris Lattner | cad063f | 2005-07-16 00:19:57 +0000 | [diff] [blame] | 243 | SDOperand Zero = getIntPtrConstant(0), Four = getIntPtrConstant(4); |
| 244 | SDOperand CstOffset = DAG.getNode(ISD::SELECT, Zero.getValueType(), |
| 245 | SignSet, Four, Zero); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 246 | |
Jim Laskey | 6269ed1 | 2005-08-17 00:39:29 +0000 | [diff] [blame] | 247 | // If the sign bit of the integer is set, the large number will be treated |
| 248 | // as a negative number. To counteract this, the dynamic code adds an |
| 249 | // offset depending on the data type. |
Chris Lattner | f4d3272 | 2005-07-18 04:31:14 +0000 | [diff] [blame] | 250 | uint64_t FF; |
| 251 | switch (Op0.getValueType()) { |
| 252 | default: assert(0 && "Unsupported integer type!"); |
| 253 | case MVT::i8 : FF = 0x43800000ULL; break; // 2^8 (as a float) |
| 254 | case MVT::i16: FF = 0x47800000ULL; break; // 2^16 (as a float) |
| 255 | case MVT::i32: FF = 0x4F800000ULL; break; // 2^32 (as a float) |
| 256 | case MVT::i64: FF = 0x5F800000ULL; break; // 2^64 (as a float) |
| 257 | } |
Chris Lattner | cad063f | 2005-07-16 00:19:57 +0000 | [diff] [blame] | 258 | if (TLI.isLittleEndian()) FF <<= 32; |
| 259 | static Constant *FudgeFactor = ConstantUInt::get(Type::ULongTy, FF); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 260 | |
Chris Lattner | 5839bf2 | 2005-08-26 17:15:30 +0000 | [diff] [blame] | 261 | SDOperand CPIdx = DAG.getConstantPool(FudgeFactor, TLI.getPointerTy()); |
Chris Lattner | cad063f | 2005-07-16 00:19:57 +0000 | [diff] [blame] | 262 | CPIdx = DAG.getNode(ISD::ADD, TLI.getPointerTy(), CPIdx, CstOffset); |
| 263 | SDOperand FudgeInReg; |
| 264 | if (DestVT == MVT::f32) |
| 265 | FudgeInReg = DAG.getLoad(MVT::f32, DAG.getEntryNode(), CPIdx, |
| 266 | DAG.getSrcValue(NULL)); |
| 267 | else { |
| 268 | assert(DestVT == MVT::f64 && "Unexpected conversion"); |
| 269 | FudgeInReg = LegalizeOp(DAG.getExtLoad(ISD::EXTLOAD, MVT::f64, |
| 270 | DAG.getEntryNode(), CPIdx, |
| 271 | DAG.getSrcValue(NULL), MVT::f32)); |
| 272 | } |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 273 | |
Chris Lattner | 69a889e | 2005-12-20 00:53:54 +0000 | [diff] [blame] | 274 | return LegalizeOp(DAG.getNode(ISD::FADD, DestVT, Tmp1, FudgeInReg)); |
Chris Lattner | cad063f | 2005-07-16 00:19:57 +0000 | [diff] [blame] | 275 | } |
| 276 | |
Chris Lattner | 149c58c | 2005-08-16 18:17:10 +0000 | [diff] [blame] | 277 | /// PromoteLegalINT_TO_FP - This function is responsible for legalizing a |
Chris Lattner | 1618beb | 2005-07-29 00:11:56 +0000 | [diff] [blame] | 278 | /// *INT_TO_FP operation of the specified operand when the target requests that |
Chris Lattner | cad063f | 2005-07-16 00:19:57 +0000 | [diff] [blame] | 279 | /// we promote it. At this point, we know that the result and operand types are |
| 280 | /// legal for the target, and that there is a legal UINT_TO_FP or SINT_TO_FP |
| 281 | /// operation that takes a larger input. |
Nate Begeman | 5a8441e | 2005-07-16 02:02:34 +0000 | [diff] [blame] | 282 | SDOperand SelectionDAGLegalize::PromoteLegalINT_TO_FP(SDOperand LegalOp, |
| 283 | MVT::ValueType DestVT, |
| 284 | bool isSigned) { |
Chris Lattner | cad063f | 2005-07-16 00:19:57 +0000 | [diff] [blame] | 285 | // First step, figure out the appropriate *INT_TO_FP operation to use. |
| 286 | MVT::ValueType NewInTy = LegalOp.getValueType(); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 287 | |
Chris Lattner | cad063f | 2005-07-16 00:19:57 +0000 | [diff] [blame] | 288 | unsigned OpToUse = 0; |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 289 | |
Chris Lattner | cad063f | 2005-07-16 00:19:57 +0000 | [diff] [blame] | 290 | // Scan for the appropriate larger type to use. |
| 291 | while (1) { |
| 292 | NewInTy = (MVT::ValueType)(NewInTy+1); |
| 293 | assert(MVT::isInteger(NewInTy) && "Ran out of possibilities!"); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 294 | |
Chris Lattner | cad063f | 2005-07-16 00:19:57 +0000 | [diff] [blame] | 295 | // If the target supports SINT_TO_FP of this type, use it. |
| 296 | switch (TLI.getOperationAction(ISD::SINT_TO_FP, NewInTy)) { |
| 297 | default: break; |
| 298 | case TargetLowering::Legal: |
Chris Lattner | c9c60f6 | 2005-08-24 16:35:28 +0000 | [diff] [blame] | 299 | if (!TLI.isTypeLegal(NewInTy)) |
Chris Lattner | cad063f | 2005-07-16 00:19:57 +0000 | [diff] [blame] | 300 | break; // Can't use this datatype. |
| 301 | // FALL THROUGH. |
| 302 | case TargetLowering::Custom: |
| 303 | OpToUse = ISD::SINT_TO_FP; |
| 304 | break; |
| 305 | } |
| 306 | if (OpToUse) break; |
Nate Begeman | 5a8441e | 2005-07-16 02:02:34 +0000 | [diff] [blame] | 307 | if (isSigned) continue; |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 308 | |
Chris Lattner | cad063f | 2005-07-16 00:19:57 +0000 | [diff] [blame] | 309 | // If the target supports UINT_TO_FP of this type, use it. |
| 310 | switch (TLI.getOperationAction(ISD::UINT_TO_FP, NewInTy)) { |
| 311 | default: break; |
| 312 | case TargetLowering::Legal: |
Chris Lattner | c9c60f6 | 2005-08-24 16:35:28 +0000 | [diff] [blame] | 313 | if (!TLI.isTypeLegal(NewInTy)) |
Chris Lattner | cad063f | 2005-07-16 00:19:57 +0000 | [diff] [blame] | 314 | break; // Can't use this datatype. |
| 315 | // FALL THROUGH. |
| 316 | case TargetLowering::Custom: |
| 317 | OpToUse = ISD::UINT_TO_FP; |
| 318 | break; |
| 319 | } |
| 320 | if (OpToUse) break; |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 321 | |
Chris Lattner | cad063f | 2005-07-16 00:19:57 +0000 | [diff] [blame] | 322 | // Otherwise, try a larger type. |
| 323 | } |
| 324 | |
Chris Lattner | cad063f | 2005-07-16 00:19:57 +0000 | [diff] [blame] | 325 | // Okay, we found the operation and type to use. Zero extend our input to the |
| 326 | // desired type then run the operation on it. |
Chris Lattner | 69a889e | 2005-12-20 00:53:54 +0000 | [diff] [blame] | 327 | SDOperand N = DAG.getNode(OpToUse, DestVT, |
Nate Begeman | 5a8441e | 2005-07-16 02:02:34 +0000 | [diff] [blame] | 328 | DAG.getNode(isSigned ? ISD::SIGN_EXTEND : ISD::ZERO_EXTEND, |
| 329 | NewInTy, LegalOp)); |
Chris Lattner | 69a889e | 2005-12-20 00:53:54 +0000 | [diff] [blame] | 330 | // Make sure to legalize any nodes we create here. |
| 331 | return LegalizeOp(N); |
Chris Lattner | cad063f | 2005-07-16 00:19:57 +0000 | [diff] [blame] | 332 | } |
| 333 | |
Chris Lattner | 1618beb | 2005-07-29 00:11:56 +0000 | [diff] [blame] | 334 | /// PromoteLegalFP_TO_INT - This function is responsible for legalizing a |
| 335 | /// FP_TO_*INT operation of the specified operand when the target requests that |
| 336 | /// we promote it. At this point, we know that the result and operand types are |
| 337 | /// legal for the target, and that there is a legal FP_TO_UINT or FP_TO_SINT |
| 338 | /// operation that returns a larger result. |
| 339 | SDOperand SelectionDAGLegalize::PromoteLegalFP_TO_INT(SDOperand LegalOp, |
| 340 | MVT::ValueType DestVT, |
| 341 | bool isSigned) { |
| 342 | // First step, figure out the appropriate FP_TO*INT operation to use. |
| 343 | MVT::ValueType NewOutTy = DestVT; |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 344 | |
Chris Lattner | 1618beb | 2005-07-29 00:11:56 +0000 | [diff] [blame] | 345 | unsigned OpToUse = 0; |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 346 | |
Chris Lattner | 1618beb | 2005-07-29 00:11:56 +0000 | [diff] [blame] | 347 | // Scan for the appropriate larger type to use. |
| 348 | while (1) { |
| 349 | NewOutTy = (MVT::ValueType)(NewOutTy+1); |
| 350 | assert(MVT::isInteger(NewOutTy) && "Ran out of possibilities!"); |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 351 | |
Chris Lattner | 1618beb | 2005-07-29 00:11:56 +0000 | [diff] [blame] | 352 | // If the target supports FP_TO_SINT returning this type, use it. |
| 353 | switch (TLI.getOperationAction(ISD::FP_TO_SINT, NewOutTy)) { |
| 354 | default: break; |
| 355 | case TargetLowering::Legal: |
Chris Lattner | c9c60f6 | 2005-08-24 16:35:28 +0000 | [diff] [blame] | 356 | if (!TLI.isTypeLegal(NewOutTy)) |
Chris Lattner | 1618beb | 2005-07-29 00:11:56 +0000 | [diff] [blame] | 357 | break; // Can't use this datatype. |
| 358 | // FALL THROUGH. |
| 359 | case TargetLowering::Custom: |
| 360 | OpToUse = ISD::FP_TO_SINT; |
| 361 | break; |
| 362 | } |
| 363 | if (OpToUse) break; |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 364 | |
Chris Lattner | 1618beb | 2005-07-29 00:11:56 +0000 | [diff] [blame] | 365 | // If the target supports FP_TO_UINT of this type, use it. |
| 366 | switch (TLI.getOperationAction(ISD::FP_TO_UINT, NewOutTy)) { |
| 367 | default: break; |
| 368 | case TargetLowering::Legal: |
Chris Lattner | c9c60f6 | 2005-08-24 16:35:28 +0000 | [diff] [blame] | 369 | if (!TLI.isTypeLegal(NewOutTy)) |
Chris Lattner | 1618beb | 2005-07-29 00:11:56 +0000 | [diff] [blame] | 370 | break; // Can't use this datatype. |
| 371 | // FALL THROUGH. |
| 372 | case TargetLowering::Custom: |
| 373 | OpToUse = ISD::FP_TO_UINT; |
| 374 | break; |
| 375 | } |
| 376 | if (OpToUse) break; |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 377 | |
Chris Lattner | 1618beb | 2005-07-29 00:11:56 +0000 | [diff] [blame] | 378 | // Otherwise, try a larger type. |
| 379 | } |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 380 | |
Chris Lattner | 1618beb | 2005-07-29 00:11:56 +0000 | [diff] [blame] | 381 | // Okay, we found the operation and type to use. Truncate the result of the |
| 382 | // extended FP_TO_*INT operation to the desired size. |
Chris Lattner | 69a889e | 2005-12-20 00:53:54 +0000 | [diff] [blame] | 383 | SDOperand N = DAG.getNode(ISD::TRUNCATE, DestVT, |
| 384 | DAG.getNode(OpToUse, NewOutTy, LegalOp)); |
| 385 | // Make sure to legalize any nodes we create here in the next pass. |
| 386 | return LegalizeOp(N); |
Chris Lattner | 1618beb | 2005-07-29 00:11:56 +0000 | [diff] [blame] | 387 | } |
| 388 | |
Chris Lattner | 32fca00 | 2005-10-06 01:20:27 +0000 | [diff] [blame] | 389 | /// ComputeTopDownOrdering - Add the specified node to the Order list if it has |
| 390 | /// not been visited yet and if all of its operands have already been visited. |
| 391 | static void ComputeTopDownOrdering(SDNode *N, std::vector<SDNode*> &Order, |
| 392 | std::map<SDNode*, unsigned> &Visited) { |
| 393 | if (++Visited[N] != N->getNumOperands()) |
| 394 | return; // Haven't visited all operands yet |
| 395 | |
| 396 | Order.push_back(N); |
| 397 | |
| 398 | if (N->hasOneUse()) { // Tail recurse in common case. |
| 399 | ComputeTopDownOrdering(*N->use_begin(), Order, Visited); |
| 400 | return; |
| 401 | } |
| 402 | |
| 403 | // Now that we have N in, add anything that uses it if all of their operands |
| 404 | // are now done. |
Chris Lattner | 32fca00 | 2005-10-06 01:20:27 +0000 | [diff] [blame] | 405 | for (SDNode::use_iterator UI = N->use_begin(), E = N->use_end(); UI != E;++UI) |
| 406 | ComputeTopDownOrdering(*UI, Order, Visited); |
| 407 | } |
| 408 | |
Chris Lattner | 1618beb | 2005-07-29 00:11:56 +0000 | [diff] [blame] | 409 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 410 | void SelectionDAGLegalize::LegalizeDAG() { |
Chris Lattner | ab510a7 | 2005-10-02 17:49:46 +0000 | [diff] [blame] | 411 | // The legalize process is inherently a bottom-up recursive process (users |
| 412 | // legalize their uses before themselves). Given infinite stack space, we |
| 413 | // could just start legalizing on the root and traverse the whole graph. In |
| 414 | // 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] | 415 | // blocks. To avoid this problem, compute an ordering of the nodes where each |
| 416 | // node is only legalized after all of its operands are legalized. |
| 417 | std::map<SDNode*, unsigned> Visited; |
| 418 | std::vector<SDNode*> Order; |
Chris Lattner | ab510a7 | 2005-10-02 17:49:46 +0000 | [diff] [blame] | 419 | |
Chris Lattner | 32fca00 | 2005-10-06 01:20:27 +0000 | [diff] [blame] | 420 | // Compute ordering from all of the leaves in the graphs, those (like the |
| 421 | // entry node) that have no operands. |
| 422 | for (SelectionDAG::allnodes_iterator I = DAG.allnodes_begin(), |
| 423 | E = DAG.allnodes_end(); I != E; ++I) { |
Chris Lattner | de202b3 | 2005-11-09 23:47:37 +0000 | [diff] [blame] | 424 | if (I->getNumOperands() == 0) { |
| 425 | Visited[I] = 0 - 1U; |
| 426 | ComputeTopDownOrdering(I, Order, Visited); |
Chris Lattner | ab510a7 | 2005-10-02 17:49:46 +0000 | [diff] [blame] | 427 | } |
Chris Lattner | ab510a7 | 2005-10-02 17:49:46 +0000 | [diff] [blame] | 428 | } |
| 429 | |
Chris Lattner | de202b3 | 2005-11-09 23:47:37 +0000 | [diff] [blame] | 430 | assert(Order.size() == Visited.size() && |
| 431 | Order.size() == |
| 432 | (unsigned)std::distance(DAG.allnodes_begin(), DAG.allnodes_end()) && |
Chris Lattner | 32fca00 | 2005-10-06 01:20:27 +0000 | [diff] [blame] | 433 | "Error: DAG is cyclic!"); |
| 434 | Visited.clear(); |
Chris Lattner | ab510a7 | 2005-10-02 17:49:46 +0000 | [diff] [blame] | 435 | |
Chris Lattner | 32fca00 | 2005-10-06 01:20:27 +0000 | [diff] [blame] | 436 | for (unsigned i = 0, e = Order.size(); i != e; ++i) { |
| 437 | SDNode *N = Order[i]; |
| 438 | switch (getTypeAction(N->getValueType(0))) { |
| 439 | default: assert(0 && "Bad type action!"); |
| 440 | case Legal: |
| 441 | LegalizeOp(SDOperand(N, 0)); |
| 442 | break; |
| 443 | case Promote: |
| 444 | PromoteOp(SDOperand(N, 0)); |
| 445 | break; |
| 446 | case Expand: { |
| 447 | SDOperand X, Y; |
| 448 | ExpandOp(SDOperand(N, 0), X, Y); |
| 449 | break; |
| 450 | } |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | // Finally, it's possible the root changed. Get the new root. |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 455 | SDOperand OldRoot = DAG.getRoot(); |
Chris Lattner | 32fca00 | 2005-10-06 01:20:27 +0000 | [diff] [blame] | 456 | assert(LegalizedNodes.count(OldRoot) && "Root didn't get legalized?"); |
| 457 | DAG.setRoot(LegalizedNodes[OldRoot]); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 458 | |
| 459 | ExpandedNodes.clear(); |
| 460 | LegalizedNodes.clear(); |
Chris Lattner | 71c42a0 | 2005-01-16 01:11:45 +0000 | [diff] [blame] | 461 | PromotedNodes.clear(); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 462 | |
| 463 | // Remove dead nodes now. |
Chris Lattner | 62fd269 | 2005-01-07 21:09:37 +0000 | [diff] [blame] | 464 | DAG.RemoveDeadNodes(OldRoot.Val); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) { |
Chris Lattner | c9c60f6 | 2005-08-24 16:35:28 +0000 | [diff] [blame] | 468 | assert(isTypeLegal(Op.getValueType()) && |
Chris Lattner | e3304a3 | 2005-01-08 20:35:13 +0000 | [diff] [blame] | 469 | "Caller should expand or promote operands that are not legal!"); |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 470 | SDNode *Node = Op.Val; |
Chris Lattner | e3304a3 | 2005-01-08 20:35:13 +0000 | [diff] [blame] | 471 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 472 | // If this operation defines any values that cannot be represented in a |
Chris Lattner | e3304a3 | 2005-01-08 20:35:13 +0000 | [diff] [blame] | 473 | // register on this target, make sure to expand or promote them. |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 474 | if (Node->getNumValues() > 1) { |
| 475 | for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) |
| 476 | switch (getTypeAction(Node->getValueType(i))) { |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 477 | case Legal: break; // Nothing to do. |
| 478 | case Expand: { |
| 479 | SDOperand T1, T2; |
| 480 | ExpandOp(Op.getValue(i), T1, T2); |
| 481 | assert(LegalizedNodes.count(Op) && |
| 482 | "Expansion didn't add legal operands!"); |
| 483 | return LegalizedNodes[Op]; |
| 484 | } |
| 485 | case Promote: |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 486 | PromoteOp(Op.getValue(i)); |
| 487 | assert(LegalizedNodes.count(Op) && |
| 488 | "Expansion didn't add legal operands!"); |
| 489 | return LegalizedNodes[Op]; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 490 | } |
| 491 | } |
| 492 | |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 493 | // Note that LegalizeOp may be reentered even from single-use nodes, which |
| 494 | // means that we always must cache transformed nodes. |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 495 | std::map<SDOperand, SDOperand>::iterator I = LegalizedNodes.find(Op); |
| 496 | if (I != LegalizedNodes.end()) return I->second; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 497 | |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 498 | SDOperand Tmp1, Tmp2, Tmp3, Tmp4; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 499 | |
| 500 | SDOperand Result = Op; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 501 | |
| 502 | switch (Node->getOpcode()) { |
| 503 | default: |
Chris Lattner | d73cc5d | 2005-05-14 06:34:48 +0000 | [diff] [blame] | 504 | if (Node->getOpcode() >= ISD::BUILTIN_OP_END) { |
| 505 | // If this is a target node, legalize it by legalizing the operands then |
| 506 | // passing it through. |
| 507 | std::vector<SDOperand> Ops; |
| 508 | bool Changed = false; |
| 509 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) { |
| 510 | Ops.push_back(LegalizeOp(Node->getOperand(i))); |
| 511 | Changed = Changed || Node->getOperand(i) != Ops.back(); |
| 512 | } |
| 513 | if (Changed) |
| 514 | if (Node->getNumValues() == 1) |
| 515 | Result = DAG.getNode(Node->getOpcode(), Node->getValueType(0), Ops); |
| 516 | else { |
| 517 | std::vector<MVT::ValueType> VTs(Node->value_begin(), |
| 518 | Node->value_end()); |
| 519 | Result = DAG.getNode(Node->getOpcode(), VTs, Ops); |
| 520 | } |
| 521 | |
| 522 | for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) |
| 523 | AddLegalizedOperand(Op.getValue(i), Result.getValue(i)); |
| 524 | return Result.getValue(Op.ResNo); |
| 525 | } |
| 526 | // Otherwise this is an unhandled builtin node. splat. |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 527 | std::cerr << "NODE: "; Node->dump(); std::cerr << "\n"; |
| 528 | assert(0 && "Do not know how to legalize this operator!"); |
| 529 | abort(); |
| 530 | case ISD::EntryToken: |
| 531 | case ISD::FrameIndex: |
Chris Lattner | 32fca00 | 2005-10-06 01:20:27 +0000 | [diff] [blame] | 532 | case ISD::TargetFrameIndex: |
| 533 | case ISD::Register: |
| 534 | case ISD::TargetConstant: |
Nate Begeman | 28a6b02 | 2005-12-10 02:36:00 +0000 | [diff] [blame] | 535 | case ISD::TargetConstantPool: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 536 | case ISD::GlobalAddress: |
Chris Lattner | b9debbf | 2005-11-17 05:52:24 +0000 | [diff] [blame] | 537 | case ISD::TargetGlobalAddress: |
Chris Lattner | 03c0cf8 | 2005-01-07 21:45:56 +0000 | [diff] [blame] | 538 | case ISD::ExternalSymbol: |
Chris Lattner | 69a5215 | 2005-01-14 22:38:01 +0000 | [diff] [blame] | 539 | case ISD::ConstantPool: // Nothing to do. |
Chris Lattner | 32fca00 | 2005-10-06 01:20:27 +0000 | [diff] [blame] | 540 | case ISD::BasicBlock: |
| 541 | case ISD::CONDCODE: |
| 542 | case ISD::VALUETYPE: |
| 543 | case ISD::SRCVALUE: |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 544 | case ISD::STRING: |
Chris Lattner | 0c8fbe3 | 2005-11-17 06:41:44 +0000 | [diff] [blame] | 545 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 546 | default: assert(0 && "This action is not supported yet!"); |
| 547 | case TargetLowering::Custom: { |
| 548 | SDOperand Tmp = TLI.LowerOperation(Op, DAG); |
| 549 | if (Tmp.Val) { |
| 550 | Result = LegalizeOp(Tmp); |
| 551 | break; |
| 552 | } |
| 553 | } // FALLTHROUGH if the target doesn't want to lower this op after all. |
| 554 | case TargetLowering::Legal: |
| 555 | assert(isTypeLegal(Node->getValueType(0)) && "This must be legal!"); |
| 556 | break; |
| 557 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 558 | break; |
Chris Lattner | 08951a3 | 2005-09-02 01:15:01 +0000 | [diff] [blame] | 559 | case ISD::AssertSext: |
| 560 | case ISD::AssertZext: |
| 561 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 562 | if (Tmp1 != Node->getOperand(0)) |
| 563 | Result = DAG.getNode(Node->getOpcode(), Node->getValueType(0), Tmp1, |
| 564 | Node->getOperand(1)); |
| 565 | break; |
Chris Lattner | 308575b | 2005-11-20 22:56:56 +0000 | [diff] [blame] | 566 | case ISD::MERGE_VALUES: |
| 567 | return LegalizeOp(Node->getOperand(Op.ResNo)); |
Chris Lattner | 69a5215 | 2005-01-14 22:38:01 +0000 | [diff] [blame] | 568 | case ISD::CopyFromReg: |
| 569 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 570 | Result = Op.getValue(0); |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 571 | if (Node->getNumValues() == 2) { |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 572 | if (Tmp1 != Node->getOperand(0)) |
| 573 | Result = DAG.getCopyFromReg(Tmp1, |
Chris Lattner | d5d0f9b | 2005-08-16 21:55:35 +0000 | [diff] [blame] | 574 | cast<RegisterSDNode>(Node->getOperand(1))->getReg(), |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 575 | Node->getValueType(0)); |
| 576 | } else { |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 577 | assert(Node->getNumValues() == 3 && "Invalid copyfromreg!"); |
| 578 | if (Node->getNumOperands() == 3) |
| 579 | Tmp2 = LegalizeOp(Node->getOperand(2)); |
| 580 | if (Tmp1 != Node->getOperand(0) || |
| 581 | (Node->getNumOperands() == 3 && Tmp2 != Node->getOperand(2))) |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 582 | Result = DAG.getCopyFromReg(Tmp1, |
| 583 | cast<RegisterSDNode>(Node->getOperand(1))->getReg(), |
| 584 | Node->getValueType(0), Tmp2); |
| 585 | AddLegalizedOperand(Op.getValue(2), Result.getValue(2)); |
| 586 | } |
Chris Lattner | 13c184d | 2005-01-28 06:27:38 +0000 | [diff] [blame] | 587 | // Since CopyFromReg produces two values, make sure to remember that we |
| 588 | // legalized both of them. |
| 589 | AddLegalizedOperand(Op.getValue(0), Result); |
| 590 | AddLegalizedOperand(Op.getValue(1), Result.getValue(1)); |
| 591 | return Result.getValue(Op.ResNo); |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 592 | case ISD::UNDEF: { |
| 593 | MVT::ValueType VT = Op.getValueType(); |
| 594 | switch (TLI.getOperationAction(ISD::UNDEF, VT)) { |
Nate Begeman | ea19cd5 | 2005-04-02 00:41:14 +0000 | [diff] [blame] | 595 | default: assert(0 && "This action is not supported yet!"); |
| 596 | case TargetLowering::Expand: |
| 597 | case TargetLowering::Promote: |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 598 | if (MVT::isInteger(VT)) |
| 599 | Result = DAG.getConstant(0, VT); |
| 600 | else if (MVT::isFloatingPoint(VT)) |
| 601 | Result = DAG.getConstantFP(0, VT); |
| 602 | else |
| 603 | assert(0 && "Unknown value type!"); |
| 604 | break; |
Nate Begeman | ea19cd5 | 2005-04-02 00:41:14 +0000 | [diff] [blame] | 605 | case TargetLowering::Legal: |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 606 | break; |
| 607 | } |
| 608 | break; |
| 609 | } |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 610 | |
| 611 | case ISD::LOCATION: |
| 612 | assert(Node->getNumOperands() == 5 && "Invalid LOCATION node!"); |
| 613 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the input chain. |
| 614 | |
| 615 | switch (TLI.getOperationAction(ISD::LOCATION, MVT::Other)) { |
| 616 | case TargetLowering::Promote: |
| 617 | default: assert(0 && "This action is not supported yet!"); |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 618 | case TargetLowering::Expand: { |
Jim Laskey | e81aecb | 2005-12-21 20:51:37 +0000 | [diff] [blame] | 619 | if (TLI.isOperationLegal(ISD::DEBUG_LOC, MVT::Other)) { |
| 620 | MachineDebugInfo &DebugInfo = DAG.getMachineFunction().getDebugInfo(); |
| 621 | std::vector<SDOperand> Ops; |
| 622 | Ops.push_back(Tmp1); // chain |
| 623 | Ops.push_back(Node->getOperand(1)); // line # |
| 624 | Ops.push_back(Node->getOperand(2)); // col # |
| 625 | const std::string &fname = |
| 626 | cast<StringSDNode>(Node->getOperand(3))->getValue(); |
| 627 | const std::string &dirname = |
| 628 | cast<StringSDNode>(Node->getOperand(4))->getValue(); |
| 629 | unsigned id = DebugInfo.RecordSource(fname, dirname); |
| 630 | Ops.push_back(DAG.getConstant(id, MVT::i32)); // source file id |
| 631 | Result = DAG.getNode(ISD::DEBUG_LOC, MVT::Other, Ops); |
| 632 | } else { |
| 633 | Result = Tmp1; // chain |
| 634 | } |
Chris Lattner | e773673 | 2005-12-18 23:54:29 +0000 | [diff] [blame] | 635 | Result = LegalizeOp(Result); // Relegalize new nodes. |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 636 | break; |
Chris Lattner | e773673 | 2005-12-18 23:54:29 +0000 | [diff] [blame] | 637 | } |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 638 | case TargetLowering::Legal: |
Chris Lattner | 9ad17c9 | 2005-12-01 18:21:35 +0000 | [diff] [blame] | 639 | if (Tmp1 != Node->getOperand(0) || |
| 640 | getTypeAction(Node->getOperand(1).getValueType()) == Promote) { |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 641 | std::vector<SDOperand> Ops; |
| 642 | Ops.push_back(Tmp1); |
Chris Lattner | 9ad17c9 | 2005-12-01 18:21:35 +0000 | [diff] [blame] | 643 | if (getTypeAction(Node->getOperand(1).getValueType()) == Legal) { |
| 644 | Ops.push_back(Node->getOperand(1)); // line # must be legal. |
| 645 | Ops.push_back(Node->getOperand(2)); // col # must be legal. |
| 646 | } else { |
| 647 | // Otherwise promote them. |
| 648 | Ops.push_back(PromoteOp(Node->getOperand(1))); |
| 649 | Ops.push_back(PromoteOp(Node->getOperand(2))); |
| 650 | } |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 651 | Ops.push_back(Node->getOperand(3)); // filename must be legal. |
| 652 | Ops.push_back(Node->getOperand(4)); // working dir # must be legal. |
| 653 | Result = DAG.getNode(ISD::LOCATION, MVT::Other, Ops); |
| 654 | } |
| 655 | break; |
| 656 | } |
| 657 | break; |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 658 | |
| 659 | case ISD::DEBUG_LOC: |
| 660 | assert(Node->getNumOperands() == 4 && "Invalid DEBUG_LOC node!"); |
| 661 | switch (TLI.getOperationAction(ISD::DEBUG_LOC, MVT::Other)) { |
| 662 | case TargetLowering::Promote: |
| 663 | case TargetLowering::Expand: |
| 664 | default: assert(0 && "This action is not supported yet!"); |
| 665 | case TargetLowering::Legal: |
| 666 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 667 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the line #. |
| 668 | Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the col #. |
| 669 | Tmp4 = LegalizeOp(Node->getOperand(3)); // Legalize the source file id. |
| 670 | |
| 671 | if (Tmp1 != Node->getOperand(0) || |
| 672 | Tmp2 != Node->getOperand(1) || |
| 673 | Tmp3 != Node->getOperand(2) || |
| 674 | Tmp4 != Node->getOperand(3)) { |
| 675 | Result = DAG.getNode(ISD::DEBUG_LOC,MVT::Other, Tmp1, Tmp2, Tmp3, Tmp4); |
| 676 | } |
| 677 | break; |
| 678 | } |
| 679 | break; |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 680 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 681 | case ISD::Constant: |
| 682 | // We know we don't need to expand constants here, constants only have one |
| 683 | // value and we check that it is fine above. |
| 684 | |
| 685 | // FIXME: Maybe we should handle things like targets that don't support full |
| 686 | // 32-bit immediates? |
| 687 | break; |
| 688 | case ISD::ConstantFP: { |
| 689 | // Spill FP immediates to the constant pool if the target cannot directly |
| 690 | // codegen them. Targets often have some immediate values that can be |
| 691 | // efficiently generated into an FP register without a load. We explicitly |
| 692 | // leave these constants as ConstantFP nodes for the target to deal with. |
| 693 | |
| 694 | ConstantFPSDNode *CFP = cast<ConstantFPSDNode>(Node); |
| 695 | |
| 696 | // Check to see if this FP immediate is already legal. |
| 697 | bool isLegal = false; |
| 698 | for (TargetLowering::legal_fpimm_iterator I = TLI.legal_fpimm_begin(), |
| 699 | E = TLI.legal_fpimm_end(); I != E; ++I) |
| 700 | if (CFP->isExactlyValue(*I)) { |
| 701 | isLegal = true; |
| 702 | break; |
| 703 | } |
| 704 | |
| 705 | if (!isLegal) { |
| 706 | // Otherwise we need to spill the constant to memory. |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 707 | bool Extend = false; |
| 708 | |
| 709 | // If a FP immediate is precise when represented as a float, we put it |
| 710 | // into the constant pool as a float, even if it's is statically typed |
| 711 | // as a double. |
| 712 | MVT::ValueType VT = CFP->getValueType(0); |
| 713 | bool isDouble = VT == MVT::f64; |
| 714 | ConstantFP *LLVMC = ConstantFP::get(isDouble ? Type::DoubleTy : |
| 715 | Type::FloatTy, CFP->getValue()); |
Chris Lattner | 99939d3 | 2005-01-28 22:58:25 +0000 | [diff] [blame] | 716 | if (isDouble && CFP->isExactlyValue((float)CFP->getValue()) && |
| 717 | // Only do this if the target has a native EXTLOAD instruction from |
| 718 | // f32. |
Chris Lattner | c9c60f6 | 2005-08-24 16:35:28 +0000 | [diff] [blame] | 719 | TLI.isOperationLegal(ISD::EXTLOAD, MVT::f32)) { |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 720 | LLVMC = cast<ConstantFP>(ConstantExpr::getCast(LLVMC, Type::FloatTy)); |
| 721 | VT = MVT::f32; |
| 722 | Extend = true; |
| 723 | } |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 724 | |
Nate Begeman | 28a6b02 | 2005-12-10 02:36:00 +0000 | [diff] [blame] | 725 | SDOperand CPIdx = |
| 726 | LegalizeOp(DAG.getConstantPool(LLVMC, TLI.getPointerTy())); |
Chris Lattner | f8161d8 | 2005-01-16 05:06:12 +0000 | [diff] [blame] | 727 | if (Extend) { |
Chris Lattner | 5f056bf | 2005-07-10 01:55:33 +0000 | [diff] [blame] | 728 | Result = DAG.getExtLoad(ISD::EXTLOAD, MVT::f64, DAG.getEntryNode(), |
| 729 | CPIdx, DAG.getSrcValue(NULL), MVT::f32); |
Chris Lattner | f8161d8 | 2005-01-16 05:06:12 +0000 | [diff] [blame] | 730 | } else { |
Chris Lattner | 52d08bd | 2005-05-09 20:23:03 +0000 | [diff] [blame] | 731 | Result = DAG.getLoad(VT, DAG.getEntryNode(), CPIdx, |
| 732 | DAG.getSrcValue(NULL)); |
Chris Lattner | f8161d8 | 2005-01-16 05:06:12 +0000 | [diff] [blame] | 733 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 734 | } |
| 735 | break; |
| 736 | } |
Nate Begeman | 8cfa57b | 2005-12-06 06:18:55 +0000 | [diff] [blame] | 737 | case ISD::ConstantVec: { |
| 738 | // We assume that vector constants are not legal, and will be immediately |
| 739 | // spilled to the constant pool. |
| 740 | // |
| 741 | // FIXME: revisit this when we have some kind of mechanism by which targets |
| 742 | // can decided legality of vector constants, of which there may be very |
| 743 | // many. |
| 744 | // |
| 745 | // Create a ConstantPacked, and put it in the constant pool. |
| 746 | std::vector<Constant*> CV; |
| 747 | MVT::ValueType VT = Node->getValueType(0); |
| 748 | for (unsigned I = 0, E = Node->getNumOperands(); I < E; ++I) { |
| 749 | SDOperand OpN = Node->getOperand(I); |
| 750 | const Type* OpNTy = MVT::getTypeForValueType(OpN.getValueType()); |
| 751 | if (MVT::isFloatingPoint(VT)) |
| 752 | CV.push_back(ConstantFP::get(OpNTy, |
| 753 | cast<ConstantFPSDNode>(OpN)->getValue())); |
| 754 | else |
| 755 | CV.push_back(ConstantUInt::get(OpNTy, |
| 756 | cast<ConstantSDNode>(OpN)->getValue())); |
| 757 | } |
| 758 | Constant *CP = ConstantPacked::get(CV); |
Nate Begeman | d7d746f | 2005-12-13 03:03:23 +0000 | [diff] [blame] | 759 | SDOperand CPIdx = LegalizeOp(DAG.getConstantPool(CP, TLI.getPointerTy())); |
Nate Begeman | 8cfa57b | 2005-12-06 06:18:55 +0000 | [diff] [blame] | 760 | Result = DAG.getLoad(VT, DAG.getEntryNode(), CPIdx, DAG.getSrcValue(NULL)); |
| 761 | break; |
| 762 | } |
Chris Lattner | 040c11c | 2005-11-09 18:48:57 +0000 | [diff] [blame] | 763 | case ISD::TokenFactor: |
| 764 | if (Node->getNumOperands() == 2) { |
| 765 | bool Changed = false; |
| 766 | SDOperand Op0 = LegalizeOp(Node->getOperand(0)); |
| 767 | SDOperand Op1 = LegalizeOp(Node->getOperand(1)); |
| 768 | if (Op0 != Node->getOperand(0) || Op1 != Node->getOperand(1)) |
| 769 | Result = DAG.getNode(ISD::TokenFactor, MVT::Other, Op0, Op1); |
| 770 | } else { |
| 771 | std::vector<SDOperand> Ops; |
| 772 | bool Changed = false; |
| 773 | // Legalize the operands. |
| 774 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) { |
| 775 | SDOperand Op = Node->getOperand(i); |
| 776 | Ops.push_back(LegalizeOp(Op)); |
| 777 | Changed |= Ops[i] != Op; |
| 778 | } |
| 779 | if (Changed) |
| 780 | Result = DAG.getNode(ISD::TokenFactor, MVT::Other, Ops); |
Chris Lattner | a385e9b | 2005-01-13 17:59:25 +0000 | [diff] [blame] | 781 | } |
Chris Lattner | a385e9b | 2005-01-13 17:59:25 +0000 | [diff] [blame] | 782 | break; |
Chris Lattner | a385e9b | 2005-01-13 17:59:25 +0000 | [diff] [blame] | 783 | |
Chris Lattner | 16cd04d | 2005-05-12 23:24:06 +0000 | [diff] [blame] | 784 | case ISD::CALLSEQ_START: |
| 785 | case ISD::CALLSEQ_END: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 786 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | 128b52d | 2005-05-12 23:24:44 +0000 | [diff] [blame] | 787 | // Do not try to legalize the target-specific arguments (#1+) |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 788 | Tmp2 = Node->getOperand(0); |
Nate Begeman | 1aa1972 | 2005-10-04 02:10:55 +0000 | [diff] [blame] | 789 | if (Tmp1 != Tmp2) |
Chris Lattner | 88de6e7 | 2005-05-12 00:17:04 +0000 | [diff] [blame] | 790 | Node->setAdjCallChain(Tmp1); |
Nate Begeman | 27d404c | 2005-10-04 00:37:37 +0000 | [diff] [blame] | 791 | |
Chris Lattner | 16cd04d | 2005-05-12 23:24:06 +0000 | [diff] [blame] | 792 | // Note that we do not create new CALLSEQ_DOWN/UP nodes here. These |
Chris Lattner | 88de6e7 | 2005-05-12 00:17:04 +0000 | [diff] [blame] | 793 | // nodes are treated specially and are mutated in place. This makes the dag |
| 794 | // legalization process more efficient and also makes libcall insertion |
| 795 | // easier. |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 796 | break; |
Chris Lattner | fa404e8 | 2005-01-09 19:03:49 +0000 | [diff] [blame] | 797 | case ISD::DYNAMIC_STACKALLOC: |
| 798 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 799 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the size. |
| 800 | Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the alignment. |
| 801 | if (Tmp1 != Node->getOperand(0) || Tmp2 != Node->getOperand(1) || |
Chris Lattner | adf6c2a | 2005-05-14 07:29:57 +0000 | [diff] [blame] | 802 | Tmp3 != Node->getOperand(2)) { |
| 803 | std::vector<MVT::ValueType> VTs(Node->value_begin(), Node->value_end()); |
| 804 | std::vector<SDOperand> Ops; |
| 805 | Ops.push_back(Tmp1); Ops.push_back(Tmp2); Ops.push_back(Tmp3); |
| 806 | Result = DAG.getNode(ISD::DYNAMIC_STACKALLOC, VTs, Ops); |
| 807 | } else |
Chris Lattner | 513e52e | 2005-01-09 19:07:54 +0000 | [diff] [blame] | 808 | Result = Op.getValue(0); |
Chris Lattner | fa404e8 | 2005-01-09 19:03:49 +0000 | [diff] [blame] | 809 | |
| 810 | // Since this op produces two values, make sure to remember that we |
| 811 | // legalized both of them. |
| 812 | AddLegalizedOperand(SDOperand(Node, 0), Result); |
| 813 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
| 814 | return Result.getValue(Op.ResNo); |
| 815 | |
Chris Lattner | d71c041 | 2005-05-13 18:43:43 +0000 | [diff] [blame] | 816 | case ISD::TAILCALL: |
Chris Lattner | 3d9dffc | 2005-01-19 20:24:35 +0000 | [diff] [blame] | 817 | case ISD::CALL: { |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 818 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 819 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the callee. |
Chris Lattner | 3d9dffc | 2005-01-19 20:24:35 +0000 | [diff] [blame] | 820 | |
| 821 | bool Changed = false; |
| 822 | std::vector<SDOperand> Ops; |
| 823 | for (unsigned i = 2, e = Node->getNumOperands(); i != e; ++i) { |
| 824 | Ops.push_back(LegalizeOp(Node->getOperand(i))); |
| 825 | Changed |= Ops.back() != Node->getOperand(i); |
| 826 | } |
| 827 | |
| 828 | if (Tmp1 != Node->getOperand(0) || Tmp2 != Node->getOperand(1) || Changed) { |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 829 | std::vector<MVT::ValueType> RetTyVTs; |
| 830 | RetTyVTs.reserve(Node->getNumValues()); |
| 831 | for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) |
Chris Lattner | ebda942 | 2005-01-07 21:34:13 +0000 | [diff] [blame] | 832 | RetTyVTs.push_back(Node->getValueType(i)); |
Chris Lattner | d71c041 | 2005-05-13 18:43:43 +0000 | [diff] [blame] | 833 | Result = SDOperand(DAG.getCall(RetTyVTs, Tmp1, Tmp2, Ops, |
| 834 | Node->getOpcode() == ISD::TAILCALL), 0); |
Chris Lattner | 38d6be5 | 2005-01-09 19:43:23 +0000 | [diff] [blame] | 835 | } else { |
| 836 | Result = Result.getValue(0); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 837 | } |
Chris Lattner | 38d6be5 | 2005-01-09 19:43:23 +0000 | [diff] [blame] | 838 | // Since calls produce multiple values, make sure to remember that we |
| 839 | // legalized all of them. |
| 840 | for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) |
| 841 | AddLegalizedOperand(SDOperand(Node, i), Result.getValue(i)); |
| 842 | return Result.getValue(Op.ResNo); |
Chris Lattner | 3d9dffc | 2005-01-19 20:24:35 +0000 | [diff] [blame] | 843 | } |
Chris Lattner | c7af179 | 2005-01-07 22:12:08 +0000 | [diff] [blame] | 844 | case ISD::BR: |
| 845 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 846 | if (Tmp1 != Node->getOperand(0)) |
| 847 | Result = DAG.getNode(ISD::BR, MVT::Other, Tmp1, Node->getOperand(1)); |
| 848 | break; |
| 849 | |
Chris Lattner | c18ae4c | 2005-01-07 08:19:42 +0000 | [diff] [blame] | 850 | case ISD::BRCOND: |
| 851 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 852 | |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 853 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 854 | case Expand: assert(0 && "It's impossible to expand bools"); |
| 855 | case Legal: |
| 856 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the condition. |
| 857 | break; |
| 858 | case Promote: |
| 859 | Tmp2 = PromoteOp(Node->getOperand(1)); // Promote the condition. |
| 860 | break; |
| 861 | } |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 862 | |
| 863 | switch (TLI.getOperationAction(ISD::BRCOND, MVT::Other)) { |
| 864 | default: assert(0 && "This action is not supported yet!"); |
| 865 | case TargetLowering::Expand: |
| 866 | // Expand brcond's setcc into its constituent parts and create a BR_CC |
| 867 | // Node. |
| 868 | if (Tmp2.getOpcode() == ISD::SETCC) { |
| 869 | Result = DAG.getNode(ISD::BR_CC, MVT::Other, Tmp1, Tmp2.getOperand(2), |
| 870 | Tmp2.getOperand(0), Tmp2.getOperand(1), |
| 871 | Node->getOperand(2)); |
| 872 | } else { |
Chris Lattner | 550b1e5 | 2005-08-21 18:03:09 +0000 | [diff] [blame] | 873 | // Make sure the condition is either zero or one. It may have been |
| 874 | // promoted from something else. |
| 875 | Tmp2 = DAG.getZeroExtendInReg(Tmp2, MVT::i1); |
| 876 | |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 877 | Result = DAG.getNode(ISD::BR_CC, MVT::Other, Tmp1, |
| 878 | DAG.getCondCode(ISD::SETNE), Tmp2, |
| 879 | DAG.getConstant(0, Tmp2.getValueType()), |
| 880 | Node->getOperand(2)); |
| 881 | } |
Chris Lattner | e773673 | 2005-12-18 23:54:29 +0000 | [diff] [blame] | 882 | Result = LegalizeOp(Result); // Relegalize new nodes. |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 883 | break; |
Evan Cheng | 898101c | 2005-12-19 23:12:38 +0000 | [diff] [blame] | 884 | case TargetLowering::Custom: { |
| 885 | SDOperand Tmp = |
| 886 | TLI.LowerOperation(DAG.getNode(ISD::BRCOND, Node->getValueType(0), |
| 887 | Tmp1, Tmp2, Node->getOperand(2)), DAG); |
| 888 | if (Tmp.Val) { |
| 889 | Result = LegalizeOp(Tmp); |
| 890 | break; |
| 891 | } |
| 892 | // FALLTHROUGH if the target thinks it is legal. |
| 893 | } |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 894 | case TargetLowering::Legal: |
| 895 | // Basic block destination (Op#2) is always legal. |
| 896 | if (Tmp1 != Node->getOperand(0) || Tmp2 != Node->getOperand(1)) |
| 897 | Result = DAG.getNode(ISD::BRCOND, MVT::Other, Tmp1, Tmp2, |
| 898 | Node->getOperand(2)); |
| 899 | break; |
| 900 | } |
| 901 | break; |
| 902 | case ISD::BR_CC: |
| 903 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | 181b7a3 | 2005-12-17 23:46:46 +0000 | [diff] [blame] | 904 | if (!isTypeLegal(Node->getOperand(2).getValueType())) { |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 905 | Tmp2 = LegalizeOp(DAG.getNode(ISD::SETCC, TLI.getSetCCResultTy(), |
| 906 | Node->getOperand(2), // LHS |
| 907 | Node->getOperand(3), // RHS |
| 908 | Node->getOperand(1))); |
| 909 | // If we get a SETCC back from legalizing the SETCC node we just |
| 910 | // created, then use its LHS, RHS, and CC directly in creating a new |
| 911 | // node. Otherwise, select between the true and false value based on |
| 912 | // comparing the result of the legalized with zero. |
| 913 | if (Tmp2.getOpcode() == ISD::SETCC) { |
| 914 | Result = DAG.getNode(ISD::BR_CC, MVT::Other, Tmp1, Tmp2.getOperand(2), |
| 915 | Tmp2.getOperand(0), Tmp2.getOperand(1), |
| 916 | Node->getOperand(4)); |
| 917 | } else { |
| 918 | Result = DAG.getNode(ISD::BR_CC, MVT::Other, Tmp1, |
| 919 | DAG.getCondCode(ISD::SETNE), |
| 920 | Tmp2, DAG.getConstant(0, Tmp2.getValueType()), |
| 921 | Node->getOperand(4)); |
| 922 | } |
Chris Lattner | 181b7a3 | 2005-12-17 23:46:46 +0000 | [diff] [blame] | 923 | break; |
| 924 | } |
| 925 | |
| 926 | Tmp2 = LegalizeOp(Node->getOperand(2)); // LHS |
| 927 | Tmp3 = LegalizeOp(Node->getOperand(3)); // RHS |
| 928 | |
| 929 | switch (TLI.getOperationAction(ISD::BR_CC, Tmp3.getValueType())) { |
| 930 | default: assert(0 && "Unexpected action for BR_CC!"); |
| 931 | case TargetLowering::Custom: { |
| 932 | Tmp4 = DAG.getNode(ISD::BR_CC, MVT::Other, Tmp1, Node->getOperand(1), |
| 933 | Tmp2, Tmp3, Node->getOperand(4)); |
| 934 | Tmp4 = TLI.LowerOperation(Tmp4, DAG); |
| 935 | if (Tmp4.Val) { |
| 936 | Result = LegalizeOp(Tmp4); |
| 937 | break; |
| 938 | } |
| 939 | } // FALLTHROUGH if the target doesn't want to lower this op after all. |
| 940 | case TargetLowering::Legal: |
| 941 | if (Tmp1 != Node->getOperand(0) || Tmp2 != Node->getOperand(2) || |
| 942 | Tmp3 != Node->getOperand(3)) { |
| 943 | Result = DAG.getNode(ISD::BR_CC, MVT::Other, Tmp1, Node->getOperand(1), |
| 944 | Tmp2, Tmp3, Node->getOperand(4)); |
| 945 | } |
| 946 | break; |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 947 | } |
Chris Lattner | c18ae4c | 2005-01-07 08:19:42 +0000 | [diff] [blame] | 948 | break; |
Chris Lattner | 411e888 | 2005-04-09 03:30:19 +0000 | [diff] [blame] | 949 | case ISD::BRCONDTWOWAY: |
| 950 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 951 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 952 | case Expand: assert(0 && "It's impossible to expand bools"); |
| 953 | case Legal: |
| 954 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the condition. |
| 955 | break; |
| 956 | case Promote: |
| 957 | Tmp2 = PromoteOp(Node->getOperand(1)); // Promote the condition. |
| 958 | break; |
| 959 | } |
| 960 | // If this target does not support BRCONDTWOWAY, lower it to a BRCOND/BR |
| 961 | // pair. |
| 962 | switch (TLI.getOperationAction(ISD::BRCONDTWOWAY, MVT::Other)) { |
| 963 | case TargetLowering::Promote: |
| 964 | default: assert(0 && "This action is not supported yet!"); |
| 965 | case TargetLowering::Legal: |
| 966 | if (Tmp1 != Node->getOperand(0) || Tmp2 != Node->getOperand(1)) { |
| 967 | std::vector<SDOperand> Ops; |
| 968 | Ops.push_back(Tmp1); |
| 969 | Ops.push_back(Tmp2); |
| 970 | Ops.push_back(Node->getOperand(2)); |
| 971 | Ops.push_back(Node->getOperand(3)); |
| 972 | Result = DAG.getNode(ISD::BRCONDTWOWAY, MVT::Other, Ops); |
| 973 | } |
| 974 | break; |
| 975 | case TargetLowering::Expand: |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 976 | // If BRTWOWAY_CC is legal for this target, then simply expand this node |
| 977 | // to that. Otherwise, skip BRTWOWAY_CC and expand directly to a |
| 978 | // BRCOND/BR pair. |
Chris Lattner | c9c60f6 | 2005-08-24 16:35:28 +0000 | [diff] [blame] | 979 | if (TLI.isOperationLegal(ISD::BRTWOWAY_CC, MVT::Other)) { |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 980 | if (Tmp2.getOpcode() == ISD::SETCC) { |
| 981 | Result = DAG.getBR2Way_CC(Tmp1, Tmp2.getOperand(2), |
| 982 | Tmp2.getOperand(0), Tmp2.getOperand(1), |
| 983 | Node->getOperand(2), Node->getOperand(3)); |
| 984 | } else { |
| 985 | Result = DAG.getBR2Way_CC(Tmp1, DAG.getCondCode(ISD::SETNE), Tmp2, |
| 986 | DAG.getConstant(0, Tmp2.getValueType()), |
| 987 | Node->getOperand(2), Node->getOperand(3)); |
| 988 | } |
| 989 | } else { |
| 990 | Result = DAG.getNode(ISD::BRCOND, MVT::Other, Tmp1, Tmp2, |
Chris Lattner | 411e888 | 2005-04-09 03:30:19 +0000 | [diff] [blame] | 991 | Node->getOperand(2)); |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 992 | Result = DAG.getNode(ISD::BR, MVT::Other, Result, Node->getOperand(3)); |
| 993 | } |
Chris Lattner | e773673 | 2005-12-18 23:54:29 +0000 | [diff] [blame] | 994 | Result = LegalizeOp(Result); // Relegalize new nodes. |
Chris Lattner | 411e888 | 2005-04-09 03:30:19 +0000 | [diff] [blame] | 995 | break; |
| 996 | } |
| 997 | break; |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 998 | case ISD::BRTWOWAY_CC: |
| 999 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | c9c60f6 | 2005-08-24 16:35:28 +0000 | [diff] [blame] | 1000 | if (isTypeLegal(Node->getOperand(2).getValueType())) { |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 1001 | Tmp2 = LegalizeOp(Node->getOperand(2)); // LHS |
| 1002 | Tmp3 = LegalizeOp(Node->getOperand(3)); // RHS |
| 1003 | if (Tmp1 != Node->getOperand(0) || Tmp2 != Node->getOperand(2) || |
| 1004 | Tmp3 != Node->getOperand(3)) { |
| 1005 | Result = DAG.getBR2Way_CC(Tmp1, Node->getOperand(1), Tmp2, Tmp3, |
| 1006 | Node->getOperand(4), Node->getOperand(5)); |
| 1007 | } |
| 1008 | break; |
| 1009 | } else { |
| 1010 | Tmp2 = LegalizeOp(DAG.getNode(ISD::SETCC, TLI.getSetCCResultTy(), |
| 1011 | Node->getOperand(2), // LHS |
| 1012 | Node->getOperand(3), // RHS |
| 1013 | Node->getOperand(1))); |
| 1014 | // If this target does not support BRTWOWAY_CC, lower it to a BRCOND/BR |
| 1015 | // pair. |
| 1016 | switch (TLI.getOperationAction(ISD::BRTWOWAY_CC, MVT::Other)) { |
| 1017 | default: assert(0 && "This action is not supported yet!"); |
| 1018 | case TargetLowering::Legal: |
| 1019 | // If we get a SETCC back from legalizing the SETCC node we just |
| 1020 | // created, then use its LHS, RHS, and CC directly in creating a new |
| 1021 | // node. Otherwise, select between the true and false value based on |
| 1022 | // comparing the result of the legalized with zero. |
| 1023 | if (Tmp2.getOpcode() == ISD::SETCC) { |
| 1024 | Result = DAG.getBR2Way_CC(Tmp1, Tmp2.getOperand(2), |
| 1025 | Tmp2.getOperand(0), Tmp2.getOperand(1), |
| 1026 | Node->getOperand(4), Node->getOperand(5)); |
| 1027 | } else { |
| 1028 | Result = DAG.getBR2Way_CC(Tmp1, DAG.getCondCode(ISD::SETNE), Tmp2, |
| 1029 | DAG.getConstant(0, Tmp2.getValueType()), |
| 1030 | Node->getOperand(4), Node->getOperand(5)); |
| 1031 | } |
| 1032 | break; |
| 1033 | case TargetLowering::Expand: |
| 1034 | Result = DAG.getNode(ISD::BRCOND, MVT::Other, Tmp1, Tmp2, |
| 1035 | Node->getOperand(4)); |
| 1036 | Result = DAG.getNode(ISD::BR, MVT::Other, Result, Node->getOperand(5)); |
| 1037 | break; |
| 1038 | } |
Chris Lattner | f9dee6a | 2005-12-21 19:40:42 +0000 | [diff] [blame] | 1039 | Result = LegalizeOp(Result); // Relegalize new nodes. |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 1040 | } |
| 1041 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1042 | case ISD::LOAD: |
| 1043 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1044 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 1045 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1046 | if (Tmp1 != Node->getOperand(0) || |
| 1047 | Tmp2 != Node->getOperand(1)) |
Chris Lattner | 52d08bd | 2005-05-09 20:23:03 +0000 | [diff] [blame] | 1048 | Result = DAG.getLoad(Node->getValueType(0), Tmp1, Tmp2, |
| 1049 | Node->getOperand(2)); |
Chris Lattner | 8afc48e | 2005-01-07 22:28:47 +0000 | [diff] [blame] | 1050 | else |
| 1051 | Result = SDOperand(Node, 0); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 1052 | |
Chris Lattner | 8afc48e | 2005-01-07 22:28:47 +0000 | [diff] [blame] | 1053 | // Since loads produce two values, make sure to remember that we legalized |
| 1054 | // both of them. |
| 1055 | AddLegalizedOperand(SDOperand(Node, 0), Result); |
| 1056 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
| 1057 | return Result.getValue(Op.ResNo); |
Nate Begeman | 5fbb5d2 | 2005-11-19 00:36:38 +0000 | [diff] [blame] | 1058 | |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 1059 | case ISD::EXTLOAD: |
| 1060 | case ISD::SEXTLOAD: |
Chris Lattner | 01ff721 | 2005-04-10 22:54:25 +0000 | [diff] [blame] | 1061 | case ISD::ZEXTLOAD: { |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 1062 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1063 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 1064 | |
Chris Lattner | 5f056bf | 2005-07-10 01:55:33 +0000 | [diff] [blame] | 1065 | MVT::ValueType SrcVT = cast<VTSDNode>(Node->getOperand(3))->getVT(); |
Chris Lattner | 01ff721 | 2005-04-10 22:54:25 +0000 | [diff] [blame] | 1066 | switch (TLI.getOperationAction(Node->getOpcode(), SrcVT)) { |
Chris Lattner | 01ff721 | 2005-04-10 22:54:25 +0000 | [diff] [blame] | 1067 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 1c51c6a | 2005-04-12 20:30:10 +0000 | [diff] [blame] | 1068 | case TargetLowering::Promote: |
| 1069 | assert(SrcVT == MVT::i1 && "Can only promote EXTLOAD from i1 -> i8!"); |
Chris Lattner | 5f056bf | 2005-07-10 01:55:33 +0000 | [diff] [blame] | 1070 | Result = DAG.getExtLoad(Node->getOpcode(), Node->getValueType(0), |
| 1071 | Tmp1, Tmp2, Node->getOperand(2), MVT::i8); |
Chris Lattner | 1c51c6a | 2005-04-12 20:30:10 +0000 | [diff] [blame] | 1072 | // Since loads produce two values, make sure to remember that we legalized |
| 1073 | // both of them. |
| 1074 | AddLegalizedOperand(SDOperand(Node, 0), Result); |
| 1075 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
| 1076 | return Result.getValue(Op.ResNo); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 1077 | |
Chris Lattner | 01ff721 | 2005-04-10 22:54:25 +0000 | [diff] [blame] | 1078 | case TargetLowering::Legal: |
| 1079 | if (Tmp1 != Node->getOperand(0) || |
| 1080 | Tmp2 != Node->getOperand(1)) |
Chris Lattner | 5f056bf | 2005-07-10 01:55:33 +0000 | [diff] [blame] | 1081 | Result = DAG.getExtLoad(Node->getOpcode(), Node->getValueType(0), |
| 1082 | Tmp1, Tmp2, Node->getOperand(2), SrcVT); |
Chris Lattner | 01ff721 | 2005-04-10 22:54:25 +0000 | [diff] [blame] | 1083 | else |
| 1084 | Result = SDOperand(Node, 0); |
| 1085 | |
| 1086 | // Since loads produce two values, make sure to remember that we legalized |
| 1087 | // both of them. |
| 1088 | AddLegalizedOperand(SDOperand(Node, 0), Result); |
| 1089 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
| 1090 | return Result.getValue(Op.ResNo); |
Chris Lattner | 01ff721 | 2005-04-10 22:54:25 +0000 | [diff] [blame] | 1091 | case TargetLowering::Expand: |
Chris Lattner | 69a889e | 2005-12-20 00:53:54 +0000 | [diff] [blame] | 1092 | // f64 = EXTLOAD f32 should expand to LOAD, FP_EXTEND |
Andrew Lenharth | 9d416f7 | 2005-06-30 19:22:37 +0000 | [diff] [blame] | 1093 | if (SrcVT == MVT::f32 && Node->getValueType(0) == MVT::f64) { |
| 1094 | SDOperand Load = DAG.getLoad(SrcVT, Tmp1, Tmp2, Node->getOperand(2)); |
Andrew Lenharth | 3155908 | 2005-06-30 19:32:57 +0000 | [diff] [blame] | 1095 | Result = DAG.getNode(ISD::FP_EXTEND, Node->getValueType(0), Load); |
Chris Lattner | e773673 | 2005-12-18 23:54:29 +0000 | [diff] [blame] | 1096 | Result = LegalizeOp(Result); // Relegalize new nodes. |
Chris Lattner | 69a889e | 2005-12-20 00:53:54 +0000 | [diff] [blame] | 1097 | Load = LegalizeOp(Load); |
| 1098 | AddLegalizedOperand(SDOperand(Node, 0), Result); |
| 1099 | AddLegalizedOperand(SDOperand(Node, 1), Load.getValue(1)); |
Andrew Lenharth | 9d416f7 | 2005-06-30 19:22:37 +0000 | [diff] [blame] | 1100 | if (Op.ResNo) |
| 1101 | return Load.getValue(1); |
| 1102 | return Result; |
| 1103 | } |
Chris Lattner | 01ff721 | 2005-04-10 22:54:25 +0000 | [diff] [blame] | 1104 | assert(Node->getOpcode() != ISD::EXTLOAD && |
| 1105 | "EXTLOAD should always be supported!"); |
| 1106 | // Turn the unsupported load into an EXTLOAD followed by an explicit |
| 1107 | // zero/sign extend inreg. |
Chris Lattner | 5f056bf | 2005-07-10 01:55:33 +0000 | [diff] [blame] | 1108 | Result = DAG.getExtLoad(ISD::EXTLOAD, Node->getValueType(0), |
| 1109 | Tmp1, Tmp2, Node->getOperand(2), SrcVT); |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 1110 | SDOperand ValRes; |
| 1111 | if (Node->getOpcode() == ISD::SEXTLOAD) |
| 1112 | ValRes = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(), |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 1113 | Result, DAG.getValueType(SrcVT)); |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 1114 | else |
| 1115 | ValRes = DAG.getZeroExtendInReg(Result, SrcVT); |
Chris Lattner | e773673 | 2005-12-18 23:54:29 +0000 | [diff] [blame] | 1116 | Result = LegalizeOp(Result); // Relegalize new nodes. |
| 1117 | ValRes = LegalizeOp(ValRes); // Relegalize new nodes. |
Chris Lattner | 69a889e | 2005-12-20 00:53:54 +0000 | [diff] [blame] | 1118 | AddLegalizedOperand(SDOperand(Node, 0), ValRes); |
| 1119 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
Chris Lattner | 01ff721 | 2005-04-10 22:54:25 +0000 | [diff] [blame] | 1120 | if (Op.ResNo) |
| 1121 | return Result.getValue(1); |
| 1122 | return ValRes; |
| 1123 | } |
| 1124 | assert(0 && "Unreachable"); |
| 1125 | } |
Nate Begeman | 5dc897b | 2005-10-19 00:06:56 +0000 | [diff] [blame] | 1126 | case ISD::EXTRACT_ELEMENT: { |
| 1127 | MVT::ValueType OpTy = Node->getOperand(0).getValueType(); |
| 1128 | switch (getTypeAction(OpTy)) { |
| 1129 | default: |
| 1130 | assert(0 && "EXTRACT_ELEMENT action for type unimplemented!"); |
| 1131 | break; |
| 1132 | case Legal: |
| 1133 | if (cast<ConstantSDNode>(Node->getOperand(1))->getValue()) { |
| 1134 | // 1 -> Hi |
| 1135 | Result = DAG.getNode(ISD::SRL, OpTy, Node->getOperand(0), |
| 1136 | DAG.getConstant(MVT::getSizeInBits(OpTy)/2, |
| 1137 | TLI.getShiftAmountTy())); |
| 1138 | Result = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0), Result); |
| 1139 | } else { |
| 1140 | // 0 -> Lo |
| 1141 | Result = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0), |
| 1142 | Node->getOperand(0)); |
| 1143 | } |
| 1144 | Result = LegalizeOp(Result); |
| 1145 | break; |
| 1146 | case Expand: |
| 1147 | // Get both the low and high parts. |
| 1148 | ExpandOp(Node->getOperand(0), Tmp1, Tmp2); |
| 1149 | if (cast<ConstantSDNode>(Node->getOperand(1))->getValue()) |
| 1150 | Result = Tmp2; // 1 -> Hi |
| 1151 | else |
| 1152 | Result = Tmp1; // 0 -> Lo |
| 1153 | break; |
| 1154 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1155 | break; |
Nate Begeman | 5dc897b | 2005-10-19 00:06:56 +0000 | [diff] [blame] | 1156 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1157 | |
| 1158 | case ISD::CopyToReg: |
| 1159 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 1160 | |
Chris Lattner | c9c60f6 | 2005-08-24 16:35:28 +0000 | [diff] [blame] | 1161 | assert(isTypeLegal(Node->getOperand(2).getValueType()) && |
Chris Lattner | d5d0f9b | 2005-08-16 21:55:35 +0000 | [diff] [blame] | 1162 | "Register type must be legal!"); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 1163 | // Legalize the incoming value (must be a legal type). |
Chris Lattner | d5d0f9b | 2005-08-16 21:55:35 +0000 | [diff] [blame] | 1164 | Tmp2 = LegalizeOp(Node->getOperand(2)); |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 1165 | if (Node->getNumValues() == 1) { |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 1166 | if (Tmp1 != Node->getOperand(0) || Tmp2 != Node->getOperand(2)) |
| 1167 | Result = DAG.getNode(ISD::CopyToReg, MVT::Other, Tmp1, |
| 1168 | Node->getOperand(1), Tmp2); |
| 1169 | } else { |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 1170 | assert(Node->getNumValues() == 2 && "Unknown CopyToReg"); |
| 1171 | if (Node->getNumOperands() == 4) |
| 1172 | Tmp3 = LegalizeOp(Node->getOperand(3)); |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 1173 | if (Tmp1 != Node->getOperand(0) || Tmp2 != Node->getOperand(2) || |
Chris Lattner | f1a47c3 | 2005-12-18 15:36:21 +0000 | [diff] [blame] | 1174 | (Node->getNumOperands() == 4 && Tmp3 != Node->getOperand(3))) { |
Chris Lattner | 7310fb1 | 2005-12-18 15:27:43 +0000 | [diff] [blame] | 1175 | unsigned Reg = cast<RegisterSDNode>(Node->getOperand(1))->getReg(); |
| 1176 | Result = DAG.getCopyToReg(Tmp1, Reg, Tmp2, Tmp3); |
| 1177 | } |
| 1178 | |
| 1179 | // Since this produces two values, make sure to remember that we legalized |
| 1180 | // both of them. |
| 1181 | AddLegalizedOperand(SDOperand(Node, 0), Result); |
| 1182 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
| 1183 | return Result.getValue(Op.ResNo); |
| 1184 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1185 | break; |
| 1186 | |
| 1187 | case ISD::RET: |
| 1188 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1189 | switch (Node->getNumOperands()) { |
| 1190 | case 2: // ret val |
| 1191 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 1192 | case Legal: |
| 1193 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
Chris Lattner | 8afc48e | 2005-01-07 22:28:47 +0000 | [diff] [blame] | 1194 | if (Tmp1 != Node->getOperand(0) || Tmp2 != Node->getOperand(1)) |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1195 | Result = DAG.getNode(ISD::RET, MVT::Other, Tmp1, Tmp2); |
| 1196 | break; |
| 1197 | case Expand: { |
| 1198 | SDOperand Lo, Hi; |
| 1199 | ExpandOp(Node->getOperand(1), Lo, Hi); |
| 1200 | Result = DAG.getNode(ISD::RET, MVT::Other, Tmp1, Lo, Hi); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 1201 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1202 | } |
| 1203 | case Promote: |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 1204 | Tmp2 = PromoteOp(Node->getOperand(1)); |
| 1205 | Result = DAG.getNode(ISD::RET, MVT::Other, Tmp1, Tmp2); |
| 1206 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1207 | } |
| 1208 | break; |
| 1209 | case 1: // ret void |
| 1210 | if (Tmp1 != Node->getOperand(0)) |
| 1211 | Result = DAG.getNode(ISD::RET, MVT::Other, Tmp1); |
| 1212 | break; |
| 1213 | default: { // ret <values> |
| 1214 | std::vector<SDOperand> NewValues; |
| 1215 | NewValues.push_back(Tmp1); |
| 1216 | for (unsigned i = 1, e = Node->getNumOperands(); i != e; ++i) |
| 1217 | switch (getTypeAction(Node->getOperand(i).getValueType())) { |
| 1218 | case Legal: |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 1219 | NewValues.push_back(LegalizeOp(Node->getOperand(i))); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1220 | break; |
| 1221 | case Expand: { |
| 1222 | SDOperand Lo, Hi; |
| 1223 | ExpandOp(Node->getOperand(i), Lo, Hi); |
| 1224 | NewValues.push_back(Lo); |
| 1225 | NewValues.push_back(Hi); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 1226 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1227 | } |
| 1228 | case Promote: |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 1229 | assert(0 && "Can't promote multiple return value yet!"); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1230 | } |
| 1231 | Result = DAG.getNode(ISD::RET, MVT::Other, NewValues); |
| 1232 | break; |
| 1233 | } |
| 1234 | } |
| 1235 | break; |
| 1236 | case ISD::STORE: |
| 1237 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1238 | Tmp2 = LegalizeOp(Node->getOperand(2)); // Legalize the pointer. |
| 1239 | |
Chris Lattner | 5d2c6c7 | 2005-01-08 06:25:56 +0000 | [diff] [blame] | 1240 | // Turn 'store float 1.0, Ptr' -> 'store int 0x12345678, Ptr' |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 1241 | if (ConstantFPSDNode *CFP =dyn_cast<ConstantFPSDNode>(Node->getOperand(1))){ |
Chris Lattner | 5d2c6c7 | 2005-01-08 06:25:56 +0000 | [diff] [blame] | 1242 | if (CFP->getValueType(0) == MVT::f32) { |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 1243 | Result = DAG.getNode(ISD::STORE, MVT::Other, Tmp1, |
Jim Laskey | cb6682f | 2005-08-17 19:34:49 +0000 | [diff] [blame] | 1244 | DAG.getConstant(FloatToBits(CFP->getValue()), |
| 1245 | MVT::i32), |
| 1246 | Tmp2, |
Chris Lattner | 52d08bd | 2005-05-09 20:23:03 +0000 | [diff] [blame] | 1247 | Node->getOperand(3)); |
Chris Lattner | 5d2c6c7 | 2005-01-08 06:25:56 +0000 | [diff] [blame] | 1248 | } else { |
| 1249 | assert(CFP->getValueType(0) == MVT::f64 && "Unknown FP type!"); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 1250 | Result = DAG.getNode(ISD::STORE, MVT::Other, Tmp1, |
Jim Laskey | cb6682f | 2005-08-17 19:34:49 +0000 | [diff] [blame] | 1251 | DAG.getConstant(DoubleToBits(CFP->getValue()), |
| 1252 | MVT::i64), |
| 1253 | Tmp2, |
Chris Lattner | 52d08bd | 2005-05-09 20:23:03 +0000 | [diff] [blame] | 1254 | Node->getOperand(3)); |
Chris Lattner | 5d2c6c7 | 2005-01-08 06:25:56 +0000 | [diff] [blame] | 1255 | } |
Chris Lattner | 84734ce | 2005-02-22 07:23:39 +0000 | [diff] [blame] | 1256 | Node = Result.Val; |
Chris Lattner | 5d2c6c7 | 2005-01-08 06:25:56 +0000 | [diff] [blame] | 1257 | } |
| 1258 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1259 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 1260 | case Legal: { |
| 1261 | SDOperand Val = LegalizeOp(Node->getOperand(1)); |
| 1262 | if (Val != Node->getOperand(1) || Tmp1 != Node->getOperand(0) || |
| 1263 | Tmp2 != Node->getOperand(2)) |
Chris Lattner | 52d08bd | 2005-05-09 20:23:03 +0000 | [diff] [blame] | 1264 | Result = DAG.getNode(ISD::STORE, MVT::Other, Tmp1, Val, Tmp2, |
| 1265 | Node->getOperand(3)); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1266 | break; |
| 1267 | } |
| 1268 | case Promote: |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 1269 | // Truncate the value and store the result. |
| 1270 | Tmp3 = PromoteOp(Node->getOperand(1)); |
| 1271 | Result = DAG.getNode(ISD::TRUNCSTORE, MVT::Other, Tmp1, Tmp3, Tmp2, |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 1272 | Node->getOperand(3), |
Chris Lattner | 9fadb4c | 2005-07-10 00:29:18 +0000 | [diff] [blame] | 1273 | DAG.getValueType(Node->getOperand(1).getValueType())); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 1274 | break; |
| 1275 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1276 | case Expand: |
| 1277 | SDOperand Lo, Hi; |
Nate Begeman | ab48be3 | 2005-11-22 18:16:00 +0000 | [diff] [blame] | 1278 | unsigned IncrementSize; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1279 | ExpandOp(Node->getOperand(1), Lo, Hi); |
| 1280 | |
| 1281 | if (!TLI.isLittleEndian()) |
| 1282 | std::swap(Lo, Hi); |
| 1283 | |
Chris Lattner | edb1add | 2005-05-11 04:51:16 +0000 | [diff] [blame] | 1284 | Lo = DAG.getNode(ISD::STORE, MVT::Other, Tmp1, Lo, Tmp2, |
| 1285 | Node->getOperand(3)); |
Nate Begeman | ab48be3 | 2005-11-22 18:16:00 +0000 | [diff] [blame] | 1286 | // If this is a vector type, then we have to calculate the increment as |
| 1287 | // the product of the element size in bytes, and the number of elements |
| 1288 | // in the high half of the vector. |
| 1289 | if (MVT::Vector == Hi.getValueType()) { |
| 1290 | unsigned NumElems = cast<ConstantSDNode>(Hi.getOperand(2))->getValue(); |
| 1291 | MVT::ValueType EVT = cast<VTSDNode>(Hi.getOperand(3))->getVT(); |
| 1292 | IncrementSize = NumElems * MVT::getSizeInBits(EVT)/8; |
| 1293 | } else { |
| 1294 | IncrementSize = MVT::getSizeInBits(Hi.getValueType())/8; |
| 1295 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1296 | Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2, |
| 1297 | getIntPtrConstant(IncrementSize)); |
| 1298 | assert(isTypeLegal(Tmp2.getValueType()) && |
| 1299 | "Pointers must be legal!"); |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 1300 | //Again, claiming both parts of the store came form the same Instr |
Chris Lattner | edb1add | 2005-05-11 04:51:16 +0000 | [diff] [blame] | 1301 | Hi = DAG.getNode(ISD::STORE, MVT::Other, Tmp1, Hi, Tmp2, |
| 1302 | Node->getOperand(3)); |
Chris Lattner | ec39a45 | 2005-01-19 18:02:17 +0000 | [diff] [blame] | 1303 | Result = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo, Hi); |
| 1304 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1305 | } |
| 1306 | break; |
Andrew Lenharth | 9576212 | 2005-03-31 21:24:06 +0000 | [diff] [blame] | 1307 | case ISD::PCMARKER: |
| 1308 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 1309 | if (Tmp1 != Node->getOperand(0)) |
| 1310 | Result = DAG.getNode(ISD::PCMARKER, MVT::Other, Tmp1,Node->getOperand(1)); |
Andrew Lenharth | 9576212 | 2005-03-31 21:24:06 +0000 | [diff] [blame] | 1311 | break; |
Andrew Lenharth | 51b8d54 | 2005-11-11 16:47:30 +0000 | [diff] [blame] | 1312 | case ISD::READCYCLECOUNTER: |
| 1313 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain |
Andrew Lenharth | cde0f5c | 2005-12-02 06:08:08 +0000 | [diff] [blame] | 1314 | if (Tmp1 != Node->getOperand(0)) { |
| 1315 | std::vector<MVT::ValueType> rtypes; |
| 1316 | std::vector<SDOperand> rvals; |
| 1317 | rtypes.push_back(MVT::i64); |
| 1318 | rtypes.push_back(MVT::Other); |
| 1319 | rvals.push_back(Tmp1); |
| 1320 | Result = DAG.getNode(ISD::READCYCLECOUNTER, rtypes, rvals); |
| 1321 | } |
Andrew Lenharth | 49c709f | 2005-12-02 04:56:24 +0000 | [diff] [blame] | 1322 | |
| 1323 | // Since rdcc produce two values, make sure to remember that we legalized |
| 1324 | // both of them. |
| 1325 | AddLegalizedOperand(SDOperand(Node, 0), Result); |
| 1326 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
| 1327 | return Result.getValue(Op.ResNo); |
Andrew Lenharth | f70e30b | 2005-11-20 21:32:07 +0000 | [diff] [blame] | 1328 | |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 1329 | case ISD::TRUNCSTORE: |
| 1330 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1331 | Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the pointer. |
| 1332 | |
| 1333 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 1334 | case Legal: |
| 1335 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
Chris Lattner | 13d58e7 | 2005-09-10 00:20:18 +0000 | [diff] [blame] | 1336 | |
| 1337 | // The only promote case we handle is TRUNCSTORE:i1 X into |
| 1338 | // -> TRUNCSTORE:i8 (and X, 1) |
| 1339 | if (cast<VTSDNode>(Node->getOperand(4))->getVT() == MVT::i1 && |
| 1340 | TLI.getOperationAction(ISD::TRUNCSTORE, MVT::i1) == |
| 1341 | TargetLowering::Promote) { |
| 1342 | // Promote the bool to a mask then store. |
| 1343 | Tmp2 = DAG.getNode(ISD::AND, Tmp2.getValueType(), Tmp2, |
| 1344 | DAG.getConstant(1, Tmp2.getValueType())); |
| 1345 | Result = DAG.getNode(ISD::TRUNCSTORE, MVT::Other, Tmp1, Tmp2, Tmp3, |
| 1346 | Node->getOperand(3), DAG.getValueType(MVT::i8)); |
| 1347 | |
| 1348 | } else if (Tmp1 != Node->getOperand(0) || Tmp2 != Node->getOperand(1) || |
| 1349 | Tmp3 != Node->getOperand(2)) { |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 1350 | Result = DAG.getNode(ISD::TRUNCSTORE, MVT::Other, Tmp1, Tmp2, Tmp3, |
Chris Lattner | 9fadb4c | 2005-07-10 00:29:18 +0000 | [diff] [blame] | 1351 | Node->getOperand(3), Node->getOperand(4)); |
Chris Lattner | 13d58e7 | 2005-09-10 00:20:18 +0000 | [diff] [blame] | 1352 | } |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 1353 | break; |
| 1354 | case Promote: |
| 1355 | case Expand: |
| 1356 | assert(0 && "Cannot handle illegal TRUNCSTORE yet!"); |
| 1357 | } |
| 1358 | break; |
Chris Lattner | 2ee743f | 2005-01-14 22:08:15 +0000 | [diff] [blame] | 1359 | case ISD::SELECT: |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 1360 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 1361 | case Expand: assert(0 && "It's impossible to expand bools"); |
| 1362 | case Legal: |
| 1363 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the condition. |
| 1364 | break; |
| 1365 | case Promote: |
| 1366 | Tmp1 = PromoteOp(Node->getOperand(0)); // Promote the condition. |
| 1367 | break; |
| 1368 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1369 | Tmp2 = LegalizeOp(Node->getOperand(1)); // TrueVal |
Chris Lattner | 2ee743f | 2005-01-14 22:08:15 +0000 | [diff] [blame] | 1370 | Tmp3 = LegalizeOp(Node->getOperand(2)); // FalseVal |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 1371 | |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 1372 | switch (TLI.getOperationAction(ISD::SELECT, Tmp2.getValueType())) { |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 1373 | default: assert(0 && "This action is not supported yet!"); |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 1374 | case TargetLowering::Expand: |
| 1375 | if (Tmp1.getOpcode() == ISD::SETCC) { |
| 1376 | Result = DAG.getSelectCC(Tmp1.getOperand(0), Tmp1.getOperand(1), |
| 1377 | Tmp2, Tmp3, |
| 1378 | cast<CondCodeSDNode>(Tmp1.getOperand(2))->get()); |
| 1379 | } else { |
Chris Lattner | 550b1e5 | 2005-08-21 18:03:09 +0000 | [diff] [blame] | 1380 | // Make sure the condition is either zero or one. It may have been |
| 1381 | // promoted from something else. |
| 1382 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, MVT::i1); |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 1383 | Result = DAG.getSelectCC(Tmp1, |
| 1384 | DAG.getConstant(0, Tmp1.getValueType()), |
| 1385 | Tmp2, Tmp3, ISD::SETNE); |
| 1386 | } |
Chris Lattner | e773673 | 2005-12-18 23:54:29 +0000 | [diff] [blame] | 1387 | Result = LegalizeOp(Result); // Relegalize new nodes. |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 1388 | break; |
Evan Cheng | 7df96d6 | 2005-12-17 01:21:05 +0000 | [diff] [blame] | 1389 | case TargetLowering::Custom: { |
| 1390 | SDOperand Tmp = |
| 1391 | TLI.LowerOperation(DAG.getNode(ISD::SELECT, Node->getValueType(0), |
| 1392 | Tmp1, Tmp2, Tmp3), DAG); |
| 1393 | if (Tmp.Val) { |
| 1394 | Result = LegalizeOp(Tmp); |
| 1395 | break; |
| 1396 | } |
| 1397 | // FALLTHROUGH if the target thinks it is legal. |
| 1398 | } |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 1399 | case TargetLowering::Legal: |
| 1400 | if (Tmp1 != Node->getOperand(0) || Tmp2 != Node->getOperand(1) || |
| 1401 | Tmp3 != Node->getOperand(2)) |
| 1402 | Result = DAG.getNode(ISD::SELECT, Node->getValueType(0), |
| 1403 | Tmp1, Tmp2, Tmp3); |
| 1404 | break; |
| 1405 | case TargetLowering::Promote: { |
| 1406 | MVT::ValueType NVT = |
| 1407 | TLI.getTypeToPromoteTo(ISD::SELECT, Tmp2.getValueType()); |
| 1408 | unsigned ExtOp, TruncOp; |
| 1409 | if (MVT::isInteger(Tmp2.getValueType())) { |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 1410 | ExtOp = ISD::ANY_EXTEND; |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 1411 | TruncOp = ISD::TRUNCATE; |
| 1412 | } else { |
| 1413 | ExtOp = ISD::FP_EXTEND; |
| 1414 | TruncOp = ISD::FP_ROUND; |
| 1415 | } |
| 1416 | // Promote each of the values to the new type. |
| 1417 | Tmp2 = DAG.getNode(ExtOp, NVT, Tmp2); |
| 1418 | Tmp3 = DAG.getNode(ExtOp, NVT, Tmp3); |
| 1419 | // Perform the larger operation, then round down. |
| 1420 | Result = DAG.getNode(ISD::SELECT, NVT, Tmp1, Tmp2,Tmp3); |
| 1421 | Result = DAG.getNode(TruncOp, Node->getValueType(0), Result); |
| 1422 | break; |
| 1423 | } |
| 1424 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1425 | break; |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 1426 | case ISD::SELECT_CC: |
| 1427 | Tmp3 = LegalizeOp(Node->getOperand(2)); // True |
| 1428 | Tmp4 = LegalizeOp(Node->getOperand(3)); // False |
| 1429 | |
Chris Lattner | c9c60f6 | 2005-08-24 16:35:28 +0000 | [diff] [blame] | 1430 | if (isTypeLegal(Node->getOperand(0).getValueType())) { |
Chris Lattner | 23004e5 | 2005-08-26 00:23:59 +0000 | [diff] [blame] | 1431 | // Everything is legal, see if we should expand this op or something. |
| 1432 | switch (TLI.getOperationAction(ISD::SELECT_CC, |
| 1433 | Node->getOperand(0).getValueType())) { |
| 1434 | default: assert(0 && "This action is not supported yet!"); |
| 1435 | case TargetLowering::Custom: { |
| 1436 | SDOperand Tmp = |
| 1437 | TLI.LowerOperation(DAG.getNode(ISD::SELECT_CC, Node->getValueType(0), |
| 1438 | Node->getOperand(0), |
| 1439 | Node->getOperand(1), Tmp3, Tmp4, |
Chris Lattner | d7050a9 | 2005-08-26 00:43:46 +0000 | [diff] [blame] | 1440 | Node->getOperand(4)), DAG); |
Chris Lattner | 23004e5 | 2005-08-26 00:23:59 +0000 | [diff] [blame] | 1441 | if (Tmp.Val) { |
| 1442 | Result = LegalizeOp(Tmp); |
| 1443 | break; |
| 1444 | } |
| 1445 | } // FALLTHROUGH if the target can't lower this operation after all. |
| 1446 | case TargetLowering::Legal: |
| 1447 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
| 1448 | Tmp2 = LegalizeOp(Node->getOperand(1)); // RHS |
| 1449 | if (Tmp1 != Node->getOperand(0) || Tmp2 != Node->getOperand(1) || |
| 1450 | Tmp3 != Node->getOperand(2) || Tmp4 != Node->getOperand(3)) { |
Chris Lattner | 1ccf26a | 2005-12-22 05:23:45 +0000 | [diff] [blame] | 1451 | Result = DAG.getNode(ISD::SELECT_CC, Node->getValueType(0), Tmp1,Tmp2, |
Chris Lattner | 23004e5 | 2005-08-26 00:23:59 +0000 | [diff] [blame] | 1452 | Tmp3, Tmp4, Node->getOperand(4)); |
| 1453 | } |
| 1454 | break; |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 1455 | } |
| 1456 | break; |
| 1457 | } else { |
| 1458 | Tmp1 = LegalizeOp(DAG.getNode(ISD::SETCC, TLI.getSetCCResultTy(), |
| 1459 | Node->getOperand(0), // LHS |
| 1460 | Node->getOperand(1), // RHS |
| 1461 | Node->getOperand(4))); |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 1462 | // If we get a SETCC back from legalizing the SETCC node we just |
| 1463 | // created, then use its LHS, RHS, and CC directly in creating a new |
| 1464 | // node. Otherwise, select between the true and false value based on |
| 1465 | // comparing the result of the legalized with zero. |
| 1466 | if (Tmp1.getOpcode() == ISD::SETCC) { |
| 1467 | Result = DAG.getNode(ISD::SELECT_CC, Tmp3.getValueType(), |
| 1468 | Tmp1.getOperand(0), Tmp1.getOperand(1), |
| 1469 | Tmp3, Tmp4, Tmp1.getOperand(2)); |
| 1470 | } else { |
| 1471 | Result = DAG.getSelectCC(Tmp1, |
| 1472 | DAG.getConstant(0, Tmp1.getValueType()), |
| 1473 | Tmp3, Tmp4, ISD::SETNE); |
| 1474 | } |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 1475 | } |
| 1476 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1477 | case ISD::SETCC: |
| 1478 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 1479 | case Legal: |
| 1480 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
| 1481 | Tmp2 = LegalizeOp(Node->getOperand(1)); // RHS |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1482 | break; |
| 1483 | case Promote: |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 1484 | Tmp1 = PromoteOp(Node->getOperand(0)); // LHS |
| 1485 | Tmp2 = PromoteOp(Node->getOperand(1)); // RHS |
| 1486 | |
| 1487 | // If this is an FP compare, the operands have already been extended. |
| 1488 | if (MVT::isInteger(Node->getOperand(0).getValueType())) { |
| 1489 | MVT::ValueType VT = Node->getOperand(0).getValueType(); |
Chris Lattner | 71c42a0 | 2005-01-16 01:11:45 +0000 | [diff] [blame] | 1490 | MVT::ValueType NVT = TLI.getTypeToTransformTo(VT); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 1491 | |
| 1492 | // Otherwise, we have to insert explicit sign or zero extends. Note |
| 1493 | // that we could insert sign extends for ALL conditions, but zero extend |
| 1494 | // is cheaper on many machines (an AND instead of two shifts), so prefer |
| 1495 | // it. |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 1496 | switch (cast<CondCodeSDNode>(Node->getOperand(2))->get()) { |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 1497 | default: assert(0 && "Unknown integer comparison!"); |
| 1498 | case ISD::SETEQ: |
| 1499 | case ISD::SETNE: |
| 1500 | case ISD::SETUGE: |
| 1501 | case ISD::SETUGT: |
| 1502 | case ISD::SETULE: |
| 1503 | case ISD::SETULT: |
| 1504 | // ALL of these operations will work if we either sign or zero extend |
| 1505 | // the operands (including the unsigned comparisons!). Zero extend is |
| 1506 | // usually a simpler/cheaper operation, so prefer it. |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 1507 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, VT); |
| 1508 | Tmp2 = DAG.getZeroExtendInReg(Tmp2, VT); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 1509 | break; |
| 1510 | case ISD::SETGE: |
| 1511 | case ISD::SETGT: |
| 1512 | case ISD::SETLT: |
| 1513 | case ISD::SETLE: |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 1514 | Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp1, |
| 1515 | DAG.getValueType(VT)); |
| 1516 | Tmp2 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp2, |
| 1517 | DAG.getValueType(VT)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 1518 | break; |
| 1519 | } |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 1520 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1521 | break; |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 1522 | case Expand: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1523 | SDOperand LHSLo, LHSHi, RHSLo, RHSHi; |
| 1524 | ExpandOp(Node->getOperand(0), LHSLo, LHSHi); |
| 1525 | ExpandOp(Node->getOperand(1), RHSLo, RHSHi); |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 1526 | switch (cast<CondCodeSDNode>(Node->getOperand(2))->get()) { |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1527 | case ISD::SETEQ: |
| 1528 | case ISD::SETNE: |
Chris Lattner | 08b698e | 2005-04-12 01:46:05 +0000 | [diff] [blame] | 1529 | if (RHSLo == RHSHi) |
| 1530 | if (ConstantSDNode *RHSCST = dyn_cast<ConstantSDNode>(RHSLo)) |
| 1531 | if (RHSCST->isAllOnesValue()) { |
| 1532 | // Comparison to -1. |
| 1533 | Tmp1 = DAG.getNode(ISD::AND, LHSLo.getValueType(), LHSLo, LHSHi); |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 1534 | Tmp2 = RHSLo; |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 1535 | break; |
Chris Lattner | 08b698e | 2005-04-12 01:46:05 +0000 | [diff] [blame] | 1536 | } |
| 1537 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1538 | Tmp1 = DAG.getNode(ISD::XOR, LHSLo.getValueType(), LHSLo, RHSLo); |
| 1539 | Tmp2 = DAG.getNode(ISD::XOR, LHSLo.getValueType(), LHSHi, RHSHi); |
| 1540 | Tmp1 = DAG.getNode(ISD::OR, Tmp1.getValueType(), Tmp1, Tmp2); |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 1541 | Tmp2 = DAG.getConstant(0, Tmp1.getValueType()); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1542 | break; |
| 1543 | default: |
Chris Lattner | 5b95ed6 | 2005-04-12 02:19:10 +0000 | [diff] [blame] | 1544 | // If this is a comparison of the sign bit, just look at the top part. |
| 1545 | // X > -1, x < 0 |
| 1546 | if (ConstantSDNode *CST = dyn_cast<ConstantSDNode>(Node->getOperand(1))) |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 1547 | if ((cast<CondCodeSDNode>(Node->getOperand(2))->get() == ISD::SETLT && |
Chris Lattner | 5b95ed6 | 2005-04-12 02:19:10 +0000 | [diff] [blame] | 1548 | CST->getValue() == 0) || // X < 0 |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 1549 | (cast<CondCodeSDNode>(Node->getOperand(2))->get() == ISD::SETGT && |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 1550 | (CST->isAllOnesValue()))) { // X > -1 |
| 1551 | Tmp1 = LHSHi; |
| 1552 | Tmp2 = RHSHi; |
| 1553 | break; |
| 1554 | } |
Chris Lattner | 5b95ed6 | 2005-04-12 02:19:10 +0000 | [diff] [blame] | 1555 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1556 | // FIXME: This generated code sucks. |
| 1557 | ISD::CondCode LowCC; |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 1558 | switch (cast<CondCodeSDNode>(Node->getOperand(2))->get()) { |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1559 | default: assert(0 && "Unknown integer setcc!"); |
| 1560 | case ISD::SETLT: |
| 1561 | case ISD::SETULT: LowCC = ISD::SETULT; break; |
| 1562 | case ISD::SETGT: |
| 1563 | case ISD::SETUGT: LowCC = ISD::SETUGT; break; |
| 1564 | case ISD::SETLE: |
| 1565 | case ISD::SETULE: LowCC = ISD::SETULE; break; |
| 1566 | case ISD::SETGE: |
| 1567 | case ISD::SETUGE: LowCC = ISD::SETUGE; break; |
| 1568 | } |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 1569 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1570 | // Tmp1 = lo(op1) < lo(op2) // Always unsigned comparison |
| 1571 | // Tmp2 = hi(op1) < hi(op2) // Signedness depends on operands |
| 1572 | // dest = hi(op1) == hi(op2) ? Tmp1 : Tmp2; |
| 1573 | |
| 1574 | // NOTE: on targets without efficient SELECT of bools, we can always use |
| 1575 | // this identity: (B1 ? B2 : B3) --> (B1 & B2)|(!B1&B3) |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 1576 | Tmp1 = DAG.getSetCC(Node->getValueType(0), LHSLo, RHSLo, LowCC); |
| 1577 | Tmp2 = DAG.getNode(ISD::SETCC, Node->getValueType(0), LHSHi, RHSHi, |
| 1578 | Node->getOperand(2)); |
| 1579 | Result = DAG.getSetCC(Node->getValueType(0), LHSHi, RHSHi, ISD::SETEQ); |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 1580 | Result = LegalizeOp(DAG.getNode(ISD::SELECT, Tmp1.getValueType(), |
| 1581 | Result, Tmp1, Tmp2)); |
Chris Lattner | 69a889e | 2005-12-20 00:53:54 +0000 | [diff] [blame] | 1582 | AddLegalizedOperand(SDOperand(Node, 0), Result); |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 1583 | return Result; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1584 | } |
| 1585 | } |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 1586 | |
Chris Lattner | 1ccf26a | 2005-12-22 05:23:45 +0000 | [diff] [blame] | 1587 | switch(TLI.getOperationAction(ISD::SETCC, |
| 1588 | Node->getOperand(0).getValueType())) { |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 1589 | default: |
| 1590 | assert(0 && "Cannot handle this action for SETCC yet!"); |
| 1591 | break; |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 1592 | case TargetLowering::Promote: { |
| 1593 | // First step, figure out the appropriate operation to use. |
| 1594 | // Allow SETCC to not be supported for all legal data types |
| 1595 | // Mostly this targets FP |
| 1596 | MVT::ValueType NewInTy = Node->getOperand(0).getValueType(); |
| 1597 | MVT::ValueType OldVT = NewInTy; |
| 1598 | |
| 1599 | // Scan for the appropriate larger type to use. |
| 1600 | while (1) { |
| 1601 | NewInTy = (MVT::ValueType)(NewInTy+1); |
| 1602 | |
| 1603 | assert(MVT::isInteger(NewInTy) == MVT::isInteger(OldVT) && |
| 1604 | "Fell off of the edge of the integer world"); |
| 1605 | assert(MVT::isFloatingPoint(NewInTy) == MVT::isFloatingPoint(OldVT) && |
| 1606 | "Fell off of the edge of the floating point world"); |
| 1607 | |
| 1608 | // If the target supports SETCC of this type, use it. |
Chris Lattner | 1ccf26a | 2005-12-22 05:23:45 +0000 | [diff] [blame] | 1609 | if (TLI.isOperationLegal(ISD::SETCC, NewInTy)) |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 1610 | break; |
| 1611 | } |
| 1612 | if (MVT::isInteger(NewInTy)) |
| 1613 | assert(0 && "Cannot promote Legal Integer SETCC yet"); |
| 1614 | else { |
| 1615 | Tmp1 = DAG.getNode(ISD::FP_EXTEND, NewInTy, Tmp1); |
| 1616 | Tmp2 = DAG.getNode(ISD::FP_EXTEND, NewInTy, Tmp2); |
| 1617 | } |
| 1618 | |
Andrew Lenharth | 5e3efbc | 2005-08-29 20:46:51 +0000 | [diff] [blame] | 1619 | Result = DAG.getNode(ISD::SETCC, Node->getValueType(0), Tmp1, Tmp2, |
| 1620 | Node->getOperand(2)); |
| 1621 | break; |
Andrew Lenharth | ae35575 | 2005-11-30 17:12:26 +0000 | [diff] [blame] | 1622 | } |
Evan Cheng | d5781fc | 2005-12-21 20:21:51 +0000 | [diff] [blame] | 1623 | case TargetLowering::Custom: { |
| 1624 | SDOperand Tmp = |
| 1625 | TLI.LowerOperation(DAG.getNode(ISD::SETCC, Node->getValueType(0), |
| 1626 | Tmp1, Tmp2, Node->getOperand(2)), DAG); |
| 1627 | if (Tmp.Val) { |
| 1628 | Result = LegalizeOp(Tmp); |
| 1629 | break; |
| 1630 | } |
| 1631 | // FALLTHROUGH if the target thinks it is legal. |
| 1632 | } |
Nate Begeman | b942a3d | 2005-08-23 04:29:48 +0000 | [diff] [blame] | 1633 | case TargetLowering::Legal: |
| 1634 | if (Tmp1 != Node->getOperand(0) || Tmp2 != Node->getOperand(1)) |
| 1635 | Result = DAG.getNode(ISD::SETCC, Node->getValueType(0), Tmp1, Tmp2, |
| 1636 | Node->getOperand(2)); |
| 1637 | break; |
| 1638 | case TargetLowering::Expand: |
| 1639 | // Expand a setcc node into a select_cc of the same condition, lhs, and |
| 1640 | // rhs that selects between const 1 (true) and const 0 (false). |
| 1641 | MVT::ValueType VT = Node->getValueType(0); |
| 1642 | Result = DAG.getNode(ISD::SELECT_CC, VT, Tmp1, Tmp2, |
| 1643 | DAG.getConstant(1, VT), DAG.getConstant(0, VT), |
| 1644 | Node->getOperand(2)); |
| 1645 | Result = LegalizeOp(Result); |
| 1646 | break; |
| 1647 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1648 | break; |
| 1649 | |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 1650 | case ISD::MEMSET: |
| 1651 | case ISD::MEMCPY: |
| 1652 | case ISD::MEMMOVE: { |
Chris Lattner | deb692e | 2005-02-01 18:38:28 +0000 | [diff] [blame] | 1653 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Chain |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 1654 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Pointer |
| 1655 | |
| 1656 | if (Node->getOpcode() == ISD::MEMSET) { // memset = ubyte |
| 1657 | switch (getTypeAction(Node->getOperand(2).getValueType())) { |
| 1658 | case Expand: assert(0 && "Cannot expand a byte!"); |
| 1659 | case Legal: |
Chris Lattner | deb692e | 2005-02-01 18:38:28 +0000 | [diff] [blame] | 1660 | Tmp3 = LegalizeOp(Node->getOperand(2)); |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 1661 | break; |
| 1662 | case Promote: |
Chris Lattner | deb692e | 2005-02-01 18:38:28 +0000 | [diff] [blame] | 1663 | Tmp3 = PromoteOp(Node->getOperand(2)); |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 1664 | break; |
| 1665 | } |
| 1666 | } else { |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 1667 | Tmp3 = LegalizeOp(Node->getOperand(2)); // memcpy/move = pointer, |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 1668 | } |
Chris Lattner | 272455b | 2005-02-02 03:44:41 +0000 | [diff] [blame] | 1669 | |
| 1670 | SDOperand Tmp4; |
| 1671 | switch (getTypeAction(Node->getOperand(3).getValueType())) { |
Chris Lattner | 6814f15 | 2005-07-13 01:42:45 +0000 | [diff] [blame] | 1672 | case Expand: { |
| 1673 | // Length is too big, just take the lo-part of the length. |
| 1674 | SDOperand HiPart; |
| 1675 | ExpandOp(Node->getOperand(3), HiPart, Tmp4); |
| 1676 | break; |
| 1677 | } |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 1678 | case Legal: |
| 1679 | Tmp4 = LegalizeOp(Node->getOperand(3)); |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 1680 | break; |
| 1681 | case Promote: |
| 1682 | Tmp4 = PromoteOp(Node->getOperand(3)); |
Chris Lattner | 272455b | 2005-02-02 03:44:41 +0000 | [diff] [blame] | 1683 | break; |
| 1684 | } |
| 1685 | |
| 1686 | SDOperand Tmp5; |
| 1687 | switch (getTypeAction(Node->getOperand(4).getValueType())) { // uint |
| 1688 | case Expand: assert(0 && "Cannot expand this yet!"); |
| 1689 | case Legal: |
| 1690 | Tmp5 = LegalizeOp(Node->getOperand(4)); |
| 1691 | break; |
| 1692 | case Promote: |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 1693 | Tmp5 = PromoteOp(Node->getOperand(4)); |
| 1694 | break; |
| 1695 | } |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 1696 | |
| 1697 | switch (TLI.getOperationAction(Node->getOpcode(), MVT::Other)) { |
| 1698 | default: assert(0 && "This action not implemented for this operation!"); |
Chris Lattner | 07dffd6 | 2005-08-26 00:14:16 +0000 | [diff] [blame] | 1699 | case TargetLowering::Custom: { |
| 1700 | SDOperand Tmp = |
| 1701 | TLI.LowerOperation(DAG.getNode(Node->getOpcode(), MVT::Other, Tmp1, |
| 1702 | Tmp2, Tmp3, Tmp4, Tmp5), DAG); |
| 1703 | if (Tmp.Val) { |
| 1704 | Result = LegalizeOp(Tmp); |
| 1705 | break; |
| 1706 | } |
| 1707 | // FALLTHROUGH if the target thinks it is legal. |
| 1708 | } |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 1709 | case TargetLowering::Legal: |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 1710 | if (Tmp1 != Node->getOperand(0) || Tmp2 != Node->getOperand(1) || |
| 1711 | Tmp3 != Node->getOperand(2) || Tmp4 != Node->getOperand(3) || |
| 1712 | Tmp5 != Node->getOperand(4)) { |
| 1713 | std::vector<SDOperand> Ops; |
| 1714 | Ops.push_back(Tmp1); Ops.push_back(Tmp2); Ops.push_back(Tmp3); |
| 1715 | Ops.push_back(Tmp4); Ops.push_back(Tmp5); |
| 1716 | Result = DAG.getNode(Node->getOpcode(), MVT::Other, Ops); |
| 1717 | } |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 1718 | break; |
| 1719 | case TargetLowering::Expand: { |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 1720 | // Otherwise, the target does not support this operation. Lower the |
| 1721 | // operation to an explicit libcall as appropriate. |
| 1722 | MVT::ValueType IntPtr = TLI.getPointerTy(); |
| 1723 | const Type *IntPtrTy = TLI.getTargetData().getIntPtrType(); |
| 1724 | std::vector<std::pair<SDOperand, const Type*> > Args; |
| 1725 | |
Reid Spencer | 3bfbf4e | 2005-01-12 14:53:45 +0000 | [diff] [blame] | 1726 | const char *FnName = 0; |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 1727 | if (Node->getOpcode() == ISD::MEMSET) { |
| 1728 | Args.push_back(std::make_pair(Tmp2, IntPtrTy)); |
| 1729 | // Extend the ubyte argument to be an int value for the call. |
| 1730 | Tmp3 = DAG.getNode(ISD::ZERO_EXTEND, MVT::i32, Tmp3); |
| 1731 | Args.push_back(std::make_pair(Tmp3, Type::IntTy)); |
| 1732 | Args.push_back(std::make_pair(Tmp4, IntPtrTy)); |
| 1733 | |
| 1734 | FnName = "memset"; |
| 1735 | } else if (Node->getOpcode() == ISD::MEMCPY || |
| 1736 | Node->getOpcode() == ISD::MEMMOVE) { |
| 1737 | Args.push_back(std::make_pair(Tmp2, IntPtrTy)); |
| 1738 | Args.push_back(std::make_pair(Tmp3, IntPtrTy)); |
| 1739 | Args.push_back(std::make_pair(Tmp4, IntPtrTy)); |
| 1740 | FnName = Node->getOpcode() == ISD::MEMMOVE ? "memmove" : "memcpy"; |
| 1741 | } else { |
| 1742 | assert(0 && "Unknown op!"); |
| 1743 | } |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 1744 | |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 1745 | std::pair<SDOperand,SDOperand> CallResult = |
Chris Lattner | adf6a96 | 2005-05-13 18:50:42 +0000 | [diff] [blame] | 1746 | TLI.LowerCallTo(Tmp1, Type::VoidTy, false, CallingConv::C, false, |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 1747 | DAG.getExternalSymbol(FnName, IntPtr), Args, DAG); |
Chris Lattner | 69a889e | 2005-12-20 00:53:54 +0000 | [diff] [blame] | 1748 | Result = LegalizeOp(CallResult.second); |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 1749 | break; |
| 1750 | } |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 1751 | } |
| 1752 | break; |
| 1753 | } |
Chris Lattner | 52d08bd | 2005-05-09 20:23:03 +0000 | [diff] [blame] | 1754 | |
| 1755 | case ISD::READPORT: |
Chris Lattner | 52d08bd | 2005-05-09 20:23:03 +0000 | [diff] [blame] | 1756 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1757 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
Chris Lattner | 6d5b8e1 | 2005-05-09 20:36:57 +0000 | [diff] [blame] | 1758 | |
Chris Lattner | 3e01136 | 2005-05-14 07:45:46 +0000 | [diff] [blame] | 1759 | if (Tmp1 != Node->getOperand(0) || Tmp2 != Node->getOperand(1)) { |
| 1760 | std::vector<MVT::ValueType> VTs(Node->value_begin(), Node->value_end()); |
| 1761 | std::vector<SDOperand> Ops; |
| 1762 | Ops.push_back(Tmp1); |
| 1763 | Ops.push_back(Tmp2); |
| 1764 | Result = DAG.getNode(ISD::READPORT, VTs, Ops); |
| 1765 | } else |
Chris Lattner | 52d08bd | 2005-05-09 20:23:03 +0000 | [diff] [blame] | 1766 | Result = SDOperand(Node, 0); |
| 1767 | // Since these produce two values, make sure to remember that we legalized |
| 1768 | // both of them. |
| 1769 | AddLegalizedOperand(SDOperand(Node, 0), Result); |
| 1770 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
| 1771 | return Result.getValue(Op.ResNo); |
Chris Lattner | 52d08bd | 2005-05-09 20:23:03 +0000 | [diff] [blame] | 1772 | case ISD::WRITEPORT: |
Chris Lattner | 52d08bd | 2005-05-09 20:23:03 +0000 | [diff] [blame] | 1773 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1774 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1775 | Tmp3 = LegalizeOp(Node->getOperand(2)); |
| 1776 | if (Tmp1 != Node->getOperand(0) || Tmp2 != Node->getOperand(1) || |
| 1777 | Tmp3 != Node->getOperand(2)) |
| 1778 | Result = DAG.getNode(Node->getOpcode(), MVT::Other, Tmp1, Tmp2, Tmp3); |
| 1779 | break; |
| 1780 | |
Chris Lattner | 6d5b8e1 | 2005-05-09 20:36:57 +0000 | [diff] [blame] | 1781 | case ISD::READIO: |
| 1782 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1783 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1784 | |
| 1785 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 1786 | case TargetLowering::Custom: |
| 1787 | default: assert(0 && "This action not implemented for this operation!"); |
| 1788 | case TargetLowering::Legal: |
Chris Lattner | 3e01136 | 2005-05-14 07:45:46 +0000 | [diff] [blame] | 1789 | if (Tmp1 != Node->getOperand(0) || Tmp2 != Node->getOperand(1)) { |
| 1790 | std::vector<MVT::ValueType> VTs(Node->value_begin(), Node->value_end()); |
| 1791 | std::vector<SDOperand> Ops; |
| 1792 | Ops.push_back(Tmp1); |
| 1793 | Ops.push_back(Tmp2); |
| 1794 | Result = DAG.getNode(ISD::READPORT, VTs, Ops); |
| 1795 | } else |
Chris Lattner | 6d5b8e1 | 2005-05-09 20:36:57 +0000 | [diff] [blame] | 1796 | Result = SDOperand(Node, 0); |
| 1797 | break; |
| 1798 | case TargetLowering::Expand: |
| 1799 | // Replace this with a load from memory. |
| 1800 | Result = DAG.getLoad(Node->getValueType(0), Node->getOperand(0), |
| 1801 | Node->getOperand(1), DAG.getSrcValue(NULL)); |
| 1802 | Result = LegalizeOp(Result); |
| 1803 | break; |
| 1804 | } |
| 1805 | |
| 1806 | // Since these produce two values, make sure to remember that we legalized |
| 1807 | // both of them. |
| 1808 | AddLegalizedOperand(SDOperand(Node, 0), Result); |
| 1809 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
| 1810 | return Result.getValue(Op.ResNo); |
| 1811 | |
| 1812 | case ISD::WRITEIO: |
| 1813 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1814 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1815 | Tmp3 = LegalizeOp(Node->getOperand(2)); |
| 1816 | |
| 1817 | switch (TLI.getOperationAction(Node->getOpcode(), |
| 1818 | Node->getOperand(1).getValueType())) { |
| 1819 | case TargetLowering::Custom: |
| 1820 | default: assert(0 && "This action not implemented for this operation!"); |
| 1821 | case TargetLowering::Legal: |
| 1822 | if (Tmp1 != Node->getOperand(0) || Tmp2 != Node->getOperand(1) || |
| 1823 | Tmp3 != Node->getOperand(2)) |
| 1824 | Result = DAG.getNode(Node->getOpcode(), MVT::Other, Tmp1, Tmp2, Tmp3); |
| 1825 | break; |
| 1826 | case TargetLowering::Expand: |
| 1827 | // Replace this with a store to memory. |
| 1828 | Result = DAG.getNode(ISD::STORE, MVT::Other, Node->getOperand(0), |
| 1829 | Node->getOperand(1), Node->getOperand(2), |
| 1830 | DAG.getSrcValue(NULL)); |
| 1831 | Result = LegalizeOp(Result); |
| 1832 | break; |
| 1833 | } |
| 1834 | break; |
| 1835 | |
Chris Lattner | 84f6788 | 2005-01-20 18:52:28 +0000 | [diff] [blame] | 1836 | case ISD::ADD_PARTS: |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 1837 | case ISD::SUB_PARTS: |
| 1838 | case ISD::SHL_PARTS: |
| 1839 | case ISD::SRA_PARTS: |
| 1840 | case ISD::SRL_PARTS: { |
Chris Lattner | 84f6788 | 2005-01-20 18:52:28 +0000 | [diff] [blame] | 1841 | std::vector<SDOperand> Ops; |
| 1842 | bool Changed = false; |
| 1843 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) { |
| 1844 | Ops.push_back(LegalizeOp(Node->getOperand(i))); |
| 1845 | Changed |= Ops.back() != Node->getOperand(i); |
| 1846 | } |
Chris Lattner | e89083a | 2005-05-14 07:25:05 +0000 | [diff] [blame] | 1847 | if (Changed) { |
| 1848 | std::vector<MVT::ValueType> VTs(Node->value_begin(), Node->value_end()); |
| 1849 | Result = DAG.getNode(Node->getOpcode(), VTs, Ops); |
| 1850 | } |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 1851 | |
| 1852 | // Since these produce multiple values, make sure to remember that we |
| 1853 | // legalized all of them. |
| 1854 | for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) |
| 1855 | AddLegalizedOperand(SDOperand(Node, i), Result.getValue(i)); |
| 1856 | return Result.getValue(Op.ResNo); |
Chris Lattner | 84f6788 | 2005-01-20 18:52:28 +0000 | [diff] [blame] | 1857 | } |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 1858 | |
| 1859 | // Binary operators |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1860 | case ISD::ADD: |
| 1861 | case ISD::SUB: |
| 1862 | case ISD::MUL: |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 1863 | case ISD::MULHS: |
| 1864 | case ISD::MULHU: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1865 | case ISD::UDIV: |
| 1866 | case ISD::SDIV: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1867 | case ISD::AND: |
| 1868 | case ISD::OR: |
| 1869 | case ISD::XOR: |
Chris Lattner | 03c0cf8 | 2005-01-07 21:45:56 +0000 | [diff] [blame] | 1870 | case ISD::SHL: |
| 1871 | case ISD::SRL: |
| 1872 | case ISD::SRA: |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 1873 | case ISD::FADD: |
| 1874 | case ISD::FSUB: |
| 1875 | case ISD::FMUL: |
| 1876 | case ISD::FDIV: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1877 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
Andrew Lenharth | f2eb139 | 2005-07-05 19:52:39 +0000 | [diff] [blame] | 1878 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 1879 | case Expand: assert(0 && "Not possible"); |
| 1880 | case Legal: |
| 1881 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the RHS. |
| 1882 | break; |
| 1883 | case Promote: |
| 1884 | Tmp2 = PromoteOp(Node->getOperand(1)); // Promote the RHS. |
| 1885 | break; |
| 1886 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1887 | if (Tmp1 != Node->getOperand(0) || |
| 1888 | Tmp2 != Node->getOperand(1)) |
| 1889 | Result = DAG.getNode(Node->getOpcode(), Node->getValueType(0), Tmp1,Tmp2); |
| 1890 | break; |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 1891 | |
Nate Begeman | 419f8b6 | 2005-10-18 00:27:41 +0000 | [diff] [blame] | 1892 | case ISD::BUILD_PAIR: { |
| 1893 | MVT::ValueType PairTy = Node->getValueType(0); |
| 1894 | // TODO: handle the case where the Lo and Hi operands are not of legal type |
| 1895 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Lo |
| 1896 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Hi |
| 1897 | switch (TLI.getOperationAction(ISD::BUILD_PAIR, PairTy)) { |
| 1898 | case TargetLowering::Legal: |
| 1899 | if (Tmp1 != Node->getOperand(0) || Tmp2 != Node->getOperand(1)) |
| 1900 | Result = DAG.getNode(ISD::BUILD_PAIR, PairTy, Tmp1, Tmp2); |
| 1901 | break; |
| 1902 | case TargetLowering::Promote: |
| 1903 | case TargetLowering::Custom: |
| 1904 | assert(0 && "Cannot promote/custom this yet!"); |
| 1905 | case TargetLowering::Expand: |
| 1906 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, PairTy, Tmp1); |
| 1907 | Tmp2 = DAG.getNode(ISD::ANY_EXTEND, PairTy, Tmp2); |
| 1908 | Tmp2 = DAG.getNode(ISD::SHL, PairTy, Tmp2, |
| 1909 | DAG.getConstant(MVT::getSizeInBits(PairTy)/2, |
| 1910 | TLI.getShiftAmountTy())); |
| 1911 | Result = LegalizeOp(DAG.getNode(ISD::OR, PairTy, Tmp1, Tmp2)); |
| 1912 | break; |
| 1913 | } |
| 1914 | break; |
| 1915 | } |
| 1916 | |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 1917 | case ISD::UREM: |
| 1918 | case ISD::SREM: |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 1919 | case ISD::FREM: |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 1920 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
| 1921 | Tmp2 = LegalizeOp(Node->getOperand(1)); // RHS |
| 1922 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 1923 | case TargetLowering::Legal: |
| 1924 | if (Tmp1 != Node->getOperand(0) || |
| 1925 | Tmp2 != Node->getOperand(1)) |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 1926 | Result = DAG.getNode(Node->getOpcode(), Node->getValueType(0), Tmp1, |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 1927 | Tmp2); |
| 1928 | break; |
| 1929 | case TargetLowering::Promote: |
| 1930 | case TargetLowering::Custom: |
| 1931 | assert(0 && "Cannot promote/custom handle this yet!"); |
Chris Lattner | 4c64dd7 | 2005-08-03 20:31:37 +0000 | [diff] [blame] | 1932 | case TargetLowering::Expand: |
| 1933 | if (MVT::isInteger(Node->getValueType(0))) { |
| 1934 | MVT::ValueType VT = Node->getValueType(0); |
| 1935 | unsigned Opc = (Node->getOpcode() == ISD::UREM) ? ISD::UDIV : ISD::SDIV; |
| 1936 | Result = DAG.getNode(Opc, VT, Tmp1, Tmp2); |
| 1937 | Result = DAG.getNode(ISD::MUL, VT, Result, Tmp2); |
| 1938 | Result = DAG.getNode(ISD::SUB, VT, Tmp1, Result); |
| 1939 | } else { |
| 1940 | // Floating point mod -> fmod libcall. |
| 1941 | const char *FnName = Node->getValueType(0) == MVT::f32 ? "fmodf":"fmod"; |
| 1942 | SDOperand Dummy; |
| 1943 | Result = ExpandLibCall(FnName, Node, Dummy); |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 1944 | } |
| 1945 | break; |
| 1946 | } |
| 1947 | break; |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 1948 | |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 1949 | case ISD::CTPOP: |
| 1950 | case ISD::CTTZ: |
| 1951 | case ISD::CTLZ: |
| 1952 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Op |
| 1953 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 1954 | case TargetLowering::Legal: |
| 1955 | if (Tmp1 != Node->getOperand(0)) |
| 1956 | Result = DAG.getNode(Node->getOpcode(), Node->getValueType(0), Tmp1); |
| 1957 | break; |
| 1958 | case TargetLowering::Promote: { |
| 1959 | MVT::ValueType OVT = Tmp1.getValueType(); |
| 1960 | MVT::ValueType NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT); |
Chris Lattner | edb1add | 2005-05-11 04:51:16 +0000 | [diff] [blame] | 1961 | |
| 1962 | // Zero extend the argument. |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 1963 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Tmp1); |
| 1964 | // Perform the larger operation, then subtract if needed. |
| 1965 | Tmp1 = DAG.getNode(Node->getOpcode(), Node->getValueType(0), Tmp1); |
| 1966 | switch(Node->getOpcode()) |
| 1967 | { |
| 1968 | case ISD::CTPOP: |
| 1969 | Result = Tmp1; |
| 1970 | break; |
| 1971 | case ISD::CTTZ: |
| 1972 | //if Tmp1 == sizeinbits(NVT) then Tmp1 = sizeinbits(Old VT) |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 1973 | Tmp2 = DAG.getSetCC(TLI.getSetCCResultTy(), Tmp1, |
| 1974 | DAG.getConstant(getSizeInBits(NVT), NVT), |
| 1975 | ISD::SETEQ); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 1976 | Result = DAG.getNode(ISD::SELECT, NVT, Tmp2, |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 1977 | DAG.getConstant(getSizeInBits(OVT),NVT), Tmp1); |
| 1978 | break; |
| 1979 | case ISD::CTLZ: |
| 1980 | //Tmp1 = Tmp1 - (sizeinbits(NVT) - sizeinbits(Old VT)) |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 1981 | Result = DAG.getNode(ISD::SUB, NVT, Tmp1, |
| 1982 | DAG.getConstant(getSizeInBits(NVT) - |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 1983 | getSizeInBits(OVT), NVT)); |
| 1984 | break; |
| 1985 | } |
| 1986 | break; |
| 1987 | } |
| 1988 | case TargetLowering::Custom: |
| 1989 | assert(0 && "Cannot custom handle this yet!"); |
| 1990 | case TargetLowering::Expand: |
Andrew Lenharth | ded10bf | 2005-05-05 15:55:21 +0000 | [diff] [blame] | 1991 | switch(Node->getOpcode()) |
| 1992 | { |
| 1993 | case ISD::CTPOP: { |
Chris Lattner | e3ef0a8 | 2005-05-11 05:21:31 +0000 | [diff] [blame] | 1994 | static const uint64_t mask[6] = { |
| 1995 | 0x5555555555555555ULL, 0x3333333333333333ULL, |
| 1996 | 0x0F0F0F0F0F0F0F0FULL, 0x00FF00FF00FF00FFULL, |
| 1997 | 0x0000FFFF0000FFFFULL, 0x00000000FFFFFFFFULL |
| 1998 | }; |
Andrew Lenharth | ded10bf | 2005-05-05 15:55:21 +0000 | [diff] [blame] | 1999 | MVT::ValueType VT = Tmp1.getValueType(); |
Chris Lattner | e3ef0a8 | 2005-05-11 05:21:31 +0000 | [diff] [blame] | 2000 | MVT::ValueType ShVT = TLI.getShiftAmountTy(); |
| 2001 | unsigned len = getSizeInBits(VT); |
| 2002 | for (unsigned i = 0; (1U << i) <= (len / 2); ++i) { |
Andrew Lenharth | ded10bf | 2005-05-05 15:55:21 +0000 | [diff] [blame] | 2003 | //x = (x & mask[i][len/8]) + (x >> (1 << i) & mask[i][len/8]) |
Chris Lattner | e3ef0a8 | 2005-05-11 05:21:31 +0000 | [diff] [blame] | 2004 | Tmp2 = DAG.getConstant(mask[i], VT); |
| 2005 | Tmp3 = DAG.getConstant(1ULL << i, ShVT); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 2006 | Tmp1 = DAG.getNode(ISD::ADD, VT, |
Andrew Lenharth | ded10bf | 2005-05-05 15:55:21 +0000 | [diff] [blame] | 2007 | DAG.getNode(ISD::AND, VT, Tmp1, Tmp2), |
| 2008 | DAG.getNode(ISD::AND, VT, |
| 2009 | DAG.getNode(ISD::SRL, VT, Tmp1, Tmp3), |
| 2010 | Tmp2)); |
| 2011 | } |
| 2012 | Result = Tmp1; |
| 2013 | break; |
| 2014 | } |
Duraid Madina | 57ff7e5 | 2005-05-11 08:45:08 +0000 | [diff] [blame] | 2015 | case ISD::CTLZ: { |
| 2016 | /* for now, we do this: |
Chris Lattner | 5c33c9a | 2005-05-11 18:35:21 +0000 | [diff] [blame] | 2017 | x = x | (x >> 1); |
| 2018 | x = x | (x >> 2); |
| 2019 | ... |
| 2020 | x = x | (x >>16); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 2021 | x = x | (x >>32); // for 64-bit input |
Chris Lattner | 5c33c9a | 2005-05-11 18:35:21 +0000 | [diff] [blame] | 2022 | return popcount(~x); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 2023 | |
Chris Lattner | 5c33c9a | 2005-05-11 18:35:21 +0000 | [diff] [blame] | 2024 | but see also: http://www.hackersdelight.org/HDcode/nlz.cc */ |
| 2025 | MVT::ValueType VT = Tmp1.getValueType(); |
Duraid Madina | 57ff7e5 | 2005-05-11 08:45:08 +0000 | [diff] [blame] | 2026 | MVT::ValueType ShVT = TLI.getShiftAmountTy(); |
| 2027 | unsigned len = getSizeInBits(VT); |
| 2028 | for (unsigned i = 0; (1U << i) <= (len / 2); ++i) { |
| 2029 | Tmp3 = DAG.getConstant(1ULL << i, ShVT); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 2030 | Tmp1 = DAG.getNode(ISD::OR, VT, Tmp1, |
Duraid Madina | 57ff7e5 | 2005-05-11 08:45:08 +0000 | [diff] [blame] | 2031 | DAG.getNode(ISD::SRL, VT, Tmp1, Tmp3)); |
| 2032 | } |
| 2033 | Tmp3 = DAG.getNode(ISD::XOR, VT, Tmp1, DAG.getConstant(~0ULL, VT)); |
Chris Lattner | 5c33c9a | 2005-05-11 18:35:21 +0000 | [diff] [blame] | 2034 | Result = LegalizeOp(DAG.getNode(ISD::CTPOP, VT, Tmp3)); |
Chris Lattner | 18aa680 | 2005-05-11 05:27:09 +0000 | [diff] [blame] | 2035 | break; |
Duraid Madina | 57ff7e5 | 2005-05-11 08:45:08 +0000 | [diff] [blame] | 2036 | } |
| 2037 | case ISD::CTTZ: { |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 2038 | // for now, we use: { return popcount(~x & (x - 1)); } |
Nate Begeman | d7c4a4a | 2005-05-11 23:43:56 +0000 | [diff] [blame] | 2039 | // unless the target has ctlz but not ctpop, in which case we use: |
| 2040 | // { return 32 - nlz(~x & (x-1)); } |
| 2041 | // see also http://www.hackersdelight.org/HDcode/ntz.cc |
Chris Lattner | 5c33c9a | 2005-05-11 18:35:21 +0000 | [diff] [blame] | 2042 | MVT::ValueType VT = Tmp1.getValueType(); |
| 2043 | Tmp2 = DAG.getConstant(~0ULL, VT); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 2044 | Tmp3 = DAG.getNode(ISD::AND, VT, |
Chris Lattner | 5c33c9a | 2005-05-11 18:35:21 +0000 | [diff] [blame] | 2045 | DAG.getNode(ISD::XOR, VT, Tmp1, Tmp2), |
| 2046 | DAG.getNode(ISD::SUB, VT, Tmp1, |
| 2047 | DAG.getConstant(1, VT))); |
Nate Begeman | d7c4a4a | 2005-05-11 23:43:56 +0000 | [diff] [blame] | 2048 | // If ISD::CTLZ is legal and CTPOP isn't, then do that instead |
Chris Lattner | c9c60f6 | 2005-08-24 16:35:28 +0000 | [diff] [blame] | 2049 | if (!TLI.isOperationLegal(ISD::CTPOP, VT) && |
| 2050 | TLI.isOperationLegal(ISD::CTLZ, VT)) { |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 2051 | Result = LegalizeOp(DAG.getNode(ISD::SUB, VT, |
Nate Begeman | d7c4a4a | 2005-05-11 23:43:56 +0000 | [diff] [blame] | 2052 | DAG.getConstant(getSizeInBits(VT), VT), |
| 2053 | DAG.getNode(ISD::CTLZ, VT, Tmp3))); |
| 2054 | } else { |
| 2055 | Result = LegalizeOp(DAG.getNode(ISD::CTPOP, VT, Tmp3)); |
| 2056 | } |
Chris Lattner | 18aa680 | 2005-05-11 05:27:09 +0000 | [diff] [blame] | 2057 | break; |
Duraid Madina | 57ff7e5 | 2005-05-11 08:45:08 +0000 | [diff] [blame] | 2058 | } |
Andrew Lenharth | ded10bf | 2005-05-05 15:55:21 +0000 | [diff] [blame] | 2059 | default: |
| 2060 | assert(0 && "Cannot expand this yet!"); |
| 2061 | break; |
| 2062 | } |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 2063 | break; |
| 2064 | } |
| 2065 | break; |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 2066 | |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 2067 | // Unary operators |
| 2068 | case ISD::FABS: |
| 2069 | case ISD::FNEG: |
Chris Lattner | da6ba87 | 2005-04-28 21:44:33 +0000 | [diff] [blame] | 2070 | case ISD::FSQRT: |
| 2071 | case ISD::FSIN: |
| 2072 | case ISD::FCOS: |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 2073 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 2074 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 2075 | case TargetLowering::Legal: |
| 2076 | if (Tmp1 != Node->getOperand(0)) |
| 2077 | Result = DAG.getNode(Node->getOpcode(), Node->getValueType(0), Tmp1); |
| 2078 | break; |
| 2079 | case TargetLowering::Promote: |
| 2080 | case TargetLowering::Custom: |
| 2081 | assert(0 && "Cannot promote/custom handle this yet!"); |
| 2082 | case TargetLowering::Expand: |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 2083 | switch(Node->getOpcode()) { |
| 2084 | case ISD::FNEG: { |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 2085 | // Expand Y = FNEG(X) -> Y = SUB -0.0, X |
| 2086 | Tmp2 = DAG.getConstantFP(-0.0, Node->getValueType(0)); |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 2087 | Result = LegalizeOp(DAG.getNode(ISD::FSUB, Node->getValueType(0), |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 2088 | Tmp2, Tmp1)); |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 2089 | break; |
| 2090 | } |
| 2091 | case ISD::FABS: { |
Chris Lattner | 4af6e0d | 2005-04-02 05:26:37 +0000 | [diff] [blame] | 2092 | // Expand Y = FABS(X) -> Y = (X >u 0.0) ? X : fneg(X). |
| 2093 | MVT::ValueType VT = Node->getValueType(0); |
| 2094 | Tmp2 = DAG.getConstantFP(0.0, VT); |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 2095 | Tmp2 = DAG.getSetCC(TLI.getSetCCResultTy(), Tmp1, Tmp2, ISD::SETUGT); |
Chris Lattner | 4af6e0d | 2005-04-02 05:26:37 +0000 | [diff] [blame] | 2096 | Tmp3 = DAG.getNode(ISD::FNEG, VT, Tmp1); |
| 2097 | Result = DAG.getNode(ISD::SELECT, VT, Tmp2, Tmp1, Tmp3); |
| 2098 | Result = LegalizeOp(Result); |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 2099 | break; |
| 2100 | } |
| 2101 | case ISD::FSQRT: |
| 2102 | case ISD::FSIN: |
| 2103 | case ISD::FCOS: { |
| 2104 | MVT::ValueType VT = Node->getValueType(0); |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 2105 | const char *FnName = 0; |
| 2106 | switch(Node->getOpcode()) { |
| 2107 | case ISD::FSQRT: FnName = VT == MVT::f32 ? "sqrtf" : "sqrt"; break; |
| 2108 | case ISD::FSIN: FnName = VT == MVT::f32 ? "sinf" : "sin"; break; |
| 2109 | case ISD::FCOS: FnName = VT == MVT::f32 ? "cosf" : "cos"; break; |
| 2110 | default: assert(0 && "Unreachable!"); |
| 2111 | } |
Nate Begeman | 2ac4fc0 | 2005-08-04 21:43:28 +0000 | [diff] [blame] | 2112 | SDOperand Dummy; |
| 2113 | Result = ExpandLibCall(FnName, Node, Dummy); |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 2114 | break; |
| 2115 | } |
| 2116 | default: |
Chris Lattner | 4af6e0d | 2005-04-02 05:26:37 +0000 | [diff] [blame] | 2117 | assert(0 && "Unreachable!"); |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 2118 | } |
| 2119 | break; |
| 2120 | } |
| 2121 | break; |
| 2122 | |
| 2123 | // Conversion operators. The source and destination have different types. |
Chris Lattner | ae0aacb | 2005-01-08 08:08:56 +0000 | [diff] [blame] | 2124 | case ISD::SINT_TO_FP: |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 2125 | case ISD::UINT_TO_FP: { |
| 2126 | bool isSigned = Node->getOpcode() == ISD::SINT_TO_FP; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2127 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 2128 | case Legal: |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 2129 | switch (TLI.getOperationAction(Node->getOpcode(), |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 2130 | Node->getOperand(0).getValueType())) { |
| 2131 | default: assert(0 && "Unknown operation action!"); |
| 2132 | case TargetLowering::Expand: |
Jim Laskey | 6269ed1 | 2005-08-17 00:39:29 +0000 | [diff] [blame] | 2133 | Result = ExpandLegalINT_TO_FP(isSigned, |
| 2134 | LegalizeOp(Node->getOperand(0)), |
| 2135 | Node->getValueType(0)); |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 2136 | AddLegalizedOperand(Op, Result); |
| 2137 | return Result; |
| 2138 | case TargetLowering::Promote: |
| 2139 | Result = PromoteLegalINT_TO_FP(LegalizeOp(Node->getOperand(0)), |
| 2140 | Node->getValueType(0), |
| 2141 | isSigned); |
| 2142 | AddLegalizedOperand(Op, Result); |
| 2143 | return Result; |
| 2144 | case TargetLowering::Legal: |
| 2145 | break; |
Andrew Lenharth | 5b5b8c2 | 2005-11-30 06:43:03 +0000 | [diff] [blame] | 2146 | case TargetLowering::Custom: { |
| 2147 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 2148 | SDOperand Tmp = |
| 2149 | DAG.getNode(Node->getOpcode(), Node->getValueType(0), Tmp1); |
| 2150 | Tmp = TLI.LowerOperation(Tmp, DAG); |
| 2151 | if (Tmp.Val) { |
Chris Lattner | 69a889e | 2005-12-20 00:53:54 +0000 | [diff] [blame] | 2152 | Tmp = LegalizeOp(Tmp); // Relegalize input. |
Andrew Lenharth | 5b5b8c2 | 2005-11-30 06:43:03 +0000 | [diff] [blame] | 2153 | AddLegalizedOperand(Op, Tmp); |
Andrew Lenharth | 5b5b8c2 | 2005-11-30 06:43:03 +0000 | [diff] [blame] | 2154 | return Tmp; |
| 2155 | } else { |
| 2156 | assert(0 && "Target Must Lower this"); |
| 2157 | } |
| 2158 | } |
Andrew Lenharth | f4b3278 | 2005-06-27 23:28:32 +0000 | [diff] [blame] | 2159 | } |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 2160 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2161 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 2162 | if (Tmp1 != Node->getOperand(0)) |
| 2163 | Result = DAG.getNode(Node->getOpcode(), Node->getValueType(0), Tmp1); |
| 2164 | break; |
Chris Lattner | b00a642 | 2005-01-07 22:37:48 +0000 | [diff] [blame] | 2165 | case Expand: |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 2166 | Result = ExpandIntToFP(Node->getOpcode() == ISD::SINT_TO_FP, |
| 2167 | Node->getValueType(0), Node->getOperand(0)); |
| 2168 | break; |
| 2169 | case Promote: |
| 2170 | if (isSigned) { |
| 2171 | Result = PromoteOp(Node->getOperand(0)); |
| 2172 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(), |
| 2173 | Result, DAG.getValueType(Node->getOperand(0).getValueType())); |
| 2174 | Result = DAG.getNode(ISD::SINT_TO_FP, Op.getValueType(), Result); |
| 2175 | } else { |
| 2176 | Result = PromoteOp(Node->getOperand(0)); |
| 2177 | Result = DAG.getZeroExtendInReg(Result, |
| 2178 | Node->getOperand(0).getValueType()); |
| 2179 | Result = DAG.getNode(ISD::UINT_TO_FP, Op.getValueType(), Result); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 2180 | } |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 2181 | break; |
| 2182 | } |
| 2183 | break; |
| 2184 | } |
| 2185 | case ISD::TRUNCATE: |
| 2186 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 2187 | case Legal: |
| 2188 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 2189 | if (Tmp1 != Node->getOperand(0)) |
| 2190 | Result = DAG.getNode(Node->getOpcode(), Node->getValueType(0), Tmp1); |
| 2191 | break; |
| 2192 | case Expand: |
| 2193 | ExpandOp(Node->getOperand(0), Tmp1, Tmp2); |
| 2194 | |
| 2195 | // Since the result is legal, we should just be able to truncate the low |
| 2196 | // part of the source. |
| 2197 | Result = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0), Tmp1); |
| 2198 | break; |
| 2199 | case Promote: |
| 2200 | Result = PromoteOp(Node->getOperand(0)); |
| 2201 | Result = DAG.getNode(ISD::TRUNCATE, Op.getValueType(), Result); |
| 2202 | break; |
| 2203 | } |
| 2204 | break; |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 2205 | |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 2206 | case ISD::FP_TO_SINT: |
| 2207 | case ISD::FP_TO_UINT: |
| 2208 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 2209 | case Legal: |
Chris Lattner | f1fa74e | 2005-07-30 00:04:12 +0000 | [diff] [blame] | 2210 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 2211 | |
Chris Lattner | 1618beb | 2005-07-29 00:11:56 +0000 | [diff] [blame] | 2212 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))){ |
| 2213 | default: assert(0 && "Unknown operation action!"); |
| 2214 | case TargetLowering::Expand: |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 2215 | if (Node->getOpcode() == ISD::FP_TO_UINT) { |
| 2216 | SDOperand True, False; |
| 2217 | MVT::ValueType VT = Node->getOperand(0).getValueType(); |
| 2218 | MVT::ValueType NVT = Node->getValueType(0); |
| 2219 | unsigned ShiftAmt = MVT::getSizeInBits(Node->getValueType(0))-1; |
| 2220 | Tmp2 = DAG.getConstantFP((double)(1ULL << ShiftAmt), VT); |
| 2221 | Tmp3 = DAG.getSetCC(TLI.getSetCCResultTy(), |
| 2222 | Node->getOperand(0), Tmp2, ISD::SETLT); |
| 2223 | True = DAG.getNode(ISD::FP_TO_SINT, NVT, Node->getOperand(0)); |
| 2224 | False = DAG.getNode(ISD::FP_TO_SINT, NVT, |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 2225 | DAG.getNode(ISD::FSUB, VT, Node->getOperand(0), |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 2226 | Tmp2)); |
| 2227 | False = DAG.getNode(ISD::XOR, NVT, False, |
| 2228 | DAG.getConstant(1ULL << ShiftAmt, NVT)); |
| 2229 | Result = LegalizeOp(DAG.getNode(ISD::SELECT, NVT, Tmp3, True, False)); |
Chris Lattner | 69a889e | 2005-12-20 00:53:54 +0000 | [diff] [blame] | 2230 | AddLegalizedOperand(SDOperand(Node, 0), Result); |
Nate Begeman | 2d56e72 | 2005-08-14 18:38:32 +0000 | [diff] [blame] | 2231 | return Result; |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 2232 | } else { |
| 2233 | assert(0 && "Do not know how to expand FP_TO_SINT yet!"); |
| 2234 | } |
| 2235 | break; |
Chris Lattner | 1618beb | 2005-07-29 00:11:56 +0000 | [diff] [blame] | 2236 | case TargetLowering::Promote: |
Chris Lattner | f1fa74e | 2005-07-30 00:04:12 +0000 | [diff] [blame] | 2237 | Result = PromoteLegalFP_TO_INT(Tmp1, Node->getValueType(0), |
Chris Lattner | 1618beb | 2005-07-29 00:11:56 +0000 | [diff] [blame] | 2238 | Node->getOpcode() == ISD::FP_TO_SINT); |
| 2239 | AddLegalizedOperand(Op, Result); |
| 2240 | return Result; |
Chris Lattner | 07dffd6 | 2005-08-26 00:14:16 +0000 | [diff] [blame] | 2241 | case TargetLowering::Custom: { |
| 2242 | SDOperand Tmp = |
| 2243 | DAG.getNode(Node->getOpcode(), Node->getValueType(0), Tmp1); |
| 2244 | Tmp = TLI.LowerOperation(Tmp, DAG); |
| 2245 | if (Tmp.Val) { |
Chris Lattner | 69a889e | 2005-12-20 00:53:54 +0000 | [diff] [blame] | 2246 | Tmp = LegalizeOp(Tmp); |
Chris Lattner | 07dffd6 | 2005-08-26 00:14:16 +0000 | [diff] [blame] | 2247 | AddLegalizedOperand(Op, Tmp); |
Chris Lattner | 507f752 | 2005-08-29 17:30:00 +0000 | [diff] [blame] | 2248 | return Tmp; |
Chris Lattner | 07dffd6 | 2005-08-26 00:14:16 +0000 | [diff] [blame] | 2249 | } else { |
| 2250 | // The target thinks this is legal afterall. |
| 2251 | break; |
| 2252 | } |
| 2253 | } |
Chris Lattner | 1618beb | 2005-07-29 00:11:56 +0000 | [diff] [blame] | 2254 | case TargetLowering::Legal: |
| 2255 | break; |
| 2256 | } |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 2257 | |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 2258 | if (Tmp1 != Node->getOperand(0)) |
| 2259 | Result = DAG.getNode(Node->getOpcode(), Node->getValueType(0), Tmp1); |
| 2260 | break; |
| 2261 | case Expand: |
| 2262 | assert(0 && "Shouldn't need to expand other operators here!"); |
| 2263 | case Promote: |
| 2264 | Result = PromoteOp(Node->getOperand(0)); |
| 2265 | Result = DAG.getNode(Node->getOpcode(), Op.getValueType(), Result); |
| 2266 | break; |
| 2267 | } |
| 2268 | break; |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 2269 | |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 2270 | case ISD::ANY_EXTEND: |
Chris Lattner | fa9c801 | 2005-07-28 23:31:12 +0000 | [diff] [blame] | 2271 | case ISD::ZERO_EXTEND: |
| 2272 | case ISD::SIGN_EXTEND: |
| 2273 | case ISD::FP_EXTEND: |
| 2274 | case ISD::FP_ROUND: |
| 2275 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 2276 | case Legal: |
| 2277 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 2278 | if (Tmp1 != Node->getOperand(0)) |
| 2279 | Result = DAG.getNode(Node->getOpcode(), Node->getValueType(0), Tmp1); |
| 2280 | break; |
| 2281 | case Expand: |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 2282 | assert(0 && "Shouldn't need to expand other operators here!"); |
Chris Lattner | b00a642 | 2005-01-07 22:37:48 +0000 | [diff] [blame] | 2283 | |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 2284 | case Promote: |
| 2285 | switch (Node->getOpcode()) { |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 2286 | case ISD::ANY_EXTEND: |
| 2287 | Result = PromoteOp(Node->getOperand(0)); |
| 2288 | Result = DAG.getNode(ISD::ANY_EXTEND, Op.getValueType(), Result); |
| 2289 | break; |
Chris Lattner | 1713e73 | 2005-01-16 00:38:00 +0000 | [diff] [blame] | 2290 | case ISD::ZERO_EXTEND: |
| 2291 | Result = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 2292 | Result = DAG.getNode(ISD::ANY_EXTEND, Op.getValueType(), Result); |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 2293 | Result = DAG.getZeroExtendInReg(Result, |
| 2294 | Node->getOperand(0).getValueType()); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 2295 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 2296 | case ISD::SIGN_EXTEND: |
Chris Lattner | 1713e73 | 2005-01-16 00:38:00 +0000 | [diff] [blame] | 2297 | Result = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 2298 | Result = DAG.getNode(ISD::ANY_EXTEND, Op.getValueType(), Result); |
Chris Lattner | 1713e73 | 2005-01-16 00:38:00 +0000 | [diff] [blame] | 2299 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(), |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 2300 | Result, |
| 2301 | DAG.getValueType(Node->getOperand(0).getValueType())); |
Chris Lattner | 1713e73 | 2005-01-16 00:38:00 +0000 | [diff] [blame] | 2302 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 2303 | case ISD::FP_EXTEND: |
Chris Lattner | 1713e73 | 2005-01-16 00:38:00 +0000 | [diff] [blame] | 2304 | Result = PromoteOp(Node->getOperand(0)); |
| 2305 | if (Result.getValueType() != Op.getValueType()) |
| 2306 | // Dynamically dead while we have only 2 FP types. |
| 2307 | Result = DAG.getNode(ISD::FP_EXTEND, Op.getValueType(), Result); |
| 2308 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 2309 | case ISD::FP_ROUND: |
Chris Lattner | f8161d8 | 2005-01-16 05:06:12 +0000 | [diff] [blame] | 2310 | Result = PromoteOp(Node->getOperand(0)); |
| 2311 | Result = DAG.getNode(Node->getOpcode(), Op.getValueType(), Result); |
| 2312 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 2313 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2314 | } |
| 2315 | break; |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 2316 | case ISD::FP_ROUND_INREG: |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 2317 | case ISD::SIGN_EXTEND_INREG: { |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 2318 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 2319 | MVT::ValueType ExtraVT = cast<VTSDNode>(Node->getOperand(1))->getVT(); |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 2320 | |
| 2321 | // If this operation is not supported, convert it to a shl/shr or load/store |
| 2322 | // pair. |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2323 | switch (TLI.getOperationAction(Node->getOpcode(), ExtraVT)) { |
| 2324 | default: assert(0 && "This action not supported for this op yet!"); |
| 2325 | case TargetLowering::Legal: |
| 2326 | if (Tmp1 != Node->getOperand(0)) |
| 2327 | Result = DAG.getNode(Node->getOpcode(), Node->getValueType(0), Tmp1, |
Chris Lattner | 5f056bf | 2005-07-10 01:55:33 +0000 | [diff] [blame] | 2328 | DAG.getValueType(ExtraVT)); |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2329 | break; |
| 2330 | case TargetLowering::Expand: |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 2331 | // If this is an integer extend and shifts are supported, do that. |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 2332 | if (Node->getOpcode() == ISD::SIGN_EXTEND_INREG) { |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 2333 | // NOTE: we could fall back on load/store here too for targets without |
| 2334 | // SAR. However, it is doubtful that any exist. |
| 2335 | unsigned BitsDiff = MVT::getSizeInBits(Node->getValueType(0)) - |
| 2336 | MVT::getSizeInBits(ExtraVT); |
Chris Lattner | 27ff112 | 2005-01-22 00:31:52 +0000 | [diff] [blame] | 2337 | SDOperand ShiftCst = DAG.getConstant(BitsDiff, TLI.getShiftAmountTy()); |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 2338 | Result = DAG.getNode(ISD::SHL, Node->getValueType(0), |
| 2339 | Node->getOperand(0), ShiftCst); |
| 2340 | Result = DAG.getNode(ISD::SRA, Node->getValueType(0), |
| 2341 | Result, ShiftCst); |
| 2342 | } else if (Node->getOpcode() == ISD::FP_ROUND_INREG) { |
| 2343 | // The only way we can lower this is to turn it into a STORETRUNC, |
| 2344 | // EXTLOAD pair, targetting a temporary location (a stack slot). |
| 2345 | |
| 2346 | // NOTE: there is a choice here between constantly creating new stack |
| 2347 | // slots and always reusing the same one. We currently always create |
| 2348 | // new ones, as reuse may inhibit scheduling. |
| 2349 | const Type *Ty = MVT::getTypeForValueType(ExtraVT); |
| 2350 | unsigned TySize = (unsigned)TLI.getTargetData().getTypeSize(Ty); |
| 2351 | unsigned Align = TLI.getTargetData().getTypeAlignment(Ty); |
| 2352 | MachineFunction &MF = DAG.getMachineFunction(); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2353 | int SSFI = |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 2354 | MF.getFrameInfo()->CreateStackObject((unsigned)TySize, Align); |
| 2355 | SDOperand StackSlot = DAG.getFrameIndex(SSFI, TLI.getPointerTy()); |
| 2356 | Result = DAG.getNode(ISD::TRUNCSTORE, MVT::Other, DAG.getEntryNode(), |
Chris Lattner | 52d08bd | 2005-05-09 20:23:03 +0000 | [diff] [blame] | 2357 | Node->getOperand(0), StackSlot, |
Chris Lattner | 9fadb4c | 2005-07-10 00:29:18 +0000 | [diff] [blame] | 2358 | DAG.getSrcValue(NULL), DAG.getValueType(ExtraVT)); |
Chris Lattner | 5f056bf | 2005-07-10 01:55:33 +0000 | [diff] [blame] | 2359 | Result = DAG.getExtLoad(ISD::EXTLOAD, Node->getValueType(0), |
| 2360 | Result, StackSlot, DAG.getSrcValue(NULL), |
| 2361 | ExtraVT); |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 2362 | } else { |
| 2363 | assert(0 && "Unknown op"); |
| 2364 | } |
| 2365 | Result = LegalizeOp(Result); |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 2366 | break; |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 2367 | } |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 2368 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2369 | } |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 2370 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2371 | |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 2372 | // Note that LegalizeOp may be reentered even from single-use nodes, which |
| 2373 | // means that we always must cache transformed nodes. |
| 2374 | AddLegalizedOperand(Op, Result); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2375 | return Result; |
| 2376 | } |
| 2377 | |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 2378 | /// PromoteOp - Given an operation that produces a value in an invalid type, |
| 2379 | /// promote it to compute the value into a larger type. The produced value will |
| 2380 | /// have the correct bits for the low portion of the register, but no guarantee |
| 2381 | /// 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] | 2382 | SDOperand SelectionDAGLegalize::PromoteOp(SDOperand Op) { |
| 2383 | MVT::ValueType VT = Op.getValueType(); |
Chris Lattner | 71c42a0 | 2005-01-16 01:11:45 +0000 | [diff] [blame] | 2384 | MVT::ValueType NVT = TLI.getTypeToTransformTo(VT); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 2385 | assert(getTypeAction(VT) == Promote && |
| 2386 | "Caller should expand or legalize operands that are not promotable!"); |
| 2387 | assert(NVT > VT && MVT::isInteger(NVT) == MVT::isInteger(VT) && |
| 2388 | "Cannot promote to smaller type!"); |
| 2389 | |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 2390 | SDOperand Tmp1, Tmp2, Tmp3; |
| 2391 | |
| 2392 | SDOperand Result; |
| 2393 | SDNode *Node = Op.Val; |
| 2394 | |
Chris Lattner | 6fdcb25 | 2005-09-02 20:32:45 +0000 | [diff] [blame] | 2395 | std::map<SDOperand, SDOperand>::iterator I = PromotedNodes.find(Op); |
| 2396 | if (I != PromotedNodes.end()) return I->second; |
Chris Lattner | 45982da | 2005-05-12 16:53:42 +0000 | [diff] [blame] | 2397 | |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 2398 | // Promotion needs an optimization step to clean up after it, and is not |
| 2399 | // careful to avoid operations the target does not support. Make sure that |
| 2400 | // all generated operations are legalized in the next iteration. |
| 2401 | NeedsAnotherIteration = true; |
| 2402 | |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 2403 | switch (Node->getOpcode()) { |
Chris Lattner | d5d0f9b | 2005-08-16 21:55:35 +0000 | [diff] [blame] | 2404 | case ISD::CopyFromReg: |
| 2405 | assert(0 && "CopyFromReg must be legal!"); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 2406 | default: |
| 2407 | std::cerr << "NODE: "; Node->dump(); std::cerr << "\n"; |
| 2408 | assert(0 && "Do not know how to promote this operator!"); |
| 2409 | abort(); |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 2410 | case ISD::UNDEF: |
| 2411 | Result = DAG.getNode(ISD::UNDEF, NVT); |
| 2412 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 2413 | case ISD::Constant: |
Chris Lattner | ec176e3 | 2005-08-30 16:56:19 +0000 | [diff] [blame] | 2414 | if (VT != MVT::i1) |
| 2415 | Result = DAG.getNode(ISD::SIGN_EXTEND, NVT, Op); |
| 2416 | else |
| 2417 | Result = DAG.getNode(ISD::ZERO_EXTEND, NVT, Op); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 2418 | assert(isa<ConstantSDNode>(Result) && "Didn't constant fold zext?"); |
| 2419 | break; |
| 2420 | case ISD::ConstantFP: |
| 2421 | Result = DAG.getNode(ISD::FP_EXTEND, NVT, Op); |
| 2422 | assert(isa<ConstantFPSDNode>(Result) && "Didn't constant fold fp_extend?"); |
| 2423 | break; |
Chris Lattner | ef5cd1d | 2005-01-18 17:54:55 +0000 | [diff] [blame] | 2424 | |
Chris Lattner | 82fbfb6 | 2005-01-18 02:59:52 +0000 | [diff] [blame] | 2425 | case ISD::SETCC: |
Chris Lattner | c9c60f6 | 2005-08-24 16:35:28 +0000 | [diff] [blame] | 2426 | assert(isTypeLegal(TLI.getSetCCResultTy()) && "SetCC type is not legal??"); |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 2427 | Result = DAG.getNode(ISD::SETCC, TLI.getSetCCResultTy(),Node->getOperand(0), |
| 2428 | Node->getOperand(1), Node->getOperand(2)); |
Chris Lattner | 82fbfb6 | 2005-01-18 02:59:52 +0000 | [diff] [blame] | 2429 | Result = LegalizeOp(Result); |
| 2430 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 2431 | |
| 2432 | case ISD::TRUNCATE: |
| 2433 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 2434 | case Legal: |
| 2435 | Result = LegalizeOp(Node->getOperand(0)); |
| 2436 | assert(Result.getValueType() >= NVT && |
| 2437 | "This truncation doesn't make sense!"); |
| 2438 | if (Result.getValueType() > NVT) // Truncate to NVT instead of VT |
| 2439 | Result = DAG.getNode(ISD::TRUNCATE, NVT, Result); |
| 2440 | break; |
Chris Lattner | e76ad6d | 2005-01-28 22:52:50 +0000 | [diff] [blame] | 2441 | case Promote: |
| 2442 | // The truncation is not required, because we don't guarantee anything |
| 2443 | // about high bits anyway. |
| 2444 | Result = PromoteOp(Node->getOperand(0)); |
| 2445 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 2446 | case Expand: |
Nate Begeman | 79e46ac | 2005-04-04 00:57:08 +0000 | [diff] [blame] | 2447 | ExpandOp(Node->getOperand(0), Tmp1, Tmp2); |
| 2448 | // Truncate the low part of the expanded value to the result type |
Chris Lattner | e21c305 | 2005-08-01 18:16:37 +0000 | [diff] [blame] | 2449 | Result = DAG.getNode(ISD::TRUNCATE, NVT, Tmp1); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 2450 | } |
| 2451 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 2452 | case ISD::SIGN_EXTEND: |
| 2453 | case ISD::ZERO_EXTEND: |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 2454 | case ISD::ANY_EXTEND: |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 2455 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 2456 | case Expand: assert(0 && "BUG: Smaller reg should have been promoted!"); |
| 2457 | case Legal: |
| 2458 | // Input is legal? Just do extend all the way to the larger type. |
| 2459 | Result = LegalizeOp(Node->getOperand(0)); |
| 2460 | Result = DAG.getNode(Node->getOpcode(), NVT, Result); |
| 2461 | break; |
| 2462 | case Promote: |
| 2463 | // Promote the reg if it's smaller. |
| 2464 | Result = PromoteOp(Node->getOperand(0)); |
| 2465 | // The high bits are not guaranteed to be anything. Insert an extend. |
| 2466 | if (Node->getOpcode() == ISD::SIGN_EXTEND) |
Chris Lattner | 595dc54 | 2005-02-04 18:39:19 +0000 | [diff] [blame] | 2467 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Result, |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 2468 | DAG.getValueType(Node->getOperand(0).getValueType())); |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 2469 | else if (Node->getOpcode() == ISD::ZERO_EXTEND) |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 2470 | Result = DAG.getZeroExtendInReg(Result, |
| 2471 | Node->getOperand(0).getValueType()); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 2472 | break; |
| 2473 | } |
| 2474 | break; |
| 2475 | |
| 2476 | case ISD::FP_EXTEND: |
| 2477 | assert(0 && "Case not implemented. Dynamically dead with 2 FP types!"); |
| 2478 | case ISD::FP_ROUND: |
| 2479 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 2480 | case Expand: assert(0 && "BUG: Cannot expand FP regs!"); |
| 2481 | case Promote: assert(0 && "Unreachable with 2 FP types!"); |
| 2482 | case Legal: |
| 2483 | // Input is legal? Do an FP_ROUND_INREG. |
| 2484 | Result = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 2485 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 2486 | DAG.getValueType(VT)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 2487 | break; |
| 2488 | } |
| 2489 | break; |
| 2490 | |
| 2491 | case ISD::SINT_TO_FP: |
| 2492 | case ISD::UINT_TO_FP: |
| 2493 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 2494 | case Legal: |
| 2495 | Result = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 2496 | // No extra round required here. |
| 2497 | Result = DAG.getNode(Node->getOpcode(), NVT, Result); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 2498 | break; |
| 2499 | |
| 2500 | case Promote: |
| 2501 | Result = PromoteOp(Node->getOperand(0)); |
| 2502 | if (Node->getOpcode() == ISD::SINT_TO_FP) |
| 2503 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(), |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 2504 | Result, |
| 2505 | DAG.getValueType(Node->getOperand(0).getValueType())); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 2506 | else |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 2507 | Result = DAG.getZeroExtendInReg(Result, |
| 2508 | Node->getOperand(0).getValueType()); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 2509 | // No extra round required here. |
| 2510 | Result = DAG.getNode(Node->getOpcode(), NVT, Result); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 2511 | break; |
| 2512 | case Expand: |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 2513 | Result = ExpandIntToFP(Node->getOpcode() == ISD::SINT_TO_FP, NVT, |
| 2514 | Node->getOperand(0)); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 2515 | // Round if we cannot tolerate excess precision. |
| 2516 | if (NoExcessFPPrecision) |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 2517 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 2518 | DAG.getValueType(VT)); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 2519 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 2520 | } |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 2521 | break; |
| 2522 | |
Chris Lattner | 5e3c5b4 | 2005-12-09 17:32:47 +0000 | [diff] [blame] | 2523 | case ISD::SIGN_EXTEND_INREG: |
| 2524 | Result = PromoteOp(Node->getOperand(0)); |
| 2525 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Result, |
| 2526 | Node->getOperand(1)); |
| 2527 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 2528 | case ISD::FP_TO_SINT: |
| 2529 | case ISD::FP_TO_UINT: |
| 2530 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 2531 | case Legal: |
| 2532 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 2533 | break; |
| 2534 | case Promote: |
| 2535 | // The input result is prerounded, so we don't have to do anything |
| 2536 | // special. |
| 2537 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 2538 | break; |
| 2539 | case Expand: |
| 2540 | assert(0 && "not implemented"); |
| 2541 | } |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 2542 | // If we're promoting a UINT to a larger size, check to see if the new node |
| 2543 | // will be legal. If it isn't, check to see if FP_TO_SINT is legal, since |
| 2544 | // we can use that instead. This allows us to generate better code for |
| 2545 | // FP_TO_UINT for small destination sizes on targets where FP_TO_UINT is not |
| 2546 | // legal, such as PowerPC. |
| 2547 | if (Node->getOpcode() == ISD::FP_TO_UINT && |
Chris Lattner | c9c60f6 | 2005-08-24 16:35:28 +0000 | [diff] [blame] | 2548 | !TLI.isOperationLegal(ISD::FP_TO_UINT, NVT) && |
Nate Begeman | b7f6ef1 | 2005-10-25 23:47:25 +0000 | [diff] [blame] | 2549 | (TLI.isOperationLegal(ISD::FP_TO_SINT, NVT) || |
| 2550 | TLI.getOperationAction(ISD::FP_TO_SINT, NVT)==TargetLowering::Custom)){ |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 2551 | Result = DAG.getNode(ISD::FP_TO_SINT, NVT, Tmp1); |
| 2552 | } else { |
| 2553 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1); |
| 2554 | } |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 2555 | break; |
| 2556 | |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 2557 | case ISD::FABS: |
| 2558 | case ISD::FNEG: |
| 2559 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 2560 | assert(Tmp1.getValueType() == NVT); |
| 2561 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1); |
| 2562 | // NOTE: we do not have to do any extra rounding here for |
| 2563 | // NoExcessFPPrecision, because we know the input will have the appropriate |
| 2564 | // precision, and these operations don't modify precision at all. |
| 2565 | break; |
| 2566 | |
Chris Lattner | da6ba87 | 2005-04-28 21:44:33 +0000 | [diff] [blame] | 2567 | case ISD::FSQRT: |
| 2568 | case ISD::FSIN: |
| 2569 | case ISD::FCOS: |
| 2570 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 2571 | assert(Tmp1.getValueType() == NVT); |
| 2572 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1); |
| 2573 | if(NoExcessFPPrecision) |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 2574 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 2575 | DAG.getValueType(VT)); |
Chris Lattner | da6ba87 | 2005-04-28 21:44:33 +0000 | [diff] [blame] | 2576 | break; |
| 2577 | |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 2578 | case ISD::AND: |
| 2579 | case ISD::OR: |
| 2580 | case ISD::XOR: |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 2581 | case ISD::ADD: |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 2582 | case ISD::SUB: |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 2583 | case ISD::MUL: |
| 2584 | // 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] | 2585 | // 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] | 2586 | // that too is okay if they are integer operations. |
| 2587 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 2588 | Tmp2 = PromoteOp(Node->getOperand(1)); |
| 2589 | assert(Tmp1.getValueType() == NVT && Tmp2.getValueType() == NVT); |
| 2590 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 2591 | break; |
| 2592 | case ISD::FADD: |
| 2593 | case ISD::FSUB: |
| 2594 | case ISD::FMUL: |
| 2595 | // The input may have strange things in the top bits of the registers, but |
| 2596 | // these operations don't care. |
| 2597 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 2598 | Tmp2 = PromoteOp(Node->getOperand(1)); |
| 2599 | assert(Tmp1.getValueType() == NVT && Tmp2.getValueType() == NVT); |
| 2600 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 2601 | |
| 2602 | // Floating point operations will give excess precision that we may not be |
| 2603 | // able to tolerate. If we DO allow excess precision, just leave it, |
| 2604 | // otherwise excise it. |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 2605 | // FIXME: Why would we need to round FP ops more than integer ones? |
| 2606 | // 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] | 2607 | if (NoExcessFPPrecision) |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 2608 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 2609 | DAG.getValueType(VT)); |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 2610 | break; |
| 2611 | |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 2612 | case ISD::SDIV: |
| 2613 | case ISD::SREM: |
| 2614 | // These operators require that their input be sign extended. |
| 2615 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 2616 | Tmp2 = PromoteOp(Node->getOperand(1)); |
| 2617 | if (MVT::isInteger(NVT)) { |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 2618 | Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp1, |
| 2619 | DAG.getValueType(VT)); |
| 2620 | Tmp2 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp2, |
| 2621 | DAG.getValueType(VT)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 2622 | } |
| 2623 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 2624 | |
| 2625 | // Perform FP_ROUND: this is probably overly pessimistic. |
| 2626 | if (MVT::isFloatingPoint(NVT) && NoExcessFPPrecision) |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 2627 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 2628 | DAG.getValueType(VT)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 2629 | break; |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 2630 | case ISD::FDIV: |
| 2631 | case ISD::FREM: |
| 2632 | // These operators require that their input be fp extended. |
| 2633 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 2634 | Tmp2 = PromoteOp(Node->getOperand(1)); |
| 2635 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 2636 | |
| 2637 | // Perform FP_ROUND: this is probably overly pessimistic. |
| 2638 | if (NoExcessFPPrecision) |
| 2639 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, |
| 2640 | DAG.getValueType(VT)); |
| 2641 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 2642 | |
| 2643 | case ISD::UDIV: |
| 2644 | case ISD::UREM: |
| 2645 | // These operators require that their input be zero extended. |
| 2646 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 2647 | Tmp2 = PromoteOp(Node->getOperand(1)); |
| 2648 | assert(MVT::isInteger(NVT) && "Operators don't apply to FP!"); |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 2649 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, VT); |
| 2650 | Tmp2 = DAG.getZeroExtendInReg(Tmp2, VT); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 2651 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 2652 | break; |
| 2653 | |
| 2654 | case ISD::SHL: |
| 2655 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 2656 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 2657 | Result = DAG.getNode(ISD::SHL, NVT, Tmp1, Tmp2); |
| 2658 | break; |
| 2659 | case ISD::SRA: |
| 2660 | // The input value must be properly sign extended. |
| 2661 | Tmp1 = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 2662 | Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp1, |
| 2663 | DAG.getValueType(VT)); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 2664 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 2665 | Result = DAG.getNode(ISD::SRA, NVT, Tmp1, Tmp2); |
| 2666 | break; |
| 2667 | case ISD::SRL: |
| 2668 | // The input value must be properly zero extended. |
| 2669 | Tmp1 = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 2670 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, VT); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 2671 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 2672 | Result = DAG.getNode(ISD::SRL, NVT, Tmp1, Tmp2); |
| 2673 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 2674 | case ISD::LOAD: |
| 2675 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 2676 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. |
Nate Begeman | ded4963 | 2005-10-13 03:11:28 +0000 | [diff] [blame] | 2677 | Result = DAG.getExtLoad(ISD::EXTLOAD, NVT, Tmp1, Tmp2, |
| 2678 | Node->getOperand(2), VT); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 2679 | // Remember that we legalized the chain. |
| 2680 | AddLegalizedOperand(Op.getValue(1), Result.getValue(1)); |
| 2681 | break; |
Chris Lattner | 4c8f8f0 | 2005-10-13 20:07:41 +0000 | [diff] [blame] | 2682 | case ISD::SEXTLOAD: |
| 2683 | case ISD::ZEXTLOAD: |
| 2684 | case ISD::EXTLOAD: |
| 2685 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 2686 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. |
Chris Lattner | 8136cda | 2005-10-15 20:24:07 +0000 | [diff] [blame] | 2687 | Result = DAG.getExtLoad(Node->getOpcode(), NVT, Tmp1, Tmp2, |
| 2688 | Node->getOperand(2), |
| 2689 | cast<VTSDNode>(Node->getOperand(3))->getVT()); |
Chris Lattner | 4c8f8f0 | 2005-10-13 20:07:41 +0000 | [diff] [blame] | 2690 | // Remember that we legalized the chain. |
| 2691 | AddLegalizedOperand(Op.getValue(1), Result.getValue(1)); |
| 2692 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 2693 | case ISD::SELECT: |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 2694 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 2695 | case Expand: assert(0 && "It's impossible to expand bools"); |
| 2696 | case Legal: |
| 2697 | Tmp1 = LegalizeOp(Node->getOperand(0));// Legalize the condition. |
| 2698 | break; |
| 2699 | case Promote: |
| 2700 | Tmp1 = PromoteOp(Node->getOperand(0)); // Promote the condition. |
| 2701 | break; |
| 2702 | } |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 2703 | Tmp2 = PromoteOp(Node->getOperand(1)); // Legalize the op0 |
| 2704 | Tmp3 = PromoteOp(Node->getOperand(2)); // Legalize the op1 |
| 2705 | Result = DAG.getNode(ISD::SELECT, NVT, Tmp1, Tmp2, Tmp3); |
| 2706 | break; |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 2707 | case ISD::SELECT_CC: |
| 2708 | Tmp2 = PromoteOp(Node->getOperand(2)); // True |
| 2709 | Tmp3 = PromoteOp(Node->getOperand(3)); // False |
| 2710 | Result = DAG.getNode(ISD::SELECT_CC, NVT, Node->getOperand(0), |
| 2711 | Node->getOperand(1), Tmp2, Tmp3, |
| 2712 | Node->getOperand(4)); |
| 2713 | break; |
Chris Lattner | d71c041 | 2005-05-13 18:43:43 +0000 | [diff] [blame] | 2714 | case ISD::TAILCALL: |
Chris Lattner | 8ac532c | 2005-01-16 19:46:48 +0000 | [diff] [blame] | 2715 | case ISD::CALL: { |
| 2716 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 2717 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the callee. |
| 2718 | |
Chris Lattner | 3d9dffc | 2005-01-19 20:24:35 +0000 | [diff] [blame] | 2719 | std::vector<SDOperand> Ops; |
| 2720 | for (unsigned i = 2, e = Node->getNumOperands(); i != e; ++i) |
| 2721 | Ops.push_back(LegalizeOp(Node->getOperand(i))); |
| 2722 | |
Chris Lattner | 8ac532c | 2005-01-16 19:46:48 +0000 | [diff] [blame] | 2723 | assert(Node->getNumValues() == 2 && Op.ResNo == 0 && |
| 2724 | "Can only promote single result calls"); |
| 2725 | std::vector<MVT::ValueType> RetTyVTs; |
| 2726 | RetTyVTs.reserve(2); |
| 2727 | RetTyVTs.push_back(NVT); |
| 2728 | RetTyVTs.push_back(MVT::Other); |
Chris Lattner | d71c041 | 2005-05-13 18:43:43 +0000 | [diff] [blame] | 2729 | SDNode *NC = DAG.getCall(RetTyVTs, Tmp1, Tmp2, Ops, |
| 2730 | Node->getOpcode() == ISD::TAILCALL); |
Chris Lattner | 8ac532c | 2005-01-16 19:46:48 +0000 | [diff] [blame] | 2731 | Result = SDOperand(NC, 0); |
| 2732 | |
| 2733 | // Insert the new chain mapping. |
| 2734 | AddLegalizedOperand(Op.getValue(1), Result.getValue(1)); |
| 2735 | break; |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2736 | } |
Andrew Lenharth | fecf095 | 2005-05-04 19:11:05 +0000 | [diff] [blame] | 2737 | case ISD::CTPOP: |
| 2738 | case ISD::CTTZ: |
| 2739 | case ISD::CTLZ: |
| 2740 | Tmp1 = Node->getOperand(0); |
| 2741 | //Zero extend the argument |
| 2742 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Tmp1); |
| 2743 | // Perform the larger operation, then subtract if needed. |
| 2744 | Tmp1 = DAG.getNode(Node->getOpcode(), NVT, Tmp1); |
| 2745 | switch(Node->getOpcode()) |
| 2746 | { |
| 2747 | case ISD::CTPOP: |
| 2748 | Result = Tmp1; |
| 2749 | break; |
| 2750 | case ISD::CTTZ: |
| 2751 | //if Tmp1 == sizeinbits(NVT) then Tmp1 = sizeinbits(Old VT) |
Nate Begeman | d2558e3 | 2005-08-14 01:20:53 +0000 | [diff] [blame] | 2752 | Tmp2 = DAG.getSetCC(TLI.getSetCCResultTy(), Tmp1, |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 2753 | DAG.getConstant(getSizeInBits(NVT), NVT), ISD::SETEQ); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 2754 | Result = DAG.getNode(ISD::SELECT, NVT, Tmp2, |
Andrew Lenharth | fecf095 | 2005-05-04 19:11:05 +0000 | [diff] [blame] | 2755 | DAG.getConstant(getSizeInBits(VT),NVT), Tmp1); |
| 2756 | break; |
| 2757 | case ISD::CTLZ: |
| 2758 | //Tmp1 = Tmp1 - (sizeinbits(NVT) - sizeinbits(Old VT)) |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 2759 | Result = DAG.getNode(ISD::SUB, NVT, Tmp1, |
| 2760 | DAG.getConstant(getSizeInBits(NVT) - |
Andrew Lenharth | fecf095 | 2005-05-04 19:11:05 +0000 | [diff] [blame] | 2761 | getSizeInBits(VT), NVT)); |
| 2762 | break; |
| 2763 | } |
| 2764 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 2765 | } |
| 2766 | |
| 2767 | assert(Result.Val && "Didn't set a result!"); |
| 2768 | AddPromotedOperand(Op, Result); |
| 2769 | return Result; |
| 2770 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2771 | |
Chris Lattner | 84f6788 | 2005-01-20 18:52:28 +0000 | [diff] [blame] | 2772 | /// ExpandAddSub - Find a clever way to expand this add operation into |
| 2773 | /// subcomponents. |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 2774 | void SelectionDAGLegalize:: |
| 2775 | ExpandByParts(unsigned NodeOp, SDOperand LHS, SDOperand RHS, |
| 2776 | SDOperand &Lo, SDOperand &Hi) { |
Chris Lattner | 84f6788 | 2005-01-20 18:52:28 +0000 | [diff] [blame] | 2777 | // Expand the subcomponents. |
| 2778 | SDOperand LHSL, LHSH, RHSL, RHSH; |
| 2779 | ExpandOp(LHS, LHSL, LHSH); |
| 2780 | ExpandOp(RHS, RHSL, RHSH); |
| 2781 | |
Chris Lattner | 84f6788 | 2005-01-20 18:52:28 +0000 | [diff] [blame] | 2782 | std::vector<SDOperand> Ops; |
| 2783 | Ops.push_back(LHSL); |
| 2784 | Ops.push_back(LHSH); |
| 2785 | Ops.push_back(RHSL); |
| 2786 | Ops.push_back(RHSH); |
Chris Lattner | e89083a | 2005-05-14 07:25:05 +0000 | [diff] [blame] | 2787 | std::vector<MVT::ValueType> VTs(2, LHSL.getValueType()); |
| 2788 | Lo = DAG.getNode(NodeOp, VTs, Ops); |
Chris Lattner | 84f6788 | 2005-01-20 18:52:28 +0000 | [diff] [blame] | 2789 | Hi = Lo.getValue(1); |
| 2790 | } |
| 2791 | |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 2792 | void SelectionDAGLegalize::ExpandShiftParts(unsigned NodeOp, |
| 2793 | SDOperand Op, SDOperand Amt, |
| 2794 | SDOperand &Lo, SDOperand &Hi) { |
| 2795 | // Expand the subcomponents. |
| 2796 | SDOperand LHSL, LHSH; |
| 2797 | ExpandOp(Op, LHSL, LHSH); |
| 2798 | |
| 2799 | std::vector<SDOperand> Ops; |
| 2800 | Ops.push_back(LHSL); |
| 2801 | Ops.push_back(LHSH); |
| 2802 | Ops.push_back(Amt); |
Chris Lattner | cc0675a | 2005-08-30 17:21:17 +0000 | [diff] [blame] | 2803 | std::vector<MVT::ValueType> VTs(2, LHSL.getValueType()); |
Chris Lattner | e89083a | 2005-05-14 07:25:05 +0000 | [diff] [blame] | 2804 | Lo = DAG.getNode(NodeOp, VTs, Ops); |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 2805 | Hi = Lo.getValue(1); |
| 2806 | } |
| 2807 | |
| 2808 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 2809 | /// ExpandShift - Try to find a clever way to expand this shift operation out to |
| 2810 | /// smaller elements. If we can't find a way that is more efficient than a |
| 2811 | /// libcall on this target, return false. Otherwise, return true with the |
| 2812 | /// low-parts expanded into Lo and Hi. |
| 2813 | bool SelectionDAGLegalize::ExpandShift(unsigned Opc, SDOperand Op,SDOperand Amt, |
| 2814 | SDOperand &Lo, SDOperand &Hi) { |
| 2815 | assert((Opc == ISD::SHL || Opc == ISD::SRA || Opc == ISD::SRL) && |
| 2816 | "This is not a shift!"); |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 2817 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 2818 | MVT::ValueType NVT = TLI.getTypeToTransformTo(Op.getValueType()); |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 2819 | SDOperand ShAmt = LegalizeOp(Amt); |
| 2820 | MVT::ValueType ShTy = ShAmt.getValueType(); |
| 2821 | unsigned VTBits = MVT::getSizeInBits(Op.getValueType()); |
| 2822 | unsigned NVTBits = MVT::getSizeInBits(NVT); |
| 2823 | |
| 2824 | // Handle the case when Amt is an immediate. Other cases are currently broken |
| 2825 | // and are disabled. |
| 2826 | if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Amt.Val)) { |
| 2827 | unsigned Cst = CN->getValue(); |
| 2828 | // Expand the incoming operand to be shifted, so that we have its parts |
| 2829 | SDOperand InL, InH; |
| 2830 | ExpandOp(Op, InL, InH); |
| 2831 | switch(Opc) { |
| 2832 | case ISD::SHL: |
| 2833 | if (Cst > VTBits) { |
| 2834 | Lo = DAG.getConstant(0, NVT); |
| 2835 | Hi = DAG.getConstant(0, NVT); |
| 2836 | } else if (Cst > NVTBits) { |
| 2837 | Lo = DAG.getConstant(0, NVT); |
| 2838 | Hi = DAG.getNode(ISD::SHL, NVT, InL, DAG.getConstant(Cst-NVTBits,ShTy)); |
Chris Lattner | ee27f57 | 2005-04-11 20:08:52 +0000 | [diff] [blame] | 2839 | } else if (Cst == NVTBits) { |
| 2840 | Lo = DAG.getConstant(0, NVT); |
| 2841 | Hi = InL; |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 2842 | } else { |
| 2843 | Lo = DAG.getNode(ISD::SHL, NVT, InL, DAG.getConstant(Cst, ShTy)); |
| 2844 | Hi = DAG.getNode(ISD::OR, NVT, |
| 2845 | DAG.getNode(ISD::SHL, NVT, InH, DAG.getConstant(Cst, ShTy)), |
| 2846 | DAG.getNode(ISD::SRL, NVT, InL, DAG.getConstant(NVTBits-Cst, ShTy))); |
| 2847 | } |
| 2848 | return true; |
| 2849 | case ISD::SRL: |
| 2850 | if (Cst > VTBits) { |
| 2851 | Lo = DAG.getConstant(0, NVT); |
| 2852 | Hi = DAG.getConstant(0, NVT); |
| 2853 | } else if (Cst > NVTBits) { |
| 2854 | Lo = DAG.getNode(ISD::SRL, NVT, InH, DAG.getConstant(Cst-NVTBits,ShTy)); |
| 2855 | Hi = DAG.getConstant(0, NVT); |
Chris Lattner | ee27f57 | 2005-04-11 20:08:52 +0000 | [diff] [blame] | 2856 | } else if (Cst == NVTBits) { |
| 2857 | Lo = InH; |
| 2858 | Hi = DAG.getConstant(0, NVT); |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 2859 | } else { |
| 2860 | Lo = DAG.getNode(ISD::OR, NVT, |
| 2861 | DAG.getNode(ISD::SRL, NVT, InL, DAG.getConstant(Cst, ShTy)), |
| 2862 | DAG.getNode(ISD::SHL, NVT, InH, DAG.getConstant(NVTBits-Cst, ShTy))); |
| 2863 | Hi = DAG.getNode(ISD::SRL, NVT, InH, DAG.getConstant(Cst, ShTy)); |
| 2864 | } |
| 2865 | return true; |
| 2866 | case ISD::SRA: |
| 2867 | if (Cst > VTBits) { |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2868 | Hi = Lo = DAG.getNode(ISD::SRA, NVT, InH, |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 2869 | DAG.getConstant(NVTBits-1, ShTy)); |
| 2870 | } else if (Cst > NVTBits) { |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2871 | Lo = DAG.getNode(ISD::SRA, NVT, InH, |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 2872 | DAG.getConstant(Cst-NVTBits, ShTy)); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2873 | Hi = DAG.getNode(ISD::SRA, NVT, InH, |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 2874 | DAG.getConstant(NVTBits-1, ShTy)); |
Chris Lattner | ee27f57 | 2005-04-11 20:08:52 +0000 | [diff] [blame] | 2875 | } else if (Cst == NVTBits) { |
| 2876 | Lo = InH; |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2877 | Hi = DAG.getNode(ISD::SRA, NVT, InH, |
Chris Lattner | ee27f57 | 2005-04-11 20:08:52 +0000 | [diff] [blame] | 2878 | DAG.getConstant(NVTBits-1, ShTy)); |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 2879 | } else { |
| 2880 | Lo = DAG.getNode(ISD::OR, NVT, |
| 2881 | DAG.getNode(ISD::SRL, NVT, InL, DAG.getConstant(Cst, ShTy)), |
| 2882 | DAG.getNode(ISD::SHL, NVT, InH, DAG.getConstant(NVTBits-Cst, ShTy))); |
| 2883 | Hi = DAG.getNode(ISD::SRA, NVT, InH, DAG.getConstant(Cst, ShTy)); |
| 2884 | } |
| 2885 | return true; |
| 2886 | } |
| 2887 | } |
| 2888 | // FIXME: The following code for expanding shifts using ISD::SELECT is buggy, |
| 2889 | // so disable it for now. Currently targets are handling this via SHL_PARTS |
| 2890 | // and friends. |
| 2891 | return false; |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 2892 | |
| 2893 | // If we have an efficient select operation (or if the selects will all fold |
| 2894 | // away), lower to some complex code, otherwise just emit the libcall. |
Chris Lattner | c9c60f6 | 2005-08-24 16:35:28 +0000 | [diff] [blame] | 2895 | if (!TLI.isOperationLegal(ISD::SELECT, NVT) && !isa<ConstantSDNode>(Amt)) |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 2896 | return false; |
| 2897 | |
| 2898 | SDOperand InL, InH; |
| 2899 | ExpandOp(Op, InL, InH); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 2900 | SDOperand NAmt = DAG.getNode(ISD::SUB, ShTy, // NAmt = 32-ShAmt |
| 2901 | DAG.getConstant(NVTBits, ShTy), ShAmt); |
| 2902 | |
Chris Lattner | e5544f8 | 2005-01-20 20:29:23 +0000 | [diff] [blame] | 2903 | // Compare the unmasked shift amount against 32. |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 2904 | SDOperand Cond = DAG.getSetCC(TLI.getSetCCResultTy(), ShAmt, |
| 2905 | DAG.getConstant(NVTBits, ShTy), ISD::SETGE); |
Chris Lattner | e5544f8 | 2005-01-20 20:29:23 +0000 | [diff] [blame] | 2906 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 2907 | if (TLI.getShiftAmountFlavor() != TargetLowering::Mask) { |
| 2908 | ShAmt = DAG.getNode(ISD::AND, ShTy, ShAmt, // ShAmt &= 31 |
| 2909 | DAG.getConstant(NVTBits-1, ShTy)); |
| 2910 | NAmt = DAG.getNode(ISD::AND, ShTy, NAmt, // NAmt &= 31 |
| 2911 | DAG.getConstant(NVTBits-1, ShTy)); |
| 2912 | } |
| 2913 | |
| 2914 | if (Opc == ISD::SHL) { |
| 2915 | SDOperand T1 = DAG.getNode(ISD::OR, NVT,// T1 = (Hi << Amt) | (Lo >> NAmt) |
| 2916 | DAG.getNode(ISD::SHL, NVT, InH, ShAmt), |
| 2917 | DAG.getNode(ISD::SRL, NVT, InL, NAmt)); |
Chris Lattner | e5544f8 | 2005-01-20 20:29:23 +0000 | [diff] [blame] | 2918 | SDOperand T2 = DAG.getNode(ISD::SHL, NVT, InL, ShAmt); // T2 = Lo << Amt&31 |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2919 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 2920 | Hi = DAG.getNode(ISD::SELECT, NVT, Cond, T2, T1); |
| 2921 | Lo = DAG.getNode(ISD::SELECT, NVT, Cond, DAG.getConstant(0, NVT), T2); |
| 2922 | } else { |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 2923 | SDOperand HiLoPart = DAG.getNode(ISD::SELECT, NVT, |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 2924 | DAG.getSetCC(TLI.getSetCCResultTy(), NAmt, |
| 2925 | DAG.getConstant(32, ShTy), |
| 2926 | ISD::SETEQ), |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 2927 | DAG.getConstant(0, NVT), |
| 2928 | DAG.getNode(ISD::SHL, NVT, InH, NAmt)); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 2929 | SDOperand T1 = DAG.getNode(ISD::OR, NVT,// T1 = (Hi << NAmt) | (Lo >> Amt) |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 2930 | HiLoPart, |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 2931 | DAG.getNode(ISD::SRL, NVT, InL, ShAmt)); |
Chris Lattner | e5544f8 | 2005-01-20 20:29:23 +0000 | [diff] [blame] | 2932 | SDOperand T2 = DAG.getNode(Opc, NVT, InH, ShAmt); // T2 = InH >> ShAmt&31 |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 2933 | |
| 2934 | SDOperand HiPart; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 2935 | if (Opc == ISD::SRA) |
| 2936 | HiPart = DAG.getNode(ISD::SRA, NVT, InH, |
| 2937 | DAG.getConstant(NVTBits-1, ShTy)); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 2938 | else |
| 2939 | HiPart = DAG.getConstant(0, NVT); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 2940 | Lo = DAG.getNode(ISD::SELECT, NVT, Cond, T2, T1); |
Chris Lattner | e5544f8 | 2005-01-20 20:29:23 +0000 | [diff] [blame] | 2941 | Hi = DAG.getNode(ISD::SELECT, NVT, Cond, HiPart, T2); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 2942 | } |
| 2943 | return true; |
| 2944 | } |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 2945 | |
Chris Lattner | 9530ddc | 2005-05-13 05:09:11 +0000 | [diff] [blame] | 2946 | /// FindLatestCallSeqStart - Scan up the dag to find the latest (highest |
| 2947 | /// NodeDepth) node that is an CallSeqStart operation and occurs later than |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 2948 | /// Found. |
Chris Lattner | 9530ddc | 2005-05-13 05:09:11 +0000 | [diff] [blame] | 2949 | static void FindLatestCallSeqStart(SDNode *Node, SDNode *&Found) { |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 2950 | if (Node->getNodeDepth() <= Found->getNodeDepth()) return; |
Chris Lattner | 2f4eca3 | 2005-08-05 16:23:57 +0000 | [diff] [blame] | 2951 | |
Chris Lattner | 16cd04d | 2005-05-12 23:24:06 +0000 | [diff] [blame] | 2952 | // If we found an CALLSEQ_START, we already know this node occurs later |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 2953 | // than the Found node. Just remember this node and return. |
Chris Lattner | 16cd04d | 2005-05-12 23:24:06 +0000 | [diff] [blame] | 2954 | if (Node->getOpcode() == ISD::CALLSEQ_START) { |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 2955 | Found = Node; |
| 2956 | return; |
| 2957 | } |
| 2958 | |
| 2959 | // Otherwise, scan the operands of Node to see if any of them is a call. |
| 2960 | assert(Node->getNumOperands() != 0 && |
| 2961 | "All leaves should have depth equal to the entry node!"); |
Nate Begeman | 829cb81 | 2005-10-05 21:44:10 +0000 | [diff] [blame] | 2962 | for (unsigned i = 0, e = Node->getNumOperands()-1; i != e; ++i) |
Chris Lattner | 9530ddc | 2005-05-13 05:09:11 +0000 | [diff] [blame] | 2963 | FindLatestCallSeqStart(Node->getOperand(i).Val, Found); |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 2964 | |
| 2965 | // Tail recurse for the last iteration. |
Chris Lattner | 9530ddc | 2005-05-13 05:09:11 +0000 | [diff] [blame] | 2966 | FindLatestCallSeqStart(Node->getOperand(Node->getNumOperands()-1).Val, |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 2967 | Found); |
| 2968 | } |
| 2969 | |
| 2970 | |
Chris Lattner | 9530ddc | 2005-05-13 05:09:11 +0000 | [diff] [blame] | 2971 | /// FindEarliestCallSeqEnd - Scan down the dag to find the earliest (lowest |
| 2972 | /// NodeDepth) node that is an CallSeqEnd operation and occurs more recent |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 2973 | /// than Found. |
Chris Lattner | 82299e7 | 2005-08-05 18:10:27 +0000 | [diff] [blame] | 2974 | static void FindEarliestCallSeqEnd(SDNode *Node, SDNode *&Found, |
| 2975 | std::set<SDNode*> &Visited) { |
| 2976 | if ((Found && Node->getNodeDepth() >= Found->getNodeDepth()) || |
| 2977 | !Visited.insert(Node).second) return; |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 2978 | |
Chris Lattner | 16cd04d | 2005-05-12 23:24:06 +0000 | [diff] [blame] | 2979 | // If we found an CALLSEQ_END, we already know this node occurs earlier |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 2980 | // than the Found node. Just remember this node and return. |
Chris Lattner | 16cd04d | 2005-05-12 23:24:06 +0000 | [diff] [blame] | 2981 | if (Node->getOpcode() == ISD::CALLSEQ_END) { |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 2982 | Found = Node; |
| 2983 | return; |
| 2984 | } |
| 2985 | |
| 2986 | // Otherwise, scan the operands of Node to see if any of them is a call. |
| 2987 | SDNode::use_iterator UI = Node->use_begin(), E = Node->use_end(); |
| 2988 | if (UI == E) return; |
| 2989 | for (--E; UI != E; ++UI) |
Chris Lattner | 82299e7 | 2005-08-05 18:10:27 +0000 | [diff] [blame] | 2990 | FindEarliestCallSeqEnd(*UI, Found, Visited); |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 2991 | |
| 2992 | // Tail recurse for the last iteration. |
Chris Lattner | 82299e7 | 2005-08-05 18:10:27 +0000 | [diff] [blame] | 2993 | FindEarliestCallSeqEnd(*UI, Found, Visited); |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 2994 | } |
| 2995 | |
Chris Lattner | 9530ddc | 2005-05-13 05:09:11 +0000 | [diff] [blame] | 2996 | /// FindCallSeqEnd - Given a chained node that is part of a call sequence, |
Chris Lattner | 16cd04d | 2005-05-12 23:24:06 +0000 | [diff] [blame] | 2997 | /// find the CALLSEQ_END node that terminates the call sequence. |
Chris Lattner | 9530ddc | 2005-05-13 05:09:11 +0000 | [diff] [blame] | 2998 | static SDNode *FindCallSeqEnd(SDNode *Node) { |
Chris Lattner | 16cd04d | 2005-05-12 23:24:06 +0000 | [diff] [blame] | 2999 | if (Node->getOpcode() == ISD::CALLSEQ_END) |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 3000 | return Node; |
Chris Lattner | f4b4579 | 2005-04-02 03:22:40 +0000 | [diff] [blame] | 3001 | if (Node->use_empty()) |
Chris Lattner | 9530ddc | 2005-05-13 05:09:11 +0000 | [diff] [blame] | 3002 | return 0; // No CallSeqEnd |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 3003 | |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 3004 | SDOperand TheChain(Node, Node->getNumValues()-1); |
Chris Lattner | 2789bde | 2005-05-14 08:34:53 +0000 | [diff] [blame] | 3005 | if (TheChain.getValueType() != MVT::Other) |
| 3006 | TheChain = SDOperand(Node, 0); |
Nate Begeman | 1aa1972 | 2005-10-04 02:10:55 +0000 | [diff] [blame] | 3007 | if (TheChain.getValueType() != MVT::Other) |
| 3008 | return 0; |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 3009 | |
| 3010 | for (SDNode::use_iterator UI = Node->use_begin(), |
Chris Lattner | 2f4eca3 | 2005-08-05 16:23:57 +0000 | [diff] [blame] | 3011 | E = Node->use_end(); UI != E; ++UI) { |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 3012 | |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 3013 | // Make sure to only follow users of our token chain. |
| 3014 | SDNode *User = *UI; |
| 3015 | for (unsigned i = 0, e = User->getNumOperands(); i != e; ++i) |
| 3016 | if (User->getOperand(i) == TheChain) |
Chris Lattner | eb516e7 | 2005-05-13 05:17:00 +0000 | [diff] [blame] | 3017 | if (SDNode *Result = FindCallSeqEnd(User)) |
| 3018 | return Result; |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 3019 | } |
Chris Lattner | 2f4eca3 | 2005-08-05 16:23:57 +0000 | [diff] [blame] | 3020 | return 0; |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 3021 | } |
| 3022 | |
Chris Lattner | 9530ddc | 2005-05-13 05:09:11 +0000 | [diff] [blame] | 3023 | /// FindCallSeqStart - Given a chained node that is part of a call sequence, |
Chris Lattner | 16cd04d | 2005-05-12 23:24:06 +0000 | [diff] [blame] | 3024 | /// find the CALLSEQ_START node that initiates the call sequence. |
Chris Lattner | 9530ddc | 2005-05-13 05:09:11 +0000 | [diff] [blame] | 3025 | static SDNode *FindCallSeqStart(SDNode *Node) { |
| 3026 | assert(Node && "Didn't find callseq_start for a call??"); |
Chris Lattner | 16cd04d | 2005-05-12 23:24:06 +0000 | [diff] [blame] | 3027 | if (Node->getOpcode() == ISD::CALLSEQ_START) return Node; |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 3028 | |
| 3029 | assert(Node->getOperand(0).getValueType() == MVT::Other && |
| 3030 | "Node doesn't have a token chain argument!"); |
Chris Lattner | 9530ddc | 2005-05-13 05:09:11 +0000 | [diff] [blame] | 3031 | return FindCallSeqStart(Node->getOperand(0).Val); |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 3032 | } |
| 3033 | |
| 3034 | |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 3035 | /// FindInputOutputChains - If we are replacing an operation with a call we need |
| 3036 | /// to find the call that occurs before and the call that occurs after it to |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 3037 | /// properly serialize the calls in the block. The returned operand is the |
| 3038 | /// input chain value for the new call (e.g. the entry node or the previous |
| 3039 | /// call), and OutChain is set to be the chain node to update to point to the |
| 3040 | /// end of the call chain. |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 3041 | static SDOperand FindInputOutputChains(SDNode *OpNode, SDNode *&OutChain, |
| 3042 | SDOperand Entry) { |
Chris Lattner | 9530ddc | 2005-05-13 05:09:11 +0000 | [diff] [blame] | 3043 | SDNode *LatestCallSeqStart = Entry.Val; |
| 3044 | SDNode *LatestCallSeqEnd = 0; |
| 3045 | FindLatestCallSeqStart(OpNode, LatestCallSeqStart); |
| 3046 | //std::cerr<<"Found node: "; LatestCallSeqStart->dump(); std::cerr <<"\n"; |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 3047 | |
Chris Lattner | 16cd04d | 2005-05-12 23:24:06 +0000 | [diff] [blame] | 3048 | // It is possible that no ISD::CALLSEQ_START was found because there is no |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 3049 | // previous call in the function. LatestCallStackDown may in that case be |
Chris Lattner | 16cd04d | 2005-05-12 23:24:06 +0000 | [diff] [blame] | 3050 | // the entry node itself. Do not attempt to find a matching CALLSEQ_END |
| 3051 | // unless LatestCallStackDown is an CALLSEQ_START. |
Nate Begeman | 1aa1972 | 2005-10-04 02:10:55 +0000 | [diff] [blame] | 3052 | if (LatestCallSeqStart->getOpcode() == ISD::CALLSEQ_START) { |
Chris Lattner | 9530ddc | 2005-05-13 05:09:11 +0000 | [diff] [blame] | 3053 | LatestCallSeqEnd = FindCallSeqEnd(LatestCallSeqStart); |
Nate Begeman | 1aa1972 | 2005-10-04 02:10:55 +0000 | [diff] [blame] | 3054 | //std::cerr<<"Found end node: "; LatestCallSeqEnd->dump(); std::cerr <<"\n"; |
| 3055 | } else { |
Chris Lattner | 9530ddc | 2005-05-13 05:09:11 +0000 | [diff] [blame] | 3056 | LatestCallSeqEnd = Entry.Val; |
Nate Begeman | 1aa1972 | 2005-10-04 02:10:55 +0000 | [diff] [blame] | 3057 | } |
Chris Lattner | 9530ddc | 2005-05-13 05:09:11 +0000 | [diff] [blame] | 3058 | assert(LatestCallSeqEnd && "NULL return from FindCallSeqEnd"); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 3059 | |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 3060 | // Finally, find the first call that this must come before, first we find the |
Chris Lattner | 9530ddc | 2005-05-13 05:09:11 +0000 | [diff] [blame] | 3061 | // CallSeqEnd that ends the call. |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 3062 | OutChain = 0; |
Chris Lattner | 82299e7 | 2005-08-05 18:10:27 +0000 | [diff] [blame] | 3063 | std::set<SDNode*> Visited; |
| 3064 | FindEarliestCallSeqEnd(OpNode, OutChain, Visited); |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 3065 | |
Chris Lattner | 9530ddc | 2005-05-13 05:09:11 +0000 | [diff] [blame] | 3066 | // If we found one, translate from the adj up to the callseq_start. |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 3067 | if (OutChain) |
Chris Lattner | 9530ddc | 2005-05-13 05:09:11 +0000 | [diff] [blame] | 3068 | OutChain = FindCallSeqStart(OutChain); |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 3069 | |
Chris Lattner | 9530ddc | 2005-05-13 05:09:11 +0000 | [diff] [blame] | 3070 | return SDOperand(LatestCallSeqEnd, 0); |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 3071 | } |
| 3072 | |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 3073 | /// SpliceCallInto - Given the result chain of a libcall (CallResult), and a |
Chris Lattner | b9fa3bc | 2005-05-12 04:49:08 +0000 | [diff] [blame] | 3074 | void SelectionDAGLegalize::SpliceCallInto(const SDOperand &CallResult, |
| 3075 | SDNode *OutChain) { |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 3076 | // Nothing to splice it into? |
| 3077 | if (OutChain == 0) return; |
| 3078 | |
| 3079 | assert(OutChain->getOperand(0).getValueType() == MVT::Other); |
| 3080 | //OutChain->dump(); |
| 3081 | |
| 3082 | // Form a token factor node merging the old inval and the new inval. |
| 3083 | SDOperand InToken = DAG.getNode(ISD::TokenFactor, MVT::Other, CallResult, |
| 3084 | OutChain->getOperand(0)); |
| 3085 | // Change the node to refer to the new token. |
| 3086 | OutChain->setAdjCallChain(InToken); |
| 3087 | } |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 3088 | |
| 3089 | |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 3090 | // ExpandLibCall - Expand a node into a call to a libcall. If the result value |
| 3091 | // does not fit into a register, return the lo part and set the hi part to the |
| 3092 | // by-reg argument. If it does fit into a single register, return the result |
| 3093 | // and leave the Hi part unset. |
| 3094 | SDOperand SelectionDAGLegalize::ExpandLibCall(const char *Name, SDNode *Node, |
| 3095 | SDOperand &Hi) { |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 3096 | SDNode *OutChain; |
| 3097 | SDOperand InChain = FindInputOutputChains(Node, OutChain, |
| 3098 | DAG.getEntryNode()); |
Chris Lattner | f4b4579 | 2005-04-02 03:22:40 +0000 | [diff] [blame] | 3099 | if (InChain.Val == 0) |
| 3100 | InChain = DAG.getEntryNode(); |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 3101 | |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 3102 | TargetLowering::ArgListTy Args; |
| 3103 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) { |
| 3104 | MVT::ValueType ArgVT = Node->getOperand(i).getValueType(); |
| 3105 | const Type *ArgTy = MVT::getTypeForValueType(ArgVT); |
| 3106 | Args.push_back(std::make_pair(Node->getOperand(i), ArgTy)); |
| 3107 | } |
| 3108 | SDOperand Callee = DAG.getExternalSymbol(Name, TLI.getPointerTy()); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 3109 | |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 3110 | // Splice the libcall in wherever FindInputOutputChains tells us to. |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 3111 | const Type *RetTy = MVT::getTypeForValueType(Node->getValueType(0)); |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 3112 | std::pair<SDOperand,SDOperand> CallInfo = |
Chris Lattner | adf6a96 | 2005-05-13 18:50:42 +0000 | [diff] [blame] | 3113 | TLI.LowerCallTo(InChain, RetTy, false, CallingConv::C, false, |
| 3114 | Callee, Args, DAG); |
Chris Lattner | b9fa3bc | 2005-05-12 04:49:08 +0000 | [diff] [blame] | 3115 | |
Chris Lattner | 99c25b8 | 2005-09-02 20:26:58 +0000 | [diff] [blame] | 3116 | SDOperand Result; |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 3117 | switch (getTypeAction(CallInfo.first.getValueType())) { |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 3118 | default: assert(0 && "Unknown thing"); |
| 3119 | case Legal: |
Chris Lattner | 99c25b8 | 2005-09-02 20:26:58 +0000 | [diff] [blame] | 3120 | Result = CallInfo.first; |
| 3121 | break; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 3122 | case Promote: |
| 3123 | assert(0 && "Cannot promote this yet!"); |
| 3124 | case Expand: |
Chris Lattner | 99c25b8 | 2005-09-02 20:26:58 +0000 | [diff] [blame] | 3125 | ExpandOp(CallInfo.first, Result, Hi); |
| 3126 | CallInfo.second = LegalizeOp(CallInfo.second); |
| 3127 | break; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 3128 | } |
Chris Lattner | 99c25b8 | 2005-09-02 20:26:58 +0000 | [diff] [blame] | 3129 | |
| 3130 | SpliceCallInto(CallInfo.second, OutChain); |
| 3131 | NeedsAnotherIteration = true; |
| 3132 | return Result; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 3133 | } |
| 3134 | |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 3135 | |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 3136 | /// ExpandIntToFP - Expand a [US]INT_TO_FP operation, assuming that the |
| 3137 | /// destination type is legal. |
| 3138 | SDOperand SelectionDAGLegalize:: |
| 3139 | ExpandIntToFP(bool isSigned, MVT::ValueType DestTy, SDOperand Source) { |
Chris Lattner | c9c60f6 | 2005-08-24 16:35:28 +0000 | [diff] [blame] | 3140 | assert(isTypeLegal(DestTy) && "Destination type is not legal!"); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 3141 | assert(getTypeAction(Source.getValueType()) == Expand && |
| 3142 | "This is not an expansion!"); |
| 3143 | assert(Source.getValueType() == MVT::i64 && "Only handle expand from i64!"); |
| 3144 | |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 3145 | if (!isSigned) { |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 3146 | assert(Source.getValueType() == MVT::i64 && |
| 3147 | "This only works for 64-bit -> FP"); |
| 3148 | // The 64-bit value loaded will be incorrectly if the 'sign bit' of the |
| 3149 | // incoming integer is set. To handle this, we dynamically test to see if |
| 3150 | // it is set, and, if so, add a fudge factor. |
| 3151 | SDOperand Lo, Hi; |
| 3152 | ExpandOp(Source, Lo, Hi); |
| 3153 | |
Chris Lattner | 66de05b | 2005-05-13 04:45:13 +0000 | [diff] [blame] | 3154 | // If this is unsigned, and not supported, first perform the conversion to |
| 3155 | // signed, then adjust the result if the sign bit is set. |
| 3156 | SDOperand SignedConv = ExpandIntToFP(true, DestTy, |
| 3157 | DAG.getNode(ISD::BUILD_PAIR, Source.getValueType(), Lo, Hi)); |
| 3158 | |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 3159 | SDOperand SignSet = DAG.getSetCC(TLI.getSetCCResultTy(), Hi, |
| 3160 | DAG.getConstant(0, Hi.getValueType()), |
| 3161 | ISD::SETLT); |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 3162 | SDOperand Zero = getIntPtrConstant(0), Four = getIntPtrConstant(4); |
| 3163 | SDOperand CstOffset = DAG.getNode(ISD::SELECT, Zero.getValueType(), |
| 3164 | SignSet, Four, Zero); |
Chris Lattner | 383203b | 2005-05-12 18:52:34 +0000 | [diff] [blame] | 3165 | uint64_t FF = 0x5f800000ULL; |
| 3166 | if (TLI.isLittleEndian()) FF <<= 32; |
| 3167 | static Constant *FudgeFactor = ConstantUInt::get(Type::ULongTy, FF); |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 3168 | |
Chris Lattner | 5839bf2 | 2005-08-26 17:15:30 +0000 | [diff] [blame] | 3169 | SDOperand CPIdx = DAG.getConstantPool(FudgeFactor, TLI.getPointerTy()); |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 3170 | CPIdx = DAG.getNode(ISD::ADD, TLI.getPointerTy(), CPIdx, CstOffset); |
| 3171 | SDOperand FudgeInReg; |
| 3172 | if (DestTy == MVT::f32) |
Chris Lattner | 52d08bd | 2005-05-09 20:23:03 +0000 | [diff] [blame] | 3173 | FudgeInReg = DAG.getLoad(MVT::f32, DAG.getEntryNode(), CPIdx, |
| 3174 | DAG.getSrcValue(NULL)); |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 3175 | else { |
| 3176 | assert(DestTy == MVT::f64 && "Unexpected conversion"); |
Chris Lattner | 5f056bf | 2005-07-10 01:55:33 +0000 | [diff] [blame] | 3177 | FudgeInReg = DAG.getExtLoad(ISD::EXTLOAD, MVT::f64, DAG.getEntryNode(), |
| 3178 | CPIdx, DAG.getSrcValue(NULL), MVT::f32); |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 3179 | } |
Chris Lattner | 473a990 | 2005-09-29 06:44:39 +0000 | [diff] [blame] | 3180 | return DAG.getNode(ISD::FADD, DestTy, SignedConv, FudgeInReg); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 3181 | } |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 3182 | |
Chris Lattner | a88a260 | 2005-05-14 05:33:54 +0000 | [diff] [blame] | 3183 | // Check to see if the target has a custom way to lower this. If so, use it. |
| 3184 | switch (TLI.getOperationAction(ISD::SINT_TO_FP, Source.getValueType())) { |
| 3185 | default: assert(0 && "This action not implemented for this operation!"); |
| 3186 | case TargetLowering::Legal: |
| 3187 | case TargetLowering::Expand: |
| 3188 | break; // This case is handled below. |
Chris Lattner | 07dffd6 | 2005-08-26 00:14:16 +0000 | [diff] [blame] | 3189 | case TargetLowering::Custom: { |
| 3190 | SDOperand NV = TLI.LowerOperation(DAG.getNode(ISD::SINT_TO_FP, DestTy, |
| 3191 | Source), DAG); |
| 3192 | if (NV.Val) |
| 3193 | return LegalizeOp(NV); |
| 3194 | break; // The target decided this was legal after all |
| 3195 | } |
Chris Lattner | a88a260 | 2005-05-14 05:33:54 +0000 | [diff] [blame] | 3196 | } |
| 3197 | |
Chris Lattner | 13689e2 | 2005-05-12 07:00:44 +0000 | [diff] [blame] | 3198 | // Expand the source, then glue it back together for the call. We must expand |
| 3199 | // the source in case it is shared (this pass of legalize must traverse it). |
| 3200 | SDOperand SrcLo, SrcHi; |
| 3201 | ExpandOp(Source, SrcLo, SrcHi); |
| 3202 | Source = DAG.getNode(ISD::BUILD_PAIR, Source.getValueType(), SrcLo, SrcHi); |
| 3203 | |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 3204 | SDNode *OutChain = 0; |
| 3205 | SDOperand InChain = FindInputOutputChains(Source.Val, OutChain, |
| 3206 | DAG.getEntryNode()); |
| 3207 | const char *FnName = 0; |
| 3208 | if (DestTy == MVT::f32) |
| 3209 | FnName = "__floatdisf"; |
| 3210 | else { |
| 3211 | assert(DestTy == MVT::f64 && "Unknown fp value type!"); |
| 3212 | FnName = "__floatdidf"; |
| 3213 | } |
| 3214 | |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 3215 | SDOperand Callee = DAG.getExternalSymbol(FnName, TLI.getPointerTy()); |
| 3216 | |
| 3217 | TargetLowering::ArgListTy Args; |
| 3218 | const Type *ArgTy = MVT::getTypeForValueType(Source.getValueType()); |
Chris Lattner | 44d105b | 2005-05-12 06:54:21 +0000 | [diff] [blame] | 3219 | |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 3220 | Args.push_back(std::make_pair(Source, ArgTy)); |
| 3221 | |
| 3222 | // We don't care about token chains for libcalls. We just use the entry |
| 3223 | // node as our input and ignore the output chain. This allows us to place |
| 3224 | // calls wherever we need them to satisfy data dependences. |
| 3225 | const Type *RetTy = MVT::getTypeForValueType(DestTy); |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 3226 | |
| 3227 | std::pair<SDOperand,SDOperand> CallResult = |
Chris Lattner | adf6a96 | 2005-05-13 18:50:42 +0000 | [diff] [blame] | 3228 | TLI.LowerCallTo(InChain, RetTy, false, CallingConv::C, true, |
| 3229 | Callee, Args, DAG); |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 3230 | |
Chris Lattner | b9fa3bc | 2005-05-12 04:49:08 +0000 | [diff] [blame] | 3231 | SpliceCallInto(CallResult.second, OutChain); |
Chris Lattner | 0d67f0c | 2005-05-11 19:02:11 +0000 | [diff] [blame] | 3232 | return CallResult.first; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 3233 | } |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 3234 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 3235 | |
| 3236 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3237 | /// ExpandOp - Expand the specified SDOperand into its two component pieces |
| 3238 | /// Lo&Hi. Note that the Op MUST be an expanded type. As a result of this, the |
| 3239 | /// LegalizeNodes map is filled in for any results that are not expanded, the |
| 3240 | /// ExpandedNodes map is filled in for any results that are expanded, and the |
| 3241 | /// Lo/Hi values are returned. |
| 3242 | void SelectionDAGLegalize::ExpandOp(SDOperand Op, SDOperand &Lo, SDOperand &Hi){ |
| 3243 | MVT::ValueType VT = Op.getValueType(); |
Chris Lattner | 71c42a0 | 2005-01-16 01:11:45 +0000 | [diff] [blame] | 3244 | MVT::ValueType NVT = TLI.getTypeToTransformTo(VT); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3245 | SDNode *Node = Op.Val; |
| 3246 | assert(getTypeAction(VT) == Expand && "Not an expanded type!"); |
Nate Begeman | ab48be3 | 2005-11-22 18:16:00 +0000 | [diff] [blame] | 3247 | assert((MVT::isInteger(VT) || VT == MVT::Vector) && |
| 3248 | "Cannot expand FP values!"); |
| 3249 | assert(((MVT::isInteger(NVT) && NVT < VT) || VT == MVT::Vector) && |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3250 | "Cannot expand to FP value or to larger int value!"); |
| 3251 | |
Chris Lattner | 6fdcb25 | 2005-09-02 20:32:45 +0000 | [diff] [blame] | 3252 | // See if we already expanded it. |
| 3253 | std::map<SDOperand, std::pair<SDOperand, SDOperand> >::iterator I |
| 3254 | = ExpandedNodes.find(Op); |
| 3255 | if (I != ExpandedNodes.end()) { |
| 3256 | Lo = I->second.first; |
| 3257 | Hi = I->second.second; |
| 3258 | return; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3259 | } |
| 3260 | |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 3261 | // Expanding to multiple registers needs to perform an optimization step, and |
| 3262 | // is not careful to avoid operations the target does not support. Make sure |
| 3263 | // that all generated operations are legalized in the next iteration. |
| 3264 | NeedsAnotherIteration = true; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3265 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3266 | switch (Node->getOpcode()) { |
Chris Lattner | d5d0f9b | 2005-08-16 21:55:35 +0000 | [diff] [blame] | 3267 | case ISD::CopyFromReg: |
| 3268 | assert(0 && "CopyFromReg must be legal!"); |
| 3269 | default: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3270 | std::cerr << "NODE: "; Node->dump(); std::cerr << "\n"; |
| 3271 | assert(0 && "Do not know how to expand this operator!"); |
| 3272 | abort(); |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 3273 | case ISD::UNDEF: |
| 3274 | Lo = DAG.getNode(ISD::UNDEF, NVT); |
| 3275 | Hi = DAG.getNode(ISD::UNDEF, NVT); |
| 3276 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3277 | case ISD::Constant: { |
| 3278 | uint64_t Cst = cast<ConstantSDNode>(Node)->getValue(); |
| 3279 | Lo = DAG.getConstant(Cst, NVT); |
| 3280 | Hi = DAG.getConstant(Cst >> MVT::getSizeInBits(NVT), NVT); |
| 3281 | break; |
| 3282 | } |
Nate Begeman | cc827e6 | 2005-12-07 19:48:11 +0000 | [diff] [blame] | 3283 | case ISD::ConstantVec: { |
| 3284 | unsigned NumElements = Node->getNumOperands(); |
| 3285 | // If we only have two elements left in the constant vector, just break it |
| 3286 | // apart into the two scalar constants it contains. Otherwise, bisect the |
| 3287 | // ConstantVec, and return each half as a new ConstantVec. |
| 3288 | // FIXME: this is hard coded as big endian, it may have to change to support |
| 3289 | // SSE and Alpha MVI |
| 3290 | if (NumElements == 2) { |
| 3291 | Hi = Node->getOperand(0); |
| 3292 | Lo = Node->getOperand(1); |
| 3293 | } else { |
| 3294 | NumElements /= 2; |
| 3295 | std::vector<SDOperand> LoOps, HiOps; |
| 3296 | for (unsigned I = 0, E = NumElements; I < E; ++I) { |
| 3297 | HiOps.push_back(Node->getOperand(I)); |
| 3298 | LoOps.push_back(Node->getOperand(I+NumElements)); |
| 3299 | } |
| 3300 | Lo = DAG.getNode(ISD::ConstantVec, MVT::Vector, LoOps); |
| 3301 | Hi = DAG.getNode(ISD::ConstantVec, MVT::Vector, HiOps); |
| 3302 | } |
| 3303 | break; |
| 3304 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3305 | |
Chris Lattner | d4e50bb | 2005-03-28 22:03:13 +0000 | [diff] [blame] | 3306 | case ISD::BUILD_PAIR: |
| 3307 | // Legalize both operands. FIXME: in the future we should handle the case |
| 3308 | // where the two elements are not legal. |
| 3309 | assert(isTypeLegal(NVT) && "Cannot expand this multiple times yet!"); |
| 3310 | Lo = LegalizeOp(Node->getOperand(0)); |
| 3311 | Hi = LegalizeOp(Node->getOperand(1)); |
| 3312 | break; |
Chris Lattner | 58f7963 | 2005-12-12 22:27:43 +0000 | [diff] [blame] | 3313 | |
| 3314 | case ISD::SIGN_EXTEND_INREG: |
| 3315 | ExpandOp(Node->getOperand(0), Lo, Hi); |
| 3316 | // Sign extend the lo-part. |
| 3317 | Hi = DAG.getNode(ISD::SRA, NVT, Lo, |
| 3318 | DAG.getConstant(MVT::getSizeInBits(NVT)-1, |
| 3319 | TLI.getShiftAmountTy())); |
| 3320 | // sext_inreg the low part if needed. |
| 3321 | Lo = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Lo, Node->getOperand(1)); |
| 3322 | break; |
Chris Lattner | d4e50bb | 2005-03-28 22:03:13 +0000 | [diff] [blame] | 3323 | |
Chris Lattner | edb1add | 2005-05-11 04:51:16 +0000 | [diff] [blame] | 3324 | case ISD::CTPOP: |
| 3325 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Chris Lattner | 9b583b4 | 2005-05-11 05:09:47 +0000 | [diff] [blame] | 3326 | Lo = DAG.getNode(ISD::ADD, NVT, // ctpop(HL) -> ctpop(H)+ctpop(L) |
| 3327 | DAG.getNode(ISD::CTPOP, NVT, Lo), |
| 3328 | DAG.getNode(ISD::CTPOP, NVT, Hi)); |
Chris Lattner | edb1add | 2005-05-11 04:51:16 +0000 | [diff] [blame] | 3329 | Hi = DAG.getConstant(0, NVT); |
| 3330 | break; |
| 3331 | |
Chris Lattner | 39a8f33 | 2005-05-12 19:05:01 +0000 | [diff] [blame] | 3332 | case ISD::CTLZ: { |
| 3333 | // ctlz (HL) -> ctlz(H) != 32 ? ctlz(H) : (ctlz(L)+32) |
Chris Lattner | 3becf20 | 2005-05-12 19:27:51 +0000 | [diff] [blame] | 3334 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Chris Lattner | 39a8f33 | 2005-05-12 19:05:01 +0000 | [diff] [blame] | 3335 | SDOperand BitsC = DAG.getConstant(MVT::getSizeInBits(NVT), NVT); |
| 3336 | SDOperand HLZ = DAG.getNode(ISD::CTLZ, NVT, Hi); |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 3337 | SDOperand TopNotZero = DAG.getSetCC(TLI.getSetCCResultTy(), HLZ, BitsC, |
| 3338 | ISD::SETNE); |
Chris Lattner | 39a8f33 | 2005-05-12 19:05:01 +0000 | [diff] [blame] | 3339 | SDOperand LowPart = DAG.getNode(ISD::CTLZ, NVT, Lo); |
| 3340 | LowPart = DAG.getNode(ISD::ADD, NVT, LowPart, BitsC); |
| 3341 | |
| 3342 | Lo = DAG.getNode(ISD::SELECT, NVT, TopNotZero, HLZ, LowPart); |
| 3343 | Hi = DAG.getConstant(0, NVT); |
| 3344 | break; |
| 3345 | } |
| 3346 | |
| 3347 | case ISD::CTTZ: { |
| 3348 | // cttz (HL) -> cttz(L) != 32 ? cttz(L) : (cttz(H)+32) |
Chris Lattner | 3becf20 | 2005-05-12 19:27:51 +0000 | [diff] [blame] | 3349 | ExpandOp(Node->getOperand(0), Lo, Hi); |
Chris Lattner | 39a8f33 | 2005-05-12 19:05:01 +0000 | [diff] [blame] | 3350 | SDOperand BitsC = DAG.getConstant(MVT::getSizeInBits(NVT), NVT); |
| 3351 | SDOperand LTZ = DAG.getNode(ISD::CTTZ, NVT, Lo); |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 3352 | SDOperand BotNotZero = DAG.getSetCC(TLI.getSetCCResultTy(), LTZ, BitsC, |
| 3353 | ISD::SETNE); |
Chris Lattner | 39a8f33 | 2005-05-12 19:05:01 +0000 | [diff] [blame] | 3354 | SDOperand HiPart = DAG.getNode(ISD::CTTZ, NVT, Hi); |
| 3355 | HiPart = DAG.getNode(ISD::ADD, NVT, HiPart, BitsC); |
| 3356 | |
| 3357 | Lo = DAG.getNode(ISD::SELECT, NVT, BotNotZero, LTZ, HiPart); |
| 3358 | Hi = DAG.getConstant(0, NVT); |
| 3359 | break; |
| 3360 | } |
Chris Lattner | edb1add | 2005-05-11 04:51:16 +0000 | [diff] [blame] | 3361 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3362 | case ISD::LOAD: { |
| 3363 | SDOperand Ch = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 3364 | SDOperand Ptr = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 3365 | Lo = DAG.getLoad(NVT, Ch, Ptr, Node->getOperand(2)); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3366 | |
| 3367 | // Increment the pointer to the other half. |
Chris Lattner | 38d6be5 | 2005-01-09 19:43:23 +0000 | [diff] [blame] | 3368 | unsigned IncrementSize = MVT::getSizeInBits(Lo.getValueType())/8; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3369 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
| 3370 | getIntPtrConstant(IncrementSize)); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 3371 | //Is this safe? declaring that the two parts of the split load |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 3372 | //are from the same instruction? |
| 3373 | Hi = DAG.getLoad(NVT, Ch, Ptr, Node->getOperand(2)); |
Chris Lattner | ec39a45 | 2005-01-19 18:02:17 +0000 | [diff] [blame] | 3374 | |
| 3375 | // Build a factor node to remember that this load is independent of the |
| 3376 | // other one. |
| 3377 | SDOperand TF = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1), |
| 3378 | Hi.getValue(1)); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 3379 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3380 | // Remember that we legalized the chain. |
Chris Lattner | ec39a45 | 2005-01-19 18:02:17 +0000 | [diff] [blame] | 3381 | AddLegalizedOperand(Op.getValue(1), TF); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3382 | if (!TLI.isLittleEndian()) |
| 3383 | std::swap(Lo, Hi); |
| 3384 | break; |
| 3385 | } |
Nate Begeman | ab48be3 | 2005-11-22 18:16:00 +0000 | [diff] [blame] | 3386 | case ISD::VLOAD: { |
| 3387 | SDOperand Ch = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 3388 | SDOperand Ptr = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. |
| 3389 | unsigned NumElements =cast<ConstantSDNode>(Node->getOperand(2))->getValue(); |
| 3390 | MVT::ValueType EVT = cast<VTSDNode>(Node->getOperand(3))->getVT(); |
| 3391 | |
| 3392 | // If we only have two elements, turn into a pair of scalar loads. |
| 3393 | // FIXME: handle case where a vector of two elements is fine, such as |
| 3394 | // 2 x double on SSE2. |
| 3395 | if (NumElements == 2) { |
| 3396 | Lo = DAG.getLoad(EVT, Ch, Ptr, Node->getOperand(4)); |
| 3397 | // Increment the pointer to the other half. |
| 3398 | unsigned IncrementSize = MVT::getSizeInBits(EVT)/8; |
| 3399 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
| 3400 | getIntPtrConstant(IncrementSize)); |
| 3401 | //Is this safe? declaring that the two parts of the split load |
| 3402 | //are from the same instruction? |
| 3403 | Hi = DAG.getLoad(EVT, Ch, Ptr, Node->getOperand(4)); |
| 3404 | } else { |
| 3405 | NumElements /= 2; // Split the vector in half |
| 3406 | Lo = DAG.getVecLoad(NumElements, EVT, Ch, Ptr, Node->getOperand(4)); |
| 3407 | unsigned IncrementSize = NumElements * MVT::getSizeInBits(EVT)/8; |
| 3408 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
| 3409 | getIntPtrConstant(IncrementSize)); |
| 3410 | //Is this safe? declaring that the two parts of the split load |
| 3411 | //are from the same instruction? |
| 3412 | Hi = DAG.getVecLoad(NumElements, EVT, Ch, Ptr, Node->getOperand(4)); |
| 3413 | } |
| 3414 | |
| 3415 | // Build a factor node to remember that this load is independent of the |
| 3416 | // other one. |
| 3417 | SDOperand TF = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1), |
| 3418 | Hi.getValue(1)); |
| 3419 | |
| 3420 | // Remember that we legalized the chain. |
| 3421 | AddLegalizedOperand(Op.getValue(1), TF); |
| 3422 | if (!TLI.isLittleEndian()) |
| 3423 | std::swap(Lo, Hi); |
| 3424 | break; |
| 3425 | } |
| 3426 | case ISD::VADD: |
| 3427 | case ISD::VSUB: |
| 3428 | case ISD::VMUL: { |
| 3429 | unsigned NumElements =cast<ConstantSDNode>(Node->getOperand(2))->getValue(); |
| 3430 | MVT::ValueType EVT = cast<VTSDNode>(Node->getOperand(3))->getVT(); |
| 3431 | SDOperand LL, LH, RL, RH; |
| 3432 | |
| 3433 | ExpandOp(Node->getOperand(0), LL, LH); |
| 3434 | ExpandOp(Node->getOperand(1), RL, RH); |
| 3435 | |
| 3436 | // If we only have two elements, turn into a pair of scalar loads. |
| 3437 | // FIXME: handle case where a vector of two elements is fine, such as |
| 3438 | // 2 x double on SSE2. |
| 3439 | if (NumElements == 2) { |
| 3440 | unsigned Opc = getScalarizedOpcode(Node->getOpcode(), EVT); |
| 3441 | Lo = DAG.getNode(Opc, EVT, LL, RL); |
| 3442 | Hi = DAG.getNode(Opc, EVT, LH, RH); |
| 3443 | } else { |
| 3444 | Lo = DAG.getNode(Node->getOpcode(), MVT::Vector, LL, RL, LL.getOperand(2), |
| 3445 | LL.getOperand(3)); |
| 3446 | Hi = DAG.getNode(Node->getOpcode(), MVT::Vector, LH, RH, LH.getOperand(2), |
| 3447 | LH.getOperand(3)); |
| 3448 | } |
| 3449 | break; |
| 3450 | } |
Chris Lattner | d71c041 | 2005-05-13 18:43:43 +0000 | [diff] [blame] | 3451 | case ISD::TAILCALL: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3452 | case ISD::CALL: { |
| 3453 | SDOperand Chain = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 3454 | SDOperand Callee = LegalizeOp(Node->getOperand(1)); // Legalize the callee. |
| 3455 | |
Chris Lattner | 3d9dffc | 2005-01-19 20:24:35 +0000 | [diff] [blame] | 3456 | bool Changed = false; |
| 3457 | std::vector<SDOperand> Ops; |
| 3458 | for (unsigned i = 2, e = Node->getNumOperands(); i != e; ++i) { |
| 3459 | Ops.push_back(LegalizeOp(Node->getOperand(i))); |
| 3460 | Changed |= Ops.back() != Node->getOperand(i); |
| 3461 | } |
| 3462 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3463 | assert(Node->getNumValues() == 2 && Op.ResNo == 0 && |
| 3464 | "Can only expand a call once so far, not i64 -> i16!"); |
| 3465 | |
| 3466 | std::vector<MVT::ValueType> RetTyVTs; |
| 3467 | RetTyVTs.reserve(3); |
| 3468 | RetTyVTs.push_back(NVT); |
| 3469 | RetTyVTs.push_back(NVT); |
| 3470 | RetTyVTs.push_back(MVT::Other); |
Chris Lattner | d71c041 | 2005-05-13 18:43:43 +0000 | [diff] [blame] | 3471 | SDNode *NC = DAG.getCall(RetTyVTs, Chain, Callee, Ops, |
| 3472 | Node->getOpcode() == ISD::TAILCALL); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3473 | Lo = SDOperand(NC, 0); |
| 3474 | Hi = SDOperand(NC, 1); |
| 3475 | |
| 3476 | // Insert the new chain mapping. |
Chris Lattner | e3304a3 | 2005-01-08 20:35:13 +0000 | [diff] [blame] | 3477 | AddLegalizedOperand(Op.getValue(1), Hi.getValue(2)); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3478 | break; |
| 3479 | } |
| 3480 | case ISD::AND: |
| 3481 | case ISD::OR: |
| 3482 | case ISD::XOR: { // Simple logical operators -> two trivial pieces. |
| 3483 | SDOperand LL, LH, RL, RH; |
| 3484 | ExpandOp(Node->getOperand(0), LL, LH); |
| 3485 | ExpandOp(Node->getOperand(1), RL, RH); |
| 3486 | Lo = DAG.getNode(Node->getOpcode(), NVT, LL, RL); |
| 3487 | Hi = DAG.getNode(Node->getOpcode(), NVT, LH, RH); |
| 3488 | break; |
| 3489 | } |
| 3490 | case ISD::SELECT: { |
| 3491 | SDOperand C, LL, LH, RL, RH; |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 3492 | |
| 3493 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3494 | case Expand: assert(0 && "It's impossible to expand bools"); |
| 3495 | case Legal: |
| 3496 | C = LegalizeOp(Node->getOperand(0)); // Legalize the condition. |
| 3497 | break; |
| 3498 | case Promote: |
| 3499 | C = PromoteOp(Node->getOperand(0)); // Promote the condition. |
| 3500 | break; |
| 3501 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3502 | ExpandOp(Node->getOperand(1), LL, LH); |
| 3503 | ExpandOp(Node->getOperand(2), RL, RH); |
| 3504 | Lo = DAG.getNode(ISD::SELECT, NVT, C, LL, RL); |
| 3505 | Hi = DAG.getNode(ISD::SELECT, NVT, C, LH, RH); |
| 3506 | break; |
| 3507 | } |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 3508 | case ISD::SELECT_CC: { |
| 3509 | SDOperand TL, TH, FL, FH; |
| 3510 | ExpandOp(Node->getOperand(2), TL, TH); |
| 3511 | ExpandOp(Node->getOperand(3), FL, FH); |
| 3512 | Lo = DAG.getNode(ISD::SELECT_CC, NVT, Node->getOperand(0), |
| 3513 | Node->getOperand(1), TL, FL, Node->getOperand(4)); |
| 3514 | Hi = DAG.getNode(ISD::SELECT_CC, NVT, Node->getOperand(0), |
| 3515 | Node->getOperand(1), TH, FH, Node->getOperand(4)); |
Nate Begeman | e5d6382 | 2005-08-11 01:12:20 +0000 | [diff] [blame] | 3516 | Lo = LegalizeOp(Lo); |
| 3517 | Hi = LegalizeOp(Hi); |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 3518 | break; |
| 3519 | } |
Nate Begeman | 144ff66 | 2005-10-13 17:15:37 +0000 | [diff] [blame] | 3520 | case ISD::SEXTLOAD: { |
| 3521 | SDOperand Chain = LegalizeOp(Node->getOperand(0)); |
| 3522 | SDOperand Ptr = LegalizeOp(Node->getOperand(1)); |
| 3523 | MVT::ValueType EVT = cast<VTSDNode>(Node->getOperand(3))->getVT(); |
| 3524 | |
| 3525 | if (EVT == NVT) |
| 3526 | Lo = DAG.getLoad(NVT, Chain, Ptr, Node->getOperand(2)); |
| 3527 | else |
| 3528 | Lo = DAG.getExtLoad(ISD::SEXTLOAD, NVT, Chain, Ptr, Node->getOperand(2), |
| 3529 | EVT); |
Chris Lattner | 9ad8481 | 2005-10-13 21:44:47 +0000 | [diff] [blame] | 3530 | |
| 3531 | // Remember that we legalized the chain. |
| 3532 | AddLegalizedOperand(SDOperand(Node, 1), Lo.getValue(1)); |
| 3533 | |
Nate Begeman | 144ff66 | 2005-10-13 17:15:37 +0000 | [diff] [blame] | 3534 | // The high part is obtained by SRA'ing all but one of the bits of the lo |
| 3535 | // part. |
| 3536 | unsigned LoSize = MVT::getSizeInBits(Lo.getValueType()); |
| 3537 | Hi = DAG.getNode(ISD::SRA, NVT, Lo, DAG.getConstant(LoSize-1, |
| 3538 | TLI.getShiftAmountTy())); |
| 3539 | Lo = LegalizeOp(Lo); |
| 3540 | Hi = LegalizeOp(Hi); |
| 3541 | break; |
| 3542 | } |
| 3543 | case ISD::ZEXTLOAD: { |
| 3544 | SDOperand Chain = LegalizeOp(Node->getOperand(0)); |
| 3545 | SDOperand Ptr = LegalizeOp(Node->getOperand(1)); |
| 3546 | MVT::ValueType EVT = cast<VTSDNode>(Node->getOperand(3))->getVT(); |
| 3547 | |
| 3548 | if (EVT == NVT) |
| 3549 | Lo = DAG.getLoad(NVT, Chain, Ptr, Node->getOperand(2)); |
| 3550 | else |
| 3551 | Lo = DAG.getExtLoad(ISD::ZEXTLOAD, NVT, Chain, Ptr, Node->getOperand(2), |
| 3552 | EVT); |
Chris Lattner | 9ad8481 | 2005-10-13 21:44:47 +0000 | [diff] [blame] | 3553 | |
| 3554 | // Remember that we legalized the chain. |
| 3555 | AddLegalizedOperand(SDOperand(Node, 1), Lo.getValue(1)); |
| 3556 | |
Nate Begeman | 144ff66 | 2005-10-13 17:15:37 +0000 | [diff] [blame] | 3557 | // The high part is just a zero. |
Chris Lattner | 9ad8481 | 2005-10-13 21:44:47 +0000 | [diff] [blame] | 3558 | Hi = LegalizeOp(DAG.getConstant(0, NVT)); |
Nate Begeman | 144ff66 | 2005-10-13 17:15:37 +0000 | [diff] [blame] | 3559 | Lo = LegalizeOp(Lo); |
Chris Lattner | 9ad8481 | 2005-10-13 21:44:47 +0000 | [diff] [blame] | 3560 | break; |
| 3561 | } |
| 3562 | case ISD::EXTLOAD: { |
| 3563 | SDOperand Chain = LegalizeOp(Node->getOperand(0)); |
| 3564 | SDOperand Ptr = LegalizeOp(Node->getOperand(1)); |
| 3565 | MVT::ValueType EVT = cast<VTSDNode>(Node->getOperand(3))->getVT(); |
| 3566 | |
| 3567 | if (EVT == NVT) |
| 3568 | Lo = DAG.getLoad(NVT, Chain, Ptr, Node->getOperand(2)); |
| 3569 | else |
| 3570 | Lo = DAG.getExtLoad(ISD::EXTLOAD, NVT, Chain, Ptr, Node->getOperand(2), |
| 3571 | EVT); |
| 3572 | |
| 3573 | // Remember that we legalized the chain. |
| 3574 | AddLegalizedOperand(SDOperand(Node, 1), Lo.getValue(1)); |
| 3575 | |
| 3576 | // The high part is undefined. |
| 3577 | Hi = LegalizeOp(DAG.getNode(ISD::UNDEF, NVT)); |
| 3578 | Lo = LegalizeOp(Lo); |
Nate Begeman | 144ff66 | 2005-10-13 17:15:37 +0000 | [diff] [blame] | 3579 | break; |
| 3580 | } |
Chris Lattner | 13c78e2 | 2005-09-02 00:18:10 +0000 | [diff] [blame] | 3581 | case ISD::ANY_EXTEND: { |
| 3582 | SDOperand In; |
| 3583 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3584 | case Expand: assert(0 && "expand-expand not implemented yet!"); |
| 3585 | case Legal: In = LegalizeOp(Node->getOperand(0)); break; |
| 3586 | case Promote: |
| 3587 | In = PromoteOp(Node->getOperand(0)); |
| 3588 | break; |
| 3589 | } |
| 3590 | |
| 3591 | // The low part is any extension of the input (which degenerates to a copy). |
| 3592 | Lo = DAG.getNode(ISD::ANY_EXTEND, NVT, In); |
| 3593 | // The high part is undefined. |
| 3594 | Hi = DAG.getNode(ISD::UNDEF, NVT); |
| 3595 | break; |
| 3596 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3597 | case ISD::SIGN_EXTEND: { |
Chris Lattner | 06098e0 | 2005-04-03 23:41:52 +0000 | [diff] [blame] | 3598 | SDOperand In; |
| 3599 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3600 | case Expand: assert(0 && "expand-expand not implemented yet!"); |
| 3601 | case Legal: In = LegalizeOp(Node->getOperand(0)); break; |
| 3602 | case Promote: |
| 3603 | In = PromoteOp(Node->getOperand(0)); |
| 3604 | // Emit the appropriate sign_extend_inreg to get the value we want. |
| 3605 | In = DAG.getNode(ISD::SIGN_EXTEND_INREG, In.getValueType(), In, |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 3606 | DAG.getValueType(Node->getOperand(0).getValueType())); |
Chris Lattner | 06098e0 | 2005-04-03 23:41:52 +0000 | [diff] [blame] | 3607 | break; |
| 3608 | } |
| 3609 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3610 | // The low part is just a sign extension of the input (which degenerates to |
| 3611 | // a copy). |
Chris Lattner | 06098e0 | 2005-04-03 23:41:52 +0000 | [diff] [blame] | 3612 | Lo = DAG.getNode(ISD::SIGN_EXTEND, NVT, In); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 3613 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3614 | // The high part is obtained by SRA'ing all but one of the bits of the lo |
| 3615 | // part. |
Chris Lattner | 2dad454 | 2005-01-12 18:19:52 +0000 | [diff] [blame] | 3616 | unsigned LoSize = MVT::getSizeInBits(Lo.getValueType()); |
Chris Lattner | 27ff112 | 2005-01-22 00:31:52 +0000 | [diff] [blame] | 3617 | Hi = DAG.getNode(ISD::SRA, NVT, Lo, DAG.getConstant(LoSize-1, |
| 3618 | TLI.getShiftAmountTy())); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3619 | break; |
| 3620 | } |
Chris Lattner | 06098e0 | 2005-04-03 23:41:52 +0000 | [diff] [blame] | 3621 | case ISD::ZERO_EXTEND: { |
| 3622 | SDOperand In; |
| 3623 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3624 | case Expand: assert(0 && "expand-expand not implemented yet!"); |
| 3625 | case Legal: In = LegalizeOp(Node->getOperand(0)); break; |
| 3626 | case Promote: |
| 3627 | In = PromoteOp(Node->getOperand(0)); |
| 3628 | // Emit the appropriate zero_extend_inreg to get the value we want. |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 3629 | In = DAG.getZeroExtendInReg(In, Node->getOperand(0).getValueType()); |
Chris Lattner | 06098e0 | 2005-04-03 23:41:52 +0000 | [diff] [blame] | 3630 | break; |
| 3631 | } |
| 3632 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3633 | // The low part is just a zero extension of the input (which degenerates to |
| 3634 | // a copy). |
Chris Lattner | dea29e2 | 2005-04-10 01:13:15 +0000 | [diff] [blame] | 3635 | Lo = DAG.getNode(ISD::ZERO_EXTEND, NVT, In); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 3636 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3637 | // The high part is just a zero. |
| 3638 | Hi = DAG.getConstant(0, NVT); |
| 3639 | break; |
Chris Lattner | 06098e0 | 2005-04-03 23:41:52 +0000 | [diff] [blame] | 3640 | } |
Andrew Lenharth | f70e30b | 2005-11-20 21:32:07 +0000 | [diff] [blame] | 3641 | |
Chris Lattner | 308575b | 2005-11-20 22:56:56 +0000 | [diff] [blame] | 3642 | case ISD::READCYCLECOUNTER: { |
| 3643 | assert(TLI.getOperationAction(ISD::READCYCLECOUNTER, VT) == |
| 3644 | TargetLowering::Custom && |
| 3645 | "Must custom expand ReadCycleCounter"); |
| 3646 | SDOperand T = TLI.LowerOperation(Op, DAG); |
| 3647 | assert(T.Val && "Node must be custom expanded!"); |
| 3648 | Lo = LegalizeOp(T.getValue(0)); |
| 3649 | Hi = LegalizeOp(T.getValue(1)); |
| 3650 | AddLegalizedOperand(SDOperand(Node, 1), // Remember we legalized the chain. |
| 3651 | LegalizeOp(T.getValue(2))); |
Andrew Lenharth | f70e30b | 2005-11-20 21:32:07 +0000 | [diff] [blame] | 3652 | break; |
Chris Lattner | 308575b | 2005-11-20 22:56:56 +0000 | [diff] [blame] | 3653 | } |
Andrew Lenharth | f70e30b | 2005-11-20 21:32:07 +0000 | [diff] [blame] | 3654 | |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 3655 | // These operators cannot be expanded directly, emit them as calls to |
| 3656 | // library functions. |
| 3657 | case ISD::FP_TO_SINT: |
Chris Lattner | 80a3e94 | 2005-07-29 00:33:32 +0000 | [diff] [blame] | 3658 | if (TLI.getOperationAction(ISD::FP_TO_SINT, VT) == TargetLowering::Custom) { |
Chris Lattner | f20d183 | 2005-07-30 01:40:57 +0000 | [diff] [blame] | 3659 | SDOperand Op; |
| 3660 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 3661 | case Expand: assert(0 && "cannot expand FP!"); |
| 3662 | case Legal: Op = LegalizeOp(Node->getOperand(0)); break; |
| 3663 | case Promote: Op = PromoteOp(Node->getOperand(0)); break; |
| 3664 | } |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 3665 | |
Chris Lattner | f20d183 | 2005-07-30 01:40:57 +0000 | [diff] [blame] | 3666 | Op = TLI.LowerOperation(DAG.getNode(ISD::FP_TO_SINT, VT, Op), DAG); |
| 3667 | |
Chris Lattner | 80a3e94 | 2005-07-29 00:33:32 +0000 | [diff] [blame] | 3668 | // Now that the custom expander is done, expand the result, which is still |
| 3669 | // VT. |
Chris Lattner | 07dffd6 | 2005-08-26 00:14:16 +0000 | [diff] [blame] | 3670 | if (Op.Val) { |
| 3671 | ExpandOp(Op, Lo, Hi); |
| 3672 | break; |
| 3673 | } |
Chris Lattner | 80a3e94 | 2005-07-29 00:33:32 +0000 | [diff] [blame] | 3674 | } |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 3675 | |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 3676 | if (Node->getOperand(0).getValueType() == MVT::f32) |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 3677 | Lo = ExpandLibCall("__fixsfdi", Node, Hi); |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 3678 | else |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 3679 | Lo = ExpandLibCall("__fixdfdi", Node, Hi); |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 3680 | break; |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 3681 | |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 3682 | case ISD::FP_TO_UINT: |
Chris Lattner | 80a3e94 | 2005-07-29 00:33:32 +0000 | [diff] [blame] | 3683 | if (TLI.getOperationAction(ISD::FP_TO_UINT, VT) == TargetLowering::Custom) { |
| 3684 | SDOperand Op = DAG.getNode(ISD::FP_TO_UINT, VT, |
| 3685 | LegalizeOp(Node->getOperand(0))); |
| 3686 | // Now that the custom expander is done, expand the result, which is still |
| 3687 | // VT. |
Chris Lattner | 07dffd6 | 2005-08-26 00:14:16 +0000 | [diff] [blame] | 3688 | Op = TLI.LowerOperation(Op, DAG); |
| 3689 | if (Op.Val) { |
| 3690 | ExpandOp(Op, Lo, Hi); |
| 3691 | break; |
| 3692 | } |
Chris Lattner | 80a3e94 | 2005-07-29 00:33:32 +0000 | [diff] [blame] | 3693 | } |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 3694 | |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 3695 | if (Node->getOperand(0).getValueType() == MVT::f32) |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 3696 | Lo = ExpandLibCall("__fixunssfdi", Node, Hi); |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 3697 | else |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 3698 | Lo = ExpandLibCall("__fixunsdfdi", Node, Hi); |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 3699 | break; |
| 3700 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 3701 | case ISD::SHL: |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 3702 | // If the target wants custom lowering, do so. |
| 3703 | if (TLI.getOperationAction(ISD::SHL, VT) == TargetLowering::Custom) { |
| 3704 | SDOperand Op = DAG.getNode(ISD::SHL, VT, Node->getOperand(0), |
| 3705 | LegalizeOp(Node->getOperand(1))); |
| 3706 | Op = TLI.LowerOperation(Op, DAG); |
| 3707 | if (Op.Val) { |
| 3708 | // Now that the custom expander is done, expand the result, which is |
| 3709 | // still VT. |
| 3710 | ExpandOp(Op, Lo, Hi); |
| 3711 | break; |
| 3712 | } |
| 3713 | } |
| 3714 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 3715 | // If we can emit an efficient shift operation, do so now. |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 3716 | if (ExpandShift(ISD::SHL, Node->getOperand(0), Node->getOperand(1), Lo, Hi)) |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 3717 | break; |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 3718 | |
| 3719 | // If this target supports SHL_PARTS, use it. |
Chris Lattner | c9c60f6 | 2005-08-24 16:35:28 +0000 | [diff] [blame] | 3720 | if (TLI.isOperationLegal(ISD::SHL_PARTS, NVT)) { |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 3721 | ExpandShiftParts(ISD::SHL_PARTS, Node->getOperand(0), Node->getOperand(1), |
| 3722 | Lo, Hi); |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 3723 | break; |
| 3724 | } |
| 3725 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 3726 | // Otherwise, emit a libcall. |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 3727 | Lo = ExpandLibCall("__ashldi3", Node, Hi); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 3728 | break; |
| 3729 | |
| 3730 | case ISD::SRA: |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 3731 | // If the target wants custom lowering, do so. |
| 3732 | if (TLI.getOperationAction(ISD::SRA, VT) == TargetLowering::Custom) { |
| 3733 | SDOperand Op = DAG.getNode(ISD::SRA, VT, Node->getOperand(0), |
| 3734 | LegalizeOp(Node->getOperand(1))); |
| 3735 | Op = TLI.LowerOperation(Op, DAG); |
| 3736 | if (Op.Val) { |
| 3737 | // Now that the custom expander is done, expand the result, which is |
| 3738 | // still VT. |
| 3739 | ExpandOp(Op, Lo, Hi); |
| 3740 | break; |
| 3741 | } |
| 3742 | } |
| 3743 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 3744 | // If we can emit an efficient shift operation, do so now. |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 3745 | if (ExpandShift(ISD::SRA, Node->getOperand(0), Node->getOperand(1), Lo, Hi)) |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 3746 | break; |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 3747 | |
| 3748 | // If this target supports SRA_PARTS, use it. |
Chris Lattner | c9c60f6 | 2005-08-24 16:35:28 +0000 | [diff] [blame] | 3749 | if (TLI.isOperationLegal(ISD::SRA_PARTS, NVT)) { |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 3750 | ExpandShiftParts(ISD::SRA_PARTS, Node->getOperand(0), Node->getOperand(1), |
| 3751 | Lo, Hi); |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 3752 | break; |
| 3753 | } |
| 3754 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 3755 | // Otherwise, emit a libcall. |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 3756 | Lo = ExpandLibCall("__ashrdi3", Node, Hi); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 3757 | break; |
| 3758 | case ISD::SRL: |
Chris Lattner | 50ec897 | 2005-08-31 19:01:53 +0000 | [diff] [blame] | 3759 | // If the target wants custom lowering, do so. |
| 3760 | if (TLI.getOperationAction(ISD::SRL, VT) == TargetLowering::Custom) { |
| 3761 | SDOperand Op = DAG.getNode(ISD::SRL, VT, Node->getOperand(0), |
| 3762 | LegalizeOp(Node->getOperand(1))); |
| 3763 | Op = TLI.LowerOperation(Op, DAG); |
| 3764 | if (Op.Val) { |
| 3765 | // Now that the custom expander is done, expand the result, which is |
| 3766 | // still VT. |
| 3767 | ExpandOp(Op, Lo, Hi); |
| 3768 | break; |
| 3769 | } |
| 3770 | } |
| 3771 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 3772 | // If we can emit an efficient shift operation, do so now. |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 3773 | if (ExpandShift(ISD::SRL, Node->getOperand(0), Node->getOperand(1), Lo, Hi)) |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 3774 | break; |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 3775 | |
| 3776 | // If this target supports SRL_PARTS, use it. |
Chris Lattner | c9c60f6 | 2005-08-24 16:35:28 +0000 | [diff] [blame] | 3777 | if (TLI.isOperationLegal(ISD::SRL_PARTS, NVT)) { |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 3778 | ExpandShiftParts(ISD::SRL_PARTS, Node->getOperand(0), Node->getOperand(1), |
| 3779 | Lo, Hi); |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 3780 | break; |
| 3781 | } |
| 3782 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 3783 | // Otherwise, emit a libcall. |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 3784 | Lo = ExpandLibCall("__lshrdi3", Node, Hi); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 3785 | break; |
| 3786 | |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 3787 | case ISD::ADD: |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 3788 | ExpandByParts(ISD::ADD_PARTS, Node->getOperand(0), Node->getOperand(1), |
| 3789 | Lo, Hi); |
Chris Lattner | 84f6788 | 2005-01-20 18:52:28 +0000 | [diff] [blame] | 3790 | break; |
| 3791 | case ISD::SUB: |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 3792 | ExpandByParts(ISD::SUB_PARTS, Node->getOperand(0), Node->getOperand(1), |
| 3793 | Lo, Hi); |
Chris Lattner | 84f6788 | 2005-01-20 18:52:28 +0000 | [diff] [blame] | 3794 | break; |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 3795 | case ISD::MUL: { |
Chris Lattner | c9c60f6 | 2005-08-24 16:35:28 +0000 | [diff] [blame] | 3796 | if (TLI.isOperationLegal(ISD::MULHU, NVT)) { |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 3797 | SDOperand LL, LH, RL, RH; |
| 3798 | ExpandOp(Node->getOperand(0), LL, LH); |
| 3799 | ExpandOp(Node->getOperand(1), RL, RH); |
Nate Begeman | 56eb868 | 2005-08-30 02:44:00 +0000 | [diff] [blame] | 3800 | unsigned SH = MVT::getSizeInBits(RH.getValueType())-1; |
| 3801 | // MULHS implicitly sign extends its inputs. Check to see if ExpandOp |
| 3802 | // extended the sign bit of the low half through the upper half, and if so |
| 3803 | // emit a MULHS instead of the alternate sequence that is valid for any |
| 3804 | // i64 x i64 multiply. |
| 3805 | if (TLI.isOperationLegal(ISD::MULHS, NVT) && |
| 3806 | // is RH an extension of the sign bit of RL? |
| 3807 | RH.getOpcode() == ISD::SRA && RH.getOperand(0) == RL && |
| 3808 | RH.getOperand(1).getOpcode() == ISD::Constant && |
| 3809 | cast<ConstantSDNode>(RH.getOperand(1))->getValue() == SH && |
| 3810 | // is LH an extension of the sign bit of LL? |
| 3811 | LH.getOpcode() == ISD::SRA && LH.getOperand(0) == LL && |
| 3812 | LH.getOperand(1).getOpcode() == ISD::Constant && |
| 3813 | cast<ConstantSDNode>(LH.getOperand(1))->getValue() == SH) { |
| 3814 | Hi = DAG.getNode(ISD::MULHS, NVT, LL, RL); |
| 3815 | } else { |
| 3816 | Hi = DAG.getNode(ISD::MULHU, NVT, LL, RL); |
| 3817 | RH = DAG.getNode(ISD::MUL, NVT, LL, RH); |
| 3818 | LH = DAG.getNode(ISD::MUL, NVT, LH, RL); |
| 3819 | Hi = DAG.getNode(ISD::ADD, NVT, Hi, RH); |
| 3820 | Hi = DAG.getNode(ISD::ADD, NVT, Hi, LH); |
| 3821 | } |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 3822 | Lo = DAG.getNode(ISD::MUL, NVT, LL, RL); |
| 3823 | } else { |
| 3824 | Lo = ExpandLibCall("__muldi3" , Node, Hi); break; |
| 3825 | } |
| 3826 | break; |
| 3827 | } |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 3828 | case ISD::SDIV: Lo = ExpandLibCall("__divdi3" , Node, Hi); break; |
| 3829 | case ISD::UDIV: Lo = ExpandLibCall("__udivdi3", Node, Hi); break; |
| 3830 | case ISD::SREM: Lo = ExpandLibCall("__moddi3" , Node, Hi); break; |
| 3831 | case ISD::UREM: Lo = ExpandLibCall("__umoddi3", Node, Hi); break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3832 | } |
| 3833 | |
| 3834 | // Remember in a map if the values will be reused later. |
Chris Lattner | 6fdcb25 | 2005-09-02 20:32:45 +0000 | [diff] [blame] | 3835 | bool isNew = ExpandedNodes.insert(std::make_pair(Op, |
| 3836 | std::make_pair(Lo, Hi))).second; |
| 3837 | assert(isNew && "Value already expanded?!?"); |
Chris Lattner | 69a889e | 2005-12-20 00:53:54 +0000 | [diff] [blame] | 3838 | |
Chris Lattner | 8339736 | 2005-12-21 18:02:52 +0000 | [diff] [blame] | 3839 | // Make sure the resultant values have been legalized themselves, unless this |
| 3840 | // is a type that requires multi-step expansion. |
| 3841 | if (getTypeAction(NVT) != Expand && NVT != MVT::isVoid) { |
| 3842 | Lo = LegalizeOp(Lo); |
| 3843 | Hi = LegalizeOp(Hi); |
| 3844 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3845 | } |
| 3846 | |
| 3847 | |
| 3848 | // SelectionDAG::Legalize - This is the entry point for the file. |
| 3849 | // |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 3850 | void SelectionDAG::Legalize() { |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3851 | /// run - This is the main entry point to this class. |
| 3852 | /// |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 3853 | SelectionDAGLegalize(*this).Run(); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 3854 | } |
| 3855 | |