blob: 298af02d8aec2752d12d4e1c9ec35488cf881d2d [file] [log] [blame]
Misha Brukmana85d6bc2002-11-22 22:42:50 +00001//===- X86InstrInfo.cpp - X86 Instruction Information -----------*- C++ -*-===//
John Criswellb576c942003-10-20 19:43:21 +00002//
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 Lattner72614082002-10-25 22:55:53 +00009//
Chris Lattner3501fea2003-01-14 22:00:31 +000010// This file contains the X86 implementation of the TargetInstrInfo class.
Chris Lattner72614082002-10-25 22:55:53 +000011//
12//===----------------------------------------------------------------------===//
13
Chris Lattner055c9652002-10-29 21:05:24 +000014#include "X86InstrInfo.h"
Chris Lattner4ce42a72002-12-03 05:42:53 +000015#include "X86.h"
Misha Brukmane9d88382003-05-24 00:09:50 +000016#include "llvm/CodeGen/MachineInstrBuilder.h"
Chris Lattner4ce42a72002-12-03 05:42:53 +000017
Chris Lattnerabf05b22003-08-03 21:55:55 +000018#include "X86GenInstrInfo.inc"
Chris Lattner72614082002-10-25 22:55:53 +000019
Brian Gaeked0fde302003-11-11 22:41:34 +000020using namespace llvm;
21
Chris Lattner055c9652002-10-29 21:05:24 +000022X86InstrInfo::X86InstrInfo()
Chris Lattner3501fea2003-01-14 22:00:31 +000023 : TargetInstrInfo(X86Insts, sizeof(X86Insts)/sizeof(X86Insts[0]), 0) {
Chris Lattner72614082002-10-25 22:55:53 +000024}
25
26
Misha Brukmane9d88382003-05-24 00:09:50 +000027// 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//
31MachineInstr* X86InstrInfo::createNOPinstr() const {
Chris Lattnerabf05b22003-08-03 21:55:55 +000032 return BuildMI(X86::XCHGrr16, 2).addReg(X86::AX, MOTy::UseAndDef)
33 .addReg(X86::AX, MOTy::UseAndDef);
Misha Brukmane9d88382003-05-24 00:09:50 +000034}
35
36
Misha Brukman12745c52003-05-24 01:08:43 +000037/// 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 Brukmane9d88382003-05-24 00:09:50 +000040//
41bool X86InstrInfo::isNOPinstr(const MachineInstr &MI) const {
42 // Make sure the instruction is EXACTLY `xchg ax, ax'
Chris Lattnerabf05b22003-08-03 21:55:55 +000043 if (MI.getOpcode() == X86::XCHGrr16) {
Misha Brukmane9d88382003-05-24 00:09:50 +000044 const MachineOperand &op0 = MI.getOperand(0), &op1 = MI.getOperand(1);
Chris Lattner6d215182004-02-10 20:31:28 +000045 if (op0.isRegister() && op0.getReg() == X86::AX &&
46 op1.isRegister() && op1.getReg() == X86::AX) {
Misha Brukmane9d88382003-05-24 00:09:50 +000047 return true;
48 }
49 }
Chris Lattnerabf05b22003-08-03 21:55:55 +000050 // FIXME: there are several NOOP instructions, we should check for them here.
Misha Brukmane9d88382003-05-24 00:09:50 +000051 return false;
52}
53
Alkis Evlogimenos5e300022003-12-28 17:35:08 +000054bool X86InstrInfo::isMoveInstr(const MachineInstr& MI,
55 unsigned& sourceReg,
56 unsigned& destReg) const {
57 MachineOpCode oc = MI.getOpcode();
Alkis Evlogimenosa1b6f952004-02-01 08:22:16 +000058 if (oc == X86::MOVrr8 || oc == X86::MOVrr16 || oc == X86::MOVrr32 ||
59 oc == X86::FpMOV) {
Alkis Evlogimenos5e300022003-12-28 17:35:08 +000060 assert(MI.getNumOperands() == 2 &&
61 MI.getOperand(0).isRegister() &&
62 MI.getOperand(1).isRegister() &&
63 "invalid register-register move instruction");
64 sourceReg = MI.getOperand(1).getAllocatedRegNum();
65 destReg = MI.getOperand(0).getAllocatedRegNum();
66 return true;
67 }
68 return false;
69}