All store instructions really want 'rd' in the first field.
[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 #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
16
17 // X86Insts - Turn the InstrInfo.def file into a bunch of instruction
18 // descriptors
19 //
20 static const TargetInstrDescriptor X86Insts[] = {
21 #define I(ENUM, NAME, BASEOPCODE, FLAGS, TSFLAGS, IMPUSES, IMPDEFS)   \
22              { NAME,                    \
23                -1, /* Always vararg */  \
24                ((TSFLAGS) & X86II::Void) ? -1 : 0,  /* Result is in 0 */ \
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 */
34 #include "X86InstrInfo.def"
35 };
36
37 X86InstrInfo::X86InstrInfo()
38   : TargetInstrInfo(X86Insts, sizeof(X86Insts)/sizeof(X86Insts[0]), 0) {
39 }
40
41
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 - not having a special NOP opcode, we need to know if a given
52 /// instruction is interpreted as an `official' NOP instr, i.e., there may be
53 /// more than one way to `do nothing' but only one canonical way to slack off.
54 //
55 bool X86InstrInfo::isNOPinstr(const MachineInstr &MI) const {
56   // Make sure the instruction is EXACTLY `xchg ax, ax'
57   if (MI.getOpcode() == X86::XCHGrr16 && MI.getNumOperands() == 2) {
58     const MachineOperand &op0 = MI.getOperand(0), &op1 = MI.getOperand(1);
59     if (op0.isMachineRegister() && op0.getMachineRegNum() == X86::AX &&
60         op1.isMachineRegister() && op1.getMachineRegNum() == X86::AX)
61     {
62       return true;
63     }
64   }
65   return false;
66 }
67
68
69 static unsigned char BaseOpcodes[] = {
70 #define I(ENUM, NAME, BASEOPCODE, FLAGS, TSFLAGS, IMPDEFS, IMPUSES) BASEOPCODE,
71 #include "X86InstrInfo.def"
72 };
73
74 // getBaseOpcodeFor - This function returns the "base" X86 opcode for the
75 // specified opcode number.
76 //
77 unsigned char X86InstrInfo::getBaseOpcodeFor(unsigned Opcode) const {
78   assert(Opcode < sizeof(BaseOpcodes)/sizeof(BaseOpcodes[0]) &&
79          "Opcode out of range!");
80   return BaseOpcodes[Opcode];
81 }