Misha Brukman | 2a8350a | 2005-02-05 02:24:26 +0000 | [diff] [blame] | 1 | //===- AlphaISelPattern.cpp - A pattern matching inst selector for Alpha --===// |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2 | // |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 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. |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 7 | // |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines a pattern matching instruction selector for Alpha. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "Alpha.h" |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 15 | #include "AlphaRegisterInfo.h" |
Andrew Lenharth | 120ab48 | 2005-09-29 22:54:56 +0000 | [diff] [blame] | 16 | #include "AlphaTargetMachine.h" |
Andrew Lenharth | aa38ce4 | 2005-09-02 18:46:02 +0000 | [diff] [blame] | 17 | #include "AlphaISelLowering.h" |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 18 | #include "llvm/Constants.h" // FIXME: REMOVE |
| 19 | #include "llvm/Function.h" |
Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 20 | #include "llvm/Module.h" |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
| 22 | #include "llvm/CodeGen/MachineConstantPool.h" // FIXME: REMOVE |
| 23 | #include "llvm/CodeGen/MachineFunction.h" |
| 24 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 25 | #include "llvm/CodeGen/SelectionDAG.h" |
| 26 | #include "llvm/CodeGen/SelectionDAGISel.h" |
| 27 | #include "llvm/CodeGen/SSARegMap.h" |
| 28 | #include "llvm/Target/TargetData.h" |
| 29 | #include "llvm/Target/TargetLowering.h" |
| 30 | #include "llvm/Support/MathExtras.h" |
| 31 | #include "llvm/ADT/Statistic.h" |
Andrew Lenharth | 032f235 | 2005-02-22 21:59:48 +0000 | [diff] [blame] | 32 | #include "llvm/Support/Debug.h" |
Andrew Lenharth | 9576212 | 2005-03-31 21:24:06 +0000 | [diff] [blame] | 33 | #include "llvm/Support/CommandLine.h" |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 34 | #include <set> |
Andrew Lenharth | 684f229 | 2005-01-30 00:35:27 +0000 | [diff] [blame] | 35 | #include <algorithm> |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 36 | using namespace llvm; |
| 37 | |
Andrew Lenharth | 9576212 | 2005-03-31 21:24:06 +0000 | [diff] [blame] | 38 | namespace llvm { |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 39 | cl::opt<bool> EnableAlphaIDIV("enable-alpha-intfpdiv", |
Andrew Lenharth | d4653b1 | 2005-06-27 17:39:17 +0000 | [diff] [blame] | 40 | cl::desc("Use the FP div instruction for integer div when possible"), |
Andrew Lenharth | 9576212 | 2005-03-31 21:24:06 +0000 | [diff] [blame] | 41 | cl::Hidden); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 42 | cl::opt<bool> EnableAlphaCount("enable-alpha-count", |
Andrew Lenharth | d4653b1 | 2005-06-27 17:39:17 +0000 | [diff] [blame] | 43 | cl::desc("Print estimates on live ins and outs"), |
| 44 | cl::Hidden); |
Andrew Lenharth | cd7f8cf | 2005-06-06 19:03:55 +0000 | [diff] [blame] | 45 | cl::opt<bool> EnableAlphaLSMark("enable-alpha-lsmark", |
Andrew Lenharth | d4653b1 | 2005-06-27 17:39:17 +0000 | [diff] [blame] | 46 | cl::desc("Emit symbols to correlate Mem ops to LLVM Values"), |
| 47 | cl::Hidden); |
Andrew Lenharth | 9576212 | 2005-03-31 21:24:06 +0000 | [diff] [blame] | 48 | } |
| 49 | |
Andrew Lenharth | e3c8c0a4 | 2005-05-31 19:49:34 +0000 | [diff] [blame] | 50 | namespace { |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 51 | |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 52 | //===--------------------------------------------------------------------===// |
| 53 | /// ISel - Alpha specific code to select Alpha machine instructions for |
| 54 | /// SelectionDAG operations. |
| 55 | //===--------------------------------------------------------------------===// |
Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 56 | class AlphaISel : public SelectionDAGISel { |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 57 | |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 58 | /// AlphaLowering - This object fully describes how to lower LLVM code to an |
| 59 | /// Alpha-specific SelectionDAG. |
| 60 | AlphaTargetLowering AlphaLowering; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 61 | |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 62 | SelectionDAG *ISelDAG; // Hack to support us having a dag->dag transform |
| 63 | // for sdiv and udiv until it is put into the future |
| 64 | // dag combiner. |
| 65 | |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 66 | /// ExprMap - As shared expressions are codegen'd, we keep track of which |
| 67 | /// vreg the value is produced in, so we only emit one copy of each compiled |
| 68 | /// tree. |
| 69 | static const unsigned notIn = (unsigned)(-1); |
| 70 | std::map<SDOperand, unsigned> ExprMap; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 71 | |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 72 | //CCInvMap sometimes (SetNE) we have the inverse CC code for free |
| 73 | std::map<SDOperand, unsigned> CCInvMap; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 74 | |
Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 75 | int count_ins; |
| 76 | int count_outs; |
Andrew Lenharth | 500b4db | 2005-04-22 13:35:18 +0000 | [diff] [blame] | 77 | int max_depth; |
Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 78 | |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 79 | public: |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 80 | AlphaISel(TargetMachine &TM) : SelectionDAGISel(AlphaLowering), |
Andrew Lenharth | d4653b1 | 2005-06-27 17:39:17 +0000 | [diff] [blame] | 81 | AlphaLowering(TM) |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 82 | {} |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 83 | |
Chris Lattner | f519fe0 | 2005-10-29 16:45:02 +0000 | [diff] [blame] | 84 | virtual const char *getPassName() const { |
| 85 | return "Alpha Pattern Instruction Selection"; |
| 86 | } |
| 87 | |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 88 | /// InstructionSelectBasicBlock - This callback is invoked by |
| 89 | /// SelectionDAGISel when it has created a SelectionDAG for us to codegen. |
| 90 | virtual void InstructionSelectBasicBlock(SelectionDAG &DAG) { |
Andrew Lenharth | 032f235 | 2005-02-22 21:59:48 +0000 | [diff] [blame] | 91 | DEBUG(BB->dump()); |
Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 92 | count_ins = 0; |
| 93 | count_outs = 0; |
Andrew Lenharth | 500b4db | 2005-04-22 13:35:18 +0000 | [diff] [blame] | 94 | max_depth = 0; |
Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 95 | |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 96 | // Codegen the basic block. |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 97 | ISelDAG = &DAG; |
Andrew Lenharth | 500b4db | 2005-04-22 13:35:18 +0000 | [diff] [blame] | 98 | max_depth = DAG.getRoot().getNodeDepth(); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 99 | Select(DAG.getRoot()); |
Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 100 | |
Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 101 | if(EnableAlphaCount) |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 102 | std::cerr << "COUNT: " |
| 103 | << BB->getParent()->getFunction ()->getName() << " " |
| 104 | << BB->getNumber() << " " |
Andrew Lenharth | 500b4db | 2005-04-22 13:35:18 +0000 | [diff] [blame] | 105 | << max_depth << " " |
Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 106 | << count_ins << " " |
| 107 | << count_outs << "\n"; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 108 | |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 109 | // Clear state used for selection. |
| 110 | ExprMap.clear(); |
| 111 | CCInvMap.clear(); |
| 112 | } |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 113 | |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 114 | unsigned SelectExpr(SDOperand N); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 115 | void Select(SDOperand N); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 116 | |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 117 | void SelectAddr(SDOperand N, unsigned& Reg, long& offset); |
| 118 | void SelectBranchCC(SDOperand N); |
Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 119 | void MoveFP2Int(unsigned src, unsigned dst, bool isDouble); |
| 120 | void MoveInt2FP(unsigned src, unsigned dst, bool isDouble); |
Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 121 | //returns whether the sense of the comparison was inverted |
| 122 | bool SelectFPSetCC(SDOperand N, unsigned dst); |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 123 | |
| 124 | // dag -> dag expanders for integer divide by constant |
| 125 | SDOperand BuildSDIVSequence(SDOperand N); |
| 126 | SDOperand BuildUDIVSequence(SDOperand N); |
| 127 | |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 128 | }; |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 129 | } |
| 130 | |
Andrew Lenharth | d228427 | 2005-08-15 14:31:37 +0000 | [diff] [blame] | 131 | static bool isSIntImmediate(SDOperand N, int64_t& Imm) { |
| 132 | // test for constant |
| 133 | if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N)) { |
| 134 | // retrieve value |
| 135 | Imm = CN->getSignExtended(); |
| 136 | // passes muster |
| 137 | return true; |
| 138 | } |
| 139 | // not a constant |
| 140 | return false; |
| 141 | } |
| 142 | |
| 143 | // isSIntImmediateBounded - This method tests to see if a constant operand |
| 144 | // bounded s.t. low <= Imm <= high |
| 145 | // If so Imm will receive the 64 bit value. |
| 146 | static bool isSIntImmediateBounded(SDOperand N, int64_t& Imm, |
| 147 | int64_t low, int64_t high) { |
Andrew Lenharth | 035b8ab | 2005-08-17 00:47:24 +0000 | [diff] [blame] | 148 | if (isSIntImmediate(N, Imm) && Imm <= high && Imm >= low) |
Andrew Lenharth | d228427 | 2005-08-15 14:31:37 +0000 | [diff] [blame] | 149 | return true; |
| 150 | return false; |
| 151 | } |
| 152 | static bool isUIntImmediate(SDOperand N, uint64_t& Imm) { |
| 153 | // test for constant |
| 154 | if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N)) { |
| 155 | // retrieve value |
| 156 | Imm = (uint64_t)CN->getValue(); |
| 157 | // passes muster |
| 158 | return true; |
| 159 | } |
| 160 | // not a constant |
| 161 | return false; |
| 162 | } |
| 163 | |
| 164 | static bool isUIntImmediateBounded(SDOperand N, uint64_t& Imm, |
| 165 | uint64_t low, uint64_t high) { |
Andrew Lenharth | 035b8ab | 2005-08-17 00:47:24 +0000 | [diff] [blame] | 166 | if (isUIntImmediate(N, Imm) && Imm <= high && Imm >= low) |
Andrew Lenharth | d228427 | 2005-08-15 14:31:37 +0000 | [diff] [blame] | 167 | return true; |
| 168 | return false; |
| 169 | } |
| 170 | |
Andrew Lenharth | 06ef884 | 2005-06-29 18:54:02 +0000 | [diff] [blame] | 171 | static void getValueInfo(const Value* v, int& type, int& fun, int& offset) |
Andrew Lenharth | cd7f8cf | 2005-06-06 19:03:55 +0000 | [diff] [blame] | 172 | { |
Andrew Lenharth | fec0e40 | 2005-07-12 04:20:52 +0000 | [diff] [blame] | 173 | fun = type = offset = 0; |
Andrew Lenharth | 06ef884 | 2005-06-29 18:54:02 +0000 | [diff] [blame] | 174 | if (v == NULL) { |
| 175 | type = 0; |
Andrew Lenharth | 06ef884 | 2005-06-29 18:54:02 +0000 | [diff] [blame] | 176 | } else if (const GlobalValue* GV = dyn_cast<GlobalValue>(v)) { |
| 177 | type = 1; |
Andrew Lenharth | 06ef884 | 2005-06-29 18:54:02 +0000 | [diff] [blame] | 178 | const Module* M = GV->getParent(); |
Andrew Lenharth | fec0e40 | 2005-07-12 04:20:52 +0000 | [diff] [blame] | 179 | for(Module::const_global_iterator ii = M->global_begin(); &*ii != GV; ++ii) |
| 180 | ++offset; |
Andrew Lenharth | 06ef884 | 2005-06-29 18:54:02 +0000 | [diff] [blame] | 181 | } else if (const Argument* Arg = dyn_cast<Argument>(v)) { |
| 182 | type = 2; |
| 183 | const Function* F = Arg->getParent(); |
| 184 | const Module* M = F->getParent(); |
Andrew Lenharth | 06ef884 | 2005-06-29 18:54:02 +0000 | [diff] [blame] | 185 | for(Module::const_iterator ii = M->begin(); &*ii != F; ++ii) |
Andrew Lenharth | fec0e40 | 2005-07-12 04:20:52 +0000 | [diff] [blame] | 186 | ++fun; |
Andrew Lenharth | 06ef884 | 2005-06-29 18:54:02 +0000 | [diff] [blame] | 187 | for(Function::const_arg_iterator ii = F->arg_begin(); &*ii != Arg; ++ii) |
Andrew Lenharth | fec0e40 | 2005-07-12 04:20:52 +0000 | [diff] [blame] | 188 | ++offset; |
Andrew Lenharth | 06ef884 | 2005-06-29 18:54:02 +0000 | [diff] [blame] | 189 | } else if (const Instruction* I = dyn_cast<Instruction>(v)) { |
Andrew Lenharth | a48f3ce | 2005-07-07 19:52:58 +0000 | [diff] [blame] | 190 | assert(dyn_cast<PointerType>(I->getType())); |
Andrew Lenharth | 06ef884 | 2005-06-29 18:54:02 +0000 | [diff] [blame] | 191 | type = 3; |
| 192 | const BasicBlock* bb = I->getParent(); |
| 193 | const Function* F = bb->getParent(); |
| 194 | const Module* M = F->getParent(); |
Andrew Lenharth | 06ef884 | 2005-06-29 18:54:02 +0000 | [diff] [blame] | 195 | for(Module::const_iterator ii = M->begin(); &*ii != F; ++ii) |
Andrew Lenharth | fec0e40 | 2005-07-12 04:20:52 +0000 | [diff] [blame] | 196 | ++fun; |
Andrew Lenharth | 06ef884 | 2005-06-29 18:54:02 +0000 | [diff] [blame] | 197 | for(Function::const_iterator ii = F->begin(); &*ii != bb; ++ii) |
Andrew Lenharth | fec0e40 | 2005-07-12 04:20:52 +0000 | [diff] [blame] | 198 | offset += ii->size(); |
Andrew Lenharth | 06ef884 | 2005-06-29 18:54:02 +0000 | [diff] [blame] | 199 | for(BasicBlock::const_iterator ii = bb->begin(); &*ii != I; ++ii) |
Andrew Lenharth | fec0e40 | 2005-07-12 04:20:52 +0000 | [diff] [blame] | 200 | ++offset; |
Andrew Lenharth | a48f3ce | 2005-07-07 19:52:58 +0000 | [diff] [blame] | 201 | } else if (const Constant* C = dyn_cast<Constant>(v)) { |
| 202 | //Don't know how to look these up yet |
| 203 | type = 0; |
Andrew Lenharth | a48f3ce | 2005-07-07 19:52:58 +0000 | [diff] [blame] | 204 | } else { |
| 205 | assert(0 && "Error in value marking"); |
Andrew Lenharth | 06ef884 | 2005-06-29 18:54:02 +0000 | [diff] [blame] | 206 | } |
Andrew Lenharth | cf8bf38 | 2005-07-01 19:12:13 +0000 | [diff] [blame] | 207 | //type = 4: register spilling |
| 208 | //type = 5: global address loading or constant loading |
Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | static int getUID() |
| 212 | { |
| 213 | static int id = 0; |
| 214 | return ++id; |
| 215 | } |
Andrew Lenharth | cd7f8cf | 2005-06-06 19:03:55 +0000 | [diff] [blame] | 216 | |
Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 217 | //Factorize a number using the list of constants |
| 218 | static bool factorize(int v[], int res[], int size, uint64_t c) |
| 219 | { |
| 220 | bool cont = true; |
| 221 | while (c != 1 && cont) |
| 222 | { |
| 223 | cont = false; |
| 224 | for(int i = 0; i < size; ++i) |
| 225 | { |
| 226 | if (c % v[i] == 0) |
| 227 | { |
| 228 | c /= v[i]; |
| 229 | ++res[i]; |
| 230 | cont=true; |
| 231 | } |
| 232 | } |
| 233 | } |
| 234 | return c == 1; |
| 235 | } |
| 236 | |
| 237 | |
Andrew Lenharth | e87f6c3 | 2005-03-11 17:48:05 +0000 | [diff] [blame] | 238 | //These describe LDAx |
Andrew Lenharth | c051383 | 2005-03-29 19:24:04 +0000 | [diff] [blame] | 239 | static const int IMM_LOW = -32768; |
| 240 | static const int IMM_HIGH = 32767; |
Andrew Lenharth | e87f6c3 | 2005-03-11 17:48:05 +0000 | [diff] [blame] | 241 | static const int IMM_MULT = 65536; |
| 242 | |
| 243 | static long getUpper16(long l) |
| 244 | { |
| 245 | long y = l / IMM_MULT; |
| 246 | if (l % IMM_MULT > IMM_HIGH) |
| 247 | ++y; |
| 248 | return y; |
| 249 | } |
| 250 | |
| 251 | static long getLower16(long l) |
| 252 | { |
| 253 | long h = getUpper16(l); |
| 254 | return l - h * IMM_MULT; |
| 255 | } |
| 256 | |
Andrew Lenharth | fe895e3 | 2005-06-27 17:15:36 +0000 | [diff] [blame] | 257 | static unsigned GetRelVersion(unsigned opcode) |
| 258 | { |
| 259 | switch (opcode) { |
| 260 | default: assert(0 && "unknown load or store"); return 0; |
| 261 | case Alpha::LDQ: return Alpha::LDQr; |
| 262 | case Alpha::LDS: return Alpha::LDSr; |
| 263 | case Alpha::LDT: return Alpha::LDTr; |
| 264 | case Alpha::LDL: return Alpha::LDLr; |
| 265 | case Alpha::LDBU: return Alpha::LDBUr; |
| 266 | case Alpha::LDWU: return Alpha::LDWUr; |
Andrew Lenharth | fce587e | 2005-06-29 00:39:17 +0000 | [diff] [blame] | 267 | case Alpha::STB: return Alpha::STBr; |
| 268 | case Alpha::STW: return Alpha::STWr; |
| 269 | case Alpha::STL: return Alpha::STLr; |
| 270 | case Alpha::STQ: return Alpha::STQr; |
| 271 | case Alpha::STS: return Alpha::STSr; |
| 272 | case Alpha::STT: return Alpha::STTr; |
| 273 | |
Andrew Lenharth | fe895e3 | 2005-06-27 17:15:36 +0000 | [diff] [blame] | 274 | } |
| 275 | } |
Andrew Lenharth | 6583890 | 2005-02-06 16:22:15 +0000 | [diff] [blame] | 276 | |
Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 277 | void AlphaISel::MoveFP2Int(unsigned src, unsigned dst, bool isDouble) |
Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 278 | { |
Andrew Lenharth | 4052f02 | 2005-11-22 20:59:00 +0000 | [diff] [blame] | 279 | unsigned Opc = Alpha::WTF; |
Andrew Lenharth | 120ab48 | 2005-09-29 22:54:56 +0000 | [diff] [blame] | 280 | if (TLI.getTargetMachine().getSubtarget<AlphaSubtarget>().hasF2I()) { |
Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 281 | Opc = isDouble ? Alpha::FTOIT : Alpha::FTOIS; |
Andrew Lenharth | 98169be | 2005-07-28 18:14:47 +0000 | [diff] [blame] | 282 | BuildMI(BB, Opc, 1, dst).addReg(src).addReg(Alpha::F31); |
Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 283 | } else { |
| 284 | //The hard way: |
| 285 | // Spill the integer to memory and reload it from there. |
| 286 | unsigned Size = MVT::getSizeInBits(MVT::f64)/8; |
| 287 | MachineFunction *F = BB->getParent(); |
| 288 | int FrameIdx = F->getFrameInfo()->CreateStackObject(Size, 8); |
| 289 | |
Andrew Lenharth | cf8bf38 | 2005-07-01 19:12:13 +0000 | [diff] [blame] | 290 | if (EnableAlphaLSMark) |
| 291 | BuildMI(BB, Alpha::MEMLABEL, 4).addImm(4).addImm(0).addImm(0) |
| 292 | .addImm(getUID()); |
Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 293 | Opc = isDouble ? Alpha::STT : Alpha::STS; |
| 294 | BuildMI(BB, Opc, 3).addReg(src).addFrameIndex(FrameIdx).addReg(Alpha::F31); |
Andrew Lenharth | cf8bf38 | 2005-07-01 19:12:13 +0000 | [diff] [blame] | 295 | |
| 296 | if (EnableAlphaLSMark) |
| 297 | BuildMI(BB, Alpha::MEMLABEL, 4).addImm(4).addImm(0).addImm(0) |
| 298 | .addImm(getUID()); |
Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 299 | Opc = isDouble ? Alpha::LDQ : Alpha::LDL; |
| 300 | BuildMI(BB, Alpha::LDQ, 2, dst).addFrameIndex(FrameIdx).addReg(Alpha::F31); |
| 301 | } |
| 302 | } |
| 303 | |
Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 304 | void AlphaISel::MoveInt2FP(unsigned src, unsigned dst, bool isDouble) |
Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 305 | { |
Andrew Lenharth | 4052f02 | 2005-11-22 20:59:00 +0000 | [diff] [blame] | 306 | unsigned Opc = Alpha::WTF; |
Andrew Lenharth | 120ab48 | 2005-09-29 22:54:56 +0000 | [diff] [blame] | 307 | if (TLI.getTargetMachine().getSubtarget<AlphaSubtarget>().hasF2I()) { |
Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 308 | Opc = isDouble?Alpha::ITOFT:Alpha::ITOFS; |
Andrew Lenharth | 98169be | 2005-07-28 18:14:47 +0000 | [diff] [blame] | 309 | BuildMI(BB, Opc, 1, dst).addReg(src).addReg(Alpha::R31); |
Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 310 | } else { |
| 311 | //The hard way: |
| 312 | // Spill the integer to memory and reload it from there. |
| 313 | unsigned Size = MVT::getSizeInBits(MVT::f64)/8; |
| 314 | MachineFunction *F = BB->getParent(); |
| 315 | int FrameIdx = F->getFrameInfo()->CreateStackObject(Size, 8); |
| 316 | |
Andrew Lenharth | cf8bf38 | 2005-07-01 19:12:13 +0000 | [diff] [blame] | 317 | if (EnableAlphaLSMark) |
| 318 | BuildMI(BB, Alpha::MEMLABEL, 4).addImm(4).addImm(0).addImm(0) |
| 319 | .addImm(getUID()); |
Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 320 | Opc = isDouble ? Alpha::STQ : Alpha::STL; |
| 321 | BuildMI(BB, Opc, 3).addReg(src).addFrameIndex(FrameIdx).addReg(Alpha::F31); |
Andrew Lenharth | cf8bf38 | 2005-07-01 19:12:13 +0000 | [diff] [blame] | 322 | |
| 323 | if (EnableAlphaLSMark) |
| 324 | BuildMI(BB, Alpha::MEMLABEL, 4).addImm(4).addImm(0).addImm(0) |
| 325 | .addImm(getUID()); |
Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 326 | Opc = isDouble ? Alpha::LDT : Alpha::LDS; |
| 327 | BuildMI(BB, Opc, 2, dst).addFrameIndex(FrameIdx).addReg(Alpha::F31); |
| 328 | } |
| 329 | } |
| 330 | |
Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 331 | bool AlphaISel::SelectFPSetCC(SDOperand N, unsigned dst) |
Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 332 | { |
Chris Lattner | 88ac32c | 2005-08-09 20:21:10 +0000 | [diff] [blame] | 333 | SDNode *SetCC = N.Val; |
Andrew Lenharth | 4052f02 | 2005-11-22 20:59:00 +0000 | [diff] [blame] | 334 | unsigned Tmp1, Tmp2, Tmp3, Opc = Alpha::WTF; |
Chris Lattner | 88ac32c | 2005-08-09 20:21:10 +0000 | [diff] [blame] | 335 | ISD::CondCode CC = cast<CondCodeSDNode>(SetCC->getOperand(2))->get(); |
Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 336 | bool rev = false; |
| 337 | bool inv = false; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 338 | |
Chris Lattner | 88ac32c | 2005-08-09 20:21:10 +0000 | [diff] [blame] | 339 | switch (CC) { |
| 340 | default: SetCC->dump(); assert(0 && "Unknown FP comparison!"); |
Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 341 | case ISD::SETEQ: Opc = Alpha::CMPTEQ; break; |
| 342 | case ISD::SETLT: Opc = Alpha::CMPTLT; break; |
| 343 | case ISD::SETLE: Opc = Alpha::CMPTLE; break; |
| 344 | case ISD::SETGT: Opc = Alpha::CMPTLT; rev = true; break; |
| 345 | case ISD::SETGE: Opc = Alpha::CMPTLE; rev = true; break; |
| 346 | case ISD::SETNE: Opc = Alpha::CMPTEQ; inv = true; break; |
| 347 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 348 | |
Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 349 | ConstantFPSDNode *CN; |
| 350 | if ((CN = dyn_cast<ConstantFPSDNode>(SetCC->getOperand(0))) |
| 351 | && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0))) |
| 352 | Tmp1 = Alpha::F31; |
| 353 | else |
| 354 | Tmp1 = SelectExpr(N.getOperand(0)); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 355 | |
Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 356 | if ((CN = dyn_cast<ConstantFPSDNode>(SetCC->getOperand(1))) |
| 357 | && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0))) |
| 358 | Tmp2 = Alpha::F31; |
| 359 | else |
Chris Lattner | 9c9183a | 2005-04-30 04:44:07 +0000 | [diff] [blame] | 360 | Tmp2 = SelectExpr(N.getOperand(1)); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 361 | |
Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 362 | //Can only compare doubles, and dag won't promote for me |
| 363 | if (SetCC->getOperand(0).getValueType() == MVT::f32) |
Andrew Lenharth | 72d32c2 | 2005-11-30 17:14:11 +0000 | [diff] [blame] | 364 | assert(0 && "Setcc On float?\n"); |
Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 365 | if (SetCC->getOperand(1).getValueType() == MVT::f32) |
Andrew Lenharth | 72d32c2 | 2005-11-30 17:14:11 +0000 | [diff] [blame] | 366 | assert (0 && "Setcc On float?\n"); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 367 | |
Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 368 | if (rev) std::swap(Tmp1, Tmp2); |
| 369 | //do the comparison |
| 370 | BuildMI(BB, Opc, 2, dst).addReg(Tmp1).addReg(Tmp2); |
| 371 | return inv; |
| 372 | } |
| 373 | |
Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 374 | //Check to see if the load is a constant offset from a base register |
Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 375 | void AlphaISel::SelectAddr(SDOperand N, unsigned& Reg, long& offset) |
Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 376 | { |
| 377 | unsigned opcode = N.getOpcode(); |
Andrew Lenharth | 694c298 | 2005-06-26 23:01:11 +0000 | [diff] [blame] | 378 | if (opcode == ISD::ADD && N.getOperand(1).getOpcode() == ISD::Constant && |
| 379 | cast<ConstantSDNode>(N.getOperand(1))->getValue() <= 32767) |
| 380 | { //Normal imm add |
| 381 | Reg = SelectExpr(N.getOperand(0)); |
| 382 | offset = cast<ConstantSDNode>(N.getOperand(1))->getValue(); |
| 383 | return; |
Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 384 | } |
| 385 | Reg = SelectExpr(N); |
| 386 | offset = 0; |
| 387 | return; |
| 388 | } |
| 389 | |
Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 390 | void AlphaISel::SelectBranchCC(SDOperand N) |
Andrew Lenharth | 445171a | 2005-02-08 00:40:03 +0000 | [diff] [blame] | 391 | { |
| 392 | assert(N.getOpcode() == ISD::BRCOND && "Not a BranchCC???"); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 393 | MachineBasicBlock *Dest = |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 394 | cast<BasicBlockSDNode>(N.getOperand(2))->getBasicBlock(); |
| 395 | unsigned Opc = Alpha::WTF; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 396 | |
Andrew Lenharth | 445171a | 2005-02-08 00:40:03 +0000 | [diff] [blame] | 397 | Select(N.getOperand(0)); //chain |
| 398 | SDOperand CC = N.getOperand(1); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 399 | |
Andrew Lenharth | 445171a | 2005-02-08 00:40:03 +0000 | [diff] [blame] | 400 | if (CC.getOpcode() == ISD::SETCC) |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 401 | { |
Chris Lattner | 88ac32c | 2005-08-09 20:21:10 +0000 | [diff] [blame] | 402 | ISD::CondCode cCode= cast<CondCodeSDNode>(CC.getOperand(2))->get(); |
| 403 | if (MVT::isInteger(CC.getOperand(0).getValueType())) { |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 404 | //Dropping the CC is only useful if we are comparing to 0 |
Chris Lattner | 88ac32c | 2005-08-09 20:21:10 +0000 | [diff] [blame] | 405 | bool RightZero = CC.getOperand(1).getOpcode() == ISD::Constant && |
| 406 | cast<ConstantSDNode>(CC.getOperand(1))->getValue() == 0; |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 407 | bool isNE = false; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 408 | |
Andrew Lenharth | 63b720a | 2005-04-03 20:35:21 +0000 | [diff] [blame] | 409 | //Fix up CC |
Andrew Lenharth | 63b720a | 2005-04-03 20:35:21 +0000 | [diff] [blame] | 410 | if(cCode == ISD::SETNE) |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 411 | isNE = true; |
Andrew Lenharth | 445171a | 2005-02-08 00:40:03 +0000 | [diff] [blame] | 412 | |
Andrew Lenharth | 694c298 | 2005-06-26 23:01:11 +0000 | [diff] [blame] | 413 | if (RightZero) { |
Andrew Lenharth | 09552bf | 2005-06-08 18:02:21 +0000 | [diff] [blame] | 414 | switch (cCode) { |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 415 | default: CC.Val->dump(); assert(0 && "Unknown integer comparison!"); |
| 416 | case ISD::SETEQ: Opc = Alpha::BEQ; break; |
| 417 | case ISD::SETLT: Opc = Alpha::BLT; break; |
| 418 | case ISD::SETLE: Opc = Alpha::BLE; break; |
| 419 | case ISD::SETGT: Opc = Alpha::BGT; break; |
| 420 | case ISD::SETGE: Opc = Alpha::BGE; break; |
| 421 | case ISD::SETULT: assert(0 && "x (unsigned) < 0 is never true"); break; |
| 422 | case ISD::SETUGT: Opc = Alpha::BNE; break; |
Andrew Lenharth | d4653b1 | 2005-06-27 17:39:17 +0000 | [diff] [blame] | 423 | //Technically you could have this CC |
| 424 | case ISD::SETULE: Opc = Alpha::BEQ; break; |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 425 | case ISD::SETUGE: assert(0 && "x (unsgined >= 0 is always true"); break; |
| 426 | case ISD::SETNE: Opc = Alpha::BNE; break; |
| 427 | } |
Chris Lattner | 88ac32c | 2005-08-09 20:21:10 +0000 | [diff] [blame] | 428 | unsigned Tmp1 = SelectExpr(CC.getOperand(0)); //Cond |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 429 | BuildMI(BB, Opc, 2).addReg(Tmp1).addMBB(Dest); |
| 430 | return; |
| 431 | } else { |
| 432 | unsigned Tmp1 = SelectExpr(CC); |
| 433 | if (isNE) |
| 434 | BuildMI(BB, Alpha::BEQ, 2).addReg(CCInvMap[CC]).addMBB(Dest); |
| 435 | else |
| 436 | BuildMI(BB, Alpha::BNE, 2).addReg(Tmp1).addMBB(Dest); |
Andrew Lenharth | 445171a | 2005-02-08 00:40:03 +0000 | [diff] [blame] | 437 | return; |
| 438 | } |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 439 | } else { //FP |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 440 | //Any comparison between 2 values should be codegened as an folded |
Andrew Lenharth | d4653b1 | 2005-06-27 17:39:17 +0000 | [diff] [blame] | 441 | //branch, as moving CC to the integer register is very expensive |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 442 | //for a cmp b: c = a - b; |
| 443 | //a = b: c = 0 |
| 444 | //a < b: c < 0 |
| 445 | //a > b: c > 0 |
Andrew Lenharth | 2b6c4f5 | 2005-02-25 22:55:15 +0000 | [diff] [blame] | 446 | |
| 447 | bool invTest = false; |
| 448 | unsigned Tmp3; |
| 449 | |
| 450 | ConstantFPSDNode *CN; |
Chris Lattner | 88ac32c | 2005-08-09 20:21:10 +0000 | [diff] [blame] | 451 | if ((CN = dyn_cast<ConstantFPSDNode>(CC.getOperand(1))) |
Andrew Lenharth | 2b6c4f5 | 2005-02-25 22:55:15 +0000 | [diff] [blame] | 452 | && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0))) |
Chris Lattner | 88ac32c | 2005-08-09 20:21:10 +0000 | [diff] [blame] | 453 | Tmp3 = SelectExpr(CC.getOperand(0)); |
| 454 | else if ((CN = dyn_cast<ConstantFPSDNode>(CC.getOperand(0))) |
Andrew Lenharth | 2b6c4f5 | 2005-02-25 22:55:15 +0000 | [diff] [blame] | 455 | && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0))) |
| 456 | { |
Chris Lattner | 88ac32c | 2005-08-09 20:21:10 +0000 | [diff] [blame] | 457 | Tmp3 = SelectExpr(CC.getOperand(1)); |
Andrew Lenharth | 2b6c4f5 | 2005-02-25 22:55:15 +0000 | [diff] [blame] | 458 | invTest = true; |
| 459 | } |
| 460 | else |
| 461 | { |
Chris Lattner | 88ac32c | 2005-08-09 20:21:10 +0000 | [diff] [blame] | 462 | unsigned Tmp1 = SelectExpr(CC.getOperand(0)); |
| 463 | unsigned Tmp2 = SelectExpr(CC.getOperand(1)); |
| 464 | bool isD = CC.getOperand(0).getValueType() == MVT::f64; |
Andrew Lenharth | 2b6c4f5 | 2005-02-25 22:55:15 +0000 | [diff] [blame] | 465 | Tmp3 = MakeReg(isD ? MVT::f64 : MVT::f32); |
| 466 | BuildMI(BB, isD ? Alpha::SUBT : Alpha::SUBS, 2, Tmp3) |
| 467 | .addReg(Tmp1).addReg(Tmp2); |
| 468 | } |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 469 | |
Chris Lattner | 88ac32c | 2005-08-09 20:21:10 +0000 | [diff] [blame] | 470 | switch (cCode) { |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 471 | default: CC.Val->dump(); assert(0 && "Unknown FP comparison!"); |
Andrew Lenharth | 2b6c4f5 | 2005-02-25 22:55:15 +0000 | [diff] [blame] | 472 | case ISD::SETEQ: Opc = invTest ? Alpha::FBNE : Alpha::FBEQ; break; |
| 473 | case ISD::SETLT: Opc = invTest ? Alpha::FBGT : Alpha::FBLT; break; |
| 474 | case ISD::SETLE: Opc = invTest ? Alpha::FBGE : Alpha::FBLE; break; |
| 475 | case ISD::SETGT: Opc = invTest ? Alpha::FBLT : Alpha::FBGT; break; |
| 476 | case ISD::SETGE: Opc = invTest ? Alpha::FBLE : Alpha::FBGE; break; |
| 477 | case ISD::SETNE: Opc = invTest ? Alpha::FBEQ : Alpha::FBNE; break; |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 478 | } |
| 479 | BuildMI(BB, Opc, 2).addReg(Tmp3).addMBB(Dest); |
Andrew Lenharth | 445171a | 2005-02-08 00:40:03 +0000 | [diff] [blame] | 480 | return; |
| 481 | } |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 482 | abort(); //Should never be reached |
| 483 | } else { |
| 484 | //Giveup and do the stupid thing |
| 485 | unsigned Tmp1 = SelectExpr(CC); |
| 486 | BuildMI(BB, Alpha::BNE, 2).addReg(Tmp1).addMBB(Dest); |
| 487 | return; |
| 488 | } |
Andrew Lenharth | 445171a | 2005-02-08 00:40:03 +0000 | [diff] [blame] | 489 | abort(); //Should never be reached |
| 490 | } |
| 491 | |
Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 492 | unsigned AlphaISel::SelectExpr(SDOperand N) { |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 493 | unsigned Result; |
Andrew Lenharth | 2966e84 | 2005-04-07 18:15:28 +0000 | [diff] [blame] | 494 | unsigned Tmp1, Tmp2 = 0, Tmp3; |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 495 | unsigned Opc = 0; |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 496 | unsigned opcode = N.getOpcode(); |
Chris Lattner | d2fc54e | 2005-10-21 16:01:26 +0000 | [diff] [blame] | 497 | int64_t SImm = 0; |
Andrew Lenharth | d228427 | 2005-08-15 14:31:37 +0000 | [diff] [blame] | 498 | uint64_t UImm; |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 499 | |
| 500 | SDNode *Node = N.Val; |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 501 | MVT::ValueType DestType = N.getValueType(); |
Andrew Lenharth | f4da945 | 2005-06-29 12:49:51 +0000 | [diff] [blame] | 502 | bool isFP = DestType == MVT::f64 || DestType == MVT::f32; |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 503 | |
| 504 | unsigned &Reg = ExprMap[N]; |
| 505 | if (Reg) return Reg; |
| 506 | |
Andrew Lenharth | 46a776e | 2005-09-06 17:00:23 +0000 | [diff] [blame] | 507 | switch(N.getOpcode()) { |
| 508 | default: |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 509 | Reg = Result = (N.getValueType() != MVT::Other) ? |
Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 510 | MakeReg(N.getValueType()) : notIn; |
Andrew Lenharth | 46a776e | 2005-09-06 17:00:23 +0000 | [diff] [blame] | 511 | break; |
| 512 | case ISD::AssertSext: |
| 513 | case ISD::AssertZext: |
| 514 | return Reg = SelectExpr(N.getOperand(0)); |
| 515 | case ISD::CALL: |
| 516 | case ISD::TAILCALL: |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 517 | // If this is a call instruction, make sure to prepare ALL of the result |
| 518 | // values as well as the chain. |
| 519 | if (Node->getNumValues() == 1) |
Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 520 | Reg = Result = notIn; // Void call, just a chain. |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 521 | else { |
| 522 | Result = MakeReg(Node->getValueType(0)); |
| 523 | ExprMap[N.getValue(0)] = Result; |
| 524 | for (unsigned i = 1, e = N.Val->getNumValues()-1; i != e; ++i) |
| 525 | ExprMap[N.getValue(i)] = MakeReg(Node->getValueType(i)); |
Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 526 | ExprMap[SDOperand(Node, Node->getNumValues()-1)] = notIn; |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 527 | } |
Andrew Lenharth | 46a776e | 2005-09-06 17:00:23 +0000 | [diff] [blame] | 528 | break; |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 529 | } |
| 530 | |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 531 | switch (opcode) { |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 532 | default: |
| 533 | Node->dump(); |
| 534 | assert(0 && "Node not handled!\n"); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 535 | |
Andrew Lenharth | 51b8d54 | 2005-11-11 16:47:30 +0000 | [diff] [blame] | 536 | case ISD::READCYCLECOUNTER: |
| 537 | Select(N.getOperand(0)); //Select chain |
Andrew Lenharth | 2729e61 | 2005-11-11 23:02:55 +0000 | [diff] [blame] | 538 | if (Result != notIn) |
| 539 | ExprMap[N.getValue(1)] = notIn; // Generate the token |
| 540 | else |
| 541 | Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType()); |
| 542 | |
Andrew Lenharth | 51b8d54 | 2005-11-11 16:47:30 +0000 | [diff] [blame] | 543 | BuildMI(BB, Alpha::RPCC, 1, Result).addReg(Alpha::R31); |
| 544 | return Result; |
| 545 | |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 546 | case ISD::CTPOP: |
| 547 | case ISD::CTTZ: |
| 548 | case ISD::CTLZ: |
| 549 | Opc = opcode == ISD::CTPOP ? Alpha::CTPOP : |
| 550 | (opcode == ISD::CTTZ ? Alpha::CTTZ : Alpha::CTLZ); |
| 551 | Tmp1 = SelectExpr(N.getOperand(0)); |
Andrew Lenharth | 964b6aa | 2005-10-20 19:39:24 +0000 | [diff] [blame] | 552 | BuildMI(BB, Opc, 1, Result).addReg(Tmp1); |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 553 | return Result; |
| 554 | |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 555 | case ISD::MULHU: |
| 556 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 557 | Tmp2 = SelectExpr(N.getOperand(1)); |
| 558 | BuildMI(BB, Alpha::UMULH, 2, Result).addReg(Tmp1).addReg(Tmp2); |
Andrew Lenharth | 706be91 | 2005-04-07 13:55:53 +0000 | [diff] [blame] | 559 | return Result; |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 560 | case ISD::MULHS: |
| 561 | { |
| 562 | //MULHU - Ra<63>*Rb - Rb<63>*Ra |
| 563 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 564 | Tmp2 = SelectExpr(N.getOperand(1)); |
| 565 | Tmp3 = MakeReg(MVT::i64); |
| 566 | BuildMI(BB, Alpha::UMULH, 2, Tmp3).addReg(Tmp1).addReg(Tmp2); |
| 567 | unsigned V1 = MakeReg(MVT::i64); |
| 568 | unsigned V2 = MakeReg(MVT::i64); |
Andrew Lenharth | d4653b1 | 2005-06-27 17:39:17 +0000 | [diff] [blame] | 569 | BuildMI(BB, Alpha::CMOVGE, 3, V1).addReg(Tmp2).addReg(Alpha::R31) |
| 570 | .addReg(Tmp1); |
| 571 | BuildMI(BB, Alpha::CMOVGE, 3, V2).addReg(Tmp1).addReg(Alpha::R31) |
| 572 | .addReg(Tmp2); |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 573 | unsigned IRes = MakeReg(MVT::i64); |
| 574 | BuildMI(BB, Alpha::SUBQ, 2, IRes).addReg(Tmp3).addReg(V1); |
| 575 | BuildMI(BB, Alpha::SUBQ, 2, Result).addReg(IRes).addReg(V2); |
| 576 | return Result; |
| 577 | } |
Andrew Lenharth | 7332f3e | 2005-04-02 19:11:07 +0000 | [diff] [blame] | 578 | case ISD::UNDEF: { |
Andrew Lenharth | 50b3784 | 2005-11-22 04:20:06 +0000 | [diff] [blame] | 579 | Opc = isFP ? (DestType == MVT::f32 ? Alpha::IDEF_F32 : Alpha::IDEF_F64) |
| 580 | : Alpha::IDEF_I; |
| 581 | BuildMI(BB, Opc, 0, Result); |
Andrew Lenharth | 7332f3e | 2005-04-02 19:11:07 +0000 | [diff] [blame] | 582 | return Result; |
| 583 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 584 | |
Andrew Lenharth | 032f235 | 2005-02-22 21:59:48 +0000 | [diff] [blame] | 585 | case ISD::DYNAMIC_STACKALLOC: |
| 586 | // Generate both result values. |
Andrew Lenharth | 3a7118d | 2005-02-23 17:33:42 +0000 | [diff] [blame] | 587 | if (Result != notIn) |
| 588 | ExprMap[N.getValue(1)] = notIn; // Generate the token |
Andrew Lenharth | 032f235 | 2005-02-22 21:59:48 +0000 | [diff] [blame] | 589 | else |
| 590 | Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType()); |
| 591 | |
| 592 | // FIXME: We are currently ignoring the requested alignment for handling |
| 593 | // greater than the stack alignment. This will need to be revisited at some |
| 594 | // point. Align = N.getOperand(2); |
| 595 | |
| 596 | if (!isa<ConstantSDNode>(N.getOperand(2)) || |
| 597 | cast<ConstantSDNode>(N.getOperand(2))->getValue() != 0) { |
| 598 | std::cerr << "Cannot allocate stack object with greater alignment than" |
| 599 | << " the stack alignment yet!"; |
| 600 | abort(); |
| 601 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 602 | |
Andrew Lenharth | 032f235 | 2005-02-22 21:59:48 +0000 | [diff] [blame] | 603 | Select(N.getOperand(0)); |
Andrew Lenharth | d228427 | 2005-08-15 14:31:37 +0000 | [diff] [blame] | 604 | if (isSIntImmediateBounded(N.getOperand(1), SImm, 0, 32767)) |
| 605 | BuildMI(BB, Alpha::LDA, 2, Alpha::R30).addImm(-SImm).addReg(Alpha::R30); |
| 606 | else { |
Andrew Lenharth | 032f235 | 2005-02-22 21:59:48 +0000 | [diff] [blame] | 607 | Tmp1 = SelectExpr(N.getOperand(1)); |
| 608 | // Subtract size from stack pointer, thereby allocating some space. |
| 609 | BuildMI(BB, Alpha::SUBQ, 2, Alpha::R30).addReg(Alpha::R30).addReg(Tmp1); |
| 610 | } |
| 611 | |
| 612 | // Put a pointer to the space into the result register, by copying the stack |
| 613 | // pointer. |
Andrew Lenharth | 7bc4702 | 2005-02-22 23:29:25 +0000 | [diff] [blame] | 614 | BuildMI(BB, Alpha::BIS, 2, Result).addReg(Alpha::R30).addReg(Alpha::R30); |
Andrew Lenharth | 032f235 | 2005-02-22 21:59:48 +0000 | [diff] [blame] | 615 | return Result; |
| 616 | |
Andrew Lenharth | 02c318e | 2005-06-27 21:02:56 +0000 | [diff] [blame] | 617 | case ISD::ConstantPool: |
Chris Lattner | 5839bf2 | 2005-08-26 17:15:30 +0000 | [diff] [blame] | 618 | Tmp1 = BB->getParent()->getConstantPool()-> |
| 619 | getConstantPoolIndex(cast<ConstantPoolSDNode>(N)->get()); |
Andrew Lenharth | 02c318e | 2005-06-27 21:02:56 +0000 | [diff] [blame] | 620 | AlphaLowering.restoreGP(BB); |
| 621 | Tmp2 = MakeReg(MVT::i64); |
| 622 | BuildMI(BB, Alpha::LDAHr, 2, Tmp2).addConstantPoolIndex(Tmp1) |
| 623 | .addReg(Alpha::R29); |
| 624 | BuildMI(BB, Alpha::LDAr, 2, Result).addConstantPoolIndex(Tmp1) |
| 625 | .addReg(Tmp2); |
| 626 | return Result; |
Andrew Lenharth | 2c59435 | 2005-01-29 15:42:07 +0000 | [diff] [blame] | 627 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 628 | case ISD::FrameIndex: |
Andrew Lenharth | 032f235 | 2005-02-22 21:59:48 +0000 | [diff] [blame] | 629 | BuildMI(BB, Alpha::LDA, 2, Result) |
| 630 | .addFrameIndex(cast<FrameIndexSDNode>(N)->getIndex()) |
| 631 | .addReg(Alpha::F31); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 632 | return Result; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 633 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 634 | case ISD::EXTLOAD: |
Andrew Lenharth | f311e8b | 2005-02-07 05:18:02 +0000 | [diff] [blame] | 635 | case ISD::ZEXTLOAD: |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 636 | case ISD::SEXTLOAD: |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 637 | case ISD::LOAD: |
Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 638 | { |
| 639 | // Make sure we generate both values. |
| 640 | if (Result != notIn) |
| 641 | ExprMap[N.getValue(1)] = notIn; // Generate the token |
| 642 | else |
| 643 | Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType()); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 644 | |
Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 645 | SDOperand Chain = N.getOperand(0); |
| 646 | SDOperand Address = N.getOperand(1); |
| 647 | Select(Chain); |
| 648 | |
Andrew Lenharth | c7989ce | 2005-06-29 00:31:08 +0000 | [diff] [blame] | 649 | bool fpext = true; |
| 650 | |
Andrew Lenharth | 0382401 | 2005-02-07 05:55:55 +0000 | [diff] [blame] | 651 | if (opcode == ISD::LOAD) |
Andrew Lenharth | c7989ce | 2005-06-29 00:31:08 +0000 | [diff] [blame] | 652 | switch (Node->getValueType(0)) { |
| 653 | default: Node->dump(); assert(0 && "Bad load!"); |
| 654 | case MVT::i64: Opc = Alpha::LDQ; break; |
| 655 | case MVT::f64: Opc = Alpha::LDT; break; |
| 656 | case MVT::f32: Opc = Alpha::LDS; break; |
| 657 | } |
Andrew Lenharth | 0382401 | 2005-02-07 05:55:55 +0000 | [diff] [blame] | 658 | else |
Chris Lattner | bce81ae | 2005-07-10 01:56:13 +0000 | [diff] [blame] | 659 | switch (cast<VTSDNode>(Node->getOperand(3))->getVT()) { |
Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 660 | default: Node->dump(); assert(0 && "Bad sign extend!"); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 661 | case MVT::i32: Opc = Alpha::LDL; |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 662 | assert(opcode != ISD::ZEXTLOAD && "Not sext"); break; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 663 | case MVT::i16: Opc = Alpha::LDWU; |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 664 | assert(opcode != ISD::SEXTLOAD && "Not zext"); break; |
Andrew Lenharth | f311e8b | 2005-02-07 05:18:02 +0000 | [diff] [blame] | 665 | case MVT::i1: //FIXME: Treat i1 as i8 since there are problems otherwise |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 666 | case MVT::i8: Opc = Alpha::LDBU; |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 667 | assert(opcode != ISD::SEXTLOAD && "Not zext"); break; |
Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 668 | } |
Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 669 | |
Andrew Lenharth | 06ef884 | 2005-06-29 18:54:02 +0000 | [diff] [blame] | 670 | int i, j, k; |
| 671 | if (EnableAlphaLSMark) |
| 672 | getValueInfo(dyn_cast<SrcValueSDNode>(N.getOperand(2))->getValue(), |
| 673 | i, j, k); |
| 674 | |
Andrew Lenharth | 4e62951 | 2005-12-24 05:36:33 +0000 | [diff] [blame] | 675 | if (Address.getOpcode() == AlphaISD::GPRelLo) { |
| 676 | unsigned Hi = SelectExpr(Address.getOperand(1)); |
| 677 | Address = Address.getOperand(0); |
| 678 | if (GlobalAddressSDNode *GASD = dyn_cast<GlobalAddressSDNode>(Address)) { |
| 679 | if (EnableAlphaLSMark) |
| 680 | BuildMI(BB, Alpha::MEMLABEL, 4).addImm(i).addImm(j).addImm(k) |
| 681 | .addImm(getUID()); |
| 682 | BuildMI(BB, GetRelVersion(Opc), 2, Result) |
| 683 | .addGlobalAddress(GASD->getGlobal()).addReg(Hi); |
| 684 | } else if (ConstantPoolSDNode *CP = |
| 685 | dyn_cast<ConstantPoolSDNode>(Address)) { |
| 686 | unsigned CPIdx = BB->getParent()->getConstantPool()-> |
| 687 | getConstantPoolIndex(CP->get()); |
Andrew Lenharth | 4e62951 | 2005-12-24 05:36:33 +0000 | [diff] [blame] | 688 | if (EnableAlphaLSMark) |
| 689 | BuildMI(BB, Alpha::MEMLABEL, 4).addImm(i).addImm(j).addImm(k) |
| 690 | .addImm(getUID()); |
| 691 | BuildMI(BB, GetRelVersion(Opc), 2, Result) |
Andrew Lenharth | 53d8970 | 2005-12-25 01:34:27 +0000 | [diff] [blame] | 692 | .addConstantPoolIndex(CPIdx).addReg(Hi); |
Andrew Lenharth | 4e62951 | 2005-12-24 05:36:33 +0000 | [diff] [blame] | 693 | } else assert(0 && "Unknown Lo part"); |
Andrew Lenharth | c7989ce | 2005-06-29 00:31:08 +0000 | [diff] [blame] | 694 | } else if(Address.getOpcode() == ISD::FrameIndex) { |
| 695 | if (EnableAlphaLSMark) |
Andrew Lenharth | 06ef884 | 2005-06-29 18:54:02 +0000 | [diff] [blame] | 696 | BuildMI(BB, Alpha::MEMLABEL, 4).addImm(i).addImm(j).addImm(k) |
| 697 | .addImm(getUID()); |
Andrew Lenharth | 032f235 | 2005-02-22 21:59:48 +0000 | [diff] [blame] | 698 | BuildMI(BB, Opc, 2, Result) |
| 699 | .addFrameIndex(cast<FrameIndexSDNode>(Address)->getIndex()) |
| 700 | .addReg(Alpha::F31); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 701 | } else { |
| 702 | long offset; |
| 703 | SelectAddr(Address, Tmp1, offset); |
Andrew Lenharth | c7989ce | 2005-06-29 00:31:08 +0000 | [diff] [blame] | 704 | if (EnableAlphaLSMark) |
Andrew Lenharth | 06ef884 | 2005-06-29 18:54:02 +0000 | [diff] [blame] | 705 | BuildMI(BB, Alpha::MEMLABEL, 4).addImm(i).addImm(j).addImm(k) |
| 706 | .addImm(getUID()); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 707 | BuildMI(BB, Opc, 2, Result).addImm(offset).addReg(Tmp1); |
| 708 | } |
Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 709 | return Result; |
Andrew Lenharth | 2f8fb77 | 2005-01-25 00:35:34 +0000 | [diff] [blame] | 710 | } |
Andrew Lenharth | 4e62951 | 2005-12-24 05:36:33 +0000 | [diff] [blame] | 711 | case AlphaISD::GlobalBaseReg: |
| 712 | AlphaLowering.restoreGP(BB); |
| 713 | BuildMI(BB, Alpha::BIS, 2, Result).addReg(Alpha::R29).addReg(Alpha::R29); |
| 714 | return Result; |
Andrew Lenharth | 53d8970 | 2005-12-25 01:34:27 +0000 | [diff] [blame] | 715 | case AlphaISD::GPRelHi: { |
| 716 | unsigned hi = SelectExpr(N.getOperand(1)); |
Andrew Lenharth | 4e62951 | 2005-12-24 05:36:33 +0000 | [diff] [blame] | 717 | if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(N.getOperand(0))) |
| 718 | BuildMI(BB, Alpha::LDAHr, 2, Result) |
| 719 | .addConstantPoolIndex(BB->getParent()->getConstantPool()-> |
Andrew Lenharth | 53d8970 | 2005-12-25 01:34:27 +0000 | [diff] [blame] | 720 | getConstantPoolIndex(CP->get())).addReg(hi); |
Andrew Lenharth | 4e62951 | 2005-12-24 05:36:33 +0000 | [diff] [blame] | 721 | else if (GlobalAddressSDNode *GASD = |
| 722 | dyn_cast<GlobalAddressSDNode>(N.getOperand(0))) |
| 723 | BuildMI(BB, Alpha::LDAHr, 2, Result) |
Andrew Lenharth | 53d8970 | 2005-12-25 01:34:27 +0000 | [diff] [blame] | 724 | .addGlobalAddress(GASD->getGlobal()).addReg(hi); |
Andrew Lenharth | 4e62951 | 2005-12-24 05:36:33 +0000 | [diff] [blame] | 725 | else assert(0 && "unknown Hi part"); |
| 726 | return Result; |
Andrew Lenharth | 53d8970 | 2005-12-25 01:34:27 +0000 | [diff] [blame] | 727 | } |
| 728 | case AlphaISD::GPRelLo: { |
| 729 | unsigned hi = SelectExpr(N.getOperand(1)); |
Andrew Lenharth | 4e62951 | 2005-12-24 05:36:33 +0000 | [diff] [blame] | 730 | if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(N.getOperand(0))) |
| 731 | BuildMI(BB, Alpha::LDAr, 2, Result) |
| 732 | .addConstantPoolIndex(BB->getParent()->getConstantPool()-> |
Andrew Lenharth | 53d8970 | 2005-12-25 01:34:27 +0000 | [diff] [blame] | 733 | getConstantPoolIndex(CP->get())).addReg(hi); |
Andrew Lenharth | 4e62951 | 2005-12-24 05:36:33 +0000 | [diff] [blame] | 734 | else if (GlobalAddressSDNode *GASD = |
| 735 | dyn_cast<GlobalAddressSDNode>(N.getOperand(0))) |
| 736 | BuildMI(BB, Alpha::LDAr, 2, Result) |
Andrew Lenharth | 53d8970 | 2005-12-25 01:34:27 +0000 | [diff] [blame] | 737 | .addGlobalAddress(GASD->getGlobal()).addReg(hi); |
Andrew Lenharth | 4e62951 | 2005-12-24 05:36:33 +0000 | [diff] [blame] | 738 | else assert(0 && "unknown Lo part"); |
| 739 | return Result; |
Andrew Lenharth | 53d8970 | 2005-12-25 01:34:27 +0000 | [diff] [blame] | 740 | } |
Andrew Lenharth | c687b48 | 2005-12-24 08:29:32 +0000 | [diff] [blame] | 741 | case AlphaISD::RelLit: { |
Andrew Lenharth | 53d8970 | 2005-12-25 01:34:27 +0000 | [diff] [blame] | 742 | unsigned hi = SelectExpr(N.getOperand(1)); |
| 743 | if (GlobalAddressSDNode *GASD = dyn_cast<GlobalAddressSDNode>(N.getOperand(0))) |
| 744 | BuildMI(BB, Alpha::LDQl, 2, Result) |
| 745 | .addGlobalAddress(GASD->getGlobal()).addReg(hi); |
| 746 | else if (ExternalSymbolSDNode *ESSD = dyn_cast<ExternalSymbolSDNode>(N.getOperand(0))) |
| 747 | BuildMI(BB, Alpha::LDQl, 2, Result) |
| 748 | .addExternalSymbol(ESSD->getSymbol()).addReg(hi); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 749 | return Result; |
Andrew Lenharth | c687b48 | 2005-12-24 08:29:32 +0000 | [diff] [blame] | 750 | } |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 751 | |
Chris Lattner | b5d8e6e | 2005-05-13 20:29:26 +0000 | [diff] [blame] | 752 | case ISD::TAILCALL: |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 753 | case ISD::CALL: |
| 754 | { |
| 755 | Select(N.getOperand(0)); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 756 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 757 | // The chain for this call is now lowered. |
Andrew Lenharth | f3f951a | 2005-07-22 20:50:29 +0000 | [diff] [blame] | 758 | ExprMap[N.getValue(Node->getNumValues()-1)] = notIn; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 759 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 760 | //grab the arguments |
| 761 | std::vector<unsigned> argvregs; |
Andrew Lenharth | 7b2a527 | 2005-01-30 20:42:36 +0000 | [diff] [blame] | 762 | //assert(Node->getNumOperands() < 8 && "Only 6 args supported"); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 763 | for(int i = 2, e = Node->getNumOperands(); i < e; ++i) |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 764 | argvregs.push_back(SelectExpr(N.getOperand(i))); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 765 | |
Andrew Lenharth | 684f229 | 2005-01-30 00:35:27 +0000 | [diff] [blame] | 766 | //in reg args |
| 767 | for(int i = 0, e = std::min(6, (int)argvregs.size()); i < e; ++i) |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 768 | { |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 769 | unsigned args_int[] = {Alpha::R16, Alpha::R17, Alpha::R18, |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 770 | Alpha::R19, Alpha::R20, Alpha::R21}; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 771 | unsigned args_float[] = {Alpha::F16, Alpha::F17, Alpha::F18, |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 772 | Alpha::F19, Alpha::F20, Alpha::F21}; |
| 773 | switch(N.getOperand(i+2).getValueType()) { |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 774 | default: |
| 775 | Node->dump(); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 776 | N.getOperand(i).Val->dump(); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 777 | std::cerr << "Type for " << i << " is: " << |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 778 | N.getOperand(i+2).getValueType() << "\n"; |
| 779 | assert(0 && "Unknown value type for call"); |
| 780 | case MVT::i1: |
| 781 | case MVT::i8: |
| 782 | case MVT::i16: |
| 783 | case MVT::i32: |
| 784 | case MVT::i64: |
Andrew Lenharth | d4653b1 | 2005-06-27 17:39:17 +0000 | [diff] [blame] | 785 | BuildMI(BB, Alpha::BIS, 2, args_int[i]).addReg(argvregs[i]) |
| 786 | .addReg(argvregs[i]); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 787 | break; |
| 788 | case MVT::f32: |
Andrew Lenharth | 5cefc5e | 2005-11-09 19:17:08 +0000 | [diff] [blame] | 789 | BuildMI(BB, Alpha::CPYSS, 2, args_float[i]).addReg(argvregs[i]) |
| 790 | .addReg(argvregs[i]); |
| 791 | break; |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 792 | case MVT::f64: |
Andrew Lenharth | 5cefc5e | 2005-11-09 19:17:08 +0000 | [diff] [blame] | 793 | BuildMI(BB, Alpha::CPYST, 2, args_float[i]).addReg(argvregs[i]) |
Andrew Lenharth | d4653b1 | 2005-06-27 17:39:17 +0000 | [diff] [blame] | 794 | .addReg(argvregs[i]); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 795 | break; |
Andrew Lenharth | 684f229 | 2005-01-30 00:35:27 +0000 | [diff] [blame] | 796 | } |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 797 | } |
Andrew Lenharth | 684f229 | 2005-01-30 00:35:27 +0000 | [diff] [blame] | 798 | //in mem args |
| 799 | for (int i = 6, e = argvregs.size(); i < e; ++i) |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 800 | { |
| 801 | switch(N.getOperand(i+2).getValueType()) { |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 802 | default: |
| 803 | Node->dump(); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 804 | N.getOperand(i).Val->dump(); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 805 | std::cerr << "Type for " << i << " is: " << |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 806 | N.getOperand(i+2).getValueType() << "\n"; |
| 807 | assert(0 && "Unknown value type for call"); |
| 808 | case MVT::i1: |
| 809 | case MVT::i8: |
| 810 | case MVT::i16: |
| 811 | case MVT::i32: |
| 812 | case MVT::i64: |
Andrew Lenharth | d4653b1 | 2005-06-27 17:39:17 +0000 | [diff] [blame] | 813 | BuildMI(BB, Alpha::STQ, 3).addReg(argvregs[i]).addImm((i - 6) * 8) |
| 814 | .addReg(Alpha::R30); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 815 | break; |
| 816 | case MVT::f32: |
Andrew Lenharth | d4653b1 | 2005-06-27 17:39:17 +0000 | [diff] [blame] | 817 | BuildMI(BB, Alpha::STS, 3).addReg(argvregs[i]).addImm((i - 6) * 8) |
| 818 | .addReg(Alpha::R30); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 819 | break; |
| 820 | case MVT::f64: |
Andrew Lenharth | d4653b1 | 2005-06-27 17:39:17 +0000 | [diff] [blame] | 821 | BuildMI(BB, Alpha::STT, 3).addReg(argvregs[i]).addImm((i - 6) * 8) |
| 822 | .addReg(Alpha::R30); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 823 | break; |
Andrew Lenharth | 684f229 | 2005-01-30 00:35:27 +0000 | [diff] [blame] | 824 | } |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 825 | } |
Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 826 | //build the right kind of call |
Andrew Lenharth | eececba | 2005-12-25 17:36:48 +0000 | [diff] [blame^] | 827 | if (N.getOperand(1).getOpcode() == AlphaISD::GPRelLo) { |
Andrew Lenharth | cf8bf38 | 2005-07-01 19:12:13 +0000 | [diff] [blame] | 828 | //use PC relative branch call |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 829 | AlphaLowering.restoreGP(BB); |
Andrew Lenharth | eececba | 2005-12-25 17:36:48 +0000 | [diff] [blame^] | 830 | BuildMI(BB, Alpha::BSR, 1) |
| 831 | .addGlobalAddress(cast<GlobalAddressSDNode>(N.getOperand(1) |
| 832 | .getOperand(0)) |
| 833 | ->getGlobal(),true); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 834 | } else { |
| 835 | //no need to restore GP as we are doing an indirect call |
| 836 | Tmp1 = SelectExpr(N.getOperand(1)); |
| 837 | BuildMI(BB, Alpha::BIS, 2, Alpha::R27).addReg(Tmp1).addReg(Tmp1); |
Andrew Lenharth | eececba | 2005-12-25 17:36:48 +0000 | [diff] [blame^] | 838 | BuildMI(BB, Alpha::JSR, 0); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 839 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 840 | |
Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 841 | //push the result into a virtual register |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 842 | |
Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 843 | switch (Node->getValueType(0)) { |
| 844 | default: Node->dump(); assert(0 && "Unknown value type for call result!"); |
Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 845 | case MVT::Other: return notIn; |
Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 846 | case MVT::i64: |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 847 | BuildMI(BB, Alpha::BIS, 2, Result).addReg(Alpha::R0).addReg(Alpha::R0); |
| 848 | break; |
Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 849 | case MVT::f32: |
Andrew Lenharth | 5cefc5e | 2005-11-09 19:17:08 +0000 | [diff] [blame] | 850 | BuildMI(BB, Alpha::CPYSS, 2, Result).addReg(Alpha::F0).addReg(Alpha::F0); |
| 851 | break; |
| 852 | case MVT::f64: |
| 853 | BuildMI(BB, Alpha::CPYST, 2, Result).addReg(Alpha::F0).addReg(Alpha::F0); |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 854 | break; |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 855 | } |
Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 856 | return Result+N.ResNo; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 857 | } |
| 858 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 859 | case ISD::SIGN_EXTEND_INREG: |
| 860 | { |
Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 861 | //do SDIV opt for all levels of ints if not dividing by a constant |
| 862 | if (EnableAlphaIDIV && N.getOperand(0).getOpcode() == ISD::SDIV |
| 863 | && N.getOperand(0).getOperand(1).getOpcode() != ISD::Constant) |
Andrew Lenharth | dc0b71b | 2005-03-22 00:24:07 +0000 | [diff] [blame] | 864 | { |
Andrew Lenharth | dc0b71b | 2005-03-22 00:24:07 +0000 | [diff] [blame] | 865 | unsigned Tmp4 = MakeReg(MVT::f64); |
| 866 | unsigned Tmp5 = MakeReg(MVT::f64); |
| 867 | unsigned Tmp6 = MakeReg(MVT::f64); |
| 868 | unsigned Tmp7 = MakeReg(MVT::f64); |
| 869 | unsigned Tmp8 = MakeReg(MVT::f64); |
| 870 | unsigned Tmp9 = MakeReg(MVT::f64); |
Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 871 | |
| 872 | Tmp1 = SelectExpr(N.getOperand(0).getOperand(0)); |
| 873 | Tmp2 = SelectExpr(N.getOperand(0).getOperand(1)); |
| 874 | MoveInt2FP(Tmp1, Tmp4, true); |
| 875 | MoveInt2FP(Tmp2, Tmp5, true); |
Andrew Lenharth | 98169be | 2005-07-28 18:14:47 +0000 | [diff] [blame] | 876 | BuildMI(BB, Alpha::CVTQT, 1, Tmp6).addReg(Alpha::F31).addReg(Tmp4); |
| 877 | BuildMI(BB, Alpha::CVTQT, 1, Tmp7).addReg(Alpha::F31).addReg(Tmp5); |
Andrew Lenharth | dc0b71b | 2005-03-22 00:24:07 +0000 | [diff] [blame] | 878 | BuildMI(BB, Alpha::DIVT, 2, Tmp8).addReg(Tmp6).addReg(Tmp7); |
Andrew Lenharth | 98169be | 2005-07-28 18:14:47 +0000 | [diff] [blame] | 879 | BuildMI(BB, Alpha::CVTTQ, 1, Tmp9).addReg(Alpha::F31).addReg(Tmp8); |
Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 880 | MoveFP2Int(Tmp9, Result, true); |
Andrew Lenharth | dc0b71b | 2005-03-22 00:24:07 +0000 | [diff] [blame] | 881 | return Result; |
| 882 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 883 | |
Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 884 | //Alpha has instructions for a bunch of signed 32 bit stuff |
Chris Lattner | bce81ae | 2005-07-10 01:56:13 +0000 | [diff] [blame] | 885 | if(cast<VTSDNode>(Node->getOperand(1))->getVT() == MVT::i32) { |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 886 | switch (N.getOperand(0).getOpcode()) { |
| 887 | case ISD::ADD: |
| 888 | case ISD::SUB: |
| 889 | case ISD::MUL: |
| 890 | { |
| 891 | bool isAdd = N.getOperand(0).getOpcode() == ISD::ADD; |
| 892 | bool isMul = N.getOperand(0).getOpcode() == ISD::MUL; |
| 893 | //FIXME: first check for Scaled Adds and Subs! |
Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 894 | if(!isMul && N.getOperand(0).getOperand(0).getOpcode() == ISD::SHL && |
Andrew Lenharth | d228427 | 2005-08-15 14:31:37 +0000 | [diff] [blame] | 895 | isSIntImmediateBounded(N.getOperand(0).getOperand(0).getOperand(1), SImm, 2, 3)) |
Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 896 | { |
Andrew Lenharth | d228427 | 2005-08-15 14:31:37 +0000 | [diff] [blame] | 897 | bool use4 = SImm == 2; |
Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 898 | Tmp1 = SelectExpr(N.getOperand(0).getOperand(0).getOperand(0)); |
| 899 | Tmp2 = SelectExpr(N.getOperand(0).getOperand(1)); |
| 900 | BuildMI(BB, isAdd?(use4?Alpha::S4ADDL:Alpha::S8ADDL):(use4?Alpha::S4SUBL:Alpha::S8SUBL), |
| 901 | 2,Result).addReg(Tmp1).addReg(Tmp2); |
| 902 | } |
| 903 | else if(isAdd && N.getOperand(0).getOperand(1).getOpcode() == ISD::SHL && |
Andrew Lenharth | d228427 | 2005-08-15 14:31:37 +0000 | [diff] [blame] | 904 | isSIntImmediateBounded(N.getOperand(0).getOperand(1).getOperand(1), SImm, 2, 3)) |
Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 905 | { |
Andrew Lenharth | d228427 | 2005-08-15 14:31:37 +0000 | [diff] [blame] | 906 | bool use4 = SImm == 2; |
Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 907 | Tmp1 = SelectExpr(N.getOperand(0).getOperand(1).getOperand(0)); |
| 908 | Tmp2 = SelectExpr(N.getOperand(0).getOperand(0)); |
| 909 | BuildMI(BB, use4?Alpha::S4ADDL:Alpha::S8ADDL, 2,Result).addReg(Tmp1).addReg(Tmp2); |
| 910 | } |
Andrew Lenharth | d228427 | 2005-08-15 14:31:37 +0000 | [diff] [blame] | 911 | else if(isSIntImmediateBounded(N.getOperand(0).getOperand(1), SImm, 0, 255)) |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 912 | { //Normal imm add/sub |
| 913 | Opc = isAdd ? Alpha::ADDLi : (isMul ? Alpha::MULLi : Alpha::SUBLi); |
Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 914 | Tmp1 = SelectExpr(N.getOperand(0).getOperand(0)); |
Andrew Lenharth | d228427 | 2005-08-15 14:31:37 +0000 | [diff] [blame] | 915 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(SImm); |
Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 916 | } |
Andrew Lenharth | d228427 | 2005-08-15 14:31:37 +0000 | [diff] [blame] | 917 | else if(!isMul && isSIntImmediate(N.getOperand(0).getOperand(1), SImm) && |
| 918 | (((SImm << 32) >> 32) >= -255) && (((SImm << 32) >> 32) <= 0)) |
Andrew Lenharth | 6b137d8 | 2005-07-22 22:24:01 +0000 | [diff] [blame] | 919 | { //handle canonicalization |
| 920 | Opc = isAdd ? Alpha::SUBLi : Alpha::ADDLi; |
| 921 | Tmp1 = SelectExpr(N.getOperand(0).getOperand(0)); |
Andrew Lenharth | d228427 | 2005-08-15 14:31:37 +0000 | [diff] [blame] | 922 | SImm = 0 - ((SImm << 32) >> 32); |
| 923 | assert(SImm >= 0 && SImm <= 255); |
| 924 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(SImm); |
Andrew Lenharth | 6b137d8 | 2005-07-22 22:24:01 +0000 | [diff] [blame] | 925 | } |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 926 | else |
| 927 | { //Normal add/sub |
Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 928 | Opc = isAdd ? Alpha::ADDL : (isMul ? Alpha::MULL : Alpha::SUBL); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 929 | Tmp1 = SelectExpr(N.getOperand(0).getOperand(0)); |
Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 930 | Tmp2 = SelectExpr(N.getOperand(0).getOperand(1)); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 931 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 932 | } |
| 933 | return Result; |
Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 934 | } |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 935 | default: break; //Fall Though; |
| 936 | } |
| 937 | } //Every thing else fall though too, including unhandled opcodes above |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 938 | Tmp1 = SelectExpr(N.getOperand(0)); |
Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 939 | //std::cerr << "SrcT: " << MVN->getExtraValueType() << "\n"; |
Chris Lattner | bce81ae | 2005-07-10 01:56:13 +0000 | [diff] [blame] | 940 | switch(cast<VTSDNode>(Node->getOperand(1))->getVT()) { |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 941 | default: |
| 942 | Node->dump(); |
| 943 | assert(0 && "Sign Extend InReg not there yet"); |
| 944 | break; |
| 945 | case MVT::i32: |
Andrew Lenharth | 3d65d31 | 2005-01-27 03:49:45 +0000 | [diff] [blame] | 946 | { |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 947 | BuildMI(BB, Alpha::ADDLi, 2, Result).addReg(Tmp1).addImm(0); |
Andrew Lenharth | 3d65d31 | 2005-01-27 03:49:45 +0000 | [diff] [blame] | 948 | break; |
| 949 | } |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 950 | case MVT::i16: |
Andrew Lenharth | 964b6aa | 2005-10-20 19:39:24 +0000 | [diff] [blame] | 951 | BuildMI(BB, Alpha::SEXTW, 1, Result).addReg(Tmp1); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 952 | break; |
| 953 | case MVT::i8: |
Andrew Lenharth | 964b6aa | 2005-10-20 19:39:24 +0000 | [diff] [blame] | 954 | BuildMI(BB, Alpha::SEXTB, 1, Result).addReg(Tmp1); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 955 | break; |
Andrew Lenharth | ebce504 | 2005-02-12 19:35:12 +0000 | [diff] [blame] | 956 | case MVT::i1: |
| 957 | Tmp2 = MakeReg(MVT::i64); |
| 958 | BuildMI(BB, Alpha::ANDi, 2, Tmp2).addReg(Tmp1).addImm(1); |
Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 959 | BuildMI(BB, Alpha::SUBQ, 2, Result).addReg(Alpha::R31).addReg(Tmp2); |
Andrew Lenharth | ebce504 | 2005-02-12 19:35:12 +0000 | [diff] [blame] | 960 | break; |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 961 | } |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 962 | return Result; |
| 963 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 964 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 965 | case ISD::SETCC: |
Andrew Lenharth | 3d65d31 | 2005-01-27 03:49:45 +0000 | [diff] [blame] | 966 | { |
Chris Lattner | 88ac32c | 2005-08-09 20:21:10 +0000 | [diff] [blame] | 967 | ISD::CondCode CC = cast<CondCodeSDNode>(N.getOperand(2))->get(); |
| 968 | if (MVT::isInteger(N.getOperand(0).getValueType())) { |
| 969 | bool isConst = false; |
| 970 | int dir; |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 971 | |
Chris Lattner | 88ac32c | 2005-08-09 20:21:10 +0000 | [diff] [blame] | 972 | //Tmp1 = SelectExpr(N.getOperand(0)); |
Andrew Lenharth | d228427 | 2005-08-15 14:31:37 +0000 | [diff] [blame] | 973 | if(isSIntImmediate(N.getOperand(1), SImm) && SImm <= 255 && SImm >= 0) |
Chris Lattner | 88ac32c | 2005-08-09 20:21:10 +0000 | [diff] [blame] | 974 | isConst = true; |
Andrew Lenharth | 3d65d31 | 2005-01-27 03:49:45 +0000 | [diff] [blame] | 975 | |
Chris Lattner | 88ac32c | 2005-08-09 20:21:10 +0000 | [diff] [blame] | 976 | switch (CC) { |
| 977 | default: Node->dump(); assert(0 && "Unknown integer comparison!"); |
| 978 | case ISD::SETEQ: |
| 979 | Opc = isConst ? Alpha::CMPEQi : Alpha::CMPEQ; dir=1; break; |
| 980 | case ISD::SETLT: |
| 981 | Opc = isConst ? Alpha::CMPLTi : Alpha::CMPLT; dir = 1; break; |
| 982 | case ISD::SETLE: |
| 983 | Opc = isConst ? Alpha::CMPLEi : Alpha::CMPLE; dir = 1; break; |
| 984 | case ISD::SETGT: Opc = Alpha::CMPLT; dir = 2; break; |
| 985 | case ISD::SETGE: Opc = Alpha::CMPLE; dir = 2; break; |
| 986 | case ISD::SETULT: |
| 987 | Opc = isConst ? Alpha::CMPULTi : Alpha::CMPULT; dir = 1; break; |
| 988 | case ISD::SETUGT: Opc = Alpha::CMPULT; dir = 2; break; |
| 989 | case ISD::SETULE: |
| 990 | Opc = isConst ? Alpha::CMPULEi : Alpha::CMPULE; dir = 1; break; |
| 991 | case ISD::SETUGE: Opc = Alpha::CMPULE; dir = 2; break; |
| 992 | case ISD::SETNE: {//Handle this one special |
| 993 | //std::cerr << "Alpha does not have a setne.\n"; |
| 994 | //abort(); |
| 995 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 996 | Tmp2 = SelectExpr(N.getOperand(1)); |
| 997 | Tmp3 = MakeReg(MVT::i64); |
| 998 | BuildMI(BB, Alpha::CMPEQ, 2, Tmp3).addReg(Tmp1).addReg(Tmp2); |
| 999 | //Remeber we have the Inv for this CC |
| 1000 | CCInvMap[N] = Tmp3; |
| 1001 | //and invert |
| 1002 | BuildMI(BB, Alpha::CMPEQ, 2, Result).addReg(Alpha::R31).addReg(Tmp3); |
| 1003 | return Result; |
| 1004 | } |
| 1005 | } |
| 1006 | if (dir == 1) { |
| 1007 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1008 | if (isConst) { |
Andrew Lenharth | d228427 | 2005-08-15 14:31:37 +0000 | [diff] [blame] | 1009 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(SImm); |
Chris Lattner | 88ac32c | 2005-08-09 20:21:10 +0000 | [diff] [blame] | 1010 | } else { |
Andrew Lenharth | d2bb960 | 2005-01-27 07:50:35 +0000 | [diff] [blame] | 1011 | Tmp2 = SelectExpr(N.getOperand(1)); |
Andrew Lenharth | 694c298 | 2005-06-26 23:01:11 +0000 | [diff] [blame] | 1012 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2); |
Andrew Lenharth | d4bdd54 | 2005-02-05 16:41:03 +0000 | [diff] [blame] | 1013 | } |
Chris Lattner | 88ac32c | 2005-08-09 20:21:10 +0000 | [diff] [blame] | 1014 | } else { //if (dir == 2) { |
| 1015 | Tmp1 = SelectExpr(N.getOperand(1)); |
| 1016 | Tmp2 = SelectExpr(N.getOperand(0)); |
| 1017 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2); |
Andrew Lenharth | d4bdd54 | 2005-02-05 16:41:03 +0000 | [diff] [blame] | 1018 | } |
Chris Lattner | 88ac32c | 2005-08-09 20:21:10 +0000 | [diff] [blame] | 1019 | } else { |
| 1020 | //do the comparison |
| 1021 | Tmp1 = MakeReg(MVT::f64); |
| 1022 | bool inv = SelectFPSetCC(N, Tmp1); |
| 1023 | |
| 1024 | //now arrange for Result (int) to have a 1 or 0 |
| 1025 | Tmp2 = MakeReg(MVT::i64); |
| 1026 | BuildMI(BB, Alpha::ADDQi, 2, Tmp2).addReg(Alpha::R31).addImm(1); |
| 1027 | Opc = inv?Alpha::CMOVNEi_FP:Alpha::CMOVEQi_FP; |
| 1028 | BuildMI(BB, Opc, 3, Result).addReg(Tmp2).addImm(0).addReg(Tmp1); |
Andrew Lenharth | 9818c05 | 2005-02-05 13:19:12 +0000 | [diff] [blame] | 1029 | } |
Andrew Lenharth | 3d65d31 | 2005-01-27 03:49:45 +0000 | [diff] [blame] | 1030 | return Result; |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1031 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1032 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1033 | case ISD::CopyFromReg: |
| 1034 | { |
Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 1035 | ++count_ins; |
| 1036 | |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1037 | // Make sure we generate both values. |
Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 1038 | if (Result != notIn) |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1039 | ExprMap[N.getValue(1)] = notIn; // Generate the token |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1040 | else |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1041 | Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType()); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1042 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1043 | SDOperand Chain = N.getOperand(0); |
| 1044 | |
| 1045 | Select(Chain); |
Chris Lattner | 707ebc5 | 2005-08-16 21:56:37 +0000 | [diff] [blame] | 1046 | unsigned r = cast<RegisterSDNode>(Node->getOperand(1))->getReg(); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1047 | //std::cerr << "CopyFromReg " << Result << " = " << r << "\n"; |
Andrew Lenharth | 5cefc5e | 2005-11-09 19:17:08 +0000 | [diff] [blame] | 1048 | switch(N.getValue(0).getValueType()) { |
| 1049 | case MVT::f32: |
| 1050 | BuildMI(BB, Alpha::CPYSS, 2, Result).addReg(r).addReg(r); |
| 1051 | break; |
| 1052 | case MVT::f64: |
| 1053 | BuildMI(BB, Alpha::CPYST, 2, Result).addReg(r).addReg(r); |
| 1054 | break; |
| 1055 | default: |
Andrew Lenharth | c7989ce | 2005-06-29 00:31:08 +0000 | [diff] [blame] | 1056 | BuildMI(BB, Alpha::BIS, 2, Result).addReg(r).addReg(r); |
Andrew Lenharth | 5cefc5e | 2005-11-09 19:17:08 +0000 | [diff] [blame] | 1057 | break; |
| 1058 | } |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1059 | return Result; |
| 1060 | } |
| 1061 | |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1062 | //Most of the plain arithmetic and logic share the same form, and the same |
Andrew Lenharth | 2d6f022 | 2005-01-24 19:44:07 +0000 | [diff] [blame] | 1063 | //constant immediate test |
Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 1064 | case ISD::XOR: |
Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 1065 | //Match Not |
Andrew Lenharth | d228427 | 2005-08-15 14:31:37 +0000 | [diff] [blame] | 1066 | if (isSIntImmediate(N.getOperand(1), SImm) && SImm == -1) { |
| 1067 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1068 | BuildMI(BB, Alpha::ORNOT, 2, Result).addReg(Alpha::R31).addReg(Tmp1); |
| 1069 | return Result; |
| 1070 | } |
Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 1071 | //Fall through |
| 1072 | case ISD::AND: |
Andrew Lenharth | 483f22d | 2005-04-13 03:47:03 +0000 | [diff] [blame] | 1073 | //handle zap |
Andrew Lenharth | d228427 | 2005-08-15 14:31:37 +0000 | [diff] [blame] | 1074 | if (opcode == ISD::AND && isUIntImmediate(N.getOperand(1), UImm)) |
Andrew Lenharth | 483f22d | 2005-04-13 03:47:03 +0000 | [diff] [blame] | 1075 | { |
Andrew Lenharth | 483f22d | 2005-04-13 03:47:03 +0000 | [diff] [blame] | 1076 | unsigned int build = 0; |
| 1077 | for(int i = 0; i < 8; ++i) |
| 1078 | { |
Andrew Lenharth | d228427 | 2005-08-15 14:31:37 +0000 | [diff] [blame] | 1079 | if ((UImm & 0x00FF) == 0x00FF) |
Andrew Lenharth | 483f22d | 2005-04-13 03:47:03 +0000 | [diff] [blame] | 1080 | build |= 1 << i; |
Andrew Lenharth | d228427 | 2005-08-15 14:31:37 +0000 | [diff] [blame] | 1081 | else if ((UImm & 0x00FF) != 0) |
Andrew Lenharth | 483f22d | 2005-04-13 03:47:03 +0000 | [diff] [blame] | 1082 | { build = 0; break; } |
Andrew Lenharth | d228427 | 2005-08-15 14:31:37 +0000 | [diff] [blame] | 1083 | UImm >>= 8; |
Andrew Lenharth | 483f22d | 2005-04-13 03:47:03 +0000 | [diff] [blame] | 1084 | } |
| 1085 | if (build) |
| 1086 | { |
| 1087 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1088 | BuildMI(BB, Alpha::ZAPNOTi, 2, Result).addReg(Tmp1).addImm(build); |
| 1089 | return Result; |
| 1090 | } |
| 1091 | } |
Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 1092 | case ISD::OR: |
Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 1093 | //Check operand(0) == Not |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1094 | if (N.getOperand(0).getOpcode() == ISD::XOR && |
Andrew Lenharth | d228427 | 2005-08-15 14:31:37 +0000 | [diff] [blame] | 1095 | isSIntImmediate(N.getOperand(0).getOperand(1), SImm) && SImm == -1) { |
Andrew Lenharth | d4653b1 | 2005-06-27 17:39:17 +0000 | [diff] [blame] | 1096 | switch(opcode) { |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1097 | case ISD::AND: Opc = Alpha::BIC; break; |
| 1098 | case ISD::OR: Opc = Alpha::ORNOT; break; |
| 1099 | case ISD::XOR: Opc = Alpha::EQV; break; |
Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 1100 | } |
Andrew Lenharth | d4653b1 | 2005-06-27 17:39:17 +0000 | [diff] [blame] | 1101 | Tmp1 = SelectExpr(N.getOperand(1)); |
| 1102 | Tmp2 = SelectExpr(N.getOperand(0).getOperand(0)); |
| 1103 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 1104 | return Result; |
| 1105 | } |
Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 1106 | //Check operand(1) == Not |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1107 | if (N.getOperand(1).getOpcode() == ISD::XOR && |
Andrew Lenharth | d228427 | 2005-08-15 14:31:37 +0000 | [diff] [blame] | 1108 | isSIntImmediate(N.getOperand(1).getOperand(1), SImm) && SImm == -1) { |
Andrew Lenharth | d4653b1 | 2005-06-27 17:39:17 +0000 | [diff] [blame] | 1109 | switch(opcode) { |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1110 | case ISD::AND: Opc = Alpha::BIC; break; |
| 1111 | case ISD::OR: Opc = Alpha::ORNOT; break; |
| 1112 | case ISD::XOR: Opc = Alpha::EQV; break; |
Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 1113 | } |
Andrew Lenharth | d4653b1 | 2005-06-27 17:39:17 +0000 | [diff] [blame] | 1114 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1115 | Tmp2 = SelectExpr(N.getOperand(1).getOperand(0)); |
| 1116 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 1117 | return Result; |
| 1118 | } |
Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 1119 | //Fall through |
Andrew Lenharth | 2d6f022 | 2005-01-24 19:44:07 +0000 | [diff] [blame] | 1120 | case ISD::SHL: |
| 1121 | case ISD::SRL: |
Andrew Lenharth | 2c59435 | 2005-01-29 15:42:07 +0000 | [diff] [blame] | 1122 | case ISD::SRA: |
Andrew Lenharth | 2d6f022 | 2005-01-24 19:44:07 +0000 | [diff] [blame] | 1123 | case ISD::MUL: |
Andrew Lenharth | d228427 | 2005-08-15 14:31:37 +0000 | [diff] [blame] | 1124 | if(isSIntImmediateBounded(N.getOperand(1), SImm, 0, 255)) { |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1125 | switch(opcode) { |
| 1126 | case ISD::AND: Opc = Alpha::ANDi; break; |
| 1127 | case ISD::OR: Opc = Alpha::BISi; break; |
| 1128 | case ISD::XOR: Opc = Alpha::XORi; break; |
| 1129 | case ISD::SHL: Opc = Alpha::SLi; break; |
| 1130 | case ISD::SRL: Opc = Alpha::SRLi; break; |
| 1131 | case ISD::SRA: Opc = Alpha::SRAi; break; |
| 1132 | case ISD::MUL: Opc = Alpha::MULQi; break; |
| 1133 | }; |
| 1134 | Tmp1 = SelectExpr(N.getOperand(0)); |
Andrew Lenharth | d228427 | 2005-08-15 14:31:37 +0000 | [diff] [blame] | 1135 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(SImm); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1136 | } else { |
| 1137 | switch(opcode) { |
| 1138 | case ISD::AND: Opc = Alpha::AND; break; |
| 1139 | case ISD::OR: Opc = Alpha::BIS; break; |
| 1140 | case ISD::XOR: Opc = Alpha::XOR; break; |
| 1141 | case ISD::SHL: Opc = Alpha::SL; break; |
| 1142 | case ISD::SRL: Opc = Alpha::SRL; break; |
| 1143 | case ISD::SRA: Opc = Alpha::SRA; break; |
Chris Lattner | 3e2bafd | 2005-09-28 22:29:17 +0000 | [diff] [blame] | 1144 | case ISD::MUL: Opc = Alpha::MULQ; break; |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1145 | }; |
| 1146 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1147 | Tmp2 = SelectExpr(N.getOperand(1)); |
| 1148 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 1149 | } |
Andrew Lenharth | 2d6f022 | 2005-01-24 19:44:07 +0000 | [diff] [blame] | 1150 | return Result; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1151 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1152 | case ISD::ADD: |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1153 | case ISD::SUB: |
Chris Lattner | 3e2bafd | 2005-09-28 22:29:17 +0000 | [diff] [blame] | 1154 | { |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1155 | bool isAdd = opcode == ISD::ADD; |
| 1156 | |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 1157 | //first check for Scaled Adds and Subs! |
| 1158 | //Valid for add and sub |
Andrew Lenharth | d228427 | 2005-08-15 14:31:37 +0000 | [diff] [blame] | 1159 | if(N.getOperand(0).getOpcode() == ISD::SHL && |
| 1160 | isSIntImmediate(N.getOperand(0).getOperand(1), SImm) && |
| 1161 | (SImm == 2 || SImm == 3)) { |
| 1162 | bool use4 = SImm == 2; |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 1163 | Tmp2 = SelectExpr(N.getOperand(0).getOperand(0)); |
Andrew Lenharth | d228427 | 2005-08-15 14:31:37 +0000 | [diff] [blame] | 1164 | if (isSIntImmediateBounded(N.getOperand(1), SImm, 0, 255)) |
Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 1165 | BuildMI(BB, isAdd?(use4?Alpha::S4ADDQi:Alpha::S8ADDQi):(use4?Alpha::S4SUBQi:Alpha::S8SUBQi), |
Andrew Lenharth | d228427 | 2005-08-15 14:31:37 +0000 | [diff] [blame] | 1166 | 2, Result).addReg(Tmp2).addImm(SImm); |
Andrew Lenharth | f77f395 | 2005-04-06 20:59:59 +0000 | [diff] [blame] | 1167 | else { |
| 1168 | Tmp1 = SelectExpr(N.getOperand(1)); |
Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 1169 | BuildMI(BB, isAdd?(use4?Alpha::S4ADDQi:Alpha::S8ADDQi):(use4?Alpha::S4SUBQi:Alpha::S8SUBQi), |
| 1170 | 2, Result).addReg(Tmp2).addReg(Tmp1); |
Andrew Lenharth | f77f395 | 2005-04-06 20:59:59 +0000 | [diff] [blame] | 1171 | } |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 1172 | } |
| 1173 | //Position prevents subs |
Andrew Lenharth | 273a1f9 | 2005-04-07 14:18:13 +0000 | [diff] [blame] | 1174 | else if(N.getOperand(1).getOpcode() == ISD::SHL && isAdd && |
Andrew Lenharth | d228427 | 2005-08-15 14:31:37 +0000 | [diff] [blame] | 1175 | isSIntImmediate(N.getOperand(1).getOperand(1), SImm) && |
| 1176 | (SImm == 2 || SImm == 3)) { |
| 1177 | bool use4 = SImm == 2; |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 1178 | Tmp2 = SelectExpr(N.getOperand(1).getOperand(0)); |
Andrew Lenharth | d228427 | 2005-08-15 14:31:37 +0000 | [diff] [blame] | 1179 | if (isSIntImmediateBounded(N.getOperand(0), SImm, 0, 255)) |
| 1180 | BuildMI(BB, use4?Alpha::S4ADDQi:Alpha::S8ADDQi, 2, Result).addReg(Tmp2).addImm(SImm); |
Andrew Lenharth | f77f395 | 2005-04-06 20:59:59 +0000 | [diff] [blame] | 1181 | else { |
| 1182 | Tmp1 = SelectExpr(N.getOperand(0)); |
Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 1183 | BuildMI(BB, use4?Alpha::S4ADDQ:Alpha::S8ADDQ, 2, Result).addReg(Tmp2).addReg(Tmp1); |
Andrew Lenharth | f77f395 | 2005-04-06 20:59:59 +0000 | [diff] [blame] | 1184 | } |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 1185 | } |
| 1186 | //small addi |
Andrew Lenharth | d228427 | 2005-08-15 14:31:37 +0000 | [diff] [blame] | 1187 | else if(isSIntImmediateBounded(N.getOperand(1), SImm, 0, 255)) |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1188 | { //Normal imm add/sub |
| 1189 | Opc = isAdd ? Alpha::ADDQi : Alpha::SUBQi; |
| 1190 | Tmp1 = SelectExpr(N.getOperand(0)); |
Andrew Lenharth | d228427 | 2005-08-15 14:31:37 +0000 | [diff] [blame] | 1191 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(SImm); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1192 | } |
Andrew Lenharth | d228427 | 2005-08-15 14:31:37 +0000 | [diff] [blame] | 1193 | else if(isSIntImmediateBounded(N.getOperand(1), SImm, -255, 0)) |
Andrew Lenharth | 6b137d8 | 2005-07-22 22:24:01 +0000 | [diff] [blame] | 1194 | { //inverted imm add/sub |
| 1195 | Opc = isAdd ? Alpha::SUBQi : Alpha::ADDQi; |
| 1196 | Tmp1 = SelectExpr(N.getOperand(0)); |
Andrew Lenharth | d228427 | 2005-08-15 14:31:37 +0000 | [diff] [blame] | 1197 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(-SImm); |
Andrew Lenharth | 6b137d8 | 2005-07-22 22:24:01 +0000 | [diff] [blame] | 1198 | } |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 1199 | //larger addi |
Andrew Lenharth | d228427 | 2005-08-15 14:31:37 +0000 | [diff] [blame] | 1200 | else if(isSIntImmediateBounded(N.getOperand(1), SImm, -32767, 32767)) |
Andrew Lenharth | 74d00d8 | 2005-03-02 17:23:03 +0000 | [diff] [blame] | 1201 | { //LDA |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1202 | Tmp1 = SelectExpr(N.getOperand(0)); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1203 | if (!isAdd) |
Andrew Lenharth | d228427 | 2005-08-15 14:31:37 +0000 | [diff] [blame] | 1204 | SImm = -SImm; |
| 1205 | BuildMI(BB, Alpha::LDA, 2, Result).addImm(SImm).addReg(Tmp1); |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 1206 | } |
| 1207 | //give up and do the operation |
| 1208 | else { |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1209 | //Normal add/sub |
| 1210 | Opc = isAdd ? Alpha::ADDQ : Alpha::SUBQ; |
| 1211 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1212 | Tmp2 = SelectExpr(N.getOperand(1)); |
| 1213 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 1214 | } |
Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 1215 | return Result; |
| 1216 | } |
Chris Lattner | 3e2bafd | 2005-09-28 22:29:17 +0000 | [diff] [blame] | 1217 | case ISD::FADD: |
| 1218 | case ISD::FSUB: |
| 1219 | case ISD::FMUL: |
| 1220 | case ISD::FDIV: { |
| 1221 | if (opcode == ISD::FADD) |
| 1222 | Opc = DestType == MVT::f64 ? Alpha::ADDT : Alpha::ADDS; |
| 1223 | else if (opcode == ISD::FSUB) |
| 1224 | Opc = DestType == MVT::f64 ? Alpha::SUBT : Alpha::SUBS; |
| 1225 | else if (opcode == ISD::FMUL) |
| 1226 | Opc = DestType == MVT::f64 ? Alpha::MULT : Alpha::MULS; |
| 1227 | else |
| 1228 | Opc = DestType == MVT::f64 ? Alpha::DIVT : Alpha::DIVS; |
| 1229 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1230 | Tmp2 = SelectExpr(N.getOperand(1)); |
| 1231 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 1232 | return Result; |
| 1233 | } |
Andrew Lenharth | 53d8970 | 2005-12-25 01:34:27 +0000 | [diff] [blame] | 1234 | case AlphaISD::DivCall: |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1235 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1236 | Tmp2 = SelectExpr(N.getOperand(1)); |
Andrew Lenharth | 53d8970 | 2005-12-25 01:34:27 +0000 | [diff] [blame] | 1237 | Tmp3 = SelectExpr(N.getOperand(2)); |
| 1238 | BuildMI(BB, Alpha::BIS, 2, Alpha::R24).addReg(Tmp2).addReg(Tmp2); |
| 1239 | BuildMI(BB, Alpha::BIS, 2, Alpha::R25).addReg(Tmp3).addReg(Tmp3); |
| 1240 | BuildMI(BB, Alpha::BIS, 2, Alpha::R27).addReg(Tmp1).addReg(Tmp1); |
Andrew Lenharth | eececba | 2005-12-25 17:36:48 +0000 | [diff] [blame^] | 1241 | BuildMI(BB, Alpha::JSRs, 0); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1242 | BuildMI(BB, Alpha::BIS, 2, Result).addReg(Alpha::R27).addReg(Alpha::R27); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1243 | return Result; |
Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 1244 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1245 | case ISD::SELECT: |
Andrew Lenharth | f4da945 | 2005-06-29 12:49:51 +0000 | [diff] [blame] | 1246 | if (isFP) { |
| 1247 | //Tmp1 = SelectExpr(N.getOperand(0)); //Cond |
| 1248 | unsigned TV = SelectExpr(N.getOperand(1)); //Use if TRUE |
| 1249 | unsigned FV = SelectExpr(N.getOperand(2)); //Use if FALSE |
| 1250 | |
| 1251 | SDOperand CC = N.getOperand(0); |
Andrew Lenharth | f4da945 | 2005-06-29 12:49:51 +0000 | [diff] [blame] | 1252 | |
Chris Lattner | 88ac32c | 2005-08-09 20:21:10 +0000 | [diff] [blame] | 1253 | if (CC.getOpcode() == ISD::SETCC && |
| 1254 | !MVT::isInteger(CC.getOperand(0).getValueType())) { |
| 1255 | //FP Setcc -> Select yay! |
Andrew Lenharth | f4da945 | 2005-06-29 12:49:51 +0000 | [diff] [blame] | 1256 | |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 1257 | |
Andrew Lenharth | f4da945 | 2005-06-29 12:49:51 +0000 | [diff] [blame] | 1258 | //for a cmp b: c = a - b; |
| 1259 | //a = b: c = 0 |
| 1260 | //a < b: c < 0 |
| 1261 | //a > b: c > 0 |
| 1262 | |
| 1263 | bool invTest = false; |
| 1264 | unsigned Tmp3; |
Andrew Lenharth | b2156f9 | 2005-11-30 17:11:20 +0000 | [diff] [blame] | 1265 | bool isD = CC.getOperand(0).getValueType() == MVT::f64; |
Andrew Lenharth | f4da945 | 2005-06-29 12:49:51 +0000 | [diff] [blame] | 1266 | ConstantFPSDNode *CN; |
Chris Lattner | 88ac32c | 2005-08-09 20:21:10 +0000 | [diff] [blame] | 1267 | if ((CN = dyn_cast<ConstantFPSDNode>(CC.getOperand(1))) |
Andrew Lenharth | f4da945 | 2005-06-29 12:49:51 +0000 | [diff] [blame] | 1268 | && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0))) |
Chris Lattner | 88ac32c | 2005-08-09 20:21:10 +0000 | [diff] [blame] | 1269 | Tmp3 = SelectExpr(CC.getOperand(0)); |
| 1270 | else if ((CN = dyn_cast<ConstantFPSDNode>(CC.getOperand(0))) |
Andrew Lenharth | f4da945 | 2005-06-29 12:49:51 +0000 | [diff] [blame] | 1271 | && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0))) |
| 1272 | { |
Chris Lattner | 88ac32c | 2005-08-09 20:21:10 +0000 | [diff] [blame] | 1273 | Tmp3 = SelectExpr(CC.getOperand(1)); |
Andrew Lenharth | f4da945 | 2005-06-29 12:49:51 +0000 | [diff] [blame] | 1274 | invTest = true; |
| 1275 | } |
| 1276 | else |
| 1277 | { |
Chris Lattner | 88ac32c | 2005-08-09 20:21:10 +0000 | [diff] [blame] | 1278 | unsigned Tmp1 = SelectExpr(CC.getOperand(0)); |
| 1279 | unsigned Tmp2 = SelectExpr(CC.getOperand(1)); |
Andrew Lenharth | f4da945 | 2005-06-29 12:49:51 +0000 | [diff] [blame] | 1280 | Tmp3 = MakeReg(isD ? MVT::f64 : MVT::f32); |
| 1281 | BuildMI(BB, isD ? Alpha::SUBT : Alpha::SUBS, 2, Tmp3) |
| 1282 | .addReg(Tmp1).addReg(Tmp2); |
| 1283 | } |
| 1284 | |
Andrew Lenharth | b2156f9 | 2005-11-30 17:11:20 +0000 | [diff] [blame] | 1285 | if(isD) |
| 1286 | switch (cast<CondCodeSDNode>(CC.getOperand(2))->get()) { |
| 1287 | default: CC.Val->dump(); assert(0 && "Unknown FP comparison!"); |
| 1288 | case ISD::SETEQ: Opc = invTest ? Alpha::FCMOVNET : Alpha::FCMOVEQT; break; |
| 1289 | case ISD::SETLT: Opc = invTest ? Alpha::FCMOVGTT : Alpha::FCMOVLTT; break; |
| 1290 | case ISD::SETLE: Opc = invTest ? Alpha::FCMOVGET : Alpha::FCMOVLET; break; |
| 1291 | case ISD::SETGT: Opc = invTest ? Alpha::FCMOVLTT : Alpha::FCMOVGTT; break; |
| 1292 | case ISD::SETGE: Opc = invTest ? Alpha::FCMOVLET : Alpha::FCMOVGET; break; |
| 1293 | case ISD::SETNE: Opc = invTest ? Alpha::FCMOVEQT : Alpha::FCMOVNET; break; |
| 1294 | } |
| 1295 | else |
| 1296 | switch (cast<CondCodeSDNode>(CC.getOperand(2))->get()) { |
| 1297 | default: CC.Val->dump(); assert(0 && "Unknown FP comparison!"); |
| 1298 | case ISD::SETEQ: Opc = invTest ? Alpha::FCMOVNES : Alpha::FCMOVEQS; break; |
| 1299 | case ISD::SETLT: Opc = invTest ? Alpha::FCMOVGTS : Alpha::FCMOVLTS; break; |
| 1300 | case ISD::SETLE: Opc = invTest ? Alpha::FCMOVGES : Alpha::FCMOVLES; break; |
| 1301 | case ISD::SETGT: Opc = invTest ? Alpha::FCMOVLTS : Alpha::FCMOVGTS; break; |
| 1302 | case ISD::SETGE: Opc = invTest ? Alpha::FCMOVLES : Alpha::FCMOVGES; break; |
| 1303 | case ISD::SETNE: Opc = invTest ? Alpha::FCMOVEQS : Alpha::FCMOVNES; break; |
| 1304 | } |
Andrew Lenharth | f4da945 | 2005-06-29 12:49:51 +0000 | [diff] [blame] | 1305 | BuildMI(BB, Opc, 3, Result).addReg(FV).addReg(TV).addReg(Tmp3); |
| 1306 | return Result; |
| 1307 | } |
| 1308 | else |
| 1309 | { |
| 1310 | Tmp1 = SelectExpr(N.getOperand(0)); //Cond |
| 1311 | BuildMI(BB, Alpha::FCMOVEQ_INT, 3, Result).addReg(TV).addReg(FV) |
| 1312 | .addReg(Tmp1); |
| 1313 | // // Spill the cond to memory and reload it from there. |
| 1314 | // unsigned Tmp4 = MakeReg(MVT::f64); |
| 1315 | // MoveIntFP(Tmp1, Tmp4, true); |
| 1316 | // //now ideally, we don't have to do anything to the flag... |
| 1317 | // // Get the condition into the zero flag. |
| 1318 | // BuildMI(BB, Alpha::FCMOVEQ, 3, Result).addReg(TV).addReg(FV).addReg(Tmp4); |
| 1319 | return Result; |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 1320 | } |
Andrew Lenharth | f4da945 | 2005-06-29 12:49:51 +0000 | [diff] [blame] | 1321 | } else { |
Andrew Lenharth | d4653b1 | 2005-06-27 17:39:17 +0000 | [diff] [blame] | 1322 | //FIXME: look at parent to decide if intCC can be folded, or if setCC(FP) |
| 1323 | //and can save stack use |
Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 1324 | //Tmp1 = SelectExpr(N.getOperand(0)); //Cond |
Andrew Lenharth | 63b720a | 2005-04-03 20:35:21 +0000 | [diff] [blame] | 1325 | //Tmp2 = SelectExpr(N.getOperand(1)); //Use if TRUE |
| 1326 | //Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1327 | // Get the condition into the zero flag. |
Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 1328 | //BuildMI(BB, Alpha::CMOVEQ, 2, Result).addReg(Tmp2).addReg(Tmp3).addReg(Tmp1); |
Andrew Lenharth | 63b720a | 2005-04-03 20:35:21 +0000 | [diff] [blame] | 1329 | |
Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 1330 | SDOperand CC = N.getOperand(0); |
Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 1331 | |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1332 | if (CC.getOpcode() == ISD::SETCC && |
Chris Lattner | 88ac32c | 2005-08-09 20:21:10 +0000 | [diff] [blame] | 1333 | !MVT::isInteger(CC.getOperand(0).getValueType())) |
Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 1334 | { //FP Setcc -> Int Select |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1335 | Tmp1 = MakeReg(MVT::f64); |
Andrew Lenharth | 63b720a | 2005-04-03 20:35:21 +0000 | [diff] [blame] | 1336 | Tmp2 = SelectExpr(N.getOperand(1)); //Use if TRUE |
| 1337 | Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1338 | bool inv = SelectFPSetCC(CC, Tmp1); |
| 1339 | BuildMI(BB, inv?Alpha::CMOVNE_FP:Alpha::CMOVEQ_FP, 2, Result) |
| 1340 | .addReg(Tmp2).addReg(Tmp3).addReg(Tmp1); |
| 1341 | return Result; |
Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 1342 | } |
| 1343 | if (CC.getOpcode() == ISD::SETCC) { |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1344 | //Int SetCC -> Select |
| 1345 | //Dropping the CC is only useful if we are comparing to 0 |
Andrew Lenharth | d228427 | 2005-08-15 14:31:37 +0000 | [diff] [blame] | 1346 | if(isSIntImmediateBounded(CC.getOperand(1), SImm, 0, 0)) { |
Andrew Lenharth | 63b720a | 2005-04-03 20:35:21 +0000 | [diff] [blame] | 1347 | //figure out a few things |
Andrew Lenharth | d228427 | 2005-08-15 14:31:37 +0000 | [diff] [blame] | 1348 | bool useImm = isSIntImmediateBounded(N.getOperand(2), SImm, 0, 255); |
Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 1349 | |
Andrew Lenharth | 63b720a | 2005-04-03 20:35:21 +0000 | [diff] [blame] | 1350 | //Fix up CC |
Chris Lattner | 88ac32c | 2005-08-09 20:21:10 +0000 | [diff] [blame] | 1351 | ISD::CondCode cCode= cast<CondCodeSDNode>(CC.getOperand(2))->get(); |
Andrew Lenharth | 694c298 | 2005-06-26 23:01:11 +0000 | [diff] [blame] | 1352 | if (useImm) //Invert sense to get Imm field right |
Andrew Lenharth | 63b720a | 2005-04-03 20:35:21 +0000 | [diff] [blame] | 1353 | cCode = ISD::getSetCCInverse(cCode, true); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1354 | |
Andrew Lenharth | 63b720a | 2005-04-03 20:35:21 +0000 | [diff] [blame] | 1355 | //Choose the CMOV |
| 1356 | switch (cCode) { |
| 1357 | default: CC.Val->dump(); assert(0 && "Unknown integer comparison!"); |
Andrew Lenharth | d4653b1 | 2005-06-27 17:39:17 +0000 | [diff] [blame] | 1358 | case ISD::SETEQ: Opc = useImm?Alpha::CMOVEQi:Alpha::CMOVEQ; break; |
| 1359 | case ISD::SETLT: Opc = useImm?Alpha::CMOVLTi:Alpha::CMOVLT; break; |
| 1360 | case ISD::SETLE: Opc = useImm?Alpha::CMOVLEi:Alpha::CMOVLE; break; |
| 1361 | case ISD::SETGT: Opc = useImm?Alpha::CMOVGTi:Alpha::CMOVGT; break; |
| 1362 | case ISD::SETGE: Opc = useImm?Alpha::CMOVGEi:Alpha::CMOVGE; break; |
| 1363 | case ISD::SETULT: assert(0 && "unsigned < 0 is never true"); break; |
| 1364 | case ISD::SETUGT: Opc = useImm?Alpha::CMOVNEi:Alpha::CMOVNE; break; |
| 1365 | //Technically you could have this CC |
| 1366 | case ISD::SETULE: Opc = useImm?Alpha::CMOVEQi:Alpha::CMOVEQ; break; |
| 1367 | case ISD::SETUGE: assert(0 && "unsgined >= 0 is always true"); break; |
| 1368 | case ISD::SETNE: Opc = useImm?Alpha::CMOVNEi:Alpha::CMOVNE; break; |
Andrew Lenharth | 63b720a | 2005-04-03 20:35:21 +0000 | [diff] [blame] | 1369 | } |
Chris Lattner | 88ac32c | 2005-08-09 20:21:10 +0000 | [diff] [blame] | 1370 | Tmp1 = SelectExpr(CC.getOperand(0)); //Cond |
Andrew Lenharth | 63b720a | 2005-04-03 20:35:21 +0000 | [diff] [blame] | 1371 | |
Andrew Lenharth | 694c298 | 2005-06-26 23:01:11 +0000 | [diff] [blame] | 1372 | if (useImm) { |
Andrew Lenharth | 63b720a | 2005-04-03 20:35:21 +0000 | [diff] [blame] | 1373 | Tmp3 = SelectExpr(N.getOperand(1)); //Use if FALSE |
Andrew Lenharth | d228427 | 2005-08-15 14:31:37 +0000 | [diff] [blame] | 1374 | BuildMI(BB, Opc, 2, Result).addReg(Tmp3).addImm(SImm).addReg(Tmp1); |
Andrew Lenharth | 63b720a | 2005-04-03 20:35:21 +0000 | [diff] [blame] | 1375 | } else { |
| 1376 | Tmp2 = SelectExpr(N.getOperand(1)); //Use if TRUE |
| 1377 | Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE |
| 1378 | BuildMI(BB, Opc, 2, Result).addReg(Tmp3).addReg(Tmp2).addReg(Tmp1); |
| 1379 | } |
| 1380 | return Result; |
| 1381 | } |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1382 | //Otherwise, fall though |
Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 1383 | } |
| 1384 | Tmp1 = SelectExpr(N.getOperand(0)); //Cond |
Andrew Lenharth | 63b720a | 2005-04-03 20:35:21 +0000 | [diff] [blame] | 1385 | Tmp2 = SelectExpr(N.getOperand(1)); //Use if TRUE |
| 1386 | Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE |
Andrew Lenharth | d4653b1 | 2005-06-27 17:39:17 +0000 | [diff] [blame] | 1387 | BuildMI(BB, Alpha::CMOVEQ, 2, Result).addReg(Tmp2).addReg(Tmp3) |
| 1388 | .addReg(Tmp1); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1389 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1390 | return Result; |
| 1391 | } |
| 1392 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1393 | case ISD::Constant: |
| 1394 | { |
Andrew Lenharth | c051383 | 2005-03-29 19:24:04 +0000 | [diff] [blame] | 1395 | int64_t val = (int64_t)cast<ConstantSDNode>(N)->getValue(); |
Andrew Lenharth | 6b137d8 | 2005-07-22 22:24:01 +0000 | [diff] [blame] | 1396 | int zero_extend_top = 0; |
Andrew Lenharth | f075cac | 2005-07-23 07:46:48 +0000 | [diff] [blame] | 1397 | if (val > 0 && (val & 0xFFFFFFFF00000000ULL) == 0 && |
Andrew Lenharth | 6b137d8 | 2005-07-22 22:24:01 +0000 | [diff] [blame] | 1398 | ((int32_t)val < 0)) { |
| 1399 | //try a small load and zero extend |
| 1400 | val = (int32_t)val; |
| 1401 | zero_extend_top = 15; |
| 1402 | } |
| 1403 | |
Andrew Lenharth | e87f6c3 | 2005-03-11 17:48:05 +0000 | [diff] [blame] | 1404 | if (val <= IMM_HIGH && val >= IMM_LOW) { |
Andrew Lenharth | 6b137d8 | 2005-07-22 22:24:01 +0000 | [diff] [blame] | 1405 | if(!zero_extend_top) |
| 1406 | BuildMI(BB, Alpha::LDA, 2, Result).addImm(val).addReg(Alpha::R31); |
| 1407 | else { |
| 1408 | Tmp1 = MakeReg(MVT::i64); |
| 1409 | BuildMI(BB, Alpha::LDA, 2, Tmp1).addImm(val).addReg(Alpha::R31); |
| 1410 | BuildMI(BB, Alpha::ZAPNOT, 2, Result).addReg(Tmp1).addImm(zero_extend_top); |
| 1411 | } |
Andrew Lenharth | e87f6c3 | 2005-03-11 17:48:05 +0000 | [diff] [blame] | 1412 | } |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1413 | else if (val <= (int64_t)IMM_HIGH +(int64_t)IMM_HIGH* (int64_t)IMM_MULT && |
| 1414 | val >= (int64_t)IMM_LOW + (int64_t)IMM_LOW * (int64_t)IMM_MULT) { |
| 1415 | Tmp1 = MakeReg(MVT::i64); |
Andrew Lenharth | d4653b1 | 2005-06-27 17:39:17 +0000 | [diff] [blame] | 1416 | BuildMI(BB, Alpha::LDAH, 2, Tmp1).addImm(getUpper16(val)) |
| 1417 | .addReg(Alpha::R31); |
Andrew Lenharth | 6b137d8 | 2005-07-22 22:24:01 +0000 | [diff] [blame] | 1418 | if (!zero_extend_top) |
| 1419 | BuildMI(BB, Alpha::LDA, 2, Result).addImm(getLower16(val)).addReg(Tmp1); |
| 1420 | else { |
| 1421 | Tmp3 = MakeReg(MVT::i64); |
| 1422 | BuildMI(BB, Alpha::LDA, 2, Tmp3).addImm(getLower16(val)).addReg(Tmp1); |
| 1423 | BuildMI(BB, Alpha::ZAPNOT, 2, Result).addReg(Tmp3).addImm(zero_extend_top); |
| 1424 | } |
Andrew Lenharth | e87f6c3 | 2005-03-11 17:48:05 +0000 | [diff] [blame] | 1425 | } |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1426 | else { |
Andrew Lenharth | 6b137d8 | 2005-07-22 22:24:01 +0000 | [diff] [blame] | 1427 | //re-get the val since we are going to mem anyway |
| 1428 | val = (int64_t)cast<ConstantSDNode>(N)->getValue(); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1429 | MachineConstantPool *CP = BB->getParent()->getConstantPool(); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 1430 | ConstantUInt *C = |
Andrew Lenharth | d4653b1 | 2005-06-27 17:39:17 +0000 | [diff] [blame] | 1431 | ConstantUInt::get(Type::getPrimitiveType(Type::ULongTyID) , val); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1432 | unsigned CPI = CP->getConstantPoolIndex(C); |
| 1433 | AlphaLowering.restoreGP(BB); |
Andrew Lenharth | fe895e3 | 2005-06-27 17:15:36 +0000 | [diff] [blame] | 1434 | Tmp1 = MakeReg(MVT::i64); |
Andrew Lenharth | d4653b1 | 2005-06-27 17:39:17 +0000 | [diff] [blame] | 1435 | BuildMI(BB, Alpha::LDAHr, 2, Tmp1).addConstantPoolIndex(CPI) |
| 1436 | .addReg(Alpha::R29); |
Andrew Lenharth | cf8bf38 | 2005-07-01 19:12:13 +0000 | [diff] [blame] | 1437 | if (EnableAlphaLSMark) |
| 1438 | BuildMI(BB, Alpha::MEMLABEL, 4).addImm(5).addImm(0).addImm(0) |
| 1439 | .addImm(getUID()); |
Andrew Lenharth | d4653b1 | 2005-06-27 17:39:17 +0000 | [diff] [blame] | 1440 | BuildMI(BB, Alpha::LDQr, 2, Result).addConstantPoolIndex(CPI) |
| 1441 | .addReg(Tmp1); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1442 | } |
| 1443 | return Result; |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1444 | } |
Andrew Lenharth | f4da945 | 2005-06-29 12:49:51 +0000 | [diff] [blame] | 1445 | case ISD::FNEG: |
| 1446 | if(ISD::FABS == N.getOperand(0).getOpcode()) |
| 1447 | { |
| 1448 | Tmp1 = SelectExpr(N.getOperand(0).getOperand(0)); |
Andrew Lenharth | 5cefc5e | 2005-11-09 19:17:08 +0000 | [diff] [blame] | 1449 | BuildMI(BB, DestType == MVT::f64 ? Alpha::CPYSNT : Alpha::CPYSNS, |
| 1450 | 2, Result).addReg(Alpha::F31).addReg(Tmp1); |
Andrew Lenharth | f4da945 | 2005-06-29 12:49:51 +0000 | [diff] [blame] | 1451 | } else { |
| 1452 | Tmp1 = SelectExpr(N.getOperand(0)); |
Andrew Lenharth | 5cefc5e | 2005-11-09 19:17:08 +0000 | [diff] [blame] | 1453 | BuildMI(BB, DestType == MVT::f64 ? Alpha::CPYSNT : Alpha::CPYSNS |
| 1454 | , 2, Result).addReg(Tmp1).addReg(Tmp1); |
Andrew Lenharth | f4da945 | 2005-06-29 12:49:51 +0000 | [diff] [blame] | 1455 | } |
| 1456 | return Result; |
| 1457 | |
| 1458 | case ISD::FABS: |
| 1459 | Tmp1 = SelectExpr(N.getOperand(0)); |
Andrew Lenharth | 5cefc5e | 2005-11-09 19:17:08 +0000 | [diff] [blame] | 1460 | BuildMI(BB, DestType == MVT::f64 ? Alpha::CPYST : Alpha::CPYSS, 2, Result) |
| 1461 | .addReg(Alpha::F31).addReg(Tmp1); |
Andrew Lenharth | f4da945 | 2005-06-29 12:49:51 +0000 | [diff] [blame] | 1462 | return Result; |
| 1463 | |
| 1464 | case ISD::FP_ROUND: |
| 1465 | assert (DestType == MVT::f32 && |
| 1466 | N.getOperand(0).getValueType() == MVT::f64 && |
| 1467 | "only f64 to f32 conversion supported here"); |
| 1468 | Tmp1 = SelectExpr(N.getOperand(0)); |
Andrew Lenharth | b921f1b | 2005-11-11 23:08:46 +0000 | [diff] [blame] | 1469 | BuildMI(BB, Alpha::CVTTS, 1, Result).addReg(Tmp1); |
Andrew Lenharth | f4da945 | 2005-06-29 12:49:51 +0000 | [diff] [blame] | 1470 | return Result; |
| 1471 | |
| 1472 | case ISD::FP_EXTEND: |
| 1473 | assert (DestType == MVT::f64 && |
| 1474 | N.getOperand(0).getValueType() == MVT::f32 && |
| 1475 | "only f32 to f64 conversion supported here"); |
| 1476 | Tmp1 = SelectExpr(N.getOperand(0)); |
Andrew Lenharth | c2c64fd | 2005-11-11 19:52:25 +0000 | [diff] [blame] | 1477 | BuildMI(BB, Alpha::CVTST, 1, Result).addReg(Tmp1); |
Andrew Lenharth | f4da945 | 2005-06-29 12:49:51 +0000 | [diff] [blame] | 1478 | return Result; |
| 1479 | |
| 1480 | case ISD::ConstantFP: |
| 1481 | if (ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(N)) { |
| 1482 | if (CN->isExactlyValue(+0.0)) { |
Andrew Lenharth | 5cefc5e | 2005-11-09 19:17:08 +0000 | [diff] [blame] | 1483 | BuildMI(BB, DestType == MVT::f64 ? Alpha::CPYST : Alpha::CPYSS |
| 1484 | , 2, Result).addReg(Alpha::F31) |
Andrew Lenharth | f4da945 | 2005-06-29 12:49:51 +0000 | [diff] [blame] | 1485 | .addReg(Alpha::F31); |
| 1486 | } else if ( CN->isExactlyValue(-0.0)) { |
Andrew Lenharth | 5cefc5e | 2005-11-09 19:17:08 +0000 | [diff] [blame] | 1487 | BuildMI(BB, DestType == MVT::f64 ? Alpha::CPYSNT : Alpha::CPYSNS, |
| 1488 | 2, Result).addReg(Alpha::F31) |
Andrew Lenharth | f4da945 | 2005-06-29 12:49:51 +0000 | [diff] [blame] | 1489 | .addReg(Alpha::F31); |
| 1490 | } else { |
| 1491 | abort(); |
| 1492 | } |
| 1493 | } |
| 1494 | return Result; |
| 1495 | |
Andrew Lenharth | 7f0db91 | 2005-11-30 07:19:56 +0000 | [diff] [blame] | 1496 | case AlphaISD::CVTQT_: |
Andrew Lenharth | 6251b36 | 2005-12-01 17:48:51 +0000 | [diff] [blame] | 1497 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1498 | BuildMI(BB, Alpha::CVTQT, 1, Result).addReg(Tmp1); |
Andrew Lenharth | 7f0db91 | 2005-11-30 07:19:56 +0000 | [diff] [blame] | 1499 | return Result; |
| 1500 | |
| 1501 | case AlphaISD::CVTQS_: |
Andrew Lenharth | 6251b36 | 2005-12-01 17:48:51 +0000 | [diff] [blame] | 1502 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1503 | BuildMI(BB, Alpha::CVTQS, 1, Result).addReg(Tmp1); |
Andrew Lenharth | 7f0db91 | 2005-11-30 07:19:56 +0000 | [diff] [blame] | 1504 | return Result; |
| 1505 | |
Andrew Lenharth | cd80496 | 2005-11-30 16:10:29 +0000 | [diff] [blame] | 1506 | case AlphaISD::CVTTQ_: |
Andrew Lenharth | 6251b36 | 2005-12-01 17:48:51 +0000 | [diff] [blame] | 1507 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1508 | BuildMI(BB, Alpha::CVTTQ, 1, Result).addReg(Tmp1); |
Andrew Lenharth | cd80496 | 2005-11-30 16:10:29 +0000 | [diff] [blame] | 1509 | return Result; |
| 1510 | |
Andrew Lenharth | 7f0db91 | 2005-11-30 07:19:56 +0000 | [diff] [blame] | 1511 | case AlphaISD::ITOFT_: |
Andrew Lenharth | 6251b36 | 2005-12-01 17:48:51 +0000 | [diff] [blame] | 1512 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1513 | BuildMI(BB, Alpha::ITOFT, 1, Result).addReg(Tmp1); |
Andrew Lenharth | 7f0db91 | 2005-11-30 07:19:56 +0000 | [diff] [blame] | 1514 | return Result; |
Andrew Lenharth | f71df33 | 2005-09-04 06:12:19 +0000 | [diff] [blame] | 1515 | |
Andrew Lenharth | cd80496 | 2005-11-30 16:10:29 +0000 | [diff] [blame] | 1516 | case AlphaISD::FTOIT_: |
Andrew Lenharth | 6251b36 | 2005-12-01 17:48:51 +0000 | [diff] [blame] | 1517 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1518 | BuildMI(BB, Alpha::FTOIT, 1, Result).addReg(Tmp1); |
Andrew Lenharth | cd80496 | 2005-11-30 16:10:29 +0000 | [diff] [blame] | 1519 | return Result; |
| 1520 | |
Andrew Lenharth | f71df33 | 2005-09-04 06:12:19 +0000 | [diff] [blame] | 1521 | case ISD::AssertSext: |
| 1522 | case ISD::AssertZext: |
| 1523 | return SelectExpr(N.getOperand(0)); |
| 1524 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1525 | } |
| 1526 | |
| 1527 | return 0; |
| 1528 | } |
| 1529 | |
Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 1530 | void AlphaISel::Select(SDOperand N) { |
Andrew Lenharth | 4052f02 | 2005-11-22 20:59:00 +0000 | [diff] [blame] | 1531 | unsigned Tmp1, Tmp2, Opc = Alpha::WTF; |
Andrew Lenharth | 760270d | 2005-02-07 23:02:23 +0000 | [diff] [blame] | 1532 | unsigned opcode = N.getOpcode(); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1533 | |
Nate Begeman | 85fdeb2 | 2005-03-24 04:39:54 +0000 | [diff] [blame] | 1534 | if (!ExprMap.insert(std::make_pair(N, notIn)).second) |
Andrew Lenharth | 6b9870a | 2005-01-28 14:06:46 +0000 | [diff] [blame] | 1535 | return; // Already selected. |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1536 | |
| 1537 | SDNode *Node = N.Val; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1538 | |
Andrew Lenharth | 760270d | 2005-02-07 23:02:23 +0000 | [diff] [blame] | 1539 | switch (opcode) { |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1540 | |
| 1541 | default: |
| 1542 | Node->dump(); std::cerr << "\n"; |
| 1543 | assert(0 && "Node not handled yet!"); |
| 1544 | |
| 1545 | case ISD::BRCOND: { |
Andrew Lenharth | 445171a | 2005-02-08 00:40:03 +0000 | [diff] [blame] | 1546 | SelectBranchCC(N); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1547 | return; |
| 1548 | } |
| 1549 | |
| 1550 | case ISD::BR: { |
| 1551 | MachineBasicBlock *Dest = |
| 1552 | cast<BasicBlockSDNode>(N.getOperand(1))->getBasicBlock(); |
| 1553 | |
| 1554 | Select(N.getOperand(0)); |
Andrew Lenharth | eececba | 2005-12-25 17:36:48 +0000 | [diff] [blame^] | 1555 | BuildMI(BB, Alpha::BR, 1).addMBB(Dest); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1556 | return; |
| 1557 | } |
| 1558 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1559 | case ISD::EntryToken: return; // Noop |
| 1560 | |
| 1561 | case ISD::TokenFactor: |
| 1562 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) |
| 1563 | Select(Node->getOperand(i)); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1564 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1565 | //N.Val->dump(); std::cerr << "\n"; |
| 1566 | //assert(0 && "Node not handled yet!"); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1567 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1568 | return; |
| 1569 | |
| 1570 | case ISD::CopyToReg: |
Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 1571 | ++count_outs; |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1572 | Select(N.getOperand(0)); |
Chris Lattner | 707ebc5 | 2005-08-16 21:56:37 +0000 | [diff] [blame] | 1573 | Tmp1 = SelectExpr(N.getOperand(2)); |
| 1574 | Tmp2 = cast<RegisterSDNode>(N.getOperand(1))->getReg(); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1575 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1576 | if (Tmp1 != Tmp2) { |
Andrew Lenharth | 5cefc5e | 2005-11-09 19:17:08 +0000 | [diff] [blame] | 1577 | switch(N.getOperand(2).getValueType()) { |
| 1578 | case MVT::f64: |
| 1579 | BuildMI(BB, Alpha::CPYST, 2, Tmp2).addReg(Tmp1).addReg(Tmp1); |
| 1580 | break; |
| 1581 | case MVT::f32: |
| 1582 | BuildMI(BB, Alpha::CPYSS, 2, Tmp2).addReg(Tmp1).addReg(Tmp1); |
| 1583 | break; |
| 1584 | default: |
Andrew Lenharth | 2921916 | 2005-02-07 06:31:44 +0000 | [diff] [blame] | 1585 | BuildMI(BB, Alpha::BIS, 2, Tmp2).addReg(Tmp1).addReg(Tmp1); |
Andrew Lenharth | 5cefc5e | 2005-11-09 19:17:08 +0000 | [diff] [blame] | 1586 | break; |
| 1587 | } |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1588 | } |
| 1589 | return; |
| 1590 | |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1591 | case ISD::RET: |
Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 1592 | ++count_outs; |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1593 | switch (N.getNumOperands()) { |
| 1594 | default: |
| 1595 | std::cerr << N.getNumOperands() << "\n"; |
| 1596 | for (unsigned i = 0; i < N.getNumOperands(); ++i) |
| 1597 | std::cerr << N.getOperand(i).getValueType() << "\n"; |
| 1598 | Node->dump(); |
| 1599 | assert(0 && "Unknown return instruction!"); |
| 1600 | case 2: |
| 1601 | Select(N.getOperand(0)); |
| 1602 | Tmp1 = SelectExpr(N.getOperand(1)); |
| 1603 | switch (N.getOperand(1).getValueType()) { |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1604 | default: Node->dump(); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1605 | assert(0 && "All other types should have been promoted!!"); |
| 1606 | case MVT::f64: |
Andrew Lenharth | 5cefc5e | 2005-11-09 19:17:08 +0000 | [diff] [blame] | 1607 | BuildMI(BB, Alpha::CPYST, 2, Alpha::F0).addReg(Tmp1).addReg(Tmp1); |
| 1608 | break; |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1609 | case MVT::f32: |
Andrew Lenharth | 5cefc5e | 2005-11-09 19:17:08 +0000 | [diff] [blame] | 1610 | BuildMI(BB, Alpha::CPYSS, 2, Alpha::F0).addReg(Tmp1).addReg(Tmp1); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1611 | break; |
| 1612 | case MVT::i32: |
| 1613 | case MVT::i64: |
| 1614 | BuildMI(BB, Alpha::BIS, 2, Alpha::R0).addReg(Tmp1).addReg(Tmp1); |
| 1615 | break; |
| 1616 | } |
| 1617 | break; |
| 1618 | case 1: |
| 1619 | Select(N.getOperand(0)); |
| 1620 | break; |
| 1621 | } |
Andrew Lenharth | d4653b1 | 2005-06-27 17:39:17 +0000 | [diff] [blame] | 1622 | // Just emit a 'ret' instruction |
Andrew Lenharth | 6968bff | 2005-06-27 23:24:11 +0000 | [diff] [blame] | 1623 | AlphaLowering.restoreRA(BB); |
Andrew Lenharth | f3f951a | 2005-07-22 20:50:29 +0000 | [diff] [blame] | 1624 | BuildMI(BB, Alpha::RET, 2, Alpha::R31).addReg(Alpha::R26).addImm(1); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1625 | return; |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1626 | |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1627 | case ISD::TRUNCSTORE: |
| 1628 | case ISD::STORE: |
Andrew Lenharth | b014d3e | 2005-02-02 17:32:39 +0000 | [diff] [blame] | 1629 | { |
Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 1630 | SDOperand Chain = N.getOperand(0); |
| 1631 | SDOperand Value = N.getOperand(1); |
| 1632 | SDOperand Address = N.getOperand(2); |
| 1633 | Select(Chain); |
| 1634 | |
| 1635 | Tmp1 = SelectExpr(Value); //value |
Andrew Lenharth | 760270d | 2005-02-07 23:02:23 +0000 | [diff] [blame] | 1636 | |
| 1637 | if (opcode == ISD::STORE) { |
| 1638 | switch(Value.getValueType()) { |
Andrew Lenharth | 4052f02 | 2005-11-22 20:59:00 +0000 | [diff] [blame] | 1639 | default: assert(0 && "unknown Type in store"); |
Andrew Lenharth | 760270d | 2005-02-07 23:02:23 +0000 | [diff] [blame] | 1640 | case MVT::i64: Opc = Alpha::STQ; break; |
| 1641 | case MVT::f64: Opc = Alpha::STT; break; |
| 1642 | case MVT::f32: Opc = Alpha::STS; break; |
| 1643 | } |
| 1644 | } else { //ISD::TRUNCSTORE |
Chris Lattner | 9fadb4c | 2005-07-10 00:29:18 +0000 | [diff] [blame] | 1645 | switch(cast<VTSDNode>(Node->getOperand(4))->getVT()) { |
Andrew Lenharth | 4052f02 | 2005-11-22 20:59:00 +0000 | [diff] [blame] | 1646 | default: assert(0 && "unknown Type in store"); |
Andrew Lenharth | 760270d | 2005-02-07 23:02:23 +0000 | [diff] [blame] | 1647 | case MVT::i8: Opc = Alpha::STB; break; |
| 1648 | case MVT::i16: Opc = Alpha::STW; break; |
| 1649 | case MVT::i32: Opc = Alpha::STL; break; |
| 1650 | } |
Andrew Lenharth | 6583890 | 2005-02-06 16:22:15 +0000 | [diff] [blame] | 1651 | } |
Andrew Lenharth | 760270d | 2005-02-07 23:02:23 +0000 | [diff] [blame] | 1652 | |
Andrew Lenharth | 06ef884 | 2005-06-29 18:54:02 +0000 | [diff] [blame] | 1653 | int i, j, k; |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 1654 | if (EnableAlphaLSMark) |
| 1655 | getValueInfo(cast<SrcValueSDNode>(N.getOperand(3))->getValue(), |
Andrew Lenharth | 06ef884 | 2005-06-29 18:54:02 +0000 | [diff] [blame] | 1656 | i, j, k); |
Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 1657 | |
Andrew Lenharth | 4e62951 | 2005-12-24 05:36:33 +0000 | [diff] [blame] | 1658 | if (Address.getOpcode() == AlphaISD::GPRelLo) { |
| 1659 | unsigned Hi = SelectExpr(Address.getOperand(1)); |
| 1660 | Address = Address.getOperand(0); |
| 1661 | if (GlobalAddressSDNode *GASD = dyn_cast<GlobalAddressSDNode>(Address)) { |
| 1662 | if (EnableAlphaLSMark) |
| 1663 | BuildMI(BB, Alpha::MEMLABEL, 4).addImm(i).addImm(j).addImm(k) |
| 1664 | .addImm(getUID()); |
| 1665 | BuildMI(BB, GetRelVersion(Opc), 3).addReg(Tmp1) |
| 1666 | .addGlobalAddress(GASD->getGlobal()).addReg(Hi); |
| 1667 | } else assert(0 && "Unknown Lo part"); |
Andrew Lenharth | fce587e | 2005-06-29 00:39:17 +0000 | [diff] [blame] | 1668 | } else if(Address.getOpcode() == ISD::FrameIndex) { |
Andrew Lenharth | c7989ce | 2005-06-29 00:31:08 +0000 | [diff] [blame] | 1669 | if (EnableAlphaLSMark) |
Andrew Lenharth | 06ef884 | 2005-06-29 18:54:02 +0000 | [diff] [blame] | 1670 | BuildMI(BB, Alpha::MEMLABEL, 4).addImm(i).addImm(j).addImm(k) |
| 1671 | .addImm(getUID()); |
Andrew Lenharth | 032f235 | 2005-02-22 21:59:48 +0000 | [diff] [blame] | 1672 | BuildMI(BB, Opc, 3).addReg(Tmp1) |
| 1673 | .addFrameIndex(cast<FrameIndexSDNode>(Address)->getIndex()) |
| 1674 | .addReg(Alpha::F31); |
Andrew Lenharth | c7989ce | 2005-06-29 00:31:08 +0000 | [diff] [blame] | 1675 | } else { |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1676 | long offset; |
| 1677 | SelectAddr(Address, Tmp2, offset); |
Andrew Lenharth | c7989ce | 2005-06-29 00:31:08 +0000 | [diff] [blame] | 1678 | if (EnableAlphaLSMark) |
Andrew Lenharth | 06ef884 | 2005-06-29 18:54:02 +0000 | [diff] [blame] | 1679 | BuildMI(BB, Alpha::MEMLABEL, 4).addImm(i).addImm(j).addImm(k) |
| 1680 | .addImm(getUID()); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1681 | BuildMI(BB, Opc, 3).addReg(Tmp1).addImm(offset).addReg(Tmp2); |
| 1682 | } |
Andrew Lenharth | b014d3e | 2005-02-02 17:32:39 +0000 | [diff] [blame] | 1683 | return; |
| 1684 | } |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1685 | |
| 1686 | case ISD::EXTLOAD: |
| 1687 | case ISD::SEXTLOAD: |
| 1688 | case ISD::ZEXTLOAD: |
| 1689 | case ISD::LOAD: |
| 1690 | case ISD::CopyFromReg: |
Chris Lattner | b5d8e6e | 2005-05-13 20:29:26 +0000 | [diff] [blame] | 1691 | case ISD::TAILCALL: |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1692 | case ISD::CALL: |
Andrew Lenharth | 82a698c | 2005-11-12 19:04:09 +0000 | [diff] [blame] | 1693 | case ISD::READCYCLECOUNTER: |
Andrew Lenharth | 032f235 | 2005-02-22 21:59:48 +0000 | [diff] [blame] | 1694 | case ISD::DYNAMIC_STACKALLOC: |
Andrew Lenharth | 6b9870a | 2005-01-28 14:06:46 +0000 | [diff] [blame] | 1695 | ExprMap.erase(N); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1696 | SelectExpr(N); |
| 1697 | return; |
| 1698 | |
Chris Lattner | 16cd04d | 2005-05-12 23:24:06 +0000 | [diff] [blame] | 1699 | case ISD::CALLSEQ_START: |
| 1700 | case ISD::CALLSEQ_END: |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1701 | Select(N.getOperand(0)); |
| 1702 | Tmp1 = cast<ConstantSDNode>(N.getOperand(1))->getValue(); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1703 | |
Chris Lattner | 16cd04d | 2005-05-12 23:24:06 +0000 | [diff] [blame] | 1704 | Opc = N.getOpcode() == ISD::CALLSEQ_START ? Alpha::ADJUSTSTACKDOWN : |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1705 | Alpha::ADJUSTSTACKUP; |
| 1706 | BuildMI(BB, Opc, 1).addImm(Tmp1); |
| 1707 | return; |
Andrew Lenharth | 9576212 | 2005-03-31 21:24:06 +0000 | [diff] [blame] | 1708 | |
| 1709 | case ISD::PCMARKER: |
| 1710 | Select(N.getOperand(0)); //Chain |
Andrew Lenharth | d4653b1 | 2005-06-27 17:39:17 +0000 | [diff] [blame] | 1711 | BuildMI(BB, Alpha::PCLABEL, 2) |
| 1712 | .addImm( cast<ConstantSDNode>(N.getOperand(1))->getValue()); |
Andrew Lenharth | 9576212 | 2005-03-31 21:24:06 +0000 | [diff] [blame] | 1713 | return; |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1714 | } |
| 1715 | assert(0 && "Should not be reached!"); |
| 1716 | } |
| 1717 | |
| 1718 | |
| 1719 | /// createAlphaPatternInstructionSelector - This pass converts an LLVM function |
| 1720 | /// into a machine code representation using pattern matching and a machine |
| 1721 | /// description file. |
| 1722 | /// |
| 1723 | FunctionPass *llvm::createAlphaPatternInstructionSelector(TargetMachine &TM) { |
Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 1724 | return new AlphaISel(TM); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1725 | } |
Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 1726 | |