Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1 | //===-- IA64ISelPattern.cpp - A pattern matching inst selector for IA64 ---===// |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2 | // |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by Duraid Madina and is distributed under the |
| 6 | // University of Illinois Open Source License. See LICENSE.TXT for details. |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 7 | // |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines a pattern matching instruction selector for IA64. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "IA64.h" |
| 15 | #include "IA64InstrBuilder.h" |
| 16 | #include "IA64RegisterInfo.h" |
| 17 | #include "IA64MachineFunctionInfo.h" |
| 18 | #include "llvm/Constants.h" // FIXME: REMOVE |
| 19 | #include "llvm/Function.h" |
| 20 | #include "llvm/CodeGen/MachineConstantPool.h" // FIXME: REMOVE |
| 21 | #include "llvm/CodeGen/MachineFunction.h" |
| 22 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 23 | #include "llvm/CodeGen/SelectionDAG.h" |
| 24 | #include "llvm/CodeGen/SelectionDAGISel.h" |
| 25 | #include "llvm/CodeGen/SSARegMap.h" |
| 26 | #include "llvm/Target/TargetData.h" |
| 27 | #include "llvm/Target/TargetLowering.h" |
| 28 | #include "llvm/Support/MathExtras.h" |
| 29 | #include "llvm/ADT/Statistic.h" |
| 30 | #include <set> |
Duraid Madina | b232256 | 2005-04-26 07:23:02 +0000 | [diff] [blame] | 31 | #include <map> |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 32 | #include <algorithm> |
| 33 | using namespace llvm; |
| 34 | |
| 35 | //===----------------------------------------------------------------------===// |
| 36 | // IA64TargetLowering - IA64 Implementation of the TargetLowering interface |
| 37 | namespace { |
| 38 | class IA64TargetLowering : public TargetLowering { |
| 39 | int VarArgsFrameIndex; // FrameIndex for start of varargs area. |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 40 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 41 | //int ReturnAddrIndex; // FrameIndex for return slot. |
| 42 | unsigned GP, SP, RP; // FIXME - clean this mess up |
| 43 | public: |
| 44 | |
| 45 | unsigned VirtGPR; // this is public so it can be accessed in the selector |
| 46 | // for ISD::RET down below. add an accessor instead? FIXME |
| 47 | |
| 48 | IA64TargetLowering(TargetMachine &TM) : TargetLowering(TM) { |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 49 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 50 | // register class for general registers |
| 51 | addRegisterClass(MVT::i64, IA64::GRRegisterClass); |
| 52 | |
| 53 | // register class for FP registers |
| 54 | addRegisterClass(MVT::f64, IA64::FPRegisterClass); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 55 | |
| 56 | // register class for predicate registers |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 57 | addRegisterClass(MVT::i1, IA64::PRRegisterClass); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 58 | |
Chris Lattner | da4d469 | 2005-04-09 03:22:37 +0000 | [diff] [blame] | 59 | setOperationAction(ISD::BRCONDTWOWAY , MVT::Other, Expand); |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 60 | setOperationAction(ISD::BRTWOWAY_CC , MVT::Other, Expand); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 61 | setOperationAction(ISD::FP_ROUND_INREG , MVT::f32 , Expand); |
| 62 | |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 63 | setSetCCResultType(MVT::i1); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 64 | setShiftAmountType(MVT::i64); |
| 65 | |
| 66 | setOperationAction(ISD::EXTLOAD , MVT::i1 , Promote); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 67 | |
| 68 | setOperationAction(ISD::ZEXTLOAD , MVT::i1 , Expand); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 69 | |
| 70 | setOperationAction(ISD::SEXTLOAD , MVT::i1 , Expand); |
| 71 | setOperationAction(ISD::SEXTLOAD , MVT::i8 , Expand); |
| 72 | setOperationAction(ISD::SEXTLOAD , MVT::i16 , Expand); |
Duraid Madina | c4ccc2d | 2005-04-14 08:37:32 +0000 | [diff] [blame] | 73 | setOperationAction(ISD::SEXTLOAD , MVT::i32 , Expand); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 74 | |
Chris Lattner | 3e2bafd | 2005-09-28 22:29:17 +0000 | [diff] [blame] | 75 | setOperationAction(ISD::FREM , MVT::f32 , Expand); |
| 76 | setOperationAction(ISD::FREM , MVT::f64 , Expand); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 77 | |
| 78 | setOperationAction(ISD::UREM , MVT::f32 , Expand); |
| 79 | setOperationAction(ISD::UREM , MVT::f64 , Expand); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 80 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 81 | setOperationAction(ISD::MEMMOVE , MVT::Other, Expand); |
| 82 | setOperationAction(ISD::MEMSET , MVT::Other, Expand); |
| 83 | setOperationAction(ISD::MEMCPY , MVT::Other, Expand); |
Chris Lattner | 7a7c979 | 2005-10-07 04:50:48 +0000 | [diff] [blame] | 84 | |
| 85 | setOperationAction(ISD::SINT_TO_FP , MVT::i1 , Promote); |
| 86 | setOperationAction(ISD::UINT_TO_FP , MVT::i1 , Promote); |
Nate Begeman | d5ce204 | 2005-10-21 01:52:45 +0000 | [diff] [blame] | 87 | |
Chris Lattner | 17234b7 | 2005-04-30 04:26:06 +0000 | [diff] [blame] | 88 | // We don't support sin/cos/sqrt |
| 89 | setOperationAction(ISD::FSIN , MVT::f64, Expand); |
| 90 | setOperationAction(ISD::FCOS , MVT::f64, Expand); |
| 91 | setOperationAction(ISD::FSQRT, MVT::f64, Expand); |
| 92 | setOperationAction(ISD::FSIN , MVT::f32, Expand); |
| 93 | setOperationAction(ISD::FCOS , MVT::f32, Expand); |
| 94 | setOperationAction(ISD::FSQRT, MVT::f32, Expand); |
| 95 | |
Andrew Lenharth | b5884d3 | 2005-05-04 19:25:37 +0000 | [diff] [blame] | 96 | //IA64 has these, but they are not implemented |
Chris Lattner | 1f38e5c | 2005-05-11 05:03:56 +0000 | [diff] [blame] | 97 | setOperationAction(ISD::CTTZ , MVT::i64 , Expand); |
| 98 | setOperationAction(ISD::CTLZ , MVT::i64 , Expand); |
Nate Begeman | d5ce204 | 2005-10-21 01:52:45 +0000 | [diff] [blame] | 99 | // FIXME: implement mulhs (xma.h) and mulhu (xma.hu) |
| 100 | setOperationAction(ISD::MULHS , MVT::i64 , Expand); |
| 101 | setOperationAction(ISD::MULHU , MVT::i64 , Expand); |
Andrew Lenharth | b5884d3 | 2005-05-04 19:25:37 +0000 | [diff] [blame] | 102 | |
Chris Lattner | 18c778f | 2005-12-01 18:19:53 +0000 | [diff] [blame] | 103 | // We don't have line number support yet. |
| 104 | setOperationAction(ISD::LOCATION, MVT::Other, Expand); |
| 105 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 106 | computeRegisterProperties(); |
| 107 | |
| 108 | addLegalFPImmediate(+0.0); |
| 109 | addLegalFPImmediate(+1.0); |
| 110 | addLegalFPImmediate(-0.0); |
| 111 | addLegalFPImmediate(-1.0); |
| 112 | } |
| 113 | |
| 114 | /// LowerArguments - This hook must be implemented to indicate how we should |
| 115 | /// lower the arguments for the specified function, into the specified DAG. |
| 116 | virtual std::vector<SDOperand> |
| 117 | LowerArguments(Function &F, SelectionDAG &DAG); |
| 118 | |
| 119 | /// LowerCallTo - This hook lowers an abstract call to a function into an |
| 120 | /// actual call. |
| 121 | virtual std::pair<SDOperand, SDOperand> |
Chris Lattner | c57f682 | 2005-05-12 19:56:45 +0000 | [diff] [blame] | 122 | LowerCallTo(SDOperand Chain, const Type *RetTy, bool isVarArg, unsigned CC, |
Chris Lattner | adf6a96 | 2005-05-13 18:50:42 +0000 | [diff] [blame] | 123 | bool isTailCall, SDOperand Callee, ArgListTy &Args, |
| 124 | SelectionDAG &DAG); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 125 | |
Chris Lattner | e0fe225 | 2005-07-05 19:58:54 +0000 | [diff] [blame] | 126 | virtual SDOperand LowerVAStart(SDOperand Chain, SDOperand VAListP, |
| 127 | Value *VAListV, SelectionDAG &DAG); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 128 | virtual std::pair<SDOperand,SDOperand> |
Chris Lattner | e0fe225 | 2005-07-05 19:58:54 +0000 | [diff] [blame] | 129 | LowerVAArg(SDOperand Chain, SDOperand VAListP, Value *VAListV, |
| 130 | const Type *ArgTy, SelectionDAG &DAG); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 131 | |
| 132 | void restoreGP_SP_RP(MachineBasicBlock* BB) |
| 133 | { |
| 134 | BuildMI(BB, IA64::MOV, 1, IA64::r1).addReg(GP); |
| 135 | BuildMI(BB, IA64::MOV, 1, IA64::r12).addReg(SP); |
| 136 | BuildMI(BB, IA64::MOV, 1, IA64::rp).addReg(RP); |
| 137 | } |
| 138 | |
Duraid Madina | beeaab2 | 2005-03-31 12:31:11 +0000 | [diff] [blame] | 139 | void restoreSP_RP(MachineBasicBlock* BB) |
| 140 | { |
| 141 | BuildMI(BB, IA64::MOV, 1, IA64::r12).addReg(SP); |
| 142 | BuildMI(BB, IA64::MOV, 1, IA64::rp).addReg(RP); |
| 143 | } |
| 144 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 145 | void restoreRP(MachineBasicBlock* BB) |
| 146 | { |
| 147 | BuildMI(BB, IA64::MOV, 1, IA64::rp).addReg(RP); |
| 148 | } |
| 149 | |
| 150 | void restoreGP(MachineBasicBlock* BB) |
| 151 | { |
| 152 | BuildMI(BB, IA64::MOV, 1, IA64::r1).addReg(GP); |
| 153 | } |
| 154 | |
| 155 | }; |
| 156 | } |
| 157 | |
| 158 | |
| 159 | std::vector<SDOperand> |
| 160 | IA64TargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) { |
| 161 | std::vector<SDOperand> ArgValues; |
| 162 | |
| 163 | // |
| 164 | // add beautiful description of IA64 stack frame format |
| 165 | // here (from intel 24535803.pdf most likely) |
| 166 | // |
| 167 | MachineFunction &MF = DAG.getMachineFunction(); |
| 168 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 169 | |
| 170 | GP = MF.getSSARegMap()->createVirtualRegister(getRegClassFor(MVT::i64)); |
| 171 | SP = MF.getSSARegMap()->createVirtualRegister(getRegClassFor(MVT::i64)); |
| 172 | RP = MF.getSSARegMap()->createVirtualRegister(getRegClassFor(MVT::i64)); |
| 173 | |
| 174 | MachineBasicBlock& BB = MF.front(); |
| 175 | |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 176 | unsigned args_int[] = {IA64::r32, IA64::r33, IA64::r34, IA64::r35, |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 177 | IA64::r36, IA64::r37, IA64::r38, IA64::r39}; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 178 | |
| 179 | unsigned args_FP[] = {IA64::F8, IA64::F9, IA64::F10, IA64::F11, |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 180 | IA64::F12,IA64::F13,IA64::F14, IA64::F15}; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 181 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 182 | unsigned argVreg[8]; |
| 183 | unsigned argPreg[8]; |
| 184 | unsigned argOpc[8]; |
| 185 | |
Duraid Madina | beeaab2 | 2005-03-31 12:31:11 +0000 | [diff] [blame] | 186 | unsigned used_FPArgs = 0; // how many FP args have been used so far? |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 187 | |
Duraid Madina | beeaab2 | 2005-03-31 12:31:11 +0000 | [diff] [blame] | 188 | unsigned ArgOffset = 0; |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 189 | int count = 0; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 190 | |
Alkis Evlogimenos | 12cf385 | 2005-03-19 09:22:17 +0000 | [diff] [blame] | 191 | for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; ++I) |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 192 | { |
| 193 | SDOperand newroot, argt; |
| 194 | if(count < 8) { // need to fix this logic? maybe. |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 195 | |
| 196 | switch (getValueType(I->getType())) { |
| 197 | default: |
| 198 | std::cerr << "ERROR in LowerArgs: unknown type " |
| 199 | << getValueType(I->getType()) << "\n"; |
| 200 | abort(); |
| 201 | case MVT::f32: |
| 202 | // fixme? (well, will need to for weird FP structy stuff, |
| 203 | // see intel ABI docs) |
| 204 | case MVT::f64: |
| 205 | //XXX BuildMI(&BB, IA64::IDEF, 0, args_FP[used_FPArgs]); |
| 206 | MF.addLiveIn(args_FP[used_FPArgs]); // mark this reg as liveIn |
| 207 | // floating point args go into f8..f15 as-needed, the increment |
| 208 | argVreg[count] = // is below..: |
| 209 | MF.getSSARegMap()->createVirtualRegister(getRegClassFor(MVT::f64)); |
| 210 | // FP args go into f8..f15 as needed: (hence the ++) |
| 211 | argPreg[count] = args_FP[used_FPArgs++]; |
| 212 | argOpc[count] = IA64::FMOV; |
Chris Lattner | 707ebc5 | 2005-08-16 21:56:37 +0000 | [diff] [blame] | 213 | argt = newroot = DAG.getCopyFromReg(DAG.getRoot(), argVreg[count], |
Chris Lattner | 0a00bec | 2005-08-22 21:33:11 +0000 | [diff] [blame] | 214 | MVT::f64); |
| 215 | if (I->getType() == Type::FloatTy) |
| 216 | argt = DAG.getNode(ISD::FP_ROUND, MVT::f32, argt); |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 217 | break; |
| 218 | case MVT::i1: // NOTE: as far as C abi stuff goes, |
| 219 | // bools are just boring old ints |
| 220 | case MVT::i8: |
| 221 | case MVT::i16: |
| 222 | case MVT::i32: |
| 223 | case MVT::i64: |
| 224 | //XXX BuildMI(&BB, IA64::IDEF, 0, args_int[count]); |
| 225 | MF.addLiveIn(args_int[count]); // mark this register as liveIn |
| 226 | argVreg[count] = |
| 227 | MF.getSSARegMap()->createVirtualRegister(getRegClassFor(MVT::i64)); |
| 228 | argPreg[count] = args_int[count]; |
| 229 | argOpc[count] = IA64::MOV; |
| 230 | argt = newroot = |
Chris Lattner | 707ebc5 | 2005-08-16 21:56:37 +0000 | [diff] [blame] | 231 | DAG.getCopyFromReg(DAG.getRoot(), argVreg[count], MVT::i64); |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 232 | if ( getValueType(I->getType()) != MVT::i64) |
| 233 | argt = DAG.getNode(ISD::TRUNCATE, getValueType(I->getType()), |
| 234 | newroot); |
| 235 | break; |
| 236 | } |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 237 | } else { // more than 8 args go into the frame |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 238 | // Create the frame index object for this incoming parameter... |
| 239 | ArgOffset = 16 + 8 * (count - 8); |
| 240 | int FI = MFI->CreateFixedObject(8, ArgOffset); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 241 | |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 242 | // Create the SelectionDAG nodes corresponding to a load |
| 243 | //from this parameter |
| 244 | SDOperand FIN = DAG.getFrameIndex(FI, MVT::i64); |
| 245 | argt = newroot = DAG.getLoad(getValueType(I->getType()), |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 246 | DAG.getEntryNode(), FIN, DAG.getSrcValue(NULL)); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 247 | } |
| 248 | ++count; |
| 249 | DAG.setRoot(newroot.getValue(1)); |
| 250 | ArgValues.push_back(argt); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 251 | } |
Duraid Madina | beeaab2 | 2005-03-31 12:31:11 +0000 | [diff] [blame] | 252 | |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 253 | |
Duraid Madina | beeaab2 | 2005-03-31 12:31:11 +0000 | [diff] [blame] | 254 | // Create a vreg to hold the output of (what will become) |
| 255 | // the "alloc" instruction |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 256 | VirtGPR = MF.getSSARegMap()->createVirtualRegister(getRegClassFor(MVT::i64)); |
| 257 | BuildMI(&BB, IA64::PSEUDO_ALLOC, 0, VirtGPR); |
| 258 | // we create a PSEUDO_ALLOC (pseudo)instruction for now |
| 259 | |
| 260 | BuildMI(&BB, IA64::IDEF, 0, IA64::r1); |
| 261 | |
| 262 | // hmm: |
| 263 | BuildMI(&BB, IA64::IDEF, 0, IA64::r12); |
| 264 | BuildMI(&BB, IA64::IDEF, 0, IA64::rp); |
| 265 | // ..hmm. |
| 266 | |
| 267 | BuildMI(&BB, IA64::MOV, 1, GP).addReg(IA64::r1); |
| 268 | |
| 269 | // hmm: |
| 270 | BuildMI(&BB, IA64::MOV, 1, SP).addReg(IA64::r12); |
| 271 | BuildMI(&BB, IA64::MOV, 1, RP).addReg(IA64::rp); |
| 272 | // ..hmm. |
| 273 | |
Duraid Madina | beeaab2 | 2005-03-31 12:31:11 +0000 | [diff] [blame] | 274 | unsigned tempOffset=0; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 275 | |
Duraid Madina | beeaab2 | 2005-03-31 12:31:11 +0000 | [diff] [blame] | 276 | // if this is a varargs function, we simply lower llvm.va_start by |
| 277 | // pointing to the first entry |
| 278 | if(F.isVarArg()) { |
| 279 | tempOffset=0; |
| 280 | VarArgsFrameIndex = MFI->CreateFixedObject(8, tempOffset); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 281 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 282 | |
Duraid Madina | beeaab2 | 2005-03-31 12:31:11 +0000 | [diff] [blame] | 283 | // here we actually do the moving of args, and store them to the stack |
| 284 | // too if this is a varargs function: |
| 285 | for (int i = 0; i < count && i < 8; ++i) { |
| 286 | BuildMI(&BB, argOpc[i], 1, argVreg[i]).addReg(argPreg[i]); |
| 287 | if(F.isVarArg()) { |
| 288 | // if this is a varargs function, we copy the input registers to the stack |
| 289 | int FI = MFI->CreateFixedObject(8, tempOffset); |
| 290 | tempOffset+=8; //XXX: is it safe to use r22 like this? |
| 291 | BuildMI(&BB, IA64::MOV, 1, IA64::r22).addFrameIndex(FI); |
| 292 | // FIXME: we should use st8.spill here, one day |
| 293 | BuildMI(&BB, IA64::ST8, 1, IA64::r22).addReg(argPreg[i]); |
| 294 | } |
| 295 | } |
| 296 | |
Duraid Madina | ca494fd | 2005-04-12 14:54:44 +0000 | [diff] [blame] | 297 | // Finally, inform the code generator which regs we return values in. |
| 298 | // (see the ISD::RET: case down below) |
| 299 | switch (getValueType(F.getReturnType())) { |
| 300 | default: assert(0 && "i have no idea where to return this type!"); |
| 301 | case MVT::isVoid: break; |
| 302 | case MVT::i1: |
| 303 | case MVT::i8: |
| 304 | case MVT::i16: |
| 305 | case MVT::i32: |
| 306 | case MVT::i64: |
| 307 | MF.addLiveOut(IA64::r8); |
| 308 | break; |
| 309 | case MVT::f32: |
| 310 | case MVT::f64: |
| 311 | MF.addLiveOut(IA64::F8); |
| 312 | break; |
| 313 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 314 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 315 | return ArgValues; |
| 316 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 317 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 318 | std::pair<SDOperand, SDOperand> |
| 319 | IA64TargetLowering::LowerCallTo(SDOperand Chain, |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 320 | const Type *RetTy, bool isVarArg, |
Chris Lattner | adf6a96 | 2005-05-13 18:50:42 +0000 | [diff] [blame] | 321 | unsigned CallingConv, bool isTailCall, |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 322 | SDOperand Callee, ArgListTy &Args, |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 323 | SelectionDAG &DAG) { |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 324 | |
| 325 | MachineFunction &MF = DAG.getMachineFunction(); |
| 326 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 327 | unsigned NumBytes = 16; |
Duraid Madina | beeaab2 | 2005-03-31 12:31:11 +0000 | [diff] [blame] | 328 | unsigned outRegsUsed = 0; |
| 329 | |
| 330 | if (Args.size() > 8) { |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 331 | NumBytes += (Args.size() - 8) * 8; |
Duraid Madina | beeaab2 | 2005-03-31 12:31:11 +0000 | [diff] [blame] | 332 | outRegsUsed = 8; |
| 333 | } else { |
| 334 | outRegsUsed = Args.size(); |
| 335 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 336 | |
Duraid Madina | beeaab2 | 2005-03-31 12:31:11 +0000 | [diff] [blame] | 337 | // FIXME? this WILL fail if we ever try to pass around an arg that |
| 338 | // consumes more than a single output slot (a 'real' double, int128 |
| 339 | // some sort of aggregate etc.), as we'll underestimate how many 'outX' |
| 340 | // registers we use. Hopefully, the assembler will notice. |
| 341 | MF.getInfo<IA64FunctionInfo>()->outRegsUsed= |
| 342 | std::max(outRegsUsed, MF.getInfo<IA64FunctionInfo>()->outRegsUsed); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 343 | |
Chris Lattner | 16cd04d | 2005-05-12 23:24:06 +0000 | [diff] [blame] | 344 | Chain = DAG.getNode(ISD::CALLSEQ_START, MVT::Other, Chain, |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 345 | DAG.getConstant(NumBytes, getPointerTy())); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 346 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 347 | std::vector<SDOperand> args_to_use; |
| 348 | for (unsigned i = 0, e = Args.size(); i != e; ++i) |
| 349 | { |
| 350 | switch (getValueType(Args[i].second)) { |
| 351 | default: assert(0 && "unexpected argument type!"); |
| 352 | case MVT::i1: |
| 353 | case MVT::i8: |
| 354 | case MVT::i16: |
| 355 | case MVT::i32: |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 356 | //promote to 64-bits, sign/zero extending based on type |
| 357 | //of the argument |
| 358 | if(Args[i].second->isSigned()) |
| 359 | Args[i].first = DAG.getNode(ISD::SIGN_EXTEND, MVT::i64, |
| 360 | Args[i].first); |
| 361 | else |
| 362 | Args[i].first = DAG.getNode(ISD::ZERO_EXTEND, MVT::i64, |
| 363 | Args[i].first); |
| 364 | break; |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 365 | case MVT::f32: |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 366 | //promote to 64-bits |
| 367 | Args[i].first = DAG.getNode(ISD::FP_EXTEND, MVT::f64, Args[i].first); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 368 | case MVT::f64: |
| 369 | case MVT::i64: |
| 370 | break; |
| 371 | } |
| 372 | args_to_use.push_back(Args[i].first); |
| 373 | } |
| 374 | |
| 375 | std::vector<MVT::ValueType> RetVals; |
| 376 | MVT::ValueType RetTyVT = getValueType(RetTy); |
| 377 | if (RetTyVT != MVT::isVoid) |
| 378 | RetVals.push_back(RetTyVT); |
| 379 | RetVals.push_back(MVT::Other); |
| 380 | |
| 381 | SDOperand TheCall = SDOperand(DAG.getCall(RetVals, Chain, |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 382 | Callee, args_to_use), 0); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 383 | Chain = TheCall.getValue(RetTyVT != MVT::isVoid); |
Chris Lattner | 16cd04d | 2005-05-12 23:24:06 +0000 | [diff] [blame] | 384 | Chain = DAG.getNode(ISD::CALLSEQ_END, MVT::Other, Chain, |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 385 | DAG.getConstant(NumBytes, getPointerTy())); |
| 386 | return std::make_pair(TheCall, Chain); |
| 387 | } |
| 388 | |
Chris Lattner | e0fe225 | 2005-07-05 19:58:54 +0000 | [diff] [blame] | 389 | SDOperand |
| 390 | IA64TargetLowering::LowerVAStart(SDOperand Chain, SDOperand VAListP, |
| 391 | Value *VAListV, SelectionDAG &DAG) { |
Andrew Lenharth | 558bc88 | 2005-06-18 18:34:52 +0000 | [diff] [blame] | 392 | // vastart just stores the address of the VarArgsFrameIndex slot. |
| 393 | SDOperand FR = DAG.getFrameIndex(VarArgsFrameIndex, MVT::i64); |
Chris Lattner | e0fe225 | 2005-07-05 19:58:54 +0000 | [diff] [blame] | 394 | return DAG.getNode(ISD::STORE, MVT::Other, Chain, FR, |
| 395 | VAListP, DAG.getSrcValue(VAListV)); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | std::pair<SDOperand,SDOperand> IA64TargetLowering:: |
Chris Lattner | e0fe225 | 2005-07-05 19:58:54 +0000 | [diff] [blame] | 399 | LowerVAArg(SDOperand Chain, SDOperand VAListP, Value *VAListV, |
| 400 | const Type *ArgTy, SelectionDAG &DAG) { |
Duraid Madina | beeaab2 | 2005-03-31 12:31:11 +0000 | [diff] [blame] | 401 | |
| 402 | MVT::ValueType ArgVT = getValueType(ArgTy); |
Chris Lattner | e0fe225 | 2005-07-05 19:58:54 +0000 | [diff] [blame] | 403 | SDOperand Val = DAG.getLoad(MVT::i64, Chain, |
| 404 | VAListP, DAG.getSrcValue(VAListV)); |
| 405 | SDOperand Result = DAG.getLoad(ArgVT, DAG.getEntryNode(), Val, |
| 406 | DAG.getSrcValue(NULL)); |
Andrew Lenharth | 558bc88 | 2005-06-18 18:34:52 +0000 | [diff] [blame] | 407 | unsigned Amt; |
| 408 | if (ArgVT == MVT::i32 || ArgVT == MVT::f32) |
| 409 | Amt = 8; |
| 410 | else { |
| 411 | assert((ArgVT == MVT::i64 || ArgVT == MVT::f64) && |
| 412 | "Other types should have been promoted for varargs!"); |
| 413 | Amt = 8; |
Duraid Madina | beeaab2 | 2005-03-31 12:31:11 +0000 | [diff] [blame] | 414 | } |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 415 | Val = DAG.getNode(ISD::ADD, Val.getValueType(), Val, |
Andrew Lenharth | 558bc88 | 2005-06-18 18:34:52 +0000 | [diff] [blame] | 416 | DAG.getConstant(Amt, Val.getValueType())); |
| 417 | Chain = DAG.getNode(ISD::STORE, MVT::Other, Chain, |
Chris Lattner | e0fe225 | 2005-07-05 19:58:54 +0000 | [diff] [blame] | 418 | Val, VAListP, DAG.getSrcValue(VAListV)); |
Duraid Madina | beeaab2 | 2005-03-31 12:31:11 +0000 | [diff] [blame] | 419 | return std::make_pair(Result, Chain); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 420 | } |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 421 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 422 | namespace { |
| 423 | |
| 424 | //===--------------------------------------------------------------------===// |
| 425 | /// ISel - IA64 specific code to select IA64 machine instructions for |
| 426 | /// SelectionDAG operations. |
| 427 | /// |
| 428 | class ISel : public SelectionDAGISel { |
| 429 | /// IA64Lowering - This object fully describes how to lower LLVM code to an |
| 430 | /// IA64-specific SelectionDAG. |
| 431 | IA64TargetLowering IA64Lowering; |
Duraid Madina | b232256 | 2005-04-26 07:23:02 +0000 | [diff] [blame] | 432 | SelectionDAG *ISelDAG; // Hack to support us having a dag->dag transform |
| 433 | // for sdiv and udiv until it is put into the future |
| 434 | // dag combiner |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 435 | |
| 436 | /// ExprMap - As shared expressions are codegen'd, we keep track of which |
| 437 | /// vreg the value is produced in, so we only emit one copy of each compiled |
| 438 | /// tree. |
| 439 | std::map<SDOperand, unsigned> ExprMap; |
| 440 | std::set<SDOperand> LoweredTokens; |
| 441 | |
| 442 | public: |
Duraid Madina | b232256 | 2005-04-26 07:23:02 +0000 | [diff] [blame] | 443 | ISel(TargetMachine &TM) : SelectionDAGISel(IA64Lowering), IA64Lowering(TM), |
| 444 | ISelDAG(0) { } |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 445 | |
| 446 | /// InstructionSelectBasicBlock - This callback is invoked by |
| 447 | /// SelectionDAGISel when it has created a SelectionDAG for us to codegen. |
| 448 | virtual void InstructionSelectBasicBlock(SelectionDAG &DAG); |
| 449 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 450 | unsigned SelectExpr(SDOperand N); |
| 451 | void Select(SDOperand N); |
Duraid Madina | b232256 | 2005-04-26 07:23:02 +0000 | [diff] [blame] | 452 | // a dag->dag to transform mul-by-constant-int to shifts+adds/subs |
| 453 | SDOperand BuildConstmulSequence(SDOperand N); |
| 454 | |
Chris Lattner | 47c0889 | 2005-08-22 18:28:09 +0000 | [diff] [blame] | 455 | const char *getPassName() const { return "IA64 Instruction Selector"; } |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 456 | }; |
| 457 | } |
| 458 | |
| 459 | /// InstructionSelectBasicBlock - This callback is invoked by SelectionDAGISel |
| 460 | /// when it has created a SelectionDAG for us to codegen. |
| 461 | void ISel::InstructionSelectBasicBlock(SelectionDAG &DAG) { |
| 462 | |
| 463 | // Codegen the basic block. |
Duraid Madina | b232256 | 2005-04-26 07:23:02 +0000 | [diff] [blame] | 464 | ISelDAG = &DAG; |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 465 | Select(DAG.getRoot()); |
| 466 | |
| 467 | // Clear state used for selection. |
| 468 | ExprMap.clear(); |
| 469 | LoweredTokens.clear(); |
Duraid Madina | b232256 | 2005-04-26 07:23:02 +0000 | [diff] [blame] | 470 | ISelDAG = 0; |
| 471 | } |
| 472 | |
Duraid Madina | b232256 | 2005-04-26 07:23:02 +0000 | [diff] [blame] | 473 | // strip leading '0' characters from a string |
| 474 | void munchLeadingZeros(std::string& inString) { |
| 475 | while(inString.c_str()[0]=='0') { |
| 476 | inString.erase(0, 1); |
| 477 | } |
| 478 | } |
| 479 | |
| 480 | // strip trailing '0' characters from a string |
| 481 | void munchTrailingZeros(std::string& inString) { |
| 482 | int curPos=inString.length()-1; |
| 483 | |
| 484 | while(inString.c_str()[curPos]=='0') { |
| 485 | inString.erase(curPos, 1); |
| 486 | curPos--; |
| 487 | } |
| 488 | } |
| 489 | |
| 490 | // return how many consecutive '0' characters are at the end of a string |
| 491 | unsigned int countTrailingZeros(std::string& inString) { |
| 492 | int curPos=inString.length()-1; |
| 493 | unsigned int zeroCount=0; |
| 494 | // assert goes here |
| 495 | while(inString.c_str()[curPos--]=='0') { |
| 496 | zeroCount++; |
| 497 | } |
| 498 | return zeroCount; |
| 499 | } |
| 500 | |
| 501 | // booth encode a string of '1' and '0' characters (returns string of 'P' (+1) |
| 502 | // '0' and 'N' (-1) characters) |
| 503 | void boothEncode(std::string inString, std::string& boothEncodedString) { |
| 504 | |
| 505 | int curpos=0; |
| 506 | int replacements=0; |
| 507 | int lim=inString.size(); |
| 508 | |
| 509 | while(curpos<lim) { |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 510 | if(inString[curpos]=='1') { // if we see a '1', look for a run of them |
Duraid Madina | b232256 | 2005-04-26 07:23:02 +0000 | [diff] [blame] | 511 | int runlength=0; |
| 512 | std::string replaceString="N"; |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 513 | |
Duraid Madina | b232256 | 2005-04-26 07:23:02 +0000 | [diff] [blame] | 514 | // find the run length |
| 515 | for(;inString[curpos+runlength]=='1';runlength++) ; |
| 516 | |
| 517 | for(int i=0; i<runlength-1; i++) |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 518 | replaceString+="0"; |
Duraid Madina | b232256 | 2005-04-26 07:23:02 +0000 | [diff] [blame] | 519 | replaceString+="1"; |
| 520 | |
| 521 | if(runlength>1) { |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 522 | inString.replace(curpos, runlength+1, replaceString); |
| 523 | curpos+=runlength-1; |
Duraid Madina | b232256 | 2005-04-26 07:23:02 +0000 | [diff] [blame] | 524 | } else |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 525 | curpos++; |
Duraid Madina | b232256 | 2005-04-26 07:23:02 +0000 | [diff] [blame] | 526 | } else { // a zero, we just keep chugging along |
| 527 | curpos++; |
| 528 | } |
| 529 | } |
| 530 | |
| 531 | // clean up (trim the string, reverse it and turn '1's into 'P's) |
| 532 | munchTrailingZeros(inString); |
| 533 | boothEncodedString=""; |
| 534 | |
| 535 | for(int i=inString.size()-1;i>=0;i--) |
| 536 | if(inString[i]=='1') |
| 537 | boothEncodedString+="P"; |
| 538 | else |
| 539 | boothEncodedString+=inString[i]; |
| 540 | |
| 541 | } |
| 542 | |
| 543 | struct shiftaddblob { // this encodes stuff like (x=) "A << B [+-] C << D" |
| 544 | unsigned firstVal; // A |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 545 | unsigned firstShift; // B |
Duraid Madina | b232256 | 2005-04-26 07:23:02 +0000 | [diff] [blame] | 546 | unsigned secondVal; // C |
| 547 | unsigned secondShift; // D |
| 548 | bool isSub; |
| 549 | }; |
| 550 | |
| 551 | /* this implements Lefevre's "pattern-based" constant multiplication, |
| 552 | * see "Multiplication by an Integer Constant", INRIA report 1999-06 |
| 553 | * |
| 554 | * TODO: implement a method to try rewriting P0N<->0PP / N0P<->0NN |
| 555 | * to get better booth encodings - this does help in practice |
| 556 | * TODO: weight shifts appropriately (most architectures can't |
| 557 | * fuse a shift and an add for arbitrary shift amounts) */ |
| 558 | unsigned lefevre(const std::string inString, |
| 559 | std::vector<struct shiftaddblob> &ops) { |
| 560 | std::string retstring; |
| 561 | std::string s = inString; |
| 562 | munchTrailingZeros(s); |
| 563 | |
| 564 | int length=s.length()-1; |
| 565 | |
| 566 | if(length==0) { |
| 567 | return(0); |
| 568 | } |
| 569 | |
| 570 | std::vector<int> p,n; |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 571 | |
Duraid Madina | b232256 | 2005-04-26 07:23:02 +0000 | [diff] [blame] | 572 | for(int i=0; i<=length; i++) { |
| 573 | if (s.c_str()[length-i]=='P') { |
| 574 | p.push_back(i); |
| 575 | } else if (s.c_str()[length-i]=='N') { |
| 576 | n.push_back(i); |
| 577 | } |
| 578 | } |
| 579 | |
| 580 | std::string t, u; |
Chris Lattner | 4a20997 | 2005-08-25 00:03:21 +0000 | [diff] [blame] | 581 | int c = 0; |
Duraid Madina | 4706c03 | 2005-04-26 09:42:50 +0000 | [diff] [blame] | 582 | bool f; |
Duraid Madina | b232256 | 2005-04-26 07:23:02 +0000 | [diff] [blame] | 583 | std::map<const int, int> w; |
| 584 | |
Duraid Madina | 85d5f60 | 2005-04-27 11:57:39 +0000 | [diff] [blame] | 585 | for(unsigned i=0; i<p.size(); i++) { |
| 586 | for(unsigned j=0; j<i; j++) { |
Duraid Madina | b232256 | 2005-04-26 07:23:02 +0000 | [diff] [blame] | 587 | w[p[i]-p[j]]++; |
| 588 | } |
| 589 | } |
| 590 | |
Duraid Madina | 85d5f60 | 2005-04-27 11:57:39 +0000 | [diff] [blame] | 591 | for(unsigned i=1; i<n.size(); i++) { |
| 592 | for(unsigned j=0; j<i; j++) { |
Duraid Madina | b232256 | 2005-04-26 07:23:02 +0000 | [diff] [blame] | 593 | w[n[i]-n[j]]++; |
| 594 | } |
| 595 | } |
| 596 | |
Duraid Madina | 85d5f60 | 2005-04-27 11:57:39 +0000 | [diff] [blame] | 597 | for(unsigned i=0; i<p.size(); i++) { |
| 598 | for(unsigned j=0; j<n.size(); j++) { |
Duraid Madina | b232256 | 2005-04-26 07:23:02 +0000 | [diff] [blame] | 599 | w[-abs(p[i]-n[j])]++; |
| 600 | } |
| 601 | } |
| 602 | |
| 603 | std::map<const int, int>::const_iterator ii; |
| 604 | std::vector<int> d; |
| 605 | std::multimap<int, int> sorted_by_value; |
| 606 | |
| 607 | for(ii = w.begin(); ii!=w.end(); ii++) |
| 608 | sorted_by_value.insert(std::pair<int, int>((*ii).second,(*ii).first)); |
| 609 | |
| 610 | for (std::multimap<int, int>::iterator it = sorted_by_value.begin(); |
| 611 | it != sorted_by_value.end(); ++it) { |
| 612 | d.push_back((*it).second); |
| 613 | } |
| 614 | |
| 615 | int int_W=0; |
| 616 | int int_d; |
| 617 | |
| 618 | while(d.size()>0 && (w[int_d=d.back()] > int_W)) { |
| 619 | d.pop_back(); |
| 620 | retstring=s; // hmmm |
| 621 | int x=0; |
| 622 | int z=abs(int_d)-1; |
| 623 | |
| 624 | if(int_d>0) { |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 625 | |
Duraid Madina | 85d5f60 | 2005-04-27 11:57:39 +0000 | [diff] [blame] | 626 | for(unsigned base=0; base<retstring.size(); base++) { |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 627 | if( ((base+z+1) < retstring.size()) && |
| 628 | retstring.c_str()[base]=='P' && |
| 629 | retstring.c_str()[base+z+1]=='P') |
| 630 | { |
| 631 | // match |
| 632 | x++; |
| 633 | retstring.replace(base, 1, "0"); |
| 634 | retstring.replace(base+z+1, 1, "p"); |
| 635 | } |
Duraid Madina | b232256 | 2005-04-26 07:23:02 +0000 | [diff] [blame] | 636 | } |
| 637 | |
Duraid Madina | 85d5f60 | 2005-04-27 11:57:39 +0000 | [diff] [blame] | 638 | for(unsigned base=0; base<retstring.size(); base++) { |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 639 | if( ((base+z+1) < retstring.size()) && |
| 640 | retstring.c_str()[base]=='N' && |
| 641 | retstring.c_str()[base+z+1]=='N') |
| 642 | { |
| 643 | // match |
| 644 | x++; |
| 645 | retstring.replace(base, 1, "0"); |
| 646 | retstring.replace(base+z+1, 1, "n"); |
| 647 | } |
Duraid Madina | b232256 | 2005-04-26 07:23:02 +0000 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | } else { |
Duraid Madina | 85d5f60 | 2005-04-27 11:57:39 +0000 | [diff] [blame] | 651 | for(unsigned base=0; base<retstring.size(); base++) { |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 652 | if( ((base+z+1) < retstring.size()) && |
| 653 | ((retstring.c_str()[base]=='P' && |
| 654 | retstring.c_str()[base+z+1]=='N') || |
| 655 | (retstring.c_str()[base]=='N' && |
| 656 | retstring.c_str()[base+z+1]=='P')) ) { |
| 657 | // match |
| 658 | x++; |
| 659 | |
| 660 | if(retstring.c_str()[base]=='P') { |
| 661 | retstring.replace(base, 1, "0"); |
| 662 | retstring.replace(base+z+1, 1, "p"); |
| 663 | } else { // retstring[base]=='N' |
| 664 | retstring.replace(base, 1, "0"); |
| 665 | retstring.replace(base+z+1, 1, "n"); |
| 666 | } |
| 667 | } |
Duraid Madina | b232256 | 2005-04-26 07:23:02 +0000 | [diff] [blame] | 668 | } |
| 669 | } |
| 670 | |
| 671 | if(x>int_W) { |
| 672 | int_W = x; |
| 673 | t = retstring; |
| 674 | c = int_d; // tofix |
| 675 | } |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 676 | |
Duraid Madina | b232256 | 2005-04-26 07:23:02 +0000 | [diff] [blame] | 677 | } d.pop_back(); // hmm |
| 678 | |
| 679 | u = t; |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 680 | |
Duraid Madina | 85d5f60 | 2005-04-27 11:57:39 +0000 | [diff] [blame] | 681 | for(unsigned i=0; i<t.length(); i++) { |
Duraid Madina | b232256 | 2005-04-26 07:23:02 +0000 | [diff] [blame] | 682 | if(t.c_str()[i]=='p' || t.c_str()[i]=='n') |
| 683 | t.replace(i, 1, "0"); |
| 684 | } |
| 685 | |
Duraid Madina | 85d5f60 | 2005-04-27 11:57:39 +0000 | [diff] [blame] | 686 | for(unsigned i=0; i<u.length(); i++) { |
Duraid Madina | 8a3042c | 2005-05-09 13:18:34 +0000 | [diff] [blame] | 687 | if(u[i]=='P' || u[i]=='N') |
Duraid Madina | b232256 | 2005-04-26 07:23:02 +0000 | [diff] [blame] | 688 | u.replace(i, 1, "0"); |
Duraid Madina | 8a3042c | 2005-05-09 13:18:34 +0000 | [diff] [blame] | 689 | if(u[i]=='p') |
Duraid Madina | b232256 | 2005-04-26 07:23:02 +0000 | [diff] [blame] | 690 | u.replace(i, 1, "P"); |
Duraid Madina | 8a3042c | 2005-05-09 13:18:34 +0000 | [diff] [blame] | 691 | if(u[i]=='n') |
Duraid Madina | b232256 | 2005-04-26 07:23:02 +0000 | [diff] [blame] | 692 | u.replace(i, 1, "N"); |
| 693 | } |
| 694 | |
| 695 | if( c<0 ) { |
Duraid Madina | 4706c03 | 2005-04-26 09:42:50 +0000 | [diff] [blame] | 696 | f=true; |
Duraid Madina | b232256 | 2005-04-26 07:23:02 +0000 | [diff] [blame] | 697 | c=-c; |
| 698 | } else |
Duraid Madina | 4706c03 | 2005-04-26 09:42:50 +0000 | [diff] [blame] | 699 | f=false; |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 700 | |
Duraid Madina | 8a3042c | 2005-05-09 13:18:34 +0000 | [diff] [blame] | 701 | int pos=0; |
| 702 | while(u[pos]=='0') |
| 703 | pos++; |
| 704 | |
| 705 | bool hit=(u[pos]=='N'); |
Duraid Madina | b232256 | 2005-04-26 07:23:02 +0000 | [diff] [blame] | 706 | |
| 707 | int g=0; |
| 708 | if(hit) { |
| 709 | g=1; |
Duraid Madina | 85d5f60 | 2005-04-27 11:57:39 +0000 | [diff] [blame] | 710 | for(unsigned p=0; p<u.length(); p++) { |
Duraid Madina | 8a3042c | 2005-05-09 13:18:34 +0000 | [diff] [blame] | 711 | bool isP=(u[p]=='P'); |
| 712 | bool isN=(u[p]=='N'); |
Duraid Madina | b232256 | 2005-04-26 07:23:02 +0000 | [diff] [blame] | 713 | |
| 714 | if(isP) |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 715 | u.replace(p, 1, "N"); |
Duraid Madina | b232256 | 2005-04-26 07:23:02 +0000 | [diff] [blame] | 716 | if(isN) |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 717 | u.replace(p, 1, "P"); |
Duraid Madina | b232256 | 2005-04-26 07:23:02 +0000 | [diff] [blame] | 718 | } |
| 719 | } |
| 720 | |
| 721 | munchLeadingZeros(u); |
| 722 | |
| 723 | int i = lefevre(u, ops); |
| 724 | |
| 725 | shiftaddblob blob; |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 726 | |
Duraid Madina | b232256 | 2005-04-26 07:23:02 +0000 | [diff] [blame] | 727 | blob.firstVal=i; blob.firstShift=c; |
| 728 | blob.isSub=f; |
| 729 | blob.secondVal=i; blob.secondShift=0; |
| 730 | |
| 731 | ops.push_back(blob); |
| 732 | |
| 733 | i = ops.size(); |
| 734 | |
| 735 | munchLeadingZeros(t); |
| 736 | |
| 737 | if(t.length()==0) |
| 738 | return i; |
| 739 | |
| 740 | if(t.c_str()[0]!='P') { |
| 741 | g=2; |
Duraid Madina | 85d5f60 | 2005-04-27 11:57:39 +0000 | [diff] [blame] | 742 | for(unsigned p=0; p<t.length(); p++) { |
Duraid Madina | b232256 | 2005-04-26 07:23:02 +0000 | [diff] [blame] | 743 | bool isP=(t.c_str()[p]=='P'); |
| 744 | bool isN=(t.c_str()[p]=='N'); |
| 745 | |
| 746 | if(isP) |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 747 | t.replace(p, 1, "N"); |
Duraid Madina | b232256 | 2005-04-26 07:23:02 +0000 | [diff] [blame] | 748 | if(isN) |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 749 | t.replace(p, 1, "P"); |
Duraid Madina | b232256 | 2005-04-26 07:23:02 +0000 | [diff] [blame] | 750 | } |
| 751 | } |
| 752 | |
| 753 | int j = lefevre(t, ops); |
| 754 | |
| 755 | int trail=countTrailingZeros(u); |
| 756 | blob.secondVal=i; blob.secondShift=trail; |
| 757 | |
| 758 | trail=countTrailingZeros(t); |
| 759 | blob.firstVal=j; blob.firstShift=trail; |
| 760 | |
| 761 | switch(g) { |
| 762 | case 0: |
| 763 | blob.isSub=false; // first + second |
| 764 | break; |
| 765 | case 1: |
| 766 | blob.isSub=true; // first - second |
| 767 | break; |
| 768 | case 2: |
| 769 | blob.isSub=true; // second - first |
| 770 | int tmpval, tmpshift; |
| 771 | tmpval=blob.firstVal; |
| 772 | tmpshift=blob.firstShift; |
| 773 | blob.firstVal=blob.secondVal; |
| 774 | blob.firstShift=blob.secondShift; |
| 775 | blob.secondVal=tmpval; |
| 776 | blob.secondShift=tmpshift; |
| 777 | break; |
| 778 | //assert |
| 779 | } |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 780 | |
Duraid Madina | b232256 | 2005-04-26 07:23:02 +0000 | [diff] [blame] | 781 | ops.push_back(blob); |
| 782 | return ops.size(); |
| 783 | } |
| 784 | |
| 785 | SDOperand ISel::BuildConstmulSequence(SDOperand N) { |
| 786 | //FIXME: we should shortcut this stuff for multiplies by 2^n+1 |
| 787 | // in particular, *3 is nicer as *2+1, not *4-1 |
| 788 | int64_t constant=cast<ConstantSDNode>(N.getOperand(1))->getValue(); |
| 789 | |
| 790 | bool flippedSign; |
| 791 | unsigned preliminaryShift=0; |
| 792 | |
Duraid Madina | 40c9e6b | 2005-05-02 07:27:14 +0000 | [diff] [blame] | 793 | assert(constant != 0 && "erk, you're trying to multiply by constant zero\n"); |
Duraid Madina | b232256 | 2005-04-26 07:23:02 +0000 | [diff] [blame] | 794 | |
| 795 | // first, we make the constant to multiply by positive |
| 796 | if(constant<0) { |
| 797 | constant=-constant; |
| 798 | flippedSign=true; |
| 799 | } else { |
| 800 | flippedSign=false; |
| 801 | } |
| 802 | |
| 803 | // next, we make it odd. |
| 804 | for(; (constant%2==0); preliminaryShift++) |
| 805 | constant>>=1; |
| 806 | |
| 807 | //OK, we have a positive, odd number of 64 bits or less. Convert it |
| 808 | //to a binary string, constantString[0] is the LSB |
| 809 | char constantString[65]; |
| 810 | for(int i=0; i<64; i++) |
| 811 | constantString[i]='0'+((constant>>i)&0x1); |
| 812 | constantString[64]=0; |
| 813 | |
| 814 | // now, Booth encode it |
| 815 | std::string boothEncodedString; |
| 816 | boothEncode(constantString, boothEncodedString); |
| 817 | |
| 818 | std::vector<struct shiftaddblob> ops; |
| 819 | // do the transformation, filling out 'ops' |
| 820 | lefevre(boothEncodedString, ops); |
| 821 | |
Duraid Madina | e75a24a | 2005-05-15 14:44:13 +0000 | [diff] [blame] | 822 | assert(ops.size() < 80 && "constmul code has gone haywire\n"); |
| 823 | SDOperand results[80]; // temporary results (of adds/subs of shifts) |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 824 | |
Duraid Madina | b232256 | 2005-04-26 07:23:02 +0000 | [diff] [blame] | 825 | // now turn 'ops' into DAG bits |
Duraid Madina | 85d5f60 | 2005-04-27 11:57:39 +0000 | [diff] [blame] | 826 | for(unsigned i=0; i<ops.size(); i++) { |
Duraid Madina | b232256 | 2005-04-26 07:23:02 +0000 | [diff] [blame] | 827 | SDOperand amt = ISelDAG->getConstant(ops[i].firstShift, MVT::i64); |
| 828 | SDOperand val = (ops[i].firstVal == 0) ? N.getOperand(0) : |
| 829 | results[ops[i].firstVal-1]; |
| 830 | SDOperand left = ISelDAG->getNode(ISD::SHL, MVT::i64, val, amt); |
| 831 | amt = ISelDAG->getConstant(ops[i].secondShift, MVT::i64); |
| 832 | val = (ops[i].secondVal == 0) ? N.getOperand(0) : |
| 833 | results[ops[i].secondVal-1]; |
| 834 | SDOperand right = ISelDAG->getNode(ISD::SHL, MVT::i64, val, amt); |
| 835 | if(ops[i].isSub) |
| 836 | results[i] = ISelDAG->getNode(ISD::SUB, MVT::i64, left, right); |
| 837 | else |
| 838 | results[i] = ISelDAG->getNode(ISD::ADD, MVT::i64, left, right); |
| 839 | } |
| 840 | |
| 841 | // don't forget flippedSign and preliminaryShift! |
Duraid Madina | 40c9e6b | 2005-05-02 07:27:14 +0000 | [diff] [blame] | 842 | SDOperand shiftedresult; |
Duraid Madina | b232256 | 2005-04-26 07:23:02 +0000 | [diff] [blame] | 843 | if(preliminaryShift) { |
| 844 | SDOperand finalshift = ISelDAG->getConstant(preliminaryShift, MVT::i64); |
Duraid Madina | 40c9e6b | 2005-05-02 07:27:14 +0000 | [diff] [blame] | 845 | shiftedresult = ISelDAG->getNode(ISD::SHL, MVT::i64, |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 846 | results[ops.size()-1], finalshift); |
Duraid Madina | b232256 | 2005-04-26 07:23:02 +0000 | [diff] [blame] | 847 | } else { // there was no preliminary divide-by-power-of-2 required |
Duraid Madina | 40c9e6b | 2005-05-02 07:27:14 +0000 | [diff] [blame] | 848 | shiftedresult = results[ops.size()-1]; |
Duraid Madina | b232256 | 2005-04-26 07:23:02 +0000 | [diff] [blame] | 849 | } |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 850 | |
Duraid Madina | 40c9e6b | 2005-05-02 07:27:14 +0000 | [diff] [blame] | 851 | SDOperand finalresult; |
| 852 | if(flippedSign) { // if we were multiplying by a negative constant: |
| 853 | SDOperand zero = ISelDAG->getConstant(0, MVT::i64); |
| 854 | // subtract the result from 0 to flip its sign |
| 855 | finalresult = ISelDAG->getNode(ISD::SUB, MVT::i64, zero, shiftedresult); |
| 856 | } else { // there was no preliminary multiply by -1 required |
| 857 | finalresult = shiftedresult; |
| 858 | } |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 859 | |
| 860 | return finalresult; |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 861 | } |
| 862 | |
Duraid Madina | 4826a07 | 2005-04-06 09:55:17 +0000 | [diff] [blame] | 863 | /// ponderIntegerDivisionBy - When handling integer divides, if the divide |
| 864 | /// is by a constant such that we can efficiently codegen it, this |
| 865 | /// function says what to do. Currently, it returns 0 if the division must |
| 866 | /// become a genuine divide, and 1 if the division can be turned into a |
| 867 | /// right shift. |
| 868 | static unsigned ponderIntegerDivisionBy(SDOperand N, bool isSigned, |
| 869 | unsigned& Imm) { |
| 870 | if (N.getOpcode() != ISD::Constant) return 0; // if not a divide by |
| 871 | // a constant, give up. |
| 872 | |
| 873 | int64_t v = (int64_t)cast<ConstantSDNode>(N)->getSignExtended(); |
| 874 | |
Chris Lattner | 0561b3f | 2005-08-02 19:26:06 +0000 | [diff] [blame] | 875 | if (isPowerOf2_64(v)) { // if a division by a power of two, say so |
| 876 | Imm = Log2_64(v); |
Duraid Madina | 4826a07 | 2005-04-06 09:55:17 +0000 | [diff] [blame] | 877 | return 1; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 878 | } |
| 879 | |
Duraid Madina | 4826a07 | 2005-04-06 09:55:17 +0000 | [diff] [blame] | 880 | return 0; // fallthrough |
| 881 | } |
| 882 | |
Duraid Madina | c02780e | 2005-04-13 04:50:54 +0000 | [diff] [blame] | 883 | static unsigned ponderIntegerAndWith(SDOperand N, unsigned& Imm) { |
| 884 | if (N.getOpcode() != ISD::Constant) return 0; // if not ANDing with |
| 885 | // a constant, give up. |
| 886 | |
| 887 | int64_t v = (int64_t)cast<ConstantSDNode>(N)->getSignExtended(); |
| 888 | |
Chris Lattner | 0561b3f | 2005-08-02 19:26:06 +0000 | [diff] [blame] | 889 | if (isMask_64(v)) { // if ANDing with ((2^n)-1) for some n |
Jim Laskey | ffb973d | 2005-08-20 11:05:23 +0000 | [diff] [blame] | 890 | Imm = Log2_64(v) + 1; |
Duraid Madina | c02780e | 2005-04-13 04:50:54 +0000 | [diff] [blame] | 891 | return 1; // say so |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 892 | } |
| 893 | |
Duraid Madina | c02780e | 2005-04-13 04:50:54 +0000 | [diff] [blame] | 894 | return 0; // fallthrough |
| 895 | } |
| 896 | |
Duraid Madina | f55e403 | 2005-04-07 12:33:38 +0000 | [diff] [blame] | 897 | static unsigned ponderIntegerAdditionWith(SDOperand N, unsigned& Imm) { |
| 898 | if (N.getOpcode() != ISD::Constant) return 0; // if not adding a |
| 899 | // constant, give up. |
| 900 | int64_t v = (int64_t)cast<ConstantSDNode>(N)->getSignExtended(); |
| 901 | |
| 902 | if (v <= 8191 && v >= -8192) { // if this constants fits in 14 bits, say so |
| 903 | Imm = v & 0x3FFF; // 14 bits |
| 904 | return 1; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 905 | } |
Duraid Madina | f55e403 | 2005-04-07 12:33:38 +0000 | [diff] [blame] | 906 | return 0; // fallthrough |
| 907 | } |
| 908 | |
| 909 | static unsigned ponderIntegerSubtractionFrom(SDOperand N, unsigned& Imm) { |
| 910 | if (N.getOpcode() != ISD::Constant) return 0; // if not subtracting a |
| 911 | // constant, give up. |
| 912 | int64_t v = (int64_t)cast<ConstantSDNode>(N)->getSignExtended(); |
| 913 | |
| 914 | if (v <= 127 && v >= -128) { // if this constants fits in 8 bits, say so |
| 915 | Imm = v & 0xFF; // 8 bits |
| 916 | return 1; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 917 | } |
Duraid Madina | f55e403 | 2005-04-07 12:33:38 +0000 | [diff] [blame] | 918 | return 0; // fallthrough |
| 919 | } |
| 920 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 921 | unsigned ISel::SelectExpr(SDOperand N) { |
| 922 | unsigned Result; |
| 923 | unsigned Tmp1, Tmp2, Tmp3; |
| 924 | unsigned Opc = 0; |
| 925 | MVT::ValueType DestType = N.getValueType(); |
| 926 | |
| 927 | unsigned opcode = N.getOpcode(); |
| 928 | |
| 929 | SDNode *Node = N.Val; |
| 930 | SDOperand Op0, Op1; |
| 931 | |
| 932 | if (Node->getOpcode() == ISD::CopyFromReg) |
| 933 | // Just use the specified register as our input. |
Chris Lattner | 707ebc5 | 2005-08-16 21:56:37 +0000 | [diff] [blame] | 934 | return cast<RegisterSDNode>(Node->getOperand(1))->getReg(); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 935 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 936 | unsigned &Reg = ExprMap[N]; |
| 937 | if (Reg) return Reg; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 938 | |
Chris Lattner | b5d8e6e | 2005-05-13 20:29:26 +0000 | [diff] [blame] | 939 | if (N.getOpcode() != ISD::CALL && N.getOpcode() != ISD::TAILCALL) |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 940 | Reg = Result = (N.getValueType() != MVT::Other) ? |
| 941 | MakeReg(N.getValueType()) : 1; |
| 942 | else { |
| 943 | // If this is a call instruction, make sure to prepare ALL of the result |
| 944 | // values as well as the chain. |
| 945 | if (Node->getNumValues() == 1) |
| 946 | Reg = Result = 1; // Void call, just a chain. |
| 947 | else { |
| 948 | Result = MakeReg(Node->getValueType(0)); |
| 949 | ExprMap[N.getValue(0)] = Result; |
| 950 | for (unsigned i = 1, e = N.Val->getNumValues()-1; i != e; ++i) |
| 951 | ExprMap[N.getValue(i)] = MakeReg(Node->getValueType(i)); |
| 952 | ExprMap[SDOperand(Node, Node->getNumValues()-1)] = 1; |
| 953 | } |
| 954 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 955 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 956 | switch (N.getOpcode()) { |
| 957 | default: |
| 958 | Node->dump(); |
| 959 | assert(0 && "Node not handled!\n"); |
| 960 | |
| 961 | case ISD::FrameIndex: { |
| 962 | Tmp1 = cast<FrameIndexSDNode>(N)->getIndex(); |
| 963 | BuildMI(BB, IA64::MOV, 1, Result).addFrameIndex(Tmp1); |
| 964 | return Result; |
| 965 | } |
| 966 | |
| 967 | case ISD::ConstantPool: { |
Chris Lattner | 5839bf2 | 2005-08-26 17:15:30 +0000 | [diff] [blame] | 968 | Tmp1 = BB->getParent()->getConstantPool()-> |
| 969 | getConstantPoolIndex(cast<ConstantPoolSDNode>(N)->get()); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 970 | IA64Lowering.restoreGP(BB); // FIXME: do i really need this? |
| 971 | BuildMI(BB, IA64::ADD, 2, Result).addConstantPoolIndex(Tmp1) |
| 972 | .addReg(IA64::r1); |
| 973 | return Result; |
| 974 | } |
| 975 | |
| 976 | case ISD::ConstantFP: { |
| 977 | Tmp1 = Result; // Intermediate Register |
| 978 | if (cast<ConstantFPSDNode>(N)->getValue() < 0.0 || |
| 979 | cast<ConstantFPSDNode>(N)->isExactlyValue(-0.0)) |
| 980 | Tmp1 = MakeReg(MVT::f64); |
| 981 | |
| 982 | if (cast<ConstantFPSDNode>(N)->isExactlyValue(+0.0) || |
| 983 | cast<ConstantFPSDNode>(N)->isExactlyValue(-0.0)) |
| 984 | BuildMI(BB, IA64::FMOV, 1, Tmp1).addReg(IA64::F0); // load 0.0 |
| 985 | else if (cast<ConstantFPSDNode>(N)->isExactlyValue(+1.0) || |
| 986 | cast<ConstantFPSDNode>(N)->isExactlyValue(-1.0)) |
| 987 | BuildMI(BB, IA64::FMOV, 1, Tmp1).addReg(IA64::F1); // load 1.0 |
| 988 | else |
| 989 | assert(0 && "Unexpected FP constant!"); |
| 990 | if (Tmp1 != Result) |
| 991 | // we multiply by +1.0, negate (this is FNMA), and then add 0.0 |
| 992 | BuildMI(BB, IA64::FNMA, 3, Result).addReg(Tmp1).addReg(IA64::F1) |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 993 | .addReg(IA64::F0); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 994 | return Result; |
| 995 | } |
| 996 | |
| 997 | case ISD::DYNAMIC_STACKALLOC: { |
| 998 | // Generate both result values. |
| 999 | if (Result != 1) |
| 1000 | ExprMap[N.getValue(1)] = 1; // Generate the token |
| 1001 | else |
| 1002 | Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType()); |
| 1003 | |
| 1004 | // FIXME: We are currently ignoring the requested alignment for handling |
| 1005 | // greater than the stack alignment. This will need to be revisited at some |
| 1006 | // point. Align = N.getOperand(2); |
| 1007 | |
| 1008 | if (!isa<ConstantSDNode>(N.getOperand(2)) || |
| 1009 | cast<ConstantSDNode>(N.getOperand(2))->getValue() != 0) { |
| 1010 | std::cerr << "Cannot allocate stack object with greater alignment than" |
| 1011 | << " the stack alignment yet!"; |
| 1012 | abort(); |
| 1013 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1014 | |
| 1015 | /* |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1016 | Select(N.getOperand(0)); |
| 1017 | if (ConstantSDNode* CN = dyn_cast<ConstantSDNode>(N.getOperand(1))) |
| 1018 | { |
| 1019 | if (CN->getValue() < 32000) |
| 1020 | { |
| 1021 | BuildMI(BB, IA64::ADDIMM22, 2, IA64::r12).addReg(IA64::r12) |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1022 | .addImm(-CN->getValue()); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1023 | } else { |
| 1024 | Tmp1 = SelectExpr(N.getOperand(1)); |
| 1025 | // Subtract size from stack pointer, thereby allocating some space. |
| 1026 | BuildMI(BB, IA64::SUB, 2, IA64::r12).addReg(IA64::r12).addReg(Tmp1); |
| 1027 | } |
| 1028 | } else { |
| 1029 | Tmp1 = SelectExpr(N.getOperand(1)); |
| 1030 | // Subtract size from stack pointer, thereby allocating some space. |
| 1031 | BuildMI(BB, IA64::SUB, 2, IA64::r12).addReg(IA64::r12).addReg(Tmp1); |
| 1032 | } |
Duraid Madina | beeaab2 | 2005-03-31 12:31:11 +0000 | [diff] [blame] | 1033 | */ |
| 1034 | Select(N.getOperand(0)); |
| 1035 | Tmp1 = SelectExpr(N.getOperand(1)); |
| 1036 | // Subtract size from stack pointer, thereby allocating some space. |
| 1037 | BuildMI(BB, IA64::SUB, 2, IA64::r12).addReg(IA64::r12).addReg(Tmp1); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1038 | // Put a pointer to the space into the result register, by copying the |
| 1039 | // stack pointer. |
| 1040 | BuildMI(BB, IA64::MOV, 1, Result).addReg(IA64::r12); |
| 1041 | return Result; |
| 1042 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1043 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1044 | case ISD::SELECT: { |
| 1045 | Tmp1 = SelectExpr(N.getOperand(0)); //Cond |
| 1046 | Tmp2 = SelectExpr(N.getOperand(1)); //Use if TRUE |
| 1047 | Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE |
| 1048 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1049 | unsigned bogoResult; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1050 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1051 | switch (N.getOperand(1).getValueType()) { |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1052 | default: assert(0 && |
Duraid Madina | 4bd708d | 2005-05-02 06:41:13 +0000 | [diff] [blame] | 1053 | "ISD::SELECT: 'select'ing something other than i1, i64 or f64!\n"); |
| 1054 | // for i1, we load the condition into an integer register, then |
| 1055 | // conditionally copy Tmp2 and Tmp3 to Tmp1 in parallel (only one |
| 1056 | // of them will go through, since the integer register will hold |
| 1057 | // either 0 or 1) |
| 1058 | case MVT::i1: { |
| 1059 | bogoResult=MakeReg(MVT::i1); |
| 1060 | |
| 1061 | // load the condition into an integer register |
| 1062 | unsigned condReg=MakeReg(MVT::i64); |
| 1063 | unsigned dummy=MakeReg(MVT::i64); |
| 1064 | BuildMI(BB, IA64::MOV, 1, dummy).addReg(IA64::r0); |
| 1065 | BuildMI(BB, IA64::TPCADDIMM22, 2, condReg).addReg(dummy) |
| 1066 | .addImm(1).addReg(Tmp1); |
| 1067 | |
| 1068 | // initialize Result (bool) to false (hence UNC) and if |
| 1069 | // the select condition (condReg) is false (0), copy Tmp3 |
| 1070 | BuildMI(BB, IA64::PCMPEQUNC, 3, bogoResult) |
| 1071 | .addReg(condReg).addReg(IA64::r0).addReg(Tmp3); |
| 1072 | |
| 1073 | // now, if the selection condition is true, write 1 to the |
| 1074 | // result if Tmp2 is 1 |
| 1075 | BuildMI(BB, IA64::TPCMPNE, 3, Result).addReg(bogoResult) |
| 1076 | .addReg(condReg).addReg(IA64::r0).addReg(Tmp2); |
| 1077 | break; |
| 1078 | } |
| 1079 | // for i64/f64, we just copy Tmp3 and then conditionally overwrite it |
| 1080 | // with Tmp2 if Tmp1 is true |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1081 | case MVT::i64: |
| 1082 | bogoResult=MakeReg(MVT::i64); |
Duraid Madina | 4bd708d | 2005-05-02 06:41:13 +0000 | [diff] [blame] | 1083 | BuildMI(BB, IA64::MOV, 1, bogoResult).addReg(Tmp3); |
| 1084 | BuildMI(BB, IA64::CMOV, 2, Result).addReg(bogoResult).addReg(Tmp2) |
| 1085 | .addReg(Tmp1); |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1086 | break; |
| 1087 | case MVT::f64: |
| 1088 | bogoResult=MakeReg(MVT::f64); |
Duraid Madina | 4bd708d | 2005-05-02 06:41:13 +0000 | [diff] [blame] | 1089 | BuildMI(BB, IA64::FMOV, 1, bogoResult).addReg(Tmp3); |
| 1090 | BuildMI(BB, IA64::CFMOV, 2, Result).addReg(bogoResult).addReg(Tmp2) |
| 1091 | .addReg(Tmp1); |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1092 | break; |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1093 | } |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 1094 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1095 | return Result; |
| 1096 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1097 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1098 | case ISD::Constant: { |
| 1099 | unsigned depositPos=0; |
| 1100 | unsigned depositLen=0; |
| 1101 | switch (N.getValueType()) { |
| 1102 | default: assert(0 && "Cannot use constants of this type!"); |
| 1103 | case MVT::i1: { // if a bool, we don't 'load' so much as generate |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1104 | // the constant: |
| 1105 | if(cast<ConstantSDNode>(N)->getValue()) // true: |
| 1106 | BuildMI(BB, IA64::CMPEQ, 2, Result).addReg(IA64::r0).addReg(IA64::r0); |
| 1107 | else // false: |
| 1108 | BuildMI(BB, IA64::CMPNE, 2, Result).addReg(IA64::r0).addReg(IA64::r0); |
| 1109 | return Result; // early exit |
| 1110 | } |
Duraid Madina | 5ef2ec9 | 2005-04-11 05:55:56 +0000 | [diff] [blame] | 1111 | case MVT::i64: break; |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1112 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1113 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1114 | int64_t immediate = cast<ConstantSDNode>(N)->getValue(); |
Duraid Madina | 5ef2ec9 | 2005-04-11 05:55:56 +0000 | [diff] [blame] | 1115 | |
| 1116 | if(immediate==0) { // if the constant is just zero, |
| 1117 | BuildMI(BB, IA64::MOV, 1, Result).addReg(IA64::r0); // just copy r0 |
| 1118 | return Result; // early exit |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1119 | } |
| 1120 | |
Duraid Madina | 5ef2ec9 | 2005-04-11 05:55:56 +0000 | [diff] [blame] | 1121 | if (immediate <= 8191 && immediate >= -8192) { |
| 1122 | // if this constants fits in 14 bits, we use a mov the assembler will |
| 1123 | // turn into: "adds rDest=imm,r0" (and _not_ "andl"...) |
| 1124 | BuildMI(BB, IA64::MOVSIMM14, 1, Result).addSImm(immediate); |
| 1125 | return Result; // early exit |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1126 | } |
Duraid Madina | 5ef2ec9 | 2005-04-11 05:55:56 +0000 | [diff] [blame] | 1127 | |
| 1128 | if (immediate <= 2097151 && immediate >= -2097152) { |
| 1129 | // if this constants fits in 22 bits, we use a mov the assembler will |
| 1130 | // turn into: "addl rDest=imm,r0" |
| 1131 | BuildMI(BB, IA64::MOVSIMM22, 1, Result).addSImm(immediate); |
| 1132 | return Result; // early exit |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1133 | } |
Duraid Madina | 5ef2ec9 | 2005-04-11 05:55:56 +0000 | [diff] [blame] | 1134 | |
| 1135 | /* otherwise, our immediate is big, so we use movl */ |
| 1136 | uint64_t Imm = immediate; |
Duraid Madina | 21478e5 | 2005-04-11 07:16:39 +0000 | [diff] [blame] | 1137 | BuildMI(BB, IA64::MOVLIMM64, 1, Result).addImm64(Imm); |
Duraid Madina | 5ef2ec9 | 2005-04-11 05:55:56 +0000 | [diff] [blame] | 1138 | return Result; |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1139 | } |
Duraid Madina | 75c9fcb | 2005-04-02 10:33:53 +0000 | [diff] [blame] | 1140 | |
| 1141 | case ISD::UNDEF: { |
| 1142 | BuildMI(BB, IA64::IDEF, 0, Result); |
| 1143 | return Result; |
| 1144 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1145 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1146 | case ISD::GlobalAddress: { |
| 1147 | GlobalValue *GV = cast<GlobalAddressSDNode>(N)->getGlobal(); |
| 1148 | unsigned Tmp1 = MakeReg(MVT::i64); |
Duraid Madina | beeaab2 | 2005-03-31 12:31:11 +0000 | [diff] [blame] | 1149 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1150 | BuildMI(BB, IA64::ADD, 2, Tmp1).addGlobalAddress(GV).addReg(IA64::r1); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1151 | BuildMI(BB, IA64::LD8, 1, Result).addReg(Tmp1); |
Duraid Madina | beeaab2 | 2005-03-31 12:31:11 +0000 | [diff] [blame] | 1152 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1153 | return Result; |
| 1154 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1155 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1156 | case ISD::ExternalSymbol: { |
| 1157 | const char *Sym = cast<ExternalSymbolSDNode>(N)->getSymbol(); |
Duraid Madina | beeaab2 | 2005-03-31 12:31:11 +0000 | [diff] [blame] | 1158 | // assert(0 && "sorry, but what did you want an ExternalSymbol for again?"); |
| 1159 | BuildMI(BB, IA64::MOV, 1, Result).addExternalSymbol(Sym); // XXX |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1160 | return Result; |
| 1161 | } |
| 1162 | |
| 1163 | case ISD::FP_EXTEND: { |
| 1164 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1165 | BuildMI(BB, IA64::FMOV, 1, Result).addReg(Tmp1); |
| 1166 | return Result; |
| 1167 | } |
| 1168 | |
Chris Lattner | 26e04bb | 2005-09-02 00:15:30 +0000 | [diff] [blame] | 1169 | case ISD::ANY_EXTEND: |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1170 | case ISD::ZERO_EXTEND: { |
| 1171 | Tmp1 = SelectExpr(N.getOperand(0)); // value |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1172 | |
Chris Lattner | 26e04bb | 2005-09-02 00:15:30 +0000 | [diff] [blame] | 1173 | assert(N.getOperand(0).getValueType() == MVT::i1 && |
| 1174 | "Cannot zero-extend this type!"); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1175 | |
Chris Lattner | 26e04bb | 2005-09-02 00:15:30 +0000 | [diff] [blame] | 1176 | // if the predicate reg has 1, we want a '1' in our GR. |
| 1177 | unsigned dummy = MakeReg(MVT::i64); |
| 1178 | // first load zero: |
| 1179 | BuildMI(BB, IA64::MOV, 1, dummy).addReg(IA64::r0); |
| 1180 | // ...then conditionally (PR:Tmp1) add 1: |
| 1181 | BuildMI(BB, IA64::TPCADDIMM22, 2, Result).addReg(dummy) |
| 1182 | .addImm(1).addReg(Tmp1); |
| 1183 | return Result; // XXX early exit! |
| 1184 | } |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1185 | |
Chris Lattner | 26e04bb | 2005-09-02 00:15:30 +0000 | [diff] [blame] | 1186 | case ISD::SIGN_EXTEND: |
| 1187 | assert(N.getOperand(0).getValueType() == MVT::i1 && |
| 1188 | "Cannot zero-extend this type!"); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1189 | |
| 1190 | Tmp1 = SelectExpr(N.getOperand(0)); // value |
Chris Lattner | 26e04bb | 2005-09-02 00:15:30 +0000 | [diff] [blame] | 1191 | assert(0 && "don't know how to sign_extend from bool yet!"); |
| 1192 | abort(); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1193 | |
Chris Lattner | 26e04bb | 2005-09-02 00:15:30 +0000 | [diff] [blame] | 1194 | case ISD::TRUNCATE: |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1195 | // we use the funky dep.z (deposit (zero)) instruction to deposit bits |
| 1196 | // of R0 appropriately. |
Chris Lattner | 26e04bb | 2005-09-02 00:15:30 +0000 | [diff] [blame] | 1197 | assert(N.getOperand(0).getValueType() == MVT::i64 && |
| 1198 | N.getValueType() == MVT::i1 && "Unknown truncate!"); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1199 | Tmp1 = SelectExpr(N.getOperand(0)); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1200 | |
Chris Lattner | 26e04bb | 2005-09-02 00:15:30 +0000 | [diff] [blame] | 1201 | // if input (normal reg) is 0, 0!=0 -> false (0), if 1, 1!=0 ->true (1): |
| 1202 | BuildMI(BB, IA64::CMPNE, 2, Result).addReg(Tmp1).addReg(IA64::r0); |
| 1203 | return Result; // XXX early exit! |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1204 | |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1205 | /* |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1206 | case ISD::FP_ROUND: { |
| 1207 | assert (DestType == MVT::f32 && N.getOperand(0).getValueType() == MVT::f64 && |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1208 | "error: trying to FP_ROUND something other than f64 -> f32!\n"); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1209 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1210 | BuildMI(BB, IA64::FADDS, 2, Result).addReg(Tmp1).addReg(IA64::F0); |
| 1211 | // we add 0.0 using a single precision add to do rounding |
| 1212 | return Result; |
| 1213 | } |
| 1214 | */ |
| 1215 | |
| 1216 | // FIXME: the following 4 cases need cleaning |
| 1217 | case ISD::SINT_TO_FP: { |
| 1218 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1219 | Tmp2 = MakeReg(MVT::f64); |
| 1220 | unsigned dummy = MakeReg(MVT::f64); |
| 1221 | BuildMI(BB, IA64::SETFSIG, 1, Tmp2).addReg(Tmp1); |
| 1222 | BuildMI(BB, IA64::FCVTXF, 1, dummy).addReg(Tmp2); |
| 1223 | BuildMI(BB, IA64::FNORMD, 1, Result).addReg(dummy); |
| 1224 | return Result; |
| 1225 | } |
| 1226 | |
| 1227 | case ISD::UINT_TO_FP: { |
| 1228 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1229 | Tmp2 = MakeReg(MVT::f64); |
| 1230 | unsigned dummy = MakeReg(MVT::f64); |
| 1231 | BuildMI(BB, IA64::SETFSIG, 1, Tmp2).addReg(Tmp1); |
| 1232 | BuildMI(BB, IA64::FCVTXUF, 1, dummy).addReg(Tmp2); |
| 1233 | BuildMI(BB, IA64::FNORMD, 1, Result).addReg(dummy); |
| 1234 | return Result; |
| 1235 | } |
| 1236 | |
| 1237 | case ISD::FP_TO_SINT: { |
| 1238 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1239 | Tmp2 = MakeReg(MVT::f64); |
| 1240 | BuildMI(BB, IA64::FCVTFXTRUNC, 1, Tmp2).addReg(Tmp1); |
| 1241 | BuildMI(BB, IA64::GETFSIG, 1, Result).addReg(Tmp2); |
| 1242 | return Result; |
| 1243 | } |
| 1244 | |
| 1245 | case ISD::FP_TO_UINT: { |
| 1246 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1247 | Tmp2 = MakeReg(MVT::f64); |
| 1248 | BuildMI(BB, IA64::FCVTFXUTRUNC, 1, Tmp2).addReg(Tmp1); |
| 1249 | BuildMI(BB, IA64::GETFSIG, 1, Result).addReg(Tmp2); |
| 1250 | return Result; |
| 1251 | } |
Chris Lattner | 3e2bafd | 2005-09-28 22:29:17 +0000 | [diff] [blame] | 1252 | |
| 1253 | case ISD::FADD: { |
| 1254 | if (N.getOperand(0).getOpcode() == ISD::FMUL && |
| 1255 | N.getOperand(0).Val->hasOneUse()) { // if we can fold this add |
| 1256 | // into an fma, do so: |
| 1257 | // ++FusedFP; // Statistic |
Duraid Madina | 4826a07 | 2005-04-06 09:55:17 +0000 | [diff] [blame] | 1258 | Tmp1 = SelectExpr(N.getOperand(0).getOperand(0)); |
| 1259 | Tmp2 = SelectExpr(N.getOperand(0).getOperand(1)); |
| 1260 | Tmp3 = SelectExpr(N.getOperand(1)); |
| 1261 | BuildMI(BB, IA64::FMA, 3, Result).addReg(Tmp1).addReg(Tmp2).addReg(Tmp3); |
| 1262 | return Result; // early exit |
| 1263 | } |
Chris Lattner | 3e2bafd | 2005-09-28 22:29:17 +0000 | [diff] [blame] | 1264 | |
| 1265 | //else, fallthrough: |
| 1266 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1267 | Tmp2 = SelectExpr(N.getOperand(1)); |
| 1268 | BuildMI(BB, IA64::FADD, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 1269 | return Result; |
| 1270 | } |
Duraid Madina | ed09502 | 2005-04-13 06:12:04 +0000 | [diff] [blame] | 1271 | |
Chris Lattner | 3e2bafd | 2005-09-28 22:29:17 +0000 | [diff] [blame] | 1272 | case ISD::ADD: { |
| 1273 | if (N.getOperand(0).getOpcode() == ISD::SHL && |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1274 | N.getOperand(0).Val->hasOneUse()) { // if we might be able to fold |
Duraid Madina | ed09502 | 2005-04-13 06:12:04 +0000 | [diff] [blame] | 1275 | // this add into a shladd, try: |
| 1276 | ConstantSDNode *CSD = NULL; |
| 1277 | if((CSD = dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) && |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1278 | (CSD->getValue() >= 1) && (CSD->getValue() <= 4) ) { // we can: |
Duraid Madina | ed09502 | 2005-04-13 06:12:04 +0000 | [diff] [blame] | 1279 | |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1280 | // ++FusedSHLADD; // Statistic |
| 1281 | Tmp1 = SelectExpr(N.getOperand(0).getOperand(0)); |
| 1282 | int shl_amt = CSD->getValue(); |
| 1283 | Tmp3 = SelectExpr(N.getOperand(1)); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 1284 | |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1285 | BuildMI(BB, IA64::SHLADD, 3, Result) |
| 1286 | .addReg(Tmp1).addImm(shl_amt).addReg(Tmp3); |
| 1287 | return Result; // early exit |
Duraid Madina | ed09502 | 2005-04-13 06:12:04 +0000 | [diff] [blame] | 1288 | } |
| 1289 | } |
| 1290 | |
| 1291 | //else, fallthrough: |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1292 | Tmp1 = SelectExpr(N.getOperand(0)); |
Chris Lattner | 3e2bafd | 2005-09-28 22:29:17 +0000 | [diff] [blame] | 1293 | switch (ponderIntegerAdditionWith(N.getOperand(1), Tmp3)) { |
| 1294 | case 1: // adding a constant that's 14 bits |
| 1295 | BuildMI(BB, IA64::ADDIMM14, 2, Result).addReg(Tmp1).addSImm(Tmp3); |
| 1296 | return Result; // early exit |
| 1297 | } // fallthrough and emit a reg+reg ADD: |
| 1298 | Tmp2 = SelectExpr(N.getOperand(1)); |
| 1299 | BuildMI(BB, IA64::ADD, 2, Result).addReg(Tmp1).addReg(Tmp2); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1300 | return Result; |
| 1301 | } |
| 1302 | |
Chris Lattner | 3e2bafd | 2005-09-28 22:29:17 +0000 | [diff] [blame] | 1303 | case ISD::FMUL: |
| 1304 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1305 | Tmp2 = SelectExpr(N.getOperand(1)); |
| 1306 | BuildMI(BB, IA64::FMPY, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 1307 | return Result; |
| 1308 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1309 | case ISD::MUL: { |
Duraid Madina | 4826a07 | 2005-04-06 09:55:17 +0000 | [diff] [blame] | 1310 | |
Chris Lattner | 3e2bafd | 2005-09-28 22:29:17 +0000 | [diff] [blame] | 1311 | // TODO: speed! |
Duraid Madina | d2ff5ef | 2005-08-10 12:38:57 +0000 | [diff] [blame] | 1312 | /* FIXME if(N.getOperand(1).getOpcode() != ISD::Constant) { // if not a const mul |
| 1313 | */ |
Chris Lattner | 3e2bafd | 2005-09-28 22:29:17 +0000 | [diff] [blame] | 1314 | // boring old integer multiply with xma |
Duraid Madina | b232256 | 2005-04-26 07:23:02 +0000 | [diff] [blame] | 1315 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1316 | Tmp2 = SelectExpr(N.getOperand(1)); |
Chris Lattner | 3e2bafd | 2005-09-28 22:29:17 +0000 | [diff] [blame] | 1317 | |
| 1318 | unsigned TempFR1=MakeReg(MVT::f64); |
| 1319 | unsigned TempFR2=MakeReg(MVT::f64); |
| 1320 | unsigned TempFR3=MakeReg(MVT::f64); |
| 1321 | BuildMI(BB, IA64::SETFSIG, 1, TempFR1).addReg(Tmp1); |
| 1322 | BuildMI(BB, IA64::SETFSIG, 1, TempFR2).addReg(Tmp2); |
| 1323 | BuildMI(BB, IA64::XMAL, 1, TempFR3).addReg(TempFR1).addReg(TempFR2) |
| 1324 | .addReg(IA64::F0); |
| 1325 | BuildMI(BB, IA64::GETFSIG, 1, Result).addReg(TempFR3); |
| 1326 | return Result; // early exit |
| 1327 | /* FIXME } else { // we are multiplying by an integer constant! yay |
| 1328 | return Reg = SelectExpr(BuildConstmulSequence(N)); // avert your eyes! |
| 1329 | } */ |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1330 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1331 | |
Chris Lattner | 3e2bafd | 2005-09-28 22:29:17 +0000 | [diff] [blame] | 1332 | case ISD::FSUB: |
| 1333 | if(N.getOperand(0).getOpcode() == ISD::FMUL && |
Duraid Madina | 4826a07 | 2005-04-06 09:55:17 +0000 | [diff] [blame] | 1334 | N.getOperand(0).Val->hasOneUse()) { // if we can fold this sub |
| 1335 | // into an fms, do so: |
Chris Lattner | 3e2bafd | 2005-09-28 22:29:17 +0000 | [diff] [blame] | 1336 | // ++FusedFP; // Statistic |
Duraid Madina | 4826a07 | 2005-04-06 09:55:17 +0000 | [diff] [blame] | 1337 | Tmp1 = SelectExpr(N.getOperand(0).getOperand(0)); |
| 1338 | Tmp2 = SelectExpr(N.getOperand(0).getOperand(1)); |
| 1339 | Tmp3 = SelectExpr(N.getOperand(1)); |
| 1340 | BuildMI(BB, IA64::FMS, 3, Result).addReg(Tmp1).addReg(Tmp2).addReg(Tmp3); |
| 1341 | return Result; // early exit |
| 1342 | } |
Chris Lattner | 3e2bafd | 2005-09-28 22:29:17 +0000 | [diff] [blame] | 1343 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1344 | Tmp2 = SelectExpr(N.getOperand(1)); |
Chris Lattner | 3e2bafd | 2005-09-28 22:29:17 +0000 | [diff] [blame] | 1345 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1346 | BuildMI(BB, IA64::FSUB, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 1347 | return Result; |
| 1348 | |
| 1349 | case ISD::SUB: { |
| 1350 | Tmp2 = SelectExpr(N.getOperand(1)); |
| 1351 | switch (ponderIntegerSubtractionFrom(N.getOperand(0), Tmp3)) { |
| 1352 | case 1: // subtracting *from* an 8 bit constant: |
| 1353 | BuildMI(BB, IA64::SUBIMM8, 2, Result).addSImm(Tmp3).addReg(Tmp2); |
| 1354 | return Result; // early exit |
| 1355 | } // fallthrough and emit a reg+reg SUB: |
| 1356 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1357 | BuildMI(BB, IA64::SUB, 2, Result).addReg(Tmp1).addReg(Tmp2); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1358 | return Result; |
| 1359 | } |
Duraid Madina | a7ee8b8 | 2005-04-02 05:18:38 +0000 | [diff] [blame] | 1360 | |
| 1361 | case ISD::FABS: { |
| 1362 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1363 | assert(DestType == MVT::f64 && "trying to fabs something other than f64?"); |
| 1364 | BuildMI(BB, IA64::FABS, 1, Result).addReg(Tmp1); |
| 1365 | return Result; |
| 1366 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1367 | |
Duraid Madina | a7ee8b8 | 2005-04-02 05:18:38 +0000 | [diff] [blame] | 1368 | case ISD::FNEG: { |
Duraid Madina | a7ee8b8 | 2005-04-02 05:18:38 +0000 | [diff] [blame] | 1369 | assert(DestType == MVT::f64 && "trying to fneg something other than f64?"); |
Duraid Madina | 75c9fcb | 2005-04-02 10:33:53 +0000 | [diff] [blame] | 1370 | |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1371 | if (ISD::FABS == N.getOperand(0).getOpcode()) { // && hasOneUse()? |
Duraid Madina | 75c9fcb | 2005-04-02 10:33:53 +0000 | [diff] [blame] | 1372 | Tmp1 = SelectExpr(N.getOperand(0).getOperand(0)); |
| 1373 | BuildMI(BB, IA64::FNEGABS, 1, Result).addReg(Tmp1); // fold in abs |
| 1374 | } else { |
| 1375 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1376 | BuildMI(BB, IA64::FNEG, 1, Result).addReg(Tmp1); // plain old fneg |
| 1377 | } |
| 1378 | |
Duraid Madina | a7ee8b8 | 2005-04-02 05:18:38 +0000 | [diff] [blame] | 1379 | return Result; |
| 1380 | } |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1381 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1382 | case ISD::AND: { |
| 1383 | switch (N.getValueType()) { |
| 1384 | default: assert(0 && "Cannot AND this type!"); |
| 1385 | case MVT::i1: { // if a bool, we emit a pseudocode AND |
| 1386 | unsigned pA = SelectExpr(N.getOperand(0)); |
| 1387 | unsigned pB = SelectExpr(N.getOperand(1)); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1388 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1389 | /* our pseudocode for AND is: |
| 1390 | * |
| 1391 | (pA) cmp.eq.unc pC,p0 = r0,r0 // pC = pA |
| 1392 | cmp.eq pTemp,p0 = r0,r0 // pTemp = NOT pB |
| 1393 | ;; |
| 1394 | (pB) cmp.ne pTemp,p0 = r0,r0 |
| 1395 | ;; |
| 1396 | (pTemp)cmp.ne pC,p0 = r0,r0 // if (NOT pB) pC = 0 |
| 1397 | |
| 1398 | */ |
| 1399 | unsigned pTemp = MakeReg(MVT::i1); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1400 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1401 | unsigned bogusTemp1 = MakeReg(MVT::i1); |
| 1402 | unsigned bogusTemp2 = MakeReg(MVT::i1); |
| 1403 | unsigned bogusTemp3 = MakeReg(MVT::i1); |
| 1404 | unsigned bogusTemp4 = MakeReg(MVT::i1); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1405 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1406 | BuildMI(BB, IA64::PCMPEQUNC, 3, bogusTemp1) |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1407 | .addReg(IA64::r0).addReg(IA64::r0).addReg(pA); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1408 | BuildMI(BB, IA64::CMPEQ, 2, bogusTemp2) |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1409 | .addReg(IA64::r0).addReg(IA64::r0); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1410 | BuildMI(BB, IA64::TPCMPNE, 3, pTemp) |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1411 | .addReg(bogusTemp2).addReg(IA64::r0).addReg(IA64::r0).addReg(pB); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1412 | BuildMI(BB, IA64::TPCMPNE, 3, Result) |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1413 | .addReg(bogusTemp1).addReg(IA64::r0).addReg(IA64::r0).addReg(pTemp); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1414 | break; |
| 1415 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1416 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1417 | // if not a bool, we just AND away: |
| 1418 | case MVT::i8: |
| 1419 | case MVT::i16: |
| 1420 | case MVT::i32: |
| 1421 | case MVT::i64: { |
| 1422 | Tmp1 = SelectExpr(N.getOperand(0)); |
Duraid Madina | 7340dd5 | 2005-08-21 15:43:53 +0000 | [diff] [blame] | 1423 | switch (ponderIntegerAndWith(N.getOperand(1), Tmp3)) { |
Duraid Madina | c02780e | 2005-04-13 04:50:54 +0000 | [diff] [blame] | 1424 | case 1: // ANDing a constant that is 2^n-1 for some n |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1425 | switch (Tmp3) { |
| 1426 | case 8: // if AND 0x00000000000000FF, be quaint and use zxt1 |
| 1427 | BuildMI(BB, IA64::ZXT1, 1, Result).addReg(Tmp1); |
| 1428 | break; |
| 1429 | case 16: // if AND 0x000000000000FFFF, be quaint and use zxt2 |
| 1430 | BuildMI(BB, IA64::ZXT2, 1, Result).addReg(Tmp1); |
| 1431 | break; |
| 1432 | case 32: // if AND 0x00000000FFFFFFFF, be quaint and use zxt4 |
| 1433 | BuildMI(BB, IA64::ZXT4, 1, Result).addReg(Tmp1); |
| 1434 | break; |
| 1435 | default: // otherwise, use dep.z to paste zeros |
Duraid Madina | 7340dd5 | 2005-08-21 15:43:53 +0000 | [diff] [blame] | 1436 | // FIXME: assert the dep.z is in bounds |
| 1437 | BuildMI(BB, IA64::DEPZ, 3, Result).addReg(Tmp1) |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1438 | .addImm(0).addImm(Tmp3); |
| 1439 | break; |
Duraid Madina | 7340dd5 | 2005-08-21 15:43:53 +0000 | [diff] [blame] | 1440 | } |
| 1441 | return Result; // early exit |
| 1442 | } // fallthrough and emit a simple AND: |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1443 | Tmp2 = SelectExpr(N.getOperand(1)); |
| 1444 | BuildMI(BB, IA64::AND, 2, Result).addReg(Tmp1).addReg(Tmp2); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1445 | } |
| 1446 | } |
| 1447 | return Result; |
| 1448 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1449 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1450 | case ISD::OR: { |
| 1451 | switch (N.getValueType()) { |
| 1452 | default: assert(0 && "Cannot OR this type!"); |
| 1453 | case MVT::i1: { // if a bool, we emit a pseudocode OR |
| 1454 | unsigned pA = SelectExpr(N.getOperand(0)); |
| 1455 | unsigned pB = SelectExpr(N.getOperand(1)); |
| 1456 | |
| 1457 | unsigned pTemp1 = MakeReg(MVT::i1); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1458 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1459 | /* our pseudocode for OR is: |
| 1460 | * |
| 1461 | |
| 1462 | pC = pA OR pB |
| 1463 | ------------- |
| 1464 | |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1465 | (pA) cmp.eq.unc pC,p0 = r0,r0 // pC = pA |
| 1466 | ;; |
| 1467 | (pB) cmp.eq pC,p0 = r0,r0 // if (pB) pC = 1 |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1468 | |
| 1469 | */ |
| 1470 | BuildMI(BB, IA64::PCMPEQUNC, 3, pTemp1) |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1471 | .addReg(IA64::r0).addReg(IA64::r0).addReg(pA); |
Duraid Madina | f2db9b8 | 2005-10-28 17:46:35 +0000 | [diff] [blame] | 1472 | BuildMI(BB, IA64::TPCMPEQ, 4, Result) |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1473 | .addReg(pTemp1).addReg(IA64::r0).addReg(IA64::r0).addReg(pB); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1474 | break; |
| 1475 | } |
| 1476 | // if not a bool, we just OR away: |
| 1477 | case MVT::i8: |
| 1478 | case MVT::i16: |
| 1479 | case MVT::i32: |
| 1480 | case MVT::i64: { |
| 1481 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1482 | Tmp2 = SelectExpr(N.getOperand(1)); |
| 1483 | BuildMI(BB, IA64::OR, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 1484 | break; |
| 1485 | } |
| 1486 | } |
| 1487 | return Result; |
| 1488 | } |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1489 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1490 | case ISD::XOR: { |
| 1491 | switch (N.getValueType()) { |
| 1492 | default: assert(0 && "Cannot XOR this type!"); |
| 1493 | case MVT::i1: { // if a bool, we emit a pseudocode XOR |
| 1494 | unsigned pY = SelectExpr(N.getOperand(0)); |
| 1495 | unsigned pZ = SelectExpr(N.getOperand(1)); |
| 1496 | |
| 1497 | /* one possible routine for XOR is: |
| 1498 | |
| 1499 | // Compute px = py ^ pz |
| 1500 | // using sum of products: px = (py & !pz) | (pz & !py) |
| 1501 | // Uses 5 instructions in 3 cycles. |
| 1502 | // cycle 1 |
| 1503 | (pz) cmp.eq.unc px = r0, r0 // px = pz |
| 1504 | (py) cmp.eq.unc pt = r0, r0 // pt = py |
| 1505 | ;; |
| 1506 | // cycle 2 |
| 1507 | (pt) cmp.ne.and px = r0, r0 // px = px & !pt (px = pz & !pt) |
| 1508 | (pz) cmp.ne.and pt = r0, r0 // pt = pt & !pz |
| 1509 | ;; |
| 1510 | } { .mmi |
| 1511 | // cycle 3 |
| 1512 | (pt) cmp.eq.or px = r0, r0 // px = px | pt |
| 1513 | |
| 1514 | *** Another, which we use here, requires one scratch GR. it is: |
| 1515 | |
| 1516 | mov rt = 0 // initialize rt off critical path |
| 1517 | ;; |
| 1518 | |
| 1519 | // cycle 1 |
| 1520 | (pz) cmp.eq.unc px = r0, r0 // px = pz |
| 1521 | (pz) mov rt = 1 // rt = pz |
| 1522 | ;; |
| 1523 | // cycle 2 |
| 1524 | (py) cmp.ne px = 1, rt // if (py) px = !pz |
| 1525 | |
| 1526 | .. these routines kindly provided by Jim Hull |
| 1527 | */ |
| 1528 | unsigned rt = MakeReg(MVT::i64); |
| 1529 | |
| 1530 | // these two temporaries will never actually appear, |
| 1531 | // due to the two-address form of some of the instructions below |
| 1532 | unsigned bogoPR = MakeReg(MVT::i1); // becomes Result |
| 1533 | unsigned bogoGR = MakeReg(MVT::i64); // becomes rt |
| 1534 | |
| 1535 | BuildMI(BB, IA64::MOV, 1, bogoGR).addReg(IA64::r0); |
| 1536 | BuildMI(BB, IA64::PCMPEQUNC, 3, bogoPR) |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1537 | .addReg(IA64::r0).addReg(IA64::r0).addReg(pZ); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1538 | BuildMI(BB, IA64::TPCADDIMM22, 2, rt) |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1539 | .addReg(bogoGR).addImm(1).addReg(pZ); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1540 | BuildMI(BB, IA64::TPCMPIMM8NE, 3, Result) |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1541 | .addReg(bogoPR).addImm(1).addReg(rt).addReg(pY); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1542 | break; |
| 1543 | } |
| 1544 | // if not a bool, we just XOR away: |
| 1545 | case MVT::i8: |
| 1546 | case MVT::i16: |
| 1547 | case MVT::i32: |
| 1548 | case MVT::i64: { |
| 1549 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1550 | Tmp2 = SelectExpr(N.getOperand(1)); |
| 1551 | BuildMI(BB, IA64::XOR, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 1552 | break; |
| 1553 | } |
| 1554 | } |
| 1555 | return Result; |
| 1556 | } |
| 1557 | |
Duraid Madina | 63bbed5 | 2005-05-11 05:16:09 +0000 | [diff] [blame] | 1558 | case ISD::CTPOP: { |
| 1559 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1560 | BuildMI(BB, IA64::POPCNT, 1, Result).addReg(Tmp1); |
| 1561 | return Result; |
| 1562 | } |
| 1563 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1564 | case ISD::SHL: { |
| 1565 | Tmp1 = SelectExpr(N.getOperand(0)); |
Duraid Madina | f55e403 | 2005-04-07 12:33:38 +0000 | [diff] [blame] | 1566 | if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N.getOperand(1))) { |
| 1567 | Tmp2 = CN->getValue(); |
| 1568 | BuildMI(BB, IA64::SHLI, 2, Result).addReg(Tmp1).addImm(Tmp2); |
| 1569 | } else { |
| 1570 | Tmp2 = SelectExpr(N.getOperand(1)); |
| 1571 | BuildMI(BB, IA64::SHL, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 1572 | } |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1573 | return Result; |
| 1574 | } |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1575 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1576 | case ISD::SRL: { |
| 1577 | Tmp1 = SelectExpr(N.getOperand(0)); |
Duraid Madina | f55e403 | 2005-04-07 12:33:38 +0000 | [diff] [blame] | 1578 | if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N.getOperand(1))) { |
| 1579 | Tmp2 = CN->getValue(); |
| 1580 | BuildMI(BB, IA64::SHRUI, 2, Result).addReg(Tmp1).addImm(Tmp2); |
| 1581 | } else { |
| 1582 | Tmp2 = SelectExpr(N.getOperand(1)); |
| 1583 | BuildMI(BB, IA64::SHRU, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 1584 | } |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1585 | return Result; |
| 1586 | } |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1587 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1588 | case ISD::SRA: { |
| 1589 | Tmp1 = SelectExpr(N.getOperand(0)); |
Duraid Madina | f55e403 | 2005-04-07 12:33:38 +0000 | [diff] [blame] | 1590 | if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N.getOperand(1))) { |
| 1591 | Tmp2 = CN->getValue(); |
| 1592 | BuildMI(BB, IA64::SHRSI, 2, Result).addReg(Tmp1).addImm(Tmp2); |
| 1593 | } else { |
| 1594 | Tmp2 = SelectExpr(N.getOperand(1)); |
| 1595 | BuildMI(BB, IA64::SHRS, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 1596 | } |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1597 | return Result; |
| 1598 | } |
| 1599 | |
Chris Lattner | 3e2bafd | 2005-09-28 22:29:17 +0000 | [diff] [blame] | 1600 | case ISD::FDIV: |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1601 | case ISD::SDIV: |
| 1602 | case ISD::UDIV: |
| 1603 | case ISD::SREM: |
| 1604 | case ISD::UREM: { |
| 1605 | |
| 1606 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1607 | Tmp2 = SelectExpr(N.getOperand(1)); |
| 1608 | |
| 1609 | bool isFP=false; |
| 1610 | |
| 1611 | if(DestType == MVT::f64) // XXX: we're not gonna be fed MVT::f32, are we? |
| 1612 | isFP=true; |
| 1613 | |
| 1614 | bool isModulus=false; // is it a division or a modulus? |
| 1615 | bool isSigned=false; |
| 1616 | |
| 1617 | switch(N.getOpcode()) { |
Chris Lattner | 3e2bafd | 2005-09-28 22:29:17 +0000 | [diff] [blame] | 1618 | case ISD::FDIV: |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1619 | case ISD::SDIV: isModulus=false; isSigned=true; break; |
| 1620 | case ISD::UDIV: isModulus=false; isSigned=false; break; |
Chris Lattner | 3e2bafd | 2005-09-28 22:29:17 +0000 | [diff] [blame] | 1621 | case ISD::FREM: |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1622 | case ISD::SREM: isModulus=true; isSigned=true; break; |
| 1623 | case ISD::UREM: isModulus=true; isSigned=false; break; |
| 1624 | } |
| 1625 | |
Duraid Madina | 4826a07 | 2005-04-06 09:55:17 +0000 | [diff] [blame] | 1626 | if(!isModulus && !isFP) { // if this is an integer divide, |
| 1627 | switch (ponderIntegerDivisionBy(N.getOperand(1), isSigned, Tmp3)) { |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1628 | case 1: // division by a constant that's a power of 2 |
| 1629 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1630 | if(isSigned) { // argument could be negative, so emit some code: |
| 1631 | unsigned divAmt=Tmp3; |
| 1632 | unsigned tempGR1=MakeReg(MVT::i64); |
| 1633 | unsigned tempGR2=MakeReg(MVT::i64); |
| 1634 | unsigned tempGR3=MakeReg(MVT::i64); |
| 1635 | BuildMI(BB, IA64::SHRS, 2, tempGR1) |
| 1636 | .addReg(Tmp1).addImm(divAmt-1); |
| 1637 | BuildMI(BB, IA64::EXTRU, 3, tempGR2) |
| 1638 | .addReg(tempGR1).addImm(64-divAmt).addImm(divAmt); |
| 1639 | BuildMI(BB, IA64::ADD, 2, tempGR3) |
| 1640 | .addReg(Tmp1).addReg(tempGR2); |
| 1641 | BuildMI(BB, IA64::SHRS, 2, Result) |
| 1642 | .addReg(tempGR3).addImm(divAmt); |
| 1643 | } |
| 1644 | else // unsigned div-by-power-of-2 becomes a simple shift right: |
| 1645 | BuildMI(BB, IA64::SHRU, 2, Result).addReg(Tmp1).addImm(Tmp3); |
| 1646 | return Result; // early exit |
Duraid Madina | 4826a07 | 2005-04-06 09:55:17 +0000 | [diff] [blame] | 1647 | } |
| 1648 | } |
| 1649 | |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1650 | unsigned TmpPR=MakeReg(MVT::i1); // we need two scratch |
Duraid Madina | beeaab2 | 2005-03-31 12:31:11 +0000 | [diff] [blame] | 1651 | unsigned TmpPR2=MakeReg(MVT::i1); // predicate registers, |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1652 | unsigned TmpF1=MakeReg(MVT::f64); // and one metric truckload of FP regs. |
| 1653 | unsigned TmpF2=MakeReg(MVT::f64); // lucky we have IA64? |
| 1654 | unsigned TmpF3=MakeReg(MVT::f64); // well, the real FIXME is to have |
| 1655 | unsigned TmpF4=MakeReg(MVT::f64); // isTwoAddress forms of these |
| 1656 | unsigned TmpF5=MakeReg(MVT::f64); // FP instructions so we can end up with |
| 1657 | unsigned TmpF6=MakeReg(MVT::f64); // stuff like setf.sig f10=f10 etc. |
| 1658 | unsigned TmpF7=MakeReg(MVT::f64); |
| 1659 | unsigned TmpF8=MakeReg(MVT::f64); |
| 1660 | unsigned TmpF9=MakeReg(MVT::f64); |
| 1661 | unsigned TmpF10=MakeReg(MVT::f64); |
| 1662 | unsigned TmpF11=MakeReg(MVT::f64); |
| 1663 | unsigned TmpF12=MakeReg(MVT::f64); |
| 1664 | unsigned TmpF13=MakeReg(MVT::f64); |
| 1665 | unsigned TmpF14=MakeReg(MVT::f64); |
| 1666 | unsigned TmpF15=MakeReg(MVT::f64); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1667 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1668 | // OK, emit some code: |
| 1669 | |
| 1670 | if(!isFP) { |
| 1671 | // first, load the inputs into FP regs. |
| 1672 | BuildMI(BB, IA64::SETFSIG, 1, TmpF1).addReg(Tmp1); |
| 1673 | BuildMI(BB, IA64::SETFSIG, 1, TmpF2).addReg(Tmp2); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1674 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1675 | // next, convert the inputs to FP |
| 1676 | if(isSigned) { |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1677 | BuildMI(BB, IA64::FCVTXF, 1, TmpF3).addReg(TmpF1); |
| 1678 | BuildMI(BB, IA64::FCVTXF, 1, TmpF4).addReg(TmpF2); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1679 | } else { |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1680 | BuildMI(BB, IA64::FCVTXUFS1, 1, TmpF3).addReg(TmpF1); |
| 1681 | BuildMI(BB, IA64::FCVTXUFS1, 1, TmpF4).addReg(TmpF2); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1682 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1683 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1684 | } else { // this is an FP divide/remainder, so we 'leak' some temp |
| 1685 | // regs and assign TmpF3=Tmp1, TmpF4=Tmp2 |
| 1686 | TmpF3=Tmp1; |
| 1687 | TmpF4=Tmp2; |
| 1688 | } |
| 1689 | |
| 1690 | // we start by computing an approximate reciprocal (good to 9 bits?) |
Duraid Madina | 6dcceb5 | 2005-04-08 10:01:48 +0000 | [diff] [blame] | 1691 | // note, this instruction writes _both_ TmpF5 (answer) and TmpPR (predicate) |
| 1692 | BuildMI(BB, IA64::FRCPAS1, 4) |
| 1693 | .addReg(TmpF5, MachineOperand::Def) |
| 1694 | .addReg(TmpPR, MachineOperand::Def) |
| 1695 | .addReg(TmpF3).addReg(TmpF4); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1696 | |
Duraid Madina | beeaab2 | 2005-03-31 12:31:11 +0000 | [diff] [blame] | 1697 | if(!isModulus) { // if this is a divide, we worry about div-by-zero |
| 1698 | unsigned bogusPR=MakeReg(MVT::i1); // won't appear, due to twoAddress |
| 1699 | // TPCMPNE below |
| 1700 | BuildMI(BB, IA64::CMPEQ, 2, bogusPR).addReg(IA64::r0).addReg(IA64::r0); |
| 1701 | BuildMI(BB, IA64::TPCMPNE, 3, TmpPR2).addReg(bogusPR) |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1702 | .addReg(IA64::r0).addReg(IA64::r0).addReg(TmpPR); |
Duraid Madina | beeaab2 | 2005-03-31 12:31:11 +0000 | [diff] [blame] | 1703 | } |
| 1704 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1705 | // now we apply newton's method, thrice! (FIXME: this is ~72 bits of |
| 1706 | // precision, don't need this much for f32/i32) |
| 1707 | BuildMI(BB, IA64::CFNMAS1, 4, TmpF6) |
| 1708 | .addReg(TmpF4).addReg(TmpF5).addReg(IA64::F1).addReg(TmpPR); |
| 1709 | BuildMI(BB, IA64::CFMAS1, 4, TmpF7) |
| 1710 | .addReg(TmpF3).addReg(TmpF5).addReg(IA64::F0).addReg(TmpPR); |
| 1711 | BuildMI(BB, IA64::CFMAS1, 4, TmpF8) |
| 1712 | .addReg(TmpF6).addReg(TmpF6).addReg(IA64::F0).addReg(TmpPR); |
| 1713 | BuildMI(BB, IA64::CFMAS1, 4, TmpF9) |
| 1714 | .addReg(TmpF6).addReg(TmpF7).addReg(TmpF7).addReg(TmpPR); |
| 1715 | BuildMI(BB, IA64::CFMAS1, 4,TmpF10) |
| 1716 | .addReg(TmpF6).addReg(TmpF5).addReg(TmpF5).addReg(TmpPR); |
| 1717 | BuildMI(BB, IA64::CFMAS1, 4,TmpF11) |
| 1718 | .addReg(TmpF8).addReg(TmpF9).addReg(TmpF9).addReg(TmpPR); |
| 1719 | BuildMI(BB, IA64::CFMAS1, 4,TmpF12) |
| 1720 | .addReg(TmpF8).addReg(TmpF10).addReg(TmpF10).addReg(TmpPR); |
| 1721 | BuildMI(BB, IA64::CFNMAS1, 4,TmpF13) |
| 1722 | .addReg(TmpF4).addReg(TmpF11).addReg(TmpF3).addReg(TmpPR); |
Duraid Madina | 6e02e68 | 2005-04-04 05:05:52 +0000 | [diff] [blame] | 1723 | |
| 1724 | // FIXME: this is unfortunate :( |
| 1725 | // the story is that the dest reg of the fnma above and the fma below |
| 1726 | // (and therefore possibly the src of the fcvt.fx[u] as well) cannot |
| 1727 | // be the same register, or this code breaks if the first argument is |
| 1728 | // zero. (e.g. without this hack, 0%8 yields -64, not 0.) |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1729 | BuildMI(BB, IA64::CFMAS1, 4,TmpF14) |
| 1730 | .addReg(TmpF13).addReg(TmpF12).addReg(TmpF11).addReg(TmpPR); |
| 1731 | |
Duraid Madina | 6e02e68 | 2005-04-04 05:05:52 +0000 | [diff] [blame] | 1732 | if(isModulus) { // XXX: fragile! fixes _only_ mod, *breaks* div! ! |
| 1733 | BuildMI(BB, IA64::IUSE, 1).addReg(TmpF13); // hack :( |
| 1734 | } |
| 1735 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1736 | if(!isFP) { |
| 1737 | // round to an integer |
| 1738 | if(isSigned) |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1739 | BuildMI(BB, IA64::FCVTFXTRUNCS1, 1, TmpF15).addReg(TmpF14); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1740 | else |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1741 | BuildMI(BB, IA64::FCVTFXUTRUNCS1, 1, TmpF15).addReg(TmpF14); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1742 | } else { |
| 1743 | BuildMI(BB, IA64::FMOV, 1, TmpF15).addReg(TmpF14); |
| 1744 | // EXERCISE: can you see why TmpF15=TmpF14 does not work here, and |
| 1745 | // we really do need the above FMOV? ;) |
| 1746 | } |
| 1747 | |
| 1748 | if(!isModulus) { |
Duraid Madina | beeaab2 | 2005-03-31 12:31:11 +0000 | [diff] [blame] | 1749 | if(isFP) { // extra worrying about div-by-zero |
| 1750 | unsigned bogoResult=MakeReg(MVT::f64); |
| 1751 | |
| 1752 | // we do a 'conditional fmov' (of the correct result, depending |
| 1753 | // on how the frcpa predicate turned out) |
| 1754 | BuildMI(BB, IA64::PFMOV, 2, bogoResult) |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1755 | .addReg(TmpF12).addReg(TmpPR2); |
Duraid Madina | beeaab2 | 2005-03-31 12:31:11 +0000 | [diff] [blame] | 1756 | BuildMI(BB, IA64::CFMOV, 2, Result) |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1757 | .addReg(bogoResult).addReg(TmpF15).addReg(TmpPR); |
Duraid Madina | beeaab2 | 2005-03-31 12:31:11 +0000 | [diff] [blame] | 1758 | } |
Duraid Madina | 6e02e68 | 2005-04-04 05:05:52 +0000 | [diff] [blame] | 1759 | else { |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1760 | BuildMI(BB, IA64::GETFSIG, 1, Result).addReg(TmpF15); |
Duraid Madina | 6e02e68 | 2005-04-04 05:05:52 +0000 | [diff] [blame] | 1761 | } |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1762 | } else { // this is a modulus |
| 1763 | if(!isFP) { |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1764 | // answer = q * (-b) + a |
| 1765 | unsigned ModulusResult = MakeReg(MVT::f64); |
| 1766 | unsigned TmpF = MakeReg(MVT::f64); |
| 1767 | unsigned TmpI = MakeReg(MVT::i64); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 1768 | |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1769 | BuildMI(BB, IA64::SUB, 2, TmpI).addReg(IA64::r0).addReg(Tmp2); |
| 1770 | BuildMI(BB, IA64::SETFSIG, 1, TmpF).addReg(TmpI); |
| 1771 | BuildMI(BB, IA64::XMAL, 3, ModulusResult) |
| 1772 | .addReg(TmpF15).addReg(TmpF).addReg(TmpF1); |
| 1773 | BuildMI(BB, IA64::GETFSIG, 1, Result).addReg(ModulusResult); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1774 | } else { // FP modulus! The horror... the horror.... |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1775 | assert(0 && "sorry, no FP modulus just yet!\n!\n"); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1776 | } |
| 1777 | } |
| 1778 | |
| 1779 | return Result; |
| 1780 | } |
| 1781 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1782 | case ISD::SIGN_EXTEND_INREG: { |
| 1783 | Tmp1 = SelectExpr(N.getOperand(0)); |
Chris Lattner | bce81ae | 2005-07-10 01:56:13 +0000 | [diff] [blame] | 1784 | switch(cast<VTSDNode>(Node->getOperand(1))->getVT()) { |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1785 | default: |
| 1786 | Node->dump(); |
| 1787 | assert(0 && "don't know how to sign extend this type"); |
| 1788 | break; |
| 1789 | case MVT::i8: Opc = IA64::SXT1; break; |
| 1790 | case MVT::i16: Opc = IA64::SXT2; break; |
| 1791 | case MVT::i32: Opc = IA64::SXT4; break; |
| 1792 | } |
| 1793 | BuildMI(BB, Opc, 1, Result).addReg(Tmp1); |
| 1794 | return Result; |
| 1795 | } |
| 1796 | |
| 1797 | case ISD::SETCC: { |
| 1798 | Tmp1 = SelectExpr(N.getOperand(0)); |
Chris Lattner | 88ac32c | 2005-08-09 20:21:10 +0000 | [diff] [blame] | 1799 | ISD::CondCode CC = cast<CondCodeSDNode>(Node->getOperand(2))->get(); |
| 1800 | if (MVT::isInteger(N.getOperand(0).getValueType())) { |
Duraid Madina | 5ef2ec9 | 2005-04-11 05:55:56 +0000 | [diff] [blame] | 1801 | |
Chris Lattner | 88ac32c | 2005-08-09 20:21:10 +0000 | [diff] [blame] | 1802 | if(ConstantSDNode *CSDN = |
| 1803 | dyn_cast<ConstantSDNode>(N.getOperand(1))) { |
| 1804 | // if we are comparing against a constant zero |
| 1805 | if(CSDN->getValue()==0) |
| 1806 | Tmp2 = IA64::r0; // then we can just compare against r0 |
| 1807 | else |
| 1808 | Tmp2 = SelectExpr(N.getOperand(1)); |
| 1809 | } else // not comparing against a constant |
| 1810 | Tmp2 = SelectExpr(N.getOperand(1)); |
Duraid Madina | 5ef2ec9 | 2005-04-11 05:55:56 +0000 | [diff] [blame] | 1811 | |
Chris Lattner | 88ac32c | 2005-08-09 20:21:10 +0000 | [diff] [blame] | 1812 | switch (CC) { |
| 1813 | default: assert(0 && "Unknown integer comparison!"); |
| 1814 | case ISD::SETEQ: |
| 1815 | BuildMI(BB, IA64::CMPEQ, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 1816 | break; |
| 1817 | case ISD::SETGT: |
| 1818 | BuildMI(BB, IA64::CMPGT, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 1819 | break; |
| 1820 | case ISD::SETGE: |
| 1821 | BuildMI(BB, IA64::CMPGE, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 1822 | break; |
| 1823 | case ISD::SETLT: |
| 1824 | BuildMI(BB, IA64::CMPLT, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 1825 | break; |
| 1826 | case ISD::SETLE: |
| 1827 | BuildMI(BB, IA64::CMPLE, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 1828 | break; |
| 1829 | case ISD::SETNE: |
| 1830 | BuildMI(BB, IA64::CMPNE, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 1831 | break; |
| 1832 | case ISD::SETULT: |
| 1833 | BuildMI(BB, IA64::CMPLTU, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 1834 | break; |
| 1835 | case ISD::SETUGT: |
| 1836 | BuildMI(BB, IA64::CMPGTU, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 1837 | break; |
| 1838 | case ISD::SETULE: |
| 1839 | BuildMI(BB, IA64::CMPLEU, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 1840 | break; |
| 1841 | case ISD::SETUGE: |
| 1842 | BuildMI(BB, IA64::CMPGEU, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 1843 | break; |
| 1844 | } |
| 1845 | } else { // if not integer, should be FP. |
| 1846 | assert(N.getOperand(0).getValueType() != MVT::f32 && |
| 1847 | "error: SETCC should have had incoming f32 promoted to f64!\n"); |
| 1848 | |
| 1849 | if(ConstantFPSDNode *CFPSDN = |
| 1850 | dyn_cast<ConstantFPSDNode>(N.getOperand(1))) { |
| 1851 | |
| 1852 | // if we are comparing against a constant +0.0 or +1.0 |
| 1853 | if(CFPSDN->isExactlyValue(+0.0)) |
| 1854 | Tmp2 = IA64::F0; // then we can just compare against f0 |
| 1855 | else if(CFPSDN->isExactlyValue(+1.0)) |
| 1856 | Tmp2 = IA64::F1; // or f1 |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1857 | else |
| 1858 | Tmp2 = SelectExpr(N.getOperand(1)); |
Chris Lattner | 88ac32c | 2005-08-09 20:21:10 +0000 | [diff] [blame] | 1859 | } else // not comparing against a constant |
| 1860 | Tmp2 = SelectExpr(N.getOperand(1)); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 1861 | |
Chris Lattner | 88ac32c | 2005-08-09 20:21:10 +0000 | [diff] [blame] | 1862 | switch (CC) { |
| 1863 | default: assert(0 && "Unknown FP comparison!"); |
| 1864 | case ISD::SETEQ: |
| 1865 | BuildMI(BB, IA64::FCMPEQ, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 1866 | break; |
| 1867 | case ISD::SETGT: |
| 1868 | BuildMI(BB, IA64::FCMPGT, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 1869 | break; |
| 1870 | case ISD::SETGE: |
| 1871 | BuildMI(BB, IA64::FCMPGE, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 1872 | break; |
| 1873 | case ISD::SETLT: |
| 1874 | BuildMI(BB, IA64::FCMPLT, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 1875 | break; |
| 1876 | case ISD::SETLE: |
| 1877 | BuildMI(BB, IA64::FCMPLE, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 1878 | break; |
| 1879 | case ISD::SETNE: |
| 1880 | BuildMI(BB, IA64::FCMPNE, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 1881 | break; |
| 1882 | case ISD::SETULT: |
| 1883 | BuildMI(BB, IA64::FCMPLTU, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 1884 | break; |
| 1885 | case ISD::SETUGT: |
| 1886 | BuildMI(BB, IA64::FCMPGTU, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 1887 | break; |
| 1888 | case ISD::SETULE: |
| 1889 | BuildMI(BB, IA64::FCMPLEU, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 1890 | break; |
| 1891 | case ISD::SETUGE: |
| 1892 | BuildMI(BB, IA64::FCMPGEU, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 1893 | break; |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1894 | } |
| 1895 | } |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1896 | return Result; |
| 1897 | } |
| 1898 | |
| 1899 | case ISD::EXTLOAD: |
| 1900 | case ISD::ZEXTLOAD: |
| 1901 | case ISD::LOAD: { |
| 1902 | // Make sure we generate both values. |
| 1903 | if (Result != 1) |
| 1904 | ExprMap[N.getValue(1)] = 1; // Generate the token |
| 1905 | else |
| 1906 | Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType()); |
| 1907 | |
| 1908 | bool isBool=false; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1909 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1910 | if(opcode == ISD::LOAD) { // this is a LOAD |
| 1911 | switch (Node->getValueType(0)) { |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1912 | default: assert(0 && "Cannot load this type!"); |
| 1913 | case MVT::i1: Opc = IA64::LD1; isBool=true; break; |
| 1914 | // FIXME: for now, we treat bool loads the same as i8 loads */ |
| 1915 | case MVT::i8: Opc = IA64::LD1; break; |
| 1916 | case MVT::i16: Opc = IA64::LD2; break; |
| 1917 | case MVT::i32: Opc = IA64::LD4; break; |
| 1918 | case MVT::i64: Opc = IA64::LD8; break; |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 1919 | |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1920 | case MVT::f32: Opc = IA64::LDF4; break; |
| 1921 | case MVT::f64: Opc = IA64::LDF8; break; |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1922 | } |
| 1923 | } else { // this is an EXTLOAD or ZEXTLOAD |
Chris Lattner | bce81ae | 2005-07-10 01:56:13 +0000 | [diff] [blame] | 1924 | MVT::ValueType TypeBeingLoaded = |
| 1925 | cast<VTSDNode>(Node->getOperand(3))->getVT(); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1926 | switch (TypeBeingLoaded) { |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1927 | default: assert(0 && "Cannot extload/zextload this type!"); |
| 1928 | // FIXME: bools? |
| 1929 | case MVT::i8: Opc = IA64::LD1; break; |
| 1930 | case MVT::i16: Opc = IA64::LD2; break; |
| 1931 | case MVT::i32: Opc = IA64::LD4; break; |
| 1932 | case MVT::f32: Opc = IA64::LDF4; break; |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1933 | } |
| 1934 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1935 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1936 | SDOperand Chain = N.getOperand(0); |
| 1937 | SDOperand Address = N.getOperand(1); |
| 1938 | |
| 1939 | if(Address.getOpcode() == ISD::GlobalAddress) { |
| 1940 | Select(Chain); |
| 1941 | unsigned dummy = MakeReg(MVT::i64); |
| 1942 | unsigned dummy2 = MakeReg(MVT::i64); |
| 1943 | BuildMI(BB, IA64::ADD, 2, dummy) |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1944 | .addGlobalAddress(cast<GlobalAddressSDNode>(Address)->getGlobal()) |
| 1945 | .addReg(IA64::r1); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1946 | BuildMI(BB, IA64::LD8, 1, dummy2).addReg(dummy); |
| 1947 | if(!isBool) |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1948 | BuildMI(BB, Opc, 1, Result).addReg(dummy2); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1949 | else { // emit a little pseudocode to load a bool (stored in one byte) |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1950 | // into a predicate register |
| 1951 | assert(Opc==IA64::LD1 && "problem loading a bool"); |
| 1952 | unsigned dummy3 = MakeReg(MVT::i64); |
| 1953 | BuildMI(BB, Opc, 1, dummy3).addReg(dummy2); |
| 1954 | // we compare to 0. true? 0. false? 1. |
| 1955 | BuildMI(BB, IA64::CMPNE, 2, Result).addReg(dummy3).addReg(IA64::r0); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1956 | } |
| 1957 | } else if(ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(Address)) { |
Chris Lattner | 5839bf2 | 2005-08-26 17:15:30 +0000 | [diff] [blame] | 1958 | unsigned CPIdx = BB->getParent()->getConstantPool()-> |
Chris Lattner | 143b675 | 2005-08-26 17:18:44 +0000 | [diff] [blame] | 1959 | getConstantPoolIndex(CP->get()); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1960 | Select(Chain); |
| 1961 | IA64Lowering.restoreGP(BB); |
| 1962 | unsigned dummy = MakeReg(MVT::i64); |
Duraid Madina | f2db9b8 | 2005-10-28 17:46:35 +0000 | [diff] [blame] | 1963 | unsigned dummy2 = MakeReg(MVT::i64); |
| 1964 | BuildMI(BB, IA64::MOVLIMM64, 1, dummy2).addConstantPoolIndex(CPIdx); |
| 1965 | BuildMI(BB, IA64::ADD, 2, dummy).addReg(dummy2).addReg(IA64::r1); //CPI+GP |
| 1966 | |
| 1967 | |
| 1968 | // OLD BuildMI(BB, IA64::ADD, 2, dummy).addConstantPoolIndex(CPIdx) |
| 1969 | // (FIXME!) .addReg(IA64::r1); // CPI+GP |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1970 | if(!isBool) |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1971 | BuildMI(BB, Opc, 1, Result).addReg(dummy); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1972 | else { // emit a little pseudocode to load a bool (stored in one byte) |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1973 | // into a predicate register |
| 1974 | assert(Opc==IA64::LD1 && "problem loading a bool"); |
| 1975 | unsigned dummy3 = MakeReg(MVT::i64); |
| 1976 | BuildMI(BB, Opc, 1, dummy3).addReg(dummy); |
| 1977 | // we compare to 0. true? 0. false? 1. |
| 1978 | BuildMI(BB, IA64::CMPNE, 2, Result).addReg(dummy3).addReg(IA64::r0); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1979 | } |
| 1980 | } else if(Address.getOpcode() == ISD::FrameIndex) { |
| 1981 | Select(Chain); // FIXME ? what about bools? |
| 1982 | unsigned dummy = MakeReg(MVT::i64); |
| 1983 | BuildMI(BB, IA64::MOV, 1, dummy) |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1984 | .addFrameIndex(cast<FrameIndexSDNode>(Address)->getIndex()); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1985 | if(!isBool) |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1986 | BuildMI(BB, Opc, 1, Result).addReg(dummy); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1987 | else { // emit a little pseudocode to load a bool (stored in one byte) |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1988 | // into a predicate register |
| 1989 | assert(Opc==IA64::LD1 && "problem loading a bool"); |
| 1990 | unsigned dummy3 = MakeReg(MVT::i64); |
| 1991 | BuildMI(BB, Opc, 1, dummy3).addReg(dummy); |
| 1992 | // we compare to 0. true? 0. false? 1. |
| 1993 | BuildMI(BB, IA64::CMPNE, 2, Result).addReg(dummy3).addReg(IA64::r0); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1994 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1995 | } else { // none of the above... |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1996 | Select(Chain); |
| 1997 | Tmp2 = SelectExpr(Address); |
| 1998 | if(!isBool) |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1999 | BuildMI(BB, Opc, 1, Result).addReg(Tmp2); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2000 | else { // emit a little pseudocode to load a bool (stored in one byte) |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 2001 | // into a predicate register |
| 2002 | assert(Opc==IA64::LD1 && "problem loading a bool"); |
| 2003 | unsigned dummy = MakeReg(MVT::i64); |
| 2004 | BuildMI(BB, Opc, 1, dummy).addReg(Tmp2); |
| 2005 | // we compare to 0. true? 0. false? 1. |
| 2006 | BuildMI(BB, IA64::CMPNE, 2, Result).addReg(dummy).addReg(IA64::r0); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 2007 | } |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2008 | } |
| 2009 | |
| 2010 | return Result; |
| 2011 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2012 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2013 | case ISD::CopyFromReg: { |
| 2014 | if (Result == 1) |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2015 | Result = ExprMap[N.getValue(0)] = |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 2016 | MakeReg(N.getValue(0).getValueType()); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2017 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2018 | SDOperand Chain = N.getOperand(0); |
| 2019 | |
| 2020 | Select(Chain); |
Chris Lattner | 707ebc5 | 2005-08-16 21:56:37 +0000 | [diff] [blame] | 2021 | unsigned r = cast<RegisterSDNode>(Node->getOperand(1))->getReg(); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2022 | |
| 2023 | if(N.getValueType() == MVT::i1) // if a bool, we use pseudocode |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 2024 | BuildMI(BB, IA64::PCMPEQUNC, 3, Result) |
| 2025 | .addReg(IA64::r0).addReg(IA64::r0).addReg(r); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2026 | // (r) Result =cmp.eq.unc(r0,r0) |
| 2027 | else |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 2028 | BuildMI(BB, IA64::MOV, 1, Result).addReg(r); // otherwise MOV |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2029 | return Result; |
| 2030 | } |
| 2031 | |
Chris Lattner | b5d8e6e | 2005-05-13 20:29:26 +0000 | [diff] [blame] | 2032 | case ISD::TAILCALL: |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2033 | case ISD::CALL: { |
| 2034 | Select(N.getOperand(0)); |
| 2035 | |
| 2036 | // The chain for this call is now lowered. |
| 2037 | ExprMap.insert(std::make_pair(N.getValue(Node->getNumValues()-1), 1)); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2038 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2039 | //grab the arguments |
| 2040 | std::vector<unsigned> argvregs; |
| 2041 | |
| 2042 | for(int i = 2, e = Node->getNumOperands(); i < e; ++i) |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 2043 | argvregs.push_back(SelectExpr(N.getOperand(i))); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2044 | |
| 2045 | // see section 8.5.8 of "Itanium Software Conventions and |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2046 | // Runtime Architecture Guide to see some examples of what's going |
| 2047 | // on here. (in short: int args get mapped 1:1 'slot-wise' to out0->out7, |
| 2048 | // while FP args get mapped to F8->F15 as needed) |
| 2049 | |
| 2050 | unsigned used_FPArgs=0; // how many FP Args have been used so far? |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2051 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2052 | // in reg args |
| 2053 | for(int i = 0, e = std::min(8, (int)argvregs.size()); i < e; ++i) |
| 2054 | { |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 2055 | unsigned intArgs[] = {IA64::out0, IA64::out1, IA64::out2, IA64::out3, |
| 2056 | IA64::out4, IA64::out5, IA64::out6, IA64::out7 }; |
| 2057 | unsigned FPArgs[] = {IA64::F8, IA64::F9, IA64::F10, IA64::F11, |
| 2058 | IA64::F12, IA64::F13, IA64::F14, IA64::F15 }; |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2059 | |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 2060 | switch(N.getOperand(i+2).getValueType()) |
| 2061 | { |
| 2062 | default: // XXX do we need to support MVT::i1 here? |
| 2063 | Node->dump(); |
| 2064 | N.getOperand(i).Val->dump(); |
| 2065 | std::cerr << "Type for " << i << " is: " << |
| 2066 | N.getOperand(i+2).getValueType() << std::endl; |
| 2067 | assert(0 && "Unknown value type for call"); |
| 2068 | case MVT::i64: |
| 2069 | BuildMI(BB, IA64::MOV, 1, intArgs[i]).addReg(argvregs[i]); |
| 2070 | break; |
| 2071 | case MVT::f64: |
| 2072 | BuildMI(BB, IA64::FMOV, 1, FPArgs[used_FPArgs++]) |
| 2073 | .addReg(argvregs[i]); |
| 2074 | // FIXME: we don't need to do this _all_ the time: |
| 2075 | BuildMI(BB, IA64::GETFD, 1, intArgs[i]).addReg(argvregs[i]); |
| 2076 | break; |
| 2077 | } |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2078 | } |
| 2079 | |
| 2080 | //in mem args |
| 2081 | for (int i = 8, e = argvregs.size(); i < e; ++i) |
| 2082 | { |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 2083 | unsigned tempAddr = MakeReg(MVT::i64); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 2084 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2085 | switch(N.getOperand(i+2).getValueType()) { |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2086 | default: |
| 2087 | Node->dump(); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2088 | N.getOperand(i).Val->dump(); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2089 | std::cerr << "Type for " << i << " is: " << |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2090 | N.getOperand(i+2).getValueType() << "\n"; |
| 2091 | assert(0 && "Unknown value type for call"); |
| 2092 | case MVT::i1: // FIXME? |
| 2093 | case MVT::i8: |
| 2094 | case MVT::i16: |
| 2095 | case MVT::i32: |
| 2096 | case MVT::i64: |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 2097 | BuildMI(BB, IA64::ADDIMM22, 2, tempAddr) |
| 2098 | .addReg(IA64::r12).addImm(16 + (i - 8) * 8); // r12 is SP |
| 2099 | BuildMI(BB, IA64::ST8, 2).addReg(tempAddr).addReg(argvregs[i]); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2100 | break; |
| 2101 | case MVT::f32: |
| 2102 | case MVT::f64: |
| 2103 | BuildMI(BB, IA64::ADDIMM22, 2, tempAddr) |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 2104 | .addReg(IA64::r12).addImm(16 + (i - 8) * 8); // r12 is SP |
| 2105 | BuildMI(BB, IA64::STF8, 2).addReg(tempAddr).addReg(argvregs[i]); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2106 | break; |
| 2107 | } |
| 2108 | } |
Duraid Madina | beeaab2 | 2005-03-31 12:31:11 +0000 | [diff] [blame] | 2109 | |
Duraid Madina | 04aa46d | 2005-05-20 11:39:17 +0000 | [diff] [blame] | 2110 | // build the right kind of call. if we can branch directly, do so: |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2111 | if (GlobalAddressSDNode *GASD = |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2112 | dyn_cast<GlobalAddressSDNode>(N.getOperand(1))) |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2113 | { |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 2114 | BuildMI(BB, IA64::BRCALL, 1).addGlobalAddress(GASD->getGlobal(),true); |
| 2115 | IA64Lowering.restoreGP_SP_RP(BB); |
Duraid Madina | 04aa46d | 2005-05-20 11:39:17 +0000 | [diff] [blame] | 2116 | } else |
Duraid Madina | beeaab2 | 2005-03-31 12:31:11 +0000 | [diff] [blame] | 2117 | if (ExternalSymbolSDNode *ESSDN = |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 2118 | dyn_cast<ExternalSymbolSDNode>(N.getOperand(1))) |
Duraid Madina | beeaab2 | 2005-03-31 12:31:11 +0000 | [diff] [blame] | 2119 | { // FIXME : currently need this case for correctness, to avoid |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 2120 | // "non-pic code with imm relocation against dynamic symbol" errors |
| 2121 | BuildMI(BB, IA64::BRCALL, 1) |
| 2122 | .addExternalSymbol(ESSDN->getSymbol(), true); |
| 2123 | IA64Lowering.restoreGP_SP_RP(BB); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2124 | } |
Duraid Madina | 04aa46d | 2005-05-20 11:39:17 +0000 | [diff] [blame] | 2125 | else { // otherwise we need to get the function descriptor |
| 2126 | // load the branch target (function)'s entry point and |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 2127 | // GP, then branch |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2128 | Tmp1 = SelectExpr(N.getOperand(1)); |
Duraid Madina | beeaab2 | 2005-03-31 12:31:11 +0000 | [diff] [blame] | 2129 | |
| 2130 | unsigned targetEntryPoint=MakeReg(MVT::i64); |
| 2131 | unsigned targetGPAddr=MakeReg(MVT::i64); |
| 2132 | unsigned currentGP=MakeReg(MVT::i64); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2133 | |
Duraid Madina | beeaab2 | 2005-03-31 12:31:11 +0000 | [diff] [blame] | 2134 | // b6 is a scratch branch register, we load the target entry point |
| 2135 | // from the base of the function descriptor |
| 2136 | BuildMI(BB, IA64::LD8, 1, targetEntryPoint).addReg(Tmp1); |
| 2137 | BuildMI(BB, IA64::MOV, 1, IA64::B6).addReg(targetEntryPoint); |
| 2138 | |
| 2139 | // save the current GP: |
| 2140 | BuildMI(BB, IA64::MOV, 1, currentGP).addReg(IA64::r1); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2141 | |
Duraid Madina | beeaab2 | 2005-03-31 12:31:11 +0000 | [diff] [blame] | 2142 | /* TODO: we need to make sure doing this never, ever loads a |
| 2143 | * bogus value into r1 (GP). */ |
| 2144 | // load the target GP (which is at mem[functiondescriptor+8]) |
| 2145 | BuildMI(BB, IA64::ADDIMM22, 2, targetGPAddr) |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 2146 | .addReg(Tmp1).addImm(8); // FIXME: addimm22? why not postincrement ld |
Duraid Madina | beeaab2 | 2005-03-31 12:31:11 +0000 | [diff] [blame] | 2147 | BuildMI(BB, IA64::LD8, 1, IA64::r1).addReg(targetGPAddr); |
| 2148 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2149 | // and then jump: (well, call) |
| 2150 | BuildMI(BB, IA64::BRCALL, 1).addReg(IA64::B6); |
Duraid Madina | beeaab2 | 2005-03-31 12:31:11 +0000 | [diff] [blame] | 2151 | // and finally restore the old GP |
| 2152 | BuildMI(BB, IA64::MOV, 1, IA64::r1).addReg(currentGP); |
| 2153 | IA64Lowering.restoreSP_RP(BB); |
| 2154 | } |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2155 | |
| 2156 | switch (Node->getValueType(0)) { |
| 2157 | default: assert(0 && "Unknown value type for call result!"); |
| 2158 | case MVT::Other: return 1; |
| 2159 | case MVT::i1: |
| 2160 | BuildMI(BB, IA64::CMPNE, 2, Result) |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 2161 | .addReg(IA64::r8).addReg(IA64::r0); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2162 | break; |
| 2163 | case MVT::i8: |
| 2164 | case MVT::i16: |
| 2165 | case MVT::i32: |
| 2166 | case MVT::i64: |
| 2167 | BuildMI(BB, IA64::MOV, 1, Result).addReg(IA64::r8); |
| 2168 | break; |
| 2169 | case MVT::f64: |
| 2170 | BuildMI(BB, IA64::FMOV, 1, Result).addReg(IA64::F8); |
| 2171 | break; |
| 2172 | } |
| 2173 | return Result+N.ResNo; |
| 2174 | } |
| 2175 | |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2176 | } // <- uhhh XXX |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2177 | return 0; |
| 2178 | } |
| 2179 | |
| 2180 | void ISel::Select(SDOperand N) { |
| 2181 | unsigned Tmp1, Tmp2, Opc; |
| 2182 | unsigned opcode = N.getOpcode(); |
| 2183 | |
Nate Begeman | 85fdeb2 | 2005-03-24 04:39:54 +0000 | [diff] [blame] | 2184 | if (!LoweredTokens.insert(N).second) |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2185 | return; // Already selected. |
| 2186 | |
| 2187 | SDNode *Node = N.Val; |
| 2188 | |
| 2189 | switch (Node->getOpcode()) { |
| 2190 | default: |
| 2191 | Node->dump(); std::cerr << "\n"; |
| 2192 | assert(0 && "Node not handled yet!"); |
| 2193 | |
| 2194 | case ISD::EntryToken: return; // Noop |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2195 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2196 | case ISD::TokenFactor: { |
| 2197 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) |
| 2198 | Select(Node->getOperand(i)); |
| 2199 | return; |
| 2200 | } |
| 2201 | |
| 2202 | case ISD::CopyToReg: { |
| 2203 | Select(N.getOperand(0)); |
Chris Lattner | 707ebc5 | 2005-08-16 21:56:37 +0000 | [diff] [blame] | 2204 | Tmp1 = SelectExpr(N.getOperand(2)); |
| 2205 | Tmp2 = cast<RegisterSDNode>(N.getOperand(1))->getReg(); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2206 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2207 | if (Tmp1 != Tmp2) { |
Chris Lattner | 707ebc5 | 2005-08-16 21:56:37 +0000 | [diff] [blame] | 2208 | // if a bool, we use pseudocode |
| 2209 | if (N.getOperand(2).getValueType() == MVT::i1) |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 2210 | BuildMI(BB, IA64::PCMPEQUNC, 3, Tmp2) |
| 2211 | .addReg(IA64::r0).addReg(IA64::r0).addReg(Tmp1); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2212 | // (Tmp1) Tmp2 = cmp.eq.unc(r0,r0) |
| 2213 | else |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 2214 | BuildMI(BB, IA64::MOV, 1, Tmp2).addReg(Tmp1); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2215 | // XXX is this the right way 'round? ;) |
Chris Lattner | 707ebc5 | 2005-08-16 21:56:37 +0000 | [diff] [blame] | 2216 | // FIXME: WHAT ABOUT FLOATING POINT? |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2217 | } |
| 2218 | return; |
| 2219 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2220 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2221 | case ISD::RET: { |
| 2222 | |
| 2223 | /* what the heck is going on here: |
| 2224 | |
| 2225 | <_sabre_> ret with two operands is obvious: chain and value |
| 2226 | <camel_> yep |
| 2227 | <_sabre_> ret with 3 values happens when 'expansion' occurs |
| 2228 | <_sabre_> e.g. i64 gets split into 2x i32 |
| 2229 | <camel_> oh right |
| 2230 | <_sabre_> you don't have this case on ia64 |
| 2231 | <camel_> yep |
| 2232 | <_sabre_> so the two returned values go into EAX/EDX on ia32 |
| 2233 | <camel_> ahhh *memories* |
| 2234 | <_sabre_> :) |
| 2235 | <camel_> ok, thanks :) |
| 2236 | <_sabre_> so yeah, everything that has a side effect takes a 'token chain' |
| 2237 | <_sabre_> this is the first operand always |
| 2238 | <_sabre_> these operand often define chains, they are the last operand |
| 2239 | <_sabre_> they are printed as 'ch' if you do DAG.dump() |
| 2240 | */ |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2241 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2242 | switch (N.getNumOperands()) { |
| 2243 | default: |
| 2244 | assert(0 && "Unknown return instruction!"); |
| 2245 | case 2: |
| 2246 | Select(N.getOperand(0)); |
| 2247 | Tmp1 = SelectExpr(N.getOperand(1)); |
| 2248 | switch (N.getOperand(1).getValueType()) { |
| 2249 | default: assert(0 && "All other types should have been promoted!!"); |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 2250 | // FIXME: do I need to add support for bools here? |
| 2251 | // (return '0' or '1' r8, basically...) |
| 2252 | // |
| 2253 | // FIXME: need to round floats - 80 bits is bad, the tester |
| 2254 | // told me so |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2255 | case MVT::i64: |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 2256 | // we mark r8 as live on exit up above in LowerArguments() |
| 2257 | BuildMI(BB, IA64::MOV, 1, IA64::r8).addReg(Tmp1); |
| 2258 | break; |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2259 | case MVT::f64: |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 2260 | // we mark F8 as live on exit up above in LowerArguments() |
| 2261 | BuildMI(BB, IA64::FMOV, 1, IA64::F8).addReg(Tmp1); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2262 | } |
| 2263 | break; |
| 2264 | case 1: |
| 2265 | Select(N.getOperand(0)); |
| 2266 | break; |
| 2267 | } |
| 2268 | // before returning, restore the ar.pfs register (set by the 'alloc' up top) |
| 2269 | BuildMI(BB, IA64::MOV, 1).addReg(IA64::AR_PFS).addReg(IA64Lowering.VirtGPR); |
| 2270 | BuildMI(BB, IA64::RET, 0); // and then just emit a 'ret' instruction |
| 2271 | return; |
| 2272 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2273 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2274 | case ISD::BR: { |
| 2275 | Select(N.getOperand(0)); |
| 2276 | MachineBasicBlock *Dest = |
| 2277 | cast<BasicBlockSDNode>(N.getOperand(1))->getBasicBlock(); |
| 2278 | BuildMI(BB, IA64::BRLCOND_NOTCALL, 1).addReg(IA64::p0).addMBB(Dest); |
| 2279 | // XXX HACK! we do _not_ need long branches all the time |
| 2280 | return; |
| 2281 | } |
| 2282 | |
| 2283 | case ISD::ImplicitDef: { |
| 2284 | Select(N.getOperand(0)); |
Chris Lattner | 707ebc5 | 2005-08-16 21:56:37 +0000 | [diff] [blame] | 2285 | BuildMI(BB, IA64::IDEF, 0, |
| 2286 | cast<RegisterSDNode>(N.getOperand(1))->getReg()); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2287 | return; |
| 2288 | } |
| 2289 | |
| 2290 | case ISD::BRCOND: { |
| 2291 | MachineBasicBlock *Dest = |
| 2292 | cast<BasicBlockSDNode>(N.getOperand(2))->getBasicBlock(); |
| 2293 | |
| 2294 | Select(N.getOperand(0)); |
| 2295 | Tmp1 = SelectExpr(N.getOperand(1)); |
| 2296 | BuildMI(BB, IA64::BRLCOND_NOTCALL, 1).addReg(Tmp1).addMBB(Dest); |
| 2297 | // XXX HACK! we do _not_ need long branches all the time |
| 2298 | return; |
| 2299 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2300 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2301 | case ISD::EXTLOAD: |
| 2302 | case ISD::ZEXTLOAD: |
| 2303 | case ISD::SEXTLOAD: |
| 2304 | case ISD::LOAD: |
Chris Lattner | b5d8e6e | 2005-05-13 20:29:26 +0000 | [diff] [blame] | 2305 | case ISD::TAILCALL: |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2306 | case ISD::CALL: |
| 2307 | case ISD::CopyFromReg: |
| 2308 | case ISD::DYNAMIC_STACKALLOC: |
| 2309 | SelectExpr(N); |
| 2310 | return; |
| 2311 | |
| 2312 | case ISD::TRUNCSTORE: |
| 2313 | case ISD::STORE: { |
| 2314 | Select(N.getOperand(0)); |
| 2315 | Tmp1 = SelectExpr(N.getOperand(1)); // value |
| 2316 | |
| 2317 | bool isBool=false; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2318 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2319 | if(opcode == ISD::STORE) { |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 2320 | switch (N.getOperand(1).getValueType()) { |
| 2321 | default: assert(0 && "Cannot store this type!"); |
| 2322 | case MVT::i1: Opc = IA64::ST1; isBool=true; break; |
| 2323 | // FIXME?: for now, we treat bool loads the same as i8 stores */ |
| 2324 | case MVT::i8: Opc = IA64::ST1; break; |
| 2325 | case MVT::i16: Opc = IA64::ST2; break; |
| 2326 | case MVT::i32: Opc = IA64::ST4; break; |
| 2327 | case MVT::i64: Opc = IA64::ST8; break; |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 2328 | |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 2329 | case MVT::f32: Opc = IA64::STF4; break; |
| 2330 | case MVT::f64: Opc = IA64::STF8; break; |
| 2331 | } |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2332 | } else { // truncstore |
Chris Lattner | 9fadb4c | 2005-07-10 00:29:18 +0000 | [diff] [blame] | 2333 | switch(cast<VTSDNode>(Node->getOperand(4))->getVT()) { |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 2334 | default: assert(0 && "unknown type in truncstore"); |
| 2335 | case MVT::i1: Opc = IA64::ST1; isBool=true; break; |
| 2336 | //FIXME: DAG does not promote this load? |
| 2337 | case MVT::i8: Opc = IA64::ST1; break; |
| 2338 | case MVT::i16: Opc = IA64::ST2; break; |
| 2339 | case MVT::i32: Opc = IA64::ST4; break; |
| 2340 | case MVT::f32: Opc = IA64::STF4; break; |
| 2341 | } |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2342 | } |
| 2343 | |
| 2344 | if(N.getOperand(2).getOpcode() == ISD::GlobalAddress) { |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 2345 | unsigned dummy = MakeReg(MVT::i64); |
| 2346 | unsigned dummy2 = MakeReg(MVT::i64); |
| 2347 | BuildMI(BB, IA64::ADD, 2, dummy) |
| 2348 | .addGlobalAddress(cast<GlobalAddressSDNode> |
| 2349 | (N.getOperand(2))->getGlobal()).addReg(IA64::r1); |
| 2350 | BuildMI(BB, IA64::LD8, 1, dummy2).addReg(dummy); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2351 | |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 2352 | if(!isBool) |
| 2353 | BuildMI(BB, Opc, 2).addReg(dummy2).addReg(Tmp1); |
| 2354 | else { // we are storing a bool, so emit a little pseudocode |
| 2355 | // to store a predicate register as one byte |
| 2356 | assert(Opc==IA64::ST1); |
| 2357 | unsigned dummy3 = MakeReg(MVT::i64); |
| 2358 | unsigned dummy4 = MakeReg(MVT::i64); |
| 2359 | BuildMI(BB, IA64::MOV, 1, dummy3).addReg(IA64::r0); |
| 2360 | BuildMI(BB, IA64::TPCADDIMM22, 2, dummy4) |
| 2361 | .addReg(dummy3).addImm(1).addReg(Tmp1); // if(Tmp1) dummy=0+1; |
| 2362 | BuildMI(BB, Opc, 2).addReg(dummy2).addReg(dummy4); |
| 2363 | } |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2364 | } else if(N.getOperand(2).getOpcode() == ISD::FrameIndex) { |
| 2365 | |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 2366 | // FIXME? (what about bools?) |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 2367 | |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 2368 | unsigned dummy = MakeReg(MVT::i64); |
| 2369 | BuildMI(BB, IA64::MOV, 1, dummy) |
| 2370 | .addFrameIndex(cast<FrameIndexSDNode>(N.getOperand(2))->getIndex()); |
| 2371 | BuildMI(BB, Opc, 2).addReg(dummy).addReg(Tmp1); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2372 | } else { // otherwise |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 2373 | Tmp2 = SelectExpr(N.getOperand(2)); //address |
| 2374 | if(!isBool) |
| 2375 | BuildMI(BB, Opc, 2).addReg(Tmp2).addReg(Tmp1); |
| 2376 | else { // we are storing a bool, so emit a little pseudocode |
| 2377 | // to store a predicate register as one byte |
| 2378 | assert(Opc==IA64::ST1); |
| 2379 | unsigned dummy3 = MakeReg(MVT::i64); |
| 2380 | unsigned dummy4 = MakeReg(MVT::i64); |
| 2381 | BuildMI(BB, IA64::MOV, 1, dummy3).addReg(IA64::r0); |
| 2382 | BuildMI(BB, IA64::TPCADDIMM22, 2, dummy4) |
| 2383 | .addReg(dummy3).addImm(1).addReg(Tmp1); // if(Tmp1) dummy=0+1; |
| 2384 | BuildMI(BB, Opc, 2).addReg(Tmp2).addReg(dummy4); |
| 2385 | } |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2386 | } |
| 2387 | return; |
| 2388 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2389 | |
Chris Lattner | 16cd04d | 2005-05-12 23:24:06 +0000 | [diff] [blame] | 2390 | case ISD::CALLSEQ_START: |
| 2391 | case ISD::CALLSEQ_END: { |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2392 | Select(N.getOperand(0)); |
| 2393 | Tmp1 = cast<ConstantSDNode>(N.getOperand(1))->getValue(); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2394 | |
Chris Lattner | 16cd04d | 2005-05-12 23:24:06 +0000 | [diff] [blame] | 2395 | Opc = N.getOpcode() == ISD::CALLSEQ_START ? IA64::ADJUSTCALLSTACKDOWN : |
| 2396 | IA64::ADJUSTCALLSTACKUP; |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2397 | BuildMI(BB, Opc, 1).addImm(Tmp1); |
| 2398 | return; |
| 2399 | } |
| 2400 | |
| 2401 | return; |
| 2402 | } |
| 2403 | assert(0 && "GAME OVER. INSERT COIN?"); |
| 2404 | } |
| 2405 | |
| 2406 | |
| 2407 | /// createIA64PatternInstructionSelector - This pass converts an LLVM function |
| 2408 | /// into a machine code representation using pattern matching and a machine |
| 2409 | /// description file. |
| 2410 | /// |
| 2411 | FunctionPass *llvm::createIA64PatternInstructionSelector(TargetMachine &TM) { |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2412 | return new ISel(TM); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 2413 | } |
| 2414 | |
| 2415 | |