Misha Brukman | a85d6bc | 2002-11-22 22:42:50 +0000 | [diff] [blame] | 1 | //===- X86InstrInfo.cpp - X86 Instruction Information -----------*- C++ -*-===// |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 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 | //===----------------------------------------------------------------------===// |
Chris Lattner | 7261408 | 2002-10-25 22:55:53 +0000 | [diff] [blame] | 9 | // |
Chris Lattner | 3501fea | 2003-01-14 22:00:31 +0000 | [diff] [blame] | 10 | // This file contains the X86 implementation of the TargetInstrInfo class. |
Chris Lattner | 7261408 | 2002-10-25 22:55:53 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Chris Lattner | 055c965 | 2002-10-29 21:05:24 +0000 | [diff] [blame] | 14 | #include "X86InstrInfo.h" |
Chris Lattner | 4ce42a7 | 2002-12-03 05:42:53 +0000 | [diff] [blame] | 15 | #include "X86.h" |
Misha Brukman | e9d8838 | 2003-05-24 00:09:50 +0000 | [diff] [blame] | 16 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Chris Lattner | 4ce42a7 | 2002-12-03 05:42:53 +0000 | [diff] [blame] | 17 | |
Chris Lattner | abf05b2 | 2003-08-03 21:55:55 +0000 | [diff] [blame] | 18 | #include "X86GenInstrInfo.inc" |
Chris Lattner | 7261408 | 2002-10-25 22:55:53 +0000 | [diff] [blame] | 19 | |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 20 | using namespace llvm; |
| 21 | |
Chris Lattner | 055c965 | 2002-10-29 21:05:24 +0000 | [diff] [blame] | 22 | X86InstrInfo::X86InstrInfo() |
Chris Lattner | 3501fea | 2003-01-14 22:00:31 +0000 | [diff] [blame] | 23 | : TargetInstrInfo(X86Insts, sizeof(X86Insts)/sizeof(X86Insts[0]), 0) { |
Chris Lattner | 7261408 | 2002-10-25 22:55:53 +0000 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | |
Misha Brukman | e9d8838 | 2003-05-24 00:09:50 +0000 | [diff] [blame] | 27 | // createNOPinstr - returns the target's implementation of NOP, which is |
| 28 | // usually a pseudo-instruction, implemented by a degenerate version of |
| 29 | // another instruction, e.g. X86: `xchg ax, ax'; SparcV9: `sethi r0, r0, r0' |
| 30 | // |
| 31 | MachineInstr* X86InstrInfo::createNOPinstr() const { |
Chris Lattner | abf05b2 | 2003-08-03 21:55:55 +0000 | [diff] [blame] | 32 | return BuildMI(X86::XCHGrr16, 2).addReg(X86::AX, MOTy::UseAndDef) |
| 33 | .addReg(X86::AX, MOTy::UseAndDef); |
Misha Brukman | e9d8838 | 2003-05-24 00:09:50 +0000 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | |
Misha Brukman | 12745c5 | 2003-05-24 01:08:43 +0000 | [diff] [blame] | 37 | /// isNOPinstr - not having a special NOP opcode, we need to know if a given |
| 38 | /// instruction is interpreted as an `official' NOP instr, i.e., there may be |
| 39 | /// more than one way to `do nothing' but only one canonical way to slack off. |
Misha Brukman | e9d8838 | 2003-05-24 00:09:50 +0000 | [diff] [blame] | 40 | // |
| 41 | bool X86InstrInfo::isNOPinstr(const MachineInstr &MI) const { |
| 42 | // Make sure the instruction is EXACTLY `xchg ax, ax' |
Chris Lattner | abf05b2 | 2003-08-03 21:55:55 +0000 | [diff] [blame] | 43 | if (MI.getOpcode() == X86::XCHGrr16) { |
Misha Brukman | e9d8838 | 2003-05-24 00:09:50 +0000 | [diff] [blame] | 44 | const MachineOperand &op0 = MI.getOperand(0), &op1 = MI.getOperand(1); |
| 45 | if (op0.isMachineRegister() && op0.getMachineRegNum() == X86::AX && |
Chris Lattner | abf05b2 | 2003-08-03 21:55:55 +0000 | [diff] [blame] | 46 | op1.isMachineRegister() && op1.getMachineRegNum() == X86::AX) { |
Misha Brukman | e9d8838 | 2003-05-24 00:09:50 +0000 | [diff] [blame] | 47 | return true; |
| 48 | } |
| 49 | } |
Chris Lattner | abf05b2 | 2003-08-03 21:55:55 +0000 | [diff] [blame] | 50 | // FIXME: there are several NOOP instructions, we should check for them here. |
Misha Brukman | e9d8838 | 2003-05-24 00:09:50 +0000 | [diff] [blame] | 51 | return false; |
| 52 | } |
| 53 | |