blob: d9ac961cd33c897c9dc43308db9f83b238014a24 [file] [log] [blame]
Jia Liuf54f60f2012-02-28 07:46:26 +00001//===-- MipsInstrInfo.h - Mips Instruction Information ----------*- C++ -*-===//
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-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 Lopes35e43c42007-06-06 07:42:06 +00007//
Akira Hatanakae2489122011-04-15 21:51:11 +00008//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +00009//
10// This file contains the Mips implementation of the TargetInstrInfo class.
11//
Akira Hatanakae2489122011-04-15 21:51:11 +000012//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000013
14#ifndef MIPSINSTRUCTIONINFO_H
15#define MIPSINSTRUCTIONINFO_H
16
17#include "Mips.h"
Akira Hatanakaacd1a7d2012-06-14 01:16:45 +000018#include "MipsAnalyzeImmediate.h"
Craig Topperb25fda92012-03-17 18:46:09 +000019#include "MipsRegisterInfo.h"
Akira Hatanaka310e26a2013-05-13 17:57:42 +000020#include "llvm/CodeGen/MachineInstrBuilder.h"
Torok Edwin56d06592009-07-11 20:10:48 +000021#include "llvm/Support/ErrorHandling.h"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000022#include "llvm/Target/TargetInstrInfo.h"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000023
Evan Cheng703a0fb2011-07-01 17:57:27 +000024#define GET_INSTRINFO_HEADER
25#include "MipsGenInstrInfo.inc"
26
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000027namespace llvm {
28
Evan Cheng703a0fb2011-07-01 17:57:27 +000029class MipsInstrInfo : public MipsGenInstrInfo {
Juergen Ributzkad12ccbd2013-11-19 00:57:56 +000030 virtual void anchor();
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000031protected:
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000032 MipsTargetMachine &TM;
Akira Hatanaka5d5e0d82011-12-12 22:39:35 +000033 unsigned UncondBrOpc;
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000034
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000035public:
Akira Hatanaka7320b232013-03-01 01:10:17 +000036 enum BranchType {
37 BT_None, // Couldn't analyze branch.
38 BT_NoBranch, // No branches found.
39 BT_Uncond, // One unconditional branch.
40 BT_Cond, // One conditional branch.
41 BT_CondUncond, // A conditional branch followed by an unconditional branch.
42 BT_Indirect // One indirct branch.
43 };
44
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000045 explicit MipsInstrInfo(MipsTargetMachine &TM, unsigned UncondBrOpc);
46
Akira Hatanakafab89292012-08-02 18:21:47 +000047 static const MipsInstrInfo *create(MipsTargetMachine &TM);
48
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000049 /// Branch Analysis
50 virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
51 MachineBasicBlock *&FBB,
52 SmallVectorImpl<MachineOperand> &Cond,
53 bool AllowModify) const;
54
55 virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
56
57 virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
58 MachineBasicBlock *FBB,
59 const SmallVectorImpl<MachineOperand> &Cond,
60 DebugLoc DL) const;
61
62 virtual
63 bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
64
Akira Hatanaka7320b232013-03-01 01:10:17 +000065 BranchType AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
66 MachineBasicBlock *&FBB,
67 SmallVectorImpl<MachineOperand> &Cond,
68 bool AllowModify,
69 SmallVectorImpl<MachineInstr*> &BranchInstrs) const;
70
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000071 /// Insert nop instruction when hazard condition is found
72 virtual void insertNoop(MachineBasicBlock &MBB,
73 MachineBasicBlock::iterator MI) const;
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000074
75 /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As
76 /// such, whenever a client has an instance of instruction info, it should
77 /// always be able to get register info as well (through this method).
78 ///
Akira Hatanakacb37e132012-07-31 23:41:32 +000079 virtual const MipsRegisterInfo &getRegisterInfo() const = 0;
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000080
Akira Hatanaka067d8152013-05-13 17:43:19 +000081 virtual unsigned getOppositeBranchOpc(unsigned Opc) const = 0;
Akira Hatanakaacd1a7d2012-06-14 01:16:45 +000082
83 /// Return the number of bytes of code the specified instruction may be.
84 unsigned GetInstSizeInBytes(const MachineInstr *MI) const;
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000085
Akira Hatanaka465facca2013-03-29 02:14:12 +000086 virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
87 MachineBasicBlock::iterator MBBI,
88 unsigned SrcReg, bool isKill, int FrameIndex,
89 const TargetRegisterClass *RC,
90 const TargetRegisterInfo *TRI) const {
91 storeRegToStack(MBB, MBBI, SrcReg, isKill, FrameIndex, RC, TRI, 0);
92 }
93
94 virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
95 MachineBasicBlock::iterator MBBI,
96 unsigned DestReg, int FrameIndex,
97 const TargetRegisterClass *RC,
98 const TargetRegisterInfo *TRI) const {
99 loadRegFromStack(MBB, MBBI, DestReg, FrameIndex, RC, TRI, 0);
100 }
101
102 virtual void storeRegToStack(MachineBasicBlock &MBB,
103 MachineBasicBlock::iterator MI,
104 unsigned SrcReg, bool isKill, int FrameIndex,
105 const TargetRegisterClass *RC,
106 const TargetRegisterInfo *TRI,
107 int64_t Offset) const = 0;
108
109 virtual void loadRegFromStack(MachineBasicBlock &MBB,
110 MachineBasicBlock::iterator MI,
111 unsigned DestReg, int FrameIndex,
112 const TargetRegisterClass *RC,
113 const TargetRegisterInfo *TRI,
114 int64_t Offset) const = 0;
115
Akira Hatanaka310e26a2013-05-13 17:57:42 +0000116 /// Create an instruction which has the same operands and memory operands
117 /// as MI but has a new opcode.
118 MachineInstrBuilder genInstrWithNewOpc(unsigned NewOpc,
119 MachineBasicBlock::iterator I) const;
120
Akira Hatanakab7fa3c92012-07-31 21:49:49 +0000121protected:
122 bool isZeroImm(const MachineOperand &op) const;
123
124 MachineMemOperand *GetMemOperand(MachineBasicBlock &MBB, int FI,
125 unsigned Flag) const;
126
127private:
Akira Hatanaka067d8152013-05-13 17:43:19 +0000128 virtual unsigned getAnalyzableBrOpc(unsigned Opc) const = 0;
Akira Hatanakab7fa3c92012-07-31 21:49:49 +0000129
130 void AnalyzeCondBr(const MachineInstr *Inst, unsigned Opc,
131 MachineBasicBlock *&BB,
132 SmallVectorImpl<MachineOperand> &Cond) const;
133
134 void BuildCondBr(MachineBasicBlock &MBB, MachineBasicBlock *TBB, DebugLoc DL,
135 const SmallVectorImpl<MachineOperand>& Cond) const;
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000136};
137
Akira Hatanakafab89292012-08-02 18:21:47 +0000138/// Create MipsInstrInfo objects.
139const MipsInstrInfo *createMips16InstrInfo(MipsTargetMachine &TM);
140const MipsInstrInfo *createMipsSEInstrInfo(MipsTargetMachine &TM);
141
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000142}
143
144#endif