blob: 7a0065b6341a7e65878c938f8d832967739a70e9 [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"
Torok Edwin56d06592009-07-11 20:10:48 +000020#include "llvm/Support/ErrorHandling.h"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000021#include "llvm/Target/TargetInstrInfo.h"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000022
Evan Cheng703a0fb2011-07-01 17:57:27 +000023#define GET_INSTRINFO_HEADER
24#include "MipsGenInstrInfo.inc"
25
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000026namespace llvm {
27
Evan Cheng703a0fb2011-07-01 17:57:27 +000028class MipsInstrInfo : public MipsGenInstrInfo {
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000029 MipsTargetMachine &TM;
Akira Hatanakae6ced5b2011-10-11 00:37:28 +000030 bool IsN64;
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000031 const MipsRegisterInfo RI;
Akira Hatanaka5d5e0d82011-12-12 22:39:35 +000032 unsigned UncondBrOpc;
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000033public:
Dan Gohmanc60c67f2008-03-25 22:06:05 +000034 explicit MipsInstrInfo(MipsTargetMachine &TM);
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000035
36 /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As
37 /// such, whenever a client has an instance of instruction info, it should
38 /// always be able to get register info as well (through this method).
39 ///
Akira Hatanaka9c6028f2011-07-07 23:56:50 +000040 virtual const MipsRegisterInfo &getRegisterInfo() const;
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000041
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000042 /// isLoadFromStackSlot - If the specified machine instruction is a direct
43 /// load from a stack slot, return the virtual or physical register number of
44 /// the destination along with the FrameIndex of the loaded stack slot. If
45 /// not, return 0. This predicate must return 0 if the instruction has
46 /// any side effects other than loading from the stack slot.
Dan Gohman0b273252008-11-18 19:49:32 +000047 virtual unsigned isLoadFromStackSlot(const MachineInstr *MI,
48 int &FrameIndex) const;
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +000049
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000050 /// isStoreToStackSlot - If the specified machine instruction is a direct
51 /// store to a stack slot, return the virtual or physical register number of
52 /// the source reg along with the FrameIndex of the loaded stack slot. If
53 /// not, return 0. This predicate must return 0 if the instruction has
54 /// any side effects other than storing to the stack slot.
Dan Gohman0b273252008-11-18 19:49:32 +000055 virtual unsigned isStoreToStackSlot(const MachineInstr *MI,
56 int &FrameIndex) const;
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +000057
Bruno Cardoso Lopes0c530632007-08-18 01:59:45 +000058 /// Branch Analysis
59 virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
60 MachineBasicBlock *&FBB,
Evan Cheng64dfcac2009-02-09 07:14:22 +000061 SmallVectorImpl<MachineOperand> &Cond,
62 bool AllowModify) const;
Bruno Cardoso Lopes0c530632007-08-18 01:59:45 +000063 virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
Akira Hatanaka93f898f2011-04-01 17:39:08 +000064
65private:
66 void BuildCondBr(MachineBasicBlock &MBB, MachineBasicBlock *TBB, DebugLoc DL,
67 const SmallVectorImpl<MachineOperand>& Cond) const;
Akira Hatanakad0ac2c92012-05-25 20:52:52 +000068 void ExpandExtractElementF64(MachineBasicBlock &MBB,
69 MachineBasicBlock::iterator I) const;
70 void ExpandBuildPairF64(MachineBasicBlock &MBB,
71 MachineBasicBlock::iterator I) const;
Akira Hatanaka93f898f2011-04-01 17:39:08 +000072
73public:
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000074 virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
Bruno Cardoso Lopes0c530632007-08-18 01:59:45 +000075 MachineBasicBlock *FBB,
Stuart Hastings0125b642010-06-17 22:43:56 +000076 const SmallVectorImpl<MachineOperand> &Cond,
77 DebugLoc DL) const;
Jakob Stoklund Olesen7002c312010-07-11 01:08:31 +000078 virtual void copyPhysReg(MachineBasicBlock &MBB,
79 MachineBasicBlock::iterator MI, DebugLoc DL,
80 unsigned DestReg, unsigned SrcReg,
81 bool KillSrc) const;
Owen Andersoneee14602008-01-01 21:11:32 +000082 virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
83 MachineBasicBlock::iterator MBBI,
Akira Hatanakae2489122011-04-15 21:51:11 +000084 unsigned SrcReg, bool isKill, int FrameIndex,
Evan Chengefb126a2010-05-06 19:06:44 +000085 const TargetRegisterClass *RC,
86 const TargetRegisterInfo *TRI) const;
Owen Andersoneee14602008-01-01 21:11:32 +000087
Owen Andersoneee14602008-01-01 21:11:32 +000088 virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
89 MachineBasicBlock::iterator MBBI,
90 unsigned DestReg, int FrameIndex,
Evan Chengefb126a2010-05-06 19:06:44 +000091 const TargetRegisterClass *RC,
92 const TargetRegisterInfo *TRI) const;
Owen Andersoneee14602008-01-01 21:11:32 +000093
Akira Hatanakad0ac2c92012-05-25 20:52:52 +000094 virtual bool expandPostRAPseudo(MachineBasicBlock::iterator MI) const;
95
Akira Hatanakaf2bcad92011-07-01 01:04:43 +000096 virtual MachineInstr* emitFrameIndexDebugValue(MachineFunction &MF,
97 int FrameIx, uint64_t Offset,
98 const MDNode *MDPtr,
99 DebugLoc DL) const;
100
Owen Anderson4f6bf042008-08-14 22:49:33 +0000101 virtual
102 bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
Bruno Cardoso Lopes0c530632007-08-18 01:59:45 +0000103
104 /// Insert nop instruction when hazard condition is found
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000105 virtual void insertNoop(MachineBasicBlock &MBB,
Bruno Cardoso Lopes0c530632007-08-18 01:59:45 +0000106 MachineBasicBlock::iterator MI) const;
Akira Hatanakaacd1a7d2012-06-14 01:16:45 +0000107
108 /// Return the number of bytes of code the specified instruction may be.
109 unsigned GetInstSizeInBytes(const MachineInstr *MI) const;
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000110};
111
Akira Hatanakaacd1a7d2012-06-14 01:16:45 +0000112namespace Mips {
113 /// GetOppositeBranchOpc - Return the inverse of the specified
114 /// opcode, e.g. turning BEQ to BNE.
115 unsigned GetOppositeBranchOpc(unsigned Opc);
116
117 /// Emit a series of instructions to load an immediate. All instructions
118 /// except for the last one are emitted. The function returns the number of
119 /// MachineInstrs generated. The opcode-immediate pair of the last
120 /// instruction is returned in LastInst, if it is not 0.
121 unsigned
122 loadImmediate(int64_t Imm, bool IsN64, const TargetInstrInfo &TII,
123 MachineBasicBlock& MBB, MachineBasicBlock::iterator II,
124 DebugLoc DL, bool LastInstrIsADDiu,
125 MipsAnalyzeImmediate::Inst *LastInst);
126}
127
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000128}
129
130#endif