Chris Lattner | c6d0567 | 2006-05-23 23:20:42 +0000 | [diff] [blame] | 1 | //===-- X86ISelLowering.cpp - X86 DAG Lowering Implementation -------------===// |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by Chris Lattner and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines the interfaces that X86 uses to lower LLVM code into a |
| 11 | // selection DAG. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "X86.h" |
Evan Cheng | 0cc3945 | 2006-01-16 21:21:29 +0000 | [diff] [blame] | 16 | #include "X86InstrBuilder.h" |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 17 | #include "X86ISelLowering.h" |
Evan Cheng | e8bd0a3 | 2006-06-06 23:30:24 +0000 | [diff] [blame] | 18 | #include "X86MachineFunctionInfo.h" |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 19 | #include "X86TargetMachine.h" |
| 20 | #include "llvm/CallingConv.h" |
Evan Cheng | 223547a | 2006-01-31 22:28:30 +0000 | [diff] [blame] | 21 | #include "llvm/Constants.h" |
Evan Cheng | 347d5f7 | 2006-04-28 21:29:37 +0000 | [diff] [blame] | 22 | #include "llvm/DerivedTypes.h" |
Lauro Ramos Venancio | b3a0417 | 2007-04-20 21:38:10 +0000 | [diff] [blame] | 23 | #include "llvm/GlobalVariable.h" |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 24 | #include "llvm/Function.h" |
Evan Cheng | 6be2c58 | 2006-04-05 23:38:46 +0000 | [diff] [blame] | 25 | #include "llvm/Intrinsics.h" |
Evan Cheng | 30b37b5 | 2006-03-13 23:18:16 +0000 | [diff] [blame] | 26 | #include "llvm/ADT/VectorExtras.h" |
| 27 | #include "llvm/Analysis/ScalarEvolutionExpressions.h" |
Chris Lattner | 362e98a | 2007-02-27 04:43:02 +0000 | [diff] [blame] | 28 | #include "llvm/CodeGen/CallingConvLower.h" |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 29 | #include "llvm/CodeGen/MachineFrameInfo.h" |
Evan Cheng | 4a46080 | 2006-01-11 00:33:36 +0000 | [diff] [blame] | 30 | #include "llvm/CodeGen/MachineFunction.h" |
| 31 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 32 | #include "llvm/CodeGen/SelectionDAG.h" |
| 33 | #include "llvm/CodeGen/SSARegMap.h" |
Evan Cheng | 0488db9 | 2007-09-25 01:57:46 +0000 | [diff] [blame] | 34 | #include "llvm/Support/CommandLine.h" |
Evan Cheng | ef6ffb1 | 2006-01-31 03:14:29 +0000 | [diff] [blame] | 35 | #include "llvm/Support/MathExtras.h" |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 36 | #include "llvm/Target/TargetOptions.h" |
Chris Lattner | 1a60aa7 | 2006-10-31 19:42:44 +0000 | [diff] [blame] | 37 | #include "llvm/ADT/StringExtras.h" |
Duncan Sands | b116fac | 2007-07-27 20:02:49 +0000 | [diff] [blame] | 38 | #include "llvm/ParameterAttributes.h" |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 39 | using namespace llvm; |
| 40 | |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 41 | X86TargetLowering::X86TargetLowering(TargetMachine &TM) |
| 42 | : TargetLowering(TM) { |
Evan Cheng | 559806f | 2006-01-27 08:10:46 +0000 | [diff] [blame] | 43 | Subtarget = &TM.getSubtarget<X86Subtarget>(); |
Dale Johannesen | f1fc3a8 | 2007-09-23 14:52:20 +0000 | [diff] [blame] | 44 | X86ScalarSSEf64 = Subtarget->hasSSE2(); |
| 45 | X86ScalarSSEf32 = Subtarget->hasSSE1(); |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 46 | X86StackPtr = Subtarget->is64Bit() ? X86::RSP : X86::ESP; |
Evan Cheng | 559806f | 2006-01-27 08:10:46 +0000 | [diff] [blame] | 47 | |
Anton Korobeynikov | 2365f51 | 2007-07-14 14:06:15 +0000 | [diff] [blame] | 48 | RegInfo = TM.getRegisterInfo(); |
| 49 | |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 50 | // Set up the TargetLowering object. |
| 51 | |
| 52 | // X86 is weird, it always uses i8 for shift amounts and setcc results. |
| 53 | setShiftAmountType(MVT::i8); |
| 54 | setSetCCResultType(MVT::i8); |
| 55 | setSetCCResultContents(ZeroOrOneSetCCResult); |
Evan Cheng | 0b2afbd | 2006-01-25 09:15:17 +0000 | [diff] [blame] | 56 | setSchedulingPreference(SchedulingForRegPressure); |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 57 | setShiftAmountFlavor(Mask); // shl X, 32 == shl X, 0 |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 58 | setStackPointerRegisterToSaveRestore(X86StackPtr); |
Evan Cheng | 714554d | 2006-03-16 21:47:42 +0000 | [diff] [blame] | 59 | |
Anton Korobeynikov | d27a258 | 2006-12-10 23:12:42 +0000 | [diff] [blame] | 60 | if (Subtarget->isTargetDarwin()) { |
Evan Cheng | df57fa0 | 2006-03-17 20:31:41 +0000 | [diff] [blame] | 61 | // Darwin should use _setjmp/_longjmp instead of setjmp/longjmp. |
Anton Korobeynikov | d27a258 | 2006-12-10 23:12:42 +0000 | [diff] [blame] | 62 | setUseUnderscoreSetJmp(false); |
| 63 | setUseUnderscoreLongJmp(false); |
Anton Korobeynikov | 317848f | 2007-01-03 11:43:14 +0000 | [diff] [blame] | 64 | } else if (Subtarget->isTargetMingw()) { |
Anton Korobeynikov | d27a258 | 2006-12-10 23:12:42 +0000 | [diff] [blame] | 65 | // MS runtime is weird: it exports _setjmp, but longjmp! |
| 66 | setUseUnderscoreSetJmp(true); |
| 67 | setUseUnderscoreLongJmp(false); |
| 68 | } else { |
| 69 | setUseUnderscoreSetJmp(true); |
| 70 | setUseUnderscoreLongJmp(true); |
| 71 | } |
| 72 | |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 73 | // Set up the register classes. |
Evan Cheng | 069287d | 2006-05-16 07:21:53 +0000 | [diff] [blame] | 74 | addRegisterClass(MVT::i8, X86::GR8RegisterClass); |
| 75 | addRegisterClass(MVT::i16, X86::GR16RegisterClass); |
| 76 | addRegisterClass(MVT::i32, X86::GR32RegisterClass); |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 77 | if (Subtarget->is64Bit()) |
| 78 | addRegisterClass(MVT::i64, X86::GR64RegisterClass); |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 79 | |
Evan Cheng | c548428 | 2006-10-04 00:56:09 +0000 | [diff] [blame] | 80 | setLoadXAction(ISD::SEXTLOAD, MVT::i1, Expand); |
| 81 | |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 82 | // Promote all UINT_TO_FP to larger SINT_TO_FP's, as X86 doesn't have this |
| 83 | // operation. |
| 84 | setOperationAction(ISD::UINT_TO_FP , MVT::i1 , Promote); |
| 85 | setOperationAction(ISD::UINT_TO_FP , MVT::i8 , Promote); |
| 86 | setOperationAction(ISD::UINT_TO_FP , MVT::i16 , Promote); |
Evan Cheng | 6892f28 | 2006-01-17 02:32:49 +0000 | [diff] [blame] | 87 | |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 88 | if (Subtarget->is64Bit()) { |
| 89 | setOperationAction(ISD::UINT_TO_FP , MVT::i64 , Expand); |
Evan Cheng | 6892f28 | 2006-01-17 02:32:49 +0000 | [diff] [blame] | 90 | setOperationAction(ISD::UINT_TO_FP , MVT::i32 , Promote); |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 91 | } else { |
Dale Johannesen | f1fc3a8 | 2007-09-23 14:52:20 +0000 | [diff] [blame] | 92 | if (X86ScalarSSEf64) |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 93 | // If SSE i64 SINT_TO_FP is not available, expand i32 UINT_TO_FP. |
| 94 | setOperationAction(ISD::UINT_TO_FP , MVT::i32 , Expand); |
| 95 | else |
| 96 | setOperationAction(ISD::UINT_TO_FP , MVT::i32 , Promote); |
| 97 | } |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 98 | |
| 99 | // Promote i1/i8 SINT_TO_FP to larger SINT_TO_FP's, as X86 doesn't have |
| 100 | // this operation. |
| 101 | setOperationAction(ISD::SINT_TO_FP , MVT::i1 , Promote); |
| 102 | setOperationAction(ISD::SINT_TO_FP , MVT::i8 , Promote); |
Nate Begeman | 4c5dcf5 | 2006-02-17 00:03:04 +0000 | [diff] [blame] | 103 | // SSE has no i16 to fp conversion, only i32 |
Dale Johannesen | f1fc3a8 | 2007-09-23 14:52:20 +0000 | [diff] [blame] | 104 | if (X86ScalarSSEf32) { |
Evan Cheng | 02568ff | 2006-01-30 22:13:22 +0000 | [diff] [blame] | 105 | setOperationAction(ISD::SINT_TO_FP , MVT::i16 , Promote); |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 106 | // f32 and f64 cases are Legal, f80 case is not |
| 107 | setOperationAction(ISD::SINT_TO_FP , MVT::i32 , Custom); |
| 108 | } else { |
Evan Cheng | 5298bcc | 2006-02-17 07:01:52 +0000 | [diff] [blame] | 109 | setOperationAction(ISD::SINT_TO_FP , MVT::i16 , Custom); |
| 110 | setOperationAction(ISD::SINT_TO_FP , MVT::i32 , Custom); |
| 111 | } |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 112 | |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 113 | // In 32-bit mode these are custom lowered. In 64-bit mode F32 and F64 |
| 114 | // are Legal, f80 is custom lowered. |
| 115 | setOperationAction(ISD::FP_TO_SINT , MVT::i64 , Custom); |
| 116 | setOperationAction(ISD::SINT_TO_FP , MVT::i64 , Custom); |
Evan Cheng | 6dab053 | 2006-01-30 08:02:57 +0000 | [diff] [blame] | 117 | |
Evan Cheng | 02568ff | 2006-01-30 22:13:22 +0000 | [diff] [blame] | 118 | // Promote i1/i8 FP_TO_SINT to larger FP_TO_SINTS's, as X86 doesn't have |
| 119 | // this operation. |
| 120 | setOperationAction(ISD::FP_TO_SINT , MVT::i1 , Promote); |
| 121 | setOperationAction(ISD::FP_TO_SINT , MVT::i8 , Promote); |
| 122 | |
Dale Johannesen | f1fc3a8 | 2007-09-23 14:52:20 +0000 | [diff] [blame] | 123 | if (X86ScalarSSEf32) { |
Evan Cheng | 02568ff | 2006-01-30 22:13:22 +0000 | [diff] [blame] | 124 | setOperationAction(ISD::FP_TO_SINT , MVT::i16 , Promote); |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 125 | // f32 and f64 cases are Legal, f80 case is not |
| 126 | setOperationAction(ISD::FP_TO_SINT , MVT::i32 , Custom); |
Evan Cheng | 02568ff | 2006-01-30 22:13:22 +0000 | [diff] [blame] | 127 | } else { |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 128 | setOperationAction(ISD::FP_TO_SINT , MVT::i16 , Custom); |
Evan Cheng | 02568ff | 2006-01-30 22:13:22 +0000 | [diff] [blame] | 129 | setOperationAction(ISD::FP_TO_SINT , MVT::i32 , Custom); |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | // Handle FP_TO_UINT by promoting the destination to a larger signed |
| 133 | // conversion. |
| 134 | setOperationAction(ISD::FP_TO_UINT , MVT::i1 , Promote); |
| 135 | setOperationAction(ISD::FP_TO_UINT , MVT::i8 , Promote); |
| 136 | setOperationAction(ISD::FP_TO_UINT , MVT::i16 , Promote); |
| 137 | |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 138 | if (Subtarget->is64Bit()) { |
| 139 | setOperationAction(ISD::FP_TO_UINT , MVT::i64 , Expand); |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 140 | setOperationAction(ISD::FP_TO_UINT , MVT::i32 , Promote); |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 141 | } else { |
Dale Johannesen | f1fc3a8 | 2007-09-23 14:52:20 +0000 | [diff] [blame] | 142 | if (X86ScalarSSEf32 && !Subtarget->hasSSE3()) |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 143 | // Expand FP_TO_UINT into a select. |
| 144 | // FIXME: We would like to use a Custom expander here eventually to do |
| 145 | // the optimal thing for SSE vs. the default expansion in the legalizer. |
| 146 | setOperationAction(ISD::FP_TO_UINT , MVT::i32 , Expand); |
| 147 | else |
| 148 | // With SSE3 we can use fisttpll to convert to a signed i64. |
| 149 | setOperationAction(ISD::FP_TO_UINT , MVT::i32 , Promote); |
| 150 | } |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 151 | |
Chris Lattner | 399610a | 2006-12-05 18:22:22 +0000 | [diff] [blame] | 152 | // TODO: when we have SSE, these could be more efficient, by using movd/movq. |
Dale Johannesen | f1fc3a8 | 2007-09-23 14:52:20 +0000 | [diff] [blame] | 153 | if (!X86ScalarSSEf64) { |
Chris Lattner | f3597a1 | 2006-12-05 18:45:06 +0000 | [diff] [blame] | 154 | setOperationAction(ISD::BIT_CONVERT , MVT::f32 , Expand); |
| 155 | setOperationAction(ISD::BIT_CONVERT , MVT::i32 , Expand); |
| 156 | } |
Chris Lattner | 21f6685 | 2005-12-23 05:15:23 +0000 | [diff] [blame] | 157 | |
Evan Cheng | c35497f | 2006-10-30 08:02:39 +0000 | [diff] [blame] | 158 | setOperationAction(ISD::BR_JT , MVT::Other, Expand); |
Evan Cheng | 5298bcc | 2006-02-17 07:01:52 +0000 | [diff] [blame] | 159 | setOperationAction(ISD::BRCOND , MVT::Other, Custom); |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 160 | setOperationAction(ISD::BR_CC , MVT::Other, Expand); |
| 161 | setOperationAction(ISD::SELECT_CC , MVT::Other, Expand); |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 162 | setOperationAction(ISD::MEMMOVE , MVT::Other, Expand); |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 163 | if (Subtarget->is64Bit()) |
Christopher Lamb | c59e521 | 2007-08-10 21:48:46 +0000 | [diff] [blame] | 164 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i32, Legal); |
| 165 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i16 , Legal); |
| 166 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i8 , Legal); |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 167 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1 , Expand); |
| 168 | setOperationAction(ISD::FP_ROUND_INREG , MVT::f32 , Expand); |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 169 | setOperationAction(ISD::FREM , MVT::f64 , Expand); |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 170 | |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 171 | setOperationAction(ISD::CTPOP , MVT::i8 , Expand); |
| 172 | setOperationAction(ISD::CTTZ , MVT::i8 , Expand); |
| 173 | setOperationAction(ISD::CTLZ , MVT::i8 , Expand); |
| 174 | setOperationAction(ISD::CTPOP , MVT::i16 , Expand); |
| 175 | setOperationAction(ISD::CTTZ , MVT::i16 , Expand); |
| 176 | setOperationAction(ISD::CTLZ , MVT::i16 , Expand); |
| 177 | setOperationAction(ISD::CTPOP , MVT::i32 , Expand); |
| 178 | setOperationAction(ISD::CTTZ , MVT::i32 , Expand); |
| 179 | setOperationAction(ISD::CTLZ , MVT::i32 , Expand); |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 180 | if (Subtarget->is64Bit()) { |
| 181 | setOperationAction(ISD::CTPOP , MVT::i64 , Expand); |
| 182 | setOperationAction(ISD::CTTZ , MVT::i64 , Expand); |
| 183 | setOperationAction(ISD::CTLZ , MVT::i64 , Expand); |
| 184 | } |
| 185 | |
Andrew Lenharth | b873ff3 | 2005-11-20 21:41:10 +0000 | [diff] [blame] | 186 | setOperationAction(ISD::READCYCLECOUNTER , MVT::i64 , Custom); |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 187 | setOperationAction(ISD::BSWAP , MVT::i16 , Expand); |
Nate Begeman | 35ef913 | 2006-01-11 21:21:00 +0000 | [diff] [blame] | 188 | |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 189 | // These should be promoted to a larger select which is supported. |
| 190 | setOperationAction(ISD::SELECT , MVT::i1 , Promote); |
| 191 | setOperationAction(ISD::SELECT , MVT::i8 , Promote); |
Nate Begeman | 4c5dcf5 | 2006-02-17 00:03:04 +0000 | [diff] [blame] | 192 | // X86 wants to expand cmov itself. |
Evan Cheng | 5298bcc | 2006-02-17 07:01:52 +0000 | [diff] [blame] | 193 | setOperationAction(ISD::SELECT , MVT::i16 , Custom); |
| 194 | setOperationAction(ISD::SELECT , MVT::i32 , Custom); |
| 195 | setOperationAction(ISD::SELECT , MVT::f32 , Custom); |
| 196 | setOperationAction(ISD::SELECT , MVT::f64 , Custom); |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 197 | setOperationAction(ISD::SELECT , MVT::f80 , Custom); |
Evan Cheng | 5298bcc | 2006-02-17 07:01:52 +0000 | [diff] [blame] | 198 | setOperationAction(ISD::SETCC , MVT::i8 , Custom); |
| 199 | setOperationAction(ISD::SETCC , MVT::i16 , Custom); |
| 200 | setOperationAction(ISD::SETCC , MVT::i32 , Custom); |
| 201 | setOperationAction(ISD::SETCC , MVT::f32 , Custom); |
| 202 | setOperationAction(ISD::SETCC , MVT::f64 , Custom); |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 203 | setOperationAction(ISD::SETCC , MVT::f80 , Custom); |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 204 | if (Subtarget->is64Bit()) { |
| 205 | setOperationAction(ISD::SELECT , MVT::i64 , Custom); |
| 206 | setOperationAction(ISD::SETCC , MVT::i64 , Custom); |
| 207 | } |
Nate Begeman | 4c5dcf5 | 2006-02-17 00:03:04 +0000 | [diff] [blame] | 208 | // X86 ret instruction may pop stack. |
Evan Cheng | 5298bcc | 2006-02-17 07:01:52 +0000 | [diff] [blame] | 209 | setOperationAction(ISD::RET , MVT::Other, Custom); |
Anton Korobeynikov | 2365f51 | 2007-07-14 14:06:15 +0000 | [diff] [blame] | 210 | if (!Subtarget->is64Bit()) |
| 211 | setOperationAction(ISD::EH_RETURN , MVT::Other, Custom); |
| 212 | |
Nate Begeman | 4c5dcf5 | 2006-02-17 00:03:04 +0000 | [diff] [blame] | 213 | // Darwin ABI issue. |
Evan Cheng | 7ccced6 | 2006-02-18 00:15:05 +0000 | [diff] [blame] | 214 | setOperationAction(ISD::ConstantPool , MVT::i32 , Custom); |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 215 | setOperationAction(ISD::JumpTable , MVT::i32 , Custom); |
Evan Cheng | 5298bcc | 2006-02-17 07:01:52 +0000 | [diff] [blame] | 216 | setOperationAction(ISD::GlobalAddress , MVT::i32 , Custom); |
Lauro Ramos Venancio | b3a0417 | 2007-04-20 21:38:10 +0000 | [diff] [blame] | 217 | setOperationAction(ISD::GlobalTLSAddress, MVT::i32 , Custom); |
Evan Cheng | 020d2e8 | 2006-02-23 20:41:18 +0000 | [diff] [blame] | 218 | setOperationAction(ISD::ExternalSymbol , MVT::i32 , Custom); |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 219 | if (Subtarget->is64Bit()) { |
| 220 | setOperationAction(ISD::ConstantPool , MVT::i64 , Custom); |
| 221 | setOperationAction(ISD::JumpTable , MVT::i64 , Custom); |
| 222 | setOperationAction(ISD::GlobalAddress , MVT::i64 , Custom); |
| 223 | setOperationAction(ISD::ExternalSymbol, MVT::i64 , Custom); |
| 224 | } |
Nate Begeman | 4c5dcf5 | 2006-02-17 00:03:04 +0000 | [diff] [blame] | 225 | // 64-bit addm sub, shl, sra, srl (iff 32-bit x86) |
Evan Cheng | 5298bcc | 2006-02-17 07:01:52 +0000 | [diff] [blame] | 226 | setOperationAction(ISD::SHL_PARTS , MVT::i32 , Custom); |
| 227 | setOperationAction(ISD::SRA_PARTS , MVT::i32 , Custom); |
| 228 | setOperationAction(ISD::SRL_PARTS , MVT::i32 , Custom); |
Nate Begeman | 4c5dcf5 | 2006-02-17 00:03:04 +0000 | [diff] [blame] | 229 | // X86 wants to expand memset / memcpy itself. |
Evan Cheng | 5298bcc | 2006-02-17 07:01:52 +0000 | [diff] [blame] | 230 | setOperationAction(ISD::MEMSET , MVT::Other, Custom); |
| 231 | setOperationAction(ISD::MEMCPY , MVT::Other, Custom); |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 232 | |
Dan Gohman | c3b0b5c | 2007-09-25 15:10:49 +0000 | [diff] [blame^] | 233 | // Use the default ISD::LOCATION expansion. |
Chris Lattner | f73bae1 | 2005-11-29 06:16:21 +0000 | [diff] [blame] | 234 | setOperationAction(ISD::LOCATION, MVT::Other, Expand); |
Evan Cheng | 3c992d2 | 2006-03-07 02:02:57 +0000 | [diff] [blame] | 235 | // FIXME - use subtarget debug flags |
Anton Korobeynikov | ab4022f | 2006-10-31 08:31:24 +0000 | [diff] [blame] | 236 | if (!Subtarget->isTargetDarwin() && |
| 237 | !Subtarget->isTargetELF() && |
Anton Korobeynikov | 317848f | 2007-01-03 11:43:14 +0000 | [diff] [blame] | 238 | !Subtarget->isTargetCygMing()) |
Jim Laskey | 1ee2925 | 2007-01-26 14:34:52 +0000 | [diff] [blame] | 239 | setOperationAction(ISD::LABEL, MVT::Other, Expand); |
Chris Lattner | f73bae1 | 2005-11-29 06:16:21 +0000 | [diff] [blame] | 240 | |
Anton Korobeynikov | ce3b465 | 2007-05-02 19:53:33 +0000 | [diff] [blame] | 241 | setOperationAction(ISD::EXCEPTIONADDR, MVT::i64, Expand); |
| 242 | setOperationAction(ISD::EHSELECTION, MVT::i64, Expand); |
| 243 | setOperationAction(ISD::EXCEPTIONADDR, MVT::i32, Expand); |
| 244 | setOperationAction(ISD::EHSELECTION, MVT::i32, Expand); |
| 245 | if (Subtarget->is64Bit()) { |
| 246 | // FIXME: Verify |
| 247 | setExceptionPointerRegister(X86::RAX); |
| 248 | setExceptionSelectorRegister(X86::RDX); |
| 249 | } else { |
| 250 | setExceptionPointerRegister(X86::EAX); |
| 251 | setExceptionSelectorRegister(X86::EDX); |
| 252 | } |
Anton Korobeynikov | 3825262 | 2007-09-03 00:36:06 +0000 | [diff] [blame] | 253 | setOperationAction(ISD::FRAME_TO_ARGS_OFFSET, MVT::i32, Custom); |
Anton Korobeynikov | ce3b465 | 2007-05-02 19:53:33 +0000 | [diff] [blame] | 254 | |
Duncan Sands | f7331b3 | 2007-09-11 14:10:23 +0000 | [diff] [blame] | 255 | setOperationAction(ISD::TRAMPOLINE, MVT::Other, Custom); |
Duncan Sands | b116fac | 2007-07-27 20:02:49 +0000 | [diff] [blame] | 256 | |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 257 | // VASTART needs to be custom lowered to use the VarArgsFrameIndex |
| 258 | setOperationAction(ISD::VASTART , MVT::Other, Custom); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 259 | setOperationAction(ISD::VAARG , MVT::Other, Expand); |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 260 | setOperationAction(ISD::VAEND , MVT::Other, Expand); |
Evan Cheng | ae64219 | 2007-03-02 23:16:35 +0000 | [diff] [blame] | 261 | if (Subtarget->is64Bit()) |
| 262 | setOperationAction(ISD::VACOPY , MVT::Other, Custom); |
| 263 | else |
| 264 | setOperationAction(ISD::VACOPY , MVT::Other, Expand); |
| 265 | |
Anton Korobeynikov | 12c49af | 2006-11-21 00:01:06 +0000 | [diff] [blame] | 266 | setOperationAction(ISD::STACKSAVE, MVT::Other, Expand); |
Chris Lattner | e112552 | 2006-01-15 09:00:21 +0000 | [diff] [blame] | 267 | setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand); |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 268 | if (Subtarget->is64Bit()) |
| 269 | setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i64, Expand); |
Anton Korobeynikov | 57fc00d | 2007-04-17 09:20:00 +0000 | [diff] [blame] | 270 | if (Subtarget->isTargetCygMing()) |
| 271 | setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32, Custom); |
| 272 | else |
| 273 | setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32, Expand); |
Chris Lattner | b99329e | 2006-01-13 02:42:53 +0000 | [diff] [blame] | 274 | |
Dale Johannesen | f1fc3a8 | 2007-09-23 14:52:20 +0000 | [diff] [blame] | 275 | if (X86ScalarSSEf64) { |
| 276 | // f32 and f64 use SSE. |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 277 | // Set up the FP register classes. |
Evan Cheng | 5ee4ccc | 2006-01-12 08:27:59 +0000 | [diff] [blame] | 278 | addRegisterClass(MVT::f32, X86::FR32RegisterClass); |
| 279 | addRegisterClass(MVT::f64, X86::FR64RegisterClass); |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 280 | |
Evan Cheng | 223547a | 2006-01-31 22:28:30 +0000 | [diff] [blame] | 281 | // Use ANDPD to simulate FABS. |
| 282 | setOperationAction(ISD::FABS , MVT::f64, Custom); |
| 283 | setOperationAction(ISD::FABS , MVT::f32, Custom); |
| 284 | |
| 285 | // Use XORP to simulate FNEG. |
| 286 | setOperationAction(ISD::FNEG , MVT::f64, Custom); |
| 287 | setOperationAction(ISD::FNEG , MVT::f32, Custom); |
| 288 | |
Evan Cheng | 68c47cb | 2007-01-05 07:55:56 +0000 | [diff] [blame] | 289 | // Use ANDPD and ORPD to simulate FCOPYSIGN. |
| 290 | setOperationAction(ISD::FCOPYSIGN, MVT::f64, Custom); |
| 291 | setOperationAction(ISD::FCOPYSIGN, MVT::f32, Custom); |
| 292 | |
Evan Cheng | d25e9e8 | 2006-02-02 00:28:23 +0000 | [diff] [blame] | 293 | // We don't support sin/cos/fmod |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 294 | setOperationAction(ISD::FSIN , MVT::f64, Expand); |
| 295 | setOperationAction(ISD::FCOS , MVT::f64, Expand); |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 296 | setOperationAction(ISD::FREM , MVT::f64, Expand); |
| 297 | setOperationAction(ISD::FSIN , MVT::f32, Expand); |
| 298 | setOperationAction(ISD::FCOS , MVT::f32, Expand); |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 299 | setOperationAction(ISD::FREM , MVT::f32, Expand); |
| 300 | |
Chris Lattner | a54aa94 | 2006-01-29 06:26:08 +0000 | [diff] [blame] | 301 | // Expand FP immediates into loads from the stack, except for the special |
| 302 | // cases we handle. |
| 303 | setOperationAction(ISD::ConstantFP, MVT::f64, Expand); |
| 304 | setOperationAction(ISD::ConstantFP, MVT::f32, Expand); |
Dale Johannesen | f1fc3a8 | 2007-09-23 14:52:20 +0000 | [diff] [blame] | 305 | addLegalFPImmediate(APFloat(+0.0)); // xorpd |
| 306 | addLegalFPImmediate(APFloat(+0.0f)); // xorps |
Dale Johannesen | 5411a39 | 2007-08-09 01:04:01 +0000 | [diff] [blame] | 307 | |
| 308 | // Conversions to long double (in X87) go through memory. |
| 309 | setConvertAction(MVT::f32, MVT::f80, Expand); |
| 310 | setConvertAction(MVT::f64, MVT::f80, Expand); |
| 311 | |
| 312 | // Conversions from long double (in X87) go through memory. |
| 313 | setConvertAction(MVT::f80, MVT::f32, Expand); |
| 314 | setConvertAction(MVT::f80, MVT::f64, Expand); |
Dale Johannesen | f1fc3a8 | 2007-09-23 14:52:20 +0000 | [diff] [blame] | 315 | } else if (X86ScalarSSEf32) { |
| 316 | // Use SSE for f32, x87 for f64. |
| 317 | // Set up the FP register classes. |
| 318 | addRegisterClass(MVT::f32, X86::FR32RegisterClass); |
| 319 | addRegisterClass(MVT::f64, X86::RFP64RegisterClass); |
| 320 | |
| 321 | // Use ANDPS to simulate FABS. |
| 322 | setOperationAction(ISD::FABS , MVT::f32, Custom); |
| 323 | |
| 324 | // Use XORP to simulate FNEG. |
| 325 | setOperationAction(ISD::FNEG , MVT::f32, Custom); |
| 326 | |
| 327 | setOperationAction(ISD::UNDEF, MVT::f64, Expand); |
| 328 | |
| 329 | // Use ANDPS and ORPS to simulate FCOPYSIGN. |
| 330 | setOperationAction(ISD::FCOPYSIGN, MVT::f64, Expand); |
| 331 | setOperationAction(ISD::FCOPYSIGN, MVT::f32, Custom); |
| 332 | |
| 333 | // We don't support sin/cos/fmod |
| 334 | setOperationAction(ISD::FSIN , MVT::f32, Expand); |
| 335 | setOperationAction(ISD::FCOS , MVT::f32, Expand); |
| 336 | setOperationAction(ISD::FREM , MVT::f32, Expand); |
| 337 | |
| 338 | // Expand FP immediates into loads from the stack, except for the special |
| 339 | // cases we handle. |
| 340 | setOperationAction(ISD::ConstantFP, MVT::f64, Expand); |
| 341 | setOperationAction(ISD::ConstantFP, MVT::f32, Expand); |
| 342 | addLegalFPImmediate(APFloat(+0.0f)); // xorps |
| 343 | addLegalFPImmediate(APFloat(+0.0)); // FLD0 |
| 344 | addLegalFPImmediate(APFloat(+1.0)); // FLD1 |
| 345 | addLegalFPImmediate(APFloat(-0.0)); // FLD0/FCHS |
| 346 | addLegalFPImmediate(APFloat(-1.0)); // FLD1/FCHS |
| 347 | |
| 348 | // SSE->x87 conversions go through memory. |
| 349 | setConvertAction(MVT::f32, MVT::f64, Expand); |
| 350 | setConvertAction(MVT::f32, MVT::f80, Expand); |
| 351 | |
| 352 | // x87->SSE truncations need to go through memory. |
| 353 | setConvertAction(MVT::f80, MVT::f32, Expand); |
| 354 | setConvertAction(MVT::f64, MVT::f32, Expand); |
| 355 | // And x87->x87 truncations also. |
| 356 | setConvertAction(MVT::f80, MVT::f64, Expand); |
| 357 | |
| 358 | if (!UnsafeFPMath) { |
| 359 | setOperationAction(ISD::FSIN , MVT::f64 , Expand); |
| 360 | setOperationAction(ISD::FCOS , MVT::f64 , Expand); |
| 361 | } |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 362 | } else { |
Dale Johannesen | f1fc3a8 | 2007-09-23 14:52:20 +0000 | [diff] [blame] | 363 | // f32 and f64 in x87. |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 364 | // Set up the FP register classes. |
Dale Johannesen | 849f214 | 2007-07-03 00:53:03 +0000 | [diff] [blame] | 365 | addRegisterClass(MVT::f64, X86::RFP64RegisterClass); |
| 366 | addRegisterClass(MVT::f32, X86::RFP32RegisterClass); |
Anton Korobeynikov | 12c49af | 2006-11-21 00:01:06 +0000 | [diff] [blame] | 367 | |
Evan Cheng | 68c47cb | 2007-01-05 07:55:56 +0000 | [diff] [blame] | 368 | setOperationAction(ISD::UNDEF, MVT::f64, Expand); |
Dale Johannesen | 849f214 | 2007-07-03 00:53:03 +0000 | [diff] [blame] | 369 | setOperationAction(ISD::UNDEF, MVT::f32, Expand); |
Evan Cheng | 68c47cb | 2007-01-05 07:55:56 +0000 | [diff] [blame] | 370 | setOperationAction(ISD::FCOPYSIGN, MVT::f64, Expand); |
| 371 | setOperationAction(ISD::FCOPYSIGN, MVT::f32, Expand); |
Dale Johannesen | 5411a39 | 2007-08-09 01:04:01 +0000 | [diff] [blame] | 372 | |
| 373 | // Floating truncations need to go through memory. |
| 374 | setConvertAction(MVT::f80, MVT::f32, Expand); |
| 375 | setConvertAction(MVT::f64, MVT::f32, Expand); |
| 376 | setConvertAction(MVT::f80, MVT::f64, Expand); |
Anton Korobeynikov | 12c49af | 2006-11-21 00:01:06 +0000 | [diff] [blame] | 377 | |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 378 | if (!UnsafeFPMath) { |
| 379 | setOperationAction(ISD::FSIN , MVT::f64 , Expand); |
| 380 | setOperationAction(ISD::FCOS , MVT::f64 , Expand); |
| 381 | } |
| 382 | |
Chris Lattner | a54aa94 | 2006-01-29 06:26:08 +0000 | [diff] [blame] | 383 | setOperationAction(ISD::ConstantFP, MVT::f64, Expand); |
Dale Johannesen | 849f214 | 2007-07-03 00:53:03 +0000 | [diff] [blame] | 384 | setOperationAction(ISD::ConstantFP, MVT::f32, Expand); |
Dale Johannesen | f04afdb | 2007-08-30 00:23:21 +0000 | [diff] [blame] | 385 | addLegalFPImmediate(APFloat(+0.0)); // FLD0 |
| 386 | addLegalFPImmediate(APFloat(+1.0)); // FLD1 |
| 387 | addLegalFPImmediate(APFloat(-0.0)); // FLD0/FCHS |
| 388 | addLegalFPImmediate(APFloat(-1.0)); // FLD1/FCHS |
Dale Johannesen | f1fc3a8 | 2007-09-23 14:52:20 +0000 | [diff] [blame] | 389 | addLegalFPImmediate(APFloat(+0.0f)); // FLD0 |
| 390 | addLegalFPImmediate(APFloat(+1.0f)); // FLD1 |
| 391 | addLegalFPImmediate(APFloat(-0.0f)); // FLD0/FCHS |
| 392 | addLegalFPImmediate(APFloat(-1.0f)); // FLD1/FCHS |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 393 | } |
Evan Cheng | 470a6ad | 2006-02-22 02:26:30 +0000 | [diff] [blame] | 394 | |
Dale Johannesen | 59a5873 | 2007-08-05 18:49:15 +0000 | [diff] [blame] | 395 | // Long double always uses X87. |
| 396 | addRegisterClass(MVT::f80, X86::RFP80RegisterClass); |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 397 | setOperationAction(ISD::UNDEF, MVT::f80, Expand); |
| 398 | setOperationAction(ISD::FCOPYSIGN, MVT::f80, Expand); |
| 399 | setOperationAction(ISD::ConstantFP, MVT::f80, Expand); |
Dale Johannesen | 59a5873 | 2007-08-05 18:49:15 +0000 | [diff] [blame] | 400 | |
Evan Cheng | d30bf01 | 2006-03-01 01:11:20 +0000 | [diff] [blame] | 401 | // First set operation action for all vector types to expand. Then we |
| 402 | // will selectively turn on ones that can be effectively codegen'd. |
Dan Gohman | fa0f77d | 2007-05-18 18:44:07 +0000 | [diff] [blame] | 403 | for (unsigned VT = (unsigned)MVT::FIRST_VECTOR_VALUETYPE; |
| 404 | VT <= (unsigned)MVT::LAST_VECTOR_VALUETYPE; ++VT) { |
Evan Cheng | d30bf01 | 2006-03-01 01:11:20 +0000 | [diff] [blame] | 405 | setOperationAction(ISD::ADD , (MVT::ValueType)VT, Expand); |
| 406 | setOperationAction(ISD::SUB , (MVT::ValueType)VT, Expand); |
Evan Cheng | 6bdb3f6 | 2006-10-27 18:49:08 +0000 | [diff] [blame] | 407 | setOperationAction(ISD::FADD, (MVT::ValueType)VT, Expand); |
Evan Cheng | a72cb0e | 2007-06-29 00:18:15 +0000 | [diff] [blame] | 408 | setOperationAction(ISD::FNEG, (MVT::ValueType)VT, Expand); |
Evan Cheng | 6bdb3f6 | 2006-10-27 18:49:08 +0000 | [diff] [blame] | 409 | setOperationAction(ISD::FSUB, (MVT::ValueType)VT, Expand); |
Evan Cheng | d30bf01 | 2006-03-01 01:11:20 +0000 | [diff] [blame] | 410 | setOperationAction(ISD::MUL , (MVT::ValueType)VT, Expand); |
Evan Cheng | 6bdb3f6 | 2006-10-27 18:49:08 +0000 | [diff] [blame] | 411 | setOperationAction(ISD::FMUL, (MVT::ValueType)VT, Expand); |
| 412 | setOperationAction(ISD::SDIV, (MVT::ValueType)VT, Expand); |
| 413 | setOperationAction(ISD::UDIV, (MVT::ValueType)VT, Expand); |
| 414 | setOperationAction(ISD::FDIV, (MVT::ValueType)VT, Expand); |
| 415 | setOperationAction(ISD::SREM, (MVT::ValueType)VT, Expand); |
| 416 | setOperationAction(ISD::UREM, (MVT::ValueType)VT, Expand); |
Evan Cheng | d30bf01 | 2006-03-01 01:11:20 +0000 | [diff] [blame] | 417 | setOperationAction(ISD::LOAD, (MVT::ValueType)VT, Expand); |
Evan Cheng | b067a1e | 2006-03-31 19:22:53 +0000 | [diff] [blame] | 418 | setOperationAction(ISD::VECTOR_SHUFFLE, (MVT::ValueType)VT, Expand); |
Chris Lattner | 9b3bd46 | 2006-03-21 20:51:05 +0000 | [diff] [blame] | 419 | setOperationAction(ISD::EXTRACT_VECTOR_ELT, (MVT::ValueType)VT, Expand); |
Evan Cheng | b067a1e | 2006-03-31 19:22:53 +0000 | [diff] [blame] | 420 | setOperationAction(ISD::INSERT_VECTOR_ELT, (MVT::ValueType)VT, Expand); |
Dan Gohman | 2038252 | 2007-07-10 00:05:58 +0000 | [diff] [blame] | 421 | setOperationAction(ISD::FABS, (MVT::ValueType)VT, Expand); |
| 422 | setOperationAction(ISD::FSIN, (MVT::ValueType)VT, Expand); |
| 423 | setOperationAction(ISD::FCOS, (MVT::ValueType)VT, Expand); |
| 424 | setOperationAction(ISD::FREM, (MVT::ValueType)VT, Expand); |
| 425 | setOperationAction(ISD::FPOWI, (MVT::ValueType)VT, Expand); |
| 426 | setOperationAction(ISD::FSQRT, (MVT::ValueType)VT, Expand); |
| 427 | setOperationAction(ISD::FCOPYSIGN, (MVT::ValueType)VT, Expand); |
Evan Cheng | d30bf01 | 2006-03-01 01:11:20 +0000 | [diff] [blame] | 428 | } |
| 429 | |
Evan Cheng | a88973f | 2006-03-22 19:22:18 +0000 | [diff] [blame] | 430 | if (Subtarget->hasMMX()) { |
Evan Cheng | 470a6ad | 2006-02-22 02:26:30 +0000 | [diff] [blame] | 431 | addRegisterClass(MVT::v8i8, X86::VR64RegisterClass); |
| 432 | addRegisterClass(MVT::v4i16, X86::VR64RegisterClass); |
| 433 | addRegisterClass(MVT::v2i32, X86::VR64RegisterClass); |
Bill Wendling | eebc8a1 | 2007-03-26 07:53:08 +0000 | [diff] [blame] | 434 | addRegisterClass(MVT::v1i64, X86::VR64RegisterClass); |
Evan Cheng | 470a6ad | 2006-02-22 02:26:30 +0000 | [diff] [blame] | 435 | |
Evan Cheng | d30bf01 | 2006-03-01 01:11:20 +0000 | [diff] [blame] | 436 | // FIXME: add MMX packed arithmetics |
Bill Wendling | bc9bffa | 2007-03-07 05:43:18 +0000 | [diff] [blame] | 437 | |
Bill Wendling | 2f88dcd | 2007-03-08 22:09:11 +0000 | [diff] [blame] | 438 | setOperationAction(ISD::ADD, MVT::v8i8, Legal); |
| 439 | setOperationAction(ISD::ADD, MVT::v4i16, Legal); |
| 440 | setOperationAction(ISD::ADD, MVT::v2i32, Legal); |
Chris Lattner | 6c284d7 | 2007-04-12 04:14:49 +0000 | [diff] [blame] | 441 | setOperationAction(ISD::ADD, MVT::v1i64, Legal); |
Bill Wendling | 2f88dcd | 2007-03-08 22:09:11 +0000 | [diff] [blame] | 442 | |
Bill Wendling | c1fb047 | 2007-03-10 09:57:05 +0000 | [diff] [blame] | 443 | setOperationAction(ISD::SUB, MVT::v8i8, Legal); |
| 444 | setOperationAction(ISD::SUB, MVT::v4i16, Legal); |
| 445 | setOperationAction(ISD::SUB, MVT::v2i32, Legal); |
| 446 | |
Bill Wendling | 74027e9 | 2007-03-15 21:24:36 +0000 | [diff] [blame] | 447 | setOperationAction(ISD::MULHS, MVT::v4i16, Legal); |
| 448 | setOperationAction(ISD::MUL, MVT::v4i16, Legal); |
| 449 | |
Bill Wendling | 1b7a81d | 2007-03-16 09:44:46 +0000 | [diff] [blame] | 450 | setOperationAction(ISD::AND, MVT::v8i8, Promote); |
Bill Wendling | ab5b49d | 2007-03-26 08:03:33 +0000 | [diff] [blame] | 451 | AddPromotedToType (ISD::AND, MVT::v8i8, MVT::v1i64); |
Bill Wendling | 1b7a81d | 2007-03-16 09:44:46 +0000 | [diff] [blame] | 452 | setOperationAction(ISD::AND, MVT::v4i16, Promote); |
Bill Wendling | ab5b49d | 2007-03-26 08:03:33 +0000 | [diff] [blame] | 453 | AddPromotedToType (ISD::AND, MVT::v4i16, MVT::v1i64); |
| 454 | setOperationAction(ISD::AND, MVT::v2i32, Promote); |
| 455 | AddPromotedToType (ISD::AND, MVT::v2i32, MVT::v1i64); |
| 456 | setOperationAction(ISD::AND, MVT::v1i64, Legal); |
Bill Wendling | 1b7a81d | 2007-03-16 09:44:46 +0000 | [diff] [blame] | 457 | |
| 458 | setOperationAction(ISD::OR, MVT::v8i8, Promote); |
Bill Wendling | ab5b49d | 2007-03-26 08:03:33 +0000 | [diff] [blame] | 459 | AddPromotedToType (ISD::OR, MVT::v8i8, MVT::v1i64); |
Bill Wendling | 1b7a81d | 2007-03-16 09:44:46 +0000 | [diff] [blame] | 460 | setOperationAction(ISD::OR, MVT::v4i16, Promote); |
Bill Wendling | ab5b49d | 2007-03-26 08:03:33 +0000 | [diff] [blame] | 461 | AddPromotedToType (ISD::OR, MVT::v4i16, MVT::v1i64); |
| 462 | setOperationAction(ISD::OR, MVT::v2i32, Promote); |
| 463 | AddPromotedToType (ISD::OR, MVT::v2i32, MVT::v1i64); |
| 464 | setOperationAction(ISD::OR, MVT::v1i64, Legal); |
Bill Wendling | 1b7a81d | 2007-03-16 09:44:46 +0000 | [diff] [blame] | 465 | |
| 466 | setOperationAction(ISD::XOR, MVT::v8i8, Promote); |
Bill Wendling | ab5b49d | 2007-03-26 08:03:33 +0000 | [diff] [blame] | 467 | AddPromotedToType (ISD::XOR, MVT::v8i8, MVT::v1i64); |
Bill Wendling | 1b7a81d | 2007-03-16 09:44:46 +0000 | [diff] [blame] | 468 | setOperationAction(ISD::XOR, MVT::v4i16, Promote); |
Bill Wendling | ab5b49d | 2007-03-26 08:03:33 +0000 | [diff] [blame] | 469 | AddPromotedToType (ISD::XOR, MVT::v4i16, MVT::v1i64); |
| 470 | setOperationAction(ISD::XOR, MVT::v2i32, Promote); |
| 471 | AddPromotedToType (ISD::XOR, MVT::v2i32, MVT::v1i64); |
| 472 | setOperationAction(ISD::XOR, MVT::v1i64, Legal); |
Bill Wendling | 1b7a81d | 2007-03-16 09:44:46 +0000 | [diff] [blame] | 473 | |
Bill Wendling | 2f88dcd | 2007-03-08 22:09:11 +0000 | [diff] [blame] | 474 | setOperationAction(ISD::LOAD, MVT::v8i8, Promote); |
Bill Wendling | eebc8a1 | 2007-03-26 07:53:08 +0000 | [diff] [blame] | 475 | AddPromotedToType (ISD::LOAD, MVT::v8i8, MVT::v1i64); |
Bill Wendling | 2f88dcd | 2007-03-08 22:09:11 +0000 | [diff] [blame] | 476 | setOperationAction(ISD::LOAD, MVT::v4i16, Promote); |
Bill Wendling | eebc8a1 | 2007-03-26 07:53:08 +0000 | [diff] [blame] | 477 | AddPromotedToType (ISD::LOAD, MVT::v4i16, MVT::v1i64); |
| 478 | setOperationAction(ISD::LOAD, MVT::v2i32, Promote); |
| 479 | AddPromotedToType (ISD::LOAD, MVT::v2i32, MVT::v1i64); |
| 480 | setOperationAction(ISD::LOAD, MVT::v1i64, Legal); |
Bill Wendling | 2f88dcd | 2007-03-08 22:09:11 +0000 | [diff] [blame] | 481 | |
Bill Wendling | ccc44ad | 2007-03-27 20:22:40 +0000 | [diff] [blame] | 482 | setOperationAction(ISD::BUILD_VECTOR, MVT::v8i8, Custom); |
| 483 | setOperationAction(ISD::BUILD_VECTOR, MVT::v4i16, Custom); |
| 484 | setOperationAction(ISD::BUILD_VECTOR, MVT::v2i32, Custom); |
| 485 | setOperationAction(ISD::BUILD_VECTOR, MVT::v1i64, Custom); |
Bill Wendling | a348c56 | 2007-03-22 18:42:45 +0000 | [diff] [blame] | 486 | |
| 487 | setOperationAction(ISD::VECTOR_SHUFFLE, MVT::v8i8, Custom); |
| 488 | setOperationAction(ISD::VECTOR_SHUFFLE, MVT::v4i16, Custom); |
| 489 | setOperationAction(ISD::VECTOR_SHUFFLE, MVT::v2i32, Custom); |
Bill Wendling | ccc44ad | 2007-03-27 20:22:40 +0000 | [diff] [blame] | 490 | setOperationAction(ISD::VECTOR_SHUFFLE, MVT::v1i64, Custom); |
Bill Wendling | 826f36f | 2007-03-28 00:57:11 +0000 | [diff] [blame] | 491 | |
| 492 | setOperationAction(ISD::SCALAR_TO_VECTOR, MVT::v8i8, Custom); |
| 493 | setOperationAction(ISD::SCALAR_TO_VECTOR, MVT::v4i16, Custom); |
Bill Wendling | 2f9bb1a | 2007-04-24 21:16:55 +0000 | [diff] [blame] | 494 | setOperationAction(ISD::SCALAR_TO_VECTOR, MVT::v2i32, Custom); |
| 495 | setOperationAction(ISD::SCALAR_TO_VECTOR, MVT::v1i64, Custom); |
Evan Cheng | 470a6ad | 2006-02-22 02:26:30 +0000 | [diff] [blame] | 496 | } |
| 497 | |
Evan Cheng | a88973f | 2006-03-22 19:22:18 +0000 | [diff] [blame] | 498 | if (Subtarget->hasSSE1()) { |
Evan Cheng | 470a6ad | 2006-02-22 02:26:30 +0000 | [diff] [blame] | 499 | addRegisterClass(MVT::v4f32, X86::VR128RegisterClass); |
| 500 | |
Evan Cheng | 6bdb3f6 | 2006-10-27 18:49:08 +0000 | [diff] [blame] | 501 | setOperationAction(ISD::FADD, MVT::v4f32, Legal); |
| 502 | setOperationAction(ISD::FSUB, MVT::v4f32, Legal); |
| 503 | setOperationAction(ISD::FMUL, MVT::v4f32, Legal); |
| 504 | setOperationAction(ISD::FDIV, MVT::v4f32, Legal); |
Dan Gohman | 2038252 | 2007-07-10 00:05:58 +0000 | [diff] [blame] | 505 | setOperationAction(ISD::FSQRT, MVT::v4f32, Legal); |
| 506 | setOperationAction(ISD::FNEG, MVT::v4f32, Custom); |
Evan Cheng | f7c378e | 2006-04-10 07:23:14 +0000 | [diff] [blame] | 507 | setOperationAction(ISD::LOAD, MVT::v4f32, Legal); |
| 508 | setOperationAction(ISD::BUILD_VECTOR, MVT::v4f32, Custom); |
| 509 | setOperationAction(ISD::VECTOR_SHUFFLE, MVT::v4f32, Custom); |
Evan Cheng | 11e15b3 | 2006-04-03 20:53:28 +0000 | [diff] [blame] | 510 | setOperationAction(ISD::EXTRACT_VECTOR_ELT, MVT::v4f32, Custom); |
Evan Cheng | f7c378e | 2006-04-10 07:23:14 +0000 | [diff] [blame] | 511 | setOperationAction(ISD::SELECT, MVT::v4f32, Custom); |
Evan Cheng | 470a6ad | 2006-02-22 02:26:30 +0000 | [diff] [blame] | 512 | } |
| 513 | |
Evan Cheng | a88973f | 2006-03-22 19:22:18 +0000 | [diff] [blame] | 514 | if (Subtarget->hasSSE2()) { |
Evan Cheng | 470a6ad | 2006-02-22 02:26:30 +0000 | [diff] [blame] | 515 | addRegisterClass(MVT::v2f64, X86::VR128RegisterClass); |
| 516 | addRegisterClass(MVT::v16i8, X86::VR128RegisterClass); |
| 517 | addRegisterClass(MVT::v8i16, X86::VR128RegisterClass); |
| 518 | addRegisterClass(MVT::v4i32, X86::VR128RegisterClass); |
| 519 | addRegisterClass(MVT::v2i64, X86::VR128RegisterClass); |
| 520 | |
Evan Cheng | f7c378e | 2006-04-10 07:23:14 +0000 | [diff] [blame] | 521 | setOperationAction(ISD::ADD, MVT::v16i8, Legal); |
| 522 | setOperationAction(ISD::ADD, MVT::v8i16, Legal); |
| 523 | setOperationAction(ISD::ADD, MVT::v4i32, Legal); |
Evan Cheng | 37e8856 | 2007-03-12 22:58:52 +0000 | [diff] [blame] | 524 | setOperationAction(ISD::ADD, MVT::v2i64, Legal); |
Evan Cheng | f7c378e | 2006-04-10 07:23:14 +0000 | [diff] [blame] | 525 | setOperationAction(ISD::SUB, MVT::v16i8, Legal); |
| 526 | setOperationAction(ISD::SUB, MVT::v8i16, Legal); |
| 527 | setOperationAction(ISD::SUB, MVT::v4i32, Legal); |
Evan Cheng | 37e8856 | 2007-03-12 22:58:52 +0000 | [diff] [blame] | 528 | setOperationAction(ISD::SUB, MVT::v2i64, Legal); |
Evan Cheng | f998984 | 2006-04-13 05:10:25 +0000 | [diff] [blame] | 529 | setOperationAction(ISD::MUL, MVT::v8i16, Legal); |
Evan Cheng | 6bdb3f6 | 2006-10-27 18:49:08 +0000 | [diff] [blame] | 530 | setOperationAction(ISD::FADD, MVT::v2f64, Legal); |
| 531 | setOperationAction(ISD::FSUB, MVT::v2f64, Legal); |
| 532 | setOperationAction(ISD::FMUL, MVT::v2f64, Legal); |
| 533 | setOperationAction(ISD::FDIV, MVT::v2f64, Legal); |
Dan Gohman | 2038252 | 2007-07-10 00:05:58 +0000 | [diff] [blame] | 534 | setOperationAction(ISD::FSQRT, MVT::v2f64, Legal); |
| 535 | setOperationAction(ISD::FNEG, MVT::v2f64, Custom); |
Evan Cheng | 2c3ae37 | 2006-04-12 21:21:57 +0000 | [diff] [blame] | 536 | |
Evan Cheng | f7c378e | 2006-04-10 07:23:14 +0000 | [diff] [blame] | 537 | setOperationAction(ISD::SCALAR_TO_VECTOR, MVT::v16i8, Custom); |
| 538 | setOperationAction(ISD::SCALAR_TO_VECTOR, MVT::v8i16, Custom); |
Evan Cheng | b067a1e | 2006-03-31 19:22:53 +0000 | [diff] [blame] | 539 | setOperationAction(ISD::INSERT_VECTOR_ELT, MVT::v8i16, Custom); |
Evan Cheng | 5edb8d2 | 2006-04-17 22:04:06 +0000 | [diff] [blame] | 540 | setOperationAction(ISD::INSERT_VECTOR_ELT, MVT::v4i32, Custom); |
| 541 | // Implement v4f32 insert_vector_elt in terms of SSE2 v8i16 ones. |
| 542 | setOperationAction(ISD::INSERT_VECTOR_ELT, MVT::v4f32, Custom); |
Evan Cheng | f7c378e | 2006-04-10 07:23:14 +0000 | [diff] [blame] | 543 | |
Evan Cheng | 2c3ae37 | 2006-04-12 21:21:57 +0000 | [diff] [blame] | 544 | // Custom lower build_vector, vector_shuffle, and extract_vector_elt. |
| 545 | for (unsigned VT = (unsigned)MVT::v16i8; VT != (unsigned)MVT::v2i64; VT++) { |
| 546 | setOperationAction(ISD::BUILD_VECTOR, (MVT::ValueType)VT, Custom); |
| 547 | setOperationAction(ISD::VECTOR_SHUFFLE, (MVT::ValueType)VT, Custom); |
| 548 | setOperationAction(ISD::EXTRACT_VECTOR_ELT, (MVT::ValueType)VT, Custom); |
| 549 | } |
| 550 | setOperationAction(ISD::BUILD_VECTOR, MVT::v2f64, Custom); |
| 551 | setOperationAction(ISD::BUILD_VECTOR, MVT::v2i64, Custom); |
| 552 | setOperationAction(ISD::VECTOR_SHUFFLE, MVT::v2f64, Custom); |
| 553 | setOperationAction(ISD::VECTOR_SHUFFLE, MVT::v2i64, Custom); |
| 554 | setOperationAction(ISD::EXTRACT_VECTOR_ELT, MVT::v2f64, Custom); |
| 555 | setOperationAction(ISD::EXTRACT_VECTOR_ELT, MVT::v2i64, Custom); |
| 556 | |
Anton Korobeynikov | 12c49af | 2006-11-21 00:01:06 +0000 | [diff] [blame] | 557 | // Promote v16i8, v8i16, v4i32 load, select, and, or, xor to v2i64. |
Evan Cheng | 2c3ae37 | 2006-04-12 21:21:57 +0000 | [diff] [blame] | 558 | for (unsigned VT = (unsigned)MVT::v16i8; VT != (unsigned)MVT::v2i64; VT++) { |
| 559 | setOperationAction(ISD::AND, (MVT::ValueType)VT, Promote); |
| 560 | AddPromotedToType (ISD::AND, (MVT::ValueType)VT, MVT::v2i64); |
| 561 | setOperationAction(ISD::OR, (MVT::ValueType)VT, Promote); |
| 562 | AddPromotedToType (ISD::OR, (MVT::ValueType)VT, MVT::v2i64); |
| 563 | setOperationAction(ISD::XOR, (MVT::ValueType)VT, Promote); |
| 564 | AddPromotedToType (ISD::XOR, (MVT::ValueType)VT, MVT::v2i64); |
Evan Cheng | 91b740d | 2006-04-12 17:12:36 +0000 | [diff] [blame] | 565 | setOperationAction(ISD::LOAD, (MVT::ValueType)VT, Promote); |
| 566 | AddPromotedToType (ISD::LOAD, (MVT::ValueType)VT, MVT::v2i64); |
Evan Cheng | 2c3ae37 | 2006-04-12 21:21:57 +0000 | [diff] [blame] | 567 | setOperationAction(ISD::SELECT, (MVT::ValueType)VT, Promote); |
| 568 | AddPromotedToType (ISD::SELECT, (MVT::ValueType)VT, MVT::v2i64); |
Evan Cheng | f7c378e | 2006-04-10 07:23:14 +0000 | [diff] [blame] | 569 | } |
Evan Cheng | 2c3ae37 | 2006-04-12 21:21:57 +0000 | [diff] [blame] | 570 | |
| 571 | // Custom lower v2i64 and v2f64 selects. |
| 572 | setOperationAction(ISD::LOAD, MVT::v2f64, Legal); |
Evan Cheng | 91b740d | 2006-04-12 17:12:36 +0000 | [diff] [blame] | 573 | setOperationAction(ISD::LOAD, MVT::v2i64, Legal); |
Evan Cheng | f7c378e | 2006-04-10 07:23:14 +0000 | [diff] [blame] | 574 | setOperationAction(ISD::SELECT, MVT::v2f64, Custom); |
Evan Cheng | 2c3ae37 | 2006-04-12 21:21:57 +0000 | [diff] [blame] | 575 | setOperationAction(ISD::SELECT, MVT::v2i64, Custom); |
Evan Cheng | 470a6ad | 2006-02-22 02:26:30 +0000 | [diff] [blame] | 576 | } |
| 577 | |
Evan Cheng | 6be2c58 | 2006-04-05 23:38:46 +0000 | [diff] [blame] | 578 | // We want to custom lower some of our intrinsics. |
| 579 | setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom); |
| 580 | |
Evan Cheng | 206ee9d | 2006-07-07 08:33:52 +0000 | [diff] [blame] | 581 | // We have target-specific dag combine patterns for the following nodes: |
| 582 | setTargetDAGCombine(ISD::VECTOR_SHUFFLE); |
Chris Lattner | 83e6c99 | 2006-10-04 06:57:07 +0000 | [diff] [blame] | 583 | setTargetDAGCombine(ISD::SELECT); |
Evan Cheng | 206ee9d | 2006-07-07 08:33:52 +0000 | [diff] [blame] | 584 | |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 585 | computeRegisterProperties(); |
| 586 | |
Evan Cheng | 87ed716 | 2006-02-14 08:25:08 +0000 | [diff] [blame] | 587 | // FIXME: These should be based on subtarget info. Plus, the values should |
| 588 | // be smaller when we are in optimizing for size mode. |
Evan Cheng | a03a5dc | 2006-02-14 08:38:30 +0000 | [diff] [blame] | 589 | maxStoresPerMemset = 16; // For %llvm.memset -> sequence of stores |
| 590 | maxStoresPerMemcpy = 16; // For %llvm.memcpy -> sequence of stores |
| 591 | maxStoresPerMemmove = 16; // For %llvm.memmove -> sequence of stores |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 592 | allowUnalignedMemoryAccesses = true; // x86 supports it! |
| 593 | } |
| 594 | |
Chris Lattner | 2b02a44 | 2007-02-25 08:29:00 +0000 | [diff] [blame] | 595 | |
| 596 | //===----------------------------------------------------------------------===// |
| 597 | // Return Value Calling Convention Implementation |
| 598 | //===----------------------------------------------------------------------===// |
| 599 | |
Chris Lattner | 59ed56b | 2007-02-28 04:55:35 +0000 | [diff] [blame] | 600 | #include "X86GenCallingConv.inc" |
Chris Lattner | 9774c91 | 2007-02-27 05:28:59 +0000 | [diff] [blame] | 601 | |
Chris Lattner | 2a9bdd7 | 2007-02-25 09:12:39 +0000 | [diff] [blame] | 602 | /// LowerRET - Lower an ISD::RET node. |
| 603 | SDOperand X86TargetLowering::LowerRET(SDOperand Op, SelectionDAG &DAG) { |
| 604 | assert((Op.getNumOperands() & 1) == 1 && "ISD::RET should have odd # args"); |
| 605 | |
Chris Lattner | 9774c91 | 2007-02-27 05:28:59 +0000 | [diff] [blame] | 606 | SmallVector<CCValAssign, 16> RVLocs; |
| 607 | unsigned CC = DAG.getMachineFunction().getFunction()->getCallingConv(); |
Chris Lattner | 52387be | 2007-06-19 00:13:10 +0000 | [diff] [blame] | 608 | bool isVarArg = DAG.getMachineFunction().getFunction()->isVarArg(); |
| 609 | CCState CCInfo(CC, isVarArg, getTargetMachine(), RVLocs); |
Chris Lattner | e32bbf6 | 2007-02-28 07:09:55 +0000 | [diff] [blame] | 610 | CCInfo.AnalyzeReturn(Op.Val, RetCC_X86); |
Chris Lattner | 2a9bdd7 | 2007-02-25 09:12:39 +0000 | [diff] [blame] | 611 | |
Chris Lattner | 2a9bdd7 | 2007-02-25 09:12:39 +0000 | [diff] [blame] | 612 | |
| 613 | // If this is the first return lowered for this function, add the regs to the |
| 614 | // liveout set for the function. |
| 615 | if (DAG.getMachineFunction().liveout_empty()) { |
Chris Lattner | 9774c91 | 2007-02-27 05:28:59 +0000 | [diff] [blame] | 616 | for (unsigned i = 0; i != RVLocs.size(); ++i) |
| 617 | if (RVLocs[i].isRegLoc()) |
| 618 | DAG.getMachineFunction().addLiveOut(RVLocs[i].getLocReg()); |
Chris Lattner | 2a9bdd7 | 2007-02-25 09:12:39 +0000 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | SDOperand Chain = Op.getOperand(0); |
| 622 | SDOperand Flag; |
| 623 | |
| 624 | // Copy the result values into the output registers. |
Chris Lattner | 9774c91 | 2007-02-27 05:28:59 +0000 | [diff] [blame] | 625 | if (RVLocs.size() != 1 || !RVLocs[0].isRegLoc() || |
| 626 | RVLocs[0].getLocReg() != X86::ST0) { |
| 627 | for (unsigned i = 0; i != RVLocs.size(); ++i) { |
| 628 | CCValAssign &VA = RVLocs[i]; |
| 629 | assert(VA.isRegLoc() && "Can only return in registers!"); |
| 630 | Chain = DAG.getCopyToReg(Chain, VA.getLocReg(), Op.getOperand(i*2+1), |
| 631 | Flag); |
Chris Lattner | 2a9bdd7 | 2007-02-25 09:12:39 +0000 | [diff] [blame] | 632 | Flag = Chain.getValue(1); |
| 633 | } |
| 634 | } else { |
| 635 | // We need to handle a destination of ST0 specially, because it isn't really |
| 636 | // a register. |
| 637 | SDOperand Value = Op.getOperand(1); |
| 638 | |
| 639 | // If this is an FP return with ScalarSSE, we need to move the value from |
| 640 | // an XMM register onto the fp-stack. |
Dale Johannesen | f1fc3a8 | 2007-09-23 14:52:20 +0000 | [diff] [blame] | 641 | if ((X86ScalarSSEf32 && RVLocs[0].getValVT()==MVT::f32) || |
| 642 | (X86ScalarSSEf64 && RVLocs[0].getValVT()==MVT::f64)) { |
Chris Lattner | 2a9bdd7 | 2007-02-25 09:12:39 +0000 | [diff] [blame] | 643 | SDOperand MemLoc; |
| 644 | |
| 645 | // If this is a load into a scalarsse value, don't store the loaded value |
| 646 | // back to the stack, only to reload it: just replace the scalar-sse load. |
| 647 | if (ISD::isNON_EXTLoad(Value.Val) && |
| 648 | (Chain == Value.getValue(1) || Chain == Value.getOperand(0))) { |
| 649 | Chain = Value.getOperand(0); |
| 650 | MemLoc = Value.getOperand(1); |
| 651 | } else { |
| 652 | // Spill the value to memory and reload it into top of stack. |
Chris Lattner | 9774c91 | 2007-02-27 05:28:59 +0000 | [diff] [blame] | 653 | unsigned Size = MVT::getSizeInBits(RVLocs[0].getValVT())/8; |
Chris Lattner | 2a9bdd7 | 2007-02-25 09:12:39 +0000 | [diff] [blame] | 654 | MachineFunction &MF = DAG.getMachineFunction(); |
| 655 | int SSFI = MF.getFrameInfo()->CreateStackObject(Size, Size); |
| 656 | MemLoc = DAG.getFrameIndex(SSFI, getPointerTy()); |
| 657 | Chain = DAG.getStore(Op.getOperand(0), Value, MemLoc, NULL, 0); |
| 658 | } |
Dale Johannesen | 849f214 | 2007-07-03 00:53:03 +0000 | [diff] [blame] | 659 | SDVTList Tys = DAG.getVTList(RVLocs[0].getValVT(), MVT::Other); |
Chris Lattner | 9774c91 | 2007-02-27 05:28:59 +0000 | [diff] [blame] | 660 | SDOperand Ops[] = {Chain, MemLoc, DAG.getValueType(RVLocs[0].getValVT())}; |
Chris Lattner | 2a9bdd7 | 2007-02-25 09:12:39 +0000 | [diff] [blame] | 661 | Value = DAG.getNode(X86ISD::FLD, Tys, Ops, 3); |
| 662 | Chain = Value.getValue(1); |
| 663 | } |
| 664 | |
| 665 | SDVTList Tys = DAG.getVTList(MVT::Other, MVT::Flag); |
| 666 | SDOperand Ops[] = { Chain, Value }; |
| 667 | Chain = DAG.getNode(X86ISD::FP_SET_RESULT, Tys, Ops, 2); |
| 668 | Flag = Chain.getValue(1); |
| 669 | } |
| 670 | |
| 671 | SDOperand BytesToPop = DAG.getConstant(getBytesToPopOnReturn(), MVT::i16); |
| 672 | if (Flag.Val) |
| 673 | return DAG.getNode(X86ISD::RET_FLAG, MVT::Other, Chain, BytesToPop, Flag); |
| 674 | else |
| 675 | return DAG.getNode(X86ISD::RET_FLAG, MVT::Other, Chain, BytesToPop); |
| 676 | } |
| 677 | |
| 678 | |
Chris Lattner | 3085e15 | 2007-02-25 08:59:22 +0000 | [diff] [blame] | 679 | /// LowerCallResult - Lower the result values of an ISD::CALL into the |
| 680 | /// appropriate copies out of appropriate physical registers. This assumes that |
| 681 | /// Chain/InFlag are the input chain/flag to use, and that TheCall is the call |
| 682 | /// being lowered. The returns a SDNode with the same number of values as the |
| 683 | /// ISD::CALL. |
| 684 | SDNode *X86TargetLowering:: |
| 685 | LowerCallResult(SDOperand Chain, SDOperand InFlag, SDNode *TheCall, |
| 686 | unsigned CallingConv, SelectionDAG &DAG) { |
Chris Lattner | e32bbf6 | 2007-02-28 07:09:55 +0000 | [diff] [blame] | 687 | |
| 688 | // Assign locations to each value returned by this call. |
Chris Lattner | 9774c91 | 2007-02-27 05:28:59 +0000 | [diff] [blame] | 689 | SmallVector<CCValAssign, 16> RVLocs; |
Chris Lattner | 52387be | 2007-06-19 00:13:10 +0000 | [diff] [blame] | 690 | bool isVarArg = cast<ConstantSDNode>(TheCall->getOperand(2))->getValue() != 0; |
| 691 | CCState CCInfo(CallingConv, isVarArg, getTargetMachine(), RVLocs); |
Chris Lattner | e32bbf6 | 2007-02-28 07:09:55 +0000 | [diff] [blame] | 692 | CCInfo.AnalyzeCallResult(TheCall, RetCC_X86); |
| 693 | |
Chris Lattner | 3085e15 | 2007-02-25 08:59:22 +0000 | [diff] [blame] | 694 | |
Chris Lattner | e32bbf6 | 2007-02-28 07:09:55 +0000 | [diff] [blame] | 695 | SmallVector<SDOperand, 8> ResultVals; |
Chris Lattner | 3085e15 | 2007-02-25 08:59:22 +0000 | [diff] [blame] | 696 | |
| 697 | // Copy all of the result registers out of their specified physreg. |
Chris Lattner | 9774c91 | 2007-02-27 05:28:59 +0000 | [diff] [blame] | 698 | if (RVLocs.size() != 1 || RVLocs[0].getLocReg() != X86::ST0) { |
| 699 | for (unsigned i = 0; i != RVLocs.size(); ++i) { |
| 700 | Chain = DAG.getCopyFromReg(Chain, RVLocs[i].getLocReg(), |
| 701 | RVLocs[i].getValVT(), InFlag).getValue(1); |
Chris Lattner | 3085e15 | 2007-02-25 08:59:22 +0000 | [diff] [blame] | 702 | InFlag = Chain.getValue(2); |
| 703 | ResultVals.push_back(Chain.getValue(0)); |
| 704 | } |
| 705 | } else { |
| 706 | // Copies from the FP stack are special, as ST0 isn't a valid register |
| 707 | // before the fp stackifier runs. |
| 708 | |
| 709 | // Copy ST0 into an RFP register with FP_GET_RESULT. |
Dale Johannesen | 849f214 | 2007-07-03 00:53:03 +0000 | [diff] [blame] | 710 | SDVTList Tys = DAG.getVTList(RVLocs[0].getValVT(), MVT::Other, MVT::Flag); |
Chris Lattner | 3085e15 | 2007-02-25 08:59:22 +0000 | [diff] [blame] | 711 | SDOperand GROps[] = { Chain, InFlag }; |
| 712 | SDOperand RetVal = DAG.getNode(X86ISD::FP_GET_RESULT, Tys, GROps, 2); |
| 713 | Chain = RetVal.getValue(1); |
| 714 | InFlag = RetVal.getValue(2); |
| 715 | |
| 716 | // If we are using ScalarSSE, store ST(0) to the stack and reload it into |
| 717 | // an XMM register. |
Dale Johannesen | f1fc3a8 | 2007-09-23 14:52:20 +0000 | [diff] [blame] | 718 | if ((X86ScalarSSEf32 && RVLocs[0].getValVT() == MVT::f32) || |
| 719 | (X86ScalarSSEf64 && RVLocs[0].getValVT() == MVT::f64)) { |
Chris Lattner | 3085e15 | 2007-02-25 08:59:22 +0000 | [diff] [blame] | 720 | // FIXME: Currently the FST is flagged to the FP_GET_RESULT. This |
| 721 | // shouldn't be necessary except that RFP cannot be live across |
| 722 | // multiple blocks. When stackifier is fixed, they can be uncoupled. |
| 723 | MachineFunction &MF = DAG.getMachineFunction(); |
| 724 | int SSFI = MF.getFrameInfo()->CreateStackObject(8, 8); |
| 725 | SDOperand StackSlot = DAG.getFrameIndex(SSFI, getPointerTy()); |
| 726 | SDOperand Ops[] = { |
Chris Lattner | 9774c91 | 2007-02-27 05:28:59 +0000 | [diff] [blame] | 727 | Chain, RetVal, StackSlot, DAG.getValueType(RVLocs[0].getValVT()), InFlag |
Chris Lattner | 3085e15 | 2007-02-25 08:59:22 +0000 | [diff] [blame] | 728 | }; |
| 729 | Chain = DAG.getNode(X86ISD::FST, MVT::Other, Ops, 5); |
Chris Lattner | 9774c91 | 2007-02-27 05:28:59 +0000 | [diff] [blame] | 730 | RetVal = DAG.getLoad(RVLocs[0].getValVT(), Chain, StackSlot, NULL, 0); |
Chris Lattner | 3085e15 | 2007-02-25 08:59:22 +0000 | [diff] [blame] | 731 | Chain = RetVal.getValue(1); |
| 732 | } |
Chris Lattner | 3085e15 | 2007-02-25 08:59:22 +0000 | [diff] [blame] | 733 | ResultVals.push_back(RetVal); |
| 734 | } |
| 735 | |
| 736 | // Merge everything together with a MERGE_VALUES node. |
| 737 | ResultVals.push_back(Chain); |
| 738 | return DAG.getNode(ISD::MERGE_VALUES, TheCall->getVTList(), |
| 739 | &ResultVals[0], ResultVals.size()).Val; |
Chris Lattner | 2b02a44 | 2007-02-25 08:29:00 +0000 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 743 | //===----------------------------------------------------------------------===// |
Anton Korobeynikov | b10308e | 2007-01-28 13:31:35 +0000 | [diff] [blame] | 744 | // C & StdCall Calling Convention implementation |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 745 | //===----------------------------------------------------------------------===// |
Anton Korobeynikov | b10308e | 2007-01-28 13:31:35 +0000 | [diff] [blame] | 746 | // StdCall calling convention seems to be standard for many Windows' API |
| 747 | // routines and around. It differs from C calling convention just a little: |
| 748 | // callee should clean up the stack, not caller. Symbols should be also |
| 749 | // decorated in some fancy way :) It doesn't support any vector arguments. |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 750 | |
Evan Cheng | 85e3800 | 2006-04-27 05:35:28 +0000 | [diff] [blame] | 751 | /// AddLiveIn - This helper function adds the specified physical register to the |
| 752 | /// MachineFunction as a live in value. It also creates a corresponding virtual |
| 753 | /// register for it. |
| 754 | static unsigned AddLiveIn(MachineFunction &MF, unsigned PReg, |
Anton Korobeynikov | b10308e | 2007-01-28 13:31:35 +0000 | [diff] [blame] | 755 | const TargetRegisterClass *RC) { |
Evan Cheng | 85e3800 | 2006-04-27 05:35:28 +0000 | [diff] [blame] | 756 | assert(RC->contains(PReg) && "Not the correct regclass!"); |
| 757 | unsigned VReg = MF.getSSARegMap()->createVirtualRegister(RC); |
| 758 | MF.addLiveIn(PReg, VReg); |
| 759 | return VReg; |
| 760 | } |
| 761 | |
Rafael Espindola | 7effac5 | 2007-09-14 15:48:13 +0000 | [diff] [blame] | 762 | SDOperand X86TargetLowering::LowerMemArgument(SDOperand Op, SelectionDAG &DAG, |
| 763 | const CCValAssign &VA, |
| 764 | MachineFrameInfo *MFI, |
| 765 | SDOperand Root, unsigned i) { |
| 766 | // Create the nodes corresponding to a load from this parameter slot. |
| 767 | int FI = MFI->CreateFixedObject(MVT::getSizeInBits(VA.getValVT())/8, |
| 768 | VA.getLocMemOffset()); |
| 769 | SDOperand FIN = DAG.getFrameIndex(FI, getPointerTy()); |
| 770 | |
| 771 | unsigned Flags = cast<ConstantSDNode>(Op.getOperand(3 + i))->getValue(); |
| 772 | |
| 773 | if (Flags & ISD::ParamFlags::ByVal) |
| 774 | return FIN; |
| 775 | else |
| 776 | return DAG.getLoad(VA.getValVT(), Root, FIN, NULL, 0); |
| 777 | } |
| 778 | |
Anton Korobeynikov | b10308e | 2007-01-28 13:31:35 +0000 | [diff] [blame] | 779 | SDOperand X86TargetLowering::LowerCCCArguments(SDOperand Op, SelectionDAG &DAG, |
| 780 | bool isStdCall) { |
Evan Cheng | 25caf63 | 2006-05-23 21:06:34 +0000 | [diff] [blame] | 781 | unsigned NumArgs = Op.Val->getNumValues() - 1; |
Evan Cheng | 1bc7804 | 2006-04-26 01:20:17 +0000 | [diff] [blame] | 782 | MachineFunction &MF = DAG.getMachineFunction(); |
| 783 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
Evan Cheng | 25caf63 | 2006-05-23 21:06:34 +0000 | [diff] [blame] | 784 | SDOperand Root = Op.getOperand(0); |
Anton Korobeynikov | b10308e | 2007-01-28 13:31:35 +0000 | [diff] [blame] | 785 | bool isVarArg = cast<ConstantSDNode>(Op.getOperand(2))->getValue() != 0; |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 786 | |
Chris Lattner | 638402b | 2007-02-28 07:00:42 +0000 | [diff] [blame] | 787 | // Assign locations to all of the incoming arguments. |
Chris Lattner | f39f771 | 2007-02-28 05:46:49 +0000 | [diff] [blame] | 788 | SmallVector<CCValAssign, 16> ArgLocs; |
Chris Lattner | 52387be | 2007-06-19 00:13:10 +0000 | [diff] [blame] | 789 | CCState CCInfo(MF.getFunction()->getCallingConv(), isVarArg, |
| 790 | getTargetMachine(), ArgLocs); |
Chris Lattner | 638402b | 2007-02-28 07:00:42 +0000 | [diff] [blame] | 791 | CCInfo.AnalyzeFormalArguments(Op.Val, CC_X86_32_C); |
| 792 | |
Chris Lattner | f39f771 | 2007-02-28 05:46:49 +0000 | [diff] [blame] | 793 | SmallVector<SDOperand, 8> ArgValues; |
| 794 | unsigned LastVal = ~0U; |
| 795 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
| 796 | CCValAssign &VA = ArgLocs[i]; |
| 797 | // TODO: If an arg is passed in two places (e.g. reg and stack), skip later |
| 798 | // places. |
| 799 | assert(VA.getValNo() != LastVal && |
| 800 | "Don't support value assigned to multiple locs yet"); |
| 801 | LastVal = VA.getValNo(); |
| 802 | |
| 803 | if (VA.isRegLoc()) { |
| 804 | MVT::ValueType RegVT = VA.getLocVT(); |
| 805 | TargetRegisterClass *RC; |
| 806 | if (RegVT == MVT::i32) |
| 807 | RC = X86::GR32RegisterClass; |
| 808 | else { |
| 809 | assert(MVT::isVector(RegVT)); |
| 810 | RC = X86::VR128RegisterClass; |
Anton Korobeynikov | b10308e | 2007-01-28 13:31:35 +0000 | [diff] [blame] | 811 | } |
Anton Korobeynikov | b10308e | 2007-01-28 13:31:35 +0000 | [diff] [blame] | 812 | |
Chris Lattner | 82932a5 | 2007-03-02 05:12:29 +0000 | [diff] [blame] | 813 | unsigned Reg = AddLiveIn(DAG.getMachineFunction(), VA.getLocReg(), RC); |
| 814 | SDOperand ArgValue = DAG.getCopyFromReg(Root, Reg, RegVT); |
Chris Lattner | f39f771 | 2007-02-28 05:46:49 +0000 | [diff] [blame] | 815 | |
| 816 | // If this is an 8 or 16-bit value, it is really passed promoted to 32 |
| 817 | // bits. Insert an assert[sz]ext to capture this, then truncate to the |
| 818 | // right size. |
| 819 | if (VA.getLocInfo() == CCValAssign::SExt) |
| 820 | ArgValue = DAG.getNode(ISD::AssertSext, RegVT, ArgValue, |
| 821 | DAG.getValueType(VA.getValVT())); |
| 822 | else if (VA.getLocInfo() == CCValAssign::ZExt) |
| 823 | ArgValue = DAG.getNode(ISD::AssertZext, RegVT, ArgValue, |
| 824 | DAG.getValueType(VA.getValVT())); |
| 825 | |
| 826 | if (VA.getLocInfo() != CCValAssign::Full) |
| 827 | ArgValue = DAG.getNode(ISD::TRUNCATE, VA.getValVT(), ArgValue); |
| 828 | |
| 829 | ArgValues.push_back(ArgValue); |
| 830 | } else { |
| 831 | assert(VA.isMemLoc()); |
Rafael Espindola | 7effac5 | 2007-09-14 15:48:13 +0000 | [diff] [blame] | 832 | ArgValues.push_back(LowerMemArgument(Op, DAG, VA, MFI, Root, i)); |
Evan Cheng | 1bc7804 | 2006-04-26 01:20:17 +0000 | [diff] [blame] | 833 | } |
Evan Cheng | 1bc7804 | 2006-04-26 01:20:17 +0000 | [diff] [blame] | 834 | } |
Chris Lattner | f39f771 | 2007-02-28 05:46:49 +0000 | [diff] [blame] | 835 | |
| 836 | unsigned StackSize = CCInfo.getNextStackOffset(); |
Evan Cheng | 1bc7804 | 2006-04-26 01:20:17 +0000 | [diff] [blame] | 837 | |
Evan Cheng | 25caf63 | 2006-05-23 21:06:34 +0000 | [diff] [blame] | 838 | ArgValues.push_back(Root); |
| 839 | |
Evan Cheng | 1bc7804 | 2006-04-26 01:20:17 +0000 | [diff] [blame] | 840 | // If the function takes variable number of arguments, make a frame index for |
| 841 | // the start of the first vararg value... for expansion of llvm.va_start. |
Evan Cheng | 4db3af3 | 2006-05-23 21:08:24 +0000 | [diff] [blame] | 842 | if (isVarArg) |
Chris Lattner | f39f771 | 2007-02-28 05:46:49 +0000 | [diff] [blame] | 843 | VarArgsFrameIndex = MFI->CreateFixedObject(1, StackSize); |
Anton Korobeynikov | b10308e | 2007-01-28 13:31:35 +0000 | [diff] [blame] | 844 | |
| 845 | if (isStdCall && !isVarArg) { |
Chris Lattner | f39f771 | 2007-02-28 05:46:49 +0000 | [diff] [blame] | 846 | BytesToPopOnReturn = StackSize; // Callee pops everything.. |
Anton Korobeynikov | b10308e | 2007-01-28 13:31:35 +0000 | [diff] [blame] | 847 | BytesCallerReserves = 0; |
| 848 | } else { |
Anton Korobeynikov | 1d9bacc | 2007-03-06 08:12:33 +0000 | [diff] [blame] | 849 | BytesToPopOnReturn = 0; // Callee pops nothing. |
Chris Lattner | f39f771 | 2007-02-28 05:46:49 +0000 | [diff] [blame] | 850 | |
| 851 | // If this is an sret function, the return should pop the hidden pointer. |
Anton Korobeynikov | 1d9bacc | 2007-03-06 08:12:33 +0000 | [diff] [blame] | 852 | if (NumArgs && |
| 853 | (cast<ConstantSDNode>(Op.getOperand(3))->getValue() & |
Anton Korobeynikov | d0b82b3 | 2007-03-07 16:25:09 +0000 | [diff] [blame] | 854 | ISD::ParamFlags::StructReturn)) |
Chris Lattner | f39f771 | 2007-02-28 05:46:49 +0000 | [diff] [blame] | 855 | BytesToPopOnReturn = 4; |
| 856 | |
| 857 | BytesCallerReserves = StackSize; |
Anton Korobeynikov | b10308e | 2007-01-28 13:31:35 +0000 | [diff] [blame] | 858 | } |
Anton Korobeynikov | a2780e1 | 2007-08-15 17:12:32 +0000 | [diff] [blame] | 859 | |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 860 | RegSaveFrameIndex = 0xAAAAAAA; // X86-64 only. |
Evan Cheng | 25caf63 | 2006-05-23 21:06:34 +0000 | [diff] [blame] | 861 | |
Anton Korobeynikov | a2780e1 | 2007-08-15 17:12:32 +0000 | [diff] [blame] | 862 | X86MachineFunctionInfo *FuncInfo = MF.getInfo<X86MachineFunctionInfo>(); |
| 863 | FuncInfo->setBytesToPopOnReturn(BytesToPopOnReturn); |
Evan Cheng | 1bc7804 | 2006-04-26 01:20:17 +0000 | [diff] [blame] | 864 | |
Evan Cheng | 25caf63 | 2006-05-23 21:06:34 +0000 | [diff] [blame] | 865 | // Return the new list of results. |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 866 | return DAG.getNode(ISD::MERGE_VALUES, Op.Val->getVTList(), |
Chris Lattner | 14dd4c9 | 2007-02-26 07:50:02 +0000 | [diff] [blame] | 867 | &ArgValues[0], ArgValues.size()).getValue(Op.ResNo); |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 868 | } |
| 869 | |
Anton Korobeynikov | b10308e | 2007-01-28 13:31:35 +0000 | [diff] [blame] | 870 | SDOperand X86TargetLowering::LowerCCCCallTo(SDOperand Op, SelectionDAG &DAG, |
Chris Lattner | 09c75a4 | 2007-02-25 09:06:15 +0000 | [diff] [blame] | 871 | unsigned CC) { |
Evan Cheng | 32fe103 | 2006-05-25 00:59:30 +0000 | [diff] [blame] | 872 | SDOperand Chain = Op.getOperand(0); |
Anton Korobeynikov | b10308e | 2007-01-28 13:31:35 +0000 | [diff] [blame] | 873 | bool isVarArg = cast<ConstantSDNode>(Op.getOperand(2))->getValue() != 0; |
Evan Cheng | 32fe103 | 2006-05-25 00:59:30 +0000 | [diff] [blame] | 874 | bool isTailCall = cast<ConstantSDNode>(Op.getOperand(3))->getValue() != 0; |
| 875 | SDOperand Callee = Op.getOperand(4); |
Evan Cheng | 32fe103 | 2006-05-25 00:59:30 +0000 | [diff] [blame] | 876 | unsigned NumOps = (Op.getNumOperands() - 5) / 2; |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 877 | |
Chris Lattner | 638402b | 2007-02-28 07:00:42 +0000 | [diff] [blame] | 878 | // Analyze operands of the call, assigning locations to each operand. |
Chris Lattner | 423c5f4 | 2007-02-28 05:31:48 +0000 | [diff] [blame] | 879 | SmallVector<CCValAssign, 16> ArgLocs; |
Chris Lattner | 52387be | 2007-06-19 00:13:10 +0000 | [diff] [blame] | 880 | CCState CCInfo(CC, isVarArg, getTargetMachine(), ArgLocs); |
Chris Lattner | 638402b | 2007-02-28 07:00:42 +0000 | [diff] [blame] | 881 | CCInfo.AnalyzeCallOperands(Op.Val, CC_X86_32_C); |
Anton Korobeynikov | b10308e | 2007-01-28 13:31:35 +0000 | [diff] [blame] | 882 | |
Chris Lattner | 423c5f4 | 2007-02-28 05:31:48 +0000 | [diff] [blame] | 883 | // Get a count of how many bytes are to be pushed on the stack. |
| 884 | unsigned NumBytes = CCInfo.getNextStackOffset(); |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 885 | |
Evan Cheng | 32fe103 | 2006-05-25 00:59:30 +0000 | [diff] [blame] | 886 | Chain = DAG.getCALLSEQ_START(Chain,DAG.getConstant(NumBytes, getPointerTy())); |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 887 | |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 888 | SmallVector<std::pair<unsigned, SDOperand>, 8> RegsToPass; |
| 889 | SmallVector<SDOperand, 8> MemOpChains; |
Evan Cheng | 32fe103 | 2006-05-25 00:59:30 +0000 | [diff] [blame] | 890 | |
Chris Lattner | 423c5f4 | 2007-02-28 05:31:48 +0000 | [diff] [blame] | 891 | SDOperand StackPtr; |
Chris Lattner | 423c5f4 | 2007-02-28 05:31:48 +0000 | [diff] [blame] | 892 | |
| 893 | // Walk the register/memloc assignments, inserting copies/loads. |
| 894 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
| 895 | CCValAssign &VA = ArgLocs[i]; |
| 896 | SDOperand Arg = Op.getOperand(5+2*VA.getValNo()); |
Anton Korobeynikov | b10308e | 2007-01-28 13:31:35 +0000 | [diff] [blame] | 897 | |
Chris Lattner | 423c5f4 | 2007-02-28 05:31:48 +0000 | [diff] [blame] | 898 | // Promote the value if needed. |
| 899 | switch (VA.getLocInfo()) { |
| 900 | default: assert(0 && "Unknown loc info!"); |
| 901 | case CCValAssign::Full: break; |
| 902 | case CCValAssign::SExt: |
| 903 | Arg = DAG.getNode(ISD::SIGN_EXTEND, VA.getLocVT(), Arg); |
| 904 | break; |
| 905 | case CCValAssign::ZExt: |
| 906 | Arg = DAG.getNode(ISD::ZERO_EXTEND, VA.getLocVT(), Arg); |
| 907 | break; |
| 908 | case CCValAssign::AExt: |
| 909 | Arg = DAG.getNode(ISD::ANY_EXTEND, VA.getLocVT(), Arg); |
| 910 | break; |
Evan Cheng | 6b5783d | 2006-05-25 18:56:34 +0000 | [diff] [blame] | 911 | } |
Chris Lattner | 423c5f4 | 2007-02-28 05:31:48 +0000 | [diff] [blame] | 912 | |
| 913 | if (VA.isRegLoc()) { |
| 914 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg)); |
| 915 | } else { |
| 916 | assert(VA.isMemLoc()); |
| 917 | if (StackPtr.Val == 0) |
| 918 | StackPtr = DAG.getRegister(getStackPtrReg(), getPointerTy()); |
Rafael Espindola | a37ac9f | 2007-09-21 15:50:22 +0000 | [diff] [blame] | 919 | |
| 920 | MemOpChains.push_back(LowerMemOpCallTo(Op, DAG, StackPtr, VA, Chain, |
| 921 | Arg)); |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 922 | } |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 923 | } |
| 924 | |
Chris Lattner | c0bdf34 | 2007-02-28 05:39:26 +0000 | [diff] [blame] | 925 | // If the first argument is an sret pointer, remember it. |
Anton Korobeynikov | 1d9bacc | 2007-03-06 08:12:33 +0000 | [diff] [blame] | 926 | bool isSRet = NumOps && |
| 927 | (cast<ConstantSDNode>(Op.getOperand(6))->getValue() & |
Anton Korobeynikov | d0b82b3 | 2007-03-07 16:25:09 +0000 | [diff] [blame] | 928 | ISD::ParamFlags::StructReturn); |
Chris Lattner | c0bdf34 | 2007-02-28 05:39:26 +0000 | [diff] [blame] | 929 | |
Evan Cheng | 32fe103 | 2006-05-25 00:59:30 +0000 | [diff] [blame] | 930 | if (!MemOpChains.empty()) |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 931 | Chain = DAG.getNode(ISD::TokenFactor, MVT::Other, |
| 932 | &MemOpChains[0], MemOpChains.size()); |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 933 | |
Evan Cheng | 347d5f7 | 2006-04-28 21:29:37 +0000 | [diff] [blame] | 934 | // Build a sequence of copy-to-reg nodes chained together with token chain |
| 935 | // and flag operands which copy the outgoing args into registers. |
| 936 | SDOperand InFlag; |
Evan Cheng | 32fe103 | 2006-05-25 00:59:30 +0000 | [diff] [blame] | 937 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 938 | Chain = DAG.getCopyToReg(Chain, RegsToPass[i].first, RegsToPass[i].second, |
| 939 | InFlag); |
Evan Cheng | 347d5f7 | 2006-04-28 21:29:37 +0000 | [diff] [blame] | 940 | InFlag = Chain.getValue(1); |
| 941 | } |
| 942 | |
Evan Cheng | f468471 | 2007-02-21 21:18:14 +0000 | [diff] [blame] | 943 | // ELF / PIC requires GOT in the EBX register before function calls via PLT |
| 944 | // GOT pointer. |
Evan Cheng | 706535d | 2007-01-22 21:34:25 +0000 | [diff] [blame] | 945 | if (getTargetMachine().getRelocationModel() == Reloc::PIC_ && |
| 946 | Subtarget->isPICStyleGOT()) { |
Anton Korobeynikov | 7f70559 | 2007-01-12 19:20:47 +0000 | [diff] [blame] | 947 | Chain = DAG.getCopyToReg(Chain, X86::EBX, |
| 948 | DAG.getNode(X86ISD::GlobalBaseReg, getPointerTy()), |
| 949 | InFlag); |
| 950 | InFlag = Chain.getValue(1); |
| 951 | } |
| 952 | |
Evan Cheng | 32fe103 | 2006-05-25 00:59:30 +0000 | [diff] [blame] | 953 | // If the callee is a GlobalAddress node (quite common, every direct call is) |
| 954 | // turn it into a TargetGlobalAddress node so that legalize doesn't hack it. |
Anton Korobeynikov | a598685 | 2006-11-20 10:46:14 +0000 | [diff] [blame] | 955 | if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { |
Anton Korobeynikov | 2b2bc68 | 2006-12-22 22:29:05 +0000 | [diff] [blame] | 956 | // We should use extra load for direct calls to dllimported functions in |
| 957 | // non-JIT mode. |
| 958 | if (!Subtarget->GVRequiresExtraLoad(G->getGlobal(), |
| 959 | getTargetMachine(), true)) |
Anton Korobeynikov | a598685 | 2006-11-20 10:46:14 +0000 | [diff] [blame] | 960 | Callee = DAG.getTargetGlobalAddress(G->getGlobal(), getPointerTy()); |
| 961 | } else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee)) |
Evan Cheng | 32fe103 | 2006-05-25 00:59:30 +0000 | [diff] [blame] | 962 | Callee = DAG.getTargetExternalSymbol(S->getSymbol(), getPointerTy()); |
| 963 | |
Chris Lattner | d96d072 | 2007-02-25 06:40:16 +0000 | [diff] [blame] | 964 | // Returns a chain & a flag for retval copy to use. |
| 965 | SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Flag); |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 966 | SmallVector<SDOperand, 8> Ops; |
Nate Begeman | 4c5dcf5 | 2006-02-17 00:03:04 +0000 | [diff] [blame] | 967 | Ops.push_back(Chain); |
| 968 | Ops.push_back(Callee); |
Evan Cheng | b69d113 | 2006-06-14 18:17:40 +0000 | [diff] [blame] | 969 | |
| 970 | // Add argument registers to the end of the list so that they are known live |
| 971 | // into the call. |
| 972 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) |
Anton Korobeynikov | 12c49af | 2006-11-21 00:01:06 +0000 | [diff] [blame] | 973 | Ops.push_back(DAG.getRegister(RegsToPass[i].first, |
Evan Cheng | b69d113 | 2006-06-14 18:17:40 +0000 | [diff] [blame] | 974 | RegsToPass[i].second.getValueType())); |
Evan Cheng | f468471 | 2007-02-21 21:18:14 +0000 | [diff] [blame] | 975 | |
| 976 | // Add an implicit use GOT pointer in EBX. |
| 977 | if (getTargetMachine().getRelocationModel() == Reloc::PIC_ && |
| 978 | Subtarget->isPICStyleGOT()) |
| 979 | Ops.push_back(DAG.getRegister(X86::EBX, getPointerTy())); |
Anton Korobeynikov | 7f70559 | 2007-01-12 19:20:47 +0000 | [diff] [blame] | 980 | |
Evan Cheng | 347d5f7 | 2006-04-28 21:29:37 +0000 | [diff] [blame] | 981 | if (InFlag.Val) |
| 982 | Ops.push_back(InFlag); |
Evan Cheng | d90eb7f | 2006-01-05 00:27:02 +0000 | [diff] [blame] | 983 | |
Evan Cheng | 32fe103 | 2006-05-25 00:59:30 +0000 | [diff] [blame] | 984 | Chain = DAG.getNode(isTailCall ? X86ISD::TAILCALL : X86ISD::CALL, |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 985 | NodeTys, &Ops[0], Ops.size()); |
Evan Cheng | 347d5f7 | 2006-04-28 21:29:37 +0000 | [diff] [blame] | 986 | InFlag = Chain.getValue(1); |
Evan Cheng | d90eb7f | 2006-01-05 00:27:02 +0000 | [diff] [blame] | 987 | |
Chris Lattner | 2d29709 | 2006-05-23 18:50:38 +0000 | [diff] [blame] | 988 | // Create the CALLSEQ_END node. |
| 989 | unsigned NumBytesForCalleeToPush = 0; |
| 990 | |
Chris Lattner | 09c75a4 | 2007-02-25 09:06:15 +0000 | [diff] [blame] | 991 | if (CC == CallingConv::X86_StdCall) { |
| 992 | if (isVarArg) |
Chris Lattner | c0bdf34 | 2007-02-28 05:39:26 +0000 | [diff] [blame] | 993 | NumBytesForCalleeToPush = isSRet ? 4 : 0; |
Chris Lattner | 09c75a4 | 2007-02-25 09:06:15 +0000 | [diff] [blame] | 994 | else |
Anton Korobeynikov | b10308e | 2007-01-28 13:31:35 +0000 | [diff] [blame] | 995 | NumBytesForCalleeToPush = NumBytes; |
Anton Korobeynikov | b10308e | 2007-01-28 13:31:35 +0000 | [diff] [blame] | 996 | } else { |
| 997 | // If this is is a call to a struct-return function, the callee |
| 998 | // pops the hidden struct pointer, so we have to push it back. |
| 999 | // This is common for Darwin/X86, Linux & Mingw32 targets. |
Chris Lattner | c0bdf34 | 2007-02-28 05:39:26 +0000 | [diff] [blame] | 1000 | NumBytesForCalleeToPush = isSRet ? 4 : 0; |
Anton Korobeynikov | b10308e | 2007-01-28 13:31:35 +0000 | [diff] [blame] | 1001 | } |
| 1002 | |
Chris Lattner | 7d53a1c | 2007-02-25 07:18:38 +0000 | [diff] [blame] | 1003 | NodeTys = DAG.getVTList(MVT::Other, MVT::Flag); |
Nate Begeman | 4c5dcf5 | 2006-02-17 00:03:04 +0000 | [diff] [blame] | 1004 | Ops.clear(); |
| 1005 | Ops.push_back(Chain); |
| 1006 | Ops.push_back(DAG.getConstant(NumBytes, getPointerTy())); |
Chris Lattner | 2d29709 | 2006-05-23 18:50:38 +0000 | [diff] [blame] | 1007 | Ops.push_back(DAG.getConstant(NumBytesForCalleeToPush, getPointerTy())); |
Nate Begeman | 4c5dcf5 | 2006-02-17 00:03:04 +0000 | [diff] [blame] | 1008 | Ops.push_back(InFlag); |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 1009 | Chain = DAG.getNode(ISD::CALLSEQ_END, NodeTys, &Ops[0], Ops.size()); |
Chris Lattner | 3085e15 | 2007-02-25 08:59:22 +0000 | [diff] [blame] | 1010 | InFlag = Chain.getValue(1); |
Anton Korobeynikov | 12c49af | 2006-11-21 00:01:06 +0000 | [diff] [blame] | 1011 | |
Chris Lattner | 3085e15 | 2007-02-25 08:59:22 +0000 | [diff] [blame] | 1012 | // Handle result values, copying them out of physregs into vregs that we |
| 1013 | // return. |
Chris Lattner | 09c75a4 | 2007-02-25 09:06:15 +0000 | [diff] [blame] | 1014 | return SDOperand(LowerCallResult(Chain, InFlag, Op.Val, CC, DAG), Op.ResNo); |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 1015 | } |
| 1016 | |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 1017 | |
| 1018 | //===----------------------------------------------------------------------===// |
Chris Lattner | fcf1a3d | 2007-02-28 06:10:12 +0000 | [diff] [blame] | 1019 | // FastCall Calling Convention implementation |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 1020 | //===----------------------------------------------------------------------===// |
| 1021 | // |
Anton Korobeynikov | b10308e | 2007-01-28 13:31:35 +0000 | [diff] [blame] | 1022 | // The X86 'fastcall' calling convention passes up to two integer arguments in |
| 1023 | // registers (an appropriate portion of ECX/EDX), passes arguments in C order, |
| 1024 | // and requires that the callee pop its arguments off the stack (allowing proper |
| 1025 | // tail calls), and has the same return value conventions as C calling convs. |
| 1026 | // |
| 1027 | // This calling convention always arranges for the callee pop value to be 8n+4 |
| 1028 | // bytes, which is needed for tail recursion elimination and stack alignment |
| 1029 | // reasons. |
Evan Cheng | 25caf63 | 2006-05-23 21:06:34 +0000 | [diff] [blame] | 1030 | SDOperand |
Chris Lattner | 2db39b8 | 2007-02-28 06:05:16 +0000 | [diff] [blame] | 1031 | X86TargetLowering::LowerFastCCArguments(SDOperand Op, SelectionDAG &DAG) { |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 1032 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1033 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
Evan Cheng | 25caf63 | 2006-05-23 21:06:34 +0000 | [diff] [blame] | 1034 | SDOperand Root = Op.getOperand(0); |
Chris Lattner | 52387be | 2007-06-19 00:13:10 +0000 | [diff] [blame] | 1035 | bool isVarArg = cast<ConstantSDNode>(Op.getOperand(2))->getValue() != 0; |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 1036 | |
Chris Lattner | 638402b | 2007-02-28 07:00:42 +0000 | [diff] [blame] | 1037 | // Assign locations to all of the incoming arguments. |
Chris Lattner | fc664c1 | 2007-02-28 06:21:19 +0000 | [diff] [blame] | 1038 | SmallVector<CCValAssign, 16> ArgLocs; |
Chris Lattner | 52387be | 2007-06-19 00:13:10 +0000 | [diff] [blame] | 1039 | CCState CCInfo(MF.getFunction()->getCallingConv(), isVarArg, |
| 1040 | getTargetMachine(), ArgLocs); |
Chris Lattner | 638402b | 2007-02-28 07:00:42 +0000 | [diff] [blame] | 1041 | CCInfo.AnalyzeFormalArguments(Op.Val, CC_X86_32_FastCall); |
Chris Lattner | fc664c1 | 2007-02-28 06:21:19 +0000 | [diff] [blame] | 1042 | |
| 1043 | SmallVector<SDOperand, 8> ArgValues; |
| 1044 | unsigned LastVal = ~0U; |
| 1045 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
| 1046 | CCValAssign &VA = ArgLocs[i]; |
| 1047 | // TODO: If an arg is passed in two places (e.g. reg and stack), skip later |
| 1048 | // places. |
| 1049 | assert(VA.getValNo() != LastVal && |
| 1050 | "Don't support value assigned to multiple locs yet"); |
| 1051 | LastVal = VA.getValNo(); |
| 1052 | |
| 1053 | if (VA.isRegLoc()) { |
| 1054 | MVT::ValueType RegVT = VA.getLocVT(); |
| 1055 | TargetRegisterClass *RC; |
| 1056 | if (RegVT == MVT::i32) |
| 1057 | RC = X86::GR32RegisterClass; |
| 1058 | else { |
| 1059 | assert(MVT::isVector(RegVT)); |
| 1060 | RC = X86::VR128RegisterClass; |
| 1061 | } |
| 1062 | |
Chris Lattner | 82932a5 | 2007-03-02 05:12:29 +0000 | [diff] [blame] | 1063 | unsigned Reg = AddLiveIn(DAG.getMachineFunction(), VA.getLocReg(), RC); |
| 1064 | SDOperand ArgValue = DAG.getCopyFromReg(Root, Reg, RegVT); |
Chris Lattner | fc664c1 | 2007-02-28 06:21:19 +0000 | [diff] [blame] | 1065 | |
| 1066 | // If this is an 8 or 16-bit value, it is really passed promoted to 32 |
| 1067 | // bits. Insert an assert[sz]ext to capture this, then truncate to the |
| 1068 | // right size. |
| 1069 | if (VA.getLocInfo() == CCValAssign::SExt) |
| 1070 | ArgValue = DAG.getNode(ISD::AssertSext, RegVT, ArgValue, |
| 1071 | DAG.getValueType(VA.getValVT())); |
| 1072 | else if (VA.getLocInfo() == CCValAssign::ZExt) |
| 1073 | ArgValue = DAG.getNode(ISD::AssertZext, RegVT, ArgValue, |
| 1074 | DAG.getValueType(VA.getValVT())); |
| 1075 | |
| 1076 | if (VA.getLocInfo() != CCValAssign::Full) |
| 1077 | ArgValue = DAG.getNode(ISD::TRUNCATE, VA.getValVT(), ArgValue); |
| 1078 | |
| 1079 | ArgValues.push_back(ArgValue); |
| 1080 | } else { |
| 1081 | assert(VA.isMemLoc()); |
Rafael Espindola | 1242d28 | 2007-09-21 14:55:38 +0000 | [diff] [blame] | 1082 | ArgValues.push_back(LowerMemArgument(Op, DAG, VA, MFI, Root, i)); |
Chris Lattner | fc664c1 | 2007-02-28 06:21:19 +0000 | [diff] [blame] | 1083 | } |
| 1084 | } |
| 1085 | |
Evan Cheng | 25caf63 | 2006-05-23 21:06:34 +0000 | [diff] [blame] | 1086 | ArgValues.push_back(Root); |
| 1087 | |
Chris Lattner | fc664c1 | 2007-02-28 06:21:19 +0000 | [diff] [blame] | 1088 | unsigned StackSize = CCInfo.getNextStackOffset(); |
Anton Korobeynikov | 9dd9abd | 2007-03-01 16:29:22 +0000 | [diff] [blame] | 1089 | |
Anton Korobeynikov | f7dcfa8 | 2007-03-02 21:50:27 +0000 | [diff] [blame] | 1090 | if (!Subtarget->isTargetCygMing() && !Subtarget->isTargetWindows()) { |
Anton Korobeynikov | 9dd9abd | 2007-03-01 16:29:22 +0000 | [diff] [blame] | 1091 | // Make sure the instruction takes 8n+4 bytes to make sure the start of the |
| 1092 | // arguments and the arguments after the retaddr has been pushed are aligned. |
| 1093 | if ((StackSize & 7) == 0) |
| 1094 | StackSize += 4; |
| 1095 | } |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 1096 | |
| 1097 | VarArgsFrameIndex = 0xAAAAAAA; // fastcc functions can't have varargs. |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 1098 | RegSaveFrameIndex = 0xAAAAAAA; // X86-64 only. |
Chris Lattner | fc664c1 | 2007-02-28 06:21:19 +0000 | [diff] [blame] | 1099 | BytesToPopOnReturn = StackSize; // Callee pops all stack arguments. |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 1100 | BytesCallerReserves = 0; |
| 1101 | |
Anton Korobeynikov | a2780e1 | 2007-08-15 17:12:32 +0000 | [diff] [blame] | 1102 | X86MachineFunctionInfo *FuncInfo = MF.getInfo<X86MachineFunctionInfo>(); |
| 1103 | FuncInfo->setBytesToPopOnReturn(BytesToPopOnReturn); |
Anton Korobeynikov | b10308e | 2007-01-28 13:31:35 +0000 | [diff] [blame] | 1104 | |
Evan Cheng | 25caf63 | 2006-05-23 21:06:34 +0000 | [diff] [blame] | 1105 | // Return the new list of results. |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 1106 | return DAG.getNode(ISD::MERGE_VALUES, Op.Val->getVTList(), |
Chris Lattner | 14dd4c9 | 2007-02-26 07:50:02 +0000 | [diff] [blame] | 1107 | &ArgValues[0], ArgValues.size()).getValue(Op.ResNo); |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 1108 | } |
| 1109 | |
Rafael Espindola | 1b5dcc3 | 2007-08-31 15:06:30 +0000 | [diff] [blame] | 1110 | SDOperand |
| 1111 | X86TargetLowering::LowerMemOpCallTo(SDOperand Op, SelectionDAG &DAG, |
| 1112 | const SDOperand &StackPtr, |
| 1113 | const CCValAssign &VA, |
| 1114 | SDOperand Chain, |
| 1115 | SDOperand Arg) { |
| 1116 | SDOperand PtrOff = DAG.getConstant(VA.getLocMemOffset(), getPointerTy()); |
| 1117 | PtrOff = DAG.getNode(ISD::ADD, getPointerTy(), StackPtr, PtrOff); |
| 1118 | SDOperand FlagsOp = Op.getOperand(6+2*VA.getValNo()); |
| 1119 | unsigned Flags = cast<ConstantSDNode>(FlagsOp)->getValue(); |
| 1120 | if (Flags & ISD::ParamFlags::ByVal) { |
| 1121 | unsigned Align = 1 << ((Flags & ISD::ParamFlags::ByValAlign) >> |
| 1122 | ISD::ParamFlags::ByValAlignOffs); |
| 1123 | |
Rafael Espindola | 1b5dcc3 | 2007-08-31 15:06:30 +0000 | [diff] [blame] | 1124 | unsigned Size = (Flags & ISD::ParamFlags::ByValSize) >> |
| 1125 | ISD::ParamFlags::ByValSizeOffs; |
| 1126 | |
| 1127 | SDOperand AlignNode = DAG.getConstant(Align, MVT::i32); |
| 1128 | SDOperand SizeNode = DAG.getConstant(Size, MVT::i32); |
| 1129 | |
| 1130 | return DAG.getNode(ISD::MEMCPY, MVT::Other, Chain, PtrOff, Arg, SizeNode, |
| 1131 | AlignNode); |
| 1132 | } else { |
| 1133 | return DAG.getStore(Chain, Arg, PtrOff, NULL, 0); |
| 1134 | } |
| 1135 | } |
| 1136 | |
Chris Lattner | e87e115 | 2006-09-26 03:57:53 +0000 | [diff] [blame] | 1137 | SDOperand X86TargetLowering::LowerFastCCCallTo(SDOperand Op, SelectionDAG &DAG, |
Chris Lattner | 09c75a4 | 2007-02-25 09:06:15 +0000 | [diff] [blame] | 1138 | unsigned CC) { |
Evan Cheng | 32fe103 | 2006-05-25 00:59:30 +0000 | [diff] [blame] | 1139 | SDOperand Chain = Op.getOperand(0); |
Evan Cheng | 32fe103 | 2006-05-25 00:59:30 +0000 | [diff] [blame] | 1140 | bool isTailCall = cast<ConstantSDNode>(Op.getOperand(3))->getValue() != 0; |
Chris Lattner | 52387be | 2007-06-19 00:13:10 +0000 | [diff] [blame] | 1141 | bool isVarArg = cast<ConstantSDNode>(Op.getOperand(2))->getValue() != 0; |
Evan Cheng | 32fe103 | 2006-05-25 00:59:30 +0000 | [diff] [blame] | 1142 | SDOperand Callee = Op.getOperand(4); |
Evan Cheng | 32fe103 | 2006-05-25 00:59:30 +0000 | [diff] [blame] | 1143 | |
Chris Lattner | 638402b | 2007-02-28 07:00:42 +0000 | [diff] [blame] | 1144 | // Analyze operands of the call, assigning locations to each operand. |
Chris Lattner | f5d280a | 2007-02-28 06:26:33 +0000 | [diff] [blame] | 1145 | SmallVector<CCValAssign, 16> ArgLocs; |
Chris Lattner | 52387be | 2007-06-19 00:13:10 +0000 | [diff] [blame] | 1146 | CCState CCInfo(CC, isVarArg, getTargetMachine(), ArgLocs); |
Chris Lattner | 638402b | 2007-02-28 07:00:42 +0000 | [diff] [blame] | 1147 | CCInfo.AnalyzeCallOperands(Op.Val, CC_X86_32_FastCall); |
Chris Lattner | f5d280a | 2007-02-28 06:26:33 +0000 | [diff] [blame] | 1148 | |
| 1149 | // Get a count of how many bytes are to be pushed on the stack. |
| 1150 | unsigned NumBytes = CCInfo.getNextStackOffset(); |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 1151 | |
Anton Korobeynikov | f7dcfa8 | 2007-03-02 21:50:27 +0000 | [diff] [blame] | 1152 | if (!Subtarget->isTargetCygMing() && !Subtarget->isTargetWindows()) { |
Anton Korobeynikov | 9dd9abd | 2007-03-01 16:29:22 +0000 | [diff] [blame] | 1153 | // Make sure the instruction takes 8n+4 bytes to make sure the start of the |
| 1154 | // arguments and the arguments after the retaddr has been pushed are aligned. |
| 1155 | if ((NumBytes & 7) == 0) |
| 1156 | NumBytes += 4; |
| 1157 | } |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 1158 | |
Chris Lattner | 94dd292 | 2006-02-13 09:00:43 +0000 | [diff] [blame] | 1159 | Chain = DAG.getCALLSEQ_START(Chain,DAG.getConstant(NumBytes, getPointerTy())); |
Chris Lattner | f5d280a | 2007-02-28 06:26:33 +0000 | [diff] [blame] | 1160 | |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 1161 | SmallVector<std::pair<unsigned, SDOperand>, 8> RegsToPass; |
| 1162 | SmallVector<SDOperand, 8> MemOpChains; |
Chris Lattner | f5d280a | 2007-02-28 06:26:33 +0000 | [diff] [blame] | 1163 | |
| 1164 | SDOperand StackPtr; |
| 1165 | |
| 1166 | // Walk the register/memloc assignments, inserting copies/loads. |
| 1167 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
| 1168 | CCValAssign &VA = ArgLocs[i]; |
| 1169 | SDOperand Arg = Op.getOperand(5+2*VA.getValNo()); |
| 1170 | |
| 1171 | // Promote the value if needed. |
| 1172 | switch (VA.getLocInfo()) { |
| 1173 | default: assert(0 && "Unknown loc info!"); |
| 1174 | case CCValAssign::Full: break; |
| 1175 | case CCValAssign::SExt: |
| 1176 | Arg = DAG.getNode(ISD::SIGN_EXTEND, VA.getLocVT(), Arg); |
Chris Lattner | 2db39b8 | 2007-02-28 06:05:16 +0000 | [diff] [blame] | 1177 | break; |
Chris Lattner | f5d280a | 2007-02-28 06:26:33 +0000 | [diff] [blame] | 1178 | case CCValAssign::ZExt: |
| 1179 | Arg = DAG.getNode(ISD::ZERO_EXTEND, VA.getLocVT(), Arg); |
| 1180 | break; |
| 1181 | case CCValAssign::AExt: |
| 1182 | Arg = DAG.getNode(ISD::ANY_EXTEND, VA.getLocVT(), Arg); |
| 1183 | break; |
| 1184 | } |
| 1185 | |
| 1186 | if (VA.isRegLoc()) { |
| 1187 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg)); |
| 1188 | } else { |
| 1189 | assert(VA.isMemLoc()); |
| 1190 | if (StackPtr.Val == 0) |
| 1191 | StackPtr = DAG.getRegister(getStackPtrReg(), getPointerTy()); |
Rafael Espindola | a37ac9f | 2007-09-21 15:50:22 +0000 | [diff] [blame] | 1192 | |
| 1193 | MemOpChains.push_back(LowerMemOpCallTo(Op, DAG, StackPtr, VA, Chain, |
| 1194 | Arg)); |
Evan Cheng | 32fe103 | 2006-05-25 00:59:30 +0000 | [diff] [blame] | 1195 | } |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 1196 | } |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 1197 | |
Evan Cheng | 32fe103 | 2006-05-25 00:59:30 +0000 | [diff] [blame] | 1198 | if (!MemOpChains.empty()) |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 1199 | Chain = DAG.getNode(ISD::TokenFactor, MVT::Other, |
| 1200 | &MemOpChains[0], MemOpChains.size()); |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 1201 | |
Nate Begeman | 4c5dcf5 | 2006-02-17 00:03:04 +0000 | [diff] [blame] | 1202 | // Build a sequence of copy-to-reg nodes chained together with token chain |
| 1203 | // and flag operands which copy the outgoing args into registers. |
| 1204 | SDOperand InFlag; |
Evan Cheng | 32fe103 | 2006-05-25 00:59:30 +0000 | [diff] [blame] | 1205 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 1206 | Chain = DAG.getCopyToReg(Chain, RegsToPass[i].first, RegsToPass[i].second, |
| 1207 | InFlag); |
Nate Begeman | 4c5dcf5 | 2006-02-17 00:03:04 +0000 | [diff] [blame] | 1208 | InFlag = Chain.getValue(1); |
| 1209 | } |
| 1210 | |
Evan Cheng | 32fe103 | 2006-05-25 00:59:30 +0000 | [diff] [blame] | 1211 | // If the callee is a GlobalAddress node (quite common, every direct call is) |
| 1212 | // turn it into a TargetGlobalAddress node so that legalize doesn't hack it. |
Anton Korobeynikov | a598685 | 2006-11-20 10:46:14 +0000 | [diff] [blame] | 1213 | if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { |
Anton Korobeynikov | 2b2bc68 | 2006-12-22 22:29:05 +0000 | [diff] [blame] | 1214 | // We should use extra load for direct calls to dllimported functions in |
| 1215 | // non-JIT mode. |
| 1216 | if (!Subtarget->GVRequiresExtraLoad(G->getGlobal(), |
| 1217 | getTargetMachine(), true)) |
Anton Korobeynikov | a598685 | 2006-11-20 10:46:14 +0000 | [diff] [blame] | 1218 | Callee = DAG.getTargetGlobalAddress(G->getGlobal(), getPointerTy()); |
| 1219 | } else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee)) |
Evan Cheng | 32fe103 | 2006-05-25 00:59:30 +0000 | [diff] [blame] | 1220 | Callee = DAG.getTargetExternalSymbol(S->getSymbol(), getPointerTy()); |
| 1221 | |
Evan Cheng | f468471 | 2007-02-21 21:18:14 +0000 | [diff] [blame] | 1222 | // ELF / PIC requires GOT in the EBX register before function calls via PLT |
| 1223 | // GOT pointer. |
Anton Korobeynikov | b10308e | 2007-01-28 13:31:35 +0000 | [diff] [blame] | 1224 | if (getTargetMachine().getRelocationModel() == Reloc::PIC_ && |
| 1225 | Subtarget->isPICStyleGOT()) { |
| 1226 | Chain = DAG.getCopyToReg(Chain, X86::EBX, |
| 1227 | DAG.getNode(X86ISD::GlobalBaseReg, getPointerTy()), |
| 1228 | InFlag); |
| 1229 | InFlag = Chain.getValue(1); |
| 1230 | } |
| 1231 | |
Chris Lattner | d96d072 | 2007-02-25 06:40:16 +0000 | [diff] [blame] | 1232 | // Returns a chain & a flag for retval copy to use. |
| 1233 | SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Flag); |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 1234 | SmallVector<SDOperand, 8> Ops; |
Nate Begeman | 4c5dcf5 | 2006-02-17 00:03:04 +0000 | [diff] [blame] | 1235 | Ops.push_back(Chain); |
| 1236 | Ops.push_back(Callee); |
Evan Cheng | b69d113 | 2006-06-14 18:17:40 +0000 | [diff] [blame] | 1237 | |
| 1238 | // Add argument registers to the end of the list so that they are known live |
| 1239 | // into the call. |
| 1240 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) |
Anton Korobeynikov | 12c49af | 2006-11-21 00:01:06 +0000 | [diff] [blame] | 1241 | Ops.push_back(DAG.getRegister(RegsToPass[i].first, |
Evan Cheng | b69d113 | 2006-06-14 18:17:40 +0000 | [diff] [blame] | 1242 | RegsToPass[i].second.getValueType())); |
| 1243 | |
Evan Cheng | f468471 | 2007-02-21 21:18:14 +0000 | [diff] [blame] | 1244 | // Add an implicit use GOT pointer in EBX. |
| 1245 | if (getTargetMachine().getRelocationModel() == Reloc::PIC_ && |
| 1246 | Subtarget->isPICStyleGOT()) |
| 1247 | Ops.push_back(DAG.getRegister(X86::EBX, getPointerTy())); |
| 1248 | |
Nate Begeman | 4c5dcf5 | 2006-02-17 00:03:04 +0000 | [diff] [blame] | 1249 | if (InFlag.Val) |
| 1250 | Ops.push_back(InFlag); |
| 1251 | |
| 1252 | // FIXME: Do not generate X86ISD::TAILCALL for now. |
Chris Lattner | 8c0c10c | 2006-05-16 06:45:34 +0000 | [diff] [blame] | 1253 | Chain = DAG.getNode(isTailCall ? X86ISD::TAILCALL : X86ISD::CALL, |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 1254 | NodeTys, &Ops[0], Ops.size()); |
Nate Begeman | 4c5dcf5 | 2006-02-17 00:03:04 +0000 | [diff] [blame] | 1255 | InFlag = Chain.getValue(1); |
| 1256 | |
Chris Lattner | 7d53a1c | 2007-02-25 07:18:38 +0000 | [diff] [blame] | 1257 | // Returns a flag for retval copy to use. |
| 1258 | NodeTys = DAG.getVTList(MVT::Other, MVT::Flag); |
Nate Begeman | 4c5dcf5 | 2006-02-17 00:03:04 +0000 | [diff] [blame] | 1259 | Ops.clear(); |
| 1260 | Ops.push_back(Chain); |
Evan Cheng | 32fe103 | 2006-05-25 00:59:30 +0000 | [diff] [blame] | 1261 | Ops.push_back(DAG.getConstant(NumBytes, getPointerTy())); |
| 1262 | Ops.push_back(DAG.getConstant(NumBytes, getPointerTy())); |
Nate Begeman | 4c5dcf5 | 2006-02-17 00:03:04 +0000 | [diff] [blame] | 1263 | Ops.push_back(InFlag); |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 1264 | Chain = DAG.getNode(ISD::CALLSEQ_END, NodeTys, &Ops[0], Ops.size()); |
Chris Lattner | 339b439 | 2007-02-25 09:10:05 +0000 | [diff] [blame] | 1265 | InFlag = Chain.getValue(1); |
Anton Korobeynikov | 12c49af | 2006-11-21 00:01:06 +0000 | [diff] [blame] | 1266 | |
Chris Lattner | 339b439 | 2007-02-25 09:10:05 +0000 | [diff] [blame] | 1267 | // Handle result values, copying them out of physregs into vregs that we |
| 1268 | // return. |
| 1269 | return SDOperand(LowerCallResult(Chain, InFlag, Op.Val, CC, DAG), Op.ResNo); |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 1270 | } |
| 1271 | |
Chris Lattner | fcf1a3d | 2007-02-28 06:10:12 +0000 | [diff] [blame] | 1272 | |
| 1273 | //===----------------------------------------------------------------------===// |
| 1274 | // X86-64 C Calling Convention implementation |
| 1275 | //===----------------------------------------------------------------------===// |
| 1276 | |
| 1277 | SDOperand |
| 1278 | X86TargetLowering::LowerX86_64CCCArguments(SDOperand Op, SelectionDAG &DAG) { |
Chris Lattner | fcf1a3d | 2007-02-28 06:10:12 +0000 | [diff] [blame] | 1279 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1280 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 1281 | SDOperand Root = Op.getOperand(0); |
| 1282 | bool isVarArg = cast<ConstantSDNode>(Op.getOperand(2))->getValue() != 0; |
| 1283 | |
| 1284 | static const unsigned GPR64ArgRegs[] = { |
| 1285 | X86::RDI, X86::RSI, X86::RDX, X86::RCX, X86::R8, X86::R9 |
| 1286 | }; |
| 1287 | static const unsigned XMMArgRegs[] = { |
| 1288 | X86::XMM0, X86::XMM1, X86::XMM2, X86::XMM3, |
| 1289 | X86::XMM4, X86::XMM5, X86::XMM6, X86::XMM7 |
| 1290 | }; |
| 1291 | |
Chris Lattner | 638402b | 2007-02-28 07:00:42 +0000 | [diff] [blame] | 1292 | |
| 1293 | // Assign locations to all of the incoming arguments. |
Chris Lattner | fcf1a3d | 2007-02-28 06:10:12 +0000 | [diff] [blame] | 1294 | SmallVector<CCValAssign, 16> ArgLocs; |
Chris Lattner | 52387be | 2007-06-19 00:13:10 +0000 | [diff] [blame] | 1295 | CCState CCInfo(MF.getFunction()->getCallingConv(), isVarArg, |
| 1296 | getTargetMachine(), ArgLocs); |
Chris Lattner | 638402b | 2007-02-28 07:00:42 +0000 | [diff] [blame] | 1297 | CCInfo.AnalyzeFormalArguments(Op.Val, CC_X86_64_C); |
Chris Lattner | fcf1a3d | 2007-02-28 06:10:12 +0000 | [diff] [blame] | 1298 | |
| 1299 | SmallVector<SDOperand, 8> ArgValues; |
| 1300 | unsigned LastVal = ~0U; |
| 1301 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
| 1302 | CCValAssign &VA = ArgLocs[i]; |
| 1303 | // TODO: If an arg is passed in two places (e.g. reg and stack), skip later |
| 1304 | // places. |
| 1305 | assert(VA.getValNo() != LastVal && |
| 1306 | "Don't support value assigned to multiple locs yet"); |
| 1307 | LastVal = VA.getValNo(); |
| 1308 | |
| 1309 | if (VA.isRegLoc()) { |
| 1310 | MVT::ValueType RegVT = VA.getLocVT(); |
| 1311 | TargetRegisterClass *RC; |
| 1312 | if (RegVT == MVT::i32) |
| 1313 | RC = X86::GR32RegisterClass; |
| 1314 | else if (RegVT == MVT::i64) |
| 1315 | RC = X86::GR64RegisterClass; |
| 1316 | else if (RegVT == MVT::f32) |
| 1317 | RC = X86::FR32RegisterClass; |
| 1318 | else if (RegVT == MVT::f64) |
| 1319 | RC = X86::FR64RegisterClass; |
| 1320 | else { |
| 1321 | assert(MVT::isVector(RegVT)); |
Chris Lattner | fdbe720 | 2007-06-09 05:08:10 +0000 | [diff] [blame] | 1322 | if (MVT::getSizeInBits(RegVT) == 64) { |
| 1323 | RC = X86::GR64RegisterClass; // MMX values are passed in GPRs. |
| 1324 | RegVT = MVT::i64; |
| 1325 | } else |
Chris Lattner | 6b7c21c | 2007-06-09 05:01:50 +0000 | [diff] [blame] | 1326 | RC = X86::VR128RegisterClass; |
Chris Lattner | fcf1a3d | 2007-02-28 06:10:12 +0000 | [diff] [blame] | 1327 | } |
Chris Lattner | 82932a5 | 2007-03-02 05:12:29 +0000 | [diff] [blame] | 1328 | |
| 1329 | unsigned Reg = AddLiveIn(DAG.getMachineFunction(), VA.getLocReg(), RC); |
| 1330 | SDOperand ArgValue = DAG.getCopyFromReg(Root, Reg, RegVT); |
Chris Lattner | fcf1a3d | 2007-02-28 06:10:12 +0000 | [diff] [blame] | 1331 | |
| 1332 | // If this is an 8 or 16-bit value, it is really passed promoted to 32 |
| 1333 | // bits. Insert an assert[sz]ext to capture this, then truncate to the |
| 1334 | // right size. |
| 1335 | if (VA.getLocInfo() == CCValAssign::SExt) |
| 1336 | ArgValue = DAG.getNode(ISD::AssertSext, RegVT, ArgValue, |
| 1337 | DAG.getValueType(VA.getValVT())); |
| 1338 | else if (VA.getLocInfo() == CCValAssign::ZExt) |
| 1339 | ArgValue = DAG.getNode(ISD::AssertZext, RegVT, ArgValue, |
| 1340 | DAG.getValueType(VA.getValVT())); |
| 1341 | |
| 1342 | if (VA.getLocInfo() != CCValAssign::Full) |
| 1343 | ArgValue = DAG.getNode(ISD::TRUNCATE, VA.getValVT(), ArgValue); |
| 1344 | |
Chris Lattner | fdbe720 | 2007-06-09 05:08:10 +0000 | [diff] [blame] | 1345 | // Handle MMX values passed in GPRs. |
| 1346 | if (RegVT != VA.getLocVT() && RC == X86::GR64RegisterClass && |
| 1347 | MVT::getSizeInBits(RegVT) == 64) |
| 1348 | ArgValue = DAG.getNode(ISD::BIT_CONVERT, VA.getLocVT(), ArgValue); |
| 1349 | |
Chris Lattner | fcf1a3d | 2007-02-28 06:10:12 +0000 | [diff] [blame] | 1350 | ArgValues.push_back(ArgValue); |
| 1351 | } else { |
| 1352 | assert(VA.isMemLoc()); |
Rafael Espindola | 7effac5 | 2007-09-14 15:48:13 +0000 | [diff] [blame] | 1353 | ArgValues.push_back(LowerMemArgument(Op, DAG, VA, MFI, Root, i)); |
Chris Lattner | fcf1a3d | 2007-02-28 06:10:12 +0000 | [diff] [blame] | 1354 | } |
| 1355 | } |
| 1356 | |
| 1357 | unsigned StackSize = CCInfo.getNextStackOffset(); |
| 1358 | |
| 1359 | // If the function takes variable number of arguments, make a frame index for |
| 1360 | // the start of the first vararg value... for expansion of llvm.va_start. |
| 1361 | if (isVarArg) { |
| 1362 | unsigned NumIntRegs = CCInfo.getFirstUnallocated(GPR64ArgRegs, 6); |
| 1363 | unsigned NumXMMRegs = CCInfo.getFirstUnallocated(XMMArgRegs, 8); |
| 1364 | |
| 1365 | // For X86-64, if there are vararg parameters that are passed via |
| 1366 | // registers, then we must store them to their spots on the stack so they |
| 1367 | // may be loaded by deferencing the result of va_next. |
| 1368 | VarArgsGPOffset = NumIntRegs * 8; |
| 1369 | VarArgsFPOffset = 6 * 8 + NumXMMRegs * 16; |
| 1370 | VarArgsFrameIndex = MFI->CreateFixedObject(1, StackSize); |
| 1371 | RegSaveFrameIndex = MFI->CreateStackObject(6 * 8 + 8 * 16, 16); |
| 1372 | |
| 1373 | // Store the integer parameter registers. |
| 1374 | SmallVector<SDOperand, 8> MemOps; |
| 1375 | SDOperand RSFIN = DAG.getFrameIndex(RegSaveFrameIndex, getPointerTy()); |
| 1376 | SDOperand FIN = DAG.getNode(ISD::ADD, getPointerTy(), RSFIN, |
| 1377 | DAG.getConstant(VarArgsGPOffset, getPointerTy())); |
| 1378 | for (; NumIntRegs != 6; ++NumIntRegs) { |
| 1379 | unsigned VReg = AddLiveIn(MF, GPR64ArgRegs[NumIntRegs], |
| 1380 | X86::GR64RegisterClass); |
| 1381 | SDOperand Val = DAG.getCopyFromReg(Root, VReg, MVT::i64); |
| 1382 | SDOperand Store = DAG.getStore(Val.getValue(1), Val, FIN, NULL, 0); |
| 1383 | MemOps.push_back(Store); |
| 1384 | FIN = DAG.getNode(ISD::ADD, getPointerTy(), FIN, |
| 1385 | DAG.getConstant(8, getPointerTy())); |
| 1386 | } |
| 1387 | |
| 1388 | // Now store the XMM (fp + vector) parameter registers. |
| 1389 | FIN = DAG.getNode(ISD::ADD, getPointerTy(), RSFIN, |
| 1390 | DAG.getConstant(VarArgsFPOffset, getPointerTy())); |
| 1391 | for (; NumXMMRegs != 8; ++NumXMMRegs) { |
| 1392 | unsigned VReg = AddLiveIn(MF, XMMArgRegs[NumXMMRegs], |
| 1393 | X86::VR128RegisterClass); |
| 1394 | SDOperand Val = DAG.getCopyFromReg(Root, VReg, MVT::v4f32); |
| 1395 | SDOperand Store = DAG.getStore(Val.getValue(1), Val, FIN, NULL, 0); |
| 1396 | MemOps.push_back(Store); |
| 1397 | FIN = DAG.getNode(ISD::ADD, getPointerTy(), FIN, |
| 1398 | DAG.getConstant(16, getPointerTy())); |
| 1399 | } |
| 1400 | if (!MemOps.empty()) |
| 1401 | Root = DAG.getNode(ISD::TokenFactor, MVT::Other, |
| 1402 | &MemOps[0], MemOps.size()); |
| 1403 | } |
| 1404 | |
| 1405 | ArgValues.push_back(Root); |
| 1406 | |
Chris Lattner | fcf1a3d | 2007-02-28 06:10:12 +0000 | [diff] [blame] | 1407 | BytesToPopOnReturn = 0; // Callee pops nothing. |
| 1408 | BytesCallerReserves = StackSize; |
| 1409 | |
Anton Korobeynikov | a2780e1 | 2007-08-15 17:12:32 +0000 | [diff] [blame] | 1410 | X86MachineFunctionInfo *FuncInfo = MF.getInfo<X86MachineFunctionInfo>(); |
| 1411 | FuncInfo->setBytesToPopOnReturn(BytesToPopOnReturn); |
| 1412 | |
Chris Lattner | fcf1a3d | 2007-02-28 06:10:12 +0000 | [diff] [blame] | 1413 | // Return the new list of results. |
| 1414 | return DAG.getNode(ISD::MERGE_VALUES, Op.Val->getVTList(), |
| 1415 | &ArgValues[0], ArgValues.size()).getValue(Op.ResNo); |
| 1416 | } |
| 1417 | |
| 1418 | SDOperand |
| 1419 | X86TargetLowering::LowerX86_64CCCCallTo(SDOperand Op, SelectionDAG &DAG, |
| 1420 | unsigned CC) { |
| 1421 | SDOperand Chain = Op.getOperand(0); |
| 1422 | bool isVarArg = cast<ConstantSDNode>(Op.getOperand(2))->getValue() != 0; |
| 1423 | bool isTailCall = cast<ConstantSDNode>(Op.getOperand(3))->getValue() != 0; |
| 1424 | SDOperand Callee = Op.getOperand(4); |
Chris Lattner | 638402b | 2007-02-28 07:00:42 +0000 | [diff] [blame] | 1425 | |
| 1426 | // Analyze operands of the call, assigning locations to each operand. |
Chris Lattner | fcf1a3d | 2007-02-28 06:10:12 +0000 | [diff] [blame] | 1427 | SmallVector<CCValAssign, 16> ArgLocs; |
Chris Lattner | 52387be | 2007-06-19 00:13:10 +0000 | [diff] [blame] | 1428 | CCState CCInfo(CC, isVarArg, getTargetMachine(), ArgLocs); |
Chris Lattner | 638402b | 2007-02-28 07:00:42 +0000 | [diff] [blame] | 1429 | CCInfo.AnalyzeCallOperands(Op.Val, CC_X86_64_C); |
Chris Lattner | fcf1a3d | 2007-02-28 06:10:12 +0000 | [diff] [blame] | 1430 | |
| 1431 | // Get a count of how many bytes are to be pushed on the stack. |
| 1432 | unsigned NumBytes = CCInfo.getNextStackOffset(); |
| 1433 | Chain = DAG.getCALLSEQ_START(Chain,DAG.getConstant(NumBytes, getPointerTy())); |
| 1434 | |
| 1435 | SmallVector<std::pair<unsigned, SDOperand>, 8> RegsToPass; |
| 1436 | SmallVector<SDOperand, 8> MemOpChains; |
| 1437 | |
| 1438 | SDOperand StackPtr; |
| 1439 | |
| 1440 | // Walk the register/memloc assignments, inserting copies/loads. |
| 1441 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
| 1442 | CCValAssign &VA = ArgLocs[i]; |
| 1443 | SDOperand Arg = Op.getOperand(5+2*VA.getValNo()); |
| 1444 | |
| 1445 | // Promote the value if needed. |
| 1446 | switch (VA.getLocInfo()) { |
| 1447 | default: assert(0 && "Unknown loc info!"); |
| 1448 | case CCValAssign::Full: break; |
| 1449 | case CCValAssign::SExt: |
| 1450 | Arg = DAG.getNode(ISD::SIGN_EXTEND, VA.getLocVT(), Arg); |
| 1451 | break; |
| 1452 | case CCValAssign::ZExt: |
| 1453 | Arg = DAG.getNode(ISD::ZERO_EXTEND, VA.getLocVT(), Arg); |
| 1454 | break; |
| 1455 | case CCValAssign::AExt: |
| 1456 | Arg = DAG.getNode(ISD::ANY_EXTEND, VA.getLocVT(), Arg); |
| 1457 | break; |
| 1458 | } |
| 1459 | |
| 1460 | if (VA.isRegLoc()) { |
| 1461 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg)); |
| 1462 | } else { |
| 1463 | assert(VA.isMemLoc()); |
| 1464 | if (StackPtr.Val == 0) |
| 1465 | StackPtr = DAG.getRegister(getStackPtrReg(), getPointerTy()); |
Rafael Espindola | 21485be | 2007-08-20 15:18:24 +0000 | [diff] [blame] | 1466 | |
Rafael Espindola | 1b5dcc3 | 2007-08-31 15:06:30 +0000 | [diff] [blame] | 1467 | MemOpChains.push_back(LowerMemOpCallTo(Op, DAG, StackPtr, VA, Chain, |
| 1468 | Arg)); |
Chris Lattner | fcf1a3d | 2007-02-28 06:10:12 +0000 | [diff] [blame] | 1469 | } |
| 1470 | } |
| 1471 | |
| 1472 | if (!MemOpChains.empty()) |
| 1473 | Chain = DAG.getNode(ISD::TokenFactor, MVT::Other, |
| 1474 | &MemOpChains[0], MemOpChains.size()); |
| 1475 | |
| 1476 | // Build a sequence of copy-to-reg nodes chained together with token chain |
| 1477 | // and flag operands which copy the outgoing args into registers. |
| 1478 | SDOperand InFlag; |
| 1479 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 1480 | Chain = DAG.getCopyToReg(Chain, RegsToPass[i].first, RegsToPass[i].second, |
| 1481 | InFlag); |
| 1482 | InFlag = Chain.getValue(1); |
| 1483 | } |
| 1484 | |
| 1485 | if (isVarArg) { |
| 1486 | // From AMD64 ABI document: |
| 1487 | // For calls that may call functions that use varargs or stdargs |
| 1488 | // (prototype-less calls or calls to functions containing ellipsis (...) in |
| 1489 | // the declaration) %al is used as hidden argument to specify the number |
| 1490 | // of SSE registers used. The contents of %al do not need to match exactly |
| 1491 | // the number of registers, but must be an ubound on the number of SSE |
| 1492 | // registers used and is in the range 0 - 8 inclusive. |
| 1493 | |
| 1494 | // Count the number of XMM registers allocated. |
| 1495 | static const unsigned XMMArgRegs[] = { |
| 1496 | X86::XMM0, X86::XMM1, X86::XMM2, X86::XMM3, |
| 1497 | X86::XMM4, X86::XMM5, X86::XMM6, X86::XMM7 |
| 1498 | }; |
| 1499 | unsigned NumXMMRegs = CCInfo.getFirstUnallocated(XMMArgRegs, 8); |
| 1500 | |
| 1501 | Chain = DAG.getCopyToReg(Chain, X86::AL, |
| 1502 | DAG.getConstant(NumXMMRegs, MVT::i8), InFlag); |
| 1503 | InFlag = Chain.getValue(1); |
| 1504 | } |
| 1505 | |
| 1506 | // If the callee is a GlobalAddress node (quite common, every direct call is) |
| 1507 | // turn it into a TargetGlobalAddress node so that legalize doesn't hack it. |
| 1508 | if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { |
| 1509 | // We should use extra load for direct calls to dllimported functions in |
| 1510 | // non-JIT mode. |
Evan Cheng | ba69300 | 2007-03-14 22:11:11 +0000 | [diff] [blame] | 1511 | if (getTargetMachine().getCodeModel() != CodeModel::Large |
Anton Korobeynikov | bed2946 | 2007-04-16 18:10:23 +0000 | [diff] [blame] | 1512 | && !Subtarget->GVRequiresExtraLoad(G->getGlobal(), |
| 1513 | getTargetMachine(), true)) |
Chris Lattner | fcf1a3d | 2007-02-28 06:10:12 +0000 | [diff] [blame] | 1514 | Callee = DAG.getTargetGlobalAddress(G->getGlobal(), getPointerTy()); |
| 1515 | } else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee)) |
Evan Cheng | ba69300 | 2007-03-14 22:11:11 +0000 | [diff] [blame] | 1516 | if (getTargetMachine().getCodeModel() != CodeModel::Large) |
| 1517 | Callee = DAG.getTargetExternalSymbol(S->getSymbol(), getPointerTy()); |
Chris Lattner | fcf1a3d | 2007-02-28 06:10:12 +0000 | [diff] [blame] | 1518 | |
| 1519 | // Returns a chain & a flag for retval copy to use. |
| 1520 | SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Flag); |
| 1521 | SmallVector<SDOperand, 8> Ops; |
| 1522 | Ops.push_back(Chain); |
| 1523 | Ops.push_back(Callee); |
| 1524 | |
| 1525 | // Add argument registers to the end of the list so that they are known live |
| 1526 | // into the call. |
| 1527 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) |
| 1528 | Ops.push_back(DAG.getRegister(RegsToPass[i].first, |
| 1529 | RegsToPass[i].second.getValueType())); |
| 1530 | |
| 1531 | if (InFlag.Val) |
| 1532 | Ops.push_back(InFlag); |
| 1533 | |
| 1534 | // FIXME: Do not generate X86ISD::TAILCALL for now. |
| 1535 | Chain = DAG.getNode(isTailCall ? X86ISD::TAILCALL : X86ISD::CALL, |
| 1536 | NodeTys, &Ops[0], Ops.size()); |
| 1537 | InFlag = Chain.getValue(1); |
| 1538 | |
| 1539 | // Returns a flag for retval copy to use. |
| 1540 | NodeTys = DAG.getVTList(MVT::Other, MVT::Flag); |
| 1541 | Ops.clear(); |
| 1542 | Ops.push_back(Chain); |
| 1543 | Ops.push_back(DAG.getConstant(NumBytes, getPointerTy())); |
| 1544 | Ops.push_back(DAG.getConstant(0, getPointerTy())); |
| 1545 | Ops.push_back(InFlag); |
| 1546 | Chain = DAG.getNode(ISD::CALLSEQ_END, NodeTys, &Ops[0], Ops.size()); |
| 1547 | InFlag = Chain.getValue(1); |
| 1548 | |
| 1549 | // Handle result values, copying them out of physregs into vregs that we |
| 1550 | // return. |
| 1551 | return SDOperand(LowerCallResult(Chain, InFlag, Op.Val, CC, DAG), Op.ResNo); |
| 1552 | } |
| 1553 | |
| 1554 | |
| 1555 | //===----------------------------------------------------------------------===// |
| 1556 | // Other Lowering Hooks |
| 1557 | //===----------------------------------------------------------------------===// |
| 1558 | |
| 1559 | |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 1560 | SDOperand X86TargetLowering::getReturnAddressFrameIndex(SelectionDAG &DAG) { |
Anton Korobeynikov | a2780e1 | 2007-08-15 17:12:32 +0000 | [diff] [blame] | 1561 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1562 | X86MachineFunctionInfo *FuncInfo = MF.getInfo<X86MachineFunctionInfo>(); |
| 1563 | int ReturnAddrIndex = FuncInfo->getRAIndex(); |
| 1564 | |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 1565 | if (ReturnAddrIndex == 0) { |
| 1566 | // Set up a frame object for the return address. |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 1567 | if (Subtarget->is64Bit()) |
| 1568 | ReturnAddrIndex = MF.getFrameInfo()->CreateFixedObject(8, -8); |
| 1569 | else |
| 1570 | ReturnAddrIndex = MF.getFrameInfo()->CreateFixedObject(4, -4); |
Anton Korobeynikov | a2780e1 | 2007-08-15 17:12:32 +0000 | [diff] [blame] | 1571 | |
| 1572 | FuncInfo->setRAIndex(ReturnAddrIndex); |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 1573 | } |
| 1574 | |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 1575 | return DAG.getFrameIndex(ReturnAddrIndex, getPointerTy()); |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 1576 | } |
| 1577 | |
| 1578 | |
| 1579 | |
Evan Cheng | 6dfa999 | 2006-01-30 23:41:35 +0000 | [diff] [blame] | 1580 | /// translateX86CC - do a one to one translation of a ISD::CondCode to the X86 |
| 1581 | /// specific condition code. It returns a false if it cannot do a direct |
Chris Lattner | f957051 | 2006-09-13 03:22:10 +0000 | [diff] [blame] | 1582 | /// translation. X86CC is the translated CondCode. LHS/RHS are modified as |
| 1583 | /// needed. |
Evan Cheng | 6be2c58 | 2006-04-05 23:38:46 +0000 | [diff] [blame] | 1584 | static bool translateX86CC(ISD::CondCode SetCCOpcode, bool isFP, |
Chris Lattner | f957051 | 2006-09-13 03:22:10 +0000 | [diff] [blame] | 1585 | unsigned &X86CC, SDOperand &LHS, SDOperand &RHS, |
| 1586 | SelectionDAG &DAG) { |
Chris Lattner | 7fbe972 | 2006-10-20 17:42:20 +0000 | [diff] [blame] | 1587 | X86CC = X86::COND_INVALID; |
Evan Cheng | d9558e0 | 2006-01-06 00:43:03 +0000 | [diff] [blame] | 1588 | if (!isFP) { |
Chris Lattner | bfd68a7 | 2006-09-13 17:04:54 +0000 | [diff] [blame] | 1589 | if (ConstantSDNode *RHSC = dyn_cast<ConstantSDNode>(RHS)) { |
| 1590 | if (SetCCOpcode == ISD::SETGT && RHSC->isAllOnesValue()) { |
| 1591 | // X > -1 -> X == 0, jump !sign. |
| 1592 | RHS = DAG.getConstant(0, RHS.getValueType()); |
Chris Lattner | 7fbe972 | 2006-10-20 17:42:20 +0000 | [diff] [blame] | 1593 | X86CC = X86::COND_NS; |
Chris Lattner | bfd68a7 | 2006-09-13 17:04:54 +0000 | [diff] [blame] | 1594 | return true; |
| 1595 | } else if (SetCCOpcode == ISD::SETLT && RHSC->isNullValue()) { |
| 1596 | // X < 0 -> X == 0, jump on sign. |
Chris Lattner | 7fbe972 | 2006-10-20 17:42:20 +0000 | [diff] [blame] | 1597 | X86CC = X86::COND_S; |
Chris Lattner | bfd68a7 | 2006-09-13 17:04:54 +0000 | [diff] [blame] | 1598 | return true; |
Dan Gohman | 5f6913c | 2007-09-17 14:49:27 +0000 | [diff] [blame] | 1599 | } else if (SetCCOpcode == ISD::SETLT && RHSC->getValue() == 1) { |
| 1600 | // X < 1 -> X <= 0 |
| 1601 | RHS = DAG.getConstant(0, RHS.getValueType()); |
| 1602 | X86CC = X86::COND_LE; |
| 1603 | return true; |
Chris Lattner | bfd68a7 | 2006-09-13 17:04:54 +0000 | [diff] [blame] | 1604 | } |
Chris Lattner | f957051 | 2006-09-13 03:22:10 +0000 | [diff] [blame] | 1605 | } |
Anton Korobeynikov | 12c49af | 2006-11-21 00:01:06 +0000 | [diff] [blame] | 1606 | |
Evan Cheng | d9558e0 | 2006-01-06 00:43:03 +0000 | [diff] [blame] | 1607 | switch (SetCCOpcode) { |
| 1608 | default: break; |
Chris Lattner | 7fbe972 | 2006-10-20 17:42:20 +0000 | [diff] [blame] | 1609 | case ISD::SETEQ: X86CC = X86::COND_E; break; |
| 1610 | case ISD::SETGT: X86CC = X86::COND_G; break; |
| 1611 | case ISD::SETGE: X86CC = X86::COND_GE; break; |
| 1612 | case ISD::SETLT: X86CC = X86::COND_L; break; |
| 1613 | case ISD::SETLE: X86CC = X86::COND_LE; break; |
| 1614 | case ISD::SETNE: X86CC = X86::COND_NE; break; |
| 1615 | case ISD::SETULT: X86CC = X86::COND_B; break; |
| 1616 | case ISD::SETUGT: X86CC = X86::COND_A; break; |
| 1617 | case ISD::SETULE: X86CC = X86::COND_BE; break; |
| 1618 | case ISD::SETUGE: X86CC = X86::COND_AE; break; |
Evan Cheng | d9558e0 | 2006-01-06 00:43:03 +0000 | [diff] [blame] | 1619 | } |
| 1620 | } else { |
| 1621 | // On a floating point condition, the flags are set as follows: |
| 1622 | // ZF PF CF op |
| 1623 | // 0 | 0 | 0 | X > Y |
| 1624 | // 0 | 0 | 1 | X < Y |
| 1625 | // 1 | 0 | 0 | X == Y |
| 1626 | // 1 | 1 | 1 | unordered |
Chris Lattner | f957051 | 2006-09-13 03:22:10 +0000 | [diff] [blame] | 1627 | bool Flip = false; |
Evan Cheng | d9558e0 | 2006-01-06 00:43:03 +0000 | [diff] [blame] | 1628 | switch (SetCCOpcode) { |
| 1629 | default: break; |
| 1630 | case ISD::SETUEQ: |
Chris Lattner | 7fbe972 | 2006-10-20 17:42:20 +0000 | [diff] [blame] | 1631 | case ISD::SETEQ: X86CC = X86::COND_E; break; |
Evan Cheng | 5001ea1 | 2006-04-17 07:24:10 +0000 | [diff] [blame] | 1632 | case ISD::SETOLT: Flip = true; // Fallthrough |
Evan Cheng | d9558e0 | 2006-01-06 00:43:03 +0000 | [diff] [blame] | 1633 | case ISD::SETOGT: |
Chris Lattner | 7fbe972 | 2006-10-20 17:42:20 +0000 | [diff] [blame] | 1634 | case ISD::SETGT: X86CC = X86::COND_A; break; |
Evan Cheng | 5001ea1 | 2006-04-17 07:24:10 +0000 | [diff] [blame] | 1635 | case ISD::SETOLE: Flip = true; // Fallthrough |
Evan Cheng | d9558e0 | 2006-01-06 00:43:03 +0000 | [diff] [blame] | 1636 | case ISD::SETOGE: |
Chris Lattner | 7fbe972 | 2006-10-20 17:42:20 +0000 | [diff] [blame] | 1637 | case ISD::SETGE: X86CC = X86::COND_AE; break; |
Evan Cheng | 5001ea1 | 2006-04-17 07:24:10 +0000 | [diff] [blame] | 1638 | case ISD::SETUGT: Flip = true; // Fallthrough |
Evan Cheng | d9558e0 | 2006-01-06 00:43:03 +0000 | [diff] [blame] | 1639 | case ISD::SETULT: |
Chris Lattner | 7fbe972 | 2006-10-20 17:42:20 +0000 | [diff] [blame] | 1640 | case ISD::SETLT: X86CC = X86::COND_B; break; |
Evan Cheng | 5001ea1 | 2006-04-17 07:24:10 +0000 | [diff] [blame] | 1641 | case ISD::SETUGE: Flip = true; // Fallthrough |
Evan Cheng | d9558e0 | 2006-01-06 00:43:03 +0000 | [diff] [blame] | 1642 | case ISD::SETULE: |
Chris Lattner | 7fbe972 | 2006-10-20 17:42:20 +0000 | [diff] [blame] | 1643 | case ISD::SETLE: X86CC = X86::COND_BE; break; |
Evan Cheng | d9558e0 | 2006-01-06 00:43:03 +0000 | [diff] [blame] | 1644 | case ISD::SETONE: |
Chris Lattner | 7fbe972 | 2006-10-20 17:42:20 +0000 | [diff] [blame] | 1645 | case ISD::SETNE: X86CC = X86::COND_NE; break; |
| 1646 | case ISD::SETUO: X86CC = X86::COND_P; break; |
| 1647 | case ISD::SETO: X86CC = X86::COND_NP; break; |
Evan Cheng | d9558e0 | 2006-01-06 00:43:03 +0000 | [diff] [blame] | 1648 | } |
Chris Lattner | f957051 | 2006-09-13 03:22:10 +0000 | [diff] [blame] | 1649 | if (Flip) |
| 1650 | std::swap(LHS, RHS); |
Evan Cheng | d9558e0 | 2006-01-06 00:43:03 +0000 | [diff] [blame] | 1651 | } |
Evan Cheng | 6dfa999 | 2006-01-30 23:41:35 +0000 | [diff] [blame] | 1652 | |
Chris Lattner | 7fbe972 | 2006-10-20 17:42:20 +0000 | [diff] [blame] | 1653 | return X86CC != X86::COND_INVALID; |
Evan Cheng | d9558e0 | 2006-01-06 00:43:03 +0000 | [diff] [blame] | 1654 | } |
| 1655 | |
Evan Cheng | 4a46080 | 2006-01-11 00:33:36 +0000 | [diff] [blame] | 1656 | /// hasFPCMov - is there a floating point cmov for the specific X86 condition |
| 1657 | /// code. Current x86 isa includes the following FP cmov instructions: |
Evan Cheng | aaca22c | 2006-01-10 20:26:56 +0000 | [diff] [blame] | 1658 | /// fcmovb, fcomvbe, fcomve, fcmovu, fcmovae, fcmova, fcmovne, fcmovnu. |
Evan Cheng | 4a46080 | 2006-01-11 00:33:36 +0000 | [diff] [blame] | 1659 | static bool hasFPCMov(unsigned X86CC) { |
Evan Cheng | aaca22c | 2006-01-10 20:26:56 +0000 | [diff] [blame] | 1660 | switch (X86CC) { |
| 1661 | default: |
| 1662 | return false; |
Chris Lattner | 7fbe972 | 2006-10-20 17:42:20 +0000 | [diff] [blame] | 1663 | case X86::COND_B: |
| 1664 | case X86::COND_BE: |
| 1665 | case X86::COND_E: |
| 1666 | case X86::COND_P: |
| 1667 | case X86::COND_A: |
| 1668 | case X86::COND_AE: |
| 1669 | case X86::COND_NE: |
| 1670 | case X86::COND_NP: |
Evan Cheng | aaca22c | 2006-01-10 20:26:56 +0000 | [diff] [blame] | 1671 | return true; |
| 1672 | } |
| 1673 | } |
| 1674 | |
Evan Cheng | 5ced1d8 | 2006-04-06 23:23:56 +0000 | [diff] [blame] | 1675 | /// isUndefOrInRange - Op is either an undef node or a ConstantSDNode. Return |
Evan Cheng | c5cdff2 | 2006-04-07 21:53:05 +0000 | [diff] [blame] | 1676 | /// true if Op is undef or if its value falls within the specified range (L, H]. |
Evan Cheng | 5ced1d8 | 2006-04-06 23:23:56 +0000 | [diff] [blame] | 1677 | static bool isUndefOrInRange(SDOperand Op, unsigned Low, unsigned Hi) { |
| 1678 | if (Op.getOpcode() == ISD::UNDEF) |
| 1679 | return true; |
| 1680 | |
| 1681 | unsigned Val = cast<ConstantSDNode>(Op)->getValue(); |
Evan Cheng | c5cdff2 | 2006-04-07 21:53:05 +0000 | [diff] [blame] | 1682 | return (Val >= Low && Val < Hi); |
| 1683 | } |
| 1684 | |
| 1685 | /// isUndefOrEqual - Op is either an undef node or a ConstantSDNode. Return |
| 1686 | /// true if Op is undef or if its value equal to the specified value. |
| 1687 | static bool isUndefOrEqual(SDOperand Op, unsigned Val) { |
| 1688 | if (Op.getOpcode() == ISD::UNDEF) |
| 1689 | return true; |
| 1690 | return cast<ConstantSDNode>(Op)->getValue() == Val; |
Evan Cheng | 5ced1d8 | 2006-04-06 23:23:56 +0000 | [diff] [blame] | 1691 | } |
| 1692 | |
Evan Cheng | 0188ecb | 2006-03-22 18:59:22 +0000 | [diff] [blame] | 1693 | /// isPSHUFDMask - Return true if the specified VECTOR_SHUFFLE operand |
| 1694 | /// specifies a shuffle of elements that is suitable for input to PSHUFD. |
| 1695 | bool X86::isPSHUFDMask(SDNode *N) { |
| 1696 | assert(N->getOpcode() == ISD::BUILD_VECTOR); |
| 1697 | |
Dan Gohman | 7f55fcb | 2007-08-02 21:17:01 +0000 | [diff] [blame] | 1698 | if (N->getNumOperands() != 2 && N->getNumOperands() != 4) |
Evan Cheng | 0188ecb | 2006-03-22 18:59:22 +0000 | [diff] [blame] | 1699 | return false; |
| 1700 | |
| 1701 | // Check if the value doesn't reference the second vector. |
Evan Cheng | 506d3df | 2006-03-29 23:07:14 +0000 | [diff] [blame] | 1702 | for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) { |
Evan Cheng | ef698ca | 2006-03-31 00:30:29 +0000 | [diff] [blame] | 1703 | SDOperand Arg = N->getOperand(i); |
| 1704 | if (Arg.getOpcode() == ISD::UNDEF) continue; |
| 1705 | assert(isa<ConstantSDNode>(Arg) && "Invalid VECTOR_SHUFFLE mask!"); |
Dan Gohman | 7f55fcb | 2007-08-02 21:17:01 +0000 | [diff] [blame] | 1706 | if (cast<ConstantSDNode>(Arg)->getValue() >= e) |
Evan Cheng | 506d3df | 2006-03-29 23:07:14 +0000 | [diff] [blame] | 1707 | return false; |
| 1708 | } |
| 1709 | |
| 1710 | return true; |
| 1711 | } |
| 1712 | |
| 1713 | /// isPSHUFHWMask - Return true if the specified VECTOR_SHUFFLE operand |
Evan Cheng | c21a053 | 2006-04-05 01:47:37 +0000 | [diff] [blame] | 1714 | /// specifies a shuffle of elements that is suitable for input to PSHUFHW. |
Evan Cheng | 506d3df | 2006-03-29 23:07:14 +0000 | [diff] [blame] | 1715 | bool X86::isPSHUFHWMask(SDNode *N) { |
| 1716 | assert(N->getOpcode() == ISD::BUILD_VECTOR); |
| 1717 | |
| 1718 | if (N->getNumOperands() != 8) |
| 1719 | return false; |
| 1720 | |
| 1721 | // Lower quadword copied in order. |
| 1722 | for (unsigned i = 0; i != 4; ++i) { |
Evan Cheng | ef698ca | 2006-03-31 00:30:29 +0000 | [diff] [blame] | 1723 | SDOperand Arg = N->getOperand(i); |
| 1724 | if (Arg.getOpcode() == ISD::UNDEF) continue; |
| 1725 | assert(isa<ConstantSDNode>(Arg) && "Invalid VECTOR_SHUFFLE mask!"); |
| 1726 | if (cast<ConstantSDNode>(Arg)->getValue() != i) |
Evan Cheng | 506d3df | 2006-03-29 23:07:14 +0000 | [diff] [blame] | 1727 | return false; |
| 1728 | } |
| 1729 | |
| 1730 | // Upper quadword shuffled. |
| 1731 | for (unsigned i = 4; i != 8; ++i) { |
Evan Cheng | ef698ca | 2006-03-31 00:30:29 +0000 | [diff] [blame] | 1732 | SDOperand Arg = N->getOperand(i); |
| 1733 | if (Arg.getOpcode() == ISD::UNDEF) continue; |
| 1734 | assert(isa<ConstantSDNode>(Arg) && "Invalid VECTOR_SHUFFLE mask!"); |
| 1735 | unsigned Val = cast<ConstantSDNode>(Arg)->getValue(); |
Evan Cheng | 506d3df | 2006-03-29 23:07:14 +0000 | [diff] [blame] | 1736 | if (Val < 4 || Val > 7) |
| 1737 | return false; |
| 1738 | } |
| 1739 | |
| 1740 | return true; |
| 1741 | } |
| 1742 | |
| 1743 | /// isPSHUFLWMask - Return true if the specified VECTOR_SHUFFLE operand |
Evan Cheng | c21a053 | 2006-04-05 01:47:37 +0000 | [diff] [blame] | 1744 | /// specifies a shuffle of elements that is suitable for input to PSHUFLW. |
Evan Cheng | 506d3df | 2006-03-29 23:07:14 +0000 | [diff] [blame] | 1745 | bool X86::isPSHUFLWMask(SDNode *N) { |
| 1746 | assert(N->getOpcode() == ISD::BUILD_VECTOR); |
| 1747 | |
| 1748 | if (N->getNumOperands() != 8) |
| 1749 | return false; |
| 1750 | |
| 1751 | // Upper quadword copied in order. |
Evan Cheng | c5cdff2 | 2006-04-07 21:53:05 +0000 | [diff] [blame] | 1752 | for (unsigned i = 4; i != 8; ++i) |
| 1753 | if (!isUndefOrEqual(N->getOperand(i), i)) |
Evan Cheng | 506d3df | 2006-03-29 23:07:14 +0000 | [diff] [blame] | 1754 | return false; |
Evan Cheng | 506d3df | 2006-03-29 23:07:14 +0000 | [diff] [blame] | 1755 | |
| 1756 | // Lower quadword shuffled. |
Evan Cheng | c5cdff2 | 2006-04-07 21:53:05 +0000 | [diff] [blame] | 1757 | for (unsigned i = 0; i != 4; ++i) |
| 1758 | if (!isUndefOrInRange(N->getOperand(i), 0, 4)) |
Evan Cheng | 506d3df | 2006-03-29 23:07:14 +0000 | [diff] [blame] | 1759 | return false; |
Evan Cheng | 0188ecb | 2006-03-22 18:59:22 +0000 | [diff] [blame] | 1760 | |
| 1761 | return true; |
| 1762 | } |
| 1763 | |
Evan Cheng | 14aed5e | 2006-03-24 01:18:28 +0000 | [diff] [blame] | 1764 | /// isSHUFPMask - Return true if the specified VECTOR_SHUFFLE operand |
| 1765 | /// specifies a shuffle of elements that is suitable for input to SHUFP*. |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 1766 | static bool isSHUFPMask(const SDOperand *Elems, unsigned NumElems) { |
Evan Cheng | 39623da | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 1767 | if (NumElems != 2 && NumElems != 4) return false; |
Evan Cheng | 14aed5e | 2006-03-24 01:18:28 +0000 | [diff] [blame] | 1768 | |
Evan Cheng | 39623da | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 1769 | unsigned Half = NumElems / 2; |
| 1770 | for (unsigned i = 0; i < Half; ++i) |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 1771 | if (!isUndefOrInRange(Elems[i], 0, NumElems)) |
Evan Cheng | 39623da | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 1772 | return false; |
| 1773 | for (unsigned i = Half; i < NumElems; ++i) |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 1774 | if (!isUndefOrInRange(Elems[i], NumElems, NumElems*2)) |
Evan Cheng | 39623da | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 1775 | return false; |
Evan Cheng | 14aed5e | 2006-03-24 01:18:28 +0000 | [diff] [blame] | 1776 | |
| 1777 | return true; |
| 1778 | } |
| 1779 | |
Evan Cheng | 39623da | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 1780 | bool X86::isSHUFPMask(SDNode *N) { |
| 1781 | assert(N->getOpcode() == ISD::BUILD_VECTOR); |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 1782 | return ::isSHUFPMask(N->op_begin(), N->getNumOperands()); |
Evan Cheng | 39623da | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 1783 | } |
| 1784 | |
Evan Cheng | 213d2cf | 2007-05-17 18:45:50 +0000 | [diff] [blame] | 1785 | /// isCommutedSHUFP - Returns true if the shuffle mask is exactly |
Evan Cheng | 39623da | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 1786 | /// the reverse of what x86 shuffles want. x86 shuffles requires the lower |
| 1787 | /// half elements to come from vector 1 (which would equal the dest.) and |
| 1788 | /// the upper half to come from vector 2. |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 1789 | static bool isCommutedSHUFP(const SDOperand *Ops, unsigned NumOps) { |
| 1790 | if (NumOps != 2 && NumOps != 4) return false; |
Evan Cheng | 39623da | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 1791 | |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 1792 | unsigned Half = NumOps / 2; |
Evan Cheng | 39623da | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 1793 | for (unsigned i = 0; i < Half; ++i) |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 1794 | if (!isUndefOrInRange(Ops[i], NumOps, NumOps*2)) |
Evan Cheng | 39623da | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 1795 | return false; |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 1796 | for (unsigned i = Half; i < NumOps; ++i) |
| 1797 | if (!isUndefOrInRange(Ops[i], 0, NumOps)) |
Evan Cheng | 39623da | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 1798 | return false; |
| 1799 | return true; |
| 1800 | } |
| 1801 | |
| 1802 | static bool isCommutedSHUFP(SDNode *N) { |
| 1803 | assert(N->getOpcode() == ISD::BUILD_VECTOR); |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 1804 | return isCommutedSHUFP(N->op_begin(), N->getNumOperands()); |
Evan Cheng | 39623da | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 1805 | } |
| 1806 | |
Evan Cheng | 2c0dbd0 | 2006-03-24 02:58:06 +0000 | [diff] [blame] | 1807 | /// isMOVHLPSMask - Return true if the specified VECTOR_SHUFFLE operand |
| 1808 | /// specifies a shuffle of elements that is suitable for input to MOVHLPS. |
| 1809 | bool X86::isMOVHLPSMask(SDNode *N) { |
| 1810 | assert(N->getOpcode() == ISD::BUILD_VECTOR); |
| 1811 | |
Evan Cheng | 2064a2b | 2006-03-28 06:50:32 +0000 | [diff] [blame] | 1812 | if (N->getNumOperands() != 4) |
Evan Cheng | 2c0dbd0 | 2006-03-24 02:58:06 +0000 | [diff] [blame] | 1813 | return false; |
| 1814 | |
Evan Cheng | 2064a2b | 2006-03-28 06:50:32 +0000 | [diff] [blame] | 1815 | // Expect bit0 == 6, bit1 == 7, bit2 == 2, bit3 == 3 |
Evan Cheng | c5cdff2 | 2006-04-07 21:53:05 +0000 | [diff] [blame] | 1816 | return isUndefOrEqual(N->getOperand(0), 6) && |
| 1817 | isUndefOrEqual(N->getOperand(1), 7) && |
| 1818 | isUndefOrEqual(N->getOperand(2), 2) && |
| 1819 | isUndefOrEqual(N->getOperand(3), 3); |
Evan Cheng | 2064a2b | 2006-03-28 06:50:32 +0000 | [diff] [blame] | 1820 | } |
| 1821 | |
Evan Cheng | 6e56e2c | 2006-11-07 22:14:24 +0000 | [diff] [blame] | 1822 | /// isMOVHLPS_v_undef_Mask - Special case of isMOVHLPSMask for canonical form |
| 1823 | /// of vector_shuffle v, v, <2, 3, 2, 3>, i.e. vector_shuffle v, undef, |
| 1824 | /// <2, 3, 2, 3> |
| 1825 | bool X86::isMOVHLPS_v_undef_Mask(SDNode *N) { |
| 1826 | assert(N->getOpcode() == ISD::BUILD_VECTOR); |
| 1827 | |
| 1828 | if (N->getNumOperands() != 4) |
| 1829 | return false; |
| 1830 | |
| 1831 | // Expect bit0 == 2, bit1 == 3, bit2 == 2, bit3 == 3 |
| 1832 | return isUndefOrEqual(N->getOperand(0), 2) && |
| 1833 | isUndefOrEqual(N->getOperand(1), 3) && |
| 1834 | isUndefOrEqual(N->getOperand(2), 2) && |
| 1835 | isUndefOrEqual(N->getOperand(3), 3); |
| 1836 | } |
| 1837 | |
Evan Cheng | 5ced1d8 | 2006-04-06 23:23:56 +0000 | [diff] [blame] | 1838 | /// isMOVLPMask - Return true if the specified VECTOR_SHUFFLE operand |
| 1839 | /// specifies a shuffle of elements that is suitable for input to MOVLP{S|D}. |
| 1840 | bool X86::isMOVLPMask(SDNode *N) { |
| 1841 | assert(N->getOpcode() == ISD::BUILD_VECTOR); |
| 1842 | |
| 1843 | unsigned NumElems = N->getNumOperands(); |
| 1844 | if (NumElems != 2 && NumElems != 4) |
| 1845 | return false; |
| 1846 | |
Evan Cheng | c5cdff2 | 2006-04-07 21:53:05 +0000 | [diff] [blame] | 1847 | for (unsigned i = 0; i < NumElems/2; ++i) |
| 1848 | if (!isUndefOrEqual(N->getOperand(i), i + NumElems)) |
| 1849 | return false; |
Evan Cheng | 5ced1d8 | 2006-04-06 23:23:56 +0000 | [diff] [blame] | 1850 | |
Evan Cheng | c5cdff2 | 2006-04-07 21:53:05 +0000 | [diff] [blame] | 1851 | for (unsigned i = NumElems/2; i < NumElems; ++i) |
| 1852 | if (!isUndefOrEqual(N->getOperand(i), i)) |
| 1853 | return false; |
Evan Cheng | 5ced1d8 | 2006-04-06 23:23:56 +0000 | [diff] [blame] | 1854 | |
| 1855 | return true; |
| 1856 | } |
| 1857 | |
| 1858 | /// isMOVHPMask - Return true if the specified VECTOR_SHUFFLE operand |
Evan Cheng | 533a0aa | 2006-04-19 20:35:22 +0000 | [diff] [blame] | 1859 | /// specifies a shuffle of elements that is suitable for input to MOVHP{S|D} |
| 1860 | /// and MOVLHPS. |
Evan Cheng | 5ced1d8 | 2006-04-06 23:23:56 +0000 | [diff] [blame] | 1861 | bool X86::isMOVHPMask(SDNode *N) { |
| 1862 | assert(N->getOpcode() == ISD::BUILD_VECTOR); |
| 1863 | |
| 1864 | unsigned NumElems = N->getNumOperands(); |
| 1865 | if (NumElems != 2 && NumElems != 4) |
| 1866 | return false; |
| 1867 | |
Evan Cheng | c5cdff2 | 2006-04-07 21:53:05 +0000 | [diff] [blame] | 1868 | for (unsigned i = 0; i < NumElems/2; ++i) |
| 1869 | if (!isUndefOrEqual(N->getOperand(i), i)) |
| 1870 | return false; |
Evan Cheng | 5ced1d8 | 2006-04-06 23:23:56 +0000 | [diff] [blame] | 1871 | |
| 1872 | for (unsigned i = 0; i < NumElems/2; ++i) { |
| 1873 | SDOperand Arg = N->getOperand(i + NumElems/2); |
Evan Cheng | c5cdff2 | 2006-04-07 21:53:05 +0000 | [diff] [blame] | 1874 | if (!isUndefOrEqual(Arg, i + NumElems)) |
| 1875 | return false; |
Evan Cheng | 5ced1d8 | 2006-04-06 23:23:56 +0000 | [diff] [blame] | 1876 | } |
| 1877 | |
| 1878 | return true; |
| 1879 | } |
| 1880 | |
Evan Cheng | 0038e59 | 2006-03-28 00:39:58 +0000 | [diff] [blame] | 1881 | /// isUNPCKLMask - Return true if the specified VECTOR_SHUFFLE operand |
| 1882 | /// specifies a shuffle of elements that is suitable for input to UNPCKL. |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 1883 | bool static isUNPCKLMask(const SDOperand *Elts, unsigned NumElts, |
| 1884 | bool V2IsSplat = false) { |
| 1885 | if (NumElts != 2 && NumElts != 4 && NumElts != 8 && NumElts != 16) |
Evan Cheng | 0038e59 | 2006-03-28 00:39:58 +0000 | [diff] [blame] | 1886 | return false; |
| 1887 | |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 1888 | for (unsigned i = 0, j = 0; i != NumElts; i += 2, ++j) { |
| 1889 | SDOperand BitI = Elts[i]; |
| 1890 | SDOperand BitI1 = Elts[i+1]; |
Evan Cheng | c5cdff2 | 2006-04-07 21:53:05 +0000 | [diff] [blame] | 1891 | if (!isUndefOrEqual(BitI, j)) |
| 1892 | return false; |
Evan Cheng | 39623da | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 1893 | if (V2IsSplat) { |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 1894 | if (isUndefOrEqual(BitI1, NumElts)) |
Evan Cheng | 39623da | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 1895 | return false; |
| 1896 | } else { |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 1897 | if (!isUndefOrEqual(BitI1, j + NumElts)) |
Evan Cheng | 39623da | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 1898 | return false; |
| 1899 | } |
Evan Cheng | 0038e59 | 2006-03-28 00:39:58 +0000 | [diff] [blame] | 1900 | } |
| 1901 | |
| 1902 | return true; |
| 1903 | } |
| 1904 | |
Evan Cheng | 39623da | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 1905 | bool X86::isUNPCKLMask(SDNode *N, bool V2IsSplat) { |
| 1906 | assert(N->getOpcode() == ISD::BUILD_VECTOR); |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 1907 | return ::isUNPCKLMask(N->op_begin(), N->getNumOperands(), V2IsSplat); |
Evan Cheng | 39623da | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 1908 | } |
| 1909 | |
Evan Cheng | 4fcb922 | 2006-03-28 02:43:26 +0000 | [diff] [blame] | 1910 | /// isUNPCKHMask - Return true if the specified VECTOR_SHUFFLE operand |
| 1911 | /// specifies a shuffle of elements that is suitable for input to UNPCKH. |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 1912 | bool static isUNPCKHMask(const SDOperand *Elts, unsigned NumElts, |
| 1913 | bool V2IsSplat = false) { |
| 1914 | if (NumElts != 2 && NumElts != 4 && NumElts != 8 && NumElts != 16) |
Evan Cheng | 4fcb922 | 2006-03-28 02:43:26 +0000 | [diff] [blame] | 1915 | return false; |
| 1916 | |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 1917 | for (unsigned i = 0, j = 0; i != NumElts; i += 2, ++j) { |
| 1918 | SDOperand BitI = Elts[i]; |
| 1919 | SDOperand BitI1 = Elts[i+1]; |
| 1920 | if (!isUndefOrEqual(BitI, j + NumElts/2)) |
Evan Cheng | c5cdff2 | 2006-04-07 21:53:05 +0000 | [diff] [blame] | 1921 | return false; |
Evan Cheng | 39623da | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 1922 | if (V2IsSplat) { |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 1923 | if (isUndefOrEqual(BitI1, NumElts)) |
Evan Cheng | 39623da | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 1924 | return false; |
| 1925 | } else { |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 1926 | if (!isUndefOrEqual(BitI1, j + NumElts/2 + NumElts)) |
Evan Cheng | 39623da | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 1927 | return false; |
| 1928 | } |
Evan Cheng | 4fcb922 | 2006-03-28 02:43:26 +0000 | [diff] [blame] | 1929 | } |
| 1930 | |
| 1931 | return true; |
| 1932 | } |
| 1933 | |
Evan Cheng | 39623da | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 1934 | bool X86::isUNPCKHMask(SDNode *N, bool V2IsSplat) { |
| 1935 | assert(N->getOpcode() == ISD::BUILD_VECTOR); |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 1936 | return ::isUNPCKHMask(N->op_begin(), N->getNumOperands(), V2IsSplat); |
Evan Cheng | 39623da | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 1937 | } |
| 1938 | |
Evan Cheng | 1d5a8cc | 2006-04-05 07:20:06 +0000 | [diff] [blame] | 1939 | /// isUNPCKL_v_undef_Mask - Special case of isUNPCKLMask for canonical form |
| 1940 | /// of vector_shuffle v, v, <0, 4, 1, 5>, i.e. vector_shuffle v, undef, |
| 1941 | /// <0, 0, 1, 1> |
| 1942 | bool X86::isUNPCKL_v_undef_Mask(SDNode *N) { |
| 1943 | assert(N->getOpcode() == ISD::BUILD_VECTOR); |
| 1944 | |
| 1945 | unsigned NumElems = N->getNumOperands(); |
Bill Wendling | 2f9bb1a | 2007-04-24 21:16:55 +0000 | [diff] [blame] | 1946 | if (NumElems != 2 && NumElems != 4 && NumElems != 8 && NumElems != 16) |
Evan Cheng | 1d5a8cc | 2006-04-05 07:20:06 +0000 | [diff] [blame] | 1947 | return false; |
| 1948 | |
| 1949 | for (unsigned i = 0, j = 0; i != NumElems; i += 2, ++j) { |
| 1950 | SDOperand BitI = N->getOperand(i); |
| 1951 | SDOperand BitI1 = N->getOperand(i+1); |
| 1952 | |
Evan Cheng | c5cdff2 | 2006-04-07 21:53:05 +0000 | [diff] [blame] | 1953 | if (!isUndefOrEqual(BitI, j)) |
| 1954 | return false; |
| 1955 | if (!isUndefOrEqual(BitI1, j)) |
| 1956 | return false; |
Evan Cheng | 1d5a8cc | 2006-04-05 07:20:06 +0000 | [diff] [blame] | 1957 | } |
| 1958 | |
| 1959 | return true; |
| 1960 | } |
| 1961 | |
Bill Wendling | 2f9bb1a | 2007-04-24 21:16:55 +0000 | [diff] [blame] | 1962 | /// isUNPCKH_v_undef_Mask - Special case of isUNPCKHMask for canonical form |
| 1963 | /// of vector_shuffle v, v, <2, 6, 3, 7>, i.e. vector_shuffle v, undef, |
| 1964 | /// <2, 2, 3, 3> |
| 1965 | bool X86::isUNPCKH_v_undef_Mask(SDNode *N) { |
| 1966 | assert(N->getOpcode() == ISD::BUILD_VECTOR); |
| 1967 | |
| 1968 | unsigned NumElems = N->getNumOperands(); |
| 1969 | if (NumElems != 2 && NumElems != 4 && NumElems != 8 && NumElems != 16) |
| 1970 | return false; |
| 1971 | |
| 1972 | for (unsigned i = 0, j = NumElems / 2; i != NumElems; i += 2, ++j) { |
| 1973 | SDOperand BitI = N->getOperand(i); |
| 1974 | SDOperand BitI1 = N->getOperand(i + 1); |
| 1975 | |
| 1976 | if (!isUndefOrEqual(BitI, j)) |
| 1977 | return false; |
| 1978 | if (!isUndefOrEqual(BitI1, j)) |
| 1979 | return false; |
| 1980 | } |
| 1981 | |
| 1982 | return true; |
| 1983 | } |
| 1984 | |
Evan Cheng | 017dcc6 | 2006-04-21 01:05:10 +0000 | [diff] [blame] | 1985 | /// isMOVLMask - Return true if the specified VECTOR_SHUFFLE operand |
| 1986 | /// specifies a shuffle of elements that is suitable for input to MOVSS, |
| 1987 | /// MOVSD, and MOVD, i.e. setting the lowest element. |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 1988 | static bool isMOVLMask(const SDOperand *Elts, unsigned NumElts) { |
| 1989 | if (NumElts != 2 && NumElts != 4 && NumElts != 8 && NumElts != 16) |
Evan Cheng | d6d1cbd | 2006-04-11 00:19:04 +0000 | [diff] [blame] | 1990 | return false; |
| 1991 | |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 1992 | if (!isUndefOrEqual(Elts[0], NumElts)) |
Evan Cheng | d6d1cbd | 2006-04-11 00:19:04 +0000 | [diff] [blame] | 1993 | return false; |
| 1994 | |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 1995 | for (unsigned i = 1; i < NumElts; ++i) { |
| 1996 | if (!isUndefOrEqual(Elts[i], i)) |
Evan Cheng | d6d1cbd | 2006-04-11 00:19:04 +0000 | [diff] [blame] | 1997 | return false; |
| 1998 | } |
| 1999 | |
| 2000 | return true; |
| 2001 | } |
Evan Cheng | 1d5a8cc | 2006-04-05 07:20:06 +0000 | [diff] [blame] | 2002 | |
Evan Cheng | 017dcc6 | 2006-04-21 01:05:10 +0000 | [diff] [blame] | 2003 | bool X86::isMOVLMask(SDNode *N) { |
Evan Cheng | 39623da | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 2004 | assert(N->getOpcode() == ISD::BUILD_VECTOR); |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 2005 | return ::isMOVLMask(N->op_begin(), N->getNumOperands()); |
Evan Cheng | 39623da | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 2006 | } |
| 2007 | |
Evan Cheng | 017dcc6 | 2006-04-21 01:05:10 +0000 | [diff] [blame] | 2008 | /// isCommutedMOVL - Returns true if the shuffle mask is except the reverse |
| 2009 | /// of what x86 movss want. X86 movs requires the lowest element to be lowest |
Evan Cheng | 39623da | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 2010 | /// element of vector 2 and the other elements to come from vector 1 in order. |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 2011 | static bool isCommutedMOVL(const SDOperand *Ops, unsigned NumOps, |
| 2012 | bool V2IsSplat = false, |
Evan Cheng | 8cf723d | 2006-09-08 01:50:06 +0000 | [diff] [blame] | 2013 | bool V2IsUndef = false) { |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 2014 | if (NumOps != 2 && NumOps != 4 && NumOps != 8 && NumOps != 16) |
Evan Cheng | 39623da | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 2015 | return false; |
| 2016 | |
| 2017 | if (!isUndefOrEqual(Ops[0], 0)) |
| 2018 | return false; |
| 2019 | |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 2020 | for (unsigned i = 1; i < NumOps; ++i) { |
Evan Cheng | 39623da | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 2021 | SDOperand Arg = Ops[i]; |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 2022 | if (!(isUndefOrEqual(Arg, i+NumOps) || |
| 2023 | (V2IsUndef && isUndefOrInRange(Arg, NumOps, NumOps*2)) || |
| 2024 | (V2IsSplat && isUndefOrEqual(Arg, NumOps)))) |
Evan Cheng | 8cf723d | 2006-09-08 01:50:06 +0000 | [diff] [blame] | 2025 | return false; |
Evan Cheng | 39623da | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 2026 | } |
| 2027 | |
| 2028 | return true; |
| 2029 | } |
| 2030 | |
Evan Cheng | 8cf723d | 2006-09-08 01:50:06 +0000 | [diff] [blame] | 2031 | static bool isCommutedMOVL(SDNode *N, bool V2IsSplat = false, |
| 2032 | bool V2IsUndef = false) { |
Evan Cheng | 39623da | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 2033 | assert(N->getOpcode() == ISD::BUILD_VECTOR); |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 2034 | return isCommutedMOVL(N->op_begin(), N->getNumOperands(), |
| 2035 | V2IsSplat, V2IsUndef); |
Evan Cheng | 39623da | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 2036 | } |
| 2037 | |
Evan Cheng | d953947 | 2006-04-14 21:59:03 +0000 | [diff] [blame] | 2038 | /// isMOVSHDUPMask - Return true if the specified VECTOR_SHUFFLE operand |
| 2039 | /// specifies a shuffle of elements that is suitable for input to MOVSHDUP. |
| 2040 | bool X86::isMOVSHDUPMask(SDNode *N) { |
| 2041 | assert(N->getOpcode() == ISD::BUILD_VECTOR); |
| 2042 | |
| 2043 | if (N->getNumOperands() != 4) |
| 2044 | return false; |
| 2045 | |
| 2046 | // Expect 1, 1, 3, 3 |
| 2047 | for (unsigned i = 0; i < 2; ++i) { |
| 2048 | SDOperand Arg = N->getOperand(i); |
| 2049 | if (Arg.getOpcode() == ISD::UNDEF) continue; |
| 2050 | assert(isa<ConstantSDNode>(Arg) && "Invalid VECTOR_SHUFFLE mask!"); |
| 2051 | unsigned Val = cast<ConstantSDNode>(Arg)->getValue(); |
| 2052 | if (Val != 1) return false; |
| 2053 | } |
Evan Cheng | 57ebe9f | 2006-04-15 05:37:34 +0000 | [diff] [blame] | 2054 | |
| 2055 | bool HasHi = false; |
Evan Cheng | d953947 | 2006-04-14 21:59:03 +0000 | [diff] [blame] | 2056 | for (unsigned i = 2; i < 4; ++i) { |
| 2057 | SDOperand Arg = N->getOperand(i); |
| 2058 | if (Arg.getOpcode() == ISD::UNDEF) continue; |
| 2059 | assert(isa<ConstantSDNode>(Arg) && "Invalid VECTOR_SHUFFLE mask!"); |
| 2060 | unsigned Val = cast<ConstantSDNode>(Arg)->getValue(); |
| 2061 | if (Val != 3) return false; |
Evan Cheng | 57ebe9f | 2006-04-15 05:37:34 +0000 | [diff] [blame] | 2062 | HasHi = true; |
Evan Cheng | d953947 | 2006-04-14 21:59:03 +0000 | [diff] [blame] | 2063 | } |
Evan Cheng | 39fc145 | 2006-04-15 03:13:24 +0000 | [diff] [blame] | 2064 | |
Evan Cheng | 57ebe9f | 2006-04-15 05:37:34 +0000 | [diff] [blame] | 2065 | // Don't use movshdup if it can be done with a shufps. |
| 2066 | return HasHi; |
Evan Cheng | d953947 | 2006-04-14 21:59:03 +0000 | [diff] [blame] | 2067 | } |
| 2068 | |
| 2069 | /// isMOVSLDUPMask - Return true if the specified VECTOR_SHUFFLE operand |
| 2070 | /// specifies a shuffle of elements that is suitable for input to MOVSLDUP. |
| 2071 | bool X86::isMOVSLDUPMask(SDNode *N) { |
| 2072 | assert(N->getOpcode() == ISD::BUILD_VECTOR); |
| 2073 | |
| 2074 | if (N->getNumOperands() != 4) |
| 2075 | return false; |
| 2076 | |
| 2077 | // Expect 0, 0, 2, 2 |
| 2078 | for (unsigned i = 0; i < 2; ++i) { |
| 2079 | SDOperand Arg = N->getOperand(i); |
| 2080 | if (Arg.getOpcode() == ISD::UNDEF) continue; |
| 2081 | assert(isa<ConstantSDNode>(Arg) && "Invalid VECTOR_SHUFFLE mask!"); |
| 2082 | unsigned Val = cast<ConstantSDNode>(Arg)->getValue(); |
| 2083 | if (Val != 0) return false; |
| 2084 | } |
Evan Cheng | 57ebe9f | 2006-04-15 05:37:34 +0000 | [diff] [blame] | 2085 | |
| 2086 | bool HasHi = false; |
Evan Cheng | d953947 | 2006-04-14 21:59:03 +0000 | [diff] [blame] | 2087 | for (unsigned i = 2; i < 4; ++i) { |
| 2088 | SDOperand Arg = N->getOperand(i); |
| 2089 | if (Arg.getOpcode() == ISD::UNDEF) continue; |
| 2090 | assert(isa<ConstantSDNode>(Arg) && "Invalid VECTOR_SHUFFLE mask!"); |
| 2091 | unsigned Val = cast<ConstantSDNode>(Arg)->getValue(); |
| 2092 | if (Val != 2) return false; |
Evan Cheng | 57ebe9f | 2006-04-15 05:37:34 +0000 | [diff] [blame] | 2093 | HasHi = true; |
Evan Cheng | d953947 | 2006-04-14 21:59:03 +0000 | [diff] [blame] | 2094 | } |
Evan Cheng | 39fc145 | 2006-04-15 03:13:24 +0000 | [diff] [blame] | 2095 | |
Evan Cheng | 57ebe9f | 2006-04-15 05:37:34 +0000 | [diff] [blame] | 2096 | // Don't use movshdup if it can be done with a shufps. |
| 2097 | return HasHi; |
Evan Cheng | d953947 | 2006-04-14 21:59:03 +0000 | [diff] [blame] | 2098 | } |
| 2099 | |
Evan Cheng | 49892af | 2007-06-19 00:02:56 +0000 | [diff] [blame] | 2100 | /// isIdentityMask - Return true if the specified VECTOR_SHUFFLE operand |
| 2101 | /// specifies a identity operation on the LHS or RHS. |
| 2102 | static bool isIdentityMask(SDNode *N, bool RHS = false) { |
| 2103 | unsigned NumElems = N->getNumOperands(); |
| 2104 | for (unsigned i = 0; i < NumElems; ++i) |
| 2105 | if (!isUndefOrEqual(N->getOperand(i), i + (RHS ? NumElems : 0))) |
| 2106 | return false; |
| 2107 | return true; |
| 2108 | } |
| 2109 | |
Evan Cheng | b9df0ca | 2006-03-22 02:53:00 +0000 | [diff] [blame] | 2110 | /// isSplatMask - Return true if the specified VECTOR_SHUFFLE operand specifies |
| 2111 | /// a splat of a single element. |
Evan Cheng | c575ca2 | 2006-04-17 20:43:08 +0000 | [diff] [blame] | 2112 | static bool isSplatMask(SDNode *N) { |
Evan Cheng | b9df0ca | 2006-03-22 02:53:00 +0000 | [diff] [blame] | 2113 | assert(N->getOpcode() == ISD::BUILD_VECTOR); |
| 2114 | |
Evan Cheng | b9df0ca | 2006-03-22 02:53:00 +0000 | [diff] [blame] | 2115 | // This is a splat operation if each element of the permute is the same, and |
| 2116 | // if the value doesn't reference the second vector. |
Evan Cheng | 94fe5eb | 2006-04-19 23:28:59 +0000 | [diff] [blame] | 2117 | unsigned NumElems = N->getNumOperands(); |
| 2118 | SDOperand ElementBase; |
| 2119 | unsigned i = 0; |
| 2120 | for (; i != NumElems; ++i) { |
| 2121 | SDOperand Elt = N->getOperand(i); |
Reid Spencer | 3ed469c | 2006-11-02 20:25:50 +0000 | [diff] [blame] | 2122 | if (isa<ConstantSDNode>(Elt)) { |
Evan Cheng | 94fe5eb | 2006-04-19 23:28:59 +0000 | [diff] [blame] | 2123 | ElementBase = Elt; |
| 2124 | break; |
| 2125 | } |
| 2126 | } |
| 2127 | |
| 2128 | if (!ElementBase.Val) |
| 2129 | return false; |
| 2130 | |
| 2131 | for (; i != NumElems; ++i) { |
Evan Cheng | ef698ca | 2006-03-31 00:30:29 +0000 | [diff] [blame] | 2132 | SDOperand Arg = N->getOperand(i); |
| 2133 | if (Arg.getOpcode() == ISD::UNDEF) continue; |
| 2134 | assert(isa<ConstantSDNode>(Arg) && "Invalid VECTOR_SHUFFLE mask!"); |
Evan Cheng | 94fe5eb | 2006-04-19 23:28:59 +0000 | [diff] [blame] | 2135 | if (Arg != ElementBase) return false; |
Evan Cheng | b9df0ca | 2006-03-22 02:53:00 +0000 | [diff] [blame] | 2136 | } |
| 2137 | |
| 2138 | // Make sure it is a splat of the first vector operand. |
Evan Cheng | 94fe5eb | 2006-04-19 23:28:59 +0000 | [diff] [blame] | 2139 | return cast<ConstantSDNode>(ElementBase)->getValue() < NumElems; |
Evan Cheng | b9df0ca | 2006-03-22 02:53:00 +0000 | [diff] [blame] | 2140 | } |
| 2141 | |
Evan Cheng | c575ca2 | 2006-04-17 20:43:08 +0000 | [diff] [blame] | 2142 | /// isSplatMask - Return true if the specified VECTOR_SHUFFLE operand specifies |
| 2143 | /// a splat of a single element and it's a 2 or 4 element mask. |
| 2144 | bool X86::isSplatMask(SDNode *N) { |
| 2145 | assert(N->getOpcode() == ISD::BUILD_VECTOR); |
| 2146 | |
Evan Cheng | 94fe5eb | 2006-04-19 23:28:59 +0000 | [diff] [blame] | 2147 | // We can only splat 64-bit, and 32-bit quantities with a single instruction. |
Evan Cheng | c575ca2 | 2006-04-17 20:43:08 +0000 | [diff] [blame] | 2148 | if (N->getNumOperands() != 4 && N->getNumOperands() != 2) |
| 2149 | return false; |
| 2150 | return ::isSplatMask(N); |
| 2151 | } |
| 2152 | |
Evan Cheng | f686d9b | 2006-10-27 21:08:32 +0000 | [diff] [blame] | 2153 | /// isSplatLoMask - Return true if the specified VECTOR_SHUFFLE operand |
| 2154 | /// specifies a splat of zero element. |
| 2155 | bool X86::isSplatLoMask(SDNode *N) { |
| 2156 | assert(N->getOpcode() == ISD::BUILD_VECTOR); |
| 2157 | |
Anton Korobeynikov | 12c49af | 2006-11-21 00:01:06 +0000 | [diff] [blame] | 2158 | for (unsigned i = 0, e = N->getNumOperands(); i < e; ++i) |
Evan Cheng | f686d9b | 2006-10-27 21:08:32 +0000 | [diff] [blame] | 2159 | if (!isUndefOrEqual(N->getOperand(i), 0)) |
| 2160 | return false; |
| 2161 | return true; |
| 2162 | } |
| 2163 | |
Evan Cheng | 63d3300 | 2006-03-22 08:01:21 +0000 | [diff] [blame] | 2164 | /// getShuffleSHUFImmediate - Return the appropriate immediate to shuffle |
| 2165 | /// the specified isShuffleMask VECTOR_SHUFFLE mask with PSHUF* and SHUFP* |
| 2166 | /// instructions. |
| 2167 | unsigned X86::getShuffleSHUFImmediate(SDNode *N) { |
Evan Cheng | b9df0ca | 2006-03-22 02:53:00 +0000 | [diff] [blame] | 2168 | unsigned NumOperands = N->getNumOperands(); |
| 2169 | unsigned Shift = (NumOperands == 4) ? 2 : 1; |
| 2170 | unsigned Mask = 0; |
Evan Cheng | 36b27f3 | 2006-03-28 23:41:33 +0000 | [diff] [blame] | 2171 | for (unsigned i = 0; i < NumOperands; ++i) { |
Evan Cheng | ef698ca | 2006-03-31 00:30:29 +0000 | [diff] [blame] | 2172 | unsigned Val = 0; |
| 2173 | SDOperand Arg = N->getOperand(NumOperands-i-1); |
| 2174 | if (Arg.getOpcode() != ISD::UNDEF) |
| 2175 | Val = cast<ConstantSDNode>(Arg)->getValue(); |
Evan Cheng | 14aed5e | 2006-03-24 01:18:28 +0000 | [diff] [blame] | 2176 | if (Val >= NumOperands) Val -= NumOperands; |
Evan Cheng | 63d3300 | 2006-03-22 08:01:21 +0000 | [diff] [blame] | 2177 | Mask |= Val; |
Evan Cheng | 36b27f3 | 2006-03-28 23:41:33 +0000 | [diff] [blame] | 2178 | if (i != NumOperands - 1) |
| 2179 | Mask <<= Shift; |
| 2180 | } |
Evan Cheng | 63d3300 | 2006-03-22 08:01:21 +0000 | [diff] [blame] | 2181 | |
| 2182 | return Mask; |
| 2183 | } |
| 2184 | |
Evan Cheng | 506d3df | 2006-03-29 23:07:14 +0000 | [diff] [blame] | 2185 | /// getShufflePSHUFHWImmediate - Return the appropriate immediate to shuffle |
| 2186 | /// the specified isShuffleMask VECTOR_SHUFFLE mask with PSHUFHW |
| 2187 | /// instructions. |
| 2188 | unsigned X86::getShufflePSHUFHWImmediate(SDNode *N) { |
| 2189 | unsigned Mask = 0; |
| 2190 | // 8 nodes, but we only care about the last 4. |
| 2191 | for (unsigned i = 7; i >= 4; --i) { |
Evan Cheng | ef698ca | 2006-03-31 00:30:29 +0000 | [diff] [blame] | 2192 | unsigned Val = 0; |
| 2193 | SDOperand Arg = N->getOperand(i); |
| 2194 | if (Arg.getOpcode() != ISD::UNDEF) |
| 2195 | Val = cast<ConstantSDNode>(Arg)->getValue(); |
Evan Cheng | 506d3df | 2006-03-29 23:07:14 +0000 | [diff] [blame] | 2196 | Mask |= (Val - 4); |
| 2197 | if (i != 4) |
| 2198 | Mask <<= 2; |
| 2199 | } |
| 2200 | |
| 2201 | return Mask; |
| 2202 | } |
| 2203 | |
| 2204 | /// getShufflePSHUFLWImmediate - Return the appropriate immediate to shuffle |
| 2205 | /// the specified isShuffleMask VECTOR_SHUFFLE mask with PSHUFLW |
| 2206 | /// instructions. |
| 2207 | unsigned X86::getShufflePSHUFLWImmediate(SDNode *N) { |
| 2208 | unsigned Mask = 0; |
| 2209 | // 8 nodes, but we only care about the first 4. |
| 2210 | for (int i = 3; i >= 0; --i) { |
Evan Cheng | ef698ca | 2006-03-31 00:30:29 +0000 | [diff] [blame] | 2211 | unsigned Val = 0; |
| 2212 | SDOperand Arg = N->getOperand(i); |
| 2213 | if (Arg.getOpcode() != ISD::UNDEF) |
| 2214 | Val = cast<ConstantSDNode>(Arg)->getValue(); |
Evan Cheng | 506d3df | 2006-03-29 23:07:14 +0000 | [diff] [blame] | 2215 | Mask |= Val; |
| 2216 | if (i != 0) |
| 2217 | Mask <<= 2; |
| 2218 | } |
| 2219 | |
| 2220 | return Mask; |
| 2221 | } |
| 2222 | |
Evan Cheng | c21a053 | 2006-04-05 01:47:37 +0000 | [diff] [blame] | 2223 | /// isPSHUFHW_PSHUFLWMask - true if the specified VECTOR_SHUFFLE operand |
| 2224 | /// specifies a 8 element shuffle that can be broken into a pair of |
| 2225 | /// PSHUFHW and PSHUFLW. |
| 2226 | static bool isPSHUFHW_PSHUFLWMask(SDNode *N) { |
| 2227 | assert(N->getOpcode() == ISD::BUILD_VECTOR); |
| 2228 | |
| 2229 | if (N->getNumOperands() != 8) |
| 2230 | return false; |
| 2231 | |
| 2232 | // Lower quadword shuffled. |
| 2233 | for (unsigned i = 0; i != 4; ++i) { |
| 2234 | SDOperand Arg = N->getOperand(i); |
| 2235 | if (Arg.getOpcode() == ISD::UNDEF) continue; |
| 2236 | assert(isa<ConstantSDNode>(Arg) && "Invalid VECTOR_SHUFFLE mask!"); |
| 2237 | unsigned Val = cast<ConstantSDNode>(Arg)->getValue(); |
| 2238 | if (Val > 4) |
| 2239 | return false; |
| 2240 | } |
| 2241 | |
| 2242 | // Upper quadword shuffled. |
| 2243 | for (unsigned i = 4; i != 8; ++i) { |
| 2244 | SDOperand Arg = N->getOperand(i); |
| 2245 | if (Arg.getOpcode() == ISD::UNDEF) continue; |
| 2246 | assert(isa<ConstantSDNode>(Arg) && "Invalid VECTOR_SHUFFLE mask!"); |
| 2247 | unsigned Val = cast<ConstantSDNode>(Arg)->getValue(); |
| 2248 | if (Val < 4 || Val > 7) |
| 2249 | return false; |
| 2250 | } |
| 2251 | |
| 2252 | return true; |
| 2253 | } |
| 2254 | |
Evan Cheng | 5ced1d8 | 2006-04-06 23:23:56 +0000 | [diff] [blame] | 2255 | /// CommuteVectorShuffle - Swap vector_shuffle operandsas well as |
| 2256 | /// values in ther permute mask. |
Evan Cheng | 9eca5e8 | 2006-10-25 21:49:50 +0000 | [diff] [blame] | 2257 | static SDOperand CommuteVectorShuffle(SDOperand Op, SDOperand &V1, |
| 2258 | SDOperand &V2, SDOperand &Mask, |
| 2259 | SelectionDAG &DAG) { |
Evan Cheng | 5ced1d8 | 2006-04-06 23:23:56 +0000 | [diff] [blame] | 2260 | MVT::ValueType VT = Op.getValueType(); |
| 2261 | MVT::ValueType MaskVT = Mask.getValueType(); |
Dan Gohman | 51eaa86 | 2007-06-14 22:58:02 +0000 | [diff] [blame] | 2262 | MVT::ValueType EltVT = MVT::getVectorElementType(MaskVT); |
Evan Cheng | 5ced1d8 | 2006-04-06 23:23:56 +0000 | [diff] [blame] | 2263 | unsigned NumElems = Mask.getNumOperands(); |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 2264 | SmallVector<SDOperand, 8> MaskVec; |
Evan Cheng | 5ced1d8 | 2006-04-06 23:23:56 +0000 | [diff] [blame] | 2265 | |
| 2266 | for (unsigned i = 0; i != NumElems; ++i) { |
| 2267 | SDOperand Arg = Mask.getOperand(i); |
Evan Cheng | 80d428c | 2006-04-19 22:48:17 +0000 | [diff] [blame] | 2268 | if (Arg.getOpcode() == ISD::UNDEF) { |
| 2269 | MaskVec.push_back(DAG.getNode(ISD::UNDEF, EltVT)); |
| 2270 | continue; |
| 2271 | } |
Evan Cheng | 5ced1d8 | 2006-04-06 23:23:56 +0000 | [diff] [blame] | 2272 | assert(isa<ConstantSDNode>(Arg) && "Invalid VECTOR_SHUFFLE mask!"); |
| 2273 | unsigned Val = cast<ConstantSDNode>(Arg)->getValue(); |
| 2274 | if (Val < NumElems) |
| 2275 | MaskVec.push_back(DAG.getConstant(Val + NumElems, EltVT)); |
| 2276 | else |
| 2277 | MaskVec.push_back(DAG.getConstant(Val - NumElems, EltVT)); |
| 2278 | } |
| 2279 | |
Evan Cheng | 9eca5e8 | 2006-10-25 21:49:50 +0000 | [diff] [blame] | 2280 | std::swap(V1, V2); |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 2281 | Mask = DAG.getNode(ISD::BUILD_VECTOR, MaskVT, &MaskVec[0], MaskVec.size()); |
Evan Cheng | 9eca5e8 | 2006-10-25 21:49:50 +0000 | [diff] [blame] | 2282 | return DAG.getNode(ISD::VECTOR_SHUFFLE, VT, V1, V2, Mask); |
Evan Cheng | 5ced1d8 | 2006-04-06 23:23:56 +0000 | [diff] [blame] | 2283 | } |
| 2284 | |
Evan Cheng | 533a0aa | 2006-04-19 20:35:22 +0000 | [diff] [blame] | 2285 | /// ShouldXformToMOVHLPS - Return true if the node should be transformed to |
| 2286 | /// match movhlps. The lower half elements should come from upper half of |
| 2287 | /// V1 (and in order), and the upper half elements should come from the upper |
Anton Korobeynikov | 12c49af | 2006-11-21 00:01:06 +0000 | [diff] [blame] | 2288 | /// half of V2 (and in order). |
Evan Cheng | 533a0aa | 2006-04-19 20:35:22 +0000 | [diff] [blame] | 2289 | static bool ShouldXformToMOVHLPS(SDNode *Mask) { |
| 2290 | unsigned NumElems = Mask->getNumOperands(); |
| 2291 | if (NumElems != 4) |
| 2292 | return false; |
| 2293 | for (unsigned i = 0, e = 2; i != e; ++i) |
| 2294 | if (!isUndefOrEqual(Mask->getOperand(i), i+2)) |
| 2295 | return false; |
| 2296 | for (unsigned i = 2; i != 4; ++i) |
| 2297 | if (!isUndefOrEqual(Mask->getOperand(i), i+4)) |
| 2298 | return false; |
| 2299 | return true; |
| 2300 | } |
| 2301 | |
Evan Cheng | 5ced1d8 | 2006-04-06 23:23:56 +0000 | [diff] [blame] | 2302 | /// isScalarLoadToVector - Returns true if the node is a scalar load that |
| 2303 | /// is promoted to a vector. |
Evan Cheng | 533a0aa | 2006-04-19 20:35:22 +0000 | [diff] [blame] | 2304 | static inline bool isScalarLoadToVector(SDNode *N) { |
| 2305 | if (N->getOpcode() == ISD::SCALAR_TO_VECTOR) { |
| 2306 | N = N->getOperand(0).Val; |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2307 | return ISD::isNON_EXTLoad(N); |
Evan Cheng | 5ced1d8 | 2006-04-06 23:23:56 +0000 | [diff] [blame] | 2308 | } |
| 2309 | return false; |
| 2310 | } |
| 2311 | |
Evan Cheng | 533a0aa | 2006-04-19 20:35:22 +0000 | [diff] [blame] | 2312 | /// ShouldXformToMOVLP{S|D} - Return true if the node should be transformed to |
| 2313 | /// match movlp{s|d}. The lower half elements should come from lower half of |
| 2314 | /// V1 (and in order), and the upper half elements should come from the upper |
| 2315 | /// half of V2 (and in order). And since V1 will become the source of the |
| 2316 | /// MOVLP, it must be either a vector load or a scalar load to vector. |
Evan Cheng | 23425f5 | 2006-10-09 21:39:25 +0000 | [diff] [blame] | 2317 | static bool ShouldXformToMOVLP(SDNode *V1, SDNode *V2, SDNode *Mask) { |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 2318 | if (!ISD::isNON_EXTLoad(V1) && !isScalarLoadToVector(V1)) |
Evan Cheng | 533a0aa | 2006-04-19 20:35:22 +0000 | [diff] [blame] | 2319 | return false; |
Evan Cheng | 23425f5 | 2006-10-09 21:39:25 +0000 | [diff] [blame] | 2320 | // Is V2 is a vector load, don't do this transformation. We will try to use |
| 2321 | // load folding shufps op. |
| 2322 | if (ISD::isNON_EXTLoad(V2)) |
| 2323 | return false; |
Evan Cheng | 5ced1d8 | 2006-04-06 23:23:56 +0000 | [diff] [blame] | 2324 | |
Evan Cheng | 533a0aa | 2006-04-19 20:35:22 +0000 | [diff] [blame] | 2325 | unsigned NumElems = Mask->getNumOperands(); |
| 2326 | if (NumElems != 2 && NumElems != 4) |
| 2327 | return false; |
| 2328 | for (unsigned i = 0, e = NumElems/2; i != e; ++i) |
| 2329 | if (!isUndefOrEqual(Mask->getOperand(i), i)) |
| 2330 | return false; |
| 2331 | for (unsigned i = NumElems/2; i != NumElems; ++i) |
| 2332 | if (!isUndefOrEqual(Mask->getOperand(i), i+NumElems)) |
| 2333 | return false; |
| 2334 | return true; |
Evan Cheng | 5ced1d8 | 2006-04-06 23:23:56 +0000 | [diff] [blame] | 2335 | } |
| 2336 | |
Evan Cheng | 39623da | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 2337 | /// isSplatVector - Returns true if N is a BUILD_VECTOR node whose elements are |
| 2338 | /// all the same. |
| 2339 | static bool isSplatVector(SDNode *N) { |
| 2340 | if (N->getOpcode() != ISD::BUILD_VECTOR) |
| 2341 | return false; |
Evan Cheng | 5ced1d8 | 2006-04-06 23:23:56 +0000 | [diff] [blame] | 2342 | |
Evan Cheng | 39623da | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 2343 | SDOperand SplatValue = N->getOperand(0); |
| 2344 | for (unsigned i = 1, e = N->getNumOperands(); i != e; ++i) |
| 2345 | if (N->getOperand(i) != SplatValue) |
Evan Cheng | 5ced1d8 | 2006-04-06 23:23:56 +0000 | [diff] [blame] | 2346 | return false; |
| 2347 | return true; |
| 2348 | } |
| 2349 | |
Evan Cheng | 8cf723d | 2006-09-08 01:50:06 +0000 | [diff] [blame] | 2350 | /// isUndefShuffle - Returns true if N is a VECTOR_SHUFFLE that can be resolved |
| 2351 | /// to an undef. |
| 2352 | static bool isUndefShuffle(SDNode *N) { |
Evan Cheng | 213d2cf | 2007-05-17 18:45:50 +0000 | [diff] [blame] | 2353 | if (N->getOpcode() != ISD::VECTOR_SHUFFLE) |
Evan Cheng | 8cf723d | 2006-09-08 01:50:06 +0000 | [diff] [blame] | 2354 | return false; |
| 2355 | |
| 2356 | SDOperand V1 = N->getOperand(0); |
| 2357 | SDOperand V2 = N->getOperand(1); |
| 2358 | SDOperand Mask = N->getOperand(2); |
| 2359 | unsigned NumElems = Mask.getNumOperands(); |
| 2360 | for (unsigned i = 0; i != NumElems; ++i) { |
| 2361 | SDOperand Arg = Mask.getOperand(i); |
| 2362 | if (Arg.getOpcode() != ISD::UNDEF) { |
| 2363 | unsigned Val = cast<ConstantSDNode>(Arg)->getValue(); |
| 2364 | if (Val < NumElems && V1.getOpcode() != ISD::UNDEF) |
| 2365 | return false; |
| 2366 | else if (Val >= NumElems && V2.getOpcode() != ISD::UNDEF) |
| 2367 | return false; |
| 2368 | } |
| 2369 | } |
| 2370 | return true; |
| 2371 | } |
| 2372 | |
Evan Cheng | 213d2cf | 2007-05-17 18:45:50 +0000 | [diff] [blame] | 2373 | /// isZeroNode - Returns true if Elt is a constant zero or a floating point |
| 2374 | /// constant +0.0. |
| 2375 | static inline bool isZeroNode(SDOperand Elt) { |
| 2376 | return ((isa<ConstantSDNode>(Elt) && |
| 2377 | cast<ConstantSDNode>(Elt)->getValue() == 0) || |
| 2378 | (isa<ConstantFPSDNode>(Elt) && |
Dale Johannesen | eaf0894 | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 2379 | cast<ConstantFPSDNode>(Elt)->getValueAPF().isPosZero())); |
Evan Cheng | 213d2cf | 2007-05-17 18:45:50 +0000 | [diff] [blame] | 2380 | } |
| 2381 | |
| 2382 | /// isZeroShuffle - Returns true if N is a VECTOR_SHUFFLE that can be resolved |
| 2383 | /// to an zero vector. |
| 2384 | static bool isZeroShuffle(SDNode *N) { |
| 2385 | if (N->getOpcode() != ISD::VECTOR_SHUFFLE) |
| 2386 | return false; |
| 2387 | |
| 2388 | SDOperand V1 = N->getOperand(0); |
| 2389 | SDOperand V2 = N->getOperand(1); |
| 2390 | SDOperand Mask = N->getOperand(2); |
| 2391 | unsigned NumElems = Mask.getNumOperands(); |
| 2392 | for (unsigned i = 0; i != NumElems; ++i) { |
| 2393 | SDOperand Arg = Mask.getOperand(i); |
| 2394 | if (Arg.getOpcode() != ISD::UNDEF) { |
| 2395 | unsigned Idx = cast<ConstantSDNode>(Arg)->getValue(); |
| 2396 | if (Idx < NumElems) { |
| 2397 | unsigned Opc = V1.Val->getOpcode(); |
| 2398 | if (Opc == ISD::UNDEF) |
| 2399 | continue; |
| 2400 | if (Opc != ISD::BUILD_VECTOR || |
| 2401 | !isZeroNode(V1.Val->getOperand(Idx))) |
| 2402 | return false; |
| 2403 | } else if (Idx >= NumElems) { |
| 2404 | unsigned Opc = V2.Val->getOpcode(); |
| 2405 | if (Opc == ISD::UNDEF) |
| 2406 | continue; |
| 2407 | if (Opc != ISD::BUILD_VECTOR || |
| 2408 | !isZeroNode(V2.Val->getOperand(Idx - NumElems))) |
| 2409 | return false; |
| 2410 | } |
| 2411 | } |
| 2412 | } |
| 2413 | return true; |
| 2414 | } |
| 2415 | |
| 2416 | /// getZeroVector - Returns a vector of specified type with all zero elements. |
| 2417 | /// |
| 2418 | static SDOperand getZeroVector(MVT::ValueType VT, SelectionDAG &DAG) { |
| 2419 | assert(MVT::isVector(VT) && "Expected a vector type"); |
Dan Gohman | 237898a | 2007-05-24 14:33:05 +0000 | [diff] [blame] | 2420 | unsigned NumElems = MVT::getVectorNumElements(VT); |
Dan Gohman | 51eaa86 | 2007-06-14 22:58:02 +0000 | [diff] [blame] | 2421 | MVT::ValueType EVT = MVT::getVectorElementType(VT); |
Evan Cheng | 213d2cf | 2007-05-17 18:45:50 +0000 | [diff] [blame] | 2422 | bool isFP = MVT::isFloatingPoint(EVT); |
| 2423 | SDOperand Zero = isFP ? DAG.getConstantFP(0.0, EVT) : DAG.getConstant(0, EVT); |
| 2424 | SmallVector<SDOperand, 8> ZeroVec(NumElems, Zero); |
| 2425 | return DAG.getNode(ISD::BUILD_VECTOR, VT, &ZeroVec[0], ZeroVec.size()); |
| 2426 | } |
| 2427 | |
Evan Cheng | 39623da | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 2428 | /// NormalizeMask - V2 is a splat, modify the mask (if needed) so all elements |
| 2429 | /// that point to V2 points to its first element. |
| 2430 | static SDOperand NormalizeMask(SDOperand Mask, SelectionDAG &DAG) { |
| 2431 | assert(Mask.getOpcode() == ISD::BUILD_VECTOR); |
| 2432 | |
| 2433 | bool Changed = false; |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 2434 | SmallVector<SDOperand, 8> MaskVec; |
Evan Cheng | 39623da | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 2435 | unsigned NumElems = Mask.getNumOperands(); |
| 2436 | for (unsigned i = 0; i != NumElems; ++i) { |
| 2437 | SDOperand Arg = Mask.getOperand(i); |
| 2438 | if (Arg.getOpcode() != ISD::UNDEF) { |
| 2439 | unsigned Val = cast<ConstantSDNode>(Arg)->getValue(); |
| 2440 | if (Val > NumElems) { |
| 2441 | Arg = DAG.getConstant(NumElems, Arg.getValueType()); |
| 2442 | Changed = true; |
| 2443 | } |
| 2444 | } |
| 2445 | MaskVec.push_back(Arg); |
| 2446 | } |
| 2447 | |
| 2448 | if (Changed) |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 2449 | Mask = DAG.getNode(ISD::BUILD_VECTOR, Mask.getValueType(), |
| 2450 | &MaskVec[0], MaskVec.size()); |
Evan Cheng | 39623da | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 2451 | return Mask; |
| 2452 | } |
| 2453 | |
Evan Cheng | 017dcc6 | 2006-04-21 01:05:10 +0000 | [diff] [blame] | 2454 | /// getMOVLMask - Returns a vector_shuffle mask for an movs{s|d}, movd |
| 2455 | /// operation of specified width. |
| 2456 | static SDOperand getMOVLMask(unsigned NumElems, SelectionDAG &DAG) { |
Evan Cheng | 39623da | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 2457 | MVT::ValueType MaskVT = MVT::getIntVectorWithNumElements(NumElems); |
Dan Gohman | 51eaa86 | 2007-06-14 22:58:02 +0000 | [diff] [blame] | 2458 | MVT::ValueType BaseVT = MVT::getVectorElementType(MaskVT); |
Evan Cheng | 39623da | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 2459 | |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 2460 | SmallVector<SDOperand, 8> MaskVec; |
Evan Cheng | 39623da | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 2461 | MaskVec.push_back(DAG.getConstant(NumElems, BaseVT)); |
| 2462 | for (unsigned i = 1; i != NumElems; ++i) |
| 2463 | MaskVec.push_back(DAG.getConstant(i, BaseVT)); |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 2464 | return DAG.getNode(ISD::BUILD_VECTOR, MaskVT, &MaskVec[0], MaskVec.size()); |
Evan Cheng | 39623da | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 2465 | } |
| 2466 | |
Evan Cheng | c575ca2 | 2006-04-17 20:43:08 +0000 | [diff] [blame] | 2467 | /// getUnpacklMask - Returns a vector_shuffle mask for an unpackl operation |
| 2468 | /// of specified width. |
| 2469 | static SDOperand getUnpacklMask(unsigned NumElems, SelectionDAG &DAG) { |
| 2470 | MVT::ValueType MaskVT = MVT::getIntVectorWithNumElements(NumElems); |
Dan Gohman | 51eaa86 | 2007-06-14 22:58:02 +0000 | [diff] [blame] | 2471 | MVT::ValueType BaseVT = MVT::getVectorElementType(MaskVT); |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 2472 | SmallVector<SDOperand, 8> MaskVec; |
Evan Cheng | c575ca2 | 2006-04-17 20:43:08 +0000 | [diff] [blame] | 2473 | for (unsigned i = 0, e = NumElems/2; i != e; ++i) { |
| 2474 | MaskVec.push_back(DAG.getConstant(i, BaseVT)); |
| 2475 | MaskVec.push_back(DAG.getConstant(i + NumElems, BaseVT)); |
| 2476 | } |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 2477 | return DAG.getNode(ISD::BUILD_VECTOR, MaskVT, &MaskVec[0], MaskVec.size()); |
Evan Cheng | c575ca2 | 2006-04-17 20:43:08 +0000 | [diff] [blame] | 2478 | } |
| 2479 | |
Evan Cheng | 39623da | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 2480 | /// getUnpackhMask - Returns a vector_shuffle mask for an unpackh operation |
| 2481 | /// of specified width. |
| 2482 | static SDOperand getUnpackhMask(unsigned NumElems, SelectionDAG &DAG) { |
| 2483 | MVT::ValueType MaskVT = MVT::getIntVectorWithNumElements(NumElems); |
Dan Gohman | 51eaa86 | 2007-06-14 22:58:02 +0000 | [diff] [blame] | 2484 | MVT::ValueType BaseVT = MVT::getVectorElementType(MaskVT); |
Evan Cheng | 39623da | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 2485 | unsigned Half = NumElems/2; |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 2486 | SmallVector<SDOperand, 8> MaskVec; |
Evan Cheng | 39623da | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 2487 | for (unsigned i = 0; i != Half; ++i) { |
| 2488 | MaskVec.push_back(DAG.getConstant(i + Half, BaseVT)); |
| 2489 | MaskVec.push_back(DAG.getConstant(i + NumElems + Half, BaseVT)); |
| 2490 | } |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 2491 | return DAG.getNode(ISD::BUILD_VECTOR, MaskVT, &MaskVec[0], MaskVec.size()); |
Evan Cheng | 39623da | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 2492 | } |
| 2493 | |
Evan Cheng | c575ca2 | 2006-04-17 20:43:08 +0000 | [diff] [blame] | 2494 | /// PromoteSplat - Promote a splat of v8i16 or v16i8 to v4i32. |
| 2495 | /// |
| 2496 | static SDOperand PromoteSplat(SDOperand Op, SelectionDAG &DAG) { |
| 2497 | SDOperand V1 = Op.getOperand(0); |
Evan Cheng | 017dcc6 | 2006-04-21 01:05:10 +0000 | [diff] [blame] | 2498 | SDOperand Mask = Op.getOperand(2); |
Evan Cheng | c575ca2 | 2006-04-17 20:43:08 +0000 | [diff] [blame] | 2499 | MVT::ValueType VT = Op.getValueType(); |
Evan Cheng | 017dcc6 | 2006-04-21 01:05:10 +0000 | [diff] [blame] | 2500 | unsigned NumElems = Mask.getNumOperands(); |
| 2501 | Mask = getUnpacklMask(NumElems, DAG); |
Evan Cheng | c575ca2 | 2006-04-17 20:43:08 +0000 | [diff] [blame] | 2502 | while (NumElems != 4) { |
Evan Cheng | 017dcc6 | 2006-04-21 01:05:10 +0000 | [diff] [blame] | 2503 | V1 = DAG.getNode(ISD::VECTOR_SHUFFLE, VT, V1, V1, Mask); |
Evan Cheng | c575ca2 | 2006-04-17 20:43:08 +0000 | [diff] [blame] | 2504 | NumElems >>= 1; |
| 2505 | } |
| 2506 | V1 = DAG.getNode(ISD::BIT_CONVERT, MVT::v4i32, V1); |
| 2507 | |
| 2508 | MVT::ValueType MaskVT = MVT::getIntVectorWithNumElements(4); |
Evan Cheng | 017dcc6 | 2006-04-21 01:05:10 +0000 | [diff] [blame] | 2509 | Mask = getZeroVector(MaskVT, DAG); |
Evan Cheng | c575ca2 | 2006-04-17 20:43:08 +0000 | [diff] [blame] | 2510 | SDOperand Shuffle = DAG.getNode(ISD::VECTOR_SHUFFLE, MVT::v4i32, V1, |
Evan Cheng | 017dcc6 | 2006-04-21 01:05:10 +0000 | [diff] [blame] | 2511 | DAG.getNode(ISD::UNDEF, MVT::v4i32), Mask); |
Evan Cheng | c575ca2 | 2006-04-17 20:43:08 +0000 | [diff] [blame] | 2512 | return DAG.getNode(ISD::BIT_CONVERT, VT, Shuffle); |
| 2513 | } |
| 2514 | |
Evan Cheng | ba05f72 | 2006-04-21 23:03:30 +0000 | [diff] [blame] | 2515 | /// getShuffleVectorZeroOrUndef - Return a vector_shuffle of the specified |
Evan Cheng | 213d2cf | 2007-05-17 18:45:50 +0000 | [diff] [blame] | 2516 | /// vector of zero or undef vector. |
Evan Cheng | ba05f72 | 2006-04-21 23:03:30 +0000 | [diff] [blame] | 2517 | static SDOperand getShuffleVectorZeroOrUndef(SDOperand V2, MVT::ValueType VT, |
Evan Cheng | 017dcc6 | 2006-04-21 01:05:10 +0000 | [diff] [blame] | 2518 | unsigned NumElems, unsigned Idx, |
Evan Cheng | ba05f72 | 2006-04-21 23:03:30 +0000 | [diff] [blame] | 2519 | bool isZero, SelectionDAG &DAG) { |
| 2520 | SDOperand V1 = isZero ? getZeroVector(VT, DAG) : DAG.getNode(ISD::UNDEF, VT); |
Evan Cheng | 017dcc6 | 2006-04-21 01:05:10 +0000 | [diff] [blame] | 2521 | MVT::ValueType MaskVT = MVT::getIntVectorWithNumElements(NumElems); |
Dan Gohman | 51eaa86 | 2007-06-14 22:58:02 +0000 | [diff] [blame] | 2522 | MVT::ValueType EVT = MVT::getVectorElementType(MaskVT); |
Evan Cheng | 017dcc6 | 2006-04-21 01:05:10 +0000 | [diff] [blame] | 2523 | SDOperand Zero = DAG.getConstant(0, EVT); |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 2524 | SmallVector<SDOperand, 8> MaskVec(NumElems, Zero); |
Evan Cheng | 017dcc6 | 2006-04-21 01:05:10 +0000 | [diff] [blame] | 2525 | MaskVec[Idx] = DAG.getConstant(NumElems, EVT); |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 2526 | SDOperand Mask = DAG.getNode(ISD::BUILD_VECTOR, MaskVT, |
| 2527 | &MaskVec[0], MaskVec.size()); |
Evan Cheng | ba05f72 | 2006-04-21 23:03:30 +0000 | [diff] [blame] | 2528 | return DAG.getNode(ISD::VECTOR_SHUFFLE, VT, V1, V2, Mask); |
Evan Cheng | 017dcc6 | 2006-04-21 01:05:10 +0000 | [diff] [blame] | 2529 | } |
| 2530 | |
Evan Cheng | c78d3b4 | 2006-04-24 18:01:45 +0000 | [diff] [blame] | 2531 | /// LowerBuildVectorv16i8 - Custom lower build_vector of v16i8. |
| 2532 | /// |
| 2533 | static SDOperand LowerBuildVectorv16i8(SDOperand Op, unsigned NonZeros, |
| 2534 | unsigned NumNonZero, unsigned NumZero, |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 2535 | SelectionDAG &DAG, TargetLowering &TLI) { |
Evan Cheng | c78d3b4 | 2006-04-24 18:01:45 +0000 | [diff] [blame] | 2536 | if (NumNonZero > 8) |
| 2537 | return SDOperand(); |
| 2538 | |
| 2539 | SDOperand V(0, 0); |
| 2540 | bool First = true; |
| 2541 | for (unsigned i = 0; i < 16; ++i) { |
| 2542 | bool ThisIsNonZero = (NonZeros & (1 << i)) != 0; |
| 2543 | if (ThisIsNonZero && First) { |
| 2544 | if (NumZero) |
| 2545 | V = getZeroVector(MVT::v8i16, DAG); |
| 2546 | else |
| 2547 | V = DAG.getNode(ISD::UNDEF, MVT::v8i16); |
| 2548 | First = false; |
| 2549 | } |
| 2550 | |
| 2551 | if ((i & 1) != 0) { |
| 2552 | SDOperand ThisElt(0, 0), LastElt(0, 0); |
| 2553 | bool LastIsNonZero = (NonZeros & (1 << (i-1))) != 0; |
| 2554 | if (LastIsNonZero) { |
| 2555 | LastElt = DAG.getNode(ISD::ZERO_EXTEND, MVT::i16, Op.getOperand(i-1)); |
| 2556 | } |
| 2557 | if (ThisIsNonZero) { |
| 2558 | ThisElt = DAG.getNode(ISD::ZERO_EXTEND, MVT::i16, Op.getOperand(i)); |
| 2559 | ThisElt = DAG.getNode(ISD::SHL, MVT::i16, |
| 2560 | ThisElt, DAG.getConstant(8, MVT::i8)); |
| 2561 | if (LastIsNonZero) |
| 2562 | ThisElt = DAG.getNode(ISD::OR, MVT::i16, ThisElt, LastElt); |
| 2563 | } else |
| 2564 | ThisElt = LastElt; |
| 2565 | |
| 2566 | if (ThisElt.Val) |
| 2567 | V = DAG.getNode(ISD::INSERT_VECTOR_ELT, MVT::v8i16, V, ThisElt, |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 2568 | DAG.getConstant(i/2, TLI.getPointerTy())); |
Evan Cheng | c78d3b4 | 2006-04-24 18:01:45 +0000 | [diff] [blame] | 2569 | } |
| 2570 | } |
| 2571 | |
| 2572 | return DAG.getNode(ISD::BIT_CONVERT, MVT::v16i8, V); |
| 2573 | } |
| 2574 | |
Bill Wendling | a348c56 | 2007-03-22 18:42:45 +0000 | [diff] [blame] | 2575 | /// LowerBuildVectorv8i16 - Custom lower build_vector of v8i16. |
Evan Cheng | c78d3b4 | 2006-04-24 18:01:45 +0000 | [diff] [blame] | 2576 | /// |
| 2577 | static SDOperand LowerBuildVectorv8i16(SDOperand Op, unsigned NonZeros, |
| 2578 | unsigned NumNonZero, unsigned NumZero, |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 2579 | SelectionDAG &DAG, TargetLowering &TLI) { |
Evan Cheng | c78d3b4 | 2006-04-24 18:01:45 +0000 | [diff] [blame] | 2580 | if (NumNonZero > 4) |
| 2581 | return SDOperand(); |
| 2582 | |
| 2583 | SDOperand V(0, 0); |
| 2584 | bool First = true; |
| 2585 | for (unsigned i = 0; i < 8; ++i) { |
| 2586 | bool isNonZero = (NonZeros & (1 << i)) != 0; |
| 2587 | if (isNonZero) { |
| 2588 | if (First) { |
| 2589 | if (NumZero) |
| 2590 | V = getZeroVector(MVT::v8i16, DAG); |
| 2591 | else |
| 2592 | V = DAG.getNode(ISD::UNDEF, MVT::v8i16); |
| 2593 | First = false; |
| 2594 | } |
| 2595 | V = DAG.getNode(ISD::INSERT_VECTOR_ELT, MVT::v8i16, V, Op.getOperand(i), |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 2596 | DAG.getConstant(i, TLI.getPointerTy())); |
Evan Cheng | c78d3b4 | 2006-04-24 18:01:45 +0000 | [diff] [blame] | 2597 | } |
| 2598 | } |
| 2599 | |
| 2600 | return V; |
| 2601 | } |
| 2602 | |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 2603 | SDOperand |
| 2604 | X86TargetLowering::LowerBUILD_VECTOR(SDOperand Op, SelectionDAG &DAG) { |
| 2605 | // All zero's are handled with pxor. |
| 2606 | if (ISD::isBuildVectorAllZeros(Op.Val)) |
| 2607 | return Op; |
| 2608 | |
| 2609 | // All one's are handled with pcmpeqd. |
| 2610 | if (ISD::isBuildVectorAllOnes(Op.Val)) |
| 2611 | return Op; |
| 2612 | |
| 2613 | MVT::ValueType VT = Op.getValueType(); |
Dan Gohman | 51eaa86 | 2007-06-14 22:58:02 +0000 | [diff] [blame] | 2614 | MVT::ValueType EVT = MVT::getVectorElementType(VT); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 2615 | unsigned EVTBits = MVT::getSizeInBits(EVT); |
| 2616 | |
| 2617 | unsigned NumElems = Op.getNumOperands(); |
| 2618 | unsigned NumZero = 0; |
| 2619 | unsigned NumNonZero = 0; |
| 2620 | unsigned NonZeros = 0; |
Dan Gohman | a394117 | 2007-07-24 22:55:08 +0000 | [diff] [blame] | 2621 | unsigned NumNonZeroImms = 0; |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 2622 | std::set<SDOperand> Values; |
| 2623 | for (unsigned i = 0; i < NumElems; ++i) { |
| 2624 | SDOperand Elt = Op.getOperand(i); |
| 2625 | if (Elt.getOpcode() != ISD::UNDEF) { |
| 2626 | Values.insert(Elt); |
| 2627 | if (isZeroNode(Elt)) |
| 2628 | NumZero++; |
| 2629 | else { |
| 2630 | NonZeros |= (1 << i); |
| 2631 | NumNonZero++; |
Dan Gohman | a394117 | 2007-07-24 22:55:08 +0000 | [diff] [blame] | 2632 | if (Elt.getOpcode() == ISD::Constant || |
| 2633 | Elt.getOpcode() == ISD::ConstantFP) |
| 2634 | NumNonZeroImms++; |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 2635 | } |
| 2636 | } |
| 2637 | } |
| 2638 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 2639 | if (NumNonZero == 0) { |
| 2640 | if (NumZero == 0) |
| 2641 | // All undef vector. Return an UNDEF. |
| 2642 | return DAG.getNode(ISD::UNDEF, VT); |
| 2643 | else |
| 2644 | // A mix of zero and undef. Return a zero vector. |
| 2645 | return getZeroVector(VT, DAG); |
| 2646 | } |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 2647 | |
| 2648 | // Splat is obviously ok. Let legalizer expand it to a shuffle. |
| 2649 | if (Values.size() == 1) |
| 2650 | return SDOperand(); |
| 2651 | |
| 2652 | // Special case for single non-zero element. |
Evan Cheng | 9bbbb98 | 2006-10-25 20:48:19 +0000 | [diff] [blame] | 2653 | if (NumNonZero == 1) { |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 2654 | unsigned Idx = CountTrailingZeros_32(NonZeros); |
| 2655 | SDOperand Item = Op.getOperand(Idx); |
| 2656 | Item = DAG.getNode(ISD::SCALAR_TO_VECTOR, VT, Item); |
| 2657 | if (Idx == 0) |
| 2658 | // Turn it into a MOVL (i.e. movss, movsd, or movd) to a zero vector. |
| 2659 | return getShuffleVectorZeroOrUndef(Item, VT, NumElems, Idx, |
| 2660 | NumZero > 0, DAG); |
| 2661 | |
| 2662 | if (EVTBits == 32) { |
| 2663 | // Turn it into a shuffle of zero and zero-extended scalar to vector. |
| 2664 | Item = getShuffleVectorZeroOrUndef(Item, VT, NumElems, 0, NumZero > 0, |
| 2665 | DAG); |
| 2666 | MVT::ValueType MaskVT = MVT::getIntVectorWithNumElements(NumElems); |
Dan Gohman | 51eaa86 | 2007-06-14 22:58:02 +0000 | [diff] [blame] | 2667 | MVT::ValueType MaskEVT = MVT::getVectorElementType(MaskVT); |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 2668 | SmallVector<SDOperand, 8> MaskVec; |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 2669 | for (unsigned i = 0; i < NumElems; i++) |
| 2670 | MaskVec.push_back(DAG.getConstant((i == Idx) ? 0 : 1, MaskEVT)); |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 2671 | SDOperand Mask = DAG.getNode(ISD::BUILD_VECTOR, MaskVT, |
| 2672 | &MaskVec[0], MaskVec.size()); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 2673 | return DAG.getNode(ISD::VECTOR_SHUFFLE, VT, Item, |
| 2674 | DAG.getNode(ISD::UNDEF, VT), Mask); |
| 2675 | } |
| 2676 | } |
| 2677 | |
Dan Gohman | a394117 | 2007-07-24 22:55:08 +0000 | [diff] [blame] | 2678 | // A vector full of immediates; various special cases are already |
| 2679 | // handled, so this is best done with a single constant-pool load. |
| 2680 | if (NumNonZero == NumNonZeroImms) |
| 2681 | return SDOperand(); |
| 2682 | |
Bill Wendling | 2f9bb1a | 2007-04-24 21:16:55 +0000 | [diff] [blame] | 2683 | // Let legalizer expand 2-wide build_vectors. |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 2684 | if (EVTBits == 64) |
| 2685 | return SDOperand(); |
| 2686 | |
| 2687 | // If element VT is < 32 bits, convert it to inserts into a zero vector. |
Bill Wendling | 826f36f | 2007-03-28 00:57:11 +0000 | [diff] [blame] | 2688 | if (EVTBits == 8 && NumElems == 16) { |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 2689 | SDOperand V = LowerBuildVectorv16i8(Op, NonZeros,NumNonZero,NumZero, DAG, |
| 2690 | *this); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 2691 | if (V.Val) return V; |
| 2692 | } |
| 2693 | |
Bill Wendling | 826f36f | 2007-03-28 00:57:11 +0000 | [diff] [blame] | 2694 | if (EVTBits == 16 && NumElems == 8) { |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 2695 | SDOperand V = LowerBuildVectorv8i16(Op, NonZeros,NumNonZero,NumZero, DAG, |
| 2696 | *this); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 2697 | if (V.Val) return V; |
| 2698 | } |
| 2699 | |
| 2700 | // If element VT is == 32 bits, turn it into a number of shuffles. |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 2701 | SmallVector<SDOperand, 8> V; |
| 2702 | V.resize(NumElems); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 2703 | if (NumElems == 4 && NumZero > 0) { |
| 2704 | for (unsigned i = 0; i < 4; ++i) { |
| 2705 | bool isZero = !(NonZeros & (1 << i)); |
| 2706 | if (isZero) |
| 2707 | V[i] = getZeroVector(VT, DAG); |
| 2708 | else |
| 2709 | V[i] = DAG.getNode(ISD::SCALAR_TO_VECTOR, VT, Op.getOperand(i)); |
| 2710 | } |
| 2711 | |
| 2712 | for (unsigned i = 0; i < 2; ++i) { |
| 2713 | switch ((NonZeros & (0x3 << i*2)) >> (i*2)) { |
| 2714 | default: break; |
| 2715 | case 0: |
| 2716 | V[i] = V[i*2]; // Must be a zero vector. |
| 2717 | break; |
| 2718 | case 1: |
| 2719 | V[i] = DAG.getNode(ISD::VECTOR_SHUFFLE, VT, V[i*2+1], V[i*2], |
| 2720 | getMOVLMask(NumElems, DAG)); |
| 2721 | break; |
| 2722 | case 2: |
| 2723 | V[i] = DAG.getNode(ISD::VECTOR_SHUFFLE, VT, V[i*2], V[i*2+1], |
| 2724 | getMOVLMask(NumElems, DAG)); |
| 2725 | break; |
| 2726 | case 3: |
| 2727 | V[i] = DAG.getNode(ISD::VECTOR_SHUFFLE, VT, V[i*2], V[i*2+1], |
| 2728 | getUnpacklMask(NumElems, DAG)); |
| 2729 | break; |
| 2730 | } |
| 2731 | } |
| 2732 | |
Evan Cheng | 069287d | 2006-05-16 07:21:53 +0000 | [diff] [blame] | 2733 | // Take advantage of the fact GR32 to VR128 scalar_to_vector (i.e. movd) |
Anton Korobeynikov | 12c49af | 2006-11-21 00:01:06 +0000 | [diff] [blame] | 2734 | // clears the upper bits. |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 2735 | // FIXME: we can do the same for v4f32 case when we know both parts of |
| 2736 | // the lower half come from scalar_to_vector (loadf32). We should do |
| 2737 | // that in post legalizer dag combiner with target specific hooks. |
Evan Cheng | 9bbbb98 | 2006-10-25 20:48:19 +0000 | [diff] [blame] | 2738 | if (MVT::isInteger(EVT) && (NonZeros & (0x3 << 2)) == 0) |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 2739 | return V[0]; |
| 2740 | MVT::ValueType MaskVT = MVT::getIntVectorWithNumElements(NumElems); |
Dan Gohman | 51eaa86 | 2007-06-14 22:58:02 +0000 | [diff] [blame] | 2741 | MVT::ValueType EVT = MVT::getVectorElementType(MaskVT); |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 2742 | SmallVector<SDOperand, 8> MaskVec; |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 2743 | bool Reverse = (NonZeros & 0x3) == 2; |
| 2744 | for (unsigned i = 0; i < 2; ++i) |
| 2745 | if (Reverse) |
| 2746 | MaskVec.push_back(DAG.getConstant(1-i, EVT)); |
| 2747 | else |
| 2748 | MaskVec.push_back(DAG.getConstant(i, EVT)); |
| 2749 | Reverse = ((NonZeros & (0x3 << 2)) >> 2) == 2; |
| 2750 | for (unsigned i = 0; i < 2; ++i) |
| 2751 | if (Reverse) |
| 2752 | MaskVec.push_back(DAG.getConstant(1-i+NumElems, EVT)); |
| 2753 | else |
| 2754 | MaskVec.push_back(DAG.getConstant(i+NumElems, EVT)); |
Chris Lattner | e219945 | 2006-08-11 17:38:39 +0000 | [diff] [blame] | 2755 | SDOperand ShufMask = DAG.getNode(ISD::BUILD_VECTOR, MaskVT, |
| 2756 | &MaskVec[0], MaskVec.size()); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 2757 | return DAG.getNode(ISD::VECTOR_SHUFFLE, VT, V[0], V[1], ShufMask); |
| 2758 | } |
| 2759 | |
| 2760 | if (Values.size() > 2) { |
| 2761 | // Expand into a number of unpckl*. |
| 2762 | // e.g. for v4f32 |
| 2763 | // Step 1: unpcklps 0, 2 ==> X: <?, ?, 2, 0> |
| 2764 | // : unpcklps 1, 3 ==> Y: <?, ?, 3, 1> |
| 2765 | // Step 2: unpcklps X, Y ==> <3, 2, 1, 0> |
| 2766 | SDOperand UnpckMask = getUnpacklMask(NumElems, DAG); |
| 2767 | for (unsigned i = 0; i < NumElems; ++i) |
| 2768 | V[i] = DAG.getNode(ISD::SCALAR_TO_VECTOR, VT, Op.getOperand(i)); |
| 2769 | NumElems >>= 1; |
| 2770 | while (NumElems != 0) { |
| 2771 | for (unsigned i = 0; i < NumElems; ++i) |
| 2772 | V[i] = DAG.getNode(ISD::VECTOR_SHUFFLE, VT, V[i], V[i + NumElems], |
| 2773 | UnpckMask); |
| 2774 | NumElems >>= 1; |
| 2775 | } |
| 2776 | return V[0]; |
| 2777 | } |
| 2778 | |
| 2779 | return SDOperand(); |
| 2780 | } |
| 2781 | |
| 2782 | SDOperand |
| 2783 | X86TargetLowering::LowerVECTOR_SHUFFLE(SDOperand Op, SelectionDAG &DAG) { |
| 2784 | SDOperand V1 = Op.getOperand(0); |
| 2785 | SDOperand V2 = Op.getOperand(1); |
| 2786 | SDOperand PermMask = Op.getOperand(2); |
| 2787 | MVT::ValueType VT = Op.getValueType(); |
| 2788 | unsigned NumElems = PermMask.getNumOperands(); |
| 2789 | bool V1IsUndef = V1.getOpcode() == ISD::UNDEF; |
| 2790 | bool V2IsUndef = V2.getOpcode() == ISD::UNDEF; |
Evan Cheng | d9b8e40 | 2006-10-16 06:36:00 +0000 | [diff] [blame] | 2791 | bool V1IsSplat = false; |
| 2792 | bool V2IsSplat = false; |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 2793 | |
Evan Cheng | 8cf723d | 2006-09-08 01:50:06 +0000 | [diff] [blame] | 2794 | if (isUndefShuffle(Op.Val)) |
| 2795 | return DAG.getNode(ISD::UNDEF, VT); |
| 2796 | |
Evan Cheng | 213d2cf | 2007-05-17 18:45:50 +0000 | [diff] [blame] | 2797 | if (isZeroShuffle(Op.Val)) |
| 2798 | return getZeroVector(VT, DAG); |
| 2799 | |
Evan Cheng | 49892af | 2007-06-19 00:02:56 +0000 | [diff] [blame] | 2800 | if (isIdentityMask(PermMask.Val)) |
| 2801 | return V1; |
| 2802 | else if (isIdentityMask(PermMask.Val, true)) |
| 2803 | return V2; |
| 2804 | |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 2805 | if (isSplatMask(PermMask.Val)) { |
| 2806 | if (NumElems <= 4) return Op; |
| 2807 | // Promote it to a v4i32 splat. |
Evan Cheng | 9bbbb98 | 2006-10-25 20:48:19 +0000 | [diff] [blame] | 2808 | return PromoteSplat(Op, DAG); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 2809 | } |
| 2810 | |
Evan Cheng | 9bbbb98 | 2006-10-25 20:48:19 +0000 | [diff] [blame] | 2811 | if (X86::isMOVLMask(PermMask.Val)) |
| 2812 | return (V1IsUndef) ? V2 : Op; |
Anton Korobeynikov | 12c49af | 2006-11-21 00:01:06 +0000 | [diff] [blame] | 2813 | |
Evan Cheng | 9bbbb98 | 2006-10-25 20:48:19 +0000 | [diff] [blame] | 2814 | if (X86::isMOVSHDUPMask(PermMask.Val) || |
| 2815 | X86::isMOVSLDUPMask(PermMask.Val) || |
| 2816 | X86::isMOVHLPSMask(PermMask.Val) || |
| 2817 | X86::isMOVHPMask(PermMask.Val) || |
| 2818 | X86::isMOVLPMask(PermMask.Val)) |
| 2819 | return Op; |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 2820 | |
Evan Cheng | 9bbbb98 | 2006-10-25 20:48:19 +0000 | [diff] [blame] | 2821 | if (ShouldXformToMOVHLPS(PermMask.Val) || |
| 2822 | ShouldXformToMOVLP(V1.Val, V2.Val, PermMask.Val)) |
Evan Cheng | 9eca5e8 | 2006-10-25 21:49:50 +0000 | [diff] [blame] | 2823 | return CommuteVectorShuffle(Op, V1, V2, PermMask, DAG); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 2824 | |
Evan Cheng | 9eca5e8 | 2006-10-25 21:49:50 +0000 | [diff] [blame] | 2825 | bool Commuted = false; |
Evan Cheng | 9bbbb98 | 2006-10-25 20:48:19 +0000 | [diff] [blame] | 2826 | V1IsSplat = isSplatVector(V1.Val); |
| 2827 | V2IsSplat = isSplatVector(V2.Val); |
| 2828 | if ((V1IsSplat || V1IsUndef) && !(V2IsSplat || V2IsUndef)) { |
Evan Cheng | 9eca5e8 | 2006-10-25 21:49:50 +0000 | [diff] [blame] | 2829 | Op = CommuteVectorShuffle(Op, V1, V2, PermMask, DAG); |
Evan Cheng | 9bbbb98 | 2006-10-25 20:48:19 +0000 | [diff] [blame] | 2830 | std::swap(V1IsSplat, V2IsSplat); |
| 2831 | std::swap(V1IsUndef, V2IsUndef); |
Evan Cheng | 9eca5e8 | 2006-10-25 21:49:50 +0000 | [diff] [blame] | 2832 | Commuted = true; |
Evan Cheng | 9bbbb98 | 2006-10-25 20:48:19 +0000 | [diff] [blame] | 2833 | } |
| 2834 | |
| 2835 | if (isCommutedMOVL(PermMask.Val, V2IsSplat, V2IsUndef)) { |
| 2836 | if (V2IsUndef) return V1; |
Evan Cheng | 9eca5e8 | 2006-10-25 21:49:50 +0000 | [diff] [blame] | 2837 | Op = CommuteVectorShuffle(Op, V1, V2, PermMask, DAG); |
Evan Cheng | 9bbbb98 | 2006-10-25 20:48:19 +0000 | [diff] [blame] | 2838 | if (V2IsSplat) { |
| 2839 | // V2 is a splat, so the mask may be malformed. That is, it may point |
| 2840 | // to any V2 element. The instruction selectior won't like this. Get |
| 2841 | // a corrected mask and commute to form a proper MOVS{S|D}. |
| 2842 | SDOperand NewMask = getMOVLMask(NumElems, DAG); |
| 2843 | if (NewMask.Val != PermMask.Val) |
| 2844 | Op = DAG.getNode(ISD::VECTOR_SHUFFLE, VT, V1, V2, NewMask); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 2845 | } |
Evan Cheng | 9bbbb98 | 2006-10-25 20:48:19 +0000 | [diff] [blame] | 2846 | return Op; |
Evan Cheng | d9b8e40 | 2006-10-16 06:36:00 +0000 | [diff] [blame] | 2847 | } |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 2848 | |
Evan Cheng | d9b8e40 | 2006-10-16 06:36:00 +0000 | [diff] [blame] | 2849 | if (X86::isUNPCKL_v_undef_Mask(PermMask.Val) || |
Bill Wendling | 2f9bb1a | 2007-04-24 21:16:55 +0000 | [diff] [blame] | 2850 | X86::isUNPCKH_v_undef_Mask(PermMask.Val) || |
Evan Cheng | d9b8e40 | 2006-10-16 06:36:00 +0000 | [diff] [blame] | 2851 | X86::isUNPCKLMask(PermMask.Val) || |
| 2852 | X86::isUNPCKHMask(PermMask.Val)) |
| 2853 | return Op; |
Evan Cheng | e111303 | 2006-10-04 18:33:38 +0000 | [diff] [blame] | 2854 | |
Evan Cheng | 9bbbb98 | 2006-10-25 20:48:19 +0000 | [diff] [blame] | 2855 | if (V2IsSplat) { |
| 2856 | // Normalize mask so all entries that point to V2 points to its first |
Anton Korobeynikov | 12c49af | 2006-11-21 00:01:06 +0000 | [diff] [blame] | 2857 | // element then try to match unpck{h|l} again. If match, return a |
Evan Cheng | 9bbbb98 | 2006-10-25 20:48:19 +0000 | [diff] [blame] | 2858 | // new vector_shuffle with the corrected mask. |
| 2859 | SDOperand NewMask = NormalizeMask(PermMask, DAG); |
| 2860 | if (NewMask.Val != PermMask.Val) { |
| 2861 | if (X86::isUNPCKLMask(PermMask.Val, true)) { |
| 2862 | SDOperand NewMask = getUnpacklMask(NumElems, DAG); |
| 2863 | return DAG.getNode(ISD::VECTOR_SHUFFLE, VT, V1, V2, NewMask); |
| 2864 | } else if (X86::isUNPCKHMask(PermMask.Val, true)) { |
| 2865 | SDOperand NewMask = getUnpackhMask(NumElems, DAG); |
| 2866 | return DAG.getNode(ISD::VECTOR_SHUFFLE, VT, V1, V2, NewMask); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 2867 | } |
| 2868 | } |
| 2869 | } |
| 2870 | |
| 2871 | // Normalize the node to match x86 shuffle ops if needed |
Evan Cheng | 9eca5e8 | 2006-10-25 21:49:50 +0000 | [diff] [blame] | 2872 | if (V2.getOpcode() != ISD::UNDEF && isCommutedSHUFP(PermMask.Val)) |
| 2873 | Op = CommuteVectorShuffle(Op, V1, V2, PermMask, DAG); |
| 2874 | |
| 2875 | if (Commuted) { |
| 2876 | // Commute is back and try unpck* again. |
| 2877 | Op = CommuteVectorShuffle(Op, V1, V2, PermMask, DAG); |
| 2878 | if (X86::isUNPCKL_v_undef_Mask(PermMask.Val) || |
Bill Wendling | 2f9bb1a | 2007-04-24 21:16:55 +0000 | [diff] [blame] | 2879 | X86::isUNPCKH_v_undef_Mask(PermMask.Val) || |
Evan Cheng | 9eca5e8 | 2006-10-25 21:49:50 +0000 | [diff] [blame] | 2880 | X86::isUNPCKLMask(PermMask.Val) || |
| 2881 | X86::isUNPCKHMask(PermMask.Val)) |
| 2882 | return Op; |
| 2883 | } |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 2884 | |
| 2885 | // If VT is integer, try PSHUF* first, then SHUFP*. |
| 2886 | if (MVT::isInteger(VT)) { |
Dan Gohman | 7f55fcb | 2007-08-02 21:17:01 +0000 | [diff] [blame] | 2887 | // MMX doesn't have PSHUFD; it does have PSHUFW. While it's theoretically |
| 2888 | // possible to shuffle a v2i32 using PSHUFW, that's not yet implemented. |
| 2889 | if (((MVT::getSizeInBits(VT) != 64 || NumElems == 4) && |
| 2890 | X86::isPSHUFDMask(PermMask.Val)) || |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 2891 | X86::isPSHUFHWMask(PermMask.Val) || |
| 2892 | X86::isPSHUFLWMask(PermMask.Val)) { |
| 2893 | if (V2.getOpcode() != ISD::UNDEF) |
| 2894 | return DAG.getNode(ISD::VECTOR_SHUFFLE, VT, V1, |
| 2895 | DAG.getNode(ISD::UNDEF, V1.getValueType()),PermMask); |
| 2896 | return Op; |
| 2897 | } |
| 2898 | |
Chris Lattner | 07c70cd | 2007-05-17 17:13:13 +0000 | [diff] [blame] | 2899 | if (X86::isSHUFPMask(PermMask.Val) && |
| 2900 | MVT::getSizeInBits(VT) != 64) // Don't do this for MMX. |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 2901 | return Op; |
| 2902 | |
| 2903 | // Handle v8i16 shuffle high / low shuffle node pair. |
| 2904 | if (VT == MVT::v8i16 && isPSHUFHW_PSHUFLWMask(PermMask.Val)) { |
| 2905 | MVT::ValueType MaskVT = MVT::getIntVectorWithNumElements(NumElems); |
Dan Gohman | 51eaa86 | 2007-06-14 22:58:02 +0000 | [diff] [blame] | 2906 | MVT::ValueType BaseVT = MVT::getVectorElementType(MaskVT); |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 2907 | SmallVector<SDOperand, 8> MaskVec; |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 2908 | for (unsigned i = 0; i != 4; ++i) |
| 2909 | MaskVec.push_back(PermMask.getOperand(i)); |
| 2910 | for (unsigned i = 4; i != 8; ++i) |
| 2911 | MaskVec.push_back(DAG.getConstant(i, BaseVT)); |
Chris Lattner | e219945 | 2006-08-11 17:38:39 +0000 | [diff] [blame] | 2912 | SDOperand Mask = DAG.getNode(ISD::BUILD_VECTOR, MaskVT, |
| 2913 | &MaskVec[0], MaskVec.size()); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 2914 | V1 = DAG.getNode(ISD::VECTOR_SHUFFLE, VT, V1, V2, Mask); |
| 2915 | MaskVec.clear(); |
| 2916 | for (unsigned i = 0; i != 4; ++i) |
| 2917 | MaskVec.push_back(DAG.getConstant(i, BaseVT)); |
| 2918 | for (unsigned i = 4; i != 8; ++i) |
| 2919 | MaskVec.push_back(PermMask.getOperand(i)); |
Chris Lattner | e219945 | 2006-08-11 17:38:39 +0000 | [diff] [blame] | 2920 | Mask = DAG.getNode(ISD::BUILD_VECTOR, MaskVT, &MaskVec[0],MaskVec.size()); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 2921 | return DAG.getNode(ISD::VECTOR_SHUFFLE, VT, V1, V2, Mask); |
| 2922 | } |
| 2923 | } else { |
| 2924 | // Floating point cases in the other order. |
| 2925 | if (X86::isSHUFPMask(PermMask.Val)) |
| 2926 | return Op; |
| 2927 | if (X86::isPSHUFDMask(PermMask.Val) || |
| 2928 | X86::isPSHUFHWMask(PermMask.Val) || |
| 2929 | X86::isPSHUFLWMask(PermMask.Val)) { |
| 2930 | if (V2.getOpcode() != ISD::UNDEF) |
| 2931 | return DAG.getNode(ISD::VECTOR_SHUFFLE, VT, V1, |
| 2932 | DAG.getNode(ISD::UNDEF, V1.getValueType()),PermMask); |
| 2933 | return Op; |
| 2934 | } |
| 2935 | } |
| 2936 | |
Chris Lattner | 07c70cd | 2007-05-17 17:13:13 +0000 | [diff] [blame] | 2937 | if (NumElems == 4 && |
| 2938 | // Don't do this for MMX. |
| 2939 | MVT::getSizeInBits(VT) != 64) { |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 2940 | MVT::ValueType MaskVT = PermMask.getValueType(); |
Dan Gohman | 51eaa86 | 2007-06-14 22:58:02 +0000 | [diff] [blame] | 2941 | MVT::ValueType MaskEVT = MVT::getVectorElementType(MaskVT); |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 2942 | SmallVector<std::pair<int, int>, 8> Locs; |
Evan Cheng | 43f3bd3 | 2006-04-28 07:03:38 +0000 | [diff] [blame] | 2943 | Locs.reserve(NumElems); |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 2944 | SmallVector<SDOperand, 8> Mask1(NumElems, DAG.getNode(ISD::UNDEF, MaskEVT)); |
| 2945 | SmallVector<SDOperand, 8> Mask2(NumElems, DAG.getNode(ISD::UNDEF, MaskEVT)); |
Evan Cheng | 43f3bd3 | 2006-04-28 07:03:38 +0000 | [diff] [blame] | 2946 | unsigned NumHi = 0; |
| 2947 | unsigned NumLo = 0; |
| 2948 | // If no more than two elements come from either vector. This can be |
| 2949 | // implemented with two shuffles. First shuffle gather the elements. |
| 2950 | // The second shuffle, which takes the first shuffle as both of its |
| 2951 | // vector operands, put the elements into the right order. |
| 2952 | for (unsigned i = 0; i != NumElems; ++i) { |
| 2953 | SDOperand Elt = PermMask.getOperand(i); |
| 2954 | if (Elt.getOpcode() == ISD::UNDEF) { |
| 2955 | Locs[i] = std::make_pair(-1, -1); |
| 2956 | } else { |
| 2957 | unsigned Val = cast<ConstantSDNode>(Elt)->getValue(); |
| 2958 | if (Val < NumElems) { |
| 2959 | Locs[i] = std::make_pair(0, NumLo); |
| 2960 | Mask1[NumLo] = Elt; |
| 2961 | NumLo++; |
| 2962 | } else { |
| 2963 | Locs[i] = std::make_pair(1, NumHi); |
| 2964 | if (2+NumHi < NumElems) |
| 2965 | Mask1[2+NumHi] = Elt; |
| 2966 | NumHi++; |
| 2967 | } |
| 2968 | } |
| 2969 | } |
| 2970 | if (NumLo <= 2 && NumHi <= 2) { |
| 2971 | V1 = DAG.getNode(ISD::VECTOR_SHUFFLE, VT, V1, V2, |
Chris Lattner | e219945 | 2006-08-11 17:38:39 +0000 | [diff] [blame] | 2972 | DAG.getNode(ISD::BUILD_VECTOR, MaskVT, |
| 2973 | &Mask1[0], Mask1.size())); |
Evan Cheng | 43f3bd3 | 2006-04-28 07:03:38 +0000 | [diff] [blame] | 2974 | for (unsigned i = 0; i != NumElems; ++i) { |
| 2975 | if (Locs[i].first == -1) |
| 2976 | continue; |
| 2977 | else { |
| 2978 | unsigned Idx = (i < NumElems/2) ? 0 : NumElems; |
| 2979 | Idx += Locs[i].first * (NumElems/2) + Locs[i].second; |
| 2980 | Mask2[i] = DAG.getConstant(Idx, MaskEVT); |
| 2981 | } |
| 2982 | } |
| 2983 | |
| 2984 | return DAG.getNode(ISD::VECTOR_SHUFFLE, VT, V1, V1, |
Chris Lattner | e219945 | 2006-08-11 17:38:39 +0000 | [diff] [blame] | 2985 | DAG.getNode(ISD::BUILD_VECTOR, MaskVT, |
| 2986 | &Mask2[0], Mask2.size())); |
Evan Cheng | 43f3bd3 | 2006-04-28 07:03:38 +0000 | [diff] [blame] | 2987 | } |
| 2988 | |
| 2989 | // Break it into (shuffle shuffle_hi, shuffle_lo). |
| 2990 | Locs.clear(); |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 2991 | SmallVector<SDOperand,8> LoMask(NumElems, DAG.getNode(ISD::UNDEF, MaskEVT)); |
| 2992 | SmallVector<SDOperand,8> HiMask(NumElems, DAG.getNode(ISD::UNDEF, MaskEVT)); |
| 2993 | SmallVector<SDOperand,8> *MaskPtr = &LoMask; |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 2994 | unsigned MaskIdx = 0; |
| 2995 | unsigned LoIdx = 0; |
| 2996 | unsigned HiIdx = NumElems/2; |
| 2997 | for (unsigned i = 0; i != NumElems; ++i) { |
| 2998 | if (i == NumElems/2) { |
| 2999 | MaskPtr = &HiMask; |
| 3000 | MaskIdx = 1; |
| 3001 | LoIdx = 0; |
| 3002 | HiIdx = NumElems/2; |
| 3003 | } |
| 3004 | SDOperand Elt = PermMask.getOperand(i); |
| 3005 | if (Elt.getOpcode() == ISD::UNDEF) { |
| 3006 | Locs[i] = std::make_pair(-1, -1); |
| 3007 | } else if (cast<ConstantSDNode>(Elt)->getValue() < NumElems) { |
| 3008 | Locs[i] = std::make_pair(MaskIdx, LoIdx); |
| 3009 | (*MaskPtr)[LoIdx] = Elt; |
| 3010 | LoIdx++; |
| 3011 | } else { |
| 3012 | Locs[i] = std::make_pair(MaskIdx, HiIdx); |
| 3013 | (*MaskPtr)[HiIdx] = Elt; |
| 3014 | HiIdx++; |
| 3015 | } |
| 3016 | } |
| 3017 | |
Chris Lattner | 8c0c10c | 2006-05-16 06:45:34 +0000 | [diff] [blame] | 3018 | SDOperand LoShuffle = |
| 3019 | DAG.getNode(ISD::VECTOR_SHUFFLE, VT, V1, V2, |
Chris Lattner | e219945 | 2006-08-11 17:38:39 +0000 | [diff] [blame] | 3020 | DAG.getNode(ISD::BUILD_VECTOR, MaskVT, |
| 3021 | &LoMask[0], LoMask.size())); |
Anton Korobeynikov | 12c49af | 2006-11-21 00:01:06 +0000 | [diff] [blame] | 3022 | SDOperand HiShuffle = |
Chris Lattner | 8c0c10c | 2006-05-16 06:45:34 +0000 | [diff] [blame] | 3023 | DAG.getNode(ISD::VECTOR_SHUFFLE, VT, V1, V2, |
Chris Lattner | e219945 | 2006-08-11 17:38:39 +0000 | [diff] [blame] | 3024 | DAG.getNode(ISD::BUILD_VECTOR, MaskVT, |
| 3025 | &HiMask[0], HiMask.size())); |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 3026 | SmallVector<SDOperand, 8> MaskOps; |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3027 | for (unsigned i = 0; i != NumElems; ++i) { |
| 3028 | if (Locs[i].first == -1) { |
| 3029 | MaskOps.push_back(DAG.getNode(ISD::UNDEF, MaskEVT)); |
| 3030 | } else { |
| 3031 | unsigned Idx = Locs[i].first * NumElems + Locs[i].second; |
| 3032 | MaskOps.push_back(DAG.getConstant(Idx, MaskEVT)); |
| 3033 | } |
| 3034 | } |
| 3035 | return DAG.getNode(ISD::VECTOR_SHUFFLE, VT, LoShuffle, HiShuffle, |
Chris Lattner | e219945 | 2006-08-11 17:38:39 +0000 | [diff] [blame] | 3036 | DAG.getNode(ISD::BUILD_VECTOR, MaskVT, |
| 3037 | &MaskOps[0], MaskOps.size())); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3038 | } |
| 3039 | |
| 3040 | return SDOperand(); |
| 3041 | } |
| 3042 | |
| 3043 | SDOperand |
| 3044 | X86TargetLowering::LowerEXTRACT_VECTOR_ELT(SDOperand Op, SelectionDAG &DAG) { |
| 3045 | if (!isa<ConstantSDNode>(Op.getOperand(1))) |
| 3046 | return SDOperand(); |
| 3047 | |
| 3048 | MVT::ValueType VT = Op.getValueType(); |
| 3049 | // TODO: handle v16i8. |
| 3050 | if (MVT::getSizeInBits(VT) == 16) { |
| 3051 | // Transform it so it match pextrw which produces a 32-bit result. |
| 3052 | MVT::ValueType EVT = (MVT::ValueType)(VT+1); |
| 3053 | SDOperand Extract = DAG.getNode(X86ISD::PEXTRW, EVT, |
| 3054 | Op.getOperand(0), Op.getOperand(1)); |
| 3055 | SDOperand Assert = DAG.getNode(ISD::AssertZext, EVT, Extract, |
| 3056 | DAG.getValueType(VT)); |
| 3057 | return DAG.getNode(ISD::TRUNCATE, VT, Assert); |
| 3058 | } else if (MVT::getSizeInBits(VT) == 32) { |
| 3059 | SDOperand Vec = Op.getOperand(0); |
| 3060 | unsigned Idx = cast<ConstantSDNode>(Op.getOperand(1))->getValue(); |
| 3061 | if (Idx == 0) |
| 3062 | return Op; |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3063 | // SHUFPS the element to the lowest double word, then movss. |
| 3064 | MVT::ValueType MaskVT = MVT::getIntVectorWithNumElements(4); |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 3065 | SmallVector<SDOperand, 8> IdxVec; |
Dan Gohman | 51eaa86 | 2007-06-14 22:58:02 +0000 | [diff] [blame] | 3066 | IdxVec.push_back(DAG.getConstant(Idx, MVT::getVectorElementType(MaskVT))); |
| 3067 | IdxVec.push_back(DAG.getNode(ISD::UNDEF, MVT::getVectorElementType(MaskVT))); |
| 3068 | IdxVec.push_back(DAG.getNode(ISD::UNDEF, MVT::getVectorElementType(MaskVT))); |
| 3069 | IdxVec.push_back(DAG.getNode(ISD::UNDEF, MVT::getVectorElementType(MaskVT))); |
Chris Lattner | e219945 | 2006-08-11 17:38:39 +0000 | [diff] [blame] | 3070 | SDOperand Mask = DAG.getNode(ISD::BUILD_VECTOR, MaskVT, |
| 3071 | &IdxVec[0], IdxVec.size()); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3072 | Vec = DAG.getNode(ISD::VECTOR_SHUFFLE, Vec.getValueType(), |
Evan Cheng | 6e56e2c | 2006-11-07 22:14:24 +0000 | [diff] [blame] | 3073 | Vec, DAG.getNode(ISD::UNDEF, Vec.getValueType()), Mask); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3074 | return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, VT, Vec, |
Evan Cheng | 015188f | 2006-06-15 08:14:54 +0000 | [diff] [blame] | 3075 | DAG.getConstant(0, getPointerTy())); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3076 | } else if (MVT::getSizeInBits(VT) == 64) { |
| 3077 | SDOperand Vec = Op.getOperand(0); |
| 3078 | unsigned Idx = cast<ConstantSDNode>(Op.getOperand(1))->getValue(); |
| 3079 | if (Idx == 0) |
| 3080 | return Op; |
| 3081 | |
| 3082 | // UNPCKHPD the element to the lowest double word, then movsd. |
| 3083 | // Note if the lower 64 bits of the result of the UNPCKHPD is then stored |
| 3084 | // to a f64mem, the whole operation is folded into a single MOVHPDmr. |
| 3085 | MVT::ValueType MaskVT = MVT::getIntVectorWithNumElements(4); |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 3086 | SmallVector<SDOperand, 8> IdxVec; |
Dan Gohman | 51eaa86 | 2007-06-14 22:58:02 +0000 | [diff] [blame] | 3087 | IdxVec.push_back(DAG.getConstant(1, MVT::getVectorElementType(MaskVT))); |
| 3088 | IdxVec.push_back(DAG.getNode(ISD::UNDEF, MVT::getVectorElementType(MaskVT))); |
Chris Lattner | e219945 | 2006-08-11 17:38:39 +0000 | [diff] [blame] | 3089 | SDOperand Mask = DAG.getNode(ISD::BUILD_VECTOR, MaskVT, |
| 3090 | &IdxVec[0], IdxVec.size()); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3091 | Vec = DAG.getNode(ISD::VECTOR_SHUFFLE, Vec.getValueType(), |
| 3092 | Vec, DAG.getNode(ISD::UNDEF, Vec.getValueType()), Mask); |
| 3093 | return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, VT, Vec, |
Evan Cheng | 015188f | 2006-06-15 08:14:54 +0000 | [diff] [blame] | 3094 | DAG.getConstant(0, getPointerTy())); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3095 | } |
| 3096 | |
| 3097 | return SDOperand(); |
| 3098 | } |
| 3099 | |
| 3100 | SDOperand |
| 3101 | X86TargetLowering::LowerINSERT_VECTOR_ELT(SDOperand Op, SelectionDAG &DAG) { |
Evan Cheng | 069287d | 2006-05-16 07:21:53 +0000 | [diff] [blame] | 3102 | // Transform it so it match pinsrw which expects a 16-bit value in a GR32 |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3103 | // as its second argument. |
| 3104 | MVT::ValueType VT = Op.getValueType(); |
Dan Gohman | 51eaa86 | 2007-06-14 22:58:02 +0000 | [diff] [blame] | 3105 | MVT::ValueType BaseVT = MVT::getVectorElementType(VT); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3106 | SDOperand N0 = Op.getOperand(0); |
| 3107 | SDOperand N1 = Op.getOperand(1); |
| 3108 | SDOperand N2 = Op.getOperand(2); |
| 3109 | if (MVT::getSizeInBits(BaseVT) == 16) { |
| 3110 | if (N1.getValueType() != MVT::i32) |
| 3111 | N1 = DAG.getNode(ISD::ANY_EXTEND, MVT::i32, N1); |
| 3112 | if (N2.getValueType() != MVT::i32) |
Evan Cheng | 0db5862 | 2007-06-29 00:01:20 +0000 | [diff] [blame] | 3113 | N2 = DAG.getConstant(cast<ConstantSDNode>(N2)->getValue(),getPointerTy()); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3114 | return DAG.getNode(X86ISD::PINSRW, VT, N0, N1, N2); |
| 3115 | } else if (MVT::getSizeInBits(BaseVT) == 32) { |
| 3116 | unsigned Idx = cast<ConstantSDNode>(N2)->getValue(); |
| 3117 | if (Idx == 0) { |
| 3118 | // Use a movss. |
| 3119 | N1 = DAG.getNode(ISD::SCALAR_TO_VECTOR, VT, N1); |
| 3120 | MVT::ValueType MaskVT = MVT::getIntVectorWithNumElements(4); |
Dan Gohman | 51eaa86 | 2007-06-14 22:58:02 +0000 | [diff] [blame] | 3121 | MVT::ValueType BaseVT = MVT::getVectorElementType(MaskVT); |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 3122 | SmallVector<SDOperand, 8> MaskVec; |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3123 | MaskVec.push_back(DAG.getConstant(4, BaseVT)); |
| 3124 | for (unsigned i = 1; i <= 3; ++i) |
| 3125 | MaskVec.push_back(DAG.getConstant(i, BaseVT)); |
| 3126 | return DAG.getNode(ISD::VECTOR_SHUFFLE, VT, N0, N1, |
Chris Lattner | e219945 | 2006-08-11 17:38:39 +0000 | [diff] [blame] | 3127 | DAG.getNode(ISD::BUILD_VECTOR, MaskVT, |
| 3128 | &MaskVec[0], MaskVec.size())); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3129 | } else { |
| 3130 | // Use two pinsrw instructions to insert a 32 bit value. |
| 3131 | Idx <<= 1; |
| 3132 | if (MVT::isFloatingPoint(N1.getValueType())) { |
Evan Cheng | 4ebcc8c | 2007-07-31 06:21:44 +0000 | [diff] [blame] | 3133 | N1 = DAG.getNode(ISD::SCALAR_TO_VECTOR, MVT::v4f32, N1); |
| 3134 | N1 = DAG.getNode(ISD::BIT_CONVERT, MVT::v4i32, N1); |
| 3135 | N1 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, MVT::i32, N1, |
| 3136 | DAG.getConstant(0, getPointerTy())); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3137 | } |
| 3138 | N0 = DAG.getNode(ISD::BIT_CONVERT, MVT::v8i16, N0); |
| 3139 | N0 = DAG.getNode(X86ISD::PINSRW, MVT::v8i16, N0, N1, |
Evan Cheng | 015188f | 2006-06-15 08:14:54 +0000 | [diff] [blame] | 3140 | DAG.getConstant(Idx, getPointerTy())); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3141 | N1 = DAG.getNode(ISD::SRL, MVT::i32, N1, DAG.getConstant(16, MVT::i8)); |
| 3142 | N0 = DAG.getNode(X86ISD::PINSRW, MVT::v8i16, N0, N1, |
Evan Cheng | 015188f | 2006-06-15 08:14:54 +0000 | [diff] [blame] | 3143 | DAG.getConstant(Idx+1, getPointerTy())); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3144 | return DAG.getNode(ISD::BIT_CONVERT, VT, N0); |
| 3145 | } |
| 3146 | } |
| 3147 | |
| 3148 | return SDOperand(); |
| 3149 | } |
| 3150 | |
| 3151 | SDOperand |
| 3152 | X86TargetLowering::LowerSCALAR_TO_VECTOR(SDOperand Op, SelectionDAG &DAG) { |
| 3153 | SDOperand AnyExt = DAG.getNode(ISD::ANY_EXTEND, MVT::i32, Op.getOperand(0)); |
| 3154 | return DAG.getNode(X86ISD::S2VEC, Op.getValueType(), AnyExt); |
| 3155 | } |
| 3156 | |
Anton Korobeynikov | 12c49af | 2006-11-21 00:01:06 +0000 | [diff] [blame] | 3157 | // ConstantPool, JumpTable, GlobalAddress, and ExternalSymbol are lowered as |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3158 | // their target countpart wrapped in the X86ISD::Wrapper node. Suppose N is |
| 3159 | // one of the above mentioned nodes. It has to be wrapped because otherwise |
| 3160 | // Select(N) returns N. So the raw TargetGlobalAddress nodes, etc. can only |
| 3161 | // be used to form addressing mode. These wrapped nodes will be selected |
| 3162 | // into MOV32ri. |
| 3163 | SDOperand |
| 3164 | X86TargetLowering::LowerConstantPool(SDOperand Op, SelectionDAG &DAG) { |
| 3165 | ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op); |
Evan Cheng | d0ff02c | 2006-11-29 23:19:46 +0000 | [diff] [blame] | 3166 | SDOperand Result = DAG.getTargetConstantPool(CP->getConstVal(), |
| 3167 | getPointerTy(), |
| 3168 | CP->getAlignment()); |
Evan Cheng | 19f2ffc | 2006-12-05 04:01:03 +0000 | [diff] [blame] | 3169 | Result = DAG.getNode(X86ISD::Wrapper, getPointerTy(), Result); |
Anton Korobeynikov | 7f70559 | 2007-01-12 19:20:47 +0000 | [diff] [blame] | 3170 | // With PIC, the address is actually $g + Offset. |
| 3171 | if (getTargetMachine().getRelocationModel() == Reloc::PIC_ && |
| 3172 | !Subtarget->isPICStyleRIPRel()) { |
| 3173 | Result = DAG.getNode(ISD::ADD, getPointerTy(), |
| 3174 | DAG.getNode(X86ISD::GlobalBaseReg, getPointerTy()), |
| 3175 | Result); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3176 | } |
| 3177 | |
| 3178 | return Result; |
| 3179 | } |
| 3180 | |
| 3181 | SDOperand |
| 3182 | X86TargetLowering::LowerGlobalAddress(SDOperand Op, SelectionDAG &DAG) { |
| 3183 | GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); |
Evan Cheng | d0ff02c | 2006-11-29 23:19:46 +0000 | [diff] [blame] | 3184 | SDOperand Result = DAG.getTargetGlobalAddress(GV, getPointerTy()); |
Evan Cheng | 19f2ffc | 2006-12-05 04:01:03 +0000 | [diff] [blame] | 3185 | Result = DAG.getNode(X86ISD::Wrapper, getPointerTy(), Result); |
Anton Korobeynikov | 7f70559 | 2007-01-12 19:20:47 +0000 | [diff] [blame] | 3186 | // With PIC, the address is actually $g + Offset. |
| 3187 | if (getTargetMachine().getRelocationModel() == Reloc::PIC_ && |
| 3188 | !Subtarget->isPICStyleRIPRel()) { |
| 3189 | Result = DAG.getNode(ISD::ADD, getPointerTy(), |
| 3190 | DAG.getNode(X86ISD::GlobalBaseReg, getPointerTy()), |
| 3191 | Result); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3192 | } |
Anton Korobeynikov | 2b2bc68 | 2006-12-22 22:29:05 +0000 | [diff] [blame] | 3193 | |
| 3194 | // For Darwin & Mingw32, external and weak symbols are indirect, so we want to |
| 3195 | // load the value at address GV, not the value of GV itself. This means that |
| 3196 | // the GlobalAddress must be in the base or index register of the address, not |
| 3197 | // the GV offset field. Platform check is inside GVRequiresExtraLoad() call |
Anton Korobeynikov | 7f70559 | 2007-01-12 19:20:47 +0000 | [diff] [blame] | 3198 | // The same applies for external symbols during PIC codegen |
Anton Korobeynikov | 2b2bc68 | 2006-12-22 22:29:05 +0000 | [diff] [blame] | 3199 | if (Subtarget->GVRequiresExtraLoad(GV, getTargetMachine(), false)) |
| 3200 | Result = DAG.getLoad(getPointerTy(), DAG.getEntryNode(), Result, NULL, 0); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3201 | |
| 3202 | return Result; |
| 3203 | } |
| 3204 | |
Lauro Ramos Venancio | b3a0417 | 2007-04-20 21:38:10 +0000 | [diff] [blame] | 3205 | // Lower ISD::GlobalTLSAddress using the "general dynamic" model |
| 3206 | static SDOperand |
| 3207 | LowerToTLSGeneralDynamicModel(GlobalAddressSDNode *GA, SelectionDAG &DAG, |
| 3208 | const MVT::ValueType PtrVT) { |
| 3209 | SDOperand InFlag; |
| 3210 | SDOperand Chain = DAG.getCopyToReg(DAG.getEntryNode(), X86::EBX, |
| 3211 | DAG.getNode(X86ISD::GlobalBaseReg, |
| 3212 | PtrVT), InFlag); |
| 3213 | InFlag = Chain.getValue(1); |
| 3214 | |
| 3215 | // emit leal symbol@TLSGD(,%ebx,1), %eax |
| 3216 | SDVTList NodeTys = DAG.getVTList(PtrVT, MVT::Other, MVT::Flag); |
| 3217 | SDOperand TGA = DAG.getTargetGlobalAddress(GA->getGlobal(), |
| 3218 | GA->getValueType(0), |
| 3219 | GA->getOffset()); |
| 3220 | SDOperand Ops[] = { Chain, TGA, InFlag }; |
| 3221 | SDOperand Result = DAG.getNode(X86ISD::TLSADDR, NodeTys, Ops, 3); |
| 3222 | InFlag = Result.getValue(2); |
| 3223 | Chain = Result.getValue(1); |
| 3224 | |
| 3225 | // call ___tls_get_addr. This function receives its argument in |
| 3226 | // the register EAX. |
| 3227 | Chain = DAG.getCopyToReg(Chain, X86::EAX, Result, InFlag); |
| 3228 | InFlag = Chain.getValue(1); |
| 3229 | |
| 3230 | NodeTys = DAG.getVTList(MVT::Other, MVT::Flag); |
| 3231 | SDOperand Ops1[] = { Chain, |
| 3232 | DAG.getTargetExternalSymbol("___tls_get_addr", |
| 3233 | PtrVT), |
| 3234 | DAG.getRegister(X86::EAX, PtrVT), |
| 3235 | DAG.getRegister(X86::EBX, PtrVT), |
| 3236 | InFlag }; |
| 3237 | Chain = DAG.getNode(X86ISD::CALL, NodeTys, Ops1, 5); |
| 3238 | InFlag = Chain.getValue(1); |
| 3239 | |
| 3240 | return DAG.getCopyFromReg(Chain, X86::EAX, PtrVT, InFlag); |
| 3241 | } |
| 3242 | |
| 3243 | // Lower ISD::GlobalTLSAddress using the "initial exec" (for no-pic) or |
| 3244 | // "local exec" model. |
| 3245 | static SDOperand |
| 3246 | LowerToTLSExecModel(GlobalAddressSDNode *GA, SelectionDAG &DAG, |
| 3247 | const MVT::ValueType PtrVT) { |
| 3248 | // Get the Thread Pointer |
| 3249 | SDOperand ThreadPointer = DAG.getNode(X86ISD::THREAD_POINTER, PtrVT); |
| 3250 | // emit "addl x@ntpoff,%eax" (local exec) or "addl x@indntpoff,%eax" (initial |
| 3251 | // exec) |
| 3252 | SDOperand TGA = DAG.getTargetGlobalAddress(GA->getGlobal(), |
| 3253 | GA->getValueType(0), |
| 3254 | GA->getOffset()); |
| 3255 | SDOperand Offset = DAG.getNode(X86ISD::Wrapper, PtrVT, TGA); |
Lauro Ramos Venancio | 7d2cc2b | 2007-04-22 22:50:52 +0000 | [diff] [blame] | 3256 | |
| 3257 | if (GA->getGlobal()->isDeclaration()) // initial exec TLS model |
| 3258 | Offset = DAG.getLoad(PtrVT, DAG.getEntryNode(), Offset, NULL, 0); |
| 3259 | |
Lauro Ramos Venancio | b3a0417 | 2007-04-20 21:38:10 +0000 | [diff] [blame] | 3260 | // The address of the thread local variable is the add of the thread |
| 3261 | // pointer with the offset of the variable. |
| 3262 | return DAG.getNode(ISD::ADD, PtrVT, ThreadPointer, Offset); |
| 3263 | } |
| 3264 | |
| 3265 | SDOperand |
| 3266 | X86TargetLowering::LowerGlobalTLSAddress(SDOperand Op, SelectionDAG &DAG) { |
| 3267 | // TODO: implement the "local dynamic" model |
Lauro Ramos Venancio | 2c5c111 | 2007-04-21 20:56:26 +0000 | [diff] [blame] | 3268 | // TODO: implement the "initial exec"model for pic executables |
| 3269 | assert(!Subtarget->is64Bit() && Subtarget->isTargetELF() && |
| 3270 | "TLS not implemented for non-ELF and 64-bit targets"); |
Lauro Ramos Venancio | b3a0417 | 2007-04-20 21:38:10 +0000 | [diff] [blame] | 3271 | GlobalAddressSDNode *GA = cast<GlobalAddressSDNode>(Op); |
| 3272 | // If the relocation model is PIC, use the "General Dynamic" TLS Model, |
| 3273 | // otherwise use the "Local Exec"TLS Model |
| 3274 | if (getTargetMachine().getRelocationModel() == Reloc::PIC_) |
| 3275 | return LowerToTLSGeneralDynamicModel(GA, DAG, getPointerTy()); |
| 3276 | else |
| 3277 | return LowerToTLSExecModel(GA, DAG, getPointerTy()); |
| 3278 | } |
| 3279 | |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3280 | SDOperand |
| 3281 | X86TargetLowering::LowerExternalSymbol(SDOperand Op, SelectionDAG &DAG) { |
| 3282 | const char *Sym = cast<ExternalSymbolSDNode>(Op)->getSymbol(); |
Evan Cheng | d0ff02c | 2006-11-29 23:19:46 +0000 | [diff] [blame] | 3283 | SDOperand Result = DAG.getTargetExternalSymbol(Sym, getPointerTy()); |
Evan Cheng | 19f2ffc | 2006-12-05 04:01:03 +0000 | [diff] [blame] | 3284 | Result = DAG.getNode(X86ISD::Wrapper, getPointerTy(), Result); |
Anton Korobeynikov | 7f70559 | 2007-01-12 19:20:47 +0000 | [diff] [blame] | 3285 | // With PIC, the address is actually $g + Offset. |
| 3286 | if (getTargetMachine().getRelocationModel() == Reloc::PIC_ && |
| 3287 | !Subtarget->isPICStyleRIPRel()) { |
| 3288 | Result = DAG.getNode(ISD::ADD, getPointerTy(), |
| 3289 | DAG.getNode(X86ISD::GlobalBaseReg, getPointerTy()), |
| 3290 | Result); |
| 3291 | } |
| 3292 | |
| 3293 | return Result; |
| 3294 | } |
| 3295 | |
| 3296 | SDOperand X86TargetLowering::LowerJumpTable(SDOperand Op, SelectionDAG &DAG) { |
| 3297 | JumpTableSDNode *JT = cast<JumpTableSDNode>(Op); |
| 3298 | SDOperand Result = DAG.getTargetJumpTable(JT->getIndex(), getPointerTy()); |
| 3299 | Result = DAG.getNode(X86ISD::Wrapper, getPointerTy(), Result); |
| 3300 | // With PIC, the address is actually $g + Offset. |
| 3301 | if (getTargetMachine().getRelocationModel() == Reloc::PIC_ && |
| 3302 | !Subtarget->isPICStyleRIPRel()) { |
| 3303 | Result = DAG.getNode(ISD::ADD, getPointerTy(), |
| 3304 | DAG.getNode(X86ISD::GlobalBaseReg, getPointerTy()), |
| 3305 | Result); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3306 | } |
| 3307 | |
| 3308 | return Result; |
| 3309 | } |
| 3310 | |
| 3311 | SDOperand X86TargetLowering::LowerShift(SDOperand Op, SelectionDAG &DAG) { |
Evan Cheng | e341316 | 2006-01-09 18:33:28 +0000 | [diff] [blame] | 3312 | assert(Op.getNumOperands() == 3 && Op.getValueType() == MVT::i32 && |
| 3313 | "Not an i64 shift!"); |
| 3314 | bool isSRA = Op.getOpcode() == ISD::SRA_PARTS; |
| 3315 | SDOperand ShOpLo = Op.getOperand(0); |
| 3316 | SDOperand ShOpHi = Op.getOperand(1); |
| 3317 | SDOperand ShAmt = Op.getOperand(2); |
Evan Cheng | 734503b | 2006-09-11 02:19:56 +0000 | [diff] [blame] | 3318 | SDOperand Tmp1 = isSRA ? |
| 3319 | DAG.getNode(ISD::SRA, MVT::i32, ShOpHi, DAG.getConstant(31, MVT::i8)) : |
| 3320 | DAG.getConstant(0, MVT::i32); |
Evan Cheng | e341316 | 2006-01-09 18:33:28 +0000 | [diff] [blame] | 3321 | |
| 3322 | SDOperand Tmp2, Tmp3; |
| 3323 | if (Op.getOpcode() == ISD::SHL_PARTS) { |
| 3324 | Tmp2 = DAG.getNode(X86ISD::SHLD, MVT::i32, ShOpHi, ShOpLo, ShAmt); |
| 3325 | Tmp3 = DAG.getNode(ISD::SHL, MVT::i32, ShOpLo, ShAmt); |
| 3326 | } else { |
| 3327 | Tmp2 = DAG.getNode(X86ISD::SHRD, MVT::i32, ShOpLo, ShOpHi, ShAmt); |
Evan Cheng | b7b5706 | 2006-01-19 01:46:14 +0000 | [diff] [blame] | 3328 | Tmp3 = DAG.getNode(isSRA ? ISD::SRA : ISD::SRL, MVT::i32, ShOpHi, ShAmt); |
Evan Cheng | e341316 | 2006-01-09 18:33:28 +0000 | [diff] [blame] | 3329 | } |
| 3330 | |
Evan Cheng | 734503b | 2006-09-11 02:19:56 +0000 | [diff] [blame] | 3331 | const MVT::ValueType *VTs = DAG.getNodeValueTypes(MVT::Other, MVT::Flag); |
| 3332 | SDOperand AndNode = DAG.getNode(ISD::AND, MVT::i8, ShAmt, |
| 3333 | DAG.getConstant(32, MVT::i8)); |
| 3334 | SDOperand COps[]={DAG.getEntryNode(), AndNode, DAG.getConstant(0, MVT::i8)}; |
Evan Cheng | 0488db9 | 2007-09-25 01:57:46 +0000 | [diff] [blame] | 3335 | SDOperand Cond = NewCCModeling |
| 3336 | ? DAG.getNode(X86ISD::CMP_NEW, MVT::i32, |
| 3337 | AndNode, DAG.getConstant(0, MVT::i8)) |
| 3338 | : DAG.getNode(X86ISD::CMP, VTs, 2, COps, 3).getValue(1); |
Evan Cheng | e341316 | 2006-01-09 18:33:28 +0000 | [diff] [blame] | 3339 | |
| 3340 | SDOperand Hi, Lo; |
Chris Lattner | 7fbe972 | 2006-10-20 17:42:20 +0000 | [diff] [blame] | 3341 | SDOperand CC = DAG.getConstant(X86::COND_NE, MVT::i8); |
Evan Cheng | 0488db9 | 2007-09-25 01:57:46 +0000 | [diff] [blame] | 3342 | unsigned Opc = NewCCModeling ? X86ISD::CMOV_NEW : X86ISD::CMOV; |
Evan Cheng | 734503b | 2006-09-11 02:19:56 +0000 | [diff] [blame] | 3343 | VTs = DAG.getNodeValueTypes(MVT::i32, MVT::Flag); |
| 3344 | SmallVector<SDOperand, 4> Ops; |
Evan Cheng | e341316 | 2006-01-09 18:33:28 +0000 | [diff] [blame] | 3345 | if (Op.getOpcode() == ISD::SHL_PARTS) { |
| 3346 | Ops.push_back(Tmp2); |
| 3347 | Ops.push_back(Tmp3); |
| 3348 | Ops.push_back(CC); |
Evan Cheng | 0488db9 | 2007-09-25 01:57:46 +0000 | [diff] [blame] | 3349 | Ops.push_back(Cond); |
| 3350 | if (NewCCModeling) |
| 3351 | Hi = DAG.getNode(Opc, MVT::i32, &Ops[0], Ops.size()); |
| 3352 | else { |
| 3353 | Hi = DAG.getNode(Opc, VTs, 2, &Ops[0], Ops.size()); |
| 3354 | Cond = Hi.getValue(1); |
| 3355 | } |
Evan Cheng | e341316 | 2006-01-09 18:33:28 +0000 | [diff] [blame] | 3356 | |
| 3357 | Ops.clear(); |
| 3358 | Ops.push_back(Tmp3); |
| 3359 | Ops.push_back(Tmp1); |
| 3360 | Ops.push_back(CC); |
Evan Cheng | 0488db9 | 2007-09-25 01:57:46 +0000 | [diff] [blame] | 3361 | Ops.push_back(Cond); |
| 3362 | if (NewCCModeling) |
| 3363 | Lo = DAG.getNode(Opc, MVT::i32, &Ops[0], Ops.size()); |
| 3364 | else |
| 3365 | Lo = DAG.getNode(Opc, VTs, 2, &Ops[0], Ops.size()); |
Evan Cheng | e341316 | 2006-01-09 18:33:28 +0000 | [diff] [blame] | 3366 | } else { |
| 3367 | Ops.push_back(Tmp2); |
| 3368 | Ops.push_back(Tmp3); |
| 3369 | Ops.push_back(CC); |
Evan Cheng | 0488db9 | 2007-09-25 01:57:46 +0000 | [diff] [blame] | 3370 | Ops.push_back(Cond); |
| 3371 | if (NewCCModeling) |
| 3372 | Lo = DAG.getNode(Opc, MVT::i32, &Ops[0], Ops.size()); |
| 3373 | else { |
| 3374 | Lo = DAG.getNode(Opc, VTs, 2, &Ops[0], Ops.size()); |
| 3375 | Cond = Lo.getValue(1); |
| 3376 | } |
Evan Cheng | e341316 | 2006-01-09 18:33:28 +0000 | [diff] [blame] | 3377 | |
| 3378 | Ops.clear(); |
| 3379 | Ops.push_back(Tmp3); |
| 3380 | Ops.push_back(Tmp1); |
| 3381 | Ops.push_back(CC); |
Evan Cheng | 0488db9 | 2007-09-25 01:57:46 +0000 | [diff] [blame] | 3382 | Ops.push_back(Cond); |
| 3383 | if (NewCCModeling) |
| 3384 | Hi = DAG.getNode(Opc, MVT::i32, &Ops[0], Ops.size()); |
| 3385 | else |
| 3386 | Hi = DAG.getNode(Opc, VTs, 2, &Ops[0], Ops.size()); |
Evan Cheng | e341316 | 2006-01-09 18:33:28 +0000 | [diff] [blame] | 3387 | } |
| 3388 | |
Evan Cheng | 734503b | 2006-09-11 02:19:56 +0000 | [diff] [blame] | 3389 | VTs = DAG.getNodeValueTypes(MVT::i32, MVT::i32); |
Evan Cheng | e341316 | 2006-01-09 18:33:28 +0000 | [diff] [blame] | 3390 | Ops.clear(); |
| 3391 | Ops.push_back(Lo); |
| 3392 | Ops.push_back(Hi); |
Evan Cheng | 734503b | 2006-09-11 02:19:56 +0000 | [diff] [blame] | 3393 | return DAG.getNode(ISD::MERGE_VALUES, VTs, 2, &Ops[0], Ops.size()); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3394 | } |
Evan Cheng | a3195e8 | 2006-01-12 22:54:21 +0000 | [diff] [blame] | 3395 | |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3396 | SDOperand X86TargetLowering::LowerSINT_TO_FP(SDOperand Op, SelectionDAG &DAG) { |
| 3397 | assert(Op.getOperand(0).getValueType() <= MVT::i64 && |
| 3398 | Op.getOperand(0).getValueType() >= MVT::i16 && |
| 3399 | "Unknown SINT_TO_FP to lower!"); |
| 3400 | |
| 3401 | SDOperand Result; |
| 3402 | MVT::ValueType SrcVT = Op.getOperand(0).getValueType(); |
| 3403 | unsigned Size = MVT::getSizeInBits(SrcVT)/8; |
| 3404 | MachineFunction &MF = DAG.getMachineFunction(); |
| 3405 | int SSFI = MF.getFrameInfo()->CreateStackObject(Size, Size); |
| 3406 | SDOperand StackSlot = DAG.getFrameIndex(SSFI, getPointerTy()); |
Evan Cheng | 786225a | 2006-10-05 23:01:46 +0000 | [diff] [blame] | 3407 | SDOperand Chain = DAG.getStore(DAG.getEntryNode(), Op.getOperand(0), |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 3408 | StackSlot, NULL, 0); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3409 | |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 3410 | // These are really Legal; caller falls through into that case. |
Dale Johannesen | f1fc3a8 | 2007-09-23 14:52:20 +0000 | [diff] [blame] | 3411 | if (SrcVT==MVT::i32 && Op.getValueType() == MVT::f32 && X86ScalarSSEf32) |
| 3412 | return Result; |
| 3413 | if (SrcVT==MVT::i32 && Op.getValueType() == MVT::f64 && X86ScalarSSEf64) |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 3414 | return Result; |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 3415 | if (SrcVT==MVT::i64 && Op.getValueType() != MVT::f80 && |
| 3416 | Subtarget->is64Bit()) |
| 3417 | return Result; |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 3418 | |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3419 | // Build the FILD |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 3420 | SDVTList Tys; |
Dale Johannesen | f1fc3a8 | 2007-09-23 14:52:20 +0000 | [diff] [blame] | 3421 | bool useSSE = (X86ScalarSSEf32 && Op.getValueType() == MVT::f32) || |
| 3422 | (X86ScalarSSEf64 && Op.getValueType() == MVT::f64); |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 3423 | if (useSSE) |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 3424 | Tys = DAG.getVTList(MVT::f64, MVT::Other, MVT::Flag); |
| 3425 | else |
Dale Johannesen | 849f214 | 2007-07-03 00:53:03 +0000 | [diff] [blame] | 3426 | Tys = DAG.getVTList(Op.getValueType(), MVT::Other); |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 3427 | SmallVector<SDOperand, 8> Ops; |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3428 | Ops.push_back(Chain); |
| 3429 | Ops.push_back(StackSlot); |
| 3430 | Ops.push_back(DAG.getValueType(SrcVT)); |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 3431 | Result = DAG.getNode(useSSE ? X86ISD::FILD_FLAG :X86ISD::FILD, |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 3432 | Tys, &Ops[0], Ops.size()); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3433 | |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 3434 | if (useSSE) { |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3435 | Chain = Result.getValue(1); |
| 3436 | SDOperand InFlag = Result.getValue(2); |
| 3437 | |
| 3438 | // FIXME: Currently the FST is flagged to the FILD_FLAG. This |
| 3439 | // shouldn't be necessary except that RFP cannot be live across |
| 3440 | // multiple blocks. When stackifier is fixed, they can be uncoupled. |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 3441 | MachineFunction &MF = DAG.getMachineFunction(); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3442 | int SSFI = MF.getFrameInfo()->CreateStackObject(8, 8); |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 3443 | SDOperand StackSlot = DAG.getFrameIndex(SSFI, getPointerTy()); |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 3444 | Tys = DAG.getVTList(MVT::Other); |
| 3445 | SmallVector<SDOperand, 8> Ops; |
Evan Cheng | a3195e8 | 2006-01-12 22:54:21 +0000 | [diff] [blame] | 3446 | Ops.push_back(Chain); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3447 | Ops.push_back(Result); |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 3448 | Ops.push_back(StackSlot); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3449 | Ops.push_back(DAG.getValueType(Op.getValueType())); |
| 3450 | Ops.push_back(InFlag); |
Chris Lattner | bd564bf | 2006-08-08 02:23:42 +0000 | [diff] [blame] | 3451 | Chain = DAG.getNode(X86ISD::FST, Tys, &Ops[0], Ops.size()); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 3452 | Result = DAG.getLoad(Op.getValueType(), Chain, StackSlot, NULL, 0); |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 3453 | } |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 3454 | |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3455 | return Result; |
| 3456 | } |
| 3457 | |
| 3458 | SDOperand X86TargetLowering::LowerFP_TO_SINT(SDOperand Op, SelectionDAG &DAG) { |
| 3459 | assert(Op.getValueType() <= MVT::i64 && Op.getValueType() >= MVT::i16 && |
| 3460 | "Unknown FP_TO_SINT to lower!"); |
| 3461 | // We lower FP->sint64 into FISTP64, followed by a load, all to a temporary |
| 3462 | // stack slot. |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 3463 | SDOperand Result; |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3464 | MachineFunction &MF = DAG.getMachineFunction(); |
| 3465 | unsigned MemSize = MVT::getSizeInBits(Op.getValueType())/8; |
| 3466 | int SSFI = MF.getFrameInfo()->CreateStackObject(MemSize, MemSize); |
| 3467 | SDOperand StackSlot = DAG.getFrameIndex(SSFI, getPointerTy()); |
| 3468 | |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 3469 | // These are really Legal. |
Dale Johannesen | f1fc3a8 | 2007-09-23 14:52:20 +0000 | [diff] [blame] | 3470 | if (Op.getValueType() == MVT::i32 && |
| 3471 | X86ScalarSSEf32 && Op.getOperand(0).getValueType() == MVT::f32) |
| 3472 | return Result; |
| 3473 | if (Op.getValueType() == MVT::i32 && |
| 3474 | X86ScalarSSEf64 && Op.getOperand(0).getValueType() == MVT::f64) |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 3475 | return Result; |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 3476 | if (Subtarget->is64Bit() && |
| 3477 | Op.getValueType() == MVT::i64 && |
| 3478 | Op.getOperand(0).getValueType() != MVT::f80) |
| 3479 | return Result; |
Dale Johannesen | 9e3d3ab | 2007-09-14 22:26:36 +0000 | [diff] [blame] | 3480 | |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3481 | unsigned Opc; |
| 3482 | switch (Op.getValueType()) { |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 3483 | default: assert(0 && "Invalid FP_TO_SINT to lower!"); |
| 3484 | case MVT::i16: Opc = X86ISD::FP_TO_INT16_IN_MEM; break; |
| 3485 | case MVT::i32: Opc = X86ISD::FP_TO_INT32_IN_MEM; break; |
| 3486 | case MVT::i64: Opc = X86ISD::FP_TO_INT64_IN_MEM; break; |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3487 | } |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 3488 | |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3489 | SDOperand Chain = DAG.getEntryNode(); |
| 3490 | SDOperand Value = Op.getOperand(0); |
Dale Johannesen | f1fc3a8 | 2007-09-23 14:52:20 +0000 | [diff] [blame] | 3491 | if ((X86ScalarSSEf32 && Op.getOperand(0).getValueType() == MVT::f32) || |
| 3492 | (X86ScalarSSEf64 && Op.getOperand(0).getValueType() == MVT::f64)) { |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3493 | assert(Op.getValueType() == MVT::i64 && "Invalid FP_TO_SINT to lower!"); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 3494 | Chain = DAG.getStore(Chain, Value, StackSlot, NULL, 0); |
Dale Johannesen | 849f214 | 2007-07-03 00:53:03 +0000 | [diff] [blame] | 3495 | SDVTList Tys = DAG.getVTList(Op.getOperand(0).getValueType(), MVT::Other); |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 3496 | SDOperand Ops[] = { |
| 3497 | Chain, StackSlot, DAG.getValueType(Op.getOperand(0).getValueType()) |
| 3498 | }; |
| 3499 | Value = DAG.getNode(X86ISD::FLD, Tys, Ops, 3); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3500 | Chain = Value.getValue(1); |
| 3501 | SSFI = MF.getFrameInfo()->CreateStackObject(MemSize, MemSize); |
| 3502 | StackSlot = DAG.getFrameIndex(SSFI, getPointerTy()); |
| 3503 | } |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 3504 | |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3505 | // Build the FP_TO_INT*_IN_MEM |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 3506 | SDOperand Ops[] = { Chain, Value, StackSlot }; |
| 3507 | SDOperand FIST = DAG.getNode(Opc, MVT::Other, Ops, 3); |
Evan Cheng | d9558e0 | 2006-01-06 00:43:03 +0000 | [diff] [blame] | 3508 | |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3509 | // Load the result. |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 3510 | return DAG.getLoad(Op.getValueType(), FIST, StackSlot, NULL, 0); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3511 | } |
| 3512 | |
| 3513 | SDOperand X86TargetLowering::LowerFABS(SDOperand Op, SelectionDAG &DAG) { |
| 3514 | MVT::ValueType VT = Op.getValueType(); |
Dan Gohman | 2038252 | 2007-07-10 00:05:58 +0000 | [diff] [blame] | 3515 | MVT::ValueType EltVT = VT; |
| 3516 | if (MVT::isVector(VT)) |
| 3517 | EltVT = MVT::getVectorElementType(VT); |
| 3518 | const Type *OpNTy = MVT::getTypeForValueType(EltVT); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3519 | std::vector<Constant*> CV; |
Dan Gohman | 2038252 | 2007-07-10 00:05:58 +0000 | [diff] [blame] | 3520 | if (EltVT == MVT::f64) { |
Dale Johannesen | 3f6eb74 | 2007-09-11 18:32:33 +0000 | [diff] [blame] | 3521 | Constant *C = ConstantFP::get(OpNTy, APFloat(APInt(64, ~(1ULL << 63)))); |
Dan Gohman | 2038252 | 2007-07-10 00:05:58 +0000 | [diff] [blame] | 3522 | CV.push_back(C); |
| 3523 | CV.push_back(C); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3524 | } else { |
Dale Johannesen | 3f6eb74 | 2007-09-11 18:32:33 +0000 | [diff] [blame] | 3525 | Constant *C = ConstantFP::get(OpNTy, APFloat(APInt(32, ~(1U << 31)))); |
Dan Gohman | 2038252 | 2007-07-10 00:05:58 +0000 | [diff] [blame] | 3526 | CV.push_back(C); |
| 3527 | CV.push_back(C); |
| 3528 | CV.push_back(C); |
| 3529 | CV.push_back(C); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3530 | } |
Dan Gohman | d300622 | 2007-07-27 17:16:43 +0000 | [diff] [blame] | 3531 | Constant *C = ConstantVector::get(CV); |
| 3532 | SDOperand CPIdx = DAG.getConstantPool(C, getPointerTy(), 4); |
| 3533 | SDOperand Mask = DAG.getLoad(VT, DAG.getEntryNode(), CPIdx, NULL, 0, |
| 3534 | false, 16); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3535 | return DAG.getNode(X86ISD::FAND, VT, Op.getOperand(0), Mask); |
| 3536 | } |
| 3537 | |
| 3538 | SDOperand X86TargetLowering::LowerFNEG(SDOperand Op, SelectionDAG &DAG) { |
| 3539 | MVT::ValueType VT = Op.getValueType(); |
Dan Gohman | 2038252 | 2007-07-10 00:05:58 +0000 | [diff] [blame] | 3540 | MVT::ValueType EltVT = VT; |
Evan Cheng | d4d01b7 | 2007-07-19 23:36:01 +0000 | [diff] [blame] | 3541 | unsigned EltNum = 1; |
| 3542 | if (MVT::isVector(VT)) { |
Dan Gohman | 2038252 | 2007-07-10 00:05:58 +0000 | [diff] [blame] | 3543 | EltVT = MVT::getVectorElementType(VT); |
Evan Cheng | d4d01b7 | 2007-07-19 23:36:01 +0000 | [diff] [blame] | 3544 | EltNum = MVT::getVectorNumElements(VT); |
| 3545 | } |
Dan Gohman | 2038252 | 2007-07-10 00:05:58 +0000 | [diff] [blame] | 3546 | const Type *OpNTy = MVT::getTypeForValueType(EltVT); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3547 | std::vector<Constant*> CV; |
Dan Gohman | 2038252 | 2007-07-10 00:05:58 +0000 | [diff] [blame] | 3548 | if (EltVT == MVT::f64) { |
Dale Johannesen | 3f6eb74 | 2007-09-11 18:32:33 +0000 | [diff] [blame] | 3549 | Constant *C = ConstantFP::get(OpNTy, APFloat(APInt(64, 1ULL << 63))); |
Dan Gohman | 2038252 | 2007-07-10 00:05:58 +0000 | [diff] [blame] | 3550 | CV.push_back(C); |
| 3551 | CV.push_back(C); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3552 | } else { |
Dale Johannesen | 3f6eb74 | 2007-09-11 18:32:33 +0000 | [diff] [blame] | 3553 | Constant *C = ConstantFP::get(OpNTy, APFloat(APInt(32, 1U << 31))); |
Dan Gohman | 2038252 | 2007-07-10 00:05:58 +0000 | [diff] [blame] | 3554 | CV.push_back(C); |
| 3555 | CV.push_back(C); |
| 3556 | CV.push_back(C); |
| 3557 | CV.push_back(C); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3558 | } |
Dan Gohman | d300622 | 2007-07-27 17:16:43 +0000 | [diff] [blame] | 3559 | Constant *C = ConstantVector::get(CV); |
| 3560 | SDOperand CPIdx = DAG.getConstantPool(C, getPointerTy(), 4); |
| 3561 | SDOperand Mask = DAG.getLoad(VT, DAG.getEntryNode(), CPIdx, NULL, 0, |
| 3562 | false, 16); |
Evan Cheng | d4d01b7 | 2007-07-19 23:36:01 +0000 | [diff] [blame] | 3563 | if (MVT::isVector(VT)) { |
Evan Cheng | d4d01b7 | 2007-07-19 23:36:01 +0000 | [diff] [blame] | 3564 | return DAG.getNode(ISD::BIT_CONVERT, VT, |
| 3565 | DAG.getNode(ISD::XOR, MVT::v2i64, |
| 3566 | DAG.getNode(ISD::BIT_CONVERT, MVT::v2i64, Op.getOperand(0)), |
| 3567 | DAG.getNode(ISD::BIT_CONVERT, MVT::v2i64, Mask))); |
| 3568 | } else { |
Evan Cheng | d4d01b7 | 2007-07-19 23:36:01 +0000 | [diff] [blame] | 3569 | return DAG.getNode(X86ISD::FXOR, VT, Op.getOperand(0), Mask); |
| 3570 | } |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3571 | } |
| 3572 | |
Evan Cheng | 68c47cb | 2007-01-05 07:55:56 +0000 | [diff] [blame] | 3573 | SDOperand X86TargetLowering::LowerFCOPYSIGN(SDOperand Op, SelectionDAG &DAG) { |
Evan Cheng | 73d6cf1 | 2007-01-05 21:37:56 +0000 | [diff] [blame] | 3574 | SDOperand Op0 = Op.getOperand(0); |
| 3575 | SDOperand Op1 = Op.getOperand(1); |
Evan Cheng | 68c47cb | 2007-01-05 07:55:56 +0000 | [diff] [blame] | 3576 | MVT::ValueType VT = Op.getValueType(); |
Evan Cheng | 73d6cf1 | 2007-01-05 21:37:56 +0000 | [diff] [blame] | 3577 | MVT::ValueType SrcVT = Op1.getValueType(); |
Evan Cheng | 68c47cb | 2007-01-05 07:55:56 +0000 | [diff] [blame] | 3578 | const Type *SrcTy = MVT::getTypeForValueType(SrcVT); |
Evan Cheng | 73d6cf1 | 2007-01-05 21:37:56 +0000 | [diff] [blame] | 3579 | |
| 3580 | // If second operand is smaller, extend it first. |
| 3581 | if (MVT::getSizeInBits(SrcVT) < MVT::getSizeInBits(VT)) { |
| 3582 | Op1 = DAG.getNode(ISD::FP_EXTEND, VT, Op1); |
| 3583 | SrcVT = VT; |
Dale Johannesen | 43421b3 | 2007-09-06 18:13:44 +0000 | [diff] [blame] | 3584 | SrcTy = MVT::getTypeForValueType(SrcVT); |
Evan Cheng | 73d6cf1 | 2007-01-05 21:37:56 +0000 | [diff] [blame] | 3585 | } |
| 3586 | |
Evan Cheng | 68c47cb | 2007-01-05 07:55:56 +0000 | [diff] [blame] | 3587 | // First get the sign bit of second operand. |
| 3588 | std::vector<Constant*> CV; |
| 3589 | if (SrcVT == MVT::f64) { |
Dale Johannesen | 3f6eb74 | 2007-09-11 18:32:33 +0000 | [diff] [blame] | 3590 | CV.push_back(ConstantFP::get(SrcTy, APFloat(APInt(64, 1ULL << 63)))); |
| 3591 | CV.push_back(ConstantFP::get(SrcTy, APFloat(APInt(64, 0)))); |
Evan Cheng | 68c47cb | 2007-01-05 07:55:56 +0000 | [diff] [blame] | 3592 | } else { |
Dale Johannesen | 3f6eb74 | 2007-09-11 18:32:33 +0000 | [diff] [blame] | 3593 | CV.push_back(ConstantFP::get(SrcTy, APFloat(APInt(32, 1U << 31)))); |
| 3594 | CV.push_back(ConstantFP::get(SrcTy, APFloat(APInt(32, 0)))); |
| 3595 | CV.push_back(ConstantFP::get(SrcTy, APFloat(APInt(32, 0)))); |
| 3596 | CV.push_back(ConstantFP::get(SrcTy, APFloat(APInt(32, 0)))); |
Evan Cheng | 68c47cb | 2007-01-05 07:55:56 +0000 | [diff] [blame] | 3597 | } |
Dan Gohman | d300622 | 2007-07-27 17:16:43 +0000 | [diff] [blame] | 3598 | Constant *C = ConstantVector::get(CV); |
| 3599 | SDOperand CPIdx = DAG.getConstantPool(C, getPointerTy(), 4); |
| 3600 | SDOperand Mask1 = DAG.getLoad(SrcVT, DAG.getEntryNode(), CPIdx, NULL, 0, |
| 3601 | false, 16); |
Evan Cheng | 73d6cf1 | 2007-01-05 21:37:56 +0000 | [diff] [blame] | 3602 | SDOperand SignBit = DAG.getNode(X86ISD::FAND, SrcVT, Op1, Mask1); |
Evan Cheng | 68c47cb | 2007-01-05 07:55:56 +0000 | [diff] [blame] | 3603 | |
| 3604 | // Shift sign bit right or left if the two operands have different types. |
| 3605 | if (MVT::getSizeInBits(SrcVT) > MVT::getSizeInBits(VT)) { |
| 3606 | // Op0 is MVT::f32, Op1 is MVT::f64. |
| 3607 | SignBit = DAG.getNode(ISD::SCALAR_TO_VECTOR, MVT::v2f64, SignBit); |
| 3608 | SignBit = DAG.getNode(X86ISD::FSRL, MVT::v2f64, SignBit, |
| 3609 | DAG.getConstant(32, MVT::i32)); |
| 3610 | SignBit = DAG.getNode(ISD::BIT_CONVERT, MVT::v4f32, SignBit); |
| 3611 | SignBit = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, MVT::f32, SignBit, |
| 3612 | DAG.getConstant(0, getPointerTy())); |
Evan Cheng | 68c47cb | 2007-01-05 07:55:56 +0000 | [diff] [blame] | 3613 | } |
| 3614 | |
Evan Cheng | 73d6cf1 | 2007-01-05 21:37:56 +0000 | [diff] [blame] | 3615 | // Clear first operand sign bit. |
| 3616 | CV.clear(); |
| 3617 | if (VT == MVT::f64) { |
Dale Johannesen | 3f6eb74 | 2007-09-11 18:32:33 +0000 | [diff] [blame] | 3618 | CV.push_back(ConstantFP::get(SrcTy, APFloat(APInt(64, ~(1ULL << 63))))); |
| 3619 | CV.push_back(ConstantFP::get(SrcTy, APFloat(APInt(64, 0)))); |
Evan Cheng | 73d6cf1 | 2007-01-05 21:37:56 +0000 | [diff] [blame] | 3620 | } else { |
Dale Johannesen | 3f6eb74 | 2007-09-11 18:32:33 +0000 | [diff] [blame] | 3621 | CV.push_back(ConstantFP::get(SrcTy, APFloat(APInt(32, ~(1U << 31))))); |
| 3622 | CV.push_back(ConstantFP::get(SrcTy, APFloat(APInt(32, 0)))); |
| 3623 | CV.push_back(ConstantFP::get(SrcTy, APFloat(APInt(32, 0)))); |
| 3624 | CV.push_back(ConstantFP::get(SrcTy, APFloat(APInt(32, 0)))); |
Evan Cheng | 73d6cf1 | 2007-01-05 21:37:56 +0000 | [diff] [blame] | 3625 | } |
Dan Gohman | d300622 | 2007-07-27 17:16:43 +0000 | [diff] [blame] | 3626 | C = ConstantVector::get(CV); |
| 3627 | CPIdx = DAG.getConstantPool(C, getPointerTy(), 4); |
| 3628 | SDOperand Mask2 = DAG.getLoad(VT, DAG.getEntryNode(), CPIdx, NULL, 0, |
| 3629 | false, 16); |
Evan Cheng | 73d6cf1 | 2007-01-05 21:37:56 +0000 | [diff] [blame] | 3630 | SDOperand Val = DAG.getNode(X86ISD::FAND, VT, Op0, Mask2); |
| 3631 | |
| 3632 | // Or the value with the sign bit. |
| 3633 | return DAG.getNode(X86ISD::FOR, VT, Val, SignBit); |
Evan Cheng | 68c47cb | 2007-01-05 07:55:56 +0000 | [diff] [blame] | 3634 | } |
| 3635 | |
Evan Cheng | 734503b | 2006-09-11 02:19:56 +0000 | [diff] [blame] | 3636 | SDOperand X86TargetLowering::LowerSETCC(SDOperand Op, SelectionDAG &DAG, |
| 3637 | SDOperand Chain) { |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3638 | assert(Op.getValueType() == MVT::i8 && "SetCC type must be 8-bit integer"); |
| 3639 | SDOperand Cond; |
Evan Cheng | 734503b | 2006-09-11 02:19:56 +0000 | [diff] [blame] | 3640 | SDOperand Op0 = Op.getOperand(0); |
| 3641 | SDOperand Op1 = Op.getOperand(1); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3642 | SDOperand CC = Op.getOperand(2); |
| 3643 | ISD::CondCode SetCCOpcode = cast<CondCodeSDNode>(CC)->get(); |
Evan Cheng | cf12ec4 | 2006-10-12 19:12:56 +0000 | [diff] [blame] | 3644 | const MVT::ValueType *VTs1 = DAG.getNodeValueTypes(MVT::Other, MVT::Flag); |
| 3645 | const MVT::ValueType *VTs2 = DAG.getNodeValueTypes(MVT::i8, MVT::Flag); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3646 | bool isFP = MVT::isFloatingPoint(Op.getOperand(1).getValueType()); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3647 | unsigned X86CC; |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3648 | |
Anton Korobeynikov | 12c49af | 2006-11-21 00:01:06 +0000 | [diff] [blame] | 3649 | if (translateX86CC(cast<CondCodeSDNode>(CC)->get(), isFP, X86CC, |
Chris Lattner | f957051 | 2006-09-13 03:22:10 +0000 | [diff] [blame] | 3650 | Op0, Op1, DAG)) { |
Evan Cheng | 734503b | 2006-09-11 02:19:56 +0000 | [diff] [blame] | 3651 | SDOperand Ops1[] = { Chain, Op0, Op1 }; |
Evan Cheng | cf12ec4 | 2006-10-12 19:12:56 +0000 | [diff] [blame] | 3652 | Cond = DAG.getNode(X86ISD::CMP, VTs1, 2, Ops1, 3).getValue(1); |
Evan Cheng | 734503b | 2006-09-11 02:19:56 +0000 | [diff] [blame] | 3653 | SDOperand Ops2[] = { DAG.getConstant(X86CC, MVT::i8), Cond }; |
Evan Cheng | cf12ec4 | 2006-10-12 19:12:56 +0000 | [diff] [blame] | 3654 | return DAG.getNode(X86ISD::SETCC, VTs2, 2, Ops2, 2); |
Evan Cheng | 734503b | 2006-09-11 02:19:56 +0000 | [diff] [blame] | 3655 | } |
| 3656 | |
| 3657 | assert(isFP && "Illegal integer SetCC!"); |
| 3658 | |
| 3659 | SDOperand COps[] = { Chain, Op0, Op1 }; |
Evan Cheng | cf12ec4 | 2006-10-12 19:12:56 +0000 | [diff] [blame] | 3660 | Cond = DAG.getNode(X86ISD::CMP, VTs1, 2, COps, 3).getValue(1); |
Evan Cheng | 734503b | 2006-09-11 02:19:56 +0000 | [diff] [blame] | 3661 | |
| 3662 | switch (SetCCOpcode) { |
| 3663 | default: assert(false && "Illegal floating point SetCC!"); |
| 3664 | case ISD::SETOEQ: { // !PF & ZF |
Chris Lattner | 7fbe972 | 2006-10-20 17:42:20 +0000 | [diff] [blame] | 3665 | SDOperand Ops1[] = { DAG.getConstant(X86::COND_NP, MVT::i8), Cond }; |
Evan Cheng | cf12ec4 | 2006-10-12 19:12:56 +0000 | [diff] [blame] | 3666 | SDOperand Tmp1 = DAG.getNode(X86ISD::SETCC, VTs2, 2, Ops1, 2); |
Chris Lattner | 7fbe972 | 2006-10-20 17:42:20 +0000 | [diff] [blame] | 3667 | SDOperand Ops2[] = { DAG.getConstant(X86::COND_E, MVT::i8), |
Evan Cheng | 734503b | 2006-09-11 02:19:56 +0000 | [diff] [blame] | 3668 | Tmp1.getValue(1) }; |
Evan Cheng | cf12ec4 | 2006-10-12 19:12:56 +0000 | [diff] [blame] | 3669 | SDOperand Tmp2 = DAG.getNode(X86ISD::SETCC, VTs2, 2, Ops2, 2); |
Evan Cheng | 734503b | 2006-09-11 02:19:56 +0000 | [diff] [blame] | 3670 | return DAG.getNode(ISD::AND, MVT::i8, Tmp1, Tmp2); |
| 3671 | } |
| 3672 | case ISD::SETUNE: { // PF | !ZF |
Chris Lattner | 7fbe972 | 2006-10-20 17:42:20 +0000 | [diff] [blame] | 3673 | SDOperand Ops1[] = { DAG.getConstant(X86::COND_P, MVT::i8), Cond }; |
Evan Cheng | cf12ec4 | 2006-10-12 19:12:56 +0000 | [diff] [blame] | 3674 | SDOperand Tmp1 = DAG.getNode(X86ISD::SETCC, VTs2, 2, Ops1, 2); |
Chris Lattner | 7fbe972 | 2006-10-20 17:42:20 +0000 | [diff] [blame] | 3675 | SDOperand Ops2[] = { DAG.getConstant(X86::COND_NE, MVT::i8), |
Evan Cheng | 734503b | 2006-09-11 02:19:56 +0000 | [diff] [blame] | 3676 | Tmp1.getValue(1) }; |
Evan Cheng | cf12ec4 | 2006-10-12 19:12:56 +0000 | [diff] [blame] | 3677 | SDOperand Tmp2 = DAG.getNode(X86ISD::SETCC, VTs2, 2, Ops2, 2); |
Evan Cheng | 734503b | 2006-09-11 02:19:56 +0000 | [diff] [blame] | 3678 | return DAG.getNode(ISD::OR, MVT::i8, Tmp1, Tmp2); |
| 3679 | } |
Evan Cheng | d5781fc | 2005-12-21 20:21:51 +0000 | [diff] [blame] | 3680 | } |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3681 | } |
Evan Cheng | 6dfa999 | 2006-01-30 23:41:35 +0000 | [diff] [blame] | 3682 | |
Evan Cheng | 0488db9 | 2007-09-25 01:57:46 +0000 | [diff] [blame] | 3683 | SDOperand X86TargetLowering::LowerSETCC_New(SDOperand Op, SelectionDAG &DAG) { |
| 3684 | assert(Op.getValueType() == MVT::i8 && "SetCC type must be 8-bit integer"); |
| 3685 | SDOperand Op0 = Op.getOperand(0); |
| 3686 | SDOperand Op1 = Op.getOperand(1); |
| 3687 | SDOperand CC = Op.getOperand(2); |
| 3688 | ISD::CondCode SetCCOpcode = cast<CondCodeSDNode>(CC)->get(); |
| 3689 | bool isFP = MVT::isFloatingPoint(Op.getOperand(1).getValueType()); |
| 3690 | unsigned X86CC; |
| 3691 | |
| 3692 | SDOperand Cond = DAG.getNode(X86ISD::CMP_NEW, MVT::i32, Op0, Op1); |
| 3693 | if (translateX86CC(cast<CondCodeSDNode>(CC)->get(), isFP, X86CC, |
| 3694 | Op0, Op1, DAG)) |
| 3695 | return DAG.getNode(X86ISD::SETCC_NEW, MVT::i8, |
| 3696 | DAG.getConstant(X86CC, MVT::i8), Cond); |
| 3697 | |
| 3698 | assert(isFP && "Illegal integer SetCC!"); |
| 3699 | |
| 3700 | switch (SetCCOpcode) { |
| 3701 | default: assert(false && "Illegal floating point SetCC!"); |
| 3702 | case ISD::SETOEQ: { // !PF & ZF |
| 3703 | SDOperand Tmp1 = DAG.getNode(X86ISD::SETCC_NEW, MVT::i8, |
| 3704 | DAG.getConstant(X86::COND_NP, MVT::i8), Cond); |
| 3705 | SDOperand Tmp2 = DAG.getNode(X86ISD::SETCC_NEW, MVT::i8, |
| 3706 | DAG.getConstant(X86::COND_E, MVT::i8), Cond); |
| 3707 | return DAG.getNode(ISD::AND, MVT::i8, Tmp1, Tmp2); |
| 3708 | } |
| 3709 | case ISD::SETUNE: { // PF | !ZF |
| 3710 | SDOperand Tmp1 = DAG.getNode(X86ISD::SETCC_NEW, MVT::i8, |
| 3711 | DAG.getConstant(X86::COND_P, MVT::i8), Cond); |
| 3712 | SDOperand Tmp2 = DAG.getNode(X86ISD::SETCC_NEW, MVT::i8, |
| 3713 | DAG.getConstant(X86::COND_NE, MVT::i8), Cond); |
| 3714 | return DAG.getNode(ISD::OR, MVT::i8, Tmp1, Tmp2); |
| 3715 | } |
| 3716 | } |
| 3717 | } |
| 3718 | |
| 3719 | |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3720 | SDOperand X86TargetLowering::LowerSELECT(SDOperand Op, SelectionDAG &DAG) { |
Evan Cheng | 734503b | 2006-09-11 02:19:56 +0000 | [diff] [blame] | 3721 | bool addTest = true; |
| 3722 | SDOperand Chain = DAG.getEntryNode(); |
| 3723 | SDOperand Cond = Op.getOperand(0); |
| 3724 | SDOperand CC; |
| 3725 | const MVT::ValueType *VTs = DAG.getNodeValueTypes(MVT::Other, MVT::Flag); |
Evan Cheng | 9bba894 | 2006-01-26 02:13:10 +0000 | [diff] [blame] | 3726 | |
Evan Cheng | 734503b | 2006-09-11 02:19:56 +0000 | [diff] [blame] | 3727 | if (Cond.getOpcode() == ISD::SETCC) |
| 3728 | Cond = LowerSETCC(Cond, DAG, Chain); |
| 3729 | |
| 3730 | if (Cond.getOpcode() == X86ISD::SETCC) { |
| 3731 | CC = Cond.getOperand(0); |
| 3732 | |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3733 | // If condition flag is set by a X86ISD::CMP, then make a copy of it |
Evan Cheng | 734503b | 2006-09-11 02:19:56 +0000 | [diff] [blame] | 3734 | // (since flag operand cannot be shared). Use it as the condition setting |
| 3735 | // operand in place of the X86ISD::SETCC. |
| 3736 | // If the X86ISD::SETCC has more than one use, then perhaps it's better |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3737 | // to use a test instead of duplicating the X86ISD::CMP (for register |
Evan Cheng | 734503b | 2006-09-11 02:19:56 +0000 | [diff] [blame] | 3738 | // pressure reason)? |
| 3739 | SDOperand Cmp = Cond.getOperand(1); |
| 3740 | unsigned Opc = Cmp.getOpcode(); |
Dale Johannesen | f1fc3a8 | 2007-09-23 14:52:20 +0000 | [diff] [blame] | 3741 | bool IllegalFPCMov = |
| 3742 | ! ((X86ScalarSSEf32 && Op.getValueType()==MVT::f32) || |
| 3743 | (X86ScalarSSEf64 && Op.getValueType()==MVT::f64)) && |
Evan Cheng | 734503b | 2006-09-11 02:19:56 +0000 | [diff] [blame] | 3744 | !hasFPCMov(cast<ConstantSDNode>(CC)->getSignExtended()); |
| 3745 | if ((Opc == X86ISD::CMP || Opc == X86ISD::COMI || Opc == X86ISD::UCOMI) && |
| 3746 | !IllegalFPCMov) { |
| 3747 | SDOperand Ops[] = { Chain, Cmp.getOperand(1), Cmp.getOperand(2) }; |
| 3748 | Cond = DAG.getNode(Opc, VTs, 2, Ops, 3); |
| 3749 | addTest = false; |
| 3750 | } |
| 3751 | } |
Evan Cheng | aaca22c | 2006-01-10 20:26:56 +0000 | [diff] [blame] | 3752 | |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3753 | if (addTest) { |
Chris Lattner | 7fbe972 | 2006-10-20 17:42:20 +0000 | [diff] [blame] | 3754 | CC = DAG.getConstant(X86::COND_NE, MVT::i8); |
Evan Cheng | 734503b | 2006-09-11 02:19:56 +0000 | [diff] [blame] | 3755 | SDOperand Ops[] = { Chain, Cond, DAG.getConstant(0, MVT::i8) }; |
| 3756 | Cond = DAG.getNode(X86ISD::CMP, VTs, 2, Ops, 3); |
Evan Cheng | 7df96d6 | 2005-12-17 01:21:05 +0000 | [diff] [blame] | 3757 | } |
Evan Cheng | 6dfa999 | 2006-01-30 23:41:35 +0000 | [diff] [blame] | 3758 | |
Evan Cheng | 734503b | 2006-09-11 02:19:56 +0000 | [diff] [blame] | 3759 | VTs = DAG.getNodeValueTypes(Op.getValueType(), MVT::Flag); |
| 3760 | SmallVector<SDOperand, 4> Ops; |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3761 | // X86ISD::CMOV means set the result (which is operand 1) to the RHS if |
| 3762 | // condition is true. |
| 3763 | Ops.push_back(Op.getOperand(2)); |
| 3764 | Ops.push_back(Op.getOperand(1)); |
| 3765 | Ops.push_back(CC); |
Evan Cheng | 734503b | 2006-09-11 02:19:56 +0000 | [diff] [blame] | 3766 | Ops.push_back(Cond.getValue(1)); |
| 3767 | return DAG.getNode(X86ISD::CMOV, VTs, 2, &Ops[0], Ops.size()); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3768 | } |
Evan Cheng | 9bba894 | 2006-01-26 02:13:10 +0000 | [diff] [blame] | 3769 | |
Evan Cheng | 0488db9 | 2007-09-25 01:57:46 +0000 | [diff] [blame] | 3770 | SDOperand X86TargetLowering::LowerSELECT_New(SDOperand Op, SelectionDAG &DAG) { |
| 3771 | bool addTest = true; |
| 3772 | SDOperand Cond = Op.getOperand(0); |
| 3773 | SDOperand CC; |
| 3774 | |
| 3775 | if (Cond.getOpcode() == ISD::SETCC) |
| 3776 | Cond = LowerSETCC_New(Cond, DAG); |
| 3777 | |
| 3778 | if (Cond.getOpcode() == X86ISD::SETCC_NEW) { |
| 3779 | CC = Cond.getOperand(0); |
| 3780 | |
| 3781 | // If condition flag is set by a X86ISD::CMP, then make a copy of it |
| 3782 | // (since flag operand cannot be shared). Use it as the condition setting |
| 3783 | // operand in place of the X86ISD::SETCC. |
| 3784 | // If the X86ISD::SETCC has more than one use, then perhaps it's better |
| 3785 | // to use a test instead of duplicating the X86ISD::CMP (for register |
| 3786 | // pressure reason)? |
| 3787 | SDOperand Cmp = Cond.getOperand(1); |
| 3788 | unsigned Opc = Cmp.getOpcode(); |
| 3789 | bool IllegalFPCMov = |
| 3790 | ! ((X86ScalarSSEf32 && Op.getValueType()==MVT::f32) || |
| 3791 | (X86ScalarSSEf64 && Op.getValueType()==MVT::f64)) && |
| 3792 | !hasFPCMov(cast<ConstantSDNode>(CC)->getSignExtended()); |
| 3793 | if ((Opc == X86ISD::CMP_NEW || |
| 3794 | Opc == X86ISD::COMI_NEW || |
| 3795 | Opc == X86ISD::UCOMI_NEW) && |
| 3796 | !IllegalFPCMov) { |
| 3797 | Cond = DAG.getNode(Opc, MVT::i32, Cmp.getOperand(0), Cmp.getOperand(1)); |
| 3798 | addTest = false; |
| 3799 | } |
| 3800 | } |
| 3801 | |
| 3802 | if (addTest) { |
| 3803 | CC = DAG.getConstant(X86::COND_NE, MVT::i8); |
| 3804 | Cond = DAG.getNode(X86ISD::CMP_NEW, MVT::i32, Cond, |
| 3805 | DAG.getConstant(0, MVT::i8)); |
| 3806 | } |
| 3807 | |
| 3808 | const MVT::ValueType *VTs = DAG.getNodeValueTypes(Op.getValueType(), |
| 3809 | MVT::Flag); |
| 3810 | SmallVector<SDOperand, 4> Ops; |
| 3811 | // X86ISD::CMOV means set the result (which is operand 1) to the RHS if |
| 3812 | // condition is true. |
| 3813 | Ops.push_back(Op.getOperand(2)); |
| 3814 | Ops.push_back(Op.getOperand(1)); |
| 3815 | Ops.push_back(CC); |
| 3816 | Ops.push_back(Cond); |
| 3817 | return DAG.getNode(X86ISD::CMOV_NEW, VTs, 2, &Ops[0], Ops.size()); |
| 3818 | } |
| 3819 | |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3820 | SDOperand X86TargetLowering::LowerBRCOND(SDOperand Op, SelectionDAG &DAG) { |
Evan Cheng | 734503b | 2006-09-11 02:19:56 +0000 | [diff] [blame] | 3821 | bool addTest = true; |
| 3822 | SDOperand Chain = Op.getOperand(0); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3823 | SDOperand Cond = Op.getOperand(1); |
| 3824 | SDOperand Dest = Op.getOperand(2); |
| 3825 | SDOperand CC; |
Evan Cheng | 734503b | 2006-09-11 02:19:56 +0000 | [diff] [blame] | 3826 | const MVT::ValueType *VTs = DAG.getNodeValueTypes(MVT::Other, MVT::Flag); |
| 3827 | |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3828 | if (Cond.getOpcode() == ISD::SETCC) |
Evan Cheng | 734503b | 2006-09-11 02:19:56 +0000 | [diff] [blame] | 3829 | Cond = LowerSETCC(Cond, DAG, Chain); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3830 | |
| 3831 | if (Cond.getOpcode() == X86ISD::SETCC) { |
Evan Cheng | 734503b | 2006-09-11 02:19:56 +0000 | [diff] [blame] | 3832 | CC = Cond.getOperand(0); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3833 | |
Evan Cheng | 734503b | 2006-09-11 02:19:56 +0000 | [diff] [blame] | 3834 | // If condition flag is set by a X86ISD::CMP, then make a copy of it |
| 3835 | // (since flag operand cannot be shared). Use it as the condition setting |
| 3836 | // operand in place of the X86ISD::SETCC. |
| 3837 | // If the X86ISD::SETCC has more than one use, then perhaps it's better |
| 3838 | // to use a test instead of duplicating the X86ISD::CMP (for register |
| 3839 | // pressure reason)? |
| 3840 | SDOperand Cmp = Cond.getOperand(1); |
| 3841 | unsigned Opc = Cmp.getOpcode(); |
| 3842 | if (Opc == X86ISD::CMP || Opc == X86ISD::COMI || Opc == X86ISD::UCOMI) { |
| 3843 | SDOperand Ops[] = { Chain, Cmp.getOperand(1), Cmp.getOperand(2) }; |
| 3844 | Cond = DAG.getNode(Opc, VTs, 2, Ops, 3); |
| 3845 | addTest = false; |
| 3846 | } |
| 3847 | } |
Evan Cheng | 1bcee36 | 2006-01-13 01:03:02 +0000 | [diff] [blame] | 3848 | |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3849 | if (addTest) { |
Chris Lattner | 7fbe972 | 2006-10-20 17:42:20 +0000 | [diff] [blame] | 3850 | CC = DAG.getConstant(X86::COND_NE, MVT::i8); |
Evan Cheng | 734503b | 2006-09-11 02:19:56 +0000 | [diff] [blame] | 3851 | SDOperand Ops[] = { Chain, Cond, DAG.getConstant(0, MVT::i8) }; |
| 3852 | Cond = DAG.getNode(X86ISD::CMP, VTs, 2, Ops, 3); |
Evan Cheng | 898101c | 2005-12-19 23:12:38 +0000 | [diff] [blame] | 3853 | } |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3854 | return DAG.getNode(X86ISD::BRCOND, Op.getValueType(), |
Evan Cheng | 734503b | 2006-09-11 02:19:56 +0000 | [diff] [blame] | 3855 | Cond, Op.getOperand(2), CC, Cond.getValue(1)); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3856 | } |
Evan Cheng | 67f92a7 | 2006-01-11 22:15:48 +0000 | [diff] [blame] | 3857 | |
Evan Cheng | 0488db9 | 2007-09-25 01:57:46 +0000 | [diff] [blame] | 3858 | SDOperand X86TargetLowering::LowerBRCOND_New(SDOperand Op, SelectionDAG &DAG) { |
| 3859 | bool addTest = true; |
| 3860 | SDOperand Chain = Op.getOperand(0); |
| 3861 | SDOperand Cond = Op.getOperand(1); |
| 3862 | SDOperand Dest = Op.getOperand(2); |
| 3863 | SDOperand CC; |
| 3864 | |
| 3865 | if (Cond.getOpcode() == ISD::SETCC) |
| 3866 | Cond = LowerSETCC_New(Cond, DAG); |
| 3867 | |
| 3868 | if (Cond.getOpcode() == X86ISD::SETCC_NEW) { |
| 3869 | CC = Cond.getOperand(0); |
| 3870 | |
| 3871 | // If condition flag is set by a X86ISD::CMP, then make a copy of it |
| 3872 | // (since flag operand cannot be shared). Use it as the condition setting |
| 3873 | // operand in place of the X86ISD::SETCC. |
| 3874 | // If the X86ISD::SETCC has more than one use, then perhaps it's better |
| 3875 | // to use a test instead of duplicating the X86ISD::CMP (for register |
| 3876 | // pressure reason)? |
| 3877 | SDOperand Cmp = Cond.getOperand(1); |
| 3878 | unsigned Opc = Cmp.getOpcode(); |
| 3879 | if (Opc == X86ISD::CMP_NEW || |
| 3880 | Opc == X86ISD::COMI_NEW || |
| 3881 | Opc == X86ISD::UCOMI_NEW) { |
| 3882 | Cond = DAG.getNode(Opc, MVT::i32, Cmp.getOperand(0), Cmp.getOperand(1)); |
| 3883 | addTest = false; |
| 3884 | } |
| 3885 | } |
| 3886 | |
| 3887 | if (addTest) { |
| 3888 | CC = DAG.getConstant(X86::COND_NE, MVT::i8); |
| 3889 | Cond= DAG.getNode(X86ISD::CMP_NEW, MVT::i32, Cond, DAG.getConstant(0, MVT::i8)); |
| 3890 | } |
| 3891 | return DAG.getNode(X86ISD::BRCOND_NEW, Op.getValueType(), |
| 3892 | Chain, Op.getOperand(2), CC, Cond); |
| 3893 | } |
| 3894 | |
Evan Cheng | 32fe103 | 2006-05-25 00:59:30 +0000 | [diff] [blame] | 3895 | SDOperand X86TargetLowering::LowerCALL(SDOperand Op, SelectionDAG &DAG) { |
| 3896 | unsigned CallingConv= cast<ConstantSDNode>(Op.getOperand(1))->getValue(); |
Anton Korobeynikov | 12c49af | 2006-11-21 00:01:06 +0000 | [diff] [blame] | 3897 | |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 3898 | if (Subtarget->is64Bit()) |
Chris Lattner | 09c75a4 | 2007-02-25 09:06:15 +0000 | [diff] [blame] | 3899 | return LowerX86_64CCCCallTo(Op, DAG, CallingConv); |
Evan Cheng | 32fe103 | 2006-05-25 00:59:30 +0000 | [diff] [blame] | 3900 | else |
Anton Korobeynikov | f824868 | 2006-09-20 22:03:51 +0000 | [diff] [blame] | 3901 | switch (CallingConv) { |
Chris Lattner | f38f543 | 2006-09-27 18:29:38 +0000 | [diff] [blame] | 3902 | default: |
Anton Korobeynikov | 12c49af | 2006-11-21 00:01:06 +0000 | [diff] [blame] | 3903 | assert(0 && "Unsupported calling convention"); |
Chris Lattner | f38f543 | 2006-09-27 18:29:38 +0000 | [diff] [blame] | 3904 | case CallingConv::Fast: |
Chris Lattner | 2db39b8 | 2007-02-28 06:05:16 +0000 | [diff] [blame] | 3905 | // TODO: Implement fastcc |
Anton Korobeynikov | f824868 | 2006-09-20 22:03:51 +0000 | [diff] [blame] | 3906 | // Falls through |
Chris Lattner | f38f543 | 2006-09-27 18:29:38 +0000 | [diff] [blame] | 3907 | case CallingConv::C: |
Anton Korobeynikov | 12c49af | 2006-11-21 00:01:06 +0000 | [diff] [blame] | 3908 | case CallingConv::X86_StdCall: |
Chris Lattner | 09c75a4 | 2007-02-25 09:06:15 +0000 | [diff] [blame] | 3909 | return LowerCCCCallTo(Op, DAG, CallingConv); |
Chris Lattner | f38f543 | 2006-09-27 18:29:38 +0000 | [diff] [blame] | 3910 | case CallingConv::X86_FastCall: |
Chris Lattner | 09c75a4 | 2007-02-25 09:06:15 +0000 | [diff] [blame] | 3911 | return LowerFastCCCallTo(Op, DAG, CallingConv); |
Anton Korobeynikov | f824868 | 2006-09-20 22:03:51 +0000 | [diff] [blame] | 3912 | } |
Evan Cheng | 32fe103 | 2006-05-25 00:59:30 +0000 | [diff] [blame] | 3913 | } |
| 3914 | |
Anton Korobeynikov | e060b53 | 2007-04-17 19:34:00 +0000 | [diff] [blame] | 3915 | |
| 3916 | // Lower dynamic stack allocation to _alloca call for Cygwin/Mingw targets. |
| 3917 | // Calls to _alloca is needed to probe the stack when allocating more than 4k |
| 3918 | // bytes in one go. Touching the stack at 4K increments is necessary to ensure |
| 3919 | // that the guard pages used by the OS virtual memory manager are allocated in |
| 3920 | // correct sequence. |
Anton Korobeynikov | 4304bcc | 2007-07-05 20:36:08 +0000 | [diff] [blame] | 3921 | SDOperand |
| 3922 | X86TargetLowering::LowerDYNAMIC_STACKALLOC(SDOperand Op, |
| 3923 | SelectionDAG &DAG) { |
Anton Korobeynikov | e060b53 | 2007-04-17 19:34:00 +0000 | [diff] [blame] | 3924 | assert(Subtarget->isTargetCygMing() && |
| 3925 | "This should be used only on Cygwin/Mingw targets"); |
| 3926 | |
Anton Korobeynikov | 57fc00d | 2007-04-17 09:20:00 +0000 | [diff] [blame] | 3927 | // Get the inputs. |
| 3928 | SDOperand Chain = Op.getOperand(0); |
| 3929 | SDOperand Size = Op.getOperand(1); |
| 3930 | // FIXME: Ensure alignment here |
| 3931 | |
Anton Korobeynikov | 4304bcc | 2007-07-05 20:36:08 +0000 | [diff] [blame] | 3932 | SDOperand Flag; |
| 3933 | |
Anton Korobeynikov | 57fc00d | 2007-04-17 09:20:00 +0000 | [diff] [blame] | 3934 | MVT::ValueType IntPtr = getPointerTy(); |
| 3935 | MVT::ValueType SPTy = (Subtarget->is64Bit() ? MVT::i64 : MVT::i32); |
Anton Korobeynikov | 57fc00d | 2007-04-17 09:20:00 +0000 | [diff] [blame] | 3936 | |
Anton Korobeynikov | 4304bcc | 2007-07-05 20:36:08 +0000 | [diff] [blame] | 3937 | Chain = DAG.getCopyToReg(Chain, X86::EAX, Size, Flag); |
| 3938 | Flag = Chain.getValue(1); |
| 3939 | |
| 3940 | SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Flag); |
| 3941 | SDOperand Ops[] = { Chain, |
| 3942 | DAG.getTargetExternalSymbol("_alloca", IntPtr), |
| 3943 | DAG.getRegister(X86::EAX, IntPtr), |
| 3944 | Flag }; |
| 3945 | Chain = DAG.getNode(X86ISD::CALL, NodeTys, Ops, 4); |
| 3946 | Flag = Chain.getValue(1); |
| 3947 | |
| 3948 | Chain = DAG.getCopyFromReg(Chain, X86StackPtr, SPTy).getValue(1); |
Anton Korobeynikov | 57fc00d | 2007-04-17 09:20:00 +0000 | [diff] [blame] | 3949 | |
| 3950 | std::vector<MVT::ValueType> Tys; |
| 3951 | Tys.push_back(SPTy); |
| 3952 | Tys.push_back(MVT::Other); |
Anton Korobeynikov | 4304bcc | 2007-07-05 20:36:08 +0000 | [diff] [blame] | 3953 | SDOperand Ops1[2] = { Chain.getValue(0), Chain }; |
| 3954 | return DAG.getNode(ISD::MERGE_VALUES, Tys, Ops1, 2); |
Anton Korobeynikov | 57fc00d | 2007-04-17 09:20:00 +0000 | [diff] [blame] | 3955 | } |
| 3956 | |
Evan Cheng | 1bc7804 | 2006-04-26 01:20:17 +0000 | [diff] [blame] | 3957 | SDOperand |
| 3958 | X86TargetLowering::LowerFORMAL_ARGUMENTS(SDOperand Op, SelectionDAG &DAG) { |
Evan Cheng | e8bd0a3 | 2006-06-06 23:30:24 +0000 | [diff] [blame] | 3959 | MachineFunction &MF = DAG.getMachineFunction(); |
| 3960 | const Function* Fn = MF.getFunction(); |
| 3961 | if (Fn->hasExternalLinkage() && |
Anton Korobeynikov | 317848f | 2007-01-03 11:43:14 +0000 | [diff] [blame] | 3962 | Subtarget->isTargetCygMing() && |
Evan Cheng | b12223e | 2006-06-09 06:24:42 +0000 | [diff] [blame] | 3963 | Fn->getName() == "main") |
Chris Lattner | d15dff2 | 2007-04-17 17:21:52 +0000 | [diff] [blame] | 3964 | MF.getInfo<X86MachineFunctionInfo>()->setForceFramePointer(true); |
Evan Cheng | e8bd0a3 | 2006-06-06 23:30:24 +0000 | [diff] [blame] | 3965 | |
Evan Cheng | 25caf63 | 2006-05-23 21:06:34 +0000 | [diff] [blame] | 3966 | unsigned CC = cast<ConstantSDNode>(Op.getOperand(1))->getValue(); |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 3967 | if (Subtarget->is64Bit()) |
| 3968 | return LowerX86_64CCCArguments(Op, DAG); |
Evan Cheng | 25caf63 | 2006-05-23 21:06:34 +0000 | [diff] [blame] | 3969 | else |
Anton Korobeynikov | f824868 | 2006-09-20 22:03:51 +0000 | [diff] [blame] | 3970 | switch(CC) { |
Chris Lattner | f38f543 | 2006-09-27 18:29:38 +0000 | [diff] [blame] | 3971 | default: |
| 3972 | assert(0 && "Unsupported calling convention"); |
| 3973 | case CallingConv::Fast: |
Chris Lattner | 2db39b8 | 2007-02-28 06:05:16 +0000 | [diff] [blame] | 3974 | // TODO: implement fastcc. |
| 3975 | |
Anton Korobeynikov | f824868 | 2006-09-20 22:03:51 +0000 | [diff] [blame] | 3976 | // Falls through |
Chris Lattner | f38f543 | 2006-09-27 18:29:38 +0000 | [diff] [blame] | 3977 | case CallingConv::C: |
Anton Korobeynikov | f824868 | 2006-09-20 22:03:51 +0000 | [diff] [blame] | 3978 | return LowerCCCArguments(Op, DAG); |
Chris Lattner | f38f543 | 2006-09-27 18:29:38 +0000 | [diff] [blame] | 3979 | case CallingConv::X86_StdCall: |
Chris Lattner | d15dff2 | 2007-04-17 17:21:52 +0000 | [diff] [blame] | 3980 | MF.getInfo<X86MachineFunctionInfo>()->setDecorationStyle(StdCall); |
Anton Korobeynikov | b10308e | 2007-01-28 13:31:35 +0000 | [diff] [blame] | 3981 | return LowerCCCArguments(Op, DAG, true); |
Chris Lattner | f38f543 | 2006-09-27 18:29:38 +0000 | [diff] [blame] | 3982 | case CallingConv::X86_FastCall: |
Chris Lattner | d15dff2 | 2007-04-17 17:21:52 +0000 | [diff] [blame] | 3983 | MF.getInfo<X86MachineFunctionInfo>()->setDecorationStyle(FastCall); |
Chris Lattner | 2db39b8 | 2007-02-28 06:05:16 +0000 | [diff] [blame] | 3984 | return LowerFastCCArguments(Op, DAG); |
Anton Korobeynikov | f824868 | 2006-09-20 22:03:51 +0000 | [diff] [blame] | 3985 | } |
Evan Cheng | 1bc7804 | 2006-04-26 01:20:17 +0000 | [diff] [blame] | 3986 | } |
| 3987 | |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3988 | SDOperand X86TargetLowering::LowerMEMSET(SDOperand Op, SelectionDAG &DAG) { |
| 3989 | SDOperand InFlag(0, 0); |
| 3990 | SDOperand Chain = Op.getOperand(0); |
| 3991 | unsigned Align = |
| 3992 | (unsigned)cast<ConstantSDNode>(Op.getOperand(4))->getValue(); |
| 3993 | if (Align == 0) Align = 1; |
| 3994 | |
| 3995 | ConstantSDNode *I = dyn_cast<ConstantSDNode>(Op.getOperand(3)); |
Rafael Espindola | 6b83b5d | 2007-08-27 10:18:20 +0000 | [diff] [blame] | 3996 | // If not DWORD aligned or size is more than the threshold, call memset. |
Rafael Espindola | 44c8265 | 2007-08-27 17:48:26 +0000 | [diff] [blame] | 3997 | // The libc version is likely to be faster for these cases. It can use the |
| 3998 | // address value and run time information about the CPU. |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 3999 | if ((Align & 3) != 0 || |
Rafael Espindola | 6b83b5d | 2007-08-27 10:18:20 +0000 | [diff] [blame] | 4000 | (I && I->getValue() > Subtarget->getMinRepStrSizeThreshold())) { |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4001 | MVT::ValueType IntPtr = getPointerTy(); |
Owen Anderson | a69571c | 2006-05-03 01:29:57 +0000 | [diff] [blame] | 4002 | const Type *IntPtrTy = getTargetData()->getIntPtrType(); |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 4003 | TargetLowering::ArgListTy Args; |
| 4004 | TargetLowering::ArgListEntry Entry; |
| 4005 | Entry.Node = Op.getOperand(1); |
| 4006 | Entry.Ty = IntPtrTy; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 4007 | Args.push_back(Entry); |
Reid Spencer | aff9387 | 2007-01-03 17:24:59 +0000 | [diff] [blame] | 4008 | // Extend the unsigned i8 argument to be an int value for the call. |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 4009 | Entry.Node = DAG.getNode(ISD::ZERO_EXTEND, MVT::i32, Op.getOperand(2)); |
| 4010 | Entry.Ty = IntPtrTy; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 4011 | Args.push_back(Entry); |
| 4012 | Entry.Node = Op.getOperand(3); |
| 4013 | Args.push_back(Entry); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4014 | std::pair<SDOperand,SDOperand> CallResult = |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 4015 | LowerCallTo(Chain, Type::VoidTy, false, false, CallingConv::C, false, |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4016 | DAG.getExternalSymbol("memset", IntPtr), Args, DAG); |
| 4017 | return CallResult.second; |
Evan Cheng | 48090aa | 2006-03-21 23:01:21 +0000 | [diff] [blame] | 4018 | } |
Evan Cheng | b9df0ca | 2006-03-22 02:53:00 +0000 | [diff] [blame] | 4019 | |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4020 | MVT::ValueType AVT; |
| 4021 | SDOperand Count; |
| 4022 | ConstantSDNode *ValC = dyn_cast<ConstantSDNode>(Op.getOperand(2)); |
| 4023 | unsigned BytesLeft = 0; |
| 4024 | bool TwoRepStos = false; |
| 4025 | if (ValC) { |
| 4026 | unsigned ValReg; |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 4027 | uint64_t Val = ValC->getValue() & 255; |
Evan Cheng | 5ced1d8 | 2006-04-06 23:23:56 +0000 | [diff] [blame] | 4028 | |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4029 | // If the value is a constant, then we can potentially use larger sets. |
| 4030 | switch (Align & 3) { |
| 4031 | case 2: // WORD aligned |
| 4032 | AVT = MVT::i16; |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4033 | ValReg = X86::AX; |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 4034 | Val = (Val << 8) | Val; |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4035 | break; |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 4036 | case 0: // DWORD aligned |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4037 | AVT = MVT::i32; |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 4038 | ValReg = X86::EAX; |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4039 | Val = (Val << 8) | Val; |
| 4040 | Val = (Val << 16) | Val; |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 4041 | if (Subtarget->is64Bit() && ((Align & 0xF) == 0)) { // QWORD aligned |
| 4042 | AVT = MVT::i64; |
| 4043 | ValReg = X86::RAX; |
| 4044 | Val = (Val << 32) | Val; |
| 4045 | } |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4046 | break; |
| 4047 | default: // Byte aligned |
| 4048 | AVT = MVT::i8; |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4049 | ValReg = X86::AL; |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 4050 | Count = Op.getOperand(3); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4051 | break; |
Evan Cheng | 80d428c | 2006-04-19 22:48:17 +0000 | [diff] [blame] | 4052 | } |
| 4053 | |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 4054 | if (AVT > MVT::i8) { |
| 4055 | if (I) { |
| 4056 | unsigned UBytes = MVT::getSizeInBits(AVT) / 8; |
| 4057 | Count = DAG.getConstant(I->getValue() / UBytes, getPointerTy()); |
| 4058 | BytesLeft = I->getValue() % UBytes; |
| 4059 | } else { |
| 4060 | assert(AVT >= MVT::i32 && |
| 4061 | "Do not use rep;stos if not at least DWORD aligned"); |
| 4062 | Count = DAG.getNode(ISD::SRL, Op.getOperand(3).getValueType(), |
| 4063 | Op.getOperand(3), DAG.getConstant(2, MVT::i8)); |
| 4064 | TwoRepStos = true; |
| 4065 | } |
| 4066 | } |
| 4067 | |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4068 | Chain = DAG.getCopyToReg(Chain, ValReg, DAG.getConstant(Val, AVT), |
| 4069 | InFlag); |
| 4070 | InFlag = Chain.getValue(1); |
| 4071 | } else { |
| 4072 | AVT = MVT::i8; |
| 4073 | Count = Op.getOperand(3); |
| 4074 | Chain = DAG.getCopyToReg(Chain, X86::AL, Op.getOperand(2), InFlag); |
| 4075 | InFlag = Chain.getValue(1); |
Evan Cheng | b9df0ca | 2006-03-22 02:53:00 +0000 | [diff] [blame] | 4076 | } |
Evan Cheng | c78d3b4 | 2006-04-24 18:01:45 +0000 | [diff] [blame] | 4077 | |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 4078 | Chain = DAG.getCopyToReg(Chain, Subtarget->is64Bit() ? X86::RCX : X86::ECX, |
| 4079 | Count, InFlag); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4080 | InFlag = Chain.getValue(1); |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 4081 | Chain = DAG.getCopyToReg(Chain, Subtarget->is64Bit() ? X86::RDI : X86::EDI, |
| 4082 | Op.getOperand(1), InFlag); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4083 | InFlag = Chain.getValue(1); |
Evan Cheng | a0b3afb | 2006-03-27 07:00:16 +0000 | [diff] [blame] | 4084 | |
Chris Lattner | d96d072 | 2007-02-25 06:40:16 +0000 | [diff] [blame] | 4085 | SDVTList Tys = DAG.getVTList(MVT::Other, MVT::Flag); |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 4086 | SmallVector<SDOperand, 8> Ops; |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4087 | Ops.push_back(Chain); |
| 4088 | Ops.push_back(DAG.getValueType(AVT)); |
| 4089 | Ops.push_back(InFlag); |
Evan Cheng | 311ace0 | 2006-08-11 07:35:45 +0000 | [diff] [blame] | 4090 | Chain = DAG.getNode(X86ISD::REP_STOS, Tys, &Ops[0], Ops.size()); |
Evan Cheng | c78d3b4 | 2006-04-24 18:01:45 +0000 | [diff] [blame] | 4091 | |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4092 | if (TwoRepStos) { |
| 4093 | InFlag = Chain.getValue(1); |
| 4094 | Count = Op.getOperand(3); |
| 4095 | MVT::ValueType CVT = Count.getValueType(); |
| 4096 | SDOperand Left = DAG.getNode(ISD::AND, CVT, Count, |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 4097 | DAG.getConstant((AVT == MVT::i64) ? 7 : 3, CVT)); |
| 4098 | Chain = DAG.getCopyToReg(Chain, (CVT == MVT::i64) ? X86::RCX : X86::ECX, |
| 4099 | Left, InFlag); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4100 | InFlag = Chain.getValue(1); |
Chris Lattner | d96d072 | 2007-02-25 06:40:16 +0000 | [diff] [blame] | 4101 | Tys = DAG.getVTList(MVT::Other, MVT::Flag); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4102 | Ops.clear(); |
| 4103 | Ops.push_back(Chain); |
| 4104 | Ops.push_back(DAG.getValueType(MVT::i8)); |
| 4105 | Ops.push_back(InFlag); |
Evan Cheng | 311ace0 | 2006-08-11 07:35:45 +0000 | [diff] [blame] | 4106 | Chain = DAG.getNode(X86ISD::REP_STOS, Tys, &Ops[0], Ops.size()); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4107 | } else if (BytesLeft) { |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 4108 | // Issue stores for the last 1 - 7 bytes. |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4109 | SDOperand Value; |
| 4110 | unsigned Val = ValC->getValue() & 255; |
| 4111 | unsigned Offset = I->getValue() - BytesLeft; |
| 4112 | SDOperand DstAddr = Op.getOperand(1); |
| 4113 | MVT::ValueType AddrVT = DstAddr.getValueType(); |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 4114 | if (BytesLeft >= 4) { |
| 4115 | Val = (Val << 8) | Val; |
| 4116 | Val = (Val << 16) | Val; |
| 4117 | Value = DAG.getConstant(Val, MVT::i32); |
Evan Cheng | 786225a | 2006-10-05 23:01:46 +0000 | [diff] [blame] | 4118 | Chain = DAG.getStore(Chain, Value, |
| 4119 | DAG.getNode(ISD::ADD, AddrVT, DstAddr, |
| 4120 | DAG.getConstant(Offset, AddrVT)), |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 4121 | NULL, 0); |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 4122 | BytesLeft -= 4; |
| 4123 | Offset += 4; |
| 4124 | } |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4125 | if (BytesLeft >= 2) { |
| 4126 | Value = DAG.getConstant((Val << 8) | Val, MVT::i16); |
Evan Cheng | 786225a | 2006-10-05 23:01:46 +0000 | [diff] [blame] | 4127 | Chain = DAG.getStore(Chain, Value, |
| 4128 | DAG.getNode(ISD::ADD, AddrVT, DstAddr, |
| 4129 | DAG.getConstant(Offset, AddrVT)), |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 4130 | NULL, 0); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4131 | BytesLeft -= 2; |
| 4132 | Offset += 2; |
Evan Cheng | 386031a | 2006-03-24 07:29:27 +0000 | [diff] [blame] | 4133 | } |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4134 | if (BytesLeft == 1) { |
| 4135 | Value = DAG.getConstant(Val, MVT::i8); |
Evan Cheng | 786225a | 2006-10-05 23:01:46 +0000 | [diff] [blame] | 4136 | Chain = DAG.getStore(Chain, Value, |
| 4137 | DAG.getNode(ISD::ADD, AddrVT, DstAddr, |
| 4138 | DAG.getConstant(Offset, AddrVT)), |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 4139 | NULL, 0); |
Evan Cheng | ba05f72 | 2006-04-21 23:03:30 +0000 | [diff] [blame] | 4140 | } |
Evan Cheng | 386031a | 2006-03-24 07:29:27 +0000 | [diff] [blame] | 4141 | } |
Evan Cheng | 11e15b3 | 2006-04-03 20:53:28 +0000 | [diff] [blame] | 4142 | |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4143 | return Chain; |
| 4144 | } |
Evan Cheng | 11e15b3 | 2006-04-03 20:53:28 +0000 | [diff] [blame] | 4145 | |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4146 | SDOperand X86TargetLowering::LowerMEMCPY(SDOperand Op, SelectionDAG &DAG) { |
| 4147 | SDOperand Chain = Op.getOperand(0); |
| 4148 | unsigned Align = |
| 4149 | (unsigned)cast<ConstantSDNode>(Op.getOperand(4))->getValue(); |
| 4150 | if (Align == 0) Align = 1; |
Evan Cheng | 11e15b3 | 2006-04-03 20:53:28 +0000 | [diff] [blame] | 4151 | |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4152 | ConstantSDNode *I = dyn_cast<ConstantSDNode>(Op.getOperand(3)); |
Rafael Espindola | 6b83b5d | 2007-08-27 10:18:20 +0000 | [diff] [blame] | 4153 | // If not DWORD aligned or size is more than the threshold, call memcpy. |
Rafael Espindola | 44c8265 | 2007-08-27 17:48:26 +0000 | [diff] [blame] | 4154 | // The libc version is likely to be faster for these cases. It can use the |
| 4155 | // address value and run time information about the CPU. |
| 4156 | // With glibc 2.6.1 on a core 2, coping an array of 100M longs was 30% faster |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4157 | if ((Align & 3) != 0 || |
Rafael Espindola | 6b83b5d | 2007-08-27 10:18:20 +0000 | [diff] [blame] | 4158 | (I && I->getValue() > Subtarget->getMinRepStrSizeThreshold())) { |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4159 | MVT::ValueType IntPtr = getPointerTy(); |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 4160 | TargetLowering::ArgListTy Args; |
| 4161 | TargetLowering::ArgListEntry Entry; |
Anton Korobeynikov | b10308e | 2007-01-28 13:31:35 +0000 | [diff] [blame] | 4162 | Entry.Ty = getTargetData()->getIntPtrType(); |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 4163 | Entry.Node = Op.getOperand(1); Args.push_back(Entry); |
| 4164 | Entry.Node = Op.getOperand(2); Args.push_back(Entry); |
| 4165 | Entry.Node = Op.getOperand(3); Args.push_back(Entry); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4166 | std::pair<SDOperand,SDOperand> CallResult = |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 4167 | LowerCallTo(Chain, Type::VoidTy, false, false, CallingConv::C, false, |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4168 | DAG.getExternalSymbol("memcpy", IntPtr), Args, DAG); |
| 4169 | return CallResult.second; |
Evan Cheng | b067a1e | 2006-03-31 19:22:53 +0000 | [diff] [blame] | 4170 | } |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4171 | |
| 4172 | MVT::ValueType AVT; |
| 4173 | SDOperand Count; |
| 4174 | unsigned BytesLeft = 0; |
| 4175 | bool TwoRepMovs = false; |
| 4176 | switch (Align & 3) { |
| 4177 | case 2: // WORD aligned |
| 4178 | AVT = MVT::i16; |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4179 | break; |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 4180 | case 0: // DWORD aligned |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4181 | AVT = MVT::i32; |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 4182 | if (Subtarget->is64Bit() && ((Align & 0xF) == 0)) // QWORD aligned |
| 4183 | AVT = MVT::i64; |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4184 | break; |
| 4185 | default: // Byte aligned |
| 4186 | AVT = MVT::i8; |
| 4187 | Count = Op.getOperand(3); |
| 4188 | break; |
| 4189 | } |
| 4190 | |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 4191 | if (AVT > MVT::i8) { |
| 4192 | if (I) { |
| 4193 | unsigned UBytes = MVT::getSizeInBits(AVT) / 8; |
| 4194 | Count = DAG.getConstant(I->getValue() / UBytes, getPointerTy()); |
| 4195 | BytesLeft = I->getValue() % UBytes; |
| 4196 | } else { |
| 4197 | assert(AVT >= MVT::i32 && |
| 4198 | "Do not use rep;movs if not at least DWORD aligned"); |
| 4199 | Count = DAG.getNode(ISD::SRL, Op.getOperand(3).getValueType(), |
| 4200 | Op.getOperand(3), DAG.getConstant(2, MVT::i8)); |
| 4201 | TwoRepMovs = true; |
| 4202 | } |
| 4203 | } |
| 4204 | |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4205 | SDOperand InFlag(0, 0); |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 4206 | Chain = DAG.getCopyToReg(Chain, Subtarget->is64Bit() ? X86::RCX : X86::ECX, |
| 4207 | Count, InFlag); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4208 | InFlag = Chain.getValue(1); |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 4209 | Chain = DAG.getCopyToReg(Chain, Subtarget->is64Bit() ? X86::RDI : X86::EDI, |
| 4210 | Op.getOperand(1), InFlag); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4211 | InFlag = Chain.getValue(1); |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 4212 | Chain = DAG.getCopyToReg(Chain, Subtarget->is64Bit() ? X86::RSI : X86::ESI, |
| 4213 | Op.getOperand(2), InFlag); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4214 | InFlag = Chain.getValue(1); |
| 4215 | |
Chris Lattner | d96d072 | 2007-02-25 06:40:16 +0000 | [diff] [blame] | 4216 | SDVTList Tys = DAG.getVTList(MVT::Other, MVT::Flag); |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 4217 | SmallVector<SDOperand, 8> Ops; |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4218 | Ops.push_back(Chain); |
| 4219 | Ops.push_back(DAG.getValueType(AVT)); |
| 4220 | Ops.push_back(InFlag); |
Evan Cheng | 311ace0 | 2006-08-11 07:35:45 +0000 | [diff] [blame] | 4221 | Chain = DAG.getNode(X86ISD::REP_MOVS, Tys, &Ops[0], Ops.size()); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4222 | |
| 4223 | if (TwoRepMovs) { |
| 4224 | InFlag = Chain.getValue(1); |
| 4225 | Count = Op.getOperand(3); |
| 4226 | MVT::ValueType CVT = Count.getValueType(); |
| 4227 | SDOperand Left = DAG.getNode(ISD::AND, CVT, Count, |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 4228 | DAG.getConstant((AVT == MVT::i64) ? 7 : 3, CVT)); |
| 4229 | Chain = DAG.getCopyToReg(Chain, (CVT == MVT::i64) ? X86::RCX : X86::ECX, |
| 4230 | Left, InFlag); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4231 | InFlag = Chain.getValue(1); |
Chris Lattner | d96d072 | 2007-02-25 06:40:16 +0000 | [diff] [blame] | 4232 | Tys = DAG.getVTList(MVT::Other, MVT::Flag); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4233 | Ops.clear(); |
| 4234 | Ops.push_back(Chain); |
| 4235 | Ops.push_back(DAG.getValueType(MVT::i8)); |
| 4236 | Ops.push_back(InFlag); |
Evan Cheng | 311ace0 | 2006-08-11 07:35:45 +0000 | [diff] [blame] | 4237 | Chain = DAG.getNode(X86ISD::REP_MOVS, Tys, &Ops[0], Ops.size()); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4238 | } else if (BytesLeft) { |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 4239 | // Issue loads and stores for the last 1 - 7 bytes. |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4240 | unsigned Offset = I->getValue() - BytesLeft; |
| 4241 | SDOperand DstAddr = Op.getOperand(1); |
| 4242 | MVT::ValueType DstVT = DstAddr.getValueType(); |
| 4243 | SDOperand SrcAddr = Op.getOperand(2); |
| 4244 | MVT::ValueType SrcVT = SrcAddr.getValueType(); |
| 4245 | SDOperand Value; |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 4246 | if (BytesLeft >= 4) { |
| 4247 | Value = DAG.getLoad(MVT::i32, Chain, |
| 4248 | DAG.getNode(ISD::ADD, SrcVT, SrcAddr, |
| 4249 | DAG.getConstant(Offset, SrcVT)), |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 4250 | NULL, 0); |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 4251 | Chain = Value.getValue(1); |
Evan Cheng | 786225a | 2006-10-05 23:01:46 +0000 | [diff] [blame] | 4252 | Chain = DAG.getStore(Chain, Value, |
| 4253 | DAG.getNode(ISD::ADD, DstVT, DstAddr, |
| 4254 | DAG.getConstant(Offset, DstVT)), |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 4255 | NULL, 0); |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 4256 | BytesLeft -= 4; |
| 4257 | Offset += 4; |
| 4258 | } |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4259 | if (BytesLeft >= 2) { |
| 4260 | Value = DAG.getLoad(MVT::i16, Chain, |
| 4261 | DAG.getNode(ISD::ADD, SrcVT, SrcAddr, |
| 4262 | DAG.getConstant(Offset, SrcVT)), |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 4263 | NULL, 0); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4264 | Chain = Value.getValue(1); |
Evan Cheng | 786225a | 2006-10-05 23:01:46 +0000 | [diff] [blame] | 4265 | Chain = DAG.getStore(Chain, Value, |
| 4266 | DAG.getNode(ISD::ADD, DstVT, DstAddr, |
| 4267 | DAG.getConstant(Offset, DstVT)), |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 4268 | NULL, 0); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4269 | BytesLeft -= 2; |
| 4270 | Offset += 2; |
Evan Cheng | b067a1e | 2006-03-31 19:22:53 +0000 | [diff] [blame] | 4271 | } |
| 4272 | |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4273 | if (BytesLeft == 1) { |
| 4274 | Value = DAG.getLoad(MVT::i8, Chain, |
| 4275 | DAG.getNode(ISD::ADD, SrcVT, SrcAddr, |
| 4276 | DAG.getConstant(Offset, SrcVT)), |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 4277 | NULL, 0); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4278 | Chain = Value.getValue(1); |
Evan Cheng | 786225a | 2006-10-05 23:01:46 +0000 | [diff] [blame] | 4279 | Chain = DAG.getStore(Chain, Value, |
| 4280 | DAG.getNode(ISD::ADD, DstVT, DstAddr, |
| 4281 | DAG.getConstant(Offset, DstVT)), |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 4282 | NULL, 0); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4283 | } |
Evan Cheng | b067a1e | 2006-03-31 19:22:53 +0000 | [diff] [blame] | 4284 | } |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4285 | |
| 4286 | return Chain; |
| 4287 | } |
| 4288 | |
| 4289 | SDOperand |
| 4290 | X86TargetLowering::LowerREADCYCLCECOUNTER(SDOperand Op, SelectionDAG &DAG) { |
Chris Lattner | d96d072 | 2007-02-25 06:40:16 +0000 | [diff] [blame] | 4291 | SDVTList Tys = DAG.getVTList(MVT::Other, MVT::Flag); |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 4292 | SDOperand TheOp = Op.getOperand(0); |
| 4293 | SDOperand rd = DAG.getNode(X86ISD::RDTSC_DAG, Tys, &TheOp, 1); |
Evan Cheng | 3fa9dff | 2006-11-29 08:28:13 +0000 | [diff] [blame] | 4294 | if (Subtarget->is64Bit()) { |
| 4295 | SDOperand Copy1 = DAG.getCopyFromReg(rd, X86::RAX, MVT::i64, rd.getValue(1)); |
| 4296 | SDOperand Copy2 = DAG.getCopyFromReg(Copy1.getValue(1), X86::RDX, |
| 4297 | MVT::i64, Copy1.getValue(2)); |
| 4298 | SDOperand Tmp = DAG.getNode(ISD::SHL, MVT::i64, Copy2, |
| 4299 | DAG.getConstant(32, MVT::i8)); |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 4300 | SDOperand Ops[] = { |
| 4301 | DAG.getNode(ISD::OR, MVT::i64, Copy1, Tmp), Copy2.getValue(1) |
| 4302 | }; |
Chris Lattner | d96d072 | 2007-02-25 06:40:16 +0000 | [diff] [blame] | 4303 | |
| 4304 | Tys = DAG.getVTList(MVT::i64, MVT::Other); |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 4305 | return DAG.getNode(ISD::MERGE_VALUES, Tys, Ops, 2); |
Evan Cheng | 3fa9dff | 2006-11-29 08:28:13 +0000 | [diff] [blame] | 4306 | } |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 4307 | |
| 4308 | SDOperand Copy1 = DAG.getCopyFromReg(rd, X86::EAX, MVT::i32, rd.getValue(1)); |
| 4309 | SDOperand Copy2 = DAG.getCopyFromReg(Copy1.getValue(1), X86::EDX, |
| 4310 | MVT::i32, Copy1.getValue(2)); |
| 4311 | SDOperand Ops[] = { Copy1, Copy2, Copy2.getValue(1) }; |
| 4312 | Tys = DAG.getVTList(MVT::i32, MVT::i32, MVT::Other); |
| 4313 | return DAG.getNode(ISD::MERGE_VALUES, Tys, Ops, 3); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4314 | } |
| 4315 | |
| 4316 | SDOperand X86TargetLowering::LowerVASTART(SDOperand Op, SelectionDAG &DAG) { |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 4317 | SrcValueSDNode *SV = cast<SrcValueSDNode>(Op.getOperand(2)); |
| 4318 | |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 4319 | if (!Subtarget->is64Bit()) { |
| 4320 | // vastart just stores the address of the VarArgsFrameIndex slot into the |
| 4321 | // memory location argument. |
| 4322 | SDOperand FR = DAG.getFrameIndex(VarArgsFrameIndex, getPointerTy()); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 4323 | return DAG.getStore(Op.getOperand(0), FR,Op.getOperand(1), SV->getValue(), |
| 4324 | SV->getOffset()); |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 4325 | } |
| 4326 | |
| 4327 | // __va_list_tag: |
| 4328 | // gp_offset (0 - 6 * 8) |
| 4329 | // fp_offset (48 - 48 + 8 * 16) |
| 4330 | // overflow_arg_area (point to parameters coming in memory). |
| 4331 | // reg_save_area |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 4332 | SmallVector<SDOperand, 8> MemOps; |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 4333 | SDOperand FIN = Op.getOperand(1); |
| 4334 | // Store gp_offset |
Evan Cheng | 786225a | 2006-10-05 23:01:46 +0000 | [diff] [blame] | 4335 | SDOperand Store = DAG.getStore(Op.getOperand(0), |
| 4336 | DAG.getConstant(VarArgsGPOffset, MVT::i32), |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 4337 | FIN, SV->getValue(), SV->getOffset()); |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 4338 | MemOps.push_back(Store); |
| 4339 | |
| 4340 | // Store fp_offset |
| 4341 | FIN = DAG.getNode(ISD::ADD, getPointerTy(), FIN, |
| 4342 | DAG.getConstant(4, getPointerTy())); |
Evan Cheng | 786225a | 2006-10-05 23:01:46 +0000 | [diff] [blame] | 4343 | Store = DAG.getStore(Op.getOperand(0), |
| 4344 | DAG.getConstant(VarArgsFPOffset, MVT::i32), |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 4345 | FIN, SV->getValue(), SV->getOffset()); |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 4346 | MemOps.push_back(Store); |
| 4347 | |
| 4348 | // Store ptr to overflow_arg_area |
| 4349 | FIN = DAG.getNode(ISD::ADD, getPointerTy(), FIN, |
| 4350 | DAG.getConstant(4, getPointerTy())); |
| 4351 | SDOperand OVFIN = DAG.getFrameIndex(VarArgsFrameIndex, getPointerTy()); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 4352 | Store = DAG.getStore(Op.getOperand(0), OVFIN, FIN, SV->getValue(), |
| 4353 | SV->getOffset()); |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 4354 | MemOps.push_back(Store); |
| 4355 | |
| 4356 | // Store ptr to reg_save_area. |
| 4357 | FIN = DAG.getNode(ISD::ADD, getPointerTy(), FIN, |
| 4358 | DAG.getConstant(8, getPointerTy())); |
| 4359 | SDOperand RSFIN = DAG.getFrameIndex(RegSaveFrameIndex, getPointerTy()); |
Evan Cheng | 8b2794a | 2006-10-13 21:14:26 +0000 | [diff] [blame] | 4360 | Store = DAG.getStore(Op.getOperand(0), RSFIN, FIN, SV->getValue(), |
| 4361 | SV->getOffset()); |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 4362 | MemOps.push_back(Store); |
| 4363 | return DAG.getNode(ISD::TokenFactor, MVT::Other, &MemOps[0], MemOps.size()); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4364 | } |
| 4365 | |
Evan Cheng | ae64219 | 2007-03-02 23:16:35 +0000 | [diff] [blame] | 4366 | SDOperand X86TargetLowering::LowerVACOPY(SDOperand Op, SelectionDAG &DAG) { |
| 4367 | // X86-64 va_list is a struct { i32, i32, i8*, i8* }. |
| 4368 | SDOperand Chain = Op.getOperand(0); |
| 4369 | SDOperand DstPtr = Op.getOperand(1); |
| 4370 | SDOperand SrcPtr = Op.getOperand(2); |
| 4371 | SrcValueSDNode *DstSV = cast<SrcValueSDNode>(Op.getOperand(3)); |
| 4372 | SrcValueSDNode *SrcSV = cast<SrcValueSDNode>(Op.getOperand(4)); |
| 4373 | |
| 4374 | SrcPtr = DAG.getLoad(getPointerTy(), Chain, SrcPtr, |
| 4375 | SrcSV->getValue(), SrcSV->getOffset()); |
| 4376 | Chain = SrcPtr.getValue(1); |
| 4377 | for (unsigned i = 0; i < 3; ++i) { |
| 4378 | SDOperand Val = DAG.getLoad(MVT::i64, Chain, SrcPtr, |
| 4379 | SrcSV->getValue(), SrcSV->getOffset()); |
| 4380 | Chain = Val.getValue(1); |
| 4381 | Chain = DAG.getStore(Chain, Val, DstPtr, |
| 4382 | DstSV->getValue(), DstSV->getOffset()); |
| 4383 | if (i == 2) |
| 4384 | break; |
| 4385 | SrcPtr = DAG.getNode(ISD::ADD, getPointerTy(), SrcPtr, |
| 4386 | DAG.getConstant(8, getPointerTy())); |
| 4387 | DstPtr = DAG.getNode(ISD::ADD, getPointerTy(), DstPtr, |
| 4388 | DAG.getConstant(8, getPointerTy())); |
| 4389 | } |
| 4390 | return Chain; |
| 4391 | } |
| 4392 | |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4393 | SDOperand |
| 4394 | X86TargetLowering::LowerINTRINSIC_WO_CHAIN(SDOperand Op, SelectionDAG &DAG) { |
| 4395 | unsigned IntNo = cast<ConstantSDNode>(Op.getOperand(0))->getValue(); |
| 4396 | switch (IntNo) { |
| 4397 | default: return SDOperand(); // Don't custom lower most intrinsics. |
Evan Cheng | 6be2c58 | 2006-04-05 23:38:46 +0000 | [diff] [blame] | 4398 | // Comparison intrinsics. |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4399 | case Intrinsic::x86_sse_comieq_ss: |
| 4400 | case Intrinsic::x86_sse_comilt_ss: |
| 4401 | case Intrinsic::x86_sse_comile_ss: |
| 4402 | case Intrinsic::x86_sse_comigt_ss: |
| 4403 | case Intrinsic::x86_sse_comige_ss: |
| 4404 | case Intrinsic::x86_sse_comineq_ss: |
| 4405 | case Intrinsic::x86_sse_ucomieq_ss: |
| 4406 | case Intrinsic::x86_sse_ucomilt_ss: |
| 4407 | case Intrinsic::x86_sse_ucomile_ss: |
| 4408 | case Intrinsic::x86_sse_ucomigt_ss: |
| 4409 | case Intrinsic::x86_sse_ucomige_ss: |
| 4410 | case Intrinsic::x86_sse_ucomineq_ss: |
| 4411 | case Intrinsic::x86_sse2_comieq_sd: |
| 4412 | case Intrinsic::x86_sse2_comilt_sd: |
| 4413 | case Intrinsic::x86_sse2_comile_sd: |
| 4414 | case Intrinsic::x86_sse2_comigt_sd: |
| 4415 | case Intrinsic::x86_sse2_comige_sd: |
| 4416 | case Intrinsic::x86_sse2_comineq_sd: |
| 4417 | case Intrinsic::x86_sse2_ucomieq_sd: |
| 4418 | case Intrinsic::x86_sse2_ucomilt_sd: |
| 4419 | case Intrinsic::x86_sse2_ucomile_sd: |
| 4420 | case Intrinsic::x86_sse2_ucomigt_sd: |
| 4421 | case Intrinsic::x86_sse2_ucomige_sd: |
| 4422 | case Intrinsic::x86_sse2_ucomineq_sd: { |
| 4423 | unsigned Opc = 0; |
| 4424 | ISD::CondCode CC = ISD::SETCC_INVALID; |
| 4425 | switch (IntNo) { |
| 4426 | default: break; |
Anton Korobeynikov | 12c49af | 2006-11-21 00:01:06 +0000 | [diff] [blame] | 4427 | case Intrinsic::x86_sse_comieq_ss: |
| 4428 | case Intrinsic::x86_sse2_comieq_sd: |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4429 | Opc = X86ISD::COMI; |
| 4430 | CC = ISD::SETEQ; |
| 4431 | break; |
Evan Cheng | 6be2c58 | 2006-04-05 23:38:46 +0000 | [diff] [blame] | 4432 | case Intrinsic::x86_sse_comilt_ss: |
Evan Cheng | 6be2c58 | 2006-04-05 23:38:46 +0000 | [diff] [blame] | 4433 | case Intrinsic::x86_sse2_comilt_sd: |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4434 | Opc = X86ISD::COMI; |
| 4435 | CC = ISD::SETLT; |
| 4436 | break; |
| 4437 | case Intrinsic::x86_sse_comile_ss: |
Evan Cheng | 6be2c58 | 2006-04-05 23:38:46 +0000 | [diff] [blame] | 4438 | case Intrinsic::x86_sse2_comile_sd: |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4439 | Opc = X86ISD::COMI; |
| 4440 | CC = ISD::SETLE; |
| 4441 | break; |
| 4442 | case Intrinsic::x86_sse_comigt_ss: |
Evan Cheng | 6be2c58 | 2006-04-05 23:38:46 +0000 | [diff] [blame] | 4443 | case Intrinsic::x86_sse2_comigt_sd: |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4444 | Opc = X86ISD::COMI; |
| 4445 | CC = ISD::SETGT; |
| 4446 | break; |
| 4447 | case Intrinsic::x86_sse_comige_ss: |
Evan Cheng | 6be2c58 | 2006-04-05 23:38:46 +0000 | [diff] [blame] | 4448 | case Intrinsic::x86_sse2_comige_sd: |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4449 | Opc = X86ISD::COMI; |
| 4450 | CC = ISD::SETGE; |
| 4451 | break; |
| 4452 | case Intrinsic::x86_sse_comineq_ss: |
Evan Cheng | 6be2c58 | 2006-04-05 23:38:46 +0000 | [diff] [blame] | 4453 | case Intrinsic::x86_sse2_comineq_sd: |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4454 | Opc = X86ISD::COMI; |
| 4455 | CC = ISD::SETNE; |
| 4456 | break; |
| 4457 | case Intrinsic::x86_sse_ucomieq_ss: |
Evan Cheng | 6be2c58 | 2006-04-05 23:38:46 +0000 | [diff] [blame] | 4458 | case Intrinsic::x86_sse2_ucomieq_sd: |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4459 | Opc = X86ISD::UCOMI; |
| 4460 | CC = ISD::SETEQ; |
| 4461 | break; |
| 4462 | case Intrinsic::x86_sse_ucomilt_ss: |
Evan Cheng | 6be2c58 | 2006-04-05 23:38:46 +0000 | [diff] [blame] | 4463 | case Intrinsic::x86_sse2_ucomilt_sd: |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4464 | Opc = X86ISD::UCOMI; |
| 4465 | CC = ISD::SETLT; |
| 4466 | break; |
| 4467 | case Intrinsic::x86_sse_ucomile_ss: |
Evan Cheng | 6be2c58 | 2006-04-05 23:38:46 +0000 | [diff] [blame] | 4468 | case Intrinsic::x86_sse2_ucomile_sd: |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4469 | Opc = X86ISD::UCOMI; |
| 4470 | CC = ISD::SETLE; |
| 4471 | break; |
| 4472 | case Intrinsic::x86_sse_ucomigt_ss: |
Evan Cheng | 6be2c58 | 2006-04-05 23:38:46 +0000 | [diff] [blame] | 4473 | case Intrinsic::x86_sse2_ucomigt_sd: |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4474 | Opc = X86ISD::UCOMI; |
| 4475 | CC = ISD::SETGT; |
| 4476 | break; |
| 4477 | case Intrinsic::x86_sse_ucomige_ss: |
Evan Cheng | 6be2c58 | 2006-04-05 23:38:46 +0000 | [diff] [blame] | 4478 | case Intrinsic::x86_sse2_ucomige_sd: |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4479 | Opc = X86ISD::UCOMI; |
| 4480 | CC = ISD::SETGE; |
| 4481 | break; |
| 4482 | case Intrinsic::x86_sse_ucomineq_ss: |
| 4483 | case Intrinsic::x86_sse2_ucomineq_sd: |
| 4484 | Opc = X86ISD::UCOMI; |
| 4485 | CC = ISD::SETNE; |
| 4486 | break; |
Evan Cheng | 6be2c58 | 2006-04-05 23:38:46 +0000 | [diff] [blame] | 4487 | } |
Evan Cheng | 734503b | 2006-09-11 02:19:56 +0000 | [diff] [blame] | 4488 | |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4489 | unsigned X86CC; |
Chris Lattner | f957051 | 2006-09-13 03:22:10 +0000 | [diff] [blame] | 4490 | SDOperand LHS = Op.getOperand(1); |
| 4491 | SDOperand RHS = Op.getOperand(2); |
| 4492 | translateX86CC(CC, true, X86CC, LHS, RHS, DAG); |
Evan Cheng | 734503b | 2006-09-11 02:19:56 +0000 | [diff] [blame] | 4493 | |
Evan Cheng | 0488db9 | 2007-09-25 01:57:46 +0000 | [diff] [blame] | 4494 | if (NewCCModeling) { |
| 4495 | Opc = (Opc == X86ISD::UCOMI) ? X86ISD::UCOMI_NEW : X86ISD::COMI_NEW; |
| 4496 | SDOperand Cond = DAG.getNode(Opc, MVT::i32, LHS, RHS); |
| 4497 | SDOperand SetCC = DAG.getNode(X86ISD::SETCC_NEW, MVT::i8, |
| 4498 | DAG.getConstant(X86CC, MVT::i8), Cond); |
| 4499 | return DAG.getNode(ISD::ANY_EXTEND, MVT::i32, SetCC); |
| 4500 | } else { |
| 4501 | const MVT::ValueType *VTs = DAG.getNodeValueTypes(MVT::Other, MVT::Flag); |
| 4502 | SDOperand Ops1[] = { DAG.getEntryNode(), LHS, RHS }; |
| 4503 | SDOperand Cond = DAG.getNode(Opc, VTs, 2, Ops1, 3); |
| 4504 | VTs = DAG.getNodeValueTypes(MVT::i8, MVT::Flag); |
| 4505 | SDOperand Ops2[] = { DAG.getConstant(X86CC, MVT::i8), Cond }; |
| 4506 | SDOperand SetCC = DAG.getNode(X86ISD::SETCC, VTs, 2, Ops2, 2); |
| 4507 | return DAG.getNode(ISD::ANY_EXTEND, MVT::i32, SetCC); |
| 4508 | } |
Evan Cheng | 6be2c58 | 2006-04-05 23:38:46 +0000 | [diff] [blame] | 4509 | } |
Evan Cheng | 38bcbaf | 2005-12-23 07:31:11 +0000 | [diff] [blame] | 4510 | } |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 4511 | } |
Evan Cheng | 7226158 | 2005-12-20 06:22:03 +0000 | [diff] [blame] | 4512 | |
Nate Begeman | bcc5f36 | 2007-01-29 22:58:52 +0000 | [diff] [blame] | 4513 | SDOperand X86TargetLowering::LowerRETURNADDR(SDOperand Op, SelectionDAG &DAG) { |
| 4514 | // Depths > 0 not supported yet! |
| 4515 | if (cast<ConstantSDNode>(Op.getOperand(0))->getValue() > 0) |
| 4516 | return SDOperand(); |
| 4517 | |
| 4518 | // Just load the return address |
| 4519 | SDOperand RetAddrFI = getReturnAddressFrameIndex(DAG); |
| 4520 | return DAG.getLoad(getPointerTy(), DAG.getEntryNode(), RetAddrFI, NULL, 0); |
| 4521 | } |
| 4522 | |
| 4523 | SDOperand X86TargetLowering::LowerFRAMEADDR(SDOperand Op, SelectionDAG &DAG) { |
| 4524 | // Depths > 0 not supported yet! |
| 4525 | if (cast<ConstantSDNode>(Op.getOperand(0))->getValue() > 0) |
| 4526 | return SDOperand(); |
| 4527 | |
| 4528 | SDOperand RetAddrFI = getReturnAddressFrameIndex(DAG); |
| 4529 | return DAG.getNode(ISD::SUB, getPointerTy(), RetAddrFI, |
| 4530 | DAG.getConstant(4, getPointerTy())); |
| 4531 | } |
| 4532 | |
Anton Korobeynikov | 2365f51 | 2007-07-14 14:06:15 +0000 | [diff] [blame] | 4533 | SDOperand X86TargetLowering::LowerFRAME_TO_ARGS_OFFSET(SDOperand Op, |
| 4534 | SelectionDAG &DAG) { |
| 4535 | // Is not yet supported on x86-64 |
| 4536 | if (Subtarget->is64Bit()) |
| 4537 | return SDOperand(); |
| 4538 | |
| 4539 | return DAG.getConstant(8, getPointerTy()); |
| 4540 | } |
| 4541 | |
| 4542 | SDOperand X86TargetLowering::LowerEH_RETURN(SDOperand Op, SelectionDAG &DAG) |
| 4543 | { |
| 4544 | assert(!Subtarget->is64Bit() && |
| 4545 | "Lowering of eh_return builtin is not supported yet on x86-64"); |
| 4546 | |
| 4547 | MachineFunction &MF = DAG.getMachineFunction(); |
| 4548 | SDOperand Chain = Op.getOperand(0); |
| 4549 | SDOperand Offset = Op.getOperand(1); |
| 4550 | SDOperand Handler = Op.getOperand(2); |
| 4551 | |
| 4552 | SDOperand Frame = DAG.getRegister(RegInfo->getFrameRegister(MF), |
| 4553 | getPointerTy()); |
| 4554 | |
| 4555 | SDOperand StoreAddr = DAG.getNode(ISD::SUB, getPointerTy(), Frame, |
| 4556 | DAG.getConstant(-4UL, getPointerTy())); |
| 4557 | StoreAddr = DAG.getNode(ISD::ADD, getPointerTy(), StoreAddr, Offset); |
| 4558 | Chain = DAG.getStore(Chain, Handler, StoreAddr, NULL, 0); |
| 4559 | Chain = DAG.getCopyToReg(Chain, X86::ECX, StoreAddr); |
| 4560 | MF.addLiveOut(X86::ECX); |
| 4561 | |
| 4562 | return DAG.getNode(X86ISD::EH_RETURN, MVT::Other, |
| 4563 | Chain, DAG.getRegister(X86::ECX, getPointerTy())); |
| 4564 | } |
| 4565 | |
Duncan Sands | b116fac | 2007-07-27 20:02:49 +0000 | [diff] [blame] | 4566 | SDOperand X86TargetLowering::LowerTRAMPOLINE(SDOperand Op, |
| 4567 | SelectionDAG &DAG) { |
| 4568 | SDOperand Root = Op.getOperand(0); |
| 4569 | SDOperand Trmp = Op.getOperand(1); // trampoline |
| 4570 | SDOperand FPtr = Op.getOperand(2); // nested function |
| 4571 | SDOperand Nest = Op.getOperand(3); // 'nest' parameter value |
| 4572 | |
| 4573 | SrcValueSDNode *TrmpSV = cast<SrcValueSDNode>(Op.getOperand(4)); |
| 4574 | |
| 4575 | if (Subtarget->is64Bit()) { |
| 4576 | return SDOperand(); // not yet supported |
| 4577 | } else { |
| 4578 | Function *Func = (Function *) |
| 4579 | cast<Function>(cast<SrcValueSDNode>(Op.getOperand(5))->getValue()); |
| 4580 | unsigned CC = Func->getCallingConv(); |
Duncan Sands | ee46574 | 2007-08-29 19:01:20 +0000 | [diff] [blame] | 4581 | unsigned NestReg; |
Duncan Sands | b116fac | 2007-07-27 20:02:49 +0000 | [diff] [blame] | 4582 | |
| 4583 | switch (CC) { |
| 4584 | default: |
| 4585 | assert(0 && "Unsupported calling convention"); |
| 4586 | case CallingConv::C: |
| 4587 | case CallingConv::Fast: |
| 4588 | case CallingConv::X86_StdCall: { |
| 4589 | // Pass 'nest' parameter in ECX. |
| 4590 | // Must be kept in sync with X86CallingConv.td |
Duncan Sands | ee46574 | 2007-08-29 19:01:20 +0000 | [diff] [blame] | 4591 | NestReg = X86::ECX; |
Duncan Sands | b116fac | 2007-07-27 20:02:49 +0000 | [diff] [blame] | 4592 | |
| 4593 | // Check that ECX wasn't needed by an 'inreg' parameter. |
| 4594 | const FunctionType *FTy = Func->getFunctionType(); |
| 4595 | const ParamAttrsList *Attrs = FTy->getParamAttrs(); |
| 4596 | |
| 4597 | if (Attrs && !Func->isVarArg()) { |
| 4598 | unsigned InRegCount = 0; |
| 4599 | unsigned Idx = 1; |
| 4600 | |
| 4601 | for (FunctionType::param_iterator I = FTy->param_begin(), |
| 4602 | E = FTy->param_end(); I != E; ++I, ++Idx) |
| 4603 | if (Attrs->paramHasAttr(Idx, ParamAttr::InReg)) |
| 4604 | // FIXME: should only count parameters that are lowered to integers. |
| 4605 | InRegCount += (getTargetData()->getTypeSizeInBits(*I) + 31) / 32; |
| 4606 | |
| 4607 | if (InRegCount > 2) { |
| 4608 | cerr << "Nest register in use - reduce number of inreg parameters!\n"; |
| 4609 | abort(); |
| 4610 | } |
| 4611 | } |
| 4612 | break; |
| 4613 | } |
| 4614 | case CallingConv::X86_FastCall: |
| 4615 | // Pass 'nest' parameter in EAX. |
| 4616 | // Must be kept in sync with X86CallingConv.td |
Duncan Sands | ee46574 | 2007-08-29 19:01:20 +0000 | [diff] [blame] | 4617 | NestReg = X86::EAX; |
Duncan Sands | b116fac | 2007-07-27 20:02:49 +0000 | [diff] [blame] | 4618 | break; |
| 4619 | } |
| 4620 | |
Duncan Sands | ee46574 | 2007-08-29 19:01:20 +0000 | [diff] [blame] | 4621 | const X86InstrInfo *TII = |
| 4622 | ((X86TargetMachine&)getTargetMachine()).getInstrInfo(); |
| 4623 | |
Duncan Sands | b116fac | 2007-07-27 20:02:49 +0000 | [diff] [blame] | 4624 | SDOperand OutChains[4]; |
| 4625 | SDOperand Addr, Disp; |
| 4626 | |
| 4627 | Addr = DAG.getNode(ISD::ADD, MVT::i32, Trmp, DAG.getConstant(10, MVT::i32)); |
| 4628 | Disp = DAG.getNode(ISD::SUB, MVT::i32, FPtr, Addr); |
| 4629 | |
Duncan Sands | ee46574 | 2007-08-29 19:01:20 +0000 | [diff] [blame] | 4630 | unsigned char MOV32ri = TII->getBaseOpcodeFor(X86::MOV32ri); |
| 4631 | unsigned char N86Reg = ((X86RegisterInfo&)RegInfo).getX86RegNum(NestReg); |
| 4632 | OutChains[0] = DAG.getStore(Root, DAG.getConstant(MOV32ri|N86Reg, MVT::i8), |
Duncan Sands | b116fac | 2007-07-27 20:02:49 +0000 | [diff] [blame] | 4633 | Trmp, TrmpSV->getValue(), TrmpSV->getOffset()); |
| 4634 | |
| 4635 | Addr = DAG.getNode(ISD::ADD, MVT::i32, Trmp, DAG.getConstant(1, MVT::i32)); |
| 4636 | OutChains[1] = DAG.getStore(Root, Nest, Addr, TrmpSV->getValue(), |
| 4637 | TrmpSV->getOffset() + 1, false, 1); |
| 4638 | |
Duncan Sands | ee46574 | 2007-08-29 19:01:20 +0000 | [diff] [blame] | 4639 | unsigned char JMP = TII->getBaseOpcodeFor(X86::JMP); |
Duncan Sands | b116fac | 2007-07-27 20:02:49 +0000 | [diff] [blame] | 4640 | Addr = DAG.getNode(ISD::ADD, MVT::i32, Trmp, DAG.getConstant(5, MVT::i32)); |
| 4641 | OutChains[2] = DAG.getStore(Root, DAG.getConstant(JMP, MVT::i8), Addr, |
| 4642 | TrmpSV->getValue() + 5, TrmpSV->getOffset()); |
| 4643 | |
| 4644 | Addr = DAG.getNode(ISD::ADD, MVT::i32, Trmp, DAG.getConstant(6, MVT::i32)); |
| 4645 | OutChains[3] = DAG.getStore(Root, Disp, Addr, TrmpSV->getValue(), |
| 4646 | TrmpSV->getOffset() + 6, false, 1); |
| 4647 | |
Duncan Sands | f7331b3 | 2007-09-11 14:10:23 +0000 | [diff] [blame] | 4648 | SDOperand Ops[] = |
| 4649 | { Trmp, DAG.getNode(ISD::TokenFactor, MVT::Other, OutChains, 4) }; |
| 4650 | return DAG.getNode(ISD::MERGE_VALUES, Op.Val->getVTList(), Ops, 2); |
Duncan Sands | b116fac | 2007-07-27 20:02:49 +0000 | [diff] [blame] | 4651 | } |
| 4652 | } |
| 4653 | |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4654 | /// LowerOperation - Provide custom lowering hooks for some operations. |
| 4655 | /// |
| 4656 | SDOperand X86TargetLowering::LowerOperation(SDOperand Op, SelectionDAG &DAG) { |
| 4657 | switch (Op.getOpcode()) { |
| 4658 | default: assert(0 && "Should not custom lower this!"); |
| 4659 | case ISD::BUILD_VECTOR: return LowerBUILD_VECTOR(Op, DAG); |
| 4660 | case ISD::VECTOR_SHUFFLE: return LowerVECTOR_SHUFFLE(Op, DAG); |
| 4661 | case ISD::EXTRACT_VECTOR_ELT: return LowerEXTRACT_VECTOR_ELT(Op, DAG); |
| 4662 | case ISD::INSERT_VECTOR_ELT: return LowerINSERT_VECTOR_ELT(Op, DAG); |
| 4663 | case ISD::SCALAR_TO_VECTOR: return LowerSCALAR_TO_VECTOR(Op, DAG); |
| 4664 | case ISD::ConstantPool: return LowerConstantPool(Op, DAG); |
| 4665 | case ISD::GlobalAddress: return LowerGlobalAddress(Op, DAG); |
Lauro Ramos Venancio | b3a0417 | 2007-04-20 21:38:10 +0000 | [diff] [blame] | 4666 | case ISD::GlobalTLSAddress: return LowerGlobalTLSAddress(Op, DAG); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4667 | case ISD::ExternalSymbol: return LowerExternalSymbol(Op, DAG); |
| 4668 | case ISD::SHL_PARTS: |
| 4669 | case ISD::SRA_PARTS: |
| 4670 | case ISD::SRL_PARTS: return LowerShift(Op, DAG); |
| 4671 | case ISD::SINT_TO_FP: return LowerSINT_TO_FP(Op, DAG); |
| 4672 | case ISD::FP_TO_SINT: return LowerFP_TO_SINT(Op, DAG); |
| 4673 | case ISD::FABS: return LowerFABS(Op, DAG); |
| 4674 | case ISD::FNEG: return LowerFNEG(Op, DAG); |
Evan Cheng | 68c47cb | 2007-01-05 07:55:56 +0000 | [diff] [blame] | 4675 | case ISD::FCOPYSIGN: return LowerFCOPYSIGN(Op, DAG); |
Evan Cheng | 0488db9 | 2007-09-25 01:57:46 +0000 | [diff] [blame] | 4676 | case ISD::SETCC: return NewCCModeling |
| 4677 | ? LowerSETCC_New(Op, DAG) |
| 4678 | : LowerSETCC(Op, DAG, DAG.getEntryNode()); |
| 4679 | case ISD::SELECT: return NewCCModeling |
| 4680 | ? LowerSELECT_New(Op, DAG) |
| 4681 | : LowerSELECT(Op, DAG); |
| 4682 | case ISD::BRCOND: return NewCCModeling |
| 4683 | ? LowerBRCOND_New(Op, DAG) |
| 4684 | : LowerBRCOND(Op, DAG); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4685 | case ISD::JumpTable: return LowerJumpTable(Op, DAG); |
Evan Cheng | 32fe103 | 2006-05-25 00:59:30 +0000 | [diff] [blame] | 4686 | case ISD::CALL: return LowerCALL(Op, DAG); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4687 | case ISD::RET: return LowerRET(Op, DAG); |
Evan Cheng | 1bc7804 | 2006-04-26 01:20:17 +0000 | [diff] [blame] | 4688 | case ISD::FORMAL_ARGUMENTS: return LowerFORMAL_ARGUMENTS(Op, DAG); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4689 | case ISD::MEMSET: return LowerMEMSET(Op, DAG); |
| 4690 | case ISD::MEMCPY: return LowerMEMCPY(Op, DAG); |
| 4691 | case ISD::READCYCLECOUNTER: return LowerREADCYCLCECOUNTER(Op, DAG); |
| 4692 | case ISD::VASTART: return LowerVASTART(Op, DAG); |
Evan Cheng | ae64219 | 2007-03-02 23:16:35 +0000 | [diff] [blame] | 4693 | case ISD::VACOPY: return LowerVACOPY(Op, DAG); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4694 | case ISD::INTRINSIC_WO_CHAIN: return LowerINTRINSIC_WO_CHAIN(Op, DAG); |
Nate Begeman | bcc5f36 | 2007-01-29 22:58:52 +0000 | [diff] [blame] | 4695 | case ISD::RETURNADDR: return LowerRETURNADDR(Op, DAG); |
| 4696 | case ISD::FRAMEADDR: return LowerFRAMEADDR(Op, DAG); |
Anton Korobeynikov | 2365f51 | 2007-07-14 14:06:15 +0000 | [diff] [blame] | 4697 | case ISD::FRAME_TO_ARGS_OFFSET: |
| 4698 | return LowerFRAME_TO_ARGS_OFFSET(Op, DAG); |
Anton Korobeynikov | 57fc00d | 2007-04-17 09:20:00 +0000 | [diff] [blame] | 4699 | case ISD::DYNAMIC_STACKALLOC: return LowerDYNAMIC_STACKALLOC(Op, DAG); |
Anton Korobeynikov | 2365f51 | 2007-07-14 14:06:15 +0000 | [diff] [blame] | 4700 | case ISD::EH_RETURN: return LowerEH_RETURN(Op, DAG); |
Duncan Sands | b116fac | 2007-07-27 20:02:49 +0000 | [diff] [blame] | 4701 | case ISD::TRAMPOLINE: return LowerTRAMPOLINE(Op, DAG); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4702 | } |
Jim Laskey | 62819f3 | 2007-02-21 22:54:50 +0000 | [diff] [blame] | 4703 | return SDOperand(); |
Evan Cheng | 0db9fe6 | 2006-04-25 20:13:52 +0000 | [diff] [blame] | 4704 | } |
| 4705 | |
Evan Cheng | 7226158 | 2005-12-20 06:22:03 +0000 | [diff] [blame] | 4706 | const char *X86TargetLowering::getTargetNodeName(unsigned Opcode) const { |
| 4707 | switch (Opcode) { |
| 4708 | default: return NULL; |
Evan Cheng | e341316 | 2006-01-09 18:33:28 +0000 | [diff] [blame] | 4709 | case X86ISD::SHLD: return "X86ISD::SHLD"; |
| 4710 | case X86ISD::SHRD: return "X86ISD::SHRD"; |
Evan Cheng | ef6ffb1 | 2006-01-31 03:14:29 +0000 | [diff] [blame] | 4711 | case X86ISD::FAND: return "X86ISD::FAND"; |
Evan Cheng | 68c47cb | 2007-01-05 07:55:56 +0000 | [diff] [blame] | 4712 | case X86ISD::FOR: return "X86ISD::FOR"; |
Evan Cheng | 223547a | 2006-01-31 22:28:30 +0000 | [diff] [blame] | 4713 | case X86ISD::FXOR: return "X86ISD::FXOR"; |
Evan Cheng | 68c47cb | 2007-01-05 07:55:56 +0000 | [diff] [blame] | 4714 | case X86ISD::FSRL: return "X86ISD::FSRL"; |
Evan Cheng | a3195e8 | 2006-01-12 22:54:21 +0000 | [diff] [blame] | 4715 | case X86ISD::FILD: return "X86ISD::FILD"; |
Evan Cheng | e3de85b | 2006-02-04 02:20:30 +0000 | [diff] [blame] | 4716 | case X86ISD::FILD_FLAG: return "X86ISD::FILD_FLAG"; |
Evan Cheng | 7226158 | 2005-12-20 06:22:03 +0000 | [diff] [blame] | 4717 | case X86ISD::FP_TO_INT16_IN_MEM: return "X86ISD::FP_TO_INT16_IN_MEM"; |
| 4718 | case X86ISD::FP_TO_INT32_IN_MEM: return "X86ISD::FP_TO_INT32_IN_MEM"; |
| 4719 | case X86ISD::FP_TO_INT64_IN_MEM: return "X86ISD::FP_TO_INT64_IN_MEM"; |
Evan Cheng | b077b84 | 2005-12-21 02:39:21 +0000 | [diff] [blame] | 4720 | case X86ISD::FLD: return "X86ISD::FLD"; |
Evan Cheng | d90eb7f | 2006-01-05 00:27:02 +0000 | [diff] [blame] | 4721 | case X86ISD::FST: return "X86ISD::FST"; |
| 4722 | case X86ISD::FP_GET_RESULT: return "X86ISD::FP_GET_RESULT"; |
Evan Cheng | b077b84 | 2005-12-21 02:39:21 +0000 | [diff] [blame] | 4723 | case X86ISD::FP_SET_RESULT: return "X86ISD::FP_SET_RESULT"; |
Evan Cheng | 7226158 | 2005-12-20 06:22:03 +0000 | [diff] [blame] | 4724 | case X86ISD::CALL: return "X86ISD::CALL"; |
| 4725 | case X86ISD::TAILCALL: return "X86ISD::TAILCALL"; |
| 4726 | case X86ISD::RDTSC_DAG: return "X86ISD::RDTSC_DAG"; |
| 4727 | case X86ISD::CMP: return "X86ISD::CMP"; |
Evan Cheng | 0488db9 | 2007-09-25 01:57:46 +0000 | [diff] [blame] | 4728 | case X86ISD::CMP_NEW: return "X86ISD::CMP_NEW"; |
Evan Cheng | 6be2c58 | 2006-04-05 23:38:46 +0000 | [diff] [blame] | 4729 | case X86ISD::COMI: return "X86ISD::COMI"; |
Evan Cheng | 0488db9 | 2007-09-25 01:57:46 +0000 | [diff] [blame] | 4730 | case X86ISD::COMI_NEW: return "X86ISD::COMI_NEW"; |
Evan Cheng | 6be2c58 | 2006-04-05 23:38:46 +0000 | [diff] [blame] | 4731 | case X86ISD::UCOMI: return "X86ISD::UCOMI"; |
Evan Cheng | 0488db9 | 2007-09-25 01:57:46 +0000 | [diff] [blame] | 4732 | case X86ISD::UCOMI_NEW: return "X86ISD::UCOMI_NEW"; |
Evan Cheng | d5781fc | 2005-12-21 20:21:51 +0000 | [diff] [blame] | 4733 | case X86ISD::SETCC: return "X86ISD::SETCC"; |
Evan Cheng | 0488db9 | 2007-09-25 01:57:46 +0000 | [diff] [blame] | 4734 | case X86ISD::SETCC_NEW: return "X86ISD::SETCC_NEW"; |
Evan Cheng | 7226158 | 2005-12-20 06:22:03 +0000 | [diff] [blame] | 4735 | case X86ISD::CMOV: return "X86ISD::CMOV"; |
Evan Cheng | 0488db9 | 2007-09-25 01:57:46 +0000 | [diff] [blame] | 4736 | case X86ISD::CMOV_NEW: return "X86ISD::CMOV_NEW"; |
Evan Cheng | 7226158 | 2005-12-20 06:22:03 +0000 | [diff] [blame] | 4737 | case X86ISD::BRCOND: return "X86ISD::BRCOND"; |
Evan Cheng | 0488db9 | 2007-09-25 01:57:46 +0000 | [diff] [blame] | 4738 | case X86ISD::BRCOND_NEW: return "X86ISD::BRCOND_NEW"; |
Evan Cheng | b077b84 | 2005-12-21 02:39:21 +0000 | [diff] [blame] | 4739 | case X86ISD::RET_FLAG: return "X86ISD::RET_FLAG"; |
Evan Cheng | 8df346b | 2006-03-04 01:12:00 +0000 | [diff] [blame] | 4740 | case X86ISD::REP_STOS: return "X86ISD::REP_STOS"; |
| 4741 | case X86ISD::REP_MOVS: return "X86ISD::REP_MOVS"; |
Evan Cheng | 7ccced6 | 2006-02-18 00:15:05 +0000 | [diff] [blame] | 4742 | case X86ISD::GlobalBaseReg: return "X86ISD::GlobalBaseReg"; |
Evan Cheng | 020d2e8 | 2006-02-23 20:41:18 +0000 | [diff] [blame] | 4743 | case X86ISD::Wrapper: return "X86ISD::Wrapper"; |
Evan Cheng | bc4832b | 2006-03-24 23:15:12 +0000 | [diff] [blame] | 4744 | case X86ISD::S2VEC: return "X86ISD::S2VEC"; |
Evan Cheng | b067a1e | 2006-03-31 19:22:53 +0000 | [diff] [blame] | 4745 | case X86ISD::PEXTRW: return "X86ISD::PEXTRW"; |
Evan Cheng | 653159f | 2006-03-31 21:55:24 +0000 | [diff] [blame] | 4746 | case X86ISD::PINSRW: return "X86ISD::PINSRW"; |
Evan Cheng | 8ca2932 | 2006-11-10 21:43:37 +0000 | [diff] [blame] | 4747 | case X86ISD::FMAX: return "X86ISD::FMAX"; |
| 4748 | case X86ISD::FMIN: return "X86ISD::FMIN"; |
Dan Gohman | 2038252 | 2007-07-10 00:05:58 +0000 | [diff] [blame] | 4749 | case X86ISD::FRSQRT: return "X86ISD::FRSQRT"; |
| 4750 | case X86ISD::FRCP: return "X86ISD::FRCP"; |
Lauro Ramos Venancio | b3a0417 | 2007-04-20 21:38:10 +0000 | [diff] [blame] | 4751 | case X86ISD::TLSADDR: return "X86ISD::TLSADDR"; |
| 4752 | case X86ISD::THREAD_POINTER: return "X86ISD::THREAD_POINTER"; |
Anton Korobeynikov | 2365f51 | 2007-07-14 14:06:15 +0000 | [diff] [blame] | 4753 | case X86ISD::EH_RETURN: return "X86ISD::EH_RETURN"; |
Evan Cheng | 7226158 | 2005-12-20 06:22:03 +0000 | [diff] [blame] | 4754 | } |
| 4755 | } |
Evan Cheng | 3a03ebb | 2005-12-21 23:05:39 +0000 | [diff] [blame] | 4756 | |
Chris Lattner | c9addb7 | 2007-03-30 23:15:24 +0000 | [diff] [blame] | 4757 | // isLegalAddressingMode - Return true if the addressing mode represented |
| 4758 | // by AM is legal for this target, for a load/store of the specified type. |
| 4759 | bool X86TargetLowering::isLegalAddressingMode(const AddrMode &AM, |
| 4760 | const Type *Ty) const { |
| 4761 | // X86 supports extremely general addressing modes. |
| 4762 | |
| 4763 | // X86 allows a sign-extended 32-bit immediate field as a displacement. |
| 4764 | if (AM.BaseOffs <= -(1LL << 32) || AM.BaseOffs >= (1LL << 32)-1) |
| 4765 | return false; |
| 4766 | |
| 4767 | if (AM.BaseGV) { |
Evan Cheng | 5278784 | 2007-08-01 23:46:47 +0000 | [diff] [blame] | 4768 | // We can only fold this if we don't need an extra load. |
Chris Lattner | c9addb7 | 2007-03-30 23:15:24 +0000 | [diff] [blame] | 4769 | if (Subtarget->GVRequiresExtraLoad(AM.BaseGV, getTargetMachine(), false)) |
| 4770 | return false; |
Evan Cheng | 5278784 | 2007-08-01 23:46:47 +0000 | [diff] [blame] | 4771 | |
| 4772 | // X86-64 only supports addr of globals in small code model. |
| 4773 | if (Subtarget->is64Bit()) { |
| 4774 | if (getTargetMachine().getCodeModel() != CodeModel::Small) |
| 4775 | return false; |
| 4776 | // If lower 4G is not available, then we must use rip-relative addressing. |
| 4777 | if (AM.BaseOffs || AM.Scale > 1) |
| 4778 | return false; |
| 4779 | } |
Chris Lattner | c9addb7 | 2007-03-30 23:15:24 +0000 | [diff] [blame] | 4780 | } |
| 4781 | |
| 4782 | switch (AM.Scale) { |
| 4783 | case 0: |
| 4784 | case 1: |
| 4785 | case 2: |
| 4786 | case 4: |
| 4787 | case 8: |
| 4788 | // These scales always work. |
| 4789 | break; |
| 4790 | case 3: |
| 4791 | case 5: |
| 4792 | case 9: |
| 4793 | // These scales are formed with basereg+scalereg. Only accept if there is |
| 4794 | // no basereg yet. |
| 4795 | if (AM.HasBaseReg) |
| 4796 | return false; |
| 4797 | break; |
| 4798 | default: // Other stuff never works. |
| 4799 | return false; |
| 4800 | } |
| 4801 | |
| 4802 | return true; |
| 4803 | } |
| 4804 | |
| 4805 | |
Evan Cheng | 60c07e1 | 2006-07-05 22:17:51 +0000 | [diff] [blame] | 4806 | /// isShuffleMaskLegal - Targets can use this to indicate that they only |
| 4807 | /// support *some* VECTOR_SHUFFLE operations, those with specific masks. |
| 4808 | /// By default, if a target supports the VECTOR_SHUFFLE node, all mask values |
| 4809 | /// are assumed to be legal. |
| 4810 | bool |
| 4811 | X86TargetLowering::isShuffleMaskLegal(SDOperand Mask, MVT::ValueType VT) const { |
| 4812 | // Only do shuffles on 128-bit vector types for now. |
| 4813 | if (MVT::getSizeInBits(VT) == 64) return false; |
| 4814 | return (Mask.Val->getNumOperands() <= 4 || |
Evan Cheng | 49892af | 2007-06-19 00:02:56 +0000 | [diff] [blame] | 4815 | isIdentityMask(Mask.Val) || |
| 4816 | isIdentityMask(Mask.Val, true) || |
Evan Cheng | 60c07e1 | 2006-07-05 22:17:51 +0000 | [diff] [blame] | 4817 | isSplatMask(Mask.Val) || |
| 4818 | isPSHUFHW_PSHUFLWMask(Mask.Val) || |
| 4819 | X86::isUNPCKLMask(Mask.Val) || |
Evan Cheng | 49892af | 2007-06-19 00:02:56 +0000 | [diff] [blame] | 4820 | X86::isUNPCKHMask(Mask.Val) || |
Evan Cheng | 60c07e1 | 2006-07-05 22:17:51 +0000 | [diff] [blame] | 4821 | X86::isUNPCKL_v_undef_Mask(Mask.Val) || |
Evan Cheng | 49892af | 2007-06-19 00:02:56 +0000 | [diff] [blame] | 4822 | X86::isUNPCKH_v_undef_Mask(Mask.Val)); |
Evan Cheng | 60c07e1 | 2006-07-05 22:17:51 +0000 | [diff] [blame] | 4823 | } |
| 4824 | |
| 4825 | bool X86TargetLowering::isVectorClearMaskLegal(std::vector<SDOperand> &BVOps, |
| 4826 | MVT::ValueType EVT, |
| 4827 | SelectionDAG &DAG) const { |
| 4828 | unsigned NumElts = BVOps.size(); |
| 4829 | // Only do shuffles on 128-bit vector types for now. |
| 4830 | if (MVT::getSizeInBits(EVT) * NumElts == 64) return false; |
| 4831 | if (NumElts == 2) return true; |
| 4832 | if (NumElts == 4) { |
Chris Lattner | 5a88b83 | 2007-02-25 07:10:00 +0000 | [diff] [blame] | 4833 | return (isMOVLMask(&BVOps[0], 4) || |
| 4834 | isCommutedMOVL(&BVOps[0], 4, true) || |
| 4835 | isSHUFPMask(&BVOps[0], 4) || |
| 4836 | isCommutedSHUFP(&BVOps[0], 4)); |
Evan Cheng | 60c07e1 | 2006-07-05 22:17:51 +0000 | [diff] [blame] | 4837 | } |
| 4838 | return false; |
| 4839 | } |
| 4840 | |
| 4841 | //===----------------------------------------------------------------------===// |
| 4842 | // X86 Scheduler Hooks |
| 4843 | //===----------------------------------------------------------------------===// |
| 4844 | |
| 4845 | MachineBasicBlock * |
| 4846 | X86TargetLowering::InsertAtEndOfBasicBlock(MachineInstr *MI, |
| 4847 | MachineBasicBlock *BB) { |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 4848 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
Evan Cheng | 60c07e1 | 2006-07-05 22:17:51 +0000 | [diff] [blame] | 4849 | switch (MI->getOpcode()) { |
| 4850 | default: assert(false && "Unexpected instr type to insert"); |
| 4851 | case X86::CMOV_FR32: |
| 4852 | case X86::CMOV_FR64: |
| 4853 | case X86::CMOV_V4F32: |
| 4854 | case X86::CMOV_V2F64: |
Evan Cheng | 0488db9 | 2007-09-25 01:57:46 +0000 | [diff] [blame] | 4855 | case X86::CMOV_V2I64: |
| 4856 | |
| 4857 | case X86::NEW_CMOV_FR32: |
| 4858 | case X86::NEW_CMOV_FR64: |
| 4859 | case X86::NEW_CMOV_V4F32: |
| 4860 | case X86::NEW_CMOV_V2F64: |
| 4861 | case X86::NEW_CMOV_V2I64: { |
Evan Cheng | 60c07e1 | 2006-07-05 22:17:51 +0000 | [diff] [blame] | 4862 | // To "insert" a SELECT_CC instruction, we actually have to insert the |
| 4863 | // diamond control-flow pattern. The incoming instruction knows the |
| 4864 | // destination vreg to set, the condition code register to branch on, the |
| 4865 | // true/false values to select between, and a branch opcode to use. |
| 4866 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 4867 | ilist<MachineBasicBlock>::iterator It = BB; |
| 4868 | ++It; |
Anton Korobeynikov | 12c49af | 2006-11-21 00:01:06 +0000 | [diff] [blame] | 4869 | |
Evan Cheng | 60c07e1 | 2006-07-05 22:17:51 +0000 | [diff] [blame] | 4870 | // thisMBB: |
| 4871 | // ... |
| 4872 | // TrueVal = ... |
| 4873 | // cmpTY ccX, r1, r2 |
| 4874 | // bCC copy1MBB |
| 4875 | // fallthrough --> copy0MBB |
| 4876 | MachineBasicBlock *thisMBB = BB; |
| 4877 | MachineBasicBlock *copy0MBB = new MachineBasicBlock(LLVM_BB); |
| 4878 | MachineBasicBlock *sinkMBB = new MachineBasicBlock(LLVM_BB); |
Anton Korobeynikov | 12c49af | 2006-11-21 00:01:06 +0000 | [diff] [blame] | 4879 | unsigned Opc = |
Chris Lattner | 7fbe972 | 2006-10-20 17:42:20 +0000 | [diff] [blame] | 4880 | X86::GetCondBranchFromCond((X86::CondCode)MI->getOperand(3).getImm()); |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 4881 | BuildMI(BB, TII->get(Opc)).addMBB(sinkMBB); |
Evan Cheng | 60c07e1 | 2006-07-05 22:17:51 +0000 | [diff] [blame] | 4882 | MachineFunction *F = BB->getParent(); |
| 4883 | F->getBasicBlockList().insert(It, copy0MBB); |
| 4884 | F->getBasicBlockList().insert(It, sinkMBB); |
| 4885 | // Update machine-CFG edges by first adding all successors of the current |
| 4886 | // block to the new block which will contain the Phi node for the select. |
Anton Korobeynikov | 12c49af | 2006-11-21 00:01:06 +0000 | [diff] [blame] | 4887 | for(MachineBasicBlock::succ_iterator i = BB->succ_begin(), |
Evan Cheng | 60c07e1 | 2006-07-05 22:17:51 +0000 | [diff] [blame] | 4888 | e = BB->succ_end(); i != e; ++i) |
| 4889 | sinkMBB->addSuccessor(*i); |
| 4890 | // Next, remove all successors of the current block, and add the true |
| 4891 | // and fallthrough blocks as its successors. |
| 4892 | while(!BB->succ_empty()) |
| 4893 | BB->removeSuccessor(BB->succ_begin()); |
| 4894 | BB->addSuccessor(copy0MBB); |
| 4895 | BB->addSuccessor(sinkMBB); |
Anton Korobeynikov | 12c49af | 2006-11-21 00:01:06 +0000 | [diff] [blame] | 4896 | |
Evan Cheng | 60c07e1 | 2006-07-05 22:17:51 +0000 | [diff] [blame] | 4897 | // copy0MBB: |
| 4898 | // %FalseValue = ... |
| 4899 | // # fallthrough to sinkMBB |
| 4900 | BB = copy0MBB; |
Anton Korobeynikov | 12c49af | 2006-11-21 00:01:06 +0000 | [diff] [blame] | 4901 | |
Evan Cheng | 60c07e1 | 2006-07-05 22:17:51 +0000 | [diff] [blame] | 4902 | // Update machine-CFG edges |
| 4903 | BB->addSuccessor(sinkMBB); |
Anton Korobeynikov | 12c49af | 2006-11-21 00:01:06 +0000 | [diff] [blame] | 4904 | |
Evan Cheng | 60c07e1 | 2006-07-05 22:17:51 +0000 | [diff] [blame] | 4905 | // sinkMBB: |
| 4906 | // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ] |
| 4907 | // ... |
| 4908 | BB = sinkMBB; |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 4909 | BuildMI(BB, TII->get(X86::PHI), MI->getOperand(0).getReg()) |
Evan Cheng | 60c07e1 | 2006-07-05 22:17:51 +0000 | [diff] [blame] | 4910 | .addReg(MI->getOperand(1).getReg()).addMBB(copy0MBB) |
| 4911 | .addReg(MI->getOperand(2).getReg()).addMBB(thisMBB); |
| 4912 | |
| 4913 | delete MI; // The pseudo instruction is gone now. |
| 4914 | return BB; |
| 4915 | } |
| 4916 | |
Dale Johannesen | 849f214 | 2007-07-03 00:53:03 +0000 | [diff] [blame] | 4917 | case X86::FP32_TO_INT16_IN_MEM: |
| 4918 | case X86::FP32_TO_INT32_IN_MEM: |
| 4919 | case X86::FP32_TO_INT64_IN_MEM: |
| 4920 | case X86::FP64_TO_INT16_IN_MEM: |
| 4921 | case X86::FP64_TO_INT32_IN_MEM: |
Dale Johannesen | a996d52 | 2007-08-07 01:17:37 +0000 | [diff] [blame] | 4922 | case X86::FP64_TO_INT64_IN_MEM: |
| 4923 | case X86::FP80_TO_INT16_IN_MEM: |
| 4924 | case X86::FP80_TO_INT32_IN_MEM: |
| 4925 | case X86::FP80_TO_INT64_IN_MEM: { |
Evan Cheng | 60c07e1 | 2006-07-05 22:17:51 +0000 | [diff] [blame] | 4926 | // Change the floating point control register to use "round towards zero" |
| 4927 | // mode when truncating to an integer value. |
| 4928 | MachineFunction *F = BB->getParent(); |
| 4929 | int CWFrameIdx = F->getFrameInfo()->CreateStackObject(2, 2); |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 4930 | addFrameReference(BuildMI(BB, TII->get(X86::FNSTCW16m)), CWFrameIdx); |
Evan Cheng | 60c07e1 | 2006-07-05 22:17:51 +0000 | [diff] [blame] | 4931 | |
| 4932 | // Load the old value of the high byte of the control word... |
| 4933 | unsigned OldCW = |
| 4934 | F->getSSARegMap()->createVirtualRegister(X86::GR16RegisterClass); |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 4935 | addFrameReference(BuildMI(BB, TII->get(X86::MOV16rm), OldCW), CWFrameIdx); |
Evan Cheng | 60c07e1 | 2006-07-05 22:17:51 +0000 | [diff] [blame] | 4936 | |
| 4937 | // Set the high part to be round to zero... |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 4938 | addFrameReference(BuildMI(BB, TII->get(X86::MOV16mi)), CWFrameIdx) |
| 4939 | .addImm(0xC7F); |
Evan Cheng | 60c07e1 | 2006-07-05 22:17:51 +0000 | [diff] [blame] | 4940 | |
| 4941 | // Reload the modified control word now... |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 4942 | addFrameReference(BuildMI(BB, TII->get(X86::FLDCW16m)), CWFrameIdx); |
Evan Cheng | 60c07e1 | 2006-07-05 22:17:51 +0000 | [diff] [blame] | 4943 | |
| 4944 | // Restore the memory image of control word to original value |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 4945 | addFrameReference(BuildMI(BB, TII->get(X86::MOV16mr)), CWFrameIdx) |
| 4946 | .addReg(OldCW); |
Evan Cheng | 60c07e1 | 2006-07-05 22:17:51 +0000 | [diff] [blame] | 4947 | |
| 4948 | // Get the X86 opcode to use. |
| 4949 | unsigned Opc; |
| 4950 | switch (MI->getOpcode()) { |
| 4951 | default: assert(0 && "illegal opcode!"); |
Dale Johannesen | e377d4d | 2007-07-04 21:07:47 +0000 | [diff] [blame] | 4952 | case X86::FP32_TO_INT16_IN_MEM: Opc = X86::IST_Fp16m32; break; |
| 4953 | case X86::FP32_TO_INT32_IN_MEM: Opc = X86::IST_Fp32m32; break; |
| 4954 | case X86::FP32_TO_INT64_IN_MEM: Opc = X86::IST_Fp64m32; break; |
| 4955 | case X86::FP64_TO_INT16_IN_MEM: Opc = X86::IST_Fp16m64; break; |
| 4956 | case X86::FP64_TO_INT32_IN_MEM: Opc = X86::IST_Fp32m64; break; |
| 4957 | case X86::FP64_TO_INT64_IN_MEM: Opc = X86::IST_Fp64m64; break; |
Dale Johannesen | a996d52 | 2007-08-07 01:17:37 +0000 | [diff] [blame] | 4958 | case X86::FP80_TO_INT16_IN_MEM: Opc = X86::IST_Fp16m80; break; |
| 4959 | case X86::FP80_TO_INT32_IN_MEM: Opc = X86::IST_Fp32m80; break; |
| 4960 | case X86::FP80_TO_INT64_IN_MEM: Opc = X86::IST_Fp64m80; break; |
Evan Cheng | 60c07e1 | 2006-07-05 22:17:51 +0000 | [diff] [blame] | 4961 | } |
| 4962 | |
| 4963 | X86AddressMode AM; |
| 4964 | MachineOperand &Op = MI->getOperand(0); |
| 4965 | if (Op.isRegister()) { |
| 4966 | AM.BaseType = X86AddressMode::RegBase; |
| 4967 | AM.Base.Reg = Op.getReg(); |
| 4968 | } else { |
| 4969 | AM.BaseType = X86AddressMode::FrameIndexBase; |
| 4970 | AM.Base.FrameIndex = Op.getFrameIndex(); |
| 4971 | } |
| 4972 | Op = MI->getOperand(1); |
| 4973 | if (Op.isImmediate()) |
Chris Lattner | 7fbe972 | 2006-10-20 17:42:20 +0000 | [diff] [blame] | 4974 | AM.Scale = Op.getImm(); |
Evan Cheng | 60c07e1 | 2006-07-05 22:17:51 +0000 | [diff] [blame] | 4975 | Op = MI->getOperand(2); |
| 4976 | if (Op.isImmediate()) |
Chris Lattner | 7fbe972 | 2006-10-20 17:42:20 +0000 | [diff] [blame] | 4977 | AM.IndexReg = Op.getImm(); |
Evan Cheng | 60c07e1 | 2006-07-05 22:17:51 +0000 | [diff] [blame] | 4978 | Op = MI->getOperand(3); |
| 4979 | if (Op.isGlobalAddress()) { |
| 4980 | AM.GV = Op.getGlobal(); |
| 4981 | } else { |
Chris Lattner | 7fbe972 | 2006-10-20 17:42:20 +0000 | [diff] [blame] | 4982 | AM.Disp = Op.getImm(); |
Evan Cheng | 60c07e1 | 2006-07-05 22:17:51 +0000 | [diff] [blame] | 4983 | } |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 4984 | addFullAddress(BuildMI(BB, TII->get(Opc)), AM) |
| 4985 | .addReg(MI->getOperand(4).getReg()); |
Evan Cheng | 60c07e1 | 2006-07-05 22:17:51 +0000 | [diff] [blame] | 4986 | |
| 4987 | // Reload the original control word now. |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 4988 | addFrameReference(BuildMI(BB, TII->get(X86::FLDCW16m)), CWFrameIdx); |
Evan Cheng | 60c07e1 | 2006-07-05 22:17:51 +0000 | [diff] [blame] | 4989 | |
| 4990 | delete MI; // The pseudo instruction is gone now. |
| 4991 | return BB; |
| 4992 | } |
| 4993 | } |
| 4994 | } |
| 4995 | |
| 4996 | //===----------------------------------------------------------------------===// |
| 4997 | // X86 Optimization Hooks |
| 4998 | //===----------------------------------------------------------------------===// |
| 4999 | |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 5000 | void X86TargetLowering::computeMaskedBitsForTargetNode(const SDOperand Op, |
| 5001 | uint64_t Mask, |
Anton Korobeynikov | 12c49af | 2006-11-21 00:01:06 +0000 | [diff] [blame] | 5002 | uint64_t &KnownZero, |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 5003 | uint64_t &KnownOne, |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 5004 | const SelectionDAG &DAG, |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 5005 | unsigned Depth) const { |
Evan Cheng | 3a03ebb | 2005-12-21 23:05:39 +0000 | [diff] [blame] | 5006 | unsigned Opc = Op.getOpcode(); |
Evan Cheng | 865f060 | 2006-04-05 06:11:20 +0000 | [diff] [blame] | 5007 | assert((Opc >= ISD::BUILTIN_OP_END || |
| 5008 | Opc == ISD::INTRINSIC_WO_CHAIN || |
| 5009 | Opc == ISD::INTRINSIC_W_CHAIN || |
| 5010 | Opc == ISD::INTRINSIC_VOID) && |
| 5011 | "Should use MaskedValueIsZero if you don't know whether Op" |
| 5012 | " is a target node!"); |
Evan Cheng | 3a03ebb | 2005-12-21 23:05:39 +0000 | [diff] [blame] | 5013 | |
Evan Cheng | 865f060 | 2006-04-05 06:11:20 +0000 | [diff] [blame] | 5014 | KnownZero = KnownOne = 0; // Don't know anything. |
Evan Cheng | 3a03ebb | 2005-12-21 23:05:39 +0000 | [diff] [blame] | 5015 | switch (Opc) { |
Evan Cheng | 865f060 | 2006-04-05 06:11:20 +0000 | [diff] [blame] | 5016 | default: break; |
Anton Korobeynikov | 12c49af | 2006-11-21 00:01:06 +0000 | [diff] [blame] | 5017 | case X86ISD::SETCC: |
Evan Cheng | 0488db9 | 2007-09-25 01:57:46 +0000 | [diff] [blame] | 5018 | case X86ISD::SETCC_NEW: |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 5019 | KnownZero |= (MVT::getIntVTBitMask(Op.getValueType()) ^ 1ULL); |
| 5020 | break; |
Evan Cheng | 3a03ebb | 2005-12-21 23:05:39 +0000 | [diff] [blame] | 5021 | } |
Evan Cheng | 3a03ebb | 2005-12-21 23:05:39 +0000 | [diff] [blame] | 5022 | } |
Chris Lattner | 259e97c | 2006-01-31 19:43:35 +0000 | [diff] [blame] | 5023 | |
Evan Cheng | 206ee9d | 2006-07-07 08:33:52 +0000 | [diff] [blame] | 5024 | /// getShuffleScalarElt - Returns the scalar element that will make up the ith |
| 5025 | /// element of the result of the vector shuffle. |
| 5026 | static SDOperand getShuffleScalarElt(SDNode *N, unsigned i, SelectionDAG &DAG) { |
| 5027 | MVT::ValueType VT = N->getValueType(0); |
| 5028 | SDOperand PermMask = N->getOperand(2); |
| 5029 | unsigned NumElems = PermMask.getNumOperands(); |
| 5030 | SDOperand V = (i < NumElems) ? N->getOperand(0) : N->getOperand(1); |
| 5031 | i %= NumElems; |
| 5032 | if (V.getOpcode() == ISD::SCALAR_TO_VECTOR) { |
| 5033 | return (i == 0) |
Dan Gohman | 51eaa86 | 2007-06-14 22:58:02 +0000 | [diff] [blame] | 5034 | ? V.getOperand(0) : DAG.getNode(ISD::UNDEF, MVT::getVectorElementType(VT)); |
Evan Cheng | 206ee9d | 2006-07-07 08:33:52 +0000 | [diff] [blame] | 5035 | } else if (V.getOpcode() == ISD::VECTOR_SHUFFLE) { |
| 5036 | SDOperand Idx = PermMask.getOperand(i); |
| 5037 | if (Idx.getOpcode() == ISD::UNDEF) |
Dan Gohman | 51eaa86 | 2007-06-14 22:58:02 +0000 | [diff] [blame] | 5038 | return DAG.getNode(ISD::UNDEF, MVT::getVectorElementType(VT)); |
Evan Cheng | 206ee9d | 2006-07-07 08:33:52 +0000 | [diff] [blame] | 5039 | return getShuffleScalarElt(V.Val,cast<ConstantSDNode>(Idx)->getValue(),DAG); |
| 5040 | } |
| 5041 | return SDOperand(); |
| 5042 | } |
| 5043 | |
| 5044 | /// isGAPlusOffset - Returns true (and the GlobalValue and the offset) if the |
| 5045 | /// node is a GlobalAddress + an offset. |
| 5046 | static bool isGAPlusOffset(SDNode *N, GlobalValue* &GA, int64_t &Offset) { |
Evan Cheng | 0085a28 | 2006-11-30 21:55:46 +0000 | [diff] [blame] | 5047 | unsigned Opc = N->getOpcode(); |
Evan Cheng | 19f2ffc | 2006-12-05 04:01:03 +0000 | [diff] [blame] | 5048 | if (Opc == X86ISD::Wrapper) { |
Evan Cheng | 206ee9d | 2006-07-07 08:33:52 +0000 | [diff] [blame] | 5049 | if (dyn_cast<GlobalAddressSDNode>(N->getOperand(0))) { |
| 5050 | GA = cast<GlobalAddressSDNode>(N->getOperand(0))->getGlobal(); |
| 5051 | return true; |
| 5052 | } |
Evan Cheng | 0085a28 | 2006-11-30 21:55:46 +0000 | [diff] [blame] | 5053 | } else if (Opc == ISD::ADD) { |
Evan Cheng | 206ee9d | 2006-07-07 08:33:52 +0000 | [diff] [blame] | 5054 | SDOperand N1 = N->getOperand(0); |
| 5055 | SDOperand N2 = N->getOperand(1); |
| 5056 | if (isGAPlusOffset(N1.Val, GA, Offset)) { |
| 5057 | ConstantSDNode *V = dyn_cast<ConstantSDNode>(N2); |
| 5058 | if (V) { |
| 5059 | Offset += V->getSignExtended(); |
| 5060 | return true; |
| 5061 | } |
| 5062 | } else if (isGAPlusOffset(N2.Val, GA, Offset)) { |
| 5063 | ConstantSDNode *V = dyn_cast<ConstantSDNode>(N1); |
| 5064 | if (V) { |
| 5065 | Offset += V->getSignExtended(); |
| 5066 | return true; |
| 5067 | } |
| 5068 | } |
| 5069 | } |
| 5070 | return false; |
| 5071 | } |
| 5072 | |
| 5073 | /// isConsecutiveLoad - Returns true if N is loading from an address of Base |
| 5074 | /// + Dist * Size. |
| 5075 | static bool isConsecutiveLoad(SDNode *N, SDNode *Base, int Dist, int Size, |
| 5076 | MachineFrameInfo *MFI) { |
| 5077 | if (N->getOperand(0).Val != Base->getOperand(0).Val) |
| 5078 | return false; |
| 5079 | |
| 5080 | SDOperand Loc = N->getOperand(1); |
| 5081 | SDOperand BaseLoc = Base->getOperand(1); |
| 5082 | if (Loc.getOpcode() == ISD::FrameIndex) { |
| 5083 | if (BaseLoc.getOpcode() != ISD::FrameIndex) |
| 5084 | return false; |
Dan Gohman | 275769a | 2007-07-23 20:24:29 +0000 | [diff] [blame] | 5085 | int FI = cast<FrameIndexSDNode>(Loc)->getIndex(); |
| 5086 | int BFI = cast<FrameIndexSDNode>(BaseLoc)->getIndex(); |
Evan Cheng | 206ee9d | 2006-07-07 08:33:52 +0000 | [diff] [blame] | 5087 | int FS = MFI->getObjectSize(FI); |
| 5088 | int BFS = MFI->getObjectSize(BFI); |
| 5089 | if (FS != BFS || FS != Size) return false; |
| 5090 | return MFI->getObjectOffset(FI) == (MFI->getObjectOffset(BFI) + Dist*Size); |
| 5091 | } else { |
| 5092 | GlobalValue *GV1 = NULL; |
| 5093 | GlobalValue *GV2 = NULL; |
| 5094 | int64_t Offset1 = 0; |
| 5095 | int64_t Offset2 = 0; |
| 5096 | bool isGA1 = isGAPlusOffset(Loc.Val, GV1, Offset1); |
| 5097 | bool isGA2 = isGAPlusOffset(BaseLoc.Val, GV2, Offset2); |
| 5098 | if (isGA1 && isGA2 && GV1 == GV2) |
| 5099 | return Offset1 == (Offset2 + Dist*Size); |
| 5100 | } |
| 5101 | |
| 5102 | return false; |
| 5103 | } |
| 5104 | |
Evan Cheng | 1e60c09 | 2006-07-10 21:37:44 +0000 | [diff] [blame] | 5105 | static bool isBaseAlignment16(SDNode *Base, MachineFrameInfo *MFI, |
| 5106 | const X86Subtarget *Subtarget) { |
Evan Cheng | 206ee9d | 2006-07-07 08:33:52 +0000 | [diff] [blame] | 5107 | GlobalValue *GV; |
| 5108 | int64_t Offset; |
| 5109 | if (isGAPlusOffset(Base, GV, Offset)) |
| 5110 | return (GV->getAlignment() >= 16 && (Offset % 16) == 0); |
| 5111 | else { |
| 5112 | assert(Base->getOpcode() == ISD::FrameIndex && "Unexpected base node!"); |
Dan Gohman | 275769a | 2007-07-23 20:24:29 +0000 | [diff] [blame] | 5113 | int BFI = cast<FrameIndexSDNode>(Base)->getIndex(); |
Evan Cheng | 1e60c09 | 2006-07-10 21:37:44 +0000 | [diff] [blame] | 5114 | if (BFI < 0) |
| 5115 | // Fixed objects do not specify alignment, however the offsets are known. |
| 5116 | return ((Subtarget->getStackAlignment() % 16) == 0 && |
| 5117 | (MFI->getObjectOffset(BFI) % 16) == 0); |
| 5118 | else |
| 5119 | return MFI->getObjectAlignment(BFI) >= 16; |
Evan Cheng | 206ee9d | 2006-07-07 08:33:52 +0000 | [diff] [blame] | 5120 | } |
| 5121 | return false; |
| 5122 | } |
| 5123 | |
| 5124 | |
| 5125 | /// PerformShuffleCombine - Combine a vector_shuffle that is equal to |
| 5126 | /// build_vector load1, load2, load3, load4, <0, 1, 2, 3> into a 128-bit load |
| 5127 | /// if the load addresses are consecutive, non-overlapping, and in the right |
| 5128 | /// order. |
Evan Cheng | 1e60c09 | 2006-07-10 21:37:44 +0000 | [diff] [blame] | 5129 | static SDOperand PerformShuffleCombine(SDNode *N, SelectionDAG &DAG, |
| 5130 | const X86Subtarget *Subtarget) { |
Evan Cheng | 206ee9d | 2006-07-07 08:33:52 +0000 | [diff] [blame] | 5131 | MachineFunction &MF = DAG.getMachineFunction(); |
| 5132 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 5133 | MVT::ValueType VT = N->getValueType(0); |
Dan Gohman | 51eaa86 | 2007-06-14 22:58:02 +0000 | [diff] [blame] | 5134 | MVT::ValueType EVT = MVT::getVectorElementType(VT); |
Evan Cheng | 206ee9d | 2006-07-07 08:33:52 +0000 | [diff] [blame] | 5135 | SDOperand PermMask = N->getOperand(2); |
| 5136 | int NumElems = (int)PermMask.getNumOperands(); |
| 5137 | SDNode *Base = NULL; |
| 5138 | for (int i = 0; i < NumElems; ++i) { |
| 5139 | SDOperand Idx = PermMask.getOperand(i); |
| 5140 | if (Idx.getOpcode() == ISD::UNDEF) { |
| 5141 | if (!Base) return SDOperand(); |
| 5142 | } else { |
| 5143 | SDOperand Arg = |
| 5144 | getShuffleScalarElt(N, cast<ConstantSDNode>(Idx)->getValue(), DAG); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 5145 | if (!Arg.Val || !ISD::isNON_EXTLoad(Arg.Val)) |
Evan Cheng | 206ee9d | 2006-07-07 08:33:52 +0000 | [diff] [blame] | 5146 | return SDOperand(); |
| 5147 | if (!Base) |
| 5148 | Base = Arg.Val; |
| 5149 | else if (!isConsecutiveLoad(Arg.Val, Base, |
| 5150 | i, MVT::getSizeInBits(EVT)/8,MFI)) |
| 5151 | return SDOperand(); |
| 5152 | } |
| 5153 | } |
| 5154 | |
Evan Cheng | 1e60c09 | 2006-07-10 21:37:44 +0000 | [diff] [blame] | 5155 | bool isAlign16 = isBaseAlignment16(Base->getOperand(1).Val, MFI, Subtarget); |
Dan Gohman | d300622 | 2007-07-27 17:16:43 +0000 | [diff] [blame] | 5156 | LoadSDNode *LD = cast<LoadSDNode>(Base); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 5157 | if (isAlign16) { |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 5158 | return DAG.getLoad(VT, LD->getChain(), LD->getBasePtr(), LD->getSrcValue(), |
Dan Gohman | d300622 | 2007-07-27 17:16:43 +0000 | [diff] [blame] | 5159 | LD->getSrcValueOffset(), LD->isVolatile()); |
Evan Cheng | 466685d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 5160 | } else { |
Dan Gohman | d300622 | 2007-07-27 17:16:43 +0000 | [diff] [blame] | 5161 | return DAG.getLoad(VT, LD->getChain(), LD->getBasePtr(), LD->getSrcValue(), |
| 5162 | LD->getSrcValueOffset(), LD->isVolatile(), |
| 5163 | LD->getAlignment()); |
Evan Cheng | 311ace0 | 2006-08-11 07:35:45 +0000 | [diff] [blame] | 5164 | } |
Evan Cheng | 206ee9d | 2006-07-07 08:33:52 +0000 | [diff] [blame] | 5165 | } |
| 5166 | |
Chris Lattner | 83e6c99 | 2006-10-04 06:57:07 +0000 | [diff] [blame] | 5167 | /// PerformSELECTCombine - Do target-specific dag combines on SELECT nodes. |
| 5168 | static SDOperand PerformSELECTCombine(SDNode *N, SelectionDAG &DAG, |
| 5169 | const X86Subtarget *Subtarget) { |
| 5170 | SDOperand Cond = N->getOperand(0); |
Anton Korobeynikov | 12c49af | 2006-11-21 00:01:06 +0000 | [diff] [blame] | 5171 | |
Chris Lattner | 83e6c99 | 2006-10-04 06:57:07 +0000 | [diff] [blame] | 5172 | // If we have SSE[12] support, try to form min/max nodes. |
| 5173 | if (Subtarget->hasSSE2() && |
| 5174 | (N->getValueType(0) == MVT::f32 || N->getValueType(0) == MVT::f64)) { |
| 5175 | if (Cond.getOpcode() == ISD::SETCC) { |
| 5176 | // Get the LHS/RHS of the select. |
| 5177 | SDOperand LHS = N->getOperand(1); |
| 5178 | SDOperand RHS = N->getOperand(2); |
| 5179 | ISD::CondCode CC = cast<CondCodeSDNode>(Cond.getOperand(2))->get(); |
Anton Korobeynikov | 12c49af | 2006-11-21 00:01:06 +0000 | [diff] [blame] | 5180 | |
Evan Cheng | 8ca2932 | 2006-11-10 21:43:37 +0000 | [diff] [blame] | 5181 | unsigned Opcode = 0; |
Chris Lattner | 83e6c99 | 2006-10-04 06:57:07 +0000 | [diff] [blame] | 5182 | if (LHS == Cond.getOperand(0) && RHS == Cond.getOperand(1)) { |
Chris Lattner | 1907a7b | 2006-10-05 04:11:26 +0000 | [diff] [blame] | 5183 | switch (CC) { |
| 5184 | default: break; |
| 5185 | case ISD::SETOLE: // (X <= Y) ? X : Y -> min |
| 5186 | case ISD::SETULE: |
| 5187 | case ISD::SETLE: |
| 5188 | if (!UnsafeFPMath) break; |
| 5189 | // FALL THROUGH. |
| 5190 | case ISD::SETOLT: // (X olt/lt Y) ? X : Y -> min |
| 5191 | case ISD::SETLT: |
Evan Cheng | 8ca2932 | 2006-11-10 21:43:37 +0000 | [diff] [blame] | 5192 | Opcode = X86ISD::FMIN; |
Chris Lattner | 1907a7b | 2006-10-05 04:11:26 +0000 | [diff] [blame] | 5193 | break; |
Anton Korobeynikov | 12c49af | 2006-11-21 00:01:06 +0000 | [diff] [blame] | 5194 | |
Chris Lattner | 1907a7b | 2006-10-05 04:11:26 +0000 | [diff] [blame] | 5195 | case ISD::SETOGT: // (X > Y) ? X : Y -> max |
| 5196 | case ISD::SETUGT: |
| 5197 | case ISD::SETGT: |
| 5198 | if (!UnsafeFPMath) break; |
| 5199 | // FALL THROUGH. |
| 5200 | case ISD::SETUGE: // (X uge/ge Y) ? X : Y -> max |
| 5201 | case ISD::SETGE: |
Evan Cheng | 8ca2932 | 2006-11-10 21:43:37 +0000 | [diff] [blame] | 5202 | Opcode = X86ISD::FMAX; |
Chris Lattner | 1907a7b | 2006-10-05 04:11:26 +0000 | [diff] [blame] | 5203 | break; |
| 5204 | } |
Chris Lattner | 83e6c99 | 2006-10-04 06:57:07 +0000 | [diff] [blame] | 5205 | } else if (LHS == Cond.getOperand(1) && RHS == Cond.getOperand(0)) { |
Chris Lattner | 1907a7b | 2006-10-05 04:11:26 +0000 | [diff] [blame] | 5206 | switch (CC) { |
| 5207 | default: break; |
| 5208 | case ISD::SETOGT: // (X > Y) ? Y : X -> min |
| 5209 | case ISD::SETUGT: |
| 5210 | case ISD::SETGT: |
| 5211 | if (!UnsafeFPMath) break; |
| 5212 | // FALL THROUGH. |
| 5213 | case ISD::SETUGE: // (X uge/ge Y) ? Y : X -> min |
| 5214 | case ISD::SETGE: |
Evan Cheng | 8ca2932 | 2006-11-10 21:43:37 +0000 | [diff] [blame] | 5215 | Opcode = X86ISD::FMIN; |
Chris Lattner | 1907a7b | 2006-10-05 04:11:26 +0000 | [diff] [blame] | 5216 | break; |
Anton Korobeynikov | 12c49af | 2006-11-21 00:01:06 +0000 | [diff] [blame] | 5217 | |
Chris Lattner | 1907a7b | 2006-10-05 04:11:26 +0000 | [diff] [blame] | 5218 | case ISD::SETOLE: // (X <= Y) ? Y : X -> max |
| 5219 | case ISD::SETULE: |
| 5220 | case ISD::SETLE: |
| 5221 | if (!UnsafeFPMath) break; |
| 5222 | // FALL THROUGH. |
| 5223 | case ISD::SETOLT: // (X olt/lt Y) ? Y : X -> max |
| 5224 | case ISD::SETLT: |
Evan Cheng | 8ca2932 | 2006-11-10 21:43:37 +0000 | [diff] [blame] | 5225 | Opcode = X86ISD::FMAX; |
Chris Lattner | 1907a7b | 2006-10-05 04:11:26 +0000 | [diff] [blame] | 5226 | break; |
| 5227 | } |
Chris Lattner | 83e6c99 | 2006-10-04 06:57:07 +0000 | [diff] [blame] | 5228 | } |
Anton Korobeynikov | 12c49af | 2006-11-21 00:01:06 +0000 | [diff] [blame] | 5229 | |
Evan Cheng | 8ca2932 | 2006-11-10 21:43:37 +0000 | [diff] [blame] | 5230 | if (Opcode) |
| 5231 | return DAG.getNode(Opcode, N->getValueType(0), LHS, RHS); |
Chris Lattner | 83e6c99 | 2006-10-04 06:57:07 +0000 | [diff] [blame] | 5232 | } |
Anton Korobeynikov | 12c49af | 2006-11-21 00:01:06 +0000 | [diff] [blame] | 5233 | |
Chris Lattner | 83e6c99 | 2006-10-04 06:57:07 +0000 | [diff] [blame] | 5234 | } |
| 5235 | |
| 5236 | return SDOperand(); |
| 5237 | } |
| 5238 | |
| 5239 | |
Anton Korobeynikov | 12c49af | 2006-11-21 00:01:06 +0000 | [diff] [blame] | 5240 | SDOperand X86TargetLowering::PerformDAGCombine(SDNode *N, |
Evan Cheng | 206ee9d | 2006-07-07 08:33:52 +0000 | [diff] [blame] | 5241 | DAGCombinerInfo &DCI) const { |
Evan Cheng | 206ee9d | 2006-07-07 08:33:52 +0000 | [diff] [blame] | 5242 | SelectionDAG &DAG = DCI.DAG; |
| 5243 | switch (N->getOpcode()) { |
| 5244 | default: break; |
| 5245 | case ISD::VECTOR_SHUFFLE: |
Evan Cheng | 1e60c09 | 2006-07-10 21:37:44 +0000 | [diff] [blame] | 5246 | return PerformShuffleCombine(N, DAG, Subtarget); |
Chris Lattner | 83e6c99 | 2006-10-04 06:57:07 +0000 | [diff] [blame] | 5247 | case ISD::SELECT: |
| 5248 | return PerformSELECTCombine(N, DAG, Subtarget); |
Evan Cheng | 206ee9d | 2006-07-07 08:33:52 +0000 | [diff] [blame] | 5249 | } |
| 5250 | |
| 5251 | return SDOperand(); |
| 5252 | } |
| 5253 | |
Evan Cheng | 60c07e1 | 2006-07-05 22:17:51 +0000 | [diff] [blame] | 5254 | //===----------------------------------------------------------------------===// |
| 5255 | // X86 Inline Assembly Support |
| 5256 | //===----------------------------------------------------------------------===// |
| 5257 | |
Chris Lattner | f4dff84 | 2006-07-11 02:54:03 +0000 | [diff] [blame] | 5258 | /// getConstraintType - Given a constraint letter, return the type of |
| 5259 | /// constraint it is for this target. |
| 5260 | X86TargetLowering::ConstraintType |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 5261 | X86TargetLowering::getConstraintType(const std::string &Constraint) const { |
| 5262 | if (Constraint.size() == 1) { |
| 5263 | switch (Constraint[0]) { |
| 5264 | case 'A': |
| 5265 | case 'r': |
| 5266 | case 'R': |
| 5267 | case 'l': |
| 5268 | case 'q': |
| 5269 | case 'Q': |
| 5270 | case 'x': |
| 5271 | case 'Y': |
| 5272 | return C_RegisterClass; |
| 5273 | default: |
| 5274 | break; |
| 5275 | } |
Chris Lattner | f4dff84 | 2006-07-11 02:54:03 +0000 | [diff] [blame] | 5276 | } |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 5277 | return TargetLowering::getConstraintType(Constraint); |
Chris Lattner | f4dff84 | 2006-07-11 02:54:03 +0000 | [diff] [blame] | 5278 | } |
| 5279 | |
Chris Lattner | 48884cd | 2007-08-25 00:47:38 +0000 | [diff] [blame] | 5280 | /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops |
| 5281 | /// vector. If it is invalid, don't add anything to Ops. |
| 5282 | void X86TargetLowering::LowerAsmOperandForConstraint(SDOperand Op, |
| 5283 | char Constraint, |
| 5284 | std::vector<SDOperand>&Ops, |
| 5285 | SelectionDAG &DAG) { |
| 5286 | SDOperand Result(0, 0); |
| 5287 | |
Chris Lattner | 22aaf1d | 2006-10-31 20:13:11 +0000 | [diff] [blame] | 5288 | switch (Constraint) { |
| 5289 | default: break; |
Devang Patel | 84f7fd2 | 2007-03-17 00:13:28 +0000 | [diff] [blame] | 5290 | case 'I': |
Chris Lattner | 188b9fe | 2007-03-25 01:57:35 +0000 | [diff] [blame] | 5291 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) { |
Chris Lattner | 48884cd | 2007-08-25 00:47:38 +0000 | [diff] [blame] | 5292 | if (C->getValue() <= 31) { |
| 5293 | Result = DAG.getTargetConstant(C->getValue(), Op.getValueType()); |
| 5294 | break; |
| 5295 | } |
Devang Patel | 84f7fd2 | 2007-03-17 00:13:28 +0000 | [diff] [blame] | 5296 | } |
Chris Lattner | 48884cd | 2007-08-25 00:47:38 +0000 | [diff] [blame] | 5297 | return; |
Chris Lattner | 188b9fe | 2007-03-25 01:57:35 +0000 | [diff] [blame] | 5298 | case 'N': |
| 5299 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) { |
Chris Lattner | 48884cd | 2007-08-25 00:47:38 +0000 | [diff] [blame] | 5300 | if (C->getValue() <= 255) { |
| 5301 | Result = DAG.getTargetConstant(C->getValue(), Op.getValueType()); |
| 5302 | break; |
| 5303 | } |
Chris Lattner | 188b9fe | 2007-03-25 01:57:35 +0000 | [diff] [blame] | 5304 | } |
Chris Lattner | 48884cd | 2007-08-25 00:47:38 +0000 | [diff] [blame] | 5305 | return; |
Chris Lattner | dc43a88 | 2007-05-03 16:52:29 +0000 | [diff] [blame] | 5306 | case 'i': { |
Chris Lattner | 22aaf1d | 2006-10-31 20:13:11 +0000 | [diff] [blame] | 5307 | // Literal immediates are always ok. |
Chris Lattner | 48884cd | 2007-08-25 00:47:38 +0000 | [diff] [blame] | 5308 | if (ConstantSDNode *CST = dyn_cast<ConstantSDNode>(Op)) { |
| 5309 | Result = DAG.getTargetConstant(CST->getValue(), Op.getValueType()); |
| 5310 | break; |
| 5311 | } |
Anton Korobeynikov | 12c49af | 2006-11-21 00:01:06 +0000 | [diff] [blame] | 5312 | |
Chris Lattner | dc43a88 | 2007-05-03 16:52:29 +0000 | [diff] [blame] | 5313 | // If we are in non-pic codegen mode, we allow the address of a global (with |
| 5314 | // an optional displacement) to be used with 'i'. |
| 5315 | GlobalAddressSDNode *GA = dyn_cast<GlobalAddressSDNode>(Op); |
| 5316 | int64_t Offset = 0; |
| 5317 | |
| 5318 | // Match either (GA) or (GA+C) |
| 5319 | if (GA) { |
| 5320 | Offset = GA->getOffset(); |
| 5321 | } else if (Op.getOpcode() == ISD::ADD) { |
| 5322 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op.getOperand(1)); |
| 5323 | GA = dyn_cast<GlobalAddressSDNode>(Op.getOperand(0)); |
| 5324 | if (C && GA) { |
| 5325 | Offset = GA->getOffset()+C->getValue(); |
| 5326 | } else { |
| 5327 | C = dyn_cast<ConstantSDNode>(Op.getOperand(1)); |
| 5328 | GA = dyn_cast<GlobalAddressSDNode>(Op.getOperand(0)); |
| 5329 | if (C && GA) |
| 5330 | Offset = GA->getOffset()+C->getValue(); |
| 5331 | else |
| 5332 | C = 0, GA = 0; |
| 5333 | } |
| 5334 | } |
| 5335 | |
| 5336 | if (GA) { |
| 5337 | // If addressing this global requires a load (e.g. in PIC mode), we can't |
| 5338 | // match. |
| 5339 | if (Subtarget->GVRequiresExtraLoad(GA->getGlobal(), getTargetMachine(), |
| 5340 | false)) |
Chris Lattner | 48884cd | 2007-08-25 00:47:38 +0000 | [diff] [blame] | 5341 | return; |
Anton Korobeynikov | 12c49af | 2006-11-21 00:01:06 +0000 | [diff] [blame] | 5342 | |
Chris Lattner | dc43a88 | 2007-05-03 16:52:29 +0000 | [diff] [blame] | 5343 | Op = DAG.getTargetGlobalAddress(GA->getGlobal(), GA->getValueType(0), |
| 5344 | Offset); |
Chris Lattner | 48884cd | 2007-08-25 00:47:38 +0000 | [diff] [blame] | 5345 | Result = Op; |
| 5346 | break; |
Chris Lattner | 22aaf1d | 2006-10-31 20:13:11 +0000 | [diff] [blame] | 5347 | } |
Anton Korobeynikov | 12c49af | 2006-11-21 00:01:06 +0000 | [diff] [blame] | 5348 | |
Chris Lattner | 22aaf1d | 2006-10-31 20:13:11 +0000 | [diff] [blame] | 5349 | // Otherwise, not valid for this mode. |
Chris Lattner | 48884cd | 2007-08-25 00:47:38 +0000 | [diff] [blame] | 5350 | return; |
Chris Lattner | 22aaf1d | 2006-10-31 20:13:11 +0000 | [diff] [blame] | 5351 | } |
Chris Lattner | dc43a88 | 2007-05-03 16:52:29 +0000 | [diff] [blame] | 5352 | } |
Chris Lattner | 48884cd | 2007-08-25 00:47:38 +0000 | [diff] [blame] | 5353 | |
| 5354 | if (Result.Val) { |
| 5355 | Ops.push_back(Result); |
| 5356 | return; |
| 5357 | } |
| 5358 | return TargetLowering::LowerAsmOperandForConstraint(Op, Constraint, Ops, DAG); |
Chris Lattner | 22aaf1d | 2006-10-31 20:13:11 +0000 | [diff] [blame] | 5359 | } |
| 5360 | |
Chris Lattner | 259e97c | 2006-01-31 19:43:35 +0000 | [diff] [blame] | 5361 | std::vector<unsigned> X86TargetLowering:: |
Chris Lattner | 1efa40f | 2006-02-22 00:56:39 +0000 | [diff] [blame] | 5362 | getRegClassForInlineAsmConstraint(const std::string &Constraint, |
| 5363 | MVT::ValueType VT) const { |
Chris Lattner | 259e97c | 2006-01-31 19:43:35 +0000 | [diff] [blame] | 5364 | if (Constraint.size() == 1) { |
| 5365 | // FIXME: not handling fp-stack yet! |
Chris Lattner | 259e97c | 2006-01-31 19:43:35 +0000 | [diff] [blame] | 5366 | switch (Constraint[0]) { // GCC X86 Constraint Letters |
Chris Lattner | f4dff84 | 2006-07-11 02:54:03 +0000 | [diff] [blame] | 5367 | default: break; // Unknown constraint letter |
| 5368 | case 'A': // EAX/EDX |
| 5369 | if (VT == MVT::i32 || VT == MVT::i64) |
| 5370 | return make_vector<unsigned>(X86::EAX, X86::EDX, 0); |
| 5371 | break; |
Chris Lattner | 259e97c | 2006-01-31 19:43:35 +0000 | [diff] [blame] | 5372 | case 'q': // Q_REGS (GENERAL_REGS in 64-bit mode) |
| 5373 | case 'Q': // Q_REGS |
Chris Lattner | 80a7ecc | 2006-05-06 00:29:37 +0000 | [diff] [blame] | 5374 | if (VT == MVT::i32) |
| 5375 | return make_vector<unsigned>(X86::EAX, X86::EDX, X86::ECX, X86::EBX, 0); |
| 5376 | else if (VT == MVT::i16) |
| 5377 | return make_vector<unsigned>(X86::AX, X86::DX, X86::CX, X86::BX, 0); |
| 5378 | else if (VT == MVT::i8) |
Evan Cheng | 1291438 | 2007-08-13 23:27:11 +0000 | [diff] [blame] | 5379 | return make_vector<unsigned>(X86::AL, X86::DL, X86::CL, X86::BL, 0); |
Chris Lattner | 80a7ecc | 2006-05-06 00:29:37 +0000 | [diff] [blame] | 5380 | break; |
Chris Lattner | 259e97c | 2006-01-31 19:43:35 +0000 | [diff] [blame] | 5381 | } |
| 5382 | } |
Anton Korobeynikov | 12c49af | 2006-11-21 00:01:06 +0000 | [diff] [blame] | 5383 | |
Chris Lattner | 1efa40f | 2006-02-22 00:56:39 +0000 | [diff] [blame] | 5384 | return std::vector<unsigned>(); |
Chris Lattner | 259e97c | 2006-01-31 19:43:35 +0000 | [diff] [blame] | 5385 | } |
Chris Lattner | f76d180 | 2006-07-31 23:26:50 +0000 | [diff] [blame] | 5386 | |
Anton Korobeynikov | 12c49af | 2006-11-21 00:01:06 +0000 | [diff] [blame] | 5387 | std::pair<unsigned, const TargetRegisterClass*> |
Chris Lattner | f76d180 | 2006-07-31 23:26:50 +0000 | [diff] [blame] | 5388 | X86TargetLowering::getRegForInlineAsmConstraint(const std::string &Constraint, |
| 5389 | MVT::ValueType VT) const { |
Chris Lattner | ad043e8 | 2007-04-09 05:11:28 +0000 | [diff] [blame] | 5390 | // First, see if this is a constraint that directly corresponds to an LLVM |
| 5391 | // register class. |
| 5392 | if (Constraint.size() == 1) { |
| 5393 | // GCC Constraint Letters |
| 5394 | switch (Constraint[0]) { |
| 5395 | default: break; |
Chris Lattner | 0f65cad | 2007-04-09 05:49:22 +0000 | [diff] [blame] | 5396 | case 'r': // GENERAL_REGS |
| 5397 | case 'R': // LEGACY_REGS |
| 5398 | case 'l': // INDEX_REGS |
| 5399 | if (VT == MVT::i64 && Subtarget->is64Bit()) |
| 5400 | return std::make_pair(0U, X86::GR64RegisterClass); |
| 5401 | if (VT == MVT::i32) |
| 5402 | return std::make_pair(0U, X86::GR32RegisterClass); |
| 5403 | else if (VT == MVT::i16) |
| 5404 | return std::make_pair(0U, X86::GR16RegisterClass); |
| 5405 | else if (VT == MVT::i8) |
| 5406 | return std::make_pair(0U, X86::GR8RegisterClass); |
| 5407 | break; |
Chris Lattner | 6c284d7 | 2007-04-12 04:14:49 +0000 | [diff] [blame] | 5408 | case 'y': // MMX_REGS if MMX allowed. |
| 5409 | if (!Subtarget->hasMMX()) break; |
| 5410 | return std::make_pair(0U, X86::VR64RegisterClass); |
| 5411 | break; |
Chris Lattner | 0f65cad | 2007-04-09 05:49:22 +0000 | [diff] [blame] | 5412 | case 'Y': // SSE_REGS if SSE2 allowed |
| 5413 | if (!Subtarget->hasSSE2()) break; |
| 5414 | // FALL THROUGH. |
| 5415 | case 'x': // SSE_REGS if SSE1 allowed |
| 5416 | if (!Subtarget->hasSSE1()) break; |
| 5417 | |
| 5418 | switch (VT) { |
| 5419 | default: break; |
| 5420 | // Scalar SSE types. |
| 5421 | case MVT::f32: |
| 5422 | case MVT::i32: |
Chris Lattner | ad043e8 | 2007-04-09 05:11:28 +0000 | [diff] [blame] | 5423 | return std::make_pair(0U, X86::FR32RegisterClass); |
Chris Lattner | 0f65cad | 2007-04-09 05:49:22 +0000 | [diff] [blame] | 5424 | case MVT::f64: |
| 5425 | case MVT::i64: |
Chris Lattner | ad043e8 | 2007-04-09 05:11:28 +0000 | [diff] [blame] | 5426 | return std::make_pair(0U, X86::FR64RegisterClass); |
Chris Lattner | 0f65cad | 2007-04-09 05:49:22 +0000 | [diff] [blame] | 5427 | // Vector types. |
Chris Lattner | 0f65cad | 2007-04-09 05:49:22 +0000 | [diff] [blame] | 5428 | case MVT::v16i8: |
| 5429 | case MVT::v8i16: |
| 5430 | case MVT::v4i32: |
| 5431 | case MVT::v2i64: |
| 5432 | case MVT::v4f32: |
| 5433 | case MVT::v2f64: |
| 5434 | return std::make_pair(0U, X86::VR128RegisterClass); |
| 5435 | } |
Chris Lattner | ad043e8 | 2007-04-09 05:11:28 +0000 | [diff] [blame] | 5436 | break; |
| 5437 | } |
| 5438 | } |
| 5439 | |
Chris Lattner | f76d180 | 2006-07-31 23:26:50 +0000 | [diff] [blame] | 5440 | // Use the default implementation in TargetLowering to convert the register |
| 5441 | // constraint into a member of a register class. |
| 5442 | std::pair<unsigned, const TargetRegisterClass*> Res; |
| 5443 | Res = TargetLowering::getRegForInlineAsmConstraint(Constraint, VT); |
Chris Lattner | 1a60aa7 | 2006-10-31 19:42:44 +0000 | [diff] [blame] | 5444 | |
| 5445 | // Not found as a standard register? |
| 5446 | if (Res.second == 0) { |
| 5447 | // GCC calls "st(0)" just plain "st". |
| 5448 | if (StringsEqualNoCase("{st}", Constraint)) { |
| 5449 | Res.first = X86::ST0; |
Chris Lattner | 9b4baf1 | 2007-09-24 05:27:37 +0000 | [diff] [blame] | 5450 | Res.second = X86::RFP80RegisterClass; |
Chris Lattner | 1a60aa7 | 2006-10-31 19:42:44 +0000 | [diff] [blame] | 5451 | } |
Anton Korobeynikov | 12c49af | 2006-11-21 00:01:06 +0000 | [diff] [blame] | 5452 | |
Chris Lattner | 1a60aa7 | 2006-10-31 19:42:44 +0000 | [diff] [blame] | 5453 | return Res; |
| 5454 | } |
Anton Korobeynikov | 12c49af | 2006-11-21 00:01:06 +0000 | [diff] [blame] | 5455 | |
Chris Lattner | f76d180 | 2006-07-31 23:26:50 +0000 | [diff] [blame] | 5456 | // Otherwise, check to see if this is a register class of the wrong value |
| 5457 | // type. For example, we want to map "{ax},i32" -> {eax}, we don't want it to |
| 5458 | // turn into {ax},{dx}. |
| 5459 | if (Res.second->hasType(VT)) |
| 5460 | return Res; // Correct type already, nothing to do. |
Anton Korobeynikov | 12c49af | 2006-11-21 00:01:06 +0000 | [diff] [blame] | 5461 | |
Chris Lattner | f76d180 | 2006-07-31 23:26:50 +0000 | [diff] [blame] | 5462 | // All of the single-register GCC register classes map their values onto |
| 5463 | // 16-bit register pieces "ax","dx","cx","bx","si","di","bp","sp". If we |
| 5464 | // really want an 8-bit or 32-bit register, map to the appropriate register |
| 5465 | // class and return the appropriate register. |
| 5466 | if (Res.second != X86::GR16RegisterClass) |
| 5467 | return Res; |
Anton Korobeynikov | 12c49af | 2006-11-21 00:01:06 +0000 | [diff] [blame] | 5468 | |
Chris Lattner | f76d180 | 2006-07-31 23:26:50 +0000 | [diff] [blame] | 5469 | if (VT == MVT::i8) { |
| 5470 | unsigned DestReg = 0; |
| 5471 | switch (Res.first) { |
| 5472 | default: break; |
| 5473 | case X86::AX: DestReg = X86::AL; break; |
| 5474 | case X86::DX: DestReg = X86::DL; break; |
| 5475 | case X86::CX: DestReg = X86::CL; break; |
| 5476 | case X86::BX: DestReg = X86::BL; break; |
| 5477 | } |
| 5478 | if (DestReg) { |
| 5479 | Res.first = DestReg; |
| 5480 | Res.second = Res.second = X86::GR8RegisterClass; |
| 5481 | } |
| 5482 | } else if (VT == MVT::i32) { |
| 5483 | unsigned DestReg = 0; |
| 5484 | switch (Res.first) { |
| 5485 | default: break; |
| 5486 | case X86::AX: DestReg = X86::EAX; break; |
| 5487 | case X86::DX: DestReg = X86::EDX; break; |
| 5488 | case X86::CX: DestReg = X86::ECX; break; |
| 5489 | case X86::BX: DestReg = X86::EBX; break; |
| 5490 | case X86::SI: DestReg = X86::ESI; break; |
| 5491 | case X86::DI: DestReg = X86::EDI; break; |
| 5492 | case X86::BP: DestReg = X86::EBP; break; |
| 5493 | case X86::SP: DestReg = X86::ESP; break; |
| 5494 | } |
| 5495 | if (DestReg) { |
| 5496 | Res.first = DestReg; |
| 5497 | Res.second = Res.second = X86::GR32RegisterClass; |
| 5498 | } |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 5499 | } else if (VT == MVT::i64) { |
| 5500 | unsigned DestReg = 0; |
| 5501 | switch (Res.first) { |
| 5502 | default: break; |
| 5503 | case X86::AX: DestReg = X86::RAX; break; |
| 5504 | case X86::DX: DestReg = X86::RDX; break; |
| 5505 | case X86::CX: DestReg = X86::RCX; break; |
| 5506 | case X86::BX: DestReg = X86::RBX; break; |
| 5507 | case X86::SI: DestReg = X86::RSI; break; |
| 5508 | case X86::DI: DestReg = X86::RDI; break; |
| 5509 | case X86::BP: DestReg = X86::RBP; break; |
| 5510 | case X86::SP: DestReg = X86::RSP; break; |
| 5511 | } |
| 5512 | if (DestReg) { |
| 5513 | Res.first = DestReg; |
| 5514 | Res.second = Res.second = X86::GR64RegisterClass; |
| 5515 | } |
Chris Lattner | f76d180 | 2006-07-31 23:26:50 +0000 | [diff] [blame] | 5516 | } |
Anton Korobeynikov | 12c49af | 2006-11-21 00:01:06 +0000 | [diff] [blame] | 5517 | |
Chris Lattner | f76d180 | 2006-07-31 23:26:50 +0000 | [diff] [blame] | 5518 | return Res; |
| 5519 | } |