Chris Lattner | 035dfbe | 2002-08-09 20:08:06 +0000 | [diff] [blame] | 1 | //===-- MachineInstr.cpp --------------------------------------------------===// |
Vikram S. Adve | 70bc4b5 | 2001-07-21 12:41:50 +0000 | [diff] [blame] | 2 | // |
Chris Lattner | 035dfbe | 2002-08-09 20:08:06 +0000 | [diff] [blame] | 3 | //===----------------------------------------------------------------------===// |
Vikram S. Adve | 70bc4b5 | 2001-07-21 12:41:50 +0000 | [diff] [blame] | 4 | |
Chris Lattner | 822b4fb | 2001-09-07 17:18:30 +0000 | [diff] [blame] | 5 | #include "llvm/CodeGen/MachineInstr.h" |
Chris Lattner | ddd7fcb | 2002-10-29 23:19:00 +0000 | [diff] [blame] | 6 | #include "llvm/CodeGen/MachineBasicBlock.h" |
Chris Lattner | 3801f6d | 2002-02-03 07:46:01 +0000 | [diff] [blame] | 7 | #include "llvm/Value.h" |
Chris Lattner | 0be79c6 | 2002-10-28 02:28:39 +0000 | [diff] [blame] | 8 | #include "llvm/Target/MachineInstrInfo.h" // FIXME: shouldn't need this! |
Chris Lattner | 1049164 | 2002-10-30 00:48:05 +0000 | [diff] [blame^] | 9 | #include "llvm/Target/TargetMachine.h" |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 10 | using std::cerr; |
Vikram S. Adve | 5b79591 | 2001-08-28 23:02:39 +0000 | [diff] [blame] | 11 | |
Chris Lattner | f1757c4 | 2002-10-29 17:40:30 +0000 | [diff] [blame] | 12 | // Global variable holding an array of descriptors for machine instructions. |
| 13 | // The actual object needs to be created separately for each target machine. |
| 14 | // This variable is initialized and reset by class MachineInstrInfo. |
| 15 | // |
| 16 | // FIXME: This should be a property of the target so that more than one target |
| 17 | // at a time can be active... |
| 18 | // |
| 19 | extern const MachineInstrDescriptor *TargetInstrDescriptors; |
Ruchira Sasanka | 69917e2 | 2001-10-18 22:40:02 +0000 | [diff] [blame] | 20 | |
Vikram S. Adve | 1885da4 | 2001-07-31 21:49:28 +0000 | [diff] [blame] | 21 | // Constructor for instructions with fixed #operands (nearly all) |
Chris Lattner | 7279122 | 2002-10-28 20:59:49 +0000 | [diff] [blame] | 22 | MachineInstr::MachineInstr(MachineOpCode _opCode) |
Chris Lattner | 9a8e412 | 2002-10-28 21:17:20 +0000 | [diff] [blame] | 23 | : opCode(_opCode), |
Vikram S. Adve | a2bae30 | 2002-10-29 19:41:18 +0000 | [diff] [blame] | 24 | operands(TargetInstrDescriptors[_opCode].numOperands, MachineOperand()), |
| 25 | numImplicitRefs(0) |
| 26 | { |
Vikram S. Adve | 1885da4 | 2001-07-31 21:49:28 +0000 | [diff] [blame] | 27 | assert(TargetInstrDescriptors[_opCode].numOperands >= 0); |
| 28 | } |
| 29 | |
| 30 | // Constructor for instructions with variable #operands |
Chris Lattner | b98a53f | 2002-10-28 21:02:40 +0000 | [diff] [blame] | 31 | MachineInstr::MachineInstr(MachineOpCode OpCode, unsigned numOperands) |
Vikram S. Adve | a2bae30 | 2002-10-29 19:41:18 +0000 | [diff] [blame] | 32 | : opCode(OpCode), |
| 33 | operands(numOperands, MachineOperand()), |
| 34 | numImplicitRefs(0) |
| 35 | { |
Vikram S. Adve | 70bc4b5 | 2001-07-21 12:41:50 +0000 | [diff] [blame] | 36 | } |
| 37 | |
Chris Lattner | ddd7fcb | 2002-10-29 23:19:00 +0000 | [diff] [blame] | 38 | /// MachineInstr ctor - This constructor only does a _reserve_ of the operands, |
| 39 | /// not a resize for them. It is expected that if you use this that you call |
| 40 | /// add* methods below to fill up the operands, instead of the Set methods. |
| 41 | /// Eventually, the "resizing" ctors will be phased out. |
| 42 | /// |
Chris Lattner | 7279122 | 2002-10-28 20:59:49 +0000 | [diff] [blame] | 43 | MachineInstr::MachineInstr(MachineOpCode Opcode, unsigned numOperands, |
Vikram S. Adve | a2bae30 | 2002-10-29 19:41:18 +0000 | [diff] [blame] | 44 | bool XX, bool YY) |
| 45 | : opCode(Opcode), |
| 46 | numImplicitRefs(0) |
| 47 | { |
Chris Lattner | 7279122 | 2002-10-28 20:59:49 +0000 | [diff] [blame] | 48 | operands.reserve(numOperands); |
| 49 | } |
| 50 | |
Chris Lattner | ddd7fcb | 2002-10-29 23:19:00 +0000 | [diff] [blame] | 51 | /// MachineInstr ctor - Work exactly the same as the ctor above, except that the |
| 52 | /// MachineInstr is created and added to the end of the specified basic block. |
| 53 | /// |
| 54 | MachineInstr::MachineInstr(MachineBasicBlock *MBB, MachineOpCode Opcode, |
| 55 | unsigned numOperands) |
| 56 | : opCode(Opcode), |
| 57 | numImplicitRefs(0) |
| 58 | { |
| 59 | assert(MBB && "Cannot use inserting ctor with null basic block!"); |
| 60 | operands.reserve(numOperands); |
| 61 | MBB->push_back(this); // Add instruction to end of basic block! |
| 62 | } |
| 63 | |
| 64 | |
Chris Lattner | 413746e | 2002-10-28 20:48:39 +0000 | [diff] [blame] | 65 | // OperandComplete - Return true if it's illegal to add a new operand |
Vikram S. Adve | a2bae30 | 2002-10-29 19:41:18 +0000 | [diff] [blame] | 66 | bool MachineInstr::OperandsComplete() const |
| 67 | { |
Chris Lattner | 413746e | 2002-10-28 20:48:39 +0000 | [diff] [blame] | 68 | int NumOperands = TargetInstrDescriptors[opCode].numOperands; |
Vikram S. Adve | a2bae30 | 2002-10-29 19:41:18 +0000 | [diff] [blame] | 69 | if (NumOperands >= 0 && getNumOperands() >= (unsigned)NumOperands) |
Chris Lattner | 413746e | 2002-10-28 20:48:39 +0000 | [diff] [blame] | 70 | return true; // Broken! |
| 71 | return false; |
| 72 | } |
| 73 | |
| 74 | |
Vikram S. Adve | e8b57ef | 2002-09-20 00:47:49 +0000 | [diff] [blame] | 75 | // |
| 76 | // Support for replacing opcode and operands of a MachineInstr in place. |
| 77 | // This only resets the size of the operand vector and initializes it. |
| 78 | // The new operands must be set explicitly later. |
| 79 | // |
Vikram S. Adve | a2bae30 | 2002-10-29 19:41:18 +0000 | [diff] [blame] | 80 | void MachineInstr::replace(MachineOpCode Opcode, unsigned numOperands) |
| 81 | { |
| 82 | assert(getNumImplicitRefs() == 0 && |
| 83 | "This is probably broken because implicit refs are going to be lost."); |
Chris Lattner | 413746e | 2002-10-28 20:48:39 +0000 | [diff] [blame] | 84 | opCode = Opcode; |
Vikram S. Adve | e8b57ef | 2002-09-20 00:47:49 +0000 | [diff] [blame] | 85 | operands.clear(); |
Chris Lattner | 413746e | 2002-10-28 20:48:39 +0000 | [diff] [blame] | 86 | operands.resize(numOperands, MachineOperand()); |
Vikram S. Adve | e8b57ef | 2002-09-20 00:47:49 +0000 | [diff] [blame] | 87 | } |
| 88 | |
Vikram S. Adve | 70bc4b5 | 2001-07-21 12:41:50 +0000 | [diff] [blame] | 89 | void |
Chris Lattner | 413746e | 2002-10-28 20:48:39 +0000 | [diff] [blame] | 90 | MachineInstr::SetMachineOperandVal(unsigned i, |
Vikram S. Adve | 7a4be95 | 2002-07-08 22:38:45 +0000 | [diff] [blame] | 91 | MachineOperand::MachineOperandType opType, |
Chris Lattner | 572f5c8 | 2002-10-28 04:24:49 +0000 | [diff] [blame] | 92 | Value* V, |
Chris Lattner | 0c0edf8 | 2002-07-25 06:17:51 +0000 | [diff] [blame] | 93 | bool isdef, |
| 94 | bool isDefAndUse) |
Vikram S. Adve | 70bc4b5 | 2001-07-21 12:41:50 +0000 | [diff] [blame] | 95 | { |
Vikram S. Adve | a2bae30 | 2002-10-29 19:41:18 +0000 | [diff] [blame] | 96 | assert(i < operands.size()); // may be explicit or implicit op |
Chris Lattner | 572f5c8 | 2002-10-28 04:24:49 +0000 | [diff] [blame] | 97 | operands[i].opType = opType; |
| 98 | operands[i].value = V; |
| 99 | operands[i].regNum = -1; |
| 100 | operands[i].flags = 0; |
| 101 | |
Vikram S. Adve | 3bc9ef9 | 2002-07-10 21:45:04 +0000 | [diff] [blame] | 102 | if (isdef || TargetInstrDescriptors[opCode].resultPos == (int) i) |
| 103 | operands[i].markDef(); |
| 104 | if (isDefAndUse) |
| 105 | operands[i].markDefAndUse(); |
Vikram S. Adve | 70bc4b5 | 2001-07-21 12:41:50 +0000 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | void |
Chris Lattner | 572f5c8 | 2002-10-28 04:24:49 +0000 | [diff] [blame] | 109 | MachineInstr::SetMachineOperandConst(unsigned i, |
Vikram S. Adve | 70bc4b5 | 2001-07-21 12:41:50 +0000 | [diff] [blame] | 110 | MachineOperand::MachineOperandType operandType, |
Vikram S. Adve | c356e56 | 2002-03-18 03:35:24 +0000 | [diff] [blame] | 111 | int64_t intValue) |
Vikram S. Adve | 70bc4b5 | 2001-07-21 12:41:50 +0000 | [diff] [blame] | 112 | { |
Vikram S. Adve | a2bae30 | 2002-10-29 19:41:18 +0000 | [diff] [blame] | 113 | assert(i < getNumOperands()); // must be explicit op |
Vikram S. Adve | c356e56 | 2002-03-18 03:35:24 +0000 | [diff] [blame] | 114 | assert(TargetInstrDescriptors[opCode].resultPos != (int) i && |
| 115 | "immed. constant cannot be defined"); |
Chris Lattner | 572f5c8 | 2002-10-28 04:24:49 +0000 | [diff] [blame] | 116 | |
| 117 | operands[i].opType = operandType; |
| 118 | operands[i].value = NULL; |
| 119 | operands[i].immedVal = intValue; |
| 120 | operands[i].regNum = -1; |
| 121 | operands[i].flags = 0; |
Vikram S. Adve | 70bc4b5 | 2001-07-21 12:41:50 +0000 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | void |
Chris Lattner | 572f5c8 | 2002-10-28 04:24:49 +0000 | [diff] [blame] | 125 | MachineInstr::SetMachineOperandReg(unsigned i, |
Vikram S. Adve | c356e56 | 2002-03-18 03:35:24 +0000 | [diff] [blame] | 126 | int regNum, |
Chris Lattner | 2f30598 | 2002-10-28 19:46:59 +0000 | [diff] [blame] | 127 | bool isdef) { |
Vikram S. Adve | a2bae30 | 2002-10-29 19:41:18 +0000 | [diff] [blame] | 128 | assert(i < getNumOperands()); // must be explicit op |
Chris Lattner | 572f5c8 | 2002-10-28 04:24:49 +0000 | [diff] [blame] | 129 | |
Chris Lattner | 2f30598 | 2002-10-28 19:46:59 +0000 | [diff] [blame] | 130 | operands[i].opType = MachineOperand::MO_MachineRegister; |
Chris Lattner | 572f5c8 | 2002-10-28 04:24:49 +0000 | [diff] [blame] | 131 | operands[i].value = NULL; |
| 132 | operands[i].regNum = regNum; |
| 133 | operands[i].flags = 0; |
| 134 | |
Vikram S. Adve | 3bc9ef9 | 2002-07-10 21:45:04 +0000 | [diff] [blame] | 135 | if (isdef || TargetInstrDescriptors[opCode].resultPos == (int) i) |
| 136 | operands[i].markDef(); |
Chris Lattner | 27a0893 | 2002-10-22 23:16:21 +0000 | [diff] [blame] | 137 | insertUsedReg(regNum); |
Vikram S. Adve | 70bc4b5 | 2001-07-21 12:41:50 +0000 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | void |
Vikram S. Adve | 7a4be95 | 2002-07-08 22:38:45 +0000 | [diff] [blame] | 141 | MachineInstr::SetRegForOperand(unsigned i, int regNum) |
Vikram S. Adve | 70bc4b5 | 2001-07-21 12:41:50 +0000 | [diff] [blame] | 142 | { |
Vikram S. Adve | a2bae30 | 2002-10-29 19:41:18 +0000 | [diff] [blame] | 143 | assert(i < getNumOperands()); // must be explicit op |
Vikram S. Adve | 7a4be95 | 2002-07-08 22:38:45 +0000 | [diff] [blame] | 144 | operands[i].setRegForValue(regNum); |
Chris Lattner | 27a0893 | 2002-10-22 23:16:21 +0000 | [diff] [blame] | 145 | insertUsedReg(regNum); |
Vikram S. Adve | 7a4be95 | 2002-07-08 22:38:45 +0000 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | |
Vikram S. Adve | e2a78e3 | 2002-08-14 16:52:58 +0000 | [diff] [blame] | 149 | // Subsitute all occurrences of Value* oldVal with newVal in all operands |
| 150 | // and all implicit refs. If defsOnly == true, substitute defs only. |
| 151 | unsigned |
| 152 | MachineInstr::substituteValue(const Value* oldVal, Value* newVal, bool defsOnly) |
| 153 | { |
| 154 | unsigned numSubst = 0; |
| 155 | |
| 156 | // Subsitute operands |
| 157 | for (MachineInstr::val_op_iterator O = begin(), E = end(); O != E; ++O) |
| 158 | if (*O == oldVal) |
| 159 | if (!defsOnly || O.isDef()) |
| 160 | { |
| 161 | O.getMachineOperand().value = newVal; |
| 162 | ++numSubst; |
| 163 | } |
| 164 | |
| 165 | // Subsitute implicit refs |
Vikram S. Adve | a2bae30 | 2002-10-29 19:41:18 +0000 | [diff] [blame] | 166 | for (unsigned i=0, N=getNumImplicitRefs(); i < N; ++i) |
Chris Lattner | 27a0893 | 2002-10-22 23:16:21 +0000 | [diff] [blame] | 167 | if (getImplicitRef(i) == oldVal) |
Vikram S. Adve | e2a78e3 | 2002-08-14 16:52:58 +0000 | [diff] [blame] | 168 | if (!defsOnly || implicitRefIsDefined(i)) |
| 169 | { |
Vikram S. Adve | a2bae30 | 2002-10-29 19:41:18 +0000 | [diff] [blame] | 170 | getImplicitOp(i).value = newVal; |
Vikram S. Adve | e2a78e3 | 2002-08-14 16:52:58 +0000 | [diff] [blame] | 171 | ++numSubst; |
| 172 | } |
| 173 | |
| 174 | return numSubst; |
| 175 | } |
| 176 | |
| 177 | |
Vikram S. Adve | 7a4be95 | 2002-07-08 22:38:45 +0000 | [diff] [blame] | 178 | void |
| 179 | MachineInstr::dump() const |
| 180 | { |
| 181 | cerr << " " << *this; |
Vikram S. Adve | 70bc4b5 | 2001-07-21 12:41:50 +0000 | [diff] [blame] | 182 | } |
| 183 | |
Vikram S. Adve | 8c6936a | 2002-09-16 15:18:53 +0000 | [diff] [blame] | 184 | static inline std::ostream& |
| 185 | OutputValue(std::ostream &os, const Value* val) |
Vikram S. Adve | 93240fe | 2002-04-25 04:31:18 +0000 | [diff] [blame] | 186 | { |
| 187 | os << "(val "; |
| 188 | if (val && val->hasName()) |
Vikram S. Adve | 3bc9ef9 | 2002-07-10 21:45:04 +0000 | [diff] [blame] | 189 | return os << val->getName() << ")"; |
Vikram S. Adve | 93240fe | 2002-04-25 04:31:18 +0000 | [diff] [blame] | 190 | else |
Vikram S. Adve | 3bc9ef9 | 2002-07-10 21:45:04 +0000 | [diff] [blame] | 191 | return os << (void*) val << ")"; // print address only |
Vikram S. Adve | 93240fe | 2002-04-25 04:31:18 +0000 | [diff] [blame] | 192 | } |
| 193 | |
Vikram S. Adve | 8c6936a | 2002-09-16 15:18:53 +0000 | [diff] [blame] | 194 | static inline std::ostream& |
| 195 | OutputReg(std::ostream &os, unsigned int regNum) |
| 196 | { |
| 197 | return os << "%mreg(" << regNum << ")"; |
| 198 | } |
| 199 | |
Chris Lattner | 1049164 | 2002-10-30 00:48:05 +0000 | [diff] [blame^] | 200 | static void print(const MachineOperand &MO, std::ostream &OS, |
| 201 | const TargetMachine &TM) { |
| 202 | bool CloseParen = true; |
| 203 | if (MO.opHiBits32()) |
| 204 | OS << "%lm("; |
| 205 | else if (MO.opLoBits32()) |
| 206 | OS << "%lo("; |
| 207 | else if (MO.opHiBits64()) |
| 208 | OS << "%hh("; |
| 209 | else if (MO.opLoBits64()) |
| 210 | OS << "%hm("; |
| 211 | else |
| 212 | CloseParen = false; |
| 213 | |
| 214 | switch (MO.getType()) { |
| 215 | case MachineOperand::MO_VirtualRegister: |
| 216 | if (MO.getVRegValue()) { |
| 217 | OS << "%reg"; |
| 218 | OutputValue(OS, MO.getVRegValue()); |
| 219 | if (MO.hasAllocatedReg()) |
| 220 | OS << "=="; |
| 221 | } |
| 222 | if (MO.hasAllocatedReg()) |
| 223 | OutputReg(OS, MO.getAllocatedRegNum()); |
| 224 | break; |
| 225 | case MachineOperand::MO_CCRegister: |
| 226 | OS << "%ccreg"; |
| 227 | OutputValue(OS, MO.getVRegValue()); |
| 228 | if (MO.hasAllocatedReg()) { |
| 229 | OS << "=="; |
| 230 | OutputReg(OS, MO.getAllocatedRegNum()); |
| 231 | } |
| 232 | break; |
| 233 | case MachineOperand::MO_MachineRegister: |
| 234 | OutputReg(OS, MO.getMachineRegNum()); |
| 235 | break; |
| 236 | case MachineOperand::MO_SignExtendedImmed: |
| 237 | OS << (long)MO.getImmedValue(); |
| 238 | break; |
| 239 | case MachineOperand::MO_UnextendedImmed: |
| 240 | OS << (long)MO.getImmedValue(); |
| 241 | break; |
| 242 | case MachineOperand::MO_PCRelativeDisp: { |
| 243 | const Value* opVal = MO.getVRegValue(); |
| 244 | bool isLabel = isa<Function>(opVal) || isa<BasicBlock>(opVal); |
| 245 | OS << "%disp(" << (isLabel? "label " : "addr-of-val "); |
| 246 | if (opVal->hasName()) |
| 247 | OS << opVal->getName(); |
| 248 | else |
| 249 | OS << (const void*) opVal; |
| 250 | OS << ")"; |
| 251 | break; |
| 252 | } |
| 253 | default: |
| 254 | assert(0 && "Unrecognized operand type"); |
| 255 | } |
| 256 | |
| 257 | if (CloseParen) |
| 258 | OS << ")"; |
| 259 | } |
| 260 | |
| 261 | void MachineInstr::print(std::ostream &OS, const TargetMachine &TM) { |
| 262 | OS << TM.getInstrInfo().getName(getOpcode()); |
| 263 | for (unsigned i = 0, e = getNumOperands(); i != e; ++i) { |
| 264 | OS << "\t"; |
| 265 | ::print(getOperand(i), OS, TM); |
| 266 | |
| 267 | if (operandIsDefinedAndUsed(i)) |
| 268 | OS << "<def&use>"; |
| 269 | else if (operandIsDefined(i)) |
| 270 | OS << "<def>"; |
| 271 | } |
| 272 | |
| 273 | // code for printing implict references |
| 274 | if (getNumImplicitRefs()) { |
| 275 | OS << "\tImplicitRefs: "; |
| 276 | for(unsigned i = 0, e = getNumImplicitRefs(); i != e; ++i) { |
| 277 | OS << "\t"; |
| 278 | OutputValue(OS, getImplicitRef(i)); |
| 279 | if (implicitRefIsDefinedAndUsed(i)) |
| 280 | OS << "<def&use>"; |
| 281 | else if (implicitRefIsDefined(i)) |
| 282 | OS << "<def>"; |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | OS << "\n"; |
| 287 | } |
| 288 | |
| 289 | |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 290 | std::ostream &operator<<(std::ostream& os, const MachineInstr& minstr) |
Vikram S. Adve | 70bc4b5 | 2001-07-21 12:41:50 +0000 | [diff] [blame] | 291 | { |
Chris Lattner | d9512ca | 2002-10-29 17:35:39 +0000 | [diff] [blame] | 292 | os << TargetInstrDescriptors[minstr.opCode].Name; |
Vikram S. Adve | 70bc4b5 | 2001-07-21 12:41:50 +0000 | [diff] [blame] | 293 | |
Ruchira Sasanka | 8d24337 | 2001-11-14 20:05:23 +0000 | [diff] [blame] | 294 | for (unsigned i=0, N=minstr.getNumOperands(); i < N; i++) { |
Vikram S. Adve | 70bc4b5 | 2001-07-21 12:41:50 +0000 | [diff] [blame] | 295 | os << "\t" << minstr.getOperand(i); |
Vikram S. Adve | 7a4be95 | 2002-07-08 22:38:45 +0000 | [diff] [blame] | 296 | if( minstr.operandIsDefined(i) ) |
| 297 | os << "*"; |
| 298 | if( minstr.operandIsDefinedAndUsed(i) ) |
Ruchira Sasanka | 07c7086 | 2001-11-15 20:46:40 +0000 | [diff] [blame] | 299 | os << "*"; |
Ruchira Sasanka | 8d24337 | 2001-11-14 20:05:23 +0000 | [diff] [blame] | 300 | } |
Vikram S. Adve | 70bc4b5 | 2001-07-21 12:41:50 +0000 | [diff] [blame] | 301 | |
Ruchira Sasanka | 69917e2 | 2001-10-18 22:40:02 +0000 | [diff] [blame] | 302 | // code for printing implict references |
Ruchira Sasanka | 69917e2 | 2001-10-18 22:40:02 +0000 | [diff] [blame] | 303 | unsigned NumOfImpRefs = minstr.getNumImplicitRefs(); |
| 304 | if( NumOfImpRefs > 0 ) { |
Vikram S. Adve | 93240fe | 2002-04-25 04:31:18 +0000 | [diff] [blame] | 305 | os << "\tImplicit: "; |
Ruchira Sasanka | 69917e2 | 2001-10-18 22:40:02 +0000 | [diff] [blame] | 306 | for(unsigned z=0; z < NumOfImpRefs; z++) { |
Vikram S. Adve | 93240fe | 2002-04-25 04:31:18 +0000 | [diff] [blame] | 307 | OutputValue(os, minstr.getImplicitRef(z)); |
Ruchira Sasanka | 8d24337 | 2001-11-14 20:05:23 +0000 | [diff] [blame] | 308 | if( minstr.implicitRefIsDefined(z)) os << "*"; |
Vikram S. Adve | 7a4be95 | 2002-07-08 22:38:45 +0000 | [diff] [blame] | 309 | if( minstr.implicitRefIsDefinedAndUsed(z)) os << "*"; |
Ruchira Sasanka | 07c7086 | 2001-11-15 20:46:40 +0000 | [diff] [blame] | 310 | os << "\t"; |
Ruchira Sasanka | 69917e2 | 2001-10-18 22:40:02 +0000 | [diff] [blame] | 311 | } |
| 312 | } |
Vikram S. Adve | 93240fe | 2002-04-25 04:31:18 +0000 | [diff] [blame] | 313 | |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 314 | return os << "\n"; |
Vikram S. Adve | 70bc4b5 | 2001-07-21 12:41:50 +0000 | [diff] [blame] | 315 | } |
| 316 | |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 317 | std::ostream &operator<<(std::ostream &os, const MachineOperand &mop) |
Vikram S. Adve | 6e44718 | 2001-09-18 12:56:28 +0000 | [diff] [blame] | 318 | { |
Vikram S. Adve | 3bc9ef9 | 2002-07-10 21:45:04 +0000 | [diff] [blame] | 319 | if (mop.opHiBits32()) |
| 320 | os << "%lm("; |
| 321 | else if (mop.opLoBits32()) |
| 322 | os << "%lo("; |
| 323 | else if (mop.opHiBits64()) |
| 324 | os << "%hh("; |
| 325 | else if (mop.opLoBits64()) |
| 326 | os << "%hm("; |
| 327 | |
Chris Lattner | 1049164 | 2002-10-30 00:48:05 +0000 | [diff] [blame^] | 328 | switch (mop.getType()) |
Vikram S. Adve | 6e44718 | 2001-09-18 12:56:28 +0000 | [diff] [blame] | 329 | { |
| 330 | case MachineOperand::MO_VirtualRegister: |
Vikram S. Adve | 6e44718 | 2001-09-18 12:56:28 +0000 | [diff] [blame] | 331 | os << "%reg"; |
Vikram S. Adve | 3bc9ef9 | 2002-07-10 21:45:04 +0000 | [diff] [blame] | 332 | OutputValue(os, mop.getVRegValue()); |
Chris Lattner | 1049164 | 2002-10-30 00:48:05 +0000 | [diff] [blame^] | 333 | if (mop.hasAllocatedReg()) { |
| 334 | os << "=="; |
| 335 | OutputReg(os, mop.getAllocatedRegNum()); |
| 336 | } |
Vikram S. Adve | 3bc9ef9 | 2002-07-10 21:45:04 +0000 | [diff] [blame] | 337 | break; |
Vikram S. Adve | 6e44718 | 2001-09-18 12:56:28 +0000 | [diff] [blame] | 338 | case MachineOperand::MO_CCRegister: |
| 339 | os << "%ccreg"; |
Vikram S. Adve | 3bc9ef9 | 2002-07-10 21:45:04 +0000 | [diff] [blame] | 340 | OutputValue(os, mop.getVRegValue()); |
Chris Lattner | 1049164 | 2002-10-30 00:48:05 +0000 | [diff] [blame^] | 341 | if (mop.hasAllocatedReg()) { |
| 342 | os << "=="; |
| 343 | OutputReg(os, mop.getAllocatedRegNum()); |
| 344 | } |
Vikram S. Adve | 3bc9ef9 | 2002-07-10 21:45:04 +0000 | [diff] [blame] | 345 | break; |
| 346 | case MachineOperand::MO_MachineRegister: |
Vikram S. Adve | 8c6936a | 2002-09-16 15:18:53 +0000 | [diff] [blame] | 347 | OutputReg(os, mop.getMachineRegNum()); |
Vikram S. Adve | 3bc9ef9 | 2002-07-10 21:45:04 +0000 | [diff] [blame] | 348 | break; |
Vikram S. Adve | 6e44718 | 2001-09-18 12:56:28 +0000 | [diff] [blame] | 349 | case MachineOperand::MO_SignExtendedImmed: |
Chris Lattner | 1049164 | 2002-10-30 00:48:05 +0000 | [diff] [blame^] | 350 | os << (long)mop.getImmedValue(); |
Vikram S. Adve | 3bc9ef9 | 2002-07-10 21:45:04 +0000 | [diff] [blame] | 351 | break; |
Vikram S. Adve | 6e44718 | 2001-09-18 12:56:28 +0000 | [diff] [blame] | 352 | case MachineOperand::MO_UnextendedImmed: |
Chris Lattner | 1049164 | 2002-10-30 00:48:05 +0000 | [diff] [blame^] | 353 | os << (long)mop.getImmedValue(); |
Vikram S. Adve | 3bc9ef9 | 2002-07-10 21:45:04 +0000 | [diff] [blame] | 354 | break; |
Vikram S. Adve | 6e44718 | 2001-09-18 12:56:28 +0000 | [diff] [blame] | 355 | case MachineOperand::MO_PCRelativeDisp: |
Vikram S. Adve | e949da5 | 2001-09-30 23:44:19 +0000 | [diff] [blame] | 356 | { |
| 357 | const Value* opVal = mop.getVRegValue(); |
Chris Lattner | 4d669b5 | 2002-04-08 22:01:15 +0000 | [diff] [blame] | 358 | bool isLabel = isa<Function>(opVal) || isa<BasicBlock>(opVal); |
Vikram S. Adve | d9beb97 | 2001-11-12 14:19:47 +0000 | [diff] [blame] | 359 | os << "%disp(" << (isLabel? "label " : "addr-of-val "); |
| 360 | if (opVal->hasName()) |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 361 | os << opVal->getName(); |
Vikram S. Adve | d9beb97 | 2001-11-12 14:19:47 +0000 | [diff] [blame] | 362 | else |
Vikram S. Adve | 7a4be95 | 2002-07-08 22:38:45 +0000 | [diff] [blame] | 363 | os << (const void*) opVal; |
Vikram S. Adve | 3bc9ef9 | 2002-07-10 21:45:04 +0000 | [diff] [blame] | 364 | os << ")"; |
| 365 | break; |
Vikram S. Adve | e949da5 | 2001-09-30 23:44:19 +0000 | [diff] [blame] | 366 | } |
Vikram S. Adve | 6e44718 | 2001-09-18 12:56:28 +0000 | [diff] [blame] | 367 | default: |
| 368 | assert(0 && "Unrecognized operand type"); |
| 369 | break; |
| 370 | } |
Vikram S. Adve | 70bc4b5 | 2001-07-21 12:41:50 +0000 | [diff] [blame] | 371 | |
Vikram S. Adve | 3bc9ef9 | 2002-07-10 21:45:04 +0000 | [diff] [blame] | 372 | if (mop.flags & |
| 373 | (MachineOperand::HIFLAG32 | MachineOperand::LOFLAG32 | |
| 374 | MachineOperand::HIFLAG64 | MachineOperand::LOFLAG64)) |
| 375 | os << ")"; |
| 376 | |
Vikram S. Adve | 70bc4b5 | 2001-07-21 12:41:50 +0000 | [diff] [blame] | 377 | return os; |
| 378 | } |