blob: d6fd6edccf4534677859b58d82c0110ec383ba87 [file] [log] [blame]
Anton Korobeynikov4403b932009-07-16 13:27:25 +00001//===-- SystemZISelLowering.cpp - SystemZ DAG Lowering Implementation -----==//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the SystemZTargetLowering class.
11//
12//===----------------------------------------------------------------------===//
13
14#define DEBUG_TYPE "systemz-lower"
15
16#include "SystemZISelLowering.h"
17#include "SystemZ.h"
18#include "SystemZTargetMachine.h"
19#include "SystemZSubtarget.h"
20#include "llvm/DerivedTypes.h"
21#include "llvm/Function.h"
22#include "llvm/Intrinsics.h"
23#include "llvm/CallingConv.h"
24#include "llvm/GlobalVariable.h"
25#include "llvm/GlobalAlias.h"
26#include "llvm/CodeGen/CallingConvLower.h"
27#include "llvm/CodeGen/MachineFrameInfo.h"
28#include "llvm/CodeGen/MachineFunction.h"
29#include "llvm/CodeGen/MachineInstrBuilder.h"
30#include "llvm/CodeGen/MachineRegisterInfo.h"
31#include "llvm/CodeGen/PseudoSourceValue.h"
32#include "llvm/CodeGen/SelectionDAGISel.h"
33#include "llvm/CodeGen/ValueTypes.h"
34#include "llvm/Support/Debug.h"
Anton Korobeynikov2c97ae82009-07-16 14:19:02 +000035#include "llvm/Target/TargetOptions.h"
Anton Korobeynikov4403b932009-07-16 13:27:25 +000036#include "llvm/ADT/VectorExtras.h"
37using namespace llvm;
38
39SystemZTargetLowering::SystemZTargetLowering(SystemZTargetMachine &tm) :
40 TargetLowering(tm), Subtarget(*tm.getSubtargetImpl()), TM(tm) {
41
Anton Korobeynikov656ac6f2009-07-16 13:51:53 +000042 RegInfo = TM.getRegisterInfo();
43
Anton Korobeynikov4403b932009-07-16 13:27:25 +000044 // Set up the register classes.
Anton Korobeynikov8d1837d2009-07-16 13:56:42 +000045 addRegisterClass(MVT::i32, SystemZ::GR32RegisterClass);
46 addRegisterClass(MVT::i64, SystemZ::GR64RegisterClass);
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +000047 addRegisterClass(MVT::v2i32,SystemZ::GR64PRegisterClass);
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +000048 addRegisterClass(MVT::v2i64,SystemZ::GR128RegisterClass);
Anton Korobeynikov4403b932009-07-16 13:27:25 +000049
Anton Korobeynikov2c97ae82009-07-16 14:19:02 +000050 if (!UseSoftFloat) {
51 addRegisterClass(MVT::f32, SystemZ::FP32RegisterClass);
52 addRegisterClass(MVT::f64, SystemZ::FP64RegisterClass);
Anton Korobeynikov1ada84d2009-07-16 14:24:16 +000053
54 addLegalFPImmediate(APFloat(+0.0)); // lzer
55 addLegalFPImmediate(APFloat(+0.0f)); // lzdr
56 addLegalFPImmediate(APFloat(-0.0)); // lzer + lner
57 addLegalFPImmediate(APFloat(-0.0f)); // lzdr + lndr
Anton Korobeynikov2c97ae82009-07-16 14:19:02 +000058 }
59
Anton Korobeynikov4403b932009-07-16 13:27:25 +000060 // Compute derived properties from the register classes
61 computeRegisterProperties();
62
Anton Korobeynikov9e4816e2009-07-16 13:43:18 +000063 // Set shifts properties
64 setShiftAmountFlavor(Extend);
Anton Korobeynikov48e8b3c2009-07-16 14:15:24 +000065 setShiftAmountType(MVT::i64);
Anton Korobeynikov9e4816e2009-07-16 13:43:18 +000066
Anton Korobeynikov4403b932009-07-16 13:27:25 +000067 // Provide all sorts of operation actions
Anton Korobeynikovbf022172009-07-16 13:53:35 +000068 setLoadExtAction(ISD::SEXTLOAD, MVT::i1, Promote);
69 setLoadExtAction(ISD::ZEXTLOAD, MVT::i1, Promote);
70 setLoadExtAction(ISD::EXTLOAD, MVT::i1, Promote);
Anton Korobeynikov4403b932009-07-16 13:27:25 +000071
Anton Korobeynikov85c5c3f2009-07-16 14:22:46 +000072 setLoadExtAction(ISD::SEXTLOAD, MVT::f32, Expand);
73 setLoadExtAction(ISD::ZEXTLOAD, MVT::f32, Expand);
74 setLoadExtAction(ISD::EXTLOAD, MVT::f32, Expand);
Anton Korobeynikov299dc782009-07-16 14:22:30 +000075
Anton Korobeynikov85c5c3f2009-07-16 14:22:46 +000076 setLoadExtAction(ISD::SEXTLOAD, MVT::f64, Expand);
77 setLoadExtAction(ISD::ZEXTLOAD, MVT::f64, Expand);
78 setLoadExtAction(ISD::EXTLOAD, MVT::f64, Expand);
Anton Korobeynikov23eff5c2009-07-16 14:20:08 +000079
Anton Korobeynikove0167c12009-07-16 13:35:30 +000080 setStackPointerRegisterToSaveRestore(SystemZ::R15D);
Anton Korobeynikov4403b932009-07-16 13:27:25 +000081 setSchedulingPreference(SchedulingForLatency);
Anton Korobeynikov159ac632009-07-16 14:28:46 +000082 setBooleanContents(ZeroOrOneBooleanContent);
Anton Korobeynikov87a24e32009-07-16 13:28:59 +000083
84 setOperationAction(ISD::RET, MVT::Other, Custom);
Anton Korobeynikov4ec3e5f2009-07-16 13:52:31 +000085
Anton Korobeynikov983d3a12009-07-16 14:07:24 +000086 setOperationAction(ISD::BR_JT, MVT::Other, Expand);
Anton Korobeynikov4ec3e5f2009-07-16 13:52:31 +000087 setOperationAction(ISD::BRCOND, MVT::Other, Expand);
88 setOperationAction(ISD::BR_CC, MVT::i32, Custom);
89 setOperationAction(ISD::BR_CC, MVT::i64, Custom);
Anton Korobeynikovae535672009-07-16 14:19:35 +000090 setOperationAction(ISD::BR_CC, MVT::f32, Custom);
91 setOperationAction(ISD::BR_CC, MVT::f64, Custom);
92 setOperationAction(ISD::ConstantPool, MVT::i32, Custom);
93 setOperationAction(ISD::ConstantPool, MVT::i64, Custom);
Anton Korobeynikovbad769f2009-07-16 13:57:27 +000094 setOperationAction(ISD::GlobalAddress, MVT::i64, Custom);
Anton Korobeynikovc16cdc52009-07-16 14:07:50 +000095 setOperationAction(ISD::JumpTable, MVT::i64, Custom);
Anton Korobeynikovc772c442009-07-16 14:08:15 +000096 setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i64, Expand);
Anton Korobeynikov7d1e39b2009-07-16 13:52:51 +000097
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +000098 setOperationAction(ISD::SDIV, MVT::i32, Expand);
99 setOperationAction(ISD::UDIV, MVT::i32, Expand);
100 setOperationAction(ISD::SDIV, MVT::i64, Expand);
101 setOperationAction(ISD::UDIV, MVT::i64, Expand);
102 setOperationAction(ISD::SREM, MVT::i32, Expand);
103 setOperationAction(ISD::UREM, MVT::i32, Expand);
104 setOperationAction(ISD::SREM, MVT::i64, Expand);
105 setOperationAction(ISD::UREM, MVT::i64, Expand);
106
Anton Korobeynikove37a37d2009-07-18 12:20:36 +0000107 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand);
108
Anton Korobeynikov0cca0692009-07-18 12:26:13 +0000109 setOperationAction(ISD::CTPOP, MVT::i32, Expand);
110 setOperationAction(ISD::CTPOP, MVT::i64, Expand);
111 setOperationAction(ISD::CTTZ, MVT::i32, Expand);
112 setOperationAction(ISD::CTTZ, MVT::i64, Expand);
113 setOperationAction(ISD::CTLZ, MVT::i32, Promote);
114 setOperationAction(ISD::CTLZ, MVT::i64, Legal);
115
Anton Korobeynikov7d1e39b2009-07-16 13:52:51 +0000116 // FIXME: Can we lower these 2 efficiently?
117 setOperationAction(ISD::SETCC, MVT::i32, Expand);
118 setOperationAction(ISD::SETCC, MVT::i64, Expand);
Anton Korobeynikovda723d72009-07-16 14:22:15 +0000119 setOperationAction(ISD::SETCC, MVT::f32, Expand);
120 setOperationAction(ISD::SETCC, MVT::f64, Expand);
Anton Korobeynikov7d1e39b2009-07-16 13:52:51 +0000121 setOperationAction(ISD::SELECT, MVT::i32, Expand);
122 setOperationAction(ISD::SELECT, MVT::i64, Expand);
Anton Korobeynikovda723d72009-07-16 14:22:15 +0000123 setOperationAction(ISD::SELECT, MVT::f32, Expand);
124 setOperationAction(ISD::SELECT, MVT::f64, Expand);
Anton Korobeynikov7d1e39b2009-07-16 13:52:51 +0000125 setOperationAction(ISD::SELECT_CC, MVT::i32, Custom);
126 setOperationAction(ISD::SELECT_CC, MVT::i64, Custom);
Anton Korobeynikovae535672009-07-16 14:19:35 +0000127 setOperationAction(ISD::SELECT_CC, MVT::f32, Custom);
128 setOperationAction(ISD::SELECT_CC, MVT::f64, Custom);
Anton Korobeynikovdd0239b2009-07-16 13:53:55 +0000129
Anton Korobeynikov8d1837d2009-07-16 13:56:42 +0000130 // Funny enough: we don't have 64-bit signed versions of these stuff, but have
131 // unsigned.
Anton Korobeynikovdd0239b2009-07-16 13:53:55 +0000132 setOperationAction(ISD::MULHS, MVT::i64, Expand);
Anton Korobeynikovdd0239b2009-07-16 13:53:55 +0000133 setOperationAction(ISD::SMUL_LOHI, MVT::i64, Expand);
Anton Korobeynikov9b4ae572009-07-16 14:20:56 +0000134
Anton Korobeynikov20d062f2009-07-16 14:25:46 +0000135 // Lower some FP stuff
Anton Korobeynikov9b4ae572009-07-16 14:20:56 +0000136 setOperationAction(ISD::FSIN, MVT::f32, Expand);
137 setOperationAction(ISD::FSIN, MVT::f64, Expand);
138 setOperationAction(ISD::FCOS, MVT::f32, Expand);
139 setOperationAction(ISD::FCOS, MVT::f64, Expand);
Anton Korobeynikov98db78a2009-07-16 14:26:06 +0000140
Anton Korobeynikov05a0b8b2009-07-16 14:27:01 +0000141 // We have only 64-bit bitconverts
Anton Korobeynikovbb8a0482009-07-16 14:30:29 +0000142 setOperationAction(ISD::BIT_CONVERT, MVT::f32, Expand);
143 setOperationAction(ISD::BIT_CONVERT, MVT::i32, Expand);
Anton Korobeynikov05a0b8b2009-07-16 14:27:01 +0000144
Anton Korobeynikova89430e2009-07-16 14:25:30 +0000145 setOperationAction(ISD::UINT_TO_FP, MVT::i32, Expand);
146 setOperationAction(ISD::UINT_TO_FP, MVT::i64, Expand);
Anton Korobeynikov98db78a2009-07-16 14:26:06 +0000147 setOperationAction(ISD::FP_TO_UINT, MVT::i32, Expand);
148 setOperationAction(ISD::FP_TO_UINT, MVT::i64, Expand);
Anton Korobeynikov20d062f2009-07-16 14:25:46 +0000149
150 setTruncStoreAction(MVT::f64, MVT::f32, Expand);
Anton Korobeynikov4403b932009-07-16 13:27:25 +0000151}
152
153SDValue SystemZTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) {
154 switch (Op.getOpcode()) {
Anton Korobeynikov87a24e32009-07-16 13:28:59 +0000155 case ISD::FORMAL_ARGUMENTS: return LowerFORMAL_ARGUMENTS(Op, DAG);
156 case ISD::RET: return LowerRET(Op, DAG);
Anton Korobeynikovba249e42009-07-16 13:50:21 +0000157 case ISD::CALL: return LowerCALL(Op, DAG);
Anton Korobeynikov4ec3e5f2009-07-16 13:52:31 +0000158 case ISD::BR_CC: return LowerBR_CC(Op, DAG);
Anton Korobeynikov7d1e39b2009-07-16 13:52:51 +0000159 case ISD::SELECT_CC: return LowerSELECT_CC(Op, DAG);
Anton Korobeynikovbad769f2009-07-16 13:57:27 +0000160 case ISD::GlobalAddress: return LowerGlobalAddress(Op, DAG);
Anton Korobeynikovc16cdc52009-07-16 14:07:50 +0000161 case ISD::JumpTable: return LowerJumpTable(Op, DAG);
Anton Korobeynikovae535672009-07-16 14:19:35 +0000162 case ISD::ConstantPool: return LowerConstantPool(Op, DAG);
Anton Korobeynikov4403b932009-07-16 13:27:25 +0000163 default:
Anton Korobeynikov31e87442009-07-18 13:33:17 +0000164 llvm_unreachable("Should not custom lower this!");
Anton Korobeynikov4403b932009-07-16 13:27:25 +0000165 return SDValue();
166 }
167}
168
169//===----------------------------------------------------------------------===//
170// Calling Convention Implementation
171//===----------------------------------------------------------------------===//
172
173#include "SystemZGenCallingConv.inc"
174
Anton Korobeynikov87a24e32009-07-16 13:28:59 +0000175SDValue SystemZTargetLowering::LowerFORMAL_ARGUMENTS(SDValue Op,
176 SelectionDAG &DAG) {
177 unsigned CC = cast<ConstantSDNode>(Op.getOperand(1))->getZExtValue();
178 switch (CC) {
179 default:
Anton Korobeynikov31e87442009-07-18 13:33:17 +0000180 llvm_unreachable("Unsupported calling convention");
Anton Korobeynikov87a24e32009-07-16 13:28:59 +0000181 case CallingConv::C:
182 case CallingConv::Fast:
183 return LowerCCCArguments(Op, DAG);
184 }
185}
186
Anton Korobeynikovba249e42009-07-16 13:50:21 +0000187SDValue SystemZTargetLowering::LowerCALL(SDValue Op, SelectionDAG &DAG) {
188 CallSDNode *TheCall = cast<CallSDNode>(Op.getNode());
189 unsigned CallingConv = TheCall->getCallingConv();
190 switch (CallingConv) {
191 default:
Anton Korobeynikov31e87442009-07-18 13:33:17 +0000192 llvm_unreachable("Unsupported calling convention");
Anton Korobeynikovba249e42009-07-16 13:50:21 +0000193 case CallingConv::Fast:
194 case CallingConv::C:
195 return LowerCCCCallTo(Op, DAG, CallingConv);
196 }
197}
198
Anton Korobeynikov87a24e32009-07-16 13:28:59 +0000199/// LowerCCCArguments - transform physical registers into virtual registers and
200/// generate load operations for arguments places on the stack.
201// FIXME: struct return stuff
202// FIXME: varargs
203SDValue SystemZTargetLowering::LowerCCCArguments(SDValue Op,
204 SelectionDAG &DAG) {
205 MachineFunction &MF = DAG.getMachineFunction();
206 MachineFrameInfo *MFI = MF.getFrameInfo();
207 MachineRegisterInfo &RegInfo = MF.getRegInfo();
208 SDValue Root = Op.getOperand(0);
209 bool isVarArg = cast<ConstantSDNode>(Op.getOperand(2))->getZExtValue() != 0;
210 unsigned CC = MF.getFunction()->getCallingConv();
211 DebugLoc dl = Op.getDebugLoc();
212
213 // Assign locations to all of the incoming arguments.
214 SmallVector<CCValAssign, 16> ArgLocs;
Anton Korobeynikov7df84622009-07-16 14:36:52 +0000215 CCState CCInfo(CC, isVarArg, getTargetMachine(), ArgLocs, DAG.getContext());
Anton Korobeynikov87a24e32009-07-16 13:28:59 +0000216 CCInfo.AnalyzeFormalArguments(Op.getNode(), CC_SystemZ);
217
Anton Korobeynikov31e87442009-07-18 13:33:17 +0000218 if (isVarArg)
219 llvm_report_error("Varargs not supported yet");
Anton Korobeynikov87a24e32009-07-16 13:28:59 +0000220
221 SmallVector<SDValue, 16> ArgValues;
222 for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
Anton Korobeynikovc1a1e4a2009-07-16 14:29:05 +0000223 SDValue ArgValue;
Anton Korobeynikov87a24e32009-07-16 13:28:59 +0000224 CCValAssign &VA = ArgLocs[i];
Anton Korobeynikovc1a1e4a2009-07-16 14:29:05 +0000225 MVT LocVT = VA.getLocVT();
Anton Korobeynikov87a24e32009-07-16 13:28:59 +0000226 if (VA.isRegLoc()) {
227 // Arguments passed in registers
Anton Korobeynikov0e31d5c2009-07-16 14:19:16 +0000228 TargetRegisterClass *RC;
Anton Korobeynikovc1a1e4a2009-07-16 14:29:05 +0000229 switch (LocVT.getSimpleVT()) {
Anton Korobeynikov87a24e32009-07-16 13:28:59 +0000230 default:
Anton Korobeynikov6d94eff2009-07-18 13:34:59 +0000231#ifndef NDEBUG
Anton Korobeynikov87a24e32009-07-16 13:28:59 +0000232 cerr << "LowerFORMAL_ARGUMENTS Unhandled argument type: "
Anton Korobeynikovc1a1e4a2009-07-16 14:29:05 +0000233 << LocVT.getSimpleVT()
Anton Korobeynikov87a24e32009-07-16 13:28:59 +0000234 << "\n";
Anton Korobeynikov6d94eff2009-07-18 13:34:59 +0000235#endif
236 llvm_unreachable(0);
237 case MVT::i64:
Anton Korobeynikov0e31d5c2009-07-16 14:19:16 +0000238 RC = SystemZ::GR64RegisterClass;
239 break;
Anton Korobeynikov6d94eff2009-07-18 13:34:59 +0000240 case MVT::f32:
Anton Korobeynikov0e31d5c2009-07-16 14:19:16 +0000241 RC = SystemZ::FP32RegisterClass;
242 break;
Anton Korobeynikov6d94eff2009-07-18 13:34:59 +0000243 case MVT::f64:
Anton Korobeynikov0e31d5c2009-07-16 14:19:16 +0000244 RC = SystemZ::FP64RegisterClass;
245 break;
Anton Korobeynikov87a24e32009-07-16 13:28:59 +0000246 }
Anton Korobeynikov0e31d5c2009-07-16 14:19:16 +0000247
248 unsigned VReg = RegInfo.createVirtualRegister(RC);
249 RegInfo.addLiveIn(VA.getLocReg(), VReg);
Anton Korobeynikovc1a1e4a2009-07-16 14:29:05 +0000250 ArgValue = DAG.getCopyFromReg(Root, dl, VReg, LocVT);
Anton Korobeynikov87a24e32009-07-16 13:28:59 +0000251 } else {
252 // Sanity check
253 assert(VA.isMemLoc());
Anton Korobeynikov980d5502009-07-16 14:08:42 +0000254
255 // Create the nodes corresponding to a load from this parameter slot.
Anton Korobeynikov87a24e32009-07-16 13:28:59 +0000256 // Create the frame index object for this incoming parameter...
Anton Korobeynikovc1a1e4a2009-07-16 14:29:05 +0000257 int FI = MFI->CreateFixedObject(LocVT.getSizeInBits()/8,
Anton Korobeynikov980d5502009-07-16 14:08:42 +0000258 VA.getLocMemOffset());
Anton Korobeynikov87a24e32009-07-16 13:28:59 +0000259
260 // Create the SelectionDAG nodes corresponding to a load
Anton Korobeynikovc1a1e4a2009-07-16 14:29:05 +0000261 // from this parameter
Anton Korobeynikov980d5502009-07-16 14:08:42 +0000262 SDValue FIN = DAG.getFrameIndex(FI, getPointerTy());
Anton Korobeynikovc1a1e4a2009-07-16 14:29:05 +0000263 ArgValue = DAG.getLoad(LocVT, dl, Root, FIN,
264 PseudoSourceValue::getFixedStack(FI), 0);
Anton Korobeynikov87a24e32009-07-16 13:28:59 +0000265 }
Anton Korobeynikovc1a1e4a2009-07-16 14:29:05 +0000266
267 // If this is an 8/16/32-bit value, it is really passed promoted to 64
268 // bits. Insert an assert[sz]ext to capture this, then truncate to the
269 // right size.
270 if (VA.getLocInfo() == CCValAssign::SExt)
271 ArgValue = DAG.getNode(ISD::AssertSext, dl, LocVT, ArgValue,
272 DAG.getValueType(VA.getValVT()));
273 else if (VA.getLocInfo() == CCValAssign::ZExt)
274 ArgValue = DAG.getNode(ISD::AssertZext, dl, LocVT, ArgValue,
275 DAG.getValueType(VA.getValVT()));
276
277 if (VA.getLocInfo() != CCValAssign::Full)
278 ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue);
279
280 ArgValues.push_back(ArgValue);
Anton Korobeynikov87a24e32009-07-16 13:28:59 +0000281 }
282
283 ArgValues.push_back(Root);
284
285 // Return the new list of results.
286 return DAG.getNode(ISD::MERGE_VALUES, dl, Op.getNode()->getVTList(),
287 &ArgValues[0], ArgValues.size()).getValue(Op.getResNo());
288}
289
Anton Korobeynikovba249e42009-07-16 13:50:21 +0000290/// LowerCCCCallTo - functions arguments are copied from virtual regs to
291/// (physical regs)/(stack frame), CALLSEQ_START and CALLSEQ_END are emitted.
292/// TODO: sret.
293SDValue SystemZTargetLowering::LowerCCCCallTo(SDValue Op, SelectionDAG &DAG,
294 unsigned CC) {
295 CallSDNode *TheCall = cast<CallSDNode>(Op.getNode());
296 SDValue Chain = TheCall->getChain();
297 SDValue Callee = TheCall->getCallee();
298 bool isVarArg = TheCall->isVarArg();
299 DebugLoc dl = Op.getDebugLoc();
Anton Korobeynikov656ac6f2009-07-16 13:51:53 +0000300 MachineFunction &MF = DAG.getMachineFunction();
Anton Korobeynikovba249e42009-07-16 13:50:21 +0000301
Anton Korobeynikovc7b71be2009-07-16 13:52:10 +0000302 // Offset to first argument stack slot.
303 const unsigned FirstArgOffset = 160;
304
Anton Korobeynikovba249e42009-07-16 13:50:21 +0000305 // Analyze operands of the call, assigning locations to each operand.
306 SmallVector<CCValAssign, 16> ArgLocs;
Anton Korobeynikov7df84622009-07-16 14:36:52 +0000307 CCState CCInfo(CC, isVarArg, getTargetMachine(), ArgLocs, DAG.getContext());
Anton Korobeynikovba249e42009-07-16 13:50:21 +0000308
309 CCInfo.AnalyzeCallOperands(TheCall, CC_SystemZ);
310
311 // Get a count of how many bytes are to be pushed on the stack.
312 unsigned NumBytes = CCInfo.getNextStackOffset();
313
314 Chain = DAG.getCALLSEQ_START(Chain ,DAG.getConstant(NumBytes,
315 getPointerTy(), true));
316
317 SmallVector<std::pair<unsigned, SDValue>, 4> RegsToPass;
318 SmallVector<SDValue, 12> MemOpChains;
319 SDValue StackPtr;
320
321 // Walk the register/memloc assignments, inserting copies/loads.
322 for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
323 CCValAssign &VA = ArgLocs[i];
324
325 // Arguments start after the 5 first operands of ISD::CALL
326 SDValue Arg = TheCall->getArg(i);
327
328 // Promote the value if needed.
329 switch (VA.getLocInfo()) {
330 default: assert(0 && "Unknown loc info!");
331 case CCValAssign::Full: break;
332 case CCValAssign::SExt:
333 Arg = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Arg);
334 break;
335 case CCValAssign::ZExt:
336 Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Arg);
337 break;
338 case CCValAssign::AExt:
339 Arg = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), Arg);
340 break;
341 }
342
343 // Arguments that can be passed on register must be kept at RegsToPass
344 // vector
345 if (VA.isRegLoc()) {
346 RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg));
347 } else {
348 assert(VA.isMemLoc());
349
350 if (StackPtr.getNode() == 0)
Anton Korobeynikov656ac6f2009-07-16 13:51:53 +0000351 StackPtr =
352 DAG.getCopyFromReg(Chain, dl,
353 (RegInfo->hasFP(MF) ?
354 SystemZ::R11D : SystemZ::R15D),
355 getPointerTy());
Anton Korobeynikovba249e42009-07-16 13:50:21 +0000356
Anton Korobeynikovc7b71be2009-07-16 13:52:10 +0000357 unsigned Offset = FirstArgOffset + VA.getLocMemOffset();
358 SDValue PtrOff = DAG.getNode(ISD::ADD, dl, getPointerTy(),
359 StackPtr,
360 DAG.getIntPtrConstant(Offset));
Anton Korobeynikovba249e42009-07-16 13:50:21 +0000361
362 MemOpChains.push_back(DAG.getStore(Chain, dl, Arg, PtrOff,
Anton Korobeynikovc7b71be2009-07-16 13:52:10 +0000363 PseudoSourceValue::getStack(), Offset));
Anton Korobeynikovba249e42009-07-16 13:50:21 +0000364 }
365 }
366
367 // Transform all store nodes into one single node because all store nodes are
368 // independent of each other.
369 if (!MemOpChains.empty())
370 Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other,
371 &MemOpChains[0], MemOpChains.size());
372
373 // Build a sequence of copy-to-reg nodes chained together with token chain and
374 // flag operands which copy the outgoing args into registers. The InFlag in
375 // necessary since all emited instructions must be stuck together.
376 SDValue InFlag;
377 for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) {
378 Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first,
379 RegsToPass[i].second, InFlag);
380 InFlag = Chain.getValue(1);
381 }
382
383 // If the callee is a GlobalAddress node (quite common, every direct call is)
384 // turn it into a TargetGlobalAddress node so that legalize doesn't hack it.
385 // Likewise ExternalSymbol -> TargetExternalSymbol.
386 if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee))
387 Callee = DAG.getTargetGlobalAddress(G->getGlobal(), getPointerTy());
388 else if (ExternalSymbolSDNode *E = dyn_cast<ExternalSymbolSDNode>(Callee))
389 Callee = DAG.getTargetExternalSymbol(E->getSymbol(), getPointerTy());
390
391 // Returns a chain & a flag for retval copy to use.
392 SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Flag);
393 SmallVector<SDValue, 8> Ops;
394 Ops.push_back(Chain);
395 Ops.push_back(Callee);
396
397 // Add argument registers to the end of the list so that they are
398 // known live into the call.
399 for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i)
400 Ops.push_back(DAG.getRegister(RegsToPass[i].first,
401 RegsToPass[i].second.getValueType()));
402
403 if (InFlag.getNode())
404 Ops.push_back(InFlag);
405
406 Chain = DAG.getNode(SystemZISD::CALL, dl, NodeTys, &Ops[0], Ops.size());
407 InFlag = Chain.getValue(1);
408
409 // Create the CALLSEQ_END node.
410 Chain = DAG.getCALLSEQ_END(Chain,
411 DAG.getConstant(NumBytes, getPointerTy(), true),
412 DAG.getConstant(0, getPointerTy(), true),
413 InFlag);
414 InFlag = Chain.getValue(1);
415
416 // Handle result values, copying them out of physregs into vregs that we
417 // return.
418 return SDValue(LowerCallResult(Chain, InFlag, TheCall, CC, DAG),
419 Op.getResNo());
420}
421
422/// LowerCallResult - Lower the result values of an ISD::CALL into the
423/// appropriate copies out of appropriate physical registers. This assumes that
424/// Chain/InFlag are the input chain/flag to use, and that TheCall is the call
425/// being lowered. Returns a SDNode with the same number of values as the
426/// ISD::CALL.
427SDNode*
428SystemZTargetLowering::LowerCallResult(SDValue Chain, SDValue InFlag,
429 CallSDNode *TheCall,
430 unsigned CallingConv,
431 SelectionDAG &DAG) {
432 bool isVarArg = TheCall->isVarArg();
433 DebugLoc dl = TheCall->getDebugLoc();
434
435 // Assign locations to each value returned by this call.
436 SmallVector<CCValAssign, 16> RVLocs;
Anton Korobeynikov7df84622009-07-16 14:36:52 +0000437 CCState CCInfo(CallingConv, isVarArg, getTargetMachine(), RVLocs,
438 DAG.getContext());
Anton Korobeynikovba249e42009-07-16 13:50:21 +0000439
440 CCInfo.AnalyzeCallResult(TheCall, RetCC_SystemZ);
441 SmallVector<SDValue, 8> ResultVals;
442
443 // Copy all of the result registers out of their specified physreg.
444 for (unsigned i = 0; i != RVLocs.size(); ++i) {
Anton Korobeynikov22836d12009-07-16 13:58:24 +0000445 CCValAssign &VA = RVLocs[i];
446
447 Chain = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(),
448 VA.getLocVT(), InFlag).getValue(1);
449 SDValue RetValue = Chain.getValue(0);
Anton Korobeynikovba249e42009-07-16 13:50:21 +0000450 InFlag = Chain.getValue(2);
Anton Korobeynikov22836d12009-07-16 13:58:24 +0000451
452 // If this is an 8/16/32-bit value, it is really passed promoted to 64
453 // bits. Insert an assert[sz]ext to capture this, then truncate to the
454 // right size.
455 if (VA.getLocInfo() == CCValAssign::SExt)
456 RetValue = DAG.getNode(ISD::AssertSext, dl, VA.getLocVT(), RetValue,
457 DAG.getValueType(VA.getValVT()));
458 else if (VA.getLocInfo() == CCValAssign::ZExt)
459 RetValue = DAG.getNode(ISD::AssertZext, dl, VA.getLocVT(), RetValue,
460 DAG.getValueType(VA.getValVT()));
461
462 if (VA.getLocInfo() != CCValAssign::Full)
463 RetValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), RetValue);
464
465 ResultVals.push_back(RetValue);
Anton Korobeynikovba249e42009-07-16 13:50:21 +0000466 }
467
468 ResultVals.push_back(Chain);
469
470 // Merge everything together with a MERGE_VALUES node.
471 return DAG.getNode(ISD::MERGE_VALUES, dl, TheCall->getVTList(),
472 &ResultVals[0], ResultVals.size()).getNode();
473}
474
475
Anton Korobeynikov87a24e32009-07-16 13:28:59 +0000476SDValue SystemZTargetLowering::LowerRET(SDValue Op, SelectionDAG &DAG) {
477 // CCValAssign - represent the assignment of the return value to a location
478 SmallVector<CCValAssign, 16> RVLocs;
479 unsigned CC = DAG.getMachineFunction().getFunction()->getCallingConv();
480 bool isVarArg = DAG.getMachineFunction().getFunction()->isVarArg();
481 DebugLoc dl = Op.getDebugLoc();
482
483 // CCState - Info about the registers and stack slot.
Anton Korobeynikov7df84622009-07-16 14:36:52 +0000484 CCState CCInfo(CC, isVarArg, getTargetMachine(), RVLocs, DAG.getContext());
Anton Korobeynikov87a24e32009-07-16 13:28:59 +0000485
486 // Analize return values of ISD::RET
487 CCInfo.AnalyzeReturn(Op.getNode(), RetCC_SystemZ);
488
489 // If this is the first return lowered for this function, add the regs to the
490 // liveout set for the function.
491 if (DAG.getMachineFunction().getRegInfo().liveout_empty()) {
492 for (unsigned i = 0; i != RVLocs.size(); ++i)
493 if (RVLocs[i].isRegLoc())
494 DAG.getMachineFunction().getRegInfo().addLiveOut(RVLocs[i].getLocReg());
495 }
496
497 // The chain is always operand #0
498 SDValue Chain = Op.getOperand(0);
499 SDValue Flag;
500
501 // Copy the result values into the output registers.
502 for (unsigned i = 0; i != RVLocs.size(); ++i) {
503 CCValAssign &VA = RVLocs[i];
Anton Korobeynikova51752c2009-07-16 13:42:31 +0000504 SDValue ResValue = Op.getOperand(i*2+1);
Anton Korobeynikov87a24e32009-07-16 13:28:59 +0000505 assert(VA.isRegLoc() && "Can only return in registers!");
506
Anton Korobeynikova51752c2009-07-16 13:42:31 +0000507 // If this is an 8/16/32-bit value, it is really should be passed promoted
508 // to 64 bits.
509 if (VA.getLocInfo() == CCValAssign::SExt)
510 ResValue = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), ResValue);
511 else if (VA.getLocInfo() == CCValAssign::ZExt)
512 ResValue = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), ResValue);
513 else if (VA.getLocInfo() == CCValAssign::AExt)
514 ResValue = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), ResValue);
515
Anton Korobeynikov87a24e32009-07-16 13:28:59 +0000516 // ISD::RET => ret chain, (regnum1,val1), ...
517 // So i*2+1 index only the regnums
Anton Korobeynikova51752c2009-07-16 13:42:31 +0000518 Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), ResValue, Flag);
Anton Korobeynikov87a24e32009-07-16 13:28:59 +0000519
520 // Guarantee that all emitted copies are stuck together,
521 // avoiding something bad.
522 Flag = Chain.getValue(1);
523 }
524
525 if (Flag.getNode())
526 return DAG.getNode(SystemZISD::RET_FLAG, dl, MVT::Other, Chain, Flag);
527
528 // Return Void
529 return DAG.getNode(SystemZISD::RET_FLAG, dl, MVT::Other, Chain);
530}
531
Anton Korobeynikov4ec3e5f2009-07-16 13:52:31 +0000532SDValue SystemZTargetLowering::EmitCmp(SDValue LHS, SDValue RHS,
533 ISD::CondCode CC, SDValue &SystemZCC,
534 SelectionDAG &DAG) {
Anton Korobeynikov4ec3e5f2009-07-16 13:52:31 +0000535 // FIXME: Emit a test if RHS is zero
536
537 bool isUnsigned = false;
538 SystemZCC::CondCodes TCC;
539 switch (CC) {
Anton Korobeynikov31e87442009-07-18 13:33:17 +0000540 default:
541 llvm_unreachable("Invalid integer condition!");
Anton Korobeynikov4ec3e5f2009-07-16 13:52:31 +0000542 case ISD::SETEQ:
Anton Korobeynikov10c086c2009-07-16 14:19:54 +0000543 case ISD::SETOEQ:
Anton Korobeynikov4ec3e5f2009-07-16 13:52:31 +0000544 TCC = SystemZCC::E;
545 break;
Anton Korobeynikov10c086c2009-07-16 14:19:54 +0000546 case ISD::SETUEQ:
547 TCC = SystemZCC::NLH;
548 break;
Anton Korobeynikov4ec3e5f2009-07-16 13:52:31 +0000549 case ISD::SETNE:
Anton Korobeynikov10c086c2009-07-16 14:19:54 +0000550 case ISD::SETONE:
Anton Korobeynikov4ec3e5f2009-07-16 13:52:31 +0000551 TCC = SystemZCC::NE;
552 break;
Anton Korobeynikov10c086c2009-07-16 14:19:54 +0000553 case ISD::SETUNE:
554 TCC = SystemZCC::LH;
555 break;
556 case ISD::SETO:
557 TCC = SystemZCC::O;
558 break;
559 case ISD::SETUO:
560 TCC = SystemZCC::NO;
561 break;
Anton Korobeynikov4ec3e5f2009-07-16 13:52:31 +0000562 case ISD::SETULE:
Anton Korobeynikov10c086c2009-07-16 14:19:54 +0000563 if (LHS.getValueType().isFloatingPoint()) {
564 TCC = SystemZCC::NH;
565 break;
566 }
Anton Korobeynikov4ec3e5f2009-07-16 13:52:31 +0000567 isUnsigned = true; // FALLTHROUGH
568 case ISD::SETLE:
Anton Korobeynikov10c086c2009-07-16 14:19:54 +0000569 case ISD::SETOLE:
Anton Korobeynikov4ec3e5f2009-07-16 13:52:31 +0000570 TCC = SystemZCC::LE;
571 break;
572 case ISD::SETUGE:
Anton Korobeynikov10c086c2009-07-16 14:19:54 +0000573 if (LHS.getValueType().isFloatingPoint()) {
574 TCC = SystemZCC::NL;
575 break;
576 }
Anton Korobeynikov4ec3e5f2009-07-16 13:52:31 +0000577 isUnsigned = true; // FALLTHROUGH
578 case ISD::SETGE:
Anton Korobeynikov10c086c2009-07-16 14:19:54 +0000579 case ISD::SETOGE:
Anton Korobeynikov4ec3e5f2009-07-16 13:52:31 +0000580 TCC = SystemZCC::HE;
581 break;
582 case ISD::SETUGT:
Anton Korobeynikov10c086c2009-07-16 14:19:54 +0000583 if (LHS.getValueType().isFloatingPoint()) {
584 TCC = SystemZCC::NLE;
585 break;
586 }
587 isUnsigned = true; // FALLTHROUGH
Anton Korobeynikov4ec3e5f2009-07-16 13:52:31 +0000588 case ISD::SETGT:
Anton Korobeynikov10c086c2009-07-16 14:19:54 +0000589 case ISD::SETOGT:
590 TCC = SystemZCC::H;
Anton Korobeynikov4ec3e5f2009-07-16 13:52:31 +0000591 break;
592 case ISD::SETULT:
Anton Korobeynikov10c086c2009-07-16 14:19:54 +0000593 if (LHS.getValueType().isFloatingPoint()) {
594 TCC = SystemZCC::NHE;
595 break;
596 }
597 isUnsigned = true; // FALLTHROUGH
598 case ISD::SETLT:
599 case ISD::SETOLT:
Anton Korobeynikov4ec3e5f2009-07-16 13:52:31 +0000600 TCC = SystemZCC::L;
601 break;
602 }
603
604 SystemZCC = DAG.getConstant(TCC, MVT::i32);
605
606 DebugLoc dl = LHS.getDebugLoc();
607 return DAG.getNode((isUnsigned ? SystemZISD::UCMP : SystemZISD::CMP),
608 dl, MVT::Flag, LHS, RHS);
609}
610
611
612SDValue SystemZTargetLowering::LowerBR_CC(SDValue Op, SelectionDAG &DAG) {
613 SDValue Chain = Op.getOperand(0);
614 ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(1))->get();
615 SDValue LHS = Op.getOperand(2);
616 SDValue RHS = Op.getOperand(3);
617 SDValue Dest = Op.getOperand(4);
618 DebugLoc dl = Op.getDebugLoc();
619
620 SDValue SystemZCC;
621 SDValue Flag = EmitCmp(LHS, RHS, CC, SystemZCC, DAG);
622 return DAG.getNode(SystemZISD::BRCOND, dl, Op.getValueType(),
623 Chain, Dest, SystemZCC, Flag);
624}
625
Anton Korobeynikov7d1e39b2009-07-16 13:52:51 +0000626SDValue SystemZTargetLowering::LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) {
627 SDValue LHS = Op.getOperand(0);
628 SDValue RHS = Op.getOperand(1);
629 SDValue TrueV = Op.getOperand(2);
630 SDValue FalseV = Op.getOperand(3);
631 ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(4))->get();
632 DebugLoc dl = Op.getDebugLoc();
633
634 SDValue SystemZCC;
635 SDValue Flag = EmitCmp(LHS, RHS, CC, SystemZCC, DAG);
636
637 SDVTList VTs = DAG.getVTList(Op.getValueType(), MVT::Flag);
638 SmallVector<SDValue, 4> Ops;
639 Ops.push_back(TrueV);
640 Ops.push_back(FalseV);
641 Ops.push_back(SystemZCC);
642 Ops.push_back(Flag);
643
644 return DAG.getNode(SystemZISD::SELECT, dl, VTs, &Ops[0], Ops.size());
645}
646
Anton Korobeynikovbad769f2009-07-16 13:57:27 +0000647SDValue SystemZTargetLowering::LowerGlobalAddress(SDValue Op,
648 SelectionDAG &DAG) {
649 DebugLoc dl = Op.getDebugLoc();
650 GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal();
Anton Korobeynikov6fe326c2009-07-16 14:16:05 +0000651 int64_t Offset = cast<GlobalAddressSDNode>(Op)->getOffset();
Anton Korobeynikovbad769f2009-07-16 13:57:27 +0000652
Anton Korobeynikov6fe326c2009-07-16 14:16:05 +0000653 bool IsPic = getTargetMachine().getRelocationModel() == Reloc::PIC_;
654 bool ExtraLoadRequired =
655 Subtarget.GVRequiresExtraLoad(GV, getTargetMachine(), false);
656
657 SDValue Result;
658 if (!IsPic && !ExtraLoadRequired) {
659 Result = DAG.getTargetGlobalAddress(GV, getPointerTy(), Offset);
660 Offset = 0;
661 } else {
662 unsigned char OpFlags = 0;
663 if (ExtraLoadRequired)
664 OpFlags = SystemZII::MO_GOTENT;
665
666 Result = DAG.getTargetGlobalAddress(GV, getPointerTy(), 0, OpFlags);
667 }
668
669 Result = DAG.getNode(SystemZISD::PCRelativeWrapper, dl,
670 getPointerTy(), Result);
671
672 if (ExtraLoadRequired)
673 Result = DAG.getLoad(getPointerTy(), dl, DAG.getEntryNode(), Result,
674 PseudoSourceValue::getGOT(), 0);
675
676 // If there was a non-zero offset that we didn't fold, create an explicit
677 // addition for it.
678 if (Offset != 0)
679 Result = DAG.getNode(ISD::ADD, dl, getPointerTy(), Result,
680 DAG.getConstant(Offset, getPointerTy()));
681
682 return Result;
Anton Korobeynikovbad769f2009-07-16 13:57:27 +0000683}
684
Anton Korobeynikovae535672009-07-16 14:19:35 +0000685// FIXME: PIC here
Anton Korobeynikovc16cdc52009-07-16 14:07:50 +0000686SDValue SystemZTargetLowering::LowerJumpTable(SDValue Op,
687 SelectionDAG &DAG) {
688 DebugLoc dl = Op.getDebugLoc();
689 JumpTableSDNode *JT = cast<JumpTableSDNode>(Op);
690 SDValue Result = DAG.getTargetJumpTable(JT->getIndex(), getPointerTy());
691
692 return DAG.getNode(SystemZISD::PCRelativeWrapper, dl, getPointerTy(), Result);
693}
694
Anton Korobeynikovae535672009-07-16 14:19:35 +0000695
696// FIXME: PIC here
697// FIXME: This is just dirty hack. We need to lower cpool properly
698SDValue SystemZTargetLowering::LowerConstantPool(SDValue Op,
699 SelectionDAG &DAG) {
700 DebugLoc dl = Op.getDebugLoc();
701 ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op);
702
703 SDValue Result = DAG.getTargetConstantPool(CP->getConstVal(), getPointerTy(),
704 CP->getAlignment(),
705 CP->getOffset());
706
707 return DAG.getNode(SystemZISD::PCRelativeWrapper, dl, getPointerTy(), Result);
708}
709
Anton Korobeynikov4403b932009-07-16 13:27:25 +0000710const char *SystemZTargetLowering::getTargetNodeName(unsigned Opcode) const {
711 switch (Opcode) {
Anton Korobeynikov87a24e32009-07-16 13:28:59 +0000712 case SystemZISD::RET_FLAG: return "SystemZISD::RET_FLAG";
Anton Korobeynikovba249e42009-07-16 13:50:21 +0000713 case SystemZISD::CALL: return "SystemZISD::CALL";
Anton Korobeynikov4ec3e5f2009-07-16 13:52:31 +0000714 case SystemZISD::BRCOND: return "SystemZISD::BRCOND";
715 case SystemZISD::CMP: return "SystemZISD::CMP";
716 case SystemZISD::UCMP: return "SystemZISD::UCMP";
Anton Korobeynikov7d1e39b2009-07-16 13:52:51 +0000717 case SystemZISD::SELECT: return "SystemZISD::SELECT";
Anton Korobeynikovbad769f2009-07-16 13:57:27 +0000718 case SystemZISD::PCRelativeWrapper: return "SystemZISD::PCRelativeWrapper";
Anton Korobeynikov4403b932009-07-16 13:27:25 +0000719 default: return NULL;
720 }
721}
722
Anton Korobeynikov7d1e39b2009-07-16 13:52:51 +0000723//===----------------------------------------------------------------------===//
724// Other Lowering Code
725//===----------------------------------------------------------------------===//
726
727MachineBasicBlock*
728SystemZTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
729 MachineBasicBlock *BB) const {
730 const SystemZInstrInfo &TII = *TM.getInstrInfo();
731 DebugLoc dl = MI->getDebugLoc();
Anton Korobeynikovda723d72009-07-16 14:22:15 +0000732 assert((MI->getOpcode() == SystemZ::Select32 ||
733 MI->getOpcode() == SystemZ::SelectF32 ||
734 MI->getOpcode() == SystemZ::Select64 ||
735 MI->getOpcode() == SystemZ::SelectF64) &&
Anton Korobeynikov7d1e39b2009-07-16 13:52:51 +0000736 "Unexpected instr type to insert");
737
738 // To "insert" a SELECT instruction, we actually have to insert the diamond
739 // control-flow pattern. The incoming instruction knows the destination vreg
740 // to set, the condition code register to branch on, the true/false values to
741 // select between, and a branch opcode to use.
742 const BasicBlock *LLVM_BB = BB->getBasicBlock();
743 MachineFunction::iterator I = BB;
744 ++I;
745
746 // thisMBB:
747 // ...
748 // TrueVal = ...
749 // cmpTY ccX, r1, r2
750 // jCC copy1MBB
751 // fallthrough --> copy0MBB
752 MachineBasicBlock *thisMBB = BB;
753 MachineFunction *F = BB->getParent();
754 MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB);
755 MachineBasicBlock *copy1MBB = F->CreateMachineBasicBlock(LLVM_BB);
756 SystemZCC::CondCodes CC = (SystemZCC::CondCodes)MI->getOperand(3).getImm();
757 BuildMI(BB, dl, TII.getBrCond(CC)).addMBB(copy1MBB);
758 F->insert(I, copy0MBB);
759 F->insert(I, copy1MBB);
760 // Update machine-CFG edges by transferring all successors of the current
761 // block to the new block which will contain the Phi node for the select.
762 copy1MBB->transferSuccessors(BB);
763 // Next, add the true and fallthrough blocks as its successors.
764 BB->addSuccessor(copy0MBB);
765 BB->addSuccessor(copy1MBB);
766
767 // copy0MBB:
768 // %FalseValue = ...
769 // # fallthrough to copy1MBB
770 BB = copy0MBB;
771
772 // Update machine-CFG edges
773 BB->addSuccessor(copy1MBB);
774
775 // copy1MBB:
776 // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ]
777 // ...
778 BB = copy1MBB;
779 BuildMI(BB, dl, TII.get(SystemZ::PHI),
780 MI->getOperand(0).getReg())
781 .addReg(MI->getOperand(2).getReg()).addMBB(copy0MBB)
782 .addReg(MI->getOperand(1).getReg()).addMBB(thisMBB);
783
784 F->DeleteMachineInstr(MI); // The pseudo instruction is gone now.
785 return BB;
786}