| 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" | 
|  | 16 | #include "llvm/Constants.h"                   // FIXME: REMOVE | 
|  | 17 | #include "llvm/Function.h" | 
| Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 18 | #include "llvm/Module.h" | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/MachineInstrBuilder.h" | 
|  | 20 | #include "llvm/CodeGen/MachineConstantPool.h" // FIXME: REMOVE | 
|  | 21 | #include "llvm/CodeGen/MachineFunction.h" | 
|  | 22 | #include "llvm/CodeGen/MachineFrameInfo.h" | 
|  | 23 | #include "llvm/CodeGen/SelectionDAG.h" | 
|  | 24 | #include "llvm/CodeGen/SelectionDAGISel.h" | 
|  | 25 | #include "llvm/CodeGen/SSARegMap.h" | 
|  | 26 | #include "llvm/Target/TargetData.h" | 
|  | 27 | #include "llvm/Target/TargetLowering.h" | 
|  | 28 | #include "llvm/Support/MathExtras.h" | 
|  | 29 | #include "llvm/ADT/Statistic.h" | 
| Andrew Lenharth | 032f235 | 2005-02-22 21:59:48 +0000 | [diff] [blame] | 30 | #include "llvm/Support/Debug.h" | 
| Andrew Lenharth | 9576212 | 2005-03-31 21:24:06 +0000 | [diff] [blame] | 31 | #include "llvm/Support/CommandLine.h" | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 32 | #include <set> | 
| Andrew Lenharth | 684f229 | 2005-01-30 00:35:27 +0000 | [diff] [blame] | 33 | #include <algorithm> | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 34 | using namespace llvm; | 
|  | 35 |  | 
| Andrew Lenharth | 9576212 | 2005-03-31 21:24:06 +0000 | [diff] [blame] | 36 | namespace llvm { | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 37 | cl::opt<bool> EnableAlphaIDIV("enable-alpha-intfpdiv", | 
|  | 38 | cl::desc("Use the FP div instruction for integer div when possible"), | 
| Andrew Lenharth | 9576212 | 2005-03-31 21:24:06 +0000 | [diff] [blame] | 39 | cl::Hidden); | 
| Andrew Lenharth | 5900919 | 2005-05-04 19:12:09 +0000 | [diff] [blame] | 40 | cl::opt<bool> EnableAlphaFTOI("enable-alpha-FTOI", | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 41 | cl::desc("Enable use of ftoi* and itof* instructions (ev6 and higher)"), | 
| Andrew Lenharth | 9576212 | 2005-03-31 21:24:06 +0000 | [diff] [blame] | 42 | cl::Hidden); | 
| Andrew Lenharth | 5900919 | 2005-05-04 19:12:09 +0000 | [diff] [blame] | 43 | cl::opt<bool> EnableAlphaCT("enable-alpha-CT", | 
|  | 44 | cl::desc("Enable use of the ctpop, ctlz, and cttz instructions"), | 
|  | 45 | cl::Hidden); | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 46 | cl::opt<bool> EnableAlphaCount("enable-alpha-count", | 
|  | 47 | cl::desc("Print estimates on live ins and outs"), | 
| Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 48 | cl::Hidden); | 
| Andrew Lenharth | cd7f8cf | 2005-06-06 19:03:55 +0000 | [diff] [blame] | 49 | cl::opt<bool> EnableAlphaLSMark("enable-alpha-lsmark", | 
| Misha Brukman | 5e96a3a | 2005-06-06 19:08:04 +0000 | [diff] [blame] | 50 | cl::desc("Emit symbols to correlate Mem ops to LLVM Values"), | 
| Andrew Lenharth | cd7f8cf | 2005-06-06 19:03:55 +0000 | [diff] [blame] | 51 | cl::Hidden); | 
| Andrew Lenharth | 9576212 | 2005-03-31 21:24:06 +0000 | [diff] [blame] | 52 | } | 
|  | 53 |  | 
| Andrew Lenharth | e3c8c0a4 | 2005-05-31 19:49:34 +0000 | [diff] [blame] | 54 | namespace { | 
|  | 55 | // Alpha Specific DAG Nodes | 
|  | 56 | namespace AlphaISD { | 
|  | 57 | enum NodeType { | 
|  | 58 | // Start the numbering where the builtin ops leave off. | 
|  | 59 | FIRST_NUMBER = ISD::BUILTIN_OP_END, | 
|  | 60 |  | 
|  | 61 | //Convert an int bit pattern in an FP reg to a Double or Float | 
|  | 62 | //Has a dest type and a source | 
|  | 63 | CVTQ, | 
|  | 64 | //Move an Ireg to a FPreg | 
|  | 65 | ITOF, | 
|  | 66 | //Move a  FPreg to an Ireg | 
|  | 67 | FTOI, | 
|  | 68 | }; | 
|  | 69 | } | 
|  | 70 | } | 
|  | 71 |  | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 72 | //===----------------------------------------------------------------------===// | 
|  | 73 | //  AlphaTargetLowering - Alpha Implementation of the TargetLowering interface | 
|  | 74 | namespace { | 
|  | 75 | class AlphaTargetLowering : public TargetLowering { | 
| Andrew Lenharth | 558bc88 | 2005-06-18 18:34:52 +0000 | [diff] [blame] | 76 | int VarArgsOffset;  // What is the offset to the first vaarg | 
|  | 77 | int VarArgsBase;    // What is the base FrameIndex | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 78 | unsigned GP; //GOT vreg | 
| Andrew Lenharth | 3f5aa1c | 2005-06-23 23:42:05 +0000 | [diff] [blame] | 79 | unsigned RA; //Return Address | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 80 | public: | 
|  | 81 | AlphaTargetLowering(TargetMachine &TM) : TargetLowering(TM) { | 
|  | 82 | // Set up the TargetLowering object. | 
| Andrew Lenharth | 3d65d31 | 2005-01-27 03:49:45 +0000 | [diff] [blame] | 83 | //I am having problems with shr n ubyte 1 | 
| Andrew Lenharth | 879ef22 | 2005-02-02 17:00:21 +0000 | [diff] [blame] | 84 | setShiftAmountType(MVT::i64); | 
|  | 85 | setSetCCResultType(MVT::i64); | 
| Andrew Lenharth | d3355e2 | 2005-04-07 20:11:32 +0000 | [diff] [blame] | 86 | setSetCCResultContents(ZeroOrOneSetCCResult); | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 87 |  | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 88 | addRegisterClass(MVT::i64, Alpha::GPRCRegisterClass); | 
|  | 89 | addRegisterClass(MVT::f64, Alpha::FPRCRegisterClass); | 
| Andrew Lenharth | 3d65d31 | 2005-01-27 03:49:45 +0000 | [diff] [blame] | 90 | addRegisterClass(MVT::f32, Alpha::FPRCRegisterClass); | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 91 |  | 
| Chris Lattner | da4d469 | 2005-04-09 03:22:37 +0000 | [diff] [blame] | 92 | setOperationAction(ISD::BRCONDTWOWAY, MVT::Other, Expand); | 
| Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 93 | setOperationAction(ISD::EXTLOAD  , MVT::i1   , Promote); | 
|  | 94 | setOperationAction(ISD::EXTLOAD  , MVT::f32  , Promote); | 
| Andrew Lenharth | 2f8fb77 | 2005-01-25 00:35:34 +0000 | [diff] [blame] | 95 |  | 
| Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 96 | setOperationAction(ISD::ZEXTLOAD , MVT::i1   , Expand); | 
|  | 97 | setOperationAction(ISD::ZEXTLOAD , MVT::i32  , Expand); | 
| Andrew Lenharth | 2f8fb77 | 2005-01-25 00:35:34 +0000 | [diff] [blame] | 98 |  | 
| Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 99 | setOperationAction(ISD::SEXTLOAD , MVT::i1   , Expand); | 
|  | 100 | setOperationAction(ISD::SEXTLOAD , MVT::i8   , Expand); | 
|  | 101 | setOperationAction(ISD::SEXTLOAD , MVT::i16  , Expand); | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 102 |  | 
| Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 103 | setOperationAction(ISD::SREM     , MVT::f32  , Expand); | 
|  | 104 | setOperationAction(ISD::SREM     , MVT::f64  , Expand); | 
| Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 105 |  | 
| Andrew Lenharth | 5900919 | 2005-05-04 19:12:09 +0000 | [diff] [blame] | 106 | if (!EnableAlphaCT) { | 
|  | 107 | setOperationAction(ISD::CTPOP    , MVT::i64  , Expand); | 
|  | 108 | setOperationAction(ISD::CTTZ     , MVT::i64  , Expand); | 
| Andrew Lenharth | b5884d3 | 2005-05-04 19:25:37 +0000 | [diff] [blame] | 109 | setOperationAction(ISD::CTLZ     , MVT::i64  , Expand); | 
| Andrew Lenharth | 5900919 | 2005-05-04 19:12:09 +0000 | [diff] [blame] | 110 | } | 
| Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 111 |  | 
| Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 112 | //If this didn't legalize into a div.... | 
|  | 113 | //      setOperationAction(ISD::SREM     , MVT::i64, Expand); | 
|  | 114 | //      setOperationAction(ISD::UREM     , MVT::i64, Expand); | 
|  | 115 |  | 
|  | 116 | setOperationAction(ISD::MEMMOVE  , MVT::Other, Expand); | 
|  | 117 | setOperationAction(ISD::MEMSET   , MVT::Other, Expand); | 
|  | 118 | setOperationAction(ISD::MEMCPY   , MVT::Other, Expand); | 
| Andrew Lenharth | 9818c05 | 2005-02-05 13:19:12 +0000 | [diff] [blame] | 119 |  | 
| Chris Lattner | 17234b7 | 2005-04-30 04:26:06 +0000 | [diff] [blame] | 120 | // We don't support sin/cos/sqrt | 
|  | 121 | setOperationAction(ISD::FSIN , MVT::f64, Expand); | 
|  | 122 | setOperationAction(ISD::FCOS , MVT::f64, Expand); | 
|  | 123 | setOperationAction(ISD::FSQRT, MVT::f64, Expand); | 
|  | 124 | setOperationAction(ISD::FSIN , MVT::f32, Expand); | 
|  | 125 | setOperationAction(ISD::FCOS , MVT::f32, Expand); | 
|  | 126 | setOperationAction(ISD::FSQRT, MVT::f32, Expand); | 
|  | 127 |  | 
| Andrew Lenharth | 3381913 | 2005-03-04 20:09:23 +0000 | [diff] [blame] | 128 | //Doesn't work yet | 
| Chris Lattner | 17234b7 | 2005-04-30 04:26:06 +0000 | [diff] [blame] | 129 | setOperationAction(ISD::SETCC, MVT::f32,   Promote); | 
| Andrew Lenharth | 572af90 | 2005-02-14 05:41:43 +0000 | [diff] [blame] | 130 |  | 
| Andrew Lenharth | e3c8c0a4 | 2005-05-31 19:49:34 +0000 | [diff] [blame] | 131 | //Try a couple things with a custom expander | 
|  | 132 | //setOperationAction(ISD::SINT_TO_FP       , MVT::i64  , Custom); | 
|  | 133 |  | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 134 | computeRegisterProperties(); | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 135 |  | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 136 | addLegalFPImmediate(+0.0); //F31 | 
|  | 137 | addLegalFPImmediate(-0.0); //-F31 | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 138 | } | 
|  | 139 |  | 
| Andrew Lenharth | e3c8c0a4 | 2005-05-31 19:49:34 +0000 | [diff] [blame] | 140 | /// LowerOperation - Provide custom lowering hooks for some operations. | 
|  | 141 | /// | 
|  | 142 | virtual SDOperand LowerOperation(SDOperand Op, SelectionDAG &DAG); | 
|  | 143 |  | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 144 | /// LowerArguments - This hook must be implemented to indicate how we should | 
|  | 145 | /// lower the arguments for the specified function, into the specified DAG. | 
|  | 146 | virtual std::vector<SDOperand> | 
|  | 147 | LowerArguments(Function &F, SelectionDAG &DAG); | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 148 |  | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 149 | /// LowerCallTo - This hook lowers an abstract call to a function into an | 
|  | 150 | /// actual call. | 
|  | 151 | virtual std::pair<SDOperand, SDOperand> | 
| Chris Lattner | c57f682 | 2005-05-12 19:56:45 +0000 | [diff] [blame] | 152 | LowerCallTo(SDOperand Chain, const Type *RetTy, bool isVarArg, unsigned CC, | 
| Chris Lattner | adf6a96 | 2005-05-13 18:50:42 +0000 | [diff] [blame] | 153 | bool isTailCall, SDOperand Callee, ArgListTy &Args, | 
|  | 154 | SelectionDAG &DAG); | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 155 |  | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 156 | virtual std::pair<SDOperand, SDOperand> | 
| Andrew Lenharth | 558bc88 | 2005-06-18 18:34:52 +0000 | [diff] [blame] | 157 | LowerVAStart(SDOperand Chain, SelectionDAG &DAG, SDOperand Dest); | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 158 |  | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 159 | virtual std::pair<SDOperand,SDOperand> | 
| Andrew Lenharth | 558bc88 | 2005-06-18 18:34:52 +0000 | [diff] [blame] | 160 | LowerVAArgNext(SDOperand Chain, SDOperand VAList, | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 161 | const Type *ArgTy, SelectionDAG &DAG); | 
|  | 162 |  | 
| Andrew Lenharth | cdf233d | 2005-06-22 23:04:28 +0000 | [diff] [blame] | 163 | std::pair<SDOperand,SDOperand> | 
|  | 164 | LowerVACopy(SDOperand Chain, SDOperand Src, SDOperand Dest, | 
|  | 165 | SelectionDAG &DAG); | 
|  | 166 |  | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 167 | virtual std::pair<SDOperand, SDOperand> | 
|  | 168 | LowerFrameReturnAddress(bool isFrameAddr, SDOperand Chain, unsigned Depth, | 
|  | 169 | SelectionDAG &DAG); | 
|  | 170 |  | 
|  | 171 | void restoreGP(MachineBasicBlock* BB) | 
|  | 172 | { | 
|  | 173 | BuildMI(BB, Alpha::BIS, 2, Alpha::R29).addReg(GP).addReg(GP); | 
|  | 174 | } | 
| Andrew Lenharth | 3f5aa1c | 2005-06-23 23:42:05 +0000 | [diff] [blame] | 175 | void restoreRA(MachineBasicBlock* BB) | 
|  | 176 | { | 
|  | 177 | BuildMI(BB, Alpha::BIS, 2, Alpha::R26).addReg(RA).addReg(RA); | 
|  | 178 | } | 
|  | 179 |  | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 180 | }; | 
|  | 181 | } | 
|  | 182 |  | 
| Andrew Lenharth | e3c8c0a4 | 2005-05-31 19:49:34 +0000 | [diff] [blame] | 183 | /// LowerOperation - Provide custom lowering hooks for some operations. | 
|  | 184 | /// | 
|  | 185 | SDOperand AlphaTargetLowering::LowerOperation(SDOperand Op, SelectionDAG &DAG) { | 
|  | 186 | MachineFunction &MF = DAG.getMachineFunction(); | 
|  | 187 | switch (Op.getOpcode()) { | 
|  | 188 | default: assert(0 && "Should not custom lower this!"); | 
| Misha Brukman | b8ee91a | 2005-06-06 17:39:46 +0000 | [diff] [blame] | 189 | #if 0 | 
|  | 190 | case ISD::SINT_TO_FP: | 
|  | 191 | { | 
|  | 192 | assert (Op.getOperand(0).getValueType() == MVT::i64 | 
|  | 193 | && "only quads can be loaded from"); | 
|  | 194 | SDOperand SRC; | 
|  | 195 | if (EnableAlphaFTOI) | 
|  | 196 | { | 
|  | 197 | std::vector<MVT::ValueType> RTs; | 
|  | 198 | RTs.push_back(Op.getValueType()); | 
|  | 199 | std::vector<SDOperand> Ops; | 
|  | 200 | Ops.push_back(Op.getOperand(0)); | 
|  | 201 | SRC = DAG.getNode(AlphaISD::ITOF, RTs, Ops); | 
|  | 202 | } else { | 
|  | 203 | int SSFI = MF.getFrameInfo()->CreateStackObject(8, 8); | 
|  | 204 | SDOperand StackSlot = DAG.getFrameIndex(SSFI, getPointerTy()); | 
|  | 205 | SDOperand Store = DAG.getNode(ISD::STORE, MVT::Other, DAG.getEntryNode(), | 
|  | 206 | Op.getOperand(0), StackSlot, DAG.getSrcValue(NULL)); | 
|  | 207 | SRC = DAG.getLoad(Op.getValueType(), Store.getValue(0), StackSlot, | 
|  | 208 | DAG.getSrcValue(NULL)); | 
|  | 209 | } | 
|  | 210 | std::vector<MVT::ValueType> RTs; | 
|  | 211 | RTs.push_back(Op.getValueType()); | 
|  | 212 | std::vector<SDOperand> Ops; | 
|  | 213 | Ops.push_back(SRC); | 
|  | 214 | return DAG.getNode(AlphaISD::CVTQ, RTs, Ops); | 
|  | 215 | } | 
|  | 216 | #endif | 
| Andrew Lenharth | e3c8c0a4 | 2005-05-31 19:49:34 +0000 | [diff] [blame] | 217 | } | 
| Misha Brukman | b8ee91a | 2005-06-06 17:39:46 +0000 | [diff] [blame] | 218 | return SDOperand(); | 
| Andrew Lenharth | e3c8c0a4 | 2005-05-31 19:49:34 +0000 | [diff] [blame] | 219 | } | 
|  | 220 |  | 
|  | 221 |  | 
| Andrew Lenharth | fd5e4b7 | 2005-05-31 18:35:43 +0000 | [diff] [blame] | 222 | /// AddLiveIn - This helper function adds the specified physical register to the | 
|  | 223 | /// MachineFunction as a live in value.  It also creates a corresponding virtual | 
|  | 224 | /// register for it. | 
|  | 225 | static unsigned AddLiveIn(MachineFunction &MF, unsigned PReg, | 
|  | 226 | TargetRegisterClass *RC) { | 
|  | 227 | assert(RC->contains(PReg) && "Not the correct regclass!"); | 
|  | 228 | unsigned VReg = MF.getSSARegMap()->createVirtualRegister(RC); | 
|  | 229 | MF.addLiveIn(PReg, VReg); | 
|  | 230 | return VReg; | 
|  | 231 | } | 
|  | 232 |  | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 233 | //http://www.cs.arizona.edu/computer.help/policy/DIGITAL_unix/AA-PY8AC-TET1_html/callCH3.html#BLOCK21 | 
|  | 234 |  | 
|  | 235 | //For now, just use variable size stack frame format | 
|  | 236 |  | 
|  | 237 | //In a standard call, the first six items are passed in registers $16 | 
|  | 238 | //- $21 and/or registers $f16 - $f21. (See Section 4.1.2 for details | 
|  | 239 | //of argument-to-register correspondence.) The remaining items are | 
|  | 240 | //collected in a memory argument list that is a naturally aligned | 
|  | 241 | //array of quadwords. In a standard call, this list, if present, must | 
|  | 242 | //be passed at 0(SP). | 
| Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 243 | //7 ... n         0(SP) ... (n-7)*8(SP) | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 244 |  | 
| Andrew Lenharth | 2513ddc | 2005-04-05 20:51:46 +0000 | [diff] [blame] | 245 | // //#define FP    $15 | 
|  | 246 | // //#define RA    $26 | 
|  | 247 | // //#define PV    $27 | 
|  | 248 | // //#define GP    $29 | 
|  | 249 | // //#define SP    $30 | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 250 |  | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 251 | std::vector<SDOperand> | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 252 | AlphaTargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 253 | { | 
|  | 254 | std::vector<SDOperand> ArgValues; | 
| Andrew Lenharth | 2513ddc | 2005-04-05 20:51:46 +0000 | [diff] [blame] | 255 |  | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 256 | MachineFunction &MF = DAG.getMachineFunction(); | 
| Andrew Lenharth | 0538034 | 2005-02-07 05:07:00 +0000 | [diff] [blame] | 257 | MachineFrameInfo*MFI = MF.getFrameInfo(); | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 258 |  | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 259 | MachineBasicBlock& BB = MF.front(); | 
|  | 260 |  | 
|  | 261 | //Handle the return address | 
|  | 262 | //BuildMI(&BB, Alpha::IDEF, 0, Alpha::R26); | 
|  | 263 |  | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 264 | unsigned args_int[] = {Alpha::R16, Alpha::R17, Alpha::R18, | 
| Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 265 | Alpha::R19, Alpha::R20, Alpha::R21}; | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 266 | unsigned args_float[] = {Alpha::F16, Alpha::F17, Alpha::F18, | 
| Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 267 | Alpha::F19, Alpha::F20, Alpha::F21}; | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 268 | int count = 0; | 
| Andrew Lenharth | 2c9e38c | 2005-02-06 21:07:31 +0000 | [diff] [blame] | 269 |  | 
| Andrew Lenharth | fd5e4b7 | 2005-05-31 18:35:43 +0000 | [diff] [blame] | 270 | GP = AddLiveIn(MF, Alpha::R29, getRegClassFor(MVT::i64)); | 
| Andrew Lenharth | 3f5aa1c | 2005-06-23 23:42:05 +0000 | [diff] [blame] | 271 | RA = AddLiveIn(MF, Alpha::R26, getRegClassFor(MVT::i64)); | 
| Andrew Lenharth | 2513ddc | 2005-04-05 20:51:46 +0000 | [diff] [blame] | 272 |  | 
| Chris Lattner | e4d5c44 | 2005-03-15 04:54:21 +0000 | [diff] [blame] | 273 | for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; ++I) | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 274 | { | 
| Andrew Lenharth | fd5e4b7 | 2005-05-31 18:35:43 +0000 | [diff] [blame] | 275 | SDOperand argt; | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 276 | if (count  < 6) { | 
| Andrew Lenharth | 2513ddc | 2005-04-05 20:51:46 +0000 | [diff] [blame] | 277 | unsigned Vreg; | 
|  | 278 | MVT::ValueType VT = getValueType(I->getType()); | 
| Andrew Lenharth | fd5e4b7 | 2005-05-31 18:35:43 +0000 | [diff] [blame] | 279 | switch (VT) { | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 280 | default: | 
|  | 281 | std::cerr << "Unknown Type " << VT << "\n"; | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 282 | abort(); | 
|  | 283 | case MVT::f64: | 
|  | 284 | case MVT::f32: | 
| Andrew Lenharth | fd5e4b7 | 2005-05-31 18:35:43 +0000 | [diff] [blame] | 285 | args_float[count] = AddLiveIn(MF,args_float[count], getRegClassFor(VT)); | 
|  | 286 | argt = DAG.getCopyFromReg(args_float[count], VT, DAG.getRoot()); | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 287 | break; | 
|  | 288 | case MVT::i1: | 
|  | 289 | case MVT::i8: | 
|  | 290 | case MVT::i16: | 
|  | 291 | case MVT::i32: | 
|  | 292 | case MVT::i64: | 
| Andrew Lenharth | 591ec57 | 2005-05-31 18:42:18 +0000 | [diff] [blame] | 293 | args_int[count] = AddLiveIn(MF, args_int[count], getRegClassFor(MVT::i64)); | 
| Andrew Lenharth | fd5e4b7 | 2005-05-31 18:35:43 +0000 | [diff] [blame] | 294 | argt = DAG.getCopyFromReg(args_int[count], VT, DAG.getRoot()); | 
| Andrew Lenharth | 14f30c9 | 2005-05-31 18:37:16 +0000 | [diff] [blame] | 295 | if (VT != MVT::i64) | 
|  | 296 | argt = DAG.getNode(ISD::TRUNCATE, VT, argt); | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 297 | break; | 
| Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 298 | } | 
| Andrew Lenharth | fd5e4b7 | 2005-05-31 18:35:43 +0000 | [diff] [blame] | 299 | DAG.setRoot(argt.getValue(1)); | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 300 | } else { //more args | 
|  | 301 | // Create the frame index object for this incoming parameter... | 
|  | 302 | int FI = MFI->CreateFixedObject(8, 8 * (count - 6)); | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 303 |  | 
|  | 304 | // Create the SelectionDAG nodes corresponding to a load | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 305 | //from this parameter | 
|  | 306 | SDOperand FIN = DAG.getFrameIndex(FI, MVT::i64); | 
| Andrew Lenharth | fd5e4b7 | 2005-05-31 18:35:43 +0000 | [diff] [blame] | 307 | argt = DAG.getLoad(getValueType(I->getType()), | 
|  | 308 | DAG.getEntryNode(), FIN, DAG.getSrcValue(NULL)); | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 309 | } | 
| Andrew Lenharth | 032f235 | 2005-02-22 21:59:48 +0000 | [diff] [blame] | 310 | ++count; | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 311 | ArgValues.push_back(argt); | 
|  | 312 | } | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 313 |  | 
| Andrew Lenharth | 2513ddc | 2005-04-05 20:51:46 +0000 | [diff] [blame] | 314 | // If the functions takes variable number of arguments, copy all regs to stack | 
| Andrew Lenharth | fd5e4b7 | 2005-05-31 18:35:43 +0000 | [diff] [blame] | 315 | if (F.isVarArg()) { | 
| Andrew Lenharth | 558bc88 | 2005-06-18 18:34:52 +0000 | [diff] [blame] | 316 | VarArgsOffset = count * 8; | 
| Andrew Lenharth | fd5e4b7 | 2005-05-31 18:35:43 +0000 | [diff] [blame] | 317 | std::vector<SDOperand> LS; | 
|  | 318 | for (int i = 0; i < 6; ++i) { | 
|  | 319 | if (args_int[i] < 1024) | 
|  | 320 | args_int[i] = AddLiveIn(MF,args_int[i], getRegClassFor(MVT::i64)); | 
|  | 321 | SDOperand argt = DAG.getCopyFromReg(args_int[i], MVT::i64, DAG.getRoot()); | 
| Andrew Lenharth | 2513ddc | 2005-04-05 20:51:46 +0000 | [diff] [blame] | 322 | int FI = MFI->CreateFixedObject(8, -8 * (6 - i)); | 
| Andrew Lenharth | 558bc88 | 2005-06-18 18:34:52 +0000 | [diff] [blame] | 323 | if (i == 0) VarArgsBase = FI; | 
| Andrew Lenharth | 2513ddc | 2005-04-05 20:51:46 +0000 | [diff] [blame] | 324 | SDOperand SDFI = DAG.getFrameIndex(FI, MVT::i64); | 
| Andrew Lenharth | fd5e4b7 | 2005-05-31 18:35:43 +0000 | [diff] [blame] | 325 | LS.push_back(DAG.getNode(ISD::STORE, MVT::Other, DAG.getRoot(), argt, SDFI, DAG.getSrcValue(NULL))); | 
|  | 326 |  | 
|  | 327 | if (args_float[i] < 1024) | 
|  | 328 | args_float[i] = AddLiveIn(MF,args_float[i], getRegClassFor(MVT::f64)); | 
|  | 329 | argt = DAG.getCopyFromReg(args_float[i], MVT::f64, DAG.getRoot()); | 
| Andrew Lenharth | 2513ddc | 2005-04-05 20:51:46 +0000 | [diff] [blame] | 330 | FI = MFI->CreateFixedObject(8, - 8 * (12 - i)); | 
|  | 331 | SDFI = DAG.getFrameIndex(FI, MVT::i64); | 
| Andrew Lenharth | fd5e4b7 | 2005-05-31 18:35:43 +0000 | [diff] [blame] | 332 | LS.push_back(DAG.getNode(ISD::STORE, MVT::Other, DAG.getRoot(), argt, SDFI, DAG.getSrcValue(NULL))); | 
| Andrew Lenharth | 2513ddc | 2005-04-05 20:51:46 +0000 | [diff] [blame] | 333 | } | 
|  | 334 |  | 
| Andrew Lenharth | fd5e4b7 | 2005-05-31 18:35:43 +0000 | [diff] [blame] | 335 | //Set up a token factor with all the stack traffic | 
|  | 336 | DAG.setRoot(DAG.getNode(ISD::TokenFactor, MVT::Other, LS)); | 
|  | 337 | } | 
| Andrew Lenharth | e1c5a00 | 2005-04-12 17:35:16 +0000 | [diff] [blame] | 338 |  | 
|  | 339 | // Finally, inform the code generator which regs we return values in. | 
|  | 340 | switch (getValueType(F.getReturnType())) { | 
|  | 341 | default: assert(0 && "Unknown type!"); | 
|  | 342 | case MVT::isVoid: break; | 
|  | 343 | case MVT::i1: | 
|  | 344 | case MVT::i8: | 
|  | 345 | case MVT::i16: | 
|  | 346 | case MVT::i32: | 
|  | 347 | case MVT::i64: | 
|  | 348 | MF.addLiveOut(Alpha::R0); | 
|  | 349 | break; | 
|  | 350 | case MVT::f32: | 
|  | 351 | case MVT::f64: | 
|  | 352 | MF.addLiveOut(Alpha::F0); | 
|  | 353 | break; | 
|  | 354 | } | 
|  | 355 |  | 
| Andrew Lenharth | 2513ddc | 2005-04-05 20:51:46 +0000 | [diff] [blame] | 356 | //return the arguments | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 357 | return ArgValues; | 
|  | 358 | } | 
|  | 359 |  | 
|  | 360 | std::pair<SDOperand, SDOperand> | 
|  | 361 | AlphaTargetLowering::LowerCallTo(SDOperand Chain, | 
| Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 362 | const Type *RetTy, bool isVarArg, | 
| Chris Lattner | adf6a96 | 2005-05-13 18:50:42 +0000 | [diff] [blame] | 363 | unsigned CallingConv, bool isTailCall, | 
| Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 364 | SDOperand Callee, ArgListTy &Args, | 
|  | 365 | SelectionDAG &DAG) { | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 366 | int NumBytes = 0; | 
| Andrew Lenharth | 684f229 | 2005-01-30 00:35:27 +0000 | [diff] [blame] | 367 | if (Args.size() > 6) | 
|  | 368 | NumBytes = (Args.size() - 6) * 8; | 
|  | 369 |  | 
| Chris Lattner | 16cd04d | 2005-05-12 23:24:06 +0000 | [diff] [blame] | 370 | Chain = DAG.getNode(ISD::CALLSEQ_START, MVT::Other, Chain, | 
| Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 371 | DAG.getConstant(NumBytes, getPointerTy())); | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 372 | std::vector<SDOperand> args_to_use; | 
|  | 373 | for (unsigned i = 0, e = Args.size(); i != e; ++i) | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 374 | { | 
|  | 375 | switch (getValueType(Args[i].second)) { | 
|  | 376 | default: assert(0 && "Unexpected ValueType for argument!"); | 
|  | 377 | case MVT::i1: | 
|  | 378 | case MVT::i8: | 
|  | 379 | case MVT::i16: | 
|  | 380 | case MVT::i32: | 
|  | 381 | // Promote the integer to 64 bits.  If the input type is signed use a | 
|  | 382 | // sign extend, otherwise use a zero extend. | 
|  | 383 | if (Args[i].second->isSigned()) | 
|  | 384 | Args[i].first = DAG.getNode(ISD::SIGN_EXTEND, MVT::i64, Args[i].first); | 
|  | 385 | else | 
|  | 386 | Args[i].first = DAG.getNode(ISD::ZERO_EXTEND, MVT::i64, Args[i].first); | 
|  | 387 | break; | 
|  | 388 | case MVT::i64: | 
|  | 389 | case MVT::f64: | 
|  | 390 | case MVT::f32: | 
|  | 391 | break; | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 392 | } | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 393 | args_to_use.push_back(Args[i].first); | 
|  | 394 | } | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 395 |  | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 396 | std::vector<MVT::ValueType> RetVals; | 
|  | 397 | MVT::ValueType RetTyVT = getValueType(RetTy); | 
|  | 398 | if (RetTyVT != MVT::isVoid) | 
|  | 399 | RetVals.push_back(RetTyVT); | 
|  | 400 | RetVals.push_back(MVT::Other); | 
|  | 401 |  | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 402 | SDOperand TheCall = SDOperand(DAG.getCall(RetVals, | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 403 | Chain, Callee, args_to_use), 0); | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 404 | Chain = TheCall.getValue(RetTyVT != MVT::isVoid); | 
| Chris Lattner | 16cd04d | 2005-05-12 23:24:06 +0000 | [diff] [blame] | 405 | Chain = DAG.getNode(ISD::CALLSEQ_END, MVT::Other, Chain, | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 406 | DAG.getConstant(NumBytes, getPointerTy())); | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 407 | return std::make_pair(TheCall, Chain); | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 408 | } | 
|  | 409 |  | 
|  | 410 | std::pair<SDOperand, SDOperand> | 
| Andrew Lenharth | 558bc88 | 2005-06-18 18:34:52 +0000 | [diff] [blame] | 411 | AlphaTargetLowering::LowerVAStart(SDOperand Chain, SelectionDAG &DAG, SDOperand Dest) { | 
|  | 412 | // vastart just stores the address of the VarArgsBase and VarArgsOffset | 
| Andrew Lenharth | a9e39e2 | 2005-06-23 16:48:51 +0000 | [diff] [blame] | 413 | SDOperand FR  = DAG.getFrameIndex(VarArgsBase, MVT::i64); | 
| Andrew Lenharth | 558bc88 | 2005-06-18 18:34:52 +0000 | [diff] [blame] | 414 | SDOperand S1  = DAG.getNode(ISD::STORE, MVT::Other, Chain, FR, Dest, DAG.getSrcValue(NULL)); | 
|  | 415 | SDOperand SA2 = DAG.getNode(ISD::ADD, MVT::i64, Dest, DAG.getConstant(8, MVT::i64)); | 
| Andrew Lenharth | a9e39e2 | 2005-06-23 16:48:51 +0000 | [diff] [blame] | 416 | SDOperand S2  = DAG.getNode(ISD::TRUNCSTORE, MVT::Other,   S1, | 
| Andrew Lenharth | 558bc88 | 2005-06-18 18:34:52 +0000 | [diff] [blame] | 417 | DAG.getConstant(VarArgsOffset, MVT::i64), SA2, | 
| Andrew Lenharth | a9e39e2 | 2005-06-23 16:48:51 +0000 | [diff] [blame] | 418 | DAG.getSrcValue(NULL), MVT::i32); | 
| Andrew Lenharth | 558bc88 | 2005-06-18 18:34:52 +0000 | [diff] [blame] | 419 | return std::make_pair(S2, S2); | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 420 | } | 
|  | 421 |  | 
|  | 422 | std::pair<SDOperand,SDOperand> AlphaTargetLowering:: | 
| Andrew Lenharth | 558bc88 | 2005-06-18 18:34:52 +0000 | [diff] [blame] | 423 | LowerVAArgNext(SDOperand Chain, SDOperand VAList, | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 424 | const Type *ArgTy, SelectionDAG &DAG) { | 
| Andrew Lenharth | 558bc88 | 2005-06-18 18:34:52 +0000 | [diff] [blame] | 425 | SDOperand Base = DAG.getLoad(MVT::i64, Chain, VAList, DAG.getSrcValue(NULL)); | 
|  | 426 | SDOperand Tmp = DAG.getNode(ISD::ADD, MVT::i64, VAList, | 
|  | 427 | DAG.getConstant(8, MVT::i64)); | 
| Andrew Lenharth | 3f5aa1c | 2005-06-23 23:42:05 +0000 | [diff] [blame] | 428 | SDOperand Offset = DAG.getNode(ISD::SEXTLOAD, MVT::i64, Base.getValue(1), Tmp, | 
| Andrew Lenharth | a9e39e2 | 2005-06-23 16:48:51 +0000 | [diff] [blame] | 429 | DAG.getSrcValue(NULL), MVT::i32); | 
| Andrew Lenharth | 558bc88 | 2005-06-18 18:34:52 +0000 | [diff] [blame] | 430 | SDOperand DataPtr = DAG.getNode(ISD::ADD, MVT::i64, Base, Offset); | 
| Andrew Lenharth | cdf233d | 2005-06-22 23:04:28 +0000 | [diff] [blame] | 431 | if (ArgTy->isFloatingPoint()) | 
|  | 432 | { | 
|  | 433 | //if fp && Offset < 6*8, then subtract 6*8 from DataPtr | 
|  | 434 | SDOperand FPDataPtr = DAG.getNode(ISD::SUB, MVT::i64, DataPtr, | 
|  | 435 | DAG.getConstant(8*6, MVT::i64)); | 
|  | 436 | SDOperand CC = DAG.getSetCC(ISD::SETLT, MVT::i64, | 
|  | 437 | Offset, DAG.getConstant(8*6, MVT::i64)); | 
|  | 438 | DataPtr = DAG.getNode(ISD::SELECT, MVT::i64, CC, FPDataPtr, DataPtr); | 
|  | 439 | } | 
|  | 440 |  | 
| Andrew Lenharth | a9e39e2 | 2005-06-23 16:48:51 +0000 | [diff] [blame] | 441 | SDOperand Result; | 
|  | 442 | if (ArgTy == Type::IntTy) | 
| Andrew Lenharth | 3f5aa1c | 2005-06-23 23:42:05 +0000 | [diff] [blame] | 443 | Result = DAG.getNode(ISD::SEXTLOAD, MVT::i64, Offset.getValue(1), DataPtr, | 
| Andrew Lenharth | a9e39e2 | 2005-06-23 16:48:51 +0000 | [diff] [blame] | 444 | DAG.getSrcValue(NULL), MVT::i32); | 
|  | 445 | else if (ArgTy == Type::UIntTy) | 
| Andrew Lenharth | 3f5aa1c | 2005-06-23 23:42:05 +0000 | [diff] [blame] | 446 | Result = DAG.getNode(ISD::ZEXTLOAD, MVT::i64, Offset.getValue(1), DataPtr, | 
| Andrew Lenharth | a9e39e2 | 2005-06-23 16:48:51 +0000 | [diff] [blame] | 447 | DAG.getSrcValue(NULL), MVT::i32); | 
|  | 448 | else | 
| Andrew Lenharth | 3f5aa1c | 2005-06-23 23:42:05 +0000 | [diff] [blame] | 449 | Result = DAG.getLoad(getValueType(ArgTy), Offset.getValue(1), DataPtr, | 
| Andrew Lenharth | a9e39e2 | 2005-06-23 16:48:51 +0000 | [diff] [blame] | 450 | DAG.getSrcValue(NULL)); | 
|  | 451 |  | 
| Andrew Lenharth | 558bc88 | 2005-06-18 18:34:52 +0000 | [diff] [blame] | 452 | SDOperand NewOffset = DAG.getNode(ISD::ADD, MVT::i64, Offset, | 
|  | 453 | DAG.getConstant(8, MVT::i64)); | 
| Andrew Lenharth | 3f5aa1c | 2005-06-23 23:42:05 +0000 | [diff] [blame] | 454 | SDOperand Update = DAG.getNode(ISD::TRUNCSTORE, MVT::Other, Result.getValue(1), NewOffset, | 
| Andrew Lenharth | a9e39e2 | 2005-06-23 16:48:51 +0000 | [diff] [blame] | 455 | Tmp, DAG.getSrcValue(NULL), MVT::i32); | 
|  | 456 | Result = DAG.getNode(ISD::TRUNCATE, getValueType(ArgTy), Result); | 
|  | 457 |  | 
| Andrew Lenharth | 558bc88 | 2005-06-18 18:34:52 +0000 | [diff] [blame] | 458 | return std::make_pair(Result, Update); | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 459 | } | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 460 |  | 
| Andrew Lenharth | cdf233d | 2005-06-22 23:04:28 +0000 | [diff] [blame] | 461 | std::pair<SDOperand,SDOperand> AlphaTargetLowering:: | 
|  | 462 | LowerVACopy(SDOperand Chain, SDOperand Src, SDOperand Dest, | 
|  | 463 | SelectionDAG &DAG) { | 
|  | 464 | //Default to returning the input list | 
|  | 465 | SDOperand Val = DAG.getLoad(getPointerTy(), Chain, Src, DAG.getSrcValue(NULL)); | 
|  | 466 | SDOperand Result = DAG.getNode(ISD::STORE, MVT::Other, Val.getValue(1), | 
|  | 467 | Val, Dest, DAG.getSrcValue(NULL)); | 
|  | 468 | SDOperand NP = DAG.getNode(ISD::ADD, MVT::i64, Src, | 
|  | 469 | DAG.getConstant(8, MVT::i64)); | 
| Andrew Lenharth | 3f5aa1c | 2005-06-23 23:42:05 +0000 | [diff] [blame] | 470 | Val = DAG.getNode(ISD::SEXTLOAD, MVT::i64, Result, NP, DAG.getSrcValue(NULL), | 
| Andrew Lenharth | a9e39e2 | 2005-06-23 16:48:51 +0000 | [diff] [blame] | 471 | MVT::i32); | 
| Andrew Lenharth | 3f5aa1c | 2005-06-23 23:42:05 +0000 | [diff] [blame] | 472 | SDOperand NPD = DAG.getNode(ISD::ADD, MVT::i64, Dest, | 
|  | 473 | DAG.getConstant(8, MVT::i64)); | 
| Andrew Lenharth | a9e39e2 | 2005-06-23 16:48:51 +0000 | [diff] [blame] | 474 | Result = DAG.getNode(ISD::TRUNCSTORE, MVT::Other, Val.getValue(1), | 
| Andrew Lenharth | 3f5aa1c | 2005-06-23 23:42:05 +0000 | [diff] [blame] | 475 | Val, NPD, DAG.getSrcValue(NULL), MVT::i32); | 
| Andrew Lenharth | cdf233d | 2005-06-22 23:04:28 +0000 | [diff] [blame] | 476 | return std::make_pair(Result, Result); | 
|  | 477 | } | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 478 |  | 
|  | 479 | std::pair<SDOperand, SDOperand> AlphaTargetLowering:: | 
|  | 480 | LowerFrameReturnAddress(bool isFrameAddress, SDOperand Chain, unsigned Depth, | 
|  | 481 | SelectionDAG &DAG) { | 
|  | 482 | abort(); | 
|  | 483 | } | 
|  | 484 |  | 
|  | 485 |  | 
|  | 486 |  | 
|  | 487 |  | 
|  | 488 |  | 
|  | 489 | namespace { | 
|  | 490 |  | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 491 | //===--------------------------------------------------------------------===// | 
|  | 492 | /// ISel - Alpha specific code to select Alpha machine instructions for | 
|  | 493 | /// SelectionDAG operations. | 
|  | 494 | //===--------------------------------------------------------------------===// | 
| Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 495 | class AlphaISel : public SelectionDAGISel { | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 496 |  | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 497 | /// AlphaLowering - This object fully describes how to lower LLVM code to an | 
|  | 498 | /// Alpha-specific SelectionDAG. | 
|  | 499 | AlphaTargetLowering AlphaLowering; | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 500 |  | 
| Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 501 | SelectionDAG *ISelDAG;  // Hack to support us having a dag->dag transform | 
|  | 502 | // for sdiv and udiv until it is put into the future | 
|  | 503 | // dag combiner. | 
|  | 504 |  | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 505 | /// ExprMap - As shared expressions are codegen'd, we keep track of which | 
|  | 506 | /// vreg the value is produced in, so we only emit one copy of each compiled | 
|  | 507 | /// tree. | 
|  | 508 | static const unsigned notIn = (unsigned)(-1); | 
|  | 509 | std::map<SDOperand, unsigned> ExprMap; | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 510 |  | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 511 | //CCInvMap sometimes (SetNE) we have the inverse CC code for free | 
|  | 512 | std::map<SDOperand, unsigned> CCInvMap; | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 513 |  | 
| Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 514 | int count_ins; | 
|  | 515 | int count_outs; | 
|  | 516 | bool has_sym; | 
| Andrew Lenharth | 500b4db | 2005-04-22 13:35:18 +0000 | [diff] [blame] | 517 | int max_depth; | 
| Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 518 |  | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 519 | public: | 
| Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 520 | AlphaISel(TargetMachine &TM) : SelectionDAGISel(AlphaLowering), AlphaLowering(TM) | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 521 | {} | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 522 |  | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 523 | /// InstructionSelectBasicBlock - This callback is invoked by | 
|  | 524 | /// SelectionDAGISel when it has created a SelectionDAG for us to codegen. | 
|  | 525 | virtual void InstructionSelectBasicBlock(SelectionDAG &DAG) { | 
| Andrew Lenharth | 032f235 | 2005-02-22 21:59:48 +0000 | [diff] [blame] | 526 | DEBUG(BB->dump()); | 
| Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 527 | count_ins = 0; | 
|  | 528 | count_outs = 0; | 
| Andrew Lenharth | 500b4db | 2005-04-22 13:35:18 +0000 | [diff] [blame] | 529 | max_depth = 0; | 
| Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 530 | has_sym = false; | 
|  | 531 |  | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 532 | // Codegen the basic block. | 
| Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 533 | ISelDAG = &DAG; | 
| Andrew Lenharth | 500b4db | 2005-04-22 13:35:18 +0000 | [diff] [blame] | 534 | max_depth = DAG.getRoot().getNodeDepth(); | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 535 | Select(DAG.getRoot()); | 
| Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 536 |  | 
|  | 537 | if(has_sym) | 
|  | 538 | ++count_ins; | 
|  | 539 | if(EnableAlphaCount) | 
| Andrew Lenharth | 500b4db | 2005-04-22 13:35:18 +0000 | [diff] [blame] | 540 | std::cerr << "COUNT: " << BB->getParent()->getFunction ()->getName() << " " | 
|  | 541 | << BB->getNumber() << " " | 
|  | 542 | << max_depth << " " | 
| Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 543 | << count_ins << " " | 
|  | 544 | << count_outs << "\n"; | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 545 |  | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 546 | // Clear state used for selection. | 
|  | 547 | ExprMap.clear(); | 
|  | 548 | CCInvMap.clear(); | 
|  | 549 | } | 
| Andrew Lenharth | fd5e4b7 | 2005-05-31 18:35:43 +0000 | [diff] [blame] | 550 |  | 
|  | 551 | virtual void EmitFunctionEntryCode(Function &Fn, MachineFunction &MF); | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 552 |  | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 553 | unsigned SelectExpr(SDOperand N); | 
|  | 554 | unsigned SelectExprFP(SDOperand N, unsigned Result); | 
|  | 555 | void Select(SDOperand N); | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 556 |  | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 557 | void SelectAddr(SDOperand N, unsigned& Reg, long& offset); | 
|  | 558 | void SelectBranchCC(SDOperand N); | 
| Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 559 | void MoveFP2Int(unsigned src, unsigned dst, bool isDouble); | 
|  | 560 | void MoveInt2FP(unsigned src, unsigned dst, bool isDouble); | 
| Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 561 | //returns whether the sense of the comparison was inverted | 
|  | 562 | bool SelectFPSetCC(SDOperand N, unsigned dst); | 
| Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 563 |  | 
|  | 564 | // dag -> dag expanders for integer divide by constant | 
|  | 565 | SDOperand BuildSDIVSequence(SDOperand N); | 
|  | 566 | SDOperand BuildUDIVSequence(SDOperand N); | 
|  | 567 |  | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 568 | }; | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 569 | } | 
|  | 570 |  | 
| Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 571 | void AlphaISel::EmitFunctionEntryCode(Function &Fn, MachineFunction &MF) { | 
| Andrew Lenharth | fd5e4b7 | 2005-05-31 18:35:43 +0000 | [diff] [blame] | 572 | // If this function has live-in values, emit the copies from pregs to vregs at | 
|  | 573 | // the top of the function, before anything else. | 
|  | 574 | MachineBasicBlock *BB = MF.begin(); | 
|  | 575 | if (MF.livein_begin() != MF.livein_end()) { | 
|  | 576 | SSARegMap *RegMap = MF.getSSARegMap(); | 
|  | 577 | for (MachineFunction::livein_iterator LI = MF.livein_begin(), | 
|  | 578 | E = MF.livein_end(); LI != E; ++LI) { | 
|  | 579 | const TargetRegisterClass *RC = RegMap->getRegClass(LI->second); | 
|  | 580 | if (RC == Alpha::GPRCRegisterClass) { | 
|  | 581 | BuildMI(BB, Alpha::BIS, 2, LI->second).addReg(LI->first).addReg(LI->first); | 
|  | 582 | } else if (RC == Alpha::FPRCRegisterClass) { | 
|  | 583 | BuildMI(BB, Alpha::CPYS, 2, LI->second).addReg(LI->first).addReg(LI->first); | 
|  | 584 | } else { | 
|  | 585 | assert(0 && "Unknown regclass!"); | 
|  | 586 | } | 
|  | 587 | } | 
|  | 588 | } | 
|  | 589 | } | 
|  | 590 |  | 
| Andrew Lenharth | cd7f8cf | 2005-06-06 19:03:55 +0000 | [diff] [blame] | 591 | //Find the offset of the arg in it's parent's function | 
|  | 592 | static int getValueOffset(const Value* v) | 
|  | 593 | { | 
| Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 594 | static int uniqneg = -1; | 
| Andrew Lenharth | cd7f8cf | 2005-06-06 19:03:55 +0000 | [diff] [blame] | 595 | if (v == NULL) | 
| Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 596 | return uniqneg--; | 
| Andrew Lenharth | cd7f8cf | 2005-06-06 19:03:55 +0000 | [diff] [blame] | 597 |  | 
|  | 598 | const Instruction* itarget = dyn_cast<Instruction>(v); | 
|  | 599 | const BasicBlock* btarget = itarget->getParent(); | 
|  | 600 | const Function* ftarget = btarget->getParent(); | 
|  | 601 |  | 
|  | 602 | //offset due to earlier BBs | 
|  | 603 | int i = 0; | 
|  | 604 | for(Function::const_iterator ii = ftarget->begin(); &*ii != btarget; ++ii) | 
|  | 605 | i += ii->size(); | 
|  | 606 |  | 
|  | 607 | for(BasicBlock::const_iterator ii = btarget->begin(); &*ii != itarget; ++ii) | 
|  | 608 | ++i; | 
|  | 609 |  | 
|  | 610 | return i; | 
|  | 611 | } | 
| Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 612 | //Find the offset of the function in it's module | 
|  | 613 | static int getFunctionOffset(const Function* fun) | 
|  | 614 | { | 
|  | 615 | const Module* M = fun->getParent(); | 
|  | 616 |  | 
|  | 617 | //offset due to earlier BBs | 
|  | 618 | int i = 0; | 
|  | 619 | for(Module::const_iterator ii = M->begin(); &*ii != fun; ++ii) | 
|  | 620 | ++i; | 
|  | 621 |  | 
|  | 622 | return i; | 
|  | 623 | } | 
|  | 624 |  | 
|  | 625 | static int getUID() | 
|  | 626 | { | 
|  | 627 | static int id = 0; | 
|  | 628 | return ++id; | 
|  | 629 | } | 
| Andrew Lenharth | cd7f8cf | 2005-06-06 19:03:55 +0000 | [diff] [blame] | 630 |  | 
| Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 631 | //Factorize a number using the list of constants | 
|  | 632 | static bool factorize(int v[], int res[], int size, uint64_t c) | 
|  | 633 | { | 
|  | 634 | bool cont = true; | 
|  | 635 | while (c != 1 && cont) | 
|  | 636 | { | 
|  | 637 | cont = false; | 
|  | 638 | for(int i = 0; i < size; ++i) | 
|  | 639 | { | 
|  | 640 | if (c % v[i] == 0) | 
|  | 641 | { | 
|  | 642 | c /= v[i]; | 
|  | 643 | ++res[i]; | 
|  | 644 | cont=true; | 
|  | 645 | } | 
|  | 646 | } | 
|  | 647 | } | 
|  | 648 | return c == 1; | 
|  | 649 | } | 
|  | 650 |  | 
|  | 651 |  | 
| Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 652 | //Shamelessly adapted from PPC32 | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 653 | // Structure used to return the necessary information to codegen an SDIV as | 
| Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 654 | // a multiply. | 
|  | 655 | struct ms { | 
|  | 656 | int64_t m; // magic number | 
|  | 657 | int64_t s; // shift amount | 
|  | 658 | }; | 
|  | 659 |  | 
|  | 660 | struct mu { | 
|  | 661 | uint64_t m; // magic number | 
|  | 662 | int64_t a;          // add indicator | 
|  | 663 | int64_t s;          // shift amount | 
|  | 664 | }; | 
|  | 665 |  | 
|  | 666 | /// magic - calculate the magic numbers required to codegen an integer sdiv as | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 667 | /// a sequence of multiply and shifts.  Requires that the divisor not be 0, 1, | 
| Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 668 | /// or -1. | 
|  | 669 | static struct ms magic(int64_t d) { | 
|  | 670 | int64_t p; | 
|  | 671 | uint64_t ad, anc, delta, q1, r1, q2, r2, t; | 
|  | 672 | const uint64_t two63 = 9223372036854775808ULL; // 2^63 | 
|  | 673 | struct ms mag; | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 674 |  | 
| Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 675 | ad = abs(d); | 
|  | 676 | t = two63 + ((uint64_t)d >> 63); | 
|  | 677 | anc = t - 1 - t%ad;   // absolute value of nc | 
| Andrew Lenharth | 320174f | 2005-04-07 17:19:16 +0000 | [diff] [blame] | 678 | p = 63;               // initialize p | 
| Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 679 | q1 = two63/anc;       // initialize q1 = 2p/abs(nc) | 
|  | 680 | r1 = two63 - q1*anc;  // initialize r1 = rem(2p,abs(nc)) | 
|  | 681 | q2 = two63/ad;        // initialize q2 = 2p/abs(d) | 
|  | 682 | r2 = two63 - q2*ad;   // initialize r2 = rem(2p,abs(d)) | 
|  | 683 | do { | 
|  | 684 | p = p + 1; | 
|  | 685 | q1 = 2*q1;        // update q1 = 2p/abs(nc) | 
|  | 686 | r1 = 2*r1;        // update r1 = rem(2p/abs(nc)) | 
|  | 687 | if (r1 >= anc) {  // must be unsigned comparison | 
|  | 688 | q1 = q1 + 1; | 
|  | 689 | r1 = r1 - anc; | 
|  | 690 | } | 
|  | 691 | q2 = 2*q2;        // update q2 = 2p/abs(d) | 
|  | 692 | r2 = 2*r2;        // update r2 = rem(2p/abs(d)) | 
|  | 693 | if (r2 >= ad) {   // must be unsigned comparison | 
|  | 694 | q2 = q2 + 1; | 
|  | 695 | r2 = r2 - ad; | 
|  | 696 | } | 
|  | 697 | delta = ad - r2; | 
|  | 698 | } while (q1 < delta || (q1 == delta && r1 == 0)); | 
|  | 699 |  | 
|  | 700 | mag.m = q2 + 1; | 
|  | 701 | if (d < 0) mag.m = -mag.m; // resulting magic number | 
|  | 702 | mag.s = p - 64;            // resulting shift | 
|  | 703 | return mag; | 
|  | 704 | } | 
|  | 705 |  | 
|  | 706 | /// magicu - calculate the magic numbers required to codegen an integer udiv as | 
|  | 707 | /// a sequence of multiply, add and shifts.  Requires that the divisor not be 0. | 
|  | 708 | static struct mu magicu(uint64_t d) | 
|  | 709 | { | 
|  | 710 | int64_t p; | 
|  | 711 | uint64_t nc, delta, q1, r1, q2, r2; | 
|  | 712 | struct mu magu; | 
|  | 713 | magu.a = 0;               // initialize "add" indicator | 
|  | 714 | nc = - 1 - (-d)%d; | 
| Andrew Lenharth | 320174f | 2005-04-07 17:19:16 +0000 | [diff] [blame] | 715 | p = 63;                   // initialize p | 
|  | 716 | q1 = 0x8000000000000000ull/nc;       // initialize q1 = 2p/nc | 
|  | 717 | r1 = 0x8000000000000000ull - q1*nc;  // initialize r1 = rem(2p,nc) | 
|  | 718 | q2 = 0x7FFFFFFFFFFFFFFFull/d;        // initialize q2 = (2p-1)/d | 
|  | 719 | r2 = 0x7FFFFFFFFFFFFFFFull - q2*d;   // initialize r2 = rem((2p-1),d) | 
| Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 720 | do { | 
|  | 721 | p = p + 1; | 
|  | 722 | if (r1 >= nc - r1 ) { | 
|  | 723 | q1 = 2*q1 + 1;  // update q1 | 
|  | 724 | r1 = 2*r1 - nc; // update r1 | 
|  | 725 | } | 
|  | 726 | else { | 
|  | 727 | q1 = 2*q1; // update q1 | 
|  | 728 | r1 = 2*r1; // update r1 | 
|  | 729 | } | 
|  | 730 | if (r2 + 1 >= d - r2) { | 
| Andrew Lenharth | 320174f | 2005-04-07 17:19:16 +0000 | [diff] [blame] | 731 | if (q2 >= 0x7FFFFFFFFFFFFFFFull) magu.a = 1; | 
| Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 732 | q2 = 2*q2 + 1;     // update q2 | 
|  | 733 | r2 = 2*r2 + 1 - d; // update r2 | 
|  | 734 | } | 
|  | 735 | else { | 
| Andrew Lenharth | 320174f | 2005-04-07 17:19:16 +0000 | [diff] [blame] | 736 | if (q2 >= 0x8000000000000000ull) magu.a = 1; | 
| Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 737 | q2 = 2*q2;     // update q2 | 
|  | 738 | r2 = 2*r2 + 1; // update r2 | 
|  | 739 | } | 
|  | 740 | delta = d - 1 - r2; | 
|  | 741 | } while (p < 64 && (q1 < delta || (q1 == delta && r1 == 0))); | 
|  | 742 | magu.m = q2 + 1; // resulting magic number | 
| Andrew Lenharth | 320174f | 2005-04-07 17:19:16 +0000 | [diff] [blame] | 743 | magu.s = p - 64;  // resulting shift | 
| Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 744 | return magu; | 
|  | 745 | } | 
|  | 746 |  | 
|  | 747 | /// BuildSDIVSequence - Given an ISD::SDIV node expressing a divide by constant, | 
|  | 748 | /// return a DAG expression to select that will generate the same value by | 
|  | 749 | /// multiplying by a magic number.  See: | 
|  | 750 | /// <http://the.wall.riscom.net/books/proc/ppc/cwg/code2.html> | 
| Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 751 | SDOperand AlphaISel::BuildSDIVSequence(SDOperand N) { | 
| Andrew Lenharth | 320174f | 2005-04-07 17:19:16 +0000 | [diff] [blame] | 752 | int64_t d = (int64_t)cast<ConstantSDNode>(N.getOperand(1))->getSignExtended(); | 
| Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 753 | ms magics = magic(d); | 
|  | 754 | // Multiply the numerator (operand 0) by the magic value | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 755 | SDOperand Q = ISelDAG->getNode(ISD::MULHS, MVT::i64, N.getOperand(0), | 
| Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 756 | ISelDAG->getConstant(magics.m, MVT::i64)); | 
|  | 757 | // If d > 0 and m < 0, add the numerator | 
|  | 758 | if (d > 0 && magics.m < 0) | 
|  | 759 | Q = ISelDAG->getNode(ISD::ADD, MVT::i64, Q, N.getOperand(0)); | 
|  | 760 | // If d < 0 and m > 0, subtract the numerator. | 
|  | 761 | if (d < 0 && magics.m > 0) | 
|  | 762 | Q = ISelDAG->getNode(ISD::SUB, MVT::i64, Q, N.getOperand(0)); | 
|  | 763 | // Shift right algebraic if shift value is nonzero | 
|  | 764 | if (magics.s > 0) | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 765 | Q = ISelDAG->getNode(ISD::SRA, MVT::i64, Q, | 
| Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 766 | ISelDAG->getConstant(magics.s, MVT::i64)); | 
|  | 767 | // Extract the sign bit and add it to the quotient | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 768 | SDOperand T = | 
| Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 769 | ISelDAG->getNode(ISD::SRL, MVT::i64, Q, ISelDAG->getConstant(63, MVT::i64)); | 
|  | 770 | return ISelDAG->getNode(ISD::ADD, MVT::i64, Q, T); | 
|  | 771 | } | 
|  | 772 |  | 
|  | 773 | /// BuildUDIVSequence - Given an ISD::UDIV node expressing a divide by constant, | 
|  | 774 | /// return a DAG expression to select that will generate the same value by | 
|  | 775 | /// multiplying by a magic number.  See: | 
|  | 776 | /// <http://the.wall.riscom.net/books/proc/ppc/cwg/code2.html> | 
| Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 777 | SDOperand AlphaISel::BuildUDIVSequence(SDOperand N) { | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 778 | unsigned d = | 
| Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 779 | (unsigned)cast<ConstantSDNode>(N.getOperand(1))->getSignExtended(); | 
|  | 780 | mu magics = magicu(d); | 
|  | 781 | // Multiply the numerator (operand 0) by the magic value | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 782 | SDOperand Q = ISelDAG->getNode(ISD::MULHU, MVT::i64, N.getOperand(0), | 
| Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 783 | ISelDAG->getConstant(magics.m, MVT::i64)); | 
|  | 784 | if (magics.a == 0) { | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 785 | Q = ISelDAG->getNode(ISD::SRL, MVT::i64, Q, | 
| Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 786 | ISelDAG->getConstant(magics.s, MVT::i64)); | 
|  | 787 | } else { | 
|  | 788 | SDOperand NPQ = ISelDAG->getNode(ISD::SUB, MVT::i64, N.getOperand(0), Q); | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 789 | NPQ = ISelDAG->getNode(ISD::SRL, MVT::i64, NPQ, | 
| Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 790 | ISelDAG->getConstant(1, MVT::i64)); | 
|  | 791 | NPQ = ISelDAG->getNode(ISD::ADD, MVT::i64, NPQ, Q); | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 792 | Q = ISelDAG->getNode(ISD::SRL, MVT::i64, NPQ, | 
| Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 793 | ISelDAG->getConstant(magics.s-1, MVT::i64)); | 
|  | 794 | } | 
|  | 795 | return Q; | 
|  | 796 | } | 
|  | 797 |  | 
| Andrew Lenharth | a565c27 | 2005-04-06 22:03:13 +0000 | [diff] [blame] | 798 | //From PPC32 | 
|  | 799 | /// ExactLog2 - This function solves for (Val == 1 << (N-1)) and returns N.  It | 
|  | 800 | /// returns zero when the input is not exactly a power of two. | 
|  | 801 | static unsigned ExactLog2(uint64_t Val) { | 
|  | 802 | if (Val == 0 || (Val & (Val-1))) return 0; | 
|  | 803 | unsigned Count = 0; | 
|  | 804 | while (Val != 1) { | 
|  | 805 | Val >>= 1; | 
|  | 806 | ++Count; | 
|  | 807 | } | 
|  | 808 | return Count; | 
|  | 809 | } | 
| Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 810 |  | 
|  | 811 |  | 
| Andrew Lenharth | e87f6c3 | 2005-03-11 17:48:05 +0000 | [diff] [blame] | 812 | //These describe LDAx | 
| Andrew Lenharth | c051383 | 2005-03-29 19:24:04 +0000 | [diff] [blame] | 813 | static const int IMM_LOW  = -32768; | 
|  | 814 | static const int IMM_HIGH = 32767; | 
| Andrew Lenharth | e87f6c3 | 2005-03-11 17:48:05 +0000 | [diff] [blame] | 815 | static const int IMM_MULT = 65536; | 
|  | 816 |  | 
|  | 817 | static long getUpper16(long l) | 
|  | 818 | { | 
|  | 819 | long y = l / IMM_MULT; | 
|  | 820 | if (l % IMM_MULT > IMM_HIGH) | 
|  | 821 | ++y; | 
|  | 822 | return y; | 
|  | 823 | } | 
|  | 824 |  | 
|  | 825 | static long getLower16(long l) | 
|  | 826 | { | 
|  | 827 | long h = getUpper16(l); | 
|  | 828 | return l - h * IMM_MULT; | 
|  | 829 | } | 
|  | 830 |  | 
| Andrew Lenharth | 6583890 | 2005-02-06 16:22:15 +0000 | [diff] [blame] | 831 | static unsigned GetSymVersion(unsigned opcode) | 
|  | 832 | { | 
|  | 833 | switch (opcode) { | 
|  | 834 | default: assert(0 && "unknown load or store"); return 0; | 
|  | 835 | case Alpha::LDQ: return Alpha::LDQ_SYM; | 
|  | 836 | case Alpha::LDS: return Alpha::LDS_SYM; | 
|  | 837 | case Alpha::LDT: return Alpha::LDT_SYM; | 
|  | 838 | case Alpha::LDL: return Alpha::LDL_SYM; | 
|  | 839 | case Alpha::LDBU: return Alpha::LDBU_SYM; | 
|  | 840 | case Alpha::LDWU: return Alpha::LDWU_SYM; | 
|  | 841 | case Alpha::LDW: return Alpha::LDW_SYM; | 
|  | 842 | case Alpha::LDB: return Alpha::LDB_SYM; | 
|  | 843 | case Alpha::STQ: return Alpha::STQ_SYM; | 
|  | 844 | case Alpha::STS: return Alpha::STS_SYM; | 
|  | 845 | case Alpha::STT: return Alpha::STT_SYM; | 
|  | 846 | case Alpha::STL: return Alpha::STL_SYM; | 
|  | 847 | case Alpha::STW: return Alpha::STW_SYM; | 
|  | 848 | case Alpha::STB: return Alpha::STB_SYM; | 
|  | 849 | } | 
|  | 850 | } | 
|  | 851 |  | 
| Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 852 | void AlphaISel::MoveFP2Int(unsigned src, unsigned dst, bool isDouble) | 
| Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 853 | { | 
|  | 854 | unsigned Opc; | 
|  | 855 | if (EnableAlphaFTOI) { | 
|  | 856 | Opc = isDouble ? Alpha::FTOIT : Alpha::FTOIS; | 
|  | 857 | BuildMI(BB, Opc, 1, dst).addReg(src); | 
|  | 858 | } else { | 
|  | 859 | //The hard way: | 
|  | 860 | // Spill the integer to memory and reload it from there. | 
|  | 861 | unsigned Size = MVT::getSizeInBits(MVT::f64)/8; | 
|  | 862 | MachineFunction *F = BB->getParent(); | 
|  | 863 | int FrameIdx = F->getFrameInfo()->CreateStackObject(Size, 8); | 
|  | 864 |  | 
|  | 865 | Opc = isDouble ? Alpha::STT : Alpha::STS; | 
|  | 866 | BuildMI(BB, Opc, 3).addReg(src).addFrameIndex(FrameIdx).addReg(Alpha::F31); | 
|  | 867 | Opc = isDouble ? Alpha::LDQ : Alpha::LDL; | 
|  | 868 | BuildMI(BB, Alpha::LDQ, 2, dst).addFrameIndex(FrameIdx).addReg(Alpha::F31); | 
|  | 869 | } | 
|  | 870 | } | 
|  | 871 |  | 
| Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 872 | void AlphaISel::MoveInt2FP(unsigned src, unsigned dst, bool isDouble) | 
| Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 873 | { | 
|  | 874 | unsigned Opc; | 
|  | 875 | if (EnableAlphaFTOI) { | 
|  | 876 | Opc = isDouble?Alpha::ITOFT:Alpha::ITOFS; | 
|  | 877 | BuildMI(BB, Opc, 1, dst).addReg(src); | 
|  | 878 | } else { | 
|  | 879 | //The hard way: | 
|  | 880 | // Spill the integer to memory and reload it from there. | 
|  | 881 | unsigned Size = MVT::getSizeInBits(MVT::f64)/8; | 
|  | 882 | MachineFunction *F = BB->getParent(); | 
|  | 883 | int FrameIdx = F->getFrameInfo()->CreateStackObject(Size, 8); | 
|  | 884 |  | 
|  | 885 | Opc = isDouble ? Alpha::STQ : Alpha::STL; | 
|  | 886 | BuildMI(BB, Opc, 3).addReg(src).addFrameIndex(FrameIdx).addReg(Alpha::F31); | 
|  | 887 | Opc = isDouble ? Alpha::LDT : Alpha::LDS; | 
|  | 888 | BuildMI(BB, Opc, 2, dst).addFrameIndex(FrameIdx).addReg(Alpha::F31); | 
|  | 889 | } | 
|  | 890 | } | 
|  | 891 |  | 
| Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 892 | bool AlphaISel::SelectFPSetCC(SDOperand N, unsigned dst) | 
| Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 893 | { | 
|  | 894 | SDNode *Node = N.Val; | 
|  | 895 | unsigned Opc, Tmp1, Tmp2, Tmp3; | 
|  | 896 | SetCCSDNode *SetCC = dyn_cast<SetCCSDNode>(Node); | 
|  | 897 |  | 
|  | 898 | //assert(SetCC->getOperand(0).getValueType() != MVT::f32 && "SetCC f32 should have been promoted"); | 
|  | 899 | bool rev = false; | 
|  | 900 | bool inv = false; | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 901 |  | 
| Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 902 | switch (SetCC->getCondition()) { | 
|  | 903 | default: Node->dump(); assert(0 && "Unknown FP comparison!"); | 
|  | 904 | case ISD::SETEQ: Opc = Alpha::CMPTEQ; break; | 
|  | 905 | case ISD::SETLT: Opc = Alpha::CMPTLT; break; | 
|  | 906 | case ISD::SETLE: Opc = Alpha::CMPTLE; break; | 
|  | 907 | case ISD::SETGT: Opc = Alpha::CMPTLT; rev = true; break; | 
|  | 908 | case ISD::SETGE: Opc = Alpha::CMPTLE; rev = true; break; | 
|  | 909 | case ISD::SETNE: Opc = Alpha::CMPTEQ; inv = true; break; | 
|  | 910 | } | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 911 |  | 
| Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 912 | //FIXME: check for constant 0.0 | 
|  | 913 | ConstantFPSDNode *CN; | 
|  | 914 | if ((CN = dyn_cast<ConstantFPSDNode>(SetCC->getOperand(0))) | 
|  | 915 | && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0))) | 
|  | 916 | Tmp1 = Alpha::F31; | 
|  | 917 | else | 
|  | 918 | Tmp1 = SelectExpr(N.getOperand(0)); | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 919 |  | 
| Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 920 | if ((CN = dyn_cast<ConstantFPSDNode>(SetCC->getOperand(1))) | 
|  | 921 | && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0))) | 
|  | 922 | Tmp2 = Alpha::F31; | 
|  | 923 | else | 
| Chris Lattner | 9c9183a | 2005-04-30 04:44:07 +0000 | [diff] [blame] | 924 | Tmp2 = SelectExpr(N.getOperand(1)); | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 925 |  | 
| Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 926 | //Can only compare doubles, and dag won't promote for me | 
|  | 927 | if (SetCC->getOperand(0).getValueType() == MVT::f32) | 
|  | 928 | { | 
|  | 929 | //assert(0 && "Setcc On float?\n"); | 
|  | 930 | std::cerr << "Setcc on float!\n"; | 
|  | 931 | Tmp3 = MakeReg(MVT::f64); | 
|  | 932 | BuildMI(BB, Alpha::CVTST, 1, Tmp3).addReg(Tmp1); | 
|  | 933 | Tmp1 = Tmp3; | 
|  | 934 | } | 
|  | 935 | if (SetCC->getOperand(1).getValueType() == MVT::f32) | 
|  | 936 | { | 
|  | 937 | //assert (0 && "Setcc On float?\n"); | 
|  | 938 | std::cerr << "Setcc on float!\n"; | 
|  | 939 | Tmp3 = MakeReg(MVT::f64); | 
|  | 940 | BuildMI(BB, Alpha::CVTST, 1, Tmp3).addReg(Tmp2); | 
|  | 941 | Tmp2 = Tmp3; | 
|  | 942 | } | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 943 |  | 
| Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 944 | if (rev) std::swap(Tmp1, Tmp2); | 
|  | 945 | //do the comparison | 
|  | 946 | BuildMI(BB, Opc, 2, dst).addReg(Tmp1).addReg(Tmp2); | 
|  | 947 | return inv; | 
|  | 948 | } | 
|  | 949 |  | 
| Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 950 | //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] | 951 | void AlphaISel::SelectAddr(SDOperand N, unsigned& Reg, long& offset) | 
| Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 952 | { | 
|  | 953 | unsigned opcode = N.getOpcode(); | 
|  | 954 | if (opcode == ISD::ADD) { | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 955 | if(N.getOperand(1).getOpcode() == ISD::Constant && | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 956 | cast<ConstantSDNode>(N.getOperand(1))->getValue() <= 32767) | 
|  | 957 | { //Normal imm add | 
|  | 958 | Reg = SelectExpr(N.getOperand(0)); | 
|  | 959 | offset = cast<ConstantSDNode>(N.getOperand(1))->getValue(); | 
|  | 960 | return; | 
|  | 961 | } | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 962 | else if(N.getOperand(0).getOpcode() == ISD::Constant && | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 963 | cast<ConstantSDNode>(N.getOperand(0))->getValue() <= 32767) | 
|  | 964 | { | 
|  | 965 | Reg = SelectExpr(N.getOperand(1)); | 
|  | 966 | offset = cast<ConstantSDNode>(N.getOperand(0))->getValue(); | 
|  | 967 | return; | 
|  | 968 | } | 
| Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 969 | } | 
|  | 970 | Reg = SelectExpr(N); | 
|  | 971 | offset = 0; | 
|  | 972 | return; | 
|  | 973 | } | 
|  | 974 |  | 
| Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 975 | void AlphaISel::SelectBranchCC(SDOperand N) | 
| Andrew Lenharth | 445171a | 2005-02-08 00:40:03 +0000 | [diff] [blame] | 976 | { | 
|  | 977 | assert(N.getOpcode() == ISD::BRCOND && "Not a BranchCC???"); | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 978 | MachineBasicBlock *Dest = | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 979 | cast<BasicBlockSDNode>(N.getOperand(2))->getBasicBlock(); | 
|  | 980 | unsigned Opc = Alpha::WTF; | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 981 |  | 
| Andrew Lenharth | 445171a | 2005-02-08 00:40:03 +0000 | [diff] [blame] | 982 | Select(N.getOperand(0));  //chain | 
|  | 983 | SDOperand CC = N.getOperand(1); | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 984 |  | 
| Andrew Lenharth | 445171a | 2005-02-08 00:40:03 +0000 | [diff] [blame] | 985 | if (CC.getOpcode() == ISD::SETCC) | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 986 | { | 
|  | 987 | SetCCSDNode* SetCC = dyn_cast<SetCCSDNode>(CC.Val); | 
|  | 988 | if (MVT::isInteger(SetCC->getOperand(0).getValueType())) { | 
|  | 989 | //Dropping the CC is only useful if we are comparing to 0 | 
| Andrew Lenharth | 63b720a | 2005-04-03 20:35:21 +0000 | [diff] [blame] | 990 | bool LeftZero = SetCC->getOperand(0).getOpcode() == ISD::Constant && | 
|  | 991 | cast<ConstantSDNode>(SetCC->getOperand(0))->getValue() == 0; | 
| Andrew Lenharth | 09552bf | 2005-06-08 18:02:21 +0000 | [diff] [blame] | 992 | bool RightZero = SetCC->getOperand(1).getOpcode() == ISD::Constant && | 
|  | 993 | cast<ConstantSDNode>(SetCC->getOperand(1))->getValue() == 0; | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 994 | bool isNE = false; | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 995 |  | 
| Andrew Lenharth | 63b720a | 2005-04-03 20:35:21 +0000 | [diff] [blame] | 996 | //Fix up CC | 
|  | 997 | ISD::CondCode cCode= SetCC->getCondition(); | 
|  | 998 | if (LeftZero && !RightZero) //Swap Operands | 
|  | 999 | cCode = ISD::getSetCCSwappedOperands(cCode); | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1000 |  | 
| Andrew Lenharth | 63b720a | 2005-04-03 20:35:21 +0000 | [diff] [blame] | 1001 | if(cCode == ISD::SETNE) | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1002 | isNE = true; | 
| Andrew Lenharth | 445171a | 2005-02-08 00:40:03 +0000 | [diff] [blame] | 1003 |  | 
| Andrew Lenharth | 63b720a | 2005-04-03 20:35:21 +0000 | [diff] [blame] | 1004 | if (LeftZero || RightZero) { | 
| Andrew Lenharth | 09552bf | 2005-06-08 18:02:21 +0000 | [diff] [blame] | 1005 | switch (cCode) { | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1006 | default: CC.Val->dump(); assert(0 && "Unknown integer comparison!"); | 
|  | 1007 | case ISD::SETEQ:  Opc = Alpha::BEQ; break; | 
|  | 1008 | case ISD::SETLT:  Opc = Alpha::BLT; break; | 
|  | 1009 | case ISD::SETLE:  Opc = Alpha::BLE; break; | 
|  | 1010 | case ISD::SETGT:  Opc = Alpha::BGT; break; | 
|  | 1011 | case ISD::SETGE:  Opc = Alpha::BGE; break; | 
|  | 1012 | case ISD::SETULT: assert(0 && "x (unsigned) < 0 is never true"); break; | 
|  | 1013 | case ISD::SETUGT: Opc = Alpha::BNE; break; | 
|  | 1014 | case ISD::SETULE: Opc = Alpha::BEQ; break; //Technically you could have this CC | 
|  | 1015 | case ISD::SETUGE: assert(0 && "x (unsgined >= 0 is always true"); break; | 
|  | 1016 | case ISD::SETNE:  Opc = Alpha::BNE; break; | 
|  | 1017 | } | 
| Andrew Lenharth | 63b720a | 2005-04-03 20:35:21 +0000 | [diff] [blame] | 1018 | unsigned Tmp1; | 
|  | 1019 | if(LeftZero && !RightZero) //swap Operands | 
|  | 1020 | Tmp1 = SelectExpr(SetCC->getOperand(1)); //Cond | 
|  | 1021 | else | 
|  | 1022 | Tmp1 = SelectExpr(SetCC->getOperand(0)); //Cond | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1023 | BuildMI(BB, Opc, 2).addReg(Tmp1).addMBB(Dest); | 
|  | 1024 | return; | 
|  | 1025 | } else { | 
|  | 1026 | unsigned Tmp1 = SelectExpr(CC); | 
|  | 1027 | if (isNE) | 
|  | 1028 | BuildMI(BB, Alpha::BEQ, 2).addReg(CCInvMap[CC]).addMBB(Dest); | 
|  | 1029 | else | 
|  | 1030 | BuildMI(BB, Alpha::BNE, 2).addReg(Tmp1).addMBB(Dest); | 
| Andrew Lenharth | 445171a | 2005-02-08 00:40:03 +0000 | [diff] [blame] | 1031 | return; | 
|  | 1032 | } | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1033 | } else { //FP | 
|  | 1034 | //Any comparison between 2 values should be codegened as an folded branch, as moving | 
|  | 1035 | //CC to the integer register is very expensive | 
|  | 1036 | //for a cmp b: c = a - b; | 
|  | 1037 | //a = b: c = 0 | 
|  | 1038 | //a < b: c < 0 | 
|  | 1039 | //a > b: c > 0 | 
| Andrew Lenharth | 2b6c4f5 | 2005-02-25 22:55:15 +0000 | [diff] [blame] | 1040 |  | 
|  | 1041 | bool invTest = false; | 
|  | 1042 | unsigned Tmp3; | 
|  | 1043 |  | 
|  | 1044 | ConstantFPSDNode *CN; | 
|  | 1045 | if ((CN = dyn_cast<ConstantFPSDNode>(SetCC->getOperand(1))) | 
|  | 1046 | && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0))) | 
|  | 1047 | Tmp3 = SelectExpr(SetCC->getOperand(0)); | 
|  | 1048 | else if ((CN = dyn_cast<ConstantFPSDNode>(SetCC->getOperand(0))) | 
|  | 1049 | && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0))) | 
|  | 1050 | { | 
|  | 1051 | Tmp3 = SelectExpr(SetCC->getOperand(1)); | 
|  | 1052 | invTest = true; | 
|  | 1053 | } | 
|  | 1054 | else | 
|  | 1055 | { | 
|  | 1056 | unsigned Tmp1 = SelectExpr(SetCC->getOperand(0)); | 
|  | 1057 | unsigned Tmp2 = SelectExpr(SetCC->getOperand(1)); | 
|  | 1058 | bool isD = SetCC->getOperand(0).getValueType() == MVT::f64; | 
|  | 1059 | Tmp3 = MakeReg(isD ? MVT::f64 : MVT::f32); | 
|  | 1060 | BuildMI(BB, isD ? Alpha::SUBT : Alpha::SUBS, 2, Tmp3) | 
|  | 1061 | .addReg(Tmp1).addReg(Tmp2); | 
|  | 1062 | } | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1063 |  | 
|  | 1064 | switch (SetCC->getCondition()) { | 
|  | 1065 | default: CC.Val->dump(); assert(0 && "Unknown FP comparison!"); | 
| Andrew Lenharth | 2b6c4f5 | 2005-02-25 22:55:15 +0000 | [diff] [blame] | 1066 | case ISD::SETEQ: Opc = invTest ? Alpha::FBNE : Alpha::FBEQ; break; | 
|  | 1067 | case ISD::SETLT: Opc = invTest ? Alpha::FBGT : Alpha::FBLT; break; | 
|  | 1068 | case ISD::SETLE: Opc = invTest ? Alpha::FBGE : Alpha::FBLE; break; | 
|  | 1069 | case ISD::SETGT: Opc = invTest ? Alpha::FBLT : Alpha::FBGT; break; | 
|  | 1070 | case ISD::SETGE: Opc = invTest ? Alpha::FBLE : Alpha::FBGE; break; | 
|  | 1071 | case ISD::SETNE: Opc = invTest ? Alpha::FBEQ : Alpha::FBNE; break; | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1072 | } | 
|  | 1073 | BuildMI(BB, Opc, 2).addReg(Tmp3).addMBB(Dest); | 
| Andrew Lenharth | 445171a | 2005-02-08 00:40:03 +0000 | [diff] [blame] | 1074 | return; | 
|  | 1075 | } | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1076 | abort(); //Should never be reached | 
|  | 1077 | } else { | 
|  | 1078 | //Giveup and do the stupid thing | 
|  | 1079 | unsigned Tmp1 = SelectExpr(CC); | 
|  | 1080 | BuildMI(BB, Alpha::BNE, 2).addReg(Tmp1).addMBB(Dest); | 
|  | 1081 | return; | 
|  | 1082 | } | 
| Andrew Lenharth | 445171a | 2005-02-08 00:40:03 +0000 | [diff] [blame] | 1083 | abort(); //Should never be reached | 
|  | 1084 | } | 
|  | 1085 |  | 
| Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 1086 | unsigned AlphaISel::SelectExprFP(SDOperand N, unsigned Result) | 
| Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1087 | { | 
|  | 1088 | unsigned Tmp1, Tmp2, Tmp3; | 
|  | 1089 | unsigned Opc = 0; | 
|  | 1090 | SDNode *Node = N.Val; | 
|  | 1091 | MVT::ValueType DestType = N.getValueType(); | 
|  | 1092 | unsigned opcode = N.getOpcode(); | 
|  | 1093 |  | 
|  | 1094 | switch (opcode) { | 
|  | 1095 | default: | 
|  | 1096 | Node->dump(); | 
|  | 1097 | assert(0 && "Node not handled!\n"); | 
| Andrew Lenharth | 2c59435 | 2005-01-29 15:42:07 +0000 | [diff] [blame] | 1098 |  | 
| Andrew Lenharth | 7332f3e | 2005-04-02 19:11:07 +0000 | [diff] [blame] | 1099 | case ISD::UNDEF: { | 
|  | 1100 | BuildMI(BB, Alpha::IDEF, 0, Result); | 
|  | 1101 | return Result; | 
|  | 1102 | } | 
|  | 1103 |  | 
| Andrew Lenharth | 30b46d4 | 2005-04-02 19:04:58 +0000 | [diff] [blame] | 1104 | case ISD::FNEG: | 
|  | 1105 | if(ISD::FABS == N.getOperand(0).getOpcode()) | 
|  | 1106 | { | 
| Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1107 | Tmp1 = SelectExpr(N.getOperand(0).getOperand(0)); | 
|  | 1108 | BuildMI(BB, Alpha::CPYSN, 2, Result).addReg(Alpha::F31).addReg(Tmp1); | 
| Andrew Lenharth | 30b46d4 | 2005-04-02 19:04:58 +0000 | [diff] [blame] | 1109 | } else { | 
| Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1110 | Tmp1 = SelectExpr(N.getOperand(0)); | 
|  | 1111 | BuildMI(BB, Alpha::CPYSN, 2, Result).addReg(Tmp1).addReg(Tmp1); | 
| Andrew Lenharth | 30b46d4 | 2005-04-02 19:04:58 +0000 | [diff] [blame] | 1112 | } | 
|  | 1113 | return Result; | 
|  | 1114 |  | 
|  | 1115 | case ISD::FABS: | 
|  | 1116 | Tmp1 = SelectExpr(N.getOperand(0)); | 
|  | 1117 | BuildMI(BB, Alpha::CPYS, 2, Result).addReg(Alpha::F31).addReg(Tmp1); | 
|  | 1118 | return Result; | 
|  | 1119 |  | 
| Andrew Lenharth | 9818c05 | 2005-02-05 13:19:12 +0000 | [diff] [blame] | 1120 | case ISD::SELECT: | 
|  | 1121 | { | 
| Andrew Lenharth | 4585969 | 2005-03-03 21:47:53 +0000 | [diff] [blame] | 1122 | //Tmp1 = SelectExpr(N.getOperand(0)); //Cond | 
|  | 1123 | unsigned TV = SelectExpr(N.getOperand(1)); //Use if TRUE | 
|  | 1124 | unsigned FV = SelectExpr(N.getOperand(2)); //Use if FALSE | 
|  | 1125 |  | 
|  | 1126 | SDOperand CC = N.getOperand(0); | 
|  | 1127 | SetCCSDNode* SetCC = dyn_cast<SetCCSDNode>(CC.Val); | 
|  | 1128 |  | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1129 | if (CC.getOpcode() == ISD::SETCC && | 
| Andrew Lenharth | 4585969 | 2005-03-03 21:47:53 +0000 | [diff] [blame] | 1130 | !MVT::isInteger(SetCC->getOperand(0).getValueType())) | 
|  | 1131 | { //FP Setcc -> Select yay! | 
| Andrew Lenharth | d4bdd54 | 2005-02-05 16:41:03 +0000 | [diff] [blame] | 1132 |  | 
|  | 1133 |  | 
| Andrew Lenharth | 4585969 | 2005-03-03 21:47:53 +0000 | [diff] [blame] | 1134 | //for a cmp b: c = a - b; | 
|  | 1135 | //a = b: c = 0 | 
|  | 1136 | //a < b: c < 0 | 
|  | 1137 | //a > b: c > 0 | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1138 |  | 
| Andrew Lenharth | 4585969 | 2005-03-03 21:47:53 +0000 | [diff] [blame] | 1139 | bool invTest = false; | 
|  | 1140 | unsigned Tmp3; | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1141 |  | 
| Andrew Lenharth | 4585969 | 2005-03-03 21:47:53 +0000 | [diff] [blame] | 1142 | ConstantFPSDNode *CN; | 
|  | 1143 | if ((CN = dyn_cast<ConstantFPSDNode>(SetCC->getOperand(1))) | 
|  | 1144 | && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0))) | 
|  | 1145 | Tmp3 = SelectExpr(SetCC->getOperand(0)); | 
|  | 1146 | else if ((CN = dyn_cast<ConstantFPSDNode>(SetCC->getOperand(0))) | 
|  | 1147 | && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0))) | 
|  | 1148 | { | 
|  | 1149 | Tmp3 = SelectExpr(SetCC->getOperand(1)); | 
|  | 1150 | invTest = true; | 
|  | 1151 | } | 
|  | 1152 | else | 
|  | 1153 | { | 
|  | 1154 | unsigned Tmp1 = SelectExpr(SetCC->getOperand(0)); | 
|  | 1155 | unsigned Tmp2 = SelectExpr(SetCC->getOperand(1)); | 
|  | 1156 | bool isD = SetCC->getOperand(0).getValueType() == MVT::f64; | 
|  | 1157 | Tmp3 = MakeReg(isD ? MVT::f64 : MVT::f32); | 
|  | 1158 | BuildMI(BB, isD ? Alpha::SUBT : Alpha::SUBS, 2, Tmp3) | 
|  | 1159 | .addReg(Tmp1).addReg(Tmp2); | 
|  | 1160 | } | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1161 |  | 
| Andrew Lenharth | 4585969 | 2005-03-03 21:47:53 +0000 | [diff] [blame] | 1162 | switch (SetCC->getCondition()) { | 
|  | 1163 | default: CC.Val->dump(); assert(0 && "Unknown FP comparison!"); | 
|  | 1164 | case ISD::SETEQ: Opc = invTest ? Alpha::FCMOVNE : Alpha::FCMOVEQ; break; | 
|  | 1165 | case ISD::SETLT: Opc = invTest ? Alpha::FCMOVGT : Alpha::FCMOVLT; break; | 
|  | 1166 | case ISD::SETLE: Opc = invTest ? Alpha::FCMOVGE : Alpha::FCMOVLE; break; | 
|  | 1167 | case ISD::SETGT: Opc = invTest ? Alpha::FCMOVLT : Alpha::FCMOVGT; break; | 
|  | 1168 | case ISD::SETGE: Opc = invTest ? Alpha::FCMOVLE : Alpha::FCMOVGE; break; | 
|  | 1169 | case ISD::SETNE: Opc = invTest ? Alpha::FCMOVEQ : Alpha::FCMOVNE; break; | 
|  | 1170 | } | 
| Andrew Lenharth | 3381913 | 2005-03-04 20:09:23 +0000 | [diff] [blame] | 1171 | BuildMI(BB, Opc, 3, Result).addReg(FV).addReg(TV).addReg(Tmp3); | 
| Andrew Lenharth | 4585969 | 2005-03-03 21:47:53 +0000 | [diff] [blame] | 1172 | return Result; | 
|  | 1173 | } | 
|  | 1174 | else | 
|  | 1175 | { | 
|  | 1176 | Tmp1 = SelectExpr(N.getOperand(0)); //Cond | 
| Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 1177 | BuildMI(BB, Alpha::FCMOVEQ_INT, 3, Result).addReg(TV).addReg(FV).addReg(Tmp1); | 
|  | 1178 | //         // Spill the cond to memory and reload it from there. | 
|  | 1179 | //         unsigned Tmp4 = MakeReg(MVT::f64); | 
|  | 1180 | //         MoveIntFP(Tmp1, Tmp4, true); | 
|  | 1181 | //         //now ideally, we don't have to do anything to the flag... | 
|  | 1182 | //         // Get the condition into the zero flag. | 
|  | 1183 | //         BuildMI(BB, Alpha::FCMOVEQ, 3, Result).addReg(TV).addReg(FV).addReg(Tmp4); | 
| Andrew Lenharth | 4585969 | 2005-03-03 21:47:53 +0000 | [diff] [blame] | 1184 | return Result; | 
|  | 1185 | } | 
| Andrew Lenharth | 9818c05 | 2005-02-05 13:19:12 +0000 | [diff] [blame] | 1186 | } | 
|  | 1187 |  | 
| Andrew Lenharth | c1faced | 2005-02-01 01:37:24 +0000 | [diff] [blame] | 1188 | case ISD::FP_ROUND: | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1189 | assert (DestType == MVT::f32 && | 
|  | 1190 | N.getOperand(0).getValueType() == MVT::f64 && | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1191 | "only f64 to f32 conversion supported here"); | 
| Andrew Lenharth | c1faced | 2005-02-01 01:37:24 +0000 | [diff] [blame] | 1192 | Tmp1 = SelectExpr(N.getOperand(0)); | 
|  | 1193 | BuildMI(BB, Alpha::CVTTS, 1, Result).addReg(Tmp1); | 
|  | 1194 | return Result; | 
|  | 1195 |  | 
| Andrew Lenharth | 7b2a527 | 2005-01-30 20:42:36 +0000 | [diff] [blame] | 1196 | case ISD::FP_EXTEND: | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1197 | assert (DestType == MVT::f64 && | 
|  | 1198 | N.getOperand(0).getValueType() == MVT::f32 && | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1199 | "only f32 to f64 conversion supported here"); | 
| Andrew Lenharth | 7b2a527 | 2005-01-30 20:42:36 +0000 | [diff] [blame] | 1200 | Tmp1 = SelectExpr(N.getOperand(0)); | 
|  | 1201 | BuildMI(BB, Alpha::CVTST, 1, Result).addReg(Tmp1); | 
|  | 1202 | return Result; | 
|  | 1203 |  | 
| Andrew Lenharth | 2c59435 | 2005-01-29 15:42:07 +0000 | [diff] [blame] | 1204 | case ISD::CopyFromReg: | 
|  | 1205 | { | 
|  | 1206 | // Make sure we generate both values. | 
|  | 1207 | if (Result != notIn) | 
|  | 1208 | ExprMap[N.getValue(1)] = notIn;   // Generate the token | 
|  | 1209 | else | 
|  | 1210 | Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType()); | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1211 |  | 
| Andrew Lenharth | 2c59435 | 2005-01-29 15:42:07 +0000 | [diff] [blame] | 1212 | SDOperand Chain   = N.getOperand(0); | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1213 |  | 
| Andrew Lenharth | 2c59435 | 2005-01-29 15:42:07 +0000 | [diff] [blame] | 1214 | Select(Chain); | 
|  | 1215 | unsigned r = dyn_cast<RegSDNode>(Node)->getReg(); | 
|  | 1216 | //std::cerr << "CopyFromReg " << Result << " = " << r << "\n"; | 
|  | 1217 | BuildMI(BB, Alpha::CPYS, 2, Result).addReg(r).addReg(r); | 
|  | 1218 | return Result; | 
|  | 1219 | } | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1220 |  | 
| Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 1221 | case ISD::LOAD: | 
|  | 1222 | { | 
|  | 1223 | // Make sure we generate both values. | 
|  | 1224 | if (Result != notIn) | 
| Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1225 | ExprMap[N.getValue(1)] = notIn;   // Generate the token | 
| Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 1226 | else | 
| Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1227 | Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType()); | 
| Andrew Lenharth | 12dd262 | 2005-02-03 21:01:15 +0000 | [diff] [blame] | 1228 |  | 
| Andrew Lenharth | 2921916 | 2005-02-07 06:31:44 +0000 | [diff] [blame] | 1229 | DestType = N.getValue(0).getValueType(); | 
| Andrew Lenharth | 12dd262 | 2005-02-03 21:01:15 +0000 | [diff] [blame] | 1230 |  | 
| Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 1231 | SDOperand Chain   = N.getOperand(0); | 
|  | 1232 | SDOperand Address = N.getOperand(1); | 
| Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 1233 | Select(Chain); | 
| Andrew Lenharth | 6583890 | 2005-02-06 16:22:15 +0000 | [diff] [blame] | 1234 | Opc = DestType == MVT::f64 ? Alpha::LDT : Alpha::LDS; | 
|  | 1235 |  | 
| Andrew Lenharth | cd7f8cf | 2005-06-06 19:03:55 +0000 | [diff] [blame] | 1236 | if (EnableAlphaLSMark) | 
|  | 1237 | { | 
|  | 1238 | int i = getValueOffset(dyn_cast<SrcValueSDNode>(N.getOperand(2))->getValue()); | 
| Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 1239 | int j = getFunctionOffset(BB->getParent()->getFunction()); | 
|  | 1240 | BuildMI(BB, Alpha::MEMLABEL, 3).addImm(j).addImm(i).addImm(getUID()); | 
| Andrew Lenharth | cd7f8cf | 2005-06-06 19:03:55 +0000 | [diff] [blame] | 1241 | } | 
|  | 1242 |  | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1243 | if (Address.getOpcode() == ISD::GlobalAddress) { | 
|  | 1244 | AlphaLowering.restoreGP(BB); | 
|  | 1245 | Opc = GetSymVersion(Opc); | 
| Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 1246 | has_sym = true; | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1247 | BuildMI(BB, Opc, 1, Result).addGlobalAddress(cast<GlobalAddressSDNode>(Address)->getGlobal()); | 
|  | 1248 | } | 
| Andrew Lenharth | e76797c | 2005-02-01 20:40:27 +0000 | [diff] [blame] | 1249 | else if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(Address)) { | 
| Andrew Lenharth | d4bdd54 | 2005-02-05 16:41:03 +0000 | [diff] [blame] | 1250 | AlphaLowering.restoreGP(BB); | 
| Andrew Lenharth | 6583890 | 2005-02-06 16:22:15 +0000 | [diff] [blame] | 1251 | Opc = GetSymVersion(Opc); | 
| Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 1252 | has_sym = true; | 
| Andrew Lenharth | 97127a1 | 2005-02-05 17:41:39 +0000 | [diff] [blame] | 1253 | BuildMI(BB, Opc, 1, Result).addConstantPoolIndex(CP->getIndex()); | 
| Andrew Lenharth | e76797c | 2005-02-01 20:40:27 +0000 | [diff] [blame] | 1254 | } | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1255 | else if(Address.getOpcode() == ISD::FrameIndex) { | 
| Andrew Lenharth | 032f235 | 2005-02-22 21:59:48 +0000 | [diff] [blame] | 1256 | BuildMI(BB, Opc, 2, Result) | 
|  | 1257 | .addFrameIndex(cast<FrameIndexSDNode>(Address)->getIndex()) | 
|  | 1258 | .addReg(Alpha::F31); | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1259 | } else { | 
|  | 1260 | long offset; | 
|  | 1261 | SelectAddr(Address, Tmp1, offset); | 
|  | 1262 | BuildMI(BB, Opc, 2, Result).addImm(offset).addReg(Tmp1); | 
|  | 1263 | } | 
| Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 1264 | return Result; | 
|  | 1265 | } | 
| Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1266 | case ISD::ConstantFP: | 
|  | 1267 | if (ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(N)) { | 
|  | 1268 | if (CN->isExactlyValue(+0.0)) { | 
|  | 1269 | BuildMI(BB, Alpha::CPYS, 2, Result).addReg(Alpha::F31).addReg(Alpha::F31); | 
| Andrew Lenharth | 12dd262 | 2005-02-03 21:01:15 +0000 | [diff] [blame] | 1270 | } else if ( CN->isExactlyValue(-0.0)) { | 
|  | 1271 | BuildMI(BB, Alpha::CPYSN, 2, Result).addReg(Alpha::F31).addReg(Alpha::F31); | 
| Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1272 | } else { | 
|  | 1273 | abort(); | 
|  | 1274 | } | 
|  | 1275 | } | 
|  | 1276 | return Result; | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1277 |  | 
| Andrew Lenharth | dc0b71b | 2005-03-22 00:24:07 +0000 | [diff] [blame] | 1278 | case ISD::SDIV: | 
| Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1279 | case ISD::MUL: | 
|  | 1280 | case ISD::ADD: | 
|  | 1281 | case ISD::SUB: | 
| Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1282 | switch( opcode ) { | 
|  | 1283 | case ISD::MUL: Opc = DestType == MVT::f64 ? Alpha::MULT : Alpha::MULS; break; | 
|  | 1284 | case ISD::ADD: Opc = DestType == MVT::f64 ? Alpha::ADDT : Alpha::ADDS; break; | 
|  | 1285 | case ISD::SUB: Opc = DestType == MVT::f64 ? Alpha::SUBT : Alpha::SUBS; break; | 
|  | 1286 | case ISD::SDIV: Opc = DestType == MVT::f64 ? Alpha::DIVT : Alpha::DIVS; break; | 
|  | 1287 | }; | 
| Andrew Lenharth | 2b6c4f5 | 2005-02-25 22:55:15 +0000 | [diff] [blame] | 1288 |  | 
|  | 1289 | ConstantFPSDNode *CN; | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1290 | if (opcode == ISD::SUB | 
| Andrew Lenharth | 2b6c4f5 | 2005-02-25 22:55:15 +0000 | [diff] [blame] | 1291 | && (CN = dyn_cast<ConstantFPSDNode>(N.getOperand(0))) | 
|  | 1292 | && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0))) | 
|  | 1293 | { | 
|  | 1294 | Tmp2 = SelectExpr(N.getOperand(1)); | 
|  | 1295 | BuildMI(BB, Alpha::CPYSN, 2, Result).addReg(Tmp2).addReg(Tmp2); | 
|  | 1296 | } else { | 
|  | 1297 | Tmp1 = SelectExpr(N.getOperand(0)); | 
|  | 1298 | Tmp2 = SelectExpr(N.getOperand(1)); | 
|  | 1299 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2); | 
|  | 1300 | } | 
| Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1301 | return Result; | 
|  | 1302 |  | 
| Andrew Lenharth | 2c59435 | 2005-01-29 15:42:07 +0000 | [diff] [blame] | 1303 | case ISD::EXTLOAD: | 
| Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 1304 | { | 
|  | 1305 | //include a conversion sequence for float loads to double | 
|  | 1306 | if (Result != notIn) | 
|  | 1307 | ExprMap[N.getValue(1)] = notIn;   // Generate the token | 
|  | 1308 | else | 
|  | 1309 | Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType()); | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1310 |  | 
| Andrew Lenharth | a549deb | 2005-02-07 05:33:15 +0000 | [diff] [blame] | 1311 | Tmp1 = MakeReg(MVT::f32); | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1312 |  | 
|  | 1313 | assert(cast<MVTSDNode>(Node)->getExtraValueType() == MVT::f32 && | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1314 | "EXTLOAD not from f32"); | 
| Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 1315 | assert(Node->getValueType(0) == MVT::f64 && "EXTLOAD not to f64"); | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1316 |  | 
| Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 1317 | SDOperand Chain   = N.getOperand(0); | 
|  | 1318 | SDOperand Address = N.getOperand(1); | 
|  | 1319 | Select(Chain); | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1320 |  | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1321 | if (Address.getOpcode() == ISD::GlobalAddress) { | 
|  | 1322 | AlphaLowering.restoreGP(BB); | 
| Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 1323 | has_sym = true; | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1324 | BuildMI(BB, Alpha::LDS_SYM, 1, Tmp1).addGlobalAddress(cast<GlobalAddressSDNode>(Address)->getGlobal()); | 
|  | 1325 | } | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1326 | else if (ConstantPoolSDNode *CP = | 
|  | 1327 | dyn_cast<ConstantPoolSDNode>(N.getOperand(1))) | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1328 | { | 
|  | 1329 | AlphaLowering.restoreGP(BB); | 
| Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 1330 | has_sym = true; | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1331 | BuildMI(BB, Alpha::LDS_SYM, 1, Tmp1).addConstantPoolIndex(CP->getIndex()); | 
|  | 1332 | } | 
|  | 1333 | else if(Address.getOpcode() == ISD::FrameIndex) { | 
|  | 1334 | Tmp2 = cast<FrameIndexSDNode>(Address)->getIndex(); | 
| Andrew Lenharth | 032f235 | 2005-02-22 21:59:48 +0000 | [diff] [blame] | 1335 | BuildMI(BB, Alpha::LDS, 2, Tmp1) | 
|  | 1336 | .addFrameIndex(cast<FrameIndexSDNode>(Address)->getIndex()) | 
|  | 1337 | .addReg(Alpha::F31); | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1338 | } else { | 
|  | 1339 | long offset; | 
|  | 1340 | SelectAddr(Address, Tmp2, offset); | 
|  | 1341 | BuildMI(BB, Alpha::LDS, 1, Tmp1).addImm(offset).addReg(Tmp2); | 
|  | 1342 | } | 
| Andrew Lenharth | 2921916 | 2005-02-07 06:31:44 +0000 | [diff] [blame] | 1343 | BuildMI(BB, Alpha::CVTST, 1, Result).addReg(Tmp1); | 
| Andrew Lenharth | 12dd262 | 2005-02-03 21:01:15 +0000 | [diff] [blame] | 1344 | return Result; | 
|  | 1345 | } | 
| Andrew Lenharth | 2c59435 | 2005-01-29 15:42:07 +0000 | [diff] [blame] | 1346 |  | 
| Andrew Lenharth | e76797c | 2005-02-01 20:40:27 +0000 | [diff] [blame] | 1347 | case ISD::UINT_TO_FP: | 
| Andrew Lenharth | 69520ed | 2005-05-26 18:18:34 +0000 | [diff] [blame] | 1348 | { | 
|  | 1349 | //FIXME: First test if we will have problems with the sign bit before doing the slow thing | 
|  | 1350 | assert (N.getOperand(0).getValueType() == MVT::i64 | 
|  | 1351 | && "only quads can be loaded from"); | 
|  | 1352 | Tmp1 = SelectExpr(N.getOperand(0));  // Get the operand register | 
|  | 1353 | Tmp2 = MakeReg(MVT::i64); | 
|  | 1354 | BuildMI(BB, Alpha::SRL, 2, Tmp2).addReg(Tmp1).addImm(1); | 
|  | 1355 | Tmp3 = MakeReg(MVT::i64); | 
|  | 1356 | BuildMI(BB, Alpha::CMPLT, 2, Tmp3).addReg(Tmp1).addReg(Alpha::R31); | 
|  | 1357 | unsigned Tmp4 = MakeReg(MVT::f64), Tmp5 = MakeReg(MVT::f64), Tmp6 = MakeReg(MVT::f64); | 
|  | 1358 | MoveInt2FP(Tmp1, Tmp4, true); | 
|  | 1359 | MoveInt2FP(Tmp2, Tmp5, true); | 
|  | 1360 | MoveInt2FP(Tmp3, Tmp6, true); | 
|  | 1361 | Tmp1 = MakeReg(MVT::f64); | 
|  | 1362 | Tmp2 = MakeReg(MVT::f64); | 
|  | 1363 | Opc = DestType == MVT::f64 ? Alpha::CVTQT : Alpha::CVTQS; | 
|  | 1364 | BuildMI(BB, Opc, 1, Tmp1).addReg(Tmp4); | 
|  | 1365 | BuildMI(BB, Opc, 1, Tmp2).addReg(Tmp5); | 
|  | 1366 | Tmp3 = MakeReg(MVT::f64); | 
|  | 1367 | BuildMI(BB, Alpha::ADDT, 2, Tmp3).addReg(Tmp2).addReg(Tmp2); | 
|  | 1368 | //Ok, now tmp1 had the plain covereted | 
|  | 1369 | //tmp3 has the reduced converted and added | 
|  | 1370 | //tmp6 has the conditional to use | 
|  | 1371 | BuildMI(BB, Alpha::FCMOVNE, 3, Result).addReg(Tmp1).addReg(Tmp3).addReg(Tmp6); | 
|  | 1372 | return Result; | 
|  | 1373 | } | 
| Andrew Lenharth | e76797c | 2005-02-01 20:40:27 +0000 | [diff] [blame] | 1374 | case ISD::SINT_TO_FP: | 
| Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1375 | { | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1376 | assert (N.getOperand(0).getValueType() == MVT::i64 | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1377 | && "only quads can be loaded from"); | 
| Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1378 | Tmp1 = SelectExpr(N.getOperand(0));  // Get the operand register | 
| Andrew Lenharth | 7efadce | 2005-01-31 01:44:26 +0000 | [diff] [blame] | 1379 | Tmp2 = MakeReg(MVT::f64); | 
| Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 1380 | MoveInt2FP(Tmp1, Tmp2, true); | 
| Andrew Lenharth | 7efadce | 2005-01-31 01:44:26 +0000 | [diff] [blame] | 1381 | Opc = DestType == MVT::f64 ? Alpha::CVTQT : Alpha::CVTQS; | 
|  | 1382 | BuildMI(BB, Opc, 1, Result).addReg(Tmp2); | 
| Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1383 | return Result; | 
|  | 1384 | } | 
|  | 1385 | } | 
|  | 1386 | assert(0 && "should not get here"); | 
|  | 1387 | return 0; | 
|  | 1388 | } | 
|  | 1389 |  | 
| Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 1390 | unsigned AlphaISel::SelectExpr(SDOperand N) { | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1391 | unsigned Result; | 
| Andrew Lenharth | 2966e84 | 2005-04-07 18:15:28 +0000 | [diff] [blame] | 1392 | unsigned Tmp1, Tmp2 = 0, Tmp3; | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1393 | unsigned Opc = 0; | 
| Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1394 | unsigned opcode = N.getOpcode(); | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1395 |  | 
|  | 1396 | SDNode *Node = N.Val; | 
| Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1397 | MVT::ValueType DestType = N.getValueType(); | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1398 |  | 
|  | 1399 | unsigned &Reg = ExprMap[N]; | 
|  | 1400 | if (Reg) return Reg; | 
|  | 1401 |  | 
| Chris Lattner | b5d8e6e | 2005-05-13 20:29:26 +0000 | [diff] [blame] | 1402 | if (N.getOpcode() != ISD::CALL && N.getOpcode() != ISD::TAILCALL) | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1403 | Reg = Result = (N.getValueType() != MVT::Other) ? | 
| Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 1404 | MakeReg(N.getValueType()) : notIn; | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1405 | else { | 
|  | 1406 | // If this is a call instruction, make sure to prepare ALL of the result | 
|  | 1407 | // values as well as the chain. | 
|  | 1408 | if (Node->getNumValues() == 1) | 
| Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 1409 | Reg = Result = notIn;  // Void call, just a chain. | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1410 | else { | 
|  | 1411 | Result = MakeReg(Node->getValueType(0)); | 
|  | 1412 | ExprMap[N.getValue(0)] = Result; | 
|  | 1413 | for (unsigned i = 1, e = N.Val->getNumValues()-1; i != e; ++i) | 
|  | 1414 | ExprMap[N.getValue(i)] = MakeReg(Node->getValueType(i)); | 
| Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 1415 | ExprMap[SDOperand(Node, Node->getNumValues()-1)] = notIn; | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1416 | } | 
|  | 1417 | } | 
|  | 1418 |  | 
| Andrew Lenharth | 50d91d7 | 2005-04-30 14:19:13 +0000 | [diff] [blame] | 1419 | if ((DestType == MVT::f64 || DestType == MVT::f32 || | 
|  | 1420 | ( | 
|  | 1421 | (opcode == ISD::LOAD || opcode == ISD::CopyFromReg || | 
|  | 1422 | opcode == ISD::EXTLOAD) && | 
|  | 1423 | (N.getValue(0).getValueType() == MVT::f32 || | 
|  | 1424 | N.getValue(0).getValueType() == MVT::f64) | 
|  | 1425 | )) | 
| Chris Lattner | b5d8e6e | 2005-05-13 20:29:26 +0000 | [diff] [blame] | 1426 | && opcode != ISD::CALL && opcode != ISD::TAILCALL | 
| Andrew Lenharth | 06342c3 | 2005-02-07 06:21:37 +0000 | [diff] [blame] | 1427 | ) | 
| Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1428 | return SelectExprFP(N, Result); | 
|  | 1429 |  | 
|  | 1430 | switch (opcode) { | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1431 | default: | 
|  | 1432 | Node->dump(); | 
|  | 1433 | assert(0 && "Node not handled!\n"); | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1434 |  | 
| Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 1435 | case ISD::CTPOP: | 
|  | 1436 | case ISD::CTTZ: | 
|  | 1437 | case ISD::CTLZ: | 
|  | 1438 | Opc = opcode == ISD::CTPOP ? Alpha::CTPOP : | 
|  | 1439 | (opcode == ISD::CTTZ ? Alpha::CTTZ : Alpha::CTLZ); | 
|  | 1440 | Tmp1 = SelectExpr(N.getOperand(0)); | 
|  | 1441 | BuildMI(BB, Opc, 1, Result).addReg(Tmp1); | 
|  | 1442 | return Result; | 
|  | 1443 |  | 
| Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 1444 | case ISD::MULHU: | 
|  | 1445 | Tmp1 = SelectExpr(N.getOperand(0)); | 
|  | 1446 | Tmp2 = SelectExpr(N.getOperand(1)); | 
|  | 1447 | BuildMI(BB, Alpha::UMULH, 2, Result).addReg(Tmp1).addReg(Tmp2); | 
| Andrew Lenharth | 706be91 | 2005-04-07 13:55:53 +0000 | [diff] [blame] | 1448 | return Result; | 
| Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 1449 | case ISD::MULHS: | 
|  | 1450 | { | 
|  | 1451 | //MULHU - Ra<63>*Rb - Rb<63>*Ra | 
|  | 1452 | Tmp1 = SelectExpr(N.getOperand(0)); | 
|  | 1453 | Tmp2 = SelectExpr(N.getOperand(1)); | 
|  | 1454 | Tmp3 = MakeReg(MVT::i64); | 
|  | 1455 | BuildMI(BB, Alpha::UMULH, 2, Tmp3).addReg(Tmp1).addReg(Tmp2); | 
|  | 1456 | unsigned V1 = MakeReg(MVT::i64); | 
|  | 1457 | unsigned V2 = MakeReg(MVT::i64); | 
|  | 1458 | BuildMI(BB, Alpha::CMOVGE, 3, V1).addReg(Tmp2).addReg(Alpha::R31).addReg(Tmp1); | 
|  | 1459 | BuildMI(BB, Alpha::CMOVGE, 3, V2).addReg(Tmp1).addReg(Alpha::R31).addReg(Tmp2); | 
|  | 1460 | unsigned IRes = MakeReg(MVT::i64); | 
|  | 1461 | BuildMI(BB, Alpha::SUBQ, 2, IRes).addReg(Tmp3).addReg(V1); | 
|  | 1462 | BuildMI(BB, Alpha::SUBQ, 2, Result).addReg(IRes).addReg(V2); | 
|  | 1463 | return Result; | 
|  | 1464 | } | 
| Andrew Lenharth | 7332f3e | 2005-04-02 19:11:07 +0000 | [diff] [blame] | 1465 | case ISD::UNDEF: { | 
|  | 1466 | BuildMI(BB, Alpha::IDEF, 0, Result); | 
|  | 1467 | return Result; | 
|  | 1468 | } | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1469 |  | 
| Andrew Lenharth | 032f235 | 2005-02-22 21:59:48 +0000 | [diff] [blame] | 1470 | case ISD::DYNAMIC_STACKALLOC: | 
|  | 1471 | // Generate both result values. | 
| Andrew Lenharth | 3a7118d | 2005-02-23 17:33:42 +0000 | [diff] [blame] | 1472 | if (Result != notIn) | 
|  | 1473 | ExprMap[N.getValue(1)] = notIn;   // Generate the token | 
| Andrew Lenharth | 032f235 | 2005-02-22 21:59:48 +0000 | [diff] [blame] | 1474 | else | 
|  | 1475 | Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType()); | 
|  | 1476 |  | 
|  | 1477 | // FIXME: We are currently ignoring the requested alignment for handling | 
|  | 1478 | // greater than the stack alignment.  This will need to be revisited at some | 
|  | 1479 | // point.  Align = N.getOperand(2); | 
|  | 1480 |  | 
|  | 1481 | if (!isa<ConstantSDNode>(N.getOperand(2)) || | 
|  | 1482 | cast<ConstantSDNode>(N.getOperand(2))->getValue() != 0) { | 
|  | 1483 | std::cerr << "Cannot allocate stack object with greater alignment than" | 
|  | 1484 | << " the stack alignment yet!"; | 
|  | 1485 | abort(); | 
|  | 1486 | } | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1487 |  | 
| Andrew Lenharth | 032f235 | 2005-02-22 21:59:48 +0000 | [diff] [blame] | 1488 | Select(N.getOperand(0)); | 
|  | 1489 | if (ConstantSDNode* CN = dyn_cast<ConstantSDNode>(N.getOperand(1))) | 
|  | 1490 | { | 
|  | 1491 | if (CN->getValue() < 32000) | 
|  | 1492 | { | 
|  | 1493 | BuildMI(BB, Alpha::LDA, 2, Alpha::R30) | 
|  | 1494 | .addImm(-CN->getValue()).addReg(Alpha::R30); | 
|  | 1495 | } else { | 
|  | 1496 | Tmp1 = SelectExpr(N.getOperand(1)); | 
|  | 1497 | // Subtract size from stack pointer, thereby allocating some space. | 
|  | 1498 | BuildMI(BB, Alpha::SUBQ, 2, Alpha::R30).addReg(Alpha::R30).addReg(Tmp1); | 
|  | 1499 | } | 
|  | 1500 | } else { | 
|  | 1501 | Tmp1 = SelectExpr(N.getOperand(1)); | 
|  | 1502 | // Subtract size from stack pointer, thereby allocating some space. | 
|  | 1503 | BuildMI(BB, Alpha::SUBQ, 2, Alpha::R30).addReg(Alpha::R30).addReg(Tmp1); | 
|  | 1504 | } | 
|  | 1505 |  | 
|  | 1506 | // Put a pointer to the space into the result register, by copying the stack | 
|  | 1507 | // pointer. | 
| Andrew Lenharth | 7bc4702 | 2005-02-22 23:29:25 +0000 | [diff] [blame] | 1508 | BuildMI(BB, Alpha::BIS, 2, Result).addReg(Alpha::R30).addReg(Alpha::R30); | 
| Andrew Lenharth | 032f235 | 2005-02-22 21:59:48 +0000 | [diff] [blame] | 1509 | return Result; | 
|  | 1510 |  | 
| Andrew Lenharth | 3381913 | 2005-03-04 20:09:23 +0000 | [diff] [blame] | 1511 | //   case ISD::ConstantPool: | 
|  | 1512 | //     Tmp1 = cast<ConstantPoolSDNode>(N)->getIndex(); | 
|  | 1513 | //     AlphaLowering.restoreGP(BB); | 
|  | 1514 | //     BuildMI(BB, Alpha::LDQ_SYM, 1, Result).addConstantPoolIndex(Tmp1); | 
|  | 1515 | //     return Result; | 
| Andrew Lenharth | 2c59435 | 2005-01-29 15:42:07 +0000 | [diff] [blame] | 1516 |  | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1517 | case ISD::FrameIndex: | 
| Andrew Lenharth | 032f235 | 2005-02-22 21:59:48 +0000 | [diff] [blame] | 1518 | BuildMI(BB, Alpha::LDA, 2, Result) | 
|  | 1519 | .addFrameIndex(cast<FrameIndexSDNode>(N)->getIndex()) | 
|  | 1520 | .addReg(Alpha::F31); | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1521 | return Result; | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1522 |  | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1523 | case ISD::EXTLOAD: | 
| Andrew Lenharth | f311e8b | 2005-02-07 05:18:02 +0000 | [diff] [blame] | 1524 | case ISD::ZEXTLOAD: | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1525 | case ISD::SEXTLOAD: | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1526 | case ISD::LOAD: | 
| Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 1527 | { | 
|  | 1528 | // Make sure we generate both values. | 
|  | 1529 | if (Result != notIn) | 
|  | 1530 | ExprMap[N.getValue(1)] = notIn;   // Generate the token | 
|  | 1531 | else | 
|  | 1532 | Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType()); | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1533 |  | 
| Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 1534 | SDOperand Chain   = N.getOperand(0); | 
|  | 1535 | SDOperand Address = N.getOperand(1); | 
|  | 1536 | Select(Chain); | 
|  | 1537 |  | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1538 | assert(Node->getValueType(0) == MVT::i64 && | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1539 | "Unknown type to sign extend to."); | 
| Andrew Lenharth | 0382401 | 2005-02-07 05:55:55 +0000 | [diff] [blame] | 1540 | if (opcode == ISD::LOAD) | 
|  | 1541 | Opc = Alpha::LDQ; | 
|  | 1542 | else | 
| Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 1543 | switch (cast<MVTSDNode>(Node)->getExtraValueType()) { | 
|  | 1544 | default: Node->dump(); assert(0 && "Bad sign extend!"); | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1545 | case MVT::i32: Opc = Alpha::LDL; | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1546 | assert(opcode != ISD::ZEXTLOAD && "Not sext"); break; | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1547 | case MVT::i16: Opc = Alpha::LDWU; | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1548 | assert(opcode != ISD::SEXTLOAD && "Not zext"); break; | 
| Andrew Lenharth | f311e8b | 2005-02-07 05:18:02 +0000 | [diff] [blame] | 1549 | 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] | 1550 | case MVT::i8: Opc = Alpha::LDBU; | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1551 | assert(opcode != ISD::SEXTLOAD && "Not zext"); break; | 
| Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 1552 | } | 
| Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 1553 |  | 
| Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 1554 | if (EnableAlphaLSMark) | 
|  | 1555 | { | 
|  | 1556 | int i = getValueOffset(dyn_cast<SrcValueSDNode>(N.getOperand(2))->getValue()); | 
|  | 1557 | int j = getFunctionOffset(BB->getParent()->getFunction()); | 
|  | 1558 | BuildMI(BB, Alpha::MEMLABEL, 3).addImm(j).addImm(i).addImm(getUID()); | 
|  | 1559 | } | 
|  | 1560 |  | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1561 | if (Address.getOpcode() == ISD::GlobalAddress) { | 
|  | 1562 | AlphaLowering.restoreGP(BB); | 
|  | 1563 | Opc = GetSymVersion(Opc); | 
| Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 1564 | has_sym = true; | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1565 | BuildMI(BB, Opc, 1, Result).addGlobalAddress(cast<GlobalAddressSDNode>(Address)->getGlobal()); | 
|  | 1566 | } | 
| Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 1567 | else if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(Address)) { | 
|  | 1568 | AlphaLowering.restoreGP(BB); | 
| Andrew Lenharth | 6583890 | 2005-02-06 16:22:15 +0000 | [diff] [blame] | 1569 | Opc = GetSymVersion(Opc); | 
| Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 1570 | has_sym = true; | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1571 | BuildMI(BB, Opc, 1, Result).addConstantPoolIndex(CP->getIndex()); | 
| Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 1572 | } | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1573 | else if(Address.getOpcode() == ISD::FrameIndex) { | 
| Andrew Lenharth | 032f235 | 2005-02-22 21:59:48 +0000 | [diff] [blame] | 1574 | BuildMI(BB, Opc, 2, Result) | 
|  | 1575 | .addFrameIndex(cast<FrameIndexSDNode>(Address)->getIndex()) | 
|  | 1576 | .addReg(Alpha::F31); | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1577 | } else { | 
|  | 1578 | long offset; | 
|  | 1579 | SelectAddr(Address, Tmp1, offset); | 
|  | 1580 | BuildMI(BB, Opc, 2, Result).addImm(offset).addReg(Tmp1); | 
|  | 1581 | } | 
| Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 1582 | return Result; | 
| Andrew Lenharth | 2f8fb77 | 2005-01-25 00:35:34 +0000 | [diff] [blame] | 1583 | } | 
| Andrew Lenharth | 2f8fb77 | 2005-01-25 00:35:34 +0000 | [diff] [blame] | 1584 |  | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1585 | case ISD::GlobalAddress: | 
|  | 1586 | AlphaLowering.restoreGP(BB); | 
| Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 1587 | has_sym = true; | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1588 | BuildMI(BB, Alpha::LOAD_ADDR, 1, Result) | 
|  | 1589 | .addGlobalAddress(cast<GlobalAddressSDNode>(N)->getGlobal()); | 
|  | 1590 | return Result; | 
|  | 1591 |  | 
| Chris Lattner | b5d8e6e | 2005-05-13 20:29:26 +0000 | [diff] [blame] | 1592 | case ISD::TAILCALL: | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1593 | case ISD::CALL: | 
|  | 1594 | { | 
|  | 1595 | Select(N.getOperand(0)); | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1596 |  | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1597 | // The chain for this call is now lowered. | 
| Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 1598 | ExprMap.insert(std::make_pair(N.getValue(Node->getNumValues()-1), notIn)); | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1599 |  | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1600 | //grab the arguments | 
|  | 1601 | std::vector<unsigned> argvregs; | 
| Andrew Lenharth | 7b2a527 | 2005-01-30 20:42:36 +0000 | [diff] [blame] | 1602 | //assert(Node->getNumOperands() < 8 && "Only 6 args supported"); | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1603 | for(int i = 2, e = Node->getNumOperands(); i < e; ++i) | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1604 | argvregs.push_back(SelectExpr(N.getOperand(i))); | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1605 |  | 
| Andrew Lenharth | 684f229 | 2005-01-30 00:35:27 +0000 | [diff] [blame] | 1606 | //in reg args | 
|  | 1607 | 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] | 1608 | { | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1609 | unsigned args_int[] = {Alpha::R16, Alpha::R17, Alpha::R18, | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1610 | Alpha::R19, Alpha::R20, Alpha::R21}; | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1611 | unsigned args_float[] = {Alpha::F16, Alpha::F17, Alpha::F18, | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1612 | Alpha::F19, Alpha::F20, Alpha::F21}; | 
|  | 1613 | switch(N.getOperand(i+2).getValueType()) { | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1614 | default: | 
|  | 1615 | Node->dump(); | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1616 | N.getOperand(i).Val->dump(); | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1617 | std::cerr << "Type for " << i << " is: " << | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1618 | N.getOperand(i+2).getValueType() << "\n"; | 
|  | 1619 | assert(0 && "Unknown value type for call"); | 
|  | 1620 | case MVT::i1: | 
|  | 1621 | case MVT::i8: | 
|  | 1622 | case MVT::i16: | 
|  | 1623 | case MVT::i32: | 
|  | 1624 | case MVT::i64: | 
|  | 1625 | BuildMI(BB, Alpha::BIS, 2, args_int[i]).addReg(argvregs[i]).addReg(argvregs[i]); | 
|  | 1626 | break; | 
|  | 1627 | case MVT::f32: | 
|  | 1628 | case MVT::f64: | 
|  | 1629 | BuildMI(BB, Alpha::CPYS, 2, args_float[i]).addReg(argvregs[i]).addReg(argvregs[i]); | 
|  | 1630 | break; | 
| Andrew Lenharth | 684f229 | 2005-01-30 00:35:27 +0000 | [diff] [blame] | 1631 | } | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1632 | } | 
| Andrew Lenharth | 684f229 | 2005-01-30 00:35:27 +0000 | [diff] [blame] | 1633 | //in mem args | 
|  | 1634 | for (int i = 6, e = argvregs.size(); i < e; ++i) | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1635 | { | 
|  | 1636 | switch(N.getOperand(i+2).getValueType()) { | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1637 | default: | 
|  | 1638 | Node->dump(); | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1639 | N.getOperand(i).Val->dump(); | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1640 | std::cerr << "Type for " << i << " is: " << | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1641 | N.getOperand(i+2).getValueType() << "\n"; | 
|  | 1642 | assert(0 && "Unknown value type for call"); | 
|  | 1643 | case MVT::i1: | 
|  | 1644 | case MVT::i8: | 
|  | 1645 | case MVT::i16: | 
|  | 1646 | case MVT::i32: | 
|  | 1647 | case MVT::i64: | 
|  | 1648 | BuildMI(BB, Alpha::STQ, 3).addReg(argvregs[i]).addImm((i - 6) * 8).addReg(Alpha::R30); | 
|  | 1649 | break; | 
|  | 1650 | case MVT::f32: | 
|  | 1651 | BuildMI(BB, Alpha::STS, 3).addReg(argvregs[i]).addImm((i - 6) * 8).addReg(Alpha::R30); | 
|  | 1652 | break; | 
|  | 1653 | case MVT::f64: | 
|  | 1654 | BuildMI(BB, Alpha::STT, 3).addReg(argvregs[i]).addImm((i - 6) * 8).addReg(Alpha::R30); | 
|  | 1655 | break; | 
| Andrew Lenharth | 684f229 | 2005-01-30 00:35:27 +0000 | [diff] [blame] | 1656 | } | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1657 | } | 
| Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 1658 | //build the right kind of call | 
|  | 1659 | if (GlobalAddressSDNode *GASD = | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1660 | dyn_cast<GlobalAddressSDNode>(N.getOperand(1))) | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1661 | { | 
| Andrew Lenharth | c24b537 | 2005-04-13 17:17:28 +0000 | [diff] [blame] | 1662 | if (GASD->getGlobal()->isExternal()) { | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1663 | //use safe calling convention | 
| Andrew Lenharth | 7b2a527 | 2005-01-30 20:42:36 +0000 | [diff] [blame] | 1664 | AlphaLowering.restoreGP(BB); | 
| Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 1665 | has_sym = true; | 
| Andrew Lenharth | c24b537 | 2005-04-13 17:17:28 +0000 | [diff] [blame] | 1666 | BuildMI(BB, Alpha::CALL, 1).addGlobalAddress(GASD->getGlobal()); | 
|  | 1667 | } else { | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1668 | //use PC relative branch call | 
| Andrew Lenharth | 1e0d9bd | 2005-04-14 17:34:20 +0000 | [diff] [blame] | 1669 | AlphaLowering.restoreGP(BB); | 
| Andrew Lenharth | c24b537 | 2005-04-13 17:17:28 +0000 | [diff] [blame] | 1670 | BuildMI(BB, Alpha::BSR, 1, Alpha::R26).addGlobalAddress(GASD->getGlobal(),true); | 
|  | 1671 | } | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1672 | } | 
| Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 1673 | else if (ExternalSymbolSDNode *ESSDN = | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1674 | dyn_cast<ExternalSymbolSDNode>(N.getOperand(1))) | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1675 | { | 
|  | 1676 | AlphaLowering.restoreGP(BB); | 
| Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 1677 | has_sym = true; | 
| Andrew Lenharth | ba05ad6 | 2005-03-30 18:22:52 +0000 | [diff] [blame] | 1678 | BuildMI(BB, Alpha::CALL, 1).addExternalSymbol(ESSDN->getSymbol(), true); | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1679 | } else { | 
|  | 1680 | //no need to restore GP as we are doing an indirect call | 
|  | 1681 | Tmp1 = SelectExpr(N.getOperand(1)); | 
|  | 1682 | BuildMI(BB, Alpha::BIS, 2, Alpha::R27).addReg(Tmp1).addReg(Tmp1); | 
|  | 1683 | BuildMI(BB, Alpha::JSR, 2, Alpha::R26).addReg(Alpha::R27).addImm(0); | 
|  | 1684 | } | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1685 |  | 
| Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 1686 | //push the result into a virtual register | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1687 |  | 
| Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 1688 | switch (Node->getValueType(0)) { | 
|  | 1689 | default: Node->dump(); assert(0 && "Unknown value type for call result!"); | 
| Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 1690 | case MVT::Other: return notIn; | 
| Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 1691 | case MVT::i1: | 
|  | 1692 | case MVT::i8: | 
|  | 1693 | case MVT::i16: | 
|  | 1694 | case MVT::i32: | 
|  | 1695 | case MVT::i64: | 
| Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1696 | BuildMI(BB, Alpha::BIS, 2, Result).addReg(Alpha::R0).addReg(Alpha::R0); | 
|  | 1697 | break; | 
| Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 1698 | case MVT::f32: | 
|  | 1699 | case MVT::f64: | 
| Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1700 | BuildMI(BB, Alpha::CPYS, 2, Result).addReg(Alpha::F0).addReg(Alpha::F0); | 
|  | 1701 | break; | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1702 | } | 
| Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 1703 | return Result+N.ResNo; | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1704 | } | 
|  | 1705 |  | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1706 | case ISD::SIGN_EXTEND_INREG: | 
|  | 1707 | { | 
| Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 1708 | //do SDIV opt for all levels of ints if not dividing by a constant | 
|  | 1709 | if (EnableAlphaIDIV && N.getOperand(0).getOpcode() == ISD::SDIV | 
|  | 1710 | && N.getOperand(0).getOperand(1).getOpcode() != ISD::Constant) | 
| Andrew Lenharth | dc0b71b | 2005-03-22 00:24:07 +0000 | [diff] [blame] | 1711 | { | 
| Andrew Lenharth | dc0b71b | 2005-03-22 00:24:07 +0000 | [diff] [blame] | 1712 | unsigned Tmp4 = MakeReg(MVT::f64); | 
|  | 1713 | unsigned Tmp5 = MakeReg(MVT::f64); | 
|  | 1714 | unsigned Tmp6 = MakeReg(MVT::f64); | 
|  | 1715 | unsigned Tmp7 = MakeReg(MVT::f64); | 
|  | 1716 | unsigned Tmp8 = MakeReg(MVT::f64); | 
|  | 1717 | unsigned Tmp9 = MakeReg(MVT::f64); | 
| Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 1718 |  | 
|  | 1719 | Tmp1 = SelectExpr(N.getOperand(0).getOperand(0)); | 
|  | 1720 | Tmp2 = SelectExpr(N.getOperand(0).getOperand(1)); | 
|  | 1721 | MoveInt2FP(Tmp1, Tmp4, true); | 
|  | 1722 | MoveInt2FP(Tmp2, Tmp5, true); | 
| Andrew Lenharth | dc0b71b | 2005-03-22 00:24:07 +0000 | [diff] [blame] | 1723 | BuildMI(BB, Alpha::CVTQT, 1, Tmp6).addReg(Tmp4); | 
|  | 1724 | BuildMI(BB, Alpha::CVTQT, 1, Tmp7).addReg(Tmp5); | 
|  | 1725 | BuildMI(BB, Alpha::DIVT, 2, Tmp8).addReg(Tmp6).addReg(Tmp7); | 
|  | 1726 | BuildMI(BB, Alpha::CVTTQ, 1, Tmp9).addReg(Tmp8); | 
| Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 1727 | MoveFP2Int(Tmp9, Result, true); | 
| Andrew Lenharth | dc0b71b | 2005-03-22 00:24:07 +0000 | [diff] [blame] | 1728 | return Result; | 
|  | 1729 | } | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1730 |  | 
| Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 1731 | //Alpha has instructions for a bunch of signed 32 bit stuff | 
|  | 1732 | if( dyn_cast<MVTSDNode>(Node)->getExtraValueType() == MVT::i32) | 
| Andrew Lenharth | dc0b71b | 2005-03-22 00:24:07 +0000 | [diff] [blame] | 1733 | { | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1734 | switch (N.getOperand(0).getOpcode()) { | 
|  | 1735 | case ISD::ADD: | 
|  | 1736 | case ISD::SUB: | 
|  | 1737 | case ISD::MUL: | 
|  | 1738 | { | 
|  | 1739 | bool isAdd = N.getOperand(0).getOpcode() == ISD::ADD; | 
|  | 1740 | bool isMul = N.getOperand(0).getOpcode() == ISD::MUL; | 
|  | 1741 | //FIXME: first check for Scaled Adds and Subs! | 
| Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 1742 | ConstantSDNode* CSD = NULL; | 
|  | 1743 | if(!isMul && N.getOperand(0).getOperand(0).getOpcode() == ISD::SHL && | 
|  | 1744 | (CSD = dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(0).getOperand(1))) && | 
|  | 1745 | (CSD->getValue() == 2 || CSD->getValue() == 3)) | 
|  | 1746 | { | 
|  | 1747 | bool use4 = CSD->getValue() == 2; | 
|  | 1748 | Tmp1 = SelectExpr(N.getOperand(0).getOperand(0).getOperand(0)); | 
|  | 1749 | Tmp2 = SelectExpr(N.getOperand(0).getOperand(1)); | 
|  | 1750 | BuildMI(BB, isAdd?(use4?Alpha::S4ADDL:Alpha::S8ADDL):(use4?Alpha::S4SUBL:Alpha::S8SUBL), | 
|  | 1751 | 2,Result).addReg(Tmp1).addReg(Tmp2); | 
|  | 1752 | } | 
|  | 1753 | else if(isAdd && N.getOperand(0).getOperand(1).getOpcode() == ISD::SHL && | 
|  | 1754 | (CSD = dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1).getOperand(1))) && | 
|  | 1755 | (CSD->getValue() == 2 || CSD->getValue() == 3)) | 
|  | 1756 | { | 
|  | 1757 | bool use4 = CSD->getValue() == 2; | 
|  | 1758 | Tmp1 = SelectExpr(N.getOperand(0).getOperand(1).getOperand(0)); | 
|  | 1759 | Tmp2 = SelectExpr(N.getOperand(0).getOperand(0)); | 
|  | 1760 | BuildMI(BB, use4?Alpha::S4ADDL:Alpha::S8ADDL, 2,Result).addReg(Tmp1).addReg(Tmp2); | 
|  | 1761 | } | 
|  | 1762 | else if(N.getOperand(0).getOperand(1).getOpcode() == ISD::Constant && | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1763 | cast<ConstantSDNode>(N.getOperand(0).getOperand(1))->getValue() <= 255) | 
|  | 1764 | { //Normal imm add/sub | 
|  | 1765 | Opc = isAdd ? Alpha::ADDLi : (isMul ? Alpha::MULLi : Alpha::SUBLi); | 
| Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 1766 | Tmp1 = SelectExpr(N.getOperand(0).getOperand(0)); | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1767 | Tmp2 = cast<ConstantSDNode>(N.getOperand(0).getOperand(1))->getValue(); | 
|  | 1768 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(Tmp2); | 
| Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 1769 | } | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1770 | else | 
|  | 1771 | { //Normal add/sub | 
| Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 1772 | Opc = isAdd ? Alpha::ADDL : (isMul ? Alpha::MULL : Alpha::SUBL); | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1773 | Tmp1 = SelectExpr(N.getOperand(0).getOperand(0)); | 
| Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 1774 | Tmp2 = SelectExpr(N.getOperand(0).getOperand(1)); | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1775 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2); | 
|  | 1776 | } | 
|  | 1777 | return Result; | 
| Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 1778 | } | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1779 | default: break; //Fall Though; | 
|  | 1780 | } | 
|  | 1781 | } //Every thing else fall though too, including unhandled opcodes above | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1782 | Tmp1 = SelectExpr(N.getOperand(0)); | 
|  | 1783 | MVTSDNode* MVN = dyn_cast<MVTSDNode>(Node); | 
| Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 1784 | //std::cerr << "SrcT: " << MVN->getExtraValueType() << "\n"; | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1785 | switch(MVN->getExtraValueType()) | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1786 | { | 
|  | 1787 | default: | 
|  | 1788 | Node->dump(); | 
|  | 1789 | assert(0 && "Sign Extend InReg not there yet"); | 
|  | 1790 | break; | 
|  | 1791 | case MVT::i32: | 
| Andrew Lenharth | 3d65d31 | 2005-01-27 03:49:45 +0000 | [diff] [blame] | 1792 | { | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1793 | BuildMI(BB, Alpha::ADDLi, 2, Result).addReg(Tmp1).addImm(0); | 
| Andrew Lenharth | 3d65d31 | 2005-01-27 03:49:45 +0000 | [diff] [blame] | 1794 | break; | 
|  | 1795 | } | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1796 | case MVT::i16: | 
|  | 1797 | BuildMI(BB, Alpha::SEXTW, 1, Result).addReg(Tmp1); | 
|  | 1798 | break; | 
|  | 1799 | case MVT::i8: | 
|  | 1800 | BuildMI(BB, Alpha::SEXTB, 1, Result).addReg(Tmp1); | 
|  | 1801 | break; | 
| Andrew Lenharth | ebce504 | 2005-02-12 19:35:12 +0000 | [diff] [blame] | 1802 | case MVT::i1: | 
|  | 1803 | Tmp2 = MakeReg(MVT::i64); | 
|  | 1804 | BuildMI(BB, Alpha::ANDi, 2, Tmp2).addReg(Tmp1).addImm(1); | 
| Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 1805 | BuildMI(BB, Alpha::SUBQ, 2, Result).addReg(Alpha::R31).addReg(Tmp2); | 
| Andrew Lenharth | ebce504 | 2005-02-12 19:35:12 +0000 | [diff] [blame] | 1806 | break; | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1807 | } | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1808 | return Result; | 
|  | 1809 | } | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1810 |  | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1811 | case ISD::SETCC: | 
| Andrew Lenharth | 3d65d31 | 2005-01-27 03:49:45 +0000 | [diff] [blame] | 1812 | { | 
|  | 1813 | if (SetCCSDNode *SetCC = dyn_cast<SetCCSDNode>(Node)) { | 
|  | 1814 | if (MVT::isInteger(SetCC->getOperand(0).getValueType())) { | 
|  | 1815 | bool isConst1 = false; | 
|  | 1816 | bool isConst2 = false; | 
|  | 1817 | int dir; | 
| Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1818 |  | 
| Andrew Lenharth | 3d65d31 | 2005-01-27 03:49:45 +0000 | [diff] [blame] | 1819 | //Tmp1 = SelectExpr(N.getOperand(0)); | 
|  | 1820 | if(N.getOperand(0).getOpcode() == ISD::Constant && | 
| Andrew Lenharth | 3d65d31 | 2005-01-27 03:49:45 +0000 | [diff] [blame] | 1821 | cast<ConstantSDNode>(N.getOperand(0))->getValue() <= 255) | 
|  | 1822 | isConst1 = true; | 
|  | 1823 | if(N.getOperand(1).getOpcode() == ISD::Constant && | 
| Andrew Lenharth | 3d65d31 | 2005-01-27 03:49:45 +0000 | [diff] [blame] | 1824 | cast<ConstantSDNode>(N.getOperand(1))->getValue() <= 255) | 
|  | 1825 | isConst2 = true; | 
|  | 1826 |  | 
|  | 1827 | switch (SetCC->getCondition()) { | 
|  | 1828 | default: Node->dump(); assert(0 && "Unknown integer comparison!"); | 
|  | 1829 | case ISD::SETEQ: Opc = Alpha::CMPEQ; dir=0; break; | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1830 | case ISD::SETLT: | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1831 | Opc = isConst2 ? Alpha::CMPLTi : Alpha::CMPLT; dir = 1; break; | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1832 | case ISD::SETLE: | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1833 | Opc = isConst2 ? Alpha::CMPLEi : Alpha::CMPLE; dir = 1; break; | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1834 | case ISD::SETGT: | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1835 | Opc = isConst1 ? Alpha::CMPLTi : Alpha::CMPLT; dir = 2; break; | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1836 | case ISD::SETGE: | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1837 | Opc = isConst1 ? Alpha::CMPLEi : Alpha::CMPLE; dir = 2; break; | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1838 | case ISD::SETULT: | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1839 | Opc = isConst2 ? Alpha::CMPULTi : Alpha::CMPULT; dir = 1; break; | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1840 | case ISD::SETUGT: | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1841 | Opc = isConst1 ? Alpha::CMPULTi : Alpha::CMPULT; dir = 2; break; | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1842 | case ISD::SETULE: | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1843 | Opc = isConst2 ? Alpha::CMPULEi : Alpha::CMPULE; dir = 1; break; | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1844 | case ISD::SETUGE: | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1845 | Opc = isConst1 ? Alpha::CMPULEi : Alpha::CMPULE; dir = 2; break; | 
| Andrew Lenharth | d2bb960 | 2005-01-27 07:50:35 +0000 | [diff] [blame] | 1846 | case ISD::SETNE: {//Handle this one special | 
|  | 1847 | //std::cerr << "Alpha does not have a setne.\n"; | 
|  | 1848 | //abort(); | 
|  | 1849 | Tmp1 = SelectExpr(N.getOperand(0)); | 
|  | 1850 | Tmp2 = SelectExpr(N.getOperand(1)); | 
|  | 1851 | Tmp3 = MakeReg(MVT::i64); | 
|  | 1852 | BuildMI(BB, Alpha::CMPEQ, 2, Tmp3).addReg(Tmp1).addReg(Tmp2); | 
| Andrew Lenharth | 445171a | 2005-02-08 00:40:03 +0000 | [diff] [blame] | 1853 | //Remeber we have the Inv for this CC | 
|  | 1854 | CCInvMap[N] = Tmp3; | 
| Andrew Lenharth | d2bb960 | 2005-01-27 07:50:35 +0000 | [diff] [blame] | 1855 | //and invert | 
| Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 1856 | BuildMI(BB, Alpha::CMPEQ, 2, Result).addReg(Alpha::R31).addReg(Tmp3); | 
| Andrew Lenharth | d2bb960 | 2005-01-27 07:50:35 +0000 | [diff] [blame] | 1857 | return Result; | 
|  | 1858 | } | 
|  | 1859 | } | 
| Andrew Lenharth | 3d65d31 | 2005-01-27 03:49:45 +0000 | [diff] [blame] | 1860 | if (dir == 1) { | 
|  | 1861 | Tmp1 = SelectExpr(N.getOperand(0)); | 
|  | 1862 | if (isConst2) { | 
|  | 1863 | Tmp2 = cast<ConstantSDNode>(N.getOperand(1))->getValue(); | 
|  | 1864 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(Tmp2); | 
|  | 1865 | } else { | 
|  | 1866 | Tmp2 = SelectExpr(N.getOperand(1)); | 
|  | 1867 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2); | 
|  | 1868 | } | 
|  | 1869 | } else if (dir == 2) { | 
|  | 1870 | Tmp1 = SelectExpr(N.getOperand(1)); | 
| Andrew Lenharth | 6b9870a | 2005-01-28 14:06:46 +0000 | [diff] [blame] | 1871 | if (isConst1) { | 
| Andrew Lenharth | 3d65d31 | 2005-01-27 03:49:45 +0000 | [diff] [blame] | 1872 | Tmp2 = cast<ConstantSDNode>(N.getOperand(0))->getValue(); | 
|  | 1873 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(Tmp2); | 
|  | 1874 | } else { | 
|  | 1875 | Tmp2 = SelectExpr(N.getOperand(0)); | 
|  | 1876 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2); | 
|  | 1877 | } | 
|  | 1878 | } else { //dir == 0 | 
|  | 1879 | if (isConst1) { | 
|  | 1880 | Tmp1 = cast<ConstantSDNode>(N.getOperand(0))->getValue(); | 
|  | 1881 | Tmp2 = SelectExpr(N.getOperand(1)); | 
|  | 1882 | BuildMI(BB, Alpha::CMPEQi, 2, Result).addReg(Tmp2).addImm(Tmp1); | 
|  | 1883 | } else if (isConst2) { | 
|  | 1884 | Tmp1 = SelectExpr(N.getOperand(0)); | 
|  | 1885 | Tmp2 = cast<ConstantSDNode>(N.getOperand(1))->getValue(); | 
|  | 1886 | BuildMI(BB, Alpha::CMPEQi, 2, Result).addReg(Tmp1).addImm(Tmp2); | 
|  | 1887 | } else { | 
|  | 1888 | Tmp1 = SelectExpr(N.getOperand(0)); | 
|  | 1889 | Tmp2 = SelectExpr(N.getOperand(1)); | 
|  | 1890 | BuildMI(BB, Alpha::CMPEQ, 2, Result).addReg(Tmp1).addReg(Tmp2); | 
|  | 1891 | } | 
| Andrew Lenharth | d4bdd54 | 2005-02-05 16:41:03 +0000 | [diff] [blame] | 1892 | } | 
|  | 1893 | } else { | 
| Andrew Lenharth | d4bdd54 | 2005-02-05 16:41:03 +0000 | [diff] [blame] | 1894 | //do the comparison | 
| Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 1895 | Tmp1 = MakeReg(MVT::f64); | 
|  | 1896 | bool inv = SelectFPSetCC(N, Tmp1); | 
|  | 1897 |  | 
| Andrew Lenharth | d4bdd54 | 2005-02-05 16:41:03 +0000 | [diff] [blame] | 1898 | //now arrange for Result (int) to have a 1 or 0 | 
| Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 1899 | Tmp2 = MakeReg(MVT::i64); | 
|  | 1900 | BuildMI(BB, Alpha::ADDQi, 2, Tmp2).addReg(Alpha::R31).addImm(1); | 
| Andrew Lenharth | dc0b71b | 2005-03-22 00:24:07 +0000 | [diff] [blame] | 1901 | Opc = inv?Alpha::CMOVNEi_FP:Alpha::CMOVEQi_FP; | 
| Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 1902 | BuildMI(BB, Opc, 3, Result).addReg(Tmp2).addImm(0).addReg(Tmp1); | 
| Andrew Lenharth | d4bdd54 | 2005-02-05 16:41:03 +0000 | [diff] [blame] | 1903 | } | 
| Andrew Lenharth | 9818c05 | 2005-02-05 13:19:12 +0000 | [diff] [blame] | 1904 | } | 
| Andrew Lenharth | 3d65d31 | 2005-01-27 03:49:45 +0000 | [diff] [blame] | 1905 | return Result; | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1906 | } | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1907 |  | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1908 | case ISD::CopyFromReg: | 
|  | 1909 | { | 
| Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 1910 | ++count_ins; | 
|  | 1911 |  | 
| Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1912 | // Make sure we generate both values. | 
| Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 1913 | if (Result != notIn) | 
| Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1914 | ExprMap[N.getValue(1)] = notIn;   // Generate the token | 
| Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1915 | else | 
| Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1916 | Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType()); | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1917 |  | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1918 | SDOperand Chain   = N.getOperand(0); | 
|  | 1919 |  | 
|  | 1920 | Select(Chain); | 
|  | 1921 | unsigned r = dyn_cast<RegSDNode>(Node)->getReg(); | 
|  | 1922 | //std::cerr << "CopyFromReg " << Result << " = " << r << "\n"; | 
|  | 1923 | BuildMI(BB, Alpha::BIS, 2, Result).addReg(r).addReg(r); | 
|  | 1924 | return Result; | 
|  | 1925 | } | 
|  | 1926 |  | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1927 | //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] | 1928 | //constant immediate test | 
| Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 1929 | case ISD::XOR: | 
| Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 1930 | //Match Not | 
|  | 1931 | if (N.getOperand(1).getOpcode() == ISD::Constant && | 
| Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1932 | cast<ConstantSDNode>(N.getOperand(1))->getSignExtended() == -1) | 
| Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 1933 | { | 
| Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1934 | Tmp1 = SelectExpr(N.getOperand(0)); | 
|  | 1935 | BuildMI(BB, Alpha::ORNOT, 2, Result).addReg(Alpha::R31).addReg(Tmp1); | 
|  | 1936 | return Result; | 
| Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 1937 | } | 
|  | 1938 | //Fall through | 
|  | 1939 | case ISD::AND: | 
| Andrew Lenharth | 483f22d | 2005-04-13 03:47:03 +0000 | [diff] [blame] | 1940 | //handle zap | 
|  | 1941 | if (opcode == ISD::AND && N.getOperand(1).getOpcode() == ISD::Constant) | 
|  | 1942 | { | 
|  | 1943 | uint64_t k = cast<ConstantSDNode>(N.getOperand(1))->getValue(); | 
|  | 1944 | unsigned int build = 0; | 
|  | 1945 | for(int i = 0; i < 8; ++i) | 
|  | 1946 | { | 
| Andrew Lenharth | 3ae1829 | 2005-04-14 16:24:00 +0000 | [diff] [blame] | 1947 | if ((k & 0x00FF) == 0x00FF) | 
| Andrew Lenharth | 483f22d | 2005-04-13 03:47:03 +0000 | [diff] [blame] | 1948 | build |= 1 << i; | 
| Andrew Lenharth | 3ae1829 | 2005-04-14 16:24:00 +0000 | [diff] [blame] | 1949 | else if ((k & 0x00FF) != 0) | 
| Andrew Lenharth | 483f22d | 2005-04-13 03:47:03 +0000 | [diff] [blame] | 1950 | { build = 0; break; } | 
|  | 1951 | k >>= 8; | 
|  | 1952 | } | 
|  | 1953 | if (build) | 
|  | 1954 | { | 
|  | 1955 | Tmp1 = SelectExpr(N.getOperand(0)); | 
|  | 1956 | BuildMI(BB, Alpha::ZAPNOTi, 2, Result).addReg(Tmp1).addImm(build); | 
|  | 1957 | return Result; | 
|  | 1958 | } | 
|  | 1959 | } | 
| Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 1960 | case ISD::OR: | 
| Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 1961 | //Check operand(0) == Not | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1962 | if (N.getOperand(0).getOpcode() == ISD::XOR && | 
| Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 1963 | N.getOperand(0).getOperand(1).getOpcode() == ISD::Constant && | 
| Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1964 | cast<ConstantSDNode>(N.getOperand(0).getOperand(1))->getSignExtended() == -1) | 
| Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 1965 | { | 
| Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1966 | switch(opcode) { | 
|  | 1967 | case ISD::AND: Opc = Alpha::BIC; break; | 
|  | 1968 | case ISD::OR:  Opc = Alpha::ORNOT; break; | 
|  | 1969 | case ISD::XOR: Opc = Alpha::EQV; break; | 
|  | 1970 | } | 
|  | 1971 | Tmp1 = SelectExpr(N.getOperand(1)); | 
|  | 1972 | Tmp2 = SelectExpr(N.getOperand(0).getOperand(0)); | 
|  | 1973 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2); | 
|  | 1974 | return Result; | 
| Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 1975 | } | 
|  | 1976 | //Check operand(1) == Not | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1977 | if (N.getOperand(1).getOpcode() == ISD::XOR && | 
| Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 1978 | N.getOperand(1).getOperand(1).getOpcode() == ISD::Constant && | 
| Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1979 | cast<ConstantSDNode>(N.getOperand(1).getOperand(1))->getSignExtended() == -1) | 
| Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 1980 | { | 
| Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1981 | switch(opcode) { | 
|  | 1982 | case ISD::AND: Opc = Alpha::BIC; break; | 
|  | 1983 | case ISD::OR:  Opc = Alpha::ORNOT; break; | 
|  | 1984 | case ISD::XOR: Opc = Alpha::EQV; break; | 
|  | 1985 | } | 
|  | 1986 | Tmp1 = SelectExpr(N.getOperand(0)); | 
|  | 1987 | Tmp2 = SelectExpr(N.getOperand(1).getOperand(0)); | 
|  | 1988 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2); | 
|  | 1989 | return Result; | 
| Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 1990 | } | 
|  | 1991 | //Fall through | 
| Andrew Lenharth | 2d6f022 | 2005-01-24 19:44:07 +0000 | [diff] [blame] | 1992 | case ISD::SHL: | 
|  | 1993 | case ISD::SRL: | 
| Andrew Lenharth | 2c59435 | 2005-01-29 15:42:07 +0000 | [diff] [blame] | 1994 | case ISD::SRA: | 
| Andrew Lenharth | 2d6f022 | 2005-01-24 19:44:07 +0000 | [diff] [blame] | 1995 | case ISD::MUL: | 
| Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1996 | assert (DestType == MVT::i64 && "Only do arithmetic on i64s!"); | 
|  | 1997 | if(N.getOperand(1).getOpcode() == ISD::Constant && | 
| Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1998 | cast<ConstantSDNode>(N.getOperand(1))->getValue() <= 255) | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1999 | { | 
|  | 2000 | switch(opcode) { | 
|  | 2001 | case ISD::AND: Opc = Alpha::ANDi; break; | 
|  | 2002 | case ISD::OR:  Opc = Alpha::BISi; break; | 
|  | 2003 | case ISD::XOR: Opc = Alpha::XORi; break; | 
|  | 2004 | case ISD::SHL: Opc = Alpha::SLi; break; | 
|  | 2005 | case ISD::SRL: Opc = Alpha::SRLi; break; | 
|  | 2006 | case ISD::SRA: Opc = Alpha::SRAi; break; | 
|  | 2007 | case ISD::MUL: Opc = Alpha::MULQi; break; | 
|  | 2008 | }; | 
|  | 2009 | Tmp1 = SelectExpr(N.getOperand(0)); | 
|  | 2010 | Tmp2 = cast<ConstantSDNode>(N.getOperand(1))->getValue(); | 
|  | 2011 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(Tmp2); | 
|  | 2012 | } else { | 
|  | 2013 | switch(opcode) { | 
|  | 2014 | case ISD::AND: Opc = Alpha::AND; break; | 
|  | 2015 | case ISD::OR:  Opc = Alpha::BIS; break; | 
|  | 2016 | case ISD::XOR: Opc = Alpha::XOR; break; | 
|  | 2017 | case ISD::SHL: Opc = Alpha::SL; break; | 
|  | 2018 | case ISD::SRL: Opc = Alpha::SRL; break; | 
|  | 2019 | case ISD::SRA: Opc = Alpha::SRA; break; | 
|  | 2020 | case ISD::MUL: Opc = Alpha::MULQ; break; | 
|  | 2021 | }; | 
|  | 2022 | Tmp1 = SelectExpr(N.getOperand(0)); | 
|  | 2023 | Tmp2 = SelectExpr(N.getOperand(1)); | 
|  | 2024 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2); | 
|  | 2025 | } | 
| Andrew Lenharth | 2d6f022 | 2005-01-24 19:44:07 +0000 | [diff] [blame] | 2026 | return Result; | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2027 |  | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2028 | case ISD::ADD: | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2029 | case ISD::SUB: | 
| Andrew Lenharth | 2f8fb77 | 2005-01-25 00:35:34 +0000 | [diff] [blame] | 2030 | { | 
| Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 2031 | bool isAdd = opcode == ISD::ADD; | 
|  | 2032 |  | 
| Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 2033 | //first check for Scaled Adds and Subs! | 
|  | 2034 | //Valid for add and sub | 
| Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 2035 | ConstantSDNode* CSD = NULL; | 
| Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 2036 | if(N.getOperand(0).getOpcode() == ISD::SHL && | 
| Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 2037 | (CSD = dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) && | 
|  | 2038 | (CSD->getValue() == 2 || CSD->getValue() == 3)) | 
| Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 2039 | { | 
| Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 2040 | bool use4 = CSD->getValue() == 2; | 
| Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 2041 | Tmp2 = SelectExpr(N.getOperand(0).getOperand(0)); | 
| Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 2042 | if ((CSD = dyn_cast<ConstantSDNode>(N.getOperand(1))) && CSD->getValue() <= 255) | 
|  | 2043 | BuildMI(BB, isAdd?(use4?Alpha::S4ADDQi:Alpha::S8ADDQi):(use4?Alpha::S4SUBQi:Alpha::S8SUBQi), | 
|  | 2044 | 2, Result).addReg(Tmp2).addImm(CSD->getValue()); | 
| Andrew Lenharth | f77f395 | 2005-04-06 20:59:59 +0000 | [diff] [blame] | 2045 | else { | 
|  | 2046 | Tmp1 = SelectExpr(N.getOperand(1)); | 
| Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 2047 | BuildMI(BB, isAdd?(use4?Alpha::S4ADDQi:Alpha::S8ADDQi):(use4?Alpha::S4SUBQi:Alpha::S8SUBQi), | 
|  | 2048 | 2, Result).addReg(Tmp2).addReg(Tmp1); | 
| Andrew Lenharth | f77f395 | 2005-04-06 20:59:59 +0000 | [diff] [blame] | 2049 | } | 
| Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 2050 | } | 
|  | 2051 | //Position prevents subs | 
| Andrew Lenharth | 273a1f9 | 2005-04-07 14:18:13 +0000 | [diff] [blame] | 2052 | else if(N.getOperand(1).getOpcode() == ISD::SHL && isAdd && | 
| Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 2053 | (CSD = dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) && | 
|  | 2054 | (CSD->getValue() == 2 || CSD->getValue() == 3)) | 
| Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 2055 | { | 
| Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 2056 | bool use4 = CSD->getValue() == 2; | 
| Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 2057 | Tmp2 = SelectExpr(N.getOperand(1).getOperand(0)); | 
| Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 2058 | if ((CSD = dyn_cast<ConstantSDNode>(N.getOperand(0))) && CSD->getValue() <= 255) | 
|  | 2059 | BuildMI(BB, use4?Alpha::S4ADDQi:Alpha::S8ADDQi, 2, Result).addReg(Tmp2) | 
|  | 2060 | .addImm(CSD->getValue()); | 
| Andrew Lenharth | f77f395 | 2005-04-06 20:59:59 +0000 | [diff] [blame] | 2061 | else { | 
|  | 2062 | Tmp1 = SelectExpr(N.getOperand(0)); | 
| Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 2063 | 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] | 2064 | } | 
| Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 2065 | } | 
|  | 2066 | //small addi | 
| Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 2067 | else if((CSD = dyn_cast<ConstantSDNode>(N.getOperand(1))) && | 
|  | 2068 | CSD->getValue() <= 255) | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 2069 | { //Normal imm add/sub | 
|  | 2070 | Opc = isAdd ? Alpha::ADDQi : Alpha::SUBQi; | 
|  | 2071 | Tmp1 = SelectExpr(N.getOperand(0)); | 
| Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 2072 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(CSD->getValue()); | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 2073 | } | 
| Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 2074 | //larger addi | 
| Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 2075 | else if((CSD = dyn_cast<ConstantSDNode>(N.getOperand(1))) && | 
|  | 2076 | CSD->getSignExtended() <= 32767 && | 
|  | 2077 | CSD->getSignExtended() >= -32767) | 
| Andrew Lenharth | 74d00d8 | 2005-03-02 17:23:03 +0000 | [diff] [blame] | 2078 | { //LDA | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 2079 | Tmp1 = SelectExpr(N.getOperand(0)); | 
| Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 2080 | Tmp2 = (long)CSD->getSignExtended(); | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 2081 | if (!isAdd) | 
|  | 2082 | Tmp2 = -Tmp2; | 
|  | 2083 | BuildMI(BB, Alpha::LDA, 2, Result).addImm(Tmp2).addReg(Tmp1); | 
| Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 2084 | } | 
|  | 2085 | //give up and do the operation | 
|  | 2086 | else { | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 2087 | //Normal add/sub | 
|  | 2088 | Opc = isAdd ? Alpha::ADDQ : Alpha::SUBQ; | 
|  | 2089 | Tmp1 = SelectExpr(N.getOperand(0)); | 
|  | 2090 | Tmp2 = SelectExpr(N.getOperand(1)); | 
|  | 2091 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2); | 
|  | 2092 | } | 
| Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 2093 | return Result; | 
|  | 2094 | } | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2095 |  | 
| Andrew Lenharth | dc0b71b | 2005-03-22 00:24:07 +0000 | [diff] [blame] | 2096 | case ISD::SDIV: | 
| Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 2097 | { | 
| Andrew Lenharth | a565c27 | 2005-04-06 22:03:13 +0000 | [diff] [blame] | 2098 | ConstantSDNode* CSD; | 
|  | 2099 | //check if we can convert into a shift! | 
|  | 2100 | if ((CSD = dyn_cast<ConstantSDNode>(N.getOperand(1).Val)) && | 
|  | 2101 | (int64_t)CSD->getSignExtended() != 0 && | 
|  | 2102 | ExactLog2(abs((int64_t)CSD->getSignExtended())) != 0) | 
|  | 2103 | { | 
|  | 2104 | unsigned k = ExactLog2(abs(CSD->getSignExtended())); | 
|  | 2105 | Tmp1 = SelectExpr(N.getOperand(0)); | 
| Andrew Lenharth | a565c27 | 2005-04-06 22:03:13 +0000 | [diff] [blame] | 2106 | if (k == 1) | 
|  | 2107 | Tmp2 = Tmp1; | 
|  | 2108 | else | 
|  | 2109 | { | 
|  | 2110 | Tmp2 = MakeReg(MVT::i64); | 
|  | 2111 | BuildMI(BB, Alpha::SRAi, 2, Tmp2).addReg(Tmp1).addImm(k - 1); | 
|  | 2112 | } | 
|  | 2113 | Tmp3 = MakeReg(MVT::i64); | 
|  | 2114 | BuildMI(BB, Alpha::SRLi, 2, Tmp3).addReg(Tmp2).addImm(64-k); | 
|  | 2115 | unsigned Tmp4 = MakeReg(MVT::i64); | 
|  | 2116 | BuildMI(BB, Alpha::ADDQ, 2, Tmp4).addReg(Tmp3).addReg(Tmp1); | 
|  | 2117 | if ((int64_t)CSD->getSignExtended() > 0) | 
|  | 2118 | BuildMI(BB, Alpha::SRAi, 2, Result).addReg(Tmp4).addImm(k); | 
|  | 2119 | else | 
|  | 2120 | { | 
|  | 2121 | unsigned Tmp5 = MakeReg(MVT::i64); | 
|  | 2122 | BuildMI(BB, Alpha::SRAi, 2, Tmp5).addReg(Tmp4).addImm(k); | 
|  | 2123 | BuildMI(BB, Alpha::SUBQ, 2, Result).addReg(Alpha::R31).addReg(Tmp5); | 
|  | 2124 | } | 
|  | 2125 | return Result; | 
|  | 2126 | } | 
|  | 2127 | } | 
|  | 2128 | //Else fall through | 
|  | 2129 |  | 
|  | 2130 | case ISD::UDIV: | 
|  | 2131 | { | 
|  | 2132 | ConstantSDNode* CSD; | 
|  | 2133 | if ((CSD = dyn_cast<ConstantSDNode>(N.getOperand(1).Val)) && | 
|  | 2134 | ((int64_t)CSD->getSignExtended() >= 2 || | 
|  | 2135 | (int64_t)CSD->getSignExtended() <= -2)) | 
|  | 2136 | { | 
|  | 2137 | // If this is a divide by constant, we can emit code using some magic | 
|  | 2138 | // constants to implement it as a multiply instead. | 
|  | 2139 | ExprMap.erase(N); | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2140 | if (opcode == ISD::SDIV) | 
| Andrew Lenharth | a565c27 | 2005-04-06 22:03:13 +0000 | [diff] [blame] | 2141 | return SelectExpr(BuildSDIVSequence(N)); | 
|  | 2142 | else | 
|  | 2143 | return SelectExpr(BuildUDIVSequence(N)); | 
|  | 2144 | } | 
| Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 2145 | } | 
|  | 2146 | //else fall though | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2147 | case ISD::UREM: | 
| Andrew Lenharth | 0298118 | 2005-01-26 01:24:38 +0000 | [diff] [blame] | 2148 | case ISD::SREM: | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2149 | //FIXME: alpha really doesn't support any of these operations, | 
| Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 2150 | // the ops are expanded into special library calls with | 
|  | 2151 | // special calling conventions | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 2152 | //Restore GP because it is a call after all... | 
| Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 2153 | switch(opcode) { | 
| Andrew Lenharth | 2b6c4f5 | 2005-02-25 22:55:15 +0000 | [diff] [blame] | 2154 | case ISD::UREM: Opc = Alpha::REMQU; break; | 
|  | 2155 | case ISD::SREM: Opc = Alpha::REMQ; break; | 
|  | 2156 | case ISD::UDIV: Opc = Alpha::DIVQU; break; | 
|  | 2157 | case ISD::SDIV: Opc = Alpha::DIVQ; break; | 
| Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 2158 | } | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2159 | Tmp1 = SelectExpr(N.getOperand(0)); | 
|  | 2160 | Tmp2 = SelectExpr(N.getOperand(1)); | 
| Andrew Lenharth | 3381913 | 2005-03-04 20:09:23 +0000 | [diff] [blame] | 2161 | //set up regs explicitly (helps Reg alloc) | 
|  | 2162 | BuildMI(BB, Alpha::BIS, 2, Alpha::R24).addReg(Tmp1).addReg(Tmp1); | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2163 | BuildMI(BB, Alpha::BIS, 2, Alpha::R25).addReg(Tmp2).addReg(Tmp2); | 
| Andrew Lenharth | 2b6c4f5 | 2005-02-25 22:55:15 +0000 | [diff] [blame] | 2164 | AlphaLowering.restoreGP(BB); | 
| Andrew Lenharth | 3381913 | 2005-03-04 20:09:23 +0000 | [diff] [blame] | 2165 | BuildMI(BB, Opc, 2).addReg(Alpha::R24).addReg(Alpha::R25); | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2166 | BuildMI(BB, Alpha::BIS, 2, Result).addReg(Alpha::R27).addReg(Alpha::R27); | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2167 | return Result; | 
| Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 2168 |  | 
| Andrew Lenharth | e76797c | 2005-02-01 20:40:27 +0000 | [diff] [blame] | 2169 | case ISD::FP_TO_UINT: | 
| Andrew Lenharth | 7efadce | 2005-01-31 01:44:26 +0000 | [diff] [blame] | 2170 | case ISD::FP_TO_SINT: | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 2171 | { | 
| Andrew Lenharth | 7efadce | 2005-01-31 01:44:26 +0000 | [diff] [blame] | 2172 | assert (DestType == MVT::i64 && "only quads can be loaded to"); | 
|  | 2173 | MVT::ValueType SrcType = N.getOperand(0).getValueType(); | 
| Andrew Lenharth | 0382401 | 2005-02-07 05:55:55 +0000 | [diff] [blame] | 2174 | assert (SrcType == MVT::f32 || SrcType == MVT::f64); | 
| Andrew Lenharth | 7efadce | 2005-01-31 01:44:26 +0000 | [diff] [blame] | 2175 | Tmp1 = SelectExpr(N.getOperand(0));  // Get the operand register | 
| Andrew Lenharth | 7efadce | 2005-01-31 01:44:26 +0000 | [diff] [blame] | 2176 | if (SrcType == MVT::f32) | 
| Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 2177 | { | 
|  | 2178 | Tmp2 = MakeReg(MVT::f64); | 
|  | 2179 | BuildMI(BB, Alpha::CVTST, 1, Tmp2).addReg(Tmp1); | 
|  | 2180 | Tmp1 = Tmp2; | 
|  | 2181 | } | 
| Andrew Lenharth | 7efadce | 2005-01-31 01:44:26 +0000 | [diff] [blame] | 2182 | Tmp2 = MakeReg(MVT::f64); | 
|  | 2183 | BuildMI(BB, Alpha::CVTTQ, 1, Tmp2).addReg(Tmp1); | 
| Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 2184 | MoveFP2Int(Tmp2, Result, true); | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2185 |  | 
| Andrew Lenharth | 7efadce | 2005-01-31 01:44:26 +0000 | [diff] [blame] | 2186 | return Result; | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 2187 | } | 
| Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 2188 |  | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2189 | case ISD::SELECT: | 
|  | 2190 | { | 
| Andrew Lenharth | dc0b71b | 2005-03-22 00:24:07 +0000 | [diff] [blame] | 2191 | //FIXME: look at parent to decide if intCC can be folded, or if setCC(FP) and can save stack use | 
| Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 2192 | //Tmp1 = SelectExpr(N.getOperand(0)); //Cond | 
| Andrew Lenharth | 63b720a | 2005-04-03 20:35:21 +0000 | [diff] [blame] | 2193 | //Tmp2 = SelectExpr(N.getOperand(1)); //Use if TRUE | 
|  | 2194 | //Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2195 | // Get the condition into the zero flag. | 
| Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 2196 | //BuildMI(BB, Alpha::CMOVEQ, 2, Result).addReg(Tmp2).addReg(Tmp3).addReg(Tmp1); | 
| Andrew Lenharth | 63b720a | 2005-04-03 20:35:21 +0000 | [diff] [blame] | 2197 |  | 
| Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 2198 | SDOperand CC = N.getOperand(0); | 
|  | 2199 | SetCCSDNode* SetCC = dyn_cast<SetCCSDNode>(CC.Val); | 
|  | 2200 |  | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2201 | if (CC.getOpcode() == ISD::SETCC && | 
| Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 2202 | !MVT::isInteger(SetCC->getOperand(0).getValueType())) | 
|  | 2203 | { //FP Setcc -> Int Select | 
| Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 2204 | Tmp1 = MakeReg(MVT::f64); | 
| Andrew Lenharth | 63b720a | 2005-04-03 20:35:21 +0000 | [diff] [blame] | 2205 | Tmp2 = SelectExpr(N.getOperand(1)); //Use if TRUE | 
|  | 2206 | Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE | 
| Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 2207 | bool inv = SelectFPSetCC(CC, Tmp1); | 
|  | 2208 | BuildMI(BB, inv?Alpha::CMOVNE_FP:Alpha::CMOVEQ_FP, 2, Result) | 
|  | 2209 | .addReg(Tmp2).addReg(Tmp3).addReg(Tmp1); | 
|  | 2210 | return Result; | 
| Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 2211 | } | 
|  | 2212 | if (CC.getOpcode() == ISD::SETCC) { | 
| Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 2213 | //Int SetCC -> Select | 
|  | 2214 | //Dropping the CC is only useful if we are comparing to 0 | 
|  | 2215 | if((SetCC->getOperand(1).getOpcode() == ISD::Constant && | 
|  | 2216 | cast<ConstantSDNode>(SetCC->getOperand(1))->getValue() == 0) || | 
| Andrew Lenharth | 63b720a | 2005-04-03 20:35:21 +0000 | [diff] [blame] | 2217 | (SetCC->getOperand(0).getOpcode() == ISD::Constant && | 
|  | 2218 | cast<ConstantSDNode>(SetCC->getOperand(0))->getValue() == 0)) | 
|  | 2219 | { | 
|  | 2220 | //figure out a few things | 
|  | 2221 | bool LeftZero = SetCC->getOperand(0).getOpcode() == ISD::Constant && | 
|  | 2222 | cast<ConstantSDNode>(SetCC->getOperand(0))->getValue() == 0; | 
|  | 2223 | bool RightZero = SetCC->getOperand(0).getOpcode() == ISD::Constant && | 
|  | 2224 | cast<ConstantSDNode>(SetCC->getOperand(0))->getValue() == 0; | 
|  | 2225 | bool LeftConst = N.getOperand(1).getOpcode() == ISD::Constant && | 
|  | 2226 | cast<ConstantSDNode>(N.getOperand(1))->getValue() <= 255; | 
|  | 2227 | bool RightConst = N.getOperand(2).getOpcode() == ISD::Constant && | 
|  | 2228 | cast<ConstantSDNode>(N.getOperand(2))->getValue() <= 255; | 
|  | 2229 | bool useImm = LeftConst || RightConst; | 
| Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 2230 |  | 
| Andrew Lenharth | 63b720a | 2005-04-03 20:35:21 +0000 | [diff] [blame] | 2231 | //Fix up CC | 
|  | 2232 | ISD::CondCode cCode= SetCC->getCondition(); | 
|  | 2233 | if (RightConst && !LeftConst) //Invert sense to get Imm field right | 
|  | 2234 | cCode = ISD::getSetCCInverse(cCode, true); | 
|  | 2235 | if (LeftZero && !RightZero) //Swap Operands | 
|  | 2236 | cCode = ISD::getSetCCSwappedOperands(cCode); | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2237 |  | 
| Andrew Lenharth | 63b720a | 2005-04-03 20:35:21 +0000 | [diff] [blame] | 2238 | //Choose the CMOV | 
|  | 2239 | switch (cCode) { | 
|  | 2240 | default: CC.Val->dump(); assert(0 && "Unknown integer comparison!"); | 
|  | 2241 | case ISD::SETEQ:  Opc = useImm?Alpha::CMOVEQi:Alpha::CMOVEQ;      break; | 
|  | 2242 | case ISD::SETLT:  Opc = useImm?Alpha::CMOVLTi:Alpha::CMOVLT;      break; | 
|  | 2243 | case ISD::SETLE:  Opc = useImm?Alpha::CMOVLEi:Alpha::CMOVLE;      break; | 
|  | 2244 | case ISD::SETGT:  Opc = useImm?Alpha::CMOVGTi:Alpha::CMOVGT;      break; | 
|  | 2245 | case ISD::SETGE:  Opc = useImm?Alpha::CMOVGEi:Alpha::CMOVGE;      break; | 
|  | 2246 | case ISD::SETULT: assert(0 && "x (unsigned) < 0 is never true");  break; | 
|  | 2247 | case ISD::SETUGT: Opc = useImm?Alpha::CMOVNEi:Alpha::CMOVNE;      break; | 
|  | 2248 | case ISD::SETULE: Opc = useImm?Alpha::CMOVEQi:Alpha::CMOVEQ;      break; //Technically you could have this CC | 
|  | 2249 | case ISD::SETUGE: assert(0 && "x (unsgined >= 0 is always true"); break; | 
|  | 2250 | case ISD::SETNE:  Opc = useImm?Alpha::CMOVNEi:Alpha::CMOVNE;      break; | 
|  | 2251 | } | 
|  | 2252 | if(LeftZero && !RightZero) //swap Operands | 
|  | 2253 | Tmp1 = SelectExpr(SetCC->getOperand(1)); //Cond | 
|  | 2254 | else | 
|  | 2255 | Tmp1 = SelectExpr(SetCC->getOperand(0)); //Cond | 
|  | 2256 |  | 
|  | 2257 | if (LeftConst) { | 
|  | 2258 | Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE | 
|  | 2259 | BuildMI(BB, Opc, 2, Result).addReg(Tmp3) | 
| Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 2260 | .addImm(cast<ConstantSDNode>(N.getOperand(1))->getValue()) | 
| Andrew Lenharth | 63b720a | 2005-04-03 20:35:21 +0000 | [diff] [blame] | 2261 | .addReg(Tmp1); | 
|  | 2262 | } else if (RightConst) { | 
|  | 2263 | Tmp3 = SelectExpr(N.getOperand(1)); //Use if FALSE | 
|  | 2264 | BuildMI(BB, Opc, 2, Result).addReg(Tmp3) | 
| Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 2265 | .addImm(cast<ConstantSDNode>(N.getOperand(2))->getValue()) | 
| Andrew Lenharth | 63b720a | 2005-04-03 20:35:21 +0000 | [diff] [blame] | 2266 | .addReg(Tmp1); | 
|  | 2267 | } else { | 
|  | 2268 | Tmp2 = SelectExpr(N.getOperand(1)); //Use if TRUE | 
|  | 2269 | Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE | 
|  | 2270 | BuildMI(BB, Opc, 2, Result).addReg(Tmp3).addReg(Tmp2).addReg(Tmp1); | 
|  | 2271 | } | 
|  | 2272 | return Result; | 
|  | 2273 | } | 
| Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 2274 | //Otherwise, fall though | 
| Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 2275 | } | 
|  | 2276 | Tmp1 = SelectExpr(N.getOperand(0)); //Cond | 
| Andrew Lenharth | 63b720a | 2005-04-03 20:35:21 +0000 | [diff] [blame] | 2277 | Tmp2 = SelectExpr(N.getOperand(1)); //Use if TRUE | 
|  | 2278 | Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE | 
| Andrew Lenharth | e76797c | 2005-02-01 20:40:27 +0000 | [diff] [blame] | 2279 | BuildMI(BB, Alpha::CMOVEQ, 2, Result).addReg(Tmp2).addReg(Tmp3).addReg(Tmp1); | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2280 |  | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2281 | return Result; | 
|  | 2282 | } | 
|  | 2283 |  | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2284 | case ISD::Constant: | 
|  | 2285 | { | 
| Andrew Lenharth | c051383 | 2005-03-29 19:24:04 +0000 | [diff] [blame] | 2286 | int64_t val = (int64_t)cast<ConstantSDNode>(N)->getValue(); | 
| Andrew Lenharth | e87f6c3 | 2005-03-11 17:48:05 +0000 | [diff] [blame] | 2287 | if (val <= IMM_HIGH && val >= IMM_LOW) { | 
| Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 2288 | BuildMI(BB, Alpha::LDA, 2, Result).addImm(val).addReg(Alpha::R31); | 
| Andrew Lenharth | e87f6c3 | 2005-03-11 17:48:05 +0000 | [diff] [blame] | 2289 | } | 
| Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 2290 | else if (val <= (int64_t)IMM_HIGH +(int64_t)IMM_HIGH* (int64_t)IMM_MULT && | 
|  | 2291 | val >= (int64_t)IMM_LOW + (int64_t)IMM_LOW * (int64_t)IMM_MULT) { | 
|  | 2292 | Tmp1 = MakeReg(MVT::i64); | 
|  | 2293 | BuildMI(BB, Alpha::LDAH, 2, Tmp1).addImm(getUpper16(val)).addReg(Alpha::R31); | 
|  | 2294 | BuildMI(BB, Alpha::LDA, 2, Result).addImm(getLower16(val)).addReg(Tmp1); | 
| Andrew Lenharth | e87f6c3 | 2005-03-11 17:48:05 +0000 | [diff] [blame] | 2295 | } | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 2296 | else { | 
|  | 2297 | MachineConstantPool *CP = BB->getParent()->getConstantPool(); | 
|  | 2298 | ConstantUInt *C = ConstantUInt::get(Type::getPrimitiveType(Type::ULongTyID) , val); | 
|  | 2299 | unsigned CPI = CP->getConstantPoolIndex(C); | 
|  | 2300 | AlphaLowering.restoreGP(BB); | 
|  | 2301 | BuildMI(BB, Alpha::LDQ_SYM, 1, Result).addConstantPoolIndex(CPI); | 
|  | 2302 | } | 
|  | 2303 | return Result; | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2304 | } | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2305 | } | 
|  | 2306 |  | 
|  | 2307 | return 0; | 
|  | 2308 | } | 
|  | 2309 |  | 
| Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 2310 | void AlphaISel::Select(SDOperand N) { | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2311 | unsigned Tmp1, Tmp2, Opc; | 
| Andrew Lenharth | 760270d | 2005-02-07 23:02:23 +0000 | [diff] [blame] | 2312 | unsigned opcode = N.getOpcode(); | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2313 |  | 
| Nate Begeman | 85fdeb2 | 2005-03-24 04:39:54 +0000 | [diff] [blame] | 2314 | if (!ExprMap.insert(std::make_pair(N, notIn)).second) | 
| Andrew Lenharth | 6b9870a | 2005-01-28 14:06:46 +0000 | [diff] [blame] | 2315 | return;  // Already selected. | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2316 |  | 
|  | 2317 | SDNode *Node = N.Val; | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2318 |  | 
| Andrew Lenharth | 760270d | 2005-02-07 23:02:23 +0000 | [diff] [blame] | 2319 | switch (opcode) { | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2320 |  | 
|  | 2321 | default: | 
|  | 2322 | Node->dump(); std::cerr << "\n"; | 
|  | 2323 | assert(0 && "Node not handled yet!"); | 
|  | 2324 |  | 
|  | 2325 | case ISD::BRCOND: { | 
| Andrew Lenharth | 445171a | 2005-02-08 00:40:03 +0000 | [diff] [blame] | 2326 | SelectBranchCC(N); | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2327 | return; | 
|  | 2328 | } | 
|  | 2329 |  | 
|  | 2330 | case ISD::BR: { | 
|  | 2331 | MachineBasicBlock *Dest = | 
|  | 2332 | cast<BasicBlockSDNode>(N.getOperand(1))->getBasicBlock(); | 
|  | 2333 |  | 
|  | 2334 | Select(N.getOperand(0)); | 
|  | 2335 | BuildMI(BB, Alpha::BR, 1, Alpha::R31).addMBB(Dest); | 
|  | 2336 | return; | 
|  | 2337 | } | 
|  | 2338 |  | 
|  | 2339 | case ISD::ImplicitDef: | 
| Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 2340 | ++count_ins; | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2341 | Select(N.getOperand(0)); | 
|  | 2342 | BuildMI(BB, Alpha::IDEF, 0, cast<RegSDNode>(N)->getReg()); | 
|  | 2343 | return; | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2344 |  | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2345 | case ISD::EntryToken: return;  // Noop | 
|  | 2346 |  | 
|  | 2347 | case ISD::TokenFactor: | 
|  | 2348 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) | 
|  | 2349 | Select(Node->getOperand(i)); | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2350 |  | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2351 | //N.Val->dump(); std::cerr << "\n"; | 
|  | 2352 | //assert(0 && "Node not handled yet!"); | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2353 |  | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2354 | return; | 
|  | 2355 |  | 
|  | 2356 | case ISD::CopyToReg: | 
| Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 2357 | ++count_outs; | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2358 | Select(N.getOperand(0)); | 
|  | 2359 | Tmp1 = SelectExpr(N.getOperand(1)); | 
|  | 2360 | Tmp2 = cast<RegSDNode>(N)->getReg(); | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2361 |  | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2362 | if (Tmp1 != Tmp2) { | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2363 | if (N.getOperand(1).getValueType() == MVT::f64 || | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 2364 | N.getOperand(1).getValueType() == MVT::f32) | 
| Andrew Lenharth | 2921916 | 2005-02-07 06:31:44 +0000 | [diff] [blame] | 2365 | BuildMI(BB, Alpha::CPYS, 2, Tmp2).addReg(Tmp1).addReg(Tmp1); | 
|  | 2366 | else | 
|  | 2367 | BuildMI(BB, Alpha::BIS, 2, Tmp2).addReg(Tmp1).addReg(Tmp1); | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2368 | } | 
|  | 2369 | return; | 
|  | 2370 |  | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 2371 | case ISD::RET: | 
| Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 2372 | ++count_outs; | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 2373 | switch (N.getNumOperands()) { | 
|  | 2374 | default: | 
|  | 2375 | std::cerr << N.getNumOperands() << "\n"; | 
|  | 2376 | for (unsigned i = 0; i < N.getNumOperands(); ++i) | 
|  | 2377 | std::cerr << N.getOperand(i).getValueType() << "\n"; | 
|  | 2378 | Node->dump(); | 
|  | 2379 | assert(0 && "Unknown return instruction!"); | 
|  | 2380 | case 2: | 
|  | 2381 | Select(N.getOperand(0)); | 
|  | 2382 | Tmp1 = SelectExpr(N.getOperand(1)); | 
|  | 2383 | switch (N.getOperand(1).getValueType()) { | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2384 | default: Node->dump(); | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 2385 | assert(0 && "All other types should have been promoted!!"); | 
|  | 2386 | case MVT::f64: | 
|  | 2387 | case MVT::f32: | 
|  | 2388 | BuildMI(BB, Alpha::CPYS, 2, Alpha::F0).addReg(Tmp1).addReg(Tmp1); | 
|  | 2389 | break; | 
|  | 2390 | case MVT::i32: | 
|  | 2391 | case MVT::i64: | 
|  | 2392 | BuildMI(BB, Alpha::BIS, 2, Alpha::R0).addReg(Tmp1).addReg(Tmp1); | 
|  | 2393 | break; | 
|  | 2394 | } | 
|  | 2395 | break; | 
|  | 2396 | case 1: | 
|  | 2397 | Select(N.getOperand(0)); | 
|  | 2398 | break; | 
|  | 2399 | } | 
| Andrew Lenharth | 3f5aa1c | 2005-06-23 23:42:05 +0000 | [diff] [blame] | 2400 | AlphaLowering.restoreRA(BB); | 
|  | 2401 | BuildMI(BB, Alpha::RET, 1, Alpha::R31).addReg(Alpha::R26); // Just emit a 'ret' instruction | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 2402 | return; | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2403 |  | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2404 | case ISD::TRUNCSTORE: | 
|  | 2405 | case ISD::STORE: | 
| Andrew Lenharth | b014d3e | 2005-02-02 17:32:39 +0000 | [diff] [blame] | 2406 | { | 
| Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 2407 | SDOperand Chain   = N.getOperand(0); | 
|  | 2408 | SDOperand Value = N.getOperand(1); | 
|  | 2409 | SDOperand Address = N.getOperand(2); | 
|  | 2410 | Select(Chain); | 
|  | 2411 |  | 
|  | 2412 | Tmp1 = SelectExpr(Value); //value | 
| Andrew Lenharth | 760270d | 2005-02-07 23:02:23 +0000 | [diff] [blame] | 2413 |  | 
|  | 2414 | if (opcode == ISD::STORE) { | 
|  | 2415 | switch(Value.getValueType()) { | 
|  | 2416 | default: assert(0 && "unknown Type in store"); | 
|  | 2417 | case MVT::i64: Opc = Alpha::STQ; break; | 
|  | 2418 | case MVT::f64: Opc = Alpha::STT; break; | 
|  | 2419 | case MVT::f32: Opc = Alpha::STS; break; | 
|  | 2420 | } | 
|  | 2421 | } else { //ISD::TRUNCSTORE | 
|  | 2422 | switch(cast<MVTSDNode>(Node)->getExtraValueType()) { | 
|  | 2423 | default: assert(0 && "unknown Type in store"); | 
|  | 2424 | case MVT::i1: //FIXME: DAG does not promote this load | 
|  | 2425 | case MVT::i8: Opc = Alpha::STB; break; | 
|  | 2426 | case MVT::i16: Opc = Alpha::STW; break; | 
|  | 2427 | case MVT::i32: Opc = Alpha::STL; break; | 
|  | 2428 | } | 
| Andrew Lenharth | 6583890 | 2005-02-06 16:22:15 +0000 | [diff] [blame] | 2429 | } | 
| Andrew Lenharth | 760270d | 2005-02-07 23:02:23 +0000 | [diff] [blame] | 2430 |  | 
| Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 2431 | if (EnableAlphaLSMark) | 
|  | 2432 | { | 
|  | 2433 | int i = getValueOffset(dyn_cast<SrcValueSDNode>(N.getOperand(3))->getValue()); | 
|  | 2434 | int j = getFunctionOffset(BB->getParent()->getFunction()); | 
|  | 2435 | BuildMI(BB, Alpha::MEMLABEL, 3).addImm(j).addImm(i).addImm(getUID()); | 
|  | 2436 | } | 
|  | 2437 |  | 
| Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 2438 | if (Address.getOpcode() == ISD::GlobalAddress) | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 2439 | { | 
|  | 2440 | AlphaLowering.restoreGP(BB); | 
|  | 2441 | Opc = GetSymVersion(Opc); | 
| Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 2442 | has_sym = true; | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 2443 | BuildMI(BB, Opc, 2).addReg(Tmp1).addGlobalAddress(cast<GlobalAddressSDNode>(Address)->getGlobal()); | 
|  | 2444 | } | 
| Andrew Lenharth | 0538034 | 2005-02-07 05:07:00 +0000 | [diff] [blame] | 2445 | else if(Address.getOpcode() == ISD::FrameIndex) | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 2446 | { | 
| Andrew Lenharth | 032f235 | 2005-02-22 21:59:48 +0000 | [diff] [blame] | 2447 | BuildMI(BB, Opc, 3).addReg(Tmp1) | 
|  | 2448 | .addFrameIndex(cast<FrameIndexSDNode>(Address)->getIndex()) | 
|  | 2449 | .addReg(Alpha::F31); | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 2450 | } | 
| Andrew Lenharth | b014d3e | 2005-02-02 17:32:39 +0000 | [diff] [blame] | 2451 | else | 
| Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 2452 | { | 
|  | 2453 | long offset; | 
|  | 2454 | SelectAddr(Address, Tmp2, offset); | 
|  | 2455 | BuildMI(BB, Opc, 3).addReg(Tmp1).addImm(offset).addReg(Tmp2); | 
|  | 2456 | } | 
| Andrew Lenharth | b014d3e | 2005-02-02 17:32:39 +0000 | [diff] [blame] | 2457 | return; | 
|  | 2458 | } | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2459 |  | 
|  | 2460 | case ISD::EXTLOAD: | 
|  | 2461 | case ISD::SEXTLOAD: | 
|  | 2462 | case ISD::ZEXTLOAD: | 
|  | 2463 | case ISD::LOAD: | 
|  | 2464 | case ISD::CopyFromReg: | 
| Chris Lattner | b5d8e6e | 2005-05-13 20:29:26 +0000 | [diff] [blame] | 2465 | case ISD::TAILCALL: | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2466 | case ISD::CALL: | 
| Andrew Lenharth | 032f235 | 2005-02-22 21:59:48 +0000 | [diff] [blame] | 2467 | case ISD::DYNAMIC_STACKALLOC: | 
| Andrew Lenharth | 6b9870a | 2005-01-28 14:06:46 +0000 | [diff] [blame] | 2468 | ExprMap.erase(N); | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2469 | SelectExpr(N); | 
|  | 2470 | return; | 
|  | 2471 |  | 
| Chris Lattner | 16cd04d | 2005-05-12 23:24:06 +0000 | [diff] [blame] | 2472 | case ISD::CALLSEQ_START: | 
|  | 2473 | case ISD::CALLSEQ_END: | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2474 | Select(N.getOperand(0)); | 
|  | 2475 | Tmp1 = cast<ConstantSDNode>(N.getOperand(1))->getValue(); | 
| Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2476 |  | 
| Chris Lattner | 16cd04d | 2005-05-12 23:24:06 +0000 | [diff] [blame] | 2477 | Opc = N.getOpcode() == ISD::CALLSEQ_START ? Alpha::ADJUSTSTACKDOWN : | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2478 | Alpha::ADJUSTSTACKUP; | 
|  | 2479 | BuildMI(BB, Opc, 1).addImm(Tmp1); | 
|  | 2480 | return; | 
| Andrew Lenharth | 9576212 | 2005-03-31 21:24:06 +0000 | [diff] [blame] | 2481 |  | 
|  | 2482 | case ISD::PCMARKER: | 
|  | 2483 | Select(N.getOperand(0)); //Chain | 
|  | 2484 | BuildMI(BB, Alpha::PCLABEL, 2).addImm( cast<ConstantSDNode>(N.getOperand(1))->getValue()); | 
|  | 2485 | return; | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2486 | } | 
|  | 2487 | assert(0 && "Should not be reached!"); | 
|  | 2488 | } | 
|  | 2489 |  | 
|  | 2490 |  | 
|  | 2491 | /// createAlphaPatternInstructionSelector - This pass converts an LLVM function | 
|  | 2492 | /// into a machine code representation using pattern matching and a machine | 
|  | 2493 | /// description file. | 
|  | 2494 | /// | 
|  | 2495 | FunctionPass *llvm::createAlphaPatternInstructionSelector(TargetMachine &TM) { | 
| Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 2496 | return new AlphaISel(TM); | 
| Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2497 | } | 
| Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 2498 |  |