blob: 699c9d21d6ed1c93040feb14ba16fe4942f72fe8 [file] [log] [blame]
Chris Lattner7c90f732006-02-05 05:50:24 +00001//===- SparcInstrInfo.cpp - Sparc Instruction Information -------*- C++ -*-===//
Misha Brukmanb5f662f2005-04-21 23:30:14 +00002//
Brian Gaekee785e532004-02-25 19:28:19 +00003// 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.
Misha Brukmanb5f662f2005-04-21 23:30:14 +00007//
Brian Gaekee785e532004-02-25 19:28:19 +00008//===----------------------------------------------------------------------===//
9//
Chris Lattner7c90f732006-02-05 05:50:24 +000010// This file contains the Sparc implementation of the TargetInstrInfo class.
Brian Gaekee785e532004-02-25 19:28:19 +000011//
12//===----------------------------------------------------------------------===//
13
Chris Lattner7c90f732006-02-05 05:50:24 +000014#include "SparcInstrInfo.h"
15#include "Sparc.h"
Brian Gaekee785e532004-02-25 19:28:19 +000016#include "llvm/CodeGen/MachineInstrBuilder.h"
Chris Lattner7c90f732006-02-05 05:50:24 +000017#include "SparcGenInstrInfo.inc"
Chris Lattner1ddf4752004-02-29 05:59:33 +000018using namespace llvm;
Brian Gaekee785e532004-02-25 19:28:19 +000019
Chris Lattner7c90f732006-02-05 05:50:24 +000020SparcInstrInfo::SparcInstrInfo(SparcSubtarget &ST)
21 : TargetInstrInfo(SparcInsts, sizeof(SparcInsts)/sizeof(SparcInsts[0])),
Chris Lattner69d39092006-02-04 06:58:46 +000022 RI(ST) {
Brian Gaekee785e532004-02-25 19:28:19 +000023}
24
Chris Lattner69d39092006-02-04 06:58:46 +000025static bool isZeroImm(const MachineOperand &op) {
26 return op.isImmediate() && op.getImmedValue() == 0;
Brian Gaeke4658ba12004-12-11 05:19:03 +000027}
28
Chris Lattner1d6dc972004-07-25 06:19:04 +000029/// Return true if the instruction is a register to register move and
30/// leave the source and dest operands in the passed parameters.
31///
Chris Lattner7c90f732006-02-05 05:50:24 +000032bool SparcInstrInfo::isMoveInstr(const MachineInstr &MI,
33 unsigned &SrcReg, unsigned &DstReg) const {
Brian Gaeke4658ba12004-12-11 05:19:03 +000034 // We look for 3 kinds of patterns here:
35 // or with G0 or 0
36 // add with G0 or 0
37 // fmovs or FpMOVD (pseudo double move).
Chris Lattner7c90f732006-02-05 05:50:24 +000038 if (MI.getOpcode() == SP::ORrr || MI.getOpcode() == SP::ADDrr) {
39 if (MI.getOperand(1).getReg() == SP::G0) {
Chris Lattner1d6dc972004-07-25 06:19:04 +000040 DstReg = MI.getOperand(0).getReg();
41 SrcReg = MI.getOperand(2).getReg();
Brian Gaeke9b8ed0e2004-09-29 03:28:15 +000042 return true;
Chris Lattner7c90f732006-02-05 05:50:24 +000043 } else if (MI.getOperand(2).getReg() == SP::G0) {
Brian Gaeke4658ba12004-12-11 05:19:03 +000044 DstReg = MI.getOperand(0).getReg();
45 SrcReg = MI.getOperand(1).getReg();
46 return true;
47 }
Chris Lattner7c90f732006-02-05 05:50:24 +000048 } else if ((MI.getOpcode() == SP::ORri || MI.getOpcode() == SP::ADDri) &&
Chris Lattner69d39092006-02-04 06:58:46 +000049 isZeroImm(MI.getOperand(2)) && MI.getOperand(1).isRegister()) {
50 DstReg = MI.getOperand(0).getReg();
51 SrcReg = MI.getOperand(1).getReg();
52 return true;
Chris Lattner7c90f732006-02-05 05:50:24 +000053 } else if (MI.getOpcode() == SP::FMOVS || MI.getOpcode() == SP::FpMOVD ||
54 MI.getOpcode() == SP::FMOVD) {
Chris Lattner1d6dc972004-07-25 06:19:04 +000055 SrcReg = MI.getOperand(1).getReg();
56 DstReg = MI.getOperand(0).getReg();
57 return true;
58 }
59 return false;
60}
Chris Lattner5ccc7222006-02-03 06:44:54 +000061
62/// isLoadFromStackSlot - If the specified machine instruction is a direct
63/// load from a stack slot, return the virtual or physical register number of
64/// the destination along with the FrameIndex of the loaded stack slot. If
65/// not, return 0. This predicate must return 0 if the instruction has
66/// any side effects other than loading from the stack slot.
Chris Lattner7c90f732006-02-05 05:50:24 +000067unsigned SparcInstrInfo::isLoadFromStackSlot(MachineInstr *MI,
68 int &FrameIndex) const {
69 if (MI->getOpcode() == SP::LDri ||
70 MI->getOpcode() == SP::LDFri ||
71 MI->getOpcode() == SP::LDDFri) {
Chris Lattner5ccc7222006-02-03 06:44:54 +000072 if (MI->getOperand(1).isFrameIndex() && MI->getOperand(2).isImmediate() &&
73 MI->getOperand(2).getImmedValue() == 0) {
74 FrameIndex = MI->getOperand(1).getFrameIndex();
75 return MI->getOperand(0).getReg();
76 }
77 }
78 return 0;
79}
80
81/// isStoreToStackSlot - If the specified machine instruction is a direct
82/// store to a stack slot, return the virtual or physical register number of
83/// the source reg along with the FrameIndex of the loaded stack slot. If
84/// not, return 0. This predicate must return 0 if the instruction has
85/// any side effects other than storing to the stack slot.
Chris Lattner7c90f732006-02-05 05:50:24 +000086unsigned SparcInstrInfo::isStoreToStackSlot(MachineInstr *MI,
87 int &FrameIndex) const {
88 if (MI->getOpcode() == SP::STri ||
89 MI->getOpcode() == SP::STFri ||
90 MI->getOpcode() == SP::STDFri) {
Chris Lattner5ccc7222006-02-03 06:44:54 +000091 if (MI->getOperand(0).isFrameIndex() && MI->getOperand(1).isImmediate() &&
92 MI->getOperand(1).getImmedValue() == 0) {
93 FrameIndex = MI->getOperand(0).getFrameIndex();
94 return MI->getOperand(2).getReg();
95 }
96 }
97 return 0;
98}