2012-02-28 15:46:26 +08:00
|
|
|
//===-- MipsInstrInfo.h - Mips Instruction Information ----------*- C++ -*-===//
|
2007-06-06 15:42:06 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:36:04 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-06-06 15:42:06 +08:00
|
|
|
//
|
2011-04-16 05:51:11 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2007-06-06 15:42:06 +08:00
|
|
|
//
|
|
|
|
// This file contains the Mips implementation of the TargetInstrInfo class.
|
|
|
|
//
|
2011-04-16 05:51:11 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2007-06-06 15:42:06 +08:00
|
|
|
|
|
|
|
#ifndef MIPSINSTRUCTIONINFO_H
|
|
|
|
#define MIPSINSTRUCTIONINFO_H
|
|
|
|
|
|
|
|
#include "Mips.h"
|
2012-06-14 09:16:45 +08:00
|
|
|
#include "MipsAnalyzeImmediate.h"
|
2012-03-18 02:46:09 +08:00
|
|
|
#include "MipsRegisterInfo.h"
|
2013-05-14 01:57:42 +08:00
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
2009-07-12 04:10:48 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2007-06-06 15:42:06 +08:00
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
|
|
|
|
2011-07-02 01:57:27 +08:00
|
|
|
#define GET_INSTRINFO_HEADER
|
|
|
|
#include "MipsGenInstrInfo.inc"
|
|
|
|
|
2007-06-06 15:42:06 +08:00
|
|
|
namespace llvm {
|
|
|
|
|
2011-07-02 01:57:27 +08:00
|
|
|
class MipsInstrInfo : public MipsGenInstrInfo {
|
2013-11-19 08:57:56 +08:00
|
|
|
virtual void anchor();
|
2012-08-01 05:49:49 +08:00
|
|
|
protected:
|
2007-06-06 15:42:06 +08:00
|
|
|
MipsTargetMachine &TM;
|
2011-12-13 06:39:35 +08:00
|
|
|
unsigned UncondBrOpc;
|
2007-06-06 15:42:06 +08:00
|
|
|
|
2012-08-01 05:49:49 +08:00
|
|
|
public:
|
2013-03-01 09:10:17 +08:00
|
|
|
enum BranchType {
|
|
|
|
BT_None, // Couldn't analyze branch.
|
|
|
|
BT_NoBranch, // No branches found.
|
|
|
|
BT_Uncond, // One unconditional branch.
|
|
|
|
BT_Cond, // One conditional branch.
|
|
|
|
BT_CondUncond, // A conditional branch followed by an unconditional branch.
|
|
|
|
BT_Indirect // One indirct branch.
|
|
|
|
};
|
|
|
|
|
2012-08-01 05:49:49 +08:00
|
|
|
explicit MipsInstrInfo(MipsTargetMachine &TM, unsigned UncondBrOpc);
|
2011-03-05 01:51:39 +08:00
|
|
|
|
2012-08-03 02:21:47 +08:00
|
|
|
static const MipsInstrInfo *create(MipsTargetMachine &TM);
|
|
|
|
|
2007-08-18 09:59:45 +08:00
|
|
|
/// Branch Analysis
|
2014-04-29 15:58:02 +08:00
|
|
|
bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
|
|
|
|
MachineBasicBlock *&FBB,
|
|
|
|
SmallVectorImpl<MachineOperand> &Cond,
|
|
|
|
bool AllowModify) const override;
|
2011-04-02 01:39:08 +08:00
|
|
|
|
2014-04-29 15:58:02 +08:00
|
|
|
unsigned RemoveBranch(MachineBasicBlock &MBB) const override;
|
2011-04-02 01:39:08 +08:00
|
|
|
|
2014-04-29 15:58:02 +08:00
|
|
|
unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
|
|
|
|
MachineBasicBlock *FBB,
|
|
|
|
const SmallVectorImpl<MachineOperand> &Cond,
|
|
|
|
DebugLoc DL) const override;
|
2012-08-01 05:49:49 +08:00
|
|
|
|
2014-04-29 15:58:02 +08:00
|
|
|
bool
|
|
|
|
ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const override;
|
2012-05-26 04:52:52 +08:00
|
|
|
|
2013-03-01 09:10:17 +08:00
|
|
|
BranchType AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
|
|
|
|
MachineBasicBlock *&FBB,
|
|
|
|
SmallVectorImpl<MachineOperand> &Cond,
|
|
|
|
bool AllowModify,
|
|
|
|
SmallVectorImpl<MachineInstr*> &BranchInstrs) const;
|
|
|
|
|
2007-08-18 09:59:45 +08:00
|
|
|
/// Insert nop instruction when hazard condition is found
|
2014-04-29 15:58:02 +08:00
|
|
|
void insertNoop(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator MI) const override;
|
2012-06-14 09:16:45 +08:00
|
|
|
|
2012-08-01 05:49:49 +08:00
|
|
|
/// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As
|
|
|
|
/// such, whenever a client has an instance of instruction info, it should
|
|
|
|
/// always be able to get register info as well (through this method).
|
|
|
|
///
|
2012-08-01 07:41:32 +08:00
|
|
|
virtual const MipsRegisterInfo &getRegisterInfo() const = 0;
|
2012-08-01 05:49:49 +08:00
|
|
|
|
2013-05-14 01:43:19 +08:00
|
|
|
virtual unsigned getOppositeBranchOpc(unsigned Opc) const = 0;
|
2012-08-01 05:49:49 +08:00
|
|
|
|
2012-06-14 09:16:45 +08:00
|
|
|
/// Return the number of bytes of code the specified instruction may be.
|
|
|
|
unsigned GetInstSizeInBytes(const MachineInstr *MI) const;
|
2012-08-01 05:49:49 +08:00
|
|
|
|
2014-04-29 15:58:02 +08:00
|
|
|
void storeRegToStackSlot(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator MBBI,
|
|
|
|
unsigned SrcReg, bool isKill, int FrameIndex,
|
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
const TargetRegisterInfo *TRI) const override {
|
2013-03-29 10:14:12 +08:00
|
|
|
storeRegToStack(MBB, MBBI, SrcReg, isKill, FrameIndex, RC, TRI, 0);
|
|
|
|
}
|
|
|
|
|
2014-04-29 15:58:02 +08:00
|
|
|
void loadRegFromStackSlot(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator MBBI,
|
|
|
|
unsigned DestReg, int FrameIndex,
|
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
const TargetRegisterInfo *TRI) const override {
|
2013-03-29 10:14:12 +08:00
|
|
|
loadRegFromStack(MBB, MBBI, DestReg, FrameIndex, RC, TRI, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void storeRegToStack(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator MI,
|
|
|
|
unsigned SrcReg, bool isKill, int FrameIndex,
|
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
const TargetRegisterInfo *TRI,
|
|
|
|
int64_t Offset) const = 0;
|
|
|
|
|
|
|
|
virtual void loadRegFromStack(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator MI,
|
|
|
|
unsigned DestReg, int FrameIndex,
|
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
const TargetRegisterInfo *TRI,
|
|
|
|
int64_t Offset) const = 0;
|
|
|
|
|
2013-05-14 01:57:42 +08:00
|
|
|
/// Create an instruction which has the same operands and memory operands
|
|
|
|
/// as MI but has a new opcode.
|
|
|
|
MachineInstrBuilder genInstrWithNewOpc(unsigned NewOpc,
|
|
|
|
MachineBasicBlock::iterator I) const;
|
|
|
|
|
2012-08-01 05:49:49 +08:00
|
|
|
protected:
|
|
|
|
bool isZeroImm(const MachineOperand &op) const;
|
|
|
|
|
|
|
|
MachineMemOperand *GetMemOperand(MachineBasicBlock &MBB, int FI,
|
|
|
|
unsigned Flag) const;
|
|
|
|
|
|
|
|
private:
|
2013-05-14 01:43:19 +08:00
|
|
|
virtual unsigned getAnalyzableBrOpc(unsigned Opc) const = 0;
|
2012-08-01 05:49:49 +08:00
|
|
|
|
|
|
|
void AnalyzeCondBr(const MachineInstr *Inst, unsigned Opc,
|
|
|
|
MachineBasicBlock *&BB,
|
|
|
|
SmallVectorImpl<MachineOperand> &Cond) const;
|
|
|
|
|
|
|
|
void BuildCondBr(MachineBasicBlock &MBB, MachineBasicBlock *TBB, DebugLoc DL,
|
|
|
|
const SmallVectorImpl<MachineOperand>& Cond) const;
|
2007-06-06 15:42:06 +08:00
|
|
|
};
|
|
|
|
|
2012-08-03 02:21:47 +08:00
|
|
|
/// Create MipsInstrInfo objects.
|
|
|
|
const MipsInstrInfo *createMips16InstrInfo(MipsTargetMachine &TM);
|
|
|
|
const MipsInstrInfo *createMipsSEInstrInfo(MipsTargetMachine &TM);
|
|
|
|
|
2007-06-06 15:42:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|