blob: 7c03a45bca591610a4bf735168b87df2c5d53144 [file] [log] [blame]
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001//===-- IA64ISelPattern.cpp - A pattern matching inst selector for IA64 ---===//
Misha Brukman4633f1c2005-04-21 23:13:11 +00002//
Duraid Madina9b9d45f2005-03-17 18:17:03 +00003// 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.
Misha Brukman4633f1c2005-04-21 23:13:11 +00007//
Duraid Madina9b9d45f2005-03-17 18:17:03 +00008//===----------------------------------------------------------------------===//
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.
Misha Brukman4633f1c2005-04-21 23:13:11 +000039
Duraid Madina9b9d45f2005-03-17 18:17:03 +000040 //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) {
Misha Brukman4633f1c2005-04-21 23:13:11 +000048
Duraid Madina9b9d45f2005-03-17 18:17:03 +000049 // register class for general registers
50 addRegisterClass(MVT::i64, IA64::GRRegisterClass);
51
52 // register class for FP registers
53 addRegisterClass(MVT::f64, IA64::FPRegisterClass);
Misha Brukman4633f1c2005-04-21 23:13:11 +000054
55 // register class for predicate registers
Duraid Madina9b9d45f2005-03-17 18:17:03 +000056 addRegisterClass(MVT::i1, IA64::PRRegisterClass);
Misha Brukman4633f1c2005-04-21 23:13:11 +000057
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
Misha Brukman4633f1c2005-04-21 23:13:11 +000061 setSetCCResultType(MVT::i1);
Duraid Madina9b9d45f2005-03-17 18:17:03 +000062 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);
Duraid Madina9b9d45f2005-03-17 18:17:03 +000067
68 setOperationAction(ISD::SEXTLOAD , MVT::i1 , Expand);
69 setOperationAction(ISD::SEXTLOAD , MVT::i8 , Expand);
70 setOperationAction(ISD::SEXTLOAD , MVT::i16 , Expand);
Duraid Madinac4ccc2d2005-04-14 08:37:32 +000071 setOperationAction(ISD::SEXTLOAD , MVT::i32 , Expand);
Duraid Madina9b9d45f2005-03-17 18:17:03 +000072
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);
Misha Brukman4633f1c2005-04-21 23:13:11 +000078
Duraid Madina9b9d45f2005-03-17 18:17:03 +000079 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
Misha Brukman4633f1c2005-04-21 23:13:11 +0000157 unsigned args_int[] = {IA64::r32, IA64::r33, IA64::r34, IA64::r35,
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000158 IA64::r36, IA64::r37, IA64::r38, IA64::r39};
Misha Brukman4633f1c2005-04-21 23:13:11 +0000159
160 unsigned args_FP[] = {IA64::F8, IA64::F9, IA64::F10, IA64::F11,
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000161 IA64::F12,IA64::F13,IA64::F14, IA64::F15};
Misha Brukman4633f1c2005-04-21 23:13:11 +0000162
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000163 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?
Misha Brukman4633f1c2005-04-21 23:13:11 +0000168
Duraid Madinabeeaab22005-03-31 12:31:11 +0000169 unsigned ArgOffset = 0;
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000170 int count = 0;
Misha Brukman4633f1c2005-04-21 23:13: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.
Misha Brukman7847fca2005-04-22 17:54:37 +0000176
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//XXX BuildMI(&BB, IA64::IDEF, 0, args_FP[used_FPArgs]);
187 MF.addLiveIn(args_FP[used_FPArgs]); // mark this reg as liveIn
188 // floating point args go into f8..f15 as-needed, the increment
189 argVreg[count] = // is below..:
190 MF.getSSARegMap()->createVirtualRegister(getRegClassFor(MVT::f64));
191 // FP args go into f8..f15 as needed: (hence the ++)
192 argPreg[count] = args_FP[used_FPArgs++];
193 argOpc[count] = IA64::FMOV;
194 argt = newroot = DAG.getCopyFromReg(argVreg[count],
195 getValueType(I->getType()), DAG.getRoot());
196 break;
197 case MVT::i1: // NOTE: as far as C abi stuff goes,
198 // bools are just boring old ints
199 case MVT::i8:
200 case MVT::i16:
201 case MVT::i32:
202 case MVT::i64:
203//XXX BuildMI(&BB, IA64::IDEF, 0, args_int[count]);
204 MF.addLiveIn(args_int[count]); // mark this register as liveIn
205 argVreg[count] =
206 MF.getSSARegMap()->createVirtualRegister(getRegClassFor(MVT::i64));
207 argPreg[count] = args_int[count];
208 argOpc[count] = IA64::MOV;
209 argt = newroot =
210 DAG.getCopyFromReg(argVreg[count], MVT::i64, DAG.getRoot());
211 if ( getValueType(I->getType()) != MVT::i64)
212 argt = DAG.getNode(ISD::TRUNCATE, getValueType(I->getType()),
213 newroot);
214 break;
215 }
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000216 } else { // more than 8 args go into the frame
Misha Brukman7847fca2005-04-22 17:54:37 +0000217 // Create the frame index object for this incoming parameter...
218 ArgOffset = 16 + 8 * (count - 8);
219 int FI = MFI->CreateFixedObject(8, ArgOffset);
220
221 // Create the SelectionDAG nodes corresponding to a load
222 //from this parameter
223 SDOperand FIN = DAG.getFrameIndex(FI, MVT::i64);
224 argt = newroot = DAG.getLoad(getValueType(I->getType()),
225 DAG.getEntryNode(), FIN);
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000226 }
227 ++count;
228 DAG.setRoot(newroot.getValue(1));
229 ArgValues.push_back(argt);
Misha Brukman4633f1c2005-04-21 23:13:11 +0000230 }
Duraid Madinabeeaab22005-03-31 12:31:11 +0000231
Misha Brukman4633f1c2005-04-21 23:13:11 +0000232
Duraid Madinabeeaab22005-03-31 12:31:11 +0000233 // Create a vreg to hold the output of (what will become)
234 // the "alloc" instruction
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000235 VirtGPR = MF.getSSARegMap()->createVirtualRegister(getRegClassFor(MVT::i64));
236 BuildMI(&BB, IA64::PSEUDO_ALLOC, 0, VirtGPR);
237 // we create a PSEUDO_ALLOC (pseudo)instruction for now
238
239 BuildMI(&BB, IA64::IDEF, 0, IA64::r1);
240
241 // hmm:
242 BuildMI(&BB, IA64::IDEF, 0, IA64::r12);
243 BuildMI(&BB, IA64::IDEF, 0, IA64::rp);
244 // ..hmm.
245
246 BuildMI(&BB, IA64::MOV, 1, GP).addReg(IA64::r1);
247
248 // hmm:
249 BuildMI(&BB, IA64::MOV, 1, SP).addReg(IA64::r12);
250 BuildMI(&BB, IA64::MOV, 1, RP).addReg(IA64::rp);
251 // ..hmm.
252
Duraid Madinabeeaab22005-03-31 12:31:11 +0000253 unsigned tempOffset=0;
Misha Brukman4633f1c2005-04-21 23:13:11 +0000254
Duraid Madinabeeaab22005-03-31 12:31:11 +0000255 // if this is a varargs function, we simply lower llvm.va_start by
256 // pointing to the first entry
257 if(F.isVarArg()) {
258 tempOffset=0;
259 VarArgsFrameIndex = MFI->CreateFixedObject(8, tempOffset);
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000260 }
Misha Brukman4633f1c2005-04-21 23:13:11 +0000261
Duraid Madinabeeaab22005-03-31 12:31:11 +0000262 // here we actually do the moving of args, and store them to the stack
263 // too if this is a varargs function:
264 for (int i = 0; i < count && i < 8; ++i) {
265 BuildMI(&BB, argOpc[i], 1, argVreg[i]).addReg(argPreg[i]);
266 if(F.isVarArg()) {
267 // if this is a varargs function, we copy the input registers to the stack
268 int FI = MFI->CreateFixedObject(8, tempOffset);
269 tempOffset+=8; //XXX: is it safe to use r22 like this?
270 BuildMI(&BB, IA64::MOV, 1, IA64::r22).addFrameIndex(FI);
271 // FIXME: we should use st8.spill here, one day
272 BuildMI(&BB, IA64::ST8, 1, IA64::r22).addReg(argPreg[i]);
273 }
274 }
275
Duraid Madinaca494fd2005-04-12 14:54:44 +0000276 // Finally, inform the code generator which regs we return values in.
277 // (see the ISD::RET: case down below)
278 switch (getValueType(F.getReturnType())) {
279 default: assert(0 && "i have no idea where to return this type!");
280 case MVT::isVoid: break;
281 case MVT::i1:
282 case MVT::i8:
283 case MVT::i16:
284 case MVT::i32:
285 case MVT::i64:
286 MF.addLiveOut(IA64::r8);
287 break;
288 case MVT::f32:
289 case MVT::f64:
290 MF.addLiveOut(IA64::F8);
291 break;
292 }
Misha Brukman4633f1c2005-04-21 23:13:11 +0000293
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000294 return ArgValues;
295}
Misha Brukman4633f1c2005-04-21 23:13:11 +0000296
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000297std::pair<SDOperand, SDOperand>
298IA64TargetLowering::LowerCallTo(SDOperand Chain,
Misha Brukman7847fca2005-04-22 17:54:37 +0000299 const Type *RetTy, bool isVarArg,
300 SDOperand Callee, ArgListTy &Args,
301 SelectionDAG &DAG) {
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000302
303 MachineFunction &MF = DAG.getMachineFunction();
304
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000305 unsigned NumBytes = 16;
Duraid Madinabeeaab22005-03-31 12:31:11 +0000306 unsigned outRegsUsed = 0;
307
308 if (Args.size() > 8) {
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000309 NumBytes += (Args.size() - 8) * 8;
Duraid Madinabeeaab22005-03-31 12:31:11 +0000310 outRegsUsed = 8;
311 } else {
312 outRegsUsed = Args.size();
313 }
Misha Brukman4633f1c2005-04-21 23:13:11 +0000314
Duraid Madinabeeaab22005-03-31 12:31:11 +0000315 // FIXME? this WILL fail if we ever try to pass around an arg that
316 // consumes more than a single output slot (a 'real' double, int128
317 // some sort of aggregate etc.), as we'll underestimate how many 'outX'
318 // registers we use. Hopefully, the assembler will notice.
319 MF.getInfo<IA64FunctionInfo>()->outRegsUsed=
320 std::max(outRegsUsed, MF.getInfo<IA64FunctionInfo>()->outRegsUsed);
Misha Brukman4633f1c2005-04-21 23:13:11 +0000321
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000322 Chain = DAG.getNode(ISD::ADJCALLSTACKDOWN, MVT::Other, Chain,
323 DAG.getConstant(NumBytes, getPointerTy()));
Misha Brukman4633f1c2005-04-21 23:13:11 +0000324
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000325 std::vector<SDOperand> args_to_use;
326 for (unsigned i = 0, e = Args.size(); i != e; ++i)
327 {
328 switch (getValueType(Args[i].second)) {
329 default: assert(0 && "unexpected argument type!");
330 case MVT::i1:
331 case MVT::i8:
332 case MVT::i16:
333 case MVT::i32:
Misha Brukman7847fca2005-04-22 17:54:37 +0000334 //promote to 64-bits, sign/zero extending based on type
335 //of the argument
336 if(Args[i].second->isSigned())
337 Args[i].first = DAG.getNode(ISD::SIGN_EXTEND, MVT::i64,
338 Args[i].first);
339 else
340 Args[i].first = DAG.getNode(ISD::ZERO_EXTEND, MVT::i64,
341 Args[i].first);
342 break;
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000343 case MVT::f32:
Misha Brukman7847fca2005-04-22 17:54:37 +0000344 //promote to 64-bits
345 Args[i].first = DAG.getNode(ISD::FP_EXTEND, MVT::f64, Args[i].first);
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000346 case MVT::f64:
347 case MVT::i64:
348 break;
349 }
350 args_to_use.push_back(Args[i].first);
351 }
352
353 std::vector<MVT::ValueType> RetVals;
354 MVT::ValueType RetTyVT = getValueType(RetTy);
355 if (RetTyVT != MVT::isVoid)
356 RetVals.push_back(RetTyVT);
357 RetVals.push_back(MVT::Other);
358
359 SDOperand TheCall = SDOperand(DAG.getCall(RetVals, Chain,
Misha Brukman7847fca2005-04-22 17:54:37 +0000360 Callee, args_to_use), 0);
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000361 Chain = TheCall.getValue(RetTyVT != MVT::isVoid);
362 Chain = DAG.getNode(ISD::ADJCALLSTACKUP, MVT::Other, Chain,
363 DAG.getConstant(NumBytes, getPointerTy()));
364 return std::make_pair(TheCall, Chain);
365}
366
367std::pair<SDOperand, SDOperand>
368IA64TargetLowering::LowerVAStart(SDOperand Chain, SelectionDAG &DAG) {
369 // vastart just returns the address of the VarArgsFrameIndex slot.
370 return std::make_pair(DAG.getFrameIndex(VarArgsFrameIndex, MVT::i64), Chain);
371}
372
373std::pair<SDOperand,SDOperand> IA64TargetLowering::
374LowerVAArgNext(bool isVANext, SDOperand Chain, SDOperand VAList,
375 const Type *ArgTy, SelectionDAG &DAG) {
Duraid Madinabeeaab22005-03-31 12:31:11 +0000376
377 MVT::ValueType ArgVT = getValueType(ArgTy);
378 SDOperand Result;
379 if (!isVANext) {
380 Result = DAG.getLoad(ArgVT, DAG.getEntryNode(), VAList);
381 } else {
382 unsigned Amt;
383 if (ArgVT == MVT::i32 || ArgVT == MVT::f32)
384 Amt = 8;
385 else {
386 assert((ArgVT == MVT::i64 || ArgVT == MVT::f64) &&
387 "Other types should have been promoted for varargs!");
388 Amt = 8;
389 }
390 Result = DAG.getNode(ISD::ADD, VAList.getValueType(), VAList,
391 DAG.getConstant(Amt, VAList.getValueType()));
392 }
393 return std::make_pair(Result, Chain);
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000394}
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000395
396std::pair<SDOperand, SDOperand> IA64TargetLowering::
397LowerFrameReturnAddress(bool isFrameAddress, SDOperand Chain, unsigned Depth,
398 SelectionDAG &DAG) {
399
400 assert(0 && "LowerFrameReturnAddress not done yet\n");
Duraid Madina817aed42005-03-17 19:00:40 +0000401 abort();
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000402}
403
404
405namespace {
406
407 //===--------------------------------------------------------------------===//
408 /// ISel - IA64 specific code to select IA64 machine instructions for
409 /// SelectionDAG operations.
410 ///
411 class ISel : public SelectionDAGISel {
412 /// IA64Lowering - This object fully describes how to lower LLVM code to an
413 /// IA64-specific SelectionDAG.
414 IA64TargetLowering IA64Lowering;
415
416 /// ExprMap - As shared expressions are codegen'd, we keep track of which
417 /// vreg the value is produced in, so we only emit one copy of each compiled
418 /// tree.
419 std::map<SDOperand, unsigned> ExprMap;
420 std::set<SDOperand> LoweredTokens;
421
422 public:
423 ISel(TargetMachine &TM) : SelectionDAGISel(IA64Lowering), IA64Lowering(TM) {
424 }
425
426 /// InstructionSelectBasicBlock - This callback is invoked by
427 /// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
428 virtual void InstructionSelectBasicBlock(SelectionDAG &DAG);
429
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000430 unsigned SelectExpr(SDOperand N);
431 void Select(SDOperand N);
432 };
433}
434
435/// InstructionSelectBasicBlock - This callback is invoked by SelectionDAGISel
436/// when it has created a SelectionDAG for us to codegen.
437void ISel::InstructionSelectBasicBlock(SelectionDAG &DAG) {
438
439 // Codegen the basic block.
440 Select(DAG.getRoot());
441
442 // Clear state used for selection.
443 ExprMap.clear();
444 LoweredTokens.clear();
445}
446
Duraid Madina4826a072005-04-06 09:55:17 +0000447/// ExactLog2 - This function solves for (Val == 1 << (N-1)) and returns N. It
448/// returns zero when the input is not exactly a power of two.
Duraid Madinac02780e2005-04-13 04:50:54 +0000449static unsigned ExactLog2(uint64_t Val) {
Duraid Madina4826a072005-04-06 09:55:17 +0000450 if (Val == 0 || (Val & (Val-1))) return 0;
451 unsigned Count = 0;
452 while (Val != 1) {
453 Val >>= 1;
454 ++Count;
455 }
456 return Count;
457}
458
Duraid Madinac02780e2005-04-13 04:50:54 +0000459/// ExactLog2sub1 - This function solves for (Val == (1 << (N-1))-1)
460/// and returns N. It returns 666 if Val is not 2^n -1 for some n.
461static unsigned ExactLog2sub1(uint64_t Val) {
462 unsigned int n;
463 for(n=0; n<64; n++) {
Duraid Madina3eb71502005-04-14 10:06:35 +0000464 if(Val==(uint64_t)((1LL<<n)-1))
Duraid Madinac02780e2005-04-13 04:50:54 +0000465 return n;
466 }
467 return 666;
468}
469
Duraid Madina4826a072005-04-06 09:55:17 +0000470/// ponderIntegerDivisionBy - When handling integer divides, if the divide
471/// is by a constant such that we can efficiently codegen it, this
472/// function says what to do. Currently, it returns 0 if the division must
473/// become a genuine divide, and 1 if the division can be turned into a
474/// right shift.
475static unsigned ponderIntegerDivisionBy(SDOperand N, bool isSigned,
476 unsigned& Imm) {
477 if (N.getOpcode() != ISD::Constant) return 0; // if not a divide by
478 // a constant, give up.
479
480 int64_t v = (int64_t)cast<ConstantSDNode>(N)->getSignExtended();
481
Misha Brukman4633f1c2005-04-21 23:13:11 +0000482 if ((Imm = ExactLog2(v))) { // if a division by a power of two, say so
Duraid Madina4826a072005-04-06 09:55:17 +0000483 return 1;
Misha Brukman4633f1c2005-04-21 23:13:11 +0000484 }
485
Duraid Madina4826a072005-04-06 09:55:17 +0000486 return 0; // fallthrough
487}
488
Duraid Madinac02780e2005-04-13 04:50:54 +0000489static unsigned ponderIntegerAndWith(SDOperand N, unsigned& Imm) {
490 if (N.getOpcode() != ISD::Constant) return 0; // if not ANDing with
491 // a constant, give up.
492
493 int64_t v = (int64_t)cast<ConstantSDNode>(N)->getSignExtended();
494
495 if ((Imm = ExactLog2sub1(v))!=666) { // if ANDing with ((2^n)-1) for some n
496 return 1; // say so
Misha Brukman4633f1c2005-04-21 23:13:11 +0000497 }
498
Duraid Madinac02780e2005-04-13 04:50:54 +0000499 return 0; // fallthrough
500}
501
Duraid Madinaf55e4032005-04-07 12:33:38 +0000502static unsigned ponderIntegerAdditionWith(SDOperand N, unsigned& Imm) {
503 if (N.getOpcode() != ISD::Constant) return 0; // if not adding a
504 // constant, give up.
505 int64_t v = (int64_t)cast<ConstantSDNode>(N)->getSignExtended();
506
507 if (v <= 8191 && v >= -8192) { // if this constants fits in 14 bits, say so
508 Imm = v & 0x3FFF; // 14 bits
509 return 1;
Misha Brukman4633f1c2005-04-21 23:13:11 +0000510 }
Duraid Madinaf55e4032005-04-07 12:33:38 +0000511 return 0; // fallthrough
512}
513
514static unsigned ponderIntegerSubtractionFrom(SDOperand N, unsigned& Imm) {
515 if (N.getOpcode() != ISD::Constant) return 0; // if not subtracting a
516 // constant, give up.
517 int64_t v = (int64_t)cast<ConstantSDNode>(N)->getSignExtended();
518
519 if (v <= 127 && v >= -128) { // if this constants fits in 8 bits, say so
520 Imm = v & 0xFF; // 8 bits
521 return 1;
Misha Brukman4633f1c2005-04-21 23:13:11 +0000522 }
Duraid Madinaf55e4032005-04-07 12:33:38 +0000523 return 0; // fallthrough
524}
525
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000526unsigned ISel::SelectExpr(SDOperand N) {
527 unsigned Result;
528 unsigned Tmp1, Tmp2, Tmp3;
529 unsigned Opc = 0;
530 MVT::ValueType DestType = N.getValueType();
531
532 unsigned opcode = N.getOpcode();
533
534 SDNode *Node = N.Val;
535 SDOperand Op0, Op1;
536
537 if (Node->getOpcode() == ISD::CopyFromReg)
538 // Just use the specified register as our input.
539 return dyn_cast<RegSDNode>(Node)->getReg();
Misha Brukman4633f1c2005-04-21 23:13:11 +0000540
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000541 unsigned &Reg = ExprMap[N];
542 if (Reg) return Reg;
Misha Brukman4633f1c2005-04-21 23:13:11 +0000543
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000544 if (N.getOpcode() != ISD::CALL)
545 Reg = Result = (N.getValueType() != MVT::Other) ?
546 MakeReg(N.getValueType()) : 1;
547 else {
548 // If this is a call instruction, make sure to prepare ALL of the result
549 // values as well as the chain.
550 if (Node->getNumValues() == 1)
551 Reg = Result = 1; // Void call, just a chain.
552 else {
553 Result = MakeReg(Node->getValueType(0));
554 ExprMap[N.getValue(0)] = Result;
555 for (unsigned i = 1, e = N.Val->getNumValues()-1; i != e; ++i)
556 ExprMap[N.getValue(i)] = MakeReg(Node->getValueType(i));
557 ExprMap[SDOperand(Node, Node->getNumValues()-1)] = 1;
558 }
559 }
Misha Brukman4633f1c2005-04-21 23:13:11 +0000560
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000561 switch (N.getOpcode()) {
562 default:
563 Node->dump();
564 assert(0 && "Node not handled!\n");
565
566 case ISD::FrameIndex: {
567 Tmp1 = cast<FrameIndexSDNode>(N)->getIndex();
568 BuildMI(BB, IA64::MOV, 1, Result).addFrameIndex(Tmp1);
569 return Result;
570 }
571
572 case ISD::ConstantPool: {
573 Tmp1 = cast<ConstantPoolSDNode>(N)->getIndex();
574 IA64Lowering.restoreGP(BB); // FIXME: do i really need this?
575 BuildMI(BB, IA64::ADD, 2, Result).addConstantPoolIndex(Tmp1)
576 .addReg(IA64::r1);
577 return Result;
578 }
579
580 case ISD::ConstantFP: {
581 Tmp1 = Result; // Intermediate Register
582 if (cast<ConstantFPSDNode>(N)->getValue() < 0.0 ||
583 cast<ConstantFPSDNode>(N)->isExactlyValue(-0.0))
584 Tmp1 = MakeReg(MVT::f64);
585
586 if (cast<ConstantFPSDNode>(N)->isExactlyValue(+0.0) ||
587 cast<ConstantFPSDNode>(N)->isExactlyValue(-0.0))
588 BuildMI(BB, IA64::FMOV, 1, Tmp1).addReg(IA64::F0); // load 0.0
589 else if (cast<ConstantFPSDNode>(N)->isExactlyValue(+1.0) ||
590 cast<ConstantFPSDNode>(N)->isExactlyValue(-1.0))
591 BuildMI(BB, IA64::FMOV, 1, Tmp1).addReg(IA64::F1); // load 1.0
592 else
593 assert(0 && "Unexpected FP constant!");
594 if (Tmp1 != Result)
595 // we multiply by +1.0, negate (this is FNMA), and then add 0.0
596 BuildMI(BB, IA64::FNMA, 3, Result).addReg(Tmp1).addReg(IA64::F1)
Misha Brukman7847fca2005-04-22 17:54:37 +0000597 .addReg(IA64::F0);
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000598 return Result;
599 }
600
601 case ISD::DYNAMIC_STACKALLOC: {
602 // Generate both result values.
603 if (Result != 1)
604 ExprMap[N.getValue(1)] = 1; // Generate the token
605 else
606 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
607
608 // FIXME: We are currently ignoring the requested alignment for handling
609 // greater than the stack alignment. This will need to be revisited at some
610 // point. Align = N.getOperand(2);
611
612 if (!isa<ConstantSDNode>(N.getOperand(2)) ||
613 cast<ConstantSDNode>(N.getOperand(2))->getValue() != 0) {
614 std::cerr << "Cannot allocate stack object with greater alignment than"
615 << " the stack alignment yet!";
616 abort();
617 }
Misha Brukman4633f1c2005-04-21 23:13:11 +0000618
619/*
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000620 Select(N.getOperand(0));
621 if (ConstantSDNode* CN = dyn_cast<ConstantSDNode>(N.getOperand(1)))
622 {
623 if (CN->getValue() < 32000)
624 {
625 BuildMI(BB, IA64::ADDIMM22, 2, IA64::r12).addReg(IA64::r12)
Misha Brukman7847fca2005-04-22 17:54:37 +0000626 .addImm(-CN->getValue());
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000627 } else {
628 Tmp1 = SelectExpr(N.getOperand(1));
629 // Subtract size from stack pointer, thereby allocating some space.
630 BuildMI(BB, IA64::SUB, 2, IA64::r12).addReg(IA64::r12).addReg(Tmp1);
631 }
632 } else {
633 Tmp1 = SelectExpr(N.getOperand(1));
634 // Subtract size from stack pointer, thereby allocating some space.
635 BuildMI(BB, IA64::SUB, 2, IA64::r12).addReg(IA64::r12).addReg(Tmp1);
636 }
Duraid Madinabeeaab22005-03-31 12:31:11 +0000637*/
638 Select(N.getOperand(0));
639 Tmp1 = SelectExpr(N.getOperand(1));
640 // Subtract size from stack pointer, thereby allocating some space.
641 BuildMI(BB, IA64::SUB, 2, IA64::r12).addReg(IA64::r12).addReg(Tmp1);
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000642 // Put a pointer to the space into the result register, by copying the
643 // stack pointer.
644 BuildMI(BB, IA64::MOV, 1, Result).addReg(IA64::r12);
645 return Result;
646 }
Misha Brukman4633f1c2005-04-21 23:13:11 +0000647
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000648 case ISD::SELECT: {
649 Tmp1 = SelectExpr(N.getOperand(0)); //Cond
650 Tmp2 = SelectExpr(N.getOperand(1)); //Use if TRUE
651 Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE
652
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000653 unsigned bogoResult;
Misha Brukman4633f1c2005-04-21 23:13:11 +0000654
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000655 switch (N.getOperand(1).getValueType()) {
Misha Brukman7847fca2005-04-22 17:54:37 +0000656 default: assert(0 &&
657 "ISD::SELECT: 'select'ing something other than i64 or f64!\n");
658 case MVT::i64:
659 bogoResult=MakeReg(MVT::i64);
660 break;
661 case MVT::f64:
662 bogoResult=MakeReg(MVT::f64);
663 break;
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000664 }
Duraid Madina69c8e202005-04-01 10:35:00 +0000665
666 BuildMI(BB, IA64::MOV, 1, bogoResult).addReg(Tmp3);
667 BuildMI(BB, IA64::CMOV, 2, Result).addReg(bogoResult).addReg(Tmp2)
Misha Brukman7847fca2005-04-22 17:54:37 +0000668 .addReg(Tmp1); // FIXME: should be FMOV/FCMOV sometimes,
Duraid Madina69c8e202005-04-01 10:35:00 +0000669 // though this will work for now (no JIT)
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000670 return Result;
671 }
Misha Brukman4633f1c2005-04-21 23:13:11 +0000672
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000673 case ISD::Constant: {
674 unsigned depositPos=0;
675 unsigned depositLen=0;
676 switch (N.getValueType()) {
677 default: assert(0 && "Cannot use constants of this type!");
678 case MVT::i1: { // if a bool, we don't 'load' so much as generate
Misha Brukman7847fca2005-04-22 17:54:37 +0000679 // the constant:
680 if(cast<ConstantSDNode>(N)->getValue()) // true:
681 BuildMI(BB, IA64::CMPEQ, 2, Result).addReg(IA64::r0).addReg(IA64::r0);
682 else // false:
683 BuildMI(BB, IA64::CMPNE, 2, Result).addReg(IA64::r0).addReg(IA64::r0);
684 return Result; // early exit
685 }
Duraid Madina5ef2ec92005-04-11 05:55:56 +0000686 case MVT::i64: break;
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000687 }
Misha Brukman4633f1c2005-04-21 23:13:11 +0000688
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000689 int64_t immediate = cast<ConstantSDNode>(N)->getValue();
Duraid Madina5ef2ec92005-04-11 05:55:56 +0000690
691 if(immediate==0) { // if the constant is just zero,
692 BuildMI(BB, IA64::MOV, 1, Result).addReg(IA64::r0); // just copy r0
693 return Result; // early exit
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000694 }
695
Duraid Madina5ef2ec92005-04-11 05:55:56 +0000696 if (immediate <= 8191 && immediate >= -8192) {
697 // if this constants fits in 14 bits, we use a mov the assembler will
698 // turn into: "adds rDest=imm,r0" (and _not_ "andl"...)
699 BuildMI(BB, IA64::MOVSIMM14, 1, Result).addSImm(immediate);
700 return Result; // early exit
Misha Brukman4633f1c2005-04-21 23:13:11 +0000701 }
Duraid Madina5ef2ec92005-04-11 05:55:56 +0000702
703 if (immediate <= 2097151 && immediate >= -2097152) {
704 // if this constants fits in 22 bits, we use a mov the assembler will
705 // turn into: "addl rDest=imm,r0"
706 BuildMI(BB, IA64::MOVSIMM22, 1, Result).addSImm(immediate);
707 return Result; // early exit
Misha Brukman4633f1c2005-04-21 23:13:11 +0000708 }
Duraid Madina5ef2ec92005-04-11 05:55:56 +0000709
710 /* otherwise, our immediate is big, so we use movl */
711 uint64_t Imm = immediate;
Duraid Madina21478e52005-04-11 07:16:39 +0000712 BuildMI(BB, IA64::MOVLIMM64, 1, Result).addImm64(Imm);
Duraid Madina5ef2ec92005-04-11 05:55:56 +0000713 return Result;
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000714 }
Duraid Madina75c9fcb2005-04-02 10:33:53 +0000715
716 case ISD::UNDEF: {
717 BuildMI(BB, IA64::IDEF, 0, Result);
718 return Result;
719 }
Misha Brukman4633f1c2005-04-21 23:13:11 +0000720
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000721 case ISD::GlobalAddress: {
722 GlobalValue *GV = cast<GlobalAddressSDNode>(N)->getGlobal();
723 unsigned Tmp1 = MakeReg(MVT::i64);
Duraid Madinabeeaab22005-03-31 12:31:11 +0000724
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000725 BuildMI(BB, IA64::ADD, 2, Tmp1).addGlobalAddress(GV).addReg(IA64::r1);
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000726 BuildMI(BB, IA64::LD8, 1, Result).addReg(Tmp1);
Duraid Madinabeeaab22005-03-31 12:31:11 +0000727
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000728 return Result;
729 }
Misha Brukman4633f1c2005-04-21 23:13:11 +0000730
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000731 case ISD::ExternalSymbol: {
732 const char *Sym = cast<ExternalSymbolSDNode>(N)->getSymbol();
Duraid Madinabeeaab22005-03-31 12:31:11 +0000733// assert(0 && "sorry, but what did you want an ExternalSymbol for again?");
734 BuildMI(BB, IA64::MOV, 1, Result).addExternalSymbol(Sym); // XXX
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000735 return Result;
736 }
737
738 case ISD::FP_EXTEND: {
739 Tmp1 = SelectExpr(N.getOperand(0));
740 BuildMI(BB, IA64::FMOV, 1, Result).addReg(Tmp1);
741 return Result;
742 }
743
744 case ISD::ZERO_EXTEND: {
745 Tmp1 = SelectExpr(N.getOperand(0)); // value
Misha Brukman4633f1c2005-04-21 23:13:11 +0000746
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000747 switch (N.getOperand(0).getValueType()) {
748 default: assert(0 && "Cannot zero-extend this type!");
749 case MVT::i8: Opc = IA64::ZXT1; break;
750 case MVT::i16: Opc = IA64::ZXT2; break;
751 case MVT::i32: Opc = IA64::ZXT4; break;
752
Misha Brukman4633f1c2005-04-21 23:13:11 +0000753 // we handle bools differently! :
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000754 case MVT::i1: { // if the predicate reg has 1, we want a '1' in our GR.
Misha Brukman7847fca2005-04-22 17:54:37 +0000755 unsigned dummy = MakeReg(MVT::i64);
756 // first load zero:
757 BuildMI(BB, IA64::MOV, 1, dummy).addReg(IA64::r0);
758 // ...then conditionally (PR:Tmp1) add 1:
759 BuildMI(BB, IA64::TPCADDIMM22, 2, Result).addReg(dummy)
760 .addImm(1).addReg(Tmp1);
761 return Result; // XXX early exit!
762 }
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000763 }
764
765 BuildMI(BB, Opc, 1, Result).addReg(Tmp1);
766 return Result;
767 }
768
769 case ISD::SIGN_EXTEND: { // we should only have to handle i1 -> i64 here!!!
770
771assert(0 && "hmm, ISD::SIGN_EXTEND: shouldn't ever be reached. bad luck!\n");
772
773 Tmp1 = SelectExpr(N.getOperand(0)); // value
Misha Brukman4633f1c2005-04-21 23:13:11 +0000774
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000775 switch (N.getOperand(0).getValueType()) {
776 default: assert(0 && "Cannot sign-extend this type!");
777 case MVT::i1: assert(0 && "trying to sign extend a bool? ow.\n");
Misha Brukman7847fca2005-04-22 17:54:37 +0000778 Opc = IA64::SXT1; break;
779 // FIXME: for now, we treat bools the same as i8s
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000780 case MVT::i8: Opc = IA64::SXT1; break;
781 case MVT::i16: Opc = IA64::SXT2; break;
782 case MVT::i32: Opc = IA64::SXT4; break;
783 }
784
785 BuildMI(BB, Opc, 1, Result).addReg(Tmp1);
786 return Result;
787 }
788
789 case ISD::TRUNCATE: {
790 // we use the funky dep.z (deposit (zero)) instruction to deposit bits
791 // of R0 appropriately.
792 switch (N.getOperand(0).getValueType()) {
793 default: assert(0 && "Unknown truncate!");
794 case MVT::i64: break;
795 }
796 Tmp1 = SelectExpr(N.getOperand(0));
797 unsigned depositPos, depositLen;
798
799 switch (N.getValueType()) {
800 default: assert(0 && "Unknown truncate!");
801 case MVT::i1: {
802 // if input (normal reg) is 0, 0!=0 -> false (0), if 1, 1!=0 ->true (1):
Misha Brukman7847fca2005-04-22 17:54:37 +0000803 BuildMI(BB, IA64::CMPNE, 2, Result).addReg(Tmp1)
804 .addReg(IA64::r0);
805 return Result; // XXX early exit!
806 }
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000807 case MVT::i8: depositPos=0; depositLen=8; break;
808 case MVT::i16: depositPos=0; depositLen=16; break;
809 case MVT::i32: depositPos=0; depositLen=32; break;
810 }
811 BuildMI(BB, IA64::DEPZ, 1, Result).addReg(Tmp1)
812 .addImm(depositPos).addImm(depositLen);
813 return Result;
814 }
815
Misha Brukman7847fca2005-04-22 17:54:37 +0000816/*
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000817 case ISD::FP_ROUND: {
818 assert (DestType == MVT::f32 && N.getOperand(0).getValueType() == MVT::f64 &&
Misha Brukman7847fca2005-04-22 17:54:37 +0000819 "error: trying to FP_ROUND something other than f64 -> f32!\n");
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000820 Tmp1 = SelectExpr(N.getOperand(0));
821 BuildMI(BB, IA64::FADDS, 2, Result).addReg(Tmp1).addReg(IA64::F0);
822 // we add 0.0 using a single precision add to do rounding
823 return Result;
824 }
825*/
826
827// FIXME: the following 4 cases need cleaning
828 case ISD::SINT_TO_FP: {
829 Tmp1 = SelectExpr(N.getOperand(0));
830 Tmp2 = MakeReg(MVT::f64);
831 unsigned dummy = MakeReg(MVT::f64);
832 BuildMI(BB, IA64::SETFSIG, 1, Tmp2).addReg(Tmp1);
833 BuildMI(BB, IA64::FCVTXF, 1, dummy).addReg(Tmp2);
834 BuildMI(BB, IA64::FNORMD, 1, Result).addReg(dummy);
835 return Result;
836 }
837
838 case ISD::UINT_TO_FP: {
839 Tmp1 = SelectExpr(N.getOperand(0));
840 Tmp2 = MakeReg(MVT::f64);
841 unsigned dummy = MakeReg(MVT::f64);
842 BuildMI(BB, IA64::SETFSIG, 1, Tmp2).addReg(Tmp1);
843 BuildMI(BB, IA64::FCVTXUF, 1, dummy).addReg(Tmp2);
844 BuildMI(BB, IA64::FNORMD, 1, Result).addReg(dummy);
845 return Result;
846 }
847
848 case ISD::FP_TO_SINT: {
849 Tmp1 = SelectExpr(N.getOperand(0));
850 Tmp2 = MakeReg(MVT::f64);
851 BuildMI(BB, IA64::FCVTFXTRUNC, 1, Tmp2).addReg(Tmp1);
852 BuildMI(BB, IA64::GETFSIG, 1, Result).addReg(Tmp2);
853 return Result;
854 }
855
856 case ISD::FP_TO_UINT: {
857 Tmp1 = SelectExpr(N.getOperand(0));
858 Tmp2 = MakeReg(MVT::f64);
859 BuildMI(BB, IA64::FCVTFXUTRUNC, 1, Tmp2).addReg(Tmp1);
860 BuildMI(BB, IA64::GETFSIG, 1, Result).addReg(Tmp2);
861 return Result;
862 }
863
864 case ISD::ADD: {
Duraid Madina4826a072005-04-06 09:55:17 +0000865 if(DestType == MVT::f64 && N.getOperand(0).getOpcode() == ISD::MUL &&
866 N.getOperand(0).Val->hasOneUse()) { // if we can fold this add
867 // into an fma, do so:
868 // ++FusedFP; // Statistic
869 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
870 Tmp2 = SelectExpr(N.getOperand(0).getOperand(1));
871 Tmp3 = SelectExpr(N.getOperand(1));
872 BuildMI(BB, IA64::FMA, 3, Result).addReg(Tmp1).addReg(Tmp2).addReg(Tmp3);
873 return Result; // early exit
874 }
Duraid Madinaed095022005-04-13 06:12:04 +0000875
876 if(DestType != MVT::f64 && N.getOperand(0).getOpcode() == ISD::SHL &&
Misha Brukman7847fca2005-04-22 17:54:37 +0000877 N.getOperand(0).Val->hasOneUse()) { // if we might be able to fold
Duraid Madinaed095022005-04-13 06:12:04 +0000878 // this add into a shladd, try:
879 ConstantSDNode *CSD = NULL;
880 if((CSD = dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) &&
Misha Brukman7847fca2005-04-22 17:54:37 +0000881 (CSD->getValue() >= 1) && (CSD->getValue() <= 4) ) { // we can:
Duraid Madinaed095022005-04-13 06:12:04 +0000882
Misha Brukman7847fca2005-04-22 17:54:37 +0000883 // ++FusedSHLADD; // Statistic
884 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
885 int shl_amt = CSD->getValue();
886 Tmp3 = SelectExpr(N.getOperand(1));
887
888 BuildMI(BB, IA64::SHLADD, 3, Result)
889 .addReg(Tmp1).addImm(shl_amt).addReg(Tmp3);
890 return Result; // early exit
Duraid Madinaed095022005-04-13 06:12:04 +0000891 }
892 }
893
894 //else, fallthrough:
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000895 Tmp1 = SelectExpr(N.getOperand(0));
Duraid Madinaf55e4032005-04-07 12:33:38 +0000896 if(DestType != MVT::f64) { // integer addition:
897 switch (ponderIntegerAdditionWith(N.getOperand(1), Tmp3)) {
Misha Brukman7847fca2005-04-22 17:54:37 +0000898 case 1: // adding a constant that's 14 bits
899 BuildMI(BB, IA64::ADDIMM14, 2, Result).addReg(Tmp1).addSImm(Tmp3);
900 return Result; // early exit
901 } // fallthrough and emit a reg+reg ADD:
902 Tmp2 = SelectExpr(N.getOperand(1));
903 BuildMI(BB, IA64::ADD, 2, Result).addReg(Tmp1).addReg(Tmp2);
Duraid Madinaf55e4032005-04-07 12:33:38 +0000904 } else { // this is a floating point addition
Duraid Madina5ef2ec92005-04-11 05:55:56 +0000905 Tmp2 = SelectExpr(N.getOperand(1));
Duraid Madinaf55e4032005-04-07 12:33:38 +0000906 BuildMI(BB, IA64::FADD, 2, Result).addReg(Tmp1).addReg(Tmp2);
907 }
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000908 return Result;
909 }
910
911 case ISD::MUL: {
912 Tmp1 = SelectExpr(N.getOperand(0));
913 Tmp2 = SelectExpr(N.getOperand(1));
Duraid Madina4826a072005-04-06 09:55:17 +0000914
915 if(DestType != MVT::f64) { // TODO: speed!
916 // boring old integer multiply with xma
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000917 unsigned TempFR1=MakeReg(MVT::f64);
918 unsigned TempFR2=MakeReg(MVT::f64);
919 unsigned TempFR3=MakeReg(MVT::f64);
920 BuildMI(BB, IA64::SETFSIG, 1, TempFR1).addReg(Tmp1);
921 BuildMI(BB, IA64::SETFSIG, 1, TempFR2).addReg(Tmp2);
922 BuildMI(BB, IA64::XMAL, 1, TempFR3).addReg(TempFR1).addReg(TempFR2)
Misha Brukman7847fca2005-04-22 17:54:37 +0000923 .addReg(IA64::F0);
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000924 BuildMI(BB, IA64::GETFSIG, 1, Result).addReg(TempFR3);
925 }
926 else // floating point multiply
927 BuildMI(BB, IA64::FMPY, 2, Result).addReg(Tmp1).addReg(Tmp2);
928 return Result;
929 }
Misha Brukman4633f1c2005-04-21 23:13:11 +0000930
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000931 case ISD::SUB: {
Duraid Madina4826a072005-04-06 09:55:17 +0000932 if(DestType == MVT::f64 && N.getOperand(0).getOpcode() == ISD::MUL &&
933 N.getOperand(0).Val->hasOneUse()) { // if we can fold this sub
934 // into an fms, do so:
935 // ++FusedFP; // Statistic
936 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
937 Tmp2 = SelectExpr(N.getOperand(0).getOperand(1));
938 Tmp3 = SelectExpr(N.getOperand(1));
939 BuildMI(BB, IA64::FMS, 3, Result).addReg(Tmp1).addReg(Tmp2).addReg(Tmp3);
940 return Result; // early exit
941 }
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000942 Tmp2 = SelectExpr(N.getOperand(1));
Duraid Madinaf55e4032005-04-07 12:33:38 +0000943 if(DestType != MVT::f64) { // integer subtraction:
944 switch (ponderIntegerSubtractionFrom(N.getOperand(0), Tmp3)) {
Misha Brukman7847fca2005-04-22 17:54:37 +0000945 case 1: // subtracting *from* an 8 bit constant:
946 BuildMI(BB, IA64::SUBIMM8, 2, Result).addSImm(Tmp3).addReg(Tmp2);
947 return Result; // early exit
948 } // fallthrough and emit a reg+reg SUB:
949 Tmp1 = SelectExpr(N.getOperand(0));
950 BuildMI(BB, IA64::SUB, 2, Result).addReg(Tmp1).addReg(Tmp2);
Duraid Madinaf55e4032005-04-07 12:33:38 +0000951 } else { // this is a floating point subtraction
Duraid Madina5ef2ec92005-04-11 05:55:56 +0000952 Tmp1 = SelectExpr(N.getOperand(0));
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000953 BuildMI(BB, IA64::FSUB, 2, Result).addReg(Tmp1).addReg(Tmp2);
Duraid Madinaf55e4032005-04-07 12:33:38 +0000954 }
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000955 return Result;
956 }
Duraid Madinaa7ee8b82005-04-02 05:18:38 +0000957
958 case ISD::FABS: {
959 Tmp1 = SelectExpr(N.getOperand(0));
960 assert(DestType == MVT::f64 && "trying to fabs something other than f64?");
961 BuildMI(BB, IA64::FABS, 1, Result).addReg(Tmp1);
962 return Result;
963 }
Misha Brukman4633f1c2005-04-21 23:13:11 +0000964
Duraid Madinaa7ee8b82005-04-02 05:18:38 +0000965 case ISD::FNEG: {
Duraid Madinaa7ee8b82005-04-02 05:18:38 +0000966 assert(DestType == MVT::f64 && "trying to fneg something other than f64?");
Duraid Madina75c9fcb2005-04-02 10:33:53 +0000967
Misha Brukman4633f1c2005-04-21 23:13:11 +0000968 if (ISD::FABS == N.getOperand(0).getOpcode()) { // && hasOneUse()?
Duraid Madina75c9fcb2005-04-02 10:33:53 +0000969 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
970 BuildMI(BB, IA64::FNEGABS, 1, Result).addReg(Tmp1); // fold in abs
971 } else {
972 Tmp1 = SelectExpr(N.getOperand(0));
973 BuildMI(BB, IA64::FNEG, 1, Result).addReg(Tmp1); // plain old fneg
974 }
975
Duraid Madinaa7ee8b82005-04-02 05:18:38 +0000976 return Result;
977 }
Misha Brukman7847fca2005-04-22 17:54:37 +0000978
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000979 case ISD::AND: {
980 switch (N.getValueType()) {
981 default: assert(0 && "Cannot AND this type!");
982 case MVT::i1: { // if a bool, we emit a pseudocode AND
983 unsigned pA = SelectExpr(N.getOperand(0));
984 unsigned pB = SelectExpr(N.getOperand(1));
Misha Brukman4633f1c2005-04-21 23:13:11 +0000985
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000986/* our pseudocode for AND is:
987 *
988(pA) cmp.eq.unc pC,p0 = r0,r0 // pC = pA
989 cmp.eq pTemp,p0 = r0,r0 // pTemp = NOT pB
990 ;;
991(pB) cmp.ne pTemp,p0 = r0,r0
992 ;;
993(pTemp)cmp.ne pC,p0 = r0,r0 // if (NOT pB) pC = 0
994
995*/
996 unsigned pTemp = MakeReg(MVT::i1);
Misha Brukman4633f1c2005-04-21 23:13:11 +0000997
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000998 unsigned bogusTemp1 = MakeReg(MVT::i1);
999 unsigned bogusTemp2 = MakeReg(MVT::i1);
1000 unsigned bogusTemp3 = MakeReg(MVT::i1);
1001 unsigned bogusTemp4 = MakeReg(MVT::i1);
Misha Brukman4633f1c2005-04-21 23:13:11 +00001002
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001003 BuildMI(BB, IA64::PCMPEQUNC, 3, bogusTemp1)
Misha Brukman7847fca2005-04-22 17:54:37 +00001004 .addReg(IA64::r0).addReg(IA64::r0).addReg(pA);
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001005 BuildMI(BB, IA64::CMPEQ, 2, bogusTemp2)
Misha Brukman7847fca2005-04-22 17:54:37 +00001006 .addReg(IA64::r0).addReg(IA64::r0);
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001007 BuildMI(BB, IA64::TPCMPNE, 3, pTemp)
Misha Brukman7847fca2005-04-22 17:54:37 +00001008 .addReg(bogusTemp2).addReg(IA64::r0).addReg(IA64::r0).addReg(pB);
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001009 BuildMI(BB, IA64::TPCMPNE, 3, Result)
Misha Brukman7847fca2005-04-22 17:54:37 +00001010 .addReg(bogusTemp1).addReg(IA64::r0).addReg(IA64::r0).addReg(pTemp);
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001011 break;
1012 }
Misha Brukman4633f1c2005-04-21 23:13:11 +00001013
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001014 // if not a bool, we just AND away:
1015 case MVT::i8:
1016 case MVT::i16:
1017 case MVT::i32:
1018 case MVT::i64: {
1019 Tmp1 = SelectExpr(N.getOperand(0));
Duraid Madinac02780e2005-04-13 04:50:54 +00001020 switch (ponderIntegerAndWith(N.getOperand(1), Tmp3)) {
1021 case 1: // ANDing a constant that is 2^n-1 for some n
Misha Brukman7847fca2005-04-22 17:54:37 +00001022 switch (Tmp3) {
1023 case 8: // if AND 0x00000000000000FF, be quaint and use zxt1
1024 BuildMI(BB, IA64::ZXT1, 1, Result).addReg(Tmp1);
1025 break;
1026 case 16: // if AND 0x000000000000FFFF, be quaint and use zxt2
1027 BuildMI(BB, IA64::ZXT2, 1, Result).addReg(Tmp1);
1028 break;
1029 case 32: // if AND 0x00000000FFFFFFFF, be quaint and use zxt4
1030 BuildMI(BB, IA64::ZXT4, 1, Result).addReg(Tmp1);
1031 break;
1032 default: // otherwise, use dep.z to paste zeros
1033 BuildMI(BB, IA64::DEPZ, 3, Result).addReg(Tmp1)
1034 .addImm(0).addImm(Tmp3);
1035 break;
1036 }
1037 return Result; // early exit
Duraid Madinac02780e2005-04-13 04:50:54 +00001038 } // fallthrough and emit a simple AND:
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001039 Tmp2 = SelectExpr(N.getOperand(1));
1040 BuildMI(BB, IA64::AND, 2, Result).addReg(Tmp1).addReg(Tmp2);
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001041 }
1042 }
1043 return Result;
1044 }
Misha Brukman4633f1c2005-04-21 23:13:11 +00001045
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001046 case ISD::OR: {
1047 switch (N.getValueType()) {
1048 default: assert(0 && "Cannot OR this type!");
1049 case MVT::i1: { // if a bool, we emit a pseudocode OR
1050 unsigned pA = SelectExpr(N.getOperand(0));
1051 unsigned pB = SelectExpr(N.getOperand(1));
1052
1053 unsigned pTemp1 = MakeReg(MVT::i1);
Misha Brukman4633f1c2005-04-21 23:13:11 +00001054
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001055/* our pseudocode for OR is:
1056 *
1057
1058pC = pA OR pB
1059-------------
1060
Misha Brukman7847fca2005-04-22 17:54:37 +00001061(pA) cmp.eq.unc pC,p0 = r0,r0 // pC = pA
1062 ;;
1063(pB) cmp.eq pC,p0 = r0,r0 // if (pB) pC = 1
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001064
1065*/
1066 BuildMI(BB, IA64::PCMPEQUNC, 3, pTemp1)
Misha Brukman7847fca2005-04-22 17:54:37 +00001067 .addReg(IA64::r0).addReg(IA64::r0).addReg(pA);
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001068 BuildMI(BB, IA64::TPCMPEQ, 3, Result)
Misha Brukman7847fca2005-04-22 17:54:37 +00001069 .addReg(pTemp1).addReg(IA64::r0).addReg(IA64::r0).addReg(pB);
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001070 break;
1071 }
1072 // if not a bool, we just OR away:
1073 case MVT::i8:
1074 case MVT::i16:
1075 case MVT::i32:
1076 case MVT::i64: {
1077 Tmp1 = SelectExpr(N.getOperand(0));
1078 Tmp2 = SelectExpr(N.getOperand(1));
1079 BuildMI(BB, IA64::OR, 2, Result).addReg(Tmp1).addReg(Tmp2);
1080 break;
1081 }
1082 }
1083 return Result;
1084 }
Misha Brukman7847fca2005-04-22 17:54:37 +00001085
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001086 case ISD::XOR: {
1087 switch (N.getValueType()) {
1088 default: assert(0 && "Cannot XOR this type!");
1089 case MVT::i1: { // if a bool, we emit a pseudocode XOR
1090 unsigned pY = SelectExpr(N.getOperand(0));
1091 unsigned pZ = SelectExpr(N.getOperand(1));
1092
1093/* one possible routine for XOR is:
1094
1095 // Compute px = py ^ pz
1096 // using sum of products: px = (py & !pz) | (pz & !py)
1097 // Uses 5 instructions in 3 cycles.
1098 // cycle 1
1099(pz) cmp.eq.unc px = r0, r0 // px = pz
1100(py) cmp.eq.unc pt = r0, r0 // pt = py
1101 ;;
1102 // cycle 2
1103(pt) cmp.ne.and px = r0, r0 // px = px & !pt (px = pz & !pt)
1104(pz) cmp.ne.and pt = r0, r0 // pt = pt & !pz
1105 ;;
1106 } { .mmi
1107 // cycle 3
1108(pt) cmp.eq.or px = r0, r0 // px = px | pt
1109
1110*** Another, which we use here, requires one scratch GR. it is:
1111
1112 mov rt = 0 // initialize rt off critical path
1113 ;;
1114
1115 // cycle 1
1116(pz) cmp.eq.unc px = r0, r0 // px = pz
1117(pz) mov rt = 1 // rt = pz
1118 ;;
1119 // cycle 2
1120(py) cmp.ne px = 1, rt // if (py) px = !pz
1121
1122.. these routines kindly provided by Jim Hull
1123*/
1124 unsigned rt = MakeReg(MVT::i64);
1125
1126 // these two temporaries will never actually appear,
1127 // due to the two-address form of some of the instructions below
1128 unsigned bogoPR = MakeReg(MVT::i1); // becomes Result
1129 unsigned bogoGR = MakeReg(MVT::i64); // becomes rt
1130
1131 BuildMI(BB, IA64::MOV, 1, bogoGR).addReg(IA64::r0);
1132 BuildMI(BB, IA64::PCMPEQUNC, 3, bogoPR)
Misha Brukman7847fca2005-04-22 17:54:37 +00001133 .addReg(IA64::r0).addReg(IA64::r0).addReg(pZ);
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001134 BuildMI(BB, IA64::TPCADDIMM22, 2, rt)
Misha Brukman7847fca2005-04-22 17:54:37 +00001135 .addReg(bogoGR).addImm(1).addReg(pZ);
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001136 BuildMI(BB, IA64::TPCMPIMM8NE, 3, Result)
Misha Brukman7847fca2005-04-22 17:54:37 +00001137 .addReg(bogoPR).addImm(1).addReg(rt).addReg(pY);
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001138 break;
1139 }
1140 // if not a bool, we just XOR away:
1141 case MVT::i8:
1142 case MVT::i16:
1143 case MVT::i32:
1144 case MVT::i64: {
1145 Tmp1 = SelectExpr(N.getOperand(0));
1146 Tmp2 = SelectExpr(N.getOperand(1));
1147 BuildMI(BB, IA64::XOR, 2, Result).addReg(Tmp1).addReg(Tmp2);
1148 break;
1149 }
1150 }
1151 return Result;
1152 }
1153
1154 case ISD::SHL: {
1155 Tmp1 = SelectExpr(N.getOperand(0));
Duraid Madinaf55e4032005-04-07 12:33:38 +00001156 if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1157 Tmp2 = CN->getValue();
1158 BuildMI(BB, IA64::SHLI, 2, Result).addReg(Tmp1).addImm(Tmp2);
1159 } else {
1160 Tmp2 = SelectExpr(N.getOperand(1));
1161 BuildMI(BB, IA64::SHL, 2, Result).addReg(Tmp1).addReg(Tmp2);
1162 }
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001163 return Result;
1164 }
Misha Brukman7847fca2005-04-22 17:54:37 +00001165
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001166 case ISD::SRL: {
1167 Tmp1 = SelectExpr(N.getOperand(0));
Duraid Madinaf55e4032005-04-07 12:33:38 +00001168 if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1169 Tmp2 = CN->getValue();
1170 BuildMI(BB, IA64::SHRUI, 2, Result).addReg(Tmp1).addImm(Tmp2);
1171 } else {
1172 Tmp2 = SelectExpr(N.getOperand(1));
1173 BuildMI(BB, IA64::SHRU, 2, Result).addReg(Tmp1).addReg(Tmp2);
1174 }
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001175 return Result;
1176 }
Misha Brukman7847fca2005-04-22 17:54:37 +00001177
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001178 case ISD::SRA: {
1179 Tmp1 = SelectExpr(N.getOperand(0));
Duraid Madinaf55e4032005-04-07 12:33:38 +00001180 if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1181 Tmp2 = CN->getValue();
1182 BuildMI(BB, IA64::SHRSI, 2, Result).addReg(Tmp1).addImm(Tmp2);
1183 } else {
1184 Tmp2 = SelectExpr(N.getOperand(1));
1185 BuildMI(BB, IA64::SHRS, 2, Result).addReg(Tmp1).addReg(Tmp2);
1186 }
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001187 return Result;
1188 }
1189
1190 case ISD::SDIV:
1191 case ISD::UDIV:
1192 case ISD::SREM:
1193 case ISD::UREM: {
1194
1195 Tmp1 = SelectExpr(N.getOperand(0));
1196 Tmp2 = SelectExpr(N.getOperand(1));
1197
1198 bool isFP=false;
1199
1200 if(DestType == MVT::f64) // XXX: we're not gonna be fed MVT::f32, are we?
1201 isFP=true;
1202
1203 bool isModulus=false; // is it a division or a modulus?
1204 bool isSigned=false;
1205
1206 switch(N.getOpcode()) {
1207 case ISD::SDIV: isModulus=false; isSigned=true; break;
1208 case ISD::UDIV: isModulus=false; isSigned=false; break;
1209 case ISD::SREM: isModulus=true; isSigned=true; break;
1210 case ISD::UREM: isModulus=true; isSigned=false; break;
1211 }
1212
Duraid Madina4826a072005-04-06 09:55:17 +00001213 if(!isModulus && !isFP) { // if this is an integer divide,
1214 switch (ponderIntegerDivisionBy(N.getOperand(1), isSigned, Tmp3)) {
Misha Brukman7847fca2005-04-22 17:54:37 +00001215 case 1: // division by a constant that's a power of 2
1216 Tmp1 = SelectExpr(N.getOperand(0));
1217 if(isSigned) { // argument could be negative, so emit some code:
1218 unsigned divAmt=Tmp3;
1219 unsigned tempGR1=MakeReg(MVT::i64);
1220 unsigned tempGR2=MakeReg(MVT::i64);
1221 unsigned tempGR3=MakeReg(MVT::i64);
1222 BuildMI(BB, IA64::SHRS, 2, tempGR1)
1223 .addReg(Tmp1).addImm(divAmt-1);
1224 BuildMI(BB, IA64::EXTRU, 3, tempGR2)
1225 .addReg(tempGR1).addImm(64-divAmt).addImm(divAmt);
1226 BuildMI(BB, IA64::ADD, 2, tempGR3)
1227 .addReg(Tmp1).addReg(tempGR2);
1228 BuildMI(BB, IA64::SHRS, 2, Result)
1229 .addReg(tempGR3).addImm(divAmt);
1230 }
1231 else // unsigned div-by-power-of-2 becomes a simple shift right:
1232 BuildMI(BB, IA64::SHRU, 2, Result).addReg(Tmp1).addImm(Tmp3);
1233 return Result; // early exit
Duraid Madina4826a072005-04-06 09:55:17 +00001234 }
1235 }
1236
Misha Brukman4633f1c2005-04-21 23:13:11 +00001237 unsigned TmpPR=MakeReg(MVT::i1); // we need two scratch
Duraid Madinabeeaab22005-03-31 12:31:11 +00001238 unsigned TmpPR2=MakeReg(MVT::i1); // predicate registers,
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001239 unsigned TmpF1=MakeReg(MVT::f64); // and one metric truckload of FP regs.
1240 unsigned TmpF2=MakeReg(MVT::f64); // lucky we have IA64?
1241 unsigned TmpF3=MakeReg(MVT::f64); // well, the real FIXME is to have
1242 unsigned TmpF4=MakeReg(MVT::f64); // isTwoAddress forms of these
1243 unsigned TmpF5=MakeReg(MVT::f64); // FP instructions so we can end up with
1244 unsigned TmpF6=MakeReg(MVT::f64); // stuff like setf.sig f10=f10 etc.
1245 unsigned TmpF7=MakeReg(MVT::f64);
1246 unsigned TmpF8=MakeReg(MVT::f64);
1247 unsigned TmpF9=MakeReg(MVT::f64);
1248 unsigned TmpF10=MakeReg(MVT::f64);
1249 unsigned TmpF11=MakeReg(MVT::f64);
1250 unsigned TmpF12=MakeReg(MVT::f64);
1251 unsigned TmpF13=MakeReg(MVT::f64);
1252 unsigned TmpF14=MakeReg(MVT::f64);
1253 unsigned TmpF15=MakeReg(MVT::f64);
Misha Brukman4633f1c2005-04-21 23:13:11 +00001254
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001255 // OK, emit some code:
1256
1257 if(!isFP) {
1258 // first, load the inputs into FP regs.
1259 BuildMI(BB, IA64::SETFSIG, 1, TmpF1).addReg(Tmp1);
1260 BuildMI(BB, IA64::SETFSIG, 1, TmpF2).addReg(Tmp2);
Misha Brukman4633f1c2005-04-21 23:13:11 +00001261
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001262 // next, convert the inputs to FP
1263 if(isSigned) {
Misha Brukman7847fca2005-04-22 17:54:37 +00001264 BuildMI(BB, IA64::FCVTXF, 1, TmpF3).addReg(TmpF1);
1265 BuildMI(BB, IA64::FCVTXF, 1, TmpF4).addReg(TmpF2);
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001266 } else {
Misha Brukman7847fca2005-04-22 17:54:37 +00001267 BuildMI(BB, IA64::FCVTXUFS1, 1, TmpF3).addReg(TmpF1);
1268 BuildMI(BB, IA64::FCVTXUFS1, 1, TmpF4).addReg(TmpF2);
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001269 }
Misha Brukman4633f1c2005-04-21 23:13:11 +00001270
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001271 } else { // this is an FP divide/remainder, so we 'leak' some temp
1272 // regs and assign TmpF3=Tmp1, TmpF4=Tmp2
1273 TmpF3=Tmp1;
1274 TmpF4=Tmp2;
1275 }
1276
1277 // we start by computing an approximate reciprocal (good to 9 bits?)
Duraid Madina6dcceb52005-04-08 10:01:48 +00001278 // note, this instruction writes _both_ TmpF5 (answer) and TmpPR (predicate)
1279 BuildMI(BB, IA64::FRCPAS1, 4)
1280 .addReg(TmpF5, MachineOperand::Def)
1281 .addReg(TmpPR, MachineOperand::Def)
1282 .addReg(TmpF3).addReg(TmpF4);
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001283
Duraid Madinabeeaab22005-03-31 12:31:11 +00001284 if(!isModulus) { // if this is a divide, we worry about div-by-zero
1285 unsigned bogusPR=MakeReg(MVT::i1); // won't appear, due to twoAddress
1286 // TPCMPNE below
1287 BuildMI(BB, IA64::CMPEQ, 2, bogusPR).addReg(IA64::r0).addReg(IA64::r0);
1288 BuildMI(BB, IA64::TPCMPNE, 3, TmpPR2).addReg(bogusPR)
Misha Brukman7847fca2005-04-22 17:54:37 +00001289 .addReg(IA64::r0).addReg(IA64::r0).addReg(TmpPR);
Duraid Madinabeeaab22005-03-31 12:31:11 +00001290 }
1291
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001292 // now we apply newton's method, thrice! (FIXME: this is ~72 bits of
1293 // precision, don't need this much for f32/i32)
1294 BuildMI(BB, IA64::CFNMAS1, 4, TmpF6)
1295 .addReg(TmpF4).addReg(TmpF5).addReg(IA64::F1).addReg(TmpPR);
1296 BuildMI(BB, IA64::CFMAS1, 4, TmpF7)
1297 .addReg(TmpF3).addReg(TmpF5).addReg(IA64::F0).addReg(TmpPR);
1298 BuildMI(BB, IA64::CFMAS1, 4, TmpF8)
1299 .addReg(TmpF6).addReg(TmpF6).addReg(IA64::F0).addReg(TmpPR);
1300 BuildMI(BB, IA64::CFMAS1, 4, TmpF9)
1301 .addReg(TmpF6).addReg(TmpF7).addReg(TmpF7).addReg(TmpPR);
1302 BuildMI(BB, IA64::CFMAS1, 4,TmpF10)
1303 .addReg(TmpF6).addReg(TmpF5).addReg(TmpF5).addReg(TmpPR);
1304 BuildMI(BB, IA64::CFMAS1, 4,TmpF11)
1305 .addReg(TmpF8).addReg(TmpF9).addReg(TmpF9).addReg(TmpPR);
1306 BuildMI(BB, IA64::CFMAS1, 4,TmpF12)
1307 .addReg(TmpF8).addReg(TmpF10).addReg(TmpF10).addReg(TmpPR);
1308 BuildMI(BB, IA64::CFNMAS1, 4,TmpF13)
1309 .addReg(TmpF4).addReg(TmpF11).addReg(TmpF3).addReg(TmpPR);
Duraid Madina6e02e682005-04-04 05:05:52 +00001310
1311 // FIXME: this is unfortunate :(
1312 // the story is that the dest reg of the fnma above and the fma below
1313 // (and therefore possibly the src of the fcvt.fx[u] as well) cannot
1314 // be the same register, or this code breaks if the first argument is
1315 // zero. (e.g. without this hack, 0%8 yields -64, not 0.)
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001316 BuildMI(BB, IA64::CFMAS1, 4,TmpF14)
1317 .addReg(TmpF13).addReg(TmpF12).addReg(TmpF11).addReg(TmpPR);
1318
Duraid Madina6e02e682005-04-04 05:05:52 +00001319 if(isModulus) { // XXX: fragile! fixes _only_ mod, *breaks* div! !
1320 BuildMI(BB, IA64::IUSE, 1).addReg(TmpF13); // hack :(
1321 }
1322
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001323 if(!isFP) {
1324 // round to an integer
1325 if(isSigned)
Misha Brukman7847fca2005-04-22 17:54:37 +00001326 BuildMI(BB, IA64::FCVTFXTRUNCS1, 1, TmpF15).addReg(TmpF14);
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001327 else
Misha Brukman7847fca2005-04-22 17:54:37 +00001328 BuildMI(BB, IA64::FCVTFXUTRUNCS1, 1, TmpF15).addReg(TmpF14);
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001329 } else {
1330 BuildMI(BB, IA64::FMOV, 1, TmpF15).addReg(TmpF14);
1331 // EXERCISE: can you see why TmpF15=TmpF14 does not work here, and
1332 // we really do need the above FMOV? ;)
1333 }
1334
1335 if(!isModulus) {
Duraid Madinabeeaab22005-03-31 12:31:11 +00001336 if(isFP) { // extra worrying about div-by-zero
1337 unsigned bogoResult=MakeReg(MVT::f64);
1338
1339 // we do a 'conditional fmov' (of the correct result, depending
1340 // on how the frcpa predicate turned out)
1341 BuildMI(BB, IA64::PFMOV, 2, bogoResult)
Misha Brukman7847fca2005-04-22 17:54:37 +00001342 .addReg(TmpF12).addReg(TmpPR2);
Duraid Madinabeeaab22005-03-31 12:31:11 +00001343 BuildMI(BB, IA64::CFMOV, 2, Result)
Misha Brukman7847fca2005-04-22 17:54:37 +00001344 .addReg(bogoResult).addReg(TmpF15).addReg(TmpPR);
Duraid Madinabeeaab22005-03-31 12:31:11 +00001345 }
Duraid Madina6e02e682005-04-04 05:05:52 +00001346 else {
Misha Brukman7847fca2005-04-22 17:54:37 +00001347 BuildMI(BB, IA64::GETFSIG, 1, Result).addReg(TmpF15);
Duraid Madina6e02e682005-04-04 05:05:52 +00001348 }
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001349 } else { // this is a modulus
1350 if(!isFP) {
Misha Brukman7847fca2005-04-22 17:54:37 +00001351 // answer = q * (-b) + a
1352 unsigned ModulusResult = MakeReg(MVT::f64);
1353 unsigned TmpF = MakeReg(MVT::f64);
1354 unsigned TmpI = MakeReg(MVT::i64);
1355
1356 BuildMI(BB, IA64::SUB, 2, TmpI).addReg(IA64::r0).addReg(Tmp2);
1357 BuildMI(BB, IA64::SETFSIG, 1, TmpF).addReg(TmpI);
1358 BuildMI(BB, IA64::XMAL, 3, ModulusResult)
1359 .addReg(TmpF15).addReg(TmpF).addReg(TmpF1);
1360 BuildMI(BB, IA64::GETFSIG, 1, Result).addReg(ModulusResult);
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001361 } else { // FP modulus! The horror... the horror....
Misha Brukman7847fca2005-04-22 17:54:37 +00001362 assert(0 && "sorry, no FP modulus just yet!\n!\n");
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001363 }
1364 }
1365
1366 return Result;
1367 }
1368
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001369 case ISD::SIGN_EXTEND_INREG: {
1370 Tmp1 = SelectExpr(N.getOperand(0));
1371 MVTSDNode* MVN = dyn_cast<MVTSDNode>(Node);
1372 switch(MVN->getExtraValueType())
1373 {
1374 default:
1375 Node->dump();
1376 assert(0 && "don't know how to sign extend this type");
1377 break;
1378 case MVT::i8: Opc = IA64::SXT1; break;
1379 case MVT::i16: Opc = IA64::SXT2; break;
1380 case MVT::i32: Opc = IA64::SXT4; break;
1381 }
1382 BuildMI(BB, Opc, 1, Result).addReg(Tmp1);
1383 return Result;
1384 }
1385
1386 case ISD::SETCC: {
1387 Tmp1 = SelectExpr(N.getOperand(0));
Duraid Madina5ef2ec92005-04-11 05:55:56 +00001388
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001389 if (SetCCSDNode *SetCC = dyn_cast<SetCCSDNode>(Node)) {
1390 if (MVT::isInteger(SetCC->getOperand(0).getValueType())) {
Duraid Madina5ef2ec92005-04-11 05:55:56 +00001391
Misha Brukman7847fca2005-04-22 17:54:37 +00001392 if(ConstantSDNode *CSDN =
1393 dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1394 // if we are comparing against a constant zero
1395 if(CSDN->getValue()==0)
1396 Tmp2 = IA64::r0; // then we can just compare against r0
1397 else
1398 Tmp2 = SelectExpr(N.getOperand(1));
1399 } else // not comparing against a constant
1400 Tmp2 = SelectExpr(N.getOperand(1));
1401
1402 switch (SetCC->getCondition()) {
1403 default: assert(0 && "Unknown integer comparison!");
1404 case ISD::SETEQ:
1405 BuildMI(BB, IA64::CMPEQ, 2, Result).addReg(Tmp1).addReg(Tmp2);
1406 break;
1407 case ISD::SETGT:
1408 BuildMI(BB, IA64::CMPGT, 2, Result).addReg(Tmp1).addReg(Tmp2);
1409 break;
1410 case ISD::SETGE:
1411 BuildMI(BB, IA64::CMPGE, 2, Result).addReg(Tmp1).addReg(Tmp2);
1412 break;
1413 case ISD::SETLT:
1414 BuildMI(BB, IA64::CMPLT, 2, Result).addReg(Tmp1).addReg(Tmp2);
1415 break;
1416 case ISD::SETLE:
1417 BuildMI(BB, IA64::CMPLE, 2, Result).addReg(Tmp1).addReg(Tmp2);
1418 break;
1419 case ISD::SETNE:
1420 BuildMI(BB, IA64::CMPNE, 2, Result).addReg(Tmp1).addReg(Tmp2);
1421 break;
1422 case ISD::SETULT:
1423 BuildMI(BB, IA64::CMPLTU, 2, Result).addReg(Tmp1).addReg(Tmp2);
1424 break;
1425 case ISD::SETUGT:
1426 BuildMI(BB, IA64::CMPGTU, 2, Result).addReg(Tmp1).addReg(Tmp2);
1427 break;
1428 case ISD::SETULE:
1429 BuildMI(BB, IA64::CMPLEU, 2, Result).addReg(Tmp1).addReg(Tmp2);
1430 break;
1431 case ISD::SETUGE:
1432 BuildMI(BB, IA64::CMPGEU, 2, Result).addReg(Tmp1).addReg(Tmp2);
1433 break;
1434 }
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001435 }
1436 else { // if not integer, should be FP. FIXME: what about bools? ;)
Misha Brukman7847fca2005-04-22 17:54:37 +00001437 assert(SetCC->getOperand(0).getValueType() != MVT::f32 &&
1438 "error: SETCC should have had incoming f32 promoted to f64!\n");
Duraid Madina5ef2ec92005-04-11 05:55:56 +00001439
Misha Brukman7847fca2005-04-22 17:54:37 +00001440 if(ConstantFPSDNode *CFPSDN =
1441 dyn_cast<ConstantFPSDNode>(N.getOperand(1))) {
Duraid Madina5ef2ec92005-04-11 05:55:56 +00001442
Misha Brukman7847fca2005-04-22 17:54:37 +00001443 // if we are comparing against a constant +0.0 or +1.0
1444 if(CFPSDN->isExactlyValue(+0.0))
1445 Tmp2 = IA64::F0; // then we can just compare against f0
1446 else if(CFPSDN->isExactlyValue(+1.0))
1447 Tmp2 = IA64::F1; // or f1
1448 else
1449 Tmp2 = SelectExpr(N.getOperand(1));
1450 } else // not comparing against a constant
1451 Tmp2 = SelectExpr(N.getOperand(1));
Duraid Madina5ef2ec92005-04-11 05:55:56 +00001452
Misha Brukman7847fca2005-04-22 17:54:37 +00001453 switch (SetCC->getCondition()) {
1454 default: assert(0 && "Unknown FP comparison!");
1455 case ISD::SETEQ:
1456 BuildMI(BB, IA64::FCMPEQ, 2, Result).addReg(Tmp1).addReg(Tmp2);
1457 break;
1458 case ISD::SETGT:
1459 BuildMI(BB, IA64::FCMPGT, 2, Result).addReg(Tmp1).addReg(Tmp2);
1460 break;
1461 case ISD::SETGE:
1462 BuildMI(BB, IA64::FCMPGE, 2, Result).addReg(Tmp1).addReg(Tmp2);
1463 break;
1464 case ISD::SETLT:
1465 BuildMI(BB, IA64::FCMPLT, 2, Result).addReg(Tmp1).addReg(Tmp2);
1466 break;
1467 case ISD::SETLE:
1468 BuildMI(BB, IA64::FCMPLE, 2, Result).addReg(Tmp1).addReg(Tmp2);
1469 break;
1470 case ISD::SETNE:
1471 BuildMI(BB, IA64::FCMPNE, 2, Result).addReg(Tmp1).addReg(Tmp2);
1472 break;
1473 case ISD::SETULT:
1474 BuildMI(BB, IA64::FCMPLTU, 2, Result).addReg(Tmp1).addReg(Tmp2);
1475 break;
1476 case ISD::SETUGT:
1477 BuildMI(BB, IA64::FCMPGTU, 2, Result).addReg(Tmp1).addReg(Tmp2);
1478 break;
1479 case ISD::SETULE:
1480 BuildMI(BB, IA64::FCMPLEU, 2, Result).addReg(Tmp1).addReg(Tmp2);
1481 break;
1482 case ISD::SETUGE:
1483 BuildMI(BB, IA64::FCMPGEU, 2, Result).addReg(Tmp1).addReg(Tmp2);
1484 break;
1485 }
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001486 }
1487 }
1488 else
1489 assert(0 && "this setcc not implemented yet");
1490
1491 return Result;
1492 }
1493
1494 case ISD::EXTLOAD:
1495 case ISD::ZEXTLOAD:
1496 case ISD::LOAD: {
1497 // Make sure we generate both values.
1498 if (Result != 1)
1499 ExprMap[N.getValue(1)] = 1; // Generate the token
1500 else
1501 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
1502
1503 bool isBool=false;
Misha Brukman4633f1c2005-04-21 23:13:11 +00001504
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001505 if(opcode == ISD::LOAD) { // this is a LOAD
1506 switch (Node->getValueType(0)) {
Misha Brukman7847fca2005-04-22 17:54:37 +00001507 default: assert(0 && "Cannot load this type!");
1508 case MVT::i1: Opc = IA64::LD1; isBool=true; break;
1509 // FIXME: for now, we treat bool loads the same as i8 loads */
1510 case MVT::i8: Opc = IA64::LD1; break;
1511 case MVT::i16: Opc = IA64::LD2; break;
1512 case MVT::i32: Opc = IA64::LD4; break;
1513 case MVT::i64: Opc = IA64::LD8; break;
1514
1515 case MVT::f32: Opc = IA64::LDF4; break;
1516 case MVT::f64: Opc = IA64::LDF8; break;
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001517 }
1518 } else { // this is an EXTLOAD or ZEXTLOAD
1519 MVT::ValueType TypeBeingLoaded = cast<MVTSDNode>(Node)->getExtraValueType();
1520 switch (TypeBeingLoaded) {
Misha Brukman7847fca2005-04-22 17:54:37 +00001521 default: assert(0 && "Cannot extload/zextload this type!");
1522 // FIXME: bools?
1523 case MVT::i8: Opc = IA64::LD1; break;
1524 case MVT::i16: Opc = IA64::LD2; break;
1525 case MVT::i32: Opc = IA64::LD4; break;
1526 case MVT::f32: Opc = IA64::LDF4; break;
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001527 }
1528 }
Misha Brukman4633f1c2005-04-21 23:13:11 +00001529
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001530 SDOperand Chain = N.getOperand(0);
1531 SDOperand Address = N.getOperand(1);
1532
1533 if(Address.getOpcode() == ISD::GlobalAddress) {
1534 Select(Chain);
1535 unsigned dummy = MakeReg(MVT::i64);
1536 unsigned dummy2 = MakeReg(MVT::i64);
1537 BuildMI(BB, IA64::ADD, 2, dummy)
Misha Brukman7847fca2005-04-22 17:54:37 +00001538 .addGlobalAddress(cast<GlobalAddressSDNode>(Address)->getGlobal())
1539 .addReg(IA64::r1);
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001540 BuildMI(BB, IA64::LD8, 1, dummy2).addReg(dummy);
1541 if(!isBool)
Misha Brukman7847fca2005-04-22 17:54:37 +00001542 BuildMI(BB, Opc, 1, Result).addReg(dummy2);
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001543 else { // emit a little pseudocode to load a bool (stored in one byte)
Misha Brukman7847fca2005-04-22 17:54:37 +00001544 // into a predicate register
1545 assert(Opc==IA64::LD1 && "problem loading a bool");
1546 unsigned dummy3 = MakeReg(MVT::i64);
1547 BuildMI(BB, Opc, 1, dummy3).addReg(dummy2);
1548 // we compare to 0. true? 0. false? 1.
1549 BuildMI(BB, IA64::CMPNE, 2, Result).addReg(dummy3).addReg(IA64::r0);
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001550 }
1551 } else if(ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(Address)) {
1552 Select(Chain);
1553 IA64Lowering.restoreGP(BB);
1554 unsigned dummy = MakeReg(MVT::i64);
1555 BuildMI(BB, IA64::ADD, 2, dummy).addConstantPoolIndex(CP->getIndex())
Misha Brukman7847fca2005-04-22 17:54:37 +00001556 .addReg(IA64::r1); // CPI+GP
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001557 if(!isBool)
Misha Brukman7847fca2005-04-22 17:54:37 +00001558 BuildMI(BB, Opc, 1, Result).addReg(dummy);
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001559 else { // emit a little pseudocode to load a bool (stored in one byte)
Misha Brukman7847fca2005-04-22 17:54:37 +00001560 // into a predicate register
1561 assert(Opc==IA64::LD1 && "problem loading a bool");
1562 unsigned dummy3 = MakeReg(MVT::i64);
1563 BuildMI(BB, Opc, 1, dummy3).addReg(dummy);
1564 // we compare to 0. true? 0. false? 1.
1565 BuildMI(BB, IA64::CMPNE, 2, Result).addReg(dummy3).addReg(IA64::r0);
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001566 }
1567 } else if(Address.getOpcode() == ISD::FrameIndex) {
1568 Select(Chain); // FIXME ? what about bools?
1569 unsigned dummy = MakeReg(MVT::i64);
1570 BuildMI(BB, IA64::MOV, 1, dummy)
Misha Brukman7847fca2005-04-22 17:54:37 +00001571 .addFrameIndex(cast<FrameIndexSDNode>(Address)->getIndex());
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001572 if(!isBool)
Misha Brukman7847fca2005-04-22 17:54:37 +00001573 BuildMI(BB, Opc, 1, Result).addReg(dummy);
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001574 else { // emit a little pseudocode to load a bool (stored in one byte)
Misha Brukman7847fca2005-04-22 17:54:37 +00001575 // into a predicate register
1576 assert(Opc==IA64::LD1 && "problem loading a bool");
1577 unsigned dummy3 = MakeReg(MVT::i64);
1578 BuildMI(BB, Opc, 1, dummy3).addReg(dummy);
1579 // we compare to 0. true? 0. false? 1.
1580 BuildMI(BB, IA64::CMPNE, 2, Result).addReg(dummy3).addReg(IA64::r0);
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001581 }
Misha Brukman4633f1c2005-04-21 23:13:11 +00001582 } else { // none of the above...
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001583 Select(Chain);
1584 Tmp2 = SelectExpr(Address);
1585 if(!isBool)
Misha Brukman7847fca2005-04-22 17:54:37 +00001586 BuildMI(BB, Opc, 1, Result).addReg(Tmp2);
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001587 else { // emit a little pseudocode to load a bool (stored in one byte)
Misha Brukman7847fca2005-04-22 17:54:37 +00001588 // into a predicate register
1589 assert(Opc==IA64::LD1 && "problem loading a bool");
1590 unsigned dummy = MakeReg(MVT::i64);
1591 BuildMI(BB, Opc, 1, dummy).addReg(Tmp2);
1592 // we compare to 0. true? 0. false? 1.
1593 BuildMI(BB, IA64::CMPNE, 2, Result).addReg(dummy).addReg(IA64::r0);
1594 }
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001595 }
1596
1597 return Result;
1598 }
Misha Brukman4633f1c2005-04-21 23:13:11 +00001599
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001600 case ISD::CopyFromReg: {
1601 if (Result == 1)
Misha Brukman4633f1c2005-04-21 23:13:11 +00001602 Result = ExprMap[N.getValue(0)] =
Misha Brukman7847fca2005-04-22 17:54:37 +00001603 MakeReg(N.getValue(0).getValueType());
Misha Brukman4633f1c2005-04-21 23:13:11 +00001604
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001605 SDOperand Chain = N.getOperand(0);
1606
1607 Select(Chain);
1608 unsigned r = dyn_cast<RegSDNode>(Node)->getReg();
1609
1610 if(N.getValueType() == MVT::i1) // if a bool, we use pseudocode
Misha Brukman7847fca2005-04-22 17:54:37 +00001611 BuildMI(BB, IA64::PCMPEQUNC, 3, Result)
1612 .addReg(IA64::r0).addReg(IA64::r0).addReg(r);
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001613 // (r) Result =cmp.eq.unc(r0,r0)
1614 else
Misha Brukman7847fca2005-04-22 17:54:37 +00001615 BuildMI(BB, IA64::MOV, 1, Result).addReg(r); // otherwise MOV
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001616 return Result;
1617 }
1618
1619 case ISD::CALL: {
1620 Select(N.getOperand(0));
1621
1622 // The chain for this call is now lowered.
1623 ExprMap.insert(std::make_pair(N.getValue(Node->getNumValues()-1), 1));
Misha Brukman4633f1c2005-04-21 23:13:11 +00001624
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001625 //grab the arguments
1626 std::vector<unsigned> argvregs;
1627
1628 for(int i = 2, e = Node->getNumOperands(); i < e; ++i)
Misha Brukman7847fca2005-04-22 17:54:37 +00001629 argvregs.push_back(SelectExpr(N.getOperand(i)));
Misha Brukman4633f1c2005-04-21 23:13:11 +00001630
1631 // see section 8.5.8 of "Itanium Software Conventions and
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001632 // Runtime Architecture Guide to see some examples of what's going
1633 // on here. (in short: int args get mapped 1:1 'slot-wise' to out0->out7,
1634 // while FP args get mapped to F8->F15 as needed)
1635
1636 unsigned used_FPArgs=0; // how many FP Args have been used so far?
Misha Brukman4633f1c2005-04-21 23:13:11 +00001637
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001638 // in reg args
1639 for(int i = 0, e = std::min(8, (int)argvregs.size()); i < e; ++i)
1640 {
Misha Brukman7847fca2005-04-22 17:54:37 +00001641 unsigned intArgs[] = {IA64::out0, IA64::out1, IA64::out2, IA64::out3,
1642 IA64::out4, IA64::out5, IA64::out6, IA64::out7 };
1643 unsigned FPArgs[] = {IA64::F8, IA64::F9, IA64::F10, IA64::F11,
1644 IA64::F12, IA64::F13, IA64::F14, IA64::F15 };
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001645
Misha Brukman7847fca2005-04-22 17:54:37 +00001646 switch(N.getOperand(i+2).getValueType())
1647 {
1648 default: // XXX do we need to support MVT::i1 here?
1649 Node->dump();
1650 N.getOperand(i).Val->dump();
1651 std::cerr << "Type for " << i << " is: " <<
1652 N.getOperand(i+2).getValueType() << std::endl;
1653 assert(0 && "Unknown value type for call");
1654 case MVT::i64:
1655 BuildMI(BB, IA64::MOV, 1, intArgs[i]).addReg(argvregs[i]);
1656 break;
1657 case MVT::f64:
1658 BuildMI(BB, IA64::FMOV, 1, FPArgs[used_FPArgs++])
1659 .addReg(argvregs[i]);
1660 // FIXME: we don't need to do this _all_ the time:
1661 BuildMI(BB, IA64::GETFD, 1, intArgs[i]).addReg(argvregs[i]);
1662 break;
1663 }
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001664 }
1665
1666 //in mem args
1667 for (int i = 8, e = argvregs.size(); i < e; ++i)
1668 {
Misha Brukman7847fca2005-04-22 17:54:37 +00001669 unsigned tempAddr = MakeReg(MVT::i64);
1670
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001671 switch(N.getOperand(i+2).getValueType()) {
Misha Brukman4633f1c2005-04-21 23:13:11 +00001672 default:
1673 Node->dump();
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001674 N.getOperand(i).Val->dump();
Misha Brukman4633f1c2005-04-21 23:13:11 +00001675 std::cerr << "Type for " << i << " is: " <<
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001676 N.getOperand(i+2).getValueType() << "\n";
1677 assert(0 && "Unknown value type for call");
1678 case MVT::i1: // FIXME?
1679 case MVT::i8:
1680 case MVT::i16:
1681 case MVT::i32:
1682 case MVT::i64:
Misha Brukman7847fca2005-04-22 17:54:37 +00001683 BuildMI(BB, IA64::ADDIMM22, 2, tempAddr)
1684 .addReg(IA64::r12).addImm(16 + (i - 8) * 8); // r12 is SP
1685 BuildMI(BB, IA64::ST8, 2).addReg(tempAddr).addReg(argvregs[i]);
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001686 break;
1687 case MVT::f32:
1688 case MVT::f64:
1689 BuildMI(BB, IA64::ADDIMM22, 2, tempAddr)
Misha Brukman7847fca2005-04-22 17:54:37 +00001690 .addReg(IA64::r12).addImm(16 + (i - 8) * 8); // r12 is SP
1691 BuildMI(BB, IA64::STF8, 2).addReg(tempAddr).addReg(argvregs[i]);
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001692 break;
1693 }
1694 }
Duraid Madinabeeaab22005-03-31 12:31:11 +00001695
1696 /* XXX we want to re-enable direct branches! crippling them now
Misha Brukman4633f1c2005-04-21 23:13:11 +00001697 * to stress-test indirect branches.:
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001698 //build the right kind of call
1699 if (GlobalAddressSDNode *GASD =
Misha Brukman4633f1c2005-04-21 23:13:11 +00001700 dyn_cast<GlobalAddressSDNode>(N.getOperand(1)))
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001701 {
Misha Brukman7847fca2005-04-22 17:54:37 +00001702 BuildMI(BB, IA64::BRCALL, 1).addGlobalAddress(GASD->getGlobal(),true);
1703 IA64Lowering.restoreGP_SP_RP(BB);
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001704 }
Misha Brukman4633f1c2005-04-21 23:13:11 +00001705 ^^^^^^^^^^^^^ we want this code one day XXX */
Duraid Madinabeeaab22005-03-31 12:31:11 +00001706 if (ExternalSymbolSDNode *ESSDN =
Misha Brukman7847fca2005-04-22 17:54:37 +00001707 dyn_cast<ExternalSymbolSDNode>(N.getOperand(1)))
Duraid Madinabeeaab22005-03-31 12:31:11 +00001708 { // FIXME : currently need this case for correctness, to avoid
Misha Brukman7847fca2005-04-22 17:54:37 +00001709 // "non-pic code with imm relocation against dynamic symbol" errors
1710 BuildMI(BB, IA64::BRCALL, 1)
1711 .addExternalSymbol(ESSDN->getSymbol(), true);
1712 IA64Lowering.restoreGP_SP_RP(BB);
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001713 }
1714 else {
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001715 Tmp1 = SelectExpr(N.getOperand(1));
Duraid Madinabeeaab22005-03-31 12:31:11 +00001716
1717 unsigned targetEntryPoint=MakeReg(MVT::i64);
1718 unsigned targetGPAddr=MakeReg(MVT::i64);
1719 unsigned currentGP=MakeReg(MVT::i64);
Misha Brukman4633f1c2005-04-21 23:13:11 +00001720
Duraid Madinabeeaab22005-03-31 12:31:11 +00001721 // b6 is a scratch branch register, we load the target entry point
1722 // from the base of the function descriptor
1723 BuildMI(BB, IA64::LD8, 1, targetEntryPoint).addReg(Tmp1);
1724 BuildMI(BB, IA64::MOV, 1, IA64::B6).addReg(targetEntryPoint);
1725
1726 // save the current GP:
1727 BuildMI(BB, IA64::MOV, 1, currentGP).addReg(IA64::r1);
Misha Brukman4633f1c2005-04-21 23:13:11 +00001728
Duraid Madinabeeaab22005-03-31 12:31:11 +00001729 /* TODO: we need to make sure doing this never, ever loads a
1730 * bogus value into r1 (GP). */
1731 // load the target GP (which is at mem[functiondescriptor+8])
1732 BuildMI(BB, IA64::ADDIMM22, 2, targetGPAddr)
Misha Brukman7847fca2005-04-22 17:54:37 +00001733 .addReg(Tmp1).addImm(8); // FIXME: addimm22? why not postincrement ld
Duraid Madinabeeaab22005-03-31 12:31:11 +00001734 BuildMI(BB, IA64::LD8, 1, IA64::r1).addReg(targetGPAddr);
1735
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001736 // and then jump: (well, call)
1737 BuildMI(BB, IA64::BRCALL, 1).addReg(IA64::B6);
Duraid Madinabeeaab22005-03-31 12:31:11 +00001738 // and finally restore the old GP
1739 BuildMI(BB, IA64::MOV, 1, IA64::r1).addReg(currentGP);
1740 IA64Lowering.restoreSP_RP(BB);
1741 }
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001742
1743 switch (Node->getValueType(0)) {
1744 default: assert(0 && "Unknown value type for call result!");
1745 case MVT::Other: return 1;
1746 case MVT::i1:
1747 BuildMI(BB, IA64::CMPNE, 2, Result)
Misha Brukman7847fca2005-04-22 17:54:37 +00001748 .addReg(IA64::r8).addReg(IA64::r0);
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001749 break;
1750 case MVT::i8:
1751 case MVT::i16:
1752 case MVT::i32:
1753 case MVT::i64:
1754 BuildMI(BB, IA64::MOV, 1, Result).addReg(IA64::r8);
1755 break;
1756 case MVT::f64:
1757 BuildMI(BB, IA64::FMOV, 1, Result).addReg(IA64::F8);
1758 break;
1759 }
1760 return Result+N.ResNo;
1761 }
1762
Misha Brukman4633f1c2005-04-21 23:13:11 +00001763 } // <- uhhh XXX
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001764 return 0;
1765}
1766
1767void ISel::Select(SDOperand N) {
1768 unsigned Tmp1, Tmp2, Opc;
1769 unsigned opcode = N.getOpcode();
1770
Nate Begeman85fdeb22005-03-24 04:39:54 +00001771 if (!LoweredTokens.insert(N).second)
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001772 return; // Already selected.
1773
1774 SDNode *Node = N.Val;
1775
1776 switch (Node->getOpcode()) {
1777 default:
1778 Node->dump(); std::cerr << "\n";
1779 assert(0 && "Node not handled yet!");
1780
1781 case ISD::EntryToken: return; // Noop
Misha Brukman4633f1c2005-04-21 23:13:11 +00001782
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001783 case ISD::TokenFactor: {
1784 for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i)
1785 Select(Node->getOperand(i));
1786 return;
1787 }
1788
1789 case ISD::CopyToReg: {
1790 Select(N.getOperand(0));
Misha Brukman4633f1c2005-04-21 23:13:11 +00001791 Tmp1 = SelectExpr(N.getOperand(1));
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001792 Tmp2 = cast<RegSDNode>(N)->getReg();
Misha Brukman4633f1c2005-04-21 23:13:11 +00001793
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001794 if (Tmp1 != Tmp2) {
1795 if(N.getValueType() == MVT::i1) // if a bool, we use pseudocode
Misha Brukman7847fca2005-04-22 17:54:37 +00001796 BuildMI(BB, IA64::PCMPEQUNC, 3, Tmp2)
1797 .addReg(IA64::r0).addReg(IA64::r0).addReg(Tmp1);
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001798 // (Tmp1) Tmp2 = cmp.eq.unc(r0,r0)
1799 else
Misha Brukman7847fca2005-04-22 17:54:37 +00001800 BuildMI(BB, IA64::MOV, 1, Tmp2).addReg(Tmp1);
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001801 // XXX is this the right way 'round? ;)
1802 }
1803 return;
1804 }
Misha Brukman4633f1c2005-04-21 23:13:11 +00001805
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001806 case ISD::RET: {
1807
1808 /* what the heck is going on here:
1809
1810<_sabre_> ret with two operands is obvious: chain and value
1811<camel_> yep
1812<_sabre_> ret with 3 values happens when 'expansion' occurs
1813<_sabre_> e.g. i64 gets split into 2x i32
1814<camel_> oh right
1815<_sabre_> you don't have this case on ia64
1816<camel_> yep
1817<_sabre_> so the two returned values go into EAX/EDX on ia32
1818<camel_> ahhh *memories*
1819<_sabre_> :)
1820<camel_> ok, thanks :)
1821<_sabre_> so yeah, everything that has a side effect takes a 'token chain'
1822<_sabre_> this is the first operand always
1823<_sabre_> these operand often define chains, they are the last operand
1824<_sabre_> they are printed as 'ch' if you do DAG.dump()
1825 */
Misha Brukman4633f1c2005-04-21 23:13:11 +00001826
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001827 switch (N.getNumOperands()) {
1828 default:
1829 assert(0 && "Unknown return instruction!");
1830 case 2:
1831 Select(N.getOperand(0));
1832 Tmp1 = SelectExpr(N.getOperand(1));
1833 switch (N.getOperand(1).getValueType()) {
1834 default: assert(0 && "All other types should have been promoted!!");
Misha Brukman7847fca2005-04-22 17:54:37 +00001835 // FIXME: do I need to add support for bools here?
1836 // (return '0' or '1' r8, basically...)
1837 //
1838 // FIXME: need to round floats - 80 bits is bad, the tester
1839 // told me so
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001840 case MVT::i64:
Misha Brukman7847fca2005-04-22 17:54:37 +00001841 // we mark r8 as live on exit up above in LowerArguments()
1842 BuildMI(BB, IA64::MOV, 1, IA64::r8).addReg(Tmp1);
1843 break;
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001844 case MVT::f64:
Misha Brukman7847fca2005-04-22 17:54:37 +00001845 // we mark F8 as live on exit up above in LowerArguments()
1846 BuildMI(BB, IA64::FMOV, 1, IA64::F8).addReg(Tmp1);
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001847 }
1848 break;
1849 case 1:
1850 Select(N.getOperand(0));
1851 break;
1852 }
1853 // before returning, restore the ar.pfs register (set by the 'alloc' up top)
1854 BuildMI(BB, IA64::MOV, 1).addReg(IA64::AR_PFS).addReg(IA64Lowering.VirtGPR);
1855 BuildMI(BB, IA64::RET, 0); // and then just emit a 'ret' instruction
1856 return;
1857 }
Misha Brukman4633f1c2005-04-21 23:13:11 +00001858
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001859 case ISD::BR: {
1860 Select(N.getOperand(0));
1861 MachineBasicBlock *Dest =
1862 cast<BasicBlockSDNode>(N.getOperand(1))->getBasicBlock();
1863 BuildMI(BB, IA64::BRLCOND_NOTCALL, 1).addReg(IA64::p0).addMBB(Dest);
1864 // XXX HACK! we do _not_ need long branches all the time
1865 return;
1866 }
1867
1868 case ISD::ImplicitDef: {
1869 Select(N.getOperand(0));
1870 BuildMI(BB, IA64::IDEF, 0, cast<RegSDNode>(N)->getReg());
1871 return;
1872 }
1873
1874 case ISD::BRCOND: {
1875 MachineBasicBlock *Dest =
1876 cast<BasicBlockSDNode>(N.getOperand(2))->getBasicBlock();
1877
1878 Select(N.getOperand(0));
1879 Tmp1 = SelectExpr(N.getOperand(1));
1880 BuildMI(BB, IA64::BRLCOND_NOTCALL, 1).addReg(Tmp1).addMBB(Dest);
1881 // XXX HACK! we do _not_ need long branches all the time
1882 return;
1883 }
Misha Brukman4633f1c2005-04-21 23:13:11 +00001884
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001885 case ISD::EXTLOAD:
1886 case ISD::ZEXTLOAD:
1887 case ISD::SEXTLOAD:
1888 case ISD::LOAD:
1889 case ISD::CALL:
1890 case ISD::CopyFromReg:
1891 case ISD::DYNAMIC_STACKALLOC:
1892 SelectExpr(N);
1893 return;
1894
1895 case ISD::TRUNCSTORE:
1896 case ISD::STORE: {
1897 Select(N.getOperand(0));
1898 Tmp1 = SelectExpr(N.getOperand(1)); // value
1899
1900 bool isBool=false;
Misha Brukman4633f1c2005-04-21 23:13:11 +00001901
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001902 if(opcode == ISD::STORE) {
Misha Brukman7847fca2005-04-22 17:54:37 +00001903 switch (N.getOperand(1).getValueType()) {
1904 default: assert(0 && "Cannot store this type!");
1905 case MVT::i1: Opc = IA64::ST1; isBool=true; break;
1906 // FIXME?: for now, we treat bool loads the same as i8 stores */
1907 case MVT::i8: Opc = IA64::ST1; break;
1908 case MVT::i16: Opc = IA64::ST2; break;
1909 case MVT::i32: Opc = IA64::ST4; break;
1910 case MVT::i64: Opc = IA64::ST8; break;
1911
1912 case MVT::f32: Opc = IA64::STF4; break;
1913 case MVT::f64: Opc = IA64::STF8; break;
1914 }
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001915 } else { // truncstore
Misha Brukman7847fca2005-04-22 17:54:37 +00001916 switch(cast<MVTSDNode>(Node)->getExtraValueType()) {
1917 default: assert(0 && "unknown type in truncstore");
1918 case MVT::i1: Opc = IA64::ST1; isBool=true; break;
1919 //FIXME: DAG does not promote this load?
1920 case MVT::i8: Opc = IA64::ST1; break;
1921 case MVT::i16: Opc = IA64::ST2; break;
1922 case MVT::i32: Opc = IA64::ST4; break;
1923 case MVT::f32: Opc = IA64::STF4; break;
1924 }
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001925 }
1926
1927 if(N.getOperand(2).getOpcode() == ISD::GlobalAddress) {
Misha Brukman7847fca2005-04-22 17:54:37 +00001928 unsigned dummy = MakeReg(MVT::i64);
1929 unsigned dummy2 = MakeReg(MVT::i64);
1930 BuildMI(BB, IA64::ADD, 2, dummy)
1931 .addGlobalAddress(cast<GlobalAddressSDNode>
1932 (N.getOperand(2))->getGlobal()).addReg(IA64::r1);
1933 BuildMI(BB, IA64::LD8, 1, dummy2).addReg(dummy);
Misha Brukman4633f1c2005-04-21 23:13:11 +00001934
Misha Brukman7847fca2005-04-22 17:54:37 +00001935 if(!isBool)
1936 BuildMI(BB, Opc, 2).addReg(dummy2).addReg(Tmp1);
1937 else { // we are storing a bool, so emit a little pseudocode
1938 // to store a predicate register as one byte
1939 assert(Opc==IA64::ST1);
1940 unsigned dummy3 = MakeReg(MVT::i64);
1941 unsigned dummy4 = MakeReg(MVT::i64);
1942 BuildMI(BB, IA64::MOV, 1, dummy3).addReg(IA64::r0);
1943 BuildMI(BB, IA64::TPCADDIMM22, 2, dummy4)
1944 .addReg(dummy3).addImm(1).addReg(Tmp1); // if(Tmp1) dummy=0+1;
1945 BuildMI(BB, Opc, 2).addReg(dummy2).addReg(dummy4);
1946 }
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001947 } else if(N.getOperand(2).getOpcode() == ISD::FrameIndex) {
1948
Misha Brukman7847fca2005-04-22 17:54:37 +00001949 // FIXME? (what about bools?)
1950
1951 unsigned dummy = MakeReg(MVT::i64);
1952 BuildMI(BB, IA64::MOV, 1, dummy)
1953 .addFrameIndex(cast<FrameIndexSDNode>(N.getOperand(2))->getIndex());
1954 BuildMI(BB, Opc, 2).addReg(dummy).addReg(Tmp1);
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001955 } else { // otherwise
Misha Brukman7847fca2005-04-22 17:54:37 +00001956 Tmp2 = SelectExpr(N.getOperand(2)); //address
1957 if(!isBool)
1958 BuildMI(BB, Opc, 2).addReg(Tmp2).addReg(Tmp1);
1959 else { // we are storing a bool, so emit a little pseudocode
1960 // to store a predicate register as one byte
1961 assert(Opc==IA64::ST1);
1962 unsigned dummy3 = MakeReg(MVT::i64);
1963 unsigned dummy4 = MakeReg(MVT::i64);
1964 BuildMI(BB, IA64::MOV, 1, dummy3).addReg(IA64::r0);
1965 BuildMI(BB, IA64::TPCADDIMM22, 2, dummy4)
1966 .addReg(dummy3).addImm(1).addReg(Tmp1); // if(Tmp1) dummy=0+1;
1967 BuildMI(BB, Opc, 2).addReg(Tmp2).addReg(dummy4);
1968 }
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001969 }
1970 return;
1971 }
Misha Brukman4633f1c2005-04-21 23:13:11 +00001972
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001973 case ISD::ADJCALLSTACKDOWN:
1974 case ISD::ADJCALLSTACKUP: {
1975 Select(N.getOperand(0));
1976 Tmp1 = cast<ConstantSDNode>(N.getOperand(1))->getValue();
Misha Brukman4633f1c2005-04-21 23:13:11 +00001977
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001978 Opc = N.getOpcode() == ISD::ADJCALLSTACKDOWN ? IA64::ADJUSTCALLSTACKDOWN :
1979 IA64::ADJUSTCALLSTACKUP;
1980 BuildMI(BB, Opc, 1).addImm(Tmp1);
1981 return;
1982 }
1983
1984 return;
1985 }
1986 assert(0 && "GAME OVER. INSERT COIN?");
1987}
1988
1989
1990/// createIA64PatternInstructionSelector - This pass converts an LLVM function
1991/// into a machine code representation using pattern matching and a machine
1992/// description file.
1993///
1994FunctionPass *llvm::createIA64PatternInstructionSelector(TargetMachine &TM) {
Misha Brukman4633f1c2005-04-21 23:13:11 +00001995 return new ISel(TM);
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001996}
1997
1998