blob: 4be727dd8994d8085acd01bbe6a1109872f4649a [file] [log] [blame]
Jia Liubb481f82012-02-28 07:46:26 +00001//===-- MipsInstrInfo.h - Mips Instruction Information ----------*- C++ -*-===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00002//
3// 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.
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00007//
Akira Hatanaka4552c9a2011-04-15 21:51:11 +00008//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00009//
10// This file contains the Mips implementation of the TargetInstrInfo class.
11//
Akira Hatanaka4552c9a2011-04-15 21:51:11 +000012//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000013
14#ifndef MIPSINSTRUCTIONINFO_H
15#define MIPSINSTRUCTIONINFO_H
16
17#include "Mips.h"
Craig Topper79aa3412012-03-17 18:46:09 +000018#include "MipsRegisterInfo.h"
Torok Edwinc25e7582009-07-11 20:10:48 +000019#include "llvm/Support/ErrorHandling.h"
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000020#include "llvm/Target/TargetInstrInfo.h"
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000021
Evan Cheng4db3cff2011-07-01 17:57:27 +000022#define GET_INSTRINFO_HEADER
23#include "MipsGenInstrInfo.inc"
24
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000025namespace llvm {
26
Bruno Cardoso Lopes0b2cd892007-08-18 01:59:45 +000027namespace Mips {
Akira Hatanaka20ada982011-04-01 17:39:08 +000028 /// GetOppositeBranchOpc - Return the inverse of the specified
29 /// opcode, e.g. turning BEQ to BNE.
30 unsigned GetOppositeBranchOpc(unsigned Opc);
Bruno Cardoso Lopes0b2cd892007-08-18 01:59:45 +000031}
32
Evan Cheng4db3cff2011-07-01 17:57:27 +000033class MipsInstrInfo : public MipsGenInstrInfo {
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000034 MipsTargetMachine &TM;
Akira Hatanaka43aed322011-10-11 00:37:28 +000035 bool IsN64;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000036 const MipsRegisterInfo RI;
Akira Hatanaka6e55ff52011-12-12 22:39:35 +000037 unsigned UncondBrOpc;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000038public:
Dan Gohman950a4c42008-03-25 22:06:05 +000039 explicit MipsInstrInfo(MipsTargetMachine &TM);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000040
41 /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As
42 /// such, whenever a client has an instance of instruction info, it should
43 /// always be able to get register info as well (through this method).
44 ///
Akira Hatanaka794bf172011-07-07 23:56:50 +000045 virtual const MipsRegisterInfo &getRegisterInfo() const;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000046
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000047 /// isLoadFromStackSlot - If the specified machine instruction is a direct
48 /// load from a stack slot, return the virtual or physical register number of
49 /// the destination along with the FrameIndex of the loaded stack slot. If
50 /// not, return 0. This predicate must return 0 if the instruction has
51 /// any side effects other than loading from the stack slot.
Dan Gohmancbad42c2008-11-18 19:49:32 +000052 virtual unsigned isLoadFromStackSlot(const MachineInstr *MI,
53 int &FrameIndex) const;
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +000054
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000055 /// isStoreToStackSlot - If the specified machine instruction is a direct
56 /// store to a stack slot, return the virtual or physical register number of
57 /// the source reg along with the FrameIndex of the loaded stack slot. If
58 /// not, return 0. This predicate must return 0 if the instruction has
59 /// any side effects other than storing to the stack slot.
Dan Gohmancbad42c2008-11-18 19:49:32 +000060 virtual unsigned isStoreToStackSlot(const MachineInstr *MI,
61 int &FrameIndex) const;
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +000062
Bruno Cardoso Lopes0b2cd892007-08-18 01:59:45 +000063 /// Branch Analysis
64 virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
65 MachineBasicBlock *&FBB,
Evan Chengdc54d312009-02-09 07:14:22 +000066 SmallVectorImpl<MachineOperand> &Cond,
67 bool AllowModify) const;
Bruno Cardoso Lopes0b2cd892007-08-18 01:59:45 +000068 virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
Akira Hatanaka20ada982011-04-01 17:39:08 +000069
70private:
71 void BuildCondBr(MachineBasicBlock &MBB, MachineBasicBlock *TBB, DebugLoc DL,
72 const SmallVectorImpl<MachineOperand>& Cond) const;
73
74public:
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000075 virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
Bruno Cardoso Lopes0b2cd892007-08-18 01:59:45 +000076 MachineBasicBlock *FBB,
Stuart Hastings3bf91252010-06-17 22:43:56 +000077 const SmallVectorImpl<MachineOperand> &Cond,
78 DebugLoc DL) const;
Jakob Stoklund Olesen273c14f2010-07-11 01:08:31 +000079 virtual void copyPhysReg(MachineBasicBlock &MBB,
80 MachineBasicBlock::iterator MI, DebugLoc DL,
81 unsigned DestReg, unsigned SrcReg,
82 bool KillSrc) const;
Owen Andersonf6372aa2008-01-01 21:11:32 +000083 virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
84 MachineBasicBlock::iterator MBBI,
Akira Hatanaka4552c9a2011-04-15 21:51:11 +000085 unsigned SrcReg, bool isKill, int FrameIndex,
Evan Cheng746ad692010-05-06 19:06:44 +000086 const TargetRegisterClass *RC,
87 const TargetRegisterInfo *TRI) const;
Owen Andersonf6372aa2008-01-01 21:11:32 +000088
Owen Andersonf6372aa2008-01-01 21:11:32 +000089 virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
90 MachineBasicBlock::iterator MBBI,
91 unsigned DestReg, int FrameIndex,
Evan Cheng746ad692010-05-06 19:06:44 +000092 const TargetRegisterClass *RC,
93 const TargetRegisterInfo *TRI) const;
Owen Andersonf6372aa2008-01-01 21:11:32 +000094
Akira Hatanakac4f24eb2011-07-01 01:04:43 +000095 virtual MachineInstr* emitFrameIndexDebugValue(MachineFunction &MF,
96 int FrameIx, uint64_t Offset,
97 const MDNode *MDPtr,
98 DebugLoc DL) const;
99
Owen Anderson44eb65c2008-08-14 22:49:33 +0000100 virtual
101 bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
Bruno Cardoso Lopes0b2cd892007-08-18 01:59:45 +0000102
103 /// Insert nop instruction when hazard condition is found
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000104 virtual void insertNoop(MachineBasicBlock &MBB,
Bruno Cardoso Lopes0b2cd892007-08-18 01:59:45 +0000105 MachineBasicBlock::iterator MI) const;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000106};
107
108}
109
110#endif