blob: 765d648f5613676d3438913cfa5893f0498b831b [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//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// 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"
Owen Anderson718cb662007-09-07 04:06:50 +000016#include "llvm/ADT/STLExtras.h"
Brian Gaekee785e532004-02-25 19:28:19 +000017#include "llvm/CodeGen/MachineInstrBuilder.h"
Chris Lattner7c90f732006-02-05 05:50:24 +000018#include "SparcGenInstrInfo.inc"
Chris Lattner1ddf4752004-02-29 05:59:33 +000019using namespace llvm;
Brian Gaekee785e532004-02-25 19:28:19 +000020
Chris Lattner7c90f732006-02-05 05:50:24 +000021SparcInstrInfo::SparcInstrInfo(SparcSubtarget &ST)
Owen Anderson718cb662007-09-07 04:06:50 +000022 : TargetInstrInfo(SparcInsts, array_lengthof(SparcInsts)),
Evan Cheng7ce45782006-11-13 23:36:35 +000023 RI(ST, *this) {
Brian Gaekee785e532004-02-25 19:28:19 +000024}
25
Chris Lattner69d39092006-02-04 06:58:46 +000026static bool isZeroImm(const MachineOperand &op) {
27 return op.isImmediate() && op.getImmedValue() == 0;
Brian Gaeke4658ba12004-12-11 05:19:03 +000028}
29
Chris Lattner1d6dc972004-07-25 06:19:04 +000030/// Return true if the instruction is a register to register move and
31/// leave the source and dest operands in the passed parameters.
32///
Chris Lattner7c90f732006-02-05 05:50:24 +000033bool SparcInstrInfo::isMoveInstr(const MachineInstr &MI,
34 unsigned &SrcReg, unsigned &DstReg) const {
Brian Gaeke4658ba12004-12-11 05:19:03 +000035 // We look for 3 kinds of patterns here:
36 // or with G0 or 0
37 // add with G0 or 0
38 // fmovs or FpMOVD (pseudo double move).
Chris Lattner7c90f732006-02-05 05:50:24 +000039 if (MI.getOpcode() == SP::ORrr || MI.getOpcode() == SP::ADDrr) {
40 if (MI.getOperand(1).getReg() == SP::G0) {
Chris Lattner1d6dc972004-07-25 06:19:04 +000041 DstReg = MI.getOperand(0).getReg();
42 SrcReg = MI.getOperand(2).getReg();
Brian Gaeke9b8ed0e2004-09-29 03:28:15 +000043 return true;
Chris Lattner7c90f732006-02-05 05:50:24 +000044 } else if (MI.getOperand(2).getReg() == SP::G0) {
Brian Gaeke4658ba12004-12-11 05:19:03 +000045 DstReg = MI.getOperand(0).getReg();
46 SrcReg = MI.getOperand(1).getReg();
47 return true;
48 }
Chris Lattner7c90f732006-02-05 05:50:24 +000049 } else if ((MI.getOpcode() == SP::ORri || MI.getOpcode() == SP::ADDri) &&
Chris Lattner69d39092006-02-04 06:58:46 +000050 isZeroImm(MI.getOperand(2)) && MI.getOperand(1).isRegister()) {
51 DstReg = MI.getOperand(0).getReg();
52 SrcReg = MI.getOperand(1).getReg();
53 return true;
Chris Lattner7c90f732006-02-05 05:50:24 +000054 } else if (MI.getOpcode() == SP::FMOVS || MI.getOpcode() == SP::FpMOVD ||
55 MI.getOpcode() == SP::FMOVD) {
Chris Lattner1d6dc972004-07-25 06:19:04 +000056 SrcReg = MI.getOperand(1).getReg();
57 DstReg = MI.getOperand(0).getReg();
58 return true;
59 }
60 return false;
61}
Chris Lattner5ccc7222006-02-03 06:44:54 +000062
63/// isLoadFromStackSlot - If the specified machine instruction is a direct
64/// load from a stack slot, return the virtual or physical register number of
65/// the destination along with the FrameIndex of the loaded stack slot. If
66/// not, return 0. This predicate must return 0 if the instruction has
67/// any side effects other than loading from the stack slot.
Chris Lattner7c90f732006-02-05 05:50:24 +000068unsigned SparcInstrInfo::isLoadFromStackSlot(MachineInstr *MI,
69 int &FrameIndex) const {
70 if (MI->getOpcode() == SP::LDri ||
71 MI->getOpcode() == SP::LDFri ||
72 MI->getOpcode() == SP::LDDFri) {
Chris Lattner5ccc7222006-02-03 06:44:54 +000073 if (MI->getOperand(1).isFrameIndex() && MI->getOperand(2).isImmediate() &&
74 MI->getOperand(2).getImmedValue() == 0) {
75 FrameIndex = MI->getOperand(1).getFrameIndex();
76 return MI->getOperand(0).getReg();
77 }
78 }
79 return 0;
80}
81
82/// isStoreToStackSlot - If the specified machine instruction is a direct
83/// store to a stack slot, return the virtual or physical register number of
84/// the source reg along with the FrameIndex of the loaded stack slot. If
85/// not, return 0. This predicate must return 0 if the instruction has
86/// any side effects other than storing to the stack slot.
Chris Lattner7c90f732006-02-05 05:50:24 +000087unsigned SparcInstrInfo::isStoreToStackSlot(MachineInstr *MI,
88 int &FrameIndex) const {
89 if (MI->getOpcode() == SP::STri ||
90 MI->getOpcode() == SP::STFri ||
91 MI->getOpcode() == SP::STDFri) {
Chris Lattner5ccc7222006-02-03 06:44:54 +000092 if (MI->getOperand(0).isFrameIndex() && MI->getOperand(1).isImmediate() &&
93 MI->getOperand(1).getImmedValue() == 0) {
94 FrameIndex = MI->getOperand(0).getFrameIndex();
95 return MI->getOperand(2).getReg();
96 }
97 }
98 return 0;
99}
Chris Lattnere87146a2006-10-24 16:39:19 +0000100
Evan Cheng6ae36262007-05-18 00:18:17 +0000101unsigned
102SparcInstrInfo::InsertBranch(MachineBasicBlock &MBB,MachineBasicBlock *TBB,
103 MachineBasicBlock *FBB,
104 const std::vector<MachineOperand> &Cond)const{
Chris Lattnere87146a2006-10-24 16:39:19 +0000105 // Can only insert uncond branches so far.
106 assert(Cond.empty() && !FBB && TBB && "Can only handle uncond branches!");
Evan Chengc0f64ff2006-11-27 23:37:22 +0000107 BuildMI(&MBB, get(SP::BA)).addMBB(TBB);
Evan Cheng6ae36262007-05-18 00:18:17 +0000108 return 1;
Rafael Espindola3d7d39a2006-10-24 17:07:11 +0000109}