blob: 7d562590624871f028083b8777a321e0226d3da7 [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 Hatanaka0bc1adb2012-07-31 21:49:49 +000034 explicit MipsInstrInfo(MipsTargetMachine &TM, unsigned UncondBrOpc);
35
Akira Hatanakaaf266262012-08-02 18:21:47 +000036 static const MipsInstrInfo *create(MipsTargetMachine &TM);
37
Akira Hatanaka0bc1adb2012-07-31 21:49:49 +000038 /// Branch Analysis
39 virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
40 MachineBasicBlock *&FBB,
41 SmallVectorImpl<MachineOperand> &Cond,
42 bool AllowModify) const;
43
44 virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
45
46 virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
47 MachineBasicBlock *FBB,
48 const SmallVectorImpl<MachineOperand> &Cond,
49 DebugLoc DL) const;
50
51 virtual
52 bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
53
54 virtual MachineInstr* emitFrameIndexDebugValue(MachineFunction &MF,
55 int FrameIx, uint64_t Offset,
56 const MDNode *MDPtr,
57 DebugLoc DL) const;
58
59 /// Insert nop instruction when hazard condition is found
60 virtual void insertNoop(MachineBasicBlock &MBB,
61 MachineBasicBlock::iterator MI) const;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000062
63 /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As
64 /// such, whenever a client has an instance of instruction info, it should
65 /// always be able to get register info as well (through this method).
66 ///
Akira Hatanaka85890102012-07-31 23:41:32 +000067 virtual const MipsRegisterInfo &getRegisterInfo() const = 0;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000068
Akira Hatanaka0bc1adb2012-07-31 21:49:49 +000069 virtual unsigned GetOppositeBranchOpc(unsigned Opc) const = 0;
Akira Hatanakad4b48b22012-06-14 01:16:45 +000070
71 /// Return the number of bytes of code the specified instruction may be.
72 unsigned GetInstSizeInBytes(const MachineInstr *MI) const;
Akira Hatanaka0bc1adb2012-07-31 21:49:49 +000073
74protected:
75 bool isZeroImm(const MachineOperand &op) const;
76
77 MachineMemOperand *GetMemOperand(MachineBasicBlock &MBB, int FI,
78 unsigned Flag) const;
79
80private:
81 virtual unsigned GetAnalyzableBrOpc(unsigned Opc) const = 0;
82
83 void AnalyzeCondBr(const MachineInstr *Inst, unsigned Opc,
84 MachineBasicBlock *&BB,
85 SmallVectorImpl<MachineOperand> &Cond) const;
86
87 void BuildCondBr(MachineBasicBlock &MBB, MachineBasicBlock *TBB, DebugLoc DL,
88 const SmallVectorImpl<MachineOperand>& Cond) const;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000089};
90
Akira Hatanakad4b48b22012-06-14 01:16:45 +000091namespace Mips {
Akira Hatanakad4b48b22012-06-14 01:16:45 +000092 /// Emit a series of instructions to load an immediate. All instructions
93 /// except for the last one are emitted. The function returns the number of
94 /// MachineInstrs generated. The opcode-immediate pair of the last
95 /// instruction is returned in LastInst, if it is not 0.
96 unsigned
97 loadImmediate(int64_t Imm, bool IsN64, const TargetInstrInfo &TII,
98 MachineBasicBlock& MBB, MachineBasicBlock::iterator II,
99 DebugLoc DL, bool LastInstrIsADDiu,
100 MipsAnalyzeImmediate::Inst *LastInst);
101}
102
Akira Hatanakaaf266262012-08-02 18:21:47 +0000103/// Create MipsInstrInfo objects.
104const MipsInstrInfo *createMips16InstrInfo(MipsTargetMachine &TM);
105const MipsInstrInfo *createMipsSEInstrInfo(MipsTargetMachine &TM);
106
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000107}
108
109#endif