blob: 7ccf5cac87f710d107dd3fc94616cd8f084bbf07 [file] [log] [blame]
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001//===-- IA64ISelPattern.cpp - A pattern matching inst selector for IA64 ---===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Duraid Madina and is distributed under the
6// University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines a pattern matching instruction selector for IA64.
11//
12//===----------------------------------------------------------------------===//
13
14#include "IA64.h"
15#include "IA64InstrBuilder.h"
16#include "IA64RegisterInfo.h"
17#include "IA64MachineFunctionInfo.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/MathExtras.h"
29#include "llvm/ADT/Statistic.h"
30#include <set>
31#include <algorithm>
32using namespace llvm;
33
34//===----------------------------------------------------------------------===//
35// IA64TargetLowering - IA64 Implementation of the TargetLowering interface
36namespace {
37 class IA64TargetLowering : public TargetLowering {
38 int VarArgsFrameIndex; // FrameIndex for start of varargs area.
39
40 //int ReturnAddrIndex; // FrameIndex for return slot.
41 unsigned GP, SP, RP; // FIXME - clean this mess up
42 public:
43
44 unsigned VirtGPR; // this is public so it can be accessed in the selector
45 // for ISD::RET down below. add an accessor instead? FIXME
46
47 IA64TargetLowering(TargetMachine &TM) : TargetLowering(TM) {
48
49 // register class for general registers
50 addRegisterClass(MVT::i64, IA64::GRRegisterClass);
51
52 // register class for FP registers
53 addRegisterClass(MVT::f64, IA64::FPRegisterClass);
54
55 // register class for predicate registers
56 addRegisterClass(MVT::i1, IA64::PRRegisterClass);
57
Chris Lattnerda4d4692005-04-09 03:22:37 +000058 setOperationAction(ISD::BRCONDTWOWAY , MVT::Other, Expand);
Duraid Madina9b9d45f2005-03-17 18:17:03 +000059 setOperationAction(ISD::FP_ROUND_INREG , MVT::f32 , Expand);
60
61 setSetCCResultType(MVT::i1);
62 setShiftAmountType(MVT::i64);
63
64 setOperationAction(ISD::EXTLOAD , MVT::i1 , Promote);
Duraid Madina9b9d45f2005-03-17 18:17:03 +000065
66 setOperationAction(ISD::ZEXTLOAD , MVT::i1 , Expand);
67 setOperationAction(ISD::ZEXTLOAD , MVT::i32 , Expand);
68
69 setOperationAction(ISD::SEXTLOAD , MVT::i1 , Expand);
70 setOperationAction(ISD::SEXTLOAD , MVT::i8 , Expand);
71 setOperationAction(ISD::SEXTLOAD , MVT::i16 , Expand);
72
73 setOperationAction(ISD::SREM , MVT::f32 , Expand);
74 setOperationAction(ISD::SREM , MVT::f64 , Expand);
75
76 setOperationAction(ISD::UREM , MVT::f32 , Expand);
77 setOperationAction(ISD::UREM , MVT::f64 , Expand);
78
79 setOperationAction(ISD::MEMMOVE , MVT::Other, Expand);
80 setOperationAction(ISD::MEMSET , MVT::Other, Expand);
81 setOperationAction(ISD::MEMCPY , MVT::Other, Expand);
82
Duraid Madina9b9d45f2005-03-17 18:17:03 +000083 computeRegisterProperties();
84
85 addLegalFPImmediate(+0.0);
86 addLegalFPImmediate(+1.0);
87 addLegalFPImmediate(-0.0);
88 addLegalFPImmediate(-1.0);
89 }
90
91 /// LowerArguments - This hook must be implemented to indicate how we should
92 /// lower the arguments for the specified function, into the specified DAG.
93 virtual std::vector<SDOperand>
94 LowerArguments(Function &F, SelectionDAG &DAG);
95
96 /// LowerCallTo - This hook lowers an abstract call to a function into an
97 /// actual call.
98 virtual std::pair<SDOperand, SDOperand>
Nate Begeman8e21e712005-03-26 01:29:23 +000099 LowerCallTo(SDOperand Chain, const Type *RetTy, bool isVarArg,
100 SDOperand Callee, ArgListTy &Args, SelectionDAG &DAG);
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000101
102 virtual std::pair<SDOperand, SDOperand>
103 LowerVAStart(SDOperand Chain, SelectionDAG &DAG);
104
105 virtual std::pair<SDOperand,SDOperand>
106 LowerVAArgNext(bool isVANext, SDOperand Chain, SDOperand VAList,
107 const Type *ArgTy, SelectionDAG &DAG);
108
109 virtual std::pair<SDOperand, SDOperand>
110 LowerFrameReturnAddress(bool isFrameAddr, SDOperand Chain, unsigned Depth,
111 SelectionDAG &DAG);
112
113 void restoreGP_SP_RP(MachineBasicBlock* BB)
114 {
115 BuildMI(BB, IA64::MOV, 1, IA64::r1).addReg(GP);
116 BuildMI(BB, IA64::MOV, 1, IA64::r12).addReg(SP);
117 BuildMI(BB, IA64::MOV, 1, IA64::rp).addReg(RP);
118 }
119
Duraid Madinabeeaab22005-03-31 12:31:11 +0000120 void restoreSP_RP(MachineBasicBlock* BB)
121 {
122 BuildMI(BB, IA64::MOV, 1, IA64::r12).addReg(SP);
123 BuildMI(BB, IA64::MOV, 1, IA64::rp).addReg(RP);
124 }
125
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000126 void restoreRP(MachineBasicBlock* BB)
127 {
128 BuildMI(BB, IA64::MOV, 1, IA64::rp).addReg(RP);
129 }
130
131 void restoreGP(MachineBasicBlock* BB)
132 {
133 BuildMI(BB, IA64::MOV, 1, IA64::r1).addReg(GP);
134 }
135
136 };
137}
138
139
140std::vector<SDOperand>
141IA64TargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) {
142 std::vector<SDOperand> ArgValues;
143
144 //
145 // add beautiful description of IA64 stack frame format
146 // here (from intel 24535803.pdf most likely)
147 //
148 MachineFunction &MF = DAG.getMachineFunction();
149 MachineFrameInfo *MFI = MF.getFrameInfo();
150
151 GP = MF.getSSARegMap()->createVirtualRegister(getRegClassFor(MVT::i64));
152 SP = MF.getSSARegMap()->createVirtualRegister(getRegClassFor(MVT::i64));
153 RP = MF.getSSARegMap()->createVirtualRegister(getRegClassFor(MVT::i64));
154
155 MachineBasicBlock& BB = MF.front();
156
157 unsigned args_int[] = {IA64::r32, IA64::r33, IA64::r34, IA64::r35,
158 IA64::r36, IA64::r37, IA64::r38, IA64::r39};
159
160 unsigned args_FP[] = {IA64::F8, IA64::F9, IA64::F10, IA64::F11,
161 IA64::F12,IA64::F13,IA64::F14, IA64::F15};
162
163 unsigned argVreg[8];
164 unsigned argPreg[8];
165 unsigned argOpc[8];
166
Duraid Madinabeeaab22005-03-31 12:31:11 +0000167 unsigned used_FPArgs = 0; // how many FP args have been used so far?
168
169 unsigned ArgOffset = 0;
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000170 int count = 0;
Duraid Madinabeeaab22005-03-31 12:31:11 +0000171
Alkis Evlogimenos12cf3852005-03-19 09:22:17 +0000172 for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; ++I)
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000173 {
174 SDOperand newroot, argt;
175 if(count < 8) { // need to fix this logic? maybe.
176
177 switch (getValueType(I->getType())) {
178 default:
179 std::cerr << "ERROR in LowerArgs: unknown type "
180 << getValueType(I->getType()) << "\n";
181 abort();
182 case MVT::f32:
183 // fixme? (well, will need to for weird FP structy stuff,
184 // see intel ABI docs)
185 case MVT::f64:
186 BuildMI(&BB, IA64::IDEF, 0, args_FP[used_FPArgs]);
187 // floating point args go into f8..f15 as-needed, the increment
188 argVreg[count] = // is below..:
189 MF.getSSARegMap()->createVirtualRegister(getRegClassFor(MVT::f64));
190 // FP args go into f8..f15 as needed: (hence the ++)
191 argPreg[count] = args_FP[used_FPArgs++];
192 argOpc[count] = IA64::FMOV;
193 argt = newroot = DAG.getCopyFromReg(argVreg[count],
194 getValueType(I->getType()), DAG.getRoot());
195 break;
196 case MVT::i1: // NOTE: as far as C abi stuff goes,
197 // bools are just boring old ints
198 case MVT::i8:
199 case MVT::i16:
200 case MVT::i32:
201 case MVT::i64:
202 BuildMI(&BB, IA64::IDEF, 0, args_int[count]);
203 argVreg[count] =
204 MF.getSSARegMap()->createVirtualRegister(getRegClassFor(MVT::i64));
205 argPreg[count] = args_int[count];
206 argOpc[count] = IA64::MOV;
207 argt = newroot =
208 DAG.getCopyFromReg(argVreg[count], MVT::i64, DAG.getRoot());
209 if ( getValueType(I->getType()) != MVT::i64)
210 argt = DAG.getNode(ISD::TRUNCATE, getValueType(I->getType()),
211 newroot);
212 break;
213 }
214 } else { // more than 8 args go into the frame
215 // Create the frame index object for this incoming parameter...
Duraid Madinabeeaab22005-03-31 12:31:11 +0000216 ArgOffset = 16 + 8 * (count - 8);
217 int FI = MFI->CreateFixedObject(8, ArgOffset);
218
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000219 // Create the SelectionDAG nodes corresponding to a load
220 //from this parameter
221 SDOperand FIN = DAG.getFrameIndex(FI, MVT::i64);
222 argt = newroot = DAG.getLoad(getValueType(I->getType()),
223 DAG.getEntryNode(), FIN);
224 }
225 ++count;
226 DAG.setRoot(newroot.getValue(1));
227 ArgValues.push_back(argt);
228 }
Duraid Madinabeeaab22005-03-31 12:31:11 +0000229
230
231 // Create a vreg to hold the output of (what will become)
232 // the "alloc" instruction
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000233 VirtGPR = MF.getSSARegMap()->createVirtualRegister(getRegClassFor(MVT::i64));
234 BuildMI(&BB, IA64::PSEUDO_ALLOC, 0, VirtGPR);
235 // we create a PSEUDO_ALLOC (pseudo)instruction for now
236
237 BuildMI(&BB, IA64::IDEF, 0, IA64::r1);
238
239 // hmm:
240 BuildMI(&BB, IA64::IDEF, 0, IA64::r12);
241 BuildMI(&BB, IA64::IDEF, 0, IA64::rp);
242 // ..hmm.
243
244 BuildMI(&BB, IA64::MOV, 1, GP).addReg(IA64::r1);
245
246 // hmm:
247 BuildMI(&BB, IA64::MOV, 1, SP).addReg(IA64::r12);
248 BuildMI(&BB, IA64::MOV, 1, RP).addReg(IA64::rp);
249 // ..hmm.
250
Duraid Madinabeeaab22005-03-31 12:31:11 +0000251 unsigned tempOffset=0;
252
253 // if this is a varargs function, we simply lower llvm.va_start by
254 // pointing to the first entry
255 if(F.isVarArg()) {
256 tempOffset=0;
257 VarArgsFrameIndex = MFI->CreateFixedObject(8, tempOffset);
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000258 }
259
Duraid Madinabeeaab22005-03-31 12:31:11 +0000260 // here we actually do the moving of args, and store them to the stack
261 // too if this is a varargs function:
262 for (int i = 0; i < count && i < 8; ++i) {
263 BuildMI(&BB, argOpc[i], 1, argVreg[i]).addReg(argPreg[i]);
264 if(F.isVarArg()) {
265 // if this is a varargs function, we copy the input registers to the stack
266 int FI = MFI->CreateFixedObject(8, tempOffset);
267 tempOffset+=8; //XXX: is it safe to use r22 like this?
268 BuildMI(&BB, IA64::MOV, 1, IA64::r22).addFrameIndex(FI);
269 // FIXME: we should use st8.spill here, one day
270 BuildMI(&BB, IA64::ST8, 1, IA64::r22).addReg(argPreg[i]);
271 }
272 }
273
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000274 return ArgValues;
275}
276
277std::pair<SDOperand, SDOperand>
278IA64TargetLowering::LowerCallTo(SDOperand Chain,
Nate Begeman8e21e712005-03-26 01:29:23 +0000279 const Type *RetTy, bool isVarArg,
280 SDOperand Callee, ArgListTy &Args, SelectionDAG &DAG) {
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000281
282 MachineFunction &MF = DAG.getMachineFunction();
283
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000284 unsigned NumBytes = 16;
Duraid Madinabeeaab22005-03-31 12:31:11 +0000285 unsigned outRegsUsed = 0;
286
287 if (Args.size() > 8) {
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000288 NumBytes += (Args.size() - 8) * 8;
Duraid Madinabeeaab22005-03-31 12:31:11 +0000289 outRegsUsed = 8;
290 } else {
291 outRegsUsed = Args.size();
292 }
293
294 // FIXME? this WILL fail if we ever try to pass around an arg that
295 // consumes more than a single output slot (a 'real' double, int128
296 // some sort of aggregate etc.), as we'll underestimate how many 'outX'
297 // registers we use. Hopefully, the assembler will notice.
298 MF.getInfo<IA64FunctionInfo>()->outRegsUsed=
299 std::max(outRegsUsed, MF.getInfo<IA64FunctionInfo>()->outRegsUsed);
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000300
301 Chain = DAG.getNode(ISD::ADJCALLSTACKDOWN, MVT::Other, Chain,
302 DAG.getConstant(NumBytes, getPointerTy()));
Duraid Madinabeeaab22005-03-31 12:31:11 +0000303
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000304 std::vector<SDOperand> args_to_use;
305 for (unsigned i = 0, e = Args.size(); i != e; ++i)
306 {
307 switch (getValueType(Args[i].second)) {
308 default: assert(0 && "unexpected argument type!");
309 case MVT::i1:
310 case MVT::i8:
311 case MVT::i16:
312 case MVT::i32:
313 //promote to 64-bits, sign/zero extending based on type
314 //of the argument
315 if(Args[i].second->isSigned())
316 Args[i].first = DAG.getNode(ISD::SIGN_EXTEND, MVT::i64,
317 Args[i].first);
318 else
319 Args[i].first = DAG.getNode(ISD::ZERO_EXTEND, MVT::i64,
320 Args[i].first);
321 break;
322 case MVT::f32:
323 //promote to 64-bits
324 Args[i].first = DAG.getNode(ISD::FP_EXTEND, MVT::f64, Args[i].first);
325 case MVT::f64:
326 case MVT::i64:
327 break;
328 }
329 args_to_use.push_back(Args[i].first);
330 }
331
332 std::vector<MVT::ValueType> RetVals;
333 MVT::ValueType RetTyVT = getValueType(RetTy);
334 if (RetTyVT != MVT::isVoid)
335 RetVals.push_back(RetTyVT);
336 RetVals.push_back(MVT::Other);
337
338 SDOperand TheCall = SDOperand(DAG.getCall(RetVals, Chain,
339 Callee, args_to_use), 0);
340 Chain = TheCall.getValue(RetTyVT != MVT::isVoid);
341 Chain = DAG.getNode(ISD::ADJCALLSTACKUP, MVT::Other, Chain,
342 DAG.getConstant(NumBytes, getPointerTy()));
343 return std::make_pair(TheCall, Chain);
344}
345
346std::pair<SDOperand, SDOperand>
347IA64TargetLowering::LowerVAStart(SDOperand Chain, SelectionDAG &DAG) {
348 // vastart just returns the address of the VarArgsFrameIndex slot.
349 return std::make_pair(DAG.getFrameIndex(VarArgsFrameIndex, MVT::i64), Chain);
350}
351
352std::pair<SDOperand,SDOperand> IA64TargetLowering::
353LowerVAArgNext(bool isVANext, SDOperand Chain, SDOperand VAList,
354 const Type *ArgTy, SelectionDAG &DAG) {
Duraid Madinabeeaab22005-03-31 12:31:11 +0000355
356 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 = 8;
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);
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000373}
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000374
375std::pair<SDOperand, SDOperand> IA64TargetLowering::
376LowerFrameReturnAddress(bool isFrameAddress, SDOperand Chain, unsigned Depth,
377 SelectionDAG &DAG) {
378
379 assert(0 && "LowerFrameReturnAddress not done yet\n");
Duraid Madina817aed42005-03-17 19:00:40 +0000380 abort();
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000381}
382
383
384namespace {
385
386 //===--------------------------------------------------------------------===//
387 /// ISel - IA64 specific code to select IA64 machine instructions for
388 /// SelectionDAG operations.
389 ///
390 class ISel : public SelectionDAGISel {
391 /// IA64Lowering - This object fully describes how to lower LLVM code to an
392 /// IA64-specific SelectionDAG.
393 IA64TargetLowering IA64Lowering;
394
395 /// ExprMap - As shared expressions are codegen'd, we keep track of which
396 /// vreg the value is produced in, so we only emit one copy of each compiled
397 /// tree.
398 std::map<SDOperand, unsigned> ExprMap;
399 std::set<SDOperand> LoweredTokens;
400
401 public:
402 ISel(TargetMachine &TM) : SelectionDAGISel(IA64Lowering), IA64Lowering(TM) {
403 }
404
405 /// InstructionSelectBasicBlock - This callback is invoked by
406 /// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
407 virtual void InstructionSelectBasicBlock(SelectionDAG &DAG);
408
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000409 unsigned SelectExpr(SDOperand N);
410 void Select(SDOperand N);
411 };
412}
413
414/// InstructionSelectBasicBlock - This callback is invoked by SelectionDAGISel
415/// when it has created a SelectionDAG for us to codegen.
416void ISel::InstructionSelectBasicBlock(SelectionDAG &DAG) {
417
418 // Codegen the basic block.
419 Select(DAG.getRoot());
420
421 // Clear state used for selection.
422 ExprMap.clear();
423 LoweredTokens.clear();
424}
425
Duraid Madina4826a072005-04-06 09:55:17 +0000426/// ExactLog2 - This function solves for (Val == 1 << (N-1)) and returns N. It
427/// returns zero when the input is not exactly a power of two.
428static uint64_t ExactLog2(uint64_t Val) {
429 if (Val == 0 || (Val & (Val-1))) return 0;
430 unsigned Count = 0;
431 while (Val != 1) {
432 Val >>= 1;
433 ++Count;
434 }
435 return Count;
436}
437
438/// ponderIntegerDivisionBy - When handling integer divides, if the divide
439/// is by a constant such that we can efficiently codegen it, this
440/// function says what to do. Currently, it returns 0 if the division must
441/// become a genuine divide, and 1 if the division can be turned into a
442/// right shift.
443static unsigned ponderIntegerDivisionBy(SDOperand N, bool isSigned,
444 unsigned& Imm) {
445 if (N.getOpcode() != ISD::Constant) return 0; // if not a divide by
446 // a constant, give up.
447
448 int64_t v = (int64_t)cast<ConstantSDNode>(N)->getSignExtended();
449
450 if ((Imm = ExactLog2(v))) { // if a division by a power of two, say so
451 return 1;
452 }
453
454 return 0; // fallthrough
455}
456
Duraid Madinaf55e4032005-04-07 12:33:38 +0000457static unsigned ponderIntegerAdditionWith(SDOperand N, unsigned& Imm) {
458 if (N.getOpcode() != ISD::Constant) return 0; // if not adding a
459 // constant, give up.
460 int64_t v = (int64_t)cast<ConstantSDNode>(N)->getSignExtended();
461
462 if (v <= 8191 && v >= -8192) { // if this constants fits in 14 bits, say so
463 Imm = v & 0x3FFF; // 14 bits
464 return 1;
465 }
466 return 0; // fallthrough
467}
468
469static unsigned ponderIntegerSubtractionFrom(SDOperand N, unsigned& Imm) {
470 if (N.getOpcode() != ISD::Constant) return 0; // if not subtracting a
471 // constant, give up.
472 int64_t v = (int64_t)cast<ConstantSDNode>(N)->getSignExtended();
473
474 if (v <= 127 && v >= -128) { // if this constants fits in 8 bits, say so
475 Imm = v & 0xFF; // 8 bits
476 return 1;
477 }
478 return 0; // fallthrough
479}
480
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000481unsigned ISel::SelectExpr(SDOperand N) {
482 unsigned Result;
483 unsigned Tmp1, Tmp2, Tmp3;
484 unsigned Opc = 0;
485 MVT::ValueType DestType = N.getValueType();
486
487 unsigned opcode = N.getOpcode();
488
489 SDNode *Node = N.Val;
490 SDOperand Op0, Op1;
491
492 if (Node->getOpcode() == ISD::CopyFromReg)
493 // Just use the specified register as our input.
494 return dyn_cast<RegSDNode>(Node)->getReg();
495
496 unsigned &Reg = ExprMap[N];
497 if (Reg) return Reg;
498
499 if (N.getOpcode() != ISD::CALL)
500 Reg = Result = (N.getValueType() != MVT::Other) ?
501 MakeReg(N.getValueType()) : 1;
502 else {
503 // If this is a call instruction, make sure to prepare ALL of the result
504 // values as well as the chain.
505 if (Node->getNumValues() == 1)
506 Reg = Result = 1; // Void call, just a chain.
507 else {
508 Result = MakeReg(Node->getValueType(0));
509 ExprMap[N.getValue(0)] = Result;
510 for (unsigned i = 1, e = N.Val->getNumValues()-1; i != e; ++i)
511 ExprMap[N.getValue(i)] = MakeReg(Node->getValueType(i));
512 ExprMap[SDOperand(Node, Node->getNumValues()-1)] = 1;
513 }
514 }
515
516 switch (N.getOpcode()) {
517 default:
518 Node->dump();
519 assert(0 && "Node not handled!\n");
520
521 case ISD::FrameIndex: {
522 Tmp1 = cast<FrameIndexSDNode>(N)->getIndex();
523 BuildMI(BB, IA64::MOV, 1, Result).addFrameIndex(Tmp1);
524 return Result;
525 }
526
527 case ISD::ConstantPool: {
528 Tmp1 = cast<ConstantPoolSDNode>(N)->getIndex();
529 IA64Lowering.restoreGP(BB); // FIXME: do i really need this?
530 BuildMI(BB, IA64::ADD, 2, Result).addConstantPoolIndex(Tmp1)
531 .addReg(IA64::r1);
532 return Result;
533 }
534
535 case ISD::ConstantFP: {
536 Tmp1 = Result; // Intermediate Register
537 if (cast<ConstantFPSDNode>(N)->getValue() < 0.0 ||
538 cast<ConstantFPSDNode>(N)->isExactlyValue(-0.0))
539 Tmp1 = MakeReg(MVT::f64);
540
541 if (cast<ConstantFPSDNode>(N)->isExactlyValue(+0.0) ||
542 cast<ConstantFPSDNode>(N)->isExactlyValue(-0.0))
543 BuildMI(BB, IA64::FMOV, 1, Tmp1).addReg(IA64::F0); // load 0.0
544 else if (cast<ConstantFPSDNode>(N)->isExactlyValue(+1.0) ||
545 cast<ConstantFPSDNode>(N)->isExactlyValue(-1.0))
546 BuildMI(BB, IA64::FMOV, 1, Tmp1).addReg(IA64::F1); // load 1.0
547 else
548 assert(0 && "Unexpected FP constant!");
549 if (Tmp1 != Result)
550 // we multiply by +1.0, negate (this is FNMA), and then add 0.0
551 BuildMI(BB, IA64::FNMA, 3, Result).addReg(Tmp1).addReg(IA64::F1)
552 .addReg(IA64::F0);
553 return Result;
554 }
555
556 case ISD::DYNAMIC_STACKALLOC: {
557 // Generate both result values.
558 if (Result != 1)
559 ExprMap[N.getValue(1)] = 1; // Generate the token
560 else
561 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
562
563 // FIXME: We are currently ignoring the requested alignment for handling
564 // greater than the stack alignment. This will need to be revisited at some
565 // point. Align = N.getOperand(2);
566
567 if (!isa<ConstantSDNode>(N.getOperand(2)) ||
568 cast<ConstantSDNode>(N.getOperand(2))->getValue() != 0) {
569 std::cerr << "Cannot allocate stack object with greater alignment than"
570 << " the stack alignment yet!";
571 abort();
572 }
Duraid Madinabeeaab22005-03-31 12:31:11 +0000573
574/*
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000575 Select(N.getOperand(0));
576 if (ConstantSDNode* CN = dyn_cast<ConstantSDNode>(N.getOperand(1)))
577 {
578 if (CN->getValue() < 32000)
579 {
580 BuildMI(BB, IA64::ADDIMM22, 2, IA64::r12).addReg(IA64::r12)
581 .addImm(-CN->getValue());
582 } else {
583 Tmp1 = SelectExpr(N.getOperand(1));
584 // Subtract size from stack pointer, thereby allocating some space.
585 BuildMI(BB, IA64::SUB, 2, IA64::r12).addReg(IA64::r12).addReg(Tmp1);
586 }
587 } else {
588 Tmp1 = SelectExpr(N.getOperand(1));
589 // Subtract size from stack pointer, thereby allocating some space.
590 BuildMI(BB, IA64::SUB, 2, IA64::r12).addReg(IA64::r12).addReg(Tmp1);
591 }
Duraid Madinabeeaab22005-03-31 12:31:11 +0000592*/
593 Select(N.getOperand(0));
594 Tmp1 = SelectExpr(N.getOperand(1));
595 // Subtract size from stack pointer, thereby allocating some space.
596 BuildMI(BB, IA64::SUB, 2, IA64::r12).addReg(IA64::r12).addReg(Tmp1);
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000597 // Put a pointer to the space into the result register, by copying the
598 // stack pointer.
599 BuildMI(BB, IA64::MOV, 1, Result).addReg(IA64::r12);
600 return Result;
601 }
602
603 case ISD::SELECT: {
604 Tmp1 = SelectExpr(N.getOperand(0)); //Cond
605 Tmp2 = SelectExpr(N.getOperand(1)); //Use if TRUE
606 Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE
607
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000608 unsigned bogoResult;
609
610 switch (N.getOperand(1).getValueType()) {
611 default: assert(0 &&
612 "ISD::SELECT: 'select'ing something other than i64 or f64!\n");
613 case MVT::i64:
614 bogoResult=MakeReg(MVT::i64);
615 break;
616 case MVT::f64:
617 bogoResult=MakeReg(MVT::f64);
618 break;
619 }
Duraid Madina69c8e202005-04-01 10:35:00 +0000620
621 BuildMI(BB, IA64::MOV, 1, bogoResult).addReg(Tmp3);
622 BuildMI(BB, IA64::CMOV, 2, Result).addReg(bogoResult).addReg(Tmp2)
623 .addReg(Tmp1); // FIXME: should be FMOV/FCMOV sometimes,
624 // though this will work for now (no JIT)
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000625 return Result;
626 }
627
628 case ISD::Constant: {
629 unsigned depositPos=0;
630 unsigned depositLen=0;
631 switch (N.getValueType()) {
632 default: assert(0 && "Cannot use constants of this type!");
633 case MVT::i1: { // if a bool, we don't 'load' so much as generate
634 // the constant:
635 if(cast<ConstantSDNode>(N)->getValue()) // true:
636 BuildMI(BB, IA64::CMPEQ, 2, Result)
637 .addReg(IA64::r0).addReg(IA64::r0);
638 else // false:
639 BuildMI(BB, IA64::CMPNE, 2, Result)
640 .addReg(IA64::r0).addReg(IA64::r0);
Duraid Madina5ef2ec92005-04-11 05:55:56 +0000641 return Result; // early exit
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000642 }
Duraid Madina5ef2ec92005-04-11 05:55:56 +0000643 case MVT::i64: break;
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000644 }
645
646 int64_t immediate = cast<ConstantSDNode>(N)->getValue();
Duraid Madina5ef2ec92005-04-11 05:55:56 +0000647
648 if(immediate==0) { // if the constant is just zero,
649 BuildMI(BB, IA64::MOV, 1, Result).addReg(IA64::r0); // just copy r0
650 return Result; // early exit
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000651 }
652
Duraid Madina5ef2ec92005-04-11 05:55:56 +0000653 if (immediate <= 8191 && immediate >= -8192) {
654 // if this constants fits in 14 bits, we use a mov the assembler will
655 // turn into: "adds rDest=imm,r0" (and _not_ "andl"...)
656 BuildMI(BB, IA64::MOVSIMM14, 1, Result).addSImm(immediate);
657 return Result; // early exit
658 }
659
660 if (immediate <= 2097151 && immediate >= -2097152) {
661 // if this constants fits in 22 bits, we use a mov the assembler will
662 // turn into: "addl rDest=imm,r0"
663 BuildMI(BB, IA64::MOVSIMM22, 1, Result).addSImm(immediate);
664 return Result; // early exit
665 }
666
667 /* otherwise, our immediate is big, so we use movl */
668 uint64_t Imm = immediate;
Duraid Madina21478e52005-04-11 07:16:39 +0000669 BuildMI(BB, IA64::MOVLIMM64, 1, Result).addImm64(Imm);
Duraid Madina5ef2ec92005-04-11 05:55:56 +0000670 return Result;
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000671 }
Duraid Madina75c9fcb2005-04-02 10:33:53 +0000672
673 case ISD::UNDEF: {
674 BuildMI(BB, IA64::IDEF, 0, Result);
675 return Result;
676 }
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000677
678 case ISD::GlobalAddress: {
679 GlobalValue *GV = cast<GlobalAddressSDNode>(N)->getGlobal();
680 unsigned Tmp1 = MakeReg(MVT::i64);
Duraid Madinabeeaab22005-03-31 12:31:11 +0000681
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000682 BuildMI(BB, IA64::ADD, 2, Tmp1).addGlobalAddress(GV).addReg(IA64::r1);
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000683 BuildMI(BB, IA64::LD8, 1, Result).addReg(Tmp1);
Duraid Madinabeeaab22005-03-31 12:31:11 +0000684
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000685 return Result;
686 }
687
688 case ISD::ExternalSymbol: {
689 const char *Sym = cast<ExternalSymbolSDNode>(N)->getSymbol();
Duraid Madinabeeaab22005-03-31 12:31:11 +0000690// assert(0 && "sorry, but what did you want an ExternalSymbol for again?");
691 BuildMI(BB, IA64::MOV, 1, Result).addExternalSymbol(Sym); // XXX
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000692 return Result;
693 }
694
695 case ISD::FP_EXTEND: {
696 Tmp1 = SelectExpr(N.getOperand(0));
697 BuildMI(BB, IA64::FMOV, 1, Result).addReg(Tmp1);
698 return Result;
699 }
700
701 case ISD::ZERO_EXTEND: {
702 Tmp1 = SelectExpr(N.getOperand(0)); // value
703
704 switch (N.getOperand(0).getValueType()) {
705 default: assert(0 && "Cannot zero-extend this type!");
706 case MVT::i8: Opc = IA64::ZXT1; break;
707 case MVT::i16: Opc = IA64::ZXT2; break;
708 case MVT::i32: Opc = IA64::ZXT4; break;
709
710 // we handle bools differently! :
711 case MVT::i1: { // if the predicate reg has 1, we want a '1' in our GR.
712 unsigned dummy = MakeReg(MVT::i64);
713 // first load zero:
714 BuildMI(BB, IA64::MOV, 1, dummy).addReg(IA64::r0);
715 // ...then conditionally (PR:Tmp1) add 1:
Duraid Madina5ef2ec92005-04-11 05:55:56 +0000716 BuildMI(BB, IA64::TPCADDIMM22, 2, Result).addReg(dummy)
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000717 .addImm(1).addReg(Tmp1);
718 return Result; // XXX early exit!
719 }
720 }
721
722 BuildMI(BB, Opc, 1, Result).addReg(Tmp1);
723 return Result;
724 }
725
726 case ISD::SIGN_EXTEND: { // we should only have to handle i1 -> i64 here!!!
727
728assert(0 && "hmm, ISD::SIGN_EXTEND: shouldn't ever be reached. bad luck!\n");
729
730 Tmp1 = SelectExpr(N.getOperand(0)); // value
731
732 switch (N.getOperand(0).getValueType()) {
733 default: assert(0 && "Cannot sign-extend this type!");
734 case MVT::i1: assert(0 && "trying to sign extend a bool? ow.\n");
735 Opc = IA64::SXT1; break;
736 // FIXME: for now, we treat bools the same as i8s
737 case MVT::i8: Opc = IA64::SXT1; break;
738 case MVT::i16: Opc = IA64::SXT2; break;
739 case MVT::i32: Opc = IA64::SXT4; break;
740 }
741
742 BuildMI(BB, Opc, 1, Result).addReg(Tmp1);
743 return Result;
744 }
745
746 case ISD::TRUNCATE: {
747 // we use the funky dep.z (deposit (zero)) instruction to deposit bits
748 // of R0 appropriately.
749 switch (N.getOperand(0).getValueType()) {
750 default: assert(0 && "Unknown truncate!");
751 case MVT::i64: break;
752 }
753 Tmp1 = SelectExpr(N.getOperand(0));
754 unsigned depositPos, depositLen;
755
756 switch (N.getValueType()) {
757 default: assert(0 && "Unknown truncate!");
758 case MVT::i1: {
759 // if input (normal reg) is 0, 0!=0 -> false (0), if 1, 1!=0 ->true (1):
760 BuildMI(BB, IA64::CMPNE, 2, Result).addReg(Tmp1)
761 .addReg(IA64::r0);
762 return Result; // XXX early exit!
763 }
764 case MVT::i8: depositPos=0; depositLen=8; break;
765 case MVT::i16: depositPos=0; depositLen=16; break;
766 case MVT::i32: depositPos=0; depositLen=32; break;
767 }
768 BuildMI(BB, IA64::DEPZ, 1, Result).addReg(Tmp1)
769 .addImm(depositPos).addImm(depositLen);
770 return Result;
771 }
772
773/*
774 case ISD::FP_ROUND: {
775 assert (DestType == MVT::f32 && N.getOperand(0).getValueType() == MVT::f64 &&
776 "error: trying to FP_ROUND something other than f64 -> f32!\n");
777 Tmp1 = SelectExpr(N.getOperand(0));
778 BuildMI(BB, IA64::FADDS, 2, Result).addReg(Tmp1).addReg(IA64::F0);
779 // we add 0.0 using a single precision add to do rounding
780 return Result;
781 }
782*/
783
784// FIXME: the following 4 cases need cleaning
785 case ISD::SINT_TO_FP: {
786 Tmp1 = SelectExpr(N.getOperand(0));
787 Tmp2 = MakeReg(MVT::f64);
788 unsigned dummy = MakeReg(MVT::f64);
789 BuildMI(BB, IA64::SETFSIG, 1, Tmp2).addReg(Tmp1);
790 BuildMI(BB, IA64::FCVTXF, 1, dummy).addReg(Tmp2);
791 BuildMI(BB, IA64::FNORMD, 1, Result).addReg(dummy);
792 return Result;
793 }
794
795 case ISD::UINT_TO_FP: {
796 Tmp1 = SelectExpr(N.getOperand(0));
797 Tmp2 = MakeReg(MVT::f64);
798 unsigned dummy = MakeReg(MVT::f64);
799 BuildMI(BB, IA64::SETFSIG, 1, Tmp2).addReg(Tmp1);
800 BuildMI(BB, IA64::FCVTXUF, 1, dummy).addReg(Tmp2);
801 BuildMI(BB, IA64::FNORMD, 1, Result).addReg(dummy);
802 return Result;
803 }
804
805 case ISD::FP_TO_SINT: {
806 Tmp1 = SelectExpr(N.getOperand(0));
807 Tmp2 = MakeReg(MVT::f64);
808 BuildMI(BB, IA64::FCVTFXTRUNC, 1, Tmp2).addReg(Tmp1);
809 BuildMI(BB, IA64::GETFSIG, 1, Result).addReg(Tmp2);
810 return Result;
811 }
812
813 case ISD::FP_TO_UINT: {
814 Tmp1 = SelectExpr(N.getOperand(0));
815 Tmp2 = MakeReg(MVT::f64);
816 BuildMI(BB, IA64::FCVTFXUTRUNC, 1, Tmp2).addReg(Tmp1);
817 BuildMI(BB, IA64::GETFSIG, 1, Result).addReg(Tmp2);
818 return Result;
819 }
820
821 case ISD::ADD: {
Duraid Madina4826a072005-04-06 09:55:17 +0000822 if(DestType == MVT::f64 && N.getOperand(0).getOpcode() == ISD::MUL &&
823 N.getOperand(0).Val->hasOneUse()) { // if we can fold this add
824 // into an fma, do so:
825 // ++FusedFP; // Statistic
826 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
827 Tmp2 = SelectExpr(N.getOperand(0).getOperand(1));
828 Tmp3 = SelectExpr(N.getOperand(1));
829 BuildMI(BB, IA64::FMA, 3, Result).addReg(Tmp1).addReg(Tmp2).addReg(Tmp3);
830 return Result; // early exit
831 }
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000832 Tmp1 = SelectExpr(N.getOperand(0));
Duraid Madinaf55e4032005-04-07 12:33:38 +0000833 if(DestType != MVT::f64) { // integer addition:
834 switch (ponderIntegerAdditionWith(N.getOperand(1), Tmp3)) {
835 case 1: // adding a constant that's 14 bits
836 BuildMI(BB, IA64::ADDIMM14, 2, Result).addReg(Tmp1).addSImm(Tmp3);
837 return Result; // early exit
838 } // fallthrough and emit a reg+reg ADD:
Duraid Madina5ef2ec92005-04-11 05:55:56 +0000839 Tmp2 = SelectExpr(N.getOperand(1));
Duraid Madinaf55e4032005-04-07 12:33:38 +0000840 BuildMI(BB, IA64::ADD, 2, Result).addReg(Tmp1).addReg(Tmp2);
841 } else { // this is a floating point addition
Duraid Madina5ef2ec92005-04-11 05:55:56 +0000842 Tmp2 = SelectExpr(N.getOperand(1));
Duraid Madinaf55e4032005-04-07 12:33:38 +0000843 BuildMI(BB, IA64::FADD, 2, Result).addReg(Tmp1).addReg(Tmp2);
844 }
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000845 return Result;
846 }
847
848 case ISD::MUL: {
849 Tmp1 = SelectExpr(N.getOperand(0));
850 Tmp2 = SelectExpr(N.getOperand(1));
Duraid Madina4826a072005-04-06 09:55:17 +0000851
852 if(DestType != MVT::f64) { // TODO: speed!
853 // boring old integer multiply with xma
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000854 unsigned TempFR1=MakeReg(MVT::f64);
855 unsigned TempFR2=MakeReg(MVT::f64);
856 unsigned TempFR3=MakeReg(MVT::f64);
857 BuildMI(BB, IA64::SETFSIG, 1, TempFR1).addReg(Tmp1);
858 BuildMI(BB, IA64::SETFSIG, 1, TempFR2).addReg(Tmp2);
859 BuildMI(BB, IA64::XMAL, 1, TempFR3).addReg(TempFR1).addReg(TempFR2)
860 .addReg(IA64::F0);
861 BuildMI(BB, IA64::GETFSIG, 1, Result).addReg(TempFR3);
862 }
863 else // floating point multiply
864 BuildMI(BB, IA64::FMPY, 2, Result).addReg(Tmp1).addReg(Tmp2);
865 return Result;
866 }
867
868 case ISD::SUB: {
Duraid Madina4826a072005-04-06 09:55:17 +0000869 if(DestType == MVT::f64 && N.getOperand(0).getOpcode() == ISD::MUL &&
870 N.getOperand(0).Val->hasOneUse()) { // if we can fold this sub
871 // into an fms, do so:
872 // ++FusedFP; // Statistic
873 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
874 Tmp2 = SelectExpr(N.getOperand(0).getOperand(1));
875 Tmp3 = SelectExpr(N.getOperand(1));
876 BuildMI(BB, IA64::FMS, 3, Result).addReg(Tmp1).addReg(Tmp2).addReg(Tmp3);
877 return Result; // early exit
878 }
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000879 Tmp2 = SelectExpr(N.getOperand(1));
Duraid Madinaf55e4032005-04-07 12:33:38 +0000880 if(DestType != MVT::f64) { // integer subtraction:
881 switch (ponderIntegerSubtractionFrom(N.getOperand(0), Tmp3)) {
882 case 1: // subtracting *from* an 8 bit constant:
883 BuildMI(BB, IA64::SUBIMM8, 2, Result).addSImm(Tmp3).addReg(Tmp2);
884 return Result; // early exit
885 } // fallthrough and emit a reg+reg SUB:
Duraid Madina5ef2ec92005-04-11 05:55:56 +0000886 Tmp1 = SelectExpr(N.getOperand(0));
Duraid Madinaf55e4032005-04-07 12:33:38 +0000887 BuildMI(BB, IA64::SUB, 2, Result).addReg(Tmp1).addReg(Tmp2);
888 } else { // this is a floating point subtraction
Duraid Madina5ef2ec92005-04-11 05:55:56 +0000889 Tmp1 = SelectExpr(N.getOperand(0));
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000890 BuildMI(BB, IA64::FSUB, 2, Result).addReg(Tmp1).addReg(Tmp2);
Duraid Madinaf55e4032005-04-07 12:33:38 +0000891 }
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000892 return Result;
893 }
Duraid Madinaa7ee8b82005-04-02 05:18:38 +0000894
895 case ISD::FABS: {
896 Tmp1 = SelectExpr(N.getOperand(0));
897 assert(DestType == MVT::f64 && "trying to fabs something other than f64?");
898 BuildMI(BB, IA64::FABS, 1, Result).addReg(Tmp1);
899 return Result;
900 }
901
902 case ISD::FNEG: {
Duraid Madinaa7ee8b82005-04-02 05:18:38 +0000903 assert(DestType == MVT::f64 && "trying to fneg something other than f64?");
Duraid Madina75c9fcb2005-04-02 10:33:53 +0000904
905 if (ISD::FABS == N.getOperand(0).getOpcode()) { // && hasOneUse()?
906 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
907 BuildMI(BB, IA64::FNEGABS, 1, Result).addReg(Tmp1); // fold in abs
908 } else {
909 Tmp1 = SelectExpr(N.getOperand(0));
910 BuildMI(BB, IA64::FNEG, 1, Result).addReg(Tmp1); // plain old fneg
911 }
912
Duraid Madinaa7ee8b82005-04-02 05:18:38 +0000913 return Result;
914 }
915
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000916 case ISD::AND: {
917 switch (N.getValueType()) {
918 default: assert(0 && "Cannot AND this type!");
919 case MVT::i1: { // if a bool, we emit a pseudocode AND
920 unsigned pA = SelectExpr(N.getOperand(0));
921 unsigned pB = SelectExpr(N.getOperand(1));
922
923/* our pseudocode for AND is:
924 *
925(pA) cmp.eq.unc pC,p0 = r0,r0 // pC = pA
926 cmp.eq pTemp,p0 = r0,r0 // pTemp = NOT pB
927 ;;
928(pB) cmp.ne pTemp,p0 = r0,r0
929 ;;
930(pTemp)cmp.ne pC,p0 = r0,r0 // if (NOT pB) pC = 0
931
932*/
933 unsigned pTemp = MakeReg(MVT::i1);
934
935 unsigned bogusTemp1 = MakeReg(MVT::i1);
936 unsigned bogusTemp2 = MakeReg(MVT::i1);
937 unsigned bogusTemp3 = MakeReg(MVT::i1);
938 unsigned bogusTemp4 = MakeReg(MVT::i1);
939
940 BuildMI(BB, IA64::PCMPEQUNC, 3, bogusTemp1)
941 .addReg(IA64::r0).addReg(IA64::r0).addReg(pA);
942 BuildMI(BB, IA64::CMPEQ, 2, bogusTemp2)
943 .addReg(IA64::r0).addReg(IA64::r0);
944 BuildMI(BB, IA64::TPCMPNE, 3, pTemp)
945 .addReg(bogusTemp2).addReg(IA64::r0).addReg(IA64::r0).addReg(pB);
946 BuildMI(BB, IA64::TPCMPNE, 3, Result)
947 .addReg(bogusTemp1).addReg(IA64::r0).addReg(IA64::r0).addReg(pTemp);
948 break;
949 }
950 // if not a bool, we just AND away:
951 case MVT::i8:
952 case MVT::i16:
953 case MVT::i32:
954 case MVT::i64: {
955 Tmp1 = SelectExpr(N.getOperand(0));
956 Tmp2 = SelectExpr(N.getOperand(1));
957 BuildMI(BB, IA64::AND, 2, Result).addReg(Tmp1).addReg(Tmp2);
958 break;
959 }
960 }
961 return Result;
962 }
963
964 case ISD::OR: {
965 switch (N.getValueType()) {
966 default: assert(0 && "Cannot OR this type!");
967 case MVT::i1: { // if a bool, we emit a pseudocode OR
968 unsigned pA = SelectExpr(N.getOperand(0));
969 unsigned pB = SelectExpr(N.getOperand(1));
970
971 unsigned pTemp1 = MakeReg(MVT::i1);
972
973/* our pseudocode for OR is:
974 *
975
976pC = pA OR pB
977-------------
978
979(pA) cmp.eq.unc pC,p0 = r0,r0 // pC = pA
980 ;;
981(pB) cmp.eq pC,p0 = r0,r0 // if (pB) pC = 1
982
983*/
984 BuildMI(BB, IA64::PCMPEQUNC, 3, pTemp1)
985 .addReg(IA64::r0).addReg(IA64::r0).addReg(pA);
986 BuildMI(BB, IA64::TPCMPEQ, 3, Result)
987 .addReg(pTemp1).addReg(IA64::r0).addReg(IA64::r0).addReg(pB);
988 break;
989 }
990 // if not a bool, we just OR away:
991 case MVT::i8:
992 case MVT::i16:
993 case MVT::i32:
994 case MVT::i64: {
995 Tmp1 = SelectExpr(N.getOperand(0));
996 Tmp2 = SelectExpr(N.getOperand(1));
997 BuildMI(BB, IA64::OR, 2, Result).addReg(Tmp1).addReg(Tmp2);
998 break;
999 }
1000 }
1001 return Result;
1002 }
1003
1004 case ISD::XOR: {
1005 switch (N.getValueType()) {
1006 default: assert(0 && "Cannot XOR this type!");
1007 case MVT::i1: { // if a bool, we emit a pseudocode XOR
1008 unsigned pY = SelectExpr(N.getOperand(0));
1009 unsigned pZ = SelectExpr(N.getOperand(1));
1010
1011/* one possible routine for XOR is:
1012
1013 // Compute px = py ^ pz
1014 // using sum of products: px = (py & !pz) | (pz & !py)
1015 // Uses 5 instructions in 3 cycles.
1016 // cycle 1
1017(pz) cmp.eq.unc px = r0, r0 // px = pz
1018(py) cmp.eq.unc pt = r0, r0 // pt = py
1019 ;;
1020 // cycle 2
1021(pt) cmp.ne.and px = r0, r0 // px = px & !pt (px = pz & !pt)
1022(pz) cmp.ne.and pt = r0, r0 // pt = pt & !pz
1023 ;;
1024 } { .mmi
1025 // cycle 3
1026(pt) cmp.eq.or px = r0, r0 // px = px | pt
1027
1028*** Another, which we use here, requires one scratch GR. it is:
1029
1030 mov rt = 0 // initialize rt off critical path
1031 ;;
1032
1033 // cycle 1
1034(pz) cmp.eq.unc px = r0, r0 // px = pz
1035(pz) mov rt = 1 // rt = pz
1036 ;;
1037 // cycle 2
1038(py) cmp.ne px = 1, rt // if (py) px = !pz
1039
1040.. these routines kindly provided by Jim Hull
1041*/
1042 unsigned rt = MakeReg(MVT::i64);
1043
1044 // these two temporaries will never actually appear,
1045 // due to the two-address form of some of the instructions below
1046 unsigned bogoPR = MakeReg(MVT::i1); // becomes Result
1047 unsigned bogoGR = MakeReg(MVT::i64); // becomes rt
1048
1049 BuildMI(BB, IA64::MOV, 1, bogoGR).addReg(IA64::r0);
1050 BuildMI(BB, IA64::PCMPEQUNC, 3, bogoPR)
1051 .addReg(IA64::r0).addReg(IA64::r0).addReg(pZ);
1052 BuildMI(BB, IA64::TPCADDIMM22, 2, rt)
1053 .addReg(bogoGR).addImm(1).addReg(pZ);
1054 BuildMI(BB, IA64::TPCMPIMM8NE, 3, Result)
1055 .addReg(bogoPR).addImm(1).addReg(rt).addReg(pY);
1056 break;
1057 }
1058 // if not a bool, we just XOR away:
1059 case MVT::i8:
1060 case MVT::i16:
1061 case MVT::i32:
1062 case MVT::i64: {
1063 Tmp1 = SelectExpr(N.getOperand(0));
1064 Tmp2 = SelectExpr(N.getOperand(1));
1065 BuildMI(BB, IA64::XOR, 2, Result).addReg(Tmp1).addReg(Tmp2);
1066 break;
1067 }
1068 }
1069 return Result;
1070 }
1071
1072 case ISD::SHL: {
1073 Tmp1 = SelectExpr(N.getOperand(0));
Duraid Madinaf55e4032005-04-07 12:33:38 +00001074 if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1075 Tmp2 = CN->getValue();
1076 BuildMI(BB, IA64::SHLI, 2, Result).addReg(Tmp1).addImm(Tmp2);
1077 } else {
1078 Tmp2 = SelectExpr(N.getOperand(1));
1079 BuildMI(BB, IA64::SHL, 2, Result).addReg(Tmp1).addReg(Tmp2);
1080 }
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001081 return Result;
1082 }
Duraid Madinaf55e4032005-04-07 12:33:38 +00001083
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001084 case ISD::SRL: {
1085 Tmp1 = SelectExpr(N.getOperand(0));
Duraid Madinaf55e4032005-04-07 12:33:38 +00001086 if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1087 Tmp2 = CN->getValue();
1088 BuildMI(BB, IA64::SHRUI, 2, Result).addReg(Tmp1).addImm(Tmp2);
1089 } else {
1090 Tmp2 = SelectExpr(N.getOperand(1));
1091 BuildMI(BB, IA64::SHRU, 2, Result).addReg(Tmp1).addReg(Tmp2);
1092 }
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001093 return Result;
1094 }
Duraid Madinaf55e4032005-04-07 12:33:38 +00001095
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001096 case ISD::SRA: {
1097 Tmp1 = SelectExpr(N.getOperand(0));
Duraid Madinaf55e4032005-04-07 12:33:38 +00001098 if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1099 Tmp2 = CN->getValue();
1100 BuildMI(BB, IA64::SHRSI, 2, Result).addReg(Tmp1).addImm(Tmp2);
1101 } else {
1102 Tmp2 = SelectExpr(N.getOperand(1));
1103 BuildMI(BB, IA64::SHRS, 2, Result).addReg(Tmp1).addReg(Tmp2);
1104 }
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001105 return Result;
1106 }
1107
1108 case ISD::SDIV:
1109 case ISD::UDIV:
1110 case ISD::SREM:
1111 case ISD::UREM: {
1112
1113 Tmp1 = SelectExpr(N.getOperand(0));
1114 Tmp2 = SelectExpr(N.getOperand(1));
1115
1116 bool isFP=false;
1117
1118 if(DestType == MVT::f64) // XXX: we're not gonna be fed MVT::f32, are we?
1119 isFP=true;
1120
1121 bool isModulus=false; // is it a division or a modulus?
1122 bool isSigned=false;
1123
1124 switch(N.getOpcode()) {
1125 case ISD::SDIV: isModulus=false; isSigned=true; break;
1126 case ISD::UDIV: isModulus=false; isSigned=false; break;
1127 case ISD::SREM: isModulus=true; isSigned=true; break;
1128 case ISD::UREM: isModulus=true; isSigned=false; break;
1129 }
1130
Duraid Madina4826a072005-04-06 09:55:17 +00001131 if(!isModulus && !isFP) { // if this is an integer divide,
1132 switch (ponderIntegerDivisionBy(N.getOperand(1), isSigned, Tmp3)) {
1133 case 1: // division by a constant that's a power of 2
1134 Tmp1 = SelectExpr(N.getOperand(0));
Duraid Madina6dcceb52005-04-08 10:01:48 +00001135 if(isSigned) { // argument could be negative, so emit some code:
1136 unsigned divAmt=Tmp3;
1137 unsigned tempGR1=MakeReg(MVT::i64);
1138 unsigned tempGR2=MakeReg(MVT::i64);
1139 unsigned tempGR3=MakeReg(MVT::i64);
1140 BuildMI(BB, IA64::SHRS, 2, tempGR1)
1141 .addReg(Tmp1).addImm(divAmt-1);
1142 BuildMI(BB, IA64::EXTRU, 3, tempGR2)
1143 .addReg(tempGR1).addImm(64-divAmt).addImm(divAmt);
1144 BuildMI(BB, IA64::ADD, 2, tempGR3)
1145 .addReg(Tmp1).addReg(tempGR2);
1146 BuildMI(BB, IA64::SHRS, 2, Result)
1147 .addReg(tempGR3).addImm(divAmt);
1148 }
1149 else // unsigned div-by-power-of-2 becomes a simple shift right:
Duraid Madina4826a072005-04-06 09:55:17 +00001150 BuildMI(BB, IA64::SHRU, 2, Result).addReg(Tmp1).addImm(Tmp3);
1151 return Result; // early exit
1152 }
1153 }
1154
Duraid Madinabeeaab22005-03-31 12:31:11 +00001155 unsigned TmpPR=MakeReg(MVT::i1); // we need two scratch
1156 unsigned TmpPR2=MakeReg(MVT::i1); // predicate registers,
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001157 unsigned TmpF1=MakeReg(MVT::f64); // and one metric truckload of FP regs.
1158 unsigned TmpF2=MakeReg(MVT::f64); // lucky we have IA64?
1159 unsigned TmpF3=MakeReg(MVT::f64); // well, the real FIXME is to have
1160 unsigned TmpF4=MakeReg(MVT::f64); // isTwoAddress forms of these
1161 unsigned TmpF5=MakeReg(MVT::f64); // FP instructions so we can end up with
1162 unsigned TmpF6=MakeReg(MVT::f64); // stuff like setf.sig f10=f10 etc.
1163 unsigned TmpF7=MakeReg(MVT::f64);
1164 unsigned TmpF8=MakeReg(MVT::f64);
1165 unsigned TmpF9=MakeReg(MVT::f64);
1166 unsigned TmpF10=MakeReg(MVT::f64);
1167 unsigned TmpF11=MakeReg(MVT::f64);
1168 unsigned TmpF12=MakeReg(MVT::f64);
1169 unsigned TmpF13=MakeReg(MVT::f64);
1170 unsigned TmpF14=MakeReg(MVT::f64);
1171 unsigned TmpF15=MakeReg(MVT::f64);
Duraid Madinabeeaab22005-03-31 12:31:11 +00001172
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001173 // OK, emit some code:
1174
1175 if(!isFP) {
1176 // first, load the inputs into FP regs.
1177 BuildMI(BB, IA64::SETFSIG, 1, TmpF1).addReg(Tmp1);
1178 BuildMI(BB, IA64::SETFSIG, 1, TmpF2).addReg(Tmp2);
1179
1180 // next, convert the inputs to FP
1181 if(isSigned) {
1182 BuildMI(BB, IA64::FCVTXF, 1, TmpF3).addReg(TmpF1);
1183 BuildMI(BB, IA64::FCVTXF, 1, TmpF4).addReg(TmpF2);
1184 } else {
1185 BuildMI(BB, IA64::FCVTXUFS1, 1, TmpF3).addReg(TmpF1);
1186 BuildMI(BB, IA64::FCVTXUFS1, 1, TmpF4).addReg(TmpF2);
1187 }
1188
1189 } else { // this is an FP divide/remainder, so we 'leak' some temp
1190 // regs and assign TmpF3=Tmp1, TmpF4=Tmp2
1191 TmpF3=Tmp1;
1192 TmpF4=Tmp2;
1193 }
1194
1195 // we start by computing an approximate reciprocal (good to 9 bits?)
Duraid Madina6dcceb52005-04-08 10:01:48 +00001196 // note, this instruction writes _both_ TmpF5 (answer) and TmpPR (predicate)
1197 BuildMI(BB, IA64::FRCPAS1, 4)
1198 .addReg(TmpF5, MachineOperand::Def)
1199 .addReg(TmpPR, MachineOperand::Def)
1200 .addReg(TmpF3).addReg(TmpF4);
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001201
Duraid Madinabeeaab22005-03-31 12:31:11 +00001202 if(!isModulus) { // if this is a divide, we worry about div-by-zero
1203 unsigned bogusPR=MakeReg(MVT::i1); // won't appear, due to twoAddress
1204 // TPCMPNE below
1205 BuildMI(BB, IA64::CMPEQ, 2, bogusPR).addReg(IA64::r0).addReg(IA64::r0);
1206 BuildMI(BB, IA64::TPCMPNE, 3, TmpPR2).addReg(bogusPR)
1207 .addReg(IA64::r0).addReg(IA64::r0).addReg(TmpPR);
1208 }
1209
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001210 // now we apply newton's method, thrice! (FIXME: this is ~72 bits of
1211 // precision, don't need this much for f32/i32)
1212 BuildMI(BB, IA64::CFNMAS1, 4, TmpF6)
1213 .addReg(TmpF4).addReg(TmpF5).addReg(IA64::F1).addReg(TmpPR);
1214 BuildMI(BB, IA64::CFMAS1, 4, TmpF7)
1215 .addReg(TmpF3).addReg(TmpF5).addReg(IA64::F0).addReg(TmpPR);
1216 BuildMI(BB, IA64::CFMAS1, 4, TmpF8)
1217 .addReg(TmpF6).addReg(TmpF6).addReg(IA64::F0).addReg(TmpPR);
1218 BuildMI(BB, IA64::CFMAS1, 4, TmpF9)
1219 .addReg(TmpF6).addReg(TmpF7).addReg(TmpF7).addReg(TmpPR);
1220 BuildMI(BB, IA64::CFMAS1, 4,TmpF10)
1221 .addReg(TmpF6).addReg(TmpF5).addReg(TmpF5).addReg(TmpPR);
1222 BuildMI(BB, IA64::CFMAS1, 4,TmpF11)
1223 .addReg(TmpF8).addReg(TmpF9).addReg(TmpF9).addReg(TmpPR);
1224 BuildMI(BB, IA64::CFMAS1, 4,TmpF12)
1225 .addReg(TmpF8).addReg(TmpF10).addReg(TmpF10).addReg(TmpPR);
1226 BuildMI(BB, IA64::CFNMAS1, 4,TmpF13)
1227 .addReg(TmpF4).addReg(TmpF11).addReg(TmpF3).addReg(TmpPR);
Duraid Madina6e02e682005-04-04 05:05:52 +00001228
1229 // FIXME: this is unfortunate :(
1230 // the story is that the dest reg of the fnma above and the fma below
1231 // (and therefore possibly the src of the fcvt.fx[u] as well) cannot
1232 // be the same register, or this code breaks if the first argument is
1233 // zero. (e.g. without this hack, 0%8 yields -64, not 0.)
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001234 BuildMI(BB, IA64::CFMAS1, 4,TmpF14)
1235 .addReg(TmpF13).addReg(TmpF12).addReg(TmpF11).addReg(TmpPR);
1236
Duraid Madina6e02e682005-04-04 05:05:52 +00001237 if(isModulus) { // XXX: fragile! fixes _only_ mod, *breaks* div! !
1238 BuildMI(BB, IA64::IUSE, 1).addReg(TmpF13); // hack :(
1239 }
1240
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001241 if(!isFP) {
1242 // round to an integer
1243 if(isSigned)
1244 BuildMI(BB, IA64::FCVTFXTRUNCS1, 1, TmpF15).addReg(TmpF14);
1245 else
1246 BuildMI(BB, IA64::FCVTFXUTRUNCS1, 1, TmpF15).addReg(TmpF14);
1247 } else {
1248 BuildMI(BB, IA64::FMOV, 1, TmpF15).addReg(TmpF14);
1249 // EXERCISE: can you see why TmpF15=TmpF14 does not work here, and
1250 // we really do need the above FMOV? ;)
1251 }
1252
1253 if(!isModulus) {
Duraid Madinabeeaab22005-03-31 12:31:11 +00001254 if(isFP) { // extra worrying about div-by-zero
1255 unsigned bogoResult=MakeReg(MVT::f64);
1256
1257 // we do a 'conditional fmov' (of the correct result, depending
1258 // on how the frcpa predicate turned out)
1259 BuildMI(BB, IA64::PFMOV, 2, bogoResult)
1260 .addReg(TmpF12).addReg(TmpPR2);
1261 BuildMI(BB, IA64::CFMOV, 2, Result)
1262 .addReg(bogoResult).addReg(TmpF15).addReg(TmpPR);
1263 }
Duraid Madina6e02e682005-04-04 05:05:52 +00001264 else {
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001265 BuildMI(BB, IA64::GETFSIG, 1, Result).addReg(TmpF15);
Duraid Madina6e02e682005-04-04 05:05:52 +00001266 }
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001267 } else { // this is a modulus
1268 if(!isFP) {
1269 // answer = q * (-b) + a
1270 unsigned ModulusResult = MakeReg(MVT::f64);
1271 unsigned TmpF = MakeReg(MVT::f64);
1272 unsigned TmpI = MakeReg(MVT::i64);
Duraid Madina6e02e682005-04-04 05:05:52 +00001273
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001274 BuildMI(BB, IA64::SUB, 2, TmpI).addReg(IA64::r0).addReg(Tmp2);
1275 BuildMI(BB, IA64::SETFSIG, 1, TmpF).addReg(TmpI);
1276 BuildMI(BB, IA64::XMAL, 3, ModulusResult)
1277 .addReg(TmpF15).addReg(TmpF).addReg(TmpF1);
1278 BuildMI(BB, IA64::GETFSIG, 1, Result).addReg(ModulusResult);
1279 } else { // FP modulus! The horror... the horror....
1280 assert(0 && "sorry, no FP modulus just yet!\n!\n");
1281 }
1282 }
1283
1284 return Result;
1285 }
1286
1287 case ISD::ZERO_EXTEND_INREG: {
1288 Tmp1 = SelectExpr(N.getOperand(0));
1289 MVTSDNode* MVN = dyn_cast<MVTSDNode>(Node);
1290 switch(MVN->getExtraValueType())
1291 {
1292 default:
1293 Node->dump();
1294 assert(0 && "don't know how to zero extend this type");
1295 break;
1296 case MVT::i8: Opc = IA64::ZXT1; break;
1297 case MVT::i16: Opc = IA64::ZXT2; break;
1298 case MVT::i32: Opc = IA64::ZXT4; break;
1299 }
1300 BuildMI(BB, Opc, 1, Result).addReg(Tmp1);
1301 return Result;
1302 }
1303
1304 case ISD::SIGN_EXTEND_INREG: {
1305 Tmp1 = SelectExpr(N.getOperand(0));
1306 MVTSDNode* MVN = dyn_cast<MVTSDNode>(Node);
1307 switch(MVN->getExtraValueType())
1308 {
1309 default:
1310 Node->dump();
1311 assert(0 && "don't know how to sign extend this type");
1312 break;
1313 case MVT::i8: Opc = IA64::SXT1; break;
1314 case MVT::i16: Opc = IA64::SXT2; break;
1315 case MVT::i32: Opc = IA64::SXT4; break;
1316 }
1317 BuildMI(BB, Opc, 1, Result).addReg(Tmp1);
1318 return Result;
1319 }
1320
1321 case ISD::SETCC: {
1322 Tmp1 = SelectExpr(N.getOperand(0));
Duraid Madina5ef2ec92005-04-11 05:55:56 +00001323
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001324 if (SetCCSDNode *SetCC = dyn_cast<SetCCSDNode>(Node)) {
1325 if (MVT::isInteger(SetCC->getOperand(0).getValueType())) {
Duraid Madina5ef2ec92005-04-11 05:55:56 +00001326
1327 if(ConstantSDNode *CSDN =
1328 dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1329 // if we are comparing against a constant zero
1330 if(CSDN->getValue()==0)
1331 Tmp2 = IA64::r0; // then we can just compare against r0
1332 else
1333 Tmp2 = SelectExpr(N.getOperand(1));
1334 } else // not comparing against a constant
1335 Tmp2 = SelectExpr(N.getOperand(1));
1336
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001337 switch (SetCC->getCondition()) {
1338 default: assert(0 && "Unknown integer comparison!");
1339 case ISD::SETEQ:
1340 BuildMI(BB, IA64::CMPEQ, 2, Result).addReg(Tmp1).addReg(Tmp2);
1341 break;
1342 case ISD::SETGT:
1343 BuildMI(BB, IA64::CMPGT, 2, Result).addReg(Tmp1).addReg(Tmp2);
1344 break;
1345 case ISD::SETGE:
1346 BuildMI(BB, IA64::CMPGE, 2, Result).addReg(Tmp1).addReg(Tmp2);
1347 break;
1348 case ISD::SETLT:
1349 BuildMI(BB, IA64::CMPLT, 2, Result).addReg(Tmp1).addReg(Tmp2);
1350 break;
1351 case ISD::SETLE:
1352 BuildMI(BB, IA64::CMPLE, 2, Result).addReg(Tmp1).addReg(Tmp2);
1353 break;
1354 case ISD::SETNE:
1355 BuildMI(BB, IA64::CMPNE, 2, Result).addReg(Tmp1).addReg(Tmp2);
1356 break;
1357 case ISD::SETULT:
1358 BuildMI(BB, IA64::CMPLTU, 2, Result).addReg(Tmp1).addReg(Tmp2);
1359 break;
1360 case ISD::SETUGT:
1361 BuildMI(BB, IA64::CMPGTU, 2, Result).addReg(Tmp1).addReg(Tmp2);
1362 break;
1363 case ISD::SETULE:
1364 BuildMI(BB, IA64::CMPLEU, 2, Result).addReg(Tmp1).addReg(Tmp2);
1365 break;
1366 case ISD::SETUGE:
1367 BuildMI(BB, IA64::CMPGEU, 2, Result).addReg(Tmp1).addReg(Tmp2);
1368 break;
1369 }
1370 }
1371 else { // if not integer, should be FP. FIXME: what about bools? ;)
1372 assert(SetCC->getOperand(0).getValueType() != MVT::f32 &&
1373 "error: SETCC should have had incoming f32 promoted to f64!\n");
Duraid Madina5ef2ec92005-04-11 05:55:56 +00001374
1375 if(ConstantFPSDNode *CFPSDN =
1376 dyn_cast<ConstantFPSDNode>(N.getOperand(1))) {
1377
1378 // if we are comparing against a constant +0.0 or +1.0
1379 if(CFPSDN->isExactlyValue(+0.0))
1380 Tmp2 = IA64::F0; // then we can just compare against f0
1381 else if(CFPSDN->isExactlyValue(+1.0))
1382 Tmp2 = IA64::F1; // or f1
1383 else
1384 Tmp2 = SelectExpr(N.getOperand(1));
1385 } else // not comparing against a constant
1386 Tmp2 = SelectExpr(N.getOperand(1));
1387
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001388 switch (SetCC->getCondition()) {
1389 default: assert(0 && "Unknown FP comparison!");
1390 case ISD::SETEQ:
1391 BuildMI(BB, IA64::FCMPEQ, 2, Result).addReg(Tmp1).addReg(Tmp2);
1392 break;
1393 case ISD::SETGT:
1394 BuildMI(BB, IA64::FCMPGT, 2, Result).addReg(Tmp1).addReg(Tmp2);
1395 break;
1396 case ISD::SETGE:
1397 BuildMI(BB, IA64::FCMPGE, 2, Result).addReg(Tmp1).addReg(Tmp2);
1398 break;
1399 case ISD::SETLT:
1400 BuildMI(BB, IA64::FCMPLT, 2, Result).addReg(Tmp1).addReg(Tmp2);
1401 break;
1402 case ISD::SETLE:
1403 BuildMI(BB, IA64::FCMPLE, 2, Result).addReg(Tmp1).addReg(Tmp2);
1404 break;
1405 case ISD::SETNE:
1406 BuildMI(BB, IA64::FCMPNE, 2, Result).addReg(Tmp1).addReg(Tmp2);
1407 break;
1408 case ISD::SETULT:
1409 BuildMI(BB, IA64::FCMPLTU, 2, Result).addReg(Tmp1).addReg(Tmp2);
1410 break;
1411 case ISD::SETUGT:
1412 BuildMI(BB, IA64::FCMPGTU, 2, Result).addReg(Tmp1).addReg(Tmp2);
1413 break;
1414 case ISD::SETULE:
1415 BuildMI(BB, IA64::FCMPLEU, 2, Result).addReg(Tmp1).addReg(Tmp2);
1416 break;
1417 case ISD::SETUGE:
1418 BuildMI(BB, IA64::FCMPGEU, 2, Result).addReg(Tmp1).addReg(Tmp2);
1419 break;
1420 }
1421 }
1422 }
1423 else
1424 assert(0 && "this setcc not implemented yet");
1425
1426 return Result;
1427 }
1428
1429 case ISD::EXTLOAD:
1430 case ISD::ZEXTLOAD:
1431 case ISD::LOAD: {
1432 // Make sure we generate both values.
1433 if (Result != 1)
1434 ExprMap[N.getValue(1)] = 1; // Generate the token
1435 else
1436 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
1437
1438 bool isBool=false;
1439
1440 if(opcode == ISD::LOAD) { // this is a LOAD
1441 switch (Node->getValueType(0)) {
1442 default: assert(0 && "Cannot load this type!");
1443 case MVT::i1: Opc = IA64::LD1; isBool=true; break;
1444 // FIXME: for now, we treat bool loads the same as i8 loads */
1445 case MVT::i8: Opc = IA64::LD1; break;
1446 case MVT::i16: Opc = IA64::LD2; break;
1447 case MVT::i32: Opc = IA64::LD4; break;
1448 case MVT::i64: Opc = IA64::LD8; break;
1449
1450 case MVT::f32: Opc = IA64::LDF4; break;
1451 case MVT::f64: Opc = IA64::LDF8; break;
1452 }
1453 } else { // this is an EXTLOAD or ZEXTLOAD
1454 MVT::ValueType TypeBeingLoaded = cast<MVTSDNode>(Node)->getExtraValueType();
1455 switch (TypeBeingLoaded) {
1456 default: assert(0 && "Cannot extload/zextload this type!");
1457 // FIXME: bools?
1458 case MVT::i8: Opc = IA64::LD1; break;
1459 case MVT::i16: Opc = IA64::LD2; break;
1460 case MVT::i32: Opc = IA64::LD4; break;
1461 case MVT::f32: Opc = IA64::LDF4; break;
1462 }
1463 }
1464
1465 SDOperand Chain = N.getOperand(0);
1466 SDOperand Address = N.getOperand(1);
1467
1468 if(Address.getOpcode() == ISD::GlobalAddress) {
1469 Select(Chain);
1470 unsigned dummy = MakeReg(MVT::i64);
1471 unsigned dummy2 = MakeReg(MVT::i64);
1472 BuildMI(BB, IA64::ADD, 2, dummy)
1473 .addGlobalAddress(cast<GlobalAddressSDNode>(Address)->getGlobal())
1474 .addReg(IA64::r1);
1475 BuildMI(BB, IA64::LD8, 1, dummy2).addReg(dummy);
1476 if(!isBool)
1477 BuildMI(BB, Opc, 1, Result).addReg(dummy2);
1478 else { // emit a little pseudocode to load a bool (stored in one byte)
1479 // into a predicate register
1480 assert(Opc==IA64::LD1 && "problem loading a bool");
1481 unsigned dummy3 = MakeReg(MVT::i64);
1482 BuildMI(BB, Opc, 1, dummy3).addReg(dummy2);
1483 // we compare to 0. true? 0. false? 1.
1484 BuildMI(BB, IA64::CMPNE, 2, Result).addReg(dummy3).addReg(IA64::r0);
1485 }
1486 } else if(ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(Address)) {
1487 Select(Chain);
1488 IA64Lowering.restoreGP(BB);
1489 unsigned dummy = MakeReg(MVT::i64);
1490 BuildMI(BB, IA64::ADD, 2, dummy).addConstantPoolIndex(CP->getIndex())
1491 .addReg(IA64::r1); // CPI+GP
1492 if(!isBool)
1493 BuildMI(BB, Opc, 1, Result).addReg(dummy);
1494 else { // emit a little pseudocode to load a bool (stored in one byte)
1495 // into a predicate register
1496 assert(Opc==IA64::LD1 && "problem loading a bool");
1497 unsigned dummy3 = MakeReg(MVT::i64);
1498 BuildMI(BB, Opc, 1, dummy3).addReg(dummy);
1499 // we compare to 0. true? 0. false? 1.
1500 BuildMI(BB, IA64::CMPNE, 2, Result).addReg(dummy3).addReg(IA64::r0);
1501 }
1502 } else if(Address.getOpcode() == ISD::FrameIndex) {
1503 Select(Chain); // FIXME ? what about bools?
1504 unsigned dummy = MakeReg(MVT::i64);
1505 BuildMI(BB, IA64::MOV, 1, dummy)
1506 .addFrameIndex(cast<FrameIndexSDNode>(Address)->getIndex());
1507 if(!isBool)
1508 BuildMI(BB, Opc, 1, Result).addReg(dummy);
1509 else { // emit a little pseudocode to load a bool (stored in one byte)
1510 // into a predicate register
1511 assert(Opc==IA64::LD1 && "problem loading a bool");
1512 unsigned dummy3 = MakeReg(MVT::i64);
1513 BuildMI(BB, Opc, 1, dummy3).addReg(dummy);
1514 // we compare to 0. true? 0. false? 1.
1515 BuildMI(BB, IA64::CMPNE, 2, Result).addReg(dummy3).addReg(IA64::r0);
1516 }
1517 } else { // none of the above...
1518 Select(Chain);
1519 Tmp2 = SelectExpr(Address);
1520 if(!isBool)
1521 BuildMI(BB, Opc, 1, Result).addReg(Tmp2);
1522 else { // emit a little pseudocode to load a bool (stored in one byte)
1523 // into a predicate register
1524 assert(Opc==IA64::LD1 && "problem loading a bool");
1525 unsigned dummy = MakeReg(MVT::i64);
1526 BuildMI(BB, Opc, 1, dummy).addReg(Tmp2);
1527 // we compare to 0. true? 0. false? 1.
1528 BuildMI(BB, IA64::CMPNE, 2, Result).addReg(dummy).addReg(IA64::r0);
1529 }
1530 }
1531
1532 return Result;
1533 }
1534
1535 case ISD::CopyFromReg: {
1536 if (Result == 1)
1537 Result = ExprMap[N.getValue(0)] =
1538 MakeReg(N.getValue(0).getValueType());
1539
1540 SDOperand Chain = N.getOperand(0);
1541
1542 Select(Chain);
1543 unsigned r = dyn_cast<RegSDNode>(Node)->getReg();
1544
1545 if(N.getValueType() == MVT::i1) // if a bool, we use pseudocode
1546 BuildMI(BB, IA64::PCMPEQUNC, 3, Result)
1547 .addReg(IA64::r0).addReg(IA64::r0).addReg(r);
1548 // (r) Result =cmp.eq.unc(r0,r0)
1549 else
1550 BuildMI(BB, IA64::MOV, 1, Result).addReg(r); // otherwise MOV
1551 return Result;
1552 }
1553
1554 case ISD::CALL: {
1555 Select(N.getOperand(0));
1556
1557 // The chain for this call is now lowered.
1558 ExprMap.insert(std::make_pair(N.getValue(Node->getNumValues()-1), 1));
1559
1560 //grab the arguments
1561 std::vector<unsigned> argvregs;
1562
1563 for(int i = 2, e = Node->getNumOperands(); i < e; ++i)
1564 argvregs.push_back(SelectExpr(N.getOperand(i)));
1565
1566 // see section 8.5.8 of "Itanium Software Conventions and
1567 // Runtime Architecture Guide to see some examples of what's going
1568 // on here. (in short: int args get mapped 1:1 'slot-wise' to out0->out7,
1569 // while FP args get mapped to F8->F15 as needed)
1570
1571 unsigned used_FPArgs=0; // how many FP Args have been used so far?
1572
1573 // in reg args
1574 for(int i = 0, e = std::min(8, (int)argvregs.size()); i < e; ++i)
1575 {
1576 unsigned intArgs[] = {IA64::out0, IA64::out1, IA64::out2, IA64::out3,
1577 IA64::out4, IA64::out5, IA64::out6, IA64::out7 };
1578 unsigned FPArgs[] = {IA64::F8, IA64::F9, IA64::F10, IA64::F11,
1579 IA64::F12, IA64::F13, IA64::F14, IA64::F15 };
1580
1581 switch(N.getOperand(i+2).getValueType())
1582 {
1583 default: // XXX do we need to support MVT::i1 here?
1584 Node->dump();
1585 N.getOperand(i).Val->dump();
1586 std::cerr << "Type for " << i << " is: " <<
1587 N.getOperand(i+2).getValueType() << std::endl;
1588 assert(0 && "Unknown value type for call");
1589 case MVT::i64:
1590 BuildMI(BB, IA64::MOV, 1, intArgs[i]).addReg(argvregs[i]);
1591 break;
1592 case MVT::f64:
1593 BuildMI(BB, IA64::FMOV, 1, FPArgs[used_FPArgs++])
1594 .addReg(argvregs[i]);
Duraid Madinabeeaab22005-03-31 12:31:11 +00001595 // FIXME: we don't need to do this _all_ the time:
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001596 BuildMI(BB, IA64::GETFD, 1, intArgs[i]).addReg(argvregs[i]);
1597 break;
1598 }
1599 }
1600
1601 //in mem args
1602 for (int i = 8, e = argvregs.size(); i < e; ++i)
1603 {
1604 unsigned tempAddr = MakeReg(MVT::i64);
1605
1606 switch(N.getOperand(i+2).getValueType()) {
1607 default:
1608 Node->dump();
1609 N.getOperand(i).Val->dump();
1610 std::cerr << "Type for " << i << " is: " <<
1611 N.getOperand(i+2).getValueType() << "\n";
1612 assert(0 && "Unknown value type for call");
1613 case MVT::i1: // FIXME?
1614 case MVT::i8:
1615 case MVT::i16:
1616 case MVT::i32:
1617 case MVT::i64:
1618 BuildMI(BB, IA64::ADDIMM22, 2, tempAddr)
1619 .addReg(IA64::r12).addImm(16 + (i - 8) * 8); // r12 is SP
1620 BuildMI(BB, IA64::ST8, 2).addReg(tempAddr).addReg(argvregs[i]);
1621 break;
1622 case MVT::f32:
1623 case MVT::f64:
1624 BuildMI(BB, IA64::ADDIMM22, 2, tempAddr)
1625 .addReg(IA64::r12).addImm(16 + (i - 8) * 8); // r12 is SP
1626 BuildMI(BB, IA64::STF8, 2).addReg(tempAddr).addReg(argvregs[i]);
1627 break;
1628 }
1629 }
Duraid Madinabeeaab22005-03-31 12:31:11 +00001630
1631 /* XXX we want to re-enable direct branches! crippling them now
1632 * to stress-test indirect branches.:
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001633 //build the right kind of call
1634 if (GlobalAddressSDNode *GASD =
1635 dyn_cast<GlobalAddressSDNode>(N.getOperand(1)))
1636 {
1637 BuildMI(BB, IA64::BRCALL, 1).addGlobalAddress(GASD->getGlobal(),true);
1638 IA64Lowering.restoreGP_SP_RP(BB);
1639 }
Duraid Madinabeeaab22005-03-31 12:31:11 +00001640 ^^^^^^^^^^^^^ we want this code one day XXX */
1641 if (ExternalSymbolSDNode *ESSDN =
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001642 dyn_cast<ExternalSymbolSDNode>(N.getOperand(1)))
Duraid Madinabeeaab22005-03-31 12:31:11 +00001643 { // FIXME : currently need this case for correctness, to avoid
1644 // "non-pic code with imm relocation against dynamic symbol" errors
1645 BuildMI(BB, IA64::BRCALL, 1)
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001646 .addExternalSymbol(ESSDN->getSymbol(), true);
1647 IA64Lowering.restoreGP_SP_RP(BB);
1648 }
1649 else {
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001650 Tmp1 = SelectExpr(N.getOperand(1));
Duraid Madinabeeaab22005-03-31 12:31:11 +00001651
1652 unsigned targetEntryPoint=MakeReg(MVT::i64);
1653 unsigned targetGPAddr=MakeReg(MVT::i64);
1654 unsigned currentGP=MakeReg(MVT::i64);
1655
1656 // b6 is a scratch branch register, we load the target entry point
1657 // from the base of the function descriptor
1658 BuildMI(BB, IA64::LD8, 1, targetEntryPoint).addReg(Tmp1);
1659 BuildMI(BB, IA64::MOV, 1, IA64::B6).addReg(targetEntryPoint);
1660
1661 // save the current GP:
1662 BuildMI(BB, IA64::MOV, 1, currentGP).addReg(IA64::r1);
1663
1664 /* TODO: we need to make sure doing this never, ever loads a
1665 * bogus value into r1 (GP). */
1666 // load the target GP (which is at mem[functiondescriptor+8])
1667 BuildMI(BB, IA64::ADDIMM22, 2, targetGPAddr)
1668 .addReg(Tmp1).addImm(8); // FIXME: addimm22? why not postincrement ld
1669 BuildMI(BB, IA64::LD8, 1, IA64::r1).addReg(targetGPAddr);
1670
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001671 // and then jump: (well, call)
1672 BuildMI(BB, IA64::BRCALL, 1).addReg(IA64::B6);
Duraid Madinabeeaab22005-03-31 12:31:11 +00001673 // and finally restore the old GP
1674 BuildMI(BB, IA64::MOV, 1, IA64::r1).addReg(currentGP);
1675 IA64Lowering.restoreSP_RP(BB);
1676 }
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001677
1678 switch (Node->getValueType(0)) {
1679 default: assert(0 && "Unknown value type for call result!");
1680 case MVT::Other: return 1;
1681 case MVT::i1:
1682 BuildMI(BB, IA64::CMPNE, 2, Result)
1683 .addReg(IA64::r8).addReg(IA64::r0);
1684 break;
1685 case MVT::i8:
1686 case MVT::i16:
1687 case MVT::i32:
1688 case MVT::i64:
1689 BuildMI(BB, IA64::MOV, 1, Result).addReg(IA64::r8);
1690 break;
1691 case MVT::f64:
1692 BuildMI(BB, IA64::FMOV, 1, Result).addReg(IA64::F8);
1693 break;
1694 }
1695 return Result+N.ResNo;
1696 }
1697
1698 } // <- uhhh XXX
1699 return 0;
1700}
1701
1702void ISel::Select(SDOperand N) {
1703 unsigned Tmp1, Tmp2, Opc;
1704 unsigned opcode = N.getOpcode();
1705
Nate Begeman85fdeb22005-03-24 04:39:54 +00001706 if (!LoweredTokens.insert(N).second)
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001707 return; // Already selected.
1708
1709 SDNode *Node = N.Val;
1710
1711 switch (Node->getOpcode()) {
1712 default:
1713 Node->dump(); std::cerr << "\n";
1714 assert(0 && "Node not handled yet!");
1715
1716 case ISD::EntryToken: return; // Noop
1717
1718 case ISD::TokenFactor: {
1719 for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i)
1720 Select(Node->getOperand(i));
1721 return;
1722 }
1723
1724 case ISD::CopyToReg: {
1725 Select(N.getOperand(0));
1726 Tmp1 = SelectExpr(N.getOperand(1));
1727 Tmp2 = cast<RegSDNode>(N)->getReg();
1728
1729 if (Tmp1 != Tmp2) {
1730 if(N.getValueType() == MVT::i1) // if a bool, we use pseudocode
1731 BuildMI(BB, IA64::PCMPEQUNC, 3, Tmp2)
1732 .addReg(IA64::r0).addReg(IA64::r0).addReg(Tmp1);
1733 // (Tmp1) Tmp2 = cmp.eq.unc(r0,r0)
1734 else
1735 BuildMI(BB, IA64::MOV, 1, Tmp2).addReg(Tmp1);
1736 // XXX is this the right way 'round? ;)
1737 }
1738 return;
1739 }
1740
1741 case ISD::RET: {
1742
1743 /* what the heck is going on here:
1744
1745<_sabre_> ret with two operands is obvious: chain and value
1746<camel_> yep
1747<_sabre_> ret with 3 values happens when 'expansion' occurs
1748<_sabre_> e.g. i64 gets split into 2x i32
1749<camel_> oh right
1750<_sabre_> you don't have this case on ia64
1751<camel_> yep
1752<_sabre_> so the two returned values go into EAX/EDX on ia32
1753<camel_> ahhh *memories*
1754<_sabre_> :)
1755<camel_> ok, thanks :)
1756<_sabre_> so yeah, everything that has a side effect takes a 'token chain'
1757<_sabre_> this is the first operand always
1758<_sabre_> these operand often define chains, they are the last operand
1759<_sabre_> they are printed as 'ch' if you do DAG.dump()
1760 */
1761
1762 switch (N.getNumOperands()) {
1763 default:
1764 assert(0 && "Unknown return instruction!");
1765 case 2:
1766 Select(N.getOperand(0));
1767 Tmp1 = SelectExpr(N.getOperand(1));
1768 switch (N.getOperand(1).getValueType()) {
1769 default: assert(0 && "All other types should have been promoted!!");
1770 // FIXME: do I need to add support for bools here?
1771 // (return '0' or '1' r8, basically...)
1772 case MVT::i64:
1773 BuildMI(BB, IA64::MOV, 1, IA64::r8).addReg(Tmp1);
1774 break;
1775 case MVT::f64:
1776 BuildMI(BB, IA64::FMOV, 1, IA64::F8).addReg(Tmp1);
1777 }
1778 break;
1779 case 1:
1780 Select(N.getOperand(0));
1781 break;
1782 }
1783 // before returning, restore the ar.pfs register (set by the 'alloc' up top)
1784 BuildMI(BB, IA64::MOV, 1).addReg(IA64::AR_PFS).addReg(IA64Lowering.VirtGPR);
1785 BuildMI(BB, IA64::RET, 0); // and then just emit a 'ret' instruction
1786 return;
1787 }
1788
1789 case ISD::BR: {
1790 Select(N.getOperand(0));
1791 MachineBasicBlock *Dest =
1792 cast<BasicBlockSDNode>(N.getOperand(1))->getBasicBlock();
1793 BuildMI(BB, IA64::BRLCOND_NOTCALL, 1).addReg(IA64::p0).addMBB(Dest);
1794 // XXX HACK! we do _not_ need long branches all the time
1795 return;
1796 }
1797
1798 case ISD::ImplicitDef: {
1799 Select(N.getOperand(0));
1800 BuildMI(BB, IA64::IDEF, 0, cast<RegSDNode>(N)->getReg());
1801 return;
1802 }
1803
1804 case ISD::BRCOND: {
1805 MachineBasicBlock *Dest =
1806 cast<BasicBlockSDNode>(N.getOperand(2))->getBasicBlock();
1807
1808 Select(N.getOperand(0));
1809 Tmp1 = SelectExpr(N.getOperand(1));
1810 BuildMI(BB, IA64::BRLCOND_NOTCALL, 1).addReg(Tmp1).addMBB(Dest);
1811 // XXX HACK! we do _not_ need long branches all the time
1812 return;
1813 }
1814
1815 case ISD::EXTLOAD:
1816 case ISD::ZEXTLOAD:
1817 case ISD::SEXTLOAD:
1818 case ISD::LOAD:
1819 case ISD::CALL:
1820 case ISD::CopyFromReg:
1821 case ISD::DYNAMIC_STACKALLOC:
1822 SelectExpr(N);
1823 return;
1824
1825 case ISD::TRUNCSTORE:
1826 case ISD::STORE: {
1827 Select(N.getOperand(0));
1828 Tmp1 = SelectExpr(N.getOperand(1)); // value
1829
1830 bool isBool=false;
1831
1832 if(opcode == ISD::STORE) {
1833 switch (N.getOperand(1).getValueType()) {
1834 default: assert(0 && "Cannot store this type!");
1835 case MVT::i1: Opc = IA64::ST1; isBool=true; break;
1836 // FIXME?: for now, we treat bool loads the same as i8 stores */
1837 case MVT::i8: Opc = IA64::ST1; break;
1838 case MVT::i16: Opc = IA64::ST2; break;
1839 case MVT::i32: Opc = IA64::ST4; break;
1840 case MVT::i64: Opc = IA64::ST8; break;
1841
1842 case MVT::f32: Opc = IA64::STF4; break;
1843 case MVT::f64: Opc = IA64::STF8; break;
1844 }
1845 } else { // truncstore
1846 switch(cast<MVTSDNode>(Node)->getExtraValueType()) {
1847 default: assert(0 && "unknown type in truncstore");
1848 case MVT::i1: Opc = IA64::ST1; isBool=true; break;
1849 //FIXME: DAG does not promote this load?
1850 case MVT::i8: Opc = IA64::ST1; break;
1851 case MVT::i16: Opc = IA64::ST2; break;
1852 case MVT::i32: Opc = IA64::ST4; break;
1853 case MVT::f32: Opc = IA64::STF4; break;
1854 }
1855 }
1856
1857 if(N.getOperand(2).getOpcode() == ISD::GlobalAddress) {
1858 unsigned dummy = MakeReg(MVT::i64);
1859 unsigned dummy2 = MakeReg(MVT::i64);
1860 BuildMI(BB, IA64::ADD, 2, dummy)
1861 .addGlobalAddress(cast<GlobalAddressSDNode>
1862 (N.getOperand(2))->getGlobal()).addReg(IA64::r1);
1863 BuildMI(BB, IA64::LD8, 1, dummy2).addReg(dummy);
1864
1865 if(!isBool)
1866 BuildMI(BB, Opc, 2).addReg(dummy2).addReg(Tmp1);
1867 else { // we are storing a bool, so emit a little pseudocode
1868 // to store a predicate register as one byte
1869 assert(Opc==IA64::ST1);
1870 unsigned dummy3 = MakeReg(MVT::i64);
1871 unsigned dummy4 = MakeReg(MVT::i64);
1872 BuildMI(BB, IA64::MOV, 1, dummy3).addReg(IA64::r0);
Duraid Madina5ef2ec92005-04-11 05:55:56 +00001873 BuildMI(BB, IA64::TPCADDIMM22, 2, dummy4)
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001874 .addReg(dummy3).addImm(1).addReg(Tmp1); // if(Tmp1) dummy=0+1;
1875 BuildMI(BB, Opc, 2).addReg(dummy2).addReg(dummy4);
1876 }
1877 } else if(N.getOperand(2).getOpcode() == ISD::FrameIndex) {
1878
1879 // FIXME? (what about bools?)
1880
1881 unsigned dummy = MakeReg(MVT::i64);
1882 BuildMI(BB, IA64::MOV, 1, dummy)
1883 .addFrameIndex(cast<FrameIndexSDNode>(N.getOperand(2))->getIndex());
1884 BuildMI(BB, Opc, 2).addReg(dummy).addReg(Tmp1);
1885 } else { // otherwise
1886 Tmp2 = SelectExpr(N.getOperand(2)); //address
1887 if(!isBool)
1888 BuildMI(BB, Opc, 2).addReg(Tmp2).addReg(Tmp1);
1889 else { // we are storing a bool, so emit a little pseudocode
1890 // to store a predicate register as one byte
1891 assert(Opc==IA64::ST1);
1892 unsigned dummy3 = MakeReg(MVT::i64);
1893 unsigned dummy4 = MakeReg(MVT::i64);
1894 BuildMI(BB, IA64::MOV, 1, dummy3).addReg(IA64::r0);
Duraid Madina5ef2ec92005-04-11 05:55:56 +00001895 BuildMI(BB, IA64::TPCADDIMM22, 2, dummy4)
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001896 .addReg(dummy3).addImm(1).addReg(Tmp1); // if(Tmp1) dummy=0+1;
1897 BuildMI(BB, Opc, 2).addReg(Tmp2).addReg(dummy4);
1898 }
1899 }
1900 return;
1901 }
1902
1903 case ISD::ADJCALLSTACKDOWN:
1904 case ISD::ADJCALLSTACKUP: {
1905 Select(N.getOperand(0));
1906 Tmp1 = cast<ConstantSDNode>(N.getOperand(1))->getValue();
1907
1908 Opc = N.getOpcode() == ISD::ADJCALLSTACKDOWN ? IA64::ADJUSTCALLSTACKDOWN :
1909 IA64::ADJUSTCALLSTACKUP;
1910 BuildMI(BB, Opc, 1).addImm(Tmp1);
1911 return;
1912 }
1913
1914 return;
1915 }
1916 assert(0 && "GAME OVER. INSERT COIN?");
1917}
1918
1919
1920/// createIA64PatternInstructionSelector - This pass converts an LLVM function
1921/// into a machine code representation using pattern matching and a machine
1922/// description file.
1923///
1924FunctionPass *llvm::createIA64PatternInstructionSelector(TargetMachine &TM) {
1925 return new ISel(TM);
1926}
1927
1928