blob: 45895355e1a54db0fc5a54e8e9affe15b47d184b [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//
Sasa Stankovic7b061a42014-04-30 15:06:25 +000012// FIXME: We need to override TargetInstrInfo::getInlineAsmLength method in
13// order for MipsLongBranch pass to work correctly when the code has inline
14// assembly. The returned value doesn't have to be the asm instruction's exact
15// size in bytes; MipsLongBranch only expects it to be the correct upper bound.
Akira Hatanakae2489122011-04-15 21:51:11 +000016//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000017
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000018#ifndef LLVM_LIB_TARGET_MIPS_MIPSINSTRINFO_H
19#define LLVM_LIB_TARGET_MIPS_MIPSINSTRINFO_H
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000020
21#include "Mips.h"
Akira Hatanakaacd1a7d2012-06-14 01:16:45 +000022#include "MipsAnalyzeImmediate.h"
Craig Topperb25fda92012-03-17 18:46:09 +000023#include "MipsRegisterInfo.h"
Akira Hatanaka310e26a2013-05-13 17:57:42 +000024#include "llvm/CodeGen/MachineInstrBuilder.h"
Torok Edwin56d06592009-07-11 20:10:48 +000025#include "llvm/Support/ErrorHandling.h"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000026#include "llvm/Target/TargetInstrInfo.h"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000027
Evan Cheng703a0fb2011-07-01 17:57:27 +000028#define GET_INSTRINFO_HEADER
29#include "MipsGenInstrInfo.inc"
30
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000031namespace llvm {
Eric Christophera20c3cf2015-03-12 05:43:57 +000032class MipsSubtarget;
Evan Cheng703a0fb2011-07-01 17:57:27 +000033class MipsInstrInfo : public MipsGenInstrInfo {
Juergen Ributzkad12ccbd2013-11-19 00:57:56 +000034 virtual void anchor();
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000035protected:
Eric Christopher675cb4d2014-07-18 23:25:00 +000036 const MipsSubtarget &Subtarget;
Akira Hatanaka5d5e0d82011-12-12 22:39:35 +000037 unsigned UncondBrOpc;
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000038
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000039public:
Akira Hatanaka7320b232013-03-01 01:10:17 +000040 enum BranchType {
41 BT_None, // Couldn't analyze branch.
42 BT_NoBranch, // No branches found.
43 BT_Uncond, // One unconditional branch.
44 BT_Cond, // One conditional branch.
45 BT_CondUncond, // A conditional branch followed by an unconditional branch.
46 BT_Indirect // One indirct branch.
47 };
48
Eric Christopher675cb4d2014-07-18 23:25:00 +000049 explicit MipsInstrInfo(const MipsSubtarget &STI, unsigned UncondBrOpc);
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000050
Eric Christopher675cb4d2014-07-18 23:25:00 +000051 static const MipsInstrInfo *create(MipsSubtarget &STI);
Akira Hatanakafab89292012-08-02 18:21:47 +000052
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000053 /// Branch Analysis
Craig Topper56c590a2014-04-29 07:58:02 +000054 bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
55 MachineBasicBlock *&FBB,
56 SmallVectorImpl<MachineOperand> &Cond,
57 bool AllowModify) const override;
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000058
Craig Topper56c590a2014-04-29 07:58:02 +000059 unsigned RemoveBranch(MachineBasicBlock &MBB) const override;
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000060
Craig Topper56c590a2014-04-29 07:58:02 +000061 unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
62 MachineBasicBlock *FBB,
63 const SmallVectorImpl<MachineOperand> &Cond,
64 DebugLoc DL) const override;
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000065
Craig Topper56c590a2014-04-29 07:58:02 +000066 bool
67 ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const override;
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000068
Akira Hatanaka7320b232013-03-01 01:10:17 +000069 BranchType AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
70 MachineBasicBlock *&FBB,
71 SmallVectorImpl<MachineOperand> &Cond,
72 bool AllowModify,
73 SmallVectorImpl<MachineInstr*> &BranchInstrs) const;
74
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000075 /// Insert nop instruction when hazard condition is found
Craig Topper56c590a2014-04-29 07:58:02 +000076 void insertNoop(MachineBasicBlock &MBB,
77 MachineBasicBlock::iterator MI) const override;
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000078
79 /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As
80 /// such, whenever a client has an instance of instruction info, it should
81 /// always be able to get register info as well (through this method).
82 ///
Akira Hatanakacb37e132012-07-31 23:41:32 +000083 virtual const MipsRegisterInfo &getRegisterInfo() const = 0;
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000084
Akira Hatanaka067d8152013-05-13 17:43:19 +000085 virtual unsigned getOppositeBranchOpc(unsigned Opc) const = 0;
Akira Hatanakaacd1a7d2012-06-14 01:16:45 +000086
87 /// Return the number of bytes of code the specified instruction may be.
88 unsigned GetInstSizeInBytes(const MachineInstr *MI) const;
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000089
Craig Topper56c590a2014-04-29 07:58:02 +000090 void storeRegToStackSlot(MachineBasicBlock &MBB,
91 MachineBasicBlock::iterator MBBI,
92 unsigned SrcReg, bool isKill, int FrameIndex,
93 const TargetRegisterClass *RC,
94 const TargetRegisterInfo *TRI) const override {
Akira Hatanaka465facca2013-03-29 02:14:12 +000095 storeRegToStack(MBB, MBBI, SrcReg, isKill, FrameIndex, RC, TRI, 0);
96 }
97
Craig Topper56c590a2014-04-29 07:58:02 +000098 void loadRegFromStackSlot(MachineBasicBlock &MBB,
99 MachineBasicBlock::iterator MBBI,
100 unsigned DestReg, int FrameIndex,
101 const TargetRegisterClass *RC,
102 const TargetRegisterInfo *TRI) const override {
Akira Hatanaka465facca2013-03-29 02:14:12 +0000103 loadRegFromStack(MBB, MBBI, DestReg, FrameIndex, RC, TRI, 0);
104 }
105
106 virtual void storeRegToStack(MachineBasicBlock &MBB,
107 MachineBasicBlock::iterator MI,
108 unsigned SrcReg, bool isKill, int FrameIndex,
109 const TargetRegisterClass *RC,
110 const TargetRegisterInfo *TRI,
111 int64_t Offset) const = 0;
112
113 virtual void loadRegFromStack(MachineBasicBlock &MBB,
114 MachineBasicBlock::iterator MI,
115 unsigned DestReg, int FrameIndex,
116 const TargetRegisterClass *RC,
117 const TargetRegisterInfo *TRI,
118 int64_t Offset) const = 0;
119
Vasileios Kalintiris6d687782015-04-02 10:42:44 +0000120 virtual void adjustStackPtr(unsigned SP, int64_t Amount,
121 MachineBasicBlock &MBB,
122 MachineBasicBlock::iterator I) const = 0;
123
Akira Hatanaka310e26a2013-05-13 17:57:42 +0000124 /// Create an instruction which has the same operands and memory operands
125 /// as MI but has a new opcode.
126 MachineInstrBuilder genInstrWithNewOpc(unsigned NewOpc,
127 MachineBasicBlock::iterator I) const;
128
Akira Hatanakab7fa3c92012-07-31 21:49:49 +0000129protected:
130 bool isZeroImm(const MachineOperand &op) const;
131
132 MachineMemOperand *GetMemOperand(MachineBasicBlock &MBB, int FI,
133 unsigned Flag) const;
134
135private:
Akira Hatanaka067d8152013-05-13 17:43:19 +0000136 virtual unsigned getAnalyzableBrOpc(unsigned Opc) const = 0;
Akira Hatanakab7fa3c92012-07-31 21:49:49 +0000137
138 void AnalyzeCondBr(const MachineInstr *Inst, unsigned Opc,
139 MachineBasicBlock *&BB,
140 SmallVectorImpl<MachineOperand> &Cond) const;
141
142 void BuildCondBr(MachineBasicBlock &MBB, MachineBasicBlock *TBB, DebugLoc DL,
143 const SmallVectorImpl<MachineOperand>& Cond) const;
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000144};
145
Akira Hatanakafab89292012-08-02 18:21:47 +0000146/// Create MipsInstrInfo objects.
Eric Christopher675cb4d2014-07-18 23:25:00 +0000147const MipsInstrInfo *createMips16InstrInfo(const MipsSubtarget &STI);
148const MipsInstrInfo *createMipsSEInstrInfo(const MipsSubtarget &STI);
Akira Hatanakafab89292012-08-02 18:21:47 +0000149
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000150}
151
152#endif