1 //===- AlphaISelPattern.cpp - A pattern matching inst selector for Alpha --===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines a pattern matching instruction selector for Alpha.
12 //===----------------------------------------------------------------------===//
15 #include "AlphaRegisterInfo.h"
16 #include "llvm/Constants.h" // FIXME: REMOVE
17 #include "llvm/Function.h"
18 #include "llvm/Module.h"
19 #include "llvm/CodeGen/MachineInstrBuilder.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 "llvm/Support/Debug.h"
31 #include "llvm/Support/CommandLine.h"
37 cl::opt<bool> EnableAlphaIDIV("enable-alpha-intfpdiv",
38 cl::desc("Use the FP div instruction for integer div when possible"),
40 cl::opt<bool> EnableAlphaFTOI("enable-alpha-FTOI",
41 cl::desc("Enable use of ftoi* and itof* instructions (ev6 and higher)"),
43 cl::opt<bool> EnableAlphaCT("enable-alpha-CT",
44 cl::desc("Enable use of the ctpop, ctlz, and cttz instructions"),
46 cl::opt<bool> EnableAlphaCount("enable-alpha-count",
47 cl::desc("Print estimates on live ins and outs"),
49 cl::opt<bool> EnableAlphaLSMark("enable-alpha-lsmark",
50 cl::desc("Emit symbols to correlate Mem ops to LLVM Values"),
55 // Alpha Specific DAG Nodes
58 // Start the numbering where the builtin ops leave off.
59 FIRST_NUMBER = ISD::BUILTIN_OP_END,
61 //Convert an int bit pattern in an FP reg to a Double or Float
62 //Has a dest type and a source
64 //Move an Ireg to a FPreg
66 //Move a FPreg to an Ireg
72 //===----------------------------------------------------------------------===//
73 // AlphaTargetLowering - Alpha Implementation of the TargetLowering interface
75 class AlphaTargetLowering : public TargetLowering {
76 int VarArgsOffset; // What is the offset to the first vaarg
77 int VarArgsBase; // What is the base FrameIndex
78 unsigned GP; //GOT vreg
79 unsigned RA; //Return Address
81 AlphaTargetLowering(TargetMachine &TM) : TargetLowering(TM) {
82 // Set up the TargetLowering object.
83 //I am having problems with shr n ubyte 1
84 setShiftAmountType(MVT::i64);
85 setSetCCResultType(MVT::i64);
86 setSetCCResultContents(ZeroOrOneSetCCResult);
88 addRegisterClass(MVT::i64, Alpha::GPRCRegisterClass);
89 addRegisterClass(MVT::f64, Alpha::FPRCRegisterClass);
90 addRegisterClass(MVT::f32, Alpha::FPRCRegisterClass);
92 setOperationAction(ISD::BRCONDTWOWAY, MVT::Other, Expand);
94 setOperationAction(ISD::EXTLOAD, MVT::i1, Promote);
95 setOperationAction(ISD::EXTLOAD, MVT::f32, Expand);
97 setOperationAction(ISD::ZEXTLOAD, MVT::i1, Promote);
98 setOperationAction(ISD::ZEXTLOAD, MVT::i32, Expand);
100 setOperationAction(ISD::SEXTLOAD, MVT::i1, Promote);
101 setOperationAction(ISD::SEXTLOAD, MVT::i8, Expand);
102 setOperationAction(ISD::SEXTLOAD, MVT::i16, Expand);
104 setOperationAction(ISD::SREM, MVT::f32, Expand);
105 setOperationAction(ISD::SREM, MVT::f64, Expand);
107 setOperationAction(ISD::UINT_TO_FP, MVT::i64, Expand);
109 if (!EnableAlphaCT) {
110 setOperationAction(ISD::CTPOP , MVT::i64 , Expand);
111 setOperationAction(ISD::CTTZ , MVT::i64 , Expand);
112 setOperationAction(ISD::CTLZ , MVT::i64 , Expand);
115 //If this didn't legalize into a div....
116 // setOperationAction(ISD::SREM , MVT::i64, Expand);
117 // setOperationAction(ISD::UREM , MVT::i64, Expand);
119 setOperationAction(ISD::MEMMOVE , MVT::Other, Expand);
120 setOperationAction(ISD::MEMSET , MVT::Other, Expand);
121 setOperationAction(ISD::MEMCPY , MVT::Other, Expand);
123 // We don't support sin/cos/sqrt
124 setOperationAction(ISD::FSIN , MVT::f64, Expand);
125 setOperationAction(ISD::FCOS , MVT::f64, Expand);
126 setOperationAction(ISD::FSQRT, MVT::f64, Expand);
127 setOperationAction(ISD::FSIN , MVT::f32, Expand);
128 setOperationAction(ISD::FCOS , MVT::f32, Expand);
129 setOperationAction(ISD::FSQRT, MVT::f32, Expand);
132 setOperationAction(ISD::SETCC, MVT::f32, Promote);
134 //Try a couple things with a custom expander
135 //setOperationAction(ISD::SINT_TO_FP , MVT::i64 , Custom);
137 computeRegisterProperties();
139 addLegalFPImmediate(+0.0); //F31
140 addLegalFPImmediate(-0.0); //-F31
143 /// LowerOperation - Provide custom lowering hooks for some operations.
145 virtual SDOperand LowerOperation(SDOperand Op, SelectionDAG &DAG);
147 /// LowerArguments - This hook must be implemented to indicate how we should
148 /// lower the arguments for the specified function, into the specified DAG.
149 virtual std::vector<SDOperand>
150 LowerArguments(Function &F, SelectionDAG &DAG);
152 /// LowerCallTo - This hook lowers an abstract call to a function into an
154 virtual std::pair<SDOperand, SDOperand>
155 LowerCallTo(SDOperand Chain, const Type *RetTy, bool isVarArg, unsigned CC,
156 bool isTailCall, SDOperand Callee, ArgListTy &Args,
159 virtual SDOperand LowerVAStart(SDOperand Chain, SDOperand VAListP,
160 Value *VAListV, SelectionDAG &DAG);
161 virtual SDOperand LowerVACopy(SDOperand Chain, SDOperand SrcP, Value *SrcV,
162 SDOperand DestP, Value *DestV,
164 virtual std::pair<SDOperand,SDOperand>
165 LowerVAArg(SDOperand Chain, SDOperand VAListP, Value *VAListV,
166 const Type *ArgTy, SelectionDAG &DAG);
168 void restoreGP(MachineBasicBlock* BB)
170 BuildMI(BB, Alpha::BIS, 2, Alpha::R29).addReg(GP).addReg(GP);
172 void restoreRA(MachineBasicBlock* BB)
174 BuildMI(BB, Alpha::BIS, 2, Alpha::R26).addReg(RA).addReg(RA);
184 /// LowerOperation - Provide custom lowering hooks for some operations.
186 SDOperand AlphaTargetLowering::LowerOperation(SDOperand Op, SelectionDAG &DAG) {
187 MachineFunction &MF = DAG.getMachineFunction();
188 switch (Op.getOpcode()) {
189 default: assert(0 && "Should not custom lower this!");
191 case ISD::SINT_TO_FP:
193 assert (Op.getOperand(0).getValueType() == MVT::i64
194 && "only quads can be loaded from");
198 std::vector<MVT::ValueType> RTs;
199 RTs.push_back(Op.getValueType());
200 std::vector<SDOperand> Ops;
201 Ops.push_back(Op.getOperand(0));
202 SRC = DAG.getNode(AlphaISD::ITOF, RTs, Ops);
204 int SSFI = MF.getFrameInfo()->CreateStackObject(8, 8);
205 SDOperand StackSlot = DAG.getFrameIndex(SSFI, getPointerTy());
206 SDOperand Store = DAG.getNode(ISD::STORE, MVT::Other,
207 DAG.getEntryNode(), Op.getOperand(0),
208 StackSlot, DAG.getSrcValue(NULL));
209 SRC = DAG.getLoad(Op.getValueType(), Store.getValue(0), StackSlot,
210 DAG.getSrcValue(NULL));
212 std::vector<MVT::ValueType> RTs;
213 RTs.push_back(Op.getValueType());
214 std::vector<SDOperand> Ops;
216 return DAG.getNode(AlphaISD::CVTQ, RTs, Ops);
224 /// AddLiveIn - This helper function adds the specified physical register to the
225 /// MachineFunction as a live in value. It also creates a corresponding virtual
227 static unsigned AddLiveIn(MachineFunction &MF, unsigned PReg,
228 TargetRegisterClass *RC) {
229 assert(RC->contains(PReg) && "Not the correct regclass!");
230 unsigned VReg = MF.getSSARegMap()->createVirtualRegister(RC);
231 MF.addLiveIn(PReg, VReg);
235 //http://www.cs.arizona.edu/computer.help/policy/DIGITAL_unix/AA-PY8AC-TET1_html/callCH3.html#BLOCK21
237 //For now, just use variable size stack frame format
239 //In a standard call, the first six items are passed in registers $16
240 //- $21 and/or registers $f16 - $f21. (See Section 4.1.2 for details
241 //of argument-to-register correspondence.) The remaining items are
242 //collected in a memory argument list that is a naturally aligned
243 //array of quadwords. In a standard call, this list, if present, must
244 //be passed at 0(SP).
245 //7 ... n 0(SP) ... (n-7)*8(SP)
253 std::vector<SDOperand>
254 AlphaTargetLowering::LowerArguments(Function &F, SelectionDAG &DAG)
256 std::vector<SDOperand> ArgValues;
258 MachineFunction &MF = DAG.getMachineFunction();
259 MachineFrameInfo*MFI = MF.getFrameInfo();
261 MachineBasicBlock& BB = MF.front();
263 unsigned args_int[] = {Alpha::R16, Alpha::R17, Alpha::R18,
264 Alpha::R19, Alpha::R20, Alpha::R21};
265 unsigned args_float[] = {Alpha::F16, Alpha::F17, Alpha::F18,
266 Alpha::F19, Alpha::F20, Alpha::F21};
269 GP = AddLiveIn(MF, Alpha::R29, getRegClassFor(MVT::i64));
270 RA = AddLiveIn(MF, Alpha::R26, getRegClassFor(MVT::i64));
272 for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; ++I)
277 MVT::ValueType VT = getValueType(I->getType());
280 std::cerr << "Unknown Type " << VT << "\n";
284 args_float[count] = AddLiveIn(MF,args_float[count], getRegClassFor(VT));
285 argt = DAG.getCopyFromReg(args_float[count], VT, DAG.getRoot());
292 args_int[count] = AddLiveIn(MF, args_int[count],
293 getRegClassFor(MVT::i64));
294 argt = DAG.getCopyFromReg(args_int[count], VT, DAG.getRoot());
296 argt = DAG.getNode(ISD::TRUNCATE, VT, argt);
299 DAG.setRoot(argt.getValue(1));
301 // Create the frame index object for this incoming parameter...
302 int FI = MFI->CreateFixedObject(8, 8 * (count - 6));
304 // Create the SelectionDAG nodes corresponding to a load
305 //from this parameter
306 SDOperand FIN = DAG.getFrameIndex(FI, MVT::i64);
307 argt = DAG.getLoad(getValueType(I->getType()),
308 DAG.getEntryNode(), FIN, DAG.getSrcValue(NULL));
311 ArgValues.push_back(argt);
314 // If the functions takes variable number of arguments, copy all regs to stack
316 VarArgsOffset = count * 8;
317 std::vector<SDOperand> LS;
318 for (int i = 0; i < 6; ++i) {
319 if (args_int[i] < 1024)
320 args_int[i] = AddLiveIn(MF,args_int[i], getRegClassFor(MVT::i64));
321 SDOperand argt = DAG.getCopyFromReg(args_int[i], MVT::i64, DAG.getRoot());
322 int FI = MFI->CreateFixedObject(8, -8 * (6 - i));
323 if (i == 0) VarArgsBase = FI;
324 SDOperand SDFI = DAG.getFrameIndex(FI, MVT::i64);
325 LS.push_back(DAG.getNode(ISD::STORE, MVT::Other, DAG.getRoot(), argt,
326 SDFI, DAG.getSrcValue(NULL)));
328 if (args_float[i] < 1024)
329 args_float[i] = AddLiveIn(MF,args_float[i], getRegClassFor(MVT::f64));
330 argt = DAG.getCopyFromReg(args_float[i], MVT::f64, DAG.getRoot());
331 FI = MFI->CreateFixedObject(8, - 8 * (12 - i));
332 SDFI = DAG.getFrameIndex(FI, MVT::i64);
333 LS.push_back(DAG.getNode(ISD::STORE, MVT::Other, DAG.getRoot(), argt,
334 SDFI, DAG.getSrcValue(NULL)));
337 //Set up a token factor with all the stack traffic
338 DAG.setRoot(DAG.getNode(ISD::TokenFactor, MVT::Other, LS));
341 // Finally, inform the code generator which regs we return values in.
342 switch (getValueType(F.getReturnType())) {
343 default: assert(0 && "Unknown type!");
344 case MVT::isVoid: break;
350 MF.addLiveOut(Alpha::R0);
354 MF.addLiveOut(Alpha::F0);
358 //return the arguments
362 std::pair<SDOperand, SDOperand>
363 AlphaTargetLowering::LowerCallTo(SDOperand Chain,
364 const Type *RetTy, bool isVarArg,
365 unsigned CallingConv, bool isTailCall,
366 SDOperand Callee, ArgListTy &Args,
370 NumBytes = (Args.size() - 6) * 8;
372 Chain = DAG.getNode(ISD::CALLSEQ_START, MVT::Other, Chain,
373 DAG.getConstant(NumBytes, getPointerTy()));
374 std::vector<SDOperand> args_to_use;
375 for (unsigned i = 0, e = Args.size(); i != e; ++i)
377 switch (getValueType(Args[i].second)) {
378 default: assert(0 && "Unexpected ValueType for argument!");
383 // Promote the integer to 64 bits. If the input type is signed use a
384 // sign extend, otherwise use a zero extend.
385 if (Args[i].second->isSigned())
386 Args[i].first = DAG.getNode(ISD::SIGN_EXTEND, MVT::i64, Args[i].first);
388 Args[i].first = DAG.getNode(ISD::ZERO_EXTEND, MVT::i64, Args[i].first);
395 args_to_use.push_back(Args[i].first);
398 std::vector<MVT::ValueType> RetVals;
399 MVT::ValueType RetTyVT = getValueType(RetTy);
400 if (RetTyVT != MVT::isVoid)
401 RetVals.push_back(RetTyVT);
402 RetVals.push_back(MVT::Other);
404 SDOperand TheCall = SDOperand(DAG.getCall(RetVals,
405 Chain, Callee, args_to_use), 0);
406 Chain = TheCall.getValue(RetTyVT != MVT::isVoid);
407 Chain = DAG.getNode(ISD::CALLSEQ_END, MVT::Other, Chain,
408 DAG.getConstant(NumBytes, getPointerTy()));
409 return std::make_pair(TheCall, Chain);
412 SDOperand AlphaTargetLowering::LowerVAStart(SDOperand Chain, SDOperand VAListP,
413 Value *VAListV, SelectionDAG &DAG) {
414 // vastart stores the address of the VarArgsBase and VarArgsOffset
415 SDOperand FR = DAG.getFrameIndex(VarArgsBase, MVT::i64);
416 SDOperand S1 = DAG.getNode(ISD::STORE, MVT::Other, Chain, FR, VAListP,
417 DAG.getSrcValue(VAListV));
418 SDOperand SA2 = DAG.getNode(ISD::ADD, MVT::i64, VAListP,
419 DAG.getConstant(8, MVT::i64));
420 return DAG.getNode(ISD::TRUNCSTORE, MVT::Other, S1,
421 DAG.getConstant(VarArgsOffset, MVT::i64), SA2,
422 DAG.getSrcValue(VAListV, 8), DAG.getValueType(MVT::i32));
425 std::pair<SDOperand,SDOperand> AlphaTargetLowering::
426 LowerVAArg(SDOperand Chain, SDOperand VAListP, Value *VAListV,
427 const Type *ArgTy, SelectionDAG &DAG) {
428 SDOperand Base = DAG.getLoad(MVT::i64, Chain, VAListP,
429 DAG.getSrcValue(VAListV));
430 SDOperand Tmp = DAG.getNode(ISD::ADD, MVT::i64, VAListP,
431 DAG.getConstant(8, MVT::i64));
432 SDOperand Offset = DAG.getExtLoad(ISD::SEXTLOAD, MVT::i64, Base.getValue(1),
433 Tmp, DAG.getSrcValue(VAListV, 8), MVT::i32);
434 SDOperand DataPtr = DAG.getNode(ISD::ADD, MVT::i64, Base, Offset);
435 if (ArgTy->isFloatingPoint())
437 //if fp && Offset < 6*8, then subtract 6*8 from DataPtr
438 SDOperand FPDataPtr = DAG.getNode(ISD::SUB, MVT::i64, DataPtr,
439 DAG.getConstant(8*6, MVT::i64));
440 SDOperand CC = DAG.getSetCC(ISD::SETLT, MVT::i64,
441 Offset, DAG.getConstant(8*6, MVT::i64));
442 DataPtr = DAG.getNode(ISD::SELECT, MVT::i64, CC, FPDataPtr, DataPtr);
446 if (ArgTy == Type::IntTy)
447 Result = DAG.getExtLoad(ISD::SEXTLOAD, MVT::i64, Offset.getValue(1),
448 DataPtr, DAG.getSrcValue(NULL), MVT::i32);
449 else if (ArgTy == Type::UIntTy)
450 Result = DAG.getExtLoad(ISD::ZEXTLOAD, MVT::i64, Offset.getValue(1),
451 DataPtr, DAG.getSrcValue(NULL), MVT::i32);
453 Result = DAG.getLoad(getValueType(ArgTy), Offset.getValue(1), DataPtr,
454 DAG.getSrcValue(NULL));
456 SDOperand NewOffset = DAG.getNode(ISD::ADD, MVT::i64, Offset,
457 DAG.getConstant(8, MVT::i64));
458 SDOperand Update = DAG.getNode(ISD::TRUNCSTORE, MVT::Other,
459 Result.getValue(1), NewOffset,
460 Tmp, DAG.getSrcValue(VAListV, 8),
461 DAG.getValueType(MVT::i32));
462 Result = DAG.getNode(ISD::TRUNCATE, getValueType(ArgTy), Result);
464 return std::make_pair(Result, Update);
468 SDOperand AlphaTargetLowering::
469 LowerVACopy(SDOperand Chain, SDOperand SrcP, Value *SrcV, SDOperand DestP,
470 Value *DestV, SelectionDAG &DAG) {
471 SDOperand Val = DAG.getLoad(getPointerTy(), Chain, SrcP,
472 DAG.getSrcValue(SrcV));
473 SDOperand Result = DAG.getNode(ISD::STORE, MVT::Other, Val.getValue(1),
474 Val, DestP, DAG.getSrcValue(DestV));
475 SDOperand NP = DAG.getNode(ISD::ADD, MVT::i64, SrcP,
476 DAG.getConstant(8, MVT::i64));
477 Val = DAG.getExtLoad(ISD::SEXTLOAD, MVT::i64, Result, NP,
478 DAG.getSrcValue(SrcV, 8), MVT::i32);
479 SDOperand NPD = DAG.getNode(ISD::ADD, MVT::i64, DestP,
480 DAG.getConstant(8, MVT::i64));
481 return DAG.getNode(ISD::TRUNCSTORE, MVT::Other, Val.getValue(1),
482 Val, NPD, DAG.getSrcValue(DestV, 8),
483 DAG.getValueType(MVT::i32));
488 //===--------------------------------------------------------------------===//
489 /// ISel - Alpha specific code to select Alpha machine instructions for
490 /// SelectionDAG operations.
491 //===--------------------------------------------------------------------===//
492 class AlphaISel : public SelectionDAGISel {
494 /// AlphaLowering - This object fully describes how to lower LLVM code to an
495 /// Alpha-specific SelectionDAG.
496 AlphaTargetLowering AlphaLowering;
498 SelectionDAG *ISelDAG; // Hack to support us having a dag->dag transform
499 // for sdiv and udiv until it is put into the future
502 /// ExprMap - As shared expressions are codegen'd, we keep track of which
503 /// vreg the value is produced in, so we only emit one copy of each compiled
505 static const unsigned notIn = (unsigned)(-1);
506 std::map<SDOperand, unsigned> ExprMap;
508 //CCInvMap sometimes (SetNE) we have the inverse CC code for free
509 std::map<SDOperand, unsigned> CCInvMap;
517 AlphaISel(TargetMachine &TM) : SelectionDAGISel(AlphaLowering),
521 /// InstructionSelectBasicBlock - This callback is invoked by
522 /// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
523 virtual void InstructionSelectBasicBlock(SelectionDAG &DAG) {
530 // Codegen the basic block.
532 max_depth = DAG.getRoot().getNodeDepth();
533 Select(DAG.getRoot());
538 std::cerr << "COUNT: "
539 << BB->getParent()->getFunction ()->getName() << " "
540 << BB->getNumber() << " "
543 << count_outs << "\n";
545 // Clear state used for selection.
550 virtual void EmitFunctionEntryCode(Function &Fn, MachineFunction &MF);
552 unsigned SelectExpr(SDOperand N);
553 void Select(SDOperand N);
555 void SelectAddr(SDOperand N, unsigned& Reg, long& offset);
556 void SelectBranchCC(SDOperand N);
557 void MoveFP2Int(unsigned src, unsigned dst, bool isDouble);
558 void MoveInt2FP(unsigned src, unsigned dst, bool isDouble);
559 //returns whether the sense of the comparison was inverted
560 bool SelectFPSetCC(SDOperand N, unsigned dst);
562 // dag -> dag expanders for integer divide by constant
563 SDOperand BuildSDIVSequence(SDOperand N);
564 SDOperand BuildUDIVSequence(SDOperand N);
569 void AlphaISel::EmitFunctionEntryCode(Function &Fn, MachineFunction &MF) {
570 // If this function has live-in values, emit the copies from pregs to vregs at
571 // the top of the function, before anything else.
572 MachineBasicBlock *BB = MF.begin();
573 if (MF.livein_begin() != MF.livein_end()) {
574 SSARegMap *RegMap = MF.getSSARegMap();
575 for (MachineFunction::livein_iterator LI = MF.livein_begin(),
576 E = MF.livein_end(); LI != E; ++LI) {
577 const TargetRegisterClass *RC = RegMap->getRegClass(LI->second);
578 if (RC == Alpha::GPRCRegisterClass) {
579 BuildMI(BB, Alpha::BIS, 2, LI->second).addReg(LI->first)
581 } else if (RC == Alpha::FPRCRegisterClass) {
582 BuildMI(BB, Alpha::CPYS, 2, LI->second).addReg(LI->first)
585 assert(0 && "Unknown regclass!");
591 static void getValueInfo(const Value* v, int& type, int& fun, int& offset)
593 fun = type = offset = 0;
596 } else if (const GlobalValue* GV = dyn_cast<GlobalValue>(v)) {
598 const Module* M = GV->getParent();
599 for(Module::const_global_iterator ii = M->global_begin(); &*ii != GV; ++ii)
601 } else if (const Argument* Arg = dyn_cast<Argument>(v)) {
603 const Function* F = Arg->getParent();
604 const Module* M = F->getParent();
605 for(Module::const_iterator ii = M->begin(); &*ii != F; ++ii)
607 for(Function::const_arg_iterator ii = F->arg_begin(); &*ii != Arg; ++ii)
609 } else if (const Instruction* I = dyn_cast<Instruction>(v)) {
610 assert(dyn_cast<PointerType>(I->getType()));
612 const BasicBlock* bb = I->getParent();
613 const Function* F = bb->getParent();
614 const Module* M = F->getParent();
615 for(Module::const_iterator ii = M->begin(); &*ii != F; ++ii)
617 for(Function::const_iterator ii = F->begin(); &*ii != bb; ++ii)
618 offset += ii->size();
619 for(BasicBlock::const_iterator ii = bb->begin(); &*ii != I; ++ii)
621 } else if (const Constant* C = dyn_cast<Constant>(v)) {
622 //Don't know how to look these up yet
625 assert(0 && "Error in value marking");
627 //type = 4: register spilling
628 //type = 5: global address loading or constant loading
637 //Factorize a number using the list of constants
638 static bool factorize(int v[], int res[], int size, uint64_t c)
641 while (c != 1 && cont)
644 for(int i = 0; i < size; ++i)
658 //Shamelessly adapted from PPC32
659 // Structure used to return the necessary information to codegen an SDIV as
662 int64_t m; // magic number
663 int64_t s; // shift amount
667 uint64_t m; // magic number
668 int64_t a; // add indicator
669 int64_t s; // shift amount
672 /// magic - calculate the magic numbers required to codegen an integer sdiv as
673 /// a sequence of multiply and shifts. Requires that the divisor not be 0, 1,
675 static struct ms magic(int64_t d) {
677 uint64_t ad, anc, delta, q1, r1, q2, r2, t;
678 const uint64_t two63 = 9223372036854775808ULL; // 2^63
682 t = two63 + ((uint64_t)d >> 63);
683 anc = t - 1 - t%ad; // absolute value of nc
684 p = 63; // initialize p
685 q1 = two63/anc; // initialize q1 = 2p/abs(nc)
686 r1 = two63 - q1*anc; // initialize r1 = rem(2p,abs(nc))
687 q2 = two63/ad; // initialize q2 = 2p/abs(d)
688 r2 = two63 - q2*ad; // initialize r2 = rem(2p,abs(d))
691 q1 = 2*q1; // update q1 = 2p/abs(nc)
692 r1 = 2*r1; // update r1 = rem(2p/abs(nc))
693 if (r1 >= anc) { // must be unsigned comparison
697 q2 = 2*q2; // update q2 = 2p/abs(d)
698 r2 = 2*r2; // update r2 = rem(2p/abs(d))
699 if (r2 >= ad) { // must be unsigned comparison
704 } while (q1 < delta || (q1 == delta && r1 == 0));
707 if (d < 0) mag.m = -mag.m; // resulting magic number
708 mag.s = p - 64; // resulting shift
712 /// magicu - calculate the magic numbers required to codegen an integer udiv as
713 /// a sequence of multiply, add and shifts. Requires that the divisor not be 0.
714 static struct mu magicu(uint64_t d)
717 uint64_t nc, delta, q1, r1, q2, r2;
719 magu.a = 0; // initialize "add" indicator
721 p = 63; // initialize p
722 q1 = 0x8000000000000000ull/nc; // initialize q1 = 2p/nc
723 r1 = 0x8000000000000000ull - q1*nc; // initialize r1 = rem(2p,nc)
724 q2 = 0x7FFFFFFFFFFFFFFFull/d; // initialize q2 = (2p-1)/d
725 r2 = 0x7FFFFFFFFFFFFFFFull - q2*d; // initialize r2 = rem((2p-1),d)
728 if (r1 >= nc - r1 ) {
729 q1 = 2*q1 + 1; // update q1
730 r1 = 2*r1 - nc; // update r1
733 q1 = 2*q1; // update q1
734 r1 = 2*r1; // update r1
736 if (r2 + 1 >= d - r2) {
737 if (q2 >= 0x7FFFFFFFFFFFFFFFull) magu.a = 1;
738 q2 = 2*q2 + 1; // update q2
739 r2 = 2*r2 + 1 - d; // update r2
742 if (q2 >= 0x8000000000000000ull) magu.a = 1;
743 q2 = 2*q2; // update q2
744 r2 = 2*r2 + 1; // update r2
747 } while (p < 64 && (q1 < delta || (q1 == delta && r1 == 0)));
748 magu.m = q2 + 1; // resulting magic number
749 magu.s = p - 64; // resulting shift
753 /// BuildSDIVSequence - Given an ISD::SDIV node expressing a divide by constant,
754 /// return a DAG expression to select that will generate the same value by
755 /// multiplying by a magic number. See:
756 /// <http://the.wall.riscom.net/books/proc/ppc/cwg/code2.html>
757 SDOperand AlphaISel::BuildSDIVSequence(SDOperand N) {
758 int64_t d = (int64_t)cast<ConstantSDNode>(N.getOperand(1))->getSignExtended();
759 ms magics = magic(d);
760 // Multiply the numerator (operand 0) by the magic value
761 SDOperand Q = ISelDAG->getNode(ISD::MULHS, MVT::i64, N.getOperand(0),
762 ISelDAG->getConstant(magics.m, MVT::i64));
763 // If d > 0 and m < 0, add the numerator
764 if (d > 0 && magics.m < 0)
765 Q = ISelDAG->getNode(ISD::ADD, MVT::i64, Q, N.getOperand(0));
766 // If d < 0 and m > 0, subtract the numerator.
767 if (d < 0 && magics.m > 0)
768 Q = ISelDAG->getNode(ISD::SUB, MVT::i64, Q, N.getOperand(0));
769 // Shift right algebraic if shift value is nonzero
771 Q = ISelDAG->getNode(ISD::SRA, MVT::i64, Q,
772 ISelDAG->getConstant(magics.s, MVT::i64));
773 // Extract the sign bit and add it to the quotient
775 ISelDAG->getNode(ISD::SRL, MVT::i64, Q, ISelDAG->getConstant(63, MVT::i64));
776 return ISelDAG->getNode(ISD::ADD, MVT::i64, Q, T);
779 /// BuildUDIVSequence - Given an ISD::UDIV node expressing a divide by constant,
780 /// return a DAG expression to select that will generate the same value by
781 /// multiplying by a magic number. See:
782 /// <http://the.wall.riscom.net/books/proc/ppc/cwg/code2.html>
783 SDOperand AlphaISel::BuildUDIVSequence(SDOperand N) {
785 (unsigned)cast<ConstantSDNode>(N.getOperand(1))->getSignExtended();
786 mu magics = magicu(d);
787 // Multiply the numerator (operand 0) by the magic value
788 SDOperand Q = ISelDAG->getNode(ISD::MULHU, MVT::i64, N.getOperand(0),
789 ISelDAG->getConstant(magics.m, MVT::i64));
791 Q = ISelDAG->getNode(ISD::SRL, MVT::i64, Q,
792 ISelDAG->getConstant(magics.s, MVT::i64));
794 SDOperand NPQ = ISelDAG->getNode(ISD::SUB, MVT::i64, N.getOperand(0), Q);
795 NPQ = ISelDAG->getNode(ISD::SRL, MVT::i64, NPQ,
796 ISelDAG->getConstant(1, MVT::i64));
797 NPQ = ISelDAG->getNode(ISD::ADD, MVT::i64, NPQ, Q);
798 Q = ISelDAG->getNode(ISD::SRL, MVT::i64, NPQ,
799 ISelDAG->getConstant(magics.s-1, MVT::i64));
805 /// ExactLog2 - This function solves for (Val == 1 << (N-1)) and returns N. It
806 /// returns zero when the input is not exactly a power of two.
807 static unsigned ExactLog2(uint64_t Val) {
808 if (Val == 0 || (Val & (Val-1))) return 0;
818 //These describe LDAx
819 static const int IMM_LOW = -32768;
820 static const int IMM_HIGH = 32767;
821 static const int IMM_MULT = 65536;
823 static long getUpper16(long l)
825 long y = l / IMM_MULT;
826 if (l % IMM_MULT > IMM_HIGH)
831 static long getLower16(long l)
833 long h = getUpper16(l);
834 return l - h * IMM_MULT;
837 static unsigned GetRelVersion(unsigned opcode)
840 default: assert(0 && "unknown load or store"); return 0;
841 case Alpha::LDQ: return Alpha::LDQr;
842 case Alpha::LDS: return Alpha::LDSr;
843 case Alpha::LDT: return Alpha::LDTr;
844 case Alpha::LDL: return Alpha::LDLr;
845 case Alpha::LDBU: return Alpha::LDBUr;
846 case Alpha::LDWU: return Alpha::LDWUr;
847 case Alpha::STB: return Alpha::STBr;
848 case Alpha::STW: return Alpha::STWr;
849 case Alpha::STL: return Alpha::STLr;
850 case Alpha::STQ: return Alpha::STQr;
851 case Alpha::STS: return Alpha::STSr;
852 case Alpha::STT: return Alpha::STTr;
857 void AlphaISel::MoveFP2Int(unsigned src, unsigned dst, bool isDouble)
860 if (EnableAlphaFTOI) {
861 Opc = isDouble ? Alpha::FTOIT : Alpha::FTOIS;
862 BuildMI(BB, Opc, 1, dst).addReg(src);
865 // Spill the integer to memory and reload it from there.
866 unsigned Size = MVT::getSizeInBits(MVT::f64)/8;
867 MachineFunction *F = BB->getParent();
868 int FrameIdx = F->getFrameInfo()->CreateStackObject(Size, 8);
870 if (EnableAlphaLSMark)
871 BuildMI(BB, Alpha::MEMLABEL, 4).addImm(4).addImm(0).addImm(0)
873 Opc = isDouble ? Alpha::STT : Alpha::STS;
874 BuildMI(BB, Opc, 3).addReg(src).addFrameIndex(FrameIdx).addReg(Alpha::F31);
876 if (EnableAlphaLSMark)
877 BuildMI(BB, Alpha::MEMLABEL, 4).addImm(4).addImm(0).addImm(0)
879 Opc = isDouble ? Alpha::LDQ : Alpha::LDL;
880 BuildMI(BB, Alpha::LDQ, 2, dst).addFrameIndex(FrameIdx).addReg(Alpha::F31);
884 void AlphaISel::MoveInt2FP(unsigned src, unsigned dst, bool isDouble)
887 if (EnableAlphaFTOI) {
888 Opc = isDouble?Alpha::ITOFT:Alpha::ITOFS;
889 BuildMI(BB, Opc, 1, dst).addReg(src);
892 // Spill the integer to memory and reload it from there.
893 unsigned Size = MVT::getSizeInBits(MVT::f64)/8;
894 MachineFunction *F = BB->getParent();
895 int FrameIdx = F->getFrameInfo()->CreateStackObject(Size, 8);
897 if (EnableAlphaLSMark)
898 BuildMI(BB, Alpha::MEMLABEL, 4).addImm(4).addImm(0).addImm(0)
900 Opc = isDouble ? Alpha::STQ : Alpha::STL;
901 BuildMI(BB, Opc, 3).addReg(src).addFrameIndex(FrameIdx).addReg(Alpha::F31);
903 if (EnableAlphaLSMark)
904 BuildMI(BB, Alpha::MEMLABEL, 4).addImm(4).addImm(0).addImm(0)
906 Opc = isDouble ? Alpha::LDT : Alpha::LDS;
907 BuildMI(BB, Opc, 2, dst).addFrameIndex(FrameIdx).addReg(Alpha::F31);
911 bool AlphaISel::SelectFPSetCC(SDOperand N, unsigned dst)
913 SDNode *Node = N.Val;
914 unsigned Opc, Tmp1, Tmp2, Tmp3;
915 SetCCSDNode *SetCC = dyn_cast<SetCCSDNode>(Node);
920 switch (SetCC->getCondition()) {
921 default: Node->dump(); assert(0 && "Unknown FP comparison!");
922 case ISD::SETEQ: Opc = Alpha::CMPTEQ; break;
923 case ISD::SETLT: Opc = Alpha::CMPTLT; break;
924 case ISD::SETLE: Opc = Alpha::CMPTLE; break;
925 case ISD::SETGT: Opc = Alpha::CMPTLT; rev = true; break;
926 case ISD::SETGE: Opc = Alpha::CMPTLE; rev = true; break;
927 case ISD::SETNE: Opc = Alpha::CMPTEQ; inv = true; break;
930 ConstantFPSDNode *CN;
931 if ((CN = dyn_cast<ConstantFPSDNode>(SetCC->getOperand(0)))
932 && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0)))
935 Tmp1 = SelectExpr(N.getOperand(0));
937 if ((CN = dyn_cast<ConstantFPSDNode>(SetCC->getOperand(1)))
938 && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0)))
941 Tmp2 = SelectExpr(N.getOperand(1));
943 //Can only compare doubles, and dag won't promote for me
944 if (SetCC->getOperand(0).getValueType() == MVT::f32)
946 //assert(0 && "Setcc On float?\n");
947 std::cerr << "Setcc on float!\n";
948 Tmp3 = MakeReg(MVT::f64);
949 BuildMI(BB, Alpha::CVTST, 1, Tmp3).addReg(Tmp1);
952 if (SetCC->getOperand(1).getValueType() == MVT::f32)
954 //assert (0 && "Setcc On float?\n");
955 std::cerr << "Setcc on float!\n";
956 Tmp3 = MakeReg(MVT::f64);
957 BuildMI(BB, Alpha::CVTST, 1, Tmp3).addReg(Tmp2);
961 if (rev) std::swap(Tmp1, Tmp2);
963 BuildMI(BB, Opc, 2, dst).addReg(Tmp1).addReg(Tmp2);
967 //Check to see if the load is a constant offset from a base register
968 void AlphaISel::SelectAddr(SDOperand N, unsigned& Reg, long& offset)
970 unsigned opcode = N.getOpcode();
971 if (opcode == ISD::ADD && N.getOperand(1).getOpcode() == ISD::Constant &&
972 cast<ConstantSDNode>(N.getOperand(1))->getValue() <= 32767)
974 Reg = SelectExpr(N.getOperand(0));
975 offset = cast<ConstantSDNode>(N.getOperand(1))->getValue();
983 void AlphaISel::SelectBranchCC(SDOperand N)
985 assert(N.getOpcode() == ISD::BRCOND && "Not a BranchCC???");
986 MachineBasicBlock *Dest =
987 cast<BasicBlockSDNode>(N.getOperand(2))->getBasicBlock();
988 unsigned Opc = Alpha::WTF;
990 Select(N.getOperand(0)); //chain
991 SDOperand CC = N.getOperand(1);
993 if (CC.getOpcode() == ISD::SETCC)
995 SetCCSDNode* SetCC = dyn_cast<SetCCSDNode>(CC.Val);
996 if (MVT::isInteger(SetCC->getOperand(0).getValueType())) {
997 //Dropping the CC is only useful if we are comparing to 0
998 bool RightZero = SetCC->getOperand(1).getOpcode() == ISD::Constant &&
999 cast<ConstantSDNode>(SetCC->getOperand(1))->getValue() == 0;
1003 ISD::CondCode cCode= SetCC->getCondition();
1005 if(cCode == ISD::SETNE)
1010 default: CC.Val->dump(); assert(0 && "Unknown integer comparison!");
1011 case ISD::SETEQ: Opc = Alpha::BEQ; break;
1012 case ISD::SETLT: Opc = Alpha::BLT; break;
1013 case ISD::SETLE: Opc = Alpha::BLE; break;
1014 case ISD::SETGT: Opc = Alpha::BGT; break;
1015 case ISD::SETGE: Opc = Alpha::BGE; break;
1016 case ISD::SETULT: assert(0 && "x (unsigned) < 0 is never true"); break;
1017 case ISD::SETUGT: Opc = Alpha::BNE; break;
1018 //Technically you could have this CC
1019 case ISD::SETULE: Opc = Alpha::BEQ; break;
1020 case ISD::SETUGE: assert(0 && "x (unsgined >= 0 is always true"); break;
1021 case ISD::SETNE: Opc = Alpha::BNE; break;
1023 unsigned Tmp1 = SelectExpr(SetCC->getOperand(0)); //Cond
1024 BuildMI(BB, Opc, 2).addReg(Tmp1).addMBB(Dest);
1027 unsigned Tmp1 = SelectExpr(CC);
1029 BuildMI(BB, Alpha::BEQ, 2).addReg(CCInvMap[CC]).addMBB(Dest);
1031 BuildMI(BB, Alpha::BNE, 2).addReg(Tmp1).addMBB(Dest);
1035 //Any comparison between 2 values should be codegened as an folded
1036 //branch, as moving CC to the integer register is very expensive
1037 //for a cmp b: c = a - b;
1042 bool invTest = false;
1045 ConstantFPSDNode *CN;
1046 if ((CN = dyn_cast<ConstantFPSDNode>(SetCC->getOperand(1)))
1047 && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0)))
1048 Tmp3 = SelectExpr(SetCC->getOperand(0));
1049 else if ((CN = dyn_cast<ConstantFPSDNode>(SetCC->getOperand(0)))
1050 && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0)))
1052 Tmp3 = SelectExpr(SetCC->getOperand(1));
1057 unsigned Tmp1 = SelectExpr(SetCC->getOperand(0));
1058 unsigned Tmp2 = SelectExpr(SetCC->getOperand(1));
1059 bool isD = SetCC->getOperand(0).getValueType() == MVT::f64;
1060 Tmp3 = MakeReg(isD ? MVT::f64 : MVT::f32);
1061 BuildMI(BB, isD ? Alpha::SUBT : Alpha::SUBS, 2, Tmp3)
1062 .addReg(Tmp1).addReg(Tmp2);
1065 switch (SetCC->getCondition()) {
1066 default: CC.Val->dump(); assert(0 && "Unknown FP comparison!");
1067 case ISD::SETEQ: Opc = invTest ? Alpha::FBNE : Alpha::FBEQ; break;
1068 case ISD::SETLT: Opc = invTest ? Alpha::FBGT : Alpha::FBLT; break;
1069 case ISD::SETLE: Opc = invTest ? Alpha::FBGE : Alpha::FBLE; break;
1070 case ISD::SETGT: Opc = invTest ? Alpha::FBLT : Alpha::FBGT; break;
1071 case ISD::SETGE: Opc = invTest ? Alpha::FBLE : Alpha::FBGE; break;
1072 case ISD::SETNE: Opc = invTest ? Alpha::FBEQ : Alpha::FBNE; break;
1074 BuildMI(BB, Opc, 2).addReg(Tmp3).addMBB(Dest);
1077 abort(); //Should never be reached
1079 //Giveup and do the stupid thing
1080 unsigned Tmp1 = SelectExpr(CC);
1081 BuildMI(BB, Alpha::BNE, 2).addReg(Tmp1).addMBB(Dest);
1084 abort(); //Should never be reached
1087 unsigned AlphaISel::SelectExpr(SDOperand N) {
1089 unsigned Tmp1, Tmp2 = 0, Tmp3;
1091 unsigned opcode = N.getOpcode();
1093 SDNode *Node = N.Val;
1094 MVT::ValueType DestType = N.getValueType();
1095 bool isFP = DestType == MVT::f64 || DestType == MVT::f32;
1097 unsigned &Reg = ExprMap[N];
1098 if (Reg) return Reg;
1100 if (N.getOpcode() != ISD::CALL && N.getOpcode() != ISD::TAILCALL)
1101 Reg = Result = (N.getValueType() != MVT::Other) ?
1102 MakeReg(N.getValueType()) : notIn;
1104 // If this is a call instruction, make sure to prepare ALL of the result
1105 // values as well as the chain.
1106 if (Node->getNumValues() == 1)
1107 Reg = Result = notIn; // Void call, just a chain.
1109 Result = MakeReg(Node->getValueType(0));
1110 ExprMap[N.getValue(0)] = Result;
1111 for (unsigned i = 1, e = N.Val->getNumValues()-1; i != e; ++i)
1112 ExprMap[N.getValue(i)] = MakeReg(Node->getValueType(i));
1113 ExprMap[SDOperand(Node, Node->getNumValues()-1)] = notIn;
1120 assert(0 && "Node not handled!\n");
1125 Opc = opcode == ISD::CTPOP ? Alpha::CTPOP :
1126 (opcode == ISD::CTTZ ? Alpha::CTTZ : Alpha::CTLZ);
1127 Tmp1 = SelectExpr(N.getOperand(0));
1128 BuildMI(BB, Opc, 1, Result).addReg(Alpha::R31).addReg(Tmp1);
1132 Tmp1 = SelectExpr(N.getOperand(0));
1133 Tmp2 = SelectExpr(N.getOperand(1));
1134 BuildMI(BB, Alpha::UMULH, 2, Result).addReg(Tmp1).addReg(Tmp2);
1138 //MULHU - Ra<63>*Rb - Rb<63>*Ra
1139 Tmp1 = SelectExpr(N.getOperand(0));
1140 Tmp2 = SelectExpr(N.getOperand(1));
1141 Tmp3 = MakeReg(MVT::i64);
1142 BuildMI(BB, Alpha::UMULH, 2, Tmp3).addReg(Tmp1).addReg(Tmp2);
1143 unsigned V1 = MakeReg(MVT::i64);
1144 unsigned V2 = MakeReg(MVT::i64);
1145 BuildMI(BB, Alpha::CMOVGE, 3, V1).addReg(Tmp2).addReg(Alpha::R31)
1147 BuildMI(BB, Alpha::CMOVGE, 3, V2).addReg(Tmp1).addReg(Alpha::R31)
1149 unsigned IRes = MakeReg(MVT::i64);
1150 BuildMI(BB, Alpha::SUBQ, 2, IRes).addReg(Tmp3).addReg(V1);
1151 BuildMI(BB, Alpha::SUBQ, 2, Result).addReg(IRes).addReg(V2);
1155 BuildMI(BB, Alpha::IDEF, 0, Result);
1159 case ISD::DYNAMIC_STACKALLOC:
1160 // Generate both result values.
1161 if (Result != notIn)
1162 ExprMap[N.getValue(1)] = notIn; // Generate the token
1164 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
1166 // FIXME: We are currently ignoring the requested alignment for handling
1167 // greater than the stack alignment. This will need to be revisited at some
1168 // point. Align = N.getOperand(2);
1170 if (!isa<ConstantSDNode>(N.getOperand(2)) ||
1171 cast<ConstantSDNode>(N.getOperand(2))->getValue() != 0) {
1172 std::cerr << "Cannot allocate stack object with greater alignment than"
1173 << " the stack alignment yet!";
1177 Select(N.getOperand(0));
1178 if (ConstantSDNode* CN = dyn_cast<ConstantSDNode>(N.getOperand(1)))
1180 if (CN->getValue() < 32000)
1182 BuildMI(BB, Alpha::LDA, 2, Alpha::R30)
1183 .addImm(-CN->getValue()).addReg(Alpha::R30);
1185 Tmp1 = SelectExpr(N.getOperand(1));
1186 // Subtract size from stack pointer, thereby allocating some space.
1187 BuildMI(BB, Alpha::SUBQ, 2, Alpha::R30).addReg(Alpha::R30).addReg(Tmp1);
1190 Tmp1 = SelectExpr(N.getOperand(1));
1191 // Subtract size from stack pointer, thereby allocating some space.
1192 BuildMI(BB, Alpha::SUBQ, 2, Alpha::R30).addReg(Alpha::R30).addReg(Tmp1);
1195 // Put a pointer to the space into the result register, by copying the stack
1197 BuildMI(BB, Alpha::BIS, 2, Result).addReg(Alpha::R30).addReg(Alpha::R30);
1200 case ISD::ConstantPool:
1201 Tmp1 = cast<ConstantPoolSDNode>(N)->getIndex();
1202 AlphaLowering.restoreGP(BB);
1203 Tmp2 = MakeReg(MVT::i64);
1204 BuildMI(BB, Alpha::LDAHr, 2, Tmp2).addConstantPoolIndex(Tmp1)
1205 .addReg(Alpha::R29);
1206 BuildMI(BB, Alpha::LDAr, 2, Result).addConstantPoolIndex(Tmp1)
1210 case ISD::FrameIndex:
1211 BuildMI(BB, Alpha::LDA, 2, Result)
1212 .addFrameIndex(cast<FrameIndexSDNode>(N)->getIndex())
1213 .addReg(Alpha::F31);
1221 // Make sure we generate both values.
1222 if (Result != notIn)
1223 ExprMap[N.getValue(1)] = notIn; // Generate the token
1225 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
1227 SDOperand Chain = N.getOperand(0);
1228 SDOperand Address = N.getOperand(1);
1233 if (opcode == ISD::LOAD)
1234 switch (Node->getValueType(0)) {
1235 default: Node->dump(); assert(0 && "Bad load!");
1236 case MVT::i64: Opc = Alpha::LDQ; break;
1237 case MVT::f64: Opc = Alpha::LDT; break;
1238 case MVT::f32: Opc = Alpha::LDS; break;
1241 switch (cast<VTSDNode>(Node->getOperand(3))->getVT()) {
1242 default: Node->dump(); assert(0 && "Bad sign extend!");
1243 case MVT::i32: Opc = Alpha::LDL;
1244 assert(opcode != ISD::ZEXTLOAD && "Not sext"); break;
1245 case MVT::i16: Opc = Alpha::LDWU;
1246 assert(opcode != ISD::SEXTLOAD && "Not zext"); break;
1247 case MVT::i1: //FIXME: Treat i1 as i8 since there are problems otherwise
1248 case MVT::i8: Opc = Alpha::LDBU;
1249 assert(opcode != ISD::SEXTLOAD && "Not zext"); break;
1253 if (EnableAlphaLSMark)
1254 getValueInfo(dyn_cast<SrcValueSDNode>(N.getOperand(2))->getValue(),
1257 GlobalAddressSDNode *GASD = dyn_cast<GlobalAddressSDNode>(Address);
1258 if (GASD && !GASD->getGlobal()->isExternal()) {
1259 Tmp1 = MakeReg(MVT::i64);
1260 AlphaLowering.restoreGP(BB);
1261 BuildMI(BB, Alpha::LDAHr, 2, Tmp1)
1262 .addGlobalAddress(GASD->getGlobal()).addReg(Alpha::R29);
1263 if (EnableAlphaLSMark)
1264 BuildMI(BB, Alpha::MEMLABEL, 4).addImm(i).addImm(j).addImm(k)
1266 BuildMI(BB, GetRelVersion(Opc), 2, Result)
1267 .addGlobalAddress(GASD->getGlobal()).addReg(Tmp1);
1268 } else if (ConstantPoolSDNode *CP =
1269 dyn_cast<ConstantPoolSDNode>(Address)) {
1270 AlphaLowering.restoreGP(BB);
1272 Tmp1 = MakeReg(MVT::i64);
1273 BuildMI(BB, Alpha::LDAHr, 2, Tmp1).addConstantPoolIndex(CP->getIndex())
1274 .addReg(Alpha::R29);
1275 if (EnableAlphaLSMark)
1276 BuildMI(BB, Alpha::MEMLABEL, 4).addImm(i).addImm(j).addImm(k)
1278 BuildMI(BB, GetRelVersion(Opc), 2, Result)
1279 .addConstantPoolIndex(CP->getIndex()).addReg(Tmp1);
1280 } else if(Address.getOpcode() == ISD::FrameIndex) {
1281 if (EnableAlphaLSMark)
1282 BuildMI(BB, Alpha::MEMLABEL, 4).addImm(i).addImm(j).addImm(k)
1284 BuildMI(BB, Opc, 2, Result)
1285 .addFrameIndex(cast<FrameIndexSDNode>(Address)->getIndex())
1286 .addReg(Alpha::F31);
1289 SelectAddr(Address, Tmp1, offset);
1290 if (EnableAlphaLSMark)
1291 BuildMI(BB, Alpha::MEMLABEL, 4).addImm(i).addImm(j).addImm(k)
1293 BuildMI(BB, Opc, 2, Result).addImm(offset).addReg(Tmp1);
1298 case ISD::GlobalAddress:
1299 AlphaLowering.restoreGP(BB);
1302 Reg = Result = MakeReg(MVT::i64);
1304 if (EnableAlphaLSMark)
1305 BuildMI(BB, Alpha::MEMLABEL, 4).addImm(5).addImm(0).addImm(0)
1308 BuildMI(BB, Alpha::LDQl, 2, Result)
1309 .addGlobalAddress(cast<GlobalAddressSDNode>(N)->getGlobal())
1310 .addReg(Alpha::R29);
1313 case ISD::ExternalSymbol:
1314 AlphaLowering.restoreGP(BB);
1317 Reg = Result = MakeReg(MVT::i64);
1319 if (EnableAlphaLSMark)
1320 BuildMI(BB, Alpha::MEMLABEL, 4).addImm(5).addImm(0).addImm(0)
1323 BuildMI(BB, Alpha::LDQl, 2, Result)
1324 .addExternalSymbol(cast<ExternalSymbolSDNode>(N)->getSymbol())
1325 .addReg(Alpha::R29);
1331 Select(N.getOperand(0));
1333 // The chain for this call is now lowered.
1334 ExprMap[N.getValue(Node->getNumValues()-1)] = notIn;
1336 //grab the arguments
1337 std::vector<unsigned> argvregs;
1338 //assert(Node->getNumOperands() < 8 && "Only 6 args supported");
1339 for(int i = 2, e = Node->getNumOperands(); i < e; ++i)
1340 argvregs.push_back(SelectExpr(N.getOperand(i)));
1343 for(int i = 0, e = std::min(6, (int)argvregs.size()); i < e; ++i)
1345 unsigned args_int[] = {Alpha::R16, Alpha::R17, Alpha::R18,
1346 Alpha::R19, Alpha::R20, Alpha::R21};
1347 unsigned args_float[] = {Alpha::F16, Alpha::F17, Alpha::F18,
1348 Alpha::F19, Alpha::F20, Alpha::F21};
1349 switch(N.getOperand(i+2).getValueType()) {
1352 N.getOperand(i).Val->dump();
1353 std::cerr << "Type for " << i << " is: " <<
1354 N.getOperand(i+2).getValueType() << "\n";
1355 assert(0 && "Unknown value type for call");
1361 BuildMI(BB, Alpha::BIS, 2, args_int[i]).addReg(argvregs[i])
1362 .addReg(argvregs[i]);
1366 BuildMI(BB, Alpha::CPYS, 2, args_float[i]).addReg(argvregs[i])
1367 .addReg(argvregs[i]);
1372 for (int i = 6, e = argvregs.size(); i < e; ++i)
1374 switch(N.getOperand(i+2).getValueType()) {
1377 N.getOperand(i).Val->dump();
1378 std::cerr << "Type for " << i << " is: " <<
1379 N.getOperand(i+2).getValueType() << "\n";
1380 assert(0 && "Unknown value type for call");
1386 BuildMI(BB, Alpha::STQ, 3).addReg(argvregs[i]).addImm((i - 6) * 8)
1387 .addReg(Alpha::R30);
1390 BuildMI(BB, Alpha::STS, 3).addReg(argvregs[i]).addImm((i - 6) * 8)
1391 .addReg(Alpha::R30);
1394 BuildMI(BB, Alpha::STT, 3).addReg(argvregs[i]).addImm((i - 6) * 8)
1395 .addReg(Alpha::R30);
1399 //build the right kind of call
1400 GlobalAddressSDNode *GASD = dyn_cast<GlobalAddressSDNode>(N.getOperand(1));
1401 if (GASD && !GASD->getGlobal()->isExternal()) {
1402 //use PC relative branch call
1403 AlphaLowering.restoreGP(BB);
1404 BuildMI(BB, Alpha::BSR, 1, Alpha::R26)
1405 .addGlobalAddress(GASD->getGlobal(),true);
1407 //no need to restore GP as we are doing an indirect call
1408 Tmp1 = SelectExpr(N.getOperand(1));
1409 BuildMI(BB, Alpha::BIS, 2, Alpha::R27).addReg(Tmp1).addReg(Tmp1);
1410 BuildMI(BB, Alpha::JSR, 2, Alpha::R26).addReg(Alpha::R27).addImm(0);
1413 //push the result into a virtual register
1415 switch (Node->getValueType(0)) {
1416 default: Node->dump(); assert(0 && "Unknown value type for call result!");
1417 case MVT::Other: return notIn;
1423 BuildMI(BB, Alpha::BIS, 2, Result).addReg(Alpha::R0).addReg(Alpha::R0);
1427 BuildMI(BB, Alpha::CPYS, 2, Result).addReg(Alpha::F0).addReg(Alpha::F0);
1430 return Result+N.ResNo;
1433 case ISD::SIGN_EXTEND_INREG:
1435 //do SDIV opt for all levels of ints if not dividing by a constant
1436 if (EnableAlphaIDIV && N.getOperand(0).getOpcode() == ISD::SDIV
1437 && N.getOperand(0).getOperand(1).getOpcode() != ISD::Constant)
1439 unsigned Tmp4 = MakeReg(MVT::f64);
1440 unsigned Tmp5 = MakeReg(MVT::f64);
1441 unsigned Tmp6 = MakeReg(MVT::f64);
1442 unsigned Tmp7 = MakeReg(MVT::f64);
1443 unsigned Tmp8 = MakeReg(MVT::f64);
1444 unsigned Tmp9 = MakeReg(MVT::f64);
1446 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
1447 Tmp2 = SelectExpr(N.getOperand(0).getOperand(1));
1448 MoveInt2FP(Tmp1, Tmp4, true);
1449 MoveInt2FP(Tmp2, Tmp5, true);
1450 BuildMI(BB, Alpha::CVTQT, 1, Tmp6).addReg(Tmp4);
1451 BuildMI(BB, Alpha::CVTQT, 1, Tmp7).addReg(Tmp5);
1452 BuildMI(BB, Alpha::DIVT, 2, Tmp8).addReg(Tmp6).addReg(Tmp7);
1453 BuildMI(BB, Alpha::CVTTQ, 1, Tmp9).addReg(Tmp8);
1454 MoveFP2Int(Tmp9, Result, true);
1458 //Alpha has instructions for a bunch of signed 32 bit stuff
1459 if(cast<VTSDNode>(Node->getOperand(1))->getVT() == MVT::i32) {
1460 switch (N.getOperand(0).getOpcode()) {
1465 bool isAdd = N.getOperand(0).getOpcode() == ISD::ADD;
1466 bool isMul = N.getOperand(0).getOpcode() == ISD::MUL;
1467 //FIXME: first check for Scaled Adds and Subs!
1468 ConstantSDNode* CSD = NULL;
1469 if(!isMul && N.getOperand(0).getOperand(0).getOpcode() == ISD::SHL &&
1470 (CSD = dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(0).getOperand(1))) &&
1471 (CSD->getValue() == 2 || CSD->getValue() == 3))
1473 bool use4 = CSD->getValue() == 2;
1474 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0).getOperand(0));
1475 Tmp2 = SelectExpr(N.getOperand(0).getOperand(1));
1476 BuildMI(BB, isAdd?(use4?Alpha::S4ADDL:Alpha::S8ADDL):(use4?Alpha::S4SUBL:Alpha::S8SUBL),
1477 2,Result).addReg(Tmp1).addReg(Tmp2);
1479 else if(isAdd && N.getOperand(0).getOperand(1).getOpcode() == ISD::SHL &&
1480 (CSD = dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1).getOperand(1))) &&
1481 (CSD->getValue() == 2 || CSD->getValue() == 3))
1483 bool use4 = CSD->getValue() == 2;
1484 Tmp1 = SelectExpr(N.getOperand(0).getOperand(1).getOperand(0));
1485 Tmp2 = SelectExpr(N.getOperand(0).getOperand(0));
1486 BuildMI(BB, use4?Alpha::S4ADDL:Alpha::S8ADDL, 2,Result).addReg(Tmp1).addReg(Tmp2);
1488 else if(N.getOperand(0).getOperand(1).getOpcode() == ISD::Constant &&
1489 cast<ConstantSDNode>(N.getOperand(0).getOperand(1))->getValue() <= 255)
1490 { //Normal imm add/sub
1491 Opc = isAdd ? Alpha::ADDLi : (isMul ? Alpha::MULLi : Alpha::SUBLi);
1492 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
1493 Tmp2 = cast<ConstantSDNode>(N.getOperand(0).getOperand(1))->getValue();
1494 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(Tmp2);
1496 else if(N.getOperand(0).getOperand(1).getOpcode() == ISD::Constant &&
1498 (CSD = dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) &&
1499 (((int64_t)(CSD->getValue() << 32) >> 32) >= -255) &&
1500 (((int64_t)(CSD->getValue() << 32) >> 32) <= 0))
1501 { //handle canonicalization
1502 Opc = isAdd ? Alpha::SUBLi : Alpha::ADDLi;
1503 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
1504 int64_t t = cast<ConstantSDNode>(N.getOperand(0).getOperand(1))->getValue();
1505 t = 0 - ((t << 32) >> 32);
1506 assert(t >= 0 && t <= 255);
1507 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(t);
1511 Opc = isAdd ? Alpha::ADDL : (isMul ? Alpha::MULL : Alpha::SUBL);
1512 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
1513 Tmp2 = SelectExpr(N.getOperand(0).getOperand(1));
1514 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
1518 default: break; //Fall Though;
1520 } //Every thing else fall though too, including unhandled opcodes above
1521 Tmp1 = SelectExpr(N.getOperand(0));
1522 //std::cerr << "SrcT: " << MVN->getExtraValueType() << "\n";
1523 switch(cast<VTSDNode>(Node->getOperand(1))->getVT()) {
1526 assert(0 && "Sign Extend InReg not there yet");
1530 BuildMI(BB, Alpha::ADDLi, 2, Result).addReg(Tmp1).addImm(0);
1534 BuildMI(BB, Alpha::SEXTW, 1, Result).addReg(Alpha::R31).addReg(Tmp1);
1537 BuildMI(BB, Alpha::SEXTB, 1, Result).addReg(Alpha::R31).addReg(Tmp1);
1540 Tmp2 = MakeReg(MVT::i64);
1541 BuildMI(BB, Alpha::ANDi, 2, Tmp2).addReg(Tmp1).addImm(1);
1542 BuildMI(BB, Alpha::SUBQ, 2, Result).addReg(Alpha::R31).addReg(Tmp2);
1550 if (SetCCSDNode *SetCC = dyn_cast<SetCCSDNode>(Node)) {
1551 if (MVT::isInteger(SetCC->getOperand(0).getValueType())) {
1552 bool isConst = false;
1555 //Tmp1 = SelectExpr(N.getOperand(0));
1556 if(N.getOperand(1).getOpcode() == ISD::Constant &&
1557 cast<ConstantSDNode>(N.getOperand(1))->getValue() <= 255)
1560 switch (SetCC->getCondition()) {
1561 default: Node->dump(); assert(0 && "Unknown integer comparison!");
1563 Opc = isConst ? Alpha::CMPEQi : Alpha::CMPEQ; dir=1; break;
1565 Opc = isConst ? Alpha::CMPLTi : Alpha::CMPLT; dir = 1; break;
1567 Opc = isConst ? Alpha::CMPLEi : Alpha::CMPLE; dir = 1; break;
1568 case ISD::SETGT: Opc = Alpha::CMPLT; dir = 2; break;
1569 case ISD::SETGE: Opc = Alpha::CMPLE; dir = 2; break;
1571 Opc = isConst ? Alpha::CMPULTi : Alpha::CMPULT; dir = 1; break;
1572 case ISD::SETUGT: Opc = Alpha::CMPULT; dir = 2; break;
1574 Opc = isConst ? Alpha::CMPULEi : Alpha::CMPULE; dir = 1; break;
1575 case ISD::SETUGE: Opc = Alpha::CMPULE; dir = 2; break;
1576 case ISD::SETNE: {//Handle this one special
1577 //std::cerr << "Alpha does not have a setne.\n";
1579 Tmp1 = SelectExpr(N.getOperand(0));
1580 Tmp2 = SelectExpr(N.getOperand(1));
1581 Tmp3 = MakeReg(MVT::i64);
1582 BuildMI(BB, Alpha::CMPEQ, 2, Tmp3).addReg(Tmp1).addReg(Tmp2);
1583 //Remeber we have the Inv for this CC
1586 BuildMI(BB, Alpha::CMPEQ, 2, Result).addReg(Alpha::R31).addReg(Tmp3);
1591 Tmp1 = SelectExpr(N.getOperand(0));
1593 Tmp2 = cast<ConstantSDNode>(N.getOperand(1))->getValue();
1594 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(Tmp2);
1596 Tmp2 = SelectExpr(N.getOperand(1));
1597 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
1599 } else { //if (dir == 2) {
1600 Tmp1 = SelectExpr(N.getOperand(1));
1601 Tmp2 = SelectExpr(N.getOperand(0));
1602 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
1606 Tmp1 = MakeReg(MVT::f64);
1607 bool inv = SelectFPSetCC(N, Tmp1);
1609 //now arrange for Result (int) to have a 1 or 0
1610 Tmp2 = MakeReg(MVT::i64);
1611 BuildMI(BB, Alpha::ADDQi, 2, Tmp2).addReg(Alpha::R31).addImm(1);
1612 Opc = inv?Alpha::CMOVNEi_FP:Alpha::CMOVEQi_FP;
1613 BuildMI(BB, Opc, 3, Result).addReg(Tmp2).addImm(0).addReg(Tmp1);
1619 case ISD::CopyFromReg:
1623 // Make sure we generate both values.
1624 if (Result != notIn)
1625 ExprMap[N.getValue(1)] = notIn; // Generate the token
1627 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
1629 SDOperand Chain = N.getOperand(0);
1632 unsigned r = cast<RegSDNode>(Node)->getReg();
1633 //std::cerr << "CopyFromReg " << Result << " = " << r << "\n";
1634 if (MVT::isFloatingPoint(N.getValue(0).getValueType()))
1635 BuildMI(BB, Alpha::CPYS, 2, Result).addReg(r).addReg(r);
1637 BuildMI(BB, Alpha::BIS, 2, Result).addReg(r).addReg(r);
1641 //Most of the plain arithmetic and logic share the same form, and the same
1642 //constant immediate test
1645 if (N.getOperand(1).getOpcode() == ISD::Constant &&
1646 cast<ConstantSDNode>(N.getOperand(1))->getSignExtended() == -1)
1648 Tmp1 = SelectExpr(N.getOperand(0));
1649 BuildMI(BB, Alpha::ORNOT, 2, Result).addReg(Alpha::R31).addReg(Tmp1);
1655 if (opcode == ISD::AND && N.getOperand(1).getOpcode() == ISD::Constant)
1657 uint64_t k = cast<ConstantSDNode>(N.getOperand(1))->getValue();
1658 unsigned int build = 0;
1659 for(int i = 0; i < 8; ++i)
1661 if ((k & 0x00FF) == 0x00FF)
1663 else if ((k & 0x00FF) != 0)
1664 { build = 0; break; }
1669 Tmp1 = SelectExpr(N.getOperand(0));
1670 BuildMI(BB, Alpha::ZAPNOTi, 2, Result).addReg(Tmp1).addImm(build);
1675 //Check operand(0) == Not
1676 if (N.getOperand(0).getOpcode() == ISD::XOR &&
1677 N.getOperand(0).getOperand(1).getOpcode() == ISD::Constant &&
1678 cast<ConstantSDNode>(N.getOperand(0).getOperand(1))->getSignExtended()
1681 case ISD::AND: Opc = Alpha::BIC; break;
1682 case ISD::OR: Opc = Alpha::ORNOT; break;
1683 case ISD::XOR: Opc = Alpha::EQV; break;
1685 Tmp1 = SelectExpr(N.getOperand(1));
1686 Tmp2 = SelectExpr(N.getOperand(0).getOperand(0));
1687 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
1690 //Check operand(1) == Not
1691 if (N.getOperand(1).getOpcode() == ISD::XOR &&
1692 N.getOperand(1).getOperand(1).getOpcode() == ISD::Constant &&
1693 cast<ConstantSDNode>(N.getOperand(1).getOperand(1))->getSignExtended()
1696 case ISD::AND: Opc = Alpha::BIC; break;
1697 case ISD::OR: Opc = Alpha::ORNOT; break;
1698 case ISD::XOR: Opc = Alpha::EQV; break;
1700 Tmp1 = SelectExpr(N.getOperand(0));
1701 Tmp2 = SelectExpr(N.getOperand(1).getOperand(0));
1702 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
1710 if(N.getOperand(1).getOpcode() == ISD::Constant &&
1711 cast<ConstantSDNode>(N.getOperand(1))->getValue() <= 255)
1714 case ISD::AND: Opc = Alpha::ANDi; break;
1715 case ISD::OR: Opc = Alpha::BISi; break;
1716 case ISD::XOR: Opc = Alpha::XORi; break;
1717 case ISD::SHL: Opc = Alpha::SLi; break;
1718 case ISD::SRL: Opc = Alpha::SRLi; break;
1719 case ISD::SRA: Opc = Alpha::SRAi; break;
1720 case ISD::MUL: Opc = Alpha::MULQi; break;
1722 Tmp1 = SelectExpr(N.getOperand(0));
1723 Tmp2 = cast<ConstantSDNode>(N.getOperand(1))->getValue();
1724 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(Tmp2);
1727 case ISD::AND: Opc = Alpha::AND; break;
1728 case ISD::OR: Opc = Alpha::BIS; break;
1729 case ISD::XOR: Opc = Alpha::XOR; break;
1730 case ISD::SHL: Opc = Alpha::SL; break;
1731 case ISD::SRL: Opc = Alpha::SRL; break;
1732 case ISD::SRA: Opc = Alpha::SRA; break;
1734 Opc = isFP ? (DestType == MVT::f64 ? Alpha::MULT : Alpha::MULS)
1738 Tmp1 = SelectExpr(N.getOperand(0));
1739 Tmp2 = SelectExpr(N.getOperand(1));
1740 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
1747 ConstantFPSDNode *CN;
1748 if (opcode == ISD::ADD)
1749 Opc = DestType == MVT::f64 ? Alpha::ADDT : Alpha::ADDS;
1751 Opc = DestType == MVT::f64 ? Alpha::SUBT : Alpha::SUBS;
1752 if (opcode == ISD::SUB
1753 && (CN = dyn_cast<ConstantFPSDNode>(N.getOperand(0)))
1754 && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0)))
1756 Tmp2 = SelectExpr(N.getOperand(1));
1757 BuildMI(BB, Alpha::CPYSN, 2, Result).addReg(Tmp2).addReg(Tmp2);
1759 Tmp1 = SelectExpr(N.getOperand(0));
1760 Tmp2 = SelectExpr(N.getOperand(1));
1761 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
1765 bool isAdd = opcode == ISD::ADD;
1767 //first check for Scaled Adds and Subs!
1768 //Valid for add and sub
1769 ConstantSDNode* CSD = NULL;
1770 if(N.getOperand(0).getOpcode() == ISD::SHL &&
1771 (CSD = dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) &&
1772 (CSD->getValue() == 2 || CSD->getValue() == 3))
1774 bool use4 = CSD->getValue() == 2;
1775 Tmp2 = SelectExpr(N.getOperand(0).getOperand(0));
1776 if ((CSD = dyn_cast<ConstantSDNode>(N.getOperand(1))) && CSD->getValue() <= 255)
1777 BuildMI(BB, isAdd?(use4?Alpha::S4ADDQi:Alpha::S8ADDQi):(use4?Alpha::S4SUBQi:Alpha::S8SUBQi),
1778 2, Result).addReg(Tmp2).addImm(CSD->getValue());
1780 Tmp1 = SelectExpr(N.getOperand(1));
1781 BuildMI(BB, isAdd?(use4?Alpha::S4ADDQi:Alpha::S8ADDQi):(use4?Alpha::S4SUBQi:Alpha::S8SUBQi),
1782 2, Result).addReg(Tmp2).addReg(Tmp1);
1785 //Position prevents subs
1786 else if(N.getOperand(1).getOpcode() == ISD::SHL && isAdd &&
1787 (CSD = dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) &&
1788 (CSD->getValue() == 2 || CSD->getValue() == 3))
1790 bool use4 = CSD->getValue() == 2;
1791 Tmp2 = SelectExpr(N.getOperand(1).getOperand(0));
1792 if ((CSD = dyn_cast<ConstantSDNode>(N.getOperand(0))) && CSD->getValue() <= 255)
1793 BuildMI(BB, use4?Alpha::S4ADDQi:Alpha::S8ADDQi, 2, Result).addReg(Tmp2)
1794 .addImm(CSD->getValue());
1796 Tmp1 = SelectExpr(N.getOperand(0));
1797 BuildMI(BB, use4?Alpha::S4ADDQ:Alpha::S8ADDQ, 2, Result).addReg(Tmp2).addReg(Tmp1);
1801 else if((CSD = dyn_cast<ConstantSDNode>(N.getOperand(1))) &&
1802 CSD->getValue() <= 255)
1803 { //Normal imm add/sub
1804 Opc = isAdd ? Alpha::ADDQi : Alpha::SUBQi;
1805 Tmp1 = SelectExpr(N.getOperand(0));
1806 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(CSD->getValue());
1808 else if((CSD = dyn_cast<ConstantSDNode>(N.getOperand(1))) &&
1809 (int64_t)CSD->getValue() >= 255 &&
1810 (int64_t)CSD->getValue() <= 0)
1811 { //inverted imm add/sub
1812 Opc = isAdd ? Alpha::SUBQi : Alpha::ADDQi;
1813 Tmp1 = SelectExpr(N.getOperand(0));
1814 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm((int64_t)CSD->getValue());
1817 else if((CSD = dyn_cast<ConstantSDNode>(N.getOperand(1))) &&
1818 CSD->getSignExtended() <= 32767 &&
1819 CSD->getSignExtended() >= -32767)
1821 Tmp1 = SelectExpr(N.getOperand(0));
1822 Tmp2 = (long)CSD->getSignExtended();
1825 BuildMI(BB, Alpha::LDA, 2, Result).addImm(Tmp2).addReg(Tmp1);
1827 //give up and do the operation
1830 Opc = isAdd ? Alpha::ADDQ : Alpha::SUBQ;
1831 Tmp1 = SelectExpr(N.getOperand(0));
1832 Tmp2 = SelectExpr(N.getOperand(1));
1833 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
1840 Tmp1 = SelectExpr(N.getOperand(0));
1841 Tmp2 = SelectExpr(N.getOperand(1));
1842 BuildMI(BB, DestType == MVT::f64 ? Alpha::DIVT : Alpha::DIVS, 2, Result)
1843 .addReg(Tmp1).addReg(Tmp2);
1846 ConstantSDNode* CSD;
1847 //check if we can convert into a shift!
1848 if ((CSD = dyn_cast<ConstantSDNode>(N.getOperand(1).Val)) &&
1849 (int64_t)CSD->getSignExtended() != 0 &&
1850 ExactLog2(abs((int64_t)CSD->getSignExtended())) != 0)
1852 unsigned k = ExactLog2(abs(CSD->getSignExtended()));
1853 Tmp1 = SelectExpr(N.getOperand(0));
1858 Tmp2 = MakeReg(MVT::i64);
1859 BuildMI(BB, Alpha::SRAi, 2, Tmp2).addReg(Tmp1).addImm(k - 1);
1861 Tmp3 = MakeReg(MVT::i64);
1862 BuildMI(BB, Alpha::SRLi, 2, Tmp3).addReg(Tmp2).addImm(64-k);
1863 unsigned Tmp4 = MakeReg(MVT::i64);
1864 BuildMI(BB, Alpha::ADDQ, 2, Tmp4).addReg(Tmp3).addReg(Tmp1);
1865 if ((int64_t)CSD->getSignExtended() > 0)
1866 BuildMI(BB, Alpha::SRAi, 2, Result).addReg(Tmp4).addImm(k);
1869 unsigned Tmp5 = MakeReg(MVT::i64);
1870 BuildMI(BB, Alpha::SRAi, 2, Tmp5).addReg(Tmp4).addImm(k);
1871 BuildMI(BB, Alpha::SUBQ, 2, Result).addReg(Alpha::R31).addReg(Tmp5);
1880 ConstantSDNode* CSD;
1881 if ((CSD = dyn_cast<ConstantSDNode>(N.getOperand(1).Val)) &&
1882 ((int64_t)CSD->getSignExtended() >= 2 ||
1883 (int64_t)CSD->getSignExtended() <= -2))
1885 // If this is a divide by constant, we can emit code using some magic
1886 // constants to implement it as a multiply instead.
1888 if (opcode == ISD::SDIV)
1889 return SelectExpr(BuildSDIVSequence(N));
1891 return SelectExpr(BuildUDIVSequence(N));
1897 const char* opstr = 0;
1899 case ISD::UREM: opstr = "__remqu"; break;
1900 case ISD::SREM: opstr = "__remq"; break;
1901 case ISD::UDIV: opstr = "__divqu"; break;
1902 case ISD::SDIV: opstr = "__divq"; break;
1904 Tmp1 = SelectExpr(N.getOperand(0));
1905 Tmp2 = SelectExpr(N.getOperand(1));
1907 ISelDAG->getExternalSymbol(opstr, AlphaLowering.getPointerTy());
1908 Tmp3 = SelectExpr(Addr);
1909 //set up regs explicitly (helps Reg alloc)
1910 BuildMI(BB, Alpha::BIS, 2, Alpha::R24).addReg(Tmp1).addReg(Tmp1);
1911 BuildMI(BB, Alpha::BIS, 2, Alpha::R25).addReg(Tmp2).addReg(Tmp2);
1912 BuildMI(BB, Alpha::BIS, 2, Alpha::R27).addReg(Tmp3).addReg(Tmp3);
1913 BuildMI(BB, Alpha::JSRs, 2, Alpha::R23).addReg(Alpha::R27).addImm(0);
1914 BuildMI(BB, Alpha::BIS, 2, Result).addReg(Alpha::R27).addReg(Alpha::R27);
1918 case ISD::FP_TO_UINT:
1919 case ISD::FP_TO_SINT:
1921 assert (DestType == MVT::i64 && "only quads can be loaded to");
1922 MVT::ValueType SrcType = N.getOperand(0).getValueType();
1923 assert (SrcType == MVT::f32 || SrcType == MVT::f64);
1924 Tmp1 = SelectExpr(N.getOperand(0)); // Get the operand register
1925 if (SrcType == MVT::f32)
1927 Tmp2 = MakeReg(MVT::f64);
1928 BuildMI(BB, Alpha::CVTST, 1, Tmp2).addReg(Tmp1);
1931 Tmp2 = MakeReg(MVT::f64);
1932 BuildMI(BB, Alpha::CVTTQ, 1, Tmp2).addReg(Tmp1);
1933 MoveFP2Int(Tmp2, Result, true);
1940 //Tmp1 = SelectExpr(N.getOperand(0)); //Cond
1941 unsigned TV = SelectExpr(N.getOperand(1)); //Use if TRUE
1942 unsigned FV = SelectExpr(N.getOperand(2)); //Use if FALSE
1944 SDOperand CC = N.getOperand(0);
1945 SetCCSDNode* SetCC = dyn_cast<SetCCSDNode>(CC.Val);
1947 if (SetCC && !MVT::isInteger(SetCC->getOperand(0).getValueType()))
1948 { //FP Setcc -> Select yay!
1951 //for a cmp b: c = a - b;
1956 bool invTest = false;
1959 ConstantFPSDNode *CN;
1960 if ((CN = dyn_cast<ConstantFPSDNode>(SetCC->getOperand(1)))
1961 && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0)))
1962 Tmp3 = SelectExpr(SetCC->getOperand(0));
1963 else if ((CN = dyn_cast<ConstantFPSDNode>(SetCC->getOperand(0)))
1964 && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0)))
1966 Tmp3 = SelectExpr(SetCC->getOperand(1));
1971 unsigned Tmp1 = SelectExpr(SetCC->getOperand(0));
1972 unsigned Tmp2 = SelectExpr(SetCC->getOperand(1));
1973 bool isD = SetCC->getOperand(0).getValueType() == MVT::f64;
1974 Tmp3 = MakeReg(isD ? MVT::f64 : MVT::f32);
1975 BuildMI(BB, isD ? Alpha::SUBT : Alpha::SUBS, 2, Tmp3)
1976 .addReg(Tmp1).addReg(Tmp2);
1979 switch (SetCC->getCondition()) {
1980 default: CC.Val->dump(); assert(0 && "Unknown FP comparison!");
1981 case ISD::SETEQ: Opc = invTest ? Alpha::FCMOVNE : Alpha::FCMOVEQ; break;
1982 case ISD::SETLT: Opc = invTest ? Alpha::FCMOVGT : Alpha::FCMOVLT; break;
1983 case ISD::SETLE: Opc = invTest ? Alpha::FCMOVGE : Alpha::FCMOVLE; break;
1984 case ISD::SETGT: Opc = invTest ? Alpha::FCMOVLT : Alpha::FCMOVGT; break;
1985 case ISD::SETGE: Opc = invTest ? Alpha::FCMOVLE : Alpha::FCMOVGE; break;
1986 case ISD::SETNE: Opc = invTest ? Alpha::FCMOVEQ : Alpha::FCMOVNE; break;
1988 BuildMI(BB, Opc, 3, Result).addReg(FV).addReg(TV).addReg(Tmp3);
1993 Tmp1 = SelectExpr(N.getOperand(0)); //Cond
1994 BuildMI(BB, Alpha::FCMOVEQ_INT, 3, Result).addReg(TV).addReg(FV)
1996 // // Spill the cond to memory and reload it from there.
1997 // unsigned Tmp4 = MakeReg(MVT::f64);
1998 // MoveIntFP(Tmp1, Tmp4, true);
1999 // //now ideally, we don't have to do anything to the flag...
2000 // // Get the condition into the zero flag.
2001 // BuildMI(BB, Alpha::FCMOVEQ, 3, Result).addReg(TV).addReg(FV).addReg(Tmp4);
2005 //FIXME: look at parent to decide if intCC can be folded, or if setCC(FP)
2006 //and can save stack use
2007 //Tmp1 = SelectExpr(N.getOperand(0)); //Cond
2008 //Tmp2 = SelectExpr(N.getOperand(1)); //Use if TRUE
2009 //Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE
2010 // Get the condition into the zero flag.
2011 //BuildMI(BB, Alpha::CMOVEQ, 2, Result).addReg(Tmp2).addReg(Tmp3).addReg(Tmp1);
2013 SDOperand CC = N.getOperand(0);
2014 SetCCSDNode* SetCC = dyn_cast<SetCCSDNode>(CC.Val);
2016 if (CC.getOpcode() == ISD::SETCC &&
2017 !MVT::isInteger(SetCC->getOperand(0).getValueType()))
2018 { //FP Setcc -> Int Select
2019 Tmp1 = MakeReg(MVT::f64);
2020 Tmp2 = SelectExpr(N.getOperand(1)); //Use if TRUE
2021 Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE
2022 bool inv = SelectFPSetCC(CC, Tmp1);
2023 BuildMI(BB, inv?Alpha::CMOVNE_FP:Alpha::CMOVEQ_FP, 2, Result)
2024 .addReg(Tmp2).addReg(Tmp3).addReg(Tmp1);
2027 if (CC.getOpcode() == ISD::SETCC) {
2028 //Int SetCC -> Select
2029 //Dropping the CC is only useful if we are comparing to 0
2030 if((SetCC->getOperand(1).getOpcode() == ISD::Constant &&
2031 cast<ConstantSDNode>(SetCC->getOperand(1))->getValue() == 0))
2033 //figure out a few things
2034 bool useImm = N.getOperand(2).getOpcode() == ISD::Constant &&
2035 cast<ConstantSDNode>(N.getOperand(2))->getValue() <= 255;
2038 ISD::CondCode cCode= SetCC->getCondition();
2039 if (useImm) //Invert sense to get Imm field right
2040 cCode = ISD::getSetCCInverse(cCode, true);
2044 default: CC.Val->dump(); assert(0 && "Unknown integer comparison!");
2045 case ISD::SETEQ: Opc = useImm?Alpha::CMOVEQi:Alpha::CMOVEQ; break;
2046 case ISD::SETLT: Opc = useImm?Alpha::CMOVLTi:Alpha::CMOVLT; break;
2047 case ISD::SETLE: Opc = useImm?Alpha::CMOVLEi:Alpha::CMOVLE; break;
2048 case ISD::SETGT: Opc = useImm?Alpha::CMOVGTi:Alpha::CMOVGT; break;
2049 case ISD::SETGE: Opc = useImm?Alpha::CMOVGEi:Alpha::CMOVGE; break;
2050 case ISD::SETULT: assert(0 && "unsigned < 0 is never true"); break;
2051 case ISD::SETUGT: Opc = useImm?Alpha::CMOVNEi:Alpha::CMOVNE; break;
2052 //Technically you could have this CC
2053 case ISD::SETULE: Opc = useImm?Alpha::CMOVEQi:Alpha::CMOVEQ; break;
2054 case ISD::SETUGE: assert(0 && "unsgined >= 0 is always true"); break;
2055 case ISD::SETNE: Opc = useImm?Alpha::CMOVNEi:Alpha::CMOVNE; break;
2057 Tmp1 = SelectExpr(SetCC->getOperand(0)); //Cond
2060 Tmp3 = SelectExpr(N.getOperand(1)); //Use if FALSE
2061 BuildMI(BB, Opc, 2, Result).addReg(Tmp3)
2062 .addImm(cast<ConstantSDNode>(N.getOperand(2))->getValue())
2065 Tmp2 = SelectExpr(N.getOperand(1)); //Use if TRUE
2066 Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE
2067 BuildMI(BB, Opc, 2, Result).addReg(Tmp3).addReg(Tmp2).addReg(Tmp1);
2071 //Otherwise, fall though
2073 Tmp1 = SelectExpr(N.getOperand(0)); //Cond
2074 Tmp2 = SelectExpr(N.getOperand(1)); //Use if TRUE
2075 Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE
2076 BuildMI(BB, Alpha::CMOVEQ, 2, Result).addReg(Tmp2).addReg(Tmp3)
2084 int64_t val = (int64_t)cast<ConstantSDNode>(N)->getValue();
2085 int zero_extend_top = 0;
2086 if (val > 0 && (val & 0xFFFFFFFF00000000ULL) == 0 &&
2087 ((int32_t)val < 0)) {
2088 //try a small load and zero extend
2090 zero_extend_top = 15;
2093 if (val <= IMM_HIGH && val >= IMM_LOW) {
2094 if(!zero_extend_top)
2095 BuildMI(BB, Alpha::LDA, 2, Result).addImm(val).addReg(Alpha::R31);
2097 Tmp1 = MakeReg(MVT::i64);
2098 BuildMI(BB, Alpha::LDA, 2, Tmp1).addImm(val).addReg(Alpha::R31);
2099 BuildMI(BB, Alpha::ZAPNOT, 2, Result).addReg(Tmp1).addImm(zero_extend_top);
2102 else if (val <= (int64_t)IMM_HIGH +(int64_t)IMM_HIGH* (int64_t)IMM_MULT &&
2103 val >= (int64_t)IMM_LOW + (int64_t)IMM_LOW * (int64_t)IMM_MULT) {
2104 Tmp1 = MakeReg(MVT::i64);
2105 BuildMI(BB, Alpha::LDAH, 2, Tmp1).addImm(getUpper16(val))
2106 .addReg(Alpha::R31);
2107 if (!zero_extend_top)
2108 BuildMI(BB, Alpha::LDA, 2, Result).addImm(getLower16(val)).addReg(Tmp1);
2110 Tmp3 = MakeReg(MVT::i64);
2111 BuildMI(BB, Alpha::LDA, 2, Tmp3).addImm(getLower16(val)).addReg(Tmp1);
2112 BuildMI(BB, Alpha::ZAPNOT, 2, Result).addReg(Tmp3).addImm(zero_extend_top);
2116 //re-get the val since we are going to mem anyway
2117 val = (int64_t)cast<ConstantSDNode>(N)->getValue();
2118 MachineConstantPool *CP = BB->getParent()->getConstantPool();
2120 ConstantUInt::get(Type::getPrimitiveType(Type::ULongTyID) , val);
2121 unsigned CPI = CP->getConstantPoolIndex(C);
2122 AlphaLowering.restoreGP(BB);
2124 Tmp1 = MakeReg(MVT::i64);
2125 BuildMI(BB, Alpha::LDAHr, 2, Tmp1).addConstantPoolIndex(CPI)
2126 .addReg(Alpha::R29);
2127 if (EnableAlphaLSMark)
2128 BuildMI(BB, Alpha::MEMLABEL, 4).addImm(5).addImm(0).addImm(0)
2130 BuildMI(BB, Alpha::LDQr, 2, Result).addConstantPoolIndex(CPI)
2136 if(ISD::FABS == N.getOperand(0).getOpcode())
2138 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
2139 BuildMI(BB, Alpha::CPYSN, 2, Result).addReg(Alpha::F31).addReg(Tmp1);
2141 Tmp1 = SelectExpr(N.getOperand(0));
2142 BuildMI(BB, Alpha::CPYSN, 2, Result).addReg(Tmp1).addReg(Tmp1);
2147 Tmp1 = SelectExpr(N.getOperand(0));
2148 BuildMI(BB, Alpha::CPYS, 2, Result).addReg(Alpha::F31).addReg(Tmp1);
2152 assert (DestType == MVT::f32 &&
2153 N.getOperand(0).getValueType() == MVT::f64 &&
2154 "only f64 to f32 conversion supported here");
2155 Tmp1 = SelectExpr(N.getOperand(0));
2156 BuildMI(BB, Alpha::CVTTS, 1, Result).addReg(Tmp1);
2159 case ISD::FP_EXTEND:
2160 assert (DestType == MVT::f64 &&
2161 N.getOperand(0).getValueType() == MVT::f32 &&
2162 "only f32 to f64 conversion supported here");
2163 Tmp1 = SelectExpr(N.getOperand(0));
2164 BuildMI(BB, Alpha::CVTST, 1, Result).addReg(Tmp1);
2167 case ISD::ConstantFP:
2168 if (ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(N)) {
2169 if (CN->isExactlyValue(+0.0)) {
2170 BuildMI(BB, Alpha::CPYS, 2, Result).addReg(Alpha::F31)
2171 .addReg(Alpha::F31);
2172 } else if ( CN->isExactlyValue(-0.0)) {
2173 BuildMI(BB, Alpha::CPYSN, 2, Result).addReg(Alpha::F31)
2174 .addReg(Alpha::F31);
2181 case ISD::SINT_TO_FP:
2183 assert (N.getOperand(0).getValueType() == MVT::i64
2184 && "only quads can be loaded from");
2185 Tmp1 = SelectExpr(N.getOperand(0)); // Get the operand register
2186 Tmp2 = MakeReg(MVT::f64);
2187 MoveInt2FP(Tmp1, Tmp2, true);
2188 Opc = DestType == MVT::f64 ? Alpha::CVTQT : Alpha::CVTQS;
2189 BuildMI(BB, Opc, 1, Result).addReg(Tmp2);
2197 void AlphaISel::Select(SDOperand N) {
2198 unsigned Tmp1, Tmp2, Opc;
2199 unsigned opcode = N.getOpcode();
2201 if (!ExprMap.insert(std::make_pair(N, notIn)).second)
2202 return; // Already selected.
2204 SDNode *Node = N.Val;
2209 Node->dump(); std::cerr << "\n";
2210 assert(0 && "Node not handled yet!");
2218 MachineBasicBlock *Dest =
2219 cast<BasicBlockSDNode>(N.getOperand(1))->getBasicBlock();
2221 Select(N.getOperand(0));
2222 BuildMI(BB, Alpha::BR, 1, Alpha::R31).addMBB(Dest);
2226 case ISD::ImplicitDef:
2228 Select(N.getOperand(0));
2229 BuildMI(BB, Alpha::IDEF, 0, cast<RegSDNode>(N)->getReg());
2232 case ISD::EntryToken: return; // Noop
2234 case ISD::TokenFactor:
2235 for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i)
2236 Select(Node->getOperand(i));
2238 //N.Val->dump(); std::cerr << "\n";
2239 //assert(0 && "Node not handled yet!");
2243 case ISD::CopyToReg:
2245 Select(N.getOperand(0));
2246 Tmp1 = SelectExpr(N.getOperand(1));
2247 Tmp2 = cast<RegSDNode>(N)->getReg();
2250 if (N.getOperand(1).getValueType() == MVT::f64 ||
2251 N.getOperand(1).getValueType() == MVT::f32)
2252 BuildMI(BB, Alpha::CPYS, 2, Tmp2).addReg(Tmp1).addReg(Tmp1);
2254 BuildMI(BB, Alpha::BIS, 2, Tmp2).addReg(Tmp1).addReg(Tmp1);
2260 switch (N.getNumOperands()) {
2262 std::cerr << N.getNumOperands() << "\n";
2263 for (unsigned i = 0; i < N.getNumOperands(); ++i)
2264 std::cerr << N.getOperand(i).getValueType() << "\n";
2266 assert(0 && "Unknown return instruction!");
2268 Select(N.getOperand(0));
2269 Tmp1 = SelectExpr(N.getOperand(1));
2270 switch (N.getOperand(1).getValueType()) {
2271 default: Node->dump();
2272 assert(0 && "All other types should have been promoted!!");
2275 BuildMI(BB, Alpha::CPYS, 2, Alpha::F0).addReg(Tmp1).addReg(Tmp1);
2279 BuildMI(BB, Alpha::BIS, 2, Alpha::R0).addReg(Tmp1).addReg(Tmp1);
2284 Select(N.getOperand(0));
2287 // Just emit a 'ret' instruction
2288 AlphaLowering.restoreRA(BB);
2289 BuildMI(BB, Alpha::RET, 2, Alpha::R31).addReg(Alpha::R26).addImm(1);
2292 case ISD::TRUNCSTORE:
2295 SDOperand Chain = N.getOperand(0);
2296 SDOperand Value = N.getOperand(1);
2297 SDOperand Address = N.getOperand(2);
2300 Tmp1 = SelectExpr(Value); //value
2302 if (opcode == ISD::STORE) {
2303 switch(Value.getValueType()) {
2304 default: assert(0 && "unknown Type in store");
2305 case MVT::i64: Opc = Alpha::STQ; break;
2306 case MVT::f64: Opc = Alpha::STT; break;
2307 case MVT::f32: Opc = Alpha::STS; break;
2309 } else { //ISD::TRUNCSTORE
2310 switch(cast<VTSDNode>(Node->getOperand(4))->getVT()) {
2311 default: assert(0 && "unknown Type in store");
2312 case MVT::i1: //FIXME: DAG does not promote this load
2313 case MVT::i8: Opc = Alpha::STB; break;
2314 case MVT::i16: Opc = Alpha::STW; break;
2315 case MVT::i32: Opc = Alpha::STL; break;
2320 if (EnableAlphaLSMark)
2321 getValueInfo(cast<SrcValueSDNode>(N.getOperand(3))->getValue(),
2324 GlobalAddressSDNode *GASD = dyn_cast<GlobalAddressSDNode>(Address);
2325 if (GASD && !GASD->getGlobal()->isExternal()) {
2326 Tmp2 = MakeReg(MVT::i64);
2327 AlphaLowering.restoreGP(BB);
2328 BuildMI(BB, Alpha::LDAHr, 2, Tmp2)
2329 .addGlobalAddress(GASD->getGlobal()).addReg(Alpha::R29);
2330 if (EnableAlphaLSMark)
2331 BuildMI(BB, Alpha::MEMLABEL, 4).addImm(i).addImm(j).addImm(k)
2333 BuildMI(BB, GetRelVersion(Opc), 3).addReg(Tmp1)
2334 .addGlobalAddress(GASD->getGlobal()).addReg(Tmp2);
2335 } else if(Address.getOpcode() == ISD::FrameIndex) {
2336 if (EnableAlphaLSMark)
2337 BuildMI(BB, Alpha::MEMLABEL, 4).addImm(i).addImm(j).addImm(k)
2339 BuildMI(BB, Opc, 3).addReg(Tmp1)
2340 .addFrameIndex(cast<FrameIndexSDNode>(Address)->getIndex())
2341 .addReg(Alpha::F31);
2344 SelectAddr(Address, Tmp2, offset);
2345 if (EnableAlphaLSMark)
2346 BuildMI(BB, Alpha::MEMLABEL, 4).addImm(i).addImm(j).addImm(k)
2348 BuildMI(BB, Opc, 3).addReg(Tmp1).addImm(offset).addReg(Tmp2);
2357 case ISD::CopyFromReg:
2360 case ISD::DYNAMIC_STACKALLOC:
2365 case ISD::CALLSEQ_START:
2366 case ISD::CALLSEQ_END:
2367 Select(N.getOperand(0));
2368 Tmp1 = cast<ConstantSDNode>(N.getOperand(1))->getValue();
2370 Opc = N.getOpcode() == ISD::CALLSEQ_START ? Alpha::ADJUSTSTACKDOWN :
2371 Alpha::ADJUSTSTACKUP;
2372 BuildMI(BB, Opc, 1).addImm(Tmp1);
2376 Select(N.getOperand(0)); //Chain
2377 BuildMI(BB, Alpha::PCLABEL, 2)
2378 .addImm( cast<ConstantSDNode>(N.getOperand(1))->getValue());
2381 assert(0 && "Should not be reached!");
2385 /// createAlphaPatternInstructionSelector - This pass converts an LLVM function
2386 /// into a machine code representation using pattern matching and a machine
2387 /// description file.
2389 FunctionPass *llvm::createAlphaPatternInstructionSelector(TargetMachine &TM) {
2390 return new AlphaISel(TM);