2017-08-04 06:12:30 +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.
|
|
|
|
//
|
2014-04-30 23:06:25 +08:00
|
|
|
// FIXME: We need to override TargetInstrInfo::getInlineAsmLength method in
|
|
|
|
// order for MipsLongBranch pass to work correctly when the code has inline
|
|
|
|
// assembly. The returned value doesn't have to be the asm instruction's exact
|
|
|
|
// size in bytes; MipsLongBranch only expects it to be the correct upper bound.
|
2011-04-16 05:51:11 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2007-06-06 15:42:06 +08:00
|
|
|
|
2014-08-14 00:26:38 +08:00
|
|
|
#ifndef LLVM_LIB_TARGET_MIPS_MIPSINSTRINFO_H
|
|
|
|
#define LLVM_LIB_TARGET_MIPS_MIPSINSTRINFO_H
|
2007-06-06 15:42:06 +08:00
|
|
|
|
2017-08-04 06:12:30 +08:00
|
|
|
#include "MCTargetDesc/MipsMCTargetDesc.h"
|
2007-06-06 15:42:06 +08:00
|
|
|
#include "Mips.h"
|
2012-03-18 02:46:09 +08:00
|
|
|
#include "MipsRegisterInfo.h"
|
2017-08-04 06:12:30 +08:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
|
|
|
#include "llvm/CodeGen/MachineBasicBlock.h"
|
2013-05-14 01:57:42 +08:00
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
2017-08-04 06:12:30 +08:00
|
|
|
#include "llvm/CodeGen/MachineMemOperand.h"
|
2007-06-06 15:42:06 +08:00
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
2017-08-04 06:12:30 +08:00
|
|
|
#include <cstdint>
|
2007-06-06 15:42:06 +08:00
|
|
|
|
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 {
|
2017-08-04 06:12:30 +08:00
|
|
|
|
|
|
|
class MachineInstr;
|
|
|
|
class MachineOperand;
|
2015-03-12 13:43:57 +08:00
|
|
|
class MipsSubtarget;
|
2017-08-04 06:12:30 +08:00
|
|
|
class TargetRegisterClass;
|
|
|
|
class TargetRegisterInfo;
|
|
|
|
|
2011-07-02 01:57:27 +08:00
|
|
|
class MipsInstrInfo : public MipsGenInstrInfo {
|
2013-11-19 08:57:56 +08:00
|
|
|
virtual void anchor();
|
2017-08-04 06:12:30 +08:00
|
|
|
|
2012-08-01 05:49:49 +08:00
|
|
|
protected:
|
2014-07-19 07:25:00 +08:00
|
|
|
const MipsSubtarget &Subtarget;
|
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.
|
|
|
|
};
|
|
|
|
|
2014-07-19 07:25:00 +08:00
|
|
|
explicit MipsInstrInfo(const MipsSubtarget &STI, unsigned UncondBrOpc);
|
2011-03-05 01:51:39 +08:00
|
|
|
|
2014-07-19 07:25:00 +08:00
|
|
|
static const MipsInstrInfo *create(MipsSubtarget &STI);
|
2012-08-03 02:21:47 +08:00
|
|
|
|
2007-08-18 09:59:45 +08:00
|
|
|
/// Branch Analysis
|
2016-07-15 22:41:04 +08:00
|
|
|
bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
|
2014-04-29 15:58:02 +08:00
|
|
|
MachineBasicBlock *&FBB,
|
|
|
|
SmallVectorImpl<MachineOperand> &Cond,
|
|
|
|
bool AllowModify) const override;
|
2011-04-02 01:39:08 +08:00
|
|
|
|
2016-09-15 04:43:16 +08:00
|
|
|
unsigned removeBranch(MachineBasicBlock &MBB,
|
2016-09-15 01:23:48 +08:00
|
|
|
int *BytesRemoved = nullptr) const override;
|
2011-04-02 01:39:08 +08:00
|
|
|
|
2016-09-15 01:24:15 +08:00
|
|
|
unsigned insertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
|
2015-06-12 03:30:37 +08:00
|
|
|
MachineBasicBlock *FBB, ArrayRef<MachineOperand> Cond,
|
2016-09-15 01:23:48 +08:00
|
|
|
const DebugLoc &DL,
|
|
|
|
int *BytesAdded = nullptr) const override;
|
2012-08-01 05:49:49 +08:00
|
|
|
|
2014-04-29 15:58:02 +08:00
|
|
|
bool
|
2016-09-15 04:43:16 +08:00
|
|
|
reverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const override;
|
2012-05-26 04:52:52 +08:00
|
|
|
|
2016-07-15 22:41:04 +08:00
|
|
|
BranchType analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
|
2013-03-01 09:10:17 +08:00
|
|
|
MachineBasicBlock *&FBB,
|
|
|
|
SmallVectorImpl<MachineOperand> &Cond,
|
|
|
|
bool AllowModify,
|
2016-07-15 22:41:04 +08:00
|
|
|
SmallVectorImpl<MachineInstr *> &BranchInstrs) const;
|
2013-03-01 09:10:17 +08:00
|
|
|
|
2016-03-15 00:24:05 +08:00
|
|
|
/// Determine the opcode of a non-delay slot form for a branch if one exists.
|
|
|
|
unsigned getEquivalentCompactForm(const MachineBasicBlock::iterator I) const;
|
|
|
|
|
|
|
|
/// Predicate to determine if an instruction can go in a forbidden slot.
|
|
|
|
bool SafeInForbiddenSlot(const MachineInstr &MI) const;
|
|
|
|
|
|
|
|
/// Predicate to determine if an instruction has a forbidden slot.
|
|
|
|
bool HasForbiddenSlot(const MachineInstr &MI) 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.
|
2016-07-29 16:16:16 +08:00
|
|
|
unsigned getInstSizeInBytes(const MachineInstr &MI) const override;
|
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;
|
2015-04-02 18:42:44 +08:00
|
|
|
|
|
|
|
virtual void adjustStackPtr(unsigned SP, int64_t Amount,
|
|
|
|
MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator I) const = 0;
|
2013-03-29 10:14:12 +08:00
|
|
|
|
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;
|
|
|
|
|
2017-03-31 22:31:55 +08:00
|
|
|
bool findCommutedOpIndices(MachineInstr &MI, unsigned &SrcOpIdx1,
|
|
|
|
unsigned &SrcOpIdx2) const override;
|
|
|
|
|
2012-08-01 05:49:49 +08:00
|
|
|
protected:
|
|
|
|
bool isZeroImm(const MachineOperand &op) const;
|
|
|
|
|
|
|
|
MachineMemOperand *GetMemOperand(MachineBasicBlock &MBB, int FI,
|
2016-07-16 02:26:59 +08:00
|
|
|
MachineMemOperand::Flags Flags) const;
|
2012-08-01 05:49:49 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2016-06-12 23:39:02 +08:00
|
|
|
void BuildCondBr(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
|
|
|
|
const DebugLoc &DL, ArrayRef<MachineOperand> Cond) const;
|
2007-06-06 15:42:06 +08:00
|
|
|
};
|
|
|
|
|
2012-08-03 02:21:47 +08:00
|
|
|
/// Create MipsInstrInfo objects.
|
2014-07-19 07:25:00 +08:00
|
|
|
const MipsInstrInfo *createMips16InstrInfo(const MipsSubtarget &STI);
|
|
|
|
const MipsInstrInfo *createMipsSEInstrInfo(const MipsSubtarget &STI);
|
2012-08-03 02:21:47 +08:00
|
|
|
|
2017-08-04 06:12:30 +08:00
|
|
|
} // end namespace llvm
|
2007-06-06 15:42:06 +08:00
|
|
|
|
2017-08-04 06:12:30 +08:00
|
|
|
#endif // LLVM_LIB_TARGET_MIPS_MIPSINSTRINFO_H
|