blob: b6480ef337618aae326b3f4f3205386eeab255db [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 {
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000030protected:
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000031 MipsTargetMachine &TM;
Akira Hatanaka5d5e0d82011-12-12 22:39:35 +000032 unsigned UncondBrOpc;
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000033
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000034public:
Akira Hatanaka7320b232013-03-01 01:10:17 +000035 enum BranchType {
36 BT_None, // Couldn't analyze branch.
37 BT_NoBranch, // No branches found.
38 BT_Uncond, // One unconditional branch.
39 BT_Cond, // One conditional branch.
40 BT_CondUncond, // A conditional branch followed by an unconditional branch.
41 BT_Indirect // One indirct branch.
42 };
43
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000044 explicit MipsInstrInfo(MipsTargetMachine &TM, unsigned UncondBrOpc);
45
Akira Hatanakafab89292012-08-02 18:21:47 +000046 static const MipsInstrInfo *create(MipsTargetMachine &TM);
47
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000048 /// Branch Analysis
49 virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
50 MachineBasicBlock *&FBB,
51 SmallVectorImpl<MachineOperand> &Cond,
52 bool AllowModify) const;
53
54 virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
55
56 virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
57 MachineBasicBlock *FBB,
58 const SmallVectorImpl<MachineOperand> &Cond,
59 DebugLoc DL) const;
60
61 virtual
62 bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
63
Akira Hatanaka7320b232013-03-01 01:10:17 +000064 BranchType AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
65 MachineBasicBlock *&FBB,
66 SmallVectorImpl<MachineOperand> &Cond,
67 bool AllowModify,
68 SmallVectorImpl<MachineInstr*> &BranchInstrs) const;
69
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000070 /// Insert nop instruction when hazard condition is found
71 virtual void insertNoop(MachineBasicBlock &MBB,
72 MachineBasicBlock::iterator MI) const;
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000073
74 /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As
75 /// such, whenever a client has an instance of instruction info, it should
76 /// always be able to get register info as well (through this method).
77 ///
Akira Hatanakacb37e132012-07-31 23:41:32 +000078 virtual const MipsRegisterInfo &getRegisterInfo() const = 0;
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000079
Akira Hatanaka067d8152013-05-13 17:43:19 +000080 virtual unsigned getOppositeBranchOpc(unsigned Opc) const = 0;
Akira Hatanakaacd1a7d2012-06-14 01:16:45 +000081
82 /// Return the number of bytes of code the specified instruction may be.
83 unsigned GetInstSizeInBytes(const MachineInstr *MI) const;
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000084
Akira Hatanaka465facca2013-03-29 02:14:12 +000085 virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
86 MachineBasicBlock::iterator MBBI,
87 unsigned SrcReg, bool isKill, int FrameIndex,
88 const TargetRegisterClass *RC,
89 const TargetRegisterInfo *TRI) const {
90 storeRegToStack(MBB, MBBI, SrcReg, isKill, FrameIndex, RC, TRI, 0);
91 }
92
93 virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
94 MachineBasicBlock::iterator MBBI,
95 unsigned DestReg, int FrameIndex,
96 const TargetRegisterClass *RC,
97 const TargetRegisterInfo *TRI) const {
98 loadRegFromStack(MBB, MBBI, DestReg, FrameIndex, RC, TRI, 0);
99 }
100
101 virtual void storeRegToStack(MachineBasicBlock &MBB,
102 MachineBasicBlock::iterator MI,
103 unsigned SrcReg, bool isKill, int FrameIndex,
104 const TargetRegisterClass *RC,
105 const TargetRegisterInfo *TRI,
106 int64_t Offset) const = 0;
107
108 virtual void loadRegFromStack(MachineBasicBlock &MBB,
109 MachineBasicBlock::iterator MI,
110 unsigned DestReg, int FrameIndex,
111 const TargetRegisterClass *RC,
112 const TargetRegisterInfo *TRI,
113 int64_t Offset) const = 0;
114
Akira Hatanaka310e26a2013-05-13 17:57:42 +0000115 /// Create an instruction which has the same operands and memory operands
116 /// as MI but has a new opcode.
117 MachineInstrBuilder genInstrWithNewOpc(unsigned NewOpc,
118 MachineBasicBlock::iterator I) const;
119
Akira Hatanakab7fa3c92012-07-31 21:49:49 +0000120protected:
121 bool isZeroImm(const MachineOperand &op) const;
122
123 MachineMemOperand *GetMemOperand(MachineBasicBlock &MBB, int FI,
124 unsigned Flag) const;
125
126private:
Akira Hatanaka067d8152013-05-13 17:43:19 +0000127 virtual unsigned getAnalyzableBrOpc(unsigned Opc) const = 0;
Akira Hatanakab7fa3c92012-07-31 21:49:49 +0000128
129 void AnalyzeCondBr(const MachineInstr *Inst, unsigned Opc,
130 MachineBasicBlock *&BB,
131 SmallVectorImpl<MachineOperand> &Cond) const;
132
133 void BuildCondBr(MachineBasicBlock &MBB, MachineBasicBlock *TBB, DebugLoc DL,
134 const SmallVectorImpl<MachineOperand>& Cond) const;
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000135};
136
Akira Hatanakafab89292012-08-02 18:21:47 +0000137/// Create MipsInstrInfo objects.
138const MipsInstrInfo *createMips16InstrInfo(MipsTargetMachine &TM);
139const MipsInstrInfo *createMipsSEInstrInfo(MipsTargetMachine &TM);
140
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000141}
142
143#endif