Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1 | //===-- WriteInst.cpp - Functions for writing instructions -------*- C++ -*--=// |
| 2 | // |
| 3 | // This file implements the routines for encoding instruction opcodes to a |
| 4 | // bytecode stream. |
| 5 | // |
| 6 | // Note that the performance of this library is not terribly important, because |
| 7 | // it shouldn't be used by JIT type applications... so it is not a huge focus |
| 8 | // at least. :) |
| 9 | // |
| 10 | //===----------------------------------------------------------------------===// |
| 11 | |
| 12 | #include "WriterInternals.h" |
| 13 | #include "llvm/Module.h" |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 14 | #include "llvm/DerivedTypes.h" |
Chris Lattner | ef9c23f | 2001-10-03 14:53:21 +0000 | [diff] [blame] | 15 | #include "llvm/iOther.h" |
Chris Lattner | 1b98c5c | 2001-10-13 06:48:38 +0000 | [diff] [blame] | 16 | #include "llvm/iTerminators.h" |
Chris Lattner | a92f696 | 2002-10-01 22:38:41 +0000 | [diff] [blame] | 17 | #include "Support/Statistic.h" |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 18 | #include <algorithm> |
| 19 | |
Chris Lattner | ce6ef11 | 2002-07-26 18:40:14 +0000 | [diff] [blame] | 20 | static Statistic<> |
Chris Lattner | a407ba1 | 2003-01-21 20:13:49 +0000 | [diff] [blame] | 21 | NumInstrs("bytecodewriter", "Number of instructions"); |
Chris Lattner | ce6ef11 | 2002-07-26 18:40:14 +0000 | [diff] [blame] | 22 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 23 | typedef unsigned char uchar; |
| 24 | |
| 25 | // outputInstructionFormat0 - Output those wierd instructions that have a large |
| 26 | // number of operands or have large operands themselves... |
| 27 | // |
| 28 | // Format: [opcode] [type] [numargs] [arg0] [arg1] ... [arg<numargs-1>] |
| 29 | // |
| 30 | static void outputInstructionFormat0(const Instruction *I, |
| 31 | const SlotCalculator &Table, |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 32 | unsigned Type, std::deque<uchar> &Out) { |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 33 | // Opcode must have top two bits clear... |
Chris Lattner | 2b9f600 | 2001-10-23 03:21:10 +0000 | [diff] [blame] | 34 | output_vbr(I->getOpcode() << 2, Out); // Instruction Opcode ID |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 35 | output_vbr(Type, Out); // Result type |
| 36 | |
Chris Lattner | c8b25d4 | 2001-07-07 08:36:50 +0000 | [diff] [blame] | 37 | unsigned NumArgs = I->getNumOperands(); |
Chris Lattner | 8f77dae | 2003-05-08 02:44:12 +0000 | [diff] [blame^] | 38 | output_vbr(NumArgs + (isa<CastInst>(I) || isa<VarArgInst>(I)), Out); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 39 | |
Chris Lattner | c8b25d4 | 2001-07-07 08:36:50 +0000 | [diff] [blame] | 40 | for (unsigned i = 0; i < NumArgs; ++i) { |
Chris Lattner | e5a57ee | 2001-07-25 22:47:55 +0000 | [diff] [blame] | 41 | int Slot = Table.getValSlot(I->getOperand(i)); |
| 42 | assert(Slot >= 0 && "No slot number for value!?!?"); |
| 43 | output_vbr((unsigned)Slot, Out); |
| 44 | } |
Chris Lattner | 5ab1f87 | 2001-10-21 00:14:44 +0000 | [diff] [blame] | 45 | |
Chris Lattner | 8f77dae | 2003-05-08 02:44:12 +0000 | [diff] [blame^] | 46 | if (isa<CastInst>(I) || isa<VarArgInst>(I)) { |
Chris Lattner | 5ab1f87 | 2001-10-21 00:14:44 +0000 | [diff] [blame] | 47 | int Slot = Table.getValSlot(I->getType()); |
Chris Lattner | 8f77dae | 2003-05-08 02:44:12 +0000 | [diff] [blame^] | 48 | assert(Slot != -1 && "Cast/VarArg return type unknown?"); |
Chris Lattner | 5ab1f87 | 2001-10-21 00:14:44 +0000 | [diff] [blame] | 49 | output_vbr((unsigned)Slot, Out); |
| 50 | } |
| 51 | |
Chris Lattner | e5a57ee | 2001-07-25 22:47:55 +0000 | [diff] [blame] | 52 | align32(Out); // We must maintain correct alignment! |
| 53 | } |
| 54 | |
| 55 | |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 56 | // outputInstrVarArgsCall - Output the obsurdly annoying varargs function calls. |
Chris Lattner | e5a57ee | 2001-07-25 22:47:55 +0000 | [diff] [blame] | 57 | // This are more annoying than most because the signature of the call does not |
| 58 | // tell us anything about the types of the arguments in the varargs portion. |
| 59 | // Because of this, we encode (as type 0) all of the argument types explicitly |
| 60 | // before the argument value. This really sucks, but you shouldn't be using |
| 61 | // varargs functions in your code! *death to printf*! |
| 62 | // |
| 63 | // Format: [opcode] [type] [numargs] [arg0] [arg1] ... [arg<numargs-1>] |
| 64 | // |
| 65 | static void outputInstrVarArgsCall(const Instruction *I, |
| 66 | const SlotCalculator &Table, unsigned Type, |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 67 | std::deque<uchar> &Out) { |
Chris Lattner | 1b98c5c | 2001-10-13 06:48:38 +0000 | [diff] [blame] | 68 | assert(isa<CallInst>(I) || isa<InvokeInst>(I)); |
Chris Lattner | e5a57ee | 2001-07-25 22:47:55 +0000 | [diff] [blame] | 69 | // Opcode must have top two bits clear... |
Chris Lattner | 2b9f600 | 2001-10-23 03:21:10 +0000 | [diff] [blame] | 70 | output_vbr(I->getOpcode() << 2, Out); // Instruction Opcode ID |
Chris Lattner | e5a57ee | 2001-07-25 22:47:55 +0000 | [diff] [blame] | 71 | output_vbr(Type, Out); // Result type (varargs type) |
| 72 | |
| 73 | unsigned NumArgs = I->getNumOperands(); |
Chris Lattner | 1b98c5c | 2001-10-13 06:48:38 +0000 | [diff] [blame] | 74 | output_vbr(NumArgs*2, Out); |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 75 | // TODO: Don't need to emit types for the fixed types of the varargs function |
Chris Lattner | 1b98c5c | 2001-10-13 06:48:38 +0000 | [diff] [blame] | 76 | // prototype... |
Chris Lattner | e5a57ee | 2001-07-25 22:47:55 +0000 | [diff] [blame] | 77 | |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 78 | // The type for the function has already been emitted in the type field of the |
Chris Lattner | 1b98c5c | 2001-10-13 06:48:38 +0000 | [diff] [blame] | 79 | // instruction. Just emit the slot # now. |
Chris Lattner | e5a57ee | 2001-07-25 22:47:55 +0000 | [diff] [blame] | 80 | int Slot = Table.getValSlot(I->getOperand(0)); |
| 81 | assert(Slot >= 0 && "No slot number for value!?!?"); |
| 82 | output_vbr((unsigned)Slot, Out); |
| 83 | |
Chris Lattner | 1b98c5c | 2001-10-13 06:48:38 +0000 | [diff] [blame] | 84 | // Output a dummy field to fill Arg#2 in the reader that is currently unused |
| 85 | // for varargs calls. This is a gross hack to make the code simpler, but we |
| 86 | // aren't really doing very small bytecode for varargs calls anyways. |
| 87 | // FIXME in the future: Smaller bytecode for varargs calls |
| 88 | output_vbr(0, Out); |
Chris Lattner | e5a57ee | 2001-07-25 22:47:55 +0000 | [diff] [blame] | 89 | |
Chris Lattner | 1b98c5c | 2001-10-13 06:48:38 +0000 | [diff] [blame] | 90 | for (unsigned i = 1; i < NumArgs; ++i) { |
Chris Lattner | e5a57ee | 2001-07-25 22:47:55 +0000 | [diff] [blame] | 91 | // Output Arg Type ID |
| 92 | Slot = Table.getValSlot(I->getOperand(i)->getType()); |
| 93 | assert(Slot >= 0 && "No slot number for value!?!?"); |
| 94 | output_vbr((unsigned)Slot, Out); |
| 95 | |
| 96 | // Output arg ID itself |
| 97 | Slot = Table.getValSlot(I->getOperand(i)); |
Chris Lattner | c8b25d4 | 2001-07-07 08:36:50 +0000 | [diff] [blame] | 98 | assert(Slot >= 0 && "No slot number for value!?!?"); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 99 | output_vbr((unsigned)Slot, Out); |
| 100 | } |
| 101 | align32(Out); // We must maintain correct alignment! |
| 102 | } |
| 103 | |
| 104 | |
| 105 | // outputInstructionFormat1 - Output one operand instructions, knowing that no |
| 106 | // operand index is >= 2^12. |
| 107 | // |
| 108 | static void outputInstructionFormat1(const Instruction *I, |
| 109 | const SlotCalculator &Table, int *Slots, |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 110 | unsigned Type, std::deque<uchar> &Out) { |
Chris Lattner | 2b9f600 | 2001-10-23 03:21:10 +0000 | [diff] [blame] | 111 | unsigned Opcode = I->getOpcode(); // Instruction Opcode ID |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 112 | |
| 113 | // bits Instruction format: |
| 114 | // -------------------------- |
Chris Lattner | 2b9f600 | 2001-10-23 03:21:10 +0000 | [diff] [blame] | 115 | // 01-00: Opcode type, fixed to 1. |
| 116 | // 07-02: Opcode |
| 117 | // 19-08: Resulting type plane |
| 118 | // 31-20: Operand #1 (if set to (2^12-1), then zero operands) |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 119 | // |
Chris Lattner | 2b9f600 | 2001-10-23 03:21:10 +0000 | [diff] [blame] | 120 | unsigned Bits = 1 | (Opcode << 2) | (Type << 8) | (Slots[0] << 20); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 121 | // cerr << "1 " << IType << " " << Type << " " << Slots[0] << endl; |
Chris Lattner | 2b9f600 | 2001-10-23 03:21:10 +0000 | [diff] [blame] | 122 | output(Bits, Out); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | |
| 126 | // outputInstructionFormat2 - Output two operand instructions, knowing that no |
| 127 | // operand index is >= 2^8. |
| 128 | // |
| 129 | static void outputInstructionFormat2(const Instruction *I, |
| 130 | const SlotCalculator &Table, int *Slots, |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 131 | unsigned Type, std::deque<uchar> &Out) { |
Chris Lattner | 2b9f600 | 2001-10-23 03:21:10 +0000 | [diff] [blame] | 132 | unsigned Opcode = I->getOpcode(); // Instruction Opcode ID |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 133 | |
| 134 | // bits Instruction format: |
| 135 | // -------------------------- |
Chris Lattner | 2b9f600 | 2001-10-23 03:21:10 +0000 | [diff] [blame] | 136 | // 01-00: Opcode type, fixed to 2. |
| 137 | // 07-02: Opcode |
| 138 | // 15-08: Resulting type plane |
| 139 | // 23-16: Operand #1 |
| 140 | // 31-24: Operand #2 |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 141 | // |
Chris Lattner | 2b9f600 | 2001-10-23 03:21:10 +0000 | [diff] [blame] | 142 | unsigned Bits = 2 | (Opcode << 2) | (Type << 8) | |
| 143 | (Slots[0] << 16) | (Slots[1] << 24); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 144 | // cerr << "2 " << IType << " " << Type << " " << Slots[0] << " " |
| 145 | // << Slots[1] << endl; |
Chris Lattner | 2b9f600 | 2001-10-23 03:21:10 +0000 | [diff] [blame] | 146 | output(Bits, Out); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | |
| 150 | // outputInstructionFormat3 - Output three operand instructions, knowing that no |
| 151 | // operand index is >= 2^6. |
| 152 | // |
| 153 | static void outputInstructionFormat3(const Instruction *I, |
| 154 | const SlotCalculator &Table, int *Slots, |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 155 | unsigned Type, std::deque<uchar> &Out) { |
Chris Lattner | 2b9f600 | 2001-10-23 03:21:10 +0000 | [diff] [blame] | 156 | unsigned Opcode = I->getOpcode(); // Instruction Opcode ID |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 157 | |
| 158 | // bits Instruction format: |
| 159 | // -------------------------- |
Chris Lattner | 2b9f600 | 2001-10-23 03:21:10 +0000 | [diff] [blame] | 160 | // 01-00: Opcode type, fixed to 3. |
| 161 | // 07-02: Opcode |
| 162 | // 13-08: Resulting type plane |
| 163 | // 19-14: Operand #1 |
| 164 | // 25-20: Operand #2 |
| 165 | // 31-26: Operand #3 |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 166 | // |
Chris Lattner | 2b9f600 | 2001-10-23 03:21:10 +0000 | [diff] [blame] | 167 | unsigned Bits = 3 | (Opcode << 2) | (Type << 8) | |
| 168 | (Slots[0] << 14) | (Slots[1] << 20) | (Slots[2] << 26); |
Chris Lattner | c8b25d4 | 2001-07-07 08:36:50 +0000 | [diff] [blame] | 169 | //cerr << "3 " << IType << " " << Type << " " << Slots[0] << " " |
| 170 | // << Slots[1] << " " << Slots[2] << endl; |
Chris Lattner | 2b9f600 | 2001-10-23 03:21:10 +0000 | [diff] [blame] | 171 | output(Bits, Out); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 172 | } |
| 173 | |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 174 | void BytecodeWriter::processInstruction(const Instruction &I) { |
| 175 | assert(I.getOpcode() < 64 && "Opcode too big???"); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 176 | |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 177 | unsigned NumOperands = I.getNumOperands(); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 178 | int MaxOpSlot = 0; |
Chris Lattner | c8b25d4 | 2001-07-07 08:36:50 +0000 | [diff] [blame] | 179 | int Slots[3]; Slots[0] = (1 << 12)-1; // Marker to signify 0 operands |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 180 | |
Chris Lattner | c8b25d4 | 2001-07-07 08:36:50 +0000 | [diff] [blame] | 181 | for (unsigned i = 0; i < NumOperands; ++i) { |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 182 | const Value *Def = I.getOperand(i); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 183 | int slot = Table.getValSlot(Def); |
| 184 | assert(slot != -1 && "Broken bytecode!"); |
| 185 | if (slot > MaxOpSlot) MaxOpSlot = slot; |
Chris Lattner | c8b25d4 | 2001-07-07 08:36:50 +0000 | [diff] [blame] | 186 | if (i < 3) Slots[i] = slot; |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | // Figure out which type to encode with the instruction. Typically we want |
| 190 | // the type of the first parameter, as opposed to the type of the instruction |
| 191 | // (for example, with setcc, we always know it returns bool, but the type of |
| 192 | // the first param is actually interesting). But if we have no arguments |
| 193 | // we take the type of the instruction itself. |
| 194 | // |
Chris Lattner | ab5ac6b | 2001-07-08 23:22:50 +0000 | [diff] [blame] | 195 | const Type *Ty; |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 196 | switch (I.getOpcode()) { |
Chris Lattner | ab5ac6b | 2001-07-08 23:22:50 +0000 | [diff] [blame] | 197 | case Instruction::Malloc: |
| 198 | case Instruction::Alloca: |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 199 | Ty = I.getType(); // Malloc & Alloca ALWAYS want to encode the return type |
Chris Lattner | ab5ac6b | 2001-07-08 23:22:50 +0000 | [diff] [blame] | 200 | break; |
| 201 | case Instruction::Store: |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 202 | Ty = I.getOperand(1)->getType(); // Encode the pointer type... |
Chris Lattner | 9b62503 | 2002-05-06 16:15:30 +0000 | [diff] [blame] | 203 | assert(isa<PointerType>(Ty) && "Store to nonpointer type!?!?"); |
Chris Lattner | ab5ac6b | 2001-07-08 23:22:50 +0000 | [diff] [blame] | 204 | break; |
| 205 | default: // Otherwise use the default behavior... |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 206 | Ty = NumOperands ? I.getOperand(0)->getType() : I.getType(); |
Chris Lattner | ab5ac6b | 2001-07-08 23:22:50 +0000 | [diff] [blame] | 207 | break; |
| 208 | } |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 209 | |
| 210 | unsigned Type; |
| 211 | int Slot = Table.getValSlot(Ty); |
| 212 | assert(Slot != -1 && "Type not available!!?!"); |
| 213 | Type = (unsigned)Slot; |
| 214 | |
Chris Lattner | 7c50147 | 2001-07-28 17:51:21 +0000 | [diff] [blame] | 215 | // Make sure that we take the type number into consideration. We don't want |
| 216 | // to overflow the field size for the instruction format we select. |
| 217 | // |
| 218 | if (Slot > MaxOpSlot) MaxOpSlot = Slot; |
| 219 | |
Chris Lattner | 0908309 | 2001-07-08 04:57:15 +0000 | [diff] [blame] | 220 | // Handle the special case for cast... |
Chris Lattner | 8f77dae | 2003-05-08 02:44:12 +0000 | [diff] [blame^] | 221 | if (isa<CastInst>(I) || isa<VarArgInst>(I)) { |
Chris Lattner | 0908309 | 2001-07-08 04:57:15 +0000 | [diff] [blame] | 222 | // Cast has to encode the destination type as the second argument in the |
| 223 | // packet, or else we won't know what type to cast to! |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 224 | Slots[1] = Table.getValSlot(I.getType()); |
Chris Lattner | 0908309 | 2001-07-08 04:57:15 +0000 | [diff] [blame] | 225 | assert(Slots[1] != -1 && "Cast return type unknown?"); |
| 226 | if (Slots[1] > MaxOpSlot) MaxOpSlot = Slots[1]; |
| 227 | NumOperands++; |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 228 | } else if (const CallInst *CI = dyn_cast<CallInst>(&I)){// Handle VarArg calls |
Chris Lattner | 9fcccb0 | 2002-06-05 17:49:40 +0000 | [diff] [blame] | 229 | const PointerType *Ty = cast<PointerType>(CI->getCalledValue()->getType()); |
Chris Lattner | 2aac6bf | 2002-04-04 22:19:18 +0000 | [diff] [blame] | 230 | if (cast<FunctionType>(Ty->getElementType())->isVarArg()) { |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 231 | outputInstrVarArgsCall(CI, Table, Type, Out); |
Chris Lattner | 1b98c5c | 2001-10-13 06:48:38 +0000 | [diff] [blame] | 232 | return; |
| 233 | } |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 234 | } else if (const InvokeInst *II = dyn_cast<InvokeInst>(&I)) {// ... & Invokes |
Chris Lattner | 9fcccb0 | 2002-06-05 17:49:40 +0000 | [diff] [blame] | 235 | const PointerType *Ty = cast<PointerType>(II->getCalledValue()->getType()); |
Chris Lattner | 2aac6bf | 2002-04-04 22:19:18 +0000 | [diff] [blame] | 236 | if (cast<FunctionType>(Ty->getElementType())->isVarArg()) { |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 237 | outputInstrVarArgsCall(II, Table, Type, Out); |
Chris Lattner | ef9c23f | 2001-10-03 14:53:21 +0000 | [diff] [blame] | 238 | return; |
| 239 | } |
Chris Lattner | 0908309 | 2001-07-08 04:57:15 +0000 | [diff] [blame] | 240 | } |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 241 | |
Chris Lattner | a407ba1 | 2003-01-21 20:13:49 +0000 | [diff] [blame] | 242 | ++NumInstrs; |
| 243 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 244 | // Decide which instruction encoding to use. This is determined primarily by |
| 245 | // the number of operands, and secondarily by whether or not the max operand |
| 246 | // will fit into the instruction encoding. More operands == fewer bits per |
| 247 | // operand. |
| 248 | // |
| 249 | switch (NumOperands) { |
| 250 | case 0: |
| 251 | case 1: |
| 252 | if (MaxOpSlot < (1 << 12)-1) { // -1 because we use 4095 to indicate 0 ops |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 253 | outputInstructionFormat1(&I, Table, Slots, Type, Out); |
Chris Lattner | e8fdde1 | 2001-09-07 16:39:41 +0000 | [diff] [blame] | 254 | return; |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 255 | } |
| 256 | break; |
| 257 | |
| 258 | case 2: |
| 259 | if (MaxOpSlot < (1 << 8)) { |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 260 | outputInstructionFormat2(&I, Table, Slots, Type, Out); |
Chris Lattner | e8fdde1 | 2001-09-07 16:39:41 +0000 | [diff] [blame] | 261 | return; |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 262 | } |
| 263 | break; |
| 264 | |
| 265 | case 3: |
| 266 | if (MaxOpSlot < (1 << 6)) { |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 267 | outputInstructionFormat3(&I, Table, Slots, Type, Out); |
Chris Lattner | e8fdde1 | 2001-09-07 16:39:41 +0000 | [diff] [blame] | 268 | return; |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 269 | } |
| 270 | break; |
| 271 | } |
| 272 | |
Chris Lattner | ab5ac6b | 2001-07-08 23:22:50 +0000 | [diff] [blame] | 273 | // If we weren't handled before here, we either have a large number of |
| 274 | // operands or a large operand index that we are refering to. |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 275 | outputInstructionFormat0(&I, Table, Type, Out); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 276 | } |