Misha Brukman | a85d6bc | 2002-11-22 22:42:50 +0000 | [diff] [blame] | 1 | //===- X86InstrInfo.cpp - X86 Instruction Information -----------*- C++ -*-===// |
Chris Lattner | 7261408 | 2002-10-25 22:55:53 +0000 | [diff] [blame] | 2 | // |
Chris Lattner | 3501fea | 2003-01-14 22:00:31 +0000 | [diff] [blame] | 3 | // This file contains the X86 implementation of the TargetInstrInfo class. |
Chris Lattner | 7261408 | 2002-10-25 22:55:53 +0000 | [diff] [blame] | 4 | // |
| 5 | //===----------------------------------------------------------------------===// |
| 6 | |
Chris Lattner | 055c965 | 2002-10-29 21:05:24 +0000 | [diff] [blame] | 7 | #include "X86InstrInfo.h" |
Chris Lattner | 4ce42a7 | 2002-12-03 05:42:53 +0000 | [diff] [blame] | 8 | #include "X86.h" |
Misha Brukman | e9d8838 | 2003-05-24 00:09:50 +0000 | [diff] [blame] | 9 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Chris Lattner | 4ce42a7 | 2002-12-03 05:42:53 +0000 | [diff] [blame] | 10 | |
| 11 | #define I(ENUM, NAME, BASEOPCODE, FLAGS, TSFLAGS, IMPDEFS, IMPUSES) |
| 12 | #define IMPREGSLIST(NAME, ...) \ |
| 13 | static const unsigned NAME[] = { __VA_ARGS__ }; |
| 14 | #include "X86InstrInfo.def" |
| 15 | |
Chris Lattner | 7261408 | 2002-10-25 22:55:53 +0000 | [diff] [blame] | 16 | |
Chris Lattner | 055c965 | 2002-10-29 21:05:24 +0000 | [diff] [blame] | 17 | // X86Insts - Turn the InstrInfo.def file into a bunch of instruction |
Chris Lattner | 7261408 | 2002-10-25 22:55:53 +0000 | [diff] [blame] | 18 | // descriptors |
| 19 | // |
Chris Lattner | 3501fea | 2003-01-14 22:00:31 +0000 | [diff] [blame] | 20 | static const TargetInstrDescriptor X86Insts[] = { |
Chris Lattner | b339223 | 2002-12-18 01:05:54 +0000 | [diff] [blame] | 21 | #define I(ENUM, NAME, BASEOPCODE, FLAGS, TSFLAGS, IMPUSES, IMPDEFS) \ |
Chris Lattner | b752e9a | 2002-10-30 01:15:31 +0000 | [diff] [blame] | 22 | { NAME, \ |
| 23 | -1, /* Always vararg */ \ |
| 24 | ((TSFLAGS) & X86II::Void) ? -1 : 0, /* Result is in 0 */ \ |
Chris Lattner | b339223 | 2002-12-18 01:05:54 +0000 | [diff] [blame] | 25 | 0, /* maxImmedConst field */\ |
| 26 | false, /* immedIsSignExtended */\ |
| 27 | 0, /* numDelaySlots */\ |
| 28 | 0, /* latency */\ |
| 29 | 0, /* schedClass */\ |
| 30 | FLAGS, /* Flags */\ |
| 31 | TSFLAGS, /* TSFlags */\ |
| 32 | IMPUSES, /* ImplicitUses */\ |
| 33 | IMPDEFS }, /* ImplicitDefs */ |
Chris Lattner | 055c965 | 2002-10-29 21:05:24 +0000 | [diff] [blame] | 34 | #include "X86InstrInfo.def" |
Chris Lattner | 7261408 | 2002-10-25 22:55:53 +0000 | [diff] [blame] | 35 | }; |
| 36 | |
Chris Lattner | 055c965 | 2002-10-29 21:05:24 +0000 | [diff] [blame] | 37 | X86InstrInfo::X86InstrInfo() |
Chris Lattner | 3501fea | 2003-01-14 22:00:31 +0000 | [diff] [blame] | 38 | : TargetInstrInfo(X86Insts, sizeof(X86Insts)/sizeof(X86Insts[0]), 0) { |
Chris Lattner | 7261408 | 2002-10-25 22:55:53 +0000 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | |
Misha Brukman | e9d8838 | 2003-05-24 00:09:50 +0000 | [diff] [blame] | 42 | // createNOPinstr - returns the target's implementation of NOP, which is |
| 43 | // usually a pseudo-instruction, implemented by a degenerate version of |
| 44 | // another instruction, e.g. X86: `xchg ax, ax'; SparcV9: `sethi r0, r0, r0' |
| 45 | // |
| 46 | MachineInstr* X86InstrInfo::createNOPinstr() const { |
| 47 | return BuildMI(X86::XCHGrr16, 2).addReg(X86::AX).addReg(X86::AX); |
| 48 | } |
| 49 | |
| 50 | |
| 51 | // isNOPinstr - since we no longer have a special NOP opcode, we need to know |
| 52 | // if a given instruction is interpreted as an `official' NOP instr, i.e., |
| 53 | // there may be more than one way to `do nothing' but only one canonical |
| 54 | // way to slack off. |
| 55 | // |
| 56 | bool X86InstrInfo::isNOPinstr(const MachineInstr &MI) const { |
| 57 | // Make sure the instruction is EXACTLY `xchg ax, ax' |
| 58 | if (MI.getOpcode() == X86::XCHGrr16 && MI.getNumOperands() == 2) { |
| 59 | const MachineOperand &op0 = MI.getOperand(0), &op1 = MI.getOperand(1); |
| 60 | if (op0.isMachineRegister() && op0.getMachineRegNum() == X86::AX && |
| 61 | op1.isMachineRegister() && op1.getMachineRegNum() == X86::AX) |
| 62 | { |
| 63 | return true; |
| 64 | } |
| 65 | } |
| 66 | return false; |
| 67 | } |
| 68 | |
| 69 | |
Chris Lattner | f21dfcd | 2002-11-18 06:56:24 +0000 | [diff] [blame] | 70 | static unsigned char BaseOpcodes[] = { |
Chris Lattner | 4ce42a7 | 2002-12-03 05:42:53 +0000 | [diff] [blame] | 71 | #define I(ENUM, NAME, BASEOPCODE, FLAGS, TSFLAGS, IMPDEFS, IMPUSES) BASEOPCODE, |
Chris Lattner | f21dfcd | 2002-11-18 06:56:24 +0000 | [diff] [blame] | 72 | #include "X86InstrInfo.def" |
| 73 | }; |
| 74 | |
| 75 | // getBaseOpcodeFor - This function returns the "base" X86 opcode for the |
| 76 | // specified opcode number. |
| 77 | // |
| 78 | unsigned char X86InstrInfo::getBaseOpcodeFor(unsigned Opcode) const { |
| 79 | assert(Opcode < sizeof(BaseOpcodes)/sizeof(BaseOpcodes[0]) && |
| 80 | "Opcode out of range!"); |
| 81 | return BaseOpcodes[Opcode]; |
| 82 | } |