Chris Lattner | 7261408 | 2002-10-25 22:55:53 +0000 | [diff] [blame] | 1 | //===-- InstSelectSimple.cpp - A simple instruction selector for x86 ------===// |
| 2 | // |
| 3 | // This file defines a simple peephole instruction selector for the x86 platform |
| 4 | // |
| 5 | //===----------------------------------------------------------------------===// |
| 6 | |
| 7 | #include "X86.h" |
Chris Lattner | 055c965 | 2002-10-29 21:05:24 +0000 | [diff] [blame] | 8 | #include "X86InstrInfo.h" |
Chris Lattner | 6fc3c52 | 2002-11-17 21:11:55 +0000 | [diff] [blame] | 9 | #include "X86InstrBuilder.h" |
Chris Lattner | 7261408 | 2002-10-25 22:55:53 +0000 | [diff] [blame] | 10 | #include "llvm/Function.h" |
| 11 | #include "llvm/iTerminators.h" |
Brian Gaeke | 1749d63 | 2002-11-07 17:59:21 +0000 | [diff] [blame] | 12 | #include "llvm/iOperators.h" |
Brian Gaeke | a1719c9 | 2002-10-31 23:03:59 +0000 | [diff] [blame] | 13 | #include "llvm/iOther.h" |
Chris Lattner | 51b49a9 | 2002-11-02 19:45:49 +0000 | [diff] [blame] | 14 | #include "llvm/iPHINode.h" |
Chris Lattner | 6fc3c52 | 2002-11-17 21:11:55 +0000 | [diff] [blame] | 15 | #include "llvm/iMemory.h" |
Chris Lattner | 7261408 | 2002-10-25 22:55:53 +0000 | [diff] [blame] | 16 | #include "llvm/Type.h" |
Chris Lattner | c5291f5 | 2002-10-27 21:16:59 +0000 | [diff] [blame] | 17 | #include "llvm/Constants.h" |
Chris Lattner | b4f68ed | 2002-10-29 22:37:54 +0000 | [diff] [blame] | 18 | #include "llvm/Pass.h" |
Chris Lattner | 341a937 | 2002-10-29 17:43:55 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/MachineFunction.h" |
Misha Brukman | d2cc017 | 2002-11-20 00:58:23 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
| 21 | #include "llvm/Target/TargetMachine.h" |
Chris Lattner | 7261408 | 2002-10-25 22:55:53 +0000 | [diff] [blame] | 22 | #include "llvm/Support/InstVisitor.h" |
Misha Brukman | d2cc017 | 2002-11-20 00:58:23 +0000 | [diff] [blame] | 23 | #include "llvm/Target/MRegisterInfo.h" |
| 24 | #include <map> |
Chris Lattner | 7261408 | 2002-10-25 22:55:53 +0000 | [diff] [blame] | 25 | |
Chris Lattner | 0692536 | 2002-11-17 21:56:38 +0000 | [diff] [blame] | 26 | using namespace MOTy; // Get Use, Def, UseAndDef |
| 27 | |
Chris Lattner | 7261408 | 2002-10-25 22:55:53 +0000 | [diff] [blame] | 28 | namespace { |
Chris Lattner | b4f68ed | 2002-10-29 22:37:54 +0000 | [diff] [blame] | 29 | struct ISel : public FunctionPass, InstVisitor<ISel> { |
| 30 | TargetMachine &TM; |
Chris Lattner | 341a937 | 2002-10-29 17:43:55 +0000 | [diff] [blame] | 31 | MachineFunction *F; // The function we are compiling into |
| 32 | MachineBasicBlock *BB; // The current MBB we are compiling |
Chris Lattner | 7261408 | 2002-10-25 22:55:53 +0000 | [diff] [blame] | 33 | |
| 34 | unsigned CurReg; |
| 35 | std::map<Value*, unsigned> RegMap; // Mapping between Val's and SSA Regs |
| 36 | |
Chris Lattner | b4f68ed | 2002-10-29 22:37:54 +0000 | [diff] [blame] | 37 | ISel(TargetMachine &tm) |
| 38 | : TM(tm), F(0), BB(0), CurReg(MRegisterInfo::FirstVirtualRegister) {} |
Chris Lattner | 7261408 | 2002-10-25 22:55:53 +0000 | [diff] [blame] | 39 | |
| 40 | /// runOnFunction - Top level implementation of instruction selection for |
| 41 | /// the entire function. |
| 42 | /// |
Chris Lattner | b4f68ed | 2002-10-29 22:37:54 +0000 | [diff] [blame] | 43 | bool runOnFunction(Function &Fn) { |
Chris Lattner | 36b3603 | 2002-10-29 23:40:58 +0000 | [diff] [blame] | 44 | F = &MachineFunction::construct(&Fn, TM); |
Chris Lattner | b4f68ed | 2002-10-29 22:37:54 +0000 | [diff] [blame] | 45 | visit(Fn); |
Chris Lattner | 7261408 | 2002-10-25 22:55:53 +0000 | [diff] [blame] | 46 | RegMap.clear(); |
Chris Lattner | b4f68ed | 2002-10-29 22:37:54 +0000 | [diff] [blame] | 47 | F = 0; |
Chris Lattner | 7261408 | 2002-10-25 22:55:53 +0000 | [diff] [blame] | 48 | return false; // We never modify the LLVM itself. |
| 49 | } |
| 50 | |
| 51 | /// visitBasicBlock - This method is called when we are visiting a new basic |
Chris Lattner | 33f53b5 | 2002-10-29 20:48:56 +0000 | [diff] [blame] | 52 | /// block. This simply creates a new MachineBasicBlock to emit code into |
| 53 | /// and adds it to the current MachineFunction. Subsequent visit* for |
| 54 | /// instructions will be invoked for all instructions in the basic block. |
Chris Lattner | 7261408 | 2002-10-25 22:55:53 +0000 | [diff] [blame] | 55 | /// |
| 56 | void visitBasicBlock(BasicBlock &LLVM_BB) { |
Chris Lattner | 42c7786 | 2002-10-30 00:47:40 +0000 | [diff] [blame] | 57 | BB = new MachineBasicBlock(&LLVM_BB); |
Chris Lattner | 7261408 | 2002-10-25 22:55:53 +0000 | [diff] [blame] | 58 | // FIXME: Use the auto-insert form when it's available |
| 59 | F->getBasicBlockList().push_back(BB); |
| 60 | } |
| 61 | |
| 62 | // Visitation methods for various instructions. These methods simply emit |
| 63 | // fixed X86 code for each instruction. |
| 64 | // |
| 65 | void visitReturnInst(ReturnInst &RI); |
Chris Lattner | 2df035b | 2002-11-02 19:27:56 +0000 | [diff] [blame] | 66 | void visitBranchInst(BranchInst &BI); |
Chris Lattner | e2954c8 | 2002-11-02 20:04:26 +0000 | [diff] [blame] | 67 | |
| 68 | // Arithmetic operators |
Chris Lattner | f01729e | 2002-11-02 20:54:46 +0000 | [diff] [blame] | 69 | void visitSimpleBinary(BinaryOperator &B, unsigned OpcodeClass); |
Chris Lattner | 68aad93 | 2002-11-02 20:13:22 +0000 | [diff] [blame] | 70 | void visitAdd(BinaryOperator &B) { visitSimpleBinary(B, 0); } |
| 71 | void visitSub(BinaryOperator &B) { visitSimpleBinary(B, 1); } |
Chris Lattner | ca9671d | 2002-11-02 20:28:58 +0000 | [diff] [blame] | 72 | void visitMul(BinaryOperator &B); |
Chris Lattner | e2954c8 | 2002-11-02 20:04:26 +0000 | [diff] [blame] | 73 | |
Chris Lattner | f01729e | 2002-11-02 20:54:46 +0000 | [diff] [blame] | 74 | void visitDiv(BinaryOperator &B) { visitDivRem(B); } |
| 75 | void visitRem(BinaryOperator &B) { visitDivRem(B); } |
| 76 | void visitDivRem(BinaryOperator &B); |
| 77 | |
Chris Lattner | e2954c8 | 2002-11-02 20:04:26 +0000 | [diff] [blame] | 78 | // Bitwise operators |
Chris Lattner | 68aad93 | 2002-11-02 20:13:22 +0000 | [diff] [blame] | 79 | void visitAnd(BinaryOperator &B) { visitSimpleBinary(B, 2); } |
| 80 | void visitOr (BinaryOperator &B) { visitSimpleBinary(B, 3); } |
| 81 | void visitXor(BinaryOperator &B) { visitSimpleBinary(B, 4); } |
Chris Lattner | e2954c8 | 2002-11-02 20:04:26 +0000 | [diff] [blame] | 82 | |
| 83 | // Binary comparison operators |
Chris Lattner | 05093a5 | 2002-11-21 15:52:38 +0000 | [diff] [blame] | 84 | void visitSetCCInst(SetCondInst &I, unsigned OpNum); |
| 85 | void visitSetEQ(SetCondInst &I) { visitSetCCInst(I, 0); } |
| 86 | void visitSetNE(SetCondInst &I) { visitSetCCInst(I, 1); } |
| 87 | void visitSetLT(SetCondInst &I) { visitSetCCInst(I, 2); } |
| 88 | void visitSetGT(SetCondInst &I) { visitSetCCInst(I, 3); } |
| 89 | void visitSetLE(SetCondInst &I) { visitSetCCInst(I, 4); } |
| 90 | void visitSetGE(SetCondInst &I) { visitSetCCInst(I, 5); } |
Chris Lattner | 6fc3c52 | 2002-11-17 21:11:55 +0000 | [diff] [blame] | 91 | |
| 92 | // Memory Instructions |
| 93 | void visitLoadInst(LoadInst &I); |
| 94 | void visitStoreInst(StoreInst &I); |
Chris Lattner | e2954c8 | 2002-11-02 20:04:26 +0000 | [diff] [blame] | 95 | |
| 96 | // Other operators |
Brian Gaeke | a1719c9 | 2002-10-31 23:03:59 +0000 | [diff] [blame] | 97 | void visitShiftInst(ShiftInst &I); |
Chris Lattner | e2954c8 | 2002-11-02 20:04:26 +0000 | [diff] [blame] | 98 | void visitPHINode(PHINode &I); |
Chris Lattner | 7261408 | 2002-10-25 22:55:53 +0000 | [diff] [blame] | 99 | |
| 100 | void visitInstruction(Instruction &I) { |
| 101 | std::cerr << "Cannot instruction select: " << I; |
| 102 | abort(); |
| 103 | } |
| 104 | |
Chris Lattner | c5291f5 | 2002-10-27 21:16:59 +0000 | [diff] [blame] | 105 | |
| 106 | /// copyConstantToRegister - Output the instructions required to put the |
| 107 | /// specified constant into the specified register. |
| 108 | /// |
| 109 | void copyConstantToRegister(Constant *C, unsigned Reg); |
| 110 | |
Chris Lattner | 7261408 | 2002-10-25 22:55:53 +0000 | [diff] [blame] | 111 | /// getReg - This method turns an LLVM value into a register number. This |
| 112 | /// is guaranteed to produce the same register number for a particular value |
| 113 | /// every time it is queried. |
| 114 | /// |
| 115 | unsigned getReg(Value &V) { return getReg(&V); } // Allow references |
| 116 | unsigned getReg(Value *V) { |
| 117 | unsigned &Reg = RegMap[V]; |
Misha Brukman | d2cc017 | 2002-11-20 00:58:23 +0000 | [diff] [blame] | 118 | if (Reg == 0) { |
Chris Lattner | 7261408 | 2002-10-25 22:55:53 +0000 | [diff] [blame] | 119 | Reg = CurReg++; |
Misha Brukman | d2cc017 | 2002-11-20 00:58:23 +0000 | [diff] [blame] | 120 | RegMap[V] = Reg; |
| 121 | |
| 122 | // Add the mapping of regnumber => reg class to MachineFunction |
| 123 | F->addRegMap(Reg, |
| 124 | TM.getRegisterInfo()->getRegClassForType(V->getType())); |
| 125 | } |
Chris Lattner | 7261408 | 2002-10-25 22:55:53 +0000 | [diff] [blame] | 126 | |
Chris Lattner | 6f8fd25 | 2002-10-27 21:23:43 +0000 | [diff] [blame] | 127 | // If this operand is a constant, emit the code to copy the constant into |
| 128 | // the register here... |
| 129 | // |
Chris Lattner | c5291f5 | 2002-10-27 21:16:59 +0000 | [diff] [blame] | 130 | if (Constant *C = dyn_cast<Constant>(V)) |
| 131 | copyConstantToRegister(C, Reg); |
| 132 | |
Chris Lattner | 7261408 | 2002-10-25 22:55:53 +0000 | [diff] [blame] | 133 | return Reg; |
| 134 | } |
Chris Lattner | 7261408 | 2002-10-25 22:55:53 +0000 | [diff] [blame] | 135 | }; |
| 136 | } |
| 137 | |
Chris Lattner | 43189d1 | 2002-11-17 20:07:45 +0000 | [diff] [blame] | 138 | /// TypeClass - Used by the X86 backend to group LLVM types by their basic X86 |
| 139 | /// Representation. |
| 140 | /// |
| 141 | enum TypeClass { |
| 142 | cByte, cShort, cInt, cLong, cFloat, cDouble |
| 143 | }; |
| 144 | |
Chris Lattner | b1761fc | 2002-11-02 01:15:18 +0000 | [diff] [blame] | 145 | /// getClass - Turn a primitive type into a "class" number which is based on the |
| 146 | /// size of the type, and whether or not it is floating point. |
| 147 | /// |
Chris Lattner | 43189d1 | 2002-11-17 20:07:45 +0000 | [diff] [blame] | 148 | static inline TypeClass getClass(const Type *Ty) { |
Chris Lattner | b1761fc | 2002-11-02 01:15:18 +0000 | [diff] [blame] | 149 | switch (Ty->getPrimitiveID()) { |
| 150 | case Type::SByteTyID: |
Chris Lattner | 43189d1 | 2002-11-17 20:07:45 +0000 | [diff] [blame] | 151 | case Type::UByteTyID: return cByte; // Byte operands are class #0 |
Chris Lattner | b1761fc | 2002-11-02 01:15:18 +0000 | [diff] [blame] | 152 | case Type::ShortTyID: |
Chris Lattner | 43189d1 | 2002-11-17 20:07:45 +0000 | [diff] [blame] | 153 | case Type::UShortTyID: return cShort; // Short operands are class #1 |
Chris Lattner | b1761fc | 2002-11-02 01:15:18 +0000 | [diff] [blame] | 154 | case Type::IntTyID: |
| 155 | case Type::UIntTyID: |
Chris Lattner | 43189d1 | 2002-11-17 20:07:45 +0000 | [diff] [blame] | 156 | case Type::PointerTyID: return cInt; // Int's and pointers are class #2 |
Chris Lattner | b1761fc | 2002-11-02 01:15:18 +0000 | [diff] [blame] | 157 | |
| 158 | case Type::LongTyID: |
Chris Lattner | 43189d1 | 2002-11-17 20:07:45 +0000 | [diff] [blame] | 159 | case Type::ULongTyID: return cLong; // Longs are class #3 |
| 160 | case Type::FloatTyID: return cFloat; // Float is class #4 |
| 161 | case Type::DoubleTyID: return cDouble; // Doubles are class #5 |
Chris Lattner | b1761fc | 2002-11-02 01:15:18 +0000 | [diff] [blame] | 162 | default: |
| 163 | assert(0 && "Invalid type to getClass!"); |
Chris Lattner | 43189d1 | 2002-11-17 20:07:45 +0000 | [diff] [blame] | 164 | return cByte; // not reached |
Chris Lattner | b1761fc | 2002-11-02 01:15:18 +0000 | [diff] [blame] | 165 | } |
| 166 | } |
Chris Lattner | c5291f5 | 2002-10-27 21:16:59 +0000 | [diff] [blame] | 167 | |
Chris Lattner | 0692536 | 2002-11-17 21:56:38 +0000 | [diff] [blame] | 168 | |
Chris Lattner | c5291f5 | 2002-10-27 21:16:59 +0000 | [diff] [blame] | 169 | /// copyConstantToRegister - Output the instructions required to put the |
| 170 | /// specified constant into the specified register. |
| 171 | /// |
| 172 | void ISel::copyConstantToRegister(Constant *C, unsigned R) { |
| 173 | assert (!isa<ConstantExpr>(C) && "Constant expressions not yet handled!\n"); |
| 174 | |
Chris Lattner | b1761fc | 2002-11-02 01:15:18 +0000 | [diff] [blame] | 175 | if (C->getType()->isIntegral()) { |
| 176 | unsigned Class = getClass(C->getType()); |
| 177 | assert(Class != 3 && "Type not handled yet!"); |
| 178 | |
| 179 | static const unsigned IntegralOpcodeTab[] = { |
| 180 | X86::MOVir8, X86::MOVir16, X86::MOVir32 |
| 181 | }; |
| 182 | |
| 183 | if (C->getType()->isSigned()) { |
| 184 | ConstantSInt *CSI = cast<ConstantSInt>(C); |
| 185 | BuildMI(BB, IntegralOpcodeTab[Class], 1, R).addSImm(CSI->getValue()); |
| 186 | } else { |
| 187 | ConstantUInt *CUI = cast<ConstantUInt>(C); |
| 188 | BuildMI(BB, IntegralOpcodeTab[Class], 1, R).addZImm(CUI->getValue()); |
| 189 | } |
| 190 | } else { |
| 191 | assert(0 && "Type not handled yet!"); |
Chris Lattner | c5291f5 | 2002-10-27 21:16:59 +0000 | [diff] [blame] | 192 | } |
| 193 | } |
| 194 | |
Chris Lattner | 0692536 | 2002-11-17 21:56:38 +0000 | [diff] [blame] | 195 | |
Brian Gaeke | 1749d63 | 2002-11-07 17:59:21 +0000 | [diff] [blame] | 196 | /// SetCC instructions - Here we just emit boilerplate code to set a byte-sized |
| 197 | /// register, then move it to wherever the result should be. |
| 198 | /// We handle FP setcc instructions by pushing them, doing a |
| 199 | /// compare-and-pop-twice, and then copying the concodes to the main |
| 200 | /// processor's concodes (I didn't make this up, it's in the Intel manual) |
| 201 | /// |
Chris Lattner | 05093a5 | 2002-11-21 15:52:38 +0000 | [diff] [blame] | 202 | void ISel::visitSetCCInst(SetCondInst &I, unsigned OpNum) { |
Brian Gaeke | 1749d63 | 2002-11-07 17:59:21 +0000 | [diff] [blame] | 203 | // The arguments are already supposed to be of the same type. |
Chris Lattner | 05093a5 | 2002-11-21 15:52:38 +0000 | [diff] [blame] | 204 | const Type *CompTy = I.getOperand(0)->getType(); |
| 205 | unsigned reg1 = getReg(I.getOperand(0)); |
| 206 | unsigned reg2 = getReg(I.getOperand(1)); |
| 207 | |
| 208 | unsigned Class = getClass(CompTy); |
| 209 | switch (Class) { |
| 210 | // Emit: cmp <var1>, <var2> (do the comparison). We can |
| 211 | // compare 8-bit with 8-bit, 16-bit with 16-bit, 32-bit with |
| 212 | // 32-bit. |
| 213 | case cByte: |
| 214 | BuildMI (BB, X86::CMPrr8, 2).addReg (reg1).addReg (reg2); |
| 215 | break; |
| 216 | case cShort: |
| 217 | BuildMI (BB, X86::CMPrr16, 2).addReg (reg1).addReg (reg2); |
| 218 | break; |
| 219 | case cInt: |
| 220 | BuildMI (BB, X86::CMPrr32, 2).addReg (reg1).addReg (reg2); |
| 221 | break; |
| 222 | |
| 223 | // Push the variables on the stack with fldl opcodes. |
| 224 | // FIXME: assuming var1, var2 are in memory, if not, spill to |
| 225 | // stack first |
| 226 | case cFloat: // Floats |
| 227 | BuildMI (BB, X86::FLDr4, 1, X86::NoReg).addReg (reg1); |
| 228 | BuildMI (BB, X86::FLDr4, 1, X86::NoReg).addReg (reg2); |
| 229 | break; |
| 230 | case cDouble: // Doubles |
| 231 | BuildMI (BB, X86::FLDr8, 1, X86::NoReg).addReg (reg1); |
| 232 | BuildMI (BB, X86::FLDr8, 1, X86::NoReg).addReg (reg2); |
| 233 | break; |
| 234 | case cLong: |
| 235 | default: |
| 236 | visitInstruction(I); |
| 237 | } |
| 238 | |
| 239 | if (CompTy->isFloatingPoint()) { |
| 240 | // (Non-trapping) compare and pop twice. |
| 241 | BuildMI (BB, X86::FUCOMPP, 0); |
| 242 | // Move fp status word (concodes) to ax. |
| 243 | BuildMI (BB, X86::FNSTSWr8, 1, X86::AX); |
| 244 | // Load real concodes from ax. |
| 245 | BuildMI (BB, X86::SAHF, 1).addReg(X86::AH); |
| 246 | } |
| 247 | |
Brian Gaeke | 1749d63 | 2002-11-07 17:59:21 +0000 | [diff] [blame] | 248 | // Emit setOp instruction (extract concode; clobbers ax), |
| 249 | // using the following mapping: |
| 250 | // LLVM -> X86 signed X86 unsigned |
| 251 | // ----- ----- ----- |
| 252 | // seteq -> sete sete |
| 253 | // setne -> setne setne |
| 254 | // setlt -> setl setb |
| 255 | // setgt -> setg seta |
| 256 | // setle -> setle setbe |
| 257 | // setge -> setge setae |
Chris Lattner | 05093a5 | 2002-11-21 15:52:38 +0000 | [diff] [blame] | 258 | |
| 259 | static const unsigned OpcodeTab[2][6] = { |
Chris Lattner | 4b4e9dd | 2002-11-21 16:19:42 +0000 | [diff] [blame^] | 260 | {X86::SETEr, X86::SETNEr, X86::SETBr, X86::SETAr, X86::SETBEr, X86::SETAEr}, |
| 261 | {X86::SETEr, X86::SETNEr, X86::SETLr, X86::SETGr, X86::SETLEr, X86::SETGEr}, |
Chris Lattner | 05093a5 | 2002-11-21 15:52:38 +0000 | [diff] [blame] | 262 | }; |
| 263 | |
| 264 | BuildMI(BB, OpcodeTab[CompTy->isSigned()][OpNum], 0, X86::AL); |
| 265 | |
Brian Gaeke | 1749d63 | 2002-11-07 17:59:21 +0000 | [diff] [blame] | 266 | // Put it in the result using a move. |
Chris Lattner | 05093a5 | 2002-11-21 15:52:38 +0000 | [diff] [blame] | 267 | BuildMI (BB, X86::MOVrr8, 1, getReg(I)).addReg(X86::AL); |
Brian Gaeke | 1749d63 | 2002-11-07 17:59:21 +0000 | [diff] [blame] | 268 | } |
Chris Lattner | 51b49a9 | 2002-11-02 19:45:49 +0000 | [diff] [blame] | 269 | |
Chris Lattner | c5291f5 | 2002-10-27 21:16:59 +0000 | [diff] [blame] | 270 | |
Chris Lattner | 7261408 | 2002-10-25 22:55:53 +0000 | [diff] [blame] | 271 | /// 'ret' instruction - Here we are interested in meeting the x86 ABI. As such, |
| 272 | /// we have the following possibilities: |
| 273 | /// |
| 274 | /// ret void: No return value, simply emit a 'ret' instruction |
| 275 | /// ret sbyte, ubyte : Extend value into EAX and return |
| 276 | /// ret short, ushort: Extend value into EAX and return |
| 277 | /// ret int, uint : Move value into EAX and return |
| 278 | /// ret pointer : Move value into EAX and return |
Chris Lattner | 0692536 | 2002-11-17 21:56:38 +0000 | [diff] [blame] | 279 | /// ret long, ulong : Move value into EAX/EDX and return |
| 280 | /// ret float/double : Top of FP stack |
Chris Lattner | 7261408 | 2002-10-25 22:55:53 +0000 | [diff] [blame] | 281 | /// |
Chris Lattner | 6fc3c52 | 2002-11-17 21:11:55 +0000 | [diff] [blame] | 282 | void ISel::visitReturnInst (ReturnInst &I) { |
Chris Lattner | 43189d1 | 2002-11-17 20:07:45 +0000 | [diff] [blame] | 283 | if (I.getNumOperands() == 0) { |
| 284 | // Emit a 'ret' instruction |
| 285 | BuildMI(BB, X86::RET, 0); |
| 286 | return; |
| 287 | } |
| 288 | |
| 289 | unsigned val = getReg(I.getOperand(0)); |
Chris Lattner | 6fc3c52 | 2002-11-17 21:11:55 +0000 | [diff] [blame] | 290 | unsigned Class = getClass(I.getOperand(0)->getType()); |
Chris Lattner | 43189d1 | 2002-11-17 20:07:45 +0000 | [diff] [blame] | 291 | bool isUnsigned = I.getOperand(0)->getType()->isUnsigned(); |
| 292 | switch (Class) { |
| 293 | case cByte: |
| 294 | // ret sbyte, ubyte: Extend value into EAX and return |
Chris Lattner | 6fc3c52 | 2002-11-17 21:11:55 +0000 | [diff] [blame] | 295 | if (isUnsigned) |
Chris Lattner | 43189d1 | 2002-11-17 20:07:45 +0000 | [diff] [blame] | 296 | BuildMI (BB, X86::MOVZXr32r8, 1, X86::EAX).addReg (val); |
Chris Lattner | 6fc3c52 | 2002-11-17 21:11:55 +0000 | [diff] [blame] | 297 | else |
Chris Lattner | 43189d1 | 2002-11-17 20:07:45 +0000 | [diff] [blame] | 298 | BuildMI (BB, X86::MOVSXr32r8, 1, X86::EAX).addReg (val); |
Chris Lattner | 43189d1 | 2002-11-17 20:07:45 +0000 | [diff] [blame] | 299 | break; |
| 300 | case cShort: |
| 301 | // ret short, ushort: Extend value into EAX and return |
Chris Lattner | 6fc3c52 | 2002-11-17 21:11:55 +0000 | [diff] [blame] | 302 | if (isUnsigned) |
Chris Lattner | 43189d1 | 2002-11-17 20:07:45 +0000 | [diff] [blame] | 303 | BuildMI (BB, X86::MOVZXr32r16, 1, X86::EAX).addReg (val); |
Chris Lattner | 6fc3c52 | 2002-11-17 21:11:55 +0000 | [diff] [blame] | 304 | else |
Chris Lattner | 43189d1 | 2002-11-17 20:07:45 +0000 | [diff] [blame] | 305 | BuildMI (BB, X86::MOVSXr32r16, 1, X86::EAX).addReg (val); |
Chris Lattner | 43189d1 | 2002-11-17 20:07:45 +0000 | [diff] [blame] | 306 | break; |
| 307 | case cInt: |
| 308 | // ret int, uint, ptr: Move value into EAX and return |
| 309 | // MOV EAX, <val> |
| 310 | BuildMI(BB, X86::MOVrr32, 1, X86::EAX).addReg(val); |
| 311 | break; |
| 312 | |
| 313 | // ret float/double: top of FP stack |
| 314 | // FLD <val> |
| 315 | case cFloat: // Floats |
| 316 | BuildMI(BB, X86::FLDr4, 1).addReg(val); |
| 317 | break; |
| 318 | case cDouble: // Doubles |
| 319 | BuildMI(BB, X86::FLDr8, 1).addReg(val); |
| 320 | break; |
| 321 | case cLong: |
| 322 | // ret long: use EAX(least significant 32 bits)/EDX (most |
| 323 | // significant 32)...uh, I think so Brain, but how do i call |
| 324 | // up the two parts of the value from inside this mouse |
| 325 | // cage? *zort* |
| 326 | default: |
| 327 | visitInstruction(I); |
| 328 | } |
| 329 | |
| 330 | // Emit a 'ret' instruction |
| 331 | BuildMI(BB, X86::RET, 0); |
Chris Lattner | 7261408 | 2002-10-25 22:55:53 +0000 | [diff] [blame] | 332 | } |
| 333 | |
Chris Lattner | 51b49a9 | 2002-11-02 19:45:49 +0000 | [diff] [blame] | 334 | /// visitBranchInst - Handle conditional and unconditional branches here. Note |
| 335 | /// that since code layout is frozen at this point, that if we are trying to |
| 336 | /// jump to a block that is the immediate successor of the current block, we can |
| 337 | /// just make a fall-through. (but we don't currently). |
| 338 | /// |
Brian Gaeke | c03a0cb | 2002-11-19 09:08:47 +0000 | [diff] [blame] | 339 | void |
| 340 | ISel::visitBranchInst (BranchInst & BI) |
| 341 | { |
| 342 | if (BI.isConditional ()) |
| 343 | { |
| 344 | BasicBlock *ifTrue = BI.getSuccessor (0); |
| 345 | BasicBlock *ifFalse = BI.getSuccessor (1); // this is really unobvious |
Chris Lattner | 2df035b | 2002-11-02 19:27:56 +0000 | [diff] [blame] | 346 | |
Brian Gaeke | c03a0cb | 2002-11-19 09:08:47 +0000 | [diff] [blame] | 347 | // simplest thing I can think of: compare condition with zero, |
| 348 | // followed by jump-if-equal to ifFalse, and jump-if-nonequal to |
| 349 | // ifTrue |
| 350 | unsigned int condReg = getReg (BI.getCondition ()); |
Chris Lattner | 97ad9e1 | 2002-11-21 01:59:50 +0000 | [diff] [blame] | 351 | BuildMI (BB, X86::CMPri8, 2).addReg (condReg).addZImm (0); |
Brian Gaeke | c03a0cb | 2002-11-19 09:08:47 +0000 | [diff] [blame] | 352 | BuildMI (BB, X86::JNE, 1).addPCDisp (BI.getSuccessor (0)); |
| 353 | BuildMI (BB, X86::JE, 1).addPCDisp (BI.getSuccessor (1)); |
| 354 | } |
| 355 | else // unconditional branch |
| 356 | { |
| 357 | BuildMI (BB, X86::JMP, 1).addPCDisp (BI.getSuccessor (0)); |
| 358 | } |
Chris Lattner | 2df035b | 2002-11-02 19:27:56 +0000 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | |
Chris Lattner | 68aad93 | 2002-11-02 20:13:22 +0000 | [diff] [blame] | 362 | /// visitSimpleBinary - Implement simple binary operators for integral types... |
| 363 | /// OperatorClass is one of: 0 for Add, 1 for Sub, 2 for And, 3 for Or, |
| 364 | /// 4 for Xor. |
| 365 | /// |
| 366 | void ISel::visitSimpleBinary(BinaryOperator &B, unsigned OperatorClass) { |
| 367 | if (B.getType() == Type::BoolTy) // FIXME: Handle bools for logicals |
Chris Lattner | e2954c8 | 2002-11-02 20:04:26 +0000 | [diff] [blame] | 368 | visitInstruction(B); |
| 369 | |
| 370 | unsigned Class = getClass(B.getType()); |
| 371 | if (Class > 2) // FIXME: Handle longs |
| 372 | visitInstruction(B); |
| 373 | |
| 374 | static const unsigned OpcodeTab[][4] = { |
Chris Lattner | 68aad93 | 2002-11-02 20:13:22 +0000 | [diff] [blame] | 375 | // Arithmetic operators |
| 376 | { X86::ADDrr8, X86::ADDrr16, X86::ADDrr32, 0 }, // ADD |
| 377 | { X86::SUBrr8, X86::SUBrr16, X86::SUBrr32, 0 }, // SUB |
| 378 | |
| 379 | // Bitwise operators |
Chris Lattner | e2954c8 | 2002-11-02 20:04:26 +0000 | [diff] [blame] | 380 | { X86::ANDrr8, X86::ANDrr16, X86::ANDrr32, 0 }, // AND |
| 381 | { X86:: ORrr8, X86:: ORrr16, X86:: ORrr32, 0 }, // OR |
| 382 | { X86::XORrr8, X86::XORrr16, X86::XORrr32, 0 }, // XOR |
| 383 | }; |
| 384 | |
| 385 | unsigned Opcode = OpcodeTab[OperatorClass][Class]; |
| 386 | unsigned Op0r = getReg(B.getOperand(0)); |
| 387 | unsigned Op1r = getReg(B.getOperand(1)); |
| 388 | BuildMI(BB, Opcode, 2, getReg(B)).addReg(Op0r).addReg(Op1r); |
| 389 | } |
| 390 | |
Chris Lattner | ca9671d | 2002-11-02 20:28:58 +0000 | [diff] [blame] | 391 | /// visitMul - Multiplies are not simple binary operators because they must deal |
| 392 | /// with the EAX register explicitly. |
| 393 | /// |
| 394 | void ISel::visitMul(BinaryOperator &I) { |
| 395 | unsigned Class = getClass(I.getType()); |
| 396 | if (Class > 2) // FIXME: Handle longs |
| 397 | visitInstruction(I); |
Chris Lattner | e2954c8 | 2002-11-02 20:04:26 +0000 | [diff] [blame] | 398 | |
Chris Lattner | ca9671d | 2002-11-02 20:28:58 +0000 | [diff] [blame] | 399 | static const unsigned Regs[] ={ X86::AL , X86::AX , X86::EAX }; |
Chris Lattner | 0692536 | 2002-11-17 21:56:38 +0000 | [diff] [blame] | 400 | static const unsigned Clobbers[] ={ X86::AH , X86::DX , X86::EDX }; |
Chris Lattner | ca9671d | 2002-11-02 20:28:58 +0000 | [diff] [blame] | 401 | static const unsigned MulOpcode[]={ X86::MULrr8, X86::MULrr16, X86::MULrr32 }; |
| 402 | static const unsigned MovOpcode[]={ X86::MOVrr8, X86::MOVrr16, X86::MOVrr32 }; |
| 403 | |
Chris Lattner | 0692536 | 2002-11-17 21:56:38 +0000 | [diff] [blame] | 404 | unsigned Reg = Regs[Class]; |
| 405 | unsigned Clobber = Clobbers[Class]; |
| 406 | unsigned Op0Reg = getReg(I.getOperand(0)); |
| 407 | unsigned Op1Reg = getReg(I.getOperand(1)); |
Chris Lattner | ca9671d | 2002-11-02 20:28:58 +0000 | [diff] [blame] | 408 | |
| 409 | // Put the first operand into one of the A registers... |
| 410 | BuildMI(BB, MovOpcode[Class], 1, Reg).addReg(Op0Reg); |
| 411 | |
Chris Lattner | 0692536 | 2002-11-17 21:56:38 +0000 | [diff] [blame] | 412 | // Emit the appropriate multiply instruction... |
Chris Lattner | 71e83ca | 2002-11-17 22:33:26 +0000 | [diff] [blame] | 413 | BuildMI(BB, MulOpcode[Class], 3) |
Chris Lattner | 0692536 | 2002-11-17 21:56:38 +0000 | [diff] [blame] | 414 | .addReg(Reg, UseAndDef).addReg(Op1Reg).addClobber(Clobber); |
Chris Lattner | ca9671d | 2002-11-02 20:28:58 +0000 | [diff] [blame] | 415 | |
| 416 | // Put the result into the destination register... |
| 417 | BuildMI(BB, MovOpcode[Class], 1, getReg(I)).addReg(Reg); |
Chris Lattner | f01729e | 2002-11-02 20:54:46 +0000 | [diff] [blame] | 418 | } |
Chris Lattner | ca9671d | 2002-11-02 20:28:58 +0000 | [diff] [blame] | 419 | |
Chris Lattner | 0692536 | 2002-11-17 21:56:38 +0000 | [diff] [blame] | 420 | |
Chris Lattner | f01729e | 2002-11-02 20:54:46 +0000 | [diff] [blame] | 421 | /// visitDivRem - Handle division and remainder instructions... these |
| 422 | /// instruction both require the same instructions to be generated, they just |
| 423 | /// select the result from a different register. Note that both of these |
| 424 | /// instructions work differently for signed and unsigned operands. |
| 425 | /// |
| 426 | void ISel::visitDivRem(BinaryOperator &I) { |
| 427 | unsigned Class = getClass(I.getType()); |
| 428 | if (Class > 2) // FIXME: Handle longs |
| 429 | visitInstruction(I); |
| 430 | |
| 431 | static const unsigned Regs[] ={ X86::AL , X86::AX , X86::EAX }; |
| 432 | static const unsigned MovOpcode[]={ X86::MOVrr8, X86::MOVrr16, X86::MOVrr32 }; |
Brian Gaeke | 6559bb9 | 2002-11-14 22:32:30 +0000 | [diff] [blame] | 433 | static const unsigned ExtOpcode[]={ X86::CBW , X86::CWD , X86::CDQ }; |
Chris Lattner | f01729e | 2002-11-02 20:54:46 +0000 | [diff] [blame] | 434 | static const unsigned ClrOpcode[]={ X86::XORrr8, X86::XORrr16, X86::XORrr32 }; |
| 435 | static const unsigned ExtRegs[] ={ X86::AH , X86::DX , X86::EDX }; |
| 436 | |
| 437 | static const unsigned DivOpcode[][4] = { |
| 438 | { X86::DIVrr8 , X86::DIVrr16 , X86::DIVrr32 , 0 }, // Unsigned division |
| 439 | { X86::IDIVrr8, X86::IDIVrr16, X86::IDIVrr32, 0 }, // Signed division |
| 440 | }; |
| 441 | |
| 442 | bool isSigned = I.getType()->isSigned(); |
| 443 | unsigned Reg = Regs[Class]; |
| 444 | unsigned ExtReg = ExtRegs[Class]; |
Chris Lattner | 6fc3c52 | 2002-11-17 21:11:55 +0000 | [diff] [blame] | 445 | unsigned Op0Reg = getReg(I.getOperand(0)); |
Chris Lattner | f01729e | 2002-11-02 20:54:46 +0000 | [diff] [blame] | 446 | unsigned Op1Reg = getReg(I.getOperand(1)); |
| 447 | |
| 448 | // Put the first operand into one of the A registers... |
| 449 | BuildMI(BB, MovOpcode[Class], 1, Reg).addReg(Op0Reg); |
| 450 | |
| 451 | if (isSigned) { |
| 452 | // Emit a sign extension instruction... |
| 453 | BuildMI(BB, ExtOpcode[Class], 1, ExtReg).addReg(Reg); |
| 454 | } else { |
| 455 | // If unsigned, emit a zeroing instruction... (reg = xor reg, reg) |
| 456 | BuildMI(BB, ClrOpcode[Class], 2, ExtReg).addReg(ExtReg).addReg(ExtReg); |
| 457 | } |
| 458 | |
Chris Lattner | 0692536 | 2002-11-17 21:56:38 +0000 | [diff] [blame] | 459 | // Emit the appropriate divide or remainder instruction... |
| 460 | BuildMI(BB, DivOpcode[isSigned][Class], 2) |
| 461 | .addReg(Reg, UseAndDef).addReg(ExtReg, UseAndDef).addReg(Op1Reg); |
| 462 | |
Chris Lattner | f01729e | 2002-11-02 20:54:46 +0000 | [diff] [blame] | 463 | // Figure out which register we want to pick the result out of... |
| 464 | unsigned DestReg = (I.getOpcode() == Instruction::Div) ? Reg : ExtReg; |
| 465 | |
Chris Lattner | f01729e | 2002-11-02 20:54:46 +0000 | [diff] [blame] | 466 | // Put the result into the destination register... |
| 467 | BuildMI(BB, MovOpcode[Class], 1, getReg(I)).addReg(DestReg); |
Chris Lattner | ca9671d | 2002-11-02 20:28:58 +0000 | [diff] [blame] | 468 | } |
Chris Lattner | e2954c8 | 2002-11-02 20:04:26 +0000 | [diff] [blame] | 469 | |
Chris Lattner | 0692536 | 2002-11-17 21:56:38 +0000 | [diff] [blame] | 470 | |
Brian Gaeke | a1719c9 | 2002-10-31 23:03:59 +0000 | [diff] [blame] | 471 | /// Shift instructions: 'shl', 'sar', 'shr' - Some special cases here |
| 472 | /// for constant immediate shift values, and for constant immediate |
| 473 | /// shift values equal to 1. Even the general case is sort of special, |
| 474 | /// because the shift amount has to be in CL, not just any old register. |
| 475 | /// |
Chris Lattner | f01729e | 2002-11-02 20:54:46 +0000 | [diff] [blame] | 476 | void ISel::visitShiftInst (ShiftInst &I) { |
| 477 | unsigned Op0r = getReg (I.getOperand(0)); |
| 478 | unsigned DestReg = getReg(I); |
Chris Lattner | e9913f2 | 2002-11-02 01:41:55 +0000 | [diff] [blame] | 479 | bool isLeftShift = I.getOpcode() == Instruction::Shl; |
| 480 | bool isOperandSigned = I.getType()->isUnsigned(); |
Chris Lattner | b1761fc | 2002-11-02 01:15:18 +0000 | [diff] [blame] | 481 | unsigned OperandClass = getClass(I.getType()); |
| 482 | |
| 483 | if (OperandClass > 2) |
| 484 | visitInstruction(I); // Can't handle longs yet! |
Chris Lattner | 796df73 | 2002-11-02 00:44:25 +0000 | [diff] [blame] | 485 | |
Brian Gaeke | a1719c9 | 2002-10-31 23:03:59 +0000 | [diff] [blame] | 486 | if (ConstantUInt *CUI = dyn_cast <ConstantUInt> (I.getOperand (1))) |
| 487 | { |
Chris Lattner | 796df73 | 2002-11-02 00:44:25 +0000 | [diff] [blame] | 488 | // The shift amount is constant, guaranteed to be a ubyte. Get its value. |
| 489 | assert(CUI->getType() == Type::UByteTy && "Shift amount not a ubyte?"); |
| 490 | unsigned char shAmt = CUI->getValue(); |
| 491 | |
Chris Lattner | e9913f2 | 2002-11-02 01:41:55 +0000 | [diff] [blame] | 492 | static const unsigned ConstantOperand[][4] = { |
| 493 | { X86::SHRir8, X86::SHRir16, X86::SHRir32, 0 }, // SHR |
| 494 | { X86::SARir8, X86::SARir16, X86::SARir32, 0 }, // SAR |
| 495 | { X86::SHLir8, X86::SHLir16, X86::SHLir32, 0 }, // SHL |
| 496 | { X86::SHLir8, X86::SHLir16, X86::SHLir32, 0 }, // SAL = SHL |
Chris Lattner | b1761fc | 2002-11-02 01:15:18 +0000 | [diff] [blame] | 497 | }; |
| 498 | |
Chris Lattner | e9913f2 | 2002-11-02 01:41:55 +0000 | [diff] [blame] | 499 | const unsigned *OpTab = // Figure out the operand table to use |
| 500 | ConstantOperand[isLeftShift*2+isOperandSigned]; |
Chris Lattner | b1761fc | 2002-11-02 01:15:18 +0000 | [diff] [blame] | 501 | |
Brian Gaeke | a1719c9 | 2002-10-31 23:03:59 +0000 | [diff] [blame] | 502 | // Emit: <insn> reg, shamt (shift-by-immediate opcode "ir" form.) |
Chris Lattner | b1761fc | 2002-11-02 01:15:18 +0000 | [diff] [blame] | 503 | BuildMI(BB, OpTab[OperandClass], 2, DestReg).addReg(Op0r).addZImm(shAmt); |
Brian Gaeke | a1719c9 | 2002-10-31 23:03:59 +0000 | [diff] [blame] | 504 | } |
| 505 | else |
| 506 | { |
| 507 | // The shift amount is non-constant. |
| 508 | // |
| 509 | // In fact, you can only shift with a variable shift amount if |
| 510 | // that amount is already in the CL register, so we have to put it |
| 511 | // there first. |
| 512 | // |
Chris Lattner | e9913f2 | 2002-11-02 01:41:55 +0000 | [diff] [blame] | 513 | |
Brian Gaeke | a1719c9 | 2002-10-31 23:03:59 +0000 | [diff] [blame] | 514 | // Emit: move cl, shiftAmount (put the shift amount in CL.) |
Chris Lattner | ca9671d | 2002-11-02 20:28:58 +0000 | [diff] [blame] | 515 | BuildMI(BB, X86::MOVrr8, 1, X86::CL).addReg(getReg(I.getOperand(1))); |
Chris Lattner | b1761fc | 2002-11-02 01:15:18 +0000 | [diff] [blame] | 516 | |
| 517 | // This is a shift right (SHR). |
Chris Lattner | e9913f2 | 2002-11-02 01:41:55 +0000 | [diff] [blame] | 518 | static const unsigned NonConstantOperand[][4] = { |
| 519 | { X86::SHRrr8, X86::SHRrr16, X86::SHRrr32, 0 }, // SHR |
| 520 | { X86::SARrr8, X86::SARrr16, X86::SARrr32, 0 }, // SAR |
| 521 | { X86::SHLrr8, X86::SHLrr16, X86::SHLrr32, 0 }, // SHL |
| 522 | { X86::SHLrr8, X86::SHLrr16, X86::SHLrr32, 0 }, // SAL = SHL |
Chris Lattner | b1761fc | 2002-11-02 01:15:18 +0000 | [diff] [blame] | 523 | }; |
| 524 | |
Chris Lattner | e9913f2 | 2002-11-02 01:41:55 +0000 | [diff] [blame] | 525 | const unsigned *OpTab = // Figure out the operand table to use |
| 526 | NonConstantOperand[isLeftShift*2+isOperandSigned]; |
Chris Lattner | b1761fc | 2002-11-02 01:15:18 +0000 | [diff] [blame] | 527 | |
Chris Lattner | e9913f2 | 2002-11-02 01:41:55 +0000 | [diff] [blame] | 528 | BuildMI(BB, OpTab[OperandClass], 2, DestReg).addReg(Op0r).addReg(X86::CL); |
Brian Gaeke | a1719c9 | 2002-10-31 23:03:59 +0000 | [diff] [blame] | 529 | } |
| 530 | } |
| 531 | |
Chris Lattner | 0692536 | 2002-11-17 21:56:38 +0000 | [diff] [blame] | 532 | |
Chris Lattner | 6fc3c52 | 2002-11-17 21:11:55 +0000 | [diff] [blame] | 533 | /// visitLoadInst - Implement LLVM load instructions in terms of the x86 'mov' |
| 534 | /// instruction. |
| 535 | /// |
| 536 | void ISel::visitLoadInst(LoadInst &I) { |
| 537 | unsigned Class = getClass(I.getType()); |
| 538 | if (Class > 2) // FIXME: Handle longs and others... |
| 539 | visitInstruction(I); |
| 540 | |
| 541 | static const unsigned Opcode[] = { X86::MOVmr8, X86::MOVmr16, X86::MOVmr32 }; |
| 542 | |
| 543 | unsigned AddressReg = getReg(I.getOperand(0)); |
| 544 | addDirectMem(BuildMI(BB, Opcode[Class], 4, getReg(I)), AddressReg); |
| 545 | } |
| 546 | |
Chris Lattner | 0692536 | 2002-11-17 21:56:38 +0000 | [diff] [blame] | 547 | |
Chris Lattner | 6fc3c52 | 2002-11-17 21:11:55 +0000 | [diff] [blame] | 548 | /// visitStoreInst - Implement LLVM store instructions in terms of the x86 'mov' |
| 549 | /// instruction. |
| 550 | /// |
| 551 | void ISel::visitStoreInst(StoreInst &I) { |
| 552 | unsigned Class = getClass(I.getOperand(0)->getType()); |
| 553 | if (Class > 2) // FIXME: Handle longs and others... |
| 554 | visitInstruction(I); |
| 555 | |
| 556 | static const unsigned Opcode[] = { X86::MOVrm8, X86::MOVrm16, X86::MOVrm32 }; |
| 557 | |
| 558 | unsigned ValReg = getReg(I.getOperand(0)); |
| 559 | unsigned AddressReg = getReg(I.getOperand(1)); |
| 560 | addDirectMem(BuildMI(BB, Opcode[Class], 1+4), AddressReg).addReg(ValReg); |
| 561 | } |
| 562 | |
| 563 | |
Chris Lattner | e2954c8 | 2002-11-02 20:04:26 +0000 | [diff] [blame] | 564 | /// visitPHINode - Turn an LLVM PHI node into an X86 PHI node... |
| 565 | /// |
| 566 | void ISel::visitPHINode(PHINode &PN) { |
| 567 | MachineInstr *MI = BuildMI(BB, X86::PHI, PN.getNumOperands(), getReg(PN)); |
Chris Lattner | 7261408 | 2002-10-25 22:55:53 +0000 | [diff] [blame] | 568 | |
Chris Lattner | e2954c8 | 2002-11-02 20:04:26 +0000 | [diff] [blame] | 569 | for (unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i) { |
| 570 | // FIXME: This will put constants after the PHI nodes in the block, which |
| 571 | // is invalid. They should be put inline into the PHI node eventually. |
| 572 | // |
| 573 | MI->addRegOperand(getReg(PN.getIncomingValue(i))); |
| 574 | MI->addPCDispOperand(PN.getIncomingBlock(i)); |
| 575 | } |
Chris Lattner | 7261408 | 2002-10-25 22:55:53 +0000 | [diff] [blame] | 576 | } |
| 577 | |
Brian Gaeke | a1719c9 | 2002-10-31 23:03:59 +0000 | [diff] [blame] | 578 | |
Chris Lattner | b4f68ed | 2002-10-29 22:37:54 +0000 | [diff] [blame] | 579 | /// createSimpleX86InstructionSelector - This pass converts an LLVM function |
| 580 | /// into a machine code representation is a very simple peep-hole fashion. The |
Chris Lattner | 7261408 | 2002-10-25 22:55:53 +0000 | [diff] [blame] | 581 | /// generated code sucks but the implementation is nice and simple. |
| 582 | /// |
Chris Lattner | b4f68ed | 2002-10-29 22:37:54 +0000 | [diff] [blame] | 583 | Pass *createSimpleX86InstructionSelector(TargetMachine &TM) { |
| 584 | return new ISel(TM); |
Chris Lattner | 7261408 | 2002-10-25 22:55:53 +0000 | [diff] [blame] | 585 | } |