blob: 6faa9723c162889f2b4c83e37170e4e95217628b [file] [log] [blame]
Brian Gaekee785e532004-02-25 19:28:19 +00001//===- SparcV8InstrInfo.cpp - SparcV8 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//
10// This file contains the SparcV8 implementation of the TargetInstrInfo class.
11//
12//===----------------------------------------------------------------------===//
13
14#include "SparcV8InstrInfo.h"
Chris Lattner1d6dc972004-07-25 06:19:04 +000015#include "SparcV8.h"
Brian Gaekee785e532004-02-25 19:28:19 +000016#include "llvm/CodeGen/MachineInstrBuilder.h"
17#include "SparcV8GenInstrInfo.inc"
Chris Lattner1ddf4752004-02-29 05:59:33 +000018using namespace llvm;
Brian Gaekee785e532004-02-25 19:28:19 +000019
20SparcV8InstrInfo::SparcV8InstrInfo()
Chris Lattnerdce363d2004-02-29 06:31:44 +000021 : TargetInstrInfo(SparcV8Insts, sizeof(SparcV8Insts)/sizeof(SparcV8Insts[0])){
Brian Gaekee785e532004-02-25 19:28:19 +000022}
23
Brian Gaeke4658ba12004-12-11 05:19:03 +000024static bool isZeroImmed (const MachineOperand &op) {
25 return (op.isImmediate() && op.getImmedValue() == 0);
26}
27
Chris Lattner1d6dc972004-07-25 06:19:04 +000028/// Return true if the instruction is a register to register move and
29/// leave the source and dest operands in the passed parameters.
30///
31bool SparcV8InstrInfo::isMoveInstr(const MachineInstr &MI,
32 unsigned &SrcReg, unsigned &DstReg) const {
Brian Gaeke4658ba12004-12-11 05:19:03 +000033 // We look for 3 kinds of patterns here:
34 // or with G0 or 0
35 // add with G0 or 0
36 // fmovs or FpMOVD (pseudo double move).
37 if (MI.getOpcode() == V8::ORrr || MI.getOpcode() == V8::ADDrr) {
38 if (MI.getOperand(1).getReg() == V8::G0) {
Chris Lattner1d6dc972004-07-25 06:19:04 +000039 DstReg = MI.getOperand(0).getReg();
40 SrcReg = MI.getOperand(2).getReg();
Brian Gaeke9b8ed0e2004-09-29 03:28:15 +000041 return true;
Brian Gaeke4658ba12004-12-11 05:19:03 +000042 } else if (MI.getOperand (2).getReg() == V8::G0) {
43 DstReg = MI.getOperand(0).getReg();
44 SrcReg = MI.getOperand(1).getReg();
45 return true;
46 }
47 } else if (MI.getOpcode() == V8::ORri || MI.getOpcode() == V8::ADDri) {
Chris Lattnerabfc2a72005-12-18 06:40:34 +000048 if (isZeroImmed(MI.getOperand(2)) && MI.getOperand(1).isRegister()) {
Brian Gaeke4658ba12004-12-11 05:19:03 +000049 DstReg = MI.getOperand(0).getReg();
50 SrcReg = MI.getOperand(1).getReg();
51 return true;
Chris Lattner1d6dc972004-07-25 06:19:04 +000052 }
Brian Gaeke9ed92042004-09-29 16:45:47 +000053 } else if (MI.getOpcode() == V8::FMOVS || MI.getOpcode() == V8::FpMOVD) {
Chris Lattner1d6dc972004-07-25 06:19:04 +000054 SrcReg = MI.getOperand(1).getReg();
55 DstReg = MI.getOperand(0).getReg();
56 return true;
57 }
58 return false;
59}
Chris Lattner5ccc7222006-02-03 06:44:54 +000060
61/// isLoadFromStackSlot - If the specified machine instruction is a direct
62/// load from a stack slot, return the virtual or physical register number of
63/// the destination along with the FrameIndex of the loaded stack slot. If
64/// not, return 0. This predicate must return 0 if the instruction has
65/// any side effects other than loading from the stack slot.
66unsigned SparcV8InstrInfo::isLoadFromStackSlot(MachineInstr *MI,
67 int &FrameIndex) const {
68 if (MI->getOpcode() == V8::LDri ||
69 MI->getOpcode() == V8::LDFri ||
70 MI->getOpcode() == V8::LDDFri) {
71 if (MI->getOperand(1).isFrameIndex() && MI->getOperand(2).isImmediate() &&
72 MI->getOperand(2).getImmedValue() == 0) {
73 FrameIndex = MI->getOperand(1).getFrameIndex();
74 return MI->getOperand(0).getReg();
75 }
76 }
77 return 0;
78}
79
80/// isStoreToStackSlot - If the specified machine instruction is a direct
81/// store to a stack slot, return the virtual or physical register number of
82/// the source reg along with the FrameIndex of the loaded stack slot. If
83/// not, return 0. This predicate must return 0 if the instruction has
84/// any side effects other than storing to the stack slot.
85unsigned SparcV8InstrInfo::isStoreToStackSlot(MachineInstr *MI,
86 int &FrameIndex) const {
87 if (MI->getOpcode() == V8::STri ||
88 MI->getOpcode() == V8::STFri ||
89 MI->getOpcode() == V8::STDFri) {
90 if (MI->getOperand(0).isFrameIndex() && MI->getOperand(1).isImmediate() &&
91 MI->getOperand(1).getImmedValue() == 0) {
92 FrameIndex = MI->getOperand(0).getFrameIndex();
93 return MI->getOperand(2).getReg();
94 }
95 }
96 return 0;
97}