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