blob: ce74c58d2e65f27a2bb123d992af827a9a029e2c [file] [log] [blame]
Nate Begemana3829d52005-04-05 17:32:30 +00001//===-- PPC64ISelPattern.cpp - A pattern matching inst selector for PPC64 -===//
Nate Begemand3e6b942005-04-05 08:51:15 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Nate Begeman and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
Misha Brukmanb5f662f2005-04-21 23:30:14 +00007//
Nate Begemand3e6b942005-04-05 08:51:15 +00008//===----------------------------------------------------------------------===//
9//
Nate Begemana3829d52005-04-05 17:32:30 +000010// This file defines a pattern matching instruction selector for 64 bit PowerPC.
Nate Begemand3e6b942005-04-05 08:51:15 +000011//
12//===----------------------------------------------------------------------===//
13
14#include "PowerPC.h"
15#include "PowerPCInstrBuilder.h"
16#include "PowerPCInstrInfo.h"
17#include "PPC64RegisterInfo.h"
18#include "llvm/Constants.h" // FIXME: REMOVE
19#include "llvm/Function.h"
20#include "llvm/CodeGen/MachineConstantPool.h" // FIXME: REMOVE
21#include "llvm/CodeGen/MachineFunction.h"
22#include "llvm/CodeGen/MachineFrameInfo.h"
23#include "llvm/CodeGen/SelectionDAG.h"
24#include "llvm/CodeGen/SelectionDAGISel.h"
25#include "llvm/CodeGen/SSARegMap.h"
26#include "llvm/Target/TargetData.h"
27#include "llvm/Target/TargetLowering.h"
28#include "llvm/Target/TargetOptions.h"
29#include "llvm/Support/Debug.h"
30#include "llvm/Support/MathExtras.h"
31#include "llvm/ADT/Statistic.h"
32#include <set>
33#include <algorithm>
34using namespace llvm;
35
36//===----------------------------------------------------------------------===//
37// PPC32TargetLowering - PPC32 Implementation of the TargetLowering interface
38namespace {
39 class PPC64TargetLowering : public TargetLowering {
40 int VarArgsFrameIndex; // FrameIndex for start of varargs area.
41 int ReturnAddrIndex; // FrameIndex for return slot.
42 public:
43 PPC64TargetLowering(TargetMachine &TM) : TargetLowering(TM) {
Chris Lattner9bce0f92005-05-12 02:06:00 +000044 // Fold away setcc operations if possible.
45 setSetCCIsExpensive();
46
Nate Begemand3e6b942005-04-05 08:51:15 +000047 // Set up the register classes.
48 addRegisterClass(MVT::i64, PPC64::GPRCRegisterClass);
49 addRegisterClass(MVT::f32, PPC64::FPRCRegisterClass);
50 addRegisterClass(MVT::f64, PPC64::FPRCRegisterClass);
Misha Brukmanb5f662f2005-04-21 23:30:14 +000051
Nate Begemand3e6b942005-04-05 08:51:15 +000052 // PowerPC has no intrinsics for these particular operations
Chris Lattner644db4e2005-04-09 03:22:30 +000053 setOperationAction(ISD::BRCONDTWOWAY, MVT::Other, Expand);
Nate Begemand3e6b942005-04-05 08:51:15 +000054 setOperationAction(ISD::MEMMOVE, MVT::Other, Expand);
55 setOperationAction(ISD::MEMSET, MVT::Other, Expand);
56 setOperationAction(ISD::MEMCPY, MVT::Other, Expand);
57
Chris Lattner32f3cf62005-05-13 16:20:22 +000058 // We don't support sin/cos/sqrt/fmod
Chris Lattner08cae7f2005-04-30 04:26:56 +000059 setOperationAction(ISD::FSIN , MVT::f64, Expand);
60 setOperationAction(ISD::FCOS , MVT::f64, Expand);
61 setOperationAction(ISD::FSQRT, MVT::f64, Expand);
Chris Lattner32f3cf62005-05-13 16:20:22 +000062 setOperationAction(ISD::SREM , MVT::f64, Expand);
Chris Lattner08cae7f2005-04-30 04:26:56 +000063 setOperationAction(ISD::FSIN , MVT::f32, Expand);
64 setOperationAction(ISD::FCOS , MVT::f32, Expand);
65 setOperationAction(ISD::FSQRT, MVT::f32, Expand);
Chris Lattner32f3cf62005-05-13 16:20:22 +000066 setOperationAction(ISD::SREM , MVT::f32, Expand);
Chris Lattner08cae7f2005-04-30 04:26:56 +000067
Nate Begemand3e6b942005-04-05 08:51:15 +000068 // PPC 64 has i16 and i32 but no i8 (or i1) SEXTLOAD
69 setOperationAction(ISD::SEXTLOAD, MVT::i1, Expand);
70 setOperationAction(ISD::SEXTLOAD, MVT::i8, Expand);
71
Nate Begemane88aa5b2005-04-09 03:05:51 +000072 // PowerPC has no SREM/UREM instructions
73 setOperationAction(ISD::SREM, MVT::i64, Expand);
74 setOperationAction(ISD::UREM, MVT::i64, Expand);
75
Andrew Lenharth691ef2b2005-05-03 17:19:30 +000076 // PowerPC has these, but they are not implemented
77 setOperationAction(ISD::CTPOP, MVT::i64, Expand);
78 setOperationAction(ISD::CTTZ , MVT::i64, Expand);
Andrew Lenharthb5884d32005-05-04 19:25:37 +000079 setOperationAction(ISD::CTLZ , MVT::i64, Expand);
Andrew Lenharth691ef2b2005-05-03 17:19:30 +000080
Nate Begemand3e6b942005-04-05 08:51:15 +000081 setShiftAmountFlavor(Extend); // shl X, 32 == 0
82 addLegalFPImmediate(+0.0); // Necessary for FSEL
Misha Brukmanb5f662f2005-04-21 23:30:14 +000083 addLegalFPImmediate(-0.0); //
Nate Begemand3e6b942005-04-05 08:51:15 +000084
85 computeRegisterProperties();
86 }
87
88 /// LowerArguments - This hook must be implemented to indicate how we should
89 /// lower the arguments for the specified function, into the specified DAG.
90 virtual std::vector<SDOperand>
91 LowerArguments(Function &F, SelectionDAG &DAG);
Misha Brukmanb5f662f2005-04-21 23:30:14 +000092
Nate Begemand3e6b942005-04-05 08:51:15 +000093 /// LowerCallTo - This hook lowers an abstract call to a function into an
94 /// actual call.
95 virtual std::pair<SDOperand, SDOperand>
Chris Lattnerc57f6822005-05-12 19:56:45 +000096 LowerCallTo(SDOperand Chain, const Type *RetTy, bool isVarArg, unsigned CC,
Chris Lattneradf6a962005-05-13 18:50:42 +000097 bool isTailCall, SDOperand Callee, ArgListTy &Args,
98 SelectionDAG &DAG);
Misha Brukmanb5f662f2005-04-21 23:30:14 +000099
Nate Begemand3e6b942005-04-05 08:51:15 +0000100 virtual std::pair<SDOperand, SDOperand>
101 LowerVAStart(SDOperand Chain, SelectionDAG &DAG);
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000102
Nate Begemand3e6b942005-04-05 08:51:15 +0000103 virtual std::pair<SDOperand,SDOperand>
104 LowerVAArgNext(bool isVANext, SDOperand Chain, SDOperand VAList,
105 const Type *ArgTy, SelectionDAG &DAG);
106
107 virtual std::pair<SDOperand, SDOperand>
108 LowerFrameReturnAddress(bool isFrameAddr, SDOperand Chain, unsigned Depth,
109 SelectionDAG &DAG);
110 };
111}
112
113
114std::vector<SDOperand>
115PPC64TargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) {
116 //
117 // add beautiful description of PPC stack frame format, or at least some docs
118 //
119 MachineFunction &MF = DAG.getMachineFunction();
120 MachineFrameInfo *MFI = MF.getFrameInfo();
121 MachineBasicBlock& BB = MF.front();
122 std::vector<SDOperand> ArgValues;
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000123
124 // Due to the rather complicated nature of the PowerPC ABI, rather than a
Nate Begemand3e6b942005-04-05 08:51:15 +0000125 // fixed size array of physical args, for the sake of simplicity let the STL
126 // handle tracking them for us.
127 std::vector<unsigned> argVR, argPR, argOp;
Nate Begemanf3f2d6d2005-04-08 21:26:05 +0000128 unsigned ArgOffset = 48;
Nate Begemand3e6b942005-04-05 08:51:15 +0000129 unsigned GPR_remaining = 8;
130 unsigned FPR_remaining = 13;
131 unsigned GPR_idx = 0, FPR_idx = 0;
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000132 static const unsigned GPR[] = {
Nate Begemand3e6b942005-04-05 08:51:15 +0000133 PPC::R3, PPC::R4, PPC::R5, PPC::R6,
134 PPC::R7, PPC::R8, PPC::R9, PPC::R10,
135 };
136 static const unsigned FPR[] = {
137 PPC::F1, PPC::F2, PPC::F3, PPC::F4, PPC::F5, PPC::F6, PPC::F7,
138 PPC::F8, PPC::F9, PPC::F10, PPC::F11, PPC::F12, PPC::F13
139 };
140
141 // Add DAG nodes to load the arguments... On entry to a function on PPC,
Nate Begemanf3f2d6d2005-04-08 21:26:05 +0000142 // the arguments start at offset 48, although they are likely to be passed
Nate Begemand3e6b942005-04-05 08:51:15 +0000143 // in registers.
144 for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; ++I) {
145 SDOperand newroot, argt;
Nate Begemand3e6b942005-04-05 08:51:15 +0000146 bool needsLoad = false;
147 MVT::ValueType ObjectVT = getValueType(I->getType());
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000148
Nate Begemand3e6b942005-04-05 08:51:15 +0000149 switch (ObjectVT) {
150 default: assert(0 && "Unhandled argument type!");
151 case MVT::i1:
152 case MVT::i8:
153 case MVT::i16:
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000154 case MVT::i32:
Nate Begemanf3f2d6d2005-04-08 21:26:05 +0000155 case MVT::i64:
Nate Begemand3e6b942005-04-05 08:51:15 +0000156 if (GPR_remaining > 0) {
157 BuildMI(&BB, PPC::IMPLICIT_DEF, 0, GPR[GPR_idx]);
158 argt = newroot = DAG.getCopyFromReg(GPR[GPR_idx], MVT::i32,
159 DAG.getRoot());
Nate Begemanf3f2d6d2005-04-08 21:26:05 +0000160 if (ObjectVT != MVT::i64)
Nate Begemand3e6b942005-04-05 08:51:15 +0000161 argt = DAG.getNode(ISD::TRUNCATE, ObjectVT, newroot);
162 } else {
163 needsLoad = true;
164 }
165 break;
Nate Begemanf3f2d6d2005-04-08 21:26:05 +0000166 case MVT::f32:
167 case MVT::f64:
Nate Begemand3e6b942005-04-05 08:51:15 +0000168 if (FPR_remaining > 0) {
169 BuildMI(&BB, PPC::IMPLICIT_DEF, 0, FPR[FPR_idx]);
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000170 argt = newroot = DAG.getCopyFromReg(FPR[FPR_idx], ObjectVT,
Nate Begemand3e6b942005-04-05 08:51:15 +0000171 DAG.getRoot());
172 --FPR_remaining;
173 ++FPR_idx;
174 } else {
175 needsLoad = true;
176 }
177 break;
178 }
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000179
Nate Begemand3e6b942005-04-05 08:51:15 +0000180 // We need to load the argument to a virtual register if we determined above
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000181 // that we ran out of physical registers of the appropriate type
Nate Begemand3e6b942005-04-05 08:51:15 +0000182 if (needsLoad) {
183 unsigned SubregOffset = 0;
Nate Begemanf3f2d6d2005-04-08 21:26:05 +0000184 switch (ObjectVT) {
185 default: assert(0 && "Unhandled argument type!");
186 case MVT::i1:
187 case MVT::i8: SubregOffset = 7; break;
188 case MVT::i16: SubregOffset = 6; break;
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000189 case MVT::i32:
Nate Begemanf3f2d6d2005-04-08 21:26:05 +0000190 case MVT::f32: SubregOffset = 4; break;
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000191 case MVT::i64:
Nate Begemanf3f2d6d2005-04-08 21:26:05 +0000192 case MVT::f64: SubregOffset = 0; break;
193 }
194 int FI = MFI->CreateFixedObject(8, ArgOffset);
195 SDOperand FIN = DAG.getFrameIndex(FI, MVT::i64);
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000196 FIN = DAG.getNode(ISD::ADD, MVT::i64, FIN,
Nate Begemanf3f2d6d2005-04-08 21:26:05 +0000197 DAG.getConstant(SubregOffset, MVT::i64));
Andrew Lenharth2d86ea22005-04-27 20:10:01 +0000198 argt = newroot = DAG.getLoad(ObjectVT, DAG.getEntryNode(), FIN, DAG.getSrcValue(NULL));
Nate Begemand3e6b942005-04-05 08:51:15 +0000199 }
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000200
Nate Begemand3e6b942005-04-05 08:51:15 +0000201 // Every 4 bytes of argument space consumes one of the GPRs available for
202 // argument passing.
203 if (GPR_remaining > 0) {
Nate Begemanf3f2d6d2005-04-08 21:26:05 +0000204 --GPR_remaining;
205 ++GPR_idx;
Nate Begemand3e6b942005-04-05 08:51:15 +0000206 }
Nate Begemanf3f2d6d2005-04-08 21:26:05 +0000207 ArgOffset += 8;
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000208
Nate Begemand3e6b942005-04-05 08:51:15 +0000209 DAG.setRoot(newroot.getValue(1));
210 ArgValues.push_back(argt);
211 }
212
213 // If the function takes variable number of arguments, make a frame index for
214 // the start of the first vararg value... for expansion of llvm.va_start.
215 if (F.isVarArg()) {
Nate Begemanf3f2d6d2005-04-08 21:26:05 +0000216 VarArgsFrameIndex = MFI->CreateFixedObject(8, ArgOffset);
217 SDOperand FIN = DAG.getFrameIndex(VarArgsFrameIndex, MVT::i64);
Nate Begemand3e6b942005-04-05 08:51:15 +0000218 // If this function is vararg, store any remaining integer argument regs
219 // to their spots on the stack so that they may be loaded by deferencing the
220 // result of va_next.
221 std::vector<SDOperand> MemOps;
222 for (; GPR_remaining > 0; --GPR_remaining, ++GPR_idx) {
223 BuildMI(&BB, PPC::IMPLICIT_DEF, 0, GPR[GPR_idx]);
Nate Begemanf3f2d6d2005-04-08 21:26:05 +0000224 SDOperand Val = DAG.getCopyFromReg(GPR[GPR_idx], MVT::i64, DAG.getRoot());
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000225 SDOperand Store = DAG.getNode(ISD::STORE, MVT::Other, Val.getValue(1),
Andrew Lenharth2d86ea22005-04-27 20:10:01 +0000226 Val, FIN, DAG.getSrcValue(NULL));
Nate Begemand3e6b942005-04-05 08:51:15 +0000227 MemOps.push_back(Store);
Nate Begemanf3f2d6d2005-04-08 21:26:05 +0000228 // Increment the address by eight for the next argument to store
229 SDOperand PtrOff = DAG.getConstant(8, getPointerTy());
Nate Begemand3e6b942005-04-05 08:51:15 +0000230 FIN = DAG.getNode(ISD::ADD, MVT::i32, FIN, PtrOff);
231 }
232 DAG.setRoot(DAG.getNode(ISD::TokenFactor, MVT::Other, MemOps));
233 }
234
235 return ArgValues;
236}
237
238std::pair<SDOperand, SDOperand>
239PPC64TargetLowering::LowerCallTo(SDOperand Chain,
Misha Brukman7847fca2005-04-22 17:54:37 +0000240 const Type *RetTy, bool isVarArg,
Chris Lattneradf6a962005-05-13 18:50:42 +0000241 unsigned CallingConv, bool isTailCall,
Misha Brukman7847fca2005-04-22 17:54:37 +0000242 SDOperand Callee, ArgListTy &Args,
243 SelectionDAG &DAG) {
Nate Begemand3e6b942005-04-05 08:51:15 +0000244 // args_to_use will accumulate outgoing args for the ISD::CALL case in
245 // SelectExpr to use to put the arguments in the appropriate registers.
246 std::vector<SDOperand> args_to_use;
247
248 // Count how many bytes are to be pushed on the stack, including the linkage
249 // area, and parameter passing area.
Nate Begemanf3f2d6d2005-04-08 21:26:05 +0000250 unsigned NumBytes = 48;
Nate Begemand3e6b942005-04-05 08:51:15 +0000251
252 if (Args.empty()) {
Chris Lattner16cd04d2005-05-12 23:24:06 +0000253 Chain = DAG.getNode(ISD::CALLSEQ_START, MVT::Other, Chain,
Nate Begemand3e6b942005-04-05 08:51:15 +0000254 DAG.getConstant(NumBytes, getPointerTy()));
255 } else {
Nate Begemanf3f2d6d2005-04-08 21:26:05 +0000256 NumBytes = 8 * Args.size(); // All arguments are rounded up to 8 bytes
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000257
258 // Just to be safe, we'll always reserve the full 48 bytes of linkage area
Nate Begemanf3f2d6d2005-04-08 21:26:05 +0000259 // plus 64 bytes of argument space in case any called code gets funky on us.
260 if (NumBytes < 112) NumBytes = 112;
Nate Begemand3e6b942005-04-05 08:51:15 +0000261
262 // Adjust the stack pointer for the new arguments...
263 // These operations are automatically eliminated by the prolog/epilog pass
Chris Lattner16cd04d2005-05-12 23:24:06 +0000264 Chain = DAG.getNode(ISD::CALLSEQ_START, MVT::Other, Chain,
Nate Begemand3e6b942005-04-05 08:51:15 +0000265 DAG.getConstant(NumBytes, getPointerTy()));
266
267 // Set up a copy of the stack pointer for use loading and storing any
268 // arguments that may not fit in the registers available for argument
269 // passing.
270 SDOperand StackPtr = DAG.getCopyFromReg(PPC::R1, MVT::i32,
271 DAG.getEntryNode());
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000272
Nate Begemand3e6b942005-04-05 08:51:15 +0000273 // Figure out which arguments are going to go in registers, and which in
274 // memory. Also, if this is a vararg function, floating point operations
275 // must be stored to our stack, and loaded into integer regs as well, if
276 // any integer regs are available for argument passing.
Nate Begemanf3f2d6d2005-04-08 21:26:05 +0000277 unsigned ArgOffset = 48;
Nate Begemand3e6b942005-04-05 08:51:15 +0000278 unsigned GPR_remaining = 8;
279 unsigned FPR_remaining = 13;
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000280
Nate Begemand3e6b942005-04-05 08:51:15 +0000281 std::vector<SDOperand> MemOps;
282 for (unsigned i = 0, e = Args.size(); i != e; ++i) {
283 // PtrOff will be used to store the current argument to the stack if a
284 // register cannot be found for it.
285 SDOperand PtrOff = DAG.getConstant(ArgOffset, getPointerTy());
286 PtrOff = DAG.getNode(ISD::ADD, MVT::i32, StackPtr, PtrOff);
287 MVT::ValueType ArgVT = getValueType(Args[i].second);
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000288
Nate Begemand3e6b942005-04-05 08:51:15 +0000289 switch (ArgVT) {
290 default: assert(0 && "Unexpected ValueType for argument!");
291 case MVT::i1:
292 case MVT::i8:
293 case MVT::i16:
Nate Begemanf3f2d6d2005-04-08 21:26:05 +0000294 case MVT::i32:
295 // Promote the integer to 64 bits. If the input type is signed use a
Nate Begemand3e6b942005-04-05 08:51:15 +0000296 // sign extend, otherwise use a zero extend.
297 if (Args[i].second->isSigned())
Nate Begemanf3f2d6d2005-04-08 21:26:05 +0000298 Args[i].first =DAG.getNode(ISD::SIGN_EXTEND, MVT::i64, Args[i].first);
Nate Begemand3e6b942005-04-05 08:51:15 +0000299 else
Nate Begemanf3f2d6d2005-04-08 21:26:05 +0000300 Args[i].first =DAG.getNode(ISD::ZERO_EXTEND, MVT::i64, Args[i].first);
Nate Begemand3e6b942005-04-05 08:51:15 +0000301 // FALL THROUGH
Nate Begemanf3f2d6d2005-04-08 21:26:05 +0000302 case MVT::i64:
Nate Begemand3e6b942005-04-05 08:51:15 +0000303 if (GPR_remaining > 0) {
304 args_to_use.push_back(Args[i].first);
305 --GPR_remaining;
306 } else {
307 MemOps.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain,
Andrew Lenharth2d86ea22005-04-27 20:10:01 +0000308 Args[i].first, PtrOff, DAG.getSrcValue(NULL)));
Nate Begemand3e6b942005-04-05 08:51:15 +0000309 }
Nate Begemand3e6b942005-04-05 08:51:15 +0000310 ArgOffset += 8;
311 break;
312 case MVT::f32:
313 case MVT::f64:
314 if (FPR_remaining > 0) {
315 args_to_use.push_back(Args[i].first);
316 --FPR_remaining;
317 if (isVarArg) {
318 SDOperand Store = DAG.getNode(ISD::STORE, MVT::Other, Chain,
Andrew Lenharth2d86ea22005-04-27 20:10:01 +0000319 Args[i].first, PtrOff, DAG.getSrcValue(NULL));
Nate Begemand3e6b942005-04-05 08:51:15 +0000320 MemOps.push_back(Store);
321 // Float varargs are always shadowed in available integer registers
322 if (GPR_remaining > 0) {
Andrew Lenharth2d86ea22005-04-27 20:10:01 +0000323 SDOperand Load = DAG.getLoad(MVT::i64, Store, PtrOff, DAG.getSrcValue(NULL));
Nate Begemand3e6b942005-04-05 08:51:15 +0000324 MemOps.push_back(Load);
325 args_to_use.push_back(Load);
326 --GPR_remaining;
327 }
328 } else {
329 // If we have any FPRs remaining, we may also have GPRs remaining.
Nate Begemanf3f2d6d2005-04-08 21:26:05 +0000330 // Args passed in FPRs also consume an available GPR.
Nate Begemand3e6b942005-04-05 08:51:15 +0000331 if (GPR_remaining > 0) {
Nate Begemanf3f2d6d2005-04-08 21:26:05 +0000332 args_to_use.push_back(DAG.getNode(ISD::UNDEF, MVT::i64));
Nate Begemand3e6b942005-04-05 08:51:15 +0000333 --GPR_remaining;
334 }
335 }
336 } else {
337 MemOps.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain,
Andrew Lenharth2d86ea22005-04-27 20:10:01 +0000338 Args[i].first, PtrOff, DAG.getSrcValue(NULL)));
Nate Begemand3e6b942005-04-05 08:51:15 +0000339 }
Nate Begemanf3f2d6d2005-04-08 21:26:05 +0000340 ArgOffset += 8;
Nate Begemand3e6b942005-04-05 08:51:15 +0000341 break;
342 }
343 }
344 if (!MemOps.empty())
345 Chain = DAG.getNode(ISD::TokenFactor, MVT::Other, MemOps);
346 }
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000347
Nate Begemand3e6b942005-04-05 08:51:15 +0000348 std::vector<MVT::ValueType> RetVals;
349 MVT::ValueType RetTyVT = getValueType(RetTy);
350 if (RetTyVT != MVT::isVoid)
351 RetVals.push_back(RetTyVT);
352 RetVals.push_back(MVT::Other);
353
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000354 SDOperand TheCall = SDOperand(DAG.getCall(RetVals,
Nate Begemand3e6b942005-04-05 08:51:15 +0000355 Chain, Callee, args_to_use), 0);
356 Chain = TheCall.getValue(RetTyVT != MVT::isVoid);
Chris Lattner16cd04d2005-05-12 23:24:06 +0000357 Chain = DAG.getNode(ISD::CALLSEQ_END, MVT::Other, Chain,
Nate Begemand3e6b942005-04-05 08:51:15 +0000358 DAG.getConstant(NumBytes, getPointerTy()));
359 return std::make_pair(TheCall, Chain);
360}
361
362std::pair<SDOperand, SDOperand>
363PPC64TargetLowering::LowerVAStart(SDOperand Chain, SelectionDAG &DAG) {
364 //vastart just returns the address of the VarArgsFrameIndex slot.
Nate Begemanf3f2d6d2005-04-08 21:26:05 +0000365 return std::make_pair(DAG.getFrameIndex(VarArgsFrameIndex, MVT::i64), Chain);
Nate Begemand3e6b942005-04-05 08:51:15 +0000366}
367
368std::pair<SDOperand,SDOperand> PPC64TargetLowering::
369LowerVAArgNext(bool isVANext, SDOperand Chain, SDOperand VAList,
370 const Type *ArgTy, SelectionDAG &DAG) {
371 MVT::ValueType ArgVT = getValueType(ArgTy);
372 SDOperand Result;
373 if (!isVANext) {
Andrew Lenharth2d86ea22005-04-27 20:10:01 +0000374 Result = DAG.getLoad(ArgVT, DAG.getEntryNode(), VAList, DAG.getSrcValue(NULL));
Nate Begemand3e6b942005-04-05 08:51:15 +0000375 } else {
Nate Begemand3e6b942005-04-05 08:51:15 +0000376 Result = DAG.getNode(ISD::ADD, VAList.getValueType(), VAList,
Nate Begemanf3f2d6d2005-04-08 21:26:05 +0000377 DAG.getConstant(8, VAList.getValueType()));
Nate Begemand3e6b942005-04-05 08:51:15 +0000378 }
379 return std::make_pair(Result, Chain);
380}
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000381
Nate Begemand3e6b942005-04-05 08:51:15 +0000382
383std::pair<SDOperand, SDOperand> PPC64TargetLowering::
384LowerFrameReturnAddress(bool isFrameAddress, SDOperand Chain, unsigned Depth,
385 SelectionDAG &DAG) {
386 assert(0 && "LowerFrameReturnAddress unimplemented");
387 abort();
388}
389
390namespace {
391Statistic<>NotLogic("ppc-codegen", "Number of inverted logical ops");
392Statistic<>FusedFP("ppc-codegen", "Number of fused fp operations");
393//===--------------------------------------------------------------------===//
394/// ISel - PPC32 specific code to select PPC32 machine instructions for
395/// SelectionDAG operations.
396//===--------------------------------------------------------------------===//
397class ISel : public SelectionDAGISel {
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000398
Nate Begemand3e6b942005-04-05 08:51:15 +0000399 /// Comment Here.
400 PPC64TargetLowering PPC64Lowering;
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000401
Nate Begemand3e6b942005-04-05 08:51:15 +0000402 /// ExprMap - As shared expressions are codegen'd, we keep track of which
403 /// vreg the value is produced in, so we only emit one copy of each compiled
404 /// tree.
405 std::map<SDOperand, unsigned> ExprMap;
406
407 unsigned GlobalBaseReg;
408 bool GlobalBaseInitialized;
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000409
Nate Begemand3e6b942005-04-05 08:51:15 +0000410public:
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000411 ISel(TargetMachine &TM) : SelectionDAGISel(PPC64Lowering), PPC64Lowering(TM)
Nate Begemand3e6b942005-04-05 08:51:15 +0000412 {}
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000413
Nate Begemand3e6b942005-04-05 08:51:15 +0000414 /// runOnFunction - Override this function in order to reset our per-function
415 /// variables.
416 virtual bool runOnFunction(Function &Fn) {
417 // Make sure we re-emit a set of the global base reg if necessary
418 GlobalBaseInitialized = false;
419 return SelectionDAGISel::runOnFunction(Fn);
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000420 }
421
Nate Begemand3e6b942005-04-05 08:51:15 +0000422 /// InstructionSelectBasicBlock - This callback is invoked by
423 /// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
424 virtual void InstructionSelectBasicBlock(SelectionDAG &DAG) {
425 DEBUG(BB->dump());
426 // Codegen the basic block.
427 Select(DAG.getRoot());
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000428
Nate Begemand3e6b942005-04-05 08:51:15 +0000429 // Clear state used for selection.
430 ExprMap.clear();
431 }
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000432
Nate Begemand3e6b942005-04-05 08:51:15 +0000433 unsigned getGlobalBaseReg();
434 unsigned getConstDouble(double floatVal, unsigned Result);
435 unsigned SelectSetCR0(SDOperand CC);
436 unsigned SelectExpr(SDOperand N);
437 unsigned SelectExprFP(SDOperand N, unsigned Result);
438 void Select(SDOperand N);
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000439
Nate Begemand3e6b942005-04-05 08:51:15 +0000440 bool SelectAddr(SDOperand N, unsigned& Reg, int& offset);
441 void SelectBranchCC(SDOperand N);
442};
443
444/// ExactLog2 - This function solves for (Val == 1 << (N-1)) and returns N. It
445/// returns zero when the input is not exactly a power of two.
446static unsigned ExactLog2(unsigned Val) {
447 if (Val == 0 || (Val & (Val-1))) return 0;
448 unsigned Count = 0;
449 while (Val != 1) {
450 Val >>= 1;
451 ++Count;
452 }
453 return Count;
454}
455
456/// getImmediateForOpcode - This method returns a value indicating whether
457/// the ConstantSDNode N can be used as an immediate to Opcode. The return
458/// values are either 0, 1 or 2. 0 indicates that either N is not a
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000459/// ConstantSDNode, or is not suitable for use by that opcode. A return value
Nate Begemand3e6b942005-04-05 08:51:15 +0000460/// of 1 indicates that the constant may be used in normal immediate form. A
461/// return value of 2 indicates that the constant may be used in shifted
462/// immediate form. A return value of 3 indicates that log base 2 of the
463/// constant may be used.
464///
465static unsigned getImmediateForOpcode(SDOperand N, unsigned Opcode,
466 unsigned& Imm, bool U = false) {
467 if (N.getOpcode() != ISD::Constant) return 0;
468
469 int v = (int)cast<ConstantSDNode>(N)->getSignExtended();
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000470
Nate Begemand3e6b942005-04-05 08:51:15 +0000471 switch(Opcode) {
472 default: return 0;
473 case ISD::ADD:
474 if (v <= 32767 && v >= -32768) { Imm = v & 0xFFFF; return 1; }
475 if ((v & 0x0000FFFF) == 0) { Imm = v >> 16; return 2; }
476 break;
477 case ISD::AND:
478 case ISD::XOR:
479 case ISD::OR:
480 if (v >= 0 && v <= 65535) { Imm = v & 0xFFFF; return 1; }
481 if ((v & 0x0000FFFF) == 0) { Imm = v >> 16; return 2; }
482 break;
483 case ISD::MUL:
484 case ISD::SUB:
485 if (v <= 32767 && v >= -32768) { Imm = v & 0xFFFF; return 1; }
486 break;
487 case ISD::SETCC:
488 if (U && (v >= 0 && v <= 65535)) { Imm = v & 0xFFFF; return 1; }
489 if (!U && (v <= 32767 && v >= -32768)) { Imm = v & 0xFFFF; return 1; }
490 break;
491 case ISD::SDIV:
492 if ((Imm = ExactLog2(v))) { return 3; }
493 break;
494 }
495 return 0;
496}
497
498/// getBCCForSetCC - Returns the PowerPC condition branch mnemonic corresponding
499/// to Condition. If the Condition is unordered or unsigned, the bool argument
500/// U is set to true, otherwise it is set to false.
501static unsigned getBCCForSetCC(unsigned Condition, bool& U) {
502 U = false;
503 switch (Condition) {
504 default: assert(0 && "Unknown condition!"); abort();
505 case ISD::SETEQ: return PPC::BEQ;
506 case ISD::SETNE: return PPC::BNE;
507 case ISD::SETULT: U = true;
508 case ISD::SETLT: return PPC::BLT;
509 case ISD::SETULE: U = true;
510 case ISD::SETLE: return PPC::BLE;
511 case ISD::SETUGT: U = true;
512 case ISD::SETGT: return PPC::BGT;
513 case ISD::SETUGE: U = true;
514 case ISD::SETGE: return PPC::BGE;
515 }
516 return 0;
517}
518
519/// IndexedOpForOp - Return the indexed variant for each of the PowerPC load
520/// and store immediate instructions.
521static unsigned IndexedOpForOp(unsigned Opcode) {
522 switch(Opcode) {
523 default: assert(0 && "Unknown opcode!"); abort();
524 case PPC::LBZ: return PPC::LBZX; case PPC::STB: return PPC::STBX;
525 case PPC::LHZ: return PPC::LHZX; case PPC::STH: return PPC::STHX;
526 case PPC::LHA: return PPC::LHAX; case PPC::STW: return PPC::STWX;
527 case PPC::LWZ: return PPC::LWZX; case PPC::STD: return PPC::STDX;
528 case PPC::LD: return PPC::LDX; case PPC::STFS: return PPC::STFSX;
529 case PPC::LFS: return PPC::LFSX; case PPC::STFD: return PPC::STFDX;
530 case PPC::LFD: return PPC::LFDX;
531 }
532 return 0;
533}
534}
535
536/// getGlobalBaseReg - Output the instructions required to put the
537/// base address to use for accessing globals into a register.
538///
539unsigned ISel::getGlobalBaseReg() {
540 if (!GlobalBaseInitialized) {
541 // Insert the set of GlobalBaseReg into the first MBB of the function
542 MachineBasicBlock &FirstMBB = BB->getParent()->front();
543 MachineBasicBlock::iterator MBBI = FirstMBB.begin();
544 GlobalBaseReg = MakeReg(MVT::i64);
545 BuildMI(FirstMBB, MBBI, PPC::MovePCtoLR, 0, PPC::LR);
546 BuildMI(FirstMBB, MBBI, PPC::MFLR, 1, GlobalBaseReg).addReg(PPC::LR);
547 GlobalBaseInitialized = true;
548 }
549 return GlobalBaseReg;
550}
551
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000552/// getConstDouble - Loads a floating point value into a register, via the
Nate Begemand3e6b942005-04-05 08:51:15 +0000553/// Constant Pool. Optionally takes a register in which to load the value.
554unsigned ISel::getConstDouble(double doubleVal, unsigned Result=0) {
Nate Begemanf3f2d6d2005-04-08 21:26:05 +0000555 unsigned Tmp1 = MakeReg(MVT::i64);
Nate Begemand3e6b942005-04-05 08:51:15 +0000556 if (0 == Result) Result = MakeReg(MVT::f64);
557 MachineConstantPool *CP = BB->getParent()->getConstantPool();
558 ConstantFP *CFP = ConstantFP::get(Type::DoubleTy, doubleVal);
559 unsigned CPI = CP->getConstantPoolIndex(CFP);
560 BuildMI(BB, PPC::LOADHiAddr, 2, Tmp1).addReg(getGlobalBaseReg())
561 .addConstantPoolIndex(CPI);
562 BuildMI(BB, PPC::LFD, 2, Result).addConstantPoolIndex(CPI).addReg(Tmp1);
563 return Result;
564}
565
566unsigned ISel::SelectSetCR0(SDOperand CC) {
567 unsigned Opc, Tmp1, Tmp2;
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000568 static const unsigned CompareOpcodes[] =
Nate Begemand3e6b942005-04-05 08:51:15 +0000569 { PPC::FCMPU, PPC::FCMPU, PPC::CMPW, PPC::CMPLW };
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000570
Nate Begemand3e6b942005-04-05 08:51:15 +0000571 // If the first operand to the select is a SETCC node, then we can fold it
572 // into the branch that selects which value to return.
573 SetCCSDNode* SetCC = dyn_cast<SetCCSDNode>(CC.Val);
574 if (SetCC && CC.getOpcode() == ISD::SETCC) {
575 bool U;
576 Opc = getBCCForSetCC(SetCC->getCondition(), U);
577 Tmp1 = SelectExpr(SetCC->getOperand(0));
578
579 // Pass the optional argument U to getImmediateForOpcode for SETCC,
580 // so that it knows whether the SETCC immediate range is signed or not.
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000581 if (1 == getImmediateForOpcode(SetCC->getOperand(1), ISD::SETCC,
Nate Begemand3e6b942005-04-05 08:51:15 +0000582 Tmp2, U)) {
583 if (U)
584 BuildMI(BB, PPC::CMPLWI, 2, PPC::CR0).addReg(Tmp1).addImm(Tmp2);
585 else
586 BuildMI(BB, PPC::CMPWI, 2, PPC::CR0).addReg(Tmp1).addSImm(Tmp2);
587 } else {
588 bool IsInteger = MVT::isInteger(SetCC->getOperand(0).getValueType());
589 unsigned CompareOpc = CompareOpcodes[2 * IsInteger + U];
590 Tmp2 = SelectExpr(SetCC->getOperand(1));
591 BuildMI(BB, CompareOpc, 2, PPC::CR0).addReg(Tmp1).addReg(Tmp2);
592 }
593 } else {
594 Tmp1 = SelectExpr(CC);
595 BuildMI(BB, PPC::CMPLWI, 2, PPC::CR0).addReg(Tmp1).addImm(0);
596 Opc = PPC::BNE;
597 }
598 return Opc;
599}
600
601/// Check to see if the load is a constant offset from a base register
602bool ISel::SelectAddr(SDOperand N, unsigned& Reg, int& offset)
603{
604 unsigned imm = 0, opcode = N.getOpcode();
605 if (N.getOpcode() == ISD::ADD) {
606 Reg = SelectExpr(N.getOperand(0));
607 if (1 == getImmediateForOpcode(N.getOperand(1), opcode, imm)) {
608 offset = imm;
609 return false;
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000610 }
Nate Begemand3e6b942005-04-05 08:51:15 +0000611 offset = SelectExpr(N.getOperand(1));
612 return true;
613 }
614 Reg = SelectExpr(N);
615 offset = 0;
616 return false;
617}
618
619void ISel::SelectBranchCC(SDOperand N)
620{
621 assert(N.getOpcode() == ISD::BRCOND && "Not a BranchCC???");
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000622 MachineBasicBlock *Dest =
Nate Begemand3e6b942005-04-05 08:51:15 +0000623 cast<BasicBlockSDNode>(N.getOperand(2))->getBasicBlock();
624
625 // Get the MBB we will fall through to so that we can hand it off to the
626 // branch selection pass as an argument to the PPC::COND_BRANCH pseudo op.
627 //ilist<MachineBasicBlock>::iterator It = BB;
628 //MachineBasicBlock *Fallthrough = ++It;
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000629
Nate Begemand3e6b942005-04-05 08:51:15 +0000630 Select(N.getOperand(0)); //chain
631 unsigned Opc = SelectSetCR0(N.getOperand(1));
632 // FIXME: Use this once we have something approximating two-way branches
633 // We cannot currently use this in case the ISel hands us something like
634 // BRcc MBBx
635 // BR MBBy
636 // since the fallthrough basic block for the conditional branch does not start
637 // with the unconditional branch (it is skipped over).
638 //BuildMI(BB, PPC::COND_BRANCH, 4).addReg(PPC::CR0).addImm(Opc)
639 // .addMBB(Dest).addMBB(Fallthrough);
640 BuildMI(BB, Opc, 2).addReg(PPC::CR0).addMBB(Dest);
641 return;
642}
643
644unsigned ISel::SelectExprFP(SDOperand N, unsigned Result)
645{
646 unsigned Tmp1, Tmp2, Tmp3;
647 unsigned Opc = 0;
648 SDNode *Node = N.Val;
649 MVT::ValueType DestType = N.getValueType();
650 unsigned opcode = N.getOpcode();
651
652 switch (opcode) {
653 default:
654 Node->dump();
655 assert(0 && "Node not handled!\n");
656
657 case ISD::SELECT: {
658 // Attempt to generate FSEL. We can do this whenever we have an FP result,
659 // and an FP comparison in the SetCC node.
660 SetCCSDNode* SetCC = dyn_cast<SetCCSDNode>(N.getOperand(0).Val);
661 if (SetCC && N.getOperand(0).getOpcode() == ISD::SETCC &&
662 !MVT::isInteger(SetCC->getOperand(0).getValueType()) &&
663 SetCC->getCondition() != ISD::SETEQ &&
664 SetCC->getCondition() != ISD::SETNE) {
665 MVT::ValueType VT = SetCC->getOperand(0).getValueType();
666 Tmp1 = SelectExpr(SetCC->getOperand(0)); // Val to compare against
667 unsigned TV = SelectExpr(N.getOperand(1)); // Use if TRUE
668 unsigned FV = SelectExpr(N.getOperand(2)); // Use if FALSE
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000669
Nate Begemand3e6b942005-04-05 08:51:15 +0000670 ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(SetCC->getOperand(1));
671 if (CN && (CN->isExactlyValue(-0.0) || CN->isExactlyValue(0.0))) {
672 switch(SetCC->getCondition()) {
673 default: assert(0 && "Invalid FSEL condition"); abort();
674 case ISD::SETULT:
675 case ISD::SETLT:
676 BuildMI(BB, PPC::FSEL, 3, Result).addReg(Tmp1).addReg(FV).addReg(TV);
677 return Result;
678 case ISD::SETUGE:
679 case ISD::SETGE:
680 BuildMI(BB, PPC::FSEL, 3, Result).addReg(Tmp1).addReg(TV).addReg(FV);
681 return Result;
682 case ISD::SETUGT:
683 case ISD::SETGT: {
684 Tmp2 = MakeReg(VT);
685 BuildMI(BB, PPC::FNEG, 1, Tmp2).addReg(Tmp1);
686 BuildMI(BB, PPC::FSEL, 3, Result).addReg(Tmp2).addReg(FV).addReg(TV);
687 return Result;
688 }
689 case ISD::SETULE:
690 case ISD::SETLE: {
691 Tmp2 = MakeReg(VT);
692 BuildMI(BB, PPC::FNEG, 1, Tmp2).addReg(Tmp1);
693 BuildMI(BB, PPC::FSEL, 3, Result).addReg(Tmp2).addReg(TV).addReg(FV);
694 return Result;
695 }
696 }
697 } else {
698 Opc = (MVT::f64 == VT) ? PPC::FSUB : PPC::FSUBS;
699 Tmp2 = SelectExpr(SetCC->getOperand(1));
700 Tmp3 = MakeReg(VT);
701 switch(SetCC->getCondition()) {
702 default: assert(0 && "Invalid FSEL condition"); abort();
703 case ISD::SETULT:
704 case ISD::SETLT:
705 BuildMI(BB, Opc, 2, Tmp3).addReg(Tmp1).addReg(Tmp2);
706 BuildMI(BB, PPC::FSEL, 3, Result).addReg(Tmp3).addReg(FV).addReg(TV);
707 return Result;
708 case ISD::SETUGE:
709 case ISD::SETGE:
710 BuildMI(BB, Opc, 2, Tmp3).addReg(Tmp1).addReg(Tmp2);
711 BuildMI(BB, PPC::FSEL, 3, Result).addReg(Tmp3).addReg(TV).addReg(FV);
712 return Result;
713 case ISD::SETUGT:
714 case ISD::SETGT:
715 BuildMI(BB, Opc, 2, Tmp3).addReg(Tmp2).addReg(Tmp1);
716 BuildMI(BB, PPC::FSEL, 3, Result).addReg(Tmp3).addReg(FV).addReg(TV);
717 return Result;
718 case ISD::SETULE:
719 case ISD::SETLE:
720 BuildMI(BB, Opc, 2, Tmp3).addReg(Tmp2).addReg(Tmp1);
721 BuildMI(BB, PPC::FSEL, 3, Result).addReg(Tmp3).addReg(TV).addReg(FV);
722 return Result;
723 }
724 }
725 assert(0 && "Should never get here");
726 return 0;
727 }
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000728
Nate Begemand3e6b942005-04-05 08:51:15 +0000729 unsigned TrueValue = SelectExpr(N.getOperand(1)); //Use if TRUE
730 unsigned FalseValue = SelectExpr(N.getOperand(2)); //Use if FALSE
731 Opc = SelectSetCR0(N.getOperand(0));
732
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000733 // Create an iterator with which to insert the MBB for copying the false
Nate Begemand3e6b942005-04-05 08:51:15 +0000734 // value and the MBB to hold the PHI instruction for this SetCC.
735 MachineBasicBlock *thisMBB = BB;
736 const BasicBlock *LLVM_BB = BB->getBasicBlock();
737 ilist<MachineBasicBlock>::iterator It = BB;
738 ++It;
739
740 // thisMBB:
741 // ...
742 // TrueVal = ...
743 // cmpTY cr0, r1, r2
744 // bCC copy1MBB
745 // fallthrough --> copy0MBB
746 MachineBasicBlock *copy0MBB = new MachineBasicBlock(LLVM_BB);
747 MachineBasicBlock *sinkMBB = new MachineBasicBlock(LLVM_BB);
748 BuildMI(BB, Opc, 2).addReg(PPC::CR0).addMBB(sinkMBB);
749 MachineFunction *F = BB->getParent();
750 F->getBasicBlockList().insert(It, copy0MBB);
751 F->getBasicBlockList().insert(It, sinkMBB);
752 // Update machine-CFG edges
753 BB->addSuccessor(copy0MBB);
754 BB->addSuccessor(sinkMBB);
755
756 // copy0MBB:
757 // %FalseValue = ...
758 // # fallthrough to sinkMBB
759 BB = copy0MBB;
760 // Update machine-CFG edges
761 BB->addSuccessor(sinkMBB);
762
763 // sinkMBB:
764 // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ]
765 // ...
766 BB = sinkMBB;
767 BuildMI(BB, PPC::PHI, 4, Result).addReg(FalseValue)
768 .addMBB(copy0MBB).addReg(TrueValue).addMBB(thisMBB);
769 return Result;
770 }
771
772 case ISD::FNEG:
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000773 if (!NoExcessFPPrecision &&
Nate Begemand3e6b942005-04-05 08:51:15 +0000774 ISD::ADD == N.getOperand(0).getOpcode() &&
775 N.getOperand(0).Val->hasOneUse() &&
776 ISD::MUL == N.getOperand(0).getOperand(0).getOpcode() &&
777 N.getOperand(0).getOperand(0).Val->hasOneUse()) {
778 ++FusedFP; // Statistic
779 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0).getOperand(0));
780 Tmp2 = SelectExpr(N.getOperand(0).getOperand(0).getOperand(1));
781 Tmp3 = SelectExpr(N.getOperand(0).getOperand(1));
782 Opc = DestType == MVT::f64 ? PPC::FNMADD : PPC::FNMADDS;
783 BuildMI(BB, Opc, 3, Result).addReg(Tmp1).addReg(Tmp2).addReg(Tmp3);
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000784 } else if (!NoExcessFPPrecision &&
Nate Begemand3e6b942005-04-05 08:51:15 +0000785 ISD::SUB == N.getOperand(0).getOpcode() &&
786 N.getOperand(0).Val->hasOneUse() &&
787 ISD::MUL == N.getOperand(0).getOperand(0).getOpcode() &&
788 N.getOperand(0).getOperand(0).Val->hasOneUse()) {
789 ++FusedFP; // Statistic
790 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0).getOperand(0));
791 Tmp2 = SelectExpr(N.getOperand(0).getOperand(0).getOperand(1));
792 Tmp3 = SelectExpr(N.getOperand(0).getOperand(1));
793 Opc = DestType == MVT::f64 ? PPC::FNMSUB : PPC::FNMSUBS;
794 BuildMI(BB, Opc, 3, Result).addReg(Tmp1).addReg(Tmp2).addReg(Tmp3);
795 } else if (ISD::FABS == N.getOperand(0).getOpcode()) {
796 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
797 BuildMI(BB, PPC::FNABS, 1, Result).addReg(Tmp1);
798 } else {
799 Tmp1 = SelectExpr(N.getOperand(0));
800 BuildMI(BB, PPC::FNEG, 1, Result).addReg(Tmp1);
801 }
802 return Result;
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000803
Nate Begemand3e6b942005-04-05 08:51:15 +0000804 case ISD::FABS:
805 Tmp1 = SelectExpr(N.getOperand(0));
806 BuildMI(BB, PPC::FABS, 1, Result).addReg(Tmp1);
807 return Result;
808
809 case ISD::FP_ROUND:
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000810 assert (DestType == MVT::f32 &&
811 N.getOperand(0).getValueType() == MVT::f64 &&
Nate Begemand3e6b942005-04-05 08:51:15 +0000812 "only f64 to f32 conversion supported here");
813 Tmp1 = SelectExpr(N.getOperand(0));
814 BuildMI(BB, PPC::FRSP, 1, Result).addReg(Tmp1);
815 return Result;
816
817 case ISD::FP_EXTEND:
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000818 assert (DestType == MVT::f64 &&
819 N.getOperand(0).getValueType() == MVT::f32 &&
Nate Begemand3e6b942005-04-05 08:51:15 +0000820 "only f32 to f64 conversion supported here");
821 Tmp1 = SelectExpr(N.getOperand(0));
822 BuildMI(BB, PPC::FMR, 1, Result).addReg(Tmp1);
823 return Result;
824
825 case ISD::CopyFromReg:
826 if (Result == 1)
827 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
828 Tmp1 = dyn_cast<RegSDNode>(Node)->getReg();
829 BuildMI(BB, PPC::FMR, 1, Result).addReg(Tmp1);
830 return Result;
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000831
Nate Begemand3e6b942005-04-05 08:51:15 +0000832 case ISD::ConstantFP: {
833 ConstantFPSDNode *CN = cast<ConstantFPSDNode>(N);
834 Result = getConstDouble(CN->getValue(), Result);
835 return Result;
836 }
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000837
Nate Begemand3e6b942005-04-05 08:51:15 +0000838 case ISD::ADD:
839 if (!NoExcessFPPrecision && N.getOperand(0).getOpcode() == ISD::MUL &&
840 N.getOperand(0).Val->hasOneUse()) {
841 ++FusedFP; // Statistic
842 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
843 Tmp2 = SelectExpr(N.getOperand(0).getOperand(1));
844 Tmp3 = SelectExpr(N.getOperand(1));
845 Opc = DestType == MVT::f64 ? PPC::FMADD : PPC::FMADDS;
846 BuildMI(BB, Opc, 3, Result).addReg(Tmp1).addReg(Tmp2).addReg(Tmp3);
847 return Result;
848 }
849 Opc = DestType == MVT::f64 ? PPC::FADD : PPC::FADDS;
850 Tmp1 = SelectExpr(N.getOperand(0));
851 Tmp2 = SelectExpr(N.getOperand(1));
852 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
853 return Result;
854
855 case ISD::SUB:
856 if (!NoExcessFPPrecision && N.getOperand(0).getOpcode() == ISD::MUL &&
857 N.getOperand(0).Val->hasOneUse()) {
858 ++FusedFP; // Statistic
859 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
860 Tmp2 = SelectExpr(N.getOperand(0).getOperand(1));
861 Tmp3 = SelectExpr(N.getOperand(1));
862 Opc = DestType == MVT::f64 ? PPC::FMSUB : PPC::FMSUBS;
863 BuildMI(BB, Opc, 3, Result).addReg(Tmp1).addReg(Tmp2).addReg(Tmp3);
864 return Result;
865 }
866 Opc = DestType == MVT::f64 ? PPC::FSUB : PPC::FSUBS;
867 Tmp1 = SelectExpr(N.getOperand(0));
868 Tmp2 = SelectExpr(N.getOperand(1));
869 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
870 return Result;
871
872 case ISD::MUL:
873 case ISD::SDIV:
874 switch( opcode ) {
875 case ISD::MUL: Opc = DestType == MVT::f64 ? PPC::FMUL : PPC::FMULS; break;
876 case ISD::SDIV: Opc = DestType == MVT::f64 ? PPC::FDIV : PPC::FDIVS; break;
877 };
878 Tmp1 = SelectExpr(N.getOperand(0));
879 Tmp2 = SelectExpr(N.getOperand(1));
880 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
881 return Result;
882
883 case ISD::UINT_TO_FP:
884 case ISD::SINT_TO_FP: {
885 bool IsUnsigned = (ISD::UINT_TO_FP == opcode);
886 Tmp1 = SelectExpr(N.getOperand(0)); // Get the operand register
887 Tmp2 = MakeReg(MVT::f64); // temp reg to load the integer value into
888 Tmp3 = MakeReg(MVT::i64); // temp reg to hold the conversion constant
889 unsigned ConstF = MakeReg(MVT::f64); // temp reg to hold the fp constant
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000890
Nate Begemand3e6b942005-04-05 08:51:15 +0000891 int FrameIdx = BB->getParent()->getFrameInfo()->CreateStackObject(8, 8);
892 MachineConstantPool *CP = BB->getParent()->getConstantPool();
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000893
Nate Begemand3e6b942005-04-05 08:51:15 +0000894 // FIXME: pull this FP constant generation stuff out into something like
895 // the simple ISel's getReg.
896 if (IsUnsigned) {
897 addFrameReference(BuildMI(BB, PPC::STD, 3).addReg(Tmp1), FrameIdx);
898 addFrameReference(BuildMI(BB, PPC::LFD, 2, Tmp2), FrameIdx);
899 BuildMI(BB, PPC::FCFID, 1, Result).addReg(Tmp2);
900 } else {
901 ConstantFP *CFP = ConstantFP::get(Type::DoubleTy, 0x1.000008p52);
902 unsigned CPI = CP->getConstantPoolIndex(CFP);
903 // Load constant fp value
904 unsigned Tmp4 = MakeReg(MVT::i32);
905 unsigned TmpL = MakeReg(MVT::i32);
906 BuildMI(BB, PPC::LOADHiAddr, 2, Tmp4).addReg(getGlobalBaseReg())
907 .addConstantPoolIndex(CPI);
908 BuildMI(BB, PPC::LFD, 2, ConstF).addConstantPoolIndex(CPI).addReg(Tmp4);
909 // Store the hi & low halves of the fp value, currently in int regs
910 BuildMI(BB, PPC::LIS, 1, Tmp3).addSImm(0x4330);
911 addFrameReference(BuildMI(BB, PPC::STW, 3).addReg(Tmp3), FrameIdx);
912 BuildMI(BB, PPC::XORIS, 2, TmpL).addReg(Tmp1).addImm(0x8000);
913 addFrameReference(BuildMI(BB, PPC::STW, 3).addReg(TmpL), FrameIdx, 4);
914 addFrameReference(BuildMI(BB, PPC::LFD, 2, Tmp2), FrameIdx);
915 // Generate the return value with a subtract
916 BuildMI(BB, PPC::FSUB, 2, Result).addReg(Tmp2).addReg(ConstF);
917 }
918 return Result;
919 }
920 }
921 assert(0 && "Should never get here");
922 return 0;
923}
924
925unsigned ISel::SelectExpr(SDOperand N) {
926 unsigned Result;
927 unsigned Tmp1, Tmp2, Tmp3;
928 unsigned Opc = 0;
929 unsigned opcode = N.getOpcode();
930
931 SDNode *Node = N.Val;
932 MVT::ValueType DestType = N.getValueType();
933
934 unsigned &Reg = ExprMap[N];
935 if (Reg) return Reg;
936
937 switch (N.getOpcode()) {
938 default:
939 Reg = Result = (N.getValueType() != MVT::Other) ?
940 MakeReg(N.getValueType()) : 1;
941 break;
942 case ISD::CALL:
943 // If this is a call instruction, make sure to prepare ALL of the result
944 // values as well as the chain.
945 if (Node->getNumValues() == 1)
946 Reg = Result = 1; // Void call, just a chain.
947 else {
948 Result = MakeReg(Node->getValueType(0));
949 ExprMap[N.getValue(0)] = Result;
950 for (unsigned i = 1, e = N.Val->getNumValues()-1; i != e; ++i)
951 ExprMap[N.getValue(i)] = MakeReg(Node->getValueType(i));
952 ExprMap[SDOperand(Node, Node->getNumValues()-1)] = 1;
953 }
954 break;
955 }
956
957 if (ISD::CopyFromReg == opcode)
958 DestType = N.getValue(0).getValueType();
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000959
Nate Begemand3e6b942005-04-05 08:51:15 +0000960 if (DestType == MVT::f64 || DestType == MVT::f32)
961 if (ISD::LOAD != opcode && ISD::EXTLOAD != opcode && ISD::UNDEF != opcode)
962 return SelectExprFP(N, Result);
963
964 switch (opcode) {
965 default:
966 Node->dump();
967 assert(0 && "Node not handled!\n");
968 case ISD::UNDEF:
969 BuildMI(BB, PPC::IMPLICIT_DEF, 0, Result);
970 return Result;
971 case ISD::DYNAMIC_STACKALLOC:
972 // Generate both result values. FIXME: Need a better commment here?
973 if (Result != 1)
974 ExprMap[N.getValue(1)] = 1;
975 else
976 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
977
978 // FIXME: We are currently ignoring the requested alignment for handling
979 // greater than the stack alignment. This will need to be revisited at some
980 // point. Align = N.getOperand(2);
981 if (!isa<ConstantSDNode>(N.getOperand(2)) ||
982 cast<ConstantSDNode>(N.getOperand(2))->getValue() != 0) {
983 std::cerr << "Cannot allocate stack object with greater alignment than"
984 << " the stack alignment yet!";
985 abort();
986 }
987 Select(N.getOperand(0));
988 Tmp1 = SelectExpr(N.getOperand(1));
989 // Subtract size from stack pointer, thereby allocating some space.
990 BuildMI(BB, PPC::SUBF, 2, PPC::R1).addReg(Tmp1).addReg(PPC::R1);
991 // Put a pointer to the space into the result register by copying the SP
992 BuildMI(BB, PPC::OR, 2, Result).addReg(PPC::R1).addReg(PPC::R1);
993 return Result;
994
995 case ISD::ConstantPool:
996 Tmp1 = cast<ConstantPoolSDNode>(N)->getIndex();
997 Tmp2 = MakeReg(MVT::i64);
998 BuildMI(BB, PPC::LOADHiAddr, 2, Tmp2).addReg(getGlobalBaseReg())
999 .addConstantPoolIndex(Tmp1);
1000 BuildMI(BB, PPC::LA, 2, Result).addReg(Tmp2).addConstantPoolIndex(Tmp1);
1001 return Result;
1002
1003 case ISD::FrameIndex:
1004 Tmp1 = cast<FrameIndexSDNode>(N)->getIndex();
1005 addFrameReference(BuildMI(BB, PPC::ADDI, 2, Result), (int)Tmp1, 0, false);
1006 return Result;
Misha Brukmanb5f662f2005-04-21 23:30:14 +00001007
Nate Begemand3e6b942005-04-05 08:51:15 +00001008 case ISD::GlobalAddress: {
1009 GlobalValue *GV = cast<GlobalAddressSDNode>(N)->getGlobal();
1010 Tmp1 = MakeReg(MVT::i64);
1011 BuildMI(BB, PPC::LOADHiAddr, 2, Tmp1).addReg(getGlobalBaseReg())
1012 .addGlobalAddress(GV);
1013 if (GV->hasWeakLinkage() || GV->isExternal()) {
Nate Begemana9532d52005-04-08 23:45:01 +00001014 BuildMI(BB, PPC::LD, 2, Result).addGlobalAddress(GV).addReg(Tmp1);
Nate Begemand3e6b942005-04-05 08:51:15 +00001015 } else {
1016 BuildMI(BB, PPC::LA, 2, Result).addReg(Tmp1).addGlobalAddress(GV);
1017 }
1018 return Result;
1019 }
1020
1021 case ISD::LOAD:
1022 case ISD::EXTLOAD:
1023 case ISD::ZEXTLOAD:
1024 case ISD::SEXTLOAD: {
1025 MVT::ValueType TypeBeingLoaded = (ISD::LOAD == opcode) ?
1026 Node->getValueType(0) : cast<MVTSDNode>(Node)->getExtraValueType();
1027 bool sext = (ISD::SEXTLOAD == opcode);
Misha Brukmanb5f662f2005-04-21 23:30:14 +00001028
Nate Begemand3e6b942005-04-05 08:51:15 +00001029 // Make sure we generate both values.
1030 if (Result != 1)
1031 ExprMap[N.getValue(1)] = 1; // Generate the token
1032 else
1033 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
1034
1035 SDOperand Chain = N.getOperand(0);
1036 SDOperand Address = N.getOperand(1);
1037 Select(Chain);
1038
1039 switch (TypeBeingLoaded) {
1040 default: Node->dump(); assert(0 && "Cannot load this type!");
1041 case MVT::i1: Opc = PPC::LBZ; break;
1042 case MVT::i8: Opc = PPC::LBZ; break;
1043 case MVT::i16: Opc = sext ? PPC::LHA : PPC::LHZ; break;
1044 case MVT::i32: Opc = sext ? PPC::LWA : PPC::LWZ; break;
1045 case MVT::i64: Opc = PPC::LD; break;
1046 case MVT::f32: Opc = PPC::LFS; break;
1047 case MVT::f64: Opc = PPC::LFD; break;
1048 }
Misha Brukmanb5f662f2005-04-21 23:30:14 +00001049
Nate Begemand3e6b942005-04-05 08:51:15 +00001050 if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(Address)) {
1051 Tmp1 = MakeReg(MVT::i64);
1052 int CPI = CP->getIndex();
1053 BuildMI(BB, PPC::LOADHiAddr, 2, Tmp1).addReg(getGlobalBaseReg())
1054 .addConstantPoolIndex(CPI);
1055 BuildMI(BB, Opc, 2, Result).addConstantPoolIndex(CPI).addReg(Tmp1);
1056 }
1057 else if(Address.getOpcode() == ISD::FrameIndex) {
1058 Tmp1 = cast<FrameIndexSDNode>(Address)->getIndex();
1059 addFrameReference(BuildMI(BB, Opc, 2, Result), (int)Tmp1);
1060 } else {
1061 int offset;
1062 bool idx = SelectAddr(Address, Tmp1, offset);
1063 if (idx) {
1064 Opc = IndexedOpForOp(Opc);
1065 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(offset);
1066 } else {
1067 BuildMI(BB, Opc, 2, Result).addSImm(offset).addReg(Tmp1);
1068 }
1069 }
1070 return Result;
1071 }
Misha Brukmanb5f662f2005-04-21 23:30:14 +00001072
Nate Begemand3e6b942005-04-05 08:51:15 +00001073 case ISD::CALL: {
1074 unsigned GPR_idx = 0, FPR_idx = 0;
Misha Brukmanb5f662f2005-04-21 23:30:14 +00001075 static const unsigned GPR[] = {
Nate Begemand3e6b942005-04-05 08:51:15 +00001076 PPC::R3, PPC::R4, PPC::R5, PPC::R6,
1077 PPC::R7, PPC::R8, PPC::R9, PPC::R10,
1078 };
1079 static const unsigned FPR[] = {
1080 PPC::F1, PPC::F2, PPC::F3, PPC::F4, PPC::F5, PPC::F6, PPC::F7,
1081 PPC::F8, PPC::F9, PPC::F10, PPC::F11, PPC::F12, PPC::F13
1082 };
1083
1084 // Lower the chain for this call.
1085 Select(N.getOperand(0));
1086 ExprMap[N.getValue(Node->getNumValues()-1)] = 1;
1087
1088 MachineInstr *CallMI;
1089 // Emit the correct call instruction based on the type of symbol called.
Misha Brukmanb5f662f2005-04-21 23:30:14 +00001090 if (GlobalAddressSDNode *GASD =
Nate Begemand3e6b942005-04-05 08:51:15 +00001091 dyn_cast<GlobalAddressSDNode>(N.getOperand(1))) {
Misha Brukmanb5f662f2005-04-21 23:30:14 +00001092 CallMI = BuildMI(PPC::CALLpcrel, 1).addGlobalAddress(GASD->getGlobal(),
Nate Begemand3e6b942005-04-05 08:51:15 +00001093 true);
Misha Brukmanb5f662f2005-04-21 23:30:14 +00001094 } else if (ExternalSymbolSDNode *ESSDN =
Nate Begemand3e6b942005-04-05 08:51:15 +00001095 dyn_cast<ExternalSymbolSDNode>(N.getOperand(1))) {
Misha Brukmanb5f662f2005-04-21 23:30:14 +00001096 CallMI = BuildMI(PPC::CALLpcrel, 1).addExternalSymbol(ESSDN->getSymbol(),
Nate Begemand3e6b942005-04-05 08:51:15 +00001097 true);
1098 } else {
1099 Tmp1 = SelectExpr(N.getOperand(1));
1100 BuildMI(BB, PPC::OR, 2, PPC::R12).addReg(Tmp1).addReg(Tmp1);
1101 BuildMI(BB, PPC::MTCTR, 1).addReg(PPC::R12);
1102 CallMI = BuildMI(PPC::CALLindirect, 3).addImm(20).addImm(0)
1103 .addReg(PPC::R12);
1104 }
Misha Brukmanb5f662f2005-04-21 23:30:14 +00001105
Nate Begemand3e6b942005-04-05 08:51:15 +00001106 // Load the register args to virtual regs
1107 std::vector<unsigned> ArgVR;
1108 for(int i = 2, e = Node->getNumOperands(); i < e; ++i)
1109 ArgVR.push_back(SelectExpr(N.getOperand(i)));
1110
1111 // Copy the virtual registers into the appropriate argument register
1112 for(int i = 0, e = ArgVR.size(); i < e; ++i) {
1113 switch(N.getOperand(i+2).getValueType()) {
1114 default: Node->dump(); assert(0 && "Unknown value type for call");
1115 case MVT::i1:
1116 case MVT::i8:
1117 case MVT::i16:
1118 case MVT::i32:
1119 case MVT::i64:
1120 assert(GPR_idx < 8 && "Too many int args");
1121 if (N.getOperand(i+2).getOpcode() != ISD::UNDEF) {
1122 BuildMI(BB, PPC::OR,2,GPR[GPR_idx]).addReg(ArgVR[i]).addReg(ArgVR[i]);
1123 CallMI->addRegOperand(GPR[GPR_idx], MachineOperand::Use);
1124 }
1125 ++GPR_idx;
1126 break;
1127 case MVT::f64:
1128 case MVT::f32:
1129 assert(FPR_idx < 13 && "Too many fp args");
1130 BuildMI(BB, PPC::FMR, 1, FPR[FPR_idx]).addReg(ArgVR[i]);
1131 CallMI->addRegOperand(FPR[FPR_idx], MachineOperand::Use);
1132 ++FPR_idx;
1133 break;
1134 }
1135 }
Misha Brukmanb5f662f2005-04-21 23:30:14 +00001136
Nate Begemand3e6b942005-04-05 08:51:15 +00001137 // Put the call instruction in the correct place in the MachineBasicBlock
1138 BB->push_back(CallMI);
1139
1140 switch (Node->getValueType(0)) {
1141 default: assert(0 && "Unknown value type for call result!");
1142 case MVT::Other: return 1;
1143 case MVT::i1:
1144 case MVT::i8:
1145 case MVT::i16:
1146 case MVT::i32:
1147 case MVT::i64:
1148 BuildMI(BB, PPC::OR, 2, Result).addReg(PPC::R3).addReg(PPC::R3);
1149 break;
1150 case MVT::f32:
1151 case MVT::f64:
1152 BuildMI(BB, PPC::FMR, 1, Result).addReg(PPC::F1);
1153 break;
1154 }
1155 return Result+N.ResNo;
1156 }
1157
1158 case ISD::SIGN_EXTEND:
1159 case ISD::SIGN_EXTEND_INREG:
1160 Tmp1 = SelectExpr(N.getOperand(0));
1161 switch(cast<MVTSDNode>(Node)->getExtraValueType()) {
1162 default: Node->dump(); assert(0 && "Unhandled SIGN_EXTEND type"); break;
1163 case MVT::i32:
Misha Brukmanb5f662f2005-04-21 23:30:14 +00001164 BuildMI(BB, PPC::EXTSW, 1, Result).addReg(Tmp1);
Nate Begemand3e6b942005-04-05 08:51:15 +00001165 break;
1166 case MVT::i16:
Misha Brukmanb5f662f2005-04-21 23:30:14 +00001167 BuildMI(BB, PPC::EXTSH, 1, Result).addReg(Tmp1);
Nate Begemand3e6b942005-04-05 08:51:15 +00001168 break;
1169 case MVT::i8:
Misha Brukmanb5f662f2005-04-21 23:30:14 +00001170 BuildMI(BB, PPC::EXTSB, 1, Result).addReg(Tmp1);
Nate Begemand3e6b942005-04-05 08:51:15 +00001171 break;
1172 case MVT::i1:
1173 BuildMI(BB, PPC::SUBFIC, 2, Result).addReg(Tmp1).addSImm(0);
1174 break;
1175 }
1176 return Result;
Misha Brukmanb5f662f2005-04-21 23:30:14 +00001177
Nate Begemand3e6b942005-04-05 08:51:15 +00001178 case ISD::CopyFromReg:
1179 if (Result == 1)
1180 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
1181 Tmp1 = dyn_cast<RegSDNode>(Node)->getReg();
1182 BuildMI(BB, PPC::OR, 2, Result).addReg(Tmp1).addReg(Tmp1);
1183 return Result;
1184
1185 case ISD::SHL:
1186 Tmp1 = SelectExpr(N.getOperand(0));
1187 if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Nate Begemana9532d52005-04-08 23:45:01 +00001188 Tmp2 = CN->getValue() & 0x3F;
1189 BuildMI(BB, PPC::RLDICR, 3, Result).addReg(Tmp1).addImm(Tmp2)
1190 .addImm(63-Tmp2);
Nate Begemand3e6b942005-04-05 08:51:15 +00001191 } else {
1192 Tmp2 = SelectExpr(N.getOperand(1));
Nate Begemana9532d52005-04-08 23:45:01 +00001193 BuildMI(BB, PPC::SLD, 2, Result).addReg(Tmp1).addReg(Tmp2);
Nate Begemand3e6b942005-04-05 08:51:15 +00001194 }
1195 return Result;
Misha Brukmanb5f662f2005-04-21 23:30:14 +00001196
Nate Begemand3e6b942005-04-05 08:51:15 +00001197 case ISD::SRL:
1198 Tmp1 = SelectExpr(N.getOperand(0));
1199 if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Nate Begemana9532d52005-04-08 23:45:01 +00001200 Tmp2 = CN->getValue() & 0x3F;
1201 BuildMI(BB, PPC::RLDICL, 3, Result).addReg(Tmp1).addImm(64-Tmp2)
1202 .addImm(Tmp2);
Nate Begemand3e6b942005-04-05 08:51:15 +00001203 } else {
1204 Tmp2 = SelectExpr(N.getOperand(1));
Nate Begemana9532d52005-04-08 23:45:01 +00001205 BuildMI(BB, PPC::SRD, 2, Result).addReg(Tmp1).addReg(Tmp2);
Nate Begemand3e6b942005-04-05 08:51:15 +00001206 }
1207 return Result;
Misha Brukmanb5f662f2005-04-21 23:30:14 +00001208
Nate Begemand3e6b942005-04-05 08:51:15 +00001209 case ISD::SRA:
1210 Tmp1 = SelectExpr(N.getOperand(0));
1211 if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Nate Begemana9532d52005-04-08 23:45:01 +00001212 Tmp2 = CN->getValue() & 0x3F;
1213 BuildMI(BB, PPC::SRADI, 2, Result).addReg(Tmp1).addImm(Tmp2);
Nate Begemand3e6b942005-04-05 08:51:15 +00001214 } else {
1215 Tmp2 = SelectExpr(N.getOperand(1));
Nate Begemana9532d52005-04-08 23:45:01 +00001216 BuildMI(BB, PPC::SRAD, 2, Result).addReg(Tmp1).addReg(Tmp2);
Nate Begemand3e6b942005-04-05 08:51:15 +00001217 }
1218 return Result;
Misha Brukmanb5f662f2005-04-21 23:30:14 +00001219
Nate Begemand3e6b942005-04-05 08:51:15 +00001220 case ISD::ADD:
1221 Tmp1 = SelectExpr(N.getOperand(0));
1222 switch(getImmediateForOpcode(N.getOperand(1), opcode, Tmp2)) {
1223 default: assert(0 && "unhandled result code");
1224 case 0: // No immediate
1225 Tmp2 = SelectExpr(N.getOperand(1));
1226 BuildMI(BB, PPC::ADD, 2, Result).addReg(Tmp1).addReg(Tmp2);
1227 break;
1228 case 1: // Low immediate
1229 BuildMI(BB, PPC::ADDI, 2, Result).addReg(Tmp1).addSImm(Tmp2);
1230 break;
1231 case 2: // Shifted immediate
1232 BuildMI(BB, PPC::ADDIS, 2, Result).addReg(Tmp1).addSImm(Tmp2);
1233 break;
1234 }
1235 return Result;
1236
1237 case ISD::AND:
1238 case ISD::OR:
1239 Tmp1 = SelectExpr(N.getOperand(0));
1240 switch(getImmediateForOpcode(N.getOperand(1), opcode, Tmp2)) {
1241 default: assert(0 && "unhandled result code");
1242 case 0: // No immediate
1243 Tmp2 = SelectExpr(N.getOperand(1));
1244 switch (opcode) {
1245 case ISD::AND: Opc = PPC::AND; break;
1246 case ISD::OR: Opc = PPC::OR; break;
1247 }
1248 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
1249 break;
1250 case 1: // Low immediate
1251 switch (opcode) {
1252 case ISD::AND: Opc = PPC::ANDIo; break;
1253 case ISD::OR: Opc = PPC::ORI; break;
1254 }
1255 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(Tmp2);
1256 break;
1257 case 2: // Shifted immediate
1258 switch (opcode) {
1259 case ISD::AND: Opc = PPC::ANDISo; break;
1260 case ISD::OR: Opc = PPC::ORIS; break;
1261 }
1262 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(Tmp2);
1263 break;
1264 }
1265 return Result;
1266
1267 case ISD::XOR: {
1268 // Check for EQV: xor, (xor a, -1), b
1269 if (N.getOperand(0).getOpcode() == ISD::XOR &&
1270 N.getOperand(0).getOperand(1).getOpcode() == ISD::Constant &&
1271 cast<ConstantSDNode>(N.getOperand(0).getOperand(1))->isAllOnesValue()) {
1272 ++NotLogic;
1273 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
1274 Tmp2 = SelectExpr(N.getOperand(1));
1275 BuildMI(BB, PPC::EQV, 2, Result).addReg(Tmp1).addReg(Tmp2);
1276 return Result;
1277 }
1278 // Check for NOT, NOR, and NAND: xor (copy, or, and), -1
1279 if (N.getOperand(1).getOpcode() == ISD::Constant &&
1280 cast<ConstantSDNode>(N.getOperand(1))->isAllOnesValue()) {
1281 ++NotLogic;
1282 switch(N.getOperand(0).getOpcode()) {
1283 case ISD::OR:
1284 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
1285 Tmp2 = SelectExpr(N.getOperand(0).getOperand(1));
1286 BuildMI(BB, PPC::NOR, 2, Result).addReg(Tmp1).addReg(Tmp2);
1287 break;
1288 case ISD::AND:
1289 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
1290 Tmp2 = SelectExpr(N.getOperand(0).getOperand(1));
1291 BuildMI(BB, PPC::NAND, 2, Result).addReg(Tmp1).addReg(Tmp2);
1292 break;
1293 default:
1294 Tmp1 = SelectExpr(N.getOperand(0));
1295 BuildMI(BB, PPC::NOR, 2, Result).addReg(Tmp1).addReg(Tmp1);
1296 break;
1297 }
1298 return Result;
1299 }
1300 Tmp1 = SelectExpr(N.getOperand(0));
1301 switch(getImmediateForOpcode(N.getOperand(1), opcode, Tmp2)) {
1302 default: assert(0 && "unhandled result code");
1303 case 0: // No immediate
1304 Tmp2 = SelectExpr(N.getOperand(1));
1305 BuildMI(BB, PPC::XOR, 2, Result).addReg(Tmp1).addReg(Tmp2);
1306 break;
1307 case 1: // Low immediate
1308 BuildMI(BB, PPC::XORI, 2, Result).addReg(Tmp1).addImm(Tmp2);
1309 break;
1310 case 2: // Shifted immediate
1311 BuildMI(BB, PPC::XORIS, 2, Result).addReg(Tmp1).addImm(Tmp2);
1312 break;
1313 }
1314 return Result;
1315 }
1316
1317 case ISD::SUB:
1318 Tmp2 = SelectExpr(N.getOperand(1));
1319 if (1 == getImmediateForOpcode(N.getOperand(0), opcode, Tmp1))
1320 BuildMI(BB, PPC::SUBFIC, 2, Result).addReg(Tmp2).addSImm(Tmp1);
1321 else {
1322 Tmp1 = SelectExpr(N.getOperand(0));
1323 BuildMI(BB, PPC::SUBF, 2, Result).addReg(Tmp2).addReg(Tmp1);
1324 }
1325 return Result;
Misha Brukmanb5f662f2005-04-21 23:30:14 +00001326
Nate Begemand3e6b942005-04-05 08:51:15 +00001327 case ISD::MUL:
1328 Tmp1 = SelectExpr(N.getOperand(0));
1329 if (1 == getImmediateForOpcode(N.getOperand(1), opcode, Tmp2))
1330 BuildMI(BB, PPC::MULLI, 2, Result).addReg(Tmp1).addSImm(Tmp2);
1331 else {
1332 Tmp2 = SelectExpr(N.getOperand(1));
1333 BuildMI(BB, PPC::MULLD, 2, Result).addReg(Tmp1).addReg(Tmp2);
1334 }
1335 return Result;
1336
1337 case ISD::SDIV:
1338 case ISD::UDIV:
1339 if (3 == getImmediateForOpcode(N.getOperand(1), opcode, Tmp3)) {
1340 Tmp1 = MakeReg(MVT::i64);
1341 Tmp2 = SelectExpr(N.getOperand(0));
Nate Begemana9532d52005-04-08 23:45:01 +00001342 BuildMI(BB, PPC::SRADI, 2, Tmp1).addReg(Tmp2).addImm(Tmp3);
Nate Begemand3e6b942005-04-05 08:51:15 +00001343 BuildMI(BB, PPC::ADDZE, 1, Result).addReg(Tmp1);
1344 return Result;
1345 }
1346 Tmp1 = SelectExpr(N.getOperand(0));
1347 Tmp2 = SelectExpr(N.getOperand(1));
1348 Opc = (ISD::UDIV == opcode) ? PPC::DIVWU : PPC::DIVW;
1349 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
1350 return Result;
1351
Nate Begemand3e6b942005-04-05 08:51:15 +00001352 case ISD::FP_TO_UINT:
1353 case ISD::FP_TO_SINT: {
Nate Begemand3e6b942005-04-05 08:51:15 +00001354 Tmp1 = SelectExpr(N.getOperand(0));
Nate Begemana3829d52005-04-05 17:32:30 +00001355 Tmp2 = MakeReg(MVT::f64);
1356 BuildMI(BB, PPC::FCTIDZ, 1, Tmp2).addReg(Tmp1);
1357 int FrameIdx = BB->getParent()->getFrameInfo()->CreateStackObject(8, 8);
1358 addFrameReference(BuildMI(BB, PPC::STFD, 3).addReg(Tmp2), FrameIdx);
1359 addFrameReference(BuildMI(BB, PPC::LD, 2, Result), FrameIdx);
1360 return Result;
Nate Begemand3e6b942005-04-05 08:51:15 +00001361 }
Misha Brukmanb5f662f2005-04-21 23:30:14 +00001362
Nate Begemand3e6b942005-04-05 08:51:15 +00001363 case ISD::SETCC:
1364 if (SetCCSDNode *SetCC = dyn_cast<SetCCSDNode>(Node)) {
1365 Opc = SelectSetCR0(N);
Misha Brukmanb5f662f2005-04-21 23:30:14 +00001366
Nate Begemand3e6b942005-04-05 08:51:15 +00001367 unsigned TrueValue = MakeReg(MVT::i32);
1368 BuildMI(BB, PPC::LI, 1, TrueValue).addSImm(1);
1369 unsigned FalseValue = MakeReg(MVT::i32);
1370 BuildMI(BB, PPC::LI, 1, FalseValue).addSImm(0);
1371
Misha Brukmanb5f662f2005-04-21 23:30:14 +00001372 // Create an iterator with which to insert the MBB for copying the false
Nate Begemand3e6b942005-04-05 08:51:15 +00001373 // value and the MBB to hold the PHI instruction for this SetCC.
1374 MachineBasicBlock *thisMBB = BB;
1375 const BasicBlock *LLVM_BB = BB->getBasicBlock();
1376 ilist<MachineBasicBlock>::iterator It = BB;
1377 ++It;
Misha Brukmanb5f662f2005-04-21 23:30:14 +00001378
Nate Begemand3e6b942005-04-05 08:51:15 +00001379 // thisMBB:
1380 // ...
1381 // cmpTY cr0, r1, r2
1382 // %TrueValue = li 1
1383 // bCC sinkMBB
1384 MachineBasicBlock *copy0MBB = new MachineBasicBlock(LLVM_BB);
1385 MachineBasicBlock *sinkMBB = new MachineBasicBlock(LLVM_BB);
1386 BuildMI(BB, Opc, 2).addReg(PPC::CR0).addMBB(sinkMBB);
1387 MachineFunction *F = BB->getParent();
1388 F->getBasicBlockList().insert(It, copy0MBB);
1389 F->getBasicBlockList().insert(It, sinkMBB);
1390 // Update machine-CFG edges
1391 BB->addSuccessor(copy0MBB);
1392 BB->addSuccessor(sinkMBB);
1393
1394 // copy0MBB:
1395 // %FalseValue = li 0
1396 // fallthrough
1397 BB = copy0MBB;
1398 // Update machine-CFG edges
1399 BB->addSuccessor(sinkMBB);
1400
1401 // sinkMBB:
1402 // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ]
1403 // ...
1404 BB = sinkMBB;
1405 BuildMI(BB, PPC::PHI, 4, Result).addReg(FalseValue)
1406 .addMBB(copy0MBB).addReg(TrueValue).addMBB(thisMBB);
1407 return Result;
1408 }
1409 assert(0 && "Is this legal?");
1410 return 0;
Misha Brukmanb5f662f2005-04-21 23:30:14 +00001411
Nate Begemand3e6b942005-04-05 08:51:15 +00001412 case ISD::SELECT: {
1413 unsigned TrueValue = SelectExpr(N.getOperand(1)); //Use if TRUE
1414 unsigned FalseValue = SelectExpr(N.getOperand(2)); //Use if FALSE
1415 Opc = SelectSetCR0(N.getOperand(0));
1416
Misha Brukmanb5f662f2005-04-21 23:30:14 +00001417 // Create an iterator with which to insert the MBB for copying the false
Nate Begemand3e6b942005-04-05 08:51:15 +00001418 // value and the MBB to hold the PHI instruction for this SetCC.
1419 MachineBasicBlock *thisMBB = BB;
1420 const BasicBlock *LLVM_BB = BB->getBasicBlock();
1421 ilist<MachineBasicBlock>::iterator It = BB;
1422 ++It;
1423
1424 // thisMBB:
1425 // ...
1426 // TrueVal = ...
1427 // cmpTY cr0, r1, r2
1428 // bCC copy1MBB
1429 // fallthrough --> copy0MBB
1430 MachineBasicBlock *copy0MBB = new MachineBasicBlock(LLVM_BB);
1431 MachineBasicBlock *sinkMBB = new MachineBasicBlock(LLVM_BB);
1432 BuildMI(BB, Opc, 2).addReg(PPC::CR0).addMBB(sinkMBB);
1433 MachineFunction *F = BB->getParent();
1434 F->getBasicBlockList().insert(It, copy0MBB);
1435 F->getBasicBlockList().insert(It, sinkMBB);
1436 // Update machine-CFG edges
1437 BB->addSuccessor(copy0MBB);
1438 BB->addSuccessor(sinkMBB);
1439
1440 // copy0MBB:
1441 // %FalseValue = ...
1442 // # fallthrough to sinkMBB
1443 BB = copy0MBB;
1444 // Update machine-CFG edges
1445 BB->addSuccessor(sinkMBB);
1446
1447 // sinkMBB:
1448 // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ]
1449 // ...
1450 BB = sinkMBB;
1451 BuildMI(BB, PPC::PHI, 4, Result).addReg(FalseValue)
1452 .addMBB(copy0MBB).addReg(TrueValue).addMBB(thisMBB);
1453
1454 // FIXME: Select i64?
1455 return Result;
1456 }
1457
1458 case ISD::Constant:
1459 switch (N.getValueType()) {
1460 default: assert(0 && "Cannot use constants of this type!");
1461 case MVT::i1:
1462 BuildMI(BB, PPC::LI, 1, Result)
1463 .addSImm(!cast<ConstantSDNode>(N)->isNullValue());
1464 break;
1465 case MVT::i32:
1466 {
1467 int v = (int)cast<ConstantSDNode>(N)->getSignExtended();
1468 if (v < 32768 && v >= -32768) {
1469 BuildMI(BB, PPC::LI, 1, Result).addSImm(v);
1470 } else {
1471 Tmp1 = MakeReg(MVT::i32);
1472 BuildMI(BB, PPC::LIS, 1, Tmp1).addSImm(v >> 16);
1473 BuildMI(BB, PPC::ORI, 2, Result).addReg(Tmp1).addImm(v & 0xFFFF);
1474 }
1475 }
1476 }
1477 return Result;
1478 }
1479
1480 return 0;
1481}
1482
1483void ISel::Select(SDOperand N) {
1484 unsigned Tmp1, Tmp2, Opc;
1485 unsigned opcode = N.getOpcode();
1486
1487 if (!ExprMap.insert(std::make_pair(N, 1)).second)
1488 return; // Already selected.
1489
1490 SDNode *Node = N.Val;
Misha Brukmanb5f662f2005-04-21 23:30:14 +00001491
Nate Begemand3e6b942005-04-05 08:51:15 +00001492 switch (Node->getOpcode()) {
1493 default:
1494 Node->dump(); std::cerr << "\n";
1495 assert(0 && "Node not handled yet!");
1496 case ISD::EntryToken: return; // Noop
1497 case ISD::TokenFactor:
1498 for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i)
1499 Select(Node->getOperand(i));
1500 return;
Chris Lattner16cd04d2005-05-12 23:24:06 +00001501 case ISD::CALLSEQ_START:
1502 case ISD::CALLSEQ_END:
Nate Begemand3e6b942005-04-05 08:51:15 +00001503 Select(N.getOperand(0));
1504 Tmp1 = cast<ConstantSDNode>(N.getOperand(1))->getValue();
Chris Lattner16cd04d2005-05-12 23:24:06 +00001505 Opc = N.getOpcode() == ISD::CALLSEQ_START ? PPC::ADJCALLSTACKDOWN :
Nate Begemand3e6b942005-04-05 08:51:15 +00001506 PPC::ADJCALLSTACKUP;
1507 BuildMI(BB, Opc, 1).addImm(Tmp1);
1508 return;
1509 case ISD::BR: {
1510 MachineBasicBlock *Dest =
1511 cast<BasicBlockSDNode>(N.getOperand(1))->getBasicBlock();
1512 Select(N.getOperand(0));
1513 BuildMI(BB, PPC::B, 1).addMBB(Dest);
1514 return;
1515 }
Misha Brukmanb5f662f2005-04-21 23:30:14 +00001516 case ISD::BRCOND:
Nate Begemand3e6b942005-04-05 08:51:15 +00001517 SelectBranchCC(N);
1518 return;
1519 case ISD::CopyToReg:
1520 Select(N.getOperand(0));
1521 Tmp1 = SelectExpr(N.getOperand(1));
1522 Tmp2 = cast<RegSDNode>(N)->getReg();
Misha Brukmanb5f662f2005-04-21 23:30:14 +00001523
Nate Begemand3e6b942005-04-05 08:51:15 +00001524 if (Tmp1 != Tmp2) {
Misha Brukmanb5f662f2005-04-21 23:30:14 +00001525 if (N.getOperand(1).getValueType() == MVT::f64 ||
Nate Begemand3e6b942005-04-05 08:51:15 +00001526 N.getOperand(1).getValueType() == MVT::f32)
1527 BuildMI(BB, PPC::FMR, 1, Tmp2).addReg(Tmp1);
1528 else
1529 BuildMI(BB, PPC::OR, 2, Tmp2).addReg(Tmp1).addReg(Tmp1);
1530 }
1531 return;
1532 case ISD::ImplicitDef:
1533 Select(N.getOperand(0));
1534 BuildMI(BB, PPC::IMPLICIT_DEF, 0, cast<RegSDNode>(N)->getReg());
1535 return;
1536 case ISD::RET:
1537 switch (N.getNumOperands()) {
1538 default:
1539 assert(0 && "Unknown return instruction!");
1540 case 3:
1541 assert(N.getOperand(1).getValueType() == MVT::i32 &&
1542 N.getOperand(2).getValueType() == MVT::i32 &&
Misha Brukman7847fca2005-04-22 17:54:37 +00001543 "Unknown two-register value!");
Nate Begemand3e6b942005-04-05 08:51:15 +00001544 Select(N.getOperand(0));
1545 Tmp1 = SelectExpr(N.getOperand(1));
1546 Tmp2 = SelectExpr(N.getOperand(2));
1547 BuildMI(BB, PPC::OR, 2, PPC::R3).addReg(Tmp2).addReg(Tmp2);
1548 BuildMI(BB, PPC::OR, 2, PPC::R4).addReg(Tmp1).addReg(Tmp1);
1549 break;
1550 case 2:
1551 Select(N.getOperand(0));
1552 Tmp1 = SelectExpr(N.getOperand(1));
1553 switch (N.getOperand(1).getValueType()) {
1554 default:
1555 assert(0 && "Unknown return type!");
1556 case MVT::f64:
1557 case MVT::f32:
1558 BuildMI(BB, PPC::FMR, 1, PPC::F1).addReg(Tmp1);
1559 break;
1560 case MVT::i32:
1561 BuildMI(BB, PPC::OR, 2, PPC::R3).addReg(Tmp1).addReg(Tmp1);
1562 break;
1563 }
1564 case 1:
1565 Select(N.getOperand(0));
1566 break;
1567 }
1568 BuildMI(BB, PPC::BLR, 0); // Just emit a 'ret' instruction
1569 return;
Misha Brukmanb5f662f2005-04-21 23:30:14 +00001570 case ISD::TRUNCSTORE:
1571 case ISD::STORE:
Nate Begemand3e6b942005-04-05 08:51:15 +00001572 {
1573 SDOperand Chain = N.getOperand(0);
1574 SDOperand Value = N.getOperand(1);
1575 SDOperand Address = N.getOperand(2);
1576 Select(Chain);
1577
1578 Tmp1 = SelectExpr(Value); //value
1579
1580 if (opcode == ISD::STORE) {
1581 switch(Value.getValueType()) {
1582 default: assert(0 && "unknown Type in store");
1583 case MVT::i64: Opc = PPC::STD; break;
1584 case MVT::f64: Opc = PPC::STFD; break;
1585 case MVT::f32: Opc = PPC::STFS; break;
1586 }
1587 } else { //ISD::TRUNCSTORE
1588 switch(cast<MVTSDNode>(Node)->getExtraValueType()) {
1589 default: assert(0 && "unknown Type in store");
1590 case MVT::i1: //FIXME: DAG does not promote this load
1591 case MVT::i8: Opc= PPC::STB; break;
1592 case MVT::i16: Opc = PPC::STH; break;
1593 case MVT::i32: Opc = PPC::STW; break;
1594 }
1595 }
1596
1597 if(Address.getOpcode() == ISD::FrameIndex)
1598 {
1599 Tmp2 = cast<FrameIndexSDNode>(Address)->getIndex();
1600 addFrameReference(BuildMI(BB, Opc, 3).addReg(Tmp1), (int)Tmp2);
1601 }
1602 else
1603 {
1604 int offset;
1605 bool idx = SelectAddr(Address, Tmp2, offset);
Misha Brukmanb5f662f2005-04-21 23:30:14 +00001606 if (idx) {
Nate Begemand3e6b942005-04-05 08:51:15 +00001607 Opc = IndexedOpForOp(Opc);
1608 BuildMI(BB, Opc, 3).addReg(Tmp1).addReg(Tmp2).addReg(offset);
1609 } else {
1610 BuildMI(BB, Opc, 3).addReg(Tmp1).addImm(offset).addReg(Tmp2);
1611 }
1612 }
1613 return;
1614 }
1615 case ISD::EXTLOAD:
1616 case ISD::SEXTLOAD:
1617 case ISD::ZEXTLOAD:
1618 case ISD::LOAD:
1619 case ISD::CopyFromReg:
1620 case ISD::CALL:
1621 case ISD::DYNAMIC_STACKALLOC:
1622 ExprMap.erase(N);
1623 SelectExpr(N);
1624 return;
1625 }
1626 assert(0 && "Should not be reached!");
1627}
1628
1629
1630/// createPPC32PatternInstructionSelector - This pass converts an LLVM function
1631/// into a machine code representation using pattern matching and a machine
1632/// description file.
1633///
1634FunctionPass *llvm::createPPC64ISelPattern(TargetMachine &TM) {
Misha Brukmanb5f662f2005-04-21 23:30:14 +00001635 return new ISel(TM);
Nate Begemand3e6b942005-04-05 08:51:15 +00001636}
1637