blob: 182798e23d7bff9f507340b444ea36bf383ffb84 [file] [log] [blame]
Misha Brukmana85d6bc2002-11-22 22:42:50 +00001//===- X86InstrInfo.cpp - X86 Instruction Information -----------*- C++ -*-===//
Chris Lattner72614082002-10-25 22:55:53 +00002//
Chris Lattner3501fea2003-01-14 22:00:31 +00003// This file contains the X86 implementation of the TargetInstrInfo class.
Chris Lattner72614082002-10-25 22:55:53 +00004//
5//===----------------------------------------------------------------------===//
6
Chris Lattner055c9652002-10-29 21:05:24 +00007#include "X86InstrInfo.h"
Chris Lattner4ce42a72002-12-03 05:42:53 +00008#include "X86.h"
Misha Brukmane9d88382003-05-24 00:09:50 +00009#include "llvm/CodeGen/MachineInstrBuilder.h"
Chris Lattner4ce42a72002-12-03 05:42:53 +000010
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 Lattner72614082002-10-25 22:55:53 +000016
Chris Lattner055c9652002-10-29 21:05:24 +000017// X86Insts - Turn the InstrInfo.def file into a bunch of instruction
Chris Lattner72614082002-10-25 22:55:53 +000018// descriptors
19//
Chris Lattner3501fea2003-01-14 22:00:31 +000020static const TargetInstrDescriptor X86Insts[] = {
Chris Lattnerb3392232002-12-18 01:05:54 +000021#define I(ENUM, NAME, BASEOPCODE, FLAGS, TSFLAGS, IMPUSES, IMPDEFS) \
Chris Lattnerb752e9a2002-10-30 01:15:31 +000022 { NAME, \
23 -1, /* Always vararg */ \
24 ((TSFLAGS) & X86II::Void) ? -1 : 0, /* Result is in 0 */ \
Chris Lattnerb3392232002-12-18 01:05:54 +000025 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 Lattner055c9652002-10-29 21:05:24 +000034#include "X86InstrInfo.def"
Chris Lattner72614082002-10-25 22:55:53 +000035};
36
Chris Lattner055c9652002-10-29 21:05:24 +000037X86InstrInfo::X86InstrInfo()
Chris Lattner3501fea2003-01-14 22:00:31 +000038 : TargetInstrInfo(X86Insts, sizeof(X86Insts)/sizeof(X86Insts[0]), 0) {
Chris Lattner72614082002-10-25 22:55:53 +000039}
40
41
Misha Brukmane9d88382003-05-24 00:09:50 +000042// 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//
46MachineInstr* 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//
56bool 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 Lattnerf21dfcd2002-11-18 06:56:24 +000070static unsigned char BaseOpcodes[] = {
Chris Lattner4ce42a72002-12-03 05:42:53 +000071#define I(ENUM, NAME, BASEOPCODE, FLAGS, TSFLAGS, IMPDEFS, IMPUSES) BASEOPCODE,
Chris Lattnerf21dfcd2002-11-18 06:56:24 +000072#include "X86InstrInfo.def"
73};
74
75// getBaseOpcodeFor - This function returns the "base" X86 opcode for the
76// specified opcode number.
77//
78unsigned char X86InstrInfo::getBaseOpcodeFor(unsigned Opcode) const {
79 assert(Opcode < sizeof(BaseOpcodes)/sizeof(BaseOpcodes[0]) &&
80 "Opcode out of range!");
81 return BaseOpcodes[Opcode];
82}