* Start using tablegen'd instruction descriptions
[oota-llvm.git] / lib / Target / X86 / X86InstrInfo.cpp
1 //===- X86InstrInfo.cpp - X86 Instruction Information -----------*- C++ -*-===//
2 //
3 // This file contains the X86 implementation of the TargetInstrInfo class.
4 //
5 //===----------------------------------------------------------------------===//
6
7 #include "X86InstrInfo.h"
8 #include "X86.h"
9 #include "llvm/CodeGen/MachineInstrBuilder.h"
10
11 #include "X86GenInstrInfo.inc"
12
13 X86InstrInfo::X86InstrInfo()
14   : TargetInstrInfo(X86Insts, sizeof(X86Insts)/sizeof(X86Insts[0]), 0) {
15 }
16
17
18 // createNOPinstr - returns the target's implementation of NOP, which is
19 // usually a pseudo-instruction, implemented by a degenerate version of
20 // another instruction, e.g. X86: `xchg ax, ax'; SparcV9: `sethi r0, r0, r0'
21 //
22 MachineInstr* X86InstrInfo::createNOPinstr() const {
23   return BuildMI(X86::XCHGrr16, 2).addReg(X86::AX, MOTy::UseAndDef)
24                                   .addReg(X86::AX, MOTy::UseAndDef);
25 }
26
27
28 /// isNOPinstr - not having a special NOP opcode, we need to know if a given
29 /// instruction is interpreted as an `official' NOP instr, i.e., there may be
30 /// more than one way to `do nothing' but only one canonical way to slack off.
31 //
32 bool X86InstrInfo::isNOPinstr(const MachineInstr &MI) const {
33   // Make sure the instruction is EXACTLY `xchg ax, ax'
34   if (MI.getOpcode() == X86::XCHGrr16) {
35     const MachineOperand &op0 = MI.getOperand(0), &op1 = MI.getOperand(1);
36     if (op0.isMachineRegister() && op0.getMachineRegNum() == X86::AX &&
37         op1.isMachineRegister() && op1.getMachineRegNum() == X86::AX) {
38       return true;
39     }
40   }
41   // FIXME: there are several NOOP instructions, we should check for them here.
42   return false;
43 }
44