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