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" |
| 15 | #include "llvm/CodeGen/MachineConstantPool.h" |
| 16 | #include "llvm/CodeGen/MachineFunction.h" |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 17 | #include "llvm/CodeGen/MachineFrameInfo.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 | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 21 | #include "llvm/Constants.h" |
| 22 | #include <iostream> |
| 23 | using namespace llvm; |
| 24 | |
| 25 | //===----------------------------------------------------------------------===// |
| 26 | /// SelectionDAGLegalize - This takes an arbitrary SelectionDAG as input and |
| 27 | /// hacks on it until the target machine can handle it. This involves |
| 28 | /// eliminating value sizes the machine cannot handle (promoting small sizes to |
| 29 | /// large sizes or splitting up large values into small values) as well as |
| 30 | /// eliminating operations the machine cannot handle. |
| 31 | /// |
| 32 | /// This code also does a small amount of optimization and recognition of idioms |
| 33 | /// as part of its processing. For example, if a target does not support a |
| 34 | /// 'setcc' instruction efficiently, but does support 'brcc' instruction, this |
| 35 | /// will attempt merge setcc and brc instructions into brcc's. |
| 36 | /// |
| 37 | namespace { |
| 38 | class SelectionDAGLegalize { |
| 39 | TargetLowering &TLI; |
| 40 | SelectionDAG &DAG; |
| 41 | |
| 42 | /// LegalizeAction - This enum indicates what action we should take for each |
| 43 | /// value type the can occur in the program. |
| 44 | enum LegalizeAction { |
| 45 | Legal, // The target natively supports this value type. |
| 46 | Promote, // This should be promoted to the next larger type. |
| 47 | Expand, // This integer type should be broken into smaller pieces. |
| 48 | }; |
| 49 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 50 | /// ValueTypeActions - This is a bitvector that contains two bits for each |
| 51 | /// value type, where the two bits correspond to the LegalizeAction enum. |
| 52 | /// This can be queried with "getTypeAction(VT)". |
| 53 | unsigned ValueTypeActions; |
| 54 | |
| 55 | /// NeedsAnotherIteration - This is set when we expand a large integer |
| 56 | /// operation into smaller integer operations, but the smaller operations are |
| 57 | /// not set. This occurs only rarely in practice, for targets that don't have |
| 58 | /// 32-bit or larger integer registers. |
| 59 | bool NeedsAnotherIteration; |
| 60 | |
| 61 | /// LegalizedNodes - For nodes that are of legal width, and that have more |
| 62 | /// than one use, this map indicates what regularized operand to use. This |
| 63 | /// allows us to avoid legalizing the same thing more than once. |
| 64 | std::map<SDOperand, SDOperand> LegalizedNodes; |
| 65 | |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 66 | /// PromotedNodes - For nodes that are below legal width, and that have more |
| 67 | /// than one use, this map indicates what promoted value to use. This allows |
| 68 | /// us to avoid promoting the same thing more than once. |
| 69 | std::map<SDOperand, SDOperand> PromotedNodes; |
| 70 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 71 | /// ExpandedNodes - For nodes that need to be expanded, and which have more |
| 72 | /// than one use, this map indicates which which operands are the expanded |
| 73 | /// version of the input. This allows us to avoid expanding the same node |
| 74 | /// more than once. |
| 75 | std::map<SDOperand, std::pair<SDOperand, SDOperand> > ExpandedNodes; |
| 76 | |
Chris Lattner | 8afc48e | 2005-01-07 22:28:47 +0000 | [diff] [blame] | 77 | void AddLegalizedOperand(SDOperand From, SDOperand To) { |
| 78 | bool isNew = LegalizedNodes.insert(std::make_pair(From, To)).second; |
| 79 | assert(isNew && "Got into the map somehow?"); |
| 80 | } |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 81 | void AddPromotedOperand(SDOperand From, SDOperand To) { |
| 82 | bool isNew = PromotedNodes.insert(std::make_pair(From, To)).second; |
| 83 | assert(isNew && "Got into the map somehow?"); |
| 84 | } |
Chris Lattner | 8afc48e | 2005-01-07 22:28:47 +0000 | [diff] [blame] | 85 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 86 | public: |
| 87 | |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 88 | SelectionDAGLegalize(SelectionDAG &DAG); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 89 | |
| 90 | /// Run - While there is still lowering to do, perform a pass over the DAG. |
| 91 | /// Most regularization can be done in a single pass, but targets that require |
| 92 | /// large values to be split into registers multiple times (e.g. i64 -> 4x |
| 93 | /// i16) require iteration for these values (the first iteration will demote |
| 94 | /// to i32, the second will demote to i16). |
| 95 | void Run() { |
| 96 | do { |
| 97 | NeedsAnotherIteration = false; |
| 98 | LegalizeDAG(); |
| 99 | } while (NeedsAnotherIteration); |
| 100 | } |
| 101 | |
| 102 | /// getTypeAction - Return how we should legalize values of this type, either |
| 103 | /// it is already legal or we need to expand it into multiple registers of |
| 104 | /// smaller integer type, or we need to promote it to a larger type. |
| 105 | LegalizeAction getTypeAction(MVT::ValueType VT) const { |
| 106 | return (LegalizeAction)((ValueTypeActions >> (2*VT)) & 3); |
| 107 | } |
| 108 | |
| 109 | /// isTypeLegal - Return true if this type is legal on this target. |
| 110 | /// |
| 111 | bool isTypeLegal(MVT::ValueType VT) const { |
| 112 | return getTypeAction(VT) == Legal; |
| 113 | } |
| 114 | |
| 115 | private: |
| 116 | void LegalizeDAG(); |
| 117 | |
| 118 | SDOperand LegalizeOp(SDOperand O); |
| 119 | void ExpandOp(SDOperand O, SDOperand &Lo, SDOperand &Hi); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 120 | SDOperand PromoteOp(SDOperand O); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 121 | |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 122 | SDOperand ExpandLibCall(const char *Name, SDNode *Node, |
| 123 | SDOperand &Hi); |
| 124 | SDOperand ExpandIntToFP(bool isSigned, MVT::ValueType DestTy, |
| 125 | SDOperand Source); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 126 | bool ExpandShift(unsigned Opc, SDOperand Op, SDOperand Amt, |
| 127 | SDOperand &Lo, SDOperand &Hi); |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 128 | void ExpandShiftParts(unsigned NodeOp, SDOperand Op, SDOperand Amt, |
| 129 | SDOperand &Lo, SDOperand &Hi); |
| 130 | void ExpandByParts(unsigned NodeOp, SDOperand LHS, SDOperand RHS, |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 131 | SDOperand &Lo, SDOperand &Hi); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 132 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 133 | SDOperand getIntPtrConstant(uint64_t Val) { |
| 134 | return DAG.getConstant(Val, TLI.getPointerTy()); |
| 135 | } |
| 136 | }; |
| 137 | } |
| 138 | |
| 139 | |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 140 | SelectionDAGLegalize::SelectionDAGLegalize(SelectionDAG &dag) |
| 141 | : TLI(dag.getTargetLoweringInfo()), DAG(dag), |
| 142 | ValueTypeActions(TLI.getValueTypeActions()) { |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 143 | assert(MVT::LAST_VALUETYPE <= 16 && |
| 144 | "Too many value types for ValueTypeActions to hold!"); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 145 | } |
| 146 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 147 | void SelectionDAGLegalize::LegalizeDAG() { |
| 148 | SDOperand OldRoot = DAG.getRoot(); |
| 149 | SDOperand NewRoot = LegalizeOp(OldRoot); |
| 150 | DAG.setRoot(NewRoot); |
| 151 | |
| 152 | ExpandedNodes.clear(); |
| 153 | LegalizedNodes.clear(); |
Chris Lattner | 71c42a0 | 2005-01-16 01:11:45 +0000 | [diff] [blame] | 154 | PromotedNodes.clear(); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 155 | |
| 156 | // Remove dead nodes now. |
Chris Lattner | 62fd269 | 2005-01-07 21:09:37 +0000 | [diff] [blame] | 157 | DAG.RemoveDeadNodes(OldRoot.Val); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) { |
Chris Lattner | e3304a3 | 2005-01-08 20:35:13 +0000 | [diff] [blame] | 161 | assert(getTypeAction(Op.getValueType()) == Legal && |
| 162 | "Caller should expand or promote operands that are not legal!"); |
| 163 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 164 | // If this operation defines any values that cannot be represented in a |
Chris Lattner | e3304a3 | 2005-01-08 20:35:13 +0000 | [diff] [blame] | 165 | // register on this target, make sure to expand or promote them. |
| 166 | if (Op.Val->getNumValues() > 1) { |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 167 | for (unsigned i = 0, e = Op.Val->getNumValues(); i != e; ++i) |
| 168 | switch (getTypeAction(Op.Val->getValueType(i))) { |
| 169 | case Legal: break; // Nothing to do. |
| 170 | case Expand: { |
| 171 | SDOperand T1, T2; |
| 172 | ExpandOp(Op.getValue(i), T1, T2); |
| 173 | assert(LegalizedNodes.count(Op) && |
| 174 | "Expansion didn't add legal operands!"); |
| 175 | return LegalizedNodes[Op]; |
| 176 | } |
| 177 | case Promote: |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 178 | PromoteOp(Op.getValue(i)); |
| 179 | assert(LegalizedNodes.count(Op) && |
| 180 | "Expansion didn't add legal operands!"); |
| 181 | return LegalizedNodes[Op]; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 182 | } |
| 183 | } |
| 184 | |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 185 | std::map<SDOperand, SDOperand>::iterator I = LegalizedNodes.find(Op); |
| 186 | if (I != LegalizedNodes.end()) return I->second; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 187 | |
Chris Lattner | fa404e8 | 2005-01-09 19:03:49 +0000 | [diff] [blame] | 188 | SDOperand Tmp1, Tmp2, Tmp3; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 189 | |
| 190 | SDOperand Result = Op; |
| 191 | SDNode *Node = Op.Val; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 192 | |
| 193 | switch (Node->getOpcode()) { |
| 194 | default: |
| 195 | std::cerr << "NODE: "; Node->dump(); std::cerr << "\n"; |
| 196 | assert(0 && "Do not know how to legalize this operator!"); |
| 197 | abort(); |
| 198 | case ISD::EntryToken: |
| 199 | case ISD::FrameIndex: |
| 200 | case ISD::GlobalAddress: |
Chris Lattner | 03c0cf8 | 2005-01-07 21:45:56 +0000 | [diff] [blame] | 201 | case ISD::ExternalSymbol: |
Chris Lattner | 69a5215 | 2005-01-14 22:38:01 +0000 | [diff] [blame] | 202 | case ISD::ConstantPool: // Nothing to do. |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 203 | assert(getTypeAction(Node->getValueType(0)) == Legal && |
| 204 | "This must be legal!"); |
| 205 | break; |
Chris Lattner | 69a5215 | 2005-01-14 22:38:01 +0000 | [diff] [blame] | 206 | case ISD::CopyFromReg: |
| 207 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 208 | if (Tmp1 != Node->getOperand(0)) |
| 209 | Result = DAG.getCopyFromReg(cast<RegSDNode>(Node)->getReg(), |
| 210 | Node->getValueType(0), Tmp1); |
Chris Lattner | 13c184d | 2005-01-28 06:27:38 +0000 | [diff] [blame] | 211 | else |
| 212 | Result = Op.getValue(0); |
| 213 | |
| 214 | // Since CopyFromReg produces two values, make sure to remember that we |
| 215 | // legalized both of them. |
| 216 | AddLegalizedOperand(Op.getValue(0), Result); |
| 217 | AddLegalizedOperand(Op.getValue(1), Result.getValue(1)); |
| 218 | return Result.getValue(Op.ResNo); |
Chris Lattner | 18c2f13 | 2005-01-13 20:50:02 +0000 | [diff] [blame] | 219 | case ISD::ImplicitDef: |
| 220 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 221 | if (Tmp1 != Node->getOperand(0)) |
Chris Lattner | 2ee743f | 2005-01-14 22:08:15 +0000 | [diff] [blame] | 222 | Result = DAG.getImplicitDef(Tmp1, cast<RegSDNode>(Node)->getReg()); |
Chris Lattner | 18c2f13 | 2005-01-13 20:50:02 +0000 | [diff] [blame] | 223 | break; |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 224 | case ISD::UNDEF: { |
| 225 | MVT::ValueType VT = Op.getValueType(); |
| 226 | switch (TLI.getOperationAction(ISD::UNDEF, VT)) { |
Nate Begeman | ea19cd5 | 2005-04-02 00:41:14 +0000 | [diff] [blame] | 227 | default: assert(0 && "This action is not supported yet!"); |
| 228 | case TargetLowering::Expand: |
| 229 | case TargetLowering::Promote: |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 230 | if (MVT::isInteger(VT)) |
| 231 | Result = DAG.getConstant(0, VT); |
| 232 | else if (MVT::isFloatingPoint(VT)) |
| 233 | Result = DAG.getConstantFP(0, VT); |
| 234 | else |
| 235 | assert(0 && "Unknown value type!"); |
| 236 | break; |
Nate Begeman | ea19cd5 | 2005-04-02 00:41:14 +0000 | [diff] [blame] | 237 | case TargetLowering::Legal: |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 238 | break; |
| 239 | } |
| 240 | break; |
| 241 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 242 | case ISD::Constant: |
| 243 | // We know we don't need to expand constants here, constants only have one |
| 244 | // value and we check that it is fine above. |
| 245 | |
| 246 | // FIXME: Maybe we should handle things like targets that don't support full |
| 247 | // 32-bit immediates? |
| 248 | break; |
| 249 | case ISD::ConstantFP: { |
| 250 | // Spill FP immediates to the constant pool if the target cannot directly |
| 251 | // codegen them. Targets often have some immediate values that can be |
| 252 | // efficiently generated into an FP register without a load. We explicitly |
| 253 | // leave these constants as ConstantFP nodes for the target to deal with. |
| 254 | |
| 255 | ConstantFPSDNode *CFP = cast<ConstantFPSDNode>(Node); |
| 256 | |
| 257 | // Check to see if this FP immediate is already legal. |
| 258 | bool isLegal = false; |
| 259 | for (TargetLowering::legal_fpimm_iterator I = TLI.legal_fpimm_begin(), |
| 260 | E = TLI.legal_fpimm_end(); I != E; ++I) |
| 261 | if (CFP->isExactlyValue(*I)) { |
| 262 | isLegal = true; |
| 263 | break; |
| 264 | } |
| 265 | |
| 266 | if (!isLegal) { |
| 267 | // Otherwise we need to spill the constant to memory. |
| 268 | MachineConstantPool *CP = DAG.getMachineFunction().getConstantPool(); |
| 269 | |
| 270 | bool Extend = false; |
| 271 | |
| 272 | // If a FP immediate is precise when represented as a float, we put it |
| 273 | // into the constant pool as a float, even if it's is statically typed |
| 274 | // as a double. |
| 275 | MVT::ValueType VT = CFP->getValueType(0); |
| 276 | bool isDouble = VT == MVT::f64; |
| 277 | ConstantFP *LLVMC = ConstantFP::get(isDouble ? Type::DoubleTy : |
| 278 | Type::FloatTy, CFP->getValue()); |
Chris Lattner | 99939d3 | 2005-01-28 22:58:25 +0000 | [diff] [blame] | 279 | if (isDouble && CFP->isExactlyValue((float)CFP->getValue()) && |
| 280 | // Only do this if the target has a native EXTLOAD instruction from |
| 281 | // f32. |
| 282 | TLI.getOperationAction(ISD::EXTLOAD, |
| 283 | MVT::f32) == TargetLowering::Legal) { |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 284 | LLVMC = cast<ConstantFP>(ConstantExpr::getCast(LLVMC, Type::FloatTy)); |
| 285 | VT = MVT::f32; |
| 286 | Extend = true; |
| 287 | } |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 288 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 289 | SDOperand CPIdx = DAG.getConstantPool(CP->getConstantPoolIndex(LLVMC), |
| 290 | TLI.getPointerTy()); |
Chris Lattner | f8161d8 | 2005-01-16 05:06:12 +0000 | [diff] [blame] | 291 | if (Extend) { |
| 292 | Result = DAG.getNode(ISD::EXTLOAD, MVT::f64, DAG.getEntryNode(), CPIdx, |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 293 | DAG.getSrcValue(NULL), MVT::f32); |
Chris Lattner | f8161d8 | 2005-01-16 05:06:12 +0000 | [diff] [blame] | 294 | } else { |
Chris Lattner | 52d08bd | 2005-05-09 20:23:03 +0000 | [diff] [blame^] | 295 | Result = DAG.getLoad(VT, DAG.getEntryNode(), CPIdx, |
| 296 | DAG.getSrcValue(NULL)); |
Chris Lattner | f8161d8 | 2005-01-16 05:06:12 +0000 | [diff] [blame] | 297 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 298 | } |
| 299 | break; |
| 300 | } |
Chris Lattner | a385e9b | 2005-01-13 17:59:25 +0000 | [diff] [blame] | 301 | case ISD::TokenFactor: { |
| 302 | std::vector<SDOperand> Ops; |
| 303 | bool Changed = false; |
| 304 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) { |
Chris Lattner | 1e81b9e | 2005-01-19 19:10:54 +0000 | [diff] [blame] | 305 | SDOperand Op = Node->getOperand(i); |
| 306 | // Fold single-use TokenFactor nodes into this token factor as we go. |
| 307 | if (Op.getOpcode() == ISD::TokenFactor && Op.hasOneUse()) { |
| 308 | Changed = true; |
| 309 | for (unsigned j = 0, e = Op.getNumOperands(); j != e; ++j) |
| 310 | Ops.push_back(LegalizeOp(Op.getOperand(j))); |
| 311 | } else { |
| 312 | Ops.push_back(LegalizeOp(Op)); // Legalize the operands |
| 313 | Changed |= Ops[i] != Op; |
| 314 | } |
Chris Lattner | a385e9b | 2005-01-13 17:59:25 +0000 | [diff] [blame] | 315 | } |
| 316 | if (Changed) |
| 317 | Result = DAG.getNode(ISD::TokenFactor, MVT::Other, Ops); |
| 318 | break; |
| 319 | } |
| 320 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 321 | case ISD::ADJCALLSTACKDOWN: |
| 322 | case ISD::ADJCALLSTACKUP: |
| 323 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 324 | // There is no need to legalize the size argument (Operand #1) |
| 325 | if (Tmp1 != Node->getOperand(0)) |
| 326 | Result = DAG.getNode(Node->getOpcode(), MVT::Other, Tmp1, |
| 327 | Node->getOperand(1)); |
| 328 | break; |
Chris Lattner | fa404e8 | 2005-01-09 19:03:49 +0000 | [diff] [blame] | 329 | case ISD::DYNAMIC_STACKALLOC: |
| 330 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 331 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the size. |
| 332 | Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the alignment. |
| 333 | if (Tmp1 != Node->getOperand(0) || Tmp2 != Node->getOperand(1) || |
| 334 | Tmp3 != Node->getOperand(2)) |
| 335 | Result = DAG.getNode(ISD::DYNAMIC_STACKALLOC, Node->getValueType(0), |
| 336 | Tmp1, Tmp2, Tmp3); |
Chris Lattner | 513e52e | 2005-01-09 19:07:54 +0000 | [diff] [blame] | 337 | else |
| 338 | Result = Op.getValue(0); |
Chris Lattner | fa404e8 | 2005-01-09 19:03:49 +0000 | [diff] [blame] | 339 | |
| 340 | // Since this op produces two values, make sure to remember that we |
| 341 | // legalized both of them. |
| 342 | AddLegalizedOperand(SDOperand(Node, 0), Result); |
| 343 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
| 344 | return Result.getValue(Op.ResNo); |
| 345 | |
Chris Lattner | 3d9dffc | 2005-01-19 20:24:35 +0000 | [diff] [blame] | 346 | case ISD::CALL: { |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 347 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 348 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the callee. |
Chris Lattner | 3d9dffc | 2005-01-19 20:24:35 +0000 | [diff] [blame] | 349 | |
| 350 | bool Changed = false; |
| 351 | std::vector<SDOperand> Ops; |
| 352 | for (unsigned i = 2, e = Node->getNumOperands(); i != e; ++i) { |
| 353 | Ops.push_back(LegalizeOp(Node->getOperand(i))); |
| 354 | Changed |= Ops.back() != Node->getOperand(i); |
| 355 | } |
| 356 | |
| 357 | if (Tmp1 != Node->getOperand(0) || Tmp2 != Node->getOperand(1) || Changed) { |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 358 | std::vector<MVT::ValueType> RetTyVTs; |
| 359 | RetTyVTs.reserve(Node->getNumValues()); |
| 360 | for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) |
Chris Lattner | ebda942 | 2005-01-07 21:34:13 +0000 | [diff] [blame] | 361 | RetTyVTs.push_back(Node->getValueType(i)); |
Chris Lattner | 3d9dffc | 2005-01-19 20:24:35 +0000 | [diff] [blame] | 362 | Result = SDOperand(DAG.getCall(RetTyVTs, Tmp1, Tmp2, Ops), 0); |
Chris Lattner | 38d6be5 | 2005-01-09 19:43:23 +0000 | [diff] [blame] | 363 | } else { |
| 364 | Result = Result.getValue(0); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 365 | } |
Chris Lattner | 38d6be5 | 2005-01-09 19:43:23 +0000 | [diff] [blame] | 366 | // Since calls produce multiple values, make sure to remember that we |
| 367 | // legalized all of them. |
| 368 | for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) |
| 369 | AddLegalizedOperand(SDOperand(Node, i), Result.getValue(i)); |
| 370 | return Result.getValue(Op.ResNo); |
Chris Lattner | 3d9dffc | 2005-01-19 20:24:35 +0000 | [diff] [blame] | 371 | } |
Chris Lattner | c7af179 | 2005-01-07 22:12:08 +0000 | [diff] [blame] | 372 | case ISD::BR: |
| 373 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 374 | if (Tmp1 != Node->getOperand(0)) |
| 375 | Result = DAG.getNode(ISD::BR, MVT::Other, Tmp1, Node->getOperand(1)); |
| 376 | break; |
| 377 | |
Chris Lattner | c18ae4c | 2005-01-07 08:19:42 +0000 | [diff] [blame] | 378 | case ISD::BRCOND: |
| 379 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 380 | |
| 381 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 382 | case Expand: assert(0 && "It's impossible to expand bools"); |
| 383 | case Legal: |
| 384 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the condition. |
| 385 | break; |
| 386 | case Promote: |
| 387 | Tmp2 = PromoteOp(Node->getOperand(1)); // Promote the condition. |
| 388 | break; |
| 389 | } |
Chris Lattner | c18ae4c | 2005-01-07 08:19:42 +0000 | [diff] [blame] | 390 | // Basic block destination (Op#2) is always legal. |
| 391 | if (Tmp1 != Node->getOperand(0) || Tmp2 != Node->getOperand(1)) |
| 392 | Result = DAG.getNode(ISD::BRCOND, MVT::Other, Tmp1, Tmp2, |
| 393 | Node->getOperand(2)); |
| 394 | break; |
Chris Lattner | 411e888 | 2005-04-09 03:30:19 +0000 | [diff] [blame] | 395 | case ISD::BRCONDTWOWAY: |
| 396 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 397 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 398 | case Expand: assert(0 && "It's impossible to expand bools"); |
| 399 | case Legal: |
| 400 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the condition. |
| 401 | break; |
| 402 | case Promote: |
| 403 | Tmp2 = PromoteOp(Node->getOperand(1)); // Promote the condition. |
| 404 | break; |
| 405 | } |
| 406 | // If this target does not support BRCONDTWOWAY, lower it to a BRCOND/BR |
| 407 | // pair. |
| 408 | switch (TLI.getOperationAction(ISD::BRCONDTWOWAY, MVT::Other)) { |
| 409 | case TargetLowering::Promote: |
| 410 | default: assert(0 && "This action is not supported yet!"); |
| 411 | case TargetLowering::Legal: |
| 412 | if (Tmp1 != Node->getOperand(0) || Tmp2 != Node->getOperand(1)) { |
| 413 | std::vector<SDOperand> Ops; |
| 414 | Ops.push_back(Tmp1); |
| 415 | Ops.push_back(Tmp2); |
| 416 | Ops.push_back(Node->getOperand(2)); |
| 417 | Ops.push_back(Node->getOperand(3)); |
| 418 | Result = DAG.getNode(ISD::BRCONDTWOWAY, MVT::Other, Ops); |
| 419 | } |
| 420 | break; |
| 421 | case TargetLowering::Expand: |
| 422 | Result = DAG.getNode(ISD::BRCOND, MVT::Other, Tmp1, Tmp2, |
| 423 | Node->getOperand(2)); |
| 424 | Result = DAG.getNode(ISD::BR, MVT::Other, Result, Node->getOperand(3)); |
| 425 | break; |
| 426 | } |
| 427 | break; |
Chris Lattner | c18ae4c | 2005-01-07 08:19:42 +0000 | [diff] [blame] | 428 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 429 | case ISD::LOAD: |
| 430 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 431 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 432 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 433 | if (Tmp1 != Node->getOperand(0) || |
| 434 | Tmp2 != Node->getOperand(1)) |
Chris Lattner | 52d08bd | 2005-05-09 20:23:03 +0000 | [diff] [blame^] | 435 | Result = DAG.getLoad(Node->getValueType(0), Tmp1, Tmp2, |
| 436 | Node->getOperand(2)); |
Chris Lattner | 8afc48e | 2005-01-07 22:28:47 +0000 | [diff] [blame] | 437 | else |
| 438 | Result = SDOperand(Node, 0); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 439 | |
Chris Lattner | 8afc48e | 2005-01-07 22:28:47 +0000 | [diff] [blame] | 440 | // Since loads produce two values, make sure to remember that we legalized |
| 441 | // both of them. |
| 442 | AddLegalizedOperand(SDOperand(Node, 0), Result); |
| 443 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
| 444 | return Result.getValue(Op.ResNo); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 445 | |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 446 | case ISD::EXTLOAD: |
| 447 | case ISD::SEXTLOAD: |
Chris Lattner | 01ff721 | 2005-04-10 22:54:25 +0000 | [diff] [blame] | 448 | case ISD::ZEXTLOAD: { |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 449 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 450 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 451 | |
Chris Lattner | 01ff721 | 2005-04-10 22:54:25 +0000 | [diff] [blame] | 452 | MVT::ValueType SrcVT = cast<MVTSDNode>(Node)->getExtraValueType(); |
| 453 | switch (TLI.getOperationAction(Node->getOpcode(), SrcVT)) { |
Chris Lattner | 01ff721 | 2005-04-10 22:54:25 +0000 | [diff] [blame] | 454 | default: assert(0 && "This action is not supported yet!"); |
Chris Lattner | 1c51c6a | 2005-04-12 20:30:10 +0000 | [diff] [blame] | 455 | case TargetLowering::Promote: |
| 456 | assert(SrcVT == MVT::i1 && "Can only promote EXTLOAD from i1 -> i8!"); |
| 457 | Result = DAG.getNode(Node->getOpcode(), Node->getValueType(0), |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 458 | Tmp1, Tmp2, Node->getOperand(2), MVT::i8); |
Chris Lattner | 1c51c6a | 2005-04-12 20:30:10 +0000 | [diff] [blame] | 459 | // Since loads produce two values, make sure to remember that we legalized |
| 460 | // both of them. |
| 461 | AddLegalizedOperand(SDOperand(Node, 0), Result); |
| 462 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
| 463 | return Result.getValue(Op.ResNo); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 464 | |
Chris Lattner | 01ff721 | 2005-04-10 22:54:25 +0000 | [diff] [blame] | 465 | case TargetLowering::Legal: |
| 466 | if (Tmp1 != Node->getOperand(0) || |
| 467 | Tmp2 != Node->getOperand(1)) |
| 468 | Result = DAG.getNode(Node->getOpcode(), Node->getValueType(0), |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 469 | Tmp1, Tmp2, Node->getOperand(2), SrcVT); |
Chris Lattner | 01ff721 | 2005-04-10 22:54:25 +0000 | [diff] [blame] | 470 | else |
| 471 | Result = SDOperand(Node, 0); |
| 472 | |
| 473 | // Since loads produce two values, make sure to remember that we legalized |
| 474 | // both of them. |
| 475 | AddLegalizedOperand(SDOperand(Node, 0), Result); |
| 476 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
| 477 | return Result.getValue(Op.ResNo); |
Chris Lattner | 01ff721 | 2005-04-10 22:54:25 +0000 | [diff] [blame] | 478 | case TargetLowering::Expand: |
| 479 | assert(Node->getOpcode() != ISD::EXTLOAD && |
| 480 | "EXTLOAD should always be supported!"); |
| 481 | // Turn the unsupported load into an EXTLOAD followed by an explicit |
| 482 | // zero/sign extend inreg. |
| 483 | Result = DAG.getNode(ISD::EXTLOAD, Node->getValueType(0), |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 484 | Tmp1, Tmp2, Node->getOperand(2), SrcVT); |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 485 | SDOperand ValRes; |
| 486 | if (Node->getOpcode() == ISD::SEXTLOAD) |
| 487 | ValRes = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(), |
| 488 | Result, SrcVT); |
| 489 | else |
| 490 | ValRes = DAG.getZeroExtendInReg(Result, SrcVT); |
Chris Lattner | 01ff721 | 2005-04-10 22:54:25 +0000 | [diff] [blame] | 491 | AddLegalizedOperand(SDOperand(Node, 0), ValRes); |
| 492 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
| 493 | if (Op.ResNo) |
| 494 | return Result.getValue(1); |
| 495 | return ValRes; |
| 496 | } |
| 497 | assert(0 && "Unreachable"); |
| 498 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 499 | case ISD::EXTRACT_ELEMENT: |
| 500 | // Get both the low and high parts. |
| 501 | ExpandOp(Node->getOperand(0), Tmp1, Tmp2); |
| 502 | if (cast<ConstantSDNode>(Node->getOperand(1))->getValue()) |
| 503 | Result = Tmp2; // 1 -> Hi |
| 504 | else |
| 505 | Result = Tmp1; // 0 -> Lo |
| 506 | break; |
| 507 | |
| 508 | case ISD::CopyToReg: |
| 509 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 510 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 511 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 512 | case Legal: |
| 513 | // Legalize the incoming value (must be legal). |
| 514 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 515 | if (Tmp1 != Node->getOperand(0) || Tmp2 != Node->getOperand(1)) |
Chris Lattner | 18c2f13 | 2005-01-13 20:50:02 +0000 | [diff] [blame] | 516 | Result = DAG.getCopyToReg(Tmp1, Tmp2, cast<RegSDNode>(Node)->getReg()); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 517 | break; |
Chris Lattner | ef5cd1d | 2005-01-18 17:54:55 +0000 | [diff] [blame] | 518 | case Promote: |
| 519 | Tmp2 = PromoteOp(Node->getOperand(1)); |
| 520 | Result = DAG.getCopyToReg(Tmp1, Tmp2, cast<RegSDNode>(Node)->getReg()); |
| 521 | break; |
| 522 | case Expand: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 523 | SDOperand Lo, Hi; |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 524 | ExpandOp(Node->getOperand(1), Lo, Hi); |
Chris Lattner | 18c2f13 | 2005-01-13 20:50:02 +0000 | [diff] [blame] | 525 | unsigned Reg = cast<RegSDNode>(Node)->getReg(); |
Chris Lattner | ec39a45 | 2005-01-19 18:02:17 +0000 | [diff] [blame] | 526 | Lo = DAG.getCopyToReg(Tmp1, Lo, Reg); |
| 527 | Hi = DAG.getCopyToReg(Tmp1, Hi, Reg+1); |
| 528 | // Note that the copytoreg nodes are independent of each other. |
| 529 | Result = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo, Hi); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 530 | assert(isTypeLegal(Result.getValueType()) && |
| 531 | "Cannot expand multiple times yet (i64 -> i16)"); |
| 532 | break; |
| 533 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 534 | break; |
| 535 | |
| 536 | case ISD::RET: |
| 537 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 538 | switch (Node->getNumOperands()) { |
| 539 | case 2: // ret val |
| 540 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 541 | case Legal: |
| 542 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
Chris Lattner | 8afc48e | 2005-01-07 22:28:47 +0000 | [diff] [blame] | 543 | if (Tmp1 != Node->getOperand(0) || Tmp2 != Node->getOperand(1)) |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 544 | Result = DAG.getNode(ISD::RET, MVT::Other, Tmp1, Tmp2); |
| 545 | break; |
| 546 | case Expand: { |
| 547 | SDOperand Lo, Hi; |
| 548 | ExpandOp(Node->getOperand(1), Lo, Hi); |
| 549 | Result = DAG.getNode(ISD::RET, MVT::Other, Tmp1, Lo, Hi); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 550 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 551 | } |
| 552 | case Promote: |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 553 | Tmp2 = PromoteOp(Node->getOperand(1)); |
| 554 | Result = DAG.getNode(ISD::RET, MVT::Other, Tmp1, Tmp2); |
| 555 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 556 | } |
| 557 | break; |
| 558 | case 1: // ret void |
| 559 | if (Tmp1 != Node->getOperand(0)) |
| 560 | Result = DAG.getNode(ISD::RET, MVT::Other, Tmp1); |
| 561 | break; |
| 562 | default: { // ret <values> |
| 563 | std::vector<SDOperand> NewValues; |
| 564 | NewValues.push_back(Tmp1); |
| 565 | for (unsigned i = 1, e = Node->getNumOperands(); i != e; ++i) |
| 566 | switch (getTypeAction(Node->getOperand(i).getValueType())) { |
| 567 | case Legal: |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 568 | NewValues.push_back(LegalizeOp(Node->getOperand(i))); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 569 | break; |
| 570 | case Expand: { |
| 571 | SDOperand Lo, Hi; |
| 572 | ExpandOp(Node->getOperand(i), Lo, Hi); |
| 573 | NewValues.push_back(Lo); |
| 574 | NewValues.push_back(Hi); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 575 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 576 | } |
| 577 | case Promote: |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 578 | assert(0 && "Can't promote multiple return value yet!"); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 579 | } |
| 580 | Result = DAG.getNode(ISD::RET, MVT::Other, NewValues); |
| 581 | break; |
| 582 | } |
| 583 | } |
| 584 | break; |
| 585 | case ISD::STORE: |
| 586 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 587 | Tmp2 = LegalizeOp(Node->getOperand(2)); // Legalize the pointer. |
| 588 | |
Chris Lattner | 5d2c6c7 | 2005-01-08 06:25:56 +0000 | [diff] [blame] | 589 | // Turn 'store float 1.0, Ptr' -> 'store int 0x12345678, Ptr' |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 590 | if (ConstantFPSDNode *CFP =dyn_cast<ConstantFPSDNode>(Node->getOperand(1))){ |
Chris Lattner | 5d2c6c7 | 2005-01-08 06:25:56 +0000 | [diff] [blame] | 591 | if (CFP->getValueType(0) == MVT::f32) { |
| 592 | union { |
| 593 | unsigned I; |
| 594 | float F; |
| 595 | } V; |
| 596 | V.F = CFP->getValue(); |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 597 | Result = DAG.getNode(ISD::STORE, MVT::Other, Tmp1, |
Chris Lattner | 52d08bd | 2005-05-09 20:23:03 +0000 | [diff] [blame^] | 598 | DAG.getConstant(V.I, MVT::i32), Tmp2, |
| 599 | Node->getOperand(3)); |
Chris Lattner | 5d2c6c7 | 2005-01-08 06:25:56 +0000 | [diff] [blame] | 600 | } else { |
| 601 | assert(CFP->getValueType(0) == MVT::f64 && "Unknown FP type!"); |
| 602 | union { |
| 603 | uint64_t I; |
| 604 | double F; |
| 605 | } V; |
| 606 | V.F = CFP->getValue(); |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 607 | Result = DAG.getNode(ISD::STORE, MVT::Other, Tmp1, |
Chris Lattner | 52d08bd | 2005-05-09 20:23:03 +0000 | [diff] [blame^] | 608 | DAG.getConstant(V.I, MVT::i64), Tmp2, |
| 609 | Node->getOperand(3)); |
Chris Lattner | 5d2c6c7 | 2005-01-08 06:25:56 +0000 | [diff] [blame] | 610 | } |
Chris Lattner | 84734ce | 2005-02-22 07:23:39 +0000 | [diff] [blame] | 611 | Node = Result.Val; |
Chris Lattner | 5d2c6c7 | 2005-01-08 06:25:56 +0000 | [diff] [blame] | 612 | } |
| 613 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 614 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 615 | case Legal: { |
| 616 | SDOperand Val = LegalizeOp(Node->getOperand(1)); |
| 617 | if (Val != Node->getOperand(1) || Tmp1 != Node->getOperand(0) || |
| 618 | Tmp2 != Node->getOperand(2)) |
Chris Lattner | 52d08bd | 2005-05-09 20:23:03 +0000 | [diff] [blame^] | 619 | Result = DAG.getNode(ISD::STORE, MVT::Other, Tmp1, Val, Tmp2, |
| 620 | Node->getOperand(3)); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 621 | break; |
| 622 | } |
| 623 | case Promote: |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 624 | // Truncate the value and store the result. |
| 625 | Tmp3 = PromoteOp(Node->getOperand(1)); |
| 626 | Result = DAG.getNode(ISD::TRUNCSTORE, MVT::Other, Tmp1, Tmp3, Tmp2, |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 627 | Node->getOperand(3), |
| 628 | Node->getOperand(1).getValueType()); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 629 | break; |
| 630 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 631 | case Expand: |
| 632 | SDOperand Lo, Hi; |
| 633 | ExpandOp(Node->getOperand(1), Lo, Hi); |
| 634 | |
| 635 | if (!TLI.isLittleEndian()) |
| 636 | std::swap(Lo, Hi); |
| 637 | |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 638 | Lo = DAG.getNode(ISD::STORE, MVT::Other,Tmp1, Lo, Tmp2,Node->getOperand(3)); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 639 | |
Chris Lattner | ec39a45 | 2005-01-19 18:02:17 +0000 | [diff] [blame] | 640 | unsigned IncrementSize = MVT::getSizeInBits(Hi.getValueType())/8; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 641 | Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2, |
| 642 | getIntPtrConstant(IncrementSize)); |
| 643 | assert(isTypeLegal(Tmp2.getValueType()) && |
| 644 | "Pointers must be legal!"); |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 645 | //Again, claiming both parts of the store came form the same Instr |
| 646 | Hi = DAG.getNode(ISD::STORE, MVT::Other, Tmp1, Hi, Tmp2, Node->getOperand(3)); |
| 647 | |
Chris Lattner | ec39a45 | 2005-01-19 18:02:17 +0000 | [diff] [blame] | 648 | Result = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo, Hi); |
| 649 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 650 | } |
| 651 | break; |
Andrew Lenharth | 9576212 | 2005-03-31 21:24:06 +0000 | [diff] [blame] | 652 | case ISD::PCMARKER: |
| 653 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 654 | if (Tmp1 != Node->getOperand(0)) |
| 655 | Result = DAG.getNode(ISD::PCMARKER, MVT::Other, Tmp1,Node->getOperand(1)); |
Andrew Lenharth | 9576212 | 2005-03-31 21:24:06 +0000 | [diff] [blame] | 656 | break; |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 657 | case ISD::TRUNCSTORE: |
| 658 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 659 | Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the pointer. |
| 660 | |
| 661 | switch (getTypeAction(Node->getOperand(1).getValueType())) { |
| 662 | case Legal: |
| 663 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 664 | if (Tmp1 != Node->getOperand(0) || Tmp2 != Node->getOperand(1) || |
| 665 | Tmp3 != Node->getOperand(2)) |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 666 | Result = DAG.getNode(ISD::TRUNCSTORE, MVT::Other, Tmp1, Tmp2, Tmp3, |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 667 | Node->getOperand(3), |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 668 | cast<MVTSDNode>(Node)->getExtraValueType()); |
| 669 | break; |
| 670 | case Promote: |
| 671 | case Expand: |
| 672 | assert(0 && "Cannot handle illegal TRUNCSTORE yet!"); |
| 673 | } |
| 674 | break; |
Chris Lattner | 2ee743f | 2005-01-14 22:08:15 +0000 | [diff] [blame] | 675 | case ISD::SELECT: |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 676 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 677 | case Expand: assert(0 && "It's impossible to expand bools"); |
| 678 | case Legal: |
| 679 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the condition. |
| 680 | break; |
| 681 | case Promote: |
| 682 | Tmp1 = PromoteOp(Node->getOperand(0)); // Promote the condition. |
| 683 | break; |
| 684 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 685 | Tmp2 = LegalizeOp(Node->getOperand(1)); // TrueVal |
Chris Lattner | 2ee743f | 2005-01-14 22:08:15 +0000 | [diff] [blame] | 686 | Tmp3 = LegalizeOp(Node->getOperand(2)); // FalseVal |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 687 | |
| 688 | switch (TLI.getOperationAction(Node->getOpcode(), Tmp2.getValueType())) { |
| 689 | default: assert(0 && "This action is not supported yet!"); |
| 690 | case TargetLowering::Legal: |
| 691 | if (Tmp1 != Node->getOperand(0) || Tmp2 != Node->getOperand(1) || |
| 692 | Tmp3 != Node->getOperand(2)) |
| 693 | Result = DAG.getNode(ISD::SELECT, Node->getValueType(0), |
| 694 | Tmp1, Tmp2, Tmp3); |
| 695 | break; |
| 696 | case TargetLowering::Promote: { |
| 697 | MVT::ValueType NVT = |
| 698 | TLI.getTypeToPromoteTo(ISD::SELECT, Tmp2.getValueType()); |
| 699 | unsigned ExtOp, TruncOp; |
| 700 | if (MVT::isInteger(Tmp2.getValueType())) { |
| 701 | ExtOp = ISD::ZERO_EXTEND; |
| 702 | TruncOp = ISD::TRUNCATE; |
| 703 | } else { |
| 704 | ExtOp = ISD::FP_EXTEND; |
| 705 | TruncOp = ISD::FP_ROUND; |
| 706 | } |
| 707 | // Promote each of the values to the new type. |
| 708 | Tmp2 = DAG.getNode(ExtOp, NVT, Tmp2); |
| 709 | Tmp3 = DAG.getNode(ExtOp, NVT, Tmp3); |
| 710 | // Perform the larger operation, then round down. |
| 711 | Result = DAG.getNode(ISD::SELECT, NVT, Tmp1, Tmp2,Tmp3); |
| 712 | Result = DAG.getNode(TruncOp, Node->getValueType(0), Result); |
| 713 | break; |
| 714 | } |
| 715 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 716 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 717 | case ISD::SETCC: |
| 718 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 719 | case Legal: |
| 720 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
| 721 | Tmp2 = LegalizeOp(Node->getOperand(1)); // RHS |
| 722 | if (Tmp1 != Node->getOperand(0) || Tmp2 != Node->getOperand(1)) |
| 723 | Result = DAG.getSetCC(cast<SetCCSDNode>(Node)->getCondition(), |
Chris Lattner | f30b73b | 2005-01-18 02:52:03 +0000 | [diff] [blame] | 724 | Node->getValueType(0), Tmp1, Tmp2); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 725 | break; |
| 726 | case Promote: |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 727 | Tmp1 = PromoteOp(Node->getOperand(0)); // LHS |
| 728 | Tmp2 = PromoteOp(Node->getOperand(1)); // RHS |
| 729 | |
| 730 | // If this is an FP compare, the operands have already been extended. |
| 731 | if (MVT::isInteger(Node->getOperand(0).getValueType())) { |
| 732 | MVT::ValueType VT = Node->getOperand(0).getValueType(); |
Chris Lattner | 71c42a0 | 2005-01-16 01:11:45 +0000 | [diff] [blame] | 733 | MVT::ValueType NVT = TLI.getTypeToTransformTo(VT); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 734 | |
| 735 | // Otherwise, we have to insert explicit sign or zero extends. Note |
| 736 | // that we could insert sign extends for ALL conditions, but zero extend |
| 737 | // is cheaper on many machines (an AND instead of two shifts), so prefer |
| 738 | // it. |
| 739 | switch (cast<SetCCSDNode>(Node)->getCondition()) { |
| 740 | default: assert(0 && "Unknown integer comparison!"); |
| 741 | case ISD::SETEQ: |
| 742 | case ISD::SETNE: |
| 743 | case ISD::SETUGE: |
| 744 | case ISD::SETUGT: |
| 745 | case ISD::SETULE: |
| 746 | case ISD::SETULT: |
| 747 | // ALL of these operations will work if we either sign or zero extend |
| 748 | // the operands (including the unsigned comparisons!). Zero extend is |
| 749 | // usually a simpler/cheaper operation, so prefer it. |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 750 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, VT); |
| 751 | Tmp2 = DAG.getZeroExtendInReg(Tmp2, VT); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 752 | break; |
| 753 | case ISD::SETGE: |
| 754 | case ISD::SETGT: |
| 755 | case ISD::SETLT: |
| 756 | case ISD::SETLE: |
| 757 | Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp1, VT); |
| 758 | Tmp2 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp2, VT); |
| 759 | break; |
| 760 | } |
| 761 | |
| 762 | } |
| 763 | Result = DAG.getSetCC(cast<SetCCSDNode>(Node)->getCondition(), |
Chris Lattner | f30b73b | 2005-01-18 02:52:03 +0000 | [diff] [blame] | 764 | Node->getValueType(0), Tmp1, Tmp2); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 765 | break; |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 766 | case Expand: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 767 | SDOperand LHSLo, LHSHi, RHSLo, RHSHi; |
| 768 | ExpandOp(Node->getOperand(0), LHSLo, LHSHi); |
| 769 | ExpandOp(Node->getOperand(1), RHSLo, RHSHi); |
| 770 | switch (cast<SetCCSDNode>(Node)->getCondition()) { |
| 771 | case ISD::SETEQ: |
| 772 | case ISD::SETNE: |
Chris Lattner | 08b698e | 2005-04-12 01:46:05 +0000 | [diff] [blame] | 773 | if (RHSLo == RHSHi) |
| 774 | if (ConstantSDNode *RHSCST = dyn_cast<ConstantSDNode>(RHSLo)) |
| 775 | if (RHSCST->isAllOnesValue()) { |
| 776 | // Comparison to -1. |
| 777 | Tmp1 = DAG.getNode(ISD::AND, LHSLo.getValueType(), LHSLo, LHSHi); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 778 | Result = DAG.getSetCC(cast<SetCCSDNode>(Node)->getCondition(), |
Chris Lattner | 08b698e | 2005-04-12 01:46:05 +0000 | [diff] [blame] | 779 | Node->getValueType(0), Tmp1, RHSLo); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 780 | break; |
Chris Lattner | 08b698e | 2005-04-12 01:46:05 +0000 | [diff] [blame] | 781 | } |
| 782 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 783 | Tmp1 = DAG.getNode(ISD::XOR, LHSLo.getValueType(), LHSLo, RHSLo); |
| 784 | Tmp2 = DAG.getNode(ISD::XOR, LHSLo.getValueType(), LHSHi, RHSHi); |
| 785 | Tmp1 = DAG.getNode(ISD::OR, Tmp1.getValueType(), Tmp1, Tmp2); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 786 | Result = DAG.getSetCC(cast<SetCCSDNode>(Node)->getCondition(), |
Chris Lattner | f30b73b | 2005-01-18 02:52:03 +0000 | [diff] [blame] | 787 | Node->getValueType(0), Tmp1, |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 788 | DAG.getConstant(0, Tmp1.getValueType())); |
| 789 | break; |
| 790 | default: |
Chris Lattner | 5b95ed6 | 2005-04-12 02:19:10 +0000 | [diff] [blame] | 791 | // If this is a comparison of the sign bit, just look at the top part. |
| 792 | // X > -1, x < 0 |
| 793 | if (ConstantSDNode *CST = dyn_cast<ConstantSDNode>(Node->getOperand(1))) |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 794 | if ((cast<SetCCSDNode>(Node)->getCondition() == ISD::SETLT && |
Chris Lattner | 5b95ed6 | 2005-04-12 02:19:10 +0000 | [diff] [blame] | 795 | CST->getValue() == 0) || // X < 0 |
| 796 | (cast<SetCCSDNode>(Node)->getCondition() == ISD::SETGT && |
| 797 | (CST->isAllOnesValue()))) // X > -1 |
| 798 | return DAG.getSetCC(cast<SetCCSDNode>(Node)->getCondition(), |
| 799 | Node->getValueType(0), LHSHi, RHSHi); |
| 800 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 801 | // FIXME: This generated code sucks. |
| 802 | ISD::CondCode LowCC; |
| 803 | switch (cast<SetCCSDNode>(Node)->getCondition()) { |
| 804 | default: assert(0 && "Unknown integer setcc!"); |
| 805 | case ISD::SETLT: |
| 806 | case ISD::SETULT: LowCC = ISD::SETULT; break; |
| 807 | case ISD::SETGT: |
| 808 | case ISD::SETUGT: LowCC = ISD::SETUGT; break; |
| 809 | case ISD::SETLE: |
| 810 | case ISD::SETULE: LowCC = ISD::SETULE; break; |
| 811 | case ISD::SETGE: |
| 812 | case ISD::SETUGE: LowCC = ISD::SETUGE; break; |
| 813 | } |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 814 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 815 | // Tmp1 = lo(op1) < lo(op2) // Always unsigned comparison |
| 816 | // Tmp2 = hi(op1) < hi(op2) // Signedness depends on operands |
| 817 | // dest = hi(op1) == hi(op2) ? Tmp1 : Tmp2; |
| 818 | |
| 819 | // NOTE: on targets without efficient SELECT of bools, we can always use |
| 820 | // this identity: (B1 ? B2 : B3) --> (B1 & B2)|(!B1&B3) |
Chris Lattner | f30b73b | 2005-01-18 02:52:03 +0000 | [diff] [blame] | 821 | Tmp1 = DAG.getSetCC(LowCC, Node->getValueType(0), LHSLo, RHSLo); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 822 | Tmp2 = DAG.getSetCC(cast<SetCCSDNode>(Node)->getCondition(), |
Chris Lattner | f30b73b | 2005-01-18 02:52:03 +0000 | [diff] [blame] | 823 | Node->getValueType(0), LHSHi, RHSHi); |
| 824 | Result = DAG.getSetCC(ISD::SETEQ, Node->getValueType(0), LHSHi, RHSHi); |
| 825 | Result = DAG.getNode(ISD::SELECT, Tmp1.getValueType(), |
| 826 | Result, Tmp1, Tmp2); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 827 | break; |
| 828 | } |
| 829 | } |
| 830 | break; |
| 831 | |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 832 | case ISD::MEMSET: |
| 833 | case ISD::MEMCPY: |
| 834 | case ISD::MEMMOVE: { |
Chris Lattner | deb692e | 2005-02-01 18:38:28 +0000 | [diff] [blame] | 835 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Chain |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 836 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Pointer |
| 837 | |
| 838 | if (Node->getOpcode() == ISD::MEMSET) { // memset = ubyte |
| 839 | switch (getTypeAction(Node->getOperand(2).getValueType())) { |
| 840 | case Expand: assert(0 && "Cannot expand a byte!"); |
| 841 | case Legal: |
Chris Lattner | deb692e | 2005-02-01 18:38:28 +0000 | [diff] [blame] | 842 | Tmp3 = LegalizeOp(Node->getOperand(2)); |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 843 | break; |
| 844 | case Promote: |
Chris Lattner | deb692e | 2005-02-01 18:38:28 +0000 | [diff] [blame] | 845 | Tmp3 = PromoteOp(Node->getOperand(2)); |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 846 | break; |
| 847 | } |
| 848 | } else { |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 849 | Tmp3 = LegalizeOp(Node->getOperand(2)); // memcpy/move = pointer, |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 850 | } |
Chris Lattner | 272455b | 2005-02-02 03:44:41 +0000 | [diff] [blame] | 851 | |
| 852 | SDOperand Tmp4; |
| 853 | switch (getTypeAction(Node->getOperand(3).getValueType())) { |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 854 | case Expand: assert(0 && "Cannot expand this yet!"); |
| 855 | case Legal: |
| 856 | Tmp4 = LegalizeOp(Node->getOperand(3)); |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 857 | break; |
| 858 | case Promote: |
| 859 | Tmp4 = PromoteOp(Node->getOperand(3)); |
Chris Lattner | 272455b | 2005-02-02 03:44:41 +0000 | [diff] [blame] | 860 | break; |
| 861 | } |
| 862 | |
| 863 | SDOperand Tmp5; |
| 864 | switch (getTypeAction(Node->getOperand(4).getValueType())) { // uint |
| 865 | case Expand: assert(0 && "Cannot expand this yet!"); |
| 866 | case Legal: |
| 867 | Tmp5 = LegalizeOp(Node->getOperand(4)); |
| 868 | break; |
| 869 | case Promote: |
Chris Lattner | e560521 | 2005-01-28 22:29:18 +0000 | [diff] [blame] | 870 | Tmp5 = PromoteOp(Node->getOperand(4)); |
| 871 | break; |
| 872 | } |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 873 | |
| 874 | switch (TLI.getOperationAction(Node->getOpcode(), MVT::Other)) { |
| 875 | default: assert(0 && "This action not implemented for this operation!"); |
| 876 | case TargetLowering::Legal: |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 877 | if (Tmp1 != Node->getOperand(0) || Tmp2 != Node->getOperand(1) || |
| 878 | Tmp3 != Node->getOperand(2) || Tmp4 != Node->getOperand(3) || |
| 879 | Tmp5 != Node->getOperand(4)) { |
| 880 | std::vector<SDOperand> Ops; |
| 881 | Ops.push_back(Tmp1); Ops.push_back(Tmp2); Ops.push_back(Tmp3); |
| 882 | Ops.push_back(Tmp4); Ops.push_back(Tmp5); |
| 883 | Result = DAG.getNode(Node->getOpcode(), MVT::Other, Ops); |
| 884 | } |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 885 | break; |
| 886 | case TargetLowering::Expand: { |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 887 | // Otherwise, the target does not support this operation. Lower the |
| 888 | // operation to an explicit libcall as appropriate. |
| 889 | MVT::ValueType IntPtr = TLI.getPointerTy(); |
| 890 | const Type *IntPtrTy = TLI.getTargetData().getIntPtrType(); |
| 891 | std::vector<std::pair<SDOperand, const Type*> > Args; |
| 892 | |
Reid Spencer | 3bfbf4e | 2005-01-12 14:53:45 +0000 | [diff] [blame] | 893 | const char *FnName = 0; |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 894 | if (Node->getOpcode() == ISD::MEMSET) { |
| 895 | Args.push_back(std::make_pair(Tmp2, IntPtrTy)); |
| 896 | // Extend the ubyte argument to be an int value for the call. |
| 897 | Tmp3 = DAG.getNode(ISD::ZERO_EXTEND, MVT::i32, Tmp3); |
| 898 | Args.push_back(std::make_pair(Tmp3, Type::IntTy)); |
| 899 | Args.push_back(std::make_pair(Tmp4, IntPtrTy)); |
| 900 | |
| 901 | FnName = "memset"; |
| 902 | } else if (Node->getOpcode() == ISD::MEMCPY || |
| 903 | Node->getOpcode() == ISD::MEMMOVE) { |
| 904 | Args.push_back(std::make_pair(Tmp2, IntPtrTy)); |
| 905 | Args.push_back(std::make_pair(Tmp3, IntPtrTy)); |
| 906 | Args.push_back(std::make_pair(Tmp4, IntPtrTy)); |
| 907 | FnName = Node->getOpcode() == ISD::MEMMOVE ? "memmove" : "memcpy"; |
| 908 | } else { |
| 909 | assert(0 && "Unknown op!"); |
| 910 | } |
| 911 | std::pair<SDOperand,SDOperand> CallResult = |
Nate Begeman | 8e21e71 | 2005-03-26 01:29:23 +0000 | [diff] [blame] | 912 | TLI.LowerCallTo(Tmp1, Type::VoidTy, false, |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 913 | DAG.getExternalSymbol(FnName, IntPtr), Args, DAG); |
| 914 | Result = LegalizeOp(CallResult.second); |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 915 | break; |
| 916 | } |
| 917 | case TargetLowering::Custom: |
| 918 | std::vector<SDOperand> Ops; |
| 919 | Ops.push_back(Tmp1); Ops.push_back(Tmp2); Ops.push_back(Tmp3); |
| 920 | Ops.push_back(Tmp4); Ops.push_back(Tmp5); |
| 921 | Result = DAG.getNode(Node->getOpcode(), MVT::Other, Ops); |
| 922 | Result = TLI.LowerOperation(Result); |
| 923 | Result = LegalizeOp(Result); |
| 924 | break; |
Chris Lattner | e1bd822 | 2005-01-11 05:57:22 +0000 | [diff] [blame] | 925 | } |
| 926 | break; |
| 927 | } |
Chris Lattner | 52d08bd | 2005-05-09 20:23:03 +0000 | [diff] [blame^] | 928 | |
| 929 | case ISD::READPORT: |
| 930 | case ISD::READIO: |
| 931 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 932 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 933 | if (Tmp1 != Node->getOperand(0) || Tmp2 != Node->getOperand(1)) |
| 934 | Result = DAG.getNode(Node->getOpcode(), Node->getValueType(0),Tmp1, Tmp2); |
| 935 | else |
| 936 | Result = SDOperand(Node, 0); |
| 937 | // Since these produce two values, make sure to remember that we legalized |
| 938 | // both of them. |
| 939 | AddLegalizedOperand(SDOperand(Node, 0), Result); |
| 940 | AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); |
| 941 | return Result.getValue(Op.ResNo); |
| 942 | |
| 943 | case ISD::WRITEPORT: |
| 944 | case ISD::WRITEIO: |
| 945 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 946 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 947 | Tmp3 = LegalizeOp(Node->getOperand(2)); |
| 948 | if (Tmp1 != Node->getOperand(0) || Tmp2 != Node->getOperand(1) || |
| 949 | Tmp3 != Node->getOperand(2)) |
| 950 | Result = DAG.getNode(Node->getOpcode(), MVT::Other, Tmp1, Tmp2, Tmp3); |
| 951 | break; |
| 952 | |
Chris Lattner | 84f6788 | 2005-01-20 18:52:28 +0000 | [diff] [blame] | 953 | case ISD::ADD_PARTS: |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 954 | case ISD::SUB_PARTS: |
| 955 | case ISD::SHL_PARTS: |
| 956 | case ISD::SRA_PARTS: |
| 957 | case ISD::SRL_PARTS: { |
Chris Lattner | 84f6788 | 2005-01-20 18:52:28 +0000 | [diff] [blame] | 958 | std::vector<SDOperand> Ops; |
| 959 | bool Changed = false; |
| 960 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) { |
| 961 | Ops.push_back(LegalizeOp(Node->getOperand(i))); |
| 962 | Changed |= Ops.back() != Node->getOperand(i); |
| 963 | } |
| 964 | if (Changed) |
| 965 | Result = DAG.getNode(Node->getOpcode(), Node->getValueType(0), Ops); |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 966 | |
| 967 | // Since these produce multiple values, make sure to remember that we |
| 968 | // legalized all of them. |
| 969 | for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) |
| 970 | AddLegalizedOperand(SDOperand(Node, i), Result.getValue(i)); |
| 971 | return Result.getValue(Op.ResNo); |
Chris Lattner | 84f6788 | 2005-01-20 18:52:28 +0000 | [diff] [blame] | 972 | } |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 973 | |
| 974 | // Binary operators |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 975 | case ISD::ADD: |
| 976 | case ISD::SUB: |
| 977 | case ISD::MUL: |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 978 | case ISD::MULHS: |
| 979 | case ISD::MULHU: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 980 | case ISD::UDIV: |
| 981 | case ISD::SDIV: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 982 | case ISD::AND: |
| 983 | case ISD::OR: |
| 984 | case ISD::XOR: |
Chris Lattner | 03c0cf8 | 2005-01-07 21:45:56 +0000 | [diff] [blame] | 985 | case ISD::SHL: |
| 986 | case ISD::SRL: |
| 987 | case ISD::SRA: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 988 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
| 989 | Tmp2 = LegalizeOp(Node->getOperand(1)); // RHS |
| 990 | if (Tmp1 != Node->getOperand(0) || |
| 991 | Tmp2 != Node->getOperand(1)) |
| 992 | Result = DAG.getNode(Node->getOpcode(), Node->getValueType(0), Tmp1,Tmp2); |
| 993 | break; |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 994 | |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 995 | case ISD::UREM: |
| 996 | case ISD::SREM: |
| 997 | Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS |
| 998 | Tmp2 = LegalizeOp(Node->getOperand(1)); // RHS |
| 999 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 1000 | case TargetLowering::Legal: |
| 1001 | if (Tmp1 != Node->getOperand(0) || |
| 1002 | Tmp2 != Node->getOperand(1)) |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 1003 | Result = DAG.getNode(Node->getOpcode(), Node->getValueType(0), Tmp1, |
Nate Begeman | c105e19 | 2005-04-06 00:23:54 +0000 | [diff] [blame] | 1004 | Tmp2); |
| 1005 | break; |
| 1006 | case TargetLowering::Promote: |
| 1007 | case TargetLowering::Custom: |
| 1008 | assert(0 && "Cannot promote/custom handle this yet!"); |
| 1009 | case TargetLowering::Expand: { |
| 1010 | MVT::ValueType VT = Node->getValueType(0); |
| 1011 | unsigned Opc = (Node->getOpcode() == ISD::UREM) ? ISD::UDIV : ISD::SDIV; |
| 1012 | Result = DAG.getNode(Opc, VT, Tmp1, Tmp2); |
| 1013 | Result = DAG.getNode(ISD::MUL, VT, Result, Tmp2); |
| 1014 | Result = DAG.getNode(ISD::SUB, VT, Tmp1, Result); |
| 1015 | } |
| 1016 | break; |
| 1017 | } |
| 1018 | break; |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 1019 | |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 1020 | case ISD::CTPOP: |
| 1021 | case ISD::CTTZ: |
| 1022 | case ISD::CTLZ: |
| 1023 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Op |
| 1024 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 1025 | case TargetLowering::Legal: |
| 1026 | if (Tmp1 != Node->getOperand(0)) |
| 1027 | Result = DAG.getNode(Node->getOpcode(), Node->getValueType(0), Tmp1); |
| 1028 | break; |
| 1029 | case TargetLowering::Promote: { |
| 1030 | MVT::ValueType OVT = Tmp1.getValueType(); |
| 1031 | MVT::ValueType NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT); |
| 1032 | //Zero extend the argument |
| 1033 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Tmp1); |
| 1034 | // Perform the larger operation, then subtract if needed. |
| 1035 | Tmp1 = DAG.getNode(Node->getOpcode(), Node->getValueType(0), Tmp1); |
| 1036 | switch(Node->getOpcode()) |
| 1037 | { |
| 1038 | case ISD::CTPOP: |
| 1039 | Result = Tmp1; |
| 1040 | break; |
| 1041 | case ISD::CTTZ: |
| 1042 | //if Tmp1 == sizeinbits(NVT) then Tmp1 = sizeinbits(Old VT) |
| 1043 | Tmp2 = DAG.getSetCC(ISD::SETEQ, MVT::i1, Tmp1, |
| 1044 | DAG.getConstant(getSizeInBits(NVT), NVT)); |
| 1045 | Result = DAG.getNode(ISD::SELECT, NVT, Tmp2, |
| 1046 | DAG.getConstant(getSizeInBits(OVT),NVT), Tmp1); |
| 1047 | break; |
| 1048 | case ISD::CTLZ: |
| 1049 | //Tmp1 = Tmp1 - (sizeinbits(NVT) - sizeinbits(Old VT)) |
| 1050 | Result = DAG.getNode(ISD::SUB, NVT, Tmp1, |
| 1051 | DAG.getConstant(getSizeInBits(NVT) - |
| 1052 | getSizeInBits(OVT), NVT)); |
| 1053 | break; |
| 1054 | } |
| 1055 | break; |
| 1056 | } |
| 1057 | case TargetLowering::Custom: |
| 1058 | assert(0 && "Cannot custom handle this yet!"); |
| 1059 | case TargetLowering::Expand: |
Andrew Lenharth | ded10bf | 2005-05-05 15:55:21 +0000 | [diff] [blame] | 1060 | switch(Node->getOpcode()) |
| 1061 | { |
| 1062 | case ISD::CTPOP: { |
| 1063 | static const uint64_t mask[6][9] = { |
| 1064 | {0, 0x55, 0x5555, 0, 0x55555555, 0, 0, 0, 0x5555555555555555ULL}, |
| 1065 | {0, 0x33, 0x3333, 0, 0x33333333, 0, 0, 0, 0x3333333333333333ULL}, |
| 1066 | {0, 0x0F, 0x0F0F, 0, 0x0F0F0F0F, 0, 0, 0, 0x0F0F0F0F0F0F0F0FULL}, |
| 1067 | {0, 0, 0x00FF, 0, 0x00FF00FF, 0, 0, 0, 0x00FF00FF00FF00FFULL}, |
| 1068 | {0, 0, 0, 0, 0x0000FFFF, 0, 0, 0, 0x0000FFFF0000FFFFULL}, |
| 1069 | {0, 0, 0, 0, 0, 0, 0, 0, 0x00000000FFFFFFFFULL}}; |
| 1070 | MVT::ValueType VT = Tmp1.getValueType(); |
| 1071 | int len = getSizeInBits(VT); |
| 1072 | for (int i = 0; (1 << i) <= (len / 2); ++i) { |
| 1073 | //x = (x & mask[i][len/8]) + (x >> (1 << i) & mask[i][len/8]) |
| 1074 | Tmp2 = DAG.getConstant(mask[i][len/8], VT); |
| 1075 | Tmp3 = DAG.getConstant(1 << i, VT); |
| 1076 | Tmp1 = DAG.getNode(ISD::ADD, VT, |
| 1077 | DAG.getNode(ISD::AND, VT, Tmp1, Tmp2), |
| 1078 | DAG.getNode(ISD::AND, VT, |
| 1079 | DAG.getNode(ISD::SRL, VT, Tmp1, Tmp3), |
| 1080 | Tmp2)); |
| 1081 | } |
| 1082 | Result = Tmp1; |
| 1083 | break; |
| 1084 | } |
| 1085 | // case ISD::CTTZ: |
| 1086 | // break; |
| 1087 | // case ISD::CTLZ: |
| 1088 | // break; |
| 1089 | default: |
| 1090 | assert(0 && "Cannot expand this yet!"); |
| 1091 | break; |
| 1092 | } |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 1093 | break; |
| 1094 | } |
| 1095 | break; |
| 1096 | |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 1097 | // Unary operators |
| 1098 | case ISD::FABS: |
| 1099 | case ISD::FNEG: |
Chris Lattner | da6ba87 | 2005-04-28 21:44:33 +0000 | [diff] [blame] | 1100 | case ISD::FSQRT: |
| 1101 | case ISD::FSIN: |
| 1102 | case ISD::FCOS: |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 1103 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1104 | switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { |
| 1105 | case TargetLowering::Legal: |
| 1106 | if (Tmp1 != Node->getOperand(0)) |
| 1107 | Result = DAG.getNode(Node->getOpcode(), Node->getValueType(0), Tmp1); |
| 1108 | break; |
| 1109 | case TargetLowering::Promote: |
| 1110 | case TargetLowering::Custom: |
| 1111 | assert(0 && "Cannot promote/custom handle this yet!"); |
| 1112 | case TargetLowering::Expand: |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 1113 | switch(Node->getOpcode()) { |
| 1114 | case ISD::FNEG: { |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 1115 | // Expand Y = FNEG(X) -> Y = SUB -0.0, X |
| 1116 | Tmp2 = DAG.getConstantFP(-0.0, Node->getValueType(0)); |
| 1117 | Result = LegalizeOp(DAG.getNode(ISD::SUB, Node->getValueType(0), |
| 1118 | Tmp2, Tmp1)); |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 1119 | break; |
| 1120 | } |
| 1121 | case ISD::FABS: { |
Chris Lattner | 4af6e0d | 2005-04-02 05:26:37 +0000 | [diff] [blame] | 1122 | // Expand Y = FABS(X) -> Y = (X >u 0.0) ? X : fneg(X). |
| 1123 | MVT::ValueType VT = Node->getValueType(0); |
| 1124 | Tmp2 = DAG.getConstantFP(0.0, VT); |
| 1125 | Tmp2 = DAG.getSetCC(ISD::SETUGT, TLI.getSetCCResultTy(), Tmp1, Tmp2); |
| 1126 | Tmp3 = DAG.getNode(ISD::FNEG, VT, Tmp1); |
| 1127 | Result = DAG.getNode(ISD::SELECT, VT, Tmp2, Tmp1, Tmp3); |
| 1128 | Result = LegalizeOp(Result); |
Chris Lattner | f76e7dc | 2005-04-30 04:43:14 +0000 | [diff] [blame] | 1129 | break; |
| 1130 | } |
| 1131 | case ISD::FSQRT: |
| 1132 | case ISD::FSIN: |
| 1133 | case ISD::FCOS: { |
| 1134 | MVT::ValueType VT = Node->getValueType(0); |
| 1135 | Type *T = VT == MVT::f32 ? Type::FloatTy : Type::DoubleTy; |
| 1136 | const char *FnName = 0; |
| 1137 | switch(Node->getOpcode()) { |
| 1138 | case ISD::FSQRT: FnName = VT == MVT::f32 ? "sqrtf" : "sqrt"; break; |
| 1139 | case ISD::FSIN: FnName = VT == MVT::f32 ? "sinf" : "sin"; break; |
| 1140 | case ISD::FCOS: FnName = VT == MVT::f32 ? "cosf" : "cos"; break; |
| 1141 | default: assert(0 && "Unreachable!"); |
| 1142 | } |
| 1143 | std::vector<std::pair<SDOperand, const Type*> > Args; |
| 1144 | Args.push_back(std::make_pair(Tmp1, T)); |
| 1145 | std::pair<SDOperand,SDOperand> CallResult = |
| 1146 | TLI.LowerCallTo(DAG.getEntryNode(), T, false, |
| 1147 | DAG.getExternalSymbol(FnName, VT), Args, DAG); |
| 1148 | Result = LegalizeOp(CallResult.first); |
| 1149 | break; |
| 1150 | } |
| 1151 | default: |
Chris Lattner | 4af6e0d | 2005-04-02 05:26:37 +0000 | [diff] [blame] | 1152 | assert(0 && "Unreachable!"); |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 1153 | } |
| 1154 | break; |
| 1155 | } |
| 1156 | break; |
| 1157 | |
| 1158 | // Conversion operators. The source and destination have different types. |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1159 | case ISD::ZERO_EXTEND: |
| 1160 | case ISD::SIGN_EXTEND: |
Chris Lattner | 7cc4777 | 2005-01-07 21:56:57 +0000 | [diff] [blame] | 1161 | case ISD::TRUNCATE: |
Chris Lattner | 03c0cf8 | 2005-01-07 21:45:56 +0000 | [diff] [blame] | 1162 | case ISD::FP_EXTEND: |
| 1163 | case ISD::FP_ROUND: |
Chris Lattner | ae0aacb | 2005-01-08 08:08:56 +0000 | [diff] [blame] | 1164 | case ISD::FP_TO_SINT: |
| 1165 | case ISD::FP_TO_UINT: |
| 1166 | case ISD::SINT_TO_FP: |
| 1167 | case ISD::UINT_TO_FP: |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1168 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 1169 | case Legal: |
| 1170 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1171 | if (Tmp1 != Node->getOperand(0)) |
| 1172 | Result = DAG.getNode(Node->getOpcode(), Node->getValueType(0), Tmp1); |
| 1173 | break; |
Chris Lattner | b00a642 | 2005-01-07 22:37:48 +0000 | [diff] [blame] | 1174 | case Expand: |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 1175 | if (Node->getOpcode() == ISD::SINT_TO_FP || |
| 1176 | Node->getOpcode() == ISD::UINT_TO_FP) { |
| 1177 | Result = ExpandIntToFP(Node->getOpcode() == ISD::SINT_TO_FP, |
| 1178 | Node->getValueType(0), Node->getOperand(0)); |
| 1179 | Result = LegalizeOp(Result); |
| 1180 | break; |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 1181 | } else if (Node->getOpcode() == ISD::TRUNCATE) { |
| 1182 | // In the expand case, we must be dealing with a truncate, because |
| 1183 | // otherwise the result would be larger than the source. |
| 1184 | ExpandOp(Node->getOperand(0), Tmp1, Tmp2); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 1185 | |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 1186 | // Since the result is legal, we should just be able to truncate the low |
| 1187 | // part of the source. |
| 1188 | Result = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0), Tmp1); |
| 1189 | break; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 1190 | } |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 1191 | assert(0 && "Shouldn't need to expand other operators here!"); |
Chris Lattner | b00a642 | 2005-01-07 22:37:48 +0000 | [diff] [blame] | 1192 | |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 1193 | case Promote: |
| 1194 | switch (Node->getOpcode()) { |
Chris Lattner | 1713e73 | 2005-01-16 00:38:00 +0000 | [diff] [blame] | 1195 | case ISD::ZERO_EXTEND: |
| 1196 | Result = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 1197 | // NOTE: Any extend would work here... |
| 1198 | Result = DAG.getNode(ISD::ZERO_EXTEND, Op.getValueType(), Result); |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 1199 | Result = DAG.getZeroExtendInReg(Result, |
| 1200 | Node->getOperand(0).getValueType()); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 1201 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 1202 | case ISD::SIGN_EXTEND: |
Chris Lattner | 1713e73 | 2005-01-16 00:38:00 +0000 | [diff] [blame] | 1203 | Result = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 1204 | // NOTE: Any extend would work here... |
Chris Lattner | d5d5682 | 2005-01-18 21:57:59 +0000 | [diff] [blame] | 1205 | Result = DAG.getNode(ISD::ZERO_EXTEND, Op.getValueType(), Result); |
Chris Lattner | 1713e73 | 2005-01-16 00:38:00 +0000 | [diff] [blame] | 1206 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(), |
| 1207 | Result, Node->getOperand(0).getValueType()); |
| 1208 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 1209 | case ISD::TRUNCATE: |
Chris Lattner | 1713e73 | 2005-01-16 00:38:00 +0000 | [diff] [blame] | 1210 | Result = PromoteOp(Node->getOperand(0)); |
| 1211 | Result = DAG.getNode(ISD::TRUNCATE, Op.getValueType(), Result); |
| 1212 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 1213 | case ISD::FP_EXTEND: |
Chris Lattner | 1713e73 | 2005-01-16 00:38:00 +0000 | [diff] [blame] | 1214 | Result = PromoteOp(Node->getOperand(0)); |
| 1215 | if (Result.getValueType() != Op.getValueType()) |
| 1216 | // Dynamically dead while we have only 2 FP types. |
| 1217 | Result = DAG.getNode(ISD::FP_EXTEND, Op.getValueType(), Result); |
| 1218 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 1219 | case ISD::FP_ROUND: |
| 1220 | case ISD::FP_TO_SINT: |
| 1221 | case ISD::FP_TO_UINT: |
Chris Lattner | f8161d8 | 2005-01-16 05:06:12 +0000 | [diff] [blame] | 1222 | Result = PromoteOp(Node->getOperand(0)); |
| 1223 | Result = DAG.getNode(Node->getOpcode(), Op.getValueType(), Result); |
| 1224 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 1225 | case ISD::SINT_TO_FP: |
Chris Lattner | f8161d8 | 2005-01-16 05:06:12 +0000 | [diff] [blame] | 1226 | Result = PromoteOp(Node->getOperand(0)); |
| 1227 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(), |
| 1228 | Result, Node->getOperand(0).getValueType()); |
| 1229 | Result = DAG.getNode(ISD::SINT_TO_FP, Op.getValueType(), Result); |
| 1230 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 1231 | case ISD::UINT_TO_FP: |
Chris Lattner | f8161d8 | 2005-01-16 05:06:12 +0000 | [diff] [blame] | 1232 | Result = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 1233 | Result = DAG.getZeroExtendInReg(Result, |
| 1234 | Node->getOperand(0).getValueType()); |
Chris Lattner | f8161d8 | 2005-01-16 05:06:12 +0000 | [diff] [blame] | 1235 | Result = DAG.getNode(ISD::UINT_TO_FP, Op.getValueType(), Result); |
| 1236 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 1237 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1238 | } |
| 1239 | break; |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 1240 | case ISD::FP_ROUND_INREG: |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 1241 | case ISD::SIGN_EXTEND_INREG: { |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 1242 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 1243 | MVT::ValueType ExtraVT = cast<MVTSDNode>(Node)->getExtraValueType(); |
| 1244 | |
| 1245 | // If this operation is not supported, convert it to a shl/shr or load/store |
| 1246 | // pair. |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 1247 | switch (TLI.getOperationAction(Node->getOpcode(), ExtraVT)) { |
| 1248 | default: assert(0 && "This action not supported for this op yet!"); |
| 1249 | case TargetLowering::Legal: |
| 1250 | if (Tmp1 != Node->getOperand(0)) |
| 1251 | Result = DAG.getNode(Node->getOpcode(), Node->getValueType(0), Tmp1, |
| 1252 | ExtraVT); |
| 1253 | break; |
| 1254 | case TargetLowering::Expand: |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 1255 | // If this is an integer extend and shifts are supported, do that. |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 1256 | if (Node->getOpcode() == ISD::SIGN_EXTEND_INREG) { |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 1257 | // NOTE: we could fall back on load/store here too for targets without |
| 1258 | // SAR. However, it is doubtful that any exist. |
| 1259 | unsigned BitsDiff = MVT::getSizeInBits(Node->getValueType(0)) - |
| 1260 | MVT::getSizeInBits(ExtraVT); |
Chris Lattner | 27ff112 | 2005-01-22 00:31:52 +0000 | [diff] [blame] | 1261 | SDOperand ShiftCst = DAG.getConstant(BitsDiff, TLI.getShiftAmountTy()); |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 1262 | Result = DAG.getNode(ISD::SHL, Node->getValueType(0), |
| 1263 | Node->getOperand(0), ShiftCst); |
| 1264 | Result = DAG.getNode(ISD::SRA, Node->getValueType(0), |
| 1265 | Result, ShiftCst); |
| 1266 | } else if (Node->getOpcode() == ISD::FP_ROUND_INREG) { |
| 1267 | // The only way we can lower this is to turn it into a STORETRUNC, |
| 1268 | // EXTLOAD pair, targetting a temporary location (a stack slot). |
| 1269 | |
| 1270 | // NOTE: there is a choice here between constantly creating new stack |
| 1271 | // slots and always reusing the same one. We currently always create |
| 1272 | // new ones, as reuse may inhibit scheduling. |
| 1273 | const Type *Ty = MVT::getTypeForValueType(ExtraVT); |
| 1274 | unsigned TySize = (unsigned)TLI.getTargetData().getTypeSize(Ty); |
| 1275 | unsigned Align = TLI.getTargetData().getTypeAlignment(Ty); |
| 1276 | MachineFunction &MF = DAG.getMachineFunction(); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 1277 | int SSFI = |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 1278 | MF.getFrameInfo()->CreateStackObject((unsigned)TySize, Align); |
| 1279 | SDOperand StackSlot = DAG.getFrameIndex(SSFI, TLI.getPointerTy()); |
| 1280 | Result = DAG.getNode(ISD::TRUNCSTORE, MVT::Other, DAG.getEntryNode(), |
Chris Lattner | 52d08bd | 2005-05-09 20:23:03 +0000 | [diff] [blame^] | 1281 | Node->getOperand(0), StackSlot, |
| 1282 | DAG.getSrcValue(NULL), ExtraVT); |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 1283 | Result = DAG.getNode(ISD::EXTLOAD, Node->getValueType(0), |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 1284 | Result, StackSlot, DAG.getSrcValue(NULL), ExtraVT); |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 1285 | } else { |
| 1286 | assert(0 && "Unknown op"); |
| 1287 | } |
| 1288 | Result = LegalizeOp(Result); |
Chris Lattner | 55ba8fb | 2005-01-16 07:29:19 +0000 | [diff] [blame] | 1289 | break; |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 1290 | } |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 1291 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1292 | } |
Chris Lattner | 45b8caf | 2005-01-15 07:15:18 +0000 | [diff] [blame] | 1293 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1294 | |
Chris Lattner | 8afc48e | 2005-01-07 22:28:47 +0000 | [diff] [blame] | 1295 | if (!Op.Val->hasOneUse()) |
| 1296 | AddLegalizedOperand(Op, Result); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1297 | |
| 1298 | return Result; |
| 1299 | } |
| 1300 | |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 1301 | /// PromoteOp - Given an operation that produces a value in an invalid type, |
| 1302 | /// promote it to compute the value into a larger type. The produced value will |
| 1303 | /// have the correct bits for the low portion of the register, but no guarantee |
| 1304 | /// 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] | 1305 | SDOperand SelectionDAGLegalize::PromoteOp(SDOperand Op) { |
| 1306 | MVT::ValueType VT = Op.getValueType(); |
Chris Lattner | 71c42a0 | 2005-01-16 01:11:45 +0000 | [diff] [blame] | 1307 | MVT::ValueType NVT = TLI.getTypeToTransformTo(VT); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 1308 | assert(getTypeAction(VT) == Promote && |
| 1309 | "Caller should expand or legalize operands that are not promotable!"); |
| 1310 | assert(NVT > VT && MVT::isInteger(NVT) == MVT::isInteger(VT) && |
| 1311 | "Cannot promote to smaller type!"); |
| 1312 | |
| 1313 | std::map<SDOperand, SDOperand>::iterator I = PromotedNodes.find(Op); |
| 1314 | if (I != PromotedNodes.end()) return I->second; |
| 1315 | |
| 1316 | SDOperand Tmp1, Tmp2, Tmp3; |
| 1317 | |
| 1318 | SDOperand Result; |
| 1319 | SDNode *Node = Op.Val; |
| 1320 | |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 1321 | // Promotion needs an optimization step to clean up after it, and is not |
| 1322 | // careful to avoid operations the target does not support. Make sure that |
| 1323 | // all generated operations are legalized in the next iteration. |
| 1324 | NeedsAnotherIteration = true; |
| 1325 | |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 1326 | switch (Node->getOpcode()) { |
| 1327 | default: |
| 1328 | std::cerr << "NODE: "; Node->dump(); std::cerr << "\n"; |
| 1329 | assert(0 && "Do not know how to promote this operator!"); |
| 1330 | abort(); |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 1331 | case ISD::UNDEF: |
| 1332 | Result = DAG.getNode(ISD::UNDEF, NVT); |
| 1333 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 1334 | case ISD::Constant: |
| 1335 | Result = DAG.getNode(ISD::ZERO_EXTEND, NVT, Op); |
| 1336 | assert(isa<ConstantSDNode>(Result) && "Didn't constant fold zext?"); |
| 1337 | break; |
| 1338 | case ISD::ConstantFP: |
| 1339 | Result = DAG.getNode(ISD::FP_EXTEND, NVT, Op); |
| 1340 | assert(isa<ConstantFPSDNode>(Result) && "Didn't constant fold fp_extend?"); |
| 1341 | break; |
Chris Lattner | ef5cd1d | 2005-01-18 17:54:55 +0000 | [diff] [blame] | 1342 | case ISD::CopyFromReg: |
| 1343 | Result = DAG.getCopyFromReg(cast<RegSDNode>(Node)->getReg(), NVT, |
| 1344 | Node->getOperand(0)); |
| 1345 | // Remember that we legalized the chain. |
| 1346 | AddLegalizedOperand(Op.getValue(1), Result.getValue(1)); |
| 1347 | break; |
| 1348 | |
Chris Lattner | 82fbfb6 | 2005-01-18 02:59:52 +0000 | [diff] [blame] | 1349 | case ISD::SETCC: |
| 1350 | assert(getTypeAction(TLI.getSetCCResultTy()) == Legal && |
| 1351 | "SetCC type is not legal??"); |
| 1352 | Result = DAG.getSetCC(cast<SetCCSDNode>(Node)->getCondition(), |
| 1353 | TLI.getSetCCResultTy(), Node->getOperand(0), |
| 1354 | Node->getOperand(1)); |
| 1355 | Result = LegalizeOp(Result); |
| 1356 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 1357 | |
| 1358 | case ISD::TRUNCATE: |
| 1359 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 1360 | case Legal: |
| 1361 | Result = LegalizeOp(Node->getOperand(0)); |
| 1362 | assert(Result.getValueType() >= NVT && |
| 1363 | "This truncation doesn't make sense!"); |
| 1364 | if (Result.getValueType() > NVT) // Truncate to NVT instead of VT |
| 1365 | Result = DAG.getNode(ISD::TRUNCATE, NVT, Result); |
| 1366 | break; |
Chris Lattner | e76ad6d | 2005-01-28 22:52:50 +0000 | [diff] [blame] | 1367 | case Promote: |
| 1368 | // The truncation is not required, because we don't guarantee anything |
| 1369 | // about high bits anyway. |
| 1370 | Result = PromoteOp(Node->getOperand(0)); |
| 1371 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 1372 | case Expand: |
Nate Begeman | 79e46ac | 2005-04-04 00:57:08 +0000 | [diff] [blame] | 1373 | ExpandOp(Node->getOperand(0), Tmp1, Tmp2); |
| 1374 | // Truncate the low part of the expanded value to the result type |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 1375 | Result = DAG.getNode(ISD::TRUNCATE, VT, Tmp1); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 1376 | } |
| 1377 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 1378 | case ISD::SIGN_EXTEND: |
| 1379 | case ISD::ZERO_EXTEND: |
| 1380 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 1381 | case Expand: assert(0 && "BUG: Smaller reg should have been promoted!"); |
| 1382 | case Legal: |
| 1383 | // Input is legal? Just do extend all the way to the larger type. |
| 1384 | Result = LegalizeOp(Node->getOperand(0)); |
| 1385 | Result = DAG.getNode(Node->getOpcode(), NVT, Result); |
| 1386 | break; |
| 1387 | case Promote: |
| 1388 | // Promote the reg if it's smaller. |
| 1389 | Result = PromoteOp(Node->getOperand(0)); |
| 1390 | // The high bits are not guaranteed to be anything. Insert an extend. |
| 1391 | if (Node->getOpcode() == ISD::SIGN_EXTEND) |
Chris Lattner | 595dc54 | 2005-02-04 18:39:19 +0000 | [diff] [blame] | 1392 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Result, |
| 1393 | Node->getOperand(0).getValueType()); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 1394 | else |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 1395 | Result = DAG.getZeroExtendInReg(Result, |
| 1396 | Node->getOperand(0).getValueType()); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 1397 | break; |
| 1398 | } |
| 1399 | break; |
| 1400 | |
| 1401 | case ISD::FP_EXTEND: |
| 1402 | assert(0 && "Case not implemented. Dynamically dead with 2 FP types!"); |
| 1403 | case ISD::FP_ROUND: |
| 1404 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 1405 | case Expand: assert(0 && "BUG: Cannot expand FP regs!"); |
| 1406 | case Promote: assert(0 && "Unreachable with 2 FP types!"); |
| 1407 | case Legal: |
| 1408 | // Input is legal? Do an FP_ROUND_INREG. |
| 1409 | Result = LegalizeOp(Node->getOperand(0)); |
| 1410 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, VT); |
| 1411 | break; |
| 1412 | } |
| 1413 | break; |
| 1414 | |
| 1415 | case ISD::SINT_TO_FP: |
| 1416 | case ISD::UINT_TO_FP: |
| 1417 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 1418 | case Legal: |
| 1419 | Result = LegalizeOp(Node->getOperand(0)); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 1420 | // No extra round required here. |
| 1421 | Result = DAG.getNode(Node->getOpcode(), NVT, Result); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 1422 | break; |
| 1423 | |
| 1424 | case Promote: |
| 1425 | Result = PromoteOp(Node->getOperand(0)); |
| 1426 | if (Node->getOpcode() == ISD::SINT_TO_FP) |
| 1427 | Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(), |
| 1428 | Result, Node->getOperand(0).getValueType()); |
| 1429 | else |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 1430 | Result = DAG.getZeroExtendInReg(Result, |
| 1431 | Node->getOperand(0).getValueType()); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 1432 | // No extra round required here. |
| 1433 | Result = DAG.getNode(Node->getOpcode(), NVT, Result); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 1434 | break; |
| 1435 | case Expand: |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 1436 | Result = ExpandIntToFP(Node->getOpcode() == ISD::SINT_TO_FP, NVT, |
| 1437 | Node->getOperand(0)); |
| 1438 | Result = LegalizeOp(Result); |
| 1439 | |
| 1440 | // Round if we cannot tolerate excess precision. |
| 1441 | if (NoExcessFPPrecision) |
| 1442 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, VT); |
| 1443 | break; |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 1444 | } |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 1445 | break; |
| 1446 | |
| 1447 | case ISD::FP_TO_SINT: |
| 1448 | case ISD::FP_TO_UINT: |
| 1449 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 1450 | case Legal: |
| 1451 | Tmp1 = LegalizeOp(Node->getOperand(0)); |
| 1452 | break; |
| 1453 | case Promote: |
| 1454 | // The input result is prerounded, so we don't have to do anything |
| 1455 | // special. |
| 1456 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 1457 | break; |
| 1458 | case Expand: |
| 1459 | assert(0 && "not implemented"); |
| 1460 | } |
| 1461 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1); |
| 1462 | break; |
| 1463 | |
Chris Lattner | 2c8086f | 2005-04-02 05:00:07 +0000 | [diff] [blame] | 1464 | case ISD::FABS: |
| 1465 | case ISD::FNEG: |
| 1466 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 1467 | assert(Tmp1.getValueType() == NVT); |
| 1468 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1); |
| 1469 | // NOTE: we do not have to do any extra rounding here for |
| 1470 | // NoExcessFPPrecision, because we know the input will have the appropriate |
| 1471 | // precision, and these operations don't modify precision at all. |
| 1472 | break; |
| 1473 | |
Chris Lattner | da6ba87 | 2005-04-28 21:44:33 +0000 | [diff] [blame] | 1474 | case ISD::FSQRT: |
| 1475 | case ISD::FSIN: |
| 1476 | case ISD::FCOS: |
| 1477 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 1478 | assert(Tmp1.getValueType() == NVT); |
| 1479 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1); |
| 1480 | if(NoExcessFPPrecision) |
| 1481 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, VT); |
| 1482 | break; |
| 1483 | |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 1484 | case ISD::AND: |
| 1485 | case ISD::OR: |
| 1486 | case ISD::XOR: |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 1487 | case ISD::ADD: |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 1488 | case ISD::SUB: |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 1489 | case ISD::MUL: |
| 1490 | // The input may have strange things in the top bits of the registers, but |
| 1491 | // these operations don't care. They may have wierd bits going out, but |
| 1492 | // that too is okay if they are integer operations. |
| 1493 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 1494 | Tmp2 = PromoteOp(Node->getOperand(1)); |
| 1495 | assert(Tmp1.getValueType() == NVT && Tmp2.getValueType() == NVT); |
| 1496 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 1497 | |
| 1498 | // However, if this is a floating point operation, they will give excess |
| 1499 | // precision that we may not be able to tolerate. If we DO allow excess |
| 1500 | // precision, just leave it, otherwise excise it. |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 1501 | // FIXME: Why would we need to round FP ops more than integer ones? |
| 1502 | // Is Round(Add(Add(A,B),C)) != Round(Add(Round(Add(A,B)), C)) |
Chris Lattner | 0f69b29 | 2005-01-15 06:18:18 +0000 | [diff] [blame] | 1503 | if (MVT::isFloatingPoint(NVT) && NoExcessFPPrecision) |
| 1504 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, VT); |
| 1505 | break; |
| 1506 | |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 1507 | case ISD::SDIV: |
| 1508 | case ISD::SREM: |
| 1509 | // These operators require that their input be sign extended. |
| 1510 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 1511 | Tmp2 = PromoteOp(Node->getOperand(1)); |
| 1512 | if (MVT::isInteger(NVT)) { |
| 1513 | Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp1, VT); |
Chris Lattner | ff3e50c | 2005-01-16 00:17:42 +0000 | [diff] [blame] | 1514 | Tmp2 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp2, VT); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 1515 | } |
| 1516 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 1517 | |
| 1518 | // Perform FP_ROUND: this is probably overly pessimistic. |
| 1519 | if (MVT::isFloatingPoint(NVT) && NoExcessFPPrecision) |
| 1520 | Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, VT); |
| 1521 | break; |
| 1522 | |
| 1523 | case ISD::UDIV: |
| 1524 | case ISD::UREM: |
| 1525 | // These operators require that their input be zero extended. |
| 1526 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 1527 | Tmp2 = PromoteOp(Node->getOperand(1)); |
| 1528 | assert(MVT::isInteger(NVT) && "Operators don't apply to FP!"); |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 1529 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, VT); |
| 1530 | Tmp2 = DAG.getZeroExtendInReg(Tmp2, VT); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 1531 | Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); |
| 1532 | break; |
| 1533 | |
| 1534 | case ISD::SHL: |
| 1535 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 1536 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1537 | Result = DAG.getNode(ISD::SHL, NVT, Tmp1, Tmp2); |
| 1538 | break; |
| 1539 | case ISD::SRA: |
| 1540 | // The input value must be properly sign extended. |
| 1541 | Tmp1 = PromoteOp(Node->getOperand(0)); |
| 1542 | Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp1, VT); |
| 1543 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1544 | Result = DAG.getNode(ISD::SRA, NVT, Tmp1, Tmp2); |
| 1545 | break; |
| 1546 | case ISD::SRL: |
| 1547 | // The input value must be properly zero extended. |
| 1548 | Tmp1 = PromoteOp(Node->getOperand(0)); |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 1549 | Tmp1 = DAG.getZeroExtendInReg(Tmp1, VT); |
Chris Lattner | 8b6fa22 | 2005-01-15 22:16:26 +0000 | [diff] [blame] | 1550 | Tmp2 = LegalizeOp(Node->getOperand(1)); |
| 1551 | Result = DAG.getNode(ISD::SRL, NVT, Tmp1, Tmp2); |
| 1552 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 1553 | case ISD::LOAD: |
| 1554 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1555 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. |
Chris Lattner | 232ee95 | 2005-04-10 04:33:47 +0000 | [diff] [blame] | 1556 | // FIXME: When the DAG combiner exists, change this to use EXTLOAD! |
Chris Lattner | 6841dec | 2005-04-10 17:40:35 +0000 | [diff] [blame] | 1557 | if (MVT::isInteger(NVT)) |
Chris Lattner | 52d08bd | 2005-05-09 20:23:03 +0000 | [diff] [blame^] | 1558 | Result = DAG.getNode(ISD::ZEXTLOAD, NVT, Tmp1, Tmp2, Node->getOperand(2), |
| 1559 | VT); |
Chris Lattner | 6841dec | 2005-04-10 17:40:35 +0000 | [diff] [blame] | 1560 | else |
Chris Lattner | 52d08bd | 2005-05-09 20:23:03 +0000 | [diff] [blame^] | 1561 | Result = DAG.getNode(ISD::EXTLOAD, NVT, Tmp1, Tmp2, Node->getOperand(2), |
| 1562 | VT); |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 1563 | |
| 1564 | // Remember that we legalized the chain. |
| 1565 | AddLegalizedOperand(Op.getValue(1), Result.getValue(1)); |
| 1566 | break; |
| 1567 | case ISD::SELECT: |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 1568 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 1569 | case Expand: assert(0 && "It's impossible to expand bools"); |
| 1570 | case Legal: |
| 1571 | Tmp1 = LegalizeOp(Node->getOperand(0));// Legalize the condition. |
| 1572 | break; |
| 1573 | case Promote: |
| 1574 | Tmp1 = PromoteOp(Node->getOperand(0)); // Promote the condition. |
| 1575 | break; |
| 1576 | } |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 1577 | Tmp2 = PromoteOp(Node->getOperand(1)); // Legalize the op0 |
| 1578 | Tmp3 = PromoteOp(Node->getOperand(2)); // Legalize the op1 |
| 1579 | Result = DAG.getNode(ISD::SELECT, NVT, Tmp1, Tmp2, Tmp3); |
| 1580 | break; |
Chris Lattner | 8ac532c | 2005-01-16 19:46:48 +0000 | [diff] [blame] | 1581 | case ISD::CALL: { |
| 1582 | Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 1583 | Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the callee. |
| 1584 | |
Chris Lattner | 3d9dffc | 2005-01-19 20:24:35 +0000 | [diff] [blame] | 1585 | std::vector<SDOperand> Ops; |
| 1586 | for (unsigned i = 2, e = Node->getNumOperands(); i != e; ++i) |
| 1587 | Ops.push_back(LegalizeOp(Node->getOperand(i))); |
| 1588 | |
Chris Lattner | 8ac532c | 2005-01-16 19:46:48 +0000 | [diff] [blame] | 1589 | assert(Node->getNumValues() == 2 && Op.ResNo == 0 && |
| 1590 | "Can only promote single result calls"); |
| 1591 | std::vector<MVT::ValueType> RetTyVTs; |
| 1592 | RetTyVTs.reserve(2); |
| 1593 | RetTyVTs.push_back(NVT); |
| 1594 | RetTyVTs.push_back(MVT::Other); |
Chris Lattner | 3d9dffc | 2005-01-19 20:24:35 +0000 | [diff] [blame] | 1595 | SDNode *NC = DAG.getCall(RetTyVTs, Tmp1, Tmp2, Ops); |
Chris Lattner | 8ac532c | 2005-01-16 19:46:48 +0000 | [diff] [blame] | 1596 | Result = SDOperand(NC, 0); |
| 1597 | |
| 1598 | // Insert the new chain mapping. |
| 1599 | AddLegalizedOperand(Op.getValue(1), Result.getValue(1)); |
| 1600 | break; |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 1601 | } |
Andrew Lenharth | fecf095 | 2005-05-04 19:11:05 +0000 | [diff] [blame] | 1602 | case ISD::CTPOP: |
| 1603 | case ISD::CTTZ: |
| 1604 | case ISD::CTLZ: |
| 1605 | Tmp1 = Node->getOperand(0); |
| 1606 | //Zero extend the argument |
| 1607 | Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Tmp1); |
| 1608 | // Perform the larger operation, then subtract if needed. |
| 1609 | Tmp1 = DAG.getNode(Node->getOpcode(), NVT, Tmp1); |
| 1610 | switch(Node->getOpcode()) |
| 1611 | { |
| 1612 | case ISD::CTPOP: |
| 1613 | Result = Tmp1; |
| 1614 | break; |
| 1615 | case ISD::CTTZ: |
| 1616 | //if Tmp1 == sizeinbits(NVT) then Tmp1 = sizeinbits(Old VT) |
| 1617 | Tmp2 = DAG.getSetCC(ISD::SETEQ, MVT::i1, Tmp1, |
| 1618 | DAG.getConstant(getSizeInBits(NVT), NVT)); |
| 1619 | Result = DAG.getNode(ISD::SELECT, NVT, Tmp2, |
| 1620 | DAG.getConstant(getSizeInBits(VT),NVT), Tmp1); |
| 1621 | break; |
| 1622 | case ISD::CTLZ: |
| 1623 | //Tmp1 = Tmp1 - (sizeinbits(NVT) - sizeinbits(Old VT)) |
| 1624 | Result = DAG.getNode(ISD::SUB, NVT, Tmp1, |
| 1625 | DAG.getConstant(getSizeInBits(NVT) - |
| 1626 | getSizeInBits(VT), NVT)); |
| 1627 | break; |
| 1628 | } |
| 1629 | break; |
Chris Lattner | 03c8546 | 2005-01-15 05:21:40 +0000 | [diff] [blame] | 1630 | } |
| 1631 | |
| 1632 | assert(Result.Val && "Didn't set a result!"); |
| 1633 | AddPromotedOperand(Op, Result); |
| 1634 | return Result; |
| 1635 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 1636 | |
Chris Lattner | 84f6788 | 2005-01-20 18:52:28 +0000 | [diff] [blame] | 1637 | /// ExpandAddSub - Find a clever way to expand this add operation into |
| 1638 | /// subcomponents. |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 1639 | void SelectionDAGLegalize:: |
| 1640 | ExpandByParts(unsigned NodeOp, SDOperand LHS, SDOperand RHS, |
| 1641 | SDOperand &Lo, SDOperand &Hi) { |
Chris Lattner | 84f6788 | 2005-01-20 18:52:28 +0000 | [diff] [blame] | 1642 | // Expand the subcomponents. |
| 1643 | SDOperand LHSL, LHSH, RHSL, RHSH; |
| 1644 | ExpandOp(LHS, LHSL, LHSH); |
| 1645 | ExpandOp(RHS, RHSL, RHSH); |
| 1646 | |
Chris Lattner | bd0781e | 2005-04-11 20:29:59 +0000 | [diff] [blame] | 1647 | // FIXME: this should be moved to the dag combiner someday. |
| 1648 | if (NodeOp == ISD::ADD_PARTS || NodeOp == ISD::SUB_PARTS) |
| 1649 | if (LHSL.getValueType() == MVT::i32) { |
| 1650 | SDOperand LowEl; |
| 1651 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(LHSL)) |
| 1652 | if (C->getValue() == 0) |
| 1653 | LowEl = RHSL; |
| 1654 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(RHSL)) |
| 1655 | if (C->getValue() == 0) |
| 1656 | LowEl = LHSL; |
| 1657 | if (LowEl.Val) { |
| 1658 | // Turn this into an add/sub of the high part only. |
| 1659 | SDOperand HiEl = |
| 1660 | DAG.getNode(NodeOp == ISD::ADD_PARTS ? ISD::ADD : ISD::SUB, |
| 1661 | LowEl.getValueType(), LHSH, RHSH); |
| 1662 | Lo = LowEl; |
| 1663 | Hi = HiEl; |
| 1664 | return; |
| 1665 | } |
| 1666 | } |
| 1667 | |
Chris Lattner | 84f6788 | 2005-01-20 18:52:28 +0000 | [diff] [blame] | 1668 | std::vector<SDOperand> Ops; |
| 1669 | Ops.push_back(LHSL); |
| 1670 | Ops.push_back(LHSH); |
| 1671 | Ops.push_back(RHSL); |
| 1672 | Ops.push_back(RHSH); |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 1673 | Lo = DAG.getNode(NodeOp, LHSL.getValueType(), Ops); |
Chris Lattner | 84f6788 | 2005-01-20 18:52:28 +0000 | [diff] [blame] | 1674 | Hi = Lo.getValue(1); |
| 1675 | } |
| 1676 | |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 1677 | void SelectionDAGLegalize::ExpandShiftParts(unsigned NodeOp, |
| 1678 | SDOperand Op, SDOperand Amt, |
| 1679 | SDOperand &Lo, SDOperand &Hi) { |
| 1680 | // Expand the subcomponents. |
| 1681 | SDOperand LHSL, LHSH; |
| 1682 | ExpandOp(Op, LHSL, LHSH); |
| 1683 | |
| 1684 | std::vector<SDOperand> Ops; |
| 1685 | Ops.push_back(LHSL); |
| 1686 | Ops.push_back(LHSH); |
| 1687 | Ops.push_back(Amt); |
| 1688 | Lo = DAG.getNode(NodeOp, LHSL.getValueType(), Ops); |
| 1689 | Hi = Lo.getValue(1); |
| 1690 | } |
| 1691 | |
| 1692 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 1693 | /// ExpandShift - Try to find a clever way to expand this shift operation out to |
| 1694 | /// smaller elements. If we can't find a way that is more efficient than a |
| 1695 | /// libcall on this target, return false. Otherwise, return true with the |
| 1696 | /// low-parts expanded into Lo and Hi. |
| 1697 | bool SelectionDAGLegalize::ExpandShift(unsigned Opc, SDOperand Op,SDOperand Amt, |
| 1698 | SDOperand &Lo, SDOperand &Hi) { |
| 1699 | assert((Opc == ISD::SHL || Opc == ISD::SRA || Opc == ISD::SRL) && |
| 1700 | "This is not a shift!"); |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 1701 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 1702 | MVT::ValueType NVT = TLI.getTypeToTransformTo(Op.getValueType()); |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 1703 | SDOperand ShAmt = LegalizeOp(Amt); |
| 1704 | MVT::ValueType ShTy = ShAmt.getValueType(); |
| 1705 | unsigned VTBits = MVT::getSizeInBits(Op.getValueType()); |
| 1706 | unsigned NVTBits = MVT::getSizeInBits(NVT); |
| 1707 | |
| 1708 | // Handle the case when Amt is an immediate. Other cases are currently broken |
| 1709 | // and are disabled. |
| 1710 | if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Amt.Val)) { |
| 1711 | unsigned Cst = CN->getValue(); |
| 1712 | // Expand the incoming operand to be shifted, so that we have its parts |
| 1713 | SDOperand InL, InH; |
| 1714 | ExpandOp(Op, InL, InH); |
| 1715 | switch(Opc) { |
| 1716 | case ISD::SHL: |
| 1717 | if (Cst > VTBits) { |
| 1718 | Lo = DAG.getConstant(0, NVT); |
| 1719 | Hi = DAG.getConstant(0, NVT); |
| 1720 | } else if (Cst > NVTBits) { |
| 1721 | Lo = DAG.getConstant(0, NVT); |
| 1722 | Hi = DAG.getNode(ISD::SHL, NVT, InL, DAG.getConstant(Cst-NVTBits,ShTy)); |
Chris Lattner | ee27f57 | 2005-04-11 20:08:52 +0000 | [diff] [blame] | 1723 | } else if (Cst == NVTBits) { |
| 1724 | Lo = DAG.getConstant(0, NVT); |
| 1725 | Hi = InL; |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 1726 | } else { |
| 1727 | Lo = DAG.getNode(ISD::SHL, NVT, InL, DAG.getConstant(Cst, ShTy)); |
| 1728 | Hi = DAG.getNode(ISD::OR, NVT, |
| 1729 | DAG.getNode(ISD::SHL, NVT, InH, DAG.getConstant(Cst, ShTy)), |
| 1730 | DAG.getNode(ISD::SRL, NVT, InL, DAG.getConstant(NVTBits-Cst, ShTy))); |
| 1731 | } |
| 1732 | return true; |
| 1733 | case ISD::SRL: |
| 1734 | if (Cst > VTBits) { |
| 1735 | Lo = DAG.getConstant(0, NVT); |
| 1736 | Hi = DAG.getConstant(0, NVT); |
| 1737 | } else if (Cst > NVTBits) { |
| 1738 | Lo = DAG.getNode(ISD::SRL, NVT, InH, DAG.getConstant(Cst-NVTBits,ShTy)); |
| 1739 | Hi = DAG.getConstant(0, NVT); |
Chris Lattner | ee27f57 | 2005-04-11 20:08:52 +0000 | [diff] [blame] | 1740 | } else if (Cst == NVTBits) { |
| 1741 | Lo = InH; |
| 1742 | Hi = DAG.getConstant(0, NVT); |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 1743 | } else { |
| 1744 | Lo = DAG.getNode(ISD::OR, NVT, |
| 1745 | DAG.getNode(ISD::SRL, NVT, InL, DAG.getConstant(Cst, ShTy)), |
| 1746 | DAG.getNode(ISD::SHL, NVT, InH, DAG.getConstant(NVTBits-Cst, ShTy))); |
| 1747 | Hi = DAG.getNode(ISD::SRL, NVT, InH, DAG.getConstant(Cst, ShTy)); |
| 1748 | } |
| 1749 | return true; |
| 1750 | case ISD::SRA: |
| 1751 | if (Cst > VTBits) { |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 1752 | Hi = Lo = DAG.getNode(ISD::SRA, NVT, InH, |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 1753 | DAG.getConstant(NVTBits-1, ShTy)); |
| 1754 | } else if (Cst > NVTBits) { |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 1755 | Lo = DAG.getNode(ISD::SRA, NVT, InH, |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 1756 | DAG.getConstant(Cst-NVTBits, ShTy)); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 1757 | Hi = DAG.getNode(ISD::SRA, NVT, InH, |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 1758 | DAG.getConstant(NVTBits-1, ShTy)); |
Chris Lattner | ee27f57 | 2005-04-11 20:08:52 +0000 | [diff] [blame] | 1759 | } else if (Cst == NVTBits) { |
| 1760 | Lo = InH; |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 1761 | Hi = DAG.getNode(ISD::SRA, NVT, InH, |
Chris Lattner | ee27f57 | 2005-04-11 20:08:52 +0000 | [diff] [blame] | 1762 | DAG.getConstant(NVTBits-1, ShTy)); |
Nate Begeman | f1fe32e | 2005-04-06 21:13:14 +0000 | [diff] [blame] | 1763 | } else { |
| 1764 | Lo = DAG.getNode(ISD::OR, NVT, |
| 1765 | DAG.getNode(ISD::SRL, NVT, InL, DAG.getConstant(Cst, ShTy)), |
| 1766 | DAG.getNode(ISD::SHL, NVT, InH, DAG.getConstant(NVTBits-Cst, ShTy))); |
| 1767 | Hi = DAG.getNode(ISD::SRA, NVT, InH, DAG.getConstant(Cst, ShTy)); |
| 1768 | } |
| 1769 | return true; |
| 1770 | } |
| 1771 | } |
| 1772 | // FIXME: The following code for expanding shifts using ISD::SELECT is buggy, |
| 1773 | // so disable it for now. Currently targets are handling this via SHL_PARTS |
| 1774 | // and friends. |
| 1775 | return false; |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 1776 | |
| 1777 | // If we have an efficient select operation (or if the selects will all fold |
| 1778 | // away), lower to some complex code, otherwise just emit the libcall. |
| 1779 | if (TLI.getOperationAction(ISD::SELECT, NVT) != TargetLowering::Legal && |
| 1780 | !isa<ConstantSDNode>(Amt)) |
| 1781 | return false; |
| 1782 | |
| 1783 | SDOperand InL, InH; |
| 1784 | ExpandOp(Op, InL, InH); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 1785 | SDOperand NAmt = DAG.getNode(ISD::SUB, ShTy, // NAmt = 32-ShAmt |
| 1786 | DAG.getConstant(NVTBits, ShTy), ShAmt); |
| 1787 | |
Chris Lattner | e5544f8 | 2005-01-20 20:29:23 +0000 | [diff] [blame] | 1788 | // Compare the unmasked shift amount against 32. |
| 1789 | SDOperand Cond = DAG.getSetCC(ISD::SETGE, TLI.getSetCCResultTy(), ShAmt, |
| 1790 | DAG.getConstant(NVTBits, ShTy)); |
| 1791 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 1792 | if (TLI.getShiftAmountFlavor() != TargetLowering::Mask) { |
| 1793 | ShAmt = DAG.getNode(ISD::AND, ShTy, ShAmt, // ShAmt &= 31 |
| 1794 | DAG.getConstant(NVTBits-1, ShTy)); |
| 1795 | NAmt = DAG.getNode(ISD::AND, ShTy, NAmt, // NAmt &= 31 |
| 1796 | DAG.getConstant(NVTBits-1, ShTy)); |
| 1797 | } |
| 1798 | |
| 1799 | if (Opc == ISD::SHL) { |
| 1800 | SDOperand T1 = DAG.getNode(ISD::OR, NVT,// T1 = (Hi << Amt) | (Lo >> NAmt) |
| 1801 | DAG.getNode(ISD::SHL, NVT, InH, ShAmt), |
| 1802 | DAG.getNode(ISD::SRL, NVT, InL, NAmt)); |
Chris Lattner | e5544f8 | 2005-01-20 20:29:23 +0000 | [diff] [blame] | 1803 | 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] | 1804 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 1805 | Hi = DAG.getNode(ISD::SELECT, NVT, Cond, T2, T1); |
| 1806 | Lo = DAG.getNode(ISD::SELECT, NVT, Cond, DAG.getConstant(0, NVT), T2); |
| 1807 | } else { |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 1808 | SDOperand HiLoPart = DAG.getNode(ISD::SELECT, NVT, |
| 1809 | DAG.getSetCC(ISD::SETEQ, |
| 1810 | TLI.getSetCCResultTy(), NAmt, |
| 1811 | DAG.getConstant(32, ShTy)), |
| 1812 | DAG.getConstant(0, NVT), |
| 1813 | DAG.getNode(ISD::SHL, NVT, InH, NAmt)); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 1814 | SDOperand T1 = DAG.getNode(ISD::OR, NVT,// T1 = (Hi << NAmt) | (Lo >> Amt) |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 1815 | HiLoPart, |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 1816 | DAG.getNode(ISD::SRL, NVT, InL, ShAmt)); |
Chris Lattner | e5544f8 | 2005-01-20 20:29:23 +0000 | [diff] [blame] | 1817 | SDOperand T2 = DAG.getNode(Opc, NVT, InH, ShAmt); // T2 = InH >> ShAmt&31 |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 1818 | |
| 1819 | SDOperand HiPart; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 1820 | if (Opc == ISD::SRA) |
| 1821 | HiPart = DAG.getNode(ISD::SRA, NVT, InH, |
| 1822 | DAG.getConstant(NVTBits-1, ShTy)); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 1823 | else |
| 1824 | HiPart = DAG.getConstant(0, NVT); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 1825 | Lo = DAG.getNode(ISD::SELECT, NVT, Cond, T2, T1); |
Chris Lattner | e5544f8 | 2005-01-20 20:29:23 +0000 | [diff] [blame] | 1826 | Hi = DAG.getNode(ISD::SELECT, NVT, Cond, HiPart, T2); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 1827 | } |
| 1828 | return true; |
| 1829 | } |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 1830 | |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 1831 | /// FindLatestAdjCallStackDown - Scan up the dag to find the latest (highest |
| 1832 | /// NodeDepth) node that is an AdjCallStackDown operation and occurs later than |
| 1833 | /// Found. |
| 1834 | static void FindLatestAdjCallStackDown(SDNode *Node, SDNode *&Found) { |
| 1835 | if (Node->getNodeDepth() <= Found->getNodeDepth()) return; |
| 1836 | |
| 1837 | // If we found an ADJCALLSTACKDOWN, we already know this node occurs later |
| 1838 | // than the Found node. Just remember this node and return. |
| 1839 | if (Node->getOpcode() == ISD::ADJCALLSTACKDOWN) { |
| 1840 | Found = Node; |
| 1841 | return; |
| 1842 | } |
| 1843 | |
| 1844 | // Otherwise, scan the operands of Node to see if any of them is a call. |
| 1845 | assert(Node->getNumOperands() != 0 && |
| 1846 | "All leaves should have depth equal to the entry node!"); |
| 1847 | for (unsigned i = 0, e = Node->getNumOperands()-1; i != e; ++i) |
| 1848 | FindLatestAdjCallStackDown(Node->getOperand(i).Val, Found); |
| 1849 | |
| 1850 | // Tail recurse for the last iteration. |
| 1851 | FindLatestAdjCallStackDown(Node->getOperand(Node->getNumOperands()-1).Val, |
| 1852 | Found); |
| 1853 | } |
| 1854 | |
| 1855 | |
| 1856 | /// FindEarliestAdjCallStackUp - Scan down the dag to find the earliest (lowest |
| 1857 | /// NodeDepth) node that is an AdjCallStackUp operation and occurs more recent |
| 1858 | /// than Found. |
| 1859 | static void FindEarliestAdjCallStackUp(SDNode *Node, SDNode *&Found) { |
| 1860 | if (Found && Node->getNodeDepth() >= Found->getNodeDepth()) return; |
| 1861 | |
| 1862 | // If we found an ADJCALLSTACKUP, we already know this node occurs earlier |
| 1863 | // than the Found node. Just remember this node and return. |
| 1864 | if (Node->getOpcode() == ISD::ADJCALLSTACKUP) { |
| 1865 | Found = Node; |
| 1866 | return; |
| 1867 | } |
| 1868 | |
| 1869 | // Otherwise, scan the operands of Node to see if any of them is a call. |
| 1870 | SDNode::use_iterator UI = Node->use_begin(), E = Node->use_end(); |
| 1871 | if (UI == E) return; |
| 1872 | for (--E; UI != E; ++UI) |
| 1873 | FindEarliestAdjCallStackUp(*UI, Found); |
| 1874 | |
| 1875 | // Tail recurse for the last iteration. |
| 1876 | FindEarliestAdjCallStackUp(*UI, Found); |
| 1877 | } |
| 1878 | |
| 1879 | /// FindAdjCallStackUp - Given a chained node that is part of a call sequence, |
| 1880 | /// find the ADJCALLSTACKUP node that terminates the call sequence. |
| 1881 | static SDNode *FindAdjCallStackUp(SDNode *Node) { |
| 1882 | if (Node->getOpcode() == ISD::ADJCALLSTACKUP) |
| 1883 | return Node; |
Chris Lattner | f4b4579 | 2005-04-02 03:22:40 +0000 | [diff] [blame] | 1884 | if (Node->use_empty()) |
| 1885 | return 0; // No adjcallstackup |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 1886 | |
| 1887 | if (Node->hasOneUse()) // Simple case, only has one user to check. |
| 1888 | return FindAdjCallStackUp(*Node->use_begin()); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 1889 | |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 1890 | SDOperand TheChain(Node, Node->getNumValues()-1); |
| 1891 | assert(TheChain.getValueType() == MVT::Other && "Is not a token chain!"); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 1892 | |
| 1893 | for (SDNode::use_iterator UI = Node->use_begin(), |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 1894 | E = Node->use_end(); ; ++UI) { |
| 1895 | assert(UI != E && "Didn't find a user of the tokchain, no ADJCALLSTACKUP!"); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 1896 | |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 1897 | // Make sure to only follow users of our token chain. |
| 1898 | SDNode *User = *UI; |
| 1899 | for (unsigned i = 0, e = User->getNumOperands(); i != e; ++i) |
| 1900 | if (User->getOperand(i) == TheChain) |
| 1901 | return FindAdjCallStackUp(User); |
| 1902 | } |
| 1903 | assert(0 && "Unreachable"); |
| 1904 | abort(); |
| 1905 | } |
| 1906 | |
| 1907 | /// FindInputOutputChains - If we are replacing an operation with a call we need |
| 1908 | /// to find the call that occurs before and the call that occurs after it to |
| 1909 | /// properly serialize the calls in the block. |
| 1910 | static SDOperand FindInputOutputChains(SDNode *OpNode, SDNode *&OutChain, |
| 1911 | SDOperand Entry) { |
| 1912 | SDNode *LatestAdjCallStackDown = Entry.Val; |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 1913 | SDNode *LatestAdjCallStackUp = 0; |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 1914 | FindLatestAdjCallStackDown(OpNode, LatestAdjCallStackDown); |
| 1915 | //std::cerr << "Found node: "; LatestAdjCallStackDown->dump(); std::cerr <<"\n"; |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 1916 | |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 1917 | // It is possible that no ISD::ADJCALLSTACKDOWN was found because there is no |
| 1918 | // previous call in the function. LatestCallStackDown may in that case be |
| 1919 | // the entry node itself. Do not attempt to find a matching ADJCALLSTACKUP |
| 1920 | // unless LatestCallStackDown is an ADJCALLSTACKDOWN. |
| 1921 | if (LatestAdjCallStackDown->getOpcode() == ISD::ADJCALLSTACKDOWN) |
| 1922 | LatestAdjCallStackUp = FindAdjCallStackUp(LatestAdjCallStackDown); |
| 1923 | else |
| 1924 | LatestAdjCallStackUp = Entry.Val; |
| 1925 | assert(LatestAdjCallStackUp && "NULL return from FindAdjCallStackUp"); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 1926 | |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 1927 | SDNode *EarliestAdjCallStackUp = 0; |
| 1928 | FindEarliestAdjCallStackUp(OpNode, EarliestAdjCallStackUp); |
| 1929 | |
| 1930 | if (EarliestAdjCallStackUp) { |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 1931 | //std::cerr << "Found node: "; |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 1932 | //EarliestAdjCallStackUp->dump(); std::cerr <<"\n"; |
| 1933 | } |
| 1934 | |
| 1935 | return SDOperand(LatestAdjCallStackUp, 0); |
| 1936 | } |
| 1937 | |
| 1938 | |
| 1939 | |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 1940 | // ExpandLibCall - Expand a node into a call to a libcall. If the result value |
| 1941 | // does not fit into a register, return the lo part and set the hi part to the |
| 1942 | // by-reg argument. If it does fit into a single register, return the result |
| 1943 | // and leave the Hi part unset. |
| 1944 | SDOperand SelectionDAGLegalize::ExpandLibCall(const char *Name, SDNode *Node, |
| 1945 | SDOperand &Hi) { |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 1946 | SDNode *OutChain; |
| 1947 | SDOperand InChain = FindInputOutputChains(Node, OutChain, |
| 1948 | DAG.getEntryNode()); |
Chris Lattner | f4b4579 | 2005-04-02 03:22:40 +0000 | [diff] [blame] | 1949 | if (InChain.Val == 0) |
| 1950 | InChain = DAG.getEntryNode(); |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 1951 | |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 1952 | TargetLowering::ArgListTy Args; |
| 1953 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) { |
| 1954 | MVT::ValueType ArgVT = Node->getOperand(i).getValueType(); |
| 1955 | const Type *ArgTy = MVT::getTypeForValueType(ArgVT); |
| 1956 | Args.push_back(std::make_pair(Node->getOperand(i), ArgTy)); |
| 1957 | } |
| 1958 | SDOperand Callee = DAG.getExternalSymbol(Name, TLI.getPointerTy()); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 1959 | |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 1960 | // We don't care about token chains for libcalls. We just use the entry |
| 1961 | // node as our input and ignore the output chain. This allows us to place |
| 1962 | // calls wherever we need them to satisfy data dependences. |
| 1963 | const Type *RetTy = MVT::getTypeForValueType(Node->getValueType(0)); |
Nate Begeman | 8e21e71 | 2005-03-26 01:29:23 +0000 | [diff] [blame] | 1964 | SDOperand Result = TLI.LowerCallTo(InChain, RetTy, false, Callee, |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 1965 | Args, DAG).first; |
| 1966 | switch (getTypeAction(Result.getValueType())) { |
| 1967 | default: assert(0 && "Unknown thing"); |
| 1968 | case Legal: |
| 1969 | return Result; |
| 1970 | case Promote: |
| 1971 | assert(0 && "Cannot promote this yet!"); |
| 1972 | case Expand: |
| 1973 | SDOperand Lo; |
| 1974 | ExpandOp(Result, Lo, Hi); |
| 1975 | return Lo; |
| 1976 | } |
| 1977 | } |
| 1978 | |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 1979 | |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 1980 | /// ExpandIntToFP - Expand a [US]INT_TO_FP operation, assuming that the |
| 1981 | /// destination type is legal. |
| 1982 | SDOperand SelectionDAGLegalize:: |
| 1983 | ExpandIntToFP(bool isSigned, MVT::ValueType DestTy, SDOperand Source) { |
| 1984 | assert(getTypeAction(DestTy) == Legal && "Destination type is not legal!"); |
| 1985 | assert(getTypeAction(Source.getValueType()) == Expand && |
| 1986 | "This is not an expansion!"); |
| 1987 | assert(Source.getValueType() == MVT::i64 && "Only handle expand from i64!"); |
| 1988 | |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 1989 | SDNode *OutChain; |
| 1990 | SDOperand InChain = FindInputOutputChains(Source.Val, OutChain, |
| 1991 | DAG.getEntryNode()); |
| 1992 | |
Chris Lattner | fed5577 | 2005-01-23 23:19:44 +0000 | [diff] [blame] | 1993 | const char *FnName = 0; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 1994 | if (isSigned) { |
| 1995 | if (DestTy == MVT::f32) |
| 1996 | FnName = "__floatdisf"; |
| 1997 | else { |
| 1998 | assert(DestTy == MVT::f64 && "Unknown fp value type!"); |
| 1999 | FnName = "__floatdidf"; |
| 2000 | } |
| 2001 | } else { |
| 2002 | // If this is unsigned, and not supported, first perform the conversion to |
| 2003 | // signed, then adjust the result if the sign bit is set. |
Chris Lattner | ffe284c | 2005-04-13 03:42:14 +0000 | [diff] [blame] | 2004 | SDOperand SignedConv = ExpandIntToFP(true, DestTy, Source); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 2005 | |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 2006 | assert(Source.getValueType() == MVT::i64 && |
| 2007 | "This only works for 64-bit -> FP"); |
| 2008 | // The 64-bit value loaded will be incorrectly if the 'sign bit' of the |
| 2009 | // incoming integer is set. To handle this, we dynamically test to see if |
| 2010 | // it is set, and, if so, add a fudge factor. |
| 2011 | SDOperand Lo, Hi; |
| 2012 | ExpandOp(Source, Lo, Hi); |
| 2013 | |
| 2014 | SDOperand SignSet = DAG.getSetCC(ISD::SETLT, TLI.getSetCCResultTy(), Hi, |
| 2015 | DAG.getConstant(0, Hi.getValueType())); |
| 2016 | SDOperand Zero = getIntPtrConstant(0), Four = getIntPtrConstant(4); |
| 2017 | SDOperand CstOffset = DAG.getNode(ISD::SELECT, Zero.getValueType(), |
| 2018 | SignSet, Four, Zero); |
| 2019 | // FIXME: This is almost certainly broken for big-endian systems. Should |
| 2020 | // this just put the fudge factor in the low bits of the uint64 constant or? |
| 2021 | static Constant *FudgeFactor = |
| 2022 | ConstantUInt::get(Type::ULongTy, 0x5f800000ULL << 32); |
| 2023 | |
| 2024 | MachineConstantPool *CP = DAG.getMachineFunction().getConstantPool(); |
| 2025 | SDOperand CPIdx = DAG.getConstantPool(CP->getConstantPoolIndex(FudgeFactor), |
| 2026 | TLI.getPointerTy()); |
| 2027 | CPIdx = DAG.getNode(ISD::ADD, TLI.getPointerTy(), CPIdx, CstOffset); |
| 2028 | SDOperand FudgeInReg; |
| 2029 | if (DestTy == MVT::f32) |
Chris Lattner | 52d08bd | 2005-05-09 20:23:03 +0000 | [diff] [blame^] | 2030 | FudgeInReg = DAG.getLoad(MVT::f32, DAG.getEntryNode(), CPIdx, |
| 2031 | DAG.getSrcValue(NULL)); |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 2032 | else { |
| 2033 | assert(DestTy == MVT::f64 && "Unexpected conversion"); |
| 2034 | FudgeInReg = DAG.getNode(ISD::EXTLOAD, MVT::f64, DAG.getEntryNode(), |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 2035 | CPIdx, DAG.getSrcValue(NULL), MVT::f32); |
Chris Lattner | e9c35e7 | 2005-04-13 05:09:42 +0000 | [diff] [blame] | 2036 | } |
| 2037 | return DAG.getNode(ISD::ADD, DestTy, SignedConv, FudgeInReg); |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 2038 | } |
| 2039 | SDOperand Callee = DAG.getExternalSymbol(FnName, TLI.getPointerTy()); |
| 2040 | |
| 2041 | TargetLowering::ArgListTy Args; |
| 2042 | const Type *ArgTy = MVT::getTypeForValueType(Source.getValueType()); |
| 2043 | Args.push_back(std::make_pair(Source, ArgTy)); |
| 2044 | |
| 2045 | // We don't care about token chains for libcalls. We just use the entry |
| 2046 | // node as our input and ignore the output chain. This allows us to place |
| 2047 | // calls wherever we need them to satisfy data dependences. |
| 2048 | const Type *RetTy = MVT::getTypeForValueType(DestTy); |
Nate Begeman | 8e21e71 | 2005-03-26 01:29:23 +0000 | [diff] [blame] | 2049 | return TLI.LowerCallTo(InChain, RetTy, false, Callee, Args, DAG).first; |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 2050 | } |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2051 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 2052 | |
| 2053 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2054 | /// ExpandOp - Expand the specified SDOperand into its two component pieces |
| 2055 | /// Lo&Hi. Note that the Op MUST be an expanded type. As a result of this, the |
| 2056 | /// LegalizeNodes map is filled in for any results that are not expanded, the |
| 2057 | /// ExpandedNodes map is filled in for any results that are expanded, and the |
| 2058 | /// Lo/Hi values are returned. |
| 2059 | void SelectionDAGLegalize::ExpandOp(SDOperand Op, SDOperand &Lo, SDOperand &Hi){ |
| 2060 | MVT::ValueType VT = Op.getValueType(); |
Chris Lattner | 71c42a0 | 2005-01-16 01:11:45 +0000 | [diff] [blame] | 2061 | MVT::ValueType NVT = TLI.getTypeToTransformTo(VT); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2062 | SDNode *Node = Op.Val; |
| 2063 | assert(getTypeAction(VT) == Expand && "Not an expanded type!"); |
| 2064 | assert(MVT::isInteger(VT) && "Cannot expand FP values!"); |
| 2065 | assert(MVT::isInteger(NVT) && NVT < VT && |
| 2066 | "Cannot expand to FP value or to larger int value!"); |
| 2067 | |
| 2068 | // If there is more than one use of this, see if we already expanded it. |
| 2069 | // There is no use remembering values that only have a single use, as the map |
| 2070 | // entries will never be reused. |
| 2071 | if (!Node->hasOneUse()) { |
| 2072 | std::map<SDOperand, std::pair<SDOperand, SDOperand> >::iterator I |
| 2073 | = ExpandedNodes.find(Op); |
| 2074 | if (I != ExpandedNodes.end()) { |
| 2075 | Lo = I->second.first; |
| 2076 | Hi = I->second.second; |
| 2077 | return; |
| 2078 | } |
| 2079 | } |
| 2080 | |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 2081 | // Expanding to multiple registers needs to perform an optimization step, and |
| 2082 | // is not careful to avoid operations the target does not support. Make sure |
| 2083 | // that all generated operations are legalized in the next iteration. |
| 2084 | NeedsAnotherIteration = true; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2085 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2086 | switch (Node->getOpcode()) { |
| 2087 | default: |
| 2088 | std::cerr << "NODE: "; Node->dump(); std::cerr << "\n"; |
| 2089 | assert(0 && "Do not know how to expand this operator!"); |
| 2090 | abort(); |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 2091 | case ISD::UNDEF: |
| 2092 | Lo = DAG.getNode(ISD::UNDEF, NVT); |
| 2093 | Hi = DAG.getNode(ISD::UNDEF, NVT); |
| 2094 | break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2095 | case ISD::Constant: { |
| 2096 | uint64_t Cst = cast<ConstantSDNode>(Node)->getValue(); |
| 2097 | Lo = DAG.getConstant(Cst, NVT); |
| 2098 | Hi = DAG.getConstant(Cst >> MVT::getSizeInBits(NVT), NVT); |
| 2099 | break; |
| 2100 | } |
| 2101 | |
| 2102 | case ISD::CopyFromReg: { |
Chris Lattner | 18c2f13 | 2005-01-13 20:50:02 +0000 | [diff] [blame] | 2103 | unsigned Reg = cast<RegSDNode>(Node)->getReg(); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2104 | // Aggregate register values are always in consequtive pairs. |
Chris Lattner | 69a5215 | 2005-01-14 22:38:01 +0000 | [diff] [blame] | 2105 | Lo = DAG.getCopyFromReg(Reg, NVT, Node->getOperand(0)); |
| 2106 | Hi = DAG.getCopyFromReg(Reg+1, NVT, Lo.getValue(1)); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2107 | |
Chris Lattner | 69a5215 | 2005-01-14 22:38:01 +0000 | [diff] [blame] | 2108 | // Remember that we legalized the chain. |
| 2109 | AddLegalizedOperand(Op.getValue(1), Hi.getValue(1)); |
| 2110 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2111 | assert(isTypeLegal(NVT) && "Cannot expand this multiple times yet!"); |
| 2112 | break; |
| 2113 | } |
| 2114 | |
Chris Lattner | d4e50bb | 2005-03-28 22:03:13 +0000 | [diff] [blame] | 2115 | case ISD::BUILD_PAIR: |
| 2116 | // Legalize both operands. FIXME: in the future we should handle the case |
| 2117 | // where the two elements are not legal. |
| 2118 | assert(isTypeLegal(NVT) && "Cannot expand this multiple times yet!"); |
| 2119 | Lo = LegalizeOp(Node->getOperand(0)); |
| 2120 | Hi = LegalizeOp(Node->getOperand(1)); |
| 2121 | break; |
| 2122 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2123 | case ISD::LOAD: { |
| 2124 | SDOperand Ch = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 2125 | SDOperand Ptr = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 2126 | Lo = DAG.getLoad(NVT, Ch, Ptr, Node->getOperand(2)); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2127 | |
| 2128 | // Increment the pointer to the other half. |
Chris Lattner | 38d6be5 | 2005-01-09 19:43:23 +0000 | [diff] [blame] | 2129 | unsigned IncrementSize = MVT::getSizeInBits(Lo.getValueType())/8; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2130 | Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, |
| 2131 | getIntPtrConstant(IncrementSize)); |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 2132 | //Is this safe? declaring that the two parts of the split load |
| 2133 | //are from the same instruction? |
| 2134 | Hi = DAG.getLoad(NVT, Ch, Ptr, Node->getOperand(2)); |
Chris Lattner | ec39a45 | 2005-01-19 18:02:17 +0000 | [diff] [blame] | 2135 | |
| 2136 | // Build a factor node to remember that this load is independent of the |
| 2137 | // other one. |
| 2138 | SDOperand TF = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1), |
| 2139 | Hi.getValue(1)); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2140 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2141 | // Remember that we legalized the chain. |
Chris Lattner | ec39a45 | 2005-01-19 18:02:17 +0000 | [diff] [blame] | 2142 | AddLegalizedOperand(Op.getValue(1), TF); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2143 | if (!TLI.isLittleEndian()) |
| 2144 | std::swap(Lo, Hi); |
| 2145 | break; |
| 2146 | } |
| 2147 | case ISD::CALL: { |
| 2148 | SDOperand Chain = LegalizeOp(Node->getOperand(0)); // Legalize the chain. |
| 2149 | SDOperand Callee = LegalizeOp(Node->getOperand(1)); // Legalize the callee. |
| 2150 | |
Chris Lattner | 3d9dffc | 2005-01-19 20:24:35 +0000 | [diff] [blame] | 2151 | bool Changed = false; |
| 2152 | std::vector<SDOperand> Ops; |
| 2153 | for (unsigned i = 2, e = Node->getNumOperands(); i != e; ++i) { |
| 2154 | Ops.push_back(LegalizeOp(Node->getOperand(i))); |
| 2155 | Changed |= Ops.back() != Node->getOperand(i); |
| 2156 | } |
| 2157 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2158 | assert(Node->getNumValues() == 2 && Op.ResNo == 0 && |
| 2159 | "Can only expand a call once so far, not i64 -> i16!"); |
| 2160 | |
| 2161 | std::vector<MVT::ValueType> RetTyVTs; |
| 2162 | RetTyVTs.reserve(3); |
| 2163 | RetTyVTs.push_back(NVT); |
| 2164 | RetTyVTs.push_back(NVT); |
| 2165 | RetTyVTs.push_back(MVT::Other); |
Chris Lattner | 3d9dffc | 2005-01-19 20:24:35 +0000 | [diff] [blame] | 2166 | SDNode *NC = DAG.getCall(RetTyVTs, Chain, Callee, Ops); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2167 | Lo = SDOperand(NC, 0); |
| 2168 | Hi = SDOperand(NC, 1); |
| 2169 | |
| 2170 | // Insert the new chain mapping. |
Chris Lattner | e3304a3 | 2005-01-08 20:35:13 +0000 | [diff] [blame] | 2171 | AddLegalizedOperand(Op.getValue(1), Hi.getValue(2)); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2172 | break; |
| 2173 | } |
| 2174 | case ISD::AND: |
| 2175 | case ISD::OR: |
| 2176 | case ISD::XOR: { // Simple logical operators -> two trivial pieces. |
| 2177 | SDOperand LL, LH, RL, RH; |
| 2178 | ExpandOp(Node->getOperand(0), LL, LH); |
| 2179 | ExpandOp(Node->getOperand(1), RL, RH); |
| 2180 | Lo = DAG.getNode(Node->getOpcode(), NVT, LL, RL); |
| 2181 | Hi = DAG.getNode(Node->getOpcode(), NVT, LH, RH); |
| 2182 | break; |
| 2183 | } |
| 2184 | case ISD::SELECT: { |
| 2185 | SDOperand C, LL, LH, RL, RH; |
Chris Lattner | 47e9223 | 2005-01-18 19:27:06 +0000 | [diff] [blame] | 2186 | |
| 2187 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 2188 | case Expand: assert(0 && "It's impossible to expand bools"); |
| 2189 | case Legal: |
| 2190 | C = LegalizeOp(Node->getOperand(0)); // Legalize the condition. |
| 2191 | break; |
| 2192 | case Promote: |
| 2193 | C = PromoteOp(Node->getOperand(0)); // Promote the condition. |
| 2194 | break; |
| 2195 | } |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2196 | ExpandOp(Node->getOperand(1), LL, LH); |
| 2197 | ExpandOp(Node->getOperand(2), RL, RH); |
| 2198 | Lo = DAG.getNode(ISD::SELECT, NVT, C, LL, RL); |
| 2199 | Hi = DAG.getNode(ISD::SELECT, NVT, C, LH, RH); |
| 2200 | break; |
| 2201 | } |
| 2202 | case ISD::SIGN_EXTEND: { |
Chris Lattner | 06098e0 | 2005-04-03 23:41:52 +0000 | [diff] [blame] | 2203 | SDOperand In; |
| 2204 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 2205 | case Expand: assert(0 && "expand-expand not implemented yet!"); |
| 2206 | case Legal: In = LegalizeOp(Node->getOperand(0)); break; |
| 2207 | case Promote: |
| 2208 | In = PromoteOp(Node->getOperand(0)); |
| 2209 | // Emit the appropriate sign_extend_inreg to get the value we want. |
| 2210 | In = DAG.getNode(ISD::SIGN_EXTEND_INREG, In.getValueType(), In, |
| 2211 | Node->getOperand(0).getValueType()); |
| 2212 | break; |
| 2213 | } |
| 2214 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2215 | // The low part is just a sign extension of the input (which degenerates to |
| 2216 | // a copy). |
Chris Lattner | 06098e0 | 2005-04-03 23:41:52 +0000 | [diff] [blame] | 2217 | Lo = DAG.getNode(ISD::SIGN_EXTEND, NVT, In); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2218 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2219 | // The high part is obtained by SRA'ing all but one of the bits of the lo |
| 2220 | // part. |
Chris Lattner | 2dad454 | 2005-01-12 18:19:52 +0000 | [diff] [blame] | 2221 | unsigned LoSize = MVT::getSizeInBits(Lo.getValueType()); |
Chris Lattner | 27ff112 | 2005-01-22 00:31:52 +0000 | [diff] [blame] | 2222 | Hi = DAG.getNode(ISD::SRA, NVT, Lo, DAG.getConstant(LoSize-1, |
| 2223 | TLI.getShiftAmountTy())); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2224 | break; |
| 2225 | } |
Chris Lattner | 06098e0 | 2005-04-03 23:41:52 +0000 | [diff] [blame] | 2226 | case ISD::ZERO_EXTEND: { |
| 2227 | SDOperand In; |
| 2228 | switch (getTypeAction(Node->getOperand(0).getValueType())) { |
| 2229 | case Expand: assert(0 && "expand-expand not implemented yet!"); |
| 2230 | case Legal: In = LegalizeOp(Node->getOperand(0)); break; |
| 2231 | case Promote: |
| 2232 | In = PromoteOp(Node->getOperand(0)); |
| 2233 | // Emit the appropriate zero_extend_inreg to get the value we want. |
Chris Lattner | 2399356 | 2005-04-13 02:38:47 +0000 | [diff] [blame] | 2234 | In = DAG.getZeroExtendInReg(In, Node->getOperand(0).getValueType()); |
Chris Lattner | 06098e0 | 2005-04-03 23:41:52 +0000 | [diff] [blame] | 2235 | break; |
| 2236 | } |
| 2237 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2238 | // The low part is just a zero extension of the input (which degenerates to |
| 2239 | // a copy). |
Chris Lattner | dea29e2 | 2005-04-10 01:13:15 +0000 | [diff] [blame] | 2240 | Lo = DAG.getNode(ISD::ZERO_EXTEND, NVT, In); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2241 | |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2242 | // The high part is just a zero. |
| 2243 | Hi = DAG.getConstant(0, NVT); |
| 2244 | break; |
Chris Lattner | 06098e0 | 2005-04-03 23:41:52 +0000 | [diff] [blame] | 2245 | } |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 2246 | // These operators cannot be expanded directly, emit them as calls to |
| 2247 | // library functions. |
| 2248 | case ISD::FP_TO_SINT: |
| 2249 | if (Node->getOperand(0).getValueType() == MVT::f32) |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 2250 | Lo = ExpandLibCall("__fixsfdi", Node, Hi); |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 2251 | else |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 2252 | Lo = ExpandLibCall("__fixdfdi", Node, Hi); |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 2253 | break; |
| 2254 | case ISD::FP_TO_UINT: |
| 2255 | if (Node->getOperand(0).getValueType() == MVT::f32) |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 2256 | Lo = ExpandLibCall("__fixunssfdi", Node, Hi); |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 2257 | else |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 2258 | Lo = ExpandLibCall("__fixunsdfdi", Node, Hi); |
Chris Lattner | 4e6c746 | 2005-01-08 19:27:05 +0000 | [diff] [blame] | 2259 | break; |
| 2260 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 2261 | case ISD::SHL: |
| 2262 | // If we can emit an efficient shift operation, do so now. |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 2263 | if (ExpandShift(ISD::SHL, Node->getOperand(0), Node->getOperand(1), Lo, Hi)) |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 2264 | break; |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 2265 | |
| 2266 | // If this target supports SHL_PARTS, use it. |
| 2267 | if (TLI.getOperationAction(ISD::SHL_PARTS, NVT) == TargetLowering::Legal) { |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 2268 | ExpandShiftParts(ISD::SHL_PARTS, Node->getOperand(0), Node->getOperand(1), |
| 2269 | Lo, Hi); |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 2270 | break; |
| 2271 | } |
| 2272 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 2273 | // Otherwise, emit a libcall. |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 2274 | Lo = ExpandLibCall("__ashldi3", Node, Hi); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 2275 | break; |
| 2276 | |
| 2277 | case ISD::SRA: |
| 2278 | // If we can emit an efficient shift operation, do so now. |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 2279 | if (ExpandShift(ISD::SRA, Node->getOperand(0), Node->getOperand(1), Lo, Hi)) |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 2280 | break; |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 2281 | |
| 2282 | // If this target supports SRA_PARTS, use it. |
| 2283 | if (TLI.getOperationAction(ISD::SRA_PARTS, NVT) == TargetLowering::Legal) { |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 2284 | ExpandShiftParts(ISD::SRA_PARTS, Node->getOperand(0), Node->getOperand(1), |
| 2285 | Lo, Hi); |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 2286 | break; |
| 2287 | } |
| 2288 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 2289 | // Otherwise, emit a libcall. |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 2290 | Lo = ExpandLibCall("__ashrdi3", Node, Hi); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 2291 | break; |
| 2292 | case ISD::SRL: |
| 2293 | // If we can emit an efficient shift operation, do so now. |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 2294 | if (ExpandShift(ISD::SRL, Node->getOperand(0), Node->getOperand(1), Lo, Hi)) |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 2295 | break; |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 2296 | |
| 2297 | // If this target supports SRL_PARTS, use it. |
| 2298 | if (TLI.getOperationAction(ISD::SRL_PARTS, NVT) == TargetLowering::Legal) { |
Chris Lattner | 5b359c6 | 2005-04-02 04:00:59 +0000 | [diff] [blame] | 2299 | ExpandShiftParts(ISD::SRL_PARTS, Node->getOperand(0), Node->getOperand(1), |
| 2300 | Lo, Hi); |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 2301 | break; |
| 2302 | } |
| 2303 | |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 2304 | // Otherwise, emit a libcall. |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 2305 | Lo = ExpandLibCall("__lshrdi3", Node, Hi); |
Chris Lattner | e34b396 | 2005-01-19 04:19:40 +0000 | [diff] [blame] | 2306 | break; |
| 2307 | |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2308 | case ISD::ADD: |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 2309 | ExpandByParts(ISD::ADD_PARTS, Node->getOperand(0), Node->getOperand(1), |
| 2310 | Lo, Hi); |
Chris Lattner | 84f6788 | 2005-01-20 18:52:28 +0000 | [diff] [blame] | 2311 | break; |
| 2312 | case ISD::SUB: |
Chris Lattner | 4759982 | 2005-04-02 03:38:53 +0000 | [diff] [blame] | 2313 | ExpandByParts(ISD::SUB_PARTS, Node->getOperand(0), Node->getOperand(1), |
| 2314 | Lo, Hi); |
Chris Lattner | 84f6788 | 2005-01-20 18:52:28 +0000 | [diff] [blame] | 2315 | break; |
Nate Begeman | c7c1657 | 2005-04-11 03:01:51 +0000 | [diff] [blame] | 2316 | case ISD::MUL: { |
| 2317 | if (TLI.getOperationAction(ISD::MULHU, NVT) == TargetLowering::Legal) { |
| 2318 | SDOperand LL, LH, RL, RH; |
| 2319 | ExpandOp(Node->getOperand(0), LL, LH); |
| 2320 | ExpandOp(Node->getOperand(1), RL, RH); |
| 2321 | Hi = DAG.getNode(ISD::MULHU, NVT, LL, RL); |
| 2322 | RH = DAG.getNode(ISD::MUL, NVT, LL, RH); |
| 2323 | LH = DAG.getNode(ISD::MUL, NVT, LH, RL); |
| 2324 | Hi = DAG.getNode(ISD::ADD, NVT, Hi, RH); |
| 2325 | Hi = DAG.getNode(ISD::ADD, NVT, Hi, LH); |
| 2326 | Lo = DAG.getNode(ISD::MUL, NVT, LL, RL); |
| 2327 | } else { |
| 2328 | Lo = ExpandLibCall("__muldi3" , Node, Hi); break; |
| 2329 | } |
| 2330 | break; |
| 2331 | } |
Chris Lattner | 77e77a6 | 2005-01-21 06:05:23 +0000 | [diff] [blame] | 2332 | case ISD::SDIV: Lo = ExpandLibCall("__divdi3" , Node, Hi); break; |
| 2333 | case ISD::UDIV: Lo = ExpandLibCall("__udivdi3", Node, Hi); break; |
| 2334 | case ISD::SREM: Lo = ExpandLibCall("__moddi3" , Node, Hi); break; |
| 2335 | case ISD::UREM: Lo = ExpandLibCall("__umoddi3", Node, Hi); break; |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2336 | } |
| 2337 | |
| 2338 | // Remember in a map if the values will be reused later. |
| 2339 | if (!Node->hasOneUse()) { |
| 2340 | bool isNew = ExpandedNodes.insert(std::make_pair(Op, |
| 2341 | std::make_pair(Lo, Hi))).second; |
| 2342 | assert(isNew && "Value already expanded?!?"); |
| 2343 | } |
| 2344 | } |
| 2345 | |
| 2346 | |
| 2347 | // SelectionDAG::Legalize - This is the entry point for the file. |
| 2348 | // |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 2349 | void SelectionDAG::Legalize() { |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2350 | /// run - This is the main entry point to this class. |
| 2351 | /// |
Chris Lattner | 9c32d3b | 2005-01-23 04:42:50 +0000 | [diff] [blame] | 2352 | SelectionDAGLegalize(*this).Run(); |
Chris Lattner | 3e928bb | 2005-01-07 07:47:09 +0000 | [diff] [blame] | 2353 | } |
| 2354 | |