Nate Begeman | 1d9d742 | 2005-10-18 00:28:58 +0000 | [diff] [blame] | 1 | //===-- PPCISelLowering.cpp - PPC DAG Lowering Implementation -------------===// |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +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 | // |
Nate Begeman | 21e463b | 2005-10-16 05:39:50 +0000 | [diff] [blame] | 10 | // This file implements the PPCISelLowering class. |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Chris Lattner | 16e71f2 | 2005-10-14 23:59:06 +0000 | [diff] [blame] | 14 | #include "PPCISelLowering.h" |
| 15 | #include "PPCTargetMachine.h" |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/VectorExtras.h" |
Evan Cheng | c4c6257 | 2006-03-13 23:20:37 +0000 | [diff] [blame] | 17 | #include "llvm/Analysis/ScalarEvolutionExpressions.h" |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 19 | #include "llvm/CodeGen/MachineFunction.h" |
Chris Lattner | 8a2d3ca | 2005-08-26 21:23:58 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/SelectionDAG.h" |
Chris Lattner | 7b73834 | 2005-09-13 19:33:40 +0000 | [diff] [blame] | 22 | #include "llvm/CodeGen/SSARegMap.h" |
Chris Lattner | 0b1e4e5 | 2005-08-26 17:36:52 +0000 | [diff] [blame] | 23 | #include "llvm/Constants.h" |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 24 | #include "llvm/Function.h" |
Chris Lattner | 6d92cad | 2006-03-26 10:06:40 +0000 | [diff] [blame] | 25 | #include "llvm/Intrinsics.h" |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 26 | #include "llvm/Support/MathExtras.h" |
Evan Cheng | d2ee218 | 2006-02-18 00:08:58 +0000 | [diff] [blame] | 27 | #include "llvm/Target/TargetOptions.h" |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 28 | using namespace llvm; |
| 29 | |
Nate Begeman | 21e463b | 2005-10-16 05:39:50 +0000 | [diff] [blame] | 30 | PPCTargetLowering::PPCTargetLowering(TargetMachine &TM) |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 31 | : TargetLowering(TM) { |
| 32 | |
| 33 | // Fold away setcc operations if possible. |
| 34 | setSetCCIsExpensive(); |
Nate Begeman | 405e3ec | 2005-10-21 00:02:42 +0000 | [diff] [blame] | 35 | setPow2DivIsCheap(); |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 36 | |
Chris Lattner | d145a61 | 2005-09-27 22:18:25 +0000 | [diff] [blame] | 37 | // Use _setjmp/_longjmp instead of setjmp/longjmp. |
| 38 | setUseUnderscoreSetJmpLongJmp(true); |
| 39 | |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 40 | // Set up the register classes. |
Nate Begeman | 1d9d742 | 2005-10-18 00:28:58 +0000 | [diff] [blame] | 41 | addRegisterClass(MVT::i32, PPC::GPRCRegisterClass); |
| 42 | addRegisterClass(MVT::f32, PPC::F4RCRegisterClass); |
| 43 | addRegisterClass(MVT::f64, PPC::F8RCRegisterClass); |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 44 | |
Chris Lattner | a54aa94 | 2006-01-29 06:26:08 +0000 | [diff] [blame] | 45 | setOperationAction(ISD::ConstantFP, MVT::f64, Expand); |
| 46 | setOperationAction(ISD::ConstantFP, MVT::f32, Expand); |
| 47 | |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 48 | // PowerPC has no intrinsics for these particular operations |
| 49 | setOperationAction(ISD::MEMMOVE, MVT::Other, Expand); |
| 50 | setOperationAction(ISD::MEMSET, MVT::Other, Expand); |
| 51 | setOperationAction(ISD::MEMCPY, MVT::Other, Expand); |
| 52 | |
| 53 | // PowerPC has an i16 but no i8 (or i1) SEXTLOAD |
| 54 | setOperationAction(ISD::SEXTLOAD, MVT::i1, Expand); |
| 55 | setOperationAction(ISD::SEXTLOAD, MVT::i8, Expand); |
| 56 | |
| 57 | // PowerPC has no SREM/UREM instructions |
| 58 | setOperationAction(ISD::SREM, MVT::i32, Expand); |
| 59 | setOperationAction(ISD::UREM, MVT::i32, Expand); |
| 60 | |
| 61 | // We don't support sin/cos/sqrt/fmod |
| 62 | setOperationAction(ISD::FSIN , MVT::f64, Expand); |
| 63 | setOperationAction(ISD::FCOS , MVT::f64, Expand); |
Chris Lattner | 615c2d0 | 2005-09-28 22:29:58 +0000 | [diff] [blame] | 64 | setOperationAction(ISD::FREM , MVT::f64, Expand); |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 65 | setOperationAction(ISD::FSIN , MVT::f32, Expand); |
| 66 | setOperationAction(ISD::FCOS , MVT::f32, Expand); |
Chris Lattner | 615c2d0 | 2005-09-28 22:29:58 +0000 | [diff] [blame] | 67 | setOperationAction(ISD::FREM , MVT::f32, Expand); |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 68 | |
| 69 | // If we're enabling GP optimizations, use hardware square root |
Chris Lattner | 1e9de3e | 2005-09-02 18:33:05 +0000 | [diff] [blame] | 70 | if (!TM.getSubtarget<PPCSubtarget>().hasFSQRT()) { |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 71 | setOperationAction(ISD::FSQRT, MVT::f64, Expand); |
| 72 | setOperationAction(ISD::FSQRT, MVT::f32, Expand); |
| 73 | } |
| 74 | |
Chris Lattner | 9601a86 | 2006-03-05 05:08:37 +0000 | [diff] [blame] | 75 | setOperationAction(ISD::FCOPYSIGN, MVT::f64, Expand); |
| 76 | setOperationAction(ISD::FCOPYSIGN, MVT::f32, Expand); |
| 77 | |
Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 78 | // PowerPC does not have BSWAP, CTPOP or CTTZ |
| 79 | setOperationAction(ISD::BSWAP, MVT::i32 , Expand); |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 80 | setOperationAction(ISD::CTPOP, MVT::i32 , Expand); |
| 81 | setOperationAction(ISD::CTTZ , MVT::i32 , Expand); |
| 82 | |
Nate Begeman | 35ef913 | 2006-01-11 21:21:00 +0000 | [diff] [blame] | 83 | // PowerPC does not have ROTR |
| 84 | setOperationAction(ISD::ROTR, MVT::i32 , Expand); |
| 85 | |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 86 | // PowerPC does not have Select |
| 87 | setOperationAction(ISD::SELECT, MVT::i32, Expand); |
| 88 | setOperationAction(ISD::SELECT, MVT::f32, Expand); |
| 89 | setOperationAction(ISD::SELECT, MVT::f64, Expand); |
Chris Lattner | a1d95e1 | 2006-04-08 22:59:15 +0000 | [diff] [blame] | 90 | setOperationAction(ISD::SELECT, MVT::v4f32, Expand); |
| 91 | setOperationAction(ISD::SELECT, MVT::v4i32, Expand); |
| 92 | setOperationAction(ISD::SELECT, MVT::v8i16, Expand); |
| 93 | setOperationAction(ISD::SELECT, MVT::v16i8, Expand); |
Chris Lattner | e4bc9ea | 2005-08-26 00:52:45 +0000 | [diff] [blame] | 94 | |
Chris Lattner | 0b1e4e5 | 2005-08-26 17:36:52 +0000 | [diff] [blame] | 95 | // PowerPC wants to turn select_cc of FP into fsel when possible. |
| 96 | setOperationAction(ISD::SELECT_CC, MVT::f32, Custom); |
| 97 | setOperationAction(ISD::SELECT_CC, MVT::f64, Custom); |
Nate Begeman | 4477590 | 2006-01-31 08:17:29 +0000 | [diff] [blame] | 98 | |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 99 | // PowerPC wants to optimize integer setcc a bit |
Nate Begeman | 4477590 | 2006-01-31 08:17:29 +0000 | [diff] [blame] | 100 | setOperationAction(ISD::SETCC, MVT::i32, Custom); |
Chris Lattner | eb9b62e | 2005-08-31 19:09:57 +0000 | [diff] [blame] | 101 | |
Nate Begeman | 81e8097 | 2006-03-17 01:40:33 +0000 | [diff] [blame] | 102 | // PowerPC does not have BRCOND which requires SetCC |
| 103 | setOperationAction(ISD::BRCOND, MVT::Other, Expand); |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 104 | |
Chris Lattner | f760532 | 2005-08-31 21:09:52 +0000 | [diff] [blame] | 105 | // PowerPC turns FP_TO_SINT into FCTIWZ and some load/stores. |
| 106 | setOperationAction(ISD::FP_TO_SINT, MVT::i32, Custom); |
Nate Begeman | c09eeec | 2005-09-06 22:03:27 +0000 | [diff] [blame] | 107 | |
Jim Laskey | ad23c9d | 2005-08-17 00:40:22 +0000 | [diff] [blame] | 108 | // PowerPC does not have [U|S]INT_TO_FP |
| 109 | setOperationAction(ISD::SINT_TO_FP, MVT::i32, Expand); |
| 110 | setOperationAction(ISD::UINT_TO_FP, MVT::i32, Expand); |
| 111 | |
Chris Lattner | 53e8845 | 2005-12-23 05:13:35 +0000 | [diff] [blame] | 112 | setOperationAction(ISD::BIT_CONVERT, MVT::f32, Expand); |
| 113 | setOperationAction(ISD::BIT_CONVERT, MVT::i32, Expand); |
| 114 | |
Chris Lattner | e6ec9f2 | 2005-09-10 00:21:06 +0000 | [diff] [blame] | 115 | // PowerPC does not have truncstore for i1. |
| 116 | setOperationAction(ISD::TRUNCSTORE, MVT::i1, Promote); |
Chris Lattner | f73bae1 | 2005-11-29 06:16:21 +0000 | [diff] [blame] | 117 | |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 118 | // Support label based line numbers. |
Chris Lattner | f73bae1 | 2005-11-29 06:16:21 +0000 | [diff] [blame] | 119 | setOperationAction(ISD::LOCATION, MVT::Other, Expand); |
Jim Laskey | e0bce71 | 2006-01-05 01:47:43 +0000 | [diff] [blame] | 120 | setOperationAction(ISD::DEBUG_LOC, MVT::Other, Expand); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 121 | // FIXME - use subtarget debug flags |
Jim Laskey | e0bce71 | 2006-01-05 01:47:43 +0000 | [diff] [blame] | 122 | if (!TM.getSubtarget<PPCSubtarget>().isDarwin()) |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 123 | setOperationAction(ISD::DEBUG_LABEL, MVT::Other, Expand); |
Chris Lattner | e6ec9f2 | 2005-09-10 00:21:06 +0000 | [diff] [blame] | 124 | |
Nate Begeman | 28a6b02 | 2005-12-10 02:36:00 +0000 | [diff] [blame] | 125 | // We want to legalize GlobalAddress and ConstantPool nodes into the |
| 126 | // appropriate instructions to materialize the address. |
Chris Lattner | 3eef4e3 | 2005-11-17 18:26:56 +0000 | [diff] [blame] | 127 | setOperationAction(ISD::GlobalAddress, MVT::i32, Custom); |
Nate Begeman | 28a6b02 | 2005-12-10 02:36:00 +0000 | [diff] [blame] | 128 | setOperationAction(ISD::ConstantPool, MVT::i32, Custom); |
Chris Lattner | b99329e | 2006-01-13 02:42:53 +0000 | [diff] [blame] | 129 | |
Nate Begeman | ee62557 | 2006-01-27 21:09:22 +0000 | [diff] [blame] | 130 | // RET must be custom lowered, to meet ABI requirements |
| 131 | setOperationAction(ISD::RET , MVT::Other, Custom); |
| 132 | |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 133 | // VASTART needs to be custom lowered to use the VarArgsFrameIndex |
| 134 | setOperationAction(ISD::VASTART , MVT::Other, Custom); |
| 135 | |
Chris Lattner | b22c08b | 2006-01-15 09:02:48 +0000 | [diff] [blame] | 136 | // Use the default implementation. |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 137 | setOperationAction(ISD::VAARG , MVT::Other, Expand); |
| 138 | setOperationAction(ISD::VACOPY , MVT::Other, Expand); |
| 139 | setOperationAction(ISD::VAEND , MVT::Other, Expand); |
Chris Lattner | b22c08b | 2006-01-15 09:02:48 +0000 | [diff] [blame] | 140 | setOperationAction(ISD::STACKSAVE , MVT::Other, Expand); |
| 141 | setOperationAction(ISD::STACKRESTORE , MVT::Other, Expand); |
| 142 | setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32 , Expand); |
Chris Lattner | 860e886 | 2005-11-17 07:30:41 +0000 | [diff] [blame] | 143 | |
Chris Lattner | 6d92cad | 2006-03-26 10:06:40 +0000 | [diff] [blame] | 144 | // We want to custom lower some of our intrinsics. |
Chris Lattner | 48b61a7 | 2006-03-28 00:40:33 +0000 | [diff] [blame] | 145 | setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom); |
Chris Lattner | 6d92cad | 2006-03-26 10:06:40 +0000 | [diff] [blame] | 146 | |
Nate Begeman | c09eeec | 2005-09-06 22:03:27 +0000 | [diff] [blame] | 147 | if (TM.getSubtarget<PPCSubtarget>().is64Bit()) { |
Nate Begeman | 1d9d742 | 2005-10-18 00:28:58 +0000 | [diff] [blame] | 148 | // They also have instructions for converting between i64 and fp. |
Nate Begeman | c09eeec | 2005-09-06 22:03:27 +0000 | [diff] [blame] | 149 | setOperationAction(ISD::FP_TO_SINT, MVT::i64, Custom); |
| 150 | setOperationAction(ISD::SINT_TO_FP, MVT::i64, Custom); |
Chris Lattner | 7fbcef7 | 2006-03-24 07:53:47 +0000 | [diff] [blame] | 151 | |
| 152 | // FIXME: disable this lowered code. This generates 64-bit register values, |
| 153 | // and we don't model the fact that the top part is clobbered by calls. We |
| 154 | // need to flag these together so that the value isn't live across a call. |
| 155 | //setOperationAction(ISD::SINT_TO_FP, MVT::i32, Custom); |
| 156 | |
Nate Begeman | ae749a9 | 2005-10-25 23:48:36 +0000 | [diff] [blame] | 157 | // To take advantage of the above i64 FP_TO_SINT, promote i32 FP_TO_UINT |
| 158 | setOperationAction(ISD::FP_TO_UINT, MVT::i32, Promote); |
| 159 | } else { |
Chris Lattner | 860e886 | 2005-11-17 07:30:41 +0000 | [diff] [blame] | 160 | // PowerPC does not have FP_TO_UINT on 32-bit implementations. |
Nate Begeman | ae749a9 | 2005-10-25 23:48:36 +0000 | [diff] [blame] | 161 | setOperationAction(ISD::FP_TO_UINT, MVT::i32, Expand); |
Nate Begeman | 9d2b817 | 2005-10-18 00:56:42 +0000 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | if (TM.getSubtarget<PPCSubtarget>().has64BitRegs()) { |
| 165 | // 64 bit PowerPC implementations can support i64 types directly |
| 166 | addRegisterClass(MVT::i64, PPC::G8RCRegisterClass); |
Nate Begeman | 1d9d742 | 2005-10-18 00:28:58 +0000 | [diff] [blame] | 167 | // BUILD_PAIR can't be handled natively, and should be expanded to shl/or |
| 168 | setOperationAction(ISD::BUILD_PAIR, MVT::i64, Expand); |
Nate Begeman | 1d9d742 | 2005-10-18 00:28:58 +0000 | [diff] [blame] | 169 | } else { |
| 170 | // 32 bit PowerPC wants to expand i64 shifts itself. |
| 171 | setOperationAction(ISD::SHL, MVT::i64, Custom); |
| 172 | setOperationAction(ISD::SRL, MVT::i64, Custom); |
| 173 | setOperationAction(ISD::SRA, MVT::i64, Custom); |
Nate Begeman | c09eeec | 2005-09-06 22:03:27 +0000 | [diff] [blame] | 174 | } |
Evan Cheng | d30bf01 | 2006-03-01 01:11:20 +0000 | [diff] [blame] | 175 | |
Nate Begeman | 425a969 | 2005-11-29 08:17:20 +0000 | [diff] [blame] | 176 | if (TM.getSubtarget<PPCSubtarget>().hasAltivec()) { |
Chris Lattner | e3fea5a | 2006-03-31 19:52:36 +0000 | [diff] [blame] | 177 | // First set operation action for all vector types to expand. Then we |
| 178 | // will selectively turn on ones that can be effectively codegen'd. |
| 179 | for (unsigned VT = (unsigned)MVT::FIRST_VECTOR_VALUETYPE; |
| 180 | VT != (unsigned)MVT::LAST_VECTOR_VALUETYPE; ++VT) { |
| 181 | // add/sub/and/or/xor are legal for all supported vector VT's. |
| 182 | setOperationAction(ISD::ADD , (MVT::ValueType)VT, Legal); |
| 183 | setOperationAction(ISD::SUB , (MVT::ValueType)VT, Legal); |
| 184 | setOperationAction(ISD::AND , (MVT::ValueType)VT, Legal); |
| 185 | setOperationAction(ISD::OR , (MVT::ValueType)VT, Legal); |
| 186 | setOperationAction(ISD::XOR , (MVT::ValueType)VT, Legal); |
| 187 | |
Chris Lattner | 7ff7e67 | 2006-04-04 17:25:31 +0000 | [diff] [blame] | 188 | // We promote all shuffles to v16i8. |
| 189 | setOperationAction(ISD::VECTOR_SHUFFLE, (MVT::ValueType)VT, Promote); |
| 190 | AddPromotedToType(ISD::VECTOR_SHUFFLE, (MVT::ValueType)VT, MVT::v16i8); |
Chris Lattner | e3fea5a | 2006-03-31 19:52:36 +0000 | [diff] [blame] | 191 | |
| 192 | setOperationAction(ISD::MUL , (MVT::ValueType)VT, Expand); |
| 193 | setOperationAction(ISD::SDIV, (MVT::ValueType)VT, Expand); |
| 194 | setOperationAction(ISD::SREM, (MVT::ValueType)VT, Expand); |
| 195 | setOperationAction(ISD::UDIV, (MVT::ValueType)VT, Expand); |
| 196 | setOperationAction(ISD::UREM, (MVT::ValueType)VT, Expand); |
| 197 | setOperationAction(ISD::EXTRACT_VECTOR_ELT, (MVT::ValueType)VT, Expand); |
| 198 | setOperationAction(ISD::INSERT_VECTOR_ELT, (MVT::ValueType)VT, Expand); |
| 199 | setOperationAction(ISD::BUILD_VECTOR, (MVT::ValueType)VT, Expand); |
Chris Lattner | 01cae07 | 2006-04-03 23:55:43 +0000 | [diff] [blame] | 200 | |
| 201 | setOperationAction(ISD::SCALAR_TO_VECTOR, (MVT::ValueType)VT, Expand); |
Chris Lattner | e3fea5a | 2006-03-31 19:52:36 +0000 | [diff] [blame] | 202 | } |
| 203 | |
Chris Lattner | 7ff7e67 | 2006-04-04 17:25:31 +0000 | [diff] [blame] | 204 | // We can custom expand all VECTOR_SHUFFLEs to VPERM, others we can handle |
| 205 | // with merges, splats, etc. |
| 206 | setOperationAction(ISD::VECTOR_SHUFFLE, MVT::v16i8, Custom); |
| 207 | |
Nate Begeman | 425a969 | 2005-11-29 08:17:20 +0000 | [diff] [blame] | 208 | addRegisterClass(MVT::v4f32, PPC::VRRCRegisterClass); |
Nate Begeman | 7fd1edd | 2005-12-19 23:25:09 +0000 | [diff] [blame] | 209 | addRegisterClass(MVT::v4i32, PPC::VRRCRegisterClass); |
Chris Lattner | 8d052bc | 2006-03-25 07:39:07 +0000 | [diff] [blame] | 210 | addRegisterClass(MVT::v8i16, PPC::VRRCRegisterClass); |
| 211 | addRegisterClass(MVT::v16i8, PPC::VRRCRegisterClass); |
Chris Lattner | ec4a0c7 | 2006-01-29 06:32:58 +0000 | [diff] [blame] | 212 | |
Chris Lattner | e3fea5a | 2006-03-31 19:52:36 +0000 | [diff] [blame] | 213 | setOperationAction(ISD::MUL, MVT::v4f32, Legal); |
Chris Lattner | f1d0b2b | 2006-03-20 01:53:53 +0000 | [diff] [blame] | 214 | |
Chris Lattner | b2177b9 | 2006-03-19 06:55:52 +0000 | [diff] [blame] | 215 | setOperationAction(ISD::SCALAR_TO_VECTOR, MVT::v4f32, Custom); |
| 216 | setOperationAction(ISD::SCALAR_TO_VECTOR, MVT::v4i32, Custom); |
Chris Lattner | 64b3a08 | 2006-03-24 07:48:08 +0000 | [diff] [blame] | 217 | |
Chris Lattner | 541f91b | 2006-04-02 00:43:36 +0000 | [diff] [blame] | 218 | setOperationAction(ISD::BUILD_VECTOR, MVT::v16i8, Custom); |
| 219 | setOperationAction(ISD::BUILD_VECTOR, MVT::v8i16, Custom); |
Chris Lattner | 64b3a08 | 2006-03-24 07:48:08 +0000 | [diff] [blame] | 220 | setOperationAction(ISD::BUILD_VECTOR, MVT::v4i32, Custom); |
| 221 | setOperationAction(ISD::BUILD_VECTOR, MVT::v4f32, Custom); |
Nate Begeman | 425a969 | 2005-11-29 08:17:20 +0000 | [diff] [blame] | 222 | } |
| 223 | |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 224 | setSetCCResultContents(ZeroOrOneSetCCResult); |
Chris Lattner | cadd742 | 2006-01-13 17:52:03 +0000 | [diff] [blame] | 225 | setStackPointerRegisterToSaveRestore(PPC::R1); |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 226 | |
Chris Lattner | 8c13d0a | 2006-03-01 04:57:39 +0000 | [diff] [blame] | 227 | // We have target-specific dag combine patterns for the following nodes: |
| 228 | setTargetDAGCombine(ISD::SINT_TO_FP); |
Chris Lattner | 5126984 | 2006-03-01 05:50:56 +0000 | [diff] [blame] | 229 | setTargetDAGCombine(ISD::STORE); |
Chris Lattner | 8c13d0a | 2006-03-01 04:57:39 +0000 | [diff] [blame] | 230 | |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 231 | computeRegisterProperties(); |
| 232 | } |
| 233 | |
Chris Lattner | da6d20f | 2006-01-09 23:52:17 +0000 | [diff] [blame] | 234 | const char *PPCTargetLowering::getTargetNodeName(unsigned Opcode) const { |
| 235 | switch (Opcode) { |
| 236 | default: return 0; |
| 237 | case PPCISD::FSEL: return "PPCISD::FSEL"; |
| 238 | case PPCISD::FCFID: return "PPCISD::FCFID"; |
| 239 | case PPCISD::FCTIDZ: return "PPCISD::FCTIDZ"; |
| 240 | case PPCISD::FCTIWZ: return "PPCISD::FCTIWZ"; |
Chris Lattner | 5126984 | 2006-03-01 05:50:56 +0000 | [diff] [blame] | 241 | case PPCISD::STFIWX: return "PPCISD::STFIWX"; |
Chris Lattner | da6d20f | 2006-01-09 23:52:17 +0000 | [diff] [blame] | 242 | case PPCISD::VMADDFP: return "PPCISD::VMADDFP"; |
| 243 | case PPCISD::VNMSUBFP: return "PPCISD::VNMSUBFP"; |
Chris Lattner | f1d0b2b | 2006-03-20 01:53:53 +0000 | [diff] [blame] | 244 | case PPCISD::VPERM: return "PPCISD::VPERM"; |
Chris Lattner | da6d20f | 2006-01-09 23:52:17 +0000 | [diff] [blame] | 245 | case PPCISD::Hi: return "PPCISD::Hi"; |
| 246 | case PPCISD::Lo: return "PPCISD::Lo"; |
| 247 | case PPCISD::GlobalBaseReg: return "PPCISD::GlobalBaseReg"; |
| 248 | case PPCISD::SRL: return "PPCISD::SRL"; |
| 249 | case PPCISD::SRA: return "PPCISD::SRA"; |
| 250 | case PPCISD::SHL: return "PPCISD::SHL"; |
Chris Lattner | ecfe55e | 2006-03-22 05:30:33 +0000 | [diff] [blame] | 251 | case PPCISD::EXTSW_32: return "PPCISD::EXTSW_32"; |
| 252 | case PPCISD::STD_32: return "PPCISD::STD_32"; |
Chris Lattner | e00ebf0 | 2006-01-28 07:33:03 +0000 | [diff] [blame] | 253 | case PPCISD::CALL: return "PPCISD::CALL"; |
Chris Lattner | da6d20f | 2006-01-09 23:52:17 +0000 | [diff] [blame] | 254 | case PPCISD::RET_FLAG: return "PPCISD::RET_FLAG"; |
Chris Lattner | 6d92cad | 2006-03-26 10:06:40 +0000 | [diff] [blame] | 255 | case PPCISD::MFCR: return "PPCISD::MFCR"; |
Chris Lattner | a17b155 | 2006-03-31 05:13:27 +0000 | [diff] [blame] | 256 | case PPCISD::VCMP: return "PPCISD::VCMP"; |
Chris Lattner | 6d92cad | 2006-03-26 10:06:40 +0000 | [diff] [blame] | 257 | case PPCISD::VCMPo: return "PPCISD::VCMPo"; |
Chris Lattner | da6d20f | 2006-01-09 23:52:17 +0000 | [diff] [blame] | 258 | } |
| 259 | } |
| 260 | |
Chris Lattner | 0b1e4e5 | 2005-08-26 17:36:52 +0000 | [diff] [blame] | 261 | /// isFloatingPointZero - Return true if this is 0.0 or -0.0. |
| 262 | static bool isFloatingPointZero(SDOperand Op) { |
| 263 | if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(Op)) |
| 264 | return CFP->isExactlyValue(-0.0) || CFP->isExactlyValue(0.0); |
| 265 | else if (Op.getOpcode() == ISD::EXTLOAD || Op.getOpcode() == ISD::LOAD) { |
| 266 | // Maybe this has already been legalized into the constant pool? |
| 267 | if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(Op.getOperand(1))) |
| 268 | if (ConstantFP *CFP = dyn_cast<ConstantFP>(CP->get())) |
| 269 | return CFP->isExactlyValue(-0.0) || CFP->isExactlyValue(0.0); |
| 270 | } |
| 271 | return false; |
| 272 | } |
| 273 | |
Chris Lattner | ddb739e | 2006-04-06 17:23:16 +0000 | [diff] [blame] | 274 | /// isConstantOrUndef - Op is either an undef node or a ConstantSDNode. Return |
| 275 | /// true if Op is undef or if it matches the specified value. |
| 276 | static bool isConstantOrUndef(SDOperand Op, unsigned Val) { |
| 277 | return Op.getOpcode() == ISD::UNDEF || |
| 278 | cast<ConstantSDNode>(Op)->getValue() == Val; |
| 279 | } |
| 280 | |
| 281 | /// isVPKUHUMShuffleMask - Return true if this is the shuffle mask for a |
| 282 | /// VPKUHUM instruction. |
Chris Lattner | f24380e | 2006-04-06 22:28:36 +0000 | [diff] [blame] | 283 | bool PPC::isVPKUHUMShuffleMask(SDNode *N, bool isUnary) { |
| 284 | if (!isUnary) { |
| 285 | for (unsigned i = 0; i != 16; ++i) |
| 286 | if (!isConstantOrUndef(N->getOperand(i), i*2+1)) |
| 287 | return false; |
| 288 | } else { |
| 289 | for (unsigned i = 0; i != 8; ++i) |
| 290 | if (!isConstantOrUndef(N->getOperand(i), i*2+1) || |
| 291 | !isConstantOrUndef(N->getOperand(i+8), i*2+1)) |
| 292 | return false; |
| 293 | } |
Chris Lattner | d0608e1 | 2006-04-06 18:26:28 +0000 | [diff] [blame] | 294 | return true; |
Chris Lattner | ddb739e | 2006-04-06 17:23:16 +0000 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | /// isVPKUWUMShuffleMask - Return true if this is the shuffle mask for a |
| 298 | /// VPKUWUM instruction. |
Chris Lattner | f24380e | 2006-04-06 22:28:36 +0000 | [diff] [blame] | 299 | bool PPC::isVPKUWUMShuffleMask(SDNode *N, bool isUnary) { |
| 300 | if (!isUnary) { |
| 301 | for (unsigned i = 0; i != 16; i += 2) |
| 302 | if (!isConstantOrUndef(N->getOperand(i ), i*2+2) || |
| 303 | !isConstantOrUndef(N->getOperand(i+1), i*2+3)) |
| 304 | return false; |
| 305 | } else { |
| 306 | for (unsigned i = 0; i != 8; i += 2) |
| 307 | if (!isConstantOrUndef(N->getOperand(i ), i*2+2) || |
| 308 | !isConstantOrUndef(N->getOperand(i+1), i*2+3) || |
| 309 | !isConstantOrUndef(N->getOperand(i+8), i*2+2) || |
| 310 | !isConstantOrUndef(N->getOperand(i+9), i*2+3)) |
| 311 | return false; |
| 312 | } |
Chris Lattner | d0608e1 | 2006-04-06 18:26:28 +0000 | [diff] [blame] | 313 | return true; |
Chris Lattner | ddb739e | 2006-04-06 17:23:16 +0000 | [diff] [blame] | 314 | } |
| 315 | |
Chris Lattner | caad163 | 2006-04-06 22:02:42 +0000 | [diff] [blame] | 316 | /// isVMerge - Common function, used to match vmrg* shuffles. |
| 317 | /// |
| 318 | static bool isVMerge(SDNode *N, unsigned UnitSize, |
| 319 | unsigned LHSStart, unsigned RHSStart) { |
Chris Lattner | 116cc48 | 2006-04-06 21:11:54 +0000 | [diff] [blame] | 320 | assert(N->getOpcode() == ISD::BUILD_VECTOR && |
| 321 | N->getNumOperands() == 16 && "PPC only supports shuffles by bytes!"); |
| 322 | assert((UnitSize == 1 || UnitSize == 2 || UnitSize == 4) && |
| 323 | "Unsupported merge size!"); |
| 324 | |
| 325 | for (unsigned i = 0; i != 8/UnitSize; ++i) // Step over units |
| 326 | for (unsigned j = 0; j != UnitSize; ++j) { // Step over bytes within unit |
| 327 | if (!isConstantOrUndef(N->getOperand(i*UnitSize*2+j), |
Chris Lattner | caad163 | 2006-04-06 22:02:42 +0000 | [diff] [blame] | 328 | LHSStart+j+i*UnitSize) || |
Chris Lattner | 116cc48 | 2006-04-06 21:11:54 +0000 | [diff] [blame] | 329 | !isConstantOrUndef(N->getOperand(i*UnitSize*2+UnitSize+j), |
Chris Lattner | caad163 | 2006-04-06 22:02:42 +0000 | [diff] [blame] | 330 | RHSStart+j+i*UnitSize)) |
Chris Lattner | 116cc48 | 2006-04-06 21:11:54 +0000 | [diff] [blame] | 331 | return false; |
| 332 | } |
Chris Lattner | caad163 | 2006-04-06 22:02:42 +0000 | [diff] [blame] | 333 | return true; |
| 334 | } |
| 335 | |
| 336 | /// isVMRGLShuffleMask - Return true if this is a shuffle mask suitable for |
| 337 | /// a VRGL* instruction with the specified unit size (1,2 or 4 bytes). |
| 338 | bool PPC::isVMRGLShuffleMask(SDNode *N, unsigned UnitSize, bool isUnary) { |
| 339 | if (!isUnary) |
| 340 | return isVMerge(N, UnitSize, 8, 24); |
| 341 | return isVMerge(N, UnitSize, 8, 8); |
Chris Lattner | 116cc48 | 2006-04-06 21:11:54 +0000 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | /// isVMRGHShuffleMask - Return true if this is a shuffle mask suitable for |
| 345 | /// a VRGH* instruction with the specified unit size (1,2 or 4 bytes). |
Chris Lattner | caad163 | 2006-04-06 22:02:42 +0000 | [diff] [blame] | 346 | bool PPC::isVMRGHShuffleMask(SDNode *N, unsigned UnitSize, bool isUnary) { |
| 347 | if (!isUnary) |
| 348 | return isVMerge(N, UnitSize, 0, 16); |
| 349 | return isVMerge(N, UnitSize, 0, 0); |
Chris Lattner | 116cc48 | 2006-04-06 21:11:54 +0000 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | |
Chris Lattner | d0608e1 | 2006-04-06 18:26:28 +0000 | [diff] [blame] | 353 | /// isVSLDOIShuffleMask - If this is a vsldoi shuffle mask, return the shift |
| 354 | /// amount, otherwise return -1. |
Chris Lattner | f24380e | 2006-04-06 22:28:36 +0000 | [diff] [blame] | 355 | int PPC::isVSLDOIShuffleMask(SDNode *N, bool isUnary) { |
Chris Lattner | 116cc48 | 2006-04-06 21:11:54 +0000 | [diff] [blame] | 356 | assert(N->getOpcode() == ISD::BUILD_VECTOR && |
| 357 | N->getNumOperands() == 16 && "PPC only supports shuffles by bytes!"); |
Chris Lattner | d0608e1 | 2006-04-06 18:26:28 +0000 | [diff] [blame] | 358 | // Find the first non-undef value in the shuffle mask. |
| 359 | unsigned i; |
| 360 | for (i = 0; i != 16 && N->getOperand(i).getOpcode() == ISD::UNDEF; ++i) |
| 361 | /*search*/; |
| 362 | |
| 363 | if (i == 16) return -1; // all undef. |
| 364 | |
| 365 | // Otherwise, check to see if the rest of the elements are consequtively |
| 366 | // numbered from this value. |
| 367 | unsigned ShiftAmt = cast<ConstantSDNode>(N->getOperand(i))->getValue(); |
| 368 | if (ShiftAmt < i) return -1; |
| 369 | ShiftAmt -= i; |
Chris Lattner | ddb739e | 2006-04-06 17:23:16 +0000 | [diff] [blame] | 370 | |
Chris Lattner | f24380e | 2006-04-06 22:28:36 +0000 | [diff] [blame] | 371 | if (!isUnary) { |
| 372 | // Check the rest of the elements to see if they are consequtive. |
| 373 | for (++i; i != 16; ++i) |
| 374 | if (!isConstantOrUndef(N->getOperand(i), ShiftAmt+i)) |
| 375 | return -1; |
| 376 | } else { |
| 377 | // Check the rest of the elements to see if they are consequtive. |
| 378 | for (++i; i != 16; ++i) |
| 379 | if (!isConstantOrUndef(N->getOperand(i), (ShiftAmt+i) & 15)) |
| 380 | return -1; |
| 381 | } |
Chris Lattner | d0608e1 | 2006-04-06 18:26:28 +0000 | [diff] [blame] | 382 | |
| 383 | return ShiftAmt; |
| 384 | } |
Chris Lattner | ef819f8 | 2006-03-20 06:33:01 +0000 | [diff] [blame] | 385 | |
| 386 | /// isSplatShuffleMask - Return true if the specified VECTOR_SHUFFLE operand |
| 387 | /// specifies a splat of a single element that is suitable for input to |
| 388 | /// VSPLTB/VSPLTH/VSPLTW. |
Chris Lattner | 7ff7e67 | 2006-04-04 17:25:31 +0000 | [diff] [blame] | 389 | bool PPC::isSplatShuffleMask(SDNode *N, unsigned EltSize) { |
| 390 | assert(N->getOpcode() == ISD::BUILD_VECTOR && |
| 391 | N->getNumOperands() == 16 && |
| 392 | (EltSize == 1 || EltSize == 2 || EltSize == 4)); |
Chris Lattner | dd4d2d0 | 2006-03-20 06:51:10 +0000 | [diff] [blame] | 393 | |
Chris Lattner | 88a99ef | 2006-03-20 06:37:44 +0000 | [diff] [blame] | 394 | // This is a splat operation if each element of the permute is the same, and |
| 395 | // if the value doesn't reference the second vector. |
Chris Lattner | 7ff7e67 | 2006-04-04 17:25:31 +0000 | [diff] [blame] | 396 | unsigned ElementBase = 0; |
Chris Lattner | 88a99ef | 2006-03-20 06:37:44 +0000 | [diff] [blame] | 397 | SDOperand Elt = N->getOperand(0); |
Chris Lattner | 7ff7e67 | 2006-04-04 17:25:31 +0000 | [diff] [blame] | 398 | if (ConstantSDNode *EltV = dyn_cast<ConstantSDNode>(Elt)) |
| 399 | ElementBase = EltV->getValue(); |
| 400 | else |
| 401 | return false; // FIXME: Handle UNDEF elements too! |
| 402 | |
| 403 | if (cast<ConstantSDNode>(Elt)->getValue() >= 16) |
| 404 | return false; |
| 405 | |
| 406 | // Check that they are consequtive. |
| 407 | for (unsigned i = 1; i != EltSize; ++i) { |
| 408 | if (!isa<ConstantSDNode>(N->getOperand(i)) || |
| 409 | cast<ConstantSDNode>(N->getOperand(i))->getValue() != i+ElementBase) |
| 410 | return false; |
| 411 | } |
| 412 | |
Chris Lattner | 88a99ef | 2006-03-20 06:37:44 +0000 | [diff] [blame] | 413 | assert(isa<ConstantSDNode>(Elt) && "Invalid VECTOR_SHUFFLE mask!"); |
Chris Lattner | 7ff7e67 | 2006-04-04 17:25:31 +0000 | [diff] [blame] | 414 | for (unsigned i = EltSize, e = 16; i != e; i += EltSize) { |
Chris Lattner | 88a99ef | 2006-03-20 06:37:44 +0000 | [diff] [blame] | 415 | assert(isa<ConstantSDNode>(N->getOperand(i)) && |
| 416 | "Invalid VECTOR_SHUFFLE mask!"); |
Chris Lattner | 7ff7e67 | 2006-04-04 17:25:31 +0000 | [diff] [blame] | 417 | for (unsigned j = 0; j != EltSize; ++j) |
| 418 | if (N->getOperand(i+j) != N->getOperand(j)) |
| 419 | return false; |
Chris Lattner | 88a99ef | 2006-03-20 06:37:44 +0000 | [diff] [blame] | 420 | } |
| 421 | |
Chris Lattner | 7ff7e67 | 2006-04-04 17:25:31 +0000 | [diff] [blame] | 422 | return true; |
Chris Lattner | ef819f8 | 2006-03-20 06:33:01 +0000 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | /// getVSPLTImmediate - Return the appropriate VSPLT* immediate to splat the |
| 426 | /// specified isSplatShuffleMask VECTOR_SHUFFLE mask. |
Chris Lattner | 7ff7e67 | 2006-04-04 17:25:31 +0000 | [diff] [blame] | 427 | unsigned PPC::getVSPLTImmediate(SDNode *N, unsigned EltSize) { |
| 428 | assert(isSplatShuffleMask(N, EltSize)); |
| 429 | return cast<ConstantSDNode>(N->getOperand(0))->getValue() / EltSize; |
Chris Lattner | ef819f8 | 2006-03-20 06:33:01 +0000 | [diff] [blame] | 430 | } |
| 431 | |
Chris Lattner | 140a58f | 2006-04-08 06:46:53 +0000 | [diff] [blame] | 432 | /// get_VSPLI_elt - If this is a build_vector of constants which can be formed |
| 433 | /// by using a vspltis[bhw] instruction of the specified element size, return |
| 434 | /// the constant being splatted. The ByteSize field indicates the number of |
| 435 | /// bytes of each element [124] -> [bhw]. |
| 436 | SDOperand PPC::get_VSPLI_elt(SDNode *N, unsigned ByteSize, SelectionDAG &DAG) { |
Chris Lattner | 9c61dcf | 2006-03-25 06:12:06 +0000 | [diff] [blame] | 437 | SDOperand OpVal(0, 0); |
Chris Lattner | 79d9a88 | 2006-04-08 07:14:26 +0000 | [diff] [blame] | 438 | |
| 439 | // If ByteSize of the splat is bigger than the element size of the |
| 440 | // build_vector, then we have a case where we are checking for a splat where |
| 441 | // multiple elements of the buildvector are folded together into a single |
| 442 | // logical element of the splat (e.g. "vsplish 1" to splat {0,1}*8). |
| 443 | unsigned EltSize = 16/N->getNumOperands(); |
| 444 | if (EltSize < ByteSize) { |
| 445 | unsigned Multiple = ByteSize/EltSize; // Number of BV entries per spltval. |
| 446 | SDOperand UniquedVals[4]; |
| 447 | assert(Multiple > 1 && Multiple <= 4 && "How can this happen?"); |
| 448 | |
| 449 | // See if all of the elements in the buildvector agree across. |
| 450 | for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) { |
| 451 | if (N->getOperand(i).getOpcode() == ISD::UNDEF) continue; |
| 452 | // If the element isn't a constant, bail fully out. |
| 453 | if (!isa<ConstantSDNode>(N->getOperand(i))) return SDOperand(); |
| 454 | |
| 455 | |
| 456 | if (UniquedVals[i&(Multiple-1)].Val == 0) |
| 457 | UniquedVals[i&(Multiple-1)] = N->getOperand(i); |
| 458 | else if (UniquedVals[i&(Multiple-1)] != N->getOperand(i)) |
| 459 | return SDOperand(); // no match. |
| 460 | } |
| 461 | |
| 462 | // Okay, if we reached this point, UniquedVals[0..Multiple-1] contains |
| 463 | // either constant or undef values that are identical for each chunk. See |
| 464 | // if these chunks can form into a larger vspltis*. |
| 465 | |
| 466 | // Check to see if all of the leading entries are either 0 or -1. If |
| 467 | // neither, then this won't fit into the immediate field. |
| 468 | bool LeadingZero = true; |
| 469 | bool LeadingOnes = true; |
| 470 | for (unsigned i = 0; i != Multiple-1; ++i) { |
| 471 | if (UniquedVals[i].Val == 0) continue; // Must have been undefs. |
| 472 | |
| 473 | LeadingZero &= cast<ConstantSDNode>(UniquedVals[i])->isNullValue(); |
| 474 | LeadingOnes &= cast<ConstantSDNode>(UniquedVals[i])->isAllOnesValue(); |
| 475 | } |
| 476 | // Finally, check the least significant entry. |
| 477 | if (LeadingZero) { |
| 478 | if (UniquedVals[Multiple-1].Val == 0) |
| 479 | return DAG.getTargetConstant(0, MVT::i32); // 0,0,0,undef |
| 480 | int Val = cast<ConstantSDNode>(UniquedVals[Multiple-1])->getValue(); |
| 481 | if (Val < 16) |
| 482 | return DAG.getTargetConstant(Val, MVT::i32); // 0,0,0,4 -> vspltisw(4) |
| 483 | } |
| 484 | if (LeadingOnes) { |
| 485 | if (UniquedVals[Multiple-1].Val == 0) |
| 486 | return DAG.getTargetConstant(~0U, MVT::i32); // -1,-1,-1,undef |
| 487 | int Val =cast<ConstantSDNode>(UniquedVals[Multiple-1])->getSignExtended(); |
| 488 | if (Val >= -16) // -1,-1,-1,-2 -> vspltisw(-2) |
| 489 | return DAG.getTargetConstant(Val, MVT::i32); |
| 490 | } |
| 491 | |
| 492 | return SDOperand(); |
| 493 | } |
| 494 | |
Chris Lattner | 9c61dcf | 2006-03-25 06:12:06 +0000 | [diff] [blame] | 495 | // Check to see if this buildvec has a single non-undef value in its elements. |
| 496 | for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) { |
| 497 | if (N->getOperand(i).getOpcode() == ISD::UNDEF) continue; |
| 498 | if (OpVal.Val == 0) |
| 499 | OpVal = N->getOperand(i); |
| 500 | else if (OpVal != N->getOperand(i)) |
Chris Lattner | 140a58f | 2006-04-08 06:46:53 +0000 | [diff] [blame] | 501 | return SDOperand(); |
Chris Lattner | 9c61dcf | 2006-03-25 06:12:06 +0000 | [diff] [blame] | 502 | } |
| 503 | |
Chris Lattner | 140a58f | 2006-04-08 06:46:53 +0000 | [diff] [blame] | 504 | if (OpVal.Val == 0) return SDOperand(); // All UNDEF: use implicit def. |
Chris Lattner | 9c61dcf | 2006-03-25 06:12:06 +0000 | [diff] [blame] | 505 | |
Nate Begeman | 98e70cc | 2006-03-28 04:15:58 +0000 | [diff] [blame] | 506 | unsigned ValSizeInBytes = 0; |
| 507 | uint64_t Value = 0; |
Chris Lattner | 9c61dcf | 2006-03-25 06:12:06 +0000 | [diff] [blame] | 508 | if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(OpVal)) { |
| 509 | Value = CN->getValue(); |
| 510 | ValSizeInBytes = MVT::getSizeInBits(CN->getValueType(0))/8; |
| 511 | } else if (ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(OpVal)) { |
| 512 | assert(CN->getValueType(0) == MVT::f32 && "Only one legal FP vector type!"); |
| 513 | Value = FloatToBits(CN->getValue()); |
| 514 | ValSizeInBytes = 4; |
| 515 | } |
| 516 | |
| 517 | // If the splat value is larger than the element value, then we can never do |
| 518 | // this splat. The only case that we could fit the replicated bits into our |
| 519 | // immediate field for would be zero, and we prefer to use vxor for it. |
Chris Lattner | 140a58f | 2006-04-08 06:46:53 +0000 | [diff] [blame] | 520 | if (ValSizeInBytes < ByteSize) return SDOperand(); |
Chris Lattner | 9c61dcf | 2006-03-25 06:12:06 +0000 | [diff] [blame] | 521 | |
| 522 | // If the element value is larger than the splat value, cut it in half and |
| 523 | // check to see if the two halves are equal. Continue doing this until we |
| 524 | // get to ByteSize. This allows us to handle 0x01010101 as 0x01. |
| 525 | while (ValSizeInBytes > ByteSize) { |
| 526 | ValSizeInBytes >>= 1; |
| 527 | |
| 528 | // If the top half equals the bottom half, we're still ok. |
Chris Lattner | 9b42bdd | 2006-04-05 17:39:25 +0000 | [diff] [blame] | 529 | if (((Value >> (ValSizeInBytes*8)) & ((1 << (8*ValSizeInBytes))-1)) != |
| 530 | (Value & ((1 << (8*ValSizeInBytes))-1))) |
Chris Lattner | 140a58f | 2006-04-08 06:46:53 +0000 | [diff] [blame] | 531 | return SDOperand(); |
Chris Lattner | 9c61dcf | 2006-03-25 06:12:06 +0000 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | // Properly sign extend the value. |
| 535 | int ShAmt = (4-ByteSize)*8; |
| 536 | int MaskVal = ((int)Value << ShAmt) >> ShAmt; |
| 537 | |
Evan Cheng | 5b6a01b | 2006-03-26 09:52:32 +0000 | [diff] [blame] | 538 | // If this is zero, don't match, zero matches ISD::isBuildVectorAllZeros. |
Chris Lattner | 140a58f | 2006-04-08 06:46:53 +0000 | [diff] [blame] | 539 | if (MaskVal == 0) return SDOperand(); |
Chris Lattner | 9c61dcf | 2006-03-25 06:12:06 +0000 | [diff] [blame] | 540 | |
Chris Lattner | 140a58f | 2006-04-08 06:46:53 +0000 | [diff] [blame] | 541 | // Finally, if this value fits in a 5 bit sext field, return it |
| 542 | if (((MaskVal << (32-5)) >> (32-5)) == MaskVal) |
| 543 | return DAG.getTargetConstant(MaskVal, MVT::i32); |
| 544 | return SDOperand(); |
Chris Lattner | 9c61dcf | 2006-03-25 06:12:06 +0000 | [diff] [blame] | 545 | } |
| 546 | |
Chris Lattner | ef819f8 | 2006-03-20 06:33:01 +0000 | [diff] [blame] | 547 | |
Chris Lattner | e4bc9ea | 2005-08-26 00:52:45 +0000 | [diff] [blame] | 548 | /// LowerOperation - Provide custom lowering hooks for some operations. |
| 549 | /// |
Nate Begeman | 21e463b | 2005-10-16 05:39:50 +0000 | [diff] [blame] | 550 | SDOperand PPCTargetLowering::LowerOperation(SDOperand Op, SelectionDAG &DAG) { |
Chris Lattner | e4bc9ea | 2005-08-26 00:52:45 +0000 | [diff] [blame] | 551 | switch (Op.getOpcode()) { |
| 552 | default: assert(0 && "Wasn't expecting to be able to lower this!"); |
Chris Lattner | f760532 | 2005-08-31 21:09:52 +0000 | [diff] [blame] | 553 | case ISD::FP_TO_SINT: { |
Nate Begeman | c09eeec | 2005-09-06 22:03:27 +0000 | [diff] [blame] | 554 | assert(MVT::isFloatingPoint(Op.getOperand(0).getValueType())); |
Chris Lattner | 7c0d664 | 2005-10-02 06:37:13 +0000 | [diff] [blame] | 555 | SDOperand Src = Op.getOperand(0); |
| 556 | if (Src.getValueType() == MVT::f32) |
| 557 | Src = DAG.getNode(ISD::FP_EXTEND, MVT::f64, Src); |
| 558 | |
Chris Lattner | 1b95e0b | 2005-12-23 00:59:59 +0000 | [diff] [blame] | 559 | SDOperand Tmp; |
Nate Begeman | c09eeec | 2005-09-06 22:03:27 +0000 | [diff] [blame] | 560 | switch (Op.getValueType()) { |
| 561 | default: assert(0 && "Unhandled FP_TO_SINT type in custom expander!"); |
| 562 | case MVT::i32: |
Chris Lattner | 1b95e0b | 2005-12-23 00:59:59 +0000 | [diff] [blame] | 563 | Tmp = DAG.getNode(PPCISD::FCTIWZ, MVT::f64, Src); |
Nate Begeman | c09eeec | 2005-09-06 22:03:27 +0000 | [diff] [blame] | 564 | break; |
| 565 | case MVT::i64: |
Chris Lattner | 1b95e0b | 2005-12-23 00:59:59 +0000 | [diff] [blame] | 566 | Tmp = DAG.getNode(PPCISD::FCTIDZ, MVT::f64, Src); |
Nate Begeman | c09eeec | 2005-09-06 22:03:27 +0000 | [diff] [blame] | 567 | break; |
| 568 | } |
Chris Lattner | f760532 | 2005-08-31 21:09:52 +0000 | [diff] [blame] | 569 | |
Chris Lattner | 1b95e0b | 2005-12-23 00:59:59 +0000 | [diff] [blame] | 570 | // Convert the FP value to an int value through memory. |
| 571 | SDOperand Bits = DAG.getNode(ISD::BIT_CONVERT, MVT::i64, Tmp); |
| 572 | if (Op.getValueType() == MVT::i32) |
| 573 | Bits = DAG.getNode(ISD::TRUNCATE, MVT::i32, Bits); |
| 574 | return Bits; |
Nate Begeman | c09eeec | 2005-09-06 22:03:27 +0000 | [diff] [blame] | 575 | } |
Chris Lattner | ecfe55e | 2006-03-22 05:30:33 +0000 | [diff] [blame] | 576 | case ISD::SINT_TO_FP: |
| 577 | if (Op.getOperand(0).getValueType() == MVT::i64) { |
| 578 | SDOperand Bits = DAG.getNode(ISD::BIT_CONVERT, MVT::f64, Op.getOperand(0)); |
| 579 | SDOperand FP = DAG.getNode(PPCISD::FCFID, MVT::f64, Bits); |
| 580 | if (Op.getValueType() == MVT::f32) |
| 581 | FP = DAG.getNode(ISD::FP_ROUND, MVT::f32, FP); |
| 582 | return FP; |
| 583 | } else { |
| 584 | assert(Op.getOperand(0).getValueType() == MVT::i32 && |
| 585 | "Unhandled SINT_TO_FP type in custom expander!"); |
| 586 | // Since we only generate this in 64-bit mode, we can take advantage of |
| 587 | // 64-bit registers. In particular, sign extend the input value into the |
| 588 | // 64-bit register with extsw, store the WHOLE 64-bit value into the stack |
| 589 | // then lfd it and fcfid it. |
| 590 | MachineFrameInfo *FrameInfo = DAG.getMachineFunction().getFrameInfo(); |
| 591 | int FrameIdx = FrameInfo->CreateStackObject(8, 8); |
| 592 | SDOperand FIdx = DAG.getFrameIndex(FrameIdx, MVT::i32); |
| 593 | |
| 594 | SDOperand Ext64 = DAG.getNode(PPCISD::EXTSW_32, MVT::i32, |
| 595 | Op.getOperand(0)); |
| 596 | |
| 597 | // STD the extended value into the stack slot. |
| 598 | SDOperand Store = DAG.getNode(PPCISD::STD_32, MVT::Other, |
| 599 | DAG.getEntryNode(), Ext64, FIdx, |
| 600 | DAG.getSrcValue(NULL)); |
| 601 | // Load the value as a double. |
| 602 | SDOperand Ld = DAG.getLoad(MVT::f64, Store, FIdx, DAG.getSrcValue(NULL)); |
| 603 | |
| 604 | // FCFID it and return it. |
| 605 | SDOperand FP = DAG.getNode(PPCISD::FCFID, MVT::f64, Ld); |
| 606 | if (Op.getValueType() == MVT::f32) |
| 607 | FP = DAG.getNode(ISD::FP_ROUND, MVT::f32, FP); |
| 608 | return FP; |
| 609 | } |
Chris Lattner | 7fbcef7 | 2006-03-24 07:53:47 +0000 | [diff] [blame] | 610 | break; |
Chris Lattner | ecfe55e | 2006-03-22 05:30:33 +0000 | [diff] [blame] | 611 | |
Chris Lattner | f760532 | 2005-08-31 21:09:52 +0000 | [diff] [blame] | 612 | case ISD::SELECT_CC: { |
Chris Lattner | e4bc9ea | 2005-08-26 00:52:45 +0000 | [diff] [blame] | 613 | // Turn FP only select_cc's into fsel instructions. |
Chris Lattner | f760532 | 2005-08-31 21:09:52 +0000 | [diff] [blame] | 614 | if (!MVT::isFloatingPoint(Op.getOperand(0).getValueType()) || |
| 615 | !MVT::isFloatingPoint(Op.getOperand(2).getValueType())) |
| 616 | break; |
| 617 | |
| 618 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(4))->get(); |
| 619 | |
| 620 | // Cannot handle SETEQ/SETNE. |
| 621 | if (CC == ISD::SETEQ || CC == ISD::SETNE) break; |
| 622 | |
| 623 | MVT::ValueType ResVT = Op.getValueType(); |
| 624 | MVT::ValueType CmpVT = Op.getOperand(0).getValueType(); |
| 625 | SDOperand LHS = Op.getOperand(0), RHS = Op.getOperand(1); |
| 626 | SDOperand TV = Op.getOperand(2), FV = Op.getOperand(3); |
Chris Lattner | e4bc9ea | 2005-08-26 00:52:45 +0000 | [diff] [blame] | 627 | |
Chris Lattner | f760532 | 2005-08-31 21:09:52 +0000 | [diff] [blame] | 628 | // If the RHS of the comparison is a 0.0, we don't need to do the |
| 629 | // subtraction at all. |
| 630 | if (isFloatingPointZero(RHS)) |
Chris Lattner | e4bc9ea | 2005-08-26 00:52:45 +0000 | [diff] [blame] | 631 | switch (CC) { |
Chris Lattner | bc38dbf | 2006-01-18 19:42:35 +0000 | [diff] [blame] | 632 | default: break; // SETUO etc aren't handled by fsel. |
Chris Lattner | e4bc9ea | 2005-08-26 00:52:45 +0000 | [diff] [blame] | 633 | case ISD::SETULT: |
| 634 | case ISD::SETLT: |
Chris Lattner | f760532 | 2005-08-31 21:09:52 +0000 | [diff] [blame] | 635 | std::swap(TV, FV); // fsel is natively setge, swap operands for setlt |
Chris Lattner | e4bc9ea | 2005-08-26 00:52:45 +0000 | [diff] [blame] | 636 | case ISD::SETUGE: |
| 637 | case ISD::SETGE: |
Chris Lattner | eb255f2 | 2005-10-25 20:54:57 +0000 | [diff] [blame] | 638 | if (LHS.getValueType() == MVT::f32) // Comparison is always 64-bits |
| 639 | LHS = DAG.getNode(ISD::FP_EXTEND, MVT::f64, LHS); |
Chris Lattner | f760532 | 2005-08-31 21:09:52 +0000 | [diff] [blame] | 640 | return DAG.getNode(PPCISD::FSEL, ResVT, LHS, TV, FV); |
Chris Lattner | e4bc9ea | 2005-08-26 00:52:45 +0000 | [diff] [blame] | 641 | case ISD::SETUGT: |
| 642 | case ISD::SETGT: |
Chris Lattner | f760532 | 2005-08-31 21:09:52 +0000 | [diff] [blame] | 643 | std::swap(TV, FV); // fsel is natively setge, swap operands for setlt |
Chris Lattner | e4bc9ea | 2005-08-26 00:52:45 +0000 | [diff] [blame] | 644 | case ISD::SETULE: |
| 645 | case ISD::SETLE: |
Chris Lattner | eb255f2 | 2005-10-25 20:54:57 +0000 | [diff] [blame] | 646 | if (LHS.getValueType() == MVT::f32) // Comparison is always 64-bits |
| 647 | LHS = DAG.getNode(ISD::FP_EXTEND, MVT::f64, LHS); |
Chris Lattner | 0bbea95 | 2005-08-26 20:25:03 +0000 | [diff] [blame] | 648 | return DAG.getNode(PPCISD::FSEL, ResVT, |
Chris Lattner | 85fd97d | 2005-10-26 18:01:11 +0000 | [diff] [blame] | 649 | DAG.getNode(ISD::FNEG, MVT::f64, LHS), TV, FV); |
Chris Lattner | e4bc9ea | 2005-08-26 00:52:45 +0000 | [diff] [blame] | 650 | } |
Chris Lattner | f760532 | 2005-08-31 21:09:52 +0000 | [diff] [blame] | 651 | |
Chris Lattner | eb255f2 | 2005-10-25 20:54:57 +0000 | [diff] [blame] | 652 | SDOperand Cmp; |
Chris Lattner | f760532 | 2005-08-31 21:09:52 +0000 | [diff] [blame] | 653 | switch (CC) { |
Chris Lattner | bc38dbf | 2006-01-18 19:42:35 +0000 | [diff] [blame] | 654 | default: break; // SETUO etc aren't handled by fsel. |
Chris Lattner | f760532 | 2005-08-31 21:09:52 +0000 | [diff] [blame] | 655 | case ISD::SETULT: |
| 656 | case ISD::SETLT: |
Chris Lattner | eb255f2 | 2005-10-25 20:54:57 +0000 | [diff] [blame] | 657 | Cmp = DAG.getNode(ISD::FSUB, CmpVT, LHS, RHS); |
| 658 | if (Cmp.getValueType() == MVT::f32) // Comparison is always 64-bits |
| 659 | Cmp = DAG.getNode(ISD::FP_EXTEND, MVT::f64, Cmp); |
| 660 | return DAG.getNode(PPCISD::FSEL, ResVT, Cmp, FV, TV); |
Chris Lattner | f760532 | 2005-08-31 21:09:52 +0000 | [diff] [blame] | 661 | case ISD::SETUGE: |
| 662 | case ISD::SETGE: |
Chris Lattner | eb255f2 | 2005-10-25 20:54:57 +0000 | [diff] [blame] | 663 | Cmp = DAG.getNode(ISD::FSUB, CmpVT, LHS, RHS); |
| 664 | if (Cmp.getValueType() == MVT::f32) // Comparison is always 64-bits |
| 665 | Cmp = DAG.getNode(ISD::FP_EXTEND, MVT::f64, Cmp); |
| 666 | return DAG.getNode(PPCISD::FSEL, ResVT, Cmp, TV, FV); |
Chris Lattner | f760532 | 2005-08-31 21:09:52 +0000 | [diff] [blame] | 667 | case ISD::SETUGT: |
| 668 | case ISD::SETGT: |
Chris Lattner | eb255f2 | 2005-10-25 20:54:57 +0000 | [diff] [blame] | 669 | Cmp = DAG.getNode(ISD::FSUB, CmpVT, RHS, LHS); |
| 670 | if (Cmp.getValueType() == MVT::f32) // Comparison is always 64-bits |
| 671 | Cmp = DAG.getNode(ISD::FP_EXTEND, MVT::f64, Cmp); |
| 672 | return DAG.getNode(PPCISD::FSEL, ResVT, Cmp, FV, TV); |
Chris Lattner | f760532 | 2005-08-31 21:09:52 +0000 | [diff] [blame] | 673 | case ISD::SETULE: |
| 674 | case ISD::SETLE: |
Chris Lattner | eb255f2 | 2005-10-25 20:54:57 +0000 | [diff] [blame] | 675 | Cmp = DAG.getNode(ISD::FSUB, CmpVT, RHS, LHS); |
| 676 | if (Cmp.getValueType() == MVT::f32) // Comparison is always 64-bits |
| 677 | Cmp = DAG.getNode(ISD::FP_EXTEND, MVT::f64, Cmp); |
| 678 | return DAG.getNode(PPCISD::FSEL, ResVT, Cmp, TV, FV); |
Chris Lattner | e4bc9ea | 2005-08-26 00:52:45 +0000 | [diff] [blame] | 679 | } |
Chris Lattner | f760532 | 2005-08-31 21:09:52 +0000 | [diff] [blame] | 680 | break; |
| 681 | } |
Chris Lattner | bc11c34 | 2005-08-31 20:23:54 +0000 | [diff] [blame] | 682 | case ISD::SHL: { |
| 683 | assert(Op.getValueType() == MVT::i64 && |
| 684 | Op.getOperand(1).getValueType() == MVT::i32 && "Unexpected SHL!"); |
| 685 | // The generic code does a fine job expanding shift by a constant. |
| 686 | if (isa<ConstantSDNode>(Op.getOperand(1))) break; |
| 687 | |
| 688 | // Otherwise, expand into a bunch of logical ops. Note that these ops |
| 689 | // depend on the PPC behavior for oversized shift amounts. |
| 690 | SDOperand Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32, Op.getOperand(0), |
| 691 | DAG.getConstant(0, MVT::i32)); |
| 692 | SDOperand Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32, Op.getOperand(0), |
| 693 | DAG.getConstant(1, MVT::i32)); |
| 694 | SDOperand Amt = Op.getOperand(1); |
| 695 | |
| 696 | SDOperand Tmp1 = DAG.getNode(ISD::SUB, MVT::i32, |
| 697 | DAG.getConstant(32, MVT::i32), Amt); |
Chris Lattner | 4172b10 | 2005-12-06 02:10:38 +0000 | [diff] [blame] | 698 | SDOperand Tmp2 = DAG.getNode(PPCISD::SHL, MVT::i32, Hi, Amt); |
| 699 | SDOperand Tmp3 = DAG.getNode(PPCISD::SRL, MVT::i32, Lo, Tmp1); |
Chris Lattner | bc11c34 | 2005-08-31 20:23:54 +0000 | [diff] [blame] | 700 | SDOperand Tmp4 = DAG.getNode(ISD::OR , MVT::i32, Tmp2, Tmp3); |
| 701 | SDOperand Tmp5 = DAG.getNode(ISD::ADD, MVT::i32, Amt, |
| 702 | DAG.getConstant(-32U, MVT::i32)); |
Chris Lattner | 4172b10 | 2005-12-06 02:10:38 +0000 | [diff] [blame] | 703 | SDOperand Tmp6 = DAG.getNode(PPCISD::SHL, MVT::i32, Lo, Tmp5); |
Chris Lattner | bc11c34 | 2005-08-31 20:23:54 +0000 | [diff] [blame] | 704 | SDOperand OutHi = DAG.getNode(ISD::OR, MVT::i32, Tmp4, Tmp6); |
Chris Lattner | 4172b10 | 2005-12-06 02:10:38 +0000 | [diff] [blame] | 705 | SDOperand OutLo = DAG.getNode(PPCISD::SHL, MVT::i32, Lo, Amt); |
Chris Lattner | bc11c34 | 2005-08-31 20:23:54 +0000 | [diff] [blame] | 706 | return DAG.getNode(ISD::BUILD_PAIR, MVT::i64, OutLo, OutHi); |
| 707 | } |
| 708 | case ISD::SRL: { |
| 709 | assert(Op.getValueType() == MVT::i64 && |
| 710 | Op.getOperand(1).getValueType() == MVT::i32 && "Unexpected SHL!"); |
| 711 | // The generic code does a fine job expanding shift by a constant. |
| 712 | if (isa<ConstantSDNode>(Op.getOperand(1))) break; |
| 713 | |
| 714 | // Otherwise, expand into a bunch of logical ops. Note that these ops |
| 715 | // depend on the PPC behavior for oversized shift amounts. |
| 716 | SDOperand Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32, Op.getOperand(0), |
| 717 | DAG.getConstant(0, MVT::i32)); |
| 718 | SDOperand Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32, Op.getOperand(0), |
| 719 | DAG.getConstant(1, MVT::i32)); |
| 720 | SDOperand Amt = Op.getOperand(1); |
| 721 | |
| 722 | SDOperand Tmp1 = DAG.getNode(ISD::SUB, MVT::i32, |
| 723 | DAG.getConstant(32, MVT::i32), Amt); |
Chris Lattner | 4172b10 | 2005-12-06 02:10:38 +0000 | [diff] [blame] | 724 | SDOperand Tmp2 = DAG.getNode(PPCISD::SRL, MVT::i32, Lo, Amt); |
| 725 | SDOperand Tmp3 = DAG.getNode(PPCISD::SHL, MVT::i32, Hi, Tmp1); |
Chris Lattner | bc11c34 | 2005-08-31 20:23:54 +0000 | [diff] [blame] | 726 | SDOperand Tmp4 = DAG.getNode(ISD::OR , MVT::i32, Tmp2, Tmp3); |
| 727 | SDOperand Tmp5 = DAG.getNode(ISD::ADD, MVT::i32, Amt, |
| 728 | DAG.getConstant(-32U, MVT::i32)); |
Chris Lattner | 4172b10 | 2005-12-06 02:10:38 +0000 | [diff] [blame] | 729 | SDOperand Tmp6 = DAG.getNode(PPCISD::SRL, MVT::i32, Hi, Tmp5); |
Chris Lattner | bc11c34 | 2005-08-31 20:23:54 +0000 | [diff] [blame] | 730 | SDOperand OutLo = DAG.getNode(ISD::OR, MVT::i32, Tmp4, Tmp6); |
Chris Lattner | 4172b10 | 2005-12-06 02:10:38 +0000 | [diff] [blame] | 731 | SDOperand OutHi = DAG.getNode(PPCISD::SRL, MVT::i32, Hi, Amt); |
Chris Lattner | bc11c34 | 2005-08-31 20:23:54 +0000 | [diff] [blame] | 732 | return DAG.getNode(ISD::BUILD_PAIR, MVT::i64, OutLo, OutHi); |
| 733 | } |
| 734 | case ISD::SRA: { |
Chris Lattner | eb9b62e | 2005-08-31 19:09:57 +0000 | [diff] [blame] | 735 | assert(Op.getValueType() == MVT::i64 && |
| 736 | Op.getOperand(1).getValueType() == MVT::i32 && "Unexpected SRA!"); |
| 737 | // The generic code does a fine job expanding shift by a constant. |
| 738 | if (isa<ConstantSDNode>(Op.getOperand(1))) break; |
| 739 | |
| 740 | // Otherwise, expand into a bunch of logical ops, followed by a select_cc. |
| 741 | SDOperand Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32, Op.getOperand(0), |
| 742 | DAG.getConstant(0, MVT::i32)); |
| 743 | SDOperand Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32, Op.getOperand(0), |
| 744 | DAG.getConstant(1, MVT::i32)); |
| 745 | SDOperand Amt = Op.getOperand(1); |
| 746 | |
| 747 | SDOperand Tmp1 = DAG.getNode(ISD::SUB, MVT::i32, |
| 748 | DAG.getConstant(32, MVT::i32), Amt); |
Chris Lattner | 4172b10 | 2005-12-06 02:10:38 +0000 | [diff] [blame] | 749 | SDOperand Tmp2 = DAG.getNode(PPCISD::SRL, MVT::i32, Lo, Amt); |
| 750 | SDOperand Tmp3 = DAG.getNode(PPCISD::SHL, MVT::i32, Hi, Tmp1); |
Chris Lattner | eb9b62e | 2005-08-31 19:09:57 +0000 | [diff] [blame] | 751 | SDOperand Tmp4 = DAG.getNode(ISD::OR , MVT::i32, Tmp2, Tmp3); |
| 752 | SDOperand Tmp5 = DAG.getNode(ISD::ADD, MVT::i32, Amt, |
| 753 | DAG.getConstant(-32U, MVT::i32)); |
Chris Lattner | 4172b10 | 2005-12-06 02:10:38 +0000 | [diff] [blame] | 754 | SDOperand Tmp6 = DAG.getNode(PPCISD::SRA, MVT::i32, Hi, Tmp5); |
| 755 | SDOperand OutHi = DAG.getNode(PPCISD::SRA, MVT::i32, Hi, Amt); |
Chris Lattner | eb9b62e | 2005-08-31 19:09:57 +0000 | [diff] [blame] | 756 | SDOperand OutLo = DAG.getSelectCC(Tmp5, DAG.getConstant(0, MVT::i32), |
| 757 | Tmp4, Tmp6, ISD::SETLE); |
| 758 | return DAG.getNode(ISD::BUILD_PAIR, MVT::i64, OutLo, OutHi); |
Chris Lattner | e4bc9ea | 2005-08-26 00:52:45 +0000 | [diff] [blame] | 759 | } |
Nate Begeman | 28a6b02 | 2005-12-10 02:36:00 +0000 | [diff] [blame] | 760 | case ISD::ConstantPool: { |
Evan Cheng | b8973bd | 2006-01-31 22:23:14 +0000 | [diff] [blame] | 761 | ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op); |
| 762 | Constant *C = CP->get(); |
| 763 | SDOperand CPI = DAG.getTargetConstantPool(C, MVT::i32, CP->getAlignment()); |
Nate Begeman | 28a6b02 | 2005-12-10 02:36:00 +0000 | [diff] [blame] | 764 | SDOperand Zero = DAG.getConstant(0, MVT::i32); |
| 765 | |
Evan Cheng | 4c1aa86 | 2006-02-22 20:19:42 +0000 | [diff] [blame] | 766 | if (getTargetMachine().getRelocationModel() == Reloc::Static) { |
Nate Begeman | 28a6b02 | 2005-12-10 02:36:00 +0000 | [diff] [blame] | 767 | // Generate non-pic code that has direct accesses to the constant pool. |
| 768 | // The address of the global is just (hi(&g)+lo(&g)). |
| 769 | SDOperand Hi = DAG.getNode(PPCISD::Hi, MVT::i32, CPI, Zero); |
| 770 | SDOperand Lo = DAG.getNode(PPCISD::Lo, MVT::i32, CPI, Zero); |
| 771 | return DAG.getNode(ISD::ADD, MVT::i32, Hi, Lo); |
| 772 | } |
| 773 | |
| 774 | // Only lower ConstantPool on Darwin. |
| 775 | if (!getTargetMachine().getSubtarget<PPCSubtarget>().isDarwin()) break; |
| 776 | SDOperand Hi = DAG.getNode(PPCISD::Hi, MVT::i32, CPI, Zero); |
Evan Cheng | 4c1aa86 | 2006-02-22 20:19:42 +0000 | [diff] [blame] | 777 | if (getTargetMachine().getRelocationModel() == Reloc::PIC) { |
Nate Begeman | 28a6b02 | 2005-12-10 02:36:00 +0000 | [diff] [blame] | 778 | // With PIC, the first instruction is actually "GR+hi(&G)". |
| 779 | Hi = DAG.getNode(ISD::ADD, MVT::i32, |
| 780 | DAG.getNode(PPCISD::GlobalBaseReg, MVT::i32), Hi); |
| 781 | } |
| 782 | |
| 783 | SDOperand Lo = DAG.getNode(PPCISD::Lo, MVT::i32, CPI, Zero); |
| 784 | Lo = DAG.getNode(ISD::ADD, MVT::i32, Hi, Lo); |
| 785 | return Lo; |
| 786 | } |
Chris Lattner | 860e886 | 2005-11-17 07:30:41 +0000 | [diff] [blame] | 787 | case ISD::GlobalAddress: { |
Nate Begeman | 50fb3c4 | 2005-12-24 01:00:15 +0000 | [diff] [blame] | 788 | GlobalAddressSDNode *GSDN = cast<GlobalAddressSDNode>(Op); |
| 789 | GlobalValue *GV = GSDN->getGlobal(); |
| 790 | SDOperand GA = DAG.getTargetGlobalAddress(GV, MVT::i32, GSDN->getOffset()); |
Chris Lattner | 860e886 | 2005-11-17 07:30:41 +0000 | [diff] [blame] | 791 | SDOperand Zero = DAG.getConstant(0, MVT::i32); |
Chris Lattner | 1d05cb4 | 2005-11-17 18:55:48 +0000 | [diff] [blame] | 792 | |
Evan Cheng | 4c1aa86 | 2006-02-22 20:19:42 +0000 | [diff] [blame] | 793 | if (getTargetMachine().getRelocationModel() == Reloc::Static) { |
Nate Begeman | 28a6b02 | 2005-12-10 02:36:00 +0000 | [diff] [blame] | 794 | // Generate non-pic code that has direct accesses to globals. |
| 795 | // The address of the global is just (hi(&g)+lo(&g)). |
Chris Lattner | 1d05cb4 | 2005-11-17 18:55:48 +0000 | [diff] [blame] | 796 | SDOperand Hi = DAG.getNode(PPCISD::Hi, MVT::i32, GA, Zero); |
| 797 | SDOperand Lo = DAG.getNode(PPCISD::Lo, MVT::i32, GA, Zero); |
| 798 | return DAG.getNode(ISD::ADD, MVT::i32, Hi, Lo); |
| 799 | } |
Chris Lattner | 860e886 | 2005-11-17 07:30:41 +0000 | [diff] [blame] | 800 | |
Chris Lattner | 1d05cb4 | 2005-11-17 18:55:48 +0000 | [diff] [blame] | 801 | // Only lower GlobalAddress on Darwin. |
| 802 | if (!getTargetMachine().getSubtarget<PPCSubtarget>().isDarwin()) break; |
Chris Lattner | a35ef63 | 2006-01-06 01:04:03 +0000 | [diff] [blame] | 803 | |
Chris Lattner | 860e886 | 2005-11-17 07:30:41 +0000 | [diff] [blame] | 804 | SDOperand Hi = DAG.getNode(PPCISD::Hi, MVT::i32, GA, Zero); |
Evan Cheng | 4c1aa86 | 2006-02-22 20:19:42 +0000 | [diff] [blame] | 805 | if (getTargetMachine().getRelocationModel() == Reloc::PIC) { |
Chris Lattner | 860e886 | 2005-11-17 07:30:41 +0000 | [diff] [blame] | 806 | // With PIC, the first instruction is actually "GR+hi(&G)". |
| 807 | Hi = DAG.getNode(ISD::ADD, MVT::i32, |
Chris Lattner | 1566613 | 2005-11-17 17:51:38 +0000 | [diff] [blame] | 808 | DAG.getNode(PPCISD::GlobalBaseReg, MVT::i32), Hi); |
Chris Lattner | 860e886 | 2005-11-17 07:30:41 +0000 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | SDOperand Lo = DAG.getNode(PPCISD::Lo, MVT::i32, GA, Zero); |
| 812 | Lo = DAG.getNode(ISD::ADD, MVT::i32, Hi, Lo); |
| 813 | |
Chris Lattner | 37dd6f1 | 2006-01-29 20:49:17 +0000 | [diff] [blame] | 814 | if (!GV->hasWeakLinkage() && !GV->hasLinkOnceLinkage() && |
| 815 | (!GV->isExternal() || GV->hasNotBeenReadFromBytecode())) |
Chris Lattner | 860e886 | 2005-11-17 07:30:41 +0000 | [diff] [blame] | 816 | return Lo; |
| 817 | |
| 818 | // If the global is weak or external, we have to go through the lazy |
| 819 | // resolution stub. |
| 820 | return DAG.getLoad(MVT::i32, DAG.getEntryNode(), Lo, DAG.getSrcValue(0)); |
| 821 | } |
Nate Begeman | 4477590 | 2006-01-31 08:17:29 +0000 | [diff] [blame] | 822 | case ISD::SETCC: { |
| 823 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(2))->get(); |
Nate Begeman | 750ac1b | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 824 | |
| 825 | // If we're comparing for equality to zero, expose the fact that this is |
| 826 | // implented as a ctlz/srl pair on ppc, so that the dag combiner can |
| 827 | // fold the new nodes. |
| 828 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op.getOperand(1))) { |
| 829 | if (C->isNullValue() && CC == ISD::SETEQ) { |
| 830 | MVT::ValueType VT = Op.getOperand(0).getValueType(); |
| 831 | SDOperand Zext = Op.getOperand(0); |
| 832 | if (VT < MVT::i32) { |
| 833 | VT = MVT::i32; |
| 834 | Zext = DAG.getNode(ISD::ZERO_EXTEND, VT, Op.getOperand(0)); |
| 835 | } |
| 836 | unsigned Log2b = Log2_32(MVT::getSizeInBits(VT)); |
| 837 | SDOperand Clz = DAG.getNode(ISD::CTLZ, VT, Zext); |
| 838 | SDOperand Scc = DAG.getNode(ISD::SRL, VT, Clz, |
| 839 | DAG.getConstant(Log2b, getShiftAmountTy())); |
| 840 | return DAG.getNode(ISD::TRUNCATE, getSetCCResultTy(), Scc); |
| 841 | } |
| 842 | // Leave comparisons against 0 and -1 alone for now, since they're usually |
| 843 | // optimized. FIXME: revisit this when we can custom lower all setcc |
| 844 | // optimizations. |
| 845 | if (C->isAllOnesValue() || C->isNullValue()) |
| 846 | break; |
| 847 | } |
| 848 | |
| 849 | // If we have an integer seteq/setne, turn it into a compare against zero |
| 850 | // by subtracting the rhs from the lhs, which is faster than setting a |
| 851 | // condition register, reading it back out, and masking the correct bit. |
| 852 | MVT::ValueType LHSVT = Op.getOperand(0).getValueType(); |
| 853 | if (MVT::isInteger(LHSVT) && (CC == ISD::SETEQ || CC == ISD::SETNE)) { |
| 854 | MVT::ValueType VT = Op.getValueType(); |
| 855 | SDOperand Sub = DAG.getNode(ISD::SUB, LHSVT, Op.getOperand(0), |
| 856 | Op.getOperand(1)); |
| 857 | return DAG.getSetCC(VT, Sub, DAG.getConstant(0, LHSVT), CC); |
| 858 | } |
Nate Begeman | 4477590 | 2006-01-31 08:17:29 +0000 | [diff] [blame] | 859 | break; |
| 860 | } |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 861 | case ISD::VASTART: { |
| 862 | // vastart just stores the address of the VarArgsFrameIndex slot into the |
| 863 | // memory location argument. |
| 864 | // FIXME: Replace MVT::i32 with PointerTy |
| 865 | SDOperand FR = DAG.getFrameIndex(VarArgsFrameIndex, MVT::i32); |
| 866 | return DAG.getNode(ISD::STORE, MVT::Other, Op.getOperand(0), FR, |
| 867 | Op.getOperand(1), Op.getOperand(2)); |
| 868 | } |
Nate Begeman | ee62557 | 2006-01-27 21:09:22 +0000 | [diff] [blame] | 869 | case ISD::RET: { |
| 870 | SDOperand Copy; |
| 871 | |
| 872 | switch(Op.getNumOperands()) { |
| 873 | default: |
| 874 | assert(0 && "Do not know how to return this many arguments!"); |
| 875 | abort(); |
| 876 | case 1: |
| 877 | return SDOperand(); // ret void is legal |
| 878 | case 2: { |
| 879 | MVT::ValueType ArgVT = Op.getOperand(1).getValueType(); |
Chris Lattner | bee9836 | 2006-04-11 01:38:39 +0000 | [diff] [blame] | 880 | unsigned ArgReg; |
| 881 | if (MVT::isVector(ArgVT)) |
| 882 | ArgReg = PPC::V2; |
| 883 | else if (MVT::isInteger(ArgVT)) |
| 884 | ArgReg = PPC::R3; |
| 885 | else { |
| 886 | assert(MVT::isFloatingPoint(ArgVT)); |
| 887 | ArgReg = PPC::F1; |
| 888 | } |
| 889 | |
Nate Begeman | ee62557 | 2006-01-27 21:09:22 +0000 | [diff] [blame] | 890 | Copy = DAG.getCopyToReg(Op.getOperand(0), ArgReg, Op.getOperand(1), |
| 891 | SDOperand()); |
Chris Lattner | 06c2435 | 2006-04-11 01:21:43 +0000 | [diff] [blame] | 892 | |
| 893 | // If we haven't noted the R3/F1 are live out, do so now. |
| 894 | if (DAG.getMachineFunction().liveout_empty()) |
| 895 | DAG.getMachineFunction().addLiveOut(ArgReg); |
Nate Begeman | ee62557 | 2006-01-27 21:09:22 +0000 | [diff] [blame] | 896 | break; |
| 897 | } |
| 898 | case 3: |
| 899 | Copy = DAG.getCopyToReg(Op.getOperand(0), PPC::R3, Op.getOperand(2), |
| 900 | SDOperand()); |
| 901 | Copy = DAG.getCopyToReg(Copy, PPC::R4, Op.getOperand(1),Copy.getValue(1)); |
Chris Lattner | 06c2435 | 2006-04-11 01:21:43 +0000 | [diff] [blame] | 902 | // If we haven't noted the R3+R4 are live out, do so now. |
| 903 | if (DAG.getMachineFunction().liveout_empty()) { |
| 904 | DAG.getMachineFunction().addLiveOut(PPC::R3); |
| 905 | DAG.getMachineFunction().addLiveOut(PPC::R4); |
| 906 | } |
Nate Begeman | ee62557 | 2006-01-27 21:09:22 +0000 | [diff] [blame] | 907 | break; |
| 908 | } |
| 909 | return DAG.getNode(PPCISD::RET_FLAG, MVT::Other, Copy, Copy.getValue(1)); |
| 910 | } |
Chris Lattner | b2177b9 | 2006-03-19 06:55:52 +0000 | [diff] [blame] | 911 | case ISD::SCALAR_TO_VECTOR: { |
| 912 | // Create a stack slot that is 16-byte aligned. |
| 913 | MachineFrameInfo *FrameInfo = DAG.getMachineFunction().getFrameInfo(); |
| 914 | int FrameIdx = FrameInfo->CreateStackObject(16, 16); |
| 915 | SDOperand FIdx = DAG.getFrameIndex(FrameIdx, MVT::i32); |
| 916 | |
| 917 | // Store the input value into Value#0 of the stack slot. |
Chris Lattner | b2177b9 | 2006-03-19 06:55:52 +0000 | [diff] [blame] | 918 | SDOperand Store = DAG.getNode(ISD::STORE, MVT::Other, DAG.getEntryNode(), |
| 919 | Op.getOperand(0), FIdx,DAG.getSrcValue(NULL)); |
Chris Lattner | 7f20b13 | 2006-03-28 01:43:22 +0000 | [diff] [blame] | 920 | // Load it out. |
| 921 | return DAG.getLoad(Op.getValueType(), Store, FIdx, DAG.getSrcValue(NULL)); |
Chris Lattner | b2177b9 | 2006-03-19 06:55:52 +0000 | [diff] [blame] | 922 | } |
Chris Lattner | 64b3a08 | 2006-03-24 07:48:08 +0000 | [diff] [blame] | 923 | case ISD::BUILD_VECTOR: |
| 924 | // If this is a case we can't handle, return null and let the default |
| 925 | // expansion code take care of it. If we CAN select this case, return Op. |
Chris Lattner | 2b1c325 | 2006-04-12 16:53:28 +0000 | [diff] [blame^] | 926 | |
Chris Lattner | 64b3a08 | 2006-03-24 07:48:08 +0000 | [diff] [blame] | 927 | // FIXME: We should handle splat(-0.0), and other cases here. |
Chris Lattner | 2b1c325 | 2006-04-12 16:53:28 +0000 | [diff] [blame^] | 928 | |
| 929 | // See if this is all zeros. |
| 930 | if (ISD::isBuildVectorAllZeros(Op.Val)) { |
| 931 | // Canonicalize all zero vectors to be v4i32. |
| 932 | if (Op.getValueType() != MVT::v4i32) { |
| 933 | SDOperand Z = DAG.getConstant(0, MVT::i32); |
| 934 | Z = DAG.getNode(ISD::BUILD_VECTOR, MVT::v4i32, Z, Z, Z, Z); |
| 935 | Op = DAG.getNode(ISD::BIT_CONVERT, Op.getValueType(), Z); |
| 936 | } |
Chris Lattner | 64b3a08 | 2006-03-24 07:48:08 +0000 | [diff] [blame] | 937 | return Op; |
Chris Lattner | 2b1c325 | 2006-04-12 16:53:28 +0000 | [diff] [blame^] | 938 | } |
Chris Lattner | 9c61dcf | 2006-03-25 06:12:06 +0000 | [diff] [blame] | 939 | |
Chris Lattner | 140a58f | 2006-04-08 06:46:53 +0000 | [diff] [blame] | 940 | if (PPC::get_VSPLI_elt(Op.Val, 1, DAG).Val || // vspltisb |
| 941 | PPC::get_VSPLI_elt(Op.Val, 2, DAG).Val || // vspltish |
| 942 | PPC::get_VSPLI_elt(Op.Val, 4, DAG).Val) // vspltisw |
Chris Lattner | 9c61dcf | 2006-03-25 06:12:06 +0000 | [diff] [blame] | 943 | return Op; |
| 944 | |
Chris Lattner | 64b3a08 | 2006-03-24 07:48:08 +0000 | [diff] [blame] | 945 | return SDOperand(); |
| 946 | |
Chris Lattner | f1d0b2b | 2006-03-20 01:53:53 +0000 | [diff] [blame] | 947 | case ISD::VECTOR_SHUFFLE: { |
Chris Lattner | dd4d2d0 | 2006-03-20 06:51:10 +0000 | [diff] [blame] | 948 | SDOperand V1 = Op.getOperand(0); |
| 949 | SDOperand V2 = Op.getOperand(1); |
| 950 | SDOperand PermMask = Op.getOperand(2); |
| 951 | |
| 952 | // Cases that are handled by instructions that take permute immediates |
| 953 | // (such as vsplt*) should be left as VECTOR_SHUFFLE nodes so they can be |
| 954 | // selected by the instruction selector. |
Chris Lattner | caad163 | 2006-04-06 22:02:42 +0000 | [diff] [blame] | 955 | if (V2.getOpcode() == ISD::UNDEF) { |
| 956 | if (PPC::isSplatShuffleMask(PermMask.Val, 1) || |
| 957 | PPC::isSplatShuffleMask(PermMask.Val, 2) || |
| 958 | PPC::isSplatShuffleMask(PermMask.Val, 4) || |
Chris Lattner | f24380e | 2006-04-06 22:28:36 +0000 | [diff] [blame] | 959 | PPC::isVPKUWUMShuffleMask(PermMask.Val, true) || |
| 960 | PPC::isVPKUHUMShuffleMask(PermMask.Val, true) || |
| 961 | PPC::isVSLDOIShuffleMask(PermMask.Val, true) != -1 || |
Chris Lattner | caad163 | 2006-04-06 22:02:42 +0000 | [diff] [blame] | 962 | PPC::isVMRGLShuffleMask(PermMask.Val, 1, true) || |
| 963 | PPC::isVMRGLShuffleMask(PermMask.Val, 2, true) || |
| 964 | PPC::isVMRGLShuffleMask(PermMask.Val, 4, true) || |
| 965 | PPC::isVMRGHShuffleMask(PermMask.Val, 1, true) || |
| 966 | PPC::isVMRGHShuffleMask(PermMask.Val, 2, true) || |
| 967 | PPC::isVMRGHShuffleMask(PermMask.Val, 4, true)) { |
| 968 | return Op; |
| 969 | } |
| 970 | } |
Chris Lattner | dd4d2d0 | 2006-03-20 06:51:10 +0000 | [diff] [blame] | 971 | |
Chris Lattner | f24380e | 2006-04-06 22:28:36 +0000 | [diff] [blame] | 972 | // Altivec has a variety of "shuffle immediates" that take two vector inputs |
| 973 | // and produce a fixed permutation. If any of these match, do not lower to |
| 974 | // VPERM. |
| 975 | if (PPC::isVPKUWUMShuffleMask(PermMask.Val, false) || |
| 976 | PPC::isVPKUHUMShuffleMask(PermMask.Val, false) || |
| 977 | PPC::isVSLDOIShuffleMask(PermMask.Val, false) != -1 || |
Chris Lattner | caad163 | 2006-04-06 22:02:42 +0000 | [diff] [blame] | 978 | PPC::isVMRGLShuffleMask(PermMask.Val, 1, false) || |
| 979 | PPC::isVMRGLShuffleMask(PermMask.Val, 2, false) || |
| 980 | PPC::isVMRGLShuffleMask(PermMask.Val, 4, false) || |
| 981 | PPC::isVMRGHShuffleMask(PermMask.Val, 1, false) || |
| 982 | PPC::isVMRGHShuffleMask(PermMask.Val, 2, false) || |
| 983 | PPC::isVMRGHShuffleMask(PermMask.Val, 4, false)) |
Chris Lattner | ddb739e | 2006-04-06 17:23:16 +0000 | [diff] [blame] | 984 | return Op; |
| 985 | |
Chris Lattner | dd4d2d0 | 2006-03-20 06:51:10 +0000 | [diff] [blame] | 986 | // TODO: Handle more cases, and also handle cases that are cheaper to do as |
| 987 | // multiple such instructions than as a constant pool load/vperm pair. |
Chris Lattner | f1d0b2b | 2006-03-20 01:53:53 +0000 | [diff] [blame] | 988 | |
| 989 | // Lower this to a VPERM(V1, V2, V3) expression, where V3 is a constant |
| 990 | // vector that will get spilled to the constant pool. |
Chris Lattner | f1d0b2b | 2006-03-20 01:53:53 +0000 | [diff] [blame] | 991 | if (V2.getOpcode() == ISD::UNDEF) V2 = V1; |
Chris Lattner | f1d0b2b | 2006-03-20 01:53:53 +0000 | [diff] [blame] | 992 | |
| 993 | // The SHUFFLE_VECTOR mask is almost exactly what we want for vperm, except |
| 994 | // that it is in input element units, not in bytes. Convert now. |
| 995 | MVT::ValueType EltVT = MVT::getVectorBaseType(V1.getValueType()); |
| 996 | unsigned BytesPerElement = MVT::getSizeInBits(EltVT)/8; |
| 997 | |
| 998 | std::vector<SDOperand> ResultMask; |
| 999 | for (unsigned i = 0, e = PermMask.getNumOperands(); i != e; ++i) { |
| 1000 | unsigned SrcElt =cast<ConstantSDNode>(PermMask.getOperand(i))->getValue(); |
| 1001 | |
| 1002 | for (unsigned j = 0; j != BytesPerElement; ++j) |
| 1003 | ResultMask.push_back(DAG.getConstant(SrcElt*BytesPerElement+j, |
| 1004 | MVT::i8)); |
| 1005 | } |
| 1006 | |
| 1007 | SDOperand VPermMask =DAG.getNode(ISD::BUILD_VECTOR, MVT::v16i8, ResultMask); |
| 1008 | return DAG.getNode(PPCISD::VPERM, V1.getValueType(), V1, V2, VPermMask); |
| 1009 | } |
Chris Lattner | 48b61a7 | 2006-03-28 00:40:33 +0000 | [diff] [blame] | 1010 | case ISD::INTRINSIC_WO_CHAIN: { |
Chris Lattner | bbe77de | 2006-04-02 06:26:07 +0000 | [diff] [blame] | 1011 | unsigned IntNo = cast<ConstantSDNode>(Op.getOperand(0))->getValue(); |
Chris Lattner | 6d92cad | 2006-03-26 10:06:40 +0000 | [diff] [blame] | 1012 | |
| 1013 | // If this is a lowered altivec predicate compare, CompareOpc is set to the |
| 1014 | // opcode number of the comparison. |
| 1015 | int CompareOpc = -1; |
Chris Lattner | a17b155 | 2006-03-31 05:13:27 +0000 | [diff] [blame] | 1016 | bool isDot = false; |
Chris Lattner | 6d92cad | 2006-03-26 10:06:40 +0000 | [diff] [blame] | 1017 | switch (IntNo) { |
| 1018 | default: return SDOperand(); // Don't custom lower most intrinsics. |
Chris Lattner | a17b155 | 2006-03-31 05:13:27 +0000 | [diff] [blame] | 1019 | // Comparison predicates. |
| 1020 | case Intrinsic::ppc_altivec_vcmpbfp_p: CompareOpc = 966; isDot = 1; break; |
| 1021 | case Intrinsic::ppc_altivec_vcmpeqfp_p: CompareOpc = 198; isDot = 1; break; |
| 1022 | case Intrinsic::ppc_altivec_vcmpequb_p: CompareOpc = 6; isDot = 1; break; |
| 1023 | case Intrinsic::ppc_altivec_vcmpequh_p: CompareOpc = 70; isDot = 1; break; |
| 1024 | case Intrinsic::ppc_altivec_vcmpequw_p: CompareOpc = 134; isDot = 1; break; |
| 1025 | case Intrinsic::ppc_altivec_vcmpgefp_p: CompareOpc = 454; isDot = 1; break; |
| 1026 | case Intrinsic::ppc_altivec_vcmpgtfp_p: CompareOpc = 710; isDot = 1; break; |
| 1027 | case Intrinsic::ppc_altivec_vcmpgtsb_p: CompareOpc = 774; isDot = 1; break; |
| 1028 | case Intrinsic::ppc_altivec_vcmpgtsh_p: CompareOpc = 838; isDot = 1; break; |
| 1029 | case Intrinsic::ppc_altivec_vcmpgtsw_p: CompareOpc = 902; isDot = 1; break; |
| 1030 | case Intrinsic::ppc_altivec_vcmpgtub_p: CompareOpc = 518; isDot = 1; break; |
| 1031 | case Intrinsic::ppc_altivec_vcmpgtuh_p: CompareOpc = 582; isDot = 1; break; |
| 1032 | case Intrinsic::ppc_altivec_vcmpgtuw_p: CompareOpc = 646; isDot = 1; break; |
| 1033 | |
| 1034 | // Normal Comparisons. |
| 1035 | case Intrinsic::ppc_altivec_vcmpbfp: CompareOpc = 966; isDot = 0; break; |
| 1036 | case Intrinsic::ppc_altivec_vcmpeqfp: CompareOpc = 198; isDot = 0; break; |
| 1037 | case Intrinsic::ppc_altivec_vcmpequb: CompareOpc = 6; isDot = 0; break; |
| 1038 | case Intrinsic::ppc_altivec_vcmpequh: CompareOpc = 70; isDot = 0; break; |
| 1039 | case Intrinsic::ppc_altivec_vcmpequw: CompareOpc = 134; isDot = 0; break; |
| 1040 | case Intrinsic::ppc_altivec_vcmpgefp: CompareOpc = 454; isDot = 0; break; |
| 1041 | case Intrinsic::ppc_altivec_vcmpgtfp: CompareOpc = 710; isDot = 0; break; |
| 1042 | case Intrinsic::ppc_altivec_vcmpgtsb: CompareOpc = 774; isDot = 0; break; |
| 1043 | case Intrinsic::ppc_altivec_vcmpgtsh: CompareOpc = 838; isDot = 0; break; |
| 1044 | case Intrinsic::ppc_altivec_vcmpgtsw: CompareOpc = 902; isDot = 0; break; |
| 1045 | case Intrinsic::ppc_altivec_vcmpgtub: CompareOpc = 518; isDot = 0; break; |
| 1046 | case Intrinsic::ppc_altivec_vcmpgtuh: CompareOpc = 582; isDot = 0; break; |
| 1047 | case Intrinsic::ppc_altivec_vcmpgtuw: CompareOpc = 646; isDot = 0; break; |
Chris Lattner | 6d92cad | 2006-03-26 10:06:40 +0000 | [diff] [blame] | 1048 | } |
| 1049 | |
| 1050 | assert(CompareOpc>0 && "We only lower altivec predicate compares so far!"); |
| 1051 | |
Chris Lattner | a17b155 | 2006-03-31 05:13:27 +0000 | [diff] [blame] | 1052 | // If this is a non-dot comparison, make the VCMP node. |
Chris Lattner | 9021799 | 2006-04-06 23:12:19 +0000 | [diff] [blame] | 1053 | if (!isDot) { |
| 1054 | SDOperand Tmp = DAG.getNode(PPCISD::VCMP, Op.getOperand(2).getValueType(), |
| 1055 | Op.getOperand(1), Op.getOperand(2), |
| 1056 | DAG.getConstant(CompareOpc, MVT::i32)); |
| 1057 | return DAG.getNode(ISD::BIT_CONVERT, Op.getValueType(), Tmp); |
| 1058 | } |
Chris Lattner | a17b155 | 2006-03-31 05:13:27 +0000 | [diff] [blame] | 1059 | |
Chris Lattner | 6d92cad | 2006-03-26 10:06:40 +0000 | [diff] [blame] | 1060 | // Create the PPCISD altivec 'dot' comparison node. |
| 1061 | std::vector<SDOperand> Ops; |
| 1062 | std::vector<MVT::ValueType> VTs; |
| 1063 | Ops.push_back(Op.getOperand(2)); // LHS |
| 1064 | Ops.push_back(Op.getOperand(3)); // RHS |
| 1065 | Ops.push_back(DAG.getConstant(CompareOpc, MVT::i32)); |
| 1066 | VTs.push_back(Op.getOperand(2).getValueType()); |
| 1067 | VTs.push_back(MVT::Flag); |
| 1068 | SDOperand CompNode = DAG.getNode(PPCISD::VCMPo, VTs, Ops); |
| 1069 | |
| 1070 | // Now that we have the comparison, emit a copy from the CR to a GPR. |
| 1071 | // This is flagged to the above dot comparison. |
| 1072 | SDOperand Flags = DAG.getNode(PPCISD::MFCR, MVT::i32, |
| 1073 | DAG.getRegister(PPC::CR6, MVT::i32), |
| 1074 | CompNode.getValue(1)); |
| 1075 | |
| 1076 | // Unpack the result based on how the target uses it. |
| 1077 | unsigned BitNo; // Bit # of CR6. |
| 1078 | bool InvertBit; // Invert result? |
| 1079 | switch (cast<ConstantSDNode>(Op.getOperand(1))->getValue()) { |
| 1080 | default: // Can't happen, don't crash on invalid number though. |
| 1081 | case 0: // Return the value of the EQ bit of CR6. |
| 1082 | BitNo = 0; InvertBit = false; |
| 1083 | break; |
| 1084 | case 1: // Return the inverted value of the EQ bit of CR6. |
| 1085 | BitNo = 0; InvertBit = true; |
| 1086 | break; |
| 1087 | case 2: // Return the value of the LT bit of CR6. |
| 1088 | BitNo = 2; InvertBit = false; |
| 1089 | break; |
| 1090 | case 3: // Return the inverted value of the LT bit of CR6. |
| 1091 | BitNo = 2; InvertBit = true; |
| 1092 | break; |
| 1093 | } |
| 1094 | |
| 1095 | // Shift the bit into the low position. |
| 1096 | Flags = DAG.getNode(ISD::SRL, MVT::i32, Flags, |
| 1097 | DAG.getConstant(8-(3-BitNo), MVT::i32)); |
| 1098 | // Isolate the bit. |
| 1099 | Flags = DAG.getNode(ISD::AND, MVT::i32, Flags, |
| 1100 | DAG.getConstant(1, MVT::i32)); |
| 1101 | |
| 1102 | // If we are supposed to, toggle the bit. |
| 1103 | if (InvertBit) |
| 1104 | Flags = DAG.getNode(ISD::XOR, MVT::i32, Flags, |
| 1105 | DAG.getConstant(1, MVT::i32)); |
| 1106 | return Flags; |
| 1107 | } |
Chris Lattner | bc11c34 | 2005-08-31 20:23:54 +0000 | [diff] [blame] | 1108 | } |
Chris Lattner | e4bc9ea | 2005-08-26 00:52:45 +0000 | [diff] [blame] | 1109 | return SDOperand(); |
| 1110 | } |
| 1111 | |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 1112 | std::vector<SDOperand> |
Nate Begeman | 21e463b | 2005-10-16 05:39:50 +0000 | [diff] [blame] | 1113 | PPCTargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) { |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 1114 | // |
| 1115 | // add beautiful description of PPC stack frame format, or at least some docs |
| 1116 | // |
| 1117 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1118 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 1119 | MachineBasicBlock& BB = MF.front(); |
Chris Lattner | 7b73834 | 2005-09-13 19:33:40 +0000 | [diff] [blame] | 1120 | SSARegMap *RegMap = MF.getSSARegMap(); |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 1121 | std::vector<SDOperand> ArgValues; |
| 1122 | |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 1123 | unsigned ArgOffset = 24; |
| 1124 | unsigned GPR_remaining = 8; |
| 1125 | unsigned FPR_remaining = 13; |
| 1126 | unsigned GPR_idx = 0, FPR_idx = 0; |
| 1127 | static const unsigned GPR[] = { |
| 1128 | PPC::R3, PPC::R4, PPC::R5, PPC::R6, |
| 1129 | PPC::R7, PPC::R8, PPC::R9, PPC::R10, |
| 1130 | }; |
| 1131 | static const unsigned FPR[] = { |
| 1132 | PPC::F1, PPC::F2, PPC::F3, PPC::F4, PPC::F5, PPC::F6, PPC::F7, |
| 1133 | PPC::F8, PPC::F9, PPC::F10, PPC::F11, PPC::F12, PPC::F13 |
| 1134 | }; |
| 1135 | |
| 1136 | // Add DAG nodes to load the arguments... On entry to a function on PPC, |
| 1137 | // the arguments start at offset 24, although they are likely to be passed |
| 1138 | // in registers. |
| 1139 | for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; ++I) { |
| 1140 | SDOperand newroot, argt; |
| 1141 | unsigned ObjSize; |
| 1142 | bool needsLoad = false; |
| 1143 | bool ArgLive = !I->use_empty(); |
| 1144 | MVT::ValueType ObjectVT = getValueType(I->getType()); |
| 1145 | |
| 1146 | switch (ObjectVT) { |
Chris Lattner | 915fb30 | 2005-08-30 00:19:00 +0000 | [diff] [blame] | 1147 | default: assert(0 && "Unhandled argument type!"); |
| 1148 | case MVT::i1: |
| 1149 | case MVT::i8: |
| 1150 | case MVT::i16: |
| 1151 | case MVT::i32: |
| 1152 | ObjSize = 4; |
| 1153 | if (!ArgLive) break; |
| 1154 | if (GPR_remaining > 0) { |
Nate Begeman | 1d9d742 | 2005-10-18 00:28:58 +0000 | [diff] [blame] | 1155 | unsigned VReg = RegMap->createVirtualRegister(&PPC::GPRCRegClass); |
Chris Lattner | 7b73834 | 2005-09-13 19:33:40 +0000 | [diff] [blame] | 1156 | MF.addLiveIn(GPR[GPR_idx], VReg); |
| 1157 | argt = newroot = DAG.getCopyFromReg(DAG.getRoot(), VReg, MVT::i32); |
Nate Begeman | 49296f1 | 2005-08-31 01:58:39 +0000 | [diff] [blame] | 1158 | if (ObjectVT != MVT::i32) { |
| 1159 | unsigned AssertOp = I->getType()->isSigned() ? ISD::AssertSext |
| 1160 | : ISD::AssertZext; |
| 1161 | argt = DAG.getNode(AssertOp, MVT::i32, argt, |
| 1162 | DAG.getValueType(ObjectVT)); |
| 1163 | argt = DAG.getNode(ISD::TRUNCATE, ObjectVT, argt); |
| 1164 | } |
Chris Lattner | 915fb30 | 2005-08-30 00:19:00 +0000 | [diff] [blame] | 1165 | } else { |
| 1166 | needsLoad = true; |
| 1167 | } |
| 1168 | break; |
Chris Lattner | 80720a9 | 2005-11-30 20:40:54 +0000 | [diff] [blame] | 1169 | case MVT::i64: |
| 1170 | ObjSize = 8; |
Chris Lattner | 915fb30 | 2005-08-30 00:19:00 +0000 | [diff] [blame] | 1171 | if (!ArgLive) break; |
| 1172 | if (GPR_remaining > 0) { |
| 1173 | SDOperand argHi, argLo; |
Nate Begeman | 1d9d742 | 2005-10-18 00:28:58 +0000 | [diff] [blame] | 1174 | unsigned VReg = RegMap->createVirtualRegister(&PPC::GPRCRegClass); |
Chris Lattner | 7b73834 | 2005-09-13 19:33:40 +0000 | [diff] [blame] | 1175 | MF.addLiveIn(GPR[GPR_idx], VReg); |
| 1176 | argHi = DAG.getCopyFromReg(DAG.getRoot(), VReg, MVT::i32); |
Chris Lattner | 915fb30 | 2005-08-30 00:19:00 +0000 | [diff] [blame] | 1177 | // If we have two or more remaining argument registers, then both halves |
| 1178 | // of the i64 can be sourced from there. Otherwise, the lower half will |
| 1179 | // have to come off the stack. This can happen when an i64 is preceded |
| 1180 | // by 28 bytes of arguments. |
| 1181 | if (GPR_remaining > 1) { |
Nate Begeman | 1d9d742 | 2005-10-18 00:28:58 +0000 | [diff] [blame] | 1182 | unsigned VReg = RegMap->createVirtualRegister(&PPC::GPRCRegClass); |
Chris Lattner | 7b73834 | 2005-09-13 19:33:40 +0000 | [diff] [blame] | 1183 | MF.addLiveIn(GPR[GPR_idx+1], VReg); |
| 1184 | argLo = DAG.getCopyFromReg(argHi, VReg, MVT::i32); |
Chris Lattner | 915fb30 | 2005-08-30 00:19:00 +0000 | [diff] [blame] | 1185 | } else { |
| 1186 | int FI = MFI->CreateFixedObject(4, ArgOffset+4); |
| 1187 | SDOperand FIN = DAG.getFrameIndex(FI, MVT::i32); |
| 1188 | argLo = DAG.getLoad(MVT::i32, DAG.getEntryNode(), FIN, |
| 1189 | DAG.getSrcValue(NULL)); |
| 1190 | } |
| 1191 | // Build the outgoing arg thingy |
| 1192 | argt = DAG.getNode(ISD::BUILD_PAIR, MVT::i64, argLo, argHi); |
| 1193 | newroot = argLo; |
| 1194 | } else { |
| 1195 | needsLoad = true; |
| 1196 | } |
| 1197 | break; |
| 1198 | case MVT::f32: |
| 1199 | case MVT::f64: |
| 1200 | ObjSize = (ObjectVT == MVT::f64) ? 8 : 4; |
Chris Lattner | 413b979 | 2006-01-11 18:21:25 +0000 | [diff] [blame] | 1201 | if (!ArgLive) { |
| 1202 | if (FPR_remaining > 0) { |
| 1203 | --FPR_remaining; |
| 1204 | ++FPR_idx; |
| 1205 | } |
| 1206 | break; |
| 1207 | } |
Chris Lattner | 915fb30 | 2005-08-30 00:19:00 +0000 | [diff] [blame] | 1208 | if (FPR_remaining > 0) { |
Chris Lattner | 919c032 | 2005-10-01 01:35:02 +0000 | [diff] [blame] | 1209 | unsigned VReg; |
| 1210 | if (ObjectVT == MVT::f32) |
Nate Begeman | 1d9d742 | 2005-10-18 00:28:58 +0000 | [diff] [blame] | 1211 | VReg = RegMap->createVirtualRegister(&PPC::F4RCRegClass); |
Chris Lattner | 919c032 | 2005-10-01 01:35:02 +0000 | [diff] [blame] | 1212 | else |
Nate Begeman | 1d9d742 | 2005-10-18 00:28:58 +0000 | [diff] [blame] | 1213 | VReg = RegMap->createVirtualRegister(&PPC::F8RCRegClass); |
Chris Lattner | 7b73834 | 2005-09-13 19:33:40 +0000 | [diff] [blame] | 1214 | MF.addLiveIn(FPR[FPR_idx], VReg); |
| 1215 | argt = newroot = DAG.getCopyFromReg(DAG.getRoot(), VReg, ObjectVT); |
Chris Lattner | 915fb30 | 2005-08-30 00:19:00 +0000 | [diff] [blame] | 1216 | --FPR_remaining; |
| 1217 | ++FPR_idx; |
| 1218 | } else { |
| 1219 | needsLoad = true; |
| 1220 | } |
| 1221 | break; |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 1222 | } |
| 1223 | |
| 1224 | // We need to load the argument to a virtual register if we determined above |
| 1225 | // that we ran out of physical registers of the appropriate type |
| 1226 | if (needsLoad) { |
| 1227 | unsigned SubregOffset = 0; |
| 1228 | if (ObjectVT == MVT::i8 || ObjectVT == MVT::i1) SubregOffset = 3; |
| 1229 | if (ObjectVT == MVT::i16) SubregOffset = 2; |
| 1230 | int FI = MFI->CreateFixedObject(ObjSize, ArgOffset); |
| 1231 | SDOperand FIN = DAG.getFrameIndex(FI, MVT::i32); |
| 1232 | FIN = DAG.getNode(ISD::ADD, MVT::i32, FIN, |
| 1233 | DAG.getConstant(SubregOffset, MVT::i32)); |
| 1234 | argt = newroot = DAG.getLoad(ObjectVT, DAG.getEntryNode(), FIN, |
| 1235 | DAG.getSrcValue(NULL)); |
| 1236 | } |
| 1237 | |
| 1238 | // Every 4 bytes of argument space consumes one of the GPRs available for |
| 1239 | // argument passing. |
| 1240 | if (GPR_remaining > 0) { |
| 1241 | unsigned delta = (GPR_remaining > 1 && ObjSize == 8) ? 2 : 1; |
| 1242 | GPR_remaining -= delta; |
| 1243 | GPR_idx += delta; |
| 1244 | } |
| 1245 | ArgOffset += ObjSize; |
| 1246 | if (newroot.Val) |
| 1247 | DAG.setRoot(newroot.getValue(1)); |
| 1248 | |
| 1249 | ArgValues.push_back(argt); |
| 1250 | } |
| 1251 | |
| 1252 | // If the function takes variable number of arguments, make a frame index for |
| 1253 | // the start of the first vararg value... for expansion of llvm.va_start. |
| 1254 | if (F.isVarArg()) { |
| 1255 | VarArgsFrameIndex = MFI->CreateFixedObject(4, ArgOffset); |
| 1256 | SDOperand FIN = DAG.getFrameIndex(VarArgsFrameIndex, MVT::i32); |
| 1257 | // If this function is vararg, store any remaining integer argument regs |
| 1258 | // to their spots on the stack so that they may be loaded by deferencing the |
| 1259 | // result of va_next. |
| 1260 | std::vector<SDOperand> MemOps; |
| 1261 | for (; GPR_remaining > 0; --GPR_remaining, ++GPR_idx) { |
Nate Begeman | 1d9d742 | 2005-10-18 00:28:58 +0000 | [diff] [blame] | 1262 | unsigned VReg = RegMap->createVirtualRegister(&PPC::GPRCRegClass); |
Chris Lattner | 7b73834 | 2005-09-13 19:33:40 +0000 | [diff] [blame] | 1263 | MF.addLiveIn(GPR[GPR_idx], VReg); |
| 1264 | SDOperand Val = DAG.getCopyFromReg(DAG.getRoot(), VReg, MVT::i32); |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 1265 | SDOperand Store = DAG.getNode(ISD::STORE, MVT::Other, Val.getValue(1), |
| 1266 | Val, FIN, DAG.getSrcValue(NULL)); |
| 1267 | MemOps.push_back(Store); |
| 1268 | // Increment the address by four for the next argument to store |
| 1269 | SDOperand PtrOff = DAG.getConstant(4, getPointerTy()); |
| 1270 | FIN = DAG.getNode(ISD::ADD, MVT::i32, FIN, PtrOff); |
| 1271 | } |
Chris Lattner | 80720a9 | 2005-11-30 20:40:54 +0000 | [diff] [blame] | 1272 | if (!MemOps.empty()) { |
| 1273 | MemOps.push_back(DAG.getRoot()); |
| 1274 | DAG.setRoot(DAG.getNode(ISD::TokenFactor, MVT::Other, MemOps)); |
| 1275 | } |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 1276 | } |
| 1277 | |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 1278 | return ArgValues; |
| 1279 | } |
| 1280 | |
| 1281 | std::pair<SDOperand, SDOperand> |
Nate Begeman | 21e463b | 2005-10-16 05:39:50 +0000 | [diff] [blame] | 1282 | PPCTargetLowering::LowerCallTo(SDOperand Chain, |
| 1283 | const Type *RetTy, bool isVarArg, |
| 1284 | unsigned CallingConv, bool isTailCall, |
| 1285 | SDOperand Callee, ArgListTy &Args, |
| 1286 | SelectionDAG &DAG) { |
Chris Lattner | 281b55e | 2006-01-27 23:34:02 +0000 | [diff] [blame] | 1287 | // args_to_use will accumulate outgoing args for the PPCISD::CALL case in |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 1288 | // SelectExpr to use to put the arguments in the appropriate registers. |
| 1289 | std::vector<SDOperand> args_to_use; |
| 1290 | |
| 1291 | // Count how many bytes are to be pushed on the stack, including the linkage |
| 1292 | // area, and parameter passing area. |
| 1293 | unsigned NumBytes = 24; |
| 1294 | |
| 1295 | if (Args.empty()) { |
Chris Lattner | 45b3976 | 2006-02-13 08:55:29 +0000 | [diff] [blame] | 1296 | Chain = DAG.getCALLSEQ_START(Chain, |
| 1297 | DAG.getConstant(NumBytes, getPointerTy())); |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 1298 | } else { |
Chris Lattner | 915fb30 | 2005-08-30 00:19:00 +0000 | [diff] [blame] | 1299 | for (unsigned i = 0, e = Args.size(); i != e; ++i) { |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 1300 | switch (getValueType(Args[i].second)) { |
Chris Lattner | 915fb30 | 2005-08-30 00:19:00 +0000 | [diff] [blame] | 1301 | default: assert(0 && "Unknown value type!"); |
| 1302 | case MVT::i1: |
| 1303 | case MVT::i8: |
| 1304 | case MVT::i16: |
| 1305 | case MVT::i32: |
| 1306 | case MVT::f32: |
| 1307 | NumBytes += 4; |
| 1308 | break; |
| 1309 | case MVT::i64: |
| 1310 | case MVT::f64: |
| 1311 | NumBytes += 8; |
| 1312 | break; |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 1313 | } |
Chris Lattner | 915fb30 | 2005-08-30 00:19:00 +0000 | [diff] [blame] | 1314 | } |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 1315 | |
Chris Lattner | 915fb30 | 2005-08-30 00:19:00 +0000 | [diff] [blame] | 1316 | // Just to be safe, we'll always reserve the full 24 bytes of linkage area |
| 1317 | // plus 32 bytes of argument space in case any called code gets funky on us. |
| 1318 | // (Required by ABI to support var arg) |
| 1319 | if (NumBytes < 56) NumBytes = 56; |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 1320 | |
| 1321 | // Adjust the stack pointer for the new arguments... |
| 1322 | // These operations are automatically eliminated by the prolog/epilog pass |
Chris Lattner | 45b3976 | 2006-02-13 08:55:29 +0000 | [diff] [blame] | 1323 | Chain = DAG.getCALLSEQ_START(Chain, |
| 1324 | DAG.getConstant(NumBytes, getPointerTy())); |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 1325 | |
| 1326 | // Set up a copy of the stack pointer for use loading and storing any |
| 1327 | // arguments that may not fit in the registers available for argument |
| 1328 | // passing. |
Chris Lattner | a243db8 | 2006-01-11 19:55:07 +0000 | [diff] [blame] | 1329 | SDOperand StackPtr = DAG.getRegister(PPC::R1, MVT::i32); |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 1330 | |
| 1331 | // Figure out which arguments are going to go in registers, and which in |
| 1332 | // memory. Also, if this is a vararg function, floating point operations |
| 1333 | // must be stored to our stack, and loaded into integer regs as well, if |
| 1334 | // any integer regs are available for argument passing. |
| 1335 | unsigned ArgOffset = 24; |
| 1336 | unsigned GPR_remaining = 8; |
| 1337 | unsigned FPR_remaining = 13; |
| 1338 | |
| 1339 | std::vector<SDOperand> MemOps; |
| 1340 | for (unsigned i = 0, e = Args.size(); i != e; ++i) { |
| 1341 | // PtrOff will be used to store the current argument to the stack if a |
| 1342 | // register cannot be found for it. |
| 1343 | SDOperand PtrOff = DAG.getConstant(ArgOffset, getPointerTy()); |
| 1344 | PtrOff = DAG.getNode(ISD::ADD, MVT::i32, StackPtr, PtrOff); |
| 1345 | MVT::ValueType ArgVT = getValueType(Args[i].second); |
| 1346 | |
| 1347 | switch (ArgVT) { |
Chris Lattner | 915fb30 | 2005-08-30 00:19:00 +0000 | [diff] [blame] | 1348 | default: assert(0 && "Unexpected ValueType for argument!"); |
| 1349 | case MVT::i1: |
| 1350 | case MVT::i8: |
| 1351 | case MVT::i16: |
| 1352 | // Promote the integer to 32 bits. If the input type is signed use a |
| 1353 | // sign extend, otherwise use a zero extend. |
| 1354 | if (Args[i].second->isSigned()) |
| 1355 | Args[i].first =DAG.getNode(ISD::SIGN_EXTEND, MVT::i32, Args[i].first); |
| 1356 | else |
| 1357 | Args[i].first =DAG.getNode(ISD::ZERO_EXTEND, MVT::i32, Args[i].first); |
| 1358 | // FALL THROUGH |
| 1359 | case MVT::i32: |
| 1360 | if (GPR_remaining > 0) { |
| 1361 | args_to_use.push_back(Args[i].first); |
| 1362 | --GPR_remaining; |
| 1363 | } else { |
| 1364 | MemOps.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain, |
| 1365 | Args[i].first, PtrOff, |
| 1366 | DAG.getSrcValue(NULL))); |
| 1367 | } |
| 1368 | ArgOffset += 4; |
| 1369 | break; |
| 1370 | case MVT::i64: |
| 1371 | // If we have one free GPR left, we can place the upper half of the i64 |
| 1372 | // in it, and store the other half to the stack. If we have two or more |
| 1373 | // free GPRs, then we can pass both halves of the i64 in registers. |
| 1374 | if (GPR_remaining > 0) { |
| 1375 | SDOperand Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32, |
| 1376 | Args[i].first, DAG.getConstant(1, MVT::i32)); |
| 1377 | SDOperand Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32, |
| 1378 | Args[i].first, DAG.getConstant(0, MVT::i32)); |
| 1379 | args_to_use.push_back(Hi); |
| 1380 | --GPR_remaining; |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 1381 | if (GPR_remaining > 0) { |
Chris Lattner | 915fb30 | 2005-08-30 00:19:00 +0000 | [diff] [blame] | 1382 | args_to_use.push_back(Lo); |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 1383 | --GPR_remaining; |
| 1384 | } else { |
Chris Lattner | 915fb30 | 2005-08-30 00:19:00 +0000 | [diff] [blame] | 1385 | SDOperand ConstFour = DAG.getConstant(4, getPointerTy()); |
| 1386 | PtrOff = DAG.getNode(ISD::ADD, MVT::i32, PtrOff, ConstFour); |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 1387 | MemOps.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain, |
Chris Lattner | 915fb30 | 2005-08-30 00:19:00 +0000 | [diff] [blame] | 1388 | Lo, PtrOff, DAG.getSrcValue(NULL))); |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 1389 | } |
Chris Lattner | 915fb30 | 2005-08-30 00:19:00 +0000 | [diff] [blame] | 1390 | } else { |
| 1391 | MemOps.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain, |
| 1392 | Args[i].first, PtrOff, |
| 1393 | DAG.getSrcValue(NULL))); |
| 1394 | } |
| 1395 | ArgOffset += 8; |
| 1396 | break; |
| 1397 | case MVT::f32: |
| 1398 | case MVT::f64: |
| 1399 | if (FPR_remaining > 0) { |
| 1400 | args_to_use.push_back(Args[i].first); |
| 1401 | --FPR_remaining; |
| 1402 | if (isVarArg) { |
| 1403 | SDOperand Store = DAG.getNode(ISD::STORE, MVT::Other, Chain, |
| 1404 | Args[i].first, PtrOff, |
| 1405 | DAG.getSrcValue(NULL)); |
| 1406 | MemOps.push_back(Store); |
| 1407 | // Float varargs are always shadowed in available integer registers |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 1408 | if (GPR_remaining > 0) { |
Chris Lattner | 915fb30 | 2005-08-30 00:19:00 +0000 | [diff] [blame] | 1409 | SDOperand Load = DAG.getLoad(MVT::i32, Store, PtrOff, |
| 1410 | DAG.getSrcValue(NULL)); |
Chris Lattner | 1df7478 | 2005-11-17 18:30:17 +0000 | [diff] [blame] | 1411 | MemOps.push_back(Load.getValue(1)); |
Chris Lattner | 915fb30 | 2005-08-30 00:19:00 +0000 | [diff] [blame] | 1412 | args_to_use.push_back(Load); |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 1413 | --GPR_remaining; |
Chris Lattner | 915fb30 | 2005-08-30 00:19:00 +0000 | [diff] [blame] | 1414 | } |
| 1415 | if (GPR_remaining > 0 && MVT::f64 == ArgVT) { |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 1416 | SDOperand ConstFour = DAG.getConstant(4, getPointerTy()); |
| 1417 | PtrOff = DAG.getNode(ISD::ADD, MVT::i32, PtrOff, ConstFour); |
Chris Lattner | 915fb30 | 2005-08-30 00:19:00 +0000 | [diff] [blame] | 1418 | SDOperand Load = DAG.getLoad(MVT::i32, Store, PtrOff, |
| 1419 | DAG.getSrcValue(NULL)); |
Chris Lattner | 1df7478 | 2005-11-17 18:30:17 +0000 | [diff] [blame] | 1420 | MemOps.push_back(Load.getValue(1)); |
Chris Lattner | 915fb30 | 2005-08-30 00:19:00 +0000 | [diff] [blame] | 1421 | args_to_use.push_back(Load); |
| 1422 | --GPR_remaining; |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 1423 | } |
| 1424 | } else { |
Chris Lattner | 915fb30 | 2005-08-30 00:19:00 +0000 | [diff] [blame] | 1425 | // If we have any FPRs remaining, we may also have GPRs remaining. |
| 1426 | // Args passed in FPRs consume either 1 (f32) or 2 (f64) available |
| 1427 | // GPRs. |
| 1428 | if (GPR_remaining > 0) { |
| 1429 | args_to_use.push_back(DAG.getNode(ISD::UNDEF, MVT::i32)); |
| 1430 | --GPR_remaining; |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 1431 | } |
Chris Lattner | 915fb30 | 2005-08-30 00:19:00 +0000 | [diff] [blame] | 1432 | if (GPR_remaining > 0 && MVT::f64 == ArgVT) { |
| 1433 | args_to_use.push_back(DAG.getNode(ISD::UNDEF, MVT::i32)); |
| 1434 | --GPR_remaining; |
| 1435 | } |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 1436 | } |
Chris Lattner | 915fb30 | 2005-08-30 00:19:00 +0000 | [diff] [blame] | 1437 | } else { |
| 1438 | MemOps.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain, |
| 1439 | Args[i].first, PtrOff, |
| 1440 | DAG.getSrcValue(NULL))); |
| 1441 | } |
| 1442 | ArgOffset += (ArgVT == MVT::f32) ? 4 : 8; |
| 1443 | break; |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 1444 | } |
| 1445 | } |
| 1446 | if (!MemOps.empty()) |
| 1447 | Chain = DAG.getNode(ISD::TokenFactor, MVT::Other, MemOps); |
| 1448 | } |
| 1449 | |
| 1450 | std::vector<MVT::ValueType> RetVals; |
| 1451 | MVT::ValueType RetTyVT = getValueType(RetTy); |
Chris Lattner | f505949 | 2005-09-02 01:24:55 +0000 | [diff] [blame] | 1452 | MVT::ValueType ActualRetTyVT = RetTyVT; |
| 1453 | if (RetTyVT >= MVT::i1 && RetTyVT <= MVT::i16) |
| 1454 | ActualRetTyVT = MVT::i32; // Promote result to i32. |
| 1455 | |
Chris Lattner | e00ebf0 | 2006-01-28 07:33:03 +0000 | [diff] [blame] | 1456 | if (RetTyVT == MVT::i64) { |
| 1457 | RetVals.push_back(MVT::i32); |
| 1458 | RetVals.push_back(MVT::i32); |
| 1459 | } else if (RetTyVT != MVT::isVoid) { |
Chris Lattner | f505949 | 2005-09-02 01:24:55 +0000 | [diff] [blame] | 1460 | RetVals.push_back(ActualRetTyVT); |
Chris Lattner | e00ebf0 | 2006-01-28 07:33:03 +0000 | [diff] [blame] | 1461 | } |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 1462 | RetVals.push_back(MVT::Other); |
| 1463 | |
Chris Lattner | 2823b3e | 2005-11-17 05:56:14 +0000 | [diff] [blame] | 1464 | // If the callee is a GlobalAddress node (quite common, every direct call is) |
| 1465 | // turn it into a TargetGlobalAddress node so that legalize doesn't hack it. |
| 1466 | if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) |
| 1467 | Callee = DAG.getTargetGlobalAddress(G->getGlobal(), MVT::i32); |
| 1468 | |
Chris Lattner | 281b55e | 2006-01-27 23:34:02 +0000 | [diff] [blame] | 1469 | std::vector<SDOperand> Ops; |
| 1470 | Ops.push_back(Chain); |
| 1471 | Ops.push_back(Callee); |
| 1472 | Ops.insert(Ops.end(), args_to_use.begin(), args_to_use.end()); |
| 1473 | SDOperand TheCall = DAG.getNode(PPCISD::CALL, RetVals, Ops); |
Chris Lattner | e00ebf0 | 2006-01-28 07:33:03 +0000 | [diff] [blame] | 1474 | Chain = TheCall.getValue(TheCall.Val->getNumValues()-1); |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 1475 | Chain = DAG.getNode(ISD::CALLSEQ_END, MVT::Other, Chain, |
| 1476 | DAG.getConstant(NumBytes, getPointerTy())); |
Chris Lattner | f505949 | 2005-09-02 01:24:55 +0000 | [diff] [blame] | 1477 | SDOperand RetVal = TheCall; |
| 1478 | |
| 1479 | // If the result is a small value, add a note so that we keep track of the |
| 1480 | // information about whether it is sign or zero extended. |
| 1481 | if (RetTyVT != ActualRetTyVT) { |
| 1482 | RetVal = DAG.getNode(RetTy->isSigned() ? ISD::AssertSext : ISD::AssertZext, |
| 1483 | MVT::i32, RetVal, DAG.getValueType(RetTyVT)); |
| 1484 | RetVal = DAG.getNode(ISD::TRUNCATE, RetTyVT, RetVal); |
Chris Lattner | e00ebf0 | 2006-01-28 07:33:03 +0000 | [diff] [blame] | 1485 | } else if (RetTyVT == MVT::i64) { |
| 1486 | RetVal = DAG.getNode(ISD::BUILD_PAIR, MVT::i64, RetVal, RetVal.getValue(1)); |
Chris Lattner | f505949 | 2005-09-02 01:24:55 +0000 | [diff] [blame] | 1487 | } |
| 1488 | |
| 1489 | return std::make_pair(RetVal, Chain); |
Chris Lattner | 7c5a3d3 | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 1490 | } |
| 1491 | |
Chris Lattner | 8a2d3ca | 2005-08-26 21:23:58 +0000 | [diff] [blame] | 1492 | MachineBasicBlock * |
Nate Begeman | 21e463b | 2005-10-16 05:39:50 +0000 | [diff] [blame] | 1493 | PPCTargetLowering::InsertAtEndOfBasicBlock(MachineInstr *MI, |
| 1494 | MachineBasicBlock *BB) { |
Chris Lattner | 8a2d3ca | 2005-08-26 21:23:58 +0000 | [diff] [blame] | 1495 | assert((MI->getOpcode() == PPC::SELECT_CC_Int || |
Chris Lattner | 919c032 | 2005-10-01 01:35:02 +0000 | [diff] [blame] | 1496 | MI->getOpcode() == PPC::SELECT_CC_F4 || |
Chris Lattner | 710ff32 | 2006-04-08 22:45:08 +0000 | [diff] [blame] | 1497 | MI->getOpcode() == PPC::SELECT_CC_F8 || |
| 1498 | MI->getOpcode() == PPC::SELECT_CC_VRRC) && |
Chris Lattner | 8a2d3ca | 2005-08-26 21:23:58 +0000 | [diff] [blame] | 1499 | "Unexpected instr type to insert"); |
| 1500 | |
| 1501 | // To "insert" a SELECT_CC instruction, we actually have to insert the diamond |
| 1502 | // control-flow pattern. The incoming instruction knows the destination vreg |
| 1503 | // to set, the condition code register to branch on, the true/false values to |
| 1504 | // select between, and a branch opcode to use. |
| 1505 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 1506 | ilist<MachineBasicBlock>::iterator It = BB; |
| 1507 | ++It; |
| 1508 | |
| 1509 | // thisMBB: |
| 1510 | // ... |
| 1511 | // TrueVal = ... |
| 1512 | // cmpTY ccX, r1, r2 |
| 1513 | // bCC copy1MBB |
| 1514 | // fallthrough --> copy0MBB |
| 1515 | MachineBasicBlock *thisMBB = BB; |
| 1516 | MachineBasicBlock *copy0MBB = new MachineBasicBlock(LLVM_BB); |
| 1517 | MachineBasicBlock *sinkMBB = new MachineBasicBlock(LLVM_BB); |
| 1518 | BuildMI(BB, MI->getOperand(4).getImmedValue(), 2) |
| 1519 | .addReg(MI->getOperand(1).getReg()).addMBB(sinkMBB); |
| 1520 | MachineFunction *F = BB->getParent(); |
| 1521 | F->getBasicBlockList().insert(It, copy0MBB); |
| 1522 | F->getBasicBlockList().insert(It, sinkMBB); |
Nate Begeman | f15485a | 2006-03-27 01:32:24 +0000 | [diff] [blame] | 1523 | // Update machine-CFG edges by first adding all successors of the current |
| 1524 | // block to the new block which will contain the Phi node for the select. |
| 1525 | for(MachineBasicBlock::succ_iterator i = BB->succ_begin(), |
| 1526 | e = BB->succ_end(); i != e; ++i) |
| 1527 | sinkMBB->addSuccessor(*i); |
| 1528 | // Next, remove all successors of the current block, and add the true |
| 1529 | // and fallthrough blocks as its successors. |
| 1530 | while(!BB->succ_empty()) |
| 1531 | BB->removeSuccessor(BB->succ_begin()); |
Chris Lattner | 8a2d3ca | 2005-08-26 21:23:58 +0000 | [diff] [blame] | 1532 | BB->addSuccessor(copy0MBB); |
| 1533 | BB->addSuccessor(sinkMBB); |
| 1534 | |
| 1535 | // copy0MBB: |
| 1536 | // %FalseValue = ... |
| 1537 | // # fallthrough to sinkMBB |
| 1538 | BB = copy0MBB; |
| 1539 | |
| 1540 | // Update machine-CFG edges |
| 1541 | BB->addSuccessor(sinkMBB); |
| 1542 | |
| 1543 | // sinkMBB: |
| 1544 | // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ] |
| 1545 | // ... |
| 1546 | BB = sinkMBB; |
| 1547 | BuildMI(BB, PPC::PHI, 4, MI->getOperand(0).getReg()) |
| 1548 | .addReg(MI->getOperand(3).getReg()).addMBB(copy0MBB) |
| 1549 | .addReg(MI->getOperand(2).getReg()).addMBB(thisMBB); |
| 1550 | |
| 1551 | delete MI; // The pseudo instruction is gone now. |
| 1552 | return BB; |
| 1553 | } |
| 1554 | |
Chris Lattner | 8c13d0a | 2006-03-01 04:57:39 +0000 | [diff] [blame] | 1555 | SDOperand PPCTargetLowering::PerformDAGCombine(SDNode *N, |
| 1556 | DAGCombinerInfo &DCI) const { |
| 1557 | TargetMachine &TM = getTargetMachine(); |
| 1558 | SelectionDAG &DAG = DCI.DAG; |
| 1559 | switch (N->getOpcode()) { |
| 1560 | default: break; |
| 1561 | case ISD::SINT_TO_FP: |
| 1562 | if (TM.getSubtarget<PPCSubtarget>().is64Bit()) { |
Chris Lattner | ecfe55e | 2006-03-22 05:30:33 +0000 | [diff] [blame] | 1563 | if (N->getOperand(0).getOpcode() == ISD::FP_TO_SINT) { |
| 1564 | // Turn (sint_to_fp (fp_to_sint X)) -> fctidz/fcfid without load/stores. |
| 1565 | // We allow the src/dst to be either f32/f64, but the intermediate |
| 1566 | // type must be i64. |
| 1567 | if (N->getOperand(0).getValueType() == MVT::i64) { |
| 1568 | SDOperand Val = N->getOperand(0).getOperand(0); |
| 1569 | if (Val.getValueType() == MVT::f32) { |
| 1570 | Val = DAG.getNode(ISD::FP_EXTEND, MVT::f64, Val); |
| 1571 | DCI.AddToWorklist(Val.Val); |
| 1572 | } |
| 1573 | |
| 1574 | Val = DAG.getNode(PPCISD::FCTIDZ, MVT::f64, Val); |
Chris Lattner | 8c13d0a | 2006-03-01 04:57:39 +0000 | [diff] [blame] | 1575 | DCI.AddToWorklist(Val.Val); |
Chris Lattner | ecfe55e | 2006-03-22 05:30:33 +0000 | [diff] [blame] | 1576 | Val = DAG.getNode(PPCISD::FCFID, MVT::f64, Val); |
Chris Lattner | 8c13d0a | 2006-03-01 04:57:39 +0000 | [diff] [blame] | 1577 | DCI.AddToWorklist(Val.Val); |
Chris Lattner | ecfe55e | 2006-03-22 05:30:33 +0000 | [diff] [blame] | 1578 | if (N->getValueType(0) == MVT::f32) { |
| 1579 | Val = DAG.getNode(ISD::FP_ROUND, MVT::f32, Val); |
| 1580 | DCI.AddToWorklist(Val.Val); |
| 1581 | } |
| 1582 | return Val; |
| 1583 | } else if (N->getOperand(0).getValueType() == MVT::i32) { |
| 1584 | // If the intermediate type is i32, we can avoid the load/store here |
| 1585 | // too. |
Chris Lattner | 8c13d0a | 2006-03-01 04:57:39 +0000 | [diff] [blame] | 1586 | } |
Chris Lattner | 8c13d0a | 2006-03-01 04:57:39 +0000 | [diff] [blame] | 1587 | } |
| 1588 | } |
| 1589 | break; |
Chris Lattner | 5126984 | 2006-03-01 05:50:56 +0000 | [diff] [blame] | 1590 | case ISD::STORE: |
| 1591 | // Turn STORE (FP_TO_SINT F) -> STFIWX(FCTIWZ(F)). |
| 1592 | if (TM.getSubtarget<PPCSubtarget>().hasSTFIWX() && |
| 1593 | N->getOperand(1).getOpcode() == ISD::FP_TO_SINT && |
| 1594 | N->getOperand(1).getValueType() == MVT::i32) { |
| 1595 | SDOperand Val = N->getOperand(1).getOperand(0); |
| 1596 | if (Val.getValueType() == MVT::f32) { |
| 1597 | Val = DAG.getNode(ISD::FP_EXTEND, MVT::f64, Val); |
| 1598 | DCI.AddToWorklist(Val.Val); |
| 1599 | } |
| 1600 | Val = DAG.getNode(PPCISD::FCTIWZ, MVT::f64, Val); |
| 1601 | DCI.AddToWorklist(Val.Val); |
| 1602 | |
| 1603 | Val = DAG.getNode(PPCISD::STFIWX, MVT::Other, N->getOperand(0), Val, |
| 1604 | N->getOperand(2), N->getOperand(3)); |
| 1605 | DCI.AddToWorklist(Val.Val); |
| 1606 | return Val; |
| 1607 | } |
| 1608 | break; |
Chris Lattner | 4468c22 | 2006-03-31 06:02:07 +0000 | [diff] [blame] | 1609 | case PPCISD::VCMP: { |
| 1610 | // If a VCMPo node already exists with exactly the same operands as this |
| 1611 | // node, use its result instead of this node (VCMPo computes both a CR6 and |
| 1612 | // a normal output). |
| 1613 | // |
| 1614 | if (!N->getOperand(0).hasOneUse() && |
| 1615 | !N->getOperand(1).hasOneUse() && |
| 1616 | !N->getOperand(2).hasOneUse()) { |
| 1617 | |
| 1618 | // Scan all of the users of the LHS, looking for VCMPo's that match. |
| 1619 | SDNode *VCMPoNode = 0; |
| 1620 | |
| 1621 | SDNode *LHSN = N->getOperand(0).Val; |
| 1622 | for (SDNode::use_iterator UI = LHSN->use_begin(), E = LHSN->use_end(); |
| 1623 | UI != E; ++UI) |
| 1624 | if ((*UI)->getOpcode() == PPCISD::VCMPo && |
| 1625 | (*UI)->getOperand(1) == N->getOperand(1) && |
| 1626 | (*UI)->getOperand(2) == N->getOperand(2) && |
| 1627 | (*UI)->getOperand(0) == N->getOperand(0)) { |
| 1628 | VCMPoNode = *UI; |
| 1629 | break; |
| 1630 | } |
| 1631 | |
| 1632 | // If there are non-zero uses of the flag value, use the VCMPo node! |
Chris Lattner | 33497cc | 2006-03-31 06:04:53 +0000 | [diff] [blame] | 1633 | if (VCMPoNode && !VCMPoNode->hasNUsesOfValue(0, 1)) |
Chris Lattner | 4468c22 | 2006-03-31 06:02:07 +0000 | [diff] [blame] | 1634 | return SDOperand(VCMPoNode, 0); |
| 1635 | } |
| 1636 | break; |
| 1637 | } |
Chris Lattner | 8c13d0a | 2006-03-01 04:57:39 +0000 | [diff] [blame] | 1638 | } |
| 1639 | |
| 1640 | return SDOperand(); |
| 1641 | } |
| 1642 | |
Chris Lattner | bbe77de | 2006-04-02 06:26:07 +0000 | [diff] [blame] | 1643 | void PPCTargetLowering::computeMaskedBitsForTargetNode(const SDOperand Op, |
| 1644 | uint64_t Mask, |
| 1645 | uint64_t &KnownZero, |
| 1646 | uint64_t &KnownOne, |
| 1647 | unsigned Depth) const { |
| 1648 | KnownZero = 0; |
| 1649 | KnownOne = 0; |
| 1650 | switch (Op.getOpcode()) { |
| 1651 | default: break; |
| 1652 | case ISD::INTRINSIC_WO_CHAIN: { |
| 1653 | switch (cast<ConstantSDNode>(Op.getOperand(0))->getValue()) { |
| 1654 | default: break; |
| 1655 | case Intrinsic::ppc_altivec_vcmpbfp_p: |
| 1656 | case Intrinsic::ppc_altivec_vcmpeqfp_p: |
| 1657 | case Intrinsic::ppc_altivec_vcmpequb_p: |
| 1658 | case Intrinsic::ppc_altivec_vcmpequh_p: |
| 1659 | case Intrinsic::ppc_altivec_vcmpequw_p: |
| 1660 | case Intrinsic::ppc_altivec_vcmpgefp_p: |
| 1661 | case Intrinsic::ppc_altivec_vcmpgtfp_p: |
| 1662 | case Intrinsic::ppc_altivec_vcmpgtsb_p: |
| 1663 | case Intrinsic::ppc_altivec_vcmpgtsh_p: |
| 1664 | case Intrinsic::ppc_altivec_vcmpgtsw_p: |
| 1665 | case Intrinsic::ppc_altivec_vcmpgtub_p: |
| 1666 | case Intrinsic::ppc_altivec_vcmpgtuh_p: |
| 1667 | case Intrinsic::ppc_altivec_vcmpgtuw_p: |
| 1668 | KnownZero = ~1U; // All bits but the low one are known to be zero. |
| 1669 | break; |
| 1670 | } |
| 1671 | } |
| 1672 | } |
| 1673 | } |
| 1674 | |
| 1675 | |
Chris Lattner | ad3bc8d | 2006-02-07 20:16:30 +0000 | [diff] [blame] | 1676 | /// getConstraintType - Given a constraint letter, return the type of |
| 1677 | /// constraint it is for this target. |
| 1678 | PPCTargetLowering::ConstraintType |
| 1679 | PPCTargetLowering::getConstraintType(char ConstraintLetter) const { |
| 1680 | switch (ConstraintLetter) { |
| 1681 | default: break; |
| 1682 | case 'b': |
| 1683 | case 'r': |
| 1684 | case 'f': |
| 1685 | case 'v': |
| 1686 | case 'y': |
| 1687 | return C_RegisterClass; |
| 1688 | } |
| 1689 | return TargetLowering::getConstraintType(ConstraintLetter); |
| 1690 | } |
| 1691 | |
| 1692 | |
Chris Lattner | ddc787d | 2006-01-31 19:20:21 +0000 | [diff] [blame] | 1693 | std::vector<unsigned> PPCTargetLowering:: |
Chris Lattner | 1efa40f | 2006-02-22 00:56:39 +0000 | [diff] [blame] | 1694 | getRegClassForInlineAsmConstraint(const std::string &Constraint, |
| 1695 | MVT::ValueType VT) const { |
Chris Lattner | ddc787d | 2006-01-31 19:20:21 +0000 | [diff] [blame] | 1696 | if (Constraint.size() == 1) { |
| 1697 | switch (Constraint[0]) { // GCC RS6000 Constraint Letters |
| 1698 | default: break; // Unknown constriant letter |
| 1699 | case 'b': |
| 1700 | return make_vector<unsigned>(/*no R0*/ PPC::R1 , PPC::R2 , PPC::R3 , |
| 1701 | PPC::R4 , PPC::R5 , PPC::R6 , PPC::R7 , |
| 1702 | PPC::R8 , PPC::R9 , PPC::R10, PPC::R11, |
| 1703 | PPC::R12, PPC::R13, PPC::R14, PPC::R15, |
| 1704 | PPC::R16, PPC::R17, PPC::R18, PPC::R19, |
| 1705 | PPC::R20, PPC::R21, PPC::R22, PPC::R23, |
| 1706 | PPC::R24, PPC::R25, PPC::R26, PPC::R27, |
| 1707 | PPC::R28, PPC::R29, PPC::R30, PPC::R31, |
| 1708 | 0); |
| 1709 | case 'r': |
| 1710 | return make_vector<unsigned>(PPC::R0 , PPC::R1 , PPC::R2 , PPC::R3 , |
| 1711 | PPC::R4 , PPC::R5 , PPC::R6 , PPC::R7 , |
| 1712 | PPC::R8 , PPC::R9 , PPC::R10, PPC::R11, |
| 1713 | PPC::R12, PPC::R13, PPC::R14, PPC::R15, |
| 1714 | PPC::R16, PPC::R17, PPC::R18, PPC::R19, |
| 1715 | PPC::R20, PPC::R21, PPC::R22, PPC::R23, |
| 1716 | PPC::R24, PPC::R25, PPC::R26, PPC::R27, |
| 1717 | PPC::R28, PPC::R29, PPC::R30, PPC::R31, |
| 1718 | 0); |
| 1719 | case 'f': |
| 1720 | return make_vector<unsigned>(PPC::F0 , PPC::F1 , PPC::F2 , PPC::F3 , |
| 1721 | PPC::F4 , PPC::F5 , PPC::F6 , PPC::F7 , |
| 1722 | PPC::F8 , PPC::F9 , PPC::F10, PPC::F11, |
| 1723 | PPC::F12, PPC::F13, PPC::F14, PPC::F15, |
| 1724 | PPC::F16, PPC::F17, PPC::F18, PPC::F19, |
| 1725 | PPC::F20, PPC::F21, PPC::F22, PPC::F23, |
| 1726 | PPC::F24, PPC::F25, PPC::F26, PPC::F27, |
| 1727 | PPC::F28, PPC::F29, PPC::F30, PPC::F31, |
| 1728 | 0); |
| 1729 | case 'v': |
| 1730 | return make_vector<unsigned>(PPC::V0 , PPC::V1 , PPC::V2 , PPC::V3 , |
| 1731 | PPC::V4 , PPC::V5 , PPC::V6 , PPC::V7 , |
| 1732 | PPC::V8 , PPC::V9 , PPC::V10, PPC::V11, |
| 1733 | PPC::V12, PPC::V13, PPC::V14, PPC::V15, |
| 1734 | PPC::V16, PPC::V17, PPC::V18, PPC::V19, |
| 1735 | PPC::V20, PPC::V21, PPC::V22, PPC::V23, |
| 1736 | PPC::V24, PPC::V25, PPC::V26, PPC::V27, |
| 1737 | PPC::V28, PPC::V29, PPC::V30, PPC::V31, |
| 1738 | 0); |
| 1739 | case 'y': |
| 1740 | return make_vector<unsigned>(PPC::CR0, PPC::CR1, PPC::CR2, PPC::CR3, |
| 1741 | PPC::CR4, PPC::CR5, PPC::CR6, PPC::CR7, |
| 1742 | 0); |
| 1743 | } |
| 1744 | } |
| 1745 | |
Chris Lattner | 1efa40f | 2006-02-22 00:56:39 +0000 | [diff] [blame] | 1746 | return std::vector<unsigned>(); |
Chris Lattner | ddc787d | 2006-01-31 19:20:21 +0000 | [diff] [blame] | 1747 | } |
Chris Lattner | 763317d | 2006-02-07 00:47:13 +0000 | [diff] [blame] | 1748 | |
| 1749 | // isOperandValidForConstraint |
| 1750 | bool PPCTargetLowering:: |
| 1751 | isOperandValidForConstraint(SDOperand Op, char Letter) { |
| 1752 | switch (Letter) { |
| 1753 | default: break; |
| 1754 | case 'I': |
| 1755 | case 'J': |
| 1756 | case 'K': |
| 1757 | case 'L': |
| 1758 | case 'M': |
| 1759 | case 'N': |
| 1760 | case 'O': |
| 1761 | case 'P': { |
| 1762 | if (!isa<ConstantSDNode>(Op)) return false; // Must be an immediate. |
| 1763 | unsigned Value = cast<ConstantSDNode>(Op)->getValue(); |
| 1764 | switch (Letter) { |
| 1765 | default: assert(0 && "Unknown constraint letter!"); |
| 1766 | case 'I': // "I" is a signed 16-bit constant. |
| 1767 | return (short)Value == (int)Value; |
| 1768 | case 'J': // "J" is a constant with only the high-order 16 bits nonzero. |
| 1769 | case 'L': // "L" is a signed 16-bit constant shifted left 16 bits. |
| 1770 | return (short)Value == 0; |
| 1771 | case 'K': // "K" is a constant with only the low-order 16 bits nonzero. |
| 1772 | return (Value >> 16) == 0; |
| 1773 | case 'M': // "M" is a constant that is greater than 31. |
| 1774 | return Value > 31; |
| 1775 | case 'N': // "N" is a positive constant that is an exact power of two. |
| 1776 | return (int)Value > 0 && isPowerOf2_32(Value); |
| 1777 | case 'O': // "O" is the constant zero. |
| 1778 | return Value == 0; |
| 1779 | case 'P': // "P" is a constant whose negation is a signed 16-bit constant. |
| 1780 | return (short)-Value == (int)-Value; |
| 1781 | } |
| 1782 | break; |
| 1783 | } |
| 1784 | } |
| 1785 | |
| 1786 | // Handle standard constraint letters. |
| 1787 | return TargetLowering::isOperandValidForConstraint(Op, Letter); |
| 1788 | } |
Evan Cheng | c4c6257 | 2006-03-13 23:20:37 +0000 | [diff] [blame] | 1789 | |
| 1790 | /// isLegalAddressImmediate - Return true if the integer value can be used |
| 1791 | /// as the offset of the target addressing mode. |
| 1792 | bool PPCTargetLowering::isLegalAddressImmediate(int64_t V) const { |
| 1793 | // PPC allows a sign-extended 16-bit immediate field. |
| 1794 | return (V > -(1 << 16) && V < (1 << 16)-1); |
| 1795 | } |