blob: 46400378a267cea48236953d06c7e3170a21aec1 [file] [log] [blame]
Nate Begeman1d9d7422005-10-18 00:28:58 +00001//===-- PPCISelLowering.cpp - PPC DAG Lowering Implementation -------------===//
Chris Lattner7c5a3d32005-08-16 17:14:42 +00002//
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 Begeman21e463b2005-10-16 05:39:50 +000010// This file implements the PPCISelLowering class.
Chris Lattner7c5a3d32005-08-16 17:14:42 +000011//
12//===----------------------------------------------------------------------===//
13
Chris Lattner16e71f22005-10-14 23:59:06 +000014#include "PPCISelLowering.h"
15#include "PPCTargetMachine.h"
Nate Begeman750ac1b2006-02-01 07:19:44 +000016#include "llvm/ADT/VectorExtras.h"
Chris Lattner7c5a3d32005-08-16 17:14:42 +000017#include "llvm/CodeGen/MachineFrameInfo.h"
18#include "llvm/CodeGen/MachineFunction.h"
Chris Lattner8a2d3ca2005-08-26 21:23:58 +000019#include "llvm/CodeGen/MachineInstrBuilder.h"
Chris Lattner7c5a3d32005-08-16 17:14:42 +000020#include "llvm/CodeGen/SelectionDAG.h"
Chris Lattner7b738342005-09-13 19:33:40 +000021#include "llvm/CodeGen/SSARegMap.h"
Chris Lattner0b1e4e52005-08-26 17:36:52 +000022#include "llvm/Constants.h"
Chris Lattner7c5a3d32005-08-16 17:14:42 +000023#include "llvm/Function.h"
Nate Begeman750ac1b2006-02-01 07:19:44 +000024#include "llvm/Support/MathExtras.h"
Chris Lattner7c5a3d32005-08-16 17:14:42 +000025using namespace llvm;
26
Nate Begeman21e463b2005-10-16 05:39:50 +000027PPCTargetLowering::PPCTargetLowering(TargetMachine &TM)
Chris Lattner7c5a3d32005-08-16 17:14:42 +000028 : TargetLowering(TM) {
29
30 // Fold away setcc operations if possible.
31 setSetCCIsExpensive();
Nate Begeman405e3ec2005-10-21 00:02:42 +000032 setPow2DivIsCheap();
Chris Lattner7c5a3d32005-08-16 17:14:42 +000033
Chris Lattnerd145a612005-09-27 22:18:25 +000034 // Use _setjmp/_longjmp instead of setjmp/longjmp.
35 setUseUnderscoreSetJmpLongJmp(true);
36
Chris Lattner7c5a3d32005-08-16 17:14:42 +000037 // Set up the register classes.
Nate Begeman1d9d7422005-10-18 00:28:58 +000038 addRegisterClass(MVT::i32, PPC::GPRCRegisterClass);
39 addRegisterClass(MVT::f32, PPC::F4RCRegisterClass);
40 addRegisterClass(MVT::f64, PPC::F8RCRegisterClass);
Chris Lattner7c5a3d32005-08-16 17:14:42 +000041
Chris Lattnera54aa942006-01-29 06:26:08 +000042 setOperationAction(ISD::ConstantFP, MVT::f64, Expand);
43 setOperationAction(ISD::ConstantFP, MVT::f32, Expand);
44
Chris Lattner7c5a3d32005-08-16 17:14:42 +000045 // PowerPC has no intrinsics for these particular operations
46 setOperationAction(ISD::MEMMOVE, MVT::Other, Expand);
47 setOperationAction(ISD::MEMSET, MVT::Other, Expand);
48 setOperationAction(ISD::MEMCPY, MVT::Other, Expand);
49
50 // PowerPC has an i16 but no i8 (or i1) SEXTLOAD
51 setOperationAction(ISD::SEXTLOAD, MVT::i1, Expand);
52 setOperationAction(ISD::SEXTLOAD, MVT::i8, Expand);
53
54 // PowerPC has no SREM/UREM instructions
55 setOperationAction(ISD::SREM, MVT::i32, Expand);
56 setOperationAction(ISD::UREM, MVT::i32, Expand);
57
58 // We don't support sin/cos/sqrt/fmod
59 setOperationAction(ISD::FSIN , MVT::f64, Expand);
60 setOperationAction(ISD::FCOS , MVT::f64, Expand);
Chris Lattner615c2d02005-09-28 22:29:58 +000061 setOperationAction(ISD::FREM , MVT::f64, Expand);
Chris Lattner7c5a3d32005-08-16 17:14:42 +000062 setOperationAction(ISD::FSIN , MVT::f32, Expand);
63 setOperationAction(ISD::FCOS , MVT::f32, Expand);
Chris Lattner615c2d02005-09-28 22:29:58 +000064 setOperationAction(ISD::FREM , MVT::f32, Expand);
Chris Lattner7c5a3d32005-08-16 17:14:42 +000065
66 // If we're enabling GP optimizations, use hardware square root
Chris Lattner1e9de3e2005-09-02 18:33:05 +000067 if (!TM.getSubtarget<PPCSubtarget>().hasFSQRT()) {
Chris Lattner7c5a3d32005-08-16 17:14:42 +000068 setOperationAction(ISD::FSQRT, MVT::f64, Expand);
69 setOperationAction(ISD::FSQRT, MVT::f32, Expand);
70 }
71
Nate Begemand88fc032006-01-14 03:14:10 +000072 // PowerPC does not have BSWAP, CTPOP or CTTZ
73 setOperationAction(ISD::BSWAP, MVT::i32 , Expand);
Chris Lattner7c5a3d32005-08-16 17:14:42 +000074 setOperationAction(ISD::CTPOP, MVT::i32 , Expand);
75 setOperationAction(ISD::CTTZ , MVT::i32 , Expand);
76
Nate Begeman35ef9132006-01-11 21:21:00 +000077 // PowerPC does not have ROTR
78 setOperationAction(ISD::ROTR, MVT::i32 , Expand);
79
Chris Lattner7c5a3d32005-08-16 17:14:42 +000080 // PowerPC does not have Select
81 setOperationAction(ISD::SELECT, MVT::i32, Expand);
82 setOperationAction(ISD::SELECT, MVT::f32, Expand);
83 setOperationAction(ISD::SELECT, MVT::f64, Expand);
Chris Lattnere4bc9ea2005-08-26 00:52:45 +000084
Chris Lattner0b1e4e52005-08-26 17:36:52 +000085 // PowerPC wants to turn select_cc of FP into fsel when possible.
86 setOperationAction(ISD::SELECT_CC, MVT::f32, Custom);
87 setOperationAction(ISD::SELECT_CC, MVT::f64, Custom);
Nate Begeman44775902006-01-31 08:17:29 +000088
Nate Begeman750ac1b2006-02-01 07:19:44 +000089 // PowerPC wants to optimize integer setcc a bit
Nate Begeman44775902006-01-31 08:17:29 +000090 setOperationAction(ISD::SETCC, MVT::i32, Custom);
Chris Lattnereb9b62e2005-08-31 19:09:57 +000091
Nate Begeman7cbd5252005-08-16 19:49:35 +000092 // PowerPC does not have BRCOND* which requires SetCC
93 setOperationAction(ISD::BRCOND, MVT::Other, Expand);
94 setOperationAction(ISD::BRCONDTWOWAY, MVT::Other, Expand);
Chris Lattner7c5a3d32005-08-16 17:14:42 +000095
Chris Lattnerf7605322005-08-31 21:09:52 +000096 // PowerPC turns FP_TO_SINT into FCTIWZ and some load/stores.
97 setOperationAction(ISD::FP_TO_SINT, MVT::i32, Custom);
Nate Begemanc09eeec2005-09-06 22:03:27 +000098
Jim Laskeyad23c9d2005-08-17 00:40:22 +000099 // PowerPC does not have [U|S]INT_TO_FP
100 setOperationAction(ISD::SINT_TO_FP, MVT::i32, Expand);
101 setOperationAction(ISD::UINT_TO_FP, MVT::i32, Expand);
102
Chris Lattner53e88452005-12-23 05:13:35 +0000103 setOperationAction(ISD::BIT_CONVERT, MVT::f32, Expand);
104 setOperationAction(ISD::BIT_CONVERT, MVT::i32, Expand);
105
Chris Lattnere6ec9f22005-09-10 00:21:06 +0000106 // PowerPC does not have truncstore for i1.
107 setOperationAction(ISD::TRUNCSTORE, MVT::i1, Promote);
Chris Lattnerf73bae12005-11-29 06:16:21 +0000108
Jim Laskeyabf6d172006-01-05 01:25:28 +0000109 // Support label based line numbers.
Chris Lattnerf73bae12005-11-29 06:16:21 +0000110 setOperationAction(ISD::LOCATION, MVT::Other, Expand);
Jim Laskeye0bce712006-01-05 01:47:43 +0000111 setOperationAction(ISD::DEBUG_LOC, MVT::Other, Expand);
Jim Laskeyabf6d172006-01-05 01:25:28 +0000112 // FIXME - use subtarget debug flags
Jim Laskeye0bce712006-01-05 01:47:43 +0000113 if (!TM.getSubtarget<PPCSubtarget>().isDarwin())
Jim Laskeyabf6d172006-01-05 01:25:28 +0000114 setOperationAction(ISD::DEBUG_LABEL, MVT::Other, Expand);
Chris Lattnere6ec9f22005-09-10 00:21:06 +0000115
Nate Begeman28a6b022005-12-10 02:36:00 +0000116 // We want to legalize GlobalAddress and ConstantPool nodes into the
117 // appropriate instructions to materialize the address.
Chris Lattner3eef4e32005-11-17 18:26:56 +0000118 setOperationAction(ISD::GlobalAddress, MVT::i32, Custom);
Nate Begeman28a6b022005-12-10 02:36:00 +0000119 setOperationAction(ISD::ConstantPool, MVT::i32, Custom);
Chris Lattnerb99329e2006-01-13 02:42:53 +0000120
Nate Begemanee625572006-01-27 21:09:22 +0000121 // RET must be custom lowered, to meet ABI requirements
122 setOperationAction(ISD::RET , MVT::Other, Custom);
123
Nate Begemanacc398c2006-01-25 18:21:52 +0000124 // VASTART needs to be custom lowered to use the VarArgsFrameIndex
125 setOperationAction(ISD::VASTART , MVT::Other, Custom);
126
Chris Lattnerb22c08b2006-01-15 09:02:48 +0000127 // Use the default implementation.
Nate Begemanacc398c2006-01-25 18:21:52 +0000128 setOperationAction(ISD::VAARG , MVT::Other, Expand);
129 setOperationAction(ISD::VACOPY , MVT::Other, Expand);
130 setOperationAction(ISD::VAEND , MVT::Other, Expand);
Chris Lattnerb22c08b2006-01-15 09:02:48 +0000131 setOperationAction(ISD::STACKSAVE , MVT::Other, Expand);
132 setOperationAction(ISD::STACKRESTORE , MVT::Other, Expand);
133 setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32 , Expand);
Chris Lattner860e8862005-11-17 07:30:41 +0000134
Nate Begemanc09eeec2005-09-06 22:03:27 +0000135 if (TM.getSubtarget<PPCSubtarget>().is64Bit()) {
Nate Begeman1d9d7422005-10-18 00:28:58 +0000136 // They also have instructions for converting between i64 and fp.
Nate Begemanc09eeec2005-09-06 22:03:27 +0000137 setOperationAction(ISD::FP_TO_SINT, MVT::i64, Custom);
138 setOperationAction(ISD::SINT_TO_FP, MVT::i64, Custom);
Nate Begemanae749a92005-10-25 23:48:36 +0000139 // To take advantage of the above i64 FP_TO_SINT, promote i32 FP_TO_UINT
140 setOperationAction(ISD::FP_TO_UINT, MVT::i32, Promote);
141 } else {
Chris Lattner860e8862005-11-17 07:30:41 +0000142 // PowerPC does not have FP_TO_UINT on 32-bit implementations.
Nate Begemanae749a92005-10-25 23:48:36 +0000143 setOperationAction(ISD::FP_TO_UINT, MVT::i32, Expand);
Nate Begeman9d2b8172005-10-18 00:56:42 +0000144 }
145
146 if (TM.getSubtarget<PPCSubtarget>().has64BitRegs()) {
147 // 64 bit PowerPC implementations can support i64 types directly
148 addRegisterClass(MVT::i64, PPC::G8RCRegisterClass);
Nate Begeman1d9d7422005-10-18 00:28:58 +0000149 // BUILD_PAIR can't be handled natively, and should be expanded to shl/or
150 setOperationAction(ISD::BUILD_PAIR, MVT::i64, Expand);
Nate Begeman1d9d7422005-10-18 00:28:58 +0000151 } else {
152 // 32 bit PowerPC wants to expand i64 shifts itself.
153 setOperationAction(ISD::SHL, MVT::i64, Custom);
154 setOperationAction(ISD::SRL, MVT::i64, Custom);
155 setOperationAction(ISD::SRA, MVT::i64, Custom);
Nate Begemanc09eeec2005-09-06 22:03:27 +0000156 }
157
Nate Begeman425a9692005-11-29 08:17:20 +0000158 if (TM.getSubtarget<PPCSubtarget>().hasAltivec()) {
Nate Begeman425a9692005-11-29 08:17:20 +0000159 addRegisterClass(MVT::v4f32, PPC::VRRCRegisterClass);
Nate Begeman7fd1edd2005-12-19 23:25:09 +0000160 addRegisterClass(MVT::v4i32, PPC::VRRCRegisterClass);
Chris Lattnerec4a0c72006-01-29 06:32:58 +0000161
162 // FIXME: We don't support any ConstantVec's yet. We should custom expand
163 // the ones we do!
Chris Lattnerd9b55dd2006-01-29 08:41:37 +0000164 setOperationAction(ISD::ConstantVec, MVT::v4f32, Expand);
165 setOperationAction(ISD::ConstantVec, MVT::v4i32, Expand);
Nate Begeman425a9692005-11-29 08:17:20 +0000166 }
167
Chris Lattner7c5a3d32005-08-16 17:14:42 +0000168 setSetCCResultContents(ZeroOrOneSetCCResult);
Chris Lattnercadd7422006-01-13 17:52:03 +0000169 setStackPointerRegisterToSaveRestore(PPC::R1);
Chris Lattner7c5a3d32005-08-16 17:14:42 +0000170
171 computeRegisterProperties();
172}
173
Chris Lattnerda6d20f2006-01-09 23:52:17 +0000174const char *PPCTargetLowering::getTargetNodeName(unsigned Opcode) const {
175 switch (Opcode) {
176 default: return 0;
177 case PPCISD::FSEL: return "PPCISD::FSEL";
178 case PPCISD::FCFID: return "PPCISD::FCFID";
179 case PPCISD::FCTIDZ: return "PPCISD::FCTIDZ";
180 case PPCISD::FCTIWZ: return "PPCISD::FCTIWZ";
181 case PPCISD::VMADDFP: return "PPCISD::VMADDFP";
182 case PPCISD::VNMSUBFP: return "PPCISD::VNMSUBFP";
183 case PPCISD::Hi: return "PPCISD::Hi";
184 case PPCISD::Lo: return "PPCISD::Lo";
185 case PPCISD::GlobalBaseReg: return "PPCISD::GlobalBaseReg";
186 case PPCISD::SRL: return "PPCISD::SRL";
187 case PPCISD::SRA: return "PPCISD::SRA";
188 case PPCISD::SHL: return "PPCISD::SHL";
Chris Lattnere00ebf02006-01-28 07:33:03 +0000189 case PPCISD::CALL: return "PPCISD::CALL";
Chris Lattnerda6d20f2006-01-09 23:52:17 +0000190 case PPCISD::RET_FLAG: return "PPCISD::RET_FLAG";
191 }
192}
193
Chris Lattner0b1e4e52005-08-26 17:36:52 +0000194/// isFloatingPointZero - Return true if this is 0.0 or -0.0.
195static bool isFloatingPointZero(SDOperand Op) {
196 if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(Op))
197 return CFP->isExactlyValue(-0.0) || CFP->isExactlyValue(0.0);
198 else if (Op.getOpcode() == ISD::EXTLOAD || Op.getOpcode() == ISD::LOAD) {
199 // Maybe this has already been legalized into the constant pool?
200 if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(Op.getOperand(1)))
201 if (ConstantFP *CFP = dyn_cast<ConstantFP>(CP->get()))
202 return CFP->isExactlyValue(-0.0) || CFP->isExactlyValue(0.0);
203 }
204 return false;
205}
206
Chris Lattnere4bc9ea2005-08-26 00:52:45 +0000207/// LowerOperation - Provide custom lowering hooks for some operations.
208///
Nate Begeman21e463b2005-10-16 05:39:50 +0000209SDOperand PPCTargetLowering::LowerOperation(SDOperand Op, SelectionDAG &DAG) {
Chris Lattnere4bc9ea2005-08-26 00:52:45 +0000210 switch (Op.getOpcode()) {
211 default: assert(0 && "Wasn't expecting to be able to lower this!");
Chris Lattnerf7605322005-08-31 21:09:52 +0000212 case ISD::FP_TO_SINT: {
Nate Begemanc09eeec2005-09-06 22:03:27 +0000213 assert(MVT::isFloatingPoint(Op.getOperand(0).getValueType()));
Chris Lattner7c0d6642005-10-02 06:37:13 +0000214 SDOperand Src = Op.getOperand(0);
215 if (Src.getValueType() == MVT::f32)
216 Src = DAG.getNode(ISD::FP_EXTEND, MVT::f64, Src);
217
Chris Lattner1b95e0b2005-12-23 00:59:59 +0000218 SDOperand Tmp;
Nate Begemanc09eeec2005-09-06 22:03:27 +0000219 switch (Op.getValueType()) {
220 default: assert(0 && "Unhandled FP_TO_SINT type in custom expander!");
221 case MVT::i32:
Chris Lattner1b95e0b2005-12-23 00:59:59 +0000222 Tmp = DAG.getNode(PPCISD::FCTIWZ, MVT::f64, Src);
Nate Begemanc09eeec2005-09-06 22:03:27 +0000223 break;
224 case MVT::i64:
Chris Lattner1b95e0b2005-12-23 00:59:59 +0000225 Tmp = DAG.getNode(PPCISD::FCTIDZ, MVT::f64, Src);
Nate Begemanc09eeec2005-09-06 22:03:27 +0000226 break;
227 }
Chris Lattnerf7605322005-08-31 21:09:52 +0000228
Chris Lattner1b95e0b2005-12-23 00:59:59 +0000229 // Convert the FP value to an int value through memory.
230 SDOperand Bits = DAG.getNode(ISD::BIT_CONVERT, MVT::i64, Tmp);
231 if (Op.getValueType() == MVT::i32)
232 Bits = DAG.getNode(ISD::TRUNCATE, MVT::i32, Bits);
233 return Bits;
Nate Begemanc09eeec2005-09-06 22:03:27 +0000234 }
235 case ISD::SINT_TO_FP: {
236 assert(MVT::i64 == Op.getOperand(0).getValueType() &&
237 "Unhandled SINT_TO_FP type in custom expander!");
Chris Lattner1b95e0b2005-12-23 00:59:59 +0000238 SDOperand Bits = DAG.getNode(ISD::BIT_CONVERT, MVT::f64, Op.getOperand(0));
239 SDOperand FP = DAG.getNode(PPCISD::FCFID, MVT::f64, Bits);
Nate Begemanc09eeec2005-09-06 22:03:27 +0000240 if (MVT::f32 == Op.getValueType())
241 FP = DAG.getNode(ISD::FP_ROUND, MVT::f32, FP);
242 return FP;
Chris Lattnerf7605322005-08-31 21:09:52 +0000243 }
244 case ISD::SELECT_CC: {
Chris Lattnere4bc9ea2005-08-26 00:52:45 +0000245 // Turn FP only select_cc's into fsel instructions.
Chris Lattnerf7605322005-08-31 21:09:52 +0000246 if (!MVT::isFloatingPoint(Op.getOperand(0).getValueType()) ||
247 !MVT::isFloatingPoint(Op.getOperand(2).getValueType()))
248 break;
249
250 ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(4))->get();
251
252 // Cannot handle SETEQ/SETNE.
253 if (CC == ISD::SETEQ || CC == ISD::SETNE) break;
254
255 MVT::ValueType ResVT = Op.getValueType();
256 MVT::ValueType CmpVT = Op.getOperand(0).getValueType();
257 SDOperand LHS = Op.getOperand(0), RHS = Op.getOperand(1);
258 SDOperand TV = Op.getOperand(2), FV = Op.getOperand(3);
Chris Lattnere4bc9ea2005-08-26 00:52:45 +0000259
Chris Lattnerf7605322005-08-31 21:09:52 +0000260 // If the RHS of the comparison is a 0.0, we don't need to do the
261 // subtraction at all.
262 if (isFloatingPointZero(RHS))
Chris Lattnere4bc9ea2005-08-26 00:52:45 +0000263 switch (CC) {
Chris Lattnerbc38dbf2006-01-18 19:42:35 +0000264 default: break; // SETUO etc aren't handled by fsel.
Chris Lattnere4bc9ea2005-08-26 00:52:45 +0000265 case ISD::SETULT:
266 case ISD::SETLT:
Chris Lattnerf7605322005-08-31 21:09:52 +0000267 std::swap(TV, FV); // fsel is natively setge, swap operands for setlt
Chris Lattnere4bc9ea2005-08-26 00:52:45 +0000268 case ISD::SETUGE:
269 case ISD::SETGE:
Chris Lattnereb255f22005-10-25 20:54:57 +0000270 if (LHS.getValueType() == MVT::f32) // Comparison is always 64-bits
271 LHS = DAG.getNode(ISD::FP_EXTEND, MVT::f64, LHS);
Chris Lattnerf7605322005-08-31 21:09:52 +0000272 return DAG.getNode(PPCISD::FSEL, ResVT, LHS, TV, FV);
Chris Lattnere4bc9ea2005-08-26 00:52:45 +0000273 case ISD::SETUGT:
274 case ISD::SETGT:
Chris Lattnerf7605322005-08-31 21:09:52 +0000275 std::swap(TV, FV); // fsel is natively setge, swap operands for setlt
Chris Lattnere4bc9ea2005-08-26 00:52:45 +0000276 case ISD::SETULE:
277 case ISD::SETLE:
Chris Lattnereb255f22005-10-25 20:54:57 +0000278 if (LHS.getValueType() == MVT::f32) // Comparison is always 64-bits
279 LHS = DAG.getNode(ISD::FP_EXTEND, MVT::f64, LHS);
Chris Lattner0bbea952005-08-26 20:25:03 +0000280 return DAG.getNode(PPCISD::FSEL, ResVT,
Chris Lattner85fd97d2005-10-26 18:01:11 +0000281 DAG.getNode(ISD::FNEG, MVT::f64, LHS), TV, FV);
Chris Lattnere4bc9ea2005-08-26 00:52:45 +0000282 }
Chris Lattnerf7605322005-08-31 21:09:52 +0000283
Chris Lattnereb255f22005-10-25 20:54:57 +0000284 SDOperand Cmp;
Chris Lattnerf7605322005-08-31 21:09:52 +0000285 switch (CC) {
Chris Lattnerbc38dbf2006-01-18 19:42:35 +0000286 default: break; // SETUO etc aren't handled by fsel.
Chris Lattnerf7605322005-08-31 21:09:52 +0000287 case ISD::SETULT:
288 case ISD::SETLT:
Chris Lattnereb255f22005-10-25 20:54:57 +0000289 Cmp = DAG.getNode(ISD::FSUB, CmpVT, LHS, RHS);
290 if (Cmp.getValueType() == MVT::f32) // Comparison is always 64-bits
291 Cmp = DAG.getNode(ISD::FP_EXTEND, MVT::f64, Cmp);
292 return DAG.getNode(PPCISD::FSEL, ResVT, Cmp, FV, TV);
Chris Lattnerf7605322005-08-31 21:09:52 +0000293 case ISD::SETUGE:
294 case ISD::SETGE:
Chris Lattnereb255f22005-10-25 20:54:57 +0000295 Cmp = DAG.getNode(ISD::FSUB, CmpVT, LHS, RHS);
296 if (Cmp.getValueType() == MVT::f32) // Comparison is always 64-bits
297 Cmp = DAG.getNode(ISD::FP_EXTEND, MVT::f64, Cmp);
298 return DAG.getNode(PPCISD::FSEL, ResVT, Cmp, TV, FV);
Chris Lattnerf7605322005-08-31 21:09:52 +0000299 case ISD::SETUGT:
300 case ISD::SETGT:
Chris Lattnereb255f22005-10-25 20:54:57 +0000301 Cmp = DAG.getNode(ISD::FSUB, CmpVT, RHS, LHS);
302 if (Cmp.getValueType() == MVT::f32) // Comparison is always 64-bits
303 Cmp = DAG.getNode(ISD::FP_EXTEND, MVT::f64, Cmp);
304 return DAG.getNode(PPCISD::FSEL, ResVT, Cmp, FV, TV);
Chris Lattnerf7605322005-08-31 21:09:52 +0000305 case ISD::SETULE:
306 case ISD::SETLE:
Chris Lattnereb255f22005-10-25 20:54:57 +0000307 Cmp = DAG.getNode(ISD::FSUB, CmpVT, RHS, LHS);
308 if (Cmp.getValueType() == MVT::f32) // Comparison is always 64-bits
309 Cmp = DAG.getNode(ISD::FP_EXTEND, MVT::f64, Cmp);
310 return DAG.getNode(PPCISD::FSEL, ResVT, Cmp, TV, FV);
Chris Lattnere4bc9ea2005-08-26 00:52:45 +0000311 }
Chris Lattnerf7605322005-08-31 21:09:52 +0000312 break;
313 }
Chris Lattnerbc11c342005-08-31 20:23:54 +0000314 case ISD::SHL: {
315 assert(Op.getValueType() == MVT::i64 &&
316 Op.getOperand(1).getValueType() == MVT::i32 && "Unexpected SHL!");
317 // The generic code does a fine job expanding shift by a constant.
318 if (isa<ConstantSDNode>(Op.getOperand(1))) break;
319
320 // Otherwise, expand into a bunch of logical ops. Note that these ops
321 // depend on the PPC behavior for oversized shift amounts.
322 SDOperand Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32, Op.getOperand(0),
323 DAG.getConstant(0, MVT::i32));
324 SDOperand Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32, Op.getOperand(0),
325 DAG.getConstant(1, MVT::i32));
326 SDOperand Amt = Op.getOperand(1);
327
328 SDOperand Tmp1 = DAG.getNode(ISD::SUB, MVT::i32,
329 DAG.getConstant(32, MVT::i32), Amt);
Chris Lattner4172b102005-12-06 02:10:38 +0000330 SDOperand Tmp2 = DAG.getNode(PPCISD::SHL, MVT::i32, Hi, Amt);
331 SDOperand Tmp3 = DAG.getNode(PPCISD::SRL, MVT::i32, Lo, Tmp1);
Chris Lattnerbc11c342005-08-31 20:23:54 +0000332 SDOperand Tmp4 = DAG.getNode(ISD::OR , MVT::i32, Tmp2, Tmp3);
333 SDOperand Tmp5 = DAG.getNode(ISD::ADD, MVT::i32, Amt,
334 DAG.getConstant(-32U, MVT::i32));
Chris Lattner4172b102005-12-06 02:10:38 +0000335 SDOperand Tmp6 = DAG.getNode(PPCISD::SHL, MVT::i32, Lo, Tmp5);
Chris Lattnerbc11c342005-08-31 20:23:54 +0000336 SDOperand OutHi = DAG.getNode(ISD::OR, MVT::i32, Tmp4, Tmp6);
Chris Lattner4172b102005-12-06 02:10:38 +0000337 SDOperand OutLo = DAG.getNode(PPCISD::SHL, MVT::i32, Lo, Amt);
Chris Lattnerbc11c342005-08-31 20:23:54 +0000338 return DAG.getNode(ISD::BUILD_PAIR, MVT::i64, OutLo, OutHi);
339 }
340 case ISD::SRL: {
341 assert(Op.getValueType() == MVT::i64 &&
342 Op.getOperand(1).getValueType() == MVT::i32 && "Unexpected SHL!");
343 // The generic code does a fine job expanding shift by a constant.
344 if (isa<ConstantSDNode>(Op.getOperand(1))) break;
345
346 // Otherwise, expand into a bunch of logical ops. Note that these ops
347 // depend on the PPC behavior for oversized shift amounts.
348 SDOperand Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32, Op.getOperand(0),
349 DAG.getConstant(0, MVT::i32));
350 SDOperand Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32, Op.getOperand(0),
351 DAG.getConstant(1, MVT::i32));
352 SDOperand Amt = Op.getOperand(1);
353
354 SDOperand Tmp1 = DAG.getNode(ISD::SUB, MVT::i32,
355 DAG.getConstant(32, MVT::i32), Amt);
Chris Lattner4172b102005-12-06 02:10:38 +0000356 SDOperand Tmp2 = DAG.getNode(PPCISD::SRL, MVT::i32, Lo, Amt);
357 SDOperand Tmp3 = DAG.getNode(PPCISD::SHL, MVT::i32, Hi, Tmp1);
Chris Lattnerbc11c342005-08-31 20:23:54 +0000358 SDOperand Tmp4 = DAG.getNode(ISD::OR , MVT::i32, Tmp2, Tmp3);
359 SDOperand Tmp5 = DAG.getNode(ISD::ADD, MVT::i32, Amt,
360 DAG.getConstant(-32U, MVT::i32));
Chris Lattner4172b102005-12-06 02:10:38 +0000361 SDOperand Tmp6 = DAG.getNode(PPCISD::SRL, MVT::i32, Hi, Tmp5);
Chris Lattnerbc11c342005-08-31 20:23:54 +0000362 SDOperand OutLo = DAG.getNode(ISD::OR, MVT::i32, Tmp4, Tmp6);
Chris Lattner4172b102005-12-06 02:10:38 +0000363 SDOperand OutHi = DAG.getNode(PPCISD::SRL, MVT::i32, Hi, Amt);
Chris Lattnerbc11c342005-08-31 20:23:54 +0000364 return DAG.getNode(ISD::BUILD_PAIR, MVT::i64, OutLo, OutHi);
365 }
366 case ISD::SRA: {
Chris Lattnereb9b62e2005-08-31 19:09:57 +0000367 assert(Op.getValueType() == MVT::i64 &&
368 Op.getOperand(1).getValueType() == MVT::i32 && "Unexpected SRA!");
369 // The generic code does a fine job expanding shift by a constant.
370 if (isa<ConstantSDNode>(Op.getOperand(1))) break;
371
372 // Otherwise, expand into a bunch of logical ops, followed by a select_cc.
373 SDOperand Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32, Op.getOperand(0),
374 DAG.getConstant(0, MVT::i32));
375 SDOperand Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32, Op.getOperand(0),
376 DAG.getConstant(1, MVT::i32));
377 SDOperand Amt = Op.getOperand(1);
378
379 SDOperand Tmp1 = DAG.getNode(ISD::SUB, MVT::i32,
380 DAG.getConstant(32, MVT::i32), Amt);
Chris Lattner4172b102005-12-06 02:10:38 +0000381 SDOperand Tmp2 = DAG.getNode(PPCISD::SRL, MVT::i32, Lo, Amt);
382 SDOperand Tmp3 = DAG.getNode(PPCISD::SHL, MVT::i32, Hi, Tmp1);
Chris Lattnereb9b62e2005-08-31 19:09:57 +0000383 SDOperand Tmp4 = DAG.getNode(ISD::OR , MVT::i32, Tmp2, Tmp3);
384 SDOperand Tmp5 = DAG.getNode(ISD::ADD, MVT::i32, Amt,
385 DAG.getConstant(-32U, MVT::i32));
Chris Lattner4172b102005-12-06 02:10:38 +0000386 SDOperand Tmp6 = DAG.getNode(PPCISD::SRA, MVT::i32, Hi, Tmp5);
387 SDOperand OutHi = DAG.getNode(PPCISD::SRA, MVT::i32, Hi, Amt);
Chris Lattnereb9b62e2005-08-31 19:09:57 +0000388 SDOperand OutLo = DAG.getSelectCC(Tmp5, DAG.getConstant(0, MVT::i32),
389 Tmp4, Tmp6, ISD::SETLE);
390 return DAG.getNode(ISD::BUILD_PAIR, MVT::i64, OutLo, OutHi);
Chris Lattnere4bc9ea2005-08-26 00:52:45 +0000391 }
Nate Begeman28a6b022005-12-10 02:36:00 +0000392 case ISD::ConstantPool: {
Evan Chengb8973bd2006-01-31 22:23:14 +0000393 ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op);
394 Constant *C = CP->get();
395 SDOperand CPI = DAG.getTargetConstantPool(C, MVT::i32, CP->getAlignment());
Nate Begeman28a6b022005-12-10 02:36:00 +0000396 SDOperand Zero = DAG.getConstant(0, MVT::i32);
397
398 if (PPCGenerateStaticCode) {
399 // Generate non-pic code that has direct accesses to the constant pool.
400 // The address of the global is just (hi(&g)+lo(&g)).
401 SDOperand Hi = DAG.getNode(PPCISD::Hi, MVT::i32, CPI, Zero);
402 SDOperand Lo = DAG.getNode(PPCISD::Lo, MVT::i32, CPI, Zero);
403 return DAG.getNode(ISD::ADD, MVT::i32, Hi, Lo);
404 }
405
406 // Only lower ConstantPool on Darwin.
407 if (!getTargetMachine().getSubtarget<PPCSubtarget>().isDarwin()) break;
408 SDOperand Hi = DAG.getNode(PPCISD::Hi, MVT::i32, CPI, Zero);
409 if (PICEnabled) {
410 // With PIC, the first instruction is actually "GR+hi(&G)".
411 Hi = DAG.getNode(ISD::ADD, MVT::i32,
412 DAG.getNode(PPCISD::GlobalBaseReg, MVT::i32), Hi);
413 }
414
415 SDOperand Lo = DAG.getNode(PPCISD::Lo, MVT::i32, CPI, Zero);
416 Lo = DAG.getNode(ISD::ADD, MVT::i32, Hi, Lo);
417 return Lo;
418 }
Chris Lattner860e8862005-11-17 07:30:41 +0000419 case ISD::GlobalAddress: {
Nate Begeman50fb3c42005-12-24 01:00:15 +0000420 GlobalAddressSDNode *GSDN = cast<GlobalAddressSDNode>(Op);
421 GlobalValue *GV = GSDN->getGlobal();
422 SDOperand GA = DAG.getTargetGlobalAddress(GV, MVT::i32, GSDN->getOffset());
Chris Lattner860e8862005-11-17 07:30:41 +0000423 SDOperand Zero = DAG.getConstant(0, MVT::i32);
Chris Lattner1d05cb42005-11-17 18:55:48 +0000424
425 if (PPCGenerateStaticCode) {
Nate Begeman28a6b022005-12-10 02:36:00 +0000426 // Generate non-pic code that has direct accesses to globals.
427 // The address of the global is just (hi(&g)+lo(&g)).
Chris Lattner1d05cb42005-11-17 18:55:48 +0000428 SDOperand Hi = DAG.getNode(PPCISD::Hi, MVT::i32, GA, Zero);
429 SDOperand Lo = DAG.getNode(PPCISD::Lo, MVT::i32, GA, Zero);
430 return DAG.getNode(ISD::ADD, MVT::i32, Hi, Lo);
431 }
Chris Lattner860e8862005-11-17 07:30:41 +0000432
Chris Lattner1d05cb42005-11-17 18:55:48 +0000433 // Only lower GlobalAddress on Darwin.
434 if (!getTargetMachine().getSubtarget<PPCSubtarget>().isDarwin()) break;
Chris Lattnera35ef632006-01-06 01:04:03 +0000435
Chris Lattner860e8862005-11-17 07:30:41 +0000436 SDOperand Hi = DAG.getNode(PPCISD::Hi, MVT::i32, GA, Zero);
437 if (PICEnabled) {
438 // With PIC, the first instruction is actually "GR+hi(&G)".
439 Hi = DAG.getNode(ISD::ADD, MVT::i32,
Chris Lattner15666132005-11-17 17:51:38 +0000440 DAG.getNode(PPCISD::GlobalBaseReg, MVT::i32), Hi);
Chris Lattner860e8862005-11-17 07:30:41 +0000441 }
442
443 SDOperand Lo = DAG.getNode(PPCISD::Lo, MVT::i32, GA, Zero);
444 Lo = DAG.getNode(ISD::ADD, MVT::i32, Hi, Lo);
445
Chris Lattner37dd6f12006-01-29 20:49:17 +0000446 if (!GV->hasWeakLinkage() && !GV->hasLinkOnceLinkage() &&
447 (!GV->isExternal() || GV->hasNotBeenReadFromBytecode()))
Chris Lattner860e8862005-11-17 07:30:41 +0000448 return Lo;
449
450 // If the global is weak or external, we have to go through the lazy
451 // resolution stub.
452 return DAG.getLoad(MVT::i32, DAG.getEntryNode(), Lo, DAG.getSrcValue(0));
453 }
Nate Begeman44775902006-01-31 08:17:29 +0000454 case ISD::SETCC: {
455 ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(2))->get();
Nate Begeman750ac1b2006-02-01 07:19:44 +0000456
457 // If we're comparing for equality to zero, expose the fact that this is
458 // implented as a ctlz/srl pair on ppc, so that the dag combiner can
459 // fold the new nodes.
460 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op.getOperand(1))) {
461 if (C->isNullValue() && CC == ISD::SETEQ) {
462 MVT::ValueType VT = Op.getOperand(0).getValueType();
463 SDOperand Zext = Op.getOperand(0);
464 if (VT < MVT::i32) {
465 VT = MVT::i32;
466 Zext = DAG.getNode(ISD::ZERO_EXTEND, VT, Op.getOperand(0));
467 }
468 unsigned Log2b = Log2_32(MVT::getSizeInBits(VT));
469 SDOperand Clz = DAG.getNode(ISD::CTLZ, VT, Zext);
470 SDOperand Scc = DAG.getNode(ISD::SRL, VT, Clz,
471 DAG.getConstant(Log2b, getShiftAmountTy()));
472 return DAG.getNode(ISD::TRUNCATE, getSetCCResultTy(), Scc);
473 }
474 // Leave comparisons against 0 and -1 alone for now, since they're usually
475 // optimized. FIXME: revisit this when we can custom lower all setcc
476 // optimizations.
477 if (C->isAllOnesValue() || C->isNullValue())
478 break;
479 }
480
481 // If we have an integer seteq/setne, turn it into a compare against zero
482 // by subtracting the rhs from the lhs, which is faster than setting a
483 // condition register, reading it back out, and masking the correct bit.
484 MVT::ValueType LHSVT = Op.getOperand(0).getValueType();
485 if (MVT::isInteger(LHSVT) && (CC == ISD::SETEQ || CC == ISD::SETNE)) {
486 MVT::ValueType VT = Op.getValueType();
487 SDOperand Sub = DAG.getNode(ISD::SUB, LHSVT, Op.getOperand(0),
488 Op.getOperand(1));
489 return DAG.getSetCC(VT, Sub, DAG.getConstant(0, LHSVT), CC);
490 }
Nate Begeman44775902006-01-31 08:17:29 +0000491 break;
492 }
Nate Begemanacc398c2006-01-25 18:21:52 +0000493 case ISD::VASTART: {
494 // vastart just stores the address of the VarArgsFrameIndex slot into the
495 // memory location argument.
496 // FIXME: Replace MVT::i32 with PointerTy
497 SDOperand FR = DAG.getFrameIndex(VarArgsFrameIndex, MVT::i32);
498 return DAG.getNode(ISD::STORE, MVT::Other, Op.getOperand(0), FR,
499 Op.getOperand(1), Op.getOperand(2));
500 }
Nate Begemanee625572006-01-27 21:09:22 +0000501 case ISD::RET: {
502 SDOperand Copy;
503
504 switch(Op.getNumOperands()) {
505 default:
506 assert(0 && "Do not know how to return this many arguments!");
507 abort();
508 case 1:
509 return SDOperand(); // ret void is legal
510 case 2: {
511 MVT::ValueType ArgVT = Op.getOperand(1).getValueType();
512 unsigned ArgReg = MVT::isInteger(ArgVT) ? PPC::R3 : PPC::F1;
513 Copy = DAG.getCopyToReg(Op.getOperand(0), ArgReg, Op.getOperand(1),
514 SDOperand());
515 break;
516 }
517 case 3:
518 Copy = DAG.getCopyToReg(Op.getOperand(0), PPC::R3, Op.getOperand(2),
519 SDOperand());
520 Copy = DAG.getCopyToReg(Copy, PPC::R4, Op.getOperand(1),Copy.getValue(1));
521 break;
522 }
523 return DAG.getNode(PPCISD::RET_FLAG, MVT::Other, Copy, Copy.getValue(1));
524 }
Chris Lattnerbc11c342005-08-31 20:23:54 +0000525 }
Chris Lattnere4bc9ea2005-08-26 00:52:45 +0000526 return SDOperand();
527}
528
Chris Lattner7c5a3d32005-08-16 17:14:42 +0000529std::vector<SDOperand>
Nate Begeman21e463b2005-10-16 05:39:50 +0000530PPCTargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) {
Chris Lattner7c5a3d32005-08-16 17:14:42 +0000531 //
532 // add beautiful description of PPC stack frame format, or at least some docs
533 //
534 MachineFunction &MF = DAG.getMachineFunction();
535 MachineFrameInfo *MFI = MF.getFrameInfo();
536 MachineBasicBlock& BB = MF.front();
Chris Lattner7b738342005-09-13 19:33:40 +0000537 SSARegMap *RegMap = MF.getSSARegMap();
Chris Lattner7c5a3d32005-08-16 17:14:42 +0000538 std::vector<SDOperand> ArgValues;
539
Chris Lattner7c5a3d32005-08-16 17:14:42 +0000540 unsigned ArgOffset = 24;
541 unsigned GPR_remaining = 8;
542 unsigned FPR_remaining = 13;
543 unsigned GPR_idx = 0, FPR_idx = 0;
544 static const unsigned GPR[] = {
545 PPC::R3, PPC::R4, PPC::R5, PPC::R6,
546 PPC::R7, PPC::R8, PPC::R9, PPC::R10,
547 };
548 static const unsigned FPR[] = {
549 PPC::F1, PPC::F2, PPC::F3, PPC::F4, PPC::F5, PPC::F6, PPC::F7,
550 PPC::F8, PPC::F9, PPC::F10, PPC::F11, PPC::F12, PPC::F13
551 };
552
553 // Add DAG nodes to load the arguments... On entry to a function on PPC,
554 // the arguments start at offset 24, although they are likely to be passed
555 // in registers.
556 for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; ++I) {
557 SDOperand newroot, argt;
558 unsigned ObjSize;
559 bool needsLoad = false;
560 bool ArgLive = !I->use_empty();
561 MVT::ValueType ObjectVT = getValueType(I->getType());
562
563 switch (ObjectVT) {
Chris Lattner915fb302005-08-30 00:19:00 +0000564 default: assert(0 && "Unhandled argument type!");
565 case MVT::i1:
566 case MVT::i8:
567 case MVT::i16:
568 case MVT::i32:
569 ObjSize = 4;
570 if (!ArgLive) break;
571 if (GPR_remaining > 0) {
Nate Begeman1d9d7422005-10-18 00:28:58 +0000572 unsigned VReg = RegMap->createVirtualRegister(&PPC::GPRCRegClass);
Chris Lattner7b738342005-09-13 19:33:40 +0000573 MF.addLiveIn(GPR[GPR_idx], VReg);
574 argt = newroot = DAG.getCopyFromReg(DAG.getRoot(), VReg, MVT::i32);
Nate Begeman49296f12005-08-31 01:58:39 +0000575 if (ObjectVT != MVT::i32) {
576 unsigned AssertOp = I->getType()->isSigned() ? ISD::AssertSext
577 : ISD::AssertZext;
578 argt = DAG.getNode(AssertOp, MVT::i32, argt,
579 DAG.getValueType(ObjectVT));
580 argt = DAG.getNode(ISD::TRUNCATE, ObjectVT, argt);
581 }
Chris Lattner915fb302005-08-30 00:19:00 +0000582 } else {
583 needsLoad = true;
584 }
585 break;
Chris Lattner80720a92005-11-30 20:40:54 +0000586 case MVT::i64:
587 ObjSize = 8;
Chris Lattner915fb302005-08-30 00:19:00 +0000588 if (!ArgLive) break;
589 if (GPR_remaining > 0) {
590 SDOperand argHi, argLo;
Nate Begeman1d9d7422005-10-18 00:28:58 +0000591 unsigned VReg = RegMap->createVirtualRegister(&PPC::GPRCRegClass);
Chris Lattner7b738342005-09-13 19:33:40 +0000592 MF.addLiveIn(GPR[GPR_idx], VReg);
593 argHi = DAG.getCopyFromReg(DAG.getRoot(), VReg, MVT::i32);
Chris Lattner915fb302005-08-30 00:19:00 +0000594 // If we have two or more remaining argument registers, then both halves
595 // of the i64 can be sourced from there. Otherwise, the lower half will
596 // have to come off the stack. This can happen when an i64 is preceded
597 // by 28 bytes of arguments.
598 if (GPR_remaining > 1) {
Nate Begeman1d9d7422005-10-18 00:28:58 +0000599 unsigned VReg = RegMap->createVirtualRegister(&PPC::GPRCRegClass);
Chris Lattner7b738342005-09-13 19:33:40 +0000600 MF.addLiveIn(GPR[GPR_idx+1], VReg);
601 argLo = DAG.getCopyFromReg(argHi, VReg, MVT::i32);
Chris Lattner915fb302005-08-30 00:19:00 +0000602 } else {
603 int FI = MFI->CreateFixedObject(4, ArgOffset+4);
604 SDOperand FIN = DAG.getFrameIndex(FI, MVT::i32);
605 argLo = DAG.getLoad(MVT::i32, DAG.getEntryNode(), FIN,
606 DAG.getSrcValue(NULL));
607 }
608 // Build the outgoing arg thingy
609 argt = DAG.getNode(ISD::BUILD_PAIR, MVT::i64, argLo, argHi);
610 newroot = argLo;
611 } else {
612 needsLoad = true;
613 }
614 break;
615 case MVT::f32:
616 case MVT::f64:
617 ObjSize = (ObjectVT == MVT::f64) ? 8 : 4;
Chris Lattner413b9792006-01-11 18:21:25 +0000618 if (!ArgLive) {
619 if (FPR_remaining > 0) {
620 --FPR_remaining;
621 ++FPR_idx;
622 }
623 break;
624 }
Chris Lattner915fb302005-08-30 00:19:00 +0000625 if (FPR_remaining > 0) {
Chris Lattner919c0322005-10-01 01:35:02 +0000626 unsigned VReg;
627 if (ObjectVT == MVT::f32)
Nate Begeman1d9d7422005-10-18 00:28:58 +0000628 VReg = RegMap->createVirtualRegister(&PPC::F4RCRegClass);
Chris Lattner919c0322005-10-01 01:35:02 +0000629 else
Nate Begeman1d9d7422005-10-18 00:28:58 +0000630 VReg = RegMap->createVirtualRegister(&PPC::F8RCRegClass);
Chris Lattner7b738342005-09-13 19:33:40 +0000631 MF.addLiveIn(FPR[FPR_idx], VReg);
632 argt = newroot = DAG.getCopyFromReg(DAG.getRoot(), VReg, ObjectVT);
Chris Lattner915fb302005-08-30 00:19:00 +0000633 --FPR_remaining;
634 ++FPR_idx;
635 } else {
636 needsLoad = true;
637 }
638 break;
Chris Lattner7c5a3d32005-08-16 17:14:42 +0000639 }
640
641 // We need to load the argument to a virtual register if we determined above
642 // that we ran out of physical registers of the appropriate type
643 if (needsLoad) {
644 unsigned SubregOffset = 0;
645 if (ObjectVT == MVT::i8 || ObjectVT == MVT::i1) SubregOffset = 3;
646 if (ObjectVT == MVT::i16) SubregOffset = 2;
647 int FI = MFI->CreateFixedObject(ObjSize, ArgOffset);
648 SDOperand FIN = DAG.getFrameIndex(FI, MVT::i32);
649 FIN = DAG.getNode(ISD::ADD, MVT::i32, FIN,
650 DAG.getConstant(SubregOffset, MVT::i32));
651 argt = newroot = DAG.getLoad(ObjectVT, DAG.getEntryNode(), FIN,
652 DAG.getSrcValue(NULL));
653 }
654
655 // Every 4 bytes of argument space consumes one of the GPRs available for
656 // argument passing.
657 if (GPR_remaining > 0) {
658 unsigned delta = (GPR_remaining > 1 && ObjSize == 8) ? 2 : 1;
659 GPR_remaining -= delta;
660 GPR_idx += delta;
661 }
662 ArgOffset += ObjSize;
663 if (newroot.Val)
664 DAG.setRoot(newroot.getValue(1));
665
666 ArgValues.push_back(argt);
667 }
668
669 // If the function takes variable number of arguments, make a frame index for
670 // the start of the first vararg value... for expansion of llvm.va_start.
671 if (F.isVarArg()) {
672 VarArgsFrameIndex = MFI->CreateFixedObject(4, ArgOffset);
673 SDOperand FIN = DAG.getFrameIndex(VarArgsFrameIndex, MVT::i32);
674 // If this function is vararg, store any remaining integer argument regs
675 // to their spots on the stack so that they may be loaded by deferencing the
676 // result of va_next.
677 std::vector<SDOperand> MemOps;
678 for (; GPR_remaining > 0; --GPR_remaining, ++GPR_idx) {
Nate Begeman1d9d7422005-10-18 00:28:58 +0000679 unsigned VReg = RegMap->createVirtualRegister(&PPC::GPRCRegClass);
Chris Lattner7b738342005-09-13 19:33:40 +0000680 MF.addLiveIn(GPR[GPR_idx], VReg);
681 SDOperand Val = DAG.getCopyFromReg(DAG.getRoot(), VReg, MVT::i32);
Chris Lattner7c5a3d32005-08-16 17:14:42 +0000682 SDOperand Store = DAG.getNode(ISD::STORE, MVT::Other, Val.getValue(1),
683 Val, FIN, DAG.getSrcValue(NULL));
684 MemOps.push_back(Store);
685 // Increment the address by four for the next argument to store
686 SDOperand PtrOff = DAG.getConstant(4, getPointerTy());
687 FIN = DAG.getNode(ISD::ADD, MVT::i32, FIN, PtrOff);
688 }
Chris Lattner80720a92005-11-30 20:40:54 +0000689 if (!MemOps.empty()) {
690 MemOps.push_back(DAG.getRoot());
691 DAG.setRoot(DAG.getNode(ISD::TokenFactor, MVT::Other, MemOps));
692 }
Chris Lattner7c5a3d32005-08-16 17:14:42 +0000693 }
694
695 // Finally, inform the code generator which regs we return values in.
696 switch (getValueType(F.getReturnType())) {
697 default: assert(0 && "Unknown type!");
698 case MVT::isVoid: break;
699 case MVT::i1:
700 case MVT::i8:
701 case MVT::i16:
702 case MVT::i32:
703 MF.addLiveOut(PPC::R3);
704 break;
705 case MVT::i64:
706 MF.addLiveOut(PPC::R3);
707 MF.addLiveOut(PPC::R4);
708 break;
709 case MVT::f32:
710 case MVT::f64:
711 MF.addLiveOut(PPC::F1);
712 break;
713 }
714
715 return ArgValues;
716}
717
718std::pair<SDOperand, SDOperand>
Nate Begeman21e463b2005-10-16 05:39:50 +0000719PPCTargetLowering::LowerCallTo(SDOperand Chain,
720 const Type *RetTy, bool isVarArg,
721 unsigned CallingConv, bool isTailCall,
722 SDOperand Callee, ArgListTy &Args,
723 SelectionDAG &DAG) {
Chris Lattner281b55e2006-01-27 23:34:02 +0000724 // args_to_use will accumulate outgoing args for the PPCISD::CALL case in
Chris Lattner7c5a3d32005-08-16 17:14:42 +0000725 // SelectExpr to use to put the arguments in the appropriate registers.
726 std::vector<SDOperand> args_to_use;
727
728 // Count how many bytes are to be pushed on the stack, including the linkage
729 // area, and parameter passing area.
730 unsigned NumBytes = 24;
731
732 if (Args.empty()) {
Chris Lattner45b39762006-02-13 08:55:29 +0000733 Chain = DAG.getCALLSEQ_START(Chain,
734 DAG.getConstant(NumBytes, getPointerTy()));
Chris Lattner7c5a3d32005-08-16 17:14:42 +0000735 } else {
Chris Lattner915fb302005-08-30 00:19:00 +0000736 for (unsigned i = 0, e = Args.size(); i != e; ++i) {
Chris Lattner7c5a3d32005-08-16 17:14:42 +0000737 switch (getValueType(Args[i].second)) {
Chris Lattner915fb302005-08-30 00:19:00 +0000738 default: assert(0 && "Unknown value type!");
739 case MVT::i1:
740 case MVT::i8:
741 case MVT::i16:
742 case MVT::i32:
743 case MVT::f32:
744 NumBytes += 4;
745 break;
746 case MVT::i64:
747 case MVT::f64:
748 NumBytes += 8;
749 break;
Chris Lattner7c5a3d32005-08-16 17:14:42 +0000750 }
Chris Lattner915fb302005-08-30 00:19:00 +0000751 }
Chris Lattner7c5a3d32005-08-16 17:14:42 +0000752
Chris Lattner915fb302005-08-30 00:19:00 +0000753 // Just to be safe, we'll always reserve the full 24 bytes of linkage area
754 // plus 32 bytes of argument space in case any called code gets funky on us.
755 // (Required by ABI to support var arg)
756 if (NumBytes < 56) NumBytes = 56;
Chris Lattner7c5a3d32005-08-16 17:14:42 +0000757
758 // Adjust the stack pointer for the new arguments...
759 // These operations are automatically eliminated by the prolog/epilog pass
Chris Lattner45b39762006-02-13 08:55:29 +0000760 Chain = DAG.getCALLSEQ_START(Chain,
761 DAG.getConstant(NumBytes, getPointerTy()));
Chris Lattner7c5a3d32005-08-16 17:14:42 +0000762
763 // Set up a copy of the stack pointer for use loading and storing any
764 // arguments that may not fit in the registers available for argument
765 // passing.
Chris Lattnera243db82006-01-11 19:55:07 +0000766 SDOperand StackPtr = DAG.getRegister(PPC::R1, MVT::i32);
Chris Lattner7c5a3d32005-08-16 17:14:42 +0000767
768 // Figure out which arguments are going to go in registers, and which in
769 // memory. Also, if this is a vararg function, floating point operations
770 // must be stored to our stack, and loaded into integer regs as well, if
771 // any integer regs are available for argument passing.
772 unsigned ArgOffset = 24;
773 unsigned GPR_remaining = 8;
774 unsigned FPR_remaining = 13;
775
776 std::vector<SDOperand> MemOps;
777 for (unsigned i = 0, e = Args.size(); i != e; ++i) {
778 // PtrOff will be used to store the current argument to the stack if a
779 // register cannot be found for it.
780 SDOperand PtrOff = DAG.getConstant(ArgOffset, getPointerTy());
781 PtrOff = DAG.getNode(ISD::ADD, MVT::i32, StackPtr, PtrOff);
782 MVT::ValueType ArgVT = getValueType(Args[i].second);
783
784 switch (ArgVT) {
Chris Lattner915fb302005-08-30 00:19:00 +0000785 default: assert(0 && "Unexpected ValueType for argument!");
786 case MVT::i1:
787 case MVT::i8:
788 case MVT::i16:
789 // Promote the integer to 32 bits. If the input type is signed use a
790 // sign extend, otherwise use a zero extend.
791 if (Args[i].second->isSigned())
792 Args[i].first =DAG.getNode(ISD::SIGN_EXTEND, MVT::i32, Args[i].first);
793 else
794 Args[i].first =DAG.getNode(ISD::ZERO_EXTEND, MVT::i32, Args[i].first);
795 // FALL THROUGH
796 case MVT::i32:
797 if (GPR_remaining > 0) {
798 args_to_use.push_back(Args[i].first);
799 --GPR_remaining;
800 } else {
801 MemOps.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain,
802 Args[i].first, PtrOff,
803 DAG.getSrcValue(NULL)));
804 }
805 ArgOffset += 4;
806 break;
807 case MVT::i64:
808 // If we have one free GPR left, we can place the upper half of the i64
809 // in it, and store the other half to the stack. If we have two or more
810 // free GPRs, then we can pass both halves of the i64 in registers.
811 if (GPR_remaining > 0) {
812 SDOperand Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32,
813 Args[i].first, DAG.getConstant(1, MVT::i32));
814 SDOperand Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32,
815 Args[i].first, DAG.getConstant(0, MVT::i32));
816 args_to_use.push_back(Hi);
817 --GPR_remaining;
Chris Lattner7c5a3d32005-08-16 17:14:42 +0000818 if (GPR_remaining > 0) {
Chris Lattner915fb302005-08-30 00:19:00 +0000819 args_to_use.push_back(Lo);
Chris Lattner7c5a3d32005-08-16 17:14:42 +0000820 --GPR_remaining;
821 } else {
Chris Lattner915fb302005-08-30 00:19:00 +0000822 SDOperand ConstFour = DAG.getConstant(4, getPointerTy());
823 PtrOff = DAG.getNode(ISD::ADD, MVT::i32, PtrOff, ConstFour);
Chris Lattner7c5a3d32005-08-16 17:14:42 +0000824 MemOps.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain,
Chris Lattner915fb302005-08-30 00:19:00 +0000825 Lo, PtrOff, DAG.getSrcValue(NULL)));
Chris Lattner7c5a3d32005-08-16 17:14:42 +0000826 }
Chris Lattner915fb302005-08-30 00:19:00 +0000827 } else {
828 MemOps.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain,
829 Args[i].first, PtrOff,
830 DAG.getSrcValue(NULL)));
831 }
832 ArgOffset += 8;
833 break;
834 case MVT::f32:
835 case MVT::f64:
836 if (FPR_remaining > 0) {
837 args_to_use.push_back(Args[i].first);
838 --FPR_remaining;
839 if (isVarArg) {
840 SDOperand Store = DAG.getNode(ISD::STORE, MVT::Other, Chain,
841 Args[i].first, PtrOff,
842 DAG.getSrcValue(NULL));
843 MemOps.push_back(Store);
844 // Float varargs are always shadowed in available integer registers
Chris Lattner7c5a3d32005-08-16 17:14:42 +0000845 if (GPR_remaining > 0) {
Chris Lattner915fb302005-08-30 00:19:00 +0000846 SDOperand Load = DAG.getLoad(MVT::i32, Store, PtrOff,
847 DAG.getSrcValue(NULL));
Chris Lattner1df74782005-11-17 18:30:17 +0000848 MemOps.push_back(Load.getValue(1));
Chris Lattner915fb302005-08-30 00:19:00 +0000849 args_to_use.push_back(Load);
Chris Lattner7c5a3d32005-08-16 17:14:42 +0000850 --GPR_remaining;
Chris Lattner915fb302005-08-30 00:19:00 +0000851 }
852 if (GPR_remaining > 0 && MVT::f64 == ArgVT) {
Chris Lattner7c5a3d32005-08-16 17:14:42 +0000853 SDOperand ConstFour = DAG.getConstant(4, getPointerTy());
854 PtrOff = DAG.getNode(ISD::ADD, MVT::i32, PtrOff, ConstFour);
Chris Lattner915fb302005-08-30 00:19:00 +0000855 SDOperand Load = DAG.getLoad(MVT::i32, Store, PtrOff,
856 DAG.getSrcValue(NULL));
Chris Lattner1df74782005-11-17 18:30:17 +0000857 MemOps.push_back(Load.getValue(1));
Chris Lattner915fb302005-08-30 00:19:00 +0000858 args_to_use.push_back(Load);
859 --GPR_remaining;
Chris Lattner7c5a3d32005-08-16 17:14:42 +0000860 }
861 } else {
Chris Lattner915fb302005-08-30 00:19:00 +0000862 // If we have any FPRs remaining, we may also have GPRs remaining.
863 // Args passed in FPRs consume either 1 (f32) or 2 (f64) available
864 // GPRs.
865 if (GPR_remaining > 0) {
866 args_to_use.push_back(DAG.getNode(ISD::UNDEF, MVT::i32));
867 --GPR_remaining;
Chris Lattner7c5a3d32005-08-16 17:14:42 +0000868 }
Chris Lattner915fb302005-08-30 00:19:00 +0000869 if (GPR_remaining > 0 && MVT::f64 == ArgVT) {
870 args_to_use.push_back(DAG.getNode(ISD::UNDEF, MVT::i32));
871 --GPR_remaining;
872 }
Chris Lattner7c5a3d32005-08-16 17:14:42 +0000873 }
Chris Lattner915fb302005-08-30 00:19:00 +0000874 } else {
875 MemOps.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain,
876 Args[i].first, PtrOff,
877 DAG.getSrcValue(NULL)));
878 }
879 ArgOffset += (ArgVT == MVT::f32) ? 4 : 8;
880 break;
Chris Lattner7c5a3d32005-08-16 17:14:42 +0000881 }
882 }
883 if (!MemOps.empty())
884 Chain = DAG.getNode(ISD::TokenFactor, MVT::Other, MemOps);
885 }
886
887 std::vector<MVT::ValueType> RetVals;
888 MVT::ValueType RetTyVT = getValueType(RetTy);
Chris Lattnerf5059492005-09-02 01:24:55 +0000889 MVT::ValueType ActualRetTyVT = RetTyVT;
890 if (RetTyVT >= MVT::i1 && RetTyVT <= MVT::i16)
891 ActualRetTyVT = MVT::i32; // Promote result to i32.
892
Chris Lattnere00ebf02006-01-28 07:33:03 +0000893 if (RetTyVT == MVT::i64) {
894 RetVals.push_back(MVT::i32);
895 RetVals.push_back(MVT::i32);
896 } else if (RetTyVT != MVT::isVoid) {
Chris Lattnerf5059492005-09-02 01:24:55 +0000897 RetVals.push_back(ActualRetTyVT);
Chris Lattnere00ebf02006-01-28 07:33:03 +0000898 }
Chris Lattner7c5a3d32005-08-16 17:14:42 +0000899 RetVals.push_back(MVT::Other);
900
Chris Lattner2823b3e2005-11-17 05:56:14 +0000901 // If the callee is a GlobalAddress node (quite common, every direct call is)
902 // turn it into a TargetGlobalAddress node so that legalize doesn't hack it.
903 if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee))
904 Callee = DAG.getTargetGlobalAddress(G->getGlobal(), MVT::i32);
905
Chris Lattner281b55e2006-01-27 23:34:02 +0000906 std::vector<SDOperand> Ops;
907 Ops.push_back(Chain);
908 Ops.push_back(Callee);
909 Ops.insert(Ops.end(), args_to_use.begin(), args_to_use.end());
910 SDOperand TheCall = DAG.getNode(PPCISD::CALL, RetVals, Ops);
Chris Lattnere00ebf02006-01-28 07:33:03 +0000911 Chain = TheCall.getValue(TheCall.Val->getNumValues()-1);
Chris Lattner7c5a3d32005-08-16 17:14:42 +0000912 Chain = DAG.getNode(ISD::CALLSEQ_END, MVT::Other, Chain,
913 DAG.getConstant(NumBytes, getPointerTy()));
Chris Lattnerf5059492005-09-02 01:24:55 +0000914 SDOperand RetVal = TheCall;
915
916 // If the result is a small value, add a note so that we keep track of the
917 // information about whether it is sign or zero extended.
918 if (RetTyVT != ActualRetTyVT) {
919 RetVal = DAG.getNode(RetTy->isSigned() ? ISD::AssertSext : ISD::AssertZext,
920 MVT::i32, RetVal, DAG.getValueType(RetTyVT));
921 RetVal = DAG.getNode(ISD::TRUNCATE, RetTyVT, RetVal);
Chris Lattnere00ebf02006-01-28 07:33:03 +0000922 } else if (RetTyVT == MVT::i64) {
923 RetVal = DAG.getNode(ISD::BUILD_PAIR, MVT::i64, RetVal, RetVal.getValue(1));
Chris Lattnerf5059492005-09-02 01:24:55 +0000924 }
925
926 return std::make_pair(RetVal, Chain);
Chris Lattner7c5a3d32005-08-16 17:14:42 +0000927}
928
Chris Lattner8a2d3ca2005-08-26 21:23:58 +0000929MachineBasicBlock *
Nate Begeman21e463b2005-10-16 05:39:50 +0000930PPCTargetLowering::InsertAtEndOfBasicBlock(MachineInstr *MI,
931 MachineBasicBlock *BB) {
Chris Lattner8a2d3ca2005-08-26 21:23:58 +0000932 assert((MI->getOpcode() == PPC::SELECT_CC_Int ||
Chris Lattner919c0322005-10-01 01:35:02 +0000933 MI->getOpcode() == PPC::SELECT_CC_F4 ||
934 MI->getOpcode() == PPC::SELECT_CC_F8) &&
Chris Lattner8a2d3ca2005-08-26 21:23:58 +0000935 "Unexpected instr type to insert");
936
937 // To "insert" a SELECT_CC instruction, we actually have to insert the diamond
938 // control-flow pattern. The incoming instruction knows the destination vreg
939 // to set, the condition code register to branch on, the true/false values to
940 // select between, and a branch opcode to use.
941 const BasicBlock *LLVM_BB = BB->getBasicBlock();
942 ilist<MachineBasicBlock>::iterator It = BB;
943 ++It;
944
945 // thisMBB:
946 // ...
947 // TrueVal = ...
948 // cmpTY ccX, r1, r2
949 // bCC copy1MBB
950 // fallthrough --> copy0MBB
951 MachineBasicBlock *thisMBB = BB;
952 MachineBasicBlock *copy0MBB = new MachineBasicBlock(LLVM_BB);
953 MachineBasicBlock *sinkMBB = new MachineBasicBlock(LLVM_BB);
954 BuildMI(BB, MI->getOperand(4).getImmedValue(), 2)
955 .addReg(MI->getOperand(1).getReg()).addMBB(sinkMBB);
956 MachineFunction *F = BB->getParent();
957 F->getBasicBlockList().insert(It, copy0MBB);
958 F->getBasicBlockList().insert(It, sinkMBB);
959 // Update machine-CFG edges
960 BB->addSuccessor(copy0MBB);
961 BB->addSuccessor(sinkMBB);
962
963 // copy0MBB:
964 // %FalseValue = ...
965 // # fallthrough to sinkMBB
966 BB = copy0MBB;
967
968 // Update machine-CFG edges
969 BB->addSuccessor(sinkMBB);
970
971 // sinkMBB:
972 // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ]
973 // ...
974 BB = sinkMBB;
975 BuildMI(BB, PPC::PHI, 4, MI->getOperand(0).getReg())
976 .addReg(MI->getOperand(3).getReg()).addMBB(copy0MBB)
977 .addReg(MI->getOperand(2).getReg()).addMBB(thisMBB);
978
979 delete MI; // The pseudo instruction is gone now.
980 return BB;
981}
982
Chris Lattnerad3bc8d2006-02-07 20:16:30 +0000983/// getConstraintType - Given a constraint letter, return the type of
984/// constraint it is for this target.
985PPCTargetLowering::ConstraintType
986PPCTargetLowering::getConstraintType(char ConstraintLetter) const {
987 switch (ConstraintLetter) {
988 default: break;
989 case 'b':
990 case 'r':
991 case 'f':
992 case 'v':
993 case 'y':
994 return C_RegisterClass;
995 }
996 return TargetLowering::getConstraintType(ConstraintLetter);
997}
998
999
Chris Lattnerddc787d2006-01-31 19:20:21 +00001000std::vector<unsigned> PPCTargetLowering::
1001getRegForInlineAsmConstraint(const std::string &Constraint) const {
1002 if (Constraint.size() == 1) {
1003 switch (Constraint[0]) { // GCC RS6000 Constraint Letters
1004 default: break; // Unknown constriant letter
1005 case 'b':
1006 return make_vector<unsigned>(/*no R0*/ PPC::R1 , PPC::R2 , PPC::R3 ,
1007 PPC::R4 , PPC::R5 , PPC::R6 , PPC::R7 ,
1008 PPC::R8 , PPC::R9 , PPC::R10, PPC::R11,
1009 PPC::R12, PPC::R13, PPC::R14, PPC::R15,
1010 PPC::R16, PPC::R17, PPC::R18, PPC::R19,
1011 PPC::R20, PPC::R21, PPC::R22, PPC::R23,
1012 PPC::R24, PPC::R25, PPC::R26, PPC::R27,
1013 PPC::R28, PPC::R29, PPC::R30, PPC::R31,
1014 0);
1015 case 'r':
1016 return make_vector<unsigned>(PPC::R0 , PPC::R1 , PPC::R2 , PPC::R3 ,
1017 PPC::R4 , PPC::R5 , PPC::R6 , PPC::R7 ,
1018 PPC::R8 , PPC::R9 , PPC::R10, PPC::R11,
1019 PPC::R12, PPC::R13, PPC::R14, PPC::R15,
1020 PPC::R16, PPC::R17, PPC::R18, PPC::R19,
1021 PPC::R20, PPC::R21, PPC::R22, PPC::R23,
1022 PPC::R24, PPC::R25, PPC::R26, PPC::R27,
1023 PPC::R28, PPC::R29, PPC::R30, PPC::R31,
1024 0);
1025 case 'f':
1026 return make_vector<unsigned>(PPC::F0 , PPC::F1 , PPC::F2 , PPC::F3 ,
1027 PPC::F4 , PPC::F5 , PPC::F6 , PPC::F7 ,
1028 PPC::F8 , PPC::F9 , PPC::F10, PPC::F11,
1029 PPC::F12, PPC::F13, PPC::F14, PPC::F15,
1030 PPC::F16, PPC::F17, PPC::F18, PPC::F19,
1031 PPC::F20, PPC::F21, PPC::F22, PPC::F23,
1032 PPC::F24, PPC::F25, PPC::F26, PPC::F27,
1033 PPC::F28, PPC::F29, PPC::F30, PPC::F31,
1034 0);
1035 case 'v':
1036 return make_vector<unsigned>(PPC::V0 , PPC::V1 , PPC::V2 , PPC::V3 ,
1037 PPC::V4 , PPC::V5 , PPC::V6 , PPC::V7 ,
1038 PPC::V8 , PPC::V9 , PPC::V10, PPC::V11,
1039 PPC::V12, PPC::V13, PPC::V14, PPC::V15,
1040 PPC::V16, PPC::V17, PPC::V18, PPC::V19,
1041 PPC::V20, PPC::V21, PPC::V22, PPC::V23,
1042 PPC::V24, PPC::V25, PPC::V26, PPC::V27,
1043 PPC::V28, PPC::V29, PPC::V30, PPC::V31,
1044 0);
1045 case 'y':
1046 return make_vector<unsigned>(PPC::CR0, PPC::CR1, PPC::CR2, PPC::CR3,
1047 PPC::CR4, PPC::CR5, PPC::CR6, PPC::CR7,
1048 0);
1049 }
1050 }
1051
1052 // Handle explicit register names.
1053 return TargetLowering::getRegForInlineAsmConstraint(Constraint);
1054}
Chris Lattner763317d2006-02-07 00:47:13 +00001055
1056// isOperandValidForConstraint
1057bool PPCTargetLowering::
1058isOperandValidForConstraint(SDOperand Op, char Letter) {
1059 switch (Letter) {
1060 default: break;
1061 case 'I':
1062 case 'J':
1063 case 'K':
1064 case 'L':
1065 case 'M':
1066 case 'N':
1067 case 'O':
1068 case 'P': {
1069 if (!isa<ConstantSDNode>(Op)) return false; // Must be an immediate.
1070 unsigned Value = cast<ConstantSDNode>(Op)->getValue();
1071 switch (Letter) {
1072 default: assert(0 && "Unknown constraint letter!");
1073 case 'I': // "I" is a signed 16-bit constant.
1074 return (short)Value == (int)Value;
1075 case 'J': // "J" is a constant with only the high-order 16 bits nonzero.
1076 case 'L': // "L" is a signed 16-bit constant shifted left 16 bits.
1077 return (short)Value == 0;
1078 case 'K': // "K" is a constant with only the low-order 16 bits nonzero.
1079 return (Value >> 16) == 0;
1080 case 'M': // "M" is a constant that is greater than 31.
1081 return Value > 31;
1082 case 'N': // "N" is a positive constant that is an exact power of two.
1083 return (int)Value > 0 && isPowerOf2_32(Value);
1084 case 'O': // "O" is the constant zero.
1085 return Value == 0;
1086 case 'P': // "P" is a constant whose negation is a signed 16-bit constant.
1087 return (short)-Value == (int)-Value;
1088 }
1089 break;
1090 }
1091 }
1092
1093 // Handle standard constraint letters.
1094 return TargetLowering::isOperandValidForConstraint(Op, Letter);
1095}