blob: 8fa30529b8d6a822e086ff36a2a240a435752a1a [file] [log] [blame]
Akira Hatanakae2489122011-04-15 21:51:11 +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"
Torok Edwin56d06592009-07-11 20:10:48 +000018#include "llvm/Support/ErrorHandling.h"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000019#include "llvm/Target/TargetInstrInfo.h"
20#include "MipsRegisterInfo.h"
21
Evan Cheng703a0fb2011-07-01 17:57:27 +000022#define GET_INSTRINFO_HEADER
23#include "MipsGenInstrInfo.inc"
24
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000025namespace llvm {
26
Bruno Cardoso Lopes0c530632007-08-18 01:59:45 +000027namespace Mips {
Akira Hatanaka93f898f2011-04-01 17:39:08 +000028 /// GetOppositeBranchOpc - Return the inverse of the specified
29 /// opcode, e.g. turning BEQ to BNE.
30 unsigned GetOppositeBranchOpc(unsigned Opc);
Bruno Cardoso Lopes0c530632007-08-18 01:59:45 +000031}
32
Evan Cheng703a0fb2011-07-01 17:57:27 +000033class MipsInstrInfo : public MipsGenInstrInfo {
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000034 MipsTargetMachine &TM;
Akira Hatanakae6ced5b2011-10-11 00:37:28 +000035 bool IsN64;
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000036 const MipsRegisterInfo RI;
37public:
Dan Gohmanc60c67f2008-03-25 22:06:05 +000038 explicit MipsInstrInfo(MipsTargetMachine &TM);
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000039
40 /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As
41 /// such, whenever a client has an instance of instruction info, it should
42 /// always be able to get register info as well (through this method).
43 ///
Akira Hatanaka9c6028f2011-07-07 23:56:50 +000044 virtual const MipsRegisterInfo &getRegisterInfo() const;
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000045
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000046 /// isLoadFromStackSlot - If the specified machine instruction is a direct
47 /// load from a stack slot, return the virtual or physical register number of
48 /// the destination along with the FrameIndex of the loaded stack slot. If
49 /// not, return 0. This predicate must return 0 if the instruction has
50 /// any side effects other than loading from the stack slot.
Dan Gohman0b273252008-11-18 19:49:32 +000051 virtual unsigned isLoadFromStackSlot(const MachineInstr *MI,
52 int &FrameIndex) const;
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +000053
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000054 /// isStoreToStackSlot - If the specified machine instruction is a direct
55 /// store to a stack slot, return the virtual or physical register number of
56 /// the source reg along with the FrameIndex of the loaded stack slot. If
57 /// not, return 0. This predicate must return 0 if the instruction has
58 /// any side effects other than storing to the stack slot.
Dan Gohman0b273252008-11-18 19:49:32 +000059 virtual unsigned isStoreToStackSlot(const MachineInstr *MI,
60 int &FrameIndex) const;
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +000061
Bruno Cardoso Lopes0c530632007-08-18 01:59:45 +000062 /// Branch Analysis
63 virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
64 MachineBasicBlock *&FBB,
Evan Cheng64dfcac2009-02-09 07:14:22 +000065 SmallVectorImpl<MachineOperand> &Cond,
66 bool AllowModify) const;
Bruno Cardoso Lopes0c530632007-08-18 01:59:45 +000067 virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
Akira Hatanaka93f898f2011-04-01 17:39:08 +000068
69private:
70 void BuildCondBr(MachineBasicBlock &MBB, MachineBasicBlock *TBB, DebugLoc DL,
71 const SmallVectorImpl<MachineOperand>& Cond) const;
72
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 Hatanakaf2bcad92011-07-01 01:04:43 +000094 virtual MachineInstr* emitFrameIndexDebugValue(MachineFunction &MF,
95 int FrameIx, uint64_t Offset,
96 const MDNode *MDPtr,
97 DebugLoc DL) const;
98
Owen Anderson4f6bf042008-08-14 22:49:33 +000099 virtual
100 bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
Bruno Cardoso Lopes0c530632007-08-18 01:59:45 +0000101
102 /// Insert nop instruction when hazard condition is found
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000103 virtual void insertNoop(MachineBasicBlock &MBB,
Bruno Cardoso Lopes0c530632007-08-18 01:59:45 +0000104 MachineBasicBlock::iterator MI) const;
Dan Gohmand5ca70642009-06-03 20:30:14 +0000105
106 /// getGlobalBaseReg - Return a virtual register initialized with the
107 /// the global base register value. Output instructions required to
108 /// initialize the register in the function entry block, if necessary.
109 ///
110 unsigned getGlobalBaseReg(MachineFunction *MF) const;
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000111};
112
113}
114
115#endif