Chris Lattner | 1c809c5 | 2004-02-29 00:27:00 +0000 | [diff] [blame] | 1 | //===-- InstSelectSimple.cpp - A simple instruction selector for SparcV8 --===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by the LLVM research group and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines a simple peephole instruction selector for the V8 target |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "SparcV8.h" |
Brian Gaeke | bc1d27a | 2004-03-03 23:03:14 +0000 | [diff] [blame] | 15 | #include "SparcV8InstrInfo.h" |
Brian Gaeke | 74dfcf1 | 2004-09-02 02:37:43 +0000 | [diff] [blame] | 16 | #include "llvm/Support/Debug.h" |
Chris Lattner | 1c809c5 | 2004-02-29 00:27:00 +0000 | [diff] [blame] | 17 | #include "llvm/Instructions.h" |
Chris Lattner | 1c809c5 | 2004-02-29 00:27:00 +0000 | [diff] [blame] | 18 | #include "llvm/Pass.h" |
Brian Gaeke | bc1d27a | 2004-03-03 23:03:14 +0000 | [diff] [blame] | 19 | #include "llvm/Constants.h" |
Chris Lattner | 3048373 | 2004-06-20 07:49:54 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/IntrinsicLowering.h" |
Chris Lattner | 1c809c5 | 2004-02-29 00:27:00 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Brian Gaeke | 9df9282 | 2004-06-15 19:16:07 +0000 | [diff] [blame] | 22 | #include "llvm/CodeGen/MachineFrameInfo.h" |
Brian Gaeke | c93a752 | 2004-06-18 05:19:16 +0000 | [diff] [blame] | 23 | #include "llvm/CodeGen/MachineConstantPool.h" |
Chris Lattner | 1c809c5 | 2004-02-29 00:27:00 +0000 | [diff] [blame] | 24 | #include "llvm/CodeGen/MachineFunction.h" |
Brian Gaeke | bc1d27a | 2004-03-03 23:03:14 +0000 | [diff] [blame] | 25 | #include "llvm/CodeGen/SSARegMap.h" |
Chris Lattner | 1c809c5 | 2004-02-29 00:27:00 +0000 | [diff] [blame] | 26 | #include "llvm/Target/TargetMachine.h" |
| 27 | #include "llvm/Support/GetElementPtrTypeIterator.h" |
| 28 | #include "llvm/Support/InstVisitor.h" |
| 29 | #include "llvm/Support/CFG.h" |
| 30 | using namespace llvm; |
| 31 | |
| 32 | namespace { |
| 33 | struct V8ISel : public FunctionPass, public InstVisitor<V8ISel> { |
| 34 | TargetMachine &TM; |
| 35 | MachineFunction *F; // The function we are compiling into |
| 36 | MachineBasicBlock *BB; // The current MBB we are compiling |
Brian Gaeke | d90282d | 2004-11-19 20:57:24 +0000 | [diff] [blame] | 37 | int VarArgsOffset; // Offset from fp for start of varargs area |
Chris Lattner | 1c809c5 | 2004-02-29 00:27:00 +0000 | [diff] [blame] | 38 | |
| 39 | std::map<Value*, unsigned> RegMap; // Mapping between Val's and SSA Regs |
| 40 | |
| 41 | // MBBMap - Mapping between LLVM BB -> Machine BB |
| 42 | std::map<const BasicBlock*, MachineBasicBlock*> MBBMap; |
| 43 | |
| 44 | V8ISel(TargetMachine &tm) : TM(tm), F(0), BB(0) {} |
| 45 | |
| 46 | /// runOnFunction - Top level implementation of instruction selection for |
| 47 | /// the entire function. |
| 48 | /// |
| 49 | bool runOnFunction(Function &Fn); |
| 50 | |
| 51 | virtual const char *getPassName() const { |
| 52 | return "SparcV8 Simple Instruction Selection"; |
| 53 | } |
| 54 | |
Brian Gaeke | 532e60c | 2004-05-08 04:21:17 +0000 | [diff] [blame] | 55 | /// emitGEPOperation - Common code shared between visitGetElementPtrInst and |
| 56 | /// constant expression GEP support. |
| 57 | /// |
| 58 | void emitGEPOperation(MachineBasicBlock *BB, MachineBasicBlock::iterator IP, |
| 59 | Value *Src, User::op_iterator IdxBegin, |
| 60 | User::op_iterator IdxEnd, unsigned TargetReg); |
| 61 | |
Brian Gaeke | 00e514e | 2004-06-24 06:33:00 +0000 | [diff] [blame] | 62 | /// emitCastOperation - Common code shared between visitCastInst and |
| 63 | /// constant expression cast support. |
| 64 | /// |
| 65 | void emitCastOperation(MachineBasicBlock *BB,MachineBasicBlock::iterator IP, |
| 66 | Value *Src, const Type *DestTy, unsigned TargetReg); |
| 67 | |
Brian Gaeke | 8b6c1ff | 2004-10-14 19:39:34 +0000 | [diff] [blame] | 68 | /// emitIntegerCast, emitFPToIntegerCast - Helper methods for |
| 69 | /// emitCastOperation. |
| 70 | /// |
Brian Gaeke | a54df25 | 2004-11-19 18:48:10 +0000 | [diff] [blame] | 71 | unsigned emitIntegerCast (MachineBasicBlock *BB, |
| 72 | MachineBasicBlock::iterator IP, |
| 73 | const Type *oldTy, unsigned SrcReg, |
| 74 | const Type *newTy, unsigned DestReg); |
Brian Gaeke | 8b6c1ff | 2004-10-14 19:39:34 +0000 | [diff] [blame] | 75 | void emitFPToIntegerCast (MachineBasicBlock *BB, |
| 76 | MachineBasicBlock::iterator IP, const Type *oldTy, |
| 77 | unsigned SrcReg, const Type *newTy, |
| 78 | unsigned DestReg); |
| 79 | |
Chris Lattner | 1c809c5 | 2004-02-29 00:27:00 +0000 | [diff] [blame] | 80 | /// visitBasicBlock - This method is called when we are visiting a new basic |
| 81 | /// block. This simply creates a new MachineBasicBlock to emit code into |
| 82 | /// and adds it to the current MachineFunction. Subsequent visit* for |
| 83 | /// instructions will be invoked for all instructions in the basic block. |
| 84 | /// |
| 85 | void visitBasicBlock(BasicBlock &LLVM_BB) { |
| 86 | BB = MBBMap[&LLVM_BB]; |
| 87 | } |
| 88 | |
Brian Gaeke | 5f91de2 | 2004-11-21 07:13:16 +0000 | [diff] [blame] | 89 | void emitOp64LibraryCall (MachineBasicBlock *MBB, |
| 90 | MachineBasicBlock::iterator IP, |
| 91 | unsigned DestReg, const char *FuncName, |
| 92 | unsigned Op0Reg, unsigned Op1Reg); |
Brian Gaeke | 9ffcf9f | 2004-11-22 08:02:06 +0000 | [diff] [blame] | 93 | void emitShift64 (MachineBasicBlock *MBB, MachineBasicBlock::iterator IP, |
| 94 | Instruction &I, unsigned DestReg, unsigned Op0Reg, |
| 95 | unsigned Op1Reg); |
Chris Lattner | 4be7ca5 | 2004-04-07 04:27:16 +0000 | [diff] [blame] | 96 | void visitBinaryOperator(Instruction &I); |
Brian Gaeke | d6a1053 | 2004-06-15 21:09:46 +0000 | [diff] [blame] | 97 | void visitShiftInst (ShiftInst &SI) { visitBinaryOperator (SI); } |
Misha Brukman | ea09126 | 2004-06-30 21:47:40 +0000 | [diff] [blame] | 98 | void visitSetCondInst(SetCondInst &I); |
Chris Lattner | 4be7ca5 | 2004-04-07 04:27:16 +0000 | [diff] [blame] | 99 | void visitCallInst(CallInst &I); |
Brian Gaeke | f3334eb | 2004-04-07 17:29:37 +0000 | [diff] [blame] | 100 | void visitReturnInst(ReturnInst &I); |
Brian Gaeke | 532e60c | 2004-05-08 04:21:17 +0000 | [diff] [blame] | 101 | void visitBranchInst(BranchInst &I); |
Chris Lattner | d14d5b4 | 2004-10-17 02:42:42 +0000 | [diff] [blame] | 102 | void visitUnreachableInst(UnreachableInst &I) {} |
Brian Gaeke | 3d11e8a | 2004-04-13 18:27:46 +0000 | [diff] [blame] | 103 | void visitCastInst(CastInst &I); |
Brian Gaeke | b6c409a | 2004-11-19 21:08:18 +0000 | [diff] [blame] | 104 | void visitVANextInst(VANextInst &I); |
| 105 | void visitVAArgInst(VAArgInst &I); |
Brian Gaeke | f3334eb | 2004-04-07 17:29:37 +0000 | [diff] [blame] | 106 | void visitLoadInst(LoadInst &I); |
| 107 | void visitStoreInst(StoreInst &I); |
Brian Gaeke | 532e60c | 2004-05-08 04:21:17 +0000 | [diff] [blame] | 108 | void visitPHINode(PHINode &I) {} // PHI nodes handled by second pass |
| 109 | void visitGetElementPtrInst(GetElementPtrInst &I); |
Brian Gaeke | c93a752 | 2004-06-18 05:19:16 +0000 | [diff] [blame] | 110 | void visitAllocaInst(AllocaInst &I); |
Brian Gaeke | 532e60c | 2004-05-08 04:21:17 +0000 | [diff] [blame] | 111 | |
Chris Lattner | 1c809c5 | 2004-02-29 00:27:00 +0000 | [diff] [blame] | 112 | void visitInstruction(Instruction &I) { |
| 113 | std::cerr << "Unhandled instruction: " << I; |
| 114 | abort(); |
| 115 | } |
| 116 | |
| 117 | /// LowerUnknownIntrinsicFunctionCalls - This performs a prepass over the |
| 118 | /// function, lowering any calls to unknown intrinsic functions into the |
| 119 | /// equivalent LLVM code. |
| 120 | void LowerUnknownIntrinsicFunctionCalls(Function &F); |
Chris Lattner | 1c809c5 | 2004-02-29 00:27:00 +0000 | [diff] [blame] | 121 | void visitIntrinsicCall(Intrinsic::ID ID, CallInst &CI); |
| 122 | |
Brian Gaeke | 562cb16 | 2004-04-07 17:04:09 +0000 | [diff] [blame] | 123 | void LoadArgumentsToVirtualRegs(Function *F); |
| 124 | |
Brian Gaeke | 6c868a4 | 2004-06-17 22:34:08 +0000 | [diff] [blame] | 125 | /// SelectPHINodes - Insert machine code to generate phis. This is tricky |
| 126 | /// because we have to generate our sources into the source basic blocks, |
| 127 | /// not the current one. |
| 128 | /// |
| 129 | void SelectPHINodes(); |
| 130 | |
Brian Gaeke | bc1d27a | 2004-03-03 23:03:14 +0000 | [diff] [blame] | 131 | /// copyConstantToRegister - Output the instructions required to put the |
| 132 | /// specified constant into the specified register. |
| 133 | /// |
| 134 | void copyConstantToRegister(MachineBasicBlock *MBB, |
| 135 | MachineBasicBlock::iterator IP, |
| 136 | Constant *C, unsigned R); |
| 137 | |
| 138 | /// makeAnotherReg - This method returns the next register number we haven't |
| 139 | /// yet used. |
| 140 | /// |
| 141 | /// Long values are handled somewhat specially. They are always allocated |
| 142 | /// as pairs of 32 bit integer values. The register number returned is the |
| 143 | /// lower 32 bits of the long value, and the regNum+1 is the upper 32 bits |
| 144 | /// of the long value. |
| 145 | /// |
| 146 | unsigned makeAnotherReg(const Type *Ty) { |
| 147 | assert(dynamic_cast<const SparcV8RegisterInfo*>(TM.getRegisterInfo()) && |
| 148 | "Current target doesn't have SparcV8 reg info??"); |
| 149 | const SparcV8RegisterInfo *MRI = |
| 150 | static_cast<const SparcV8RegisterInfo*>(TM.getRegisterInfo()); |
| 151 | if (Ty == Type::LongTy || Ty == Type::ULongTy) { |
| 152 | const TargetRegisterClass *RC = MRI->getRegClassForType(Type::IntTy); |
| 153 | // Create the lower part |
| 154 | F->getSSARegMap()->createVirtualRegister(RC); |
| 155 | // Create the upper part. |
| 156 | return F->getSSARegMap()->createVirtualRegister(RC)-1; |
| 157 | } |
| 158 | |
| 159 | // Add the mapping of regnumber => reg class to MachineFunction |
| 160 | const TargetRegisterClass *RC = MRI->getRegClassForType(Ty); |
| 161 | return F->getSSARegMap()->createVirtualRegister(RC); |
| 162 | } |
| 163 | |
| 164 | unsigned getReg(Value &V) { return getReg (&V); } // allow refs. |
| 165 | unsigned getReg(Value *V) { |
| 166 | // Just append to the end of the current bb. |
| 167 | MachineBasicBlock::iterator It = BB->end(); |
| 168 | return getReg(V, BB, It); |
| 169 | } |
| 170 | unsigned getReg(Value *V, MachineBasicBlock *MBB, |
| 171 | MachineBasicBlock::iterator IPt) { |
| 172 | unsigned &Reg = RegMap[V]; |
| 173 | if (Reg == 0) { |
| 174 | Reg = makeAnotherReg(V->getType()); |
| 175 | RegMap[V] = Reg; |
| 176 | } |
| 177 | // If this operand is a constant, emit the code to copy the constant into |
| 178 | // the register here... |
| 179 | // |
| 180 | if (Constant *C = dyn_cast<Constant>(V)) { |
| 181 | copyConstantToRegister(MBB, IPt, C, Reg); |
| 182 | RegMap.erase(V); // Assign a new name to this constant if ref'd again |
| 183 | } else if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) { |
| 184 | // Move the address of the global into the register |
Brian Gaeke | cf47198 | 2004-03-09 04:49:13 +0000 | [diff] [blame] | 185 | unsigned TmpReg = makeAnotherReg(V->getType()); |
| 186 | BuildMI (*MBB, IPt, V8::SETHIi, 1, TmpReg).addGlobalAddress (GV); |
| 187 | BuildMI (*MBB, IPt, V8::ORri, 2, Reg).addReg (TmpReg) |
| 188 | .addGlobalAddress (GV); |
Brian Gaeke | bc1d27a | 2004-03-03 23:03:14 +0000 | [diff] [blame] | 189 | RegMap.erase(V); // Assign a new name to this address if ref'd again |
| 190 | } |
| 191 | |
| 192 | return Reg; |
| 193 | } |
| 194 | |
Chris Lattner | 1c809c5 | 2004-02-29 00:27:00 +0000 | [diff] [blame] | 195 | }; |
| 196 | } |
| 197 | |
| 198 | FunctionPass *llvm::createSparcV8SimpleInstructionSelector(TargetMachine &TM) { |
| 199 | return new V8ISel(TM); |
| 200 | } |
| 201 | |
Brian Gaeke | bc1d27a | 2004-03-03 23:03:14 +0000 | [diff] [blame] | 202 | enum TypeClass { |
Brian Gaeke | f57e364 | 2004-03-16 22:37:11 +0000 | [diff] [blame] | 203 | cByte, cShort, cInt, cLong, cFloat, cDouble |
Brian Gaeke | bc1d27a | 2004-03-03 23:03:14 +0000 | [diff] [blame] | 204 | }; |
| 205 | |
| 206 | static TypeClass getClass (const Type *T) { |
Chris Lattner | f70c22b | 2004-06-17 18:19:28 +0000 | [diff] [blame] | 207 | switch (T->getTypeID()) { |
Brian Gaeke | bc1d27a | 2004-03-03 23:03:14 +0000 | [diff] [blame] | 208 | case Type::UByteTyID: case Type::SByteTyID: return cByte; |
| 209 | case Type::UShortTyID: case Type::ShortTyID: return cShort; |
Brian Gaeke | 562cb16 | 2004-04-07 17:04:09 +0000 | [diff] [blame] | 210 | case Type::PointerTyID: |
Brian Gaeke | bc1d27a | 2004-03-03 23:03:14 +0000 | [diff] [blame] | 211 | case Type::UIntTyID: case Type::IntTyID: return cInt; |
Brian Gaeke | f57e364 | 2004-03-16 22:37:11 +0000 | [diff] [blame] | 212 | case Type::ULongTyID: case Type::LongTyID: return cLong; |
Brian Gaeke | bc1d27a | 2004-03-03 23:03:14 +0000 | [diff] [blame] | 213 | case Type::FloatTyID: return cFloat; |
| 214 | case Type::DoubleTyID: return cDouble; |
| 215 | default: |
| 216 | assert (0 && "Type of unknown class passed to getClass?"); |
| 217 | return cByte; |
| 218 | } |
| 219 | } |
Brian Gaeke | 50094ed | 2004-10-10 19:57:18 +0000 | [diff] [blame] | 220 | |
Chris Lattner | 0d538bb | 2004-04-07 04:36:53 +0000 | [diff] [blame] | 221 | static TypeClass getClassB(const Type *T) { |
| 222 | if (T == Type::BoolTy) return cByte; |
| 223 | return getClass(T); |
| 224 | } |
| 225 | |
Brian Gaeke | bc1d27a | 2004-03-03 23:03:14 +0000 | [diff] [blame] | 226 | /// copyConstantToRegister - Output the instructions required to put the |
| 227 | /// specified constant into the specified register. |
| 228 | /// |
| 229 | void V8ISel::copyConstantToRegister(MachineBasicBlock *MBB, |
| 230 | MachineBasicBlock::iterator IP, |
| 231 | Constant *C, unsigned R) { |
Brian Gaeke | 9df9282 | 2004-06-15 19:16:07 +0000 | [diff] [blame] | 232 | if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) { |
| 233 | switch (CE->getOpcode()) { |
| 234 | case Instruction::GetElementPtr: |
| 235 | emitGEPOperation(MBB, IP, CE->getOperand(0), |
| 236 | CE->op_begin()+1, CE->op_end(), R); |
| 237 | return; |
Brian Gaeke | 00e514e | 2004-06-24 06:33:00 +0000 | [diff] [blame] | 238 | case Instruction::Cast: |
| 239 | emitCastOperation(MBB, IP, CE->getOperand(0), CE->getType(), R); |
| 240 | return; |
Brian Gaeke | 9df9282 | 2004-06-15 19:16:07 +0000 | [diff] [blame] | 241 | default: |
| 242 | std::cerr << "Copying this constant expr not yet handled: " << *CE; |
| 243 | abort(); |
| 244 | } |
Chris Lattner | d14d5b4 | 2004-10-17 02:42:42 +0000 | [diff] [blame] | 245 | } else if (isa<UndefValue>(C)) { |
| 246 | BuildMI(*MBB, IP, V8::IMPLICIT_DEF, 0, R); |
| 247 | if (getClassB (C->getType ()) == cLong) |
| 248 | BuildMI(*MBB, IP, V8::IMPLICIT_DEF, 0, R+1); |
| 249 | return; |
Brian Gaeke | 9df9282 | 2004-06-15 19:16:07 +0000 | [diff] [blame] | 250 | } |
| 251 | |
Brian Gaeke | e302a7e | 2004-05-07 21:39:30 +0000 | [diff] [blame] | 252 | if (C->getType()->isIntegral ()) { |
| 253 | uint64_t Val; |
Brian Gaeke | 9df9282 | 2004-06-15 19:16:07 +0000 | [diff] [blame] | 254 | unsigned Class = getClassB (C->getType ()); |
| 255 | if (Class == cLong) { |
| 256 | unsigned TmpReg = makeAnotherReg (Type::IntTy); |
| 257 | unsigned TmpReg2 = makeAnotherReg (Type::IntTy); |
| 258 | // Copy the value into the register pair. |
| 259 | // R = top(more-significant) half, R+1 = bottom(less-significant) half |
| 260 | uint64_t Val = cast<ConstantInt>(C)->getRawValue(); |
Brian Gaeke | 1df468e | 2004-09-29 03:34:41 +0000 | [diff] [blame] | 261 | copyConstantToRegister(MBB, IP, ConstantUInt::get(Type::UIntTy, |
| 262 | Val >> 32), R); |
| 263 | copyConstantToRegister(MBB, IP, ConstantUInt::get(Type::UIntTy, |
| 264 | Val & 0xffffffffU), R+1); |
Brian Gaeke | 9df9282 | 2004-06-15 19:16:07 +0000 | [diff] [blame] | 265 | return; |
| 266 | } |
| 267 | |
| 268 | assert(Class <= cInt && "Type not handled yet!"); |
| 269 | |
Brian Gaeke | e302a7e | 2004-05-07 21:39:30 +0000 | [diff] [blame] | 270 | if (C->getType() == Type::BoolTy) { |
| 271 | Val = (C == ConstantBool::True); |
| 272 | } else { |
Brian Gaeke | 13dc433 | 2004-06-24 09:17:47 +0000 | [diff] [blame] | 273 | ConstantInt *CI = cast<ConstantInt> (C); |
Brian Gaeke | e302a7e | 2004-05-07 21:39:30 +0000 | [diff] [blame] | 274 | Val = CI->getRawValue (); |
| 275 | } |
Brian Gaeke | 9df9282 | 2004-06-15 19:16:07 +0000 | [diff] [blame] | 276 | switch (Class) { |
Brian Gaeke | 13dc433 | 2004-06-24 09:17:47 +0000 | [diff] [blame] | 277 | case cByte: Val = (int8_t) Val; break; |
| 278 | case cShort: Val = (int16_t) Val; break; |
| 279 | case cInt: Val = (int32_t) Val; break; |
Brian Gaeke | e806173 | 2004-03-04 00:56:25 +0000 | [diff] [blame] | 280 | default: |
Brian Gaeke | 2d4fa8f | 2004-04-07 04:00:49 +0000 | [diff] [blame] | 281 | std::cerr << "Offending constant: " << *C << "\n"; |
Brian Gaeke | 775158d | 2004-03-04 04:37:45 +0000 | [diff] [blame] | 282 | assert (0 && "Can't copy this kind of constant into register yet"); |
Brian Gaeke | e806173 | 2004-03-04 00:56:25 +0000 | [diff] [blame] | 283 | return; |
| 284 | } |
Brian Gaeke | 13dc433 | 2004-06-24 09:17:47 +0000 | [diff] [blame] | 285 | if (Val == 0) { |
| 286 | BuildMI (*MBB, IP, V8::ORrr, 2, R).addReg (V8::G0).addReg(V8::G0); |
| 287 | } else if (((int64_t)Val >= -4096) && ((int64_t)Val <= 4095)) { |
| 288 | BuildMI (*MBB, IP, V8::ORri, 2, R).addReg (V8::G0).addSImm(Val); |
| 289 | } else { |
| 290 | unsigned TmpReg = makeAnotherReg (C->getType ()); |
| 291 | BuildMI (*MBB, IP, V8::SETHIi, 1, TmpReg) |
| 292 | .addSImm (((uint32_t) Val) >> 10); |
| 293 | BuildMI (*MBB, IP, V8::ORri, 2, R).addReg (TmpReg) |
| 294 | .addSImm (((uint32_t) Val) & 0x03ff); |
| 295 | return; |
| 296 | } |
Brian Gaeke | c93a752 | 2004-06-18 05:19:16 +0000 | [diff] [blame] | 297 | } else if (ConstantFP *CFP = dyn_cast<ConstantFP>(C)) { |
| 298 | // We need to spill the constant to memory... |
| 299 | MachineConstantPool *CP = F->getConstantPool(); |
| 300 | unsigned CPI = CP->getConstantPoolIndex(CFP); |
| 301 | const Type *Ty = CFP->getType(); |
Brian Gaeke | 1df468e | 2004-09-29 03:34:41 +0000 | [diff] [blame] | 302 | unsigned TmpReg = makeAnotherReg (Type::UIntTy); |
| 303 | unsigned AddrReg = makeAnotherReg (Type::UIntTy); |
Brian Gaeke | c93a752 | 2004-06-18 05:19:16 +0000 | [diff] [blame] | 304 | |
| 305 | assert(Ty == Type::FloatTy || Ty == Type::DoubleTy && "Unknown FP type!"); |
Brian Gaeke | 4473303 | 2004-06-24 07:36:48 +0000 | [diff] [blame] | 306 | unsigned LoadOpcode = Ty == Type::FloatTy ? V8::LDFri : V8::LDDFri; |
Brian Gaeke | 1df468e | 2004-09-29 03:34:41 +0000 | [diff] [blame] | 307 | BuildMI (*MBB, IP, V8::SETHIi, 1, TmpReg).addConstantPoolIndex (CPI); |
Brian Gaeke | 50094ed | 2004-10-10 19:57:18 +0000 | [diff] [blame] | 308 | BuildMI (*MBB, IP, V8::ORri, 2, AddrReg).addReg (TmpReg) |
| 309 | .addConstantPoolIndex (CPI); |
Brian Gaeke | 1df468e | 2004-09-29 03:34:41 +0000 | [diff] [blame] | 310 | BuildMI (*MBB, IP, LoadOpcode, 2, R).addReg (AddrReg).addSImm (0); |
Brian Gaeke | 9df9282 | 2004-06-15 19:16:07 +0000 | [diff] [blame] | 311 | } else if (isa<ConstantPointerNull>(C)) { |
| 312 | // Copy zero (null pointer) to the register. |
Brian Gaeke | c7fd0f4 | 2004-06-24 08:55:09 +0000 | [diff] [blame] | 313 | BuildMI (*MBB, IP, V8::ORri, 2, R).addReg (V8::G0).addSImm (0); |
Chris Lattner | 7330248 | 2004-07-18 07:26:17 +0000 | [diff] [blame] | 314 | } else if (GlobalValue *GV = dyn_cast<GlobalValue>(C)) { |
Brian Gaeke | 9df9282 | 2004-06-15 19:16:07 +0000 | [diff] [blame] | 315 | // Copy it with a SETHI/OR pair; the JIT + asmwriter should recognize |
| 316 | // that SETHI %reg,global == SETHI %reg,%hi(global) and |
| 317 | // OR %reg,global,%reg == OR %reg,%lo(global),%reg. |
| 318 | unsigned TmpReg = makeAnotherReg (C->getType ()); |
Chris Lattner | 7330248 | 2004-07-18 07:26:17 +0000 | [diff] [blame] | 319 | BuildMI (*MBB, IP, V8::SETHIi, 1, TmpReg).addGlobalAddress(GV); |
| 320 | BuildMI (*MBB, IP, V8::ORri, 2, R).addReg(TmpReg).addGlobalAddress(GV); |
Brian Gaeke | 9df9282 | 2004-06-15 19:16:07 +0000 | [diff] [blame] | 321 | } else { |
| 322 | std::cerr << "Offending constant: " << *C << "\n"; |
| 323 | assert (0 && "Can't copy this kind of constant into register yet"); |
Brian Gaeke | bc1d27a | 2004-03-03 23:03:14 +0000 | [diff] [blame] | 324 | } |
Brian Gaeke | bc1d27a | 2004-03-03 23:03:14 +0000 | [diff] [blame] | 325 | } |
Chris Lattner | 1c809c5 | 2004-02-29 00:27:00 +0000 | [diff] [blame] | 326 | |
Brian Gaeke | 812c488 | 2004-07-16 10:31:25 +0000 | [diff] [blame] | 327 | void V8ISel::LoadArgumentsToVirtualRegs (Function *LF) { |
Brian Gaeke | 562cb16 | 2004-04-07 17:04:09 +0000 | [diff] [blame] | 328 | static const unsigned IncomingArgRegs[] = { V8::I0, V8::I1, V8::I2, |
| 329 | V8::I3, V8::I4, V8::I5 }; |
Brian Gaeke | 7c0afe0 | 2004-11-18 07:43:33 +0000 | [diff] [blame] | 330 | |
Brian Gaeke | 812c488 | 2004-07-16 10:31:25 +0000 | [diff] [blame] | 331 | // Add IMPLICIT_DEFs of input regs. |
Brian Gaeke | 7c0afe0 | 2004-11-18 07:43:33 +0000 | [diff] [blame] | 332 | unsigned ArgNo = 0; |
Brian Gaeke | 1df468e | 2004-09-29 03:34:41 +0000 | [diff] [blame] | 333 | for (Function::aiterator I = LF->abegin(), E = LF->aend(); |
Brian Gaeke | 7c0afe0 | 2004-11-18 07:43:33 +0000 | [diff] [blame] | 334 | I != E && ArgNo < 6; ++I, ++ArgNo) { |
Brian Gaeke | 812c488 | 2004-07-16 10:31:25 +0000 | [diff] [blame] | 335 | switch (getClassB(I->getType())) { |
| 336 | case cByte: |
| 337 | case cShort: |
| 338 | case cInt: |
| 339 | case cFloat: |
Brian Gaeke | 7c0afe0 | 2004-11-18 07:43:33 +0000 | [diff] [blame] | 340 | BuildMI(BB, V8::IMPLICIT_DEF, 0, IncomingArgRegs[ArgNo]); |
Brian Gaeke | 812c488 | 2004-07-16 10:31:25 +0000 | [diff] [blame] | 341 | break; |
Brian Gaeke | 1df468e | 2004-09-29 03:34:41 +0000 | [diff] [blame] | 342 | case cDouble: |
| 343 | case cLong: |
| 344 | // Double and Long use register pairs. |
Brian Gaeke | 7c0afe0 | 2004-11-18 07:43:33 +0000 | [diff] [blame] | 345 | BuildMI(BB, V8::IMPLICIT_DEF, 0, IncomingArgRegs[ArgNo]); |
| 346 | ++ArgNo; |
| 347 | if (ArgNo < 6) |
| 348 | BuildMI(BB, V8::IMPLICIT_DEF, 0, IncomingArgRegs[ArgNo]); |
Brian Gaeke | 1df468e | 2004-09-29 03:34:41 +0000 | [diff] [blame] | 349 | break; |
Brian Gaeke | 812c488 | 2004-07-16 10:31:25 +0000 | [diff] [blame] | 350 | default: |
Brian Gaeke | 1df468e | 2004-09-29 03:34:41 +0000 | [diff] [blame] | 351 | assert (0 && "type not handled"); |
Brian Gaeke | 812c488 | 2004-07-16 10:31:25 +0000 | [diff] [blame] | 352 | return; |
| 353 | } |
Brian Gaeke | 812c488 | 2004-07-16 10:31:25 +0000 | [diff] [blame] | 354 | } |
| 355 | |
Brian Gaeke | 7c0afe0 | 2004-11-18 07:43:33 +0000 | [diff] [blame] | 356 | const unsigned *IAREnd = &IncomingArgRegs[6]; |
| 357 | const unsigned *IAR = &IncomingArgRegs[0]; |
| 358 | unsigned ArgOffset = 68; |
Brian Gaeke | 4e459c4 | 2004-11-19 20:31:08 +0000 | [diff] [blame] | 359 | |
| 360 | // Store registers onto stack if this is a varargs function. |
| 361 | // FIXME: This doesn't really pertain to "loading arguments into |
| 362 | // virtual registers", so it's not clear that it really belongs here. |
| 363 | // FIXME: We could avoid storing any args onto the stack that don't |
| 364 | // need to be in memory, because they come before the ellipsis in the |
| 365 | // parameter list (and thus could never be accessed through va_arg). |
| 366 | if (LF->getFunctionType ()->isVarArg ()) { |
| 367 | for (unsigned i = 0; i < 6; ++i) { |
| 368 | int FI = F->getFrameInfo()->CreateFixedObject(4, ArgOffset); |
| 369 | assert (IAR != IAREnd |
| 370 | && "About to dereference past end of IncomingArgRegs"); |
| 371 | BuildMI (BB, V8::ST, 3).addFrameIndex (FI).addSImm (0).addReg (*IAR++); |
| 372 | ArgOffset += 4; |
| 373 | } |
| 374 | // Reset the pointers now that we're done. |
| 375 | ArgOffset = 68; |
| 376 | IAR = &IncomingArgRegs[0]; |
| 377 | } |
| 378 | |
| 379 | // Copy args out of their incoming hard regs or stack slots into virtual regs. |
Brian Gaeke | 7c0afe0 | 2004-11-18 07:43:33 +0000 | [diff] [blame] | 380 | for (Function::aiterator I = LF->abegin(), E = LF->aend(); I != E; ++I) { |
| 381 | Argument &A = *I; |
| 382 | unsigned ArgReg = getReg (A); |
| 383 | if (getClassB (A.getType ()) < cLong) { |
| 384 | // Get it out of the incoming arg register |
| 385 | if (ArgOffset < 92) { |
| 386 | assert (IAR != IAREnd |
| 387 | && "About to dereference past end of IncomingArgRegs"); |
| 388 | BuildMI (BB, V8::ORrr, 2, ArgReg).addReg (V8::G0).addReg (*IAR++); |
| 389 | } else { |
| 390 | int FI = F->getFrameInfo()->CreateFixedObject(4, ArgOffset); |
| 391 | BuildMI (BB, V8::LD, 3, ArgReg).addFrameIndex (FI).addSImm (0); |
| 392 | } |
| 393 | ArgOffset += 4; |
| 394 | } else if (getClassB (A.getType ()) == cFloat) { |
| 395 | if (ArgOffset < 92) { |
Brian Gaeke | 1df468e | 2004-09-29 03:34:41 +0000 | [diff] [blame] | 396 | // Single-fp args are passed in integer registers; go through |
Brian Gaeke | 7c0afe0 | 2004-11-18 07:43:33 +0000 | [diff] [blame] | 397 | // memory to get them out of integer registers and back into fp. (Bleh!) |
Brian Gaeke | 1df468e | 2004-09-29 03:34:41 +0000 | [diff] [blame] | 398 | unsigned FltAlign = TM.getTargetData().getFloatAlignment(); |
| 399 | int FI = F->getFrameInfo()->CreateStackObject(4, FltAlign); |
Brian Gaeke | 7c0afe0 | 2004-11-18 07:43:33 +0000 | [diff] [blame] | 400 | assert (IAR != IAREnd |
| 401 | && "About to dereference past end of IncomingArgRegs"); |
| 402 | BuildMI (BB, V8::ST, 3).addFrameIndex (FI).addSImm (0).addReg (*IAR++); |
| 403 | BuildMI (BB, V8::LDFri, 2, ArgReg).addFrameIndex (FI).addSImm (0); |
| 404 | } else { |
| 405 | int FI = F->getFrameInfo()->CreateFixedObject(4, ArgOffset); |
| 406 | BuildMI (BB, V8::LDFri, 3, ArgReg).addFrameIndex (FI).addSImm (0); |
Brian Gaeke | 1df468e | 2004-09-29 03:34:41 +0000 | [diff] [blame] | 407 | } |
Brian Gaeke | 7c0afe0 | 2004-11-18 07:43:33 +0000 | [diff] [blame] | 408 | ArgOffset += 4; |
| 409 | } else if (getClassB (A.getType ()) == cDouble) { |
| 410 | // Double-fp args are passed in pairs of integer registers; go through |
| 411 | // memory to get them out of integer registers and back into fp. (Bleh!) |
| 412 | // We'd like to 'ldd' these right out of the incoming-args area, |
| 413 | // but it might not be 8-byte aligned (e.g., call x(int x, double d)). |
| 414 | unsigned DblAlign = TM.getTargetData().getDoubleAlignment(); |
| 415 | int FI = F->getFrameInfo()->CreateStackObject(8, DblAlign); |
| 416 | if (ArgOffset < 92 && IAR != IAREnd) { |
| 417 | BuildMI (BB, V8::ST, 3).addFrameIndex (FI).addSImm (0).addReg (*IAR++); |
| 418 | } else { |
| 419 | unsigned TempReg = makeAnotherReg (Type::IntTy); |
| 420 | BuildMI (BB, V8::LD, 2, TempReg).addFrameIndex (FI).addSImm (0); |
| 421 | BuildMI (BB, V8::ST, 3).addFrameIndex (FI).addSImm (0).addReg (TempReg); |
Brian Gaeke | 6672f86 | 2004-09-30 19:44:32 +0000 | [diff] [blame] | 422 | } |
Brian Gaeke | 7c0afe0 | 2004-11-18 07:43:33 +0000 | [diff] [blame] | 423 | ArgOffset += 4; |
| 424 | if (ArgOffset < 92 && IAR != IAREnd) { |
| 425 | BuildMI (BB, V8::ST, 3).addFrameIndex (FI).addSImm (4).addReg (*IAR++); |
| 426 | } else { |
| 427 | unsigned TempReg = makeAnotherReg (Type::IntTy); |
| 428 | BuildMI (BB, V8::LD, 2, TempReg).addFrameIndex (FI).addSImm (4); |
| 429 | BuildMI (BB, V8::ST, 3).addFrameIndex (FI).addSImm (4).addReg (TempReg); |
Brian Gaeke | 1df468e | 2004-09-29 03:34:41 +0000 | [diff] [blame] | 430 | } |
Brian Gaeke | 7c0afe0 | 2004-11-18 07:43:33 +0000 | [diff] [blame] | 431 | ArgOffset += 4; |
| 432 | BuildMI (BB, V8::LDDFri, 2, ArgReg).addFrameIndex (FI).addSImm (0); |
| 433 | } else if (getClassB (A.getType ()) == cLong) { |
| 434 | // do the first half... |
| 435 | if (ArgOffset < 92) { |
| 436 | assert (IAR != IAREnd |
| 437 | && "About to dereference past end of IncomingArgRegs"); |
| 438 | BuildMI (BB, V8::ORrr, 2, ArgReg).addReg (V8::G0).addReg (*IAR++); |
| 439 | } else { |
| 440 | int FI = F->getFrameInfo()->CreateFixedObject(4, ArgOffset); |
| 441 | BuildMI (BB, V8::LD, 2, ArgReg).addFrameIndex (FI).addSImm (0); |
| 442 | } |
| 443 | ArgOffset += 4; |
| 444 | // ...then do the second half |
| 445 | if (ArgOffset < 92) { |
| 446 | assert (IAR != IAREnd |
| 447 | && "About to dereference past end of IncomingArgRegs"); |
| 448 | BuildMI (BB, V8::ORrr, 2, ArgReg+1).addReg (V8::G0).addReg (*IAR++); |
| 449 | } else { |
| 450 | int FI = F->getFrameInfo()->CreateFixedObject(4, ArgOffset); |
| 451 | BuildMI (BB, V8::LD, 2, ArgReg+1).addFrameIndex (FI).addSImm (0); |
| 452 | } |
| 453 | ArgOffset += 4; |
Brian Gaeke | 1df468e | 2004-09-29 03:34:41 +0000 | [diff] [blame] | 454 | } else { |
Brian Gaeke | 7c0afe0 | 2004-11-18 07:43:33 +0000 | [diff] [blame] | 455 | assert (0 && "Unknown class?!"); |
Brian Gaeke | 812c488 | 2004-07-16 10:31:25 +0000 | [diff] [blame] | 456 | } |
Brian Gaeke | 562cb16 | 2004-04-07 17:04:09 +0000 | [diff] [blame] | 457 | } |
Brian Gaeke | d90282d | 2004-11-19 20:57:24 +0000 | [diff] [blame] | 458 | |
| 459 | // If the function takes variable number of arguments, remember the fp |
| 460 | // offset for the start of the first vararg value... this is used to expand |
| 461 | // llvm.va_start. |
| 462 | if (LF->getFunctionType ()->isVarArg ()) |
| 463 | VarArgsOffset = ArgOffset; |
Brian Gaeke | 562cb16 | 2004-04-07 17:04:09 +0000 | [diff] [blame] | 464 | } |
| 465 | |
Brian Gaeke | 6c868a4 | 2004-06-17 22:34:08 +0000 | [diff] [blame] | 466 | void V8ISel::SelectPHINodes() { |
| 467 | const TargetInstrInfo &TII = *TM.getInstrInfo(); |
| 468 | const Function &LF = *F->getFunction(); // The LLVM function... |
| 469 | for (Function::const_iterator I = LF.begin(), E = LF.end(); I != E; ++I) { |
| 470 | const BasicBlock *BB = I; |
| 471 | MachineBasicBlock &MBB = *MBBMap[I]; |
| 472 | |
| 473 | // Loop over all of the PHI nodes in the LLVM basic block... |
| 474 | MachineBasicBlock::iterator PHIInsertPoint = MBB.begin(); |
| 475 | for (BasicBlock::const_iterator I = BB->begin(); |
| 476 | PHINode *PN = const_cast<PHINode*>(dyn_cast<PHINode>(I)); ++I) { |
| 477 | |
| 478 | // Create a new machine instr PHI node, and insert it. |
| 479 | unsigned PHIReg = getReg(*PN); |
| 480 | MachineInstr *PhiMI = BuildMI(MBB, PHIInsertPoint, |
| 481 | V8::PHI, PN->getNumOperands(), PHIReg); |
| 482 | |
| 483 | MachineInstr *LongPhiMI = 0; |
| 484 | if (PN->getType() == Type::LongTy || PN->getType() == Type::ULongTy) |
| 485 | LongPhiMI = BuildMI(MBB, PHIInsertPoint, |
| 486 | V8::PHI, PN->getNumOperands(), PHIReg+1); |
| 487 | |
| 488 | // PHIValues - Map of blocks to incoming virtual registers. We use this |
| 489 | // so that we only initialize one incoming value for a particular block, |
| 490 | // even if the block has multiple entries in the PHI node. |
| 491 | // |
| 492 | std::map<MachineBasicBlock*, unsigned> PHIValues; |
| 493 | |
| 494 | for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) { |
| 495 | MachineBasicBlock *PredMBB = 0; |
| 496 | for (MachineBasicBlock::pred_iterator PI = MBB.pred_begin (), |
| 497 | PE = MBB.pred_end (); PI != PE; ++PI) |
| 498 | if (PN->getIncomingBlock(i) == (*PI)->getBasicBlock()) { |
| 499 | PredMBB = *PI; |
| 500 | break; |
| 501 | } |
| 502 | assert (PredMBB && "Couldn't find incoming machine-cfg edge for phi"); |
| 503 | |
| 504 | unsigned ValReg; |
| 505 | std::map<MachineBasicBlock*, unsigned>::iterator EntryIt = |
| 506 | PHIValues.lower_bound(PredMBB); |
| 507 | |
| 508 | if (EntryIt != PHIValues.end() && EntryIt->first == PredMBB) { |
| 509 | // We already inserted an initialization of the register for this |
| 510 | // predecessor. Recycle it. |
| 511 | ValReg = EntryIt->second; |
| 512 | |
| 513 | } else { |
| 514 | // Get the incoming value into a virtual register. |
| 515 | // |
| 516 | Value *Val = PN->getIncomingValue(i); |
| 517 | |
| 518 | // If this is a constant or GlobalValue, we may have to insert code |
| 519 | // into the basic block to compute it into a virtual register. |
| 520 | if ((isa<Constant>(Val) && !isa<ConstantExpr>(Val)) || |
| 521 | isa<GlobalValue>(Val)) { |
| 522 | // Simple constants get emitted at the end of the basic block, |
| 523 | // before any terminator instructions. We "know" that the code to |
| 524 | // move a constant into a register will never clobber any flags. |
| 525 | ValReg = getReg(Val, PredMBB, PredMBB->getFirstTerminator()); |
| 526 | } else { |
| 527 | // Because we don't want to clobber any values which might be in |
| 528 | // physical registers with the computation of this constant (which |
| 529 | // might be arbitrarily complex if it is a constant expression), |
| 530 | // just insert the computation at the top of the basic block. |
| 531 | MachineBasicBlock::iterator PI = PredMBB->begin(); |
| 532 | |
| 533 | // Skip over any PHI nodes though! |
| 534 | while (PI != PredMBB->end() && PI->getOpcode() == V8::PHI) |
| 535 | ++PI; |
| 536 | |
| 537 | ValReg = getReg(Val, PredMBB, PI); |
| 538 | } |
| 539 | |
| 540 | // Remember that we inserted a value for this PHI for this predecessor |
| 541 | PHIValues.insert(EntryIt, std::make_pair(PredMBB, ValReg)); |
| 542 | } |
| 543 | |
| 544 | PhiMI->addRegOperand(ValReg); |
| 545 | PhiMI->addMachineBasicBlockOperand(PredMBB); |
| 546 | if (LongPhiMI) { |
| 547 | LongPhiMI->addRegOperand(ValReg+1); |
| 548 | LongPhiMI->addMachineBasicBlockOperand(PredMBB); |
| 549 | } |
| 550 | } |
| 551 | |
| 552 | // Now that we emitted all of the incoming values for the PHI node, make |
| 553 | // sure to reposition the InsertPoint after the PHI that we just added. |
| 554 | // This is needed because we might have inserted a constant into this |
| 555 | // block, right after the PHI's which is before the old insert point! |
| 556 | PHIInsertPoint = LongPhiMI ? LongPhiMI : PhiMI; |
| 557 | ++PHIInsertPoint; |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
Chris Lattner | 1c809c5 | 2004-02-29 00:27:00 +0000 | [diff] [blame] | 562 | bool V8ISel::runOnFunction(Function &Fn) { |
| 563 | // First pass over the function, lower any unknown intrinsic functions |
| 564 | // with the IntrinsicLowering class. |
| 565 | LowerUnknownIntrinsicFunctionCalls(Fn); |
| 566 | |
| 567 | F = &MachineFunction::construct(&Fn, TM); |
| 568 | |
| 569 | // Create all of the machine basic blocks for the function... |
| 570 | for (Function::iterator I = Fn.begin(), E = Fn.end(); I != E; ++I) |
| 571 | F->getBasicBlockList().push_back(MBBMap[I] = new MachineBasicBlock(I)); |
| 572 | |
| 573 | BB = &F->front(); |
| 574 | |
| 575 | // Set up a frame object for the return address. This is used by the |
| 576 | // llvm.returnaddress & llvm.frameaddress intrinisics. |
| 577 | //ReturnAddressIndex = F->getFrameInfo()->CreateFixedObject(4, -4); |
| 578 | |
| 579 | // Copy incoming arguments off of the stack and out of fixed registers. |
Brian Gaeke | 562cb16 | 2004-04-07 17:04:09 +0000 | [diff] [blame] | 580 | LoadArgumentsToVirtualRegs(&Fn); |
Chris Lattner | 1c809c5 | 2004-02-29 00:27:00 +0000 | [diff] [blame] | 581 | |
| 582 | // Instruction select everything except PHI nodes |
| 583 | visit(Fn); |
| 584 | |
| 585 | // Select the PHI nodes |
Brian Gaeke | 6c868a4 | 2004-06-17 22:34:08 +0000 | [diff] [blame] | 586 | SelectPHINodes(); |
Chris Lattner | 1c809c5 | 2004-02-29 00:27:00 +0000 | [diff] [blame] | 587 | |
| 588 | RegMap.clear(); |
| 589 | MBBMap.clear(); |
| 590 | F = 0; |
| 591 | // We always build a machine code representation for the function |
| 592 | return true; |
| 593 | } |
| 594 | |
Brian Gaeke | 3d11e8a | 2004-04-13 18:27:46 +0000 | [diff] [blame] | 595 | void V8ISel::visitCastInst(CastInst &I) { |
Brian Gaeke | 00e514e | 2004-06-24 06:33:00 +0000 | [diff] [blame] | 596 | Value *Op = I.getOperand(0); |
| 597 | unsigned DestReg = getReg(I); |
| 598 | MachineBasicBlock::iterator MI = BB->end(); |
| 599 | emitCastOperation(BB, MI, Op, I.getType(), DestReg); |
| 600 | } |
| 601 | |
Brian Gaeke | a54df25 | 2004-11-19 18:48:10 +0000 | [diff] [blame] | 602 | unsigned V8ISel::emitIntegerCast (MachineBasicBlock *BB, |
Brian Gaeke | 8b6c1ff | 2004-10-14 19:39:34 +0000 | [diff] [blame] | 603 | MachineBasicBlock::iterator IP, const Type *oldTy, |
| 604 | unsigned SrcReg, const Type *newTy, |
| 605 | unsigned DestReg) { |
| 606 | if (oldTy == newTy) { |
| 607 | // No-op cast - just emit a copy; assume the reg. allocator will zap it. |
| 608 | BuildMI (*BB, IP, V8::ORrr, 2, DestReg).addReg (V8::G0).addReg(SrcReg); |
Brian Gaeke | a54df25 | 2004-11-19 18:48:10 +0000 | [diff] [blame] | 609 | return SrcReg; |
Brian Gaeke | 8b6c1ff | 2004-10-14 19:39:34 +0000 | [diff] [blame] | 610 | } |
| 611 | // Emit left-shift, then right-shift to sign- or zero-extend. |
| 612 | unsigned TmpReg = makeAnotherReg (newTy); |
| 613 | unsigned shiftWidth = 32 - (8 * TM.getTargetData ().getTypeSize (newTy)); |
| 614 | BuildMI (*BB, IP, V8::SLLri, 2, TmpReg).addZImm (shiftWidth).addReg(SrcReg); |
| 615 | if (newTy->isSigned ()) { // sign-extend with SRA |
| 616 | BuildMI(*BB, IP, V8::SRAri, 2, DestReg).addZImm (shiftWidth).addReg(TmpReg); |
| 617 | } else { // zero-extend with SRL |
| 618 | BuildMI(*BB, IP, V8::SRLri, 2, DestReg).addZImm (shiftWidth).addReg(TmpReg); |
| 619 | } |
Brian Gaeke | a54df25 | 2004-11-19 18:48:10 +0000 | [diff] [blame] | 620 | // Return the temp reg. in case this is one half of a cast to long. |
| 621 | return TmpReg; |
Brian Gaeke | 8b6c1ff | 2004-10-14 19:39:34 +0000 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | void V8ISel::emitFPToIntegerCast (MachineBasicBlock *BB, |
| 625 | MachineBasicBlock::iterator IP, |
| 626 | const Type *oldTy, unsigned SrcReg, |
| 627 | const Type *newTy, unsigned DestReg) { |
| 628 | unsigned FPCastOpcode, FPStoreOpcode, FPSize, FPAlign; |
| 629 | unsigned oldTyClass = getClassB(oldTy); |
| 630 | if (oldTyClass == cFloat) { |
| 631 | FPCastOpcode = V8::FSTOI; FPStoreOpcode = V8::STFri; FPSize = 4; |
| 632 | FPAlign = TM.getTargetData().getFloatAlignment(); |
| 633 | } else { // it's a double |
| 634 | FPCastOpcode = V8::FDTOI; FPStoreOpcode = V8::STDFri; FPSize = 8; |
| 635 | FPAlign = TM.getTargetData().getDoubleAlignment(); |
| 636 | } |
| 637 | unsigned TempReg = makeAnotherReg (oldTy); |
| 638 | BuildMI (*BB, IP, FPCastOpcode, 1, TempReg).addReg (SrcReg); |
| 639 | int FI = F->getFrameInfo()->CreateStackObject(FPSize, FPAlign); |
| 640 | BuildMI (*BB, IP, FPStoreOpcode, 3).addFrameIndex (FI).addSImm (0) |
| 641 | .addReg (TempReg); |
| 642 | unsigned TempReg2 = makeAnotherReg (newTy); |
| 643 | BuildMI (*BB, IP, V8::LD, 3, TempReg2).addFrameIndex (FI).addSImm (0); |
| 644 | emitIntegerCast (BB, IP, Type::IntTy, TempReg2, newTy, DestReg); |
| 645 | } |
| 646 | |
Brian Gaeke | 00e514e | 2004-06-24 06:33:00 +0000 | [diff] [blame] | 647 | /// emitCastOperation - Common code shared between visitCastInst and constant |
| 648 | /// expression cast support. |
| 649 | /// |
| 650 | void V8ISel::emitCastOperation(MachineBasicBlock *BB, |
Brian Gaeke | 8b6c1ff | 2004-10-14 19:39:34 +0000 | [diff] [blame] | 651 | MachineBasicBlock::iterator IP, Value *Src, |
| 652 | const Type *DestTy, unsigned DestReg) { |
Brian Gaeke | 00e514e | 2004-06-24 06:33:00 +0000 | [diff] [blame] | 653 | const Type *SrcTy = Src->getType(); |
| 654 | unsigned SrcClass = getClassB(SrcTy); |
| 655 | unsigned DestClass = getClassB(DestTy); |
| 656 | unsigned SrcReg = getReg(Src, BB, IP); |
| 657 | |
| 658 | const Type *oldTy = SrcTy; |
| 659 | const Type *newTy = DestTy; |
| 660 | unsigned oldTyClass = SrcClass; |
| 661 | unsigned newTyClass = DestClass; |
Brian Gaeke | 3d11e8a | 2004-04-13 18:27:46 +0000 | [diff] [blame] | 662 | |
Brian Gaeke | 429022b | 2004-05-08 06:36:14 +0000 | [diff] [blame] | 663 | if (oldTyClass < cLong && newTyClass < cLong) { |
Brian Gaeke | 8b6c1ff | 2004-10-14 19:39:34 +0000 | [diff] [blame] | 664 | emitIntegerCast (BB, IP, oldTy, SrcReg, newTy, DestReg); |
| 665 | } else switch (newTyClass) { |
| 666 | case cByte: |
| 667 | case cShort: |
| 668 | case cInt: |
Brian Gaeke | 495a097 | 2004-06-24 21:22:08 +0000 | [diff] [blame] | 669 | switch (oldTyClass) { |
Brian Gaeke | a54df25 | 2004-11-19 18:48:10 +0000 | [diff] [blame] | 670 | case cLong: |
| 671 | // Treat it like a cast from the lower half of the value. |
| 672 | emitIntegerCast (BB, IP, Type::IntTy, SrcReg+1, newTy, DestReg); |
| 673 | break; |
Brian Gaeke | 8b6c1ff | 2004-10-14 19:39:34 +0000 | [diff] [blame] | 674 | case cFloat: |
| 675 | case cDouble: |
| 676 | emitFPToIntegerCast (BB, IP, oldTy, SrcReg, newTy, DestReg); |
| 677 | break; |
| 678 | default: goto not_yet; |
| 679 | } |
| 680 | return; |
| 681 | |
| 682 | case cFloat: |
| 683 | switch (oldTyClass) { |
| 684 | case cLong: goto not_yet; |
Brian Gaeke | 495a097 | 2004-06-24 21:22:08 +0000 | [diff] [blame] | 685 | case cFloat: |
| 686 | BuildMI (*BB, IP, V8::FMOVS, 1, DestReg).addReg (SrcReg); |
| 687 | break; |
| 688 | case cDouble: |
| 689 | BuildMI (*BB, IP, V8::FDTOS, 1, DestReg).addReg (SrcReg); |
| 690 | break; |
Brian Gaeke | ec3227f | 2004-06-27 22:47:33 +0000 | [diff] [blame] | 691 | default: { |
| 692 | unsigned FltAlign = TM.getTargetData().getFloatAlignment(); |
Brian Gaeke | 8b6c1ff | 2004-10-14 19:39:34 +0000 | [diff] [blame] | 693 | // cast integer type to float. Store it to a stack slot and then load |
Brian Gaeke | 495a097 | 2004-06-24 21:22:08 +0000 | [diff] [blame] | 694 | // it using ldf into a floating point register. then do fitos. |
Brian Gaeke | ec3227f | 2004-06-27 22:47:33 +0000 | [diff] [blame] | 695 | unsigned TmpReg = makeAnotherReg (newTy); |
| 696 | int FI = F->getFrameInfo()->CreateStackObject(4, FltAlign); |
| 697 | BuildMI (*BB, IP, V8::ST, 3).addFrameIndex (FI).addSImm (0) |
| 698 | .addReg (SrcReg); |
| 699 | BuildMI (*BB, IP, V8::LDFri, 2, TmpReg).addFrameIndex (FI).addSImm (0); |
| 700 | BuildMI (*BB, IP, V8::FITOS, 1, DestReg).addReg(TmpReg); |
Brian Gaeke | 495a097 | 2004-06-24 21:22:08 +0000 | [diff] [blame] | 701 | break; |
| 702 | } |
Brian Gaeke | ec3227f | 2004-06-27 22:47:33 +0000 | [diff] [blame] | 703 | } |
Brian Gaeke | 8b6c1ff | 2004-10-14 19:39:34 +0000 | [diff] [blame] | 704 | return; |
| 705 | |
| 706 | case cDouble: |
Brian Gaeke | 495a097 | 2004-06-24 21:22:08 +0000 | [diff] [blame] | 707 | switch (oldTyClass) { |
Brian Gaeke | 8b6c1ff | 2004-10-14 19:39:34 +0000 | [diff] [blame] | 708 | case cLong: goto not_yet; |
Brian Gaeke | 495a097 | 2004-06-24 21:22:08 +0000 | [diff] [blame] | 709 | case cFloat: |
| 710 | BuildMI (*BB, IP, V8::FSTOD, 1, DestReg).addReg (SrcReg); |
| 711 | break; |
Brian Gaeke | 1df468e | 2004-09-29 03:34:41 +0000 | [diff] [blame] | 712 | case cDouble: // use double move pseudo-instr |
| 713 | BuildMI (*BB, IP, V8::FpMOVD, 1, DestReg).addReg (SrcReg); |
Brian Gaeke | 495a097 | 2004-06-24 21:22:08 +0000 | [diff] [blame] | 714 | break; |
Brian Gaeke | ec3227f | 2004-06-27 22:47:33 +0000 | [diff] [blame] | 715 | default: { |
| 716 | unsigned DoubleAlignment = TM.getTargetData().getDoubleAlignment(); |
| 717 | unsigned TmpReg = makeAnotherReg (newTy); |
| 718 | int FI = F->getFrameInfo()->CreateStackObject(8, DoubleAlignment); |
| 719 | BuildMI (*BB, IP, V8::ST, 3).addFrameIndex (FI).addSImm (0) |
| 720 | .addReg (SrcReg); |
| 721 | BuildMI (*BB, IP, V8::LDDFri, 2, TmpReg).addFrameIndex (FI).addSImm (0); |
| 722 | BuildMI (*BB, IP, V8::FITOD, 1, DestReg).addReg(TmpReg); |
| 723 | break; |
| 724 | } |
| 725 | } |
Brian Gaeke | 8b6c1ff | 2004-10-14 19:39:34 +0000 | [diff] [blame] | 726 | return; |
| 727 | |
| 728 | case cLong: |
| 729 | switch (oldTyClass) { |
Brian Gaeke | 7c0afe0 | 2004-11-18 07:43:33 +0000 | [diff] [blame] | 730 | case cByte: |
| 731 | case cShort: |
Brian Gaeke | a54df25 | 2004-11-19 18:48:10 +0000 | [diff] [blame] | 732 | case cInt: { |
| 733 | // Cast to (u)int in the bottom half, and sign(zero) extend in the top |
| 734 | // half. |
| 735 | const Type *OldHalfTy = oldTy->isSigned() ? Type::IntTy : Type::UIntTy; |
| 736 | const Type *NewHalfTy = newTy->isSigned() ? Type::IntTy : Type::UIntTy; |
| 737 | unsigned TempReg = emitIntegerCast (BB, IP, OldHalfTy, SrcReg, |
| 738 | NewHalfTy, DestReg+1); |
| 739 | if (newTy->isSigned ()) { |
| 740 | BuildMI (*BB, IP, V8::SRAri, 2, DestReg).addReg (TempReg) |
| 741 | .addZImm (31); |
| 742 | } else { |
| 743 | BuildMI (*BB, IP, V8::ORrr, 2, DestReg).addReg (V8::G0) |
| 744 | .addReg (V8::G0); |
| 745 | } |
Brian Gaeke | 7c0afe0 | 2004-11-18 07:43:33 +0000 | [diff] [blame] | 746 | break; |
Brian Gaeke | a54df25 | 2004-11-19 18:48:10 +0000 | [diff] [blame] | 747 | } |
Brian Gaeke | 8b6c1ff | 2004-10-14 19:39:34 +0000 | [diff] [blame] | 748 | case cLong: |
Brian Gaeke | 7c0afe0 | 2004-11-18 07:43:33 +0000 | [diff] [blame] | 749 | // Just copy both halves. |
Brian Gaeke | 2a9f539 | 2004-07-08 07:52:13 +0000 | [diff] [blame] | 750 | BuildMI (*BB, IP, V8::ORrr, 2, DestReg).addReg (V8::G0).addReg (SrcReg); |
| 751 | BuildMI (*BB, IP, V8::ORrr, 2, DestReg+1).addReg (V8::G0) |
| 752 | .addReg (SrcReg+1); |
Brian Gaeke | 8b6c1ff | 2004-10-14 19:39:34 +0000 | [diff] [blame] | 753 | break; |
| 754 | default: goto not_yet; |
Brian Gaeke | 2a9f539 | 2004-07-08 07:52:13 +0000 | [diff] [blame] | 755 | } |
Brian Gaeke | 8b6c1ff | 2004-10-14 19:39:34 +0000 | [diff] [blame] | 756 | return; |
| 757 | |
| 758 | default: goto not_yet; |
Brian Gaeke | e302a7e | 2004-05-07 21:39:30 +0000 | [diff] [blame] | 759 | } |
Brian Gaeke | 8b6c1ff | 2004-10-14 19:39:34 +0000 | [diff] [blame] | 760 | return; |
| 761 | not_yet: |
| 762 | std::cerr << "Sorry, cast still unsupported: SrcTy = " << *SrcTy |
| 763 | << ", DestTy = " << *DestTy << "\n"; |
| 764 | abort (); |
Brian Gaeke | 3d11e8a | 2004-04-13 18:27:46 +0000 | [diff] [blame] | 765 | } |
| 766 | |
Brian Gaeke | f3334eb | 2004-04-07 17:29:37 +0000 | [diff] [blame] | 767 | void V8ISel::visitLoadInst(LoadInst &I) { |
| 768 | unsigned DestReg = getReg (I); |
| 769 | unsigned PtrReg = getReg (I.getOperand (0)); |
Brian Gaeke | 532e60c | 2004-05-08 04:21:17 +0000 | [diff] [blame] | 770 | switch (getClassB (I.getType ())) { |
Brian Gaeke | f3334eb | 2004-04-07 17:29:37 +0000 | [diff] [blame] | 771 | case cByte: |
| 772 | if (I.getType ()->isSigned ()) |
Brian Gaeke | 4473303 | 2004-06-24 07:36:48 +0000 | [diff] [blame] | 773 | BuildMI (BB, V8::LDSB, 2, DestReg).addReg (PtrReg).addSImm(0); |
Brian Gaeke | f3334eb | 2004-04-07 17:29:37 +0000 | [diff] [blame] | 774 | else |
Brian Gaeke | 4473303 | 2004-06-24 07:36:48 +0000 | [diff] [blame] | 775 | BuildMI (BB, V8::LDUB, 2, DestReg).addReg (PtrReg).addSImm(0); |
Brian Gaeke | f3334eb | 2004-04-07 17:29:37 +0000 | [diff] [blame] | 776 | return; |
| 777 | case cShort: |
| 778 | if (I.getType ()->isSigned ()) |
Brian Gaeke | 4473303 | 2004-06-24 07:36:48 +0000 | [diff] [blame] | 779 | BuildMI (BB, V8::LDSH, 2, DestReg).addReg (PtrReg).addSImm(0); |
Brian Gaeke | f3334eb | 2004-04-07 17:29:37 +0000 | [diff] [blame] | 780 | else |
Brian Gaeke | 4473303 | 2004-06-24 07:36:48 +0000 | [diff] [blame] | 781 | BuildMI (BB, V8::LDUH, 2, DestReg).addReg (PtrReg).addSImm(0); |
Brian Gaeke | f3334eb | 2004-04-07 17:29:37 +0000 | [diff] [blame] | 782 | return; |
| 783 | case cInt: |
Brian Gaeke | 4473303 | 2004-06-24 07:36:48 +0000 | [diff] [blame] | 784 | BuildMI (BB, V8::LD, 2, DestReg).addReg (PtrReg).addSImm(0); |
Brian Gaeke | f3334eb | 2004-04-07 17:29:37 +0000 | [diff] [blame] | 785 | return; |
| 786 | case cLong: |
Brian Gaeke | 4473303 | 2004-06-24 07:36:48 +0000 | [diff] [blame] | 787 | BuildMI (BB, V8::LD, 2, DestReg).addReg (PtrReg).addSImm(0); |
| 788 | BuildMI (BB, V8::LD, 2, DestReg+1).addReg (PtrReg).addSImm(4); |
| 789 | return; |
| 790 | case cFloat: |
| 791 | BuildMI (BB, V8::LDFri, 2, DestReg).addReg (PtrReg).addSImm(0); |
| 792 | return; |
| 793 | case cDouble: |
| 794 | BuildMI (BB, V8::LDDFri, 2, DestReg).addReg (PtrReg).addSImm(0); |
Brian Gaeke | f3334eb | 2004-04-07 17:29:37 +0000 | [diff] [blame] | 795 | return; |
| 796 | default: |
| 797 | std::cerr << "Load instruction not handled: " << I; |
| 798 | abort (); |
| 799 | return; |
| 800 | } |
| 801 | } |
| 802 | |
| 803 | void V8ISel::visitStoreInst(StoreInst &I) { |
Brian Gaeke | 532e60c | 2004-05-08 04:21:17 +0000 | [diff] [blame] | 804 | Value *SrcVal = I.getOperand (0); |
| 805 | unsigned SrcReg = getReg (SrcVal); |
Brian Gaeke | f3334eb | 2004-04-07 17:29:37 +0000 | [diff] [blame] | 806 | unsigned PtrReg = getReg (I.getOperand (1)); |
Brian Gaeke | 532e60c | 2004-05-08 04:21:17 +0000 | [diff] [blame] | 807 | switch (getClassB (SrcVal->getType ())) { |
| 808 | case cByte: |
Brian Gaeke | 4473303 | 2004-06-24 07:36:48 +0000 | [diff] [blame] | 809 | BuildMI (BB, V8::STB, 3).addReg (PtrReg).addSImm (0).addReg (SrcReg); |
Brian Gaeke | 532e60c | 2004-05-08 04:21:17 +0000 | [diff] [blame] | 810 | return; |
| 811 | case cShort: |
Brian Gaeke | 4473303 | 2004-06-24 07:36:48 +0000 | [diff] [blame] | 812 | BuildMI (BB, V8::STH, 3).addReg (PtrReg).addSImm (0).addReg (SrcReg); |
Brian Gaeke | 532e60c | 2004-05-08 04:21:17 +0000 | [diff] [blame] | 813 | return; |
| 814 | case cInt: |
Brian Gaeke | 4473303 | 2004-06-24 07:36:48 +0000 | [diff] [blame] | 815 | BuildMI (BB, V8::ST, 3).addReg (PtrReg).addSImm (0).addReg (SrcReg); |
Brian Gaeke | 532e60c | 2004-05-08 04:21:17 +0000 | [diff] [blame] | 816 | return; |
| 817 | case cLong: |
Brian Gaeke | 4473303 | 2004-06-24 07:36:48 +0000 | [diff] [blame] | 818 | BuildMI (BB, V8::ST, 3).addReg (PtrReg).addSImm (0).addReg (SrcReg); |
| 819 | BuildMI (BB, V8::ST, 3).addReg (PtrReg).addSImm (4).addReg (SrcReg+1); |
| 820 | return; |
| 821 | case cFloat: |
| 822 | BuildMI (BB, V8::STFri, 3).addReg (PtrReg).addSImm (0).addReg (SrcReg); |
| 823 | return; |
| 824 | case cDouble: |
| 825 | BuildMI (BB, V8::STDFri, 3).addReg (PtrReg).addSImm (0).addReg (SrcReg); |
Brian Gaeke | 532e60c | 2004-05-08 04:21:17 +0000 | [diff] [blame] | 826 | return; |
| 827 | default: |
| 828 | std::cerr << "Store instruction not handled: " << I; |
| 829 | abort (); |
| 830 | return; |
| 831 | } |
Brian Gaeke | f3334eb | 2004-04-07 17:29:37 +0000 | [diff] [blame] | 832 | } |
| 833 | |
Brian Gaeke | f7e44ef | 2004-04-02 20:53:33 +0000 | [diff] [blame] | 834 | void V8ISel::visitCallInst(CallInst &I) { |
Brian Gaeke | 9d67ea0 | 2004-06-18 06:27:48 +0000 | [diff] [blame] | 835 | MachineInstr *TheCall; |
| 836 | // Is it an intrinsic function call? |
| 837 | if (Function *F = I.getCalledFunction()) { |
| 838 | if (Intrinsic::ID ID = (Intrinsic::ID)F->getIntrinsicID()) { |
| 839 | visitIntrinsicCall(ID, I); // Special intrinsics are not handled here |
| 840 | return; |
| 841 | } |
| 842 | } |
| 843 | |
Brian Gaeke | 50094ed | 2004-10-10 19:57:18 +0000 | [diff] [blame] | 844 | // How much extra call stack will we need? |
Brian Gaeke | 79fe833 | 2004-11-21 03:35:22 +0000 | [diff] [blame] | 845 | int extraStack = 0; |
| 846 | for (unsigned i = 0; i < I.getNumOperands (); ++i) { |
Brian Gaeke | 50094ed | 2004-10-10 19:57:18 +0000 | [diff] [blame] | 847 | switch (getClassB (I.getOperand (i)->getType ())) { |
| 848 | case cLong: extraStack += 8; break; |
| 849 | case cFloat: extraStack += 4; break; |
| 850 | case cDouble: extraStack += 8; break; |
| 851 | default: extraStack += 4; break; |
| 852 | } |
| 853 | } |
Brian Gaeke | 79fe833 | 2004-11-21 03:35:22 +0000 | [diff] [blame] | 854 | extraStack -= 24; |
| 855 | if (extraStack < 0) { |
| 856 | extraStack = 0; |
| 857 | } else { |
| 858 | // Round up extra stack size to the nearest doubleword. |
| 859 | extraStack = (extraStack + 7) & ~7; |
| 860 | } |
Brian Gaeke | 50094ed | 2004-10-10 19:57:18 +0000 | [diff] [blame] | 861 | |
Brian Gaeke | 9d67ea0 | 2004-06-18 06:27:48 +0000 | [diff] [blame] | 862 | // Deal with args |
Brian Gaeke | 562cb16 | 2004-04-07 17:04:09 +0000 | [diff] [blame] | 863 | static const unsigned OutgoingArgRegs[] = { V8::O0, V8::O1, V8::O2, V8::O3, |
Brian Gaeke | d54c38b | 2004-04-07 16:41:22 +0000 | [diff] [blame] | 864 | V8::O4, V8::O5 }; |
Brian Gaeke | 24b90c3 | 2004-11-14 03:22:07 +0000 | [diff] [blame] | 865 | const unsigned *OAREnd = &OutgoingArgRegs[6]; |
Brian Gaeke | 6931fd6 | 2004-11-04 00:27:04 +0000 | [diff] [blame] | 866 | const unsigned *OAR = &OutgoingArgRegs[0]; |
Brian Gaeke | 24b90c3 | 2004-11-14 03:22:07 +0000 | [diff] [blame] | 867 | unsigned ArgOffset = 68; |
Brian Gaeke | da9b366 | 2004-11-14 06:32:08 +0000 | [diff] [blame] | 868 | if (extraStack) BuildMI (BB, V8::ADJCALLSTACKDOWN, 1).addImm (extraStack); |
Brian Gaeke | 50094ed | 2004-10-10 19:57:18 +0000 | [diff] [blame] | 869 | for (unsigned i = 1; i < I.getNumOperands (); ++i) { |
| 870 | unsigned ArgReg = getReg (I.getOperand (i)); |
Brian Gaeke | 24b90c3 | 2004-11-14 03:22:07 +0000 | [diff] [blame] | 871 | if (getClassB (I.getOperand (i)->getType ()) < cLong) { |
| 872 | // Schlep it over into the incoming arg register |
| 873 | if (ArgOffset < 92) { |
| 874 | assert (OAR != OAREnd && "About to dereference past end of OutgoingArgRegs"); |
| 875 | BuildMI (BB, V8::ORrr, 2, *OAR++).addReg (V8::G0).addReg (ArgReg); |
Brian Gaeke | 812c488 | 2004-07-16 10:31:25 +0000 | [diff] [blame] | 876 | } else { |
Brian Gaeke | 24b90c3 | 2004-11-14 03:22:07 +0000 | [diff] [blame] | 877 | BuildMI (BB, V8::ST, 3).addReg (V8::SP).addSImm (ArgOffset).addReg (ArgReg); |
Brian Gaeke | 812c488 | 2004-07-16 10:31:25 +0000 | [diff] [blame] | 878 | } |
Brian Gaeke | 24b90c3 | 2004-11-14 03:22:07 +0000 | [diff] [blame] | 879 | ArgOffset += 4; |
| 880 | } else if (getClassB (I.getOperand (i)->getType ()) == cFloat) { |
| 881 | if (ArgOffset < 92) { |
| 882 | // Single-fp args are passed in integer registers; go through |
| 883 | // memory to get them out of FP registers. (Bleh!) |
| 884 | unsigned FltAlign = TM.getTargetData().getFloatAlignment(); |
| 885 | int FI = F->getFrameInfo()->CreateStackObject(4, FltAlign); |
| 886 | BuildMI (BB, V8::STFri, 3).addFrameIndex (FI).addSImm (0).addReg (ArgReg); |
| 887 | assert (OAR != OAREnd && "About to dereference past end of OutgoingArgRegs"); |
| 888 | BuildMI (BB, V8::LD, 2, *OAR++).addFrameIndex (FI).addSImm (0); |
| 889 | } else { |
| 890 | BuildMI (BB, V8::STFri, 3).addReg (V8::SP).addSImm (ArgOffset).addReg (ArgReg); |
| 891 | } |
| 892 | ArgOffset += 4; |
| 893 | } else if (getClassB (I.getOperand (i)->getType ()) == cDouble) { |
| 894 | // Double-fp args are passed in pairs of integer registers; go through |
| 895 | // memory to get them out of FP registers. (Bleh!) |
| 896 | // We'd like to 'std' these right onto the outgoing-args area, but it might |
| 897 | // not be 8-byte aligned (e.g., call x(int x, double d)). sigh. |
| 898 | unsigned DblAlign = TM.getTargetData().getDoubleAlignment(); |
| 899 | int FI = F->getFrameInfo()->CreateStackObject(8, DblAlign); |
| 900 | BuildMI (BB, V8::STDFri, 3).addFrameIndex (FI).addSImm (0).addReg (ArgReg); |
| 901 | if (ArgOffset < 92 && OAR != OAREnd) { |
| 902 | assert (OAR != OAREnd && "About to dereference past end of OutgoingArgRegs"); |
| 903 | BuildMI (BB, V8::LD, 2, *OAR++).addFrameIndex (FI).addSImm (0); |
| 904 | } else { |
| 905 | unsigned TempReg = makeAnotherReg (Type::IntTy); |
| 906 | BuildMI (BB, V8::LD, 2, TempReg).addFrameIndex (FI).addSImm (0); |
| 907 | BuildMI (BB, V8::ST, 3).addReg (V8::SP).addSImm (ArgOffset).addReg (TempReg); |
| 908 | } |
| 909 | ArgOffset += 4; |
| 910 | if (ArgOffset < 92 && OAR != OAREnd) { |
| 911 | assert (OAR != OAREnd && "About to dereference past end of OutgoingArgRegs"); |
| 912 | BuildMI (BB, V8::LD, 2, *OAR++).addFrameIndex (FI).addSImm (4); |
| 913 | } else { |
| 914 | unsigned TempReg = makeAnotherReg (Type::IntTy); |
| 915 | BuildMI (BB, V8::LD, 2, TempReg).addFrameIndex (FI).addSImm (4); |
| 916 | BuildMI (BB, V8::ST, 3).addReg (V8::SP).addSImm (ArgOffset).addReg (TempReg); |
| 917 | } |
| 918 | ArgOffset += 4; |
| 919 | } else if (getClassB (I.getOperand (i)->getType ()) == cLong) { |
| 920 | // do the first half... |
| 921 | if (ArgOffset < 92) { |
| 922 | assert (OAR != OAREnd && "About to dereference past end of OutgoingArgRegs"); |
| 923 | BuildMI (BB, V8::ORrr, 2, *OAR++).addReg (V8::G0).addReg (ArgReg); |
| 924 | } else { |
| 925 | BuildMI (BB, V8::ST, 3).addReg (V8::SP).addSImm (ArgOffset).addReg (ArgReg); |
| 926 | } |
| 927 | ArgOffset += 4; |
| 928 | // ...then do the second half |
| 929 | if (ArgOffset < 92) { |
| 930 | assert (OAR != OAREnd && "About to dereference past end of OutgoingArgRegs"); |
| 931 | BuildMI (BB, V8::ORrr, 2, *OAR++).addReg (V8::G0).addReg (ArgReg+1); |
| 932 | } else { |
| 933 | BuildMI (BB, V8::ST, 3).addReg (V8::SP).addSImm (ArgOffset).addReg (ArgReg+1); |
| 934 | } |
| 935 | ArgOffset += 4; |
Brian Gaeke | 50094ed | 2004-10-10 19:57:18 +0000 | [diff] [blame] | 936 | } else { |
Brian Gaeke | 24b90c3 | 2004-11-14 03:22:07 +0000 | [diff] [blame] | 937 | assert (0 && "Unknown class?!"); |
Brian Gaeke | d54c38b | 2004-04-07 16:41:22 +0000 | [diff] [blame] | 938 | } |
Brian Gaeke | 50094ed | 2004-10-10 19:57:18 +0000 | [diff] [blame] | 939 | } |
Brian Gaeke | d54c38b | 2004-04-07 16:41:22 +0000 | [diff] [blame] | 940 | |
Brian Gaeke | 9d67ea0 | 2004-06-18 06:27:48 +0000 | [diff] [blame] | 941 | // Emit call instruction |
| 942 | if (Function *F = I.getCalledFunction ()) { |
| 943 | BuildMI (BB, V8::CALL, 1).addGlobalAddress (F, true); |
| 944 | } else { // Emit an indirect call... |
| 945 | unsigned Reg = getReg (I.getCalledValue ()); |
| 946 | BuildMI (BB, V8::JMPLrr, 3, V8::O7).addReg (Reg).addReg (V8::G0); |
| 947 | } |
| 948 | |
Brian Gaeke | 50094ed | 2004-10-10 19:57:18 +0000 | [diff] [blame] | 949 | if (extraStack) BuildMI (BB, V8::ADJCALLSTACKUP, 1).addImm (extraStack); |
| 950 | |
Brian Gaeke | 9d67ea0 | 2004-06-18 06:27:48 +0000 | [diff] [blame] | 951 | // Deal w/ return value: schlep it over into the destination register |
Brian Gaeke | e14e338 | 2004-06-15 20:06:32 +0000 | [diff] [blame] | 952 | if (I.getType () == Type::VoidTy) |
Brian Gaeke | ea8494b | 2004-04-06 22:09:23 +0000 | [diff] [blame] | 953 | return; |
Brian Gaeke | e14e338 | 2004-06-15 20:06:32 +0000 | [diff] [blame] | 954 | unsigned DestReg = getReg (I); |
Brian Gaeke | 299b39d | 2004-10-10 20:34:17 +0000 | [diff] [blame] | 955 | switch (getClassB (I.getType ())) { |
Brian Gaeke | ea8494b | 2004-04-06 22:09:23 +0000 | [diff] [blame] | 956 | case cByte: |
| 957 | case cShort: |
| 958 | case cInt: |
Brian Gaeke | ea8494b | 2004-04-06 22:09:23 +0000 | [diff] [blame] | 959 | BuildMI (BB, V8::ORrr, 2, DestReg).addReg(V8::G0).addReg(V8::O0); |
| 960 | break; |
Brian Gaeke | 9d67ea0 | 2004-06-18 06:27:48 +0000 | [diff] [blame] | 961 | case cFloat: |
| 962 | BuildMI (BB, V8::FMOVS, 2, DestReg).addReg(V8::F0); |
| 963 | break; |
Brian Gaeke | 1df468e | 2004-09-29 03:34:41 +0000 | [diff] [blame] | 964 | case cDouble: |
| 965 | BuildMI (BB, V8::FpMOVD, 2, DestReg).addReg(V8::D0); |
| 966 | break; |
| 967 | case cLong: |
| 968 | BuildMI (BB, V8::ORrr, 2, DestReg).addReg(V8::G0).addReg(V8::O0); |
| 969 | BuildMI (BB, V8::ORrr, 2, DestReg+1).addReg(V8::G0).addReg(V8::O1); |
| 970 | break; |
Brian Gaeke | ea8494b | 2004-04-06 22:09:23 +0000 | [diff] [blame] | 971 | default: |
Brian Gaeke | 532e60c | 2004-05-08 04:21:17 +0000 | [diff] [blame] | 972 | std::cerr << "Return type of call instruction not handled: " << I; |
| 973 | abort (); |
Brian Gaeke | ea8494b | 2004-04-06 22:09:23 +0000 | [diff] [blame] | 974 | } |
Brian Gaeke | f7e44ef | 2004-04-02 20:53:33 +0000 | [diff] [blame] | 975 | } |
Chris Lattner | 1c809c5 | 2004-02-29 00:27:00 +0000 | [diff] [blame] | 976 | |
| 977 | void V8ISel::visitReturnInst(ReturnInst &I) { |
Brian Gaeke | 08f64c3 | 2004-03-06 05:32:28 +0000 | [diff] [blame] | 978 | if (I.getNumOperands () == 1) { |
| 979 | unsigned RetValReg = getReg (I.getOperand (0)); |
Brian Gaeke | 299b39d | 2004-10-10 20:34:17 +0000 | [diff] [blame] | 980 | switch (getClassB (I.getOperand (0)->getType ())) { |
Brian Gaeke | 08f64c3 | 2004-03-06 05:32:28 +0000 | [diff] [blame] | 981 | case cByte: |
| 982 | case cShort: |
| 983 | case cInt: |
| 984 | // Schlep it over into i0 (where it will become o0 after restore). |
| 985 | BuildMI (BB, V8::ORrr, 2, V8::I0).addReg(V8::G0).addReg(RetValReg); |
| 986 | break; |
Brian Gaeke | f9a7546 | 2004-07-08 07:22:27 +0000 | [diff] [blame] | 987 | case cFloat: |
Brian Gaeke | 1df468e | 2004-09-29 03:34:41 +0000 | [diff] [blame] | 988 | BuildMI (BB, V8::FMOVS, 1, V8::F0).addReg(RetValReg); |
Brian Gaeke | f9a7546 | 2004-07-08 07:22:27 +0000 | [diff] [blame] | 989 | break; |
Brian Gaeke | 1df468e | 2004-09-29 03:34:41 +0000 | [diff] [blame] | 990 | case cDouble: |
| 991 | BuildMI (BB, V8::FpMOVD, 1, V8::D0).addReg(RetValReg); |
Brian Gaeke | 812c488 | 2004-07-16 10:31:25 +0000 | [diff] [blame] | 992 | break; |
Brian Gaeke | 2a9f539 | 2004-07-08 07:52:13 +0000 | [diff] [blame] | 993 | case cLong: |
| 994 | BuildMI (BB, V8::ORrr, 2, V8::I0).addReg(V8::G0).addReg(RetValReg); |
| 995 | BuildMI (BB, V8::ORrr, 2, V8::I1).addReg(V8::G0).addReg(RetValReg+1); |
| 996 | break; |
Brian Gaeke | 08f64c3 | 2004-03-06 05:32:28 +0000 | [diff] [blame] | 997 | default: |
Brian Gaeke | 532e60c | 2004-05-08 04:21:17 +0000 | [diff] [blame] | 998 | std::cerr << "Return instruction of this type not handled: " << I; |
| 999 | abort (); |
Brian Gaeke | 08f64c3 | 2004-03-06 05:32:28 +0000 | [diff] [blame] | 1000 | } |
Chris Lattner | 1c809c5 | 2004-02-29 00:27:00 +0000 | [diff] [blame] | 1001 | } |
Chris Lattner | 0d538bb | 2004-04-07 04:36:53 +0000 | [diff] [blame] | 1002 | |
Brian Gaeke | 08f64c3 | 2004-03-06 05:32:28 +0000 | [diff] [blame] | 1003 | // Just emit a 'retl' instruction to return. |
| 1004 | BuildMI(BB, V8::RETL, 0); |
| 1005 | return; |
Chris Lattner | 1c809c5 | 2004-02-29 00:27:00 +0000 | [diff] [blame] | 1006 | } |
| 1007 | |
Brian Gaeke | 532e60c | 2004-05-08 04:21:17 +0000 | [diff] [blame] | 1008 | static inline BasicBlock *getBlockAfter(BasicBlock *BB) { |
| 1009 | Function::iterator I = BB; ++I; // Get iterator to next block |
| 1010 | return I != BB->getParent()->end() ? &*I : 0; |
| 1011 | } |
| 1012 | |
Brian Gaeke | 6a8c46c | 2004-12-12 06:01:26 +0000 | [diff] [blame^] | 1013 | /// canFoldSetCCIntoBranch - Return the setcc instruction if we can fold it |
| 1014 | /// into the conditional branch which is the only user of the cc instruction. |
| 1015 | /// This is the case if the conditional branch is the only user of the setcc. |
| 1016 | /// |
| 1017 | static SetCondInst *canFoldSetCCIntoBranch(Value *V) { |
| 1018 | return 0; // disable. |
| 1019 | } |
| 1020 | |
Brian Gaeke | 532e60c | 2004-05-08 04:21:17 +0000 | [diff] [blame] | 1021 | /// visitBranchInst - Handles conditional and unconditional branches. |
| 1022 | /// |
| 1023 | void V8ISel::visitBranchInst(BranchInst &I) { |
Brian Gaeke | 532e60c | 2004-05-08 04:21:17 +0000 | [diff] [blame] | 1024 | BasicBlock *takenSucc = I.getSuccessor (0); |
Brian Gaeke | 6c868a4 | 2004-06-17 22:34:08 +0000 | [diff] [blame] | 1025 | MachineBasicBlock *takenSuccMBB = MBBMap[takenSucc]; |
| 1026 | BB->addSuccessor (takenSuccMBB); |
| 1027 | if (I.isConditional()) { // conditional branch |
| 1028 | BasicBlock *notTakenSucc = I.getSuccessor (1); |
| 1029 | MachineBasicBlock *notTakenSuccMBB = MBBMap[notTakenSucc]; |
| 1030 | BB->addSuccessor (notTakenSuccMBB); |
Brian Gaeke | 532e60c | 2004-05-08 04:21:17 +0000 | [diff] [blame] | 1031 | |
Brian Gaeke | 6c868a4 | 2004-06-17 22:34:08 +0000 | [diff] [blame] | 1032 | // CondReg=(<condition>); |
| 1033 | // If (CondReg==0) goto notTakenSuccMBB; |
| 1034 | unsigned CondReg = getReg (I.getCondition ()); |
| 1035 | BuildMI (BB, V8::CMPri, 2).addSImm (0).addReg (CondReg); |
| 1036 | BuildMI (BB, V8::BE, 1).addMBB (notTakenSuccMBB); |
Brian Gaeke | 532e60c | 2004-05-08 04:21:17 +0000 | [diff] [blame] | 1037 | } |
Brian Gaeke | 6c868a4 | 2004-06-17 22:34:08 +0000 | [diff] [blame] | 1038 | // goto takenSuccMBB; |
| 1039 | BuildMI (BB, V8::BA, 1).addMBB (takenSuccMBB); |
Brian Gaeke | 532e60c | 2004-05-08 04:21:17 +0000 | [diff] [blame] | 1040 | } |
| 1041 | |
| 1042 | /// emitGEPOperation - Common code shared between visitGetElementPtrInst and |
| 1043 | /// constant expression GEP support. |
| 1044 | /// |
Brian Gaeke | 9f56482 | 2004-05-08 05:27:20 +0000 | [diff] [blame] | 1045 | void V8ISel::emitGEPOperation (MachineBasicBlock *MBB, |
Brian Gaeke | 532e60c | 2004-05-08 04:21:17 +0000 | [diff] [blame] | 1046 | MachineBasicBlock::iterator IP, |
| 1047 | Value *Src, User::op_iterator IdxBegin, |
| 1048 | User::op_iterator IdxEnd, unsigned TargetReg) { |
Brian Gaeke | 9f56482 | 2004-05-08 05:27:20 +0000 | [diff] [blame] | 1049 | const TargetData &TD = TM.getTargetData (); |
| 1050 | const Type *Ty = Src->getType (); |
Brian Gaeke | c7fd0f4 | 2004-06-24 08:55:09 +0000 | [diff] [blame] | 1051 | unsigned basePtrReg = getReg (Src, MBB, IP); |
Brian Gaeke | 9f56482 | 2004-05-08 05:27:20 +0000 | [diff] [blame] | 1052 | |
| 1053 | // GEPs have zero or more indices; we must perform a struct access |
| 1054 | // or array access for each one. |
| 1055 | for (GetElementPtrInst::op_iterator oi = IdxBegin, oe = IdxEnd; oi != oe; |
| 1056 | ++oi) { |
| 1057 | Value *idx = *oi; |
| 1058 | unsigned nextBasePtrReg = makeAnotherReg (Type::UIntTy); |
| 1059 | if (const StructType *StTy = dyn_cast<StructType> (Ty)) { |
| 1060 | // It's a struct access. idx is the index into the structure, |
| 1061 | // which names the field. Use the TargetData structure to |
| 1062 | // pick out what the layout of the structure is in memory. |
| 1063 | // Use the (constant) structure index's value to find the |
| 1064 | // right byte offset from the StructLayout class's list of |
| 1065 | // structure member offsets. |
| 1066 | unsigned fieldIndex = cast<ConstantUInt> (idx)->getValue (); |
| 1067 | unsigned memberOffset = |
| 1068 | TD.getStructLayout (StTy)->MemberOffsets[fieldIndex]; |
| 1069 | // Emit an ADD to add memberOffset to the basePtr. |
Brian Gaeke | 4f70b63 | 2004-12-11 05:19:02 +0000 | [diff] [blame] | 1070 | // We might have to copy memberOffset into a register first, if |
| 1071 | // it's big. |
Brian Gaeke | 31e5759 | 2004-11-24 04:07:33 +0000 | [diff] [blame] | 1072 | if (memberOffset + 4096 < 8191) { |
| 1073 | BuildMI (*MBB, IP, V8::ADDri, 2, |
| 1074 | nextBasePtrReg).addReg (basePtrReg).addSImm (memberOffset); |
| 1075 | } else { |
| 1076 | unsigned offsetReg = makeAnotherReg (Type::IntTy); |
| 1077 | copyConstantToRegister (MBB, IP, |
Brian Gaeke | 4f70b63 | 2004-12-11 05:19:02 +0000 | [diff] [blame] | 1078 | ConstantSInt::get(Type::IntTy, memberOffset), offsetReg); |
Brian Gaeke | 31e5759 | 2004-11-24 04:07:33 +0000 | [diff] [blame] | 1079 | BuildMI (*MBB, IP, V8::ADDrr, 2, |
| 1080 | nextBasePtrReg).addReg (basePtrReg).addReg (offsetReg); |
| 1081 | } |
Brian Gaeke | 9f56482 | 2004-05-08 05:27:20 +0000 | [diff] [blame] | 1082 | // The next type is the member of the structure selected by the |
| 1083 | // index. |
| 1084 | Ty = StTy->getElementType (fieldIndex); |
| 1085 | } else if (const SequentialType *SqTy = dyn_cast<SequentialType> (Ty)) { |
| 1086 | // It's an array or pointer access: [ArraySize x ElementType]. |
| 1087 | // We want to add basePtrReg to (idxReg * sizeof ElementType). First, we |
| 1088 | // must find the size of the pointed-to type (Not coincidentally, the next |
| 1089 | // type is the type of the elements in the array). |
| 1090 | Ty = SqTy->getElementType (); |
| 1091 | unsigned elementSize = TD.getTypeSize (Ty); |
Brian Gaeke | 4f70b63 | 2004-12-11 05:19:02 +0000 | [diff] [blame] | 1092 | unsigned OffsetReg = ~0U; |
| 1093 | int64_t Offset = -1; |
| 1094 | bool addImmed = false; |
| 1095 | if (isa<ConstantIntegral> (idx)) { |
| 1096 | // If idx is a constant, we don't have to emit the multiply. |
| 1097 | int64_t Val = cast<ConstantIntegral> (idx)->getRawValue (); |
| 1098 | if ((Val * elementSize) + 4096 < 8191) { |
| 1099 | // (Val * elementSize) is constant and fits in an immediate field. |
| 1100 | // emit: nextBasePtrReg = ADDri basePtrReg, (Val * elementSize) |
| 1101 | addImmed = true; |
| 1102 | Offset = Val * elementSize; |
| 1103 | } else { |
| 1104 | // (Val * elementSize) is constant, but doesn't fit in an immediate |
| 1105 | // field. emit: OffsetReg = (Val * elementSize) |
| 1106 | // nextBasePtrReg = ADDrr OffsetReg, basePtrReg |
| 1107 | OffsetReg = makeAnotherReg (Type::IntTy); |
| 1108 | copyConstantToRegister (MBB, IP, |
| 1109 | ConstantSInt::get(Type::IntTy, Val * elementSize), OffsetReg); |
| 1110 | } |
| 1111 | } else { |
| 1112 | // idx is not constant, we have to shift or multiply. |
| 1113 | OffsetReg = makeAnotherReg (Type::IntTy); |
| 1114 | unsigned idxReg = getReg (idx, MBB, IP); |
| 1115 | switch (elementSize) { |
| 1116 | case 1: |
| 1117 | BuildMI (*MBB, IP, V8::ORrr, 2, OffsetReg).addReg (V8::G0).addReg (idxReg); |
| 1118 | break; |
| 1119 | case 2: |
| 1120 | BuildMI (*MBB, IP, V8::SLLri, 2, OffsetReg).addReg (idxReg).addZImm (1); |
| 1121 | break; |
| 1122 | case 4: |
| 1123 | BuildMI (*MBB, IP, V8::SLLri, 2, OffsetReg).addReg (idxReg).addZImm (2); |
| 1124 | break; |
| 1125 | case 8: |
| 1126 | BuildMI (*MBB, IP, V8::SLLri, 2, OffsetReg).addReg (idxReg).addZImm (3); |
| 1127 | break; |
| 1128 | default: { |
| 1129 | if (elementSize + 4096 < 8191) { |
| 1130 | // Emit a SMUL to multiply the register holding the index by |
| 1131 | // elementSize, putting the result in OffsetReg. |
| 1132 | BuildMI (*MBB, IP, V8::SMULri, 2, |
| 1133 | OffsetReg).addReg (idxReg).addSImm (elementSize); |
| 1134 | } else { |
| 1135 | unsigned elementSizeReg = makeAnotherReg (Type::UIntTy); |
| 1136 | copyConstantToRegister (MBB, IP, |
| 1137 | ConstantUInt::get(Type::UIntTy, elementSize), elementSizeReg); |
| 1138 | // Emit a SMUL to multiply the register holding the index by |
| 1139 | // the register w/ elementSize, putting the result in OffsetReg. |
| 1140 | BuildMI (*MBB, IP, V8::SMULrr, 2, |
| 1141 | OffsetReg).addReg (idxReg).addReg (elementSizeReg); |
| 1142 | } |
| 1143 | break; |
| 1144 | } |
| 1145 | } |
| 1146 | } |
| 1147 | if (addImmed) { |
| 1148 | // Emit an ADD to add the constant immediate Offset to the basePtr. |
| 1149 | BuildMI (*MBB, IP, V8::ADDri, 2, |
| 1150 | nextBasePtrReg).addReg (basePtrReg).addSImm (Offset); |
| 1151 | } else { |
| 1152 | // Emit an ADD to add OffsetReg to the basePtr. |
| 1153 | BuildMI (*MBB, IP, V8::ADDrr, 2, |
| 1154 | nextBasePtrReg).addReg (basePtrReg).addReg (OffsetReg); |
| 1155 | } |
Brian Gaeke | 9f56482 | 2004-05-08 05:27:20 +0000 | [diff] [blame] | 1156 | } |
| 1157 | basePtrReg = nextBasePtrReg; |
| 1158 | } |
| 1159 | // After we have processed all the indices, the result is left in |
| 1160 | // basePtrReg. Move it to the register where we were expected to |
| 1161 | // put the answer. |
| 1162 | BuildMI (BB, V8::ORrr, 1, TargetReg).addReg (V8::G0).addReg (basePtrReg); |
Brian Gaeke | 532e60c | 2004-05-08 04:21:17 +0000 | [diff] [blame] | 1163 | } |
| 1164 | |
| 1165 | void V8ISel::visitGetElementPtrInst (GetElementPtrInst &I) { |
| 1166 | unsigned outputReg = getReg (I); |
| 1167 | emitGEPOperation (BB, BB->end (), I.getOperand (0), |
| 1168 | I.op_begin ()+1, I.op_end (), outputReg); |
| 1169 | } |
| 1170 | |
Brian Gaeke | 5f91de2 | 2004-11-21 07:13:16 +0000 | [diff] [blame] | 1171 | void V8ISel::emitOp64LibraryCall (MachineBasicBlock *MBB, |
| 1172 | MachineBasicBlock::iterator IP, |
| 1173 | unsigned DestReg, |
| 1174 | const char *FuncName, |
| 1175 | unsigned Op0Reg, unsigned Op1Reg) { |
| 1176 | BuildMI (*MBB, IP, V8::ORrr, 2, V8::O0).addReg (V8::G0).addReg (Op0Reg); |
| 1177 | BuildMI (*MBB, IP, V8::ORrr, 2, V8::O1).addReg (V8::G0).addReg (Op0Reg+1); |
| 1178 | BuildMI (*MBB, IP, V8::ORrr, 2, V8::O2).addReg (V8::G0).addReg (Op1Reg); |
| 1179 | BuildMI (*MBB, IP, V8::ORrr, 2, V8::O3).addReg (V8::G0).addReg (Op1Reg+1); |
| 1180 | BuildMI (*MBB, IP, V8::CALL, 1).addExternalSymbol (FuncName, true); |
| 1181 | BuildMI (*MBB, IP, V8::ORrr, 2, DestReg).addReg (V8::G0).addReg (V8::O0); |
| 1182 | BuildMI (*MBB, IP, V8::ORrr, 2, DestReg+1).addReg (V8::G0).addReg (V8::O1); |
| 1183 | } |
Brian Gaeke | d6a1053 | 2004-06-15 21:09:46 +0000 | [diff] [blame] | 1184 | |
Brian Gaeke | 9ffcf9f | 2004-11-22 08:02:06 +0000 | [diff] [blame] | 1185 | void V8ISel::emitShift64 (MachineBasicBlock *MBB, |
| 1186 | MachineBasicBlock::iterator IP, Instruction &I, |
Brian Gaeke | fbe558c | 2004-11-23 08:14:09 +0000 | [diff] [blame] | 1187 | unsigned DestReg, unsigned SrcReg, |
| 1188 | unsigned ShiftAmtReg) { |
Brian Gaeke | 9ffcf9f | 2004-11-22 08:02:06 +0000 | [diff] [blame] | 1189 | bool isSigned = I.getType()->isSigned(); |
| 1190 | |
| 1191 | switch (I.getOpcode ()) { |
Brian Gaeke | 88108b8 | 2004-11-23 21:10:50 +0000 | [diff] [blame] | 1192 | case Instruction::Shr: { |
| 1193 | unsigned CarryReg = makeAnotherReg (Type::IntTy), |
| 1194 | ThirtyTwo = makeAnotherReg (Type::IntTy), |
| 1195 | HalfShiftReg = makeAnotherReg (Type::IntTy), |
| 1196 | NegHalfShiftReg = makeAnotherReg (Type::IntTy), |
| 1197 | TempReg = makeAnotherReg (Type::IntTy); |
| 1198 | unsigned OneShiftOutReg = makeAnotherReg (Type::ULongTy), |
| 1199 | TwoShiftsOutReg = makeAnotherReg (Type::ULongTy); |
| 1200 | |
| 1201 | MachineBasicBlock *thisMBB = BB; |
| 1202 | const BasicBlock *LLVM_BB = BB->getBasicBlock (); |
| 1203 | MachineBasicBlock *shiftMBB = new MachineBasicBlock (LLVM_BB); |
| 1204 | F->getBasicBlockList ().push_back (shiftMBB); |
| 1205 | MachineBasicBlock *oneShiftMBB = new MachineBasicBlock (LLVM_BB); |
| 1206 | F->getBasicBlockList ().push_back (oneShiftMBB); |
| 1207 | MachineBasicBlock *twoShiftsMBB = new MachineBasicBlock (LLVM_BB); |
| 1208 | F->getBasicBlockList ().push_back (twoShiftsMBB); |
| 1209 | MachineBasicBlock *continueMBB = new MachineBasicBlock (LLVM_BB); |
| 1210 | F->getBasicBlockList ().push_back (continueMBB); |
| 1211 | |
| 1212 | // .lshr_begin: |
| 1213 | // ... |
| 1214 | // subcc %g0, ShiftAmtReg, %g0 ! Is ShAmt == 0? |
| 1215 | // be .lshr_continue ! Then don't shift. |
| 1216 | // ba .lshr_shift ! else shift. |
| 1217 | |
| 1218 | BuildMI (BB, V8::SUBCCrr, 2, V8::G0).addReg (V8::G0) |
| 1219 | .addReg (ShiftAmtReg); |
| 1220 | BuildMI (BB, V8::BE, 1).addMBB (continueMBB); |
| 1221 | BuildMI (BB, V8::BA, 1).addMBB (shiftMBB); |
| 1222 | |
| 1223 | // Update machine-CFG edges |
| 1224 | BB->addSuccessor (continueMBB); |
| 1225 | BB->addSuccessor (shiftMBB); |
| 1226 | |
| 1227 | // .lshr_shift: ! [preds: begin] |
| 1228 | // or %g0, 32, ThirtyTwo |
| 1229 | // subcc ThirtyTwo, ShiftAmtReg, HalfShiftReg ! Calculate 32 - shamt |
| 1230 | // bg .lshr_two_shifts ! If >0, b two_shifts |
| 1231 | // ba .lshr_one_shift ! else one_shift. |
| 1232 | |
| 1233 | BB = shiftMBB; |
| 1234 | |
| 1235 | BuildMI (BB, V8::ORri, 2, ThirtyTwo).addReg (V8::G0).addSImm (32); |
| 1236 | BuildMI (BB, V8::SUBCCrr, 2, HalfShiftReg).addReg (ThirtyTwo) |
| 1237 | .addReg (ShiftAmtReg); |
| 1238 | BuildMI (BB, V8::BG, 1).addMBB (twoShiftsMBB); |
| 1239 | BuildMI (BB, V8::BA, 1).addMBB (oneShiftMBB); |
| 1240 | |
| 1241 | // Update machine-CFG edges |
| 1242 | BB->addSuccessor (twoShiftsMBB); |
| 1243 | BB->addSuccessor (oneShiftMBB); |
| 1244 | |
| 1245 | // .lshr_two_shifts: ! [preds: shift] |
| 1246 | // sll SrcReg, HalfShiftReg, CarryReg ! Save the borrows |
| 1247 | // ! <SHIFT> in following is sra if signed, srl if unsigned |
| 1248 | // <SHIFT> SrcReg, ShiftAmtReg, TwoShiftsOutReg ! Shift top half |
| 1249 | // srl SrcReg+1, ShiftAmtReg, TempReg ! Shift bottom half |
| 1250 | // or TempReg, CarryReg, TwoShiftsOutReg+1 ! Restore the borrows |
| 1251 | // ba .lshr_continue |
| 1252 | unsigned ShiftOpcode = (isSigned ? V8::SRArr : V8::SRLrr); |
| 1253 | |
| 1254 | BB = twoShiftsMBB; |
| 1255 | |
| 1256 | BuildMI (BB, V8::SLLrr, 2, CarryReg).addReg (SrcReg) |
| 1257 | .addReg (HalfShiftReg); |
| 1258 | BuildMI (BB, ShiftOpcode, 2, TwoShiftsOutReg).addReg (SrcReg) |
| 1259 | .addReg (ShiftAmtReg); |
| 1260 | BuildMI (BB, V8::SRLrr, 2, TempReg).addReg (SrcReg+1) |
| 1261 | .addReg (ShiftAmtReg); |
| 1262 | BuildMI (BB, V8::ORrr, 2, TwoShiftsOutReg+1).addReg (TempReg) |
| 1263 | .addReg (CarryReg); |
| 1264 | BuildMI (BB, V8::BA, 1).addMBB (continueMBB); |
| 1265 | |
| 1266 | // Update machine-CFG edges |
| 1267 | BB->addSuccessor (continueMBB); |
| 1268 | |
| 1269 | // .lshr_one_shift: ! [preds: shift] |
| 1270 | // ! if unsigned: |
| 1271 | // or %g0, %g0, OneShiftOutReg ! Zero top half |
| 1272 | // ! or, if signed: |
| 1273 | // sra SrcReg, 31, OneShiftOutReg ! Sign-ext top half |
| 1274 | // sub %g0, HalfShiftReg, NegHalfShiftReg ! Make ShiftAmt >0 |
| 1275 | // <SHIFT> SrcReg, NegHalfShiftReg, OneShiftOutReg+1 ! Shift bottom half |
| 1276 | // ba .lshr_continue |
| 1277 | |
| 1278 | BB = oneShiftMBB; |
| 1279 | |
| 1280 | if (isSigned) |
| 1281 | BuildMI (BB, V8::SRAri, 2, OneShiftOutReg).addReg (SrcReg).addZImm (31); |
| 1282 | else |
| 1283 | BuildMI (BB, V8::ORrr, 2, OneShiftOutReg).addReg (V8::G0) |
| 1284 | .addReg (V8::G0); |
| 1285 | BuildMI (BB, V8::SUBrr, 2, NegHalfShiftReg).addReg (V8::G0) |
| 1286 | .addReg (HalfShiftReg); |
| 1287 | BuildMI (BB, ShiftOpcode, 2, OneShiftOutReg+1).addReg (SrcReg) |
| 1288 | .addReg (NegHalfShiftReg); |
| 1289 | BuildMI (BB, V8::BA, 1).addMBB (continueMBB); |
| 1290 | |
| 1291 | // Update machine-CFG edges |
| 1292 | BB->addSuccessor (continueMBB); |
| 1293 | |
| 1294 | // .lshr_continue: ! [preds: begin, do_one_shift, do_two_shifts] |
| 1295 | // phi (SrcReg, begin), (TwoShiftsOutReg, two_shifts), |
| 1296 | // (OneShiftOutReg, one_shift), DestReg ! Phi top half... |
| 1297 | // phi (SrcReg+1, begin), (TwoShiftsOutReg+1, two_shifts), |
| 1298 | // (OneShiftOutReg+1, one_shift), DestReg+1 ! And phi bottom half. |
| 1299 | |
| 1300 | BB = continueMBB; |
| 1301 | BuildMI (BB, V8::PHI, 6, DestReg).addReg (SrcReg).addMBB (thisMBB) |
| 1302 | .addReg (TwoShiftsOutReg).addMBB (twoShiftsMBB) |
| 1303 | .addReg (OneShiftOutReg).addMBB (oneShiftMBB); |
| 1304 | BuildMI (BB, V8::PHI, 6, DestReg+1).addReg (SrcReg+1).addMBB (thisMBB) |
| 1305 | .addReg (TwoShiftsOutReg+1).addMBB (twoShiftsMBB) |
| 1306 | .addReg (OneShiftOutReg+1).addMBB (oneShiftMBB); |
| 1307 | return; |
| 1308 | } |
Brian Gaeke | 9ffcf9f | 2004-11-22 08:02:06 +0000 | [diff] [blame] | 1309 | case Instruction::Shl: |
Brian Gaeke | 9ffcf9f | 2004-11-22 08:02:06 +0000 | [diff] [blame] | 1310 | default: |
| 1311 | std::cerr << "Sorry, 64-bit shifts are not yet supported:\n" << I; |
| 1312 | abort (); |
| 1313 | } |
| 1314 | } |
| 1315 | |
Chris Lattner | 4be7ca5 | 2004-04-07 04:27:16 +0000 | [diff] [blame] | 1316 | void V8ISel::visitBinaryOperator (Instruction &I) { |
Brian Gaeke | bc1d27a | 2004-03-03 23:03:14 +0000 | [diff] [blame] | 1317 | unsigned DestReg = getReg (I); |
| 1318 | unsigned Op0Reg = getReg (I.getOperand (0)); |
Brian Gaeke | bc1d27a | 2004-03-03 23:03:14 +0000 | [diff] [blame] | 1319 | |
Brian Gaeke | ec3227f | 2004-06-27 22:47:33 +0000 | [diff] [blame] | 1320 | unsigned Class = getClassB (I.getType()); |
Chris Lattner | 22ede70 | 2004-04-07 04:06:46 +0000 | [diff] [blame] | 1321 | unsigned OpCase = ~0; |
| 1322 | |
Brian Gaeke | ec3227f | 2004-06-27 22:47:33 +0000 | [diff] [blame] | 1323 | if (Class > cLong) { |
Brian Gaeke | 1f42181 | 2004-12-10 08:39:28 +0000 | [diff] [blame] | 1324 | unsigned Op1Reg = getReg (I.getOperand (1)); |
Brian Gaeke | ec3227f | 2004-06-27 22:47:33 +0000 | [diff] [blame] | 1325 | switch (I.getOpcode ()) { |
| 1326 | case Instruction::Add: OpCase = 0; break; |
| 1327 | case Instruction::Sub: OpCase = 1; break; |
| 1328 | case Instruction::Mul: OpCase = 2; break; |
| 1329 | case Instruction::Div: OpCase = 3; break; |
| 1330 | default: visitInstruction (I); return; |
| 1331 | } |
| 1332 | static unsigned Opcodes[] = { V8::FADDS, V8::FADDD, |
| 1333 | V8::FSUBS, V8::FSUBD, |
| 1334 | V8::FMULS, V8::FMULD, |
| 1335 | V8::FDIVS, V8::FDIVD }; |
| 1336 | BuildMI (BB, Opcodes[2*OpCase + (Class - cFloat)], 2, DestReg) |
| 1337 | .addReg (Op0Reg).addReg (Op1Reg); |
| 1338 | return; |
| 1339 | } |
| 1340 | |
| 1341 | unsigned ResultReg = DestReg; |
Brian Gaeke | 1df468e | 2004-09-29 03:34:41 +0000 | [diff] [blame] | 1342 | if (Class != cInt && Class != cLong) |
Brian Gaeke | ec3227f | 2004-06-27 22:47:33 +0000 | [diff] [blame] | 1343 | ResultReg = makeAnotherReg (I.getType ()); |
| 1344 | |
Brian Gaeke | 1df468e | 2004-09-29 03:34:41 +0000 | [diff] [blame] | 1345 | if (Class == cLong) { |
Brian Gaeke | 5f91de2 | 2004-11-21 07:13:16 +0000 | [diff] [blame] | 1346 | const char *FuncName; |
Brian Gaeke | 1f42181 | 2004-12-10 08:39:28 +0000 | [diff] [blame] | 1347 | unsigned Op1Reg = getReg (I.getOperand (1)); |
Brian Gaeke | 1df468e | 2004-09-29 03:34:41 +0000 | [diff] [blame] | 1348 | DEBUG (std::cerr << "Class = cLong\n"); |
| 1349 | DEBUG (std::cerr << "Op0Reg = " << Op0Reg << ", " << Op0Reg+1 << "\n"); |
| 1350 | DEBUG (std::cerr << "Op1Reg = " << Op1Reg << ", " << Op1Reg+1 << "\n"); |
| 1351 | DEBUG (std::cerr << "ResultReg = " << ResultReg << ", " << ResultReg+1 << "\n"); |
| 1352 | DEBUG (std::cerr << "DestReg = " << DestReg << ", " << DestReg+1 << "\n"); |
Brian Gaeke | 5f91de2 | 2004-11-21 07:13:16 +0000 | [diff] [blame] | 1353 | switch (I.getOpcode ()) { |
| 1354 | case Instruction::Add: |
| 1355 | BuildMI (BB, V8::ADDCCrr, 2, ResultReg+1).addReg (Op0Reg+1) |
| 1356 | .addReg (Op1Reg+1); |
| 1357 | BuildMI (BB, V8::ADDXrr, 2, ResultReg).addReg (Op0Reg).addReg (Op1Reg); |
| 1358 | return; |
| 1359 | case Instruction::Sub: |
| 1360 | BuildMI (BB, V8::SUBCCrr, 2, ResultReg+1).addReg (Op0Reg+1) |
| 1361 | .addReg (Op1Reg+1); |
| 1362 | BuildMI (BB, V8::SUBXrr, 2, ResultReg).addReg (Op0Reg).addReg (Op1Reg); |
| 1363 | return; |
| 1364 | case Instruction::Mul: |
| 1365 | FuncName = I.getType ()->isSigned () ? "__mul64" : "__umul64"; |
| 1366 | emitOp64LibraryCall (BB, BB->end (), DestReg, FuncName, Op0Reg, Op1Reg); |
| 1367 | return; |
| 1368 | case Instruction::Div: |
| 1369 | FuncName = I.getType ()->isSigned () ? "__div64" : "__udiv64"; |
| 1370 | emitOp64LibraryCall (BB, BB->end (), DestReg, FuncName, Op0Reg, Op1Reg); |
| 1371 | return; |
| 1372 | case Instruction::Rem: |
| 1373 | FuncName = I.getType ()->isSigned () ? "__rem64" : "__urem64"; |
| 1374 | emitOp64LibraryCall (BB, BB->end (), DestReg, FuncName, Op0Reg, Op1Reg); |
| 1375 | return; |
Brian Gaeke | 9ffcf9f | 2004-11-22 08:02:06 +0000 | [diff] [blame] | 1376 | case Instruction::Shl: |
| 1377 | case Instruction::Shr: |
| 1378 | emitShift64 (BB, BB->end (), I, DestReg, Op0Reg, Op1Reg); |
| 1379 | return; |
Brian Gaeke | 5f91de2 | 2004-11-21 07:13:16 +0000 | [diff] [blame] | 1380 | } |
Brian Gaeke | 1df468e | 2004-09-29 03:34:41 +0000 | [diff] [blame] | 1381 | } |
| 1382 | |
Brian Gaeke | bc1d27a | 2004-03-03 23:03:14 +0000 | [diff] [blame] | 1383 | switch (I.getOpcode ()) { |
Chris Lattner | 22ede70 | 2004-04-07 04:06:46 +0000 | [diff] [blame] | 1384 | case Instruction::Add: OpCase = 0; break; |
| 1385 | case Instruction::Sub: OpCase = 1; break; |
| 1386 | case Instruction::Mul: OpCase = 2; break; |
| 1387 | case Instruction::And: OpCase = 3; break; |
| 1388 | case Instruction::Or: OpCase = 4; break; |
| 1389 | case Instruction::Xor: OpCase = 5; break; |
Chris Lattner | 4be7ca5 | 2004-04-07 04:27:16 +0000 | [diff] [blame] | 1390 | case Instruction::Shl: OpCase = 6; break; |
| 1391 | case Instruction::Shr: OpCase = 7+I.getType()->isSigned(); break; |
Chris Lattner | 22ede70 | 2004-04-07 04:06:46 +0000 | [diff] [blame] | 1392 | |
| 1393 | case Instruction::Div: |
| 1394 | case Instruction::Rem: { |
| 1395 | unsigned Dest = ResultReg; |
Brian Gaeke | 1f42181 | 2004-12-10 08:39:28 +0000 | [diff] [blame] | 1396 | unsigned Op1Reg = getReg (I.getOperand (1)); |
Chris Lattner | 22ede70 | 2004-04-07 04:06:46 +0000 | [diff] [blame] | 1397 | if (I.getOpcode() == Instruction::Rem) |
| 1398 | Dest = makeAnotherReg(I.getType()); |
| 1399 | |
| 1400 | // FIXME: this is probably only right for 32 bit operands. |
| 1401 | if (I.getType ()->isSigned()) { |
| 1402 | unsigned Tmp = makeAnotherReg (I.getType ()); |
| 1403 | // Sign extend into the Y register |
| 1404 | BuildMI (BB, V8::SRAri, 2, Tmp).addReg (Op0Reg).addZImm (31); |
| 1405 | BuildMI (BB, V8::WRrr, 2, V8::Y).addReg (Tmp).addReg (V8::G0); |
| 1406 | BuildMI (BB, V8::SDIVrr, 2, Dest).addReg (Op0Reg).addReg (Op1Reg); |
| 1407 | } else { |
| 1408 | // Zero extend into the Y register, ie, just set it to zero |
| 1409 | BuildMI (BB, V8::WRrr, 2, V8::Y).addReg (V8::G0).addReg (V8::G0); |
| 1410 | BuildMI (BB, V8::UDIVrr, 2, Dest).addReg (Op0Reg).addReg (Op1Reg); |
Brian Gaeke | 2d4fa8f | 2004-04-07 04:00:49 +0000 | [diff] [blame] | 1411 | } |
Chris Lattner | 22ede70 | 2004-04-07 04:06:46 +0000 | [diff] [blame] | 1412 | |
| 1413 | if (I.getOpcode() == Instruction::Rem) { |
| 1414 | unsigned Tmp = makeAnotherReg (I.getType ()); |
| 1415 | BuildMI (BB, V8::SMULrr, 2, Tmp).addReg(Dest).addReg(Op1Reg); |
| 1416 | BuildMI (BB, V8::SUBrr, 2, ResultReg).addReg(Op0Reg).addReg(Tmp); |
Brian Gaeke | f57e364 | 2004-03-16 22:37:11 +0000 | [diff] [blame] | 1417 | } |
Chris Lattner | 22ede70 | 2004-04-07 04:06:46 +0000 | [diff] [blame] | 1418 | break; |
| 1419 | } |
| 1420 | default: |
| 1421 | visitInstruction (I); |
| 1422 | return; |
| 1423 | } |
| 1424 | |
Brian Gaeke | c7fd0f4 | 2004-06-24 08:55:09 +0000 | [diff] [blame] | 1425 | static const unsigned Opcodes[] = { |
| 1426 | V8::ADDrr, V8::SUBrr, V8::SMULrr, V8::ANDrr, V8::ORrr, V8::XORrr, |
| 1427 | V8::SLLrr, V8::SRLrr, V8::SRArr |
| 1428 | }; |
Brian Gaeke | 1f42181 | 2004-12-10 08:39:28 +0000 | [diff] [blame] | 1429 | static const unsigned OpcodesRI[] = { |
| 1430 | V8::ADDri, V8::SUBri, V8::SMULri, V8::ANDri, V8::ORri, V8::XORri, |
| 1431 | V8::SLLri, V8::SRLri, V8::SRAri |
| 1432 | }; |
| 1433 | unsigned Op1Reg = ~0U; |
Chris Lattner | 22ede70 | 2004-04-07 04:06:46 +0000 | [diff] [blame] | 1434 | if (OpCase != ~0U) { |
Brian Gaeke | 1f42181 | 2004-12-10 08:39:28 +0000 | [diff] [blame] | 1435 | Value *Arg1 = I.getOperand (1); |
| 1436 | bool useImmed = false; |
| 1437 | int64_t Val = 0; |
| 1438 | if ((getClassB (I.getType ()) <= cInt) && (isa<ConstantIntegral> (Arg1))) { |
| 1439 | Val = cast<ConstantIntegral> (Arg1)->getRawValue (); |
| 1440 | useImmed = (Val > -4096 && Val < 4095); |
| 1441 | } |
| 1442 | if (useImmed) { |
| 1443 | BuildMI (BB, OpcodesRI[OpCase], 2, ResultReg).addReg (Op0Reg).addSImm (Val); |
| 1444 | } else { |
| 1445 | Op1Reg = getReg (I.getOperand (1)); |
| 1446 | BuildMI (BB, Opcodes[OpCase], 2, ResultReg).addReg (Op0Reg).addReg (Op1Reg); |
| 1447 | } |
Brian Gaeke | bc1d27a | 2004-03-03 23:03:14 +0000 | [diff] [blame] | 1448 | } |
| 1449 | |
Brian Gaeke | ccdd70a | 2004-07-08 08:08:10 +0000 | [diff] [blame] | 1450 | switch (getClassB (I.getType ())) { |
Brian Gaeke | bc1d27a | 2004-03-03 23:03:14 +0000 | [diff] [blame] | 1451 | case cByte: |
Brian Gaeke | 08f64c3 | 2004-03-06 05:32:28 +0000 | [diff] [blame] | 1452 | if (I.getType ()->isSigned ()) { // add byte |
| 1453 | BuildMI (BB, V8::ANDri, 2, DestReg).addReg (ResultReg).addZImm (0xff); |
| 1454 | } else { // add ubyte |
| 1455 | unsigned TmpReg = makeAnotherReg (I.getType ()); |
| 1456 | BuildMI (BB, V8::SLLri, 2, TmpReg).addReg (ResultReg).addZImm (24); |
| 1457 | BuildMI (BB, V8::SRAri, 2, DestReg).addReg (TmpReg).addZImm (24); |
| 1458 | } |
Brian Gaeke | bc1d27a | 2004-03-03 23:03:14 +0000 | [diff] [blame] | 1459 | break; |
| 1460 | case cShort: |
Brian Gaeke | 08f64c3 | 2004-03-06 05:32:28 +0000 | [diff] [blame] | 1461 | if (I.getType ()->isSigned ()) { // add short |
| 1462 | unsigned TmpReg = makeAnotherReg (I.getType ()); |
| 1463 | BuildMI (BB, V8::SLLri, 2, TmpReg).addReg (ResultReg).addZImm (16); |
| 1464 | BuildMI (BB, V8::SRAri, 2, DestReg).addReg (TmpReg).addZImm (16); |
| 1465 | } else { // add ushort |
| 1466 | unsigned TmpReg = makeAnotherReg (I.getType ()); |
Brian Gaeke | 6d339f9 | 2004-03-16 22:45:42 +0000 | [diff] [blame] | 1467 | BuildMI (BB, V8::SLLri, 2, TmpReg).addReg (ResultReg).addZImm (16); |
| 1468 | BuildMI (BB, V8::SRLri, 2, DestReg).addReg (TmpReg).addZImm (16); |
Brian Gaeke | 08f64c3 | 2004-03-06 05:32:28 +0000 | [diff] [blame] | 1469 | } |
Brian Gaeke | bc1d27a | 2004-03-03 23:03:14 +0000 | [diff] [blame] | 1470 | break; |
| 1471 | case cInt: |
Brian Gaeke | ccdd70a | 2004-07-08 08:08:10 +0000 | [diff] [blame] | 1472 | // Nothing to do here. |
Brian Gaeke | bc1d27a | 2004-03-03 23:03:14 +0000 | [diff] [blame] | 1473 | break; |
Brian Gaeke | 1f42181 | 2004-12-10 08:39:28 +0000 | [diff] [blame] | 1474 | case cLong: { |
Brian Gaeke | 5f91de2 | 2004-11-21 07:13:16 +0000 | [diff] [blame] | 1475 | // Only support and, or, xor here - others taken care of above. |
Brian Gaeke | c7fd0f4 | 2004-06-24 08:55:09 +0000 | [diff] [blame] | 1476 | if (OpCase < 3 || OpCase > 5) { |
| 1477 | visitInstruction (I); |
| 1478 | return; |
| 1479 | } |
| 1480 | // Do the other half of the value: |
Brian Gaeke | ec3227f | 2004-06-27 22:47:33 +0000 | [diff] [blame] | 1481 | BuildMI (BB, Opcodes[OpCase], 2, ResultReg+1).addReg (Op0Reg+1) |
| 1482 | .addReg (Op1Reg+1); |
Brian Gaeke | c7fd0f4 | 2004-06-24 08:55:09 +0000 | [diff] [blame] | 1483 | break; |
Brian Gaeke | 1f42181 | 2004-12-10 08:39:28 +0000 | [diff] [blame] | 1484 | } |
Brian Gaeke | bc1d27a | 2004-03-03 23:03:14 +0000 | [diff] [blame] | 1485 | default: |
Brian Gaeke | 08f64c3 | 2004-03-06 05:32:28 +0000 | [diff] [blame] | 1486 | visitInstruction (I); |
Brian Gaeke | bc1d27a | 2004-03-03 23:03:14 +0000 | [diff] [blame] | 1487 | } |
| 1488 | } |
| 1489 | |
Misha Brukman | ea09126 | 2004-06-30 21:47:40 +0000 | [diff] [blame] | 1490 | void V8ISel::visitSetCondInst(SetCondInst &I) { |
Brian Gaeke | 6a8c46c | 2004-12-12 06:01:26 +0000 | [diff] [blame^] | 1491 | if (canFoldSetCCIntoBranch(&I)) |
| 1492 | return; // Fold this into a branch. |
| 1493 | |
Chris Lattner | 4d0cda4 | 2004-04-07 05:04:51 +0000 | [diff] [blame] | 1494 | unsigned Op0Reg = getReg (I.getOperand (0)); |
| 1495 | unsigned Op1Reg = getReg (I.getOperand (1)); |
| 1496 | unsigned DestReg = getReg (I); |
Brian Gaeke | 429022b | 2004-05-08 06:36:14 +0000 | [diff] [blame] | 1497 | const Type *Ty = I.getOperand (0)->getType (); |
Chris Lattner | 4d0cda4 | 2004-04-07 05:04:51 +0000 | [diff] [blame] | 1498 | |
| 1499 | // Compare the two values. |
Brian Gaeke | 3a08589 | 2004-07-08 09:08:35 +0000 | [diff] [blame] | 1500 | if (getClass (Ty) < cLong) { |
| 1501 | BuildMI(BB, V8::SUBCCrr, 2, V8::G0).addReg(Op0Reg).addReg(Op1Reg); |
Brian Gaeke | 5f91de2 | 2004-11-21 07:13:16 +0000 | [diff] [blame] | 1502 | } else if (getClass (Ty) == cLong) { |
Brian Gaeke | c7b4f10 | 2004-11-21 08:11:28 +0000 | [diff] [blame] | 1503 | switch (I.getOpcode()) { |
| 1504 | default: assert(0 && "Unknown setcc instruction!"); |
| 1505 | case Instruction::SetEQ: |
| 1506 | case Instruction::SetNE: { |
| 1507 | unsigned TempReg0 = makeAnotherReg (Type::IntTy), |
| 1508 | TempReg1 = makeAnotherReg (Type::IntTy), |
| 1509 | TempReg2 = makeAnotherReg (Type::IntTy), |
| 1510 | TempReg3 = makeAnotherReg (Type::IntTy); |
| 1511 | MachineOpCode Opcode; |
| 1512 | int Immed; |
| 1513 | // These guys are special - no branches needed! |
| 1514 | BuildMI (BB, V8::XORrr, 2, TempReg0).addReg (Op0Reg+1).addReg (Op1Reg+1); |
| 1515 | BuildMI (BB, V8::XORrr, 2, TempReg1).addReg (Op0Reg).addReg (Op1Reg); |
| 1516 | BuildMI (BB, V8::SUBCCrr, 2, V8::G0).addReg (V8::G0).addReg (TempReg1); |
| 1517 | Opcode = I.getOpcode() == Instruction::SetEQ ? V8::SUBXri : V8::ADDXri; |
| 1518 | Immed = I.getOpcode() == Instruction::SetEQ ? -1 : 0; |
| 1519 | BuildMI (BB, Opcode, 2, TempReg2).addReg (V8::G0).addSImm (Immed); |
| 1520 | BuildMI (BB, V8::SUBCCrr, 2, V8::G0).addReg (V8::G0).addReg (TempReg0); |
| 1521 | BuildMI (BB, Opcode, 2, TempReg3).addReg (V8::G0).addSImm (Immed); |
| 1522 | Opcode = I.getOpcode() == Instruction::SetEQ ? V8::ANDrr : V8::ORrr; |
| 1523 | BuildMI (BB, Opcode, 2, DestReg).addReg (TempReg2).addReg (TempReg3); |
| 1524 | return; |
| 1525 | } |
| 1526 | case Instruction::SetLT: |
| 1527 | case Instruction::SetGE: |
| 1528 | BuildMI (BB, V8::SUBCCrr, 2, V8::G0).addReg (Op0Reg+1).addReg (Op1Reg+1); |
| 1529 | BuildMI (BB, V8::SUBXCCrr, 2, V8::G0).addReg (Op0Reg).addReg (Op1Reg); |
| 1530 | break; |
| 1531 | case Instruction::SetGT: |
| 1532 | case Instruction::SetLE: |
| 1533 | BuildMI (BB, V8::SUBCCri, 2, V8::G0).addReg (V8::G0).addSImm (1); |
| 1534 | BuildMI (BB, V8::SUBXCCrr, 2, V8::G0).addReg (Op0Reg+1).addReg (Op1Reg+1); |
| 1535 | BuildMI (BB, V8::SUBXCCrr, 2, V8::G0).addReg (Op0Reg).addReg (Op1Reg); |
| 1536 | break; |
| 1537 | } |
Brian Gaeke | 3a08589 | 2004-07-08 09:08:35 +0000 | [diff] [blame] | 1538 | } else if (getClass (Ty) == cFloat) { |
| 1539 | BuildMI(BB, V8::FCMPS, 2).addReg(Op0Reg).addReg(Op1Reg); |
| 1540 | } else if (getClass (Ty) == cDouble) { |
| 1541 | BuildMI(BB, V8::FCMPD, 2).addReg(Op0Reg).addReg(Op1Reg); |
| 1542 | } |
Chris Lattner | 4d0cda4 | 2004-04-07 05:04:51 +0000 | [diff] [blame] | 1543 | |
Brian Gaeke | 429022b | 2004-05-08 06:36:14 +0000 | [diff] [blame] | 1544 | unsigned BranchIdx; |
Chris Lattner | 4d0cda4 | 2004-04-07 05:04:51 +0000 | [diff] [blame] | 1545 | switch (I.getOpcode()) { |
| 1546 | default: assert(0 && "Unknown setcc instruction!"); |
Brian Gaeke | 429022b | 2004-05-08 06:36:14 +0000 | [diff] [blame] | 1547 | case Instruction::SetEQ: BranchIdx = 0; break; |
| 1548 | case Instruction::SetNE: BranchIdx = 1; break; |
| 1549 | case Instruction::SetLT: BranchIdx = 2; break; |
| 1550 | case Instruction::SetGT: BranchIdx = 3; break; |
| 1551 | case Instruction::SetLE: BranchIdx = 4; break; |
| 1552 | case Instruction::SetGE: BranchIdx = 5; break; |
Chris Lattner | 4d0cda4 | 2004-04-07 05:04:51 +0000 | [diff] [blame] | 1553 | } |
Brian Gaeke | c7b4f10 | 2004-11-21 08:11:28 +0000 | [diff] [blame] | 1554 | |
Brian Gaeke | 3a08589 | 2004-07-08 09:08:35 +0000 | [diff] [blame] | 1555 | unsigned Column = 0; |
Brian Gaeke | b3e0017 | 2004-11-17 22:06:56 +0000 | [diff] [blame] | 1556 | if (Ty->isSigned() && !Ty->isFloatingPoint()) Column = 1; |
| 1557 | if (Ty->isFloatingPoint()) Column = 2; |
Brian Gaeke | 3a08589 | 2004-07-08 09:08:35 +0000 | [diff] [blame] | 1558 | static unsigned OpcodeTab[3*6] = { |
| 1559 | // LLVM SparcV8 |
| 1560 | // unsigned signed fp |
| 1561 | V8::BE, V8::BE, V8::FBE, // seteq = be be fbe |
| 1562 | V8::BNE, V8::BNE, V8::FBNE, // setne = bne bne fbne |
| 1563 | V8::BCS, V8::BL, V8::FBL, // setlt = bcs bl fbl |
| 1564 | V8::BGU, V8::BG, V8::FBG, // setgt = bgu bg fbg |
| 1565 | V8::BLEU, V8::BLE, V8::FBLE, // setle = bleu ble fble |
| 1566 | V8::BCC, V8::BGE, V8::FBGE // setge = bcc bge fbge |
Brian Gaeke | 429022b | 2004-05-08 06:36:14 +0000 | [diff] [blame] | 1567 | }; |
Brian Gaeke | 3a08589 | 2004-07-08 09:08:35 +0000 | [diff] [blame] | 1568 | unsigned Opcode = OpcodeTab[3*BranchIdx + Column]; |
Brian Gaeke | 6c868a4 | 2004-06-17 22:34:08 +0000 | [diff] [blame] | 1569 | |
| 1570 | MachineBasicBlock *thisMBB = BB; |
| 1571 | const BasicBlock *LLVM_BB = BB->getBasicBlock (); |
| 1572 | // thisMBB: |
| 1573 | // ... |
| 1574 | // subcc %reg0, %reg1, %g0 |
| 1575 | // bCC copy1MBB |
| 1576 | // ba copy0MBB |
| 1577 | |
| 1578 | // FIXME: we wouldn't need copy0MBB (we could fold it into thisMBB) |
| 1579 | // if we could insert other, non-terminator instructions after the |
| 1580 | // bCC. But MBB->getFirstTerminator() can't understand this. |
| 1581 | MachineBasicBlock *copy1MBB = new MachineBasicBlock (LLVM_BB); |
| 1582 | F->getBasicBlockList ().push_back (copy1MBB); |
| 1583 | BuildMI (BB, Opcode, 1).addMBB (copy1MBB); |
| 1584 | MachineBasicBlock *copy0MBB = new MachineBasicBlock (LLVM_BB); |
| 1585 | F->getBasicBlockList ().push_back (copy0MBB); |
| 1586 | BuildMI (BB, V8::BA, 1).addMBB (copy0MBB); |
| 1587 | // Update machine-CFG edges |
| 1588 | BB->addSuccessor (copy1MBB); |
| 1589 | BB->addSuccessor (copy0MBB); |
| 1590 | |
| 1591 | // copy0MBB: |
| 1592 | // %FalseValue = or %G0, 0 |
| 1593 | // ba sinkMBB |
| 1594 | BB = copy0MBB; |
| 1595 | unsigned FalseValue = makeAnotherReg (I.getType ()); |
| 1596 | BuildMI (BB, V8::ORri, 2, FalseValue).addReg (V8::G0).addZImm (0); |
| 1597 | MachineBasicBlock *sinkMBB = new MachineBasicBlock (LLVM_BB); |
| 1598 | F->getBasicBlockList ().push_back (sinkMBB); |
| 1599 | BuildMI (BB, V8::BA, 1).addMBB (sinkMBB); |
| 1600 | // Update machine-CFG edges |
| 1601 | BB->addSuccessor (sinkMBB); |
| 1602 | |
| 1603 | DEBUG (std::cerr << "thisMBB is at " << (void*)thisMBB << "\n"); |
| 1604 | DEBUG (std::cerr << "copy1MBB is at " << (void*)copy1MBB << "\n"); |
| 1605 | DEBUG (std::cerr << "copy0MBB is at " << (void*)copy0MBB << "\n"); |
| 1606 | DEBUG (std::cerr << "sinkMBB is at " << (void*)sinkMBB << "\n"); |
| 1607 | |
| 1608 | // copy1MBB: |
| 1609 | // %TrueValue = or %G0, 1 |
| 1610 | // ba sinkMBB |
| 1611 | BB = copy1MBB; |
| 1612 | unsigned TrueValue = makeAnotherReg (I.getType ()); |
| 1613 | BuildMI (BB, V8::ORri, 2, TrueValue).addReg (V8::G0).addZImm (1); |
| 1614 | BuildMI (BB, V8::BA, 1).addMBB (sinkMBB); |
| 1615 | // Update machine-CFG edges |
| 1616 | BB->addSuccessor (sinkMBB); |
| 1617 | |
| 1618 | // sinkMBB: |
| 1619 | // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, copy1MBB ] |
| 1620 | // ... |
| 1621 | BB = sinkMBB; |
| 1622 | BuildMI (BB, V8::PHI, 4, DestReg).addReg (FalseValue) |
| 1623 | .addMBB (copy0MBB).addReg (TrueValue).addMBB (copy1MBB); |
Chris Lattner | 4d0cda4 | 2004-04-07 05:04:51 +0000 | [diff] [blame] | 1624 | } |
| 1625 | |
Brian Gaeke | c93a752 | 2004-06-18 05:19:16 +0000 | [diff] [blame] | 1626 | void V8ISel::visitAllocaInst(AllocaInst &I) { |
| 1627 | // Find the data size of the alloca inst's getAllocatedType. |
| 1628 | const Type *Ty = I.getAllocatedType(); |
| 1629 | unsigned TySize = TM.getTargetData().getTypeSize(Ty); |
Chris Lattner | 4d0cda4 | 2004-04-07 05:04:51 +0000 | [diff] [blame] | 1630 | |
Brian Gaeke | c93a752 | 2004-06-18 05:19:16 +0000 | [diff] [blame] | 1631 | unsigned ArraySizeReg = getReg (I.getArraySize ()); |
| 1632 | unsigned TySizeReg = getReg (ConstantUInt::get (Type::UIntTy, TySize)); |
| 1633 | unsigned TmpReg1 = makeAnotherReg (Type::UIntTy); |
| 1634 | unsigned TmpReg2 = makeAnotherReg (Type::UIntTy); |
| 1635 | unsigned StackAdjReg = makeAnotherReg (Type::UIntTy); |
Brian Gaeke | c93a752 | 2004-06-18 05:19:16 +0000 | [diff] [blame] | 1636 | |
Brian Gaeke | 79fe833 | 2004-11-21 03:35:22 +0000 | [diff] [blame] | 1637 | // StackAdjReg = (ArraySize * TySize) rounded up to nearest |
| 1638 | // doubleword boundary. |
Brian Gaeke | c93a752 | 2004-06-18 05:19:16 +0000 | [diff] [blame] | 1639 | BuildMI (BB, V8::UMULrr, 2, TmpReg1).addReg (ArraySizeReg).addReg (TySizeReg); |
Brian Gaeke | cfaf224 | 2004-06-18 08:45:52 +0000 | [diff] [blame] | 1640 | |
Brian Gaeke | c93a752 | 2004-06-18 05:19:16 +0000 | [diff] [blame] | 1641 | // Round up TmpReg1 to nearest doubleword boundary: |
| 1642 | BuildMI (BB, V8::ADDri, 2, TmpReg2).addReg (TmpReg1).addSImm (7); |
| 1643 | BuildMI (BB, V8::ANDri, 2, StackAdjReg).addReg (TmpReg2).addSImm (-8); |
Brian Gaeke | cfaf224 | 2004-06-18 08:45:52 +0000 | [diff] [blame] | 1644 | |
| 1645 | // Subtract size from stack pointer, thereby allocating some space. |
Brian Gaeke | c93a752 | 2004-06-18 05:19:16 +0000 | [diff] [blame] | 1646 | BuildMI (BB, V8::SUBrr, 2, V8::SP).addReg (V8::SP).addReg (StackAdjReg); |
Brian Gaeke | cfaf224 | 2004-06-18 08:45:52 +0000 | [diff] [blame] | 1647 | |
| 1648 | // Put a pointer to the space into the result register, by copying |
| 1649 | // the stack pointer. |
| 1650 | BuildMI (BB, V8::ADDri, 2, getReg(I)).addReg (V8::SP).addSImm (96); |
| 1651 | |
| 1652 | // Inform the Frame Information that we have just allocated a variable-sized |
| 1653 | // object. |
| 1654 | F->getFrameInfo()->CreateVariableSizedObject(); |
Brian Gaeke | c93a752 | 2004-06-18 05:19:16 +0000 | [diff] [blame] | 1655 | } |
Chris Lattner | 1c809c5 | 2004-02-29 00:27:00 +0000 | [diff] [blame] | 1656 | |
| 1657 | /// LowerUnknownIntrinsicFunctionCalls - This performs a prepass over the |
| 1658 | /// function, lowering any calls to unknown intrinsic functions into the |
| 1659 | /// equivalent LLVM code. |
| 1660 | void V8ISel::LowerUnknownIntrinsicFunctionCalls(Function &F) { |
| 1661 | for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) |
| 1662 | for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ) |
| 1663 | if (CallInst *CI = dyn_cast<CallInst>(I++)) |
| 1664 | if (Function *F = CI->getCalledFunction()) |
| 1665 | switch (F->getIntrinsicID()) { |
Brian Gaeke | d90282d | 2004-11-19 20:57:24 +0000 | [diff] [blame] | 1666 | case Intrinsic::vastart: |
| 1667 | case Intrinsic::vacopy: |
| 1668 | case Intrinsic::vaend: |
| 1669 | // We directly implement these intrinsics |
Chris Lattner | 1c809c5 | 2004-02-29 00:27:00 +0000 | [diff] [blame] | 1670 | case Intrinsic::not_intrinsic: break; |
| 1671 | default: |
| 1672 | // All other intrinsic calls we must lower. |
| 1673 | Instruction *Before = CI->getPrev(); |
| 1674 | TM.getIntrinsicLowering().LowerIntrinsicCall(CI); |
| 1675 | if (Before) { // Move iterator to instruction after call |
| 1676 | I = Before; ++I; |
| 1677 | } else { |
| 1678 | I = BB->begin(); |
| 1679 | } |
| 1680 | } |
| 1681 | } |
| 1682 | |
| 1683 | |
| 1684 | void V8ISel::visitIntrinsicCall(Intrinsic::ID ID, CallInst &CI) { |
Chris Lattner | 1c809c5 | 2004-02-29 00:27:00 +0000 | [diff] [blame] | 1685 | switch (ID) { |
Brian Gaeke | 9e672a2 | 2004-11-19 18:53:59 +0000 | [diff] [blame] | 1686 | default: |
| 1687 | std::cerr << "Sorry, unknown intrinsic function call:\n" << CI; abort (); |
| 1688 | |
Brian Gaeke | d90282d | 2004-11-19 20:57:24 +0000 | [diff] [blame] | 1689 | case Intrinsic::vastart: { |
Brian Gaeke | e6e7e3a | 2004-11-20 03:32:12 +0000 | [diff] [blame] | 1690 | // Add the VarArgsOffset to the frame pointer, and copy it to the result. |
Brian Gaeke | d90282d | 2004-11-19 20:57:24 +0000 | [diff] [blame] | 1691 | unsigned DestReg = getReg (CI); |
| 1692 | BuildMI (BB, V8::ADDri, 2, DestReg).addReg (V8::FP).addSImm (VarArgsOffset); |
| 1693 | return; |
| 1694 | } |
Brian Gaeke | 9e672a2 | 2004-11-19 18:53:59 +0000 | [diff] [blame] | 1695 | |
| 1696 | case Intrinsic::vaend: |
Brian Gaeke | 2f95ed6 | 2004-11-19 19:21:34 +0000 | [diff] [blame] | 1697 | // va_end is a no-op on SparcV8. |
| 1698 | return; |
Brian Gaeke | 9e672a2 | 2004-11-19 18:53:59 +0000 | [diff] [blame] | 1699 | |
Brian Gaeke | e6e7e3a | 2004-11-20 03:32:12 +0000 | [diff] [blame] | 1700 | case Intrinsic::vacopy: { |
| 1701 | // Copy the va_list ptr (arg1) to the result. |
| 1702 | unsigned DestReg = getReg (CI), SrcReg = getReg (CI.getOperand (1)); |
| 1703 | BuildMI (BB, V8::ORrr, 2, DestReg).addReg (V8::G0).addReg (SrcReg); |
| 1704 | return; |
| 1705 | } |
Chris Lattner | 1c809c5 | 2004-02-29 00:27:00 +0000 | [diff] [blame] | 1706 | } |
| 1707 | } |
Brian Gaeke | b6c409a | 2004-11-19 21:08:18 +0000 | [diff] [blame] | 1708 | |
| 1709 | void V8ISel::visitVANextInst (VANextInst &I) { |
Brian Gaeke | e6e7e3a | 2004-11-20 03:32:12 +0000 | [diff] [blame] | 1710 | // Add the type size to the vararg pointer (arg0). |
| 1711 | unsigned DestReg = getReg (I); |
| 1712 | unsigned SrcReg = getReg (I.getOperand (0)); |
| 1713 | unsigned TySize = TM.getTargetData ().getTypeSize (I.getArgType ()); |
| 1714 | BuildMI (BB, V8::ADDri, 2, DestReg).addReg (SrcReg).addSImm (TySize); |
Brian Gaeke | b6c409a | 2004-11-19 21:08:18 +0000 | [diff] [blame] | 1715 | } |
| 1716 | |
| 1717 | void V8ISel::visitVAArgInst (VAArgInst &I) { |
Brian Gaeke | b95cbee | 2004-11-20 22:50:42 +0000 | [diff] [blame] | 1718 | unsigned VAList = getReg (I.getOperand (0)); |
| 1719 | unsigned DestReg = getReg (I); |
| 1720 | |
| 1721 | switch (I.getType ()->getTypeID ()) { |
| 1722 | case Type::PointerTyID: |
| 1723 | case Type::UIntTyID: |
| 1724 | case Type::IntTyID: |
| 1725 | BuildMI (BB, V8::LD, 2, DestReg).addReg (VAList).addSImm (0); |
| 1726 | return; |
| 1727 | |
| 1728 | case Type::ULongTyID: |
| 1729 | case Type::LongTyID: |
| 1730 | BuildMI (BB, V8::LD, 2, DestReg).addReg (VAList).addSImm (0); |
| 1731 | BuildMI (BB, V8::LD, 2, DestReg+1).addReg (VAList).addSImm (4); |
| 1732 | return; |
| 1733 | |
Brian Gaeke | 79fe833 | 2004-11-21 03:35:22 +0000 | [diff] [blame] | 1734 | case Type::DoubleTyID: { |
| 1735 | unsigned DblAlign = TM.getTargetData().getDoubleAlignment(); |
| 1736 | unsigned TempReg = makeAnotherReg (Type::IntTy); |
| 1737 | unsigned TempReg2 = makeAnotherReg (Type::IntTy); |
| 1738 | int FI = F->getFrameInfo()->CreateStackObject(8, DblAlign); |
| 1739 | BuildMI (BB, V8::LD, 2, TempReg).addReg (VAList).addSImm (0); |
| 1740 | BuildMI (BB, V8::LD, 2, TempReg2).addReg (VAList).addSImm (4); |
| 1741 | BuildMI (BB, V8::ST, 3).addFrameIndex (FI).addSImm (0).addReg (TempReg); |
| 1742 | BuildMI (BB, V8::ST, 3).addFrameIndex (FI).addSImm (4).addReg (TempReg2); |
| 1743 | BuildMI (BB, V8::LDDFri, 2, DestReg).addFrameIndex (FI).addSImm (0); |
Brian Gaeke | b95cbee | 2004-11-20 22:50:42 +0000 | [diff] [blame] | 1744 | return; |
Brian Gaeke | 79fe833 | 2004-11-21 03:35:22 +0000 | [diff] [blame] | 1745 | } |
Brian Gaeke | b95cbee | 2004-11-20 22:50:42 +0000 | [diff] [blame] | 1746 | |
| 1747 | default: |
| 1748 | std::cerr << "Sorry, vaarg instruction of this type still unsupported:\n" |
| 1749 | << I; |
| 1750 | abort (); |
| 1751 | return; |
| 1752 | } |
Brian Gaeke | b6c409a | 2004-11-19 21:08:18 +0000 | [diff] [blame] | 1753 | } |