blob: 451ff031c6b38a06368a2cf908ba6a91ac1759c6 [file] [log] [blame]
Nate Begemana9795f82005-03-24 04:41:43 +00001//===-- PPC32ISelPattern.cpp - A pattern matching inst selector for PPC32 -===//
2//
3// The LLVM Compiler Infrastructure
4//
Nate Begeman5e966612005-03-24 06:28:42 +00005// This file was developed by Nate Begeman and is distributed under
Nate Begemana9795f82005-03-24 04:41:43 +00006// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines a pattern matching instruction selector for 32 bit PowerPC.
11//
12//===----------------------------------------------------------------------===//
13
14#include "PowerPC.h"
15#include "PowerPCInstrBuilder.h"
16#include "PowerPCInstrInfo.h"
17#include "PPC32RegisterInfo.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/Support/Debug.h"
29#include "llvm/Support/MathExtras.h"
30#include "llvm/ADT/Statistic.h"
31#include <set>
32#include <algorithm>
33using namespace llvm;
34
35//===----------------------------------------------------------------------===//
36// PPC32TargetLowering - PPC32 Implementation of the TargetLowering interface
37namespace {
38 class PPC32TargetLowering : public TargetLowering {
39 int VarArgsFrameIndex; // FrameIndex for start of varargs area.
40 int ReturnAddrIndex; // FrameIndex for return slot.
41 public:
42 PPC32TargetLowering(TargetMachine &TM) : TargetLowering(TM) {
43 // Set up the TargetLowering object.
44
45 // Set up the register classes.
46 addRegisterClass(MVT::i32, PPC32::GPRCRegisterClass);
Nate Begeman7532e2f2005-03-26 08:25:22 +000047 addRegisterClass(MVT::f32, PPC32::FPRCRegisterClass);
Nate Begemana9795f82005-03-24 04:41:43 +000048 addRegisterClass(MVT::f64, PPC32::FPRCRegisterClass);
49
Nate Begeman01d05262005-03-30 01:45:43 +000050 setOperationAction(ISD::MEMMOVE, MVT::Other, Expand);
51 setOperationAction(ISD::MEMSET, MVT::Other, Expand);
52 setOperationAction(ISD::MEMCPY, MVT::Other, Expand);
53
Nate Begemana9795f82005-03-24 04:41:43 +000054 computeRegisterProperties();
55 }
56
57 /// LowerArguments - This hook must be implemented to indicate how we should
58 /// lower the arguments for the specified function, into the specified DAG.
59 virtual std::vector<SDOperand>
60 LowerArguments(Function &F, SelectionDAG &DAG);
61
62 /// LowerCallTo - This hook lowers an abstract call to a function into an
63 /// actual call.
64 virtual std::pair<SDOperand, SDOperand>
Nate Begeman307e7442005-03-26 01:28:53 +000065 LowerCallTo(SDOperand Chain, const Type *RetTy, bool isVarArg,
66 SDOperand Callee, ArgListTy &Args, SelectionDAG &DAG);
Nate Begemana9795f82005-03-24 04:41:43 +000067
68 virtual std::pair<SDOperand, SDOperand>
69 LowerVAStart(SDOperand Chain, SelectionDAG &DAG);
70
71 virtual std::pair<SDOperand,SDOperand>
72 LowerVAArgNext(bool isVANext, SDOperand Chain, SDOperand VAList,
73 const Type *ArgTy, SelectionDAG &DAG);
74
75 virtual std::pair<SDOperand, SDOperand>
76 LowerFrameReturnAddress(bool isFrameAddr, SDOperand Chain, unsigned Depth,
77 SelectionDAG &DAG);
78 };
79}
80
81
82std::vector<SDOperand>
83PPC32TargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) {
84 //
85 // add beautiful description of PPC stack frame format, or at least some docs
86 //
87 MachineFunction &MF = DAG.getMachineFunction();
88 MachineFrameInfo *MFI = MF.getFrameInfo();
89 MachineBasicBlock& BB = MF.front();
90 std::vector<SDOperand> ArgValues;
91
92 // Due to the rather complicated nature of the PowerPC ABI, rather than a
93 // fixed size array of physical args, for the sake of simplicity let the STL
94 // handle tracking them for us.
95 std::vector<unsigned> argVR, argPR, argOp;
96 unsigned ArgOffset = 24;
97 unsigned GPR_remaining = 8;
98 unsigned FPR_remaining = 13;
99 unsigned GPR_idx = 0, FPR_idx = 0;
100 static const unsigned GPR[] = {
101 PPC::R3, PPC::R4, PPC::R5, PPC::R6,
102 PPC::R7, PPC::R8, PPC::R9, PPC::R10,
103 };
104 static const unsigned FPR[] = {
105 PPC::F1, PPC::F2, PPC::F3, PPC::F4, PPC::F5, PPC::F6, PPC::F7,
106 PPC::F8, PPC::F9, PPC::F10, PPC::F11, PPC::F12, PPC::F13
107 };
108
109 // Add DAG nodes to load the arguments... On entry to a function on PPC,
110 // the arguments start at offset 24, although they are likely to be passed
111 // in registers.
112 for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; ++I) {
113 SDOperand newroot, argt;
114 unsigned ObjSize;
115 bool needsLoad = false;
116 MVT::ValueType ObjectVT = getValueType(I->getType());
117
118 switch (ObjectVT) {
119 default: assert(0 && "Unhandled argument type!");
120 case MVT::i1:
121 case MVT::i8:
122 case MVT::i16:
123 case MVT::i32:
124 ObjSize = 4;
125 if (GPR_remaining > 0) {
126 BuildMI(&BB, PPC::IMPLICIT_DEF, 0, GPR[GPR_idx]);
Nate Begemanf70b5762005-03-28 23:08:54 +0000127 argt = newroot = DAG.getCopyFromReg(GPR[GPR_idx], MVT::i32,
128 DAG.getRoot());
Nate Begemana9795f82005-03-24 04:41:43 +0000129 if (ObjectVT != MVT::i32)
130 argt = DAG.getNode(ISD::TRUNCATE, ObjectVT, newroot);
Nate Begemana9795f82005-03-24 04:41:43 +0000131 } else {
132 needsLoad = true;
133 }
134 break;
Nate Begemanf7e43382005-03-26 07:46:36 +0000135 case MVT::i64: ObjSize = 8;
136 // FIXME: can split 64b load between reg/mem if it is last arg in regs
Nate Begemana9795f82005-03-24 04:41:43 +0000137 if (GPR_remaining > 1) {
138 BuildMI(&BB, PPC::IMPLICIT_DEF, 0, GPR[GPR_idx]);
139 BuildMI(&BB, PPC::IMPLICIT_DEF, 0, GPR[GPR_idx+1]);
Nate Begemanca12a2b2005-03-28 22:28:37 +0000140 // Copy the extracted halves into the virtual registers
Nate Begemanf70b5762005-03-28 23:08:54 +0000141 SDOperand argHi = DAG.getCopyFromReg(GPR[GPR_idx], MVT::i32,
142 DAG.getRoot());
143 SDOperand argLo = DAG.getCopyFromReg(GPR[GPR_idx+1], MVT::i32, argHi);
Nate Begemanca12a2b2005-03-28 22:28:37 +0000144 // Build the outgoing arg thingy
Nate Begemanf70b5762005-03-28 23:08:54 +0000145 argt = DAG.getNode(ISD::BUILD_PAIR, MVT::i64, argLo, argHi);
146 newroot = argLo;
Nate Begemana9795f82005-03-24 04:41:43 +0000147 } else {
148 needsLoad = true;
149 }
150 break;
151 case MVT::f32: ObjSize = 4;
152 case MVT::f64: ObjSize = 8;
153 if (FPR_remaining > 0) {
154 BuildMI(&BB, PPC::IMPLICIT_DEF, 0, FPR[FPR_idx]);
Nate Begemanf70b5762005-03-28 23:08:54 +0000155 argt = newroot = DAG.getCopyFromReg(FPR[FPR_idx], ObjectVT,
156 DAG.getRoot());
Nate Begemana9795f82005-03-24 04:41:43 +0000157 --FPR_remaining;
158 ++FPR_idx;
159 } else {
160 needsLoad = true;
161 }
162 break;
163 }
164
165 // We need to load the argument to a virtual register if we determined above
166 // that we ran out of physical registers of the appropriate type
167 if (needsLoad) {
168 int FI = MFI->CreateFixedObject(ObjSize, ArgOffset);
169 SDOperand FIN = DAG.getFrameIndex(FI, MVT::i32);
170 argt = newroot = DAG.getLoad(ObjectVT, DAG.getEntryNode(), FIN);
171 }
172
173 // Every 4 bytes of argument space consumes one of the GPRs available for
174 // argument passing.
175 if (GPR_remaining > 0) {
176 unsigned delta = (GPR_remaining > 1 && ObjSize == 8) ? 2 : 1;
177 GPR_remaining -= delta;
178 GPR_idx += delta;
179 }
180 ArgOffset += ObjSize;
181
182 DAG.setRoot(newroot.getValue(1));
183 ArgValues.push_back(argt);
184 }
185
Nate Begemana9795f82005-03-24 04:41:43 +0000186 // If the function takes variable number of arguments, make a frame index for
187 // the start of the first vararg value... for expansion of llvm.va_start.
188 if (F.isVarArg())
189 VarArgsFrameIndex = MFI->CreateFixedObject(4, ArgOffset);
190
191 return ArgValues;
192}
193
194std::pair<SDOperand, SDOperand>
195PPC32TargetLowering::LowerCallTo(SDOperand Chain,
Nate Begeman307e7442005-03-26 01:28:53 +0000196 const Type *RetTy, bool isVarArg,
197 SDOperand Callee, ArgListTy &Args, SelectionDAG &DAG) {
198 // args_to_use will accumulate outgoing args for the ISD::CALL case in
199 // SelectExpr to use to put the arguments in the appropriate registers.
Nate Begemana9795f82005-03-24 04:41:43 +0000200 std::vector<SDOperand> args_to_use;
Nate Begeman307e7442005-03-26 01:28:53 +0000201
202 // Count how many bytes are to be pushed on the stack, including the linkage
203 // area, and parameter passing area.
204 unsigned NumBytes = 24;
205
206 if (Args.empty()) {
207 NumBytes = 0; // Save zero bytes.
208 } else {
209 for (unsigned i = 0, e = Args.size(); i != e; ++i)
210 switch (getValueType(Args[i].second)) {
211 default: assert(0 && "Unknown value type!");
212 case MVT::i1:
213 case MVT::i8:
214 case MVT::i16:
215 case MVT::i32:
216 case MVT::f32:
217 NumBytes += 4;
218 break;
219 case MVT::i64:
220 case MVT::f64:
221 NumBytes += 8;
222 break;
223 }
224
225 // Just to be safe, we'll always reserve the full 24 bytes of linkage area
226 // plus 32 bytes of argument space in case any called code gets funky on us.
227 if (NumBytes < 56) NumBytes = 56;
228
229 // Adjust the stack pointer for the new arguments...
230 // These operations are automatically eliminated by the prolog/epilog pass
231 Chain = DAG.getNode(ISD::ADJCALLSTACKDOWN, MVT::Other, Chain,
232 DAG.getConstant(NumBytes, getPointerTy()));
233
234 // Set up a copy of the stack pointer for use loading and storing any
235 // arguments that may not fit in the registers available for argument
236 // passing.
237 SDOperand StackPtr = DAG.getCopyFromReg(PPC::R1, MVT::i32,
238 DAG.getEntryNode());
239
240 // Figure out which arguments are going to go in registers, and which in
241 // memory. Also, if this is a vararg function, floating point operations
242 // must be stored to our stack, and loaded into integer regs as well, if
243 // any integer regs are available for argument passing.
244 unsigned ArgOffset = 24;
245 unsigned GPR_remaining = 8;
246 unsigned FPR_remaining = 13;
247 std::vector<SDOperand> Stores;
248 for (unsigned i = 0, e = Args.size(); i != e; ++i) {
249 // PtrOff will be used to store the current argument to the stack if a
250 // register cannot be found for it.
251 SDOperand PtrOff = DAG.getConstant(ArgOffset, getPointerTy());
252 PtrOff = DAG.getNode(ISD::ADD, MVT::i32, StackPtr, PtrOff);
Nate Begemanf7e43382005-03-26 07:46:36 +0000253 MVT::ValueType ArgVT = getValueType(Args[i].second);
Nate Begeman307e7442005-03-26 01:28:53 +0000254
Nate Begemanf7e43382005-03-26 07:46:36 +0000255 switch (ArgVT) {
Nate Begeman307e7442005-03-26 01:28:53 +0000256 default: assert(0 && "Unexpected ValueType for argument!");
257 case MVT::i1:
258 case MVT::i8:
259 case MVT::i16:
260 // Promote the integer to 32 bits. If the input type is signed use a
261 // sign extend, otherwise use a zero extend.
262 if (Args[i].second->isSigned())
263 Args[i].first =DAG.getNode(ISD::SIGN_EXTEND, MVT::i32, Args[i].first);
264 else
265 Args[i].first =DAG.getNode(ISD::ZERO_EXTEND, MVT::i32, Args[i].first);
266 // FALL THROUGH
267 case MVT::i32:
268 if (GPR_remaining > 0) {
269 args_to_use.push_back(Args[i].first);
270 --GPR_remaining;
271 } else {
272 Stores.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain,
273 Args[i].first, PtrOff));
274 }
275 ArgOffset += 4;
276 break;
277 case MVT::i64:
Nate Begemanf7e43382005-03-26 07:46:36 +0000278 // If we have one free GPR left, we can place the upper half of the i64
279 // in it, and store the other half to the stack. If we have two or more
280 // free GPRs, then we can pass both halves of the i64 in registers.
281 if (GPR_remaining > 0) {
Nate Begemanf2622612005-03-26 02:17:46 +0000282 SDOperand Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32,
283 Args[i].first, DAG.getConstant(1, MVT::i32));
284 SDOperand Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32,
285 Args[i].first, DAG.getConstant(0, MVT::i32));
Nate Begemanf7e43382005-03-26 07:46:36 +0000286 args_to_use.push_back(Hi);
287 if (GPR_remaining > 1) {
288 args_to_use.push_back(Lo);
289 GPR_remaining -= 2;
290 } else {
291 SDOperand ConstFour = DAG.getConstant(4, getPointerTy());
292 PtrOff = DAG.getNode(ISD::ADD, MVT::i32, PtrOff, ConstFour);
293 Stores.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain,
294 Lo, PtrOff));
295 --GPR_remaining;
296 }
Nate Begeman307e7442005-03-26 01:28:53 +0000297 } else {
298 Stores.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain,
299 Args[i].first, PtrOff));
300 }
301 ArgOffset += 8;
302 break;
303 case MVT::f32:
Nate Begeman307e7442005-03-26 01:28:53 +0000304 case MVT::f64:
Nate Begemanf7e43382005-03-26 07:46:36 +0000305 if (FPR_remaining > 0) {
306 if (isVarArg) {
307 // FIXME: Need FunctionType information so we can conditionally
308 // store only the non-fixed arguments in a vararg function.
309 Stores.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain,
310 Args[i].first, PtrOff));
Nate Begeman7532e2f2005-03-26 08:25:22 +0000311 // FIXME: Need a way to communicate to the ISD::CALL select code
312 // that a particular argument is non-fixed so that we can load them
313 // into the correct GPR to shadow the FPR
Nate Begemanf7e43382005-03-26 07:46:36 +0000314 }
Nate Begemanf2622612005-03-26 02:17:46 +0000315 args_to_use.push_back(Args[i].first);
Nate Begeman307e7442005-03-26 01:28:53 +0000316 --FPR_remaining;
Nate Begemanf7e43382005-03-26 07:46:36 +0000317 // If we have any FPRs remaining, we may also have GPRs remaining.
318 // Args passed in FPRs consume either 1 (f32) or 2 (f64) available
319 // GPRs.
Nate Begeman307e7442005-03-26 01:28:53 +0000320 if (GPR_remaining > 0) --GPR_remaining;
Nate Begemanf7e43382005-03-26 07:46:36 +0000321 if (GPR_remaining > 0 && MVT::f64 == ArgVT) --GPR_remaining;
Nate Begeman307e7442005-03-26 01:28:53 +0000322 } else {
323 Stores.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain,
324 Args[i].first, PtrOff));
325 }
Nate Begemanf7e43382005-03-26 07:46:36 +0000326 ArgOffset += (ArgVT == MVT::f32) ? 4 : 8;
Nate Begeman307e7442005-03-26 01:28:53 +0000327 break;
328 }
Nate Begemana9795f82005-03-24 04:41:43 +0000329 }
Nate Begeman307e7442005-03-26 01:28:53 +0000330 Chain = DAG.getNode(ISD::TokenFactor, MVT::Other, Stores);
Nate Begemana9795f82005-03-24 04:41:43 +0000331 }
332
333 std::vector<MVT::ValueType> RetVals;
334 MVT::ValueType RetTyVT = getValueType(RetTy);
335 if (RetTyVT != MVT::isVoid)
336 RetVals.push_back(RetTyVT);
337 RetVals.push_back(MVT::Other);
338
339 SDOperand TheCall = SDOperand(DAG.getCall(RetVals,
340 Chain, Callee, args_to_use), 0);
341 Chain = TheCall.getValue(RetTyVT != MVT::isVoid);
342 Chain = DAG.getNode(ISD::ADJCALLSTACKUP, MVT::Other, Chain,
343 DAG.getConstant(NumBytes, getPointerTy()));
344 return std::make_pair(TheCall, Chain);
345}
346
347std::pair<SDOperand, SDOperand>
348PPC32TargetLowering::LowerVAStart(SDOperand Chain, SelectionDAG &DAG) {
349 //vastart just returns the address of the VarArgsFrameIndex slot.
350 return std::make_pair(DAG.getFrameIndex(VarArgsFrameIndex, MVT::i32), Chain);
351}
352
353std::pair<SDOperand,SDOperand> PPC32TargetLowering::
354LowerVAArgNext(bool isVANext, SDOperand Chain, SDOperand VAList,
355 const Type *ArgTy, SelectionDAG &DAG) {
Nate Begemanc7b09f12005-03-25 08:34:25 +0000356 MVT::ValueType ArgVT = getValueType(ArgTy);
357 SDOperand Result;
358 if (!isVANext) {
359 Result = DAG.getLoad(ArgVT, DAG.getEntryNode(), VAList);
360 } else {
361 unsigned Amt;
362 if (ArgVT == MVT::i32 || ArgVT == MVT::f32)
363 Amt = 4;
364 else {
365 assert((ArgVT == MVT::i64 || ArgVT == MVT::f64) &&
366 "Other types should have been promoted for varargs!");
367 Amt = 8;
368 }
369 Result = DAG.getNode(ISD::ADD, VAList.getValueType(), VAList,
370 DAG.getConstant(Amt, VAList.getValueType()));
371 }
372 return std::make_pair(Result, Chain);
Nate Begemana9795f82005-03-24 04:41:43 +0000373}
374
375
376std::pair<SDOperand, SDOperand> PPC32TargetLowering::
377LowerFrameReturnAddress(bool isFrameAddress, SDOperand Chain, unsigned Depth,
378 SelectionDAG &DAG) {
Nate Begeman01d05262005-03-30 01:45:43 +0000379 assert(0 && "LowerFrameReturnAddress unimplemented");
Nate Begemana9795f82005-03-24 04:41:43 +0000380 abort();
381}
382
383namespace {
384
385//===--------------------------------------------------------------------===//
386/// ISel - PPC32 specific code to select PPC32 machine instructions for
387/// SelectionDAG operations.
388//===--------------------------------------------------------------------===//
389class ISel : public SelectionDAGISel {
390
391 /// Comment Here.
392 PPC32TargetLowering PPC32Lowering;
393
394 /// ExprMap - As shared expressions are codegen'd, we keep track of which
395 /// vreg the value is produced in, so we only emit one copy of each compiled
396 /// tree.
397 std::map<SDOperand, unsigned> ExprMap;
Nate Begemanc7b09f12005-03-25 08:34:25 +0000398
399 unsigned GlobalBaseReg;
400 bool GlobalBaseInitialized;
Nate Begemana9795f82005-03-24 04:41:43 +0000401
402public:
403 ISel(TargetMachine &TM) : SelectionDAGISel(PPC32Lowering), PPC32Lowering(TM)
404 {}
405
Nate Begemanc7b09f12005-03-25 08:34:25 +0000406 /// runOnFunction - Override this function in order to reset our per-function
407 /// variables.
408 virtual bool runOnFunction(Function &Fn) {
409 // Make sure we re-emit a set of the global base reg if necessary
410 GlobalBaseInitialized = false;
411 return SelectionDAGISel::runOnFunction(Fn);
412 }
413
Nate Begemana9795f82005-03-24 04:41:43 +0000414 /// InstructionSelectBasicBlock - This callback is invoked by
415 /// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
416 virtual void InstructionSelectBasicBlock(SelectionDAG &DAG) {
417 DEBUG(BB->dump());
418 // Codegen the basic block.
419 Select(DAG.getRoot());
420
421 // Clear state used for selection.
422 ExprMap.clear();
423 }
424
Nate Begemanc7b09f12005-03-25 08:34:25 +0000425 unsigned ISel::getGlobalBaseReg();
Nate Begemana9795f82005-03-24 04:41:43 +0000426 unsigned SelectExpr(SDOperand N);
427 unsigned SelectExprFP(SDOperand N, unsigned Result);
428 void Select(SDOperand N);
429
430 void SelectAddr(SDOperand N, unsigned& Reg, int& offset);
431 void SelectBranchCC(SDOperand N);
432};
433
434/// canUseAsImmediateForOpcode - This method returns a value indicating whether
435/// the ConstantSDNode N can be used as an immediate to Opcode. The return
436/// values are either 0, 1 or 2. 0 indicates that either N is not a
437/// ConstantSDNode, or is not suitable for use by that opcode. A return value
438/// of 1 indicates that the constant may be used in normal immediate form. A
439/// return value of 2 indicates that the constant may be used in shifted
440/// immediate form. If the return value is nonzero, the constant value is
441/// placed in Imm.
442///
443static unsigned canUseAsImmediateForOpcode(SDOperand N, unsigned Opcode,
444 unsigned& Imm) {
445 if (N.getOpcode() != ISD::Constant) return 0;
446
447 int v = (int)cast<ConstantSDNode>(N)->getSignExtended();
448
449 switch(Opcode) {
450 default: return 0;
451 case ISD::ADD:
452 if (v <= 32767 && v >= -32768) { Imm = v & 0xFFFF; return 1; }
453 if ((v & 0x0000FFFF) == 0) { Imm = v >> 16; return 2; }
454 break;
455 case ISD::AND:
456 case ISD::XOR:
457 case ISD::OR:
458 if (v >= 0 && v <= 65535) { Imm = v & 0xFFFF; return 1; }
459 if ((v & 0x0000FFFF) == 0) { Imm = v >> 16; return 2; }
460 break;
Nate Begeman307e7442005-03-26 01:28:53 +0000461 case ISD::MUL:
462 if (v <= 32767 && v >= -32768) { Imm = v & 0xFFFF; return 1; }
463 break;
Nate Begemana9795f82005-03-24 04:41:43 +0000464 }
465 return 0;
466}
467}
468
Nate Begemanc7b09f12005-03-25 08:34:25 +0000469/// getGlobalBaseReg - Output the instructions required to put the
470/// base address to use for accessing globals into a register.
471///
472unsigned ISel::getGlobalBaseReg() {
473 if (!GlobalBaseInitialized) {
474 // Insert the set of GlobalBaseReg into the first MBB of the function
475 MachineBasicBlock &FirstMBB = BB->getParent()->front();
476 MachineBasicBlock::iterator MBBI = FirstMBB.begin();
477 GlobalBaseReg = MakeReg(MVT::i32);
478 BuildMI(FirstMBB, MBBI, PPC::MovePCtoLR, 0, PPC::LR);
479 BuildMI(FirstMBB, MBBI, PPC::MFLR, 1, GlobalBaseReg).addReg(PPC::LR);
480 GlobalBaseInitialized = true;
481 }
482 return GlobalBaseReg;
483}
484
Nate Begemana9795f82005-03-24 04:41:43 +0000485//Check to see if the load is a constant offset from a base register
486void ISel::SelectAddr(SDOperand N, unsigned& Reg, int& offset)
487{
488 Reg = SelectExpr(N);
489 offset = 0;
490 return;
491}
492
493void ISel::SelectBranchCC(SDOperand N)
494{
495 assert(N.getOpcode() == ISD::BRCOND && "Not a BranchCC???");
496 MachineBasicBlock *Dest =
497 cast<BasicBlockSDNode>(N.getOperand(2))->getBasicBlock();
498 unsigned Opc;
499
500 Select(N.getOperand(0)); //chain
501 SDOperand CC = N.getOperand(1);
502
Nate Begeman23afcfb2005-03-29 22:48:55 +0000503 //Give up and do the stupid thing
Nate Begemana9795f82005-03-24 04:41:43 +0000504 unsigned Tmp1 = SelectExpr(CC);
Nate Begeman23afcfb2005-03-29 22:48:55 +0000505 BuildMI(BB, PPC::CMPLWI, 2, PPC::CR0).addReg(Tmp1).addImm(0);
506 BuildMI(BB, PPC::BNE, 2).addReg(PPC::CR0).addMBB(Dest);
Nate Begemana9795f82005-03-24 04:41:43 +0000507 return;
508}
509
510unsigned ISel::SelectExprFP(SDOperand N, unsigned Result)
511{
512 unsigned Tmp1, Tmp2, Tmp3;
513 unsigned Opc = 0;
514 SDNode *Node = N.Val;
515 MVT::ValueType DestType = N.getValueType();
516 unsigned opcode = N.getOpcode();
517
518 switch (opcode) {
519 default:
520 Node->dump();
521 assert(0 && "Node not handled!\n");
522
Nate Begeman23afcfb2005-03-29 22:48:55 +0000523 case ISD::SELECT: {
524 Tmp1 = SelectExpr(N.getOperand(0)); //Cond
525
526 // FIXME: generate FSEL here
527
528 // Create an iterator with which to insert the MBB for copying the false
529 // value and the MBB to hold the PHI instruction for this SetCC.
530 MachineBasicBlock *thisMBB = BB;
531 const BasicBlock *LLVM_BB = BB->getBasicBlock();
532 ilist<MachineBasicBlock>::iterator It = BB;
533 ++It;
534
535 // thisMBB:
536 // ...
537 // TrueVal = ...
538 // cmpTY cr0, r1, r2
539 // bCC copy1MBB
540 // fallthrough --> copy0MBB
541 BuildMI(BB, PPC::CMPLWI, 2, PPC::CR0).addReg(Tmp1).addImm(0);
542 MachineBasicBlock *copy0MBB = new MachineBasicBlock(LLVM_BB);
543 MachineBasicBlock *sinkMBB = new MachineBasicBlock(LLVM_BB);
544 unsigned TrueValue = SelectExpr(N.getOperand(1)); //Use if TRUE
545 BuildMI(BB, PPC::BNE, 2).addReg(PPC::CR0).addMBB(sinkMBB);
546 MachineFunction *F = BB->getParent();
547 F->getBasicBlockList().insert(It, copy0MBB);
548 F->getBasicBlockList().insert(It, sinkMBB);
549 // Update machine-CFG edges
550 BB->addSuccessor(copy0MBB);
551 BB->addSuccessor(sinkMBB);
552
553 // copy0MBB:
554 // %FalseValue = ...
555 // # fallthrough to sinkMBB
556 BB = copy0MBB;
557 unsigned FalseValue = SelectExpr(N.getOperand(2)); //Use if FALSE
558 // Update machine-CFG edges
559 BB->addSuccessor(sinkMBB);
560
561 // sinkMBB:
562 // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ]
563 // ...
564 BB = sinkMBB;
565 BuildMI(BB, PPC::PHI, 4, Result).addReg(FalseValue)
566 .addMBB(copy0MBB).addReg(TrueValue).addMBB(thisMBB);
567 return Result;
568 }
Nate Begemana9795f82005-03-24 04:41:43 +0000569
570 case ISD::FP_ROUND:
571 assert (DestType == MVT::f32 &&
572 N.getOperand(0).getValueType() == MVT::f64 &&
573 "only f64 to f32 conversion supported here");
574 Tmp1 = SelectExpr(N.getOperand(0));
575 BuildMI(BB, PPC::FRSP, 1, Result).addReg(Tmp1);
576 return Result;
577
578 case ISD::FP_EXTEND:
579 assert (DestType == MVT::f64 &&
580 N.getOperand(0).getValueType() == MVT::f32 &&
581 "only f32 to f64 conversion supported here");
582 Tmp1 = SelectExpr(N.getOperand(0));
583 BuildMI(BB, PPC::FMR, 1, Result).addReg(Tmp1);
584 return Result;
585
586 case ISD::CopyFromReg:
Nate Begemanf2622612005-03-26 02:17:46 +0000587 if (Result == 1)
588 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
589 Tmp1 = dyn_cast<RegSDNode>(Node)->getReg();
590 BuildMI(BB, PPC::FMR, 1, Result).addReg(Tmp1);
591 return Result;
Nate Begemana9795f82005-03-24 04:41:43 +0000592
593 case ISD::LOAD:
Nate Begeman9db505c2005-03-28 19:36:43 +0000594 case ISD::EXTLOAD: {
595 MVT::ValueType TypeBeingLoaded = (ISD::LOAD == opcode) ?
596 Node->getValueType(0) : cast<MVTSDNode>(Node)->getExtraValueType();
597
598 // Make sure we generate both values.
599 if (Result != 1)
600 ExprMap[N.getValue(1)] = 1; // Generate the token
601 else
602 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
603
604 SDOperand Chain = N.getOperand(0);
605 SDOperand Address = N.getOperand(1);
606 Select(Chain);
607
608 switch (TypeBeingLoaded) {
609 default: assert(0 && "Cannot fp load this type!");
610 case MVT::f32: Opc = PPC::LFS; break;
611 case MVT::f64: Opc = PPC::LFD; break;
612 }
613
614 if(Address.getOpcode() == ISD::FrameIndex) {
615 BuildMI(BB, Opc, 2, Result)
616 .addFrameIndex(cast<FrameIndexSDNode>(Address)->getIndex())
617 .addReg(PPC::R1);
618 } else {
619 int offset;
620 SelectAddr(Address, Tmp1, offset);
621 BuildMI(BB, Opc, 2, Result).addSImm(offset).addReg(Tmp1);
622 }
623 return Result;
624 }
Nate Begemana9795f82005-03-24 04:41:43 +0000625
626 case ISD::ConstantFP:
Nate Begemanca12a2b2005-03-28 22:28:37 +0000627 assert(0 && "ISD::ConstantFP Unimplemented");
Nate Begemana9795f82005-03-24 04:41:43 +0000628 abort();
629
630 case ISD::MUL:
631 case ISD::ADD:
632 case ISD::SUB:
633 case ISD::SDIV:
634 switch( opcode ) {
635 case ISD::MUL: Opc = DestType == MVT::f64 ? PPC::FMUL : PPC::FMULS; break;
636 case ISD::ADD: Opc = DestType == MVT::f64 ? PPC::FADD : PPC::FADDS; break;
637 case ISD::SUB: Opc = DestType == MVT::f64 ? PPC::FSUB : PPC::FSUBS; break;
638 case ISD::SDIV: Opc = DestType == MVT::f64 ? PPC::FDIV : PPC::FDIVS; break;
639 };
Nate Begemana9795f82005-03-24 04:41:43 +0000640 Tmp1 = SelectExpr(N.getOperand(0));
641 Tmp2 = SelectExpr(N.getOperand(1));
642 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
643 return Result;
644
Nate Begemana9795f82005-03-24 04:41:43 +0000645 case ISD::UINT_TO_FP:
646 case ISD::SINT_TO_FP:
Nate Begemanf3d08f32005-03-29 00:03:27 +0000647 assert(0 && "ISD::U/SINT_TO_FP Unimplemented");
Nate Begemana9795f82005-03-24 04:41:43 +0000648 abort();
649 }
650 assert(0 && "should not get here");
651 return 0;
652}
653
654unsigned ISel::SelectExpr(SDOperand N) {
655 unsigned Result;
656 unsigned Tmp1, Tmp2, Tmp3;
657 unsigned Opc = 0;
658 unsigned opcode = N.getOpcode();
659
660 SDNode *Node = N.Val;
661 MVT::ValueType DestType = N.getValueType();
662
663 unsigned &Reg = ExprMap[N];
664 if (Reg) return Reg;
665
Nate Begeman9e3e1b52005-03-24 23:35:30 +0000666 if (N.getOpcode() != ISD::CALL && N.getOpcode() != ISD::ADD_PARTS &&
667 N.getOpcode() != ISD::SUB_PARTS)
Nate Begemana9795f82005-03-24 04:41:43 +0000668 Reg = Result = (N.getValueType() != MVT::Other) ?
669 MakeReg(N.getValueType()) : 1;
Nate Begeman9e3e1b52005-03-24 23:35:30 +0000670 else {
671 // If this is a call instruction, make sure to prepare ALL of the result
672 // values as well as the chain.
673 if (N.getOpcode() == ISD::CALL) {
674 if (Node->getNumValues() == 1)
675 Reg = Result = 1; // Void call, just a chain.
676 else {
677 Result = MakeReg(Node->getValueType(0));
678 ExprMap[N.getValue(0)] = Result;
679 for (unsigned i = 1, e = N.Val->getNumValues()-1; i != e; ++i)
680 ExprMap[N.getValue(i)] = MakeReg(Node->getValueType(i));
681 ExprMap[SDOperand(Node, Node->getNumValues()-1)] = 1;
682 }
683 } else {
684 Result = MakeReg(Node->getValueType(0));
685 ExprMap[N.getValue(0)] = Result;
686 for (unsigned i = 1, e = N.Val->getNumValues(); i != e; ++i)
687 ExprMap[N.getValue(i)] = MakeReg(Node->getValueType(i));
688 }
689 }
690
691 if (DestType == MVT::f64 || DestType == MVT::f32)
692 return SelectExprFP(N, Result);
Nate Begemana9795f82005-03-24 04:41:43 +0000693
694 switch (opcode) {
695 default:
696 Node->dump();
697 assert(0 && "Node not handled!\n");
698
699 case ISD::DYNAMIC_STACKALLOC:
Nate Begeman5e966612005-03-24 06:28:42 +0000700 // Generate both result values. FIXME: Need a better commment here?
701 if (Result != 1)
702 ExprMap[N.getValue(1)] = 1;
703 else
704 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
705
706 // FIXME: We are currently ignoring the requested alignment for handling
707 // greater than the stack alignment. This will need to be revisited at some
708 // point. Align = N.getOperand(2);
709 if (!isa<ConstantSDNode>(N.getOperand(2)) ||
710 cast<ConstantSDNode>(N.getOperand(2))->getValue() != 0) {
711 std::cerr << "Cannot allocate stack object with greater alignment than"
712 << " the stack alignment yet!";
713 abort();
714 }
715 Select(N.getOperand(0));
716 Tmp1 = SelectExpr(N.getOperand(1));
717 // Subtract size from stack pointer, thereby allocating some space.
718 BuildMI(BB, PPC::SUBF, 2, PPC::R1).addReg(Tmp1).addReg(PPC::R1);
719 // Put a pointer to the space into the result register by copying the SP
720 BuildMI(BB, PPC::OR, 2, Result).addReg(PPC::R1).addReg(PPC::R1);
721 return Result;
Nate Begemana9795f82005-03-24 04:41:43 +0000722
723 case ISD::ConstantPool:
Nate Begemanca12a2b2005-03-28 22:28:37 +0000724 Tmp1 = cast<ConstantPoolSDNode>(N)->getIndex();
725 Tmp2 = MakeReg(MVT::i32);
726 BuildMI(BB, PPC::LOADHiAddr, 2, Tmp2).addReg(getGlobalBaseReg())
727 .addConstantPoolIndex(Tmp1);
728 BuildMI(BB, PPC::LA, 2, Result).addReg(Tmp2).addConstantPoolIndex(Tmp1);
729 return Result;
Nate Begemana9795f82005-03-24 04:41:43 +0000730
731 case ISD::FrameIndex:
Nate Begemanf3d08f32005-03-29 00:03:27 +0000732 Tmp1 = cast<FrameIndexSDNode>(N)->getIndex();
733 addFrameReference(BuildMI(BB, PPC::ADDI, 2, Result), (int)Tmp1);
734 return Result;
Nate Begemana9795f82005-03-24 04:41:43 +0000735
Nate Begeman9e3e1b52005-03-24 23:35:30 +0000736 case ISD::GlobalAddress: {
737 GlobalValue *GV = cast<GlobalAddressSDNode>(N)->getGlobal();
Nate Begemanca12a2b2005-03-28 22:28:37 +0000738 Tmp1 = MakeReg(MVT::i32);
Nate Begemanc7b09f12005-03-25 08:34:25 +0000739 BuildMI(BB, PPC::LOADHiAddr, 2, Tmp1).addReg(getGlobalBaseReg())
740 .addGlobalAddress(GV);
Nate Begeman9e3e1b52005-03-24 23:35:30 +0000741 if (GV->hasWeakLinkage() || GV->isExternal()) {
742 BuildMI(BB, PPC::LWZ, 2, Result).addGlobalAddress(GV).addReg(Tmp1);
743 } else {
744 BuildMI(BB, PPC::LA, 2, Result).addReg(Tmp1).addGlobalAddress(GV);
745 }
746 return Result;
747 }
748
Nate Begeman5e966612005-03-24 06:28:42 +0000749 case ISD::LOAD:
Nate Begemana9795f82005-03-24 04:41:43 +0000750 case ISD::EXTLOAD:
751 case ISD::ZEXTLOAD:
Nate Begeman9e3e1b52005-03-24 23:35:30 +0000752 case ISD::SEXTLOAD: {
Nate Begeman9db505c2005-03-28 19:36:43 +0000753 bool sext = (ISD::SEXTLOAD == opcode);
754 bool byte = (MVT::i8 == Node->getValueType(0));
755 MVT::ValueType TypeBeingLoaded = (ISD::LOAD == opcode) ?
756 Node->getValueType(0) : cast<MVTSDNode>(Node)->getExtraValueType();
757
Nate Begeman5e966612005-03-24 06:28:42 +0000758 // Make sure we generate both values.
759 if (Result != 1)
760 ExprMap[N.getValue(1)] = 1; // Generate the token
761 else
762 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
763
764 SDOperand Chain = N.getOperand(0);
765 SDOperand Address = N.getOperand(1);
766 Select(Chain);
767
Nate Begeman9db505c2005-03-28 19:36:43 +0000768 switch (TypeBeingLoaded) {
Nate Begeman5e966612005-03-24 06:28:42 +0000769 default: assert(0 && "Cannot load this type!");
Nate Begeman9db505c2005-03-28 19:36:43 +0000770 case MVT::i1: Opc = PPC::LBZ; break;
771 case MVT::i8: Opc = PPC::LBZ; break;
772 case MVT::i16: Opc = sext ? PPC::LHA : PPC::LHZ; break;
773 case MVT::i32: Opc = PPC::LWZ; break;
Nate Begeman5e966612005-03-24 06:28:42 +0000774 }
775
Nate Begeman9db505c2005-03-28 19:36:43 +0000776 // Since there's no load byte & sign extend instruction we have to split
777 // byte SEXTLOADs into lbz + extsb. This requires we make a temp register.
778 if (sext && byte) {
779 Tmp3 = Result;
780 Result = MakeReg(MVT::i32);
Chris Lattner848132d2005-03-29 15:13:27 +0000781 } else {
782 Tmp3 = 0; // Silence GCC warning.
Nate Begeman9db505c2005-03-28 19:36:43 +0000783 }
Nate Begeman9e3e1b52005-03-24 23:35:30 +0000784 if(Address.getOpcode() == ISD::FrameIndex) {
Nate Begeman5e966612005-03-24 06:28:42 +0000785 BuildMI(BB, Opc, 2, Result)
786 .addFrameIndex(cast<FrameIndexSDNode>(Address)->getIndex())
787 .addReg(PPC::R1);
788 } else {
789 int offset;
790 SelectAddr(Address, Tmp1, offset);
791 BuildMI(BB, Opc, 2, Result).addSImm(offset).addReg(Tmp1);
792 }
Nate Begeman9db505c2005-03-28 19:36:43 +0000793 if (sext && byte) {
794 BuildMI(BB, PPC::EXTSB, 1, Tmp3).addReg(Result);
795 Result = Tmp3;
796 }
Nate Begeman5e966612005-03-24 06:28:42 +0000797 return Result;
798 }
799
Nate Begeman9e3e1b52005-03-24 23:35:30 +0000800 case ISD::CALL: {
801 // Lower the chain for this call.
802 Select(N.getOperand(0));
803 ExprMap[N.getValue(Node->getNumValues()-1)] = 1;
804
805 // get the virtual reg for each argument
806 std::vector<unsigned> VRegs;
807 for(int i = 2, e = Node->getNumOperands(); i < e; ++i)
808 VRegs.push_back(SelectExpr(N.getOperand(i)));
809
810 // The ABI specifies that the first 32 bytes of args may be passed in GPRs,
811 // and that 13 FPRs may also be used for passing any floating point args.
812 int GPR_remaining = 8, FPR_remaining = 13;
813 unsigned GPR_idx = 0, FPR_idx = 0;
814 static const unsigned GPR[] = {
815 PPC::R3, PPC::R4, PPC::R5, PPC::R6,
816 PPC::R7, PPC::R8, PPC::R9, PPC::R10,
817 };
818 static const unsigned FPR[] = {
819 PPC::F1, PPC::F2, PPC::F3, PPC::F4, PPC::F5, PPC::F6,
820 PPC::F7, PPC::F8, PPC::F9, PPC::F10, PPC::F11, PPC::F12,
821 PPC::F13
822 };
823
824 // move the vregs into the appropriate architected register or stack slot
825 for(int i = 0, e = VRegs.size(); i < e; ++i) {
826 unsigned OperandType = N.getOperand(i+2).getValueType();
827 switch(OperandType) {
828 default:
829 Node->dump();
830 N.getOperand(i).Val->dump();
831 std::cerr << "Type for " << i << " is: " <<
832 N.getOperand(i+2).getValueType() << "\n";
833 assert(0 && "Unknown value type for call");
834 case MVT::i1:
835 case MVT::i8:
836 case MVT::i16:
837 case MVT::i32:
838 if (GPR_remaining > 0)
839 BuildMI(BB, PPC::OR, 2, GPR[GPR_idx]).addReg(VRegs[i])
840 .addReg(VRegs[i]);
841 break;
842 case MVT::f32:
843 case MVT::f64:
844 if (FPR_remaining > 0) {
845 BuildMI(BB, PPC::FMR, 1, FPR[FPR_idx]).addReg(VRegs[i]);
Nate Begemanf2622612005-03-26 02:17:46 +0000846 ++FPR_idx;
Nate Begeman9e3e1b52005-03-24 23:35:30 +0000847 --FPR_remaining;
848 }
849 break;
850 }
851 // All arguments consume GPRs available for argument passing
Nate Begemanf2622612005-03-26 02:17:46 +0000852 if (GPR_remaining > 0) {
853 ++GPR_idx;
854 --GPR_remaining;
855 }
856 if (MVT::f64 == OperandType && GPR_remaining > 0) {
857 ++GPR_idx;
858 --GPR_remaining;
859 }
Nate Begeman9e3e1b52005-03-24 23:35:30 +0000860 }
861
862 // Emit the correct call instruction based on the type of symbol called.
863 if (GlobalAddressSDNode *GASD =
864 dyn_cast<GlobalAddressSDNode>(N.getOperand(1))) {
865 BuildMI(BB, PPC::CALLpcrel, 1).addGlobalAddress(GASD->getGlobal(), true);
866 } else if (ExternalSymbolSDNode *ESSDN =
867 dyn_cast<ExternalSymbolSDNode>(N.getOperand(1))) {
868 BuildMI(BB, PPC::CALLpcrel, 1).addExternalSymbol(ESSDN->getSymbol(), true);
869 } else {
870 Tmp1 = SelectExpr(N.getOperand(1));
871 BuildMI(BB, PPC::OR, 2, PPC::R12).addReg(Tmp1).addReg(Tmp1);
872 BuildMI(BB, PPC::MTCTR, 1).addReg(PPC::R12);
873 BuildMI(BB, PPC::CALLindirect, 3).addImm(20).addImm(0).addReg(PPC::R12);
874 }
875
876 switch (Node->getValueType(0)) {
877 default: assert(0 && "Unknown value type for call result!");
878 case MVT::Other: return 1;
879 case MVT::i1:
880 case MVT::i8:
881 case MVT::i16:
882 case MVT::i32:
Nate Begemanc7b09f12005-03-25 08:34:25 +0000883 BuildMI(BB, PPC::OR, 2, Result).addReg(PPC::R3).addReg(PPC::R3);
Nate Begeman9e3e1b52005-03-24 23:35:30 +0000884 if (Node->getValueType(1) == MVT::i32)
Nate Begemanc7b09f12005-03-25 08:34:25 +0000885 BuildMI(BB, PPC::OR, 2, Result+1).addReg(PPC::R4).addReg(PPC::R4);
Nate Begeman9e3e1b52005-03-24 23:35:30 +0000886 break;
887 case MVT::f32:
888 case MVT::f64:
889 BuildMI(BB, PPC::FMR, 1, Result).addReg(PPC::F1);
890 break;
891 }
892 return Result+N.ResNo;
893 }
Nate Begemana9795f82005-03-24 04:41:43 +0000894
895 case ISD::SIGN_EXTEND:
896 case ISD::SIGN_EXTEND_INREG:
897 Tmp1 = SelectExpr(N.getOperand(0));
Nate Begeman9db505c2005-03-28 19:36:43 +0000898 switch(cast<MVTSDNode>(Node)->getExtraValueType()) {
899 default: Node->dump(); assert(0 && "Unhandled SIGN_EXTEND type"); break;
900 case MVT::i16:
901 BuildMI(BB, PPC::EXTSH, 1, Result).addReg(Tmp1);
902 break;
903 case MVT::i8:
904 BuildMI(BB, PPC::EXTSB, 1, Result).addReg(Tmp1);
905 break;
Nate Begeman74747862005-03-29 22:24:51 +0000906 case MVT::i1:
907 BuildMI(BB, PPC::SUBFIC, 2, Result).addReg(Tmp1).addSImm(0);
908 break;
Nate Begeman9db505c2005-03-28 19:36:43 +0000909 }
Nate Begemana9795f82005-03-24 04:41:43 +0000910 return Result;
911
912 case ISD::ZERO_EXTEND_INREG:
913 Tmp1 = SelectExpr(N.getOperand(0));
914 switch(cast<MVTSDNode>(Node)->getExtraValueType()) {
Nate Begeman9db505c2005-03-28 19:36:43 +0000915 default: Node->dump(); assert(0 && "Unhandled ZERO_EXTEND type"); break;
Nate Begemana9795f82005-03-24 04:41:43 +0000916 case MVT::i16: Tmp2 = 16; break;
917 case MVT::i8: Tmp2 = 24; break;
918 case MVT::i1: Tmp2 = 31; break;
919 }
Nate Begeman33162522005-03-29 21:54:38 +0000920 BuildMI(BB, PPC::RLWINM, 4, Result).addReg(Tmp1).addImm(0).addImm(Tmp2)
921 .addImm(31);
Nate Begemana9795f82005-03-24 04:41:43 +0000922 return Result;
923
Nate Begemana9795f82005-03-24 04:41:43 +0000924 case ISD::CopyFromReg:
925 if (Result == 1)
926 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
927 Tmp1 = dyn_cast<RegSDNode>(Node)->getReg();
928 BuildMI(BB, PPC::OR, 2, Result).addReg(Tmp1).addReg(Tmp1);
929 return Result;
930
931 case ISD::SHL:
Nate Begeman5e966612005-03-24 06:28:42 +0000932 Tmp1 = SelectExpr(N.getOperand(0));
933 if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
934 Tmp2 = CN->getValue() & 0x1F;
Nate Begeman33162522005-03-29 21:54:38 +0000935 BuildMI(BB, PPC::RLWINM, 4, Result).addReg(Tmp1).addImm(Tmp2).addImm(0)
Nate Begeman5e966612005-03-24 06:28:42 +0000936 .addImm(31-Tmp2);
937 } else {
938 Tmp2 = SelectExpr(N.getOperand(1));
939 BuildMI(BB, PPC::SLW, 2, Result).addReg(Tmp1).addReg(Tmp2);
940 }
941 return Result;
Nate Begemana9795f82005-03-24 04:41:43 +0000942
Nate Begeman5e966612005-03-24 06:28:42 +0000943 case ISD::SRL:
944 Tmp1 = SelectExpr(N.getOperand(0));
945 if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
946 Tmp2 = CN->getValue() & 0x1F;
Nate Begeman33162522005-03-29 21:54:38 +0000947 BuildMI(BB, PPC::RLWINM, 4, Result).addReg(Tmp1).addImm(32-Tmp2)
Nate Begeman5e966612005-03-24 06:28:42 +0000948 .addImm(Tmp2).addImm(31);
949 } else {
950 Tmp2 = SelectExpr(N.getOperand(1));
951 BuildMI(BB, PPC::SRW, 2, Result).addReg(Tmp1).addReg(Tmp2);
952 }
953 return Result;
954
955 case ISD::SRA:
956 Tmp1 = SelectExpr(N.getOperand(0));
957 if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
958 Tmp2 = CN->getValue() & 0x1F;
959 BuildMI(BB, PPC::SRAWI, 2, Result).addReg(Tmp1).addImm(Tmp2);
960 } else {
961 Tmp2 = SelectExpr(N.getOperand(1));
962 BuildMI(BB, PPC::SRAW, 2, Result).addReg(Tmp1).addReg(Tmp2);
963 }
964 return Result;
965
Nate Begemana9795f82005-03-24 04:41:43 +0000966 case ISD::ADD:
967 assert (DestType == MVT::i32 && "Only do arithmetic on i32s!");
968 Tmp1 = SelectExpr(N.getOperand(0));
969 switch(canUseAsImmediateForOpcode(N.getOperand(1), opcode, Tmp2)) {
970 default: assert(0 && "unhandled result code");
971 case 0: // No immediate
972 Tmp2 = SelectExpr(N.getOperand(1));
973 BuildMI(BB, PPC::ADD, 2, Result).addReg(Tmp1).addReg(Tmp2);
974 break;
975 case 1: // Low immediate
976 BuildMI(BB, PPC::ADDI, 2, Result).addReg(Tmp1).addSImm(Tmp2);
977 break;
978 case 2: // Shifted immediate
979 BuildMI(BB, PPC::ADDIS, 2, Result).addReg(Tmp1).addSImm(Tmp2);
980 break;
981 }
982 return Result;
Nate Begeman9e3e1b52005-03-24 23:35:30 +0000983
Nate Begemana9795f82005-03-24 04:41:43 +0000984 case ISD::AND:
985 case ISD::OR:
986 case ISD::XOR:
987 assert (DestType == MVT::i32 && "Only do arithmetic on i32s!");
988 Tmp1 = SelectExpr(N.getOperand(0));
989 switch(canUseAsImmediateForOpcode(N.getOperand(1), opcode, Tmp2)) {
990 default: assert(0 && "unhandled result code");
991 case 0: // No immediate
992 Tmp2 = SelectExpr(N.getOperand(1));
993 switch (opcode) {
Nate Begeman5e966612005-03-24 06:28:42 +0000994 case ISD::AND: Opc = PPC::AND; break;
995 case ISD::OR: Opc = PPC::OR; break;
996 case ISD::XOR: Opc = PPC::XOR; break;
Nate Begemana9795f82005-03-24 04:41:43 +0000997 }
Nate Begeman5e966612005-03-24 06:28:42 +0000998 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
Nate Begemana9795f82005-03-24 04:41:43 +0000999 break;
1000 case 1: // Low immediate
1001 switch (opcode) {
Nate Begeman5e966612005-03-24 06:28:42 +00001002 case ISD::AND: Opc = PPC::ANDIo; break;
1003 case ISD::OR: Opc = PPC::ORI; break;
1004 case ISD::XOR: Opc = PPC::XORI; break;
Nate Begemana9795f82005-03-24 04:41:43 +00001005 }
Nate Begeman5e966612005-03-24 06:28:42 +00001006 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(Tmp2);
Nate Begemana9795f82005-03-24 04:41:43 +00001007 break;
1008 case 2: // Shifted immediate
1009 switch (opcode) {
Nate Begeman5e966612005-03-24 06:28:42 +00001010 case ISD::AND: Opc = PPC::ANDISo; break;
1011 case ISD::OR: Opc = PPC::ORIS; break;
1012 case ISD::XOR: Opc = PPC::XORIS; break;
Nate Begemana9795f82005-03-24 04:41:43 +00001013 }
Nate Begeman5e966612005-03-24 06:28:42 +00001014 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(Tmp2);
Nate Begemana9795f82005-03-24 04:41:43 +00001015 break;
1016 }
1017 return Result;
Nate Begeman9e3e1b52005-03-24 23:35:30 +00001018
1019 case ISD::SUB:
1020 assert (DestType == MVT::i32 && "Only do arithmetic on i32s!");
1021 Tmp1 = SelectExpr(N.getOperand(0));
1022 Tmp2 = SelectExpr(N.getOperand(1));
1023 BuildMI(BB, PPC::SUBF, 2, Result).addReg(Tmp2).addReg(Tmp1);
1024 return Result;
Nate Begemana9795f82005-03-24 04:41:43 +00001025
Nate Begeman5e966612005-03-24 06:28:42 +00001026 case ISD::MUL:
Nate Begeman9e3e1b52005-03-24 23:35:30 +00001027 assert (DestType == MVT::i32 && "Only do arithmetic on i32s!");
1028 Tmp1 = SelectExpr(N.getOperand(0));
Nate Begeman307e7442005-03-26 01:28:53 +00001029 if (1 == canUseAsImmediateForOpcode(N.getOperand(1), opcode, Tmp2))
1030 BuildMI(BB, PPC::MULLI, 2, Result).addReg(Tmp1).addSImm(Tmp2);
1031 else {
1032 Tmp2 = SelectExpr(N.getOperand(1));
1033 BuildMI(BB, PPC::MULLW, 2, Result).addReg(Tmp1).addReg(Tmp2);
1034 }
Nate Begeman9e3e1b52005-03-24 23:35:30 +00001035 return Result;
1036
Nate Begemanf3d08f32005-03-29 00:03:27 +00001037 case ISD::SDIV:
1038 case ISD::UDIV:
1039 assert (DestType == MVT::i32 && "Only do arithmetic on i32s!");
1040 Tmp1 = SelectExpr(N.getOperand(0));
1041 Tmp2 = SelectExpr(N.getOperand(1));
1042 Opc = (ISD::UDIV == opcode) ? PPC::DIVWU : PPC::DIVW;
1043 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
1044 return Result;
1045
1046 case ISD::UREM:
1047 case ISD::SREM: {
1048 assert (DestType == MVT::i32 && "Only do arithmetic on i32s!");
1049 Tmp1 = SelectExpr(N.getOperand(0));
1050 Tmp2 = SelectExpr(N.getOperand(1));
1051 Tmp3 = MakeReg(MVT::i32);
1052 unsigned Tmp4 = MakeReg(MVT::i32);
1053 Opc = (ISD::UREM == opcode) ? PPC::DIVWU : PPC::DIVW;
1054 BuildMI(BB, Opc, 2, Tmp3).addReg(Tmp1).addReg(Tmp2);
1055 BuildMI(BB, PPC::MULLW, 2, Tmp4).addReg(Tmp3).addReg(Tmp2);
1056 BuildMI(BB, PPC::SUBF, 2, Result).addReg(Tmp4).addReg(Tmp1);
1057 return Result;
1058 }
1059
Nate Begeman9e3e1b52005-03-24 23:35:30 +00001060 case ISD::ADD_PARTS:
Nate Begemanca12a2b2005-03-28 22:28:37 +00001061 case ISD::SUB_PARTS: {
1062 assert(N.getNumOperands() == 4 && N.getValueType() == MVT::i32 &&
1063 "Not an i64 add/sub!");
1064 // Emit all of the operands.
1065 std::vector<unsigned> InVals;
1066 for (unsigned i = 0, e = N.getNumOperands(); i != e; ++i)
1067 InVals.push_back(SelectExpr(N.getOperand(i)));
1068 if (N.getOpcode() == ISD::ADD_PARTS) {
Nate Begemanf70b5762005-03-28 23:08:54 +00001069 BuildMI(BB, PPC::ADDC, 2, Result+1).addReg(InVals[0]).addReg(InVals[2]);
1070 BuildMI(BB, PPC::ADDE, 2, Result).addReg(InVals[1]).addReg(InVals[3]);
Nate Begemanca12a2b2005-03-28 22:28:37 +00001071 } else {
Nate Begemanf70b5762005-03-28 23:08:54 +00001072 BuildMI(BB, PPC::SUBFC, 2, Result+1).addReg(InVals[2]).addReg(InVals[0]);
1073 BuildMI(BB, PPC::SUBFE, 2, Result).addReg(InVals[3]).addReg(InVals[1]);
Nate Begemanca12a2b2005-03-28 22:28:37 +00001074 }
1075 return Result+N.ResNo;
1076 }
1077
Nate Begemana9795f82005-03-24 04:41:43 +00001078 case ISD::FP_TO_UINT:
1079 case ISD::FP_TO_SINT:
Nate Begeman01d05262005-03-30 01:45:43 +00001080 assert(0 && "FP_TO_S/UINT unimplemented");
Nate Begemana9795f82005-03-24 04:41:43 +00001081 abort();
1082
Nate Begeman9e3e1b52005-03-24 23:35:30 +00001083 case ISD::SETCC:
Nate Begeman33162522005-03-29 21:54:38 +00001084 if (SetCCSDNode *SetCC = dyn_cast<SetCCSDNode>(Node)) {
1085 bool U = false;
1086 bool IsInteger = MVT::isInteger(SetCC->getOperand(0).getValueType());
1087
1088 switch (SetCC->getCondition()) {
1089 default: Node->dump(); assert(0 && "Unknown comparison!");
1090 case ISD::SETEQ: Opc = PPC::BEQ; break;
1091 case ISD::SETNE: Opc = PPC::BNE; break;
1092 case ISD::SETULT: U = true;
1093 case ISD::SETLT: Opc = PPC::BLT; break;
1094 case ISD::SETULE: U = true;
1095 case ISD::SETLE: Opc = PPC::BLE; break;
1096 case ISD::SETUGT: U = true;
1097 case ISD::SETGT: Opc = PPC::BGT; break;
1098 case ISD::SETUGE: U = true;
1099 case ISD::SETGE: Opc = PPC::BGE; break;
1100 }
1101
1102 // FIXME: Is there a situation in which we would ever need to emit fcmpo?
1103 static const unsigned CompareOpcodes[] =
1104 { PPC::FCMPU, PPC::FCMPU, PPC::CMPW, PPC::CMPLW };
1105 unsigned CompareOpc = CompareOpcodes[2 * IsInteger + U];
1106
1107 // Create an iterator with which to insert the MBB for copying the false
1108 // value and the MBB to hold the PHI instruction for this SetCC.
1109 MachineBasicBlock *thisMBB = BB;
1110 const BasicBlock *LLVM_BB = BB->getBasicBlock();
1111 ilist<MachineBasicBlock>::iterator It = BB;
1112 ++It;
1113
1114 // thisMBB:
1115 // ...
1116 // cmpTY cr0, r1, r2
1117 // %TrueValue = li 1
1118 // bCC sinkMBB
1119 Tmp1 = SelectExpr(N.getOperand(0));
1120 Tmp2 = SelectExpr(N.getOperand(1));
1121 BuildMI(BB, CompareOpc, 2, PPC::CR0).addReg(Tmp1).addReg(Tmp2);
1122 unsigned TrueValue = MakeReg(MVT::i32);
1123 BuildMI(BB, PPC::LI, 1, TrueValue).addSImm(1);
1124 MachineBasicBlock *copy0MBB = new MachineBasicBlock(LLVM_BB);
1125 MachineBasicBlock *sinkMBB = new MachineBasicBlock(LLVM_BB);
1126 BuildMI(BB, Opc, 2).addReg(PPC::CR0).addMBB(sinkMBB);
1127 MachineFunction *F = BB->getParent();
1128 F->getBasicBlockList().insert(It, copy0MBB);
1129 F->getBasicBlockList().insert(It, sinkMBB);
1130 // Update machine-CFG edges
1131 BB->addSuccessor(copy0MBB);
1132 BB->addSuccessor(sinkMBB);
1133
1134 // copy0MBB:
1135 // %FalseValue = li 0
1136 // fallthrough
1137 BB = copy0MBB;
1138 unsigned FalseValue = MakeReg(MVT::i32);
1139 BuildMI(BB, PPC::LI, 1, FalseValue).addSImm(0);
1140 // Update machine-CFG edges
1141 BB->addSuccessor(sinkMBB);
1142
1143 // sinkMBB:
1144 // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ]
1145 // ...
1146 BB = sinkMBB;
1147 BuildMI(BB, PPC::PHI, 4, Result).addReg(FalseValue)
1148 .addMBB(copy0MBB).addReg(TrueValue).addMBB(thisMBB);
1149 return Result;
1150 }
1151 assert(0 && "Is this legal?");
1152 return 0;
Nate Begeman9e3e1b52005-03-24 23:35:30 +00001153
Nate Begeman74747862005-03-29 22:24:51 +00001154 case ISD::SELECT: {
1155 Tmp1 = SelectExpr(N.getOperand(0)); //Cond
1156
1157 // Create an iterator with which to insert the MBB for copying the false
1158 // value and the MBB to hold the PHI instruction for this SetCC.
1159 MachineBasicBlock *thisMBB = BB;
1160 const BasicBlock *LLVM_BB = BB->getBasicBlock();
1161 ilist<MachineBasicBlock>::iterator It = BB;
1162 ++It;
1163
1164 // thisMBB:
1165 // ...
1166 // TrueVal = ...
1167 // cmpTY cr0, r1, r2
1168 // bCC copy1MBB
1169 // fallthrough --> copy0MBB
1170 BuildMI(BB, PPC::CMPLWI, 2, PPC::CR0).addReg(Tmp1).addImm(0);
1171 MachineBasicBlock *copy0MBB = new MachineBasicBlock(LLVM_BB);
1172 MachineBasicBlock *sinkMBB = new MachineBasicBlock(LLVM_BB);
1173 unsigned TrueValue = SelectExpr(N.getOperand(1)); //Use if TRUE
1174 BuildMI(BB, PPC::BNE, 2).addReg(PPC::CR0).addMBB(sinkMBB);
1175 MachineFunction *F = BB->getParent();
1176 F->getBasicBlockList().insert(It, copy0MBB);
1177 F->getBasicBlockList().insert(It, sinkMBB);
1178 // Update machine-CFG edges
1179 BB->addSuccessor(copy0MBB);
1180 BB->addSuccessor(sinkMBB);
1181
1182 // copy0MBB:
1183 // %FalseValue = ...
1184 // # fallthrough to sinkMBB
1185 BB = copy0MBB;
1186 unsigned FalseValue = SelectExpr(N.getOperand(2)); //Use if FALSE
1187 // Update machine-CFG edges
1188 BB->addSuccessor(sinkMBB);
1189
1190 // sinkMBB:
1191 // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ]
1192 // ...
1193 BB = sinkMBB;
1194 BuildMI(BB, PPC::PHI, 4, Result).addReg(FalseValue)
1195 .addMBB(copy0MBB).addReg(TrueValue).addMBB(thisMBB);
1196
1197 // FIXME: Select i64?
1198 return Result;
1199 }
Nate Begemana9795f82005-03-24 04:41:43 +00001200
1201 case ISD::Constant:
1202 switch (N.getValueType()) {
1203 default: assert(0 && "Cannot use constants of this type!");
1204 case MVT::i1:
1205 BuildMI(BB, PPC::LI, 1, Result)
1206 .addSImm(!cast<ConstantSDNode>(N)->isNullValue());
1207 break;
1208 case MVT::i32:
1209 {
1210 int v = (int)cast<ConstantSDNode>(N)->getSignExtended();
1211 if (v < 32768 && v >= -32768) {
1212 BuildMI(BB, PPC::LI, 1, Result).addSImm(v);
1213 } else {
Nate Begeman5e966612005-03-24 06:28:42 +00001214 Tmp1 = MakeReg(MVT::i32);
1215 BuildMI(BB, PPC::LIS, 1, Tmp1).addSImm(v >> 16);
1216 BuildMI(BB, PPC::ORI, 2, Result).addReg(Tmp1).addImm(v & 0xFFFF);
Nate Begemana9795f82005-03-24 04:41:43 +00001217 }
1218 }
1219 }
1220 return Result;
1221 }
1222
1223 return 0;
1224}
1225
1226void ISel::Select(SDOperand N) {
1227 unsigned Tmp1, Tmp2, Opc;
1228 unsigned opcode = N.getOpcode();
1229
1230 if (!ExprMap.insert(std::make_pair(N, 1)).second)
1231 return; // Already selected.
1232
1233 SDNode *Node = N.Val;
1234
1235 switch (Node->getOpcode()) {
1236 default:
1237 Node->dump(); std::cerr << "\n";
1238 assert(0 && "Node not handled yet!");
1239 case ISD::EntryToken: return; // Noop
1240 case ISD::TokenFactor:
1241 for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i)
1242 Select(Node->getOperand(i));
1243 return;
1244 case ISD::ADJCALLSTACKDOWN:
1245 case ISD::ADJCALLSTACKUP:
1246 Select(N.getOperand(0));
1247 Tmp1 = cast<ConstantSDNode>(N.getOperand(1))->getValue();
1248 Opc = N.getOpcode() == ISD::ADJCALLSTACKDOWN ? PPC::ADJCALLSTACKDOWN :
1249 PPC::ADJCALLSTACKUP;
1250 BuildMI(BB, Opc, 1).addImm(Tmp1);
1251 return;
1252 case ISD::BR: {
1253 MachineBasicBlock *Dest =
1254 cast<BasicBlockSDNode>(N.getOperand(1))->getBasicBlock();
Nate Begemana9795f82005-03-24 04:41:43 +00001255 Select(N.getOperand(0));
1256 BuildMI(BB, PPC::B, 1).addMBB(Dest);
1257 return;
1258 }
1259 case ISD::BRCOND:
1260 SelectBranchCC(N);
1261 return;
1262 case ISD::CopyToReg:
1263 Select(N.getOperand(0));
1264 Tmp1 = SelectExpr(N.getOperand(1));
1265 Tmp2 = cast<RegSDNode>(N)->getReg();
1266
1267 if (Tmp1 != Tmp2) {
1268 if (N.getOperand(1).getValueType() == MVT::f64 ||
1269 N.getOperand(1).getValueType() == MVT::f32)
1270 BuildMI(BB, PPC::FMR, 1, Tmp2).addReg(Tmp1);
1271 else
1272 BuildMI(BB, PPC::OR, 2, Tmp2).addReg(Tmp1).addReg(Tmp1);
1273 }
1274 return;
1275 case ISD::ImplicitDef:
1276 Select(N.getOperand(0));
1277 BuildMI(BB, PPC::IMPLICIT_DEF, 0, cast<RegSDNode>(N)->getReg());
1278 return;
1279 case ISD::RET:
1280 switch (N.getNumOperands()) {
1281 default:
1282 assert(0 && "Unknown return instruction!");
1283 case 3:
1284 assert(N.getOperand(1).getValueType() == MVT::i32 &&
1285 N.getOperand(2).getValueType() == MVT::i32 &&
1286 "Unknown two-register value!");
1287 Select(N.getOperand(0));
1288 Tmp1 = SelectExpr(N.getOperand(1));
1289 Tmp2 = SelectExpr(N.getOperand(2));
1290 BuildMI(BB, PPC::OR, 2, PPC::R3).addReg(Tmp1).addReg(Tmp1);
1291 BuildMI(BB, PPC::OR, 2, PPC::R4).addReg(Tmp2).addReg(Tmp2);
1292 break;
1293 case 2:
1294 Select(N.getOperand(0));
1295 Tmp1 = SelectExpr(N.getOperand(1));
1296 switch (N.getOperand(1).getValueType()) {
1297 default:
1298 assert(0 && "Unknown return type!");
1299 case MVT::f64:
1300 case MVT::f32:
1301 BuildMI(BB, PPC::FMR, 1, PPC::F1).addReg(Tmp1);
1302 break;
1303 case MVT::i32:
1304 BuildMI(BB, PPC::OR, 2, PPC::R3).addReg(Tmp1).addReg(Tmp1);
1305 break;
1306 }
Nate Begeman9e3e1b52005-03-24 23:35:30 +00001307 case 1:
1308 Select(N.getOperand(0));
1309 break;
Nate Begemana9795f82005-03-24 04:41:43 +00001310 }
1311 BuildMI(BB, PPC::BLR, 0); // Just emit a 'ret' instruction
1312 return;
Nate Begemana9795f82005-03-24 04:41:43 +00001313 case ISD::TRUNCSTORE:
1314 case ISD::STORE:
1315 {
1316 SDOperand Chain = N.getOperand(0);
1317 SDOperand Value = N.getOperand(1);
1318 SDOperand Address = N.getOperand(2);
1319 Select(Chain);
1320
1321 Tmp1 = SelectExpr(Value); //value
1322
1323 if (opcode == ISD::STORE) {
1324 switch(Value.getValueType()) {
1325 default: assert(0 && "unknown Type in store");
1326 case MVT::i32: Opc = PPC::STW; break;
1327 case MVT::f64: Opc = PPC::STFD; break;
1328 case MVT::f32: Opc = PPC::STFS; break;
1329 }
1330 } else { //ISD::TRUNCSTORE
1331 switch(cast<MVTSDNode>(Node)->getExtraValueType()) {
1332 default: assert(0 && "unknown Type in store");
1333 case MVT::i1: //FIXME: DAG does not promote this load
1334 case MVT::i8: Opc = PPC::STB; break;
1335 case MVT::i16: Opc = PPC::STH; break;
1336 }
1337 }
1338
1339 if (Address.getOpcode() == ISD::GlobalAddress)
1340 {
1341 BuildMI(BB, Opc, 2).addReg(Tmp1)
1342 .addGlobalAddress(cast<GlobalAddressSDNode>(Address)->getGlobal());
1343 }
1344 else if(Address.getOpcode() == ISD::FrameIndex)
1345 {
1346 BuildMI(BB, Opc, 2).addReg(Tmp1)
1347 .addFrameIndex(cast<FrameIndexSDNode>(Address)->getIndex());
1348 }
1349 else
1350 {
1351 int offset;
1352 SelectAddr(Address, Tmp2, offset);
1353 BuildMI(BB, Opc, 3).addReg(Tmp1).addImm(offset).addReg(Tmp2);
1354 }
1355 return;
1356 }
1357 case ISD::EXTLOAD:
1358 case ISD::SEXTLOAD:
1359 case ISD::ZEXTLOAD:
1360 case ISD::LOAD:
1361 case ISD::CopyFromReg:
1362 case ISD::CALL:
1363 case ISD::DYNAMIC_STACKALLOC:
1364 ExprMap.erase(N);
1365 SelectExpr(N);
1366 return;
1367 }
1368 assert(0 && "Should not be reached!");
1369}
1370
1371
1372/// createPPC32PatternInstructionSelector - This pass converts an LLVM function
1373/// into a machine code representation using pattern matching and a machine
1374/// description file.
1375///
1376FunctionPass *llvm::createPPC32ISelPattern(TargetMachine &TM) {
1377 return new ISel(TM);
Chris Lattner246fa632005-03-24 06:16:18 +00001378}
1379