1 //===- MipsInstrInfo.cpp - Mips Instruction Information ---------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by Bruno Cardoso Lopes and is distributed under the
6 // University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains the Mips implementation of the TargetInstrInfo class.
12 //===----------------------------------------------------------------------===//
15 #include "MipsInstrInfo.h"
16 #include "llvm/CodeGen/MachineInstrBuilder.h"
17 #include "MipsGenInstrInfo.inc"
21 // TODO: Add the subtarget support on this constructor
22 MipsInstrInfo::MipsInstrInfo(MipsTargetMachine &tm)
23 : TargetInstrInfo(MipsInsts, sizeof(MipsInsts)/sizeof(MipsInsts[0])),
26 static bool isZeroImm(const MachineOperand &op) {
27 return op.isImmediate() && op.getImmedValue() == 0;
30 /// Return true if the instruction is a register to register move and
31 /// leave the source and dest operands in the passed parameters.
33 isMoveInstr(const MachineInstr &MI, unsigned &SrcReg, unsigned &DstReg) const
35 // addu $dst, $src, $zero || addu $dst, $zero, $src
36 // or $dst, $src, $zero || or $dst, $zero, $src
37 if ((MI.getOpcode() == Mips::ADDu) || (MI.getOpcode() == Mips::OR))
39 if (MI.getOperand(1).getReg() == Mips::ZERO) {
40 DstReg = MI.getOperand(0).getReg();
41 SrcReg = MI.getOperand(2).getReg();
43 } else if (MI.getOperand(2).getReg() == Mips::ZERO) {
44 DstReg = MI.getOperand(0).getReg();
45 SrcReg = MI.getOperand(1).getReg();
50 // addiu $dst, $src, 0
51 if (MI.getOpcode() == Mips::ADDiu)
53 if ((MI.getOperand(1).isRegister()) && (isZeroImm(MI.getOperand(2)))) {
54 DstReg = MI.getOperand(0).getReg();
55 SrcReg = MI.getOperand(1).getReg();
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.
67 unsigned MipsInstrInfo::
68 isLoadFromStackSlot(MachineInstr *MI, int &FrameIndex) const
70 // TODO: add lhu, lbu ???
71 if (MI->getOpcode() == Mips::LW)
73 if ((MI->getOperand(2).isFrameIndex()) && // is a stack slot
74 (MI->getOperand(1).isImmediate()) && // the imm is zero
75 (isZeroImm(MI->getOperand(1))))
77 FrameIndex = MI->getOperand(2).getFrameIndex();
78 return MI->getOperand(0).getReg();
85 /// isStoreToStackSlot - If the specified machine instruction is a direct
86 /// store to a stack slot, return the virtual or physical register number of
87 /// the source reg along with the FrameIndex of the loaded stack slot. If
88 /// not, return 0. This predicate must return 0 if the instruction has
89 /// any side effects other than storing to the stack slot.
90 unsigned MipsInstrInfo::
91 isStoreToStackSlot(MachineInstr *MI, int &FrameIndex) const
93 // TODO: add sb, sh ???
94 if (MI->getOpcode() == Mips::SW) {
95 if ((MI->getOperand(0).isFrameIndex()) && // is a stack slot
96 (MI->getOperand(1).isImmediate()) && // the imm is zero
97 (isZeroImm(MI->getOperand(1))))
99 FrameIndex = MI->getOperand(0).getFrameIndex();
100 return MI->getOperand(2).getReg();
106 unsigned MipsInstrInfo::
107 InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
108 MachineBasicBlock *FBB, const std::vector<MachineOperand> &Cond)
111 // TODO: add Mips::J here.
112 assert(0 && "Cant handle any kind of branches!");