blob: 358f8173a041497861541adfcbcf68018493c811 [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"
Akira Hatanakad4b48b22012-06-14 01:16:45 +000018#include "MipsAnalyzeImmediate.h"
Craig Topper79aa3412012-03-17 18:46:09 +000019#include "MipsRegisterInfo.h"
Torok Edwinc25e7582009-07-11 20:10:48 +000020#include "llvm/Support/ErrorHandling.h"
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000021#include "llvm/Target/TargetInstrInfo.h"
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000022
Evan Cheng4db3cff2011-07-01 17:57:27 +000023#define GET_INSTRINFO_HEADER
24#include "MipsGenInstrInfo.inc"
25
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000026namespace llvm {
27
Evan Cheng4db3cff2011-07-01 17:57:27 +000028class MipsInstrInfo : public MipsGenInstrInfo {
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000029 MipsTargetMachine &TM;
Akira Hatanaka3ee306c2012-07-23 23:45:54 +000030 bool IsN64; bool InMips16Mode;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000031 const MipsRegisterInfo RI;
Akira Hatanaka6e55ff52011-12-12 22:39:35 +000032 unsigned UncondBrOpc;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000033public:
Dan Gohman950a4c42008-03-25 22:06:05 +000034 explicit MipsInstrInfo(MipsTargetMachine &TM);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000035
36 /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As
37 /// such, whenever a client has an instance of instruction info, it should
38 /// always be able to get register info as well (through this method).
39 ///
Akira Hatanaka794bf172011-07-07 23:56:50 +000040 virtual const MipsRegisterInfo &getRegisterInfo() const;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000041
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000042 /// isLoadFromStackSlot - If the specified machine instruction is a direct
43 /// load from a stack slot, return the virtual or physical register number of
44 /// the destination along with the FrameIndex of the loaded stack slot. If
45 /// not, return 0. This predicate must return 0 if the instruction has
46 /// any side effects other than loading from the stack slot.
Dan Gohmancbad42c2008-11-18 19:49:32 +000047 virtual unsigned isLoadFromStackSlot(const MachineInstr *MI,
48 int &FrameIndex) const;
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +000049
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000050 /// isStoreToStackSlot - If the specified machine instruction is a direct
51 /// store to a stack slot, return the virtual or physical register number of
52 /// the source reg along with the FrameIndex of the loaded stack slot. If
53 /// not, return 0. This predicate must return 0 if the instruction has
54 /// any side effects other than storing to the stack slot.
Dan Gohmancbad42c2008-11-18 19:49:32 +000055 virtual unsigned isStoreToStackSlot(const MachineInstr *MI,
56 int &FrameIndex) const;
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +000057
Bruno Cardoso Lopes0b2cd892007-08-18 01:59:45 +000058 /// Branch Analysis
59 virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
60 MachineBasicBlock *&FBB,
Evan Chengdc54d312009-02-09 07:14:22 +000061 SmallVectorImpl<MachineOperand> &Cond,
62 bool AllowModify) const;
Bruno Cardoso Lopes0b2cd892007-08-18 01:59:45 +000063 virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
Akira Hatanaka20ada982011-04-01 17:39:08 +000064
65private:
Akira Hatanaka182ef6f2012-07-10 00:19:06 +000066 void ExpandRetRA(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
67 unsigned Opc) const;
Akira Hatanaka3ee306c2012-07-23 23:45:54 +000068 void ExpandRetRA16(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
69 unsigned Opc) const;
70
Akira Hatanaka20ada982011-04-01 17:39:08 +000071 void BuildCondBr(MachineBasicBlock &MBB, MachineBasicBlock *TBB, DebugLoc DL,
72 const SmallVectorImpl<MachineOperand>& Cond) const;
Akira Hatanaka564f6902012-05-25 20:52:52 +000073 void ExpandExtractElementF64(MachineBasicBlock &MBB,
74 MachineBasicBlock::iterator I) const;
75 void ExpandBuildPairF64(MachineBasicBlock &MBB,
76 MachineBasicBlock::iterator I) const;
Akira Hatanaka20ada982011-04-01 17:39:08 +000077
78public:
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000079 virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
Bruno Cardoso Lopes0b2cd892007-08-18 01:59:45 +000080 MachineBasicBlock *FBB,
Stuart Hastings3bf91252010-06-17 22:43:56 +000081 const SmallVectorImpl<MachineOperand> &Cond,
82 DebugLoc DL) const;
Jakob Stoklund Olesen273c14f2010-07-11 01:08:31 +000083 virtual void copyPhysReg(MachineBasicBlock &MBB,
84 MachineBasicBlock::iterator MI, DebugLoc DL,
85 unsigned DestReg, unsigned SrcReg,
86 bool KillSrc) const;
Owen Andersonf6372aa2008-01-01 21:11:32 +000087 virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
88 MachineBasicBlock::iterator MBBI,
Akira Hatanaka4552c9a2011-04-15 21:51:11 +000089 unsigned SrcReg, bool isKill, int FrameIndex,
Evan Cheng746ad692010-05-06 19:06:44 +000090 const TargetRegisterClass *RC,
91 const TargetRegisterInfo *TRI) const;
Owen Andersonf6372aa2008-01-01 21:11:32 +000092
Owen Andersonf6372aa2008-01-01 21:11:32 +000093 virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
94 MachineBasicBlock::iterator MBBI,
95 unsigned DestReg, int FrameIndex,
Evan Cheng746ad692010-05-06 19:06:44 +000096 const TargetRegisterClass *RC,
97 const TargetRegisterInfo *TRI) const;
Owen Andersonf6372aa2008-01-01 21:11:32 +000098
Akira Hatanaka564f6902012-05-25 20:52:52 +000099 virtual bool expandPostRAPseudo(MachineBasicBlock::iterator MI) const;
100
Akira Hatanakac4f24eb2011-07-01 01:04:43 +0000101 virtual MachineInstr* emitFrameIndexDebugValue(MachineFunction &MF,
102 int FrameIx, uint64_t Offset,
103 const MDNode *MDPtr,
104 DebugLoc DL) const;
105
Owen Anderson44eb65c2008-08-14 22:49:33 +0000106 virtual
107 bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
Bruno Cardoso Lopes0b2cd892007-08-18 01:59:45 +0000108
109 /// Insert nop instruction when hazard condition is found
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000110 virtual void insertNoop(MachineBasicBlock &MBB,
Bruno Cardoso Lopes0b2cd892007-08-18 01:59:45 +0000111 MachineBasicBlock::iterator MI) const;
Akira Hatanakad4b48b22012-06-14 01:16:45 +0000112
113 /// Return the number of bytes of code the specified instruction may be.
114 unsigned GetInstSizeInBytes(const MachineInstr *MI) const;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000115};
116
Akira Hatanakad4b48b22012-06-14 01:16:45 +0000117namespace Mips {
118 /// GetOppositeBranchOpc - Return the inverse of the specified
119 /// opcode, e.g. turning BEQ to BNE.
120 unsigned GetOppositeBranchOpc(unsigned Opc);
121
122 /// Emit a series of instructions to load an immediate. All instructions
123 /// except for the last one are emitted. The function returns the number of
124 /// MachineInstrs generated. The opcode-immediate pair of the last
125 /// instruction is returned in LastInst, if it is not 0.
126 unsigned
127 loadImmediate(int64_t Imm, bool IsN64, const TargetInstrInfo &TII,
128 MachineBasicBlock& MBB, MachineBasicBlock::iterator II,
129 DebugLoc DL, bool LastInstrIsADDiu,
130 MipsAnalyzeImmediate::Inst *LastInst);
131}
132
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000133}
134
135#endif