MipsInstrInfo.h revision c713e996d305df99cc7fc58c9d8dc1f5fa00518d
1cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com//===-- MipsInstrInfo.h - Mips Instruction Information ----------*- C++ -*-===// 2cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com// 3cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com// The LLVM Compiler Infrastructure 4cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com// 5cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com// This file is distributed under the University of Illinois Open Source 6cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com// License. See LICENSE.TXT for details. 7cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com// 8cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com//===----------------------------------------------------------------------===// 9cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com// 108cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com// This file contains the Mips implementation of the TargetInstrInfo class. 118cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com// 128cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com//===----------------------------------------------------------------------===// 138cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 148cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#ifndef MIPSINSTRUCTIONINFO_H 158cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#define MIPSINSTRUCTIONINFO_H 168cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 178cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#include "Mips.h" 188cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#include "MipsAnalyzeImmediate.h" 198cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#include "MipsRegisterInfo.h" 208cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#include "llvm/Support/ErrorHandling.h" 218cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#include "llvm/Target/TargetInstrInfo.h" 228cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 238cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#define GET_INSTRINFO_HEADER 248cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#include "MipsGenInstrInfo.inc" 258cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 268cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comnamespace llvm { 278cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 288cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comclass MipsInstrInfo : public MipsGenInstrInfo { 298cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comprotected: 308cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com MipsTargetMachine &TM; 318cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com unsigned UncondBrOpc; 328cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 338cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.compublic: 348cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com enum BranchType { 358cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com BT_None, // Couldn't analyze branch. 368cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com BT_NoBranch, // No branches found. 378cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com BT_Uncond, // One unconditional branch. 388cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com BT_Cond, // One conditional branch. 398cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com BT_CondUncond, // A conditional branch followed by an unconditional branch. 408cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com BT_Indirect // One indirct branch. 418cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com }; 428cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 438cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com explicit MipsInstrInfo(MipsTargetMachine &TM, unsigned UncondBrOpc); 448cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 458cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com static const MipsInstrInfo *create(MipsTargetMachine &TM); 468cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 478cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com /// Branch Analysis 488cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, 498cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com MachineBasicBlock *&FBB, 508cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com SmallVectorImpl<MachineOperand> &Cond, 518cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com bool AllowModify) const; 528cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 538cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const; 548cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 558cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, 568cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com MachineBasicBlock *FBB, 578cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com const SmallVectorImpl<MachineOperand> &Cond, 588cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com DebugLoc DL) const; 598cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 608cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com virtual 618cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const; 628cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 638cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com BranchType AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, 648cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com MachineBasicBlock *&FBB, 658cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com SmallVectorImpl<MachineOperand> &Cond, 668cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com bool AllowModify, 678cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com SmallVectorImpl<MachineInstr*> &BranchInstrs) const; 688cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 698cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com virtual MachineInstr* emitFrameIndexDebugValue(MachineFunction &MF, 708cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com int FrameIx, uint64_t Offset, 718cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com const MDNode *MDPtr, 728cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com DebugLoc DL) const; 738cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 748cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com /// Insert nop instruction when hazard condition is found 758cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com virtual void insertNoop(MachineBasicBlock &MBB, 768cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com MachineBasicBlock::iterator MI) const; 778cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 788cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As 798cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com /// such, whenever a client has an instance of instruction info, it should 808cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com /// always be able to get register info as well (through this method). 818cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com /// 828cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com virtual const MipsRegisterInfo &getRegisterInfo() const = 0; 838cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 848cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com virtual unsigned GetOppositeBranchOpc(unsigned Opc) const = 0; 858cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 868cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com /// Return the number of bytes of code the specified instruction may be. 878cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com unsigned GetInstSizeInBytes(const MachineInstr *MI) const; 888cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 898cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com virtual void storeRegToStackSlot(MachineBasicBlock &MBB, 908cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com MachineBasicBlock::iterator MBBI, 918cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com unsigned SrcReg, bool isKill, int FrameIndex, 928cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com const TargetRegisterClass *RC, 938cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com const TargetRegisterInfo *TRI) const { 948cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com storeRegToStack(MBB, MBBI, SrcReg, isKill, FrameIndex, RC, TRI, 0); 958cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com } 968cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 978cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com virtual void loadRegFromStackSlot(MachineBasicBlock &MBB, 988cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com MachineBasicBlock::iterator MBBI, 998cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com unsigned DestReg, int FrameIndex, 1008cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com const TargetRegisterClass *RC, 1018cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com const TargetRegisterInfo *TRI) const { 1028cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com loadRegFromStack(MBB, MBBI, DestReg, FrameIndex, RC, TRI, 0); 1038cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com } 1048cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 1058cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com virtual void storeRegToStack(MachineBasicBlock &MBB, 1068cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com MachineBasicBlock::iterator MI, 1078cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com unsigned SrcReg, bool isKill, int FrameIndex, 1088cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com const TargetRegisterClass *RC, 1098cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com const TargetRegisterInfo *TRI, 1108cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com int64_t Offset) const = 0; 1118cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 1128cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com virtual void loadRegFromStack(MachineBasicBlock &MBB, 1138cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com MachineBasicBlock::iterator MI, 1148cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com unsigned DestReg, int FrameIndex, 1158cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com const TargetRegisterClass *RC, 1168cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com const TargetRegisterInfo *TRI, 1178cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com int64_t Offset) const = 0; 1188cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 1198cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comprotected: 1208cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com bool isZeroImm(const MachineOperand &op) const; 1218cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 1228cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com MachineMemOperand *GetMemOperand(MachineBasicBlock &MBB, int FI, 1238cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com unsigned Flag) const; 1248cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 1258cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comprivate: 1268cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com virtual unsigned GetAnalyzableBrOpc(unsigned Opc) const = 0; 1278cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 1288cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com void AnalyzeCondBr(const MachineInstr *Inst, unsigned Opc, 1298cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com MachineBasicBlock *&BB, 1308cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com SmallVectorImpl<MachineOperand> &Cond) const; 1318cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 1328cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com void BuildCondBr(MachineBasicBlock &MBB, MachineBasicBlock *TBB, DebugLoc DL, 1338cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com const SmallVectorImpl<MachineOperand>& Cond) const; 1348cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com}; 1358cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 1368cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com/// Create MipsInstrInfo objects. 1378cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comconst MipsInstrInfo *createMips16InstrInfo(MipsTargetMachine &TM); 1388cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comconst MipsInstrInfo *createMipsSEInstrInfo(MipsTargetMachine &TM); 1398cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 1408cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com} 1418cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 1428cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#endif 1438cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com