blob: 3cd9088140b9218992a92f598cbf81fb49bb3bc8 [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 {
Akira Hatanaka0bc1adb2012-07-31 21:49:49 +000029protected:
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000030 MipsTargetMachine &TM;
Akira Hatanaka6e55ff52011-12-12 22:39:35 +000031 unsigned UncondBrOpc;
Akira Hatanaka0bc1adb2012-07-31 21:49:49 +000032
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000033public:
Akira Hatanakad0a4b602013-03-01 01:10:17 +000034 enum BranchType {
35 BT_None, // Couldn't analyze branch.
36 BT_NoBranch, // No branches found.
37 BT_Uncond, // One unconditional branch.
38 BT_Cond, // One conditional branch.
39 BT_CondUncond, // A conditional branch followed by an unconditional branch.
40 BT_Indirect // One indirct branch.
41 };
42
Akira Hatanaka0bc1adb2012-07-31 21:49:49 +000043 explicit MipsInstrInfo(MipsTargetMachine &TM, unsigned UncondBrOpc);
44
Akira Hatanakaaf266262012-08-02 18:21:47 +000045 static const MipsInstrInfo *create(MipsTargetMachine &TM);
46
Akira Hatanaka0bc1adb2012-07-31 21:49:49 +000047 /// Branch Analysis
48 virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
49 MachineBasicBlock *&FBB,
50 SmallVectorImpl<MachineOperand> &Cond,
51 bool AllowModify) const;
52
53 virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
54
55 virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
56 MachineBasicBlock *FBB,
57 const SmallVectorImpl<MachineOperand> &Cond,
58 DebugLoc DL) const;
59
60 virtual
61 bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
62
Akira Hatanakad0a4b602013-03-01 01:10:17 +000063 BranchType AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
64 MachineBasicBlock *&FBB,
65 SmallVectorImpl<MachineOperand> &Cond,
66 bool AllowModify,
67 SmallVectorImpl<MachineInstr*> &BranchInstrs) const;
68
Akira Hatanaka0bc1adb2012-07-31 21:49:49 +000069 virtual MachineInstr* emitFrameIndexDebugValue(MachineFunction &MF,
70 int FrameIx, uint64_t Offset,
71 const MDNode *MDPtr,
72 DebugLoc DL) const;
73
74 /// Insert nop instruction when hazard condition is found
75 virtual void insertNoop(MachineBasicBlock &MBB,
76 MachineBasicBlock::iterator MI) const;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000077
78 /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As
79 /// such, whenever a client has an instance of instruction info, it should
80 /// always be able to get register info as well (through this method).
81 ///
Akira Hatanaka85890102012-07-31 23:41:32 +000082 virtual const MipsRegisterInfo &getRegisterInfo() const = 0;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000083
Akira Hatanaka0bc1adb2012-07-31 21:49:49 +000084 virtual unsigned GetOppositeBranchOpc(unsigned Opc) const = 0;
Akira Hatanakad4b48b22012-06-14 01:16:45 +000085
86 /// Return the number of bytes of code the specified instruction may be.
87 unsigned GetInstSizeInBytes(const MachineInstr *MI) const;
Akira Hatanaka0bc1adb2012-07-31 21:49:49 +000088
89protected:
90 bool isZeroImm(const MachineOperand &op) const;
91
92 MachineMemOperand *GetMemOperand(MachineBasicBlock &MBB, int FI,
93 unsigned Flag) const;
94
95private:
96 virtual unsigned GetAnalyzableBrOpc(unsigned Opc) const = 0;
97
98 void AnalyzeCondBr(const MachineInstr *Inst, unsigned Opc,
99 MachineBasicBlock *&BB,
100 SmallVectorImpl<MachineOperand> &Cond) const;
101
102 void BuildCondBr(MachineBasicBlock &MBB, MachineBasicBlock *TBB, DebugLoc DL,
103 const SmallVectorImpl<MachineOperand>& Cond) const;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000104};
105
Akira Hatanakaaf266262012-08-02 18:21:47 +0000106/// Create MipsInstrInfo objects.
107const MipsInstrInfo *createMips16InstrInfo(MipsTargetMachine &TM);
108const MipsInstrInfo *createMipsSEInstrInfo(MipsTargetMachine &TM);
109
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000110}
111
112#endif