blob: b03a12078dea16c89e8da40858b0be09c2577847 [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
Misha Brukman12745c52003-05-24 01:08:43 +000051/// 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.
Misha Brukmane9d88382003-05-24 00:09:50 +000054//
55bool 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
Chris Lattnerf21dfcd2002-11-18 06:56:24 +000069static unsigned char BaseOpcodes[] = {
Chris Lattner4ce42a72002-12-03 05:42:53 +000070#define I(ENUM, NAME, BASEOPCODE, FLAGS, TSFLAGS, IMPDEFS, IMPUSES) BASEOPCODE,
Chris Lattnerf21dfcd2002-11-18 06:56:24 +000071#include "X86InstrInfo.def"
72};
73
74// getBaseOpcodeFor - This function returns the "base" X86 opcode for the
75// specified opcode number.
76//
77unsigned char X86InstrInfo::getBaseOpcodeFor(unsigned Opcode) const {
78 assert(Opcode < sizeof(BaseOpcodes)/sizeof(BaseOpcodes[0]) &&
79 "Opcode out of range!");
80 return BaseOpcodes[Opcode];
81}