| Andrew Lenharth | 794f158 | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 1 | //===-- AlphaISelDAGToDAG.cpp - Alpha pattern matching inst selector ------===// | 
|  | 2 | // | 
|  | 3 | //                     The LLVM Compiler Infrastructure | 
|  | 4 | // | 
| Chris Lattner | f3ebc3f | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source | 
|  | 6 | // License. See LICENSE.TXT for details. | 
| Andrew Lenharth | 794f158 | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 7 | // | 
|  | 8 | //===----------------------------------------------------------------------===// | 
|  | 9 | // | 
|  | 10 | // This file defines a pattern matching instruction selector for Alpha, | 
|  | 11 | // converting from a legalized dag to a Alpha dag. | 
|  | 12 | // | 
|  | 13 | //===----------------------------------------------------------------------===// | 
|  | 14 |  | 
|  | 15 | #include "Alpha.h" | 
|  | 16 | #include "AlphaTargetMachine.h" | 
|  | 17 | #include "AlphaISelLowering.h" | 
|  | 18 | #include "llvm/CodeGen/MachineInstrBuilder.h" | 
| Andrew Lenharth | 6db615d | 2005-11-30 07:19:56 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/MachineFrameInfo.h" | 
| Andrew Lenharth | 794f158 | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/MachineFunction.h" | 
| Chris Lattner | a10fff5 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/MachineRegisterInfo.h" | 
| Andrew Lenharth | 794f158 | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 22 | #include "llvm/CodeGen/SelectionDAG.h" | 
|  | 23 | #include "llvm/CodeGen/SelectionDAGISel.h" | 
|  | 24 | #include "llvm/Target/TargetOptions.h" | 
| Andrew Lenharth | 794f158 | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 25 | #include "llvm/Constants.h" | 
| Reid Spencer | a94d394 | 2007-01-19 21:13:56 +0000 | [diff] [blame] | 26 | #include "llvm/DerivedTypes.h" | 
| Andrew Lenharth | 794f158 | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 27 | #include "llvm/GlobalValue.h" | 
| Chris Lattner | 5d70a7c | 2006-03-25 06:47:10 +0000 | [diff] [blame] | 28 | #include "llvm/Intrinsics.h" | 
| Owen Anderson | b6b2530 | 2009-07-14 23:09:55 +0000 | [diff] [blame] | 29 | #include "llvm/LLVMContext.h" | 
| Chris Lattner | 1770fb8 | 2008-02-03 05:43:57 +0000 | [diff] [blame] | 30 | #include "llvm/Support/Compiler.h" | 
| Andrew Lenharth | 794f158 | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 31 | #include "llvm/Support/Debug.h" | 
| Torok Edwin | fb8d6d5 | 2009-07-08 20:53:28 +0000 | [diff] [blame] | 32 | #include "llvm/Support/ErrorHandling.h" | 
| Andrew Lenharth | 794f158 | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 33 | #include "llvm/Support/MathExtras.h" | 
| Torok Edwin | fb8d6d5 | 2009-07-08 20:53:28 +0000 | [diff] [blame] | 34 | #include "llvm/Support/raw_ostream.h" | 
| Andrew Lenharth | 5a99041 | 2005-10-22 22:06:58 +0000 | [diff] [blame] | 35 | #include <algorithm> | 
| Andrew Lenharth | 794f158 | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 36 | using namespace llvm; | 
|  | 37 |  | 
|  | 38 | namespace { | 
|  | 39 |  | 
|  | 40 | //===--------------------------------------------------------------------===// | 
|  | 41 | /// AlphaDAGToDAGISel - Alpha specific code to select Alpha machine | 
|  | 42 | /// instructions for SelectionDAG operations. | 
| Andrew Lenharth | 794f158 | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 43 | class AlphaDAGToDAGISel : public SelectionDAGISel { | 
| Andrew Lenharth | 60ab61f | 2005-12-30 02:30:02 +0000 | [diff] [blame] | 44 | static const int64_t IMM_LOW  = -32768; | 
|  | 45 | static const int64_t IMM_HIGH = 32767; | 
|  | 46 | static const int64_t IMM_MULT = 65536; | 
| Andrew Lenharth | 6bec63a | 2006-01-01 22:16:14 +0000 | [diff] [blame] | 47 | static const int64_t IMM_FULLHIGH = IMM_HIGH + IMM_HIGH * IMM_MULT; | 
|  | 48 | static const int64_t IMM_FULLLOW = IMM_LOW + IMM_LOW  * IMM_MULT; | 
|  | 49 |  | 
|  | 50 | static int64_t get_ldah16(int64_t x) { | 
|  | 51 | int64_t y = x / IMM_MULT; | 
|  | 52 | if (x % IMM_MULT > IMM_HIGH) | 
| Anton Korobeynikov | fb80151 | 2007-04-16 18:10:23 +0000 | [diff] [blame] | 53 | ++y; | 
| Andrew Lenharth | 6bec63a | 2006-01-01 22:16:14 +0000 | [diff] [blame] | 54 | return y; | 
|  | 55 | } | 
|  | 56 |  | 
|  | 57 | static int64_t get_lda16(int64_t x) { | 
|  | 58 | return x - get_ldah16(x) * IMM_MULT; | 
|  | 59 | } | 
|  | 60 |  | 
| Chris Lattner | 6487854 | 2006-10-11 05:13:56 +0000 | [diff] [blame] | 61 | /// get_zapImm - Return a zap mask if X is a valid immediate for a zapnot | 
|  | 62 | /// instruction (if not, return 0).  Note that this code accepts partial | 
|  | 63 | /// zap masks.  For example (and LHS, 1) is a valid zap, as long we know | 
|  | 64 | /// that the bits 1-7 of LHS are already zero.  If LHS is non-null, we are | 
|  | 65 | /// in checking mode.  If LHS is null, we assume that the mask has already | 
|  | 66 | /// been validated before. | 
| Chris Lattner | 52bfe24 | 2010-02-16 07:26:36 +0000 | [diff] [blame^] | 67 | uint64_t get_zapImm(SDValue LHS, uint64_t Constant) const { | 
| Chris Lattner | 6487854 | 2006-10-11 05:13:56 +0000 | [diff] [blame] | 68 | uint64_t BitsToCheck = 0; | 
|  | 69 | unsigned Result = 0; | 
|  | 70 | for (unsigned i = 0; i != 8; ++i) { | 
|  | 71 | if (((Constant >> 8*i) & 0xFF) == 0) { | 
|  | 72 | // nothing to do. | 
|  | 73 | } else { | 
|  | 74 | Result |= 1 << i; | 
|  | 75 | if (((Constant >> 8*i) & 0xFF) == 0xFF) { | 
|  | 76 | // If the entire byte is set, zapnot the byte. | 
| Gabor Greif | f304a7a | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 77 | } else if (LHS.getNode() == 0) { | 
| Chris Lattner | 6487854 | 2006-10-11 05:13:56 +0000 | [diff] [blame] | 78 | // Otherwise, if the mask was previously validated, we know its okay | 
|  | 79 | // to zapnot this entire byte even though all the bits aren't set. | 
|  | 80 | } else { | 
|  | 81 | // Otherwise we don't know that the it's okay to zapnot this entire | 
|  | 82 | // byte.  Only do this iff we can prove that the missing bits are | 
|  | 83 | // already null, so the bytezap doesn't need to really null them. | 
|  | 84 | BitsToCheck |= ~Constant & (0xFF << 8*i); | 
|  | 85 | } | 
|  | 86 | } | 
|  | 87 | } | 
|  | 88 |  | 
|  | 89 | // If there are missing bits in a byte (for example, X & 0xEF00), check to | 
|  | 90 | // see if the missing bits (0x1000) are already known zero if not, the zap | 
|  | 91 | // isn't okay to do, as it won't clear all the required bits. | 
|  | 92 | if (BitsToCheck && | 
| Dan Gohman | 1f372ed | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 93 | !CurDAG->MaskedValueIsZero(LHS, | 
|  | 94 | APInt(LHS.getValueSizeInBits(), | 
|  | 95 | BitsToCheck))) | 
| Chris Lattner | 6487854 | 2006-10-11 05:13:56 +0000 | [diff] [blame] | 96 | return 0; | 
|  | 97 |  | 
|  | 98 | return Result; | 
|  | 99 | } | 
|  | 100 |  | 
| Andrew Lenharth | 6bec63a | 2006-01-01 22:16:14 +0000 | [diff] [blame] | 101 | static uint64_t get_zapImm(uint64_t x) { | 
| Chris Lattner | 6487854 | 2006-10-11 05:13:56 +0000 | [diff] [blame] | 102 | unsigned build = 0; | 
|  | 103 | for(int i = 0; i != 8; ++i) { | 
|  | 104 | if ((x & 0x00FF) == 0x00FF) | 
|  | 105 | build |= 1 << i; | 
|  | 106 | else if ((x & 0x00FF) != 0) | 
|  | 107 | return 0; | 
|  | 108 | x >>= 8; | 
|  | 109 | } | 
| Andrew Lenharth | eaf5ed1 | 2006-01-02 21:15:53 +0000 | [diff] [blame] | 110 | return build; | 
| Andrew Lenharth | 6bec63a | 2006-01-01 22:16:14 +0000 | [diff] [blame] | 111 | } | 
| Chris Lattner | 6487854 | 2006-10-11 05:13:56 +0000 | [diff] [blame] | 112 |  | 
|  | 113 |  | 
| Andrew Lenharth | 4e2c073 | 2006-04-03 03:18:59 +0000 | [diff] [blame] | 114 | static uint64_t getNearPower2(uint64_t x) { | 
|  | 115 | if (!x) return 0; | 
|  | 116 | unsigned at = CountLeadingZeros_64(x); | 
|  | 117 | uint64_t complow = 1 << (63 - at); | 
|  | 118 | uint64_t comphigh = 1 << (64 - at); | 
| Bill Wendling | 9bfb1e1 | 2006-12-07 22:21:48 +0000 | [diff] [blame] | 119 | //cerr << x << ":" << complow << ":" << comphigh << "\n"; | 
| Benjamin Kramer | 6e046f4 | 2009-08-09 22:37:07 +0000 | [diff] [blame] | 120 | if (abs64(complow - x) <= abs64(comphigh - x)) | 
| Andrew Lenharth | 4e2c073 | 2006-04-03 03:18:59 +0000 | [diff] [blame] | 121 | return complow; | 
|  | 122 | else | 
|  | 123 | return comphigh; | 
|  | 124 | } | 
|  | 125 |  | 
| Andrew Lenharth | 8b20fa4 | 2006-10-31 19:52:12 +0000 | [diff] [blame] | 126 | static bool chkRemNearPower2(uint64_t x, uint64_t r, bool swap) { | 
|  | 127 | uint64_t y = getNearPower2(x); | 
|  | 128 | if (swap) | 
|  | 129 | return (y - x) == r; | 
|  | 130 | else | 
|  | 131 | return (x - y) == r; | 
|  | 132 | } | 
|  | 133 |  | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 134 | static bool isFPZ(SDValue N) { | 
| Andrew Lenharth | 6bec63a | 2006-01-01 22:16:14 +0000 | [diff] [blame] | 135 | ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(N); | 
| Dale Johannesen | 3cf889f | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 136 | return (CN && (CN->getValueAPF().isZero())); | 
| Andrew Lenharth | 6bec63a | 2006-01-01 22:16:14 +0000 | [diff] [blame] | 137 | } | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 138 | static bool isFPZn(SDValue N) { | 
| Andrew Lenharth | 6bec63a | 2006-01-01 22:16:14 +0000 | [diff] [blame] | 139 | ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(N); | 
| Dale Johannesen | 3cf889f | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 140 | return (CN && CN->getValueAPF().isNegZero()); | 
| Andrew Lenharth | 6bec63a | 2006-01-01 22:16:14 +0000 | [diff] [blame] | 141 | } | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 142 | static bool isFPZp(SDValue N) { | 
| Andrew Lenharth | 6bec63a | 2006-01-01 22:16:14 +0000 | [diff] [blame] | 143 | ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(N); | 
| Dale Johannesen | 3cf889f | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 144 | return (CN && CN->getValueAPF().isPosZero()); | 
| Andrew Lenharth | 6bec63a | 2006-01-01 22:16:14 +0000 | [diff] [blame] | 145 | } | 
|  | 146 |  | 
| Andrew Lenharth | 794f158 | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 147 | public: | 
| Dan Gohman | eabd647 | 2008-05-14 01:58:56 +0000 | [diff] [blame] | 148 | explicit AlphaDAGToDAGISel(AlphaTargetMachine &TM) | 
| Dan Gohman | 619ef48 | 2009-01-15 19:20:50 +0000 | [diff] [blame] | 149 | : SelectionDAGISel(TM) | 
| Andrew Lenharth | 60ab61f | 2005-12-30 02:30:02 +0000 | [diff] [blame] | 150 | {} | 
| Andrew Lenharth | 794f158 | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 151 |  | 
|  | 152 | /// getI64Imm - Return a target constant with the specified value, of type | 
|  | 153 | /// i64. | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 154 | inline SDValue getI64Imm(int64_t Imm) { | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 155 | return CurDAG->getTargetConstant(Imm, MVT::i64); | 
| Andrew Lenharth | 794f158 | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 156 | } | 
|  | 157 |  | 
| Andrew Lenharth | 794f158 | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 158 | // Select - Convert the specified operand from a target-independent to a | 
|  | 159 | // target-specific node if it hasn't already been changed. | 
| Dan Gohman | ea6f91f | 2010-01-05 01:24:18 +0000 | [diff] [blame] | 160 | SDNode *Select(SDNode *N); | 
| Andrew Lenharth | 794f158 | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 161 |  | 
| Evan Cheng | 0711d68 | 2008-06-30 20:45:06 +0000 | [diff] [blame] | 162 | /// InstructionSelect - This callback is invoked by | 
| Andrew Lenharth | 794f158 | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 163 | /// SelectionDAGISel when it has created a SelectionDAG for us to codegen. | 
| Dan Gohman | eb0cee9 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 164 | virtual void InstructionSelect(); | 
| Andrew Lenharth | 794f158 | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 165 |  | 
|  | 166 | virtual const char *getPassName() const { | 
|  | 167 | return "Alpha DAG->DAG Pattern Instruction Selection"; | 
|  | 168 | } | 
|  | 169 |  | 
| Andrew Lenharth | 680ac12 | 2006-06-21 15:42:36 +0000 | [diff] [blame] | 170 | /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for | 
|  | 171 | /// inline asm expressions. | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 172 | virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op, | 
| Andrew Lenharth | 680ac12 | 2006-06-21 15:42:36 +0000 | [diff] [blame] | 173 | char ConstraintCode, | 
| Dan Gohman | eb0cee9 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 174 | std::vector<SDValue> &OutOps) { | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 175 | SDValue Op0; | 
| Andrew Lenharth | 680ac12 | 2006-06-21 15:42:36 +0000 | [diff] [blame] | 176 | switch (ConstraintCode) { | 
|  | 177 | default: return true; | 
|  | 178 | case 'm':   // memory | 
| Evan Cheng | ab8297f | 2006-08-26 01:07:58 +0000 | [diff] [blame] | 179 | Op0 = Op; | 
| Andrew Lenharth | 680ac12 | 2006-06-21 15:42:36 +0000 | [diff] [blame] | 180 | break; | 
|  | 181 | } | 
|  | 182 |  | 
|  | 183 | OutOps.push_back(Op0); | 
|  | 184 | return false; | 
|  | 185 | } | 
|  | 186 |  | 
| Andrew Lenharth | 794f158 | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 187 | // Include the pieces autogenerated from the target description. | 
|  | 188 | #include "AlphaGenDAGISel.inc" | 
|  | 189 |  | 
|  | 190 | private: | 
| Dan Gohman | d5ca7064 | 2009-06-03 20:30:14 +0000 | [diff] [blame] | 191 | /// getTargetMachine - Return a reference to the TargetMachine, casted | 
|  | 192 | /// to the target-specific type. | 
|  | 193 | const AlphaTargetMachine &getTargetMachine() { | 
|  | 194 | return static_cast<const AlphaTargetMachine &>(TM); | 
|  | 195 | } | 
|  | 196 |  | 
|  | 197 | /// getInstrInfo - Return a reference to the TargetInstrInfo, casted | 
|  | 198 | /// to the target-specific type. | 
|  | 199 | const AlphaInstrInfo *getInstrInfo() { | 
|  | 200 | return getTargetMachine().getInstrInfo(); | 
|  | 201 | } | 
|  | 202 |  | 
|  | 203 | SDNode *getGlobalBaseReg(); | 
|  | 204 | SDNode *getGlobalRetAddr(); | 
| Dan Gohman | ea6f91f | 2010-01-05 01:24:18 +0000 | [diff] [blame] | 205 | void SelectCALL(SDNode *Op); | 
| Andrew Lenharth | 5a99041 | 2005-10-22 22:06:58 +0000 | [diff] [blame] | 206 |  | 
| Andrew Lenharth | 794f158 | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 207 | }; | 
|  | 208 | } | 
|  | 209 |  | 
| Andrew Lenharth | 5a99041 | 2005-10-22 22:06:58 +0000 | [diff] [blame] | 210 | /// getGlobalBaseReg - Output the instructions required to put the | 
|  | 211 | /// GOT address into a register. | 
|  | 212 | /// | 
| Dan Gohman | d5ca7064 | 2009-06-03 20:30:14 +0000 | [diff] [blame] | 213 | SDNode *AlphaDAGToDAGISel::getGlobalBaseReg() { | 
| Dan Gohman | d5ca7064 | 2009-06-03 20:30:14 +0000 | [diff] [blame] | 214 | unsigned GlobalBaseReg = getInstrInfo()->getGlobalBaseReg(MF); | 
|  | 215 | return CurDAG->getRegister(GlobalBaseReg, TLI.getPointerTy()).getNode(); | 
| Andrew Lenharth | ce68ef8 | 2005-12-01 01:53:10 +0000 | [diff] [blame] | 216 | } | 
|  | 217 |  | 
| Dan Gohman | d5ca7064 | 2009-06-03 20:30:14 +0000 | [diff] [blame] | 218 | /// getGlobalRetAddr - Grab the return address. | 
| Andrew Lenharth | ce68ef8 | 2005-12-01 01:53:10 +0000 | [diff] [blame] | 219 | /// | 
| Dan Gohman | d5ca7064 | 2009-06-03 20:30:14 +0000 | [diff] [blame] | 220 | SDNode *AlphaDAGToDAGISel::getGlobalRetAddr() { | 
| Dan Gohman | d5ca7064 | 2009-06-03 20:30:14 +0000 | [diff] [blame] | 221 | unsigned GlobalRetAddr = getInstrInfo()->getGlobalRetAddr(MF); | 
|  | 222 | return CurDAG->getRegister(GlobalRetAddr, TLI.getPointerTy()).getNode(); | 
| Andrew Lenharth | 5a99041 | 2005-10-22 22:06:58 +0000 | [diff] [blame] | 223 | } | 
|  | 224 |  | 
| Evan Cheng | 0711d68 | 2008-06-30 20:45:06 +0000 | [diff] [blame] | 225 | /// InstructionSelect - This callback is invoked by | 
| Andrew Lenharth | 794f158 | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 226 | /// SelectionDAGISel when it has created a SelectionDAG for us to codegen. | 
| Dan Gohman | eb0cee9 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 227 | void AlphaDAGToDAGISel::InstructionSelect() { | 
| Andrew Lenharth | 794f158 | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 228 | // Select target instructions for the DAG. | 
| David Greene | ce2a938 | 2008-10-27 21:56:29 +0000 | [diff] [blame] | 229 | SelectRoot(*CurDAG); | 
| Dan Gohman | eb0cee9 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 230 | CurDAG->RemoveDeadNodes(); | 
| Andrew Lenharth | 794f158 | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 231 | } | 
|  | 232 |  | 
|  | 233 | // Select - Convert the specified operand from a target-independent to a | 
|  | 234 | // target-specific node if it hasn't already been changed. | 
| Dan Gohman | ea6f91f | 2010-01-05 01:24:18 +0000 | [diff] [blame] | 235 | SDNode *AlphaDAGToDAGISel::Select(SDNode *N) { | 
| Dan Gohman | 1705968 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 236 | if (N->isMachineOpcode()) { | 
| Evan Cheng | bd1c5a8 | 2006-08-11 09:08:15 +0000 | [diff] [blame] | 237 | return NULL;   // Already selected. | 
| Evan Cheng | 6dc90ca | 2006-02-09 00:37:58 +0000 | [diff] [blame] | 238 | } | 
| Dale Johannesen | f08a47b | 2009-02-04 23:02:30 +0000 | [diff] [blame] | 239 | DebugLoc dl = N->getDebugLoc(); | 
| Andrew Lenharth | 794f158 | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 240 |  | 
| Andrew Lenharth | 794f158 | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 241 | switch (N->getOpcode()) { | 
|  | 242 | default: break; | 
| Evan Cheng | 6dc90ca | 2006-02-09 00:37:58 +0000 | [diff] [blame] | 243 | case AlphaISD::CALL: | 
| Dan Gohman | ea6f91f | 2010-01-05 01:24:18 +0000 | [diff] [blame] | 244 | SelectCALL(N); | 
| Evan Cheng | bd1c5a8 | 2006-08-11 09:08:15 +0000 | [diff] [blame] | 245 | return NULL; | 
| Andrew Lenharth | 5a99041 | 2005-10-22 22:06:58 +0000 | [diff] [blame] | 246 |  | 
| Andrew Lenharth | 794f158 | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 247 | case ISD::FrameIndex: { | 
| Andrew Lenharth | 0294e33 | 2005-11-22 04:20:06 +0000 | [diff] [blame] | 248 | int FI = cast<FrameIndexSDNode>(N)->getIndex(); | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 249 | return CurDAG->SelectNodeTo(N, Alpha::LDA, MVT::i64, | 
|  | 250 | CurDAG->getTargetFrameIndex(FI, MVT::i32), | 
| Evan Cheng | 34b70ee | 2006-08-26 08:00:10 +0000 | [diff] [blame] | 251 | getI64Imm(0)); | 
| Andrew Lenharth | 794f158 | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 252 | } | 
| Dan Gohman | d5ca7064 | 2009-06-03 20:30:14 +0000 | [diff] [blame] | 253 | case ISD::GLOBAL_OFFSET_TABLE: | 
|  | 254 | return getGlobalBaseReg(); | 
|  | 255 | case AlphaISD::GlobalRetAddr: | 
|  | 256 | return getGlobalRetAddr(); | 
| Andrew Lenharth | 4621488 | 2005-12-24 05:36:33 +0000 | [diff] [blame] | 257 |  | 
| Andrew Lenharth | 0fce613 | 2005-12-25 01:34:27 +0000 | [diff] [blame] | 258 | case AlphaISD::DivCall: { | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 259 | SDValue Chain = CurDAG->getEntryNode(); | 
| Dan Gohman | ea6f91f | 2010-01-05 01:24:18 +0000 | [diff] [blame] | 260 | SDValue N0 = N->getOperand(0); | 
|  | 261 | SDValue N1 = N->getOperand(1); | 
|  | 262 | SDValue N2 = N->getOperand(2); | 
| Dale Johannesen | f08a47b | 2009-02-04 23:02:30 +0000 | [diff] [blame] | 263 | Chain = CurDAG->getCopyToReg(Chain, dl, Alpha::R24, N1, | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 264 | SDValue(0,0)); | 
| Dale Johannesen | f08a47b | 2009-02-04 23:02:30 +0000 | [diff] [blame] | 265 | Chain = CurDAG->getCopyToReg(Chain, dl, Alpha::R25, N2, | 
| Anton Korobeynikov | fb80151 | 2007-04-16 18:10:23 +0000 | [diff] [blame] | 266 | Chain.getValue(1)); | 
| Dale Johannesen | f08a47b | 2009-02-04 23:02:30 +0000 | [diff] [blame] | 267 | Chain = CurDAG->getCopyToReg(Chain, dl, Alpha::R27, N0, | 
| Anton Korobeynikov | fb80151 | 2007-04-16 18:10:23 +0000 | [diff] [blame] | 268 | Chain.getValue(1)); | 
| Evan Cheng | d1b82d8 | 2006-02-09 07:17:49 +0000 | [diff] [blame] | 269 | SDNode *CNode = | 
| Dan Gohman | 32f71d7 | 2009-09-25 18:54:59 +0000 | [diff] [blame] | 270 | CurDAG->getMachineNode(Alpha::JSRs, dl, MVT::Other, MVT::Flag, | 
|  | 271 | Chain, Chain.getValue(1)); | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 272 | Chain = CurDAG->getCopyFromReg(Chain, dl, Alpha::R27, MVT::i64, | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 273 | SDValue(CNode, 1)); | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 274 | return CurDAG->SelectNodeTo(N, Alpha::BISr, MVT::i64, Chain, Chain); | 
| Andrew Lenharth | 794f158 | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 275 | } | 
| Andrew Lenharth | 794f158 | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 276 |  | 
| Andrew Lenharth | 34380b7 | 2006-01-16 21:22:38 +0000 | [diff] [blame] | 277 | case ISD::READCYCLECOUNTER: { | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 278 | SDValue Chain = N->getOperand(0); | 
| Dan Gohman | 32f71d7 | 2009-09-25 18:54:59 +0000 | [diff] [blame] | 279 | return CurDAG->getMachineNode(Alpha::RPCC, dl, MVT::i64, MVT::Other, | 
|  | 280 | Chain); | 
| Andrew Lenharth | 34380b7 | 2006-01-16 21:22:38 +0000 | [diff] [blame] | 281 | } | 
|  | 282 |  | 
| Andrew Lenharth | 0294e33 | 2005-11-22 04:20:06 +0000 | [diff] [blame] | 283 | case ISD::Constant: { | 
| Dan Gohman | effb894 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 284 | uint64_t uval = cast<ConstantSDNode>(N)->getZExtValue(); | 
| Andrew Lenharth | 346b412 | 2006-01-06 19:41:51 +0000 | [diff] [blame] | 285 |  | 
| Evan Cheng | 6dc90ca | 2006-02-09 00:37:58 +0000 | [diff] [blame] | 286 | if (uval == 0) { | 
| Dale Johannesen | f08a47b | 2009-02-04 23:02:30 +0000 | [diff] [blame] | 287 | SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl, | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 288 | Alpha::R31, MVT::i64); | 
| Dan Gohman | ea6f91f | 2010-01-05 01:24:18 +0000 | [diff] [blame] | 289 | ReplaceUses(SDValue(N, 0), Result); | 
| Evan Cheng | bd1c5a8 | 2006-08-11 09:08:15 +0000 | [diff] [blame] | 290 | return NULL; | 
| Evan Cheng | 6dc90ca | 2006-02-09 00:37:58 +0000 | [diff] [blame] | 291 | } | 
| Andrew Lenharth | 346b412 | 2006-01-06 19:41:51 +0000 | [diff] [blame] | 292 |  | 
| Andrew Lenharth | 60ab61f | 2005-12-30 02:30:02 +0000 | [diff] [blame] | 293 | int64_t val = (int64_t)uval; | 
|  | 294 | int32_t val32 = (int32_t)val; | 
|  | 295 | if (val <= IMM_HIGH + IMM_HIGH * IMM_MULT && | 
| Anton Korobeynikov | fb80151 | 2007-04-16 18:10:23 +0000 | [diff] [blame] | 296 | val >= IMM_LOW  + IMM_LOW  * IMM_MULT) | 
| Andrew Lenharth | 60ab61f | 2005-12-30 02:30:02 +0000 | [diff] [blame] | 297 | break; //(LDAH (LDA)) | 
|  | 298 | if ((uval >> 32) == 0 && //empty upper bits | 
| Anton Korobeynikov | fb80151 | 2007-04-16 18:10:23 +0000 | [diff] [blame] | 299 | val32 <= IMM_HIGH + IMM_HIGH * IMM_MULT) | 
|  | 300 | // val32 >= IMM_LOW  + IMM_LOW  * IMM_MULT) //always true | 
| Andrew Lenharth | 60ab61f | 2005-12-30 02:30:02 +0000 | [diff] [blame] | 301 | break; //(zext (LDAH (LDA))) | 
|  | 302 | //Else use the constant pool | 
| Owen Anderson | 55f1c09 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 303 | ConstantInt *C = ConstantInt::get( | 
|  | 304 | Type::getInt64Ty(*CurDAG->getContext()), uval); | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 305 | SDValue CPI = CurDAG->getTargetConstantPool(C, MVT::i64); | 
| Dan Gohman | 32f71d7 | 2009-09-25 18:54:59 +0000 | [diff] [blame] | 306 | SDNode *Tmp = CurDAG->getMachineNode(Alpha::LDAHr, dl, MVT::i64, CPI, | 
|  | 307 | SDValue(getGlobalBaseReg(), 0)); | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 308 | return CurDAG->SelectNodeTo(N, Alpha::LDQr, MVT::i64, MVT::Other, | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 309 | CPI, SDValue(Tmp, 0), CurDAG->getEntryNode()); | 
| Andrew Lenharth | 0294e33 | 2005-11-22 04:20:06 +0000 | [diff] [blame] | 310 | } | 
| Andrew Lenharth | 64861a7 | 2008-10-07 02:10:26 +0000 | [diff] [blame] | 311 | case ISD::TargetConstantFP: | 
|  | 312 | case ISD::ConstantFP: { | 
| Chris Lattner | b5f0ba6 | 2006-01-29 06:25:22 +0000 | [diff] [blame] | 313 | ConstantFPSDNode *CN = cast<ConstantFPSDNode>(N); | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 314 | bool isDouble = N->getValueType(0) == MVT::f64; | 
|  | 315 | EVT T = isDouble ? MVT::f64 : MVT::f32; | 
| Dale Johannesen | 3cf889f | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 316 | if (CN->getValueAPF().isPosZero()) { | 
| Evan Cheng | 63d178f | 2006-08-16 07:30:09 +0000 | [diff] [blame] | 317 | return CurDAG->SelectNodeTo(N, isDouble ? Alpha::CPYST : Alpha::CPYSS, | 
|  | 318 | T, CurDAG->getRegister(Alpha::F31, T), | 
| Evan Cheng | 34b70ee | 2006-08-26 08:00:10 +0000 | [diff] [blame] | 319 | CurDAG->getRegister(Alpha::F31, T)); | 
| Dale Johannesen | 3cf889f | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 320 | } else if (CN->getValueAPF().isNegZero()) { | 
| Evan Cheng | 63d178f | 2006-08-16 07:30:09 +0000 | [diff] [blame] | 321 | return CurDAG->SelectNodeTo(N, isDouble ? Alpha::CPYSNT : Alpha::CPYSNS, | 
|  | 322 | T, CurDAG->getRegister(Alpha::F31, T), | 
| Evan Cheng | 34b70ee | 2006-08-26 08:00:10 +0000 | [diff] [blame] | 323 | CurDAG->getRegister(Alpha::F31, T)); | 
| Chris Lattner | b5f0ba6 | 2006-01-29 06:25:22 +0000 | [diff] [blame] | 324 | } else { | 
| Torok Edwin | fa04002 | 2009-07-08 19:04:27 +0000 | [diff] [blame] | 325 | llvm_report_error("Unhandled FP constant type"); | 
| Andrew Lenharth | 0294e33 | 2005-11-22 04:20:06 +0000 | [diff] [blame] | 326 | } | 
| Chris Lattner | b5f0ba6 | 2006-01-29 06:25:22 +0000 | [diff] [blame] | 327 | break; | 
|  | 328 | } | 
| Andrew Lenharth | 6db615d | 2005-11-30 07:19:56 +0000 | [diff] [blame] | 329 |  | 
|  | 330 | case ISD::SETCC: | 
| Gabor Greif | f304a7a | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 331 | if (N->getOperand(0).getNode()->getValueType(0).isFloatingPoint()) { | 
| Andrew Lenharth | 6db615d | 2005-11-30 07:19:56 +0000 | [diff] [blame] | 332 | ISD::CondCode CC = cast<CondCodeSDNode>(N->getOperand(2))->get(); | 
| Andrew Lenharth | 8a75518 | 2007-01-24 18:43:14 +0000 | [diff] [blame] | 333 |  | 
|  | 334 | unsigned Opc = Alpha::WTF; | 
| Andrew Lenharth | 6db615d | 2005-11-30 07:19:56 +0000 | [diff] [blame] | 335 | bool rev = false; | 
| Andrew Lenharth | 8a75518 | 2007-01-24 18:43:14 +0000 | [diff] [blame] | 336 | bool inv = false; | 
| Andrew Lenharth | 6db615d | 2005-11-30 07:19:56 +0000 | [diff] [blame] | 337 | switch(CC) { | 
| Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 338 | default: DEBUG(N->dump(CurDAG)); llvm_unreachable("Unknown FP comparison!"); | 
| Andrew Lenharth | 8a75518 | 2007-01-24 18:43:14 +0000 | [diff] [blame] | 339 | case ISD::SETEQ: case ISD::SETOEQ: case ISD::SETUEQ: | 
| Anton Korobeynikov | fb80151 | 2007-04-16 18:10:23 +0000 | [diff] [blame] | 340 | Opc = Alpha::CMPTEQ; break; | 
| Andrew Lenharth | 8a75518 | 2007-01-24 18:43:14 +0000 | [diff] [blame] | 341 | case ISD::SETLT: case ISD::SETOLT: case ISD::SETULT: | 
| Anton Korobeynikov | fb80151 | 2007-04-16 18:10:23 +0000 | [diff] [blame] | 342 | Opc = Alpha::CMPTLT; break; | 
| Andrew Lenharth | 8a75518 | 2007-01-24 18:43:14 +0000 | [diff] [blame] | 343 | case ISD::SETLE: case ISD::SETOLE: case ISD::SETULE: | 
| Anton Korobeynikov | fb80151 | 2007-04-16 18:10:23 +0000 | [diff] [blame] | 344 | Opc = Alpha::CMPTLE; break; | 
| Andrew Lenharth | 8a75518 | 2007-01-24 18:43:14 +0000 | [diff] [blame] | 345 | case ISD::SETGT: case ISD::SETOGT: case ISD::SETUGT: | 
| Anton Korobeynikov | fb80151 | 2007-04-16 18:10:23 +0000 | [diff] [blame] | 346 | Opc = Alpha::CMPTLT; rev = true; break; | 
| Andrew Lenharth | 8a75518 | 2007-01-24 18:43:14 +0000 | [diff] [blame] | 347 | case ISD::SETGE: case ISD::SETOGE: case ISD::SETUGE: | 
| Anton Korobeynikov | fb80151 | 2007-04-16 18:10:23 +0000 | [diff] [blame] | 348 | Opc = Alpha::CMPTLE; rev = true; break; | 
| Andrew Lenharth | 8a75518 | 2007-01-24 18:43:14 +0000 | [diff] [blame] | 349 | case ISD::SETNE: case ISD::SETONE: case ISD::SETUNE: | 
| Anton Korobeynikov | fb80151 | 2007-04-16 18:10:23 +0000 | [diff] [blame] | 350 | Opc = Alpha::CMPTEQ; inv = true; break; | 
| Andrew Lenharth | 8a75518 | 2007-01-24 18:43:14 +0000 | [diff] [blame] | 351 | case ISD::SETO: | 
| Anton Korobeynikov | fb80151 | 2007-04-16 18:10:23 +0000 | [diff] [blame] | 352 | Opc = Alpha::CMPTUN; inv = true; break; | 
| Andrew Lenharth | 8a75518 | 2007-01-24 18:43:14 +0000 | [diff] [blame] | 353 | case ISD::SETUO: | 
| Anton Korobeynikov | fb80151 | 2007-04-16 18:10:23 +0000 | [diff] [blame] | 354 | Opc = Alpha::CMPTUN; break; | 
| Andrew Lenharth | 6db615d | 2005-11-30 07:19:56 +0000 | [diff] [blame] | 355 | }; | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 356 | SDValue tmp1 = N->getOperand(rev?1:0); | 
|  | 357 | SDValue tmp2 = N->getOperand(rev?0:1); | 
| Dan Gohman | 32f71d7 | 2009-09-25 18:54:59 +0000 | [diff] [blame] | 358 | SDNode *cmp = CurDAG->getMachineNode(Opc, dl, MVT::f64, tmp1, tmp2); | 
| Andrew Lenharth | 8a75518 | 2007-01-24 18:43:14 +0000 | [diff] [blame] | 359 | if (inv) | 
| Dan Gohman | 32f71d7 | 2009-09-25 18:54:59 +0000 | [diff] [blame] | 360 | cmp = CurDAG->getMachineNode(Alpha::CMPTEQ, dl, | 
|  | 361 | MVT::f64, SDValue(cmp, 0), | 
|  | 362 | CurDAG->getRegister(Alpha::F31, MVT::f64)); | 
| Andrew Lenharth | 8a75518 | 2007-01-24 18:43:14 +0000 | [diff] [blame] | 363 | switch(CC) { | 
|  | 364 | case ISD::SETUEQ: case ISD::SETULT: case ISD::SETULE: | 
|  | 365 | case ISD::SETUNE: case ISD::SETUGT: case ISD::SETUGE: | 
| Anton Korobeynikov | fb80151 | 2007-04-16 18:10:23 +0000 | [diff] [blame] | 366 | { | 
| Dan Gohman | 32f71d7 | 2009-09-25 18:54:59 +0000 | [diff] [blame] | 367 | SDNode* cmp2 = CurDAG->getMachineNode(Alpha::CMPTUN, dl, MVT::f64, | 
|  | 368 | tmp1, tmp2); | 
|  | 369 | cmp = CurDAG->getMachineNode(Alpha::ADDT, dl, MVT::f64, | 
|  | 370 | SDValue(cmp2, 0), SDValue(cmp, 0)); | 
| Anton Korobeynikov | fb80151 | 2007-04-16 18:10:23 +0000 | [diff] [blame] | 371 | break; | 
|  | 372 | } | 
| Andrew Lenharth | 8a75518 | 2007-01-24 18:43:14 +0000 | [diff] [blame] | 373 | default: break; | 
|  | 374 | } | 
|  | 375 |  | 
| Dan Gohman | 32f71d7 | 2009-09-25 18:54:59 +0000 | [diff] [blame] | 376 | SDNode* LD = CurDAG->getMachineNode(Alpha::FTOIT, dl, | 
|  | 377 | MVT::i64, SDValue(cmp, 0)); | 
|  | 378 | return CurDAG->getMachineNode(Alpha::CMPULT, dl, MVT::i64, | 
|  | 379 | CurDAG->getRegister(Alpha::R31, MVT::i64), | 
|  | 380 | SDValue(LD,0)); | 
| Andrew Lenharth | 6db615d | 2005-11-30 07:19:56 +0000 | [diff] [blame] | 381 | } | 
|  | 382 | break; | 
| Andrew Lenharth | 873ed82 | 2005-11-30 16:10:29 +0000 | [diff] [blame] | 383 |  | 
| Andrew Lenharth | a438ef0 | 2006-02-13 18:52:29 +0000 | [diff] [blame] | 384 | case ISD::AND: { | 
| Andrew Lenharth | b90055e | 2006-05-18 17:29:34 +0000 | [diff] [blame] | 385 | ConstantSDNode* SC = NULL; | 
|  | 386 | ConstantSDNode* MC = NULL; | 
| Andrew Lenharth | a438ef0 | 2006-02-13 18:52:29 +0000 | [diff] [blame] | 387 | if (N->getOperand(0).getOpcode() == ISD::SRL && | 
| Anton Korobeynikov | fb80151 | 2007-04-16 18:10:23 +0000 | [diff] [blame] | 388 | (MC = dyn_cast<ConstantSDNode>(N->getOperand(1))) && | 
|  | 389 | (SC = dyn_cast<ConstantSDNode>(N->getOperand(0).getOperand(1)))) { | 
| Dan Gohman | effb894 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 390 | uint64_t sval = SC->getZExtValue(); | 
|  | 391 | uint64_t mval = MC->getZExtValue(); | 
| Anton Korobeynikov | fb80151 | 2007-04-16 18:10:23 +0000 | [diff] [blame] | 392 | // If the result is a zap, let the autogened stuff handle it. | 
|  | 393 | if (get_zapImm(N->getOperand(0), mval)) | 
|  | 394 | break; | 
|  | 395 | // given mask X, and shift S, we want to see if there is any zap in the | 
|  | 396 | // mask if we play around with the botton S bits | 
|  | 397 | uint64_t dontcare = (~0ULL) >> (64 - sval); | 
|  | 398 | uint64_t mask = mval << sval; | 
|  | 399 |  | 
|  | 400 | if (get_zapImm(mask | dontcare)) | 
|  | 401 | mask = mask | dontcare; | 
|  | 402 |  | 
|  | 403 | if (get_zapImm(mask)) { | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 404 | SDValue Z = | 
| Dan Gohman | 32f71d7 | 2009-09-25 18:54:59 +0000 | [diff] [blame] | 405 | SDValue(CurDAG->getMachineNode(Alpha::ZAPNOTi, dl, MVT::i64, | 
|  | 406 | N->getOperand(0).getOperand(0), | 
|  | 407 | getI64Imm(get_zapImm(mask))), 0); | 
|  | 408 | return CurDAG->getMachineNode(Alpha::SRLr, dl, MVT::i64, Z, | 
|  | 409 | getI64Imm(sval)); | 
| Andrew Lenharth | a438ef0 | 2006-02-13 18:52:29 +0000 | [diff] [blame] | 410 | } | 
| Anton Korobeynikov | fb80151 | 2007-04-16 18:10:23 +0000 | [diff] [blame] | 411 | } | 
| Andrew Lenharth | a438ef0 | 2006-02-13 18:52:29 +0000 | [diff] [blame] | 412 | break; | 
|  | 413 | } | 
|  | 414 |  | 
| Andrew Lenharth | 794f158 | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 415 | } | 
| Andrew Lenharth | 873ed82 | 2005-11-30 16:10:29 +0000 | [diff] [blame] | 416 |  | 
| Dan Gohman | ea6f91f | 2010-01-05 01:24:18 +0000 | [diff] [blame] | 417 | return SelectCode(N); | 
| Andrew Lenharth | 794f158 | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 418 | } | 
|  | 419 |  | 
| Dan Gohman | ea6f91f | 2010-01-05 01:24:18 +0000 | [diff] [blame] | 420 | void AlphaDAGToDAGISel::SelectCALL(SDNode *N) { | 
| Andrew Lenharth | 0294e33 | 2005-11-22 04:20:06 +0000 | [diff] [blame] | 421 | //TODO: add flag stuff to prevent nondeturministic breakage! | 
|  | 422 |  | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 423 | SDValue Chain = N->getOperand(0); | 
|  | 424 | SDValue Addr = N->getOperand(1); | 
| Eli Friedman | 916a0f3 | 2009-07-19 01:11:32 +0000 | [diff] [blame] | 425 | SDValue InFlag = N->getOperand(N->getNumOperands() - 1); | 
| Dale Johannesen | f08a47b | 2009-02-04 23:02:30 +0000 | [diff] [blame] | 426 | DebugLoc dl = N->getDebugLoc(); | 
| Andrew Lenharth | 5a99041 | 2005-10-22 22:06:58 +0000 | [diff] [blame] | 427 |  | 
| Andrew Lenharth | f520093 | 2005-12-25 17:36:48 +0000 | [diff] [blame] | 428 | if (Addr.getOpcode() == AlphaISD::GPRelLo) { | 
| Dan Gohman | d5ca7064 | 2009-06-03 20:30:14 +0000 | [diff] [blame] | 429 | SDValue GOT = SDValue(getGlobalBaseReg(), 0); | 
| Dale Johannesen | f08a47b | 2009-02-04 23:02:30 +0000 | [diff] [blame] | 430 | Chain = CurDAG->getCopyToReg(Chain, dl, Alpha::R29, GOT, InFlag); | 
| Andrew Lenharth | f520093 | 2005-12-25 17:36:48 +0000 | [diff] [blame] | 431 | InFlag = Chain.getValue(1); | 
| Dan Gohman | 32f71d7 | 2009-09-25 18:54:59 +0000 | [diff] [blame] | 432 | Chain = SDValue(CurDAG->getMachineNode(Alpha::BSR, dl, MVT::Other, | 
|  | 433 | MVT::Flag, Addr.getOperand(0), | 
|  | 434 | Chain, InFlag), 0); | 
| Andrew Lenharth | f520093 | 2005-12-25 17:36:48 +0000 | [diff] [blame] | 435 | } else { | 
| Dale Johannesen | f08a47b | 2009-02-04 23:02:30 +0000 | [diff] [blame] | 436 | Chain = CurDAG->getCopyToReg(Chain, dl, Alpha::R27, Addr, InFlag); | 
| Andrew Lenharth | f520093 | 2005-12-25 17:36:48 +0000 | [diff] [blame] | 437 | InFlag = Chain.getValue(1); | 
| Dan Gohman | 32f71d7 | 2009-09-25 18:54:59 +0000 | [diff] [blame] | 438 | Chain = SDValue(CurDAG->getMachineNode(Alpha::JSR, dl, MVT::Other, | 
|  | 439 | MVT::Flag, Chain, InFlag), 0); | 
| Andrew Lenharth | f520093 | 2005-12-25 17:36:48 +0000 | [diff] [blame] | 440 | } | 
| Andrew Lenharth | ce68ef8 | 2005-12-01 01:53:10 +0000 | [diff] [blame] | 441 | InFlag = Chain.getValue(1); | 
|  | 442 |  | 
| Dan Gohman | ea6f91f | 2010-01-05 01:24:18 +0000 | [diff] [blame] | 443 | ReplaceUses(SDValue(N, 0), Chain); | 
|  | 444 | ReplaceUses(SDValue(N, 1), InFlag); | 
| Andrew Lenharth | 5a99041 | 2005-10-22 22:06:58 +0000 | [diff] [blame] | 445 | } | 
|  | 446 |  | 
|  | 447 |  | 
| Andrew Lenharth | 794f158 | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 448 | /// createAlphaISelDag - This pass converts a legalized DAG into a | 
|  | 449 | /// Alpha-specific DAG, ready for instruction scheduling. | 
|  | 450 | /// | 
| Dan Gohman | eabd647 | 2008-05-14 01:58:56 +0000 | [diff] [blame] | 451 | FunctionPass *llvm::createAlphaISelDag(AlphaTargetMachine &TM) { | 
| Andrew Lenharth | 794f158 | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 452 | return new AlphaDAGToDAGISel(TM); | 
|  | 453 | } |